diff --git a/novelforge-project/agent-workspace/flutter/examples/api/README.md b/novelforge-project/agent-workspace/flutter/examples/api/README.md new file mode 100644 index 0000000000000000000000000000000000000000..73770a426f4c11e11419ab4d76b03943225ba327 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/api/README.md @@ -0,0 +1,154 @@ +# API Example Code + +This directory contains the API sample code that is referenced from the API +documentation in the framework. + +The examples can be run individually by just specifying the path to the example +on the command line (or in the run configuration of an IDE). + +For example (no pun intended!), to run the first example from the `Curve2D` +class in Chrome, you would run it like so from the [api](.) directory: + +``` +% flutter run -d chrome lib/animation/curves/curve2_d.0.dart +``` + +All of these same examples are available on the API docs site. For instance, the +example above is available on [this page]( +https://api.flutter.dev/flutter/animation/Curve2D-class.html#animation.Curve2D.1). +Most of the samples are available as interactive examples in +[Dartpad](https://dartpad.dev), but some (the ones marked with `{@tool sample}` +in the framework source code), just don't make sense on the web, and so are +available as standalone examples that can be run here. For instance, setting the +system overlay style doesn't make sense on the web (it only changes the +notification area background color on Android), so you can run the example for +that on an Android device like so: + +``` +% flutter run -d MyAndroidDevice lib/services/system_chrome/system_chrome.set_system_u_i_overlay_style.1.dart +``` + +## Naming + +> `lib/library/file/class_name.n.dart` +> +> `lib/library/file/class_name.member_name.n.dart` + +The naming scheme for the files is similar to the hierarchy under +[packages/flutter/lib/src](../../packages/flutter/lib/src), except that the +files are represented as directories (without the `.dart` suffix), and each +sample in the file is a separate file in that directory. So, for the example +above, where the examples are from the +[packages/flutter/lib/src/animation/curves.dart](../../packages/flutter/lib/src/animation/curves.dart) +file, the `Curve2D` class, the first sample (hence the index "0") for that +symbol resides in the file named +[lib/animation/curves/curve2_d.0.dart](lib/animation/curves/curve2_d.0.dart). + +Symbol names are converted from "CamelCase" to "snake_case". Dots are left +between symbol names, so the first example for symbol +`InputDecoration.prefixIconConstraints` would be converted to +`input_decoration.prefix_icon_constraints.0.dart`. + +If the same example is linked to from multiple symbols, the source will be in +the canonical location for one of the symbols, and the link in the API docs +block for the other symbols will point to the first symbol's example location. + +## Authoring + +> For more detailed information about authoring examples, see +> [the snippets package](https://pub.dev/packages/snippets). + +When authoring examples, first place a block in the Dartdoc documentation for +the symbol you would like to attach it to. Here's what it might look like if you +wanted to add a new example to the `Curve2D` class: + +```dart +/// {@tool dartpad} +/// Write a description of the example here. This description will appear in the +/// API web documentation to introduce the example. +/// +/// ** See code in examples/api/lib/animation/curves/curve2_d.0.dart ** +/// {@end-tool} +``` + +The "See code in" line needs to be formatted exactly as above, with no wrapping +or newlines, one space after the "`**`" at the beginning, and one space before +the "`**`" at the end, and the words "See code in" at the beginning of the line. +This is what the snippets tool use when finding the example source code that you +are creating. + +Use `{@tool dartpad}` for Dartpad examples, and use `{@tool sample}` for +examples that shouldn't be run/shown in Dartpad. + +Once that comment block is inserted in the source code, create a new file at the +appropriate path under [`examples/api`](.). See the +[sample_templates](./lib/sample_templates/) directory for examples of different +types of samples with some best practices applied. + +The filename should match the location of the source file it is linked from, and +is named for the symbol it is attached to, in lower_snake_case, with an index +relating to their order within the doc comment. So, for the `Curve2D` example +above, since it's in the `animation` library, in a file called `curves.dart`, +and it's the first example, it should have the name +`examples/api/lib/animation/curves/curve2_d.0.dart`. + +You should also add tests for your sample code under +[`examples/api/test`](./test), that matches their location under [lib](./lib), +ending in `_test.dart`. See the section on [writing tests](#writing-tests) for +more information on what kinds of tests to write. + +The entire example should be in a single file, so that Dartpad can load it. + +Only packages that can be loaded by Dartpad may be imported. If you use one that +hasn't been used in an example before, you may have to add it to the +[pubspec.yaml](pubspec.yaml) in the api directory. + +## Snippets + +There is another type of example that can also be authored, using `{@tool +snippet}`. Snippet examples are just written inline in the source, like so: + +```dart +/// {@tool dartpad} +/// Write a description of the example here. This description will appear in the +/// API web documentation to introduce the example. +/// +/// ```dart +/// // Sample code goes here, e.g.: +/// const Widget emptyBox = SizedBox(); +/// ``` +/// {@end-tool} +``` + +The source for these snippets isn't stored under the [`examples/api`](.) +directory, or available in Dartpad in the API docs, since they're not intended +to be runnable, they just show some incomplete snippet of example code. It must +compile (in the context of the sample analyzer), but doesn't need to do +anything. See [the snippets documentation]( +https://pub.dev/packages/snippets#snippet-tool) for more information about the +context that the analyzer uses. + +## Writing Tests + +Examples are required to have tests. There is already a "smoke test" that simply +builds and runs all the API examples, just to make sure that they start up +without crashing. Functionality tests are required the examples, and generally +just do what is normally done for writing tests. The one thing that makes it +more challenging to do for examples is that they can't really be written for +testability in any obvious way, since that would complicate the examples and +make them harder to explain. + +As an example, in regular framework code, you might include a parameter for a +`Platform` object that can be overridden by a test to supply a dummy platform, +but in the example. This would be unnecessarily complex for the example. In all +other ways, these are just normal tests. You don't need to re-test the +functionality of the widget being used in the example, but you should test the +functionality and integrity of the example itself. + +Tests go into a directory under [test](./test) that matches their location under +[lib](./lib). They are named the same as the example they are testing, with +`_test.dart` at the end, like other tests. For instance, a `LayoutBuilder` +example that resides in [`lib/widgets/layout_builder/layout_builder.0.dart`]( +./lib/widgets/layout_builder/layout_builder.0.dart) would have its tests in a +file named [`test/widgets/layout_builder/layout_builder.0_test.dart`]( +./test/widgets/layout_builder/layout_builder.0_test.dart) diff --git a/novelforge-project/agent-workspace/flutter/examples/api/analysis_options.yaml b/novelforge-project/agent-workspace/flutter/examples/api/analysis_options.yaml new file mode 100644 index 0000000000000000000000000000000000000000..dec61f90edbccae7d10c2bad23f1e5532adaf441 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/api/analysis_options.yaml @@ -0,0 +1,10 @@ +# This file is also used by dev/bots/analyze_snippet_code.dart to analyze code snippets (`{@tool snippet}` sections). + +include: ../../analysis_options.yaml + +linter: + rules: + # Samples want to print things pretty often. + avoid_print: false + # Samples are sometimes incomplete and don't show usage of everything. + unreachable_from_main: false diff --git a/novelforge-project/agent-workspace/flutter/examples/api/pubspec.lock b/novelforge-project/agent-workspace/flutter/examples/api/pubspec.lock new file mode 100644 index 0000000000000000000000000000000000000000..9496976efe5ee259b30159e07f7584fd1560d572 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/api/pubspec.lock @@ -0,0 +1,531 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: "direct dev" + description: + name: _fe_analyzer_shared + sha256: "36a321c3d2cbe01cbcb3540a87b8843846e0206df3e691fa7b23e19e78de6d49" + url: "https://pub.dev" + source: hosted + version: "65.0.0" + analyzer: + dependency: "direct dev" + description: + name: analyzer + sha256: dfe03b90ec022450e22513b5e5ca1f01c0c01de9c3fba2f7fd233cb57a6b9a07 + url: "https://pub.dev" + source: hosted + version: "6.3.0" + args: + dependency: "direct dev" + description: + name: args + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" + source: hosted + version: "2.4.2" + async: + dependency: "direct dev" + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: "direct dev" + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: "direct main" + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: "direct dev" + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: "direct dev" + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: "direct dev" + description: + name: coverage + sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76" + url: "https://pub.dev" + source: hosted + version: "1.7.2" + crypto: + dependency: "direct dev" + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d + url: "https://pub.dev" + source: hosted + version: "1.0.6" + fake_async: + dependency: "direct dev" + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + file: + dependency: "direct dev" + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_driver: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_goldens: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_localizations: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_web_plugins: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + frontend_server_client: + dependency: "direct dev" + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + fuchsia_remote_debug_protocol: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + glob: + dependency: "direct dev" + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + http_multi_server: + dependency: "direct dev" + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: "direct dev" + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + integration_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + intl: + dependency: "direct dev" + description: + name: intl + sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + url: "https://pub.dev" + source: hosted + version: "0.18.1" + io: + dependency: "direct dev" + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: "direct dev" + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + leak_tracker: + dependency: "direct dev" + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: "direct dev" + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: "direct dev" + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + logging: + dependency: "direct dev" + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: "direct dev" + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: "direct main" + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: "direct main" + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + mime: + dependency: "direct dev" + description: + name: mime + sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + url: "https://pub.dev" + source: hosted + version: "1.0.4" + node_preamble: + dependency: "direct dev" + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: "direct dev" + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: "direct dev" + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + platform: + dependency: "direct dev" + description: + name: platform + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + url: "https://pub.dev" + source: hosted + version: "3.1.4" + pool: + dependency: "direct dev" + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + process: + dependency: "direct dev" + description: + name: process + sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32" + url: "https://pub.dev" + source: hosted + version: "5.0.2" + pub_semver: + dependency: "direct dev" + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + shelf: + dependency: "direct dev" + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: "direct dev" + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: "direct dev" + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: "direct dev" + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_map_stack_trace: + dependency: "direct dev" + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: "direct dev" + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" + source_span: + dependency: "direct dev" + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: "direct dev" + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: "direct dev" + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: "direct dev" + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + sync_http: + dependency: "direct dev" + description: + name: sync_http + sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961" + url: "https://pub.dev" + source: hosted + version: "0.3.1" + term_glyph: + dependency: "direct dev" + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f + url: "https://pub.dev" + source: hosted + version: "1.24.9" + test_api: + dependency: "direct dev" + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + test_core: + dependency: "direct dev" + description: + name: test_core + sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a + url: "https://pub.dev" + source: hosted + version: "0.5.9" + typed_data: + dependency: "direct dev" + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: "direct dev" + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" + watcher: + dependency: "direct dev" + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web: + dependency: "direct dev" + description: + name: web + sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa + url: "https://pub.dev" + source: hosted + version: "0.4.0" + web_socket_channel: + dependency: "direct dev" + description: + name: web_socket_channel + sha256: "045ec2137c27bf1a32e6ffa0e734d532a6677bf9016a0d1a406c54e499ff945b" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + webdriver: + dependency: "direct dev" + description: + name: webdriver + sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + webkit_inspection_protocol: + dependency: "direct dev" + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: "direct dev" + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.2.0 <4.0.0" + flutter: ">=2.5.0-6.0.pre.30" diff --git a/novelforge-project/agent-workspace/flutter/examples/api/pubspec.yaml b/novelforge-project/agent-workspace/flutter/examples/api/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..17b0d3a01e83da3217aa4fab56c035197355d531 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/api/pubspec.yaml @@ -0,0 +1,96 @@ +# This file is also used by dev/bots/analyze_snippet_code.dart to analyze code snippets (`{@tool snippet}` sections). + +name: flutter_api_samples +description: API code samples for the Flutter repo. +publish_to: 'none' + +version: 1.0.0 + +environment: + sdk: '>=3.2.0-0 <4.0.0' + flutter: ">=2.5.0-6.0.pre.30 <3.0.0" + +dependencies: + cupertino_icons: 1.0.6 + flutter: + sdk: flutter + + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +dev_dependencies: + integration_test: + sdk: flutter + flutter_driver: + sdk: flutter + flutter_goldens: + sdk: flutter + flutter_localizations: + sdk: flutter + flutter_test: + sdk: flutter + flutter_web_plugins: + sdk: flutter + test: 1.24.9 + + _fe_analyzer_shared: 65.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + analyzer: 6.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + args: 2.4.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + convert: 3.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + coverage: 1.7.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + crypto: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + file: 7.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + frontend_server_client: 3.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + glob: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_multi_server: 3.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_parser: 4.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + intl: 0.18.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + io: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + js: 0.6.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker: 10.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_flutter_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + logging: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + matcher: 0.12.16+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + mime: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + node_preamble: 2.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + package_config: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + path: 1.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + platform: 3.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pool: 1.5.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + process: 5.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pub_semver: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf: 1.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_packages_handler: 3.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_static: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_web_socket: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_map_stack_trace: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_maps: 0.10.12 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + sync_http: 0.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_core: 0.5.9 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + typed_data: 1.3.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + watcher: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web_socket_channel: 2.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webdriver: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + yaml: 3.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +flutter: + uses-material-design: true + +# PUBSPEC CHECKSUM: e00b diff --git a/novelforge-project/agent-workspace/flutter/examples/catalog/catalog.iml b/novelforge-project/agent-workspace/flutter/examples/catalog/catalog.iml new file mode 100644 index 0000000000000000000000000000000000000000..1d83ed3abc9085f991ca3f8f864f38df5577a8a6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/catalog/catalog.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/flutter_gallery/android.iml b/novelforge-project/agent-workspace/flutter/examples/flutter_gallery/android.iml new file mode 100644 index 0000000000000000000000000000000000000000..79f6223dbf740f805ef97f2b382f592944c1b899 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/flutter_gallery/android.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/flutter_gallery/flutter_gallery.iml b/novelforge-project/agent-workspace/flutter/examples/flutter_gallery/flutter_gallery.iml new file mode 100644 index 0000000000000000000000000000000000000000..71ade4c2bb561947180eea687a9e885b50433c75 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/flutter_gallery/flutter_gallery.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/flutter_view/README.md b/novelforge-project/agent-workspace/flutter/examples/flutter_view/README.md new file mode 100644 index 0000000000000000000000000000000000000000..70146153945bb8f899022985b586a0c4060b4710 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/flutter_view/README.md @@ -0,0 +1,18 @@ +# Example of embedding Flutter using FlutterView + +This project demonstrates how to embed Flutter within an iOS or Android +application. On iOS, the iOS and Flutter components are built with Xcode. On +Android, the Android and Flutter components are built with Android Studio or +Gradle. + +You can read more about +[accessing platform and third-party services in Flutter](https://flutter.dev/platform-services/). + +## iOS + +You can open `ios/Runner.xcworkspace` in Xcode and build the project as +usual. + +## Android + +You can open `android/` in Android Studio and build the project as usual. diff --git a/novelforge-project/agent-workspace/flutter/examples/flutter_view/flutter_view.iml b/novelforge-project/agent-workspace/flutter/examples/flutter_view/flutter_view.iml new file mode 100644 index 0000000000000000000000000000000000000000..1d83ed3abc9085f991ca3f8f864f38df5577a8a6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/flutter_view/flutter_view.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/flutter_view/pubspec.lock b/novelforge-project/agent-workspace/flutter/examples/flutter_view/pubspec.lock new file mode 100644 index 0000000000000000000000000000000000000000..36bc7e99c2379e280e9449f9a2375c5cc29f144d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/flutter_view/pubspec.lock @@ -0,0 +1,55 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + characters: + dependency: "direct main" + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + material_color_utilities: + dependency: "direct main" + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: "direct main" + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" +sdks: + dart: ">=3.2.0-0 <4.0.0" diff --git a/novelforge-project/agent-workspace/flutter/examples/flutter_view/pubspec.yaml b/novelforge-project/agent-workspace/flutter/examples/flutter_view/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7cccec050e458da0a2c1235e973498c3d27e0539 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/flutter_view/pubspec.yaml @@ -0,0 +1,22 @@ +name: flutter_view +description: A new flutter project. + +environment: + sdk: '>=3.2.0-0 <4.0.0' + +dependencies: + flutter: + sdk: flutter + + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +flutter: + uses-material-design: true + assets: + - assets/flutter-mark-square-64.png + +# PUBSPEC CHECKSUM: 4694 diff --git a/novelforge-project/agent-workspace/flutter/examples/hello_world/README.md b/novelforge-project/agent-workspace/flutter/examples/hello_world/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0a9132c3761313fbc2080a6b4567e678927a21d5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/hello_world/README.md @@ -0,0 +1,8 @@ +## To run the Hello World demo: +``` +flutter run +``` +## To run the Hello World demo showing Arabic: +``` +flutter run lib/arabic.dart +``` diff --git a/novelforge-project/agent-workspace/flutter/examples/hello_world/android.iml b/novelforge-project/agent-workspace/flutter/examples/hello_world/android.iml new file mode 100644 index 0000000000000000000000000000000000000000..79f6223dbf740f805ef97f2b382f592944c1b899 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/hello_world/android.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/hello_world/hello_world.iml b/novelforge-project/agent-workspace/flutter/examples/hello_world/hello_world.iml new file mode 100644 index 0000000000000000000000000000000000000000..71ade4c2bb561947180eea687a9e885b50433c75 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/hello_world/hello_world.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/hello_world/pubspec.lock b/novelforge-project/agent-workspace/flutter/examples/hello_world/pubspec.lock new file mode 100644 index 0000000000000000000000000000000000000000..ad1b0b9a0996e1d4cf90d2df5ba990b0823723d3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/hello_world/pubspec.lock @@ -0,0 +1,494 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: "direct dev" + description: + name: _fe_analyzer_shared + sha256: "36a321c3d2cbe01cbcb3540a87b8843846e0206df3e691fa7b23e19e78de6d49" + url: "https://pub.dev" + source: hosted + version: "65.0.0" + analyzer: + dependency: "direct dev" + description: + name: analyzer + sha256: dfe03b90ec022450e22513b5e5ca1f01c0c01de9c3fba2f7fd233cb57a6b9a07 + url: "https://pub.dev" + source: hosted + version: "6.3.0" + args: + dependency: "direct dev" + description: + name: args + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" + source: hosted + version: "2.4.2" + async: + dependency: "direct dev" + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: "direct dev" + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: "direct main" + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: "direct dev" + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: "direct dev" + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: "direct dev" + description: + name: coverage + sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76" + url: "https://pub.dev" + source: hosted + version: "1.7.2" + crypto: + dependency: "direct dev" + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + fake_async: + dependency: "direct dev" + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + file: + dependency: "direct dev" + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_driver: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + frontend_server_client: + dependency: "direct dev" + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + fuchsia_remote_debug_protocol: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + glob: + dependency: "direct dev" + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + http_multi_server: + dependency: "direct dev" + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: "direct dev" + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: "direct dev" + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: "direct dev" + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + leak_tracker: + dependency: "direct dev" + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: "direct dev" + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: "direct dev" + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + logging: + dependency: "direct dev" + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: "direct dev" + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: "direct main" + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: "direct main" + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + mime: + dependency: "direct dev" + description: + name: mime + sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + url: "https://pub.dev" + source: hosted + version: "1.0.4" + node_preamble: + dependency: "direct dev" + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: "direct dev" + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: "direct dev" + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + platform: + dependency: transitive + description: + name: platform + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + url: "https://pub.dev" + source: hosted + version: "3.1.4" + pool: + dependency: "direct dev" + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + process: + dependency: transitive + description: + name: process + sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32" + url: "https://pub.dev" + source: hosted + version: "5.0.2" + pub_semver: + dependency: "direct dev" + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + shelf: + dependency: "direct dev" + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: "direct dev" + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: "direct dev" + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: "direct dev" + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_map_stack_trace: + dependency: "direct dev" + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: "direct dev" + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" + source_span: + dependency: "direct dev" + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: "direct dev" + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: "direct dev" + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: "direct dev" + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + sync_http: + dependency: "direct dev" + description: + name: sync_http + sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961" + url: "https://pub.dev" + source: hosted + version: "0.3.1" + term_glyph: + dependency: "direct dev" + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f + url: "https://pub.dev" + source: hosted + version: "1.24.9" + test_api: + dependency: "direct dev" + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + test_core: + dependency: "direct dev" + description: + name: test_core + sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a + url: "https://pub.dev" + source: hosted + version: "0.5.9" + typed_data: + dependency: "direct dev" + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: "direct dev" + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" + watcher: + dependency: "direct dev" + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web: + dependency: "direct dev" + description: + name: web + sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa + url: "https://pub.dev" + source: hosted + version: "0.4.0" + web_socket_channel: + dependency: "direct dev" + description: + name: web_socket_channel + sha256: "045ec2137c27bf1a32e6ffa0e734d532a6677bf9016a0d1a406c54e499ff945b" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + webdriver: + dependency: "direct dev" + description: + name: webdriver + sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + webkit_inspection_protocol: + dependency: "direct dev" + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: "direct dev" + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.2.0 <4.0.0" diff --git a/novelforge-project/agent-workspace/flutter/examples/hello_world/pubspec.yaml b/novelforge-project/agent-workspace/flutter/examples/hello_world/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..de6cfa22ab95c384ebdc83d232d84d697f6e0978 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/hello_world/pubspec.yaml @@ -0,0 +1,74 @@ +name: hello_world + +environment: + sdk: '>=3.2.0-0 <4.0.0' + +dependencies: + flutter: + sdk: flutter + + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +dev_dependencies: + flutter_driver: + sdk: flutter + flutter_test: + sdk: flutter + test: 1.24.9 + + _fe_analyzer_shared: 65.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + analyzer: 6.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + args: 2.4.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + convert: 3.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + coverage: 1.7.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + crypto: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + file: 7.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + frontend_server_client: 3.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + glob: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_multi_server: 3.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_parser: 4.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + io: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + js: 0.6.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker: 10.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_flutter_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + logging: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + matcher: 0.12.16+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + mime: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + node_preamble: 2.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + package_config: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + path: 1.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pool: 1.5.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pub_semver: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf: 1.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_packages_handler: 3.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_static: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_web_socket: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_map_stack_trace: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_maps: 0.10.12 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + sync_http: 0.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_core: 0.5.9 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + typed_data: 1.3.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + watcher: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web_socket_channel: 2.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webdriver: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + yaml: 3.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +# PUBSPEC CHECKSUM: 6020 diff --git a/novelforge-project/agent-workspace/flutter/examples/image_list/README.md b/novelforge-project/agent-workspace/flutter/examples/image_list/README.md new file mode 100644 index 0000000000000000000000000000000000000000..109f142e9ca480a25467a667ef5a8b56d0abdfc5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/image_list/README.md @@ -0,0 +1,7 @@ +# Image List + +An example that sets up a local HTTP server for serving one +image then creates a single flutter widget with five copies of requested +image and prints how long the loading took. + +This is used in [$FH/flutter/devicelab/bin/tasks/image_list_reported_duration.dart] test. diff --git a/novelforge-project/agent-workspace/flutter/examples/image_list/android/build.gradle b/novelforge-project/agent-workspace/flutter/examples/image_list/android/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..2de20623576a82c3115eca8b1bdb56fd5b5051cb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/image_list/android/build.gradle @@ -0,0 +1,51 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is auto generated. +// To update all the build.gradle files in the Flutter repo, +// See dev/tools/bin/generate_gradle_lockfiles.dart. + +buildscript { + ext.kotlin_version = '1.5.31' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.2.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } + + configurations.classpath { + resolutionStrategy.activateDependencyLocking() + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' + +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') + dependencyLocking { + ignoredDependencies.add('io.flutter:*') + lockFile = file("${rootProject.projectDir}/project-${project.name}.lockfile") + if (!project.hasProperty('local-engine-repo')) { + lockAllConfigurations() + } + } +} + +tasks.register("clean", Delete) { + delete rootProject.buildDir +} diff --git a/novelforge-project/agent-workspace/flutter/examples/image_list/android/buildscript-gradle.lockfile b/novelforge-project/agent-workspace/flutter/examples/image_list/android/buildscript-gradle.lockfile new file mode 100644 index 0000000000000000000000000000000000000000..efe13277310ee8fef3c9d7f6f8a2cbbe601d110f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/image_list/android/buildscript-gradle.lockfile @@ -0,0 +1,163 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +androidx.databinding:databinding-common:7.2.0=classpath +androidx.databinding:databinding-compiler-common:7.2.0=classpath +com.android.databinding:baseLibrary:7.2.0=classpath +com.android.tools.analytics-library:crash:30.2.0=classpath +com.android.tools.analytics-library:protos:30.2.0=classpath +com.android.tools.analytics-library:shared:30.2.0=classpath +com.android.tools.analytics-library:tracker:30.2.0=classpath +com.android.tools.build.jetifier:jetifier-core:1.0.0-beta09=classpath +com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta09=classpath +com.android.tools.build:aapt2-proto:7.2.0-7984345=classpath +com.android.tools.build:aaptcompiler:7.2.0=classpath +com.android.tools.build:apksig:7.2.0=classpath +com.android.tools.build:apkzlib:7.2.0=classpath +com.android.tools.build:builder-model:7.2.0=classpath +com.android.tools.build:builder-test-api:7.2.0=classpath +com.android.tools.build:builder:7.2.0=classpath +com.android.tools.build:bundletool:1.8.2=classpath +com.android.tools.build:gradle-api:7.2.0=classpath +com.android.tools.build:gradle:7.2.0=classpath +com.android.tools.build:manifest-merger:30.2.0=classpath +com.android.tools.build:transform-api:2.0.0-deprecated-use-gradle-api=classpath +com.android.tools.ddms:ddmlib:30.2.0=classpath +com.android.tools.layoutlib:layoutlib-api:30.2.0=classpath +com.android.tools.lint:lint-model:30.2.0=classpath +com.android.tools.lint:lint-typedef-remover:30.2.0=classpath +com.android.tools.utp:android-device-provider-ddmlib-proto:30.2.0=classpath +com.android.tools.utp:android-device-provider-gradle-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-host-additional-test-output-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-host-coverage-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-host-retention-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-result-listener-gradle-proto:30.2.0=classpath +com.android.tools:annotations:30.2.0=classpath +com.android.tools:common:30.2.0=classpath +com.android.tools:dvlib:30.2.0=classpath +com.android.tools:repository:30.2.0=classpath +com.android.tools:sdk-common:30.2.0=classpath +com.android.tools:sdklib:30.2.0=classpath +com.android:signflinger:7.2.0=classpath +com.android:zipflinger:7.2.0=classpath +com.fasterxml.jackson.core:jackson-annotations:2.11.1=classpath +com.fasterxml.jackson.core:jackson-core:2.11.1=classpath +com.fasterxml.jackson.core:jackson-databind:2.11.1=classpath +com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.1=classpath +com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.11.1=classpath +com.fasterxml.jackson.module:jackson-module-kotlin:2.11.1=classpath +com.fasterxml.woodstox:woodstox-core:6.2.1=classpath +com.github.gundy:semver4j:0.16.4=classpath +com.google.android:annotations:4.1.1.4=classpath +com.google.api.grpc:proto-google-common-protos:1.12.0=classpath +com.google.auto.value:auto-value-annotations:1.6.2=classpath +com.google.code.findbugs:jsr305:3.0.2=classpath +com.google.code.gson:gson:2.8.6=classpath +com.google.crypto.tink:tink:1.3.0-rc2=classpath +com.google.dagger:dagger:2.28.3=classpath +com.google.errorprone:error_prone_annotations:2.3.4=classpath +com.google.flatbuffers:flatbuffers-java:1.12.0=classpath +com.google.guava:failureaccess:1.0.1=classpath +com.google.guava:guava:30.1-jre=classpath +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=classpath +com.google.j2objc:j2objc-annotations:1.3=classpath +com.google.jimfs:jimfs:1.1=classpath +com.google.protobuf:protobuf-java-util:3.10.0=classpath +com.google.protobuf:protobuf-java:3.10.0=classpath +com.google.testing.platform:core-proto:0.0.8-alpha07=classpath +com.googlecode.json-simple:json-simple:1.1=classpath +com.googlecode.juniversalchardet:juniversalchardet:1.0.3=classpath +com.squareup:javapoet:1.10.0=classpath +com.squareup:javawriter:2.5.0=classpath +com.sun.activation:javax.activation:1.2.0=classpath +com.sun.istack:istack-commons-runtime:3.0.8=classpath +com.sun.xml.fastinfoset:FastInfoset:1.2.16=classpath +commons-codec:commons-codec:1.11=classpath +commons-io:commons-io:2.4=classpath +commons-logging:commons-logging:1.2=classpath +de.undercouch:gradle-download-task:4.1.1=classpath +io.grpc:grpc-api:1.21.1=classpath +io.grpc:grpc-context:1.21.1=classpath +io.grpc:grpc-core:1.21.1=classpath +io.grpc:grpc-netty:1.21.1=classpath +io.grpc:grpc-protobuf-lite:1.21.1=classpath +io.grpc:grpc-protobuf:1.21.1=classpath +io.grpc:grpc-stub:1.21.1=classpath +io.netty:netty-buffer:4.1.34.Final=classpath +io.netty:netty-codec-http2:4.1.34.Final=classpath +io.netty:netty-codec-http:4.1.34.Final=classpath +io.netty:netty-codec-socks:4.1.34.Final=classpath +io.netty:netty-codec:4.1.34.Final=classpath +io.netty:netty-common:4.1.34.Final=classpath +io.netty:netty-handler-proxy:4.1.34.Final=classpath +io.netty:netty-handler:4.1.34.Final=classpath +io.netty:netty-resolver:4.1.34.Final=classpath +io.netty:netty-transport:4.1.34.Final=classpath +io.opencensus:opencensus-api:0.21.0=classpath +io.opencensus:opencensus-contrib-grpc-metrics:0.21.0=classpath +it.unimi.dsi:fastutil:8.4.0=classpath +jakarta.activation:jakarta.activation-api:1.2.1=classpath +jakarta.xml.bind:jakarta.xml.bind-api:2.3.2=classpath +javax.inject:javax.inject:1=classpath +net.java.dev.jna:jna-platform:5.6.0=classpath +net.java.dev.jna:jna:5.6.0=classpath +net.sf.jopt-simple:jopt-simple:4.9=classpath +net.sf.kxml:kxml2:2.3.0=classpath +org.apache.commons:commons-compress:1.20=classpath +org.apache.httpcomponents:httpclient:4.5.9=classpath +org.apache.httpcomponents:httpcore:4.4.11=classpath +org.apache.httpcomponents:httpmime:4.5.6=classpath +org.bitbucket.b_c:jose4j:0.7.0=classpath +org.bouncycastle:bcpkix-jdk15on:1.56=classpath +org.bouncycastle:bcprov-jdk15on:1.56=classpath +org.checkerframework:checker-qual:3.5.0=classpath +org.codehaus.mojo:animal-sniffer-annotations:1.17=classpath +org.codehaus.woodstox:stax2-api:4.2.1=classpath +org.glassfish.jaxb:jaxb-runtime:2.3.2=classpath +org.glassfish.jaxb:txw2:2.3.2=classpath +org.jdom:jdom2:2.0.6=classpath +org.jetbrains.dokka:dokka-core:1.4.32=classpath +org.jetbrains.intellij.deps:trove4j:1.0.20181211=classpath +org.jetbrains.kotlin:kotlin-android-extensions:1.5.31=classpath +org.jetbrains.kotlin:kotlin-annotation-processing-gradle:1.5.31=classpath +org.jetbrains.kotlin:kotlin-build-common:1.5.31=classpath +org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-compiler-runner:1.5.31=classpath +org.jetbrains.kotlin:kotlin-daemon-client:1.5.31=classpath +org.jetbrains.kotlin:kotlin-daemon-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.5.31=classpath +org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.5.31=classpath +org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31=classpath +org.jetbrains.kotlin:kotlin-klib-commonizer-api:1.5.31=classpath +org.jetbrains.kotlin:kotlin-native-utils:1.5.31=classpath +org.jetbrains.kotlin:kotlin-project-model:1.5.31=classpath +org.jetbrains.kotlin:kotlin-reflect:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-common:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-jvm:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib:1.5.31=classpath +org.jetbrains.kotlin:kotlin-tooling-metadata:1.5.31=classpath +org.jetbrains.kotlin:kotlin-util-io:1.5.31=classpath +org.jetbrains.kotlin:kotlin-util-klib:1.5.31=classpath +org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.0=classpath +org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0=classpath +org.jetbrains:annotations:13.0=classpath +org.jetbrains:markdown-jvm:0.2.1=classpath +org.jetbrains:markdown:0.2.1=classpath +org.json:json:20180813=classpath +org.jsoup:jsoup:1.13.1=classpath +org.jvnet.staxex:stax-ex:1.8.1=classpath +org.ow2.asm:asm-analysis:9.1=classpath +org.ow2.asm:asm-commons:9.1=classpath +org.ow2.asm:asm-tree:9.1=classpath +org.ow2.asm:asm-util:9.1=classpath +org.ow2.asm:asm:9.1=classpath +org.slf4j:slf4j-api:1.7.30=classpath +org.tensorflow:tensorflow-lite-metadata:0.1.0-rc2=classpath +xerces:xercesImpl:2.12.0=classpath +xml-apis:xml-apis:1.4.01=classpath +empty= diff --git a/novelforge-project/agent-workspace/flutter/examples/image_list/android/gradle.properties b/novelforge-project/agent-workspace/flutter/examples/image_list/android/gradle.properties new file mode 100644 index 0000000000000000000000000000000000000000..598d13fee446372f156ecc38527b54c7cdcc8e3b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/image_list/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx4G +android.useAndroidX=true +android.enableJetifier=true diff --git a/novelforge-project/agent-workspace/flutter/examples/image_list/android/project-app.lockfile b/novelforge-project/agent-workspace/flutter/examples/image_list/android/project-app.lockfile new file mode 100644 index 0000000000000000000000000000000000000000..e160a81ffd42a36bca35a414c624786fdac26bc3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/image_list/android/project-app.lockfile @@ -0,0 +1,118 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +androidx.activity:activity:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.annotation:annotation-experimental:1.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.annotation:annotation:1.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.arch.core:core-common:2.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.arch.core:core-runtime:2.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.collection:collection:1.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.core:core:1.6.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.customview:customview:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.fragment:fragment:1.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-common-java8:2.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-common:2.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-livedata-core:2.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-livedata:2.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-runtime:2.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-viewmodel:2.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.loader:loader:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.savedstate:savedstate:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.tracing:tracing:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.versionedparcelable:versionedparcelable:1.1.1=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.viewpager:viewpager:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.window:window-java:1.0.0-beta04=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.window:window:1.0.0-beta04=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +com.android.tools.analytics-library:protos:27.1.3=lintClassPath +com.android.tools.analytics-library:shared:27.1.3=lintClassPath +com.android.tools.analytics-library:tracker:27.1.3=lintClassPath +com.android.tools.build:aapt2-proto:4.1.0-alpha01-6193524=lintClassPath +com.android.tools.build:aapt2:4.1.3-6503028=_internal_aapt2_binary +com.android.tools.build:apksig:4.1.3=lintClassPath +com.android.tools.build:apkzlib:4.1.3=lintClassPath +com.android.tools.build:builder-model:4.1.3=lintClassPath +com.android.tools.build:builder-test-api:4.1.3=lintClassPath +com.android.tools.build:builder:4.1.3=lintClassPath +com.android.tools.build:gradle-api:4.1.3=lintClassPath +com.android.tools.build:manifest-merger:27.1.3=lintClassPath +com.android.tools.ddms:ddmlib:27.1.3=lintClassPath +com.android.tools.external.com-intellij:intellij-core:27.1.3=lintClassPath +com.android.tools.external.com-intellij:kotlin-compiler:27.1.3=lintClassPath +com.android.tools.external.org-jetbrains:uast:27.1.3=lintClassPath +com.android.tools.layoutlib:layoutlib-api:27.1.3=lintClassPath +com.android.tools.lint:lint-api:27.1.3=lintClassPath +com.android.tools.lint:lint-checks:27.1.3=lintClassPath +com.android.tools.lint:lint-gradle-api:27.1.3=lintClassPath +com.android.tools.lint:lint-gradle:27.1.3=lintClassPath +com.android.tools.lint:lint-model:27.1.3=lintClassPath +com.android.tools.lint:lint:27.1.3=lintClassPath +com.android.tools:annotations:27.1.3=lintClassPath +com.android.tools:common:27.1.3=lintClassPath +com.android.tools:dvlib:27.1.3=lintClassPath +com.android.tools:repository:27.1.3=lintClassPath +com.android.tools:sdk-common:27.1.3=lintClassPath +com.android.tools:sdklib:27.1.3=lintClassPath +com.android:signflinger:4.1.3=lintClassPath +com.android:zipflinger:4.1.3=lintClassPath +com.google.code.findbugs:jsr305:3.0.2=lintClassPath +com.google.code.gson:gson:2.8.5=lintClassPath +com.google.errorprone:error_prone_annotations:2.3.2=lintClassPath +com.google.guava:failureaccess:1.0.1=lintClassPath +com.google.guava:guava:28.1-jre=lintClassPath +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=lintClassPath +com.google.j2objc:j2objc-annotations:1.3=lintClassPath +com.google.jimfs:jimfs:1.1=lintClassPath +com.google.protobuf:protobuf-java:3.10.0=lintClassPath +com.googlecode.json-simple:json-simple:1.1=lintClassPath +com.squareup:javawriter:2.5.0=lintClassPath +com.sun.activation:javax.activation:1.2.0=lintClassPath +com.sun.istack:istack-commons-runtime:3.0.7=lintClassPath +com.sun.xml.fastinfoset:FastInfoset:1.2.15=lintClassPath +commons-codec:commons-codec:1.10=lintClassPath +commons-logging:commons-logging:1.2=lintClassPath +it.unimi.dsi:fastutil:7.2.0=lintClassPath +javax.activation:javax.activation-api:1.2.0=lintClassPath +javax.inject:javax.inject:1=lintClassPath +javax.xml.bind:jaxb-api:2.3.1=lintClassPath +net.sf.jopt-simple:jopt-simple:4.9=lintClassPath +net.sf.kxml:kxml2:2.3.0=lintClassPath +org.apache.commons:commons-compress:1.12=lintClassPath +org.apache.httpcomponents:httpclient:4.5.6=lintClassPath +org.apache.httpcomponents:httpcore:4.4.10=lintClassPath +org.apache.httpcomponents:httpmime:4.5.6=lintClassPath +org.bouncycastle:bcpkix-jdk15on:1.56=lintClassPath +org.bouncycastle:bcprov-jdk15on:1.56=lintClassPath +org.checkerframework:checker-qual:2.8.1=lintClassPath +org.codehaus.groovy:groovy-all:2.4.15=lintClassPath +org.codehaus.mojo:animal-sniffer-annotations:1.18=lintClassPath +org.glassfish.jaxb:jaxb-runtime:2.3.1=lintClassPath +org.glassfish.jaxb:txw2:2.3.1=lintClassPath +org.jacoco:org.jacoco.agent:0.8.7=androidJacocoAnt +org.jacoco:org.jacoco.ant:0.8.7=androidJacocoAnt +org.jacoco:org.jacoco.core:0.8.7=androidJacocoAnt +org.jacoco:org.jacoco.report:0.8.7=androidJacocoAnt +org.jetbrains.kotlin:kotlin-reflect:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-common:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.30=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib:1.5.31=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.trove4j:trove4j:20160824=lintClassPath +org.jetbrains:annotations:13.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,lintClassPath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jvnet.staxex:stax-ex:1.8=lintClassPath +org.ow2.asm:asm-analysis:7.0=lintClassPath +org.ow2.asm:asm-analysis:9.1=androidJacocoAnt +org.ow2.asm:asm-commons:7.0=lintClassPath +org.ow2.asm:asm-commons:9.1=androidJacocoAnt +org.ow2.asm:asm-tree:7.0=lintClassPath +org.ow2.asm:asm-tree:9.1=androidJacocoAnt +org.ow2.asm:asm-util:7.0=lintClassPath +org.ow2.asm:asm:7.0=lintClassPath +org.ow2.asm:asm:9.1=androidJacocoAnt +empty=androidApis,androidJdkImage,androidTestUtil,compile,coreLibraryDesugaring,debugAndroidTestAnnotationProcessorClasspath,debugAndroidTestRuntimeClasspath,debugAnnotationProcessorClasspath,debugReverseMetadataValues,debugUnitTestAnnotationProcessorClasspath,debugWearBundling,lintChecks,lintPublish,profileAnnotationProcessorClasspath,profileReverseMetadataValues,profileUnitTestAnnotationProcessorClasspath,profileWearBundling,releaseAnnotationProcessorClasspath,releaseReverseMetadataValues,releaseUnitTestAnnotationProcessorClasspath,releaseWearBundling,testCompile diff --git a/novelforge-project/agent-workspace/flutter/examples/image_list/android/settings.gradle b/novelforge-project/agent-workspace/flutter/examples/image_list/android/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..03ae72d135c01f849e6812b36575b62b14fee791 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/image_list/android/settings.gradle @@ -0,0 +1,21 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is auto generated. +// To update all the settings.gradle files in the Flutter repo, +// See dev/tools/bin/generate_gradle_lockfiles.dart. + +include ':app' + +enableFeaturePreview('ONE_LOCKFILE_PER_PROJECT') + +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() + +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/novelforge-project/agent-workspace/flutter/examples/image_list/images/coast.jpg b/novelforge-project/agent-workspace/flutter/examples/image_list/images/coast.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2a5e7a0f3493de6e7962bc4f91e5fb5b3dbac165 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/image_list/images/coast.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da957fd30c51b8d27d74c2c918692dc4d3c5c99bb00f0d6b5ebb30395a6ede82 +size 202344 diff --git a/novelforge-project/agent-workspace/flutter/examples/image_list/lib/main.dart b/novelforge-project/agent-workspace/flutter/examples/image_list/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..5c7522263baf37f5d7fba819e8a65c3e06625042 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/image_list/lib/main.dart @@ -0,0 +1,244 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:io'; +import 'dart:math'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +/// An example that sets up local http server for serving single +/// image, creates single flutter widget with five copies of requested +/// image and prints how long the loading took. +/// +/// This is used in [$FH/flutter/devicelab/bin/tasks/image_list_reported_duration.dart] test. +/// +/// +/// To generate new certificate: +/// +/// $ openssl req -new -out image_list.csr +/// Generating a 2048 bit RSA private key +/// Enter PEM pass phrase: +/// ... +/// Common Name (eg, fully qualified host name) []:localhost +/// +/// Copy content of the privateKey below into image_list.key file, then +/// $ openssl x509 -req -sha256 -days 3650 -in image_list.csr -signkey image_list.key -out image_list.crt +/// +/// Copy content of the image_list.crt into certificate string below. +String certificate = ''' +-----BEGIN CERTIFICATE----- +MIICpDCCAYwCCQD1kfAz8IhbazANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDDAls +b2NhbGhvc3QwHhcNMjAwODI0MjE1MTUwWhcNMzAwODIyMjE1MTUwWjAUMRIwEAYD +VQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCi +/fmozdYuCIZbJS7y4zYPp2NRboLXrpUcUzzvzz+24k/TYUPNeRvf6wiNXHvr1ijM +g1j3wQP72RphxI7cY7XCwzRiM5QeQy3EtRz4ETYBzOev3mHLLEgZ9RnSq/u42siS +S9CNjoz97liPyQUq8h37/09qhYG0hR/2pRN+YB9g7sNYoGe2B7zkh3azRS0/Ltgl +tXwHUId7QzJc15W9Q7adsNVTpOCo7dOj2KWz6sEtFGkYfwLV5uiTslRdWCCOUD9i +ZjCtlPqALkGnWyhNiFJESLbVNC6MURyMngcALW0JTMwc2oDjMxtdNkMl0cdzPlhX +MDKIKpY9bWbRKUUdsfOnAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAHZo/Io7hE9P +jDhSSP+4iSwx6xjnkRjBHReoea+XwSCv1s9Alwe1Nub6u5jUBhCpGCyU4diKFV1W +zhunXKY+zRGGtr09nYoN9UVizS5fAFb+h2x3Tw8lsxs4JpPQeWTbGK9Ci+jyfuZu +xPvdU8I8oxiTRPoWa1KpPm6UVvcrjyftvbqJ4l7cZ8KZN4JNSZlphX8lIM14xR4H +12sFFTcYWPNDTqO1A9MSflG4OkG59LDHV36JAEqB61pP8hipowVp48+rzD2DVpqb +r/Mw+0x0HENUTMVExSA5rj/3fxNMggUSl2YsujVJjkb1LiQNPORX7rBndcjknAMt +TvaTkrwwZA4= +-----END CERTIFICATE----- +'''; + +String privateKey = ''' +-----BEGIN PRIVATE KEY----- +MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCi/fmozdYuCIZb +JS7y4zYPp2NRboLXrpUcUzzvzz+24k/TYUPNeRvf6wiNXHvr1ijMg1j3wQP72Rph +xI7cY7XCwzRiM5QeQy3EtRz4ETYBzOev3mHLLEgZ9RnSq/u42siSS9CNjoz97liP +yQUq8h37/09qhYG0hR/2pRN+YB9g7sNYoGe2B7zkh3azRS0/LtgltXwHUId7QzJc +15W9Q7adsNVTpOCo7dOj2KWz6sEtFGkYfwLV5uiTslRdWCCOUD9iZjCtlPqALkGn +WyhNiFJESLbVNC6MURyMngcALW0JTMwc2oDjMxtdNkMl0cdzPlhXMDKIKpY9bWbR +KUUdsfOnAgMBAAECggEADUStiS9Qayjofwz02HLkmLugmyVq41Hj841XHZJ6dlHP ++74kPdrJCR5h8NgBgn5JjfR3TpvYziyrOCA/HPPE/RjU79WRDjGbzTKNLCiCg/0B +M1DgFyEAsZRBSOQVNsQgpcAkNxHOqnE3pmTP1eIlzLjI5zv9Bgv8QSDJCHWcuFA2 +NrvGudq3dlFnZwjipx0k0E1hCsaClqLsi5jEXIBA6TX7RTeeXjC+j2/DlmTpBxo0 +c34o/sSoCl+mfJDQ3QApXLFuycBl7nauO0M+VsUWrKYqHHr4NIcgoIpIX28QjWc/ +Y2+iooMSBO1ToK2nPD8hZQwNDF8xz6Xf7QNkTOpnqQKBgQDNgfNYkEvgWxhSMmW7 +cK06supZC/isj2JfQmlJc80JcAvf8rpynZLi4XWZWRo0PykM4szI91h3YHTG27VX +YVHSsFs+6FwP7fLAHR7FYn65p/bwTuqpWGjcmQhc0HWx7y45HRIoSK/m+Z7lNA/J +QxnCp1khTmhPqCNglo+38vZSzQKBgQDLCeBhji0K/BOmCrhNxRxrCvHYEd6gqRtC ++rKhco6mMrxma/UmggRKoGXg0yMcya3199y3pDkumHSlcMdUb+I9b+3j8R6ivoqN +TI1ned5K1uq3FyZpD0dZQWuunVeqYXuUQw5y5GxvK7haohbVpUG6lC3qYq2ubiYC +D0ENUfNoQwKBgEGucOozZCzWsJVEykL4JkWGfWPscZQlV5l+jkwNmNCVYRY4a+LJ +/fJJgN58HeXo8ePOcQkiFMJCr9AG1JSS5CXke6VFencU4+sG45jOfBY2WrQ/ZLyv +JwSqXIPdlGBEQ4+5fN4nLSEzUteKpij7KzaNae09NBWRdY0fUdvG6XdZAoGAf02S +/TfKsB97JlmEU2aqOcdj+WjC4JMG/8j2JVoRbM1U6Rb5X4qXrD7DgeKAGnWteBJP +tmjmXXvDb1O19xArlv/N9WRiJAI6FvwPkPiNUvlLsz51m9uzjZgCLzqCE9cJR91/ +erQT9ORBs7n7fTsfah+sZlA2u65ecF4mGHbwmccCgYAqHNRHnx1iHrYfr97cmXc9 +fNjJ7e1NHhVdgpGjaOiBSKj2rHNRy6iwCNbs5wjmRWlgqnFEM5r0VfFn9L0PvcQK +7iExMTm/PkSqHUntpy82Q8zRWmhw0G5p9DYyIPtaeW1NIKpIlCw6dTlf750BiGkr +mhBKvYQc85gja0s1c+1VXA== +-----END PRIVATE KEY----- +'''; + +class MyHttpOverrides extends HttpOverrides { + @override + HttpClient createHttpClient(SecurityContext? context) { + return super.createHttpClient( + (context ?? SecurityContext())..setTrustedCertificatesBytes(certificate.codeUnits), + ); + } +} + +Future main() async { + HttpOverrides.global = MyHttpOverrides(); + + final SecurityContext serverContext = SecurityContext() + ..useCertificateChainBytes(certificate.codeUnits) + ..usePrivateKeyBytes(privateKey.codeUnits); + + final HttpServer httpServer = + await HttpServer.bindSecure('localhost', 0, serverContext); + final int port = httpServer.port; + debugPrint('Listening on port $port.'); + + // Initializes bindings before using any platform channels. + WidgetsFlutterBinding.ensureInitialized(); + final ByteData byteData = await rootBundle.load('images/coast.jpg'); + httpServer.listen((HttpRequest request) async { + const int chunk_size = 2048; + int offset = byteData.offsetInBytes; + while (offset < byteData.lengthInBytes) { + final int length = min(byteData.lengthInBytes - offset, chunk_size); + final Uint8List bytes = byteData.buffer.asUint8List(offset, length); + offset += length; + request.response.add(bytes); + // Let other isolates and microtasks to run. + await Future.delayed(Duration.zero); + } + request.response.close(); + }); + + runApp(MyApp(port)); +} + +const int images = 50; + +@immutable +class MyApp extends StatelessWidget { + const MyApp(this.port, {super.key}); + + final int port; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: MyHomePage(title: 'Flutter Demo Home Page', port: port), + ); + } +} + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title, required this.port}); + final String title; + final int port; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State with TickerProviderStateMixin { + int _counter = 0; + + void _incrementCounter() { + setState(() { + _counter++; + }); + } + + Widget createImage(final int index, final Completer completer) { + return Image.network( + 'https://localhost:${widget.port}/${_counter * images + index}', + frameBuilder: ( + BuildContext context, + Widget child, + int? frame, + bool wasSynchronouslyLoaded, + ) { + if (frame == 0 && !completer.isCompleted) { + completer.complete(true); + } + return child; + }, + ); + } + + @override + Widget build(BuildContext context) { + final List controllers = [ + for (int i = 0; i < images; i++) + AnimationController( + duration: const Duration(milliseconds: 3600), + vsync: this, + )..repeat(), + ]; + final List> completers = >[ + for (int i = 0; i < images; i++) + Completer(), + ]; + final List> futures = completers.map( + (Completer completer) => completer.future, + ).toList(); + final DateTime started = DateTime.now(); + Future.wait(futures).then((_) { + debugPrint( + '===image_list=== all loaded in ${DateTime.now().difference(started).inMilliseconds}ms.', + ); + }); + return Scaffold( + appBar: AppBar( + title: Text(widget.title), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row(children: createImageList(images, completers, controllers)), + const Text( + 'You have pushed the button this many times:', + ), + Text( + '$_counter', + style: Theme.of(context).textTheme.headlineMedium, + ), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + ); + } + + List createImageList( + int count, + List> completers, + List controllers, + ) { + final List list = []; + for (int i = 0; i < count; i++) { + list.add(Flexible( + fit: FlexFit.tight, + flex: i + 1, + child: RotationTransition( + turns: controllers[i], + child: createImage(i + 1, completers[i]), + ), + )); + } + return list; + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/image_list/pubspec.lock b/novelforge-project/agent-workspace/flutter/examples/image_list/pubspec.lock new file mode 100644 index 0000000000000000000000000000000000000000..00c431571a5c28834859140dafc317710af81d84 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/image_list/pubspec.lock @@ -0,0 +1,196 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: "direct dev" + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: "direct dev" + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: "direct main" + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: "direct dev" + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d + url: "https://pub.dev" + source: hosted + version: "1.0.6" + fake_async: + dependency: "direct dev" + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + leak_tracker: + dependency: "direct dev" + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: "direct dev" + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: "direct dev" + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + matcher: + dependency: "direct dev" + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: "direct main" + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: "direct main" + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + path: + dependency: "direct dev" + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: "direct dev" + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: "direct dev" + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: "direct dev" + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: "direct dev" + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: "direct dev" + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: "direct dev" + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: "direct dev" + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" +sdks: + dart: ">=3.2.0-0 <4.0.0" diff --git a/novelforge-project/agent-workspace/flutter/examples/image_list/pubspec.yaml b/novelforge-project/agent-workspace/flutter/examples/image_list/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8a6d11936ec168f6e17adec464a708e72abcc0b9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/image_list/pubspec.yaml @@ -0,0 +1,60 @@ +name: image_list +description: Simple Flutter project used for benchmarking image loading over network. + +version: 1.0.0+1 + +environment: + sdk: '>=3.2.0-0 <4.0.0' + +dependencies: + flutter: + sdk: flutter + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: 1.0.6 + + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +dev_dependencies: + flutter_test: + sdk: flutter + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter. + + async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker: 10.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_flutter_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + matcher: 0.12.16+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + path: 1.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + assets: + - images/coast.jpg + +# PUBSPEC CHECKSUM: 58cb diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/README.md b/novelforge-project/agent-workspace/flutter/examples/layers/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d888e5e26005522d61afc66b05a701830089afa5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/README.md @@ -0,0 +1,28 @@ +# Examples of Flutter's layered architecture + +This directory contains several self-contained examples that illustrate +Flutter's layered architecture. + + * [*raw/*](raw/) These examples show how to program against the lowest layer of + the system. They manually receive input packets and construct composited + scenes. + + * [*rendering/*](rendering/) These examples use Flutter's render tree to + structure your app using a retained tree of visual objects. These objects + coordinate to determine their size and position on screen and to handle + events. + + * [*widgets/*](widgets/) These examples use Flutter's widgets to build more + elaborate apps using a reactive framework. + + * [*services/*](services/) These examples use services available in Flutter to + interact with the host platform. + +To run each example, specify the demo file on the `flutter run` +command line, for example: + +``` +flutter run raw/spinning_square.dart +flutter run rendering/spinning_square.dart +flutter run widgets/spinning_square.dart +``` diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/analysis_options.yaml b/novelforge-project/agent-workspace/flutter/examples/layers/analysis_options.yaml new file mode 100644 index 0000000000000000000000000000000000000000..76be938a6b861cf3e4c7f00d5aa2469c0c9b2bc4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/analysis_options.yaml @@ -0,0 +1,8 @@ +# This file is also used by dev/bots/analyze_snippet_code.dart to analyze code snippets (`{@tool snippet}` sections). + +include: ../../analysis_options.yaml + +linter: + rules: + # Samples want to print things pretty often. + avoid_print: false diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/android/build.gradle b/novelforge-project/agent-workspace/flutter/examples/layers/android/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..2de20623576a82c3115eca8b1bdb56fd5b5051cb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/android/build.gradle @@ -0,0 +1,51 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is auto generated. +// To update all the build.gradle files in the Flutter repo, +// See dev/tools/bin/generate_gradle_lockfiles.dart. + +buildscript { + ext.kotlin_version = '1.5.31' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.2.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } + + configurations.classpath { + resolutionStrategy.activateDependencyLocking() + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' + +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') + dependencyLocking { + ignoredDependencies.add('io.flutter:*') + lockFile = file("${rootProject.projectDir}/project-${project.name}.lockfile") + if (!project.hasProperty('local-engine-repo')) { + lockAllConfigurations() + } + } +} + +tasks.register("clean", Delete) { + delete rootProject.buildDir +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/android/buildscript-gradle.lockfile b/novelforge-project/agent-workspace/flutter/examples/layers/android/buildscript-gradle.lockfile new file mode 100644 index 0000000000000000000000000000000000000000..efe13277310ee8fef3c9d7f6f8a2cbbe601d110f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/android/buildscript-gradle.lockfile @@ -0,0 +1,163 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +androidx.databinding:databinding-common:7.2.0=classpath +androidx.databinding:databinding-compiler-common:7.2.0=classpath +com.android.databinding:baseLibrary:7.2.0=classpath +com.android.tools.analytics-library:crash:30.2.0=classpath +com.android.tools.analytics-library:protos:30.2.0=classpath +com.android.tools.analytics-library:shared:30.2.0=classpath +com.android.tools.analytics-library:tracker:30.2.0=classpath +com.android.tools.build.jetifier:jetifier-core:1.0.0-beta09=classpath +com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta09=classpath +com.android.tools.build:aapt2-proto:7.2.0-7984345=classpath +com.android.tools.build:aaptcompiler:7.2.0=classpath +com.android.tools.build:apksig:7.2.0=classpath +com.android.tools.build:apkzlib:7.2.0=classpath +com.android.tools.build:builder-model:7.2.0=classpath +com.android.tools.build:builder-test-api:7.2.0=classpath +com.android.tools.build:builder:7.2.0=classpath +com.android.tools.build:bundletool:1.8.2=classpath +com.android.tools.build:gradle-api:7.2.0=classpath +com.android.tools.build:gradle:7.2.0=classpath +com.android.tools.build:manifest-merger:30.2.0=classpath +com.android.tools.build:transform-api:2.0.0-deprecated-use-gradle-api=classpath +com.android.tools.ddms:ddmlib:30.2.0=classpath +com.android.tools.layoutlib:layoutlib-api:30.2.0=classpath +com.android.tools.lint:lint-model:30.2.0=classpath +com.android.tools.lint:lint-typedef-remover:30.2.0=classpath +com.android.tools.utp:android-device-provider-ddmlib-proto:30.2.0=classpath +com.android.tools.utp:android-device-provider-gradle-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-host-additional-test-output-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-host-coverage-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-host-retention-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-result-listener-gradle-proto:30.2.0=classpath +com.android.tools:annotations:30.2.0=classpath +com.android.tools:common:30.2.0=classpath +com.android.tools:dvlib:30.2.0=classpath +com.android.tools:repository:30.2.0=classpath +com.android.tools:sdk-common:30.2.0=classpath +com.android.tools:sdklib:30.2.0=classpath +com.android:signflinger:7.2.0=classpath +com.android:zipflinger:7.2.0=classpath +com.fasterxml.jackson.core:jackson-annotations:2.11.1=classpath +com.fasterxml.jackson.core:jackson-core:2.11.1=classpath +com.fasterxml.jackson.core:jackson-databind:2.11.1=classpath +com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.1=classpath +com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.11.1=classpath +com.fasterxml.jackson.module:jackson-module-kotlin:2.11.1=classpath +com.fasterxml.woodstox:woodstox-core:6.2.1=classpath +com.github.gundy:semver4j:0.16.4=classpath +com.google.android:annotations:4.1.1.4=classpath +com.google.api.grpc:proto-google-common-protos:1.12.0=classpath +com.google.auto.value:auto-value-annotations:1.6.2=classpath +com.google.code.findbugs:jsr305:3.0.2=classpath +com.google.code.gson:gson:2.8.6=classpath +com.google.crypto.tink:tink:1.3.0-rc2=classpath +com.google.dagger:dagger:2.28.3=classpath +com.google.errorprone:error_prone_annotations:2.3.4=classpath +com.google.flatbuffers:flatbuffers-java:1.12.0=classpath +com.google.guava:failureaccess:1.0.1=classpath +com.google.guava:guava:30.1-jre=classpath +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=classpath +com.google.j2objc:j2objc-annotations:1.3=classpath +com.google.jimfs:jimfs:1.1=classpath +com.google.protobuf:protobuf-java-util:3.10.0=classpath +com.google.protobuf:protobuf-java:3.10.0=classpath +com.google.testing.platform:core-proto:0.0.8-alpha07=classpath +com.googlecode.json-simple:json-simple:1.1=classpath +com.googlecode.juniversalchardet:juniversalchardet:1.0.3=classpath +com.squareup:javapoet:1.10.0=classpath +com.squareup:javawriter:2.5.0=classpath +com.sun.activation:javax.activation:1.2.0=classpath +com.sun.istack:istack-commons-runtime:3.0.8=classpath +com.sun.xml.fastinfoset:FastInfoset:1.2.16=classpath +commons-codec:commons-codec:1.11=classpath +commons-io:commons-io:2.4=classpath +commons-logging:commons-logging:1.2=classpath +de.undercouch:gradle-download-task:4.1.1=classpath +io.grpc:grpc-api:1.21.1=classpath +io.grpc:grpc-context:1.21.1=classpath +io.grpc:grpc-core:1.21.1=classpath +io.grpc:grpc-netty:1.21.1=classpath +io.grpc:grpc-protobuf-lite:1.21.1=classpath +io.grpc:grpc-protobuf:1.21.1=classpath +io.grpc:grpc-stub:1.21.1=classpath +io.netty:netty-buffer:4.1.34.Final=classpath +io.netty:netty-codec-http2:4.1.34.Final=classpath +io.netty:netty-codec-http:4.1.34.Final=classpath +io.netty:netty-codec-socks:4.1.34.Final=classpath +io.netty:netty-codec:4.1.34.Final=classpath +io.netty:netty-common:4.1.34.Final=classpath +io.netty:netty-handler-proxy:4.1.34.Final=classpath +io.netty:netty-handler:4.1.34.Final=classpath +io.netty:netty-resolver:4.1.34.Final=classpath +io.netty:netty-transport:4.1.34.Final=classpath +io.opencensus:opencensus-api:0.21.0=classpath +io.opencensus:opencensus-contrib-grpc-metrics:0.21.0=classpath +it.unimi.dsi:fastutil:8.4.0=classpath +jakarta.activation:jakarta.activation-api:1.2.1=classpath +jakarta.xml.bind:jakarta.xml.bind-api:2.3.2=classpath +javax.inject:javax.inject:1=classpath +net.java.dev.jna:jna-platform:5.6.0=classpath +net.java.dev.jna:jna:5.6.0=classpath +net.sf.jopt-simple:jopt-simple:4.9=classpath +net.sf.kxml:kxml2:2.3.0=classpath +org.apache.commons:commons-compress:1.20=classpath +org.apache.httpcomponents:httpclient:4.5.9=classpath +org.apache.httpcomponents:httpcore:4.4.11=classpath +org.apache.httpcomponents:httpmime:4.5.6=classpath +org.bitbucket.b_c:jose4j:0.7.0=classpath +org.bouncycastle:bcpkix-jdk15on:1.56=classpath +org.bouncycastle:bcprov-jdk15on:1.56=classpath +org.checkerframework:checker-qual:3.5.0=classpath +org.codehaus.mojo:animal-sniffer-annotations:1.17=classpath +org.codehaus.woodstox:stax2-api:4.2.1=classpath +org.glassfish.jaxb:jaxb-runtime:2.3.2=classpath +org.glassfish.jaxb:txw2:2.3.2=classpath +org.jdom:jdom2:2.0.6=classpath +org.jetbrains.dokka:dokka-core:1.4.32=classpath +org.jetbrains.intellij.deps:trove4j:1.0.20181211=classpath +org.jetbrains.kotlin:kotlin-android-extensions:1.5.31=classpath +org.jetbrains.kotlin:kotlin-annotation-processing-gradle:1.5.31=classpath +org.jetbrains.kotlin:kotlin-build-common:1.5.31=classpath +org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-compiler-runner:1.5.31=classpath +org.jetbrains.kotlin:kotlin-daemon-client:1.5.31=classpath +org.jetbrains.kotlin:kotlin-daemon-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.5.31=classpath +org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.5.31=classpath +org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31=classpath +org.jetbrains.kotlin:kotlin-klib-commonizer-api:1.5.31=classpath +org.jetbrains.kotlin:kotlin-native-utils:1.5.31=classpath +org.jetbrains.kotlin:kotlin-project-model:1.5.31=classpath +org.jetbrains.kotlin:kotlin-reflect:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-common:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-jvm:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib:1.5.31=classpath +org.jetbrains.kotlin:kotlin-tooling-metadata:1.5.31=classpath +org.jetbrains.kotlin:kotlin-util-io:1.5.31=classpath +org.jetbrains.kotlin:kotlin-util-klib:1.5.31=classpath +org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.0=classpath +org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0=classpath +org.jetbrains:annotations:13.0=classpath +org.jetbrains:markdown-jvm:0.2.1=classpath +org.jetbrains:markdown:0.2.1=classpath +org.json:json:20180813=classpath +org.jsoup:jsoup:1.13.1=classpath +org.jvnet.staxex:stax-ex:1.8.1=classpath +org.ow2.asm:asm-analysis:9.1=classpath +org.ow2.asm:asm-commons:9.1=classpath +org.ow2.asm:asm-tree:9.1=classpath +org.ow2.asm:asm-util:9.1=classpath +org.ow2.asm:asm:9.1=classpath +org.slf4j:slf4j-api:1.7.30=classpath +org.tensorflow:tensorflow-lite-metadata:0.1.0-rc2=classpath +xerces:xercesImpl:2.12.0=classpath +xml-apis:xml-apis:1.4.01=classpath +empty= diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/android/gradle.properties b/novelforge-project/agent-workspace/flutter/examples/layers/android/gradle.properties new file mode 100644 index 0000000000000000000000000000000000000000..598d13fee446372f156ecc38527b54c7cdcc8e3b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx4G +android.useAndroidX=true +android.enableJetifier=true diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/android/project-app.lockfile b/novelforge-project/agent-workspace/flutter/examples/layers/android/project-app.lockfile new file mode 100644 index 0000000000000000000000000000000000000000..e160a81ffd42a36bca35a414c624786fdac26bc3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/android/project-app.lockfile @@ -0,0 +1,118 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +androidx.activity:activity:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.annotation:annotation-experimental:1.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.annotation:annotation:1.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.arch.core:core-common:2.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.arch.core:core-runtime:2.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.collection:collection:1.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.core:core:1.6.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.customview:customview:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.fragment:fragment:1.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-common-java8:2.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-common:2.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-livedata-core:2.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-livedata:2.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-runtime:2.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-viewmodel:2.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.loader:loader:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.savedstate:savedstate:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.tracing:tracing:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.versionedparcelable:versionedparcelable:1.1.1=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.viewpager:viewpager:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.window:window-java:1.0.0-beta04=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.window:window:1.0.0-beta04=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +com.android.tools.analytics-library:protos:27.1.3=lintClassPath +com.android.tools.analytics-library:shared:27.1.3=lintClassPath +com.android.tools.analytics-library:tracker:27.1.3=lintClassPath +com.android.tools.build:aapt2-proto:4.1.0-alpha01-6193524=lintClassPath +com.android.tools.build:aapt2:4.1.3-6503028=_internal_aapt2_binary +com.android.tools.build:apksig:4.1.3=lintClassPath +com.android.tools.build:apkzlib:4.1.3=lintClassPath +com.android.tools.build:builder-model:4.1.3=lintClassPath +com.android.tools.build:builder-test-api:4.1.3=lintClassPath +com.android.tools.build:builder:4.1.3=lintClassPath +com.android.tools.build:gradle-api:4.1.3=lintClassPath +com.android.tools.build:manifest-merger:27.1.3=lintClassPath +com.android.tools.ddms:ddmlib:27.1.3=lintClassPath +com.android.tools.external.com-intellij:intellij-core:27.1.3=lintClassPath +com.android.tools.external.com-intellij:kotlin-compiler:27.1.3=lintClassPath +com.android.tools.external.org-jetbrains:uast:27.1.3=lintClassPath +com.android.tools.layoutlib:layoutlib-api:27.1.3=lintClassPath +com.android.tools.lint:lint-api:27.1.3=lintClassPath +com.android.tools.lint:lint-checks:27.1.3=lintClassPath +com.android.tools.lint:lint-gradle-api:27.1.3=lintClassPath +com.android.tools.lint:lint-gradle:27.1.3=lintClassPath +com.android.tools.lint:lint-model:27.1.3=lintClassPath +com.android.tools.lint:lint:27.1.3=lintClassPath +com.android.tools:annotations:27.1.3=lintClassPath +com.android.tools:common:27.1.3=lintClassPath +com.android.tools:dvlib:27.1.3=lintClassPath +com.android.tools:repository:27.1.3=lintClassPath +com.android.tools:sdk-common:27.1.3=lintClassPath +com.android.tools:sdklib:27.1.3=lintClassPath +com.android:signflinger:4.1.3=lintClassPath +com.android:zipflinger:4.1.3=lintClassPath +com.google.code.findbugs:jsr305:3.0.2=lintClassPath +com.google.code.gson:gson:2.8.5=lintClassPath +com.google.errorprone:error_prone_annotations:2.3.2=lintClassPath +com.google.guava:failureaccess:1.0.1=lintClassPath +com.google.guava:guava:28.1-jre=lintClassPath +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=lintClassPath +com.google.j2objc:j2objc-annotations:1.3=lintClassPath +com.google.jimfs:jimfs:1.1=lintClassPath +com.google.protobuf:protobuf-java:3.10.0=lintClassPath +com.googlecode.json-simple:json-simple:1.1=lintClassPath +com.squareup:javawriter:2.5.0=lintClassPath +com.sun.activation:javax.activation:1.2.0=lintClassPath +com.sun.istack:istack-commons-runtime:3.0.7=lintClassPath +com.sun.xml.fastinfoset:FastInfoset:1.2.15=lintClassPath +commons-codec:commons-codec:1.10=lintClassPath +commons-logging:commons-logging:1.2=lintClassPath +it.unimi.dsi:fastutil:7.2.0=lintClassPath +javax.activation:javax.activation-api:1.2.0=lintClassPath +javax.inject:javax.inject:1=lintClassPath +javax.xml.bind:jaxb-api:2.3.1=lintClassPath +net.sf.jopt-simple:jopt-simple:4.9=lintClassPath +net.sf.kxml:kxml2:2.3.0=lintClassPath +org.apache.commons:commons-compress:1.12=lintClassPath +org.apache.httpcomponents:httpclient:4.5.6=lintClassPath +org.apache.httpcomponents:httpcore:4.4.10=lintClassPath +org.apache.httpcomponents:httpmime:4.5.6=lintClassPath +org.bouncycastle:bcpkix-jdk15on:1.56=lintClassPath +org.bouncycastle:bcprov-jdk15on:1.56=lintClassPath +org.checkerframework:checker-qual:2.8.1=lintClassPath +org.codehaus.groovy:groovy-all:2.4.15=lintClassPath +org.codehaus.mojo:animal-sniffer-annotations:1.18=lintClassPath +org.glassfish.jaxb:jaxb-runtime:2.3.1=lintClassPath +org.glassfish.jaxb:txw2:2.3.1=lintClassPath +org.jacoco:org.jacoco.agent:0.8.7=androidJacocoAnt +org.jacoco:org.jacoco.ant:0.8.7=androidJacocoAnt +org.jacoco:org.jacoco.core:0.8.7=androidJacocoAnt +org.jacoco:org.jacoco.report:0.8.7=androidJacocoAnt +org.jetbrains.kotlin:kotlin-reflect:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-common:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.30=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib:1.5.31=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.trove4j:trove4j:20160824=lintClassPath +org.jetbrains:annotations:13.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,lintClassPath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jvnet.staxex:stax-ex:1.8=lintClassPath +org.ow2.asm:asm-analysis:7.0=lintClassPath +org.ow2.asm:asm-analysis:9.1=androidJacocoAnt +org.ow2.asm:asm-commons:7.0=lintClassPath +org.ow2.asm:asm-commons:9.1=androidJacocoAnt +org.ow2.asm:asm-tree:7.0=lintClassPath +org.ow2.asm:asm-tree:9.1=androidJacocoAnt +org.ow2.asm:asm-util:7.0=lintClassPath +org.ow2.asm:asm:7.0=lintClassPath +org.ow2.asm:asm:9.1=androidJacocoAnt +empty=androidApis,androidJdkImage,androidTestUtil,compile,coreLibraryDesugaring,debugAndroidTestAnnotationProcessorClasspath,debugAndroidTestRuntimeClasspath,debugAnnotationProcessorClasspath,debugReverseMetadataValues,debugUnitTestAnnotationProcessorClasspath,debugWearBundling,lintChecks,lintPublish,profileAnnotationProcessorClasspath,profileReverseMetadataValues,profileUnitTestAnnotationProcessorClasspath,profileWearBundling,releaseAnnotationProcessorClasspath,releaseReverseMetadataValues,releaseUnitTestAnnotationProcessorClasspath,releaseWearBundling,testCompile diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/android/settings.gradle b/novelforge-project/agent-workspace/flutter/examples/layers/android/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..03ae72d135c01f849e6812b36575b62b14fee791 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/android/settings.gradle @@ -0,0 +1,21 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is auto generated. +// To update all the settings.gradle files in the Flutter repo, +// See dev/tools/bin/generate_gradle_lockfiles.dart. + +include ':app' + +enableFeaturePreview('ONE_LOCKFILE_PER_PROJECT') + +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() + +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/layers.iml b/novelforge-project/agent-workspace/flutter/examples/layers/layers.iml new file mode 100644 index 0000000000000000000000000000000000000000..1d83ed3abc9085f991ca3f8f864f38df5577a8a6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/layers.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/lib/main.dart b/novelforge-project/agent-workspace/flutter/examples/layers/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..7b09b8be6fabab51671af31064a00a371a85b407 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/lib/main.dart @@ -0,0 +1,16 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +void main() { + runApp( + const Center( + child: Text( + 'Instead run:\nflutter run xxx/yyy.dart', + textDirection: TextDirection.ltr, + ), + ), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/linux/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/layers/linux/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a240ba4342260ddf581a360ffb909fb1cdd928d4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/linux/CMakeLists.txt @@ -0,0 +1,139 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.10) +project(runner LANGUAGES CXX) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "layers") +# The unique GTK application identifier for this application. See: +# https://wiki.gnome.org/HowDoI/ChooseApplicationID +set(APPLICATION_ID "io.flutter.examples.layers") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(SET CMP0063 NEW) + +# Load bundled libraries from the lib/ directory relative to the binary. +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Root filesystem for cross-building. +if(FLUTTER_TARGET_PLATFORM_SYSROOT) + set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endif() + +# Define build configuration options. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") +endif() + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_14) + target_compile_options(${TARGET} PRIVATE -Wall -Werror) + target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) + +add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") + +# Define the application target. To change its name, change BINARY_NAME above, +# not the value here, or `flutter run` will no longer work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} + "main.cc" + "my_application.cc" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add dependency libraries. Add any application-specific dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) + +# Only the install-generated bundle's copy of the executable will launch +# correctly, since the resources must in the right relative locations. To avoid +# people trying to run the unbundled copy, put it in a subdirectory instead of +# the default top-level location. +set_target_properties(${BINARY_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" +) + + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# By default, "installing" just makes a relocatable bundle in the build +# directory. +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +# Start with a clean build bundle directory every time. +install(CODE " + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") + " COMPONENT Runtime) + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) + install(FILES "${bundled_library}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endforeach(bundled_library) + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/linux/main.cc b/novelforge-project/agent-workspace/flutter/examples/layers/linux/main.cc new file mode 100644 index 0000000000000000000000000000000000000000..281a29e16b599a95421e7a35112eda77900ff549 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/linux/main.cc @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "my_application.h" + +int main(int argc, char** argv) { + g_autoptr(MyApplication) app = my_application_new(); + return g_application_run(G_APPLICATION(app), argc, argv); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/linux/my_application.cc b/novelforge-project/agent-workspace/flutter/examples/layers/linux/my_application.cc new file mode 100644 index 0000000000000000000000000000000000000000..dde28c955a6e7e2528aad21870d8f6dba83f6375 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/linux/my_application.cc @@ -0,0 +1,108 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "my_application.h" + +#include +#ifdef GDK_WINDOWING_X11 +#include +#endif + +#include "flutter/generated_plugin_registrant.h" + +struct _MyApplication { + GtkApplication parent_instance; + char** dart_entrypoint_arguments; +}; + +G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) + +// Implements GApplication::activate. +static void my_application_activate(GApplication* application) { + MyApplication* self = MY_APPLICATION(application); + GtkWindow* window = + GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + + // Use a header bar when running in GNOME as this is the common style used + // by applications and is the setup most users will be using (e.g. Ubuntu + // desktop). + // If running on X and not using GNOME then just use a traditional title bar + // in case the window manager does more exotic layout, e.g. tiling. + // If running on Wayland assume the header bar will work (may need changing + // if future cases occur). + gboolean use_header_bar = TRUE; +#ifdef GDK_WINDOWING_X11 + GdkScreen* screen = gtk_window_get_screen(window); + if (GDK_IS_X11_SCREEN(screen)) { + const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); + if (g_strcmp0(wm_name, "GNOME Shell") != 0) { + use_header_bar = FALSE; + } + } +#endif + if (use_header_bar) { + GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + gtk_widget_show(GTK_WIDGET(header_bar)); + gtk_header_bar_set_title(header_bar, "layers"); + gtk_header_bar_set_show_close_button(header_bar, TRUE); + gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); + } else { + gtk_window_set_title(window, "layers"); + } + + gtk_window_set_default_size(window, 1280, 720); + gtk_widget_show(GTK_WIDGET(window)); + + g_autoptr(FlDartProject) project = fl_dart_project_new(); + fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); + + FlView* view = fl_view_new(project); + gtk_widget_show(GTK_WIDGET(view)); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); + + fl_register_plugins(FL_PLUGIN_REGISTRY(view)); + + gtk_widget_grab_focus(GTK_WIDGET(view)); +} + +// Implements GApplication::local_command_line. +static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { + MyApplication* self = MY_APPLICATION(application); + // Strip out the first argument as it is the binary name. + self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); + + g_autoptr(GError) error = nullptr; + if (!g_application_register(application, nullptr, &error)) { + g_warning("Failed to register: %s", error->message); + *exit_status = 1; + return TRUE; + } + + g_application_activate(application); + *exit_status = 0; + + return TRUE; +} + +// Implements GObject::dispose. +static void my_application_dispose(GObject* object) { + MyApplication* self = MY_APPLICATION(object); + g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); + G_OBJECT_CLASS(my_application_parent_class)->dispose(object); +} + +static void my_application_class_init(MyApplicationClass* klass) { + G_APPLICATION_CLASS(klass)->activate = my_application_activate; + G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; + G_OBJECT_CLASS(klass)->dispose = my_application_dispose; +} + +static void my_application_init(MyApplication* self) {} + +MyApplication* my_application_new() { + return MY_APPLICATION(g_object_new(my_application_get_type(), + "application-id", APPLICATION_ID, + "flags", G_APPLICATION_NON_UNIQUE, + nullptr)); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/linux/my_application.h b/novelforge-project/agent-workspace/flutter/examples/layers/linux/my_application.h new file mode 100644 index 0000000000000000000000000000000000000000..8c66ec485434d1f922c9915bdaefcb8969cdfec9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/linux/my_application.h @@ -0,0 +1,22 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_MY_APPLICATION_H_ +#define FLUTTER_MY_APPLICATION_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, + GtkApplication) + +/** + * my_application_new: + * + * Creates a new Flutter-based application. + * + * Returns: a new #MyApplication. + */ +MyApplication* my_application_new(); + +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/pubspec.lock b/novelforge-project/agent-workspace/flutter/examples/layers/pubspec.lock new file mode 100644 index 0000000000000000000000000000000000000000..2d3f6c8c4454cc1d7407a2d0755161ed06822cc8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/pubspec.lock @@ -0,0 +1,188 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: "direct dev" + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: "direct dev" + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: "direct main" + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: "direct dev" + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + fake_async: + dependency: "direct dev" + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + leak_tracker: + dependency: "direct dev" + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: "direct dev" + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: "direct dev" + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + matcher: + dependency: "direct dev" + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: "direct main" + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: "direct main" + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + path: + dependency: "direct dev" + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: "direct dev" + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: "direct dev" + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: "direct dev" + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: "direct dev" + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: "direct dev" + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: "direct dev" + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: "direct dev" + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" +sdks: + dart: ">=3.2.0-0 <4.0.0" diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/pubspec.yaml b/novelforge-project/agent-workspace/flutter/examples/layers/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2b42be330691a33a13b524c9910a5a41bb396298 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/pubspec.yaml @@ -0,0 +1,42 @@ +name: flutter_examples_layers + +environment: + sdk: '>=3.2.0-0 <4.0.0' + +dependencies: + flutter: + sdk: flutter + + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +dev_dependencies: + flutter_test: + sdk: flutter + + async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker: 10.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_flutter_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + matcher: 0.12.16+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + path: 1.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +flutter: + assets: + - services/data.json + uses-material-design: true + +# PUBSPEC CHECKSUM: 8023 diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/raw/canvas.dart b/novelforge-project/agent-workspace/flutter/examples/layers/raw/canvas.dart new file mode 100644 index 0000000000000000000000000000000000000000..8af0ca2fd47b2a2c3a950f7a0fc1ef8360e7fd89 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/raw/canvas.dart @@ -0,0 +1,135 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to use the ui.Canvas interface to draw various shapes +// with gradients and transforms. + +import 'dart:math' as math; +import 'dart:typed_data'; +import 'dart:ui' as ui; + +// The FlutterView into which this example will draw; set in the main method. +late final ui.FlutterView view; + +ui.Picture paint(ui.Rect paintBounds) { + // First we create a PictureRecorder to record the commands we're going to + // feed in the canvas. The PictureRecorder will eventually produce a Picture, + // which is an immutable record of those commands. + final ui.PictureRecorder recorder = ui.PictureRecorder(); + + // Next, we create a canvas from the recorder. The canvas is an interface + // which can receive drawing commands. The canvas interface is modeled after + // the SkCanvas interface from Skia. The paintBounds establishes a "cull rect" + // for the canvas, which lets the implementation discard any commands that + // are entirely outside this rectangle. + final ui.Canvas canvas = ui.Canvas(recorder, paintBounds); + + final ui.Paint paint = ui.Paint(); + canvas.drawPaint(ui.Paint()..color = const ui.Color(0xFFFFFFFF)); + + final ui.Size size = paintBounds.size; + final ui.Offset mid = size.center(ui.Offset.zero); + final double radius = size.shortestSide / 2.0; + + final double devicePixelRatio = view.devicePixelRatio; + final ui.Size logicalSize = view.physicalSize / devicePixelRatio; + + // Saves a copy of current transform onto the save stack. + canvas.save(); + + // Transforms that occur after this point apply only to the + // yellow-bluish rectangle. + + // This line will cause the transform to shift entirely outside the paint + // boundaries, which will cause the canvas interface to discard its + // commands. Comment it out to see it on screen. + canvas.translate(-mid.dx / 2.0, logicalSize.height * 2.0); + + // Clips the current transform. + canvas.clipRect( + ui.Rect.fromLTRB(0, radius + 50, logicalSize.width, logicalSize.height), + clipOp: ui.ClipOp.difference, + ); + + // Shifts the coordinate space of and rotates the current transform. + canvas.translate(mid.dx, mid.dy); + canvas.rotate(math.pi/4); + + final ui.Gradient yellowBlue = ui.Gradient.linear( + ui.Offset(-radius, -radius), + ui.Offset.zero, + [const ui.Color(0xFFFFFF00), const ui.Color(0xFF0000FF)], + ); + + // Draws a yellow-bluish rectangle. + canvas.drawRect( + ui.Rect.fromLTRB(-radius, -radius, radius, radius), + ui.Paint()..shader = yellowBlue, + ); + + // Transforms that occur after this point apply only to the + // yellow circle. + + // Scale x and y by 0.5. + final Float64List scaleMatrix = Float64List.fromList([ + 0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0, + ]); + canvas.transform(scaleMatrix); + + // Sets paint to transparent yellow. + paint.color = const ui.Color.fromARGB(128, 0, 255, 0); + + // Draws a transparent yellow circle. + canvas.drawCircle(ui.Offset.zero, radius, paint); + + // Restores the transform from before `save` was called. + canvas.restore(); + + // Sets paint to transparent red. + paint.color = const ui.Color.fromARGB(128, 255, 0, 0); + + // This circle is drawn on top of the previous layer that contains + // the rectangle and smaller circle. + canvas.drawCircle(const ui.Offset(150.0, 300.0), radius, paint); + + // When we're done issuing painting commands, we end the recording and receive + // a Picture, which is an immutable record of the commands we've issued. You + // can draw a Picture into another canvas or include it as part of a + // composited scene. + return recorder.endRecording(); +} + +ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) { + final double devicePixelRatio = view.devicePixelRatio; + final Float64List deviceTransform = Float64List(16) + ..[0] = devicePixelRatio + ..[5] = devicePixelRatio + ..[10] = 1.0 + ..[15] = 1.0; + final ui.SceneBuilder sceneBuilder = ui.SceneBuilder() + ..pushTransform(deviceTransform) + ..addPicture(ui.Offset.zero, picture) + ..pop(); + return sceneBuilder.build(); +} + +void beginFrame(Duration timeStamp) { + final ui.Rect paintBounds = ui.Offset.zero & (view.physicalSize / view.devicePixelRatio); + final ui.Picture picture = paint(paintBounds); + final ui.Scene scene = composite(picture, paintBounds); + view.render(scene); +} + +void main() { + // TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into. + assert(ui.PlatformDispatcher.instance.implicitView != null); + view = ui.PlatformDispatcher.instance.implicitView!; + + ui.PlatformDispatcher.instance + ..onBeginFrame = beginFrame + ..scheduleFrame(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/raw/hello_world.dart b/novelforge-project/agent-workspace/flutter/examples/layers/raw/hello_world.dart new file mode 100644 index 0000000000000000000000000000000000000000..e0a24c3fcd348418fb9adba74e60d47dc8874d82 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/raw/hello_world.dart @@ -0,0 +1,57 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to show the text 'Hello, world.' using the raw +// interface to the engine. + +import 'dart:ui' as ui; + +// The FlutterView into which this example will draw; set in the main method. +late final ui.FlutterView view; + +void beginFrame(Duration timeStamp) { + final double devicePixelRatio = view.devicePixelRatio; + final ui.Size logicalSize = view.physicalSize / devicePixelRatio; + + final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder( + ui.ParagraphStyle(textDirection: ui.TextDirection.ltr), + ) + ..addText('Hello, world.'); + final ui.Paragraph paragraph = paragraphBuilder.build() + ..layout(ui.ParagraphConstraints(width: logicalSize.width)); + + final ui.Rect physicalBounds = ui.Offset.zero & (logicalSize * devicePixelRatio); + final ui.PictureRecorder recorder = ui.PictureRecorder(); + final ui.Canvas canvas = ui.Canvas(recorder, physicalBounds); + canvas.scale(devicePixelRatio, devicePixelRatio); + canvas.drawParagraph(paragraph, ui.Offset( + (logicalSize.width - paragraph.maxIntrinsicWidth) / 2.0, + (logicalSize.height - paragraph.height) / 2.0, + )); + final ui.Picture picture = recorder.endRecording(); + + final ui.SceneBuilder sceneBuilder = ui.SceneBuilder() + // TODO(abarth): We should be able to add a picture without pushing a + // container layer first. + ..pushClipRect(physicalBounds) + ..addPicture(ui.Offset.zero, picture) + ..pop(); + + view.render(sceneBuilder.build()); +} + +// This function is the primary entry point to your application. The engine +// calls main() as soon as it has loaded your code. +void main() { + // TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into. + assert(ui.PlatformDispatcher.instance.implicitView != null); + view = ui.PlatformDispatcher.instance.implicitView!; + + // The engine calls onBeginFrame whenever it wants us to produce a frame. + ui.PlatformDispatcher.instance.onBeginFrame = beginFrame; + // Here we kick off the whole process by asking the engine to schedule a new + // frame. The engine will eventually call onBeginFrame when it is time for us + // to actually produce the frame. + ui.PlatformDispatcher.instance.scheduleFrame(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/raw/spinning_square.dart b/novelforge-project/agent-workspace/flutter/examples/layers/raw/spinning_square.dart new file mode 100644 index 0000000000000000000000000000000000000000..df8515ca646685024b3a32304e87cc52a8a423ba --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/raw/spinning_square.dart @@ -0,0 +1,69 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to perform a simple animation using the raw interface +// to the engine. + +import 'dart:math' as math; +import 'dart:typed_data'; +import 'dart:ui' as ui; + +// The FlutterView into which this example will draw; set in the main method. +late final ui.FlutterView view; + +void beginFrame(Duration timeStamp) { + // The timeStamp argument to beginFrame indicates the timing information we + // should use to clock our animations. It's important to use timeStamp rather + // than reading the system time because we want all the parts of the system to + // coordinate the timings of their animations. If each component read the + // system clock independently, the animations that we processed later would be + // slightly ahead of the animations we processed earlier. + + // PAINT + + final ui.Rect paintBounds = ui.Offset.zero & (view.physicalSize / view.devicePixelRatio); + final ui.PictureRecorder recorder = ui.PictureRecorder(); + final ui.Canvas canvas = ui.Canvas(recorder, paintBounds); + canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0); + + // Here we determine the rotation according to the timeStamp given to us by + // the engine. + final double t = timeStamp.inMicroseconds / Duration.microsecondsPerMillisecond / 1800.0; + canvas.rotate(math.pi * (t % 1.0)); + + canvas.drawRect( + const ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0), + ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0), + ); + final ui.Picture picture = recorder.endRecording(); + + // COMPOSITE + + final double devicePixelRatio = view.devicePixelRatio; + final Float64List deviceTransform = Float64List(16) + ..[0] = devicePixelRatio + ..[5] = devicePixelRatio + ..[10] = 1.0 + ..[15] = 1.0; + final ui.SceneBuilder sceneBuilder = ui.SceneBuilder() + ..pushTransform(deviceTransform) + ..addPicture(ui.Offset.zero, picture) + ..pop(); + view.render(sceneBuilder.build()); + + // After rendering the current frame of the animation, we ask the engine to + // schedule another frame. The engine will call beginFrame again when its time + // to produce the next frame. + ui.PlatformDispatcher.instance.scheduleFrame(); +} + +void main() { + // TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into. + assert(ui.PlatformDispatcher.instance.implicitView != null); + view = ui.PlatformDispatcher.instance.implicitView!; + + ui.PlatformDispatcher.instance + ..onBeginFrame = beginFrame + ..scheduleFrame(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/raw/text.dart b/novelforge-project/agent-workspace/flutter/examples/layers/raw/text.dart new file mode 100644 index 0000000000000000000000000000000000000000..616e8fa75ad75a299d92955f629c99be43ece5ba --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/raw/text.dart @@ -0,0 +1,102 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to draw some bi-directional text using the raw +// interface to the engine. + +import 'dart:typed_data'; +import 'dart:ui' as ui; + +// The FlutterView into which this example will draw; set in the main method. +late final ui.FlutterView view; + +// A paragraph represents a rectangular region that contains some text. +late ui.Paragraph paragraph; + +ui.Picture paint(ui.Rect paintBounds) { + final ui.PictureRecorder recorder = ui.PictureRecorder(); + final ui.Canvas canvas = ui.Canvas(recorder, paintBounds); + + final double devicePixelRatio = view.devicePixelRatio; + final ui.Size logicalSize = view.physicalSize / devicePixelRatio; + + canvas.translate(logicalSize.width / 2.0, logicalSize.height / 2.0); + canvas.drawRect( + const ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0), + ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0), + ); + + // The paint method of Paragraph draws the contents of the paragraph onto the + // given canvas. + canvas.drawParagraph(paragraph, ui.Offset(-paragraph.width / 2.0, (paragraph.width / 2.0) - 125.0)); + + return recorder.endRecording(); +} + +ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) { + final double devicePixelRatio = view.devicePixelRatio; + final Float64List deviceTransform = Float64List(16) + ..[0] = devicePixelRatio + ..[5] = devicePixelRatio + ..[10] = 1.0 + ..[15] = 1.0; + final ui.SceneBuilder sceneBuilder = ui.SceneBuilder() + ..pushTransform(deviceTransform) + ..addPicture(ui.Offset.zero, picture) + ..pop(); + return sceneBuilder.build(); +} + +void beginFrame(Duration timeStamp) { + final ui.Rect paintBounds = ui.Offset.zero & (view.physicalSize / view.devicePixelRatio); + final ui.Picture picture = paint(paintBounds); + final ui.Scene scene = composite(picture, paintBounds); + view.render(scene); +} + +void main() { + // TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into. + assert(ui.PlatformDispatcher.instance.implicitView != null); + view = ui.PlatformDispatcher.instance.implicitView!; + + // To create a paragraph of text, we use ParagraphBuilder. + final ui.ParagraphBuilder builder = ui.ParagraphBuilder( + // The text below has a primary direction of left-to-right. + // The embedded text has other directions. + // If this was TextDirection.rtl, the "Hello, world" text would end up on + // the other side of the right-to-left text. + ui.ParagraphStyle(textDirection: ui.TextDirection.ltr), + ) + // We first push a style that turns the text blue. + ..pushStyle(ui.TextStyle(color: const ui.Color(0xFF0000FF))) + ..addText('Hello, ') + // The next run of text will be bold. + ..pushStyle(ui.TextStyle(fontWeight: ui.FontWeight.bold)) + ..addText('world. ') + // The pop() command signals the end of the bold styling. + ..pop() + // We add text to the paragraph in logical order. The paragraph object + // understands bi-directional text and will compute the visual ordering + // during layout. + ..addText('هذا هو قليلا طويلة من النص الذي يجب التفاف .') + // The second pop() removes the blue color. + ..pop() + // We can add more text with the default styling. + ..addText(' و أكثر قليلا لجعله أطول. ') + ..addText('สวัสดี'); + // When we're done adding styles and text, we build the Paragraph object, at + // which time we can apply styling that affects the entire paragraph, such as + // left, right, or center alignment. Once built, the contents of the paragraph + // cannot be altered, but sizing and positioning information can be updated. + paragraph = builder.build() + // Next, we supply a width that the text is permitted to occupy and we ask + // the paragraph to the visual position of each its glyphs as well as its + // overall size, subject to its sizing constraints. + ..layout(const ui.ParagraphConstraints(width: 180.0)); + + // Finally, we register our beginFrame callback and kick off the first frame. + ui.PlatformDispatcher.instance + ..onBeginFrame = beginFrame + ..scheduleFrame(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/raw/touch_input.dart b/novelforge-project/agent-workspace/flutter/examples/layers/raw/touch_input.dart new file mode 100644 index 0000000000000000000000000000000000000000..cd83f4ee61d829cb892aa15f2fd49aa8a446937e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/raw/touch_input.dart @@ -0,0 +1,122 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to put some pixels on the screen using the raw +// interface to the engine. + +import 'dart:typed_data'; +import 'dart:ui' as ui; + +// The FlutterView into which this example will draw; set in the main method. +late final ui.FlutterView view; + +late ui.Color color; + +ui.Picture paint(ui.Rect paintBounds) { + // First we create a PictureRecorder to record the commands we're going to + // feed in the canvas. The PictureRecorder will eventually produce a Picture, + // which is an immutable record of those commands. + final ui.PictureRecorder recorder = ui.PictureRecorder(); + + // Next, we create a canvas from the recorder. The canvas is an interface + // which can receive drawing commands. The canvas interface is modeled after + // the SkCanvas interface from Skia. The paintBounds establishes a "cull rect" + // for the canvas, which lets the implementation discard any commands that + // are entirely outside this rectangle. + final ui.Canvas canvas = ui.Canvas(recorder, paintBounds); + + // The commands draw a circle in the center of the screen. + final ui.Size size = paintBounds.size; + canvas.drawCircle( + size.center(ui.Offset.zero), + size.shortestSide * 0.45, + ui.Paint()..color = color, + ); + + // When we're done issuing painting commands, we end the recording an receive + // a Picture, which is an immutable record of the commands we've issued. You + // can draw a Picture into another canvas or include it as part of a + // composited scene. + return recorder.endRecording(); +} + +ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) { + // The device pixel ratio gives an approximate ratio of the size of pixels on + // the device's screen to "normal" sized pixels. We commonly work in logical + // pixels, which are then scaled by the device pixel ratio before being drawn + // on the screen. + final double devicePixelRatio = view.devicePixelRatio; + + // This transform scales the x and y coordinates by the devicePixelRatio. + final Float64List deviceTransform = Float64List(16) + ..[0] = devicePixelRatio + ..[5] = devicePixelRatio + ..[10] = 1.0 + ..[15] = 1.0; + + // We build a very simple scene graph with two nodes. The root node is a + // transform that scale its children by the device pixel ratio. This transform + // lets us paint in "logical" pixels which are converted to device pixels by + // this scaling operation. + final ui.SceneBuilder sceneBuilder = ui.SceneBuilder() + ..pushTransform(deviceTransform) + ..addPicture(ui.Offset.zero, picture) + ..pop(); + + // When we're done recording the scene, we call build() to obtain an immutable + // record of the scene we've recorded. + return sceneBuilder.build(); +} + +void beginFrame(Duration timeStamp) { + final ui.Rect paintBounds = ui.Offset.zero & (view.physicalSize / view.devicePixelRatio); + // First, record a picture with our painting commands. + final ui.Picture picture = paint(paintBounds); + // Second, include that picture in a scene graph. + final ui.Scene scene = composite(picture, paintBounds); + // Third, instruct the engine to render that scene graph. + view.render(scene); +} + +void handlePointerDataPacket(ui.PointerDataPacket packet) { + // The pointer packet contains a number of pointer movements, which we iterate + // through and process. + for (final ui.PointerData datum in packet.data) { + if (datum.change == ui.PointerChange.down) { + // If the pointer went down, we change the color of the circle to blue. + color = const ui.Color(0xFF0000FF); + // Rather than calling paint() synchronously, we ask the engine to + // schedule a frame. The engine will call onBeginFrame when it is actually + // time to produce the frame. + ui.PlatformDispatcher.instance.scheduleFrame(); + } else if (datum.change == ui.PointerChange.up) { + // Similarly, if the pointer went up, we change the color of the circle to + // green and schedule a frame. It's harmless to call scheduleFrame many + // times because the engine will ignore redundant requests up until the + // point where the engine calls onBeginFrame, which signals the boundary + // between one frame and another. + color = const ui.Color(0xFF00FF00); + ui.PlatformDispatcher.instance.scheduleFrame(); + } + } +} + +// This function is the primary entry point to your application. The engine +// calls main() as soon as it has loaded your code. +void main() { + // TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into. + assert(ui.PlatformDispatcher.instance.implicitView != null); + view = ui.PlatformDispatcher.instance.implicitView!; + + color = const ui.Color(0xFF00FF00); + // The engine calls onBeginFrame whenever it wants us to produce a frame. + ui.PlatformDispatcher.instance.onBeginFrame = beginFrame; + // The engine calls onPointerDataPacket whenever it had updated information + // about the pointers directed at our app. + ui.PlatformDispatcher.instance.onPointerDataPacket = handlePointerDataPacket; + // Here we kick off the whole process by asking the engine to schedule a new + // frame. The engine will eventually call onBeginFrame when it is time for us + // to actually produce the frame. + ui.PlatformDispatcher.instance.scheduleFrame(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/rendering/custom_coordinate_systems.dart b/novelforge-project/agent-workspace/flutter/examples/layers/rendering/custom_coordinate_systems.dart new file mode 100644 index 0000000000000000000000000000000000000000..d7fd16186e5d08010e2b05b1eed0c21a471e1a56 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/rendering/custom_coordinate_systems.dart @@ -0,0 +1,26 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to build a render tree with a non-cartesian coordinate +// system. Most of the guts of this examples are in src/sector_layout.dart. + +import 'package:flutter/rendering.dart'; +import 'src/binding.dart'; +import 'src/sector_layout.dart'; + +RenderBox buildSectorExample() { + final RenderSectorRing rootCircle = RenderSectorRing(padding: 20.0); + rootCircle.add(RenderSolidColor(const Color(0xFF00FFFF), desiredDeltaTheta: kTwoPi * 0.15)); + rootCircle.add(RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta: kTwoPi * 0.4)); + final RenderSectorSlice stack = RenderSectorSlice(padding: 2.0); + stack.add(RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20.0)); + stack.add(RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20.0)); + stack.add(RenderSolidColor(const Color(0xFF00FF00))); + rootCircle.add(stack); + return RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCircle); +} + +void main() { + ViewRenderingFlutterBinding(root: buildSectorExample()).scheduleFrame(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/rendering/flex_layout.dart b/novelforge-project/agent-workspace/flutter/examples/layers/rendering/flex_layout.dart new file mode 100644 index 0000000000000000000000000000000000000000..845a232fa18199864924faa12ff1878823731467 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/rendering/flex_layout.dart @@ -0,0 +1,91 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to use flex layout directly in the underlying render +// tree. + +import 'package:flutter/rendering.dart'; + +import 'src/binding.dart'; +import 'src/solid_color_box.dart'; + +void main() { + final RenderFlex table = RenderFlex(direction: Axis.vertical, textDirection: TextDirection.ltr); + + void addAlignmentRow(CrossAxisAlignment crossAxisAlignment) { + TextStyle style = const TextStyle(color: Color(0xFF000000)); + final RenderParagraph paragraph = RenderParagraph( + TextSpan(style: style, text: '$crossAxisAlignment'), + textDirection: TextDirection.ltr, + ); + table.add(RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0))); + final RenderFlex row = RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic, textDirection: TextDirection.ltr); + style = const TextStyle(fontSize: 15.0, color: Color(0xFF000000)); + row.add(RenderDecoratedBox( + decoration: const BoxDecoration(color: Color(0x7FFFCCCC)), + child: RenderParagraph( + TextSpan(style: style, text: 'foo foo foo'), + textDirection: TextDirection.ltr, + ), + )); + style = const TextStyle(fontSize: 10.0, color: Color(0xFF000000)); + row.add(RenderDecoratedBox( + decoration: const BoxDecoration(color: Color(0x7FCCFFCC)), + child: RenderParagraph( + TextSpan(style: style, text: 'foo foo foo'), + textDirection: TextDirection.ltr, + ), + )); + final RenderFlex subrow = RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic, textDirection: TextDirection.ltr); + style = const TextStyle(fontSize: 25.0, color: Color(0xFF000000)); + subrow.add(RenderDecoratedBox( + decoration: const BoxDecoration(color: Color(0x7FCCCCFF)), + child: RenderParagraph( + TextSpan(style: style, text: 'foo foo foo foo'), + textDirection: TextDirection.ltr, + ), + )); + subrow.add(RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: const Size(30.0, 40.0))); + row.add(subrow); + table.add(row); + final FlexParentData rowParentData = row.parentData! as FlexParentData; + rowParentData.flex = 1; + } + + addAlignmentRow(CrossAxisAlignment.start); + addAlignmentRow(CrossAxisAlignment.end); + addAlignmentRow(CrossAxisAlignment.center); + addAlignmentRow(CrossAxisAlignment.stretch); + addAlignmentRow(CrossAxisAlignment.baseline); + + void addJustificationRow(MainAxisAlignment justify) { + const TextStyle style = TextStyle(color: Color(0xFF000000)); + final RenderParagraph paragraph = RenderParagraph( + TextSpan(style: style, text: '$justify'), + textDirection: TextDirection.ltr, + ); + table.add(RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0))); + final RenderFlex row = RenderFlex(textDirection: TextDirection.ltr); + row.add(RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: const Size(80.0, 60.0))); + row.add(RenderSolidColorBox(const Color(0xFFCCFFCC), desiredSize: const Size(64.0, 60.0))); + row.add(RenderSolidColorBox(const Color(0xFFCCCCFF), desiredSize: const Size(160.0, 60.0))); + row.mainAxisAlignment = justify; + table.add(row); + final FlexParentData rowParentData = row.parentData! as FlexParentData; + rowParentData.flex = 1; + } + + addJustificationRow(MainAxisAlignment.start); + addJustificationRow(MainAxisAlignment.end); + addJustificationRow(MainAxisAlignment.center); + addJustificationRow(MainAxisAlignment.spaceBetween); + addJustificationRow(MainAxisAlignment.spaceAround); + + final RenderDecoratedBox root = RenderDecoratedBox( + decoration: const BoxDecoration(color: Color(0xFFFFFFFF)), + child: RenderPadding(child: table, padding: const EdgeInsets.symmetric(vertical: 50.0)), + ); + + ViewRenderingFlutterBinding(root: root).scheduleFrame(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/rendering/hello_world.dart b/novelforge-project/agent-workspace/flutter/examples/layers/rendering/hello_world.dart new file mode 100644 index 0000000000000000000000000000000000000000..cb49f94d373b234eccd559958c4954701d2ed794 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/rendering/hello_world.dart @@ -0,0 +1,30 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to show the text 'Hello, world.' using the underlying +// render tree. + +import 'package:flutter/rendering.dart'; + +import 'src/binding.dart'; + +void main() { + // We use ViewRenderingFlutterBinding to attach the render tree to the window. + ViewRenderingFlutterBinding( + // The root of our render tree is a RenderPositionedBox, which centers its + // child both vertically and horizontally. + root: RenderPositionedBox( + // We use a RenderParagraph to display the text 'Hello, world.' without + // any explicit styling. + child: RenderParagraph( + const TextSpan(text: 'Hello, world.'), + // The text is in English so we specify the text direction as + // left-to-right. If the text had been in Hebrew or Arabic, we would + // have specified right-to-left. The Flutter framework does not assume a + // particular text direction. + textDirection: TextDirection.ltr, + ), + ), + ).scheduleFrame(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/rendering/spinning_square.dart b/novelforge-project/agent-workspace/flutter/examples/layers/rendering/spinning_square.dart new file mode 100644 index 0000000000000000000000000000000000000000..cb833069fdeccf750019386c3661cdaf97f2a357 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/rendering/spinning_square.dart @@ -0,0 +1,69 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to perform a simple animation using the underlying +// render tree. + +import 'dart:math' as math; + +import 'package:flutter/animation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; + +import 'src/binding.dart'; + +class NonStopVSync implements TickerProvider { + const NonStopVSync(); + @override + Ticker createTicker(TickerCallback onTick) => Ticker(onTick); +} + +void main() { + // We first create a render object that represents a green box. + final RenderBox green = RenderDecoratedBox( + decoration: const BoxDecoration(color: Color(0xFF00FF00)), + ); + // Second, we wrap that green box in a render object that forces the green box + // to have a specific size. + final RenderBox square = RenderConstrainedBox( + additionalConstraints: const BoxConstraints.tightFor(width: 200.0, height: 200.0), + child: green, + ); + // Third, we wrap the sized green square in a render object that applies rotation + // transform before painting its child. Each frame of the animation, we'll + // update the transform of this render object to cause the green square to + // spin. + final RenderTransform spin = RenderTransform( + transform: Matrix4.identity(), + alignment: Alignment.center, + child: square, + ); + // Finally, we center the spinning green square... + final RenderBox root = RenderPositionedBox( + child: spin, + ); + // and attach it to the window. + ViewRenderingFlutterBinding(root: root); + + // To make the square spin, we use an animation that repeats every 1800 + // milliseconds. + final AnimationController animation = AnimationController( + duration: const Duration(milliseconds: 1800), + vsync: const NonStopVSync(), + )..repeat(); + // The animation will produce a value between 0.0 and 1.0 each frame, but we + // want to rotate the square using a value between 0.0 and math.pi. To change + // the range of the animation, we use a Tween. + final Tween tween = Tween(begin: 0.0, end: math.pi); + // We add a listener to the animation, which will be called every time the + // animation ticks. + animation.addListener(() { + // This code runs every tick of the animation and sets a new transform on + // the "spin" render object by evaluating the tween on the current value + // of the animation. Setting this value will mark a number of dirty bits + // inside the render tree, which cause the render tree to repaint with the + // new transform value this frame. + spin.transform = Matrix4.rotationZ(tween.evaluate(animation)); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/rendering/touch_input.dart b/novelforge-project/agent-workspace/flutter/examples/layers/rendering/touch_input.dart new file mode 100644 index 0000000000000000000000000000000000000000..37a944528447dd38c64b2db25c3e587d6263119a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/rendering/touch_input.dart @@ -0,0 +1,139 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to use process input events in the underlying render +// tree. + +import 'package:flutter/material.dart'; // Imported just for its color palette. +import 'package:flutter/rendering.dart'; + +import 'src/binding.dart'; + +// Material design colors. :p +List _kColors = [ + Colors.teal, + Colors.amber, + Colors.purple, + Colors.lightBlue, + Colors.deepPurple, + Colors.lime, +]; + +/// A simple model object for a dot that reacts to pointer pressure. +class Dot { + Dot({ required Color color }) : _paint = Paint()..color = color; + + final Paint _paint; + Offset position = Offset.zero; + double radius = 0.0; + + void update(PointerEvent event) { + position = event.position; + radius = 5 + (95 * event.pressure); + } + + void paint(Canvas canvas, Offset offset) { + canvas.drawCircle(position + offset, radius, _paint); + } +} + +/// A render object that draws dots under each pointer. +class RenderDots extends RenderBox { + RenderDots(); + + /// State to remember which dots to paint. + final Map _dots = {}; + + /// Indicates that the size of this render object depends only on the + /// layout constraints provided by the parent. + @override + bool get sizedByParent => true; + + /// By selecting the biggest value permitted by the incoming constraints + /// during layout, this function makes this render object as large as + /// possible (i.e., fills the entire screen). + @override + void performResize() { + size = constraints.biggest; + } + + /// Makes this render object hittable so that it receives pointer events. + @override + bool hitTestSelf(Offset position) => true; + + /// Processes pointer events by mutating state and invalidating its previous + /// painting commands. + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + if (event is PointerDownEvent) { + final Color color = _kColors[event.pointer.remainder(_kColors.length)]; + _dots[event.pointer] = Dot(color: color)..update(event); + // We call markNeedsPaint to indicate that our painting commands have + // changed and that paint needs to be called before displaying a new frame + // to the user. It's harmless to call markNeedsPaint multiple times + // because the render tree will ignore redundant calls. + markNeedsPaint(); + } else if (event is PointerUpEvent || event is PointerCancelEvent) { + _dots.remove(event.pointer); + markNeedsPaint(); + } else if (event is PointerMoveEvent) { + _dots[event.pointer]!.update(event); + markNeedsPaint(); + } + } + + /// Issues new painting commands. + @override + void paint(PaintingContext context, Offset offset) { + final Canvas canvas = context.canvas; + // The "size" property indicates the size of that this render box was + // allotted during layout. Here we paint our bounds white. Notice that we're + // located at "offset" from the origin of the canvas' coordinate system. + // Passing offset during the render tree's paint walk is an optimization to + // avoid having to change the origin of the canvas's coordinate system too + // often. + canvas.drawRect(offset & size, Paint()..color = const Color(0xFFFFFFFF)); + + // We iterate through our model and paint each dot. + for (final Dot dot in _dots.values) { + dot.paint(canvas, offset); + } + } +} + +void main() { + // Create some styled text to tell the user to interact with the app. + final RenderParagraph paragraph = RenderParagraph( + const TextSpan( + style: TextStyle(color: Colors.black87), + text: 'Touch me!', + ), + textDirection: TextDirection.ltr, + ); + // A stack is a render object that layers its children on top of each other. + // The bottom later is our RenderDots object, and on top of that we show the + // text. + final RenderStack stack = RenderStack( + textDirection: TextDirection.ltr, + children: [ + RenderDots(), + paragraph, + ], + ); + // The "parentData" field of a render object is controlled by the render + // object's parent render object. Now that we've added the paragraph as a + // child of the RenderStack, the paragraph's parentData field has been + // populated with a StackParentData, which we can use to provide input to the + // stack's layout algorithm. + // + // We use the StackParentData of the paragraph to position the text in the top + // left corner of the screen. + final StackParentData paragraphParentData = paragraph.parentData! as StackParentData; + paragraphParentData + ..top = 40.0 + ..left = 20.0; + + // Finally, we attach the render tree we've built to the screen. + ViewRenderingFlutterBinding(root: stack).scheduleFrame(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/services/data.json b/novelforge-project/agent-workspace/flutter/examples/layers/services/data.json new file mode 100644 index 0000000000000000000000000000000000000000..ea856f985dedcad8b3246ab0f80753f8c2a4c16a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/services/data.json @@ -0,0 +1,45 @@ +{ + "_id": "57112806d874e9e6df7099d4", + "index": 0, + "guid": "77dc6167-2351-4a64-a603-aceaff115432", + "isActive": false, + "balance": "$1,316.41", + "picture": "http://placehold.it/32x32", + "age": 21, + "eyeColor": "brown", + "name": "Marta Hartman", + "gender": "female", + "company": "EXAMPLE", + "email": "martahartman@example.com", + "phone": "+1 (555) 555-2328", + "address": "463 Temple Court, Brandywine, Kansas, 1113", + "about": "Incididunt commodo sunt commodo nulla adipisicing duis aute enim aute minim reprehenderit aute consectetur. Eu laborum esse aute laborum aute. Tempor in cillum exercitation aliqua velit quis incididunt esse ea nisi. Cillum pariatur reprehenderit est nisi nisi exercitation.\r\n", + "registered": "2014-01-18T12:32:22 +08:00", + "latitude": 4.101477, + "longitude": 39.153115, + "tags": [ + "pariatur", + "sit", + "sint", + "ex", + "minim", + "veniam", + "ullamco" + ], + "friends": [ + { + "id": 0, + "name": "Tricia Guerra" + }, + { + "id": 1, + "name": "Paula Dillard" + }, + { + "id": 2, + "name": "Ursula Stout" + } + ], + "greeting": "Hello, Marta Hartman! You have 4 unread messages.", + "favoriteFruit": "strawberry" +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/services/isolate.dart b/novelforge-project/agent-workspace/flutter/examples/layers/services/isolate.dart new file mode 100644 index 0000000000000000000000000000000000000000..c7cd96782e9b40af1365250c2729d2fd162aabdd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/services/isolate.dart @@ -0,0 +1,294 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:convert'; +import 'dart:isolate'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +typedef OnProgressListener = void Function(double completed, double total); +typedef OnResultListener = void Function(String result); + +// An encapsulation of a large amount of synchronous processing. +// +// The choice of JSON parsing here is meant as an example that might surface +// in real-world applications. +class Calculator { + Calculator({ required this.onProgressListener, required this.onResultListener, String? data }) + : _data = _replicateJson(data, 10000); + + final OnProgressListener onProgressListener; + final OnResultListener onResultListener; + final String _data; + // This example assumes that the number of objects to parse is known in + // advance. In a real-world situation, this might not be true; in that case, + // the app might choose to display an indeterminate progress indicator. + static const int _NUM_ITEMS = 110000; + static const int _NOTIFY_INTERVAL = 1000; + + // Run the computation associated with this Calculator. + void run() { + int i = 0; + final JsonDecoder decoder = JsonDecoder( + (dynamic key, dynamic value) { + if (key is int && i++ % _NOTIFY_INTERVAL == 0) { + onProgressListener(i.toDouble(), _NUM_ITEMS.toDouble()); + } + return value; + }, + ); + try { + final List result = decoder.convert(_data) as List; + final int n = result.length; + onResultListener('Decoded $n results'); + } on FormatException catch (e, stack) { + debugPrint('Invalid JSON file: $e'); + debugPrint('$stack'); + } + } + + static String _replicateJson(String? data, int count) { + final StringBuffer buffer = StringBuffer()..write('['); + for (int i = 0; i < count; i++) { + buffer.write(data); + if (i < count - 1) { + buffer.write(','); + } + } + buffer.write(']'); + return buffer.toString(); + } +} + +// The current state of the calculation. +enum CalculationState { + idle, + loading, + calculating +} + +// Structured message to initialize the spawned isolate. +class CalculationMessage { + CalculationMessage(this.data, this.sendPort); + String data; + SendPort sendPort; +} + +// A manager for the connection to a spawned isolate. +// +// Isolates communicate with each other via ReceivePorts and SendPorts. +// This class manages these ports and maintains state related to the +// progress of the background computation. +class CalculationManager { + CalculationManager({ required this.onProgressListener, required this.onResultListener }) + : _receivePort = ReceivePort() { + _receivePort.listen(_handleMessage); + } + + CalculationState _state = CalculationState.idle; + CalculationState get state => _state; + bool get isRunning => _state != CalculationState.idle; + + double _completed = 0.0; + double _total = 1.0; + + final OnProgressListener onProgressListener; + final OnResultListener onResultListener; + + // Start the background computation. + // + // Does nothing if the computation is already running. + void start() { + if (!isRunning) { + _state = CalculationState.loading; + _runCalculation(); + } + } + + // Stop the background computation. + // + // Kills the isolate immediately, if spawned. Does nothing if the + // computation is not running. + void stop() { + if (isRunning) { + _state = CalculationState.idle; + if (_isolate != null) { + _isolate!.kill(priority: Isolate.immediate); + _isolate = null; + _completed = 0.0; + _total = 1.0; + } + } + } + + final ReceivePort _receivePort; + Isolate? _isolate; + + void _runCalculation() { + // Load the JSON string. This is done in the main isolate because spawned + // isolates do not have access to the root bundle. However, the loading + // process is asynchronous, so the UI will not block while the file is + // loaded. + rootBundle.loadString('services/data.json').then((String data) { + if (isRunning) { + final CalculationMessage message = CalculationMessage(data, _receivePort.sendPort); + // Spawn an isolate to JSON-parse the file contents. The JSON parsing + // is synchronous, so if done in the main isolate, the UI would block. + Isolate.spawn(_calculate, message).then((Isolate isolate) { + if (!isRunning) { + isolate.kill(priority: Isolate.immediate); + } else { + _state = CalculationState.calculating; + _isolate = isolate; + } + }); + } + }); + } + + void _handleMessage(dynamic message) { + if (message is List) { + _completed = message[0]; + _total = message[1]; + onProgressListener(_completed, _total); + } else if (message is String) { + _completed = 0.0; + _total = 1.0; + _isolate = null; + _state = CalculationState.idle; + onResultListener(message); + } + } + + // Main entry point for the spawned isolate. + // + // This entry point must be static, and its (single) argument must match + // the message passed in Isolate.spawn above. Typically, some part of the + // message will contain a SendPort so that the spawned isolate can + // communicate back to the main isolate. + // + // Static and global variables are initialized anew in the spawned isolate, + // in a separate memory space. + static void _calculate(CalculationMessage message) { + final SendPort sender = message.sendPort; + final Calculator calculator = Calculator( + onProgressListener: (double completed, double total) { + sender.send([ completed, total ]); + }, + onResultListener: sender.send, + data: message.data, + ); + calculator.run(); + } +} + +// Main app widget. +// +// The app shows a simple UI that allows control of the background computation, +// as well as an animation to illustrate that the UI does not block while this +// computation is performed. +// +// This is a StatefulWidget in order to hold the CalculationManager and +// the AnimationController for the running animation. +class IsolateExampleWidget extends StatefulWidget { + const IsolateExampleWidget({super.key}); + + @override + IsolateExampleState createState() => IsolateExampleState(); +} + +// Main application state. +class IsolateExampleState extends State with SingleTickerProviderStateMixin { + + String _status = 'Idle'; + String _label = 'Start'; + String _result = ' '; + double _progress = 0.0; + late final AnimationController _animation = AnimationController( + duration: const Duration(milliseconds: 3600), + vsync: this, + )..repeat(); + late final CalculationManager _calculationManager = CalculationManager( + onProgressListener: _handleProgressUpdate, + onResultListener: _handleResult, + ); + + @override + void dispose() { + _animation.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Material( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + RotationTransition( + turns: _animation, + child: Container( + width: 120.0, + height: 120.0, + color: const Color(0xFF882222), + ), + ), + Opacity( + opacity: _calculationManager.isRunning ? 1.0 : 0.0, + child: CircularProgressIndicator( + value: _progress, + ), + ), + Text(_status), + Center( + child: ElevatedButton( + onPressed: _handleButtonPressed, + child: Text(_label), + ), + ), + Text(_result), + ], + ), + ); + } + + void _handleProgressUpdate(double completed, double total) { + _updateState(' ', completed / total); + } + + void _handleResult(String result) { + _updateState(result, 0.0); + } + + void _handleButtonPressed() { + if (_calculationManager.isRunning) { + _calculationManager.stop(); + } else { + _calculationManager.start(); + } + _updateState(' ', 0.0); + } + + String _getStatus(CalculationState state) { + return switch (state) { + CalculationState.loading => 'Loading...', + CalculationState.calculating => 'In Progress', + CalculationState.idle => 'Idle', + }; + } + + void _updateState(String result, double progress) { + setState(() { + _result = result; + _progress = progress; + _label = _calculationManager.isRunning ? 'Stop' : 'Start'; + _status = _getStatus(_calculationManager.state); + }); + } +} + +void main() { + runApp(const MaterialApp(home: IsolateExampleWidget())); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/services/lifecycle.dart b/novelforge-project/agent-workspace/flutter/examples/layers/services/lifecycle.dart new file mode 100644 index 0000000000000000000000000000000000000000..5a60b86304021fcaf1ecc27e2464b4cb1e0502a8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/services/lifecycle.dart @@ -0,0 +1,56 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +class LifecycleWatcher extends StatefulWidget { + const LifecycleWatcher({ super.key }); + + @override + State createState() => _LifecycleWatcherState(); +} + +class _LifecycleWatcherState extends State + with WidgetsBindingObserver { + AppLifecycleState? _lastLifecycleState; + + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addObserver(this); + } + + @override + void dispose() { + WidgetsBinding.instance.removeObserver(this); + super.dispose(); + } + + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + setState(() { + _lastLifecycleState = state; + }); + } + + @override + Widget build(BuildContext context) { + if (_lastLifecycleState == null) { + return const Text('This widget has not observed any lifecycle changes.'); + } + return Text('The most recent lifecycle state this widget observed was: $_lastLifecycleState.'); + } +} + + +void main() { + runApp( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: LifecycleWatcher(), + ), + ), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/test/analysis_options.yaml b/novelforge-project/agent-workspace/flutter/examples/layers/test/analysis_options.yaml new file mode 100644 index 0000000000000000000000000000000000000000..60222f820cd28c9d9d79aaeb9c58e21108119ccd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/test/analysis_options.yaml @@ -0,0 +1,5 @@ +include: ../../../analysis_options.yaml + +linter: + rules: + only_throw_errors: false # We are more flexible for tests. diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/test/gestures_test.dart b/novelforge-project/agent-workspace/flutter/examples/layers/test/gestures_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..82e64f28aad05caf93e98e177c6d52a1338e29b0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/test/gestures_test.dart @@ -0,0 +1,38 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../widgets/gestures.dart'; + +void main() { + testWidgets('Tap on center change color', (WidgetTester tester) async { + await tester.pumpWidget(const Directionality( + textDirection: TextDirection.ltr, + child: GestureDemo(), + )); + final Finder finder = find.byType(GestureDemo); + + MaterialColor getSwatch() => tester.state(finder).swatch; + Future tap() async { + final Offset topLeft = tester.getTopLeft(finder); + await tester.tapAt(tester.getSize(finder).center(topLeft)); + await tester.pump(const Duration(seconds: 1)); + } + + // initial swatch + expect(getSwatch(), GestureDemoState.kSwatches[0]); + + // every tap change swatch + for (int i = 1; i < GestureDemoState.kSwatches.length; i++) { + await tap(); + expect(getSwatch(), GestureDemoState.kSwatches[i]); + } + + // tap on last swatch display first swatch + await tap(); + expect(getSwatch(), GestureDemoState.kSwatches[0]); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/test/sector_layout_test.dart b/novelforge-project/agent-workspace/flutter/examples/layers/test/sector_layout_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..06968cd6c1ab50cbafe110cbf5a65272fc90cfcc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/test/sector_layout_test.dart @@ -0,0 +1,41 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/gestures.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../rendering/src/sector_layout.dart'; + +void main() { + group('hit testing', () { + test('SectorHitTestResult wrapping HitTestResult', () { + final HitTestEntry entry1 = HitTestEntry(_DummyHitTestTarget()); + final HitTestEntry entry2 = HitTestEntry(_DummyHitTestTarget()); + final HitTestEntry entry3 = HitTestEntry(_DummyHitTestTarget()); + + final HitTestResult wrapped = HitTestResult(); + wrapped.add(entry1); + expect(wrapped.path, equals([entry1])); + + final SectorHitTestResult wrapping = SectorHitTestResult.wrap(wrapped); + expect(wrapping.path, equals([entry1])); + expect(wrapping.path, same(wrapped.path)); + + wrapping.add(entry2); + expect(wrapping.path, equals([entry1, entry2])); + expect(wrapped.path, equals([entry1, entry2])); + + wrapped.add(entry3); + expect(wrapping.path, equals([entry1, entry2, entry3])); + expect(wrapped.path, equals([entry1, entry2, entry3])); + }); + }); +} + +class _DummyHitTestTarget implements HitTestTarget { + @override + void handleEvent(PointerEvent event, HitTestEntry entry) { + // Nothing to do. + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/test/sector_test.dart b/novelforge-project/agent-workspace/flutter/examples/layers/test/sector_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..b85616aada7db0859d14160f692377bd3a60ed73 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/test/sector_test.dart @@ -0,0 +1,18 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; + +import '../rendering/src/sector_layout.dart'; +import '../widgets/sectors.dart'; + +void main() { + test('SectorConstraints', () { + expect(const SectorConstraints().isTight, isFalse); + }); + + testWidgets('Sector Sixes', (WidgetTester tester) async { + await tester.pumpWidget(const SectorApp()); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/layers/widgets/custom_render_box.dart b/novelforge-project/agent-workspace/flutter/examples/layers/widgets/custom_render_box.dart new file mode 100644 index 0000000000000000000000000000000000000000..8838cbdcf967aa118b9ff44e42801b95affcf2e1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/layers/widgets/custom_render_box.dart @@ -0,0 +1,60 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +class RenderDots extends RenderConstrainedBox { + RenderDots() : super(additionalConstraints: const BoxConstraints.expand()); + + // Makes this render box hittable so that we'll get pointer events. + @override + bool hitTestSelf(Offset position) => true; + + final Map _dots = {}; + + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + if (event is PointerDownEvent || event is PointerMoveEvent) { + _dots[event.pointer] = event.position; + markNeedsPaint(); + } else if (event is PointerUpEvent || event is PointerCancelEvent) { + _dots.remove(event.pointer); + markNeedsPaint(); + } + } + + @override + void paint(PaintingContext context, Offset offset) { + final Canvas canvas = context.canvas; + canvas.drawRect(offset & size, Paint()..color = const Color(0xFF0000FF)); + + final Paint paint = Paint()..color = const Color(0xFF00FF00); + for (final Offset point in _dots.values) { + canvas.drawCircle(point, 50.0, paint); + } + + super.paint(context, offset); + } +} + +class Dots extends SingleChildRenderObjectWidget { + const Dots({ super.key, super.child }); + + @override + RenderDots createRenderObject(BuildContext context) => RenderDots(); +} + +void main() { + runApp( + const Directionality( + textDirection: TextDirection.ltr, + child: Dots( + child: Center( + child: Text('Touch me!'), + ), + ), + ), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/README.md b/novelforge-project/agent-workspace/flutter/examples/platform_channel/README.md new file mode 100644 index 0000000000000000000000000000000000000000..da81169a6904be5037bdb4b0faee86a11740ce43 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/README.md @@ -0,0 +1,22 @@ +# Example of calling platform services from Flutter + +This project demonstrates how to connect a Flutter app to platform-specific services. + +You can read more about +[accessing platform and third-party services in Flutter](https://flutter.dev/platform-channels/). + +## iOS +You can use the commands `flutter build` and `flutter run` from the app's root +directory to build/run the app or you can open `ios/Runner.xcworkspace` in Xcode +and build/run the project as usual. + +## Android + +You can use the commands `flutter build` and `flutter run` from the app's root +directory to build/run the app or to build with Android Studio, open the +`android` folder in Android Studio and build the project as usual. + +## Windows +You can use the commands `flutter build` and `flutter run` from the app's root +directory to build/run the app or you can build once then open +`build\windows\platform_channel.sln` in Visual Studio to build and run. diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android.iml b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android.iml new file mode 100644 index 0000000000000000000000000000000000000000..79f6223dbf740f805ef97f2b382f592944c1b899 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/build.gradle b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..3c28e7c27a16ec2d827edeaceb87d837a135e36e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/build.gradle @@ -0,0 +1,66 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +apply plugin: 'com.android.application' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + +android { + namespace "com.example.platformchannel" + compileSdk flutter.compileSdkVersion + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + defaultConfig { + applicationId "io.flutter.examples.platform_channel" + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies { + testImplementation 'junit:junit:4.13' + androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/androidTest/java/com/example/platformchannel/ExampleInstrumentedTest.java b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/androidTest/java/com/example/platformchannel/ExampleInstrumentedTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0ff8a400e59cc832e743efc53809c5bc96a54cf4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/androidTest/java/com/example/platformchannel/ExampleInstrumentedTest.java @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package com.example.platformchannel; + +import android.graphics.Bitmap; +import android.support.test.InstrumentationRegistry; +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; + +import io.flutter.view.FlutterView; + +import android.app.Instrumentation; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Rule + public ActivityTestRule activityRule = + new ActivityTestRule<>(MainActivity.class); + + + @Test + public void testBitmap() { + final Instrumentation instr = InstrumentationRegistry.getInstrumentation(); + final BitmapPoller poller = new BitmapPoller(5); + instr.runOnMainSync(new Runnable() { + public void run() { + final FlutterView flutterView = activityRule.getActivity().getFlutterView(); + + // Call onPostResume to start the engine's renderer even if the activity + // is paused in the test environment. + flutterView.onPostResume(); + + poller.start(flutterView); + } + }); + + Bitmap bitmap = null; + try { + bitmap = poller.waitForBitmap(); + } catch (InterruptedException e) { + fail(e.getMessage()); + } + + assertNotNull(bitmap); + assertTrue(bitmap.getWidth() > 0); + assertTrue(bitmap.getHeight() > 0); + + // Check that a pixel matches the default Material background color. + assertTrue(bitmap.getPixel(bitmap.getWidth() - 1, bitmap.getHeight() - 1) == 0xFFFAFAFA); + } + + // Waits on a FlutterView until it is able to produce a bitmap. + private class BitmapPoller { + private int triesPending; + private int waitMsec; + private FlutterView flutterView; + private Bitmap bitmap; + private CountDownLatch latch = new CountDownLatch(1); + + private final int delayMsec = 1000; + + BitmapPoller(int tries) { + triesPending = tries; + waitMsec = delayMsec * tries + 100; + } + + void start(FlutterView flutterView) { + this.flutterView = flutterView; + flutterView.postDelayed(checkBitmap, delayMsec); + } + + Bitmap waitForBitmap() throws InterruptedException { + latch.await(waitMsec, TimeUnit.MILLISECONDS); + return bitmap; + } + + private Runnable checkBitmap = new Runnable() { + public void run() { + bitmap = flutterView.getBitmap(); + triesPending--; + if (bitmap != null || triesPending == 0) { + latch.countDown(); + } else { + flutterView.postDelayed(checkBitmap, delayMsec); + } + } + }; + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/main/AndroidManifest.xml b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000000000000000000000000000000000..803e946a373e1508e1a19c3e860127472cc5cff2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/main/java/com/example/platformchannel/MainActivity.java b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/main/java/com/example/platformchannel/MainActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..e0241b8fd48b9ca00b2d780598fce61bcc86c404 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/main/java/com/example/platformchannel/MainActivity.java @@ -0,0 +1,100 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package com.example.platformchannel; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.ContextWrapper; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.BatteryManager; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; +import android.os.Bundle; +import androidx.annotation.NonNull; +import io.flutter.embedding.android.FlutterActivity; +import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.plugin.common.EventChannel; +import io.flutter.plugin.common.EventChannel.EventSink; +import io.flutter.plugin.common.EventChannel.StreamHandler; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; +import io.flutter.plugin.common.MethodChannel.Result; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugins.GeneratedPluginRegistrant; + +public class MainActivity extends FlutterActivity { + private static final String BATTERY_CHANNEL = "samples.flutter.io/battery"; + private static final String CHARGING_CHANNEL = "samples.flutter.io/charging"; + + @Override + public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { + new EventChannel(flutterEngine.getDartExecutor(), CHARGING_CHANNEL).setStreamHandler( + new StreamHandler() { + private BroadcastReceiver chargingStateChangeReceiver; + @Override + public void onListen(Object arguments, EventSink events) { + chargingStateChangeReceiver = createChargingStateChangeReceiver(events); + registerReceiver( + chargingStateChangeReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + } + + @Override + public void onCancel(Object arguments) { + unregisterReceiver(chargingStateChangeReceiver); + chargingStateChangeReceiver = null; + } + } + ); + + new MethodChannel(flutterEngine.getDartExecutor(), BATTERY_CHANNEL).setMethodCallHandler( + new MethodCallHandler() { + @Override + public void onMethodCall(MethodCall call, Result result) { + if (call.method.equals("getBatteryLevel")) { + int batteryLevel = getBatteryLevel(); + + if (batteryLevel != -1) { + result.success(batteryLevel); + } else { + result.error("UNAVAILABLE", "Battery level not available.", null); + } + } else { + result.notImplemented(); + } + } + } + ); + } + + private BroadcastReceiver createChargingStateChangeReceiver(final EventSink events) { + return new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); + + if (status == BatteryManager.BATTERY_STATUS_UNKNOWN) { + events.error("UNAVAILABLE", "Charging status unavailable", null); + } else { + boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || + status == BatteryManager.BATTERY_STATUS_FULL; + events.success(isCharging ? "charging" : "discharging"); + } + } + }; + } + + private int getBatteryLevel() { + if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { + BatteryManager batteryManager = (BatteryManager) getSystemService(BATTERY_SERVICE); + return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); + } else { + Intent intent = new ContextWrapper(getApplicationContext()). + registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + return (intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100) / + intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/main/res/values/strings.xml b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000000000000000000000000000000000000..1b56c58c71fc998a200eab28c394987c807fb021 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/app/src/main/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + Platform Channel + Flutter Application + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/build.gradle b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..2de20623576a82c3115eca8b1bdb56fd5b5051cb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/build.gradle @@ -0,0 +1,51 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is auto generated. +// To update all the build.gradle files in the Flutter repo, +// See dev/tools/bin/generate_gradle_lockfiles.dart. + +buildscript { + ext.kotlin_version = '1.5.31' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.2.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } + + configurations.classpath { + resolutionStrategy.activateDependencyLocking() + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' + +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') + dependencyLocking { + ignoredDependencies.add('io.flutter:*') + lockFile = file("${rootProject.projectDir}/project-${project.name}.lockfile") + if (!project.hasProperty('local-engine-repo')) { + lockAllConfigurations() + } + } +} + +tasks.register("clean", Delete) { + delete rootProject.buildDir +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/buildscript-gradle.lockfile b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/buildscript-gradle.lockfile new file mode 100644 index 0000000000000000000000000000000000000000..efe13277310ee8fef3c9d7f6f8a2cbbe601d110f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/buildscript-gradle.lockfile @@ -0,0 +1,163 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +androidx.databinding:databinding-common:7.2.0=classpath +androidx.databinding:databinding-compiler-common:7.2.0=classpath +com.android.databinding:baseLibrary:7.2.0=classpath +com.android.tools.analytics-library:crash:30.2.0=classpath +com.android.tools.analytics-library:protos:30.2.0=classpath +com.android.tools.analytics-library:shared:30.2.0=classpath +com.android.tools.analytics-library:tracker:30.2.0=classpath +com.android.tools.build.jetifier:jetifier-core:1.0.0-beta09=classpath +com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta09=classpath +com.android.tools.build:aapt2-proto:7.2.0-7984345=classpath +com.android.tools.build:aaptcompiler:7.2.0=classpath +com.android.tools.build:apksig:7.2.0=classpath +com.android.tools.build:apkzlib:7.2.0=classpath +com.android.tools.build:builder-model:7.2.0=classpath +com.android.tools.build:builder-test-api:7.2.0=classpath +com.android.tools.build:builder:7.2.0=classpath +com.android.tools.build:bundletool:1.8.2=classpath +com.android.tools.build:gradle-api:7.2.0=classpath +com.android.tools.build:gradle:7.2.0=classpath +com.android.tools.build:manifest-merger:30.2.0=classpath +com.android.tools.build:transform-api:2.0.0-deprecated-use-gradle-api=classpath +com.android.tools.ddms:ddmlib:30.2.0=classpath +com.android.tools.layoutlib:layoutlib-api:30.2.0=classpath +com.android.tools.lint:lint-model:30.2.0=classpath +com.android.tools.lint:lint-typedef-remover:30.2.0=classpath +com.android.tools.utp:android-device-provider-ddmlib-proto:30.2.0=classpath +com.android.tools.utp:android-device-provider-gradle-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-host-additional-test-output-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-host-coverage-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-host-retention-proto:30.2.0=classpath +com.android.tools.utp:android-test-plugin-result-listener-gradle-proto:30.2.0=classpath +com.android.tools:annotations:30.2.0=classpath +com.android.tools:common:30.2.0=classpath +com.android.tools:dvlib:30.2.0=classpath +com.android.tools:repository:30.2.0=classpath +com.android.tools:sdk-common:30.2.0=classpath +com.android.tools:sdklib:30.2.0=classpath +com.android:signflinger:7.2.0=classpath +com.android:zipflinger:7.2.0=classpath +com.fasterxml.jackson.core:jackson-annotations:2.11.1=classpath +com.fasterxml.jackson.core:jackson-core:2.11.1=classpath +com.fasterxml.jackson.core:jackson-databind:2.11.1=classpath +com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.1=classpath +com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.11.1=classpath +com.fasterxml.jackson.module:jackson-module-kotlin:2.11.1=classpath +com.fasterxml.woodstox:woodstox-core:6.2.1=classpath +com.github.gundy:semver4j:0.16.4=classpath +com.google.android:annotations:4.1.1.4=classpath +com.google.api.grpc:proto-google-common-protos:1.12.0=classpath +com.google.auto.value:auto-value-annotations:1.6.2=classpath +com.google.code.findbugs:jsr305:3.0.2=classpath +com.google.code.gson:gson:2.8.6=classpath +com.google.crypto.tink:tink:1.3.0-rc2=classpath +com.google.dagger:dagger:2.28.3=classpath +com.google.errorprone:error_prone_annotations:2.3.4=classpath +com.google.flatbuffers:flatbuffers-java:1.12.0=classpath +com.google.guava:failureaccess:1.0.1=classpath +com.google.guava:guava:30.1-jre=classpath +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=classpath +com.google.j2objc:j2objc-annotations:1.3=classpath +com.google.jimfs:jimfs:1.1=classpath +com.google.protobuf:protobuf-java-util:3.10.0=classpath +com.google.protobuf:protobuf-java:3.10.0=classpath +com.google.testing.platform:core-proto:0.0.8-alpha07=classpath +com.googlecode.json-simple:json-simple:1.1=classpath +com.googlecode.juniversalchardet:juniversalchardet:1.0.3=classpath +com.squareup:javapoet:1.10.0=classpath +com.squareup:javawriter:2.5.0=classpath +com.sun.activation:javax.activation:1.2.0=classpath +com.sun.istack:istack-commons-runtime:3.0.8=classpath +com.sun.xml.fastinfoset:FastInfoset:1.2.16=classpath +commons-codec:commons-codec:1.11=classpath +commons-io:commons-io:2.4=classpath +commons-logging:commons-logging:1.2=classpath +de.undercouch:gradle-download-task:4.1.1=classpath +io.grpc:grpc-api:1.21.1=classpath +io.grpc:grpc-context:1.21.1=classpath +io.grpc:grpc-core:1.21.1=classpath +io.grpc:grpc-netty:1.21.1=classpath +io.grpc:grpc-protobuf-lite:1.21.1=classpath +io.grpc:grpc-protobuf:1.21.1=classpath +io.grpc:grpc-stub:1.21.1=classpath +io.netty:netty-buffer:4.1.34.Final=classpath +io.netty:netty-codec-http2:4.1.34.Final=classpath +io.netty:netty-codec-http:4.1.34.Final=classpath +io.netty:netty-codec-socks:4.1.34.Final=classpath +io.netty:netty-codec:4.1.34.Final=classpath +io.netty:netty-common:4.1.34.Final=classpath +io.netty:netty-handler-proxy:4.1.34.Final=classpath +io.netty:netty-handler:4.1.34.Final=classpath +io.netty:netty-resolver:4.1.34.Final=classpath +io.netty:netty-transport:4.1.34.Final=classpath +io.opencensus:opencensus-api:0.21.0=classpath +io.opencensus:opencensus-contrib-grpc-metrics:0.21.0=classpath +it.unimi.dsi:fastutil:8.4.0=classpath +jakarta.activation:jakarta.activation-api:1.2.1=classpath +jakarta.xml.bind:jakarta.xml.bind-api:2.3.2=classpath +javax.inject:javax.inject:1=classpath +net.java.dev.jna:jna-platform:5.6.0=classpath +net.java.dev.jna:jna:5.6.0=classpath +net.sf.jopt-simple:jopt-simple:4.9=classpath +net.sf.kxml:kxml2:2.3.0=classpath +org.apache.commons:commons-compress:1.20=classpath +org.apache.httpcomponents:httpclient:4.5.9=classpath +org.apache.httpcomponents:httpcore:4.4.11=classpath +org.apache.httpcomponents:httpmime:4.5.6=classpath +org.bitbucket.b_c:jose4j:0.7.0=classpath +org.bouncycastle:bcpkix-jdk15on:1.56=classpath +org.bouncycastle:bcprov-jdk15on:1.56=classpath +org.checkerframework:checker-qual:3.5.0=classpath +org.codehaus.mojo:animal-sniffer-annotations:1.17=classpath +org.codehaus.woodstox:stax2-api:4.2.1=classpath +org.glassfish.jaxb:jaxb-runtime:2.3.2=classpath +org.glassfish.jaxb:txw2:2.3.2=classpath +org.jdom:jdom2:2.0.6=classpath +org.jetbrains.dokka:dokka-core:1.4.32=classpath +org.jetbrains.intellij.deps:trove4j:1.0.20181211=classpath +org.jetbrains.kotlin:kotlin-android-extensions:1.5.31=classpath +org.jetbrains.kotlin:kotlin-annotation-processing-gradle:1.5.31=classpath +org.jetbrains.kotlin:kotlin-build-common:1.5.31=classpath +org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-compiler-runner:1.5.31=classpath +org.jetbrains.kotlin:kotlin-daemon-client:1.5.31=classpath +org.jetbrains.kotlin:kotlin-daemon-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.5.31=classpath +org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.5.31=classpath +org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31=classpath +org.jetbrains.kotlin:kotlin-klib-commonizer-api:1.5.31=classpath +org.jetbrains.kotlin:kotlin-native-utils:1.5.31=classpath +org.jetbrains.kotlin:kotlin-project-model:1.5.31=classpath +org.jetbrains.kotlin:kotlin-reflect:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-common:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.5.31=classpath +org.jetbrains.kotlin:kotlin-scripting-jvm:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31=classpath +org.jetbrains.kotlin:kotlin-stdlib:1.5.31=classpath +org.jetbrains.kotlin:kotlin-tooling-metadata:1.5.31=classpath +org.jetbrains.kotlin:kotlin-util-io:1.5.31=classpath +org.jetbrains.kotlin:kotlin-util-klib:1.5.31=classpath +org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.0=classpath +org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0=classpath +org.jetbrains:annotations:13.0=classpath +org.jetbrains:markdown-jvm:0.2.1=classpath +org.jetbrains:markdown:0.2.1=classpath +org.json:json:20180813=classpath +org.jsoup:jsoup:1.13.1=classpath +org.jvnet.staxex:stax-ex:1.8.1=classpath +org.ow2.asm:asm-analysis:9.1=classpath +org.ow2.asm:asm-commons:9.1=classpath +org.ow2.asm:asm-tree:9.1=classpath +org.ow2.asm:asm-util:9.1=classpath +org.ow2.asm:asm:9.1=classpath +org.slf4j:slf4j-api:1.7.30=classpath +org.tensorflow:tensorflow-lite-metadata:0.1.0-rc2=classpath +xerces:xercesImpl:2.12.0=classpath +xml-apis:xml-apis:1.4.01=classpath +empty= diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/gradle.properties b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/gradle.properties new file mode 100644 index 0000000000000000000000000000000000000000..598d13fee446372f156ecc38527b54c7cdcc8e3b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx4G +android.useAndroidX=true +android.enableJetifier=true diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/gradle/wrapper/gradle-wrapper.properties b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..e1ca574ef017c1bc00556b96ea372e2c07948771 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/project-app.lockfile b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/project-app.lockfile new file mode 100644 index 0000000000000000000000000000000000000000..a482ce1f40d46fcd124bffd55b61609d975c6f65 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/project-app.lockfile @@ -0,0 +1,129 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +androidx.activity:activity:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.annotation:annotation-experimental:1.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.annotation:annotation:1.2.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.arch.core:core-common:2.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.arch.core:core-runtime:2.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.collection:collection:1.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.core:core:1.6.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.customview:customview:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.fragment:fragment:1.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-common-java8:2.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-common:2.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-livedata-core:2.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-livedata:2.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-runtime:2.2.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.lifecycle:lifecycle-viewmodel:2.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.loader:loader:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.savedstate:savedstate:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.test.espresso:espresso-core:3.1.1=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath +androidx.test.espresso:espresso-idling-resource:3.1.1=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath +androidx.test:monitor:1.1.1=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath +androidx.test:runner:1.1.1=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath +androidx.tracing:tracing:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.versionedparcelable:versionedparcelable:1.1.1=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.viewpager:viewpager:1.0.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.window:window-java:1.0.0-beta04=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +androidx.window:window:1.0.0-beta04=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +com.android.tools.analytics-library:protos:27.1.3=lintClassPath +com.android.tools.analytics-library:shared:27.1.3=lintClassPath +com.android.tools.analytics-library:tracker:27.1.3=lintClassPath +com.android.tools.build:aapt2-proto:4.1.0-alpha01-6193524=lintClassPath +com.android.tools.build:aapt2:4.1.3-6503028=_internal_aapt2_binary +com.android.tools.build:apksig:4.1.3=lintClassPath +com.android.tools.build:apkzlib:4.1.3=lintClassPath +com.android.tools.build:builder-model:4.1.3=lintClassPath +com.android.tools.build:builder-test-api:4.1.3=lintClassPath +com.android.tools.build:builder:4.1.3=lintClassPath +com.android.tools.build:gradle-api:4.1.3=lintClassPath +com.android.tools.build:manifest-merger:27.1.3=lintClassPath +com.android.tools.ddms:ddmlib:27.1.3=lintClassPath +com.android.tools.external.com-intellij:intellij-core:27.1.3=lintClassPath +com.android.tools.external.com-intellij:kotlin-compiler:27.1.3=lintClassPath +com.android.tools.external.org-jetbrains:uast:27.1.3=lintClassPath +com.android.tools.layoutlib:layoutlib-api:27.1.3=lintClassPath +com.android.tools.lint:lint-api:27.1.3=lintClassPath +com.android.tools.lint:lint-checks:27.1.3=lintClassPath +com.android.tools.lint:lint-gradle-api:27.1.3=lintClassPath +com.android.tools.lint:lint-gradle:27.1.3=lintClassPath +com.android.tools.lint:lint-model:27.1.3=lintClassPath +com.android.tools.lint:lint:27.1.3=lintClassPath +com.android.tools:annotations:27.1.3=lintClassPath +com.android.tools:common:27.1.3=lintClassPath +com.android.tools:dvlib:27.1.3=lintClassPath +com.android.tools:repository:27.1.3=lintClassPath +com.android.tools:sdk-common:27.1.3=lintClassPath +com.android.tools:sdklib:27.1.3=lintClassPath +com.android:signflinger:4.1.3=lintClassPath +com.android:zipflinger:4.1.3=lintClassPath +com.google.code.findbugs:jsr305:2.0.1=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath +com.google.code.findbugs:jsr305:3.0.2=lintClassPath +com.google.code.gson:gson:2.8.5=lintClassPath +com.google.errorprone:error_prone_annotations:2.3.2=lintClassPath +com.google.guava:failureaccess:1.0.1=lintClassPath +com.google.guava:guava:28.1-jre=lintClassPath +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=lintClassPath +com.google.j2objc:j2objc-annotations:1.3=lintClassPath +com.google.jimfs:jimfs:1.1=lintClassPath +com.google.protobuf:protobuf-java:3.10.0=lintClassPath +com.googlecode.json-simple:json-simple:1.1=lintClassPath +com.squareup:javawriter:2.1.1=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath +com.squareup:javawriter:2.5.0=lintClassPath +com.sun.activation:javax.activation:1.2.0=lintClassPath +com.sun.istack:istack-commons-runtime:3.0.7=lintClassPath +com.sun.xml.fastinfoset:FastInfoset:1.2.15=lintClassPath +commons-codec:commons-codec:1.10=lintClassPath +commons-logging:commons-logging:1.2=lintClassPath +it.unimi.dsi:fastutil:7.2.0=lintClassPath +javax.activation:javax.activation-api:1.2.0=lintClassPath +javax.inject:javax.inject:1=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,lintClassPath +javax.xml.bind:jaxb-api:2.3.1=lintClassPath +junit:junit:4.12=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath +junit:junit:4.13=debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +net.sf.jopt-simple:jopt-simple:4.9=lintClassPath +net.sf.kxml:kxml2:2.3.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,lintClassPath +org.apache.commons:commons-compress:1.12=lintClassPath +org.apache.httpcomponents:httpclient:4.5.6=lintClassPath +org.apache.httpcomponents:httpcore:4.4.10=lintClassPath +org.apache.httpcomponents:httpmime:4.5.6=lintClassPath +org.bouncycastle:bcpkix-jdk15on:1.56=lintClassPath +org.bouncycastle:bcprov-jdk15on:1.56=lintClassPath +org.checkerframework:checker-qual:2.8.1=lintClassPath +org.codehaus.groovy:groovy-all:2.4.15=lintClassPath +org.codehaus.mojo:animal-sniffer-annotations:1.18=lintClassPath +org.glassfish.jaxb:jaxb-runtime:2.3.1=lintClassPath +org.glassfish.jaxb:txw2:2.3.1=lintClassPath +org.hamcrest:hamcrest-core:1.3=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.hamcrest:hamcrest-integration:1.3=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath +org.hamcrest:hamcrest-library:1.3=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath +org.jacoco:org.jacoco.agent:0.8.7=androidJacocoAnt +org.jacoco:org.jacoco.ant:0.8.7=androidJacocoAnt +org.jacoco:org.jacoco.core:0.8.7=androidJacocoAnt +org.jacoco:org.jacoco.report:0.8.7=androidJacocoAnt +org.jetbrains.kotlin:kotlin-reflect:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-common:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.30=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib:1.3.72=lintClassPath +org.jetbrains.kotlin:kotlin-stdlib:1.5.31=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jetbrains.trove4j:trove4j:20160824=lintClassPath +org.jetbrains:annotations:13.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,lintClassPath,profileCompileClasspath,profileRuntimeClasspath,profileUnitTestCompileClasspath,profileUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath +org.jvnet.staxex:stax-ex:1.8=lintClassPath +org.ow2.asm:asm-analysis:7.0=lintClassPath +org.ow2.asm:asm-analysis:9.1=androidJacocoAnt +org.ow2.asm:asm-commons:7.0=lintClassPath +org.ow2.asm:asm-commons:9.1=androidJacocoAnt +org.ow2.asm:asm-tree:7.0=lintClassPath +org.ow2.asm:asm-tree:9.1=androidJacocoAnt +org.ow2.asm:asm-util:7.0=lintClassPath +org.ow2.asm:asm:7.0=lintClassPath +org.ow2.asm:asm:9.1=androidJacocoAnt +empty=androidApis,androidJdkImage,androidTestUtil,compile,coreLibraryDesugaring,debugAndroidTestAnnotationProcessorClasspath,debugAnnotationProcessorClasspath,debugReverseMetadataValues,debugUnitTestAnnotationProcessorClasspath,debugWearBundling,lintChecks,lintPublish,profileAnnotationProcessorClasspath,profileReverseMetadataValues,profileUnitTestAnnotationProcessorClasspath,profileWearBundling,releaseAnnotationProcessorClasspath,releaseReverseMetadataValues,releaseUnitTestAnnotationProcessorClasspath,releaseWearBundling,testCompile diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/settings.gradle b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..03ae72d135c01f849e6812b36575b62b14fee791 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/android/settings.gradle @@ -0,0 +1,21 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is auto generated. +// To update all the settings.gradle files in the Flutter repo, +// See dev/tools/bin/generate_gradle_lockfiles.dart. + +include ':app' + +enableFeaturePreview('ONE_LOCKFILE_PER_PROJECT') + +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() + +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Flutter/AppFrameworkInfo.plist b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 0000000000000000000000000000000000000000..8c6e56146e23c84aa60ea78f20bc3a7b3d8ef259 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + MinimumOSVersion + 12.0 + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Flutter/Debug.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Flutter/Debug.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..592ceee85b89bd111b779db6116b130509ab6d4b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Flutter/Debug.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Flutter/Release.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Flutter/Release.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..592ceee85b89bd111b779db6116b130509ab6d4b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Flutter/Release.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/project.pbxproj b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000000000000000000000000000000000000..5e51a2118c80019a52a0dc52be8ffbb35516c7c3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,474 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXBuildFile section */ + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 74970F681EDC0F26000507F3 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 74970F671EDC0F26000507F3 /* GeneratedPluginRegistrant.m */; }; + 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; + 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 74970F661EDC0F26000507F3 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 74970F671EDC0F26000507F3 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + CF3B75C9A7D2FA2A4C99F110 /* Frameworks */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 74970F661EDC0F26000507F3 /* GeneratedPluginRegistrant.h */, + 74970F671EDC0F26000507F3 /* GeneratedPluginRegistrant.m */, + 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 97C146F11CF9000F007C117D /* Supporting Files */, + ); + path = Runner; + sourceTree = ""; + }; + 97C146F11CF9000F007C117D /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 97C146F21CF9000F007C117D /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + CF3B75C9A7D2FA2A4C99F110 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1510; + ORGANIZATIONNAME = "The Flutter Authors"; + TargetAttributes = { + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, + 97C146F31CF9000F007C117D /* main.m in Sources */, + 74970F681EDC0F26000507F3 /* GeneratedPluginRegistrant.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 2460D06F21828D6700436BDB /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Profile; + }; + 2460D07021828D6700436BDB /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.example.PlatformChannel; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Profile; + }; + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.example.PlatformChannel; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.example.PlatformChannel; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + 2460D06F21828D6700436BDB /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + 2460D07021828D6700436BDB /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000000000000000000000000000000000..919434a6254f0e9651f402737811be6634a03e9c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000000000000000000000000000000000..18d981003d68d0546c4804ac2ff47dd97c6e7921 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000000000000000000000000000000000000..e67b2808af02f9ec16f2d72b7961aefdf844afa5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcworkspace/contents.xcworkspacedata b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000000000000000000000000000000000..1d526a16ed0f1cd0c2409d848bf489b93fefa3b2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/AppDelegate.h b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/AppDelegate.h new file mode 100644 index 0000000000000000000000000000000000000000..ee7664daab9799e6bfe925cfd65446b730876abc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/AppDelegate.h @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import +#import + +@interface AppDelegate : FlutterAppDelegate + +@end diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/AppDelegate.m b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/AppDelegate.m new file mode 100644 index 0000000000000000000000000000000000000000..31512fc8c78479a01ade3cb992476ed7c3bf1adc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/AppDelegate.m @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "AppDelegate.h" +#import +#import "GeneratedPluginRegistrant.h" + +@implementation AppDelegate { + FlutterEventSink _eventSink; +} + +- (BOOL)application:(UIApplication*)application + didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { + [GeneratedPluginRegistrant registerWithRegistry:self]; + FlutterViewController* controller = + (FlutterViewController*)self.window.rootViewController; + + FlutterMethodChannel* batteryChannel = [FlutterMethodChannel + methodChannelWithName:@"samples.flutter.io/battery" + binaryMessenger:controller]; + __weak typeof(self) weakSelf = self; + [batteryChannel setMethodCallHandler:^(FlutterMethodCall* call, + FlutterResult result) { + if ([@"getBatteryLevel" isEqualToString:call.method]) { + int batteryLevel = [weakSelf getBatteryLevel]; + if (batteryLevel == -1) { + result([FlutterError errorWithCode:@"UNAVAILABLE" + message:@"Battery info unavailable" + details:nil]); + } else { + result(@(batteryLevel)); + } + } else { + result(FlutterMethodNotImplemented); + } + }]; + + FlutterEventChannel* chargingChannel = [FlutterEventChannel + eventChannelWithName:@"samples.flutter.io/charging" + binaryMessenger:controller]; + [chargingChannel setStreamHandler:self]; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; +} + +- (int)getBatteryLevel { + UIDevice* device = UIDevice.currentDevice; + device.batteryMonitoringEnabled = YES; + if (device.batteryState == UIDeviceBatteryStateUnknown) { + return -1; + } else { + return ((int)(device.batteryLevel * 100)); + } +} + +- (FlutterError*)onListenWithArguments:(id)arguments + eventSink:(FlutterEventSink)eventSink { + _eventSink = eventSink; + [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; + [self sendBatteryStateEvent]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(onBatteryStateDidChange:) + name:UIDeviceBatteryStateDidChangeNotification + object:nil]; + return nil; +} + +- (void)onBatteryStateDidChange:(NSNotification*)notification { + [self sendBatteryStateEvent]; +} + +- (void)sendBatteryStateEvent { + if (!_eventSink) return; + UIDeviceBatteryState state = [[UIDevice currentDevice] batteryState]; + switch (state) { + case UIDeviceBatteryStateFull: + case UIDeviceBatteryStateCharging: + _eventSink(@"charging"); + break; + case UIDeviceBatteryStateUnplugged: + _eventSink(@"discharging"); + break; + default: + _eventSink([FlutterError errorWithCode:@"UNAVAILABLE" + message:@"Charging status unavailable" + details:nil]); + break; + } +} + +- (FlutterError*)onCancelWithArguments:(id)arguments { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + _eventSink = nil; + return nil; +} + +@end diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000000000000000000000000000000000..1d060ed28827ed6aca9565d946e6b5595c8978df --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,93 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Base.lproj/LaunchScreen.storyboard b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000000000000000000000000000000000000..ebf48f6039745ccdb57ad6237321024eb6cdf9af --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Base.lproj/Main.storyboard b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 0000000000000000000000000000000000000000..f3c28516fb38e64d88cfcf5fb1791175df078f2f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Info.plist b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..97a48d5f7b0c45327f5381bdafd85f70966c9735 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + PlatformChannel + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/main.m b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/main.m new file mode 100644 index 0000000000000000000000000000000000000000..1d8e5c06c2cf4644b1872d3651116c63a762667b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/ios/Runner/main.m @@ -0,0 +1,14 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/lib/main.dart b/novelforge-project/agent-workspace/flutter/examples/platform_channel/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..ede86a0f1b9eaf73a4d28e9179a366150a235bd1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/lib/main.dart @@ -0,0 +1,90 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +class PlatformChannel extends StatefulWidget { + const PlatformChannel({super.key}); + + @override + State createState() => _PlatformChannelState(); +} + +class _PlatformChannelState extends State { + static const MethodChannel methodChannel = + MethodChannel('samples.flutter.io/battery'); + static const EventChannel eventChannel = + EventChannel('samples.flutter.io/charging'); + + String _batteryLevel = 'Battery level: unknown.'; + String _chargingStatus = 'Battery status: unknown.'; + + Future _getBatteryLevel() async { + String batteryLevel; + try { + final int? result = await methodChannel.invokeMethod('getBatteryLevel'); + batteryLevel = 'Battery level: $result%.'; + } on PlatformException catch (e) { + if (e.code == 'NO_BATTERY') { + batteryLevel = 'No battery.'; + } else { + batteryLevel = 'Failed to get battery level.'; + } + } + setState(() { + _batteryLevel = batteryLevel; + }); + } + + @override + void initState() { + super.initState(); + eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); + } + + void _onEvent(Object? event) { + setState(() { + _chargingStatus = + "Battery status: ${event == 'charging' ? '' : 'dis'}charging."; + }); + } + + void _onError(Object error) { + setState(() { + _chargingStatus = 'Battery status: unknown.'; + }); + } + + @override + Widget build(BuildContext context) { + return Material( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(_batteryLevel, key: const Key('Battery level label')), + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: _getBatteryLevel, + child: const Text('Refresh'), + ), + ), + ], + ), + Text(_chargingStatus), + ], + ), + ); + } +} + +void main() { + runApp(const MaterialApp(home: PlatformChannel())); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3272f1ecd58ea92404cd19d6b3c8b065ecfccf3f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/CMakeLists.txt @@ -0,0 +1,138 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.10) +project(runner LANGUAGES CXX) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "platform_channel") +# The unique GTK application identifier for this application. See: +# https://wiki.gnome.org/HowDoI/ChooseApplicationID +set(APPLICATION_ID "io.flutter.examples.platform_channel") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(SET CMP0063 NEW) + +# Load bundled libraries from the lib/ directory relative to the binary. +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Root filesystem for cross-building. +if(FLUTTER_TARGET_PLATFORM_SYSROOT) + set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endif() + +# Define build configuration options. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") +endif() + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_14) + target_compile_options(${TARGET} PRIVATE -Wall -Werror) + target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0 upower-glib) + +add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") + +# Define the application target. To change its name, change BINARY_NAME above, +# not the value here, or `flutter run` will no longer work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} + "main.cc" + "my_application.cc" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add dependency libraries. Add any application-specific dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) + +# Only the install-generated bundle's copy of the executable will launch +# correctly, since the resources must in the right relative locations. To avoid +# people trying to run the unbundled copy, put it in a subdirectory instead of +# the default top-level location. +set_target_properties(${BINARY_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" +) + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# By default, "installing" just makes a relocatable bundle in the build +# directory. +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +# Start with a clean build bundle directory every time. +install(CODE " + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") + " COMPONENT Runtime) + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) + install(FILES "${bundled_library}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endforeach(bundled_library) + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/flutter/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/flutter/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d5bd01648a96d50136b2a97c8bb9aa5b711f6c39 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/flutter/CMakeLists.txt @@ -0,0 +1,88 @@ +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.10) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. + +# Serves the same purpose as list(TRANSFORM ... PREPEND ...), +# which isn't available in 3.10. +function(list_prepend LIST_NAME PREFIX) + set(NEW_LIST "") + foreach(element ${${LIST_NAME}}) + list(APPEND NEW_LIST "${PREFIX}${element}") + endforeach(element) + set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) +endfunction() + +# === Flutter Library === +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) +pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) +pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) + +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "fl_basic_message_channel.h" + "fl_binary_codec.h" + "fl_binary_messenger.h" + "fl_dart_project.h" + "fl_engine.h" + "fl_json_message_codec.h" + "fl_json_method_codec.h" + "fl_message_codec.h" + "fl_method_call.h" + "fl_method_channel.h" + "fl_method_codec.h" + "fl_method_response.h" + "fl_plugin_registrar.h" + "fl_plugin_registry.h" + "fl_standard_message_codec.h" + "fl_standard_method_codec.h" + "fl_string_codec.h" + "fl_value.h" + "fl_view.h" + "flutter_linux.h" +) +list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") +target_link_libraries(flutter INTERFACE + PkgConfig::GTK + PkgConfig::GLIB + PkgConfig::GIO +) +add_dependencies(flutter flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/_phony_ + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" + ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} +) diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/main.cc b/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/main.cc new file mode 100644 index 0000000000000000000000000000000000000000..281a29e16b599a95421e7a35112eda77900ff549 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/main.cc @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "my_application.h" + +int main(int argc, char** argv) { + g_autoptr(MyApplication) app = my_application_new(); + return g_application_run(G_APPLICATION(app), argc, argv); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/my_application.cc b/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/my_application.cc new file mode 100644 index 0000000000000000000000000000000000000000..9abcb1bbb478375eab1704464e96cffa11980d6a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/my_application.cc @@ -0,0 +1,303 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "my_application.h" + +#include +#include +#include +#ifdef GDK_WINDOWING_X11 +#include +#endif + +#include "flutter/generated_plugin_registrant.h" + +struct _MyApplication { + GtkApplication parent_instance; + char** dart_entrypoint_arguments; + + FlView* view; + + // Connection to UPower. + UpClient* up_client; + GPtrArray* battery_devices; + + // Channel for Dart code to request the battery information. + FlMethodChannel* battery_channel; + + // Channel to send updates to Dart code about battery charging state. + FlEventChannel* charging_channel; + gchar* last_charge_event; + bool emit_charge_events; +}; + +G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) + +// Checks the charging state and emits an event if necessary. +static void update_charging_state(MyApplication* self) { + if (!self->emit_charge_events) { + return; + } + + const gchar* charge_event = "discharging"; + for (guint i = 0; i < self->battery_devices->len; i++) { + UpDevice* device = + static_cast(g_ptr_array_index(self->battery_devices, i)); + + guint state; + g_object_get(device, "state", &state, nullptr); + if (state == UP_DEVICE_STATE_CHARGING || + state == UP_DEVICE_STATE_FULLY_CHARGED) { + charge_event = "charging"; + } + } + + if (g_strcmp0(charge_event, self->last_charge_event) != 0) { + g_autoptr(GError) error = nullptr; + g_autoptr(FlValue) value = fl_value_new_string(charge_event); + if (!fl_event_channel_send(self->charging_channel, value, nullptr, + &error)) { + g_warning("Failed to send charging event: %s", error->message); + return; + } + g_free(self->last_charge_event); + self->last_charge_event = g_strdup(charge_event); + } +} + +// Called when a UPower device changes state. +static void up_device_state_changed_cb(MyApplication* self, GParamSpec* pspec, + UpDevice* device) { + update_charging_state(self); +} + +// Called when UPower devices are added. +static void up_device_added_cb(MyApplication* self, UpDevice* device) { + // Listen for state changes from battery_devices. + guint kind; + g_object_get(device, "kind", &kind, nullptr); + if (kind == UP_DEVICE_KIND_BATTERY) { + g_ptr_array_add(self->battery_devices, g_object_ref(device)); + g_signal_connect_swapped(device, "notify::state", + G_CALLBACK(up_device_state_changed_cb), self); + up_device_state_changed_cb(self, nullptr, device); + } +} + +// Called when UPower devices are removed. +static void up_device_removed_cb(MyApplication* self, UpDevice* device) { + g_ptr_array_remove(self->battery_devices, device); + g_signal_handlers_disconnect_matched( + device, G_SIGNAL_MATCH_FUNC, 0, 0, nullptr, + reinterpret_cast(up_device_state_changed_cb), nullptr); +} + +// Gets the current battery level. +static FlMethodResponse* get_battery_level(MyApplication* self) { + // Find the first available battery and use that. + for (guint i = 0; i < self->battery_devices->len; i++) { + UpDevice* device = + static_cast(g_ptr_array_index(self->battery_devices, i)); + + double percentage; + g_object_get(device, "percentage", &percentage, nullptr); + g_autoptr(FlValue) result = + fl_value_new_int(static_cast(round(percentage))); + return FL_METHOD_RESPONSE(fl_method_success_response_new(result)); + } + + return FL_METHOD_RESPONSE(fl_method_error_response_new( + "NO_BATTERY", "Device does not have a battery.", nullptr)); +} + +// Called when the Dart code requests battery information. +static void battery_method_call_cb(FlMethodChannel* channel, + FlMethodCall* method_call, + gpointer user_data) { + MyApplication* self = static_cast(user_data); + + g_autoptr(FlMethodResponse) response = nullptr; + if (strcmp(fl_method_call_get_name(method_call), "getBatteryLevel") == 0) { + response = get_battery_level(self); + } else { + response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new()); + } + + g_autoptr(GError) error = nullptr; + if (!fl_method_call_respond(method_call, response, &error)) { + g_warning("Failed to send response: %s", error->message); + } +} + +// Called when the Dart code starts listening for charging events. +static FlMethodErrorResponse* charging_listen_cb(FlEventChannel* channel, + FlValue* args, + gpointer user_data) { + MyApplication* self = static_cast(user_data); + + self->emit_charge_events = true; + update_charging_state(self); + + return nullptr; +} + +// Called when the Dart code stops listening for charging events. +static FlMethodErrorResponse* charging_cancel_cb(FlEventChannel* channel, + FlValue* args, + gpointer user_data) { + MyApplication* self = static_cast(user_data); + + self->emit_charge_events = false; + + return nullptr; +} + +// Creates the platform channels this application provides. +static void create_channels(MyApplication* self) { + FlEngine* engine = fl_view_get_engine(self->view); + FlBinaryMessenger* messenger = fl_engine_get_binary_messenger(engine); + g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new(); + + self->battery_channel = fl_method_channel_new( + messenger, "samples.flutter.io/battery", FL_METHOD_CODEC(codec)); + fl_method_channel_set_method_call_handler( + self->battery_channel, battery_method_call_cb, self, nullptr); + + self->charging_channel = fl_event_channel_new( + messenger, "samples.flutter.io/charging", FL_METHOD_CODEC(codec)); + fl_event_channel_set_stream_handlers(self->charging_channel, + charging_listen_cb, charging_cancel_cb, + self, nullptr); +} + +// Implements GApplication::activate. +static void my_application_activate(GApplication* application) { + MyApplication* self = MY_APPLICATION(application); + GtkWindow* window = + GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + + // Use a header bar when running in GNOME as this is the common style used + // by applications and is the setup most users will be using (e.g. Ubuntu + // desktop). + // If running on X and not using GNOME then just use a traditional title bar + // in case the window manager does more exotic layout, e.g. tiling. + // If running on Wayland assume the header bar will work (may need changing + // if future cases occur). + gboolean use_header_bar = TRUE; +#ifdef GDK_WINDOWING_X11 + GdkScreen* screen = gtk_window_get_screen(window); + if (GDK_IS_X11_SCREEN(screen)) { + const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); + if (g_strcmp0(wm_name, "GNOME Shell") != 0) { + use_header_bar = FALSE; + } + } +#endif + if (use_header_bar) { + GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + gtk_widget_show(GTK_WIDGET(header_bar)); + gtk_header_bar_set_title(header_bar, "platform_channel"); + gtk_header_bar_set_show_close_button(header_bar, TRUE); + gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); + } else { + gtk_window_set_title(window, "platform_channel"); + } + + gtk_window_set_default_size(window, 1280, 720); + gtk_widget_show(GTK_WIDGET(window)); + + g_autoptr(FlDartProject) project = fl_dart_project_new(); + fl_dart_project_set_dart_entrypoint_arguments( + project, self->dart_entrypoint_arguments); + + // Connect to UPower. + self->up_client = up_client_new(); + g_signal_connect_swapped(self->up_client, "device-added", + G_CALLBACK(up_device_added_cb), self); + g_signal_connect_swapped(self->up_client, "device-removed", + G_CALLBACK(up_device_removed_cb), self); +#if UP_CHECK_VERSION(0, 99, 8) + // up_client_get_devices was deprecated and replaced with + // up_client_get_devices2 in libupower 0.99.8. + g_autoptr(GPtrArray) devices = up_client_get_devices2(self->up_client); +#else + g_autoptr(GPtrArray) devices = up_client_get_devices(self->up_client); +#endif + for (guint i = 0; i < devices->len; i++) { + g_autoptr(UpDevice) device = + static_cast(g_ptr_array_index(devices, i)); + up_device_added_cb(self, device); + } + + self->view = fl_view_new(project); + gtk_widget_show(GTK_WIDGET(self->view)); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(self->view)); + + fl_register_plugins(FL_PLUGIN_REGISTRY(self->view)); + + // Create application specific platform channels. + create_channels(self); + + gtk_widget_grab_focus(GTK_WIDGET(self->view)); +} + +// Implements GApplication::local_command_line. +static gboolean my_application_local_command_line(GApplication* application, + gchar*** arguments, + int* exit_status) { + MyApplication* self = MY_APPLICATION(application); + // Strip out the first argument as it is the binary name. + self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); + + g_autoptr(GError) error = nullptr; + if (!g_application_register(application, nullptr, &error)) { + g_warning("Failed to register: %s", error->message); + *exit_status = 1; + return TRUE; + } + + g_application_activate(application); + *exit_status = 0; + + return TRUE; +} + +// Implements GObject::dispose. +static void my_application_dispose(GObject* object) { + MyApplication* self = MY_APPLICATION(object); + + for (guint i = 0; i < self->battery_devices->len; i++) { + UpDevice* device = + static_cast(g_ptr_array_index(self->battery_devices, i)); + g_signal_handlers_disconnect_matched(device, G_SIGNAL_MATCH_DATA, 0, 0, + nullptr, nullptr, self); + } + g_signal_handlers_disconnect_matched(self->up_client, G_SIGNAL_MATCH_DATA, 0, + 0, nullptr, nullptr, self); + + g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); + g_clear_object(&self->up_client); + g_clear_object(&self->battery_devices); + g_clear_object(&self->battery_channel); + g_clear_object(&self->charging_channel); + g_clear_pointer(&self->last_charge_event, g_free); + G_OBJECT_CLASS(my_application_parent_class)->dispose(object); +} + +static void my_application_class_init(MyApplicationClass* klass) { + G_APPLICATION_CLASS(klass)->activate = my_application_activate; + G_APPLICATION_CLASS(klass)->local_command_line = + my_application_local_command_line; + G_OBJECT_CLASS(klass)->dispose = my_application_dispose; +} + +static void my_application_init(MyApplication* self) { + self->battery_devices = g_ptr_array_new_with_free_func(g_object_unref); +} + +MyApplication* my_application_new() { + return MY_APPLICATION(g_object_new(my_application_get_type(), + "application-id", APPLICATION_ID, "flags", + G_APPLICATION_NON_UNIQUE, nullptr)); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/my_application.h b/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/my_application.h new file mode 100644 index 0000000000000000000000000000000000000000..8c66ec485434d1f922c9915bdaefcb8969cdfec9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/linux/my_application.h @@ -0,0 +1,22 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_MY_APPLICATION_H_ +#define FLUTTER_MY_APPLICATION_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, + GtkApplication) + +/** + * my_application_new: + * + * Creates a new Flutter-based application. + * + * Returns: a new #MyApplication. + */ +MyApplication* my_application_new(); + +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Flutter/Flutter-Debug.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Flutter/Flutter-Debug.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..c2efd0b608ba84712fb3e1d01122468a50c7fba1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Flutter/Flutter-Debug.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Flutter/Flutter-Release.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Flutter/Flutter-Release.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..c2efd0b608ba84712fb3e1d01122468a50c7fba1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Flutter/Flutter-Release.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcodeproj/project.pbxproj b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000000000000000000000000000000000000..7cf512c2edd446ac3bc69c6ede2f95b62764328c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,577 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXAggregateTarget section */ + 33CC111A2044C6BA0003C045 /* Flutter Assemble */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */; + buildPhases = ( + 33CC111E2044C6BF0003C045 /* ShellScript */, + ); + dependencies = ( + ); + name = "Flutter Assemble"; + productName = FLX; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */; }; + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC10F02044A3C60003C045 /* AppDelegate.swift */; }; + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; + 3BCBDA4429CA221F00E88DEA /* PowerSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BCBDA4329CA221F00E88DEA /* PowerSource.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC111A2044C6BA0003C045; + remoteInfo = FLX; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 33CC110E2044A8840003C045 /* Bundle Framework */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Bundle Framework"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; + 33CC10ED2044A3C60003C045 /* platform_channel.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = platform_channel.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; + 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 33CC10F72044A3C60003C045 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Runner/Info.plist; sourceTree = ""; }; + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainFlutterWindow.swift; sourceTree = ""; }; + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; + 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; + 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; + 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; + 3BCBDA4329CA221F00E88DEA /* PowerSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PowerSource.swift; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 33CC10EA2044A3C60003C045 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 33BA886A226E78AF003329D5 /* Configs */ = { + isa = PBXGroup; + children = ( + 33E5194F232828860026EE4D /* AppInfo.xcconfig */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */, + ); + path = Configs; + sourceTree = ""; + }; + 33CC10E42044A3C60003C045 = { + isa = PBXGroup; + children = ( + 33FAB671232836740065AC1E /* Runner */, + 33CEB47122A05771004F2AC0 /* Flutter */, + 33CC10EE2044A3C60003C045 /* Products */, + D73912EC22F37F3D000D13A0 /* Frameworks */, + ); + sourceTree = ""; + }; + 33CC10EE2044A3C60003C045 /* Products */ = { + isa = PBXGroup; + children = ( + 33CC10ED2044A3C60003C045 /* platform_channel.app */, + ); + name = Products; + sourceTree = ""; + }; + 33CC11242044D66E0003C045 /* Resources */ = { + isa = PBXGroup; + children = ( + 33CC10F22044A3C60003C045 /* Assets.xcassets */, + 33CC10F42044A3C60003C045 /* MainMenu.xib */, + 33CC10F72044A3C60003C045 /* Info.plist */, + ); + name = Resources; + path = ..; + sourceTree = ""; + }; + 33CEB47122A05771004F2AC0 /* Flutter */ = { + isa = PBXGroup; + children = ( + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */, + ); + path = Flutter; + sourceTree = ""; + }; + 33FAB671232836740065AC1E /* Runner */ = { + isa = PBXGroup; + children = ( + 33CC10F02044A3C60003C045 /* AppDelegate.swift */, + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */, + 3BCBDA4329CA221F00E88DEA /* PowerSource.swift */, + 33E51913231747F40026EE4D /* DebugProfile.entitlements */, + 33E51914231749380026EE4D /* Release.entitlements */, + 33CC11242044D66E0003C045 /* Resources */, + 33BA886A226E78AF003329D5 /* Configs */, + ); + path = Runner; + sourceTree = ""; + }; + D73912EC22F37F3D000D13A0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 33CC10EC2044A3C60003C045 /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 33CC10E92044A3C60003C045 /* Sources */, + 33CC10EA2044A3C60003C045 /* Frameworks */, + 33CC10EB2044A3C60003C045 /* Resources */, + 33CC110E2044A8840003C045 /* Bundle Framework */, + 3399D490228B24CF009A79C7 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 33CC11202044C79F0003C045 /* PBXTargetDependency */, + ); + name = Runner; + productName = Runner; + productReference = 33CC10ED2044A3C60003C045 /* platform_channel.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 33CC10E52044A3C60003C045 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0920; + LastUpgradeCheck = 1510; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 33CC10EC2044A3C60003C045 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1420; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; + 33CC111A2044C6BA0003C045 = { + CreatedOnToolsVersion = 9.2; + ProvisioningStyle = Manual; + }; + }; + }; + buildConfigurationList = 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 33CC10E42044A3C60003C045; + productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 33CC10EC2044A3C60003C045 /* Runner */, + 33CC111A2044C6BA0003C045 /* Flutter Assemble */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 33CC10EB2044A3C60003C045 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */, + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3399D490228B24CF009A79C7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; + }; + 33CC111E2044C6BF0003C045 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + Flutter/ephemeral/FlutterInputs.xcfilelist, + ); + inputPaths = ( + Flutter/ephemeral/tripwire, + ); + outputFileListPaths = ( + Flutter/ephemeral/FlutterOutputs.xcfilelist, + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 33CC10E92044A3C60003C045 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */, + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */, + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */, + 3BCBDA4429CA221F00E88DEA /* PowerSource.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 33CC11202044C79F0003C045 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC111A2044C6BA0003C045 /* Flutter Assemble */; + targetProxy = 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 33CC10F42044A3C60003C045 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 33CC10F52044A3C60003C045 /* Base */, + ); + name = MainMenu.xib; + path = Runner; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 338D0CE9231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Profile; + }; + 338D0CEA231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Profile; + }; + 338D0CEB231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Profile; + }; + 33CC10F92044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 33CC10FA2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 33CC10FC2044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 33CC10FD2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 33CC111C2044C6BA0003C045 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 33CC111D2044C6BA0003C045 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10F92044A3C60003C045 /* Debug */, + 33CC10FA2044A3C60003C045 /* Release */, + 338D0CE9231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10FC2044A3C60003C045 /* Debug */, + 33CC10FD2044A3C60003C045 /* Release */, + 338D0CEA231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC111C2044C6BA0003C045 /* Debug */, + 33CC111D2044C6BA0003C045 /* Release */, + 338D0CEB231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 33CC10E52044A3C60003C045 /* Project object */; +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000000000000000000000000000000000..18d981003d68d0546c4804ac2ff47dd97c6e7921 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000000000000000000000000000000000000..8d923f3b2bbce015fd092da2a7f1e240708abb28 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcworkspace/contents.xcworkspacedata b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000000000000000000000000000000000..1d526a16ed0f1cd0c2409d848bf489b93fefa3b2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000000000000000000000000000000000..18d981003d68d0546c4804ac2ff47dd97c6e7921 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/AppDelegate.swift b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/AppDelegate.swift new file mode 100644 index 0000000000000000000000000000000000000000..d080d41951d3506a861ceadcf4354bbbb609a562 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Cocoa +import FlutterMacOS + +@NSApplicationMain +class AppDelegate: FlutterAppDelegate { + override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return true + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Assets.xcassets/Contents.json b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Assets.xcassets/Contents.json new file mode 100644 index 0000000000000000000000000000000000000000..73c00596a7fca3f3d4bdd64053b69d86745f9e10 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Base.lproj/MainMenu.xib b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Base.lproj/MainMenu.xib new file mode 100644 index 0000000000000000000000000000000000000000..80e867a4e06b4dc26d0a2b327cbd54041addc50a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Base.lproj/MainMenu.xib @@ -0,0 +1,343 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/AppInfo.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/AppInfo.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..3082e17f61e0f3affcdaed508af6e9361f336f14 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/AppInfo.xcconfig @@ -0,0 +1,14 @@ +// Application-level settings for the Runner target. +// +// This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the +// future. If not, the values below would default to using the project name when this becomes a +// 'flutter create' template. + +// The application's name. By default this is also the title of the Flutter window. +PRODUCT_NAME = platform_channel + +// The application's bundle identifier +PRODUCT_BUNDLE_IDENTIFIER = com.example.platformChannel + +// The copyright displayed in application information +PRODUCT_COPYRIGHT = Copyright © 2014 The Flutter Authors. All rights reserved. diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/Debug.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/Debug.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..36b0fd9464f45b33f482e64bea579787e142affa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/Debug.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Debug.xcconfig" +#include "Warnings.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/Release.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/Release.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..dff4f49561c816f70eaea557d889d31cf63447ac --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/Release.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Release.xcconfig" +#include "Warnings.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/Warnings.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/Warnings.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..42bcbf4780b187e80025b7917058bcb882012aa1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Configs/Warnings.xcconfig @@ -0,0 +1,13 @@ +WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings +GCC_WARN_UNDECLARED_SELECTOR = YES +CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES +CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES +CLANG_WARN_PRAGMA_PACK = YES +CLANG_WARN_STRICT_PROTOTYPES = YES +CLANG_WARN_COMMA = YES +GCC_WARN_STRICT_SELECTOR_MATCH = YES +CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES +GCC_WARN_SHADOW = YES +CLANG_WARN_UNREACHABLE_CODE = YES diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/DebugProfile.entitlements b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/DebugProfile.entitlements new file mode 100644 index 0000000000000000000000000000000000000000..dddb8a30c851e7ef5b16a9108934bd1217b6b43f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/DebugProfile.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.cs.allow-jit + + com.apple.security.network.server + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Info.plist b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..4789daa6a443eefa7f3f729164a18351e06e9800 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + $(PRODUCT_COPYRIGHT) + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/MainFlutterWindow.swift b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/MainFlutterWindow.swift new file mode 100644 index 0000000000000000000000000000000000000000..239c019ddf57b5d53dda2b309aec1686a9a3a5d8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/MainFlutterWindow.swift @@ -0,0 +1,97 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Cocoa +import FlutterMacOS + +class MainFlutterWindow: NSWindow { + private let powerSource = PowerSource() + private let stateChangeHandler = PowerSourceStateChangeHandler() + private var eventSink: FlutterEventSink? + + override func awakeFromNib() { + let flutterViewController = FlutterViewController() + let windowFrame = self.frame + self.contentViewController = flutterViewController + self.displayIfNeeded() + self.setFrame(windowFrame, display: true) + + // Register battery method channel. + let registrar = flutterViewController.registrar(forPlugin: "BatteryLevel") + let batteryChannel = FlutterMethodChannel( + name: "samples.flutter.io/battery", + binaryMessenger: registrar.messenger) + batteryChannel.setMethodCallHandler { [powerSource = self.powerSource] (call, result) in + switch call.method { + case "getBatteryLevel": + guard powerSource.hasBattery() else { + result( + FlutterError( + code: "NO_BATTERY", + message: "Device does not have a battery", + details: nil)) + return + } + guard let level = powerSource.getCurrentCapacity() else { + result( + FlutterError( + code: "UNAVAILABLE", + message: "Battery info unavailable", + details: nil)) + return + } + result(level) + default: + result(FlutterMethodNotImplemented) + } + } + + // Register charging event channel. + let chargingChannel = FlutterEventChannel( + name: "samples.flutter.io/charging", + binaryMessenger: registrar.messenger) + chargingChannel.setStreamHandler(self) + + RegisterGeneratedPlugins(registry: flutterViewController) + + super.awakeFromNib() + } + + /// Emit a power status event to the registered event sink. + func emitPowerStatusEvent() { + if let sink = self.eventSink { + switch self.powerSource.getPowerState() { + case .ac: + sink("charging") + case .battery: + sink("discharging") + case .unknown: + sink("UNAVAILABLE") + } + } + } +} + +extension MainFlutterWindow: FlutterStreamHandler { + func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) + -> FlutterError? + { + self.eventSink = events + self.emitPowerStatusEvent() + self.stateChangeHandler.delegate = self + return nil + } + + func onCancel(withArguments arguments: Any?) -> FlutterError? { + self.stateChangeHandler.delegate = nil + self.eventSink = nil + return nil + } +} + +extension MainFlutterWindow: PowerSourceStateChangeDelegate { + func didChangePowerSourceState() { + self.emitPowerStatusEvent() + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/PowerSource.swift b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/PowerSource.swift new file mode 100644 index 0000000000000000000000000000000000000000..c465b2a611f812b5df21c69880c5c1850f085eab --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/PowerSource.swift @@ -0,0 +1,85 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Foundation +import IOKit.ps + +enum PowerState { + case ac + case battery + case unknown +} + +/// A convenience wrapper for an IOKit power source. +final class PowerSource { + let info = IOPSCopyPowerSourcesInfo().takeRetainedValue() + let sources: Array + + init() { + sources = IOPSCopyPowerSourcesList(info).takeRetainedValue() as Array + } + + func hasBattery() -> Bool { + return !sources.isEmpty + } + + /// Returns the current power source capacity. Apple-defined power sources will return this value + /// as a percentage. + func getCurrentCapacity() -> Int? { + if let source = sources.first { + let description = + IOPSGetPowerSourceDescription(info, source).takeUnretainedValue() as! [String: AnyObject] + if let level = description[kIOPSCurrentCapacityKey] as? Int { + return level + } + } + return nil + } + + /// Returns whether the device is drawing battery power or connected to an external power source. + func getPowerState() -> PowerState { + if let source = sources.first { + let description = + IOPSGetPowerSourceDescription(info, source).takeUnretainedValue() as! [String: AnyObject] + if let state = description[kIOPSPowerSourceStateKey] as? String { + switch state { + case kIOPSACPowerValue: + return .ac + case kIOPSBatteryPowerValue: + return .battery + default: + return .unknown + } + } + } + return .unknown + } +} + +protocol PowerSourceStateChangeDelegate: AnyObject { + func didChangePowerSourceState() +} + +/// A listener for system power source state change events. Notifies the delegate on each event. +final class PowerSourceStateChangeHandler { + private var runLoopSource: CFRunLoopSource? + weak var delegate: PowerSourceStateChangeDelegate? + + init() { + let context = UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()) + self.runLoopSource = IOPSNotificationCreateRunLoopSource( + { (context: UnsafeMutableRawPointer?) in + let unownedSelf = Unmanaged.fromOpaque( + UnsafeRawPointer(context!) + ).takeUnretainedValue() + unownedSelf.delegate?.didChangePowerSourceState() + }, context + ).takeRetainedValue() + CFRunLoopAddSource(CFRunLoopGetCurrent(), self.runLoopSource, .defaultMode) + } + + deinit { + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), self.runLoopSource, .defaultMode) + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Release.entitlements b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Release.entitlements new file mode 100644 index 0000000000000000000000000000000000000000..852fa1a4728ae4789e3bca55dd07caef3b41f2a5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/macos/Runner/Release.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.security.app-sandbox + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/platform_channel.iml b/novelforge-project/agent-workspace/flutter/examples/platform_channel/platform_channel.iml new file mode 100644 index 0000000000000000000000000000000000000000..1d83ed3abc9085f991ca3f8f864f38df5577a8a6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/platform_channel.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/pubspec.lock b/novelforge-project/agent-workspace/flutter/examples/platform_channel/pubspec.lock new file mode 100644 index 0000000000000000000000000000000000000000..ad1b0b9a0996e1d4cf90d2df5ba990b0823723d3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/pubspec.lock @@ -0,0 +1,494 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: "direct dev" + description: + name: _fe_analyzer_shared + sha256: "36a321c3d2cbe01cbcb3540a87b8843846e0206df3e691fa7b23e19e78de6d49" + url: "https://pub.dev" + source: hosted + version: "65.0.0" + analyzer: + dependency: "direct dev" + description: + name: analyzer + sha256: dfe03b90ec022450e22513b5e5ca1f01c0c01de9c3fba2f7fd233cb57a6b9a07 + url: "https://pub.dev" + source: hosted + version: "6.3.0" + args: + dependency: "direct dev" + description: + name: args + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" + source: hosted + version: "2.4.2" + async: + dependency: "direct dev" + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: "direct dev" + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: "direct main" + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: "direct dev" + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: "direct dev" + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: "direct dev" + description: + name: coverage + sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76" + url: "https://pub.dev" + source: hosted + version: "1.7.2" + crypto: + dependency: "direct dev" + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + fake_async: + dependency: "direct dev" + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + file: + dependency: "direct dev" + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_driver: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + frontend_server_client: + dependency: "direct dev" + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + fuchsia_remote_debug_protocol: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + glob: + dependency: "direct dev" + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + http_multi_server: + dependency: "direct dev" + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: "direct dev" + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: "direct dev" + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: "direct dev" + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + leak_tracker: + dependency: "direct dev" + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: "direct dev" + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: "direct dev" + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + logging: + dependency: "direct dev" + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: "direct dev" + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: "direct main" + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: "direct main" + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + mime: + dependency: "direct dev" + description: + name: mime + sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + url: "https://pub.dev" + source: hosted + version: "1.0.4" + node_preamble: + dependency: "direct dev" + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: "direct dev" + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: "direct dev" + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + platform: + dependency: transitive + description: + name: platform + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + url: "https://pub.dev" + source: hosted + version: "3.1.4" + pool: + dependency: "direct dev" + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + process: + dependency: transitive + description: + name: process + sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32" + url: "https://pub.dev" + source: hosted + version: "5.0.2" + pub_semver: + dependency: "direct dev" + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + shelf: + dependency: "direct dev" + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: "direct dev" + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: "direct dev" + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: "direct dev" + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_map_stack_trace: + dependency: "direct dev" + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: "direct dev" + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" + source_span: + dependency: "direct dev" + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: "direct dev" + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: "direct dev" + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: "direct dev" + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + sync_http: + dependency: "direct dev" + description: + name: sync_http + sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961" + url: "https://pub.dev" + source: hosted + version: "0.3.1" + term_glyph: + dependency: "direct dev" + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f + url: "https://pub.dev" + source: hosted + version: "1.24.9" + test_api: + dependency: "direct dev" + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + test_core: + dependency: "direct dev" + description: + name: test_core + sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a + url: "https://pub.dev" + source: hosted + version: "0.5.9" + typed_data: + dependency: "direct dev" + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: "direct dev" + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" + watcher: + dependency: "direct dev" + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web: + dependency: "direct dev" + description: + name: web + sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa + url: "https://pub.dev" + source: hosted + version: "0.4.0" + web_socket_channel: + dependency: "direct dev" + description: + name: web_socket_channel + sha256: "045ec2137c27bf1a32e6ffa0e734d532a6677bf9016a0d1a406c54e499ff945b" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + webdriver: + dependency: "direct dev" + description: + name: webdriver + sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + webkit_inspection_protocol: + dependency: "direct dev" + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: "direct dev" + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.2.0 <4.0.0" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/pubspec.yaml b/novelforge-project/agent-workspace/flutter/examples/platform_channel/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3486f86b7a2ee94d622cb330645c075a1c0f921f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/pubspec.yaml @@ -0,0 +1,77 @@ +name: platform_channel + +environment: + sdk: '>=3.2.0-0 <4.0.0' + +dependencies: + flutter: + sdk: flutter + + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_driver: + sdk: flutter + test: 1.24.9 + + _fe_analyzer_shared: 65.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + analyzer: 6.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + args: 2.4.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + convert: 3.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + coverage: 1.7.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + crypto: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + file: 7.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + frontend_server_client: 3.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + glob: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_multi_server: 3.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_parser: 4.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + io: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + js: 0.6.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker: 10.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_flutter_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + logging: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + matcher: 0.12.16+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + mime: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + node_preamble: 2.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + package_config: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + path: 1.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pool: 1.5.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pub_semver: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf: 1.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_packages_handler: 3.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_static: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_web_socket: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_map_stack_trace: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_maps: 0.10.12 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + sync_http: 0.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_core: 0.5.9 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + typed_data: 1.3.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + watcher: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web_socket_channel: 2.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webdriver: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + yaml: 3.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +flutter: + uses-material-design: true + +# PUBSPEC CHECKSUM: 6020 diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/test_driver/button_tap.dart b/novelforge-project/agent-workspace/flutter/examples/platform_channel/test_driver/button_tap.dart new file mode 100644 index 0000000000000000000000000000000000000000..7e1dc1cd5f8071b678ba57a0b0cf4a9993f074d3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/test_driver/button_tap.dart @@ -0,0 +1,11 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_driver/driver_extension.dart'; +import 'package:platform_channel/main.dart' as app; + +void main() { + enableFlutterDriverExtension(); + app.main(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/test_driver/button_tap_test.dart b/novelforge-project/agent-workspace/flutter/examples/platform_channel/test_driver/button_tap_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..be36536c5632d2ae99213af841110df97d2a737a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/test_driver/button_tap_test.dart @@ -0,0 +1,41 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_driver/flutter_driver.dart'; +import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; + +void main() { + group('button tap test', () { + late FlutterDriver driver; + + setUpAll(() async { + driver = await FlutterDriver.connect(); + }); + + tearDownAll(() async { + driver.close(); + }); + + test('tap on the button, verify result', () async { + final SerializableFinder batteryLevelLabel = + find.byValueKey('Battery level label'); + expect(batteryLevelLabel, isNotNull); + + final SerializableFinder button = find.text('Refresh'); + await driver.waitFor(button); + await driver.tap(button); + + String? batteryLevel; + while (batteryLevel == null || batteryLevel.contains('unknown')) { + batteryLevel = await driver.getText(batteryLevelLabel); + } + + // Allow either a battery percentage or "No battery" since it will vary + // by device; either indicates that a known response came from the host + // implementation. + expect(batteryLevel.contains('%') || batteryLevel.contains('No battery'), + isTrue); + }); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a8a64c8d510c1dc742ab97dca53b9d46538650d4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/CMakeLists.txt @@ -0,0 +1,101 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.14) +project(platform_channel LANGUAGES CXX) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "platform_channel") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(VERSION 3.14...3.25) + +# Define build configuration option. +get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(IS_MULTICONFIG) + set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" + CACHE STRING "" FORCE) +else() + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") + endif() +endif() +# Define settings for the Profile build mode. +set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") +set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") +set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") + +# Use Unicode for all projects. +add_definitions(-DUNICODE -D_UNICODE) + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_17) + target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") + target_compile_options(${TARGET} PRIVATE /EHsc) + target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") + target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# Application build; see runner/CMakeLists.txt. +add_subdirectory("runner") + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# Support files are copied into place next to the executable, so that it can +# run in place. This is done instead of making a separate bundle (as on Linux) +# so that building and running from within Visual Studio will work. +set(BUILD_BUNDLE_DIR "$") +# Make the "install" step default, as it's required to run. +set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + CONFIGURATIONS Profile;Release + COMPONENT Runtime) diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/flutter/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/flutter/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..903f4899d6fced0eb941e159f7322b21b320c40c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/flutter/CMakeLists.txt @@ -0,0 +1,109 @@ +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.14) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. +set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") + +# Set fallback configurations for older versions of the flutter tool. +if (NOT DEFINED FLUTTER_TARGET_PLATFORM) + set(FLUTTER_TARGET_PLATFORM "windows-x64") +endif() + +# === Flutter Library === +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "flutter_export.h" + "flutter_windows.h" + "flutter_messenger.h" + "flutter_plugin_registrar.h" + "flutter_texture_registrar.h" +) +list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") +add_dependencies(flutter flutter_assemble) + +# === Wrapper === +list(APPEND CPP_WRAPPER_SOURCES_CORE + "core_implementations.cc" + "standard_codec.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_PLUGIN + "plugin_registrar.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_APP + "flutter_engine.cc" + "flutter_view_controller.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") + +# Wrapper sources needed for a plugin. +add_library(flutter_wrapper_plugin STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} +) +apply_standard_settings(flutter_wrapper_plugin) +set_target_properties(flutter_wrapper_plugin PROPERTIES + POSITION_INDEPENDENT_CODE ON) +set_target_properties(flutter_wrapper_plugin PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) +target_include_directories(flutter_wrapper_plugin PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_plugin flutter_assemble) + +# Wrapper sources needed for the runner. +add_library(flutter_wrapper_app STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_APP} +) +apply_standard_settings(flutter_wrapper_app) +target_link_libraries(flutter_wrapper_app PUBLIC flutter) +target_include_directories(flutter_wrapper_app PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_app flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") +set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} + ${PHONY_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" + ${FLUTTER_TARGET_PLATFORM} $ + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} +) diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..394917c053a04daa76d8b94f0a02db0bd99e1034 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.14) +project(runner LANGUAGES CXX) + +# Define the application target. To change its name, change BINARY_NAME in the +# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer +# work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} WIN32 + "flutter_window.cpp" + "main.cpp" + "utils.cpp" + "win32_window.cpp" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" + "Runner.rc" + "runner.exe.manifest" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add preprocessor definitions for the build version. +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") + +# Disable Windows macros that collide with C++ standard library functions. +target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") + +# Add dependency libraries and include directories. Add any application-specific +# dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) +target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/Runner.rc b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/Runner.rc new file mode 100644 index 0000000000000000000000000000000000000000..66e11ee9f436eea02dcaba07c6bd52ad26eaf8a8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/Runner.rc @@ -0,0 +1,111 @@ +// Microsoft Visual C++ generated resource script. +// +#pragma code_page(65001) +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) +#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD +#else +#define VERSION_AS_NUMBER 1,0,0,0 +#endif + +#if defined(FLUTTER_VERSION) +#define VERSION_AS_STRING FLUTTER_VERSION +#else +#define VERSION_AS_STRING "1.0.0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VERSION_AS_NUMBER + PRODUCTVERSION VERSION_AS_NUMBER + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "io.flutter.examples" "\0" + VALUE "FileDescription", "platform_channel" "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "platform_channel" "\0" + VALUE "LegalCopyright", "Copyright (C) 2022 io.flutter.examples. All rights reserved." "\0" + VALUE "OriginalFilename", "platform_channel.exe" "\0" + VALUE "ProductName", "platform_channel" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/flutter_window.cpp b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/flutter_window.cpp new file mode 100644 index 0000000000000000000000000000000000000000..97c041167a9c37b07805e0557dbc430b05b5e2b9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/flutter_window.cpp @@ -0,0 +1,161 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter_window.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "flutter/generated_plugin_registrant.h" + +static constexpr int kBatteryError = -1; +static constexpr int kNoBattery = -2; + +static int GetBatteryLevel() { + SYSTEM_POWER_STATUS status; + if (GetSystemPowerStatus(&status) == 0) { + return kBatteryError; + } else if (status.BatteryFlag == 128) { + return kNoBattery; + } else if (status.BatteryLifePercent == 255) { + return kBatteryError; + } + return status.BatteryLifePercent; +} + +FlutterWindow::FlutterWindow(const flutter::DartProject& project) + : project_(project) {} + +FlutterWindow::~FlutterWindow() { + if (power_notification_handle_) { + UnregisterPowerSettingNotification(power_notification_handle_); + } +} + +bool FlutterWindow::OnCreate() { + if (!Win32Window::OnCreate()) { + return false; + } + + RECT frame = GetClientArea(); + + // The size here must match the window dimensions to avoid unnecessary surface + // creation / destruction in the startup path. + flutter_controller_ = std::make_unique( + frame.right - frame.left, frame.bottom - frame.top, project_); + // Ensure that basic setup of the controller was successful. + if (!flutter_controller_->engine() || !flutter_controller_->view()) { + return false; + } + RegisterPlugins(flutter_controller_->engine()); + + flutter::MethodChannel<> channel( + flutter_controller_->engine()->messenger(), "samples.flutter.io/battery", + &flutter::StandardMethodCodec::GetInstance()); + channel.SetMethodCallHandler( + [](const flutter::MethodCall<>& call, + std::unique_ptr> result) { + if (call.method_name() == "getBatteryLevel") { + int battery_level = GetBatteryLevel(); + + if (battery_level == kBatteryError) { + result->Error("UNAVAILABLE", "Battery level not available."); + } else if (battery_level == kNoBattery) { + result->Error("NO_BATTERY", "Device does not have a battery."); + } else { + result->Success(battery_level); + } + } else { + result->NotImplemented(); + } + }); + + flutter::EventChannel<> charging_channel( + flutter_controller_->engine()->messenger(), "samples.flutter.io/charging", + &flutter::StandardMethodCodec::GetInstance()); + charging_channel.SetStreamHandler( + std::make_unique>( + [this](auto arguments, auto events) { + this->OnStreamListen(std::move(events)); + return nullptr; + }, + [this](auto arguments) { + this->OnStreamCancel(); + return nullptr; + })); + + SetChildContent(flutter_controller_->view()->GetNativeWindow()); + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + this->Show(); + }); + + // Flutter can complete the first frame before the "show window" callback is + // registered. The following call ensures a frame is pending to ensure the + // window is shown. It is a no-op if the first frame hasn't completed yet. + flutter_controller_->ForceRedraw(); + + return true; +} + +void FlutterWindow::OnDestroy() { + if (flutter_controller_) { + flutter_controller_ = nullptr; + } + + Win32Window::OnDestroy(); +} + +LRESULT +FlutterWindow::MessageHandler(HWND hwnd, UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + // Give Flutter, including plugins, an opportunity to handle window messages. + if (flutter_controller_) { + std::optional result = + flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, + lparam); + if (result) { + return *result; + } + } + + switch (message) { + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; + case WM_POWERBROADCAST: + SendBatteryStateEvent(); + break; + } + + return Win32Window::MessageHandler(hwnd, message, wparam, lparam); +} + +void FlutterWindow::OnStreamListen( + std::unique_ptr>&& events) { + event_sink_ = std::move(events); + SendBatteryStateEvent(); + power_notification_handle_ = + RegisterPowerSettingNotification(GetHandle(), &GUID_ACDC_POWER_SOURCE, 0); +} + +void FlutterWindow::OnStreamCancel() { event_sink_ = nullptr; } + +void FlutterWindow::SendBatteryStateEvent() { + SYSTEM_POWER_STATUS status; + if (GetSystemPowerStatus(&status) == 0 || status.ACLineStatus == 255) { + event_sink_->Error("UNAVAILABLE", "Charging status unavailable"); + } else { + event_sink_->Success(flutter::EncodableValue( + status.ACLineStatus == 1 ? "charging" : "discharging")); + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/flutter_window.h b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/flutter_window.h new file mode 100644 index 0000000000000000000000000000000000000000..f1175559ab9d6f99cddd96a34260c1f7053659a0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/flutter_window.h @@ -0,0 +1,49 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef RUNNER_FLUTTER_WINDOW_H_ +#define RUNNER_FLUTTER_WINDOW_H_ + +#include +#include +#include +#include + +#include + +#include "win32_window.h" + +// A window that does nothing but host a Flutter view. +class FlutterWindow : public Win32Window { + public: + // Creates a new FlutterWindow hosting a Flutter view running |project|. + explicit FlutterWindow(const flutter::DartProject& project); + virtual ~FlutterWindow(); + + protected: + // Win32Window: + bool OnCreate() override; + void OnDestroy() override; + LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, + LPARAM const lparam) noexcept override; + + private: + // EventStream handlers: + void OnStreamListen(std::unique_ptr>&& events); + void OnStreamCancel(); + + // Sends a state event to |event_sink_| with the current charging status. + void SendBatteryStateEvent(); + + // The project to run. + flutter::DartProject project_; + + // The Flutter instance hosted by this window. + std::unique_ptr flutter_controller_; + + std::unique_ptr> event_sink_; + HPOWERNOTIFY power_notification_handle_ = nullptr; +}; + +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/main.cpp b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1cadf8d747d7aee7b6447ba70ff17a5647fd3fbc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/main.cpp @@ -0,0 +1,46 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include +#include +#include + +#include "flutter_window.h" +#include "utils.h" + +int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, + _In_ wchar_t* command_line, _In_ int show_command) { + // Attach to console when present (e.g., 'flutter run') or create a + // new console when running with a debugger. + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { + CreateAndAttachConsole(); + } + + // Initialize COM, so that it is available for use in the library and/or + // plugins. + ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + flutter::DartProject project(L"data"); + + std::vector command_line_arguments = GetCommandLineArguments(); + + project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); + + FlutterWindow window(project); + Win32Window::Point origin(10, 10); + Win32Window::Size size(1280, 720); + if (!window.Create(L"platform_channel", origin, size)) { + return EXIT_FAILURE; + } + window.SetQuitOnClose(true); + + ::MSG msg; + while (::GetMessage(&msg, nullptr, 0, 0)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + + ::CoUninitialize(); + return EXIT_SUCCESS; +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/resource.h b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/resource.h new file mode 100644 index 0000000000000000000000000000000000000000..c245ff19cb5805345a3d3265122298cb01b9d71f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/resource.h @@ -0,0 +1,20 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Runner.rc +// +#define IDI_APP_ICON 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/runner.exe.manifest b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/runner.exe.manifest new file mode 100644 index 0000000000000000000000000000000000000000..a42ea7687cb67e55af955dc8874a072e087ce3ed --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/runner.exe.manifest @@ -0,0 +1,20 @@ + + + + + PerMonitorV2 + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/utils.cpp b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a05ed58ca9a52d311cdb78383eff2413889dd11f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/utils.cpp @@ -0,0 +1,68 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "utils.h" + +#include +#include +#include +#include + +#include + +void CreateAndAttachConsole() { + if (::AllocConsole()) { + FILE* unused; + if (freopen_s(&unused, "CONOUT$", "w", stdout)) { + _dup2(_fileno(stdout), 1); + } + if (freopen_s(&unused, "CONOUT$", "w", stderr)) { + _dup2(_fileno(stdout), 2); + } + std::ios::sync_with_stdio(); + FlutterDesktopResyncOutputStreams(); + } +} + +std::vector GetCommandLineArguments() { + // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. + int argc; + wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + if (argv == nullptr) { + return std::vector(); + } + + std::vector command_line_arguments; + + // Skip the first argument as it's the binary name. + for (int i = 1; i < argc; i++) { + command_line_arguments.push_back(Utf8FromUtf16(argv[i])); + } + + ::LocalFree(argv); + + return command_line_arguments; +} + +std::string Utf8FromUtf16(const wchar_t* utf16_string) { + if (utf16_string == nullptr) { + return std::string(); + } + int target_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, nullptr, 0, nullptr, nullptr) + -1; // remove the trailing null character + std::string utf8_string; + if (target_length <= 0 || target_length > utf8_string.max_size()) { + return utf8_string; + } + utf8_string.resize(target_length); + int converted_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, utf8_string.data(), target_length, nullptr, nullptr); + if (converted_length == 0) { + return std::string(); + } + return utf8_string; +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/utils.h b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/utils.h new file mode 100644 index 0000000000000000000000000000000000000000..54414c989ba716f78f3640e5407dd8ac74284aef --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/utils.h @@ -0,0 +1,23 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef RUNNER_UTILS_H_ +#define RUNNER_UTILS_H_ + +#include +#include + +// Creates a console for the process, and redirects stdout and stderr to +// it for both the runner and the Flutter library. +void CreateAndAttachConsole(); + +// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string +// encoded in UTF-8. Returns an empty std::string on failure. +std::string Utf8FromUtf16(const wchar_t* utf16_string); + +// Gets the command line arguments passed in as a std::vector, +// encoded in UTF-8. Returns an empty std::vector on failure. +std::vector GetCommandLineArguments(); + +#endif // RUNNER_UTILS_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/win32_window.cpp b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/win32_window.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14a183d7eaa272a6faf6cc8811639b68142331fa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/win32_window.cpp @@ -0,0 +1,292 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "win32_window.h" + +#include +#include + +#include "resource.h" + +namespace { + +/// Window attribute that enables dark mode window decorations. +/// +/// Redefined in case the developer's machine has a Windows SDK older than +/// version 10.0.22000.0. +/// See: https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +#endif + +constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; + +/// Registry key for app theme preference. +/// +/// A value of 0 indicates apps should use dark mode. A non-zero or missing +/// value indicates apps should use light mode. +constexpr const wchar_t kGetPreferredBrightnessRegKey[] = + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; +constexpr const wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme"; + +// The number of Win32Window objects that currently exist. +static int g_active_window_count = 0; + +using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); + +// Scale helper to convert logical scaler values to physical using passed in +// scale factor +int Scale(int source, double scale_factor) { + return static_cast(source * scale_factor); +} + +// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. +// This API is only needed for PerMonitor V1 awareness mode. +void EnableFullDpiSupportIfAvailable(HWND hwnd) { + HMODULE user32_module = LoadLibraryA("User32.dll"); + if (!user32_module) { + return; + } + auto enable_non_client_dpi_scaling = + reinterpret_cast( + GetProcAddress(user32_module, "EnableNonClientDpiScaling")); + if (enable_non_client_dpi_scaling != nullptr) { + enable_non_client_dpi_scaling(hwnd); + } + FreeLibrary(user32_module); +} + +} // namespace + +// Manages the Win32Window's window class registration. +class WindowClassRegistrar { + public: + ~WindowClassRegistrar() = default; + + // Returns the singleton registrar instance. + static WindowClassRegistrar* GetInstance() { + if (!instance_) { + instance_ = new WindowClassRegistrar(); + } + return instance_; + } + + // Returns the name of the window class, registering the class if it hasn't + // previously been registered. + const wchar_t* GetWindowClass(); + + // Unregisters the window class. Should only be called if there are no + // instances of the window. + void UnregisterWindowClass(); + + private: + WindowClassRegistrar() = default; + + static WindowClassRegistrar* instance_; + + bool class_registered_ = false; +}; + +WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; + +const wchar_t* WindowClassRegistrar::GetWindowClass() { + if (!class_registered_) { + WNDCLASS window_class{}; + window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); + window_class.lpszClassName = kWindowClassName; + window_class.style = CS_HREDRAW | CS_VREDRAW; + window_class.cbClsExtra = 0; + window_class.cbWndExtra = 0; + window_class.hInstance = GetModuleHandle(nullptr); + window_class.hIcon = + LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); + window_class.hbrBackground = 0; + window_class.lpszMenuName = nullptr; + window_class.lpfnWndProc = Win32Window::WndProc; + RegisterClass(&window_class); + class_registered_ = true; + } + return kWindowClassName; +} + +void WindowClassRegistrar::UnregisterWindowClass() { + UnregisterClass(kWindowClassName, nullptr); + class_registered_ = false; +} + +Win32Window::Win32Window() { + ++g_active_window_count; +} + +Win32Window::~Win32Window() { + --g_active_window_count; + Destroy(); +} + +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { + Destroy(); + + const wchar_t* window_class = + WindowClassRegistrar::GetInstance()->GetWindowClass(); + + const POINT target_point = {static_cast(origin.x), + static_cast(origin.y)}; + HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); + UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); + double scale_factor = dpi / 96.0; + + HWND window = CreateWindow( + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, + Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), + Scale(size.width, scale_factor), Scale(size.height, scale_factor), + nullptr, nullptr, GetModuleHandle(nullptr), this); + + if (!window) { + return false; + } + + UpdateTheme(window); + + return OnCreate(); +} + +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + +// static +LRESULT CALLBACK Win32Window::WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + if (message == WM_NCCREATE) { + auto window_struct = reinterpret_cast(lparam); + SetWindowLongPtr(window, GWLP_USERDATA, + reinterpret_cast(window_struct->lpCreateParams)); + + auto that = static_cast(window_struct->lpCreateParams); + EnableFullDpiSupportIfAvailable(window); + that->window_handle_ = window; + } else if (Win32Window* that = GetThisFromHandle(window)) { + return that->MessageHandler(window, message, wparam, lparam); + } + + return DefWindowProc(window, message, wparam, lparam); +} + +LRESULT +Win32Window::MessageHandler(HWND hwnd, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + switch (message) { + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + } + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; + + case WM_DWMCOLORIZATIONCOLORCHANGED: + UpdateTheme(hwnd); + return 0; + } + + return DefWindowProc(window_handle_, message, wparam, lparam); +} + +void Win32Window::Destroy() { + OnDestroy(); + + if (window_handle_) { + DestroyWindow(window_handle_); + window_handle_ = nullptr; + } + if (g_active_window_count == 0) { + WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); + } +} + +Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( + GetWindowLongPtr(window, GWLP_USERDATA)); +} + +void Win32Window::SetChildContent(HWND content) { + child_content_ = content; + SetParent(content, window_handle_); + RECT frame = GetClientArea(); + + MoveWindow(content, frame.left, frame.top, frame.right - frame.left, + frame.bottom - frame.top, true); + + SetFocus(child_content_); +} + +RECT Win32Window::GetClientArea() { + RECT frame; + GetClientRect(window_handle_, &frame); + return frame; +} + +HWND Win32Window::GetHandle() { + return window_handle_; +} + +void Win32Window::SetQuitOnClose(bool quit_on_close) { + quit_on_close_ = quit_on_close; +} + +bool Win32Window::OnCreate() { + // No-op; provided for subclasses. + return true; +} + +void Win32Window::OnDestroy() { + // No-op; provided for subclasses. +} + +void Win32Window::UpdateTheme(HWND const window) { + DWORD light_mode; + DWORD light_mode_size = sizeof(light_mode); + LSTATUS result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey, + kGetPreferredBrightnessRegValue, + RRF_RT_REG_DWORD, nullptr, &light_mode, + &light_mode_size); + + if (result == ERROR_SUCCESS) { + BOOL enable_dark_mode = light_mode == 0; + DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE, + &enable_dark_mode, sizeof(enable_dark_mode)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/win32_window.h b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/win32_window.h new file mode 100644 index 0000000000000000000000000000000000000000..bb93e8879162ee652a0af7e428d938ad027ddcd7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel/windows/runner/win32_window.h @@ -0,0 +1,106 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef RUNNER_WIN32_WINDOW_H_ +#define RUNNER_WIN32_WINDOW_H_ + +#include + +#include +#include +#include + +// A class abstraction for a high DPI-aware Win32 Window. Intended to be +// inherited from by classes that wish to specialize with custom +// rendering and input handling +class Win32Window { + public: + struct Point { + unsigned int x; + unsigned int y; + Point(unsigned int x, unsigned int y) : x(x), y(y) {} + }; + + struct Size { + unsigned int width; + unsigned int height; + Size(unsigned int width, unsigned int height) + : width(width), height(height) {} + }; + + Win32Window(); + virtual ~Win32Window(); + + // Creates a win32 window with |title| that is positioned and sized using + // |origin| and |size|. New windows are created on the default monitor. Window + // sizes are specified to the OS in physical pixels, hence to ensure a + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); + + // Release OS resources associated with window. + void Destroy(); + + // Inserts |content| into the window tree. + void SetChildContent(HWND content); + + // Returns the backing Window handle to enable clients to set icon and other + // window properties. Returns nullptr if the window has been destroyed. + HWND GetHandle(); + + // If true, closing this window will quit the application. + void SetQuitOnClose(bool quit_on_close); + + // Return a RECT representing the bounds of the current client area. + RECT GetClientArea(); + + protected: + // Processes and route salient window messages for mouse handling, + // size change and DPI. Delegates handling of these to member overloads that + // inheriting classes can handle. + virtual LRESULT MessageHandler(HWND window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Called when CreateAndShow is called, allowing subclass window-related + // setup. Subclasses should return false if setup fails. + virtual bool OnCreate(); + + // Called when Destroy is called. + virtual void OnDestroy(); + + private: + friend class WindowClassRegistrar; + + // OS callback called by message pump. Handles the WM_NCCREATE message which + // is passed when the non-client area is being created and enables automatic + // non-client DPI scaling so that the non-client area automatically + // responds to changes in DPI. All other messages are handled by + // MessageHandler. + static LRESULT CALLBACK WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Retrieves a class instance pointer for |window| + static Win32Window* GetThisFromHandle(HWND const window) noexcept; + + // Update the window frame's theme to match the system theme. + static void UpdateTheme(HWND const window); + + bool quit_on_close_ = false; + + // window handle for top level window. + HWND window_handle_ = nullptr; + + // window handle for hosted content. + HWND child_content_ = nullptr; +}; + +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/README.md b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/README.md new file mode 100644 index 0000000000000000000000000000000000000000..da415d80ba0d3e4546c8c8eed410e19466ee3408 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/README.md @@ -0,0 +1,18 @@ +# Example of calling platform services from Flutter + +This project demonstrates how to connect a Flutter app to platform-specific +services on iOS using Swift. The equivalent version of this project in +Objective C is found in examples/platform_channel. + +You can read more about +[accessing platform and third-party services in Flutter](https://flutter.dev/platform-channels/). + +## iOS + +You can use the commands `flutter build` and `flutter run` from the app's root +directory to build/run the app or you can open `ios/Runner.xcworkspace` in Xcode +and build/run the project as usual. + +## Android + +We refer to the platform_channel project. diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Flutter/AppFrameworkInfo.plist b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 0000000000000000000000000000000000000000..8c6e56146e23c84aa60ea78f20bc3a7b3d8ef259 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + MinimumOSVersion + 12.0 + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Flutter/Debug.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Flutter/Debug.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..592ceee85b89bd111b779db6116b130509ab6d4b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Flutter/Debug.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Flutter/Release.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Flutter/Release.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..592ceee85b89bd111b779db6116b130509ab6d4b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Flutter/Release.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/project.pbxproj b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000000000000000000000000000000000000..36bcf9a59f4d9d3b5a28ef4227cf54d7bc726871 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,484 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXBuildFile section */ + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 3BAEBBFF1EBA9DA300EE9294 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BAEBBFE1EBA9DA300EE9294 /* AppDelegate.swift */; }; + 74970F6B1EDC12EC000507F3 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 74970F6A1EDC12EC000507F3 /* GeneratedPluginRegistrant.m */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 3BAEBBFE1EBA9DA300EE9294 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 3BAEBC001EBA9DCA00EE9294 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; + 74970F691EDC12EC000507F3 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 74970F6A1EDC12EC000507F3 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + CF3B75C9A7D2FA2A4C99F110 /* Frameworks */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 74970F691EDC12EC000507F3 /* GeneratedPluginRegistrant.h */, + 74970F6A1EDC12EC000507F3 /* GeneratedPluginRegistrant.m */, + 3BAEBBFE1EBA9DA300EE9294 /* AppDelegate.swift */, + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 3BAEBC001EBA9DCA00EE9294 /* Runner-Bridging-Header.h */, + 97C146F11CF9000F007C117D /* Supporting Files */, + ); + path = Runner; + sourceTree = ""; + }; + 97C146F11CF9000F007C117D /* Supporting Files */ = { + isa = PBXGroup; + children = ( + ); + name = "Supporting Files"; + sourceTree = ""; + }; + CF3B75C9A7D2FA2A4C99F110 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1510; + ORGANIZATIONNAME = "The Flutter Authors"; + TargetAttributes = { + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 1100; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3BAEBBFF1EBA9DA300EE9294 /* AppDelegate.swift in Sources */, + 74970F6B1EDC12EC000507F3 /* GeneratedPluginRegistrant.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 2470A27921828D8700ACAC9C /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Profile; + }; + 2470A27A21828D8700ACAC9C /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.example.PlatformChannelSwift; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Profile; + }; + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.example.PlatformChannelSwift; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.example.PlatformChannelSwift; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + 2470A27921828D8700ACAC9C /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + 2470A27A21828D8700ACAC9C /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000000000000000000000000000000000..919434a6254f0e9651f402737811be6634a03e9c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000000000000000000000000000000000..18d981003d68d0546c4804ac2ff47dd97c6e7921 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000000000000000000000000000000000000..e67b2808af02f9ec16f2d72b7961aefdf844afa5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcworkspace/contents.xcworkspacedata b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000000000000000000000000000000000..1d526a16ed0f1cd0c2409d848bf489b93fefa3b2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/AppDelegate.swift b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/AppDelegate.swift new file mode 100644 index 0000000000000000000000000000000000000000..f5eadb6930270ce535b086e2452d59c82f468d08 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/AppDelegate.swift @@ -0,0 +1,103 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import UIKit +import Flutter + +enum ChannelName { + static let battery = "samples.flutter.io/battery" + static let charging = "samples.flutter.io/charging" +} + +enum BatteryState { + static let charging = "charging" + static let discharging = "discharging" +} + +enum MyFlutterErrorCode { + static let unavailable = "UNAVAILABLE" +} + +@UIApplicationMain +@objc class AppDelegate: FlutterAppDelegate, FlutterStreamHandler { + private var eventSink: FlutterEventSink? + + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + GeneratedPluginRegistrant.register(with: self) + guard let controller = window?.rootViewController as? FlutterViewController else { + fatalError("rootViewController is not type FlutterViewController") + } + let batteryChannel = FlutterMethodChannel(name: ChannelName.battery, + binaryMessenger: controller.binaryMessenger) + batteryChannel.setMethodCallHandler({ + [weak self] (call: FlutterMethodCall, result: FlutterResult) -> Void in + guard call.method == "getBatteryLevel" else { + result(FlutterMethodNotImplemented) + return + } + self?.receiveBatteryLevel(result: result) + }) + + let chargingChannel = FlutterEventChannel(name: ChannelName.charging, + binaryMessenger: controller.binaryMessenger) + chargingChannel.setStreamHandler(self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } + + private func receiveBatteryLevel(result: FlutterResult) { + let device = UIDevice.current + device.isBatteryMonitoringEnabled = true + guard device.batteryState != .unknown else { + result(FlutterError(code: MyFlutterErrorCode.unavailable, + message: "Battery info unavailable", + details: nil)) + return + } + result(Int(device.batteryLevel * 100)) + } + + public func onListen(withArguments arguments: Any?, + eventSink: @escaping FlutterEventSink) -> FlutterError? { + self.eventSink = eventSink + UIDevice.current.isBatteryMonitoringEnabled = true + sendBatteryStateEvent() + NotificationCenter.default.addObserver( + self, + selector: #selector(AppDelegate.onBatteryStateDidChange), + name: UIDevice.batteryStateDidChangeNotification, + object: nil) + return nil + } + + @objc private func onBatteryStateDidChange(notification: NSNotification) { + sendBatteryStateEvent() + } + + private func sendBatteryStateEvent() { + guard let eventSink = eventSink else { + return + } + + switch UIDevice.current.batteryState { + case .full: + eventSink(BatteryState.charging) + case .charging: + eventSink(BatteryState.charging) + case .unplugged: + eventSink(BatteryState.discharging) + default: + eventSink(FlutterError(code: MyFlutterErrorCode.unavailable, + message: "Charging status unavailable", + details: nil)) + } + } + + public func onCancel(withArguments arguments: Any?) -> FlutterError? { + NotificationCenter.default.removeObserver(self) + eventSink = nil + return nil + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000000000000000000000000000000000..1d060ed28827ed6aca9565d946e6b5595c8978df --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,93 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Base.lproj/LaunchScreen.storyboard b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000000000000000000000000000000000000..ebf48f6039745ccdb57ad6237321024eb6cdf9af --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Base.lproj/Main.storyboard b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 0000000000000000000000000000000000000000..f3c28516fb38e64d88cfcf5fb1791175df078f2f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Info.plist b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..97a48d5f7b0c45327f5381bdafd85f70966c9735 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + PlatformChannel + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Runner-Bridging-Header.h b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Runner-Bridging-Header.h new file mode 100644 index 0000000000000000000000000000000000000000..95b7baf386d06a38be9c775a9e97659baad52dc5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/ios/Runner/Runner-Bridging-Header.h @@ -0,0 +1,5 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "GeneratedPluginRegistrant.h" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/lib/main.dart b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..ada6ab5b592368d6e1a8ae4d820514163c38ea81 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/lib/main.dart @@ -0,0 +1,86 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +class PlatformChannel extends StatefulWidget { + const PlatformChannel({super.key}); + + @override + State createState() => _PlatformChannelState(); +} + +class _PlatformChannelState extends State { + static const MethodChannel methodChannel = + MethodChannel('samples.flutter.io/battery'); + static const EventChannel eventChannel = + EventChannel('samples.flutter.io/charging'); + + String _batteryLevel = 'Battery level: unknown.'; + String _chargingStatus = 'Battery status: unknown.'; + + Future _getBatteryLevel() async { + String batteryLevel; + try { + final int? result = await methodChannel.invokeMethod('getBatteryLevel'); + batteryLevel = 'Battery level: $result%.'; + } on PlatformException { + batteryLevel = 'Failed to get battery level.'; + } + setState(() { + _batteryLevel = batteryLevel; + }); + } + + @override + void initState() { + super.initState(); + eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); + } + + void _onEvent(Object? event) { + setState(() { + _chargingStatus = + "Battery status: ${event == 'charging' ? '' : 'dis'}charging."; + }); + } + + void _onError(Object error) { + setState(() { + _chargingStatus = 'Battery status: unknown.'; + }); + } + + @override + Widget build(BuildContext context) { + return Material( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(_batteryLevel, key: const Key('Battery level label')), + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: _getBatteryLevel, + child: const Text('Refresh'), + ), + ), + ], + ), + Text(_chargingStatus), + ], + ), + ); + } +} + +void main() { + runApp(const MaterialApp(home: PlatformChannel())); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/platform_channel_swift.iml b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/platform_channel_swift.iml new file mode 100644 index 0000000000000000000000000000000000000000..1d83ed3abc9085f991ca3f8f864f38df5577a8a6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/platform_channel_swift.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/pubspec.lock b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/pubspec.lock new file mode 100644 index 0000000000000000000000000000000000000000..ad1b0b9a0996e1d4cf90d2df5ba990b0823723d3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/pubspec.lock @@ -0,0 +1,494 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: "direct dev" + description: + name: _fe_analyzer_shared + sha256: "36a321c3d2cbe01cbcb3540a87b8843846e0206df3e691fa7b23e19e78de6d49" + url: "https://pub.dev" + source: hosted + version: "65.0.0" + analyzer: + dependency: "direct dev" + description: + name: analyzer + sha256: dfe03b90ec022450e22513b5e5ca1f01c0c01de9c3fba2f7fd233cb57a6b9a07 + url: "https://pub.dev" + source: hosted + version: "6.3.0" + args: + dependency: "direct dev" + description: + name: args + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" + source: hosted + version: "2.4.2" + async: + dependency: "direct dev" + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: "direct dev" + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: "direct main" + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: "direct dev" + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: "direct dev" + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: "direct dev" + description: + name: coverage + sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76" + url: "https://pub.dev" + source: hosted + version: "1.7.2" + crypto: + dependency: "direct dev" + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + fake_async: + dependency: "direct dev" + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + file: + dependency: "direct dev" + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_driver: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + frontend_server_client: + dependency: "direct dev" + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + fuchsia_remote_debug_protocol: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + glob: + dependency: "direct dev" + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + http_multi_server: + dependency: "direct dev" + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: "direct dev" + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: "direct dev" + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: "direct dev" + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + leak_tracker: + dependency: "direct dev" + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: "direct dev" + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: "direct dev" + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + logging: + dependency: "direct dev" + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: "direct dev" + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: "direct main" + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: "direct main" + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + mime: + dependency: "direct dev" + description: + name: mime + sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + url: "https://pub.dev" + source: hosted + version: "1.0.4" + node_preamble: + dependency: "direct dev" + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: "direct dev" + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: "direct dev" + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + platform: + dependency: transitive + description: + name: platform + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + url: "https://pub.dev" + source: hosted + version: "3.1.4" + pool: + dependency: "direct dev" + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + process: + dependency: transitive + description: + name: process + sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32" + url: "https://pub.dev" + source: hosted + version: "5.0.2" + pub_semver: + dependency: "direct dev" + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + shelf: + dependency: "direct dev" + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: "direct dev" + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: "direct dev" + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: "direct dev" + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_map_stack_trace: + dependency: "direct dev" + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: "direct dev" + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" + source_span: + dependency: "direct dev" + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: "direct dev" + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: "direct dev" + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: "direct dev" + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + sync_http: + dependency: "direct dev" + description: + name: sync_http + sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961" + url: "https://pub.dev" + source: hosted + version: "0.3.1" + term_glyph: + dependency: "direct dev" + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f + url: "https://pub.dev" + source: hosted + version: "1.24.9" + test_api: + dependency: "direct dev" + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + test_core: + dependency: "direct dev" + description: + name: test_core + sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a + url: "https://pub.dev" + source: hosted + version: "0.5.9" + typed_data: + dependency: "direct dev" + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: "direct dev" + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" + watcher: + dependency: "direct dev" + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web: + dependency: "direct dev" + description: + name: web + sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa + url: "https://pub.dev" + source: hosted + version: "0.4.0" + web_socket_channel: + dependency: "direct dev" + description: + name: web_socket_channel + sha256: "045ec2137c27bf1a32e6ffa0e734d532a6677bf9016a0d1a406c54e499ff945b" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + webdriver: + dependency: "direct dev" + description: + name: webdriver + sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + webkit_inspection_protocol: + dependency: "direct dev" + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: "direct dev" + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.2.0 <4.0.0" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/pubspec.yaml b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..01bc3ffac36cc7653f1bb13aac700d661b1dfcaa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/pubspec.yaml @@ -0,0 +1,77 @@ +name: platform_channel_swift + +environment: + sdk: '>=3.2.0-0 <4.0.0' + +dependencies: + flutter: + sdk: flutter + + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_driver: + sdk: flutter + test: 1.24.9 + + _fe_analyzer_shared: 65.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + analyzer: 6.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + args: 2.4.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + convert: 3.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + coverage: 1.7.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + crypto: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + file: 7.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + frontend_server_client: 3.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + glob: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_multi_server: 3.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_parser: 4.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + io: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + js: 0.6.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker: 10.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_flutter_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + logging: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + matcher: 0.12.16+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + mime: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + node_preamble: 2.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + package_config: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + path: 1.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pool: 1.5.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pub_semver: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf: 1.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_packages_handler: 3.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_static: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_web_socket: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_map_stack_trace: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_maps: 0.10.12 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + sync_http: 0.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_core: 0.5.9 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + typed_data: 1.3.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + watcher: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web_socket_channel: 2.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webdriver: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + yaml: 3.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +flutter: + uses-material-design: true + +# PUBSPEC CHECKSUM: 6020 diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/test_driver/button_tap.dart b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/test_driver/button_tap.dart new file mode 100644 index 0000000000000000000000000000000000000000..70b078e68447dfa4083ac40d41d800790506b51a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/test_driver/button_tap.dart @@ -0,0 +1,11 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_driver/driver_extension.dart'; +import 'package:platform_channel_swift/main.dart' as app; + +void main() { + enableFlutterDriverExtension(); + app.main(); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/test_driver/button_tap_test.dart b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/test_driver/button_tap_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..53d4c997d1866101fa4f1637853fbb259a0bf4cf --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_channel_swift/test_driver/button_tap_test.dart @@ -0,0 +1,37 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_driver/flutter_driver.dart'; +import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; + +void main() { + group('button tap test', () { + late FlutterDriver driver; + + setUpAll(() async { + driver = await FlutterDriver.connect(); + }); + + tearDownAll(() async { + driver.close(); + }); + + test('tap on the button, verify result', () async { + final SerializableFinder batteryLevelLabel = + find.byValueKey('Battery level label'); + expect(batteryLevelLabel, isNotNull); + + final SerializableFinder button = find.text('Refresh'); + await driver.waitFor(button); + await driver.tap(button); + + String? batteryLevel; + while (batteryLevel == null || batteryLevel.contains('unknown')) { + batteryLevel = await driver.getText(batteryLevelLabel); + } + + expect(batteryLevel.contains('%'), isTrue); + }); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/README.md b/novelforge-project/agent-workspace/flutter/examples/platform_view/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c1a95888e18f18c4fda19d33ca0ae92796649bc0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/README.md @@ -0,0 +1,12 @@ +# Example of switching between full-screen Flutter and Platform View + +This project demonstrates how to bring up a full-screen iOS/Android view from a +full-screen Flutter view along with passing data back and forth between the two. + +On iOS, we use a CocoaPods dependency to add a Material Design button, and so +`pod install` needs to be invoked in the `ios/` folder before `flutter run`: + +``` +pushd ios/ ; pod install ; popd +flutter run +``` diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/android.iml b/novelforge-project/agent-workspace/flutter/examples/platform_view/android.iml new file mode 100644 index 0000000000000000000000000000000000000000..5f07b2c1a639c51b9163861138ca86eace1cc46a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/android.iml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/build.gradle b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..228e73ecbb04bb1fb03b9276fbbd35eed645c028 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/build.gradle @@ -0,0 +1,64 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +apply plugin: 'com.android.application' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + +android { + namespace "io.flutter.examples.platform_view" + compileSdk flutter.compileSdkVersion + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + defaultConfig { + applicationId "io.flutter.examples.platform_view" + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies { + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'com.google.android.material:material:1.0.0' +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/AndroidManifest.xml b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000000000000000000000000000000000..4dd54b32013d19ed7b34619c9bb277ea60ba85f8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/java/io/flutter/examples/platform_view/CountActivity.java b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/java/io/flutter/examples/platform_view/CountActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..dd1f5834b45fbc230b37feabaf1c6711088793dc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/java/io/flutter/examples/platform_view/CountActivity.java @@ -0,0 +1,66 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.examples.platform_view; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +public class CountActivity extends AppCompatActivity { + public static final String EXTRA_COUNTER = "counter"; + private int counter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.android_full_screen_layout); + Toolbar myToolbar = findViewById(R.id.my_toolbar); + myToolbar.setTitle("Platform View"); + setSupportActionBar(myToolbar); + + counter = getIntent().getIntExtra(EXTRA_COUNTER, 0); + updateText(); + + FloatingActionButton fab = findViewById(R.id.fab); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + counter++; + updateText(); + } + }); + + Button switchViewButton = findViewById(R.id.button); + switchViewButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + returnToFlutterView(); + } + }); + } + + private void updateText() { + TextView textView = findViewById(R.id.button_tap); + String value = "Button tapped " + counter + (counter == 1 ? " time" : " times"); + textView.setText(value); + } + + private void returnToFlutterView() { + Intent returnIntent = new Intent(); + returnIntent.putExtra(EXTRA_COUNTER, counter); + setResult(Activity.RESULT_OK, returnIntent); + finish(); + } + + public void onBackPressed() { + returnToFlutterView(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/java/io/flutter/examples/platform_view/MainActivity.java b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/java/io/flutter/examples/platform_view/MainActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..8a637a4239b023027b1f3b2c47dfe7d3243fea5f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/java/io/flutter/examples/platform_view/MainActivity.java @@ -0,0 +1,56 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.examples.platform_view; + +import android.content.Intent; +import androidx.annotation.NonNull; +import io.flutter.embedding.android.FlutterActivity; +import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugins.GeneratedPluginRegistrant; + +public class MainActivity extends FlutterActivity { + private static final String CHANNEL = "samples.flutter.io/platform_view"; + private static final String METHOD_SWITCH_VIEW = "switchView"; + private static final int COUNT_REQUEST = 1; + + private MethodChannel.Result result; + + @Override + public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { + new MethodChannel(flutterEngine.getDartExecutor(), CHANNEL).setMethodCallHandler( + new MethodChannel.MethodCallHandler() { + @Override + public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { + MainActivity.this.result = result; + int count = methodCall.arguments(); + if (methodCall.method.equals(METHOD_SWITCH_VIEW)) { + onLaunchFullScreen(count); + } else { + result.notImplemented(); + } + } + } + ); + } + + private void onLaunchFullScreen(int count) { + Intent fullScreenIntent = new Intent(this, CountActivity.class); + fullScreenIntent.putExtra(CountActivity.EXTRA_COUNTER, count); + startActivityForResult(fullScreenIntent, COUNT_REQUEST); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == COUNT_REQUEST) { + if (resultCode == RESULT_OK) { + result.success(data.getIntExtra(CountActivity.EXTRA_COUNTER, 0)); + } else { + result.error("ACTIVITY_FAILURE", "Failed while launching activity", null); + } + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/res/drawable/ic_add_black_24dp.xml b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/res/drawable/ic_add_black_24dp.xml new file mode 100644 index 0000000000000000000000000000000000000000..f99c4c64f65c169034105c526ea7c011d4ac418f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/res/drawable/ic_add_black_24dp.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/res/layout/android_full_screen_layout.xml b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/res/layout/android_full_screen_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..d0dbc52707a2bbf62b4d9ff0813c4302d4ca8806 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/android/app/src/main/res/layout/android_full_screen_layout.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/Info.plist b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..ca51ebe361e8685ff658795a50ef46cb07a487aa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + platform_view + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/PlatformViewController.h b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/PlatformViewController.h new file mode 100644 index 0000000000000000000000000000000000000000..8fea8243c3df94b46cbdb743b3ee6f21892e1965 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/PlatformViewController.h @@ -0,0 +1,15 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import + +@protocol PlatformViewControllerDelegate +- (void)didUpdateCounter:(int)counter; +@end + + +@interface PlatformViewController : UIViewController +@property (strong, nonatomic) id delegate; +@property int counter; +@end diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/PlatformViewController.m b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/PlatformViewController.m new file mode 100644 index 0000000000000000000000000000000000000000..397dd3c75642da85502c41c11ae67b2ce5819274 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/PlatformViewController.m @@ -0,0 +1,36 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import +#import "PlatformViewController.h" + +@interface PlatformViewController () +@property (weak, nonatomic) IBOutlet UILabel *incrementLabel; +@end + +@implementation PlatformViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + [self setIncrementLabelText]; +} + +- (IBAction)handleIncrement:(id)sender { + self.counter++; + [self setIncrementLabelText]; +} + +- (IBAction)switchToFlutterView:(id)sender { + [self.delegate didUpdateCounter:self.counter]; + [self dismissViewControllerAnimated:NO completion:nil]; +} + +- (void)setIncrementLabelText { + NSString* text = [NSString stringWithFormat:@"Button tapped %d %@.", + self.counter, + (self.counter == 1) ? @"time" : @"times"]; + self.incrementLabel.text = text; +} + +@end diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/ic_add.png b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/ic_add.png new file mode 100644 index 0000000000000000000000000000000000000000..23bf119211e02b139ad2e0961bc71662ce1caf1e Binary files /dev/null and b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/ic_add.png differ diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/main.m b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/main.m new file mode 100644 index 0000000000000000000000000000000000000000..86070722733949a969321315b3d1ad7ed69711bc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/Runner/main.m @@ -0,0 +1,14 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/RunnerTests/PlatformViewControllerTests.m b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/RunnerTests/PlatformViewControllerTests.m new file mode 100644 index 0000000000000000000000000000000000000000..4ce3beb49825822db660575f0b424234bed97317 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/ios/RunnerTests/PlatformViewControllerTests.m @@ -0,0 +1,36 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import +#import + +#import "PlatformViewController.h" + +@interface PlatformViewControllerTests : XCTestCase +@property (nonatomic, strong) XCUIApplication *app; +@end + +@implementation PlatformViewControllerTests + +- (void)setUp { + // Put setup code here. + // This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. + // This method is called after the invocation of each test method in the class. +} + +- (void)testViewControllerIconLoaded { + UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; + PlatformViewController* controller = [storyboard instantiateViewControllerWithIdentifier:@"PlatformView"]; + XCTAssertNotNil(controller); + [controller loadViewIfNeeded]; + + UIImage* incrementButtonIcon = [controller.incrementButton imageForState:UIControlStateNormal]; + XCTAssertNotNil(incrementButtonIcon); +} + +@end diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/lib/main.dart b/novelforge-project/agent-workspace/flutter/examples/platform_view/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..5efefe72ffd4a3cd4be9aa2d0b73d92d28293f7c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/lib/main.dart @@ -0,0 +1,117 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +void main() { + runApp(const PlatformView()); +} + +class PlatformView extends StatelessWidget { + const PlatformView({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Platform View', + theme: ThemeData( + primarySwatch: Colors.grey, + ), + home: const MyHomePage(title: 'Platform View'), + ); + } +} + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title}); + + final String title; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + static const MethodChannel _methodChannel = + MethodChannel('samples.flutter.io/platform_view'); + + int _counter = 0; + + void _incrementCounter() { + setState(() { + _counter++; + }); + } + + static Widget get _buttonText { + return switch (defaultTargetPlatform) { + TargetPlatform.android => const Text('Continue in Android view'), + TargetPlatform.iOS => const Text('Continue in iOS view'), + TargetPlatform.windows => const Text('Continue in Windows view'), + TargetPlatform.macOS => const Text('Continue in macOS view'), + TargetPlatform.linux => const Text('Continue in Linux view'), + TargetPlatform.fuchsia => throw UnimplementedError('Platform not yet implemented'), + }; + } + + Future _launchPlatformCount() async { + final int? platformCounter = + await _methodChannel.invokeMethod('switchView', _counter); + setState(() { + _counter = platformCounter!; + }); + } + + @override + Widget build(BuildContext context) => Scaffold( + appBar: AppBar( + title: Text(widget.title), + ), + body: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Button tapped $_counter time${ _counter == 1 ? '' : 's' }.', + style: const TextStyle(fontSize: 17.0), + ), + Padding( + padding: const EdgeInsets.all(18.0), + child: ElevatedButton( + onPressed: _launchPlatformCount, + child: _buttonText, + ), + ), + ], + ), + ), + ), + Container( + padding: const EdgeInsets.only(bottom: 15.0, left: 5.0), + child: Row( + children: [ + Image.asset('assets/flutter-mark-square-64.png', scale: 1.5), + const Text( + 'Flutter', + style: TextStyle(fontSize: 30.0), + ), + ], + ), + ), + ], + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..67f289712447faeb9d486c3f3b5ecc1fa05e708a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/CMakeLists.txt @@ -0,0 +1,140 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.10) +project(runner LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 17) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "platform_view") +# The unique GTK application identifier for this application. See: +# https://wiki.gnome.org/HowDoI/ChooseApplicationID +set(APPLICATION_ID "io.flutter.examples.platform_view") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(SET CMP0063 NEW) + +# Load bundled libraries from the lib/ directory relative to the binary. +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Root filesystem for cross-building. +if(FLUTTER_TARGET_PLATFORM_SYSROOT) + set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endif() + +# Define build configuration options. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") +endif() + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_14) + target_compile_options(${TARGET} PRIVATE -Wall -Werror) + target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) + +add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") + +# Define the application target. To change its name, change BINARY_NAME above, +# not the value here, or `flutter run` will no longer work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} + "main.cc" + "my_application.cc" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add dependency libraries. Add any application-specific dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) + +# Only the install-generated bundle's copy of the executable will launch +# correctly, since the resources must in the right relative locations. To avoid +# people trying to run the unbundled copy, put it in a subdirectory instead of +# the default top-level location. +set_target_properties(${BINARY_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" +) + + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# By default, "installing" just makes a relocatable bundle in the build +# directory. +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +# Start with a clean build bundle directory every time. +install(CODE " + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") + " COMPONENT Runtime) + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) + install(FILES "${bundled_library}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endforeach(bundled_library) + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/flutter/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/flutter/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d5bd01648a96d50136b2a97c8bb9aa5b711f6c39 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/flutter/CMakeLists.txt @@ -0,0 +1,88 @@ +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.10) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. + +# Serves the same purpose as list(TRANSFORM ... PREPEND ...), +# which isn't available in 3.10. +function(list_prepend LIST_NAME PREFIX) + set(NEW_LIST "") + foreach(element ${${LIST_NAME}}) + list(APPEND NEW_LIST "${PREFIX}${element}") + endforeach(element) + set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) +endfunction() + +# === Flutter Library === +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) +pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) +pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) + +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "fl_basic_message_channel.h" + "fl_binary_codec.h" + "fl_binary_messenger.h" + "fl_dart_project.h" + "fl_engine.h" + "fl_json_message_codec.h" + "fl_json_method_codec.h" + "fl_message_codec.h" + "fl_method_call.h" + "fl_method_channel.h" + "fl_method_codec.h" + "fl_method_response.h" + "fl_plugin_registrar.h" + "fl_plugin_registry.h" + "fl_standard_message_codec.h" + "fl_standard_method_codec.h" + "fl_string_codec.h" + "fl_value.h" + "fl_view.h" + "flutter_linux.h" +) +list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") +target_link_libraries(flutter INTERFACE + PkgConfig::GTK + PkgConfig::GLIB + PkgConfig::GIO +) +add_dependencies(flutter flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/_phony_ + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" + ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} +) diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/main.cc b/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/main.cc new file mode 100644 index 0000000000000000000000000000000000000000..281a29e16b599a95421e7a35112eda77900ff549 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/main.cc @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "my_application.h" + +int main(int argc, char** argv) { + g_autoptr(MyApplication) app = my_application_new(); + return g_application_run(G_APPLICATION(app), argc, argv); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/my_application.cc b/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/my_application.cc new file mode 100644 index 0000000000000000000000000000000000000000..403df877b0ac7d70004e0253a20a022c07c39060 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/my_application.cc @@ -0,0 +1,167 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "my_application.h" + +#include + +#ifdef GDK_WINDOWING_X11 +#include +#endif + +#include "flutter/generated_plugin_registrant.h" + +struct _MyApplication { + GtkApplication parent_instance; + + // Channel to receive platform view requests from Flutter. + FlMethodChannel* platform_view_channel; + + // Main window. + GtkWindow* window; + + // Current counter. + int64_t counter; + + // Request in progress. + FlMethodCall* method_call; + + // Native window requested by Flutter. + GtkWindow* native_window; + + // Label to show count. + GtkLabel* counter_label; +}; + +G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) + +static void update_counter_label(MyApplication* self) { + g_autofree gchar* text = + g_strdup_printf("Button tapped %" G_GINT64_FORMAT " %s.", self->counter, + self->counter == 1 ? "time" : "times"); + gtk_label_set_text(self->counter_label, text); +} + +static void button_clicked_cb(MyApplication* self) { + self->counter++; + update_counter_label(self); +} + +static void native_window_delete_event_cb(MyApplication* self, + gint response_id) { + g_autoptr(FlValue) counter_value = fl_value_new_int(self->counter); + fl_method_call_respond_success(self->method_call, counter_value, nullptr); + g_clear_object(&self->method_call); +} + +// Handle request to switch the view. +static void handle_switch_view(MyApplication* self, FlMethodCall* method_call) { + FlValue* counter_value = fl_method_call_get_args(method_call); + if (fl_value_get_type(counter_value) != FL_VALUE_TYPE_INT) { + fl_method_call_respond_error(self->method_call, "Invalid args", + "Invalid switchView args", nullptr, nullptr); + return; + } + + self->counter = fl_value_get_int(counter_value); + self->method_call = FL_METHOD_CALL(g_object_ref(method_call)); + + // Show the same UI in a native window. + self->native_window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); + gtk_window_set_transient_for(self->native_window, self->window); + gtk_window_set_modal(self->native_window, TRUE); + gtk_window_set_destroy_with_parent(self->native_window, TRUE); + g_signal_connect_swapped(self->native_window, "delete-event", + G_CALLBACK(native_window_delete_event_cb), self); + + GtkWidget* box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12); + gtk_widget_set_margin_start(box, 24); + gtk_widget_set_margin_end(box, 24); + gtk_widget_set_margin_top(box, 24); + gtk_widget_set_margin_bottom(box, 24); + gtk_widget_show(box); + gtk_container_add(GTK_CONTAINER(self->native_window), box); + + self->counter_label = GTK_LABEL(gtk_label_new("")); + gtk_widget_show(GTK_WIDGET(self->counter_label)); + gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(self->counter_label)); + + GtkWidget* button = gtk_button_new_with_label("+"); + gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(button)), + "circular"); + gtk_widget_set_halign(button, GTK_ALIGN_CENTER); + gtk_widget_show(button); + gtk_container_add(GTK_CONTAINER(box), button); + g_signal_connect_swapped(button, "clicked", G_CALLBACK(button_clicked_cb), + self); + + update_counter_label(self); + + gtk_window_present(self->native_window); +} + +// Handle platform view requests from Flutter. +static void platform_view_channel_method_cb(FlMethodChannel* channel, + FlMethodCall* method_call, + gpointer user_data) { + MyApplication* self = MY_APPLICATION(user_data); + + const char* name = fl_method_call_get_name(method_call); + if (g_str_equal(name, "switchView")) { + handle_switch_view(self, method_call); + } else { + fl_method_call_respond_not_implemented(method_call, nullptr); + } +} + +// Implements GObject::dispose. +static void my_application_dispose(GObject* object) { + MyApplication* self = MY_APPLICATION(object); + + g_clear_object(&self->platform_view_channel); + + G_OBJECT_CLASS(my_application_parent_class)->dispose(object); +} + +// Implements GApplication::activate. +static void my_application_activate(GApplication* application) { + MyApplication* self = MY_APPLICATION(application); + self->window = + GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + + gtk_window_set_default_size(self->window, 1280, 720); + gtk_widget_show(GTK_WIDGET(self->window)); + + g_autoptr(FlDartProject) project = fl_dart_project_new(); + FlView* view = fl_view_new(project); + gtk_widget_show(GTK_WIDGET(view)); + gtk_container_add(GTK_CONTAINER(self->window), GTK_WIDGET(view)); + + // Create channel to handle platform view requests from Flutter. + FlEngine* engine = fl_view_get_engine(view); + g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new(); + self->platform_view_channel = fl_method_channel_new( + fl_engine_get_binary_messenger(engine), + "samples.flutter.io/platform_view", FL_METHOD_CODEC(codec)); + fl_method_channel_set_method_call_handler(self->platform_view_channel, + platform_view_channel_method_cb, + self, nullptr); + + fl_register_plugins(FL_PLUGIN_REGISTRY(view)); + + gtk_widget_grab_focus(GTK_WIDGET(view)); +} + +static void my_application_class_init(MyApplicationClass* klass) { + G_OBJECT_CLASS(klass)->dispose = my_application_dispose; + G_APPLICATION_CLASS(klass)->activate = my_application_activate; +} + +static void my_application_init(MyApplication* self) {} + +MyApplication* my_application_new() { + return MY_APPLICATION(g_object_new(my_application_get_type(), + "application-id", APPLICATION_ID, "flags", + G_APPLICATION_NON_UNIQUE, nullptr)); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/my_application.h b/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/my_application.h new file mode 100644 index 0000000000000000000000000000000000000000..8c66ec485434d1f922c9915bdaefcb8969cdfec9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/linux/my_application.h @@ -0,0 +1,22 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_MY_APPLICATION_H_ +#define FLUTTER_MY_APPLICATION_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, + GtkApplication) + +/** + * my_application_new: + * + * Creates a new Flutter-based application. + * + * Returns: a new #MyApplication. + */ +MyApplication* my_application_new(); + +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Flutter/Flutter-Debug.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Flutter/Flutter-Debug.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..c2efd0b608ba84712fb3e1d01122468a50c7fba1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Flutter/Flutter-Debug.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Flutter/Flutter-Release.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Flutter/Flutter-Release.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..c2efd0b608ba84712fb3e1d01122468a50c7fba1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Flutter/Flutter-Release.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcodeproj/project.pbxproj b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000000000000000000000000000000000000..23575315d5d465e0e57e98686bac4f1ff132fb81 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,581 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXAggregateTarget section */ + 33CC111A2044C6BA0003C045 /* Flutter Assemble */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */; + buildPhases = ( + 33CC111E2044C6BF0003C045 /* ShellScript */, + ); + dependencies = ( + ); + name = "Flutter Assemble"; + productName = FLX; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */; }; + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC10F02044A3C60003C045 /* AppDelegate.swift */; }; + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; + F34FE5C128C663500068B3C3 /* PlatformViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F34FE5BF28C663500068B3C3 /* PlatformViewController.swift */; }; + F34FE5C228C663500068B3C3 /* PlatformViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F34FE5C028C663500068B3C3 /* PlatformViewController.xib */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC111A2044C6BA0003C045; + remoteInfo = FLX; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 33CC110E2044A8840003C045 /* Bundle Framework */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Bundle Framework"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; + 33CC10ED2044A3C60003C045 /* platform_view.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = platform_view.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; + 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 33CC10F72044A3C60003C045 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Runner/Info.plist; sourceTree = ""; }; + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainFlutterWindow.swift; sourceTree = ""; }; + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; + 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; + 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; + 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; + F34FE5BF28C663500068B3C3 /* PlatformViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlatformViewController.swift; sourceTree = ""; }; + F34FE5C028C663500068B3C3 /* PlatformViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PlatformViewController.xib; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 33CC10EA2044A3C60003C045 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 33BA886A226E78AF003329D5 /* Configs */ = { + isa = PBXGroup; + children = ( + 33E5194F232828860026EE4D /* AppInfo.xcconfig */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */, + ); + path = Configs; + sourceTree = ""; + }; + 33CC10E42044A3C60003C045 = { + isa = PBXGroup; + children = ( + 33FAB671232836740065AC1E /* Runner */, + 33CEB47122A05771004F2AC0 /* Flutter */, + 33CC10EE2044A3C60003C045 /* Products */, + D73912EC22F37F3D000D13A0 /* Frameworks */, + ); + sourceTree = ""; + }; + 33CC10EE2044A3C60003C045 /* Products */ = { + isa = PBXGroup; + children = ( + 33CC10ED2044A3C60003C045 /* platform_view.app */, + ); + name = Products; + sourceTree = ""; + }; + 33CC11242044D66E0003C045 /* Resources */ = { + isa = PBXGroup; + children = ( + 33CC10F22044A3C60003C045 /* Assets.xcassets */, + 33CC10F42044A3C60003C045 /* MainMenu.xib */, + 33CC10F72044A3C60003C045 /* Info.plist */, + ); + name = Resources; + path = ..; + sourceTree = ""; + }; + 33CEB47122A05771004F2AC0 /* Flutter */ = { + isa = PBXGroup; + children = ( + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */, + ); + path = Flutter; + sourceTree = ""; + }; + 33FAB671232836740065AC1E /* Runner */ = { + isa = PBXGroup; + children = ( + 33CC10F02044A3C60003C045 /* AppDelegate.swift */, + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */, + F34FE5BF28C663500068B3C3 /* PlatformViewController.swift */, + F34FE5C028C663500068B3C3 /* PlatformViewController.xib */, + 33E51913231747F40026EE4D /* DebugProfile.entitlements */, + 33E51914231749380026EE4D /* Release.entitlements */, + 33CC11242044D66E0003C045 /* Resources */, + 33BA886A226E78AF003329D5 /* Configs */, + ); + path = Runner; + sourceTree = ""; + }; + D73912EC22F37F3D000D13A0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 33CC10EC2044A3C60003C045 /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 33CC10E92044A3C60003C045 /* Sources */, + 33CC10EA2044A3C60003C045 /* Frameworks */, + 33CC10EB2044A3C60003C045 /* Resources */, + 33CC110E2044A8840003C045 /* Bundle Framework */, + 3399D490228B24CF009A79C7 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 33CC11202044C79F0003C045 /* PBXTargetDependency */, + ); + name = Runner; + productName = Runner; + productReference = 33CC10ED2044A3C60003C045 /* platform_view.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 33CC10E52044A3C60003C045 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0920; + LastUpgradeCheck = 1510; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 33CC10EC2044A3C60003C045 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1100; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; + 33CC111A2044C6BA0003C045 = { + CreatedOnToolsVersion = 9.2; + ProvisioningStyle = Manual; + }; + }; + }; + buildConfigurationList = 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 33CC10E42044A3C60003C045; + productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 33CC10EC2044A3C60003C045 /* Runner */, + 33CC111A2044C6BA0003C045 /* Flutter Assemble */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 33CC10EB2044A3C60003C045 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */, + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */, + F34FE5C228C663500068B3C3 /* PlatformViewController.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3399D490228B24CF009A79C7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; + }; + 33CC111E2044C6BF0003C045 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + Flutter/ephemeral/FlutterInputs.xcfilelist, + ); + inputPaths = ( + Flutter/ephemeral/tripwire, + ); + outputFileListPaths = ( + Flutter/ephemeral/FlutterOutputs.xcfilelist, + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 33CC10E92044A3C60003C045 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */, + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */, + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */, + F34FE5C128C663500068B3C3 /* PlatformViewController.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 33CC11202044C79F0003C045 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC111A2044C6BA0003C045 /* Flutter Assemble */; + targetProxy = 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 33CC10F42044A3C60003C045 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 33CC10F52044A3C60003C045 /* Base */, + ); + name = MainMenu.xib; + path = Runner; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 338D0CE9231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Profile; + }; + 338D0CEA231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Profile; + }; + 338D0CEB231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Profile; + }; + 33CC10F92044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 33CC10FA2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 33CC10FC2044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 33CC10FD2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 33CC111C2044C6BA0003C045 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 33CC111D2044C6BA0003C045 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10F92044A3C60003C045 /* Debug */, + 33CC10FA2044A3C60003C045 /* Release */, + 338D0CE9231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10FC2044A3C60003C045 /* Debug */, + 33CC10FD2044A3C60003C045 /* Release */, + 338D0CEA231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC111C2044C6BA0003C045 /* Debug */, + 33CC111D2044C6BA0003C045 /* Release */, + 338D0CEB231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 33CC10E52044A3C60003C045 /* Project object */; +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000000000000000000000000000000000..18d981003d68d0546c4804ac2ff47dd97c6e7921 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000000000000000000000000000000000000..cbcf3c2dd486772469647d3a877daa84af4e5f7d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcworkspace/contents.xcworkspacedata b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000000000000000000000000000000000..1d526a16ed0f1cd0c2409d848bf489b93fefa3b2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000000000000000000000000000000000..18d981003d68d0546c4804ac2ff47dd97c6e7921 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/AppDelegate.swift b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/AppDelegate.swift new file mode 100644 index 0000000000000000000000000000000000000000..d080d41951d3506a861ceadcf4354bbbb609a562 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Cocoa +import FlutterMacOS + +@NSApplicationMain +class AppDelegate: FlutterAppDelegate { + override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return true + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Base.lproj/MainMenu.xib b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Base.lproj/MainMenu.xib new file mode 100644 index 0000000000000000000000000000000000000000..80e867a4e06b4dc26d0a2b327cbd54041addc50a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Base.lproj/MainMenu.xib @@ -0,0 +1,343 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/AppInfo.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/AppInfo.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..0ec4e5a45b55fec25ce49e4fcc1f8685f66c3a2e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/AppInfo.xcconfig @@ -0,0 +1,14 @@ +// Application-level settings for the Runner target. +// +// This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the +// future. If not, the values below would default to using the project name when this becomes a +// 'flutter create' template. + +// The application's name. By default this is also the title of the Flutter window. +PRODUCT_NAME = platform_view + +// The application's bundle identifier +PRODUCT_BUNDLE_IDENTIFIER = io.flutter.examples.platformView + +// The copyright displayed in application information +PRODUCT_COPYRIGHT = Copyright © 2022 io.flutter.examples. All rights reserved. diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/Debug.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/Debug.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..36b0fd9464f45b33f482e64bea579787e142affa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/Debug.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Debug.xcconfig" +#include "Warnings.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/Release.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/Release.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..dff4f49561c816f70eaea557d889d31cf63447ac --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/Release.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Release.xcconfig" +#include "Warnings.xcconfig" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/Warnings.xcconfig b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/Warnings.xcconfig new file mode 100644 index 0000000000000000000000000000000000000000..42bcbf4780b187e80025b7917058bcb882012aa1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Configs/Warnings.xcconfig @@ -0,0 +1,13 @@ +WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings +GCC_WARN_UNDECLARED_SELECTOR = YES +CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES +CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES +CLANG_WARN_PRAGMA_PACK = YES +CLANG_WARN_STRICT_PROTOTYPES = YES +CLANG_WARN_COMMA = YES +GCC_WARN_STRICT_SELECTOR_MATCH = YES +CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES +GCC_WARN_SHADOW = YES +CLANG_WARN_UNREACHABLE_CODE = YES diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/DebugProfile.entitlements b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/DebugProfile.entitlements new file mode 100644 index 0000000000000000000000000000000000000000..dddb8a30c851e7ef5b16a9108934bd1217b6b43f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/DebugProfile.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.cs.allow-jit + + com.apple.security.network.server + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Info.plist b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..4789daa6a443eefa7f3f729164a18351e06e9800 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + $(PRODUCT_COPYRIGHT) + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/MainFlutterWindow.swift b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/MainFlutterWindow.swift new file mode 100644 index 0000000000000000000000000000000000000000..e56d2ac9905ddd43e6b3ea951c716e4951a1fe90 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/MainFlutterWindow.swift @@ -0,0 +1,44 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Cocoa +import FlutterMacOS + +/** + The main application window. + + Performs Flutter app initialization, and handles channel method calls over the + `samples.flutter.io/platform_view` channel. +*/ +class MainFlutterWindow: NSWindow { + override func awakeFromNib() { + let flutterViewController = FlutterViewController() + let windowFrame = self.frame + self.contentViewController = flutterViewController + self.setFrame(windowFrame, display: true) + + RegisterGeneratedPlugins(registry: flutterViewController) + RegisterMethodChannel(registry: flutterViewController) + + super.awakeFromNib() + } + + func RegisterMethodChannel(registry: FlutterPluginRegistry) { + let registrar = registry.registrar(forPlugin: "platform_view") + let channel = FlutterMethodChannel(name: "samples.flutter.io/platform_view", + binaryMessenger: registrar.messenger) + channel.setMethodCallHandler({ (call, result) in + if (call.method == "switchView") { + let count = call.arguments as! Int + let controller: NSViewController = PlatformViewController( + withCount: count, + onClose: { platformViewController in + result(platformViewController.count) + } + ) + self.contentViewController?.presentAsSheet(controller) + } + }) + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/PlatformViewController.swift b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/PlatformViewController.swift new file mode 100644 index 0000000000000000000000000000000000000000..12bbd4cbe8f226924ec34dca89a3b4cf1b446b42 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/PlatformViewController.swift @@ -0,0 +1,57 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Cocoa + +/** +`ViewControllers` in the xib can inherit from this class to communicate with +the flutter view for this application. ViewControllers that inherit from this +class should be displayed as a popover or modal, with a button that binds to +the IBAction `pop()`. + +To get the value of the popover during close, pass a callback function as +the `dispose` parameter. The callback passed will have access to the +`PlatformViewController` and all of it's properties at close so that the `count` +can be passed back through the message channel if needed. +*/ +class PlatformViewController: NSViewController { + var count: Int = 0 + + var dispose: ((PlatformViewController)->())? + + @IBOutlet weak var label: NSTextField! + + var labelText: String { + get { + return "Button tapped \(self.count) time\(self.count != 1 ? "s" : "")." + } + } + + override func viewDidLoad() { + super.viewDidLoad() + self.label.stringValue = labelText + } + + public required init?(coder aDecoder: NSCoder) { + self.count = 0 + self.dispose = nil + super.init(coder: aDecoder) + } + + init(withCount count: Int, onClose dispose: ((PlatformViewController)->())?) { + self.count = count + self.dispose = dispose + super.init(nibName: nil, bundle: nil) + } + + @IBAction func pop(_ sender: Any) { + self.dispose?(self) + dismiss(self) + } + + @IBAction func increment(_ sender: Any) { + self.count += 1 + self.label.stringValue = labelText + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/PlatformViewController.xib b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/PlatformViewController.xib new file mode 100644 index 0000000000000000000000000000000000000000..82a80df93e92137b942b26f0b4f761e44ff0c054 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/PlatformViewController.xib @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Release.entitlements b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Release.entitlements new file mode 100644 index 0000000000000000000000000000000000000000..852fa1a4728ae4789e3bca55dd07caef3b41f2a5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/macos/Runner/Release.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.security.app-sandbox + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/pubspec.lock b/novelforge-project/agent-workspace/flutter/examples/platform_view/pubspec.lock new file mode 100644 index 0000000000000000000000000000000000000000..36bc7e99c2379e280e9449f9a2375c5cc29f144d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/pubspec.lock @@ -0,0 +1,55 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + characters: + dependency: "direct main" + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + material_color_utilities: + dependency: "direct main" + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: "direct main" + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" +sdks: + dart: ">=3.2.0-0 <4.0.0" diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/pubspec.yaml b/novelforge-project/agent-workspace/flutter/examples/platform_view/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2026264243950346cc54a5d63dd15ecf92324d72 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/pubspec.yaml @@ -0,0 +1,22 @@ +name: platform_view + +environment: + sdk: '>=3.2.0-0 <4.0.0' + +dependencies: + flutter: + sdk: flutter + + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +flutter: + + uses-material-design: true + assets: + - assets/flutter-mark-square-64.png + +# PUBSPEC CHECKSUM: 4694 diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..36fa4a7d46f67bec7da1938ed66fcda0d16a081f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/CMakeLists.txt @@ -0,0 +1,109 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Project-level configuration. +cmake_minimum_required(VERSION 3.14) +project(platform_view LANGUAGES CXX) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "platform_view") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(VERSION 3.14...3.25) + +# Define build configuration option. +get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(IS_MULTICONFIG) + set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" + CACHE STRING "" FORCE) +else() + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") + endif() +endif() +# Define settings for the Profile build mode. +set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") +set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") +set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") + +# Use Unicode for all projects. +add_definitions(-DUNICODE -D_UNICODE) + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_17) + target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") + target_compile_options(${TARGET} PRIVATE /EHsc) + target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") + target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# Application build; see runner/CMakeLists.txt. +add_subdirectory("runner") + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + +target_include_directories(${BINARY_NAME} INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_plugin) + +# === Installation === +# Support files are copied into place next to the executable, so that it can +# run in place. This is done instead of making a separate bundle (as on Linux) +# so that building and running from within Visual Studio will work. +set(BUILD_BUNDLE_DIR "$") +# Make the "install" step default, as it's required to run. +set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +set(PLUGIN_BUNDLED_LIBRARIES) +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + CONFIGURATIONS Profile;Release + COMPONENT Runtime) diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/flutter/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/flutter/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c8f7abf1ebea9a6acf8801c930ba7fe241bebbee --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/flutter/CMakeLists.txt @@ -0,0 +1,113 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.14) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. +set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") + +# Set fallback configurations for older versions of the flutter tool. +if (NOT DEFINED FLUTTER_TARGET_PLATFORM) + set(FLUTTER_TARGET_PLATFORM "windows-x64") +endif() + +# === Flutter Library === +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "flutter_export.h" + "flutter_windows.h" + "flutter_messenger.h" + "flutter_plugin_registrar.h" + "flutter_texture_registrar.h" +) +list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") +add_dependencies(flutter flutter_assemble) + +# === Wrapper === +list(APPEND CPP_WRAPPER_SOURCES_CORE + "core_implementations.cc" + "standard_codec.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_PLUGIN + "plugin_registrar.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_APP + "flutter_engine.cc" + "flutter_view_controller.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") + +# Wrapper sources needed for a plugin. +add_library(flutter_wrapper_plugin STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} +) +apply_standard_settings(flutter_wrapper_plugin) +set_target_properties(flutter_wrapper_plugin PROPERTIES + POSITION_INDEPENDENT_CODE ON) +set_target_properties(flutter_wrapper_plugin PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) +target_include_directories(flutter_wrapper_plugin PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_plugin flutter_assemble) + +# Wrapper sources needed for the runner. +add_library(flutter_wrapper_app STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_APP} +) +apply_standard_settings(flutter_wrapper_app) +target_link_libraries(flutter_wrapper_app PUBLIC flutter) +target_include_directories(flutter_wrapper_app PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_app flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") +set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} + ${PHONY_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" + ${FLUTTER_TARGET_PLATFORM} $ + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} +) diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e851e112e09f327d5ff51fe4001fd4d4a414c5a0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/CMakeLists.txt @@ -0,0 +1,43 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +cmake_minimum_required(VERSION 3.14) +project(runner LANGUAGES CXX) + +# Define the application target. To change its name, change BINARY_NAME in the +# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer +# work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} WIN32 + "flutter_window.cpp" + "main.cpp" + "utils.cpp" + "win32_window.cpp" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" + "Runner.rc" + "runner.exe.manifest" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add preprocessor definitions for the build version. +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") + +# Disable Windows macros that collide with C++ standard library functions. +target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") + +# Add dependency libraries and include directories. Add any application-specific +# dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/Runner.rc b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/Runner.rc new file mode 100644 index 0000000000000000000000000000000000000000..d9d83c4f73acfcad6e03a98284d6b0ef7f2d8bac --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/Runner.rc @@ -0,0 +1,121 @@ +// Microsoft Visual C++ generated resource script. +// +#pragma code_page(65001) +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +// IDI_APP_ICON ICON "resources\\app_icon.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) +#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD +#else +#define VERSION_AS_NUMBER 1,0,0,0 +#endif + +#if defined(FLUTTER_VERSION) +#define VERSION_AS_STRING FLUTTER_VERSION +#else +#define VERSION_AS_STRING "1.0.0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VERSION_AS_NUMBER + PRODUCTVERSION VERSION_AS_NUMBER + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "io.flutter.examples" "\0" + VALUE "FileDescription", "platform_view" "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "platform_view" "\0" + VALUE "LegalCopyright", "Copyright (C) 2022 io.flutter.examples. All rights reserved." "\0" + VALUE "OriginalFilename", "platform_view.exe" "\0" + VALUE "ProductName", "platform_view" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/flutter_window.cpp b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/flutter_window.cpp new file mode 100644 index 0000000000000000000000000000000000000000..643a1c3cad4f0040452915a12546132f9e5e65b6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/flutter_window.cpp @@ -0,0 +1,94 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter_window.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "flutter/generated_plugin_registrant.h" + +void RegisterMethodChannel(flutter::FlutterEngine* engine) { + FlutterDesktopPluginRegistrarRef plugin_registrar_ref = + engine->GetRegistrarForPlugin("platform_view"); + flutter::PluginRegistrarWindows* registrar = + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(plugin_registrar_ref); + auto channel = + std::make_unique>( + registrar->messenger(), "samples.flutter.io/platform_view", + &flutter::StandardMethodCodec::GetInstance()); + channel->SetMethodCallHandler([](const auto& call, auto result) { + int counter = std::get(*call.arguments()); + std::string msg = std::string("Pressed the button ") + + std::to_string(counter) + " times!"; + MessageBoxA(NULL, msg.c_str(), "Popup", MB_OK); + result->Success(flutter::EncodableValue(counter)); + }); +} + +FlutterWindow::FlutterWindow(const flutter::DartProject& project) + : project_(project) {} + +FlutterWindow::~FlutterWindow() {} + +bool FlutterWindow::OnCreate() { + if (!Win32Window::OnCreate()) { + return false; + } + + RECT frame = GetClientArea(); + + // The size here must match the window dimensions to avoid unnecessary surface + // creation / destruction in the startup path. + flutter_controller_ = std::make_unique( + frame.right - frame.left, frame.bottom - frame.top, project_); + // Ensure that basic setup of the controller was successful. + if (!flutter_controller_->engine() || !flutter_controller_->view()) { + return false; + } + RegisterPlugins(flutter_controller_->engine()); + RegisterMethodChannel(flutter_controller_->engine()); + SetChildContent(flutter_controller_->view()->GetNativeWindow()); + return true; +} + +void FlutterWindow::OnDestroy() { + if (flutter_controller_) { + flutter_controller_ = nullptr; + } + + Win32Window::OnDestroy(); +} + +LRESULT +FlutterWindow::MessageHandler(HWND hwnd, UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + // Give Flutter, including plugins, an opportunity to handle window messages. + if (flutter_controller_) { + std::optional result = + flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, + lparam); + if (result) { + return *result; + } + } + + switch (message) { + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; + } + + return Win32Window::MessageHandler(hwnd, message, wparam, lparam); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/flutter_window.h b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/flutter_window.h new file mode 100644 index 0000000000000000000000000000000000000000..bbc5836c018a235235e8094ab411d98e1c5443fa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/flutter_window.h @@ -0,0 +1,37 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef RUNNER_FLUTTER_WINDOW_H_ +#define RUNNER_FLUTTER_WINDOW_H_ + +#include +#include + +#include + +#include "win32_window.h" + +// A window that does nothing but host a Flutter view. +class FlutterWindow : public Win32Window { + public: + // Creates a new FlutterWindow hosting a Flutter view running |project|. + explicit FlutterWindow(const flutter::DartProject& project); + virtual ~FlutterWindow(); + + protected: + // Win32Window: + bool OnCreate() override; + void OnDestroy() override; + LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, + LPARAM const lparam) noexcept override; + + private: + // The project to run. + flutter::DartProject project_; + + // The Flutter instance hosted by this window. + std::unique_ptr flutter_controller_; +}; + +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/main.cpp b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..573327f640cb1c39f02e6b2b1adafcf71eaaab5f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/main.cpp @@ -0,0 +1,47 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include +#include +#include + +#include "flutter_window.h" +#include "utils.h" + +int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, + _In_ wchar_t *command_line, _In_ int show_command) { + // Attach to console when present (e.g., 'flutter run') or create a + // new console when running with a debugger. + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { + CreateAndAttachConsole(); + } + + // Initialize COM, so that it is available for use in the library and/or + // plugins. + ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + flutter::DartProject project(L"data"); + + std::vector command_line_arguments = + GetCommandLineArguments(); + + project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); + + FlutterWindow window(project); + Win32Window::Point origin(10, 10); + Win32Window::Size size(1280, 720); + if (!window.CreateAndShow(L"platform_view", origin, size)) { + return EXIT_FAILURE; + } + window.SetQuitOnClose(true); + + ::MSG msg; + while (::GetMessage(&msg, nullptr, 0, 0)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + + ::CoUninitialize(); + return EXIT_SUCCESS; +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/resource.h b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/resource.h new file mode 100644 index 0000000000000000000000000000000000000000..c245ff19cb5805345a3d3265122298cb01b9d71f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/resource.h @@ -0,0 +1,20 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Runner.rc +// +#define IDI_APP_ICON 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/runner.exe.manifest b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/runner.exe.manifest new file mode 100644 index 0000000000000000000000000000000000000000..a42ea7687cb67e55af955dc8874a072e087ce3ed --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/runner.exe.manifest @@ -0,0 +1,20 @@ + + + + + PerMonitorV2 + + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/utils.cpp b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b849ce2c32702dc4b1f35161e794e7dcc5a81ef8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/utils.cpp @@ -0,0 +1,68 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "utils.h" + +#include +#include +#include +#include + +#include + +void CreateAndAttachConsole() { + if (::AllocConsole()) { + FILE *unused; + if (freopen_s(&unused, "CONOUT$", "w", stdout)) { + _dup2(_fileno(stdout), 1); + } + if (freopen_s(&unused, "CONOUT$", "w", stderr)) { + _dup2(_fileno(stdout), 2); + } + std::ios::sync_with_stdio(); + FlutterDesktopResyncOutputStreams(); + } +} + +std::vector GetCommandLineArguments() { + // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. + int argc; + wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + if (argv == nullptr) { + return std::vector(); + } + + std::vector command_line_arguments; + + // Skip the first argument as it's the binary name. + for (int i = 1; i < argc; i++) { + command_line_arguments.push_back(Utf8FromUtf16(argv[i])); + } + + ::LocalFree(argv); + + return command_line_arguments; +} + +std::string Utf8FromUtf16(const wchar_t* utf16_string) { + if (utf16_string == nullptr) { + return std::string(); + } + int target_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, nullptr, 0, nullptr, nullptr) + -1; // remove the trailing null character + std::string utf8_string; + if (target_length <= 0 || target_length > utf8_string.max_size()) { + return utf8_string; + } + utf8_string.resize(target_length); + int converted_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, utf8_string.data(), target_length, nullptr, nullptr); + if (converted_length == 0) { + return std::string(); + } + return utf8_string; +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/utils.h b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/utils.h new file mode 100644 index 0000000000000000000000000000000000000000..54414c989ba716f78f3640e5407dd8ac74284aef --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/utils.h @@ -0,0 +1,23 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef RUNNER_UTILS_H_ +#define RUNNER_UTILS_H_ + +#include +#include + +// Creates a console for the process, and redirects stdout and stderr to +// it for both the runner and the Flutter library. +void CreateAndAttachConsole(); + +// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string +// encoded in UTF-8. Returns an empty std::string on failure. +std::string Utf8FromUtf16(const wchar_t* utf16_string); + +// Gets the command line arguments passed in as a std::vector, +// encoded in UTF-8. Returns an empty std::vector on failure. +std::vector GetCommandLineArguments(); + +#endif // RUNNER_UTILS_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/win32_window.cpp b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/win32_window.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8fef19b0fbfd42ed35473b73ded3f6e1d70910e0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/win32_window.cpp @@ -0,0 +1,249 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "win32_window.h" + +#include + +#include "resource.h" + +namespace { + +constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; + +// The number of Win32Window objects that currently exist. +static int g_active_window_count = 0; + +using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); + +// Scale helper to convert logical scaler values to physical using passed in +// scale factor +int Scale(int source, double scale_factor) { + return static_cast(source * scale_factor); +} + +// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. +// This API is only needed for PerMonitor V1 awareness mode. +void EnableFullDpiSupportIfAvailable(HWND hwnd) { + HMODULE user32_module = LoadLibraryA("User32.dll"); + if (!user32_module) { + return; + } + auto enable_non_client_dpi_scaling = + reinterpret_cast( + GetProcAddress(user32_module, "EnableNonClientDpiScaling")); + if (enable_non_client_dpi_scaling != nullptr) { + enable_non_client_dpi_scaling(hwnd); + } + FreeLibrary(user32_module); +} + +} // namespace + +// Manages the Win32Window's window class registration. +class WindowClassRegistrar { + public: + ~WindowClassRegistrar() = default; + + // Returns the singleton registrar instance. + static WindowClassRegistrar* GetInstance() { + if (!instance_) { + instance_ = new WindowClassRegistrar(); + } + return instance_; + } + + // Returns the name of the window class, registering the class if it hasn't + // previously been registered. + const wchar_t* GetWindowClass(); + + // Unregisters the window class. Should only be called if there are no + // instances of the window. + void UnregisterWindowClass(); + + private: + WindowClassRegistrar() = default; + + static WindowClassRegistrar* instance_; + + bool class_registered_ = false; +}; + +WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; + +const wchar_t* WindowClassRegistrar::GetWindowClass() { + if (!class_registered_) { + WNDCLASS window_class{}; + window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); + window_class.lpszClassName = kWindowClassName; + window_class.style = CS_HREDRAW | CS_VREDRAW; + window_class.cbClsExtra = 0; + window_class.cbWndExtra = 0; + window_class.hInstance = GetModuleHandle(nullptr); + window_class.hIcon = + LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); + window_class.hbrBackground = 0; + window_class.lpszMenuName = nullptr; + window_class.lpfnWndProc = Win32Window::WndProc; + RegisterClass(&window_class); + class_registered_ = true; + } + return kWindowClassName; +} + +void WindowClassRegistrar::UnregisterWindowClass() { + UnregisterClass(kWindowClassName, nullptr); + class_registered_ = false; +} + +Win32Window::Win32Window() { + ++g_active_window_count; +} + +Win32Window::~Win32Window() { + --g_active_window_count; + Destroy(); +} + +bool Win32Window::CreateAndShow(const std::wstring& title, + const Point& origin, + const Size& size) { + Destroy(); + + const wchar_t* window_class = + WindowClassRegistrar::GetInstance()->GetWindowClass(); + + const POINT target_point = {static_cast(origin.x), + static_cast(origin.y)}; + HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); + UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); + double scale_factor = dpi / 96.0; + + HWND window = CreateWindow( + window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), + Scale(size.width, scale_factor), Scale(size.height, scale_factor), + nullptr, nullptr, GetModuleHandle(nullptr), this); + + if (!window) { + return false; + } + + return OnCreate(); +} + +// static +LRESULT CALLBACK Win32Window::WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + if (message == WM_NCCREATE) { + auto window_struct = reinterpret_cast(lparam); + SetWindowLongPtr(window, GWLP_USERDATA, + reinterpret_cast(window_struct->lpCreateParams)); + + auto that = static_cast(window_struct->lpCreateParams); + EnableFullDpiSupportIfAvailable(window); + that->window_handle_ = window; + } else if (Win32Window* that = GetThisFromHandle(window)) { + return that->MessageHandler(window, message, wparam, lparam); + } + + return DefWindowProc(window, message, wparam, lparam); +} + +LRESULT +Win32Window::MessageHandler(HWND hwnd, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + switch (message) { + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + } + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; + } + + return DefWindowProc(window_handle_, message, wparam, lparam); +} + +void Win32Window::Destroy() { + OnDestroy(); + + if (window_handle_) { + DestroyWindow(window_handle_); + window_handle_ = nullptr; + } + if (g_active_window_count == 0) { + WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); + } +} + +Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( + GetWindowLongPtr(window, GWLP_USERDATA)); +} + +void Win32Window::SetChildContent(HWND content) { + child_content_ = content; + SetParent(content, window_handle_); + RECT frame = GetClientArea(); + + MoveWindow(content, frame.left, frame.top, frame.right - frame.left, + frame.bottom - frame.top, true); + + SetFocus(child_content_); +} + +RECT Win32Window::GetClientArea() { + RECT frame; + GetClientRect(window_handle_, &frame); + return frame; +} + +HWND Win32Window::GetHandle() { + return window_handle_; +} + +void Win32Window::SetQuitOnClose(bool quit_on_close) { + quit_on_close_ = quit_on_close; +} + +bool Win32Window::OnCreate() { + // No-op; provided for subclasses. + return true; +} + +void Win32Window::OnDestroy() { + // No-op; provided for subclasses. +} diff --git a/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/win32_window.h b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/win32_window.h new file mode 100644 index 0000000000000000000000000000000000000000..33786ecd6f0b9bfeb539621c8f53fa415038fbad --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/platform_view/windows/runner/win32_window.h @@ -0,0 +1,102 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef RUNNER_WIN32_WINDOW_H_ +#define RUNNER_WIN32_WINDOW_H_ + +#include + +#include +#include +#include + +// A class abstraction for a high DPI-aware Win32 Window. Intended to be +// inherited from by classes that wish to specialize with custom +// rendering and input handling +class Win32Window { + public: + struct Point { + unsigned int x; + unsigned int y; + Point(unsigned int x, unsigned int y) : x(x), y(y) {} + }; + + struct Size { + unsigned int width; + unsigned int height; + Size(unsigned int width, unsigned int height) + : width(width), height(height) {} + }; + + Win32Window(); + virtual ~Win32Window(); + + // Creates and shows a win32 window with |title| and position and size using + // |origin| and |size|. New windows are created on the default monitor. Window + // sizes are specified to the OS in physical pixels, hence to ensure a + // consistent size to will treat the width height passed in to this function + // as logical pixels and scale to appropriate for the default monitor. Returns + // true if the window was created successfully. + bool CreateAndShow(const std::wstring& title, + const Point& origin, + const Size& size); + + // Release OS resources associated with window. + void Destroy(); + + // Inserts |content| into the window tree. + void SetChildContent(HWND content); + + // Returns the backing Window handle to enable clients to set icon and other + // window properties. Returns nullptr if the window has been destroyed. + HWND GetHandle(); + + // If true, closing this window will quit the application. + void SetQuitOnClose(bool quit_on_close); + + // Return a RECT representing the bounds of the current client area. + RECT GetClientArea(); + + protected: + // Processes and route salient window messages for mouse handling, + // size change and DPI. Delegates handling of these to member overloads that + // inheriting classes can handle. + virtual LRESULT MessageHandler(HWND window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Called when CreateAndShow is called, allowing subclass window-related + // setup. Subclasses should return false if setup fails. + virtual bool OnCreate(); + + // Called when Destroy is called. + virtual void OnDestroy(); + + private: + friend class WindowClassRegistrar; + + // OS callback called by message pump. Handles the WM_NCCREATE message which + // is passed when the non-client area is being created and enables automatic + // non-client DPI scaling so that the non-client area automatically + // responds to changes in DPI. All other messages are handled by + // MessageHandler. + static LRESULT CALLBACK WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Retrieves a class instance pointer for |window| + static Win32Window* GetThisFromHandle(HWND const window) noexcept; + + bool quit_on_close_ = false; + + // window handle for top level window. + HWND window_handle_ = nullptr; + + // window handle for hosted content. + HWND child_content_ = nullptr; +}; + +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/splash/lib/main.dart b/novelforge-project/agent-workspace/flutter/examples/splash/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..6062b6cb4d8ad65948bab92f3b6db8096b93b639 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/splash/lib/main.dart @@ -0,0 +1,31 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; + +void main() { + runApp( + const DecoratedBox( + decoration: BoxDecoration(color: Colors.white), + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + textDirection: TextDirection.ltr, + children: [ + FlutterLogo(size: 48), + Padding( + padding: EdgeInsets.all(32), + child: Text( + 'This app is only meant to be run under the Flutter debugger', + textDirection: TextDirection.ltr, + textAlign: TextAlign.center, + style: TextStyle(color: Colors.black87), + ), + ), + ], + ), + ), + ), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/splash/pubspec.lock b/novelforge-project/agent-workspace/flutter/examples/splash/pubspec.lock new file mode 100644 index 0000000000000000000000000000000000000000..2d3f6c8c4454cc1d7407a2d0755161ed06822cc8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/splash/pubspec.lock @@ -0,0 +1,188 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: "direct dev" + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: "direct dev" + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: "direct main" + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: "direct dev" + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + fake_async: + dependency: "direct dev" + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + leak_tracker: + dependency: "direct dev" + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: "direct dev" + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: "direct dev" + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + matcher: + dependency: "direct dev" + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: "direct main" + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: "direct main" + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + path: + dependency: "direct dev" + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: "direct dev" + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: "direct dev" + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: "direct dev" + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: "direct dev" + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: "direct dev" + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: "direct dev" + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: "direct dev" + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" +sdks: + dart: ">=3.2.0-0 <4.0.0" diff --git a/novelforge-project/agent-workspace/flutter/examples/splash/pubspec.yaml b/novelforge-project/agent-workspace/flutter/examples/splash/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..94eab77d7c395fe371a4a25a9faf60743fadea99 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/splash/pubspec.yaml @@ -0,0 +1,37 @@ +name: splash + +environment: + sdk: '>=3.2.0-0 <4.0.0' + +dependencies: + flutter: + sdk: flutter + + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +dev_dependencies: + flutter_test: + sdk: flutter + + async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker: 10.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_flutter_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + matcher: 0.12.16+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + path: 1.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +# PUBSPEC CHECKSUM: 8023 diff --git a/novelforge-project/agent-workspace/flutter/examples/splash/test/splash_test.dart b/novelforge-project/agent-workspace/flutter/examples/splash/test/splash_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..130c0e5f2cd478d58fc02f34cf57ae92b021e3c9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/splash/test/splash_test.dart @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:splash/main.dart' as entrypoint; + +void main() { + testWidgets('Displays flutter logo and message', (WidgetTester tester) async { + entrypoint.main(); + + expect(find.byType(FlutterLogo), findsOneWidget); + expect(find.text('This app is only meant to be run under the Flutter debugger'), findsOneWidget); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/stocks/android.iml b/novelforge-project/agent-workspace/flutter/examples/stocks/android.iml new file mode 100644 index 0000000000000000000000000000000000000000..79f6223dbf740f805ef97f2b382f592944c1b899 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/stocks/android.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/stocks/stocks.iml b/novelforge-project/agent-workspace/flutter/examples/stocks/stocks.iml new file mode 100644 index 0000000000000000000000000000000000000000..1d83ed3abc9085f991ca3f8f864f38df5577a8a6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/stocks/stocks.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/README.md b/novelforge-project/agent-workspace/flutter/examples/texture/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8a46fe3023ee0a9a7f3df0569dae2b54fe02f98a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/README.md @@ -0,0 +1,3 @@ +# Flutter Texture + +An example to show how to use custom Flutter textures. diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/lib/main.dart b/novelforge-project/agent-workspace/flutter/examples/texture/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..2f0cc7eed357fd7034484881e9cb240a169df4b6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/lib/main.dart @@ -0,0 +1,94 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +class TexturePage extends StatefulWidget { + const TexturePage({super.key}); + + @override + State createState() => _TexturePageState(); +} + +class _TexturePageState extends State { + static const int textureWidth = 300; + static const int textureHeight = 300; + static const MethodChannel channel = + MethodChannel('samples.flutter.io/texture'); + final Future textureId = + channel.invokeMethod('create', [textureWidth, textureHeight]); + + // Set the color of the texture. + Future setColor(int r, int g, int b) async { + await channel.invokeMethod('setColor', [r, g, b]); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + backgroundColor: Theme.of(context).colorScheme.inversePrimary, + title: const Text('Texture Example'), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + FutureBuilder( + future: textureId, + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasData) { + if (snapshot.data != null) { + return SizedBox( + width: textureWidth.toDouble(), + height: textureHeight.toDouble(), + child: Texture(textureId: snapshot.data!), + ); + } else { + return const Text('Error creating texture'); + } + } else { + return const Text('Creating texture...'); + } + }, + ), + const SizedBox(height: 10), + OutlinedButton( + child: const Text('Flutter Navy'), + onPressed: () => setColor(0x04, 0x2b, 0x59)), + const SizedBox(height: 10), + OutlinedButton( + child: const Text('Flutter Blue'), + onPressed: () => setColor(0x05, 0x53, 0xb1)), + const SizedBox(height: 10), + OutlinedButton( + child: const Text('Flutter Sky'), + onPressed: () => setColor(0x02, 0x7d, 0xfd)), + const SizedBox(height: 10), + OutlinedButton( + child: const Text('Red'), + onPressed: () => setColor(0xf2, 0x5d, 0x50)), + const SizedBox(height: 10), + OutlinedButton( + child: const Text('Yellow'), + onPressed: () => setColor(0xff, 0xf2, 0x75)), + const SizedBox(height: 10), + OutlinedButton( + child: const Text('Purple'), + onPressed: () => setColor(0x62, 0x00, 0xee)), + const SizedBox(height: 10), + OutlinedButton( + child: const Text('Green'), + onPressed: () => setColor(0x1c, 0xda, 0xc5)), + ], + ), + ), + ); + } +} + +void main() { + runApp(const MaterialApp(home: TexturePage())); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/linux/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/texture/linux/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..af26da2160e32c256ff2787baf527d7f2e4009c5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/linux/CMakeLists.txt @@ -0,0 +1,141 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.10) +project(runner LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 17) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "texture") +# The unique GTK application identifier for this application. See: +# https://wiki.gnome.org/HowDoI/ChooseApplicationID +set(APPLICATION_ID "io.flutter.examples.texture") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(SET CMP0063 NEW) + +# Load bundled libraries from the lib/ directory relative to the binary. +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Root filesystem for cross-building. +if(FLUTTER_TARGET_PLATFORM_SYSROOT) + set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endif() + +# Define build configuration options. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") +endif() + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_14) + target_compile_options(${TARGET} PRIVATE -Wall -Werror) + target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) + +add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") + +# Define the application target. To change its name, change BINARY_NAME above, +# not the value here, or `flutter run` will no longer work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} + "main.cc" + "my_application.cc" + "my_texture.cc" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add dependency libraries. Add any application-specific dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) + +# Only the install-generated bundle's copy of the executable will launch +# correctly, since the resources must in the right relative locations. To avoid +# people trying to run the unbundled copy, put it in a subdirectory instead of +# the default top-level location. +set_target_properties(${BINARY_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" +) + + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# By default, "installing" just makes a relocatable bundle in the build +# directory. +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +# Start with a clean build bundle directory every time. +install(CODE " + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") + " COMPONENT Runtime) + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) + install(FILES "${bundled_library}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endforeach(bundled_library) + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/linux/flutter/CMakeLists.txt b/novelforge-project/agent-workspace/flutter/examples/texture/linux/flutter/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d5bd01648a96d50136b2a97c8bb9aa5b711f6c39 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/linux/flutter/CMakeLists.txt @@ -0,0 +1,88 @@ +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.10) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. + +# Serves the same purpose as list(TRANSFORM ... PREPEND ...), +# which isn't available in 3.10. +function(list_prepend LIST_NAME PREFIX) + set(NEW_LIST "") + foreach(element ${${LIST_NAME}}) + list(APPEND NEW_LIST "${PREFIX}${element}") + endforeach(element) + set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) +endfunction() + +# === Flutter Library === +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) +pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) +pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) + +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "fl_basic_message_channel.h" + "fl_binary_codec.h" + "fl_binary_messenger.h" + "fl_dart_project.h" + "fl_engine.h" + "fl_json_message_codec.h" + "fl_json_method_codec.h" + "fl_message_codec.h" + "fl_method_call.h" + "fl_method_channel.h" + "fl_method_codec.h" + "fl_method_response.h" + "fl_plugin_registrar.h" + "fl_plugin_registry.h" + "fl_standard_message_codec.h" + "fl_standard_method_codec.h" + "fl_string_codec.h" + "fl_value.h" + "fl_view.h" + "flutter_linux.h" +) +list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") +target_link_libraries(flutter INTERFACE + PkgConfig::GTK + PkgConfig::GLIB + PkgConfig::GIO +) +add_dependencies(flutter flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/_phony_ + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" + ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} +) diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/linux/main.cc b/novelforge-project/agent-workspace/flutter/examples/texture/linux/main.cc new file mode 100644 index 0000000000000000000000000000000000000000..281a29e16b599a95421e7a35112eda77900ff549 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/linux/main.cc @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "my_application.h" + +int main(int argc, char** argv) { + g_autoptr(MyApplication) app = my_application_new(); + return g_application_run(G_APPLICATION(app), argc, argv); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_application.cc b/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_application.cc new file mode 100644 index 0000000000000000000000000000000000000000..f46cf9ca471540e378121ca20cc67967db55c900 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_application.cc @@ -0,0 +1,172 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "my_application.h" + +#include + +#include "my_texture.h" +#ifdef GDK_WINDOWING_X11 +#include +#endif + +#include "flutter/generated_plugin_registrant.h" + +struct _MyApplication { + GtkApplication parent_instance; + + // Channel to receive texture requests from Flutter. + FlMethodChannel* texture_channel; + + // Texture we've created. + MyTexture* texture; + + FlView* view; +}; + +G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) + +// Handle request to create the texture. +static FlMethodResponse* handle_create(MyApplication* self, + FlMethodCall* method_call) { + if (self->texture != nullptr) { + return FL_METHOD_RESPONSE(fl_method_error_response_new( + "Error", "texture already created", nullptr)); + } + + FlValue* args = fl_method_call_get_args(method_call); + if (fl_value_get_type(args) != FL_VALUE_TYPE_LIST || + fl_value_get_length(args) != 2) { + return FL_METHOD_RESPONSE(fl_method_error_response_new( + "Invalid args", "Invalid create args", nullptr)); + } + FlValue* width_value = fl_value_get_list_value(args, 0); + FlValue* height_value = fl_value_get_list_value(args, 1); + if (fl_value_get_type(width_value) != FL_VALUE_TYPE_INT || + fl_value_get_type(height_value) != FL_VALUE_TYPE_INT) { + return FL_METHOD_RESPONSE(fl_method_error_response_new( + "Invalid args", "Invalid create args", nullptr)); + } + + FlEngine* engine = fl_view_get_engine(self->view); + FlTextureRegistrar* texture_registrar = + fl_engine_get_texture_registrar(engine); + + self->texture = + my_texture_new(fl_value_get_int(width_value), + fl_value_get_int(height_value), 0x05, 0x53, 0xb1); + if (!fl_texture_registrar_register_texture(texture_registrar, + FL_TEXTURE(self->texture))) { + return FL_METHOD_RESPONSE(fl_method_error_response_new( + "Error", "Failed to register texture", nullptr)); + } + + // Return the texture ID to Flutter so it can use this texture. + g_autoptr(FlValue) id = + fl_value_new_int(fl_texture_get_id(FL_TEXTURE(self->texture))); + return FL_METHOD_RESPONSE(fl_method_success_response_new(id)); +} + +// Handle request to set the texture color. +static FlMethodResponse* handle_set_color(MyApplication* self, + FlMethodCall* method_call) { + FlValue* args = fl_method_call_get_args(method_call); + if (fl_value_get_type(args) != FL_VALUE_TYPE_LIST || + fl_value_get_length(args) != 3) { + return FL_METHOD_RESPONSE(fl_method_error_response_new( + "Invalid args", "Invalid setColor args", nullptr)); + } + FlValue* r_value = fl_value_get_list_value(args, 0); + FlValue* g_value = fl_value_get_list_value(args, 1); + FlValue* b_value = fl_value_get_list_value(args, 2); + if (fl_value_get_type(r_value) != FL_VALUE_TYPE_INT || + fl_value_get_type(g_value) != FL_VALUE_TYPE_INT || + fl_value_get_type(b_value) != FL_VALUE_TYPE_INT) { + return FL_METHOD_RESPONSE(fl_method_error_response_new( + "Invalid args", "Invalid setColor args", nullptr)); + } + + FlEngine* engine = fl_view_get_engine(self->view); + FlTextureRegistrar* texture_registrar = + fl_engine_get_texture_registrar(engine); + + // Redraw in requested color. + my_texture_set_color(self->texture, fl_value_get_int(r_value), + fl_value_get_int(g_value), fl_value_get_int(b_value)); + + // Notify Flutter the texture has changed. + fl_texture_registrar_mark_texture_frame_available(texture_registrar, + FL_TEXTURE(self->texture)); + + return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr)); +} + +// Handle texture requests from Flutter. +static void texture_channel_method_cb(FlMethodChannel* channel, + FlMethodCall* method_call, + gpointer user_data) { + MyApplication* self = MY_APPLICATION(user_data); + + const char* name = fl_method_call_get_name(method_call); + if (g_str_equal(name, "create")) { + g_autoptr(FlMethodResponse) response = handle_create(self, method_call); + fl_method_call_respond(method_call, response, NULL); + } else if (g_str_equal(name, "setColor")) { + g_autoptr(FlMethodResponse) response = handle_set_color(self, method_call); + fl_method_call_respond(method_call, response, NULL); + } else { + fl_method_call_respond_not_implemented(method_call, NULL); + } +} + +// Implements GObject::dispose. +static void my_application_dispose(GObject* object) { + MyApplication* self = MY_APPLICATION(object); + + g_clear_object(&self->texture_channel); + g_clear_object(&self->texture); + + G_OBJECT_CLASS(my_application_parent_class)->dispose(object); +} + +// Implements GApplication::activate. +static void my_application_activate(GApplication* application) { + MyApplication* self = MY_APPLICATION(application); + GtkWindow* window = + GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + + gtk_window_set_default_size(window, 1280, 720); + gtk_widget_show(GTK_WIDGET(window)); + + g_autoptr(FlDartProject) project = fl_dart_project_new(); + self->view = fl_view_new(project); + gtk_widget_show(GTK_WIDGET(self->view)); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(self->view)); + + // Create channel to handle texture requests from Flutter. + FlEngine* engine = fl_view_get_engine(self->view); + g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new(); + self->texture_channel = fl_method_channel_new( + fl_engine_get_binary_messenger(engine), "samples.flutter.io/texture", + FL_METHOD_CODEC(codec)); + fl_method_channel_set_method_call_handler( + self->texture_channel, texture_channel_method_cb, self, nullptr); + + fl_register_plugins(FL_PLUGIN_REGISTRY(self->view)); + + gtk_widget_grab_focus(GTK_WIDGET(self->view)); +} + +static void my_application_class_init(MyApplicationClass* klass) { + G_OBJECT_CLASS(klass)->dispose = my_application_dispose; + G_APPLICATION_CLASS(klass)->activate = my_application_activate; +} + +static void my_application_init(MyApplication* self) {} + +MyApplication* my_application_new() { + return MY_APPLICATION(g_object_new(my_application_get_type(), + "application-id", APPLICATION_ID, "flags", + G_APPLICATION_NON_UNIQUE, nullptr)); +} diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_application.h b/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_application.h new file mode 100644 index 0000000000000000000000000000000000000000..8c66ec485434d1f922c9915bdaefcb8969cdfec9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_application.h @@ -0,0 +1,22 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_MY_APPLICATION_H_ +#define FLUTTER_MY_APPLICATION_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, + GtkApplication) + +/** + * my_application_new: + * + * Creates a new Flutter-based application. + * + * Returns: a new #MyApplication. + */ +MyApplication* my_application_new(); + +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_texture.cc b/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_texture.cc new file mode 100644 index 0000000000000000000000000000000000000000..5690ad000455ee7a3b3c536c4a876e028086c742 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_texture.cc @@ -0,0 +1,72 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "my_texture.h" + +// An object that generates a texture for Flutter. +struct _MyTexture { + FlPixelBufferTexture parent_instance; + + // Dimensions of texture. + uint32_t width; + uint32_t height; + + // Buffer used to store texture. + uint8_t* buffer; +}; + +G_DEFINE_TYPE(MyTexture, my_texture, fl_pixel_buffer_texture_get_type()) + +// Implements GObject::dispose. +static void my_texture_dispose(GObject* object) { + MyTexture* self = MY_TEXTURE(object); + + free(self->buffer); + + G_OBJECT_CLASS(my_texture_parent_class)->dispose(object); +} + +// Implements FlPixelBufferTexture::copy_pixels. +static gboolean my_texture_copy_pixels(FlPixelBufferTexture* texture, + const uint8_t** out_buffer, + uint32_t* width, uint32_t* height, + GError** error) { + MyTexture* self = MY_TEXTURE(texture); + *out_buffer = self->buffer; + *width = self->width; + *height = self->height; + return TRUE; +} + +static void my_texture_class_init(MyTextureClass* klass) { + G_OBJECT_CLASS(klass)->dispose = my_texture_dispose; + FL_PIXEL_BUFFER_TEXTURE_CLASS(klass)->copy_pixels = my_texture_copy_pixels; +} + +static void my_texture_init(MyTexture* self) {} + +MyTexture* my_texture_new(uint32_t width, uint32_t height, uint8_t r, uint8_t g, + uint8_t b) { + MyTexture* self = MY_TEXTURE(g_object_new(my_texture_get_type(), nullptr)); + self->width = width; + self->height = height; + self->buffer = static_cast(malloc(self->width * self->height * 4)); + my_texture_set_color(self, r, g, b); + return self; +} + +// Draws the texture with the requested color. +void my_texture_set_color(MyTexture* self, uint8_t r, uint8_t g, uint8_t b) { + g_return_if_fail(MY_IS_TEXTURE(self)); + + for (size_t y = 0; y < self->height; y++) { + for (size_t x = 0; x < self->width; x++) { + uint8_t* pixel = self->buffer + (y * self->width * 4) + (x * 4); + pixel[0] = r; + pixel[1] = g; + pixel[2] = b; + pixel[3] = 255; + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_texture.h b/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_texture.h new file mode 100644 index 0000000000000000000000000000000000000000..2b8cf82ab6577304a2b126073c34db53013b6e14 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/linux/my_texture.h @@ -0,0 +1,39 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_MY_TEXTURE_H_ +#define FLUTTER_MY_TEXTURE_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyTexture, my_texture, MY, TEXTURE, FlPixelBufferTexture) + +/** + * my_texture_new: + * @self: a #MyTexture. + * @width: width of texture in pixels. + * @height: height of texture in pixels. + * @r: red value for texture color. + * @g: green value for texture color. + * @b: blue value for texture color. + * + * Creates a new texture containing a single color for Flutter to render with. + * + * Returns: a new #MyTexture. + */ +MyTexture* my_texture_new(uint32_t width, uint32_t height, uint8_t r, uint8_t g, + uint8_t b); + +/** + * my_texture_new: + * @self: a #MyTexture. + * @r: red value for texture color. + * @g: green value for texture color. + * @b: blue value for texture color. + * + * Sets the color the texture contains. + */ +void my_texture_set_color(MyTexture* self, uint8_t r, uint8_t g, uint8_t b); + +#endif // FLUTTER_MY_TEXTURE_H_ diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/pubspec.lock b/novelforge-project/agent-workspace/flutter/examples/texture/pubspec.lock new file mode 100644 index 0000000000000000000000000000000000000000..1481be86c3d550c7abbae66c8b1281b34ffe2a59 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/pubspec.lock @@ -0,0 +1,452 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: "direct dev" + description: + name: _fe_analyzer_shared + sha256: "36a321c3d2cbe01cbcb3540a87b8843846e0206df3e691fa7b23e19e78de6d49" + url: "https://pub.dev" + source: hosted + version: "65.0.0" + analyzer: + dependency: "direct dev" + description: + name: analyzer + sha256: dfe03b90ec022450e22513b5e5ca1f01c0c01de9c3fba2f7fd233cb57a6b9a07 + url: "https://pub.dev" + source: hosted + version: "6.3.0" + args: + dependency: "direct dev" + description: + name: args + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" + source: hosted + version: "2.4.2" + async: + dependency: "direct dev" + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: "direct dev" + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: "direct main" + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: "direct dev" + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: "direct dev" + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: "direct dev" + description: + name: coverage + sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76" + url: "https://pub.dev" + source: hosted + version: "1.7.2" + crypto: + dependency: "direct dev" + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + fake_async: + dependency: "direct dev" + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + file: + dependency: "direct dev" + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + frontend_server_client: + dependency: "direct dev" + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + glob: + dependency: "direct dev" + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + http_multi_server: + dependency: "direct dev" + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: "direct dev" + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: "direct dev" + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: "direct dev" + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + leak_tracker: + dependency: "direct dev" + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: "direct dev" + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: "direct dev" + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + logging: + dependency: "direct dev" + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: "direct dev" + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: "direct main" + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: "direct main" + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + mime: + dependency: "direct dev" + description: + name: mime + sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + url: "https://pub.dev" + source: hosted + version: "1.0.4" + node_preamble: + dependency: "direct dev" + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: "direct dev" + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: "direct dev" + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + pool: + dependency: "direct dev" + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + pub_semver: + dependency: "direct dev" + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + shelf: + dependency: "direct dev" + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: "direct dev" + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: "direct dev" + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: "direct dev" + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_map_stack_trace: + dependency: "direct dev" + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: "direct dev" + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" + source_span: + dependency: "direct dev" + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: "direct dev" + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: "direct dev" + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: "direct dev" + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: "direct dev" + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f + url: "https://pub.dev" + source: hosted + version: "1.24.9" + test_api: + dependency: "direct dev" + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + test_core: + dependency: "direct dev" + description: + name: test_core + sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a + url: "https://pub.dev" + source: hosted + version: "0.5.9" + typed_data: + dependency: "direct dev" + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: "direct dev" + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" + watcher: + dependency: "direct dev" + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web: + dependency: "direct dev" + description: + name: web + sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa + url: "https://pub.dev" + source: hosted + version: "0.4.0" + web_socket_channel: + dependency: "direct dev" + description: + name: web_socket_channel + sha256: "045ec2137c27bf1a32e6ffa0e734d532a6677bf9016a0d1a406c54e499ff945b" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + webkit_inspection_protocol: + dependency: "direct dev" + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: "direct dev" + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.2.0 <4.0.0" diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/pubspec.yaml b/novelforge-project/agent-workspace/flutter/examples/texture/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8fe045051bf6f1728092b7a54c0a051e0a68bbc7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/pubspec.yaml @@ -0,0 +1,70 @@ +name: texture + +environment: + sdk: '>=3.2.0-0 <4.0.0' + +dependencies: + flutter: + sdk: flutter + + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +dev_dependencies: + flutter_test: + sdk: flutter + test: 1.24.9 + + _fe_analyzer_shared: 65.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + analyzer: 6.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + args: 2.4.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + convert: 3.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + coverage: 1.7.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + crypto: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + file: 7.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + frontend_server_client: 3.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + glob: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_multi_server: 3.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_parser: 4.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + io: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + js: 0.6.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker: 10.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_flutter_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_testing: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + logging: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + matcher: 0.12.16+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + mime: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + node_preamble: 2.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + package_config: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + path: 1.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pool: 1.5.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pub_semver: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf: 1.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_packages_handler: 3.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_static: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_web_socket: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_map_stack_trace: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_maps: 0.10.12 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_core: 0.5.9 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + typed_data: 1.3.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + watcher: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web_socket_channel: 2.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + yaml: 3.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +# PUBSPEC CHECKSUM: f8d9 diff --git a/novelforge-project/agent-workspace/flutter/examples/texture/test/texture_test.dart b/novelforge-project/agent-workspace/flutter/examples/texture/test/texture_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..b5c796dc27107f303b954092129633d242a630ec --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/examples/texture/test/texture_test.dart @@ -0,0 +1,16 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:texture/main.dart' as texture; + +void main() { + testWidgets('Texture smoke test', (WidgetTester tester) async { + texture + .main(); // builds the app and schedules a frame but doesn't trigger one + await tester.pump(); // triggers a frame + + expect(find.text('Flutter Blue'), findsOneWidget); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/README.md b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9e98e276db08afa3ac268b96327a84f49bd55dc4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/README.md @@ -0,0 +1,43 @@ +## Directory contents + +The `.yaml` files in these directories are used to +define the [`dart fix` framework](https://dart.dev/tools/dart-fix) refactorings +used by the Flutter framework. + +The number of fix rules defined in a file should not exceed 50 for better +maintainability. Searching for `title:` in a given `.yaml` file will account +for the number of fixes. Splitting out fix rules should be done by class. + +When adding a new `.yaml` file, make a copy of `fix_template.yaml`. If the new +file is not for generic library fixes (`fix_material.yaml`), ensure it is +enclosed in an appropriate library directory (`fix_data/fix_material`), and +named after the class. Fix files outside of generic libraries should represent +individual classes (`fix_data/fix_material/fix_app_bar.yaml`). + +See the flutter/packages/flutter/test_fixes directory for the tests that +validate these fix rules. + +To run these tests locally, execute this command in the +flutter/packages/flutter/test_fixes directory. +```sh +dart fix --compare-to-golden +``` + +For more documentation about Data Driven Fixes, see +https://dart.dev/go/data-driven-fixes#test-folder. + +To learn more about how fixes are authored in package:flutter, see +https://github.com/flutter/flutter/wiki/Data-driven-Fixes + +## When making structural changes to this directory + +The tests in this directory are also invoked from external +repositories. Specifically, the CI system for the dart-lang/sdk repo +runs these tests in order to ensure that changes to the dart fix file +format do not break Flutter. + +See [tools/bots/flutter/analyze_flutter_flutter.sh](https://github.com/dart-lang/sdk/blob/main/tools/bots/flutter/analyze_flutter_flutter.sh) +for where the tests are invoked. + +When possible, please coordinate changes to this directory that might affect the +`analyze_flutter_flutter.sh` script. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_cupertino.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_cupertino.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b9e40b7f1e74953ad84d05dbfb9304365453b399 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_cupertino.yaml @@ -0,0 +1,298 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are from the Cupertino library. * +version: 1 +transforms: + # Change made in https://github.com/flutter/flutter/pull/20649 + # TODO(Piinks): Add tests when `bulkApply:false` testing is supported, https://github.com/dart-lang/sdk/issues/44639 + - title: "Replace with 'CupertinoPopupSurface'" + date: 2021-01-07 + bulkApply: false + element: + uris: [ 'cupertino.dart' ] + class: 'CupertinoDialog' + changes: + - kind: 'rename' + newName: 'CupertinoPopupSurface' + + # Change made in https://github.com/flutter/flutter/pull/20649 + # TODO(Piinks): Add tests when `bulkApply:false` testing is supported, https://github.com/dart-lang/sdk/issues/44639 + - title: "Replace with 'CupertinoAlertDialog'" + date: 2021-01-07 + bulkApply: false + element: + uris: [ 'cupertino.dart' ] + class: 'CupertinoDialog' + changes: + - kind: 'rename' + newName: 'CupertinoAlertDialog' + - kind: 'renameParameter' + oldName: 'child' + newName: 'content' + + # Changes made in https://github.com/flutter/flutter/pull/68905. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'cupertino.dart' ] + method: 'resolveFrom' + inClass: 'CupertinoTextThemeData' + changes: + - kind: 'removeParameter' + name: 'nullOk' + + # Changes made in https://github.com/flutter/flutter/pull/68905. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'cupertino.dart' ] + method: 'resolveFrom' + inClass: 'NoDefaultCupertinoThemeData' + changes: + - kind: 'removeParameter' + name: 'nullOk' + + # Changes made in https://github.com/flutter/flutter/pull/68905. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'cupertino.dart' ] + method: 'resolveFrom' + inClass: 'CupertinoThemeData' + changes: + - kind: 'removeParameter' + name: 'nullOk' + + # Changes made in https://github.com/flutter/flutter/pull/68736. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'cupertino.dart' ] + method: 'brightnessOf' + inClass: 'CupertinoTheme' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeBrightnessOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68905. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'cupertino.dart' ] + method: 'of' + inClass: 'CupertinoUserInterfaceLevel' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68905. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'cupertino.dart' ] + method: 'resolveFrom' + inClass: 'CupertinoDynamicColor' + changes: + - kind: 'removeParameter' + name: 'nullOk' + + # Changes made in https://github.com/flutter/flutter/pull/68905. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'cupertino.dart' ] + method: 'resolve' + inClass: 'CupertinoDynamicColor' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeResolve' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/72043 + - title: "Migrate to 'maxLengthEnforcement'" + date: 2020-12-13 + element: + uris: [ 'cupertino.dart' ] + field: 'maxLengthEnforced' + inClass: 'CupertinoTextField' + changes: + - kind: 'rename' + newName: 'maxLengthEnforcement' + + # Changes made in https://github.com/flutter/flutter/pull/72043 + - title: "Migrate to 'maxLengthEnforcement'" + date: 2020-12-13 + element: + uris: [ 'cupertino.dart' ] + constructor: 'borderless' + inClass: 'CupertinoTextField' + oneOf: + - if: "maxLengthEnforced == 'true'" + changes: + - kind: 'addParameter' + index: 0 + name: 'maxLengthEnforcement' + style: optional_named + argumentValue: + expression: 'MaxLengthEnforcement.enforce' + requiredIf: "maxLengthEnforced == 'true'" + - kind: 'removeParameter' + name: 'maxLengthEnforced' + - if: "maxLengthEnforced == 'false'" + changes: + - kind: 'addParameter' + index: 0 + name: 'maxLengthEnforcement' + style: optional_named + argumentValue: + expression: 'MaxLengthEnforcement.none' + requiredIf: "maxLengthEnforced == 'false'" + - kind: 'removeParameter' + name: 'maxLengthEnforced' + variables: + maxLengthEnforced: + kind: 'fragment' + value: 'arguments[maxLengthEnforced]' + + # Changes made in https://github.com/flutter/flutter/pull/72043 + - title: "Migrate to 'maxLengthEnforcement'" + date: 2020-12-13 + element: + uris: [ 'cupertino.dart' ] + constructor: '' + inClass: 'CupertinoTextField' + oneOf: + - if: "maxLengthEnforced == 'true'" + changes: + - kind: 'addParameter' + index: 0 + name: 'maxLengthEnforcement' + style: optional_named + argumentValue: + expression: 'MaxLengthEnforcement.enforce' + requiredIf: "maxLengthEnforced == 'true'" + - kind: 'removeParameter' + name: 'maxLengthEnforced' + - if: "maxLengthEnforced == 'false'" + changes: + - kind: 'addParameter' + index: 0 + name: 'maxLengthEnforcement' + style: optional_named + argumentValue: + expression: 'MaxLengthEnforcement.none' + requiredIf: "maxLengthEnforced == 'false'" + - kind: 'removeParameter' + name: 'maxLengthEnforced' + variables: + maxLengthEnforced: + kind: 'fragment' + value: 'arguments[maxLengthEnforced]' + + # Changes made in https://github.com/flutter/flutter/pull/96957 + - title: "Migrate to 'thumbVisibility'" + date: 2022-01-20 + element: + uris: [ 'cupertino.dart' ] + field: 'isAlwaysShown' + inClass: 'CupertinoScrollbar' + changes: + - kind: 'rename' + newName: 'thumbVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/96957 + - title: "Migrate to 'thumbVisibility'" + date: 2022-01-20 + element: + uris: [ 'cupertino.dart' ] + constructor: '' + inClass: 'CupertinoScrollbar' + changes: + - kind: 'renameParameter' + oldName: 'isAlwaysShown' + newName: 'thumbVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/41859 + - title: "Remove 'brightness'" + date: 2020-12-10 + element: + uris: [ 'cupertino.dart' ] + constructor: '' + inClass: 'CupertinoTextThemeData' + changes: + - kind: 'removeParameter' + name: 'brightness' + + # Changes made in https://github.com/flutter/flutter/pull/41859 + - title: "Remove 'brightness'" + date: 2020-12-10 + element: + uris: [ 'cupertino.dart' ] + method: 'copyWith' + inClass: 'CupertinoTextThemeData' + changes: + - kind: 'removeParameter' + name: 'brightness' + + # Changes made in https://github.com/flutter/flutter/pull/78588 + - title: "Migrate to 'buildOverscrollIndicator'" + date: 2021-03-18 + element: + uris: [ 'cupertino.dart' ] + method: 'buildViewportChrome' + inClass: 'CupertinoScrollBehavior' + changes: + - kind: 'rename' + newName: 'buildOverscrollIndicator' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_gestures.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_gestures.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b9b2accf53887670a92bbd7e7eab027e8f274284 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_gestures.yaml @@ -0,0 +1,478 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are from the Gestures library. * +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/28602 + - title: "Rename to 'fromMouseEvent'" + date: 2020-12-15 + element: + uris: [ 'gestures.dart' ] + constructor: 'fromHoverEvent' + inClass: 'PointerEnterEvent' + changes: + - kind: 'rename' + newName: 'fromMouseEvent' + + # Changes made in https://github.com/flutter/flutter/pull/28602 + - title: "Rename to 'fromMouseEvent'" + date: 2020-12-15 + element: + uris: [ 'gestures.dart' ] + constructor: 'fromHoverEvent' + inClass: 'PointerExitEvent' + changes: + - kind: 'rename' + newName: 'fromMouseEvent' + + # Changes made in https://github.com/flutter/flutter/pull/66043 + - title: "Use withKind" + date: 2020-09-17 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'VelocityTracker' + oneOf: + - if: "pointerDeviceKind == ''" + changes: + - kind: 'rename' + newName: 'withKind' + - kind: 'addParameter' + index: 0 + name: 'kind' + style: required_positional + argumentValue: + expression: 'PointerDeviceKind.touch' + - if: "pointerDeviceKind != ''" + changes: + - kind: 'rename' + newName: 'withKind' + variables: + pointerDeviceKind: + kind: 'fragment' + value: 'arguments[0]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'ScaleGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 3 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'MultiTapGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 4 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'DoubleTapGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 3 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'DelayedMultiDragGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 4 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'VerticalMultiDragGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 3 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'HorizontalMultiDragGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 3 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'ImmediateMultiDragGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 3 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'MultiDragGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 3 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'LongPressGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 4 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'ForcePressGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 6 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'EagerGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 2 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'PrimaryPointerGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 6 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'OneSequenceGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 3 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'GestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 3 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'HorizontalDragGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 3 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'VerticalDragGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 3 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + + # Changes made in https://github.com/flutter/flutter/pull/81858 + - title: "Migrate to 'supportedDevices'" + date: 2021-05-04 + element: + uris: [ 'gestures.dart' ] + constructor: '' + inClass: 'DragGestureRecognizer' + oneOf: + - if: "kind != ''" + changes: + - kind: 'addParameter' + index: 5 + name: 'supportedDevices' + style: optional_named + argumentValue: + expression: '{{% kind %}}' + requiredIf: "kind != ''" + - kind: 'removeParameter' + name: 'kind' + variables: + kind: + kind: 'fragment' + value: 'arguments[kind]' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_app_bar.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_app_bar.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4a6a6509663d71e07d41394bd770ecdbfc9592e3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_app_bar.yaml @@ -0,0 +1,150 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for AppBar from the Material library. * +# For fixes to +# * AppBarTheme: fix_app_bar_theme.yaml +# * ColorScheme: fix_color_scheme.yaml +# * Material (general): fix_material.yaml +# * SliverAppBar: fix_sliver_app_bar.yaml +# * TextTheme: fix_text_theme.yaml +# * ThemeData: fix_theme_data.yaml +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Remove 'backwardsCompatibility'" + date: 2020-07-12 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'AppBar' + changes: + - kind: 'removeParameter' + name: 'backwardsCompatibility' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'toolbarTextStyle' & 'titleTextStyle'" + date: 2020-07-12 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'AppBar' + changes: + - kind: 'addParameter' + index: 24 + name: 'toolbarTextStyle' + style: optional_named + argumentValue: + expression: '{% textTheme %}.bodyText2' + requiredIf: "textTheme != ''" + - kind: 'addParameter' + index: 25 + name: 'titleTextStyle' + style: optional_named + argumentValue: + expression: '{% textTheme %}.headline6' + requiredIf: "textTheme != ''" + - kind: 'removeParameter' + name: 'textTheme' + variables: + textTheme: + kind: 'fragment' + value: 'arguments[textTheme]' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'toolbarTextStyle'" + date: 2021-07-12 + # TODO(Piinks): Add tests when `bulkApply:false` testing is supported, https://github.com/dart-lang/sdk/issues/44639 + bulkApply: false + element: + uris: [ 'material.dart' ] + field: 'textTheme' + inClass: 'AppBar' + changes: + - kind: 'rename' + newName: 'toolbarTextStyle' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'titleTextStyle'" + date: 2021-07-12 + # TODO(Piinks): Add tests when `bulkApply:false` testing is supported, https://github.com/dart-lang/sdk/issues/44639 + bulkApply: false + element: + uris: [ 'material.dart' ] + field: 'textTheme' + inClass: 'AppBar' + changes: + - kind: 'rename' + newName: 'titleTextStyle' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'systemOverlayStyle'" + date: 2020-07-12 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'AppBar' + oneOf: + - if: "brightness == 'Brightness.dark'" + changes: + - kind: 'addParameter' + index: 27 + name: 'systemOverlayStyle' + style: optional_named + argumentValue: + expression: '{% SystemUiOverlayStyle %}.light' + requiredIf: "brightness == 'Brightness.dark'" + variables: + SystemUiOverlayStyle: + kind: 'import' + uris: [ 'services.dart' ] + name: 'SystemUiOverlayStyle' + - kind: 'removeParameter' + name: 'brightness' + - if: "brightness == 'Brightness.light'" + changes: + - kind: 'addParameter' + index: 27 + name: 'systemOverlayStyle' + style: optional_named + argumentValue: + expression: '{% SystemUiOverlayStyle %}.dark' + requiredIf: "brightness == 'Brightness.light'" + variables: + SystemUiOverlayStyle: + kind: 'import' + uris: [ 'services.dart' ] + name: 'SystemUiOverlayStyle' + - kind: 'removeParameter' + name: 'brightness' + variables: + brightness: + kind: 'fragment' + value: 'arguments[brightness]' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'systemOverlayStyle'" + date: 2021-07-12 + element: + uris: [ 'material.dart' ] + field: 'brightness' + inClass: 'AppBar' + changes: + - kind: 'rename' + newName: 'systemOverlayStyle' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_app_bar_theme.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_app_bar_theme.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1c0ea6537a04ab0670099443e74d2b819feea9ca --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_app_bar_theme.yaml @@ -0,0 +1,246 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for AppBarTheme from the Material library. * +# For fixes to +# * AppBar: fix_app_bar.yaml +# * ColorScheme: fix_color_scheme.yaml +# * Material (general): fix_material.yaml +# * SliverAppBar: fix_sliver_app_bar.yaml +# * TextTheme: fix_text_theme.yaml +# * ThemeData: fix_theme_data.yaml +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'systemOverlayStyle'" + date: 2021-07-12 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'AppBarTheme' + oneOf: + - if: "brightness == 'Brightness.dark'" + changes: + - kind: 'addParameter' + index: 14 + name: 'systemOverlayStyle' + style: optional_named + argumentValue: + expression: '{% SystemUiOverlayStyle %}.light' + requiredIf: "brightness == 'Brightness.dark'" + variables: + SystemUiOverlayStyle: + kind: 'import' + uris: [ 'services.dart' ] + name: 'SystemUiOverlayStyle' + - kind: 'removeParameter' + name: 'brightness' + - if: "brightness == 'Brightness.light'" + changes: + - kind: 'addParameter' + index: 14 + name: 'systemOverlayStyle' + style: optional_named + argumentValue: + expression: '{% SystemUiOverlayStyle %}.dark' + requiredIf: "brightness == 'Brightness.light'" + variables: + SystemUiOverlayStyle: + kind: 'import' + uris: [ 'services.dart' ] + name: 'SystemUiOverlayStyle' + - kind: 'removeParameter' + name: 'brightness' + variables: + brightness: + kind: 'fragment' + value: 'arguments[brightness]' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'systemOverlayStyle'" + date: 2020-07-12 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'AppBarTheme' + oneOf: + - if: "brightness == 'Brightness.dark'" + changes: + - kind: 'addParameter' + index: 14 + name: 'systemOverlayStyle' + style: optional_named + argumentValue: + expression: '{% SystemUiOverlayStyle %}.light' + requiredIf: "brightness == 'Brightness.dark'" + variables: + SystemUiOverlayStyle: + kind: 'import' + uris: [ 'services.dart' ] + name: 'SystemUiOverlayStyle' + - kind: 'removeParameter' + name: 'brightness' + - if: "brightness == 'Brightness.light'" + changes: + - kind: 'addParameter' + index: 14 + name: 'systemOverlayStyle' + style: optional_named + argumentValue: + expression: '{% SystemUiOverlayStyle %}.dark' + requiredIf: "brightness == 'Brightness.light'" + variables: + SystemUiOverlayStyle: + kind: 'import' + uris: [ 'services.dart' ] + name: 'SystemUiOverlayStyle' + - kind: 'removeParameter' + name: 'brightness' + variables: + brightness: + kind: 'fragment' + value: 'arguments[brightness]' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'systemOverlayStyle'" + date: 2021-07-12 + element: + uris: [ 'material.dart' ] + field: 'brightness' + inClass: 'AppBarTheme' + changes: + - kind: 'rename' + newName: 'systemOverlayStyle' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'toolbarTextStyle'" + date: 2021-07-12 + # TODO(Piinks): Add tests when `bulkApply:false` testing is supported, https://github.com/dart-lang/sdk/issues/44639 + bulkApply: false + element: + uris: [ 'material.dart' ] + field: 'textTheme' + inClass: 'AppBarTheme' + changes: + - kind: 'rename' + newName: 'toolbarTextStyle' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'titleTextStyle'" + date: 2021-07-12 + # TODO(Piinks): Add tests when `bulkApply:false` testing is supported, https://github.com/dart-lang/sdk/issues/44639 + bulkApply: false + element: + uris: [ 'material.dart' ] + field: 'textTheme' + inClass: 'AppBarTheme' + changes: + - kind: 'rename' + newName: 'titleTextStyle' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'toolbarTextStyle' & 'titleTextStyle'" + date: 2021-07-12 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'AppBarTheme' + changes: + - kind: 'addParameter' + index: 12 + name: 'toolbarTextStyle' + style: optional_named + argumentValue: + expression: '{% textTheme %}.bodyText2' + requiredIf: "textTheme != ''" + - kind: 'addParameter' + index: 13 + name: 'titleTextStyle' + style: optional_named + argumentValue: + expression: '{% textTheme %}.headline6' + requiredIf: "textTheme != ''" + - kind: 'removeParameter' + name: 'textTheme' + variables: + textTheme: + kind: 'fragment' + value: 'arguments[textTheme]' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'toolbarTextStyle' & 'titleTextStyle'" + date: 2020-07-12 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'AppBarTheme' + changes: + - kind: 'addParameter' + index: 13 + name: 'toolbarTextStyle' + style: optional_named + argumentValue: + expression: '{% textTheme %}.bodyText2' + requiredIf: "textTheme != ''" + - kind: 'addParameter' + index: 14 + name: 'titleTextStyle' + style: optional_named + argumentValue: + expression: '{% textTheme %}.headline6' + requiredIf: "textTheme != ''" + - kind: 'removeParameter' + name: 'textTheme' + variables: + textTheme: + kind: 'fragment' + value: 'arguments[textTheme]' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'backgroundColor'" + date: 2021-07-12 + element: + uris: [ 'material.dart' ] + getter: color + inClass: 'AppBarTheme' + changes: + - kind: 'rename' + newName: 'backgroundColor' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Remove 'backwardsCompatibility'" + date: 2021-07-12 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'AppBarTheme' + changes: + - kind: 'removeParameter' + name: 'backwardsCompatibility' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Remove 'backwardsCompatibility'" + date: 2020-07-12 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'AppBarTheme' + changes: + - kind: 'removeParameter' + name: 'backwardsCompatibility' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_button_bar.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_button_bar.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b340e3f70a6be749b0c495460f879d6509a35e24 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_button_bar.yaml @@ -0,0 +1,40 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/to/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for ButtonBar from the Material library. * +# For fixes to +# * AppBarTheme: fix_app_bar_theme.yaml +# * AppBar: fix_app_bar.yaml +# * ButtonBar: fix_button_bar.yaml +# * ColorScheme: fix_color_scheme.yaml +# * Material (general): fix_material.yaml +# * SliverAppBar: fix_sliver_app_bar.yaml +# * TextTheme: fix_text_theme.yaml +# * ThemeData: fix_theme_data.yaml +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/145523 + - title: "Migrate to 'OverflowBar'" + date: 2024-02-28 + element: + uris: [ 'material.dart' ] + class: 'ButtonBar' + changes: + - kind: 'rename' + newName: 'OverflowBar' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_color_scheme.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_color_scheme.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6e7c3d18a36c5ff067916a3042af7bc89111c236 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_color_scheme.yaml @@ -0,0 +1,129 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for ColorScheme from the Material library. * +# For fixes to +# * AppBar: fix_app_bar.yaml +# * AppBarTheme: fix_app_bar_theme.yaml +# * Material (general): fix_material.yaml +# * SliverAppBar: fix_sliver_app_bar.yaml +# * TextTheme: fix_text_theme.yaml +# * ThemeData: fix_theme_data.yaml +version: 1 +transforms: + + # Changes made in https://github.com/flutter/flutter/pull/93427 + - title: "Remove 'primaryVariant' and 'secondaryVariant'" + date: 2021-11-19 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ColorScheme' + changes: + - kind: 'removeParameter' + name: 'primaryVariant' + - kind: 'removeParameter' + name: 'secondaryVariant' + + # Changes made in https://github.com/flutter/flutter/pull/93427 + - title: "Remove 'primaryVariant' and 'secondaryVariant'" + date: 2021-11-19 + element: + uris: [ 'material.dart' ] + constructor: 'light' + inClass: 'ColorScheme' + changes: + - kind: 'removeParameter' + name: 'primaryVariant' + - kind: 'removeParameter' + name: 'secondaryVariant' + + # Changes made in https://github.com/flutter/flutter/pull/93427 + - title: "Remove 'primaryVariant' and 'secondaryVariant'" + date: 2021-11-19 + element: + uris: [ 'material.dart' ] + constructor: 'dark' + inClass: 'ColorScheme' + changes: + - kind: 'removeParameter' + name: 'primaryVariant' + - kind: 'removeParameter' + name: 'secondaryVariant' + + # Changes made in https://github.com/flutter/flutter/pull/93427 + - title: "Remove 'primaryVariant' and 'secondaryVariant'" + date: 2021-11-19 + element: + uris: [ 'material.dart' ] + constructor: 'highContrastLight' + inClass: 'ColorScheme' + changes: + - kind: 'removeParameter' + name: 'primaryVariant' + - kind: 'removeParameter' + name: 'secondaryVariant' + + # Changes made in https://github.com/flutter/flutter/pull/93427 + - title: "Remove 'primaryVariant' and 'secondaryVariant'" + date: 2021-11-19 + element: + uris: [ 'material.dart' ] + constructor: 'highContrastDark' + inClass: 'ColorScheme' + changes: + - kind: 'removeParameter' + name: 'primaryVariant' + - kind: 'removeParameter' + name: 'secondaryVariant' + + # Changes made in https://github.com/flutter/flutter/pull/93427 + - title: "Remove 'primaryVariant' and 'secondaryVariant'" + date: 2021-11-19 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ColorScheme' + changes: + - kind: 'removeParameter' + name: 'primaryVariant' + - kind: 'removeParameter' + name: 'secondaryVariant' + + # Changes made in https://github.com/flutter/flutter/pull/93427 + - title: "Migrate 'primaryVariant' to 'primaryContainer'" + date: 2021-11-19 + element: + uris: [ 'material.dart' ] + getter: 'primaryVariant' + inClass: 'ColorScheme' + changes: + - kind: 'rename' + newName: 'primaryContainer' + + # Changes made in https://github.com/flutter/flutter/pull/93427 + - title: "Migrate 'secondaryVariant' to 'secondaryContainer'" + date: 2021-11-19 + element: + uris: [ 'material.dart' ] + getter: 'secondaryVariant' + inClass: 'ColorScheme' + changes: + - kind: 'rename' + newName: 'secondaryContainer' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_material.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_material.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fb8467c0c858fbaab12c7991b01cc0ddefae53a4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_material.yaml @@ -0,0 +1,939 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are from the Material library. * +# For fixes to +# * AppBar: fix_app_bar.yaml +# * AppBarTheme: fix_app_bar_theme.yaml +# * ColorScheme: fix_color_scheme.yaml +# * SliverAppBar: fix_sliver_app_bar.yaml +# * TextTheme: fix_text_theme.yaml +# * ThemeData: fix_theme_data.yaml +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/15303 + - title: "Replace 'child' with 'builder'" + date: 2020-12-17 + element: + uris: [ 'material.dart' ] + function: 'showDialog' + changes: + - kind: 'addParameter' + index: 0 + name: 'builder' + style: optional_named + argumentValue: + expression: '(context) => {% widget %}' + requiredIf: "widget != ''" + variables: + widget: + kind: fragment + value: 'arguments[child]' + - kind: 'removeParameter' + name: 'child' + + # Changes made in https://github.com/flutter/flutter/pull/61648 + - title: "Migrate to 'autovalidateMode'" + date: 2020-09-02 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'TextFormField' + oneOf: + - if: "autovalidate == 'true'" + changes: + - kind: 'addParameter' + index: 0 + name: 'autovalidateMode' + style: optional_named + argumentValue: + expression: 'AutovalidateMode.always' + requiredIf: "autovalidate == 'true'" + - kind: 'removeParameter' + name: 'autovalidate' + - if: "autovalidate == 'false'" + changes: + - kind: 'addParameter' + index: 0 + name: 'autovalidateMode' + style: optional_named + argumentValue: + expression: 'AutovalidateMode.disabled' + requiredIf: "autovalidate == 'false'" + - kind: 'removeParameter' + name: 'autovalidate' + variables: + autovalidate: + kind: 'fragment' + value: 'arguments[autovalidate]' + + # Changes made in https://github.com/flutter/flutter/pull/61648 + - title: "Migrate to 'autovalidateMode'" + date: 2020-09-02 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'DropdownButtonFormField' + oneOf: + - if: "autovalidate == 'true'" + changes: + - kind: 'addParameter' + index: 0 + name: 'autovalidateMode' + style: optional_named + argumentValue: + expression: 'AutovalidateMode.always' + requiredIf: "autovalidate == 'true'" + - kind: 'removeParameter' + name: 'autovalidate' + - if: "autovalidate == 'false'" + changes: + - kind: 'addParameter' + index: 0 + name: 'autovalidateMode' + style: optional_named + argumentValue: + expression: 'AutovalidateMode.disabled' + requiredIf: "autovalidate == 'false'" + - kind: 'removeParameter' + name: 'autovalidate' + variables: + autovalidate: + kind: 'fragment' + value: 'arguments[autovalidate]' + + # Changes made in https://github.com/flutter/flutter/pull/26259 + - title: "Rename to 'resizeToAvoidBottomInset'" + date: 2020-12-23 + element: + uris: [ 'material.dart' ] + field: 'resizeToAvoidBottomPadding' + inClass: 'Scaffold' + changes: + - kind: 'rename' + newName: 'resizeToAvoidBottomInset' + + # Changes made in https://github.com/flutter/flutter/pull/26259 + - title: "Rename to 'resizeToAvoidBottomInset'" + date: 2020-12-23 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'Scaffold' + changes: + - kind: 'renameParameter' + oldName: 'resizeToAvoidBottomPadding' + newName: 'resizeToAvoidBottomInset' + + # Changes made in https://github.com/flutter/flutter/pull/68908. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'material.dart' ] + method: 'of' + inClass: 'Scaffold' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68908. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'material.dart' ] + method: 'of' + inClass: 'ScaffoldMessenger' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68905. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'material.dart' ] + method: 'resolveFrom' + inClass: 'MaterialBasedCupertinoThemeData' + changes: + - kind: 'removeParameter' + name: 'nullOk' + + # Changes made in https://github.com/flutter/flutter/pull/72043 + - title: "Migrate to 'maxLengthEnforcement'" + date: 2020-12-13 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'TextFormField' + oneOf: + - if: "maxLengthEnforced == 'true'" + changes: + - kind: 'addParameter' + index: 0 + name: 'maxLengthEnforcement' + style: optional_named + argumentValue: + expression: 'MaxLengthEnforcement.enforce' + requiredIf: "maxLengthEnforced == 'true'" + - kind: 'removeParameter' + name: 'maxLengthEnforced' + - if: "maxLengthEnforced == 'false'" + changes: + - kind: 'addParameter' + index: 0 + name: 'maxLengthEnforcement' + style: optional_named + argumentValue: + expression: 'MaxLengthEnforcement.none' + requiredIf: "maxLengthEnforced == 'false'" + - kind: 'removeParameter' + name: 'maxLengthEnforced' + variables: + maxLengthEnforced: + kind: 'fragment' + value: 'arguments[maxLengthEnforced]' + + # Changes made in https://github.com/flutter/flutter/pull/72043 + - title: "Migrate to 'maxLengthEnforcement'" + date: 2020-12-13 + element: + uris: [ 'material.dart' ] + field: 'maxLengthEnforced' + inClass: 'TextField' + changes: + - kind: 'rename' + newName: 'maxLengthEnforcement' + + # Changes made in https://github.com/flutter/flutter/pull/72043 + - title: "Migrate to 'maxLengthEnforcement'" + date: 2020-12-13 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'TextField' + oneOf: + - if: "maxLengthEnforced == 'true'" + changes: + - kind: 'addParameter' + index: 0 + name: 'maxLengthEnforcement' + style: optional_named + argumentValue: + expression: 'MaxLengthEnforcement.enforce' + requiredIf: "maxLengthEnforced == 'true'" + - kind: 'removeParameter' + name: 'maxLengthEnforced' + - if: "maxLengthEnforced == 'false'" + changes: + - kind: 'addParameter' + index: 0 + name: 'maxLengthEnforcement' + style: optional_named + argumentValue: + expression: 'MaxLengthEnforcement.none' + requiredIf: "maxLengthEnforced == 'false'" + - kind: 'removeParameter' + name: 'maxLengthEnforced' + variables: + maxLengthEnforced: + kind: 'fragment' + value: 'arguments[maxLengthEnforced]' + + # Changes made in https://github.com/flutter/flutter/pull/65246 + - title: "Remove 'disabledThumbGapWidth'" + date: 2020-11-17 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'RectangularSliderTrackShape' + changes: + - kind: 'removeParameter' + name: 'disabledThumbGapWidth' + + # Changes made in https://github.com/flutter/flutter/pull/46115 + - title: "Migrate to 'floatingLabelBehavior'" + date: 2020-01-15 + element: + uris: [ 'material.dart' ] + field: 'hasFloatingPlaceholder' + inClass: 'InputDecorationTheme' + changes: + - kind: 'rename' + newName: 'floatingLabelBehavior' + + # Changes made in https://github.com/flutter/flutter/pull/46115 + - title: "Migrate to 'floatingLabelBehavior'" + date: 2020-01-15 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'InputDecorationTheme' + oneOf: + - if: "hasFloatingPlaceholder == 'true'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% FloatingLabelBehavior %}.auto' + requiredIf: "hasFloatingPlaceholder == 'true'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + - if: "hasFloatingPlaceholder == 'false'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% FloatingLabelBehavior %}.never' + requiredIf: "hasFloatingPlaceholder == 'false'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + variables: + hasFloatingPlaceholder: + kind: 'fragment' + value: 'arguments[hasFloatingPlaceholder]' + + # Changes made in https://github.com/flutter/flutter/pull/46115 + - title: "Migrate to 'floatingLabelBehavior'" + date: 2020-01-15 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'InputDecorationTheme' + oneOf: + - if: "hasFloatingPlaceholder == 'true'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% FloatingLabelBehavior %}.auto' + requiredIf: "hasFloatingPlaceholder == 'true'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + - if: "hasFloatingPlaceholder == 'false'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% FloatingLabelBehavior %}.never' + requiredIf: "hasFloatingPlaceholder == 'false'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + variables: + hasFloatingPlaceholder: + kind: 'fragment' + value: 'arguments[hasFloatingPlaceholder]' + + # Changes made in https://github.com/flutter/flutter/pull/46115 + - title: "Migrate to 'floatingLabelBehavior'" + date: 2020-01-15 + element: + uris: [ 'material.dart' ] + field: 'hasFloatingPlaceholder' + inClass: 'InputDecoration' + changes: + - kind: 'rename' + newName: 'floatingLabelBehavior' + + # Changes made in https://github.com/flutter/flutter/pull/46115 + - title: "Rename to 'floatingLabelBehavior'" + date: 2020-01-15 + element: + uris: [ 'material.dart' ] + constructor: 'collapsed' + inClass: 'InputDecoration' + oneOf: + - if: "hasFloatingPlaceholder == 'true'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% FloatingLabelBehavior %}.auto' + requiredIf: "hasFloatingPlaceholder == 'true'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + - if: "hasFloatingPlaceholder == 'false'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% FloatingLabelBehavior %}.never' + requiredIf: "hasFloatingPlaceholder == 'false'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + variables: + hasFloatingPlaceholder: + kind: 'fragment' + value: 'arguments[hasFloatingPlaceholder]' + + # Changes made in https://github.com/flutter/flutter/pull/46115 + - title: "Rename to 'floatingLabelBehavior'" + date: 2020-01-15 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'InputDecoration' + oneOf: + - if: "hasFloatingPlaceholder == 'true'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% FloatingLabelBehavior %}.auto' + requiredIf: "hasFloatingPlaceholder == 'true'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + - if: "hasFloatingPlaceholder == 'false'" + changes: + - kind: 'addParameter' + index: 14 + name: 'floatingLabelBehavior' + style: optional_named + argumentValue: + expression: '{% FloatingLabelBehavior %}.never' + requiredIf: "hasFloatingPlaceholder == 'false'" + variables: + FloatingLabelBehavior: + kind: 'import' + uris: [ 'material.dart' ] + name: 'FloatingLabelBehavior' + - kind: 'removeParameter' + name: 'hasFloatingPlaceholder' + variables: + hasFloatingPlaceholder: + kind: 'fragment' + value: 'arguments[hasFloatingPlaceholder]' + + # Changes made in https://github.com/flutter/flutter/pull/96115 + - title: "Migrate 'Icons.pie_chart_outlined' to 'Icons.pie_chart_outline'" + date: 2022-01-04 + element: + uris: [ 'material.dart' ] + field: 'pie_chart_outlined' + inClass: 'Icons' + changes: + - kind: 'rename' + newName: 'pie_chart_outline' + + # Changes made in https://github.com/flutter/flutter/pull/96957 + - title: "Migrate to 'thumbVisibility'" + date: 2022-01-20 + element: + uris: [ 'material.dart' ] + field: 'isAlwaysShown' + inClass: 'Scrollbar' + changes: + - kind: 'rename' + newName: 'thumbVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/96957 + - title: "Migrate to 'thumbVisibility'" + date: 2022-01-20 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'Scrollbar' + changes: + - kind: 'renameParameter' + oldName: 'isAlwaysShown' + newName: 'thumbVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/96957 + - title: "Migrate to 'thumbVisibility'" + date: 2022-01-20 + element: + uris: [ 'material.dart' ] + field: 'isAlwaysShown' + inClass: 'ScrollbarThemeData' + changes: + - kind: 'rename' + newName: 'thumbVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/96957 + - title: "Migrate to 'thumbVisibility'" + date: 2022-01-20 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ScrollbarThemeData' + changes: + - kind: 'renameParameter' + oldName: 'isAlwaysShown' + newName: 'thumbVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/96957 + - title: "Migrate to 'thumbVisibility'" + date: 2022-01-20 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ScrollbarThemeData' + changes: + - kind: 'renameParameter' + oldName: 'isAlwaysShown' + newName: 'thumbVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/96174 + - title: "Migrate 'useDeleteButtonTooltip' to 'deleteButtonTooltipMessage'" + date: 2022-01-05 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'Chip' + changes: + - kind: 'addParameter' + index: 9 + name: 'deleteButtonTooltipMessage' + style: optional_named + argumentValue: + expression: "''" + requiredIf: "useDeleteButtonTooltip == 'false' && deleteButtonTooltipMessage == ''" + - kind: 'removeParameter' + name: 'useDeleteButtonTooltip' + variables: + useDeleteButtonTooltip: + kind: 'fragment' + value: 'arguments[useDeleteButtonTooltip]' + deleteButtonTooltipMessage: + kind: 'fragment' + value: 'arguments[deleteButtonTooltipMessage]' + + # Changes made in https://github.com/flutter/flutter/pull/96174 + - title: "Migrate 'useDeleteButtonTooltip' to 'deleteButtonTooltipMessage'" + date: 2022-01-05 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'InputChip' + changes: + - kind: 'addParameter' + index: 9 + name: 'deleteButtonTooltipMessage' + style: optional_named + argumentValue: + expression: "''" + requiredIf: "useDeleteButtonTooltip == 'false' && deleteButtonTooltipMessage == ''" + - kind: 'removeParameter' + name: 'useDeleteButtonTooltip' + variables: + useDeleteButtonTooltip: + kind: 'fragment' + value: 'arguments[useDeleteButtonTooltip]' + deleteButtonTooltipMessage: + kind: 'fragment' + value: 'arguments[deleteButtonTooltipMessage]' + + # Changes made in https://github.com/flutter/flutter/pull/96174 + - title: "Migrate 'useDeleteButtonTooltip' to 'deleteButtonTooltipMessage'" + date: 2022-01-05 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'RawChip' + changes: + - kind: 'addParameter' + index: 9 + name: 'deleteButtonTooltipMessage' + style: optional_named + argumentValue: + expression: "''" + requiredIf: "useDeleteButtonTooltip == 'false' && deleteButtonTooltipMessage == ''" + - kind: 'removeParameter' + name: 'useDeleteButtonTooltip' + variables: + useDeleteButtonTooltip: + kind: 'fragment' + value: 'arguments[useDeleteButtonTooltip]' + deleteButtonTooltipMessage: + kind: 'fragment' + value: 'arguments[deleteButtonTooltipMessage]' + + # Changes made in https://github.com/flutter/flutter/pull/96174 + - title: "Migrate 'useDeleteButtonTooltip' to 'deleteButtonTooltipMessage'" + date: 2022-01-05 + element: + uris: [ 'material.dart' ] + field: 'useDeleteButtonTooltip' + inClass: 'Chip' + changes: + - kind: 'rename' + newName: 'deleteButtonTooltipMessage' + + # Changes made in https://github.com/flutter/flutter/pull/96174 + - title: "Migrate 'useDeleteButtonTooltip' to 'deleteButtonTooltipMessage'" + date: 2022-01-05 + element: + uris: [ 'material.dart' ] + field: 'useDeleteButtonTooltip' + inClass: 'InputChip' + changes: + - kind: 'rename' + newName: 'deleteButtonTooltipMessage' + + # Changes made in https://github.com/flutter/flutter/pull/96174 + - title: "Migrate 'useDeleteButtonTooltip' to 'deleteButtonTooltipMessage'" + date: 2022-01-05 + element: + uris: [ 'material.dart' ] + field: 'useDeleteButtonTooltip' + inClass: 'RawChip' + changes: + - kind: 'rename' + newName: 'deleteButtonTooltipMessage' + + # Changes made in https://github.com/flutter/flutter/pull/105291 + - title: "Migrate 'ElevatedButton.styleFrom(primary)' to 'ElevatedButton.styleFrom(backgroundColor)'" + date: 2022-05-27 + element: + uris: [ 'material.dart' ] + method: 'styleFrom' + inClass: 'ElevatedButton' + changes: + - kind: 'addParameter' + index: 1 + name: 'backgroundColor' + style: optional_named + argumentValue: + expression: '{% primary %}' + requiredIf: "primary != ''" + - kind: 'removeParameter' + name: 'primary' + variables: + primary: + kind: 'fragment' + value: 'arguments[primary]' + + # Changes made in https://github.com/flutter/flutter/pull/105291 + - title: "Migrate 'ElevatedButton.styleFrom(onPrimary)' to 'ElevatedButton.styleFrom(foregroundColor)'" + date: 2022-05-27 + element: + uris: [ 'material.dart' ] + method: 'styleFrom' + inClass: 'ElevatedButton' + changes: + - kind: 'addParameter' + index: 0 + name: 'foregroundColor' + style: optional_named + argumentValue: + expression: '{% onPrimary %}' + requiredIf: "onPrimary != ''" + - kind: 'removeParameter' + name: 'onPrimary' + variables: + onPrimary: + kind: 'fragment' + value: 'arguments[onPrimary]' + + # Changes made in https://github.com/flutter/flutter/pull/105291 + - title: "Migrate 'ElevatedButton.styleFrom(onSurface)' to 'ElevatedButton.styleFrom(disabledForegroundColor)'" + date: 2022-05-27 + element: + uris: [ 'material.dart' ] + method: 'styleFrom' + inClass: 'ElevatedButton' + changes: + - kind: 'addParameter' + index: 2 + name: 'disabledForegroundColor' + style: optional_named + argumentValue: + expression: '{% onSurface %}.withOpacity(0.38)' + requiredIf: "onSurface != ''" + - kind: 'addParameter' + index: 3 + name: 'disabledBackgroundColor' + style: optional_named + argumentValue: + expression: '{% onSurface %}.withOpacity(0.12)' + requiredIf: "onSurface != ''" + - kind: 'removeParameter' + name: 'onSurface' + variables: + onSurface: + kind: 'fragment' + value: 'arguments[onSurface]' + + # Changes made in https://github.com/flutter/flutter/pull/105291 + - title: "Migrate 'OutlinedButton.styleFrom(primary)' to 'OutlinedButton.styleFrom(foregroundColor)'" + date: 2022-05-27 + element: + uris: [ 'material.dart' ] + method: 'styleFrom' + inClass: 'OutlinedButton' + changes: + - kind: 'addParameter' + index: 0 + name: 'foregroundColor' + style: optional_named + argumentValue: + expression: '{% primary %}' + requiredIf: "primary != ''" + - kind: 'removeParameter' + name: 'primary' + variables: + primary: + kind: 'fragment' + value: 'arguments[primary]' + + # Changes made in https://github.com/flutter/flutter/pull/105291 + - title: "Migrate 'OutlinedButton.styleFrom(onSurface)' to 'OutlinedButton.styleFrom(disabledForeground)'" + date: 2022-05-27 + element: + uris: [ 'material.dart' ] + method: 'styleFrom' + inClass: 'OutlinedButton' + changes: + - kind: 'addParameter' + index: 2 + name: 'disabledForegroundColor' + style: optional_named + argumentValue: + expression: '{% onSurface %}.withOpacity(0.38)' + requiredIf: "onSurface != ''" + - kind: 'removeParameter' + name: 'onSurface' + variables: + onSurface: + kind: 'fragment' + value: 'arguments[onSurface]' + + # Changes made in https://github.com/flutter/flutter/pull/105291 + - title: "Migrate 'TextButton.styleFrom(primary)' to 'TextButton.styleFrom(foregroundColor)'" + date: 2022-05-27 + element: + uris: [ 'material.dart' ] + method: 'styleFrom' + inClass: 'TextButton' + changes: + - kind: 'addParameter' + index: 0 + name: 'foregroundColor' + style: optional_named + argumentValue: + expression: '{% primary %}' + requiredIf: "primary != ''" + - kind: 'removeParameter' + name: 'primary' + variables: + primary: + kind: 'fragment' + value: 'arguments[primary]' + + # Changes made in https://github.com/flutter/flutter/pull/105291 + - title: "Migrate 'TextButton.styleFrom(onSurface)' to 'TextButton.styleFrom(disabledForeground)'" + date: 2022-05-27 + element: + uris: [ 'material.dart' ] + method: 'styleFrom' + inClass: 'TextButton' + changes: + - kind: 'addParameter' + index: 2 + name: 'disabledForegroundColor' + style: optional_named + argumentValue: + expression: '{% onSurface %}.withOpacity(0.38)' + requiredIf: "onSurface != ''" + - kind: 'removeParameter' + name: 'onSurface' + variables: + onSurface: + kind: 'fragment' + value: 'arguments[onSurface]' + + # Changes made in https://github.com/flutter/flutter/pull/78588 + - title: "Migrate to 'buildOverscrollIndicator'" + date: 2021-03-18 + element: + uris: [ 'material.dart' ] + method: 'buildViewportChrome' + inClass: 'MaterialScrollBehavior' + changes: + - kind: 'rename' + newName: 'buildOverscrollIndicator' + + # Changes made in https://github.com/flutter/flutter/pull/111706 + - title: "Migrate to 'trackVisibility'" + date: 2022-09-15 + element: + uris: [ 'material.dart' ] + field: 'showTrackOnHover' + inClass: 'Scrollbar' + changes: + - kind: 'rename' + newName: 'trackVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/111706 + - title: "Migrate to 'trackVisibility'" + date: 2022-09-15 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'Scrollbar' + changes: + - kind: 'renameParameter' + oldName: 'showTrackOnHover' + newName: 'trackVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/111706 + - title: "Migrate to 'trackVisibility'" + date: 2022-09-15 + element: + uris: [ 'material.dart' ] + field: 'showTrackOnHover' + inClass: 'ScrollbarThemeData' + changes: + - kind: 'rename' + newName: 'trackVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/111706 + - title: "Migrate to 'thumbVisibility'" + date: 2022-09-15 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ScrollbarThemeData' + changes: + - kind: 'renameParameter' + oldName: 'showTrackOnHover' + newName: 'trackVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/111706 + - title: "Migrate to 'trackVisibility'" + date: 2022-09-15 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ScrollbarThemeData' + changes: + - kind: 'renameParameter' + oldName: 'showTrackOnHover' + newName: 'trackVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/129942 + - title: "Migrate to 'Easing.legacy'" + date: 2023-07-04 + element: + uris: [ 'material.dart' ] + variable: 'standardEasing' + changes: + - kind: 'replacedBy' + newElement: + uris: [ 'material.dart' ] + field: legacy + inClass: Easing + + # Changes made in https://github.com/flutter/flutter/pull/129942 + - title: "Migrate to 'Easing.legacyAccelerate'" + date: 2023-07-04 + element: + uris: [ 'material.dart' ] + variable: 'accelerateEasing' + changes: + - kind: 'replacedBy' + newElement: + uris: [ 'material.dart' ] + field: legacyAccelerate + inClass: Easing + + # Changes made in https://github.com/flutter/flutter/pull/129942 + - title: "Migrate to 'Easing.legacyDecelerate'" + date: 2023-07-04 + element: + uris: [ 'material.dart' ] + variable: 'decelerateEasing' + changes: + - kind: 'replacedBy' + newElement: + uris: [ 'material.dart' ] + field: legacyDecelerate + inClass: Easing + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_sliver_app_bar.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_sliver_app_bar.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8aa23f6b14f004c5dac6c606c2763f02b951f29e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_sliver_app_bar.yaml @@ -0,0 +1,150 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for SliverAppBar from the Material library. * +# For fixes to +# * AppBar: fix_app_bar.yaml +# * AppBarTheme: fix_app_bar_theme.yaml +# * ColorScheme: fix_color_scheme.yaml +# * Material (general): fix_material.yaml +# * TextTheme: fix_text_theme.yaml +# * ThemeData: fix_theme_data.yaml +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'systemOverlayStyle'" + date: 2020-07-12 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'SliverAppBar' + oneOf: + - if: "brightness == 'Brightness.dark'" + changes: + - kind: 'addParameter' + index: 34 + name: 'systemOverlayStyle' + style: optional_named + argumentValue: + expression: '{% SystemUiOverlayStyle %}.light' + requiredIf: "brightness == 'Brightness.dark'" + variables: + SystemUiOverlayStyle: + kind: 'import' + uris: [ 'services.dart' ] + name: 'SystemUiOverlayStyle' + - kind: 'removeParameter' + name: 'brightness' + - if: "brightness == 'Brightness.light'" + changes: + - kind: 'addParameter' + index: 34 + name: 'systemOverlayStyle' + style: optional_named + argumentValue: + expression: '{% SystemUiOverlayStyle %}.dark' + requiredIf: "brightness == 'Brightness.light'" + variables: + SystemUiOverlayStyle: + kind: 'import' + uris: [ 'services.dart' ] + name: 'SystemUiOverlayStyle' + - kind: 'removeParameter' + name: 'brightness' + variables: + brightness: + kind: 'fragment' + value: 'arguments[brightness]' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'systemOverlayStyle'" + date: 2021-07-12 + element: + uris: [ 'material.dart' ] + field: 'brightness' + inClass: 'SliverAppBar' + changes: + - kind: 'rename' + newName: 'systemOverlayStyle' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'toolbarTextStyle' & 'titleTextStyle'" + date: 2020-07-12 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'SliverAppBar' + changes: + - kind: 'addParameter' + index: 32 + name: 'toolbarTextStyle' + style: optional_named + argumentValue: + expression: '{% textTheme %}.bodyText2' + requiredIf: "textTheme != ''" + - kind: 'addParameter' + index: 33 + name: 'titleTextStyle' + style: optional_named + argumentValue: + expression: '{% textTheme %}.headline6' + requiredIf: "textTheme != ''" + - kind: 'removeParameter' + name: 'textTheme' + variables: + textTheme: + kind: 'fragment' + value: 'arguments[textTheme]' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'toolbarTextStyle'" + date: 2021-07-12 + # TODO(Piinks): Add tests when `bulkApply:false` testing is supported, https://github.com/dart-lang/sdk/issues/44639 + bulkApply: false + element: + uris: [ 'material.dart' ] + field: 'textTheme' + inClass: 'SliverAppBar' + changes: + - kind: 'rename' + newName: 'toolbarTextStyle' + + # Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Migrate to 'titleTextStyle'" + date: 2021-07-12 + # TODO(Piinks): Add tests when `bulkApply:false` testing is supported, https://github.com/dart-lang/sdk/issues/44639 + bulkApply: false + element: + uris: [ 'material.dart' ] + field: 'textTheme' + inClass: 'SliverAppBar' + changes: + - kind: 'rename' + newName: 'titleTextStyle' + +# Changes made in https://github.com/flutter/flutter/pull/86198 + - title: "Remove 'backwardsCompatibility'" + date: 2020-07-12 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'SliverAppBar' + changes: + - kind: 'removeParameter' + name: 'backwardsCompatibility' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_text_theme.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_text_theme.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c691938d3af48ed376b600e6f0f17abd796ce9ed --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_text_theme.yaml @@ -0,0 +1,455 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for the TextTheme class from the Material library. * +# For fixes to +# * AppBar: fix_app_bar.yaml +# * AppBarTheme: fix_app_bar_theme.yaml +# * ColorScheme: fix_color_scheme.yaml +# * Material (general): fix_material.yaml +# * SliverAppBar: fix_sliver_app_bar.yaml +# * ThemeData: fix_theme_data.yaml +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: "Rename to 'headline1'" + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + getter: display4 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'headline1' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: "Rename to 'headline2'" + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + getter: display3 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'headline2' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: "Rename to 'headline3'" + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + getter: display2 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'headline3' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: "Rename to 'headline4'" + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + getter: display1 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'headline4' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: "Rename to 'headline5'" + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + getter: headline + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'headline5' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: "Rename to 'headline6'" + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + getter: title + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'headline6' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: "Rename to 'subtitle1'" + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + getter: subhead + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'subtitle1' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: "Rename to 'bodyText1'" + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + getter: body2 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'bodyText1' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: "Rename to 'bodyText2'" + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + getter: body1 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'bodyText2' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: "Rename to 'subtitle2'" + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + getter: subtitle + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'subtitle2' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: 'Rename arguments' + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'TextTheme' + changes: + - kind: 'renameParameter' + oldName: 'display4' + newName: 'headline1' + - kind: 'renameParameter' + oldName: 'display3' + newName: 'headline2' + - kind: 'renameParameter' + oldName: 'display2' + newName: 'headline3' + - kind: 'renameParameter' + oldName: 'display1' + newName: 'headline4' + - kind: 'renameParameter' + oldName: 'headline' + newName: 'headline5' + - kind: 'renameParameter' + oldName: 'title' + newName: 'headline6' + - kind: 'renameParameter' + oldName: 'subhead' + newName: 'subtitle1' + - kind: 'renameParameter' + oldName: 'subtitle' + newName: 'subtitle2' + - kind: 'renameParameter' + oldName: 'body2' + newName: 'bodyText1' + - kind: 'renameParameter' + oldName: 'body1' + newName: 'bodyText2' + + # Changes made in https://github.com/flutter/flutter/pull/48547 + - title: 'Rename arguments' + date: 2020-01-24 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'TextTheme' + changes: + - kind: 'renameParameter' + oldName: 'display4' + newName: 'headline1' + - kind: 'renameParameter' + oldName: 'display3' + newName: 'headline2' + - kind: 'renameParameter' + oldName: 'display2' + newName: 'headline3' + - kind: 'renameParameter' + oldName: 'display1' + newName: 'headline4' + - kind: 'renameParameter' + oldName: 'headline' + newName: 'headline5' + - kind: 'renameParameter' + oldName: 'title' + newName: 'headline6' + - kind: 'renameParameter' + oldName: 'subhead' + newName: 'subtitle1' + - kind: 'renameParameter' + oldName: 'subtitle' + newName: 'subtitle2' + - kind: 'renameParameter' + oldName: 'body2' + newName: 'bodyText1' + - kind: 'renameParameter' + oldName: 'body1' + newName: 'bodyText2' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'displayLarge'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: headline1 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'displayLarge' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'displayMedium'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: headline2 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'displayMedium' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'displaySmall'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: headline3 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'displaySmall' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'headlineMedium'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: headline4 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'headlineMedium' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'headlineSmall'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: headline5 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'headlineSmall' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'titleLarge'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: headline6 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'titleLarge' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'titleMedium'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: subtitle1 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'titleMedium' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'titleSmall'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: subtitle2 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'titleSmall' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'bodyLarge'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: bodyText1 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'bodyLarge' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'bodyMedium'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: bodyText2 + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'bodyMedium' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'bodySmall'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: caption + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'bodySmall' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'labelLarge'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: button + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'labelLarge' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: "Rename to 'labelSmall'" + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + getter: overline + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'labelSmall' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: 'Rename arguments' + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'TextTheme' + changes: + - kind: 'renameParameter' + oldName: 'headline1' + newName: 'displayLarge' + - kind: 'renameParameter' + oldName: 'headline2' + newName: 'displayMedium' + - kind: 'renameParameter' + oldName: 'headline3' + newName: 'displaySmall' + - kind: 'renameParameter' + oldName: 'headline4' + newName: 'headlineMedium' + - kind: 'renameParameter' + oldName: 'headline5' + newName: 'headlineSmall' + - kind: 'renameParameter' + oldName: 'headline6' + newName: 'titleLarge' + - kind: 'renameParameter' + oldName: 'subtitle1' + newName: 'titleMedium' + - kind: 'renameParameter' + oldName: 'subtitle2' + newName: 'titleSmall' + - kind: 'renameParameter' + oldName: 'bodyText1' + newName: 'bodyLarge' + - kind: 'renameParameter' + oldName: 'bodyText2' + newName: 'bodyMedium' + - kind: 'renameParameter' + oldName: 'caption' + newName: 'bodySmall' + - kind: 'renameParameter' + oldName: 'button' + newName: 'labelLarge' + - kind: 'renameParameter' + oldName: 'overline' + newName: 'labelSmall' + + # Changes made in https://github.com/flutter/flutter/pull/109817 + - title: 'Rename arguments' + date: 2022-08-18 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'TextTheme' + changes: + - kind: 'renameParameter' + oldName: 'headline1' + newName: 'displayLarge' + - kind: 'renameParameter' + oldName: 'headline2' + newName: 'displayMedium' + - kind: 'renameParameter' + oldName: 'headline3' + newName: 'displaySmall' + - kind: 'renameParameter' + oldName: 'headline4' + newName: 'headlineMedium' + - kind: 'renameParameter' + oldName: 'headline5' + newName: 'headlineSmall' + - kind: 'renameParameter' + oldName: 'headline6' + newName: 'titleLarge' + - kind: 'renameParameter' + oldName: 'subtitle1' + newName: 'titleMedium' + - kind: 'renameParameter' + oldName: 'subtitle2' + newName: 'titleSmall' + - kind: 'renameParameter' + oldName: 'bodyText1' + newName: 'bodyLarge' + - kind: 'renameParameter' + oldName: 'bodyText2' + newName: 'bodyMedium' + - kind: 'renameParameter' + oldName: 'caption' + newName: 'bodySmall' + - kind: 'renameParameter' + oldName: 'button' + newName: 'labelLarge' + - kind: 'renameParameter' + oldName: 'overline' + newName: 'labelSmall' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_theme_data.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_theme_data.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f3742f88e7b74406ead0589a0b83ad71f6c29535 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_theme_data.yaml @@ -0,0 +1,1700 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for the ThemeData class from the Material library. * +# For fixes to +# * AppBar: fix_app_bar.yaml +# * AppBarTheme: fix_app_bar_theme.yaml +# * ColorScheme: fix_color_scheme.yaml +# * Material (general): fix_material.yaml +# * SliverAppBar: fix_sliver_app_bar.yaml +# * TextTheme: fix_text_theme.yaml +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/87281 + - title: "Remove 'fixTextFieldOutlineLabel'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'fixTextFieldOutlineLabel' + + # Changes made in https://github.com/flutter/flutter/pull/87281 + - title: "Remove 'fixTextFieldOutlineLabel'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'fixTextFieldOutlineLabel' + + # Changes made in https://github.com/flutter/flutter/pull/87281 + - title: "Remove 'fixTextFieldOutlineLabel'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'fixTextFieldOutlineLabel' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'buttonColor'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'buttonColor' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'buttonColor'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'buttonColor' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'buttonColor'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'buttonColor' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'accentIconTheme'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'accentIconTheme' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'accentIconTheme'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'accentIconTheme' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'accentIconTheme'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'accentIconTheme' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'accentTextTheme'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'accentTextTheme' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'accentTextTheme'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'accentTextTheme' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'accentTextTheme'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'accentTextTheme' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'accentColorBrightness'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'accentColorBrightness' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'accentColorBrightness'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'accentColorBrightness' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Remove 'accentColorBrightness'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'accentColorBrightness' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Migrate to 'ColorScheme.secondary'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + field: 'accentColor' + inClass: 'ThemeData' + changes: + - kind: 'rename' + newName: 'colorScheme.secondary' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Migrate to 'ColorScheme.secondary'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + oneOf: + - if: "accentColor != '' && primarySwatch == '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch().copyWith(secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch == '' && colorScheme ==''" + - kind: 'removeParameter' + name: 'accentColor' + - if: "accentColor != '' && primarySwatch != '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch(primarySwatch: {% primarySwatch %}).copyWith(secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch != '' && colorScheme == ''" + - kind: 'removeParameter' + name: 'accentColor' + - kind: 'removeParameter' + name: 'primarySwatch' + - if: "accentColor != '' && primarySwatch == '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch == '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'accentColor' + - if: "accentColor != '' && primarySwatch != '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(primarySwatch: {% primarySwatch %}, secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch != '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'accentColor' + - kind: 'removeParameter' + name: 'primarySwatch' + variables: + accentColor: + kind: 'fragment' + value: 'arguments[accentColor]' + primarySwatch: + kind: 'fragment' + value: 'arguments[primarySwatch]' + colorScheme: + kind: 'fragment' + value: 'arguments[colorScheme]' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Migrate to 'ColorScheme.secondary'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + oneOf: + - if: "accentColor != '' && primarySwatch == '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch().copyWith(secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch == '' && colorScheme ==''" + - kind: 'removeParameter' + name: 'accentColor' + - if: "accentColor != '' && primarySwatch != '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch(primarySwatch: {% primarySwatch %}).copyWith(secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch != '' && colorScheme == ''" + - kind: 'removeParameter' + name: 'accentColor' + - kind: 'removeParameter' + name: 'primarySwatch' + - if: "accentColor != '' && primarySwatch == '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch == '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'accentColor' + - if: "accentColor != '' && primarySwatch != '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(primarySwatch: {% primarySwatch %}, secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch != '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'accentColor' + - kind: 'removeParameter' + name: 'primarySwatch' + variables: + accentColor: + kind: 'fragment' + value: 'arguments[accentColor]' + primarySwatch: + kind: 'fragment' + value: 'arguments[primarySwatch]' + colorScheme: + kind: 'fragment' + value: 'arguments[colorScheme]' + + # Changes made in https://github.com/flutter/flutter/pull/81336 + - title: "Migrate to 'ColorScheme.secondary'" + date: 2021-04-30 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + oneOf: + - if: "accentColor != '' && primarySwatch == '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch().copyWith(secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch == '' && colorScheme ==''" + - kind: 'removeParameter' + name: 'accentColor' + - if: "accentColor != '' && primarySwatch != '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch(primarySwatch: {% primarySwatch %}).copyWith(secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch != '' && colorScheme == ''" + - kind: 'removeParameter' + name: 'accentColor' + - kind: 'removeParameter' + name: 'primarySwatch' + - if: "accentColor != '' && primarySwatch == '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch == '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'accentColor' + - if: "accentColor != '' && primarySwatch != '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(primarySwatch: {% primarySwatch %}, secondary: {% accentColor %})' + requiredIf: "accentColor != '' && primarySwatch != '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'accentColor' + - kind: 'removeParameter' + name: 'primarySwatch' + variables: + accentColor: + kind: 'fragment' + value: 'arguments[accentColor]' + primarySwatch: + kind: 'fragment' + value: 'arguments[primarySwatch]' + colorScheme: + kind: 'fragment' + value: 'arguments[colorScheme]' + + # Changes made in https://github.com/flutter/flutter/pull/93396 + - title: "Remove 'primaryColorBrightness'" + date: 2021-11-11 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'primaryColorBrightness' + + # Changes made in https://github.com/flutter/flutter/pull/93396 + - title: "Remove 'primaryColorBrightness'" + date: 2021-11-11 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'primaryColorBrightness' + + # Changes made in https://github.com/flutter/flutter/pull/93396 + - title: "Remove 'primaryColorBrightness'" + date: 2021-11-11 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'primaryColorBrightness' + + # Changes made in https://github.com/flutter/flutter/pull/66482 + - title: "Migrate to 'TextSelectionThemeData'" + date: 2020-09-24 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + oneOf: + - if: "textSelectionColor != '' && cursorColor != '' && textSelectionHandleColor != ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(cursorColor: {% cursorColor %}, selectionColor: {% textSelectionColor %}, selectionHandleColor: {% textSelectionHandleColor %},)' + requiredIf: "textSelectionColor != '' && cursorColor != '' && textSelectionHandleColor != ''" + - kind: 'removeParameter' + name: 'textSelectionColor' + - kind: 'removeParameter' + name: 'cursorColor' + - kind: 'removeParameter' + name: 'textSelectionHandleColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor == '' && cursorColor != '' && textSelectionHandleColor != ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(cursorColor: {% cursorColor %}, selectionHandleColor: {% textSelectionHandleColor %},)' + requiredIf: "textSelectionColor == '' && cursorColor != '' && textSelectionHandleColor != ''" + - kind: 'removeParameter' + name: 'cursorColor' + - kind: 'removeParameter' + name: 'textSelectionHandleColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor != '' && cursorColor != '' && textSelectionHandleColor == ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(cursorColor: {% cursorColor %}, selectionColor: {% textSelectionColor %},)' + requiredIf: "textSelectionColor != '' && cursorColor != '' && textSelectionHandleColor == ''" + - kind: 'removeParameter' + name: 'textSelectionColor' + - kind: 'removeParameter' + name: 'cursorColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor != '' && cursorColor == '' && textSelectionHandleColor != ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(selectionColor: {% textSelectionColor %}, selectionHandleColor: {% textSelectionHandleColor %},)' + requiredIf: "textSelectionColor != '' && cursorColor == '' && textSelectionHandleColor != ''" + - kind: 'removeParameter' + name: 'textSelectionColor' + - kind: 'removeParameter' + name: 'textSelectionHandleColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor == '' && cursorColor != '' && textSelectionHandleColor == ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(cursorColor: {% cursorColor %})' + requiredIf: "textSelectionColor == '' && cursorColor != '' && textSelectionHandleColor == ''" + - kind: 'removeParameter' + name: 'cursorColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor != '' && cursorColor == '' && textSelectionHandleColor == ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(selectionColor: {% textSelectionColor %})' + requiredIf: "textSelectionColor != '' && cursorColor == '' && textSelectionHandleColor == ''" + - kind: 'removeParameter' + name: 'textSelectionColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor == '' && cursorColor == '' && textSelectionHandleColor != ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(selectionHandleColor: {% textSelectionHandleColor %})' + requiredIf: "textSelectionColor == '' && cursorColor == '' && textSelectionHandleColor != ''" + - kind: 'removeParameter' + name: 'textSelectionHandleColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "useTextSelectionTheme != ''" + changes: + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + variables: + textSelectionColor: + kind: 'fragment' + value: 'arguments[textSelectionColor]' + cursorColor: + kind: 'fragment' + value: 'arguments[cursorColor]' + textSelectionHandleColor: + kind: 'fragment' + value: 'arguments[textSelectionHandleColor]' + useTextSelectionTheme: + kind: 'fragment' + value: 'arguments[useTextSelectionTheme]' + + # Changes made in https://github.com/flutter/flutter/pull/66482 + - title: "Migrate to 'TextSelectionThemeData'" + date: 2020-09-24 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + oneOf: + - if: "textSelectionColor != '' && cursorColor != '' && textSelectionHandleColor != ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(cursorColor: {% cursorColor %}, selectionColor: {% textSelectionColor %}, selectionHandleColor: {% textSelectionHandleColor %},)' + requiredIf: "textSelectionColor != '' && cursorColor != '' && textSelectionHandleColor != ''" + - kind: 'removeParameter' + name: 'textSelectionColor' + - kind: 'removeParameter' + name: 'cursorColor' + - kind: 'removeParameter' + name: 'textSelectionHandleColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor == '' && cursorColor != '' && textSelectionHandleColor != ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(cursorColor: {% cursorColor %}, selectionHandleColor: {% textSelectionHandleColor %},)' + requiredIf: "textSelectionColor == '' && cursorColor != '' && textSelectionHandleColor != ''" + - kind: 'removeParameter' + name: 'cursorColor' + - kind: 'removeParameter' + name: 'textSelectionHandleColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor != '' && cursorColor != '' && textSelectionHandleColor == ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(cursorColor: {% cursorColor %}, selectionColor: {% textSelectionColor %},)' + requiredIf: "textSelectionColor != '' && cursorColor != '' && textSelectionHandleColor == ''" + - kind: 'removeParameter' + name: 'textSelectionColor' + - kind: 'removeParameter' + name: 'cursorColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor != '' && cursorColor == '' && textSelectionHandleColor != ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(selectionColor: {% textSelectionColor %}, selectionHandleColor: {% textSelectionHandleColor %},)' + requiredIf: "textSelectionColor != '' && cursorColor == '' && textSelectionHandleColor != ''" + - kind: 'removeParameter' + name: 'textSelectionColor' + - kind: 'removeParameter' + name: 'textSelectionHandleColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor == '' && cursorColor != '' && textSelectionHandleColor == ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(cursorColor: {% cursorColor %})' + requiredIf: "textSelectionColor == '' && cursorColor != '' && textSelectionHandleColor == ''" + - kind: 'removeParameter' + name: 'cursorColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor != '' && cursorColor == '' && textSelectionHandleColor == ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(selectionColor: {% textSelectionColor %})' + requiredIf: "textSelectionColor != '' && cursorColor == '' && textSelectionHandleColor == ''" + - kind: 'removeParameter' + name: 'textSelectionColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "textSelectionColor == '' && cursorColor == '' && textSelectionHandleColor != ''" + changes: + - kind: 'addParameter' + index: 73 + name: 'textSelectionTheme' + style: optional_named + argumentValue: + expression: 'TextSelectionThemeData(selectionHandleColor: {% textSelectionHandleColor %})' + requiredIf: "textSelectionColor == '' && cursorColor == '' && textSelectionHandleColor != ''" + - kind: 'removeParameter' + name: 'textSelectionHandleColor' + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + - if: "useTextSelectionTheme != ''" + changes: + - kind: 'removeParameter' + name: 'useTextSelectionTheme' + variables: + textSelectionColor: + kind: 'fragment' + value: 'arguments[textSelectionColor]' + cursorColor: + kind: 'fragment' + value: 'arguments[cursorColor]' + textSelectionHandleColor: + kind: 'fragment' + value: 'arguments[textSelectionHandleColor]' + useTextSelectionTheme: + kind: 'fragment' + value: 'arguments[useTextSelectionTheme]' + + # Changes made in https://github.com/flutter/flutter/pull/109070 + - title: "Remove 'selectedRowColor'" + date: 2022-08-05 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'selectedRowColor' + + # Changes made in https://github.com/flutter/flutter/pull/109070 + - title: "Remove 'selectedRowColor'" + date: 2022-08-05 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'selectedRowColor' + + # Changes made in https://github.com/flutter/flutter/pull/109070 + - title: "Remove 'selectedRowColor'" + date: 2022-08-05 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'selectedRowColor' + + # Changes made in https://github.com/flutter/flutter/pull/97972/ + - title: "Migrate 'ThemeData.toggleableActiveColor' to individual themes" + date: 2022-05-18 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'toggleableActiveColor' + - kind: 'addParameter' + index: 96 + name: 'checkboxTheme' + style: optional_named + argumentValue: + expression: "CheckboxThemeData(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && checkboxTheme == ''" + - kind: 'addParameter' + index: 97 + name: 'checkboxTheme' + style: optional_named + argumentValue: + expression: "{% checkboxTheme %}.copyWith(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && checkboxTheme != ''" + - kind: 'addParameter' + index: 98 + name: 'radioTheme' + style: optional_named + argumentValue: + expression: "RadioThemeData(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && radioTheme == ''" + - kind: 'addParameter' + index: 99 + name: 'radioTheme' + style: optional_named + argumentValue: + expression: "{% radioTheme %}.copyWith(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && radioTheme != ''" + - kind: 'addParameter' + index: 100 + name: 'switchTheme' + style: optional_named + argumentValue: + expression: "SwitchThemeData(\n + thumbColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + trackColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && switchTheme == ''" + - kind: 'addParameter' + index: 101 + name: 'switchTheme' + style: optional_named + argumentValue: + expression: "{% switchTheme %}.copyWith(\n + thumbColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + trackColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && switchTheme != ''" + variables: + checkboxTheme: + kind: 'fragment' + value: 'arguments[checkboxTheme]' + radioTheme: + kind: 'fragment' + value: 'arguments[radioTheme]' + switchTheme: + kind: 'fragment' + value: 'arguments[switchTheme]' + toggleableActiveColor: + kind: 'fragment' + value: 'arguments[toggleableActiveColor]' + + # Changes made in https://github.com/flutter/flutter/pull/97972/ + - title: "Migrate 'ThemeData.raw.toggleableActiveColor' to individual themes" + date: 2022-05-18 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'toggleableActiveColor' + - kind: 'addParameter' + index: 96 + name: 'checkboxTheme' + style: optional_named + argumentValue: + expression: "CheckboxThemeData(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && checkboxTheme == ''" + - kind: 'addParameter' + index: 97 + name: 'checkboxTheme' + style: optional_named + argumentValue: + expression: "{% checkboxTheme %}.copyWith(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && checkboxTheme != ''" + - kind: 'addParameter' + index: 98 + name: 'radioTheme' + style: optional_named + argumentValue: + expression: "RadioThemeData(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && radioTheme == ''" + - kind: 'addParameter' + index: 99 + name: 'radioTheme' + style: optional_named + argumentValue: + expression: "{% radioTheme %}.copyWith(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && radioTheme != ''" + - kind: 'addParameter' + index: 100 + name: 'switchTheme' + style: optional_named + argumentValue: + expression: "SwitchThemeData(\n + thumbColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + trackColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && switchTheme == ''" + - kind: 'addParameter' + index: 101 + name: 'switchTheme' + style: optional_named + argumentValue: + expression: "{% switchTheme %}.copyWith(\n + thumbColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + trackColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && switchTheme != ''" + variables: + checkboxTheme: + kind: 'fragment' + value: 'arguments[checkboxTheme]' + radioTheme: + kind: 'fragment' + value: 'arguments[radioTheme]' + switchTheme: + kind: 'fragment' + value: 'arguments[switchTheme]' + toggleableActiveColor: + kind: 'fragment' + value: 'arguments[toggleableActiveColor]' + + # Changes made in https://github.com/flutter/flutter/pull/97972/ + - title: "Migrate 'ThemeData.copyWith.toggleableActiveColor' to individual themes" + date: 2022-05-18 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'toggleableActiveColor' + - kind: 'addParameter' + index: 96 + name: 'checkboxTheme' + style: optional_named + argumentValue: + expression: "CheckboxThemeData(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && checkboxTheme == ''" + - kind: 'addParameter' + index: 97 + name: 'checkboxTheme' + style: optional_named + argumentValue: + expression: "{% checkboxTheme %}.copyWith(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && checkboxTheme != ''" + - kind: 'addParameter' + index: 98 + name: 'radioTheme' + style: optional_named + argumentValue: + expression: "RadioThemeData(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && radioTheme == ''" + - kind: 'addParameter' + index: 99 + name: 'radioTheme' + style: optional_named + argumentValue: + expression: "{% radioTheme %}.copyWith(\n + fillColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && radioTheme != ''" + - kind: 'addParameter' + index: 100 + name: 'switchTheme' + style: optional_named + argumentValue: + expression: "SwitchThemeData(\n + thumbColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + trackColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && switchTheme == ''" + - kind: 'addParameter' + index: 101 + name: 'switchTheme' + style: optional_named + argumentValue: + expression: "{% switchTheme %}.copyWith(\n + thumbColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + trackColor: MaterialStateProperty.resolveWith((Set states) {\n + if (states.contains(MaterialState.disabled)) { + return null; + }\n + if (states.contains(MaterialState.selected)) { + return {% toggleableActiveColor %}; + }\n + return null;\n + }),\n + )" + requiredIf: "toggleableActiveColor != '' && switchTheme != ''" + variables: + checkboxTheme: + kind: 'fragment' + value: 'arguments[checkboxTheme]' + radioTheme: + kind: 'fragment' + value: 'arguments[radioTheme]' + switchTheme: + kind: 'fragment' + value: 'arguments[switchTheme]' + toggleableActiveColor: + kind: 'fragment' + value: 'arguments[toggleableActiveColor]' + + # Changes made in https://github.com/flutter/flutter/pull/111080 + - title: "Migrate to 'BottomAppBarTheme.color'" + date: 2022-09-07 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + oneOf: + - if: "bottomAppBarColor != ''" + changes: + - kind: 'removeParameter' + name: 'bottomAppBarColor' + - kind: 'addParameter' + index: 73 + name: 'bottomAppBarTheme' + style: optional_named + argumentValue: + expression: 'BottomAppBarTheme(color: {% bottomAppBarColor %})' + requiredIf: "bottomAppBarColor != ''" + variables: + bottomAppBarColor: + kind: 'fragment' + value: 'arguments[bottomAppBarColor]' + + # Changes made in https://github.com/flutter/flutter/pull/111080 + - title: "Migrate to 'BottomAppBarTheme.color'" + date: 2022-09-07 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + oneOf: + - if: "bottomAppBarColor != ''" + changes: + - kind: 'removeParameter' + name: 'bottomAppBarColor' + - kind: 'addParameter' + index: 73 + name: 'bottomAppBarTheme' + style: optional_named + argumentValue: + expression: 'BottomAppBarTheme(color: {% bottomAppBarColor %})' + requiredIf: "bottomAppBarColor != ''" + variables: + bottomAppBarColor: + kind: 'fragment' + value: 'arguments[bottomAppBarColor]' + + # Changes made in https://github.com/flutter/flutter/pull/111080 + - title: "Migrate to 'BottomAppBarTheme.color'" + date: 2022-09-06 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + oneOf: + - if: "bottomAppBarColor != ''" + changes: + - kind: 'removeParameter' + name: 'bottomAppBarColor' + - kind: 'addParameter' + index: 73 + name: 'bottomAppBarTheme' + style: optional_named + argumentValue: + expression: 'BottomAppBarTheme(color: {% bottomAppBarColor %})' + requiredIf: "bottomAppBarColor != ''" + variables: + bottomAppBarColor: + kind: 'fragment' + value: 'arguments[bottomAppBarColor]' + + # Changes made in https://github.com/flutter/flutter/pull/110162 + - title: "Migrate to 'ColorScheme.background'" + date: 2022-08-24 + element: + uris: [ 'material.dart' ] + field: 'backgroundColor' + inClass: 'ThemeData' + changes: + - kind: 'rename' + newName: 'colorScheme.background' + + # Changes made in https://github.com/flutter/flutter/pull/110162 + - title: "Migrate to 'ColorScheme.background'" + date: 2022-08-24 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + oneOf: + - if: "backgroundColor != '' && primarySwatch == '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme(background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch == '' && colorScheme ==''" + - kind: 'removeParameter' + name: 'backgroundColor' + - if: "backgroundColor != '' && primarySwatch != '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch(primarySwatch: {% primarySwatch %}).copyWith(background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch != '' && colorScheme == ''" + - kind: 'removeParameter' + name: 'backgroundColor' + - kind: 'removeParameter' + name: 'primarySwatch' + - if: "backgroundColor != '' && primarySwatch == '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch == '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'backgroundColor' + - if: "backgroundColor != '' && primarySwatch != '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(primarySwatch: {% primarySwatch %}, background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch != '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'backgroundColor' + - kind: 'removeParameter' + name: 'primarySwatch' + variables: + backgroundColor: + kind: 'fragment' + value: 'arguments[backgroundColor]' + primarySwatch: + kind: 'fragment' + value: 'arguments[primarySwatch]' + colorScheme: + kind: 'fragment' + value: 'arguments[colorScheme]' + + # Changes made in https://github.com/flutter/flutter/pull/110162 + - title: "Migrate to 'ColorScheme.background'" + date: 2022-08-24 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + oneOf: + - if: "backgroundColor != '' && primarySwatch == '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme(background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch == '' && colorScheme ==''" + - kind: 'removeParameter' + name: 'backgroundColor' + - if: "backgroundColor != '' && primarySwatch != '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch(primarySwatch: {% primarySwatch %}).copyWith(background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch != '' && colorScheme == ''" + - kind: 'removeParameter' + name: 'backgroundColor' + - kind: 'removeParameter' + name: 'primarySwatch' + - if: "backgroundColor != '' && primarySwatch == '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch == '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'backgroundColor' + - if: "backgroundColor != '' && primarySwatch != '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(primarySwatch: {% primarySwatch %}, background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch != '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'backgroundColor' + - kind: 'removeParameter' + name: 'primarySwatch' + variables: + backgroundColor: + kind: 'fragment' + value: 'arguments[backgroundColor]' + primarySwatch: + kind: 'fragment' + value: 'arguments[primarySwatch]' + colorScheme: + kind: 'fragment' + value: 'arguments[colorScheme]' + + # Changes made in https://github.com/flutter/flutter/pull/110162 + - title: "Migrate to 'ColorScheme.background'" + date: 2022-08-24 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + oneOf: + - if: "backgroundColor != '' && primarySwatch == '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme(background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch == '' && colorScheme == ''" + - kind: 'removeParameter' + name: 'backgroundColor' + - if: "backgroundColor != '' && primarySwatch != '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch(primarySwatch: {% primarySwatch %}).copyWith(background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch != '' && colorScheme == ''" + - kind: 'removeParameter' + name: 'backgroundColor' + - kind: 'removeParameter' + name: 'primarySwatch' + - if: "backgroundColor != '' && primarySwatch == '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch == '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'backgroundColor' + - if: "backgroundColor != '' && primarySwatch != '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(primarySwatch: {% primarySwatch %}, background: {% backgroundColor %})' + requiredIf: "backgroundColor != '' && primarySwatch != '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'backgroundColor' + - kind: 'removeParameter' + name: 'primarySwatch' + variables: + backgroundColor: + kind: 'fragment' + value: 'arguments[backgroundColor]' + primarySwatch: + kind: 'fragment' + value: 'arguments[primarySwatch]' + colorScheme: + kind: 'fragment' + value: 'arguments[colorScheme]' + + # Changes made in https://github.com/flutter/flutter/pull/110162 + - title: "Migrate to 'ColorScheme.error'" + date: 2022-08-24 + element: + uris: [ 'material.dart' ] + field: 'errorColor' + inClass: 'ThemeData' + changes: + - kind: 'rename' + newName: 'colorScheme.error' + + # Changes made in https://github.com/flutter/flutter/pull/110162 + - title: "Migrate to 'ColorScheme.error'" + date: 2022-08-24 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + oneOf: + - if: "errorColor != '' && primarySwatch == '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme(error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch == '' && colorScheme ==''" + - kind: 'removeParameter' + name: 'errorColor' + - if: "errorColor != '' && primarySwatch != '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch(primarySwatch: {% primarySwatch %}).copyWith(error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch != '' && colorScheme == ''" + - kind: 'removeParameter' + name: 'errorColor' + - kind: 'removeParameter' + name: 'primarySwatch' + - if: "errorColor != '' && primarySwatch == '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch == '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'errorColor' + - if: "errorColor != '' && primarySwatch != '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(primarySwatch: {% primarySwatch %}, error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch != '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'errorColor' + - kind: 'removeParameter' + name: 'primarySwatch' + variables: + errorColor: + kind: 'fragment' + value: 'arguments[errorColor]' + primarySwatch: + kind: 'fragment' + value: 'arguments[primarySwatch]' + colorScheme: + kind: 'fragment' + value: 'arguments[colorScheme]' + + # Changes made in https://github.com/flutter/flutter/pull/110162 + - title: "Migrate to 'ColorScheme.error'" + date: 2022-08-24 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + oneOf: + - if: "errorColor != '' && primarySwatch == '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme(error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch == '' && colorScheme ==''" + - kind: 'removeParameter' + name: 'errorColor' + - if: "errorColor != '' && primarySwatch != '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch(primarySwatch: {% primarySwatch %}).copyWith(error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch != '' && colorScheme == ''" + - kind: 'removeParameter' + name: 'errorColor' + - kind: 'removeParameter' + name: 'primarySwatch' + - if: "errorColor != '' && primarySwatch == '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch == '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'errorColor' + - if: "errorColor != '' && primarySwatch != '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(primarySwatch: {% primarySwatch %}, error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch != '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'errorColor' + - kind: 'removeParameter' + name: 'primarySwatch' + variables: + errorColor: + kind: 'fragment' + value: 'arguments[errorColor]' + primarySwatch: + kind: 'fragment' + value: 'arguments[primarySwatch]' + colorScheme: + kind: 'fragment' + value: 'arguments[colorScheme]' + + # Changes made in https://github.com/flutter/flutter/pull/110162 + - title: "Migrate to 'ColorScheme.error'" + date: 2022-08-24 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + oneOf: + - if: "errorColor != '' && primarySwatch == '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme(error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch == '' && colorScheme ==''" + - kind: 'removeParameter' + name: 'errorColor' + - if: "errorColor != '' && primarySwatch != '' && colorScheme == ''" + changes: + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: 'ColorScheme.fromSwatch(primarySwatch: {% primarySwatch %}).copyWith(error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch != '' && colorScheme == ''" + - kind: 'removeParameter' + name: 'errorColor' + - kind: 'removeParameter' + name: 'primarySwatch' + - if: "errorColor != '' && primarySwatch == '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch == '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'errorColor' + - if: "errorColor != '' && primarySwatch != '' && colorScheme != ''" + changes: + - kind: 'removeParameter' + name: 'colorScheme' # Remove to add back with modification + - kind: 'addParameter' + index: 56 + name: 'colorScheme' + style: optional_named + argumentValue: + expression: '{% colorScheme %}.copyWith(primarySwatch: {% primarySwatch %}, error: {% errorColor %})' + requiredIf: "errorColor != '' && primarySwatch != '' && colorScheme != ''" + - kind: 'removeParameter' + name: 'errorColor' + - kind: 'removeParameter' + name: 'primarySwatch' + variables: + errorColor: + kind: 'fragment' + value: 'arguments[errorColor]' + primarySwatch: + kind: 'fragment' + value: 'arguments[primarySwatch]' + colorScheme: + kind: 'fragment' + value: 'arguments[colorScheme]' + + # Changes made in https://github.com/flutter/flutter/pull/131455 + - title: "Remove 'useMaterial3'" + date: 2023-07-27 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'useMaterial3' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_widget_state.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_widget_state.yaml new file mode 100644 index 0000000000000000000000000000000000000000..65343238b6b03ce782c65a08f70d259c92e4944e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_material/fix_widget_state.yaml @@ -0,0 +1,129 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/to/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for the MaterialState enum and classes from the Material library. * +# For fixes to +# * AppBar: fix_app_bar.yaml +# * AppBarTheme: fix_app_bar_theme.yaml +# * ColorScheme: fix_color_scheme.yaml +# * Material (general): fix_material.yaml +# * SliverAppBar: fix_sliver_app_bar.yaml +# * TextTheme: fix_text_theme.yaml +# * ThemeDate: fix_theme_data.yaml +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/142151 + - title: "Replace with 'WidgetState'" + date: 2024-02-01 + element: + uris: [ 'material.dart', 'widgets.dart' ] + enum: 'MaterialState' + changes: + - kind: 'rename' + newName: 'WidgetState' + + # Changes made in https://github.com/flutter/flutter/pull/142151 + - title: "Replace with 'WidgetPropertyResolver'" + date: 2024-02-01 + element: + uris: [ 'material.dart', 'widgets.dart' ] + typedef: 'MaterialPropertyResolver' + changes: + - kind: 'rename' + newName: 'WidgetPropertyResolver' + + # Changes made in https://github.com/flutter/flutter/pull/142151 + - title: "Replace with 'WidgetStateColor'" + date: 2024-02-01 + element: + uris: [ 'material.dart', 'widgets.dart' ] + class: 'MaterialStateColor' + changes: + - kind: 'rename' + newName: 'WidgetStateColor' + + # Changes made in https://github.com/flutter/flutter/pull/142151 + - title: "Replace with 'WidgetStateMouseCursor'" + date: 2024-02-01 + element: + uris: [ 'material.dart', 'widgets.dart' ] + class: 'MaterialStateMouseCursor' + changes: + - kind: 'rename' + newName: 'WidgetStateMouseCursor' + + # Changes made in https://github.com/flutter/flutter/pull/142151 + - title: "Replace with 'WidgetStateBorderSide'" + date: 2024-02-01 + element: + uris: [ 'material.dart', 'widgets.dart' ] + class: 'MaterialStateBorderSide' + changes: + - kind: 'rename' + newName: 'WidgetStateBorderSide' + + # Changes made in https://github.com/flutter/flutter/pull/142151 + - title: "Replace with 'WidgetStateOutlinedBorder'" + date: 2024-02-01 + element: + uris: [ 'material.dart', 'widgets.dart' ] + class: 'MaterialStateOutlinedBorder' + changes: + - kind: 'rename' + newName: 'WidgetStateOutlinedBorder' + + # Changes made in https://github.com/flutter/flutter/pull/142151 + - title: "Replace with 'WidgetStateTextStyle'" + date: 2024-02-01 + element: + uris: [ 'material.dart', 'widgets.dart' ] + class: 'MaterialStateTextStyle' + changes: + - kind: 'rename' + newName: 'WidgetStateTextStyle' + + # Changes made in https://github.com/flutter/flutter/pull/142151 + - title: "Replace with 'WidgetStateProperty'" + date: 2024-02-01 + element: + uris: [ 'material.dart', 'widgets.dart' ] + class: 'MaterialStateProperty' + changes: + - kind: 'rename' + newName: 'WidgetStateProperty' + + # Changes made in https://github.com/flutter/flutter/pull/142151 + - title: "Replace with 'WidgetStatePropertyAll'" + date: 2024-02-01 + element: + uris: [ 'material.dart', 'widgets.dart' ] + class: 'MaterialStatePropertyAll' + changes: + - kind: 'rename' + newName: 'WidgetStatePropertyAll' + + # Changes made in https://github.com/flutter/flutter/pull/142151 + - title: "Replace with 'WidgetStatesController'" + date: 2024-02-01 + element: + uris: [ 'material.dart', 'widgets.dart' ] + class: 'MaterialStatesController' + changes: + - kind: 'rename' + newName: 'WidgetStatesController' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_painting.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_painting.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b83d86f28ce9c1214a408bd7c57db7a8ec49e30d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_painting.yaml @@ -0,0 +1,120 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are from the Painting library. * +version: 1 +transforms: + # Change made in https://github.com/flutter/flutter/pull/128522 + - title: "Migrate to 'textScaler'" + date: 2023-06-09 + element: + uris: [ 'painting.dart' ] + method: 'computeMaxIntrinsicWidth' + inClass: 'TextPainter' + changes: + - kind: 'addParameter' + index: 4 + name: 'textScaler' + style: optional_named + argumentValue: + expression: 'TextScaler.linear({% textScaleFactor %})' + requiredIf: "textScaleFactor != ''" + - kind: 'removeParameter' + name: 'textScaleFactor' + variables: + textScaleFactor: + kind: 'fragment' + value: 'arguments[textScaleFactor]' + + # Change made in https://github.com/flutter/flutter/pull/128522 + - title: "Migrate to 'textScaler'" + date: 2023-06-09 + element: + uris: [ 'painting.dart' ] + method: 'computeWidth' + inClass: 'TextPainter' + changes: + - kind: 'addParameter' + index: 4 + name: 'textScaler' + style: optional_named + argumentValue: + expression: 'TextScaler.linear({% textScaleFactor %})' + requiredIf: "textScaleFactor != ''" + - kind: 'removeParameter' + name: 'textScaleFactor' + variables: + textScaleFactor: + kind: 'fragment' + value: 'arguments[textScaleFactor]' + + # Change made in https://github.com/flutter/flutter/pull/128522 + - title: "Migrate to 'textScaler'" + date: 2023-06-09 + element: + uris: [ 'painting.dart' ] + constructor: '' + inClass: 'TextPainter' + changes: + - kind: 'addParameter' + index: 0 + name: 'textScaler' + style: optional_named + argumentValue: + expression: 'TextScaler.linear({% textScaleFactor %})' + requiredIf: "textScaleFactor != ''" + - kind: 'removeParameter' + name: 'textScaleFactor' + variables: + textScaleFactor: + kind: 'fragment' + value: 'arguments[textScaleFactor]' + + # Change made in https://github.com/flutter/flutter/pull/128522 + - title: "Migrate to 'textScaler'" + date: 2023-06-09 + element: + uris: [ 'painting.dart' ] + method: 'getTextStyle' + inClass: 'TextStyle' + changes: + - kind: 'addParameter' + index: 0 + name: 'textScaler' + style: optional_named + argumentValue: + expression: 'TextScaler.linear({% textScaleFactor %})' + requiredIf: "textScaleFactor != ''" + - kind: 'removeParameter' + name: 'textScaleFactor' + variables: + textScaleFactor: + kind: 'fragment' + value: 'arguments[textScaleFactor]' + + # Changes made in https://github.com/flutter/flutter/pull/121152 + - title: "Rename to 'fromViewPadding'" + date: 2022-02-21 + element: + uris: [ 'painting.dart' ] + constructor: 'fromWindowPadding' + inClass: 'EdgeInsets' + changes: + - kind: 'rename' + newName: 'fromViewPadding' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_rendering.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_rendering.yaml new file mode 100644 index 0000000000000000000000000000000000000000..75ae29fc5615d72ebf160b91955db6ae2afeb85b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_rendering.yaml @@ -0,0 +1,157 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are from the Rendering library. * +version: 1 +transforms: + # Change made in https://github.com/flutter/flutter/pull/128522 + - title: "Migrate to 'textScaler'" + date: 2023-06-09 + element: + uris: [ 'rendering.dart' ] + constructor: '' + inClass: 'RenderParagraph' + changes: + - kind: 'addParameter' + index: 5 + name: 'textScaler' + style: optional_named + argumentValue: + expression: 'TextScaler.linear({% textScaleFactor %})' + requiredIf: "textScaleFactor != ''" + - kind: 'removeParameter' + name: 'textScaleFactor' + variables: + textScaleFactor: + kind: 'fragment' + value: 'arguments[textScaleFactor]' + + # Change made in https://github.com/flutter/flutter/pull/128522 + - title: "Migrate to 'textScaler'" + date: 2023-06-09 + element: + uris: [ 'rendering.dart' ] + constructor: '' + inClass: 'RenderEditable' + changes: + - kind: 'addParameter' + index: 15 + name: 'textScaler' + style: optional_named + argumentValue: + expression: 'TextScaler.linear({% textScaleFactor %})' + requiredIf: "textScaleFactor != ''" + - kind: 'removeParameter' + name: 'textScaleFactor' + variables: + textScaleFactor: + kind: 'fragment' + value: 'arguments[textScaleFactor]' + + # Changes made in https://github.com/flutter/flutter/pull/66305 + - title: "Migrate to 'clipBehavior'" + date: 2020-09-22 + element: + uris: [ 'rendering.dart' ] + field: 'overflow' + inClass: 'RenderStack' + changes: + - kind: 'rename' + newName: 'clipBehavior' + + # Changes made in https://github.com/flutter/flutter/pull/66305 + - title: "Migrate to 'clipBehavior'" + date: 2020-09-22 + element: + uris: [ 'rendering.dart' ] + constructor: '' + inClass: 'RenderStack' + oneOf: + - if: "overflow == 'Overflow.clip'" + changes: + - kind: 'addParameter' + index: 0 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.hardEdge' + requiredIf: "overflow == 'Overflow.clip'" + - kind: 'removeParameter' + name: 'overflow' + - if: "overflow == 'Overflow.visible'" + changes: + - kind: 'addParameter' + index: 0 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.none' + requiredIf: "overflow == 'Overflow.visible'" + - kind: 'removeParameter' + name: 'overflow' + variables: + overflow: + kind: 'fragment' + value: 'arguments[overflow]' + + # Changes made in https://flutter.dev/docs/release/breaking-changes/clip-behavior + - title: "Migrate to 'clipBehavior'" + date: 2020-08-20 + element: + uris: [ 'rendering.dart' ] + field: 'clipToSize' + inClass: 'RenderListWheelViewport' + changes: + - kind: 'rename' + newName: 'clipBehavior' + + # Changes made in https://flutter.dev/docs/release/breaking-changes/clip-behavior + - title: "Migrate to 'clipBehavior'" + date: 2020-08-20 + element: + uris: [ 'rendering.dart' ] + constructor: '' + inClass: 'RenderListWheelViewport' + oneOf: + - if: "clipToSize == 'true'" + changes: + - kind: 'addParameter' + index: 13 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.hardEdge' + requiredIf: "clipToSize == 'true'" + - kind: 'removeParameter' + name: 'clipToSize' + - if: "clipToSize == 'false'" + changes: + - kind: 'addParameter' + index: 13 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.none' + requiredIf: "clipToSize == 'false'" + - kind: 'removeParameter' + name: 'clipToSize' + variables: + clipToSize: + kind: 'fragment' + value: 'arguments[clipToSize]' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_services.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_services.yaml new file mode 100644 index 0000000000000000000000000000000000000000..35c8a238d191f2c540c804346eab0ce6c6d5cbb4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_services.yaml @@ -0,0 +1,87 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are from the Services library. * +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/122446 + - title: "Migrate to empty 'text' string" + date: 2023-06-26 + element: + uris: [ 'services.dart' ] + constructor: '' + inClass: 'ClipboardData' + changes: + - kind: 'changeParameterType' + name: 'text' + nullability: 'non_null' + argumentValue: + expression: "''" + + # Changes made in https://github.com/flutter/flutter/pull/60320 + - title: "Migrate to 'viewId'" + date: 2020-07-05 + element: + uris: [ 'services.dart' ] + getter: id + inClass: 'TextureAndroidViewController' + changes: + - kind: 'rename' + newName: 'viewId' + + # Changes made in https://github.com/flutter/flutter/pull/60320 + - title: "Migrate to 'viewId'" + date: 2020-07-05 + element: + uris: [ 'services.dart' ] + getter: id + inClass: 'SurfaceAndroidViewController' + changes: + - kind: 'rename' + newName: 'viewId' + + # Changes made in https://github.com/flutter/flutter/pull/81303 + - title: "Migrate to 'setEnabledSystemUIMode'" + date: 2021-06-08 + element: + uris: [ 'services.dart' ] + method: 'setEnabledSystemUIOverlays' + inClass: 'SystemChrome' + changes: + - kind: 'rename' + newName: 'setEnabledSystemUIMode' + - kind: 'removeParameter' + index: 0 + - kind: 'addParameter' + index: 0 + name: 'mode' + style: required_positional + argumentValue: + expression: 'SystemUiMode.manual' + - kind: 'addParameter' + index: 1 + name: 'overlays' + style: optional_named + argumentValue: + expression: '{% overlays %}' + requiredIf: "overlays != ''" + variables: + overlays: + kind: 'fragment' + value: 'arguments[0]' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_template.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a11962a57d1a53b01ece2cfcf0b7268e60bdd1aa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_template.yaml @@ -0,0 +1,24 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are [for CLASS] from the library. * + +# Uncomment version & transforms, and follow with fixes. +# version: 1 +# transforms: + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_actions.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_actions.yaml new file mode 100644 index 0000000000000000000000000000000000000000..56cf1dc8a848c58e565ce3b1de88dc842ddeb867 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_actions.yaml @@ -0,0 +1,83 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for Actions from the Widgets library. * +# For fixes to +# * BuildContext: fix_build_context.yaml +# * Element: fix_element.yaml +# * ListWheelScrollView: fix_list_wheel_scroll_view.yaml +# * Widgets (general): fix_widgets.yaml +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/68921. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'invoke' + inClass: 'Actions' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeInvoke' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68921. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'find' + inClass: 'Actions' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeFind' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68921. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'handler' + inClass: 'Actions' + changes: + - kind: 'removeParameter' + name: 'nullOk' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_build_context.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_build_context.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4fd4db33a6840dba5d02c0c5fe21385a47c42f82 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_build_context.yaml @@ -0,0 +1,169 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for BuildContext from the Widgets library. * +# For fixes to +# * Actions: fix_actions.yaml +# * Element: fix_element.yaml +# * ListWheelScrollView: fix_list_wheel_scroll_view.yaml +# * Widgets (general): fix_widgets.yaml +version: 1 +transforms: + # Change made in https://github.com/flutter/flutter/pull/44189. + - title: "Rename to 'dependOnInheritedElement'" + date: 2019-11-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + inClass: 'BuildContext' + method: 'inheritFromElement' + changes: + - kind: 'rename' + newName: 'dependOnInheritedElement' + + # Change made in https://github.com/flutter/flutter/pull/44189. + - title: "Migrate to 'dependOnInheritedWidgetOfExactType'" + date: 2019-11-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + inClass: 'BuildContext' + method: 'inheritFromWidgetOfExactType' + changes: + - kind: 'rename' + newName: 'dependOnInheritedWidgetOfExactType' + - kind: 'removeParameter' + index: 0 + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: fragment + value: 'arguments[0]' + + # Change made in https://github.com/flutter/flutter/pull/44189. + - title: "Migrate to 'getElementForInheritedWidgetOfExactType'" + date: 2019-11-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + inClass: 'BuildContext' + method: 'ancestorInheritedElementForWidgetOfExactType' + changes: + - kind: 'rename' + newName: 'getElementForInheritedWidgetOfExactType' + - kind: 'removeParameter' + index: 0 + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: fragment + value: 'arguments[0]' + + # Change made in https://github.com/flutter/flutter/pull/44189. + - title: "Migrate to 'findAncestorWidgetOfExactType'" + date: 2019-11-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + inClass: 'BuildContext' + method: 'ancestorWidgetOfExactType' + changes: + - kind: 'rename' + newName: 'findAncestorWidgetOfExactType' + - kind: 'removeParameter' + index: 0 + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: fragment + value: 'arguments[0]' + + # Change made in https://github.com/flutter/flutter/pull/44189. + - title: "Migrate to 'findAncestorStateOfType'" + date: 2019-11-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + inClass: 'BuildContext' + method: 'ancestorStateOfType' + changes: + - kind: 'rename' + newName: 'findAncestorStateOfType' + - kind: 'removeParameter' + index: 0 + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: fragment + value: 'arguments[0].typeArguments[0]' + + # Change made in https://github.com/flutter/flutter/pull/44189. + - title: "Migrate to 'rootAncestorStateOfType'" + date: 2019-11-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + inClass: 'BuildContext' + method: 'rootAncestorStateOfType' + changes: + - kind: 'rename' + newName: 'findRootAncestorStateOfType' + - kind: 'removeParameter' + index: 0 + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: fragment + value: 'arguments[0].typeArguments[0]' + + # Change made in https://github.com/flutter/flutter/pull/44189. + - title: "Migrate to 'ancestorRenderObjectOfType'" + date: 2019-11-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + inClass: 'BuildContext' + method: 'ancestorRenderObjectOfType' + changes: + - kind: 'rename' + newName: 'findAncestorRenderObjectOfType' + - kind: 'removeParameter' + index: 0 + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: fragment + value: 'arguments[0].typeArguments[0]' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_drag_target.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_drag_target.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ab10142a8b843fb2fbd087ed1d1af8d0b58d6d2f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_drag_target.yaml @@ -0,0 +1,46 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for DragTarget from the Widgets library. * +version: 1 +transforms: + + # Changes made in https://github.com/flutter/flutter/pull/133691 + - title: "Migrate 'onWillAccept' to 'onWillAcceptWithDetails'" + date: 2023-08-30 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'DragTarget' + changes: + - kind: 'renameParameter' + oldName: 'onWillAccept' + newName: 'onWillAcceptWithDetails' + + # Changes made in https://github.com/flutter/flutter/pull/133691 + - title: "Migrate 'onAccept' to 'onAcceptWithDetails'" + date: 2023-08-30 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'DragTarget' + changes: + - kind: 'renameParameter' + oldName: 'onAccept' + newName: 'onAcceptWithDetails' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_element.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_element.yaml new file mode 100644 index 0000000000000000000000000000000000000000..bf615802b61e51c6edc4f920a6a82c3f5e0734e1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_element.yaml @@ -0,0 +1,169 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for Element from the Widgets library. * +# For fixes to +# * Actions: fix_actions.yaml +# * BuildContext: fix_build_context.yaml +# * ListWheelScrollView: fix_list_wheel_scroll_view.yaml +# * Widgets (general): fix_widgets.yaml +version: 1 +transforms: + # Changes made in https://github.com/flutter/flutter/pull/44189. + - title: "Rename to 'dependOnInheritedElement'" + date: 2020-12-23 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'inheritFromElement' + inClass: 'Element' + changes: + - kind: 'rename' + newName: 'dependOnInheritedElement' + + # Changes made in https://github.com/flutter/flutter/pull/44189. + - title: "Rename to 'dependOnInheritedWidgetOfExactType'" + date: 2020-09-14 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'inheritFromWidgetOfExactType' + inClass: 'Element' + changes: + - kind: 'rename' + newName: 'dependOnInheritedWidgetOfExactType' + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: 'fragment' + value: 'arguments[0]' + - kind: 'removeParameter' + index: 0 + + # Changes made in https://github.com/flutter/flutter/pull/44189. + - title: "Rename to 'getElementForInheritedWidgetOfExactType'" + date: 2020-09-14 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'ancestorInheritedElementForWidgetOfExactType' + inClass: 'Element' + changes: + - kind: 'rename' + newName: 'getElementForInheritedWidgetOfExactType' + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: 'fragment' + value: 'arguments[0]' + - kind: 'removeParameter' + index: 0 + + # Changes made in https://github.com/flutter/flutter/pull/44189. + - title: "Rename to 'getElementForInheritedWidgetOfExactType'" + date: 2020-12-23 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'ancestorWidgetOfExactType' + inClass: 'Element' + changes: + - kind: 'rename' + newName: 'findAncestorWidgetOfExactType' + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: 'fragment' + value: 'arguments[0]' + - kind: 'removeParameter' + index: 0 + + # Changes made in https://github.com/flutter/flutter/pull/44189. + - title: "Rename to 'findAncestorStateOfType'" + date: 2020-12-23 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'ancestorStateOfType' + inClass: 'Element' + changes: + - kind: 'rename' + newName: 'findAncestorStateOfType' + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: 'fragment' + value: 'arguments[0].typeArguments[0]' + - kind: 'removeParameter' + index: 0 + + # Changes made in https://github.com/flutter/flutter/pull/44189. + - title: "Rename to 'findAncestorRenderObjectOfType'" + date: 2020-12-23 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'ancestorRenderObjectOfType' + inClass: 'Element' + changes: + - kind: 'rename' + newName: 'findAncestorRenderObjectOfType' + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: 'fragment' + value: 'arguments[0].typeArguments[0]' + - kind: 'removeParameter' + index: 0 + + # Changes made in https://github.com/flutter/flutter/pull/44189. + - title: "Rename to 'findAncestorRenderObjectOfType'" + date: 2020-12-23 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'rootAncestorStateOfType' + inClass: 'Element' + changes: + - kind: 'rename' + newName: 'findRootAncestorStateOfType' + - kind: 'addTypeParameter' + index: 0 + name: 'T' + argumentValue: + expression: '{% type %}' + variables: + type: + kind: 'fragment' + value: 'arguments[0].typeArguments[0]' + - kind: 'removeParameter' + index: 0 + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_interactive_viewer.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_interactive_viewer.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7ed5e3f103b7cda99cee2fad853104c19b9ebece --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_interactive_viewer.yaml @@ -0,0 +1,105 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/to/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for InteractiveViewer from the widgets library. * +version: 1 +transforms: + # Change made in https://github.com/flutter/flutter/pull/109014 + - title: "Migrate to 'panAxis'" + date: 2024-02-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'InteractiveViewer' + variables: + alignPanAxis: + kind: 'fragment' + value: 'arguments[alignPanAxis]' + panAxis: + kind: 'fragment' + value: 'arguments[panAxis]' + oneOf: + - if: "panAxis == '' && alignPanAxis == 'true'" + changes: + - kind: 'addParameter' + index: 0 + name: 'panAxis' + style: optional_named + argumentValue: + expression: 'PanAxis.aligned' + requiredIf: "alignPanAxis == 'true'" + - kind: 'removeParameter' + name: 'alignPanAxis' + - if: "panAxis == '' && alignPanAxis == 'false'" + changes: + - kind: 'addParameter' + index: 0 + name: 'panAxis' + style: optional_named + argumentValue: + expression: 'PanAxis.free' + requiredIf: "alignPanAxis == 'false'" + - kind: 'removeParameter' + name: 'alignPanAxis' + - if: "alignPanAxis != ''" + changes: + - kind: 'removeParameter' + name: 'alignPanAxis' + + # Change made in https://github.com/flutter/flutter/pull/109014 + - title: "Migrate to 'panAxis'" + date: 2024-02-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: 'builder' + inClass: 'InteractiveViewer' + variables: + alignPanAxis: + kind: 'fragment' + value: 'arguments[alignPanAxis]' + panAxis: + kind: 'fragment' + value: 'arguments[panAxis]' + oneOf: + - if: "panAxis == '' && alignPanAxis == 'true'" + changes: + - kind: 'addParameter' + index: 0 + name: 'panAxis' + style: optional_named + argumentValue: + expression: 'PanAxis.aligned' + requiredIf: "alignPanAxis == 'true'" + - kind: 'removeParameter' + name: 'alignPanAxis' + - if: "panAxis == '' && alignPanAxis == 'false'" + changes: + - kind: 'addParameter' + index: 0 + name: 'panAxis' + style: optional_named + argumentValue: + expression: 'PanAxis.free' + requiredIf: "alignPanAxis == 'false'" + - kind: 'removeParameter' + name: 'alignPanAxis' + - if: "alignPanAxis != ''" + changes: + - kind: 'removeParameter' + name: 'alignPanAxis' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_list_wheel_scroll_view.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_list_wheel_scroll_view.yaml new file mode 100644 index 0000000000000000000000000000000000000000..426d503fa23b11d79417da21b55522c0c8896fdb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_list_wheel_scroll_view.yaml @@ -0,0 +1,107 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for ListWheelScrollView from the Widgets library. * +# For fixes to +# * Actions: fix_actions.yaml +# * BuildContext: fix_build_context.yaml +# * Element: fix_element.yaml +# * Widgets (general): fix_widgets.yaml +version: 1 +transforms: + # Changes made in https://flutter.dev/docs/release/breaking-changes/clip-behavior + - title: "Migrate to 'clipBehavior'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: 'useDelegate' + inClass: 'ListWheelScrollView' + oneOf: + - if: "clipToSize == 'true'" + changes: + - kind: 'addParameter' + index: 13 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.hardEdge' + requiredIf: "clipToSize == 'true'" + - kind: 'removeParameter' + name: 'clipToSize' + - if: "clipToSize == 'false'" + changes: + - kind: 'addParameter' + index: 13 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.none' + requiredIf: "clipToSize == 'false'" + - kind: 'removeParameter' + name: 'clipToSize' + variables: + clipToSize: + kind: 'fragment' + value: 'arguments[clipToSize]' + + # Changes made in https://flutter.dev/docs/release/breaking-changes/clip-behavior + - title: "Migrate to 'clipBehavior'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'clipToSize' + inClass: 'ListWheelScrollView' + changes: + - kind: 'rename' + newName: 'clipBehavior' + + # Changes made in https://flutter.dev/docs/release/breaking-changes/clip-behavior + - title: "Migrate to 'clipBehavior'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'ListWheelScrollView' + oneOf: + - if: "clipToSize == 'true'" + changes: + - kind: 'addParameter' + index: 13 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.hardEdge' + requiredIf: "clipToSize == 'true'" + - kind: 'removeParameter' + name: 'clipToSize' + - if: "clipToSize == 'false'" + changes: + - kind: 'addParameter' + index: 13 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.none' + requiredIf: "clipToSize == 'false'" + - kind: 'removeParameter' + name: 'clipToSize' + variables: + clipToSize: + kind: 'fragment' + value: 'arguments[clipToSize]' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_media_query.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_media_query.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c7092e9311b4533994db6aa71d1c4f1e13b47fd5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_media_query.yaml @@ -0,0 +1,65 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for MediaQuery and MediaQueryData from the widgets library. * +version: 1 +transforms: + # Change made in https://github.com/flutter/flutter/pull/128522 + - title: "Migrate to 'textScaler'" + date: 2023-06-09 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'copyWith' + inClass: 'MediaQueryData' + changes: + - kind: 'addParameter' + index: 3 + name: 'textScaler' + style: optional_named + argumentValue: + expression: 'TextScaler.linear({% textScaleFactor %})' + requiredIf: "textScaleFactor != ''" + - kind: 'removeParameter' + name: 'textScaleFactor' + variables: + textScaleFactor: + kind: 'fragment' + value: 'arguments[textScaleFactor]' + + # Change made in https://github.com/flutter/flutter/pull/128522 + - title: "Migrate to 'textScaler'" + date: 2023-06-09 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'MediaQueryData' + changes: + - kind: 'addParameter' + index: 3 + name: 'textScaler' + style: optional_named + argumentValue: + expression: 'TextScaler.linear({% textScaleFactor %})' + requiredIf: "textScaleFactor != ''" + - kind: 'removeParameter' + name: 'textScaleFactor' + variables: + textScaleFactor: + kind: 'fragment' + value: 'arguments[textScaleFactor]' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_rich_text.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_rich_text.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1f3f5cc0148375b0bc15636faa7a5bfd1e90f052 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_rich_text.yaml @@ -0,0 +1,43 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are for RichText from the widgets library. * +version: 1 +transforms: + # Change made in https://github.com/flutter/flutter/pull/128522 + - title: "Migrate to 'textScaler'" + date: 2023-06-09 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'RichText' + changes: + - kind: 'addParameter' + index: 7 + name: 'textScaler' + style: optional_named + argumentValue: + expression: 'TextScaler.linear({% textScaleFactor %})' + requiredIf: "textScaleFactor != ''" + - kind: 'removeParameter' + name: 'textScaleFactor' + variables: + textScaleFactor: + kind: 'fragment' + value: 'arguments[textScaleFactor]' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_widgets.yaml b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_widgets.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c1421376123a64dc707a8d22737a4493936b60d9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/fix_data/fix_widgets/fix_widgets.yaml @@ -0,0 +1,944 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the flutter/packages/flutter/test_fixes/README.md +# file for instructions on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are from the Widgets library. * +# For fixes to +# * Actions: fix_actions.yaml +# * BuildContext: fix_build_context.yaml +# * Element: fix_element.yaml +# * ListWheelScrollView: fix_list_wheel_scroll_view.yaml +version: 1 +transforms: + # Changes made in TBD + - title: "Migrate to focusNode.enclosingScope!" + date: 2023-11-29 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + getter: 'focusScopeNode' + inClass: 'NavigatorState' + changes: + - kind: 'rename' + newName: 'focusNode.enclosingScope!' + + # Changes made in https://github.com/flutter/flutter/pull/138509 + - title: "Migrate to 'PlatformMenuBar.child'" + date: 2023-11-15 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'body' + inClass: 'PlatformMenuBar' + changes: + - kind: 'rename' + newName: 'child' + - title: "Migrate PlatformMenuBar(body:) to PlatformMenuBar(child:)" + date: 2023-11-15 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'PlatformMenuBar' + changes: + - kind: 'renameParameter' + oldName: 'body' + newName: 'child' + + # Changes made in https://github.com/flutter/flutter/pull/123352 + - title: "Migrate to 'rootElement'" + date: 2023-03-13 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'renderViewElement' + inClass: 'WidgetsBinding' + changes: + - kind: 'rename' + newName: 'rootElement' + + # Changes made in https://github.com/flutter/flutter/pull/122555 + - title: "Migrate to 'decorationClipBehavior'" + date: 2023-03-13 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'clipBehavior' + inClass: 'ScrollableDetails' + changes: + - kind: 'rename' + newName: 'decorationClipBehavior' + + # Changes made in https://github.com/flutter/flutter/pull/122555 + - title: "Migrate to 'decorationClipBehavior'" + date: 2023-03-13 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'ScrollableDetails' + changes: + - kind: 'renameParameter' + oldName: 'clipBehavior' + newName: 'decorationClipBehavior' + + # Changes made in https://github.com/flutter/flutter/pull/119647 + - title: "Migrate to 'fromView'" + date: 2022-10-28 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: 'fromWindow' + inClass: 'MediaQueryData' + changes: + - kind: 'rename' + newName: 'fromView' + + # Changes made in https://github.com/flutter/flutter/pull/119186 and https://github.com/flutter/flutter/pull/81067 + - title: "Remove 'vsync'" + date: 2023-01-30 + element: + uris: ['widgets.dart', 'material.dart', 'cupertino.dart'] + constructor: '' + inClass: 'AnimatedSize' + changes: + - kind: 'removeParameter' + name: 'vsync' + + # Changes made in https://github.com/flutter/flutter/pull/114459 + - title: "Migrate to 'boldTextOf'" + date: 2022-10-28 + element: + uris: ['widgets.dart', 'material.dart', 'cupertino.dart'] + method: 'boldTextOverride' + inClass: 'MediaQuery' + changes: + - kind: 'rename' + newName: 'boldTextOf' + + # Changes made in https://github.com/flutter/flutter/pull/87839 + - title: "Migrate to 'disallowIndicator'" + date: 2021-08-06 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'disallowGlow' + inClass: 'OverscrollIndicatorNotification' + changes: + - kind: 'rename' + newName: 'disallowIndicator' + + # Changes made in https://github.com/flutter/flutter/pull/66305 + - title: "Migrate to 'clipBehavior'" + date: 2020-09-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'overflow' + inClass: 'Stack' + changes: + - kind: 'rename' + newName: 'clipBehavior' + + # Changes made in https://github.com/flutter/flutter/pull/66305 + - title: "Migrate to 'clipBehavior'" + date: 2020-09-22 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'Stack' + oneOf: + - if: "overflow == 'Overflow.clip'" + changes: + - kind: 'addParameter' + index: 0 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.hardEdge' + requiredIf: "overflow == 'Overflow.clip'" + - kind: 'removeParameter' + name: 'overflow' + - if: "overflow == 'Overflow.visible'" + changes: + - kind: 'addParameter' + index: 0 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.none' + requiredIf: "overflow == 'Overflow.visible'" + - kind: 'removeParameter' + name: 'overflow' + variables: + overflow: + kind: 'fragment' + value: 'arguments[overflow]' + + # Changes made in https://github.com/flutter/flutter/pull/45941 + - title: "Rename to 'deferFirstFrame'" + date: 2020-12-23 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'deferFirstFrameReport' + inClass: 'WidgetsBinding' + changes: + - kind: 'rename' + newName: 'deferFirstFrame' + + # Changes made in https://github.com/flutter/flutter/pull/45941 + - title: "Rename to 'allowFirstFrame'" + date: 2020-12-23 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'allowFirstFrameReport' + inClass: 'WidgetsBinding' + changes: + - kind: 'rename' + newName: 'allowFirstFrame' + + # Changes made in https://github.com/flutter/flutter/pull/44189 + - title: "Rename to 'dependOnInheritedElement'" + date: 2020-12-23 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'inheritFromElement' + inClass: 'StatefulElement' + changes: + - kind: 'rename' + newName: 'dependOnInheritedElement' + + # Changes made in https://github.com/flutter/flutter/pull/61648 + - title: "Migrate to 'autovalidateMode'" + date: 2020-09-02 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'autovalidate' + inClass: 'Form' + changes: + - kind: 'rename' + newName: 'autovalidateMode' + + # Changes made in https://github.com/flutter/flutter/pull/61648 + - title: "Migrate to 'autovalidateMode'" + date: 2020-09-02 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'Form' + oneOf: + - if: "autovalidate == 'true'" + changes: + - kind: 'addParameter' + index: 0 + name: 'autovalidateMode' + style: optional_named + argumentValue: + expression: 'AutovalidateMode.always' + requiredIf: "autovalidate == 'true'" + - kind: 'removeParameter' + name: 'autovalidate' + - if: "autovalidate == 'false'" + changes: + - kind: 'addParameter' + index: 0 + name: 'autovalidateMode' + style: optional_named + argumentValue: + expression: 'AutovalidateMode.disabled' + requiredIf: "autovalidate == 'false'" + - kind: 'removeParameter' + name: 'autovalidate' + variables: + autovalidate: + kind: 'fragment' + value: 'arguments[autovalidate]' + + # Changes made in https://github.com/flutter/flutter/pull/61648 + - title: "Migrate to 'autovalidateMode'" + date: 2020-09-02 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'autovalidate' + inClass: 'FormField' + changes: + - kind: 'rename' + newName: 'autovalidateMode' + + # Changes made in https://github.com/flutter/flutter/pull/61648 + - title: "Migrate to 'autovalidateMode'" + date: 2020-09-02 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'FormField' + oneOf: + - if: "autovalidate == 'true'" + changes: + - kind: 'addParameter' + index: 0 + name: 'autovalidateMode' + style: optional_named + argumentValue: + expression: 'AutovalidateMode.always' + requiredIf: "autovalidate == 'true'" + - kind: 'removeParameter' + name: 'autovalidate' + - if: "autovalidate == 'false'" + changes: + - kind: 'addParameter' + index: 0 + name: 'autovalidateMode' + style: optional_named + argumentValue: + expression: 'AutovalidateMode.disabled' + requiredIf: "autovalidate == 'false'" + - kind: 'removeParameter' + name: 'autovalidate' + variables: + autovalidate: + kind: 'fragment' + value: 'arguments[autovalidate]' + + # Changes made in https://github.com/flutter/flutter/pull/70726. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'of' + inClass: 'Navigator' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68736. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'of' + inClass: 'MediaQuery' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68925. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'of' + inClass: 'SliverAnimatedList' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68925. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'of' + inClass: 'AnimatedList' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68921. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'of' + inClass: 'Shortcuts' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68917. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'of' + inClass: 'Focus' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68917. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'of' + inClass: 'FocusTraversalGroup' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68917. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'of' + inClass: 'FocusTraversalOrder' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68911. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'localeOf' + inClass: 'Localizations' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeLocaleOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/68910. + - title: "Migrate from 'nullOk'" + date: 2021-01-27 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'of' + inClass: 'Router' + oneOf: + - if: "nullOk == 'true'" + changes: + - kind: 'rename' + newName: 'maybeOf' + - kind: 'removeParameter' + name: 'nullOk' + - if: "nullOk == 'false'" + changes: + - kind: 'removeParameter' + name: 'nullOk' + variables: + nullOk: + kind: 'fragment' + value: 'arguments[nullOk]' + + # Changes made in https://github.com/flutter/flutter/pull/59127 + - title: "Migrate to 'label'" + date: 2020-07-09 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'title' + inClass: 'BottomNavigationBarItem' + changes: + - kind: 'rename' + newName: 'label' + + # Changes made in https://github.com/flutter/flutter/pull/59127 + - title: "Migrate to 'label'" + date: 2020-07-09 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'BottomNavigationBarItem' + changes: + - kind: 'renameParameter' + oldName: 'title' + newName: 'label' + + # Changes made in https://github.com/flutter/flutter/pull/79160 + - title: "Migrate to 'dragAnchorStrategy'" + date: 2021-04-05 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'dragAnchor' + inClass: 'Draggable' + changes: + - kind: 'rename' + newName: 'dragAnchorStrategy' + + # Changes made in https://github.com/flutter/flutter/pull/79160 + - title: "Migrate to 'dragAnchorStrategy'" + date: 2021-04-05 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'Draggable' + oneOf: + - if: "dragAnchor == 'DragAnchor.child'" + changes: + - kind: 'addParameter' + index: 9 + name: 'dragAnchorStrategy' + style: optional_named + argumentValue: + expression: 'childDragAnchorStrategy' + requiredIf: "dragAnchor == 'DragAnchor.child'" + - kind: 'removeParameter' + name: 'dragAnchor' + - if: "dragAnchor == 'DragAnchor.pointer'" + changes: + - kind: 'addParameter' + index: 9 + name: 'dragAnchorStrategy' + style: optional_named + argumentValue: + expression: 'pointerDragAnchorStrategy' + requiredIf: "dragAnchor == 'DragAnchor.pointer'" + - kind: 'removeParameter' + name: 'dragAnchor' + variables: + dragAnchor: + kind: 'fragment' + value: 'arguments[dragAnchor]' + + # Changes made in https://github.com/flutter/flutter/pull/79160 + - title: "Migrate to 'dragAnchorStrategy'" + date: 2021-04-05 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'dragAnchor' + inClass: 'LongPressDraggable' + changes: + - kind: 'rename' + newName: 'dragAnchorStrategy' + + # Changes made in https://github.com/flutter/flutter/pull/79160 + - title: "Migrate to 'dragAnchorStrategy'" + date: 2021-04-05 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'LongPressDraggable' + oneOf: + - if: "dragAnchor == 'DragAnchor.child'" + changes: + - kind: 'addParameter' + index: 9 + name: 'dragAnchorStrategy' + style: optional_named + argumentValue: + expression: 'childDragAnchorStrategy' + requiredIf: "dragAnchor == 'DragAnchor.child'" + - kind: 'removeParameter' + name: 'dragAnchor' + - if: "dragAnchor == 'DragAnchor.pointer'" + changes: + - kind: 'addParameter' + index: 9 + name: 'dragAnchorStrategy' + style: optional_named + argumentValue: + expression: 'pointerDragAnchorStrategy' + requiredIf: "dragAnchor == 'DragAnchor.pointer'" + - kind: 'removeParameter' + name: 'dragAnchor' + variables: + dragAnchor: + kind: 'fragment' + value: 'arguments[dragAnchor]' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'removeRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'removeChildRenderObject' + inClass: 'RenderObjectToWidgetElement' + changes: + - kind: 'rename' + newName: 'removeRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'moveRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'moveChildRenderObject' + inClass: 'RenderObjectToWidgetElement' + changes: + - kind: 'rename' + newName: 'moveRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'insertRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'insertChildRenderObject' + inClass: 'RenderObjectToWidgetElement' + changes: + - kind: 'rename' + newName: 'insertRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'removeRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'removeChildRenderObject' + inClass: 'SliverMultiBoxAdaptorElement' + changes: + - kind: 'rename' + newName: 'removeRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'moveRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'moveChildRenderObject' + inClass: 'SliverMultiBoxAdaptorElement' + changes: + - kind: 'rename' + newName: 'moveRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'insertRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'insertChildRenderObject' + inClass: 'SliverMultiBoxAdaptorElement' + changes: + - kind: 'rename' + newName: 'insertRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'removeRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'removeChildRenderObject' + inClass: 'SingleChildRenderObjectElement' + changes: + - kind: 'rename' + newName: 'removeRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'moveRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'moveChildRenderObject' + inClass: 'SingleChildRenderObjectElement' + changes: + - kind: 'rename' + newName: 'moveRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'insertRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'insertChildRenderObject' + inClass: 'SingleChildRenderObjectElement' + changes: + - kind: 'rename' + newName: 'insertRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'removeRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'removeChildRenderObject' + inClass: 'MultiChildRenderObjectElement' + changes: + - kind: 'rename' + newName: 'removeRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'moveRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'moveChildRenderObject' + inClass: 'MultiChildRenderObjectElement' + changes: + - kind: 'rename' + newName: 'moveRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'insertRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'insertChildRenderObject' + inClass: 'MultiChildRenderObjectElement' + changes: + - kind: 'rename' + newName: 'insertRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'removeRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'removeChildRenderObject' + inClass: 'ListWheelElement' + changes: + - kind: 'rename' + newName: 'removeRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'moveRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'moveChildRenderObject' + inClass: 'ListWheelElement' + changes: + - kind: 'rename' + newName: 'moveRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'insertRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'insertChildRenderObject' + inClass: 'ListWheelElement' + changes: + - kind: 'rename' + newName: 'insertRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'removeRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'removeChildRenderObject' + inClass: 'LeafRenderObjectElement' + changes: + - kind: 'rename' + newName: 'removeRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'moveRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'moveChildRenderObject' + inClass: 'LeafRenderObjectElement' + changes: + - kind: 'rename' + newName: 'moveRenderObjectChild' + + # Changes made in https://github.com/flutter/flutter/pull/64254 + - title: "Migrate to 'insertRenderObjectChild'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'insertChildRenderObject' + inClass: 'LeafRenderObjectElement' + changes: + - kind: 'rename' + newName: 'insertRenderObjectChild' + + # Changes made in https://flutter.dev/docs/release/breaking-changes/clip-behavior + - title: "Migrate to 'clipBehavior'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'clipToSize' + inClass: 'ListWheelViewport' + changes: + - kind: 'rename' + newName: 'clipBehavior' + + # Changes made in https://flutter.dev/docs/release/breaking-changes/clip-behavior + - title: "Migrate to 'clipBehavior'" + date: 2020-08-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'ListWheelViewport' + oneOf: + - if: "clipToSize == 'true'" + changes: + - kind: 'addParameter' + index: 13 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.hardEdge' + requiredIf: "clipToSize == 'true'" + - kind: 'removeParameter' + name: 'clipToSize' + - if: "clipToSize == 'false'" + changes: + - kind: 'addParameter' + index: 13 + name: 'clipBehavior' + style: optional_named + argumentValue: + expression: 'Clip.none' + requiredIf: "clipToSize == 'false'" + - kind: 'removeParameter' + name: 'clipToSize' + variables: + clipToSize: + kind: 'fragment' + value: 'arguments[clipToSize]' + + # Changes made in https://github.com/flutter/flutter/pull/96957 + - title: "Migrate to 'thumbVisibility'" + date: 2022-01-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'isAlwaysShown' + inClass: 'RawScrollbar' + changes: + - kind: 'rename' + newName: 'thumbVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/96957 + - title: "Migrate to 'thumbVisibility'" + date: 2022-01-20 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + constructor: '' + inClass: 'RawScrollbar' + changes: + - kind: 'renameParameter' + oldName: 'isAlwaysShown' + newName: 'thumbVisibility' + + # Changes made in https://github.com/flutter/flutter/pull/100381 + - title: "Migrate 'TextSelectionOverlay.fadeDuration' to SelectionOverlay.fadeDuration" + date: 2022-03-18 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'fadeDuration' + inClass: 'TextSelectionOverlay' + changes: + - kind: 'replacedBy' + newElement: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + field: 'fadeDuration' + inClass: 'SelectionOverlay' + + # Changes made in https://github.com/flutter/flutter/pull/78588 + - title: "Migrate to 'buildOverscrollIndicator'" + date: 2021-03-18 + element: + uris: [ 'widgets.dart', 'material.dart', 'cupertino.dart' ] + method: 'buildViewportChrome' + inClass: 'ScrollBehavior' + changes: + - kind: 'rename' + newName: 'buildOverscrollIndicator' + +# Before adding a new fix: read instructions at the top of this file. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animation.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animation.dart new file mode 100644 index 0000000000000000000000000000000000000000..d7e9a024fccf139fd66782d9b00d6c540134f59c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animation.dart @@ -0,0 +1,315 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'package:flutter/foundation.dart'; + +import 'tween.dart'; + +export 'dart:ui' show VoidCallback; + +export 'tween.dart' show Animatable; + +// Examples can assume: +// late AnimationController _controller; +// late ValueNotifier _scrollPosition; + +/// The status of an animation. +enum AnimationStatus { + /// The animation is stopped at the beginning. + dismissed, + + /// The animation is running from beginning to end. + forward, + + /// The animation is running backwards, from end to beginning. + reverse, + + /// The animation is stopped at the end. + completed, +} + +/// Signature for listeners attached using [Animation.addStatusListener]. +typedef AnimationStatusListener = void Function(AnimationStatus status); + +/// Signature for method used to transform values in [Animation.fromValueListenable]. +typedef ValueListenableTransformer = T Function(T); + +/// An animation with a value of type `T`. +/// +/// An animation consists of a value (of type `T`) together with a status. The +/// status indicates whether the animation is conceptually running from +/// beginning to end or from the end back to the beginning, although the actual +/// value of the animation might not change monotonically (e.g., if the +/// animation uses a curve that bounces). +/// +/// Animations also let other objects listen for changes to either their value +/// or their status. These callbacks are called during the "animation" phase of +/// the pipeline, just prior to rebuilding widgets. +/// +/// To create a new animation that you can run forward and backward, consider +/// using [AnimationController]. +/// +/// See also: +/// +/// * [Tween], which can be used to create [Animation] subclasses that +/// convert `Animation`s into other kinds of [Animation]s. +abstract class Animation extends Listenable implements ValueListenable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const Animation(); + + /// Create a new animation from a [ValueListenable]. + /// + /// The returned animation will always have an animations status of + /// [AnimationStatus.forward]. The value of the provided listenable can + /// be optionally transformed using the [transformer] function. + /// + /// {@tool snippet} + /// + /// This constructor can be used to replace instances of [ValueListenableBuilder] + /// widgets with a corresponding animated widget, like a [FadeTransition]. + /// + /// Before: + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return ValueListenableBuilder( + /// valueListenable: _scrollPosition, + /// builder: (BuildContext context, double value, Widget? child) { + /// final double opacity = (value / 1000).clamp(0, 1); + /// return Opacity(opacity: opacity, child: child); + /// }, + /// child: const ColoredBox( + /// color: Colors.red, + /// child: Text('Hello, Animation'), + /// ), + /// ); + /// } + /// ``` + /// + /// {@end-tool} + /// {@tool snippet} + /// + /// After: + /// + /// ```dart + /// Widget build2(BuildContext context) { + /// return FadeTransition( + /// opacity: Animation.fromValueListenable(_scrollPosition, transformer: (double value) { + /// return (value / 1000).clamp(0, 1); + /// }), + /// child: const ColoredBox( + /// color: Colors.red, + /// child: Text('Hello, Animation'), + /// ), + /// ); + /// } + /// ``` + /// {@end-tool} + factory Animation.fromValueListenable(ValueListenable listenable, { + ValueListenableTransformer? transformer, + }) = _ValueListenableDelegateAnimation; + + // keep these next five dartdocs in sync with the dartdocs in AnimationWithParentMixin + + /// Calls the listener every time the value of the animation changes. + /// + /// Listeners can be removed with [removeListener]. + @override + void addListener(VoidCallback listener); + + /// Stop calling the listener every time the value of the animation changes. + /// + /// If `listener` is not currently registered as a listener, this method does + /// nothing. + /// + /// Listeners can be added with [addListener]. + @override + void removeListener(VoidCallback listener); + + /// Calls listener every time the status of the animation changes. + /// + /// Listeners can be removed with [removeStatusListener]. + void addStatusListener(AnimationStatusListener listener); + + /// Stops calling the listener every time the status of the animation changes. + /// + /// If `listener` is not currently registered as a status listener, this + /// method does nothing. + /// + /// Listeners can be added with [addStatusListener]. + void removeStatusListener(AnimationStatusListener listener); + + /// The current status of this animation. + AnimationStatus get status; + + /// The current value of the animation. + @override + T get value; + + /// Whether this animation is stopped at the beginning. + bool get isDismissed => status == AnimationStatus.dismissed; + + /// Whether this animation is stopped at the end. + bool get isCompleted => status == AnimationStatus.completed; + + /// Chains a [Tween] (or [CurveTween]) to this [Animation]. + /// + /// This method is only valid for `Animation` instances (i.e. when `T` + /// is `double`). This means, for instance, that it can be called on + /// [AnimationController] objects, as well as [CurvedAnimation]s, + /// [ProxyAnimation]s, [ReverseAnimation]s, [TrainHoppingAnimation]s, etc. + /// + /// It returns an [Animation] specialized to the same type, `U`, as the + /// argument to the method (`child`), whose value is derived by applying the + /// given [Tween] to the value of this [Animation]. + /// + /// {@tool snippet} + /// + /// Given an [AnimationController] `_controller`, the following code creates + /// an `Animation` that swings from top left to top right as the + /// controller goes from 0.0 to 1.0: + /// + /// ```dart + /// Animation alignment1 = _controller.drive( + /// AlignmentTween( + /// begin: Alignment.topLeft, + /// end: Alignment.topRight, + /// ), + /// ); + /// ``` + /// {@end-tool} + /// {@tool snippet} + /// + /// The `_alignment.value` could then be used in a widget's build method, for + /// instance, to position a child using an [Align] widget such that the + /// position of the child shifts over time from the top left to the top right. + /// + /// It is common to ease this kind of curve, e.g. making the transition slower + /// at the start and faster at the end. The following snippet shows one way to + /// chain the alignment tween in the previous example to an easing curve (in + /// this case, [Curves.easeIn]). In this example, the tween is created + /// elsewhere as a variable that can be reused, since none of its arguments + /// vary. + /// + /// ```dart + /// final Animatable tween = AlignmentTween(begin: Alignment.topLeft, end: Alignment.topRight) + /// .chain(CurveTween(curve: Curves.easeIn)); + /// // ... + /// final Animation alignment2 = _controller.drive(tween); + /// ``` + /// {@end-tool} + /// {@tool snippet} + /// + /// The following code is exactly equivalent, and is typically clearer when + /// the tweens are created inline, as might be preferred when the tweens have + /// values that depend on other variables: + /// + /// ```dart + /// Animation alignment3 = _controller + /// .drive(CurveTween(curve: Curves.easeIn)) + /// .drive(AlignmentTween( + /// begin: Alignment.topLeft, + /// end: Alignment.topRight, + /// )); + /// ``` + /// {@end-tool} + /// {@tool snippet} + /// + /// This method can be paired with an [Animatable] created via + /// [Animatable.fromCallback] in order to transform an animation with a + /// callback function. This can be useful for performing animations that + /// do not have well defined start or end points. This example transforms + /// the current scroll position into a color that cycles through values + /// of red. + /// + /// ```dart + /// Animation color = Animation.fromValueListenable(_scrollPosition) + /// .drive(Animatable.fromCallback((double value) { + /// return Color.fromRGBO(value.round() % 255, 0, 0, 1); + /// })); + /// ``` + /// + /// {@end-tool} + /// + /// See also: + /// + /// * [Animatable.animate], which does the same thing. + /// * [AnimationController], which is usually used to drive animations. + /// * [CurvedAnimation], an alternative to [CurveTween] for applying easing + /// curves, which supports distinct curves in the forward direction and the + /// reverse direction. + /// * [Animatable.fromCallback], which allows creating an [Animatable] from an + /// arbitrary transformation. + @optionalTypeArgs + Animation drive(Animatable child) { + assert(this is Animation); + return child.animate(this as Animation); + } + + @override + String toString() { + return '${describeIdentity(this)}(${toStringDetails()})'; + } + + /// Provides a string describing the status of this object, but not including + /// information about the object itself. + /// + /// This function is used by [Animation.toString] so that [Animation] + /// subclasses can provide additional details while ensuring all [Animation] + /// subclasses have a consistent [toString] style. + /// + /// The result of this function includes an icon describing the status of this + /// [Animation] object: + /// + /// * "▶": [AnimationStatus.forward] ([value] increasing) + /// * "◀": [AnimationStatus.reverse] ([value] decreasing) + /// * "⏭": [AnimationStatus.completed] ([value] == 1.0) + /// * "⏮": [AnimationStatus.dismissed] ([value] == 0.0) + String toStringDetails() { + return switch (status) { + AnimationStatus.forward => '\u25B6', // > + AnimationStatus.reverse => '\u25C0', // < + AnimationStatus.completed => '\u23ED', // >>| + AnimationStatus.dismissed => '\u23EE', // |<< + }; + } +} + +// An implementation of an animation that delegates to a value listenable with a fixed direction. +class _ValueListenableDelegateAnimation extends Animation { + _ValueListenableDelegateAnimation(this._listenable, { + ValueListenableTransformer? transformer, + }) : _transformer = transformer; + + final ValueListenable _listenable; + final ValueListenableTransformer? _transformer; + + @override + void addListener(VoidCallback listener) { + _listenable.addListener(listener); + } + + @override + void addStatusListener(AnimationStatusListener listener) { + // status will never change. + } + + @override + void removeListener(VoidCallback listener) { + _listenable.removeListener(listener); + } + + @override + void removeStatusListener(AnimationStatusListener listener) { + // status will never change. + } + + @override + AnimationStatus get status => AnimationStatus.forward; + + @override + T get value => _transformer?.call(_listenable.value) ?? _listenable.value; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animation_controller.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animation_controller.dart new file mode 100644 index 0000000000000000000000000000000000000000..27919f2c1bb61035db4ab59add93663426773397 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animation_controller.dart @@ -0,0 +1,957 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/physics.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/semantics.dart'; + +import 'animation.dart'; +import 'curves.dart'; +import 'listener_helpers.dart'; + +export 'package:flutter/physics.dart' show Simulation, SpringDescription; +export 'package:flutter/scheduler.dart' show TickerFuture, TickerProvider; + +export 'animation.dart' show Animation, AnimationStatus; +export 'curves.dart' show Curve; + +const String _flutterAnimationLibrary = 'package:flutter/animation.dart'; + +// Examples can assume: +// late AnimationController _controller, fadeAnimationController, sizeAnimationController; +// late bool dismissed; +// void setState(VoidCallback fn) { } + +/// The direction in which an animation is running. +enum _AnimationDirection { + /// The animation is running from beginning to end. + forward, + + /// The animation is running backwards, from end to beginning. + reverse, +} + +final SpringDescription _kFlingSpringDescription = SpringDescription.withDampingRatio( + mass: 1.0, + stiffness: 500.0, +); + +const Tolerance _kFlingTolerance = Tolerance( + velocity: double.infinity, + distance: 0.01, +); + +/// Configures how an [AnimationController] behaves when animations are +/// disabled. +/// +/// When [AccessibilityFeatures.disableAnimations] is true, the device is asking +/// Flutter to reduce or disable animations as much as possible. To honor this, +/// we reduce the duration and the corresponding number of frames for +/// animations. This enum is used to allow certain [AnimationController]s to opt +/// out of this behavior. +/// +/// For example, the [AnimationController] which controls the physics simulation +/// for a scrollable list will have [AnimationBehavior.preserve], so that when +/// a user attempts to scroll it does not jump to the end/beginning too quickly. +enum AnimationBehavior { + /// The [AnimationController] will reduce its duration when + /// [AccessibilityFeatures.disableAnimations] is true. + normal, + + /// The [AnimationController] will preserve its behavior. + /// + /// This is the default for repeating animations in order to prevent them from + /// flashing rapidly on the screen if the widget does not take the + /// [AccessibilityFeatures.disableAnimations] flag into account. + preserve, +} + +/// A controller for an animation. +/// +/// This class lets you perform tasks such as: +/// +/// * Play an animation [forward] or in [reverse], or [stop] an animation. +/// * Set the animation to a specific [value]. +/// * Define the [upperBound] and [lowerBound] values of an animation. +/// * Create a [fling] animation effect using a physics simulation. +/// +/// By default, an [AnimationController] linearly produces values that range +/// from 0.0 to 1.0, during a given duration. The animation controller generates +/// a new value whenever the device running your app is ready to display a new +/// frame (typically, this rate is around 60 values per second). +/// +/// ## Ticker providers +/// +/// An [AnimationController] needs a [TickerProvider], which is configured using +/// the `vsync` argument on the constructor. +/// +/// The [TickerProvider] interface describes a factory for [Ticker] objects. A +/// [Ticker] is an object that knows how to register itself with the +/// [SchedulerBinding] and fires a callback every frame. The +/// [AnimationController] class uses a [Ticker] to step through the animation +/// that it controls. +/// +/// If an [AnimationController] is being created from a [State], then the State +/// can use the [TickerProviderStateMixin] and [SingleTickerProviderStateMixin] +/// classes to implement the [TickerProvider] interface. The +/// [TickerProviderStateMixin] class always works for this purpose; the +/// [SingleTickerProviderStateMixin] is slightly more efficient in the case of +/// the class only ever needing one [Ticker] (e.g. if the class creates only a +/// single [AnimationController] during its entire lifetime). +/// +/// The widget test framework [WidgetTester] object can be used as a ticker +/// provider in the context of tests. In other contexts, you will have to either +/// pass a [TickerProvider] from a higher level (e.g. indirectly from a [State] +/// that mixes in [TickerProviderStateMixin]), or create a custom +/// [TickerProvider] subclass. +/// +/// ## Life cycle +/// +/// An [AnimationController] should be [dispose]d when it is no longer needed. +/// This reduces the likelihood of leaks. When used with a [StatefulWidget], it +/// is common for an [AnimationController] to be created in the +/// [State.initState] method and then disposed in the [State.dispose] method. +/// +/// ## Using [Future]s with [AnimationController] +/// +/// The methods that start animations return a [TickerFuture] object which +/// completes when the animation completes successfully, and never throws an +/// error; if the animation is canceled, the future never completes. This object +/// also has a [TickerFuture.orCancel] property which returns a future that +/// completes when the animation completes successfully, and completes with an +/// error when the animation is aborted. +/// +/// This can be used to write code such as the `fadeOutAndUpdateState` method +/// below. +/// +/// {@tool snippet} +/// +/// Here is a stateful `Foo` widget. Its [State] uses the +/// [SingleTickerProviderStateMixin] to implement the necessary +/// [TickerProvider], creating its controller in the [State.initState] method +/// and disposing of it in the [State.dispose] method. The duration of the +/// controller is configured from a property in the `Foo` widget; as that +/// changes, the [State.didUpdateWidget] method is used to update the +/// controller. +/// +/// ```dart +/// class Foo extends StatefulWidget { +/// const Foo({ super.key, required this.duration }); +/// +/// final Duration duration; +/// +/// @override +/// State createState() => _FooState(); +/// } +/// +/// class _FooState extends State with SingleTickerProviderStateMixin { +/// late AnimationController _controller; +/// +/// @override +/// void initState() { +/// super.initState(); +/// _controller = AnimationController( +/// vsync: this, // the SingleTickerProviderStateMixin +/// duration: widget.duration, +/// ); +/// } +/// +/// @override +/// void didUpdateWidget(Foo oldWidget) { +/// super.didUpdateWidget(oldWidget); +/// _controller.duration = widget.duration; +/// } +/// +/// @override +/// void dispose() { +/// _controller.dispose(); +/// super.dispose(); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return Container(); // ... +/// } +/// } +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// The following method (for a [State] subclass) drives two animation +/// controllers using Dart's asynchronous syntax for awaiting [Future] objects: +/// +/// ```dart +/// Future fadeOutAndUpdateState() async { +/// try { +/// await fadeAnimationController.forward().orCancel; +/// await sizeAnimationController.forward().orCancel; +/// setState(() { +/// dismissed = true; +/// }); +/// } on TickerCanceled { +/// // the animation got canceled, probably because we were disposed +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// The assumption in the code above is that the animation controllers are being +/// disposed in the [State] subclass' override of the [State.dispose] method. +/// Since disposing the controller cancels the animation (raising a +/// [TickerCanceled] exception), the code here can skip verifying whether +/// [State.mounted] is still true at each step. (Again, this assumes that the +/// controllers are created in [State.initState] and disposed in +/// [State.dispose], as described in the previous section.) +/// +/// {@tool dartpad} +/// This example shows how to use [AnimationController] and +/// [SlideTransition] to create an animated digit like you might find +/// on an old pinball machine our your car's odometer. New digit +/// values slide into place from below, as the old value slides +/// upwards and out of view. Taps that occur while the controller is +/// already animating cause the controller's +/// [AnimationController.duration] to be reduced so that the visuals +/// don't fall behind. +/// +/// ** See code in examples/api/lib/animation/animation_controller/animated_digit.0.dart ** +/// {@end-tool} + +/// See also: +/// +/// * [Tween], the base class for converting an [AnimationController] to a +/// range of values of other types. +class AnimationController extends Animation + with AnimationEagerListenerMixin, AnimationLocalListenersMixin, AnimationLocalStatusListenersMixin { + /// Creates an animation controller. + /// + /// * `value` is the initial value of the animation. If defaults to the lower + /// bound. + /// + /// * [duration] is the length of time this animation should last. + /// + /// * [debugLabel] is a string to help identify this animation during + /// debugging (used by [toString]). + /// + /// * [lowerBound] is the smallest value this animation can obtain and the + /// value at which this animation is deemed to be dismissed. It cannot be + /// null. + /// + /// * [upperBound] is the largest value this animation can obtain and the + /// value at which this animation is deemed to be completed. It cannot be + /// null. + /// + /// * `vsync` is the required [TickerProvider] for the current context. It can + /// be changed by calling [resync]. See [TickerProvider] for advice on + /// obtaining a ticker provider. + AnimationController({ + double? value, + this.duration, + this.reverseDuration, + this.debugLabel, + this.lowerBound = 0.0, + this.upperBound = 1.0, + this.animationBehavior = AnimationBehavior.normal, + required TickerProvider vsync, + }) : assert(upperBound >= lowerBound), + _direction = _AnimationDirection.forward { + if (kFlutterMemoryAllocationsEnabled) { + _maybeDispatchObjectCreation(); + } + _ticker = vsync.createTicker(_tick); + _internalSetValue(value ?? lowerBound); + } + + /// Creates an animation controller with no upper or lower bound for its + /// value. + /// + /// * [value] is the initial value of the animation. + /// + /// * [duration] is the length of time this animation should last. + /// + /// * [debugLabel] is a string to help identify this animation during + /// debugging (used by [toString]). + /// + /// * `vsync` is the required [TickerProvider] for the current context. It can + /// be changed by calling [resync]. See [TickerProvider] for advice on + /// obtaining a ticker provider. + /// + /// This constructor is most useful for animations that will be driven using a + /// physics simulation, especially when the physics simulation has no + /// pre-determined bounds. + AnimationController.unbounded({ + double value = 0.0, + this.duration, + this.reverseDuration, + this.debugLabel, + required TickerProvider vsync, + this.animationBehavior = AnimationBehavior.preserve, + }) : lowerBound = double.negativeInfinity, + upperBound = double.infinity, + _direction = _AnimationDirection.forward { + if (kFlutterMemoryAllocationsEnabled) { + _maybeDispatchObjectCreation(); + } + _ticker = vsync.createTicker(_tick); + _internalSetValue(value); + } + + /// Dispatches event of object creation to [FlutterMemoryAllocations.instance]. + void _maybeDispatchObjectCreation() { + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: _flutterAnimationLibrary, + className: '$AnimationController', + object: this, + ); + } + } + + /// The value at which this animation is deemed to be dismissed. + final double lowerBound; + + /// The value at which this animation is deemed to be completed. + final double upperBound; + + /// A label that is used in the [toString] output. Intended to aid with + /// identifying animation controller instances in debug output. + final String? debugLabel; + + /// The behavior of the controller when [AccessibilityFeatures.disableAnimations] + /// is true. + /// + /// Defaults to [AnimationBehavior.normal] for the [AnimationController.new] + /// constructor, and [AnimationBehavior.preserve] for the + /// [AnimationController.unbounded] constructor. + final AnimationBehavior animationBehavior; + + /// Returns an [Animation] for this animation controller, so that a + /// pointer to this object can be passed around without allowing users of that + /// pointer to mutate the [AnimationController] state. + Animation get view => this; + + /// The length of time this animation should last. + /// + /// If [reverseDuration] is specified, then [duration] is only used when going + /// [forward]. Otherwise, it specifies the duration going in both directions. + Duration? duration; + + /// The length of time this animation should last when going in [reverse]. + /// + /// The value of [duration] is used if [reverseDuration] is not specified or + /// set to null. + Duration? reverseDuration; + + Ticker? _ticker; + + /// Recreates the [Ticker] with the new [TickerProvider]. + void resync(TickerProvider vsync) { + final Ticker oldTicker = _ticker!; + _ticker = vsync.createTicker(_tick); + _ticker!.absorbTicker(oldTicker); + } + + Simulation? _simulation; + + /// The current value of the animation. + /// + /// Setting this value notifies all the listeners that the value + /// changed. + /// + /// Setting this value also stops the controller if it is currently + /// running; if this happens, it also notifies all the status + /// listeners. + @override + double get value => _value; + late double _value; + /// Stops the animation controller and sets the current value of the + /// animation. + /// + /// The new value is clamped to the range set by [lowerBound] and + /// [upperBound]. + /// + /// Value listeners are notified even if this does not change the value. + /// Status listeners are notified if the animation was previously playing. + /// + /// The most recently returned [TickerFuture], if any, is marked as having been + /// canceled, meaning the future never completes and its [TickerFuture.orCancel] + /// derivative future completes with a [TickerCanceled] error. + /// + /// See also: + /// + /// * [reset], which is equivalent to setting [value] to [lowerBound]. + /// * [stop], which aborts the animation without changing its value or status + /// and without dispatching any notifications other than completing or + /// canceling the [TickerFuture]. + /// * [forward], [reverse], [animateTo], [animateWith], [fling], and [repeat], + /// which start the animation controller. + set value(double newValue) { + stop(); + _internalSetValue(newValue); + notifyListeners(); + _checkStatusChanged(); + } + + /// Sets the controller's value to [lowerBound], stopping the animation (if + /// in progress), and resetting to its beginning point, or dismissed state. + /// + /// The most recently returned [TickerFuture], if any, is marked as having been + /// canceled, meaning the future never completes and its [TickerFuture.orCancel] + /// derivative future completes with a [TickerCanceled] error. + /// + /// See also: + /// + /// * [value], which can be explicitly set to a specific value as desired. + /// * [forward], which starts the animation in the forward direction. + /// * [stop], which aborts the animation without changing its value or status + /// and without dispatching any notifications other than completing or + /// canceling the [TickerFuture]. + void reset() { + value = lowerBound; + } + + /// The rate of change of [value] per second. + /// + /// If [isAnimating] is false, then [value] is not changing and the rate of + /// change is zero. + double get velocity { + if (!isAnimating) { + return 0.0; + } + return _simulation!.dx(lastElapsedDuration!.inMicroseconds.toDouble() / Duration.microsecondsPerSecond); + } + + void _internalSetValue(double newValue) { + _value = clampDouble(newValue, lowerBound, upperBound); + if (_value == lowerBound) { + _status = AnimationStatus.dismissed; + } else if (_value == upperBound) { + _status = AnimationStatus.completed; + } else { + _status = (_direction == _AnimationDirection.forward) ? + AnimationStatus.forward : + AnimationStatus.reverse; + } + } + + /// The amount of time that has passed between the time the animation started + /// and the most recent tick of the animation. + /// + /// If the controller is not animating, the last elapsed duration is null. + Duration? get lastElapsedDuration => _lastElapsedDuration; + Duration? _lastElapsedDuration; + + /// Whether this animation is currently animating in either the forward or reverse direction. + /// + /// This is separate from whether it is actively ticking. An animation + /// controller's ticker might get muted, in which case the animation + /// controller's callbacks will no longer fire even though time is continuing + /// to pass. See [Ticker.muted] and [TickerMode]. + bool get isAnimating => _ticker != null && _ticker!.isActive; + + _AnimationDirection _direction; + + @override + AnimationStatus get status => _status; + late AnimationStatus _status; + + /// Starts running this animation forwards (towards the end). + /// + /// Returns a [TickerFuture] that completes when the animation is complete. + /// + /// The most recently returned [TickerFuture], if any, is marked as having been + /// canceled, meaning the future never completes and its [TickerFuture.orCancel] + /// derivative future completes with a [TickerCanceled] error. + /// + /// During the animation, [status] is reported as [AnimationStatus.forward], + /// which switches to [AnimationStatus.completed] when [upperBound] is + /// reached at the end of the animation. + TickerFuture forward({ double? from }) { + assert(() { + if (duration == null) { + throw FlutterError( + 'AnimationController.forward() called with no default duration.\n' + 'The "duration" property should be set, either in the constructor or later, before ' + 'calling the forward() function.', + ); + } + return true; + }()); + assert( + _ticker != null, + 'AnimationController.forward() called after AnimationController.dispose()\n' + 'AnimationController methods should not be used after calling dispose.', + ); + _direction = _AnimationDirection.forward; + if (from != null) { + value = from; + } + return _animateToInternal(upperBound); + } + + /// Starts running this animation in reverse (towards the beginning). + /// + /// Returns a [TickerFuture] that completes when the animation is dismissed. + /// + /// The most recently returned [TickerFuture], if any, is marked as having been + /// canceled, meaning the future never completes and its [TickerFuture.orCancel] + /// derivative future completes with a [TickerCanceled] error. + /// + /// During the animation, [status] is reported as [AnimationStatus.reverse], + /// which switches to [AnimationStatus.dismissed] when [lowerBound] is + /// reached at the end of the animation. + TickerFuture reverse({ double? from }) { + assert(() { + if (duration == null && reverseDuration == null) { + throw FlutterError( + 'AnimationController.reverse() called with no default duration or reverseDuration.\n' + 'The "duration" or "reverseDuration" property should be set, either in the constructor or later, before ' + 'calling the reverse() function.', + ); + } + return true; + }()); + assert( + _ticker != null, + 'AnimationController.reverse() called after AnimationController.dispose()\n' + 'AnimationController methods should not be used after calling dispose.', + ); + _direction = _AnimationDirection.reverse; + if (from != null) { + value = from; + } + return _animateToInternal(lowerBound); + } + + /// Drives the animation from its current value to target. + /// + /// Returns a [TickerFuture] that completes when the animation is complete. + /// + /// The most recently returned [TickerFuture], if any, is marked as having been + /// canceled, meaning the future never completes and its [TickerFuture.orCancel] + /// derivative future completes with a [TickerCanceled] error. + /// + /// During the animation, [status] is reported as [AnimationStatus.forward] + /// regardless of whether `target` > [value] or not. At the end of the + /// animation, when `target` is reached, [status] is reported as + /// [AnimationStatus.completed]. + /// + /// If the `target` argument is the same as the current [value] of the + /// animation, then this won't animate, and the returned [TickerFuture] will + /// be already complete. + TickerFuture animateTo(double target, { Duration? duration, Curve curve = Curves.linear }) { + assert(() { + if (this.duration == null && duration == null) { + throw FlutterError( + 'AnimationController.animateTo() called with no explicit duration and no default duration.\n' + 'Either the "duration" argument to the animateTo() method should be provided, or the ' + '"duration" property should be set, either in the constructor or later, before ' + 'calling the animateTo() function.', + ); + } + return true; + }()); + assert( + _ticker != null, + 'AnimationController.animateTo() called after AnimationController.dispose()\n' + 'AnimationController methods should not be used after calling dispose.', + ); + _direction = _AnimationDirection.forward; + return _animateToInternal(target, duration: duration, curve: curve); + } + + /// Drives the animation from its current value to target. + /// + /// Returns a [TickerFuture] that completes when the animation is complete. + /// + /// The most recently returned [TickerFuture], if any, is marked as having been + /// canceled, meaning the future never completes and its [TickerFuture.orCancel] + /// derivative future completes with a [TickerCanceled] error. + /// + /// During the animation, [status] is reported as [AnimationStatus.reverse] + /// regardless of whether `target` < [value] or not. At the end of the + /// animation, when `target` is reached, [status] is reported as + /// [AnimationStatus.dismissed]. + TickerFuture animateBack(double target, { Duration? duration, Curve curve = Curves.linear }) { + assert(() { + if (this.duration == null && reverseDuration == null && duration == null) { + throw FlutterError( + 'AnimationController.animateBack() called with no explicit duration and no default duration or reverseDuration.\n' + 'Either the "duration" argument to the animateBack() method should be provided, or the ' + '"duration" or "reverseDuration" property should be set, either in the constructor or later, before ' + 'calling the animateBack() function.', + ); + } + return true; + }()); + assert( + _ticker != null, + 'AnimationController.animateBack() called after AnimationController.dispose()\n' + 'AnimationController methods should not be used after calling dispose.', + ); + _direction = _AnimationDirection.reverse; + return _animateToInternal(target, duration: duration, curve: curve); + } + + TickerFuture _animateToInternal(double target, { Duration? duration, Curve curve = Curves.linear }) { + double scale = 1.0; + if (SemanticsBinding.instance.disableAnimations) { + switch (animationBehavior) { + case AnimationBehavior.normal: + // Since the framework cannot handle zero duration animations, we run it at 5% of the normal + // duration to limit most animations to a single frame. + // Ideally, the framework would be able to handle zero duration animations, however, the common + // pattern of an eternally repeating animation might cause an endless loop if it weren't delayed + // for at least one frame. + scale = 0.05; + case AnimationBehavior.preserve: + break; + } + } + Duration? simulationDuration = duration; + if (simulationDuration == null) { + assert(!(this.duration == null && _direction == _AnimationDirection.forward)); + assert(!(this.duration == null && _direction == _AnimationDirection.reverse && reverseDuration == null)); + final double range = upperBound - lowerBound; + final double remainingFraction = range.isFinite ? (target - _value).abs() / range : 1.0; + final Duration directionDuration = + (_direction == _AnimationDirection.reverse && reverseDuration != null) + ? reverseDuration! + : this.duration!; + simulationDuration = directionDuration * remainingFraction; + } else if (target == value) { + // Already at target, don't animate. + simulationDuration = Duration.zero; + } + stop(); + if (simulationDuration == Duration.zero) { + if (value != target) { + _value = clampDouble(target, lowerBound, upperBound); + notifyListeners(); + } + _status = (_direction == _AnimationDirection.forward) ? + AnimationStatus.completed : + AnimationStatus.dismissed; + _checkStatusChanged(); + return TickerFuture.complete(); + } + assert(simulationDuration > Duration.zero); + assert(!isAnimating); + return _startSimulation(_InterpolationSimulation(_value, target, simulationDuration, curve, scale)); + } + + /// Starts running this animation in the forward direction, and + /// restarts the animation when it completes. + /// + /// Defaults to repeating between the [lowerBound] and [upperBound] of the + /// [AnimationController] when no explicit value is set for [min] and [max]. + /// + /// With [reverse] set to true, instead of always starting over at [min] + /// the starting value will alternate between [min] and [max] values on each + /// repeat. The [status] will be reported as [AnimationStatus.reverse] when + /// the animation runs from [max] to [min]. + /// + /// Each run of the animation will have a duration of `period`. If `period` is not + /// provided, [duration] will be used instead, which has to be set before [repeat] is + /// called either in the constructor or later by using the [duration] setter. + /// + /// Returns a [TickerFuture] that never completes. The [TickerFuture.orCancel] future + /// completes with an error when the animation is stopped (e.g. with [stop]). + /// + /// The most recently returned [TickerFuture], if any, is marked as having been + /// canceled, meaning the future never completes and its [TickerFuture.orCancel] + /// derivative future completes with a [TickerCanceled] error. + TickerFuture repeat({ double? min, double? max, bool reverse = false, Duration? period }) { + min ??= lowerBound; + max ??= upperBound; + period ??= duration; + assert(() { + if (period == null) { + throw FlutterError( + 'AnimationController.repeat() called without an explicit period and with no default Duration.\n' + 'Either the "period" argument to the repeat() method should be provided, or the ' + '"duration" property should be set, either in the constructor or later, before ' + 'calling the repeat() function.', + ); + } + return true; + }()); + assert(max >= min); + assert(max <= upperBound && min >= lowerBound); + stop(); + return _startSimulation(_RepeatingSimulation(_value, min, max, reverse, period!, _directionSetter)); + } + + void _directionSetter(_AnimationDirection direction) { + _direction = direction; + _status = (_direction == _AnimationDirection.forward) ? + AnimationStatus.forward : + AnimationStatus.reverse; + _checkStatusChanged(); + } + + /// Drives the animation with a spring (within [lowerBound] and [upperBound]) + /// and initial velocity. + /// + /// If velocity is positive, the animation will complete, otherwise it will + /// dismiss. The velocity is specified in units per second. If the + /// [SemanticsBinding.disableAnimations] flag is set, the velocity is somewhat + /// arbitrarily multiplied by 200. + /// + /// The [springDescription] parameter can be used to specify a custom + /// [SpringType.criticallyDamped] or [SpringType.overDamped] spring with which + /// to drive the animation. By default, a [SpringType.criticallyDamped] spring + /// is used. See [SpringDescription.withDampingRatio] for how to create a + /// suitable [SpringDescription]. + /// + /// The resulting spring simulation cannot be of type [SpringType.underDamped]; + /// such a spring would oscillate rather than fling. + /// + /// Returns a [TickerFuture] that completes when the animation is complete. + /// + /// The most recently returned [TickerFuture], if any, is marked as having been + /// canceled, meaning the future never completes and its [TickerFuture.orCancel] + /// derivative future completes with a [TickerCanceled] error. + TickerFuture fling({ double velocity = 1.0, SpringDescription? springDescription, AnimationBehavior? animationBehavior }) { + springDescription ??= _kFlingSpringDescription; + _direction = velocity < 0.0 ? _AnimationDirection.reverse : _AnimationDirection.forward; + final double target = velocity < 0.0 ? lowerBound - _kFlingTolerance.distance + : upperBound + _kFlingTolerance.distance; + double scale = 1.0; + final AnimationBehavior behavior = animationBehavior ?? this.animationBehavior; + if (SemanticsBinding.instance.disableAnimations) { + switch (behavior) { + case AnimationBehavior.normal: + scale = 200.0; // This is arbitrary (it was chosen because it worked for the drawer widget). + case AnimationBehavior.preserve: + break; + } + } + final SpringSimulation simulation = SpringSimulation(springDescription, value, target, velocity * scale) + ..tolerance = _kFlingTolerance; + assert( + simulation.type != SpringType.underDamped, + 'The specified spring simulation is of type SpringType.underDamped.\n' + 'An underdamped spring results in oscillation rather than a fling. ' + 'Consider specifying a different springDescription, or use animateWith() ' + 'with an explicit SpringSimulation if an underdamped spring is intentional.', + ); + stop(); + return _startSimulation(simulation); + } + + /// Drives the animation according to the given simulation. + /// + /// The values from the simulation are clamped to the [lowerBound] and + /// [upperBound]. To avoid this, consider creating the [AnimationController] + /// using the [AnimationController.unbounded] constructor. + /// + /// Returns a [TickerFuture] that completes when the animation is complete. + /// + /// The most recently returned [TickerFuture], if any, is marked as having been + /// canceled, meaning the future never completes and its [TickerFuture.orCancel] + /// derivative future completes with a [TickerCanceled] error. + /// + /// The [status] is always [AnimationStatus.forward] for the entire duration + /// of the simulation. + TickerFuture animateWith(Simulation simulation) { + assert( + _ticker != null, + 'AnimationController.animateWith() called after AnimationController.dispose()\n' + 'AnimationController methods should not be used after calling dispose.', + ); + stop(); + _direction = _AnimationDirection.forward; + return _startSimulation(simulation); + } + + TickerFuture _startSimulation(Simulation simulation) { + assert(!isAnimating); + _simulation = simulation; + _lastElapsedDuration = Duration.zero; + _value = clampDouble(simulation.x(0.0), lowerBound, upperBound); + final TickerFuture result = _ticker!.start(); + _status = (_direction == _AnimationDirection.forward) ? + AnimationStatus.forward : + AnimationStatus.reverse; + _checkStatusChanged(); + return result; + } + + /// Stops running this animation. + /// + /// This does not trigger any notifications. The animation stops in its + /// current state. + /// + /// By default, the most recently returned [TickerFuture] is marked as having + /// been canceled, meaning the future never completes and its + /// [TickerFuture.orCancel] derivative future completes with a [TickerCanceled] + /// error. By passing the `canceled` argument with the value false, this is + /// reversed, and the futures complete successfully. + /// + /// See also: + /// + /// * [reset], which stops the animation and resets it to the [lowerBound], + /// and which does send notifications. + /// * [forward], [reverse], [animateTo], [animateWith], [fling], and [repeat], + /// which restart the animation controller. + void stop({ bool canceled = true }) { + assert( + _ticker != null, + 'AnimationController.stop() called after AnimationController.dispose()\n' + 'AnimationController methods should not be used after calling dispose.', + ); + _simulation = null; + _lastElapsedDuration = null; + _ticker!.stop(canceled: canceled); + } + + /// Release the resources used by this object. The object is no longer usable + /// after this method is called. + /// + /// The most recently returned [TickerFuture], if any, is marked as having been + /// canceled, meaning the future never completes and its [TickerFuture.orCancel] + /// derivative future completes with a [TickerCanceled] error. + @override + void dispose() { + assert(() { + if (_ticker == null) { + throw FlutterError.fromParts([ + ErrorSummary('AnimationController.dispose() called more than once.'), + ErrorDescription('A given $runtimeType cannot be disposed more than once.\n'), + DiagnosticsProperty( + 'The following $runtimeType object was disposed multiple times', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]); + } + return true; + }()); + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _ticker!.dispose(); + _ticker = null; + clearStatusListeners(); + clearListeners(); + super.dispose(); + } + + AnimationStatus _lastReportedStatus = AnimationStatus.dismissed; + void _checkStatusChanged() { + final AnimationStatus newStatus = status; + if (_lastReportedStatus != newStatus) { + _lastReportedStatus = newStatus; + notifyStatusListeners(newStatus); + } + } + + void _tick(Duration elapsed) { + _lastElapsedDuration = elapsed; + final double elapsedInSeconds = elapsed.inMicroseconds.toDouble() / Duration.microsecondsPerSecond; + assert(elapsedInSeconds >= 0.0); + _value = clampDouble(_simulation!.x(elapsedInSeconds), lowerBound, upperBound); + if (_simulation!.isDone(elapsedInSeconds)) { + _status = (_direction == _AnimationDirection.forward) ? + AnimationStatus.completed : + AnimationStatus.dismissed; + stop(canceled: false); + } + notifyListeners(); + _checkStatusChanged(); + } + + @override + String toStringDetails() { + final String paused = isAnimating ? '' : '; paused'; + final String ticker = _ticker == null ? '; DISPOSED' : (_ticker!.muted ? '; silenced' : ''); + String label = ''; + assert(() { + if (debugLabel != null) { + label = '; for $debugLabel'; + } + return true; + }()); + final String more = '${super.toStringDetails()} ${value.toStringAsFixed(3)}'; + return '$more$paused$ticker$label'; + } +} + +class _InterpolationSimulation extends Simulation { + _InterpolationSimulation(this._begin, this._end, Duration duration, this._curve, double scale) + : assert(duration.inMicroseconds > 0), + _durationInSeconds = (duration.inMicroseconds * scale) / Duration.microsecondsPerSecond; + + final double _durationInSeconds; + final double _begin; + final double _end; + final Curve _curve; + + @override + double x(double timeInSeconds) { + final double t = clampDouble(timeInSeconds / _durationInSeconds, 0.0, 1.0); + if (t == 0.0) { + return _begin; + } else if (t == 1.0) { + return _end; + } else { + return _begin + (_end - _begin) * _curve.transform(t); + } + } + + @override + double dx(double timeInSeconds) { + final double epsilon = tolerance.time; + return (x(timeInSeconds + epsilon) - x(timeInSeconds - epsilon)) / (2 * epsilon); + } + + @override + bool isDone(double timeInSeconds) => timeInSeconds > _durationInSeconds; +} + +typedef _DirectionSetter = void Function(_AnimationDirection direction); + +class _RepeatingSimulation extends Simulation { + _RepeatingSimulation(double initialValue, this.min, this.max, this.reverse, Duration period, this.directionSetter) + : _periodInSeconds = period.inMicroseconds / Duration.microsecondsPerSecond, + _initialT = (max == min) ? 0.0 : (initialValue / (max - min)) * (period.inMicroseconds / Duration.microsecondsPerSecond) { + assert(_periodInSeconds > 0.0); + assert(_initialT >= 0.0); + } + + final double min; + final double max; + final bool reverse; + final _DirectionSetter directionSetter; + + final double _periodInSeconds; + final double _initialT; + + @override + double x(double timeInSeconds) { + assert(timeInSeconds >= 0.0); + + final double totalTimeInSeconds = timeInSeconds + _initialT; + final double t = (totalTimeInSeconds / _periodInSeconds) % 1.0; + final bool isPlayingReverse = (totalTimeInSeconds ~/ _periodInSeconds).isOdd; + + if (reverse && isPlayingReverse) { + directionSetter(_AnimationDirection.reverse); + return ui.lerpDouble(max, min, t)!; + } else { + directionSetter(_AnimationDirection.forward); + return ui.lerpDouble(min, max, t)!; + } + } + + @override + double dx(double timeInSeconds) => (max - min) / _periodInSeconds; + + @override + bool isDone(double timeInSeconds) => false; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animation_style.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animation_style.dart new file mode 100644 index 0000000000000000000000000000000000000000..18f95aa24642bbf5259aa24f2e9feb7baee57997 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animation_style.dart @@ -0,0 +1,110 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'curves.dart'; +import 'tween.dart'; + +/// Used to override the default parameters of an animation. +/// +/// Currently, this class is used by the following widgets: +/// - [ExpansionTile] +/// - [MaterialApp] +/// - [PopupMenuButton] +/// +/// If [duration] and [reverseDuration] are set to [Duration.zero], the +/// corresponding animation will be disabled. +/// +/// All of the parameters are optional. If no parameters are specified, +/// the default animation will be used. +@immutable +class AnimationStyle with Diagnosticable { + /// Creates an instance of Animation Style class. + AnimationStyle({ + this.curve, + this.duration, + this.reverseCurve, + this.reverseDuration, + }); + + /// Creates an instance of Animation Style class with no animation. + static AnimationStyle noAnimation = AnimationStyle( + duration: Duration.zero, + reverseDuration: Duration.zero, + ); + + /// When specified, the animation will use this curve. + final Curve? curve; + + /// When specified, the animation will use this duration. + final Duration? duration; + + /// When specified, the reverse animation will use this curve. + final Curve? reverseCurve; + + /// When specified, the reverse animation will use this duration. + final Duration? reverseDuration; + + /// Creates a new [AnimationStyle] based on the current selection, with the + /// provided parameters overridden. + AnimationStyle copyWith({ + final Curve? curve, + final Duration? duration, + final Curve? reverseCurve, + final Duration? reverseDuration, + }) { + return AnimationStyle( + curve: curve ?? this.curve, + duration: duration ?? this.duration, + reverseCurve: reverseCurve ?? this.reverseCurve, + reverseDuration: reverseDuration ?? this.reverseDuration, + ); + } + + /// Linearly interpolate between two animation styles. + static AnimationStyle? lerp(AnimationStyle? a, AnimationStyle? b, double t) { + if (identical(a, b)) { + return a; + } + return AnimationStyle( + curve: t < 0.5 ? a?.curve : b?.curve, + duration: t < 0.5 ? a?.duration : b?.duration, + reverseCurve: t < 0.5 ? a?.reverseCurve : b?.reverseCurve, + reverseDuration: t < 0.5 ? a?.reverseDuration : b?.reverseDuration, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is AnimationStyle + && other.curve == curve + && other.duration == duration + && other.reverseCurve == reverseCurve + && other.reverseDuration == reverseDuration; + } + + @override + int get hashCode => Object.hash( + curve, + duration, + reverseCurve, + reverseDuration, + ); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('curve', curve, defaultValue: null)); + properties.add(DiagnosticsProperty('duration', duration, defaultValue: null)); + properties.add(DiagnosticsProperty('reverseCurve', reverseCurve, defaultValue: null)); + properties.add(DiagnosticsProperty('reverseDuration', reverseDuration, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animations.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animations.dart new file mode 100644 index 0000000000000000000000000000000000000000..463240bf5b63de15b5b6aff690cc0793ed23b72c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/animations.dart @@ -0,0 +1,741 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'animation.dart'; +import 'curves.dart'; +import 'listener_helpers.dart'; + +export 'dart:ui' show VoidCallback; + +export 'animation.dart' show Animation, AnimationStatus, AnimationStatusListener; +export 'curves.dart' show Curve; + +// Examples can assume: +// late AnimationController controller; + +class _AlwaysCompleteAnimation extends Animation { + const _AlwaysCompleteAnimation(); + + @override + void addListener(VoidCallback listener) { } + + @override + void removeListener(VoidCallback listener) { } + + @override + void addStatusListener(AnimationStatusListener listener) { } + + @override + void removeStatusListener(AnimationStatusListener listener) { } + + @override + AnimationStatus get status => AnimationStatus.completed; + + @override + double get value => 1.0; + + @override + String toString() => 'kAlwaysCompleteAnimation'; +} + +/// An animation that is always complete. +/// +/// Using this constant involves less overhead than building an +/// [AnimationController] with an initial value of 1.0. This is useful when an +/// API expects an animation but you don't actually want to animate anything. +const Animation kAlwaysCompleteAnimation = _AlwaysCompleteAnimation(); + +class _AlwaysDismissedAnimation extends Animation { + const _AlwaysDismissedAnimation(); + + @override + void addListener(VoidCallback listener) { } + + @override + void removeListener(VoidCallback listener) { } + + @override + void addStatusListener(AnimationStatusListener listener) { } + + @override + void removeStatusListener(AnimationStatusListener listener) { } + + @override + AnimationStatus get status => AnimationStatus.dismissed; + + @override + double get value => 0.0; + + @override + String toString() => 'kAlwaysDismissedAnimation'; +} + +/// An animation that is always dismissed. +/// +/// Using this constant involves less overhead than building an +/// [AnimationController] with an initial value of 0.0. This is useful when an +/// API expects an animation but you don't actually want to animate anything. +const Animation kAlwaysDismissedAnimation = _AlwaysDismissedAnimation(); + +/// An animation that is always stopped at a given value. +/// +/// The [status] is always [AnimationStatus.forward]. +class AlwaysStoppedAnimation extends Animation { + /// Creates an [AlwaysStoppedAnimation] with the given value. + /// + /// Since the [value] and [status] of an [AlwaysStoppedAnimation] can never + /// change, the listeners can never be called. It is therefore safe to reuse + /// an [AlwaysStoppedAnimation] instance in multiple places. If the [value] to + /// be used is known at compile time, the constructor should be called as a + /// `const` constructor. + const AlwaysStoppedAnimation(this.value); + + @override + final T value; + + @override + void addListener(VoidCallback listener) { } + + @override + void removeListener(VoidCallback listener) { } + + @override + void addStatusListener(AnimationStatusListener listener) { } + + @override + void removeStatusListener(AnimationStatusListener listener) { } + + @override + AnimationStatus get status => AnimationStatus.forward; + + @override + String toStringDetails() { + return '${super.toStringDetails()} $value; paused'; + } +} + +/// Implements most of the [Animation] interface by deferring its behavior to a +/// given [parent] Animation. +/// +/// To implement an [Animation] that is driven by a parent, it is only necessary +/// to mix in this class, implement [parent], and implement `T get value`. +/// +/// To define a mapping from values in the range 0..1, consider subclassing +/// [Tween] instead. +mixin AnimationWithParentMixin { + /// The animation whose value this animation will proxy. + /// + /// This animation must remain the same for the lifetime of this object. If + /// you wish to proxy a different animation at different times, consider using + /// [ProxyAnimation]. + Animation get parent; + + // keep these next five dartdocs in sync with the dartdocs in Animation + + /// Calls the listener every time the value of the animation changes. + /// + /// Listeners can be removed with [removeListener]. + void addListener(VoidCallback listener) => parent.addListener(listener); + + /// Stop calling the listener every time the value of the animation changes. + /// + /// Listeners can be added with [addListener]. + void removeListener(VoidCallback listener) => parent.removeListener(listener); + + /// Calls listener every time the status of the animation changes. + /// + /// Listeners can be removed with [removeStatusListener]. + void addStatusListener(AnimationStatusListener listener) => parent.addStatusListener(listener); + + /// Stops calling the listener every time the status of the animation changes. + /// + /// Listeners can be added with [addStatusListener]. + void removeStatusListener(AnimationStatusListener listener) => parent.removeStatusListener(listener); + + /// The current status of this animation. + AnimationStatus get status => parent.status; +} + +/// An animation that is a proxy for another animation. +/// +/// A proxy animation is useful because the parent animation can be mutated. For +/// example, one object can create a proxy animation, hand the proxy to another +/// object, and then later change the animation from which the proxy receives +/// its value. +class ProxyAnimation extends Animation + with AnimationLazyListenerMixin, AnimationLocalListenersMixin, AnimationLocalStatusListenersMixin { + + /// Creates a proxy animation. + /// + /// If the animation argument is omitted, the proxy animation will have the + /// status [AnimationStatus.dismissed] and a value of 0.0. + ProxyAnimation([Animation? animation]) { + _parent = animation; + if (_parent == null) { + _status = AnimationStatus.dismissed; + _value = 0.0; + } + } + + AnimationStatus? _status; + double? _value; + + /// The animation whose value this animation will proxy. + /// + /// This value is mutable. When mutated, the listeners on the proxy animation + /// will be transparently updated to be listening to the new parent animation. + Animation? get parent => _parent; + Animation? _parent; + set parent(Animation? value) { + if (value == _parent) { + return; + } + if (_parent != null) { + _status = _parent!.status; + _value = _parent!.value; + if (isListening) { + didStopListening(); + } + } + _parent = value; + if (_parent != null) { + if (isListening) { + didStartListening(); + } + if (_value != _parent!.value) { + notifyListeners(); + } + if (_status != _parent!.status) { + notifyStatusListeners(_parent!.status); + } + _status = null; + _value = null; + } + } + + @override + void didStartListening() { + if (_parent != null) { + _parent!.addListener(notifyListeners); + _parent!.addStatusListener(notifyStatusListeners); + } + } + + @override + void didStopListening() { + if (_parent != null) { + _parent!.removeListener(notifyListeners); + _parent!.removeStatusListener(notifyStatusListeners); + } + } + + @override + AnimationStatus get status => _parent != null ? _parent!.status : _status!; + + @override + double get value => _parent != null ? _parent!.value : _value!; + + @override + String toString() { + if (parent == null) { + return '${objectRuntimeType(this, 'ProxyAnimation')}(null; ${super.toStringDetails()} ${value.toStringAsFixed(3)})'; + } + return '$parent\u27A9${objectRuntimeType(this, 'ProxyAnimation')}'; + } +} + +/// An animation that is the reverse of another animation. +/// +/// If the parent animation is running forward from 0.0 to 1.0, this animation +/// is running in reverse from 1.0 to 0.0. +/// +/// Using a [ReverseAnimation] is different from using a [Tween] with a +/// `begin` of 1.0 and an `end` of 0.0 because the tween does not change the status +/// or direction of the animation. +/// +/// See also: +/// +/// * [Curve.flipped] and [FlippedCurve], which provide a similar effect but on +/// [Curve]s. +/// * [CurvedAnimation], which can take separate curves for when the animation +/// is going forward than for when it is going in reverse. +class ReverseAnimation extends Animation + with AnimationLazyListenerMixin, AnimationLocalStatusListenersMixin { + + /// Creates a reverse animation. + ReverseAnimation(this.parent); + + /// The animation whose value and direction this animation is reversing. + final Animation parent; + + @override + void addListener(VoidCallback listener) { + didRegisterListener(); + parent.addListener(listener); + } + + @override + void removeListener(VoidCallback listener) { + parent.removeListener(listener); + didUnregisterListener(); + } + + @override + void didStartListening() { + parent.addStatusListener(_statusChangeHandler); + } + + @override + void didStopListening() { + parent.removeStatusListener(_statusChangeHandler); + } + + void _statusChangeHandler(AnimationStatus status) { + notifyStatusListeners(_reverseStatus(status)); + } + + @override + AnimationStatus get status => _reverseStatus(parent.status); + + @override + double get value => 1.0 - parent.value; + + AnimationStatus _reverseStatus(AnimationStatus status) { + return switch (status) { + AnimationStatus.forward => AnimationStatus.reverse, + AnimationStatus.reverse => AnimationStatus.forward, + AnimationStatus.completed => AnimationStatus.dismissed, + AnimationStatus.dismissed => AnimationStatus.completed, + }; + } + + @override + String toString() { + return '$parent\u27AA${objectRuntimeType(this, 'ReverseAnimation')}'; + } +} + +/// An animation that applies a curve to another animation. +/// +/// [CurvedAnimation] is useful when you want to apply a non-linear [Curve] to +/// an animation object, especially if you want different curves when the +/// animation is going forward vs when it is going backward. +/// +/// Depending on the given curve, the output of the [CurvedAnimation] could have +/// a wider range than its input. For example, elastic curves such as +/// [Curves.elasticIn] will significantly overshoot or undershoot the default +/// range of 0.0 to 1.0. +/// +/// If you want to apply a [Curve] to a [Tween], consider using [CurveTween]. +/// +/// {@tool snippet} +/// +/// The following code snippet shows how you can apply a curve to a linear +/// animation produced by an [AnimationController] `controller`. +/// +/// ```dart +/// final Animation animation = CurvedAnimation( +/// parent: controller, +/// curve: Curves.ease, +/// ); +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// This second code snippet shows how to apply a different curve in the forward +/// direction than in the reverse direction. This can't be done using a +/// [CurveTween] (since [Tween]s are not aware of the animation direction when +/// they are applied). +/// +/// ```dart +/// final Animation animation = CurvedAnimation( +/// parent: controller, +/// curve: Curves.easeIn, +/// reverseCurve: Curves.easeOut, +/// ); +/// ``` +/// {@end-tool} +/// +/// By default, the [reverseCurve] matches the forward [curve]. +/// +/// See also: +/// +/// * [CurveTween], for an alternative way of expressing the first sample +/// above. +/// * [AnimationController], for examples of creating and disposing of an +/// [AnimationController]. +/// * [Curve.flipped] and [FlippedCurve], which provide the reverse of a +/// [Curve]. +class CurvedAnimation extends Animation with AnimationWithParentMixin { + /// Creates a curved animation. + CurvedAnimation({ + required this.parent, + required this.curve, + this.reverseCurve, + }) { + _updateCurveDirection(parent.status); + parent.addStatusListener(_updateCurveDirection); + } + + /// The animation to which this animation applies a curve. + @override + final Animation parent; + + /// The curve to use in the forward direction. + Curve curve; + + /// The curve to use in the reverse direction. + /// + /// If the parent animation changes direction without first reaching the + /// [AnimationStatus.completed] or [AnimationStatus.dismissed] status, the + /// [CurvedAnimation] stays on the same curve (albeit in the opposite + /// direction) to avoid visual discontinuities. + /// + /// If you use a non-null [reverseCurve], you might want to hold this object + /// in a [State] object rather than recreating it each time your widget builds + /// in order to take advantage of the state in this object that avoids visual + /// discontinuities. + /// + /// If this field is null, uses [curve] in both directions. + Curve? reverseCurve; + + /// The direction used to select the current curve. + /// + /// The curve direction is only reset when we hit the beginning or the end of + /// the timeline to avoid discontinuities in the value of any variables this + /// animation is used to animate. + AnimationStatus? _curveDirection; + + /// True if this CurvedAnimation has been disposed. + bool isDisposed = false; + + void _updateCurveDirection(AnimationStatus status) { + switch (status) { + case AnimationStatus.dismissed: + case AnimationStatus.completed: + _curveDirection = null; + case AnimationStatus.forward: + _curveDirection ??= AnimationStatus.forward; + case AnimationStatus.reverse: + _curveDirection ??= AnimationStatus.reverse; + } + } + + bool get _useForwardCurve { + return reverseCurve == null || (_curveDirection ?? parent.status) != AnimationStatus.reverse; + } + + /// Cleans up any listeners added by this CurvedAnimation. + void dispose() { + isDisposed = true; + parent.removeStatusListener(_updateCurveDirection); + } + + @override + double get value { + final Curve? activeCurve = _useForwardCurve ? curve : reverseCurve; + + final double t = parent.value; + if (activeCurve == null) { + return t; + } + if (t == 0.0 || t == 1.0) { + assert(() { + final double transformedValue = activeCurve.transform(t); + final double roundedTransformedValue = transformedValue.round().toDouble(); + if (roundedTransformedValue != t) { + throw FlutterError( + 'Invalid curve endpoint at $t.\n' + 'Curves must map 0.0 to near zero and 1.0 to near one but ' + '${activeCurve.runtimeType} mapped $t to $transformedValue, which ' + 'is near $roundedTransformedValue.', + ); + } + return true; + }()); + return t; + } + return activeCurve.transform(t); + } + + @override + String toString() { + if (reverseCurve == null) { + return '$parent\u27A9$curve'; + } + if (_useForwardCurve) { + return '$parent\u27A9$curve\u2092\u2099/$reverseCurve'; + } + return '$parent\u27A9$curve/$reverseCurve\u2092\u2099'; + } +} + +enum _TrainHoppingMode { minimize, maximize } + +/// This animation starts by proxying one animation, but when the value of that +/// animation crosses the value of the second (either because the second is +/// going in the opposite direction, or because the one overtakes the other), +/// the animation hops over to proxying the second animation. +/// +/// When the [TrainHoppingAnimation] starts proxying the second animation +/// instead of the first, the [onSwitchedTrain] callback is called. +/// +/// If the two animations start at the same value, then the +/// [TrainHoppingAnimation] immediately hops to the second animation, and the +/// [onSwitchedTrain] callback is not called. If only one animation is provided +/// (i.e. if the second is null), then the [TrainHoppingAnimation] just proxies +/// the first animation. +/// +/// Since this object must track the two animations even when it has no +/// listeners of its own, instead of shutting down when all its listeners are +/// removed, it exposes a [dispose()] method. Call this method to shut this +/// object down. +class TrainHoppingAnimation extends Animation + with AnimationEagerListenerMixin, AnimationLocalListenersMixin, AnimationLocalStatusListenersMixin { + + /// Creates a train-hopping animation. + /// + /// The current train argument must not be null but the next train argument + /// can be null. If the next train is null, then this object will just proxy + /// the first animation and never hop. + TrainHoppingAnimation( + Animation this._currentTrain, + this._nextTrain, { + this.onSwitchedTrain, + }) { + if (_nextTrain != null) { + if (_currentTrain!.value == _nextTrain!.value) { + _currentTrain = _nextTrain; + _nextTrain = null; + } else if (_currentTrain!.value > _nextTrain!.value) { + _mode = _TrainHoppingMode.maximize; + } else { + assert(_currentTrain!.value < _nextTrain!.value); + _mode = _TrainHoppingMode.minimize; + } + } + _currentTrain!.addStatusListener(_statusChangeHandler); + _currentTrain!.addListener(_valueChangeHandler); + _nextTrain?.addListener(_valueChangeHandler); + assert(_mode != null || _nextTrain == null); + } + + /// The animation that is currently driving this animation. + /// + /// The identity of this object will change from the first animation to the + /// second animation when [onSwitchedTrain] is called. + Animation? get currentTrain => _currentTrain; + Animation? _currentTrain; + Animation? _nextTrain; + _TrainHoppingMode? _mode; + + /// Called when this animation switches to be driven by the second animation. + /// + /// This is not called if the two animations provided to the constructor have + /// the same value at the time of the call to the constructor. In that case, + /// the second animation is used from the start, and the first is ignored. + VoidCallback? onSwitchedTrain; + + AnimationStatus? _lastStatus; + void _statusChangeHandler(AnimationStatus status) { + assert(_currentTrain != null); + if (status != _lastStatus) { + notifyListeners(); + _lastStatus = status; + } + assert(_lastStatus != null); + } + + @override + AnimationStatus get status => _currentTrain!.status; + + double? _lastValue; + void _valueChangeHandler() { + assert(_currentTrain != null); + bool hop = false; + if (_nextTrain != null) { + assert(_mode != null); + switch (_mode!) { + case _TrainHoppingMode.minimize: + hop = _nextTrain!.value <= _currentTrain!.value; + case _TrainHoppingMode.maximize: + hop = _nextTrain!.value >= _currentTrain!.value; + } + if (hop) { + _currentTrain! + ..removeStatusListener(_statusChangeHandler) + ..removeListener(_valueChangeHandler); + _currentTrain = _nextTrain; + _nextTrain = null; + _currentTrain!.addStatusListener(_statusChangeHandler); + _statusChangeHandler(_currentTrain!.status); + } + } + final double newValue = value; + if (newValue != _lastValue) { + notifyListeners(); + _lastValue = newValue; + } + assert(_lastValue != null); + if (hop && onSwitchedTrain != null) { + onSwitchedTrain!(); + } + } + + @override + double get value => _currentTrain!.value; + + /// Frees all the resources used by this performance. + /// After this is called, this object is no longer usable. + @override + void dispose() { + assert(_currentTrain != null); + _currentTrain!.removeStatusListener(_statusChangeHandler); + _currentTrain!.removeListener(_valueChangeHandler); + _currentTrain = null; + _nextTrain?.removeListener(_valueChangeHandler); + _nextTrain = null; + clearListeners(); + clearStatusListeners(); + super.dispose(); + } + + @override + String toString() { + if (_nextTrain != null) { + return '$currentTrain\u27A9${objectRuntimeType(this, 'TrainHoppingAnimation')}(next: $_nextTrain)'; + } + return '$currentTrain\u27A9${objectRuntimeType(this, 'TrainHoppingAnimation')}(no next)'; + } +} + +/// An interface for combining multiple Animations. Subclasses need only +/// implement the `value` getter to control how the child animations are +/// combined. Can be chained to combine more than 2 animations. +/// +/// For example, to create an animation that is the sum of two others, subclass +/// this class and define `T get value = first.value + second.value;` +/// +/// By default, the [status] of a [CompoundAnimation] is the status of the +/// [next] animation if [next] is moving, and the status of the [first] +/// animation otherwise. +abstract class CompoundAnimation extends Animation + with AnimationLazyListenerMixin, AnimationLocalListenersMixin, AnimationLocalStatusListenersMixin { + /// Creates a [CompoundAnimation]. + /// + /// Either argument can be a [CompoundAnimation] itself to combine multiple animations. + CompoundAnimation({ + required this.first, + required this.next, + }); + + /// The first sub-animation. Its status takes precedence if neither are + /// animating. + final Animation first; + + /// The second sub-animation. + final Animation next; + + @override + void didStartListening() { + first.addListener(_maybeNotifyListeners); + first.addStatusListener(_maybeNotifyStatusListeners); + next.addListener(_maybeNotifyListeners); + next.addStatusListener(_maybeNotifyStatusListeners); + } + + @override + void didStopListening() { + first.removeListener(_maybeNotifyListeners); + first.removeStatusListener(_maybeNotifyStatusListeners); + next.removeListener(_maybeNotifyListeners); + next.removeStatusListener(_maybeNotifyStatusListeners); + } + + /// Gets the status of this animation based on the [first] and [next] status. + /// + /// The default is that if the [next] animation is moving, use its status. + /// Otherwise, default to [first]. + @override + AnimationStatus get status { + if (next.status == AnimationStatus.forward || next.status == AnimationStatus.reverse) { + return next.status; + } + return first.status; + } + + @override + String toString() { + return '${objectRuntimeType(this, 'CompoundAnimation')}($first, $next)'; + } + + AnimationStatus? _lastStatus; + void _maybeNotifyStatusListeners(AnimationStatus _) { + if (status != _lastStatus) { + _lastStatus = status; + notifyStatusListeners(status); + } + } + + T? _lastValue; + void _maybeNotifyListeners() { + if (value != _lastValue) { + _lastValue = value; + notifyListeners(); + } + } +} + +/// An animation of [double]s that tracks the mean of two other animations. +/// +/// The [status] of this animation is the status of the `right` animation if it is +/// moving, and the `left` animation otherwise. +/// +/// The [value] of this animation is the [double] that represents the mean value +/// of the values of the `left` and `right` animations. +class AnimationMean extends CompoundAnimation { + /// Creates an animation that tracks the mean of two other animations. + AnimationMean({ + required Animation left, + required Animation right, + }) : super(first: left, next: right); + + @override + double get value => (first.value + next.value) / 2.0; +} + +/// An animation that tracks the maximum of two other animations. +/// +/// The [value] of this animation is the maximum of the values of +/// [first] and [next]. +class AnimationMax extends CompoundAnimation { + /// Creates an [AnimationMax]. + /// + /// Either argument can be an [AnimationMax] itself to combine multiple + /// animations. + AnimationMax(Animation first, Animation next) : super(first: first, next: next); + + @override + T get value => math.max(first.value, next.value); +} + +/// An animation that tracks the minimum of two other animations. +/// +/// The [value] of this animation is the maximum of the values of +/// [first] and [next]. +class AnimationMin extends CompoundAnimation { + /// Creates an [AnimationMin]. + /// + /// Either argument can be an [AnimationMin] itself to combine multiple + /// animations. + AnimationMin(Animation first, Animation next) : super(first: first, next: next); + + @override + T get value => math.min(first.value, next.value); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/curves.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/curves.dart new file mode 100644 index 0000000000000000000000000000000000000000..c5b5b7a3f8f0ab2f1dbe2284b5744a3b35ac2dfa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/curves.dart @@ -0,0 +1,1797 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'dart:math' as math; +import 'dart:ui'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; + +export 'dart:ui' show Offset; + +/// An abstract class providing an interface for evaluating a parametric curve. +/// +/// A parametric curve transforms a parameter (hence the name) `t` along a curve +/// to the value of the curve at that value of `t`. The curve can be of +/// arbitrary dimension, but is typically a 1D, 2D, or 3D curve. +/// +/// See also: +/// +/// * [Curve], a 1D animation easing curve that starts at 0.0 and ends at 1.0. +/// * [Curve2D], a parametric curve that transforms the parameter to a 2D point. +abstract class ParametricCurve { + /// Abstract const constructor to enable subclasses to provide + /// const constructors so that they can be used in const expressions. + const ParametricCurve(); + + /// Returns the value of the curve at point `t`. + /// + /// This method asserts that t is between 0 and 1 before delegating to + /// [transformInternal]. + /// + /// It is recommended that subclasses override [transformInternal] instead of + /// this function, as the above case is already handled in the default + /// implementation of [transform], which delegates the remaining logic to + /// [transformInternal]. + T transform(double t) { + assert(t >= 0.0 && t <= 1.0, 'parametric value $t is outside of [0, 1] range.'); + return transformInternal(t); + } + + /// Returns the value of the curve at point `t`. + /// + /// The given parametric value `t` will be between 0.0 and 1.0, inclusive. + @protected + T transformInternal(double t) { + throw UnimplementedError(); + } + + @override + String toString() => objectRuntimeType(this, 'ParametricCurve'); +} + +/// An parametric animation easing curve, i.e. a mapping of the unit interval to +/// the unit interval. +/// +/// Easing curves are used to adjust the rate of change of an animation over +/// time, allowing them to speed up and slow down, rather than moving at a +/// constant rate. +/// +/// A [Curve] must map t=0.0 to 0.0 and t=1.0 to 1.0. +/// +/// See also: +/// +/// * [Curves], a collection of common animation easing curves. +/// * [CurveTween], which can be used to apply a [Curve] to an [Animation]. +/// * [Canvas.drawArc], which draws an arc, and has nothing to do with easing +/// curves. +/// * [Animatable], for a more flexible interface that maps fractions to +/// arbitrary values. +@immutable +abstract class Curve extends ParametricCurve { + /// Abstract const constructor to enable subclasses to provide + /// const constructors so that they can be used in const expressions. + const Curve(); + + /// Returns the value of the curve at point `t`. + /// + /// This function must ensure the following: + /// - The value of `t` must be between 0.0 and 1.0 + /// - Values of `t`=0.0 and `t`=1.0 must be mapped to 0.0 and 1.0, + /// respectively. + /// + /// It is recommended that subclasses override [transformInternal] instead of + /// this function, as the above cases are already handled in the default + /// implementation of [transform], which delegates the remaining logic to + /// [transformInternal]. + @override + double transform(double t) { + if (t == 0.0 || t == 1.0) { + return t; + } + return super.transform(t); + } + + /// Returns a new curve that is the reversed inversion of this one. + /// + /// This is often useful with [CurvedAnimation.reverseCurve]. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_in.mp4} + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_flipped.mp4} + /// + /// See also: + /// + /// * [FlippedCurve], the class that is used to implement this getter. + /// * [ReverseAnimation], which reverses an [Animation] rather than a [Curve]. + /// * [CurvedAnimation], which can take a separate curve and reverse curve. + Curve get flipped => FlippedCurve(this); +} + +/// The identity map over the unit interval. +/// +/// See [Curves.linear] for an instance of this class. +class _Linear extends Curve { + const _Linear._(); + + @override + double transformInternal(double t) => t; +} + +/// A sawtooth curve that repeats a given number of times over the unit interval. +/// +/// The curve rises linearly from 0.0 to 1.0 and then falls discontinuously back +/// to 0.0 each iteration. +/// +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_sawtooth.mp4} +class SawTooth extends Curve { + /// Creates a sawtooth curve. + const SawTooth(this.count); + + /// The number of repetitions of the sawtooth pattern in the unit interval. + final int count; + + @override + double transformInternal(double t) { + t *= count; + return t - t.truncateToDouble(); + } + + @override + String toString() { + return '${objectRuntimeType(this, 'SawTooth')}($count)'; + } +} + +/// A curve that is 0.0 until [begin], then curved (according to [curve]) from +/// 0.0 at [begin] to 1.0 at [end], then remains 1.0 past [end]. +/// +/// An [Interval] can be used to delay an animation. For example, a six second +/// animation that uses an [Interval] with its [begin] set to 0.5 and its [end] +/// set to 1.0 will essentially become a three-second animation that starts +/// three seconds later. +/// +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_interval.mp4} +class Interval extends Curve { + /// Creates an interval curve. + const Interval(this.begin, this.end, { this.curve = Curves.linear }); + + /// The largest value for which this interval is 0.0. + /// + /// From t=0.0 to t=[begin], the interval's value is 0.0. + final double begin; + + /// The smallest value for which this interval is 1.0. + /// + /// From t=[end] to t=1.0, the interval's value is 1.0. + final double end; + + /// The curve to apply between [begin] and [end]. + final Curve curve; + + @override + double transformInternal(double t) { + assert(begin >= 0.0); + assert(begin <= 1.0); + assert(end >= 0.0); + assert(end <= 1.0); + assert(end >= begin); + t = clampDouble((t - begin) / (end - begin), 0.0, 1.0); + if (t == 0.0 || t == 1.0) { + return t; + } + return curve.transform(t); + } + + @override + String toString() { + if (curve is! _Linear) { + return '${objectRuntimeType(this, 'Interval')}($begin\u22EF$end)\u27A9$curve'; + } + return '${objectRuntimeType(this, 'Interval')}($begin\u22EF$end)'; + } +} + +/// A curve that is 0.0 until it hits the threshold, then it jumps to 1.0. +/// +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_threshold.mp4} +class Threshold extends Curve { + /// Creates a threshold curve. + const Threshold(this.threshold); + + /// The value before which the curve is 0.0 and after which the curve is 1.0. + /// + /// When t is exactly [threshold], the curve has the value 1.0. + final double threshold; + + @override + double transformInternal(double t) { + assert(threshold >= 0.0); + assert(threshold <= 1.0); + return t < threshold ? 0.0 : 1.0; + } +} + +/// A cubic polynomial mapping of the unit interval. +/// +/// The [Curves] class contains some commonly used cubic curves: +/// +/// * [Curves.fastLinearToSlowEaseIn] +/// * [Curves.ease] +/// * [Curves.easeIn] +/// * [Curves.easeInToLinear] +/// * [Curves.easeInSine] +/// * [Curves.easeInQuad] +/// * [Curves.easeInCubic] +/// * [Curves.easeInQuart] +/// * [Curves.easeInQuint] +/// * [Curves.easeInExpo] +/// * [Curves.easeInCirc] +/// * [Curves.easeInBack] +/// * [Curves.easeOut] +/// * [Curves.linearToEaseOut] +/// * [Curves.easeOutSine] +/// * [Curves.easeOutQuad] +/// * [Curves.easeOutCubic] +/// * [Curves.easeOutQuart] +/// * [Curves.easeOutQuint] +/// * [Curves.easeOutExpo] +/// * [Curves.easeOutCirc] +/// * [Curves.easeOutBack] +/// * [Curves.easeInOut] +/// * [Curves.easeInOutSine] +/// * [Curves.easeInOutQuad] +/// * [Curves.easeInOutCubic] +/// * [Curves.easeInOutQuart] +/// * [Curves.easeInOutQuint] +/// * [Curves.easeInOutExpo] +/// * [Curves.easeInOutCirc] +/// * [Curves.easeInOutBack] +/// * [Curves.fastOutSlowIn] +/// * [Curves.slowMiddle] +/// +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_fast_linear_to_slow_ease_in.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_to_linear.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_sine.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_quad.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_cubic.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_quart.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_quint.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_expo.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_circ.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_back.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_linear_to_ease_out.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_sine.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_quad.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_cubic.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_quart.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_quint.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_expo.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_circ.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_back.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_sine.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_quad.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_cubic.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_quart.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_quint.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_expo.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_circ.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_back.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_fast_out_slow_in.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_slow_middle.mp4} +/// +/// The [Cubic] class implements third-order Bézier curves. +/// +/// See also: +/// +/// * [Curves], where many more predefined curves are available. +/// * [CatmullRomCurve], a curve which passes through specific values. +class Cubic extends Curve { + /// Creates a cubic curve. + /// + /// Rather than creating a new instance, consider using one of the common + /// cubic curves in [Curves]. + const Cubic(this.a, this.b, this.c, this.d); + + /// The x coordinate of the first control point. + /// + /// The line through the point (0, 0) and the first control point is tangent + /// to the curve at the point (0, 0). + final double a; + + /// The y coordinate of the first control point. + /// + /// The line through the point (0, 0) and the first control point is tangent + /// to the curve at the point (0, 0). + final double b; + + /// The x coordinate of the second control point. + /// + /// The line through the point (1, 1) and the second control point is tangent + /// to the curve at the point (1, 1). + final double c; + + /// The y coordinate of the second control point. + /// + /// The line through the point (1, 1) and the second control point is tangent + /// to the curve at the point (1, 1). + final double d; + + static const double _cubicErrorBound = 0.001; + + double _evaluateCubic(double a, double b, double m) { + return 3 * a * (1 - m) * (1 - m) * m + + 3 * b * (1 - m) * m * m + + m * m * m; + } + + @override + double transformInternal(double t) { + double start = 0.0; + double end = 1.0; + while (true) { + final double midpoint = (start + end) / 2; + final double estimate = _evaluateCubic(a, c, midpoint); + if ((t - estimate).abs() < _cubicErrorBound) { + return _evaluateCubic(b, d, midpoint); + } + if (estimate < t) { + start = midpoint; + } else { + end = midpoint; + } + } + } + + @override + String toString() { + return '${objectRuntimeType(this, 'Cubic')}(${a.toStringAsFixed(2)}, ${b.toStringAsFixed(2)}, ${c.toStringAsFixed(2)}, ${d.toStringAsFixed(2)})'; + } +} + +/// A cubic polynomial composed of two curves that share a common center point. +/// +/// The curve runs through three points: (0,0), the [midpoint], and (1,1). +/// +/// The [Curves] class contains a curve defined with this class: +/// [Curves.easeInOutCubicEmphasized]. +/// +/// The [ThreePointCubic] class implements third-order Bézier curves, where two +/// curves share an interior [midpoint] that the curve passes through. If the +/// control points surrounding the middle point ([b1], and [a2]) are not +/// colinear with the middle point, then the curve's derivative will have a +/// discontinuity (a cusp) at the shared middle point. +/// +/// See also: +/// +/// * [Curves], where many more predefined curves are available. +/// * [Cubic], which defines a single cubic polynomial. +/// * [CatmullRomCurve], a curve which passes through specific values. +class ThreePointCubic extends Curve { + /// Creates two cubic curves that share a common control point. + /// + /// Rather than creating a new instance, consider using one of the common + /// three-point cubic curves in [Curves]. + /// + /// The arguments correspond to the control points for the two curves, + /// including the [midpoint], but do not include the two implied end points at + /// (0,0) and (1,1), which are fixed. + const ThreePointCubic(this.a1, this.b1, this.midpoint, this.a2, this.b2); + + /// The coordinates of the first control point of the first curve. + /// + /// The line through the point (0, 0) and this control point is tangent to the + /// curve at the point (0, 0). + final Offset a1; + + /// The coordinates of the second control point of the first curve. + /// + /// The line through the [midpoint] and this control point is tangent to the + /// curve approaching the [midpoint]. + final Offset b1; + + /// The coordinates of the middle shared point. + /// + /// The curve will go through this point. If the control points surrounding + /// this middle point ([b1], and [a2]) are not colinear with this point, then + /// the curve's derivative will have a discontinuity (a cusp) at this point. + final Offset midpoint; + + /// The coordinates of the first control point of the second curve. + /// + /// The line through the [midpoint] and this control point is tangent to the + /// curve approaching the [midpoint]. + final Offset a2; + + /// The coordinates of the second control point of the second curve. + /// + /// The line through the point (1, 1) and this control point is tangent to the + /// curve at (1, 1). + final Offset b2; + + @override + double transformInternal(double t) { + final bool firstCurve = t < midpoint.dx; + final double scaleX = firstCurve ? midpoint.dx : 1.0 - midpoint.dx; + final double scaleY = firstCurve ? midpoint.dy : 1.0 - midpoint.dy; + final double scaledT = (t - (firstCurve ? 0.0 : midpoint.dx)) / scaleX; + if (firstCurve) { + return Cubic( + a1.dx / scaleX, + a1.dy / scaleY, + b1.dx / scaleX, + b1.dy / scaleY, + ).transform(scaledT) * scaleY; + } else { + return Cubic( + (a2.dx - midpoint.dx) / scaleX, + (a2.dy - midpoint.dy) / scaleY, + (b2.dx - midpoint.dx) / scaleX, + (b2.dy - midpoint.dy) / scaleY, + ).transform(scaledT) * scaleY + midpoint.dy; + } + } + + @override + String toString() { + return '${objectRuntimeType(this, 'ThreePointCubic($a1, $b1, $midpoint, $a2, $b2)')} '; + } +} + +/// Abstract class that defines an API for evaluating 2D parametric curves. +/// +/// [Curve2D] differs from [Curve] in that the values interpolated are [Offset] +/// values instead of [double] values, hence the "2D" in the name. They both +/// take a single double `t` that has a range of 0.0 to 1.0, inclusive, as input +/// to the [transform] function . Unlike [Curve], [Curve2D] is not required to +/// map `t=0.0` and `t=1.0` to specific output values. +/// +/// The interpolated `t` value given to [transform] represents the progression +/// along the curve, but it doesn't necessarily progress at a constant velocity, so +/// incrementing `t` by, say, 0.1 might move along the curve by quite a lot at one +/// part of the curve, or hardly at all in another part of the curve, depending +/// on the definition of the curve. +/// +/// {@tool dartpad} +/// This example shows how to use a [Curve2D] to modify the position of a widget +/// so that it can follow an arbitrary path. +/// +/// ** See code in examples/api/lib/animation/curves/curve2_d.0.dart ** +/// {@end-tool} +/// +abstract class Curve2D extends ParametricCurve { + /// Abstract const constructor to enable subclasses to provide const + /// constructors so that they can be used in const expressions. + const Curve2D(); + + /// Generates a list of samples with a recursive subdivision until a tolerance + /// of `tolerance` is reached. + /// + /// Samples are generated in order. + /// + /// Samples can be used to render a curve efficiently, since the samples + /// constitute line segments which vary in size with the curvature of the + /// curve. They can also be used to quickly approximate the value of the curve + /// by searching for the desired range in X and linearly interpolating between + /// samples to obtain an approximation of Y at the desired X value. The + /// implementation of [CatmullRomCurve] uses samples for this purpose + /// internally. + /// + /// The tolerance is computed as the area of a triangle formed by a new point + /// and the preceding and following point. + /// + /// See also: + /// + /// * Luiz Henrique de Figueire's Graphics Gem on [the algorithm](http://ariel.chronotext.org/dd/defigueiredo93adaptive.pdf). + Iterable generateSamples({ + double start = 0.0, + double end = 1.0, + double tolerance = 1e-10, + }) { + // The sampling algorithm is: + // 1. Evaluate the area of the triangle (a proxy for the "flatness" of the + // curve) formed by two points and a test point. + // 2. If the area of the triangle is small enough (below tolerance), then + // the two points form the final segment. + // 3. If the area is still too large, divide the interval into two parts + // using a random subdivision point to avoid aliasing. + // 4. Recursively sample the two parts. + // + // This algorithm concentrates samples in areas of high curvature. + assert(end > start); + // We want to pick a random seed that will keep the result stable if + // evaluated again, so we use the first non-generated control point. + final math.Random rand = math.Random(samplingSeed); + bool isFlat(Offset p, Offset q, Offset r) { + // Calculates the area of the triangle given by the three points. + final Offset pr = p - r; + final Offset qr = q - r; + final double z = pr.dx * qr.dy - qr.dx * pr.dy; + return (z * z) < tolerance; + } + + final Curve2DSample first = Curve2DSample(start, transform(start)); + final Curve2DSample last = Curve2DSample(end, transform(end)); + final List samples = [first]; + void sample(Curve2DSample p, Curve2DSample q, {bool forceSubdivide = false}) { + // Pick a random point somewhat near the center, which avoids aliasing + // problems with periodic curves. + final double t = p.t + (0.45 + 0.1 * rand.nextDouble()) * (q.t - p.t); + final Curve2DSample r = Curve2DSample(t, transform(t)); + + if (!forceSubdivide && isFlat(p.value, q.value, r.value)) { + samples.add(q); + } else { + sample(p, r); + sample(r, q); + } + } + // If the curve starts and ends on the same point, then we force it to + // subdivide at least once, because otherwise it will terminate immediately. + sample( + first, + last, + forceSubdivide: (first.value.dx - last.value.dx).abs() < tolerance && (first.value.dy - last.value.dy).abs() < tolerance, + ); + return samples; + } + + /// Returns a seed value used by [generateSamples] to seed a random number + /// generator to avoid sample aliasing. + /// + /// Subclasses should override this and provide a custom seed. + /// + /// The value returned should be the same each time it is called, unless the + /// curve definition changes. + @protected + int get samplingSeed => 0; + + /// Returns the parameter `t` that corresponds to the given x value of the spline. + /// + /// This will only work properly for curves which are single-valued in x + /// (where every value of `x` maps to only one value in 'y', i.e. the curve + /// does not loop or curve back over itself). For curves that are not + /// single-valued, it will return the parameter for only one of the values at + /// the given `x` location. + double findInverse(double x) { + double start = 0.0; + double end = 1.0; + late double mid; + double offsetToOrigin(double pos) => x - transform(pos).dx; + // Use a binary search to find the inverse point within 1e-6, or 100 + // subdivisions, whichever comes first. + const double errorLimit = 1e-6; + int count = 100; + final double startValue = offsetToOrigin(start); + while ((end - start) / 2.0 > errorLimit && count > 0) { + mid = (end + start) / 2.0; + final double value = offsetToOrigin(mid); + if (value.sign == startValue.sign) { + start = mid; + } else { + end = mid; + } + count--; + } + return mid; + } +} + +/// A class that holds a sample of a 2D parametric curve, containing the [value] +/// (the X, Y coordinates) of the curve at the parametric value [t]. +/// +/// See also: +/// +/// * [Curve2D.generateSamples], which generates samples of this type. +/// * [Curve2D], a parametric curve that maps a double parameter to a 2D location. +class Curve2DSample { + /// Creates an object that holds a sample; used with [Curve2D] subclasses. + const Curve2DSample(this.t, this.value); + + /// The parametric location of this sample point along the curve. + final double t; + + /// The value (the X, Y coordinates) of the curve at parametric value [t]. + final Offset value; + + @override + String toString() { + return '[(${value.dx.toStringAsFixed(2)}, ${value.dy.toStringAsFixed(2)}), ${t.toStringAsFixed(2)}]'; + } +} + +/// A 2D spline that passes smoothly through the given control points using a +/// centripetal Catmull-Rom spline. +/// +/// When the curve is evaluated with [transform], the output values will move +/// smoothly from one control point to the next, passing through the control +/// points. +/// +/// {@template flutter.animation.CatmullRomSpline} +/// Unlike most cubic splines, Catmull-Rom splines have the advantage that their +/// curves pass through the control points given to them. They are cubic +/// polynomial representations, and, in fact, Catmull-Rom splines can be +/// converted mathematically into cubic splines. This class implements a +/// "centripetal" Catmull-Rom spline. The term centripetal implies that it won't +/// form loops or self-intersections within a single segment. +/// {@endtemplate} +/// +/// See also: +/// * [Centripetal Catmull–Rom splines](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline) +/// on Wikipedia. +/// * [Parameterization and Applications of Catmull-Rom Curves](http://faculty.cs.tamu.edu/schaefer/research/cr_cad.pdf), +/// a paper on using Catmull-Rom splines. +/// * [CatmullRomCurve], an animation curve that uses a [CatmullRomSpline] as its +/// internal representation. +class CatmullRomSpline extends Curve2D { + /// Constructs a centripetal Catmull-Rom spline curve. + /// + /// The `controlPoints` argument is a list of four or more points that + /// describe the points that the curve must pass through. + /// + /// The optional `tension` argument controls how tightly the curve approaches + /// the given `controlPoints`. It must be in the range 0.0 to 1.0, inclusive. It + /// defaults to 0.0, which provides the smoothest curve. A value of 1.0 + /// produces a linear interpolation between points. + /// + /// The optional `endHandle` and `startHandle` points are the beginning and + /// ending handle positions. If not specified, they are created automatically + /// by extending the line formed by the first and/or last line segment in the + /// `controlPoints`, respectively. The spline will not go through these handle + /// points, but they will affect the slope of the line at the beginning and + /// end of the spline. The spline will attempt to match the slope of the line + /// formed by the start or end handle and the neighboring first or last + /// control point. The default is chosen so that the slope of the line at the + /// ends matches that of the first or last line segment in the control points. + /// + /// The `controlPoints` list must contain at least four control points to + /// interpolate. + /// + /// The internal curve data structures are lazily computed the first time + /// [transform] is called. If you would rather pre-compute the structures, + /// use [CatmullRomSpline.precompute] instead. + CatmullRomSpline( + List controlPoints, { + double tension = 0.0, + Offset? startHandle, + Offset? endHandle, + }) : assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'), + assert(tension >= 0.0, 'tension $tension must not be negative.'), + assert(controlPoints.length > 3, 'There must be at least four control points to create a CatmullRomSpline.'), + _controlPoints = controlPoints, + _startHandle = startHandle, + _endHandle = endHandle, + _tension = tension, + _cubicSegments = >[]; + + /// Constructs a centripetal Catmull-Rom spline curve. + /// + /// The same as [CatmullRomSpline.new], except that the internal data + /// structures are precomputed instead of being computed lazily. + CatmullRomSpline.precompute( + List controlPoints, { + double tension = 0.0, + Offset? startHandle, + Offset? endHandle, + }) : assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'), + assert(tension >= 0.0, 'tension $tension must not be negative.'), + assert(controlPoints.length > 3, 'There must be at least four control points to create a CatmullRomSpline.'), + _controlPoints = null, + _startHandle = null, + _endHandle = null, + _tension = null, + _cubicSegments = _computeSegments(controlPoints, tension, startHandle: startHandle, endHandle: endHandle); + + + static List> _computeSegments( + List controlPoints, + double tension, { + Offset? startHandle, + Offset? endHandle, + }) { + assert( + startHandle == null || startHandle.isFinite, + 'The provided startHandle of CatmullRomSpline must be finite. The ' + 'startHandle given was $startHandle.' + ); + assert( + endHandle == null || endHandle.isFinite, + 'The provided endHandle of CatmullRomSpline must be finite. The endHandle ' + 'given was $endHandle.' + ); + assert(() { + for (int index = 0; index < controlPoints.length; index++) { + if (!controlPoints[index].isFinite) { + throw FlutterError( + 'The provided CatmullRomSpline control point at index $index is not ' + 'finite. The control point given was ${controlPoints[index]}.' + ); + } + } + return true; + }()); + // If not specified, select the first and last control points (which are + // handles: they are not intersected by the resulting curve) so that they + // extend the first and last segments, respectively. + startHandle ??= controlPoints[0] * 2.0 - controlPoints[1]; + endHandle ??= controlPoints.last * 2.0 - controlPoints[controlPoints.length - 2]; + final List allPoints = [ + startHandle, + ...controlPoints, + endHandle, + ]; + + // An alpha of 0.5 is what makes it a centripetal Catmull-Rom spline. A + // value of 0.0 would make it a uniform Catmull-Rom spline, and a value of + // 1.0 would make it a chordal Catmull-Rom spline. Non-centripetal values + // for alpha can give self-intersecting behavior or looping within a + // segment. + const double alpha = 0.5; + final double reverseTension = 1.0 - tension; + final List> result = >[]; + for (int i = 0; i < allPoints.length - 3; ++i) { + final List curve = [allPoints[i], allPoints[i + 1], allPoints[i + 2], allPoints[i + 3]]; + final Offset diffCurve10 = curve[1] - curve[0]; + final Offset diffCurve21 = curve[2] - curve[1]; + final Offset diffCurve32 = curve[3] - curve[2]; + final double t01 = math.pow(diffCurve10.distance, alpha).toDouble(); + final double t12 = math.pow(diffCurve21.distance, alpha).toDouble(); + final double t23 = math.pow(diffCurve32.distance, alpha).toDouble(); + + final Offset m1 = (diffCurve21 + (diffCurve10 / t01 - (curve[2] - curve[0]) / (t01 + t12)) * t12) * reverseTension; + final Offset m2 = (diffCurve21 + (diffCurve32 / t23 - (curve[3] - curve[1]) / (t12 + t23)) * t12) * reverseTension; + final Offset sumM12 = m1 + m2; + + final List segment = [ + diffCurve21 * -2.0 + sumM12, + diffCurve21 * 3.0 - m1 - sumM12, + m1, + curve[1], + ]; + result.add(segment); + } + return result; + } + + // The list of control point lists for each cubic segment of the spline. + final List> _cubicSegments; + + // This is non-empty only if the _cubicSegments are being computed lazily. + final List? _controlPoints; + final Offset? _startHandle; + final Offset? _endHandle; + final double? _tension; + + void _initializeIfNeeded() { + if (_cubicSegments.isNotEmpty) { + return; + } + _cubicSegments.addAll( + _computeSegments(_controlPoints!, _tension!, startHandle: _startHandle, endHandle: _endHandle), + ); + } + + @override + @protected + int get samplingSeed { + _initializeIfNeeded(); + final Offset seedPoint = _cubicSegments[0][1]; + return ((seedPoint.dx + seedPoint.dy) * 10000).round(); + } + + @override + Offset transformInternal(double t) { + _initializeIfNeeded(); + final double length = _cubicSegments.length.toDouble(); + final double position; + final double localT; + final int index; + if (t < 1.0) { + position = t * length; + localT = position % 1.0; + index = position.floor(); + } else { + position = length; + localT = 1.0; + index = _cubicSegments.length - 1; + } + final List cubicControlPoints = _cubicSegments[index]; + final double localT2 = localT * localT; + return cubicControlPoints[0] * localT2 * localT + + cubicControlPoints[1] * localT2 + + cubicControlPoints[2] * localT + + cubicControlPoints[3]; + } +} + +/// An animation easing curve that passes smoothly through the given control +/// points using a centripetal Catmull-Rom spline. +/// +/// When this curve is evaluated with [transform], the values will interpolate +/// smoothly from one control point to the next, passing through (0.0, 0.0), the +/// given points, and then (1.0, 1.0). +/// +/// {@macro flutter.animation.CatmullRomSpline} +/// +/// This class uses a centripetal Catmull-Rom curve (a [CatmullRomSpline]) as +/// its internal representation. The term centripetal implies that it won't form +/// loops or self-intersections within a single segment, and corresponds to a +/// Catmull-Rom α (alpha) value of 0.5. +/// +/// See also: +/// +/// * [CatmullRomSpline], the 2D spline that this curve uses to generate its values. +/// * A Wikipedia article on [centripetal Catmull-Rom splines](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline). +/// * [CatmullRomCurve.new] for a description of the constraints put on the +/// input control points. +/// * This [paper on using Catmull-Rom splines](http://faculty.cs.tamu.edu/schaefer/research/cr_cad.pdf). +class CatmullRomCurve extends Curve { + /// Constructs a centripetal [CatmullRomCurve]. + /// + /// It takes a list of two or more points that describe the points that the + /// curve must pass through. See [controlPoints] for a description of the + /// restrictions placed on control points. In addition to the given + /// [controlPoints], the curve will begin with an implicit control point at + /// (0.0, 0.0) and end with an implicit control point at (1.0, 1.0), so that + /// the curve begins and ends at those points. + /// + /// The optional [tension] argument controls how tightly the curve approaches + /// the given `controlPoints`. It must be in the range 0.0 to 1.0, inclusive. It + /// defaults to 0.0, which provides the smoothest curve. A value of 1.0 + /// is equivalent to a linear interpolation between points. + /// + /// The internal curve data structures are lazily computed the first time + /// [transform] is called. If you would rather pre-compute the curve, use + /// [CatmullRomCurve.precompute] instead. + /// + /// See also: + /// + /// * This [paper on using Catmull-Rom splines](http://faculty.cs.tamu.edu/schaefer/research/cr_cad.pdf). + CatmullRomCurve(this.controlPoints, {this.tension = 0.0}) + : assert(() { + return validateControlPoints( + controlPoints, + tension: tension, + reasons: _debugAssertReasons..clear(), + ); + }(), 'control points $controlPoints could not be validated:\n ${_debugAssertReasons.join('\n ')}'), + // Pre-compute samples so that we don't have to evaluate the spline's inverse + // all the time in transformInternal. + _precomputedSamples = []; + + /// Constructs a centripetal [CatmullRomCurve]. + /// + /// Same as [CatmullRomCurve.new], but it precomputes the internal curve data + /// structures for a more predictable computation load. + CatmullRomCurve.precompute(this.controlPoints, {this.tension = 0.0}) + : assert(() { + return validateControlPoints( + controlPoints, + tension: tension, + reasons: _debugAssertReasons..clear(), + ); + }(), 'control points $controlPoints could not be validated:\n ${_debugAssertReasons.join('\n ')}'), + // Pre-compute samples so that we don't have to evaluate the spline's inverse + // all the time in transformInternal. + _precomputedSamples = _computeSamples(controlPoints, tension); + + static List _computeSamples(List controlPoints, double tension) { + return CatmullRomSpline.precompute( + // Force the first and last control points for the spline to be (0, 0) + // and (1, 1), respectively. + [Offset.zero, ...controlPoints, const Offset(1.0, 1.0)], + tension: tension, + ).generateSamples(tolerance: 1e-12).toList(); + } + + /// A static accumulator for assertion failures. Not used in release mode. + static final List _debugAssertReasons = []; + + // The precomputed approximation curve, so that evaluation of the curve is + // efficient. + // + // If the curve is constructed lazily, then this will be empty, and will be filled + // the first time transform is called. + final List _precomputedSamples; + + /// The control points used to create this curve. + /// + /// The `dx` value of each [Offset] in [controlPoints] represents the + /// animation value at which the curve should pass through the `dy` value of + /// the same control point. + /// + /// The [controlPoints] list must meet the following criteria: + /// + /// * The list must contain at least two points. + /// * The X value of each point must be greater than 0.0 and less then 1.0. + /// * The X values of each point must be greater than the + /// previous point's X value (i.e. monotonically increasing). The Y values + /// are not constrained. + /// * The resulting spline must be single-valued in X. That is, for each X + /// value, there must be exactly one Y value. This means that the control + /// points must not generated a spline that loops or overlaps itself. + /// + /// The static function [validateControlPoints] can be used to check that + /// these conditions are met, and will return true if they are. In debug mode, + /// it will also optionally return a list of reasons in text form. In debug + /// mode, the constructor will assert that these conditions are met and print + /// the reasons if the assert fires. + /// + /// When the curve is evaluated with [transform], the values will interpolate + /// smoothly from one control point to the next, passing through (0.0, 0.0), the + /// given control points, and (1.0, 1.0). + final List controlPoints; + + /// The "tension" of the curve. + /// + /// The [tension] attribute controls how tightly the curve approaches the + /// given [controlPoints]. It must be in the range 0.0 to 1.0, inclusive. It + /// is optional, and defaults to 0.0, which provides the smoothest curve. A + /// value of 1.0 is equivalent to a linear interpolation between control + /// points. + final double tension; + + /// Validates that a given set of control points for a [CatmullRomCurve] is + /// well-formed and will not produce a spline that self-intersects. + /// + /// This method is also used in debug mode to validate a curve to make sure + /// that it won't violate the contract for the [CatmullRomCurve.new] + /// constructor. + /// + /// If in debug mode, and `reasons` is non-null, this function will fill in + /// `reasons` with descriptions of the problems encountered. The `reasons` + /// argument is ignored in release mode. + /// + /// In release mode, this function can be used to decide if a proposed + /// modification to the curve will result in a valid curve. + static bool validateControlPoints( + List? controlPoints, { + double tension = 0.0, + List? reasons, + }) { + if (controlPoints == null) { + assert(() { + reasons?.add('Supplied control points cannot be null'); + return true; + }()); + return false; + } + + if (controlPoints.length < 2) { + assert(() { + reasons?.add('There must be at least two points supplied to create a valid curve.'); + return true; + }()); + return false; + } + + controlPoints = [Offset.zero, ...controlPoints, const Offset(1.0, 1.0)]; + final Offset startHandle = controlPoints[0] * 2.0 - controlPoints[1]; + final Offset endHandle = controlPoints.last * 2.0 - controlPoints[controlPoints.length - 2]; + controlPoints = [startHandle, ...controlPoints, endHandle]; + double lastX = -double.infinity; + for (int i = 0; i < controlPoints.length; ++i) { + if (i > 1 && + i < controlPoints.length - 2 && + (controlPoints[i].dx <= 0.0 || controlPoints[i].dx >= 1.0)) { + assert(() { + reasons?.add( + 'Control points must have X values between 0.0 and 1.0, exclusive. ' + 'Point $i has an x value (${controlPoints![i].dx}) which is outside the range.', + ); + return true; + }()); + return false; + } + if (controlPoints[i].dx <= lastX) { + assert(() { + reasons?.add( + 'Each X coordinate must be greater than the preceding X coordinate ' + '(i.e. must be monotonically increasing in X). Point $i has an x value of ' + '${controlPoints![i].dx}, which is not greater than $lastX', + ); + return true; + }()); + return false; + } + lastX = controlPoints[i].dx; + } + + bool success = true; + + // An empirical test to make sure things are single-valued in X. + lastX = -double.infinity; + const double tolerance = 1e-3; + final CatmullRomSpline testSpline = CatmullRomSpline(controlPoints, tension: tension); + final double start = testSpline.findInverse(0.0); + final double end = testSpline.findInverse(1.0); + final Iterable samplePoints = testSpline.generateSamples(start: start, end: end); + /// If the first and last points in the samples aren't at (0,0) or (1,1) + /// respectively, then the curve is multi-valued at the ends. + if (samplePoints.first.value.dy.abs() > tolerance || (1.0 - samplePoints.last.value.dy).abs() > tolerance) { + bool bail = true; + success = false; + assert(() { + reasons?.add( + 'The curve has more than one Y value at X = ${samplePoints.first.value.dx}. ' + 'Try moving some control points further away from this value of X, or increasing ' + 'the tension.', + ); + // No need to keep going if we're not giving reasons. + bail = reasons == null; + return true; + }()); + if (bail) { + // If we're not in debug mode, then we want to bail immediately + // instead of checking everything else. + return false; + } + } + for (final Curve2DSample sample in samplePoints) { + final Offset point = sample.value; + final double t = sample.t; + final double x = point.dx; + if (t >= start && t <= end && (x < -1e-3 || x > 1.0 + 1e-3)) { + bool bail = true; + success = false; + assert(() { + reasons?.add( + 'The resulting curve has an X value ($x) which is outside ' + 'the range [0.0, 1.0], inclusive.', + ); + // No need to keep going if we're not giving reasons. + bail = reasons == null; + return true; + }()); + if (bail) { + // If we're not in debug mode, then we want to bail immediately + // instead of checking all the segments. + return false; + } + } + if (x < lastX) { + bool bail = true; + success = false; + assert(() { + reasons?.add( + 'The curve has more than one Y value at x = $x. Try moving ' + 'some control points further apart in X, or increasing the tension.', + ); + // No need to keep going if we're not giving reasons. + bail = reasons == null; + return true; + }()); + if (bail) { + // If we're not in debug mode, then we want to bail immediately + // instead of checking all the segments. + return false; + } + } + lastX = x; + } + return success; + } + + @override + double transformInternal(double t) { + // Linearly interpolate between the two closest samples generated when the + // curve was created. + if (_precomputedSamples.isEmpty) { + // Compute the samples now if we were constructed lazily. + _precomputedSamples.addAll(_computeSamples(controlPoints, tension)); + } + int start = 0; + int end = _precomputedSamples.length - 1; + int mid; + Offset value; + Offset startValue = _precomputedSamples[start].value; + Offset endValue = _precomputedSamples[end].value; + // Use a binary search to find the index of the sample point that is just + // before t. + while (end - start > 1) { + mid = (end + start) ~/ 2; + value = _precomputedSamples[mid].value; + if (t >= value.dx) { + start = mid; + startValue = value; + } else { + end = mid; + endValue = value; + } + } + + // Now interpolate between the found sample and the next one. + final double t2 = (t - startValue.dx) / (endValue.dx - startValue.dx); + return lerpDouble(startValue.dy, endValue.dy, t2)!; + } +} + +/// A curve that is the reversed inversion of its given curve. +/// +/// This curve evaluates the given curve in reverse (i.e., from 1.0 to 0.0 as t +/// increases from 0.0 to 1.0) and returns the inverse of the given curve's +/// value (i.e., 1.0 minus the given curve's value). +/// +/// This is the class used to implement the [flipped] getter on curves. +/// +/// This is often useful with [CurvedAnimation.reverseCurve]. +/// +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_in.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_flipped.mp4} +/// +/// See also: +/// +/// * [Curve.flipped], which provides the [FlippedCurve] of a [Curve]. +/// * [ReverseAnimation], which reverses an [Animation] rather than a [Curve]. +/// * [CurvedAnimation], which can take a separate curve and reverse curve. +class FlippedCurve extends Curve { + /// Creates a flipped curve. + const FlippedCurve(this.curve); + + /// The curve that is being flipped. + final Curve curve; + + @override + double transformInternal(double t) => 1.0 - curve.transform(1.0 - t); + + @override + String toString() { + return '${objectRuntimeType(this, 'FlippedCurve')}($curve)'; + } +} + +/// A curve where the rate of change starts out quickly and then decelerates; an +/// upside-down `f(t) = t²` parabola. +/// +/// This is equivalent to the Android `DecelerateInterpolator` class with a unit +/// factor (the default factor). +/// +/// See [Curves.decelerate] for an instance of this class. +class _DecelerateCurve extends Curve { + const _DecelerateCurve._(); + + @override + double transformInternal(double t) { + // Intended to match the behavior of: + // https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/animation/DecelerateInterpolator.java + // ...as of December 2016. + t = 1.0 - t; + return 1.0 - t * t; + } +} + +// BOUNCE CURVES + +double _bounce(double t) { + if (t < 1.0 / 2.75) { + return 7.5625 * t * t; + } else if (t < 2 / 2.75) { + t -= 1.5 / 2.75; + return 7.5625 * t * t + 0.75; + } else if (t < 2.5 / 2.75) { + t -= 2.25 / 2.75; + return 7.5625 * t * t + 0.9375; + } + t -= 2.625 / 2.75; + return 7.5625 * t * t + 0.984375; +} + +/// An oscillating curve that grows in magnitude. +/// +/// See [Curves.bounceIn] for an instance of this class. +class _BounceInCurve extends Curve { + const _BounceInCurve._(); + + @override + double transformInternal(double t) { + return 1.0 - _bounce(1.0 - t); + } +} + +/// An oscillating curve that shrink in magnitude. +/// +/// See [Curves.bounceOut] for an instance of this class. +class _BounceOutCurve extends Curve { + const _BounceOutCurve._(); + + @override + double transformInternal(double t) { + return _bounce(t); + } +} + +/// An oscillating curve that first grows and then shrink in magnitude. +/// +/// See [Curves.bounceInOut] for an instance of this class. +class _BounceInOutCurve extends Curve { + const _BounceInOutCurve._(); + + @override + double transformInternal(double t) { + if (t < 0.5) { + return (1.0 - _bounce(1.0 - t * 2.0)) * 0.5; + } else { + return _bounce(t * 2.0 - 1.0) * 0.5 + 0.5; + } + } +} + + +// ELASTIC CURVES + +/// An oscillating curve that grows in magnitude while overshooting its bounds. +/// +/// An instance of this class using the default period of 0.4 is available as +/// [Curves.elasticIn]. +/// +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_elastic_in.mp4} +class ElasticInCurve extends Curve { + /// Creates an elastic-in curve. + /// + /// Rather than creating a new instance, consider using [Curves.elasticIn]. + const ElasticInCurve([this.period = 0.4]); + + /// The duration of the oscillation. + final double period; + + @override + double transformInternal(double t) { + final double s = period / 4.0; + t = t - 1.0; + return -math.pow(2.0, 10.0 * t) * math.sin((t - s) * (math.pi * 2.0) / period); + } + + @override + String toString() { + return '${objectRuntimeType(this, 'ElasticInCurve')}($period)'; + } +} + +/// An oscillating curve that shrinks in magnitude while overshooting its bounds. +/// +/// An instance of this class using the default period of 0.4 is available as +/// [Curves.elasticOut]. +/// +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_elastic_out.mp4} +class ElasticOutCurve extends Curve { + /// Creates an elastic-out curve. + /// + /// Rather than creating a new instance, consider using [Curves.elasticOut]. + const ElasticOutCurve([this.period = 0.4]); + + /// The duration of the oscillation. + final double period; + + @override + double transformInternal(double t) { + final double s = period / 4.0; + return math.pow(2.0, -10 * t) * math.sin((t - s) * (math.pi * 2.0) / period) + 1.0; + } + + @override + String toString() { + return '${objectRuntimeType(this, 'ElasticOutCurve')}($period)'; + } +} + +/// An oscillating curve that grows and then shrinks in magnitude while +/// overshooting its bounds. +/// +/// An instance of this class using the default period of 0.4 is available as +/// [Curves.elasticInOut]. +/// +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_elastic_in_out.mp4} +class ElasticInOutCurve extends Curve { + /// Creates an elastic-in-out curve. + /// + /// Rather than creating a new instance, consider using [Curves.elasticInOut]. + const ElasticInOutCurve([this.period = 0.4]); + + /// The duration of the oscillation. + final double period; + + @override + double transformInternal(double t) { + final double s = period / 4.0; + t = 2.0 * t - 1.0; + if (t < 0.0) { + return -0.5 * math.pow(2.0, 10.0 * t) * math.sin((t - s) * (math.pi * 2.0) / period); + } else { + return math.pow(2.0, -10.0 * t) * math.sin((t - s) * (math.pi * 2.0) / period) * 0.5 + 1.0; + } + } + + @override + String toString() { + return '${objectRuntimeType(this, 'ElasticInOutCurve')}($period)'; + } +} + + +// PREDEFINED CURVES + +/// A collection of common animation curves. +/// +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_in.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_in_out.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_out.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_decelerate.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_sine.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_quad.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_cubic.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_quart.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_quint.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_expo.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_circ.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_back.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_sine.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_quad.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_cubic.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_quart.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_quint.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_expo.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_circ.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_back.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_sine.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_quad.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_cubic.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_quart.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_quint.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_expo.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_circ.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_back.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_elastic_in.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_elastic_in_out.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_elastic_out.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_fast_out_slow_in.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_slow_middle.mp4} +/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_linear.mp4} +/// +/// See also: +/// +/// * [Curve], the interface implemented by the constants available from the +/// [Curves] class. +/// * [Easing], for the Material animation curves. +abstract final class Curves { + /// A linear animation curve. + /// + /// This is the identity map over the unit interval: its [Curve.transform] + /// method returns its input unmodified. This is useful as a default curve for + /// cases where a [Curve] is required but no actual curve is desired. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_linear.mp4} + static const Curve linear = _Linear._(); + + /// A curve where the rate of change starts out quickly and then decelerates; an + /// upside-down `f(t) = t²` parabola. + /// + /// This is equivalent to the Android `DecelerateInterpolator` class with a unit + /// factor (the default factor). + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_decelerate.mp4} + static const Curve decelerate = _DecelerateCurve._(); + + /// A curve that is very steep and linear at the beginning, but quickly flattens out + /// and very slowly eases in. + /// + /// By default is the curve used to animate pages on iOS back to their original + /// position if a swipe gesture is ended midway through a swipe. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_fast_linear_to_slow_ease_in.mp4} + static const Cubic fastLinearToSlowEaseIn = Cubic(0.18, 1.0, 0.04, 1.0); + + /// A curve that starts slowly, speeds up very quickly, and then ends slowly. + /// + /// This curve is used by default to animate page transitions used by + /// [CupertinoPageRoute]. + /// + /// It has been derived from plots of native iOS 16.3 + /// animation frames on iPhone 14 Pro Max. + /// Specifically, transition animation positions were measured + /// every frame and plotted against time. Then, a cubic curve was + /// strictly fit to the measured data points. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_fast_ease_in_to_slow_ease_out.mp4} + static const ThreePointCubic fastEaseInToSlowEaseOut = ThreePointCubic( + Offset(0.056, 0.024), + Offset(0.108, 0.3085), + Offset(0.198, 0.541), + Offset(0.3655, 1.0), + Offset(0.5465, 0.989), + ); + + /// A cubic animation curve that speeds up quickly and ends slowly. + /// + /// This is the same as the CSS easing function `ease`. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease.mp4} + static const Cubic ease = Cubic(0.25, 0.1, 0.25, 1.0); + + /// A cubic animation curve that starts slowly and ends quickly. + /// + /// This is the same as the CSS easing function `ease-in`. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in.mp4} + static const Cubic easeIn = Cubic(0.42, 0.0, 1.0, 1.0); + + /// A cubic animation curve that starts slowly and ends linearly. + /// + /// The symmetric animation to [linearToEaseOut]. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_to_linear.mp4} + static const Cubic easeInToLinear = Cubic(0.67, 0.03, 0.65, 0.09); + + /// A cubic animation curve that starts slowly and ends quickly. This is + /// similar to [Curves.easeIn], but with sinusoidal easing for a slightly less + /// abrupt beginning and end. Nonetheless, the result is quite gentle and is + /// hard to distinguish from [Curves.linear] at a glance. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_sine.mp4} + static const Cubic easeInSine = Cubic(0.47, 0.0, 0.745, 0.715); + + /// A cubic animation curve that starts slowly and ends quickly. Based on a + /// quadratic equation where `f(t) = t²`, this is effectively the inverse of + /// [Curves.decelerate]. + /// + /// Compared to [Curves.easeInSine], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_quad.mp4} + static const Cubic easeInQuad = Cubic(0.55, 0.085, 0.68, 0.53); + + /// A cubic animation curve that starts slowly and ends quickly. This curve is + /// based on a cubic equation where `f(t) = t³`. The result is a safe sweet + /// spot when choosing a curve for widgets animating off the viewport. + /// + /// Compared to [Curves.easeInQuad], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_cubic.mp4} + static const Cubic easeInCubic = Cubic(0.55, 0.055, 0.675, 0.19); + + /// A cubic animation curve that starts slowly and ends quickly. This curve is + /// based on a quartic equation where `f(t) = t⁴`. + /// + /// Animations using this curve or steeper curves will benefit from a longer + /// duration to avoid motion feeling unnatural. + /// + /// Compared to [Curves.easeInCubic], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_quart.mp4} + static const Cubic easeInQuart = Cubic(0.895, 0.03, 0.685, 0.22); + + /// A cubic animation curve that starts slowly and ends quickly. This curve is + /// based on a quintic equation where `f(t) = t⁵`. + /// + /// Compared to [Curves.easeInQuart], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_quint.mp4} + static const Cubic easeInQuint = Cubic(0.755, 0.05, 0.855, 0.06); + + /// A cubic animation curve that starts slowly and ends quickly. This curve is + /// based on an exponential equation where `f(t) = 2¹⁰⁽ᵗ⁻¹⁾`. + /// + /// Using this curve can give your animations extra flare, but a longer + /// duration may need to be used to compensate for the steepness of the curve. + /// + /// Compared to [Curves.easeInQuint], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_expo.mp4} + static const Cubic easeInExpo = Cubic(0.95, 0.05, 0.795, 0.035); + + /// A cubic animation curve that starts slowly and ends quickly. This curve is + /// effectively the bottom-right quarter of a circle. + /// + /// Like [Curves.easeInExpo], this curve is fairly dramatic and will reduce + /// the clarity of an animation if not given a longer duration. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_circ.mp4} + static const Cubic easeInCirc = Cubic(0.6, 0.04, 0.98, 0.335); + + /// A cubic animation curve that starts slowly and ends quickly. This curve + /// is similar to [Curves.elasticIn] in that it overshoots its bounds before + /// reaching its end. Instead of repeated swinging motions before ascending, + /// though, this curve overshoots once, then continues to ascend. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_back.mp4} + static const Cubic easeInBack = Cubic(0.6, -0.28, 0.735, 0.045); + + /// A cubic animation curve that starts quickly and ends slowly. + /// + /// This is the same as the CSS easing function `ease-out`. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out.mp4} + static const Cubic easeOut = Cubic(0.0, 0.0, 0.58, 1.0); + + /// A cubic animation curve that starts linearly and ends slowly. + /// + /// A symmetric animation to [easeInToLinear]. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_linear_to_ease_out.mp4} + static const Cubic linearToEaseOut = Cubic(0.35, 0.91, 0.33, 0.97); + + /// A cubic animation curve that starts quickly and ends slowly. This is + /// similar to [Curves.easeOut], but with sinusoidal easing for a slightly + /// less abrupt beginning and end. Nonetheless, the result is quite gentle and + /// is hard to distinguish from [Curves.linear] at a glance. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_sine.mp4} + static const Cubic easeOutSine = Cubic(0.39, 0.575, 0.565, 1.0); + + /// A cubic animation curve that starts quickly and ends slowly. This is + /// effectively the same as [Curves.decelerate], only simulated using a cubic + /// bezier function. + /// + /// Compared to [Curves.easeOutSine], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_quad.mp4} + static const Cubic easeOutQuad = Cubic(0.25, 0.46, 0.45, 0.94); + + /// A cubic animation curve that starts quickly and ends slowly. This curve is + /// a flipped version of [Curves.easeInCubic]. + /// + /// The result is a safe sweet spot when choosing a curve for animating a + /// widget's position entering or already inside the viewport. + /// + /// Compared to [Curves.easeOutQuad], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_cubic.mp4} + static const Cubic easeOutCubic = Cubic(0.215, 0.61, 0.355, 1.0); + + /// A cubic animation curve that starts quickly and ends slowly. This curve is + /// a flipped version of [Curves.easeInQuart]. + /// + /// Animations using this curve or steeper curves will benefit from a longer + /// duration to avoid motion feeling unnatural. + /// + /// Compared to [Curves.easeOutCubic], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_quart.mp4} + static const Cubic easeOutQuart = Cubic(0.165, 0.84, 0.44, 1.0); + + /// A cubic animation curve that starts quickly and ends slowly. This curve is + /// a flipped version of [Curves.easeInQuint]. + /// + /// Compared to [Curves.easeOutQuart], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_quint.mp4} + static const Cubic easeOutQuint = Cubic(0.23, 1.0, 0.32, 1.0); + + /// A cubic animation curve that starts quickly and ends slowly. This curve is + /// a flipped version of [Curves.easeInExpo]. Using this curve can give your + /// animations extra flare, but a longer duration may need to be used to + /// compensate for the steepness of the curve. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_expo.mp4} + static const Cubic easeOutExpo = Cubic(0.19, 1.0, 0.22, 1.0); + + /// A cubic animation curve that starts quickly and ends slowly. This curve is + /// effectively the top-left quarter of a circle. + /// + /// Like [Curves.easeOutExpo], this curve is fairly dramatic and will reduce + /// the clarity of an animation if not given a longer duration. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_circ.mp4} + static const Cubic easeOutCirc = Cubic(0.075, 0.82, 0.165, 1.0); + + /// A cubic animation curve that starts quickly and ends slowly. This curve is + /// similar to [Curves.elasticOut] in that it overshoots its bounds before + /// reaching its end. Instead of repeated swinging motions after ascending, + /// though, this curve only overshoots once. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_out_back.mp4} + static const Cubic easeOutBack = Cubic(0.175, 0.885, 0.32, 1.275); + + /// A cubic animation curve that starts slowly, speeds up, and then ends + /// slowly. + /// + /// This is the same as the CSS easing function `ease-in-out`. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out.mp4} + static const Cubic easeInOut = Cubic(0.42, 0.0, 0.58, 1.0); + + /// A cubic animation curve that starts slowly, speeds up, and then ends + /// slowly. This is similar to [Curves.easeInOut], but with sinusoidal easing + /// for a slightly less abrupt beginning and end. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_sine.mp4} + static const Cubic easeInOutSine = Cubic(0.445, 0.05, 0.55, 0.95); + + /// A cubic animation curve that starts slowly, speeds up, and then ends + /// slowly. This curve can be imagined as [Curves.easeInQuad] as the first + /// half, and [Curves.easeOutQuad] as the second. + /// + /// Compared to [Curves.easeInOutSine], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_quad.mp4} + static const Cubic easeInOutQuad = Cubic(0.455, 0.03, 0.515, 0.955); + + /// A cubic animation curve that starts slowly, speeds up, and then ends + /// slowly. This curve can be imagined as [Curves.easeInCubic] as the first + /// half, and [Curves.easeOutCubic] as the second. + /// + /// The result is a safe sweet spot when choosing a curve for a widget whose + /// initial and final positions are both within the viewport. + /// + /// Compared to [Curves.easeInOutQuad], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_cubic.mp4} + static const Cubic easeInOutCubic = Cubic(0.645, 0.045, 0.355, 1.0); + + /// A cubic animation curve that starts slowly, speeds up shortly thereafter, + /// and then ends slowly. This curve can be imagined as a steeper version of + /// [easeInOutCubic]. + /// + /// The result is a more emphasized eased curve when choosing a curve for a + /// widget whose initial and final positions are both within the viewport. + /// + /// Compared to [Curves.easeInOutCubic], this curve is slightly steeper. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_cubic_emphasized.mp4} + static const ThreePointCubic easeInOutCubicEmphasized = ThreePointCubic( + Offset(0.05, 0), Offset(0.133333, 0.06), + Offset(0.166666, 0.4), + Offset(0.208333, 0.82), Offset(0.25, 1), + ); + + /// A cubic animation curve that starts slowly, speeds up, and then ends + /// slowly. This curve can be imagined as [Curves.easeInQuart] as the first + /// half, and [Curves.easeOutQuart] as the second. + /// + /// Animations using this curve or steeper curves will benefit from a longer + /// duration to avoid motion feeling unnatural. + /// + /// Compared to [Curves.easeInOutCubic], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_quart.mp4} + static const Cubic easeInOutQuart = Cubic(0.77, 0.0, 0.175, 1.0); + + /// A cubic animation curve that starts slowly, speeds up, and then ends + /// slowly. This curve can be imagined as [Curves.easeInQuint] as the first + /// half, and [Curves.easeOutQuint] as the second. + /// + /// Compared to [Curves.easeInOutQuart], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_quint.mp4} + static const Cubic easeInOutQuint = Cubic(0.86, 0.0, 0.07, 1.0); + + /// A cubic animation curve that starts slowly, speeds up, and then ends + /// slowly. + /// + /// Since this curve is arrived at with an exponential function, the midpoint + /// is exceptionally steep. Extra consideration should be taken when designing + /// an animation using this. + /// + /// Compared to [Curves.easeInOutQuint], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_expo.mp4} + static const Cubic easeInOutExpo = Cubic(1.0, 0.0, 0.0, 1.0); + + /// A cubic animation curve that starts slowly, speeds up, and then ends + /// slowly. This curve can be imagined as [Curves.easeInCirc] as the first + /// half, and [Curves.easeOutCirc] as the second. + /// + /// Like [Curves.easeInOutExpo], this curve is fairly dramatic and will reduce + /// the clarity of an animation if not given a longer duration. + /// + /// Compared to [Curves.easeInOutExpo], this curve is slightly steeper. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_circ.mp4} + static const Cubic easeInOutCirc = Cubic(0.785, 0.135, 0.15, 0.86); + + /// A cubic animation curve that starts slowly, speeds up, and then ends + /// slowly. This curve can be imagined as [Curves.easeInBack] as the first + /// half, and [Curves.easeOutBack] as the second. + /// + /// Since two curves are used as a basis for this curve, the resulting + /// animation will overshoot its bounds twice before reaching its end - first + /// by exceeding its lower bound, then exceeding its upper bound and finally + /// descending to its final position. + /// + /// Derived from Robert Penner’s easing functions. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_ease_in_out_back.mp4} + static const Cubic easeInOutBack = Cubic(0.68, -0.55, 0.265, 1.55); + + /// A curve that starts quickly and eases into its final position. + /// + /// Over the course of the animation, the object spends more time near its + /// final destination. As a result, the user isn’t left waiting for the + /// animation to finish, and the negative effects of motion are minimized. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_fast_out_slow_in.mp4} + /// + /// See also: + /// + /// * [Easing.legacy], the name for this curve in the Material specification. + static const Cubic fastOutSlowIn = Cubic(0.4, 0.0, 0.2, 1.0); + + /// A cubic animation curve that starts quickly, slows down, and then ends + /// quickly. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_slow_middle.mp4} + static const Cubic slowMiddle = Cubic(0.15, 0.85, 0.85, 0.15); + + /// An oscillating curve that grows in magnitude. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_in.mp4} + static const Curve bounceIn = _BounceInCurve._(); + + /// An oscillating curve that first grows and then shrink in magnitude. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_out.mp4} + static const Curve bounceOut = _BounceOutCurve._(); + + /// An oscillating curve that first grows and then shrink in magnitude. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_in_out.mp4} + static const Curve bounceInOut = _BounceInOutCurve._(); + + /// An oscillating curve that grows in magnitude while overshooting its bounds. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_elastic_in.mp4} + static const ElasticInCurve elasticIn = ElasticInCurve(); + + /// An oscillating curve that shrinks in magnitude while overshooting its bounds. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_elastic_out.mp4} + static const ElasticOutCurve elasticOut = ElasticOutCurve(); + + /// An oscillating curve that grows and then shrinks in magnitude while overshooting its bounds. + /// + /// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_elastic_in_out.mp4} + static const ElasticInOutCurve elasticInOut = ElasticInOutCurve(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/listener_helpers.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/listener_helpers.dart new file mode 100644 index 0000000000000000000000000000000000000000..acecaa12fb6cf4b7b461b2224459efcce61c0436 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/listener_helpers.dart @@ -0,0 +1,264 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'package:flutter/foundation.dart'; + +import 'animation.dart'; + +export 'dart:ui' show VoidCallback; + +export 'animation.dart' show AnimationStatus, AnimationStatusListener; + +/// A mixin that helps listen to another object only when this object has registered listeners. +/// +/// This mixin provides implementations of [didRegisterListener] and [didUnregisterListener], +/// and therefore can be used in conjunction with mixins that require these methods, +/// [AnimationLocalListenersMixin] and [AnimationLocalStatusListenersMixin]. +mixin AnimationLazyListenerMixin { + int _listenerCounter = 0; + + /// Calls [didStartListening] every time a registration of a listener causes + /// an empty list of listeners to become non-empty. + /// + /// See also: + /// + /// * [didUnregisterListener], which may cause the listener list to + /// become empty again, and in turn cause this method to call + /// [didStartListening] again. + @protected + void didRegisterListener() { + assert(_listenerCounter >= 0); + if (_listenerCounter == 0) { + didStartListening(); + } + _listenerCounter += 1; + } + + /// Calls [didStopListening] when an only remaining listener is unregistered, + /// thus making the list empty. + /// + /// See also: + /// + /// * [didRegisterListener], which causes the listener list to become non-empty. + @protected + void didUnregisterListener() { + assert(_listenerCounter >= 1); + _listenerCounter -= 1; + if (_listenerCounter == 0) { + didStopListening(); + } + } + + /// Called when the number of listeners changes from zero to one. + @protected + void didStartListening(); + + /// Called when the number of listeners changes from one to zero. + @protected + void didStopListening(); + + /// Whether there are any listeners. + bool get isListening => _listenerCounter > 0; +} + +/// A mixin that replaces the [didRegisterListener]/[didUnregisterListener] contract +/// with a dispose contract. +/// +/// This mixin provides implementations of [didRegisterListener] and [didUnregisterListener], +/// and therefore can be used in conjunction with mixins that require these methods, +/// [AnimationLocalListenersMixin] and [AnimationLocalStatusListenersMixin]. +mixin AnimationEagerListenerMixin { + /// This implementation ignores listener registrations. + @protected + void didRegisterListener() { } + + /// This implementation ignores listener registrations. + @protected + void didUnregisterListener() { } + + /// Release the resources used by this object. The object is no longer usable + /// after this method is called. + @mustCallSuper + void dispose() { } +} + +/// A mixin that implements the [addListener]/[removeListener] protocol and notifies +/// all the registered listeners when [notifyListeners] is called. +/// +/// This mixin requires that the mixing class provide methods [didRegisterListener] +/// and [didUnregisterListener]. Implementations of these methods can be obtained +/// by mixing in another mixin from this library, such as [AnimationLazyListenerMixin]. +mixin AnimationLocalListenersMixin { + final ObserverList _listeners = ObserverList(); + + /// Called immediately before a listener is added via [addListener]. + /// + /// At the time this method is called the registered listener is not yet + /// notified by [notifyListeners]. + @protected + void didRegisterListener(); + + /// Called immediately after a listener is removed via [removeListener]. + /// + /// At the time this method is called the removed listener is no longer + /// notified by [notifyListeners]. + @protected + void didUnregisterListener(); + + /// Calls the listener every time the value of the animation changes. + /// + /// Listeners can be removed with [removeListener]. + void addListener(VoidCallback listener) { + didRegisterListener(); + _listeners.add(listener); + } + + /// Stop calling the listener every time the value of the animation changes. + /// + /// Listeners can be added with [addListener]. + void removeListener(VoidCallback listener) { + final bool removed = _listeners.remove(listener); + if (removed) { + didUnregisterListener(); + } + } + + /// Removes all listeners added with [addListener]. + /// + /// This method is typically called from the `dispose` method of the class + /// using this mixin if the class also uses the [AnimationEagerListenerMixin]. + /// + /// Calling this method will not trigger [didUnregisterListener]. + @protected + void clearListeners() { + _listeners.clear(); + } + + /// Calls all the listeners. + /// + /// If listeners are added or removed during this function, the modifications + /// will not change which listeners are called during this iteration. + @protected + @pragma('vm:notify-debugger-on-exception') + void notifyListeners() { + final List localListeners = _listeners.toList(growable: false); + for (final VoidCallback listener in localListeners) { + InformationCollector? collector; + assert(() { + collector = () => [ + DiagnosticsProperty( + 'The $runtimeType notifying listeners was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]; + return true; + }()); + try { + if (_listeners.contains(listener)) { + listener(); + } + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'animation library', + context: ErrorDescription('while notifying listeners for $runtimeType'), + informationCollector: collector, + )); + } + } + } +} + +/// A mixin that implements the addStatusListener/removeStatusListener protocol +/// and notifies all the registered listeners when notifyStatusListeners is +/// called. +/// +/// This mixin requires that the mixing class provide methods [didRegisterListener] +/// and [didUnregisterListener]. Implementations of these methods can be obtained +/// by mixing in another mixin from this library, such as [AnimationLazyListenerMixin]. +mixin AnimationLocalStatusListenersMixin { + final ObserverList _statusListeners = ObserverList(); + + /// Called immediately before a status listener is added via [addStatusListener]. + /// + /// At the time this method is called the registered listener is not yet + /// notified by [notifyStatusListeners]. + @protected + void didRegisterListener(); + + /// Called immediately after a status listener is removed via [removeStatusListener]. + /// + /// At the time this method is called the removed listener is no longer + /// notified by [notifyStatusListeners]. + @protected + void didUnregisterListener(); + + /// Calls listener every time the status of the animation changes. + /// + /// Listeners can be removed with [removeStatusListener]. + void addStatusListener(AnimationStatusListener listener) { + didRegisterListener(); + _statusListeners.add(listener); + } + + /// Stops calling the listener every time the status of the animation changes. + /// + /// Listeners can be added with [addStatusListener]. + void removeStatusListener(AnimationStatusListener listener) { + final bool removed = _statusListeners.remove(listener); + if (removed) { + didUnregisterListener(); + } + } + + /// Removes all listeners added with [addStatusListener]. + /// + /// This method is typically called from the `dispose` method of the class + /// using this mixin if the class also uses the [AnimationEagerListenerMixin]. + /// + /// Calling this method will not trigger [didUnregisterListener]. + @protected + void clearStatusListeners() { + _statusListeners.clear(); + } + + /// Calls all the status listeners. + /// + /// If listeners are added or removed during this function, the modifications + /// will not change which listeners are called during this iteration. + @protected + @pragma('vm:notify-debugger-on-exception') + void notifyStatusListeners(AnimationStatus status) { + final List localListeners = _statusListeners.toList(growable: false); + for (final AnimationStatusListener listener in localListeners) { + try { + if (_statusListeners.contains(listener)) { + listener(status); + } + } catch (exception, stack) { + InformationCollector? collector; + assert(() { + collector = () => [ + DiagnosticsProperty( + 'The $runtimeType notifying status listeners was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'animation library', + context: ErrorDescription('while notifying status listeners for $runtimeType'), + informationCollector: collector, + )); + } + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/tween.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/tween.dart new file mode 100644 index 0000000000000000000000000000000000000000..59ac6f1b0f819fa3bff9d74d1ab0a72876581e67 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/tween.dart @@ -0,0 +1,566 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show Color, Rect, Size; + +import 'package:flutter/foundation.dart'; + +import 'animations.dart'; + +export 'dart:ui' show Color, Rect, Size; + +export 'animation.dart' show Animation; +export 'curves.dart' show Curve; + +// Examples can assume: +// late Animation _animation; +// late AnimationController _controller; + +/// A typedef used by [Animatable.fromCallback] to create an [Animatable] +/// from a callback. +typedef AnimatableCallback = T Function(double value); + +/// An object that can produce a value of type `T` given an [Animation] +/// as input. +/// +/// Typically, the values of the input animation are nominally in the range 0.0 +/// to 1.0. In principle, however, any value could be provided. +/// +/// The main subclass of [Animatable] is [Tween]. +abstract class Animatable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const Animatable(); + + /// Create a new [Animatable] from the provided [callback]. + /// + /// See also: + /// + /// * [Animation.drive], which provides an example for how this can be + /// used. + const factory Animatable.fromCallback(AnimatableCallback callback) = _CallbackAnimatable; + + /// Returns the value of the object at point `t`. + /// + /// The value of `t` is nominally a fraction in the range 0.0 to 1.0, though + /// in practice it may extend outside this range. + /// + /// See also: + /// + /// * [evaluate], which is a shorthand for applying [transform] to the value + /// of an [Animation]. + /// * [Curve.transform], a similar method for easing curves. + T transform(double t); + + /// The current value of this object for the given [Animation]. + /// + /// This function is implemented by deferring to [transform]. Subclasses that + /// want to provide custom behavior should override [transform], not + /// [evaluate]. + /// + /// See also: + /// + /// * [transform], which is similar but takes a `t` value directly instead of + /// an [Animation]. + /// * [animate], which creates an [Animation] out of this object, continually + /// applying [evaluate]. + T evaluate(Animation animation) => transform(animation.value); + + /// Returns a new [Animation] that is driven by the given animation but that + /// takes on values determined by this object. + /// + /// Essentially this returns an [Animation] that automatically applies the + /// [evaluate] method to the parent's value. + /// + /// See also: + /// + /// * [AnimationController.drive], which does the same thing from the + /// opposite starting point. + Animation animate(Animation parent) { + return _AnimatedEvaluation(parent, this); + } + + /// Returns a new [Animatable] whose value is determined by first evaluating + /// the given parent and then evaluating this object. + /// + /// This allows [Tween]s to be chained before obtaining an [Animation]. + Animatable chain(Animatable parent) { + return _ChainedEvaluation(parent, this); + } +} + +// A concrete subclass of `Animatable` used by `Animatable.fromCallback`. +class _CallbackAnimatable extends Animatable { + const _CallbackAnimatable(this._callback); + + final AnimatableCallback _callback; + + @override + T transform(double t) { + return _callback(t); + } +} + +class _AnimatedEvaluation extends Animation with AnimationWithParentMixin { + _AnimatedEvaluation(this.parent, this._evaluatable); + + @override + final Animation parent; + + final Animatable _evaluatable; + + @override + T get value => _evaluatable.evaluate(parent); + + @override + String toString() { + return '$parent\u27A9$_evaluatable\u27A9$value'; + } + + @override + String toStringDetails() { + return '${super.toStringDetails()} $_evaluatable'; + } +} + +class _ChainedEvaluation extends Animatable { + _ChainedEvaluation(this._parent, this._evaluatable); + + final Animatable _parent; + final Animatable _evaluatable; + + @override + T transform(double t) { + return _evaluatable.transform(_parent.transform(t)); + } + + @override + String toString() { + return '$_parent\u27A9$_evaluatable'; + } +} + +/// A linear interpolation between a beginning and ending value. +/// +/// [Tween] is useful if you want to interpolate across a range. +/// +/// To use a [Tween] object with an animation, call the [Tween] object's +/// [animate] method and pass it the [Animation] object that you want to +/// modify. +/// +/// You can chain [Tween] objects together using the [chain] method, so that a +/// single [Animation] object is configured by multiple [Tween] objects called +/// in succession. This is different than calling the [animate] method twice, +/// which results in two separate [Animation] objects, each configured with a +/// single [Tween]. +/// +/// {@tool snippet} +/// +/// Suppose `_controller` is an [AnimationController], and we want to create an +/// [Animation] that is controlled by that controller, and save it in +/// `_animation`. Here are two possible ways of expressing this: +/// +/// ```dart +/// _animation = _controller.drive( +/// Tween( +/// begin: const Offset(100.0, 50.0), +/// end: const Offset(200.0, 300.0), +/// ), +/// ); +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// ```dart +/// _animation = Tween( +/// begin: const Offset(100.0, 50.0), +/// end: const Offset(200.0, 300.0), +/// ).animate(_controller); +/// ``` +/// {@end-tool} +/// +/// In both cases, the `_animation` variable holds an object that, over the +/// lifetime of the `_controller`'s animation, returns a value +/// (`_animation.value`) that depicts a point along the line between the two +/// offsets above. If we used a [MaterialPointArcTween] instead of a +/// [Tween] in the code above, the points would follow a pleasing curve +/// instead of a straight line, with no other changes necessary. +/// +/// ## Performance optimizations +/// +/// Tweens are mutable; specifically, their [begin] and [end] values can be +/// changed at runtime. An object created with [Animation.drive] using a [Tween] +/// will immediately honor changes to that underlying [Tween] (though the +/// listeners will only be triggered if the [Animation] is actively animating). +/// This can be used to change an animation on the fly without having to +/// recreate all the objects in the chain from the [AnimationController] to the +/// final [Tween]. +/// +/// If a [Tween]'s values are never changed, however, a further optimization can +/// be applied: the object can be stored in a `static final` variable, so that +/// the exact same instance is used whenever the [Tween] is needed. This is +/// preferable to creating an identical [Tween] afresh each time a [State.build] +/// method is called, for example. +/// +/// ## Types with special considerations +/// +/// Classes with [lerp] static methods typically have corresponding dedicated +/// [Tween] subclasses that call that method. For example, [ColorTween] uses +/// [Color.lerp] to implement the [ColorTween.lerp] method. +/// +/// Types that define `+` and `-` operators to combine values (`T + T → T` and +/// `T - T → T`) and an `*` operator to scale by multiplying with a double (`T * +/// double → T`) can be directly used with `Tween`. +/// +/// This does not extend to any type with `+`, `-`, and `*` operators. In +/// particular, [int] does not satisfy this precise contract (`int * double` +/// actually returns [num], not [int]). There are therefore two specific classes +/// that can be used to interpolate integers: +/// +/// * [IntTween], which is an approximation of a linear interpolation (using +/// [double.round]). +/// * [StepTween], which uses [double.floor] to ensure that the result is +/// never greater than it would be using if a `Tween`. +/// +/// The relevant operators on [Size] also don't fulfill this contract, so +/// [SizeTween] uses [Size.lerp]. +/// +/// In addition, some of the types that _do_ have suitable `+`, `-`, and `*` +/// operators still have dedicated [Tween] subclasses that perform the +/// interpolation in a more specialized manner. One such class is +/// [MaterialPointArcTween], which is mentioned above. The [AlignmentTween], and +/// [AlignmentGeometryTween], and [FractionalOffsetTween] are another group of +/// [Tween]s that use dedicated `lerp` methods instead of merely relying on the +/// operators (in particular, this allows them to handle null values in a more +/// useful manner). +/// +/// ## Nullability +/// +/// The [begin] and [end] fields are nullable; a [Tween] does not have to +/// have non-null values specified when it is created. +/// +/// If `T` is nullable, then [lerp] and [transform] may return null. +/// This is typically seen in the case where [begin] is null and `t` +/// is 0.0, or [end] is null and `t` is 1.0, or both are null (at any +/// `t` value). +/// +/// If `T` is not nullable, then [begin] and [end] must both be set to +/// non-null values before using [lerp] or [transform], otherwise they +/// will throw. +/// +/// ## Implementing a Tween +/// +/// To specialize this class for a new type, the subclass should implement +/// the [lerp] method (and a constructor). The other methods of this class +/// are all defined in terms of [lerp]. +class Tween extends Animatable { + /// Creates a tween. + /// + /// The [begin] and [end] properties must be non-null before the tween is + /// first used, but the arguments can be null if the values are going to be + /// filled in later. + Tween({ + this.begin, + this.end, + }); + + /// The value this variable has at the beginning of the animation. + /// + /// See the constructor for details about whether this property may be null + /// (it varies from subclass to subclass). + T? begin; + + /// The value this variable has at the end of the animation. + /// + /// See the constructor for details about whether this property may be null + /// (it varies from subclass to subclass). + T? end; + + /// Returns the value this variable has at the given animation clock value. + /// + /// The default implementation of this method uses the `+`, `-`, and `*` + /// operators on `T`. The [begin] and [end] properties must therefore be + /// non-null by the time this method is called. + /// + /// In general, however, it is possible for this to return null, especially + /// when `t`=0.0 and [begin] is null, or `t`=1.0 and [end] is null. + @protected + T lerp(double t) { + assert(begin != null); + assert(end != null); + assert(() { + // Assertions that attempt to catch common cases of tweening types + // that do not conform to the Tween requirements. + dynamic result; + try { + // ignore: avoid_dynamic_calls + result = (begin as dynamic) + ((end as dynamic) - (begin as dynamic)) * t; + result as T; + return true; + } on NoSuchMethodError { + throw FlutterError.fromParts([ + ErrorSummary('Cannot lerp between "$begin" and "$end".'), + ErrorDescription( + 'The type ${begin.runtimeType} might not fully implement `+`, `-`, and/or `*`. ' + 'See "Types with special considerations" at https://api.flutter.dev/flutter/animation/Tween-class.html ' + 'for more information.', + ), + if (begin is Color || end is Color) + ErrorHint('To lerp colors, consider ColorTween instead.') + else if (begin is Rect || end is Rect) + ErrorHint('To lerp rects, consider RectTween instead.') + else + ErrorHint( + 'There may be a dedicated "${begin.runtimeType}Tween" for this type, ' + 'or you may need to create one.', + ), + ]); + } on TypeError { + throw FlutterError.fromParts([ + ErrorSummary('Cannot lerp between "$begin" and "$end".'), + ErrorDescription( + 'The type ${begin.runtimeType} returned a ${result.runtimeType} after ' + 'multiplication with a double value. ' + 'See "Types with special considerations" at https://api.flutter.dev/flutter/animation/Tween-class.html ' + 'for more information.', + ), + if (begin is int || end is int) + ErrorHint('To lerp int values, consider IntTween or StepTween instead.') + else + ErrorHint( + 'There may be a dedicated "${begin.runtimeType}Tween" for this type, ' + 'or you may need to create one.', + ), + ]); + } + }()); + // ignore: avoid_dynamic_calls + return (begin as dynamic) + ((end as dynamic) - (begin as dynamic)) * t as T; + } + + /// Returns the interpolated value for the current value of the given animation. + /// + /// This method returns `begin` and `end` when the animation values are 0.0 or + /// 1.0, respectively. + /// + /// This function is implemented by deferring to [lerp]. Subclasses that want + /// to provide custom behavior should override [lerp], not [transform] (nor + /// [evaluate]). + /// + /// See the constructor for details about whether the [begin] and [end] + /// properties may be null when this is called. It varies from subclass to + /// subclass. + @override + T transform(double t) { + if (t == 0.0) { + return begin as T; + } + if (t == 1.0) { + return end as T; + } + return lerp(t); + } + + @override + String toString() => '${objectRuntimeType(this, 'Animatable')}($begin \u2192 $end)'; +} + +/// A [Tween] that evaluates its [parent] in reverse. +class ReverseTween extends Tween { + /// Construct a [Tween] that evaluates its [parent] in reverse. + ReverseTween(this.parent) + : super(begin: parent.end, end: parent.begin); + + /// This tween's value is the same as the parent's value evaluated in reverse. + /// + /// This tween's [begin] is the parent's [end] and its [end] is the parent's + /// [begin]. The [lerp] method returns `parent.lerp(1.0 - t)` and its + /// [evaluate] method is similar. + final Tween parent; + + @override + T lerp(double t) => parent.lerp(1.0 - t); +} + +/// An interpolation between two colors. +/// +/// This class specializes the interpolation of [Tween] to use +/// [Color.lerp]. +/// +/// The values can be null, representing no color (which is distinct to +/// transparent black, as represented by [Colors.transparent]). +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class ColorTween extends Tween { + /// Creates a [Color] tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as transparent. + /// + /// We recommend that you do not pass [Colors.transparent] as [begin] + /// or [end] if you want the effect of fading in or out of transparent. + /// Instead prefer null. [Colors.transparent] refers to black transparent and + /// thus will fade out of or into black which is likely unwanted. + ColorTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + Color? lerp(double t) => Color.lerp(begin, end, t); +} + +/// An interpolation between two sizes. +/// +/// This class specializes the interpolation of [Tween] to use +/// [Size.lerp]. +/// +/// The values can be null, representing [Size.zero]. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class SizeTween extends Tween { + /// Creates a [Size] tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as an empty size. + SizeTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + Size? lerp(double t) => Size.lerp(begin, end, t); +} + +/// An interpolation between two rectangles. +/// +/// This class specializes the interpolation of [Tween] to use +/// [Rect.lerp]. +/// +/// The values can be null, representing a zero-sized rectangle at the +/// origin ([Rect.zero]). +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class RectTween extends Tween { + /// Creates a [Rect] tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as an empty rect at the top left corner. + RectTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + Rect? lerp(double t) => Rect.lerp(begin, end, t); +} + +/// An interpolation between two integers that rounds. +/// +/// This class specializes the interpolation of [Tween] to be +/// appropriate for integers by interpolating between the given begin +/// and end values and then rounding the result to the nearest +/// integer. +/// +/// This is the closest approximation to a linear tween that is possible with an +/// integer. Compare to [StepTween] and [Tween]. +/// +/// The [begin] and [end] values must be set to non-null values before +/// calling [lerp] or [transform]. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class IntTween extends Tween { + /// Creates an int tween. + /// + /// The [begin] and [end] properties must be non-null before the tween is + /// first used, but the arguments can be null if the values are going to be + /// filled in later. + IntTween({ super.begin, super.end }); + + // The inherited lerp() function doesn't work with ints because it multiplies + // the begin and end types by a double, and int * double returns a double. + @override + int lerp(double t) => (begin! + (end! - begin!) * t).round(); +} + +/// An interpolation between two integers that floors. +/// +/// This class specializes the interpolation of [Tween] to be +/// appropriate for integers by interpolating between the given begin +/// and end values and then using [double.floor] to return the current +/// integer component, dropping the fractional component. +/// +/// This results in a value that is never greater than the equivalent +/// value from a linear double interpolation. Compare to [IntTween]. +/// +/// The [begin] and [end] values must be set to non-null values before +/// calling [lerp] or [transform]. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class StepTween extends Tween { + /// Creates an [int] tween that floors. + /// + /// The [begin] and [end] properties must be non-null before the tween is + /// first used, but the arguments can be null if the values are going to be + /// filled in later. + StepTween({ super.begin, super.end }); + + // The inherited lerp() function doesn't work with ints because it multiplies + // the begin and end types by a double, and int * double returns a double. + @override + int lerp(double t) => (begin! + (end! - begin!) * t).floor(); +} + +/// A tween with a constant value. +class ConstantTween extends Tween { + /// Create a tween whose [begin] and [end] values equal [value]. + ConstantTween(T value) : super(begin: value, end: value); + + /// This tween doesn't interpolate, it always returns the same value. + @override + T lerp(double t) => begin as T; + + @override + String toString() => '${objectRuntimeType(this, 'ConstantTween')}(value: $begin)'; +} + +/// Transforms the value of the given animation by the given curve. +/// +/// This class differs from [CurvedAnimation] in that [CurvedAnimation] applies +/// a curve to an existing [Animation] object whereas [CurveTween] can be +/// chained with another [Tween] prior to receiving the underlying [Animation]. +/// ([CurvedAnimation] also has the additional ability of having different +/// curves when the animation is going forward vs when it is going backward, +/// which can be useful in some scenarios.) +/// +/// {@tool snippet} +/// +/// The following code snippet shows how you can apply a curve to a linear +/// animation produced by an [AnimationController] `controller`: +/// +/// ```dart +/// final Animation animation = _controller.drive( +/// CurveTween(curve: Curves.ease), +/// ); +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [CurvedAnimation], for an alternative way of expressing the sample above. +/// * [AnimationController], for examples of creating and disposing of an +/// [AnimationController]. +class CurveTween extends Animatable { + /// Creates a curve tween. + CurveTween({ required this.curve }); + + /// The curve to use when transforming the value of the animation. + Curve curve; + + @override + double transform(double t) { + if (t == 0.0 || t == 1.0) { + assert(curve.transform(t).round() == t); + return t; + } + return curve.transform(t); + } + + @override + String toString() => '${objectRuntimeType(this, 'CurveTween')}(curve: $curve)'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/tween_sequence.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/tween_sequence.dart new file mode 100644 index 0000000000000000000000000000000000000000..8600ea836dbcb047d6cca2b9a44844941779078f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/animation/tween_sequence.dart @@ -0,0 +1,167 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'tween.dart'; + +export 'tween.dart' show Animatable; + +// Examples can assume: +// late AnimationController myAnimationController; + +/// Enables creating an [Animation] whose value is defined by a sequence of +/// [Tween]s. +/// +/// Each [TweenSequenceItem] has a weight that defines its percentage of the +/// animation's duration. Each tween defines the animation's value during the +/// interval indicated by its weight. +/// +/// {@tool snippet} +/// This example defines an animation that uses an easing curve to interpolate +/// between 5.0 and 10.0 during the first 40% of the animation, remains at 10.0 +/// for the next 20%, and then returns to 5.0 for the final 40%. +/// +/// ```dart +/// final Animation animation = TweenSequence( +/// >[ +/// TweenSequenceItem( +/// tween: Tween(begin: 5.0, end: 10.0) +/// .chain(CurveTween(curve: Curves.ease)), +/// weight: 40.0, +/// ), +/// TweenSequenceItem( +/// tween: ConstantTween(10.0), +/// weight: 20.0, +/// ), +/// TweenSequenceItem( +/// tween: Tween(begin: 10.0, end: 5.0) +/// .chain(CurveTween(curve: Curves.ease)), +/// weight: 40.0, +/// ), +/// ], +/// ).animate(myAnimationController); +/// ``` +/// {@end-tool} +class TweenSequence extends Animatable { + /// Construct a TweenSequence. + /// + /// The [items] parameter must be a list of one or more [TweenSequenceItem]s. + /// + /// There's a small cost associated with building a [TweenSequence] so it's + /// best to reuse one, rather than rebuilding it on every frame, when that's + /// possible. + TweenSequence(List> items) + : assert(items.isNotEmpty) { + _items.addAll(items); + + double totalWeight = 0.0; + for (final TweenSequenceItem item in _items) { + totalWeight += item.weight; + } + assert(totalWeight > 0.0); + + double start = 0.0; + for (int i = 0; i < _items.length; i += 1) { + final double end = i == _items.length - 1 ? 1.0 : start + _items[i].weight / totalWeight; + _intervals.add(_Interval(start, end)); + start = end; + } + } + + final List> _items = >[]; + final List<_Interval> _intervals = <_Interval>[]; + + T _evaluateAt(double t, int index) { + final TweenSequenceItem element = _items[index]; + final double tInterval = _intervals[index].value(t); + return element.tween.transform(tInterval); + } + + @override + T transform(double t) { + assert(t >= 0.0 && t <= 1.0); + if (t == 1.0) { + return _evaluateAt(t, _items.length - 1); + } + for (int index = 0; index < _items.length; index++) { + if (_intervals[index].contains(t)) { + return _evaluateAt(t, index); + } + } + // Should be unreachable. + throw StateError('TweenSequence.evaluate() could not find an interval for $t'); + } + + @override + String toString() => 'TweenSequence(${_items.length} items)'; +} + +/// Enables creating a flipped [Animation] whose value is defined by a sequence +/// of [Tween]s. +/// +/// This creates a [TweenSequence] that evaluates to a result that flips the +/// tween both horizontally and vertically. +/// +/// This tween sequence assumes that the evaluated result has to be a double +/// between 0.0 and 1.0. +class FlippedTweenSequence extends TweenSequence { + /// Creates a flipped [TweenSequence]. + /// + /// The [items] parameter must be a list of one or more [TweenSequenceItem]s. + /// + /// There's a small cost associated with building a `TweenSequence` so it's + /// best to reuse one, rather than rebuilding it on every frame, when that's + /// possible. + FlippedTweenSequence(super.items); + + @override + double transform(double t) => 1 - super.transform(1 - t); +} + +/// A simple holder for one element of a [TweenSequence]. +class TweenSequenceItem { + /// Construct a TweenSequenceItem. + /// + /// The [weight] must be greater than 0.0. + const TweenSequenceItem({ + required this.tween, + required this.weight, + }) : assert(weight > 0.0); + + /// Defines the value of the [TweenSequence] for the interval within the + /// animation's duration indicated by [weight] and this item's position + /// in the list of items. + /// + /// {@tool snippet} + /// + /// The value of this item can be "curved" by chaining it to a [CurveTween]. + /// For example to create a tween that eases from 0.0 to 10.0: + /// + /// ```dart + /// Tween(begin: 0.0, end: 10.0) + /// .chain(CurveTween(curve: Curves.ease)) + /// ``` + /// {@end-tool} + final Animatable tween; + + /// An arbitrary value that indicates the relative percentage of a + /// [TweenSequence] animation's duration when [tween] will be used. + /// + /// The percentage for an individual item is the item's weight divided by the + /// sum of all of the items' weights. + final double weight; +} + +class _Interval { + const _Interval(this.start, this.end) : assert(end > start); + + final double start; + final double end; + + bool contains(double t) => t >= start && t < end; + + double value(double t) => (t - start) / (end - start); + + @override + String toString() => '<$start, $end>'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/activity_indicator.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/activity_indicator.dart new file mode 100644 index 0000000000000000000000000000000000000000..b1c2e5ce62d45568adf55d06f7e6210945e2f090 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/activity_indicator.dart @@ -0,0 +1,205 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; + +const double _kDefaultIndicatorRadius = 10.0; + +// Extracted from iOS 13.2 Beta. +const Color _kActiveTickColor = CupertinoDynamicColor.withBrightness( + color: Color(0xFF3C3C44), + darkColor: Color(0xFFEBEBF5), +); + +/// An iOS-style activity indicator that spins clockwise. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=AENVH-ZqKDQ} +/// +/// {@tool dartpad} +/// This example shows how [CupertinoActivityIndicator] can be customized. +/// +/// ** See code in examples/api/lib/cupertino/activity_indicator/cupertino_activity_indicator.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * +class CupertinoActivityIndicator extends StatefulWidget { + /// Creates an iOS-style activity indicator that spins clockwise. + const CupertinoActivityIndicator({ + super.key, + this.color, + this.animating = true, + this.radius = _kDefaultIndicatorRadius, + }) : assert(radius > 0.0), + progress = 1.0; + + /// Creates a non-animated iOS-style activity indicator that displays + /// a partial count of ticks based on the value of [progress]. + /// + /// When provided, the value of [progress] must be between 0.0 (zero ticks + /// will be shown) and 1.0 (all ticks will be shown) inclusive. Defaults + /// to 1.0. + const CupertinoActivityIndicator.partiallyRevealed({ + super.key, + this.color, + this.radius = _kDefaultIndicatorRadius, + this.progress = 1.0, + }) : assert(radius > 0.0), + assert(progress >= 0.0), + assert(progress <= 1.0), + animating = false; + + /// Color of the activity indicator. + /// + /// Defaults to color extracted from native iOS. + final Color? color; + + /// Whether the activity indicator is running its animation. + /// + /// Defaults to true. + final bool animating; + + /// Radius of the spinner widget. + /// + /// Defaults to 10 pixels. Must be positive. + final double radius; + + /// Determines the percentage of spinner ticks that will be shown. Typical usage would + /// display all ticks, however, this allows for more fine-grained control such as + /// during pull-to-refresh when the drag-down action shows one tick at a time as + /// the user continues to drag down. + /// + /// Defaults to one. Must be between zero and one, inclusive. + final double progress; + + @override + State createState() => _CupertinoActivityIndicatorState(); +} + +class _CupertinoActivityIndicatorState extends State + with SingleTickerProviderStateMixin { + late AnimationController _controller; + + @override + void initState() { + super.initState(); + _controller = AnimationController( + duration: const Duration(seconds: 1), + vsync: this, + ); + + if (widget.animating) { + _controller.repeat(); + } + } + + @override + void didUpdateWidget(CupertinoActivityIndicator oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.animating != oldWidget.animating) { + if (widget.animating) { + _controller.repeat(); + } else { + _controller.stop(); + } + } + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return SizedBox( + height: widget.radius * 2, + width: widget.radius * 2, + child: CustomPaint( + painter: _CupertinoActivityIndicatorPainter( + position: _controller, + activeColor: widget.color ?? CupertinoDynamicColor.resolve(_kActiveTickColor, context), + radius: widget.radius, + progress: widget.progress, + ), + ), + ); + } +} + +const double _kTwoPI = math.pi * 2.0; + +/// Alpha values extracted from the native component (for both dark and light mode) to +/// draw the spinning ticks. +const List _kAlphaValues = [ + 47, + 47, + 47, + 47, + 72, + 97, + 122, + 147, +]; + +/// The alpha value that is used to draw the partially revealed ticks. +const int _partiallyRevealedAlpha = 147; + +class _CupertinoActivityIndicatorPainter extends CustomPainter { + _CupertinoActivityIndicatorPainter({ + required this.position, + required this.activeColor, + required this.radius, + required this.progress, + }) : tickFundamentalRRect = RRect.fromLTRBXY( + -radius / _kDefaultIndicatorRadius, + -radius / 3.0, + radius / _kDefaultIndicatorRadius, + -radius, + radius / _kDefaultIndicatorRadius, + radius / _kDefaultIndicatorRadius, + ), + super(repaint: position); + + final Animation position; + final Color activeColor; + final double radius; + final double progress; + + final RRect tickFundamentalRRect; + + @override + void paint(Canvas canvas, Size size) { + final Paint paint = Paint(); + final int tickCount = _kAlphaValues.length; + + canvas.save(); + canvas.translate(size.width / 2.0, size.height / 2.0); + + final int activeTick = (tickCount * position.value).floor(); + + for (int i = 0; i < tickCount * progress; ++i) { + final int t = (i - activeTick) % tickCount; + paint.color = activeColor + .withAlpha(progress < 1 ? _partiallyRevealedAlpha : _kAlphaValues[t]); + canvas.drawRRect(tickFundamentalRRect, paint); + canvas.rotate(_kTwoPI / tickCount); + } + + canvas.restore(); + } + + @override + bool shouldRepaint(_CupertinoActivityIndicatorPainter oldPainter) { + return oldPainter.position != position || + oldPainter.activeColor != activeColor || + oldPainter.progress != progress; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/adaptive_text_selection_toolbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/adaptive_text_selection_toolbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..da1c8bb08239bc251f0e31b28ca0815516a76918 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/adaptive_text_selection_toolbar.dart @@ -0,0 +1,234 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show defaultTargetPlatform; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'desktop_text_selection_toolbar.dart'; +import 'desktop_text_selection_toolbar_button.dart'; +import 'text_selection_toolbar.dart'; +import 'text_selection_toolbar_button.dart'; + +/// The default Cupertino context menu for text selection for the current +/// platform with the given children. +/// +/// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.platforms} +/// Builds the mobile Cupertino context menu on all mobile platforms, not just +/// iOS, and builds the desktop Cupertino context menu on all desktop platforms, +/// not just MacOS. For a widget that builds the native-looking context menu for +/// all platforms, see [AdaptiveTextSelectionToolbar]. +/// {@endtemplate} +/// +/// See also: +/// +/// * [AdaptiveTextSelectionToolbar], which does the same thing as this widget +/// but for all platforms, not just the Cupertino-styled platforms. +/// * [CupertinoAdaptiveTextSelectionToolbar.getAdaptiveButtons], which builds +/// the Cupertino button Widgets for the current platform given +/// [ContextMenuButtonItem]s. +class CupertinoAdaptiveTextSelectionToolbar extends StatelessWidget { + /// Create an instance of [CupertinoAdaptiveTextSelectionToolbar] with the + /// given [children]. + /// + /// See also: + /// + /// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.buttonItems} + /// * [CupertinoAdaptiveTextSelectionToolbar.buttonItems], which takes a list + /// of [ContextMenuButtonItem]s instead of [children] widgets. + /// {@endtemplate} + /// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editable} + /// * [CupertinoAdaptiveTextSelectionToolbar.editable], which builds the + /// default Cupertino children for an editable field. + /// {@endtemplate} + /// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editableText} + /// * [CupertinoAdaptiveTextSelectionToolbar.editableText], which builds the + /// default Cupertino children for an [EditableText]. + /// {@endtemplate} + /// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.selectable} + /// * [CupertinoAdaptiveTextSelectionToolbar.selectable], which builds the + /// Cupertino children for content that is selectable but not editable. + /// {@endtemplate} + const CupertinoAdaptiveTextSelectionToolbar({ + super.key, + required this.children, + required this.anchors, + }) : buttonItems = null; + + /// Create an instance of [CupertinoAdaptiveTextSelectionToolbar] whose + /// children will be built from the given [buttonItems]. + /// + /// See also: + /// + /// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.new} + /// * [CupertinoAdaptiveTextSelectionToolbar.new], which takes the children + /// directly as a list of widgets. + /// {@endtemplate} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editable} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editableText} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.selectable} + const CupertinoAdaptiveTextSelectionToolbar.buttonItems({ + super.key, + required this.buttonItems, + required this.anchors, + }) : children = null; + + /// Create an instance of [CupertinoAdaptiveTextSelectionToolbar] with the + /// default children for an editable field. + /// + /// If a callback is null, then its corresponding button will not be built. + /// + /// See also: + /// + /// * [AdaptiveTextSelectionToolbar.editable], which is similar to this but + /// includes Material and Cupertino toolbars. + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.new} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editableText} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.buttonItems} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.selectable} + CupertinoAdaptiveTextSelectionToolbar.editable({ + super.key, + required ClipboardStatus clipboardStatus, + required VoidCallback? onCopy, + required VoidCallback? onCut, + required VoidCallback? onPaste, + required VoidCallback? onSelectAll, + required VoidCallback? onLookUp, + required VoidCallback? onSearchWeb, + required VoidCallback? onShare, + required VoidCallback? onLiveTextInput, + required this.anchors, + }) : children = null, + buttonItems = EditableText.getEditableButtonItems( + clipboardStatus: clipboardStatus, + onCopy: onCopy, + onCut: onCut, + onPaste: onPaste, + onSelectAll: onSelectAll, + onLookUp: onLookUp, + onSearchWeb: onSearchWeb, + onShare: onShare, + onLiveTextInput: onLiveTextInput + ); + + /// Create an instance of [CupertinoAdaptiveTextSelectionToolbar] with the + /// default children for an [EditableText]. + /// + /// See also: + /// + /// * [AdaptiveTextSelectionToolbar.editableText], which is similar to this + /// but includes Material and Cupertino toolbars. + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.new} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editable} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.buttonItems} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.selectable} + CupertinoAdaptiveTextSelectionToolbar.editableText({ + super.key, + required EditableTextState editableTextState, + }) : children = null, + buttonItems = editableTextState.contextMenuButtonItems, + anchors = editableTextState.contextMenuAnchors; + + /// Create an instance of [CupertinoAdaptiveTextSelectionToolbar] with the + /// default children for selectable, but not editable, content. + /// + /// See also: + /// + /// * [AdaptiveTextSelectionToolbar.selectable], which is similar to this but + /// includes Material and Cupertino toolbars. + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.new} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.buttonItems} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editable} + /// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editableText} + CupertinoAdaptiveTextSelectionToolbar.selectable({ + super.key, + required VoidCallback onCopy, + required VoidCallback onSelectAll, + required SelectionGeometry selectionGeometry, + required this.anchors, + }) : children = null, + buttonItems = SelectableRegion.getSelectableButtonItems( + selectionGeometry: selectionGeometry, + onCopy: onCopy, + onSelectAll: onSelectAll, + ); + + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.anchors} + final TextSelectionToolbarAnchors anchors; + + /// The children of the toolbar, typically buttons. + final List? children; + + /// The [ContextMenuButtonItem]s that will be turned into the correct button + /// widgets for the current platform. + final List? buttonItems; + + /// Returns a List of Widgets generated by turning [buttonItems] into the + /// default context menu buttons for Cupertino on the current platform. + /// + /// This is useful when building a text selection toolbar with the default + /// button appearance for the given platform, but where the toolbar and/or the + /// button actions and labels may be custom. + /// + /// Does not build Material buttons. On non-Apple platforms, Cupertino buttons + /// will still be used, because the Cupertino library does not access the + /// Material library. To get the native-looking buttons on every platform, + /// use [AdaptiveTextSelectionToolbar.getAdaptiveButtons] in the Material + /// library. + /// + /// See also: + /// + /// * [AdaptiveTextSelectionToolbar.getAdaptiveButtons], which is the Material + /// equivalent of this class and builds only the Material buttons. It + /// includes a live example of using `getAdaptiveButtons`. + static Iterable getAdaptiveButtons(BuildContext context, List buttonItems) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + return buttonItems.map((ContextMenuButtonItem buttonItem) { + return CupertinoTextSelectionToolbarButton.buttonItem( + buttonItem: buttonItem, + ); + }); + case TargetPlatform.linux: + case TargetPlatform.windows: + case TargetPlatform.macOS: + return buttonItems.map((ContextMenuButtonItem buttonItem) { + return CupertinoDesktopTextSelectionToolbarButton.buttonItem( + buttonItem: buttonItem, + ); + }); + } + } + + @override + Widget build(BuildContext context) { + // If there aren't any buttons to build, build an empty toolbar. + if ((children?.isEmpty ?? false) || (buttonItems?.isEmpty ?? false)) { + return const SizedBox.shrink(); + } + + final List resultChildren = children + ?? getAdaptiveButtons(context, buttonItems!).toList(); + + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + case TargetPlatform.fuchsia: + return CupertinoTextSelectionToolbar( + anchorAbove: anchors.primaryAnchor, + anchorBelow: anchors.secondaryAnchor ?? anchors.primaryAnchor, + children: resultChildren, + ); + case TargetPlatform.linux: + case TargetPlatform.windows: + case TargetPlatform.macOS: + return CupertinoDesktopTextSelectionToolbar( + anchor: anchors.primaryAnchor, + children: resultChildren, + ); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/app.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/app.dart new file mode 100644 index 0000000000000000000000000000000000000000..f68ffc92bcd0923a74f15bada75ebadf88cfb794 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/app.dart @@ -0,0 +1,632 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'button.dart'; +import 'colors.dart'; +import 'icons.dart'; +import 'interface_level.dart'; +import 'localizations.dart'; +import 'route.dart'; +import 'scrollbar.dart'; +import 'theme.dart'; + +/// An application that uses Cupertino design. +/// +/// A convenience widget that wraps a number of widgets that are commonly +/// required for an iOS-design targeting application. It builds upon a +/// [WidgetsApp] by iOS specific defaulting such as fonts and scrolling +/// physics. +/// +/// The [CupertinoApp] configures the top-level [Navigator] to search for routes +/// in the following order: +/// +/// 1. For the `/` route, the [home] property, if non-null, is used. +/// +/// 2. Otherwise, the [routes] table is used, if it has an entry for the route. +/// +/// 3. Otherwise, [onGenerateRoute] is called, if provided. It should return a +/// non-null value for any _valid_ route not handled by [home] and [routes]. +/// +/// 4. Finally if all else fails [onUnknownRoute] is called. +/// +/// If [home], [routes], [onGenerateRoute], and [onUnknownRoute] are all null, +/// and [builder] is not null, then no [Navigator] is created. +/// +/// This widget also configures the observer of the top-level [Navigator] (if +/// any) to perform [Hero] animations. +/// +/// The [CupertinoApp] widget isn't a required ancestor for other Cupertino +/// widgets, but many Cupertino widgets could depend on the [CupertinoTheme] +/// widget, which the [CupertinoApp] composes. If you use Material widgets, a +/// [MaterialApp] also creates the needed dependencies for Cupertino widgets. +/// +/// {@template flutter.cupertino.CupertinoApp.defaultSelectionStyle} +/// The [CupertinoApp] automatically creates a [DefaultSelectionStyle] with +/// selectionColor sets to [CupertinoThemeData.primaryColor] with 0.2 opacity +/// and cursorColor sets to [CupertinoThemeData.primaryColor]. +/// {@endtemplate} +/// +/// Use this widget with caution on Android since it may produce behaviors +/// Android users are not expecting such as: +/// +/// * Pages will be dismissible via a back swipe. +/// * Scrolling past extremities will trigger iOS-style spring overscrolls. +/// * The San Francisco font family is unavailable on Android and can result +/// in undefined font behavior. +/// +/// {@tool snippet} +/// This example shows how to create a [CupertinoApp] that disables the "debug" +/// banner with a [home] route that will be displayed when the app is launched. +/// +/// ![The CupertinoApp displays a CupertinoPageScaffold](https://flutter.github.io/assets-for-api-docs/assets/cupertino/basic_cupertino_app.png) +/// +/// ```dart +/// const CupertinoApp( +/// home: CupertinoPageScaffold( +/// navigationBar: CupertinoNavigationBar( +/// middle: Text('Home'), +/// ), +/// child: Center(child: Icon(CupertinoIcons.share)), +/// ), +/// debugShowCheckedModeBanner: false, +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// This example shows how to create a [CupertinoApp] that uses the [routes] +/// `Map` to define the "home" route and an "about" route. +/// +/// ```dart +/// CupertinoApp( +/// routes: { +/// '/': (BuildContext context) { +/// return const CupertinoPageScaffold( +/// navigationBar: CupertinoNavigationBar( +/// middle: Text('Home Route'), +/// ), +/// child: Center(child: Icon(CupertinoIcons.share)), +/// ); +/// }, +/// '/about': (BuildContext context) { +/// return const CupertinoPageScaffold( +/// navigationBar: CupertinoNavigationBar( +/// middle: Text('About Route'), +/// ), +/// child: Center(child: Icon(CupertinoIcons.share)), +/// ); +/// } +/// }, +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// This example shows how to create a [CupertinoApp] that defines a [theme] that +/// will be used for Cupertino widgets in the app. +/// +/// ![The CupertinoApp displays a CupertinoPageScaffold with orange-colored icons](https://flutter.github.io/assets-for-api-docs/assets/cupertino/theme_cupertino_app.png) +/// +/// ```dart +/// const CupertinoApp( +/// theme: CupertinoThemeData( +/// brightness: Brightness.dark, +/// primaryColor: CupertinoColors.systemOrange, +/// ), +/// home: CupertinoPageScaffold( +/// navigationBar: CupertinoNavigationBar( +/// middle: Text('CupertinoApp Theme'), +/// ), +/// child: Center(child: Icon(CupertinoIcons.share)), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoPageScaffold], which provides a standard page layout default +/// with nav bars. +/// * [Navigator], which is used to manage the app's stack of pages. +/// * [CupertinoPageRoute], which defines an app page that transitions in an +/// iOS-specific way. +/// * [WidgetsApp], which defines the basic app elements but does not depend +/// on the Cupertino library. +class CupertinoApp extends StatefulWidget { + /// Creates a CupertinoApp. + /// + /// At least one of [home], [routes], [onGenerateRoute], or [builder] must be + /// non-null. If only [routes] is given, it must include an entry for the + /// [Navigator.defaultRouteName] (`/`), since that is the route used when the + /// application is launched with an intent that specifies an otherwise + /// unsupported route. + /// + /// This class creates an instance of [WidgetsApp]. + const CupertinoApp({ + super.key, + this.navigatorKey, + this.home, + this.theme, + Map this.routes = const {}, + this.initialRoute, + this.onGenerateRoute, + this.onGenerateInitialRoutes, + this.onUnknownRoute, + this.onNavigationNotification, + List this.navigatorObservers = const [], + this.builder, + this.title = '', + this.onGenerateTitle, + this.color, + this.locale, + this.localizationsDelegates, + this.localeListResolutionCallback, + this.localeResolutionCallback, + this.supportedLocales = const [Locale('en', 'US')], + this.showPerformanceOverlay = false, + this.checkerboardRasterCacheImages = false, + this.checkerboardOffscreenLayers = false, + this.showSemanticsDebugger = false, + this.debugShowCheckedModeBanner = true, + this.shortcuts, + this.actions, + this.restorationScopeId, + this.scrollBehavior, + @Deprecated( + 'Remove this parameter as it is now ignored. ' + 'CupertinoApp never introduces its own MediaQuery; the View widget takes care of that. ' + 'This feature was deprecated after v3.7.0-29.0.pre.' + ) + this.useInheritedMediaQuery = false, + }) : routeInformationProvider = null, + routeInformationParser = null, + routerDelegate = null, + backButtonDispatcher = null, + routerConfig = null; + + /// Creates a [CupertinoApp] that uses the [Router] instead of a [Navigator]. + /// + /// {@macro flutter.widgets.WidgetsApp.router} + const CupertinoApp.router({ + super.key, + this.routeInformationProvider, + this.routeInformationParser, + this.routerDelegate, + this.backButtonDispatcher, + this.routerConfig, + this.theme, + this.builder, + this.title = '', + this.onGenerateTitle, + this.onNavigationNotification, + this.color, + this.locale, + this.localizationsDelegates, + this.localeListResolutionCallback, + this.localeResolutionCallback, + this.supportedLocales = const [Locale('en', 'US')], + this.showPerformanceOverlay = false, + this.checkerboardRasterCacheImages = false, + this.checkerboardOffscreenLayers = false, + this.showSemanticsDebugger = false, + this.debugShowCheckedModeBanner = true, + this.shortcuts, + this.actions, + this.restorationScopeId, + this.scrollBehavior, + @Deprecated( + 'Remove this parameter as it is now ignored. ' + 'CupertinoApp never introduces its own MediaQuery; the View widget takes care of that. ' + 'This feature was deprecated after v3.7.0-29.0.pre.' + ) + this.useInheritedMediaQuery = false, + }) : assert(routerDelegate != null || routerConfig != null), + navigatorObservers = null, + navigatorKey = null, + onGenerateRoute = null, + home = null, + onGenerateInitialRoutes = null, + onUnknownRoute = null, + routes = null, + initialRoute = null; + + /// {@macro flutter.widgets.widgetsApp.navigatorKey} + final GlobalKey? navigatorKey; + + /// {@macro flutter.widgets.widgetsApp.home} + final Widget? home; + + /// The top-level [CupertinoTheme] styling. + /// + /// A null [theme] or unspecified [theme] attributes will default to iOS + /// system values. + final CupertinoThemeData? theme; + + /// The application's top-level routing table. + /// + /// When a named route is pushed with [Navigator.pushNamed], the route name is + /// looked up in this map. If the name is present, the associated + /// [widgets.WidgetBuilder] is used to construct a [CupertinoPageRoute] that + /// performs an appropriate transition, including [Hero] animations, to the + /// new route. + /// + /// {@macro flutter.widgets.widgetsApp.routes} + final Map? routes; + + /// {@macro flutter.widgets.widgetsApp.initialRoute} + final String? initialRoute; + + /// {@macro flutter.widgets.widgetsApp.onGenerateRoute} + final RouteFactory? onGenerateRoute; + + /// {@macro flutter.widgets.widgetsApp.onGenerateInitialRoutes} + final InitialRouteListFactory? onGenerateInitialRoutes; + + /// {@macro flutter.widgets.widgetsApp.onUnknownRoute} + final RouteFactory? onUnknownRoute; + + /// {@macro flutter.widgets.widgetsApp.onNavigationNotification} + final NotificationListenerCallback? onNavigationNotification; + + /// {@macro flutter.widgets.widgetsApp.navigatorObservers} + final List? navigatorObservers; + + /// {@macro flutter.widgets.widgetsApp.routeInformationProvider} + final RouteInformationProvider? routeInformationProvider; + + /// {@macro flutter.widgets.widgetsApp.routeInformationParser} + final RouteInformationParser? routeInformationParser; + + /// {@macro flutter.widgets.widgetsApp.routerDelegate} + final RouterDelegate? routerDelegate; + + /// {@macro flutter.widgets.widgetsApp.backButtonDispatcher} + final BackButtonDispatcher? backButtonDispatcher; + + /// {@macro flutter.widgets.widgetsApp.routerConfig} + final RouterConfig? routerConfig; + + /// {@macro flutter.widgets.widgetsApp.builder} + final TransitionBuilder? builder; + + /// {@macro flutter.widgets.widgetsApp.title} + /// + /// This value is passed unmodified to [WidgetsApp.title]. + final String title; + + /// {@macro flutter.widgets.widgetsApp.onGenerateTitle} + /// + /// This value is passed unmodified to [WidgetsApp.onGenerateTitle]. + final GenerateAppTitle? onGenerateTitle; + + /// {@macro flutter.widgets.widgetsApp.color} + final Color? color; + + /// {@macro flutter.widgets.widgetsApp.locale} + final Locale? locale; + + /// {@macro flutter.widgets.widgetsApp.localizationsDelegates} + final Iterable>? localizationsDelegates; + + /// {@macro flutter.widgets.widgetsApp.localeListResolutionCallback} + /// + /// This callback is passed along to the [WidgetsApp] built by this widget. + final LocaleListResolutionCallback? localeListResolutionCallback; + + /// {@macro flutter.widgets.LocaleResolutionCallback} + /// + /// This callback is passed along to the [WidgetsApp] built by this widget. + final LocaleResolutionCallback? localeResolutionCallback; + + /// {@macro flutter.widgets.widgetsApp.supportedLocales} + /// + /// It is passed along unmodified to the [WidgetsApp] built by this widget. + final Iterable supportedLocales; + + /// Turns on a performance overlay. + /// + /// See also: + /// + /// * + final bool showPerformanceOverlay; + + /// Turns on checkerboarding of raster cache images. + final bool checkerboardRasterCacheImages; + + /// Turns on checkerboarding of layers rendered to offscreen bitmaps. + final bool checkerboardOffscreenLayers; + + /// Turns on an overlay that shows the accessibility information + /// reported by the framework. + final bool showSemanticsDebugger; + + /// {@macro flutter.widgets.widgetsApp.debugShowCheckedModeBanner} + final bool debugShowCheckedModeBanner; + + /// {@macro flutter.widgets.widgetsApp.shortcuts} + /// {@tool snippet} + /// This example shows how to add a single shortcut for + /// [LogicalKeyboardKey.select] to the default shortcuts without needing to + /// add your own [Shortcuts] widget. + /// + /// Alternatively, you could insert a [Shortcuts] widget with just the mapping + /// you want to add between the [WidgetsApp] and its child and get the same + /// effect. + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return WidgetsApp( + /// shortcuts: { + /// ... WidgetsApp.defaultShortcuts, + /// const SingleActivator(LogicalKeyboardKey.select): const ActivateIntent(), + /// }, + /// color: const Color(0xFFFF0000), + /// builder: (BuildContext context, Widget? child) { + /// return const Placeholder(); + /// }, + /// ); + /// } + /// ``` + /// {@end-tool} + /// {@macro flutter.widgets.widgetsApp.shortcuts.seeAlso} + final Map? shortcuts; + + /// {@macro flutter.widgets.widgetsApp.actions} + /// {@tool snippet} + /// This example shows how to add a single action handling an + /// [ActivateAction] to the default actions without needing to + /// add your own [Actions] widget. + /// + /// Alternatively, you could insert a [Actions] widget with just the mapping + /// you want to add between the [WidgetsApp] and its child and get the same + /// effect. + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return WidgetsApp( + /// actions: >{ + /// ... WidgetsApp.defaultActions, + /// ActivateAction: CallbackAction( + /// onInvoke: (Intent intent) { + /// // Do something here... + /// return null; + /// }, + /// ), + /// }, + /// color: const Color(0xFFFF0000), + /// builder: (BuildContext context, Widget? child) { + /// return const Placeholder(); + /// }, + /// ); + /// } + /// ``` + /// {@end-tool} + /// {@macro flutter.widgets.widgetsApp.actions.seeAlso} + final Map>? actions; + + /// {@macro flutter.widgets.widgetsApp.restorationScopeId} + final String? restorationScopeId; + + /// {@macro flutter.material.materialApp.scrollBehavior} + /// + /// When null, defaults to [CupertinoScrollBehavior]. + /// + /// See also: + /// + /// * [ScrollConfiguration], which controls how [Scrollable] widgets behave + /// in a subtree. + final ScrollBehavior? scrollBehavior; + + /// {@macro flutter.widgets.widgetsApp.useInheritedMediaQuery} + @Deprecated( + 'This setting is now ignored. ' + 'CupertinoApp never introduces its own MediaQuery; the View widget takes care of that. ' + 'This feature was deprecated after v3.7.0-29.0.pre.' + ) + final bool useInheritedMediaQuery; + + @override + State createState() => _CupertinoAppState(); + + /// The [HeroController] used for Cupertino page transitions. + /// + /// Used by [CupertinoTabView] and [CupertinoApp]. + static HeroController createCupertinoHeroController() => + HeroController(); // Linear tweening. +} + +/// Describes how [Scrollable] widgets behave for [CupertinoApp]s. +/// +/// {@macro flutter.widgets.scrollBehavior} +/// +/// Setting a [CupertinoScrollBehavior] will result in descendant [Scrollable] widgets +/// using [BouncingScrollPhysics] by default. No [GlowingOverscrollIndicator] is +/// applied when using a [CupertinoScrollBehavior] either, regardless of platform. +/// When executing on desktop platforms, a [CupertinoScrollbar] is applied to the child. +/// +/// See also: +/// +/// * [ScrollBehavior], the default scrolling behavior extended by this class. +class CupertinoScrollBehavior extends ScrollBehavior { + /// Creates a CupertinoScrollBehavior that uses [BouncingScrollPhysics] and + /// adds [CupertinoScrollbar]s on desktop platforms. + const CupertinoScrollBehavior(); + + @override + Widget buildScrollbar(BuildContext context , Widget child, ScrollableDetails details) { + // When modifying this function, consider modifying the implementation in + // the base class as well. + switch (getPlatform(context)) { + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + assert(details.controller != null); + return CupertinoScrollbar( + controller: details.controller, + child: child, + ); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + return child; + } + } + + @override + Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) { + // No overscroll indicator. + // When modifying this function, consider modifying the implementation in + // the base class as well. + return child; + } + + @override + ScrollPhysics getScrollPhysics(BuildContext context) { + // When modifying this function, consider modifying the implementation in + // the base class ScrollBehavior as well. + if (getPlatform(context) == TargetPlatform.macOS) { + return const BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast); + } + return const BouncingScrollPhysics(); + } +} + +class _CupertinoAppState extends State { + late HeroController _heroController; + bool get _usesRouter => widget.routerDelegate != null || widget.routerConfig != null; + + @override + void initState() { + super.initState(); + _heroController = CupertinoApp.createCupertinoHeroController(); + } + + @override + void dispose() { + _heroController.dispose(); + super.dispose(); + } + + // Combine the default localization for Cupertino with the ones contributed + // by the localizationsDelegates parameter, if any. Only the first delegate + // of a particular LocalizationsDelegate.type is loaded so the + // localizationsDelegate parameter can be used to override + // _CupertinoLocalizationsDelegate. + Iterable> get _localizationsDelegates { + return >[ + if (widget.localizationsDelegates != null) + ...widget.localizationsDelegates!, + DefaultCupertinoLocalizations.delegate, + ]; + } + + Widget _inspectorSelectButtonBuilder(BuildContext context, VoidCallback onPressed) { + return CupertinoButton.filled( + padding: EdgeInsets.zero, + onPressed: onPressed, + child: const Icon( + CupertinoIcons.search, + size: 28.0, + color: CupertinoColors.white, + ), + ); + } + + WidgetsApp _buildWidgetApp(BuildContext context) { + final CupertinoThemeData effectiveThemeData = CupertinoTheme.of(context); + final Color color = CupertinoDynamicColor.resolve(widget.color ?? effectiveThemeData.primaryColor, context); + + if (_usesRouter) { + return WidgetsApp.router( + key: GlobalObjectKey(this), + routeInformationProvider: widget.routeInformationProvider, + routeInformationParser: widget.routeInformationParser, + routerDelegate: widget.routerDelegate, + routerConfig: widget.routerConfig, + backButtonDispatcher: widget.backButtonDispatcher, + builder: widget.builder, + title: widget.title, + onGenerateTitle: widget.onGenerateTitle, + textStyle: effectiveThemeData.textTheme.textStyle, + color: color, + locale: widget.locale, + localizationsDelegates: _localizationsDelegates, + localeResolutionCallback: widget.localeResolutionCallback, + localeListResolutionCallback: widget.localeListResolutionCallback, + supportedLocales: widget.supportedLocales, + showPerformanceOverlay: widget.showPerformanceOverlay, + checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages, + checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers, + showSemanticsDebugger: widget.showSemanticsDebugger, + debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner, + inspectorSelectButtonBuilder: _inspectorSelectButtonBuilder, + shortcuts: widget.shortcuts, + actions: widget.actions, + restorationScopeId: widget.restorationScopeId, + ); + } + + return WidgetsApp( + key: GlobalObjectKey(this), + navigatorKey: widget.navigatorKey, + navigatorObservers: widget.navigatorObservers!, + pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) { + return CupertinoPageRoute(settings: settings, builder: builder); + }, + home: widget.home, + routes: widget.routes!, + initialRoute: widget.initialRoute, + onGenerateRoute: widget.onGenerateRoute, + onGenerateInitialRoutes: widget.onGenerateInitialRoutes, + onUnknownRoute: widget.onUnknownRoute, + onNavigationNotification: widget.onNavigationNotification, + builder: widget.builder, + title: widget.title, + onGenerateTitle: widget.onGenerateTitle, + textStyle: effectiveThemeData.textTheme.textStyle, + color: color, + locale: widget.locale, + localizationsDelegates: _localizationsDelegates, + localeResolutionCallback: widget.localeResolutionCallback, + localeListResolutionCallback: widget.localeListResolutionCallback, + supportedLocales: widget.supportedLocales, + showPerformanceOverlay: widget.showPerformanceOverlay, + checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages, + checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers, + showSemanticsDebugger: widget.showSemanticsDebugger, + debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner, + inspectorSelectButtonBuilder: _inspectorSelectButtonBuilder, + shortcuts: widget.shortcuts, + actions: widget.actions, + restorationScopeId: widget.restorationScopeId, + ); + } + + @override + Widget build(BuildContext context) { + final CupertinoThemeData effectiveThemeData = (widget.theme ?? const CupertinoThemeData()).resolveFrom(context); + + return ScrollConfiguration( + behavior: widget.scrollBehavior ?? const CupertinoScrollBehavior(), + child: CupertinoUserInterfaceLevel( + data: CupertinoUserInterfaceLevelData.base, + child: CupertinoTheme( + data: effectiveThemeData, + child: DefaultSelectionStyle( + selectionColor: effectiveThemeData.primaryColor.withOpacity(0.2), + cursorColor: effectiveThemeData.primaryColor, + child: HeroControllerScope( + controller: _heroController, + child: Builder( + builder: _buildWidgetApp, + ), + ), + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..6dd1bf37864044783f9eff232666778d1a0330d6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart @@ -0,0 +1,310 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show ImageFilter; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'localizations.dart'; +import 'theme.dart'; + +// Standard iOS 10 tab bar height. +const double _kTabBarHeight = 50.0; + +const Color _kDefaultTabBarBorderColor = CupertinoDynamicColor.withBrightness( + color: Color(0x4D000000), + darkColor: Color(0x29000000), +); +const Color _kDefaultTabBarInactiveColor = CupertinoColors.inactiveGray; + +/// An iOS-styled bottom navigation tab bar. +/// +/// Displays multiple tabs using [BottomNavigationBarItem] with one tab being +/// active, the first tab by default. +/// +/// This [StatelessWidget] doesn't store the active tab itself. You must +/// listen to the [onTap] callbacks and call `setState` with a new [currentIndex] +/// for the new selection to reflect. This can also be done automatically +/// by wrapping this with a [CupertinoTabScaffold]. +/// +/// Tab changes typically trigger a switch between [Navigator]s, each with its +/// own navigation stack, per standard iOS design. This can be done by using +/// [CupertinoTabView]s inside each tab builder in [CupertinoTabScaffold]. +/// +/// If the given [backgroundColor]'s opacity is not 1.0 (which is the case by +/// default), it will produce a blurring effect to the content behind it. +/// +/// When used as [CupertinoTabScaffold.tabBar], by default [CupertinoTabBar] +/// disables text scaling to match the native iOS behavior. To override +/// this behavior, wrap each of the `navigationBar`'s components inside a +/// [MediaQuery] with the desired [TextScaler]. +/// +/// {@tool dartpad} +/// This example shows a [CupertinoTabBar] placed in a [CupertinoTabScaffold]. +/// +/// ** See code in examples/api/lib/cupertino/bottom_tab_bar/cupertino_tab_bar.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoTabScaffold], which hosts the [CupertinoTabBar] at the bottom. +/// * [BottomNavigationBarItem], an item in a [CupertinoTabBar]. +/// * +class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { + /// Creates a tab bar in the iOS style. + const CupertinoTabBar({ + super.key, + required this.items, + this.onTap, + this.currentIndex = 0, + this.backgroundColor, + this.activeColor, + this.inactiveColor = _kDefaultTabBarInactiveColor, + this.iconSize = 30.0, + this.height = _kTabBarHeight, + this.border = const Border( + top: BorderSide( + color: _kDefaultTabBarBorderColor, + width: 0.0, // 0.0 means one physical pixel + ), + ), + }) : assert( + items.length >= 2, + "Tabs need at least 2 items to conform to Apple's HIG", + ), + assert(0 <= currentIndex && currentIndex < items.length), + assert(height >= 0.0); + + /// The interactive items laid out within the bottom navigation bar. + final List items; + + /// The callback that is called when a item is tapped. + /// + /// The widget creating the bottom navigation bar needs to keep track of the + /// current index and call `setState` to rebuild it with the newly provided + /// index. + final ValueChanged? onTap; + + /// The index into [items] of the current active item. + /// + /// Must be between 0 and the number of tabs minus 1, inclusive. + final int currentIndex; + + /// The background color of the tab bar. If it contains transparency, the + /// tab bar will automatically produce a blurring effect to the content + /// behind it. + /// + /// Defaults to [CupertinoTheme]'s `barBackgroundColor` when null. + final Color? backgroundColor; + + /// The foreground color of the icon and title for the [BottomNavigationBarItem] + /// of the selected tab. + /// + /// Defaults to [CupertinoTheme]'s `primaryColor` if null. + final Color? activeColor; + + /// The foreground color of the icon and title for the [BottomNavigationBarItem]s + /// in the unselected state. + /// + /// Defaults to a [CupertinoDynamicColor] that matches the disabled foreground + /// color of the native `UITabBar` component. + final Color inactiveColor; + + /// The size of all of the [BottomNavigationBarItem] icons. + /// + /// This value is used to configure the [IconTheme] for the navigation bar. + /// When a [BottomNavigationBarItem.icon] widget is not an [Icon] the widget + /// should configure itself to match the icon theme's size and color. + final double iconSize; + + /// The height of the [CupertinoTabBar]. + /// + /// Defaults to 50. + final double height; + + /// The border of the [CupertinoTabBar]. + /// + /// The default value is a one physical pixel top border with grey color. + final Border? border; + + @override + Size get preferredSize => Size.fromHeight(height); + + /// Indicates whether the tab bar is fully opaque or can have contents behind + /// it show through it. + bool opaque(BuildContext context) { + final Color backgroundColor = + this.backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor; + return CupertinoDynamicColor.resolve(backgroundColor, context).alpha == 0xFF; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final double bottomPadding = MediaQuery.viewPaddingOf(context).bottom; + + final Color backgroundColor = CupertinoDynamicColor.resolve( + this.backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor, + context, + ); + + BorderSide resolveBorderSide(BorderSide side) { + return side == BorderSide.none + ? side + : side.copyWith(color: CupertinoDynamicColor.resolve(side.color, context)); + } + + // Return the border as is when it's a subclass. + final Border? resolvedBorder = border == null || border.runtimeType != Border + ? border + : Border( + top: resolveBorderSide(border!.top), + left: resolveBorderSide(border!.left), + bottom: resolveBorderSide(border!.bottom), + right: resolveBorderSide(border!.right), + ); + + final Color inactive = CupertinoDynamicColor.resolve(inactiveColor, context); + Widget result = DecoratedBox( + decoration: BoxDecoration( + border: resolvedBorder, + color: backgroundColor, + ), + child: SizedBox( + height: height + bottomPadding, + child: IconTheme.merge( // Default with the inactive state. + data: IconThemeData(color: inactive, size: iconSize), + child: DefaultTextStyle( // Default with the inactive state. + style: CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(color: inactive), + child: Padding( + padding: EdgeInsets.only(bottom: bottomPadding), + child: Semantics( + explicitChildNodes: true, + child: Row( + // Align bottom since we want the labels to be aligned. + crossAxisAlignment: CrossAxisAlignment.end, + children: _buildTabItems(context), + ), + ), + ), + ), + ), + ), + ); + + if (!opaque(context)) { + // For non-opaque backgrounds, apply a blur effect. + result = ClipRect( + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), + child: result, + ), + ); + } + + return result; + } + + List _buildTabItems(BuildContext context) { + final List result = []; + final CupertinoLocalizations localizations = CupertinoLocalizations.of(context); + + for (int index = 0; index < items.length; index += 1) { + final bool active = index == currentIndex; + result.add( + _wrapActiveItem( + context, + Expanded( + // Make tab items part of the EditableText tap region so that + // switching tabs doesn't unfocus text fields. + child: TextFieldTapRegion( + child: Semantics( + selected: active, + hint: localizations.tabSemanticsLabel( + tabIndex: index + 1, + tabCount: items.length, + ), + child: MouseRegion( + cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: onTap == null ? null : () { onTap!(index); }, + child: Padding( + padding: const EdgeInsets.only(bottom: 4.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: _buildSingleTabItem(items[index], active), + ), + ), + ), + ), + ), + ), + ), + active: active, + ), + ); + } + + return result; + } + + List _buildSingleTabItem(BottomNavigationBarItem item, bool active) { + return [ + Expanded( + child: Center(child: active ? item.activeIcon : item.icon), + ), + if (item.label != null) Text(item.label!), + ]; + } + + /// Change the active tab item's icon and title colors to active. + Widget _wrapActiveItem(BuildContext context, Widget item, { required bool active }) { + if (!active) { + return item; + } + + final Color activeColor = CupertinoDynamicColor.resolve( + this.activeColor ?? CupertinoTheme.of(context).primaryColor, + context, + ); + return IconTheme.merge( + data: IconThemeData(color: activeColor), + child: DefaultTextStyle.merge( + style: TextStyle(color: activeColor), + child: item, + ), + ); + } + + /// Create a clone of the current [CupertinoTabBar] but with provided + /// parameters overridden. + CupertinoTabBar copyWith({ + Key? key, + List? items, + Color? backgroundColor, + Color? activeColor, + Color? inactiveColor, + double? iconSize, + double? height, + Border? border, + int? currentIndex, + ValueChanged? onTap, + }) { + return CupertinoTabBar( + key: key ?? this.key, + items: items ?? this.items, + backgroundColor: backgroundColor ?? this.backgroundColor, + activeColor: activeColor ?? this.activeColor, + inactiveColor: inactiveColor ?? this.inactiveColor, + iconSize: iconSize ?? this.iconSize, + height: height ?? this.height, + border: border ?? this.border, + currentIndex: currentIndex ?? this.currentIndex, + onTap: onTap ?? this.onTap, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/button.dart new file mode 100644 index 0000000000000000000000000000000000000000..73c90d01f1c2576e5c0cfd61733860330637ed43 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/button.dart @@ -0,0 +1,294 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'constants.dart'; +import 'theme.dart'; + +// Measured against iOS 12 in Xcode. +const EdgeInsets _kButtonPadding = EdgeInsets.all(16.0); +const EdgeInsets _kBackgroundButtonPadding = EdgeInsets.symmetric( + vertical: 14.0, + horizontal: 64.0, +); + +/// An iOS-style button. +/// +/// Takes in a text or an icon that fades out and in on touch. May optionally have a +/// background. +/// +/// The [padding] defaults to 16.0 pixels. When using a [CupertinoButton] within +/// a fixed height parent, like a [CupertinoNavigationBar], a smaller, or even +/// [EdgeInsets.zero], should be used to prevent clipping larger [child] +/// widgets. +/// +/// {@tool dartpad} +/// This sample shows produces an enabled and disabled [CupertinoButton] and +/// [CupertinoButton.filled]. +/// +/// ** See code in examples/api/lib/cupertino/button/cupertino_button.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * +class CupertinoButton extends StatefulWidget { + /// Creates an iOS-style button. + const CupertinoButton({ + super.key, + required this.child, + this.padding, + this.color, + this.disabledColor = CupertinoColors.quaternarySystemFill, + this.minSize = kMinInteractiveDimensionCupertino, + this.pressedOpacity = 0.4, + this.borderRadius = const BorderRadius.all(Radius.circular(8.0)), + this.alignment = Alignment.center, + required this.onPressed, + }) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)), + _filled = false; + + /// Creates an iOS-style button with a filled background. + /// + /// The background color is derived from the [CupertinoTheme]'s `primaryColor`. + /// + /// To specify a custom background color, use the [color] argument of the + /// default constructor. + const CupertinoButton.filled({ + super.key, + required this.child, + this.padding, + this.disabledColor = CupertinoColors.quaternarySystemFill, + this.minSize = kMinInteractiveDimensionCupertino, + this.pressedOpacity = 0.4, + this.borderRadius = const BorderRadius.all(Radius.circular(8.0)), + this.alignment = Alignment.center, + required this.onPressed, + }) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)), + color = null, + _filled = true; + + /// The widget below this widget in the tree. + /// + /// Typically a [Text] widget. + final Widget child; + + /// The amount of space to surround the child inside the bounds of the button. + /// + /// Defaults to 16.0 pixels. + final EdgeInsetsGeometry? padding; + + /// The color of the button's background. + /// + /// Defaults to null which produces a button with no background or border. + /// + /// Defaults to the [CupertinoTheme]'s `primaryColor` when the + /// [CupertinoButton.filled] constructor is used. + final Color? color; + + /// The color of the button's background when the button is disabled. + /// + /// Ignored if the [CupertinoButton] doesn't also have a [color]. + /// + /// Defaults to [CupertinoColors.quaternarySystemFill] when [color] is + /// specified. + final Color disabledColor; + + /// The callback that is called when the button is tapped or otherwise activated. + /// + /// If this is set to null, the button will be disabled. + final VoidCallback? onPressed; + + /// Minimum size of the button. + /// + /// Defaults to kMinInteractiveDimensionCupertino which the iOS Human + /// Interface Guidelines recommends as the minimum tappable area. + final double? minSize; + + /// The opacity that the button will fade to when it is pressed. + /// The button will have an opacity of 1.0 when it is not pressed. + /// + /// This defaults to 0.4. If null, opacity will not change on pressed if using + /// your own custom effects is desired. + final double? pressedOpacity; + + /// The radius of the button's corners when it has a background color. + /// + /// Defaults to round corners of 8 logical pixels. + final BorderRadius? borderRadius; + + /// The alignment of the button's [child]. + /// + /// Typically buttons are sized to be just big enough to contain the child and its + /// [padding]. If the button's size is constrained to a fixed size, for example by + /// enclosing it with a [SizedBox], this property defines how the child is aligned + /// within the available space. + /// + /// Always defaults to [Alignment.center]. + final AlignmentGeometry alignment; + + final bool _filled; + + /// Whether the button is enabled or disabled. Buttons are disabled by default. To + /// enable a button, set its [onPressed] property to a non-null value. + bool get enabled => onPressed != null; + + @override + State createState() => _CupertinoButtonState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('enabled', value: enabled, ifFalse: 'disabled')); + } +} + +class _CupertinoButtonState extends State with SingleTickerProviderStateMixin { + // Eyeballed values. Feel free to tweak. + static const Duration kFadeOutDuration = Duration(milliseconds: 120); + static const Duration kFadeInDuration = Duration(milliseconds: 180); + final Tween _opacityTween = Tween(begin: 1.0); + + late AnimationController _animationController; + late Animation _opacityAnimation; + + @override + void initState() { + super.initState(); + _animationController = AnimationController( + duration: const Duration(milliseconds: 200), + value: 0.0, + vsync: this, + ); + _opacityAnimation = _animationController + .drive(CurveTween(curve: Curves.decelerate)) + .drive(_opacityTween); + _setTween(); + } + + @override + void didUpdateWidget(CupertinoButton old) { + super.didUpdateWidget(old); + _setTween(); + } + + void _setTween() { + _opacityTween.end = widget.pressedOpacity ?? 1.0; + } + + @override + void dispose() { + _animationController.dispose(); + super.dispose(); + } + + bool _buttonHeldDown = false; + + void _handleTapDown(TapDownDetails event) { + if (!_buttonHeldDown) { + _buttonHeldDown = true; + _animate(); + } + } + + void _handleTapUp(TapUpDetails event) { + if (_buttonHeldDown) { + _buttonHeldDown = false; + _animate(); + } + } + + void _handleTapCancel() { + if (_buttonHeldDown) { + _buttonHeldDown = false; + _animate(); + } + } + + void _animate() { + if (_animationController.isAnimating) { + return; + } + final bool wasHeldDown = _buttonHeldDown; + final TickerFuture ticker = _buttonHeldDown + ? _animationController.animateTo(1.0, duration: kFadeOutDuration, curve: Curves.easeInOutCubicEmphasized) + : _animationController.animateTo(0.0, duration: kFadeInDuration, curve: Curves.easeOutCubic); + ticker.then((void value) { + if (mounted && wasHeldDown != _buttonHeldDown) { + _animate(); + } + }); + } + + @override + Widget build(BuildContext context) { + final bool enabled = widget.enabled; + final CupertinoThemeData themeData = CupertinoTheme.of(context); + final Color primaryColor = themeData.primaryColor; + final Color? backgroundColor = widget.color == null + ? (widget._filled ? primaryColor : null) + : CupertinoDynamicColor.maybeResolve(widget.color, context); + + final Color foregroundColor = backgroundColor != null + ? themeData.primaryContrastingColor + : enabled + ? primaryColor + : CupertinoDynamicColor.resolve(CupertinoColors.placeholderText, context); + + final TextStyle textStyle = themeData.textTheme.textStyle.copyWith(color: foregroundColor); + + return MouseRegion( + cursor: enabled && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTapDown: enabled ? _handleTapDown : null, + onTapUp: enabled ? _handleTapUp : null, + onTapCancel: enabled ? _handleTapCancel : null, + onTap: widget.onPressed, + child: Semantics( + button: true, + child: ConstrainedBox( + constraints: widget.minSize == null + ? const BoxConstraints() + : BoxConstraints( + minWidth: widget.minSize!, + minHeight: widget.minSize!, + ), + child: FadeTransition( + opacity: _opacityAnimation, + child: DecoratedBox( + decoration: BoxDecoration( + borderRadius: widget.borderRadius, + color: backgroundColor != null && !enabled + ? CupertinoDynamicColor.resolve(widget.disabledColor, context) + : backgroundColor, + ), + child: Padding( + padding: widget.padding ?? (backgroundColor != null + ? _kBackgroundButtonPadding + : _kButtonPadding), + child: Align( + alignment: widget.alignment, + widthFactor: 1.0, + heightFactor: 1.0, + child: DefaultTextStyle( + style: textStyle, + child: IconTheme( + data: IconThemeData(color: foregroundColor), + child: widget.child, + ), + ), + ), + ), + ), + ), + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/checkbox.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/checkbox.dart new file mode 100644 index 0000000000000000000000000000000000000000..b0ba4ce741b0d279c67fa7c232ac7d97e8450e41 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/checkbox.dart @@ -0,0 +1,394 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'constants.dart'; +import 'toggleable.dart'; + +// Examples can assume: +// bool _throwShotAway = false; +// late StateSetter setState; + +// The relative values needed to transform a color to it's equivalent focus +// outline color. +const double _kCupertinoFocusColorOpacity = 0.80; +const double _kCupertinoFocusColorBrightness = 0.69; +const double _kCupertinoFocusColorSaturation = 0.835; + +/// A macOS style checkbox. +/// +/// The checkbox itself does not maintain any state. Instead, when the state of +/// the checkbox changes, the widget calls the [onChanged] callback. Most +/// widgets that use a checkbox will listen for the [onChanged] callback and +/// rebuild the checkbox with a new [value] to update the visual appearance of +/// the checkbox. +/// +/// The checkbox can optionally display three values - true, false, and null - +/// if [tristate] is true. When [value] is null a dash is displayed. By default +/// [tristate] is false and the checkbox's [value] must be true or false. +/// +/// In the Apple Human Interface Guidelines (HIG), checkboxes are encouraged for +/// use on macOS, but is silent about their use on iOS. If a multi-selection +/// component is needed on iOS, the HIG encourages the developer to use switches +/// ([CupertinoSwitch] in Flutter) instead, or to find a creative custom +/// solution. +/// +/// See also: +/// +/// * [Checkbox], the Material Design equivalent. +/// * [CupertinoSwitch], a widget with semantics similar to [CupertinoCheckbox]. +/// * [CupertinoSlider], for selecting a value in a range. +/// * +class CupertinoCheckbox extends StatefulWidget { + /// Creates a macOS-styled checkbox. + /// + /// The checkbox itself does not maintain any state. Instead, when the state of + /// the checkbox changes, the widget calls the [onChanged] callback. Most + /// widgets that use a checkbox will listen for the [onChanged] callback and + /// rebuild the checkbox with a new [value] to update the visual appearance of + /// the checkbox. + /// + /// The following arguments are required: + /// + /// * [value], which determines whether the checkbox is checked. The [value] + /// can only be null if [tristate] is true. + /// * [onChanged], which is called when the value of the checkbox should + /// change. It can be set to null to disable the checkbox. + const CupertinoCheckbox({ + super.key, + required this.value, + this.tristate = false, + required this.onChanged, + this.activeColor, + this.inactiveColor, + this.checkColor, + this.focusColor, + this.focusNode, + this.autofocus = false, + this.side, + this.shape, + }) : assert(tristate || value != null); + + /// Whether this checkbox is checked. + /// + /// When [tristate] is true, a value of null corresponds to the mixed state. + /// When [tristate] is false, this value must not be null. This is asserted in + /// debug mode. + final bool? value; + + /// Called when the value of the checkbox should change. + /// + /// The checkbox passes the new value to the callback but does not actually + /// change state until the parent widget rebuilds the checkbox with the new + /// value. + /// + /// If this callback is null, the checkbox will be displayed as disabled + /// and will not respond to input gestures. + /// + /// When the checkbox is tapped, if [tristate] is false (the default) then + /// the [onChanged] callback will be applied to `!value`. If [tristate] is + /// true this callback cycle from false to true to null and back to false + /// again. + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// CupertinoCheckbox( + /// value: _throwShotAway, + /// onChanged: (bool? newValue) { + /// setState(() { + /// _throwShotAway = newValue!; + /// }); + /// }, + /// ) + /// ``` + final ValueChanged? onChanged; + + /// The color to use when this checkbox is checked. + /// + /// Defaults to [CupertinoColors.activeBlue]. + final Color? activeColor; + + /// The color used if the checkbox is inactive. + /// + /// By default, [CupertinoColors.inactiveGray] is used. + final Color? inactiveColor; + + /// The color to use for the check icon when this checkbox is checked. + /// + /// If null, then the value of [CupertinoColors.white] is used. + final Color? checkColor; + + /// If true, the checkbox's [value] can be true, false, or null. + /// + /// [CupertinoCheckbox] displays a dash when its value is null. + /// + /// When a tri-state checkbox ([tristate] is true) is tapped, its [onChanged] + /// callback will be applied to true if the current value is false, to null if + /// value is true, and to false if value is null (i.e. it cycles through false + /// => true => null => false when tapped). + /// + /// If tristate is false (the default), [value] must not be null, and + /// [onChanged] will only toggle between true and false. + final bool tristate; + + /// The color for the checkbox's border shadow when it has the input focus. + /// + /// If null, then a paler form of the [activeColor] will be used. + final Color? focusColor; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// The color and width of the checkbox's border. + /// + /// If this property is null, then the side defaults to a one pixel wide + /// black, solid border. + final BorderSide? side; + + /// The shape of the checkbox. + /// + /// If this property is null then the shape defaults to a + /// [RoundedRectangleBorder] with a circular corner radius of 4.0. + final OutlinedBorder? shape; + + /// The width of a checkbox widget. + static const double width = 18.0; + + @override + State createState() => _CupertinoCheckboxState(); +} + +class _CupertinoCheckboxState extends State with TickerProviderStateMixin, ToggleableStateMixin { + final _CheckboxPainter _painter = _CheckboxPainter(); + bool? _previousValue; + + bool focused = false; + + @override + void initState() { + super.initState(); + _previousValue = widget.value; + } + + @override + void didUpdateWidget(CupertinoCheckbox oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.value != widget.value) { + _previousValue = oldWidget.value; + } + } + + @override + void dispose() { + _painter.dispose(); + super.dispose(); + } + + @override + ValueChanged? get onChanged => widget.onChanged; + + @override + bool get tristate => widget.tristate; + + @override + bool? get value => widget.value; + + void onFocusChange(bool value) { + if (focused != value) { + focused = value; + } + } + + @override + Widget build(BuildContext context) { + final Color effectiveActiveColor = widget.activeColor + ?? CupertinoColors.activeBlue; + final Color? inactiveColor = widget.inactiveColor; + final Color effectiveInactiveColor = inactiveColor + ?? CupertinoColors.inactiveGray; + + final Color effectiveFocusOverlayColor = widget.focusColor + ?? HSLColor + .fromColor(effectiveActiveColor.withOpacity(_kCupertinoFocusColorOpacity)) + .withLightness(_kCupertinoFocusColorBrightness) + .withSaturation(_kCupertinoFocusColorSaturation) + .toColor(); + + final Color effectiveCheckColor = widget.checkColor + ?? CupertinoColors.white; + + return Semantics( + checked: widget.value ?? false, + mixed: widget.tristate ? widget.value == null : null, + child: buildToggleable( + focusNode: widget.focusNode, + autofocus: widget.autofocus, + onFocusChange: onFocusChange, + size: const Size.square(kMinInteractiveDimensionCupertino), + painter: _painter + ..focusColor = effectiveFocusOverlayColor + ..isFocused = focused + ..downPosition = downPosition + ..activeColor = effectiveActiveColor + ..inactiveColor = effectiveInactiveColor + ..checkColor = effectiveCheckColor + ..value = value + ..previousValue = _previousValue + ..isActive = widget.onChanged != null + ..shape = widget.shape ?? RoundedRectangleBorder( + borderRadius: BorderRadius.circular(4.0), + ) + ..side = widget.side, + ), + ); + } +} + +class _CheckboxPainter extends ToggleablePainter { + Color get checkColor => _checkColor!; + Color? _checkColor; + set checkColor(Color value) { + if (_checkColor == value) { + return; + } + _checkColor = value; + notifyListeners(); + } + + bool? get value => _value; + bool? _value; + set value(bool? value) { + if (_value == value) { + return; + } + _value = value; + notifyListeners(); + } + + bool? get previousValue => _previousValue; + bool? _previousValue; + set previousValue(bool? value) { + if (_previousValue == value) { + return; + } + _previousValue = value; + notifyListeners(); + } + + OutlinedBorder get shape => _shape!; + OutlinedBorder? _shape; + set shape(OutlinedBorder value) { + if (_shape == value) { + return; + } + _shape = value; + notifyListeners(); + } + + BorderSide? get side => _side; + BorderSide? _side; + set side(BorderSide? value) { + if (_side == value) { + return; + } + _side = value; + notifyListeners(); + } + + Rect _outerRectAt(Offset origin) { + const double size = CupertinoCheckbox.width; + final Rect rect = Rect.fromLTWH(origin.dx, origin.dy, size, size); + return rect; + } + + // The checkbox's border color if value == false, or its fill color when + // value == true or null. + Color _colorAt(bool value) { + return value && isActive ? activeColor : inactiveColor; + } + + // White stroke used to paint the check and dash. + Paint _createStrokePaint() { + return Paint() + ..color = checkColor + ..style = PaintingStyle.stroke + ..strokeWidth = 2.5 + ..strokeCap = StrokeCap.round; + } + + void _drawBox(Canvas canvas, Rect outer, Paint paint, BorderSide? side, bool fill) { + if (fill) { + canvas.drawPath(shape.getOuterPath(outer), paint); + } + if (side != null) { + shape.copyWith(side: side).paint(canvas, outer); + } + } + + void _drawCheck(Canvas canvas, Offset origin, Paint paint) { + final Path path = Path(); + // The ratios for the offsets below were found from looking at the checkbox + // examples on in the HIG docs. The distance from the needed point to the + // edge was measured, then divided by the total width. + const Offset start = Offset(CupertinoCheckbox.width * 0.25, CupertinoCheckbox.width * 0.52); + const Offset mid = Offset(CupertinoCheckbox.width * 0.46, CupertinoCheckbox.width * 0.75); + const Offset end = Offset(CupertinoCheckbox.width * 0.72, CupertinoCheckbox.width * 0.29); + path.moveTo(origin.dx + start.dx, origin.dy + start.dy); + path.lineTo(origin.dx + mid.dx, origin.dy + mid.dy); + canvas.drawPath(path, paint); + path.moveTo(origin.dx + mid.dx, origin.dy + mid.dy); + path.lineTo(origin.dx + end.dx, origin.dy + end.dy); + canvas.drawPath(path, paint); + } + + void _drawDash(Canvas canvas, Offset origin, Paint paint) { + // From measuring the checkbox example in the HIG docs, the dash was found + // to be half the total width, centered in the middle. + const Offset start = Offset(CupertinoCheckbox.width * 0.25, CupertinoCheckbox.width * 0.5); + const Offset end = Offset(CupertinoCheckbox.width * 0.75, CupertinoCheckbox.width * 0.5); + canvas.drawLine(origin + start, origin + end, paint); + } + + @override + void paint(Canvas canvas, Size size) { + final Paint strokePaint = _createStrokePaint(); + final Offset origin = size / 2.0 - const Size.square(CupertinoCheckbox.width) / 2.0 as Offset; + + final Rect outer = _outerRectAt(origin); + final Paint paint = Paint()..color = _colorAt(value ?? true); + + if (value == false) { + + final BorderSide border = side ?? BorderSide(color: paint.color); + _drawBox(canvas, outer, paint, border, false); + } else { + + _drawBox(canvas, outer, paint, side, true); + if (value ?? false) { + _drawCheck(canvas, origin, strokePaint); + } else { + _drawDash(canvas, origin, strokePaint); + } + } + + if (isFocused) { + final Rect focusOuter = outer.inflate(1); + + final Paint borderPaint = Paint() + ..color = focusColor + ..style = PaintingStyle.stroke + ..strokeWidth = 3.5; + + _drawBox(canvas, focusOuter, borderPaint, side, true); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/colors.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/colors.dart new file mode 100644 index 0000000000000000000000000000000000000000..e103a14c0e5ef2cae83d17cdaac66e4208a11781 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/colors.dart @@ -0,0 +1,1184 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show Brightness, Color; + +import '../../foundation.dart'; +import '../widgets/basic.dart'; +import '../widgets/framework.dart'; +import '../widgets/media_query.dart'; +import 'interface_level.dart'; +import 'theme.dart'; + +// Examples can assume: +// late Widget child; +// late BuildContext context; + +/// A palette of [Color] constants that describe colors commonly used when +/// matching the iOS platform aesthetics. +/// +/// ## Color palettes +/// +/// ### Basic Colors +/// ![](https://flutter.github.io/assets-for-api-docs/assets/cupertino/cupertino_basic_colors.png) +/// +/// ### Active Colors +/// ![](https://flutter.github.io/assets-for-api-docs/assets/cupertino/cupertino_active_colors.png) +/// +/// ### System Colors +/// ![](https://flutter.github.io/assets-for-api-docs/assets/cupertino/cupertino_system_colors_1.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/cupertino/cupertino_system_colors_2.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/cupertino/cupertino_system_colors_3.png) +/// +/// ### Label Colors +/// ![](https://flutter.github.io/assets-for-api-docs/assets/cupertino/cupertino_label_colors.png) +/// +/// ### Background Colors +/// ![](https://flutter.github.io/assets-for-api-docs/assets/cupertino/cupertino_background_colors.png) +/// +abstract final class CupertinoColors { + /// iOS 13's default blue color. Used to indicate active elements such as + /// buttons, selected tabs and your own chat bubbles. + /// + /// This is SystemBlue in the iOS palette. + static const CupertinoDynamicColor activeBlue = systemBlue; + + /// iOS 13's default green color. Used to indicate active accents such as + /// the switch in its on state and some accent buttons such as the call button + /// and Apple Map's 'Go' button. + /// + /// This is SystemGreen in the iOS palette. + static const CupertinoDynamicColor activeGreen = systemGreen; + + /// iOS 13's orange color. + /// + /// This is SystemOrange in the iOS palette. + static const CupertinoDynamicColor activeOrange = systemOrange; + + /// Opaque white color. Used for backgrounds and fonts against dark backgrounds. + /// + /// This is SystemWhiteColor in the iOS palette. + /// + /// See also: + /// + /// * [material.Colors.white], the same color, in the Material Design palette. + /// * [black], opaque black in the [CupertinoColors] palette. + static const Color white = Color(0xFFFFFFFF); + + /// Opaque black color. Used for texts against light backgrounds. + /// + /// This is SystemBlackColor in the iOS palette. + /// + /// See also: + /// + /// * [material.Colors.black], the same color, in the Material Design palette. + /// * [white], opaque white in the [CupertinoColors] palette. + static const Color black = Color(0xFF000000); + + /// Used in iOS 10 for light background fills such as the chat bubble background. + /// + /// This is SystemLightGrayColor in the iOS palette. + static const Color lightBackgroundGray = Color(0xFFE5E5EA); + + /// Used in iOS 12 for very light background fills in tables between cell groups. + /// + /// This is SystemExtraLightGrayColor in the iOS palette. + static const Color extraLightBackgroundGray = Color(0xFFEFEFF4); + + /// Used in iOS 12 for very dark background fills in tables between cell groups + /// in dark mode. + // Value derived from screenshot from the dark themed Apple Watch app. + static const Color darkBackgroundGray = Color(0xFF171717); + + /// Used in iOS 13 for unselected selectables such as tab bar items in their + /// inactive state or de-emphasized subtitles and details text. + /// + /// Not the same grey as disabled buttons etc. + /// + /// This is the disabled color in the iOS palette. + static const CupertinoDynamicColor inactiveGray = CupertinoDynamicColor.withBrightness( + debugLabel: 'inactiveGray', + color: Color(0xFF999999), + darkColor: Color(0xFF757575), + ); + + /// Used for iOS 13 for destructive actions such as the delete actions in + /// table view cells and dialogs. + /// + /// Not the same red as the camera shutter or springboard icon notifications + /// or the foreground red theme in various native apps such as HealthKit. + /// + /// This is SystemRed in the iOS palette. + static const Color destructiveRed = systemRed; + + /// A blue color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemBlue](https://developer.apple.com/documentation/uikit/uicolor/3173141-systemblue), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemBlue = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemBlue', + color: Color.fromARGB(255, 0, 122, 255), + darkColor: Color.fromARGB(255, 10, 132, 255), + highContrastColor: Color.fromARGB(255, 0, 64, 221), + darkHighContrastColor: Color.fromARGB(255, 64, 156, 255), + ); + + /// A green color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemGreen](https://developer.apple.com/documentation/uikit/uicolor/3173144-systemgreen), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemGreen = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGreen', + color: Color.fromARGB(255, 52, 199, 89), + darkColor: Color.fromARGB(255, 48, 209, 88), + highContrastColor: Color.fromARGB(255, 36, 138, 61), + darkHighContrastColor: Color.fromARGB(255, 48, 219, 91), + ); + + /// A mint color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemMint](https://developer.apple.com/documentation/uikit/uicolor/3852741-systemmint), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemMint = + CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemMint', + color: Color.fromARGB(255, 0, 199, 190), + darkColor: Color.fromARGB(255, 99, 230, 226), + highContrastColor: Color.fromARGB(255, 12, 129, 123), + darkHighContrastColor: Color.fromARGB(255, 102, 212, 207), + ); + + /// An indigo color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemIndigo](https://developer.apple.com/documentation/uikit/uicolor/3173146-systemindigo), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemIndigo = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemIndigo', + color: Color.fromARGB(255, 88, 86, 214), + darkColor: Color.fromARGB(255, 94, 92, 230), + highContrastColor: Color.fromARGB(255, 54, 52, 163), + darkHighContrastColor: Color.fromARGB(255, 125, 122, 255), + ); + + /// An orange color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemOrange](https://developer.apple.com/documentation/uikit/uicolor/3173147-systemorange), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemOrange = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemOrange', + color: Color.fromARGB(255, 255, 149, 0), + darkColor: Color.fromARGB(255, 255, 159, 10), + highContrastColor: Color.fromARGB(255, 201, 52, 0), + darkHighContrastColor: Color.fromARGB(255, 255, 179, 64), + ); + + /// A pink color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemPink](https://developer.apple.com/documentation/uikit/uicolor/3173148-systempink), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemPink = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemPink', + color: Color.fromARGB(255, 255, 45, 85), + darkColor: Color.fromARGB(255, 255, 55, 95), + highContrastColor: Color.fromARGB(255, 211, 15, 69), + darkHighContrastColor: Color.fromARGB(255, 255, 100, 130), + ); + + /// A brown color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemBrown](https://developer.apple.com/documentation/uikit/uicolor/3173142-systembrown), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemBrown = + CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemBrown', + color: Color.fromARGB(255, 162, 132, 94), + darkColor: Color.fromARGB(255, 172, 142, 104), + highContrastColor: Color.fromARGB(255, 127, 101, 69), + darkHighContrastColor: Color.fromARGB(255, 181, 148, 105), + ); + + /// A purple color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemPurple](https://developer.apple.com/documentation/uikit/uicolor/3173149-systempurple), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemPurple = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemPurple', + color: Color.fromARGB(255, 175, 82, 222), + darkColor: Color.fromARGB(255, 191, 90, 242), + highContrastColor: Color.fromARGB(255, 137, 68, 171), + darkHighContrastColor: Color.fromARGB(255, 218, 143, 255), + ); + + /// A red color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemRed](https://developer.apple.com/documentation/uikit/uicolor/3173150-systemred), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemRed = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemRed', + color: Color.fromARGB(255, 255, 59, 48), + darkColor: Color.fromARGB(255, 255, 69, 58), + highContrastColor: Color.fromARGB(255, 215, 0, 21), + darkHighContrastColor: Color.fromARGB(255, 255, 105, 97), + ); + + /// A teal color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemTeal](https://developer.apple.com/documentation/uikit/uicolor/3173151-systemteal), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemTeal = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemTeal', + color: Color.fromARGB(255, 90, 200, 250), + darkColor: Color.fromARGB(255, 100, 210, 255), + highContrastColor: Color.fromARGB(255, 0, 113, 164), + darkHighContrastColor: Color.fromARGB(255, 112, 215, 255), + ); + + /// A cyan color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemCyan](https://developer.apple.com/documentation/uikit/uicolor/3852740-systemcyan), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemCyan = + CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemCyan', + color: Color.fromARGB(255, 50, 173, 230), + darkColor: Color.fromARGB(255, 100, 210, 255), + highContrastColor: Color.fromARGB(255, 0, 113, 164), + darkHighContrastColor: Color.fromARGB(255, 112, 215, 255), + ); + + /// A yellow color that can adapt to the given [BuildContext]. + /// + /// See also: + /// + /// * [UIColor.systemYellow](https://developer.apple.com/documentation/uikit/uicolor/3173152-systemyellow), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemYellow = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemYellow', + color: Color.fromARGB(255, 255, 204, 0), + darkColor: Color.fromARGB(255, 255, 214, 10), + highContrastColor: Color.fromARGB(255, 160, 90, 0), + darkHighContrastColor: Color.fromARGB(255, 255, 212, 38), + ); + + /// The base grey color. + /// + /// See also: + /// + /// * [UIColor.systemGray](https://developer.apple.com/documentation/uikit/uicolor/3173143-systemgray), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemGrey = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey', + color: Color.fromARGB(255, 142, 142, 147), + darkColor: Color.fromARGB(255, 142, 142, 147), + highContrastColor: Color.fromARGB(255, 108, 108, 112), + darkHighContrastColor: Color.fromARGB(255, 174, 174, 178), + ); + + /// A second-level shade of grey. + /// + /// See also: + /// + /// * [UIColor.systemGray2](https://developer.apple.com/documentation/uikit/uicolor/3255071-systemgray2), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemGrey2 = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey2', + color: Color.fromARGB(255, 174, 174, 178), + darkColor: Color.fromARGB(255, 99, 99, 102), + highContrastColor: Color.fromARGB(255, 142, 142, 147), + darkHighContrastColor: Color.fromARGB(255, 124, 124, 128), + ); + + /// A third-level shade of grey. + /// + /// See also: + /// + /// * [UIColor.systemGray3](https://developer.apple.com/documentation/uikit/uicolor/3255072-systemgray3), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemGrey3 = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey3', + color: Color.fromARGB(255, 199, 199, 204), + darkColor: Color.fromARGB(255, 72, 72, 74), + highContrastColor: Color.fromARGB(255, 174, 174, 178), + darkHighContrastColor: Color.fromARGB(255, 84, 84, 86), + ); + + /// A fourth-level shade of grey. + /// + /// See also: + /// + /// * [UIColor.systemGray4](https://developer.apple.com/documentation/uikit/uicolor/3255073-systemgray4), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemGrey4 = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey4', + color: Color.fromARGB(255, 209, 209, 214), + darkColor: Color.fromARGB(255, 58, 58, 60), + highContrastColor: Color.fromARGB(255, 188, 188, 192), + darkHighContrastColor: Color.fromARGB(255, 68, 68, 70), + ); + + /// A fifth-level shade of grey. + /// + /// See also: + /// + /// * [UIColor.systemGray5](https://developer.apple.com/documentation/uikit/uicolor/3255074-systemgray5), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemGrey5 = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey5', + color: Color.fromARGB(255, 229, 229, 234), + darkColor: Color.fromARGB(255, 44, 44, 46), + highContrastColor: Color.fromARGB(255, 216, 216, 220), + darkHighContrastColor: Color.fromARGB(255, 54, 54, 56), + ); + + /// A sixth-level shade of grey. + /// + /// See also: + /// + /// * [UIColor.systemGray6](https://developer.apple.com/documentation/uikit/uicolor/3255075-systemgray6), + /// the `UIKit` equivalent. + static const CupertinoDynamicColor systemGrey6 = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey6', + color: Color.fromARGB(255, 242, 242, 247), + darkColor: Color.fromARGB(255, 28, 28, 30), + highContrastColor: Color.fromARGB(255, 235, 235, 240), + darkHighContrastColor: Color.fromARGB(255, 36, 36, 38), + ); + + /// The color for text labels containing primary content, equivalent to + /// [UIColor.label](https://developer.apple.com/documentation/uikit/uicolor/3173131-label). + static const CupertinoDynamicColor label = CupertinoDynamicColor( + debugLabel: 'label', + color: Color.fromARGB(255, 0, 0, 0), + darkColor: Color.fromARGB(255, 255, 255, 255), + highContrastColor: Color.fromARGB(255, 0, 0, 0), + darkHighContrastColor: Color.fromARGB(255, 255, 255, 255), + elevatedColor: Color.fromARGB(255, 0, 0, 0), + darkElevatedColor: Color.fromARGB(255, 255, 255, 255), + highContrastElevatedColor: Color.fromARGB(255, 0, 0, 0), + darkHighContrastElevatedColor: Color.fromARGB(255, 255, 255, 255), + ); + + /// The color for text labels containing secondary content, equivalent to + /// [UIColor.secondaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173136-secondarylabel). + static const CupertinoDynamicColor secondaryLabel = CupertinoDynamicColor( + debugLabel: 'secondaryLabel', + color: Color.fromARGB(153, 60, 60, 67), + darkColor: Color.fromARGB(153, 235, 235, 245), + highContrastColor: Color.fromARGB(173, 60, 60, 67), + darkHighContrastColor: Color.fromARGB(173, 235, 235, 245), + elevatedColor: Color.fromARGB(153, 60, 60, 67), + darkElevatedColor: Color.fromARGB(153, 235, 235, 245), + highContrastElevatedColor: Color.fromARGB(173, 60, 60, 67), + darkHighContrastElevatedColor: Color.fromARGB(173, 235, 235, 245), +); + + /// The color for text labels containing tertiary content, equivalent to + /// [UIColor.tertiaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173153-tertiarylabel). + static const CupertinoDynamicColor tertiaryLabel = CupertinoDynamicColor( + debugLabel: 'tertiaryLabel', + color: Color.fromARGB(76, 60, 60, 67), + darkColor: Color.fromARGB(76, 235, 235, 245), + highContrastColor: Color.fromARGB(96, 60, 60, 67), + darkHighContrastColor: Color.fromARGB(96, 235, 235, 245), + elevatedColor: Color.fromARGB(76, 60, 60, 67), + darkElevatedColor: Color.fromARGB(76, 235, 235, 245), + highContrastElevatedColor: Color.fromARGB(96, 60, 60, 67), + darkHighContrastElevatedColor: Color.fromARGB(96, 235, 235, 245), + ); + + /// The color for text labels containing quaternary content, equivalent to + /// [UIColor.quaternaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173135-quaternarylabel). + static const CupertinoDynamicColor quaternaryLabel = CupertinoDynamicColor( + debugLabel: 'quaternaryLabel', + color: Color.fromARGB(45, 60, 60, 67), + darkColor: Color.fromARGB(40, 235, 235, 245), + highContrastColor: Color.fromARGB(66, 60, 60, 67), + darkHighContrastColor: Color.fromARGB(61, 235, 235, 245), + elevatedColor: Color.fromARGB(45, 60, 60, 67), + darkElevatedColor: Color.fromARGB(40, 235, 235, 245), + highContrastElevatedColor: Color.fromARGB(66, 60, 60, 67), + darkHighContrastElevatedColor: Color.fromARGB(61, 235, 235, 245), + ); + + /// An overlay fill color for thin and small shapes, equivalent to + /// [UIColor.systemFill](https://developer.apple.com/documentation/uikit/uicolor/3255070-systemfill). + static const CupertinoDynamicColor systemFill = CupertinoDynamicColor( + debugLabel: 'systemFill', + color: Color.fromARGB(51, 120, 120, 128), + darkColor: Color.fromARGB(91, 120, 120, 128), + highContrastColor: Color.fromARGB(71, 120, 120, 128), + darkHighContrastColor: Color.fromARGB(112, 120, 120, 128), + elevatedColor: Color.fromARGB(51, 120, 120, 128), + darkElevatedColor: Color.fromARGB(91, 120, 120, 128), + highContrastElevatedColor: Color.fromARGB(71, 120, 120, 128), + darkHighContrastElevatedColor: Color.fromARGB(112, 120, 120, 128), + ); + + /// An overlay fill color for medium-size shapes, equivalent to + /// [UIColor.secondarySystemFill](https://developer.apple.com/documentation/uikit/uicolor/3255069-secondarysystemfill). + static const CupertinoDynamicColor secondarySystemFill = CupertinoDynamicColor( + debugLabel: 'secondarySystemFill', + color: Color.fromARGB(40, 120, 120, 128), + darkColor: Color.fromARGB(81, 120, 120, 128), + highContrastColor: Color.fromARGB(61, 120, 120, 128), + darkHighContrastColor: Color.fromARGB(102, 120, 120, 128), + elevatedColor: Color.fromARGB(40, 120, 120, 128), + darkElevatedColor: Color.fromARGB(81, 120, 120, 128), + highContrastElevatedColor: Color.fromARGB(61, 120, 120, 128), + darkHighContrastElevatedColor: Color.fromARGB(102, 120, 120, 128), + ); + + /// An overlay fill color for large shapes, equivalent to + /// [UIColor.tertiarySystemFill](https://developer.apple.com/documentation/uikit/uicolor/3255076-tertiarysystemfill). + static const CupertinoDynamicColor tertiarySystemFill = CupertinoDynamicColor( + debugLabel: 'tertiarySystemFill', + color: Color.fromARGB(30, 118, 118, 128), + darkColor: Color.fromARGB(61, 118, 118, 128), + highContrastColor: Color.fromARGB(51, 118, 118, 128), + darkHighContrastColor: Color.fromARGB(81, 118, 118, 128), + elevatedColor: Color.fromARGB(30, 118, 118, 128), + darkElevatedColor: Color.fromARGB(61, 118, 118, 128), + highContrastElevatedColor: Color.fromARGB(51, 118, 118, 128), + darkHighContrastElevatedColor: Color.fromARGB(81, 118, 118, 128), + ); + + /// An overlay fill color for large areas containing complex content, equivalent + /// to [UIColor.quaternarySystemFill](https://developer.apple.com/documentation/uikit/uicolor/3255068-quaternarysystemfill). + static const CupertinoDynamicColor quaternarySystemFill = CupertinoDynamicColor( + debugLabel: 'quaternarySystemFill', + color: Color.fromARGB(20, 116, 116, 128), + darkColor: Color.fromARGB(45, 118, 118, 128), + highContrastColor: Color.fromARGB(40, 116, 116, 128), + darkHighContrastColor: Color.fromARGB(66, 118, 118, 128), + elevatedColor: Color.fromARGB(20, 116, 116, 128), + darkElevatedColor: Color.fromARGB(45, 118, 118, 128), + highContrastElevatedColor: Color.fromARGB(40, 116, 116, 128), + darkHighContrastElevatedColor: Color.fromARGB(66, 118, 118, 128), + ); + + /// The color for placeholder text in controls or text views, equivalent to + /// [UIColor.placeholderText](https://developer.apple.com/documentation/uikit/uicolor/3173134-placeholdertext). + static const CupertinoDynamicColor placeholderText = CupertinoDynamicColor( + debugLabel: 'placeholderText', + color: Color.fromARGB(76, 60, 60, 67), + darkColor: Color.fromARGB(76, 235, 235, 245), + highContrastColor: Color.fromARGB(96, 60, 60, 67), + darkHighContrastColor: Color.fromARGB(96, 235, 235, 245), + elevatedColor: Color.fromARGB(76, 60, 60, 67), + darkElevatedColor: Color.fromARGB(76, 235, 235, 245), + highContrastElevatedColor: Color.fromARGB(96, 60, 60, 67), + darkHighContrastElevatedColor: Color.fromARGB(96, 235, 235, 245), + ); + + /// The color for the main background of your interface, equivalent to + /// [UIColor.systemBackground](https://developer.apple.com/documentation/uikit/uicolor/3173140-systembackground). + /// + /// Typically used for designs that have a white primary background in a light environment. + static const CupertinoDynamicColor systemBackground = CupertinoDynamicColor( + debugLabel: 'systemBackground', + color: Color.fromARGB(255, 255, 255, 255), + darkColor: Color.fromARGB(255, 0, 0, 0), + highContrastColor: Color.fromARGB(255, 255, 255, 255), + darkHighContrastColor: Color.fromARGB(255, 0, 0, 0), + elevatedColor: Color.fromARGB(255, 255, 255, 255), + darkElevatedColor: Color.fromARGB(255, 28, 28, 30), + highContrastElevatedColor: Color.fromARGB(255, 255, 255, 255), + darkHighContrastElevatedColor: Color.fromARGB(255, 36, 36, 38), + ); + + /// The color for content layered on top of the main background, equivalent to + /// [UIColor.secondarySystemBackground](https://developer.apple.com/documentation/uikit/uicolor/3173137-secondarysystembackground). + /// + /// Typically used for designs that have a white primary background in a light environment. + static const CupertinoDynamicColor secondarySystemBackground = CupertinoDynamicColor( + debugLabel: 'secondarySystemBackground', + color: Color.fromARGB(255, 242, 242, 247), + darkColor: Color.fromARGB(255, 28, 28, 30), + highContrastColor: Color.fromARGB(255, 235, 235, 240), + darkHighContrastColor: Color.fromARGB(255, 36, 36, 38), + elevatedColor: Color.fromARGB(255, 242, 242, 247), + darkElevatedColor: Color.fromARGB(255, 44, 44, 46), + highContrastElevatedColor: Color.fromARGB(255, 235, 235, 240), + darkHighContrastElevatedColor: Color.fromARGB(255, 54, 54, 56), + ); + + /// The color for content layered on top of secondary backgrounds, equivalent + /// to [UIColor.tertiarySystemBackground](https://developer.apple.com/documentation/uikit/uicolor/3173154-tertiarysystembackground). + /// + /// Typically used for designs that have a white primary background in a light environment. + static const CupertinoDynamicColor tertiarySystemBackground = CupertinoDynamicColor( + debugLabel: 'tertiarySystemBackground', + color: Color.fromARGB(255, 255, 255, 255), + darkColor: Color.fromARGB(255, 44, 44, 46), + highContrastColor: Color.fromARGB(255, 255, 255, 255), + darkHighContrastColor: Color.fromARGB(255, 54, 54, 56), + elevatedColor: Color.fromARGB(255, 255, 255, 255), + darkElevatedColor: Color.fromARGB(255, 58, 58, 60), + highContrastElevatedColor: Color.fromARGB(255, 255, 255, 255), + darkHighContrastElevatedColor: Color.fromARGB(255, 68, 68, 70), + ); + + /// The color for the main background of your grouped interface, equivalent to + /// [UIColor.systemGroupedBackground](https://developer.apple.com/documentation/uikit/uicolor/3173145-systemgroupedbackground). + /// + /// Typically used for grouped content, including table views and platter-based designs. + static const CupertinoDynamicColor systemGroupedBackground = CupertinoDynamicColor( + debugLabel: 'systemGroupedBackground', + color: Color.fromARGB(255, 242, 242, 247), + darkColor: Color.fromARGB(255, 0, 0, 0), + highContrastColor: Color.fromARGB(255, 235, 235, 240), + darkHighContrastColor: Color.fromARGB(255, 0, 0, 0), + elevatedColor: Color.fromARGB(255, 242, 242, 247), + darkElevatedColor: Color.fromARGB(255, 28, 28, 30), + highContrastElevatedColor: Color.fromARGB(255, 235, 235, 240), + darkHighContrastElevatedColor: Color.fromARGB(255, 36, 36, 38), + ); + + /// The color for content layered on top of the main background of your grouped interface, + /// equivalent to [UIColor.secondarySystemGroupedBackground](https://developer.apple.com/documentation/uikit/uicolor/3173138-secondarysystemgroupedbackground). + /// + /// Typically used for grouped content, including table views and platter-based designs. + static const CupertinoDynamicColor secondarySystemGroupedBackground = CupertinoDynamicColor( + debugLabel: 'secondarySystemGroupedBackground', + color: Color.fromARGB(255, 255, 255, 255), + darkColor: Color.fromARGB(255, 28, 28, 30), + highContrastColor: Color.fromARGB(255, 255, 255, 255), + darkHighContrastColor: Color.fromARGB(255, 36, 36, 38), + elevatedColor: Color.fromARGB(255, 255, 255, 255), + darkElevatedColor: Color.fromARGB(255, 44, 44, 46), + highContrastElevatedColor: Color.fromARGB(255, 255, 255, 255), + darkHighContrastElevatedColor: Color.fromARGB(255, 54, 54, 56), + ); + + /// The color for content layered on top of secondary backgrounds of your grouped interface, + /// equivalent to [UIColor.tertiarySystemGroupedBackground](https://developer.apple.com/documentation/uikit/uicolor/3173155-tertiarysystemgroupedbackground). + /// + /// Typically used for grouped content, including table views and platter-based designs. + static const CupertinoDynamicColor tertiarySystemGroupedBackground = CupertinoDynamicColor( + debugLabel: 'tertiarySystemGroupedBackground', + color: Color.fromARGB(255, 242, 242, 247), + darkColor: Color.fromARGB(255, 44, 44, 46), + highContrastColor: Color.fromARGB(255, 235, 235, 240), + darkHighContrastColor: Color.fromARGB(255, 54, 54, 56), + elevatedColor: Color.fromARGB(255, 242, 242, 247), + darkElevatedColor: Color.fromARGB(255, 58, 58, 60), + highContrastElevatedColor: Color.fromARGB(255, 235, 235, 240), + darkHighContrastElevatedColor: Color.fromARGB(255, 68, 68, 70), + ); + + /// The color for thin borders or divider lines that allows some underlying content to be visible, + /// equivalent to [UIColor.separator](https://developer.apple.com/documentation/uikit/uicolor/3173139-separator). + static const CupertinoDynamicColor separator = CupertinoDynamicColor( + debugLabel: 'separator', + color: Color.fromARGB(73, 60, 60, 67), + darkColor: Color.fromARGB(153, 84, 84, 88), + highContrastColor: Color.fromARGB(94, 60, 60, 67), + darkHighContrastColor: Color.fromARGB(173, 84, 84, 88), + elevatedColor: Color.fromARGB(73, 60, 60, 67), + darkElevatedColor: Color.fromARGB(153, 84, 84, 88), + highContrastElevatedColor: Color.fromARGB(94, 60, 60, 67), + darkHighContrastElevatedColor: Color.fromARGB(173, 84, 84, 88), + ); + + /// The color for borders or divider lines that hide any underlying content, + /// equivalent to [UIColor.opaqueSeparator](https://developer.apple.com/documentation/uikit/uicolor/3173133-opaqueseparator). + static const CupertinoDynamicColor opaqueSeparator = CupertinoDynamicColor( + debugLabel: 'opaqueSeparator', + color: Color.fromARGB(255, 198, 198, 200), + darkColor: Color.fromARGB(255, 56, 56, 58), + highContrastColor: Color.fromARGB(255, 198, 198, 200), + darkHighContrastColor: Color.fromARGB(255, 56, 56, 58), + elevatedColor: Color.fromARGB(255, 198, 198, 200), + darkElevatedColor: Color.fromARGB(255, 56, 56, 58), + highContrastElevatedColor: Color.fromARGB(255, 198, 198, 200), + darkHighContrastElevatedColor: Color.fromARGB(255, 56, 56, 58), + ); + + /// The color for links, equivalent to + /// [UIColor.link](https://developer.apple.com/documentation/uikit/uicolor/3173132-link). + static const CupertinoDynamicColor link = CupertinoDynamicColor( + debugLabel: 'link', + color: Color.fromARGB(255, 0, 122, 255), + darkColor: Color.fromARGB(255, 9, 132, 255), + highContrastColor: Color.fromARGB(255, 0, 122, 255), + darkHighContrastColor: Color.fromARGB(255, 9, 132, 255), + elevatedColor: Color.fromARGB(255, 0, 122, 255), + darkElevatedColor: Color.fromARGB(255, 9, 132, 255), + highContrastElevatedColor: Color.fromARGB(255, 0, 122, 255), + darkHighContrastElevatedColor: Color.fromARGB(255, 9, 132, 255), + ); +} + +/// A [Color] subclass that represents a family of colors, and the correct effective +/// color in the color family. +/// +/// When used as a regular color, [CupertinoDynamicColor] is equivalent to the +/// effective color (i.e. [CupertinoDynamicColor.value] will come from the effective +/// color), which is determined by the [BuildContext] it is last resolved against. +/// If it has never been resolved, the light, normal contrast, base elevation variant +/// [CupertinoDynamicColor.color] will be the default effective color. +/// +/// Sometimes manually resolving a [CupertinoDynamicColor] is not necessary, because +/// the Cupertino Library provides built-in support for it. +/// +/// ### Using [CupertinoDynamicColor] in a Cupertino widget +/// +/// When a Cupertino widget is provided with a [CupertinoDynamicColor], either +/// directly in its constructor, or from an [InheritedWidget] it depends on (for example, +/// [DefaultTextStyle]), the widget will automatically resolve the color using +/// [CupertinoDynamicColor.resolve] against its own [BuildContext], on a best-effort +/// basis. +/// +/// {@tool snippet} +/// By default a [CupertinoButton] has no background color. The following sample +/// code shows how to build a [CupertinoButton] that appears white in light mode, +/// and changes automatically to black in dark mode. +/// +/// ```dart +/// CupertinoButton( +/// // CupertinoDynamicColor works out of box in a CupertinoButton. +/// color: const CupertinoDynamicColor.withBrightness( +/// color: CupertinoColors.white, +/// darkColor: CupertinoColors.black, +/// ), +/// onPressed: () { }, +/// child: child, +/// ) +/// ``` +/// {@end-tool} +/// +/// ### Using a [CupertinoDynamicColor] from a [CupertinoTheme] +/// +/// When referring to a [CupertinoTheme] color, generally the color will already +/// have adapted to the ambient [BuildContext], because [CupertinoTheme.of] +/// implicitly resolves all the colors used in the retrieved [CupertinoThemeData], +/// before returning it. +/// +/// {@tool snippet} +/// The following code sample creates a [Container] with the `primaryColor` of the +/// current theme. If `primaryColor` is a [CupertinoDynamicColor], the container +/// will be adaptive, thanks to [CupertinoTheme.of]: it will switch to `primaryColor`'s +/// dark variant once dark mode is turned on, and turns to primaryColor`'s high +/// contrast variant when [MediaQueryData.highContrast] is requested in the ambient +/// [MediaQuery], etc. +/// +/// ```dart +/// Container( +/// // Container is not a Cupertino widget, but CupertinoTheme.of implicitly +/// // resolves colors used in the retrieved CupertinoThemeData. +/// color: CupertinoTheme.of(context).primaryColor, +/// ) +/// ``` +/// {@end-tool} +/// +/// ### Manually Resolving a [CupertinoDynamicColor] +/// +/// When used to configure a non-Cupertino widget, or wrapped in an object opaque +/// to the receiving Cupertino component, a [CupertinoDynamicColor] may need to be +/// manually resolved using [CupertinoDynamicColor.resolve], before it can used +/// to paint. For example, to use a custom [Border] in a [CupertinoNavigationBar], +/// the colors used in the [Border] have to be resolved manually before being passed +/// to [CupertinoNavigationBar]'s constructor. +/// +/// {@tool snippet} +/// +/// The following code samples demonstrate two cases where you have to manually +/// resolve a [CupertinoDynamicColor]. +/// +/// ```dart +/// CupertinoNavigationBar( +/// // CupertinoNavigationBar does not know how to resolve colors used in +/// // a Border class. +/// border: Border( +/// bottom: BorderSide( +/// color: CupertinoDynamicColor.resolve(CupertinoColors.systemBlue, context), +/// ), +/// ), +/// ) +/// ``` +/// +/// ```dart +/// Container( +/// // Container is not a Cupertino widget. +/// color: CupertinoDynamicColor.resolve(CupertinoColors.systemBlue, context), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoUserInterfaceLevel], an [InheritedWidget] that may affect color +/// resolution of a [CupertinoDynamicColor]. +/// * [CupertinoTheme.of], a static method that retrieves the ambient [CupertinoThemeData], +/// and then resolves [CupertinoDynamicColor]s used in the retrieved data. +@immutable +class CupertinoDynamicColor extends Color with Diagnosticable { + /// Creates an adaptive [Color] that changes its effective color based on the + /// [BuildContext] given. The default effective color is [color]. + const CupertinoDynamicColor({ + String? debugLabel, + required Color color, + required Color darkColor, + required Color highContrastColor, + required Color darkHighContrastColor, + required Color elevatedColor, + required Color darkElevatedColor, + required Color highContrastElevatedColor, + required Color darkHighContrastElevatedColor, + }) : this._( + color, + color, + darkColor, + highContrastColor, + darkHighContrastColor, + elevatedColor, + darkElevatedColor, + highContrastElevatedColor, + darkHighContrastElevatedColor, + null, + debugLabel, + ); + + /// Creates an adaptive [Color] that changes its effective color based on the + /// given [BuildContext]'s brightness (from [MediaQueryData.platformBrightness] + /// or [CupertinoThemeData.brightness]) and accessibility contrast setting + /// ([MediaQueryData.highContrast]). The default effective color is [color]. + const CupertinoDynamicColor.withBrightnessAndContrast({ + String? debugLabel, + required Color color, + required Color darkColor, + required Color highContrastColor, + required Color darkHighContrastColor, + }) : this( + debugLabel: debugLabel, + color: color, + darkColor: darkColor, + highContrastColor: highContrastColor, + darkHighContrastColor: darkHighContrastColor, + elevatedColor: color, + darkElevatedColor: darkColor, + highContrastElevatedColor: highContrastColor, + darkHighContrastElevatedColor: darkHighContrastColor, + ); + + /// Creates an adaptive [Color] that changes its effective color based on the given + /// [BuildContext]'s brightness (from [MediaQueryData.platformBrightness] or + /// [CupertinoThemeData.brightness]). The default effective color is [color]. + const CupertinoDynamicColor.withBrightness({ + String? debugLabel, + required Color color, + required Color darkColor, + }) : this( + debugLabel: debugLabel, + color: color, + darkColor: darkColor, + highContrastColor: color, + darkHighContrastColor: darkColor, + elevatedColor: color, + darkElevatedColor: darkColor, + highContrastElevatedColor: color, + darkHighContrastElevatedColor: darkColor, + ); + + const CupertinoDynamicColor._( + this._effectiveColor, + this.color, + this.darkColor, + this.highContrastColor, + this.darkHighContrastColor, + this.elevatedColor, + this.darkElevatedColor, + this.highContrastElevatedColor, + this.darkHighContrastElevatedColor, + this._debugResolveContext, + this._debugLabel, + ) : // The super constructor has to be called with a dummy value in order to mark + // this constructor const. + // The field `value` is overridden in the class implementation. + super(0); + + /// The current effective color. + /// + /// Defaults to [color] if this [CupertinoDynamicColor] has never been + /// resolved. + final Color _effectiveColor; + + @override + int get value => _effectiveColor.value; + + final String? _debugLabel; + + final Element? _debugResolveContext; + + /// The color to use when the [BuildContext] implies a combination of light mode, + /// normal contrast, and base interface elevation. + /// + /// In other words, this color will be the effective color of the [CupertinoDynamicColor] + /// after it is resolved against a [BuildContext] that: + /// - has a [CupertinoTheme] whose [CupertinoThemeData.brightness] is [Brightness.light], + /// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [Brightness.light]. + /// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`. + /// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base]. + final Color color; + + /// The color to use when the [BuildContext] implies a combination of dark mode, + /// normal contrast, and base interface elevation. + /// + /// In other words, this color will be the effective color of the [CupertinoDynamicColor] + /// after it is resolved against a [BuildContext] that: + /// - has a [CupertinoTheme] whose [CupertinoThemeData.brightness] is [Brightness.dark], + /// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [Brightness.dark]. + /// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`. + /// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base]. + final Color darkColor; + + /// The color to use when the [BuildContext] implies a combination of light mode, + /// high contrast, and base interface elevation. + /// + /// In other words, this color will be the effective color of the [CupertinoDynamicColor] + /// after it is resolved against a [BuildContext] that: + /// - has a [CupertinoTheme] whose [CupertinoThemeData.brightness] is [Brightness.light], + /// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [Brightness.light]. + /// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`. + /// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base]. + final Color highContrastColor; + + /// The color to use when the [BuildContext] implies a combination of dark mode, + /// high contrast, and base interface elevation. + /// + /// In other words, this color will be the effective color of the [CupertinoDynamicColor] + /// after it is resolved against a [BuildContext] that: + /// - has a [CupertinoTheme] whose [CupertinoThemeData.brightness] is [Brightness.dark], + /// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [Brightness.dark]. + /// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`. + /// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base]. + final Color darkHighContrastColor; + + /// The color to use when the [BuildContext] implies a combination of light mode, + /// normal contrast, and elevated interface elevation. + /// + /// In other words, this color will be the effective color of the [CupertinoDynamicColor] + /// after it is resolved against a [BuildContext] that: + /// - has a [CupertinoTheme] whose [CupertinoThemeData.brightness] is [Brightness.light], + /// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [Brightness.light]. + /// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`. + /// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated]. + final Color elevatedColor; + + /// The color to use when the [BuildContext] implies a combination of dark mode, + /// normal contrast, and elevated interface elevation. + /// + /// In other words, this color will be the effective color of the [CupertinoDynamicColor] + /// after it is resolved against a [BuildContext] that: + /// - has a [CupertinoTheme] whose [CupertinoThemeData.brightness] is [Brightness.dark], + /// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [Brightness.dark]. + /// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`. + /// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated]. + final Color darkElevatedColor; + + /// The color to use when the [BuildContext] implies a combination of light mode, + /// high contrast, and elevated interface elevation. + /// + /// In other words, this color will be the effective color of the [CupertinoDynamicColor] + /// after it is resolved against a [BuildContext] that: + /// - has a [CupertinoTheme] whose [CupertinoThemeData.brightness] is [Brightness.light], + /// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [Brightness.light]. + /// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`. + /// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated]. + final Color highContrastElevatedColor; + + /// The color to use when the [BuildContext] implies a combination of dark mode, + /// high contrast, and elevated interface elevation. + /// + /// In other words, this color will be the effective color of the [CupertinoDynamicColor] + /// after it is resolved against a [BuildContext] that: + /// - has a [CupertinoTheme] whose [CupertinoThemeData.brightness] is [Brightness.dark], + /// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [Brightness.dark]. + /// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`. + /// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated]. + final Color darkHighContrastElevatedColor; + + /// Resolves the given [Color] by calling [resolveFrom]. + /// + /// If the given color is already a concrete [Color], it will be returned as is. + /// If the given color is a [CupertinoDynamicColor], but the given [BuildContext] + /// lacks the dependencies required to the color resolution, the default trait + /// value will be used ([Brightness.light] platform brightness, normal contrast, + /// [CupertinoUserInterfaceLevelData.base] elevation level). + /// + /// See also: + /// + /// * [maybeResolve], which is similar to this function, but will allow a + /// null `resolvable` color. + static Color resolve(Color resolvable, BuildContext context) { + return (resolvable is CupertinoDynamicColor) + ? resolvable.resolveFrom(context) + : resolvable; + } + + /// Resolves the given [Color] by calling [resolveFrom]. + /// + /// If the given color is already a concrete [Color], it will be returned as is. + /// If the given color is null, returns null. + /// If the given color is a [CupertinoDynamicColor], but the given [BuildContext] + /// lacks the dependencies required to the color resolution, the default trait + /// value will be used ([Brightness.light] platform brightness, normal contrast, + /// [CupertinoUserInterfaceLevelData.base] elevation level). + /// + /// See also: + /// + /// * [resolve], which is similar to this function, but returns a + /// non-nullable value, and does not allow a null `resolvable` color. + static Color? maybeResolve(Color? resolvable, BuildContext context) { + if (resolvable == null) { + return null; + } + return (resolvable is CupertinoDynamicColor) + ? resolvable.resolveFrom(context) + : resolvable; + } + + bool get _isPlatformBrightnessDependent { + return color != darkColor + || elevatedColor != darkElevatedColor + || highContrastColor != darkHighContrastColor + || highContrastElevatedColor != darkHighContrastElevatedColor; + } + + bool get _isHighContrastDependent { + return color != highContrastColor + || darkColor != darkHighContrastColor + || elevatedColor != highContrastElevatedColor + || darkElevatedColor != darkHighContrastElevatedColor; + } + + bool get _isInterfaceElevationDependent { + return color != elevatedColor + || darkColor != darkElevatedColor + || highContrastColor != highContrastElevatedColor + || darkHighContrastColor != darkHighContrastElevatedColor; + } + + /// Resolves this [CupertinoDynamicColor] using the provided [BuildContext]. + /// + /// Calling this method will create a new [CupertinoDynamicColor] that is + /// almost identical to this [CupertinoDynamicColor], except the effective + /// color is changed to adapt to the given [BuildContext]. + /// + /// For example, if the given [BuildContext] indicates the widgets in the + /// subtree should be displayed in dark mode (the surrounding + /// [CupertinoTheme]'s [CupertinoThemeData.brightness] or [MediaQuery]'s + /// [MediaQueryData.platformBrightness] is [Brightness.dark]), with a high + /// accessibility contrast (the surrounding [MediaQuery]'s + /// [MediaQueryData.highContrast] is `true`), and an elevated interface + /// elevation (the surrounding [CupertinoUserInterfaceLevel]'s `data` is + /// [CupertinoUserInterfaceLevelData.elevated]), the resolved + /// [CupertinoDynamicColor] will be the same as this [CupertinoDynamicColor], + /// except its effective color will be the `darkHighContrastElevatedColor` + /// variant from the original [CupertinoDynamicColor]. + /// + /// Calling this function may create dependencies on the closest instance of + /// some [InheritedWidget]s that enclose the given [BuildContext]. E.g., if + /// [darkColor] is different from [color], this method will call + /// [CupertinoTheme.maybeBrightnessOf] in an effort to determine the + /// brightness. If [color] is different from [highContrastColor], this method + /// will call [MediaQuery.maybeHighContrastOf] in an effort to determine the + /// high contrast setting. + /// + /// If any of the required dependencies are missing from the given context, + /// the default value of that trait will be used ([Brightness.light] platform + /// brightness, normal contrast, [CupertinoUserInterfaceLevelData.base] + /// elevation level). + CupertinoDynamicColor resolveFrom(BuildContext context) { + Brightness brightness = Brightness.light; + if (_isPlatformBrightnessDependent) { + brightness = CupertinoTheme.maybeBrightnessOf(context) ?? Brightness.light; + } + bool isHighContrastEnabled = false; + if (_isHighContrastDependent) { + isHighContrastEnabled = MediaQuery.maybeHighContrastOf(context) ?? false; + } + + final CupertinoUserInterfaceLevelData level = _isInterfaceElevationDependent + ? CupertinoUserInterfaceLevel.maybeOf(context) ?? CupertinoUserInterfaceLevelData.base + : CupertinoUserInterfaceLevelData.base; + + final Color resolved; + switch (brightness) { + case Brightness.light: + switch (level) { + case CupertinoUserInterfaceLevelData.base: + resolved = isHighContrastEnabled ? highContrastColor : color; + case CupertinoUserInterfaceLevelData.elevated: + resolved = isHighContrastEnabled ? highContrastElevatedColor : elevatedColor; + } + case Brightness.dark: + switch (level) { + case CupertinoUserInterfaceLevelData.base: + resolved = isHighContrastEnabled ? darkHighContrastColor : darkColor; + case CupertinoUserInterfaceLevelData.elevated: + resolved = isHighContrastEnabled ? darkHighContrastElevatedColor : darkElevatedColor; + } + } + + Element? debugContext; + assert(() { + debugContext = context as Element; + return true; + }()); + return CupertinoDynamicColor._( + resolved, + color, + darkColor, + highContrastColor, + darkHighContrastColor, + elevatedColor, + darkElevatedColor, + highContrastElevatedColor, + darkHighContrastElevatedColor, + debugContext, + _debugLabel, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is CupertinoDynamicColor + && other.value == value + && other.color == color + && other.darkColor == darkColor + && other.highContrastColor == highContrastColor + && other.darkHighContrastColor == darkHighContrastColor + && other.elevatedColor == elevatedColor + && other.darkElevatedColor == darkElevatedColor + && other.highContrastElevatedColor == highContrastElevatedColor + && other.darkHighContrastElevatedColor == darkHighContrastElevatedColor; + } + + @override + int get hashCode => Object.hash( + value, + color, + darkColor, + highContrastColor, + elevatedColor, + darkElevatedColor, + darkHighContrastColor, + darkHighContrastElevatedColor, + highContrastElevatedColor, + ); + + @override + String toString({ DiagnosticLevel minLevel = DiagnosticLevel.info }) { + String toString(String name, Color color) { + final String marker = color == _effectiveColor ? '*' : ''; + return '$marker$name = $color$marker'; + } + + final List xs = [toString('color', color), + if (_isPlatformBrightnessDependent) toString('darkColor', darkColor), + if (_isHighContrastDependent) toString('highContrastColor', highContrastColor), + if (_isPlatformBrightnessDependent && _isHighContrastDependent) toString('darkHighContrastColor', darkHighContrastColor), + if (_isInterfaceElevationDependent) toString('elevatedColor', elevatedColor), + if (_isPlatformBrightnessDependent && _isInterfaceElevationDependent) toString('darkElevatedColor', darkElevatedColor), + if (_isHighContrastDependent && _isInterfaceElevationDependent) toString('highContrastElevatedColor', highContrastElevatedColor), + if (_isPlatformBrightnessDependent && _isHighContrastDependent && _isInterfaceElevationDependent) toString('darkHighContrastElevatedColor', darkHighContrastElevatedColor), + ]; + + return '${_debugLabel ?? objectRuntimeType(this, 'CupertinoDynamicColor')}(${xs.join(', ')}, resolved by: ${_debugResolveContext?.widget ?? "UNRESOLVED"})'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + if (_debugLabel != null) { + properties.add(MessageProperty('debugLabel', _debugLabel)); + } + properties.add(createCupertinoColorProperty('color', color)); + if (_isPlatformBrightnessDependent) { + properties.add(createCupertinoColorProperty('darkColor', darkColor)); + } + if (_isHighContrastDependent) { + properties.add(createCupertinoColorProperty('highContrastColor', highContrastColor)); + } + if (_isPlatformBrightnessDependent && _isHighContrastDependent) { + properties.add(createCupertinoColorProperty('darkHighContrastColor', darkHighContrastColor)); + } + if (_isInterfaceElevationDependent) { + properties.add(createCupertinoColorProperty('elevatedColor', elevatedColor)); + } + if (_isPlatformBrightnessDependent && _isInterfaceElevationDependent) { + properties.add(createCupertinoColorProperty('darkElevatedColor', darkElevatedColor)); + } + if (_isHighContrastDependent && _isInterfaceElevationDependent) { + properties.add(createCupertinoColorProperty('highContrastElevatedColor', highContrastElevatedColor)); + } + if (_isPlatformBrightnessDependent && _isHighContrastDependent && _isInterfaceElevationDependent) { + properties.add(createCupertinoColorProperty('darkHighContrastElevatedColor', darkHighContrastElevatedColor)); + } + + if (_debugResolveContext != null) { + properties.add(DiagnosticsProperty('last resolved', _debugResolveContext)); + } + } +} + +/// Creates a diagnostics property for [CupertinoDynamicColor]. +DiagnosticsProperty createCupertinoColorProperty( + String name, + Color? value, { + bool showName = true, + Object? defaultValue = kNoDefaultValue, + DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine, + DiagnosticLevel level = DiagnosticLevel.info, +}) { + if (value is CupertinoDynamicColor) { + return DiagnosticsProperty( + name, + value, + description: value._debugLabel, + showName: showName, + defaultValue: defaultValue, + style: style, + level: level, + ); + } else { + return ColorProperty( + name, + value, + showName: showName, + defaultValue: defaultValue, + style: style, + level: level, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/constants.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/constants.dart new file mode 100644 index 0000000000000000000000000000000000000000..2831c50bd20181aa48cbb718445a64aa89f2124d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/constants.dart @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// The minimum dimension of any interactive region according to the iOS Human +/// Interface Guidelines. +/// +/// This is used to avoid small regions that are hard for the user to interact +/// with. It applies to both dimensions of a region, so a square of size +/// kMinInteractiveDimension x kMinInteractiveDimension is the smallest +/// acceptable region that should respond to gestures. +/// +/// See also: +/// +/// * [kMinInteractiveDimension] +/// * +const double kMinInteractiveDimensionCupertino = 44.0; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/context_menu.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/context_menu.dart new file mode 100644 index 0000000000000000000000000000000000000000..1f1509f0006a4860a8f1de0941f18dda07749813 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/context_menu.dart @@ -0,0 +1,1510 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart' show HapticFeedback; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'localizations.dart'; + +// The scale of the child at the time that the CupertinoContextMenu opens. +// This value was eyeballed from a physical device running iOS 13.1.2. +const double _kOpenScale = 1.15; + +// The ratio for the borderRadius of the context menu preview image. This value +// was eyeballed by overlapping the CupertinoContextMenu with a context menu +// from iOS 16.0 in the XCode iPhone simulator. +const double _previewBorderRadiusRatio = 12.0; + +// The duration of the transition used when a modal popup is shown. Eyeballed +// from a physical device running iOS 13.1.2. +const Duration _kModalPopupTransitionDuration = Duration(milliseconds: 335); + +// The duration it takes for the CupertinoContextMenu to open. +// This value was eyeballed from the XCode simulator running iOS 16.0. +const Duration _previewLongPressTimeout = Duration(milliseconds: 800); + +// The total length of the combined animations until the menu is fully open. +final int _animationDuration = + _previewLongPressTimeout.inMilliseconds + _kModalPopupTransitionDuration.inMilliseconds; + +// The final box shadow for the opening child widget. +// This value was eyeballed from the XCode simulator running iOS 16.0. +const List _endBoxShadow = [ + BoxShadow( + color: Color(0x40000000), + blurRadius: 10.0, + spreadRadius: 0.5, + ), +]; + +const Color _borderColor = CupertinoDynamicColor.withBrightness( + color: Color(0xFFA9A9AF), + darkColor: Color(0xFF57585A), +); + +typedef _DismissCallback = void Function( + BuildContext context, + double scale, + double opacity, +); + +/// A function that produces the preview when the CupertinoContextMenu is open. +/// +/// Called every time the animation value changes. +typedef ContextMenuPreviewBuilder = Widget Function( + BuildContext context, + Animation animation, + Widget child, +); + +/// A function that builds the child and handles the transition between the +/// default child and the preview when the CupertinoContextMenu is open. +typedef CupertinoContextMenuBuilder = Widget Function( + BuildContext context, + Animation animation, +); + +// Given a GlobalKey, return the Rect of the corresponding RenderBox's +// paintBounds in global coordinates. +Rect _getRect(GlobalKey globalKey) { + assert(globalKey.currentContext != null); + final RenderBox renderBoxContainer = globalKey.currentContext!.findRenderObject()! as RenderBox; + return Rect.fromPoints(renderBoxContainer.localToGlobal( + renderBoxContainer.paintBounds.topLeft, + ), renderBoxContainer.localToGlobal( + renderBoxContainer.paintBounds.bottomRight + )); +} + +// The context menu arranges itself slightly differently based on the location +// on the screen of [CupertinoContextMenu.child] before the +// [CupertinoContextMenu] opens. +enum _ContextMenuLocation { + center, + left, + right, +} + +/// A full-screen modal route that opens when the [child] is long-pressed. +/// +/// When open, the [CupertinoContextMenu] shows the child, or the widget returned +/// by [previewBuilder] if given, in a large full-screen [Overlay] with a list +/// of buttons specified by [actions]. The child/preview is placed in an +/// [Expanded] widget so that it will grow to fill the Overlay if its size is +/// unconstrained. +/// +/// When closed, the [CupertinoContextMenu] displays the child as if the +/// [CupertinoContextMenu] were not there. Sizing and positioning is unaffected. +/// The menu can be closed like other [PopupRoute]s, such as by tapping the +/// background or by calling `Navigator.pop(context)`. Unlike [PopupRoute], it can +/// also be closed by swiping downwards. +/// +/// The [previewBuilder] parameter is most commonly used to display a slight +/// variation of [child]. See [previewBuilder] for an example of rounding the +/// child's corners and allowing its aspect ratio to expand, similar to the +/// Photos app on iOS. +/// +/// {@tool dartpad} +/// This sample shows a very simple [CupertinoContextMenu] for the Flutter logo. +/// Long press on it to open. +/// +/// ** See code in examples/api/lib/cupertino/context_menu/cupertino_context_menu.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows a similar CupertinoContextMenu, this time using [builder] +/// to add a border radius to the widget. +/// +/// ** See code in examples/api/lib/cupertino/context_menu/cupertino_context_menu.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * +class CupertinoContextMenu extends StatefulWidget { + /// Create a context menu. + /// + /// The [actions] parameter cannot be empty. + CupertinoContextMenu({ + super.key, + required this.actions, + required Widget this.child, + this.enableHapticFeedback = false, + @Deprecated( + 'Use CupertinoContextMenu.builder instead. ' + 'This feature was deprecated after v3.4.0-34.1.pre.', + ) + this.previewBuilder = _defaultPreviewBuilder, + }) : assert(actions.isNotEmpty), + builder = ((BuildContext context, Animation animation) => child); + + /// Creates a context menu with a custom [builder] controlling the widget. + /// + /// Use instead of the default constructor when it is needed to have a more + /// custom animation. + /// + /// The [actions] parameter cannot be empty. + CupertinoContextMenu.builder({ + super.key, + required this.actions, + required this.builder, + this.enableHapticFeedback = false, + }) : assert(actions.isNotEmpty), + child = null, + previewBuilder = null; + + /// Exposes the default border radius for matching iOS 16.0 behavior. This + /// value was eyeballed from the iOS simulator running iOS 16.0. + /// + /// {@tool snippet} + /// + /// Below is example code in order to match the default border radius for an + /// iOS 16.0 open preview. + /// + /// ```dart + /// CupertinoContextMenu.builder( + /// actions: [ + /// CupertinoContextMenuAction( + /// child: const Text('Action one'), + /// onPressed: () {}, + /// ), + /// ], + /// builder:(BuildContext context, Animation animation) { + /// final Animation borderRadiusAnimation = BorderRadiusTween( + /// begin: BorderRadius.circular(0.0), + /// end: BorderRadius.circular(CupertinoContextMenu.kOpenBorderRadius), + /// ).animate( + /// CurvedAnimation( + /// parent: animation, + /// curve: Interval( + /// CupertinoContextMenu.animationOpensAt, + /// 1.0, + /// ), + /// ), + /// ); + /// + /// final Animation boxDecorationAnimation = DecorationTween( + /// begin: const BoxDecoration( + /// color: Color(0xFFFFFFFF), + /// boxShadow: [], + /// ), + /// end: const BoxDecoration( + /// color: Color(0xFFFFFFFF), + /// boxShadow: CupertinoContextMenu.kEndBoxShadow, + /// ), + /// ).animate( + /// CurvedAnimation( + /// parent: animation, + /// curve: Interval( + /// 0.0, + /// CupertinoContextMenu.animationOpensAt, + /// ), + /// ) + /// ); + /// + /// return Container( + /// decoration: + /// animation.value < CupertinoContextMenu.animationOpensAt ? boxDecorationAnimation.value : null, + /// child: FittedBox( + /// fit: BoxFit.cover, + /// child: ClipRRect( + /// borderRadius: borderRadiusAnimation.value ?? BorderRadius.circular(0.0), + /// child: SizedBox( + /// height: 150, + /// width: 150, + /// child: Image.network('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'), + /// ), + /// ), + /// ) + /// ); + /// }, + /// ) + /// ``` + /// + /// {@end-tool} + static const double kOpenBorderRadius = _previewBorderRadiusRatio; + + /// Exposes the final box shadow of the opening animation of the child widget + /// to match the default behavior of the native iOS widget. This value was + /// eyeballed from the iOS simulator running iOS 16.0. + static const List kEndBoxShadow = _endBoxShadow; + + /// The point at which the CupertinoContextMenu begins to animate + /// into the open position. + /// + /// A value between 0.0 and 1.0 corresponding to a point in [builder]'s + /// animation. When passing in an animation to [builder] the range before + /// [animationOpensAt] will correspond to the animation when the widget is + /// pressed and held, and the range after is the animation as the menu is + /// fully opening. For an example, see the documentation for [builder]. + static final double animationOpensAt = + _previewLongPressTimeout.inMilliseconds / _animationDuration; + + /// A function that returns a widget to be used alternatively from [child]. + /// + /// The widget returned by the function will be shown at all times: when the + /// [CupertinoContextMenu] is closed, when it is in the middle of opening, + /// and when it is fully open. This will overwrite the default animation that + /// matches the behavior of an iOS 16.0 context menu. + /// + /// This builder can be used instead of the child when the intended child has + /// a property that would conflict with the default animation, such as a + /// border radius or a shadow, or if a more custom animation is needed. + /// + /// In addition to the current [BuildContext], the function is also called + /// with an [Animation]. The complete animation goes from 0 to 1 when + /// the CupertinoContextMenu opens, and from 1 to 0 when it closes, and it can + /// be used to animate the widget in sync with this opening and closing. + /// + /// The animation works in two stages. The first happens on press and hold of + /// the widget from 0 to [animationOpensAt], and the second stage for when the + /// widget fully opens up to the menu, from [animationOpensAt] to 1. + /// + /// {@tool snippet} + /// + /// Below is an example of using [builder] to show an image tile setup to be + /// opened in the default way to match a native iOS 16.0 app. The behavior + /// will match what will happen if the simple child image was passed as just + /// the [child] parameter, instead of [builder]. This can be manipulated to + /// add more customizability to the widget's animation. + /// + /// ```dart + /// CupertinoContextMenu.builder( + /// actions: [ + /// CupertinoContextMenuAction( + /// child: const Text('Action one'), + /// onPressed: () {}, + /// ), + /// ], + /// builder:(BuildContext context, Animation animation) { + /// final Animation borderRadiusAnimation = BorderRadiusTween( + /// begin: BorderRadius.circular(0.0), + /// end: BorderRadius.circular(CupertinoContextMenu.kOpenBorderRadius), + /// ).animate( + /// CurvedAnimation( + /// parent: animation, + /// curve: Interval( + /// CupertinoContextMenu.animationOpensAt, + /// 1.0, + /// ), + /// ), + /// ); + /// + /// final Animation boxDecorationAnimation = DecorationTween( + /// begin: const BoxDecoration( + /// color: Color(0xFFFFFFFF), + /// boxShadow: [], + /// ), + /// end: const BoxDecoration( + /// color: Color(0xFFFFFFFF), + /// boxShadow: CupertinoContextMenu.kEndBoxShadow, + /// ), + /// ).animate( + /// CurvedAnimation( + /// parent: animation, + /// curve: Interval( + /// 0.0, + /// CupertinoContextMenu.animationOpensAt, + /// ), + /// ), + /// ); + /// + /// return Container( + /// decoration: + /// animation.value < CupertinoContextMenu.animationOpensAt ? boxDecorationAnimation.value : null, + /// child: FittedBox( + /// fit: BoxFit.cover, + /// child: ClipRRect( + /// borderRadius: borderRadiusAnimation.value ?? BorderRadius.circular(0.0), + /// child: SizedBox( + /// height: 150, + /// width: 150, + /// child: Image.network('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'), + /// ), + /// ), + /// ), + /// ); + /// }, + /// ) + /// ``` + /// + /// {@end-tool} + /// + /// {@tool dartpad} + /// Additionally below is an example of a real world use case for [builder]. + /// + /// If a widget is passed to the [child] parameter with properties that + /// conflict with the default animation, in this case the border radius, + /// unwanted behaviors can arise. Here a boxed shadow will wrap the widget as + /// it is expanded. To handle this, a more custom animation and widget can be + /// passed to the builder, using values exposed by [CupertinoContextMenu], + /// like [CupertinoContextMenu.kEndBoxShadow], to match the native iOS + /// animation as close as desired. + /// + /// ** See code in examples/api/lib/cupertino/context_menu/cupertino_context_menu.1.dart ** + /// {@end-tool} + final CupertinoContextMenuBuilder builder; + + /// The default preview builder if none is provided. It makes a rectangle + /// around the child widget with rounded borders, matching the iOS 16 opened + /// context menu eyeballed on the XCode iOS simulator. + static Widget _defaultPreviewBuilder(BuildContext context, Animation animation, Widget child) { + return FittedBox( + fit: BoxFit.cover, + child: ClipRRect( + borderRadius: BorderRadius.circular(_previewBorderRadiusRatio * animation.value), + child: child, + ), + ); + } + + // TODO(mitchgoodwin): deprecate [child] with builder refactor https://github.com/flutter/flutter/issues/116306 + + /// The widget that can be "opened" with the [CupertinoContextMenu]. + /// + /// When the [CupertinoContextMenu] is long-pressed, the menu will open and + /// this widget (or the widget returned by [previewBuilder], if provided) will + /// be moved to the new route and placed inside of an [Expanded] widget. This + /// allows the child to resize to fit in its place in the new route, if it + /// doesn't size itself. + /// + /// When the [CupertinoContextMenu] is "closed", this widget acts like a + /// [Container], i.e. it does not constrain its child's size or affect its + /// position. + final Widget? child; + + /// The actions that are shown in the menu. + /// + /// These actions are typically [CupertinoContextMenuAction]s. + /// + /// This parameter must not be empty. + final List actions; + + /// If true, clicking on the [CupertinoContextMenuAction]s will + /// produce haptic feedback. + /// + /// Uses [HapticFeedback.heavyImpact] when activated. + /// Defaults to false. + final bool enableHapticFeedback; + + /// A function that returns an alternative widget to show when the + /// [CupertinoContextMenu] is open. + /// + /// If not specified, [child] will be shown. + /// + /// The preview is often used to show a slight variation of the [child]. For + /// example, the child could be given rounded corners in the preview but have + /// sharp corners when in the page. + /// + /// In addition to the current [BuildContext], the function is also called + /// with an [Animation] and the [child]. The animation goes from 0 to 1 when + /// the CupertinoContextMenu opens, and from 1 to 0 when it closes, and it can + /// be used to animate the preview in sync with this opening and closing. The + /// child parameter provides access to the child displayed when the + /// CupertinoContextMenu is closed. + /// + /// {@tool snippet} + /// + /// Below is an example of using [previewBuilder] to show an image tile that's + /// similar to each tile in the iOS iPhoto app's context menu. Several of + /// these could be used in a GridView for a similar effect. + /// + /// When opened, the child animates to show its full aspect ratio and has + /// rounded corners. The larger size of the open CupertinoContextMenu allows + /// the FittedBox to fit the entire image, even when it has a very tall or + /// wide aspect ratio compared to the square of a GridView, so this animates + /// into view as the CupertinoContextMenu is opened. The preview is swapped in + /// right when the open animation begins, which includes the rounded corners. + /// + /// ```dart + /// CupertinoContextMenu( + /// // The FittedBox in the preview here allows the image to animate its + /// // aspect ratio when the CupertinoContextMenu is animating its preview + /// // widget open and closed. + /// // ignore: deprecated_member_use + /// previewBuilder: (BuildContext context, Animation animation, Widget child) { + /// return FittedBox( + /// fit: BoxFit.cover, + /// // This ClipRRect rounds the corners of the image when the + /// // CupertinoContextMenu is open, even though it's not rounded when + /// // it's closed. It uses the given animation to animate the corners + /// // in sync with the opening animation. + /// child: ClipRRect( + /// borderRadius: BorderRadius.circular(64.0 * animation.value), + /// child: Image.asset('assets/photo.jpg'), + /// ), + /// ); + /// }, + /// actions: [ + /// CupertinoContextMenuAction( + /// child: const Text('Action one'), + /// onPressed: () {}, + /// ), + /// ], + /// child: FittedBox( + /// fit: BoxFit.cover, + /// child: Image.asset('assets/photo.jpg'), + /// ), + /// ) + /// ``` + /// + /// {@end-tool} + @Deprecated( + 'Use CupertinoContextMenu.builder instead. ' + 'This feature was deprecated after v3.4.0-34.1.pre.', + ) + final ContextMenuPreviewBuilder? previewBuilder; + + @override + State createState() => _CupertinoContextMenuState(); +} + +class _CupertinoContextMenuState extends State with TickerProviderStateMixin { + final GlobalKey _childGlobalKey = GlobalKey(); + bool _childHidden = false; + // Animates the child while it's opening. + late AnimationController _openController; + Rect? _decoyChildEndRect; + OverlayEntry? _lastOverlayEntry; + _ContextMenuRoute? _route; + final double _midpoint = CupertinoContextMenu.animationOpensAt / 2; + late final TapGestureRecognizer _tapGestureRecognizer; + + @override + void initState() { + super.initState(); + _openController = AnimationController( + duration: _previewLongPressTimeout, + vsync: this, + upperBound: CupertinoContextMenu.animationOpensAt, + ); + _openController.addStatusListener(_onDecoyAnimationStatusChange); + _tapGestureRecognizer = TapGestureRecognizer() + ..onTapCancel = _onTapCancel + ..onTapDown = _onTapDown + ..onTapUp = _onTapUp + ..onTap = _onTap; + } + + void _listenerCallback() { + if (_openController.status != AnimationStatus.reverse && + _openController.value >= _midpoint) { + if (widget.enableHapticFeedback) { + HapticFeedback.heavyImpact(); + } + _tapGestureRecognizer.resolve(GestureDisposition.accepted); + _openController.removeListener(_listenerCallback); + } + } + + // Determine the _ContextMenuLocation based on the location of the original + // child in the screen. + // + // The location of the original child is used to determine how to horizontally + // align the content of the open CupertinoContextMenu. For example, if the + // child is near the center of the screen, it will also appear in the center + // of the screen when the menu is open, and the actions will be centered below + // it. + _ContextMenuLocation get _contextMenuLocation { + final Rect childRect = _getRect(_childGlobalKey); + final double screenWidth = MediaQuery.sizeOf(context).width; + + final double center = screenWidth / 2; + final bool centerDividesChild = childRect.left < center + && childRect.right > center; + final double distanceFromCenter = (center - childRect.center.dx).abs(); + if (centerDividesChild && distanceFromCenter <= childRect.width / 4) { + return _ContextMenuLocation.center; + } + + if (childRect.center.dx > center) { + return _ContextMenuLocation.right; + } + + return _ContextMenuLocation.left; + } + + // Push the new route and open the CupertinoContextMenu overlay. + void _openContextMenu() { + setState(() { + _childHidden = true; + }); + + _route = _ContextMenuRoute( + actions: widget.actions, + barrierLabel: CupertinoLocalizations.of(context).menuDismissLabel, + filter: ui.ImageFilter.blur( + sigmaX: 5.0, + sigmaY: 5.0, + ), + contextMenuLocation: _contextMenuLocation, + previousChildRect: _decoyChildEndRect!, + builder: (BuildContext context, Animation animation) { + if (widget.child == null) { + final Animation localAnimation = Tween(begin: CupertinoContextMenu.animationOpensAt, end: 1).animate(animation); + return widget.builder(context, localAnimation); + } + return widget.previewBuilder!(context, animation, widget.child!); + }, + ); + Navigator.of(context, rootNavigator: true).push(_route!); + _route!.animation!.addStatusListener(_routeAnimationStatusListener); + } + + void _onDecoyAnimationStatusChange(AnimationStatus animationStatus) { + switch (animationStatus) { + case AnimationStatus.dismissed: + if (_route == null) { + setState(() { + _childHidden = false; + }); + } + _lastOverlayEntry?.remove(); + _lastOverlayEntry?.dispose(); + _lastOverlayEntry = null; + + case AnimationStatus.completed: + setState(() { + _childHidden = true; + }); + _openContextMenu(); + // Keep the decoy on the screen for one extra frame. We have to do this + // because _ContextMenuRoute renders its first frame offscreen. + // Otherwise there would be a visible flash when nothing is rendered for + // one frame. + SchedulerBinding.instance.addPostFrameCallback((Duration _) { + _lastOverlayEntry?.remove(); + _lastOverlayEntry?.dispose(); + _lastOverlayEntry = null; + _openController.reset(); + }, debugLabel: 'removeContextMenuDecoy'); + + case AnimationStatus.forward: + case AnimationStatus.reverse: + return; + } + } + + // Watch for when _ContextMenuRoute is closed and return to the state where + // the CupertinoContextMenu just behaves as a Container. + void _routeAnimationStatusListener(AnimationStatus status) { + if (status != AnimationStatus.dismissed) { + return; + } + if (mounted) { + setState(() { + _childHidden = false; + }); + } + _route!.animation!.removeStatusListener(_routeAnimationStatusListener); + _route = null; + } + + void _onTap() { + _openController.removeListener(_listenerCallback); + if (_openController.isAnimating && _openController.value < _midpoint) { + _openController.reverse(); + } + } + + void _onTapCancel() { + _openController.removeListener(_listenerCallback); + if (_openController.isAnimating && _openController.value < _midpoint) { + _openController.reverse(); + } + } + + void _onTapUp(TapUpDetails details) { + _openController.removeListener(_listenerCallback); + if (_openController.isAnimating && _openController.value < _midpoint) { + _openController.reverse(); + } + } + + void _onTapDown(TapDownDetails details) { + _openController.addListener(_listenerCallback); + setState(() { + _childHidden = true; + }); + + final Rect childRect = _getRect(_childGlobalKey); + _decoyChildEndRect = Rect.fromCenter( + center: childRect.center, + width: childRect.width * _kOpenScale, + height: childRect.height * _kOpenScale, + ); + + // Create a decoy child in an overlay directly on top of the original child. + // TODO(justinmc): There is a known inconsistency with native here, due to + // doing the bounce animation using a decoy in the top level Overlay. The + // decoy will pop on top of the AppBar if the child is partially behind it, + // such as a top item in a partially scrolled view. However, if we don't use + // an overlay, then the decoy will appear behind its neighboring widget when + // it expands. This may be solvable by adding a widget to Scaffold that's + // underneath the AppBar. + _lastOverlayEntry = OverlayEntry( + builder: (BuildContext context) { + return _DecoyChild( + beginRect: childRect, + controller: _openController, + endRect: _decoyChildEndRect, + builder: widget.builder, + child: widget.child, + ); + }, + ); + Overlay.of(context, rootOverlay: true, debugRequiredFor: widget).insert(_lastOverlayEntry!); + _openController.forward(); + } + + @override + Widget build(BuildContext context) { + return MouseRegion( + cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, + child: Listener( + onPointerDown: _tapGestureRecognizer.addPointer, + child: TickerMode( + enabled: !_childHidden, + child: Visibility.maintain( + key: _childGlobalKey, + visible: !_childHidden, + child: widget.builder(context, _openController), + ), + ), + ), + ); + } + + @override + void dispose() { + _tapGestureRecognizer.dispose(); + _openController.dispose(); + super.dispose(); + } +} + +// A floating copy of the CupertinoContextMenu's child. +// +// When the child is pressed, but before the CupertinoContextMenu opens, it does +// an animation where it slowly grows. This is implemented by hiding the +// original child and placing _DecoyChild on top of it in an Overlay. The use of +// an Overlay allows the _DecoyChild to appear on top of siblings of the +// original child. +class _DecoyChild extends StatefulWidget { + const _DecoyChild({ + this.beginRect, + required this.controller, + this.endRect, + this.child, + this.builder, + }); + + final Rect? beginRect; + final AnimationController controller; + final Rect? endRect; + final Widget? child; + final CupertinoContextMenuBuilder? builder; + + @override + _DecoyChildState createState() => _DecoyChildState(); +} + +class _DecoyChildState extends State<_DecoyChild> with TickerProviderStateMixin { + late Animation _rect; + late Animation _boxDecoration; + + @override + void initState() { + super.initState(); + + const double beginPause = 1.0; + const double openAnimationLength = 5.0; + const double totalOpenAnimationLength = beginPause + openAnimationLength; + final double endPause = + ((totalOpenAnimationLength * _animationDuration) / _previewLongPressTimeout.inMilliseconds) - totalOpenAnimationLength; + + // The timing on the animation was eyeballed from the XCode iOS simulator + // running iOS 16.0. + // Because the animation no longer goes from 0.0 to 1.0, but to a number + // depending on the ratio between the press animation time and the opening + // animation time, a pause needs to be added to the end of the tween + // sequence that completes that ratio. This is to allow the animation to + // fully complete as expected without doing crazy math to the _kOpenScale + // value. This change was necessary from the inclusion of the builder and + // the complete animation value that it passes along. + _rect = TweenSequence(>[ + TweenSequenceItem( + tween: RectTween( + begin: widget.beginRect, + end: widget.beginRect, + ).chain(CurveTween(curve: Curves.linear)), + weight: beginPause, + ), + TweenSequenceItem( + tween: RectTween( + begin: widget.beginRect, + end: widget.endRect, + ).chain(CurveTween(curve: Curves.easeOutSine)), + weight: openAnimationLength, + ), + TweenSequenceItem( + tween: RectTween( + begin: widget.endRect, + end: widget.endRect, + ).chain(CurveTween(curve: Curves.linear)), + weight: endPause, + ), + ]).animate(widget.controller); + + _boxDecoration = DecorationTween( + begin: const BoxDecoration( + color: Color(0xFFFFFFFF), + boxShadow: [], + ), + end: const BoxDecoration( + color: Color(0xFFFFFFFF), + boxShadow: _endBoxShadow, + ), + ).animate(CurvedAnimation( + parent: widget.controller, + curve: Interval(0.0, CupertinoContextMenu.animationOpensAt), + ), + ); + } + + Widget _buildAnimation(BuildContext context, Widget? child) { + return Positioned.fromRect( + rect: _rect.value!, + child: Container( + decoration: _boxDecoration.value, + child: widget.child, + ), + ); + } + + Widget _buildBuilder(BuildContext context, Widget? child) { + return Positioned.fromRect( + rect: _rect.value!, + child: widget.builder!(context, widget.controller), + ); + } + + @override + Widget build(BuildContext context) { + return Stack( + children: [ + AnimatedBuilder( + builder: widget.child != null ? _buildAnimation : _buildBuilder, + animation: widget.controller, + ), + ], + ); + } +} + +// The open CupertinoContextMenu modal. +class _ContextMenuRoute extends PopupRoute { + // Build a _ContextMenuRoute. + _ContextMenuRoute({ + required List actions, + required _ContextMenuLocation contextMenuLocation, + this.barrierLabel, + CupertinoContextMenuBuilder? builder, + super.filter, + required Rect previousChildRect, + super.settings, + }) : assert(actions.isNotEmpty), + _actions = actions, + _builder = builder, + _contextMenuLocation = contextMenuLocation, + _previousChildRect = previousChildRect; + + // Barrier color for a Cupertino modal barrier. + static const Color _kModalBarrierColor = Color(0x6604040F); + + final List _actions; + final CupertinoContextMenuBuilder? _builder; + final GlobalKey _childGlobalKey = GlobalKey(); + final _ContextMenuLocation _contextMenuLocation; + bool _externalOffstage = false; + bool _internalOffstage = false; + Orientation? _lastOrientation; + // The Rect of the child at the moment that the CupertinoContextMenu opens. + final Rect _previousChildRect; + double? _scale = 1.0; + final GlobalKey _sheetGlobalKey = GlobalKey(); + + static final CurveTween _curve = CurveTween( + curve: Curves.easeOutBack, + ); + static final CurveTween _curveReverse = CurveTween( + curve: Curves.easeInBack, + ); + static final RectTween _rectTween = RectTween(); + static final Animatable _rectAnimatable = _rectTween.chain(_curve); + static final RectTween _rectTweenReverse = RectTween(); + static final Animatable _rectAnimatableReverse = _rectTweenReverse + .chain( + _curveReverse, + ); + static final RectTween _sheetRectTween = RectTween(); + final Animatable _sheetRectAnimatable = _sheetRectTween.chain( + _curve, + ); + final Animatable _sheetRectAnimatableReverse = _sheetRectTween.chain( + _curveReverse, + ); + static final Tween _sheetScaleTween = Tween(); + static final Animatable _sheetScaleAnimatable = _sheetScaleTween + .chain( + _curve, + ); + static final Animatable _sheetScaleAnimatableReverse = + _sheetScaleTween.chain( + _curveReverse, + ); + final Tween _opacityTween = Tween(begin: 0.0, end: 1.0); + late Animation _sheetOpacity; + + @override + final String? barrierLabel; + + @override + Color get barrierColor => _kModalBarrierColor; + + @override + bool get barrierDismissible => true; + + @override + bool get semanticsDismissible => false; + + @override + Duration get transitionDuration => _kModalPopupTransitionDuration; + + // Getting the RenderBox doesn't include the scale from the Transform.scale, + // so it's manually accounted for here. + static Rect _getScaledRect(GlobalKey globalKey, double scale) { + final Rect childRect = _getRect(globalKey); + final Size sizeScaled = childRect.size * scale; + final Offset offsetScaled = Offset( + childRect.left + (childRect.size.width - sizeScaled.width) / 2, + childRect.top + (childRect.size.height - sizeScaled.height) / 2, + ); + return offsetScaled & sizeScaled; + } + + // Get the alignment for the _ContextMenuSheet's Transform.scale based on the + // contextMenuLocation. + static AlignmentDirectional getSheetAlignment(_ContextMenuLocation contextMenuLocation) { + switch (contextMenuLocation) { + case _ContextMenuLocation.center: + return AlignmentDirectional.topCenter; + case _ContextMenuLocation.right: + return AlignmentDirectional.topEnd; + case _ContextMenuLocation.left: + return AlignmentDirectional.topStart; + } + } + + // The place to start the sheetRect animation from. + static Rect _getSheetRectBegin(Orientation? orientation, _ContextMenuLocation contextMenuLocation, Rect childRect, Rect sheetRect) { + switch (contextMenuLocation) { + case _ContextMenuLocation.center: + final Offset target = orientation == Orientation.portrait + ? childRect.bottomCenter + : childRect.topCenter; + final Offset centered = target - Offset(sheetRect.width / 2, 0.0); + return centered & sheetRect.size; + case _ContextMenuLocation.right: + final Offset target = orientation == Orientation.portrait + ? childRect.bottomRight + : childRect.topRight; + return (target - Offset(sheetRect.width, 0.0)) & sheetRect.size; + case _ContextMenuLocation.left: + final Offset target = orientation == Orientation.portrait + ? childRect.bottomLeft + : childRect.topLeft; + return target & sheetRect.size; + } + } + + void _onDismiss(BuildContext context, double scale, double opacity) { + _scale = scale; + _opacityTween.end = opacity; + _sheetOpacity = _opacityTween.animate(CurvedAnimation( + parent: animation!, + curve: const Interval(0.9, 1.0), + )); + Navigator.of(context).pop(); + } + + // Take measurements on the child and _ContextMenuSheet and update the + // animation tweens to match. + void _updateTweenRects() { + final Rect childRect = _scale == null + ? _getRect(_childGlobalKey) + : _getScaledRect(_childGlobalKey, _scale!); + _rectTween.begin = _previousChildRect; + _rectTween.end = childRect; + + // When opening, the transition happens from the end of the child's bounce + // animation to the final state. When closing, it goes from the final state + // to the original position before the bounce. + final Rect childRectOriginal = Rect.fromCenter( + center: _previousChildRect.center, + width: _previousChildRect.width / _kOpenScale, + height: _previousChildRect.height / _kOpenScale, + ); + + final Rect sheetRect = _getRect(_sheetGlobalKey); + final Rect sheetRectBegin = _getSheetRectBegin( + _lastOrientation, + _contextMenuLocation, + childRectOriginal, + sheetRect, + ); + _sheetRectTween.begin = sheetRectBegin; + _sheetRectTween.end = sheetRect; + _sheetScaleTween.begin = 0.0; + _sheetScaleTween.end = _scale; + + _rectTweenReverse.begin = childRectOriginal; + _rectTweenReverse.end = childRect; + } + + void _setOffstageInternally() { + super.offstage = _externalOffstage || _internalOffstage; + // It's necessary to call changedInternalState to get the backdrop to + // update. + changedInternalState(); + } + + @override + bool didPop(T? result) { + _updateTweenRects(); + return super.didPop(result); + } + + @override + set offstage(bool value) { + _externalOffstage = value; + _setOffstageInternally(); + } + + @override + TickerFuture didPush() { + _internalOffstage = true; + _setOffstageInternally(); + + // Render one frame offstage in the final position so that we can take + // measurements of its layout and then animate to them. + SchedulerBinding.instance.addPostFrameCallback((Duration _) { + _updateTweenRects(); + _internalOffstage = false; + _setOffstageInternally(); + }, debugLabel: 'renderContextMenuRouteOffstage'); + return super.didPush(); + } + + @override + Animation createAnimation() { + final Animation animation = super.createAnimation(); + _sheetOpacity = _opacityTween.animate(CurvedAnimation( + parent: animation, + curve: Curves.linear, + )); + return animation; + } + + @override + Widget buildPage(BuildContext context, Animation animation, Animation secondaryAnimation) { + // This is usually used to build the "page", which is then passed to + // buildTransitions as child, the idea being that buildTransitions will + // animate the entire page into the scene. In the case of _ContextMenuRoute, + // two individual pieces of the page are animated into the scene in + // buildTransitions, and a SizedBox.shrink() is returned here. + return const SizedBox.shrink(); + } + + @override + Widget buildTransitions(BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { + return OrientationBuilder( + builder: (BuildContext context, Orientation orientation) { + _lastOrientation = orientation; + + // While the animation is running, render everything in a Stack so that + // they're movable. + if (!animation.isCompleted) { + final bool reverse = animation.status == AnimationStatus.reverse; + final Rect rect = reverse + ? _rectAnimatableReverse.evaluate(animation)! + : _rectAnimatable.evaluate(animation)!; + final Rect sheetRect = reverse + ? _sheetRectAnimatableReverse.evaluate(animation)! + : _sheetRectAnimatable.evaluate(animation)!; + final double sheetScale = reverse + ? _sheetScaleAnimatableReverse.evaluate(animation) + : _sheetScaleAnimatable.evaluate(animation); + return Stack( + children: [ + Positioned.fromRect( + rect: sheetRect, + child: FadeTransition( + opacity: _sheetOpacity, + child: Transform.scale( + alignment: getSheetAlignment(_contextMenuLocation), + scale: sheetScale, + child: _ContextMenuSheet( + key: _sheetGlobalKey, + actions: _actions, + contextMenuLocation: _contextMenuLocation, + orientation: orientation, + ), + ), + ), + ), + Positioned.fromRect( + key: _childGlobalKey, + rect: rect, + child: _builder!(context, animation), + ), + ], + ); + } + + // When the animation is done, just render everything in a static layout + // in the final position. + return _ContextMenuRouteStatic( + actions: _actions, + childGlobalKey: _childGlobalKey, + contextMenuLocation: _contextMenuLocation, + onDismiss: _onDismiss, + orientation: orientation, + sheetGlobalKey: _sheetGlobalKey, + child: _builder!(context, animation), + ); + }, + ); + } +} + +// The final state of the _ContextMenuRoute after animating in and before +// animating out. +class _ContextMenuRouteStatic extends StatefulWidget { + const _ContextMenuRouteStatic({ + this.actions, + required this.child, + this.childGlobalKey, + required this.contextMenuLocation, + this.onDismiss, + required this.orientation, + this.sheetGlobalKey, + }); + + final List? actions; + final Widget child; + final GlobalKey? childGlobalKey; + final _ContextMenuLocation contextMenuLocation; + final _DismissCallback? onDismiss; + final Orientation orientation; + final GlobalKey? sheetGlobalKey; + + @override + _ContextMenuRouteStaticState createState() => _ContextMenuRouteStaticState(); +} + +class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with TickerProviderStateMixin { + // The child is scaled down as it is dragged down until it hits this minimum + // value. + static const double _kMinScale = 0.8; + // The CupertinoContextMenuSheet disappears at this scale. + static const double _kSheetScaleThreshold = 0.9; + static const double _kPadding = 20.0; + static const double _kDamping = 400.0; + static const Duration _kMoveControllerDuration = Duration(milliseconds: 600); + + late Offset _dragOffset; + double _lastScale = 1.0; + late AnimationController _moveController; + late AnimationController _sheetController; + late Animation _moveAnimation; + late Animation _sheetScaleAnimation; + late Animation _sheetOpacityAnimation; + + // The scale of the child changes as a function of the distance it is dragged. + static double _getScale(Orientation orientation, double maxDragDistance, double dy) { + final double dyDirectional = dy <= 0.0 ? dy : -dy; + return math.max( + _kMinScale, + (maxDragDistance + dyDirectional) / maxDragDistance, + ); + } + + void _onPanStart(DragStartDetails details) { + _moveController.value = 1.0; + _setDragOffset(Offset.zero); + } + + void _onPanUpdate(DragUpdateDetails details) { + _setDragOffset(_dragOffset + details.delta); + } + + void _onPanEnd(DragEndDetails details) { + // If flung, animate a bit before handling the potential dismiss. + if (details.velocity.pixelsPerSecond.dy.abs() >= kMinFlingVelocity) { + final bool flingIsAway = details.velocity.pixelsPerSecond.dy > 0; + final double finalPosition = flingIsAway + ? _moveAnimation.value.dy + 100.0 + : 0.0; + + if (flingIsAway && _sheetController.status != AnimationStatus.forward) { + _sheetController.forward(); + } else if (!flingIsAway && _sheetController.status != AnimationStatus.reverse) { + _sheetController.reverse(); + } + + _moveAnimation = Tween( + begin: Offset(0.0, _moveAnimation.value.dy), + end: Offset(0.0, finalPosition), + ).animate(_moveController); + _moveController.reset(); + _moveController.duration = const Duration( + milliseconds: 64, + ); + _moveController.forward(); + _moveController.addStatusListener(_flingStatusListener); + return; + } + + // Dismiss if the drag is enough to scale down all the way. + if (_lastScale == _kMinScale) { + widget.onDismiss!(context, _lastScale, _sheetOpacityAnimation.value); + return; + } + + // Otherwise animate back home. + _moveController.addListener(_moveListener); + _moveController.reverse(); + } + + void _moveListener() { + // When the scale passes the threshold, animate the sheet back in. + if (_lastScale > _kSheetScaleThreshold) { + _moveController.removeListener(_moveListener); + if (_sheetController.status != AnimationStatus.dismissed) { + _sheetController.reverse(); + } + } + } + + void _flingStatusListener(AnimationStatus status) { + if (status != AnimationStatus.completed) { + return; + } + + // Reset the duration back to its original value. + _moveController.duration = _kMoveControllerDuration; + + _moveController.removeStatusListener(_flingStatusListener); + // If it was a fling back to the start, it has reset itself, and it should + // not be dismissed. + if (_moveAnimation.value.dy == 0.0) { + return; + } + widget.onDismiss!(context, _lastScale, _sheetOpacityAnimation.value); + } + + Alignment _getChildAlignment(Orientation orientation, _ContextMenuLocation contextMenuLocation) { + switch (contextMenuLocation) { + case _ContextMenuLocation.center: + return orientation == Orientation.portrait + ? Alignment.bottomCenter + : Alignment.topRight; + case _ContextMenuLocation.right: + return orientation == Orientation.portrait + ? Alignment.bottomCenter + : Alignment.topLeft; + case _ContextMenuLocation.left: + return orientation == Orientation.portrait + ? Alignment.bottomCenter + : Alignment.topRight; + } + } + + void _setDragOffset(Offset dragOffset) { + // Allow horizontal and negative vertical movement, but damp it. + final double endX = _kPadding * dragOffset.dx / _kDamping; + final double endY = dragOffset.dy >= 0.0 + ? dragOffset.dy + : _kPadding * dragOffset.dy / _kDamping; + setState(() { + _dragOffset = dragOffset; + _moveAnimation = Tween( + begin: Offset.zero, + end: Offset( + clampDouble(endX, -_kPadding, _kPadding), + endY, + ), + ).animate( + CurvedAnimation( + parent: _moveController, + curve: Curves.elasticIn, + ), + ); + + // Fade the _ContextMenuSheet out or in, if needed. + if (_lastScale <= _kSheetScaleThreshold + && _sheetController.status != AnimationStatus.forward + && _sheetScaleAnimation.value != 0.0) { + _sheetController.forward(); + } else if (_lastScale > _kSheetScaleThreshold + && _sheetController.status != AnimationStatus.reverse + && _sheetScaleAnimation.value != 1.0) { + _sheetController.reverse(); + } + }); + } + + // The order and alignment of the _ContextMenuSheet and the child depend on + // both the orientation of the screen as well as the position on the screen of + // the original child. + List _getChildren(Orientation orientation, _ContextMenuLocation contextMenuLocation) { + final Expanded child = Expanded( + child: Align( + alignment: _getChildAlignment( + widget.orientation, + widget.contextMenuLocation, + ), + child: AnimatedBuilder( + animation: _moveController, + builder: _buildChildAnimation, + child: widget.child, + ), + ), + ); + const SizedBox spacer = SizedBox( + width: _kPadding, + height: _kPadding, + ); + final Expanded sheet = Expanded( + child: AnimatedBuilder( + animation: _sheetController, + builder: _buildSheetAnimation, + child: _ContextMenuSheet( + key: widget.sheetGlobalKey, + actions: widget.actions!, + contextMenuLocation: widget.contextMenuLocation, + orientation: widget.orientation, + ), + ), + ); + + switch (contextMenuLocation) { + case _ContextMenuLocation.center: + return [child, spacer, sheet]; + case _ContextMenuLocation.right: + return orientation == Orientation.portrait + ? [child, spacer, sheet] + : [sheet, spacer, child]; + case _ContextMenuLocation.left: + return [child, spacer, sheet]; + } + } + + // Build the animation for the _ContextMenuSheet. + Widget _buildSheetAnimation(BuildContext context, Widget? child) { + return Transform.scale( + alignment: _ContextMenuRoute.getSheetAlignment(widget.contextMenuLocation), + scale: _sheetScaleAnimation.value, + child: FadeTransition( + opacity: _sheetOpacityAnimation, + child: child, + ), + ); + } + + // Build the animation for the child. + Widget _buildChildAnimation(BuildContext context, Widget? child) { + _lastScale = _getScale( + widget.orientation, + MediaQuery.sizeOf(context).height, + _moveAnimation.value.dy, + ); + return Transform.scale( + key: widget.childGlobalKey, + scale: _lastScale, + child: child, + ); + } + + // Build the animation for the overall draggable dismissible content. + Widget _buildAnimation(BuildContext context, Widget? child) { + return Transform.translate( + offset: _moveAnimation.value, + child: child, + ); + } + + @override + void initState() { + super.initState(); + _moveController = AnimationController( + duration: _kMoveControllerDuration, + value: 1.0, + vsync: this, + ); + _sheetController = AnimationController( + duration: const Duration(milliseconds: 100), + reverseDuration: const Duration(milliseconds: 300), + vsync: this, + ); + _sheetScaleAnimation = Tween( + begin: 1.0, + end: 0.0, + ).animate( + CurvedAnimation( + parent: _sheetController, + curve: Curves.linear, + reverseCurve: Curves.easeInBack, + ), + ); + _sheetOpacityAnimation = Tween( + begin: 1.0, + end: 0.0, + ).animate(_sheetController); + _setDragOffset(Offset.zero); + } + + @override + void dispose() { + _moveController.dispose(); + _sheetController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final List children = _getChildren( + widget.orientation, + widget.contextMenuLocation, + ); + + return SafeArea( + child: Align( + alignment: Alignment.topLeft, + child: GestureDetector( + onPanEnd: _onPanEnd, + onPanStart: _onPanStart, + onPanUpdate: _onPanUpdate, + child: AnimatedBuilder( + animation: _moveController, + builder: _buildAnimation, + child: widget.orientation == Orientation.portrait + ? Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: children, + ) + : Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: children, + ), + ), + ), + ), + ); + } +} + +// The menu that displays when CupertinoContextMenu is open. It consists of a +// list of actions that are typically CupertinoContextMenuActions. +class _ContextMenuSheet extends StatelessWidget { + _ContextMenuSheet({ + super.key, + required this.actions, + required _ContextMenuLocation contextMenuLocation, + required Orientation orientation, + }) : assert(actions.isNotEmpty), + _contextMenuLocation = contextMenuLocation, + _orientation = orientation; + + final List actions; + final _ContextMenuLocation _contextMenuLocation; + final Orientation _orientation; + + static const double _kMenuWidth = 250.0; + + // Get the children, whose order depends on orientation and + // contextMenuLocation. + List getChildren(BuildContext context) { + final Widget menu = SizedBox( + width: _kMenuWidth, + child: IntrinsicHeight( + child: ClipRRect( + borderRadius: const BorderRadius.all(Radius.circular(13.0)), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + actions.first, + for (final Widget action in actions.skip(1)) + DecoratedBox( + decoration: BoxDecoration( + border: Border( + top: BorderSide( + color: CupertinoDynamicColor.resolve( + _borderColor, + context, + ), + width: 0.4, + ), + ), + ), + position: DecorationPosition.foreground, + child: action, + ), + ], + ), + ), + ), + ); + + switch (_contextMenuLocation) { + case _ContextMenuLocation.center: + return _orientation == Orientation.portrait + ? [ + const Spacer(), + menu, + const Spacer(), + ] + : [ + menu, + const Spacer(), + ]; + case _ContextMenuLocation.right: + return [ + const Spacer(), + menu, + ]; + case _ContextMenuLocation.left: + return [ + menu, + const Spacer(), + ]; + } + } + + @override + Widget build(BuildContext context) { + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: getChildren(context), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/context_menu_action.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/context_menu_action.dart new file mode 100644 index 0000000000000000000000000000000000000000..fc45889171bd636b0993ee9902c8a3d4377ca1fd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/context_menu_action.dart @@ -0,0 +1,157 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; +import 'colors.dart'; + +/// A button in a _ContextMenuSheet. +/// +/// A typical use case is to pass a [Text] as the [child] here, but be sure to +/// use [TextOverflow.ellipsis] for the [Text.overflow] field if the text may be +/// long, as without it the text will wrap to the next line. +class CupertinoContextMenuAction extends StatefulWidget { + /// Construct a CupertinoContextMenuAction. + const CupertinoContextMenuAction({ + super.key, + required this.child, + this.isDefaultAction = false, + this.isDestructiveAction = false, + this.onPressed, + this.trailingIcon, + }); + + /// The widget that will be placed inside the action. + final Widget child; + + /// Indicates whether this action should receive the style of an emphasized, + /// default action. + final bool isDefaultAction; + + /// Indicates whether this action should receive the style of a destructive + /// action. + final bool isDestructiveAction; + + /// Called when the action is pressed. + final VoidCallback? onPressed; + + /// An optional icon to display to the right of the child. + /// + /// Will be colored in the same way as the [TextStyle] used for [child] (for + /// example, if using [isDestructiveAction]). + final IconData? trailingIcon; + + @override + State createState() => _CupertinoContextMenuActionState(); +} + +class _CupertinoContextMenuActionState extends State { + static const Color _kBackgroundColor = CupertinoDynamicColor.withBrightness( + color: Color(0xFFF1F1F1), + darkColor: Color(0xFF212122), + ); + static const Color _kBackgroundColorPressed = CupertinoDynamicColor.withBrightness( + color: Color(0xFFDDDDDD), + darkColor: Color(0xFF3F3F40), + ); + static const double _kButtonHeight = 43; + static const TextStyle _kActionSheetActionStyle = TextStyle( + fontFamily: 'CupertinoSystemText', + inherit: false, + fontSize: 16.0, + fontWeight: FontWeight.w400, + color: CupertinoColors.black, + textBaseline: TextBaseline.alphabetic, + ); + + final GlobalKey _globalKey = GlobalKey(); + bool _isPressed = false; + + void onTapDown(TapDownDetails details) { + setState(() { + _isPressed = true; + }); + } + + void onTapUp(TapUpDetails details) { + setState(() { + _isPressed = false; + }); + } + + void onTapCancel() { + setState(() { + _isPressed = false; + }); + } + + TextStyle get _textStyle { + if (widget.isDefaultAction) { + return _kActionSheetActionStyle.copyWith( + fontWeight: FontWeight.w600, + ); + } + if (widget.isDestructiveAction) { + return _kActionSheetActionStyle.copyWith( + color: CupertinoColors.destructiveRed, + ); + } + return _kActionSheetActionStyle.copyWith( + color: CupertinoDynamicColor.resolve(CupertinoColors.label, context) + ); + } + + @override + Widget build(BuildContext context) { + return MouseRegion( + cursor: widget.onPressed != null && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, + child: GestureDetector( + key: _globalKey, + onTapDown: onTapDown, + onTapUp: onTapUp, + onTapCancel: onTapCancel, + onTap: widget.onPressed, + behavior: HitTestBehavior.opaque, + child: ConstrainedBox( + constraints: const BoxConstraints( + minHeight: _kButtonHeight, + ), + child: Semantics( + button: true, + child: Container( + decoration: BoxDecoration( + color: _isPressed + ? CupertinoDynamicColor.resolve(_kBackgroundColorPressed, context) + : CupertinoDynamicColor.resolve(_kBackgroundColor, context), + ), + padding: const EdgeInsets.only( + top: 8, + bottom: 8, + left: 15.5, + right: 17.5, + ), + child: DefaultTextStyle( + style: _textStyle, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Flexible( + child: widget.child, + ), + if (widget.trailingIcon != null) + Icon( + widget.trailingIcon, + color: _textStyle.color, + size: 21.0, + ), + ], + ), + ), + ), + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/date_picker.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/date_picker.dart new file mode 100644 index 0000000000000000000000000000000000000000..1505dac681e3645d731fd505325d1bc4d54a9318 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/date_picker.dart @@ -0,0 +1,2544 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/scheduler.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'localizations.dart'; +import 'picker.dart'; +import 'theme.dart'; + +// Values derived from https://developer.apple.com/design/resources/ and on iOS +// simulators with "Debug View Hierarchy". +const double _kItemExtent = 32.0; +// From the picker's intrinsic content size constraint. +const double _kPickerWidth = 320.0; +const double _kPickerHeight = 216.0; +const bool _kUseMagnifier = true; +const double _kMagnification = 2.35/2.1; +const double _kDatePickerPadSize = 12.0; +// The density of a date picker is different from a generic picker. +// Eyeballed from iOS. +const double _kSqueeze = 1.25; + +const TextStyle _kDefaultPickerTextStyle = TextStyle( + letterSpacing: -0.83, +); + +// The item height is 32 and the magnifier height is 34, from +// iOS simulators with "Debug View Hierarchy". +// And the magnified fontSize by [_kTimerPickerMagnification] conforms to the +// iOS 14 native style by eyeball test. +const double _kTimerPickerMagnification = 34 / 32; +// Minimum horizontal padding between [CupertinoTimerPicker] +// +// It shouldn't actually be hard-coded for direct use, and the perfect solution +// should be to calculate the values that match the magnified values by +// offAxisFraction and _kSqueeze. +// Such calculations are complex, so we'll hard-code them for now. +const double _kTimerPickerMinHorizontalPadding = 30; +// Half of the horizontal padding value between the timer picker's columns. +const double _kTimerPickerHalfColumnPadding = 4; +// The horizontal padding between the timer picker's number label and its +// corresponding unit label. +const double _kTimerPickerLabelPadSize = 6; +const double _kTimerPickerLabelFontSize = 17.0; + +// The width of each column of the countdown time picker. +const double _kTimerPickerColumnIntrinsicWidth = 106; + +TextStyle _themeTextStyle(BuildContext context, { bool isValid = true }) { + final TextStyle style = CupertinoTheme.of(context).textTheme.dateTimePickerTextStyle; + return isValid + ? style.copyWith(color: CupertinoDynamicColor.maybeResolve(style.color, context)) + : style.copyWith(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context)); +} + +void _animateColumnControllerToItem(FixedExtentScrollController controller, int targetItem) { + controller.animateToItem( + targetItem, + curve: Curves.easeInOut, + duration: const Duration(milliseconds: 200), + ); +} + +const Widget _startSelectionOverlay = CupertinoPickerDefaultSelectionOverlay(capEndEdge: false); +const Widget _centerSelectionOverlay = CupertinoPickerDefaultSelectionOverlay(capStartEdge: false, capEndEdge: false); +const Widget _endSelectionOverlay = CupertinoPickerDefaultSelectionOverlay(capStartEdge: false); + +// Lays out the date picker based on how much space each single column needs. +// +// Each column is a child of this delegate, indexed from 0 to number of columns - 1. +// Each column will be padded horizontally by 12.0 both left and right. +// +// The picker will be placed in the center, and the leftmost and rightmost +// column will be extended equally to the remaining width. +class _DatePickerLayoutDelegate extends MultiChildLayoutDelegate { + _DatePickerLayoutDelegate({ + required this.columnWidths, + required this.textDirectionFactor, + required this.maxWidth, + }); + + // The list containing widths of all columns. + final List columnWidths; + + // textDirectionFactor is 1 if text is written left to right, and -1 if right to left. + final int textDirectionFactor; + + // The max width the children should reach to avoid bending outwards. + final double maxWidth; + + @override + void performLayout(Size size) { + double remainingWidth = maxWidth < size.width ? maxWidth : size.width; + + double currentHorizontalOffset = (size.width - remainingWidth) / 2; + + for (int i = 0; i < columnWidths.length; i++) { + remainingWidth -= columnWidths[i] + _kDatePickerPadSize * 2; + } + + for (int i = 0; i < columnWidths.length; i++) { + final int index = textDirectionFactor == 1 ? i : columnWidths.length - i - 1; + + double childWidth = columnWidths[index] + _kDatePickerPadSize * 2; + if (index == 0 || index == columnWidths.length - 1) { + childWidth += remainingWidth / 2; + } + + // We can't actually assert here because it would break things badly for + // semantics, which will expect that we laid things out here. + assert(() { + if (childWidth < 0) { + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError( + 'Insufficient horizontal space to render the ' + 'CupertinoDatePicker because the parent is too narrow at ' + '${size.width}px.\n' + 'An additional ${-remainingWidth}px is needed to avoid ' + 'overlapping columns.', + ), + ), + ); + } + return true; + }()); + layoutChild(index, BoxConstraints.tight(Size(math.max(0.0, childWidth), size.height))); + positionChild(index, Offset(currentHorizontalOffset, 0.0)); + + currentHorizontalOffset += childWidth; + } + } + + @override + bool shouldRelayout(_DatePickerLayoutDelegate oldDelegate) { + return columnWidths != oldDelegate.columnWidths + || textDirectionFactor != oldDelegate.textDirectionFactor; + } +} + +/// Different display modes of [CupertinoDatePicker]. +/// +/// See also: +/// +/// * [CupertinoDatePicker], the class that implements different display modes +/// of the iOS-style date picker. +/// * [CupertinoPicker], the class that implements a content agnostic spinner UI. +enum CupertinoDatePickerMode { + /// Mode that shows the date in hour, minute, and (optional) an AM/PM designation. + /// The AM/PM designation is shown only if [CupertinoDatePicker] does not use 24h format. + /// Column order is subject to internationalization. + /// + /// Example: ` 4 | 14 | PM `. + time, + /// Mode that shows the date in month, day of month, and year. + /// Name of month is spelled in full. + /// Column order is subject to internationalization. + /// + /// Example: ` July | 13 | 2012 `. + date, + /// Mode that shows the date as day of the week, month, day of month and + /// the time in hour, minute, and (optional) an AM/PM designation. + /// The AM/PM designation is shown only if [CupertinoDatePicker] does not use 24h format. + /// Column order is subject to internationalization. + /// + /// Example: ` Fri Jul 13 | 4 | 14 | PM ` + dateAndTime, + /// Mode that shows the date in month and year. + /// Name of month is spelled in full. + /// Column order is subject to internationalization. + /// + /// Example: ` July | 2012 `. + monthYear, +} + +// Different types of column in CupertinoDatePicker. +enum _PickerColumnType { + // Day of month column in date mode. + dayOfMonth, + // Month column in date mode. + month, + // Year column in date mode. + year, + // Medium date column in dateAndTime mode. + date, + // Hour column in time and dateAndTime mode. + hour, + // minute column in time and dateAndTime mode. + minute, + // AM/PM column in time and dateAndTime mode. + dayPeriod, +} + +/// A date picker widget in iOS style. +/// +/// There are several modes of the date picker listed in [CupertinoDatePickerMode]. +/// +/// The class will display its children as consecutive columns. Its children +/// order is based on internationalization, or the [dateOrder] property if specified. +/// +/// Example of the picker in date mode: +/// +/// * US-English: `| July | 13 | 2012 |` +/// * Vietnamese: `| 13 | Tháng 7 | 2012 |` +/// +/// Can be used with [showCupertinoModalPopup] to display the picker modally at +/// the bottom of the screen. +/// +/// Sizes itself to its parent and may not render correctly if not given the +/// full screen width. Content texts are shown with +/// [CupertinoTextThemeData.dateTimePickerTextStyle]. +/// +/// {@tool dartpad} +/// This sample shows how to implement CupertinoDatePicker with different picker modes. +/// We can provide initial dateTime value for the picker to display. When user changes +/// the drag the date or time wheels, the picker will call onDateTimeChanged callback. +/// +/// CupertinoDatePicker can be displayed directly on a screen or in a popup. +/// +/// ** See code in examples/api/lib/cupertino/date_picker/cupertino_date_picker.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoTimerPicker], the class that implements the iOS-style timer picker. +/// * [CupertinoPicker], the class that implements a content agnostic spinner UI. +/// * +class CupertinoDatePicker extends StatefulWidget { + /// Constructs an iOS style date picker. + /// + /// [mode] is one of the mode listed in [CupertinoDatePickerMode] and defaults + /// to [CupertinoDatePickerMode.dateAndTime]. + /// + /// [onDateTimeChanged] is the callback called when the selected date or time + /// changes. When in [CupertinoDatePickerMode.time] mode, the year, month and + /// day will be the same as [initialDateTime]. When in + /// [CupertinoDatePickerMode.date] mode, this callback will always report the + /// start time of the currently selected day. When in + /// [CupertinoDatePickerMode.monthYear] mode, the day and time will be the + /// start time of the first day of the month. + /// + /// [initialDateTime] is the initial date time of the picker. Defaults to the + /// present date and time. The present must conform to the intervals set in + /// [minimumDate], [maximumDate], [minimumYear], and [maximumYear]. + /// + /// [minimumDate] is the minimum selectable [DateTime] of the picker. When set + /// to null, the picker does not limit the minimum [DateTime] the user can pick. + /// In [CupertinoDatePickerMode.time] mode, [minimumDate] should typically be + /// on the same date as [initialDateTime], as the picker will not limit the + /// minimum time the user can pick if it's set to a date earlier than that. + /// + /// [maximumDate] is the maximum selectable [DateTime] of the picker. When set + /// to null, the picker does not limit the maximum [DateTime] the user can pick. + /// In [CupertinoDatePickerMode.time] mode, [maximumDate] should typically be + /// on the same date as [initialDateTime], as the picker will not limit the + /// maximum time the user can pick if it's set to a date later than that. + /// + /// [minimumYear] is the minimum year that the picker can be scrolled to in + /// [CupertinoDatePickerMode.date] mode. Defaults to 1. + /// + /// [maximumYear] is the maximum year that the picker can be scrolled to in + /// [CupertinoDatePickerMode.date] mode. Null if there's no limit. + /// + /// [minuteInterval] is the granularity of the minute spinner. Must be a + /// positive integer factor of 60. + /// + /// [use24hFormat] decides whether 24 hour format is used. Defaults to false. + /// + /// [dateOrder] determines the order of the columns inside [CupertinoDatePicker] + /// in [CupertinoDatePickerMode.date] and [CupertinoDatePickerMode.monthYear] + /// mode. When using monthYear mode, both [DatePickerDateOrder.dmy] and + /// [DatePickerDateOrder.mdy] will result in the month|year order. + /// Defaults to the locale's default date format/order. + CupertinoDatePicker({ + super.key, + this.mode = CupertinoDatePickerMode.dateAndTime, + required this.onDateTimeChanged, + DateTime? initialDateTime, + this.minimumDate, + this.maximumDate, + this.minimumYear = 1, + this.maximumYear, + this.minuteInterval = 1, + this.use24hFormat = false, + this.dateOrder, + this.backgroundColor, + this.showDayOfWeek = false, + this.itemExtent = _kItemExtent, + }) : initialDateTime = initialDateTime ?? DateTime.now(), + assert( + itemExtent > 0, + 'item extent should be greater than 0', + ), + assert( + minuteInterval > 0 && 60 % minuteInterval == 0, + 'minute interval is not a positive integer factor of 60', + ) { + assert( + mode != CupertinoDatePickerMode.dateAndTime || minimumDate == null || !this.initialDateTime.isBefore(minimumDate!), + 'initial date is before minimum date', + ); + assert( + mode != CupertinoDatePickerMode.dateAndTime || maximumDate == null || !this.initialDateTime.isAfter(maximumDate!), + 'initial date is after maximum date', + ); + assert( + (mode != CupertinoDatePickerMode.date && mode != CupertinoDatePickerMode.monthYear) || (minimumYear >= 1 && this.initialDateTime.year >= minimumYear), + 'initial year is not greater than minimum year, or minimum year is not positive', + ); + assert( + (mode != CupertinoDatePickerMode.date && mode != CupertinoDatePickerMode.monthYear) || maximumYear == null || this.initialDateTime.year <= maximumYear!, + 'initial year is not smaller than maximum year', + ); + assert( + (mode != CupertinoDatePickerMode.date && mode != CupertinoDatePickerMode.monthYear) || minimumDate == null || !minimumDate!.isAfter(this.initialDateTime), + 'initial date ${this.initialDateTime} is not greater than or equal to minimumDate $minimumDate', + ); + assert( + (mode != CupertinoDatePickerMode.date && mode != CupertinoDatePickerMode.monthYear) || maximumDate == null || !maximumDate!.isBefore(this.initialDateTime), + 'initial date ${this.initialDateTime} is not less than or equal to maximumDate $maximumDate', + ); + assert( + this.initialDateTime.minute % minuteInterval == 0, + 'initial minute is not divisible by minute interval', + ); + } + + /// The mode of the date picker as one of [CupertinoDatePickerMode]. Defaults + /// to [CupertinoDatePickerMode.dateAndTime]. Value cannot change after + /// initial build. + final CupertinoDatePickerMode mode; + + /// The initial date and/or time of the picker. Defaults to the present date + /// and time. The present must conform to the intervals set in [minimumDate], + /// [maximumDate], [minimumYear], and [maximumYear]. + /// + /// Changing this value after the initial build will not affect the currently + /// selected date time. + final DateTime initialDateTime; + + /// The minimum selectable date that the picker can settle on. + /// + /// When non-null, the user can still scroll the picker to [DateTime]s earlier + /// than [minimumDate], but the [onDateTimeChanged] will not be called on + /// these [DateTime]s. Once let go, the picker will scroll back to [minimumDate]. + /// + /// In [CupertinoDatePickerMode.time] mode, a time becomes unselectable if the + /// [DateTime] produced by combining that particular time and the date part of + /// [initialDateTime] is earlier than [minimumDate]. So typically [minimumDate] + /// needs to be set to a [DateTime] that is on the same date as [initialDateTime]. + /// + /// Defaults to null. When set to null, the picker does not impose a limit on + /// the earliest [DateTime] the user can select. + final DateTime? minimumDate; + + /// The maximum selectable date that the picker can settle on. + /// + /// When non-null, the user can still scroll the picker to [DateTime]s later + /// than [maximumDate], but the [onDateTimeChanged] will not be called on + /// these [DateTime]s. Once let go, the picker will scroll back to [maximumDate]. + /// + /// In [CupertinoDatePickerMode.time] mode, a time becomes unselectable if the + /// [DateTime] produced by combining that particular time and the date part of + /// [initialDateTime] is later than [maximumDate]. So typically [maximumDate] + /// needs to be set to a [DateTime] that is on the same date as [initialDateTime]. + /// + /// Defaults to null. When set to null, the picker does not impose a limit on + /// the latest [DateTime] the user can select. + final DateTime? maximumDate; + + /// Minimum year that the picker can be scrolled to in + /// [CupertinoDatePickerMode.date] mode. Defaults to 1. + final int minimumYear; + + /// Maximum year that the picker can be scrolled to in + /// [CupertinoDatePickerMode.date] mode. Null if there's no limit. + final int? maximumYear; + + /// The granularity of the minutes spinner, if it is shown in the current mode. + /// Must be an integer factor of 60. + final int minuteInterval; + + /// Whether to use 24 hour format. Defaults to false. + final bool use24hFormat; + + /// Determines the order of the columns inside [CupertinoDatePicker] in + /// [CupertinoDatePickerMode.date] and [CupertinoDatePickerMode.monthYear] + /// mode. When using monthYear mode, both [DatePickerDateOrder.dmy] and + /// [DatePickerDateOrder.mdy] will result in the month|year order. + /// Defaults to the locale's default date format/order. + final DatePickerDateOrder? dateOrder; + + /// Callback called when the selected date and/or time changes. If the new + /// selected [DateTime] is not valid, or is not in the [minimumDate] through + /// [maximumDate] range, this callback will not be called. + final ValueChanged onDateTimeChanged; + + /// Background color of date picker. + /// + /// Defaults to null, which disables background painting entirely. + final Color? backgroundColor; + + /// Whether to to show day of week alongside day. Defaults to false. + final bool showDayOfWeek; + + /// {@macro flutter.cupertino.picker.itemExtent} + /// + /// Defaults to a value that matches the default iOS date picker wheel. + final double itemExtent; + + @override + State createState() { // ignore: no_logic_in_create_state, https://github.com/flutter/flutter/issues/70499 + // The `time` mode and `dateAndTime` mode of the picker share the time + // columns, so they are placed together to one state. + // The `date` mode has different children and is implemented in a different + // state. + switch (mode) { + case CupertinoDatePickerMode.time: + case CupertinoDatePickerMode.dateAndTime: + return _CupertinoDatePickerDateTimeState(); + case CupertinoDatePickerMode.date: + return _CupertinoDatePickerDateState(dateOrder: dateOrder); + case CupertinoDatePickerMode.monthYear: + return _CupertinoDatePickerMonthYearState(dateOrder: dateOrder); + } + } + + // Estimate the minimum width that each column needs to layout its content. + static double _getColumnWidth( + _PickerColumnType columnType, + CupertinoLocalizations localizations, + BuildContext context, + bool showDayOfWeek, { + bool standaloneMonth = false, + }) { + String longestText = ''; + + switch (columnType) { + case _PickerColumnType.date: + // Measuring the length of all possible date is impossible, so here + // just some dates are measured. + for (int i = 1; i <= 12; i++) { + // An arbitrary date. + final String date = + localizations.datePickerMediumDate(DateTime(2018, i, 25)); + if (longestText.length < date.length) { + longestText = date; + } + } + case _PickerColumnType.hour: + for (int i = 0; i < 24; i++) { + final String hour = localizations.datePickerHour(i); + if (longestText.length < hour.length) { + longestText = hour; + } + } + case _PickerColumnType.minute: + for (int i = 0; i < 60; i++) { + final String minute = localizations.datePickerMinute(i); + if (longestText.length < minute.length) { + longestText = minute; + } + } + case _PickerColumnType.dayPeriod: + longestText = + localizations.anteMeridiemAbbreviation.length > localizations.postMeridiemAbbreviation.length + ? localizations.anteMeridiemAbbreviation + : localizations.postMeridiemAbbreviation; + case _PickerColumnType.dayOfMonth: + int longestDayOfMonth = 1; + for (int i = 1; i <=31; i++) { + final String dayOfMonth = localizations.datePickerDayOfMonth(i); + if (longestText.length < dayOfMonth.length) { + longestText = dayOfMonth; + longestDayOfMonth = i; + } + } + if (showDayOfWeek) { + for (int wd = 1; wd < DateTime.daysPerWeek; wd++) { + final String dayOfMonth = localizations.datePickerDayOfMonth(longestDayOfMonth, wd); + if (longestText.length < dayOfMonth.length) { + longestText = dayOfMonth; + } + } + } + case _PickerColumnType.month: + for (int i = 1; i <= 12; i++) { + final String month = standaloneMonth + ? localizations.datePickerStandaloneMonth(i) + : localizations.datePickerMonth(i); + if (longestText.length < month.length) { + longestText = month; + } + } + case _PickerColumnType.year: + longestText = localizations.datePickerYear(2018); + } + + assert(longestText != '', 'column type is not appropriate'); + + return TextPainter.computeMaxIntrinsicWidth( + text: TextSpan( + style: _themeTextStyle(context), + text: longestText, + ), + textDirection: Directionality.of(context), + ); + } +} + +typedef _ColumnBuilder = Widget Function(double offAxisFraction, TransitionBuilder itemPositioningBuilder, Widget selectionOverlay); + +class _CupertinoDatePickerDateTimeState extends State { + // Fraction of the farthest column's vanishing point vs its width. Eyeballed + // vs iOS. + static const double _kMaximumOffAxisFraction = 0.45; + + late int textDirectionFactor; + late CupertinoLocalizations localizations; + + // Alignment based on text direction. The variable name is self descriptive, + // however, when text direction is rtl, alignment is reversed. + late Alignment alignCenterLeft; + late Alignment alignCenterRight; + + // Read this out when the state is initially created. Changes in initialDateTime + // in the widget after first build is ignored. + late DateTime initialDateTime; + + // The difference in days between the initial date and the currently selected date. + // 0 if the current mode does not involve a date. + int get selectedDayFromInitial { + switch (widget.mode) { + case CupertinoDatePickerMode.dateAndTime: + return dateController.hasClients ? dateController.selectedItem : 0; + case CupertinoDatePickerMode.time: + return 0; + case CupertinoDatePickerMode.date: + case CupertinoDatePickerMode.monthYear: + break; + } + assert( + false, + '$runtimeType is only meant for dateAndTime mode or time mode', + ); + return 0; + } + // The controller of the date column. + late FixedExtentScrollController dateController; + + // The current selection of the hour picker. Values range from 0 to 23. + int get selectedHour => _selectedHour(selectedAmPm, _selectedHourIndex); + int get _selectedHourIndex => hourController.hasClients ? hourController.selectedItem % 24 : initialDateTime.hour; + // Calculates the selected hour given the selected indices of the hour picker + // and the meridiem picker. + int _selectedHour(int selectedAmPm, int selectedHour) { + return _isHourRegionFlipped(selectedAmPm) ? (selectedHour + 12) % 24 : selectedHour; + } + // The controller of the hour column. + late FixedExtentScrollController hourController; + + // The current selection of the minute picker. Values range from 0 to 59. + int get selectedMinute { + return minuteController.hasClients + ? minuteController.selectedItem * widget.minuteInterval % 60 + : initialDateTime.minute; + } + // The controller of the minute column. + late FixedExtentScrollController minuteController; + + // Whether the current meridiem selection is AM or PM. + // + // We can't use the selectedItem of meridiemController as the source of truth + // because the meridiem picker can be scrolled **animatedly** by the hour picker + // (e.g. if you scroll from 12 to 1 in 12h format), but the meridiem change + // should take effect immediately, **before** the animation finishes. + late int selectedAmPm; + // Whether the physical-region-to-meridiem mapping is flipped. + bool get isHourRegionFlipped => _isHourRegionFlipped(selectedAmPm); + bool _isHourRegionFlipped(int selectedAmPm) => selectedAmPm != meridiemRegion; + // The index of the 12-hour region the hour picker is currently in. + // + // Used to determine whether the meridiemController should start animating. + // Valid values are 0 and 1. + // + // The AM/PM correspondence of the two regions flips when the meridiem picker + // scrolls. This variable is to keep track of the selected "physical" + // (meridiem picker invariant) region of the hour picker. The "physical" region + // of an item of index `i` is `i ~/ 12`. + late int meridiemRegion; + // The current selection of the AM/PM picker. + // + // - 0 means AM + // - 1 means PM + late FixedExtentScrollController meridiemController; + + bool isDatePickerScrolling = false; + bool isHourPickerScrolling = false; + bool isMinutePickerScrolling = false; + bool isMeridiemPickerScrolling = false; + + bool get isScrolling { + return isDatePickerScrolling + || isHourPickerScrolling + || isMinutePickerScrolling + || isMeridiemPickerScrolling; + } + + // The estimated width of columns. + final Map estimatedColumnWidths = {}; + + @override + void initState() { + super.initState(); + initialDateTime = widget.initialDateTime; + + // Initially each of the "physical" regions is mapped to the meridiem region + // with the same number, e.g., the first 12 items are mapped to the first 12 + // hours of a day. Such mapping is flipped when the meridiem picker is scrolled + // by the user, the first 12 items are mapped to the last 12 hours of a day. + selectedAmPm = initialDateTime.hour ~/ 12; + meridiemRegion = selectedAmPm; + + meridiemController = FixedExtentScrollController(initialItem: selectedAmPm); + hourController = FixedExtentScrollController(initialItem: initialDateTime.hour); + minuteController = FixedExtentScrollController(initialItem: initialDateTime.minute ~/ widget.minuteInterval); + dateController = FixedExtentScrollController(); + + PaintingBinding.instance.systemFonts.addListener(_handleSystemFontsChange); + } + + void _handleSystemFontsChange () { + setState(() { + // System fonts change might cause the text layout width to change. + // Clears cached width to ensure that they get recalculated with the + // new system fonts. + estimatedColumnWidths.clear(); + }); + } + + @override + void dispose() { + dateController.dispose(); + hourController.dispose(); + minuteController.dispose(); + meridiemController.dispose(); + + PaintingBinding.instance.systemFonts.removeListener(_handleSystemFontsChange); + super.dispose(); + } + + @override + void didUpdateWidget(CupertinoDatePicker oldWidget) { + super.didUpdateWidget(oldWidget); + + assert( + oldWidget.mode == widget.mode, + "The $runtimeType's mode cannot change once it's built.", + ); + + if (!widget.use24hFormat && oldWidget.use24hFormat) { + // Thanks to the physical and meridiem region mapping, the only thing we + // need to update is the meridiem controller, if it's not previously attached. + meridiemController.dispose(); + meridiemController = FixedExtentScrollController(initialItem: selectedAmPm); + } + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + textDirectionFactor = Directionality.of(context) == TextDirection.ltr ? 1 : -1; + localizations = CupertinoLocalizations.of(context); + + alignCenterLeft = textDirectionFactor == 1 ? Alignment.centerLeft : Alignment.centerRight; + alignCenterRight = textDirectionFactor == 1 ? Alignment.centerRight : Alignment.centerLeft; + + estimatedColumnWidths.clear(); + } + + // Lazily calculate the column width of the column being displayed only. + double _getEstimatedColumnWidth(_PickerColumnType columnType) { + if (estimatedColumnWidths[columnType.index] == null) { + estimatedColumnWidths[columnType.index] = + CupertinoDatePicker._getColumnWidth(columnType, localizations, context, widget.showDayOfWeek); + } + + return estimatedColumnWidths[columnType.index]!; + } + + // Gets the current date time of the picker. + DateTime get selectedDateTime { + return DateTime( + initialDateTime.year, + initialDateTime.month, + initialDateTime.day + selectedDayFromInitial, + selectedHour, + selectedMinute, + ); + } + + // Only reports datetime change when the date time is valid. + void _onSelectedItemChange(int index) { + final DateTime selected = selectedDateTime; + + final bool isDateInvalid = (widget.minimumDate?.isAfter(selected) ?? false) + || (widget.maximumDate?.isBefore(selected) ?? false); + + if (isDateInvalid) { + return; + } + + widget.onDateTimeChanged(selected); + } + + // Builds the date column. The date is displayed in medium date format (e.g. Fri Aug 31). + Widget _buildMediumDatePicker(double offAxisFraction, TransitionBuilder itemPositioningBuilder, Widget selectionOverlay) { + return NotificationListener( + onNotification: (ScrollNotification notification) { + if (notification is ScrollStartNotification) { + isDatePickerScrolling = true; + } else if (notification is ScrollEndNotification) { + isDatePickerScrolling = false; + _pickerDidStopScrolling(); + } + + return false; + }, + child: CupertinoPicker.builder( + scrollController: dateController, + offAxisFraction: offAxisFraction, + itemExtent: widget.itemExtent, + useMagnifier: _kUseMagnifier, + magnification: _kMagnification, + backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, + onSelectedItemChanged: (int index) { + _onSelectedItemChange(index); + }, + itemBuilder: (BuildContext context, int index) { + final DateTime rangeStart = DateTime( + initialDateTime.year, + initialDateTime.month, + initialDateTime.day + index, + ); + + // Exclusive. + final DateTime rangeEnd = DateTime( + initialDateTime.year, + initialDateTime.month, + initialDateTime.day + index + 1, + ); + + final DateTime now = DateTime.now(); + + if (widget.minimumDate?.isBefore(rangeEnd) == false) { + return null; + } + if (widget.maximumDate?.isAfter(rangeStart) == false) { + return null; + } + + final String dateText = rangeStart == DateTime(now.year, now.month, now.day) + ? localizations.todayLabel + : localizations.datePickerMediumDate(rangeStart); + + return itemPositioningBuilder( + context, + Text(dateText, style: _themeTextStyle(context)), + ); + }, + selectionOverlay: selectionOverlay, + ), + ); + } + + // With the meridiem picker set to `meridiemIndex`, and the hour picker set to + // `hourIndex`, is it possible to change the value of the minute picker, so + // that the resulting date stays in the valid range. + bool _isValidHour(int meridiemIndex, int hourIndex) { + final DateTime rangeStart = DateTime( + initialDateTime.year, + initialDateTime.month, + initialDateTime.day + selectedDayFromInitial, + _selectedHour(meridiemIndex, hourIndex), + ); + + // The end value of the range is exclusive, i.e. [rangeStart, rangeEnd). + final DateTime rangeEnd = rangeStart.add(const Duration(hours: 1)); + + return (widget.minimumDate?.isBefore(rangeEnd) ?? true) + && !(widget.maximumDate?.isBefore(rangeStart) ?? false); + } + + Widget _buildHourPicker(double offAxisFraction, TransitionBuilder itemPositioningBuilder, Widget selectionOverlay) { + return NotificationListener( + onNotification: (ScrollNotification notification) { + if (notification is ScrollStartNotification) { + isHourPickerScrolling = true; + } else if (notification is ScrollEndNotification) { + isHourPickerScrolling = false; + _pickerDidStopScrolling(); + } + + return false; + }, + child: CupertinoPicker( + scrollController: hourController, + offAxisFraction: offAxisFraction, + itemExtent: widget.itemExtent, + useMagnifier: _kUseMagnifier, + magnification: _kMagnification, + backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, + onSelectedItemChanged: (int index) { + final bool regionChanged = meridiemRegion != index ~/ 12; + final bool debugIsFlipped = isHourRegionFlipped; + + if (regionChanged) { + meridiemRegion = index ~/ 12; + selectedAmPm = 1 - selectedAmPm; + } + + if (!widget.use24hFormat && regionChanged) { + // Scroll the meridiem column to adjust AM/PM. + // + // _onSelectedItemChanged will be called when the animation finishes. + // + // Animation values obtained by comparing with iOS version. + meridiemController.animateToItem( + selectedAmPm, + duration: const Duration(milliseconds: 300), + curve: Curves.easeOut, + ); + } else { + _onSelectedItemChange(index); + } + + assert(debugIsFlipped == isHourRegionFlipped); + }, + looping: true, + selectionOverlay: selectionOverlay, + children: List.generate(24, (int index) { + final int hour = isHourRegionFlipped ? (index + 12) % 24 : index; + final int displayHour = widget.use24hFormat ? hour : (hour + 11) % 12 + 1; + + return itemPositioningBuilder( + context, + Text( + localizations.datePickerHour(displayHour), + semanticsLabel: localizations.datePickerHourSemanticsLabel(displayHour), + style: _themeTextStyle(context, isValid: _isValidHour(selectedAmPm, index)), + ), + ); + }), + ), + ); + } + + Widget _buildMinutePicker(double offAxisFraction, TransitionBuilder itemPositioningBuilder, Widget selectionOverlay) { + return NotificationListener( + onNotification: (ScrollNotification notification) { + if (notification is ScrollStartNotification) { + isMinutePickerScrolling = true; + } else if (notification is ScrollEndNotification) { + isMinutePickerScrolling = false; + _pickerDidStopScrolling(); + } + + return false; + }, + child: CupertinoPicker( + scrollController: minuteController, + offAxisFraction: offAxisFraction, + itemExtent: widget.itemExtent, + useMagnifier: _kUseMagnifier, + magnification: _kMagnification, + backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, + onSelectedItemChanged: _onSelectedItemChange, + looping: true, + selectionOverlay: selectionOverlay, + children: List.generate(60 ~/ widget.minuteInterval, (int index) { + final int minute = index * widget.minuteInterval; + + final DateTime date = DateTime( + initialDateTime.year, + initialDateTime.month, + initialDateTime.day + selectedDayFromInitial, + selectedHour, + minute, + ); + + final bool isInvalidMinute = (widget.minimumDate?.isAfter(date) ?? false) + || (widget.maximumDate?.isBefore(date) ?? false); + + return itemPositioningBuilder( + context, + Text( + localizations.datePickerMinute(minute), + semanticsLabel: localizations.datePickerMinuteSemanticsLabel(minute), + style: _themeTextStyle(context, isValid: !isInvalidMinute), + ), + ); + }), + ), + ); + } + + Widget _buildAmPmPicker(double offAxisFraction, TransitionBuilder itemPositioningBuilder, Widget selectionOverlay) { + return NotificationListener( + onNotification: (ScrollNotification notification) { + if (notification is ScrollStartNotification) { + isMeridiemPickerScrolling = true; + } else if (notification is ScrollEndNotification) { + isMeridiemPickerScrolling = false; + _pickerDidStopScrolling(); + } + + return false; + }, + child: CupertinoPicker( + scrollController: meridiemController, + offAxisFraction: offAxisFraction, + itemExtent: widget.itemExtent, + useMagnifier: _kUseMagnifier, + magnification: _kMagnification, + backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, + onSelectedItemChanged: (int index) { + selectedAmPm = index; + assert(selectedAmPm == 0 || selectedAmPm == 1); + _onSelectedItemChange(index); + }, + selectionOverlay: selectionOverlay, + children: List.generate(2, (int index) { + return itemPositioningBuilder( + context, + Text( + index == 0 + ? localizations.anteMeridiemAbbreviation + : localizations.postMeridiemAbbreviation, + style: _themeTextStyle(context, isValid: _isValidHour(index, _selectedHourIndex)), + ), + ); + }), + ), + ); + } + + // One or more pickers have just stopped scrolling. + void _pickerDidStopScrolling() { + // Call setState to update the greyed out date/hour/minute/meridiem. + setState(() { }); + + if (isScrolling) { + return; + } + + // Whenever scrolling lands on an invalid entry, the picker + // automatically scrolls to a valid one. + final DateTime selectedDate = selectedDateTime; + + final bool minCheck = widget.minimumDate?.isAfter(selectedDate) ?? false; + final bool maxCheck = widget.maximumDate?.isBefore(selectedDate) ?? false; + + if (minCheck || maxCheck) { + // We have minCheck === !maxCheck. + final DateTime targetDate = minCheck ? widget.minimumDate! : widget.maximumDate!; + _scrollToDate(targetDate, selectedDate, minCheck); + } + } + + void _scrollToDate(DateTime newDate, DateTime fromDate, bool minCheck) { + SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) { + if (fromDate.year != newDate.year || fromDate.month != newDate.month || fromDate.day != newDate.day) { + _animateColumnControllerToItem(dateController, selectedDayFromInitial); + } + + if (fromDate.hour != newDate.hour) { + final bool needsMeridiemChange = !widget.use24hFormat + && fromDate.hour ~/ 12 != newDate.hour ~/ 12; + // In AM/PM mode, the pickers should not scroll all the way to the other hour region. + if (needsMeridiemChange) { + _animateColumnControllerToItem(meridiemController, 1 - meridiemController.selectedItem); + + // Keep the target item index in the current 12-h region. + final int newItem = (hourController.selectedItem ~/ 12) * 12 + + (hourController.selectedItem + newDate.hour - fromDate.hour) % 12; + _animateColumnControllerToItem(hourController, newItem); + } else { + _animateColumnControllerToItem( + hourController, + hourController.selectedItem + newDate.hour - fromDate.hour, + ); + } + } + + if (fromDate.minute != newDate.minute) { + final double positionDouble = newDate.minute / widget.minuteInterval; + final int position = minCheck ? positionDouble.ceil() : positionDouble.floor(); + _animateColumnControllerToItem(minuteController, position); + } + }, debugLabel: 'DatePicker.scrollToDate'); + } + + @override + Widget build(BuildContext context) { + // Widths of the columns in this picker, ordered from left to right. + final List columnWidths = [ + _getEstimatedColumnWidth(_PickerColumnType.hour), + _getEstimatedColumnWidth(_PickerColumnType.minute), + ]; + + // Swap the hours and minutes if RTL to ensure they are in the correct position. + final List<_ColumnBuilder> pickerBuilders = Directionality.of(context) == TextDirection.rtl + ? <_ColumnBuilder>[_buildMinutePicker, _buildHourPicker] + : <_ColumnBuilder>[_buildHourPicker, _buildMinutePicker]; + + // Adds am/pm column if the picker is not using 24h format. + if (!widget.use24hFormat) { + if (localizations.datePickerDateTimeOrder == DatePickerDateTimeOrder.date_time_dayPeriod + || localizations.datePickerDateTimeOrder == DatePickerDateTimeOrder.time_dayPeriod_date) { + pickerBuilders.add(_buildAmPmPicker); + columnWidths.add(_getEstimatedColumnWidth(_PickerColumnType.dayPeriod)); + } else { + pickerBuilders.insert(0, _buildAmPmPicker); + columnWidths.insert(0, _getEstimatedColumnWidth(_PickerColumnType.dayPeriod)); + } + } + + // Adds medium date column if the picker's mode is date and time. + if (widget.mode == CupertinoDatePickerMode.dateAndTime) { + if (localizations.datePickerDateTimeOrder == DatePickerDateTimeOrder.time_dayPeriod_date + || localizations.datePickerDateTimeOrder == DatePickerDateTimeOrder.dayPeriod_time_date) { + pickerBuilders.add(_buildMediumDatePicker); + columnWidths.add(_getEstimatedColumnWidth(_PickerColumnType.date)); + } else { + pickerBuilders.insert(0, _buildMediumDatePicker); + columnWidths.insert(0, _getEstimatedColumnWidth(_PickerColumnType.date)); + } + } + + final List pickers = []; + double totalColumnWidths = 4 * _kDatePickerPadSize; + + for (int i = 0; i < columnWidths.length; i++) { + double offAxisFraction = 0.0; + Widget selectionOverlay = _centerSelectionOverlay; + if (i == 0) { + offAxisFraction = -_kMaximumOffAxisFraction * textDirectionFactor; + selectionOverlay = _startSelectionOverlay; + } else if (i >= 2 || columnWidths.length == 2) { + offAxisFraction = _kMaximumOffAxisFraction * textDirectionFactor; + } + + EdgeInsets padding = const EdgeInsets.only(right: _kDatePickerPadSize); + if (i == columnWidths.length - 1) { + padding = padding.flipped; + selectionOverlay = _endSelectionOverlay; + } + if (textDirectionFactor == -1) { + padding = padding.flipped; + } + + totalColumnWidths += columnWidths[i] + (2 * _kDatePickerPadSize); + + pickers.add(LayoutId( + id: i, + child: pickerBuilders[i]( + offAxisFraction, + (BuildContext context, Widget? child) { + return Container( + alignment: i == columnWidths.length - 1 + ? alignCenterLeft + : alignCenterRight, + padding: padding, + child: Container( + alignment: i == columnWidths.length - 1 ? alignCenterLeft : alignCenterRight, + width: i == 0 || i == columnWidths.length - 1 + ? null + : columnWidths[i] + _kDatePickerPadSize, + child: child, + ), + ); + }, + selectionOverlay, + ), + )); + } + + final double maxPickerWidth = totalColumnWidths > _kPickerWidth ? totalColumnWidths : _kPickerWidth; + + return MediaQuery.withNoTextScaling( + child: DefaultTextStyle.merge( + style: _kDefaultPickerTextStyle, + child: CustomMultiChildLayout( + delegate: _DatePickerLayoutDelegate( + columnWidths: columnWidths, + textDirectionFactor: textDirectionFactor, + maxWidth: maxPickerWidth, + ), + children: pickers, + ), + ), + ); + } +} + +class _CupertinoDatePickerDateState extends State { + + _CupertinoDatePickerDateState({ + required this.dateOrder, + }); + + final DatePickerDateOrder? dateOrder; + + late int textDirectionFactor; + late CupertinoLocalizations localizations; + + // Alignment based on text direction. The variable name is self descriptive, + // however, when text direction is rtl, alignment is reversed. + late Alignment alignCenterLeft; + late Alignment alignCenterRight; + + // The currently selected values of the picker. + late int selectedDay; + late int selectedMonth; + late int selectedYear; + + // The controller of the day picker. There are cases where the selected value + // of the picker is invalid (e.g. February 30th 2018), and this dayController + // is responsible for jumping to a valid value. + late FixedExtentScrollController dayController; + late FixedExtentScrollController monthController; + late FixedExtentScrollController yearController; + + bool isDayPickerScrolling = false; + bool isMonthPickerScrolling = false; + bool isYearPickerScrolling = false; + + bool get isScrolling => isDayPickerScrolling || isMonthPickerScrolling || isYearPickerScrolling; + + // Estimated width of columns. + Map estimatedColumnWidths = {}; + + @override + void initState() { + super.initState(); + selectedDay = widget.initialDateTime.day; + selectedMonth = widget.initialDateTime.month; + selectedYear = widget.initialDateTime.year; + + dayController = FixedExtentScrollController(initialItem: selectedDay - 1); + monthController = FixedExtentScrollController(initialItem: selectedMonth - 1); + yearController = FixedExtentScrollController(initialItem: selectedYear); + + PaintingBinding.instance.systemFonts.addListener(_handleSystemFontsChange); + } + + void _handleSystemFontsChange() { + setState(() { + // System fonts change might cause the text layout width to change. + _refreshEstimatedColumnWidths(); + }); + } + + @override + void dispose() { + dayController.dispose(); + monthController.dispose(); + yearController.dispose(); + + PaintingBinding.instance.systemFonts.removeListener(_handleSystemFontsChange); + super.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + textDirectionFactor = Directionality.of(context) == TextDirection.ltr ? 1 : -1; + localizations = CupertinoLocalizations.of(context); + + alignCenterLeft = textDirectionFactor == 1 ? Alignment.centerLeft : Alignment.centerRight; + alignCenterRight = textDirectionFactor == 1 ? Alignment.centerRight : Alignment.centerLeft; + + _refreshEstimatedColumnWidths(); + } + + void _refreshEstimatedColumnWidths() { + estimatedColumnWidths[_PickerColumnType.dayOfMonth.index] = CupertinoDatePicker._getColumnWidth(_PickerColumnType.dayOfMonth, localizations, context, widget.showDayOfWeek); + estimatedColumnWidths[_PickerColumnType.month.index] = CupertinoDatePicker._getColumnWidth(_PickerColumnType.month, localizations, context, widget.showDayOfWeek); + estimatedColumnWidths[_PickerColumnType.year.index] = CupertinoDatePicker._getColumnWidth(_PickerColumnType.year, localizations, context, widget.showDayOfWeek); + } + + // The DateTime of the last day of a given month in a given year. + // Let `DateTime` handle the year/month overflow. + DateTime _lastDayInMonth(int year, int month) => DateTime(year, month + 1, 0); + + Widget _buildDayPicker(double offAxisFraction, TransitionBuilder itemPositioningBuilder, Widget selectionOverlay) { + final int daysInCurrentMonth = _lastDayInMonth(selectedYear, selectedMonth).day; + return NotificationListener( + onNotification: (ScrollNotification notification) { + if (notification is ScrollStartNotification) { + isDayPickerScrolling = true; + } else if (notification is ScrollEndNotification) { + isDayPickerScrolling = false; + _pickerDidStopScrolling(); + } + + return false; + }, + child: CupertinoPicker( + scrollController: dayController, + offAxisFraction: offAxisFraction, + itemExtent: widget.itemExtent, + useMagnifier: _kUseMagnifier, + magnification: _kMagnification, + backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, + onSelectedItemChanged: (int index) { + selectedDay = index + 1; + if (_isCurrentDateValid) { + widget.onDateTimeChanged(DateTime(selectedYear, selectedMonth, selectedDay)); + } + }, + looping: true, + selectionOverlay: selectionOverlay, + children: List.generate(31, (int index) { + final int day = index + 1; + final int? dayOfWeek = widget.showDayOfWeek ? DateTime(selectedYear, selectedMonth, day).weekday : null; + return itemPositioningBuilder( + context, + Text( + localizations.datePickerDayOfMonth(day, dayOfWeek), + style: _themeTextStyle(context, isValid: day <= daysInCurrentMonth), + ), + ); + }), + ), + ); + } + + Widget _buildMonthPicker(double offAxisFraction, TransitionBuilder itemPositioningBuilder, Widget selectionOverlay) { + return NotificationListener( + onNotification: (ScrollNotification notification) { + if (notification is ScrollStartNotification) { + isMonthPickerScrolling = true; + } else if (notification is ScrollEndNotification) { + isMonthPickerScrolling = false; + _pickerDidStopScrolling(); + } + + return false; + }, + child: CupertinoPicker( + scrollController: monthController, + offAxisFraction: offAxisFraction, + itemExtent: widget.itemExtent, + useMagnifier: _kUseMagnifier, + magnification: _kMagnification, + backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, + onSelectedItemChanged: (int index) { + selectedMonth = index + 1; + if (_isCurrentDateValid) { + widget.onDateTimeChanged(DateTime(selectedYear, selectedMonth, selectedDay)); + } + }, + looping: true, + selectionOverlay: selectionOverlay, + children: List.generate(12, (int index) { + final int month = index + 1; + final bool isInvalidMonth = (widget.minimumDate?.year == selectedYear && widget.minimumDate!.month > month) + || (widget.maximumDate?.year == selectedYear && widget.maximumDate!.month < month); + final String monthName = (widget.mode == CupertinoDatePickerMode.monthYear) ? localizations.datePickerStandaloneMonth(month) : localizations.datePickerMonth(month); + + return itemPositioningBuilder( + context, + Text( + monthName, + style: _themeTextStyle(context, isValid: !isInvalidMonth), + ), + ); + }), + ), + ); + } + + Widget _buildYearPicker(double offAxisFraction, TransitionBuilder itemPositioningBuilder, Widget selectionOverlay) { + return NotificationListener( + onNotification: (ScrollNotification notification) { + if (notification is ScrollStartNotification) { + isYearPickerScrolling = true; + } else if (notification is ScrollEndNotification) { + isYearPickerScrolling = false; + _pickerDidStopScrolling(); + } + + return false; + }, + child: CupertinoPicker.builder( + scrollController: yearController, + itemExtent: widget.itemExtent, + offAxisFraction: offAxisFraction, + useMagnifier: _kUseMagnifier, + magnification: _kMagnification, + backgroundColor: widget.backgroundColor, + onSelectedItemChanged: (int index) { + selectedYear = index; + if (_isCurrentDateValid) { + widget.onDateTimeChanged(DateTime(selectedYear, selectedMonth, selectedDay)); + } + }, + itemBuilder: (BuildContext context, int year) { + if (year < widget.minimumYear) { + return null; + } + + if (widget.maximumYear != null && year > widget.maximumYear!) { + return null; + } + + final bool isValidYear = (widget.minimumDate == null || widget.minimumDate!.year <= year) + && (widget.maximumDate == null || widget.maximumDate!.year >= year); + + return itemPositioningBuilder( + context, + Text( + localizations.datePickerYear(year), + style: _themeTextStyle(context, isValid: isValidYear), + ), + ); + }, + selectionOverlay: selectionOverlay, + ), + ); + } + + bool get _isCurrentDateValid { + // The current date selection represents a range [minSelectedData, maxSelectDate]. + final DateTime minSelectedDate = DateTime(selectedYear, selectedMonth, selectedDay); + final DateTime maxSelectedDate = DateTime(selectedYear, selectedMonth, selectedDay + 1); + + final bool minCheck = widget.minimumDate?.isBefore(maxSelectedDate) ?? true; + final bool maxCheck = widget.maximumDate?.isBefore(minSelectedDate) ?? false; + + return minCheck && !maxCheck && minSelectedDate.day == selectedDay; + } + + // One or more pickers have just stopped scrolling. + void _pickerDidStopScrolling() { + // Call setState to update the greyed out days/months/years, as the currently + // selected year/month may have changed. + setState(() { }); + + if (isScrolling) { + return; + } + + // Whenever scrolling lands on an invalid entry, the picker + // automatically scrolls to a valid one. + final DateTime minSelectDate = DateTime(selectedYear, selectedMonth, selectedDay); + final DateTime maxSelectDate = DateTime(selectedYear, selectedMonth, selectedDay + 1); + + final bool minCheck = widget.minimumDate?.isBefore(maxSelectDate) ?? true; + final bool maxCheck = widget.maximumDate?.isBefore(minSelectDate) ?? false; + + if (!minCheck || maxCheck) { + // We have minCheck === !maxCheck. + final DateTime targetDate = minCheck ? widget.maximumDate! : widget.minimumDate!; + _scrollToDate(targetDate); + return; + } + + // Some months have less days (e.g. February). Go to the last day of that month + // if the selectedDay exceeds the maximum. + if (minSelectDate.day != selectedDay) { + final DateTime lastDay = _lastDayInMonth(selectedYear, selectedMonth); + _scrollToDate(lastDay); + } + } + + void _scrollToDate(DateTime newDate) { + SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) { + if (selectedYear != newDate.year) { + _animateColumnControllerToItem(yearController, newDate.year); + } + + if (selectedMonth != newDate.month) { + _animateColumnControllerToItem(monthController, newDate.month - 1); + } + + if (selectedDay != newDate.day) { + _animateColumnControllerToItem(dayController, newDate.day - 1); + } + }, debugLabel: 'DatePicker.scrollToDate'); + } + + @override + Widget build(BuildContext context) { + List<_ColumnBuilder> pickerBuilders = <_ColumnBuilder>[]; + List columnWidths = []; + + final DatePickerDateOrder datePickerDateOrder = + dateOrder ?? localizations.datePickerDateOrder; + + switch (datePickerDateOrder) { + case DatePickerDateOrder.mdy: + pickerBuilders = <_ColumnBuilder>[_buildMonthPicker, _buildDayPicker, _buildYearPicker]; + columnWidths = [ + estimatedColumnWidths[_PickerColumnType.month.index]!, + estimatedColumnWidths[_PickerColumnType.dayOfMonth.index]!, + estimatedColumnWidths[_PickerColumnType.year.index]!, + ]; + case DatePickerDateOrder.dmy: + pickerBuilders = <_ColumnBuilder>[_buildDayPicker, _buildMonthPicker, _buildYearPicker]; + columnWidths = [ + estimatedColumnWidths[_PickerColumnType.dayOfMonth.index]!, + estimatedColumnWidths[_PickerColumnType.month.index]!, + estimatedColumnWidths[_PickerColumnType.year.index]!, + ]; + case DatePickerDateOrder.ymd: + pickerBuilders = <_ColumnBuilder>[_buildYearPicker, _buildMonthPicker, _buildDayPicker]; + columnWidths = [ + estimatedColumnWidths[_PickerColumnType.year.index]!, + estimatedColumnWidths[_PickerColumnType.month.index]!, + estimatedColumnWidths[_PickerColumnType.dayOfMonth.index]!, + ]; + case DatePickerDateOrder.ydm: + pickerBuilders = <_ColumnBuilder>[_buildYearPicker, _buildDayPicker, _buildMonthPicker]; + columnWidths = [ + estimatedColumnWidths[_PickerColumnType.year.index]!, + estimatedColumnWidths[_PickerColumnType.dayOfMonth.index]!, + estimatedColumnWidths[_PickerColumnType.month.index]!, + ]; + } + + final List pickers = []; + double totalColumnWidths = 4 * _kDatePickerPadSize; + + for (int i = 0; i < columnWidths.length; i++) { + final double offAxisFraction = (i - 1) * 0.3 * textDirectionFactor; + + EdgeInsets padding = const EdgeInsets.only(right: _kDatePickerPadSize); + if (textDirectionFactor == -1) { + padding = const EdgeInsets.only(left: _kDatePickerPadSize); + } + + Widget selectionOverlay = _centerSelectionOverlay; + if (i == 0) { + selectionOverlay = _startSelectionOverlay; + } else if (i == columnWidths.length - 1) { + selectionOverlay = _endSelectionOverlay; + } + + totalColumnWidths += columnWidths[i] + (2 * _kDatePickerPadSize); + + pickers.add(LayoutId( + id: i, + child: pickerBuilders[i]( + offAxisFraction, + (BuildContext context, Widget? child) { + return Container( + alignment: i == columnWidths.length - 1 + ? alignCenterLeft + : alignCenterRight, + padding: i == 0 ? null : padding, + child: Container( + alignment: i == 0 ? alignCenterLeft : alignCenterRight, + width: columnWidths[i] + _kDatePickerPadSize, + child: child, + ), + ); + }, + selectionOverlay, + ), + )); + } + + final double maxPickerWidth = totalColumnWidths > _kPickerWidth ? totalColumnWidths : _kPickerWidth; + + return MediaQuery.withNoTextScaling( + child: DefaultTextStyle.merge( + style: _kDefaultPickerTextStyle, + child: CustomMultiChildLayout( + delegate: _DatePickerLayoutDelegate( + columnWidths: columnWidths, + textDirectionFactor: textDirectionFactor, + maxWidth: maxPickerWidth, + ), + children: pickers, + ), + ), + ); + } +} + +class _CupertinoDatePickerMonthYearState extends State { + _CupertinoDatePickerMonthYearState({ + required this.dateOrder, + }); + + final DatePickerDateOrder? dateOrder; + + late int textDirectionFactor; + late CupertinoLocalizations localizations; + + // Alignment based on text direction. The variable name is self descriptive, + // however, when text direction is rtl, alignment is reversed. + late Alignment alignCenterLeft; + late Alignment alignCenterRight; + + // The currently selected values of the picker. + late int selectedYear; + late int selectedMonth; + + // The controller of the day picker. There are cases where the selected value + // of the picker is invalid (e.g. February 30th 2018), and this monthController + // is responsible for jumping to a valid value. + late FixedExtentScrollController monthController; + late FixedExtentScrollController yearController; + + bool isMonthPickerScrolling = false; + bool isYearPickerScrolling = false; + + bool get isScrolling => isMonthPickerScrolling || isYearPickerScrolling; + + // Estimated width of columns. + Map estimatedColumnWidths = {}; + + @override + void initState() { + super.initState(); + selectedMonth = widget.initialDateTime.month; + selectedYear = widget.initialDateTime.year; + + monthController = FixedExtentScrollController(initialItem: selectedMonth - 1); + yearController = FixedExtentScrollController(initialItem: selectedYear); + + PaintingBinding.instance.systemFonts.addListener(_handleSystemFontsChange); + } + + void _handleSystemFontsChange() { + setState(() { + // System fonts change might cause the text layout width to change. + _refreshEstimatedColumnWidths(); + }); + } + + @override + void dispose() { + monthController.dispose(); + yearController.dispose(); + + PaintingBinding.instance.systemFonts.removeListener(_handleSystemFontsChange); + super.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + textDirectionFactor = Directionality.of(context) == TextDirection.ltr ? 1 : -1; + localizations = CupertinoLocalizations.of(context); + + alignCenterLeft = textDirectionFactor == 1 ? Alignment.centerLeft : Alignment.centerRight; + alignCenterRight = textDirectionFactor == 1 ? Alignment.centerRight : Alignment.centerLeft; + + _refreshEstimatedColumnWidths(); + } + + void _refreshEstimatedColumnWidths() { + estimatedColumnWidths[_PickerColumnType.month.index] = + CupertinoDatePicker._getColumnWidth(_PickerColumnType.month, localizations, context, false, standaloneMonth: widget.mode == CupertinoDatePickerMode.monthYear); + estimatedColumnWidths[_PickerColumnType.year.index] = CupertinoDatePicker._getColumnWidth(_PickerColumnType.year, localizations, context, false); + } + + Widget _buildMonthPicker(double offAxisFraction, TransitionBuilder itemPositioningBuilder, Widget selectionOverlay) { + return NotificationListener( + onNotification: (ScrollNotification notification) { + if (notification is ScrollStartNotification) { + isMonthPickerScrolling = true; + } else if (notification is ScrollEndNotification) { + isMonthPickerScrolling = false; + _pickerDidStopScrolling(); + } + + return false; + }, + child: CupertinoPicker( + scrollController: monthController, + offAxisFraction: offAxisFraction, + itemExtent: _kItemExtent, + useMagnifier: _kUseMagnifier, + magnification: _kMagnification, + backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, + onSelectedItemChanged: (int index) { + selectedMonth = index + 1; + if (_isCurrentDateValid) { + widget.onDateTimeChanged(DateTime(selectedYear, selectedMonth)); + } + }, + looping: true, + selectionOverlay: selectionOverlay, + children: List.generate(12, (int index) { + final int month = index + 1; + final bool isInvalidMonth = (widget.minimumDate?.year == selectedYear && widget.minimumDate!.month > month) + || (widget.maximumDate?.year == selectedYear && widget.maximumDate!.month < month); + final String monthName = (widget.mode == CupertinoDatePickerMode.monthYear) ? localizations.datePickerStandaloneMonth(month) : localizations.datePickerMonth(month); + + return itemPositioningBuilder( + context, + Text( + monthName, + style: _themeTextStyle(context, isValid: !isInvalidMonth), + ), + ); + }), + ), + ); + } + + Widget _buildYearPicker(double offAxisFraction, TransitionBuilder itemPositioningBuilder, Widget selectionOverlay) { + return NotificationListener( + onNotification: (ScrollNotification notification) { + if (notification is ScrollStartNotification) { + isYearPickerScrolling = true; + } else if (notification is ScrollEndNotification) { + isYearPickerScrolling = false; + _pickerDidStopScrolling(); + } + + return false; + }, + child: CupertinoPicker.builder( + scrollController: yearController, + itemExtent: _kItemExtent, + offAxisFraction: offAxisFraction, + useMagnifier: _kUseMagnifier, + magnification: _kMagnification, + backgroundColor: widget.backgroundColor, + onSelectedItemChanged: (int index) { + selectedYear = index; + if (_isCurrentDateValid) { + widget.onDateTimeChanged(DateTime(selectedYear, selectedMonth)); + } + }, + itemBuilder: (BuildContext context, int year) { + if (year < widget.minimumYear) { + return null; + } + + if (widget.maximumYear != null && year > widget.maximumYear!) { + return null; + } + + final bool isValidYear = (widget.minimumDate == null || widget.minimumDate!.year <= year) + && (widget.maximumDate == null || widget.maximumDate!.year >= year); + + return itemPositioningBuilder( + context, + Text( + localizations.datePickerYear(year), + style: _themeTextStyle(context, isValid: isValidYear), + ), + ); + }, + selectionOverlay: selectionOverlay, + ), + ); + } + + bool get _isCurrentDateValid { + // The current date selection represents a range [minSelectedData, maxSelectDate]. + final DateTime minSelectedDate = DateTime(selectedYear, selectedMonth); + final DateTime maxSelectedDate = DateTime(selectedYear, selectedMonth, widget.initialDateTime.day + 1); + + final bool minCheck = widget.minimumDate?.isBefore(maxSelectedDate) ?? true; + final bool maxCheck = widget.maximumDate?.isBefore(minSelectedDate) ?? false; + + return minCheck && !maxCheck; + } + + // One or more pickers have just stopped scrolling. + void _pickerDidStopScrolling() { + // Call setState to update the greyed out days/months/years, as the currently + // selected year/month may have changed. + setState(() { }); + + if (isScrolling) { + return; + } + + // Whenever scrolling lands on an invalid entry, the picker + // automatically scrolls to a valid one. + final DateTime minSelectDate = DateTime(selectedYear, selectedMonth); + final DateTime maxSelectDate = DateTime(selectedYear, selectedMonth, widget.initialDateTime.day + 1); + + final bool minCheck = widget.minimumDate?.isBefore(maxSelectDate) ?? true; + final bool maxCheck = widget.maximumDate?.isBefore(minSelectDate) ?? false; + + if (!minCheck || maxCheck) { + // We have minCheck === !maxCheck. + final DateTime targetDate = minCheck ? widget.maximumDate! : widget.minimumDate!; + _scrollToDate(targetDate); + return; + } + } + + void _scrollToDate(DateTime newDate) { + SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) { + if (selectedYear != newDate.year) { + _animateColumnControllerToItem(yearController, newDate.year); + } + + if (selectedMonth != newDate.month) { + _animateColumnControllerToItem(monthController, newDate.month - 1); + } + }, debugLabel: 'DatePicker.scrollToDate'); + } + + @override + Widget build(BuildContext context) { + List<_ColumnBuilder> pickerBuilders = <_ColumnBuilder>[]; + List columnWidths = []; + + final DatePickerDateOrder datePickerDateOrder = + dateOrder ?? localizations.datePickerDateOrder; + + switch (datePickerDateOrder) { + case DatePickerDateOrder.mdy: + case DatePickerDateOrder.dmy: + pickerBuilders = <_ColumnBuilder>[_buildMonthPicker, _buildYearPicker]; + columnWidths = [ + estimatedColumnWidths[_PickerColumnType.month.index]!, + estimatedColumnWidths[_PickerColumnType.year.index]!, + ]; + case DatePickerDateOrder.ymd: + case DatePickerDateOrder.ydm: + pickerBuilders = <_ColumnBuilder>[_buildYearPicker, _buildMonthPicker]; + columnWidths = [ + estimatedColumnWidths[_PickerColumnType.year.index]!, + estimatedColumnWidths[_PickerColumnType.month.index]!, + ]; + } + + final List pickers = []; + double totalColumnWidths = 3 * _kDatePickerPadSize; + + for (int i = 0; i < columnWidths.length; i++) { + late final double offAxisFraction; + switch (i) { + case 0: + offAxisFraction = -0.3 * textDirectionFactor; + default: + offAxisFraction = 0.5 * textDirectionFactor; + } + + EdgeInsets padding = const EdgeInsets.only(right: _kDatePickerPadSize); + if (textDirectionFactor == -1) { + padding = const EdgeInsets.only(left: _kDatePickerPadSize); + } + + Widget selectionOverlay = _centerSelectionOverlay; + if (i == 0) { + selectionOverlay = _startSelectionOverlay; + } else if (i == columnWidths.length - 1) { + selectionOverlay = _endSelectionOverlay; + } + + totalColumnWidths += columnWidths[i] + (2 * _kDatePickerPadSize); + + pickers.add(LayoutId( + id: i, + child: pickerBuilders[i]( + offAxisFraction, + (BuildContext context, Widget? child) { + return Container( + alignment: i == columnWidths.length - 1 + ? alignCenterLeft + : alignCenterRight, + padding: i == 0 ? null : padding, + child: Container( + alignment: i == 0 ? alignCenterLeft : alignCenterRight, + width: columnWidths[i] + _kDatePickerPadSize, + child: child, + ), + ); + }, + selectionOverlay, + ), + )); + } + + final double maxPickerWidth = totalColumnWidths > _kPickerWidth ? totalColumnWidths : _kPickerWidth; + + return MediaQuery.withNoTextScaling( + child: DefaultTextStyle.merge( + style: _kDefaultPickerTextStyle, + child: CustomMultiChildLayout( + delegate: _DatePickerLayoutDelegate( + columnWidths: columnWidths, + textDirectionFactor: textDirectionFactor, + maxWidth: maxPickerWidth, + ), + children: pickers, + ), + ), + ); + } +} + +// The iOS date picker and timer picker has their width fixed to 320.0 in all +// modes. The only exception is the hms mode (which doesn't have a native counterpart), +// with a fixed width of 330.0 px. +// +// For date pickers, if the maximum width given to the picker is greater than +// 320.0, the leftmost and rightmost column will be extended equally so that the +// widths match, and the picker is in the center. +// +// For timer pickers, if the maximum width given to the picker is greater than +// its intrinsic width, it will keep its intrinsic size and position itself in the +// parent using its alignment parameter. +// +// If the maximum width given to the picker is smaller than 320.0, the picker's +// layout will be broken. + + +/// Different modes of [CupertinoTimerPicker]. +/// +/// See also: +/// +/// * [CupertinoTimerPicker], the class that implements the iOS-style timer picker. +/// * [CupertinoPicker], the class that implements a content agnostic spinner UI. +enum CupertinoTimerPickerMode { + /// Mode that shows the timer duration in hour and minute. + /// + /// Examples: 16 hours | 14 min. + hm, + /// Mode that shows the timer duration in minute and second. + /// + /// Examples: 14 min | 43 sec. + ms, + /// Mode that shows the timer duration in hour, minute, and second. + /// + /// Examples: 16 hours | 14 min | 43 sec. + hms, +} + +/// A countdown timer picker in iOS style. +/// +/// This picker shows a countdown duration with hour, minute and second spinners. +/// The duration is bound between 0 and 23 hours 59 minutes 59 seconds. +/// +/// There are several modes of the timer picker listed in [CupertinoTimerPickerMode]. +/// +/// The picker has a fixed size of 320 x 216, in logical pixels, with the exception +/// of [CupertinoTimerPickerMode.hms], which is 330 x 216. If the parent widget +/// provides more space than it needs, the picker will position itself according +/// to its [alignment] property. +/// +/// {@tool dartpad} +/// This example shows a [CupertinoTimerPicker] that returns a countdown duration. +/// +/// ** See code in examples/api/lib/cupertino/date_picker/cupertino_timer_picker.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoDatePicker], the class that implements different display modes +/// of the iOS-style date picker. +/// * [CupertinoPicker], the class that implements a content agnostic spinner UI. +/// * +class CupertinoTimerPicker extends StatefulWidget { + /// Constructs an iOS style countdown timer picker. + /// + /// [mode] is one of the modes listed in [CupertinoTimerPickerMode] and + /// defaults to [CupertinoTimerPickerMode.hms]. + /// + /// [onTimerDurationChanged] is the callback called when the selected duration + /// changes. + /// + /// [initialTimerDuration] defaults to 0 second and is limited from 0 second + /// to 23 hours 59 minutes 59 seconds. + /// + /// [minuteInterval] is the granularity of the minute spinner. Must be a + /// positive integer factor of 60. + /// + /// [secondInterval] is the granularity of the second spinner. Must be a + /// positive integer factor of 60. + CupertinoTimerPicker({ + super.key, + this.mode = CupertinoTimerPickerMode.hms, + this.initialTimerDuration = Duration.zero, + this.minuteInterval = 1, + this.secondInterval = 1, + this.alignment = Alignment.center, + this.backgroundColor, + this.itemExtent = _kItemExtent, + required this.onTimerDurationChanged, + }) : assert(initialTimerDuration >= Duration.zero), + assert(initialTimerDuration < const Duration(days: 1)), + assert(minuteInterval > 0 && 60 % minuteInterval == 0), + assert(secondInterval > 0 && 60 % secondInterval == 0), + assert(initialTimerDuration.inMinutes % minuteInterval == 0), + assert(initialTimerDuration.inSeconds % secondInterval == 0), + assert( + itemExtent > 0, + 'item extent should be greater than 0' + ); + + /// The mode of the timer picker. + final CupertinoTimerPickerMode mode; + + /// The initial duration of the countdown timer. + final Duration initialTimerDuration; + + /// The granularity of the minute spinner. Must be a positive integer factor + /// of 60. + final int minuteInterval; + + /// The granularity of the second spinner. Must be a positive integer factor + /// of 60. + final int secondInterval; + + /// Callback called when the timer duration changes. + final ValueChanged onTimerDurationChanged; + + /// Defines how the timer picker should be positioned within its parent. + /// + /// Defaults to [Alignment.center]. + final AlignmentGeometry alignment; + + /// Background color of timer picker. + /// + /// Defaults to null, which disables background painting entirely. + final Color? backgroundColor; + + /// {@macro flutter.cupertino.picker.itemExtent} + /// + /// Defaults to a value that matches the default iOS timer picker wheel. + final double itemExtent; + + @override + State createState() => _CupertinoTimerPickerState(); +} + +class _CupertinoTimerPickerState extends State { + late TextDirection textDirection; + late CupertinoLocalizations localizations; + int get textDirectionFactor { + switch (textDirection) { + case TextDirection.ltr: + return 1; + case TextDirection.rtl: + return -1; + } + } + + // The currently selected values of the picker. + int? selectedHour; + late int selectedMinute; + int? selectedSecond; + + // On iOS the selected values won't be reported until the scrolling fully stops. + // The values below are the latest selected values when the picker comes to a full stop. + int? lastSelectedHour; + int? lastSelectedMinute; + int? lastSelectedSecond; + + final TextPainter textPainter = TextPainter(); + final List numbers = List.generate(10, (int i) => '${9 - i}'); + late double numberLabelWidth; + late double numberLabelHeight; + late double numberLabelBaseline; + + late double hourLabelWidth; + late double minuteLabelWidth; + late double secondLabelWidth; + + late double totalWidth; + late double pickerColumnWidth; + + FixedExtentScrollController? _hourScrollController; + FixedExtentScrollController? _minuteScrollController; + FixedExtentScrollController? _secondScrollController; + + @override + void initState() { + super.initState(); + + selectedMinute = widget.initialTimerDuration.inMinutes % 60; + + if (widget.mode != CupertinoTimerPickerMode.ms) { + selectedHour = widget.initialTimerDuration.inHours; + } + + if (widget.mode != CupertinoTimerPickerMode.hm) { + selectedSecond = widget.initialTimerDuration.inSeconds % 60; + } + + PaintingBinding.instance.systemFonts.addListener(_handleSystemFontsChange); + } + + void _handleSystemFontsChange() { + setState(() { + // System fonts change might cause the text layout width to change. + textPainter.markNeedsLayout(); + _measureLabelMetrics(); + }); + } + + @override + void dispose() { + PaintingBinding.instance.systemFonts.removeListener(_handleSystemFontsChange); + textPainter.dispose(); + + _hourScrollController?.dispose(); + _minuteScrollController?.dispose(); + _secondScrollController?.dispose(); + super.dispose(); + } + + @override + void didUpdateWidget(CupertinoTimerPicker oldWidget) { + super.didUpdateWidget(oldWidget); + + assert( + oldWidget.mode == widget.mode, + "The CupertinoTimerPicker's mode cannot change once it's built", + ); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + textDirection = Directionality.of(context); + localizations = CupertinoLocalizations.of(context); + + _measureLabelMetrics(); + } + + void _measureLabelMetrics() { + textPainter.textDirection = textDirection; + final TextStyle textStyle = _textStyleFrom(context, _kTimerPickerMagnification); + + double maxWidth = double.negativeInfinity; + String? widestNumber; + + // Assumes that: + // - 2-digit numbers are always wider than 1-digit numbers. + // - There's at least one number in 1-9 that's wider than or equal to 0. + // - The widest 2-digit number is composed of 2 same 1-digit numbers + // that has the biggest width. + // - If two different 1-digit numbers are of the same width, their corresponding + // 2 digit numbers are of the same width. + for (final String input in numbers) { + textPainter.text = TextSpan( + text: input, + style: textStyle, + ); + textPainter.layout(); + + if (textPainter.maxIntrinsicWidth > maxWidth) { + maxWidth = textPainter.maxIntrinsicWidth; + widestNumber = input; + } + } + + textPainter.text = TextSpan( + text: '$widestNumber$widestNumber', + style: textStyle, + ); + + textPainter.layout(); + numberLabelWidth = textPainter.maxIntrinsicWidth; + numberLabelHeight = textPainter.height; + numberLabelBaseline = textPainter.computeDistanceToActualBaseline(TextBaseline.alphabetic); + + minuteLabelWidth = + _measureLabelsMaxWidth(localizations.timerPickerMinuteLabels, textStyle); + + if (widget.mode != CupertinoTimerPickerMode.ms) { + hourLabelWidth = + _measureLabelsMaxWidth(localizations.timerPickerHourLabels, textStyle); + } + + if (widget.mode != CupertinoTimerPickerMode.hm) { + secondLabelWidth = + _measureLabelsMaxWidth(localizations.timerPickerSecondLabels, textStyle); + } + } + + // Measures all possible time text labels and return maximum width. + double _measureLabelsMaxWidth(List labels, TextStyle style) { + double maxWidth = double.negativeInfinity; + for (int i = 0; i < labels.length; i++) { + final String? label = labels[i]; + if (label == null) { + continue; + } + + textPainter.text = TextSpan(text: label, style: style); + textPainter.layout(); + textPainter.maxIntrinsicWidth; + if (textPainter.maxIntrinsicWidth > maxWidth) { + maxWidth = textPainter.maxIntrinsicWidth; + } + } + + return maxWidth; + } + + // Builds a text label with scale factor 1.0 and font weight semi-bold. + // `pickerPadding ` is the additional padding the corresponding picker has to apply + // around the `Text`, in order to extend its separators towards the closest + // horizontal edge of the encompassing widget. + Widget _buildLabel(String text, EdgeInsetsDirectional pickerPadding) { + final EdgeInsetsDirectional padding = EdgeInsetsDirectional.only( + start: numberLabelWidth + + _kTimerPickerLabelPadSize + + pickerPadding.start, + ); + + return IgnorePointer( + child: Container( + alignment: AlignmentDirectional.centerStart.resolve(textDirection), + padding: padding.resolve(textDirection), + child: SizedBox( + height: numberLabelHeight, + child: Baseline( + baseline: numberLabelBaseline, + baselineType: TextBaseline.alphabetic, + child: Text( + text, + style: const TextStyle( + fontSize: _kTimerPickerLabelFontSize, + fontWeight: FontWeight.w600, + ), + maxLines: 1, + softWrap: false, + ), + ), + ), + ), + ); + } + + // The picker has to be wider than its content, since the separators + // are part of the picker. + Widget _buildPickerNumberLabel(String text, EdgeInsetsDirectional padding) { + return Container( + width: _kTimerPickerColumnIntrinsicWidth + padding.horizontal, + padding: padding.resolve(textDirection), + alignment: AlignmentDirectional.centerStart.resolve(textDirection), + child: Container( + width: numberLabelWidth, + alignment: AlignmentDirectional.centerEnd.resolve(textDirection), + child: Text(text, softWrap: false, maxLines: 1, overflow: TextOverflow.visible), + ), + ); + } + + Widget _buildHourPicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) { + _hourScrollController ??= FixedExtentScrollController( + initialItem: selectedHour! + ); + return CupertinoPicker( + scrollController: _hourScrollController, + magnification: _kMagnification, + offAxisFraction: _calculateOffAxisFraction(additionalPadding.start, 0), + itemExtent: widget.itemExtent, + backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, + onSelectedItemChanged: (int index) { + setState(() { + selectedHour = index; + widget.onTimerDurationChanged( + Duration( + hours: selectedHour!, + minutes: selectedMinute, + seconds: selectedSecond ?? 0, + ), + ); + }); + }, + selectionOverlay: selectionOverlay, + children: List.generate(24, (int index) { + final String label = localizations.timerPickerHourLabel(index) ?? ''; + final String semanticsLabel = textDirectionFactor == 1 + ? localizations.timerPickerHour(index) + label + : label + localizations.timerPickerHour(index); + + return Semantics( + label: semanticsLabel, + excludeSemantics: true, + child: _buildPickerNumberLabel(localizations.timerPickerHour(index), additionalPadding), + ); + }), + ); + } + + Widget _buildHourColumn(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) { + additionalPadding = EdgeInsetsDirectional.only( + start: math.max(additionalPadding.start, 0), + end: math.max(additionalPadding.end, 0), + ); + + return Stack( + children: [ + NotificationListener( + onNotification: (ScrollEndNotification notification) { + setState(() { lastSelectedHour = selectedHour; }); + return false; + }, + child: _buildHourPicker(additionalPadding, selectionOverlay), + ), + _buildLabel( + localizations.timerPickerHourLabel(lastSelectedHour ?? selectedHour!) ?? '', + additionalPadding, + ), + ], + ); + } + + Widget _buildMinutePicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) { + _minuteScrollController ??= FixedExtentScrollController( + initialItem: selectedMinute ~/ widget.minuteInterval, + ); + return CupertinoPicker( + scrollController: _minuteScrollController, + magnification: _kMagnification, + offAxisFraction: _calculateOffAxisFraction( + additionalPadding.start, + widget.mode == CupertinoTimerPickerMode.ms ? 0 : 1, + ), + itemExtent: widget.itemExtent, + backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, + looping: true, + onSelectedItemChanged: (int index) { + setState(() { + selectedMinute = index * widget.minuteInterval; + widget.onTimerDurationChanged( + Duration( + hours: selectedHour ?? 0, + minutes: selectedMinute, + seconds: selectedSecond ?? 0, + ), + ); + }); + }, + selectionOverlay: selectionOverlay, + children: List.generate(60 ~/ widget.minuteInterval, (int index) { + final int minute = index * widget.minuteInterval; + final String label = localizations.timerPickerMinuteLabel(minute) ?? ''; + final String semanticsLabel = textDirectionFactor == 1 + ? localizations.timerPickerMinute(minute) + label + : label + localizations.timerPickerMinute(minute); + + return Semantics( + label: semanticsLabel, + excludeSemantics: true, + child: _buildPickerNumberLabel(localizations.timerPickerMinute(minute), additionalPadding), + ); + }), + ); + } + + Widget _buildMinuteColumn(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) { + additionalPadding = EdgeInsetsDirectional.only( + start: math.max(additionalPadding.start, 0), + end: math.max(additionalPadding.end, 0), + ); + + return Stack( + children: [ + NotificationListener( + onNotification: (ScrollEndNotification notification) { + setState(() { lastSelectedMinute = selectedMinute; }); + return false; + }, + child: _buildMinutePicker(additionalPadding, selectionOverlay), + ), + _buildLabel( + localizations.timerPickerMinuteLabel(lastSelectedMinute ?? selectedMinute) ?? '', + additionalPadding, + ), + ], + ); + } + + Widget _buildSecondPicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) { + _secondScrollController ??= FixedExtentScrollController( + initialItem: selectedSecond! ~/ widget.secondInterval, + ); + return CupertinoPicker( + scrollController: _secondScrollController, + magnification: _kMagnification, + offAxisFraction: _calculateOffAxisFraction( + additionalPadding.start, + widget.mode == CupertinoTimerPickerMode.ms ? 1 : 2, + ), + itemExtent: widget.itemExtent, + backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, + looping: true, + onSelectedItemChanged: (int index) { + setState(() { + selectedSecond = index * widget.secondInterval; + widget.onTimerDurationChanged( + Duration( + hours: selectedHour ?? 0, + minutes: selectedMinute, + seconds: selectedSecond!, + ), + ); + }); + }, + selectionOverlay: selectionOverlay, + children: List.generate(60 ~/ widget.secondInterval, (int index) { + final int second = index * widget.secondInterval; + final String label = localizations.timerPickerSecondLabel(second) ?? ''; + final String semanticsLabel = textDirectionFactor == 1 + ? localizations.timerPickerSecond(second) + label + : label + localizations.timerPickerSecond(second); + + return Semantics( + label: semanticsLabel, + excludeSemantics: true, + child: _buildPickerNumberLabel(localizations.timerPickerSecond(second), additionalPadding), + ); + }), + ); + } + + Widget _buildSecondColumn(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) { + additionalPadding = EdgeInsetsDirectional.only( + start: math.max(additionalPadding.start, 0), + end: math.max(additionalPadding.end, 0), + ); + + return Stack( + children: [ + NotificationListener( + onNotification: (ScrollEndNotification notification) { + setState(() { lastSelectedSecond = selectedSecond; }); + return false; + }, + child: _buildSecondPicker(additionalPadding, selectionOverlay), + ), + _buildLabel( + localizations.timerPickerSecondLabel(lastSelectedSecond ?? selectedSecond!) ?? '', + additionalPadding, + ), + ], + ); + } + + // Returns [CupertinoTextThemeData.pickerTextStyle] and magnifies the fontSize + // by [magnification]. + TextStyle _textStyleFrom(BuildContext context, [double magnification = 1.0]) { + final TextStyle textStyle = CupertinoTheme.of(context).textTheme.pickerTextStyle; + return textStyle.copyWith( + color: CupertinoDynamicColor.maybeResolve(textStyle.color, context), + fontSize: textStyle.fontSize! * magnification, + ); + } + + // Calculate the number label center point by padding start and position to + // get a reasonable offAxisFraction. + double _calculateOffAxisFraction(double paddingStart, int position) { + final double centerPoint = paddingStart + (numberLabelWidth / 2); + + // Compute the offAxisFraction needed to be straight within the pickerColumn. + final double pickerColumnOffAxisFraction = + 0.5 - centerPoint / pickerColumnWidth; + // Position is to calculate the reasonable offAxisFraction in the picker. + final double timerPickerOffAxisFraction = + 0.5 - (centerPoint + pickerColumnWidth * position) / totalWidth; + return (pickerColumnOffAxisFraction - timerPickerOffAxisFraction) * textDirectionFactor; + } + + @override + Widget build(BuildContext context) { + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + // The timer picker can be divided into columns corresponding to hour, + // minute, and second. Each column consists of a scrollable and a fixed + // label on top of it. + List columns; + + if (widget.mode == CupertinoTimerPickerMode.hms) { + // Pad the widget to make it as wide as `_kPickerWidth`. + pickerColumnWidth = + _kTimerPickerColumnIntrinsicWidth + (_kTimerPickerHalfColumnPadding * 2); + totalWidth = pickerColumnWidth * 3; + } else { + // The default totalWidth for 2-column modes. + totalWidth = _kPickerWidth; + pickerColumnWidth = totalWidth / 2; + } + + if (constraints.maxWidth < totalWidth) { + totalWidth = constraints.maxWidth; + pickerColumnWidth = + totalWidth / (widget.mode == CupertinoTimerPickerMode.hms ? 3 : 2); + } + + final double baseLabelContentWidth = numberLabelWidth + _kTimerPickerLabelPadSize; + final double minuteLabelContentWidth = baseLabelContentWidth + minuteLabelWidth; + + switch (widget.mode) { + case CupertinoTimerPickerMode.hm: + // Pad the widget to make it as wide as `_kPickerWidth`. + final double hourLabelContentWidth = baseLabelContentWidth + hourLabelWidth; + double hourColumnStartPadding = + pickerColumnWidth - hourLabelContentWidth - _kTimerPickerHalfColumnPadding; + if (hourColumnStartPadding < _kTimerPickerMinHorizontalPadding) { + hourColumnStartPadding = _kTimerPickerMinHorizontalPadding; + } + + double minuteColumnEndPadding = + pickerColumnWidth - minuteLabelContentWidth - _kTimerPickerHalfColumnPadding; + if (minuteColumnEndPadding < _kTimerPickerMinHorizontalPadding) { + minuteColumnEndPadding = _kTimerPickerMinHorizontalPadding; + } + + columns = [ + _buildHourColumn( + EdgeInsetsDirectional.only( + start: hourColumnStartPadding, + end: pickerColumnWidth - hourColumnStartPadding - hourLabelContentWidth, + ), + _startSelectionOverlay, + ), + _buildMinuteColumn( + EdgeInsetsDirectional.only( + start: pickerColumnWidth - minuteColumnEndPadding - minuteLabelContentWidth, + end: minuteColumnEndPadding, + ), + _endSelectionOverlay, + ), + ]; + case CupertinoTimerPickerMode.ms: + final double secondLabelContentWidth = baseLabelContentWidth + secondLabelWidth; + double secondColumnEndPadding = + pickerColumnWidth - secondLabelContentWidth - _kTimerPickerHalfColumnPadding; + if (secondColumnEndPadding < _kTimerPickerMinHorizontalPadding) { + secondColumnEndPadding = _kTimerPickerMinHorizontalPadding; + } + + double minuteColumnStartPadding = + pickerColumnWidth - minuteLabelContentWidth - _kTimerPickerHalfColumnPadding; + if (minuteColumnStartPadding < _kTimerPickerMinHorizontalPadding) { + minuteColumnStartPadding = _kTimerPickerMinHorizontalPadding; + } + + columns = [ + _buildMinuteColumn( + EdgeInsetsDirectional.only( + start: minuteColumnStartPadding, + end: pickerColumnWidth - minuteColumnStartPadding - minuteLabelContentWidth, + ), + _startSelectionOverlay, + ), + _buildSecondColumn( + EdgeInsetsDirectional.only( + start: pickerColumnWidth - secondColumnEndPadding - minuteLabelContentWidth, + end: secondColumnEndPadding, + ), + _endSelectionOverlay, + ), + ]; + case CupertinoTimerPickerMode.hms: + final double hourColumnEndPadding = + pickerColumnWidth - baseLabelContentWidth - hourLabelWidth - _kTimerPickerMinHorizontalPadding; + final double minuteColumnPadding = + (pickerColumnWidth - minuteLabelContentWidth) / 2; + final double secondColumnStartPadding = + pickerColumnWidth - baseLabelContentWidth - secondLabelWidth - _kTimerPickerMinHorizontalPadding; + + columns = [ + _buildHourColumn( + EdgeInsetsDirectional.only( + start: _kTimerPickerMinHorizontalPadding, + end: math.max(hourColumnEndPadding, 0), + ), + _startSelectionOverlay, + ), + _buildMinuteColumn( + EdgeInsetsDirectional.only( + start: minuteColumnPadding, + end: minuteColumnPadding, + ), + _centerSelectionOverlay, + ), + _buildSecondColumn( + EdgeInsetsDirectional.only( + start: math.max(secondColumnStartPadding, 0), + end: _kTimerPickerMinHorizontalPadding, + ), + _endSelectionOverlay, + ), + ]; + } + final CupertinoThemeData themeData = CupertinoTheme.of(context); + // The native iOS picker's text scaling is fixed, so we will also fix it + // as well in our picker. + return MediaQuery.withNoTextScaling( + child: CupertinoTheme( + data: themeData.copyWith( + textTheme: themeData.textTheme.copyWith( + pickerTextStyle: _textStyleFrom(context, _kTimerPickerMagnification), + ), + ), + child: Align( + alignment: widget.alignment, + child: Container( + color: CupertinoDynamicColor.maybeResolve(widget.backgroundColor, context), + width: totalWidth, + height: _kPickerHeight, + child: DefaultTextStyle( + style: _textStyleFrom(context), + child: Row(children: columns.map((Widget child) => Expanded(child: child)).toList(growable: false)), + ), + ), + ), + ), + ); + }, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/debug.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/debug.dart new file mode 100644 index 0000000000000000000000000000000000000000..bbdb2b29a1516743dd0a08620eb4e87030211959 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/debug.dart @@ -0,0 +1,52 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'localizations.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Asserts that the given context has a [Localizations] ancestor that contains +/// a [CupertinoLocalizations] delegate. +/// +/// To call this function, use the following pattern, typically in the +/// relevant Widget's build method: +/// +/// ```dart +/// assert(debugCheckHasCupertinoLocalizations(context)); +/// ``` +/// +/// Always place this before any early returns, so that the invariant is checked +/// in all cases. This prevents bugs from hiding until a particular codepath is +/// hit. +/// +/// Does nothing if asserts are disabled. Always returns true. +bool debugCheckHasCupertinoLocalizations(BuildContext context) { + assert(() { + if (Localizations.of(context, CupertinoLocalizations) == null) { + throw FlutterError.fromParts([ + ErrorSummary('No CupertinoLocalizations found.'), + ErrorDescription( + '${context.widget.runtimeType} widgets require CupertinoLocalizations ' + 'to be provided by a Localizations widget ancestor.', + ), + ErrorDescription( + 'The cupertino library uses Localizations to generate messages, ' + 'labels, and abbreviations.', + ), + ErrorHint( + 'To introduce a CupertinoLocalizations, either use a ' + 'CupertinoApp at the root of your application to include them ' + 'automatically, or add a Localization widget with a ' + 'CupertinoLocalizations delegate.', + ), + ...context.describeMissingAncestor(expectedAncestorType: CupertinoLocalizations), + ]); + } + return true; + }()); + return true; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/desktop_text_selection.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/desktop_text_selection.dart new file mode 100644 index 0000000000000000000000000000000000000000..7b586efd9796df1ec47f2e3a7da5bb227fd353d1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/desktop_text_selection.dart @@ -0,0 +1,214 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show ValueListenable, clampDouble; +import 'package:flutter/widgets.dart'; + +import 'desktop_text_selection_toolbar.dart'; +import 'desktop_text_selection_toolbar_button.dart'; +import 'localizations.dart'; + +/// MacOS Cupertino styled text selection handle controls. +/// +/// Specifically does not manage the toolbar, which is left to +/// [EditableText.contextMenuBuilder]. +class _CupertinoDesktopTextSelectionHandleControls extends CupertinoDesktopTextSelectionControls with TextSelectionHandleControls { +} + +/// Desktop Cupertino styled text selection controls. +/// +/// The [cupertinoDesktopTextSelectionControls] global variable has a +/// suitable instance of this class. +class CupertinoDesktopTextSelectionControls extends TextSelectionControls { + /// Desktop has no text selection handles. + @override + Size getHandleSize(double textLineHeight) { + return Size.zero; + } + + /// Builder for the MacOS-style copy/paste text selection toolbar. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + Widget buildToolbar( + BuildContext context, + Rect globalEditableRegion, + double textLineHeight, + Offset selectionMidpoint, + List endpoints, + TextSelectionDelegate delegate, + ValueListenable? clipboardStatus, + Offset? lastSecondaryTapDownPosition, + ) { + return _CupertinoDesktopTextSelectionControlsToolbar( + clipboardStatus: clipboardStatus, + endpoints: endpoints, + globalEditableRegion: globalEditableRegion, + handleCut: canCut(delegate) ? () => handleCut(delegate) : null, + handleCopy: canCopy(delegate) ? () => handleCopy(delegate) : null, + handlePaste: canPaste(delegate) ? () => handlePaste(delegate) : null, + handleSelectAll: canSelectAll(delegate) ? () => handleSelectAll(delegate) : null, + selectionMidpoint: selectionMidpoint, + lastSecondaryTapDownPosition: lastSecondaryTapDownPosition, + textLineHeight: textLineHeight, + ); + } + + /// Builds the text selection handles, but desktop has none. + @override + Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textLineHeight, [VoidCallback? onTap]) { + return const SizedBox.shrink(); + } + + /// Gets the position for the text selection handles, but desktop has none. + @override + Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) { + return Offset.zero; + } + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + void handleSelectAll(TextSelectionDelegate delegate) { + super.handleSelectAll(delegate); + delegate.hideToolbar(); + } +} + +// TODO(justinmc): Deprecate this after TextSelectionControls.buildToolbar is +// deleted, when users should migrate back to +// cupertinoDesktopTextSelectionControls. +// See https://github.com/flutter/flutter/pull/124262 +/// Text selection handle controls that follow MacOS design conventions. +final TextSelectionControls cupertinoDesktopTextSelectionHandleControls = + _CupertinoDesktopTextSelectionHandleControls(); + +/// Text selection controls that follows MacOS design conventions. +final TextSelectionControls cupertinoDesktopTextSelectionControls = + CupertinoDesktopTextSelectionControls(); + +// Generates the child that's passed into CupertinoDesktopTextSelectionToolbar. +class _CupertinoDesktopTextSelectionControlsToolbar extends StatefulWidget { + const _CupertinoDesktopTextSelectionControlsToolbar({ + required this.clipboardStatus, + required this.endpoints, + required this.globalEditableRegion, + required this.handleCopy, + required this.handleCut, + required this.handlePaste, + required this.handleSelectAll, + required this.selectionMidpoint, + required this.textLineHeight, + required this.lastSecondaryTapDownPosition, + }); + + final ValueListenable? clipboardStatus; + final List endpoints; + final Rect globalEditableRegion; + final VoidCallback? handleCopy; + final VoidCallback? handleCut; + final VoidCallback? handlePaste; + final VoidCallback? handleSelectAll; + final Offset? lastSecondaryTapDownPosition; + final Offset selectionMidpoint; + final double textLineHeight; + + @override + _CupertinoDesktopTextSelectionControlsToolbarState createState() => _CupertinoDesktopTextSelectionControlsToolbarState(); +} + +class _CupertinoDesktopTextSelectionControlsToolbarState extends State<_CupertinoDesktopTextSelectionControlsToolbar> { + void _onChangedClipboardStatus() { + setState(() { + // Inform the widget that the value of clipboardStatus has changed. + }); + } + + @override + void initState() { + super.initState(); + widget.clipboardStatus?.addListener(_onChangedClipboardStatus); + } + + @override + void didUpdateWidget(_CupertinoDesktopTextSelectionControlsToolbar oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.clipboardStatus != widget.clipboardStatus) { + oldWidget.clipboardStatus?.removeListener(_onChangedClipboardStatus); + widget.clipboardStatus?.addListener(_onChangedClipboardStatus); + } + } + + @override + void dispose() { + widget.clipboardStatus?.removeListener(_onChangedClipboardStatus); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + // Don't render the menu until the state of the clipboard is known. + if (widget.handlePaste != null && widget.clipboardStatus?.value == ClipboardStatus.unknown) { + return const SizedBox.shrink(); + } + + assert(debugCheckHasMediaQuery(context)); + final EdgeInsets mediaQueryPadding = MediaQuery.paddingOf(context); + + final Offset midpointAnchor = Offset( + clampDouble(widget.selectionMidpoint.dx - widget.globalEditableRegion.left, + mediaQueryPadding.left, + MediaQuery.sizeOf(context).width - mediaQueryPadding.right, + ), + widget.selectionMidpoint.dy - widget.globalEditableRegion.top, + ); + + final List items = []; + final CupertinoLocalizations localizations = CupertinoLocalizations.of(context); + final Widget onePhysicalPixelVerticalDivider = + SizedBox(width: 1.0 / MediaQuery.devicePixelRatioOf(context)); + + void addToolbarButton( + String text, + VoidCallback onPressed, + ) { + if (items.isNotEmpty) { + items.add(onePhysicalPixelVerticalDivider); + } + + items.add(CupertinoDesktopTextSelectionToolbarButton.text( + onPressed: onPressed, + text: text, + )); + } + + if (widget.handleCut != null) { + addToolbarButton(localizations.cutButtonLabel, widget.handleCut!); + } + if (widget.handleCopy != null) { + addToolbarButton(localizations.copyButtonLabel, widget.handleCopy!); + } + if (widget.handlePaste != null + && widget.clipboardStatus?.value == ClipboardStatus.pasteable) { + addToolbarButton(localizations.pasteButtonLabel, widget.handlePaste!); + } + if (widget.handleSelectAll != null) { + addToolbarButton(localizations.selectAllButtonLabel, widget.handleSelectAll!); + } + + // If there is no option available, build an empty widget. + if (items.isEmpty) { + return const SizedBox.shrink(); + } + + return CupertinoDesktopTextSelectionToolbar( + anchor: widget.lastSecondaryTapDownPosition ?? midpointAnchor, + children: items, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/desktop_text_selection_toolbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/desktop_text_selection_toolbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..a72f2ae6aa21e18db65dcb6eba7ee934ccb93357 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/desktop_text_selection_toolbar.dart @@ -0,0 +1,169 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; + +// The minimum padding from all edges of the selection toolbar to all edges of +// the screen. +const double _kToolbarScreenPadding = 8.0; + +// These values were measured from a screenshot of the native context menu on +// macOS 13.2 on a Macbook Pro. +const double _kToolbarSaturationBoost = 3; +const double _kToolbarBlurSigma = 20; +const double _kToolbarWidth = 222.0; +const Radius _kToolbarBorderRadius = Radius.circular(8.0); +const EdgeInsets _kToolbarPadding = EdgeInsets.all(6.0); +const List _kToolbarShadow = [ + BoxShadow( + color: Color.fromARGB(60, 0, 0, 0), + blurRadius: 10.0, + spreadRadius: 0.5, + offset: Offset(0.0, 4.0), + ), +]; + +// These values were measured from a screenshot of the native context menu on +// macOS 13.2 on a Macbook Pro. +const CupertinoDynamicColor _kToolbarBorderColor = + CupertinoDynamicColor.withBrightness( + color: Color(0xFFB8B8B8), + darkColor: Color(0xFF5B5B5B), +); +const CupertinoDynamicColor _kToolbarBackgroundColor = + CupertinoDynamicColor.withBrightness( + color: Color(0xB2FFFFFF), + darkColor: Color(0xB2303030), +); + +/// A macOS-style text selection toolbar. +/// +/// Typically displays buttons for text manipulation, e.g. copying and pasting +/// text. +/// +/// Tries to position itself as closely as possible to [anchor] while remaining +/// fully inside the viewport. +/// +/// See also: +/// +/// * [CupertinoAdaptiveTextSelectionToolbar], where this is used to build the +/// toolbar for desktop platforms. +/// * [AdaptiveTextSelectionToolbar], where this is used to build the toolbar on +/// macOS. +/// * [DesktopTextSelectionToolbar], which is similar but builds a +/// Material-style desktop toolbar. +class CupertinoDesktopTextSelectionToolbar extends StatelessWidget { + /// Creates a const instance of CupertinoTextSelectionToolbar. + const CupertinoDesktopTextSelectionToolbar({ + super.key, + required this.anchor, + required this.children, + }) : assert(children.length > 0); + + /// Creates a 5x5 matrix that increases saturation when used with [ColorFilter.matrix]. + /// + /// The numbers were taken from this comment: + /// [Cupertino blurs should boost saturation](https://github.com/flutter/flutter/issues/29483#issuecomment-477334981). + static List _matrixWithSaturation(double saturation) { + final double r = 0.213 * (1 - saturation); + final double g = 0.715 * (1 - saturation); + final double b = 0.072 * (1 - saturation); + + return [ + r + saturation, g, b, 0, 0, // + r, g + saturation, b, 0, 0, // + r, g, b + saturation, 0, 0, // + 0, 0, 0, 1, 0, // + ]; + } + + /// {@macro flutter.material.DesktopTextSelectionToolbar.anchor} + final Offset anchor; + + /// {@macro flutter.material.TextSelectionToolbar.children} + /// + /// See also: + /// * [CupertinoDesktopTextSelectionToolbarButton], which builds a default + /// macOS-style text selection toolbar text button. + final List children; + + // Builds a toolbar just like the default Mac toolbar, with the right color + // background, padding, and rounded corners. + static Widget _defaultToolbarBuilder(BuildContext context, Widget child) { + return Container( + width: _kToolbarWidth, + clipBehavior: Clip.hardEdge, + decoration: const BoxDecoration( + boxShadow: _kToolbarShadow, + borderRadius: BorderRadius.all(_kToolbarBorderRadius), + ), + child: BackdropFilter( + // Flutter web doesn't support ImageFilter.compose on CanvasKit yet + // (https://github.com/flutter/flutter/issues/120123). + filter: kIsWeb + ? ImageFilter.blur( + sigmaX: _kToolbarBlurSigma, + sigmaY: _kToolbarBlurSigma, + ) + : ImageFilter.compose( + outer: ColorFilter.matrix( + _matrixWithSaturation(_kToolbarSaturationBoost), + ), + inner: ImageFilter.blur( + sigmaX: _kToolbarBlurSigma, + sigmaY: _kToolbarBlurSigma, + ), + ), + child: DecoratedBox( + decoration: BoxDecoration( + color: _kToolbarBackgroundColor.resolveFrom(context), + border: Border.all( + color: _kToolbarBorderColor.resolveFrom(context), + ), + borderRadius: const BorderRadius.all(_kToolbarBorderRadius), + ), + child: Padding( + padding: _kToolbarPadding, + child: child, + ), + ), + ), + ); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + + final double paddingAbove = + MediaQuery.paddingOf(context).top + _kToolbarScreenPadding; + final Offset localAdjustment = Offset(_kToolbarScreenPadding, paddingAbove); + + return Padding( + padding: EdgeInsets.fromLTRB( + _kToolbarScreenPadding, + paddingAbove, + _kToolbarScreenPadding, + _kToolbarScreenPadding, + ), + child: CustomSingleChildLayout( + delegate: DesktopTextSelectionToolbarLayoutDelegate( + anchor: anchor - localAdjustment, + ), + child: _defaultToolbarBuilder( + context, + Column( + mainAxisSize: MainAxisSize.min, + children: children, + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/desktop_text_selection_toolbar_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/desktop_text_selection_toolbar_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..07c41c3cea2a91b3e5c626d9fc833e36a5516b62 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/desktop_text_selection_toolbar_button.dart @@ -0,0 +1,130 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/gestures.dart'; +import 'package:flutter/widgets.dart'; + +import 'button.dart'; +import 'colors.dart'; +import 'text_selection_toolbar_button.dart'; +import 'theme.dart'; + +// These values were measured from a screenshot of the native context menu on +// macOS 13.2 on a Macbook Pro. +const TextStyle _kToolbarButtonFontStyle = TextStyle( + inherit: false, + fontSize: 14.0, + letterSpacing: -0.15, + fontWeight: FontWeight.w400, +); + +// This value was measured from a screenshot of the native context menu on +// macOS 13.2 on a Macbook Pro. +const EdgeInsets _kToolbarButtonPadding = EdgeInsets.fromLTRB( + 8.0, + 2.0, + 8.0, + 5.0, +); + +/// A button in the style of the Mac context menu buttons. +class CupertinoDesktopTextSelectionToolbarButton extends StatefulWidget { + /// Creates an instance of CupertinoDesktopTextSelectionToolbarButton. + const CupertinoDesktopTextSelectionToolbarButton({ + super.key, + required this.onPressed, + required Widget this.child, + }) : buttonItem = null, + text = null; + + /// Create an instance of [CupertinoDesktopTextSelectionToolbarButton] whose child is + /// a [Text] widget styled like the default Mac context menu button. + const CupertinoDesktopTextSelectionToolbarButton.text({ + super.key, + required this.onPressed, + required this.text, + }) : buttonItem = null, + child = null; + + /// Create an instance of [CupertinoDesktopTextSelectionToolbarButton] from + /// the given [ContextMenuButtonItem]. + CupertinoDesktopTextSelectionToolbarButton.buttonItem({ + super.key, + required ContextMenuButtonItem this.buttonItem, + }) : onPressed = buttonItem.onPressed, + text = null, + child = null; + + /// {@macro flutter.cupertino.CupertinoTextSelectionToolbarButton.onPressed} + final VoidCallback? onPressed; + + /// {@macro flutter.cupertino.CupertinoTextSelectionToolbarButton.child} + final Widget? child; + + /// {@macro flutter.cupertino.CupertinoTextSelectionToolbarButton.onPressed} + final ContextMenuButtonItem? buttonItem; + + /// {@macro flutter.cupertino.CupertinoTextSelectionToolbarButton.text} + final String? text; + + @override + State createState() => + _CupertinoDesktopTextSelectionToolbarButtonState(); +} + +class _CupertinoDesktopTextSelectionToolbarButtonState + extends State { + bool _isHovered = false; + + void _onEnter(PointerEnterEvent event) { + setState(() { + _isHovered = true; + }); + } + + void _onExit(PointerExitEvent event) { + setState(() { + _isHovered = false; + }); + } + + @override + Widget build(BuildContext context) { + final Widget child = widget.child ?? + Text( + widget.text ?? + CupertinoTextSelectionToolbarButton.getButtonLabel( + context, + widget.buttonItem!, + ), + overflow: TextOverflow.ellipsis, + style: _kToolbarButtonFontStyle.copyWith( + color: _isHovered + ? CupertinoTheme.of(context).primaryContrastingColor + : const CupertinoDynamicColor.withBrightness( + color: CupertinoColors.black, + darkColor: CupertinoColors.white, + ).resolveFrom(context), + ), + ); + + return SizedBox( + width: double.infinity, + child: MouseRegion( + onEnter: _onEnter, + onExit: _onExit, + child: CupertinoButton( + alignment: Alignment.centerLeft, + borderRadius: const BorderRadius.all(Radius.circular(4.0)), + color: _isHovered ? CupertinoTheme.of(context).primaryColor : null, + minSize: 0.0, + onPressed: widget.onPressed, + padding: _kToolbarButtonPadding, + pressedOpacity: 0.7, + child: child, + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/dialog.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/dialog.dart new file mode 100644 index 0000000000000000000000000000000000000000..16dc69b85cd82da18a0224395a456230102426a4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/dialog.dart @@ -0,0 +1,2409 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show ImageFilter; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'interface_level.dart'; +import 'localizations.dart'; +import 'scrollbar.dart'; +import 'theme.dart'; + +// TODO(abarth): These constants probably belong somewhere more general. + +// Used XD to flutter plugin(https://github.com/AdobeXD/xd-to-flutter-plugin/) +// to derive values of TextStyle(height and letterSpacing) from +// Adobe XD template for iOS 13, which can be found in +// Apple Design Resources(https://developer.apple.com/design/resources/). +// However the values are not exactly the same as native, so eyeballing is needed. +const TextStyle _kCupertinoDialogTitleStyle = TextStyle( + fontFamily: 'CupertinoSystemDisplay', + inherit: false, + fontSize: 17.0, + fontWeight: FontWeight.w600, + height: 1.3, + letterSpacing: -0.5, + textBaseline: TextBaseline.alphabetic, +); + +const TextStyle _kCupertinoDialogContentStyle = TextStyle( + fontFamily: 'CupertinoSystemText', + inherit: false, + fontSize: 13.0, + fontWeight: FontWeight.w400, + height: 1.35, + letterSpacing: -0.2, + textBaseline: TextBaseline.alphabetic, +); + +const TextStyle _kCupertinoDialogActionStyle = TextStyle( + fontFamily: 'CupertinoSystemText', + inherit: false, + fontSize: 16.8, + fontWeight: FontWeight.w400, + textBaseline: TextBaseline.alphabetic, +); + +// CupertinoActionSheet-specific text styles. +const TextStyle _kActionSheetActionStyle = TextStyle( + fontFamily: 'CupertinoSystemText', + inherit: false, + fontSize: 17.0, + fontWeight: FontWeight.w400, + textBaseline: TextBaseline.alphabetic, +); + +const TextStyle _kActionSheetContentStyle = TextStyle( + fontFamily: 'CupertinoSystemText', + inherit: false, + fontSize: 13.0, + fontWeight: FontWeight.w400, + color: _kActionSheetContentTextColor, + textBaseline: TextBaseline.alphabetic, +); + +// Generic constants shared between Dialog and ActionSheet. +const double _kBlurAmount = 20.0; +const double _kCornerRadius = 14.0; +const double _kDividerThickness = 0.3; + +// Dialog specific constants. +// iOS dialogs have a normal display width and another display width that is +// used when the device is in accessibility mode. Each of these widths are +// listed below. +const double _kCupertinoDialogWidth = 270.0; +const double _kAccessibilityCupertinoDialogWidth = 310.0; +const double _kDialogEdgePadding = 20.0; +const double _kDialogMinButtonHeight = 45.0; +const double _kDialogMinButtonFontSize = 10.0; + +// ActionSheet specific constants. +const double _kActionSheetEdgeHorizontalPadding = 8.0; +const double _kActionSheetCancelButtonPadding = 8.0; +const double _kActionSheetEdgeVerticalPadding = 10.0; +const double _kActionSheetContentHorizontalPadding = 16.0; +const double _kActionSheetContentVerticalPadding = 12.0; +const double _kActionSheetButtonHeight = 56.0; + +// A translucent color that is painted on top of the blurred backdrop as the +// dialog's background color +// Extracted from https://developer.apple.com/design/resources/. +const Color _kDialogColor = CupertinoDynamicColor.withBrightness( + color: Color(0xCCF2F2F2), + darkColor: Color(0xBF1E1E1E), +); + +// Translucent light gray that is painted on top of the blurred backdrop as the +// background color of a pressed button. +// Eyeballed from iOS 13 beta simulator. +const Color _kPressedColor = CupertinoDynamicColor.withBrightness( + color: Color(0xFFE1E1E1), + darkColor: Color(0xFF2E2E2E), +); + +const Color _kActionSheetCancelPressedColor = CupertinoDynamicColor.withBrightness( + color: Color(0xFFECECEC), + darkColor: Color(0xFF49494B), +); + +// Translucent, very light gray that is painted on top of the blurred backdrop +// as the action sheet's background color. +// TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/39272. Use +// System Materials once we have them. +// Extracted from https://developer.apple.com/design/resources/. +const Color _kActionSheetBackgroundColor = CupertinoDynamicColor.withBrightness( + color: Color(0xC7F9F9F9), + darkColor: Color(0xC7252525), +); + +// The gray color used for text that appears in the title area. +// Extracted from https://developer.apple.com/design/resources/. +const Color _kActionSheetContentTextColor = Color(0xFF8F8F8F); + +// Translucent gray that is painted on top of the blurred backdrop in the gap +// areas between the content section and actions section, as well as between +// buttons. +// Eye-balled from iOS 13 beta simulator. +const Color _kActionSheetButtonDividerColor = _kActionSheetContentTextColor; + +// The alert dialog layout policy changes depending on whether the user is using +// a "regular" font size vs a "large" font size. This is a spectrum. There are +// many "regular" font sizes and many "large" font sizes. But depending on which +// policy is currently being used, a dialog is laid out differently. +// +// Empirically, the jump from one policy to the other occurs at the following text +// scale factors: +// Largest regular scale factor: 1.3529411764705883 +// Smallest large scale factor: 1.6470588235294117 +// +// The following constant represents a division in text scale factor beyond which +// we want to change how the dialog is laid out. +const double _kMaxRegularTextScaleFactor = 1.4; + +// Accessibility mode on iOS is determined by the text scale factor that the +// user has selected. +bool _isInAccessibilityMode(BuildContext context) { + final double? factor = MediaQuery.maybeTextScalerOf(context)?.textScaleFactor; + return factor != null && factor > _kMaxRegularTextScaleFactor; +} + +/// An iOS-style alert dialog. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=75CsnyRXf5I} +/// +/// An alert dialog informs the user about situations that require +/// acknowledgment. An alert dialog has an optional title, optional content, +/// and an optional list of actions. The title is displayed above the content +/// and the actions are displayed below the content. +/// +/// This dialog styles its title and content (typically a message) to match the +/// standard iOS title and message dialog text style. These default styles can +/// be overridden by explicitly defining [TextStyle]s for [Text] widgets that +/// are part of the title or content. +/// +/// To display action buttons that look like standard iOS dialog buttons, +/// provide [CupertinoDialogAction]s for the [actions] given to this dialog. +/// +/// Typically passed as the child widget to [showDialog], which displays the +/// dialog. +/// +/// {@tool dartpad} +/// This sample shows how to use a [CupertinoAlertDialog]. +/// The [CupertinoAlertDialog] shows an alert with a set of two choices +/// when [CupertinoButton] is pressed. +/// +/// ** See code in examples/api/lib/cupertino/dialog/cupertino_alert_dialog.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoPopupSurface], which is a generic iOS-style popup surface that +/// holds arbitrary content to create custom popups. +/// * [CupertinoDialogAction], which is an iOS-style dialog button. +/// * [AlertDialog], a Material Design alert dialog. +/// * +class CupertinoAlertDialog extends StatefulWidget { + /// Creates an iOS-style alert dialog. + const CupertinoAlertDialog({ + super.key, + this.title, + this.content, + this.actions = const [], + this.scrollController, + this.actionScrollController, + this.insetAnimationDuration = const Duration(milliseconds: 100), + this.insetAnimationCurve = Curves.decelerate, + }); + + /// The (optional) title of the dialog is displayed in a large font at the top + /// of the dialog. + /// + /// Typically a [Text] widget. + final Widget? title; + + /// The (optional) content of the dialog is displayed in the center of the + /// dialog in a lighter font. + /// + /// Typically a [Text] widget. + final Widget? content; + + /// The (optional) set of actions that are displayed at the bottom of the + /// dialog. + /// + /// Typically this is a list of [CupertinoDialogAction] widgets. + final List actions; + + /// A scroll controller that can be used to control the scrolling of the + /// [content] in the dialog. + /// + /// Defaults to null, and is typically not needed, since most alert messages + /// are short. + /// + /// See also: + /// + /// * [actionScrollController], which can be used for controlling the actions + /// section when there are many actions. + final ScrollController? scrollController; + + /// A scroll controller that can be used to control the scrolling of the + /// actions in the dialog. + /// + /// Defaults to null, and is typically not needed. + /// + /// See also: + /// + /// * [scrollController], which can be used for controlling the [content] + /// section when it is long. + final ScrollController? actionScrollController; + + /// {@macro flutter.material.dialog.insetAnimationDuration} + final Duration insetAnimationDuration; + + /// {@macro flutter.material.dialog.insetAnimationCurve} + final Curve insetAnimationCurve; + + @override + State createState() => _CupertinoAlertDialogState(); +} + +class _CupertinoAlertDialogState extends State { + ScrollController? _backupScrollController; + + ScrollController? _backupActionScrollController; + + ScrollController get _effectiveScrollController => + widget.scrollController ?? (_backupScrollController ??= ScrollController()); + + ScrollController get _effectiveActionScrollController => + widget.actionScrollController ?? (_backupActionScrollController ??= ScrollController()); + + Widget _buildContent(BuildContext context) { + final double textScaleFactor = MediaQuery.textScalerOf(context).textScaleFactor; + + final List children = [ + if (widget.title != null || widget.content != null) + Flexible( + flex: 3, + child: _CupertinoAlertContentSection( + title: widget.title, + message: widget.content, + scrollController: _effectiveScrollController, + titlePadding: EdgeInsets.only( + left: _kDialogEdgePadding, + right: _kDialogEdgePadding, + bottom: widget.content == null ? _kDialogEdgePadding : 1.0, + top: _kDialogEdgePadding * textScaleFactor, + ), + messagePadding: EdgeInsets.only( + left: _kDialogEdgePadding, + right: _kDialogEdgePadding, + bottom: _kDialogEdgePadding * textScaleFactor, + top: widget.title == null ? _kDialogEdgePadding : 1.0, + ), + titleTextStyle: _kCupertinoDialogTitleStyle.copyWith( + color: CupertinoDynamicColor.resolve(CupertinoColors.label, context), + ), + messageTextStyle: _kCupertinoDialogContentStyle.copyWith( + color: CupertinoDynamicColor.resolve(CupertinoColors.label, context), + ), + ), + ), + ]; + + return ColoredBox( + color: CupertinoDynamicColor.resolve(_kDialogColor, context), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: children, + ), + ); + } + + Widget _buildActions() { + Widget actionSection = Container( + height: 0.0, + ); + if (widget.actions.isNotEmpty) { + actionSection = _CupertinoAlertActionSection( + scrollController: _effectiveActionScrollController, + children: widget.actions, + ); + } + + return actionSection; + } + + @override + Widget build(BuildContext context) { + final CupertinoLocalizations localizations = CupertinoLocalizations.of(context); + final bool isInAccessibilityMode = _isInAccessibilityMode(context); + return CupertinoUserInterfaceLevel( + data: CupertinoUserInterfaceLevelData.elevated, + child: MediaQuery.withClampedTextScaling( + // iOS does not shrink dialog content below a 1.0 scale factor + minScaleFactor: 1.0, + child: ScrollConfiguration( + // A CupertinoScrollbar is built-in below. + behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false), + child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return AnimatedPadding( + padding: MediaQuery.viewInsetsOf(context) + + const EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0), + duration: widget.insetAnimationDuration, + curve: widget.insetAnimationCurve, + child: MediaQuery.removeViewInsets( + removeLeft: true, + removeTop: true, + removeRight: true, + removeBottom: true, + context: context, + child: Center( + child: Container( + margin: const EdgeInsets.symmetric(vertical: _kDialogEdgePadding), + width: isInAccessibilityMode + ? _kAccessibilityCupertinoDialogWidth + : _kCupertinoDialogWidth, + child: CupertinoPopupSurface( + isSurfacePainted: false, + child: Semantics( + namesRoute: true, + scopesRoute: true, + explicitChildNodes: true, + label: localizations.alertDialogLabel, + child: _CupertinoDialogRenderWidget( + contentSection: _buildContent(context), + actionsSection: _buildActions(), + dividerColor: CupertinoColors.separator, + ), + ), + ), + ), + ), + ), + ); + }, + ), + ), + ), + ); + } + + @override + void dispose() { + _backupScrollController?.dispose(); + _backupActionScrollController?.dispose(); + super.dispose(); + } +} + +/// Rounded rectangle surface that looks like an iOS popup surface, e.g., alert dialog +/// and action sheet. +/// +/// A [CupertinoPopupSurface] can be configured to paint or not paint a white +/// color on top of its blurred area. Typical usage should paint white on top +/// of the blur. However, the white paint can be disabled for the purpose of +/// rendering divider gaps for a more complicated layout, e.g., [CupertinoAlertDialog]. +/// Additionally, the white paint can be disabled to render a blurred rounded +/// rectangle without any color (similar to iOS's volume control popup). +/// +/// See also: +/// +/// * [CupertinoAlertDialog], which is a dialog with a title, content, and +/// actions. +/// * +class CupertinoPopupSurface extends StatelessWidget { + /// Creates an iOS-style rounded rectangle popup surface. + const CupertinoPopupSurface({ + super.key, + this.isSurfacePainted = true, + this.child, + }); + + /// Whether or not to paint a translucent white on top of this surface's + /// blurred background. [isSurfacePainted] should be true for a typical popup + /// that contains content without any dividers. A popup that requires dividers + /// should set [isSurfacePainted] to false and then paint its own surface area. + /// + /// Some popups, like iOS's volume control popup, choose to render a blurred + /// area without any white paint covering it. To achieve this effect, + /// [isSurfacePainted] should be set to false. + final bool isSurfacePainted; + + /// The widget below this widget in the tree. + final Widget? child; + + @override + Widget build(BuildContext context) { + return ClipRRect( + borderRadius: const BorderRadius.all(Radius.circular(_kCornerRadius)), + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: _kBlurAmount, sigmaY: _kBlurAmount), + child: Container( + color: isSurfacePainted ? CupertinoDynamicColor.resolve(_kDialogColor, context) : null, + child: child, + ), + ), + ); + } +} + +/// An iOS-style action sheet. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=U-ao8p4A82k} +/// +/// An action sheet is a specific style of alert that presents the user +/// with a set of two or more choices related to the current context. +/// An action sheet can have a title, an additional message, and a list +/// of actions. The title is displayed above the message and the actions +/// are displayed below this content. +/// +/// This action sheet styles its title and message to match standard iOS action +/// sheet title and message text style. +/// +/// To display action buttons that look like standard iOS action sheet buttons, +/// provide [CupertinoActionSheetAction]s for the [actions] given to this action +/// sheet. +/// +/// To include a iOS-style cancel button separate from the other buttons, +/// provide an [CupertinoActionSheetAction] for the [cancelButton] given to this +/// action sheet. +/// +/// An action sheet is typically passed as the child widget to +/// [showCupertinoModalPopup], which displays the action sheet by sliding it up +/// from the bottom of the screen. +/// +/// {@tool dartpad} +/// This sample shows how to use a [CupertinoActionSheet]. +/// The [CupertinoActionSheet] shows a modal popup that slides in from the +/// bottom when [CupertinoButton] is pressed. +/// +/// ** See code in examples/api/lib/cupertino/dialog/cupertino_action_sheet.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoActionSheetAction], which is an iOS-style action sheet button. +/// * +class CupertinoActionSheet extends StatefulWidget { + /// Creates an iOS-style action sheet. + /// + /// An action sheet must have a non-null value for at least one of the + /// following arguments: [actions], [title], [message], or [cancelButton]. + /// + /// Generally, action sheets are used to give the user a choice between + /// two or more choices for the current context. + const CupertinoActionSheet({ + super.key, + this.title, + this.message, + this.actions, + this.messageScrollController, + this.actionScrollController, + this.cancelButton, + }) : assert( + actions != null || title != null || message != null || cancelButton != null, + 'An action sheet must have a non-null value for at least one of the following arguments: ' + 'actions, title, message, or cancelButton', + ); + + /// An optional title of the action sheet. When the [message] is non-null, + /// the font of the [title] is bold. + /// + /// Typically a [Text] widget. + final Widget? title; + + /// An optional descriptive message that provides more details about the + /// reason for the alert. + /// + /// Typically a [Text] widget. + final Widget? message; + + /// The set of actions that are displayed for the user to select. + /// + /// Typically this is a list of [CupertinoActionSheetAction] widgets. + final List? actions; + + /// A scroll controller that can be used to control the scrolling of the + /// [message] in the action sheet. + /// + /// This attribute is typically not needed, as alert messages should be + /// short. + final ScrollController? messageScrollController; + + /// A scroll controller that can be used to control the scrolling of the + /// [actions] in the action sheet. + /// + /// This attribute is typically not needed. + final ScrollController? actionScrollController; + + /// The optional cancel button that is grouped separately from the other + /// actions. + /// + /// Typically this is an [CupertinoActionSheetAction] widget. + final Widget? cancelButton; + + @override + State createState() => _CupertinoActionSheetState(); +} + +class _CupertinoActionSheetState extends State { + ScrollController? _backupMessageScrollController; + + ScrollController? _backupActionScrollController; + + ScrollController get _effectiveMessageScrollController => + widget.messageScrollController ?? (_backupMessageScrollController ??= ScrollController()); + + ScrollController get _effectiveActionScrollController => + widget.actionScrollController ?? (_backupActionScrollController ??= ScrollController()); + + @override + void dispose() { + _backupMessageScrollController?.dispose(); + _backupActionScrollController?.dispose(); + super.dispose(); + } + + Widget _buildContent(BuildContext context) { + final List content = []; + if (widget.title != null || widget.message != null) { + final Widget titleSection = _CupertinoAlertContentSection( + title: widget.title, + message: widget.message, + scrollController: _effectiveMessageScrollController, + titlePadding: EdgeInsets.only( + left: _kActionSheetContentHorizontalPadding, + right: _kActionSheetContentHorizontalPadding, + bottom: widget.message == null ? _kActionSheetContentVerticalPadding : 0.0, + top: _kActionSheetContentVerticalPadding, + ), + messagePadding: EdgeInsets.only( + left: _kActionSheetContentHorizontalPadding, + right: _kActionSheetContentHorizontalPadding, + bottom: _kActionSheetContentVerticalPadding, + top: widget.title == null ? _kActionSheetContentVerticalPadding : 0.0, + ), + titleTextStyle: widget.message == null + ? _kActionSheetContentStyle + : _kActionSheetContentStyle.copyWith(fontWeight: FontWeight.w600), + messageTextStyle: widget.title == null + ? _kActionSheetContentStyle.copyWith(fontWeight: FontWeight.w600) + : _kActionSheetContentStyle, + additionalPaddingBetweenTitleAndMessage: const EdgeInsets.only(top: 4.0), + ); + content.add(Flexible(child: titleSection)); + } + + return ColoredBox( + color: CupertinoDynamicColor.resolve(_kActionSheetBackgroundColor, context), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: content, + ), + ); + } + + Widget _buildActions() { + if (widget.actions == null || widget.actions!.isEmpty) { + return Container( + height: 0.0, + ); + } + return _CupertinoAlertActionSection( + scrollController: _effectiveActionScrollController, + hasCancelButton: widget.cancelButton != null, + isActionSheet: true, + children: widget.actions!, + ); + } + + Widget _buildCancelButton() { + final double cancelPadding = (widget.actions != null || widget.message != null || widget.title != null) + ? _kActionSheetCancelButtonPadding : 0.0; + return Padding( + padding: EdgeInsets.only(top: cancelPadding), + child: _CupertinoActionSheetCancelButton( + child: widget.cancelButton, + ), + ); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + + final List children = [ + Flexible(child: ClipRRect( + borderRadius: const BorderRadius.all(Radius.circular(12.0)), + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: _kBlurAmount, sigmaY: _kBlurAmount), + child: _CupertinoDialogRenderWidget( + contentSection: Builder(builder: _buildContent), + actionsSection: _buildActions(), + dividerColor: _kActionSheetButtonDividerColor, + isActionSheet: true, + ), + ), + ), + ), + if (widget.cancelButton != null) _buildCancelButton(), + ]; + + final Orientation orientation = MediaQuery.orientationOf(context); + final double actionSheetWidth; + if (orientation == Orientation.portrait) { + actionSheetWidth = MediaQuery.sizeOf(context).width - (_kActionSheetEdgeHorizontalPadding * 2); + } else { + actionSheetWidth = MediaQuery.sizeOf(context).height - (_kActionSheetEdgeHorizontalPadding * 2); + } + + return SafeArea( + child: ScrollConfiguration( + // A CupertinoScrollbar is built-in below + behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false), + child: Semantics( + namesRoute: true, + scopesRoute: true, + explicitChildNodes: true, + label: 'Alert', + child: CupertinoUserInterfaceLevel( + data: CupertinoUserInterfaceLevelData.elevated, + child: Container( + width: actionSheetWidth, + margin: const EdgeInsets.symmetric( + horizontal: _kActionSheetEdgeHorizontalPadding, + vertical: _kActionSheetEdgeVerticalPadding, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: children, + ), + ), + ), + ), + ), + ); + } +} + +/// A button typically used in a [CupertinoActionSheet]. +/// +/// See also: +/// +/// * [CupertinoActionSheet], an alert that presents the user with a set of two or +/// more choices related to the current context. +class CupertinoActionSheetAction extends StatelessWidget { + /// Creates an action for an iOS-style action sheet. + const CupertinoActionSheetAction({ + super.key, + required this.onPressed, + this.isDefaultAction = false, + this.isDestructiveAction = false, + required this.child, + }); + + /// The callback that is called when the button is tapped. + final VoidCallback onPressed; + + /// Whether this action is the default choice in the action sheet. + /// + /// Default buttons have bold text. + final bool isDefaultAction; + + /// Whether this action might change or delete data. + /// + /// Destructive buttons have red text. + final bool isDestructiveAction; + + /// The widget below this widget in the tree. + /// + /// Typically a [Text] widget. + final Widget child; + + @override + Widget build(BuildContext context) { + TextStyle style = _kActionSheetActionStyle.copyWith( + color: isDestructiveAction + ? CupertinoDynamicColor.resolve(CupertinoColors.systemRed, context) + : CupertinoTheme.of(context).primaryColor, + ); + + if (isDefaultAction) { + style = style.copyWith(fontWeight: FontWeight.w600); + } + + return MouseRegion( + cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, + child: GestureDetector( + onTap: onPressed, + behavior: HitTestBehavior.opaque, + child: ConstrainedBox( + constraints: const BoxConstraints( + minHeight: _kActionSheetButtonHeight, + ), + child: Semantics( + button: true, + child: Container( + alignment: Alignment.center, + padding: const EdgeInsets.symmetric( + vertical: 16.0, + horizontal: 10.0, + ), + child: DefaultTextStyle( + style: style, + textAlign: TextAlign.center, + child: child, + ), + ), + ), + ), + ), + ); + } +} + +class _CupertinoActionSheetCancelButton extends StatefulWidget { + const _CupertinoActionSheetCancelButton({ + this.child, + }); + + final Widget? child; + + @override + _CupertinoActionSheetCancelButtonState createState() => _CupertinoActionSheetCancelButtonState(); +} + +class _CupertinoActionSheetCancelButtonState extends State<_CupertinoActionSheetCancelButton> { + bool isBeingPressed = false; + + void _onTapDown(TapDownDetails event) { + setState(() { isBeingPressed = true; }); + } + + void _onTapUp(TapUpDetails event) { + setState(() { isBeingPressed = false; }); + } + + void _onTapCancel() { + setState(() { isBeingPressed = false; }); + } + + @override + Widget build(BuildContext context) { + final Color backgroundColor = isBeingPressed + ? _kActionSheetCancelPressedColor + : CupertinoColors.secondarySystemGroupedBackground; + return GestureDetector( + excludeFromSemantics: true, + onTapDown: _onTapDown, + onTapUp: _onTapUp, + onTapCancel: _onTapCancel, + child: Container( + decoration: BoxDecoration( + color: CupertinoDynamicColor.resolve(backgroundColor, context), + borderRadius: const BorderRadius.all(Radius.circular(_kCornerRadius)), + ), + child: widget.child, + ), + ); + } +} + +// iOS style layout policy widget for sizing an alert dialog's content section and +// action button section. +// +// See [_RenderCupertinoDialog] for specific layout policy details. +class _CupertinoDialogRenderWidget extends RenderObjectWidget { + const _CupertinoDialogRenderWidget({ + required this.contentSection, + required this.actionsSection, + required this.dividerColor, + this.isActionSheet = false, + }); + + final Widget contentSection; + final Widget actionsSection; + final Color dividerColor; + final bool isActionSheet; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderCupertinoDialog( + dividerThickness: _kDividerThickness, + isInAccessibilityMode: _isInAccessibilityMode(context) && !isActionSheet, + dividerColor: CupertinoDynamicColor.resolve(dividerColor, context), + isActionSheet: isActionSheet, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderCupertinoDialog renderObject) { + renderObject + ..isInAccessibilityMode = _isInAccessibilityMode(context) && !isActionSheet + ..dividerColor = CupertinoDynamicColor.resolve(dividerColor, context) + ..isActionSheet = isActionSheet; + } + + @override + RenderObjectElement createElement() { + return _CupertinoDialogRenderElement(this, allowMoveRenderObjectChild: isActionSheet); + } +} + +class _CupertinoDialogRenderElement extends RenderObjectElement { + _CupertinoDialogRenderElement(_CupertinoDialogRenderWidget super.widget, {this.allowMoveRenderObjectChild = false}); + + // Whether to allow overridden method moveRenderObjectChild call or default to super. + // CupertinoActionSheet should default to [super] but CupertinoAlertDialog not. + final bool allowMoveRenderObjectChild; + + Element? _contentElement; + Element? _actionsElement; + + @override + _RenderCupertinoDialog get renderObject => super.renderObject as _RenderCupertinoDialog; + + @override + void visitChildren(ElementVisitor visitor) { + if (_contentElement != null) { + visitor(_contentElement!); + } + if (_actionsElement != null) { + visitor(_actionsElement!); + } + } + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + final _CupertinoDialogRenderWidget dialogRenderWidget = widget as _CupertinoDialogRenderWidget; + _contentElement = updateChild(_contentElement, dialogRenderWidget.contentSection, _AlertDialogSections.contentSection); + _actionsElement = updateChild(_actionsElement, dialogRenderWidget.actionsSection, _AlertDialogSections.actionsSection); + } + + @override + void insertRenderObjectChild(RenderObject child, _AlertDialogSections slot) { + _placeChildInSlot(child, slot); + } + + @override + void moveRenderObjectChild(RenderObject child, _AlertDialogSections oldSlot, _AlertDialogSections newSlot) { + if (!allowMoveRenderObjectChild) { + assert(false); + return; + } + + _placeChildInSlot(child, newSlot); + } + + @override + void update(RenderObjectWidget newWidget) { + super.update(newWidget); + final _CupertinoDialogRenderWidget dialogRenderWidget = widget as _CupertinoDialogRenderWidget; + _contentElement = updateChild(_contentElement, dialogRenderWidget.contentSection, _AlertDialogSections.contentSection); + _actionsElement = updateChild(_actionsElement, dialogRenderWidget.actionsSection, _AlertDialogSections.actionsSection); + } + + @override + void forgetChild(Element child) { + assert(child == _contentElement || child == _actionsElement); + if (_contentElement == child) { + _contentElement = null; + } else { + assert(_actionsElement == child); + _actionsElement = null; + } + super.forgetChild(child); + } + + @override + void removeRenderObjectChild(RenderObject child, _AlertDialogSections slot) { + assert(child == renderObject.contentSection || child == renderObject.actionsSection); + if (renderObject.contentSection == child) { + renderObject.contentSection = null; + } else { + assert(renderObject.actionsSection == child); + renderObject.actionsSection = null; + } + } + + void _placeChildInSlot(RenderObject child, _AlertDialogSections slot) { + switch (slot) { + case _AlertDialogSections.contentSection: + renderObject.contentSection = child as RenderBox; + case _AlertDialogSections.actionsSection: + renderObject.actionsSection = child as RenderBox; + } + } +} + +// iOS style layout policy for sizing an alert dialog's content section and action +// button section. +// +// The policy is as follows: +// +// If all content and buttons fit on screen: +// The content section and action button section are sized intrinsically and centered +// vertically on screen. +// +// If all content and buttons do not fit on screen, and iOS is NOT in accessibility mode: +// A minimum height for the action button section is calculated. The action +// button section will not be rendered shorter than this minimum. See +// [_RenderCupertinoDialogActions] for the minimum height calculation. +// +// With the minimum action button section calculated, the content section can +// take up as much space as is available, up to the point that it hits the +// minimum button height at the bottom. +// +// After the content section is laid out, the action button section is allowed +// to take up any remaining space that was not consumed by the content section. +// +// If all content and buttons do not fit on screen, and iOS IS in accessibility mode: +// The button section is given up to 50% of the available height. Then the content +// section is given whatever height remains. +class _RenderCupertinoDialog extends RenderBox { + _RenderCupertinoDialog({ + RenderBox? contentSection, + RenderBox? actionsSection, + double dividerThickness = 0.0, + bool isInAccessibilityMode = false, + bool isActionSheet = false, + required Color dividerColor, + }) : _contentSection = contentSection, + _actionsSection = actionsSection, + _dividerThickness = dividerThickness, + _isInAccessibilityMode = isInAccessibilityMode, + _isActionSheet = isActionSheet, + _dividerPaint = Paint() + ..color = dividerColor + ..style = PaintingStyle.fill; + + RenderBox? get contentSection => _contentSection; + RenderBox? _contentSection; + set contentSection(RenderBox? newContentSection) { + if (newContentSection != _contentSection) { + if (_contentSection != null) { + dropChild(_contentSection!); + } + _contentSection = newContentSection; + if (_contentSection != null) { + adoptChild(_contentSection!); + } + } + } + + RenderBox? get actionsSection => _actionsSection; + RenderBox? _actionsSection; + set actionsSection(RenderBox? newActionsSection) { + if (newActionsSection != _actionsSection) { + if (null != _actionsSection) { + dropChild(_actionsSection!); + } + _actionsSection = newActionsSection; + if (null != _actionsSection) { + adoptChild(_actionsSection!); + } + } + } + + bool get isInAccessibilityMode => _isInAccessibilityMode; + bool _isInAccessibilityMode; + set isInAccessibilityMode(bool newValue) { + if (newValue != _isInAccessibilityMode) { + _isInAccessibilityMode = newValue; + markNeedsLayout(); + } + } + + bool _isActionSheet; + bool get isActionSheet => _isActionSheet; + set isActionSheet(bool newValue) { + if (newValue != _isActionSheet) { + _isActionSheet = newValue; + markNeedsLayout(); + } + } + + double get _dialogWidth => isInAccessibilityMode + ? _kAccessibilityCupertinoDialogWidth + : _kCupertinoDialogWidth; + + final double _dividerThickness; + final Paint _dividerPaint; + + Color get dividerColor => _dividerPaint.color; + set dividerColor(Color newValue) { + if (dividerColor == newValue) { + return; + } + + _dividerPaint.color = newValue; + markNeedsPaint(); + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + if (null != contentSection) { + contentSection!.attach(owner); + } + if (null != actionsSection) { + actionsSection!.attach(owner); + } + } + + @override + void detach() { + super.detach(); + if (null != contentSection) { + contentSection!.detach(); + } + if (null != actionsSection) { + actionsSection!.detach(); + } + } + + @override + void redepthChildren() { + if (null != contentSection) { + redepthChild(contentSection!); + } + if (null != actionsSection) { + redepthChild(actionsSection!); + } + } + + @override + void setupParentData(RenderBox child) { + if (!isActionSheet && child.parentData is! BoxParentData) { + child.parentData = BoxParentData(); + } else if (child.parentData is! MultiChildLayoutParentData) { + child.parentData = MultiChildLayoutParentData(); + } + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + if (contentSection != null) { + visitor(contentSection!); + } + if (actionsSection != null) { + visitor(actionsSection!); + } + } + + @override + List debugDescribeChildren() => [ + if (contentSection != null) contentSection!.toDiagnosticsNode(name: 'content'), + if (actionsSection != null) actionsSection!.toDiagnosticsNode(name: 'actions'), + ]; + + @override + double computeMinIntrinsicWidth(double height) { + return isActionSheet ? constraints.minWidth : _dialogWidth; + } + + @override + double computeMaxIntrinsicWidth(double height) { + return isActionSheet ? constraints.maxWidth : _dialogWidth; + } + + @override + double computeMinIntrinsicHeight(double width) { + final double contentHeight = contentSection!.getMinIntrinsicHeight(width); + final double actionsHeight = actionsSection!.getMinIntrinsicHeight(width); + final bool hasDivider = contentHeight > 0.0 && actionsHeight > 0.0; + double height = contentHeight + (hasDivider ? _dividerThickness : 0.0) + actionsHeight; + + if (isActionSheet && (actionsHeight > 0 || contentHeight > 0)) { + height -= 2 * _kActionSheetEdgeVerticalPadding; + } + if (height.isFinite) { + return height; + } + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + final double contentHeight = contentSection!.getMaxIntrinsicHeight(width); + final double actionsHeight = actionsSection!.getMaxIntrinsicHeight(width); + final bool hasDivider = contentHeight > 0.0 && actionsHeight > 0.0; + double height = contentHeight + (hasDivider ? _dividerThickness : 0.0) + actionsHeight; + + if (isActionSheet && (actionsHeight > 0 || contentHeight > 0)) { + height -= 2 * _kActionSheetEdgeVerticalPadding; + } + if (height.isFinite) { + return height; + } + return 0.0; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return _performLayout( + constraints: constraints, + layoutChild: ChildLayoutHelper.dryLayoutChild, + ).size; + } + + @override + void performLayout() { + final _AlertDialogSizes dialogSizes = _performLayout( + constraints: constraints, + layoutChild: ChildLayoutHelper.layoutChild, + ); + size = dialogSizes.size; + + // Set the position of the actions box to sit at the bottom of the dialog. + // The content box defaults to the top left, which is where we want it. + assert( + (!isActionSheet && actionsSection!.parentData is BoxParentData) || + (isActionSheet && actionsSection!.parentData is MultiChildLayoutParentData), + ); + if (isActionSheet) { + final MultiChildLayoutParentData actionParentData = actionsSection!.parentData! as MultiChildLayoutParentData; + actionParentData.offset = Offset(0.0, dialogSizes.contentHeight + dialogSizes.dividerThickness); + } else { + final BoxParentData actionParentData = actionsSection!.parentData! as BoxParentData; + actionParentData.offset = Offset(0.0, dialogSizes.contentHeight + dialogSizes.dividerThickness); + } + } + + _AlertDialogSizes _performLayout({required BoxConstraints constraints, required ChildLayouter layoutChild}) { + return isInAccessibilityMode + ? performAccessibilityLayout( + constraints: constraints, + layoutChild: layoutChild, + ) : performRegularLayout( + constraints: constraints, + layoutChild: layoutChild, + ); + } + + // When not in accessibility mode, an alert dialog might reduce the space + // for buttons to just over 1 button's height to make room for the content + // section. + _AlertDialogSizes performRegularLayout({required BoxConstraints constraints, required ChildLayouter layoutChild}) { + final bool hasDivider = contentSection!.getMaxIntrinsicHeight(computeMaxIntrinsicWidth(0)) > 0.0 + && actionsSection!.getMaxIntrinsicHeight(computeMaxIntrinsicWidth(0)) > 0.0; + final double dividerThickness = hasDivider ? _dividerThickness : 0.0; + + final double minActionsHeight = actionsSection!.getMinIntrinsicHeight(computeMaxIntrinsicWidth(0)); + + final Size contentSize = layoutChild( + contentSection!, + constraints.deflate(EdgeInsets.only(bottom: minActionsHeight + dividerThickness)), + ); + + final Size actionsSize = layoutChild( + actionsSection!, + constraints.deflate(EdgeInsets.only(top: contentSize.height + dividerThickness)), + ); + + final double dialogHeight = contentSize.height + dividerThickness + actionsSize.height; + + return _AlertDialogSizes( + size: isActionSheet + ? Size(constraints.maxWidth, dialogHeight) + : constraints.constrain(Size(_dialogWidth, dialogHeight)), + contentHeight: contentSize.height, + dividerThickness: dividerThickness, + ); + } + + // When in accessibility mode, an alert dialog will allow buttons to take + // up to 50% of the dialog height, even if the content exceeds available space. + _AlertDialogSizes performAccessibilityLayout({required BoxConstraints constraints, required ChildLayouter layoutChild}) { + final bool hasDivider = contentSection!.getMaxIntrinsicHeight(_dialogWidth) > 0.0 + && actionsSection!.getMaxIntrinsicHeight(_dialogWidth) > 0.0; + final double dividerThickness = hasDivider ? _dividerThickness : 0.0; + + final double maxContentHeight = contentSection!.getMaxIntrinsicHeight(_dialogWidth); + final double maxActionsHeight = actionsSection!.getMaxIntrinsicHeight(_dialogWidth); + + final Size contentSize; + final Size actionsSize; + if (maxContentHeight + dividerThickness + maxActionsHeight > constraints.maxHeight) { + // AlertDialog: There isn't enough room for everything. Following iOS's + // accessibility dialog layout policy, first we allow the actions to take + // up to 50% of the dialog height. Second we fill the rest of the + // available space with the content section. + + actionsSize = layoutChild( + actionsSection!, + constraints.deflate(EdgeInsets.only(top: constraints.maxHeight / 2.0)), + ); + + contentSize = layoutChild( + contentSection!, + constraints.deflate(EdgeInsets.only(bottom: actionsSize.height + dividerThickness)), + ); + } else { + // Everything fits. Give content and actions all the space they want. + + contentSize = layoutChild( + contentSection!, + constraints, + ); + + actionsSize = layoutChild( + actionsSection!, + constraints.deflate(EdgeInsets.only(top: contentSize.height)), + ); + } + + // Calculate overall dialog height. + final double dialogHeight = contentSize.height + dividerThickness + actionsSize.height; + + return _AlertDialogSizes( + size: constraints.constrain(Size(_dialogWidth, dialogHeight)), + contentHeight: contentSize.height, + dividerThickness: dividerThickness, + ); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (isActionSheet) { + final MultiChildLayoutParentData contentParentData = contentSection!.parentData! as MultiChildLayoutParentData; + contentSection!.paint(context, offset + contentParentData.offset); + } else { + final BoxParentData contentParentData = contentSection!.parentData! as BoxParentData; + contentSection!.paint(context, offset + contentParentData.offset); + } + + final bool hasDivider = contentSection!.size.height > 0.0 && actionsSection!.size.height > 0.0; + if (hasDivider) { + _paintDividerBetweenContentAndActions(context.canvas, offset); + } + + if (isActionSheet) { + final MultiChildLayoutParentData actionsParentData = actionsSection!.parentData! as MultiChildLayoutParentData; + actionsSection!.paint(context, offset + actionsParentData.offset); + } else { + final BoxParentData actionsParentData = actionsSection!.parentData! as BoxParentData; + actionsSection!.paint(context, offset + actionsParentData.offset); + } + } + + void _paintDividerBetweenContentAndActions(Canvas canvas, Offset offset) { + canvas.drawRect( + Rect.fromLTWH( + offset.dx, + offset.dy + contentSection!.size.height, + size.width, + _dividerThickness, + ), + _dividerPaint, + ); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + if (isActionSheet) { + final MultiChildLayoutParentData contentSectionParentData = contentSection!.parentData! as MultiChildLayoutParentData; + final MultiChildLayoutParentData actionsSectionParentData = actionsSection!.parentData! as MultiChildLayoutParentData; + return result.addWithPaintOffset( + offset: contentSectionParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - contentSectionParentData.offset); + return contentSection!.hitTest(result, position: transformed); + }, + ) || + result.addWithPaintOffset( + offset: actionsSectionParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - actionsSectionParentData.offset); + return actionsSection!.hitTest(result, position: transformed); + }, + ); + } + + final BoxParentData contentSectionParentData = contentSection!.parentData! as BoxParentData; + final BoxParentData actionsSectionParentData = actionsSection!.parentData! as BoxParentData; + return result.addWithPaintOffset( + offset: contentSectionParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - contentSectionParentData.offset); + return contentSection!.hitTest(result, position: transformed); + }, + ) || + result.addWithPaintOffset( + offset: actionsSectionParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - actionsSectionParentData.offset); + return actionsSection!.hitTest(result, position: transformed); + }, + ); + } +} + +class _AlertDialogSizes { + const _AlertDialogSizes({ + required this.size, + required this.contentHeight, + required this.dividerThickness, + }); + + final Size size; + final double contentHeight; + final double dividerThickness; +} + +// Visual components of an alert dialog that need to be explicitly sized and +// laid out at runtime. +enum _AlertDialogSections { + contentSection, + actionsSection, +} + +// The "content section" of a CupertinoAlertDialog. +// +// If title is missing, then only content is added. If content is +// missing, then only title is added. If both are missing, then it returns +// a SingleChildScrollView with a zero-sized Container. +class _CupertinoAlertContentSection extends StatelessWidget { + const _CupertinoAlertContentSection({ + this.title, + this.message, + this.scrollController, + this.titlePadding, + this.messagePadding, + this.titleTextStyle, + this.messageTextStyle, + this.additionalPaddingBetweenTitleAndMessage, + }) : assert(title == null || titlePadding != null && titleTextStyle != null), + assert(message == null || messagePadding != null && messageTextStyle != null); + + // The (optional) title of the dialog is displayed in a large font at the top + // of the dialog. + // + // Typically a Text widget. + final Widget? title; + + // The (optional) message of the dialog is displayed in the center of the + // dialog in a lighter font. + // + // Typically a Text widget. + final Widget? message; + + // A scroll controller that can be used to control the scrolling of the + // content in the dialog. + // + // Defaults to null, and is typically not needed, since most alert contents + // are short. + final ScrollController? scrollController; + + // Paddings used around title and message. + // CupertinoAlertDialog and CupertinoActionSheet have different paddings. + final EdgeInsets? titlePadding; + final EdgeInsets? messagePadding; + + // Additional padding to be inserted between title and message. + // Only used for CupertinoActionSheet. + final EdgeInsets? additionalPaddingBetweenTitleAndMessage; + + // Text styles used for title and message. + // CupertinoAlertDialog and CupertinoActionSheet have different text styles. + final TextStyle? titleTextStyle; + final TextStyle? messageTextStyle; + + @override + Widget build(BuildContext context) { + if (title == null && message == null) { + return SingleChildScrollView( + controller: scrollController, + child: const SizedBox.shrink(), + ); + } + + final List titleContentGroup = [ + if (title != null) + Padding( + padding: titlePadding!, + child: DefaultTextStyle( + style: titleTextStyle!, + textAlign: TextAlign.center, + child: title!, + ), + ), + if (message != null) + Padding( + padding: messagePadding!, + child: DefaultTextStyle( + style: messageTextStyle!, + textAlign: TextAlign.center, + child: message!, + ), + ), + ]; + + // Add padding between the widgets if necessary. + if (additionalPaddingBetweenTitleAndMessage != null && titleContentGroup.length > 1) { + titleContentGroup.insert(1, Padding(padding: additionalPaddingBetweenTitleAndMessage!)); + } + + return CupertinoScrollbar( + controller: scrollController, + child: SingleChildScrollView( + controller: scrollController, + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: titleContentGroup, + ), + ), + ); + } +} + +// The "actions section" of a [CupertinoAlertDialog]. +// +// See [_RenderCupertinoDialogActions] for details about action button sizing +// and layout. +class _CupertinoAlertActionSection extends StatelessWidget { + const _CupertinoAlertActionSection({ + required this.children, + this.scrollController, + this.hasCancelButton = false, + this.isActionSheet = false, + }); + + final List children; + + // A scroll controller that can be used to control the scrolling of the + // actions in the dialog. + // + // Defaults to null, and is typically not needed, since most alert dialogs + // don't have many actions. + final ScrollController? scrollController; + + // Used in ActionSheet to denote if ActionSheet has a separate so-called + // cancel button. + // + // Defaults to false, and is not needed in dialogs. + final bool hasCancelButton; + + final bool isActionSheet; + + @override + Widget build(BuildContext context) { + + final List interactiveButtons = []; + for (int i = 0; i < children.length; i += 1) { + interactiveButtons.add( + _PressableActionButton( + child: children[i], + ), + ); + } + + return CupertinoScrollbar( + controller: scrollController, + child: SingleChildScrollView( + controller: scrollController, + child: _CupertinoDialogActionsRenderWidget( + actionButtons: interactiveButtons, + dividerThickness: _kDividerThickness, + hasCancelButton: hasCancelButton, + isActionSheet: isActionSheet, + ), + ), + ); + } +} + +// Button that updates its render state when pressed. +// +// The pressed state is forwarded to an _ActionButtonParentDataWidget. The +// corresponding _ActionButtonParentData is then interpreted and rendered +// appropriately by _RenderCupertinoDialogActions. +class _PressableActionButton extends StatefulWidget { + const _PressableActionButton({ + required this.child, + }); + + final Widget child; + + @override + _PressableActionButtonState createState() => _PressableActionButtonState(); +} + +class _PressableActionButtonState extends State<_PressableActionButton> { + bool _isPressed = false; + + @override + Widget build(BuildContext context) { + return _ActionButtonParentDataWidget( + isPressed: _isPressed, + child: MergeSemantics( + // TODO(mattcarroll): Button press dynamics need overhaul for iOS: + // https://github.com/flutter/flutter/issues/19786 + child: GestureDetector( + excludeFromSemantics: true, + behavior: HitTestBehavior.opaque, + onTapDown: (TapDownDetails details) => setState(() { + _isPressed = true; + }), + onTapUp: (TapUpDetails details) => setState(() { + _isPressed = false; + }), + // TODO(mattcarroll): Cancel is currently triggered when user moves + // past slop instead of off button: https://github.com/flutter/flutter/issues/19783 + onTapCancel: () => setState(() => _isPressed = false), + child: widget.child, + ), + ), + ); + } +} + +// ParentDataWidget that updates _ActionButtonParentData for an action button. +// +// Each action button requires knowledge of whether or not it is pressed so that +// the dialog can correctly render the button. The pressed state is held within +// _ActionButtonParentData. _ActionButtonParentDataWidget is responsible for +// updating the pressed state of an _ActionButtonParentData based on the +// incoming [isPressed] property. +class _ActionButtonParentDataWidget + extends ParentDataWidget<_ActionButtonParentData> { + const _ActionButtonParentDataWidget({ + required this.isPressed, + required super.child, + }); + + final bool isPressed; + + @override + void applyParentData(RenderObject renderObject) { + assert(renderObject.parentData is _ActionButtonParentData); + final _ActionButtonParentData parentData = + renderObject.parentData! as _ActionButtonParentData; + if (parentData.isPressed != isPressed) { + parentData.isPressed = isPressed; + + // Force a repaint. + final RenderObject? targetParent = renderObject.parent; + if (targetParent is RenderObject) { + targetParent.markNeedsPaint(); + } + } + } + + @override + Type get debugTypicalAncestorWidgetClass => _CupertinoDialogActionsRenderWidget; +} + +// ParentData applied to individual action buttons that report whether or not +// that button is currently pressed by the user. +class _ActionButtonParentData extends MultiChildLayoutParentData { + bool isPressed = false; +} + +/// A button typically used in a [CupertinoAlertDialog]. +/// +/// See also: +/// +/// * [CupertinoAlertDialog], a dialog that informs the user about situations +/// that require acknowledgment. +class CupertinoDialogAction extends StatelessWidget { + /// Creates an action for an iOS-style dialog. + const CupertinoDialogAction({ + super.key, + this.onPressed, + this.isDefaultAction = false, + this.isDestructiveAction = false, + this.textStyle, + required this.child, + }); + + /// The callback that is called when the button is tapped or otherwise + /// activated. + /// + /// If this is set to null, the button will be disabled. + final VoidCallback? onPressed; + + /// Set to true if button is the default choice in the dialog. + /// + /// Default buttons have bold text. Similar to + /// [UIAlertController.preferredAction](https://developer.apple.com/documentation/uikit/uialertcontroller/1620102-preferredaction), + /// but more than one action can have this attribute set to true in the same + /// [CupertinoAlertDialog]. + /// + /// This parameters defaults to false. + final bool isDefaultAction; + + /// Whether this action destroys an object. + /// + /// For example, an action that deletes an email is destructive. + /// + /// Defaults to false. + final bool isDestructiveAction; + + /// [TextStyle] to apply to any text that appears in this button. + /// + /// Dialog actions have a built-in text resizing policy for long text. To + /// ensure that this resizing policy always works as expected, [textStyle] + /// must be used if a text size is desired other than that specified in + /// [_kCupertinoDialogActionStyle]. + final TextStyle? textStyle; + + /// The widget below this widget in the tree. + /// + /// Typically a [Text] widget. + final Widget child; + + /// Whether the button is enabled or disabled. Buttons are disabled by + /// default. To enable a button, set its [onPressed] property to a non-null + /// value. + bool get enabled => onPressed != null; + + double _calculatePadding(BuildContext context) { + return 8.0 * MediaQuery.textScalerOf(context).textScaleFactor; + } + + // Dialog action content shrinks to fit, up to a certain point, and if it still + // cannot fit at the minimum size, the text content is ellipsized. + // + // This policy only applies when the device is not in accessibility mode. + Widget _buildContentWithRegularSizingPolicy({ + required BuildContext context, + required TextStyle textStyle, + required Widget content, + }) { + final bool isInAccessibilityMode = _isInAccessibilityMode(context); + final double dialogWidth = isInAccessibilityMode + ? _kAccessibilityCupertinoDialogWidth + : _kCupertinoDialogWidth; + // The fontSizeRatio is the ratio of the current text size (including any + // iOS scale factor) vs the minimum text size that we allow in action + // buttons. This ratio information is used to automatically scale down action + // button text to fit the available space. + final double fontSizeRatio = MediaQuery.textScalerOf(context).scale(textStyle.fontSize!) / _kDialogMinButtonFontSize; + final double padding = _calculatePadding(context); + + return IntrinsicHeight( + child: SizedBox( + width: double.infinity, + child: FittedBox( + fit: BoxFit.scaleDown, + child: ConstrainedBox( + constraints: BoxConstraints( + maxWidth: fontSizeRatio * (dialogWidth - (2 * padding)), + ), + child: Semantics( + button: true, + onTap: onPressed, + child: DefaultTextStyle( + style: textStyle, + textAlign: TextAlign.center, + overflow: TextOverflow.ellipsis, + maxLines: 1, + child: content, + ), + ), + ), + ), + ), + ); + } + + // Dialog action content is permitted to be as large as it wants when in + // accessibility mode. If text is used as the content, the text wraps instead + // of ellipsizing. + Widget _buildContentWithAccessibilitySizingPolicy({ + required TextStyle textStyle, + required Widget content, + }) { + return DefaultTextStyle( + style: textStyle, + textAlign: TextAlign.center, + child: content, + ); + } + + @override + Widget build(BuildContext context) { + TextStyle style = _kCupertinoDialogActionStyle.copyWith( + color: CupertinoDynamicColor.resolve( + isDestructiveAction ? CupertinoColors.systemRed : CupertinoTheme.of(context).primaryColor, + context, + ), + ); + style = style.merge(textStyle); + + if (isDefaultAction) { + style = style.copyWith(fontWeight: FontWeight.w600); + } + + if (!enabled) { + style = style.copyWith(color: style.color!.withOpacity(0.5)); + } + + // Apply a sizing policy to the action button's content based on whether or + // not the device is in accessibility mode. + // TODO(mattcarroll): The following logic is not entirely correct. It is also + // the case that if content text does not contain a space, it should also + // wrap instead of ellipsizing. We are consciously not implementing that + // now due to complexity. + final Widget sizedContent = _isInAccessibilityMode(context) + ? _buildContentWithAccessibilitySizingPolicy( + textStyle: style, + content: child, + ) + : _buildContentWithRegularSizingPolicy( + context: context, + textStyle: style, + content: child, + ); + + return MouseRegion( + cursor: onPressed != null && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, + child: GestureDetector( + excludeFromSemantics: true, + onTap: onPressed, + behavior: HitTestBehavior.opaque, + child: ConstrainedBox( + constraints: const BoxConstraints( + minHeight: _kDialogMinButtonHeight, + ), + child: Container( + alignment: Alignment.center, + padding: EdgeInsets.all(_calculatePadding(context)), + child: sizedContent, + ), + ), + ), + ); + } +} + +// iOS style dialog action button layout. +// +// [_CupertinoDialogActionsRenderWidget] does not provide any scrolling +// behavior for its buttons. It only handles the sizing and layout of buttons. +// Scrolling behavior can be composed on top of this widget, if desired. +// +// See [_RenderCupertinoDialogActions] for specific layout policy details. +class _CupertinoDialogActionsRenderWidget extends MultiChildRenderObjectWidget { + const _CupertinoDialogActionsRenderWidget({ + required List actionButtons, + double dividerThickness = 0.0, + bool hasCancelButton = false, + bool isActionSheet = false, + }) : _dividerThickness = dividerThickness, + _hasCancelButton = hasCancelButton, + _isActionSheet = isActionSheet, + super(children: actionButtons); + + final double _dividerThickness; + final bool _hasCancelButton; + final bool _isActionSheet; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderCupertinoDialogActions( + dialogWidth: _isActionSheet + ? null + : _isInAccessibilityMode(context) + ? _kAccessibilityCupertinoDialogWidth + : _kCupertinoDialogWidth, + dividerThickness: _dividerThickness, + dialogColor: CupertinoDynamicColor.resolve(_isActionSheet ? _kActionSheetBackgroundColor : _kDialogColor, context), + dialogPressedColor: CupertinoDynamicColor.resolve(_kPressedColor, context), + dividerColor: CupertinoDynamicColor.resolve(_isActionSheet ? _kActionSheetButtonDividerColor : CupertinoColors.separator, context), + hasCancelButton: _hasCancelButton, + isActionSheet: _isActionSheet, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderCupertinoDialogActions renderObject) { + renderObject + ..dialogWidth = _isActionSheet + ? null + : _isInAccessibilityMode(context) + ? _kAccessibilityCupertinoDialogWidth + : _kCupertinoDialogWidth + ..dividerThickness = _dividerThickness + ..dialogColor = CupertinoDynamicColor.resolve(_isActionSheet ? _kActionSheetBackgroundColor : _kDialogColor, context) + ..dialogPressedColor = CupertinoDynamicColor.resolve(_kPressedColor, context) + ..dividerColor = CupertinoDynamicColor.resolve(_isActionSheet ? _kActionSheetButtonDividerColor : CupertinoColors.separator, context) + ..hasCancelButton = _hasCancelButton + ..isActionSheet = _isActionSheet; + } +} + +// iOS style layout policy for sizing and positioning an alert dialog's action +// buttons. +// +// The policy is as follows: +// +// If a single action button is provided, or if 2 action buttons are provided +// that can fit side-by-side, then action buttons are sized and laid out in a +// single horizontal row. The row is exactly as wide as the dialog, and the row +// is as tall as the tallest action button. A horizontal divider is drawn above +// the button row. If 2 action buttons are provided, a vertical divider is +// drawn between them. The thickness of the divider is set by [dividerThickness]. +// +// If 2 action buttons are provided but they cannot fit side-by-side, then the +// 2 buttons are stacked vertically. A horizontal divider is drawn above each +// button. The thickness of the divider is set by [dividerThickness]. The minimum +// height of this [RenderBox] in the case of 2 stacked buttons is as tall as +// the 2 buttons stacked. This is different than the 3+ button case where the +// minimum height is only 1.5 buttons tall. See the 3+ button explanation for +// more info. +// +// If 3+ action buttons are provided then they are all stacked vertically. A +// horizontal divider is drawn above each button. The thickness of the divider +// is set by [dividerThickness]. The minimum height of this [RenderBox] in the case +// of 3+ stacked buttons is as tall as the 1st button + 50% the height of the +// 2nd button. In other words, the minimum height is 1.5 buttons tall. This +// minimum height of 1.5 buttons is expected to work in tandem with a surrounding +// [ScrollView] to match the iOS dialog behavior. +// +// Each button is expected to have an _ActionButtonParentData which reports +// whether or not that button is currently pressed. If a button is pressed, +// then the dividers above and below that pressed button are not drawn - instead +// they are filled with the standard white dialog background color. The one +// exception is the very 1st divider which is always rendered. This policy comes +// from observation of native iOS dialogs. +class _RenderCupertinoDialogActions extends RenderBox + with ContainerRenderObjectMixin, + RenderBoxContainerDefaultsMixin { + _RenderCupertinoDialogActions({ + List? children, + double? dialogWidth, + double dividerThickness = 0.0, + required Color dialogColor, + required Color dialogPressedColor, + required Color dividerColor, + bool hasCancelButton = false, + bool isActionSheet = false, + }) : assert(isActionSheet || dialogWidth != null), + _dialogWidth = dialogWidth, + _buttonBackgroundPaint = Paint() + ..color = dialogColor + ..style = PaintingStyle.fill, + _pressedButtonBackgroundPaint = Paint() + ..color = dialogPressedColor + ..style = PaintingStyle.fill, + _dividerPaint = Paint() + ..color = dividerColor + ..style = PaintingStyle.fill, + _dividerThickness = dividerThickness, + _hasCancelButton = hasCancelButton, + _isActionSheet = isActionSheet { + addAll(children); + } + + double? get dialogWidth => _dialogWidth; + double? _dialogWidth; + set dialogWidth(double? newWidth) { + if (newWidth != _dialogWidth) { + _dialogWidth = newWidth; + markNeedsLayout(); + } + } + + // The thickness of the divider between buttons. + double get dividerThickness => _dividerThickness; + double _dividerThickness; + set dividerThickness(double newValue) { + if (newValue != _dividerThickness) { + _dividerThickness = newValue; + markNeedsLayout(); + } + } + + bool _hasCancelButton; + bool get hasCancelButton => _hasCancelButton; + set hasCancelButton(bool newValue) { + if (newValue == _hasCancelButton) { + return; + } + + _hasCancelButton = newValue; + markNeedsLayout(); + } + + Color get dialogColor => _buttonBackgroundPaint.color; + final Paint _buttonBackgroundPaint; + set dialogColor(Color value) { + if (value == _buttonBackgroundPaint.color) { + return; + } + + _buttonBackgroundPaint.color = value; + markNeedsPaint(); + } + + Color get dialogPressedColor => _pressedButtonBackgroundPaint.color; + final Paint _pressedButtonBackgroundPaint; + set dialogPressedColor(Color value) { + if (value == _pressedButtonBackgroundPaint.color) { + return; + } + + _pressedButtonBackgroundPaint.color = value; + markNeedsPaint(); + } + + Color get dividerColor => _dividerPaint.color; + final Paint _dividerPaint; + set dividerColor(Color value) { + if (value == _dividerPaint.color) { + return; + } + + _dividerPaint.color = value; + markNeedsPaint(); + } + + bool get isActionSheet => _isActionSheet; + bool _isActionSheet; + set isActionSheet(bool value) { + if (value == _isActionSheet) { + return; + } + + _isActionSheet = value; + markNeedsPaint(); + } + + Iterable get _pressedButtons { + final List boxes = []; + RenderBox? currentChild = firstChild; + while (currentChild != null) { + assert(currentChild.parentData is _ActionButtonParentData); + final _ActionButtonParentData parentData = currentChild.parentData! as _ActionButtonParentData; + if (parentData.isPressed) { + boxes.add(currentChild); + } + currentChild = childAfter(currentChild); + } + return boxes; + } + + bool get _isButtonPressed { + RenderBox? currentChild = firstChild; + while (currentChild != null) { + assert(currentChild.parentData is _ActionButtonParentData); + final _ActionButtonParentData parentData = currentChild.parentData! as _ActionButtonParentData; + if (parentData.isPressed) { + return true; + } + currentChild = childAfter(currentChild); + } + return false; + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! _ActionButtonParentData) { + child.parentData = _ActionButtonParentData(); + } + } + + @override + double computeMinIntrinsicWidth(double height) { + return isActionSheet ? constraints.minWidth : dialogWidth!; + } + + @override + double computeMaxIntrinsicWidth(double height) { + return isActionSheet ? constraints.maxWidth : dialogWidth!; + } + + @override + double computeMinIntrinsicHeight(double width) { + if (childCount == 0) { + return 0.0; + } else if (isActionSheet) { + if (childCount == 1) { + return firstChild!.computeMaxIntrinsicHeight(width) + dividerThickness; + } + if (hasCancelButton && childCount < 4) { + return _computeMinIntrinsicHeightWithCancel(width); + } + return _computeMinIntrinsicHeightStacked(width); + } else if (childCount == 1) { + // If only 1 button, display the button across the entire dialog. + return _computeMinIntrinsicHeightSideBySide(width); + } else if (childCount == 2 && _isSingleButtonRow(width)) { + // The first 2 buttons fit side-by-side. Display them horizontally. + return _computeMinIntrinsicHeightSideBySide(width); + } + // 3+ buttons are always stacked. The minimum height when stacked is + // 1.5 buttons tall. + return _computeMinIntrinsicHeightStacked(width); + } + + // The minimum height for more than 2-3 buttons when a cancel button is + // included is the full height of button stack. + double _computeMinIntrinsicHeightWithCancel(double width) { + assert(childCount == 2 || childCount == 3); + if (childCount == 2) { + return firstChild!.getMinIntrinsicHeight(width) + + childAfter(firstChild!)!.getMinIntrinsicHeight(width) + + dividerThickness; + } + return firstChild!.getMinIntrinsicHeight(width) + + childAfter(firstChild!)!.getMinIntrinsicHeight(width) + + childAfter(childAfter(firstChild!)!)!.getMinIntrinsicHeight(width) + + (dividerThickness * 2); + } + + // The minimum height for a single row of buttons is the larger of the buttons' + // min intrinsic heights. + double _computeMinIntrinsicHeightSideBySide(double width) { + assert(childCount >= 1 && childCount <= 2); + + final double minHeight; + if (childCount == 1) { + minHeight = firstChild!.getMinIntrinsicHeight(width); + } else { + final double perButtonWidth = (width - dividerThickness) / 2.0; + minHeight = math.max( + firstChild!.getMinIntrinsicHeight(perButtonWidth), + lastChild!.getMinIntrinsicHeight(perButtonWidth), + ); + } + return minHeight; + } + + // Dialog: The minimum height for 2+ stacked buttons is the height of the 1st + // button + 50% the height of the 2nd button + the divider between the two. + // + // ActionSheet: The minimum height for more than 2 buttons when no cancel + // button or 4+ buttons when a cancel button is included is the height of the + // 1st button + 50% the height of the 2nd button + 2 dividers. + double _computeMinIntrinsicHeightStacked(double width) { + assert(childCount >= 2); + + return firstChild!.getMinIntrinsicHeight(width) + + dividerThickness + + (0.5 * childAfter(firstChild!)!.getMinIntrinsicHeight(width)); + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (childCount == 0) { + // No buttons. Zero height. + return 0.0; + } else if (isActionSheet) { + if (childCount == 1) { + return firstChild!.computeMaxIntrinsicHeight(width) + dividerThickness; + } + return _computeMaxIntrinsicHeightStacked(width); + } else if (childCount == 1) { + // One button. Our max intrinsic height is equal to the button's. + return firstChild!.getMaxIntrinsicHeight(width); + } else if (childCount == 2) { + // Two buttons... + if (_isSingleButtonRow(width)) { + // The 2 buttons fit side by side so our max intrinsic height is equal + // to the taller of the 2 buttons. + final double perButtonWidth = (width - dividerThickness) / 2.0; + return math.max( + firstChild!.getMaxIntrinsicHeight(perButtonWidth), + lastChild!.getMaxIntrinsicHeight(perButtonWidth), + ); + } else { + // The 2 buttons do not fit side by side. Measure total height as a + // vertical stack. + return _computeMaxIntrinsicHeightStacked(width); + } + } + // Three+ buttons. Stack the buttons vertically with dividers and measure + // the overall height. + return _computeMaxIntrinsicHeightStacked(width); + } + + // Max height of a stack of buttons is the sum of all button heights + a + // divider for each button. + double _computeMaxIntrinsicHeightStacked(double width) { + assert(childCount >= 2); + + final double allDividersHeight = (childCount - 1) * dividerThickness; + double heightAccumulation = allDividersHeight; + RenderBox? button = firstChild; + while (button != null) { + heightAccumulation += button.getMaxIntrinsicHeight(width); + button = childAfter(button); + } + return heightAccumulation; + } + + bool _isSingleButtonRow(double width) { + final bool isSingleButtonRow; + if (childCount == 1) { + isSingleButtonRow = true; + } else if (childCount == 2) { + // There are 2 buttons. If they can fit side-by-side then that's what + // we want to do. Otherwise, stack them vertically. + final double sideBySideWidth = firstChild!.getMaxIntrinsicWidth(double.infinity) + + dividerThickness + + lastChild!.getMaxIntrinsicWidth(double.infinity); + isSingleButtonRow = sideBySideWidth <= width; + } else { + isSingleButtonRow = false; + } + return isSingleButtonRow; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return _performLayout(constraints: constraints, dry: true); + } + + @override + void performLayout() { + size = _performLayout(constraints: constraints); + } + + Size _performLayout({required BoxConstraints constraints, bool dry = false}) { + final ChildLayouter layoutChild = dry + ? ChildLayoutHelper.dryLayoutChild + : ChildLayoutHelper.layoutChild; + + if (!isActionSheet && _isSingleButtonRow(dialogWidth!)) { + if (childCount == 1) { + // We have 1 button. Our size is the width of the dialog and the height + // of the single button. + final Size childSize = layoutChild( + firstChild!, + constraints, + ); + + return constraints.constrain( + Size(dialogWidth!, childSize.height), + ); + } else { + // Each button gets half the available width, minus a single divider. + final BoxConstraints perButtonConstraints = BoxConstraints( + minWidth: (constraints.minWidth - dividerThickness) / 2.0, + maxWidth: (constraints.maxWidth - dividerThickness) / 2.0, + ); + + // Layout the 2 buttons. + final Size firstChildSize = layoutChild( + firstChild!, + perButtonConstraints, + ); + final Size lastChildSize = layoutChild( + lastChild!, + perButtonConstraints, + ); + + if (!dry) { + // The 2nd button needs to be offset to the right. + assert(lastChild!.parentData is MultiChildLayoutParentData); + final MultiChildLayoutParentData secondButtonParentData = lastChild!.parentData! as MultiChildLayoutParentData; + secondButtonParentData.offset = Offset(firstChildSize.width + dividerThickness, 0.0); + } + + // Calculate our size based on the button sizes. + return constraints.constrain( + Size( + dialogWidth!, + math.max( + firstChildSize.height, + lastChildSize.height, + ), + ), + ); + } + } else { + // We need to stack buttons vertically, plus dividers above each button (except the 1st). + final BoxConstraints perButtonConstraints = constraints.copyWith( + minHeight: 0.0, + maxHeight: double.infinity, + ); + + RenderBox? child = firstChild; + int index = 0; + double verticalOffset = 0.0; + while (child != null) { + final Size childSize = layoutChild( + child, + perButtonConstraints, + ); + + if (!dry) { + assert(child.parentData is MultiChildLayoutParentData); + final MultiChildLayoutParentData parentData = child.parentData! as MultiChildLayoutParentData; + parentData.offset = Offset(0.0, verticalOffset); + } + verticalOffset += childSize.height; + if (index < childCount - 1) { + // Add a gap for the next divider. + verticalOffset += dividerThickness; + } + + index += 1; + child = childAfter(child); + } + + // Our height is the accumulated height of all buttons and dividers. + return constraints.constrain( + Size(computeMaxIntrinsicWidth(0), verticalOffset), + ); + } + } + + @override + void paint(PaintingContext context, Offset offset) { + final Canvas canvas = context.canvas; + + if (!isActionSheet && _isSingleButtonRow(size.width)) { + _drawButtonBackgroundsAndDividersSingleRow(canvas, offset); + } else { + _drawButtonBackgroundsAndDividersStacked(canvas, offset); + } + + _drawButtons(context, offset); + } + + void _drawButtonBackgroundsAndDividersSingleRow(Canvas canvas, Offset offset) { + // The vertical divider sits between the left button and right button (if + // the dialog has 2 buttons). The vertical divider is hidden if either the + // left or right button is pressed. + final Rect verticalDivider = childCount == 2 && !_isButtonPressed + ? Rect.fromLTWH( + offset.dx + firstChild!.size.width, + offset.dy, + dividerThickness, + math.max( + firstChild!.size.height, + lastChild!.size.height, + ), + ) + : Rect.zero; + + final List pressedButtonRects = _pressedButtons.map((RenderBox pressedButton) { + final MultiChildLayoutParentData buttonParentData = pressedButton.parentData! as MultiChildLayoutParentData; + + return Rect.fromLTWH( + offset.dx + buttonParentData.offset.dx, + offset.dy + buttonParentData.offset.dy, + pressedButton.size.width, + pressedButton.size.height, + ); + }).toList(); + + // Create the button backgrounds path and paint it. + final Path backgroundFillPath = Path() + ..fillType = PathFillType.evenOdd + ..addRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height)) + ..addRect(verticalDivider); + + for (int i = 0; i < pressedButtonRects.length; i += 1) { + backgroundFillPath.addRect(pressedButtonRects[i]); + } + + canvas.drawPath( + backgroundFillPath, + _buttonBackgroundPaint, + ); + + // Create the pressed buttons background path and paint it. + final Path pressedBackgroundFillPath = Path(); + for (int i = 0; i < pressedButtonRects.length; i += 1) { + pressedBackgroundFillPath.addRect(pressedButtonRects[i]); + } + + canvas.drawPath( + pressedBackgroundFillPath, + _pressedButtonBackgroundPaint, + ); + + // Create the dividers path and paint it. + final Path dividersPath = Path() + ..addRect(verticalDivider); + + canvas.drawPath( + dividersPath, + _dividerPaint, + ); + } + + void _drawButtonBackgroundsAndDividersStacked(Canvas canvas, Offset offset) { + final Offset dividerOffset = Offset(0.0, dividerThickness); + + final Path backgroundFillPath = Path() + ..fillType = PathFillType.evenOdd + ..addRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height)); + + final Path pressedBackgroundFillPath = Path(); + + final Path dividersPath = Path(); + + Offset accumulatingOffset = offset; + + RenderBox? child = firstChild; + RenderBox? prevChild; + while (child != null) { + assert(child.parentData is _ActionButtonParentData); + final _ActionButtonParentData currentButtonParentData = child.parentData! as _ActionButtonParentData; + final bool isButtonPressed = currentButtonParentData.isPressed; + + bool isPrevButtonPressed = false; + if (prevChild != null) { + assert(prevChild.parentData is _ActionButtonParentData); + final _ActionButtonParentData previousButtonParentData = prevChild.parentData! as _ActionButtonParentData; + isPrevButtonPressed = previousButtonParentData.isPressed; + } + + final bool isDividerPresent = child != firstChild; + final bool isDividerPainted = isDividerPresent && !(isButtonPressed || isPrevButtonPressed); + final Rect dividerRect = Rect.fromLTWH( + accumulatingOffset.dx, + accumulatingOffset.dy, + size.width, + dividerThickness, + ); + + final Rect buttonBackgroundRect = Rect.fromLTWH( + accumulatingOffset.dx, + accumulatingOffset.dy + (isDividerPresent ? dividerThickness : 0.0), + size.width, + child.size.height, + ); + + // If this button is pressed, then we don't want a white background to be + // painted, so we erase this button from the background path. + if (isButtonPressed) { + backgroundFillPath.addRect(buttonBackgroundRect); + pressedBackgroundFillPath.addRect(buttonBackgroundRect); + } + + // If this divider is needed, then we erase the divider area from the + // background path, and on top of that we paint a translucent gray to + // darken the divider area. + if (isDividerPainted) { + backgroundFillPath.addRect(dividerRect); + dividersPath.addRect(dividerRect); + } + + accumulatingOffset += (isDividerPresent ? dividerOffset : Offset.zero) + + Offset(0.0, child.size.height); + + prevChild = child; + child = childAfter(child); + } + + canvas.drawPath(backgroundFillPath, _buttonBackgroundPaint); + canvas.drawPath(pressedBackgroundFillPath, _pressedButtonBackgroundPaint); + canvas.drawPath(dividersPath, _dividerPaint); + } + + void _drawButtons(PaintingContext context, Offset offset) { + RenderBox? child = firstChild; + while (child != null) { + final MultiChildLayoutParentData childParentData = child.parentData! as MultiChildLayoutParentData; + context.paintChild(child, childParentData.offset + offset); + child = childAfter(child); + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, {required Offset position}) { + return defaultHitTestChildren(result, position: position); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/form_row.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/form_row.dart new file mode 100644 index 0000000000000000000000000000000000000000..cec1b504a22b0b5cc5174c5e4ead54a50e0637c6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/form_row.dart @@ -0,0 +1,162 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'theme.dart'; + +// Content padding determined via SwiftUI's `Form` view in the iOS 14.2 SDK. +const EdgeInsetsGeometry _kDefaultPadding = + EdgeInsetsDirectional.fromSTEB(20.0, 6.0, 6.0, 6.0); + +/// An iOS-style form row. +/// +/// Creates an iOS-style split form row with a standard prefix and child widget. +/// Also provides a space for error and helper widgets that appear underneath. +/// +/// The [child] parameter is required. This widget is displayed at the end of +/// the row. +/// +/// The [prefix] parameter is optional and is displayed at the start of the +/// row. Standard iOS guidelines encourage passing a [Text] widget to [prefix] +/// to detail the nature of the row's [child] widget. +/// +/// The [padding] parameter is used to pad the contents of the row. It defaults +/// to the standard iOS padding. If no edge insets are intended, explicitly pass +/// [EdgeInsets.zero] to [padding]. +/// +/// The [helper] and [error] parameters are both optional widgets targeted at +/// displaying more information about the row. Both widgets are placed +/// underneath the [prefix] and [child], and will expand the row's height to +/// accommodate for their presence. When a [Text] is given to [error], it will +/// be shown in [CupertinoColors.destructiveRed] coloring and +/// medium-weighted font. +/// +/// {@tool dartpad} +/// Creates a [CupertinoFormSection] containing a [CupertinoFormRow] with [prefix], +/// [child], [helper] and [error] specified. +/// +/// ** See code in examples/api/lib/cupertino/form_row/cupertino_form_row.0.dart ** +/// {@end-tool} +/// +class CupertinoFormRow extends StatelessWidget { + /// Creates an iOS-style split form row with a standard prefix and child widget. + /// Also provides a space for error and helper widgets that appear underneath. + /// + /// The [child] parameter is required. This widget is displayed at the end of + /// the row. + /// + /// The [prefix] parameter is optional and is displayed at the start of the + /// row. Standard iOS guidelines encourage passing a [Text] widget to [prefix] + /// to detail the nature of the row's [child] widget. + /// + /// The [padding] parameter is used to pad the contents of the row. It defaults + /// to the standard iOS padding. If no edge insets are intended, explicitly + /// pass [EdgeInsets.zero] to [padding]. + /// + /// The [helper] and [error] parameters are both optional widgets targeted at + /// displaying more information about the row. Both widgets are placed + /// underneath the [prefix] and [child], and will expand the row's height to + /// accommodate for their presence. When a [Text] is given to [error], it will + /// be shown in [CupertinoColors.destructiveRed] coloring and + /// medium-weighted font. + const CupertinoFormRow({ + super.key, + required this.child, + this.prefix, + this.padding, + this.helper, + this.error, + }); + + /// A widget that is displayed at the start of the row. + /// + /// The [prefix] parameter is displayed at the start of the row. Standard iOS + /// guidelines encourage passing a [Text] widget to [prefix] to detail the + /// nature of the row's [child] widget. If null, the [child] widget will take + /// up all horizontal space in the row. + final Widget? prefix; + + /// Content padding for the row. + /// + /// Defaults to the standard iOS padding for form rows. If no edge insets are + /// intended, explicitly pass [EdgeInsets.zero] to [padding]. + final EdgeInsetsGeometry? padding; + + /// A widget that is displayed underneath the [prefix] and [child] widgets. + /// + /// The [helper] appears in primary label coloring, and is meant to inform the + /// user about interaction with the child widget. The row becomes taller in + /// order to display the [helper] widget underneath [prefix] and [child]. If + /// null, the row is shorter. + final Widget? helper; + + /// A widget that is displayed underneath the [prefix] and [child] widgets. + /// + /// The [error] widget is primarily used to inform users of input errors. When + /// a [Text] is given to [error], it will be shown in + /// [CupertinoColors.destructiveRed] coloring and medium-weighted font. The + /// row becomes taller in order to display the [helper] widget underneath + /// [prefix] and [child]. If null, the row is shorter. + final Widget? error; + + /// Child widget. + /// + /// The [child] widget is primarily used for input. It end-aligned and + /// horizontally flexible, taking up the entire space trailing past the + /// [prefix] widget. + final Widget child; + + @override + Widget build(BuildContext context) { + final CupertinoThemeData theme = CupertinoTheme.of(context); + final TextStyle textStyle = theme.textTheme.textStyle.copyWith( + color: CupertinoDynamicColor.maybeResolve(theme.textTheme.textStyle.color, context) + ); + + return Padding( + padding: padding ?? _kDefaultPadding, + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + if (prefix != null) + DefaultTextStyle( + style: textStyle, + child: prefix!, + ), + Flexible( + child: Align( + alignment: AlignmentDirectional.centerEnd, + child: child, + ), + ), + ], + ), + if (helper != null) + Align( + alignment: AlignmentDirectional.centerStart, + child: DefaultTextStyle( + style: textStyle, + child: helper!, + ), + ), + if (error != null) + Align( + alignment: AlignmentDirectional.centerStart, + child: DefaultTextStyle( + style: const TextStyle( + color: CupertinoColors.destructiveRed, + fontWeight: FontWeight.w500, + ), + child: error!, + ), + ), + ], + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/form_section.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/form_section.dart new file mode 100644 index 0000000000000000000000000000000000000000..c3d662575a40ab475601422f13419df83f388d69 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/form_section.dart @@ -0,0 +1,233 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'list_section.dart'; + +// Used for iOS "Inset Grouped" margin, determined from SwiftUI's Forms in +// iOS 14.2 SDK. +const EdgeInsetsDirectional _kFormDefaultInsetGroupedRowsMargin = EdgeInsetsDirectional.fromSTEB(20.0, 0.0, 20.0, 10.0); + +/// An iOS-style form section. +/// +/// The base constructor for [CupertinoFormSection] constructs an +/// edge-to-edge style section which includes an iOS-style header, rows, +/// the dividers between rows, and borders on top and bottom of the rows. +/// +/// The [CupertinoFormSection.insetGrouped] constructor creates a round-edged and +/// padded section that is commonly seen in notched-displays like iPhone X and +/// beyond. Creates an iOS-style header, rows, and the dividers +/// between rows. Does not create borders on top and bottom of the rows. +/// +/// The [header] parameter sets the form section header. The section header lies +/// above the [children] rows, with margins that match the iOS style. +/// +/// The [footer] parameter sets the form section footer. The section footer +/// lies below the [children] rows. +/// +/// The [children] parameter is required and sets the list of rows shown in +/// the section. The [children] parameter takes a list, as opposed to a more +/// efficient builder function that lazy builds, because forms are intended to +/// be short in row count. It is recommended that only [CupertinoFormRow] and +/// [CupertinoTextFormFieldRow] widgets be included in the [children] list in +/// order to retain the iOS look. +/// +/// The [margin] parameter sets the spacing around the content area of the +/// section encapsulating [children]. +/// +/// The [decoration] parameter sets the decoration around [children]. +/// If null, defaults to [CupertinoColors.secondarySystemGroupedBackground]. +/// If null, defaults to 10.0 circular radius when constructing with +/// [CupertinoFormSection.insetGrouped]. Defaults to zero radius for the +/// standard [CupertinoFormSection] constructor. +/// +/// The [backgroundColor] parameter sets the background color behind the section. +/// If null, defaults to [CupertinoColors.systemGroupedBackground]. +/// +/// {@macro flutter.material.Material.clipBehavior} +/// +/// See also: +/// +/// * [CupertinoFormRow], an iOS-style list tile, a typical child of +/// [CupertinoFormSection]. +/// * [CupertinoListSection], an iOS-style list section. +class CupertinoFormSection extends StatelessWidget { + /// Creates a section that mimics standard iOS forms. + /// + /// The base constructor for [CupertinoFormSection] constructs an + /// edge-to-edge style section which includes an iOS-style header, + /// rows, the dividers between rows, and borders on top and bottom of the rows. + /// + /// The [header] parameter sets the form section header. The section header + /// lies above the [children] rows, with margins that match the iOS style. + /// + /// The [footer] parameter sets the form section footer. The section footer + /// lies below the [children] rows. + /// + /// The [children] parameter is required and sets the list of rows shown in + /// the section. The [children] parameter takes a list, as opposed to a more + /// efficient builder function that lazy builds, because forms are intended to + /// be short in row count. It is recommended that only [CupertinoFormRow] and + /// [CupertinoTextFormFieldRow] widgets be included in the [children] list in + /// order to retain the iOS look. + /// + /// The [margin] parameter sets the spacing around the content area of the + /// section encapsulating [children], and defaults to zero padding. + /// + /// The [decoration] parameter sets the decoration around [children]. + /// If null, defaults to [CupertinoColors.secondarySystemGroupedBackground]. + /// If null, defaults to 10.0 circular radius when constructing with + /// [CupertinoFormSection.insetGrouped]. Defaults to zero radius for the + /// standard [CupertinoFormSection] constructor. + /// + /// The [backgroundColor] parameter sets the background color behind the + /// section. If null, defaults to [CupertinoColors.systemGroupedBackground]. + /// + /// {@macro flutter.material.Material.clipBehavior} + const CupertinoFormSection({ + super.key, + required this.children, + this.header, + this.footer, + this.margin = EdgeInsets.zero, + this.backgroundColor = CupertinoColors.systemGroupedBackground, + this.decoration, + this.clipBehavior = Clip.none, + }) : _type = CupertinoListSectionType.base, + assert(children.length > 0); + + /// Creates a section that mimics standard "Inset Grouped" iOS forms. + /// + /// The [CupertinoFormSection.insetGrouped] constructor creates a round-edged and + /// padded section that is commonly seen in notched-displays like iPhone X and + /// beyond. Creates an iOS-style header, rows, and the dividers + /// between rows. Does not create borders on top and bottom of the rows. + /// + /// The [header] parameter sets the form section header. The section header + /// lies above the [children] rows, with margins that match the iOS style. + /// + /// The [footer] parameter sets the form section footer. The section footer + /// lies below the [children] rows. + /// + /// The [children] parameter is required and sets the list of rows shown in + /// the section. The [children] parameter takes a list, as opposed to a more + /// efficient builder function that lazy builds, because forms are intended to + /// be short in row count. It is recommended that only [CupertinoFormRow] and + /// [CupertinoTextFormFieldRow] widgets be included in the [children] list in + /// order to retain the iOS look. + /// + /// The [margin] parameter sets the spacing around the content area of the + /// section encapsulating [children], and defaults to the standard + /// notched-style iOS form padding. + /// + /// The [decoration] parameter sets the decoration around [children]. + /// If null, defaults to [CupertinoColors.secondarySystemGroupedBackground]. + /// If null, defaults to 10.0 circular radius when constructing with + /// [CupertinoFormSection.insetGrouped]. Defaults to zero radius for the + /// standard [CupertinoFormSection] constructor. + /// + /// The [backgroundColor] parameter sets the background color behind the + /// section. If null, defaults to [CupertinoColors.systemGroupedBackground]. + /// + /// {@macro flutter.material.Material.clipBehavior} + const CupertinoFormSection.insetGrouped({ + super.key, + required this.children, + this.header, + this.footer, + this.margin = _kFormDefaultInsetGroupedRowsMargin, + this.backgroundColor = CupertinoColors.systemGroupedBackground, + this.decoration, + this.clipBehavior = Clip.none, + }) : _type = CupertinoListSectionType.insetGrouped, + assert(children.length > 0); + + final CupertinoListSectionType _type; + + /// Sets the form section header. The section header lies above the + /// [children] rows. + final Widget? header; + + /// Sets the form section footer. The section footer lies below the + /// [children] rows. + final Widget? footer; + + /// Margin around the content area of the section encapsulating [children]. + /// + /// Defaults to zero padding if constructed with standard + /// [CupertinoFormSection] constructor. Defaults to the standard notched-style + /// iOS margin when constructing with [CupertinoFormSection.insetGrouped]. + final EdgeInsetsGeometry margin; + + /// The list of rows in the section. + /// + /// This takes a list, as opposed to a more efficient builder function that + /// lazy builds, because forms are intended to be short in row count. It is + /// recommended that only [CupertinoFormRow] and [CupertinoTextFormFieldRow] + /// widgets be included in the [children] list in order to retain the iOS look. + final List children; + + /// Sets the decoration around [children]. + /// + /// If null, background color defaults to + /// [CupertinoColors.secondarySystemGroupedBackground]. + /// + /// If null, border radius defaults to 10.0 circular radius when constructing + /// with [CupertinoFormSection.insetGrouped]. Defaults to zero radius for the + /// standard [CupertinoFormSection] constructor. + final BoxDecoration? decoration; + + /// Sets the background color behind the section. + /// + /// Defaults to [CupertinoColors.systemGroupedBackground]. + final Color backgroundColor; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + @override + Widget build(BuildContext context) { + final Widget? headerWidget = header == null + ? null + : DefaultTextStyle( + style: TextStyle( + fontSize: 13.0, + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ), + child: header!); + + final Widget? footerWidget = footer == null + ? null + : DefaultTextStyle( + style: TextStyle( + fontSize: 13.0, + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ), + child: footer!); + + return _type == CupertinoListSectionType.base + ? CupertinoListSection( + header: headerWidget, + footer: footerWidget, + margin: margin, + backgroundColor: backgroundColor, + decoration: decoration, + clipBehavior: clipBehavior, + hasLeading: false, + children: children) + : CupertinoListSection.insetGrouped( + header: headerWidget, + footer: footerWidget, + margin: margin, + backgroundColor: backgroundColor, + decoration: decoration, + clipBehavior: clipBehavior, + hasLeading: false, + children: children); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/icon_theme_data.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/icon_theme_data.dart new file mode 100644 index 0000000000000000000000000000000000000000..8aa981af4dbd371861f8490f025e1607d7d345ec --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/icon_theme_data.dart @@ -0,0 +1,64 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; +import 'colors.dart'; + +/// An [IconThemeData] subclass that automatically resolves its [color] when retrieved +/// using [IconTheme.of]. +class CupertinoIconThemeData extends IconThemeData with Diagnosticable { + /// Creates a [CupertinoIconThemeData]. + const CupertinoIconThemeData({ + super.size, + super.fill, + super.weight, + super.grade, + super.opticalSize, + super.color, + super.opacity, + super.shadows, + super.applyTextScaling, + }); + + /// Called by [IconTheme.of] to resolve [color] against the given [BuildContext]. + @override + IconThemeData resolve(BuildContext context) { + final Color? resolvedColor = CupertinoDynamicColor.maybeResolve(color, context); + return resolvedColor == color ? this : copyWith(color: resolvedColor); + } + + /// Creates a copy of this icon theme but with the given fields replaced with + /// the new values. + @override + CupertinoIconThemeData copyWith({ + double? size, + double? fill, + double? weight, + double? grade, + double? opticalSize, + Color? color, + double? opacity, + List? shadows, + bool? applyTextScaling, + }) { + return CupertinoIconThemeData( + size: size ?? this.size, + fill: fill ?? this.fill, + weight: weight ?? this.weight, + grade: grade ?? this.grade, + opticalSize: opticalSize ?? this.opticalSize, + color: color ?? this.color, + opacity: opacity ?? this.opacity, + shadows: shadows ?? this.shadows, + applyTextScaling: applyTextScaling ?? this.applyTextScaling, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(createCupertinoColorProperty('color', color, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/icons.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/icons.dart new file mode 100644 index 0000000000000000000000000000000000000000..9d9eda6210ba10f6a8fc04c0ca64648d6867e912 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/icons.dart @@ -0,0 +1,3579 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +/// Identifiers for the supported Cupertino icons. +/// +/// Use with the [Icon] class to show specific icons. +/// +/// Icons are identified by their name as listed below. +/// +/// To use this class, make sure you add a dependency on `cupertino_icons` in your +/// project's `pubspec.yaml` file. This ensures that the CupertinoIcons font is +/// included in your application. This font is used to display the icons. For example: +/// +/// ```yaml +/// name: my_awesome_application +/// +/// dependencies: +/// cupertino_icons: ^1.0.0 +/// ``` +/// +/// {@tool snippet} +/// +/// This example shows how to create a [Row] of Cupertino [Icon]s in different colors and +/// sizes. The first [Icon] uses a [Icon.semanticLabel] to announce in accessibility +/// modes like VoiceOver. +/// +/// ![The following code snippet would generate a row of icons consisting of a pink heart, a green bell, and a blue umbrella, each progressively bigger than the last.](https://flutter.github.io/assets-for-api-docs/assets/cupertino/cupertino_icon.png) +/// +/// ```dart +/// const Row( +/// mainAxisAlignment: MainAxisAlignment.spaceAround, +/// children: [ +/// Icon( +/// CupertinoIcons.heart_fill, +/// color: Colors.pink, +/// size: 24.0, +/// semanticLabel: 'Text to announce in accessibility modes', +/// ), +/// Icon( +/// CupertinoIcons.bell_fill, +/// color: Colors.green, +/// size: 30.0, +/// ), +/// Icon( +/// CupertinoIcons.umbrella_fill, +/// color: Colors.blue, +/// size: 36.0, +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// For versions 0.1.3 and below, see this [glyph map](https://raw.githubusercontent.com/flutter/packages/master/third_party/packages/cupertino_icons/map.png). +/// +/// See also: +/// +/// * [Icon], used to show these icons. +@staticIconProvider +abstract final class CupertinoIcons { + /// The icon font used for Cupertino icons. + static const String iconFont = 'CupertinoIcons'; + + /// The dependent package providing the Cupertino icons font. + static const String iconFontPackage = 'cupertino_icons'; + + // =========================================================================== + // BEGIN LEGACY PRE SF SYMBOLS NAMES + // We need to leave them as-is with the same codepoints for backward + // compatibility with cupertino_icons <0.1.3. + + /// chevron_left — Cupertino icon for a thin left chevron. + /// This is the same icon as [chevron_left] in cupertino_icons 1.0.0+. + static const IconData left_chevron = IconData(0xf3d2, fontFamily: iconFont, fontPackage: iconFontPackage, matchTextDirection: true); + + /// chevron_right — Cupertino icon for a thin right chevron. + /// This is the same icon as [chevron_right] in cupertino_icons 1.0.0+. + static const IconData right_chevron = IconData(0xf3d3, fontFamily: iconFont, fontPackage: iconFontPackage, matchTextDirection: true); + + /// square_arrow_up — Cupertino icon for an iOS style share icon with an arrow pointing up from a box. This icon is not filled in. + /// This is the same icon as [square_arrow_up] and [share_up] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [share_solid], which is similar, but filled in. + /// * [share_up], for another (pre-iOS 7) version of this icon. + static const IconData share = IconData(0xf4ca, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// square_arrow_up_fill — Cupertino icon for an iOS style share icon with an arrow pointing up from a box. This icon is filled in. + /// This is the same icon as [square_arrow_up_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [share], which is similar, but not filled in. + /// * [share_up], for another (pre-iOS 7) version of this icon. + static const IconData share_solid = IconData(0xf4cb, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// book — Cupertino icon for a book silhouette spread open. This icon is not filled in. + /// See also: + /// + /// * [book_solid], which is similar, but filled in. + static const IconData book = IconData(0xf3e7, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// book_fill — Cupertino icon for a book silhouette spread open. This icon is filled in. + /// This is the same icon as [book_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [book], which is similar, but not filled in. + static const IconData book_solid = IconData(0xf3e8, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// bookmark — Cupertino icon for a book silhouette spread open containing a bookmark in the upper right. This icon is not filled in. + /// + /// See also: + /// + /// * [bookmark_solid], which is similar, but filled in. + static const IconData bookmark = IconData(0xf3e9, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// bookmark_fill — Cupertino icon for a book silhouette spread open containing a bookmark in the upper right. This icon is filled in. + /// This is the same icon as [bookmark_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [bookmark], which is similar, but not filled in. + static const IconData bookmark_solid = IconData(0xf3ea, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// info_circle — Cupertino icon for a letter 'i' in a circle. + /// This is the same icon as [info_circle] in cupertino_icons 1.0.0+. + static const IconData info = IconData(0xf44c, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrowshape_turn_up_left — Cupertino icon for a curved up and left pointing arrow. + /// This is the same icon as [arrowshape_turn_up_left] in cupertino_icons 1.0.0+. + /// + /// For another version of this icon, see [reply_thick_solid]. + static const IconData reply = IconData(0xf4c6, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// chat_bubble — Cupertino icon for a chat bubble. + /// This is the same icon as [chat_bubble] in cupertino_icons 1.0.0+. + static const IconData conversation_bubble = IconData(0xf3fb, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// person_crop_circle — Cupertino icon for a person's silhouette in a circle. + /// This is the same icon as [person_crop_circle] in cupertino_icons 1.0.0+. + static const IconData profile_circled = IconData(0xf419, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// plus_circle — Cupertino icon for a '+' sign in a circle. + /// This is the same icon as [plus_circle] in cupertino_icons 1.0.0+. + static const IconData plus_circled = IconData(0xf48a, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// minus_circle — Cupertino icon for a '-' sign in a circle. + /// This is the same icon as [minus_circle] in cupertino_icons 1.0.0+. + static const IconData minus_circled = IconData(0xf463, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// flag — Cupertino icon for a right facing flag and pole outline. + static const IconData flag = IconData(0xf42c, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// search — Cupertino icon for a magnifier loop outline. + static const IconData search = IconData(0xf4a5, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// checkmark — Cupertino icon for a checkmark. + /// This is the same icon as [checkmark] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [check_mark_circled], which consists of this check mark and a circle surrounding it. + static const IconData check_mark = IconData(0xf3fd, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// checkmark_circle — Cupertino icon for a checkmark in a circle. The circle is not filled in. + /// This is the same icon as [checkmark_circle] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [check_mark_circled_solid], which is similar, but filled in. + /// * [check_mark], which is the check mark without a circle. + static const IconData check_mark_circled = IconData(0xf3fe, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// checkmark_circle_fill — Cupertino icon for a checkmark in a circle. The circle is filled in. + /// This is the same icon as [checkmark_circle_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [check_mark_circled], which is similar, but not filled in. + static const IconData check_mark_circled_solid = IconData(0xf3ff, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// circle — Cupertino icon for an empty circle (a ring). An un-selected radio button. + /// + /// See also: + /// + /// * [circle_filled], which is similar but filled in. + static const IconData circle = IconData(0xf401, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// circle_fill — Cupertino icon for a filled circle. The circle is surrounded by a ring. A selected radio button. + /// This is the same icon as [circle_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [circle], which is similar but not filled in. + static const IconData circle_filled = IconData(0xf400, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// chevron_back — Cupertino icon for a thicker left chevron used in iOS for the navigation bar back button. + /// This is the same icon as [chevron_back] in cupertino_icons 1.0.0+. + static const IconData back = IconData(0xf3cf, fontFamily: iconFont, fontPackage: iconFontPackage, matchTextDirection: true); + + /// chevron_forward — Cupertino icon for a thicker right chevron that's the reverse of [back]. + /// This is the same icon as [chevron_forward] in cupertino_icons 1.0.0+. + static const IconData forward = IconData(0xf3d1, fontFamily: iconFont, fontPackage: iconFontPackage, matchTextDirection: true); + + /// house — Cupertino icon for an outline of a simple front-facing house. + /// This is the same icon as [house] in cupertino_icons 1.0.0+. + static const IconData home = IconData(0xf447, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// cart — Cupertino icon for a right-facing shopping cart outline. + /// This is the same icon as [cart] in cupertino_icons 1.0.0+. + static const IconData shopping_cart = IconData(0xf3f7, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// ellipsis — Cupertino icon for three solid dots. + static const IconData ellipsis = IconData(0xf46a, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// phone — Cupertino icon for a phone handset outline. + static const IconData phone = IconData(0xf4b8, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// phone_fill — Cupertino icon for a phone handset. + /// This is the same icon as [phone_fill] in cupertino_icons 1.0.0+. + static const IconData phone_solid = IconData(0xf4b9, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_down — Cupertino icon for a solid down arrow. + /// This is the same icon as [arrow_down] in cupertino_icons 1.0.0+. + static const IconData down_arrow = IconData(0xf35d, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_up — Cupertino icon for a solid up arrow. + /// This is the same icon as [arrow_up] in cupertino_icons 1.0.0+. + static const IconData up_arrow = IconData(0xf366, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// battery_100 — Cupertino icon for a charging battery. + /// This is the same icon as [battery_100], [battery_full] and [battery_75_percent] in cupertino_icons 1.0.0+. + static const IconData battery_charging = IconData(0xf111, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// battery_0 — Cupertino icon for an empty battery. + /// This is the same icon as [battery_0] in cupertino_icons 1.0.0+. + static const IconData battery_empty = IconData(0xf112, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// battery_100 — Cupertino icon for a full battery. + /// This is the same icon as [battery_100], [battery_charging] and [battery_75_percent] in cupertino_icons 1.0.0+. + static const IconData battery_full = IconData(0xf113, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// battery_100 — Cupertino icon for a 75% charged battery. + /// This is the same icon as [battery_100], [battery_charging] and [battery_full] in cupertino_icons 1.0.0+. + static const IconData battery_75_percent = IconData(0xf114, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// battery_25 — Cupertino icon for a 25% charged battery. + /// This is the same icon as [battery_25] in cupertino_icons 1.0.0+. + static const IconData battery_25_percent = IconData(0xf115, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// bluetooth — Cupertino icon for the Bluetooth logo. + /// This icon is available in cupertino_icons 1.0.0+ for backward + /// compatibility but not part of Apple icons' aesthetics. + static const IconData bluetooth = IconData(0xf116, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_counterclockwise — Cupertino icon for a restart arrow, pointing downwards. + /// This is the same icon as [arrow_counterclockwise] in cupertino_icons 1.0.0+. + static const IconData restart = IconData(0xf21c, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrowshape_turn_up_left_2 — Cupertino icon for two curved up and left pointing arrows. + /// This is the same icon as [arrowshape_turn_up_left_2] in cupertino_icons 1.0.0+. + static const IconData reply_all = IconData(0xf21d, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrowshape_turn_up_left_2_fill — Cupertino icon for a curved up and left pointing arrow. + /// This is the same icon as [arrowshape_turn_up_left_2_fill] in cupertino_icons 1.0.0+. + /// + /// For another version of this icon, see [reply]. + static const IconData reply_thick_solid = IconData(0xf21e, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// square_arrow_up — Cupertino icon for an iOS style share icon with an arrow pointing upwards to the right from a box. + /// This is the same icon as [square_arrow_up] and [share_up] in cupertino_icons 1.0.0+. + /// + /// For another version of this icon (introduced in iOS 7), see [share]. + static const IconData share_up = IconData(0xf220, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// shuffle_medium — Cupertino icon for two thin right-facing intertwined arrows. + /// This is the same icon as [shuffle_medium] and [shuffle_thick] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [shuffle_medium], with slightly thicker arrows. + /// * [shuffle_thick], with thicker, bold arrows. + static const IconData shuffle = IconData(0xf4a9, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// shuffle — Cupertino icon for an two medium thickness right-facing intertwined arrows. + /// This is the same icon as [shuffle] and [shuffle_thick] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [shuffle], with thin arrows. + /// * [shuffle_thick], with thicker, bold arrows. + static const IconData shuffle_medium = IconData(0xf4a8, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// shuffle_medium — Cupertino icon for two thick right-facing intertwined arrows. + /// This is the same icon as [shuffle_medium] and [shuffle] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [shuffle], with thin arrows. + /// * [shuffle_medium], with slightly thinner arrows. + static const IconData shuffle_thick = IconData(0xf221, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// camera — Cupertino icon for a camera for still photographs. This icon is filled in. + /// This is the same icon as [camera] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [photo_camera], which is similar, but not filled in. + /// * [video_camera_solid], for the moving picture equivalent. + static const IconData photo_camera = IconData(0xf3f5, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// camera_fill — Cupertino icon for a camera for still photographs. This icon is not filled in. + /// This is the same icon as [camera_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [photo_camera_solid], which is similar, but filled in. + /// * [video_camera], for the moving picture equivalent. + static const IconData photo_camera_solid = IconData(0xf3f6, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// videocam — Cupertino icon for a camera for moving pictures. This icon is not filled in. + /// This is the same icon as [videocam] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [video_camera_solid], which is similar, but filled in. + /// * [photo_camera], for the still photograph equivalent. + static const IconData video_camera = IconData(0xf4cc, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// videocam_fill — Cupertino icon for a camera for moving pictures. This icon is filled in. + /// This is the same icon as [videocam_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [video_camera], which is similar, but not filled in. + /// * [photo_camera_solid], for the still photograph equivalent. + static const IconData video_camera_solid = IconData(0xf4cd, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// camera_rotate — Cupertino icon for a camera containing two circular arrows pointing at each other, which indicate switching. This icon is not filled in. + /// This is the same icon as [camera_rotate] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [switch_camera_solid], which is similar, but filled in. + static const IconData switch_camera = IconData(0xf49e, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// camera_rotate_fill — Cupertino icon for a camera containing two circular arrows pointing at each other, which indicate switching. This icon is filled in. + /// This is the same icon as [camera_rotate_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [switch_camera], which is similar, but not filled in. + static const IconData switch_camera_solid = IconData(0xf49f, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// rectangle_stack — Cupertino icon for a collection of folders, which store collections of files, i.e. an album. This icon is not filled in. + /// This is the same icon as [rectangle_stack] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [collections_solid], which is similar, but filled in. + static const IconData collections = IconData(0xf3c9, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// rectangle_stack_fill — Cupertino icon for a collection of folders, which store collections of files, i.e. an album. This icon is filled in. + /// This is the same icon as [rectangle_stack_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [collections], which is similar, but not filled in. + static const IconData collections_solid = IconData(0xf3ca, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// folder_open — Cupertino icon for a single folder, which stores multiple files. This icon is not filled in. + /// This is the same icon as [folder_open] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [folder_solid], which is similar, but filled in. + /// * [folder_open], which is the pre-iOS 7 version of this icon. + static const IconData folder = IconData(0xf434, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// folder_fill — Cupertino icon for a single folder, which stores multiple files. This icon is filled in. + /// This is the same icon as [folder_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [folder], which is similar, but not filled in. + /// * [folder_open], which is the pre-iOS 7 version of this icon and not filled in. + static const IconData folder_solid = IconData(0xf435, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// folder — Cupertino icon for a single folder that indicates being opened. A folder like this typically stores multiple files. + /// This is the same icon as [folder] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [folder], which is the equivalent of this icon for iOS versions later than or equal to iOS 7. + static const IconData folder_open = IconData(0xf38a, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// trash — Cupertino icon for a trash bin for removing items. This icon is not filled in. + /// This is the same icon as [trash] and [delete_simple] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [delete_solid], which is similar, but filled in. + static const IconData delete = IconData(0xf4c4, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// trash_fill — Cupertino icon for a trash bin for removing items. This icon is filled in. + /// This is the same icon as [trash_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [delete], which is similar, but not filled in. + static const IconData delete_solid = IconData(0xf4c5, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// trash — Cupertino icon for a trash bin with minimal detail for removing items. + /// This is the same icon as [trash] and [delete] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [delete], which is the iOS 7 equivalent of this icon with richer detail. + static const IconData delete_simple = IconData(0xf37f, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// pen — Cupertino icon for a simple pen. + /// + /// See also: + /// + /// * [pencil], which is similar, but has less detail and looks like a pencil. + static const IconData pen = IconData(0xf2bf, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// pencil — Cupertino icon for a simple pencil. + /// + /// See also: + /// + /// * [pen], which is similar, but has more detail and looks like a pen. + static const IconData pencil = IconData(0xf37e, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// square_pencil — Cupertino icon for a box for writing and a pen on top (that indicates the writing). This icon is not filled in. + /// This is the same icon as [square_pencil] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [create_solid], which is similar, but filled in. + /// * [pencil], which is just a pencil. + /// * [pen], which is just a pen. + static const IconData create = IconData(0xf417, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// square_pencil_fill — Cupertino icon for a box for writing and a pen on top (that indicates the writing). This icon is filled in. + /// This is the same icon as [square_pencil_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [create], which is similar, but not filled in. + /// * [pencil], which is just a pencil. + /// * [pen], which is just a pen. + static const IconData create_solid = IconData(0xf417, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_clockwise — Cupertino icon for an arrow on a circular path with its end pointing at its start. + /// This is the same icon as [arrow_clockwise], [refresh_thin] and [refresh_thick] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [refresh_circled], which is this icon put in a circle. + /// * [refresh_thin], which is an arrow of the same concept, but thinner and with a smaller gap in between its end and start. + /// * [refresh_thick], which is similar, but rotated 45 degrees clockwise and thicker. + /// * [refresh_bold], which is similar, but rotated 90 degrees clockwise and much thicker. + static const IconData refresh = IconData(0xf49a, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_clockwise_circle — Cupertino icon for an arrow on a circular path with its end pointing at its start surrounded by a circle. This is icon is not filled in. + /// This is the same icon as [arrow_clockwise_circle] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [refresh_circled_solid], which is similar, but filled in. + /// * [refresh], which is the arrow of this icon without a circle. + static const IconData refresh_circled = IconData(0xf49b, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_clockwise_circle_fill — Cupertino icon for an arrow on a circular path with its end pointing at its start surrounded by a circle. This is icon is filled in. + /// This is the same icon as [arrow_clockwise_circle_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [refresh_circled], which is similar, but not filled in. + /// * [refresh], which is the arrow of this icon filled in without a circle. + static const IconData refresh_circled_solid = IconData(0xf49c, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_clockwise — Cupertino icon for an arrow on a circular path with its end pointing at its start. + /// This is the same icon as [arrow_clockwise], [refresh] and [refresh_thick] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [refresh], which is an arrow of the same concept, but thicker and with a larger gap in between its end and start. + static const IconData refresh_thin = IconData(0xf49d, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_clockwise — Cupertino icon for an arrow on a circular path with its end pointing at its start. + /// This is the same icon as [arrow_clockwise], [refresh_thin] and [refresh] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [refresh], which is similar, but rotated 45 degrees anti-clockwise and thinner. + /// * [refresh_bold], which is similar, but rotated 45 degrees clockwise and thicker. + static const IconData refresh_thick = IconData(0xf3a8, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_counterclockwise — Cupertino icon for an arrow on a circular path with its end pointing at its start. + /// This is the same icon as [arrow_counterclockwise] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [refresh_thick], which is similar, but rotated 45 degrees anti-clockwise and thinner. + /// * [refresh], which is similar, but rotated 90 degrees anti-clockwise and much thinner. + static const IconData refresh_bold = IconData(0xf21c, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// xmark — Cupertino icon for a cross of two diagonal lines from edge to edge crossing in an angle of 90 degrees, which is used for dismissal. + /// This is the same icon as [xmark] and [clear] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [clear_circled], which uses this cross as a blank space in a filled out circled. + /// * [clear], which uses a thinner cross and is the iOS 7 equivalent of this icon. + static const IconData clear_thick = IconData(0xf2d7, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// xmark_circle_fill — Cupertino icon for a cross of two diagonal lines from edge to edge crossing in an angle of 90 degrees, which is used for dismissal, used as a blank space in a circle. + /// This is the same icon as [xmark_circle_fill] and [clear_circled_solid] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [clear], which is equivalent to the cross of this icon without a circle. + /// * [clear_circled_solid], which is similar, but uses a thinner cross. + static const IconData clear_thick_circled = IconData(0xf36e, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// xmark — Cupertino icon for a cross of two diagonal lines from edge to edge crossing in an angle of 90 degrees, which is used for dismissal. + /// This is the same icon as [xmark] and [clear_thick] in cupertino_icons 1.0.0+. + /// + /// + /// See also: + /// + /// * [clear_circled], which consists of this cross and a circle surrounding it. + /// * [clear], which uses a thicker cross and is the pre-iOS 7 equivalent of this icon. + static const IconData clear = IconData(0xf404, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// xmark_circle — Cupertino icon for a cross of two diagonal lines from edge to edge crossing in an angle of 90 degrees, which is used for dismissal, surrounded by circle. This icon is not filled in. + /// This is the same icon as [xmark_circle] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [clear_circled_solid], which is similar, but filled in. + /// * [clear], which is the standalone cross of this icon. + static const IconData clear_circled = IconData(0xf405, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// xmark_circle_fill — Cupertino icon for a cross of two diagonal lines from edge to edge crossing in an angle of 90 degrees, which is used for dismissal, used as a blank space in a circle. This icon is filled in. + /// This is the same icon as [xmark_circle_fill] and [clear_thick_circled] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [clear_circled], which is similar, but not filled in. + static const IconData clear_circled_solid = IconData(0xf406, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// plus — Cupertino icon for an two straight lines, one horizontal and one vertical, meeting in the middle, which is the equivalent of a plus sign. + /// This is the same icon as [plus] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [plus_circled], which is the pre-iOS 7 version of this icon with a thicker cross. + /// * [add_circled], which consists of the plus and a circle around it. + static const IconData add = IconData(0xf489, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// plus_circle — Cupertino icon for an two straight lines, one horizontal and one vertical, meeting in the middle, which is the equivalent of a plus sign, surrounded by a circle. This icon is not filled in. + /// This is the same icon as [plus_circle] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [plus_circled], which is the pre-iOS 7 version of this icon with a thicker cross and a filled in circle. + /// * [add_circled_solid], which is similar, but filled in. + static const IconData add_circled = IconData(0xf48a, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// plus_circle_fill — Cupertino icon for an two straight lines, one horizontal and one vertical, meeting in the middle, which is the equivalent of a plus sign, surrounded by a circle. This icon is not filled in. + /// This is the same icon as [plus_circle_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [plus_circled], which is the pre-iOS 7 version of this icon with a thicker cross. + /// * [add_circled], which is similar, but not filled in. + static const IconData add_circled_solid = IconData(0xf48b, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// gear_alt — Cupertino icon for a gear with eight cogs. This icon is not filled in. + /// This is the same icon as [gear_alt] and [gear_big] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [gear_solid], which is similar, but filled in. + /// * [gear_big], which is the pre-iOS 7 version of this icon and appears bigger because of fewer and bigger cogs. + /// * [settings], which is another cogwheel with a different design. + static const IconData gear = IconData(0xf43c, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// gear_alt_fill — Cupertino icon for a gear with eight cogs. This icon is filled in. + /// This is the same icon as [gear_alt_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [gear], which is similar, but not filled in. + /// * [settings_solid], which is another cogwheel with a different design. + static const IconData gear_solid = IconData(0xf43d, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// gear_alt — Cupertino icon for a gear with six cogs. + /// This is the same icon as [gear_alt] and [gear] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [gear], which is the iOS 7 version of this icon and appears smaller because of more and larger cogs. + /// * [settings_solid], which is another cogwheel with a different design. + static const IconData gear_big = IconData(0xf2f7, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// settings — Cupertino icon for a cogwheel with many cogs and decoration in the middle. This icon is not filled in. + /// + /// See also: + /// + /// * [settings_solid], which is similar, but filled in. + /// * [gear], which is another cogwheel with a different design. + static const IconData settings = IconData(0xf411, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// settings_solid — Cupertino icon for a cogwheel with many cogs and decoration in the middle. This icon is filled in. + /// + /// See also: + /// + /// * [settings], which is similar, but not filled in. + /// * [gear_solid], which is another cogwheel with a different design. + static const IconData settings_solid = IconData(0xf412, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// music_note — Cupertino icon for a symbol representing a solid single musical note. + /// + /// See also: + /// + /// * [double_music_note], which is similar, but with 2 connected notes. + static const IconData music_note = IconData(0xf46b, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// music_note_2 — Cupertino icon for a symbol representing 2 connected musical notes. + /// This is the same icon as [music_note_2] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [music_note], which is similar, but with a single note. + static const IconData double_music_note = IconData(0xf46c, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// play — Cupertino icon for a triangle facing to the right. This icon is not filled in. + /// This is the same icon as [play] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [play_arrow_solid], which is similar, but filled in. + static const IconData play_arrow = IconData(0xf487, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// play_fill — Cupertino icon for a triangle facing to the right. This icon is filled in. + /// This is the same icon as [play_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [play_arrow], which is similar, but not filled in. + static const IconData play_arrow_solid = IconData(0xf488, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// pause — Cupertino icon for an two vertical rectangles. This icon is not filled in. + /// + /// See also: + /// + /// * [pause_solid], which is similar, but filled in. + static const IconData pause = IconData(0xf477, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// pause_fill — Cupertino icon for an two vertical rectangles. This icon is filled in. + /// This is the same icon as [pause_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [pause], which is similar, but not filled in. + static const IconData pause_solid = IconData(0xf478, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// infinite — Cupertino icon for the infinity symbol. + /// This is the same icon as [infinite] and [loop_thick] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [loop_thick], which is similar, but thicker. + static const IconData loop = IconData(0xf449, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// infinite — Cupertino icon for the infinity symbol. + /// This is the same icon as [infinite] and [loop] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [loop], which is similar, but thinner. + static const IconData loop_thick = IconData(0xf44a, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// speaker_1_fill — Cupertino icon for a speaker with a single small sound wave. + /// This is the same icon as [speaker_1_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [volume_mute], which is similar, but has no sound waves. + /// * [volume_off], which is similar, but with an additional larger sound wave and a diagonal line crossing the whole icon. + /// * [volume_up], which has an additional larger sound wave next to the small one. + static const IconData volume_down = IconData(0xf3b7, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// speaker_fill — Cupertino icon for a speaker symbol. + /// This is the same icon as [speaker_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [volume_down], which is similar, but adds a small sound wave. + /// * [volume_off], which is similar, but adds a small and a large sound wave and a diagonal line crossing the whole icon. + /// * [volume_up], which is similar, but has a small and a large sound wave. + static const IconData volume_mute = IconData(0xf3b8, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// speaker_slash_fill — Cupertino icon for a speaker with a small and a large sound wave and a diagonal line crossing the whole icon. + /// This is the same icon as [speaker_slash_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [volume_down], which is similar, but not crossed out and only has the small wave. + /// * [volume_mute], which is similar, but not crossed out. + /// * [volume_up], which is the version of this icon that is not crossed out. + static const IconData volume_off = IconData(0xf3b9, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// speaker_3_fill — Cupertino icon for a speaker with a small and a large sound wave. + /// This is the same icon as [speaker_3_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [volume_down], which is similar, but only has the small sound wave. + /// * [volume_mute], which is similar, but has no sound waves. + /// * [volume_off], which is the crossed out version of this icon. + static const IconData volume_up = IconData(0xf3ba, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_up_left_arrow_down_right — Cupertino icon for all four corners of a square facing inwards. + /// This is the same icon as [arrow_up_left_arrow_down_right] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [fullscreen_exit], which is similar, but has the corners facing outwards. + static const IconData fullscreen = IconData(0xf386, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// arrow_down_right_arrow_up_left — Cupertino icon for all four corners of a square facing outwards. + /// This is the same icon as [arrow_down_right_arrow_up_left] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [fullscreen], which is similar, but has the corners facing inwards. + static const IconData fullscreen_exit = IconData(0xf37d, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// mic_slash — Cupertino icon for a filled in microphone with a diagonal line crossing it. + /// This is the same icon as [mic_slash] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [mic], which is similar, but not filled in and without a diagonal line. + /// * [mic_solid], which is similar, but without a diagonal line. + static const IconData mic_off = IconData(0xf45f, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// mic — Cupertino icon for a microphone. + /// + /// See also: + /// + /// * [mic_solid], which is similar, but filled in. + /// * [mic_off], which is similar, but filled in and with a diagonal line crossing the icon. + static const IconData mic = IconData(0xf460, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// mic_fill — Cupertino icon for a filled in microphone. + /// This is the same icon as [mic_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [mic], which is similar, but not filled in. + /// * [mic_off], which is similar, but with a diagonal line crossing the icon. + static const IconData mic_solid = IconData(0xf461, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// time — Cupertino icon for a circle with a dotted clock face inside with hands showing 10:30. + /// This is the same icon as [time] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [clock_solid], which is similar, but filled in. + /// * [time], which is similar, but without dots on the clock face. + /// * [time_solid], which is similar, but filled in and without dots on the clock face. + static const IconData clock = IconData(0xf4be, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// clock_fill — Cupertino icon for a filled in circle with a dotted clock face inside with hands showing 10:30. + /// This is the same icon as [clock_fill] and [time_solid] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [clock], which is similar, but not filled in. + /// * [time], which is similar, but not filled in and without dots on the clock face. + /// * [time_solid], which is similar, but without dots on the clock face. + static const IconData clock_solid = IconData(0xf4bf, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// clock — Cupertino icon for a circle with a 90 degree angle shape in the center, resembling a clock with hands showing 09:00. + /// This is the same icon as [clock] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [time_solid], which is similar, but filled in. + /// * [clock], which is similar, but with dots on the clock face. + /// * [clock_solid], which is similar, but filled in and with dots on the clock face. + static const IconData time = IconData(0xf402, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// clock_fill — Cupertino icon for a filled in circle with a 90 degree angle shape in the center, resembling a clock with hands showing 09:00. + /// This is the same icon as [clock_fill] and [clock_solid] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [time], which is similar, but not filled in. + /// * [clock], which is similar, but not filled in and with dots on the clock face. + /// * [clock_solid], which is similar, but with dots on the clock face. + static const IconData time_solid = IconData(0xf403, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// lock — Cupertino icon for an unlocked padlock. + /// This is the same icon as [lock] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [padlock_solid], which is similar, but filled in. + static const IconData padlock = IconData(0xf4c8, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// lock_fill — Cupertino icon for an unlocked padlock. + /// This is the same icon as [lock_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [padlock], which is similar, but not filled in. + static const IconData padlock_solid = IconData(0xf4c9, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// eye — Cupertino icon for an open eye. + /// + /// See also: + /// + /// * [eye_solid], which is similar, but filled in. + static const IconData eye = IconData(0xf424, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// eye_fill — Cupertino icon for an open eye. + /// This is the same icon as [eye_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [eye], which is similar, but not filled in. + static const IconData eye_solid = IconData(0xf425, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// person — Cupertino icon for a single person. This icon is not filled in. + /// + /// See also: + /// + /// * [person_solid], which is similar, but filled in. + /// * [person_add], which has an additional plus sign next to the person. + /// * [group], which consists of three people. + static const IconData person = IconData(0xf47d, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// person_fill — Cupertino icon for a single person. This icon is filled in. + /// This is the same icon as [person_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [person], which is similar, but not filled in. + /// * [person_add_solid], which has an additional plus sign next to the person. + /// * [group_solid], which consists of three people. + static const IconData person_solid = IconData(0xf47e, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// person_badge_plus — Cupertino icon for a single person with a plus sign next to it. This icon is not filled in. + /// This is the same icon as [person_badge_plus] in cupertino_icons 1.0.0+.x + /// + /// See also: + /// + /// * [person_add_solid], which is similar, but filled in. + /// * [person], which is just the person. + /// * [group], which consists of three people. + static const IconData person_add = IconData(0xf47f, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// person_badge_plus_fill — Cupertino icon for a single person with a plus sign next to it. This icon is filled in. + /// This is the same icon as [person_badge_plus_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [person_add], which is similar, but not filled in. + /// * [person_solid], which is just the person. + /// * [group_solid], which consists of three people. + static const IconData person_add_solid = IconData(0xf480, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// person_3 — Cupertino icon for a group of three people. This icon is not filled in. + /// This is the same icon as [person_3] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [group_solid], which is similar, but filled in. + /// * [person], which is just a single person. + static const IconData group = IconData(0xf47b, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// person_3_fill — Cupertino icon for a group of three people. This icon is filled in. + /// This is the same icon as [person_3_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [group], which is similar, but not filled in. + /// * [person_solid], which is just a single person. + static const IconData group_solid = IconData(0xf47c, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// envelope — Cupertino icon for the outline of a closed mail envelope. + /// This is the same icon as [envelope] in cupertino_icons 1.0.0+. + static const IconData mail = IconData(0xf422, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// envelope_fill — Cupertino icon for a closed mail envelope. This icon is filled in. + /// This is the same icon as [envelope_fill] in cupertino_icons 1.0.0+. + static const IconData mail_solid = IconData(0xf423, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// location — Cupertino icon for a location pin. + static const IconData location = IconData(0xf6ee, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// placemark_fill — Cupertino icon for a location pin. This icon is filled in. + /// This is the same icon as [placemark_fill] in cupertino_icons 1.0.0+. + static const IconData location_solid = IconData(0xf456, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// tags — Cupertino icon for the outline of a sticker tag. + /// This is the same icon as [tags] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [tags], similar but with 2 overlapping tags. + static const IconData tag = IconData(0xf48c, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// tag_fill — Cupertino icon for a sticker tag. This icon is filled in. + /// This is the same icon as [tag_fill] and [tags_solid] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [tags_solid], similar but with 2 overlapping tags. + static const IconData tag_solid = IconData(0xf48d, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// tag — Cupertino icon for outlines of 2 overlapping sticker tags. + /// This is the same icon as [tag] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [tag], similar but with only one tag. + static const IconData tags = IconData(0xf48e, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// tag_fill — Cupertino icon for 2 overlapping sticker tags. This icon is filled in. + /// This is the same icon as [tag_fill] and [tag_solid] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [tag_solid], similar but with only one tag. + static const IconData tags_solid = IconData(0xf48f, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// bus — Cupertino icon for a filled in bus. + /// This icon is available in cupertino_icons 1.0.0+ for backward + /// compatibility but not part of Apple icons' aesthetics. + static const IconData bus = IconData(0xf36d, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// car_fill — Cupertino icon for a filled in car. + /// This is the same icon as [car_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [car_detailed], similar, but a more detailed and realistic representation. + static const IconData car = IconData(0xf36f, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// car_detailed — Cupertino icon for a filled in detailed, realistic car. + /// + /// See also: + /// + /// * [car], similar, but a more simple representation. + /// This icon is available in cupertino_icons 1.0.0+ for backward + /// compatibility but not part of Apple icons' aesthetics. + static const IconData car_detailed = IconData(0xf2c1, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// train_style_one — Cupertino icon for a filled in train with a window divided in half and two headlights. + /// This icon is available in cupertino_icons 1.0.0+ for backward + /// compatibility but not part of Apple icons' aesthetics. + /// + /// See also: + /// + /// * [train_style_two], similar, but with a full, undivided window and a single, centered headlight. + static const IconData train_style_one = IconData(0xf3af, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// train_style_two — Cupertino icon for a filled in train with a window and a single, centered headlight. + /// This icon is available in cupertino_icons 1.0.0+ for backward + /// compatibility but not part of Apple icons' aesthetics. + /// + /// See also: + /// + /// * [train_style_one], similar, but with a with a window divided in half and two headlights. + static const IconData train_style_two = IconData(0xf3b4, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// paw — Cupertino icon for an outlined paw. + /// + /// See also: + /// + /// * [paw_solid], similar, but filled in. + static const IconData paw = IconData(0xf479, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// paw — Cupertino icon for a filled in paw. + /// This is the same icon as [paw] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [paw], similar, but not filled in. + static const IconData paw_solid = IconData(0xf47a, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// gamecontroller — Cupertino icon for an outlined game controller. + /// This is the same icon as [gamecontroller] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [game_controller_solid], similar, but filled in. + static const IconData game_controller = IconData(0xf43a, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// gamecontroller_fill — Cupertino icon for a filled in game controller. + /// This is the same icon as [gamecontroller_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [game_controller], similar, but not filled in. + static const IconData game_controller_solid = IconData(0xf43b, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// lab_flask — Cupertino icon for an outlined lab flask. + /// This icon is available in cupertino_icons 1.0.0+ for backward + /// compatibility but not part of Apple icons' aesthetics. + /// + /// See also: + /// + /// * [lab_flask_solid], similar, but filled in. + static const IconData lab_flask = IconData(0xf430, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// lab_flask_solid — Cupertino icon for a filled in lab flask. + /// This icon is available in cupertino_icons 1.0.0+ for backward + /// compatibility but not part of Apple icons' aesthetics. + /// + /// See also: + /// + /// * [lab_flask], similar, but not filled in. + static const IconData lab_flask_solid = IconData(0xf431, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// heart — Cupertino icon for an outlined heart shape. Can be used to indicate like or favorite states. + /// + /// See also: + /// + /// * [heart_solid], same shape, but filled in. + static const IconData heart = IconData(0xf442, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// heart_solid — Cupertino icon for a filled heart shape. Can be used to indicate like or favorite states. + /// This is the same icon as [heart_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [heart], same shape, but not filled in. + static const IconData heart_solid = IconData(0xf443, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// bell — Cupertino icon for an outlined bell. Can be used to represent notifications. + /// + /// See also: + /// + /// * [bell_solid], same shape, but filled in. + static const IconData bell = IconData(0xf3e1, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// bell_fill — Cupertino icon for a filled bell. Can be used represent notifications. + /// This is the same icon as [bell_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [bell], same shape, but not filled in. + static const IconData bell_solid = IconData(0xf3e2, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// news — Cupertino icon for an outlined folded newspaper icon. + /// This icon is available in cupertino_icons 1.0.0+ for backward + /// compatibility but not part of Apple icons' aesthetics. + /// + /// See also: + /// + /// * [news_solid], same shape, but filled in. + static const IconData news = IconData(0xf471, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// news_solid — Cupertino icon for a filled folded newspaper icon. + /// This icon is available in cupertino_icons 1.0.0+ for backward + /// compatibility but not part of Apple icons' aesthetics. + /// + /// See also: + /// + /// * [news], same shape, but not filled in. + static const IconData news_solid = IconData(0xf472, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// sun_max — Cupertino icon for an outlined brightness icon. + /// This is the same icon as [sun_max] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [brightness_solid], same shape, but filled in. + static const IconData brightness = IconData(0xf4B6, fontFamily: iconFont, fontPackage: iconFontPackage); + + /// sun_max_fill — Cupertino icon for a filled in brightness icon. + /// This is the same icon as [sun_max_fill] in cupertino_icons 1.0.0+. + /// + /// See also: + /// + /// * [brightness], same shape, but not filled in. + static const IconData brightness_solid = IconData(0xf4B7, fontFamily: iconFont, fontPackage: iconFontPackage); + // END LEGACY PRE SF SYMBOLS NAMES + // =========================================================================== + + // =========================================================================== + // BEGIN GENERATED SF SYMBOLS NAMES + /// airplane — Cupertino icon named "airplane". Available on cupertino_icons package 1.0.0+ only. + static const IconData airplane = IconData(0xf4d4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// alarm — Cupertino icon named "alarm". Available on cupertino_icons package 1.0.0+ only. + static const IconData alarm = IconData(0xf4d5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// alarm_fill — Cupertino icon named "alarm_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData alarm_fill = IconData(0xf4d6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// alt — Cupertino icon named "alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData alt = IconData(0xf4d7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ant — Cupertino icon named "ant". Available on cupertino_icons package 1.0.0+ only. + static const IconData ant = IconData(0xf4d8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ant_circle — Cupertino icon named "ant_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData ant_circle = IconData(0xf4d9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ant_circle_fill — Cupertino icon named "ant_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData ant_circle_fill = IconData(0xf4da, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ant_fill — Cupertino icon named "ant_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData ant_fill = IconData(0xf4db, fontFamily: iconFont, fontPackage: iconFontPackage); + /// antenna_radiowaves_left_right — Cupertino icon named "antenna_radiowaves_left_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData antenna_radiowaves_left_right = IconData(0xf4dc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// app — Cupertino icon named "app". Available on cupertino_icons package 1.0.0+ only. + static const IconData app = IconData(0xf4dd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// app_badge — Cupertino icon named "app_badge". Available on cupertino_icons package 1.0.0+ only. + static const IconData app_badge = IconData(0xf4de, fontFamily: iconFont, fontPackage: iconFontPackage); + /// app_badge_fill — Cupertino icon named "app_badge_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData app_badge_fill = IconData(0xf4df, fontFamily: iconFont, fontPackage: iconFontPackage); + /// app_fill — Cupertino icon named "app_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData app_fill = IconData(0xf4e0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// archivebox — Cupertino icon named "archivebox". Available on cupertino_icons package 1.0.0+ only. + static const IconData archivebox = IconData(0xf4e1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// archivebox_fill — Cupertino icon named "archivebox_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData archivebox_fill = IconData(0xf4e2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_2_circlepath — Cupertino icon named "arrow_2_circlepath". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_2_circlepath = IconData(0xf4e3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_2_circlepath_circle — Cupertino icon named "arrow_2_circlepath_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_2_circlepath_circle = IconData(0xf4e4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_2_circlepath_circle_fill — Cupertino icon named "arrow_2_circlepath_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_2_circlepath_circle_fill = IconData(0xf4e5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_2_squarepath — Cupertino icon named "arrow_2_squarepath". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_2_squarepath = IconData(0xf4e6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_3_trianglepath — Cupertino icon named "arrow_3_trianglepath". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_3_trianglepath = IconData(0xf4e7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_branch — Cupertino icon named "arrow_branch". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_branch = IconData(0xf4e8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_clockwise — Cupertino icon named "arrow_clockwise". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [refresh] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [refresh_thin] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [refresh_thick] which is available in cupertino_icons 0.1.3. + static const IconData arrow_clockwise = IconData(0xf49a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_clockwise_circle — Cupertino icon named "arrow_clockwise_circle". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [refresh_circled] which is available in cupertino_icons 0.1.3. + static const IconData arrow_clockwise_circle = IconData(0xf49b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_clockwise_circle_fill — Cupertino icon named "arrow_clockwise_circle_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [refresh_circled_solid] which is available in cupertino_icons 0.1.3. + static const IconData arrow_clockwise_circle_fill = IconData(0xf49c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_counterclockwise — Cupertino icon named "arrow_counterclockwise". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [restart] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [refresh_bold] which is available in cupertino_icons 0.1.3. + static const IconData arrow_counterclockwise = IconData(0xf21c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_counterclockwise_circle — Cupertino icon named "arrow_counterclockwise_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_counterclockwise_circle = IconData(0xf4e9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_counterclockwise_circle_fill — Cupertino icon named "arrow_counterclockwise_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_counterclockwise_circle_fill = IconData(0xf4ea, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down — Cupertino icon named "arrow_down". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [down_arrow] which is available in cupertino_icons 0.1.3. + static const IconData arrow_down = IconData(0xf35d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_circle — Cupertino icon named "arrow_down_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_circle = IconData(0xf4eb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_circle_fill — Cupertino icon named "arrow_down_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_circle_fill = IconData(0xf4ec, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_doc — Cupertino icon named "arrow_down_doc". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_doc = IconData(0xf4ed, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_doc_fill — Cupertino icon named "arrow_down_doc_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_doc_fill = IconData(0xf4ee, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_left — Cupertino icon named "arrow_down_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_left = IconData(0xf4ef, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_left_circle — Cupertino icon named "arrow_down_left_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_left_circle = IconData(0xf4f0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_left_circle_fill — Cupertino icon named "arrow_down_left_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_left_circle_fill = IconData(0xf4f1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_left_square — Cupertino icon named "arrow_down_left_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_left_square = IconData(0xf4f2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_left_square_fill — Cupertino icon named "arrow_down_left_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_left_square_fill = IconData(0xf4f3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_right — Cupertino icon named "arrow_down_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_right = IconData(0xf4f4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_right_arrow_up_left — Cupertino icon named "arrow_down_right_arrow_up_left". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [fullscreen_exit] which is available in cupertino_icons 0.1.3. + static const IconData arrow_down_right_arrow_up_left = IconData(0xf37d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_right_circle — Cupertino icon named "arrow_down_right_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_right_circle = IconData(0xf4f5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_right_circle_fill — Cupertino icon named "arrow_down_right_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_right_circle_fill = IconData(0xf4f6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_right_square — Cupertino icon named "arrow_down_right_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_right_square = IconData(0xf4f7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_right_square_fill — Cupertino icon named "arrow_down_right_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_right_square_fill = IconData(0xf4f8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_square — Cupertino icon named "arrow_down_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_square = IconData(0xf4f9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_square_fill — Cupertino icon named "arrow_down_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_square_fill = IconData(0xf4fa, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_to_line — Cupertino icon named "arrow_down_to_line". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_to_line = IconData(0xf4fb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_down_to_line_alt — Cupertino icon named "arrow_down_to_line_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_down_to_line_alt = IconData(0xf4fc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left — Cupertino icon named "arrow_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left = IconData(0xf4fd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_circle — Cupertino icon named "arrow_left_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_circle = IconData(0xf4fe, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_circle_fill — Cupertino icon named "arrow_left_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_circle_fill = IconData(0xf4ff, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_right — Cupertino icon named "arrow_left_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_right = IconData(0xf500, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_right_circle — Cupertino icon named "arrow_left_right_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_right_circle = IconData(0xf501, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_right_circle_fill — Cupertino icon named "arrow_left_right_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_right_circle_fill = IconData(0xf502, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_right_square — Cupertino icon named "arrow_left_right_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_right_square = IconData(0xf503, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_right_square_fill — Cupertino icon named "arrow_left_right_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_right_square_fill = IconData(0xf504, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_square — Cupertino icon named "arrow_left_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_square = IconData(0xf505, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_square_fill — Cupertino icon named "arrow_left_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_square_fill = IconData(0xf506, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_to_line — Cupertino icon named "arrow_left_to_line". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_to_line = IconData(0xf507, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_left_to_line_alt — Cupertino icon named "arrow_left_to_line_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_left_to_line_alt = IconData(0xf508, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_merge — Cupertino icon named "arrow_merge". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_merge = IconData(0xf509, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right — Cupertino icon named "arrow_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right = IconData(0xf50a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_arrow_left — Cupertino icon named "arrow_right_arrow_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_arrow_left = IconData(0xf50b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_arrow_left_circle — Cupertino icon named "arrow_right_arrow_left_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_arrow_left_circle = IconData(0xf50c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_arrow_left_circle_fill — Cupertino icon named "arrow_right_arrow_left_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_arrow_left_circle_fill = IconData(0xf50d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_arrow_left_square — Cupertino icon named "arrow_right_arrow_left_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_arrow_left_square = IconData(0xf50e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_arrow_left_square_fill — Cupertino icon named "arrow_right_arrow_left_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_arrow_left_square_fill = IconData(0xf50f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_circle — Cupertino icon named "arrow_right_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_circle = IconData(0xf510, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_circle_fill — Cupertino icon named "arrow_right_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_circle_fill = IconData(0xf511, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_square — Cupertino icon named "arrow_right_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_square = IconData(0xf512, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_square_fill — Cupertino icon named "arrow_right_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_square_fill = IconData(0xf513, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_to_line — Cupertino icon named "arrow_right_to_line". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_to_line = IconData(0xf514, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_right_to_line_alt — Cupertino icon named "arrow_right_to_line_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_right_to_line_alt = IconData(0xf515, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_swap — Cupertino icon named "arrow_swap". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_swap = IconData(0xf516, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_turn_down_left — Cupertino icon named "arrow_turn_down_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_turn_down_left = IconData(0xf517, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_turn_down_right — Cupertino icon named "arrow_turn_down_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_turn_down_right = IconData(0xf518, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_turn_left_down — Cupertino icon named "arrow_turn_left_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_turn_left_down = IconData(0xf519, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_turn_left_up — Cupertino icon named "arrow_turn_left_up". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_turn_left_up = IconData(0xf51a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_turn_right_down — Cupertino icon named "arrow_turn_right_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_turn_right_down = IconData(0xf51b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_turn_right_up — Cupertino icon named "arrow_turn_right_up". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_turn_right_up = IconData(0xf51c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_turn_up_left — Cupertino icon named "arrow_turn_up_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_turn_up_left = IconData(0xf51d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_turn_up_right — Cupertino icon named "arrow_turn_up_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_turn_up_right = IconData(0xf51e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up — Cupertino icon named "arrow_up". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [up_arrow] which is available in cupertino_icons 0.1.3. + static const IconData arrow_up = IconData(0xf366, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_arrow_down — Cupertino icon named "arrow_up_arrow_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_arrow_down = IconData(0xf51f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_arrow_down_circle — Cupertino icon named "arrow_up_arrow_down_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_arrow_down_circle = IconData(0xf520, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_arrow_down_circle_fill — Cupertino icon named "arrow_up_arrow_down_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_arrow_down_circle_fill = IconData(0xf521, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_arrow_down_square — Cupertino icon named "arrow_up_arrow_down_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_arrow_down_square = IconData(0xf522, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_arrow_down_square_fill — Cupertino icon named "arrow_up_arrow_down_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_arrow_down_square_fill = IconData(0xf523, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_bin — Cupertino icon named "arrow_up_bin". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_bin = IconData(0xf524, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_bin_fill — Cupertino icon named "arrow_up_bin_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_bin_fill = IconData(0xf525, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_circle — Cupertino icon named "arrow_up_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_circle = IconData(0xf526, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_circle_fill — Cupertino icon named "arrow_up_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_circle_fill = IconData(0xf527, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_doc — Cupertino icon named "arrow_up_doc". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_doc = IconData(0xf528, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_doc_fill — Cupertino icon named "arrow_up_doc_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_doc_fill = IconData(0xf529, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_down — Cupertino icon named "arrow_up_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_down = IconData(0xf52a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_down_circle — Cupertino icon named "arrow_up_down_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_down_circle = IconData(0xf52b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_down_circle_fill — Cupertino icon named "arrow_up_down_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_down_circle_fill = IconData(0xf52c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_down_square — Cupertino icon named "arrow_up_down_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_down_square = IconData(0xf52d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_down_square_fill — Cupertino icon named "arrow_up_down_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_down_square_fill = IconData(0xf52e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_left — Cupertino icon named "arrow_up_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_left = IconData(0xf52f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_left_arrow_down_right — Cupertino icon named "arrow_up_left_arrow_down_right". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [fullscreen] which is available in cupertino_icons 0.1.3. + static const IconData arrow_up_left_arrow_down_right = IconData(0xf386, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_left_circle — Cupertino icon named "arrow_up_left_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_left_circle = IconData(0xf530, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_left_circle_fill — Cupertino icon named "arrow_up_left_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_left_circle_fill = IconData(0xf531, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_left_square — Cupertino icon named "arrow_up_left_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_left_square = IconData(0xf532, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_left_square_fill — Cupertino icon named "arrow_up_left_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_left_square_fill = IconData(0xf533, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_right — Cupertino icon named "arrow_up_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_right = IconData(0xf534, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_right_circle — Cupertino icon named "arrow_up_right_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_right_circle = IconData(0xf535, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_right_circle_fill — Cupertino icon named "arrow_up_right_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_right_circle_fill = IconData(0xf536, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_right_diamond — Cupertino icon named "arrow_up_right_diamond". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_right_diamond = IconData(0xf537, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_right_diamond_fill — Cupertino icon named "arrow_up_right_diamond_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_right_diamond_fill = IconData(0xf538, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_right_square — Cupertino icon named "arrow_up_right_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_right_square = IconData(0xf539, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_right_square_fill — Cupertino icon named "arrow_up_right_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_right_square_fill = IconData(0xf53a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_square — Cupertino icon named "arrow_up_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_square = IconData(0xf53b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_square_fill — Cupertino icon named "arrow_up_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_square_fill = IconData(0xf53c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_to_line — Cupertino icon named "arrow_up_to_line". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_to_line = IconData(0xf53d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_up_to_line_alt — Cupertino icon named "arrow_up_to_line_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_up_to_line_alt = IconData(0xf53e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_down — Cupertino icon named "arrow_uturn_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_down = IconData(0xf53f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_down_circle — Cupertino icon named "arrow_uturn_down_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_down_circle = IconData(0xf540, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_down_circle_fill — Cupertino icon named "arrow_uturn_down_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_down_circle_fill = IconData(0xf541, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_down_square — Cupertino icon named "arrow_uturn_down_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_down_square = IconData(0xf542, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_down_square_fill — Cupertino icon named "arrow_uturn_down_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_down_square_fill = IconData(0xf543, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_left — Cupertino icon named "arrow_uturn_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_left = IconData(0xf544, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_left_circle — Cupertino icon named "arrow_uturn_left_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_left_circle = IconData(0xf545, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_left_circle_fill — Cupertino icon named "arrow_uturn_left_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_left_circle_fill = IconData(0xf546, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_left_square — Cupertino icon named "arrow_uturn_left_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_left_square = IconData(0xf547, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_left_square_fill — Cupertino icon named "arrow_uturn_left_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_left_square_fill = IconData(0xf548, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_right — Cupertino icon named "arrow_uturn_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_right = IconData(0xf549, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_right_circle — Cupertino icon named "arrow_uturn_right_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_right_circle = IconData(0xf54a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_right_circle_fill — Cupertino icon named "arrow_uturn_right_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_right_circle_fill = IconData(0xf54b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_right_square — Cupertino icon named "arrow_uturn_right_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_right_square = IconData(0xf54c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_right_square_fill — Cupertino icon named "arrow_uturn_right_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_right_square_fill = IconData(0xf54d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_up — Cupertino icon named "arrow_uturn_up". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_up = IconData(0xf54e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_up_circle — Cupertino icon named "arrow_uturn_up_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_up_circle = IconData(0xf54f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_up_circle_fill — Cupertino icon named "arrow_uturn_up_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_up_circle_fill = IconData(0xf550, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_up_square — Cupertino icon named "arrow_uturn_up_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_up_square = IconData(0xf551, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrow_uturn_up_square_fill — Cupertino icon named "arrow_uturn_up_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrow_uturn_up_square_fill = IconData(0xf552, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowshape_turn_up_left — Cupertino icon named "arrowshape_turn_up_left". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [reply] which is available in cupertino_icons 0.1.3. + static const IconData arrowshape_turn_up_left = IconData(0xf4c6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowshape_turn_up_left_2 — Cupertino icon named "arrowshape_turn_up_left_2". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [reply_all] which is available in cupertino_icons 0.1.3. + static const IconData arrowshape_turn_up_left_2 = IconData(0xf21d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowshape_turn_up_left_2_fill — Cupertino icon named "arrowshape_turn_up_left_2_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [reply_thick_solid] which is available in cupertino_icons 0.1.3. + static const IconData arrowshape_turn_up_left_2_fill = IconData(0xf21e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowshape_turn_up_left_circle — Cupertino icon named "arrowshape_turn_up_left_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowshape_turn_up_left_circle = IconData(0xf553, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowshape_turn_up_left_circle_fill — Cupertino icon named "arrowshape_turn_up_left_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowshape_turn_up_left_circle_fill = IconData(0xf554, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowshape_turn_up_left_fill — Cupertino icon named "arrowshape_turn_up_left_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowshape_turn_up_left_fill = IconData(0xf555, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowshape_turn_up_right — Cupertino icon named "arrowshape_turn_up_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowshape_turn_up_right = IconData(0xf556, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowshape_turn_up_right_circle — Cupertino icon named "arrowshape_turn_up_right_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowshape_turn_up_right_circle = IconData(0xf557, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowshape_turn_up_right_circle_fill — Cupertino icon named "arrowshape_turn_up_right_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowshape_turn_up_right_circle_fill = IconData(0xf558, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowshape_turn_up_right_fill — Cupertino icon named "arrowshape_turn_up_right_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowshape_turn_up_right_fill = IconData(0xf559, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_down — Cupertino icon named "arrowtriangle_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_down = IconData(0xf55a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_down_circle — Cupertino icon named "arrowtriangle_down_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_down_circle = IconData(0xf55b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_down_circle_fill — Cupertino icon named "arrowtriangle_down_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_down_circle_fill = IconData(0xf55c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_down_fill — Cupertino icon named "arrowtriangle_down_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_down_fill = IconData(0xf55d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_down_square — Cupertino icon named "arrowtriangle_down_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_down_square = IconData(0xf55e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_down_square_fill — Cupertino icon named "arrowtriangle_down_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_down_square_fill = IconData(0xf55f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_left — Cupertino icon named "arrowtriangle_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_left = IconData(0xf560, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_left_circle — Cupertino icon named "arrowtriangle_left_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_left_circle = IconData(0xf561, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_left_circle_fill — Cupertino icon named "arrowtriangle_left_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_left_circle_fill = IconData(0xf562, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_left_fill — Cupertino icon named "arrowtriangle_left_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_left_fill = IconData(0xf563, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_left_square — Cupertino icon named "arrowtriangle_left_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_left_square = IconData(0xf564, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_left_square_fill — Cupertino icon named "arrowtriangle_left_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_left_square_fill = IconData(0xf565, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_right — Cupertino icon named "arrowtriangle_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_right = IconData(0xf566, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_right_circle — Cupertino icon named "arrowtriangle_right_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_right_circle = IconData(0xf567, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_right_circle_fill — Cupertino icon named "arrowtriangle_right_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_right_circle_fill = IconData(0xf568, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_right_fill — Cupertino icon named "arrowtriangle_right_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_right_fill = IconData(0xf569, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_right_square — Cupertino icon named "arrowtriangle_right_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_right_square = IconData(0xf56a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_right_square_fill — Cupertino icon named "arrowtriangle_right_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_right_square_fill = IconData(0xf56b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_up — Cupertino icon named "arrowtriangle_up". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_up = IconData(0xf56c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_up_circle — Cupertino icon named "arrowtriangle_up_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_up_circle = IconData(0xf56d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_up_circle_fill — Cupertino icon named "arrowtriangle_up_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_up_circle_fill = IconData(0xf56e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_up_fill — Cupertino icon named "arrowtriangle_up_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_up_fill = IconData(0xf56f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_up_square — Cupertino icon named "arrowtriangle_up_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_up_square = IconData(0xf570, fontFamily: iconFont, fontPackage: iconFontPackage); + /// arrowtriangle_up_square_fill — Cupertino icon named "arrowtriangle_up_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData arrowtriangle_up_square_fill = IconData(0xf571, fontFamily: iconFont, fontPackage: iconFontPackage); + /// asterisk_circle — Cupertino icon named "asterisk_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData asterisk_circle = IconData(0xf572, fontFamily: iconFont, fontPackage: iconFontPackage); + /// asterisk_circle_fill — Cupertino icon named "asterisk_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData asterisk_circle_fill = IconData(0xf573, fontFamily: iconFont, fontPackage: iconFontPackage); + /// at — Cupertino icon named "at". Available on cupertino_icons package 1.0.0+ only. + static const IconData at = IconData(0xf574, fontFamily: iconFont, fontPackage: iconFontPackage); + /// at_badge_minus — Cupertino icon named "at_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData at_badge_minus = IconData(0xf575, fontFamily: iconFont, fontPackage: iconFontPackage); + /// at_badge_plus — Cupertino icon named "at_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData at_badge_plus = IconData(0xf576, fontFamily: iconFont, fontPackage: iconFontPackage); + /// at_circle — Cupertino icon named "at_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData at_circle = IconData(0xf8af, fontFamily: iconFont, fontPackage: iconFontPackage); + /// at_circle_fill — Cupertino icon named "at_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData at_circle_fill = IconData(0xf8b0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// backward — Cupertino icon named "backward". Available on cupertino_icons package 1.0.0+ only. + static const IconData backward = IconData(0xf577, fontFamily: iconFont, fontPackage: iconFontPackage); + /// backward_end — Cupertino icon named "backward_end". Available on cupertino_icons package 1.0.0+ only. + static const IconData backward_end = IconData(0xf578, fontFamily: iconFont, fontPackage: iconFontPackage); + /// backward_end_alt — Cupertino icon named "backward_end_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData backward_end_alt = IconData(0xf579, fontFamily: iconFont, fontPackage: iconFontPackage); + /// backward_end_alt_fill — Cupertino icon named "backward_end_alt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData backward_end_alt_fill = IconData(0xf57a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// backward_end_fill — Cupertino icon named "backward_end_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData backward_end_fill = IconData(0xf57b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// backward_fill — Cupertino icon named "backward_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData backward_fill = IconData(0xf57c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// badge_plus_radiowaves_right — Cupertino icon named "badge_plus_radiowaves_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData badge_plus_radiowaves_right = IconData(0xf57d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bag — Cupertino icon named "bag". Available on cupertino_icons package 1.0.0+ only. + static const IconData bag = IconData(0xf57e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bag_badge_minus — Cupertino icon named "bag_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData bag_badge_minus = IconData(0xf57f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bag_badge_plus — Cupertino icon named "bag_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData bag_badge_plus = IconData(0xf580, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bag_fill — Cupertino icon named "bag_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bag_fill = IconData(0xf581, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bag_fill_badge_minus — Cupertino icon named "bag_fill_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData bag_fill_badge_minus = IconData(0xf582, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bag_fill_badge_plus — Cupertino icon named "bag_fill_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData bag_fill_badge_plus = IconData(0xf583, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bandage — Cupertino icon named "bandage". Available on cupertino_icons package 1.0.0+ only. + static const IconData bandage = IconData(0xf584, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bandage_fill — Cupertino icon named "bandage_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bandage_fill = IconData(0xf585, fontFamily: iconFont, fontPackage: iconFontPackage); + /// barcode — Cupertino icon named "barcode". Available on cupertino_icons package 1.0.0+ only. + static const IconData barcode = IconData(0xf586, fontFamily: iconFont, fontPackage: iconFontPackage); + /// barcode_viewfinder — Cupertino icon named "barcode_viewfinder". Available on cupertino_icons package 1.0.0+ only. + static const IconData barcode_viewfinder = IconData(0xf587, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bars — Cupertino icon named "bars". Available on cupertino_icons package 1.0.0+ only. + static const IconData bars = IconData(0xf8b1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// battery_0 — Cupertino icon named "battery_0". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [battery_empty] which is available in cupertino_icons 0.1.3. + static const IconData battery_0 = IconData(0xf112, fontFamily: iconFont, fontPackage: iconFontPackage); + /// battery_100 — Cupertino icon named "battery_100". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [battery_charging] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [battery_full] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [battery_75_percent] which is available in cupertino_icons 0.1.3. + static const IconData battery_100 = IconData(0xf113, fontFamily: iconFont, fontPackage: iconFontPackage); + /// battery_25 — Cupertino icon named "battery_25". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [battery_25_percent] which is available in cupertino_icons 0.1.3. + static const IconData battery_25 = IconData(0xf115, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bed_double — Cupertino icon named "bed_double". Available on cupertino_icons package 1.0.0+ only. + static const IconData bed_double = IconData(0xf588, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bed_double_fill — Cupertino icon named "bed_double_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bed_double_fill = IconData(0xf589, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bell_circle — Cupertino icon named "bell_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData bell_circle = IconData(0xf58a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bell_circle_fill — Cupertino icon named "bell_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bell_circle_fill = IconData(0xf58b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bell_fill — Cupertino icon named "bell_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [bell_solid] which is available in cupertino_icons 0.1.3. + static const IconData bell_fill = IconData(0xf3e2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bell_slash — Cupertino icon named "bell_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData bell_slash = IconData(0xf58c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bell_slash_fill — Cupertino icon named "bell_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bell_slash_fill = IconData(0xf58d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bin_xmark — Cupertino icon named "bin_xmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData bin_xmark = IconData(0xf58e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bin_xmark_fill — Cupertino icon named "bin_xmark_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bin_xmark_fill = IconData(0xf58f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bitcoin — Cupertino icon named "bitcoin". Available on cupertino_icons package 1.0.0+ only. + static const IconData bitcoin = IconData(0xf8b2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bitcoin_circle — Cupertino icon named "bitcoin_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData bitcoin_circle = IconData(0xf8b3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bitcoin_circle_fill — Cupertino icon named "bitcoin_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bitcoin_circle_fill = IconData(0xf8b4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bold — Cupertino icon named "bold". Available on cupertino_icons package 1.0.0+ only. + static const IconData bold = IconData(0xf590, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bold_italic_underline — Cupertino icon named "bold_italic_underline". Available on cupertino_icons package 1.0.0+ only. + static const IconData bold_italic_underline = IconData(0xf591, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bold_underline — Cupertino icon named "bold_underline". Available on cupertino_icons package 1.0.0+ only. + static const IconData bold_underline = IconData(0xf592, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt — Cupertino icon named "bolt". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt = IconData(0xf593, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_badge_a — Cupertino icon named "bolt_badge_a". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_badge_a = IconData(0xf594, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_badge_a_fill — Cupertino icon named "bolt_badge_a_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_badge_a_fill = IconData(0xf595, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_circle — Cupertino icon named "bolt_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_circle = IconData(0xf596, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_circle_fill — Cupertino icon named "bolt_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_circle_fill = IconData(0xf597, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_fill — Cupertino icon named "bolt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_fill = IconData(0xf598, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_horizontal — Cupertino icon named "bolt_horizontal". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_horizontal = IconData(0xf599, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_horizontal_circle — Cupertino icon named "bolt_horizontal_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_horizontal_circle = IconData(0xf59a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_horizontal_circle_fill — Cupertino icon named "bolt_horizontal_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_horizontal_circle_fill = IconData(0xf59b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_horizontal_fill — Cupertino icon named "bolt_horizontal_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_horizontal_fill = IconData(0xf59c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_slash — Cupertino icon named "bolt_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_slash = IconData(0xf59d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bolt_slash_fill — Cupertino icon named "bolt_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bolt_slash_fill = IconData(0xf59e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// book_circle — Cupertino icon named "book_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData book_circle = IconData(0xf59f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// book_circle_fill — Cupertino icon named "book_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData book_circle_fill = IconData(0xf5a0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// book_fill — Cupertino icon named "book_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [book_solid] which is available in cupertino_icons 0.1.3. + static const IconData book_fill = IconData(0xf3e8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bookmark_fill — Cupertino icon named "bookmark_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [bookmark_solid] which is available in cupertino_icons 0.1.3. + static const IconData bookmark_fill = IconData(0xf3ea, fontFamily: iconFont, fontPackage: iconFontPackage); + /// briefcase — Cupertino icon named "briefcase". Available on cupertino_icons package 1.0.0+ only. + static const IconData briefcase = IconData(0xf5a1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// briefcase_fill — Cupertino icon named "briefcase_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData briefcase_fill = IconData(0xf5a2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bubble_left — Cupertino icon named "bubble_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData bubble_left = IconData(0xf5a3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bubble_left_bubble_right — Cupertino icon named "bubble_left_bubble_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData bubble_left_bubble_right = IconData(0xf5a4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bubble_left_bubble_right_fill — Cupertino icon named "bubble_left_bubble_right_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bubble_left_bubble_right_fill = IconData(0xf5a5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bubble_left_fill — Cupertino icon named "bubble_left_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bubble_left_fill = IconData(0xf5a6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bubble_middle_bottom — Cupertino icon named "bubble_middle_bottom". Available on cupertino_icons package 1.0.0+ only. + static const IconData bubble_middle_bottom = IconData(0xf5a7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bubble_middle_bottom_fill — Cupertino icon named "bubble_middle_bottom_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bubble_middle_bottom_fill = IconData(0xf5a8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bubble_middle_top — Cupertino icon named "bubble_middle_top". Available on cupertino_icons package 1.0.0+ only. + static const IconData bubble_middle_top = IconData(0xf5a9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bubble_middle_top_fill — Cupertino icon named "bubble_middle_top_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bubble_middle_top_fill = IconData(0xf5aa, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bubble_right — Cupertino icon named "bubble_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData bubble_right = IconData(0xf5ab, fontFamily: iconFont, fontPackage: iconFontPackage); + /// bubble_right_fill — Cupertino icon named "bubble_right_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData bubble_right_fill = IconData(0xf5ac, fontFamily: iconFont, fontPackage: iconFontPackage); + /// building_2_fill — Cupertino icon named "building_2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData building_2_fill = IconData(0xf8b5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// burn — Cupertino icon named "burn". Available on cupertino_icons package 1.0.0+ only. + static const IconData burn = IconData(0xf5ad, fontFamily: iconFont, fontPackage: iconFontPackage); + /// burst — Cupertino icon named "burst". Available on cupertino_icons package 1.0.0+ only. + static const IconData burst = IconData(0xf5ae, fontFamily: iconFont, fontPackage: iconFontPackage); + /// burst_fill — Cupertino icon named "burst_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData burst_fill = IconData(0xf5af, fontFamily: iconFont, fontPackage: iconFontPackage); + /// calendar — Cupertino icon named "calendar". Available on cupertino_icons package 1.0.0+ only. + static const IconData calendar = IconData(0xf5b0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// calendar_badge_minus — Cupertino icon named "calendar_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData calendar_badge_minus = IconData(0xf5b1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// calendar_badge_plus — Cupertino icon named "calendar_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData calendar_badge_plus = IconData(0xf5b2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// calendar_circle — Cupertino icon named "calendar_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData calendar_circle = IconData(0xf5b3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// calendar_circle_fill — Cupertino icon named "calendar_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData calendar_circle_fill = IconData(0xf5b4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// calendar_today — Cupertino icon named "calendar_today". Available on cupertino_icons package 1.0.0+ only. + static const IconData calendar_today = IconData(0xf8b6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// camera — Cupertino icon named "camera". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [photo_camera] which is available in cupertino_icons 0.1.3. + static const IconData camera = IconData(0xf3f5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// camera_circle — Cupertino icon named "camera_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData camera_circle = IconData(0xf5b5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// camera_circle_fill — Cupertino icon named "camera_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData camera_circle_fill = IconData(0xf5b6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// camera_fill — Cupertino icon named "camera_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [photo_camera_solid] which is available in cupertino_icons 0.1.3. + static const IconData camera_fill = IconData(0xf3f6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// camera_on_rectangle — Cupertino icon named "camera_on_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData camera_on_rectangle = IconData(0xf5b7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// camera_on_rectangle_fill — Cupertino icon named "camera_on_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData camera_on_rectangle_fill = IconData(0xf5b8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// camera_rotate — Cupertino icon named "camera_rotate". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [switch_camera] which is available in cupertino_icons 0.1.3. + static const IconData camera_rotate = IconData(0xf49e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// camera_rotate_fill — Cupertino icon named "camera_rotate_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [switch_camera_solid] which is available in cupertino_icons 0.1.3. + static const IconData camera_rotate_fill = IconData(0xf49f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// camera_viewfinder — Cupertino icon named "camera_viewfinder". Available on cupertino_icons package 1.0.0+ only. + static const IconData camera_viewfinder = IconData(0xf5b9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// capslock — Cupertino icon named "capslock". Available on cupertino_icons package 1.0.0+ only. + static const IconData capslock = IconData(0xf5ba, fontFamily: iconFont, fontPackage: iconFontPackage); + /// capslock_fill — Cupertino icon named "capslock_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData capslock_fill = IconData(0xf5bb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// capsule — Cupertino icon named "capsule". Available on cupertino_icons package 1.0.0+ only. + static const IconData capsule = IconData(0xf5bc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// capsule_fill — Cupertino icon named "capsule_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData capsule_fill = IconData(0xf5bd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// captions_bubble — Cupertino icon named "captions_bubble". Available on cupertino_icons package 1.0.0+ only. + static const IconData captions_bubble = IconData(0xf5be, fontFamily: iconFont, fontPackage: iconFontPackage); + /// captions_bubble_fill — Cupertino icon named "captions_bubble_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData captions_bubble_fill = IconData(0xf5bf, fontFamily: iconFont, fontPackage: iconFontPackage); + /// car_fill — Cupertino icon named "car_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [car] which is available in cupertino_icons 0.1.3. + static const IconData car_fill = IconData(0xf36f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cart — Cupertino icon named "cart". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [shopping_cart] which is available in cupertino_icons 0.1.3. + static const IconData cart = IconData(0xf3f7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cart_badge_minus — Cupertino icon named "cart_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData cart_badge_minus = IconData(0xf5c0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cart_badge_plus — Cupertino icon named "cart_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData cart_badge_plus = IconData(0xf5c1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cart_fill — Cupertino icon named "cart_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cart_fill = IconData(0xf5c2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cart_fill_badge_minus — Cupertino icon named "cart_fill_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData cart_fill_badge_minus = IconData(0xf5c3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cart_fill_badge_plus — Cupertino icon named "cart_fill_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData cart_fill_badge_plus = IconData(0xf5c4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chart_bar — Cupertino icon named "chart_bar". Available on cupertino_icons package 1.0.0+ only. + static const IconData chart_bar = IconData(0xf5c5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chart_bar_alt_fill — Cupertino icon named "chart_bar_alt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chart_bar_alt_fill = IconData(0xf8b7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chart_bar_circle — Cupertino icon named "chart_bar_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData chart_bar_circle = IconData(0xf8b8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chart_bar_circle_fill — Cupertino icon named "chart_bar_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chart_bar_circle_fill = IconData(0xf8b9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chart_bar_fill — Cupertino icon named "chart_bar_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chart_bar_fill = IconData(0xf5c6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chart_bar_square — Cupertino icon named "chart_bar_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData chart_bar_square = IconData(0xf8ba, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chart_bar_square_fill — Cupertino icon named "chart_bar_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chart_bar_square_fill = IconData(0xf8bb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chart_pie — Cupertino icon named "chart_pie". Available on cupertino_icons package 1.0.0+ only. + static const IconData chart_pie = IconData(0xf5c7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chart_pie_fill — Cupertino icon named "chart_pie_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chart_pie_fill = IconData(0xf5c8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chat_bubble — Cupertino icon named "chat_bubble". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [conversation_bubble] which is available in cupertino_icons 0.1.3. + static const IconData chat_bubble = IconData(0xf3fb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chat_bubble_2 — Cupertino icon named "chat_bubble_2". Available on cupertino_icons package 1.0.0+ only. + static const IconData chat_bubble_2 = IconData(0xf8bc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chat_bubble_2_fill — Cupertino icon named "chat_bubble_2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chat_bubble_2_fill = IconData(0xf8bd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chat_bubble_fill — Cupertino icon named "chat_bubble_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chat_bubble_fill = IconData(0xf8be, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chat_bubble_text — Cupertino icon named "chat_bubble_text". Available on cupertino_icons package 1.0.0+ only. + static const IconData chat_bubble_text = IconData(0xf8bf, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chat_bubble_text_fill — Cupertino icon named "chat_bubble_text_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chat_bubble_text_fill = IconData(0xf8c0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark — Cupertino icon named "checkmark". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [check_mark] which is available in cupertino_icons 0.1.3. + static const IconData checkmark = IconData(0xf3fd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_alt — Cupertino icon named "checkmark_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_alt = IconData(0xf8c1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_alt_circle — Cupertino icon named "checkmark_alt_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_alt_circle = IconData(0xf8c2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_alt_circle_fill — Cupertino icon named "checkmark_alt_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_alt_circle_fill = IconData(0xf8c3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_circle — Cupertino icon named "checkmark_circle". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [check_mark_circled] which is available in cupertino_icons 0.1.3. + static const IconData checkmark_circle = IconData(0xf3fe, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_circle_fill — Cupertino icon named "checkmark_circle_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [check_mark_circled_solid] which is available in cupertino_icons 0.1.3. + static const IconData checkmark_circle_fill = IconData(0xf3ff, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_rectangle — Cupertino icon named "checkmark_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_rectangle = IconData(0xf5c9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_rectangle_fill — Cupertino icon named "checkmark_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_rectangle_fill = IconData(0xf5ca, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_seal — Cupertino icon named "checkmark_seal". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_seal = IconData(0xf5cb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_seal_fill — Cupertino icon named "checkmark_seal_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_seal_fill = IconData(0xf5cc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_shield — Cupertino icon named "checkmark_shield". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_shield = IconData(0xf5cd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_shield_fill — Cupertino icon named "checkmark_shield_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_shield_fill = IconData(0xf5ce, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_square — Cupertino icon named "checkmark_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_square = IconData(0xf5cf, fontFamily: iconFont, fontPackage: iconFontPackage); + /// checkmark_square_fill — Cupertino icon named "checkmark_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData checkmark_square_fill = IconData(0xf5d0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_back — Cupertino icon named "chevron_back". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [back] which is available in cupertino_icons 0.1.3. + static const IconData chevron_back = IconData(0xf3cf, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_compact_down — Cupertino icon named "chevron_compact_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_compact_down = IconData(0xf5d1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_compact_left — Cupertino icon named "chevron_compact_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_compact_left = IconData(0xf5d2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_compact_right — Cupertino icon named "chevron_compact_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_compact_right = IconData(0xf5d3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_compact_up — Cupertino icon named "chevron_compact_up". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_compact_up = IconData(0xf5d4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_down — Cupertino icon named "chevron_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_down = IconData(0xf5d5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_down_circle — Cupertino icon named "chevron_down_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_down_circle = IconData(0xf5d6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_down_circle_fill — Cupertino icon named "chevron_down_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_down_circle_fill = IconData(0xf5d7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_down_square — Cupertino icon named "chevron_down_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_down_square = IconData(0xf5d8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_down_square_fill — Cupertino icon named "chevron_down_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_down_square_fill = IconData(0xf5d9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_forward — Cupertino icon named "chevron_forward". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [forward] which is available in cupertino_icons 0.1.3. + static const IconData chevron_forward = IconData(0xf3d1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_left — Cupertino icon named "chevron_left". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [left_chevron] which is available in cupertino_icons 0.1.3. + static const IconData chevron_left = IconData(0xf3d2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_left_2 — Cupertino icon named "chevron_left_2". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_left_2 = IconData(0xf5da, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_left_circle — Cupertino icon named "chevron_left_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_left_circle = IconData(0xf5db, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_left_circle_fill — Cupertino icon named "chevron_left_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_left_circle_fill = IconData(0xf5dc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_left_slash_chevron_right — Cupertino icon named "chevron_left_slash_chevron_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_left_slash_chevron_right = IconData(0xf5dd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_left_square — Cupertino icon named "chevron_left_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_left_square = IconData(0xf5de, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_left_square_fill — Cupertino icon named "chevron_left_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_left_square_fill = IconData(0xf5df, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_right — Cupertino icon named "chevron_right". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [right_chevron] which is available in cupertino_icons 0.1.3. + static const IconData chevron_right = IconData(0xf3d3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_right_2 — Cupertino icon named "chevron_right_2". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_right_2 = IconData(0xf5e0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_right_circle — Cupertino icon named "chevron_right_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_right_circle = IconData(0xf5e1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_right_circle_fill — Cupertino icon named "chevron_right_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_right_circle_fill = IconData(0xf5e2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_right_square — Cupertino icon named "chevron_right_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_right_square = IconData(0xf5e3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_right_square_fill — Cupertino icon named "chevron_right_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_right_square_fill = IconData(0xf5e4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_up — Cupertino icon named "chevron_up". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_up = IconData(0xf5e5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_up_chevron_down — Cupertino icon named "chevron_up_chevron_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_up_chevron_down = IconData(0xf5e6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_up_circle — Cupertino icon named "chevron_up_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_up_circle = IconData(0xf5e7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_up_circle_fill — Cupertino icon named "chevron_up_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_up_circle_fill = IconData(0xf5e8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_up_square — Cupertino icon named "chevron_up_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_up_square = IconData(0xf5e9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// chevron_up_square_fill — Cupertino icon named "chevron_up_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData chevron_up_square_fill = IconData(0xf5ea, fontFamily: iconFont, fontPackage: iconFontPackage); + /// circle_bottomthird_split — Cupertino icon named "circle_bottomthird_split". Available on cupertino_icons package 1.0.0+ only. + static const IconData circle_bottomthird_split = IconData(0xf5eb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// circle_fill — Cupertino icon named "circle_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [circle_filled] which is available in cupertino_icons 0.1.3. + static const IconData circle_fill = IconData(0xf400, fontFamily: iconFont, fontPackage: iconFontPackage); + /// circle_grid_3x3 — Cupertino icon named "circle_grid_3x3". Available on cupertino_icons package 1.0.0+ only. + static const IconData circle_grid_3x3 = IconData(0xf5ec, fontFamily: iconFont, fontPackage: iconFontPackage); + /// circle_grid_3x3_fill — Cupertino icon named "circle_grid_3x3_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData circle_grid_3x3_fill = IconData(0xf5ed, fontFamily: iconFont, fontPackage: iconFontPackage); + /// circle_grid_hex — Cupertino icon named "circle_grid_hex". Available on cupertino_icons package 1.0.0+ only. + static const IconData circle_grid_hex = IconData(0xf5ee, fontFamily: iconFont, fontPackage: iconFontPackage); + /// circle_grid_hex_fill — Cupertino icon named "circle_grid_hex_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData circle_grid_hex_fill = IconData(0xf5ef, fontFamily: iconFont, fontPackage: iconFontPackage); + /// circle_lefthalf_fill — Cupertino icon named "circle_lefthalf_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData circle_lefthalf_fill = IconData(0xf5f0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// circle_righthalf_fill — Cupertino icon named "circle_righthalf_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData circle_righthalf_fill = IconData(0xf5f1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// clear_fill — Cupertino icon named "clear_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData clear_fill = IconData(0xf5f3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// clock_fill — Cupertino icon named "clock_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [clock_solid] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [time_solid] which is available in cupertino_icons 0.1.3. + static const IconData clock_fill = IconData(0xf403, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud — Cupertino icon named "cloud". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud = IconData(0xf5f4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_bolt — Cupertino icon named "cloud_bolt". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_bolt = IconData(0xf5f5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_bolt_fill — Cupertino icon named "cloud_bolt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_bolt_fill = IconData(0xf5f6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_bolt_rain — Cupertino icon named "cloud_bolt_rain". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_bolt_rain = IconData(0xf5f7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_bolt_rain_fill — Cupertino icon named "cloud_bolt_rain_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_bolt_rain_fill = IconData(0xf5f8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_download — Cupertino icon named "cloud_download". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_download = IconData(0xf8c4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_download_fill — Cupertino icon named "cloud_download_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_download_fill = IconData(0xf8c5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_drizzle — Cupertino icon named "cloud_drizzle". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_drizzle = IconData(0xf5f9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_drizzle_fill — Cupertino icon named "cloud_drizzle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_drizzle_fill = IconData(0xf5fa, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_fill — Cupertino icon named "cloud_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_fill = IconData(0xf5fb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_fog — Cupertino icon named "cloud_fog". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_fog = IconData(0xf5fc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_fog_fill — Cupertino icon named "cloud_fog_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_fog_fill = IconData(0xf5fd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_hail — Cupertino icon named "cloud_hail". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_hail = IconData(0xf5fe, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_hail_fill — Cupertino icon named "cloud_hail_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_hail_fill = IconData(0xf5ff, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_heavyrain — Cupertino icon named "cloud_heavyrain". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_heavyrain = IconData(0xf600, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_heavyrain_fill — Cupertino icon named "cloud_heavyrain_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_heavyrain_fill = IconData(0xf601, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_moon — Cupertino icon named "cloud_moon". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_moon = IconData(0xf602, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_moon_bolt — Cupertino icon named "cloud_moon_bolt". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_moon_bolt = IconData(0xf603, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_moon_bolt_fill — Cupertino icon named "cloud_moon_bolt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_moon_bolt_fill = IconData(0xf604, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_moon_fill — Cupertino icon named "cloud_moon_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_moon_fill = IconData(0xf605, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_moon_rain — Cupertino icon named "cloud_moon_rain". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_moon_rain = IconData(0xf606, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_moon_rain_fill — Cupertino icon named "cloud_moon_rain_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_moon_rain_fill = IconData(0xf607, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_rain — Cupertino icon named "cloud_rain". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_rain = IconData(0xf608, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_rain_fill — Cupertino icon named "cloud_rain_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_rain_fill = IconData(0xf609, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_sleet — Cupertino icon named "cloud_sleet". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_sleet = IconData(0xf60a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_sleet_fill — Cupertino icon named "cloud_sleet_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_sleet_fill = IconData(0xf60b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_snow — Cupertino icon named "cloud_snow". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_snow = IconData(0xf60c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_snow_fill — Cupertino icon named "cloud_snow_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_snow_fill = IconData(0xf60d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_sun — Cupertino icon named "cloud_sun". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_sun = IconData(0xf60e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_sun_bolt — Cupertino icon named "cloud_sun_bolt". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_sun_bolt = IconData(0xf60f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_sun_bolt_fill — Cupertino icon named "cloud_sun_bolt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_sun_bolt_fill = IconData(0xf610, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_sun_fill — Cupertino icon named "cloud_sun_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_sun_fill = IconData(0xf611, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_sun_rain — Cupertino icon named "cloud_sun_rain". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_sun_rain = IconData(0xf612, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_sun_rain_fill — Cupertino icon named "cloud_sun_rain_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_sun_rain_fill = IconData(0xf613, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_upload — Cupertino icon named "cloud_upload". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_upload = IconData(0xf8c6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cloud_upload_fill — Cupertino icon named "cloud_upload_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cloud_upload_fill = IconData(0xf8c7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// color_filter — Cupertino icon named "color_filter". Available on cupertino_icons package 1.0.0+ only. + static const IconData color_filter = IconData(0xf8c8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// color_filter_fill — Cupertino icon named "color_filter_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData color_filter_fill = IconData(0xf8c9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// command — Cupertino icon named "command". Available on cupertino_icons package 1.0.0+ only. + static const IconData command = IconData(0xf614, fontFamily: iconFont, fontPackage: iconFontPackage); + /// compass — Cupertino icon named "compass". Available on cupertino_icons package 1.0.0+ only. + static const IconData compass = IconData(0xf8ca, fontFamily: iconFont, fontPackage: iconFontPackage); + /// compass_fill — Cupertino icon named "compass_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData compass_fill = IconData(0xf8cb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// control — Cupertino icon named "control". Available on cupertino_icons package 1.0.0+ only. + static const IconData control = IconData(0xf615, fontFamily: iconFont, fontPackage: iconFontPackage); + /// creditcard — Cupertino icon named "creditcard". Available on cupertino_icons package 1.0.0+ only. + static const IconData creditcard = IconData(0xf616, fontFamily: iconFont, fontPackage: iconFontPackage); + /// creditcard_fill — Cupertino icon named "creditcard_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData creditcard_fill = IconData(0xf617, fontFamily: iconFont, fontPackage: iconFontPackage); + /// crop — Cupertino icon named "crop". Available on cupertino_icons package 1.0.0+ only. + static const IconData crop = IconData(0xf618, fontFamily: iconFont, fontPackage: iconFontPackage); + /// crop_rotate — Cupertino icon named "crop_rotate". Available on cupertino_icons package 1.0.0+ only. + static const IconData crop_rotate = IconData(0xf619, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cube — Cupertino icon named "cube". Available on cupertino_icons package 1.0.0+ only. + static const IconData cube = IconData(0xf61a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cube_box — Cupertino icon named "cube_box". Available on cupertino_icons package 1.0.0+ only. + static const IconData cube_box = IconData(0xf61b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cube_box_fill — Cupertino icon named "cube_box_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cube_box_fill = IconData(0xf61c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cube_fill — Cupertino icon named "cube_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData cube_fill = IconData(0xf61d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// cursor_rays — Cupertino icon named "cursor_rays". Available on cupertino_icons package 1.0.0+ only. + static const IconData cursor_rays = IconData(0xf61e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// decrease_indent — Cupertino icon named "decrease_indent". Available on cupertino_icons package 1.0.0+ only. + static const IconData decrease_indent = IconData(0xf61f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// decrease_quotelevel — Cupertino icon named "decrease_quotelevel". Available on cupertino_icons package 1.0.0+ only. + static const IconData decrease_quotelevel = IconData(0xf620, fontFamily: iconFont, fontPackage: iconFontPackage); + /// delete_left — Cupertino icon named "delete_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData delete_left = IconData(0xf621, fontFamily: iconFont, fontPackage: iconFontPackage); + /// delete_left_fill — Cupertino icon named "delete_left_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData delete_left_fill = IconData(0xf622, fontFamily: iconFont, fontPackage: iconFontPackage); + /// delete_right — Cupertino icon named "delete_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData delete_right = IconData(0xf623, fontFamily: iconFont, fontPackage: iconFontPackage); + /// delete_right_fill — Cupertino icon named "delete_right_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData delete_right_fill = IconData(0xf624, fontFamily: iconFont, fontPackage: iconFontPackage); + /// desktopcomputer — Cupertino icon named "desktopcomputer". Available on cupertino_icons package 1.0.0+ only. + static const IconData desktopcomputer = IconData(0xf625, fontFamily: iconFont, fontPackage: iconFontPackage); + /// device_desktop — Cupertino icon named "device_desktop". Available on cupertino_icons package 1.0.0+ only. + static const IconData device_desktop = IconData(0xf8cc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// device_laptop — Cupertino icon named "device_laptop". Available on cupertino_icons package 1.0.0+ only. + static const IconData device_laptop = IconData(0xf8cd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// device_phone_landscape — Cupertino icon named "device_phone_landscape". Available on cupertino_icons package 1.0.0+ only. + static const IconData device_phone_landscape = IconData(0xf8ce, fontFamily: iconFont, fontPackage: iconFontPackage); + /// device_phone_portrait — Cupertino icon named "device_phone_portrait". Available on cupertino_icons package 1.0.0+ only. + static const IconData device_phone_portrait = IconData(0xf8cf, fontFamily: iconFont, fontPackage: iconFontPackage); + /// dial — Cupertino icon named "dial". Available on cupertino_icons package 1.0.0+ only. + static const IconData dial = IconData(0xf626, fontFamily: iconFont, fontPackage: iconFontPackage); + /// dial_fill — Cupertino icon named "dial_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData dial_fill = IconData(0xf627, fontFamily: iconFont, fontPackage: iconFontPackage); + /// divide — Cupertino icon named "divide". Available on cupertino_icons package 1.0.0+ only. + static const IconData divide = IconData(0xf628, fontFamily: iconFont, fontPackage: iconFontPackage); + /// divide_circle — Cupertino icon named "divide_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData divide_circle = IconData(0xf629, fontFamily: iconFont, fontPackage: iconFontPackage); + /// divide_circle_fill — Cupertino icon named "divide_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData divide_circle_fill = IconData(0xf62a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// divide_square — Cupertino icon named "divide_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData divide_square = IconData(0xf62b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// divide_square_fill — Cupertino icon named "divide_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData divide_square_fill = IconData(0xf62c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc — Cupertino icon named "doc". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc = IconData(0xf62d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_append — Cupertino icon named "doc_append". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_append = IconData(0xf62e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_chart — Cupertino icon named "doc_chart". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_chart = IconData(0xf8d0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_chart_fill — Cupertino icon named "doc_chart_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_chart_fill = IconData(0xf8d1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_checkmark — Cupertino icon named "doc_checkmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_checkmark = IconData(0xf8d2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_checkmark_fill — Cupertino icon named "doc_checkmark_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_checkmark_fill = IconData(0xf8d3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_circle — Cupertino icon named "doc_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_circle = IconData(0xf62f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_circle_fill — Cupertino icon named "doc_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_circle_fill = IconData(0xf630, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_fill — Cupertino icon named "doc_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_fill = IconData(0xf631, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_on_clipboard — Cupertino icon named "doc_on_clipboard". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_on_clipboard = IconData(0xf632, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_on_clipboard_fill — Cupertino icon named "doc_on_clipboard_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_on_clipboard_fill = IconData(0xf633, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_on_doc — Cupertino icon named "doc_on_doc". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_on_doc = IconData(0xf634, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_on_doc_fill — Cupertino icon named "doc_on_doc_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_on_doc_fill = IconData(0xf635, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_person — Cupertino icon named "doc_person". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_person = IconData(0xf8d4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_person_fill — Cupertino icon named "doc_person_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_person_fill = IconData(0xf8d5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_plaintext — Cupertino icon named "doc_plaintext". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_plaintext = IconData(0xf636, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_richtext — Cupertino icon named "doc_richtext". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_richtext = IconData(0xf637, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_text — Cupertino icon named "doc_text". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_text = IconData(0xf638, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_text_fill — Cupertino icon named "doc_text_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_text_fill = IconData(0xf639, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_text_search — Cupertino icon named "doc_text_search". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_text_search = IconData(0xf63a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// doc_text_viewfinder — Cupertino icon named "doc_text_viewfinder". Available on cupertino_icons package 1.0.0+ only. + static const IconData doc_text_viewfinder = IconData(0xf63b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// dot_radiowaves_left_right — Cupertino icon named "dot_radiowaves_left_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData dot_radiowaves_left_right = IconData(0xf63c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// dot_radiowaves_right — Cupertino icon named "dot_radiowaves_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData dot_radiowaves_right = IconData(0xf63d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// dot_square — Cupertino icon named "dot_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData dot_square = IconData(0xf63e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// dot_square_fill — Cupertino icon named "dot_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData dot_square_fill = IconData(0xf63f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// download_circle — Cupertino icon named "download_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData download_circle = IconData(0xf8d6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// download_circle_fill — Cupertino icon named "download_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData download_circle_fill = IconData(0xf8d7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// drop — Cupertino icon named "drop". Available on cupertino_icons package 1.0.0+ only. + static const IconData drop = IconData(0xf8d8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// drop_fill — Cupertino icon named "drop_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData drop_fill = IconData(0xf8d9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// drop_triangle — Cupertino icon named "drop_triangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData drop_triangle = IconData(0xf640, fontFamily: iconFont, fontPackage: iconFontPackage); + /// drop_triangle_fill — Cupertino icon named "drop_triangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData drop_triangle_fill = IconData(0xf641, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ear — Cupertino icon named "ear". Available on cupertino_icons package 1.0.0+ only. + static const IconData ear = IconData(0xf642, fontFamily: iconFont, fontPackage: iconFontPackage); + /// eject — Cupertino icon named "eject". Available on cupertino_icons package 1.0.0+ only. + static const IconData eject = IconData(0xf643, fontFamily: iconFont, fontPackage: iconFontPackage); + /// eject_fill — Cupertino icon named "eject_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData eject_fill = IconData(0xf644, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ellipses_bubble — Cupertino icon named "ellipses_bubble". Available on cupertino_icons package 1.0.0+ only. + static const IconData ellipses_bubble = IconData(0xf645, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ellipses_bubble_fill — Cupertino icon named "ellipses_bubble_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData ellipses_bubble_fill = IconData(0xf646, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ellipsis_circle — Cupertino icon named "ellipsis_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData ellipsis_circle = IconData(0xf647, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ellipsis_circle_fill — Cupertino icon named "ellipsis_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData ellipsis_circle_fill = IconData(0xf648, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ellipsis_vertical — Cupertino icon named "ellipsis_vertical". Available on cupertino_icons package 1.0.0+ only. + static const IconData ellipsis_vertical = IconData(0xf8da, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ellipsis_vertical_circle — Cupertino icon named "ellipsis_vertical_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData ellipsis_vertical_circle = IconData(0xf8db, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ellipsis_vertical_circle_fill — Cupertino icon named "ellipsis_vertical_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData ellipsis_vertical_circle_fill = IconData(0xf8dc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// envelope — Cupertino icon named "envelope". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [mail] which is available in cupertino_icons 0.1.3. + static const IconData envelope = IconData(0xf422, fontFamily: iconFont, fontPackage: iconFontPackage); + /// envelope_badge — Cupertino icon named "envelope_badge". Available on cupertino_icons package 1.0.0+ only. + static const IconData envelope_badge = IconData(0xf649, fontFamily: iconFont, fontPackage: iconFontPackage); + /// envelope_badge_fill — Cupertino icon named "envelope_badge_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData envelope_badge_fill = IconData(0xf64a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// envelope_circle — Cupertino icon named "envelope_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData envelope_circle = IconData(0xf64b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// envelope_circle_fill — Cupertino icon named "envelope_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData envelope_circle_fill = IconData(0xf64c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// envelope_fill — Cupertino icon named "envelope_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [mail_solid] which is available in cupertino_icons 0.1.3. + static const IconData envelope_fill = IconData(0xf423, fontFamily: iconFont, fontPackage: iconFontPackage); + /// envelope_open — Cupertino icon named "envelope_open". Available on cupertino_icons package 1.0.0+ only. + static const IconData envelope_open = IconData(0xf64d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// envelope_open_fill — Cupertino icon named "envelope_open_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData envelope_open_fill = IconData(0xf64e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// equal — Cupertino icon named "equal". Available on cupertino_icons package 1.0.0+ only. + static const IconData equal = IconData(0xf64f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// equal_circle — Cupertino icon named "equal_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData equal_circle = IconData(0xf650, fontFamily: iconFont, fontPackage: iconFontPackage); + /// equal_circle_fill — Cupertino icon named "equal_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData equal_circle_fill = IconData(0xf651, fontFamily: iconFont, fontPackage: iconFontPackage); + /// equal_square — Cupertino icon named "equal_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData equal_square = IconData(0xf652, fontFamily: iconFont, fontPackage: iconFontPackage); + /// equal_square_fill — Cupertino icon named "equal_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData equal_square_fill = IconData(0xf653, fontFamily: iconFont, fontPackage: iconFontPackage); + /// escape — Cupertino icon named "escape". Available on cupertino_icons package 1.0.0+ only. + static const IconData escape = IconData(0xf654, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark — Cupertino icon named "exclamationmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark = IconData(0xf655, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_bubble — Cupertino icon named "exclamationmark_bubble". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_bubble = IconData(0xf656, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_bubble_fill — Cupertino icon named "exclamationmark_bubble_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_bubble_fill = IconData(0xf657, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_circle — Cupertino icon named "exclamationmark_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_circle = IconData(0xf658, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_circle_fill — Cupertino icon named "exclamationmark_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_circle_fill = IconData(0xf659, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_octagon — Cupertino icon named "exclamationmark_octagon". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_octagon = IconData(0xf65a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_octagon_fill — Cupertino icon named "exclamationmark_octagon_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_octagon_fill = IconData(0xf65b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_shield — Cupertino icon named "exclamationmark_shield". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_shield = IconData(0xf65c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_shield_fill — Cupertino icon named "exclamationmark_shield_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_shield_fill = IconData(0xf65d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_square — Cupertino icon named "exclamationmark_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_square = IconData(0xf65e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_square_fill — Cupertino icon named "exclamationmark_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_square_fill = IconData(0xf65f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_triangle — Cupertino icon named "exclamationmark_triangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_triangle = IconData(0xf660, fontFamily: iconFont, fontPackage: iconFontPackage); + /// exclamationmark_triangle_fill — Cupertino icon named "exclamationmark_triangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData exclamationmark_triangle_fill = IconData(0xf661, fontFamily: iconFont, fontPackage: iconFontPackage); + /// eye_fill — Cupertino icon named "eye_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [eye_solid] which is available in cupertino_icons 0.1.3. + static const IconData eye_fill = IconData(0xf425, fontFamily: iconFont, fontPackage: iconFontPackage); + /// eye_slash — Cupertino icon named "eye_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData eye_slash = IconData(0xf662, fontFamily: iconFont, fontPackage: iconFontPackage); + /// eye_slash_fill — Cupertino icon named "eye_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData eye_slash_fill = IconData(0xf663, fontFamily: iconFont, fontPackage: iconFontPackage); + /// eyedropper — Cupertino icon named "eyedropper". Available on cupertino_icons package 1.0.0+ only. + static const IconData eyedropper = IconData(0xf664, fontFamily: iconFont, fontPackage: iconFontPackage); + /// eyedropper_full — Cupertino icon named "eyedropper_full". Available on cupertino_icons package 1.0.0+ only. + static const IconData eyedropper_full = IconData(0xf665, fontFamily: iconFont, fontPackage: iconFontPackage); + /// eyedropper_halffull — Cupertino icon named "eyedropper_halffull". Available on cupertino_icons package 1.0.0+ only. + static const IconData eyedropper_halffull = IconData(0xf666, fontFamily: iconFont, fontPackage: iconFontPackage); + /// eyeglasses — Cupertino icon named "eyeglasses". Available on cupertino_icons package 1.0.0+ only. + static const IconData eyeglasses = IconData(0xf667, fontFamily: iconFont, fontPackage: iconFontPackage); + /// f_cursive — Cupertino icon named "f_cursive". Available on cupertino_icons package 1.0.0+ only. + static const IconData f_cursive = IconData(0xf668, fontFamily: iconFont, fontPackage: iconFontPackage); + /// f_cursive_circle — Cupertino icon named "f_cursive_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData f_cursive_circle = IconData(0xf669, fontFamily: iconFont, fontPackage: iconFontPackage); + /// f_cursive_circle_fill — Cupertino icon named "f_cursive_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData f_cursive_circle_fill = IconData(0xf66a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// film — Cupertino icon named "film". Available on cupertino_icons package 1.0.0+ only. + static const IconData film = IconData(0xf66b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// film_fill — Cupertino icon named "film_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData film_fill = IconData(0xf66c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// flag_circle — Cupertino icon named "flag_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData flag_circle = IconData(0xf66d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// flag_circle_fill — Cupertino icon named "flag_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData flag_circle_fill = IconData(0xf66e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// flag_fill — Cupertino icon named "flag_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData flag_fill = IconData(0xf66f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// flag_slash — Cupertino icon named "flag_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData flag_slash = IconData(0xf670, fontFamily: iconFont, fontPackage: iconFontPackage); + /// flag_slash_fill — Cupertino icon named "flag_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData flag_slash_fill = IconData(0xf671, fontFamily: iconFont, fontPackage: iconFontPackage); + /// flame — Cupertino icon named "flame". Available on cupertino_icons package 1.0.0+ only. + static const IconData flame = IconData(0xf672, fontFamily: iconFont, fontPackage: iconFontPackage); + /// flame_fill — Cupertino icon named "flame_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData flame_fill = IconData(0xf673, fontFamily: iconFont, fontPackage: iconFontPackage); + /// floppy_disk — Cupertino icon named "floppy_disk". Available on cupertino_icons package 1.0.0+ only. + static const IconData floppy_disk = IconData(0xf8dd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// flowchart — Cupertino icon named "flowchart". Available on cupertino_icons package 1.0.0+ only. + static const IconData flowchart = IconData(0xf674, fontFamily: iconFont, fontPackage: iconFontPackage); + /// flowchart_fill — Cupertino icon named "flowchart_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData flowchart_fill = IconData(0xf675, fontFamily: iconFont, fontPackage: iconFontPackage); + /// folder_badge_minus — Cupertino icon named "folder_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData folder_badge_minus = IconData(0xf676, fontFamily: iconFont, fontPackage: iconFontPackage); + /// folder_badge_person_crop — Cupertino icon named "folder_badge_person_crop". Available on cupertino_icons package 1.0.0+ only. + static const IconData folder_badge_person_crop = IconData(0xf677, fontFamily: iconFont, fontPackage: iconFontPackage); + /// folder_badge_plus — Cupertino icon named "folder_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData folder_badge_plus = IconData(0xf678, fontFamily: iconFont, fontPackage: iconFontPackage); + /// folder_circle — Cupertino icon named "folder_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData folder_circle = IconData(0xf679, fontFamily: iconFont, fontPackage: iconFontPackage); + /// folder_circle_fill — Cupertino icon named "folder_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData folder_circle_fill = IconData(0xf67a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// folder_fill — Cupertino icon named "folder_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [folder_solid] which is available in cupertino_icons 0.1.3. + static const IconData folder_fill = IconData(0xf435, fontFamily: iconFont, fontPackage: iconFontPackage); + /// folder_fill_badge_minus — Cupertino icon named "folder_fill_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData folder_fill_badge_minus = IconData(0xf67b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// folder_fill_badge_person_crop — Cupertino icon named "folder_fill_badge_person_crop". Available on cupertino_icons package 1.0.0+ only. + static const IconData folder_fill_badge_person_crop = IconData(0xf67c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// folder_fill_badge_plus — Cupertino icon named "folder_fill_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData folder_fill_badge_plus = IconData(0xf67d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// forward_end — Cupertino icon named "forward_end". Available on cupertino_icons package 1.0.0+ only. + static const IconData forward_end = IconData(0xf67f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// forward_end_alt — Cupertino icon named "forward_end_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData forward_end_alt = IconData(0xf680, fontFamily: iconFont, fontPackage: iconFontPackage); + /// forward_end_alt_fill — Cupertino icon named "forward_end_alt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData forward_end_alt_fill = IconData(0xf681, fontFamily: iconFont, fontPackage: iconFontPackage); + /// forward_end_fill — Cupertino icon named "forward_end_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData forward_end_fill = IconData(0xf682, fontFamily: iconFont, fontPackage: iconFontPackage); + /// forward_fill — Cupertino icon named "forward_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData forward_fill = IconData(0xf683, fontFamily: iconFont, fontPackage: iconFontPackage); + /// function — Cupertino icon named "function". Available on cupertino_icons package 1.0.0+ only. + static const IconData function = IconData(0xf684, fontFamily: iconFont, fontPackage: iconFontPackage); + /// fx — Cupertino icon named "fx". Available on cupertino_icons package 1.0.0+ only. + static const IconData fx = IconData(0xf685, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gamecontroller — Cupertino icon named "gamecontroller". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [game_controller] which is available in cupertino_icons 0.1.3. + static const IconData gamecontroller = IconData(0xf43a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gamecontroller_alt_fill — Cupertino icon named "gamecontroller_alt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData gamecontroller_alt_fill = IconData(0xf8de, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gamecontroller_fill — Cupertino icon named "gamecontroller_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [game_controller_solid] which is available in cupertino_icons 0.1.3. + static const IconData gamecontroller_fill = IconData(0xf43b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gauge — Cupertino icon named "gauge". Available on cupertino_icons package 1.0.0+ only. + static const IconData gauge = IconData(0xf686, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gauge_badge_minus — Cupertino icon named "gauge_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData gauge_badge_minus = IconData(0xf687, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gauge_badge_plus — Cupertino icon named "gauge_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData gauge_badge_plus = IconData(0xf688, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gear_alt — Cupertino icon named "gear_alt". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [gear] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [gear_big] which is available in cupertino_icons 0.1.3. + static const IconData gear_alt = IconData(0xf43c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gear_alt_fill — Cupertino icon named "gear_alt_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [gear_solid] which is available in cupertino_icons 0.1.3. + static const IconData gear_alt_fill = IconData(0xf43d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gift — Cupertino icon named "gift". Available on cupertino_icons package 1.0.0+ only. + static const IconData gift = IconData(0xf689, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gift_alt — Cupertino icon named "gift_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData gift_alt = IconData(0xf68a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gift_alt_fill — Cupertino icon named "gift_alt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData gift_alt_fill = IconData(0xf68b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gift_fill — Cupertino icon named "gift_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData gift_fill = IconData(0xf68c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// globe — Cupertino icon named "globe". Available on cupertino_icons package 1.0.0+ only. + static const IconData globe = IconData(0xf68d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gobackward — Cupertino icon named "gobackward". Available on cupertino_icons package 1.0.0+ only. + static const IconData gobackward = IconData(0xf68e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gobackward_10 — Cupertino icon named "gobackward_10". Available on cupertino_icons package 1.0.0+ only. + static const IconData gobackward_10 = IconData(0xf68f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gobackward_15 — Cupertino icon named "gobackward_15". Available on cupertino_icons package 1.0.0+ only. + static const IconData gobackward_15 = IconData(0xf690, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gobackward_30 — Cupertino icon named "gobackward_30". Available on cupertino_icons package 1.0.0+ only. + static const IconData gobackward_30 = IconData(0xf691, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gobackward_45 — Cupertino icon named "gobackward_45". Available on cupertino_icons package 1.0.0+ only. + static const IconData gobackward_45 = IconData(0xf692, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gobackward_60 — Cupertino icon named "gobackward_60". Available on cupertino_icons package 1.0.0+ only. + static const IconData gobackward_60 = IconData(0xf693, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gobackward_75 — Cupertino icon named "gobackward_75". Available on cupertino_icons package 1.0.0+ only. + static const IconData gobackward_75 = IconData(0xf694, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gobackward_90 — Cupertino icon named "gobackward_90". Available on cupertino_icons package 1.0.0+ only. + static const IconData gobackward_90 = IconData(0xf695, fontFamily: iconFont, fontPackage: iconFontPackage); + /// gobackward_minus — Cupertino icon named "gobackward_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData gobackward_minus = IconData(0xf696, fontFamily: iconFont, fontPackage: iconFontPackage); + /// goforward — Cupertino icon named "goforward". Available on cupertino_icons package 1.0.0+ only. + static const IconData goforward = IconData(0xf697, fontFamily: iconFont, fontPackage: iconFontPackage); + /// goforward_10 — Cupertino icon named "goforward_10". Available on cupertino_icons package 1.0.0+ only. + static const IconData goforward_10 = IconData(0xf698, fontFamily: iconFont, fontPackage: iconFontPackage); + /// goforward_15 — Cupertino icon named "goforward_15". Available on cupertino_icons package 1.0.0+ only. + static const IconData goforward_15 = IconData(0xf699, fontFamily: iconFont, fontPackage: iconFontPackage); + /// goforward_30 — Cupertino icon named "goforward_30". Available on cupertino_icons package 1.0.0+ only. + static const IconData goforward_30 = IconData(0xf69a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// goforward_45 — Cupertino icon named "goforward_45". Available on cupertino_icons package 1.0.0+ only. + static const IconData goforward_45 = IconData(0xf69b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// goforward_60 — Cupertino icon named "goforward_60". Available on cupertino_icons package 1.0.0+ only. + static const IconData goforward_60 = IconData(0xf69c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// goforward_75 — Cupertino icon named "goforward_75". Available on cupertino_icons package 1.0.0+ only. + static const IconData goforward_75 = IconData(0xf69d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// goforward_90 — Cupertino icon named "goforward_90". Available on cupertino_icons package 1.0.0+ only. + static const IconData goforward_90 = IconData(0xf69e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// goforward_plus — Cupertino icon named "goforward_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData goforward_plus = IconData(0xf69f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// graph_circle — Cupertino icon named "graph_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData graph_circle = IconData(0xf8df, fontFamily: iconFont, fontPackage: iconFontPackage); + /// graph_circle_fill — Cupertino icon named "graph_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData graph_circle_fill = IconData(0xf8e0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// graph_square — Cupertino icon named "graph_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData graph_square = IconData(0xf8e1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// graph_square_fill — Cupertino icon named "graph_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData graph_square_fill = IconData(0xf8e2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// greaterthan — Cupertino icon named "greaterthan". Available on cupertino_icons package 1.0.0+ only. + static const IconData greaterthan = IconData(0xf6a0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// greaterthan_circle — Cupertino icon named "greaterthan_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData greaterthan_circle = IconData(0xf6a1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// greaterthan_circle_fill — Cupertino icon named "greaterthan_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData greaterthan_circle_fill = IconData(0xf6a2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// greaterthan_square — Cupertino icon named "greaterthan_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData greaterthan_square = IconData(0xf6a3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// greaterthan_square_fill — Cupertino icon named "greaterthan_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData greaterthan_square_fill = IconData(0xf6a4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// grid — Cupertino icon named "grid". Available on cupertino_icons package 1.0.0+ only. + static const IconData grid = IconData(0xf6a5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// grid_circle — Cupertino icon named "grid_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData grid_circle = IconData(0xf6a6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// grid_circle_fill — Cupertino icon named "grid_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData grid_circle_fill = IconData(0xf6a7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// guitars — Cupertino icon named "guitars". Available on cupertino_icons package 1.0.0+ only. + static const IconData guitars = IconData(0xf6a8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hammer — Cupertino icon named "hammer". Available on cupertino_icons package 1.0.0+ only. + static const IconData hammer = IconData(0xf6a9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hammer_fill — Cupertino icon named "hammer_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hammer_fill = IconData(0xf6aa, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_draw — Cupertino icon named "hand_draw". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_draw = IconData(0xf6ab, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_draw_fill — Cupertino icon named "hand_draw_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_draw_fill = IconData(0xf6ac, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_point_left — Cupertino icon named "hand_point_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_point_left = IconData(0xf6ad, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_point_left_fill — Cupertino icon named "hand_point_left_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_point_left_fill = IconData(0xf6ae, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_point_right — Cupertino icon named "hand_point_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_point_right = IconData(0xf6af, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_point_right_fill — Cupertino icon named "hand_point_right_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_point_right_fill = IconData(0xf6b0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_raised — Cupertino icon named "hand_raised". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_raised = IconData(0xf6b1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_raised_fill — Cupertino icon named "hand_raised_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_raised_fill = IconData(0xf6b2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_raised_slash — Cupertino icon named "hand_raised_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_raised_slash = IconData(0xf6b3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_raised_slash_fill — Cupertino icon named "hand_raised_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_raised_slash_fill = IconData(0xf6b4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_thumbsdown — Cupertino icon named "hand_thumbsdown". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_thumbsdown = IconData(0xf6b5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_thumbsdown_fill — Cupertino icon named "hand_thumbsdown_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_thumbsdown_fill = IconData(0xf6b6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_thumbsup — Cupertino icon named "hand_thumbsup". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_thumbsup = IconData(0xf6b7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hand_thumbsup_fill — Cupertino icon named "hand_thumbsup_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hand_thumbsup_fill = IconData(0xf6b8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hare — Cupertino icon named "hare". Available on cupertino_icons package 1.0.0+ only. + static const IconData hare = IconData(0xf6b9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hare_fill — Cupertino icon named "hare_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hare_fill = IconData(0xf6ba, fontFamily: iconFont, fontPackage: iconFontPackage); + /// headphones — Cupertino icon named "headphones". Available on cupertino_icons package 1.0.0+ only. + static const IconData headphones = IconData(0xf6bb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// heart_circle — Cupertino icon named "heart_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData heart_circle = IconData(0xf6bc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// heart_circle_fill — Cupertino icon named "heart_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData heart_circle_fill = IconData(0xf6bd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// heart_fill — Cupertino icon named "heart_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [heart_solid] which is available in cupertino_icons 0.1.3. + static const IconData heart_fill = IconData(0xf443, fontFamily: iconFont, fontPackage: iconFontPackage); + /// heart_slash — Cupertino icon named "heart_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData heart_slash = IconData(0xf6be, fontFamily: iconFont, fontPackage: iconFontPackage); + /// heart_slash_circle — Cupertino icon named "heart_slash_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData heart_slash_circle = IconData(0xf6bf, fontFamily: iconFont, fontPackage: iconFontPackage); + /// heart_slash_circle_fill — Cupertino icon named "heart_slash_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData heart_slash_circle_fill = IconData(0xf6c0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// heart_slash_fill — Cupertino icon named "heart_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData heart_slash_fill = IconData(0xf6c1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// helm — Cupertino icon named "helm". Available on cupertino_icons package 1.0.0+ only. + static const IconData helm = IconData(0xf6c2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hexagon — Cupertino icon named "hexagon". Available on cupertino_icons package 1.0.0+ only. + static const IconData hexagon = IconData(0xf6c3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hexagon_fill — Cupertino icon named "hexagon_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hexagon_fill = IconData(0xf6c4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hifispeaker — Cupertino icon named "hifispeaker". Available on cupertino_icons package 1.0.0+ only. + static const IconData hifispeaker = IconData(0xf6c5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hifispeaker_fill — Cupertino icon named "hifispeaker_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hifispeaker_fill = IconData(0xf6c6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hourglass — Cupertino icon named "hourglass". Available on cupertino_icons package 1.0.0+ only. + static const IconData hourglass = IconData(0xf6c7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hourglass_bottomhalf_fill — Cupertino icon named "hourglass_bottomhalf_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hourglass_bottomhalf_fill = IconData(0xf6c8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hourglass_tophalf_fill — Cupertino icon named "hourglass_tophalf_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData hourglass_tophalf_fill = IconData(0xf6c9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// house — Cupertino icon named "house". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [home] which is available in cupertino_icons 0.1.3. + static const IconData house = IconData(0xf447, fontFamily: iconFont, fontPackage: iconFontPackage); + /// house_alt — Cupertino icon named "house_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData house_alt = IconData(0xf8e3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// house_alt_fill — Cupertino icon named "house_alt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData house_alt_fill = IconData(0xf8e4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// house_fill — Cupertino icon named "house_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData house_fill = IconData(0xf6ca, fontFamily: iconFont, fontPackage: iconFontPackage); + /// hurricane — Cupertino icon named "hurricane". Available on cupertino_icons package 1.0.0+ only. + static const IconData hurricane = IconData(0xf6cb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// increase_indent — Cupertino icon named "increase_indent". Available on cupertino_icons package 1.0.0+ only. + static const IconData increase_indent = IconData(0xf6cc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// increase_quotelevel — Cupertino icon named "increase_quotelevel". Available on cupertino_icons package 1.0.0+ only. + static const IconData increase_quotelevel = IconData(0xf6cd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// infinite — Cupertino icon named "infinite". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [loop] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [loop_thick] which is available in cupertino_icons 0.1.3. + static const IconData infinite = IconData(0xf449, fontFamily: iconFont, fontPackage: iconFontPackage); + /// info_circle — Cupertino icon named "info_circle". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [info] which is available in cupertino_icons 0.1.3. + static const IconData info_circle = IconData(0xf44c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// info_circle_fill — Cupertino icon named "info_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData info_circle_fill = IconData(0xf6cf, fontFamily: iconFont, fontPackage: iconFontPackage); + /// italic — Cupertino icon named "italic". Available on cupertino_icons package 1.0.0+ only. + static const IconData italic = IconData(0xf6d0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// keyboard — Cupertino icon named "keyboard". Available on cupertino_icons package 1.0.0+ only. + static const IconData keyboard = IconData(0xf6d1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// keyboard_chevron_compact_down — Cupertino icon named "keyboard_chevron_compact_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData keyboard_chevron_compact_down = IconData(0xf6d2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// largecircle_fill_circle — Cupertino icon named "largecircle_fill_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData largecircle_fill_circle = IconData(0xf6d3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lasso — Cupertino icon named "lasso". Available on cupertino_icons package 1.0.0+ only. + static const IconData lasso = IconData(0xf6d4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// layers — Cupertino icon named "layers". Available on cupertino_icons package 1.0.0+ only. + static const IconData layers = IconData(0xf8e5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// layers_alt — Cupertino icon named "layers_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData layers_alt = IconData(0xf8e6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// layers_alt_fill — Cupertino icon named "layers_alt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData layers_alt_fill = IconData(0xf8e7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// layers_fill — Cupertino icon named "layers_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData layers_fill = IconData(0xf8e8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// leaf_arrow_circlepath — Cupertino icon named "leaf_arrow_circlepath". Available on cupertino_icons package 1.0.0+ only. + static const IconData leaf_arrow_circlepath = IconData(0xf6d5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lessthan — Cupertino icon named "lessthan". Available on cupertino_icons package 1.0.0+ only. + static const IconData lessthan = IconData(0xf6d6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lessthan_circle — Cupertino icon named "lessthan_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData lessthan_circle = IconData(0xf6d7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lessthan_circle_fill — Cupertino icon named "lessthan_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData lessthan_circle_fill = IconData(0xf6d8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lessthan_square — Cupertino icon named "lessthan_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData lessthan_square = IconData(0xf6d9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lessthan_square_fill — Cupertino icon named "lessthan_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData lessthan_square_fill = IconData(0xf6da, fontFamily: iconFont, fontPackage: iconFontPackage); + /// light_max — Cupertino icon named "light_max". Available on cupertino_icons package 1.0.0+ only. + static const IconData light_max = IconData(0xf6db, fontFamily: iconFont, fontPackage: iconFontPackage); + /// light_min — Cupertino icon named "light_min". Available on cupertino_icons package 1.0.0+ only. + static const IconData light_min = IconData(0xf6dc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lightbulb — Cupertino icon named "lightbulb". Available on cupertino_icons package 1.0.0+ only. + static const IconData lightbulb = IconData(0xf6dd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lightbulb_fill — Cupertino icon named "lightbulb_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData lightbulb_fill = IconData(0xf6de, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lightbulb_slash — Cupertino icon named "lightbulb_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData lightbulb_slash = IconData(0xf6df, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lightbulb_slash_fill — Cupertino icon named "lightbulb_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData lightbulb_slash_fill = IconData(0xf6e0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// line_horizontal_3 — Cupertino icon named "line_horizontal_3". Available on cupertino_icons package 1.0.0+ only. + static const IconData line_horizontal_3 = IconData(0xf6e1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// line_horizontal_3_decrease — Cupertino icon named "line_horizontal_3_decrease". Available on cupertino_icons package 1.0.0+ only. + static const IconData line_horizontal_3_decrease = IconData(0xf6e2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// line_horizontal_3_decrease_circle — Cupertino icon named "line_horizontal_3_decrease_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData line_horizontal_3_decrease_circle = IconData(0xf6e3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// line_horizontal_3_decrease_circle_fill — Cupertino icon named "line_horizontal_3_decrease_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData line_horizontal_3_decrease_circle_fill = IconData(0xf6e4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// link — Cupertino icon named "link". Available on cupertino_icons package 1.0.0+ only. + static const IconData link = IconData(0xf6e5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// link_circle — Cupertino icon named "link_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData link_circle = IconData(0xf6e6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// link_circle_fill — Cupertino icon named "link_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData link_circle_fill = IconData(0xf6e7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// list_bullet — Cupertino icon named "list_bullet". Available on cupertino_icons package 1.0.0+ only. + static const IconData list_bullet = IconData(0xf6e8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// list_bullet_below_rectangle — Cupertino icon named "list_bullet_below_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData list_bullet_below_rectangle = IconData(0xf6e9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// list_bullet_indent — Cupertino icon named "list_bullet_indent". Available on cupertino_icons package 1.0.0+ only. + static const IconData list_bullet_indent = IconData(0xf6ea, fontFamily: iconFont, fontPackage: iconFontPackage); + /// list_dash — Cupertino icon named "list_dash". Available on cupertino_icons package 1.0.0+ only. + static const IconData list_dash = IconData(0xf6eb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// list_number — Cupertino icon named "list_number". Available on cupertino_icons package 1.0.0+ only. + static const IconData list_number = IconData(0xf6ec, fontFamily: iconFont, fontPackage: iconFontPackage); + /// list_number_rtl — Cupertino icon named "list_number_rtl". Available on cupertino_icons package 1.0.0+ only. + static const IconData list_number_rtl = IconData(0xf6ed, fontFamily: iconFont, fontPackage: iconFontPackage); + /// location_circle — Cupertino icon named "location_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData location_circle = IconData(0xf6ef, fontFamily: iconFont, fontPackage: iconFontPackage); + /// location_circle_fill — Cupertino icon named "location_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData location_circle_fill = IconData(0xf6f0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// location_fill — Cupertino icon named "location_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData location_fill = IconData(0xf6f1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// location_north — Cupertino icon named "location_north". Available on cupertino_icons package 1.0.0+ only. + static const IconData location_north = IconData(0xf6f2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// location_north_fill — Cupertino icon named "location_north_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData location_north_fill = IconData(0xf6f3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// location_north_line — Cupertino icon named "location_north_line". Available on cupertino_icons package 1.0.0+ only. + static const IconData location_north_line = IconData(0xf6f4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// location_north_line_fill — Cupertino icon named "location_north_line_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData location_north_line_fill = IconData(0xf6f5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// location_slash — Cupertino icon named "location_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData location_slash = IconData(0xf6f6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// location_slash_fill — Cupertino icon named "location_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData location_slash_fill = IconData(0xf6f7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock — Cupertino icon named "lock". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [padlock] which is available in cupertino_icons 0.1.3. + static const IconData lock = IconData(0xf4c8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_circle — Cupertino icon named "lock_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData lock_circle = IconData(0xf6f8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_circle_fill — Cupertino icon named "lock_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData lock_circle_fill = IconData(0xf6f9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_fill — Cupertino icon named "lock_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [padlock_solid] which is available in cupertino_icons 0.1.3. + static const IconData lock_fill = IconData(0xf4c9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_open — Cupertino icon named "lock_open". Available on cupertino_icons package 1.0.0+ only. + static const IconData lock_open = IconData(0xf6fa, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_open_fill — Cupertino icon named "lock_open_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData lock_open_fill = IconData(0xf6fb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_rotation — Cupertino icon named "lock_rotation". Available on cupertino_icons package 1.0.0+ only. + static const IconData lock_rotation = IconData(0xf6fc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_rotation_open — Cupertino icon named "lock_rotation_open". Available on cupertino_icons package 1.0.0+ only. + static const IconData lock_rotation_open = IconData(0xf6fd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_shield — Cupertino icon named "lock_shield". Available on cupertino_icons package 1.0.0+ only. + static const IconData lock_shield = IconData(0xf6fe, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_shield_fill — Cupertino icon named "lock_shield_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData lock_shield_fill = IconData(0xf6ff, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_slash — Cupertino icon named "lock_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData lock_slash = IconData(0xf700, fontFamily: iconFont, fontPackage: iconFontPackage); + /// lock_slash_fill — Cupertino icon named "lock_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData lock_slash_fill = IconData(0xf701, fontFamily: iconFont, fontPackage: iconFontPackage); + /// macwindow — Cupertino icon named "macwindow". Available on cupertino_icons package 1.0.0+ only. + static const IconData macwindow = IconData(0xf702, fontFamily: iconFont, fontPackage: iconFontPackage); + /// map — Cupertino icon named "map". Available on cupertino_icons package 1.0.0+ only. + static const IconData map = IconData(0xf703, fontFamily: iconFont, fontPackage: iconFontPackage); + /// map_fill — Cupertino icon named "map_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData map_fill = IconData(0xf704, fontFamily: iconFont, fontPackage: iconFontPackage); + /// map_pin — Cupertino icon named "map_pin". Available on cupertino_icons package 1.0.0+ only. + static const IconData map_pin = IconData(0xf705, fontFamily: iconFont, fontPackage: iconFontPackage); + /// map_pin_ellipse — Cupertino icon named "map_pin_ellipse". Available on cupertino_icons package 1.0.0+ only. + static const IconData map_pin_ellipse = IconData(0xf706, fontFamily: iconFont, fontPackage: iconFontPackage); + /// map_pin_slash — Cupertino icon named "map_pin_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData map_pin_slash = IconData(0xf707, fontFamily: iconFont, fontPackage: iconFontPackage); + /// memories — Cupertino icon named "memories". Available on cupertino_icons package 1.0.0+ only. + static const IconData memories = IconData(0xf708, fontFamily: iconFont, fontPackage: iconFontPackage); + /// memories_badge_minus — Cupertino icon named "memories_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData memories_badge_minus = IconData(0xf709, fontFamily: iconFont, fontPackage: iconFontPackage); + /// memories_badge_plus — Cupertino icon named "memories_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData memories_badge_plus = IconData(0xf70a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// metronome — Cupertino icon named "metronome". Available on cupertino_icons package 1.0.0+ only. + static const IconData metronome = IconData(0xf70b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// mic_circle — Cupertino icon named "mic_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData mic_circle = IconData(0xf70c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// mic_circle_fill — Cupertino icon named "mic_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData mic_circle_fill = IconData(0xf70d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// mic_fill — Cupertino icon named "mic_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [mic_solid] which is available in cupertino_icons 0.1.3. + static const IconData mic_fill = IconData(0xf461, fontFamily: iconFont, fontPackage: iconFontPackage); + /// mic_slash — Cupertino icon named "mic_slash". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [mic_off] which is available in cupertino_icons 0.1.3. + static const IconData mic_slash = IconData(0xf45f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// mic_slash_fill — Cupertino icon named "mic_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData mic_slash_fill = IconData(0xf70e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// minus — Cupertino icon named "minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData minus = IconData(0xf70f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// minus_circle — Cupertino icon named "minus_circle". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [minus_circled] which is available in cupertino_icons 0.1.3. + static const IconData minus_circle = IconData(0xf463, fontFamily: iconFont, fontPackage: iconFontPackage); + /// minus_circle_fill — Cupertino icon named "minus_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData minus_circle_fill = IconData(0xf710, fontFamily: iconFont, fontPackage: iconFontPackage); + /// minus_rectangle — Cupertino icon named "minus_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData minus_rectangle = IconData(0xf711, fontFamily: iconFont, fontPackage: iconFontPackage); + /// minus_rectangle_fill — Cupertino icon named "minus_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData minus_rectangle_fill = IconData(0xf712, fontFamily: iconFont, fontPackage: iconFontPackage); + /// minus_slash_plus — Cupertino icon named "minus_slash_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData minus_slash_plus = IconData(0xf713, fontFamily: iconFont, fontPackage: iconFontPackage); + /// minus_square — Cupertino icon named "minus_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData minus_square = IconData(0xf714, fontFamily: iconFont, fontPackage: iconFontPackage); + /// minus_square_fill — Cupertino icon named "minus_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData minus_square_fill = IconData(0xf715, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_dollar — Cupertino icon named "money_dollar". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_dollar = IconData(0xf8e9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_dollar_circle — Cupertino icon named "money_dollar_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_dollar_circle = IconData(0xf8ea, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_dollar_circle_fill — Cupertino icon named "money_dollar_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_dollar_circle_fill = IconData(0xf8eb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_euro — Cupertino icon named "money_euro". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_euro = IconData(0xf8ec, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_euro_circle — Cupertino icon named "money_euro_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_euro_circle = IconData(0xf8ed, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_euro_circle_fill — Cupertino icon named "money_euro_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_euro_circle_fill = IconData(0xf8ee, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_pound — Cupertino icon named "money_pound". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_pound = IconData(0xf8ef, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_pound_circle — Cupertino icon named "money_pound_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_pound_circle = IconData(0xf8f0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_pound_circle_fill — Cupertino icon named "money_pound_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_pound_circle_fill = IconData(0xf8f1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_rubl — Cupertino icon named "money_rubl". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_rubl = IconData(0xf8f2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_rubl_circle — Cupertino icon named "money_rubl_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_rubl_circle = IconData(0xf8f3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_rubl_circle_fill — Cupertino icon named "money_rubl_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_rubl_circle_fill = IconData(0xf8f4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_yen — Cupertino icon named "money_yen". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_yen = IconData(0xf8f5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_yen_circle — Cupertino icon named "money_yen_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_yen_circle = IconData(0xf8f6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// money_yen_circle_fill — Cupertino icon named "money_yen_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData money_yen_circle_fill = IconData(0xf8f7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// moon — Cupertino icon named "moon". Available on cupertino_icons package 1.0.0+ only. + static const IconData moon = IconData(0xf716, fontFamily: iconFont, fontPackage: iconFontPackage); + /// moon_circle — Cupertino icon named "moon_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData moon_circle = IconData(0xf717, fontFamily: iconFont, fontPackage: iconFontPackage); + /// moon_circle_fill — Cupertino icon named "moon_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData moon_circle_fill = IconData(0xf718, fontFamily: iconFont, fontPackage: iconFontPackage); + /// moon_fill — Cupertino icon named "moon_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData moon_fill = IconData(0xf719, fontFamily: iconFont, fontPackage: iconFontPackage); + /// moon_stars — Cupertino icon named "moon_stars". Available on cupertino_icons package 1.0.0+ only. + static const IconData moon_stars = IconData(0xf71a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// moon_stars_fill — Cupertino icon named "moon_stars_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData moon_stars_fill = IconData(0xf71b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// moon_zzz — Cupertino icon named "moon_zzz". Available on cupertino_icons package 1.0.0+ only. + static const IconData moon_zzz = IconData(0xf71c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// moon_zzz_fill — Cupertino icon named "moon_zzz_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData moon_zzz_fill = IconData(0xf71d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// move — Cupertino icon named "move". Available on cupertino_icons package 1.0.0+ only. + static const IconData move = IconData(0xf8f8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// multiply — Cupertino icon named "multiply". Available on cupertino_icons package 1.0.0+ only. + static const IconData multiply = IconData(0xf71e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// multiply_circle — Cupertino icon named "multiply_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData multiply_circle = IconData(0xf71f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// multiply_circle_fill — Cupertino icon named "multiply_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData multiply_circle_fill = IconData(0xf720, fontFamily: iconFont, fontPackage: iconFontPackage); + /// multiply_square — Cupertino icon named "multiply_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData multiply_square = IconData(0xf721, fontFamily: iconFont, fontPackage: iconFontPackage); + /// multiply_square_fill — Cupertino icon named "multiply_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData multiply_square_fill = IconData(0xf722, fontFamily: iconFont, fontPackage: iconFontPackage); + /// music_albums — Cupertino icon named "music_albums". Available on cupertino_icons package 1.0.0+ only. + static const IconData music_albums = IconData(0xf8f9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// music_albums_fill — Cupertino icon named "music_albums_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData music_albums_fill = IconData(0xf8fa, fontFamily: iconFont, fontPackage: iconFontPackage); + /// music_house — Cupertino icon named "music_house". Available on cupertino_icons package 1.0.0+ only. + static const IconData music_house = IconData(0xf723, fontFamily: iconFont, fontPackage: iconFontPackage); + /// music_house_fill — Cupertino icon named "music_house_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData music_house_fill = IconData(0xf724, fontFamily: iconFont, fontPackage: iconFontPackage); + /// music_mic — Cupertino icon named "music_mic". Available on cupertino_icons package 1.0.0+ only. + static const IconData music_mic = IconData(0xf725, fontFamily: iconFont, fontPackage: iconFontPackage); + /// music_note_2 — Cupertino icon named "music_note_2". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [double_music_note] which is available in cupertino_icons 0.1.3. + static const IconData music_note_2 = IconData(0xf46c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// music_note_list — Cupertino icon named "music_note_list". Available on cupertino_icons package 1.0.0+ only. + static const IconData music_note_list = IconData(0xf726, fontFamily: iconFont, fontPackage: iconFontPackage); + /// nosign — Cupertino icon named "nosign". Available on cupertino_icons package 1.0.0+ only. + static const IconData nosign = IconData(0xf727, fontFamily: iconFont, fontPackage: iconFontPackage); + /// number — Cupertino icon named "number". Available on cupertino_icons package 1.0.0+ only. + static const IconData number = IconData(0xf728, fontFamily: iconFont, fontPackage: iconFontPackage); + /// number_circle — Cupertino icon named "number_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData number_circle = IconData(0xf729, fontFamily: iconFont, fontPackage: iconFontPackage); + /// number_circle_fill — Cupertino icon named "number_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData number_circle_fill = IconData(0xf72a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// number_square — Cupertino icon named "number_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData number_square = IconData(0xf72b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// number_square_fill — Cupertino icon named "number_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData number_square_fill = IconData(0xf72c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// option — Cupertino icon named "option". Available on cupertino_icons package 1.0.0+ only. + static const IconData option = IconData(0xf72d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// paintbrush — Cupertino icon named "paintbrush". Available on cupertino_icons package 1.0.0+ only. + static const IconData paintbrush = IconData(0xf72e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// paintbrush_fill — Cupertino icon named "paintbrush_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData paintbrush_fill = IconData(0xf72f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pano — Cupertino icon named "pano". Available on cupertino_icons package 1.0.0+ only. + static const IconData pano = IconData(0xf730, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pano_fill — Cupertino icon named "pano_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData pano_fill = IconData(0xf731, fontFamily: iconFont, fontPackage: iconFontPackage); + /// paperclip — Cupertino icon named "paperclip". Available on cupertino_icons package 1.0.0+ only. + static const IconData paperclip = IconData(0xf732, fontFamily: iconFont, fontPackage: iconFontPackage); + /// paperplane — Cupertino icon named "paperplane". Available on cupertino_icons package 1.0.0+ only. + static const IconData paperplane = IconData(0xf733, fontFamily: iconFont, fontPackage: iconFontPackage); + /// paperplane_fill — Cupertino icon named "paperplane_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData paperplane_fill = IconData(0xf734, fontFamily: iconFont, fontPackage: iconFontPackage); + /// paragraph — Cupertino icon named "paragraph". Available on cupertino_icons package 1.0.0+ only. + static const IconData paragraph = IconData(0xf735, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pause_circle — Cupertino icon named "pause_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData pause_circle = IconData(0xf736, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pause_circle_fill — Cupertino icon named "pause_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData pause_circle_fill = IconData(0xf737, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pause_fill — Cupertino icon named "pause_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [pause_solid] which is available in cupertino_icons 0.1.3. + static const IconData pause_fill = IconData(0xf478, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pause_rectangle — Cupertino icon named "pause_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData pause_rectangle = IconData(0xf738, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pause_rectangle_fill — Cupertino icon named "pause_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData pause_rectangle_fill = IconData(0xf739, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pencil_circle — Cupertino icon named "pencil_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData pencil_circle = IconData(0xf73a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pencil_circle_fill — Cupertino icon named "pencil_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData pencil_circle_fill = IconData(0xf73b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pencil_ellipsis_rectangle — Cupertino icon named "pencil_ellipsis_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData pencil_ellipsis_rectangle = IconData(0xf73c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pencil_outline — Cupertino icon named "pencil_outline". Available on cupertino_icons package 1.0.0+ only. + static const IconData pencil_outline = IconData(0xf73d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pencil_slash — Cupertino icon named "pencil_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData pencil_slash = IconData(0xf73e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// percent — Cupertino icon named "percent". Available on cupertino_icons package 1.0.0+ only. + static const IconData percent = IconData(0xf73f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_2 — Cupertino icon named "person_2". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_2 = IconData(0xf740, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_2_alt — Cupertino icon named "person_2_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_2_alt = IconData(0xf8fb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_2_fill — Cupertino icon named "person_2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_2_fill = IconData(0xf741, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_2_square_stack — Cupertino icon named "person_2_square_stack". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_2_square_stack = IconData(0xf742, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_2_square_stack_fill — Cupertino icon named "person_2_square_stack_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_2_square_stack_fill = IconData(0xf743, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_3 — Cupertino icon named "person_3". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [group] which is available in cupertino_icons 0.1.3. + static const IconData person_3 = IconData(0xf47b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_3_fill — Cupertino icon named "person_3_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [group_solid] which is available in cupertino_icons 0.1.3. + static const IconData person_3_fill = IconData(0xf47c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_alt — Cupertino icon named "person_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_alt = IconData(0xf8fc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_alt_circle — Cupertino icon named "person_alt_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_alt_circle = IconData(0xf8fd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_alt_circle_fill — Cupertino icon named "person_alt_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_alt_circle_fill = IconData(0xf8fe, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_badge_minus — Cupertino icon named "person_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_badge_minus = IconData(0xf744, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_badge_minus_fill — Cupertino icon named "person_badge_minus_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_badge_minus_fill = IconData(0xf745, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_badge_plus — Cupertino icon named "person_badge_plus". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [person_add] which is available in cupertino_icons 0.1.3. + static const IconData person_badge_plus = IconData(0xf47f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_badge_plus_fill — Cupertino icon named "person_badge_plus_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [person_add_solid] which is available in cupertino_icons 0.1.3. + static const IconData person_badge_plus_fill = IconData(0xf480, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_circle — Cupertino icon named "person_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_circle = IconData(0xf746, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_circle_fill — Cupertino icon named "person_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_circle_fill = IconData(0xf747, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle — Cupertino icon named "person_crop_circle". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [profile_circled] which is available in cupertino_icons 0.1.3. + static const IconData person_crop_circle = IconData(0xf419, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_badge_checkmark — Cupertino icon named "person_crop_circle_badge_checkmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_badge_checkmark = IconData(0xf748, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_badge_exclam — Cupertino icon named "person_crop_circle_badge_exclam". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_badge_exclam = IconData(0xf749, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_badge_minus — Cupertino icon named "person_crop_circle_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_badge_minus = IconData(0xf74a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_badge_plus — Cupertino icon named "person_crop_circle_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_badge_plus = IconData(0xf74b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_badge_xmark — Cupertino icon named "person_crop_circle_badge_xmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_badge_xmark = IconData(0xf74c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_fill — Cupertino icon named "person_crop_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_fill = IconData(0xf74d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_fill_badge_checkmark — Cupertino icon named "person_crop_circle_fill_badge_checkmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_fill_badge_checkmark = IconData(0xf74e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_fill_badge_exclam — Cupertino icon named "person_crop_circle_fill_badge_exclam". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_fill_badge_exclam = IconData(0xf74f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_fill_badge_minus — Cupertino icon named "person_crop_circle_fill_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_fill_badge_minus = IconData(0xf750, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_fill_badge_plus — Cupertino icon named "person_crop_circle_fill_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_fill_badge_plus = IconData(0xf751, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_circle_fill_badge_xmark — Cupertino icon named "person_crop_circle_fill_badge_xmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_circle_fill_badge_xmark = IconData(0xf752, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_rectangle — Cupertino icon named "person_crop_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_rectangle = IconData(0xf753, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_rectangle_fill — Cupertino icon named "person_crop_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_rectangle_fill = IconData(0xf754, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_square — Cupertino icon named "person_crop_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_square = IconData(0xf755, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_crop_square_fill — Cupertino icon named "person_crop_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData person_crop_square_fill = IconData(0xf756, fontFamily: iconFont, fontPackage: iconFontPackage); + /// person_fill — Cupertino icon named "person_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [person_solid] which is available in cupertino_icons 0.1.3. + static const IconData person_fill = IconData(0xf47e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// personalhotspot — Cupertino icon named "personalhotspot". Available on cupertino_icons package 1.0.0+ only. + static const IconData personalhotspot = IconData(0xf757, fontFamily: iconFont, fontPackage: iconFontPackage); + /// perspective — Cupertino icon named "perspective". Available on cupertino_icons package 1.0.0+ only. + static const IconData perspective = IconData(0xf758, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_arrow_down_left — Cupertino icon named "phone_arrow_down_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_arrow_down_left = IconData(0xf759, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_arrow_right — Cupertino icon named "phone_arrow_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_arrow_right = IconData(0xf75a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_arrow_up_right — Cupertino icon named "phone_arrow_up_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_arrow_up_right = IconData(0xf75b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_badge_plus — Cupertino icon named "phone_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_badge_plus = IconData(0xf75c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_circle — Cupertino icon named "phone_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_circle = IconData(0xf75d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_circle_fill — Cupertino icon named "phone_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_circle_fill = IconData(0xf75e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_down — Cupertino icon named "phone_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_down = IconData(0xf75f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_down_circle — Cupertino icon named "phone_down_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_down_circle = IconData(0xf760, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_down_circle_fill — Cupertino icon named "phone_down_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_down_circle_fill = IconData(0xf761, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_down_fill — Cupertino icon named "phone_down_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_down_fill = IconData(0xf762, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_fill — Cupertino icon named "phone_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [phone_solid] which is available in cupertino_icons 0.1.3. + static const IconData phone_fill = IconData(0xf4b9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_fill_arrow_down_left — Cupertino icon named "phone_fill_arrow_down_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_fill_arrow_down_left = IconData(0xf763, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_fill_arrow_right — Cupertino icon named "phone_fill_arrow_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_fill_arrow_right = IconData(0xf764, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_fill_arrow_up_right — Cupertino icon named "phone_fill_arrow_up_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_fill_arrow_up_right = IconData(0xf765, fontFamily: iconFont, fontPackage: iconFontPackage); + /// phone_fill_badge_plus — Cupertino icon named "phone_fill_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData phone_fill_badge_plus = IconData(0xf766, fontFamily: iconFont, fontPackage: iconFontPackage); + /// photo — Cupertino icon named "photo". Available on cupertino_icons package 1.0.0+ only. + static const IconData photo = IconData(0xf767, fontFamily: iconFont, fontPackage: iconFontPackage); + /// photo_fill — Cupertino icon named "photo_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData photo_fill = IconData(0xf768, fontFamily: iconFont, fontPackage: iconFontPackage); + /// photo_fill_on_rectangle_fill — Cupertino icon named "photo_fill_on_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData photo_fill_on_rectangle_fill = IconData(0xf769, fontFamily: iconFont, fontPackage: iconFontPackage); + /// photo_on_rectangle — Cupertino icon named "photo_on_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData photo_on_rectangle = IconData(0xf76a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// piano — Cupertino icon named "piano". Available on cupertino_icons package 1.0.0+ only. + static const IconData piano = IconData(0xf8ff, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pin — Cupertino icon named "pin". Available on cupertino_icons package 1.0.0+ only. + static const IconData pin = IconData(0xf76b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pin_fill — Cupertino icon named "pin_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData pin_fill = IconData(0xf76c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pin_slash — Cupertino icon named "pin_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData pin_slash = IconData(0xf76d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// pin_slash_fill — Cupertino icon named "pin_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData pin_slash_fill = IconData(0xf76e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// placemark — Cupertino icon named "placemark". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [location] which is available in cupertino_icons 0.1.3. + static const IconData placemark = IconData(0xf455, fontFamily: iconFont, fontPackage: iconFontPackage); + /// placemark_fill — Cupertino icon named "placemark_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [location_solid] which is available in cupertino_icons 0.1.3. + static const IconData placemark_fill = IconData(0xf456, fontFamily: iconFont, fontPackage: iconFontPackage); + /// play — Cupertino icon named "play". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [play_arrow] which is available in cupertino_icons 0.1.3. + static const IconData play = IconData(0xf487, fontFamily: iconFont, fontPackage: iconFontPackage); + /// play_circle — Cupertino icon named "play_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData play_circle = IconData(0xf76f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// play_circle_fill — Cupertino icon named "play_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData play_circle_fill = IconData(0xf770, fontFamily: iconFont, fontPackage: iconFontPackage); + /// play_fill — Cupertino icon named "play_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [play_arrow_solid] which is available in cupertino_icons 0.1.3. + static const IconData play_fill = IconData(0xf488, fontFamily: iconFont, fontPackage: iconFontPackage); + /// play_rectangle — Cupertino icon named "play_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData play_rectangle = IconData(0xf771, fontFamily: iconFont, fontPackage: iconFontPackage); + /// play_rectangle_fill — Cupertino icon named "play_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData play_rectangle_fill = IconData(0xf772, fontFamily: iconFont, fontPackage: iconFontPackage); + /// playpause — Cupertino icon named "playpause". Available on cupertino_icons package 1.0.0+ only. + static const IconData playpause = IconData(0xf773, fontFamily: iconFont, fontPackage: iconFontPackage); + /// playpause_fill — Cupertino icon named "playpause_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData playpause_fill = IconData(0xf774, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus — Cupertino icon named "plus". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [add] which is available in cupertino_icons 0.1.3. + static const IconData plus = IconData(0xf489, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_app — Cupertino icon named "plus_app". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_app = IconData(0xf775, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_app_fill — Cupertino icon named "plus_app_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_app_fill = IconData(0xf776, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_bubble — Cupertino icon named "plus_bubble". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_bubble = IconData(0xf777, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_bubble_fill — Cupertino icon named "plus_bubble_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_bubble_fill = IconData(0xf778, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_circle — Cupertino icon named "plus_circle". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [plus_circled] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [add_circled] which is available in cupertino_icons 0.1.3. + static const IconData plus_circle = IconData(0xf48a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_circle_fill — Cupertino icon named "plus_circle_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [add_circled_solid] which is available in cupertino_icons 0.1.3. + static const IconData plus_circle_fill = IconData(0xf48b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_rectangle — Cupertino icon named "plus_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_rectangle = IconData(0xf779, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_rectangle_fill — Cupertino icon named "plus_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_rectangle_fill = IconData(0xf77a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_rectangle_fill_on_rectangle_fill — Cupertino icon named "plus_rectangle_fill_on_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_rectangle_fill_on_rectangle_fill = IconData(0xf77b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_rectangle_on_rectangle — Cupertino icon named "plus_rectangle_on_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_rectangle_on_rectangle = IconData(0xf77c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_slash_minus — Cupertino icon named "plus_slash_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_slash_minus = IconData(0xf77d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_square — Cupertino icon named "plus_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_square = IconData(0xf77e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_square_fill — Cupertino icon named "plus_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_square_fill = IconData(0xf77f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_square_fill_on_square_fill — Cupertino icon named "plus_square_fill_on_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_square_fill_on_square_fill = IconData(0xf780, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plus_square_on_square — Cupertino icon named "plus_square_on_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData plus_square_on_square = IconData(0xf781, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plusminus — Cupertino icon named "plusminus". Available on cupertino_icons package 1.0.0+ only. + static const IconData plusminus = IconData(0xf782, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plusminus_circle — Cupertino icon named "plusminus_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData plusminus_circle = IconData(0xf783, fontFamily: iconFont, fontPackage: iconFontPackage); + /// plusminus_circle_fill — Cupertino icon named "plusminus_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData plusminus_circle_fill = IconData(0xf784, fontFamily: iconFont, fontPackage: iconFontPackage); + /// power — Cupertino icon named "power". Available on cupertino_icons package 1.0.0+ only. + static const IconData power = IconData(0xf785, fontFamily: iconFont, fontPackage: iconFontPackage); + /// printer — Cupertino icon named "printer". Available on cupertino_icons package 1.0.0+ only. + static const IconData printer = IconData(0xf786, fontFamily: iconFont, fontPackage: iconFontPackage); + /// printer_fill — Cupertino icon named "printer_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData printer_fill = IconData(0xf787, fontFamily: iconFont, fontPackage: iconFontPackage); + /// projective — Cupertino icon named "projective". Available on cupertino_icons package 1.0.0+ only. + static const IconData projective = IconData(0xf788, fontFamily: iconFont, fontPackage: iconFontPackage); + /// purchased — Cupertino icon named "purchased". Available on cupertino_icons package 1.0.0+ only. + static const IconData purchased = IconData(0xf789, fontFamily: iconFont, fontPackage: iconFontPackage); + /// purchased_circle — Cupertino icon named "purchased_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData purchased_circle = IconData(0xf78a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// purchased_circle_fill — Cupertino icon named "purchased_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData purchased_circle_fill = IconData(0xf78b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// qrcode — Cupertino icon named "qrcode". Available on cupertino_icons package 1.0.0+ only. + static const IconData qrcode = IconData(0xf78c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// qrcode_viewfinder — Cupertino icon named "qrcode_viewfinder". Available on cupertino_icons package 1.0.0+ only. + static const IconData qrcode_viewfinder = IconData(0xf78d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// question — Cupertino icon named "question". Available on cupertino_icons package 1.0.0+ only. + static const IconData question = IconData(0xf78e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// question_circle — Cupertino icon named "question_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData question_circle = IconData(0xf78f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// question_circle_fill — Cupertino icon named "question_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData question_circle_fill = IconData(0xf790, fontFamily: iconFont, fontPackage: iconFontPackage); + /// question_diamond — Cupertino icon named "question_diamond". Available on cupertino_icons package 1.0.0+ only. + static const IconData question_diamond = IconData(0xf791, fontFamily: iconFont, fontPackage: iconFontPackage); + /// question_diamond_fill — Cupertino icon named "question_diamond_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData question_diamond_fill = IconData(0xf792, fontFamily: iconFont, fontPackage: iconFontPackage); + /// question_square — Cupertino icon named "question_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData question_square = IconData(0xf793, fontFamily: iconFont, fontPackage: iconFontPackage); + /// question_square_fill — Cupertino icon named "question_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData question_square_fill = IconData(0xf794, fontFamily: iconFont, fontPackage: iconFontPackage); + /// quote_bubble — Cupertino icon named "quote_bubble". Available on cupertino_icons package 1.0.0+ only. + static const IconData quote_bubble = IconData(0xf795, fontFamily: iconFont, fontPackage: iconFontPackage); + /// quote_bubble_fill — Cupertino icon named "quote_bubble_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData quote_bubble_fill = IconData(0xf796, fontFamily: iconFont, fontPackage: iconFontPackage); + /// radiowaves_left — Cupertino icon named "radiowaves_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData radiowaves_left = IconData(0xf797, fontFamily: iconFont, fontPackage: iconFontPackage); + /// radiowaves_right — Cupertino icon named "radiowaves_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData radiowaves_right = IconData(0xf798, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rays — Cupertino icon named "rays". Available on cupertino_icons package 1.0.0+ only. + static const IconData rays = IconData(0xf799, fontFamily: iconFont, fontPackage: iconFontPackage); + /// recordingtape — Cupertino icon named "recordingtape". Available on cupertino_icons package 1.0.0+ only. + static const IconData recordingtape = IconData(0xf79a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle — Cupertino icon named "rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle = IconData(0xf79b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_3_offgrid — Cupertino icon named "rectangle_3_offgrid". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_3_offgrid = IconData(0xf79c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_3_offgrid_fill — Cupertino icon named "rectangle_3_offgrid_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_3_offgrid_fill = IconData(0xf79d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_arrow_up_right_arrow_down_left — Cupertino icon named "rectangle_arrow_up_right_arrow_down_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_arrow_up_right_arrow_down_left = IconData(0xf79e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_arrow_up_right_arrow_down_left_slash — Cupertino icon named "rectangle_arrow_up_right_arrow_down_left_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_arrow_up_right_arrow_down_left_slash = IconData(0xf79f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_badge_checkmark — Cupertino icon named "rectangle_badge_checkmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_badge_checkmark = IconData(0xf7a0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_badge_xmark — Cupertino icon named "rectangle_badge_xmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_badge_xmark = IconData(0xf7a1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_compress_vertical — Cupertino icon named "rectangle_compress_vertical". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_compress_vertical = IconData(0xf7a2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_dock — Cupertino icon named "rectangle_dock". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_dock = IconData(0xf7a3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_expand_vertical — Cupertino icon named "rectangle_expand_vertical". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_expand_vertical = IconData(0xf7a4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_fill — Cupertino icon named "rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_fill = IconData(0xf7a5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_fill_badge_checkmark — Cupertino icon named "rectangle_fill_badge_checkmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_fill_badge_checkmark = IconData(0xf7a6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_fill_badge_xmark — Cupertino icon named "rectangle_fill_badge_xmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_fill_badge_xmark = IconData(0xf7a7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_fill_on_rectangle_angled_fill — Cupertino icon named "rectangle_fill_on_rectangle_angled_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_fill_on_rectangle_angled_fill = IconData(0xf7a8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_fill_on_rectangle_fill — Cupertino icon named "rectangle_fill_on_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_fill_on_rectangle_fill = IconData(0xf7a9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_grid_1x2 — Cupertino icon named "rectangle_grid_1x2". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_grid_1x2 = IconData(0xf7aa, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_grid_1x2_fill — Cupertino icon named "rectangle_grid_1x2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_grid_1x2_fill = IconData(0xf7ab, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_grid_2x2 — Cupertino icon named "rectangle_grid_2x2". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_grid_2x2 = IconData(0xf7ac, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_grid_2x2_fill — Cupertino icon named "rectangle_grid_2x2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_grid_2x2_fill = IconData(0xf7ad, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_grid_3x2 — Cupertino icon named "rectangle_grid_3x2". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_grid_3x2 = IconData(0xf7ae, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_grid_3x2_fill — Cupertino icon named "rectangle_grid_3x2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_grid_3x2_fill = IconData(0xf7af, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_on_rectangle — Cupertino icon named "rectangle_on_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_on_rectangle = IconData(0xf7b0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_on_rectangle_angled — Cupertino icon named "rectangle_on_rectangle_angled". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_on_rectangle_angled = IconData(0xf7b1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_paperclip — Cupertino icon named "rectangle_paperclip". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_paperclip = IconData(0xf7b2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_split_3x1 — Cupertino icon named "rectangle_split_3x1". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_split_3x1 = IconData(0xf7b3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_split_3x1_fill — Cupertino icon named "rectangle_split_3x1_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_split_3x1_fill = IconData(0xf7b4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_split_3x3 — Cupertino icon named "rectangle_split_3x3". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_split_3x3 = IconData(0xf7b5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_split_3x3_fill — Cupertino icon named "rectangle_split_3x3_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_split_3x3_fill = IconData(0xf7b6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_stack — Cupertino icon named "rectangle_stack". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [collections] which is available in cupertino_icons 0.1.3. + static const IconData rectangle_stack = IconData(0xf3c9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_stack_badge_minus — Cupertino icon named "rectangle_stack_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_stack_badge_minus = IconData(0xf7b7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_stack_badge_person_crop — Cupertino icon named "rectangle_stack_badge_person_crop". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_stack_badge_person_crop = IconData(0xf7b8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_stack_badge_plus — Cupertino icon named "rectangle_stack_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_stack_badge_plus = IconData(0xf7b9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_stack_fill — Cupertino icon named "rectangle_stack_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [collections_solid] which is available in cupertino_icons 0.1.3. + static const IconData rectangle_stack_fill = IconData(0xf3ca, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_stack_fill_badge_minus — Cupertino icon named "rectangle_stack_fill_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_stack_fill_badge_minus = IconData(0xf7ba, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_stack_fill_badge_person_crop — Cupertino icon named "rectangle_stack_fill_badge_person_crop". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_stack_fill_badge_person_crop = IconData(0xf7bb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_stack_fill_badge_plus — Cupertino icon named "rectangle_stack_fill_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_stack_fill_badge_plus = IconData(0xf7bc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_stack_person_crop — Cupertino icon named "rectangle_stack_person_crop". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_stack_person_crop = IconData(0xf7bd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rectangle_stack_person_crop_fill — Cupertino icon named "rectangle_stack_person_crop_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rectangle_stack_person_crop_fill = IconData(0xf7be, fontFamily: iconFont, fontPackage: iconFontPackage); + /// repeat — Cupertino icon named "repeat". Available on cupertino_icons package 1.0.0+ only. + static const IconData repeat = IconData(0xf7bf, fontFamily: iconFont, fontPackage: iconFontPackage); + /// repeat_1 — Cupertino icon named "repeat_1". Available on cupertino_icons package 1.0.0+ only. + static const IconData repeat_1 = IconData(0xf7c0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// resize — Cupertino icon named "resize". Available on cupertino_icons package 1.0.0+ only. + static const IconData resize = IconData(0xf900, fontFamily: iconFont, fontPackage: iconFontPackage); + /// resize_h — Cupertino icon named "resize_h". Available on cupertino_icons package 1.0.0+ only. + static const IconData resize_h = IconData(0xf901, fontFamily: iconFont, fontPackage: iconFontPackage); + /// resize_v — Cupertino icon named "resize_v". Available on cupertino_icons package 1.0.0+ only. + static const IconData resize_v = IconData(0xf902, fontFamily: iconFont, fontPackage: iconFontPackage); + /// return_icon — Cupertino icon named "return_icon". Available on cupertino_icons package 1.0.0+ only. + static const IconData return_icon = IconData(0xf7c1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rhombus — Cupertino icon named "rhombus". Available on cupertino_icons package 1.0.0+ only. + static const IconData rhombus = IconData(0xf7c2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rhombus_fill — Cupertino icon named "rhombus_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rhombus_fill = IconData(0xf7c3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rocket — Cupertino icon named "rocket". Available on cupertino_icons package 1.0.0+ only. + static const IconData rocket = IconData(0xf903, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rocket_fill — Cupertino icon named "rocket_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rocket_fill = IconData(0xf904, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rosette — Cupertino icon named "rosette". Available on cupertino_icons package 1.0.0+ only. + static const IconData rosette = IconData(0xf7c4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rotate_left — Cupertino icon named "rotate_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData rotate_left = IconData(0xf7c5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rotate_left_fill — Cupertino icon named "rotate_left_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rotate_left_fill = IconData(0xf7c6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rotate_right — Cupertino icon named "rotate_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData rotate_right = IconData(0xf7c7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// rotate_right_fill — Cupertino icon named "rotate_right_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData rotate_right_fill = IconData(0xf7c8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// scissors — Cupertino icon named "scissors". Available on cupertino_icons package 1.0.0+ only. + static const IconData scissors = IconData(0xf7c9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// scissors_alt — Cupertino icon named "scissors_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData scissors_alt = IconData(0xf905, fontFamily: iconFont, fontPackage: iconFontPackage); + /// scope — Cupertino icon named "scope". Available on cupertino_icons package 1.0.0+ only. + static const IconData scope = IconData(0xf7ca, fontFamily: iconFont, fontPackage: iconFontPackage); + /// scribble — Cupertino icon named "scribble". Available on cupertino_icons package 1.0.0+ only. + static const IconData scribble = IconData(0xf7cb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// search_circle — Cupertino icon named "search_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData search_circle = IconData(0xf7cc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// search_circle_fill — Cupertino icon named "search_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData search_circle_fill = IconData(0xf7cd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// selection_pin_in_out — Cupertino icon named "selection_pin_in_out". Available on cupertino_icons package 1.0.0+ only. + static const IconData selection_pin_in_out = IconData(0xf7ce, fontFamily: iconFont, fontPackage: iconFontPackage); + /// shield — Cupertino icon named "shield". Available on cupertino_icons package 1.0.0+ only. + static const IconData shield = IconData(0xf7cf, fontFamily: iconFont, fontPackage: iconFontPackage); + /// shield_fill — Cupertino icon named "shield_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData shield_fill = IconData(0xf7d0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// shield_lefthalf_fill — Cupertino icon named "shield_lefthalf_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData shield_lefthalf_fill = IconData(0xf7d1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// shield_slash — Cupertino icon named "shield_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData shield_slash = IconData(0xf7d2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// shield_slash_fill — Cupertino icon named "shield_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData shield_slash_fill = IconData(0xf7d3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// shift — Cupertino icon named "shift". Available on cupertino_icons package 1.0.0+ only. + static const IconData shift = IconData(0xf7d4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// shift_fill — Cupertino icon named "shift_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData shift_fill = IconData(0xf7d5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sidebar_left — Cupertino icon named "sidebar_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData sidebar_left = IconData(0xf7d6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sidebar_right — Cupertino icon named "sidebar_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData sidebar_right = IconData(0xf7d7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// signature — Cupertino icon named "signature". Available on cupertino_icons package 1.0.0+ only. + static const IconData signature = IconData(0xf7d8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// skew — Cupertino icon named "skew". Available on cupertino_icons package 1.0.0+ only. + static const IconData skew = IconData(0xf7d9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// slash_circle — Cupertino icon named "slash_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData slash_circle = IconData(0xf7da, fontFamily: iconFont, fontPackage: iconFontPackage); + /// slash_circle_fill — Cupertino icon named "slash_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData slash_circle_fill = IconData(0xf7db, fontFamily: iconFont, fontPackage: iconFontPackage); + /// slider_horizontal_3 — Cupertino icon named "slider_horizontal_3". Available on cupertino_icons package 1.0.0+ only. + static const IconData slider_horizontal_3 = IconData(0xf7dc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// slider_horizontal_below_rectangle — Cupertino icon named "slider_horizontal_below_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData slider_horizontal_below_rectangle = IconData(0xf7dd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// slowmo — Cupertino icon named "slowmo". Available on cupertino_icons package 1.0.0+ only. + static const IconData slowmo = IconData(0xf7de, fontFamily: iconFont, fontPackage: iconFontPackage); + /// smallcircle_circle — Cupertino icon named "smallcircle_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData smallcircle_circle = IconData(0xf7df, fontFamily: iconFont, fontPackage: iconFontPackage); + /// smallcircle_circle_fill — Cupertino icon named "smallcircle_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData smallcircle_circle_fill = IconData(0xf7e0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// smallcircle_fill_circle — Cupertino icon named "smallcircle_fill_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData smallcircle_fill_circle = IconData(0xf7e1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// smallcircle_fill_circle_fill — Cupertino icon named "smallcircle_fill_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData smallcircle_fill_circle_fill = IconData(0xf7e2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// smiley — Cupertino icon named "smiley". Available on cupertino_icons package 1.0.0+ only. + static const IconData smiley = IconData(0xf7e3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// smiley_fill — Cupertino icon named "smiley_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData smiley_fill = IconData(0xf7e4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// smoke — Cupertino icon named "smoke". Available on cupertino_icons package 1.0.0+ only. + static const IconData smoke = IconData(0xf7e5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// smoke_fill — Cupertino icon named "smoke_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData smoke_fill = IconData(0xf7e6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// snow — Cupertino icon named "snow". Available on cupertino_icons package 1.0.0+ only. + static const IconData snow = IconData(0xf7e7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sort_down — Cupertino icon named "sort_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData sort_down = IconData(0xf906, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sort_down_circle — Cupertino icon named "sort_down_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData sort_down_circle = IconData(0xf907, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sort_down_circle_fill — Cupertino icon named "sort_down_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData sort_down_circle_fill = IconData(0xf908, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sort_up — Cupertino icon named "sort_up". Available on cupertino_icons package 1.0.0+ only. + static const IconData sort_up = IconData(0xf909, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sort_up_circle — Cupertino icon named "sort_up_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData sort_up_circle = IconData(0xf90a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sort_up_circle_fill — Cupertino icon named "sort_up_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData sort_up_circle_fill = IconData(0xf90b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sparkles — Cupertino icon named "sparkles". Available on cupertino_icons package 1.0.0+ only. + static const IconData sparkles = IconData(0xf7e8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker — Cupertino icon named "speaker". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker = IconData(0xf7e9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_1 — Cupertino icon named "speaker_1". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_1 = IconData(0xf7ea, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_1_fill — Cupertino icon named "speaker_1_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [volume_down] which is available in cupertino_icons 0.1.3. + static const IconData speaker_1_fill = IconData(0xf3b7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_2 — Cupertino icon named "speaker_2". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_2 = IconData(0xf7eb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_2_fill — Cupertino icon named "speaker_2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_2_fill = IconData(0xf7ec, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_3 — Cupertino icon named "speaker_3". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_3 = IconData(0xf7ed, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_3_fill — Cupertino icon named "speaker_3_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [volume_up] which is available in cupertino_icons 0.1.3. + static const IconData speaker_3_fill = IconData(0xf3ba, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_fill — Cupertino icon named "speaker_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [volume_mute] which is available in cupertino_icons 0.1.3. + static const IconData speaker_fill = IconData(0xf3b8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_slash — Cupertino icon named "speaker_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_slash = IconData(0xf7ee, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_slash_fill — Cupertino icon named "speaker_slash_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [volume_off] which is available in cupertino_icons 0.1.3. + static const IconData speaker_slash_fill = IconData(0xf3b9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_slash_fill_rtl — Cupertino icon named "speaker_slash_fill_rtl". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_slash_fill_rtl = IconData(0xf7ef, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_slash_rtl — Cupertino icon named "speaker_slash_rtl". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_slash_rtl = IconData(0xf7f0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_zzz — Cupertino icon named "speaker_zzz". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_zzz = IconData(0xf7f1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_zzz_fill — Cupertino icon named "speaker_zzz_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_zzz_fill = IconData(0xf7f2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_zzz_fill_rtl — Cupertino icon named "speaker_zzz_fill_rtl". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_zzz_fill_rtl = IconData(0xf7f3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speaker_zzz_rtl — Cupertino icon named "speaker_zzz_rtl". Available on cupertino_icons package 1.0.0+ only. + static const IconData speaker_zzz_rtl = IconData(0xf7f4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// speedometer — Cupertino icon named "speedometer". Available on cupertino_icons package 1.0.0+ only. + static const IconData speedometer = IconData(0xf7f5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sportscourt — Cupertino icon named "sportscourt". Available on cupertino_icons package 1.0.0+ only. + static const IconData sportscourt = IconData(0xf7f6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sportscourt_fill — Cupertino icon named "sportscourt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData sportscourt_fill = IconData(0xf7f7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square — Cupertino icon named "square". Available on cupertino_icons package 1.0.0+ only. + static const IconData square = IconData(0xf7f8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_down — Cupertino icon named "square_arrow_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_arrow_down = IconData(0xf7f9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_down_fill — Cupertino icon named "square_arrow_down_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_arrow_down_fill = IconData(0xf7fa, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_down_on_square — Cupertino icon named "square_arrow_down_on_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_arrow_down_on_square = IconData(0xf7fb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_down_on_square_fill — Cupertino icon named "square_arrow_down_on_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_arrow_down_on_square_fill = IconData(0xf7fc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_left — Cupertino icon named "square_arrow_left". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_arrow_left = IconData(0xf90c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_left_fill — Cupertino icon named "square_arrow_left_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_arrow_left_fill = IconData(0xf90d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_right — Cupertino icon named "square_arrow_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_arrow_right = IconData(0xf90e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_right_fill — Cupertino icon named "square_arrow_right_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_arrow_right_fill = IconData(0xf90f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_up — Cupertino icon named "square_arrow_up". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [share] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [share_up] which is available in cupertino_icons 0.1.3. + static const IconData square_arrow_up = IconData(0xf4ca, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_up_fill — Cupertino icon named "square_arrow_up_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [share_solid] which is available in cupertino_icons 0.1.3. + static const IconData square_arrow_up_fill = IconData(0xf4cb, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_up_on_square — Cupertino icon named "square_arrow_up_on_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_arrow_up_on_square = IconData(0xf7fd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_arrow_up_on_square_fill — Cupertino icon named "square_arrow_up_on_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_arrow_up_on_square_fill = IconData(0xf7fe, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_favorites — Cupertino icon named "square_favorites". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_favorites = IconData(0xf910, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_favorites_alt — Cupertino icon named "square_favorites_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_favorites_alt = IconData(0xf911, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_favorites_alt_fill — Cupertino icon named "square_favorites_alt_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_favorites_alt_fill = IconData(0xf912, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_favorites_fill — Cupertino icon named "square_favorites_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_favorites_fill = IconData(0xf913, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_fill — Cupertino icon named "square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_fill = IconData(0xf7ff, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_fill_line_vertical_square — Cupertino icon named "square_fill_line_vertical_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_fill_line_vertical_square = IconData(0xf800, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_fill_line_vertical_square_fill — Cupertino icon named "square_fill_line_vertical_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_fill_line_vertical_square_fill = IconData(0xf801, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_fill_on_circle_fill — Cupertino icon named "square_fill_on_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_fill_on_circle_fill = IconData(0xf802, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_fill_on_square_fill — Cupertino icon named "square_fill_on_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_fill_on_square_fill = IconData(0xf803, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_grid_2x2 — Cupertino icon named "square_grid_2x2". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_grid_2x2 = IconData(0xf804, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_grid_2x2_fill — Cupertino icon named "square_grid_2x2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_grid_2x2_fill = IconData(0xf805, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_grid_3x2 — Cupertino icon named "square_grid_3x2". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_grid_3x2 = IconData(0xf806, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_grid_3x2_fill — Cupertino icon named "square_grid_3x2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_grid_3x2_fill = IconData(0xf807, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_grid_4x3_fill — Cupertino icon named "square_grid_4x3_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_grid_4x3_fill = IconData(0xf808, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_lefthalf_fill — Cupertino icon named "square_lefthalf_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_lefthalf_fill = IconData(0xf809, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_line_vertical_square — Cupertino icon named "square_line_vertical_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_line_vertical_square = IconData(0xf80a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_line_vertical_square_fill — Cupertino icon named "square_line_vertical_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_line_vertical_square_fill = IconData(0xf80b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_list — Cupertino icon named "square_list". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_list = IconData(0xf914, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_list_fill — Cupertino icon named "square_list_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_list_fill = IconData(0xf915, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_on_circle — Cupertino icon named "square_on_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_on_circle = IconData(0xf80c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_on_square — Cupertino icon named "square_on_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_on_square = IconData(0xf80d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_pencil — Cupertino icon named "square_pencil". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [create] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [create_solid] which is available in cupertino_icons 0.1.3. + static const IconData square_pencil = IconData(0xf417, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_pencil_fill — Cupertino icon named "square_pencil_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [create] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [create_solid] which is available in cupertino_icons 0.1.3. + static const IconData square_pencil_fill = IconData(0xf417, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_righthalf_fill — Cupertino icon named "square_righthalf_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_righthalf_fill = IconData(0xf80e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_split_1x2 — Cupertino icon named "square_split_1x2". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_split_1x2 = IconData(0xf80f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_split_1x2_fill — Cupertino icon named "square_split_1x2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_split_1x2_fill = IconData(0xf810, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_split_2x1 — Cupertino icon named "square_split_2x1". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_split_2x1 = IconData(0xf811, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_split_2x1_fill — Cupertino icon named "square_split_2x1_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_split_2x1_fill = IconData(0xf812, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_split_2x2 — Cupertino icon named "square_split_2x2". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_split_2x2 = IconData(0xf813, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_split_2x2_fill — Cupertino icon named "square_split_2x2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_split_2x2_fill = IconData(0xf814, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_stack — Cupertino icon named "square_stack". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_stack = IconData(0xf815, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_stack_3d_down_dottedline — Cupertino icon named "square_stack_3d_down_dottedline". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_stack_3d_down_dottedline = IconData(0xf816, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_stack_3d_down_right — Cupertino icon named "square_stack_3d_down_right". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_stack_3d_down_right = IconData(0xf817, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_stack_3d_down_right_fill — Cupertino icon named "square_stack_3d_down_right_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_stack_3d_down_right_fill = IconData(0xf818, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_stack_3d_up — Cupertino icon named "square_stack_3d_up". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_stack_3d_up = IconData(0xf819, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_stack_3d_up_fill — Cupertino icon named "square_stack_3d_up_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_stack_3d_up_fill = IconData(0xf81a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_stack_3d_up_slash — Cupertino icon named "square_stack_3d_up_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_stack_3d_up_slash = IconData(0xf81b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_stack_3d_up_slash_fill — Cupertino icon named "square_stack_3d_up_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_stack_3d_up_slash_fill = IconData(0xf81c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// square_stack_fill — Cupertino icon named "square_stack_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData square_stack_fill = IconData(0xf81d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// squares_below_rectangle — Cupertino icon named "squares_below_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData squares_below_rectangle = IconData(0xf81e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// star — Cupertino icon named "star". Available on cupertino_icons package 1.0.0+ only. + static const IconData star = IconData(0xf81f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// star_circle — Cupertino icon named "star_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData star_circle = IconData(0xf820, fontFamily: iconFont, fontPackage: iconFontPackage); + /// star_circle_fill — Cupertino icon named "star_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData star_circle_fill = IconData(0xf821, fontFamily: iconFont, fontPackage: iconFontPackage); + /// star_fill — Cupertino icon named "star_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData star_fill = IconData(0xf822, fontFamily: iconFont, fontPackage: iconFontPackage); + /// star_lefthalf_fill — Cupertino icon named "star_lefthalf_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData star_lefthalf_fill = IconData(0xf823, fontFamily: iconFont, fontPackage: iconFontPackage); + /// star_slash — Cupertino icon named "star_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData star_slash = IconData(0xf824, fontFamily: iconFont, fontPackage: iconFontPackage); + /// star_slash_fill — Cupertino icon named "star_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData star_slash_fill = IconData(0xf825, fontFamily: iconFont, fontPackage: iconFontPackage); + /// staroflife — Cupertino icon named "staroflife". Available on cupertino_icons package 1.0.0+ only. + static const IconData staroflife = IconData(0xf826, fontFamily: iconFont, fontPackage: iconFontPackage); + /// staroflife_fill — Cupertino icon named "staroflife_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData staroflife_fill = IconData(0xf827, fontFamily: iconFont, fontPackage: iconFontPackage); + /// stop — Cupertino icon named "stop". Available on cupertino_icons package 1.0.0+ only. + static const IconData stop = IconData(0xf828, fontFamily: iconFont, fontPackage: iconFontPackage); + /// stop_circle — Cupertino icon named "stop_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData stop_circle = IconData(0xf829, fontFamily: iconFont, fontPackage: iconFontPackage); + /// stop_circle_fill — Cupertino icon named "stop_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData stop_circle_fill = IconData(0xf82a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// stop_fill — Cupertino icon named "stop_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData stop_fill = IconData(0xf82b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// stopwatch — Cupertino icon named "stopwatch". Available on cupertino_icons package 1.0.0+ only. + static const IconData stopwatch = IconData(0xf82c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// stopwatch_fill — Cupertino icon named "stopwatch_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData stopwatch_fill = IconData(0xf82d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// strikethrough — Cupertino icon named "strikethrough". Available on cupertino_icons package 1.0.0+ only. + static const IconData strikethrough = IconData(0xf82e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// suit_club — Cupertino icon named "suit_club". Available on cupertino_icons package 1.0.0+ only. + static const IconData suit_club = IconData(0xf82f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// suit_club_fill — Cupertino icon named "suit_club_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData suit_club_fill = IconData(0xf830, fontFamily: iconFont, fontPackage: iconFontPackage); + /// suit_diamond — Cupertino icon named "suit_diamond". Available on cupertino_icons package 1.0.0+ only. + static const IconData suit_diamond = IconData(0xf831, fontFamily: iconFont, fontPackage: iconFontPackage); + /// suit_diamond_fill — Cupertino icon named "suit_diamond_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData suit_diamond_fill = IconData(0xf832, fontFamily: iconFont, fontPackage: iconFontPackage); + /// suit_heart — Cupertino icon named "suit_heart". Available on cupertino_icons package 1.0.0+ only. + static const IconData suit_heart = IconData(0xf833, fontFamily: iconFont, fontPackage: iconFontPackage); + /// suit_heart_fill — Cupertino icon named "suit_heart_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData suit_heart_fill = IconData(0xf834, fontFamily: iconFont, fontPackage: iconFontPackage); + /// suit_spade — Cupertino icon named "suit_spade". Available on cupertino_icons package 1.0.0+ only. + static const IconData suit_spade = IconData(0xf835, fontFamily: iconFont, fontPackage: iconFontPackage); + /// suit_spade_fill — Cupertino icon named "suit_spade_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData suit_spade_fill = IconData(0xf836, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sum — Cupertino icon named "sum". Available on cupertino_icons package 1.0.0+ only. + static const IconData sum = IconData(0xf837, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sun_dust — Cupertino icon named "sun_dust". Available on cupertino_icons package 1.0.0+ only. + static const IconData sun_dust = IconData(0xf838, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sun_dust_fill — Cupertino icon named "sun_dust_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData sun_dust_fill = IconData(0xf839, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sun_haze — Cupertino icon named "sun_haze". Available on cupertino_icons package 1.0.0+ only. + static const IconData sun_haze = IconData(0xf83a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sun_haze_fill — Cupertino icon named "sun_haze_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData sun_haze_fill = IconData(0xf83b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sun_max — Cupertino icon named "sun_max". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [brightness] which is available in cupertino_icons 0.1.3. + static const IconData sun_max = IconData(0xf4b6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sun_max_fill — Cupertino icon named "sun_max_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [brightness_solid] which is available in cupertino_icons 0.1.3. + static const IconData sun_max_fill = IconData(0xf4b7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sun_min — Cupertino icon named "sun_min". Available on cupertino_icons package 1.0.0+ only. + static const IconData sun_min = IconData(0xf83c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sun_min_fill — Cupertino icon named "sun_min_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData sun_min_fill = IconData(0xf83d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sunrise — Cupertino icon named "sunrise". Available on cupertino_icons package 1.0.0+ only. + static const IconData sunrise = IconData(0xf83e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sunrise_fill — Cupertino icon named "sunrise_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData sunrise_fill = IconData(0xf83f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sunset — Cupertino icon named "sunset". Available on cupertino_icons package 1.0.0+ only. + static const IconData sunset = IconData(0xf840, fontFamily: iconFont, fontPackage: iconFontPackage); + /// sunset_fill — Cupertino icon named "sunset_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData sunset_fill = IconData(0xf841, fontFamily: iconFont, fontPackage: iconFontPackage); + /// t_bubble — Cupertino icon named "t_bubble". Available on cupertino_icons package 1.0.0+ only. + static const IconData t_bubble = IconData(0xf842, fontFamily: iconFont, fontPackage: iconFontPackage); + /// t_bubble_fill — Cupertino icon named "t_bubble_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData t_bubble_fill = IconData(0xf843, fontFamily: iconFont, fontPackage: iconFontPackage); + /// table — Cupertino icon named "table". Available on cupertino_icons package 1.0.0+ only. + static const IconData table = IconData(0xf844, fontFamily: iconFont, fontPackage: iconFontPackage); + /// table_badge_more — Cupertino icon named "table_badge_more". Available on cupertino_icons package 1.0.0+ only. + static const IconData table_badge_more = IconData(0xf845, fontFamily: iconFont, fontPackage: iconFontPackage); + /// table_badge_more_fill — Cupertino icon named "table_badge_more_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData table_badge_more_fill = IconData(0xf846, fontFamily: iconFont, fontPackage: iconFontPackage); + /// table_fill — Cupertino icon named "table_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData table_fill = IconData(0xf847, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tag_circle — Cupertino icon named "tag_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData tag_circle = IconData(0xf848, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tag_circle_fill — Cupertino icon named "tag_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tag_circle_fill = IconData(0xf849, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tag_fill — Cupertino icon named "tag_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [tag_solid] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [tags_solid] which is available in cupertino_icons 0.1.3. + static const IconData tag_fill = IconData(0xf48d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_aligncenter — Cupertino icon named "text_aligncenter". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_aligncenter = IconData(0xf84a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_alignleft — Cupertino icon named "text_alignleft". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_alignleft = IconData(0xf84b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_alignright — Cupertino icon named "text_alignright". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_alignright = IconData(0xf84c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_append — Cupertino icon named "text_append". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_append = IconData(0xf84d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_badge_checkmark — Cupertino icon named "text_badge_checkmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_badge_checkmark = IconData(0xf84e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_badge_minus — Cupertino icon named "text_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_badge_minus = IconData(0xf84f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_badge_plus — Cupertino icon named "text_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_badge_plus = IconData(0xf850, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_badge_star — Cupertino icon named "text_badge_star". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_badge_star = IconData(0xf851, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_badge_xmark — Cupertino icon named "text_badge_xmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_badge_xmark = IconData(0xf852, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_bubble — Cupertino icon named "text_bubble". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_bubble = IconData(0xf853, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_bubble_fill — Cupertino icon named "text_bubble_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_bubble_fill = IconData(0xf854, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_cursor — Cupertino icon named "text_cursor". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_cursor = IconData(0xf855, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_insert — Cupertino icon named "text_insert". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_insert = IconData(0xf856, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_justify — Cupertino icon named "text_justify". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_justify = IconData(0xf857, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_justifyleft — Cupertino icon named "text_justifyleft". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_justifyleft = IconData(0xf858, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_justifyright — Cupertino icon named "text_justifyright". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_justifyright = IconData(0xf859, fontFamily: iconFont, fontPackage: iconFontPackage); + /// text_quote — Cupertino icon named "text_quote". Available on cupertino_icons package 1.0.0+ only. + static const IconData text_quote = IconData(0xf85a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// textbox — Cupertino icon named "textbox". Available on cupertino_icons package 1.0.0+ only. + static const IconData textbox = IconData(0xf85b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// textformat — Cupertino icon named "textformat". Available on cupertino_icons package 1.0.0+ only. + static const IconData textformat = IconData(0xf85c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// textformat_123 — Cupertino icon named "textformat_123". Available on cupertino_icons package 1.0.0+ only. + static const IconData textformat_123 = IconData(0xf85d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// textformat_abc — Cupertino icon named "textformat_abc". Available on cupertino_icons package 1.0.0+ only. + static const IconData textformat_abc = IconData(0xf85e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// textformat_abc_dottedunderline — Cupertino icon named "textformat_abc_dottedunderline". Available on cupertino_icons package 1.0.0+ only. + static const IconData textformat_abc_dottedunderline = IconData(0xf85f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// textformat_alt — Cupertino icon named "textformat_alt". Available on cupertino_icons package 1.0.0+ only. + static const IconData textformat_alt = IconData(0xf860, fontFamily: iconFont, fontPackage: iconFontPackage); + /// textformat_size — Cupertino icon named "textformat_size". Available on cupertino_icons package 1.0.0+ only. + static const IconData textformat_size = IconData(0xf861, fontFamily: iconFont, fontPackage: iconFontPackage); + /// textformat_subscript — Cupertino icon named "textformat_subscript". Available on cupertino_icons package 1.0.0+ only. + static const IconData textformat_subscript = IconData(0xf862, fontFamily: iconFont, fontPackage: iconFontPackage); + /// textformat_superscript — Cupertino icon named "textformat_superscript". Available on cupertino_icons package 1.0.0+ only. + static const IconData textformat_superscript = IconData(0xf863, fontFamily: iconFont, fontPackage: iconFontPackage); + /// thermometer — Cupertino icon named "thermometer". Available on cupertino_icons package 1.0.0+ only. + static const IconData thermometer = IconData(0xf864, fontFamily: iconFont, fontPackage: iconFontPackage); + /// thermometer_snowflake — Cupertino icon named "thermometer_snowflake". Available on cupertino_icons package 1.0.0+ only. + static const IconData thermometer_snowflake = IconData(0xf865, fontFamily: iconFont, fontPackage: iconFontPackage); + /// thermometer_sun — Cupertino icon named "thermometer_sun". Available on cupertino_icons package 1.0.0+ only. + static const IconData thermometer_sun = IconData(0xf866, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ticket — Cupertino icon named "ticket". Available on cupertino_icons package 1.0.0+ only. + static const IconData ticket = IconData(0xf916, fontFamily: iconFont, fontPackage: iconFontPackage); + /// ticket_fill — Cupertino icon named "ticket_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData ticket_fill = IconData(0xf917, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tickets — Cupertino icon named "tickets". Available on cupertino_icons package 1.0.0+ only. + static const IconData tickets = IconData(0xf918, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tickets_fill — Cupertino icon named "tickets_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tickets_fill = IconData(0xf919, fontFamily: iconFont, fontPackage: iconFontPackage); + /// timelapse — Cupertino icon named "timelapse". Available on cupertino_icons package 1.0.0+ only. + static const IconData timelapse = IconData(0xf867, fontFamily: iconFont, fontPackage: iconFontPackage); + /// timer — Cupertino icon named "timer". Available on cupertino_icons package 1.0.0+ only. + static const IconData timer = IconData(0xf868, fontFamily: iconFont, fontPackage: iconFontPackage); + /// timer_fill — Cupertino icon named "timer_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData timer_fill = IconData(0xf91a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// today — Cupertino icon named "today". Available on cupertino_icons package 1.0.0+ only. + static const IconData today = IconData(0xf91b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// today_fill — Cupertino icon named "today_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData today_fill = IconData(0xf91c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tornado — Cupertino icon named "tornado". Available on cupertino_icons package 1.0.0+ only. + static const IconData tornado = IconData(0xf869, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tortoise — Cupertino icon named "tortoise". Available on cupertino_icons package 1.0.0+ only. + static const IconData tortoise = IconData(0xf86a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tortoise_fill — Cupertino icon named "tortoise_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tortoise_fill = IconData(0xf86b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tram_fill — Cupertino icon named "tram_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tram_fill = IconData(0xf86c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// trash — Cupertino icon named "trash". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [delete] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [delete_simple] which is available in cupertino_icons 0.1.3. + static const IconData trash = IconData(0xf4c4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// trash_circle — Cupertino icon named "trash_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData trash_circle = IconData(0xf86d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// trash_circle_fill — Cupertino icon named "trash_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData trash_circle_fill = IconData(0xf86e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// trash_fill — Cupertino icon named "trash_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [delete_solid] which is available in cupertino_icons 0.1.3. + static const IconData trash_fill = IconData(0xf4c5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// trash_slash — Cupertino icon named "trash_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData trash_slash = IconData(0xf86f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// trash_slash_fill — Cupertino icon named "trash_slash_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData trash_slash_fill = IconData(0xf870, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tray — Cupertino icon named "tray". Available on cupertino_icons package 1.0.0+ only. + static const IconData tray = IconData(0xf871, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tray_2 — Cupertino icon named "tray_2". Available on cupertino_icons package 1.0.0+ only. + static const IconData tray_2 = IconData(0xf872, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tray_2_fill — Cupertino icon named "tray_2_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tray_2_fill = IconData(0xf873, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tray_arrow_down — Cupertino icon named "tray_arrow_down". Available on cupertino_icons package 1.0.0+ only. + static const IconData tray_arrow_down = IconData(0xf874, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tray_arrow_down_fill — Cupertino icon named "tray_arrow_down_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tray_arrow_down_fill = IconData(0xf875, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tray_arrow_up — Cupertino icon named "tray_arrow_up". Available on cupertino_icons package 1.0.0+ only. + static const IconData tray_arrow_up = IconData(0xf876, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tray_arrow_up_fill — Cupertino icon named "tray_arrow_up_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tray_arrow_up_fill = IconData(0xf877, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tray_fill — Cupertino icon named "tray_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tray_fill = IconData(0xf878, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tray_full — Cupertino icon named "tray_full". Available on cupertino_icons package 1.0.0+ only. + static const IconData tray_full = IconData(0xf879, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tray_full_fill — Cupertino icon named "tray_full_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tray_full_fill = IconData(0xf87a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tree — Cupertino icon named "tree". Available on cupertino_icons package 1.0.0+ only. + static const IconData tree = IconData(0xf91d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// triangle — Cupertino icon named "triangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData triangle = IconData(0xf87b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// triangle_fill — Cupertino icon named "triangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData triangle_fill = IconData(0xf87c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// triangle_lefthalf_fill — Cupertino icon named "triangle_lefthalf_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData triangle_lefthalf_fill = IconData(0xf87d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// triangle_righthalf_fill — Cupertino icon named "triangle_righthalf_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData triangle_righthalf_fill = IconData(0xf87e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tropicalstorm — Cupertino icon named "tropicalstorm". Available on cupertino_icons package 1.0.0+ only. + static const IconData tropicalstorm = IconData(0xf87f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tuningfork — Cupertino icon named "tuningfork". Available on cupertino_icons package 1.0.0+ only. + static const IconData tuningfork = IconData(0xf880, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tv — Cupertino icon named "tv". Available on cupertino_icons package 1.0.0+ only. + static const IconData tv = IconData(0xf881, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tv_circle — Cupertino icon named "tv_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData tv_circle = IconData(0xf882, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tv_circle_fill — Cupertino icon named "tv_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tv_circle_fill = IconData(0xf883, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tv_fill — Cupertino icon named "tv_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tv_fill = IconData(0xf884, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tv_music_note — Cupertino icon named "tv_music_note". Available on cupertino_icons package 1.0.0+ only. + static const IconData tv_music_note = IconData(0xf885, fontFamily: iconFont, fontPackage: iconFontPackage); + /// tv_music_note_fill — Cupertino icon named "tv_music_note_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData tv_music_note_fill = IconData(0xf886, fontFamily: iconFont, fontPackage: iconFontPackage); + /// uiwindow_split_2x1 — Cupertino icon named "uiwindow_split_2x1". Available on cupertino_icons package 1.0.0+ only. + static const IconData uiwindow_split_2x1 = IconData(0xf887, fontFamily: iconFont, fontPackage: iconFontPackage); + /// umbrella — Cupertino icon named "umbrella". Available on cupertino_icons package 1.0.0+ only. + static const IconData umbrella = IconData(0xf888, fontFamily: iconFont, fontPackage: iconFontPackage); + /// umbrella_fill — Cupertino icon named "umbrella_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData umbrella_fill = IconData(0xf889, fontFamily: iconFont, fontPackage: iconFontPackage); + /// underline — Cupertino icon named "underline". Available on cupertino_icons package 1.0.0+ only. + static const IconData underline = IconData(0xf88a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// upload_circle — Cupertino icon named "upload_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData upload_circle = IconData(0xf91e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// upload_circle_fill — Cupertino icon named "upload_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData upload_circle_fill = IconData(0xf91f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// videocam — Cupertino icon named "videocam". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [video_camera] which is available in cupertino_icons 0.1.3. + static const IconData videocam = IconData(0xf4cc, fontFamily: iconFont, fontPackage: iconFontPackage); + /// videocam_circle — Cupertino icon named "videocam_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData videocam_circle = IconData(0xf920, fontFamily: iconFont, fontPackage: iconFontPackage); + /// videocam_circle_fill — Cupertino icon named "videocam_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData videocam_circle_fill = IconData(0xf921, fontFamily: iconFont, fontPackage: iconFontPackage); + /// videocam_fill — Cupertino icon named "videocam_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [video_camera_solid] which is available in cupertino_icons 0.1.3. + static const IconData videocam_fill = IconData(0xf4cd, fontFamily: iconFont, fontPackage: iconFontPackage); + /// view_2d — Cupertino icon named "view_2d". Available on cupertino_icons package 1.0.0+ only. + static const IconData view_2d = IconData(0xf88b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// view_3d — Cupertino icon named "view_3d". Available on cupertino_icons package 1.0.0+ only. + static const IconData view_3d = IconData(0xf88c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// viewfinder — Cupertino icon named "viewfinder". Available on cupertino_icons package 1.0.0+ only. + static const IconData viewfinder = IconData(0xf88d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// viewfinder_circle — Cupertino icon named "viewfinder_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData viewfinder_circle = IconData(0xf88e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// viewfinder_circle_fill — Cupertino icon named "viewfinder_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData viewfinder_circle_fill = IconData(0xf88f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wand_rays — Cupertino icon named "wand_rays". Available on cupertino_icons package 1.0.0+ only. + static const IconData wand_rays = IconData(0xf890, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wand_rays_inverse — Cupertino icon named "wand_rays_inverse". Available on cupertino_icons package 1.0.0+ only. + static const IconData wand_rays_inverse = IconData(0xf891, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wand_stars — Cupertino icon named "wand_stars". Available on cupertino_icons package 1.0.0+ only. + static const IconData wand_stars = IconData(0xf892, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wand_stars_inverse — Cupertino icon named "wand_stars_inverse". Available on cupertino_icons package 1.0.0+ only. + static const IconData wand_stars_inverse = IconData(0xf893, fontFamily: iconFont, fontPackage: iconFontPackage); + /// waveform — Cupertino icon named "waveform". Available on cupertino_icons package 1.0.0+ only. + static const IconData waveform = IconData(0xf894, fontFamily: iconFont, fontPackage: iconFontPackage); + /// waveform_circle — Cupertino icon named "waveform_circle". Available on cupertino_icons package 1.0.0+ only. + static const IconData waveform_circle = IconData(0xf895, fontFamily: iconFont, fontPackage: iconFontPackage); + /// waveform_circle_fill — Cupertino icon named "waveform_circle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData waveform_circle_fill = IconData(0xf896, fontFamily: iconFont, fontPackage: iconFontPackage); + /// waveform_path — Cupertino icon named "waveform_path". Available on cupertino_icons package 1.0.0+ only. + static const IconData waveform_path = IconData(0xf897, fontFamily: iconFont, fontPackage: iconFontPackage); + /// waveform_path_badge_minus — Cupertino icon named "waveform_path_badge_minus". Available on cupertino_icons package 1.0.0+ only. + static const IconData waveform_path_badge_minus = IconData(0xf898, fontFamily: iconFont, fontPackage: iconFontPackage); + /// waveform_path_badge_plus — Cupertino icon named "waveform_path_badge_plus". Available on cupertino_icons package 1.0.0+ only. + static const IconData waveform_path_badge_plus = IconData(0xf899, fontFamily: iconFont, fontPackage: iconFontPackage); + /// waveform_path_ecg — Cupertino icon named "waveform_path_ecg". Available on cupertino_icons package 1.0.0+ only. + static const IconData waveform_path_ecg = IconData(0xf89a, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wifi — Cupertino icon named "wifi". Available on cupertino_icons package 1.0.0+ only. + static const IconData wifi = IconData(0xf89b, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wifi_exclamationmark — Cupertino icon named "wifi_exclamationmark". Available on cupertino_icons package 1.0.0+ only. + static const IconData wifi_exclamationmark = IconData(0xf89c, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wifi_slash — Cupertino icon named "wifi_slash". Available on cupertino_icons package 1.0.0+ only. + static const IconData wifi_slash = IconData(0xf89d, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wind — Cupertino icon named "wind". Available on cupertino_icons package 1.0.0+ only. + static const IconData wind = IconData(0xf89e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wind_snow — Cupertino icon named "wind_snow". Available on cupertino_icons package 1.0.0+ only. + static const IconData wind_snow = IconData(0xf89f, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wrench — Cupertino icon named "wrench". Available on cupertino_icons package 1.0.0+ only. + static const IconData wrench = IconData(0xf8a0, fontFamily: iconFont, fontPackage: iconFontPackage); + /// wrench_fill — Cupertino icon named "wrench_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData wrench_fill = IconData(0xf8a1, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark — Cupertino icon named "xmark". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [clear_thick] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [clear] which is available in cupertino_icons 0.1.3. + static const IconData xmark = IconData(0xf404, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_circle — Cupertino icon named "xmark_circle". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [clear_circled] which is available in cupertino_icons 0.1.3. + static const IconData xmark_circle = IconData(0xf405, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_circle_fill — Cupertino icon named "xmark_circle_fill". Available on cupertino_icons package 1.0.0+ only. + /// This is the same icon as [clear_thick_circled] which is available in cupertino_icons 0.1.3. + /// This is the same icon as [clear_circled_solid] which is available in cupertino_icons 0.1.3. + static const IconData xmark_circle_fill = IconData(0xf36e, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_octagon — Cupertino icon named "xmark_octagon". Available on cupertino_icons package 1.0.0+ only. + static const IconData xmark_octagon = IconData(0xf8a2, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_octagon_fill — Cupertino icon named "xmark_octagon_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData xmark_octagon_fill = IconData(0xf8a3, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_rectangle — Cupertino icon named "xmark_rectangle". Available on cupertino_icons package 1.0.0+ only. + static const IconData xmark_rectangle = IconData(0xf8a4, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_rectangle_fill — Cupertino icon named "xmark_rectangle_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData xmark_rectangle_fill = IconData(0xf8a5, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_seal — Cupertino icon named "xmark_seal". Available on cupertino_icons package 1.0.0+ only. + static const IconData xmark_seal = IconData(0xf8a6, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_seal_fill — Cupertino icon named "xmark_seal_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData xmark_seal_fill = IconData(0xf8a7, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_shield — Cupertino icon named "xmark_shield". Available on cupertino_icons package 1.0.0+ only. + static const IconData xmark_shield = IconData(0xf8a8, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_shield_fill — Cupertino icon named "xmark_shield_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData xmark_shield_fill = IconData(0xf8a9, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_square — Cupertino icon named "xmark_square". Available on cupertino_icons package 1.0.0+ only. + static const IconData xmark_square = IconData(0xf8aa, fontFamily: iconFont, fontPackage: iconFontPackage); + /// xmark_square_fill — Cupertino icon named "xmark_square_fill". Available on cupertino_icons package 1.0.0+ only. + static const IconData xmark_square_fill = IconData(0xf8ab, fontFamily: iconFont, fontPackage: iconFontPackage); + /// zoom_in — Cupertino icon named "zoom_in". Available on cupertino_icons package 1.0.0+ only. + static const IconData zoom_in = IconData(0xf8ac, fontFamily: iconFont, fontPackage: iconFontPackage); + /// zoom_out — Cupertino icon named "zoom_out". Available on cupertino_icons package 1.0.0+ only. + static const IconData zoom_out = IconData(0xf8ad, fontFamily: iconFont, fontPackage: iconFontPackage); + /// zzz — Cupertino icon named "zzz". Available on cupertino_icons package 1.0.0+ only. + static const IconData zzz = IconData(0xf8ae, fontFamily: iconFont, fontPackage: iconFontPackage); + // END GENERATED SF SYMBOLS NAMES + // =========================================================================== +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/interface_level.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/interface_level.dart new file mode 100644 index 0000000000000000000000000000000000000000..e4de7829a17363d7007dbcb4cc4e2f38b172f597 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/interface_level.dart @@ -0,0 +1,108 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import '../widgets/framework.dart'; + +/// Indicates the visual level for a piece of content. Equivalent to `UIUserInterfaceLevel` +/// from `UIKit`. +/// +/// See also: +/// +/// * `UIUserInterfaceLevel`, the UIKit equivalent: https://developer.apple.com/documentation/uikit/uiuserinterfacelevel. +enum CupertinoUserInterfaceLevelData { + /// The level for your window's main content. + base, + + /// The level for content visually above [base]. + elevated, +} + +/// Establishes a subtree in which [CupertinoUserInterfaceLevel.of] resolves to +/// the given visual elevation from the [CupertinoUserInterfaceLevelData]. This +/// can be used to apply style differences based on a widget's elevation. +/// +/// Querying the current elevation status using [CupertinoUserInterfaceLevel.of] +/// will cause your widget to rebuild automatically whenever the +/// [CupertinoUserInterfaceLevelData] changes. +/// +/// If no [CupertinoUserInterfaceLevel] is in scope then the +/// [CupertinoUserInterfaceLevel.of] method will throw an exception. +/// Alternatively, [CupertinoUserInterfaceLevel.maybeOf] can be used, which +/// returns null instead of throwing if no [CupertinoUserInterfaceLevel] is in +/// scope. +/// +/// See also: +/// +/// * [CupertinoUserInterfaceLevelData], specifies the visual level for the content +/// in the subtree [CupertinoUserInterfaceLevel] established. +class CupertinoUserInterfaceLevel extends InheritedWidget { + /// Creates a [CupertinoUserInterfaceLevel] to change descendant Cupertino widget's + /// visual level. + const CupertinoUserInterfaceLevel({ + super.key, + required CupertinoUserInterfaceLevelData data, + required super.child, + }) : _data = data; + + final CupertinoUserInterfaceLevelData _data; + + @override + bool updateShouldNotify(CupertinoUserInterfaceLevel oldWidget) => oldWidget._data != _data; + + /// The data from the closest instance of this class that encloses the given + /// context. + /// + /// You can use this function to query the user interface elevation level within + /// the given [BuildContext]. When that information changes, your widget will + /// be scheduled to be rebuilt, keeping your widget up-to-date. + /// + /// See also: + /// + /// * [maybeOf], which is similar, but will return null if no + /// [CupertinoUserInterfaceLevel] encloses the given context. + static CupertinoUserInterfaceLevelData of(BuildContext context) { + final CupertinoUserInterfaceLevel? query = context.dependOnInheritedWidgetOfExactType(); + if (query != null) { + return query._data; + } + throw FlutterError( + 'CupertinoUserInterfaceLevel.of() called with a context that does not contain a CupertinoUserInterfaceLevel.\n' + 'No CupertinoUserInterfaceLevel ancestor could be found starting from the context that was passed ' + 'to CupertinoUserInterfaceLevel.of(). This can happen because you do not have a WidgetsApp or ' + 'MaterialApp widget (those widgets introduce a CupertinoUserInterfaceLevel), or it can happen ' + 'if the context you use comes from a widget above those widgets.\n' + 'The context used was:\n' + ' $context', + ); + } + + /// The data from the closest instance of this class that encloses the given + /// context, if there is one. + /// + /// Returns null if no [CupertinoUserInterfaceLevel] encloses the given context. + /// + /// You can use this function to query the user interface elevation level within + /// the given [BuildContext]. When that information changes, your widget will + /// be scheduled to be rebuilt, keeping your widget up-to-date. + /// + /// See also: + /// + /// * [of], which is similar, but will throw an exception if no + /// [CupertinoUserInterfaceLevel] encloses the given context. + static CupertinoUserInterfaceLevelData? maybeOf(BuildContext context) { + final CupertinoUserInterfaceLevel? query = context.dependOnInheritedWidgetOfExactType(); + if (query != null) { + return query._data; + } + return null; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty('user interface level', _data)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/list_section.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/list_section.dart new file mode 100644 index 0000000000000000000000000000000000000000..9568f9bcacbcbc8639b7c2da34a9b9c793f30baf --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/list_section.dart @@ -0,0 +1,489 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'theme.dart'; + +// Margin on top of the list section. This was eyeballed from iOS 14.4 Simulator +// and should be always present on top of the edge-to-edge variant. +const double _kMarginTop = 22.0; + +// Standard header margin, determined from SwiftUI's Forms in iOS 14.2 SDK. +const EdgeInsetsDirectional _kDefaultHeaderMargin = EdgeInsetsDirectional.fromSTEB(20.0, 0.0, 20.0, 6.0); + +// Header margin for inset grouped variant, determined from iOS 14.4 Simulator. +const EdgeInsetsDirectional _kInsetGroupedDefaultHeaderMargin = EdgeInsetsDirectional.fromSTEB(20.0, 16.0, 20.0, 6.0); + +// Standard footer margin, determined from SwiftUI's Forms in iOS 14.2 SDK. +const EdgeInsetsDirectional _kDefaultFooterMargin = EdgeInsetsDirectional.fromSTEB(20.0, 0.0, 20.0, 0.0); + +// Footer margin for inset grouped variant, determined from iOS 14.4 Simulator. +const EdgeInsetsDirectional _kInsetGroupedDefaultFooterMargin = EdgeInsetsDirectional.fromSTEB(20.0, 0.0, 20.0, 10.0); + +// Margin around children in edge-to-edge variant, determined from iOS 14.4 +// Simulator. +const EdgeInsets _kDefaultRowsMargin = EdgeInsets.only(bottom: 8.0); + +// Used for iOS "Inset Grouped" margin, determined from SwiftUI's Forms in +// iOS 14.2 SDK. +const EdgeInsetsDirectional _kDefaultInsetGroupedRowsMargin = EdgeInsetsDirectional.fromSTEB(20.0, 20.0, 20.0, 10.0); + +// Used for iOS "Inset Grouped" margin, determined from SwiftUI's Forms in +// iOS 14.2 SDK. +const EdgeInsetsDirectional _kDefaultInsetGroupedRowsMarginWithHeader = EdgeInsetsDirectional.fromSTEB(20.0, 0.0, 20.0, 10.0); + +// Used for iOS "Inset Grouped" border radius, estimated from SwiftUI's Forms in +// iOS 14.2 SDK. +// TODO(edrisian): This should be a rounded rectangle once that shape is added. +const BorderRadius _kDefaultInsetGroupedBorderRadius = BorderRadius.all(Radius.circular(10.0)); + +// The margin of divider used in base list section. Estimated from iOS 14.4 SDK +// Settings app. +const double _kBaseDividerMargin = 20.0; + +// Additional margin of divider used in base list section with list tiles with +// leading widgets. Estimated from iOS 14.4 SDK Settings app. +const double _kBaseAdditionalDividerMargin = 44.0; + +// The margin of divider used in inset grouped version of list section. +// Estimated from iOS 14.4 SDK Reminders app. +const double _kInsetDividerMargin = 14.0; + +// Additional margin of divider used in inset grouped version of list section. +// Estimated from iOS 14.4 SDK Reminders app. +const double _kInsetAdditionalDividerMargin = 42.0; + +// Additional margin of divider used in inset grouped version of list section +// when there is no leading widgets. Estimated from iOS 14.4 SDK Notes app. +const double _kInsetAdditionalDividerMarginWithoutLeading = 14.0; + +// Color of header and footer text in edge-to-edge variant. +const Color _kHeaderFooterColor = CupertinoDynamicColor( + color: Color.fromRGBO(108, 108, 108, 1.0), + darkColor: Color.fromRGBO(142, 142, 146, 1.0), + highContrastColor: Color.fromRGBO(74, 74, 77, 1.0), + darkHighContrastColor: Color.fromRGBO(176, 176, 183, 1.0), + elevatedColor: Color.fromRGBO(108, 108, 108, 1.0), + darkElevatedColor: Color.fromRGBO(142, 142, 146, 1.0), + highContrastElevatedColor: Color.fromRGBO(108, 108, 108, 1.0), + darkHighContrastElevatedColor: Color.fromRGBO(142, 142, 146, 1.0), +); + +/// Denotes what type of the list section a [CupertinoListSection] is. +/// +/// This is for internal use only. +enum CupertinoListSectionType { + /// A basic form of [CupertinoListSection]. + base, + + /// An inset-grouped style of [CupertinoListSection]. + insetGrouped, +} + +/// An iOS-style list section. +/// +/// The [CupertinoListSection] is a container for children widgets. These are +/// most often [CupertinoListTile]s. +/// +/// The base constructor for [CupertinoListSection] constructs an +/// edge-to-edge style section which includes an iOS-style header, the dividers +/// between rows, and borders on top and bottom of the rows. An example of such +/// list section are sections in iOS Settings app. +/// +/// The [CupertinoListSection.insetGrouped] constructor creates a round-edged +/// and padded section that is seen in iOS Notes and Reminders apps. It creates +/// an iOS-style header, and the dividers between rows. Does not create borders +/// on top and bottom of the rows. +/// +/// The section [header] lies above the [children] rows, with margins and style +/// that match the iOS style. +/// +/// The section [footer] lies below the [children] rows and is used to provide +/// additional information for current list section. +/// +/// The [children] is the list of widgets to be displayed in this list section. +/// Typically, the children are of type [CupertinoListTile], however these is +/// not enforced. +/// +/// The [margin] is used to provide spacing around the content area of the +/// section encapsulating [children]. +/// +/// The [decoration] of [children] specifies how they should be decorated. If it +/// is not provided in constructor, the background color of [children] defaults +/// to [CupertinoColors.secondarySystemGroupedBackground] and border radius of +/// children group defaults to 10.0 circular radius when constructing with +/// [CupertinoListSection.insetGrouped]. Defaults to zero radius for the +/// standard [CupertinoListSection] constructor. +/// +/// The [dividerMargin] and [additionalDividerMargin] specify the starting +/// margin of the divider between list tiles. The [dividerMargin] is always +/// present, but [additionalDividerMargin] is only added to the [dividerMargin] +/// if `hasLeading` is set to true in the constructor, which is the default +/// value. +/// +/// The [backgroundColor] of the section defaults to +/// [CupertinoColors.systemGroupedBackground]. +/// +/// {@macro flutter.material.Material.clipBehavior} +/// +/// {@tool dartpad} +/// Creates a base [CupertinoListSection] containing [CupertinoListTile]s with +/// `leading`, `title`, `additionalInfo` and `trailing` widgets. +/// +/// ** See code in examples/api/lib/cupertino/list_section/list_section_base.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// Creates an "Inset Grouped" [CupertinoListSection] containing +/// notched [CupertinoListTile]s with `leading`, `title`, `additionalInfo` and +/// `trailing` widgets. +/// +/// ** See code in examples/api/lib/cupertino/list_section/list_section_inset.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoListTile], an iOS-style list tile, a typical child of +/// [CupertinoListSection]. +/// * [CupertinoFormSection], an iOS-style form section. +class CupertinoListSection extends StatelessWidget { + /// Creates a section that mimics standard iOS forms. + /// + /// The base constructor for [CupertinoListSection] constructs an + /// edge-to-edge style section which includes an iOS-style header, the dividers + /// between rows, and borders on top and bottom of the rows. An example of such + /// list section are sections in iOS Settings app. + /// + /// The [header] parameter sets the form section header. The section header + /// lies above the [children] rows, with margins that match the iOS style. + /// + /// The [footer] parameter sets the form section footer. The section footer + /// lies below the [children] rows. + /// + /// The [children] parameter is required and sets the list of rows shown in + /// the section. The [children] parameter takes a list, as opposed to a more + /// efficient builder function that lazy builds, because forms are intended to + /// be short in row count. It is recommended that only [CupertinoFormRow] and + /// [CupertinoTextFormFieldRow] widgets be included in the [children] list in + /// order to retain the iOS look. + /// + /// The [margin] parameter sets the spacing around the content area of the + /// section encapsulating [children], and defaults to zero padding. + /// + /// The [decoration] parameter sets the decoration around [children]. + /// If null, defaults to [CupertinoColors.secondarySystemGroupedBackground]. + /// If null, defaults to 10.0 circular radius when constructing with + /// [CupertinoListSection.insetGrouped]. Defaults to zero radius for the + /// standard [CupertinoListSection] constructor. + /// + /// The [backgroundColor] parameter sets the background color behind the + /// section. If null, defaults to [CupertinoColors.systemGroupedBackground]. + /// + /// The [dividerMargin] parameter sets the starting offset of the divider + /// between rows. + /// + /// The [additionalDividerMargin] parameter adds additional margin to existing + /// [dividerMargin] when [hasLeading] is set to true. By default, it offsets + /// for the width of leading and space between leading and title of + /// [CupertinoListTile], but it can be overwritten for custom look. + /// + /// The [hasLeading] parameter specifies whether children [CupertinoListTile] + /// widgets contain leading or not. Used for calculating correct starting + /// margin for the divider between rows. + /// + /// The [topMargin] is used to specify the margin above the list section. It + /// matches the iOS look by default. + /// + /// {@macro flutter.material.Material.clipBehavior} + const CupertinoListSection({ + super.key, + this.children, + this.header, + this.footer, + this.margin = _kDefaultRowsMargin, + this.backgroundColor = CupertinoColors.systemGroupedBackground, + this.decoration, + this.clipBehavior = Clip.none, + this.dividerMargin = _kBaseDividerMargin, + double? additionalDividerMargin, + this.topMargin = _kMarginTop, + bool hasLeading = true, + this.separatorColor, + }) : assert((children != null && children.length > 0) || header != null), + type = CupertinoListSectionType.base, + additionalDividerMargin = additionalDividerMargin ?? + (hasLeading ? _kBaseAdditionalDividerMargin : 0.0); + + /// Creates a section that mimics standard "Inset Grouped" iOS list section. + /// + /// The [CupertinoListSection.insetGrouped] constructor creates a round-edged + /// and padded section that is seen in iOS Notes and Reminders apps. It creates + /// an iOS-style header, and the dividers between rows. Does not create borders + /// on top and bottom of the rows. + /// + /// The [header] parameter sets the form section header. The section header + /// lies above the [children] rows, with margins that match the iOS style. + /// + /// The [footer] parameter sets the form section footer. The section footer + /// lies below the [children] rows. + /// + /// The [children] parameter is required and sets the list of rows shown in + /// the section. The [children] parameter takes a list, as opposed to a more + /// efficient builder function that lazy builds, because forms are intended to + /// be short in row count. It is recommended that only [CupertinoListTile] + /// widget be included in the [children] list in order to retain the iOS look. + /// + /// The [margin] parameter sets the spacing around the content area of the + /// section encapsulating [children], and defaults to the standard + /// notched-style iOS form padding. + /// + /// The [decoration] parameter sets the decoration around [children]. + /// If null, defaults to [CupertinoColors.secondarySystemGroupedBackground]. + /// If null, defaults to 10.0 circular radius when constructing with + /// [CupertinoListSection.insetGrouped]. Defaults to zero radius for the + /// standard [CupertinoListSection] constructor. + /// + /// The [backgroundColor] parameter sets the background color behind the + /// section. If null, defaults to [CupertinoColors.systemGroupedBackground]. + /// + /// The [dividerMargin] parameter sets the starting offset of the divider + /// between rows. + /// + /// The [additionalDividerMargin] parameter adds additional margin to existing + /// [dividerMargin] when [hasLeading] is set to true. By default, it offsets + /// for the width of leading and space between leading and title of + /// [CupertinoListTile], but it can be overwritten for custom look. + /// + /// The [hasLeading] parameter specifies whether children [CupertinoListTile] + /// widgets contain leading or not. Used for calculating correct starting + /// margin for the divider between rows. + /// + /// {@macro flutter.material.Material.clipBehavior} + const CupertinoListSection.insetGrouped({ + super.key, + this.children, + this.header, + this.footer, + EdgeInsetsGeometry? margin, + this.backgroundColor = CupertinoColors.systemGroupedBackground, + this.decoration, + this.clipBehavior = Clip.hardEdge, + this.dividerMargin = _kInsetDividerMargin, + double? additionalDividerMargin, + this.topMargin, + bool hasLeading = true, + this.separatorColor, + }) : assert((children != null && children.length > 0) || header != null), + type = CupertinoListSectionType.insetGrouped, + additionalDividerMargin = additionalDividerMargin ?? + (hasLeading + ? _kInsetAdditionalDividerMargin + : _kInsetAdditionalDividerMarginWithoutLeading), + margin = margin ?? (header == null ? _kDefaultInsetGroupedRowsMargin : _kDefaultInsetGroupedRowsMarginWithHeader); + + /// The type of list section, either base or inset grouped. + /// + /// This member is public for testing purposes only and cannot be set + /// manually. Instead, use a corresponding constructors. + @visibleForTesting + final CupertinoListSectionType type; + + /// Sets the form section header. The section header lies above the [children] + /// rows. Usually a [Text] widget. + final Widget? header; + + /// Sets the form section footer. The section footer lies below the [children] + /// rows. Usually a [Text] widget. + final Widget? footer; + + /// Margin around the content area of the section encapsulating [children]. + /// + /// Defaults to zero padding if constructed with standard + /// [CupertinoListSection] constructor. Defaults to the standard notched-style + /// iOS margin when constructing with [CupertinoListSection.insetGrouped]. + final EdgeInsetsGeometry margin; + + /// The list of rows in the section. Usually a list of [CupertinoListTile]s. + /// + /// This takes a list, as opposed to a more efficient builder function that + /// lazy builds, because such lists are intended to be short in row count. + /// It is recommended that only [CupertinoListTile] widget be included in the + /// [children] list in order to retain the iOS look. + final List? children; + + /// Sets the decoration around [children]. + /// + /// If null, background color defaults to + /// [CupertinoColors.secondarySystemGroupedBackground]. + /// + /// If null, border radius defaults to 10.0 circular radius when constructing + /// with [CupertinoListSection.insetGrouped]. Defaults to zero radius for the + /// standard [CupertinoListSection] constructor. + final BoxDecoration? decoration; + + /// Sets the background color behind the section. + /// + /// Defaults to [CupertinoColors.systemGroupedBackground]. + final Color backgroundColor; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// The starting offset of a margin between two list tiles. + final double dividerMargin; + + /// Additional starting inset of the divider used between rows. This is used + /// when adding a leading icon to children and a divider should start at the + /// text inset instead of the icon. + final double additionalDividerMargin; + + /// Margin above the list section. Only used in edge-to-edge variant and it + /// matches iOS style by default. + final double? topMargin; + + /// Sets the color for the dividers between rows, and borders on top and + /// bottom of the rows. + /// + /// If null, defaults to [CupertinoColors.separator]. + final Color? separatorColor; + + @override + Widget build(BuildContext context) { + final Color dividerColor = separatorColor ?? CupertinoColors.separator.resolveFrom(context); + final double dividerHeight = 1.0 / MediaQuery.devicePixelRatioOf(context); + + // Long divider is used for wrapping the top and bottom of rows. + // Only used in CupertinoListSectionType.base mode. + final Widget longDivider = Container( + color: dividerColor, + height: dividerHeight, + ); + + // Short divider is used between rows. + final Widget shortDivider = Container( + margin: EdgeInsetsDirectional.only( + start: dividerMargin + additionalDividerMargin), + color: dividerColor, + height: dividerHeight, + ); + + Widget? headerWidget; + if (header != null) { + headerWidget = DefaultTextStyle( + style: CupertinoTheme.of(context).textTheme.textStyle.merge( + type == CupertinoListSectionType.base + ? TextStyle( + fontSize: 13.0, + color: CupertinoDynamicColor.resolve( + _kHeaderFooterColor, context)) + : const TextStyle( + fontSize: 20.0, fontWeight: FontWeight.bold), + ), + child: header!, + ); + } + + Widget? footerWidget; + if (footer != null) { + footerWidget = DefaultTextStyle( + style: type == CupertinoListSectionType.base + ? CupertinoTheme.of(context).textTheme.textStyle.merge(TextStyle( + fontSize: 13.0, + color: CupertinoDynamicColor.resolve( + _kHeaderFooterColor, context), + )) + : CupertinoTheme.of(context).textTheme.textStyle, + child: footer!, + ); + } + + Widget? decoratedChildrenGroup; + if (children != null && children!.isNotEmpty) { + // We construct childrenWithDividers as follows: + // Insert a short divider between all rows. + // If it is a `CupertinoListSectionType.base` type, add a long divider + // to the top and bottom of the rows. + final List childrenWithDividers = []; + + if (type == CupertinoListSectionType.base) { + childrenWithDividers.add(longDivider); + } + + children!.sublist(0, children!.length - 1).forEach((Widget widget) { + childrenWithDividers.add(widget); + childrenWithDividers.add(shortDivider); + }); + + childrenWithDividers.add(children!.last); + if (type == CupertinoListSectionType.base) { + childrenWithDividers.add(longDivider); + } + + final BorderRadius childrenGroupBorderRadius = switch (type) { + CupertinoListSectionType.insetGrouped => _kDefaultInsetGroupedBorderRadius, + CupertinoListSectionType.base => BorderRadius.zero, + }; + + decoratedChildrenGroup = DecoratedBox( + decoration: decoration ?? + BoxDecoration( + color: CupertinoDynamicColor.resolve( + decoration?.color ?? + CupertinoColors.secondarySystemGroupedBackground, + context), + borderRadius: childrenGroupBorderRadius, + ), + child: Column(children: childrenWithDividers), + ); + + decoratedChildrenGroup = Padding( + padding: margin, + child: clipBehavior == Clip.none + ? decoratedChildrenGroup + : ClipRRect( + borderRadius: childrenGroupBorderRadius, + clipBehavior: clipBehavior, + child: decoratedChildrenGroup, + ), + ); + } + + return DecoratedBox( + decoration: BoxDecoration( + color: CupertinoDynamicColor.resolve(backgroundColor, context)), + child: Column( + children: [ + if (type == CupertinoListSectionType.base) + SizedBox(height: topMargin), + if (headerWidget != null) + Align( + alignment: AlignmentDirectional.centerStart, + child: Padding( + padding: type == CupertinoListSectionType.base + ? _kDefaultHeaderMargin + : _kInsetGroupedDefaultHeaderMargin, + child: headerWidget, + ), + ), + if (decoratedChildrenGroup != null) + decoratedChildrenGroup, + if (footerWidget != null) + Align( + alignment: AlignmentDirectional.centerStart, + child: Padding( + padding: type == CupertinoListSectionType.base + ? _kDefaultFooterMargin + : _kInsetGroupedDefaultFooterMargin, + child: footerWidget, + ), + ), + ], + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/list_tile.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/list_tile.dart new file mode 100644 index 0000000000000000000000000000000000000000..83c542f3ba2dcbf8c3a5b2e72b77688147f9822d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/list_tile.dart @@ -0,0 +1,415 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'icons.dart'; +import 'theme.dart'; + +// These constants were eyeballed from iOS 14.4 Settings app for base, Notes for +// notched without leading, and Reminders app for notched with leading. +const double _kLeadingSize = 28.0; +const double _kNotchedLeadingSize = 30.0; +const double _kMinHeight = _kLeadingSize + 2 * 8.0; +const double _kMinHeightWithSubtitle = _kLeadingSize + 2 * 10.0; +const double _kNotchedMinHeight = _kNotchedLeadingSize + 2 * 12.0; +const double _kNotchedMinHeightWithoutLeading = _kNotchedLeadingSize + 2 * 10.0; +const EdgeInsetsDirectional _kPadding = EdgeInsetsDirectional.only(start: 20.0, end: 14.0); +const EdgeInsetsDirectional _kPaddingWithSubtitle = EdgeInsetsDirectional.only(start: 20.0, end: 14.0); +const EdgeInsets _kNotchedPadding = EdgeInsets.symmetric(horizontal: 14.0); +const EdgeInsetsDirectional _kNotchedPaddingWithoutLeading = EdgeInsetsDirectional.fromSTEB(28.0, 10.0, 14.0, 10.0); +const double _kLeadingToTitle = 16.0; +const double _kNotchedLeadingToTitle = 12.0; +const double _kNotchedTitleToSubtitle = 3.0; +const double _kAdditionalInfoToTrailing = 6.0; +const double _kNotchedTitleWithSubtitleFontSize = 16.0; +const double _kSubtitleFontSize = 12.0; +const double _kNotchedSubtitleFontSize = 14.0; + +enum _CupertinoListTileType { base, notched } + +/// An iOS-style list tile. +/// +/// The [CupertinoListTile] is a Cupertino equivalent of Material [ListTile]. +/// It comes in two forms, an old-fashioned edge-to-edge variant known from iOS +/// Settings app and in a new, "Inset Grouped" form, known from either iOS Notes +/// or Reminders app. The first is constructed using default constructor, and +/// the latter using named constructor [CupertinoListTile.notched]. +/// +/// The [title], [subtitle], and [additionalInfo] are usually [Text] widgets. +/// They are all limited to one line so it is a responsibility of the caller to +/// take care of text wrapping. +/// +/// The size of [leading] is by default constrained to match the iOS size, +/// depending of the type of list tile. This can however be overridden by +/// providing [leadingSize]. The [trailing] widget is not constrained and is +/// therefore a responsibility of the caller to ensure reasonable size of the +/// [trailing] widget. +/// +/// The background color of the tile can be set with [backgroundColor] for the +/// state before tile was tapped and with [backgroundColorActivated] for the +/// state after the tile was tapped. By default, both values are set to match +/// the default iOS appearance. +/// +/// The [padding] and [leadingToTitle] are by default set to match iOS but can +/// be overwritten if necessary. +/// +/// The [onTap] callback provides an option to react to taps anywhere inside the +/// list tile. This can be used to navigate routes and according to iOS +/// behavior it should not be used for example to toggle the [CupertinoSwitch] +/// in the trailing widget. +/// +/// See also: +/// +/// * [CupertinoListSection], an iOS-style list that is a typical container for +/// [CupertinoListTile]. +/// * [ListTile], a Material Design list tile. +class CupertinoListTile extends StatefulWidget { + /// Creates an edge-to-edge iOS-style list tile like the tiles in iOS Settings + /// app. + /// + /// The [title] parameter is required. It is used to convey the most important + /// information of list tile. It is typically a [Text]. + /// + /// The [subtitle] parameter is used to display additional information. It is + /// placed below the [title]. + /// + /// The [additionalInfo] parameter is used to display additional information. + /// It is placed at the end of the tile, before the [trailing] if supplied. + /// + /// The [leading] parameter is typically an [Icon] or an [Image] and it comes + /// at the start of the tile. If omitted in all list tiles, a `hasLeading` of + /// enclosing [CupertinoListSection] should be set to `false` to ensure + /// correct margin of divider between tiles. + /// + /// The [trailing] parameter is typically a [CupertinoListTileChevron], an + /// [Icon], or a [CupertinoButton]. It is placed at the very end of the tile. + /// + /// The [onTap] parameter is used to provide an action that is called when the + /// tile is tapped. It is mainly used for navigating to a new route. It should + /// not be used to toggle a trailing [CupertinoSwitch] and similar use cases + /// because when tile is tapped, it switches the background color and remains + /// changed. This is according to iOS behavior. + /// + /// The [backgroundColor] provides a custom background color for the tile in + /// a state before tapped. By default, it matches the theme's background color + /// which is by default a [CupertinoColors.systemBackground]. + /// + /// The [backgroundColorActivated] provides a custom background color for the + /// tile after it was tapped. By default, it matches the theme's background + /// color which is by default a [CupertinoColors.systemGrey4]. + /// + /// The [padding] parameter sets the padding of the content inside the tile. + /// It defaults to a value that matches the iOS look, depending on a type of + /// [CupertinoListTile]. For native look, it should not be provided. + /// + /// The [leadingSize] constrains the width and height of the leading widget. + /// By default, it is set to a value that matches the iOS look, depending on a + /// type of [CupertinoListTile]. For native look, it should not be provided. + /// + /// The [leadingToTitle] specifies the horizontal space between [leading] and + /// [title] widgets. By default, it is set to a value that matched the iOS + /// look, depending on a type of [CupertinoListTile]. For native look, it + /// should not be provided. + const CupertinoListTile({ + super.key, + required this.title, + this.subtitle, + this.additionalInfo, + this.leading, + this.trailing, + this.onTap, + this.backgroundColor, + this.backgroundColorActivated, + this.padding, + this.leadingSize = _kLeadingSize, + this.leadingToTitle = _kLeadingToTitle, + }) : _type = _CupertinoListTileType.base; + + /// Creates a notched iOS-style list tile like the tiles in iOS Notes app or + /// Reminders app. + /// + /// The [title] parameter is required. It is used to convey the most important + /// information of list tile. It is typically a [Text]. + /// + /// The [subtitle] parameter is used to display additional information. It is + /// placed below the [title]. + /// + /// The [additionalInfo] parameter is used to display additional information. + /// It is placed at the end of the tile, before the [trailing] if supplied. + /// + /// The [leading] parameter is typically an [Icon] or an [Image] and it comes + /// at the start of the tile. If omitted in all list tiles, a `hasLeading` of + /// enclosing [CupertinoListSection] should be set to `false` to ensure + /// correct margin of divider between tiles. For Notes-like tile appearance, + /// the [leading] can be left `null`. + /// + /// The [trailing] parameter is typically a [CupertinoListTileChevron], an + /// [Icon], or a [CupertinoButton]. It is placed at the very end of the tile. + /// For Notes-like tile appearance, the [trailing] can be left `null`. + /// + /// The [onTap] parameter is used to provide an action that is called when the + /// tile is tapped. It is mainly used for navigating to a new route. It should + /// not be used to toggle a trailing [CupertinoSwitch] and similar use cases + /// because when tile is tapped, it switches the background color and remains + /// changed. This is according to iOS behavior. + /// + /// The [backgroundColor] provides a custom background color for the tile in + /// a state before tapped. By default, it matches the theme's background color + /// which is by default a [CupertinoColors.systemBackground]. + /// + /// The [backgroundColorActivated] provides a custom background color for the + /// tile after it was tapped. By default, it matches the theme's background + /// color which is by default a [CupertinoColors.systemGrey4]. + /// + /// The [padding] parameter sets the padding of the content inside the tile. + /// It defaults to a value that matches the iOS look, depending on a type of + /// [CupertinoListTile]. For native look, it should not be provided. + /// + /// The [leadingSize] constrains the width and height of the leading widget. + /// By default, it is set to a value that matches the iOS look, depending on a + /// type of [CupertinoListTile]. For native look, it should not be provided. + /// + /// The [leadingToTitle] specifies the horizontal space between [leading] and + /// [title] widgets. By default, it is set to a value that matched the iOS + /// look, depending on a type of [CupertinoListTile]. For native look, it + /// should not be provided. + const CupertinoListTile.notched({ + super.key, + required this.title, + this.subtitle, + this.additionalInfo, + this.leading, + this.trailing, + this.onTap, + this.backgroundColor, + this.backgroundColorActivated, + this.padding, + this.leadingSize = _kNotchedLeadingSize, + this.leadingToTitle = _kNotchedLeadingToTitle, + }) : _type = _CupertinoListTileType.notched; + + final _CupertinoListTileType _type; + + /// A [title] is used to convey the central information. Usually a [Text]. + final Widget title; + + /// A [subtitle] is used to display additional information. It is located + /// below [title]. Usually a [Text] widget. + final Widget? subtitle; + + /// Similar to [subtitle], an [additionalInfo] is used to display additional + /// information. However, instead of being displayed below [title], it is + /// displayed on the right, before [trailing]. Usually a [Text] widget. + final Widget? additionalInfo; + + /// A widget displayed at the start of the [CupertinoListTile]. This is + /// typically an `Icon` or an `Image`. + final Widget? leading; + + /// A widget displayed at the end of the [CupertinoListTile]. This is usually + /// a right chevron icon (e.g. `CupertinoListTileChevron`), or an `Icon`. + final Widget? trailing; + + /// The [onTap] function is called when a user taps on [CupertinoListTile]. If + /// left `null`, the [CupertinoListTile] will not react on taps. If this is a + /// `Future Function()`, then the [CupertinoListTile] remains activated + /// until the returned future is awaited. This is according to iOS behavior. + /// However, if this function is a `void Function()`, then the tile is active + /// only for the duration of invocation. + final FutureOr Function()? onTap; + + /// The [backgroundColor] of the tile in normal state. Once the tile is + /// tapped, the background color switches to [backgroundColorActivated]. It is + /// set to match the iOS look by default. + final Color? backgroundColor; + + /// The [backgroundColorActivated] is the background color of the tile after + /// the tile was tapped. It is set to match the iOS look by default. + final Color? backgroundColorActivated; + + /// Padding of the content inside [CupertinoListTile]. + final EdgeInsetsGeometry? padding; + + /// The [leadingSize] is used to constrain the width and height of [leading] + /// widget. + final double leadingSize; + + /// The horizontal space between [leading] widget and [title]. + final double leadingToTitle; + + @override + State createState() => _CupertinoListTileState(); +} + +class _CupertinoListTileState extends State { + bool _tapped = false; + + @override + Widget build(BuildContext context) { + final TextStyle titleTextStyle = + widget._type == _CupertinoListTileType.base || widget.subtitle == null + ? CupertinoTheme.of(context).textTheme.textStyle + : CupertinoTheme.of(context).textTheme.textStyle.merge( + TextStyle( + fontWeight: FontWeight.w600, + fontSize: widget.leading == null ? _kNotchedTitleWithSubtitleFontSize : null, + ), + ); + + final TextStyle subtitleTextStyle = widget._type == _CupertinoListTileType.base + ? CupertinoTheme.of(context).textTheme.textStyle.merge( + TextStyle( + fontSize: _kSubtitleFontSize, + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ), + ) + : CupertinoTheme.of(context).textTheme.textStyle.merge( + TextStyle( + fontSize: _kNotchedSubtitleFontSize, + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ), + ); + + final TextStyle? additionalInfoTextStyle = widget.additionalInfo != null + ? CupertinoTheme.of(context).textTheme.textStyle.merge( + TextStyle(color: CupertinoColors.secondaryLabel.resolveFrom(context))) + : null; + + final Widget title = DefaultTextStyle( + style: titleTextStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + child: widget.title, + ); + + EdgeInsetsGeometry? padding = widget.padding; + if (padding == null) { + switch (widget._type) { + case _CupertinoListTileType.base: + padding = widget.subtitle == null ? _kPadding : _kPaddingWithSubtitle; + case _CupertinoListTileType.notched: + padding = widget.leading == null ? _kNotchedPaddingWithoutLeading : _kNotchedPadding; + } + } + + Widget? subtitle; + if (widget.subtitle != null) { + subtitle = DefaultTextStyle( + style: subtitleTextStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + child: widget.subtitle!, + ); + } + + Widget? additionalInfo; + if (widget.additionalInfo != null) { + additionalInfo = DefaultTextStyle( + style: additionalInfoTextStyle!, + maxLines: 1, + child: widget.additionalInfo!, + ); + } + + // The color for default state tile is set to either what user provided or + // null and it will resolve to the correct color provided by context. But if + // the tile was tapped, it is set to what user provided or if null to the + // default color that matched the iOS-style. + Color? backgroundColor = widget.backgroundColor; + if (_tapped) { + backgroundColor = widget.backgroundColorActivated ?? CupertinoColors.systemGrey4.resolveFrom(context); + } + + double minHeight; + switch (widget._type) { + case _CupertinoListTileType.base: + minHeight = subtitle == null ? _kMinHeight : _kMinHeightWithSubtitle; + case _CupertinoListTileType.notched: + minHeight = widget.leading == null ? _kNotchedMinHeightWithoutLeading : _kNotchedMinHeight; + } + + final Widget child = Container( + constraints: BoxConstraints(minWidth: double.infinity, minHeight: minHeight), + color: backgroundColor, + child: Padding( + padding: padding, + child: Row( + children: [ + if (widget.leading != null) ...[ + SizedBox( + width: widget.leadingSize, + height: widget.leadingSize, + child: Center( + child: widget.leading, + ), + ), + SizedBox(width: widget.leadingToTitle), + ] else + SizedBox(height: widget.leadingSize), + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + title, + if (subtitle != null) ...[ + const SizedBox(height: _kNotchedTitleToSubtitle), + subtitle, + ], + ], + ), + ), + if (additionalInfo != null) ...[ + additionalInfo, + if (widget.trailing != null) + const SizedBox(width: _kAdditionalInfoToTrailing), + ], + if (widget.trailing != null) widget.trailing! + ], + ), + ), + ); + + if (widget.onTap == null) { + return child; + } + + return GestureDetector( + onTapDown: (_) => setState(() { _tapped = true; }), + onTapCancel: () => setState(() { _tapped = false; }), + onTap: () async { + await widget.onTap!(); + if (mounted) { + setState(() { _tapped = false; }); + } + }, + behavior: HitTestBehavior.opaque, + child: child, + ); + } +} + +/// A typical iOS trailing widget used to denote that a `CupertinoListTile` is a +/// button with an action. +/// +/// The [CupertinoListTileChevron] is meant as a convenience implementation of +/// trailing right chevron. +class CupertinoListTileChevron extends StatelessWidget { + /// Creates a typical widget used to denote that a `CupertinoListTile` is a + /// button with action. + const CupertinoListTileChevron({super.key}); + + @override + Widget build(BuildContext context) { + return Icon( + CupertinoIcons.right_chevron, + size: CupertinoTheme.of(context).textTheme.textStyle.fontSize, + color: CupertinoColors.systemGrey2.resolveFrom(context), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/localizations.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/localizations.dart new file mode 100644 index 0000000000000000000000000000000000000000..bbe65d1b3c96d1483544096bfe85f0abeeda48f9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/localizations.dart @@ -0,0 +1,526 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'debug.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Determines the order of the columns inside [CupertinoDatePicker] in +/// time and date time mode. +enum DatePickerDateTimeOrder { + /// Order of the columns, from left to right: date, hour, minute, am/pm. + /// + /// Example: Fri Aug 31 | 02 | 08 | PM. + date_time_dayPeriod, + /// Order of the columns, from left to right: date, am/pm, hour, minute. + /// + /// Example: Fri Aug 31 | PM | 02 | 08. + date_dayPeriod_time, + /// Order of the columns, from left to right: hour, minute, am/pm, date. + /// + /// Example: 02 | 08 | PM | Fri Aug 31. + time_dayPeriod_date, + /// Order of the columns, from left to right: am/pm, hour, minute, date. + /// + /// Example: PM | 02 | 08 | Fri Aug 31. + dayPeriod_time_date, +} + +/// Determines the order of the columns inside [CupertinoDatePicker] in date mode. +enum DatePickerDateOrder { + /// Order of the columns, from left to right: day, month, year. + /// + /// Example: 12 | March | 1996. + dmy, + /// Order of the columns, from left to right: month, day, year. + /// + /// Example: March | 12 | 1996. + mdy, + /// Order of the columns, from left to right: year, month, day. + /// + /// Example: 1996 | March | 12. + ymd, + /// Order of the columns, from left to right: year, day, month. + /// + /// Example: 1996 | 12 | March. + ydm, +} + +/// Defines the localized resource values used by the Cupertino widgets. +/// +/// See also: +/// +/// * [DefaultCupertinoLocalizations], the default, English-only, implementation +/// of this interface. +abstract class CupertinoLocalizations { + /// Year that is shown in [CupertinoDatePicker] spinner corresponding to the + /// given year index. + /// + /// Examples: datePickerYear(1) in: + /// + /// - US English: 2018 + /// - Korean: 2018년 + // The global version uses date symbols data from the intl package. + String datePickerYear(int yearIndex); + + /// Month that is shown in [CupertinoDatePicker] spinner corresponding to + /// the given month index. + /// + /// Examples: datePickerMonth(1) in: + /// + /// - US English: January + /// - Korean: 1월 + /// - Russian: января + // The global version uses date symbols data from the intl package. + String datePickerMonth(int monthIndex); + + /// Month that is shown in [CupertinoDatePicker] spinner corresponding to + /// the given month index in [CupertinoDatePickerMode.monthYear] mode. + /// + /// This is distinct from [datePickerMonth] because in some languages, like Russian, + /// the name of a month takes a different form depending + /// on whether it is preceded by a day or whether it stands alone. + /// + /// Examples: datePickerMonth(1) in: + /// + /// - US English: January + /// - Korean: 1월 + /// - Russian: Январь + // The global version uses date symbols data from the intl package. + String datePickerStandaloneMonth(int monthIndex); + + /// Day of month that is shown in [CupertinoDatePicker] spinner corresponding + /// to the given day index. + /// + /// If weekDay is provided then it will also show weekday name alongside the numerical day. + /// + /// Examples: datePickerDayOfMonth(1) in: + /// + /// - US English: 1 + /// - Korean: 1일 + /// Examples: datePickerDayOfMonth(1, 1) in: + /// + /// - US English: Mon 1 + // The global version uses date symbols data from the intl package. + String datePickerDayOfMonth(int dayIndex, [int? weekDay]); + + /// The medium-width date format that is shown in [CupertinoDatePicker] + /// spinner. Abbreviates month and days of week. + /// + /// Examples: + /// + /// - US English: Wed Sep 27 + /// - Russian: ср сент. 27 + // The global version is based on intl package's DateFormat.MMMEd. + String datePickerMediumDate(DateTime date); + + /// Hour that is shown in [CupertinoDatePicker] spinner corresponding + /// to the given hour value. + /// + /// Examples: datePickerHour(1) in: + /// + /// - US English: 1 + /// - Arabic: ٠١ + // The global version uses date symbols data from the intl package. + String datePickerHour(int hour); + + /// Semantics label for the given hour value in [CupertinoDatePicker]. + // The global version uses the translated string from the arb file. + String? datePickerHourSemanticsLabel(int hour); + + /// Minute that is shown in [CupertinoDatePicker] spinner corresponding + /// to the given minute value. + /// + /// Examples: datePickerMinute(1) in: + /// + /// - US English: 01 + /// - Arabic: ٠١ + // The global version uses date symbols data from the intl package. + String datePickerMinute(int minute); + + /// Semantics label for the given minute value in [CupertinoDatePicker]. + // The global version uses the translated string from the arb file. + String? datePickerMinuteSemanticsLabel(int minute); + + /// The order of the date elements that will be shown in [CupertinoDatePicker]. + // The global version uses the translated string from the arb file. + DatePickerDateOrder get datePickerDateOrder; + + /// The order of the time elements that will be shown in [CupertinoDatePicker]. + // The global version uses the translated string from the arb file. + DatePickerDateTimeOrder get datePickerDateTimeOrder; + + /// The abbreviation for ante meridiem (before noon) shown in the time picker. + // The global version uses the translated string from the arb file. + String get anteMeridiemAbbreviation; + + /// The abbreviation for post meridiem (after noon) shown in the time picker. + // The global version uses the translated string from the arb file. + String get postMeridiemAbbreviation; + + /// Label shown in date pickers when the date is today. + // The global version uses the translated string from the arb file. + String get todayLabel; + + /// The term used by the system to announce dialog alerts. + // The global version uses the translated string from the arb file. + String get alertDialogLabel; + + /// The accessibility label used on a tab in a [CupertinoTabBar]. + /// + /// This message describes the index of the selected tab and how many tabs + /// there are, e.g. 'tab, 1 of 2' in United States English. + /// + /// `tabIndex` and `tabCount` must be greater than or equal to one. + String tabSemanticsLabel({required int tabIndex, required int tabCount}); + + /// Hour that is shown in [CupertinoTimerPicker] corresponding to + /// the given hour value. + /// + /// Examples: timerPickerHour(1) in: + /// + /// - US English: 1 + /// - Arabic: ١ + // The global version uses date symbols data from the intl package. + String timerPickerHour(int hour); + + /// Minute that is shown in [CupertinoTimerPicker] corresponding to + /// the given minute value. + /// + /// Examples: timerPickerMinute(1) in: + /// + /// - US English: 1 + /// - Arabic: ١ + // The global version uses date symbols data from the intl package. + String timerPickerMinute(int minute); + + /// Second that is shown in [CupertinoTimerPicker] corresponding to + /// the given second value. + /// + /// Examples: timerPickerSecond(1) in: + /// + /// - US English: 1 + /// - Arabic: ١ + // The global version uses date symbols data from the intl package. + String timerPickerSecond(int second); + + /// Label that appears next to the hour picker in + /// [CupertinoTimerPicker] when selected hour value is `hour`. + /// This function will deal with pluralization based on the `hour` parameter. + // The global version uses the translated string from the arb file. + String? timerPickerHourLabel(int hour); + + /// All possible hour labels that appears next to the hour picker in + /// [CupertinoTimerPicker] + List get timerPickerHourLabels; + + /// Label that appears next to the minute picker in + /// [CupertinoTimerPicker] when selected minute value is `minute`. + /// This function will deal with pluralization based on the `minute` parameter. + // The global version uses the translated string from the arb file. + String? timerPickerMinuteLabel(int minute); + + /// All possible minute labels that appears next to the minute picker in + /// [CupertinoTimerPicker] + List get timerPickerMinuteLabels; + + /// Label that appears next to the minute picker in + /// [CupertinoTimerPicker] when selected minute value is `second`. + /// This function will deal with pluralization based on the `second` parameter. + // The global version uses the translated string from the arb file. + String? timerPickerSecondLabel(int second); + + /// All possible second labels that appears next to the second picker in + /// [CupertinoTimerPicker] + List get timerPickerSecondLabels; + + /// The term used for cutting. + // The global version uses the translated string from the arb file. + String get cutButtonLabel; + + /// The term used for copying. + // The global version uses the translated string from the arb file. + String get copyButtonLabel; + + /// The term used for pasting. + // The global version uses the translated string from the arb file. + String get pasteButtonLabel; + + /// The term used for clearing a field. + // The global version uses the translated string from the arb file. + String get clearButtonLabel; + + /// Label that appears in the Cupertino toolbar when the spell checker + /// couldn't find any replacements for the current word. + // The global version uses the translated string from the arb file. + String get noSpellCheckReplacementsLabel; + + /// The term used for selecting everything. + // The global version uses the translated string from the arb file. + String get selectAllButtonLabel; + + /// The term used for looking up a selection. + // The global version uses the translated string from the arb file. + String get lookUpButtonLabel; + + /// The term used for launching a web search on a selection. + // The global version uses the translated string from the arb file. + String get searchWebButtonLabel; + + /// The term used for launching a web search on a selection. + // The global version uses the translated string from the arb file. + String get shareButtonLabel; + + /// The default placeholder used in [CupertinoSearchTextField]. + // The global version uses the translated string from the arb file. + String get searchTextFieldPlaceholderLabel; + + /// Label read out by accessibility tools (VoiceOver) for a modal + /// barrier to indicate that a tap dismisses the barrier. + /// + /// A modal barrier can for example be found behind an alert or popup to block + /// user interaction with elements behind it. + String get modalBarrierDismissLabel; + + /// Label read out by accessibility tools (VoiceOver) for a context menu to + /// indicate that a tap outside dismisses the context menu. + String get menuDismissLabel; + + /// The `CupertinoLocalizations` from the closest [Localizations] instance + /// that encloses the given context. + /// + /// If no [CupertinoLocalizations] are available in the given `context`, this + /// method throws an exception. + /// + /// This method is just a convenient shorthand for: + /// `Localizations.of(context, CupertinoLocalizations)!`. + /// + /// References to the localized resources defined by this class are typically + /// written in terms of this method. For example: + /// + /// ```dart + /// CupertinoLocalizations.of(context).anteMeridiemAbbreviation; + /// ``` + static CupertinoLocalizations of(BuildContext context) { + assert(debugCheckHasCupertinoLocalizations(context)); + return Localizations.of(context, CupertinoLocalizations)!; + } +} + +class _CupertinoLocalizationsDelegate extends LocalizationsDelegate { + const _CupertinoLocalizationsDelegate(); + + @override + bool isSupported(Locale locale) => locale.languageCode == 'en'; + + @override + Future load(Locale locale) => DefaultCupertinoLocalizations.load(locale); + + @override + bool shouldReload(_CupertinoLocalizationsDelegate old) => false; + + @override + String toString() => 'DefaultCupertinoLocalizations.delegate(en_US)'; +} + +/// US English strings for the Cupertino widgets. +class DefaultCupertinoLocalizations implements CupertinoLocalizations { + /// Constructs an object that defines the cupertino widgets' localized strings + /// for US English (only). + /// + /// [LocalizationsDelegate] implementations typically call the static [load] + /// function, rather than constructing this class directly. + const DefaultCupertinoLocalizations(); + + /// Short version of days of week. + static const List shortWeekdays = [ + 'Mon', + 'Tue', + 'Wed', + 'Thu', + 'Fri', + 'Sat', + 'Sun', + ]; + + static const List _shortMonths = [ + 'Jan', + 'Feb', + 'Mar', + 'Apr', + 'May', + 'Jun', + 'Jul', + 'Aug', + 'Sep', + 'Oct', + 'Nov', + 'Dec', + ]; + + static const List _months = [ + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December', + ]; + + + + @override + String datePickerYear(int yearIndex) => yearIndex.toString(); + + @override + String datePickerMonth(int monthIndex) => _months[monthIndex - 1]; + + @override + String datePickerStandaloneMonth(int monthIndex) => _months[monthIndex - 1]; + + @override + String datePickerDayOfMonth(int dayIndex, [int? weekDay]) { + if (weekDay != null) { + return ' ${shortWeekdays[weekDay - DateTime.monday]} $dayIndex '; + } + + return dayIndex.toString(); + } + + @override + String datePickerHour(int hour) => hour.toString(); + + @override + String datePickerHourSemanticsLabel(int hour) => "$hour o'clock"; + + @override + String datePickerMinute(int minute) => minute.toString().padLeft(2, '0'); + + @override + String datePickerMinuteSemanticsLabel(int minute) { + if (minute == 1) { + return '1 minute'; + } + return '$minute minutes'; + } + + @override + String datePickerMediumDate(DateTime date) { + return '${shortWeekdays[date.weekday - DateTime.monday]} ' + '${_shortMonths[date.month - DateTime.january]} ' + '${date.day.toString().padRight(2)}'; + } + + @override + DatePickerDateOrder get datePickerDateOrder => DatePickerDateOrder.mdy; + + @override + DatePickerDateTimeOrder get datePickerDateTimeOrder => DatePickerDateTimeOrder.date_time_dayPeriod; + + @override + String get anteMeridiemAbbreviation => 'AM'; + + @override + String get postMeridiemAbbreviation => 'PM'; + + @override + String get todayLabel => 'Today'; + + @override + String get alertDialogLabel => 'Alert'; + + @override + String tabSemanticsLabel({required int tabIndex, required int tabCount}) { + assert(tabIndex >= 1); + assert(tabCount >= 1); + return 'Tab $tabIndex of $tabCount'; + } + + @override + String timerPickerHour(int hour) => hour.toString(); + + @override + String timerPickerMinute(int minute) => minute.toString(); + + @override + String timerPickerSecond(int second) => second.toString(); + + @override + String timerPickerHourLabel(int hour) => hour == 1 ? 'hour' : 'hours'; + + @override + List get timerPickerHourLabels => const ['hour', 'hours']; + + @override + String timerPickerMinuteLabel(int minute) => 'min.'; + + @override + List get timerPickerMinuteLabels => const ['min.']; + + @override + String timerPickerSecondLabel(int second) => 'sec.'; + + @override + List get timerPickerSecondLabels => const ['sec.']; + + @override + String get cutButtonLabel => 'Cut'; + + @override + String get copyButtonLabel => 'Copy'; + + @override + String get pasteButtonLabel => 'Paste'; + + @override + String get clearButtonLabel => 'Clear'; + + @override + String get noSpellCheckReplacementsLabel => 'No Replacements Found'; + + @override + String get selectAllButtonLabel => 'Select All'; + + @override + String get lookUpButtonLabel => 'Look Up'; + + @override + String get searchWebButtonLabel => 'Search Web'; + + @override + String get shareButtonLabel => 'Share...'; + + @override + String get searchTextFieldPlaceholderLabel => 'Search'; + + @override + String get modalBarrierDismissLabel => 'Dismiss'; + + @override + String get menuDismissLabel => 'Dismiss menu'; + + /// Creates an object that provides US English resource values for the + /// cupertino library widgets. + /// + /// The [locale] parameter is ignored. + /// + /// This method is typically used to create a [LocalizationsDelegate]. + static Future load(Locale locale) { + return SynchronousFuture(const DefaultCupertinoLocalizations()); + } + + /// A [LocalizationsDelegate] that uses [DefaultCupertinoLocalizations.load] + /// to create an instance of this class. + static const LocalizationsDelegate delegate = _CupertinoLocalizationsDelegate(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/magnifier.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/magnifier.dart new file mode 100644 index 0000000000000000000000000000000000000000..74aef3fe26b67cfb311cf51b67490c67563603c7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/magnifier.dart @@ -0,0 +1,323 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'package:flutter/widgets.dart'; + +/// A [CupertinoMagnifier] used for magnifying text in cases where a user's +/// finger may be blocking the point of interest, like a selection handle. +/// +/// Delegates styling to [CupertinoMagnifier] with its position depending on +/// [magnifierInfo]. +/// +/// Specifically, the [CupertinoTextMagnifier] follows the following rules. +/// [CupertinoTextMagnifier]: +/// - is positioned horizontally inside the screen width, with [horizontalScreenEdgePadding] padding. +/// - is hidden if a gesture is detected [hideBelowThreshold] units below the line +/// that the magnifier is on, shown otherwise. +/// - follows the x coordinate of the gesture directly (with respect to rule 1). +/// - has some vertical drag resistance; i.e. if a gesture is detected k units below the field, +/// then has vertical offset [dragResistance] * k. +class CupertinoTextMagnifier extends StatefulWidget { + /// Constructs a [RawMagnifier] in the Cupertino style, positioning with respect to + /// [magnifierInfo]. + /// + /// The default constructor parameters and constants were eyeballed on + /// an iPhone XR iOS v15.5. + const CupertinoTextMagnifier({ + super.key, + this.animationCurve = Curves.easeOut, + required this.controller, + this.dragResistance = 10.0, + this.hideBelowThreshold = 48.0, + this.horizontalScreenEdgePadding = 10.0, + required this.magnifierInfo, + }); + + /// The curve used for the in / out animations. + final Curve animationCurve; + + /// This magnifier's controller. + /// + /// The [CupertinoTextMagnifier] requires a [MagnifierController] + /// in order to show / hide itself without removing itself from the + /// overlay. + final MagnifierController controller; + + /// A drag resistance on the downward Y position of the lens. + final double dragResistance; + + /// The difference in Y between the gesture position and the caret center + /// so that the magnifier hides itself. + final double hideBelowThreshold; + + /// The padding on either edge of the screen that any part of the magnifier + /// cannot exist past. + /// + /// This includes any part of the magnifier, not just the center; for example, + /// the left edge of the magnifier cannot be outside the [horizontalScreenEdgePadding].v + /// + /// If the screen has width w, then the magnifier is bound to + /// `_kHorizontalScreenEdgePadding, w - _kHorizontalScreenEdgePadding`. + final double horizontalScreenEdgePadding; + + /// [CupertinoTextMagnifier] will determine its own positioning + /// based on the [MagnifierInfo] of this notifier. + final ValueNotifier + magnifierInfo; + + /// The duration that the magnifier drags behind its final position. + static const Duration _kDragAnimationDuration = Duration(milliseconds: 45); + + @override + State createState() => + _CupertinoTextMagnifierState(); +} + +class _CupertinoTextMagnifierState extends State + with SingleTickerProviderStateMixin { + // Initialize to dummy values for the event that the initial call to + // _determineMagnifierPositionAndFocalPoint calls hide, and thus does not + // set these values. + Offset _currentAdjustedMagnifierPosition = Offset.zero; + double _verticalFocalPointAdjustment = 0; + late AnimationController _ioAnimationController; + late Animation _ioAnimation; + + @override + void initState() { + super.initState(); + _ioAnimationController = AnimationController( + value: 0, + vsync: this, + duration: CupertinoMagnifier._kInOutAnimationDuration, + )..addListener(() => setState(() {})); + + widget.controller.animationController = _ioAnimationController; + widget.magnifierInfo + .addListener(_determineMagnifierPositionAndFocalPoint); + + _ioAnimation = Tween( + begin: 0.0, + end: 1.0, + ).animate(CurvedAnimation( + parent: _ioAnimationController, + curve: widget.animationCurve, + )); + } + + @override + void dispose() { + widget.controller.animationController = null; + _ioAnimationController.dispose(); + widget.magnifierInfo + .removeListener(_determineMagnifierPositionAndFocalPoint); + super.dispose(); + } + + @override + void didUpdateWidget(CupertinoTextMagnifier oldWidget) { + if (oldWidget.magnifierInfo != widget.magnifierInfo) { + oldWidget.magnifierInfo.removeListener(_determineMagnifierPositionAndFocalPoint); + widget.magnifierInfo.addListener(_determineMagnifierPositionAndFocalPoint); + } + super.didUpdateWidget(oldWidget); + } + + @override + void didChangeDependencies() { + _determineMagnifierPositionAndFocalPoint(); + super.didChangeDependencies(); + } + + void _determineMagnifierPositionAndFocalPoint() { + final MagnifierInfo textEditingContext = + widget.magnifierInfo.value; + + // The exact Y of the center of the current line. + final double verticalCenterOfCurrentLine = + textEditingContext.caretRect.center.dy; + + // If the magnifier is currently showing, but we have dragged out of threshold, + // we should hide it. + if (verticalCenterOfCurrentLine - + textEditingContext.globalGesturePosition.dy < + -widget.hideBelowThreshold) { + // Only signal a hide if we are currently showing. + if (widget.controller.shown) { + widget.controller.hide(removeFromOverlay: false); + } + return; + } + + // If we are gone, but got to this point, we shouldn't be: show. + if (!widget.controller.shown) { + _ioAnimationController.forward(); + } + + // Never go above the center of the line, but have some resistance + // going downward if the drag goes too far. + final double verticalPositionOfLens = math.max( + verticalCenterOfCurrentLine, + verticalCenterOfCurrentLine - + (verticalCenterOfCurrentLine - + textEditingContext.globalGesturePosition.dy) / + widget.dragResistance); + + // The raw position, tracking the gesture directly. + final Offset rawMagnifierPosition = Offset( + textEditingContext.globalGesturePosition.dx - + CupertinoMagnifier.kDefaultSize.width / 2, + verticalPositionOfLens - + (CupertinoMagnifier.kDefaultSize.height - + CupertinoMagnifier.kMagnifierAboveFocalPoint), + ); + + final Rect screenRect = Offset.zero & MediaQuery.sizeOf(context); + + // Adjust the magnifier position so that it never exists outside the horizontal + // padding. + final Offset adjustedMagnifierPosition = MagnifierController.shiftWithinBounds( + bounds: Rect.fromLTRB( + screenRect.left + widget.horizontalScreenEdgePadding, + // iOS doesn't reposition for Y, so we should expand the threshold + // so we can send the whole magnifier out of bounds if need be. + screenRect.top - + (CupertinoMagnifier.kDefaultSize.height + + CupertinoMagnifier.kMagnifierAboveFocalPoint), + screenRect.right - widget.horizontalScreenEdgePadding, + screenRect.bottom + + (CupertinoMagnifier.kDefaultSize.height + + CupertinoMagnifier.kMagnifierAboveFocalPoint)), + rect: rawMagnifierPosition & CupertinoMagnifier.kDefaultSize, + ).topLeft; + + setState(() { + _currentAdjustedMagnifierPosition = adjustedMagnifierPosition; + // The lens should always point to the center of the line. + _verticalFocalPointAdjustment = + verticalCenterOfCurrentLine - verticalPositionOfLens; + }); + } + + @override + Widget build(BuildContext context) { + return AnimatedPositioned( + duration: CupertinoTextMagnifier._kDragAnimationDuration, + curve: widget.animationCurve, + left: _currentAdjustedMagnifierPosition.dx, + top: _currentAdjustedMagnifierPosition.dy, + child: CupertinoMagnifier( + inOutAnimation: _ioAnimation, + additionalFocalPointOffset: Offset(0, _verticalFocalPointAdjustment), + ), + ); + } +} + +/// A [RawMagnifier] used for magnifying text in cases where a user's +/// finger may be blocking the point of interest, like a selection handle. +/// +/// [CupertinoMagnifier] is a wrapper around [RawMagnifier] that handles styling +/// and transitions. +/// +/// {@macro flutter.widgets.magnifier.intro} +/// +/// See also: +/// +/// * [RawMagnifier], the backing implementation. +/// * [CupertinoTextMagnifier], a widget that positions [CupertinoMagnifier] based on +/// [MagnifierInfo]. +/// * [MagnifierController], the controller for this magnifier. +class CupertinoMagnifier extends StatelessWidget { + /// Creates a [RawMagnifier] in the Cupertino style. + /// + /// The default constructor parameters and constants were eyeballed on + /// an iPhone XR iOS v15.5. + const CupertinoMagnifier({ + super.key, + this.size = kDefaultSize, + this.borderRadius = const BorderRadius.all(Radius.elliptical(60, 50)), + this.additionalFocalPointOffset = Offset.zero, + this.shadows = const [ + BoxShadow( + color: Color.fromARGB(25, 0, 0, 0), + blurRadius: 11, + spreadRadius: 0.2, + ), + ], + this.borderSide = + const BorderSide(color: Color.fromARGB(255, 232, 232, 232)), + this.inOutAnimation, + }); + + /// The shadows displayed under the magnifier. + final List shadows; + + /// The border, or "rim", of this magnifier. + final BorderSide borderSide; + + /// The vertical offset that the magnifier is along the Y axis above + /// the focal point. + @visibleForTesting + static const double kMagnifierAboveFocalPoint = -26; + + /// The default size of the magnifier. + /// + /// This is public so that positioners can choose to depend on it, although + /// it is overridable. + @visibleForTesting + static const Size kDefaultSize = Size(80, 47.5); + + /// The duration that this magnifier animates in / out for. + /// + /// The animation is a translation and a fade. The translation + /// begins at the focal point, and ends at [kMagnifierAboveFocalPoint]. + /// The opacity begins at 0 and ends at 1. + static const Duration _kInOutAnimationDuration = Duration(milliseconds: 150); + + /// The size of this magnifier. + final Size size; + + /// The border radius of this magnifier. + final BorderRadius borderRadius; + + /// This [RawMagnifier]'s controller. + /// + /// Since [CupertinoMagnifier] has no knowledge of shown / hidden state, + /// this animation should be driven by an external actor. + final Animation? inOutAnimation; + + /// Any additional focal point offset, applied over the regular focal + /// point offset defined in [kMagnifierAboveFocalPoint]. + final Offset additionalFocalPointOffset; + + @override + Widget build(BuildContext context) { + Offset focalPointOffset = + Offset(0, (kDefaultSize.height / 2) - kMagnifierAboveFocalPoint); + focalPointOffset.scale(1, inOutAnimation?.value ?? 1); + focalPointOffset += additionalFocalPointOffset; + + return Transform.translate( + offset: Offset.lerp( + const Offset(0, -kMagnifierAboveFocalPoint), + Offset.zero, + inOutAnimation?.value ?? 1, + )!, + child: RawMagnifier( + size: size, + focalPointOffset: focalPointOffset, + decoration: MagnifierDecoration( + opacity: inOutAnimation?.value ?? 1, + shape: RoundedRectangleBorder( + borderRadius: borderRadius, + side: borderSide, + ), + shadows: shadows, + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/nav_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/nav_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..665da8b7257cfe7f98a9097a3baf8a038c2262d9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -0,0 +1,2470 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show ImageFilter; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'button.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'icons.dart'; +import 'page_scaffold.dart'; +import 'route.dart'; +import 'theme.dart'; + +/// Standard iOS navigation bar height without the status bar. +/// +/// This height is constant and independent of accessibility as it is in iOS. +const double _kNavBarPersistentHeight = kMinInteractiveDimensionCupertino; + +/// Size increase from expanding the navigation bar into an iOS-11-style large title +/// form in a [CustomScrollView]. +const double _kNavBarLargeTitleHeightExtension = 52.0; + +/// Number of logical pixels scrolled down before the title text is transferred +/// from the normal navigation bar to a big title below the navigation bar. +const double _kNavBarShowLargeTitleThreshold = 10.0; + +const double _kNavBarEdgePadding = 16.0; + +const double _kNavBarBottomPadding = 8.0; + +const double _kNavBarBackButtonTapWidth = 50.0; + +/// Title text transfer fade. +const Duration _kNavBarTitleFadeDuration = Duration(milliseconds: 150); + +const Color _kDefaultNavBarBorderColor = Color(0x4D000000); + +const Border _kDefaultNavBarBorder = Border( + bottom: BorderSide( + color: _kDefaultNavBarBorderColor, + width: 0.0, // 0.0 means one physical pixel + ), +); + +// There's a single tag for all instances of navigation bars because they can +// all transition between each other (per Navigator) via Hero transitions. +const _HeroTag _defaultHeroTag = _HeroTag(null); + +@immutable +class _HeroTag { + const _HeroTag(this.navigator); + + final NavigatorState? navigator; + + // Let the Hero tag be described in tree dumps. + @override + String toString() => 'Default Hero tag for Cupertino navigation bars with navigator $navigator'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is _HeroTag + && other.navigator == navigator; + } + + @override + int get hashCode => identityHashCode(navigator); +} + +// An `AnimatedWidget` that imposes a fixed size on its child widget, and +// shifts the child widget in the parent stack, driven by its `offsetAnimation` +// property. +class _FixedSizeSlidingTransition extends AnimatedWidget { + const _FixedSizeSlidingTransition({ + required this.isLTR, + required this.offsetAnimation, + required this.size, + required this.child, + }) : super(listenable: offsetAnimation); + + // Whether the writing direction used in the navigation bar transition is + // left-to-right. + final bool isLTR; + + // The fixed size to impose on `child`. + final Size size; + + // The animated offset from the top-leading corner of the stack. + // + // When `isLTR` is true, the `Offset` is the position of the child widget in + // the stack render box's regular coordinate space. + // + // When `isLTR` is false, the coordinate system is flipped around the + // horizontal axis and the origin is set to the top right corner of the render + // boxes. In other words, this parameter describes the offset from the top + // right corner of the stack, to the top right corner of the child widget, and + // the x-axis runs right to left. + final Animation offsetAnimation; + + final Widget child; + + @override + Widget build(BuildContext context) { + return Positioned( + top: offsetAnimation.value.dy, + left: isLTR ? offsetAnimation.value.dx : null, + right: isLTR ? null : offsetAnimation.value.dx, + width: size.width, + height: size.height, + child: child, + ); + } +} + +/// Returns `child` wrapped with background and a bottom border if background color +/// is opaque. Otherwise, also blur with [BackdropFilter]. +/// +/// When `updateSystemUiOverlay` is true, the nav bar will update the OS +/// status bar's color theme based on the background color of the nav bar. +Widget _wrapWithBackground({ + Border? border, + required Color backgroundColor, + Brightness? brightness, + required Widget child, + bool updateSystemUiOverlay = true, +}) { + Widget result = child; + if (updateSystemUiOverlay) { + final bool isDark = backgroundColor.computeLuminance() < 0.179; + final Brightness newBrightness = brightness ?? (isDark ? Brightness.dark : Brightness.light); + final SystemUiOverlayStyle overlayStyle; + switch (newBrightness) { + case Brightness.dark: + overlayStyle = SystemUiOverlayStyle.light; + case Brightness.light: + overlayStyle = SystemUiOverlayStyle.dark; + } + // [SystemUiOverlayStyle.light] and [SystemUiOverlayStyle.dark] set some system + // navigation bar properties, + // Before https://github.com/flutter/flutter/pull/104827 those properties + // had no effect, now they are used if there is no AnnotatedRegion on the + // bottom of the screen. + // For backward compatibility, create a `SystemUiOverlayStyle` without the + // system navigation bar properties. + result = AnnotatedRegion( + value: SystemUiOverlayStyle( + statusBarColor: overlayStyle.statusBarColor, + statusBarBrightness: overlayStyle.statusBarBrightness, + statusBarIconBrightness: overlayStyle.statusBarIconBrightness, + systemStatusBarContrastEnforced: overlayStyle.systemStatusBarContrastEnforced, + ), + child: result, + ); + } + final DecoratedBox childWithBackground = DecoratedBox( + decoration: BoxDecoration( + border: border, + color: backgroundColor, + ), + child: result, + ); + + if (backgroundColor.alpha == 0xFF) { + return childWithBackground; + } + + return ClipRect( + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), + child: childWithBackground, + ), + ); +} + +// Whether the current route supports nav bar hero transitions from or to. +bool _isTransitionable(BuildContext context) { + final ModalRoute? route = ModalRoute.of(context); + + // Fullscreen dialogs never transitions their nav bar with other push-style + // pages' nav bars or with other fullscreen dialog pages on the way in or on + // the way out. + return route is PageRoute && !route.fullscreenDialog; +} + +/// An iOS-styled navigation bar. +/// +/// The navigation bar is a toolbar that minimally consists of a widget, normally +/// a page title, in the [middle] of the toolbar. +/// +/// It also supports a [leading] and [trailing] widget before and after the +/// [middle] widget while keeping the [middle] widget centered. +/// +/// The [leading] widget will automatically be a back chevron icon button (or a +/// close button in case of a fullscreen dialog) to pop the current route if none +/// is provided and [automaticallyImplyLeading] is true (true by default). +/// +/// The [middle] widget will automatically be a title text from the current +/// [CupertinoPageRoute] if none is provided and [automaticallyImplyMiddle] is +/// true (true by default). +/// +/// It should be placed at top of the screen and automatically accounts for +/// the OS's status bar. +/// +/// If the given [backgroundColor]'s opacity is not 1.0 (which is the case by +/// default), it will produce a blurring effect to the content behind it. +/// +/// When [transitionBetweenRoutes] is true, this navigation bar will transition +/// on top of the routes instead of inside them if the route being transitioned +/// to also has a [CupertinoNavigationBar] or a [CupertinoSliverNavigationBar] +/// with [transitionBetweenRoutes] set to true. If [transitionBetweenRoutes] is +/// true, none of the [Widget] parameters can contain a key in its subtree since +/// that widget will exist in multiple places in the tree simultaneously. +/// +/// By default, only one [CupertinoNavigationBar] or [CupertinoSliverNavigationBar] +/// should be present in each [PageRoute] to support the default transitions. +/// Use [transitionBetweenRoutes] or [heroTag] to customize the transition +/// behavior for multiple navigation bars per route. +/// +/// When used in a [CupertinoPageScaffold], [CupertinoPageScaffold.navigationBar] +/// disables text scaling to match the native iOS behavior. To override +/// this behavior, wrap each of the `navigationBar`'s components inside a +/// [MediaQuery] with the desired [TextScaler]. +/// +/// {@tool dartpad} +/// This example shows a [CupertinoNavigationBar] placed in a [CupertinoPageScaffold]. +/// Since [backgroundColor]'s opacity is not 1.0, there is a blur effect and +/// content slides underneath. +/// +/// ** See code in examples/api/lib/cupertino/nav_bar/cupertino_navigation_bar.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoPageScaffold], a page layout helper typically hosting the +/// [CupertinoNavigationBar]. +/// * [CupertinoSliverNavigationBar] for a navigation bar to be placed in a +/// scrolling list and that supports iOS-11-style large titles. +/// * +class CupertinoNavigationBar extends StatefulWidget implements ObstructingPreferredSizeWidget { + /// Creates a navigation bar in the iOS style. + const CupertinoNavigationBar({ + super.key, + this.leading, + this.automaticallyImplyLeading = true, + this.automaticallyImplyMiddle = true, + this.previousPageTitle, + this.middle, + this.trailing, + this.border = _kDefaultNavBarBorder, + this.backgroundColor, + this.brightness, + this.padding, + this.transitionBetweenRoutes = true, + this.heroTag = _defaultHeroTag, + }) : assert( + !transitionBetweenRoutes || identical(heroTag, _defaultHeroTag), + 'Cannot specify a heroTag override if this navigation bar does not ' + 'transition due to transitionBetweenRoutes = false.', + ); + + /// {@template flutter.cupertino.CupertinoNavigationBar.leading} + /// Widget to place at the start of the navigation bar. Normally a back button + /// for a normal page or a cancel button for full page dialogs. + /// + /// If null and [automaticallyImplyLeading] is true, an appropriate button + /// will be automatically created. + /// {@endtemplate} + final Widget? leading; + + /// {@template flutter.cupertino.CupertinoNavigationBar.automaticallyImplyLeading} + /// Controls whether we should try to imply the leading widget if null. + /// + /// If true and [leading] is null, automatically try to deduce what the [leading] + /// widget should be. If [leading] widget is not null, this parameter has no effect. + /// + /// Specifically this navigation bar will: + /// + /// 1. Show a 'Close' button if the current route is a `fullscreenDialog`. + /// 2. Show a back chevron with [previousPageTitle] if [previousPageTitle] is + /// not null. + /// 3. Show a back chevron with the previous route's `title` if the current + /// route is a [CupertinoPageRoute] and the previous route is also a + /// [CupertinoPageRoute]. + /// {@endtemplate} + final bool automaticallyImplyLeading; + + /// Controls whether we should try to imply the middle widget if null. + /// + /// If true and [middle] is null, automatically fill in a [Text] widget with + /// the current route's `title` if the route is a [CupertinoPageRoute]. + /// If [middle] widget is not null, this parameter has no effect. + final bool automaticallyImplyMiddle; + + /// {@template flutter.cupertino.CupertinoNavigationBar.previousPageTitle} + /// Manually specify the previous route's title when automatically implying + /// the leading back button. + /// + /// Overrides the text shown with the back chevron instead of automatically + /// showing the previous [CupertinoPageRoute]'s `title` when + /// [automaticallyImplyLeading] is true. + /// + /// Has no effect when [leading] is not null or if [automaticallyImplyLeading] + /// is false. + /// {@endtemplate} + final String? previousPageTitle; + + /// Widget to place in the middle of the navigation bar. Normally a title or + /// a segmented control. + /// + /// If null and [automaticallyImplyMiddle] is true, an appropriate [Text] + /// title will be created if the current route is a [CupertinoPageRoute] and + /// has a `title`. + final Widget? middle; + + /// {@template flutter.cupertino.CupertinoNavigationBar.trailing} + /// Widget to place at the end of the navigation bar. Normally additional actions + /// taken on the page such as a search or edit function. + /// {@endtemplate} + final Widget? trailing; + + // TODO(xster): https://github.com/flutter/flutter/issues/10469 implement + // support for double row navigation bars. + + /// {@template flutter.cupertino.CupertinoNavigationBar.backgroundColor} + /// The background color of the navigation bar. If it contains transparency, the + /// tab bar will automatically produce a blurring effect to the content + /// behind it. + /// + /// Defaults to [CupertinoTheme]'s `barBackgroundColor` if null. + /// {@endtemplate} + final Color? backgroundColor; + + /// {@template flutter.cupertino.CupertinoNavigationBar.brightness} + /// The brightness of the specified [backgroundColor]. + /// + /// Setting this value changes the style of the system status bar. Typically + /// used to increase the contrast ratio of the system status bar over + /// [backgroundColor]. + /// + /// If set to null, the value of the property will be inferred from the relative + /// luminance of [backgroundColor]. + /// {@endtemplate} + final Brightness? brightness; + + /// {@template flutter.cupertino.CupertinoNavigationBar.padding} + /// Padding for the contents of the navigation bar. + /// + /// If null, the navigation bar will adopt the following defaults: + /// + /// * Vertically, contents will be sized to the same height as the navigation + /// bar itself minus the status bar. + /// * Horizontally, padding will be 16 pixels according to iOS specifications + /// unless the leading widget is an automatically inserted back button, in + /// which case the padding will be 0. + /// + /// Vertical padding won't change the height of the nav bar. + /// {@endtemplate} + final EdgeInsetsDirectional? padding; + + /// {@template flutter.cupertino.CupertinoNavigationBar.border} + /// The border of the navigation bar. By default renders a single pixel bottom border side. + /// + /// If a border is null, the navigation bar will not display a border. + /// {@endtemplate} + final Border? border; + + /// {@template flutter.cupertino.CupertinoNavigationBar.transitionBetweenRoutes} + /// Whether to transition between navigation bars. + /// + /// When [transitionBetweenRoutes] is true, this navigation bar will transition + /// on top of the routes instead of inside it if the route being transitioned + /// to also has a [CupertinoNavigationBar] or a [CupertinoSliverNavigationBar] + /// with [transitionBetweenRoutes] set to true. + /// + /// This transition will also occur on edge back swipe gestures like on iOS + /// but only if the previous page below has `maintainState` set to true on the + /// [PageRoute]. + /// + /// When set to true, only one navigation bar can be present per route unless + /// [heroTag] is also set. + /// + /// This value defaults to true. + /// {@endtemplate} + final bool transitionBetweenRoutes; + + /// {@template flutter.cupertino.CupertinoNavigationBar.heroTag} + /// Tag for the navigation bar's Hero widget if [transitionBetweenRoutes] is true. + /// + /// Defaults to a common tag between all [CupertinoNavigationBar] and + /// [CupertinoSliverNavigationBar] instances of the same [Navigator]. With the + /// default tag, all navigation bars of the same navigator can transition + /// between each other as long as there's only one navigation bar per route. + /// + /// This [heroTag] can be overridden to manually handle having multiple + /// navigation bars per route or to transition between multiple + /// [Navigator]s. + /// + /// To disable Hero transitions for this navigation bar, set + /// [transitionBetweenRoutes] to false. + /// {@endtemplate} + final Object heroTag; + + /// True if the navigation bar's background color has no transparency. + @override + bool shouldFullyObstruct(BuildContext context) { + final Color backgroundColor = CupertinoDynamicColor.maybeResolve(this.backgroundColor, context) + ?? CupertinoTheme.of(context).barBackgroundColor; + return backgroundColor.alpha == 0xFF; + } + + @override + Size get preferredSize { + return const Size.fromHeight(_kNavBarPersistentHeight); + } + + @override + State createState() => _CupertinoNavigationBarState(); +} + +// A state class exists for the nav bar so that the keys of its sub-components +// don't change when rebuilding the nav bar, causing the sub-components to +// lose their own states. +class _CupertinoNavigationBarState extends State { + late _NavigationBarStaticComponentsKeys keys; + + @override + void initState() { + super.initState(); + keys = _NavigationBarStaticComponentsKeys(); + } + + @override + Widget build(BuildContext context) { + final Color backgroundColor = + CupertinoDynamicColor.maybeResolve(widget.backgroundColor, context) ?? CupertinoTheme.of(context).barBackgroundColor; + + final _NavigationBarStaticComponents components = _NavigationBarStaticComponents( + keys: keys, + route: ModalRoute.of(context), + userLeading: widget.leading, + automaticallyImplyLeading: widget.automaticallyImplyLeading, + automaticallyImplyTitle: widget.automaticallyImplyMiddle, + previousPageTitle: widget.previousPageTitle, + userMiddle: widget.middle, + userTrailing: widget.trailing, + padding: widget.padding, + userLargeTitle: null, + large: false, + ); + + final Widget navBar = _wrapWithBackground( + border: widget.border, + backgroundColor: backgroundColor, + brightness: widget.brightness, + child: DefaultTextStyle( + style: CupertinoTheme.of(context).textTheme.textStyle, + child: _PersistentNavigationBar( + components: components, + padding: widget.padding, + ), + ), + ); + + if (!widget.transitionBetweenRoutes || !_isTransitionable(context)) { + // Lint ignore to maintain backward compatibility. + return navBar; + } + + return Builder( + // Get the context that might have a possibly changed CupertinoTheme. + builder: (BuildContext context) { + return Hero( + tag: widget.heroTag == _defaultHeroTag + ? _HeroTag(Navigator.of(context)) + : widget.heroTag, + createRectTween: _linearTranslateWithLargestRectSizeTween, + placeholderBuilder: _navBarHeroLaunchPadBuilder, + flightShuttleBuilder: _navBarHeroFlightShuttleBuilder, + transitionOnUserGestures: true, + child: _TransitionableNavigationBar( + componentsKeys: keys, + backgroundColor: backgroundColor, + backButtonTextStyle: CupertinoTheme.of(context).textTheme.navActionTextStyle, + titleTextStyle: CupertinoTheme.of(context).textTheme.navTitleTextStyle, + largeTitleTextStyle: null, + border: widget.border, + hasUserMiddle: widget.middle != null, + largeExpanded: false, + child: navBar, + ), + ); + }, + ); + } +} + +/// An iOS-styled navigation bar with iOS-11-style large titles using slivers. +/// +/// The [CupertinoSliverNavigationBar] must be placed in a sliver group such +/// as the [CustomScrollView]. +/// +/// This navigation bar consists of two sections, a pinned static section on top +/// and a sliding section containing iOS-11-style large title below it. +/// +/// It should be placed at top of the screen and automatically accounts for +/// the iOS status bar. +/// +/// Minimally, a [largeTitle] widget will appear in the middle of the app bar +/// when the sliver is collapsed and transfer to the area below in larger font +/// when the sliver is expanded. +/// +/// For advanced uses, an optional [middle] widget can be supplied to show a +/// different widget in the middle of the navigation bar when the sliver is collapsed. +/// +/// Like [CupertinoNavigationBar], it also supports a [leading] and [trailing] +/// widget on the static section on top that remains while scrolling. +/// +/// The [leading] widget will automatically be a back chevron icon button (or a +/// close button in case of a fullscreen dialog) to pop the current route if none +/// is provided and [automaticallyImplyLeading] is true (true by default). +/// +/// The [largeTitle] widget will automatically be a title text from the current +/// [CupertinoPageRoute] if none is provided and [automaticallyImplyTitle] is +/// true (true by default). +/// +/// When [transitionBetweenRoutes] is true, this navigation bar will transition +/// on top of the routes instead of inside them if the route being transitioned +/// to also has a [CupertinoNavigationBar] or a [CupertinoSliverNavigationBar] +/// with [transitionBetweenRoutes] set to true. If [transitionBetweenRoutes] is +/// true, none of the [Widget] parameters can contain any [GlobalKey]s in their +/// subtrees since those widgets will exist in multiple places in the tree +/// simultaneously. +/// +/// By default, only one [CupertinoNavigationBar] or [CupertinoSliverNavigationBar] +/// should be present in each [PageRoute] to support the default transitions. +/// Use [transitionBetweenRoutes] or [heroTag] to customize the transition +/// behavior for multiple navigation bars per route. +/// +/// [CupertinoSliverNavigationBar] by default disables text scaling to match the +/// native iOS behavior. To override this behavior, wrap each of the +/// [CupertinoSliverNavigationBar]'s components inside a [MediaQuery] with the +/// desired [TextScaler]. +/// +/// The [stretch] parameter determines whether the nav bar should stretch to +/// fill the over-scroll area. The nav bar can still expand and contract as the +/// user scrolls, but it will also stretch when the user over-scrolls if the +/// [stretch] value is `true`. Defaults to `false`. +/// +/// {@tool dartpad} +/// This example shows [CupertinoSliverNavigationBar] in action inside a [CustomScrollView]. +/// +/// ** See code in examples/api/lib/cupertino/nav_bar/cupertino_sliver_nav_bar.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoNavigationBar], an iOS navigation bar for use on non-scrolling +/// pages. +/// * [CustomScrollView], a ScrollView that creates custom scroll effects using slivers. +/// * +class CupertinoSliverNavigationBar extends StatefulWidget { + /// Creates a navigation bar for scrolling lists. + /// + /// If [automaticallyImplyTitle] is false, then the [largeTitle] argument is + /// required. + const CupertinoSliverNavigationBar({ + super.key, + this.largeTitle, + this.leading, + this.automaticallyImplyLeading = true, + this.automaticallyImplyTitle = true, + this.alwaysShowMiddle = true, + this.previousPageTitle, + this.middle, + this.trailing, + this.border = _kDefaultNavBarBorder, + this.backgroundColor, + this.brightness, + this.padding, + this.transitionBetweenRoutes = true, + this.heroTag = _defaultHeroTag, + this.stretch = false, + }) : assert( + automaticallyImplyTitle || largeTitle != null, + 'No largeTitle has been provided but automaticallyImplyTitle is also ' + 'false. Either provide a largeTitle or set automaticallyImplyTitle to ' + 'true.', + ); + + /// The navigation bar's title. + /// + /// This text will appear in the top static navigation bar when collapsed and + /// below the navigation bar, in a larger font, when expanded. + /// + /// A suitable [DefaultTextStyle] is provided around this widget as it is + /// moved around, to change its font size. + /// + /// If [middle] is null, then the [largeTitle] widget will be inserted into + /// the tree in two places when transitioning from the collapsed state to the + /// expanded state. It is therefore imperative that this subtree not contain + /// any [GlobalKey]s, and that it not rely on maintaining state (for example, + /// animations will not survive the transition from one location to the other, + /// and may in fact be visible in two places at once during the transition). + /// + /// If null and [automaticallyImplyTitle] is true, an appropriate [Text] + /// title will be created if the current route is a [CupertinoPageRoute] and + /// has a `title`. + /// + /// This parameter must either be non-null or the route must have a title + /// ([CupertinoPageRoute.title]) and [automaticallyImplyTitle] must be true. + final Widget? largeTitle; + + /// {@macro flutter.cupertino.CupertinoNavigationBar.leading} + /// + /// This widget is visible in both collapsed and expanded states. + final Widget? leading; + + /// {@macro flutter.cupertino.CupertinoNavigationBar.automaticallyImplyLeading} + final bool automaticallyImplyLeading; + + /// Controls whether we should try to imply the [largeTitle] widget if null. + /// + /// If true and [largeTitle] is null, automatically fill in a [Text] widget + /// with the current route's `title` if the route is a [CupertinoPageRoute]. + /// If [largeTitle] widget is not null, this parameter has no effect. + final bool automaticallyImplyTitle; + + /// Controls whether [middle] widget should always be visible (even in + /// expanded state). + /// + /// If true (default) and [middle] is not null, [middle] widget is always + /// visible. If false, [middle] widget is visible only in collapsed state if + /// it is provided. + /// + /// This should be set to false if you only want to show [largeTitle] in + /// expanded state and [middle] in collapsed state. + final bool alwaysShowMiddle; + + /// {@macro flutter.cupertino.CupertinoNavigationBar.previousPageTitle} + final String? previousPageTitle; + + /// A widget to place in the middle of the static navigation bar instead of + /// the [largeTitle]. + /// + /// This widget is visible in both collapsed and expanded states if + /// [alwaysShowMiddle] is true, otherwise just in collapsed state. The text + /// supplied in [largeTitle] will no longer appear in collapsed state if a + /// [middle] widget is provided. + final Widget? middle; + + /// {@macro flutter.cupertino.CupertinoNavigationBar.trailing} + /// + /// This widget is visible in both collapsed and expanded states. + final Widget? trailing; + + /// {@macro flutter.cupertino.CupertinoNavigationBar.backgroundColor} + final Color? backgroundColor; + + /// {@macro flutter.cupertino.CupertinoNavigationBar.brightness} + final Brightness? brightness; + + /// {@macro flutter.cupertino.CupertinoNavigationBar.padding} + final EdgeInsetsDirectional? padding; + + /// {@macro flutter.cupertino.CupertinoNavigationBar.border} + final Border? border; + + /// {@macro flutter.cupertino.CupertinoNavigationBar.transitionBetweenRoutes} + final bool transitionBetweenRoutes; + + /// {@macro flutter.cupertino.CupertinoNavigationBar.heroTag} + final Object heroTag; + + /// True if the navigation bar's background color has no transparency. + bool get opaque => backgroundColor?.alpha == 0xFF; + + /// Whether the nav bar should stretch to fill the over-scroll area. + /// + /// The nav bar can still expand and contract as the user scrolls, but it will + /// also stretch when the user over-scrolls if the [stretch] value is `true`. + /// + /// When set to `true`, the nav bar will prevent subsequent slivers from + /// accessing overscrolls. This may be undesirable for using overscroll-based + /// widgets like the [CupertinoSliverRefreshControl]. + /// + /// Defaults to `false`. + final bool stretch; + + @override + State createState() => _CupertinoSliverNavigationBarState(); +} + +// A state class exists for the nav bar so that the keys of its sub-components +// don't change when rebuilding the nav bar, causing the sub-components to +// lose their own states. +class _CupertinoSliverNavigationBarState extends State { + late _NavigationBarStaticComponentsKeys keys; + + @override + void initState() { + super.initState(); + keys = _NavigationBarStaticComponentsKeys(); + } + + @override + Widget build(BuildContext context) { + final _NavigationBarStaticComponents components = _NavigationBarStaticComponents( + keys: keys, + route: ModalRoute.of(context), + userLeading: widget.leading, + automaticallyImplyLeading: widget.automaticallyImplyLeading, + automaticallyImplyTitle: widget.automaticallyImplyTitle, + previousPageTitle: widget.previousPageTitle, + userMiddle: widget.middle, + userTrailing: widget.trailing, + userLargeTitle: widget.largeTitle, + padding: widget.padding, + large: true, + ); + + return MediaQuery.withNoTextScaling( + child: SliverPersistentHeader( + pinned: true, // iOS navigation bars are always pinned. + delegate: _LargeTitleNavigationBarSliverDelegate( + keys: keys, + components: components, + userMiddle: widget.middle, + backgroundColor: CupertinoDynamicColor.maybeResolve(widget.backgroundColor, context) ?? CupertinoTheme.of(context).barBackgroundColor, + brightness: widget.brightness, + border: widget.border, + padding: widget.padding, + actionsForegroundColor: CupertinoTheme.of(context).primaryColor, + transitionBetweenRoutes: widget.transitionBetweenRoutes, + heroTag: widget.heroTag, + persistentHeight: _kNavBarPersistentHeight + MediaQuery.paddingOf(context).top, + alwaysShowMiddle: widget.alwaysShowMiddle && widget.middle != null, + stretchConfiguration: widget.stretch ? OverScrollHeaderStretchConfiguration() : null, + ), + ), + ); + } +} + +class _LargeTitleNavigationBarSliverDelegate + extends SliverPersistentHeaderDelegate with DiagnosticableTreeMixin { + _LargeTitleNavigationBarSliverDelegate({ + required this.keys, + required this.components, + required this.userMiddle, + required this.backgroundColor, + required this.brightness, + required this.border, + required this.padding, + required this.actionsForegroundColor, + required this.transitionBetweenRoutes, + required this.heroTag, + required this.persistentHeight, + required this.alwaysShowMiddle, + required this.stretchConfiguration, + }); + + final _NavigationBarStaticComponentsKeys keys; + final _NavigationBarStaticComponents components; + final Widget? userMiddle; + final Color backgroundColor; + final Brightness? brightness; + final Border? border; + final EdgeInsetsDirectional? padding; + final Color actionsForegroundColor; + final bool transitionBetweenRoutes; + final Object heroTag; + final double persistentHeight; + final bool alwaysShowMiddle; + + @override + double get minExtent => persistentHeight; + + @override + double get maxExtent => persistentHeight + _kNavBarLargeTitleHeightExtension; + + @override + OverScrollHeaderStretchConfiguration? stretchConfiguration; + + @override + Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) { + final bool showLargeTitle = shrinkOffset < maxExtent - minExtent - _kNavBarShowLargeTitleThreshold; + + final _PersistentNavigationBar persistentNavigationBar = + _PersistentNavigationBar( + components: components, + padding: padding, + // If a user specified middle exists, always show it. Otherwise, show + // title when sliver is collapsed. + middleVisible: alwaysShowMiddle ? null : !showLargeTitle, + ); + + final Widget navBar = _wrapWithBackground( + border: border, + backgroundColor: CupertinoDynamicColor.resolve(backgroundColor, context), + brightness: brightness, + child: DefaultTextStyle( + style: CupertinoTheme.of(context).textTheme.textStyle, + child: Stack( + fit: StackFit.expand, + children: [ + Positioned( + top: persistentHeight, + left: 0.0, + right: 0.0, + bottom: 0.0, + child: ClipRect( + child: Padding( + padding: const EdgeInsetsDirectional.only( + start: _kNavBarEdgePadding, + bottom: _kNavBarBottomPadding + ), + child: SafeArea( + top: false, + bottom: false, + child: AnimatedOpacity( + opacity: showLargeTitle ? 1.0 : 0.0, + duration: _kNavBarTitleFadeDuration, + child: Semantics( + header: true, + child: DefaultTextStyle( + style: CupertinoTheme.of(context) + .textTheme + .navLargeTitleTextStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + child: _LargeTitle( + child: components.largeTitle, + ), + ), + ), + ), + ), + ), + ), + ), + Positioned( + left: 0.0, + right: 0.0, + top: 0.0, + child: persistentNavigationBar, + ), + ], + ), + ), + ); + + if (!transitionBetweenRoutes || !_isTransitionable(context)) { + return navBar; + } + + return Hero( + tag: heroTag == _defaultHeroTag + ? _HeroTag(Navigator.of(context)) + : heroTag, + createRectTween: _linearTranslateWithLargestRectSizeTween, + flightShuttleBuilder: _navBarHeroFlightShuttleBuilder, + placeholderBuilder: _navBarHeroLaunchPadBuilder, + transitionOnUserGestures: true, + // This is all the way down here instead of being at the top level of + // CupertinoSliverNavigationBar like CupertinoNavigationBar because it + // needs to wrap the top level RenderBox rather than a RenderSliver. + child: _TransitionableNavigationBar( + componentsKeys: keys, + backgroundColor: CupertinoDynamicColor.resolve(backgroundColor, context), + backButtonTextStyle: CupertinoTheme.of(context).textTheme.navActionTextStyle, + titleTextStyle: CupertinoTheme.of(context).textTheme.navTitleTextStyle, + largeTitleTextStyle: CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle, + border: border, + hasUserMiddle: userMiddle != null && (alwaysShowMiddle || !showLargeTitle), + largeExpanded: showLargeTitle, + child: navBar, + ), + ); + } + + @override + bool shouldRebuild(_LargeTitleNavigationBarSliverDelegate oldDelegate) { + return components != oldDelegate.components + || userMiddle != oldDelegate.userMiddle + || backgroundColor != oldDelegate.backgroundColor + || border != oldDelegate.border + || padding != oldDelegate.padding + || actionsForegroundColor != oldDelegate.actionsForegroundColor + || transitionBetweenRoutes != oldDelegate.transitionBetweenRoutes + || persistentHeight != oldDelegate.persistentHeight + || alwaysShowMiddle != oldDelegate.alwaysShowMiddle + || heroTag != oldDelegate.heroTag; + } +} + +/// The large title of the navigation bar. +/// +/// Magnifies on over-scroll when [CupertinoSliverNavigationBar.stretch] +/// parameter is true. +class _LargeTitle extends SingleChildRenderObjectWidget { + const _LargeTitle({ super.child }); + + @override + _RenderLargeTitle createRenderObject(BuildContext context) { + return _RenderLargeTitle(alignment: AlignmentDirectional.bottomStart.resolve(Directionality.of(context))); + } + + @override + void updateRenderObject(BuildContext context, _RenderLargeTitle renderObject) { + renderObject.alignment = AlignmentDirectional.bottomStart.resolve(Directionality.of(context)); + } +} + +class _RenderLargeTitle extends RenderShiftedBox { + _RenderLargeTitle({ + required Alignment alignment, + }) : _alignment = alignment, + super(null); + + Alignment get alignment => _alignment; + Alignment _alignment; + set alignment(Alignment value) { + if (_alignment == value) { + return; + } + _alignment = value; + + markNeedsLayout(); + } + + double _scale = 1.0; + + @override + void performLayout() { + final RenderBox? child = this.child; + Size childSize = Size.zero; + + size = constraints.biggest; + + if (child == null) { + return; + } + + final BoxConstraints childConstraints = constraints.widthConstraints().loosen(); + child.layout(childConstraints, parentUsesSize: true); + + final double maxScale = child.size.width != 0.0 + ? clampDouble(constraints.maxWidth / child.size.width, 1.0, 1.1) + : 1.1; + _scale = clampDouble( + 1.0 + (constraints.maxHeight - (_kNavBarLargeTitleHeightExtension - _kNavBarBottomPadding)) / (_kNavBarLargeTitleHeightExtension - _kNavBarBottomPadding) * 0.03, + 1.0, + maxScale, + ); + + childSize = child.size * _scale; + final BoxParentData childParentData = child.parentData! as BoxParentData; + childParentData.offset = alignment.alongOffset(size - childSize as Offset); + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + assert(child == this.child); + + super.applyPaintTransform(child, transform); + + transform.scale(_scale, _scale); + } + + @override + void paint(PaintingContext context, Offset offset) { + final RenderBox? child = this.child; + + if (child == null) { + layer = null; + } else { + final BoxParentData childParentData = child.parentData! as BoxParentData; + + layer = context.pushTransform( + needsCompositing, + offset + childParentData.offset, + Matrix4.diagonal3Values(_scale, _scale, 1.0), + (PaintingContext context, Offset offset) => context.paintChild(child, offset), + oldLayer: layer as TransformLayer?, + ); + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, {required Offset position}) { + final RenderBox? child = this.child; + + if (child == null) { + return false; + } + + final Offset childOffset = (child.parentData! as BoxParentData).offset; + + final Matrix4 transform = Matrix4.identity() + ..scale(1.0/_scale, 1.0/_scale, 1.0) + ..translate(-childOffset.dx, -childOffset.dy); + + return result.addWithRawTransform( + transform: transform, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + return child.hitTest(result, position: transformed); + } + ); + } +} + +/// The top part of the navigation bar that's never scrolled away. +/// +/// Consists of the entire navigation bar without background and border when used +/// without large titles. With large titles, it's the top static half that +/// doesn't scroll. +class _PersistentNavigationBar extends StatelessWidget { + const _PersistentNavigationBar({ + required this.components, + this.padding, + this.middleVisible, + }); + + final _NavigationBarStaticComponents components; + + final EdgeInsetsDirectional? padding; + /// Whether the middle widget has a visible animated opacity. A null value + /// means the middle opacity will not be animated. + final bool? middleVisible; + + @override + Widget build(BuildContext context) { + Widget? middle = components.middle; + + if (middle != null) { + middle = DefaultTextStyle( + style: CupertinoTheme.of(context).textTheme.navTitleTextStyle, + child: Semantics(header: true, child: middle), + ); + // When the middle's visibility can change on the fly like with large title + // slivers, wrap with animated opacity. + middle = middleVisible == null + ? middle + : AnimatedOpacity( + opacity: middleVisible! ? 1.0 : 0.0, + duration: _kNavBarTitleFadeDuration, + child: middle, + ); + } + + Widget? leading = components.leading; + final Widget? backChevron = components.backChevron; + final Widget? backLabel = components.backLabel; + + if (leading == null && backChevron != null && backLabel != null) { + leading = CupertinoNavigationBarBackButton._assemble( + backChevron, + backLabel, + ); + } + + Widget paddedToolbar = NavigationToolbar( + leading: leading, + middle: middle, + trailing: components.trailing, + middleSpacing: 6.0, + ); + + if (padding != null) { + paddedToolbar = Padding( + padding: EdgeInsets.only( + top: padding!.top, + bottom: padding!.bottom, + ), + child: paddedToolbar, + ); + } + + return SizedBox( + height: _kNavBarPersistentHeight + MediaQuery.paddingOf(context).top, + child: SafeArea( + bottom: false, + child: paddedToolbar, + ), + ); + } +} + +// A collection of keys always used when building static routes' nav bars's +// components with _NavigationBarStaticComponents and read in +// _NavigationBarTransition in Hero flights in order to reference the components' +// RenderBoxes for their positions. +// +// These keys should never re-appear inside the Hero flights. +@immutable +class _NavigationBarStaticComponentsKeys { + _NavigationBarStaticComponentsKeys() + : navBarBoxKey = GlobalKey(debugLabel: 'Navigation bar render box'), + leadingKey = GlobalKey(debugLabel: 'Leading'), + backChevronKey = GlobalKey(debugLabel: 'Back chevron'), + backLabelKey = GlobalKey(debugLabel: 'Back label'), + middleKey = GlobalKey(debugLabel: 'Middle'), + trailingKey = GlobalKey(debugLabel: 'Trailing'), + largeTitleKey = GlobalKey(debugLabel: 'Large title'); + + final GlobalKey navBarBoxKey; + final GlobalKey leadingKey; + final GlobalKey backChevronKey; + final GlobalKey backLabelKey; + final GlobalKey middleKey; + final GlobalKey trailingKey; + final GlobalKey largeTitleKey; +} + +// Based on various user Widgets and other parameters, construct KeyedSubtree +// components that are used in common by the CupertinoNavigationBar and +// CupertinoSliverNavigationBar. The KeyedSubtrees are inserted into static +// routes and the KeyedSubtrees' child are reused in the Hero flights. +@immutable +class _NavigationBarStaticComponents { + _NavigationBarStaticComponents({ + required _NavigationBarStaticComponentsKeys keys, + required ModalRoute? route, + required Widget? userLeading, + required bool automaticallyImplyLeading, + required bool automaticallyImplyTitle, + required String? previousPageTitle, + required Widget? userMiddle, + required Widget? userTrailing, + required Widget? userLargeTitle, + required EdgeInsetsDirectional? padding, + required bool large, + }) : leading = createLeading( + leadingKey: keys.leadingKey, + userLeading: userLeading, + route: route, + automaticallyImplyLeading: automaticallyImplyLeading, + padding: padding, + ), + backChevron = createBackChevron( + backChevronKey: keys.backChevronKey, + userLeading: userLeading, + route: route, + automaticallyImplyLeading: automaticallyImplyLeading, + ), + backLabel = createBackLabel( + backLabelKey: keys.backLabelKey, + userLeading: userLeading, + route: route, + previousPageTitle: previousPageTitle, + automaticallyImplyLeading: automaticallyImplyLeading, + ), + middle = createMiddle( + middleKey: keys.middleKey, + userMiddle: userMiddle, + userLargeTitle: userLargeTitle, + route: route, + automaticallyImplyTitle: automaticallyImplyTitle, + large: large, + ), + trailing = createTrailing( + trailingKey: keys.trailingKey, + userTrailing: userTrailing, + padding: padding, + ), + largeTitle = createLargeTitle( + largeTitleKey: keys.largeTitleKey, + userLargeTitle: userLargeTitle, + route: route, + automaticImplyTitle: automaticallyImplyTitle, + large: large, + ); + + static Widget? _derivedTitle({ + required bool automaticallyImplyTitle, + ModalRoute? currentRoute, + }) { + // Auto use the CupertinoPageRoute's title if middle not provided. + if (automaticallyImplyTitle && + currentRoute is CupertinoRouteTransitionMixin && + currentRoute.title != null) { + return Text(currentRoute.title!); + } + + return null; + } + + final KeyedSubtree? leading; + static KeyedSubtree? createLeading({ + required GlobalKey leadingKey, + required Widget? userLeading, + required ModalRoute? route, + required bool automaticallyImplyLeading, + required EdgeInsetsDirectional? padding, + }) { + Widget? leadingContent; + + if (userLeading != null) { + leadingContent = userLeading; + } else if ( + automaticallyImplyLeading && + route is PageRoute && + route.canPop && + route.fullscreenDialog + ) { + leadingContent = CupertinoButton( + padding: EdgeInsets.zero, + onPressed: () { route.navigator!.maybePop(); }, + child: const Text('Close'), + ); + } + + if (leadingContent == null) { + return null; + } + + return KeyedSubtree( + key: leadingKey, + child: Padding( + padding: EdgeInsetsDirectional.only( + start: padding?.start ?? _kNavBarEdgePadding, + ), + child: IconTheme.merge( + data: const IconThemeData( + size: 32.0, + ), + child: leadingContent, + ), + ), + ); + } + + final KeyedSubtree? backChevron; + static KeyedSubtree? createBackChevron({ + required GlobalKey backChevronKey, + required Widget? userLeading, + required ModalRoute? route, + required bool automaticallyImplyLeading, + }) { + if ( + userLeading != null || + !automaticallyImplyLeading || + route == null || + !route.canPop || + (route is PageRoute && route.fullscreenDialog) + ) { + return null; + } + + return KeyedSubtree(key: backChevronKey, child: const _BackChevron()); + } + + /// This widget is not decorated with a font since the font style could + /// animate during transitions. + final KeyedSubtree? backLabel; + static KeyedSubtree? createBackLabel({ + required GlobalKey backLabelKey, + required Widget? userLeading, + required ModalRoute? route, + required bool automaticallyImplyLeading, + required String? previousPageTitle, + }) { + if ( + userLeading != null || + !automaticallyImplyLeading || + route == null || + !route.canPop || + (route is PageRoute && route.fullscreenDialog) + ) { + return null; + } + + return KeyedSubtree( + key: backLabelKey, + child: _BackLabel( + specifiedPreviousTitle: previousPageTitle, + route: route, + ), + ); + } + + /// This widget is not decorated with a font since the font style could + /// animate during transitions. + final KeyedSubtree? middle; + static KeyedSubtree? createMiddle({ + required GlobalKey middleKey, + required Widget? userMiddle, + required Widget? userLargeTitle, + required bool large, + required bool automaticallyImplyTitle, + required ModalRoute? route, + }) { + Widget? middleContent = userMiddle; + + if (large) { + middleContent ??= userLargeTitle; + } + + middleContent ??= _derivedTitle( + automaticallyImplyTitle: automaticallyImplyTitle, + currentRoute: route, + ); + + if (middleContent == null) { + return null; + } + + return KeyedSubtree( + key: middleKey, + child: middleContent, + ); + } + + final KeyedSubtree? trailing; + static KeyedSubtree? createTrailing({ + required GlobalKey trailingKey, + required Widget? userTrailing, + required EdgeInsetsDirectional? padding, + }) { + if (userTrailing == null) { + return null; + } + + return KeyedSubtree( + key: trailingKey, + child: Padding( + padding: EdgeInsetsDirectional.only( + end: padding?.end ?? _kNavBarEdgePadding, + ), + child: IconTheme.merge( + data: const IconThemeData( + size: 32.0, + ), + child: userTrailing, + ), + ), + ); + } + + /// This widget is not decorated with a font since the font style could + /// animate during transitions. + final KeyedSubtree? largeTitle; + static KeyedSubtree? createLargeTitle({ + required GlobalKey largeTitleKey, + required Widget? userLargeTitle, + required bool large, + required bool automaticImplyTitle, + required ModalRoute? route, + }) { + if (!large) { + return null; + } + + final Widget? largeTitleContent = userLargeTitle ?? _derivedTitle( + automaticallyImplyTitle: automaticImplyTitle, + currentRoute: route, + ); + + assert( + largeTitleContent != null, + 'largeTitle was not provided and there was no title from the route.', + ); + + return KeyedSubtree( + key: largeTitleKey, + child: largeTitleContent!, + ); + } +} + +/// A nav bar back button typically used in [CupertinoNavigationBar]. +/// +/// This is automatically inserted into [CupertinoNavigationBar] and +/// [CupertinoSliverNavigationBar]'s `leading` slot when +/// `automaticallyImplyLeading` is true. +/// +/// When manually inserted, the [CupertinoNavigationBarBackButton] should only +/// be used in routes that can be popped unless a custom [onPressed] is +/// provided. +/// +/// Shows a back chevron and the previous route's title when available from +/// the previous [CupertinoPageRoute.title]. If [previousPageTitle] is specified, +/// it will be shown instead. +class CupertinoNavigationBarBackButton extends StatelessWidget { + /// Construct a [CupertinoNavigationBarBackButton] that can be used to pop + /// the current route. + const CupertinoNavigationBarBackButton({ + super.key, + this.color, + this.previousPageTitle, + this.onPressed, + }) : _backChevron = null, + _backLabel = null; + + // Allow the back chevron and label to be separately created (and keyed) + // because they animate separately during page transitions. + const CupertinoNavigationBarBackButton._assemble( + this._backChevron, + this._backLabel, + ) : previousPageTitle = null, + color = null, + onPressed = null; + + /// The [Color] of the back button. + /// + /// Can be used to override the color of the back button chevron and label. + /// + /// Defaults to [CupertinoTheme]'s `primaryColor` if null. + final Color? color; + + /// An override for showing the previous route's title. If null, it will be + /// automatically derived from [CupertinoPageRoute.title] if the current and + /// previous routes are both [CupertinoPageRoute]s. + final String? previousPageTitle; + + /// An override callback to perform instead of the default behavior which is + /// to pop the [Navigator]. + /// + /// It can, for instance, be used to pop the platform's navigation stack + /// via [SystemNavigator] instead of Flutter's [Navigator] in add-to-app + /// situations. + /// + /// Defaults to null. + final VoidCallback? onPressed; + + final Widget? _backChevron; + + final Widget? _backLabel; + + @override + Widget build(BuildContext context) { + final ModalRoute? currentRoute = ModalRoute.of(context); + if (onPressed == null) { + assert( + currentRoute?.canPop ?? false, + 'CupertinoNavigationBarBackButton should only be used in routes that can be popped', + ); + } + + TextStyle actionTextStyle = CupertinoTheme.of(context).textTheme.navActionTextStyle; + if (color != null) { + actionTextStyle = actionTextStyle.copyWith(color: CupertinoDynamicColor.maybeResolve(color, context)); + } + + return CupertinoButton( + padding: EdgeInsets.zero, + child: Semantics( + container: true, + excludeSemantics: true, + label: 'Back', + button: true, + child: DefaultTextStyle( + style: actionTextStyle, + child: ConstrainedBox( + constraints: const BoxConstraints(minWidth: _kNavBarBackButtonTapWidth), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + const Padding(padding: EdgeInsetsDirectional.only(start: 8.0)), + _backChevron ?? const _BackChevron(), + const Padding(padding: EdgeInsetsDirectional.only(start: 6.0)), + Flexible( + child: _backLabel ?? _BackLabel( + specifiedPreviousTitle: previousPageTitle, + route: currentRoute, + ), + ), + ], + ), + ), + ), + ), + onPressed: () { + if (onPressed != null) { + onPressed!(); + } else { + Navigator.maybePop(context); + } + }, + ); + } +} + + +class _BackChevron extends StatelessWidget { + const _BackChevron(); + + @override + Widget build(BuildContext context) { + final TextDirection textDirection = Directionality.of(context); + final TextStyle textStyle = DefaultTextStyle.of(context).style; + + // Replicate the Icon logic here to get a tightly sized icon and add + // custom non-square padding. + Widget iconWidget = Padding( + padding: const EdgeInsetsDirectional.only(start: 6, end: 2), + child: Text.rich( + TextSpan( + text: String.fromCharCode(CupertinoIcons.back.codePoint), + style: TextStyle( + inherit: false, + color: textStyle.color, + fontSize: 30.0, + fontFamily: CupertinoIcons.back.fontFamily, + package: CupertinoIcons.back.fontPackage, + ), + ), + ), + ); + switch (textDirection) { + case TextDirection.rtl: + iconWidget = Transform( + transform: Matrix4.identity()..scale(-1.0, 1.0, 1.0), + alignment: Alignment.center, + transformHitTests: false, + child: iconWidget, + ); + case TextDirection.ltr: + break; + } + + return iconWidget; + } +} + +/// A widget that shows next to the back chevron when `automaticallyImplyLeading` +/// is true. +class _BackLabel extends StatelessWidget { + const _BackLabel({ + required this.specifiedPreviousTitle, + required this.route, + }); + + final String? specifiedPreviousTitle; + final ModalRoute? route; + + // `child` is never passed in into ValueListenableBuilder so it's always + // null here and unused. + Widget _buildPreviousTitleWidget(BuildContext context, String? previousTitle, Widget? child) { + if (previousTitle == null) { + return const SizedBox.shrink(); + } + + Text textWidget = Text( + previousTitle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ); + + if (previousTitle.length > 12) { + textWidget = const Text('Back'); + } + + return Align( + alignment: AlignmentDirectional.centerStart, + widthFactor: 1.0, + child: textWidget, + ); + } + + @override + Widget build(BuildContext context) { + if (specifiedPreviousTitle != null) { + return _buildPreviousTitleWidget(context, specifiedPreviousTitle, null); + } else if (route is CupertinoRouteTransitionMixin && !route!.isFirst) { + final CupertinoRouteTransitionMixin cupertinoRoute = route! as CupertinoRouteTransitionMixin; + // There is no timing issue because the previousTitle Listenable changes + // happen during route modifications before the ValueListenableBuilder + // is built. + return ValueListenableBuilder( + valueListenable: cupertinoRoute.previousTitle, + builder: _buildPreviousTitleWidget, + ); + } else { + return const SizedBox.shrink(); + } + } +} + +/// This should always be the first child of Hero widgets. +/// +/// This class helps each Hero transition obtain the start or end navigation +/// bar's box size and the inner components of the navigation bar that will +/// move around. +/// +/// It should be wrapped around the biggest [RenderBox] of the static +/// navigation bar in each route. +class _TransitionableNavigationBar extends StatelessWidget { + _TransitionableNavigationBar({ + required this.componentsKeys, + required this.backgroundColor, + required this.backButtonTextStyle, + required this.titleTextStyle, + required this.largeTitleTextStyle, + required this.border, + required this.hasUserMiddle, + required this.largeExpanded, + required this.child, + }) : assert(!largeExpanded || largeTitleTextStyle != null), + super(key: componentsKeys.navBarBoxKey); + + final _NavigationBarStaticComponentsKeys componentsKeys; + final Color? backgroundColor; + final TextStyle backButtonTextStyle; + final TextStyle titleTextStyle; + final TextStyle? largeTitleTextStyle; + final Border? border; + final bool hasUserMiddle; + final bool largeExpanded; + final Widget child; + + RenderBox get renderBox { + final RenderBox box = componentsKeys.navBarBoxKey.currentContext!.findRenderObject()! as RenderBox; + assert( + box.attached, + '_TransitionableNavigationBar.renderBox should be called when building ' + 'hero flight shuttles when the from and the to nav bar boxes are already ' + 'laid out and painted.', + ); + return box; + } + + @override + Widget build(BuildContext context) { + assert(() { + bool inHero = false; + context.visitAncestorElements((Element ancestor) { + if (ancestor is ComponentElement) { + assert( + ancestor.widget.runtimeType != _NavigationBarTransition, + '_TransitionableNavigationBar should never re-appear inside ' + '_NavigationBarTransition. Keyed _TransitionableNavigationBar should ' + 'only serve as anchor points in routes rather than appearing inside ' + 'Hero flights themselves.', + ); + if (ancestor.widget.runtimeType == Hero) { + inHero = true; + } + } + return true; + }); + assert( + inHero, + '_TransitionableNavigationBar should only be added as the immediate ' + 'child of Hero widgets.', + ); + return true; + }()); + return child; + } +} + +/// This class represents the widget that will be in the Hero flight instead of +/// the 2 static navigation bars by taking inner components from both. +/// +/// The `topNavBar` parameter is the nav bar that was on top regardless of +/// push/pop direction. +/// +/// Similarly, the `bottomNavBar` parameter is the nav bar that was at the +/// bottom regardless of the push/pop direction. +/// +/// If [MediaQuery.padding] is still present in this widget's [BuildContext], +/// that padding will become part of the transitional navigation bar as well. +/// +/// [MediaQuery.padding] should be consistent between the from/to routes and +/// the Hero overlay. Inconsistent [MediaQuery.padding] will produce undetermined +/// results. +class _NavigationBarTransition extends StatelessWidget { + _NavigationBarTransition({ + required this.animation, + required this.topNavBar, + required this.bottomNavBar, + }) : heightTween = Tween( + begin: bottomNavBar.renderBox.size.height, + end: topNavBar.renderBox.size.height, + ), + backgroundTween = ColorTween( + begin: bottomNavBar.backgroundColor, + end: topNavBar.backgroundColor, + ), + borderTween = BorderTween( + begin: bottomNavBar.border, + end: topNavBar.border, + ); + + final Animation animation; + final _TransitionableNavigationBar topNavBar; + final _TransitionableNavigationBar bottomNavBar; + + final Tween heightTween; + final ColorTween backgroundTween; + final BorderTween borderTween; + + @override + Widget build(BuildContext context) { + final _NavigationBarComponentsTransition componentsTransition = _NavigationBarComponentsTransition( + animation: animation, + bottomNavBar: bottomNavBar, + topNavBar: topNavBar, + directionality: Directionality.of(context), + ); + + final List children = [ + // Draw an empty navigation bar box with changing shape behind all the + // moving components without any components inside it itself. + AnimatedBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + return _wrapWithBackground( + // Don't update the system status bar color mid-flight. + updateSystemUiOverlay: false, + backgroundColor: backgroundTween.evaluate(animation)!, + border: borderTween.evaluate(animation), + child: SizedBox( + height: heightTween.evaluate(animation), + width: double.infinity, + ), + ); + }, + ), + // Draw all the components on top of the empty bar box. + if (componentsTransition.bottomBackChevron != null) componentsTransition.bottomBackChevron!, + if (componentsTransition.bottomBackLabel != null) componentsTransition.bottomBackLabel!, + if (componentsTransition.bottomLeading != null) componentsTransition.bottomLeading!, + if (componentsTransition.bottomMiddle != null) componentsTransition.bottomMiddle!, + if (componentsTransition.bottomLargeTitle != null) componentsTransition.bottomLargeTitle!, + if (componentsTransition.bottomTrailing != null) componentsTransition.bottomTrailing!, + // Draw top components on top of the bottom components. + if (componentsTransition.topLeading != null) componentsTransition.topLeading!, + if (componentsTransition.topBackChevron != null) componentsTransition.topBackChevron!, + if (componentsTransition.topBackLabel != null) componentsTransition.topBackLabel!, + if (componentsTransition.topMiddle != null) componentsTransition.topMiddle!, + if (componentsTransition.topLargeTitle != null) componentsTransition.topLargeTitle!, + if (componentsTransition.topTrailing != null) componentsTransition.topTrailing!, + ]; + + + // The actual outer box is big enough to contain both the bottom and top + // navigation bars. It's not a direct Rect lerp because some components + // can actually be outside the linearly lerp'ed Rect in the middle of + // the animation, such as the topLargeTitle. The text scaling is disabled to + // avoid odd transitions between pages. + return MediaQuery.withNoTextScaling( + child: SizedBox( + height: math.max(heightTween.begin!, heightTween.end!) + MediaQuery.paddingOf(context).top, + width: double.infinity, + child: Stack( + children: children, + ), + ), + ); + } +} + +/// This class helps create widgets that are in transition based on static +/// components from the bottom and top navigation bars. +/// +/// It animates these transitional components both in terms of position and +/// their appearance. +/// +/// Instead of running the transitional components through their normal static +/// navigation bar layout logic, this creates transitional widgets that are based +/// on these widgets' existing render objects' layout and position. +/// +/// This is possible because this widget is only used during Hero transitions +/// where both the from and to routes are already built and laid out. +/// +/// The components' existing layout constraints and positions are then +/// replicated using [Positioned] or [PositionedTransition] wrappers. +/// +/// This class should never return [KeyedSubtree]s created by +/// _NavigationBarStaticComponents directly. Since widgets from +/// _NavigationBarStaticComponents are still present in the widget tree during the +/// hero transitions, it would cause global key duplications. Instead, return +/// only the [KeyedSubtree]s' child. +@immutable +class _NavigationBarComponentsTransition { + _NavigationBarComponentsTransition({ + required this.animation, + required _TransitionableNavigationBar bottomNavBar, + required _TransitionableNavigationBar topNavBar, + required TextDirection directionality, + }) : bottomComponents = bottomNavBar.componentsKeys, + topComponents = topNavBar.componentsKeys, + bottomNavBarBox = bottomNavBar.renderBox, + topNavBarBox = topNavBar.renderBox, + bottomBackButtonTextStyle = bottomNavBar.backButtonTextStyle, + topBackButtonTextStyle = topNavBar.backButtonTextStyle, + bottomTitleTextStyle = bottomNavBar.titleTextStyle, + topTitleTextStyle = topNavBar.titleTextStyle, + bottomLargeTitleTextStyle = bottomNavBar.largeTitleTextStyle, + topLargeTitleTextStyle = topNavBar.largeTitleTextStyle, + bottomHasUserMiddle = bottomNavBar.hasUserMiddle, + topHasUserMiddle = topNavBar.hasUserMiddle, + bottomLargeExpanded = bottomNavBar.largeExpanded, + topLargeExpanded = topNavBar.largeExpanded, + transitionBox = + // paintBounds are based on offset zero so it's ok to expand the Rects. + bottomNavBar.renderBox.paintBounds.expandToInclude(topNavBar.renderBox.paintBounds), + forwardDirection = directionality == TextDirection.ltr ? 1.0 : -1.0; + + static final Animatable fadeOut = Tween( + begin: 1.0, + end: 0.0, + ); + static final Animatable fadeIn = Tween( + begin: 0.0, + end: 1.0, + ); + + final Animation animation; + final _NavigationBarStaticComponentsKeys bottomComponents; + final _NavigationBarStaticComponentsKeys topComponents; + + // These render boxes that are the ancestors of all the bottom and top + // components are used to determine the components' relative positions inside + // their respective navigation bars. + final RenderBox bottomNavBarBox; + final RenderBox topNavBarBox; + + final TextStyle bottomBackButtonTextStyle; + final TextStyle topBackButtonTextStyle; + final TextStyle bottomTitleTextStyle; + final TextStyle topTitleTextStyle; + final TextStyle? bottomLargeTitleTextStyle; + final TextStyle? topLargeTitleTextStyle; + + final bool bottomHasUserMiddle; + final bool topHasUserMiddle; + final bool bottomLargeExpanded; + final bool topLargeExpanded; + + // This is the outer box in which all the components will be fitted. The + // sizing component of RelativeRects will be based on this rect's size. + final Rect transitionBox; + + // x-axis unity number representing the direction of growth for text. + final double forwardDirection; + + // Take a widget it its original ancestor navigation bar render box and + // translate it into a RelativeBox in the transition navigation bar box. + RelativeRect positionInTransitionBox( + GlobalKey key, { + required RenderBox from, + }) { + final RenderBox componentBox = key.currentContext!.findRenderObject()! as RenderBox; + assert(componentBox.attached); + + return RelativeRect.fromRect( + componentBox.localToGlobal(Offset.zero, ancestor: from) & componentBox.size, + transitionBox, + ); + } + + // Create an animated widget that moves the given child widget between its + // original position in its ancestor navigation bar to another widget's + // position in that widget's navigation bar. + // + // Anchor their positions based on the vertical middle of their respective + // render boxes' leading edge. + // + // This method assumes there's no other transforms other than translations + // when converting a rect from the original navigation bar's coordinate space + // to the other navigation bar's coordinate space, to avoid performing + // floating point operations on the size of the child widget, so that the + // incoming constraints used for sizing the child widget will be exactly the + // same. + _FixedSizeSlidingTransition slideFromLeadingEdge({ + required GlobalKey fromKey, + required RenderBox fromNavBarBox, + required GlobalKey toKey, + required RenderBox toNavBarBox, + required Widget child, + }) { + final RenderBox fromBox = fromKey.currentContext!.findRenderObject()! as RenderBox; + final RenderBox toBox = toKey.currentContext!.findRenderObject()! as RenderBox; + + final bool isLTR = forwardDirection > 0; + + // The animation moves the fromBox so its anchor (left-center or right-center + // depending on the writing direction) aligns with toBox's anchor. + final Offset fromAnchorLocal = Offset( + isLTR ? 0 : fromBox.size.width, + fromBox.size.height / 2, + ); + final Offset toAnchorLocal = Offset( + isLTR ? 0 : toBox.size.width, + toBox.size.height / 2, + ); + final Offset fromAnchorInFromBox = fromBox.localToGlobal(fromAnchorLocal, ancestor: fromNavBarBox); + final Offset toAnchorInToBox = toBox.localToGlobal(toAnchorLocal, ancestor: toNavBarBox); + + // We can't get ahold of the render box of the stack (i.e., `transitionBox`) + // we place components on yet, but we know the stack needs to be top-leading + // aligned with both fromNavBarBox and toNavBarBox to make the transition + // look smooth. Also use the top-leading point as the origin for ease of + // calculation. + + // The offset to move fromAnchor to toAnchor, in transitionBox's top-leading + // coordinates. + final Offset translation = isLTR + ? toAnchorInToBox - fromAnchorInFromBox + : Offset(toNavBarBox.size.width - toAnchorInToBox.dx, toAnchorInToBox.dy) + - Offset(fromNavBarBox.size.width - fromAnchorInFromBox.dx, fromAnchorInFromBox.dy); + + final RelativeRect fromBoxMargin = positionInTransitionBox(fromKey, from: fromNavBarBox); + final Offset fromOriginInTransitionBox = Offset( + isLTR ? fromBoxMargin.left : fromBoxMargin.right, + fromBoxMargin.top, + ); + + final Tween anchorMovementInTransitionBox = Tween( + begin: fromOriginInTransitionBox, + end: fromOriginInTransitionBox + translation, + ); + + return _FixedSizeSlidingTransition( + isLTR: isLTR, + offsetAnimation: animation.drive(anchorMovementInTransitionBox), + size: fromBox.size, + child: child, + ); + } + + Animation fadeInFrom(double t, { Curve curve = Curves.easeIn }) { + return animation.drive(fadeIn.chain( + CurveTween(curve: Interval(t, 1.0, curve: curve)), + )); + } + + Animation fadeOutBy(double t, { Curve curve = Curves.easeOut }) { + return animation.drive(fadeOut.chain( + CurveTween(curve: Interval(0.0, t, curve: curve)), + )); + } + + Widget? get bottomLeading { + final KeyedSubtree? bottomLeading = bottomComponents.leadingKey.currentWidget as KeyedSubtree?; + + if (bottomLeading == null) { + return null; + } + + return Positioned.fromRelativeRect( + rect: positionInTransitionBox(bottomComponents.leadingKey, from: bottomNavBarBox), + child: FadeTransition( + opacity: fadeOutBy(0.4), + child: bottomLeading.child, + ), + ); + } + + Widget? get bottomBackChevron { + final KeyedSubtree? bottomBackChevron = bottomComponents.backChevronKey.currentWidget as KeyedSubtree?; + + if (bottomBackChevron == null) { + return null; + } + + return Positioned.fromRelativeRect( + rect: positionInTransitionBox(bottomComponents.backChevronKey, from: bottomNavBarBox), + child: FadeTransition( + opacity: fadeOutBy(0.6), + child: DefaultTextStyle( + style: bottomBackButtonTextStyle, + child: bottomBackChevron.child, + ), + ), + ); + } + + Widget? get bottomBackLabel { + final KeyedSubtree? bottomBackLabel = bottomComponents.backLabelKey.currentWidget as KeyedSubtree?; + + if (bottomBackLabel == null) { + return null; + } + + final RelativeRect from = positionInTransitionBox(bottomComponents.backLabelKey, from: bottomNavBarBox); + + // Transition away by sliding horizontally to the leading edge off of the screen. + final RelativeRectTween positionTween = RelativeRectTween( + begin: from, + end: from.shift( + Offset( + forwardDirection * (-bottomNavBarBox.size.width / 2.0), + 0.0, + ), + ), + ); + + return PositionedTransition( + rect: animation.drive(positionTween), + child: FadeTransition( + opacity: fadeOutBy(0.2), + child: DefaultTextStyle( + style: bottomBackButtonTextStyle, + child: bottomBackLabel.child, + ), + ), + ); + } + + Widget? get bottomMiddle { + final KeyedSubtree? bottomMiddle = bottomComponents.middleKey.currentWidget as KeyedSubtree?; + final KeyedSubtree? topBackLabel = topComponents.backLabelKey.currentWidget as KeyedSubtree?; + final KeyedSubtree? topLeading = topComponents.leadingKey.currentWidget as KeyedSubtree?; + + // The middle component is non-null when the nav bar is a large title + // nav bar but would be invisible when expanded, therefore don't show it here. + if (!bottomHasUserMiddle && bottomLargeExpanded) { + return null; + } + + if (bottomMiddle != null && topBackLabel != null) { + // Move from current position to the top page's back label position. + return slideFromLeadingEdge( + fromKey: bottomComponents.middleKey, + fromNavBarBox: bottomNavBarBox, + toKey: topComponents.backLabelKey, + toNavBarBox: topNavBarBox, + child: FadeTransition( + // A custom middle widget like a segmented control fades away faster. + opacity: fadeOutBy(bottomHasUserMiddle ? 0.4 : 0.7), + child: Align( + // As the text shrinks, make sure it's still anchored to the leading + // edge of a constantly sized outer box. + alignment: AlignmentDirectional.centerStart, + child: DefaultTextStyleTransition( + style: animation.drive(TextStyleTween( + begin: bottomTitleTextStyle, + end: topBackButtonTextStyle, + )), + child: bottomMiddle.child, + ), + ), + ), + ); + } + + // When the top page has a leading widget override (one of the few ways to + // not have a top back label), don't move the bottom middle widget and just + // fade. + if (bottomMiddle != null && topLeading != null) { + return Positioned.fromRelativeRect( + rect: positionInTransitionBox(bottomComponents.middleKey, from: bottomNavBarBox), + child: FadeTransition( + opacity: fadeOutBy(bottomHasUserMiddle ? 0.4 : 0.7), + // Keep the font when transitioning into a non-back label leading. + child: DefaultTextStyle( + style: bottomTitleTextStyle, + child: bottomMiddle.child, + ), + ), + ); + } + + return null; + } + + Widget? get bottomLargeTitle { + final KeyedSubtree? bottomLargeTitle = bottomComponents.largeTitleKey.currentWidget as KeyedSubtree?; + final KeyedSubtree? topBackLabel = topComponents.backLabelKey.currentWidget as KeyedSubtree?; + final KeyedSubtree? topLeading = topComponents.leadingKey.currentWidget as KeyedSubtree?; + + if (bottomLargeTitle == null || !bottomLargeExpanded) { + return null; + } + + if (topBackLabel != null) { + // Move from current position to the top page's back label position. + return slideFromLeadingEdge( + fromKey: bottomComponents.largeTitleKey, + fromNavBarBox: bottomNavBarBox, + toKey: topComponents.backLabelKey, + toNavBarBox: topNavBarBox, + child: FadeTransition( + opacity: fadeOutBy(0.6), + child: Align( + // As the text shrinks, make sure it's still anchored to the leading + // edge of a constantly sized outer box. + alignment: AlignmentDirectional.centerStart, + child: DefaultTextStyleTransition( + style: animation.drive(TextStyleTween( + begin: bottomLargeTitleTextStyle, + end: topBackButtonTextStyle, + )), + maxLines: 1, + overflow: TextOverflow.ellipsis, + child: bottomLargeTitle.child, + ), + ), + ), + ); + } + + if (topLeading != null) { + // Unlike bottom middle, the bottom large title moves when it can't + // transition to the top back label position. + final RelativeRect from = positionInTransitionBox(bottomComponents.largeTitleKey, from: bottomNavBarBox); + + final RelativeRectTween positionTween = RelativeRectTween( + begin: from, + end: from.shift( + Offset( + forwardDirection * bottomNavBarBox.size.width / 4.0, + 0.0, + ), + ), + ); + + // Just shift slightly towards the trailing edge instead of moving to the + // back label position. + return PositionedTransition( + rect: animation.drive(positionTween), + child: FadeTransition( + opacity: fadeOutBy(0.4), + // Keep the font when transitioning into a non-back-label leading. + child: DefaultTextStyle( + style: bottomLargeTitleTextStyle!, + child: bottomLargeTitle.child, + ), + ), + ); + } + + return null; + } + + Widget? get bottomTrailing { + final KeyedSubtree? bottomTrailing = bottomComponents.trailingKey.currentWidget as KeyedSubtree?; + + if (bottomTrailing == null) { + return null; + } + + return Positioned.fromRelativeRect( + rect: positionInTransitionBox(bottomComponents.trailingKey, from: bottomNavBarBox), + child: FadeTransition( + opacity: fadeOutBy(0.6), + child: bottomTrailing.child, + ), + ); + } + + Widget? get topLeading { + final KeyedSubtree? topLeading = topComponents.leadingKey.currentWidget as KeyedSubtree?; + + if (topLeading == null) { + return null; + } + + return Positioned.fromRelativeRect( + rect: positionInTransitionBox(topComponents.leadingKey, from: topNavBarBox), + child: FadeTransition( + opacity: fadeInFrom(0.6), + child: topLeading.child, + ), + ); + } + + Widget? get topBackChevron { + final KeyedSubtree? topBackChevron = topComponents.backChevronKey.currentWidget as KeyedSubtree?; + final KeyedSubtree? bottomBackChevron = bottomComponents.backChevronKey.currentWidget as KeyedSubtree?; + + if (topBackChevron == null) { + return null; + } + + final RelativeRect to = positionInTransitionBox(topComponents.backChevronKey, from: topNavBarBox); + RelativeRect from = to; + + // If it's the first page with a back chevron, shift in slightly from the + // right. + if (bottomBackChevron == null) { + final RenderBox topBackChevronBox = topComponents.backChevronKey.currentContext!.findRenderObject()! as RenderBox; + from = to.shift( + Offset( + forwardDirection * topBackChevronBox.size.width * 2.0, + 0.0, + ), + ); + } + + final RelativeRectTween positionTween = RelativeRectTween( + begin: from, + end: to, + ); + + return PositionedTransition( + rect: animation.drive(positionTween), + child: FadeTransition( + opacity: fadeInFrom(bottomBackChevron == null ? 0.7 : 0.4), + child: DefaultTextStyle( + style: topBackButtonTextStyle, + child: topBackChevron.child, + ), + ), + ); + } + + Widget? get topBackLabel { + final KeyedSubtree? bottomMiddle = bottomComponents.middleKey.currentWidget as KeyedSubtree?; + final KeyedSubtree? bottomLargeTitle = bottomComponents.largeTitleKey.currentWidget as KeyedSubtree?; + final KeyedSubtree? topBackLabel = topComponents.backLabelKey.currentWidget as KeyedSubtree?; + + if (topBackLabel == null) { + return null; + } + + final RenderAnimatedOpacity? topBackLabelOpacity = + topComponents.backLabelKey.currentContext?.findAncestorRenderObjectOfType(); + + Animation? midClickOpacity; + if (topBackLabelOpacity != null && topBackLabelOpacity.opacity.value < 1.0) { + midClickOpacity = animation.drive(Tween( + begin: 0.0, + end: topBackLabelOpacity.opacity.value, + )); + } + + // Pick up from an incoming transition from the large title. This is + // duplicated here from the bottomLargeTitle transition widget because the + // content text might be different. For instance, if the bottomLargeTitle + // text is too long, the topBackLabel will say 'Back' instead of the original + // text. + if (bottomLargeTitle != null && + bottomLargeExpanded) { + return slideFromLeadingEdge( + fromKey: bottomComponents.largeTitleKey, + fromNavBarBox: bottomNavBarBox, + toKey: topComponents.backLabelKey, + toNavBarBox: topNavBarBox, + child: FadeTransition( + opacity: midClickOpacity ?? fadeInFrom(0.4), + child: DefaultTextStyleTransition( + style: animation.drive(TextStyleTween( + begin: bottomLargeTitleTextStyle, + end: topBackButtonTextStyle, + )), + maxLines: 1, + overflow: TextOverflow.ellipsis, + child: topBackLabel.child, + ), + ), + ); + } + + // The topBackLabel always comes from the large title first if available + // and expanded instead of middle. + if (bottomMiddle != null) { + return slideFromLeadingEdge( + fromKey: bottomComponents.middleKey, + fromNavBarBox: bottomNavBarBox, + toKey: topComponents.backLabelKey, + toNavBarBox: topNavBarBox, + child: FadeTransition( + opacity: midClickOpacity ?? fadeInFrom(0.3), + child: DefaultTextStyleTransition( + style: animation.drive(TextStyleTween( + begin: bottomTitleTextStyle, + end: topBackButtonTextStyle, + )), + child: topBackLabel.child, + ), + ), + ); + } + + return null; + } + + Widget? get topMiddle { + final KeyedSubtree? topMiddle = topComponents.middleKey.currentWidget as KeyedSubtree?; + + if (topMiddle == null) { + return null; + } + + // The middle component is non-null when the nav bar is a large title + // nav bar but would be invisible when expanded, therefore don't show it here. + if (!topHasUserMiddle && topLargeExpanded) { + return null; + } + + final RelativeRect to = positionInTransitionBox(topComponents.middleKey, from: topNavBarBox); + final RenderBox toBox = topComponents.middleKey.currentContext!.findRenderObject()! as RenderBox; + + final bool isLTR = forwardDirection > 0; + + // Anchor is the top-leading point of toBox, in transition box's top-leading + // coordinate space. + final Offset toAnchorInTransitionBox = Offset( + isLTR ? to.left : to.right, + to.top, + ); + + // Shift in from the trailing edge of the screen. + final Tween anchorMovementInTransitionBox = Tween( + begin: Offset( + // the "width / 2" here makes the middle widget's horizontal center on + // the trailing edge of the top nav bar. + topNavBarBox.size.width - toBox.size.width / 2, + to.top, + ), + end: toAnchorInTransitionBox, + ); + + return _FixedSizeSlidingTransition( + isLTR: isLTR, + offsetAnimation: animation.drive(anchorMovementInTransitionBox), + size: toBox.size, + child: FadeTransition( + opacity: fadeInFrom(0.25), + child: DefaultTextStyle( + style: topTitleTextStyle, + child: topMiddle.child, + ), + ), + ); + } + + Widget? get topTrailing { + final KeyedSubtree? topTrailing = topComponents.trailingKey.currentWidget as KeyedSubtree?; + + if (topTrailing == null) { + return null; + } + + return Positioned.fromRelativeRect( + rect: positionInTransitionBox(topComponents.trailingKey, from: topNavBarBox), + child: FadeTransition( + opacity: fadeInFrom(0.4), + child: topTrailing.child, + ), + ); + } + + Widget? get topLargeTitle { + final KeyedSubtree? topLargeTitle = topComponents.largeTitleKey.currentWidget as KeyedSubtree?; + + if (topLargeTitle == null || !topLargeExpanded) { + return null; + } + + final RelativeRect to = positionInTransitionBox(topComponents.largeTitleKey, from: topNavBarBox); + + // Shift in from the trailing edge of the screen. + final RelativeRectTween positionTween = RelativeRectTween( + begin: to.shift( + Offset( + forwardDirection * topNavBarBox.size.width, + 0.0, + ), + ), + end: to, + ); + + return PositionedTransition( + rect: animation.drive(positionTween), + child: FadeTransition( + opacity: fadeInFrom(0.3), + child: DefaultTextStyle( + style: topLargeTitleTextStyle!, + maxLines: 1, + overflow: TextOverflow.ellipsis, + child: topLargeTitle.child, + ), + ), + ); + } +} + +/// Navigation bars' hero rect tween that will move between the static bars +/// but keep a constant size that's the bigger of both navigation bars. +RectTween _linearTranslateWithLargestRectSizeTween(Rect? begin, Rect? end) { + final Size largestSize = Size( + math.max(begin!.size.width, end!.size.width), + math.max(begin.size.height, end.size.height), + ); + return RectTween( + begin: begin.topLeft & largestSize, + end: end.topLeft & largestSize, + ); +} + +Widget _navBarHeroLaunchPadBuilder( + BuildContext context, + Size heroSize, + Widget child, +) { + assert(child is _TransitionableNavigationBar); + // Tree reshaping is fine here because the Heroes' child is always a + // _TransitionableNavigationBar which has a GlobalKey. + + // Keeping the Hero subtree here is needed (instead of just swapping out the + // anchor nav bars for fixed size boxes during flights) because the nav bar + // and their specific component children may serve as anchor points again if + // another mid-transition flight diversion is triggered. + + // This is ok performance-wise because static nav bars are generally cheap to + // build and layout but expensive to GPU render (due to clips and blurs) which + // we're skipping here. + return Visibility( + maintainSize: true, + maintainAnimation: true, + maintainState: true, + visible: false, + child: child, + ); +} + +/// Navigation bars' hero flight shuttle builder. +Widget _navBarHeroFlightShuttleBuilder( + BuildContext flightContext, + Animation animation, + HeroFlightDirection flightDirection, + BuildContext fromHeroContext, + BuildContext toHeroContext, +) { + assert(fromHeroContext.widget is Hero); + assert(toHeroContext.widget is Hero); + + final Hero fromHeroWidget = fromHeroContext.widget as Hero; + final Hero toHeroWidget = toHeroContext.widget as Hero; + + assert(fromHeroWidget.child is _TransitionableNavigationBar); + assert(toHeroWidget.child is _TransitionableNavigationBar); + + final _TransitionableNavigationBar fromNavBar = fromHeroWidget.child as _TransitionableNavigationBar; + final _TransitionableNavigationBar toNavBar = toHeroWidget.child as _TransitionableNavigationBar; + + + assert( + fromNavBar.componentsKeys.navBarBoxKey.currentContext!.owner != null, + 'The from nav bar to Hero must have been mounted in the previous frame', + ); + assert( + toNavBar.componentsKeys.navBarBoxKey.currentContext!.owner != null, + 'The to nav bar to Hero must have been mounted in the previous frame', + ); + + switch (flightDirection) { + case HeroFlightDirection.push: + return _NavigationBarTransition( + animation: animation, + bottomNavBar: fromNavBar, + topNavBar: toNavBar, + ); + case HeroFlightDirection.pop: + return _NavigationBarTransition( + animation: animation, + bottomNavBar: toNavBar, + topNavBar: fromNavBar, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/page_scaffold.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/page_scaffold.dart new file mode 100644 index 0000000000000000000000000000000000000000..ea34f2556550cd466b44f973e8723e1c86b3b884 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/page_scaffold.dart @@ -0,0 +1,213 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'theme.dart'; + +/// Implements a single iOS application page's layout. +/// +/// The scaffold lays out the navigation bar on top and the content between or +/// behind the navigation bar. +/// +/// When tapping a status bar at the top of the CupertinoPageScaffold, an +/// animation will complete for the current primary [ScrollView], scrolling to +/// the beginning. This is done using the [PrimaryScrollController] that +/// encloses the [ScrollView]. The [ScrollView.primary] flag is used to connect +/// a [ScrollView] to the enclosing [PrimaryScrollController]. +/// +/// {@tool dartpad} +/// This example shows a [CupertinoPageScaffold] with a [ListView] as a [child]. +/// The [CupertinoButton] is connected to a callback that increments a counter. +/// The [backgroundColor] can be changed. +/// +/// ** See code in examples/api/lib/cupertino/page_scaffold/cupertino_page_scaffold.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoTabScaffold], a similar widget for tabbed applications. +/// * [CupertinoPageRoute], a modal page route that typically hosts a +/// [CupertinoPageScaffold] with support for iOS-style page transitions. +class CupertinoPageScaffold extends StatefulWidget { + /// Creates a layout for pages with a navigation bar at the top. + const CupertinoPageScaffold({ + super.key, + this.navigationBar, + this.backgroundColor, + this.resizeToAvoidBottomInset = true, + required this.child, + }); + + /// The [navigationBar], typically a [CupertinoNavigationBar], is drawn at the + /// top of the screen. + /// + /// If translucent, the main content may slide behind it. + /// Otherwise, the main content's top margin will be offset by its height. + /// + /// The scaffold assumes the navigation bar will account for the [MediaQuery] + /// top padding, also consume it if the navigation bar is opaque. + /// + /// By default [navigationBar] disables text scaling to match the native iOS + /// behavior. To override such behavior, wrap each of the [navigationBar]'s + /// components inside a [MediaQuery] with the desired [TextScaler]. + // TODO(xster): document its page transition animation when ready + final ObstructingPreferredSizeWidget? navigationBar; + + /// Widget to show in the main content area. + /// + /// Content can slide under the [navigationBar] when they're translucent. + /// In that case, the child's [BuildContext]'s [MediaQuery] will have a + /// top padding indicating the area of obstructing overlap from the + /// [navigationBar]. + final Widget child; + + /// The color of the widget that underlies the entire scaffold. + /// + /// By default uses [CupertinoTheme]'s `scaffoldBackgroundColor` when null. + final Color? backgroundColor; + + /// Whether the [child] should size itself to avoid the window's bottom inset. + /// + /// For example, if there is an onscreen keyboard displayed above the + /// scaffold, the body can be resized to avoid overlapping the keyboard, which + /// prevents widgets inside the body from being obscured by the keyboard. + /// + /// Defaults to true. + final bool resizeToAvoidBottomInset; + + @override + State createState() => _CupertinoPageScaffoldState(); +} + +class _CupertinoPageScaffoldState extends State { + + void _handleStatusBarTap() { + final ScrollController? primaryScrollController = PrimaryScrollController.maybeOf(context); + // Only act on the scroll controller if it has any attached scroll positions. + if (primaryScrollController != null && primaryScrollController.hasClients) { + primaryScrollController.animateTo( + 0.0, + // Eyeballed from iOS. + duration: const Duration(milliseconds: 500), + curve: Curves.linearToEaseOut, + ); + } + } + + @override + Widget build(BuildContext context) { + Widget paddedContent = widget.child; + + final MediaQueryData existingMediaQuery = MediaQuery.of(context); + if (widget.navigationBar != null) { + // TODO(xster): Use real size after partial layout instead of preferred size. + // https://github.com/flutter/flutter/issues/12912 + final double topPadding = + widget.navigationBar!.preferredSize.height + existingMediaQuery.padding.top; + + // Propagate bottom padding and include viewInsets if appropriate + final double bottomPadding = widget.resizeToAvoidBottomInset + ? existingMediaQuery.viewInsets.bottom + : 0.0; + + final EdgeInsets newViewInsets = widget.resizeToAvoidBottomInset + // The insets are consumed by the scaffolds and no longer exposed to + // the descendant subtree. + ? existingMediaQuery.viewInsets.copyWith(bottom: 0.0) + : existingMediaQuery.viewInsets; + + final bool fullObstruction = widget.navigationBar!.shouldFullyObstruct(context); + + // If navigation bar is opaquely obstructing, directly shift the main content + // down. If translucent, let main content draw behind navigation bar but hint the + // obstructed area. + if (fullObstruction) { + paddedContent = MediaQuery( + data: existingMediaQuery + // If the navigation bar is opaque, the top media query padding is fully consumed by the navigation bar. + .removePadding(removeTop: true) + .copyWith( + viewInsets: newViewInsets, + ), + child: Padding( + padding: EdgeInsets.only(top: topPadding, bottom: bottomPadding), + child: paddedContent, + ), + ); + } else { + paddedContent = MediaQuery( + data: existingMediaQuery.copyWith( + padding: existingMediaQuery.padding.copyWith( + top: topPadding, + ), + viewInsets: newViewInsets, + ), + child: Padding( + padding: EdgeInsets.only(bottom: bottomPadding), + child: paddedContent, + ), + ); + } + } else { + // If there is no navigation bar, still may need to add padding in order + // to support resizeToAvoidBottomInset. + final double bottomPadding = widget.resizeToAvoidBottomInset + ? existingMediaQuery.viewInsets.bottom + : 0.0; + paddedContent = Padding( + padding: EdgeInsets.only(bottom: bottomPadding), + child: paddedContent, + ); + } + + return DecoratedBox( + decoration: BoxDecoration( + color: CupertinoDynamicColor.maybeResolve(widget.backgroundColor, context) + ?? CupertinoTheme.of(context).scaffoldBackgroundColor, + ), + child: Stack( + children: [ + // The main content being at the bottom is added to the stack first. + paddedContent, + if (widget.navigationBar != null) + Positioned( + top: 0.0, + left: 0.0, + right: 0.0, + child: MediaQuery.withNoTextScaling( + child: widget.navigationBar!, + ), + ), + // Add a touch handler the size of the status bar on top of all contents + // to handle scroll to top by status bar taps. + Positioned( + top: 0.0, + left: 0.0, + right: 0.0, + height: existingMediaQuery.padding.top, + child: GestureDetector( + excludeFromSemantics: true, + onTap: _handleStatusBarTap, + ), + ), + ], + ), + ); + } +} + +/// Widget that has a preferred size and reports whether it fully obstructs +/// widgets behind it. +/// +/// Used by [CupertinoPageScaffold] to either shift away fully obstructed content +/// or provide a padding guide to partially obstructed content. +abstract class ObstructingPreferredSizeWidget implements PreferredSizeWidget { + /// If true, this widget fully obstructs widgets behind it by the specified + /// size. + /// + /// If false, this widget partially obstructs. + bool shouldFullyObstruct(BuildContext context); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/picker.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/picker.dart new file mode 100644 index 0000000000000000000000000000000000000000..88a70f1cc842bf31c7ee1af9c3c116c52adf5bf4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/picker.dart @@ -0,0 +1,510 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'theme.dart'; + +// Eyeballed values comparing with a native picker to produce the right +// curvatures and densities. +const double _kDefaultDiameterRatio = 1.07; +const double _kDefaultPerspective = 0.003; +const double _kSqueeze = 1.45; + +// Opacity fraction value that dims the wheel above and below the "magnifier" +// lens. +const double _kOverAndUnderCenterOpacity = 0.447; + +/// An iOS-styled picker. +/// +/// Displays its children widgets on a wheel for selection and +/// calls back when the currently selected item changes. +/// +/// By default, the first child in `children` will be the initially selected child. +/// The index of a different child can be specified in [scrollController], to make +/// that child the initially selected child. +/// +/// Can be used with [showCupertinoModalPopup] to display the picker modally at the +/// bottom of the screen. When calling [showCupertinoModalPopup], be sure to set +/// `semanticsDismissible` to true to enable dismissing the modal via semantics. +/// +/// Sizes itself to its parent. All children are sized to the same size based +/// on [itemExtent]. +/// +/// By default, descendent texts are shown with [CupertinoTextThemeData.pickerTextStyle]. +/// +/// {@tool dartpad} +/// This example shows a [CupertinoPicker] that displays a list of fruits on a wheel for +/// selection. +/// +/// ** See code in examples/api/lib/cupertino/picker/cupertino_picker.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListWheelScrollView], the generic widget backing this picker without +/// the iOS design specific chrome. +/// * +class CupertinoPicker extends StatefulWidget { + /// Creates a picker from a concrete list of children. + /// + /// The [itemExtent] must be greater than zero. + /// + /// The [backgroundColor] defaults to null, which disables background painting entirely. + /// (i.e. the picker is going to have a completely transparent background), to match + /// the native UIPicker and UIDatePicker. Also, if it has transparency, no gradient + /// effect will be rendered. + /// + /// The [scrollController] argument can be used to specify a custom + /// [FixedExtentScrollController] for programmatically reading or changing + /// the current picker index or for selecting an initial index value. + /// + /// The [looping] argument decides whether the child list loops and can be + /// scrolled infinitely. If set to true, scrolling past the end of the list + /// will loop the list back to the beginning. If set to false, the list will + /// stop scrolling when you reach the end or the beginning. + CupertinoPicker({ + super.key, + this.diameterRatio = _kDefaultDiameterRatio, + this.backgroundColor, + this.offAxisFraction = 0.0, + this.useMagnifier = false, + this.magnification = 1.0, + this.scrollController, + this.squeeze = _kSqueeze, + required this.itemExtent, + required this.onSelectedItemChanged, + required List children, + this.selectionOverlay = const CupertinoPickerDefaultSelectionOverlay(), + bool looping = false, + }) : assert(diameterRatio > 0.0, RenderListWheelViewport.diameterRatioZeroMessage), + assert(magnification > 0), + assert(itemExtent > 0), + assert(squeeze > 0), + childDelegate = looping + ? ListWheelChildLoopingListDelegate(children: children) + : ListWheelChildListDelegate(children: children); + + /// Creates a picker from an [IndexedWidgetBuilder] callback where the builder + /// is dynamically invoked during layout. + /// + /// A child is lazily created when it starts becoming visible in the viewport. + /// All of the children provided by the builder are cached and reused, so + /// normally the builder is only called once for each index (except when + /// rebuilding - the cache is cleared). + /// + /// The [childCount] argument reflects the number of children that will be + /// provided by the [itemBuilder]. + /// {@macro flutter.widgets.ListWheelChildBuilderDelegate.childCount} + /// + /// The [itemExtent] argument must be positive. + /// + /// The [backgroundColor] defaults to null, which disables background painting entirely. + /// (i.e. the picker is going to have a completely transparent background), to match + /// the native UIPicker and UIDatePicker. + CupertinoPicker.builder({ + super.key, + this.diameterRatio = _kDefaultDiameterRatio, + this.backgroundColor, + this.offAxisFraction = 0.0, + this.useMagnifier = false, + this.magnification = 1.0, + this.scrollController, + this.squeeze = _kSqueeze, + required this.itemExtent, + required this.onSelectedItemChanged, + required NullableIndexedWidgetBuilder itemBuilder, + int? childCount, + this.selectionOverlay = const CupertinoPickerDefaultSelectionOverlay(), + }) : assert(diameterRatio > 0.0, RenderListWheelViewport.diameterRatioZeroMessage), + assert(magnification > 0), + assert(itemExtent > 0), + assert(squeeze > 0), + childDelegate = ListWheelChildBuilderDelegate(builder: itemBuilder, childCount: childCount); + + /// Relative ratio between this picker's height and the simulated cylinder's diameter. + /// + /// Smaller values creates more pronounced curvatures in the scrollable wheel. + /// + /// For more details, see [ListWheelScrollView.diameterRatio]. + /// + /// Defaults to 1.1 to visually mimic iOS. + final double diameterRatio; + + /// Background color behind the children. + /// + /// Defaults to null, which disables background painting entirely. + /// (i.e. the picker is going to have a completely transparent background), to match + /// the native UIPicker and UIDatePicker. + /// + /// Any alpha value less 255 (fully opaque) will cause the removal of the + /// wheel list edge fade gradient from rendering of the widget. + final Color? backgroundColor; + + /// {@macro flutter.rendering.RenderListWheelViewport.offAxisFraction} + final double offAxisFraction; + + /// {@macro flutter.rendering.RenderListWheelViewport.useMagnifier} + final bool useMagnifier; + + /// {@macro flutter.rendering.RenderListWheelViewport.magnification} + final double magnification; + + /// A [FixedExtentScrollController] to read and control the current item, and + /// to set the initial item. + /// + /// If null, an implicit one will be created internally. + final FixedExtentScrollController? scrollController; + + /// {@template flutter.cupertino.picker.itemExtent} + /// The uniform height of all children. + /// + /// All children will be given the [BoxConstraints] to match this exact + /// height. Must be a positive value. + /// {@endtemplate} + final double itemExtent; + + /// {@macro flutter.rendering.RenderListWheelViewport.squeeze} + /// + /// Defaults to `1.45` to visually mimic iOS. + final double squeeze; + + /// An option callback when the currently centered item changes. + /// + /// Value changes when the item closest to the center changes. + /// + /// This can be called during scrolls and during ballistic flings. To get the + /// value only when the scrolling settles, use a [NotificationListener], + /// listen for [ScrollEndNotification] and read its [FixedExtentMetrics]. + final ValueChanged? onSelectedItemChanged; + + /// A delegate that lazily instantiates children. + final ListWheelChildDelegate childDelegate; + + /// A widget overlaid on the picker to highlight the currently selected entry. + /// + /// The [selectionOverlay] widget drawn above the [CupertinoPicker]'s picker + /// wheel. + /// It is vertically centered in the picker and is constrained to have the + /// same height as the center row. + /// + /// If unspecified, it defaults to a [CupertinoPickerDefaultSelectionOverlay] + /// which is a gray rounded rectangle overlay in iOS 14 style. + /// This property can be set to null to remove the overlay. + final Widget? selectionOverlay; + + @override + State createState() => _CupertinoPickerState(); +} + +class _CupertinoPickerState extends State { + int? _lastHapticIndex; + FixedExtentScrollController? _controller; + + @override + void initState() { + super.initState(); + if (widget.scrollController == null) { + _controller = FixedExtentScrollController(); + } + } + + @override + void didUpdateWidget(CupertinoPicker oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.scrollController != null && oldWidget.scrollController == null) { + _controller?.dispose(); + _controller = null; + } else if (widget.scrollController == null && oldWidget.scrollController != null) { + assert(_controller == null); + _controller = FixedExtentScrollController(); + } + } + + @override + void dispose() { + _controller?.dispose(); + super.dispose(); + } + + void _handleSelectedItemChanged(int index) { + // Only the haptic engine hardware on iOS devices would produce the + // intended effects. + final bool hasSuitableHapticHardware; + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + hasSuitableHapticHardware = true; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + hasSuitableHapticHardware = false; + } + if (hasSuitableHapticHardware && index != _lastHapticIndex) { + _lastHapticIndex = index; + HapticFeedback.selectionClick(); + } + + widget.onSelectedItemChanged?.call(index); + } + + /// Draws the selectionOverlay. + Widget _buildSelectionOverlay(Widget selectionOverlay) { + final double height = widget.itemExtent * widget.magnification; + + return IgnorePointer( + child: Center( + child: ConstrainedBox( + constraints: BoxConstraints.expand( + height: height, + ), + child: selectionOverlay, + ), + ), + ); + } + + @override + Widget build(BuildContext context) { + final TextStyle textStyle = CupertinoTheme.of(context).textTheme.pickerTextStyle; + final Color? resolvedBackgroundColor = CupertinoDynamicColor.maybeResolve(widget.backgroundColor, context); + + assert(RenderListWheelViewport.defaultPerspective == _kDefaultPerspective); + final Widget result = DefaultTextStyle( + style: textStyle.copyWith(color: CupertinoDynamicColor.maybeResolve(textStyle.color, context)), + child: Stack( + children: [ + Positioned.fill( + child: _CupertinoPickerSemantics( + scrollController: widget.scrollController ?? _controller!, + child: ListWheelScrollView.useDelegate( + controller: widget.scrollController ?? _controller, + physics: const FixedExtentScrollPhysics(), + diameterRatio: widget.diameterRatio, + offAxisFraction: widget.offAxisFraction, + useMagnifier: widget.useMagnifier, + magnification: widget.magnification, + overAndUnderCenterOpacity: _kOverAndUnderCenterOpacity, + itemExtent: widget.itemExtent, + squeeze: widget.squeeze, + onSelectedItemChanged: _handleSelectedItemChanged, + childDelegate: widget.childDelegate, + ), + ), + ), + if (widget.selectionOverlay != null) + _buildSelectionOverlay(widget.selectionOverlay!), + ], + ), + ); + + return DecoratedBox( + decoration: BoxDecoration(color: resolvedBackgroundColor), + child: result, + ); + } +} + +/// A default selection overlay for [CupertinoPicker]s. +/// +/// It draws a gray rounded rectangle to match the picker visuals introduced in +/// iOS 14. +/// +/// This widget is typically only used in [CupertinoPicker.selectionOverlay]. +/// In an iOS 14 multi-column picker, the selection overlay is a single rounded +/// rectangle that spans the entire multi-column picker. +/// To achieve the same effect using [CupertinoPickerDefaultSelectionOverlay], +/// the additional margin and corner radii on the left or the right side can be +/// disabled by turning off [capStartEdge] and [capEndEdge], so this selection +/// overlay visually connects with selection overlays of adjoining +/// [CupertinoPicker]s (i.e., other "column"s). +/// +/// See also: +/// +/// * [CupertinoPicker], which uses this widget as its default [CupertinoPicker.selectionOverlay]. +class CupertinoPickerDefaultSelectionOverlay extends StatelessWidget { + + /// Creates an iOS 14 style selection overlay that highlights the magnified + /// area (or the currently selected item, depending on how you described it + /// elsewhere) of a [CupertinoPicker]. + /// + /// The [background] argument default value is + /// [CupertinoColors.tertiarySystemFill]. + /// + /// The [capStartEdge] and [capEndEdge] arguments decide whether to add a + /// default margin and use rounded corners on the left and right side of the + /// rectangular overlay, and they both default to true. + const CupertinoPickerDefaultSelectionOverlay({ + super.key, + this.background = CupertinoColors.tertiarySystemFill, + this.capStartEdge = true, + this.capEndEdge = true, + }); + + /// Whether to use the default use rounded corners and margin on the start side. + final bool capStartEdge; + + /// Whether to use the default use rounded corners and margin on the end side. + final bool capEndEdge; + + /// The color to fill in the background of the [CupertinoPickerDefaultSelectionOverlay]. + /// It Support for use [CupertinoDynamicColor]. + /// + /// Typically this should not be set to a fully opaque color, as the currently + /// selected item of the underlying [CupertinoPicker] should remain visible. + /// Defaults to [CupertinoColors.tertiarySystemFill]. + final Color background; + + /// Default margin of the 'SelectionOverlay'. + static const double _defaultSelectionOverlayHorizontalMargin = 9; + + /// Default radius of the 'SelectionOverlay'. + static const double _defaultSelectionOverlayRadius = 8; + + @override + Widget build(BuildContext context) { + const Radius radius = Radius.circular(_defaultSelectionOverlayRadius); + + return Container( + margin: EdgeInsetsDirectional.only( + start: capStartEdge ? _defaultSelectionOverlayHorizontalMargin : 0, + end: capEndEdge ? _defaultSelectionOverlayHorizontalMargin : 0, + ), + decoration: BoxDecoration( + borderRadius: BorderRadiusDirectional.horizontal( + start: capStartEdge ? radius : Radius.zero, + end: capEndEdge ? radius : Radius.zero, + ), + color: CupertinoDynamicColor.resolve(background, context), + ), + ); + } +} + +// Turns the scroll semantics of the ListView into a single adjustable semantics +// node. This is done by removing all of the child semantics of the scroll +// wheel and using the scroll indexes to look up the current, previous, and +// next semantic label. This label is then turned into the value of a new +// adjustable semantic node, with adjustment callbacks wired to move the +// scroll controller. +class _CupertinoPickerSemantics extends SingleChildRenderObjectWidget { + const _CupertinoPickerSemantics({ + super.child, + required this.scrollController, + }); + + final FixedExtentScrollController scrollController; + + @override + RenderObject createRenderObject(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + return _RenderCupertinoPickerSemantics(scrollController, Directionality.of(context)); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderCupertinoPickerSemantics renderObject) { + assert(debugCheckHasDirectionality(context)); + renderObject + ..textDirection = Directionality.of(context) + ..controller = scrollController; + } +} + +class _RenderCupertinoPickerSemantics extends RenderProxyBox { + _RenderCupertinoPickerSemantics(FixedExtentScrollController controller, this._textDirection) { + _updateController(null, controller); + } + + FixedExtentScrollController get controller => _controller; + late FixedExtentScrollController _controller; + set controller(FixedExtentScrollController value) => _updateController(_controller, value); + + // This method exists to allow controller to be non-null. It is only called with a null oldValue from constructor. + void _updateController(FixedExtentScrollController? oldValue, FixedExtentScrollController value) { + if (value == oldValue) { + return; + } + if (oldValue != null) { + oldValue.removeListener(_handleScrollUpdate); + } else { + _currentIndex = value.initialItem; + } + value.addListener(_handleScrollUpdate); + _controller = value; + } + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (textDirection == value) { + return; + } + _textDirection = value; + markNeedsSemanticsUpdate(); + } + + int _currentIndex = 0; + + void _handleIncrease() { + controller.jumpToItem(_currentIndex + 1); + } + + void _handleDecrease() { + controller.jumpToItem(_currentIndex - 1); + } + + void _handleScrollUpdate() { + if (controller.selectedItem == _currentIndex) { + return; + } + _currentIndex = controller.selectedItem; + markNeedsSemanticsUpdate(); + } + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.isSemanticBoundary = true; + config.textDirection = textDirection; + } + + @override + void assembleSemanticsNode(SemanticsNode node, SemanticsConfiguration config, Iterable children) { + if (children.isEmpty) { + return super.assembleSemanticsNode(node, config, children); + } + final SemanticsNode scrollable = children.first; + final Map indexedChildren = {}; + scrollable.visitChildren((SemanticsNode child) { + assert(child.indexInParent != null); + indexedChildren[child.indexInParent!] = child; + return true; + }); + if (indexedChildren[_currentIndex] == null) { + return node.updateWith(config: config); + } + config.value = indexedChildren[_currentIndex]!.label; + final SemanticsNode? previousChild = indexedChildren[_currentIndex - 1]; + final SemanticsNode? nextChild = indexedChildren[_currentIndex + 1]; + if (nextChild != null) { + config.increasedValue = nextChild.label; + config.onIncrease = _handleIncrease; + } + if (previousChild != null) { + config.decreasedValue = previousChild.label; + config.onDecrease = _handleDecrease; + } + node.updateWith(config: config); + } + + @override + void dispose() { + super.dispose(); + controller.removeListener(_handleScrollUpdate); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/radio.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/radio.dart new file mode 100644 index 0000000000000000000000000000000000000000..52b752c847126c287d89171152c8f9c2082b18bc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/radio.dart @@ -0,0 +1,365 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'toggleable.dart'; + +// Examples can assume: +// late BuildContext context; +// enum SingingCharacter { lafayette } +// late SingingCharacter? _character; +// late StateSetter setState; + +const Size _size = Size(18.0, 18.0); +const double _kOuterRadius = 7.0; +const double _kInnerRadius = 2.975; + +// The relative values needed to transform a color to its equivalent focus +// outline color. +const double _kCupertinoFocusColorOpacity = 0.80; +const double _kCupertinoFocusColorBrightness = 0.69; +const double _kCupertinoFocusColorSaturation = 0.835; + +/// A macOS-style radio button. +/// +/// Used to select between a number of mutually exclusive values. When one radio +/// button in a group is selected, the other radio buttons in the group are +/// deselected. The values are of type `T`, the type parameter of the +/// [CupertinoRadio] class. Enums are commonly used for this purpose. +/// +/// The radio button itself does not maintain any state. Instead, selecting the +/// radio invokes the [onChanged] callback, passing [value] as a parameter. If +/// [groupValue] and [value] match, this radio will be selected. Most widgets +/// will respond to [onChanged] by calling [State.setState] to update the +/// radio button's [groupValue]. +/// +/// {@tool dartpad} +/// Here is an example of CupertinoRadio widgets wrapped in CupertinoListTiles. +/// +/// The currently selected character is passed into `groupValue`, which is +/// maintained by the example's `State`. In this case, the first [CupertinoRadio] +/// will start off selected because `_character` is initialized to +/// `SingingCharacter.lafayette`. +/// +/// If the second radio button is pressed, the example's state is updated +/// with `setState`, updating `_character` to `SingingCharacter.jefferson`. +/// This causes the buttons to rebuild with the updated `groupValue`, and +/// therefore the selection of the second button. +/// +/// ** See code in examples/api/lib/cupertino/radio/cupertino_radio.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoSlider], for selecting a value in a range. +/// * [CupertinoCheckbox] and [CupertinoSwitch], for toggling a particular value on or off. +/// * [Radio], the Material Design equivalent. +/// * +class CupertinoRadio extends StatefulWidget { + /// Creates a macOS-styled radio button. + /// + /// The following arguments are required: + /// + /// * [value] and [groupValue] together determine whether the radio button is + /// selected. + /// * [onChanged] is called when the user selects this radio button. + const CupertinoRadio({ + super.key, + required this.value, + required this.groupValue, + required this.onChanged, + this.toggleable = false, + this.activeColor, + this.inactiveColor, + this.fillColor, + this.focusColor, + this.focusNode, + this.autofocus = false, + this.useCheckmarkStyle = false, + }); + + /// The value represented by this radio button. + /// + /// If this equals the [groupValue], then this radio button will appear + /// selected. + final T value; + + /// The currently selected value for a group of radio buttons. + /// + /// This radio button is considered selected if its [value] matches the + /// [groupValue]. + final T? groupValue; + + /// Called when the user selects this [CupertinoRadio] button. + /// + /// The radio button passes [value] as a parameter to this callback. It does + /// not actually change state until the parent widget rebuilds the radio + /// button with a new [groupValue]. + /// + /// If null, the radio button will be displayed as disabled. + /// + /// The provided callback will not be invoked if this radio button is already + /// selected. + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// CupertinoRadio( + /// value: SingingCharacter.lafayette, + /// groupValue: _character, + /// onChanged: (SingingCharacter? newValue) { + /// setState(() { + /// _character = newValue; + /// }); + /// }, + /// ) + /// ``` + final ValueChanged? onChanged; + + /// Set to true if this radio button is allowed to be returned to an + /// indeterminate state by selecting it again when selected. + /// + /// To indicate returning to an indeterminate state, [onChanged] will be + /// called with null. + /// + /// If true, [onChanged] can be called with [value] when selected while + /// [groupValue] != [value], or with null when selected again while + /// [groupValue] == [value]. + /// + /// If false, [onChanged] will be called with [value] when it is selected + /// while [groupValue] != [value], and only by selecting another radio button + /// in the group (i.e. changing the value of [groupValue]) can this radio + /// button be unselected. + /// + /// The default is false. + /// + /// {@tool dartpad} + /// This example shows how to enable deselecting a radio button by setting the + /// [toggleable] attribute. + /// + /// ** See code in examples/api/lib/cupertino/radio/cupertino_radio.toggleable.0.dart ** + /// {@end-tool} + final bool toggleable; + + /// Controls whether the radio displays in a checkbox style or the default iOS + /// radio style. + /// + /// Defaults to false. + final bool useCheckmarkStyle; + + /// The color to use when this radio button is selected. + /// + /// Defaults to [CupertinoColors.activeBlue]. + final Color? activeColor; + + /// The color to use when this radio button is not selected. + /// + /// Defaults to [CupertinoColors.white]. + final Color? inactiveColor; + + /// The color that fills the inner circle of the radio button when selected. + /// + /// Defaults to [CupertinoColors.white]. + final Color? fillColor; + + /// The color for the radio's border when it has the input focus. + /// + /// If null, then a paler form of the [activeColor] will be used. + final Color? focusColor; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + bool get _selected => value == groupValue; + + @override + State> createState() => _CupertinoRadioState(); +} + +class _CupertinoRadioState extends State> with TickerProviderStateMixin, ToggleableStateMixin { + final _RadioPainter _painter = _RadioPainter(); + + bool focused = false; + + void _handleChanged(bool? selected) { + if (selected == null) { + widget.onChanged!(null); + return; + } + if (selected) { + widget.onChanged!(widget.value); + } + } + + @override + void dispose() { + _painter.dispose(); + super.dispose(); + } + + @override + ValueChanged? get onChanged => widget.onChanged != null ? _handleChanged : null; + + @override + bool get tristate => widget.toggleable; + + @override + bool? get value => widget._selected; + + void onFocusChange(bool value) { + if (focused != value) { + focused = value; + } + } + + @override + Widget build(BuildContext context) { + final Color effectiveActiveColor = widget.activeColor + ?? CupertinoColors.activeBlue; + final Color effectiveInactiveColor = widget.inactiveColor + ?? CupertinoColors.white; + + final Color effectiveFocusOverlayColor = widget.focusColor + ?? HSLColor + .fromColor(effectiveActiveColor.withOpacity(_kCupertinoFocusColorOpacity)) + .withLightness(_kCupertinoFocusColorBrightness) + .withSaturation(_kCupertinoFocusColorSaturation) + .toColor(); + + final Color effectiveActivePressedOverlayColor = + HSLColor.fromColor(effectiveActiveColor).withLightness(0.45).toColor(); + + final Color effectiveFillColor = widget.fillColor ?? CupertinoColors.white; + + final bool? accessibilitySelected; + // Apple devices also use `selected` to annotate radio button's semantics + // state. + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + accessibilitySelected = null; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + accessibilitySelected = widget._selected; + } + + return Semantics( + inMutuallyExclusiveGroup: true, + checked: widget._selected, + selected: accessibilitySelected, + child: buildToggleable( + focusNode: widget.focusNode, + autofocus: widget.autofocus, + onFocusChange: onFocusChange, + size: _size, + painter: _painter + ..focusColor = effectiveFocusOverlayColor + ..downPosition = downPosition + ..isFocused = focused + ..activeColor = downPosition != null ? effectiveActivePressedOverlayColor : effectiveActiveColor + ..inactiveColor = effectiveInactiveColor + ..fillColor = effectiveFillColor + ..value = value + ..checkmarkStyle = widget.useCheckmarkStyle, + ), + ); + } +} + +class _RadioPainter extends ToggleablePainter { + bool? get value => _value; + bool? _value; + set value(bool? value) { + if (_value == value) { + return; + } + _value = value; + notifyListeners(); + } + + Color get fillColor => _fillColor!; + Color? _fillColor; + set fillColor(Color value) { + if (value == _fillColor) { + return; + } + _fillColor = value; + notifyListeners(); + } + + bool get checkmarkStyle => _checkmarkStyle; + bool _checkmarkStyle = false; + set checkmarkStyle(bool value) { + if (value == _checkmarkStyle) { + return; + } + _checkmarkStyle = value; + notifyListeners(); + } + + @override + void paint(Canvas canvas, Size size) { + + final Offset center = (Offset.zero & size).center; + + final Paint paint = Paint() + ..color = inactiveColor + ..style = PaintingStyle.fill + ..strokeWidth = 0.1; + + if (checkmarkStyle) { + if (value ?? false) { + final Path path = Path(); + final Paint checkPaint = Paint() + ..color = activeColor + ..style = PaintingStyle.stroke + ..strokeWidth = 2 + ..strokeCap = StrokeCap.round; + final double width = _size.width; + final Offset origin = Offset(center.dx - (width/2), center.dy - (width/2)); + final Offset start = Offset(width * 0.25, width * 0.52); + final Offset mid = Offset(width * 0.46, width * 0.75); + final Offset end = Offset(width * 0.85, width * 0.29); + path.moveTo(origin.dx + start.dx, origin.dy + start.dy); + path.lineTo(origin.dx + mid.dx, origin.dy + mid.dy); + canvas.drawPath(path, checkPaint); + path.moveTo(origin.dx + mid.dx, origin.dy + mid.dy); + path.lineTo(origin.dx + end.dx, origin.dy + end.dy); + canvas.drawPath(path, checkPaint); + } + } else { + // Outer border + canvas.drawCircle(center, _kOuterRadius, paint); + + paint.style = PaintingStyle.stroke; + paint.color = CupertinoColors.inactiveGray; + canvas.drawCircle(center, _kOuterRadius, paint); + + if (value ?? false) { + paint.style = PaintingStyle.fill; + paint.color = activeColor; + canvas.drawCircle(center, _kOuterRadius, paint); + paint.color = fillColor; + canvas.drawCircle(center, _kInnerRadius, paint); + } + } + + if (isFocused) { + paint.style = PaintingStyle.stroke; + paint.color = focusColor; + paint.strokeWidth = 3.0; + canvas.drawCircle(center, _kOuterRadius + 1.5, paint); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/refresh.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/refresh.dart new file mode 100644 index 0000000000000000000000000000000000000000..507758b0f086cb578e7f038ab9fee520006a0ad7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/refresh.dart @@ -0,0 +1,566 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math'; + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'activity_indicator.dart'; + +const double _kActivityIndicatorRadius = 14.0; +const double _kActivityIndicatorMargin = 16.0; + +class _CupertinoSliverRefresh extends SingleChildRenderObjectWidget { + const _CupertinoSliverRefresh({ + this.refreshIndicatorLayoutExtent = 0.0, + this.hasLayoutExtent = false, + super.child, + }) : assert(refreshIndicatorLayoutExtent >= 0.0); + + // The amount of space the indicator should occupy in the sliver in a + // resting state when in the refreshing mode. + final double refreshIndicatorLayoutExtent; + + // _RenderCupertinoSliverRefresh will paint the child in the available + // space either way but this instructs the _RenderCupertinoSliverRefresh + // on whether to also occupy any layoutExtent space or not. + final bool hasLayoutExtent; + + @override + _RenderCupertinoSliverRefresh createRenderObject(BuildContext context) { + return _RenderCupertinoSliverRefresh( + refreshIndicatorExtent: refreshIndicatorLayoutExtent, + hasLayoutExtent: hasLayoutExtent, + ); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderCupertinoSliverRefresh renderObject) { + renderObject + ..refreshIndicatorLayoutExtent = refreshIndicatorLayoutExtent + ..hasLayoutExtent = hasLayoutExtent; + } +} + +// RenderSliver object that gives its child RenderBox object space to paint +// in the overscrolled gap and may or may not hold that overscrolled gap +// around the RenderBox depending on whether [layoutExtent] is set. +// +// The [layoutExtentOffsetCompensation] field keeps internal accounting to +// prevent scroll position jumps as the [layoutExtent] is set and unset. +class _RenderCupertinoSliverRefresh extends RenderSliver + with RenderObjectWithChildMixin { + _RenderCupertinoSliverRefresh({ + required double refreshIndicatorExtent, + required bool hasLayoutExtent, + RenderBox? child, + }) : assert(refreshIndicatorExtent >= 0.0), + _refreshIndicatorExtent = refreshIndicatorExtent, + _hasLayoutExtent = hasLayoutExtent { + this.child = child; + } + + // The amount of layout space the indicator should occupy in the sliver in a + // resting state when in the refreshing mode. + double get refreshIndicatorLayoutExtent => _refreshIndicatorExtent; + double _refreshIndicatorExtent; + set refreshIndicatorLayoutExtent(double value) { + assert(value >= 0.0); + if (value == _refreshIndicatorExtent) { + return; + } + _refreshIndicatorExtent = value; + markNeedsLayout(); + } + + // The child box will be laid out and painted in the available space either + // way but this determines whether to also occupy any + // [SliverGeometry.layoutExtent] space or not. + bool get hasLayoutExtent => _hasLayoutExtent; + bool _hasLayoutExtent; + set hasLayoutExtent(bool value) { + if (value == _hasLayoutExtent) { + return; + } + _hasLayoutExtent = value; + markNeedsLayout(); + } + + // This keeps track of the previously applied scroll offsets to the scrollable + // so that when [refreshIndicatorLayoutExtent] or [hasLayoutExtent] changes, + // the appropriate delta can be applied to keep everything in the same place + // visually. + double layoutExtentOffsetCompensation = 0.0; + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + // Only pulling to refresh from the top is currently supported. + assert(constraints.axisDirection == AxisDirection.down); + assert(constraints.growthDirection == GrowthDirection.forward); + + // The new layout extent this sliver should now have. + final double layoutExtent = + (_hasLayoutExtent ? 1.0 : 0.0) * _refreshIndicatorExtent; + // If the new layoutExtent instructive changed, the SliverGeometry's + // layoutExtent will take that value (on the next performLayout run). Shift + // the scroll offset first so it doesn't make the scroll position suddenly jump. + if (layoutExtent != layoutExtentOffsetCompensation) { + geometry = SliverGeometry( + scrollOffsetCorrection: layoutExtent - layoutExtentOffsetCompensation, + ); + layoutExtentOffsetCompensation = layoutExtent; + // Return so we don't have to do temporary accounting and adjusting the + // child's constraints accounting for this one transient frame using a + // combination of existing layout extent, new layout extent change and + // the overlap. + return; + } + + final bool active = constraints.overlap < 0.0 || layoutExtent > 0.0; + final double overscrolledExtent = + constraints.overlap < 0.0 ? constraints.overlap.abs() : 0.0; + // Layout the child giving it the space of the currently dragged overscroll + // which may or may not include a sliver layout extent space that it will + // keep after the user lets go during the refresh process. + child!.layout( + constraints.asBoxConstraints( + maxExtent: layoutExtent + // Plus only the overscrolled portion immediately preceding this + // sliver. + + overscrolledExtent, + ), + parentUsesSize: true, + ); + if (active) { + geometry = SliverGeometry( + scrollExtent: layoutExtent, + paintOrigin: -overscrolledExtent - constraints.scrollOffset, + paintExtent: max( + // Check child size (which can come from overscroll) because + // layoutExtent may be zero. Check layoutExtent also since even + // with a layoutExtent, the indicator builder may decide to not + // build anything. + max(child!.size.height, layoutExtent) - constraints.scrollOffset, + 0.0, + ), + maxPaintExtent: max( + max(child!.size.height, layoutExtent) - constraints.scrollOffset, + 0.0, + ), + layoutExtent: max(layoutExtent - constraints.scrollOffset, 0.0), + ); + } else { + // If we never started overscrolling, return no geometry. + geometry = SliverGeometry.zero; + } + } + + @override + void paint(PaintingContext paintContext, Offset offset) { + if (constraints.overlap < 0.0 || + constraints.scrollOffset + child!.size.height > 0) { + paintContext.paintChild(child!, offset); + } + } + + // Nothing special done here because this sliver always paints its child + // exactly between paintOrigin and paintExtent. + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { } +} + +/// The current state of the refresh control. +/// +/// Passed into the [RefreshControlIndicatorBuilder] builder function so +/// users can show different UI in different modes. +enum RefreshIndicatorMode { + /// Initial state, when not being overscrolled into, or after the overscroll + /// is canceled or after done and the sliver retracted away. + inactive, + + /// While being overscrolled but not far enough yet to trigger the refresh. + drag, + + /// Dragged far enough that the onRefresh callback will run and the dragged + /// displacement is not yet at the final refresh resting state. + armed, + + /// While the onRefresh task is running. + refresh, + + /// While the indicator is animating away after refreshing. + done, +} + +/// Signature for a builder that can create a different widget to show in the +/// refresh indicator space depending on the current state of the refresh +/// control and the space available. +/// +/// The `refreshTriggerPullDistance` and `refreshIndicatorExtent` parameters are +/// the same values passed into the [CupertinoSliverRefreshControl]. +/// +/// The `pulledExtent` parameter is the currently available space either from +/// overscrolling or as held by the sliver during refresh. +typedef RefreshControlIndicatorBuilder = Widget Function( + BuildContext context, + RefreshIndicatorMode refreshState, + double pulledExtent, + double refreshTriggerPullDistance, + double refreshIndicatorExtent, +); + +/// A callback function that's invoked when the [CupertinoSliverRefreshControl] is +/// pulled a `refreshTriggerPullDistance`. Must return a [Future]. Upon +/// completion of the [Future], the [CupertinoSliverRefreshControl] enters the +/// [RefreshIndicatorMode.done] state and will start to go away. +typedef RefreshCallback = Future Function(); + +/// A sliver widget implementing the iOS-style pull to refresh content control. +/// +/// When inserted as the first sliver in a scroll view or behind other slivers +/// that still lets the scrollable overscroll in front of this sliver (such as +/// the [CupertinoSliverNavigationBar], this widget will: +/// +/// * Let the user draw inside the overscrolled area via the passed in [builder]. +/// * Trigger the provided [onRefresh] function when overscrolled far enough to +/// pass [refreshTriggerPullDistance]. +/// * Continue to hold [refreshIndicatorExtent] amount of space for the [builder] +/// to keep drawing inside of as the [Future] returned by [onRefresh] processes. +/// * Scroll away once the [onRefresh] [Future] completes. +/// +/// The [builder] function will be informed of the current [RefreshIndicatorMode] +/// when invoking it, except in the [RefreshIndicatorMode.inactive] state when +/// no space is available and nothing needs to be built. The [builder] function +/// will otherwise be continuously invoked as the amount of space available +/// changes from overscroll, as the sliver scrolls away after the [onRefresh] +/// task is done, etc. +/// +/// Only one refresh can be triggered until the previous refresh has completed +/// and the indicator sliver has retracted at least 90% of the way back. +/// +/// Can only be used in downward-scrolling vertical lists that overscrolls. In +/// other words, refreshes can't be triggered with [Scrollable]s using +/// [ClampingScrollPhysics] which is the default on Android. To allow overscroll +/// on Android, use an overscrolling physics such as [BouncingScrollPhysics]. +/// This can be done via: +/// +/// * Providing a [BouncingScrollPhysics] (possibly in combination with a +/// [AlwaysScrollableScrollPhysics]) while constructing the scrollable. +/// * By inserting a [ScrollConfiguration] with [BouncingScrollPhysics] above +/// the scrollable. +/// * By using [CupertinoApp], which always uses a [ScrollConfiguration] +/// with [BouncingScrollPhysics] regardless of platform. +/// +/// In a typical application, this sliver should be inserted between the app bar +/// sliver such as [CupertinoSliverNavigationBar] and your main scrollable +/// content's sliver. +/// +/// {@tool dartpad} +/// When the user scrolls past [refreshTriggerPullDistance], +/// this sample shows the default iOS pull to refresh indicator for 1 second and +/// adds a new item to the top of the list view. +/// +/// ** See code in examples/api/lib/cupertino/refresh/cupertino_sliver_refresh_control.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CustomScrollView], a typical sliver holding scroll view this control +/// should go into. +/// * +/// * [RefreshIndicator], a Material Design version of the pull-to-refresh +/// paradigm. This widget works differently than [RefreshIndicator] because +/// instead of being an overlay on top of the scrollable, the +/// [CupertinoSliverRefreshControl] is part of the scrollable and actively occupies +/// scrollable space. +class CupertinoSliverRefreshControl extends StatefulWidget { + /// Create a new refresh control for inserting into a list of slivers. + /// + /// The [refreshTriggerPullDistance] and [refreshIndicatorExtent] arguments + /// must be greater than or equal to 0. + /// + /// The [builder] argument may be null, in which case no indicator UI will be + /// shown but the [onRefresh] will still be invoked. By default, [builder] + /// shows a [CupertinoActivityIndicator]. + /// + /// The [onRefresh] argument will be called when pulled far enough to trigger + /// a refresh. + const CupertinoSliverRefreshControl({ + super.key, + this.refreshTriggerPullDistance = _defaultRefreshTriggerPullDistance, + this.refreshIndicatorExtent = _defaultRefreshIndicatorExtent, + this.builder = buildRefreshIndicator, + this.onRefresh, + }) : assert(refreshTriggerPullDistance > 0.0), + assert(refreshIndicatorExtent >= 0.0), + assert( + refreshTriggerPullDistance >= refreshIndicatorExtent, + 'The refresh indicator cannot take more space in its final state ' + 'than the amount initially created by overscrolling.', + ); + + /// The amount of overscroll the scrollable must be dragged to trigger a reload. + /// + /// Must be larger than zero and larger than [refreshIndicatorExtent]. + /// Defaults to 100 pixels when not specified. + /// + /// When overscrolled past this distance, [onRefresh] will be called if not + /// null and the [builder] will build in the [RefreshIndicatorMode.armed] state. + final double refreshTriggerPullDistance; + + /// The amount of space the refresh indicator sliver will keep holding while + /// [onRefresh]'s [Future] is still running. + /// + /// Must be a positive number, but can be zero, in which case the sliver will + /// start retracting back to zero as soon as the refresh is started. Defaults + /// to 60 pixels when not specified. + /// + /// Must be smaller than [refreshTriggerPullDistance], since the sliver + /// shouldn't grow further after triggering the refresh. + final double refreshIndicatorExtent; + + /// A builder that's called as this sliver's size changes, and as the state + /// changes. + /// + /// Can be set to null, in which case nothing will be drawn in the overscrolled + /// space. + /// + /// Will not be called when the available space is zero such as before any + /// overscroll. + final RefreshControlIndicatorBuilder? builder; + + /// Callback invoked when pulled by [refreshTriggerPullDistance]. + /// + /// If provided, must return a [Future] which will keep the indicator in the + /// [RefreshIndicatorMode.refresh] state until the [Future] completes. + /// + /// Can be null, in which case a single frame of [RefreshIndicatorMode.armed] + /// state will be drawn before going immediately to the [RefreshIndicatorMode.done] + /// where the sliver will start retracting. + final RefreshCallback? onRefresh; + + static const double _defaultRefreshTriggerPullDistance = 100.0; + static const double _defaultRefreshIndicatorExtent = 60.0; + + /// Retrieve the current state of the CupertinoSliverRefreshControl. The same as the + /// state that gets passed into the [builder] function. Used for testing. + @visibleForTesting + static RefreshIndicatorMode state(BuildContext context) { + final _CupertinoSliverRefreshControlState state = context.findAncestorStateOfType<_CupertinoSliverRefreshControlState>()!; + return state.refreshState; + } + + /// Builds a refresh indicator that reflects the standard iOS pull-to-refresh + /// behavior. Specifically, this entails presenting an activity indicator that + /// changes depending on the current refreshState. As the user initially drags + /// down, the indicator will gradually reveal individual ticks until the refresh + /// becomes armed. At this point, the animated activity indicator will begin rotating. + /// Once the refresh has completed, the activity indicator shrinks away as the + /// space allocation animates back to closed. + static Widget buildRefreshIndicator( + BuildContext context, + RefreshIndicatorMode refreshState, + double pulledExtent, + double refreshTriggerPullDistance, + double refreshIndicatorExtent, + ) { + final double percentageComplete = clampDouble(pulledExtent / refreshTriggerPullDistance, 0.0, 1.0); + + // Place the indicator at the top of the sliver that opens up. We're using a + // Stack/Positioned widget because the CupertinoActivityIndicator does some + // internal translations based on the current size (which grows as the user drags) + // that makes Padding calculations difficult. Rather than be reliant on the + // internal implementation of the activity indicator, the Positioned widget allows + // us to be explicit where the widget gets placed. The indicator should appear + // over the top of the dragged widget, hence the use of Clip.none. + return Center( + child: Stack( + clipBehavior: Clip.none, + children: [ + Positioned( + top: _kActivityIndicatorMargin, + left: 0.0, + right: 0.0, + child: _buildIndicatorForRefreshState(refreshState, _kActivityIndicatorRadius, percentageComplete), + ), + ], + ), + ); + } + + static Widget _buildIndicatorForRefreshState(RefreshIndicatorMode refreshState, double radius, double percentageComplete) { + switch (refreshState) { + case RefreshIndicatorMode.drag: + // While we're dragging, we draw individual ticks of the spinner while simultaneously + // easing the opacity in. The opacity curve values here were derived using + // Xcode through inspecting a native app running on iOS 13.5. + const Curve opacityCurve = Interval(0.0, 0.35, curve: Curves.easeInOut); + return Opacity( + opacity: opacityCurve.transform(percentageComplete), + child: CupertinoActivityIndicator.partiallyRevealed(radius: radius, progress: percentageComplete), + ); + case RefreshIndicatorMode.armed: + case RefreshIndicatorMode.refresh: + // Once we're armed or performing the refresh, we just show the normal spinner. + return CupertinoActivityIndicator(radius: radius); + case RefreshIndicatorMode.done: + // When the user lets go, the standard transition is to shrink the spinner. + return CupertinoActivityIndicator(radius: radius * percentageComplete); + case RefreshIndicatorMode.inactive: + // Anything else doesn't show anything. + return const SizedBox.shrink(); + } + } + + @override + State createState() => _CupertinoSliverRefreshControlState(); +} + +class _CupertinoSliverRefreshControlState extends State { + // Reset the state from done to inactive when only this fraction of the + // original `refreshTriggerPullDistance` is left. + static const double _inactiveResetOverscrollFraction = 0.1; + + late RefreshIndicatorMode refreshState; + // [Future] returned by the widget's `onRefresh`. + Future? refreshTask; + // The amount of space available from the inner indicator box's perspective. + // + // The value is the sum of the sliver's layout extent and the overscroll + // (which partially gets transferred into the layout extent when the refresh + // triggers). + // + // The value of latestIndicatorBoxExtent doesn't change when the sliver scrolls + // away without retracting; it is independent from the sliver's scrollOffset. + double latestIndicatorBoxExtent = 0.0; + bool hasSliverLayoutExtent = false; + + @override + void initState() { + super.initState(); + refreshState = RefreshIndicatorMode.inactive; + } + + // A state machine transition calculator. Multiple states can be transitioned + // through per single call. + RefreshIndicatorMode transitionNextState() { + RefreshIndicatorMode nextState; + + void goToDone() { + nextState = RefreshIndicatorMode.done; + // Either schedule the RenderSliver to re-layout on the next frame + // when not currently in a frame or schedule it on the next frame. + if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.idle) { + setState(() => hasSliverLayoutExtent = false); + } else { + SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) { + setState(() => hasSliverLayoutExtent = false); + }, debugLabel: 'Refresh.goToDone'); + } + } + + switch (refreshState) { + case RefreshIndicatorMode.inactive: + if (latestIndicatorBoxExtent <= 0) { + return RefreshIndicatorMode.inactive; + } else { + nextState = RefreshIndicatorMode.drag; + } + continue drag; + drag: + case RefreshIndicatorMode.drag: + if (latestIndicatorBoxExtent == 0) { + return RefreshIndicatorMode.inactive; + } else if (latestIndicatorBoxExtent < widget.refreshTriggerPullDistance) { + return RefreshIndicatorMode.drag; + } else { + if (widget.onRefresh != null) { + HapticFeedback.mediumImpact(); + // Call onRefresh after this frame finished since the function is + // user supplied and we're always here in the middle of the sliver's + // performLayout. + SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) { + refreshTask = widget.onRefresh!()..whenComplete(() { + if (mounted) { + setState(() => refreshTask = null); + // Trigger one more transition because by this time, BoxConstraint's + // maxHeight might already be resting at 0 in which case no + // calls to [transitionNextState] will occur anymore and the + // state may be stuck in a non-inactive state. + refreshState = transitionNextState(); + } + }); + setState(() => hasSliverLayoutExtent = true); + }, debugLabel: 'Refresh.transition'); + } + return RefreshIndicatorMode.armed; + } + case RefreshIndicatorMode.armed: + if (refreshState == RefreshIndicatorMode.armed && refreshTask == null) { + goToDone(); + continue done; + } + + if (latestIndicatorBoxExtent > widget.refreshIndicatorExtent) { + return RefreshIndicatorMode.armed; + } else { + nextState = RefreshIndicatorMode.refresh; + } + continue refresh; + refresh: + case RefreshIndicatorMode.refresh: + if (refreshTask != null) { + return RefreshIndicatorMode.refresh; + } else { + goToDone(); + } + continue done; + done: + case RefreshIndicatorMode.done: + // Let the transition back to inactive trigger before strictly going + // to 0.0 since the last bit of the animation can take some time and + // can feel sluggish if not going all the way back to 0.0 prevented + // a subsequent pull-to-refresh from starting. + if (latestIndicatorBoxExtent > + widget.refreshTriggerPullDistance * _inactiveResetOverscrollFraction) { + return RefreshIndicatorMode.done; + } else { + nextState = RefreshIndicatorMode.inactive; + } + } + + return nextState; + } + + @override + Widget build(BuildContext context) { + return _CupertinoSliverRefresh( + refreshIndicatorLayoutExtent: widget.refreshIndicatorExtent, + hasLayoutExtent: hasSliverLayoutExtent, + // A LayoutBuilder lets the sliver's layout changes be fed back out to + // its owner to trigger state changes. + child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + latestIndicatorBoxExtent = constraints.maxHeight; + refreshState = transitionNextState(); + if (widget.builder != null && latestIndicatorBoxExtent > 0) { + return widget.builder!( + context, + refreshState, + latestIndicatorBoxExtent, + widget.refreshTriggerPullDistance, + widget.refreshIndicatorExtent, + ); + } + return Container(); + }, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/route.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/route.dart new file mode 100644 index 0000000000000000000000000000000000000000..5ad137b9ed56f6028d8c525e588a099d7098852e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/route.dart @@ -0,0 +1,1354 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math'; +import 'dart:ui' show ImageFilter, lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'interface_level.dart'; +import 'localizations.dart'; + +const double _kBackGestureWidth = 20.0; +const double _kMinFlingVelocity = 1.0; // Screen widths per second. + +// An eyeballed value for the maximum time it takes for a page to animate forward +// if the user releases a page mid swipe. +const int _kMaxDroppedSwipePageForwardAnimationTime = 800; // Milliseconds. + +// The maximum time for a page to get reset to it's original position if the +// user releases a page mid swipe. +const int _kMaxPageBackAnimationTime = 300; // Milliseconds. + +/// Barrier color used for a barrier visible during transitions for Cupertino +/// page routes. +/// +/// This barrier color is only used for full-screen page routes with +/// `fullscreenDialog: false`. +/// +/// By default, `fullscreenDialog` Cupertino route transitions have no +/// `barrierColor`, and [CupertinoDialogRoute]s and [CupertinoModalPopupRoute]s +/// have a `barrierColor` defined by [kCupertinoModalBarrierColor]. +/// +/// A relatively rigorous eyeball estimation. +const Color _kCupertinoPageTransitionBarrierColor = Color(0x18000000); + +/// Barrier color for a Cupertino modal barrier. +/// +/// Extracted from https://developer.apple.com/design/resources/. +const Color kCupertinoModalBarrierColor = CupertinoDynamicColor.withBrightness( + color: Color(0x33000000), + darkColor: Color(0x7A000000), +); + +// The duration of the transition used when a modal popup is shown. +const Duration _kModalPopupTransitionDuration = Duration(milliseconds: 335); + +// Offset from offscreen to the right to fully on screen. +final Animatable _kRightMiddleTween = Tween( + begin: const Offset(1.0, 0.0), + end: Offset.zero, +); + +// Offset from fully on screen to 1/3 offscreen to the left. +final Animatable _kMiddleLeftTween = Tween( + begin: Offset.zero, + end: const Offset(-1.0/3.0, 0.0), +); + +// Offset from offscreen below to fully on screen. +final Animatable _kBottomUpTween = Tween( + begin: const Offset(0.0, 1.0), + end: Offset.zero, +); + +/// A mixin that replaces the entire screen with an iOS transition for a +/// [PageRoute]. +/// +/// {@template flutter.cupertino.cupertinoRouteTransitionMixin} +/// The page slides in from the right and exits in reverse. The page also shifts +/// to the left in parallax when another page enters to cover it. +/// +/// The page slides in from the bottom and exits in reverse with no parallax +/// effect for fullscreen dialogs. +/// {@endtemplate} +/// +/// See also: +/// +/// * [MaterialRouteTransitionMixin], which is a mixin that provides +/// platform-appropriate transitions for a [PageRoute]. +/// * [CupertinoPageRoute], which is a [PageRoute] that leverages this mixin. +mixin CupertinoRouteTransitionMixin on PageRoute { + /// Builds the primary contents of the route. + @protected + Widget buildContent(BuildContext context); + + /// {@template flutter.cupertino.CupertinoRouteTransitionMixin.title} + /// A title string for this route. + /// + /// Used to auto-populate [CupertinoNavigationBar] and + /// [CupertinoSliverNavigationBar]'s `middle`/`largeTitle` widgets when + /// one is not manually supplied. + /// {@endtemplate} + String? get title; + + ValueNotifier? _previousTitle; + + /// The title string of the previous [CupertinoPageRoute]. + /// + /// The [ValueListenable]'s value is readable after the route is installed + /// onto a [Navigator]. The [ValueListenable] will also notify its listeners + /// if the value changes (such as by replacing the previous route). + /// + /// The [ValueListenable] itself will be null before the route is installed. + /// Its content value will be null if the previous route has no title or + /// is not a [CupertinoPageRoute]. + /// + /// See also: + /// + /// * [ValueListenableBuilder], which can be used to listen and rebuild + /// widgets based on a ValueListenable. + ValueListenable get previousTitle { + assert( + _previousTitle != null, + 'Cannot read the previousTitle for a route that has not yet been installed', + ); + return _previousTitle!; + } + + @override + void dispose() { + _previousTitle?.dispose(); + super.dispose(); + } + + @override + void didChangePrevious(Route? previousRoute) { + final String? previousTitleString = previousRoute is CupertinoRouteTransitionMixin + ? previousRoute.title + : null; + if (_previousTitle == null) { + _previousTitle = ValueNotifier(previousTitleString); + } else { + _previousTitle!.value = previousTitleString; + } + super.didChangePrevious(previousRoute); + } + + @override + // A relatively rigorous eyeball estimation. + Duration get transitionDuration => const Duration(milliseconds: 500); + + @override + Color? get barrierColor => fullscreenDialog ? null : _kCupertinoPageTransitionBarrierColor; + + @override + String? get barrierLabel => null; + + @override + bool canTransitionTo(TransitionRoute nextRoute) { + // Don't perform outgoing animation if the next route is a fullscreen dialog. + return nextRoute is CupertinoRouteTransitionMixin && !nextRoute.fullscreenDialog; + } + + /// True if an iOS-style back swipe pop gesture is currently underway for [route]. + /// + /// This just check the route's [NavigatorState.userGestureInProgress]. + /// + /// See also: + /// + /// * [popGestureEnabled], which returns true if a user-triggered pop gesture + /// would be allowed. + static bool isPopGestureInProgress(PageRoute route) { + return route.navigator!.userGestureInProgress; + } + + /// True if an iOS-style back swipe pop gesture is currently underway for this route. + /// + /// See also: + /// + /// * [isPopGestureInProgress], which returns true if a Cupertino pop gesture + /// is currently underway for specific route. + /// * [popGestureEnabled], which returns true if a user-triggered pop gesture + /// would be allowed. + bool get popGestureInProgress => isPopGestureInProgress(this); + + /// Whether a pop gesture can be started by the user. + /// + /// Returns true if the user can edge-swipe to a previous route. + /// + /// Returns false once [isPopGestureInProgress] is true, but + /// [isPopGestureInProgress] can only become true if [popGestureEnabled] was + /// true first. + /// + /// This should only be used between frames, not during build. + bool get popGestureEnabled => _isPopGestureEnabled(this); + + static bool _isPopGestureEnabled(PageRoute route) { + // If there's nothing to go back to, then obviously we don't support + // the back gesture. + if (route.isFirst) { + return false; + } + // If the route wouldn't actually pop if we popped it, then the gesture + // would be really confusing (or would skip internal routes), so disallow it. + if (route.willHandlePopInternally) { + return false; + } + // If attempts to dismiss this route might be vetoed such as in a page + // with forms, then do not allow the user to dismiss the route with a swipe. + if (route.hasScopedWillPopCallback + || route.popDisposition == RoutePopDisposition.doNotPop) { + return false; + } + // Fullscreen dialogs aren't dismissible by back swipe. + if (route.fullscreenDialog) { + return false; + } + // If we're in an animation already, we cannot be manually swiped. + if (route.animation!.status != AnimationStatus.completed) { + return false; + } + // If we're being popped into, we also cannot be swiped until the pop above + // it completes. This translates to our secondary animation being + // dismissed. + if (route.secondaryAnimation!.status != AnimationStatus.dismissed) { + return false; + } + // If we're in a gesture already, we cannot start another. + if (isPopGestureInProgress(route)) { + return false; + } + + // Looks like a back gesture would be welcome! + return true; + } + + @override + Widget buildPage(BuildContext context, Animation animation, Animation secondaryAnimation) { + final Widget child = buildContent(context); + return Semantics( + scopesRoute: true, + explicitChildNodes: true, + child: child, + ); + } + + // Called by _CupertinoBackGestureDetector when a pop ("back") drag start + // gesture is detected. The returned controller handles all of the subsequent + // drag events. + static _CupertinoBackGestureController _startPopGesture(PageRoute route) { + assert(_isPopGestureEnabled(route)); + + return _CupertinoBackGestureController( + navigator: route.navigator!, + controller: route.controller!, // protected access + ); + } + + /// Returns a [CupertinoFullscreenDialogTransition] if [route] is a full + /// screen dialog, otherwise a [CupertinoPageTransition] is returned. + /// + /// Used by [CupertinoPageRoute.buildTransitions]. + /// + /// This method can be applied to any [PageRoute], not just + /// [CupertinoPageRoute]. It's typically used to provide a Cupertino style + /// horizontal transition for material widgets when the target platform + /// is [TargetPlatform.iOS]. + /// + /// See also: + /// + /// * [CupertinoPageTransitionsBuilder], which uses this method to define a + /// [PageTransitionsBuilder] for the [PageTransitionsTheme]. + static Widget buildPageTransitions( + PageRoute route, + BuildContext context, + Animation animation, + Animation secondaryAnimation, + Widget child, + ) { + // Check if the route has an animation that's currently participating + // in a back swipe gesture. + // + // In the middle of a back gesture drag, let the transition be linear to + // match finger motions. + final bool linearTransition = isPopGestureInProgress(route); + if (route.fullscreenDialog) { + return CupertinoFullscreenDialogTransition( + primaryRouteAnimation: animation, + secondaryRouteAnimation: secondaryAnimation, + linearTransition: linearTransition, + child: child, + ); + } else { + return CupertinoPageTransition( + primaryRouteAnimation: animation, + secondaryRouteAnimation: secondaryAnimation, + linearTransition: linearTransition, + child: _CupertinoBackGestureDetector( + enabledCallback: () => _isPopGestureEnabled(route), + onStartPopGesture: () => _startPopGesture(route), + child: child, + ), + ); + } + } + + @override + Widget buildTransitions(BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { + return buildPageTransitions(this, context, animation, secondaryAnimation, child); + } +} + +/// A modal route that replaces the entire screen with an iOS transition. +/// +/// {@macro flutter.cupertino.cupertinoRouteTransitionMixin} +/// +/// By default, when a modal route is replaced by another, the previous route +/// remains in memory. To free all the resources when this is not necessary, set +/// [maintainState] to false. +/// +/// The type `T` specifies the return type of the route which can be supplied as +/// the route is popped from the stack via [Navigator.pop] when an optional +/// `result` can be provided. +/// +/// If `barrierDismissible` is true, then pressing the escape key on the keyboard +/// will cause the current route to be popped with null as the value. +/// +/// See also: +/// +/// * [CupertinoRouteTransitionMixin], for a mixin that provides iOS transition +/// for this modal route. +/// * [MaterialPageRoute], for an adaptive [PageRoute] that uses a +/// platform-appropriate transition. +/// * [CupertinoPageScaffold], for applications that have one page with a fixed +/// navigation bar on top. +/// * [CupertinoTabScaffold], for applications that have a tab bar at the +/// bottom with multiple pages. +/// * [CupertinoPage], for a [Page] version of this class. +class CupertinoPageRoute extends PageRoute with CupertinoRouteTransitionMixin { + /// Creates a page route for use in an iOS designed app. + /// + /// The [builder], [maintainState], and [fullscreenDialog] arguments must not + /// be null. + CupertinoPageRoute({ + required this.builder, + this.title, + super.settings, + this.maintainState = true, + super.fullscreenDialog, + super.allowSnapshotting = true, + super.barrierDismissible = false, + }) { + assert(opaque); + } + + /// Builds the primary contents of the route. + final WidgetBuilder builder; + + @override + Widget buildContent(BuildContext context) => builder(context); + + @override + final String? title; + + @override + final bool maintainState; + + @override + String get debugLabel => '${super.debugLabel}(${settings.name})'; +} + +// A page-based version of CupertinoPageRoute. +// +// This route uses the builder from the page to build its content. This ensures +// the content is up to date after page updates. +class _PageBasedCupertinoPageRoute extends PageRoute with CupertinoRouteTransitionMixin { + _PageBasedCupertinoPageRoute({ + required CupertinoPage page, + super.allowSnapshotting = true, + }) : super(settings: page) { + assert(opaque); + } + + CupertinoPage get _page => settings as CupertinoPage; + + @override + Widget buildContent(BuildContext context) => _page.child; + + @override + String? get title => _page.title; + + @override + bool get maintainState => _page.maintainState; + + @override + bool get fullscreenDialog => _page.fullscreenDialog; + + @override + String get debugLabel => '${super.debugLabel}(${_page.name})'; +} + +/// A page that creates a cupertino style [PageRoute]. +/// +/// {@macro flutter.cupertino.cupertinoRouteTransitionMixin} +/// +/// By default, when a created modal route is replaced by another, the previous +/// route remains in memory. To free all the resources when this is not +/// necessary, set [maintainState] to false. +/// +/// The type `T` specifies the return type of the route which can be supplied as +/// the route is popped from the stack via [Navigator.transitionDelegate] by +/// providing the optional `result` argument to the +/// [RouteTransitionRecord.markForPop] in the [TransitionDelegate.resolve]. +/// +/// See also: +/// +/// * [CupertinoPageRoute], for a [PageRoute] version of this class. +class CupertinoPage extends Page { + /// Creates a cupertino page. + const CupertinoPage({ + required this.child, + this.maintainState = true, + this.title, + this.fullscreenDialog = false, + this.allowSnapshotting = true, + super.key, + super.name, + super.arguments, + super.restorationId, + }); + + /// The content to be shown in the [Route] created by this page. + final Widget child; + + /// {@macro flutter.cupertino.CupertinoRouteTransitionMixin.title} + final String? title; + + /// {@macro flutter.widgets.ModalRoute.maintainState} + final bool maintainState; + + /// {@macro flutter.widgets.PageRoute.fullscreenDialog} + final bool fullscreenDialog; + + /// {@macro flutter.widgets.TransitionRoute.allowSnapshotting} + final bool allowSnapshotting; + + @override + Route createRoute(BuildContext context) { + return _PageBasedCupertinoPageRoute(page: this, allowSnapshotting: allowSnapshotting); + } +} + +/// Provides an iOS-style page transition animation. +/// +/// The page slides in from the right and exits in reverse. It also shifts to the left in +/// a parallax motion when another page enters to cover it. +class CupertinoPageTransition extends StatelessWidget { + /// Creates an iOS-style page transition. + /// + /// * `primaryRouteAnimation` is a linear route animation from 0.0 to 1.0 + /// when this screen is being pushed. + /// * `secondaryRouteAnimation` is a linear route animation from 0.0 to 1.0 + /// when another screen is being pushed on top of this one. + /// * `linearTransition` is whether to perform the transitions linearly. + /// Used to precisely track back gesture drags. + CupertinoPageTransition({ + super.key, + required Animation primaryRouteAnimation, + required Animation secondaryRouteAnimation, + required this.child, + required bool linearTransition, + }) : _primaryPositionAnimation = + (linearTransition + ? primaryRouteAnimation + : CurvedAnimation( + parent: primaryRouteAnimation, + curve: Curves.fastEaseInToSlowEaseOut, + reverseCurve: Curves.fastEaseInToSlowEaseOut.flipped, + ) + ).drive(_kRightMiddleTween), + _secondaryPositionAnimation = + (linearTransition + ? secondaryRouteAnimation + : CurvedAnimation( + parent: secondaryRouteAnimation, + curve: Curves.linearToEaseOut, + reverseCurve: Curves.easeInToLinear, + ) + ).drive(_kMiddleLeftTween), + _primaryShadowAnimation = + (linearTransition + ? primaryRouteAnimation + : CurvedAnimation( + parent: primaryRouteAnimation, + curve: Curves.linearToEaseOut, + ) + ).drive(_CupertinoEdgeShadowDecoration.kTween); + + // When this page is coming in to cover another page. + final Animation _primaryPositionAnimation; + // When this page is becoming covered by another page. + final Animation _secondaryPositionAnimation; + final Animation _primaryShadowAnimation; + + /// The widget below this widget in the tree. + final Widget child; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + final TextDirection textDirection = Directionality.of(context); + return SlideTransition( + position: _secondaryPositionAnimation, + textDirection: textDirection, + transformHitTests: false, + child: SlideTransition( + position: _primaryPositionAnimation, + textDirection: textDirection, + child: DecoratedBoxTransition( + decoration: _primaryShadowAnimation, + child: child, + ), + ), + ); + } +} + +/// An iOS-style transition used for summoning fullscreen dialogs. +/// +/// For example, used when creating a new calendar event by bringing in the next +/// screen from the bottom. +class CupertinoFullscreenDialogTransition extends StatelessWidget { + /// Creates an iOS-style transition used for summoning fullscreen dialogs. + /// + /// * `primaryRouteAnimation` is a linear route animation from 0.0 to 1.0 + /// when this screen is being pushed. + /// * `secondaryRouteAnimation` is a linear route animation from 0.0 to 1.0 + /// when another screen is being pushed on top of this one. + /// * `linearTransition` is whether to perform the secondary transition linearly. + /// Used to precisely track back gesture drags. + CupertinoFullscreenDialogTransition({ + super.key, + required Animation primaryRouteAnimation, + required Animation secondaryRouteAnimation, + required this.child, + required bool linearTransition, + }) : _positionAnimation = CurvedAnimation( + parent: primaryRouteAnimation, + curve: Curves.linearToEaseOut, + // The curve must be flipped so that the reverse animation doesn't play + // an ease-in curve, which iOS does not use. + reverseCurve: Curves.linearToEaseOut.flipped, + ).drive(_kBottomUpTween), + _secondaryPositionAnimation = + (linearTransition + ? secondaryRouteAnimation + : CurvedAnimation( + parent: secondaryRouteAnimation, + curve: Curves.linearToEaseOut, + reverseCurve: Curves.easeInToLinear, + ) + ).drive(_kMiddleLeftTween); + + final Animation _positionAnimation; + // When this page is becoming covered by another page. + final Animation _secondaryPositionAnimation; + + /// The widget below this widget in the tree. + final Widget child; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + final TextDirection textDirection = Directionality.of(context); + return SlideTransition( + position: _secondaryPositionAnimation, + textDirection: textDirection, + transformHitTests: false, + child: SlideTransition( + position: _positionAnimation, + child: child, + ), + ); + } +} + +/// This is the widget side of [_CupertinoBackGestureController]. +/// +/// This widget provides a gesture recognizer which, when it determines the +/// route can be closed with a back gesture, creates the controller and +/// feeds it the input from the gesture recognizer. +/// +/// The gesture data is converted from absolute coordinates to logical +/// coordinates by this widget. +/// +/// The type `T` specifies the return type of the route with which this gesture +/// detector is associated. +class _CupertinoBackGestureDetector extends StatefulWidget { + const _CupertinoBackGestureDetector({ + super.key, + required this.enabledCallback, + required this.onStartPopGesture, + required this.child, + }); + + final Widget child; + + final ValueGetter enabledCallback; + + final ValueGetter<_CupertinoBackGestureController> onStartPopGesture; + + @override + _CupertinoBackGestureDetectorState createState() => _CupertinoBackGestureDetectorState(); +} + +class _CupertinoBackGestureDetectorState extends State<_CupertinoBackGestureDetector> { + _CupertinoBackGestureController? _backGestureController; + + late HorizontalDragGestureRecognizer _recognizer; + + @override + void initState() { + super.initState(); + _recognizer = HorizontalDragGestureRecognizer(debugOwner: this) + ..onStart = _handleDragStart + ..onUpdate = _handleDragUpdate + ..onEnd = _handleDragEnd + ..onCancel = _handleDragCancel; + } + + @override + void dispose() { + _recognizer.dispose(); + + // If this is disposed during a drag, call navigator.didStopUserGesture. + if (_backGestureController != null) { + WidgetsBinding.instance.addPostFrameCallback((_) { + if (_backGestureController?.navigator.mounted ?? false) { + _backGestureController?.navigator.didStopUserGesture(); + } + _backGestureController = null; + }); + } + super.dispose(); + } + + void _handleDragStart(DragStartDetails details) { + assert(mounted); + assert(_backGestureController == null); + _backGestureController = widget.onStartPopGesture(); + } + + void _handleDragUpdate(DragUpdateDetails details) { + assert(mounted); + assert(_backGestureController != null); + _backGestureController!.dragUpdate(_convertToLogical(details.primaryDelta! / context.size!.width)); + } + + void _handleDragEnd(DragEndDetails details) { + assert(mounted); + assert(_backGestureController != null); + _backGestureController!.dragEnd(_convertToLogical(details.velocity.pixelsPerSecond.dx / context.size!.width)); + _backGestureController = null; + } + + void _handleDragCancel() { + assert(mounted); + // This can be called even if start is not called, paired with the "down" event + // that we don't consider here. + _backGestureController?.dragEnd(0.0); + _backGestureController = null; + } + + void _handlePointerDown(PointerDownEvent event) { + if (widget.enabledCallback()) { + _recognizer.addPointer(event); + } + } + + double _convertToLogical(double value) { + switch (Directionality.of(context)) { + case TextDirection.rtl: + return -value; + case TextDirection.ltr: + return value; + } + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + // For devices with notches, the drag area needs to be larger on the side + // that has the notch. + double dragAreaWidth = Directionality.of(context) == TextDirection.ltr ? + MediaQuery.paddingOf(context).left : + MediaQuery.paddingOf(context).right; + dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth); + return Stack( + fit: StackFit.passthrough, + children: [ + widget.child, + PositionedDirectional( + start: 0.0, + width: dragAreaWidth, + top: 0.0, + bottom: 0.0, + child: Listener( + onPointerDown: _handlePointerDown, + behavior: HitTestBehavior.translucent, + ), + ), + ], + ); + } +} + +/// A controller for an iOS-style back gesture. +/// +/// This is created by a [CupertinoPageRoute] in response from a gesture caught +/// by a [_CupertinoBackGestureDetector] widget, which then also feeds it input +/// from the gesture. It controls the animation controller owned by the route, +/// based on the input provided by the gesture detector. +/// +/// This class works entirely in logical coordinates (0.0 is new page dismissed, +/// 1.0 is new page on top). +/// +/// The type `T` specifies the return type of the route with which this gesture +/// detector controller is associated. +class _CupertinoBackGestureController { + /// Creates a controller for an iOS-style back gesture. + _CupertinoBackGestureController({ + required this.navigator, + required this.controller, + }) { + navigator.didStartUserGesture(); + } + + final AnimationController controller; + final NavigatorState navigator; + + /// The drag gesture has changed by [fractionalDelta]. The total range of the + /// drag should be 0.0 to 1.0. + void dragUpdate(double delta) { + controller.value -= delta; + } + + /// The drag gesture has ended with a horizontal motion of + /// [fractionalVelocity] as a fraction of screen width per second. + void dragEnd(double velocity) { + // Fling in the appropriate direction. + // + // This curve has been determined through rigorously eyeballing native iOS + // animations. + const Curve animationCurve = Curves.fastLinearToSlowEaseIn; + final bool animateForward; + + // If the user releases the page before mid screen with sufficient velocity, + // or after mid screen, we should animate the page out. Otherwise, the page + // should be animated back in. + if (velocity.abs() >= _kMinFlingVelocity) { + animateForward = velocity <= 0; + } else { + animateForward = controller.value > 0.5; + } + + if (animateForward) { + // The closer the panel is to dismissing, the shorter the animation is. + // We want to cap the animation time, but we want to use a linear curve + // to determine it. + final int droppedPageForwardAnimationTime = min( + lerpDouble(_kMaxDroppedSwipePageForwardAnimationTime, 0, controller.value)!.floor(), + _kMaxPageBackAnimationTime, + ); + controller.animateTo(1.0, duration: Duration(milliseconds: droppedPageForwardAnimationTime), curve: animationCurve); + } else { + // This route is destined to pop at this point. Reuse navigator's pop. + navigator.pop(); + + // The popping may have finished inline if already at the target destination. + if (controller.isAnimating) { + // Otherwise, use a custom popping animation duration and curve. + final int droppedPageBackAnimationTime = lerpDouble(0, _kMaxDroppedSwipePageForwardAnimationTime, controller.value)!.floor(); + controller.animateBack(0.0, duration: Duration(milliseconds: droppedPageBackAnimationTime), curve: animationCurve); + } + } + + if (controller.isAnimating) { + // Keep the userGestureInProgress in true state so we don't change the + // curve of the page transition mid-flight since CupertinoPageTransition + // depends on userGestureInProgress. + late AnimationStatusListener animationStatusCallback; + animationStatusCallback = (AnimationStatus status) { + navigator.didStopUserGesture(); + controller.removeStatusListener(animationStatusCallback); + }; + controller.addStatusListener(animationStatusCallback); + } else { + navigator.didStopUserGesture(); + } + } +} + +// A custom [Decoration] used to paint an extra shadow on the start edge of the +// box it's decorating. It's like a [BoxDecoration] with only a gradient except +// it paints on the start side of the box instead of behind the box. +class _CupertinoEdgeShadowDecoration extends Decoration { + const _CupertinoEdgeShadowDecoration._([this._colors]); + + static DecorationTween kTween = DecorationTween( + begin: const _CupertinoEdgeShadowDecoration._(), // No decoration initially. + end: const _CupertinoEdgeShadowDecoration._( + // Eyeballed gradient used to mimic a drop shadow on the start side only. + [ + Color(0x04000000), + Color(0x00000000), + ], + ), + ); + + // Colors used to paint a gradient at the start edge of the box it is + // decorating. + // + // The first color in the list is used at the start of the gradient, which + // is located at the start edge of the decorated box. + // + // If this is null, no shadow is drawn. + // + // The list must have at least two colors in it (otherwise it would not be a + // gradient). + final List? _colors; + + // Linearly interpolate between two edge shadow decorations decorations. + // + // The `t` argument represents position on the timeline, with 0.0 meaning + // that the interpolation has not started, returning `a` (or something + // equivalent to `a`), 1.0 meaning that the interpolation has finished, + // returning `b` (or something equivalent to `b`), and values in between + // meaning that the interpolation is at the relevant point on the timeline + // between `a` and `b`. The interpolation can be extrapolated beyond 0.0 and + // 1.0, so negative values and values greater than 1.0 are valid (and can + // easily be generated by curves such as [Curves.elasticInOut]). + // + // Values for `t` are usually obtained from an [Animation], such as + // an [AnimationController]. + // + // See also: + // + // * [Decoration.lerp]. + static _CupertinoEdgeShadowDecoration? lerp( + _CupertinoEdgeShadowDecoration? a, + _CupertinoEdgeShadowDecoration? b, + double t, + ) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!._colors == null ? b : _CupertinoEdgeShadowDecoration._(b._colors!.map((Color color) => Color.lerp(null, color, t)!).toList()); + } + if (b == null) { + return a._colors == null ? a : _CupertinoEdgeShadowDecoration._(a._colors.map((Color color) => Color.lerp(null, color, 1.0 - t)!).toList()); + } + assert(b._colors != null || a._colors != null); + // If it ever becomes necessary, we could allow decorations with different + // length' here, similarly to how it is handled in [LinearGradient.lerp]. + assert(b._colors == null || a._colors == null || a._colors.length == b._colors.length); + return _CupertinoEdgeShadowDecoration._( + [ + for (int i = 0; i < b._colors!.length; i += 1) + Color.lerp(a._colors?[i], b._colors[i], t)!, + ], + ); + } + + @override + _CupertinoEdgeShadowDecoration lerpFrom(Decoration? a, double t) { + if (a is _CupertinoEdgeShadowDecoration) { + return _CupertinoEdgeShadowDecoration.lerp(a, this, t)!; + } + return _CupertinoEdgeShadowDecoration.lerp(null, this, t)!; + } + + @override + _CupertinoEdgeShadowDecoration lerpTo(Decoration? b, double t) { + if (b is _CupertinoEdgeShadowDecoration) { + return _CupertinoEdgeShadowDecoration.lerp(this, b, t)!; + } + return _CupertinoEdgeShadowDecoration.lerp(this, null, t)!; + } + + @override + _CupertinoEdgeShadowPainter createBoxPainter([ VoidCallback? onChanged ]) { + return _CupertinoEdgeShadowPainter(this, onChanged); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _CupertinoEdgeShadowDecoration + && other._colors == _colors; + } + + @override + int get hashCode => _colors.hashCode; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IterableProperty('colors', _colors)); + } +} + +/// A [BoxPainter] used to draw the page transition shadow using gradients. +class _CupertinoEdgeShadowPainter extends BoxPainter { + _CupertinoEdgeShadowPainter( + this._decoration, + super.onChanged, + ) : assert(_decoration._colors == null || _decoration._colors.length > 1); + + final _CupertinoEdgeShadowDecoration _decoration; + + @override + void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { + final List? colors = _decoration._colors; + if (colors == null) { + return; + } + + // The following code simulates drawing a [LinearGradient] configured as + // follows: + // + // LinearGradient( + // begin: AlignmentDirectional(0.90, 0.0), // Spans 5% of the page. + // colors: _decoration._colors, + // ) + // + // A performance evaluation on Feb 8, 2021 showed, that drawing the gradient + // manually as implemented below is more performant than relying on + // [LinearGradient.createShader] because compiling that shader takes a long + // time. On an iPhone XR, the implementation below reduced the worst frame + // time for a cupertino page transition of a newly installed app from ~95ms + // down to ~30ms, mainly because there's no longer a need to compile a + // shader for the LinearGradient. + // + // The implementation below divides the width of the shadow into multiple + // bands of equal width, one for each color interval defined by + // `_decoration._colors`. Band x is filled with a gradient going from + // `_decoration._colors[x]` to `_decoration._colors[x + 1]` by drawing a + // bunch of 1px wide rects. The rects change their color by lerping between + // the two colors that define the interval of the band. + + // Shadow spans 5% of the page. + final double shadowWidth = 0.05 * configuration.size!.width; + final double shadowHeight = configuration.size!.height; + final double bandWidth = shadowWidth / (colors.length - 1); + + final TextDirection? textDirection = configuration.textDirection; + assert(textDirection != null); + final double start; + final double shadowDirection; // -1 for ltr, 1 for rtl. + switch (textDirection!) { + case TextDirection.rtl: + start = offset.dx + configuration.size!.width; + shadowDirection = 1; + case TextDirection.ltr: + start = offset.dx; + shadowDirection = -1; + } + + int bandColorIndex = 0; + for (int dx = 0; dx < shadowWidth; dx += 1) { + if (dx ~/ bandWidth != bandColorIndex) { + bandColorIndex += 1; + } + final Paint paint = Paint() + ..color = Color.lerp(colors[bandColorIndex], colors[bandColorIndex + 1], (dx % bandWidth) / bandWidth)!; + final double x = start + shadowDirection * dx; + canvas.drawRect(Rect.fromLTWH(x - 1.0, offset.dy, 1.0, shadowHeight), paint); + } + } +} + +/// A route that shows a modal iOS-style popup that slides up from the +/// bottom of the screen. +/// +/// Such a popup is an alternative to a menu or a dialog and prevents the user +/// from interacting with the rest of the app. +/// +/// It is used internally by [showCupertinoModalPopup] or can be directly pushed +/// onto the [Navigator] stack to enable state restoration. See +/// [showCupertinoModalPopup] for a state restoration app example. +/// +/// The `barrierColor` argument determines the [Color] of the barrier underneath +/// the popup. When unspecified, the barrier color defaults to a light opacity +/// black scrim based on iOS's dialog screens. To correctly have iOS resolve +/// to the appropriate modal colors, pass in +/// `CupertinoDynamicColor.resolve(kCupertinoModalBarrierColor, context)`. +/// +/// The `barrierDismissible` argument determines whether clicking outside the +/// popup results in dismissal. It is `true` by default. +/// +/// The `semanticsDismissible` argument is used to determine whether the +/// semantics of the modal barrier are included in the semantics tree. +/// +/// The `routeSettings` argument is used to provide [RouteSettings] to the +/// created Route. +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// See also: +/// +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +/// * [CupertinoActionSheet], which is the widget usually returned by the +/// `builder` argument. +/// * +class CupertinoModalPopupRoute extends PopupRoute { + /// A route that shows a modal iOS-style popup that slides up from the + /// bottom of the screen. + CupertinoModalPopupRoute({ + required this.builder, + this.barrierLabel = 'Dismiss', + this.barrierColor = kCupertinoModalBarrierColor, + bool barrierDismissible = true, + bool semanticsDismissible = false, + super.filter, + super.settings, + this.anchorPoint, + }) : _barrierDismissible = barrierDismissible, + _semanticsDismissible = semanticsDismissible; + + /// A builder that builds the widget tree for the [CupertinoModalPopupRoute]. + /// + /// The [builder] argument typically builds a [CupertinoActionSheet] widget. + /// + /// Content below the widget is dimmed with a [ModalBarrier]. The widget built + /// by the [builder] does not share a context with the route it was originally + /// built from. Use a [StatefulBuilder] or a custom [StatefulWidget] if the + /// widget needs to update dynamically. + final WidgetBuilder builder; + + final bool _barrierDismissible; + + final bool _semanticsDismissible; + + @override + final String barrierLabel; + + @override + final Color? barrierColor; + + @override + bool get barrierDismissible => _barrierDismissible; + + @override + bool get semanticsDismissible => _semanticsDismissible; + + @override + Duration get transitionDuration => _kModalPopupTransitionDuration; + + Animation? _animation; + + late Tween _offsetTween; + + /// {@macro flutter.widgets.DisplayFeatureSubScreen.anchorPoint} + final Offset? anchorPoint; + + @override + Animation createAnimation() { + assert(_animation == null); + _animation = CurvedAnimation( + parent: super.createAnimation(), + + // These curves were initially measured from native iOS horizontal page + // route animations and seemed to be a good match here as well. + curve: Curves.linearToEaseOut, + reverseCurve: Curves.linearToEaseOut.flipped, + ); + _offsetTween = Tween( + begin: const Offset(0.0, 1.0), + end: Offset.zero, + ); + return _animation!; + } + + @override + Widget buildPage(BuildContext context, Animation animation, Animation secondaryAnimation) { + return CupertinoUserInterfaceLevel( + data: CupertinoUserInterfaceLevelData.elevated, + child: DisplayFeatureSubScreen( + anchorPoint: anchorPoint, + child: Builder(builder: builder), + ), + ); + } + + @override + Widget buildTransitions(BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { + return Align( + alignment: Alignment.bottomCenter, + child: FractionalTranslation( + translation: _offsetTween.evaluate(_animation!), + child: child, + ), + ); + } +} + +/// Shows a modal iOS-style popup that slides up from the bottom of the screen. +/// +/// Such a popup is an alternative to a menu or a dialog and prevents the user +/// from interacting with the rest of the app. +/// +/// The `context` argument is used to look up the [Navigator] for the popup. +/// It is only used when the method is called. Its corresponding widget can be +/// safely removed from the tree before the popup is closed. +/// +/// The `barrierColor` argument determines the [Color] of the barrier underneath +/// the popup. When unspecified, the barrier color defaults to a light opacity +/// black scrim based on iOS's dialog screens. +/// +/// The `barrierDismissible` argument determines whether clicking outside the +/// popup results in dismissal. It is `true` by default. +/// +/// The `useRootNavigator` argument is used to determine whether to push the +/// popup to the [Navigator] furthest from or nearest to the given `context`. It +/// is `true` by default. +/// +/// The `semanticsDismissible` argument is used to determine whether the +/// semantics of the modal barrier are included in the semantics tree. +/// +/// The `routeSettings` argument is used to provide [RouteSettings] to the +/// created Route. +/// +/// The `builder` argument typically builds a [CupertinoActionSheet] widget. +/// Content below the widget is dimmed with a [ModalBarrier]. The widget built +/// by the `builder` does not share a context with the location that +/// [showCupertinoModalPopup] is originally called from. Use a +/// [StatefulBuilder] or a custom [StatefulWidget] if the widget needs to +/// update dynamically. +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// Returns a `Future` that resolves to the value that was passed to +/// [Navigator.pop] when the popup was closed. +/// +/// ### State Restoration in Modals +/// +/// Using this method will not enable state restoration for the modal. In order +/// to enable state restoration for a modal, use [Navigator.restorablePush] +/// or [Navigator.restorablePushNamed] with [CupertinoModalPopupRoute]. +/// +/// For more information about state restoration, see [RestorationManager]. +/// +/// {@tool dartpad} +/// This sample demonstrates how to create a restorable Cupertino modal route. +/// This is accomplished by enabling state restoration by specifying +/// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to +/// push [CupertinoModalPopupRoute] when the [CupertinoButton] is tapped. +/// +/// {@macro flutter.widgets.RestorationManager} +/// +/// ** See code in examples/api/lib/cupertino/route/show_cupertino_modal_popup.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +/// * [CupertinoActionSheet], which is the widget usually returned by the +/// `builder` argument to [showCupertinoModalPopup]. +/// * +Future showCupertinoModalPopup({ + required BuildContext context, + required WidgetBuilder builder, + ImageFilter? filter, + Color barrierColor = kCupertinoModalBarrierColor, + bool barrierDismissible = true, + bool useRootNavigator = true, + bool semanticsDismissible = false, + RouteSettings? routeSettings, + Offset? anchorPoint, +}) { + return Navigator.of(context, rootNavigator: useRootNavigator).push( + CupertinoModalPopupRoute( + builder: builder, + filter: filter, + barrierColor: CupertinoDynamicColor.resolve(barrierColor, context), + barrierDismissible: barrierDismissible, + semanticsDismissible: semanticsDismissible, + settings: routeSettings, + anchorPoint: anchorPoint, + ), + ); +} + +// The curve and initial scale values were mostly eyeballed from iOS, however +// they reuse the same animation curve that was modeled after native page +// transitions. +final Animatable _dialogScaleTween = Tween(begin: 1.3, end: 1.0) + .chain(CurveTween(curve: Curves.linearToEaseOut)); + +Widget _buildCupertinoDialogTransitions(BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { + final CurvedAnimation fadeAnimation = CurvedAnimation( + parent: animation, + curve: Curves.easeInOut, + ); + if (animation.status == AnimationStatus.reverse) { + return FadeTransition( + opacity: fadeAnimation, + child: child, + ); + } + return FadeTransition( + opacity: fadeAnimation, + child: ScaleTransition( + scale: animation.drive(_dialogScaleTween), + child: child, + ), + ); +} + +/// Displays an iOS-style dialog above the current contents of the app, with +/// iOS-style entrance and exit animations, modal barrier color, and modal +/// barrier behavior (by default, the dialog is not dismissible with a tap on +/// the barrier). +/// +/// This function takes a `builder` which typically builds a [CupertinoAlertDialog] +/// widget. Content below the dialog is dimmed with a [ModalBarrier]. The widget +/// returned by the `builder` does not share a context with the location that +/// [showCupertinoDialog] is originally called from. Use a [StatefulBuilder] or +/// a custom [StatefulWidget] if the dialog needs to update dynamically. +/// +/// The `context` argument is used to look up the [Navigator] for the dialog. +/// It is only used when the method is called. Its corresponding widget can +/// be safely removed from the tree before the dialog is closed. +/// +/// The `useRootNavigator` argument is used to determine whether to push the +/// dialog to the [Navigator] furthest from or nearest to the given `context`. +/// By default, `useRootNavigator` is `true` and the dialog route created by +/// this method is pushed to the root navigator. +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// If the application has multiple [Navigator] objects, it may be necessary to +/// call `Navigator.of(context, rootNavigator: true).pop(result)` to close the +/// dialog rather than just `Navigator.pop(context, result)`. +/// +/// Returns a [Future] that resolves to the value (if any) that was passed to +/// [Navigator.pop] when the dialog was closed. +/// +/// ### State Restoration in Dialogs +/// +/// Using this method will not enable state restoration for the dialog. In order +/// to enable state restoration for a dialog, use [Navigator.restorablePush] +/// or [Navigator.restorablePushNamed] with [CupertinoDialogRoute]. +/// +/// For more information about state restoration, see [RestorationManager]. +/// +/// {@tool dartpad} +/// This sample demonstrates how to create a restorable Cupertino dialog. This is +/// accomplished by enabling state restoration by specifying +/// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to +/// push [CupertinoDialogRoute] when the [CupertinoButton] is tapped. +/// +/// {@macro flutter.widgets.RestorationManager} +/// +/// ** See code in examples/api/lib/cupertino/route/show_cupertino_dialog.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoAlertDialog], an iOS-style alert dialog. +/// * [showDialog], which displays a Material-style dialog. +/// * [showGeneralDialog], which allows for customization of the dialog popup. +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +/// * +Future showCupertinoDialog({ + required BuildContext context, + required WidgetBuilder builder, + String? barrierLabel, + bool useRootNavigator = true, + bool barrierDismissible = false, + RouteSettings? routeSettings, + Offset? anchorPoint, +}) { + + return Navigator.of(context, rootNavigator: useRootNavigator).push(CupertinoDialogRoute( + builder: builder, + context: context, + barrierDismissible: barrierDismissible, + barrierLabel: barrierLabel, + barrierColor: CupertinoDynamicColor.resolve(kCupertinoModalBarrierColor, context), + settings: routeSettings, + anchorPoint: anchorPoint, + )); +} + +/// A dialog route that shows an iOS-style dialog. +/// +/// It is used internally by [showCupertinoDialog] or can be directly pushed +/// onto the [Navigator] stack to enable state restoration. See +/// [showCupertinoDialog] for a state restoration app example. +/// +/// This function takes a `builder` which typically builds a [Dialog] widget. +/// Content below the dialog is dimmed with a [ModalBarrier]. The widget +/// returned by the `builder` does not share a context with the location that +/// `showDialog` is originally called from. Use a [StatefulBuilder] or a +/// custom [StatefulWidget] if the dialog needs to update dynamically. +/// +/// The `context` argument is used to look up +/// [CupertinoLocalizations.modalBarrierDismissLabel], which provides the +/// modal with a localized accessibility label that will be used for the +/// modal's barrier. However, a custom `barrierLabel` can be passed in as well. +/// +/// The `barrierDismissible` argument is used to indicate whether tapping on the +/// barrier will dismiss the dialog. It is `true` by default and cannot be `null`. +/// +/// The `barrierColor` argument is used to specify the color of the modal +/// barrier that darkens everything below the dialog. If `null`, then +/// [CupertinoDynamicColor.resolve] is used to compute the modal color. +/// +/// The `settings` argument define the settings for this route. See +/// [RouteSettings] for details. +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// See also: +/// +/// * [showCupertinoDialog], which is a way to display +/// an iOS-style dialog. +/// * [showGeneralDialog], which allows for customization of the dialog popup. +/// * [showDialog], which displays a Material dialog. +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +class CupertinoDialogRoute extends RawDialogRoute { + /// A dialog route that shows an iOS-style dialog. + CupertinoDialogRoute({ + required WidgetBuilder builder, + required BuildContext context, + super.barrierDismissible, + Color? barrierColor, + String? barrierLabel, + // This transition duration was eyeballed comparing with iOS + super.transitionDuration = const Duration(milliseconds: 250), + super.transitionBuilder = _buildCupertinoDialogTransitions, + super.settings, + super.anchorPoint, + }) : super( + pageBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation) { + return builder(context); + }, + barrierLabel: barrierLabel ?? CupertinoLocalizations.of(context).modalBarrierDismissLabel, + barrierColor: barrierColor ?? CupertinoDynamicColor.resolve(kCupertinoModalBarrierColor, context), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/scrollbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/scrollbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..b3423554319e9003494002cc2220657c1c74c305 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/scrollbar.dart @@ -0,0 +1,223 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; + +// All values eyeballed. +const double _kScrollbarMinLength = 36.0; +const double _kScrollbarMinOverscrollLength = 8.0; +const Duration _kScrollbarTimeToFade = Duration(milliseconds: 1200); +const Duration _kScrollbarFadeDuration = Duration(milliseconds: 250); +const Duration _kScrollbarResizeDuration = Duration(milliseconds: 100); + +// Extracted from iOS 13.1 beta using Debug View Hierarchy. +const Color _kScrollbarColor = CupertinoDynamicColor.withBrightness( + color: Color(0x59000000), + darkColor: Color(0x80FFFFFF), +); + +// This is the amount of space from the top of a vertical scrollbar to the +// top edge of the scrollable, measured when the vertical scrollbar overscrolls +// to the top. +// TODO(LongCatIsLooong): fix https://github.com/flutter/flutter/issues/32175 +const double _kScrollbarMainAxisMargin = 3.0; +const double _kScrollbarCrossAxisMargin = 3.0; + +/// An iOS style scrollbar. +/// +/// To add a scrollbar to a [ScrollView], wrap the scroll view widget in +/// a [CupertinoScrollbar] widget. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=DbkIQSvwnZc} +/// +/// {@macro flutter.widgets.Scrollbar} +/// +/// When dragging a [CupertinoScrollbar] thumb, the thickness and radius will +/// animate from [thickness] and [radius] to [thicknessWhileDragging] and +/// [radiusWhileDragging], respectively. +/// +/// {@tool dartpad} +/// This sample shows a [CupertinoScrollbar] that fades in and out of view as scrolling occurs. +/// The scrollbar will fade into view as the user scrolls, and fade out when scrolling stops. +/// The `thickness` of the scrollbar will animate from 6 pixels to the `thicknessWhileDragging` of 10 +/// when it is dragged by the user. The `radius` of the scrollbar thumb corners will animate from 34 +/// to the `radiusWhileDragging` of 0 when the scrollbar is being dragged by the user. +/// +/// ** See code in examples/api/lib/cupertino/scrollbar/cupertino_scrollbar.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// When [thumbVisibility] is true, the scrollbar thumb will remain visible without the +/// fade animation. This requires that a [ScrollController] is provided to controller, +/// or that the [PrimaryScrollController] is available. +/// +/// ** See code in examples/api/lib/cupertino/scrollbar/cupertino_scrollbar.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListView], which displays a linear, scrollable list of children. +/// * [GridView], which displays a 2 dimensional, scrollable array of children. +/// * [Scrollbar], a Material Design scrollbar. +/// * [RawScrollbar], a basic scrollbar that fades in and out, extended +/// by this class to add more animations and behaviors. +class CupertinoScrollbar extends RawScrollbar { + /// Creates an iOS style scrollbar that wraps the given [child]. + /// + /// The [child] should be a source of [ScrollNotification] notifications, + /// typically a [Scrollable] widget. + const CupertinoScrollbar({ + super.key, + required super.child, + super.controller, + bool? thumbVisibility, + double super.thickness = defaultThickness, + this.thicknessWhileDragging = defaultThicknessWhileDragging, + Radius super.radius = defaultRadius, + this.radiusWhileDragging = defaultRadiusWhileDragging, + ScrollNotificationPredicate? notificationPredicate, + super.scrollbarOrientation, + }) : assert(thickness < double.infinity), + assert(thicknessWhileDragging < double.infinity), + super( + thumbVisibility: thumbVisibility ?? false, + fadeDuration: _kScrollbarFadeDuration, + timeToFade: _kScrollbarTimeToFade, + pressDuration: const Duration(milliseconds: 100), + notificationPredicate: notificationPredicate ?? defaultScrollNotificationPredicate, + ); + + /// Default value for [thickness] if it's not specified in [CupertinoScrollbar]. + static const double defaultThickness = 3; + + /// Default value for [thicknessWhileDragging] if it's not specified in + /// [CupertinoScrollbar]. + static const double defaultThicknessWhileDragging = 8.0; + + /// Default value for [radius] if it's not specified in [CupertinoScrollbar]. + static const Radius defaultRadius = Radius.circular(1.5); + + /// Default value for [radiusWhileDragging] if it's not specified in + /// [CupertinoScrollbar]. + static const Radius defaultRadiusWhileDragging = Radius.circular(4.0); + + /// The thickness of the scrollbar when it's being dragged by the user. + /// + /// When the user starts dragging the scrollbar, the thickness will animate + /// from [thickness] to this value, then animate back when the user stops + /// dragging the scrollbar. + final double thicknessWhileDragging; + + /// The radius of the scrollbar edges when the scrollbar is being dragged by + /// the user. + /// + /// When the user starts dragging the scrollbar, the radius will animate + /// from [radius] to this value, then animate back when the user stops + /// dragging the scrollbar. + final Radius radiusWhileDragging; + + @override + RawScrollbarState createState() => _CupertinoScrollbarState(); +} + +class _CupertinoScrollbarState extends RawScrollbarState { + late AnimationController _thicknessAnimationController; + + double get _thickness { + return widget.thickness! + _thicknessAnimationController.value * (widget.thicknessWhileDragging - widget.thickness!); + } + + Radius get _radius { + return Radius.lerp(widget.radius, widget.radiusWhileDragging, _thicknessAnimationController.value)!; + } + + @override + void initState() { + super.initState(); + _thicknessAnimationController = AnimationController( + vsync: this, + duration: _kScrollbarResizeDuration, + ); + _thicknessAnimationController.addListener(() { + updateScrollbarPainter(); + }); + } + + @override + void updateScrollbarPainter() { + scrollbarPainter + ..color = CupertinoDynamicColor.resolve(_kScrollbarColor, context) + ..textDirection = Directionality.of(context) + ..thickness = _thickness + ..mainAxisMargin = _kScrollbarMainAxisMargin + ..crossAxisMargin = _kScrollbarCrossAxisMargin + ..radius = _radius + ..padding = MediaQuery.paddingOf(context) + ..minLength = _kScrollbarMinLength + ..minOverscrollLength = _kScrollbarMinOverscrollLength + ..scrollbarOrientation = widget.scrollbarOrientation; + } + + double _pressStartAxisPosition = 0.0; + + // Long press event callbacks handle the gesture where the user long presses + // on the scrollbar thumb and then drags the scrollbar without releasing. + + @override + void handleThumbPressStart(Offset localPosition) { + super.handleThumbPressStart(localPosition); + final Axis? direction = getScrollbarDirection(); + if (direction == null) { + return; + } + switch (direction) { + case Axis.vertical: + _pressStartAxisPosition = localPosition.dy; + case Axis.horizontal: + _pressStartAxisPosition = localPosition.dx; + } + } + + @override + void handleThumbPress() { + if (getScrollbarDirection() == null) { + return; + } + super.handleThumbPress(); + _thicknessAnimationController.forward().then( + (_) => HapticFeedback.mediumImpact(), + ); + } + + @override + void handleThumbPressEnd(Offset localPosition, Velocity velocity) { + final Axis? direction = getScrollbarDirection(); + if (direction == null) { + return; + } + _thicknessAnimationController.reverse(); + super.handleThumbPressEnd(localPosition, velocity); + switch (direction) { + case Axis.vertical: + if (velocity.pixelsPerSecond.dy.abs() < 10 && + (localPosition.dy - _pressStartAxisPosition).abs() > 0) { + HapticFeedback.mediumImpact(); + } + case Axis.horizontal: + if (velocity.pixelsPerSecond.dx.abs() < 10 && + (localPosition.dx - _pressStartAxisPosition).abs() > 0) { + HapticFeedback.mediumImpact(); + } + } + } + + @override + void dispose() { + _thicknessAnimationController.dispose(); + super.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/search_field.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/search_field.dart new file mode 100644 index 0000000000000000000000000000000000000000..2ef0bbd786da9f6b62b6ec8702f00b0cd18d41f4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/search_field.dart @@ -0,0 +1,471 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'button.dart'; +import 'colors.dart'; +import 'icons.dart'; +import 'localizations.dart'; +import 'text_field.dart'; + +export 'package:flutter/services.dart' show SmartDashesType, SmartQuotesType; + +/// A [CupertinoTextField] that mimics the look and behavior of UIKit's +/// `UISearchTextField`. +/// +/// This control defaults to showing the basic parts of a `UISearchTextField`, +/// like the 'Search' placeholder, prefix-ed Search icon, and suffix-ed +/// X-Mark icon. +/// +/// To control the text that is displayed in the text field, use the +/// [controller]. For example, to set the initial value of the text field, use +/// a [controller] that already contains some text such as: +/// +/// {@tool dartpad} +/// This examples shows how to provide initial text to a [CupertinoSearchTextField] +/// using the [controller] property. +/// +/// ** See code in examples/api/lib/cupertino/search_field/cupertino_search_field.0.dart ** +/// {@end-tool} +/// +/// It is recommended to pass a [ValueChanged] to both [onChanged] and +/// [onSubmitted] parameters in order to be notified once the value of the +/// field changes or is submitted by the keyboard: +/// +/// {@tool dartpad} +/// This examples shows how to be notified of field changes or submitted text from +/// a [CupertinoSearchTextField]. +/// +/// ** See code in examples/api/lib/cupertino/search_field/cupertino_search_field.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * +class CupertinoSearchTextField extends StatefulWidget { + /// Creates a [CupertinoTextField] that mimics the look and behavior of + /// UIKit's `UISearchTextField`. + /// + /// Similar to [CupertinoTextField], to provide a prefilled text entry, pass + /// in a [TextEditingController] with an initial value to the [controller] + /// parameter. + /// + /// The [onChanged] parameter takes a [ValueChanged] which is invoked + /// upon a change in the text field's value. + /// + /// The [onSubmitted] parameter takes a [ValueChanged] which is + /// invoked when the keyboard submits. + /// + /// To provide a hint placeholder text that appears when the text entry is + /// empty, pass a [String] to the [placeholder] parameter. This defaults to + /// 'Search'. + // TODO(DanielEdrisian): Localize the 'Search' placeholder. + /// + /// The [style] and [placeholderStyle] properties allow changing the style of + /// the text and placeholder of the text field. [placeholderStyle] defaults + /// to the gray [CupertinoColors.secondaryLabel] iOS color. + /// + /// To set the text field's background color and border radius, pass a + /// [BoxDecoration] to the [decoration] parameter. This defaults to the + /// default translucent tertiarySystemFill iOS color and 9 px corner radius. + // TODO(DanielEdrisian): Must make border radius continuous, see + // https://github.com/flutter/flutter/issues/13914. + /// + /// The [itemColor] and [itemSize] properties allow changing the icon color + /// and icon size of the search icon (prefix) and X-Mark (suffix). + /// They default to [CupertinoColors.secondaryLabel] and `20.0`. + /// + /// The [padding], [prefixInsets], and [suffixInsets] let you set the padding + /// insets for text, the search icon (prefix), and the X-Mark icon (suffix). + /// They default to values that replicate the `UISearchTextField` look. These + /// default fields were determined using the comparison tool in + /// https://github.com/flutter/platform_tests/. + /// + /// To customize the prefix icon, pass a [Widget] to [prefixIcon]. This + /// defaults to the search icon. + /// + /// To customize the suffix icon, pass an [Icon] to [suffixIcon]. This + /// defaults to the X-Mark. + /// + /// To dictate when the X-Mark (suffix) should be visible, a.k.a. only on when + /// editing, not editing, on always, or on never, pass a + /// [OverlayVisibilityMode] to [suffixMode]. This defaults to only on when + /// editing. + /// + /// To customize the X-Mark (suffix) action, pass a [VoidCallback] to + /// [onSuffixTap]. This defaults to clearing the text. + const CupertinoSearchTextField({ + super.key, + this.controller, + this.onChanged, + this.onSubmitted, + this.style, + this.placeholder, + this.placeholderStyle, + this.decoration, + this.backgroundColor, + this.borderRadius, + this.keyboardType = TextInputType.text, + this.padding = const EdgeInsetsDirectional.fromSTEB(5.5, 8, 5.5, 8), + this.itemColor = CupertinoColors.secondaryLabel, + this.itemSize = 20.0, + this.prefixInsets = const EdgeInsetsDirectional.fromSTEB(6, 0, 0, 3), + this.prefixIcon = const Icon(CupertinoIcons.search), + this.suffixInsets = const EdgeInsetsDirectional.fromSTEB(0, 0, 5, 2), + this.suffixIcon = const Icon(CupertinoIcons.xmark_circle_fill), + this.suffixMode = OverlayVisibilityMode.editing, + this.onSuffixTap, + this.restorationId, + this.focusNode, + this.smartQuotesType, + this.smartDashesType, + this.enableIMEPersonalizedLearning = true, + this.autofocus = false, + this.onTap, + this.autocorrect = true, + this.enabled, + }) : assert( + !((decoration != null) && (backgroundColor != null)), + 'Cannot provide both a background color and a decoration\n' + 'To provide both, use "decoration: BoxDecoration(color: ' + 'backgroundColor)"', + ), + assert( + !((decoration != null) && (borderRadius != null)), + 'Cannot provide both a border radius and a decoration\n' + 'To provide both, use "decoration: BoxDecoration(borderRadius: ' + 'borderRadius)"', + ); + + /// Controls the text being edited. + /// + /// Similar to [CupertinoTextField], to provide a prefilled text entry, pass + /// in a [TextEditingController] with an initial value to the [controller] + /// parameter. Defaults to creating its own [TextEditingController]. + final TextEditingController? controller; + + /// Invoked upon user input. + final ValueChanged? onChanged; + + /// Invoked upon keyboard submission. + final ValueChanged? onSubmitted; + + /// Allows changing the style of the text. + /// + /// Defaults to the gray [CupertinoColors.secondaryLabel] iOS color. + final TextStyle? style; + + /// A hint placeholder text that appears when the text entry is empty. + /// + /// Defaults to 'Search' localized in each supported language. + final String? placeholder; + + /// Sets the style of the placeholder of the text field. + /// + /// Defaults to the gray [CupertinoColors.secondaryLabel] iOS color. + final TextStyle? placeholderStyle; + + /// Sets the decoration for the text field. + /// + /// This property is automatically set using the [backgroundColor] and + /// [borderRadius] properties, which both have default values. Therefore, + /// [decoration] has a default value upon building the widget. It is designed + /// to mimic the look of a `UISearchTextField`. + final BoxDecoration? decoration; + + /// Set the [decoration] property's background color. + /// + /// Can't be set along with the [decoration]. Defaults to the translucent + /// [CupertinoColors.tertiarySystemFill] iOS color. + final Color? backgroundColor; + + /// Sets the [decoration] property's border radius. + /// + /// Can't be set along with the [decoration]. Defaults to 9 px circular + /// corner radius. + // TODO(DanielEdrisian): Must make border radius continuous, see + // https://github.com/flutter/flutter/issues/13914. + final BorderRadius? borderRadius; + + /// The keyboard type for this search field. + /// + /// Defaults to [TextInputType.text]. + final TextInputType? keyboardType; + + /// Sets the padding insets for the text and placeholder. + /// + /// Defaults to padding that replicates the `UISearchTextField` look. The + /// inset values were determined using the comparison tool in + /// https://github.com/flutter/platform_tests/. + final EdgeInsetsGeometry padding; + + /// Sets the color for the suffix and prefix icons. + /// + /// Defaults to [CupertinoColors.secondaryLabel]. + final Color itemColor; + + /// Sets the base icon size for the suffix and prefix icons. + /// + /// The size of the icon is scaled using the accessibility font scale + /// settings. Defaults to `20.0`. + final double itemSize; + + /// Sets the padding insets for the suffix. + /// + /// Defaults to padding that replicates the `UISearchTextField` suffix look. + /// The inset values were determined using the comparison tool in + /// https://github.com/flutter/platform_tests/. + final EdgeInsetsGeometry prefixInsets; + + /// Sets a prefix widget. + /// + /// Defaults to an [Icon] widget with the [CupertinoIcons.search] icon. + final Widget prefixIcon; + + /// Sets the padding insets for the prefix. + /// + /// Defaults to padding that replicates the `UISearchTextField` prefix look. + /// The inset values were determined using the comparison tool in + /// https://github.com/flutter/platform_tests/. + final EdgeInsetsGeometry suffixInsets; + + /// Sets the suffix widget's icon. + /// + /// Defaults to the X-Mark [CupertinoIcons.xmark_circle_fill]. "To change the + /// functionality of the suffix icon, provide a custom onSuffixTap callback + /// and specify an intuitive suffixIcon. + final Icon suffixIcon; + + /// Dictates when the X-Mark (suffix) should be visible. + /// + /// Defaults to only on when editing. + final OverlayVisibilityMode suffixMode; + + /// Sets the X-Mark (suffix) action. + /// + /// Defaults to clearing the text. The suffix action is customizable + /// so that users can override it with other functionality, that isn't + /// necessarily clearing text. + final VoidCallback? onSuffixTap; + + /// {@macro flutter.material.textfield.restorationId} + final String? restorationId; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.editableText.autofocus} + final bool autofocus; + + /// {@macro flutter.material.textfield.onTap} + final VoidCallback? onTap; + + /// {@macro flutter.widgets.editableText.autocorrect} + final bool autocorrect; + + /// Whether to allow the platform to automatically format quotes. + /// + /// This flag only affects iOS, where it is equivalent to [`UITextSmartQuotesType`](https://developer.apple.com/documentation/uikit/uitextsmartquotestype?language=objc). + /// + /// When set to [SmartQuotesType.enabled], it passes + /// [`UITextSmartQuotesTypeYes`](https://developer.apple.com/documentation/uikit/uitextsmartquotestype/uitextsmartquotestypeyes?language=objc), + /// and when set to [SmartQuotesType.disabled], it passes + /// [`UITextSmartQuotesTypeNo`](https://developer.apple.com/documentation/uikit/uitextsmartquotestype/uitextsmartquotestypeno?language=objc). + /// + /// If set to null, [SmartQuotesType.enabled] will be used. + /// + /// As an example of what this does, a standard vertical double quote + /// character will be automatically replaced by a left or right double quote + /// depending on its position in a word. + /// + /// Defaults to null. + /// + /// See also: + /// + /// * [smartDashesType] + /// * + final SmartQuotesType? smartQuotesType; + + /// Whether to allow the platform to automatically format dashes. + /// + /// This flag only affects iOS versions 11 and above, where it is equivalent to [`UITextSmartDashesType`](https://developer.apple.com/documentation/uikit/uitextsmartdashestype?language=objc). + /// + /// When set to [SmartDashesType.enabled], it passes + /// [`UITextSmartDashesTypeYes`](https://developer.apple.com/documentation/uikit/uitextsmartdashestype/uitextsmartdashestypeyes?language=objc), + /// and when set to [SmartDashesType.disabled], it passes + /// [`UITextSmartDashesTypeNo`](https://developer.apple.com/documentation/uikit/uitextsmartdashestype/uitextsmartdashestypeno?language=objc). + /// + /// If set to null, [SmartDashesType.enabled] will be used. + /// + /// As an example of what this does, two consecutive hyphen characters will be + /// automatically replaced with one en dash, and three consecutive hyphens + /// will become one em dash. + /// + /// Defaults to null. + /// + /// See also: + /// + /// * [smartQuotesType] + /// * + final SmartDashesType? smartDashesType; + + /// {@macro flutter.services.TextInputConfiguration.enableIMEPersonalizedLearning} + final bool enableIMEPersonalizedLearning; + + /// Disables the text field when false. + /// + /// Text fields in disabled states have a light grey background and don't + /// respond to touch events including the [prefixIcon] and [suffixIcon] button. + final bool? enabled; + + @override + State createState() => _CupertinoSearchTextFieldState(); +} + +class _CupertinoSearchTextFieldState extends State + with RestorationMixin { + /// Default value for the border radius. Radius value was determined using the + /// comparison tool in https://github.com/flutter/platform_tests/. + final BorderRadius _kDefaultBorderRadius = + const BorderRadius.all(Radius.circular(9.0)); + + RestorableTextEditingController? _controller; + + TextEditingController get _effectiveController => + widget.controller ?? _controller!.value; + + @override + void initState() { + super.initState(); + if (widget.controller == null) { + _createLocalController(); + } + } + + @override + void didUpdateWidget(CupertinoSearchTextField oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.controller == null && oldWidget.controller != null) { + _createLocalController(oldWidget.controller!.value); + } else if (widget.controller != null && oldWidget.controller == null) { + unregisterFromRestoration(_controller!); + _controller!.dispose(); + _controller = null; + } + } + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + if (_controller != null) { + _registerController(); + } + } + + @override + void dispose() { + super.dispose(); + if (widget.controller == null) { + _controller?.dispose(); + } + } + + void _registerController() { + assert(_controller != null); + registerForRestoration(_controller!, 'controller'); + } + + void _createLocalController([TextEditingValue? value]) { + assert(_controller == null); + _controller = value == null + ? RestorableTextEditingController() + : RestorableTextEditingController.fromValue(value); + if (!restorePending) { + _registerController(); + } + } + + @override + String? get restorationId => widget.restorationId; + + void _defaultOnSuffixTap() { + final bool textChanged = _effectiveController.text.isNotEmpty; + _effectiveController.clear(); + if (widget.onChanged != null && textChanged) { + widget.onChanged!(_effectiveController.text); + } + } + + @override + Widget build(BuildContext context) { + final String placeholder = widget.placeholder ?? + CupertinoLocalizations.of(context).searchTextFieldPlaceholderLabel; + + final TextStyle placeholderStyle = widget.placeholderStyle ?? + const TextStyle(color: CupertinoColors.systemGrey); + + // The icon size will be scaled by a factor of the accessibility text scale, + // to follow the behavior of `UISearchTextField`. + final double scaledIconSize = MediaQuery.textScalerOf(context).textScaleFactor * widget.itemSize; + + // If decoration was not provided, create a decoration with the provided + // background color and border radius. + final BoxDecoration decoration = widget.decoration ?? + BoxDecoration( + color: widget.backgroundColor ?? CupertinoColors.tertiarySystemFill, + borderRadius: widget.borderRadius ?? _kDefaultBorderRadius, + ); + + final IconThemeData iconThemeData = IconThemeData( + color: CupertinoDynamicColor.resolve(widget.itemColor, context), + size: scaledIconSize, + ); + + final Widget prefix = Padding( + padding: widget.prefixInsets, + child: IconTheme( + data: iconThemeData, + child: widget.prefixIcon, + ), + ); + + final Widget suffix = Padding( + padding: widget.suffixInsets, + child: CupertinoButton( + onPressed: widget.onSuffixTap ?? _defaultOnSuffixTap, + minSize: 0, + padding: EdgeInsets.zero, + child: IconTheme( + data: iconThemeData, + child: widget.suffixIcon, + ), + ), + ); + + return CupertinoTextField( + controller: _effectiveController, + decoration: decoration, + style: widget.style, + prefix: prefix, + suffix: suffix, + keyboardType: widget.keyboardType, + onTap: widget.onTap, + enabled: widget.enabled ?? true, + suffixMode: widget.suffixMode, + placeholder: placeholder, + placeholderStyle: placeholderStyle, + padding: widget.padding, + onChanged: widget.onChanged, + onSubmitted: widget.onSubmitted, + focusNode: widget.focusNode, + autofocus: widget.autofocus, + autocorrect: widget.autocorrect, + smartQuotesType: widget.smartQuotesType, + smartDashesType: widget.smartDashesType, + enableIMEPersonalizedLearning: widget.enableIMEPersonalizedLearning, + textInputAction: TextInputAction.search, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/segmented_control.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/segmented_control.dart new file mode 100644 index 0000000000000000000000000000000000000000..dcb0cde6604a5384bf0345c570098c4eabe1bcfb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/segmented_control.dart @@ -0,0 +1,720 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +// Minimum padding from edges of the segmented control to edges of +// encompassing widget. +const EdgeInsetsGeometry _kHorizontalItemPadding = EdgeInsets.symmetric(horizontal: 16.0); + +// Minimum height of the segmented control. +const double _kMinSegmentedControlHeight = 28.0; + +// The duration of the fade animation used to transition when a new widget +// is selected. +const Duration _kFadeDuration = Duration(milliseconds: 165); + +/// An iOS-style segmented control. +/// +/// Displays the widgets provided in the [Map] of [children] in a +/// horizontal list. Used to select between a number of mutually exclusive +/// options. When one option in the segmented control is selected, the other +/// options in the segmented control cease to be selected. +/// +/// A segmented control can feature any [Widget] as one of the values in its +/// [Map] of [children]. The type T is the type of the keys used +/// to identify each widget and determine which widget is selected. As +/// required by the [Map] class, keys must be of consistent types +/// and must be comparable. The ordering of the keys will determine the order +/// of the widgets in the segmented control. +/// +/// When the state of the segmented control changes, the widget calls the +/// [onValueChanged] callback. The map key associated with the newly selected +/// widget is returned in the [onValueChanged] callback. Typically, widgets +/// that use a segmented control will listen for the [onValueChanged] callback +/// and rebuild the segmented control with a new [groupValue] to update which +/// option is currently selected. +/// +/// The [children] will be displayed in the order of the keys in the [Map]. +/// The height of the segmented control is determined by the height of the +/// tallest widget provided as a value in the [Map] of [children]. +/// The width of each child in the segmented control will be equal to the width +/// of widest child, unless the combined width of the children is wider than +/// the available horizontal space. In this case, the available horizontal space +/// is divided by the number of provided [children] to determine the width of +/// each widget. The selection area for each of the widgets in the [Map] of +/// [children] will then be expanded to fill the calculated space, so each +/// widget will appear to have the same dimensions. +/// +/// A segmented control may optionally be created with custom colors. The +/// [unselectedColor], [selectedColor], [borderColor], and [pressedColor] +/// arguments can be used to override the segmented control's colors from +/// [CupertinoTheme] defaults. +/// +/// {@tool dartpad} +/// This example shows a [CupertinoSegmentedControl] with an enum type. +/// +/// The callback provided to [onValueChanged] should update the state of +/// the parent [StatefulWidget] using the [State.setState] method, so that +/// the parent gets rebuilt; for example: +/// +/// ** See code in examples/api/lib/cupertino/segmented_control/cupertino_segmented_control.0.dart ** +/// {@end-tool} +/// See also: +/// +/// * [CupertinoSegmentedControl], a segmented control widget in the style used +/// up until iOS 13. +/// * +class CupertinoSegmentedControl extends StatefulWidget { + /// Creates an iOS-style segmented control bar. + /// + /// The [children] argument must be an ordered [Map] such as a + /// [LinkedHashMap]. Further, the length of the [children] list must be + /// greater than one. + /// + /// Each widget value in the map of [children] must have an associated key + /// that uniquely identifies this widget. This key is what will be returned + /// in the [onValueChanged] callback when a new value from the [children] map + /// is selected. + /// + /// The [groupValue] is the currently selected value for the segmented control. + /// If no [groupValue] is provided, or the [groupValue] is null, no widget will + /// appear as selected. The [groupValue] must be either null or one of the keys + /// in the [children] map. + CupertinoSegmentedControl({ + super.key, + required this.children, + required this.onValueChanged, + this.groupValue, + this.unselectedColor, + this.selectedColor, + this.borderColor, + this.pressedColor, + this.padding, + }) : assert(children.length >= 2), + assert( + groupValue == null || children.keys.any((T child) => child == groupValue), + 'The groupValue must be either null or one of the keys in the children map.', + ); + + /// The identifying keys and corresponding widget values in the + /// segmented control. + /// + /// The map must have more than one entry. + /// This attribute must be an ordered [Map] such as a [LinkedHashMap]. + final Map children; + + /// The identifier of the widget that is currently selected. + /// + /// This must be one of the keys in the [Map] of [children]. + /// If this attribute is null, no widget will be initially selected. + final T? groupValue; + + /// The callback that is called when a new option is tapped. + /// + /// The segmented control passes the newly selected widget's associated key + /// to the callback but does not actually change state until the parent + /// widget rebuilds the segmented control with the new [groupValue]. + final ValueChanged onValueChanged; + + /// The color used to fill the backgrounds of unselected widgets and as the + /// text color of the selected widget. + /// + /// Defaults to [CupertinoTheme]'s `primaryContrastingColor` if null. + final Color? unselectedColor; + + /// The color used to fill the background of the selected widget and as the text + /// color of unselected widgets. + /// + /// Defaults to [CupertinoTheme]'s `primaryColor` if null. + final Color? selectedColor; + + /// The color used as the border around each widget. + /// + /// Defaults to [CupertinoTheme]'s `primaryColor` if null. + final Color? borderColor; + + /// The color used to fill the background of the widget the user is + /// temporarily interacting with through a long press or drag. + /// + /// Defaults to the selectedColor at 20% opacity if null. + final Color? pressedColor; + + /// The CupertinoSegmentedControl will be placed inside this padding. + /// + /// Defaults to EdgeInsets.symmetric(horizontal: 16.0) + final EdgeInsetsGeometry? padding; + + @override + State> createState() => _SegmentedControlState(); +} + +class _SegmentedControlState extends State> + with TickerProviderStateMixin> { + T? _pressedKey; + + final List _selectionControllers = []; + final List _childTweens = []; + + late ColorTween _forwardBackgroundColorTween; + late ColorTween _reverseBackgroundColorTween; + late ColorTween _textColorTween; + + Color? _selectedColor; + Color? _unselectedColor; + Color? _borderColor; + Color? _pressedColor; + + AnimationController createAnimationController() { + return AnimationController( + duration: _kFadeDuration, + vsync: this, + )..addListener(() { + setState(() { + // State of background/text colors has changed + }); + }); + } + + bool _updateColors() { + assert(mounted, 'This should only be called after didUpdateDependencies'); + bool changed = false; + final Color selectedColor = widget.selectedColor ?? CupertinoTheme.of(context).primaryColor; + if (_selectedColor != selectedColor) { + changed = true; + _selectedColor = selectedColor; + } + final Color unselectedColor = widget.unselectedColor ?? CupertinoTheme.of(context).primaryContrastingColor; + if (_unselectedColor != unselectedColor) { + changed = true; + _unselectedColor = unselectedColor; + } + final Color borderColor = widget.borderColor ?? CupertinoTheme.of(context).primaryColor; + if (_borderColor != borderColor) { + changed = true; + _borderColor = borderColor; + } + final Color pressedColor = widget.pressedColor ?? CupertinoTheme.of(context).primaryColor.withOpacity(0.2); + if (_pressedColor != pressedColor) { + changed = true; + _pressedColor = pressedColor; + } + + _forwardBackgroundColorTween = ColorTween( + begin: _pressedColor, + end: _selectedColor, + ); + _reverseBackgroundColorTween = ColorTween( + begin: _unselectedColor, + end: _selectedColor, + ); + _textColorTween = ColorTween( + begin: _selectedColor, + end: _unselectedColor, + ); + return changed; + } + + void _updateAnimationControllers() { + assert(mounted, 'This should only be called after didUpdateDependencies'); + for (final AnimationController controller in _selectionControllers) { + controller.dispose(); + } + _selectionControllers.clear(); + _childTweens.clear(); + + for (final T key in widget.children.keys) { + final AnimationController animationController = createAnimationController(); + if (widget.groupValue == key) { + _childTweens.add(_reverseBackgroundColorTween); + animationController.value = 1.0; + } else { + _childTweens.add(_forwardBackgroundColorTween); + } + _selectionControllers.add(animationController); + } + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + if (_updateColors()) { + _updateAnimationControllers(); + } + } + + @override + void didUpdateWidget(CupertinoSegmentedControl oldWidget) { + super.didUpdateWidget(oldWidget); + + if (_updateColors() || oldWidget.children.length != widget.children.length) { + _updateAnimationControllers(); + } + + if (oldWidget.groupValue != widget.groupValue) { + int index = 0; + for (final T key in widget.children.keys) { + if (widget.groupValue == key) { + _childTweens[index] = _forwardBackgroundColorTween; + _selectionControllers[index].forward(); + } else { + _childTweens[index] = _reverseBackgroundColorTween; + _selectionControllers[index].reverse(); + } + index += 1; + } + } + } + + @override + void dispose() { + for (final AnimationController animationController in _selectionControllers) { + animationController.dispose(); + } + super.dispose(); + } + + + void _onTapDown(T currentKey) { + if (_pressedKey == null && currentKey != widget.groupValue) { + setState(() { + _pressedKey = currentKey; + }); + } + } + + void _onTapCancel() { + setState(() { + _pressedKey = null; + }); + } + + void _onTap(T currentKey) { + if (currentKey != _pressedKey) { + return; + } + if (currentKey != widget.groupValue) { + widget.onValueChanged(currentKey); + } + _pressedKey = null; + } + + Color? getTextColor(int index, T currentKey) { + if (_selectionControllers[index].isAnimating) { + return _textColorTween.evaluate(_selectionControllers[index]); + } + if (widget.groupValue == currentKey) { + return _unselectedColor; + } + return _selectedColor; + } + + Color? getBackgroundColor(int index, T currentKey) { + if (_selectionControllers[index].isAnimating) { + return _childTweens[index].evaluate(_selectionControllers[index]); + } + if (widget.groupValue == currentKey) { + return _selectedColor; + } + if (_pressedKey == currentKey) { + return _pressedColor; + } + return _unselectedColor; + } + + @override + Widget build(BuildContext context) { + final List gestureChildren = []; + final List backgroundColors = []; + int index = 0; + int? selectedIndex; + int? pressedIndex; + for (final T currentKey in widget.children.keys) { + selectedIndex = (widget.groupValue == currentKey) ? index : selectedIndex; + pressedIndex = (_pressedKey == currentKey) ? index : pressedIndex; + + final TextStyle textStyle = DefaultTextStyle.of(context).style.copyWith( + color: getTextColor(index, currentKey), + ); + final IconThemeData iconTheme = IconThemeData( + color: getTextColor(index, currentKey), + ); + + Widget child = Center( + child: widget.children[currentKey], + ); + + child = MouseRegion( + cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTapDown: (TapDownDetails event) { + _onTapDown(currentKey); + }, + onTapCancel: _onTapCancel, + onTap: () { + _onTap(currentKey); + }, + child: IconTheme( + data: iconTheme, + child: DefaultTextStyle( + style: textStyle, + child: Semantics( + button: true, + inMutuallyExclusiveGroup: true, + selected: widget.groupValue == currentKey, + child: child, + ), + ), + ), + ), + ); + + backgroundColors.add(getBackgroundColor(index, currentKey)!); + gestureChildren.add(child); + index += 1; + } + + final Widget box = _SegmentedControlRenderWidget( + selectedIndex: selectedIndex, + pressedIndex: pressedIndex, + backgroundColors: backgroundColors, + borderColor: _borderColor!, + children: gestureChildren, + ); + + return Padding( + padding: widget.padding ?? _kHorizontalItemPadding, + child: UnconstrainedBox( + constrainedAxis: Axis.horizontal, + child: box, + ), + ); + } +} + +class _SegmentedControlRenderWidget extends MultiChildRenderObjectWidget { + const _SegmentedControlRenderWidget({ + super.key, + super.children, + required this.selectedIndex, + required this.pressedIndex, + required this.backgroundColors, + required this.borderColor, + }); + + final int? selectedIndex; + final int? pressedIndex; + final List backgroundColors; + final Color borderColor; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderSegmentedControl( + textDirection: Directionality.of(context), + selectedIndex: selectedIndex, + pressedIndex: pressedIndex, + backgroundColors: backgroundColors, + borderColor: borderColor, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderSegmentedControl renderObject) { + renderObject + ..textDirection = Directionality.of(context) + ..selectedIndex = selectedIndex + ..pressedIndex = pressedIndex + ..backgroundColors = backgroundColors + ..borderColor = borderColor; + } +} + +class _SegmentedControlContainerBoxParentData extends ContainerBoxParentData { + RRect? surroundingRect; +} + +typedef _NextChild = RenderBox? Function(RenderBox child); + +class _RenderSegmentedControl extends RenderBox + with ContainerRenderObjectMixin>, + RenderBoxContainerDefaultsMixin> { + _RenderSegmentedControl({ + required int? selectedIndex, + required int? pressedIndex, + required TextDirection textDirection, + required List backgroundColors, + required Color borderColor, + }) : _textDirection = textDirection, + _selectedIndex = selectedIndex, + _pressedIndex = pressedIndex, + _backgroundColors = backgroundColors, + _borderColor = borderColor; + + int? get selectedIndex => _selectedIndex; + int? _selectedIndex; + set selectedIndex(int? value) { + if (_selectedIndex == value) { + return; + } + _selectedIndex = value; + markNeedsPaint(); + } + + int? get pressedIndex => _pressedIndex; + int? _pressedIndex; + set pressedIndex(int? value) { + if (_pressedIndex == value) { + return; + } + _pressedIndex = value; + markNeedsPaint(); + } + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsLayout(); + } + + List get backgroundColors => _backgroundColors; + List _backgroundColors; + set backgroundColors(List value) { + if (_backgroundColors == value) { + return; + } + _backgroundColors = value; + markNeedsPaint(); + } + + Color get borderColor => _borderColor; + Color _borderColor; + set borderColor(Color value) { + if (_borderColor == value) { + return; + } + _borderColor = value; + markNeedsPaint(); + } + + @override + double computeMinIntrinsicWidth(double height) { + RenderBox? child = firstChild; + double minWidth = 0.0; + while (child != null) { + final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; + final double childWidth = child.getMinIntrinsicWidth(height); + minWidth = math.max(minWidth, childWidth); + child = childParentData.nextSibling; + } + return minWidth * childCount; + } + + @override + double computeMaxIntrinsicWidth(double height) { + RenderBox? child = firstChild; + double maxWidth = 0.0; + while (child != null) { + final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; + final double childWidth = child.getMaxIntrinsicWidth(height); + maxWidth = math.max(maxWidth, childWidth); + child = childParentData.nextSibling; + } + return maxWidth * childCount; + } + + @override + double computeMinIntrinsicHeight(double width) { + RenderBox? child = firstChild; + double minHeight = 0.0; + while (child != null) { + final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; + final double childHeight = child.getMinIntrinsicHeight(width); + minHeight = math.max(minHeight, childHeight); + child = childParentData.nextSibling; + } + return minHeight; + } + + @override + double computeMaxIntrinsicHeight(double width) { + RenderBox? child = firstChild; + double maxHeight = 0.0; + while (child != null) { + final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; + final double childHeight = child.getMaxIntrinsicHeight(width); + maxHeight = math.max(maxHeight, childHeight); + child = childParentData.nextSibling; + } + return maxHeight; + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + return defaultComputeDistanceToHighestActualBaseline(baseline); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! _SegmentedControlContainerBoxParentData) { + child.parentData = _SegmentedControlContainerBoxParentData(); + } + } + + void _layoutRects(_NextChild nextChild, RenderBox? leftChild, RenderBox? rightChild) { + RenderBox? child = leftChild; + double start = 0.0; + while (child != null) { + final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; + final Offset childOffset = Offset(start, 0.0); + childParentData.offset = childOffset; + final Rect childRect = Rect.fromLTWH(start, 0.0, child.size.width, child.size.height); + final RRect rChildRect; + if (child == leftChild) { + rChildRect = RRect.fromRectAndCorners( + childRect, + topLeft: const Radius.circular(3.0), + bottomLeft: const Radius.circular(3.0), + ); + } else if (child == rightChild) { + rChildRect = RRect.fromRectAndCorners( + childRect, + topRight: const Radius.circular(3.0), + bottomRight: const Radius.circular(3.0), + ); + } else { + rChildRect = RRect.fromRectAndCorners(childRect); + } + childParentData.surroundingRect = rChildRect; + start += child.size.width; + child = nextChild(child); + } + } + + Size _calculateChildSize(BoxConstraints constraints) { + double maxHeight = _kMinSegmentedControlHeight; + double childWidth = constraints.minWidth / childCount; + RenderBox? child = firstChild; + while (child != null) { + childWidth = math.max(childWidth, child.getMaxIntrinsicWidth(double.infinity)); + child = childAfter(child); + } + childWidth = math.min(childWidth, constraints.maxWidth / childCount); + child = firstChild; + while (child != null) { + final double boxHeight = child.getMaxIntrinsicHeight(childWidth); + maxHeight = math.max(maxHeight, boxHeight); + child = childAfter(child); + } + return Size(childWidth, maxHeight); + } + + Size _computeOverallSizeFromChildSize(Size childSize) { + return constraints.constrain(Size(childSize.width * childCount, childSize.height)); + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + final Size childSize = _calculateChildSize(constraints); + return _computeOverallSizeFromChildSize(childSize); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + final Size childSize = _calculateChildSize(constraints); + + final BoxConstraints childConstraints = BoxConstraints.tightFor( + width: childSize.width, + height: childSize.height, + ); + + RenderBox? child = firstChild; + while (child != null) { + child.layout(childConstraints, parentUsesSize: true); + child = childAfter(child); + } + + switch (textDirection) { + case TextDirection.rtl: + _layoutRects( + childBefore, + lastChild, + firstChild, + ); + case TextDirection.ltr: + _layoutRects( + childAfter, + firstChild, + lastChild, + ); + } + + size = _computeOverallSizeFromChildSize(childSize); + } + + @override + void paint(PaintingContext context, Offset offset) { + RenderBox? child = firstChild; + int index = 0; + while (child != null) { + _paintChild(context, offset, child, index); + child = childAfter(child); + index += 1; + } + } + + void _paintChild(PaintingContext context, Offset offset, RenderBox child, int childIndex) { + + final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; + + context.canvas.drawRRect( + childParentData.surroundingRect!.shift(offset), + Paint() + ..color = backgroundColors[childIndex] + ..style = PaintingStyle.fill, + ); + context.canvas.drawRRect( + childParentData.surroundingRect!.shift(offset), + Paint() + ..color = borderColor + ..strokeWidth = 1.0 + ..style = PaintingStyle.stroke, + ); + + context.paintChild(child, childParentData.offset + offset); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + RenderBox? child = lastChild; + while (child != null) { + final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; + if (childParentData.surroundingRect!.contains(position)) { + return result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset localOffset) { + assert(localOffset == position - childParentData.offset); + return child!.hitTest(result, position: localOffset); + }, + ); + } + child = childParentData.previousSibling; + } + return false; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/slider.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/slider.dart new file mode 100644 index 0000000000000000000000000000000000000000..921f74423a0f4f9ebab335900cf4d9d140c77d6c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/slider.dart @@ -0,0 +1,607 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'theme.dart'; +import 'thumb_painter.dart'; + +// Examples can assume: +// int _cupertinoSliderValue = 1; +// void setState(VoidCallback fn) { } + +/// An iOS-style slider. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ufb4gIPDmEs} +/// +/// Used to select from a range of values. +/// +/// A slider can be used to select from either a continuous or a discrete set of +/// values. The default is use a continuous range of values from [min] to [max]. +/// To use discrete values, use a non-null value for [divisions], which +/// indicates the number of discrete intervals. For example, if [min] is 0.0 and +/// [max] is 50.0 and [divisions] is 5, then the slider can take on the values +/// discrete values 0.0, 10.0, 20.0, 30.0, 40.0, and 50.0. +/// +/// The slider itself does not maintain any state. Instead, when the state of +/// the slider changes, the widget calls the [onChanged] callback. Most widgets +/// that use a slider will listen for the [onChanged] callback and rebuild the +/// slider with a new [value] to update the visual appearance of the slider. +/// +/// {@tool dartpad} +/// This example shows how to show the current slider value as it changes. +/// +/// ** See code in examples/api/lib/cupertino/slider/cupertino_slider.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * +class CupertinoSlider extends StatefulWidget { + /// Creates an iOS-style slider. + /// + /// The slider itself does not maintain any state. Instead, when the state of + /// the slider changes, the widget calls the [onChanged] callback. Most widgets + /// that use a slider will listen for the [onChanged] callback and rebuild the + /// slider with a new [value] to update the visual appearance of the slider. + /// + /// * [value] determines currently selected value for this slider. + /// * [onChanged] is called when the user selects a new value for the slider. + /// * [onChangeStart] is called when the user starts to select a new value for + /// the slider. + /// * [onChangeEnd] is called when the user is done selecting a new value for + /// the slider. + const CupertinoSlider({ + super.key, + required this.value, + required this.onChanged, + this.onChangeStart, + this.onChangeEnd, + this.min = 0.0, + this.max = 1.0, + this.divisions, + this.activeColor, + this.thumbColor = CupertinoColors.white, + }) : assert(value >= min && value <= max), + assert(divisions == null || divisions > 0); + + /// The currently selected value for this slider. + /// + /// The slider's thumb is drawn at a position that corresponds to this value. + final double value; + + /// Called when the user selects a new value for the slider. + /// + /// The slider passes the new value to the callback but does not actually + /// change state until the parent widget rebuilds the slider with the new + /// value. + /// + /// If null, the slider will be displayed as disabled. + /// + /// The callback provided to onChanged should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// CupertinoSlider( + /// value: _cupertinoSliderValue.toDouble(), + /// min: 1.0, + /// max: 10.0, + /// divisions: 10, + /// onChanged: (double newValue) { + /// setState(() { + /// _cupertinoSliderValue = newValue.round(); + /// }); + /// }, + /// ) + /// ``` + /// + /// See also: + /// + /// * [onChangeStart] for a callback that is called when the user starts + /// changing the value. + /// * [onChangeEnd] for a callback that is called when the user stops + /// changing the value. + final ValueChanged? onChanged; + + /// Called when the user starts selecting a new value for the slider. + /// + /// This callback shouldn't be used to update the slider [value] (use + /// [onChanged] for that), but rather to be notified when the user has started + /// selecting a new value by starting a drag. + /// + /// The value passed will be the last [value] that the slider had before the + /// change began. + /// + /// {@tool snippet} + /// + /// ```dart + /// CupertinoSlider( + /// value: _cupertinoSliderValue.toDouble(), + /// min: 1.0, + /// max: 10.0, + /// divisions: 10, + /// onChanged: (double newValue) { + /// setState(() { + /// _cupertinoSliderValue = newValue.round(); + /// }); + /// }, + /// onChangeStart: (double startValue) { + /// print('Started change at $startValue'); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [onChangeEnd] for a callback that is called when the value change is + /// complete. + final ValueChanged? onChangeStart; + + /// Called when the user is done selecting a new value for the slider. + /// + /// This callback shouldn't be used to update the slider [value] (use + /// [onChanged] for that), but rather to know when the user has completed + /// selecting a new [value] by ending a drag. + /// + /// {@tool snippet} + /// + /// ```dart + /// CupertinoSlider( + /// value: _cupertinoSliderValue.toDouble(), + /// min: 1.0, + /// max: 10.0, + /// divisions: 10, + /// onChanged: (double newValue) { + /// setState(() { + /// _cupertinoSliderValue = newValue.round(); + /// }); + /// }, + /// onChangeEnd: (double newValue) { + /// print('Ended change on $newValue'); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [onChangeStart] for a callback that is called when a value change + /// begins. + final ValueChanged? onChangeEnd; + + /// The minimum value the user can select. + /// + /// Defaults to 0.0. + final double min; + + /// The maximum value the user can select. + /// + /// Defaults to 1.0. + final double max; + + /// The number of discrete divisions. + /// + /// If null, the slider is continuous. + final int? divisions; + + /// The color to use for the portion of the slider that has been selected. + /// + /// Defaults to the [CupertinoTheme]'s primary color if null. + final Color? activeColor; + + /// The color to use for the thumb of the slider. + /// + /// Defaults to [CupertinoColors.white]. + final Color thumbColor; + + @override + State createState() => _CupertinoSliderState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('value', value)); + properties.add(DoubleProperty('min', min)); + properties.add(DoubleProperty('max', max)); + } +} + +class _CupertinoSliderState extends State with TickerProviderStateMixin { + void _handleChanged(double value) { + assert(widget.onChanged != null); + final double lerpValue = lerpDouble(widget.min, widget.max, value)!; + if (lerpValue != widget.value) { + widget.onChanged!(lerpValue); + } + } + + void _handleDragStart(double value) { + assert(widget.onChangeStart != null); + widget.onChangeStart!(lerpDouble(widget.min, widget.max, value)!); + } + + void _handleDragEnd(double value) { + assert(widget.onChangeEnd != null); + widget.onChangeEnd!(lerpDouble(widget.min, widget.max, value)!); + } + + @override + Widget build(BuildContext context) { + return _CupertinoSliderRenderObjectWidget( + value: (widget.value - widget.min) / (widget.max - widget.min), + divisions: widget.divisions, + activeColor: CupertinoDynamicColor.resolve( + widget.activeColor ?? CupertinoTheme.of(context).primaryColor, + context, + ), + thumbColor: widget.thumbColor, + onChanged: widget.onChanged != null ? _handleChanged : null, + onChangeStart: widget.onChangeStart != null ? _handleDragStart : null, + onChangeEnd: widget.onChangeEnd != null ? _handleDragEnd : null, + vsync: this, + ); + } +} + +class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget { + const _CupertinoSliderRenderObjectWidget({ + required this.value, + this.divisions, + required this.activeColor, + required this.thumbColor, + this.onChanged, + this.onChangeStart, + this.onChangeEnd, + required this.vsync, + }); + + final double value; + final int? divisions; + final Color activeColor; + final Color thumbColor; + final ValueChanged? onChanged; + final ValueChanged? onChangeStart; + final ValueChanged? onChangeEnd; + final TickerProvider vsync; + + @override + _RenderCupertinoSlider createRenderObject(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + return _RenderCupertinoSlider( + value: value, + divisions: divisions, + activeColor: activeColor, + thumbColor: CupertinoDynamicColor.resolve(thumbColor, context), + trackColor: CupertinoDynamicColor.resolve(CupertinoColors.systemFill, context), + onChanged: onChanged, + onChangeStart: onChangeStart, + onChangeEnd: onChangeEnd, + vsync: vsync, + textDirection: Directionality.of(context), + cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderCupertinoSlider renderObject) { + assert(debugCheckHasDirectionality(context)); + renderObject + ..value = value + ..divisions = divisions + ..activeColor = activeColor + ..thumbColor = CupertinoDynamicColor.resolve(thumbColor, context) + ..trackColor = CupertinoDynamicColor.resolve(CupertinoColors.systemFill, context) + ..onChanged = onChanged + ..onChangeStart = onChangeStart + ..onChangeEnd = onChangeEnd + ..textDirection = Directionality.of(context); + // Ticker provider cannot change since there's a 1:1 relationship between + // the _SliderRenderObjectWidget object and the _SliderState object. + } +} + +const double _kPadding = 8.0; +const double _kSliderHeight = 2.0 * (CupertinoThumbPainter.radius + _kPadding); +const double _kSliderWidth = 176.0; // Matches Material Design slider. +const Duration _kDiscreteTransitionDuration = Duration(milliseconds: 500); + +const double _kAdjustmentUnit = 0.1; // Matches iOS implementation of material slider. + +class _RenderCupertinoSlider extends RenderConstrainedBox implements MouseTrackerAnnotation { + _RenderCupertinoSlider({ + required double value, + int? divisions, + required Color activeColor, + required Color thumbColor, + required Color trackColor, + ValueChanged? onChanged, + this.onChangeStart, + this.onChangeEnd, + required TickerProvider vsync, + required TextDirection textDirection, + MouseCursor cursor = MouseCursor.defer, + }) : assert(value >= 0.0 && value <= 1.0), + _cursor = cursor, + _value = value, + _divisions = divisions, + _activeColor = activeColor, + _thumbColor = thumbColor, + _trackColor = trackColor, + _onChanged = onChanged, + _textDirection = textDirection, + super(additionalConstraints: const BoxConstraints.tightFor(width: _kSliderWidth, height: _kSliderHeight)) { + _drag = HorizontalDragGestureRecognizer() + ..onStart = _handleDragStart + ..onUpdate = _handleDragUpdate + ..onEnd = _handleDragEnd; + _position = AnimationController( + value: value, + duration: _kDiscreteTransitionDuration, + vsync: vsync, + )..addListener(markNeedsPaint); + } + + double get value => _value; + double _value; + set value(double newValue) { + assert(newValue >= 0.0 && newValue <= 1.0); + if (newValue == _value) { + return; + } + _value = newValue; + if (divisions != null) { + _position.animateTo(newValue, curve: Curves.fastOutSlowIn); + } else { + _position.value = newValue; + } + markNeedsSemanticsUpdate(); + } + + int? get divisions => _divisions; + int? _divisions; + set divisions(int? value) { + if (value == _divisions) { + return; + } + _divisions = value; + markNeedsPaint(); + } + + Color get activeColor => _activeColor; + Color _activeColor; + set activeColor(Color value) { + if (value == _activeColor) { + return; + } + _activeColor = value; + markNeedsPaint(); + } + + Color get thumbColor => _thumbColor; + Color _thumbColor; + set thumbColor(Color value) { + if (value == _thumbColor) { + return; + } + _thumbColor = value; + markNeedsPaint(); + } + + Color get trackColor => _trackColor; + Color _trackColor; + set trackColor(Color value) { + if (value == _trackColor) { + return; + } + _trackColor = value; + markNeedsPaint(); + } + + ValueChanged? get onChanged => _onChanged; + ValueChanged? _onChanged; + set onChanged(ValueChanged? value) { + if (value == _onChanged) { + return; + } + final bool wasInteractive = isInteractive; + _onChanged = value; + if (wasInteractive != isInteractive) { + markNeedsSemanticsUpdate(); + } + } + + ValueChanged? onChangeStart; + ValueChanged? onChangeEnd; + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsPaint(); + } + + late AnimationController _position; + + late HorizontalDragGestureRecognizer _drag; + double _currentDragValue = 0.0; + + double get _discretizedCurrentDragValue { + double dragValue = clampDouble(_currentDragValue, 0.0, 1.0); + if (divisions != null) { + dragValue = (dragValue * divisions!).round() / divisions!; + } + return dragValue; + } + + double get _trackLeft => _kPadding; + double get _trackRight => size.width - _kPadding; + double get _thumbCenter { + final double visualPosition; + switch (textDirection) { + case TextDirection.rtl: + visualPosition = 1.0 - _value; + case TextDirection.ltr: + visualPosition = _value; + } + return lerpDouble(_trackLeft + CupertinoThumbPainter.radius, _trackRight - CupertinoThumbPainter.radius, visualPosition)!; + } + + bool get isInteractive => onChanged != null; + + void _handleDragStart(DragStartDetails details) => _startInteraction(details.globalPosition); + + void _handleDragUpdate(DragUpdateDetails details) { + if (isInteractive) { + final double extent = math.max(_kPadding, size.width - 2.0 * (_kPadding + CupertinoThumbPainter.radius)); + final double valueDelta = details.primaryDelta! / extent; + switch (textDirection) { + case TextDirection.rtl: + _currentDragValue -= valueDelta; + case TextDirection.ltr: + _currentDragValue += valueDelta; + } + onChanged!(_discretizedCurrentDragValue); + } + } + + void _handleDragEnd(DragEndDetails details) => _endInteraction(); + + void _startInteraction(Offset globalPosition) { + if (isInteractive) { + onChangeStart?.call(_discretizedCurrentDragValue); + _currentDragValue = _value; + onChanged!(_discretizedCurrentDragValue); + } + } + + void _endInteraction() { + onChangeEnd?.call(_discretizedCurrentDragValue); + _currentDragValue = 0.0; + } + + @override + bool hitTestSelf(Offset position) { + return (position.dx - _thumbCenter).abs() < CupertinoThumbPainter.radius + _kPadding; + } + + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + assert(debugHandleEvent(event, entry)); + if (event is PointerDownEvent && isInteractive) { + _drag.addPointer(event); + } + } + + @override + void paint(PaintingContext context, Offset offset) { + final double visualPosition; + final Color leftColor; + final Color rightColor; + switch (textDirection) { + case TextDirection.rtl: + visualPosition = 1.0 - _position.value; + leftColor = _activeColor; + rightColor = trackColor; + case TextDirection.ltr: + visualPosition = _position.value; + leftColor = trackColor; + rightColor = _activeColor; + } + + final double trackCenter = offset.dy + size.height / 2.0; + final double trackLeft = offset.dx + _trackLeft; + final double trackTop = trackCenter - 1.0; + final double trackBottom = trackCenter + 1.0; + final double trackRight = offset.dx + _trackRight; + final double trackActive = offset.dx + _thumbCenter; + + final Canvas canvas = context.canvas; + + if (visualPosition > 0.0) { + final Paint paint = Paint()..color = rightColor; + canvas.drawRRect(RRect.fromLTRBXY(trackLeft, trackTop, trackActive, trackBottom, 1.0, 1.0), paint); + } + + if (visualPosition < 1.0) { + final Paint paint = Paint()..color = leftColor; + canvas.drawRRect(RRect.fromLTRBXY(trackActive, trackTop, trackRight, trackBottom, 1.0, 1.0), paint); + } + + final Offset thumbCenter = Offset(trackActive, trackCenter); + CupertinoThumbPainter(color: thumbColor).paint(canvas, Rect.fromCircle(center: thumbCenter, radius: CupertinoThumbPainter.radius)); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + + config.isSemanticBoundary = isInteractive; + config.isSlider = true; + if (isInteractive) { + config.textDirection = textDirection; + config.onIncrease = _increaseAction; + config.onDecrease = _decreaseAction; + config.value = '${(value * 100).round()}%'; + config.increasedValue = '${(clampDouble(value + _semanticActionUnit, 0.0, 1.0) * 100).round()}%'; + config.decreasedValue = '${(clampDouble(value - _semanticActionUnit, 0.0, 1.0) * 100).round()}%'; + } + } + + double get _semanticActionUnit => divisions != null ? 1.0 / divisions! : _kAdjustmentUnit; + + void _increaseAction() { + if (isInteractive) { + onChanged!(clampDouble(value + _semanticActionUnit, 0.0, 1.0)); + } + } + + void _decreaseAction() { + if (isInteractive) { + onChanged!(clampDouble(value - _semanticActionUnit, 0.0, 1.0)); + } + } + + @override + MouseCursor get cursor => _cursor; + MouseCursor _cursor; + set cursor(MouseCursor value) { + if (_cursor != value) { + _cursor = value; + // A repaint is needed in order to trigger a device update of + // [MouseTracker] so that this new value can be found. + markNeedsPaint(); + } + } + + @override + PointerEnterEventListener? onEnter; + + PointerHoverEventListener? onHover; + + @override + PointerExitEventListener? onExit; + + @override + bool get validForMouseTracker => false; + + @override + void dispose() { + _drag.dispose(); + _position.dispose(); + super.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/sliding_segmented_control.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/sliding_segmented_control.dart new file mode 100644 index 0000000000000000000000000000000000000000..930d44d9ef6c70fd6b5725c335d16f0591c2ec21 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/sliding_segmented_control.dart @@ -0,0 +1,1129 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/physics.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; + +// Extracted from https://developer.apple.com/design/resources/. + +// Minimum padding from edges of the segmented control to edges of +// encompassing widget. +const EdgeInsetsGeometry _kHorizontalItemPadding = EdgeInsets.symmetric(vertical: 2, horizontal: 3); + +// The corner radius of the thumb. +const Radius _kThumbRadius = Radius.circular(6.93); +// The amount of space by which to expand the thumb from the size of the currently +// selected child. +const EdgeInsets _kThumbInsets = EdgeInsets.symmetric(horizontal: 1); + +// Minimum height of the segmented control. +const double _kMinSegmentedControlHeight = 28.0; + +const Color _kSeparatorColor = Color(0x4D8E8E93); + +const CupertinoDynamicColor _kThumbColor = CupertinoDynamicColor.withBrightness( + color: Color(0xFFFFFFFF), + darkColor: Color(0xFF636366), +); + +// The amount of space by which to inset each separator. +const EdgeInsets _kSeparatorInset = EdgeInsets.symmetric(vertical: 6); +const double _kSeparatorWidth = 1; +const Radius _kSeparatorRadius = Radius.circular(_kSeparatorWidth/2); + +// The minimum scale factor of the thumb, when being pressed on for a sufficient +// amount of time. +const double _kMinThumbScale = 0.95; + +// The minimum horizontal distance between the edges of the separator and the +// closest child. +const double _kSegmentMinPadding = 9.25; + +// The threshold value used in hasDraggedTooFar, for checking against the square +// L2 distance from the location of the current drag pointer, to the closest +// vertex of the CupertinoSlidingSegmentedControl's Rect. +// +// Both the mechanism and the value are speculated. +const double _kTouchYDistanceThreshold = 50.0 * 50.0; + +// The corner radius of the segmented control. +// +// Inspected from iOS 13.2 simulator. +const double _kCornerRadius = 8; + +// The minimum opacity of an unselected segment, when the user presses on the +// segment and it starts to fadeout. +// +// Inspected from iOS 13.2 simulator. +const double _kContentPressedMinOpacity = 0.2; + +// The spring animation used when the thumb changes its rect. +final SpringSimulation _kThumbSpringAnimationSimulation = SpringSimulation( + const SpringDescription(mass: 1, stiffness: 503.551, damping: 44.8799), + 0, + 1, + 0, // Every time a new spring animation starts the previous animation stops. +); + +const Duration _kSpringAnimationDuration = Duration(milliseconds: 412); + +const Duration _kOpacityAnimationDuration = Duration(milliseconds: 470); + +const Duration _kHighlightAnimationDuration = Duration(milliseconds: 200); + +class _Segment extends StatefulWidget { + const _Segment({ + required ValueKey key, + required this.child, + required this.pressed, + required this.highlighted, + required this.isDragging, + }) : super(key: key); + + final Widget child; + + final bool pressed; + final bool highlighted; + + // Whether the thumb of the parent widget (CupertinoSlidingSegmentedControl) + // is currently being dragged. + final bool isDragging; + + bool get shouldFadeoutContent => pressed && !highlighted; + bool get shouldScaleContent => pressed && highlighted && isDragging; + + @override + _SegmentState createState() => _SegmentState(); +} + +class _SegmentState extends State<_Segment> with TickerProviderStateMixin<_Segment> { + late final AnimationController highlightPressScaleController; + late Animation highlightPressScaleAnimation; + + @override + void initState() { + super.initState(); + highlightPressScaleController = AnimationController( + duration: _kOpacityAnimationDuration, + value: widget.shouldScaleContent ? 1 : 0, + vsync: this, + ); + + highlightPressScaleAnimation = highlightPressScaleController.drive( + Tween(begin: 1.0, end: _kMinThumbScale), + ); + } + + @override + void didUpdateWidget(_Segment oldWidget) { + super.didUpdateWidget(oldWidget); + assert(oldWidget.key == widget.key); + + if (oldWidget.shouldScaleContent != widget.shouldScaleContent) { + highlightPressScaleAnimation = highlightPressScaleController.drive( + Tween( + begin: highlightPressScaleAnimation.value, + end: widget.shouldScaleContent ? _kMinThumbScale : 1.0, + ), + ); + highlightPressScaleController.animateWith(_kThumbSpringAnimationSimulation); + } + } + + @override + void dispose() { + highlightPressScaleController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return MetaData( + // Expand the hitTest area of this widget. + behavior: HitTestBehavior.opaque, + child: IndexedStack( + alignment: Alignment.center, + children: [ + AnimatedOpacity( + opacity: widget.shouldFadeoutContent ? _kContentPressedMinOpacity : 1, + duration: _kOpacityAnimationDuration, + curve: Curves.ease, + child: AnimatedDefaultTextStyle( + style: DefaultTextStyle.of(context) + .style + .merge(TextStyle(fontWeight: widget.highlighted ? FontWeight.w500 : FontWeight.normal)), + duration: _kHighlightAnimationDuration, + curve: Curves.ease, + child: ScaleTransition( + scale: highlightPressScaleAnimation, + child: widget.child, + ), + ), + ), + // The entire widget will assume the size of this widget, so when a + // segment's "highlight" animation plays the size of the parent stays + // the same and will always be greater than equal to that of the + // visible child (at index 0), to keep the size of the entire + // SegmentedControl widget consistent throughout the animation. + Offstage( + child: DefaultTextStyle.merge( + style: const TextStyle(fontWeight: FontWeight.w500), + child: widget.child, + ), + ), + ], + ), + ); + } +} + +// Fadeout the separator when either adjacent segment is highlighted. +class _SegmentSeparator extends StatefulWidget { + const _SegmentSeparator({ + required ValueKey key, + required this.highlighted, + }) : super(key: key); + + final bool highlighted; + + @override + _SegmentSeparatorState createState() => _SegmentSeparatorState(); +} + +class _SegmentSeparatorState extends State<_SegmentSeparator> with TickerProviderStateMixin<_SegmentSeparator> { + late final AnimationController separatorOpacityController; + + @override + void initState() { + super.initState(); + + separatorOpacityController = AnimationController( + duration: _kSpringAnimationDuration, + value: widget.highlighted ? 0 : 1, + vsync: this, + ); + } + + @override + void didUpdateWidget(_SegmentSeparator oldWidget) { + super.didUpdateWidget(oldWidget); + assert(oldWidget.key == widget.key); + + if (oldWidget.highlighted != widget.highlighted) { + separatorOpacityController.animateTo( + widget.highlighted ? 0 : 1, + duration: _kSpringAnimationDuration, + curve: Curves.ease, + ); + } + } + + @override + void dispose() { + separatorOpacityController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return AnimatedBuilder( + animation: separatorOpacityController, + child: const SizedBox(width: _kSeparatorWidth), + builder: (BuildContext context, Widget? child) { + return Padding( + padding: _kSeparatorInset, + child: DecoratedBox( + decoration: BoxDecoration( + color: _kSeparatorColor.withOpacity(_kSeparatorColor.opacity * separatorOpacityController.value), + borderRadius: const BorderRadius.all(_kSeparatorRadius), + ), + child: child, + ), + ); + }, + ); + } +} + +/// An iOS 13 style segmented control. +/// +/// Displays the widgets provided in the [Map] of [children] in a horizontal list. +/// It allows the user to select between a number of mutually exclusive options, +/// by tapping or dragging within the segmented control. +/// +/// A segmented control can feature any [Widget] as one of the values in its +/// [Map] of [children]. The type T is the type of the [Map] keys used to identify +/// each widget and determine which widget is selected. As required by the [Map] +/// class, keys must be of consistent types and must be comparable. The [children] +/// argument must be an ordered [Map] such as a [LinkedHashMap], the ordering of +/// the keys will determine the order of the widgets in the segmented control. +/// +/// The widget calls the [onValueChanged] callback *when a valid user gesture +/// completes on an unselected segment*. The map key associated with the newly +/// selected widget is returned in the [onValueChanged] callback. Typically, +/// widgets that use a segmented control will listen for the [onValueChanged] +/// callback and rebuild the segmented control with a new [groupValue] to update +/// which option is currently selected. +/// +/// The [children] will be displayed in the order of the keys in the [Map], +/// along the current [TextDirection]. Each child widget will have the same size. +/// The height of the segmented control is determined by the height of the +/// tallest child widget. The width of each child will be the intrinsic width of +/// the widest child, or the available horizontal space divided by the number of +/// [children], which ever is smaller. +/// +/// A segmented control may optionally be created with custom colors. The +/// [thumbColor], [backgroundColor] arguments can be used to override the +/// segmented control's colors from its defaults. +/// +/// {@tool dartpad} +/// This example shows a [CupertinoSlidingSegmentedControl] with an enum type. +/// +/// The callback provided to [onValueChanged] should update the state of +/// the parent [StatefulWidget] using the [State.setState] method, so that +/// the parent gets rebuilt; for example: +/// +/// ** See code in examples/api/lib/cupertino/segmented_control/cupertino_sliding_segmented_control.0.dart ** +/// {@end-tool} +/// See also: +/// +/// * +class CupertinoSlidingSegmentedControl extends StatefulWidget { + /// Creates an iOS-style segmented control bar. + /// + /// The [children] argument must be an ordered [Map] such as a + /// [LinkedHashMap]. Further, the length of the [children] list must be + /// greater than one. + /// + /// Each widget value in the map of [children] must have an associated key + /// that uniquely identifies this widget. This key is what will be returned + /// in the [onValueChanged] callback when a new value from the [children] map + /// is selected. + /// + /// The [groupValue] is the currently selected value for the segmented control. + /// If no [groupValue] is provided, or the [groupValue] is null, no widget will + /// appear as selected. The [groupValue] must be either null or one of the keys + /// in the [children] map. + CupertinoSlidingSegmentedControl({ + super.key, + required this.children, + required this.onValueChanged, + this.groupValue, + this.thumbColor = _kThumbColor, + this.padding = _kHorizontalItemPadding, + this.backgroundColor = CupertinoColors.tertiarySystemFill, + }) : assert(children.length >= 2), + assert( + groupValue == null || children.keys.contains(groupValue), + 'The groupValue must be either null or one of the keys in the children map.', + ); + + /// The identifying keys and corresponding widget values in the + /// segmented control. + /// + /// This attribute must be an ordered [Map] such as a [LinkedHashMap]. Each + /// widget is typically a single-line [Text] widget or an [Icon] widget. + /// + /// The map must have more than one entry. + final Map children; + + /// The identifier of the widget that is currently selected. + /// + /// This must be one of the keys in the [Map] of [children]. + /// If this attribute is null, no widget will be initially selected. + final T? groupValue; + + /// The callback that is called when a new option is tapped. + /// + /// The segmented control passes the newly selected widget's associated key + /// to the callback but does not actually change state until the parent + /// widget rebuilds the segmented control with the new [groupValue]. + /// + /// The callback provided to [onValueChanged] should update the state of + /// the parent [StatefulWidget] using the [State.setState] method, so that + /// the parent gets rebuilt; for example: + /// + /// {@tool snippet} + /// + /// ```dart + /// class SegmentedControlExample extends StatefulWidget { + /// const SegmentedControlExample({super.key}); + /// + /// @override + /// State createState() => SegmentedControlExampleState(); + /// } + /// + /// class SegmentedControlExampleState extends State { + /// final Map children = const { + /// 0: Text('Child 1'), + /// 1: Text('Child 2'), + /// }; + /// + /// int? currentValue; + /// + /// @override + /// Widget build(BuildContext context) { + /// return CupertinoSlidingSegmentedControl( + /// children: children, + /// onValueChanged: (int? newValue) { + /// setState(() { + /// currentValue = newValue; + /// }); + /// }, + /// groupValue: currentValue, + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + final ValueChanged onValueChanged; + + /// The color used to paint the rounded rect behind the [children] and the separators. + /// + /// The default value is [CupertinoColors.tertiarySystemFill]. The background + /// will not be painted if null is specified. + final Color backgroundColor; + + /// The color used to paint the interior of the thumb that appears behind the + /// currently selected item. + /// + /// The default value is a [CupertinoDynamicColor] that appears white in light + /// mode and becomes a gray color in dark mode. + final Color thumbColor; + + /// The amount of space by which to inset the [children]. + /// + /// Defaults to `EdgeInsets.symmetric(vertical: 2, horizontal: 3)`. + final EdgeInsetsGeometry padding; + + @override + State> createState() => _SegmentedControlState(); +} + +class _SegmentedControlState extends State> + with TickerProviderStateMixin> { + late final AnimationController thumbController = AnimationController(duration: _kSpringAnimationDuration, value: 0, vsync: this); + Animatable? thumbAnimatable; + + late final AnimationController thumbScaleController = AnimationController(duration: _kSpringAnimationDuration, value: 0, vsync: this); + late Animation thumbScaleAnimation = thumbScaleController.drive(Tween(begin: 1, end: _kMinThumbScale)); + + final TapGestureRecognizer tap = TapGestureRecognizer(); + final HorizontalDragGestureRecognizer drag = HorizontalDragGestureRecognizer(); + final LongPressGestureRecognizer longPress = LongPressGestureRecognizer(); + + @override + void initState() { + super.initState(); + // If the long press or horizontal drag recognizer gets accepted, we know for + // sure the gesture is meant for the segmented control. Hand everything to + // the drag gesture recognizer. + final GestureArenaTeam team = GestureArenaTeam(); + longPress.team = team; + drag.team = team; + team.captain = drag; + + drag + ..onDown = onDown + ..onUpdate = onUpdate + ..onEnd = onEnd + ..onCancel = onCancel; + + tap.onTapUp = onTapUp; + + // Empty callback to enable the long press recognizer. + longPress.onLongPress = () { }; + + highlighted = widget.groupValue; + } + + @override + void didUpdateWidget(CupertinoSlidingSegmentedControl oldWidget) { + super.didUpdateWidget(oldWidget); + + // Temporarily ignore highlight changes from the widget when the thumb is + // being dragged. When the drag gesture finishes the widget will be forced + // to build (see the onEnd method), and didUpdateWidget will be called again. + if (!isThumbDragging && highlighted != widget.groupValue) { + thumbController.animateWith(_kThumbSpringAnimationSimulation); + thumbAnimatable = null; + highlighted = widget.groupValue; + } + } + + @override + void dispose() { + thumbScaleController.dispose(); + thumbController.dispose(); + + drag.dispose(); + tap.dispose(); + longPress.dispose(); + + super.dispose(); + } + + // Whether the current drag gesture started on a selected segment. When this + // flag is false, the `onUpdate` method does not update `highlighted`. + // Otherwise the thumb can be dragged around in an ongoing drag gesture. + bool? _startedOnSelectedSegment; + + // Whether an ongoing horizontal drag gesture that started on the thumb is + // present. When true, defer/ignore changes to the `highlighted` variable + // from other sources (except for semantics) until the gesture ends, preventing + // them from interfering with the active drag gesture. + bool get isThumbDragging => _startedOnSelectedSegment ?? false; + + // Converts local coordinate to segments. This method assumes each segment has + // the same width. + T segmentForXPosition(double dx) { + final RenderBox renderBox = context.findRenderObject()! as RenderBox; + final int numOfChildren = widget.children.length; + assert(renderBox.hasSize); + assert(numOfChildren >= 2); + int index = (dx ~/ (renderBox.size.width / numOfChildren)).clamp(0, numOfChildren - 1); + + switch (Directionality.of(context)) { + case TextDirection.ltr: + break; + case TextDirection.rtl: + index = numOfChildren - 1 - index; + } + + return widget.children.keys.elementAt(index); + } + + bool _hasDraggedTooFar(DragUpdateDetails details) { + final RenderBox renderBox = context.findRenderObject()! as RenderBox; + assert(renderBox.hasSize); + final Size size = renderBox.size; + final Offset offCenter = details.localPosition - Offset(size.width/2, size.height/2); + final double l2 = math.pow(math.max(0.0, offCenter.dx.abs() - size.width/2), 2) + + math.pow(math.max(0.0, offCenter.dy.abs() - size.height/2), 2) as double; + return l2 > _kTouchYDistanceThreshold; + } + + // The thumb shrinks when the user presses on it, and starts expanding when + // the user lets go. + // This animation must be synced with the segment scale animation (see the + // _Segment widget) to make the overall animation look natural when the thumb + // is not sliding. + void _playThumbScaleAnimation({ required bool isExpanding }) { + thumbScaleAnimation = thumbScaleController.drive( + Tween( + begin: thumbScaleAnimation.value, + end: isExpanding ? 1 : _kMinThumbScale, + ), + ); + thumbScaleController.animateWith(_kThumbSpringAnimationSimulation); + } + + void onHighlightChangedByGesture(T newValue) { + if (highlighted == newValue) { + return; + } + setState(() { highlighted = newValue; }); + // Additionally, start the thumb animation if the highlighted segment + // changes. If the thumbController is already running, the render object's + // paint method will create a new tween to drive the animation with. + // TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/74356: + // the current thumb will be painted at the same location twice (before and + // after the new animation starts). + thumbController.animateWith(_kThumbSpringAnimationSimulation); + thumbAnimatable = null; + } + + void onPressedChangedByGesture(T? newValue) { + if (pressed != newValue) { + setState(() { pressed = newValue; }); + } + } + + void onTapUp(TapUpDetails details) { + // No gesture should interfere with an ongoing thumb drag. + if (isThumbDragging) { + return; + } + final T segment = segmentForXPosition(details.localPosition.dx); + onPressedChangedByGesture(null); + if (segment != widget.groupValue) { + widget.onValueChanged(segment); + } + } + + void onDown(DragDownDetails details) { + final T touchDownSegment = segmentForXPosition(details.localPosition.dx); + _startedOnSelectedSegment = touchDownSegment == highlighted; + onPressedChangedByGesture(touchDownSegment); + + if (isThumbDragging) { + _playThumbScaleAnimation(isExpanding: false); + } + } + + void onUpdate(DragUpdateDetails details) { + if (isThumbDragging) { + final T segment = segmentForXPosition(details.localPosition.dx); + onPressedChangedByGesture(segment); + onHighlightChangedByGesture(segment); + } else { + final T? segment = _hasDraggedTooFar(details) + ? null + : segmentForXPosition(details.localPosition.dx); + onPressedChangedByGesture(segment); + } + } + + void onEnd(DragEndDetails details) { + final T? pressed = this.pressed; + if (isThumbDragging) { + _playThumbScaleAnimation(isExpanding: true); + if (highlighted != widget.groupValue) { + widget.onValueChanged(highlighted); + } + } else if (pressed != null) { + onHighlightChangedByGesture(pressed); + assert(pressed == highlighted); + if (highlighted != widget.groupValue) { + widget.onValueChanged(highlighted); + } + } + + onPressedChangedByGesture(null); + _startedOnSelectedSegment = null; + } + + void onCancel() { + if (isThumbDragging) { + _playThumbScaleAnimation(isExpanding: true); + } + + onPressedChangedByGesture(null); + _startedOnSelectedSegment = null; + } + + // The segment the sliding thumb is currently located at, or animating to. It + // may have a different value from widget.groupValue, since this widget does + // not report a selection change via `onValueChanged` until the user stops + // interacting with the widget (onTapUp). For example, the user can drag the + // thumb around, and the `onValueChanged` callback will not be invoked until + // the thumb is let go. + T? highlighted; + + // The segment the user is currently pressing. + T? pressed; + + @override + Widget build(BuildContext context) { + assert(widget.children.length >= 2); + List children = []; + bool isPreviousSegmentHighlighted = false; + + int index = 0; + int? highlightedIndex; + for (final MapEntry entry in widget.children.entries) { + final bool isHighlighted = highlighted == entry.key; + if (isHighlighted) { + highlightedIndex = index; + } + + if (index != 0) { + children.add( + _SegmentSeparator( + // Let separators be TextDirection-invariant. If the TextDirection + // changes, the separators should mostly stay where they were. + key: ValueKey(index), + highlighted: isPreviousSegmentHighlighted || isHighlighted, + ), + ); + } + + children.add( + Semantics( + button: true, + onTap: () { widget.onValueChanged(entry.key); }, + inMutuallyExclusiveGroup: true, + selected: widget.groupValue == entry.key, + child: MouseRegion( + cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, + child: _Segment( + key: ValueKey(entry.key), + highlighted: isHighlighted, + pressed: pressed == entry.key, + isDragging: isThumbDragging, + child: entry.value, + ), + ), + ), + ); + + index += 1; + isPreviousSegmentHighlighted = isHighlighted; + } + + assert((highlightedIndex == null) == (highlighted == null)); + + switch (Directionality.of(context)) { + case TextDirection.ltr: + break; + case TextDirection.rtl: + children = children.reversed.toList(growable: false); + if (highlightedIndex != null) { + highlightedIndex = index - 1 - highlightedIndex; + } + } + + return UnconstrainedBox( + constrainedAxis: Axis.horizontal, + child: Container( + padding: widget.padding.resolve(Directionality.of(context)), + decoration: BoxDecoration( + borderRadius: const BorderRadius.all(Radius.circular(_kCornerRadius)), + color: CupertinoDynamicColor.resolve(widget.backgroundColor, context), + ), + child: AnimatedBuilder( + animation: thumbScaleAnimation, + builder: (BuildContext context, Widget? child) { + return _SegmentedControlRenderWidget( + highlightedIndex: highlightedIndex, + thumbColor: CupertinoDynamicColor.resolve(widget.thumbColor, context), + thumbScale: thumbScaleAnimation.value, + state: this, + children: children, + ); + }, + ), + ), + ); + } +} + +class _SegmentedControlRenderWidget extends MultiChildRenderObjectWidget { + const _SegmentedControlRenderWidget({ + super.key, + super.children, + required this.highlightedIndex, + required this.thumbColor, + required this.thumbScale, + required this.state, + }); + + final int? highlightedIndex; + final Color thumbColor; + final double thumbScale; + final _SegmentedControlState state; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderSegmentedControl( + highlightedIndex: highlightedIndex, + thumbColor: thumbColor, + thumbScale: thumbScale, + state: state, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderSegmentedControl renderObject) { + assert(renderObject.state == state); + renderObject + ..thumbColor = thumbColor + ..thumbScale = thumbScale + ..highlightedIndex = highlightedIndex; + } +} + +class _SegmentedControlContainerBoxParentData extends ContainerBoxParentData { } + +// The behavior of a UISegmentedControl as observed on iOS 13.1: +// +// 1. Tap up inside events will set the current selected index to the index of the +// segment at the tap up location instantaneously (there might be animation but +// the index change seems to happen before animation finishes), unless the tap +// down event from the same touch event didn't happen within the segmented +// control, in which case the touch event will be ignored entirely (will be +// referring to these touch events as invalid touch events below). +// +// 2. A valid tap up event will also trigger the sliding CASpringAnimation (even +// when it lands on the current segment), starting from the current `frame` +// of the thumb. The previous sliding animation, if still playing, will be +// removed and its velocity reset to 0. The sliding animation has a fixed +// duration, regardless of the distance or transform. +// +// 3. When the sliding animation plays two other animations take place. In one animation +// the content of the current segment gradually becomes "highlighted", turning the +// font weight to semibold (CABasicAnimation, timingFunction = default, duration = 0.2). +// The other is the separator fadein/fadeout animation (duration = 0.41). +// +// 4. A tap down event on the segment pointed to by the current selected +// index will trigger a CABasicAnimation that shrinks the thumb to 95% of its +// original size, even if the sliding animation is still playing. The +/// corresponding tap up event inverts the process (eyeballed). +// +// 5. A tap down event on other segments will trigger a CABasicAnimation +// (timingFunction = default, duration = 0.47.) that fades out the content +// from its current alpha, eventually reducing the alpha of that segment to +// 20% unless interrupted by a tap up event or the pointer moves out of the +// region (either outside of the segmented control's vicinity or to a +// different segment). The reverse animation has the same duration and timing +// function. +class _RenderSegmentedControl extends RenderBox + with ContainerRenderObjectMixin>, + RenderBoxContainerDefaultsMixin> { + _RenderSegmentedControl({ + required int? highlightedIndex, + required Color thumbColor, + required double thumbScale, + required this.state, + }) : _highlightedIndex = highlightedIndex, + _thumbColor = thumbColor, + _thumbScale = thumbScale; + + final _SegmentedControlState state; + + // The current **Unscaled** Thumb Rect in this RenderBox's coordinate space. + Rect? currentThumbRect; + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + state.thumbController.addListener(markNeedsPaint); + } + + @override + void detach() { + state.thumbController.removeListener(markNeedsPaint); + super.detach(); + } + + double get thumbScale => _thumbScale; + double _thumbScale; + set thumbScale(double value) { + if (_thumbScale == value) { + return; + } + + _thumbScale = value; + if (state.highlighted != null) { + markNeedsPaint(); + } + } + + int? get highlightedIndex => _highlightedIndex; + int? _highlightedIndex; + set highlightedIndex(int? value) { + if (_highlightedIndex == value) { + return; + } + + _highlightedIndex = value; + markNeedsPaint(); + } + + Color get thumbColor => _thumbColor; + Color _thumbColor; + set thumbColor(Color value) { + if (_thumbColor == value) { + return; + } + _thumbColor = value; + markNeedsPaint(); + } + + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + assert(debugHandleEvent(event, entry)); + // No gesture should interfere with an ongoing thumb drag. + if (event is PointerDownEvent && !state.isThumbDragging) { + state.tap.addPointer(event); + state.longPress.addPointer(event); + state.drag.addPointer(event); + } + } + + // Intrinsic Dimensions + + double get totalSeparatorWidth => (_kSeparatorInset.horizontal + _kSeparatorWidth) * (childCount ~/ 2); + + RenderBox? nonSeparatorChildAfter(RenderBox child) { + final RenderBox? nextChild = childAfter(child); + return nextChild == null ? null : childAfter(nextChild); + } + + @override + double computeMinIntrinsicWidth(double height) { + final int childCount = this.childCount ~/ 2 + 1; + RenderBox? child = firstChild; + double maxMinChildWidth = 0; + while (child != null) { + final double childWidth = child.getMinIntrinsicWidth(height); + maxMinChildWidth = math.max(maxMinChildWidth, childWidth); + child = nonSeparatorChildAfter(child); + } + return (maxMinChildWidth + 2 * _kSegmentMinPadding) * childCount + totalSeparatorWidth; + } + + @override + double computeMaxIntrinsicWidth(double height) { + final int childCount = this.childCount ~/ 2 + 1; + RenderBox? child = firstChild; + double maxMaxChildWidth = 0; + while (child != null) { + final double childWidth = child.getMaxIntrinsicWidth(height); + maxMaxChildWidth = math.max(maxMaxChildWidth, childWidth); + child = nonSeparatorChildAfter(child); + } + return (maxMaxChildWidth + 2 * _kSegmentMinPadding) * childCount + totalSeparatorWidth; + } + + @override + double computeMinIntrinsicHeight(double width) { + RenderBox? child = firstChild; + double maxMinChildHeight = _kMinSegmentedControlHeight; + while (child != null) { + final double childHeight = child.getMinIntrinsicHeight(width); + maxMinChildHeight = math.max(maxMinChildHeight, childHeight); + child = nonSeparatorChildAfter(child); + } + return maxMinChildHeight; + } + + @override + double computeMaxIntrinsicHeight(double width) { + RenderBox? child = firstChild; + double maxMaxChildHeight = _kMinSegmentedControlHeight; + while (child != null) { + final double childHeight = child.getMaxIntrinsicHeight(width); + maxMaxChildHeight = math.max(maxMaxChildHeight, childHeight); + child = nonSeparatorChildAfter(child); + } + return maxMaxChildHeight; + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + return defaultComputeDistanceToHighestActualBaseline(baseline); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! _SegmentedControlContainerBoxParentData) { + child.parentData = _SegmentedControlContainerBoxParentData(); + } + } + + Size _calculateChildSize(BoxConstraints constraints) { + final int childCount = this.childCount ~/ 2 + 1; + double childWidth = (constraints.minWidth - totalSeparatorWidth) / childCount; + double maxHeight = _kMinSegmentedControlHeight; + RenderBox? child = firstChild; + while (child != null) { + childWidth = math.max(childWidth, child.getMaxIntrinsicWidth(double.infinity) + 2 * _kSegmentMinPadding); + child = nonSeparatorChildAfter(child); + } + childWidth = math.min( + childWidth, + (constraints.maxWidth - totalSeparatorWidth) / childCount, + ); + child = firstChild; + while (child != null) { + final double boxHeight = child.getMaxIntrinsicHeight(childWidth); + maxHeight = math.max(maxHeight, boxHeight); + child = nonSeparatorChildAfter(child); + } + return Size(childWidth, maxHeight); + } + + Size _computeOverallSizeFromChildSize(Size childSize, BoxConstraints constraints) { + final int childCount = this.childCount ~/ 2 + 1; + return constraints.constrain(Size(childSize.width * childCount + totalSeparatorWidth, childSize.height)); + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + final Size childSize = _calculateChildSize(constraints); + return _computeOverallSizeFromChildSize(childSize, constraints); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + final Size childSize = _calculateChildSize(constraints); + final BoxConstraints childConstraints = BoxConstraints.tight(childSize); + final BoxConstraints separatorConstraints = childConstraints.heightConstraints(); + + RenderBox? child = firstChild; + int index = 0; + double start = 0; + while (child != null) { + child.layout(index.isEven ? childConstraints : separatorConstraints, parentUsesSize: true); + final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; + final Offset childOffset = Offset(start, 0); + childParentData.offset = childOffset; + start += child.size.width; + assert( + index.isEven || child.size.width == _kSeparatorWidth + _kSeparatorInset.horizontal, + '${child.size.width} != ${_kSeparatorWidth + _kSeparatorInset.horizontal}', + ); + child = childAfter(child); + index += 1; + } + + size = _computeOverallSizeFromChildSize(childSize, constraints); + } + + // This method is used to convert the original unscaled thumb rect painted in + // the previous frame, to a Rect that is within the valid boundary defined by + // the child segments. + // + // The overall size does not include that of the thumb. That is, if the thumb + // is located at the first or the last segment, the thumb can get cut off if + // one of the values in _kThumbInsets is positive. + Rect? moveThumbRectInBound(Rect? thumbRect, List children) { + assert(hasSize); + assert(children.length >= 2); + if (thumbRect == null) { + return null; + } + + final Offset firstChildOffset = (children.first.parentData! as _SegmentedControlContainerBoxParentData).offset; + final double leftMost = firstChildOffset.dx; + final double rightMost = (children.last.parentData! as _SegmentedControlContainerBoxParentData).offset.dx + children.last.size.width; + assert(rightMost > leftMost); + + // Ignore the horizontal position and the height of `thumbRect`, and + // calculates them from `children`. + return Rect.fromLTRB( + math.max(thumbRect.left, leftMost - _kThumbInsets.left), + firstChildOffset.dy - _kThumbInsets.top, + math.min(thumbRect.right, rightMost + _kThumbInsets.right), + firstChildOffset.dy + children.first.size.height + _kThumbInsets.bottom, + ); + } + + @override + void paint(PaintingContext context, Offset offset) { + final List children = getChildrenAsList(); + + for (int index = 1; index < childCount; index += 2) { + _paintSeparator(context, offset, children[index]); + } + + final int? highlightedChildIndex = highlightedIndex; + // Paint thumb if there's a highlighted segment. + if (highlightedChildIndex != null) { + final RenderBox selectedChild = children[highlightedChildIndex * 2]; + + final _SegmentedControlContainerBoxParentData childParentData = selectedChild.parentData! as _SegmentedControlContainerBoxParentData; + final Rect newThumbRect = _kThumbInsets.inflateRect(childParentData.offset & selectedChild.size); + + // Update thumb animation's tween, in case the end rect changed (e.g., a + // new segment is added during the animation). + if (state.thumbController.isAnimating) { + final Animatable? thumbTween = state.thumbAnimatable; + if (thumbTween == null) { + // This is the first frame of the animation. + final Rect startingRect = moveThumbRectInBound(currentThumbRect, children) ?? newThumbRect; + state.thumbAnimatable = RectTween(begin: startingRect, end: newThumbRect); + } else if (newThumbRect != thumbTween.transform(1)) { + // The thumbTween of the running sliding animation needs updating, + // without restarting the animation. + final Rect startingRect = moveThumbRectInBound(currentThumbRect, children) ?? newThumbRect; + state.thumbAnimatable = RectTween(begin: startingRect, end: newThumbRect) + .chain(CurveTween(curve: Interval(state.thumbController.value, 1))); + } + } else { + state.thumbAnimatable = null; + } + + final Rect unscaledThumbRect = state.thumbAnimatable?.evaluate(state.thumbController) ?? newThumbRect; + currentThumbRect = unscaledThumbRect; + final Rect thumbRect = Rect.fromCenter( + center: unscaledThumbRect.center, + width: unscaledThumbRect.width * thumbScale, + height: unscaledThumbRect.height * thumbScale, + ); + + _paintThumb(context, offset, thumbRect); + } else { + currentThumbRect = null; + } + + for (int index = 0; index < children.length; index += 2) { + _paintChild(context, offset, children[index]); + } + } + + // Paint the separator to the right of the given child. + final Paint separatorPaint = Paint(); + void _paintSeparator(PaintingContext context, Offset offset, RenderBox child) { + final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; + context.paintChild(child, offset + childParentData.offset); + } + + void _paintChild(PaintingContext context, Offset offset, RenderBox child) { + final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; + context.paintChild(child, childParentData.offset + offset); + } + + void _paintThumb(PaintingContext context, Offset offset, Rect thumbRect) { + // Colors extracted from https://developer.apple.com/design/resources/. + const List thumbShadow = [ + BoxShadow( + color: Color(0x1F000000), + offset: Offset(0, 3), + blurRadius: 8, + ), + BoxShadow( + color: Color(0x0A000000), + offset: Offset(0, 3), + blurRadius: 1, + ), + ]; + + final RRect thumbRRect = RRect.fromRectAndRadius(thumbRect.shift(offset), _kThumbRadius); + + for (final BoxShadow shadow in thumbShadow) { + context.canvas.drawRRect(thumbRRect.shift(shadow.offset), shadow.toPaint()); + } + + context.canvas.drawRRect( + thumbRRect.inflate(0.5), + Paint()..color = const Color(0x0A000000), + ); + + context.canvas.drawRRect( + thumbRRect, + Paint()..color = thumbColor, + ); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + RenderBox? child = lastChild; + while (child != null) { + final _SegmentedControlContainerBoxParentData childParentData = + child.parentData! as _SegmentedControlContainerBoxParentData; + if ((childParentData.offset & child.size).contains(position)) { + return result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset localOffset) { + assert(localOffset == position - childParentData.offset); + return child!.hitTest(result, position: localOffset); + }, + ); + } + child = childParentData.previousSibling; + } + return false; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/spell_check_suggestions_toolbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/spell_check_suggestions_toolbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..2e100c13875a7facd36743d270ab048f680a20b3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/spell_check_suggestions_toolbar.dart @@ -0,0 +1,159 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart' show SelectionChangedCause, SuggestionSpan; +import 'package:flutter/widgets.dart'; + +import 'debug.dart'; +import 'localizations.dart'; +import 'text_selection_toolbar.dart'; +import 'text_selection_toolbar_button.dart'; + +/// iOS only shows 3 spell check suggestions in the toolbar. +const int _kMaxSuggestions = 3; + +/// The default spell check suggestions toolbar for iOS. +/// +/// Tries to position itself below the [anchors], but if it doesn't fit, then it +/// readjusts to fit above bottom view insets. +/// +/// See also: +/// * [SpellCheckSuggestionsToolbar], which is similar but for both the +/// Material and Cupertino libraries. +class CupertinoSpellCheckSuggestionsToolbar extends StatelessWidget { + /// Constructs a [CupertinoSpellCheckSuggestionsToolbar]. + /// + /// [buttonItems] must not contain more than three items. + const CupertinoSpellCheckSuggestionsToolbar({ + super.key, + required this.anchors, + required this.buttonItems, + }) : assert(buttonItems.length <= _kMaxSuggestions); + + /// Constructs a [CupertinoSpellCheckSuggestionsToolbar] with the default + /// children for an [EditableText]. + /// + /// See also: + /// * [SpellCheckSuggestionsToolbar.editableText], which is similar but + /// builds an Android-style toolbar. + CupertinoSpellCheckSuggestionsToolbar.editableText({ + super.key, + required EditableTextState editableTextState, + }) : buttonItems = buildButtonItems(editableTextState) ?? [], + anchors = editableTextState.contextMenuAnchors; + + /// The location on which to anchor the menu. + final TextSelectionToolbarAnchors anchors; + + /// The [ContextMenuButtonItem]s that will be turned into the correct button + /// widgets and displayed in the spell check suggestions toolbar. + /// + /// Must not contain more than three items. + /// + /// See also: + /// + /// * [AdaptiveTextSelectionToolbar.buttonItems], the list of + /// [ContextMenuButtonItem]s that are used to build the buttons of the + /// text selection toolbar. + /// * [SpellCheckSuggestionsToolbar.buttonItems], the list of + /// [ContextMenuButtonItem]s used to build the Material style spell check + /// suggestions toolbar. + final List buttonItems; + + /// Builds the button items for the toolbar based on the available + /// spell check suggestions. + static List? buildButtonItems( + EditableTextState editableTextState, + ) { + // Determine if composing region is misspelled. + final SuggestionSpan? spanAtCursorIndex = + editableTextState.findSuggestionSpanAtCursorIndex( + editableTextState.currentTextEditingValue.selection.baseOffset, + ); + + if (spanAtCursorIndex == null) { + return null; + } + if (spanAtCursorIndex.suggestions.isEmpty) { + assert(debugCheckHasCupertinoLocalizations(editableTextState.context)); + final CupertinoLocalizations localizations = + CupertinoLocalizations.of(editableTextState.context); + return [ + ContextMenuButtonItem( + onPressed: null, + label: localizations.noSpellCheckReplacementsLabel, + ) + ]; + } + + final List buttonItems = []; + + // Build suggestion buttons. + for (final String suggestion in spanAtCursorIndex.suggestions.take(_kMaxSuggestions)) { + buttonItems.add(ContextMenuButtonItem( + onPressed: () { + if (!editableTextState.mounted) { + return; + } + _replaceText( + editableTextState, + suggestion, + spanAtCursorIndex.range, + ); + }, + label: suggestion, + )); + } + return buttonItems; + } + + static void _replaceText(EditableTextState editableTextState, String text, TextRange replacementRange) { + // Replacement cannot be performed if the text is read only or obscured. + assert(!editableTextState.widget.readOnly && !editableTextState.widget.obscureText); + + final TextEditingValue newValue = editableTextState.textEditingValue + .replaced( + replacementRange, + text, + ) + .copyWith( + selection: TextSelection.collapsed( + offset: replacementRange.start + text.length, + ), + ); + editableTextState.userUpdateTextEditingValue(newValue,SelectionChangedCause.toolbar); + + // Schedule a call to bringIntoView() after renderEditable updates. + SchedulerBinding.instance.addPostFrameCallback((Duration duration) { + if (editableTextState.mounted) { + editableTextState.bringIntoView(editableTextState.textEditingValue.selection.extent); + } + }, debugLabel: 'SpellCheckSuggestions.bringIntoView'); + editableTextState.hideToolbar(); + } + + /// Builds the toolbar buttons based on the [buttonItems]. + List _buildToolbarButtons(BuildContext context) { + return buttonItems.map((ContextMenuButtonItem buttonItem) { + return CupertinoTextSelectionToolbarButton.buttonItem( + buttonItem: buttonItem, + ); + }).toList(); + } + + @override + Widget build(BuildContext context) { + if (buttonItems.isEmpty) { + return const SizedBox.shrink(); + } + + final List children = _buildToolbarButtons(context); + return CupertinoTextSelectionToolbar( + anchorAbove: anchors.primaryAnchor, + anchorBelow: anchors.secondaryAnchor == null ? anchors.primaryAnchor : anchors.secondaryAnchor!, + children: children, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/switch.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/switch.dart new file mode 100644 index 0000000000000000000000000000000000000000..7c0a1957f3d7318b7b0d9580e8d7c03277af1363 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/switch.dart @@ -0,0 +1,793 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Examples can assume: +// bool _giveVerse = false; + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'theme.dart'; +import 'thumb_painter.dart'; + +// Examples can assume: +// bool _lights = false; +// void setState(VoidCallback fn) { } + +/// An iOS-style switch. +/// +/// Used to toggle the on/off state of a single setting. +/// +/// The switch itself does not maintain any state. Instead, when the state of +/// the switch changes, the widget calls the [onChanged] callback. Most widgets +/// that use a switch will listen for the [onChanged] callback and rebuild the +/// switch with a new [value] to update the visual appearance of the switch. +/// +/// {@tool dartpad} +/// This example shows a toggleable [CupertinoSwitch]. When the thumb slides to +/// the other side of the track, the switch is toggled between on/off. +/// +/// ** See code in examples/api/lib/cupertino/switch/cupertino_switch.0.dart ** +/// {@end-tool} +/// +/// {@tool snippet} +/// +/// This sample shows how to use a [CupertinoSwitch] in a [ListTile]. The +/// [MergeSemantics] is used to turn the entire [ListTile] into a single item +/// for accessibility tools. +/// +/// ```dart +/// MergeSemantics( +/// child: ListTile( +/// title: const Text('Lights'), +/// trailing: CupertinoSwitch( +/// value: _lights, +/// onChanged: (bool value) { setState(() { _lights = value; }); }, +/// ), +/// onTap: () { setState(() { _lights = !_lights; }); }, +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Switch], the Material Design equivalent. +/// * +class CupertinoSwitch extends StatefulWidget { + /// Creates an iOS-style switch. + /// + /// The [dragStartBehavior] parameter defaults to [DragStartBehavior.start]. + const CupertinoSwitch({ + super.key, + required this.value, + required this.onChanged, + this.activeColor, + this.trackColor, + this.thumbColor, + this.applyTheme, + this.focusColor, + this.onLabelColor, + this.offLabelColor, + this.focusNode, + this.onFocusChange, + this.autofocus = false, + this.dragStartBehavior = DragStartBehavior.start, + }); + + /// Whether this switch is on or off. + final bool value; + + /// Called when the user toggles with switch on or off. + /// + /// The switch passes the new value to the callback but does not actually + /// change state until the parent widget rebuilds the switch with the new + /// value. + /// + /// If null, the switch will be displayed as disabled, which has a reduced opacity. + /// + /// The callback provided to onChanged should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// CupertinoSwitch( + /// value: _giveVerse, + /// onChanged: (bool newValue) { + /// setState(() { + /// _giveVerse = newValue; + /// }); + /// }, + /// ) + /// ``` + final ValueChanged? onChanged; + + /// The color to use for the track when the switch is on. + /// + /// If null and [applyTheme] is false, defaults to [CupertinoColors.systemGreen] + /// in accordance to native iOS behavior. Otherwise, defaults to + /// [CupertinoThemeData.primaryColor]. + final Color? activeColor; + + + /// The color to use for the track when the switch is off. + /// + /// Defaults to [CupertinoColors.secondarySystemFill] when null. + final Color? trackColor; + + /// The color to use for the thumb of the switch. + /// + /// Defaults to [CupertinoColors.white] when null. + final Color? thumbColor; + + /// The color to use for the focus highlight for keyboard interactions. + /// + /// Defaults to a slightly transparent [activeColor]. + final Color? focusColor; + + /// The color to use for the accessibility label when the switch is on. + /// + /// Defaults to [CupertinoColors.white] when null. + final Color? onLabelColor; + + /// The color to use for the accessibility label when the switch is off. + /// + /// Defaults to [Color.fromARGB(255, 179, 179, 179)] + /// (or [Color.fromARGB(255, 255, 255, 255)] in high contrast) when null. + final Color? offLabelColor; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.material.inkwell.onFocusChange} + final ValueChanged? onFocusChange; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@template flutter.cupertino.CupertinoSwitch.applyTheme} + /// Whether to apply the ambient [CupertinoThemeData]. + /// + /// If true, the track uses [CupertinoThemeData.primaryColor] for the track + /// when the switch is on. + /// + /// Defaults to [CupertinoThemeData.applyThemeToAll]. + /// {@endtemplate} + final bool? applyTheme; + + /// {@template flutter.cupertino.CupertinoSwitch.dragStartBehavior} + /// Determines the way that drag start behavior is handled. + /// + /// If set to [DragStartBehavior.start], the drag behavior used to move the + /// switch from on to off will begin at the position where the drag gesture won + /// the arena. If set to [DragStartBehavior.down] it will begin at the position + /// where a down event was first detected. + /// + /// In general, setting this to [DragStartBehavior.start] will make drag + /// animation smoother and setting it to [DragStartBehavior.down] will make + /// drag behavior feel slightly more reactive. + /// + /// By default, the drag start behavior is [DragStartBehavior.start]. + /// + /// See also: + /// + /// * [DragGestureRecognizer.dragStartBehavior], which gives an example for + /// the different behaviors. + /// + /// {@endtemplate} + final DragStartBehavior dragStartBehavior; + + @override + State createState() => _CupertinoSwitchState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('value', value: value, ifTrue: 'on', ifFalse: 'off', showName: true)); + properties.add(ObjectFlagProperty>('onChanged', onChanged, ifNull: 'disabled')); + } +} + +class _CupertinoSwitchState extends State with TickerProviderStateMixin { + late TapGestureRecognizer _tap; + late HorizontalDragGestureRecognizer _drag; + + late AnimationController _positionController; + late CurvedAnimation position; + + late AnimationController _reactionController; + late Animation _reaction; + + late bool isFocused; + + bool get isInteractive => widget.onChanged != null; + + late final Map> _actionMap = >{ + ActivateIntent: CallbackAction(onInvoke: _handleTap), + }; + + // A non-null boolean value that changes to true at the end of a drag if the + // switch must be animated to the position indicated by the widget's value. + bool needsPositionAnimation = false; + + @override + void initState() { + super.initState(); + + isFocused = false; + + _tap = TapGestureRecognizer() + ..onTapDown = _handleTapDown + ..onTapUp = _handleTapUp + ..onTap = _handleTap + ..onTapCancel = _handleTapCancel; + _drag = HorizontalDragGestureRecognizer() + ..onStart = _handleDragStart + ..onUpdate = _handleDragUpdate + ..onEnd = _handleDragEnd + ..dragStartBehavior = widget.dragStartBehavior; + + _positionController = AnimationController( + duration: _kToggleDuration, + value: widget.value ? 1.0 : 0.0, + vsync: this, + ); + position = CurvedAnimation( + parent: _positionController, + curve: Curves.linear, + ); + _reactionController = AnimationController( + duration: _kReactionDuration, + vsync: this, + ); + _reaction = CurvedAnimation( + parent: _reactionController, + curve: Curves.ease, + ); + } + + @override + void didUpdateWidget(CupertinoSwitch oldWidget) { + super.didUpdateWidget(oldWidget); + _drag.dragStartBehavior = widget.dragStartBehavior; + + if (needsPositionAnimation || oldWidget.value != widget.value) { + _resumePositionAnimation(isLinear: needsPositionAnimation); + } + } + + // `isLinear` must be true if the position animation is trying to move the + // thumb to the closest end after the most recent drag animation, so the curve + // does not change when the controller's value is not 0 or 1. + // + // It can be set to false when it's an implicit animation triggered by + // widget.value changes. + void _resumePositionAnimation({ bool isLinear = true }) { + needsPositionAnimation = false; + position + ..curve = isLinear ? Curves.linear : Curves.ease + ..reverseCurve = isLinear ? Curves.linear : Curves.ease.flipped; + if (widget.value) { + _positionController.forward(); + } else { + _positionController.reverse(); + } + } + + void _handleTapDown(TapDownDetails details) { + if (isInteractive) { + needsPositionAnimation = false; + } + _reactionController.forward(); + } + + void _handleTap([Intent? _]) { + if (isInteractive) { + widget.onChanged!(!widget.value); + _emitVibration(); + } + } + + void _handleTapUp(TapUpDetails details) { + if (isInteractive) { + needsPositionAnimation = false; + _reactionController.reverse(); + } + } + + void _handleTapCancel() { + if (isInteractive) { + _reactionController.reverse(); + } + } + + void _handleDragStart(DragStartDetails details) { + if (isInteractive) { + needsPositionAnimation = false; + _reactionController.forward(); + _emitVibration(); + } + } + + void _handleDragUpdate(DragUpdateDetails details) { + if (isInteractive) { + position + ..curve = Curves.linear + ..reverseCurve = Curves.linear; + final double delta = details.primaryDelta! / _kTrackInnerLength; + switch (Directionality.of(context)) { + case TextDirection.rtl: + _positionController.value -= delta; + case TextDirection.ltr: + _positionController.value += delta; + } + } + } + + void _handleDragEnd(DragEndDetails details) { + // Deferring the animation to the next build phase. + setState(() { needsPositionAnimation = true; }); + // Call onChanged when the user's intent to change value is clear. + if (position.value >= 0.5 != widget.value) { + widget.onChanged!(!widget.value); + } + _reactionController.reverse(); + } + + void _emitVibration() { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + HapticFeedback.lightImpact(); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + break; + } + } + + void _onShowFocusHighlight(bool showHighlight) { + setState(() { isFocused = showHighlight; }); + } + + @override + Widget build(BuildContext context) { + final CupertinoThemeData theme = CupertinoTheme.of(context); + final Color activeColor = CupertinoDynamicColor.resolve( + widget.activeColor + ?? ((widget.applyTheme ?? theme.applyThemeToAll) ? theme.primaryColor : null) + ?? CupertinoColors.systemGreen, + context, + ); + final (Color onLabelColor, Color offLabelColor)? onOffLabelColors = + MediaQuery.onOffSwitchLabelsOf(context) + ? ( + CupertinoDynamicColor.resolve( + widget.onLabelColor ?? CupertinoColors.white, + context, + ), + CupertinoDynamicColor.resolve( + widget.offLabelColor ?? _kOffLabelColor, + context, + ), + ) + : null; + if (needsPositionAnimation) { + _resumePositionAnimation(); + } + return MouseRegion( + cursor: isInteractive && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, + child: Opacity( + opacity: widget.onChanged == null ? _kCupertinoSwitchDisabledOpacity : 1.0, + child: FocusableActionDetector( + onShowFocusHighlight: _onShowFocusHighlight, + actions: _actionMap, + enabled: isInteractive, + focusNode: widget.focusNode, + onFocusChange: widget.onFocusChange, + autofocus: widget.autofocus, + child: _CupertinoSwitchRenderObjectWidget( + value: widget.value, + activeColor: activeColor, + trackColor: CupertinoDynamicColor.resolve(widget.trackColor ?? CupertinoColors.secondarySystemFill, context), + thumbColor: CupertinoDynamicColor.resolve(widget.thumbColor ?? CupertinoColors.white, context), + // Opacity, lightness, and saturation values were approximated with + // color pickers on the switches in the macOS settings. + focusColor: CupertinoDynamicColor.resolve( + widget.focusColor ?? + HSLColor + .fromColor(activeColor.withOpacity(0.80)) + .withLightness(0.69).withSaturation(0.835) + .toColor(), + context), + onChanged: widget.onChanged, + textDirection: Directionality.of(context), + isFocused: isFocused, + state: this, + onOffLabelColors: onOffLabelColors, + ), + ), + ), + ); + } + + @override + void dispose() { + _tap.dispose(); + _drag.dispose(); + + _positionController.dispose(); + _reactionController.dispose(); + super.dispose(); + } +} + +class _CupertinoSwitchRenderObjectWidget extends LeafRenderObjectWidget { + const _CupertinoSwitchRenderObjectWidget({ + required this.value, + required this.activeColor, + required this.trackColor, + required this.thumbColor, + required this.focusColor, + required this.onChanged, + required this.textDirection, + required this.isFocused, + required this.state, + required this.onOffLabelColors, + }); + + final bool value; + final Color activeColor; + final Color trackColor; + final Color thumbColor; + final Color focusColor; + final ValueChanged? onChanged; + final _CupertinoSwitchState state; + final TextDirection textDirection; + final bool isFocused; + final (Color onLabelColor, Color offLabelColor)? onOffLabelColors; + + @override + _RenderCupertinoSwitch createRenderObject(BuildContext context) { + return _RenderCupertinoSwitch( + value: value, + activeColor: activeColor, + trackColor: trackColor, + thumbColor: thumbColor, + focusColor: focusColor, + onChanged: onChanged, + textDirection: textDirection, + isFocused: isFocused, + state: state, + onOffLabelColors: onOffLabelColors, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderCupertinoSwitch renderObject) { + assert(renderObject._state == state); + renderObject + ..value = value + ..activeColor = activeColor + ..trackColor = trackColor + ..thumbColor = thumbColor + ..focusColor = focusColor + ..onChanged = onChanged + ..textDirection = textDirection + ..isFocused = isFocused; + } +} + +const double _kTrackWidth = 51.0; +const double _kTrackHeight = 31.0; +const double _kTrackRadius = _kTrackHeight / 2.0; +const double _kTrackInnerStart = _kTrackHeight / 2.0; +const double _kTrackInnerEnd = _kTrackWidth - _kTrackInnerStart; +const double _kTrackInnerLength = _kTrackInnerEnd - _kTrackInnerStart; +const double _kSwitchWidth = 59.0; +const double _kSwitchHeight = 39.0; +// Label sizes and padding taken from xcode inspector. +// See https://github.com/flutter/flutter/issues/4830#issuecomment-528495360 +const double _kOnLabelWidth = 1.0; +const double _kOnLabelHeight = 10.0; +const double _kOnLabelPaddingHorizontal = 11.0; +const double _kOffLabelWidth = 1.0; +const double _kOffLabelPaddingHorizontal = 12.0; +const double _kOffLabelRadius = 5.0; +const CupertinoDynamicColor _kOffLabelColor = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'offSwitchLabel', + // Source: https://github.com/flutter/flutter/pull/39993#discussion_r321946033 + color: Color.fromARGB(255, 179, 179, 179), + // Source: https://github.com/flutter/flutter/pull/39993#issuecomment-535196665 + darkColor: Color.fromARGB(255, 179, 179, 179), + // Source: https://github.com/flutter/flutter/pull/127776#discussion_r1244208264 + highContrastColor: Color.fromARGB(255, 255, 255, 255), + darkHighContrastColor: Color.fromARGB(255, 255, 255, 255), +); +// Opacity of a disabled switch, as eye-balled from iOS Simulator on Mac. +const double _kCupertinoSwitchDisabledOpacity = 0.5; + +const Duration _kReactionDuration = Duration(milliseconds: 300); +const Duration _kToggleDuration = Duration(milliseconds: 200); + +class _RenderCupertinoSwitch extends RenderConstrainedBox { + _RenderCupertinoSwitch({ + required bool value, + required Color activeColor, + required Color trackColor, + required Color thumbColor, + required Color focusColor, + ValueChanged? onChanged, + required TextDirection textDirection, + required bool isFocused, + required _CupertinoSwitchState state, + required (Color onLabelColor, Color offLabelColor)? onOffLabelColors, + }) : _value = value, + _activeColor = activeColor, + _trackColor = trackColor, + _focusColor = focusColor, + _thumbPainter = CupertinoThumbPainter.switchThumb(color: thumbColor), + _onChanged = onChanged, + _textDirection = textDirection, + _isFocused = isFocused, + _state = state, + _onOffLabelColors = onOffLabelColors, + super(additionalConstraints: const BoxConstraints.tightFor(width: _kSwitchWidth, height: _kSwitchHeight)) { + state.position.addListener(markNeedsPaint); + state._reaction.addListener(markNeedsPaint); + } + + final _CupertinoSwitchState _state; + + bool get value => _value; + bool _value; + set value(bool value) { + if (value == _value) { + return; + } + _value = value; + markNeedsSemanticsUpdate(); + } + + Color get activeColor => _activeColor; + Color _activeColor; + set activeColor(Color value) { + if (value == _activeColor) { + return; + } + _activeColor = value; + markNeedsPaint(); + } + + Color get trackColor => _trackColor; + Color _trackColor; + set trackColor(Color value) { + if (value == _trackColor) { + return; + } + _trackColor = value; + markNeedsPaint(); + } + + Color get thumbColor => _thumbPainter.color; + CupertinoThumbPainter _thumbPainter; + set thumbColor(Color value) { + if (value == thumbColor) { + return; + } + _thumbPainter = CupertinoThumbPainter.switchThumb(color: value); + markNeedsPaint(); + } + + Color get focusColor => _focusColor; + Color _focusColor; + set focusColor(Color value) { + if (value == _focusColor) { + return; + } + _focusColor = value; + markNeedsPaint(); + } + + ValueChanged? get onChanged => _onChanged; + ValueChanged? _onChanged; + set onChanged(ValueChanged? value) { + if (value == _onChanged) { + return; + } + final bool wasInteractive = isInteractive; + _onChanged = value; + if (wasInteractive != isInteractive) { + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsPaint(); + } + + bool get isFocused => _isFocused; + bool _isFocused; + set isFocused(bool value) { + if (value == _isFocused) { + return; + } + _isFocused = value; + markNeedsPaint(); + } + + (Color onLabelColor, Color offLabelColor)? get onOffLabelColors => _onOffLabelColors; + (Color onLabelColor, Color offLabelColor)? _onOffLabelColors; + set onOffLabelColors((Color onLabelColor, Color offLabelColor)? value) { + if (value == _onOffLabelColors) { + return; + } + _onOffLabelColors = value; + markNeedsPaint(); + } + + bool get isInteractive => onChanged != null; + + @override + bool hitTestSelf(Offset position) => true; + + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + assert(debugHandleEvent(event, entry)); + if (event is PointerDownEvent && isInteractive) { + _state._drag.addPointer(event); + _state._tap.addPointer(event); + } + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + + if (isInteractive) { + config.onTap = _state._handleTap; + } + + config.isEnabled = isInteractive; + config.isToggled = _value; + } + + @override + void paint(PaintingContext context, Offset offset) { + final Canvas canvas = context.canvas; + + final double currentValue = _state.position.value; + final double currentReactionValue = _state._reaction.value; + + final double visualPosition; + switch (textDirection) { + case TextDirection.rtl: + visualPosition = 1.0 - currentValue; + case TextDirection.ltr: + visualPosition = currentValue; + } + + final Paint paint = Paint() + ..color = Color.lerp(trackColor, activeColor, currentValue)!; + + final Rect trackRect = Rect.fromLTWH( + offset.dx + (size.width - _kTrackWidth) / 2.0, + offset.dy + (size.height - _kTrackHeight) / 2.0, + _kTrackWidth, + _kTrackHeight, + ); + final RRect trackRRect = RRect.fromRectAndRadius(trackRect, const Radius.circular(_kTrackRadius)); + canvas.drawRRect(trackRRect, paint); + + if (_isFocused) { + // Paints a border around the switch in the focus color. + final RRect borderTrackRRect = trackRRect.inflate(1.75); + + final Paint borderPaint = Paint() + ..color = focusColor + ..style = PaintingStyle.stroke + ..strokeWidth = 3.5; + + canvas.drawRRect(borderTrackRRect, borderPaint); + } + + if (_onOffLabelColors != null) { + final (Color onLabelColor, Color offLabelColor) = onOffLabelColors!; + + final double leftLabelOpacity = visualPosition * (1.0 - currentReactionValue); + final double rightLabelOpacity = (1.0 - visualPosition) * (1.0 - currentReactionValue); + final (double onLabelOpacity, double offLabelOpacity) = + switch (textDirection) { + TextDirection.ltr => (leftLabelOpacity, rightLabelOpacity), + TextDirection.rtl => (rightLabelOpacity, leftLabelOpacity), + }; + + final (Offset onLabelOffset, Offset offLabelOffset) = + switch (textDirection) { + TextDirection.ltr => ( + trackRect.centerLeft.translate(_kOnLabelPaddingHorizontal, 0), + trackRect.centerRight.translate(-_kOffLabelPaddingHorizontal, 0), + ), + TextDirection.rtl => ( + trackRect.centerRight.translate(-_kOnLabelPaddingHorizontal, 0), + trackRect.centerLeft.translate(_kOffLabelPaddingHorizontal, 0), + ), + }; + + // Draws '|' label + final Rect onLabelRect = Rect.fromCenter( + center: onLabelOffset, + width: _kOnLabelWidth, + height: _kOnLabelHeight, + ); + final Paint onLabelPaint = Paint() + ..color = onLabelColor.withOpacity(onLabelOpacity) + ..style = PaintingStyle.fill; + canvas.drawRect(onLabelRect, onLabelPaint); + + // Draws 'O' label + final Paint offLabelPaint = Paint() + ..color = offLabelColor.withOpacity(offLabelOpacity) + ..style = PaintingStyle.stroke + ..strokeWidth = _kOffLabelWidth; + canvas.drawCircle( + offLabelOffset, + _kOffLabelRadius, + offLabelPaint, + ); + } + + final double currentThumbExtension = CupertinoThumbPainter.extension * currentReactionValue; + final double thumbLeft = lerpDouble( + trackRect.left + _kTrackInnerStart - CupertinoThumbPainter.radius, + trackRect.left + _kTrackInnerEnd - CupertinoThumbPainter.radius - currentThumbExtension, + visualPosition, + )!; + final double thumbRight = lerpDouble( + trackRect.left + _kTrackInnerStart + CupertinoThumbPainter.radius + currentThumbExtension, + trackRect.left + _kTrackInnerEnd + CupertinoThumbPainter.radius, + visualPosition, + )!; + final double thumbCenterY = offset.dy + size.height / 2.0; + final Rect thumbBounds = Rect.fromLTRB( + thumbLeft, + thumbCenterY - CupertinoThumbPainter.radius, + thumbRight, + thumbCenterY + CupertinoThumbPainter.radius, + ); + + _clipRRectLayer.layer = context.pushClipRRect(needsCompositing, Offset.zero, thumbBounds, trackRRect, (PaintingContext innerContext, Offset offset) { + _thumbPainter.paint(innerContext.canvas, thumbBounds); + }, oldLayer: _clipRRectLayer.layer); + } + + final LayerHandle _clipRRectLayer = LayerHandle(); + + @override + void dispose() { + _clipRRectLayer.layer = null; + super.dispose(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(FlagProperty('value', value: value, ifTrue: 'checked', ifFalse: 'unchecked', showName: true)); + description.add(FlagProperty('isInteractive', value: isInteractive, ifTrue: 'enabled', ifFalse: 'disabled', showName: true, defaultValue: true)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/tab_scaffold.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/tab_scaffold.dart new file mode 100644 index 0000000000000000000000000000000000000000..8995abfe5d4d2bea87febbc47d2a16f41b9e2688 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/tab_scaffold.dart @@ -0,0 +1,534 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'bottom_tab_bar.dart'; +import 'colors.dart'; +import 'theme.dart'; + +/// Coordinates tab selection between a [CupertinoTabBar] and a [CupertinoTabScaffold]. +/// +/// The [index] property is the index of the selected tab. Changing its value +/// updates the actively displayed tab of the [CupertinoTabScaffold] the +/// [CupertinoTabController] controls, as well as the currently selected tab item of +/// its [CupertinoTabBar]. +/// +/// {@tool snippet} +/// This samples shows how [CupertinoTabController] can be used to switch tabs in +/// [CupertinoTabScaffold]. +/// +/// ** See code in examples/api/lib/cupertino/tab_scaffold/cupertino_tab_controller.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CupertinoTabScaffold], a tabbed application root layout that can be +/// controlled by a [CupertinoTabController]. +/// * [RestorableCupertinoTabController], which is a restorable version +/// of this controller. +class CupertinoTabController extends ChangeNotifier { + /// Creates a [CupertinoTabController] to control the tab index of [CupertinoTabScaffold] + /// and [CupertinoTabBar]. + /// + /// The [initialIndex] defaults to 0. The value must be greater than or equal + /// to 0, and less than the total number of tabs. + CupertinoTabController({ int initialIndex = 0 }) + : _index = initialIndex, + assert(initialIndex >= 0); + + bool _isDisposed = false; + + /// The index of the currently selected tab. + /// + /// Changing the value of [index] updates the actively displayed tab of the + /// [CupertinoTabScaffold] controlled by this [CupertinoTabController], as well + /// as the currently selected tab item of its [CupertinoTabScaffold.tabBar]. + /// + /// The value must be greater than or equal to 0, and less than the total + /// number of tabs. + int get index => _index; + int _index; + set index(int value) { + assert(value >= 0); + if (_index == value) { + return; + } + _index = value; + notifyListeners(); + } + + @mustCallSuper + @override + void dispose() { + super.dispose(); + _isDisposed = true; + } +} + +/// Implements a tabbed iOS application's root layout and behavior structure. +/// +/// The scaffold lays out the tab bar at the bottom and the content between or +/// behind the tab bar. +/// +/// A [tabBar] and a [tabBuilder] are required. The [CupertinoTabScaffold] +/// will automatically listen to the provided [CupertinoTabBar]'s tap callbacks +/// to change the active tab. +/// +/// A [controller] can be used to provide an initially selected tab index and manage +/// subsequent tab changes. If a controller is not specified, the scaffold will +/// create its own [CupertinoTabController] and manage it internally. Otherwise +/// it's up to the owner of [controller] to call `dispose` on it after finish +/// using it. +/// +/// Tabs' contents are built with the provided [tabBuilder] at the active +/// tab index. The [tabBuilder] must be able to build the same number of +/// pages as there are [tabBar] items. Inactive tabs will be moved [Offstage] +/// and their animations disabled. +/// +/// Adding/removing tabs, or changing the order of tabs is supported but not +/// recommended. Doing so is against the iOS human interface guidelines, and +/// [CupertinoTabScaffold] may lose some tabs' state in the process. +/// +/// Use [CupertinoTabView] as the root widget of each tab to support tabs with +/// parallel navigation state and history. Since each [CupertinoTabView] contains +/// a [Navigator], rebuilding the [CupertinoTabView] with a different +/// [WidgetBuilder] instance in [CupertinoTabView.builder] will not recreate +/// the [CupertinoTabView]'s navigation stack or update its UI. To update the +/// contents of the [CupertinoTabView] after it's built, trigger a rebuild +/// (via [State.setState], for instance) from its descendant rather than from +/// its ancestor. +/// +/// {@tool dartpad} +/// A sample code implementing a typical iOS information architecture with tabs. +/// +/// ** See code in examples/api/lib/cupertino/tab_scaffold/cupertino_tab_scaffold.0.dart ** +/// {@end-tool} +/// +/// To push a route above all tabs instead of inside the currently selected one +/// (such as when showing a dialog on top of this scaffold), use +/// `Navigator.of(rootNavigator: true)` from inside the [BuildContext] of a +/// [CupertinoTabView]. +/// +/// See also: +/// +/// * [CupertinoTabBar], the bottom tab bar inserted in the scaffold. +/// * [CupertinoTabController], the selection state of this widget. +/// * [CupertinoTabView], the typical root content of each tab that holds its own +/// [Navigator] stack. +/// * [CupertinoPageRoute], a route hosting modal pages with iOS style transitions. +/// * [CupertinoPageScaffold], typical contents of an iOS modal page implementing +/// layout with a navigation bar on top. +/// * [iOS human interface guidelines](https://developer.apple.com/design/human-interface-guidelines/ios/bars/tab-bars/). +class CupertinoTabScaffold extends StatefulWidget { + /// Creates a layout for applications with a tab bar at the bottom. + CupertinoTabScaffold({ + super.key, + required this.tabBar, + required this.tabBuilder, + this.controller, + this.backgroundColor, + this.resizeToAvoidBottomInset = true, + this.restorationId, + }) : assert( + controller == null || controller.index < tabBar.items.length, + "The CupertinoTabController's current index ${controller.index} is " + 'out of bounds for the tab bar with ${tabBar.items.length} tabs', + ); + + /// The [tabBar] is a [CupertinoTabBar] drawn at the bottom of the screen + /// that lets the user switch between different tabs in the main content area + /// when present. + /// + /// The [CupertinoTabBar.currentIndex] is only used to initialize a + /// [CupertinoTabController] when no [controller] is provided. Subsequently + /// providing a different [CupertinoTabBar.currentIndex] does not affect the + /// scaffold or the tab bar's active tab index. To programmatically change + /// the active tab index, use a [CupertinoTabController]. + /// + /// If [CupertinoTabBar.onTap] is provided, it will still be called. + /// [CupertinoTabScaffold] automatically also listen to the + /// [CupertinoTabBar]'s `onTap` to change the [controller]'s `index` + /// and change the actively displayed tab in [CupertinoTabScaffold]'s own + /// main content area. + /// + /// If translucent, the main content may slide behind it. + /// Otherwise, the main content's bottom margin will be offset by its height. + /// + /// By default [tabBar] disables text scaling to match the native iOS behavior. + /// To override this behavior, wrap each of the [tabBar]'s items inside a + /// [MediaQuery] with the desired [TextScaler]. + final CupertinoTabBar tabBar; + + /// Controls the currently selected tab index of the [tabBar], as well as the + /// active tab index of the [tabBuilder]. Providing a different [controller] + /// will also update the scaffold's current active index to the new controller's + /// index value. + /// + /// Defaults to null. + final CupertinoTabController? controller; + + /// An [IndexedWidgetBuilder] that's called when tabs become active. + /// + /// The widgets built by [IndexedWidgetBuilder] are typically a + /// [CupertinoTabView] in order to achieve the parallel hierarchical + /// information architecture seen on iOS apps with tab bars. + /// + /// When the tab becomes inactive, its content is cached in the widget tree + /// [Offstage] and its animations disabled. + /// + /// Content can slide under the [tabBar] when they're translucent. + /// In that case, the child's [BuildContext]'s [MediaQuery] will have a + /// bottom padding indicating the area of obstructing overlap from the + /// [tabBar]. + final IndexedWidgetBuilder tabBuilder; + + /// The color of the widget that underlies the entire scaffold. + /// + /// By default uses [CupertinoTheme]'s `scaffoldBackgroundColor` when null. + final Color? backgroundColor; + + /// Whether the body should size itself to avoid the window's bottom inset. + /// + /// For example, if there is an onscreen keyboard displayed above the + /// scaffold, the body can be resized to avoid overlapping the keyboard, which + /// prevents widgets inside the body from being obscured by the keyboard. + /// + /// Defaults to true. + final bool resizeToAvoidBottomInset; + + /// Restoration ID to save and restore the state of the [CupertinoTabScaffold]. + /// + /// This property only has an effect when no [controller] has been provided: + /// If it is non-null (and no [controller] has been provided), the scaffold + /// will persist and restore the currently selected tab index. If a + /// [controller] has been provided, it is the responsibility of the owner of + /// that controller to persist and restore it, e.g. by using a + /// [RestorableCupertinoTabController]. + /// + /// The state of this widget is persisted in a [RestorationBucket] claimed + /// from the surrounding [RestorationScope] using the provided restoration ID. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + final String? restorationId; + + @override + State createState() => _CupertinoTabScaffoldState(); +} + +class _CupertinoTabScaffoldState extends State with RestorationMixin { + RestorableCupertinoTabController? _internalController; + CupertinoTabController get _controller => widget.controller ?? _internalController!.value; + + @override + String? get restorationId => widget.restorationId; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + _restoreInternalController(); + } + + void _restoreInternalController() { + if (_internalController != null) { + registerForRestoration(_internalController!, 'controller'); + _internalController!.value.addListener(_onCurrentIndexChange); + } + } + + @override + void initState() { + super.initState(); + _updateTabController(); + } + + void _updateTabController([CupertinoTabController? oldWidgetController]) { + if (widget.controller == null && _internalController == null) { + // No widget-provided controller: create an internal controller. + _internalController = RestorableCupertinoTabController(initialIndex: widget.tabBar.currentIndex); + if (!restorePending) { + _restoreInternalController(); // Also adds the listener to the controller. + } + } + if (widget.controller != null && _internalController != null) { + // Use the widget-provided controller. + unregisterFromRestoration(_internalController!); + _internalController!.dispose(); + _internalController = null; + } + if (oldWidgetController != widget.controller) { + // The widget-provided controller has changed: move listeners. + if (oldWidgetController?._isDisposed == false) { + oldWidgetController!.removeListener(_onCurrentIndexChange); + } + widget.controller?.addListener(_onCurrentIndexChange); + } + } + + void _onCurrentIndexChange() { + assert( + _controller.index >= 0 && _controller.index < widget.tabBar.items.length, + "The $runtimeType's current index ${_controller.index} is " + 'out of bounds for the tab bar with ${widget.tabBar.items.length} tabs', + ); + + // The value of `_controller.index` has already been updated at this point. + // Calling `setState` to rebuild using `_controller.index`. + setState(() {}); + } + + @override + void didUpdateWidget(CupertinoTabScaffold oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.controller != oldWidget.controller) { + _updateTabController(oldWidget.controller); + } else if (_controller.index >= widget.tabBar.items.length) { + // If a new [tabBar] with less than (_controller.index + 1) items is provided, + // clamp the current index. + _controller.index = widget.tabBar.items.length - 1; + } + } + + @override + Widget build(BuildContext context) { + final MediaQueryData existingMediaQuery = MediaQuery.of(context); + MediaQueryData newMediaQuery = MediaQuery.of(context); + + Widget content = _TabSwitchingView( + currentTabIndex: _controller.index, + tabCount: widget.tabBar.items.length, + tabBuilder: widget.tabBuilder, + ); + EdgeInsets contentPadding = EdgeInsets.zero; + + if (widget.resizeToAvoidBottomInset) { + // Remove the view inset and add it back as a padding in the inner content. + newMediaQuery = newMediaQuery.removeViewInsets(removeBottom: true); + contentPadding = EdgeInsets.only(bottom: existingMediaQuery.viewInsets.bottom); + } + + // Only pad the content with the height of the tab bar if the tab + // isn't already entirely obstructed by a keyboard or other view insets. + // Don't double pad. + if (!widget.resizeToAvoidBottomInset || widget.tabBar.preferredSize.height > existingMediaQuery.viewInsets.bottom) { + // TODO(xster): Use real size after partial layout instead of preferred size. + // https://github.com/flutter/flutter/issues/12912 + final double bottomPadding = + widget.tabBar.preferredSize.height + existingMediaQuery.padding.bottom; + + // If tab bar opaque, directly stop the main content higher. If + // translucent, let main content draw behind the tab bar but hint the + // obstructed area. + if (widget.tabBar.opaque(context)) { + contentPadding = EdgeInsets.only(bottom: bottomPadding); + newMediaQuery = newMediaQuery.removePadding(removeBottom: true); + } else { + newMediaQuery = newMediaQuery.copyWith( + padding: newMediaQuery.padding.copyWith( + bottom: bottomPadding, + ), + ); + } + } + + content = MediaQuery( + data: newMediaQuery, + child: Padding( + padding: contentPadding, + child: content, + ), + ); + + return DecoratedBox( + decoration: BoxDecoration( + color: CupertinoDynamicColor.maybeResolve(widget.backgroundColor, context) + ?? CupertinoTheme.of(context).scaffoldBackgroundColor, + ), + child: Stack( + children: [ + // The main content being at the bottom is added to the stack first. + content, + MediaQuery.withNoTextScaling( + child: Align( + alignment: Alignment.bottomCenter, + // Override the tab bar's currentIndex to the current tab and hook in + // our own listener to update the [_controller.currentIndex] on top of a possibly user + // provided callback. + child: widget.tabBar.copyWith( + currentIndex: _controller.index, + onTap: (int newIndex) { + _controller.index = newIndex; + // Chain the user's original callback. + widget.tabBar.onTap?.call(newIndex); + }, + ), + ), + ), + ], + ), + ); + } + + @override + void dispose() { + if (widget.controller?._isDisposed == false) { + _controller.removeListener(_onCurrentIndexChange); + } + _internalController?.dispose(); + super.dispose(); + } +} + +/// A widget laying out multiple tabs with only one active tab being built +/// at a time and on stage. Off stage tabs' animations are stopped. +class _TabSwitchingView extends StatefulWidget { + const _TabSwitchingView({ + required this.currentTabIndex, + required this.tabCount, + required this.tabBuilder, + }) : assert(tabCount > 0); + + final int currentTabIndex; + final int tabCount; + final IndexedWidgetBuilder tabBuilder; + + @override + _TabSwitchingViewState createState() => _TabSwitchingViewState(); +} + +class _TabSwitchingViewState extends State<_TabSwitchingView> { + final List shouldBuildTab = []; + final List tabFocusNodes = []; + + // When focus nodes are no longer needed, we need to dispose of them, but we + // can't be sure that nothing else is listening to them until this widget is + // disposed of, so when they are no longer needed, we move them to this list, + // and dispose of them when we dispose of this widget. + final List discardedNodes = []; + + @override + void initState() { + super.initState(); + shouldBuildTab.addAll(List.filled(widget.tabCount, false)); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _focusActiveTab(); + } + + @override + void didUpdateWidget(_TabSwitchingView oldWidget) { + super.didUpdateWidget(oldWidget); + + // Only partially invalidate the tabs cache to avoid breaking the current + // behavior. We assume that the only possible change is either: + // - new tabs are appended to the tab list, or + // - some trailing tabs are removed. + // If the above assumption is not true, some tabs may lose their state. + final int lengthDiff = widget.tabCount - shouldBuildTab.length; + if (lengthDiff > 0) { + shouldBuildTab.addAll(List.filled(lengthDiff, false)); + } else if (lengthDiff < 0) { + shouldBuildTab.removeRange(widget.tabCount, shouldBuildTab.length); + } + _focusActiveTab(); + } + + // Will focus the active tab if the FocusScope above it has focus already. If + // not, then it will just mark it as the preferred focus for that scope. + void _focusActiveTab() { + if (tabFocusNodes.length != widget.tabCount) { + if (tabFocusNodes.length > widget.tabCount) { + discardedNodes.addAll(tabFocusNodes.sublist(widget.tabCount)); + tabFocusNodes.removeRange(widget.tabCount, tabFocusNodes.length); + } else { + tabFocusNodes.addAll( + List.generate( + widget.tabCount - tabFocusNodes.length, + (int index) => FocusScopeNode(debugLabel: '$CupertinoTabScaffold Tab ${index + tabFocusNodes.length}'), + ), + ); + } + } + FocusScope.of(context).setFirstFocus(tabFocusNodes[widget.currentTabIndex]); + } + + @override + void dispose() { + for (final FocusScopeNode focusScopeNode in tabFocusNodes) { + focusScopeNode.dispose(); + } + for (final FocusScopeNode focusScopeNode in discardedNodes) { + focusScopeNode.dispose(); + } + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Stack( + fit: StackFit.expand, + children: List.generate(widget.tabCount, (int index) { + final bool active = index == widget.currentTabIndex; + shouldBuildTab[index] = active || shouldBuildTab[index]; + + return HeroMode( + enabled: active, + child: Offstage( + offstage: !active, + child: TickerMode( + enabled: active, + child: FocusScope( + node: tabFocusNodes[index], + child: Builder(builder: (BuildContext context) { + return shouldBuildTab[index] ? widget.tabBuilder(context, index) : const SizedBox.shrink(); + }), + ), + ), + ), + ); + }), + ); + } +} + +/// A [RestorableProperty] that knows how to store and restore a +/// [CupertinoTabController]. +/// +/// The [CupertinoTabController] is accessible via the [value] getter. During +/// state restoration, the property will restore [CupertinoTabController.index] +/// to the value it had when the restoration data it is getting restored from +/// was collected. +class RestorableCupertinoTabController extends RestorableChangeNotifier { + /// Creates a [RestorableCupertinoTabController] to control the tab index of + /// [CupertinoTabScaffold] and [CupertinoTabBar]. + /// + /// The `initialIndex` defaults to zero. The value must be greater than or + /// equal to zero, and less than the total number of tabs. + RestorableCupertinoTabController({ int initialIndex = 0 }) + : assert(initialIndex >= 0), + _initialIndex = initialIndex; + + final int _initialIndex; + + @override + CupertinoTabController createDefaultValue() { + return CupertinoTabController(initialIndex: _initialIndex); + } + + @override + CupertinoTabController fromPrimitives(Object? data) { + assert(data != null); + return CupertinoTabController(initialIndex: data! as int); + } + + @override + Object? toPrimitives() { + return value.index; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/tab_view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/tab_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..1d38eb0bf7186b20bc9306b064836f1cde11c92e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/tab_view.dart @@ -0,0 +1,257 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'app.dart' show CupertinoApp; +import 'route.dart'; + +/// A single tab view with its own [Navigator] state and history. +/// +/// A typical tab view is used as the content of each tab in a +/// [CupertinoTabScaffold] where multiple tabs with parallel navigation states +/// and history can co-exist. +/// +/// [CupertinoTabView] configures the top-level [Navigator] to search for routes +/// in the following order: +/// +/// 1. For the `/` route, the [builder] property, if non-null, is used. +/// +/// 2. Otherwise, the [routes] table is used, if it has an entry for the route, +/// including `/` if [builder] is not specified. +/// +/// 3. Otherwise, [onGenerateRoute] is called, if provided. It should return a +/// non-null value for any _valid_ route not handled by [builder] and [routes]. +/// +/// 4. Finally if all else fails [onUnknownRoute] is called. +/// +/// These navigation properties are not shared with any sibling [CupertinoTabView] +/// nor any ancestor or descendant [Navigator] instances. +/// +/// To push a route above this [CupertinoTabView] instead of inside it (such +/// as when showing a dialog on top of all tabs), use +/// `Navigator.of(rootNavigator: true)`. +/// +/// See also: +/// +/// * [CupertinoTabScaffold], a typical host that supports switching between tabs. +/// * [CupertinoPageRoute], a typical modal page route pushed onto the +/// [CupertinoTabView]'s [Navigator]. +class CupertinoTabView extends StatefulWidget { + /// Creates the content area for a tab in a [CupertinoTabScaffold]. + const CupertinoTabView({ + super.key, + this.builder, + this.navigatorKey, + this.defaultTitle, + this.routes, + this.onGenerateRoute, + this.onUnknownRoute, + this.navigatorObservers = const [], + this.restorationScopeId, + }); + + /// The widget builder for the default route of the tab view + /// ([Navigator.defaultRouteName], which is `/`). + /// + /// If a [builder] is specified, then [routes] must not include an entry for `/`, + /// as [builder] takes its place. + /// + /// Rebuilding a [CupertinoTabView] with a different [builder] will not clear + /// its current navigation stack or update its descendant. Instead, trigger a + /// rebuild from a descendant in its subtree. This can be done via methods such + /// as: + /// + /// * Calling [State.setState] on a descendant [StatefulWidget]'s [State] + /// * Modifying an [InheritedWidget] that a descendant registered itself + /// as a dependent to. + final WidgetBuilder? builder; + + /// A key to use when building this widget's [Navigator]. + /// + /// If a [navigatorKey] is specified, the [Navigator] can be directly + /// manipulated without first obtaining it from a [BuildContext] via + /// [Navigator.of]: from the [navigatorKey], use the [GlobalKey.currentState] + /// getter. + /// + /// If this is changed, a new [Navigator] will be created, losing all the + /// tab's state in the process; in that case, the [navigatorObservers] + /// must also be changed, since the previous observers will be attached to the + /// previous navigator. + final GlobalKey? navigatorKey; + + /// The title of the default route. + final String? defaultTitle; + + /// This tab view's routing table. + /// + /// When a named route is pushed with [Navigator.pushNamed] inside this tab view, + /// the route name is looked up in this map. If the name is present, + /// the associated [widgets.WidgetBuilder] is used to construct a + /// [CupertinoPageRoute] that performs an appropriate transition to the new + /// route. + /// + /// If the tab view only has one page, then you can specify it using [builder] instead. + /// + /// If [builder] is specified, then it implies an entry in this table for the + /// [Navigator.defaultRouteName] route (`/`), and it is an error to + /// redundantly provide such a route in the [routes] table. + /// + /// If a route is requested that is not specified in this table (or by + /// [builder]), then the [onGenerateRoute] callback is called to build the page + /// instead. + /// + /// This routing table is not shared with any routing tables of ancestor or + /// descendant [Navigator]s. + final Map? routes; + + /// The route generator callback used when the tab view is navigated to a named route. + /// + /// This is used if [routes] does not contain the requested route. + final RouteFactory? onGenerateRoute; + + /// Called when [onGenerateRoute] also fails to generate a route. + /// + /// This callback is typically used for error handling. For example, this + /// callback might always generate a "not found" page that describes the route + /// that wasn't found. + /// + /// The default implementation pushes a route that displays an ugly error + /// message. + final RouteFactory? onUnknownRoute; + + /// The list of observers for the [Navigator] created in this tab view. + /// + /// This list of observers is not shared with ancestor or descendant [Navigator]s. + final List navigatorObservers; + + /// Restoration ID to save and restore the state of the [Navigator] built by + /// this [CupertinoTabView]. + /// + /// {@macro flutter.widgets.navigator.restorationScopeId} + final String? restorationScopeId; + + @override + State createState() => _CupertinoTabViewState(); +} + +class _CupertinoTabViewState extends State { + late HeroController _heroController; + late List _navigatorObservers; + + @override + void initState() { + super.initState(); + _heroController = CupertinoApp.createCupertinoHeroController(); + _updateObservers(); + } + + @override + void didUpdateWidget(CupertinoTabView oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.navigatorKey != oldWidget.navigatorKey + || widget.navigatorObservers != oldWidget.navigatorObservers) { + _updateObservers(); + } + } + + @override + void dispose() { + _heroController.dispose(); + super.dispose(); + } + + void _updateObservers() { + _navigatorObservers = + List.of(widget.navigatorObservers) + ..add(_heroController); + } + + GlobalKey? _ownedNavigatorKey; + GlobalKey get _navigatorKey { + if (widget.navigatorKey != null) { + return widget.navigatorKey!; + } + _ownedNavigatorKey ??= GlobalKey(); + return _ownedNavigatorKey!; + } + + // Whether this tab is currently the active tab. + bool get _isActive => TickerMode.of(context); + + @override + Widget build(BuildContext context) { + final Widget child = Navigator( + key: _navigatorKey, + onGenerateRoute: _onGenerateRoute, + onUnknownRoute: _onUnknownRoute, + observers: _navigatorObservers, + restorationScopeId: widget.restorationScopeId, + ); + + // Handle system back gestures only if the tab is currently active. + return NavigatorPopHandler( + enabled: _isActive, + onPop: () { + if (!_isActive) { + return; + } + _navigatorKey.currentState!.pop(); + }, + child: child, + ); + } + + Route? _onGenerateRoute(RouteSettings settings) { + final String? name = settings.name; + final WidgetBuilder? routeBuilder; + String? title; + if (name == Navigator.defaultRouteName && widget.builder != null) { + routeBuilder = widget.builder; + title = widget.defaultTitle; + } else { + routeBuilder = widget.routes?[name]; + } + if (routeBuilder != null) { + return CupertinoPageRoute( + builder: routeBuilder, + title: title, + settings: settings, + ); + } + return widget.onGenerateRoute?.call(settings); + } + + Route? _onUnknownRoute(RouteSettings settings) { + assert(() { + if (widget.onUnknownRoute == null) { + throw FlutterError( + 'Could not find a generator for route $settings in the $runtimeType.\n' + 'Generators for routes are searched for in the following order:\n' + ' 1. For the "/" route, the "builder" property, if non-null, is used.\n' + ' 2. Otherwise, the "routes" table is used, if it has an entry for ' + 'the route.\n' + ' 3. Otherwise, onGenerateRoute is called. It should return a ' + 'non-null value for any valid route not handled by "builder" and "routes".\n' + ' 4. Finally if all else fails onUnknownRoute is called.\n' + 'Unfortunately, onUnknownRoute was not set.', + ); + } + return true; + }()); + final Route? result = widget.onUnknownRoute!(settings); + assert(() { + if (result == null) { + throw FlutterError( + 'The onUnknownRoute callback returned null.\n' + 'When the $runtimeType requested the route $settings from its ' + 'onUnknownRoute callback, the callback returned null. Such callbacks ' + 'must never return null.', + ); + } + return true; + }()); + return result; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_field.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_field.dart new file mode 100644 index 0000000000000000000000000000000000000000..7a6756a648418dd5f63c66860960da7187e7ce61 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_field.dart @@ -0,0 +1,1450 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle; + +import 'package:flutter/foundation.dart' show defaultTargetPlatform; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'adaptive_text_selection_toolbar.dart'; +import 'colors.dart'; +import 'desktop_text_selection.dart'; +import 'icons.dart'; +import 'localizations.dart'; +import 'magnifier.dart'; +import 'spell_check_suggestions_toolbar.dart'; +import 'text_selection.dart'; +import 'theme.dart'; + +export 'package:flutter/services.dart' show SmartDashesType, SmartQuotesType, TextCapitalization, TextInputAction, TextInputType; + +const TextStyle _kDefaultPlaceholderStyle = TextStyle( + fontWeight: FontWeight.w400, + color: CupertinoColors.placeholderText, +); + +// Value inspected from Xcode 11 & iOS 13.0 Simulator. +const BorderSide _kDefaultRoundedBorderSide = BorderSide( + color: CupertinoDynamicColor.withBrightness( + color: Color(0x33000000), + darkColor: Color(0x33FFFFFF), + ), + width: 0.0, +); +const Border _kDefaultRoundedBorder = Border( + top: _kDefaultRoundedBorderSide, + bottom: _kDefaultRoundedBorderSide, + left: _kDefaultRoundedBorderSide, + right: _kDefaultRoundedBorderSide, +); + +const BoxDecoration _kDefaultRoundedBorderDecoration = BoxDecoration( + color: CupertinoDynamicColor.withBrightness( + color: CupertinoColors.white, + darkColor: CupertinoColors.black, + ), + border: _kDefaultRoundedBorder, + borderRadius: BorderRadius.all(Radius.circular(5.0)), +); + +const Color _kDisabledBackground = CupertinoDynamicColor.withBrightness( + color: Color(0xFFFAFAFA), + darkColor: Color(0xFF050505), +); + +// Value inspected from Xcode 12 & iOS 14.0 Simulator. +// Note it may not be consistent with https://developer.apple.com/design/resources/. +const CupertinoDynamicColor _kClearButtonColor = CupertinoDynamicColor.withBrightness( + color: Color(0x33000000), + darkColor: Color(0x33FFFFFF), +); + +// An eyeballed value that moves the cursor slightly left of where it is +// rendered for text on Android so it's positioning more accurately matches the +// native iOS text cursor positioning. +// +// This value is in device pixels, not logical pixels as is typically used +// throughout the codebase. +const int _iOSHorizontalCursorOffsetPixels = -2; + +/// Visibility of text field overlays based on the state of the current text entry. +/// +/// Used to toggle the visibility behavior of the optional decorating widgets +/// surrounding the [EditableText] such as the clear text button. +enum OverlayVisibilityMode { + /// Overlay will never appear regardless of the text entry state. + never, + + /// Overlay will only appear when the current text entry is not empty. + /// + /// This includes prefilled text that the user did not type in manually. But + /// does not include text in placeholders. + editing, + + /// Overlay will only appear when the current text entry is empty. + /// + /// This also includes not having prefilled text that the user did not type + /// in manually. Texts in placeholders are ignored. + notEditing, + + /// Always show the overlay regardless of the text entry state. + always, +} + +class _CupertinoTextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDetectorBuilder { + _CupertinoTextFieldSelectionGestureDetectorBuilder({ + required _CupertinoTextFieldState state, + }) : _state = state, + super(delegate: state); + + final _CupertinoTextFieldState _state; + + @override + void onSingleTapUp(TapDragUpDetails details) { + // Because TextSelectionGestureDetector listens to taps that happen on + // widgets in front of it, tapping the clear button will also trigger + // this handler. If the clear button widget recognizes the up event, + // then do not handle it. + if (_state._clearGlobalKey.currentContext != null) { + final RenderBox renderBox = _state._clearGlobalKey.currentContext!.findRenderObject()! as RenderBox; + final Offset localOffset = renderBox.globalToLocal(details.globalPosition); + if (renderBox.hitTest(BoxHitTestResult(), position: localOffset)) { + return; + } + } + super.onSingleTapUp(details); + _state._requestKeyboard(); + _state.widget.onTap?.call(); + } + + @override + void onDragSelectionEnd(TapDragEndDetails details) { + _state._requestKeyboard(); + super.onDragSelectionEnd(details); + } +} + +/// An iOS-style text field. +/// +/// A text field lets the user enter text, either with a hardware keyboard or with +/// an onscreen keyboard. +/// +/// This widget corresponds to both a `UITextField` and an editable `UITextView` +/// on iOS. +/// +/// The text field calls the [onChanged] callback whenever the user changes the +/// text in the field. If the user indicates that they are done typing in the +/// field (e.g., by pressing a button on the soft keyboard), the text field +/// calls the [onSubmitted] callback. +/// +/// {@macro flutter.widgets.EditableText.onChanged} +/// +/// {@tool dartpad} +/// This example shows how to set the initial value of the [CupertinoTextField] using +/// a [controller] that already contains some text. +/// +/// ** See code in examples/api/lib/cupertino/text_field/cupertino_text_field.0.dart ** +/// {@end-tool} +/// +/// The [controller] can also control the selection and composing region (and to +/// observe changes to the text, selection, and composing region). +/// +/// The text field has an overridable [decoration] that, by default, draws a +/// rounded rectangle border around the text field. If you set the [decoration] +/// property to null, the decoration will be removed entirely. +/// +/// {@macro flutter.material.textfield.wantKeepAlive} +/// +/// Remember to call [TextEditingController.dispose] when it is no longer +/// needed. This will ensure we discard any resources used by the object. +/// +/// {@macro flutter.widgets.editableText.showCaretOnScreen} +/// +/// See also: +/// +/// * +/// * [TextField], an alternative text field widget that follows the Material +/// Design UI conventions. +/// * [EditableText], which is the raw text editing control at the heart of a +/// [TextField]. +/// * Learn how to use a [TextEditingController] in one of our [cookbook recipes](https://flutter.dev/docs/cookbook/forms/text-field-changes#2-use-a-texteditingcontroller). +/// * +class CupertinoTextField extends StatefulWidget { + /// Creates an iOS-style text field. + /// + /// To provide a prefilled text entry, pass in a [TextEditingController] with + /// an initial value to the [controller] parameter. + /// + /// To provide a hint placeholder text that appears when the text entry is + /// empty, pass a [String] to the [placeholder] parameter. + /// + /// The [maxLines] property can be set to null to remove the restriction on + /// the number of lines. In this mode, the intrinsic height of the widget will + /// grow as the number of lines of text grows. By default, it is `1`, meaning + /// this is a single-line text field and will scroll horizontally when + /// it overflows. [maxLines] must not be zero. + /// + /// The text cursor is not shown if [showCursor] is false or if [showCursor] + /// is null (the default) and [readOnly] is true. + /// + /// If specified, the [maxLength] property must be greater than zero. + /// + /// The [selectionHeightStyle] and [selectionWidthStyle] properties allow + /// changing the shape of the selection highlighting. These properties default + /// to [ui.BoxHeightStyle.tight] and [ui.BoxWidthStyle.tight], respectively. + /// + /// The [autocorrect], [autofocus], [clearButtonMode], [dragStartBehavior], + /// [expands], [obscureText], [prefixMode], [readOnly], [scrollPadding], + /// [suffixMode], [textAlign], [selectionHeightStyle], [selectionWidthStyle], + /// [enableSuggestions], and [enableIMEPersonalizedLearning] properties must + /// not be null. + /// + /// {@macro flutter.widgets.editableText.accessibility} + /// + /// See also: + /// + /// * [minLines], which is the minimum number of lines to occupy when the + /// content spans fewer lines. + /// * [expands], to allow the widget to size itself to its parent's height. + /// * [maxLength], which discusses the precise meaning of "number of + /// characters" and how it may differ from the intuitive meaning. + const CupertinoTextField({ + super.key, + this.controller, + this.focusNode, + this.undoController, + this.decoration = _kDefaultRoundedBorderDecoration, + this.padding = const EdgeInsets.all(7.0), + this.placeholder, + this.placeholderStyle = const TextStyle( + fontWeight: FontWeight.w400, + color: CupertinoColors.placeholderText, + ), + this.prefix, + this.prefixMode = OverlayVisibilityMode.always, + this.suffix, + this.suffixMode = OverlayVisibilityMode.always, + this.clearButtonMode = OverlayVisibilityMode.never, + this.clearButtonSemanticLabel, + TextInputType? keyboardType, + this.textInputAction, + this.textCapitalization = TextCapitalization.none, + this.style, + this.strutStyle, + this.textAlign = TextAlign.start, + this.textAlignVertical, + this.textDirection, + this.readOnly = false, + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + this.toolbarOptions, + this.showCursor, + this.autofocus = false, + this.obscuringCharacter = '•', + this.obscureText = false, + this.autocorrect = true, + SmartDashesType? smartDashesType, + SmartQuotesType? smartQuotesType, + this.enableSuggestions = true, + this.maxLines = 1, + this.minLines, + this.expands = false, + this.maxLength, + this.maxLengthEnforcement, + this.onChanged, + this.onEditingComplete, + this.onSubmitted, + this.onTapOutside, + this.inputFormatters, + this.enabled = true, + this.cursorWidth = 2.0, + this.cursorHeight, + this.cursorRadius = const Radius.circular(2.0), + this.cursorOpacityAnimates = true, + this.cursorColor, + this.selectionHeightStyle = ui.BoxHeightStyle.tight, + this.selectionWidthStyle = ui.BoxWidthStyle.tight, + this.keyboardAppearance, + this.scrollPadding = const EdgeInsets.all(20.0), + this.dragStartBehavior = DragStartBehavior.start, + bool? enableInteractiveSelection, + this.selectionControls, + this.onTap, + this.scrollController, + this.scrollPhysics, + this.autofillHints = const [], + this.contentInsertionConfiguration, + this.clipBehavior = Clip.hardEdge, + this.restorationId, + this.scribbleEnabled = true, + this.enableIMEPersonalizedLearning = true, + this.contextMenuBuilder = _defaultContextMenuBuilder, + this.spellCheckConfiguration, + this.magnifierConfiguration, + }) : assert(obscuringCharacter.length == 1), + smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), + smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), + assert(maxLines == null || maxLines > 0), + assert(minLines == null || minLines > 0), + assert( + (maxLines == null) || (minLines == null) || (maxLines >= minLines), + "minLines can't be greater than maxLines", + ), + assert( + !expands || (maxLines == null && minLines == null), + 'minLines and maxLines must be null when expands is true.', + ), + assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'), + assert(maxLength == null || maxLength > 0), + // Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set. + assert( + !identical(textInputAction, TextInputAction.newline) || + maxLines == 1 || + !identical(keyboardType, TextInputType.text), + 'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.', + ), + keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline), + enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText); + + /// Creates a borderless iOS-style text field. + /// + /// To provide a prefilled text entry, pass in a [TextEditingController] with + /// an initial value to the [controller] parameter. + /// + /// To provide a hint placeholder text that appears when the text entry is + /// empty, pass a [String] to the [placeholder] parameter. + /// + /// The [maxLines] property can be set to null to remove the restriction on + /// the number of lines. In this mode, the intrinsic height of the widget will + /// grow as the number of lines of text grows. By default, it is `1`, meaning + /// this is a single-line text field and will scroll horizontally when + /// it overflows. [maxLines] must not be zero. + /// + /// The text cursor is not shown if [showCursor] is false or if [showCursor] + /// is null (the default) and [readOnly] is true. + /// + /// If specified, the [maxLength] property must be greater than zero. + /// + /// The [selectionHeightStyle] and [selectionWidthStyle] properties allow + /// changing the shape of the selection highlighting. These properties default + /// to [ui.BoxHeightStyle.tight] and [ui.BoxWidthStyle.tight] respectively. + /// + /// See also: + /// + /// * [minLines], which is the minimum number of lines to occupy when the + /// content spans fewer lines. + /// * [expands], to allow the widget to size itself to its parent's height. + /// * [maxLength], which discusses the precise meaning of "number of + /// characters" and how it may differ from the intuitive meaning. + const CupertinoTextField.borderless({ + super.key, + this.controller, + this.focusNode, + this.undoController, + this.decoration, + this.padding = const EdgeInsets.all(7.0), + this.placeholder, + this.placeholderStyle = _kDefaultPlaceholderStyle, + this.prefix, + this.prefixMode = OverlayVisibilityMode.always, + this.suffix, + this.suffixMode = OverlayVisibilityMode.always, + this.clearButtonMode = OverlayVisibilityMode.never, + this.clearButtonSemanticLabel, + TextInputType? keyboardType, + this.textInputAction, + this.textCapitalization = TextCapitalization.none, + this.style, + this.strutStyle, + this.textAlign = TextAlign.start, + this.textAlignVertical, + this.textDirection, + this.readOnly = false, + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + this.toolbarOptions, + this.showCursor, + this.autofocus = false, + this.obscuringCharacter = '•', + this.obscureText = false, + this.autocorrect = true, + SmartDashesType? smartDashesType, + SmartQuotesType? smartQuotesType, + this.enableSuggestions = true, + this.maxLines = 1, + this.minLines, + this.expands = false, + this.maxLength, + this.maxLengthEnforcement, + this.onChanged, + this.onEditingComplete, + this.onSubmitted, + this.onTapOutside, + this.inputFormatters, + this.enabled = true, + this.cursorWidth = 2.0, + this.cursorHeight, + this.cursorRadius = const Radius.circular(2.0), + this.cursorOpacityAnimates = true, + this.cursorColor, + this.selectionHeightStyle = ui.BoxHeightStyle.tight, + this.selectionWidthStyle = ui.BoxWidthStyle.tight, + this.keyboardAppearance, + this.scrollPadding = const EdgeInsets.all(20.0), + this.dragStartBehavior = DragStartBehavior.start, + bool? enableInteractiveSelection, + this.selectionControls, + this.onTap, + this.scrollController, + this.scrollPhysics, + this.autofillHints = const [], + this.contentInsertionConfiguration, + this.clipBehavior = Clip.hardEdge, + this.restorationId, + this.scribbleEnabled = true, + this.enableIMEPersonalizedLearning = true, + this.contextMenuBuilder = _defaultContextMenuBuilder, + this.spellCheckConfiguration, + this.magnifierConfiguration, + }) : assert(obscuringCharacter.length == 1), + smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), + smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), + assert(maxLines == null || maxLines > 0), + assert(minLines == null || minLines > 0), + assert( + (maxLines == null) || (minLines == null) || (maxLines >= minLines), + "minLines can't be greater than maxLines", + ), + assert( + !expands || (maxLines == null && minLines == null), + 'minLines and maxLines must be null when expands is true.', + ), + assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'), + assert(maxLength == null || maxLength > 0), + // Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set. + assert( + !identical(textInputAction, TextInputAction.newline) || + maxLines == 1 || + !identical(keyboardType, TextInputType.text), + 'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.', + ), + keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline), + enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText); + + /// Controls the text being edited. + /// + /// If null, this widget will create its own [TextEditingController]. + final TextEditingController? controller; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// Controls the [BoxDecoration] of the box behind the text input. + /// + /// Defaults to having a rounded rectangle grey border and can be null to have + /// no box decoration. + final BoxDecoration? decoration; + + /// Padding around the text entry area between the [prefix] and [suffix] + /// or the clear button when [clearButtonMode] is not never. + /// + /// Defaults to a padding of 6 pixels on all sides and can be null. + final EdgeInsetsGeometry padding; + + /// A lighter colored placeholder hint that appears on the first line of the + /// text field when the text entry is empty. + /// + /// Defaults to having no placeholder text. + /// + /// The text style of the placeholder text matches that of the text field's + /// main text entry except a lighter font weight and a grey font color. + final String? placeholder; + + /// The style to use for the placeholder text. + /// + /// The [placeholderStyle] is merged with the [style] [TextStyle] when applied + /// to the [placeholder] text. To avoid merging with [style], specify + /// [TextStyle.inherit] as false. + /// + /// Defaults to the [style] property with w300 font weight and grey color. + /// + /// If specifically set to null, placeholder's style will be the same as [style]. + final TextStyle? placeholderStyle; + + /// An optional [Widget] to display before the text. + final Widget? prefix; + + /// Controls the visibility of the [prefix] widget based on the state of + /// text entry when the [prefix] argument is not null. + /// + /// Defaults to [OverlayVisibilityMode.always]. + /// + /// Has no effect when [prefix] is null. + final OverlayVisibilityMode prefixMode; + + /// An optional [Widget] to display after the text. + final Widget? suffix; + + /// Controls the visibility of the [suffix] widget based on the state of + /// text entry when the [suffix] argument is not null. + /// + /// Defaults to [OverlayVisibilityMode.always]. + /// + /// Has no effect when [suffix] is null. + final OverlayVisibilityMode suffixMode; + + /// Show an iOS-style clear button to clear the current text entry. + /// + /// Can be made to appear depending on various text states of the + /// [TextEditingController]. + /// + /// Will only appear if no [suffix] widget is appearing. + /// + /// Defaults to [OverlayVisibilityMode.never]. + final OverlayVisibilityMode clearButtonMode; + + /// The semantic label for the clear button used by screen readers. + /// + /// This will be used by screen reading software to identify the clear button + /// widget. Defaults to "Clear". + final String? clearButtonSemanticLabel; + + /// {@macro flutter.widgets.editableText.keyboardType} + final TextInputType keyboardType; + + /// The type of action button to use for the keyboard. + /// + /// Defaults to [TextInputAction.newline] if [keyboardType] is + /// [TextInputType.multiline] and [TextInputAction.done] otherwise. + final TextInputAction? textInputAction; + + /// {@macro flutter.widgets.editableText.textCapitalization} + final TextCapitalization textCapitalization; + + /// The style to use for the text being edited. + /// + /// Also serves as a base for the [placeholder] text's style. + /// + /// Defaults to the standard iOS font style from [CupertinoTheme] if null. + final TextStyle? style; + + /// {@macro flutter.widgets.editableText.strutStyle} + final StrutStyle? strutStyle; + + /// {@macro flutter.widgets.editableText.textAlign} + final TextAlign textAlign; + + /// Configuration of toolbar options. + /// + /// If not set, select all and paste will default to be enabled. Copy and cut + /// will be disabled if [obscureText] is true. If [readOnly] is true, + /// paste and cut will be disabled regardless. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + final ToolbarOptions? toolbarOptions; + + /// {@macro flutter.material.InputDecorator.textAlignVertical} + final TextAlignVertical? textAlignVertical; + + /// {@macro flutter.widgets.editableText.textDirection} + final TextDirection? textDirection; + + /// {@macro flutter.widgets.editableText.readOnly} + final bool readOnly; + + /// {@macro flutter.widgets.editableText.showCursor} + final bool? showCursor; + + /// {@macro flutter.widgets.editableText.autofocus} + final bool autofocus; + + /// {@macro flutter.widgets.editableText.obscuringCharacter} + final String obscuringCharacter; + + /// {@macro flutter.widgets.editableText.obscureText} + final bool obscureText; + + /// {@macro flutter.widgets.editableText.autocorrect} + final bool autocorrect; + + /// {@macro flutter.services.TextInputConfiguration.smartDashesType} + final SmartDashesType smartDashesType; + + /// {@macro flutter.services.TextInputConfiguration.smartQuotesType} + final SmartQuotesType smartQuotesType; + + /// {@macro flutter.services.TextInputConfiguration.enableSuggestions} + final bool enableSuggestions; + + /// {@macro flutter.widgets.editableText.maxLines} + /// * [expands], which determines whether the field should fill the height of + /// its parent. + final int? maxLines; + + /// {@macro flutter.widgets.editableText.minLines} + /// * [expands], which determines whether the field should fill the height of + /// its parent. + final int? minLines; + + /// {@macro flutter.widgets.editableText.expands} + final bool expands; + + /// The maximum number of characters (Unicode grapheme clusters) to allow in + /// the text field. + /// + /// After [maxLength] characters have been input, additional input + /// is ignored, unless [maxLengthEnforcement] is set to + /// [MaxLengthEnforcement.none]. + /// + /// The TextField enforces the length with a + /// [LengthLimitingTextInputFormatter], which is evaluated after the supplied + /// [inputFormatters], if any. + /// + /// This value must be either null or greater than zero. If set to null + /// (the default), there is no limit to the number of characters allowed. + /// + /// Whitespace characters (e.g. newline, space, tab) are included in the + /// character count. + /// + /// {@macro flutter.services.lengthLimitingTextInputFormatter.maxLength} + final int? maxLength; + + /// Determines how the [maxLength] limit should be enforced. + /// + /// If [MaxLengthEnforcement.none] is set, additional input beyond [maxLength] + /// will not be enforced by the limit. + /// + /// {@macro flutter.services.textFormatter.effectiveMaxLengthEnforcement} + /// + /// {@macro flutter.services.textFormatter.maxLengthEnforcement} + final MaxLengthEnforcement? maxLengthEnforcement; + + /// {@macro flutter.widgets.editableText.onChanged} + final ValueChanged? onChanged; + + /// {@macro flutter.widgets.editableText.onEditingComplete} + final VoidCallback? onEditingComplete; + + /// {@macro flutter.widgets.editableText.onSubmitted} + /// + /// See also: + /// + /// * [TextInputAction.next] and [TextInputAction.previous], which + /// automatically shift the focus to the next/previous focusable item when + /// the user is done editing. + final ValueChanged? onSubmitted; + + /// {@macro flutter.widgets.editableText.onTapOutside} + final TapRegionCallback? onTapOutside; + + /// {@macro flutter.widgets.editableText.inputFormatters} + final List? inputFormatters; + + /// Disables the text field when false. + /// + /// Text fields in disabled states have a light grey background and don't + /// respond to touch events including the [prefix], [suffix] and the clear + /// button. + /// + /// Defaults to true. + final bool enabled; + + /// {@macro flutter.widgets.editableText.cursorWidth} + final double cursorWidth; + + /// {@macro flutter.widgets.editableText.cursorHeight} + final double? cursorHeight; + + /// {@macro flutter.widgets.editableText.cursorRadius} + final Radius cursorRadius; + + /// {@macro flutter.widgets.editableText.cursorOpacityAnimates} + final bool cursorOpacityAnimates; + + /// The color to use when painting the cursor. + /// + /// Defaults to the [DefaultSelectionStyle.cursorColor]. If that color is + /// null, it uses the [CupertinoThemeData.primaryColor] of the ambient theme, + /// which itself defaults to [CupertinoColors.activeBlue] in the light theme + /// and [CupertinoColors.activeOrange] in the dark theme. + final Color? cursorColor; + + /// Controls how tall the selection highlight boxes are computed to be. + /// + /// See [ui.BoxHeightStyle] for details on available styles. + final ui.BoxHeightStyle selectionHeightStyle; + + /// Controls how wide the selection highlight boxes are computed to be. + /// + /// See [ui.BoxWidthStyle] for details on available styles. + final ui.BoxWidthStyle selectionWidthStyle; + + /// The appearance of the keyboard. + /// + /// This setting is only honored on iOS devices. + /// + /// If null, defaults to [Brightness.light]. + final Brightness? keyboardAppearance; + + /// {@macro flutter.widgets.editableText.scrollPadding} + final EdgeInsets scrollPadding; + + /// {@macro flutter.widgets.editableText.enableInteractiveSelection} + final bool enableInteractiveSelection; + + /// {@macro flutter.widgets.editableText.selectionControls} + final TextSelectionControls? selectionControls; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@macro flutter.widgets.editableText.scrollController} + final ScrollController? scrollController; + + /// {@macro flutter.widgets.editableText.scrollPhysics} + final ScrollPhysics? scrollPhysics; + + /// {@macro flutter.widgets.editableText.selectionEnabled} + bool get selectionEnabled => enableInteractiveSelection; + + /// {@macro flutter.material.textfield.onTap} + final GestureTapCallback? onTap; + + /// {@macro flutter.widgets.editableText.autofillHints} + /// {@macro flutter.services.AutofillConfiguration.autofillHints} + final Iterable? autofillHints; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// {@macro flutter.material.textfield.restorationId} + final String? restorationId; + + /// {@macro flutter.widgets.editableText.scribbleEnabled} + final bool scribbleEnabled; + + /// {@macro flutter.services.TextInputConfiguration.enableIMEPersonalizedLearning} + final bool enableIMEPersonalizedLearning; + + /// {@macro flutter.widgets.editableText.contentInsertionConfiguration} + final ContentInsertionConfiguration? contentInsertionConfiguration; + + /// {@macro flutter.widgets.EditableText.contextMenuBuilder} + /// + /// If not provided, will build a default menu based on the platform. + /// + /// See also: + /// + /// * [CupertinoAdaptiveTextSelectionToolbar], which is built by default. + final EditableTextContextMenuBuilder? contextMenuBuilder; + + static Widget _defaultContextMenuBuilder(BuildContext context, EditableTextState editableTextState) { + return CupertinoAdaptiveTextSelectionToolbar.editableText( + editableTextState: editableTextState, + ); + } + + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.intro} + /// + /// {@macro flutter.widgets.magnifier.intro} + /// + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.details} + /// + /// By default, builds a [CupertinoTextMagnifier] on iOS and Android nothing on all other + /// platforms. If it is desired to suppress the magnifier, consider passing + /// [TextMagnifierConfiguration.disabled]. + /// + /// {@tool dartpad} + /// This sample demonstrates how to customize the magnifier that this text field uses. + /// + /// ** See code in examples/api/lib/widgets/text_magnifier/text_magnifier.0.dart ** + /// {@end-tool} + final TextMagnifierConfiguration? magnifierConfiguration; + + /// {@macro flutter.widgets.EditableText.spellCheckConfiguration} + /// + /// If [SpellCheckConfiguration.misspelledTextStyle] is not specified in this + /// configuration, then [cupertinoMisspelledTextStyle] is used by default. + final SpellCheckConfiguration? spellCheckConfiguration; + + /// The [TextStyle] used to indicate misspelled words in the Cupertino style. + /// + /// See also: + /// * [SpellCheckConfiguration.misspelledTextStyle], the style configured to + /// mark misspelled words with. + /// * [TextField.materialMisspelledTextStyle], the style configured + /// to mark misspelled words with in the Material style. + static const TextStyle cupertinoMisspelledTextStyle = + TextStyle( + decoration: TextDecoration.underline, + decorationColor: CupertinoColors.systemRed, + decorationStyle: TextDecorationStyle.dotted, + ); + + /// The color of the selection highlight when the spell check menu is visible. + /// + /// Eyeballed from a screenshot taken on an iPhone 11 running iOS 16.2. + @visibleForTesting + static const Color kMisspelledSelectionColor = Color(0x62ff9699); + + /// Default builder for the spell check suggestions toolbar in the Cupertino + /// style. + /// + /// See also: + /// * [spellCheckConfiguration], where this is typically specified for + /// [CupertinoTextField]. + /// * [SpellCheckConfiguration.spellCheckSuggestionsToolbarBuilder], the + /// parameter for which this is the default value for [CupertinoTextField]. + /// * [TextField.defaultSpellCheckSuggestionsToolbarBuilder], which is like + /// this but specifies the default for [CupertinoTextField]. + @visibleForTesting + static Widget defaultSpellCheckSuggestionsToolbarBuilder( + BuildContext context, + EditableTextState editableTextState, + ) { + return CupertinoSpellCheckSuggestionsToolbar.editableText( + editableTextState: editableTextState, + ); + } + + /// {@macro flutter.widgets.undoHistory.controller} + final UndoHistoryController? undoController; + + @override + State createState() => _CupertinoTextFieldState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('controller', controller, defaultValue: null)); + properties.add(DiagnosticsProperty('focusNode', focusNode, defaultValue: null)); + properties.add(DiagnosticsProperty('undoController', undoController, defaultValue: null)); + properties.add(DiagnosticsProperty('decoration', decoration)); + properties.add(DiagnosticsProperty('padding', padding)); + properties.add(StringProperty('placeholder', placeholder)); + properties.add(DiagnosticsProperty('placeholderStyle', placeholderStyle)); + properties.add(DiagnosticsProperty('prefix', prefix == null ? null : prefixMode)); + properties.add(DiagnosticsProperty('suffix', suffix == null ? null : suffixMode)); + properties.add(DiagnosticsProperty('clearButtonMode', clearButtonMode)); + properties.add(DiagnosticsProperty('clearButtonSemanticLabel', clearButtonSemanticLabel)); + properties.add(DiagnosticsProperty('keyboardType', keyboardType, defaultValue: TextInputType.text)); + properties.add(DiagnosticsProperty('style', style, defaultValue: null)); + properties.add(DiagnosticsProperty('autofocus', autofocus, defaultValue: false)); + properties.add(DiagnosticsProperty('obscuringCharacter', obscuringCharacter, defaultValue: '•')); + properties.add(DiagnosticsProperty('obscureText', obscureText, defaultValue: false)); + properties.add(DiagnosticsProperty('autocorrect', autocorrect, defaultValue: true)); + properties.add(EnumProperty('smartDashesType', smartDashesType, defaultValue: obscureText ? SmartDashesType.disabled : SmartDashesType.enabled)); + properties.add(EnumProperty('smartQuotesType', smartQuotesType, defaultValue: obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled)); + properties.add(DiagnosticsProperty('enableSuggestions', enableSuggestions, defaultValue: true)); + properties.add(IntProperty('maxLines', maxLines, defaultValue: 1)); + properties.add(IntProperty('minLines', minLines, defaultValue: null)); + properties.add(DiagnosticsProperty('expands', expands, defaultValue: false)); + properties.add(IntProperty('maxLength', maxLength, defaultValue: null)); + properties.add(EnumProperty('maxLengthEnforcement', maxLengthEnforcement, defaultValue: null)); + properties.add(DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0)); + properties.add(DoubleProperty('cursorHeight', cursorHeight, defaultValue: null)); + properties.add(DiagnosticsProperty('cursorRadius', cursorRadius, defaultValue: null)); + properties.add(DiagnosticsProperty('cursorOpacityAnimates', cursorOpacityAnimates, defaultValue: true)); + properties.add(createCupertinoColorProperty('cursorColor', cursorColor, defaultValue: null)); + properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); + properties.add(DiagnosticsProperty('selectionControls', selectionControls, defaultValue: null)); + properties.add(DiagnosticsProperty('scrollController', scrollController, defaultValue: null)); + properties.add(DiagnosticsProperty('scrollPhysics', scrollPhysics, defaultValue: null)); + properties.add(EnumProperty('textAlign', textAlign, defaultValue: TextAlign.start)); + properties.add(DiagnosticsProperty('textAlignVertical', textAlignVertical, defaultValue: null)); + properties.add(EnumProperty('textDirection', textDirection, defaultValue: null)); + properties.add(DiagnosticsProperty('clipBehavior', clipBehavior, defaultValue: Clip.hardEdge)); + properties.add(DiagnosticsProperty('scribbleEnabled', scribbleEnabled, defaultValue: true)); + properties.add(DiagnosticsProperty('enableIMEPersonalizedLearning', enableIMEPersonalizedLearning, defaultValue: true)); + properties.add(DiagnosticsProperty('spellCheckConfiguration', spellCheckConfiguration, defaultValue: null)); + properties.add(DiagnosticsProperty>('contentCommitMimeTypes', contentInsertionConfiguration?.allowedMimeTypes ?? const [], defaultValue: contentInsertionConfiguration == null ? const [] : kDefaultContentInsertionMimeTypes)); + } + + static final TextMagnifierConfiguration _iosMagnifierConfiguration = TextMagnifierConfiguration( + magnifierBuilder: ( + BuildContext context, + MagnifierController controller, + ValueNotifier magnifierInfo + ) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + return CupertinoTextMagnifier( + controller: controller, + magnifierInfo: magnifierInfo, + ); + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return null; + } + }); + + /// Returns a new [SpellCheckConfiguration] where the given configuration has + /// had any missing values replaced with their defaults for the iOS platform. + static SpellCheckConfiguration inferIOSSpellCheckConfiguration( + SpellCheckConfiguration? configuration, + ) { + if (configuration == null + || configuration == const SpellCheckConfiguration.disabled()) { + return const SpellCheckConfiguration.disabled(); + } + + return configuration.copyWith( + misspelledTextStyle: configuration.misspelledTextStyle + ?? CupertinoTextField.cupertinoMisspelledTextStyle, + misspelledSelectionColor: configuration.misspelledSelectionColor + ?? CupertinoTextField.kMisspelledSelectionColor, + spellCheckSuggestionsToolbarBuilder: + configuration.spellCheckSuggestionsToolbarBuilder + ?? CupertinoTextField.defaultSpellCheckSuggestionsToolbarBuilder, + ); + } +} + +class _CupertinoTextFieldState extends State with RestorationMixin, AutomaticKeepAliveClientMixin implements TextSelectionGestureDetectorBuilderDelegate, AutofillClient { + final GlobalKey _clearGlobalKey = GlobalKey(); + + RestorableTextEditingController? _controller; + TextEditingController get _effectiveController => widget.controller ?? _controller!.value; + + FocusNode? _focusNode; + FocusNode get _effectiveFocusNode => widget.focusNode ?? (_focusNode ??= FocusNode()); + + MaxLengthEnforcement get _effectiveMaxLengthEnforcement => widget.maxLengthEnforcement + ?? LengthLimitingTextInputFormatter.getDefaultMaxLengthEnforcement(); + + bool _showSelectionHandles = false; + + late _CupertinoTextFieldSelectionGestureDetectorBuilder _selectionGestureDetectorBuilder; + + // API for TextSelectionGestureDetectorBuilderDelegate. + @override + bool get forcePressEnabled => true; + + @override + final GlobalKey editableTextKey = GlobalKey(); + + @override + bool get selectionEnabled => widget.selectionEnabled; + // End of API for TextSelectionGestureDetectorBuilderDelegate. + + @override + void initState() { + super.initState(); + _selectionGestureDetectorBuilder = _CupertinoTextFieldSelectionGestureDetectorBuilder( + state: this, + ); + if (widget.controller == null) { + _createLocalController(); + } + _effectiveFocusNode.canRequestFocus = widget.enabled; + _effectiveFocusNode.addListener(_handleFocusChanged); + } + + @override + void didUpdateWidget(CupertinoTextField oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.controller == null && oldWidget.controller != null) { + _createLocalController(oldWidget.controller!.value); + } else if (widget.controller != null && oldWidget.controller == null) { + unregisterFromRestoration(_controller!); + _controller!.dispose(); + _controller = null; + } + + if (widget.focusNode != oldWidget.focusNode) { + (oldWidget.focusNode ?? _focusNode)?.removeListener(_handleFocusChanged); + (widget.focusNode ?? _focusNode)?.addListener(_handleFocusChanged); + } + _effectiveFocusNode.canRequestFocus = widget.enabled; + } + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + if (_controller != null) { + _registerController(); + } + } + + void _registerController() { + assert(_controller != null); + registerForRestoration(_controller!, 'controller'); + _controller!.value.addListener(updateKeepAlive); + } + + void _createLocalController([TextEditingValue? value]) { + assert(_controller == null); + _controller = value == null + ? RestorableTextEditingController() + : RestorableTextEditingController.fromValue(value); + if (!restorePending) { + _registerController(); + } + } + + @override + String? get restorationId => widget.restorationId; + + @override + void dispose() { + _effectiveFocusNode.removeListener(_handleFocusChanged); + _focusNode?.dispose(); + _controller?.dispose(); + super.dispose(); + } + + EditableTextState get _editableText => editableTextKey.currentState!; + + void _requestKeyboard() { + _editableText.requestKeyboard(); + } + + void _handleFocusChanged() { + setState(() { + // Rebuild the widget on focus change to show/hide the text selection + // highlight. + }); + } + + bool _shouldShowSelectionHandles(SelectionChangedCause? cause) { + // When the text field is activated by something that doesn't trigger the + // selection overlay, we shouldn't show the handles either. + if (!_selectionGestureDetectorBuilder.shouldShowSelectionToolbar) { + return false; + } + + // On iOS, we don't show handles when the selection is collapsed. + if (_effectiveController.selection.isCollapsed) { + return false; + } + + if (cause == SelectionChangedCause.keyboard) { + return false; + } + + if (cause == SelectionChangedCause.scribble) { + return true; + } + + if (_effectiveController.text.isNotEmpty) { + return true; + } + + return false; + } + + void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) { + final bool willShowSelectionHandles = _shouldShowSelectionHandles(cause); + if (willShowSelectionHandles != _showSelectionHandles) { + setState(() { + _showSelectionHandles = willShowSelectionHandles; + }); + } + + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + case TargetPlatform.fuchsia: + case TargetPlatform.android: + if (cause == SelectionChangedCause.longPress) { + _editableText.bringIntoView(selection.extent); + } + } + + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.fuchsia: + case TargetPlatform.android: + break; + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + if (cause == SelectionChangedCause.drag) { + _editableText.hideToolbar(); + } + } + } + + @override + bool get wantKeepAlive => _controller?.value.text.isNotEmpty ?? false; + + static bool _shouldShowAttachment({ + required OverlayVisibilityMode attachment, + required bool hasText, + }) { + return switch (attachment) { + OverlayVisibilityMode.never => false, + OverlayVisibilityMode.always => true, + OverlayVisibilityMode.editing => hasText, + OverlayVisibilityMode.notEditing => !hasText, + }; + } + + // True if any surrounding decoration widgets will be shown. + bool get _hasDecoration { + return widget.placeholder != null || + widget.clearButtonMode != OverlayVisibilityMode.never || + widget.prefix != null || + widget.suffix != null; + } + + // Provide default behavior if widget.textAlignVertical is not set. + // CupertinoTextField has top alignment by default, unless it has decoration + // like a prefix or suffix, in which case it's aligned to the center. + TextAlignVertical get _textAlignVertical { + if (widget.textAlignVertical != null) { + return widget.textAlignVertical!; + } + return _hasDecoration ? TextAlignVertical.center : TextAlignVertical.top; + } + + void _onClearButtonTapped() { + final bool hadText = _effectiveController.text.isNotEmpty; + _effectiveController.clear(); + if (hadText) { + // Tapping the clear button is also considered a "user initiated" change + // (instead of a programmatical one), so call `onChanged` if the text + // changed as a result. + widget.onChanged?.call(_effectiveController.text); + } + } + + Widget _buildClearButton() { + final String clearLabel = widget.clearButtonSemanticLabel ?? CupertinoLocalizations.of(context).clearButtonLabel; + + return Semantics( + button: true, + label: clearLabel, + child: GestureDetector( + key: _clearGlobalKey, + onTap: widget.enabled ? _onClearButtonTapped : null, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 6.0), + child: Icon( + CupertinoIcons.clear_thick_circled, + size: 18.0, + color: CupertinoDynamicColor.resolve(_kClearButtonColor, context), + ), + ), + ), + ); + } + + Widget _addTextDependentAttachments(Widget editableText, TextStyle textStyle, TextStyle placeholderStyle) { + // If there are no surrounding widgets, just return the core editable text + // part. + if (!_hasDecoration) { + return editableText; + } + + // Otherwise, listen to the current state of the text entry. + return ValueListenableBuilder( + valueListenable: _effectiveController, + child: editableText, + builder: (BuildContext context, TextEditingValue text, Widget? child) { + final bool hasText = text.text.isNotEmpty; + final String? placeholderText = widget.placeholder; + final Widget? placeholder = placeholderText == null + ? null + // Make the placeholder invisible when hasText is true. + : Visibility( + maintainAnimation: true, + maintainSize: true, + maintainState: true, + visible: !hasText, + child: SizedBox( + width: double.infinity, + child: Padding( + padding: widget.padding, + child: Text( + placeholderText, + // This is to make sure the text field is always tall enough + // to accommodate the first line of the placeholder, so the + // text does not shrink vertically as you type (however in + // rare circumstances, the height may still change when + // there's no placeholder text). + maxLines: hasText ? 1 : widget.maxLines, + overflow: placeholderStyle.overflow, + style: placeholderStyle, + textAlign: widget.textAlign, + ), + ), + ), + ); + + final Widget? prefixWidget = _shouldShowAttachment(attachment: widget.prefixMode, hasText: hasText) ? widget.prefix : null; + + // Show user specified suffix if applicable and fall back to clear button. + final bool showUserSuffix = _shouldShowAttachment(attachment: widget.suffixMode, hasText: hasText); + final bool showClearButton = _shouldShowAttachment(attachment: widget.clearButtonMode, hasText: hasText); + final Widget? suffixWidget = switch ((showUserSuffix, showClearButton)) { + (false, false) => null, + (true, false) => widget.suffix, + (true, true) => widget.suffix ?? _buildClearButton(), + (false, true) => _buildClearButton(), + }; + return Row(children: [ + // Insert a prefix at the front if the prefix visibility mode matches + // the current text state. + if (prefixWidget != null) prefixWidget, + // In the middle part, stack the placeholder on top of the main EditableText + // if needed. + Expanded( + child: Stack( + // Ideally this should be baseline aligned. However that comes at + // the cost of the ability to compute the intrinsic dimensions of + // this widget. + // See also https://github.com/flutter/flutter/issues/13715. + alignment: AlignmentDirectional.center, + textDirection: widget.textDirection, + children: [ + if (placeholder != null) placeholder, + editableText, + ], + ), + ), + if (suffixWidget != null) suffixWidget + ]); + }, + ); + } + // AutofillClient implementation start. + @override + String get autofillId => _editableText.autofillId; + + @override + void autofill(TextEditingValue newEditingValue) => _editableText.autofill(newEditingValue); + + @override + TextInputConfiguration get textInputConfiguration { + final List? autofillHints = widget.autofillHints?.toList(growable: false); + final AutofillConfiguration autofillConfiguration = autofillHints != null + ? AutofillConfiguration( + uniqueIdentifier: autofillId, + autofillHints: autofillHints, + currentEditingValue: _effectiveController.value, + hintText: widget.placeholder, + ) + : AutofillConfiguration.disabled; + + return _editableText.textInputConfiguration.copyWith(autofillConfiguration: autofillConfiguration); + } + // AutofillClient implementation end. + + @override + Widget build(BuildContext context) { + super.build(context); // See AutomaticKeepAliveClientMixin. + assert(debugCheckHasDirectionality(context)); + final TextEditingController controller = _effectiveController; + + TextSelectionControls? textSelectionControls = widget.selectionControls; + VoidCallback? handleDidGainAccessibilityFocus; + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + textSelectionControls ??= cupertinoTextSelectionHandleControls; + + case TargetPlatform.macOS: + case TargetPlatform.windows: + textSelectionControls ??= cupertinoDesktopTextSelectionHandleControls; + handleDidGainAccessibilityFocus = () { + // Automatically activate the TextField when it receives accessibility focus. + if (!_effectiveFocusNode.hasFocus && _effectiveFocusNode.canRequestFocus) { + _effectiveFocusNode.requestFocus(); + } + }; + } + + final bool enabled = widget.enabled; + final Offset cursorOffset = Offset(_iOSHorizontalCursorOffsetPixels / MediaQuery.devicePixelRatioOf(context), 0); + final List formatters = [ + ...?widget.inputFormatters, + if (widget.maxLength != null) + LengthLimitingTextInputFormatter( + widget.maxLength, + maxLengthEnforcement: _effectiveMaxLengthEnforcement, + ), + ]; + final CupertinoThemeData themeData = CupertinoTheme.of(context); + + final TextStyle? resolvedStyle = widget.style?.copyWith( + color: CupertinoDynamicColor.maybeResolve(widget.style?.color, context), + backgroundColor: CupertinoDynamicColor.maybeResolve(widget.style?.backgroundColor, context), + ); + + final TextStyle textStyle = themeData.textTheme.textStyle.merge(resolvedStyle); + + final TextStyle? resolvedPlaceholderStyle = widget.placeholderStyle?.copyWith( + color: CupertinoDynamicColor.maybeResolve(widget.placeholderStyle?.color, context), + backgroundColor: CupertinoDynamicColor.maybeResolve(widget.placeholderStyle?.backgroundColor, context), + ); + + final TextStyle placeholderStyle = textStyle.merge(resolvedPlaceholderStyle); + + final Brightness keyboardAppearance = widget.keyboardAppearance ?? CupertinoTheme.brightnessOf(context); + final Color cursorColor = CupertinoDynamicColor.maybeResolve( + widget.cursorColor ?? DefaultSelectionStyle.of(context).cursorColor, + context, + ) ?? themeData.primaryColor; + + final Color disabledColor = CupertinoDynamicColor.resolve(_kDisabledBackground, context); + + final Color? decorationColor = CupertinoDynamicColor.maybeResolve(widget.decoration?.color, context); + + final BoxBorder? border = widget.decoration?.border; + Border? resolvedBorder = border as Border?; + if (border is Border) { + BorderSide resolveBorderSide(BorderSide side) { + return side == BorderSide.none + ? side + : side.copyWith(color: CupertinoDynamicColor.resolve(side.color, context)); + } + resolvedBorder = border.runtimeType != Border + ? border + : Border( + top: resolveBorderSide(border.top), + left: resolveBorderSide(border.left), + bottom: resolveBorderSide(border.bottom), + right: resolveBorderSide(border.right), + ); + } + + final BoxDecoration? effectiveDecoration = widget.decoration?.copyWith( + border: resolvedBorder, + color: enabled ? decorationColor : disabledColor, + ); + + final Color selectionColor = CupertinoDynamicColor.maybeResolve( + DefaultSelectionStyle.of(context).selectionColor, + context, + ) ?? CupertinoTheme.of(context).primaryColor.withOpacity(0.2); + + // Set configuration as disabled if not otherwise specified. If specified, + // ensure that configuration uses Cupertino text style for misspelled words + // unless a custom style is specified. + final SpellCheckConfiguration spellCheckConfiguration = + CupertinoTextField.inferIOSSpellCheckConfiguration( + widget.spellCheckConfiguration, + ); + + final Widget paddedEditable = Padding( + padding: widget.padding, + child: RepaintBoundary( + child: UnmanagedRestorationScope( + bucket: bucket, + child: EditableText( + key: editableTextKey, + controller: controller, + undoController: widget.undoController, + readOnly: widget.readOnly || !enabled, + toolbarOptions: widget.toolbarOptions, + showCursor: widget.showCursor, + showSelectionHandles: _showSelectionHandles, + focusNode: _effectiveFocusNode, + keyboardType: widget.keyboardType, + textInputAction: widget.textInputAction, + textCapitalization: widget.textCapitalization, + style: textStyle, + strutStyle: widget.strutStyle, + textAlign: widget.textAlign, + textDirection: widget.textDirection, + autofocus: widget.autofocus, + obscuringCharacter: widget.obscuringCharacter, + obscureText: widget.obscureText, + autocorrect: widget.autocorrect, + smartDashesType: widget.smartDashesType, + smartQuotesType: widget.smartQuotesType, + enableSuggestions: widget.enableSuggestions, + maxLines: widget.maxLines, + minLines: widget.minLines, + expands: widget.expands, + magnifierConfiguration: widget.magnifierConfiguration ?? CupertinoTextField._iosMagnifierConfiguration, + // Only show the selection highlight when the text field is focused. + selectionColor: _effectiveFocusNode.hasFocus ? selectionColor : null, + selectionControls: widget.selectionEnabled + ? textSelectionControls : null, + onChanged: widget.onChanged, + onSelectionChanged: _handleSelectionChanged, + onEditingComplete: widget.onEditingComplete, + onSubmitted: widget.onSubmitted, + onTapOutside: widget.onTapOutside, + inputFormatters: formatters, + rendererIgnoresPointer: true, + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: widget.cursorRadius, + cursorColor: cursorColor, + cursorOpacityAnimates: widget.cursorOpacityAnimates, + cursorOffset: cursorOffset, + paintCursorAboveText: true, + autocorrectionTextRectColor: selectionColor, + backgroundCursorColor: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context), + selectionHeightStyle: widget.selectionHeightStyle, + selectionWidthStyle: widget.selectionWidthStyle, + scrollPadding: widget.scrollPadding, + keyboardAppearance: keyboardAppearance, + dragStartBehavior: widget.dragStartBehavior, + scrollController: widget.scrollController, + scrollPhysics: widget.scrollPhysics, + enableInteractiveSelection: widget.enableInteractiveSelection, + autofillClient: this, + clipBehavior: widget.clipBehavior, + restorationId: 'editable', + scribbleEnabled: widget.scribbleEnabled, + enableIMEPersonalizedLearning: widget.enableIMEPersonalizedLearning, + contentInsertionConfiguration: widget.contentInsertionConfiguration, + contextMenuBuilder: widget.contextMenuBuilder, + spellCheckConfiguration: spellCheckConfiguration, + ), + ), + ), + ); + + return Semantics( + enabled: enabled, + onTap: !enabled || widget.readOnly ? null : () { + if (!controller.selection.isValid) { + controller.selection = TextSelection.collapsed(offset: controller.text.length); + } + _requestKeyboard(); + }, + onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus, + child: TextFieldTapRegion( + child: IgnorePointer( + ignoring: !enabled, + child: Container( + decoration: effectiveDecoration, + color: !enabled && effectiveDecoration == null ? disabledColor : null, + child: _selectionGestureDetectorBuilder.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: Align( + alignment: Alignment(-1.0, _textAlignVertical.y), + widthFactor: 1.0, + heightFactor: 1.0, + child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle), + ), + ), + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_form_field_row.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_form_field_row.dart new file mode 100644 index 0000000000000000000000000000000000000000..5f9c951ebd4dc0899d4b7c2a8db778f9b0ed5579 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_form_field_row.dart @@ -0,0 +1,351 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'adaptive_text_selection_toolbar.dart'; +import 'colors.dart'; +import 'form_row.dart'; +import 'text_field.dart'; + +/// Creates a [CupertinoFormRow] containing a [FormField] that wraps +/// a [CupertinoTextField]. +/// +/// A [Form] ancestor is not required. The [Form] allows one to +/// save, reset, or validate multiple fields at once. To use without a [Form], +/// pass a [GlobalKey] to the constructor and use [GlobalKey.currentState] to +/// save or reset the form field. +/// +/// When a [controller] is specified, its [TextEditingController.text] +/// defines the [initialValue]. If this [FormField] is part of a scrolling +/// container that lazily constructs its children, like a [ListView] or a +/// [CustomScrollView], then a [controller] should be specified. +/// The controller's lifetime should be managed by a stateful widget ancestor +/// of the scrolling container. +/// +/// The [prefix] parameter is displayed at the start of the row. Standard iOS +/// guidelines encourage passing a [Text] widget to [prefix] to detail the +/// nature of the input. +/// +/// The [padding] parameter is used to pad the contents of the row. It is +/// directly passed to [CupertinoFormRow]. If the [padding] +/// parameter is null, [CupertinoFormRow] constructs its own default +/// padding (which is the standard form row padding in iOS.) If no edge +/// insets are intended, explicitly pass [EdgeInsets.zero] to [padding]. +/// +/// If a [controller] is not specified, [initialValue] can be used to give +/// the automatically generated controller an initial value. +/// +/// Consider calling [TextEditingController.dispose] of the [controller], if one +/// is specified, when it is no longer needed. This will ensure we discard any +/// resources used by the object. +/// +/// For documentation about the various parameters, see the +/// [CupertinoTextField] class and [CupertinoTextField.borderless], +/// the constructor. +/// +/// {@tool snippet} +/// +/// Creates a [CupertinoTextFormFieldRow] with a leading text and validator +/// function. +/// +/// If the user enters valid text, the CupertinoTextField appears normally +/// without any warnings to the user. +/// +/// If the user enters invalid text, the error message returned from the +/// validator function is displayed in dark red underneath the input. +/// +/// ```dart +/// CupertinoTextFormFieldRow( +/// prefix: const Text('Username'), +/// onSaved: (String? value) { +/// // This optional block of code can be used to run +/// // code when the user saves the form. +/// }, +/// validator: (String? value) { +/// return (value != null && value.contains('@')) ? 'Do not use the @ char.' : null; +/// }, +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to move the focus to the next field when the user +/// presses the SPACE key. +/// +/// ** See code in examples/api/lib/cupertino/text_form_field_row/cupertino_text_form_field_row.1.dart ** +/// {@end-tool} +class CupertinoTextFormFieldRow extends FormField { + /// Creates a [CupertinoFormRow] containing a [FormField] that wraps + /// a [CupertinoTextField]. + /// + /// When a [controller] is specified, [initialValue] must be null (the + /// default). If [controller] is null, then a [TextEditingController] + /// will be constructed automatically and its `text` will be initialized + /// to [initialValue] or the empty string. + /// + /// The [prefix] parameter is displayed at the start of the row. Standard iOS + /// guidelines encourage passing a [Text] widget to [prefix] to detail the + /// nature of the input. + /// + /// The [padding] parameter is used to pad the contents of the row. It is + /// directly passed to [CupertinoFormRow]. If the [padding] + /// parameter is null, [CupertinoFormRow] constructs its own default + /// padding (which is the standard form row padding in iOS.) If no edge + /// insets are intended, explicitly pass [EdgeInsets.zero] to [padding]. + /// + /// For documentation about the various parameters, see the + /// [CupertinoTextField] class and [CupertinoTextField.borderless], + /// the constructor. + CupertinoTextFormFieldRow({ + super.key, + this.prefix, + this.padding, + this.controller, + String? initialValue, + FocusNode? focusNode, + BoxDecoration? decoration, + TextInputType? keyboardType, + TextCapitalization textCapitalization = TextCapitalization.none, + TextInputAction? textInputAction, + TextStyle? style, + StrutStyle? strutStyle, + TextDirection? textDirection, + TextAlign textAlign = TextAlign.start, + TextAlignVertical? textAlignVertical, + bool autofocus = false, + bool readOnly = false, + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + ToolbarOptions? toolbarOptions, + bool? showCursor, + String obscuringCharacter = '•', + bool obscureText = false, + bool autocorrect = true, + SmartDashesType? smartDashesType, + SmartQuotesType? smartQuotesType, + bool enableSuggestions = true, + int? maxLines = 1, + int? minLines, + bool expands = false, + int? maxLength, + this.onChanged, + GestureTapCallback? onTap, + VoidCallback? onEditingComplete, + ValueChanged? onFieldSubmitted, + super.onSaved, + super.validator, + List? inputFormatters, + bool? enabled, + double cursorWidth = 2.0, + double? cursorHeight, + Color? cursorColor, + Brightness? keyboardAppearance, + EdgeInsets scrollPadding = const EdgeInsets.all(20.0), + bool enableInteractiveSelection = true, + TextSelectionControls? selectionControls, + ScrollPhysics? scrollPhysics, + Iterable? autofillHints, + AutovalidateMode super.autovalidateMode = AutovalidateMode.disabled, + String? placeholder, + TextStyle? placeholderStyle = const TextStyle( + fontWeight: FontWeight.w400, + color: CupertinoColors.placeholderText, + ), + EditableTextContextMenuBuilder? contextMenuBuilder = _defaultContextMenuBuilder, + }) : assert(initialValue == null || controller == null), + assert(obscuringCharacter.length == 1), + assert(maxLines == null || maxLines > 0), + assert(minLines == null || minLines > 0), + assert( + (maxLines == null) || (minLines == null) || (maxLines >= minLines), + "minLines can't be greater than maxLines", + ), + assert( + !expands || (maxLines == null && minLines == null), + 'minLines and maxLines must be null when expands is true.', + ), + assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'), + assert(maxLength == null || maxLength > 0), + super( + initialValue: controller?.text ?? initialValue ?? '', + builder: (FormFieldState field) { + final _CupertinoTextFormFieldRowState state = + field as _CupertinoTextFormFieldRowState; + + void onChangedHandler(String value) { + field.didChange(value); + onChanged?.call(value); + } + + return CupertinoFormRow( + prefix: prefix, + padding: padding, + error: (field.errorText == null) ? null : Text(field.errorText!), + child: CupertinoTextField.borderless( + controller: state._effectiveController, + focusNode: focusNode, + keyboardType: keyboardType, + decoration: decoration, + textInputAction: textInputAction, + style: style, + strutStyle: strutStyle, + textAlign: textAlign, + textAlignVertical: textAlignVertical, + textCapitalization: textCapitalization, + textDirection: textDirection, + autofocus: autofocus, + toolbarOptions: toolbarOptions, + readOnly: readOnly, + showCursor: showCursor, + obscuringCharacter: obscuringCharacter, + obscureText: obscureText, + autocorrect: autocorrect, + smartDashesType: smartDashesType, + smartQuotesType: smartQuotesType, + enableSuggestions: enableSuggestions, + maxLines: maxLines, + minLines: minLines, + expands: expands, + maxLength: maxLength, + onChanged: onChangedHandler, + onTap: onTap, + onEditingComplete: onEditingComplete, + onSubmitted: onFieldSubmitted, + inputFormatters: inputFormatters, + enabled: enabled ?? true, + cursorWidth: cursorWidth, + cursorHeight: cursorHeight, + cursorColor: cursorColor, + scrollPadding: scrollPadding, + scrollPhysics: scrollPhysics, + keyboardAppearance: keyboardAppearance, + enableInteractiveSelection: enableInteractiveSelection, + selectionControls: selectionControls, + autofillHints: autofillHints, + placeholder: placeholder, + placeholderStyle: placeholderStyle, + contextMenuBuilder: contextMenuBuilder, + ), + ); + }, + ); + + /// A widget that is displayed at the start of the row. + /// + /// The [prefix] widget is displayed at the start of the row. Standard iOS + /// guidelines encourage passing a [Text] widget to [prefix] to detail the + /// nature of the input. + final Widget? prefix; + + /// Content padding for the row. + /// + /// The [padding] widget is passed to [CupertinoFormRow]. If the [padding] + /// parameter is null, [CupertinoFormRow] constructs its own default + /// padding, which is the standard form row padding in iOS. + /// + /// If no edge insets are intended, explicitly pass [EdgeInsets.zero] to + /// [padding]. + final EdgeInsetsGeometry? padding; + + /// Controls the text being edited. + /// + /// If null, this widget will create its own [TextEditingController] and + /// initialize its [TextEditingController.text] with [initialValue]. + final TextEditingController? controller; + + /// {@macro flutter.material.TextFormField.onChanged} + final ValueChanged? onChanged; + + static Widget _defaultContextMenuBuilder(BuildContext context, EditableTextState editableTextState) { + return CupertinoAdaptiveTextSelectionToolbar.editableText( + editableTextState: editableTextState, + ); + } + + @override + FormFieldState createState() => _CupertinoTextFormFieldRowState(); +} + +class _CupertinoTextFormFieldRowState extends FormFieldState { + TextEditingController? _controller; + + TextEditingController? get _effectiveController => + _cupertinoTextFormFieldRow.controller ?? _controller; + + CupertinoTextFormFieldRow get _cupertinoTextFormFieldRow => + super.widget as CupertinoTextFormFieldRow; + + @override + void initState() { + super.initState(); + if (_cupertinoTextFormFieldRow.controller == null) { + _controller = TextEditingController(text: widget.initialValue); + } else { + _cupertinoTextFormFieldRow.controller!.addListener(_handleControllerChanged); + } + } + + @override + void didUpdateWidget(CupertinoTextFormFieldRow oldWidget) { + super.didUpdateWidget(oldWidget); + if (_cupertinoTextFormFieldRow.controller != oldWidget.controller) { + oldWidget.controller?.removeListener(_handleControllerChanged); + _cupertinoTextFormFieldRow.controller?.addListener(_handleControllerChanged); + + if (oldWidget.controller != null && _cupertinoTextFormFieldRow.controller == null) { + _controller = + TextEditingController.fromValue(oldWidget.controller!.value); + } + + if (_cupertinoTextFormFieldRow.controller != null) { + setValue(_cupertinoTextFormFieldRow.controller!.text); + if (oldWidget.controller == null) { + _controller = null; + } + } + } + } + + @override + void dispose() { + _cupertinoTextFormFieldRow.controller?.removeListener(_handleControllerChanged); + _controller?.dispose(); + super.dispose(); + } + + @override + void didChange(String? value) { + super.didChange(value); + + if (value != null && _effectiveController!.text != value) { + _effectiveController!.text = value; + } + } + + @override + void reset() { + // Set the controller value before calling super.reset() to let + // _handleControllerChanged suppress the change. + _effectiveController!.text = widget.initialValue!; + super.reset(); + _cupertinoTextFormFieldRow.onChanged?.call(_effectiveController!.text); + } + + void _handleControllerChanged() { + // Suppress changes that originated from within this class. + // + // In the case where a controller has been passed in to this widget, we + // register this change listener. In these cases, we'll also receive change + // notifications for changes originating from within this class -- for + // example, the reset() method. In such cases, the FormField value will + // already have been set. + if (_effectiveController!.text != value) { + didChange(_effectiveController!.text); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_selection.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_selection.dart new file mode 100644 index 0000000000000000000000000000000000000000..25992431b9418f7ce023e3246d23c428db00085e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_selection.dart @@ -0,0 +1,332 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart' show ValueListenable, clampDouble; +import 'package:flutter/widgets.dart'; + +import 'localizations.dart'; +import 'text_selection_toolbar.dart'; +import 'text_selection_toolbar_button.dart'; +import 'theme.dart'; + +// Read off from the output on iOS 12. This color does not vary with the +// application's theme color. +const double _kSelectionHandleOverlap = 1.5; +// Extracted from https://developer.apple.com/design/resources/. +const double _kSelectionHandleRadius = 6; + +// Minimal padding from tip of the selection toolbar arrow to horizontal edges of the +// screen. Eyeballed value. +const double _kArrowScreenPadding = 26.0; + +/// Draws a single text selection handle with a bar and a ball. +class _TextSelectionHandlePainter extends CustomPainter { + const _TextSelectionHandlePainter(this.color); + + final Color color; + + @override + void paint(Canvas canvas, Size size) { + const double halfStrokeWidth = 1.0; + final Paint paint = Paint()..color = color; + final Rect circle = Rect.fromCircle( + center: const Offset(_kSelectionHandleRadius, _kSelectionHandleRadius), + radius: _kSelectionHandleRadius, + ); + final Rect line = Rect.fromPoints( + const Offset( + _kSelectionHandleRadius - halfStrokeWidth, + 2 * _kSelectionHandleRadius - _kSelectionHandleOverlap, + ), + Offset(_kSelectionHandleRadius + halfStrokeWidth, size.height), + ); + final Path path = Path() + ..addOval(circle) + // Draw line so it slightly overlaps the circle. + ..addRect(line); + canvas.drawPath(path, paint); + } + + @override + bool shouldRepaint(_TextSelectionHandlePainter oldPainter) => color != oldPainter.color; +} + +/// iOS Cupertino styled text selection handle controls. +/// +/// Specifically does not manage the toolbar, which is left to +/// [EditableText.contextMenuBuilder]. +@Deprecated( + 'Use `CupertinoTextSelectionControls`. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', +) +class CupertinoTextSelectionHandleControls extends CupertinoTextSelectionControls with TextSelectionHandleControls { +} + +/// iOS Cupertino styled text selection controls. +/// +/// The [cupertinoTextSelectionControls] global variable has a +/// suitable instance of this class. +class CupertinoTextSelectionControls extends TextSelectionControls { + /// Returns the size of the Cupertino handle. + @override + Size getHandleSize(double textLineHeight) { + return Size( + _kSelectionHandleRadius * 2, + textLineHeight + _kSelectionHandleRadius * 2 - _kSelectionHandleOverlap, + ); + } + + /// Builder for iOS-style copy/paste text selection toolbar. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + Widget buildToolbar( + BuildContext context, + Rect globalEditableRegion, + double textLineHeight, + Offset selectionMidpoint, + List endpoints, + TextSelectionDelegate delegate, + ValueListenable? clipboardStatus, + Offset? lastSecondaryTapDownPosition, + ) { + return _CupertinoTextSelectionControlsToolbar( + clipboardStatus: clipboardStatus, + endpoints: endpoints, + globalEditableRegion: globalEditableRegion, + handleCut: canCut(delegate) ? () => handleCut(delegate) : null, + handleCopy: canCopy(delegate) ? () => handleCopy(delegate) : null, + handlePaste: canPaste(delegate) ? () => handlePaste(delegate) : null, + handleSelectAll: canSelectAll(delegate) ? () => handleSelectAll(delegate) : null, + selectionMidpoint: selectionMidpoint, + textLineHeight: textLineHeight, + ); + } + + /// Builder for iOS text selection edges. + @override + Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textLineHeight, [VoidCallback? onTap]) { + // iOS selection handles do not respond to taps. + final Size desiredSize; + final Widget handle; + + final Widget customPaint = CustomPaint( + painter: _TextSelectionHandlePainter(CupertinoTheme.of(context).primaryColor), + ); + + // [buildHandle]'s widget is positioned at the selection cursor's bottom + // baseline. We transform the handle such that the SizedBox is superimposed + // on top of the text selection endpoints. + switch (type) { + case TextSelectionHandleType.left: + desiredSize = getHandleSize(textLineHeight); + handle = SizedBox.fromSize( + size: desiredSize, + child: customPaint, + ); + return handle; + case TextSelectionHandleType.right: + desiredSize = getHandleSize(textLineHeight); + handle = SizedBox.fromSize( + size: desiredSize, + child: customPaint, + ); + return Transform( + transform: Matrix4.identity() + ..translate(desiredSize.width / 2, desiredSize.height / 2) + ..rotateZ(math.pi) + ..translate(-desiredSize.width / 2, -desiredSize.height / 2), + child: handle, + ); + // iOS doesn't draw anything for collapsed selections. + case TextSelectionHandleType.collapsed: + return const SizedBox.shrink(); + } + } + + /// Gets anchor for cupertino-style text selection handles. + /// + /// See [TextSelectionControls.getHandleAnchor]. + @override + Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) { + final Size handleSize; + + switch (type) { + // The circle is at the top for the left handle, and the anchor point is + // all the way at the bottom of the line. + case TextSelectionHandleType.left: + handleSize = getHandleSize(textLineHeight); + return Offset( + handleSize.width / 2, + handleSize.height, + ); + // The right handle is vertically flipped, and the anchor point is near + // the top of the circle to give slight overlap. + case TextSelectionHandleType.right: + handleSize = getHandleSize(textLineHeight); + return Offset( + handleSize.width / 2, + handleSize.height - 2 * _kSelectionHandleRadius + _kSelectionHandleOverlap, + ); + // A collapsed handle anchors itself so that it's centered. + case TextSelectionHandleType.collapsed: + handleSize = getHandleSize(textLineHeight); + return Offset( + handleSize.width / 2, + textLineHeight + (handleSize.height - textLineHeight) / 2, + ); + } + } +} + +// TODO(justinmc): Deprecate this after TextSelectionControls.buildToolbar is +// deleted, when users should migrate back to cupertinoTextSelectionControls. +// See https://github.com/flutter/flutter/pull/124262 +/// Text selection handle controls that follow iOS design conventions. +final TextSelectionControls cupertinoTextSelectionHandleControls = + CupertinoTextSelectionHandleControls(); + +/// Text selection controls that follow iOS design conventions. +final TextSelectionControls cupertinoTextSelectionControls = + CupertinoTextSelectionControls(); + +// Generates the child that's passed into CupertinoTextSelectionToolbar. +class _CupertinoTextSelectionControlsToolbar extends StatefulWidget { + const _CupertinoTextSelectionControlsToolbar({ + required this.clipboardStatus, + required this.endpoints, + required this.globalEditableRegion, + required this.handleCopy, + required this.handleCut, + required this.handlePaste, + required this.handleSelectAll, + required this.selectionMidpoint, + required this.textLineHeight, + }); + + final ValueListenable? clipboardStatus; + final List endpoints; + final Rect globalEditableRegion; + final VoidCallback? handleCopy; + final VoidCallback? handleCut; + final VoidCallback? handlePaste; + final VoidCallback? handleSelectAll; + final Offset selectionMidpoint; + final double textLineHeight; + + @override + _CupertinoTextSelectionControlsToolbarState createState() => _CupertinoTextSelectionControlsToolbarState(); +} + +class _CupertinoTextSelectionControlsToolbarState extends State<_CupertinoTextSelectionControlsToolbar> { + void _onChangedClipboardStatus() { + setState(() { + // Inform the widget that the value of clipboardStatus has changed. + }); + } + + @override + void initState() { + super.initState(); + widget.clipboardStatus?.addListener(_onChangedClipboardStatus); + } + + @override + void didUpdateWidget(_CupertinoTextSelectionControlsToolbar oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.clipboardStatus != widget.clipboardStatus) { + oldWidget.clipboardStatus?.removeListener(_onChangedClipboardStatus); + widget.clipboardStatus?.addListener(_onChangedClipboardStatus); + } + } + + @override + void dispose() { + widget.clipboardStatus?.removeListener(_onChangedClipboardStatus); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + // Don't render the menu until the state of the clipboard is known. + if (widget.handlePaste != null && widget.clipboardStatus?.value == ClipboardStatus.unknown) { + return const SizedBox.shrink(); + } + + assert(debugCheckHasMediaQuery(context)); + final EdgeInsets mediaQueryPadding = MediaQuery.paddingOf(context); + + // The toolbar should appear below the TextField when there is not enough + // space above the TextField to show it, assuming there's always enough + // space at the bottom in this case. + final double anchorX = clampDouble(widget.selectionMidpoint.dx + widget.globalEditableRegion.left, + _kArrowScreenPadding + mediaQueryPadding.left, + MediaQuery.sizeOf(context).width - mediaQueryPadding.right - _kArrowScreenPadding, + ); + + final double topAmountInEditableRegion = widget.endpoints.first.point.dy - widget.textLineHeight; + final double anchorTop = math.max(topAmountInEditableRegion, 0) + widget.globalEditableRegion.top; + + // The y-coordinate has to be calculated instead of directly quoting + // selectionMidpoint.dy, since the caller + // (TextSelectionOverlay._buildToolbar) does not know whether the toolbar is + // going to be facing up or down. + final Offset anchorAbove = Offset( + anchorX, + anchorTop, + ); + final Offset anchorBelow = Offset( + anchorX, + widget.endpoints.last.point.dy + widget.globalEditableRegion.top, + ); + + final List items = []; + final CupertinoLocalizations localizations = CupertinoLocalizations.of(context); + final Widget onePhysicalPixelVerticalDivider = + SizedBox(width: 1.0 / MediaQuery.devicePixelRatioOf(context)); + + void addToolbarButton( + String text, + VoidCallback onPressed, + ) { + if (items.isNotEmpty) { + items.add(onePhysicalPixelVerticalDivider); + } + + items.add(CupertinoTextSelectionToolbarButton.text( + onPressed: onPressed, + text: text, + )); + } + + if (widget.handleCut != null) { + addToolbarButton(localizations.cutButtonLabel, widget.handleCut!); + } + if (widget.handleCopy != null) { + addToolbarButton(localizations.copyButtonLabel, widget.handleCopy!); + } + if (widget.handlePaste != null + && widget.clipboardStatus?.value == ClipboardStatus.pasteable) { + addToolbarButton(localizations.pasteButtonLabel, widget.handlePaste!); + } + if (widget.handleSelectAll != null) { + addToolbarButton(localizations.selectAllButtonLabel, widget.handleSelectAll!); + } + + // If there is no option available, build an empty widget. + if (items.isEmpty) { + return const SizedBox.shrink(); + } + + return CupertinoTextSelectionToolbar( + anchorAbove: anchorAbove, + anchorBelow: anchorBelow, + children: items, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..6e89fc6dd5d5e302edec6f0685bd5c23707310d5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart @@ -0,0 +1,1278 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:math' as math show pi; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart' show Brightness, clampDouble; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'text_selection_toolbar_button.dart'; +import 'theme.dart'; + +// The radius of the toolbar RRect shape. +// Value extracted from https://developer.apple.com/design/resources/. +const Radius _kToolbarBorderRadius = Radius.circular(8.0); + +// Vertical distance between the tip of the arrow and the line of text the arrow +// is pointing to. The value used here is eyeballed. +const double _kToolbarContentDistance = 8.0; + +// The size of the arrow pointing to the anchor. Eyeballed value. +const Size _kToolbarArrowSize = Size(14.0, 7.0); + +// Minimal padding from tip of the selection toolbar arrow to horizontal edges of the +// screen. Eyeballed value. +const double _kArrowScreenPadding = 26.0; + +// The size and thickness of the chevron icon used for navigating between toolbar pages. +// Eyeballed values. +const double _kToolbarChevronSize = 10.0; +const double _kToolbarChevronThickness = 2.0; + +// Color was measured from a screenshot of iOS 16.0.2 +// TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/41507. +const CupertinoDynamicColor _kToolbarBackgroundColor = CupertinoDynamicColor.withBrightness( + color: Color(0xFFF6F6F6), + darkColor: Color(0xFF222222), +); + +// Color was measured from a screenshot of iOS 16.0.2. +const CupertinoDynamicColor _kToolbarDividerColor = CupertinoDynamicColor.withBrightness( + color: Color(0xFFD6D6D6), + darkColor: Color(0xFF424242), +); + +const CupertinoDynamicColor _kToolbarTextColor = CupertinoDynamicColor.withBrightness( + color: CupertinoColors.black, + darkColor: CupertinoColors.white, +); + +const Duration _kToolbarTransitionDuration = Duration(milliseconds: 125); + +/// The type for a Function that builds a toolbar's container with the given +/// child. +/// +/// The anchor is provided in global coordinates. +/// +/// See also: +/// +/// * [CupertinoTextSelectionToolbar.toolbarBuilder], which is of this type. +/// * [TextSelectionToolbar.toolbarBuilder], which is similar, but for an +/// Material-style toolbar. +typedef CupertinoToolbarBuilder = Widget Function( + BuildContext context, + Offset anchorAbove, + Offset anchorBelow, + Widget child, +); + +/// An iOS-style text selection toolbar. +/// +/// Typically displays buttons for text manipulation, e.g. copying and pasting +/// text. +/// +/// Tries to position itself above [anchorAbove], but if it doesn't fit, then +/// it positions itself below [anchorBelow]. +/// +/// If any children don't fit in the menu, an overflow menu will automatically +/// be created. +/// +/// See also: +/// +/// * [AdaptiveTextSelectionToolbar], which builds the toolbar for the current +/// platform. +/// * [TextSelectionToolbar], which is similar, but builds an Android-style +/// toolbar. +class CupertinoTextSelectionToolbar extends StatelessWidget { + /// Creates an instance of CupertinoTextSelectionToolbar. + const CupertinoTextSelectionToolbar({ + super.key, + required this.anchorAbove, + required this.anchorBelow, + required this.children, + this.toolbarBuilder = _defaultToolbarBuilder, + }) : assert(children.length > 0); + + /// {@macro flutter.material.TextSelectionToolbar.anchorAbove} + final Offset anchorAbove; + + /// {@macro flutter.material.TextSelectionToolbar.anchorBelow} + final Offset anchorBelow; + + /// {@macro flutter.material.TextSelectionToolbar.children} + /// + /// See also: + /// * [CupertinoTextSelectionToolbarButton], which builds a default + /// Cupertino-style text selection toolbar text button. + final List children; + + /// {@macro flutter.material.TextSelectionToolbar.toolbarBuilder} + /// + /// The given anchor and isAbove can be used to position an arrow, as in the + /// default Cupertino toolbar. + final CupertinoToolbarBuilder toolbarBuilder; + + /// Minimal padding from all edges of the selection toolbar to all edges of the + /// viewport. + /// + /// See also: + /// + /// * [SpellCheckSuggestionsToolbar], which uses this same value for its + /// padding from the edges of the viewport. + /// * [TextSelectionToolbar], which uses this same value as well. + static const double kToolbarScreenPadding = 8.0; + + // Builds a toolbar just like the default iOS toolbar, with the right color + // background and a rounded cutout with an arrow. + static Widget _defaultToolbarBuilder( + BuildContext context, + Offset anchorAbove, + Offset anchorBelow, + Widget child, + ) { + return _CupertinoTextSelectionToolbarShape( + anchorAbove: anchorAbove, + anchorBelow: anchorBelow, + shadowColor: CupertinoTheme.brightnessOf(context) == Brightness.light + ? CupertinoColors.black.withOpacity(0.2) + : null, + child: ColoredBox( + color: _kToolbarBackgroundColor.resolveFrom(context), + child: child, + ), + ); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final EdgeInsets mediaQueryPadding = MediaQuery.paddingOf(context); + + final double paddingAbove = mediaQueryPadding.top + kToolbarScreenPadding; + + // The arrow, which points to the anchor, has some margin so it can't get + // too close to the horizontal edges of the screen. + final double leftMargin = _kArrowScreenPadding + mediaQueryPadding.left; + final double rightMargin = MediaQuery.sizeOf(context).width - mediaQueryPadding.right - _kArrowScreenPadding; + + final Offset anchorAboveAdjusted = Offset( + clampDouble(anchorAbove.dx, leftMargin, rightMargin), + anchorAbove.dy - _kToolbarContentDistance - paddingAbove, + ); + final Offset anchorBelowAdjusted = Offset( + clampDouble(anchorBelow.dx, leftMargin, rightMargin), + anchorBelow.dy + _kToolbarContentDistance - paddingAbove, + ); + + return Padding( + padding: EdgeInsets.fromLTRB( + kToolbarScreenPadding, + paddingAbove, + kToolbarScreenPadding, + kToolbarScreenPadding, + ), + child: CustomSingleChildLayout( + delegate: TextSelectionToolbarLayoutDelegate( + anchorAbove: anchorAboveAdjusted, + anchorBelow: anchorBelowAdjusted, + ), + child: _CupertinoTextSelectionToolbarContent( + anchorAbove: anchorAboveAdjusted, + anchorBelow: anchorBelowAdjusted, + toolbarBuilder: toolbarBuilder, + children: children, + ), + ), + ); + } +} + +// Clips the child so that it has the shape of the default iOS text selection +// toolbar, with rounded corners and an arrow pointing at the anchor. +// +// The anchor should be in global coordinates. +class _CupertinoTextSelectionToolbarShape extends SingleChildRenderObjectWidget { + const _CupertinoTextSelectionToolbarShape({ + required Offset anchorAbove, + required Offset anchorBelow, + Color? shadowColor, + super.child, + }) : _anchorAbove = anchorAbove, + _anchorBelow = anchorBelow, + _shadowColor = shadowColor; + + final Offset _anchorAbove; + final Offset _anchorBelow; + final Color? _shadowColor; + + @override + _RenderCupertinoTextSelectionToolbarShape createRenderObject(BuildContext context) => _RenderCupertinoTextSelectionToolbarShape( + _anchorAbove, + _anchorBelow, + _shadowColor, + null, + ); + + @override + void updateRenderObject(BuildContext context, _RenderCupertinoTextSelectionToolbarShape renderObject) { + renderObject + ..anchorAbove = _anchorAbove + ..anchorBelow = _anchorBelow + ..shadowColor = _shadowColor; + } +} + +// Clips the child into the shape of the default iOS text selection toolbar. +// +// The shape is a rounded rectangle with a protruding arrow pointing at the +// given anchor in the direction indicated by isAbove. +// +// In order to allow the child to render itself independent of isAbove, its +// height is clipped on both the top and the bottom, leaving the arrow remaining +// on the necessary side. +class _RenderCupertinoTextSelectionToolbarShape extends RenderShiftedBox { + _RenderCupertinoTextSelectionToolbarShape( + this._anchorAbove, + this._anchorBelow, + this._shadowColor, + super.child, + ); + + @override + bool get isRepaintBoundary => true; + + Offset get anchorAbove => _anchorAbove; + Offset _anchorAbove; + set anchorAbove(Offset value) { + if (value == _anchorAbove) { + return; + } + _anchorAbove = value; + markNeedsLayout(); + } + + Offset get anchorBelow => _anchorBelow; + Offset _anchorBelow; + set anchorBelow(Offset value) { + if (value == _anchorBelow) { + return; + } + _anchorBelow = value; + markNeedsLayout(); + } + + Color? get shadowColor => _shadowColor; + Color? _shadowColor; + set shadowColor(Color? value) { + if (value == _shadowColor) { + return; + } + _shadowColor = value; + markNeedsPaint(); + } + + bool get isAbove => anchorAbove.dy >= (child?.size.height ?? 0.0) - _kToolbarArrowSize.height * 2; + + @override + void performLayout() { + final RenderBox? child = this.child; + if (child == null) { + return; + } + + final BoxConstraints enforcedConstraint = BoxConstraints( + minWidth: _kToolbarArrowSize.width + _kToolbarBorderRadius.x * 2, + ).enforce(constraints.loosen()); + child.layout(enforcedConstraint, parentUsesSize: true); + + // The buttons are padded on both top and bottom sufficiently to have + // the arrow clipped out of it on either side. By + // using this approach, the buttons don't need any special padding that + // depends on isAbove. + // The height of one arrow will be clipped off of the child, so adjust the + // size and position to remove that piece from the layout. + final BoxParentData childParentData = child.parentData! as BoxParentData; + childParentData.offset = Offset( + 0.0, + isAbove ? -_kToolbarArrowSize.height : 0.0, + ); + size = Size( + child.size.width, + child.size.height - _kToolbarArrowSize.height, + ); + } + + // Returns the RRect inside which the child is painted. + RRect _shapeRRect(RenderBox child) { + final Rect rect = Offset(0.0, _kToolbarArrowSize.height) + & Size(child.size.width, child.size.height - _kToolbarArrowSize.height * 2); + return RRect.fromRectAndRadius(rect, _kToolbarBorderRadius).scaleRadii(); + } + + // Adds the given `rrect` to the current `path`, starting from the last point + // in `path` and ends after the last corner of the rrect (closest corner to + // `startAngle` in the counterclockwise direction), without closing the path. + // + // The `startAngle` argument must be a multiple of pi / 2, with 0 being the + // positive half of the x-axis, and pi / 2 being the negative half of the + // y-axis. + // + // For instance, if `startAngle` equals pi/2 then this method draws a line + // segment to the bottom-left corner of `rrect` from the last point in `path`, + // and follows the `rrect` path clockwise until the bottom-right corner is + // added, then this method returns the mutated path without closing it. + static Path _addRRectToPath(Path path, RRect rrect, { required double startAngle }) { + const double halfPI = math.pi / 2; + assert(startAngle % halfPI == 0.0); + final Rect rect = rrect.outerRect; + + final List<(Offset, Radius)> rrectCorners = <(Offset, Radius)>[ + (rect.bottomRight, -rrect.brRadius), + (rect.bottomLeft, Radius.elliptical(rrect.blRadiusX, -rrect.blRadiusY)), + (rect.topLeft, rrect.tlRadius), + (rect.topRight, Radius.elliptical(-rrect.trRadiusX, rrect.trRadiusY)), + ]; + + // Add the 4 corners to the path clockwise. Convert radians to quadrants + // to avoid fp arithmetics. The order is br -> bl -> tl -> tr if the starting + // angle is 0. + final int startQuadrantIndex = startAngle ~/ halfPI; + for (int i = startQuadrantIndex; i < rrectCorners.length + startQuadrantIndex; i += 1) { + final (Offset vertex, Radius rectCenterOffset) = rrectCorners[i % rrectCorners.length]; + final Offset otherVertex = Offset(vertex.dx + 2 * rectCenterOffset.x, vertex.dy + 2 * rectCenterOffset.y); + final Rect rect = Rect.fromPoints(vertex, otherVertex); + path.arcTo(rect, halfPI * i, halfPI, false); + } + return path; + } + + // The path is described in the toolbar child's coordinate system. + Path _clipPath(RenderBox child, RRect rrect) { + final Path path = Path(); + // If there isn't enough width for the arrow + radii, ignore the arrow. + // Because of the constraints we gave children in performLayout, this should + // only happen if the parent isn't wide enough which should be very rare, and + // when that happens the arrow won't be too useful anyways. + if (_kToolbarBorderRadius.x * 2 + _kToolbarArrowSize.width > size.width) { + return path..addRRect(rrect); + } + + final Offset localAnchor = globalToLocal(isAbove ? _anchorAbove : _anchorBelow); + final double arrowTipX = clampDouble( + localAnchor.dx, + _kToolbarBorderRadius.x + _kToolbarArrowSize.width / 2, + size.width - _kToolbarArrowSize.width / 2 - _kToolbarBorderRadius.x, + ); + + // Draw the path clockwise, starting from the beginning side of the arrow. + if (isAbove) { + final double arrowBaseY = child.size.height - _kToolbarArrowSize.height; + final double arrowTipY = child.size.height; + path + ..moveTo(arrowTipX + _kToolbarArrowSize.width / 2, arrowBaseY) // right side of the arrow triangle + ..lineTo(arrowTipX, arrowTipY) // The tip of the arrow + ..lineTo(arrowTipX - _kToolbarArrowSize.width / 2, arrowBaseY); // left side of the arrow triangle + } else { + final double arrowBaseY = _kToolbarArrowSize.height; + const double arrowTipY = 0.0; + path + ..moveTo(arrowTipX - _kToolbarArrowSize.width / 2, arrowBaseY) // right side of the arrow triangle + ..lineTo(arrowTipX, arrowTipY) // The tip of the arrow + ..lineTo(arrowTipX + _kToolbarArrowSize.width / 2, arrowBaseY); // left side of the arrow triangle + } + final double startAngle = isAbove ? math.pi / 2 : -math.pi / 2; + return _addRRectToPath(path, rrect, startAngle: startAngle)..close(); + } + + @override + void paint(PaintingContext context, Offset offset) { + final RenderBox? child = this.child; + if (child == null) { + return; + } + + final BoxParentData childParentData = child.parentData! as BoxParentData; + + final RRect rrect = _shapeRRect(child); + final Path clipPath = _clipPath(child, rrect); + + // If configured, paint the shadow beneath the shape. + if (_shadowColor != null) { + final BoxShadow boxShadow = BoxShadow( + color: _shadowColor!, + blurRadius: 15.0, + ); + final RRect shadowRRect = RRect.fromLTRBR( + rrect.left, + rrect.top, + rrect.right, + rrect.bottom + _kToolbarArrowSize.height, + _kToolbarBorderRadius, + ).shift(offset + childParentData.offset + boxShadow.offset); + context.canvas.drawRRect(shadowRRect, boxShadow.toPaint()); + } + + _clipPathLayer.layer = context.pushClipPath( + needsCompositing, + offset + childParentData.offset, + Offset.zero & child.size, + clipPath, + (PaintingContext innerContext, Offset innerOffset) => innerContext.paintChild(child, innerOffset), + oldLayer: _clipPathLayer.layer, + ); + } + + final LayerHandle _clipPathLayer = LayerHandle(); + Paint? _debugPaint; + + @override + void dispose() { + _clipPathLayer.layer = null; + super.dispose(); + } + + @override + void debugPaintSize(PaintingContext context, Offset offset) { + assert(() { + final RenderBox? child = this.child; + if (child == null) { + return true; + } + + final ui.Paint debugPaint = _debugPaint ??= Paint() + ..shader = ui.Gradient.linear( + Offset.zero, + const Offset(10.0, 10.0), + const [Color(0x00000000), Color(0xFFFF00FF), Color(0xFFFF00FF), Color(0x00000000)], + const [0.25, 0.25, 0.75, 0.75], + TileMode.repeated, + ) + ..strokeWidth = 2.0 + ..style = PaintingStyle.stroke; + + final BoxParentData childParentData = child.parentData! as BoxParentData; + final Path clipPath = _clipPath(child, _shapeRRect(child)); + context.canvas.drawPath(clipPath.shift(offset + childParentData.offset), debugPaint); + return true; + }()); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + final RenderBox? child = this.child; + if (child == null) { + return false; + } + + // Positions outside of the clipped area of the child are not counted as + // hits. + final BoxParentData childParentData = child.parentData! as BoxParentData; + final Rect hitBox = Rect.fromLTWH( + childParentData.offset.dx, + childParentData.offset.dy + _kToolbarArrowSize.height, + child.size.width, + child.size.height - _kToolbarArrowSize.height * 2, + ); + if (!hitBox.contains(position)) { + return false; + } + + return super.hitTestChildren(result, position: position); + } +} + +// A toolbar containing the given children. If they overflow the width +// available, then the menu will be paginated with the overflowing children +// displayed on subsequent pages. +// +// The anchor should be in global coordinates. +class _CupertinoTextSelectionToolbarContent extends StatefulWidget { + const _CupertinoTextSelectionToolbarContent({ + required this.anchorAbove, + required this.anchorBelow, + required this.toolbarBuilder, + required this.children, + }) : assert(children.length > 0); + + final Offset anchorAbove; + final Offset anchorBelow; + final List children; + final CupertinoToolbarBuilder toolbarBuilder; + + @override + _CupertinoTextSelectionToolbarContentState createState() => _CupertinoTextSelectionToolbarContentState(); +} + +class _CupertinoTextSelectionToolbarContentState extends State<_CupertinoTextSelectionToolbarContent> with TickerProviderStateMixin { + // Controls the fading of the buttons within the menu during page transitions. + late AnimationController _controller; + int? _nextPage; + int _page = 0; + + final GlobalKey _toolbarItemsKey = GlobalKey(); + + void _onHorizontalDragEnd(DragEndDetails details) { + final double? velocity = details.primaryVelocity; + + if (velocity != null && velocity != 0) { + if (velocity > 0) { + _handlePreviousPage(); + } else { + _handleNextPage(); + } + } + } + + void _handleNextPage() { + final RenderBox? renderToolbar = + _toolbarItemsKey.currentContext?.findRenderObject() as RenderBox?; + + if (renderToolbar is _RenderCupertinoTextSelectionToolbarItems && renderToolbar.hasNextPage) { + _controller.reverse(); + _controller.addStatusListener(_statusListener); + _nextPage = _page + 1; + } + } + + void _handlePreviousPage() { + final RenderBox? renderToolbar = + _toolbarItemsKey.currentContext?.findRenderObject() as RenderBox?; + + if (renderToolbar is _RenderCupertinoTextSelectionToolbarItems && renderToolbar.hasPreviousPage) { + _controller.reverse(); + _controller.addStatusListener(_statusListener); + _nextPage = _page - 1; + } + } + + void _statusListener(AnimationStatus status) { + if (status != AnimationStatus.dismissed) { + return; + } + + setState(() { + _page = _nextPage!; + _nextPage = null; + }); + _controller.forward(); + _controller.removeStatusListener(_statusListener); + } + + @override + void initState() { + super.initState(); + _controller = AnimationController( + value: 1.0, + vsync: this, + // This was eyeballed on a physical iOS device running iOS 13. + duration: _kToolbarTransitionDuration, + ); + } + + @override + void didUpdateWidget(_CupertinoTextSelectionToolbarContent oldWidget) { + super.didUpdateWidget(oldWidget); + // If the children are changing, the current page should be reset. + if (widget.children != oldWidget.children) { + _page = 0; + _nextPage = null; + _controller.forward(); + _controller.removeStatusListener(_statusListener); + } + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final Color chevronColor = _kToolbarTextColor.resolveFrom(context); + + // Wrap the children and the chevron painters in Center with widthFactor + // and heightFactor of 1.0 so _CupertinoTextSelectionToolbarItems can get + // the natural size of the buttons and then expand vertically as needed. + final Widget backButton = Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: CupertinoTextSelectionToolbarButton( + onPressed: _handlePreviousPage, + child: IgnorePointer( + child: CustomPaint( + painter: _LeftCupertinoChevronPainter(color: chevronColor), + size: const Size.square(_kToolbarChevronSize), + ), + ), + ), + ); + final Widget nextButton = Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: CupertinoTextSelectionToolbarButton( + onPressed: _handleNextPage, + child: IgnorePointer( + child: CustomPaint( + painter: _RightCupertinoChevronPainter(color: chevronColor), + size: const Size.square(_kToolbarChevronSize), + ), + ), + ), + ); + final List children = widget.children.map((Widget child) { + return Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: child, + ); + }).toList(); + + return widget.toolbarBuilder(context, widget.anchorAbove, widget.anchorBelow, FadeTransition( + opacity: _controller, + child: AnimatedSize( + duration: _kToolbarTransitionDuration, + curve: Curves.decelerate, + child: GestureDetector( + onHorizontalDragEnd: _onHorizontalDragEnd, + child: _CupertinoTextSelectionToolbarItems( + key: _toolbarItemsKey, + page: _page, + backButton: backButton, + dividerColor: _kToolbarDividerColor.resolveFrom(context), + dividerWidth: 1.0 / MediaQuery.devicePixelRatioOf(context), + nextButton: nextButton, + children: children, + ), + ), + ), + )); + } +} + +// These classes help to test the chevrons. As _CupertinoChevronPainter must be +// private, it's possible to check the runtimeType of each chevron to know if +// they should be pointing left or right. +class _LeftCupertinoChevronPainter extends _CupertinoChevronPainter { + _LeftCupertinoChevronPainter({required super.color}) : super(isLeft: true); +} +class _RightCupertinoChevronPainter extends _CupertinoChevronPainter { + _RightCupertinoChevronPainter({required super.color}) : super(isLeft: false); +} +abstract class _CupertinoChevronPainter extends CustomPainter { + _CupertinoChevronPainter({ + required this.color, + required this.isLeft, + }); + + final Color color; + + /// If this is true the chevron will point left, else it will point right. + final bool isLeft; + + @override + void paint(Canvas canvas, Size size) { + assert(size.height == size.width, 'size must have the same height and width: $size'); + + final double iconSize = size.height; + + // The chevron is half of a square rotated 45˚, so it needs a margin of 1/4 + // its size on each side to be centered horizontally. + // + // If pointing left, it means the left half of a square is being used and + // the offset is positive. If pointing right, the right half is being used + // and the offset is negative. + final Offset centerOffset = Offset( + iconSize / 4 * (isLeft ? 1 : -1), + 0, + ); + + final Offset firstPoint = Offset(iconSize / 2, 0) + centerOffset; + final Offset middlePoint = Offset(isLeft ? 0 : iconSize, iconSize / 2) + centerOffset; + final Offset lowerPoint = Offset(iconSize / 2, iconSize) + centerOffset; + + final Paint paint = Paint() + ..color = color + ..style = PaintingStyle.stroke + ..strokeWidth = _kToolbarChevronThickness + ..strokeCap = StrokeCap.round + ..strokeJoin = StrokeJoin.round; + + // `drawLine` is used here because it's testable. When using `drawPath`, + // there's no way to test that the chevron points to the correct side. + canvas.drawLine(firstPoint, middlePoint, paint); + canvas.drawLine(middlePoint, lowerPoint, paint); + } + + @override + bool shouldRepaint(_CupertinoChevronPainter oldDelegate) => + oldDelegate.color != color || oldDelegate.isLeft != isLeft; +} + +// The custom RenderObjectWidget that, together with +// _RenderCupertinoTextSelectionToolbarItems and +// _CupertinoTextSelectionToolbarItemsElement, paginates the menu items. +class _CupertinoTextSelectionToolbarItems extends RenderObjectWidget { + _CupertinoTextSelectionToolbarItems({ + super.key, + required this.page, + required this.children, + required this.backButton, + required this.dividerColor, + required this.dividerWidth, + required this.nextButton, + }) : assert(children.isNotEmpty); + + final Widget backButton; + final List children; + final Color dividerColor; + final double dividerWidth; + final Widget nextButton; + final int page; + + @override + _RenderCupertinoTextSelectionToolbarItems createRenderObject(BuildContext context) { + return _RenderCupertinoTextSelectionToolbarItems( + dividerColor: dividerColor, + dividerWidth: dividerWidth, + page: page, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderCupertinoTextSelectionToolbarItems renderObject) { + renderObject + ..page = page + ..dividerColor = dividerColor + ..dividerWidth = dividerWidth; + } + + @override + _CupertinoTextSelectionToolbarItemsElement createElement() => _CupertinoTextSelectionToolbarItemsElement(this); +} + +// The custom RenderObjectElement that helps paginate the menu items. +class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement { + _CupertinoTextSelectionToolbarItemsElement( + _CupertinoTextSelectionToolbarItems super.widget, + ); + + late List _children; + final Map<_CupertinoTextSelectionToolbarItemsSlot, Element> slotToChild = <_CupertinoTextSelectionToolbarItemsSlot, Element>{}; + + // We keep a set of forgotten children to avoid O(n^2) work walking _children + // repeatedly to remove children. + final Set _forgottenChildren = HashSet(); + + @override + _RenderCupertinoTextSelectionToolbarItems get renderObject => super.renderObject as _RenderCupertinoTextSelectionToolbarItems; + + void _updateRenderObject(RenderBox? child, _CupertinoTextSelectionToolbarItemsSlot slot) { + switch (slot) { + case _CupertinoTextSelectionToolbarItemsSlot.backButton: + renderObject.backButton = child; + case _CupertinoTextSelectionToolbarItemsSlot.nextButton: + renderObject.nextButton = child; + } + } + + @override + void insertRenderObjectChild(RenderObject child, Object? slot) { + if (slot is _CupertinoTextSelectionToolbarItemsSlot) { + assert(child is RenderBox); + _updateRenderObject(child as RenderBox, slot); + assert(renderObject.slottedChildren.containsKey(slot)); + return; + } + if (slot is IndexedSlot) { + assert(renderObject.debugValidateChild(child)); + renderObject.insert(child as RenderBox, after: slot.value?.renderObject as RenderBox?); + return; + } + assert(false, 'slot must be _CupertinoTextSelectionToolbarItemsSlot or IndexedSlot'); + } + + // This is not reachable for children that don't have an IndexedSlot. + @override + void moveRenderObjectChild(RenderObject child, IndexedSlot oldSlot, IndexedSlot newSlot) { + assert(child.parent == renderObject); + renderObject.move(child as RenderBox, after: newSlot.value.renderObject as RenderBox?); + } + + static bool _shouldPaint(Element child) { + return (child.renderObject!.parentData! as ToolbarItemsParentData).shouldPaint; + } + + @override + void removeRenderObjectChild(RenderObject child, Object? slot) { + // Check if the child is in a slot. + if (slot is _CupertinoTextSelectionToolbarItemsSlot) { + assert(child is RenderBox); + assert(renderObject.slottedChildren.containsKey(slot)); + _updateRenderObject(null, slot); + assert(!renderObject.slottedChildren.containsKey(slot)); + return; + } + + // Otherwise look for it in the list of children. + assert(slot is IndexedSlot); + assert(child.parent == renderObject); + renderObject.remove(child as RenderBox); + } + + @override + void visitChildren(ElementVisitor visitor) { + slotToChild.values.forEach(visitor); + for (final Element child in _children) { + if (!_forgottenChildren.contains(child)) { + visitor(child); + } + } + } + + @override + void forgetChild(Element child) { + assert(slotToChild.containsValue(child) || _children.contains(child)); + assert(!_forgottenChildren.contains(child)); + // Handle forgetting a child in children or in a slot. + if (slotToChild.containsKey(child.slot)) { + final _CupertinoTextSelectionToolbarItemsSlot slot = child.slot! as _CupertinoTextSelectionToolbarItemsSlot; + slotToChild.remove(slot); + } else { + _forgottenChildren.add(child); + } + super.forgetChild(child); + } + + // Mount or update slotted child. + void _mountChild(Widget widget, _CupertinoTextSelectionToolbarItemsSlot slot) { + final Element? oldChild = slotToChild[slot]; + final Element? newChild = updateChild(oldChild, widget, slot); + if (oldChild != null) { + slotToChild.remove(slot); + } + if (newChild != null) { + slotToChild[slot] = newChild; + } + } + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + // Mount slotted children. + final _CupertinoTextSelectionToolbarItems toolbarItems = widget as _CupertinoTextSelectionToolbarItems; + _mountChild(toolbarItems.backButton, _CupertinoTextSelectionToolbarItemsSlot.backButton); + _mountChild(toolbarItems.nextButton, _CupertinoTextSelectionToolbarItemsSlot.nextButton); + + // Mount list children. + _children = List.filled(toolbarItems.children.length, _NullElement.instance); + Element? previousChild; + for (int i = 0; i < _children.length; i += 1) { + final Element newChild = inflateWidget(toolbarItems.children[i], IndexedSlot(i, previousChild)); + _children[i] = newChild; + previousChild = newChild; + } + } + + @override + void debugVisitOnstageChildren(ElementVisitor visitor) { + // Visit slot children. + for (final Element child in slotToChild.values) { + if (_shouldPaint(child) && !_forgottenChildren.contains(child)) { + visitor(child); + } + } + // Visit list children. + _children + .where((Element child) => !_forgottenChildren.contains(child) && _shouldPaint(child)) + .forEach(visitor); + } + + @override + void update(_CupertinoTextSelectionToolbarItems newWidget) { + super.update(newWidget); + assert(widget == newWidget); + + // Update slotted children. + final _CupertinoTextSelectionToolbarItems toolbarItems = widget as _CupertinoTextSelectionToolbarItems; + _mountChild(toolbarItems.backButton, _CupertinoTextSelectionToolbarItemsSlot.backButton); + _mountChild(toolbarItems.nextButton, _CupertinoTextSelectionToolbarItemsSlot.nextButton); + + // Update list children. + _children = updateChildren(_children, toolbarItems.children, forgottenChildren: _forgottenChildren); + _forgottenChildren.clear(); + } +} + +// The custom RenderBox that helps paginate the menu items. +class _RenderCupertinoTextSelectionToolbarItems extends RenderBox with ContainerRenderObjectMixin, RenderBoxContainerDefaultsMixin { + _RenderCupertinoTextSelectionToolbarItems({ + required Color dividerColor, + required double dividerWidth, + required int page, + }) : _dividerColor = dividerColor, + _dividerWidth = dividerWidth, + _page = page, + super(); + + final Map<_CupertinoTextSelectionToolbarItemsSlot, RenderBox> slottedChildren = <_CupertinoTextSelectionToolbarItemsSlot, RenderBox>{}; + + late bool hasNextPage; + late bool hasPreviousPage; + + RenderBox? _updateChild(RenderBox? oldChild, RenderBox? newChild, _CupertinoTextSelectionToolbarItemsSlot slot) { + if (oldChild != null) { + dropChild(oldChild); + slottedChildren.remove(slot); + } + if (newChild != null) { + slottedChildren[slot] = newChild; + adoptChild(newChild); + } + return newChild; + } + + int _page; + int get page => _page; + set page(int value) { + if (value == _page) { + return; + } + _page = value; + markNeedsLayout(); + } + + Color _dividerColor; + Color get dividerColor => _dividerColor; + set dividerColor(Color value) { + if (value == _dividerColor) { + return; + } + _dividerColor = value; + markNeedsLayout(); + } + + double _dividerWidth; + double get dividerWidth => _dividerWidth; + set dividerWidth(double value) { + if (value == _dividerWidth) { + return; + } + _dividerWidth = value; + markNeedsLayout(); + } + + RenderBox? _backButton; + RenderBox? get backButton => _backButton; + set backButton(RenderBox? value) { + _backButton = _updateChild(_backButton, value, _CupertinoTextSelectionToolbarItemsSlot.backButton); + } + + RenderBox? _nextButton; + RenderBox? get nextButton => _nextButton; + set nextButton(RenderBox? value) { + _nextButton = _updateChild(_nextButton, value, _CupertinoTextSelectionToolbarItemsSlot.nextButton); + } + + @override + void performLayout() { + if (firstChild == null) { + size = constraints.smallest; + return; + } + + // First pass: determine the height of the tallest child. + double greatestHeight = 0.0; + visitChildren((RenderObject renderObjectChild) { + final RenderBox child = renderObjectChild as RenderBox; + final double childHeight = child.getMaxIntrinsicHeight(constraints.maxWidth); + if (childHeight > greatestHeight) { + greatestHeight = childHeight; + } + }); + + // Layout slotted children. + final BoxConstraints slottedConstraints = BoxConstraints( + maxWidth: constraints.maxWidth, + minHeight: greatestHeight, + maxHeight: greatestHeight, + ); + _backButton!.layout(slottedConstraints, parentUsesSize: true); + _nextButton!.layout(slottedConstraints, parentUsesSize: true); + + final double subsequentPageButtonsWidth = _backButton!.size.width + _nextButton!.size.width; + double currentButtonPosition = 0.0; + late double toolbarWidth; // The width of the whole widget. + late double firstPageWidth; + int currentPage = 0; + int i = -1; + visitChildren((RenderObject renderObjectChild) { + i++; + final RenderBox child = renderObjectChild as RenderBox; + final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData; + childParentData.shouldPaint = false; + + // Skip slotted children and children on pages after the visible page. + if (child == _backButton || child == _nextButton || currentPage > _page) { + return; + } + + // If this is the last child on the first page, it's ok to fit without a forward button. + // Note childCount doesn't include slotted children which come before the list ones. + double paginationButtonsWidth = currentPage == 0 + ? i == childCount + 1 ? 0.0 : _nextButton!.size.width + : subsequentPageButtonsWidth; + + // The width of the menu is set by the first page. + child.layout( + BoxConstraints( + maxWidth: (currentPage == 0 ? constraints.maxWidth : firstPageWidth) - paginationButtonsWidth, + minHeight: greatestHeight, + maxHeight: greatestHeight, + ), + parentUsesSize: true, + ); + + // If this child causes the current page to overflow, move to the next + // page and relayout the child. + final double currentWidth = currentButtonPosition + paginationButtonsWidth + child.size.width; + if (currentWidth > constraints.maxWidth) { + currentPage++; + currentButtonPosition = _backButton!.size.width + dividerWidth; + paginationButtonsWidth = _backButton!.size.width + _nextButton!.size.width; + child.layout( + BoxConstraints( + maxWidth: firstPageWidth - paginationButtonsWidth, + minHeight: greatestHeight, + maxHeight: greatestHeight, + ), + parentUsesSize: true, + ); + } + childParentData.offset = Offset(currentButtonPosition, 0.0); + currentButtonPosition += child.size.width + dividerWidth; + childParentData.shouldPaint = currentPage == page; + + if (currentPage == 0) { + firstPageWidth = currentButtonPosition + _nextButton!.size.width; + } + if (currentPage == page) { + toolbarWidth = currentButtonPosition; + } + }); + + // It shouldn't be possible to navigate beyond the last page. + assert(page <= currentPage); + + // Position page nav buttons. + if (currentPage > 0) { + final ToolbarItemsParentData nextButtonParentData = _nextButton!.parentData! as ToolbarItemsParentData; + final ToolbarItemsParentData backButtonParentData = _backButton!.parentData! as ToolbarItemsParentData; + // The forward button only shows when there's a page after this one. + if (page != currentPage) { + nextButtonParentData.offset = Offset(toolbarWidth, 0.0); + nextButtonParentData.shouldPaint = true; + toolbarWidth += nextButton!.size.width; + } + if (page > 0) { + backButtonParentData.offset = Offset.zero; + backButtonParentData.shouldPaint = true; + // No need to add the width of the back button to toolbarWidth here. It's + // already been taken care of when laying out the children to + // accommodate the back button. + } + } else { + // No divider for the next button when there's only one page. + toolbarWidth -= dividerWidth; + } + + // Update previous/next page values so that we can check in the horizontal + // drag gesture callback if it's possible to navigate. + hasNextPage = page != currentPage; + hasPreviousPage = page > 0; + + size = constraints.constrain(Size(toolbarWidth, greatestHeight)); + } + + @override + void paint(PaintingContext context, Offset offset) { + visitChildren((RenderObject renderObjectChild) { + final RenderBox child = renderObjectChild as RenderBox; + final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData; + + if (childParentData.shouldPaint) { + final Offset childOffset = childParentData.offset + offset; + context.paintChild(child, childOffset); + + // backButton is a slotted child and is not in the children list, so its + // childParentData.nextSibling is null. So either when there's a + // nextSibling or when child is the backButton, draw a divider to the + // child's right. + if (childParentData.nextSibling != null || child == backButton) { + context.canvas.drawLine( + Offset(child.size.width, 0) + childOffset, + Offset(child.size.width, child.size.height) + childOffset, + Paint()..color = dividerColor, + ); + } + } + }); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! ToolbarItemsParentData) { + child.parentData = ToolbarItemsParentData(); + } + } + + // Returns true if the single child is hit by the given position. + static bool hitTestChild(RenderBox? child, BoxHitTestResult result, { required Offset position }) { + if (child == null) { + return false; + } + final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData; + if (!childParentData.shouldPaint) { + return false; + } + return result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - childParentData.offset); + return child.hitTest(result, position: transformed); + }, + ); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + // Hit test list children. + RenderBox? child = lastChild; + while (child != null) { + final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData; + + // Don't hit test children that aren't shown. + if (!childParentData.shouldPaint) { + child = childParentData.previousSibling; + continue; + } + + if (hitTestChild(child, result, position: position)) { + return true; + } + child = childParentData.previousSibling; + } + + // Hit test slot children. + if (hitTestChild(backButton, result, position: position)) { + return true; + } + if (hitTestChild(nextButton, result, position: position)) { + return true; + } + + return false; + } + + @override + void attach(PipelineOwner owner) { + // Attach list children. + super.attach(owner); + + // Attach slot children. + for (final RenderBox child in slottedChildren.values) { + child.attach(owner); + } + } + + @override + void detach() { + // Detach list children. + super.detach(); + + // Detach slot children. + for (final RenderBox child in slottedChildren.values) { + child.detach(); + } + } + + @override + void redepthChildren() { + visitChildren((RenderObject renderObjectChild) { + final RenderBox child = renderObjectChild as RenderBox; + redepthChild(child); + }); + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + // Visit the slotted children. + if (_backButton != null) { + visitor(_backButton!); + } + if (_nextButton != null) { + visitor(_nextButton!); + } + // Visit the list children. + super.visitChildren(visitor); + } + + // Visit only the children that should be painted. + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + visitChildren((RenderObject renderObjectChild) { + final RenderBox child = renderObjectChild as RenderBox; + final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData; + if (childParentData.shouldPaint) { + visitor(renderObjectChild); + } + }); + } + + @override + List debugDescribeChildren() { + final List value = []; + visitChildren((RenderObject renderObjectChild) { + final RenderBox child = renderObjectChild as RenderBox; + if (child == backButton) { + value.add(child.toDiagnosticsNode(name: 'back button')); + } else if (child == nextButton) { + value.add(child.toDiagnosticsNode(name: 'next button')); + + // List children. + } else { + value.add(child.toDiagnosticsNode(name: 'menu item')); + } + }); + return value; + } +} + +// The slots that can be occupied by widgets in +// _CupertinoTextSelectionToolbarItems, excluding the list of children. +enum _CupertinoTextSelectionToolbarItemsSlot { + backButton, + nextButton, +} + +class _NullElement extends Element { + _NullElement() : super(const _NullWidget()); + + static _NullElement instance = _NullElement(); + + @override + bool get debugDoingBuild => throw UnimplementedError(); +} + +class _NullWidget extends Widget { + const _NullWidget(); + + @override + Element createElement() => throw UnimplementedError(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_selection_toolbar_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_selection_toolbar_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..cc991db20d651087d246c9d128ae55073d0d6a87 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_selection_toolbar_button.dart @@ -0,0 +1,255 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math'; + +import 'package:flutter/widgets.dart'; + +import 'button.dart'; +import 'colors.dart'; +import 'debug.dart'; +import 'localizations.dart'; + +const TextStyle _kToolbarButtonFontStyle = TextStyle( + inherit: false, + fontSize: 15.0, + letterSpacing: -0.15, + fontWeight: FontWeight.w400, +); + +const CupertinoDynamicColor _kToolbarTextColor = CupertinoDynamicColor.withBrightness( + color: CupertinoColors.black, + darkColor: CupertinoColors.white, +); + +const CupertinoDynamicColor _kToolbarPressedColor = CupertinoDynamicColor.withBrightness( + color: Color(0x10000000), + darkColor: Color(0x10FFFFFF), +); + +// Value measured from screenshot of iOS 16.0.2 +const EdgeInsets _kToolbarButtonPadding = EdgeInsets.symmetric(vertical: 18.0, horizontal: 16.0); + +/// A button in the style of the iOS text selection toolbar buttons. +class CupertinoTextSelectionToolbarButton extends StatefulWidget { + /// Create an instance of [CupertinoTextSelectionToolbarButton]. + const CupertinoTextSelectionToolbarButton({ + super.key, + this.onPressed, + required Widget this.child, + }) : text = null, + buttonItem = null; + + /// Create an instance of [CupertinoTextSelectionToolbarButton] whose child is + /// a [Text] widget styled like the default iOS text selection toolbar button. + const CupertinoTextSelectionToolbarButton.text({ + super.key, + this.onPressed, + required this.text, + }) : buttonItem = null, + child = null; + + /// Create an instance of [CupertinoTextSelectionToolbarButton] from the given + /// [ContextMenuButtonItem]. + CupertinoTextSelectionToolbarButton.buttonItem({ + super.key, + required ContextMenuButtonItem this.buttonItem, + }) : child = null, + text = null, + onPressed = buttonItem.onPressed; + + /// {@template flutter.cupertino.CupertinoTextSelectionToolbarButton.child} + /// The child of this button. + /// + /// Usually a [Text] or an [Icon]. + /// {@endtemplate} + final Widget? child; + + /// {@template flutter.cupertino.CupertinoTextSelectionToolbarButton.onPressed} + /// Called when this button is pressed. + /// {@endtemplate} + final VoidCallback? onPressed; + + /// {@template flutter.cupertino.CupertinoTextSelectionToolbarButton.onPressed} + /// The buttonItem used to generate the button when using + /// [CupertinoTextSelectionToolbarButton.buttonItem]. + /// {@endtemplate} + final ContextMenuButtonItem? buttonItem; + + /// {@template flutter.cupertino.CupertinoTextSelectionToolbarButton.text} + /// The text used in the button's label when using + /// [CupertinoTextSelectionToolbarButton.text]. + /// {@endtemplate} + final String? text; + + /// Returns the default button label String for the button of the given + /// [ContextMenuButtonItem]'s [ContextMenuButtonType]. + static String getButtonLabel(BuildContext context, ContextMenuButtonItem buttonItem) { + if (buttonItem.label != null) { + return buttonItem.label!; + } + + assert(debugCheckHasCupertinoLocalizations(context)); + final CupertinoLocalizations localizations = CupertinoLocalizations.of(context); + switch (buttonItem.type) { + case ContextMenuButtonType.cut: + return localizations.cutButtonLabel; + case ContextMenuButtonType.copy: + return localizations.copyButtonLabel; + case ContextMenuButtonType.paste: + return localizations.pasteButtonLabel; + case ContextMenuButtonType.selectAll: + return localizations.selectAllButtonLabel; + case ContextMenuButtonType.lookUp: + return localizations.lookUpButtonLabel; + case ContextMenuButtonType.searchWeb: + return localizations.searchWebButtonLabel; + case ContextMenuButtonType.share: + return localizations.shareButtonLabel; + case ContextMenuButtonType.liveTextInput: + case ContextMenuButtonType.delete: + case ContextMenuButtonType.custom: + return ''; + } + } + + @override + State createState() => _CupertinoTextSelectionToolbarButtonState(); +} + +class _CupertinoTextSelectionToolbarButtonState extends State { + bool isPressed = false; + + void _onTapDown(TapDownDetails details) { + setState(() => isPressed = true); + } + + void _onTapUp(TapUpDetails details) { + setState(() => isPressed = false); + widget.onPressed?.call(); + } + + void _onTapCancel() { + setState(() => isPressed = false); + } + + @override + Widget build(BuildContext context) { + final Widget content = _getContentWidget(context); + final Widget child = CupertinoButton( + color: isPressed + ? _kToolbarPressedColor.resolveFrom(context) + : const Color(0x00000000), + borderRadius: null, + disabledColor: const Color(0x00000000), + // This CupertinoButton does not actually handle the onPressed callback, + // this is only here to correctly enable/disable the button (see + // GestureDetector comment below). + onPressed: widget.onPressed, + padding: _kToolbarButtonPadding, + // There's no foreground fade on iOS toolbar anymore, just the background + // is darkened. + pressedOpacity: 1.0, + child: content, + ); + + if (widget.onPressed != null) { + // As it's needed to change the CupertinoButton's backgroundColor when + // pressed, not its opacity, this GestureDetector handles both the + // onPressed callback and the backgroundColor change. + return GestureDetector( + onTapDown: _onTapDown, + onTapUp: _onTapUp, + onTapCancel: _onTapCancel, + child: child, + ); + } else { + return child; + } + } + + Widget _getContentWidget(BuildContext context) { + if (widget.child != null) { + return widget.child!; + } + final Widget textWidget = Text( + widget.text ?? CupertinoTextSelectionToolbarButton.getButtonLabel(context, widget.buttonItem!), + overflow: TextOverflow.ellipsis, + style: _kToolbarButtonFontStyle.copyWith( + color: widget.onPressed != null + ? _kToolbarTextColor.resolveFrom(context) + : CupertinoColors.inactiveGray, + ), + ); + if (widget.buttonItem == null) { + return textWidget; + } + switch (widget.buttonItem!.type) { + case ContextMenuButtonType.cut: + case ContextMenuButtonType.copy: + case ContextMenuButtonType.paste: + case ContextMenuButtonType.selectAll: + case ContextMenuButtonType.delete: + case ContextMenuButtonType.lookUp: + case ContextMenuButtonType.searchWeb: + case ContextMenuButtonType.share: + case ContextMenuButtonType.custom: + return textWidget; + case ContextMenuButtonType.liveTextInput: + return SizedBox( + width: 13.0, + height: 13.0, + child: CustomPaint( + painter: _LiveTextIconPainter(color: _kToolbarTextColor.resolveFrom(context)), + ), + ); + } + } +} + +class _LiveTextIconPainter extends CustomPainter { + _LiveTextIconPainter({required this.color}); + + final Color color; + + final Paint _painter = Paint() + ..strokeCap = StrokeCap.round + ..strokeJoin = StrokeJoin.round + ..strokeWidth = 1.0 + ..style = PaintingStyle.stroke; + + @override + void paint(Canvas canvas, Size size) { + _painter.color = color; + canvas.save(); + canvas.translate(size.width / 2.0, size.height / 2.0); + + final Offset origin = Offset(-size.width / 2.0, -size.height / 2.0); + // Path for the one corner. + final Path path = Path() + ..moveTo(origin.dx, origin.dy + 3.5) + ..lineTo(origin.dx, origin.dy + 1.0) + ..arcToPoint(Offset(origin.dx + 1.0, origin.dy), radius: const Radius.circular(1)) + ..lineTo(origin.dx + 3.5, origin.dy); + + // Rotate to draw corner four times. + final Matrix4 rotationMatrix = Matrix4.identity()..rotateZ(pi / 2.0); + for (int i = 0; i < 4; i += 1) { + canvas.drawPath(path, _painter); + canvas.transform(rotationMatrix.storage); + } + + // Draw three lines. + canvas.drawLine(const Offset(-3.0, -3.0), const Offset(3.0, -3.0), _painter); + canvas.drawLine(const Offset(-3.0, 0.0), const Offset(3.0, 0.0), _painter); + canvas.drawLine(const Offset(-3.0, 3.0), const Offset(1.0, 3.0), _painter); + + canvas.restore(); + } + + @override + bool shouldRepaint(covariant _LiveTextIconPainter oldDelegate) { + return oldDelegate.color != color; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..b325148ab175db66fd33cd2a34c0e2a8d3fef301 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/text_theme.dart @@ -0,0 +1,351 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; + +// Please update _TextThemeDefaultsBuilder accordingly after changing the default +// color here, as their implementation depends on the default value of the color +// field. +// +// Values derived from https://developer.apple.com/design/resources/. +const TextStyle _kDefaultTextStyle = TextStyle( + inherit: false, + fontFamily: 'CupertinoSystemText', + fontSize: 17.0, + letterSpacing: -0.41, + color: CupertinoColors.label, + decoration: TextDecoration.none, +); + +// Please update _TextThemeDefaultsBuilder accordingly after changing the default +// color here, as their implementation depends on the default value of the color +// field. +// +// Values derived from https://developer.apple.com/design/resources/. +const TextStyle _kDefaultActionTextStyle = TextStyle( + inherit: false, + fontFamily: 'CupertinoSystemText', + fontSize: 17.0, + letterSpacing: -0.41, + color: CupertinoColors.activeBlue, + decoration: TextDecoration.none, +); + +// Please update _TextThemeDefaultsBuilder accordingly after changing the default +// color here, as their implementation depends on the default value of the color +// field. +// +// Values derived from https://developer.apple.com/design/resources/. +const TextStyle _kDefaultTabLabelTextStyle = TextStyle( + inherit: false, + fontFamily: 'CupertinoSystemText', + fontSize: 10.0, + fontWeight: FontWeight.w500, + letterSpacing: -0.24, + color: CupertinoColors.inactiveGray, +); + +const TextStyle _kDefaultMiddleTitleTextStyle = TextStyle( + inherit: false, + fontFamily: 'CupertinoSystemText', + fontSize: 17.0, + fontWeight: FontWeight.w600, + letterSpacing: -0.41, + color: CupertinoColors.label, +); + +const TextStyle _kDefaultLargeTitleTextStyle = TextStyle( + inherit: false, + fontFamily: 'CupertinoSystemDisplay', + fontSize: 34.0, + fontWeight: FontWeight.w700, + letterSpacing: 0.38, + color: CupertinoColors.label, +); + +// Please update _TextThemeDefaultsBuilder accordingly after changing the default +// color here, as their implementation depends on the default value of the color +// field. +// +// Inspected on iOS 13 simulator with "Debug View Hierarchy". +// Value extracted from off-center labels. Centered labels have a font size of 25pt. +// +// The letterSpacing sourced from iOS 14 simulator screenshots for comparison. +// See also: +// +// * https://github.com/flutter/flutter/pull/65501#discussion_r486557093 +const TextStyle _kDefaultPickerTextStyle = TextStyle( + inherit: false, + fontFamily: 'CupertinoSystemDisplay', + fontSize: 21.0, + fontWeight: FontWeight.w400, + letterSpacing: -0.6, + color: CupertinoColors.label, +); + +// Please update _TextThemeDefaultsBuilder accordingly after changing the default +// color here, as their implementation depends on the default value of the color +// field. +// +// Inspected on iOS 13 simulator with "Debug View Hierarchy". +// Value extracted from off-center labels. Centered labels have a font size of 25pt. +const TextStyle _kDefaultDateTimePickerTextStyle = TextStyle( + inherit: false, + fontFamily: 'CupertinoSystemDisplay', + fontSize: 21, + letterSpacing: 0.4, + fontWeight: FontWeight.normal, + color: CupertinoColors.label, +); + +TextStyle? _resolveTextStyle(TextStyle? style, BuildContext context) { + // This does not resolve the shadow color, foreground, background, etc. + return style?.copyWith( + color: CupertinoDynamicColor.maybeResolve(style.color, context), + backgroundColor: CupertinoDynamicColor.maybeResolve(style.backgroundColor, context), + decorationColor: CupertinoDynamicColor.maybeResolve(style.decorationColor, context), + ); +} + +/// Cupertino typography theme in a [CupertinoThemeData]. +@immutable +class CupertinoTextThemeData with Diagnosticable { + /// Create a [CupertinoTextThemeData]. + /// + /// The [primaryColor] is used to derive TextStyle defaults of other attributes + /// such as [navActionTextStyle] and [actionTextStyle]. It must not be null when + /// either [navActionTextStyle] or [actionTextStyle] is null. Defaults to + /// [CupertinoColors.systemBlue]. + /// + /// Other [TextStyle] parameters default to default iOS text styles when + /// unspecified. + const CupertinoTextThemeData({ + Color primaryColor = CupertinoColors.systemBlue, + TextStyle? textStyle, + TextStyle? actionTextStyle, + TextStyle? tabLabelTextStyle, + TextStyle? navTitleTextStyle, + TextStyle? navLargeTitleTextStyle, + TextStyle? navActionTextStyle, + TextStyle? pickerTextStyle, + TextStyle? dateTimePickerTextStyle, + }) : this._raw( + const _TextThemeDefaultsBuilder(CupertinoColors.label, CupertinoColors.inactiveGray), + primaryColor, + textStyle, + actionTextStyle, + tabLabelTextStyle, + navTitleTextStyle, + navLargeTitleTextStyle, + navActionTextStyle, + pickerTextStyle, + dateTimePickerTextStyle, + ); + + const CupertinoTextThemeData._raw( + this._defaults, + this._primaryColor, + this._textStyle, + this._actionTextStyle, + this._tabLabelTextStyle, + this._navTitleTextStyle, + this._navLargeTitleTextStyle, + this._navActionTextStyle, + this._pickerTextStyle, + this._dateTimePickerTextStyle, + ) : assert((_navActionTextStyle != null && _actionTextStyle != null) || _primaryColor != null); + + final _TextThemeDefaultsBuilder _defaults; + final Color? _primaryColor; + + final TextStyle? _textStyle; + /// The [TextStyle] of general text content for Cupertino widgets. + TextStyle get textStyle => _textStyle ?? _defaults.textStyle; + + final TextStyle? _actionTextStyle; + /// The [TextStyle] of interactive text content such as text in a button without background. + TextStyle get actionTextStyle { + return _actionTextStyle ?? _defaults.actionTextStyle(primaryColor: _primaryColor); + } + + final TextStyle? _tabLabelTextStyle; + /// The [TextStyle] of unselected tabs. + TextStyle get tabLabelTextStyle => _tabLabelTextStyle ?? _defaults.tabLabelTextStyle; + + final TextStyle? _navTitleTextStyle; + /// The [TextStyle] of titles in standard navigation bars. + TextStyle get navTitleTextStyle => _navTitleTextStyle ?? _defaults.navTitleTextStyle; + + final TextStyle? _navLargeTitleTextStyle; + /// The [TextStyle] of large titles in sliver navigation bars. + TextStyle get navLargeTitleTextStyle => _navLargeTitleTextStyle ?? _defaults.navLargeTitleTextStyle; + + final TextStyle? _navActionTextStyle; + /// The [TextStyle] of interactive text content in navigation bars. + TextStyle get navActionTextStyle { + return _navActionTextStyle ?? _defaults.navActionTextStyle(primaryColor: _primaryColor); + } + + final TextStyle? _pickerTextStyle; + /// The [TextStyle] of pickers. + TextStyle get pickerTextStyle => _pickerTextStyle ?? _defaults.pickerTextStyle; + + final TextStyle? _dateTimePickerTextStyle; + /// The [TextStyle] of date time pickers. + TextStyle get dateTimePickerTextStyle => _dateTimePickerTextStyle ?? _defaults.dateTimePickerTextStyle; + + /// Returns a copy of the current [CupertinoTextThemeData] with all the colors + /// resolved against the given [BuildContext]. + /// + /// If any of the [InheritedWidget]s required to resolve this + /// [CupertinoTextThemeData] is not found in [context], any unresolved + /// [CupertinoDynamicColor]s will use the default trait value + /// ([Brightness.light] platform brightness, normal contrast, + /// [CupertinoUserInterfaceLevelData.base] elevation level). + CupertinoTextThemeData resolveFrom(BuildContext context) { + return CupertinoTextThemeData._raw( + _defaults.resolveFrom(context), + CupertinoDynamicColor.maybeResolve(_primaryColor, context), + _resolveTextStyle(_textStyle, context), + _resolveTextStyle(_actionTextStyle, context), + _resolveTextStyle(_tabLabelTextStyle, context), + _resolveTextStyle(_navTitleTextStyle, context), + _resolveTextStyle(_navLargeTitleTextStyle, context), + _resolveTextStyle(_navActionTextStyle, context), + _resolveTextStyle(_pickerTextStyle, context), + _resolveTextStyle(_dateTimePickerTextStyle, context), + ); + } + + /// Returns a copy of the current [CupertinoTextThemeData] instance with + /// specified overrides. + CupertinoTextThemeData copyWith({ + Color? primaryColor, + TextStyle? textStyle, + TextStyle? actionTextStyle, + TextStyle? tabLabelTextStyle, + TextStyle? navTitleTextStyle, + TextStyle? navLargeTitleTextStyle, + TextStyle? navActionTextStyle, + TextStyle? pickerTextStyle, + TextStyle? dateTimePickerTextStyle, + }) { + return CupertinoTextThemeData._raw( + _defaults, + primaryColor ?? _primaryColor, + textStyle ?? _textStyle, + actionTextStyle ?? _actionTextStyle, + tabLabelTextStyle ?? _tabLabelTextStyle, + navTitleTextStyle ?? _navTitleTextStyle, + navLargeTitleTextStyle ?? _navLargeTitleTextStyle, + navActionTextStyle ?? _navActionTextStyle, + pickerTextStyle ?? _pickerTextStyle, + dateTimePickerTextStyle ?? _dateTimePickerTextStyle, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + const CupertinoTextThemeData defaultData = CupertinoTextThemeData(); + properties.add(DiagnosticsProperty('textStyle', textStyle, defaultValue: defaultData.textStyle)); + properties.add(DiagnosticsProperty('actionTextStyle', actionTextStyle, defaultValue: defaultData.actionTextStyle)); + properties.add(DiagnosticsProperty('tabLabelTextStyle', tabLabelTextStyle, defaultValue: defaultData.tabLabelTextStyle)); + properties.add(DiagnosticsProperty('navTitleTextStyle', navTitleTextStyle, defaultValue: defaultData.navTitleTextStyle)); + properties.add(DiagnosticsProperty('navLargeTitleTextStyle', navLargeTitleTextStyle, defaultValue: defaultData.navLargeTitleTextStyle)); + properties.add(DiagnosticsProperty('navActionTextStyle', navActionTextStyle, defaultValue: defaultData.navActionTextStyle)); + properties.add(DiagnosticsProperty('pickerTextStyle', pickerTextStyle, defaultValue: defaultData.pickerTextStyle)); + properties.add(DiagnosticsProperty('dateTimePickerTextStyle', dateTimePickerTextStyle, defaultValue: defaultData.dateTimePickerTextStyle)); + } + + @override + bool operator == (Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is CupertinoTextThemeData + && other._defaults == _defaults + && other._primaryColor == _primaryColor + && other._textStyle == _textStyle + && other._actionTextStyle == _actionTextStyle + && other._tabLabelTextStyle == _tabLabelTextStyle + && other._navTitleTextStyle == _navTitleTextStyle + && other._navLargeTitleTextStyle == _navLargeTitleTextStyle + && other._navActionTextStyle == _navActionTextStyle + && other._pickerTextStyle == _pickerTextStyle + && other._dateTimePickerTextStyle == _dateTimePickerTextStyle; + } + + @override + int get hashCode => Object.hash( + _defaults, + _primaryColor, + _textStyle, + _actionTextStyle, + _tabLabelTextStyle, + _navTitleTextStyle, + _navLargeTitleTextStyle, + _navActionTextStyle, + _pickerTextStyle, + _dateTimePickerTextStyle, + ); +} + + +@immutable +class _TextThemeDefaultsBuilder { + const _TextThemeDefaultsBuilder( + this.labelColor, + this.inactiveGrayColor, + ); + + final Color labelColor; + final Color inactiveGrayColor; + + static TextStyle _applyLabelColor(TextStyle original, Color color) { + return original.color == color + ? original + : original.copyWith(color: color); + } + + TextStyle get textStyle => _applyLabelColor(_kDefaultTextStyle, labelColor); + TextStyle get tabLabelTextStyle => _applyLabelColor(_kDefaultTabLabelTextStyle, inactiveGrayColor); + TextStyle get navTitleTextStyle => _applyLabelColor(_kDefaultMiddleTitleTextStyle, labelColor); + TextStyle get navLargeTitleTextStyle => _applyLabelColor(_kDefaultLargeTitleTextStyle, labelColor); + TextStyle get pickerTextStyle => _applyLabelColor(_kDefaultPickerTextStyle, labelColor); + TextStyle get dateTimePickerTextStyle => _applyLabelColor(_kDefaultDateTimePickerTextStyle, labelColor); + + TextStyle actionTextStyle({ Color? primaryColor }) => _kDefaultActionTextStyle.copyWith(color: primaryColor); + TextStyle navActionTextStyle({ Color? primaryColor }) => actionTextStyle(primaryColor: primaryColor); + + _TextThemeDefaultsBuilder resolveFrom(BuildContext context) { + final Color resolvedLabelColor = CupertinoDynamicColor.resolve(labelColor, context); + final Color resolvedInactiveGray = CupertinoDynamicColor.resolve(inactiveGrayColor, context); + return resolvedLabelColor == labelColor && resolvedInactiveGray == CupertinoColors.inactiveGray + ? this + : _TextThemeDefaultsBuilder(resolvedLabelColor, resolvedInactiveGray); + } + + @override + bool operator == (Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is _TextThemeDefaultsBuilder + && other.labelColor == labelColor + && other.inactiveGrayColor == inactiveGrayColor; + } + + @override + int get hashCode => Object.hash(labelColor, inactiveGrayColor); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..b4daa961c138370deb1c2857a59caa397dc93ed3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/theme.dart @@ -0,0 +1,595 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'icon_theme_data.dart'; +import 'text_theme.dart'; + +export 'package:flutter/foundation.dart' show Brightness; + +// Values derived from https://developer.apple.com/design/resources/. +const _CupertinoThemeDefaults _kDefaultTheme = _CupertinoThemeDefaults( + null, + CupertinoColors.systemBlue, + CupertinoColors.systemBackground, + CupertinoDynamicColor.withBrightness( + color: Color(0xF0F9F9F9), + darkColor: Color(0xF01D1D1D), + // Values extracted from navigation bar. For toolbar or tabbar the dark color is 0xF0161616. + ), + CupertinoColors.systemBackground, + false, + _CupertinoTextThemeDefaults(CupertinoColors.label, CupertinoColors.inactiveGray), +); + +/// Applies a visual styling theme to descendant Cupertino widgets. +/// +/// Affects the color and text styles of Cupertino widgets whose styling +/// are not overridden when constructing the respective widgets instances. +/// +/// Descendant widgets can retrieve the current [CupertinoThemeData] by calling +/// [CupertinoTheme.of]. An [InheritedWidget] dependency is created when +/// an ancestor [CupertinoThemeData] is retrieved via [CupertinoTheme.of]. +/// +/// The [CupertinoTheme] widget implies an [IconTheme] widget, whose +/// [IconTheme.data] has the same color as [CupertinoThemeData.primaryColor] +/// +/// See also: +/// +/// * [CupertinoThemeData], specifies the theme's visual styling. +/// * [CupertinoApp], which will automatically add a [CupertinoTheme] based on the +/// value of [CupertinoApp.theme]. +/// * [Theme], a Material theme which will automatically add a [CupertinoTheme] +/// with a [CupertinoThemeData] derived from the Material [ThemeData]. +class CupertinoTheme extends StatelessWidget { + /// Creates a [CupertinoTheme] to change descendant Cupertino widgets' styling. + const CupertinoTheme({ + super.key, + required this.data, + required this.child, + }); + + /// The [CupertinoThemeData] styling for this theme. + final CupertinoThemeData data; + + /// Retrieves the [CupertinoThemeData] from the closest ancestor [CupertinoTheme] + /// widget, or a default [CupertinoThemeData] if no [CupertinoTheme] ancestor + /// exists. + /// + /// Resolves all the colors defined in that [CupertinoThemeData] against the + /// given [BuildContext] on a best-effort basis. + static CupertinoThemeData of(BuildContext context) { + final _InheritedCupertinoTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>(); + return (inheritedTheme?.theme.data ?? const CupertinoThemeData()).resolveFrom(context); + } + + /// Retrieves the [Brightness] to use for descendant Cupertino widgets, based + /// on the value of [CupertinoThemeData.brightness] in the given [context]. + /// + /// If no [CupertinoTheme] can be found in the given [context], or its `brightness` + /// is null, it will fall back to [MediaQueryData.platformBrightness]. + /// + /// Throws an exception if no valid [CupertinoTheme] or [MediaQuery] widgets + /// exist in the ancestry tree. + /// + /// See also: + /// + /// * [maybeBrightnessOf], which returns null if no valid [CupertinoTheme] or + /// [MediaQuery] exists, instead of throwing. + /// * [CupertinoThemeData.brightness], the property takes precedence over + /// [MediaQueryData.platformBrightness] for descendant Cupertino widgets. + static Brightness brightnessOf(BuildContext context) { + final _InheritedCupertinoTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>(); + return inheritedTheme?.theme.data.brightness ?? MediaQuery.platformBrightnessOf(context); + } + + /// Retrieves the [Brightness] to use for descendant Cupertino widgets, based + /// on the value of [CupertinoThemeData.brightness] in the given [context]. + /// + /// If no [CupertinoTheme] can be found in the given [context], it will fall + /// back to [MediaQueryData.platformBrightness]. + /// + /// Returns null if no valid [CupertinoTheme] or [MediaQuery] widgets exist in + /// the ancestry tree. + /// + /// See also: + /// + /// * [CupertinoThemeData.brightness], the property takes precedence over + /// [MediaQueryData.platformBrightness] for descendant Cupertino widgets. + /// * [brightnessOf], which throws if no valid [CupertinoTheme] or + /// [MediaQuery] exists, instead of returning null. + static Brightness? maybeBrightnessOf(BuildContext context) { + final _InheritedCupertinoTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>(); + return inheritedTheme?.theme.data.brightness ?? MediaQuery.maybePlatformBrightnessOf(context); + } + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + return _InheritedCupertinoTheme( + theme: this, + child: IconTheme( + data: CupertinoIconThemeData(color: data.primaryColor), + child: child, + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + data.debugFillProperties(properties); + } +} + +class _InheritedCupertinoTheme extends InheritedWidget { + const _InheritedCupertinoTheme({ + required this.theme, + required super.child, + }); + + final CupertinoTheme theme; + + @override + bool updateShouldNotify(_InheritedCupertinoTheme old) => theme.data != old.theme.data; +} + +/// Styling specifications for a [CupertinoTheme]. +/// +/// All constructor parameters can be null, in which case a +/// [CupertinoColors.activeBlue] based default iOS theme styling is used. +/// +/// Parameters can also be partially specified, in which case some parameters +/// will cascade down to other dependent parameters to create a cohesive +/// visual effect. For instance, if a [primaryColor] is specified, it would +/// cascade down to affect some fonts in [textTheme] if [textTheme] is not +/// specified. +/// +/// See also: +/// +/// * [CupertinoTheme], in which this [CupertinoThemeData] is inserted. +/// * [ThemeData], a Material equivalent that also configures Cupertino +/// styling via a [CupertinoThemeData] subclass [MaterialBasedCupertinoThemeData]. +@immutable +class CupertinoThemeData extends NoDefaultCupertinoThemeData with Diagnosticable { + /// Creates a [CupertinoTheme] styling specification. + /// + /// Unspecified parameters default to a reasonable iOS default style. + const CupertinoThemeData({ + Brightness? brightness, + Color? primaryColor, + Color? primaryContrastingColor, + CupertinoTextThemeData? textTheme, + Color? barBackgroundColor, + Color? scaffoldBackgroundColor, + bool? applyThemeToAll, + }) : this.raw( + brightness, + primaryColor, + primaryContrastingColor, + textTheme, + barBackgroundColor, + scaffoldBackgroundColor, + applyThemeToAll, + ); + + /// Same as the default constructor but with positional arguments to avoid + /// forgetting any and to specify all arguments. + /// + /// Used by subclasses to get the superclass's defaulting behaviors. + @protected + const CupertinoThemeData.raw( + Brightness? brightness, + Color? primaryColor, + Color? primaryContrastingColor, + CupertinoTextThemeData? textTheme, + Color? barBackgroundColor, + Color? scaffoldBackgroundColor, + bool? applyThemeToAll, + ) : this._rawWithDefaults( + brightness, + primaryColor, + primaryContrastingColor, + textTheme, + barBackgroundColor, + scaffoldBackgroundColor, + applyThemeToAll, + _kDefaultTheme, + ); + + const CupertinoThemeData._rawWithDefaults( + Brightness? brightness, + Color? primaryColor, + Color? primaryContrastingColor, + CupertinoTextThemeData? textTheme, + Color? barBackgroundColor, + Color? scaffoldBackgroundColor, + bool? applyThemeToAll, + this._defaults, + ) : super( + brightness: brightness, + primaryColor: primaryColor, + primaryContrastingColor: primaryContrastingColor, + textTheme: textTheme, + barBackgroundColor: barBackgroundColor, + scaffoldBackgroundColor: scaffoldBackgroundColor, + applyThemeToAll: applyThemeToAll, + ); + + final _CupertinoThemeDefaults _defaults; + + @override + Color get primaryColor => super.primaryColor ?? _defaults.primaryColor; + + @override + Color get primaryContrastingColor => super.primaryContrastingColor ?? _defaults.primaryContrastingColor; + + @override + CupertinoTextThemeData get textTheme { + return super.textTheme ?? _defaults.textThemeDefaults.createDefaults(primaryColor: primaryColor); + } + + @override + Color get barBackgroundColor => super.barBackgroundColor ?? _defaults.barBackgroundColor; + + @override + Color get scaffoldBackgroundColor => super.scaffoldBackgroundColor ?? _defaults.scaffoldBackgroundColor; + + @override + bool get applyThemeToAll => super.applyThemeToAll ?? _defaults.applyThemeToAll; + + @override + NoDefaultCupertinoThemeData noDefault() { + return NoDefaultCupertinoThemeData( + brightness: super.brightness, + primaryColor: super.primaryColor, + primaryContrastingColor: super.primaryContrastingColor, + textTheme: super.textTheme, + barBackgroundColor: super.barBackgroundColor, + scaffoldBackgroundColor: super.scaffoldBackgroundColor, + applyThemeToAll: super.applyThemeToAll, + ); + } + + @override + CupertinoThemeData resolveFrom(BuildContext context) { + Color? convertColor(Color? color) => CupertinoDynamicColor.maybeResolve(color, context); + + return CupertinoThemeData._rawWithDefaults( + brightness, + convertColor(super.primaryColor), + convertColor(super.primaryContrastingColor), + super.textTheme?.resolveFrom(context), + convertColor(super.barBackgroundColor), + convertColor(super.scaffoldBackgroundColor), + applyThemeToAll, + _defaults.resolveFrom(context, super.textTheme == null), + ); + } + + @override + CupertinoThemeData copyWith({ + Brightness? brightness, + Color? primaryColor, + Color? primaryContrastingColor, + CupertinoTextThemeData? textTheme, + Color? barBackgroundColor, + Color? scaffoldBackgroundColor, + bool? applyThemeToAll, + }) { + return CupertinoThemeData._rawWithDefaults( + brightness ?? super.brightness, + primaryColor ?? super.primaryColor, + primaryContrastingColor ?? super.primaryContrastingColor, + textTheme ?? super.textTheme, + barBackgroundColor ?? super.barBackgroundColor, + scaffoldBackgroundColor ?? super.scaffoldBackgroundColor, + applyThemeToAll ?? super.applyThemeToAll, + _defaults, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + const CupertinoThemeData defaultData = CupertinoThemeData(); + properties.add(EnumProperty('brightness', brightness, defaultValue: null)); + properties.add(createCupertinoColorProperty('primaryColor', primaryColor, defaultValue: defaultData.primaryColor)); + properties.add(createCupertinoColorProperty('primaryContrastingColor', primaryContrastingColor, defaultValue: defaultData.primaryContrastingColor)); + properties.add(createCupertinoColorProperty('barBackgroundColor', barBackgroundColor, defaultValue: defaultData.barBackgroundColor)); + properties.add(createCupertinoColorProperty('scaffoldBackgroundColor', scaffoldBackgroundColor, defaultValue: defaultData.scaffoldBackgroundColor)); + properties.add(DiagnosticsProperty('applyThemeToAll', applyThemeToAll, defaultValue: defaultData.applyThemeToAll)); + textTheme.debugFillProperties(properties); + } + + @override + bool operator == (Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is CupertinoThemeData + && other.brightness == brightness + && other.primaryColor == primaryColor + && other.primaryContrastingColor == primaryContrastingColor + && other.textTheme == textTheme + && other.barBackgroundColor == barBackgroundColor + && other.scaffoldBackgroundColor == scaffoldBackgroundColor + && other.applyThemeToAll == applyThemeToAll; + } + + @override + int get hashCode => Object.hash( + brightness, + primaryColor, + primaryContrastingColor, + textTheme, + barBackgroundColor, + scaffoldBackgroundColor, + applyThemeToAll, + ); +} + +/// Styling specifications for a cupertino theme without default values for +/// unspecified properties. +/// +/// Unlike [CupertinoThemeData] instances of this class do not return default +/// values for properties that have been left unspecified in the constructor. +/// Instead, unspecified properties will return null. This is used by +/// Material's [ThemeData.cupertinoOverrideTheme]. +/// +/// See also: +/// +/// * [CupertinoThemeData], which uses reasonable default values for +/// unspecified theme properties. +class NoDefaultCupertinoThemeData { + /// Creates a [NoDefaultCupertinoThemeData] styling specification. + /// + /// Unspecified properties default to null. + const NoDefaultCupertinoThemeData({ + this.brightness, + this.primaryColor, + this.primaryContrastingColor, + this.textTheme, + this.barBackgroundColor, + this.scaffoldBackgroundColor, + this.applyThemeToAll, + }); + + /// The brightness override for Cupertino descendants. + /// + /// Defaults to null. If a non-null [Brightness] is specified, the value will + /// take precedence over the ambient [MediaQueryData.platformBrightness], when + /// determining the brightness of descendant Cupertino widgets. + /// + /// If coming from a Material [Theme] and unspecified, [brightness] will be + /// derived from the Material [ThemeData]'s [brightness]. + /// + /// See also: + /// + /// * [MaterialBasedCupertinoThemeData], a [CupertinoThemeData] that defers + /// [brightness] to its Material [Theme] parent if it's unspecified. + /// + /// * [CupertinoTheme.brightnessOf], a method used to retrieve the overall + /// [Brightness] from a [BuildContext], for Cupertino widgets. + final Brightness? brightness; + + /// A color used on interactive elements of the theme. + /// + /// This color is generally used on text and icons in buttons and tappable + /// elements. Defaults to [CupertinoColors.activeBlue]. + /// + /// If coming from a Material [Theme] and unspecified, [primaryColor] will be + /// derived from the Material [ThemeData]'s `colorScheme.primary`. However, in + /// iOS styling, the [primaryColor] is more sparsely used than in Material + /// Design where the [primaryColor] can appear on non-interactive surfaces like + /// the [AppBar] background, [TextField] borders etc. + /// + /// See also: + /// + /// * [MaterialBasedCupertinoThemeData], a [CupertinoThemeData] that defers + /// [primaryColor] to its Material [Theme] parent if it's unspecified. + final Color? primaryColor; + + /// A color that must be easy to see when rendered on a [primaryColor] background. + /// + /// For example, this color is used for a [CupertinoButton]'s text and icons + /// when the button's background is [primaryColor]. + /// + /// If coming from a Material [Theme] and unspecified, [primaryContrastingColor] + /// will be derived from the Material [ThemeData]'s `colorScheme.onPrimary`. + /// + /// See also: + /// + /// * [MaterialBasedCupertinoThemeData], a [CupertinoThemeData] that defers + /// [primaryContrastingColor] to its Material [Theme] parent if it's unspecified. + final Color? primaryContrastingColor; + + /// Text styles used by Cupertino widgets. + /// + /// Derived from [primaryColor] if unspecified. + final CupertinoTextThemeData? textTheme; + + /// Background color of the top nav bar and bottom tab bar. + /// + /// Defaults to a light gray in light mode, or a dark translucent gray color in + /// dark mode. + final Color? barBackgroundColor; + + /// Background color of the scaffold. + /// + /// Defaults to [CupertinoColors.systemBackground]. + final Color? scaffoldBackgroundColor; + + /// Flag to apply this theme to all descendant Cupertino widgets. + /// + /// Certain Cupertino widgets previously didn't use theming, matching past + /// versions of iOS. For example, [CupertinoSwitch]s always used + /// [CupertinoColors.systemGreen] when active. + /// + /// Today, however, these widgets can indeed be themed on iOS. Moreover on + /// macOS, the accent color is reflected in these widgets. Turning this flag + /// on ensures that descendant Cupertino widgets will be themed accordingly. + /// + /// This flag currently applies to the following widgets: + /// - [CupertinoSwitch] & [Switch.adaptive] + /// + /// Defaults to false. + final bool? applyThemeToAll; + + /// Returns an instance of the theme data whose property getters only return + /// the construction time specifications with no derived values. + /// + /// Used in Material themes to let unspecified properties fallback to Material + /// theme properties instead of iOS defaults. + NoDefaultCupertinoThemeData noDefault() => this; + + /// Returns a new theme data with all its colors resolved against the + /// given [BuildContext]. + /// + /// Called by [CupertinoTheme.of] to resolve colors defined in the retrieved + /// [CupertinoThemeData]. + @protected + NoDefaultCupertinoThemeData resolveFrom(BuildContext context) { + Color? convertColor(Color? color) => CupertinoDynamicColor.maybeResolve(color, context); + + return NoDefaultCupertinoThemeData( + brightness: brightness, + primaryColor: convertColor(primaryColor), + primaryContrastingColor: convertColor(primaryContrastingColor), + textTheme: textTheme?.resolveFrom(context), + barBackgroundColor: convertColor(barBackgroundColor), + scaffoldBackgroundColor: convertColor(scaffoldBackgroundColor), + applyThemeToAll: applyThemeToAll, + ); + } + + /// Creates a copy of the theme data with specified attributes overridden. + /// + /// Only the current instance's specified attributes are copied instead of + /// derived values. For instance, if the current [textTheme] is implied from + /// the current [primaryColor] because it was not specified, copying with a + /// different [primaryColor] will also change the copy's implied [textTheme]. + NoDefaultCupertinoThemeData copyWith({ + Brightness? brightness, + Color? primaryColor, + Color? primaryContrastingColor, + CupertinoTextThemeData? textTheme, + Color? barBackgroundColor , + Color? scaffoldBackgroundColor, + bool? applyThemeToAll, + }) { + return NoDefaultCupertinoThemeData( + brightness: brightness ?? this.brightness, + primaryColor: primaryColor ?? this.primaryColor, + primaryContrastingColor: primaryContrastingColor ?? this.primaryContrastingColor, + textTheme: textTheme ?? this.textTheme, + barBackgroundColor: barBackgroundColor ?? this.barBackgroundColor, + scaffoldBackgroundColor: scaffoldBackgroundColor ?? this.scaffoldBackgroundColor, + applyThemeToAll: applyThemeToAll ?? this.applyThemeToAll, + ); + } +} + +@immutable +class _CupertinoThemeDefaults { + const _CupertinoThemeDefaults( + this.brightness, + this.primaryColor, + this.primaryContrastingColor, + this.barBackgroundColor, + this.scaffoldBackgroundColor, + this.applyThemeToAll, + this.textThemeDefaults, + ); + + final Brightness? brightness; + final Color primaryColor; + final Color primaryContrastingColor; + final Color barBackgroundColor; + final Color scaffoldBackgroundColor; + final bool applyThemeToAll; + final _CupertinoTextThemeDefaults textThemeDefaults; + + _CupertinoThemeDefaults resolveFrom(BuildContext context, bool resolveTextTheme) { + Color convertColor(Color color) => CupertinoDynamicColor.resolve(color, context); + + return _CupertinoThemeDefaults( + brightness, + convertColor(primaryColor), + convertColor(primaryContrastingColor), + convertColor(barBackgroundColor), + convertColor(scaffoldBackgroundColor), + applyThemeToAll, + resolveTextTheme ? textThemeDefaults.resolveFrom(context) : textThemeDefaults, + ); + } +} + +@immutable +class _CupertinoTextThemeDefaults { + const _CupertinoTextThemeDefaults( + this.labelColor, + this.inactiveGray, + ); + + final Color labelColor; + final Color inactiveGray; + + _CupertinoTextThemeDefaults resolveFrom(BuildContext context) { + return _CupertinoTextThemeDefaults( + CupertinoDynamicColor.resolve(labelColor, context), + CupertinoDynamicColor.resolve(inactiveGray, context), + ); + } + + CupertinoTextThemeData createDefaults({ required Color primaryColor }) { + return _DefaultCupertinoTextThemeData( + primaryColor: primaryColor, + labelColor: labelColor, + inactiveGray: inactiveGray, + ); + } +} + +// CupertinoTextThemeData with no text styles explicitly specified. +// The implementation of this class may need to be updated when any of the default +// text styles changes. +class _DefaultCupertinoTextThemeData extends CupertinoTextThemeData { + const _DefaultCupertinoTextThemeData({ + required this.labelColor, + required this.inactiveGray, + required super.primaryColor, + }); + + final Color labelColor; + final Color inactiveGray; + + @override + TextStyle get textStyle => super.textStyle.copyWith(color: labelColor); + + @override + TextStyle get tabLabelTextStyle => super.tabLabelTextStyle.copyWith(color: inactiveGray); + + @override + TextStyle get navTitleTextStyle => super.navTitleTextStyle.copyWith(color: labelColor); + + @override + TextStyle get navLargeTitleTextStyle => super.navLargeTitleTextStyle.copyWith(color: labelColor); + + @override + TextStyle get pickerTextStyle => super.pickerTextStyle.copyWith(color: labelColor); + + @override + TextStyle get dateTimePickerTextStyle => super.dateTimePickerTextStyle.copyWith(color: labelColor); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/thumb_painter.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/thumb_painter.dart new file mode 100644 index 0000000000000000000000000000000000000000..08f43f63ba857cf3e869c93a4354a1a73fd03c2a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/thumb_painter.dart @@ -0,0 +1,90 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/painting.dart'; + +import 'colors.dart'; + +const Color _kThumbBorderColor = Color(0x0A000000); + +const List _kSwitchBoxShadows = [ + BoxShadow( + color: Color(0x26000000), + offset: Offset(0, 3), + blurRadius: 8.0, + ), + BoxShadow( + color: Color(0x0F000000), + offset: Offset(0, 3), + blurRadius: 1.0, + ), +]; + +const List _kSliderBoxShadows = [ + BoxShadow( + color: Color(0x26000000), + offset: Offset(0, 3), + blurRadius: 8.0, + ), + BoxShadow( + color: Color(0x29000000), + offset: Offset(0, 1), + blurRadius: 1.0, + ), + BoxShadow( + color: Color(0x1A000000), + offset: Offset(0, 3), + blurRadius: 1.0, + ), +]; + +/// Paints an iOS-style slider thumb or switch thumb. +/// +/// Used by [CupertinoSwitch] and [CupertinoSlider]. +class CupertinoThumbPainter { + /// Creates an object that paints an iOS-style slider thumb. + const CupertinoThumbPainter({ + this.color = CupertinoColors.white, + this.shadows = _kSliderBoxShadows, + }); + + /// Creates an object that paints an iOS-style switch thumb. + const CupertinoThumbPainter.switchThumb({ + Color color = CupertinoColors.white, + List shadows = _kSwitchBoxShadows, + }) : this(color: color, shadows: shadows); + + /// The color of the interior of the thumb. + final Color color; + + /// The list of [BoxShadow] to paint below the thumb. + final List shadows; + + /// Half the default diameter of the thumb. + static const double radius = 14.0; + + /// The default amount the thumb should be extended horizontally when pressed. + static const double extension = 7.0; + + /// Paints the thumb onto the given canvas in the given rectangle. + /// + /// Consider using [radius] and [extension] when deciding how large a + /// rectangle to use for the thumb. + void paint(Canvas canvas, Rect rect) { + final RRect rrect = RRect.fromRectAndRadius( + rect, + Radius.circular(rect.shortestSide / 2.0), + ); + + for (final BoxShadow shadow in shadows) { + canvas.drawRRect(rrect.shift(shadow.offset), shadow.toPaint()); + } + + canvas.drawRRect( + rrect.inflate(0.5), + Paint()..color = _kThumbBorderColor, + ); + canvas.drawRRect(rrect, Paint()..color = color); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/toggleable.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/toggleable.dart new file mode 100644 index 0000000000000000000000000000000000000000..a5fb38d9a6d84dce9574831dba0fcac98c512317 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/cupertino/toggleable.dart @@ -0,0 +1,244 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +/// A mixin for [StatefulWidget]s that implements iOS-themed toggleable +/// controls (e.g.[CupertinoCheckbox]es). +/// +/// This mixin implements the logic for toggling the control when tapped. +/// It does not have any opinion about the visual representation of the +/// toggleable widget. The visuals are defined by a [CustomPainter] passed to +/// the [buildToggleable]. [State] objects using this mixin should call that +/// method from their [build] method. +/// +/// This mixin is used to implement the Cupertino components for +/// [CupertinoCheckbox] controls. +@optionalTypeArgs +mixin ToggleableStateMixin on TickerProviderStateMixin { + + /// Whether the [value] of this control can be changed by user interaction. + /// + /// The control is considered interactive if the [onChanged] callback is + /// non-null. If the callback is null, then the control is disabled and + /// non-interactive. A disabled checkbox, for example, is displayed using a + /// grey color and its value cannot be changed. + bool get isInteractive => onChanged != null; + + /// Called when the control changes value. + /// + /// If the control is tapped, [onChanged] is called immediately with the new + /// value. + /// + /// The control is considered interactive (see [isInteractive]) if this + /// callback is non-null. If the callback is null, then the control is + /// disabled and non-interactive. A disabled checkbox, for example, is + /// displayed using a grey color and its value cannot be changed. + ValueChanged? get onChanged; + + /// The [value] accessor returns false if this control is "inactive" (not + /// checked, off, or unselected). + /// + /// If [value] is true then the control "active" (checked, on, or selected). If + /// tristate is true and value is null, then the control is considered to be + /// in its third or "indeterminate" state.. + bool? get value; + + /// If true, [value] can be true, false, or null, otherwise [value] must + /// be true or false. + /// + /// When [tristate] is true and [value] is null, then the control is + /// considered to be in its third or "indeterminate" state. + bool get tristate; + + /// The most recent [Offset] at which a pointer touched the Toggleable. + /// + /// This is null if currently no pointer is touching the Toggleable or if + /// [isInteractive] is false. + Offset? get downPosition => _downPosition; + Offset? _downPosition; + + void _handleTapDown(TapDownDetails details) { + if (isInteractive) { + setState(() { + _downPosition = details.localPosition; + }); + } + } + + void _handleTap([Intent? _]) { + if (!isInteractive) { + return; + } + switch (value) { + case false: + onChanged!(true); + case true: + onChanged!(tristate ? null : false); + case null: + onChanged!(false); + } + context.findRenderObject()!.sendSemanticsEvent(const TapSemanticEvent()); + } + + void _handleTapEnd([TapUpDetails? _]) { + if (_downPosition != null) { + setState(() { _downPosition = null; }); + } + } + + bool _focused = false; + void _handleFocusHighlightChanged(bool focused) { + if (focused != _focused) { + setState(() { _focused = focused; }); + } + } + + late final Map> _actionMap = >{ + ActivateIntent: CallbackAction(onInvoke: _handleTap), + }; + + /// Typically wraps a `painter` that draws the actual visuals of the + /// Toggleable with logic to toggle it. + /// + /// Consider providing a subclass of [ToggleablePainter] as a `painter`. + /// + /// This method must be called from the [build] method of the [State] class + /// that uses this mixin. The returned [Widget] must be returned from the + /// build method - potentially after wrapping it in other widgets. + Widget buildToggleable({ + FocusNode? focusNode, + ValueChanged? onFocusChange, + bool autofocus = false, + required Size size, + required CustomPainter painter, + }) { + return FocusableActionDetector( + focusNode: focusNode, + autofocus: autofocus, + onFocusChange: onFocusChange, + enabled: isInteractive, + actions: _actionMap, + onShowFocusHighlight: _handleFocusHighlightChanged, + child: GestureDetector( + excludeFromSemantics: !isInteractive, + onTapDown: isInteractive ? _handleTapDown : null, + onTap: isInteractive ? _handleTap : null, + onTapUp: isInteractive ? _handleTapEnd : null, + onTapCancel: isInteractive ? _handleTapEnd : null, + child: Semantics( + enabled: isInteractive, + child: CustomPaint( + size: size, + painter: painter, + ), + ), + ), + ); + } +} + +/// A base class for a [CustomPainter] that may be passed to +/// [ToggleableStateMixin.buildToggleable] to draw the visual representation of +/// a Toggleable. +/// +/// Subclasses must implement the [paint] method to draw the actual visuals of +/// the Toggleable. +abstract class ToggleablePainter extends ChangeNotifier implements CustomPainter { + /// The color that should be used in the active state (i.e., when + /// [ToggleableStateMixin.value] is true). + /// + /// For example, a checkbox should use this color when checked. + Color get activeColor => _activeColor!; + Color? _activeColor; + set activeColor(Color value) { + if (_activeColor == value) { + return; + } + _activeColor = value; + notifyListeners(); + } + + /// The color that should be used in the inactive state (i.e., when + /// [ToggleableStateMixin.value] is false). + /// + /// For example, a checkbox should use this color when unchecked. + Color get inactiveColor => _inactiveColor!; + Color? _inactiveColor; + set inactiveColor(Color value) { + if (_inactiveColor == value) { + return; + } + _inactiveColor = value; + notifyListeners(); + } + + /// The color that should be used for the reaction when [isFocused] is true. + /// + /// Used when the toggleable needs to change the reaction color/transparency, + /// when it has focus. + Color get focusColor => _focusColor!; + Color? _focusColor; + set focusColor(Color value) { + if (value == _focusColor) { + return; + } + _focusColor = value; + notifyListeners(); + } + + /// The [Offset] within the Toggleable at which a pointer touched the Toggleable. + /// + /// This is null if currently no pointer is touching the Toggleable. + /// + /// Usually set to [ToggleableStateMixin.downPosition]. + Offset? get downPosition => _downPosition; + Offset? _downPosition; + set downPosition(Offset? value) { + if (value == _downPosition) { + return; + } + _downPosition = value; + notifyListeners(); + } + + /// True if this toggleable has the input focus. + bool get isFocused => _isFocused!; + bool? _isFocused; + set isFocused(bool? value) { + if (value == _isFocused) { + return; + } + _isFocused = value; + notifyListeners(); + } + + /// Determines whether the toggleable shows as active. + bool get isActive => _isActive!; + bool? _isActive; + set isActive(bool? value) { + if (value == _isActive) { + return; + } + _isActive = value; + notifyListeners(); + } + + @override + bool shouldRepaint(covariant CustomPainter oldDelegate) => true; + + @override + bool? hitTest(Offset position) => null; + + @override + SemanticsBuilderCallback? get semanticsBuilder => null; + + @override + bool shouldRebuildSemantics(covariant CustomPainter oldDelegate) => false; + + @override + String toString() => describeIdentity(this); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/dart_plugin_registrant.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/dart_plugin_registrant.dart new file mode 100644 index 0000000000000000000000000000000000000000..cbe5354303c86781f1ea5cc8109e03d734648ef2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/dart_plugin_registrant.dart @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// The location of the Dart Plugin Registrant. This is used by the engine to +/// execute the Dart Plugin Registrant when the Isolate is started or +/// DartPluginRegistrant.ensureInitialized() is called from a background +/// Isolate. +@pragma('vm:entry-point') +const String dartPluginRegistrantLibrary = String.fromEnvironment('flutter.dart_plugin_registrant'); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/README.md b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d32effc8c2381370089537a36f79c905bfc3dd76 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/README.md @@ -0,0 +1,17 @@ +The rule for packages in this directory is that they can depend on +nothing but core Dart packages. They can't depend on `dart:ui`, they +can't depend on any `package:`, and they can't depend on anything +outside this directory. + +Currently they do depend on dart:ui, but only for `VoidCallback` and +`clampDouble` (and maybe one day `lerpDouble`), which are all intended +to be moved out of `dart:ui` and into `dart:core`. + +There is currently also an unfortunate dependency on the platform +dispatcher logic (SingletonFlutterWindow, Brightness, +PlatformDispatcher, window), though that should probably move to the +'services' library. + +See also: + + * https://github.com/dart-lang/sdk/issues/25217 diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_bitfield_io.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_bitfield_io.dart new file mode 100644 index 0000000000000000000000000000000000000000..680d56f26222919d3722173fe0209f0da7cb35d4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_bitfield_io.dart @@ -0,0 +1,51 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'bitfield.dart' as bitfield; + +/// The dart:io implementation of [bitfield.kMaxUnsignedSMI]. +const int kMaxUnsignedSMI = 0x3FFFFFFFFFFFFFFF; // ignore: avoid_js_rounded_ints, (VM-only code) + +/// The dart:io implementation of [bitfield.Bitfield]. +class BitField implements bitfield.BitField { + /// The dart:io implementation of [bitfield.Bitfield()]. + BitField(this._length) + : assert(_length <= _smiBits), + _bits = _allZeros; + + /// The dart:io implementation of [bitfield.Bitfield.filled]. + BitField.filled(this._length, bool value) + : assert(_length <= _smiBits), + _bits = value ? _allOnes : _allZeros; + + final int _length; + int _bits; + + static const int _smiBits = 62; // see https://www.dartlang.org/articles/numeric-computation/#smis-and-mints + static const int _allZeros = 0; + static const int _allOnes = kMaxUnsignedSMI; // 2^(_kSMIBits+1)-1 + + @override + bool operator [](T index) { + final int intIndex = index.index as int; + assert(intIndex < _length); + return (_bits & 1 << intIndex) > 0; + } + + @override + void operator []=(T index, bool value) { + final int intIndex = index.index as int; + assert(intIndex < _length); + if (value) { + _bits = _bits | (1 << intIndex); + } else { + _bits = _bits & ~(1 << intIndex); + } + } + + @override + void reset([ bool value = false ]) { + _bits = value ? _allOnes : _allZeros; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_bitfield_web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_bitfield_web.dart new file mode 100644 index 0000000000000000000000000000000000000000..e1f74cc3b59224cc39df300addf6612547fbf368 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_bitfield_web.dart @@ -0,0 +1,42 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'bitfield.dart' as bitfield; + +/// The dart:html implementation of [bitfield.kMaxUnsignedSMI]. +/// +/// This value is used as an optimization to coerce some numbers to be within +/// the SMI range and avoid heap allocations. Because number encoding is +/// VM-specific, there's no guarantee that this optimization will be effective +/// on all JavaScript engines. The value picked here should be correct, but it +/// does not have to guarantee efficiency. +const int kMaxUnsignedSMI = -1; + +/// The dart:html implementation of [bitfield.Bitfield]. +class BitField implements bitfield.BitField { + /// The dart:html implementation of [bitfield.Bitfield]. + // Can remove when we have metaclasses. + // ignore: avoid_unused_constructor_parameters + BitField(int length); + + /// The dart:html implementation of [bitfield.Bitfield.filled]. + // Can remove when we have metaclasses. + // ignore: avoid_unused_constructor_parameters + BitField.filled(int length, bool value); + + @override + bool operator [](T index) { + throw UnsupportedError('Not supported when compiling to JavaScript'); + } + + @override + void operator []=(T index, bool value) { + throw UnsupportedError('Not supported when compiling to JavaScript'); + } + + @override + void reset([ bool value = false ]) { + throw UnsupportedError('Not supported when compiling to JavaScript'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_capabilities_io.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_capabilities_io.dart new file mode 100644 index 0000000000000000000000000000000000000000..202dc7ba00d4a006d0fc826de93408ed3ccd3378 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_capabilities_io.dart @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// The dart:io implementation of [isCanvasKit]. +/// +/// This bool shouldn't be used outside of web. +bool get isCanvasKit { + throw UnimplementedError('isCanvasKit is not implemented for dart:io.'); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_capabilities_web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_capabilities_web.dart new file mode 100644 index 0000000000000000000000000000000000000000..a71c517d8ef3c48027f7f031253bd0e22745b875 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_capabilities_web.dart @@ -0,0 +1,13 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:js_interop'; + +// This value is set by the engine. It is used to determine if the application is +// using canvaskit. +@JS('window.flutterCanvasKit') +external JSAny? get _windowFlutterCanvasKit; + +/// The web implementation of [isCanvasKit] +bool get isCanvasKit => _windowFlutterCanvasKit != null; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_isolates_io.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_isolates_io.dart new file mode 100644 index 0000000000000000000000000000000000000000..08bd8ca0c7379d683227397b380c603ea3dd6256 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_isolates_io.dart @@ -0,0 +1,21 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:isolate'; + +import 'constants.dart'; +import 'isolates.dart' as isolates; + +export 'isolates.dart' show ComputeCallback; + +/// The dart:io implementation of [isolate.compute]. +@pragma('vm:prefer-inline') +Future compute(isolates.ComputeCallback callback, M message, {String? debugLabel}) async { + debugLabel ??= kReleaseMode ? 'compute' : callback.toString(); + + return Isolate.run(() { + return callback(message); + }, debugName: debugLabel); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_isolates_web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_isolates_web.dart new file mode 100644 index 0000000000000000000000000000000000000000..4350e54614c105592efcd74fcd12c72b50c06391 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_isolates_web.dart @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'isolates.dart' as isolates; + +export 'isolates.dart' show ComputeCallback; + +/// The dart:html implementation of [isolate.compute]. +@pragma('dart2js:tryInline') +Future compute(isolates.ComputeCallback callback, M message, { String? debugLabel }) async { + // To avoid blocking the UI immediately for an expensive function call, we + // pump a single frame to allow the framework to complete the current set + // of work. + await null; + return callback(message); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_platform_io.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_platform_io.dart new file mode 100644 index 0000000000000000000000000000000000000000..d7750c08b20b4d97b1b1f598dd7aaca6079e8d54 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_platform_io.dart @@ -0,0 +1,44 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:io'; +import 'assertions.dart'; +import 'platform.dart' as platform; + +export 'platform.dart' show TargetPlatform; + +/// The dart:io implementation of [platform.defaultTargetPlatform]. +platform.TargetPlatform get defaultTargetPlatform { + platform.TargetPlatform? result; + if (Platform.isAndroid) { + result = platform.TargetPlatform.android; + } else if (Platform.isIOS) { + result = platform.TargetPlatform.iOS; + } else if (Platform.isFuchsia) { + result = platform.TargetPlatform.fuchsia; + } else if (Platform.isLinux) { + result = platform.TargetPlatform.linux; + } else if (Platform.isMacOS) { + result = platform.TargetPlatform.macOS; + } else if (Platform.isWindows) { + result = platform.TargetPlatform.windows; + } + assert(() { + if (Platform.environment.containsKey('FLUTTER_TEST')) { + result = platform.TargetPlatform.android; + } + return true; + }()); + if (platform.debugDefaultTargetPlatformOverride != null) { + result = platform.debugDefaultTargetPlatformOverride; + } + if (result == null) { + throw FlutterError( + 'Unknown platform.\n' + '${Platform.operatingSystem} was not recognized as a target platform. ' + 'Consider updating the list of TargetPlatforms to include this platform.', + ); + } + return result!; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_platform_web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_platform_web.dart new file mode 100644 index 0000000000000000000000000000000000000000..161921fba4313a7e0a2f1cbfc4b4b929a26199a3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_platform_web.dart @@ -0,0 +1,64 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui_web' as ui_web; + +import '../web.dart' as web; +import 'platform.dart' as platform; + +export 'platform.dart' show TargetPlatform; + +/// The web implementation of [platform.defaultTargetPlatform]. +platform.TargetPlatform get defaultTargetPlatform { + // To get a better guess at the targetPlatform we need to be able to reference + // the window, but that won't be available until we fix the platforms + // configuration for Flutter. + return platform.debugDefaultTargetPlatformOverride ?? + _testPlatform ?? + _browserPlatform; +} + +final platform.TargetPlatform? _testPlatform = () { + platform.TargetPlatform? result; + assert(() { + if (ui_web.debugEmulateFlutterTesterEnvironment) { + result = platform.TargetPlatform.android; + } + return true; + }()); + return result; +}(); + +// Lazy-initialized and forever cached current browser platform. +// +// Computing the platform is expensive as it uses `window.matchMedia`, which +// needs to parse and evaluate a CSS selector. On some devices this takes up to +// 0.20ms. As `defaultTargetPlatform` is routinely called dozens of times per +// frame this value should be cached. +final platform.TargetPlatform _browserPlatform = () { + final String navigatorPlatform = web.window.navigator.platform.toLowerCase(); + if (navigatorPlatform.startsWith('mac')) { + return platform.TargetPlatform.macOS; + } + if (navigatorPlatform.startsWith('win')) { + return platform.TargetPlatform.windows; + } + if (navigatorPlatform.contains('iphone') || + navigatorPlatform.contains('ipad') || + navigatorPlatform.contains('ipod')) { + return platform.TargetPlatform.iOS; + } + if (navigatorPlatform.contains('android')) { + return platform.TargetPlatform.android; + } + // Since some phones can report a window.navigator.platform as Linux, fall + // back to use CSS to disambiguate Android vs Linux desktop. If the CSS + // indicates that a device has a "fine pointer" (mouse) as the primary + // pointing device, then we'll assume desktop linux, and otherwise we'll + // assume Android. + if (web.window.matchMedia('only screen and (pointer: fine)').matches) { + return platform.TargetPlatform.linux; + } + return platform.TargetPlatform.android; +}(); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_timeline_io.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_timeline_io.dart new file mode 100644 index 0000000000000000000000000000000000000000..8c4886b382c0a821929114ee7f994cb279defb94 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_timeline_io.dart @@ -0,0 +1,11 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:developer'; + +/// Returns the current timestamp in microseconds from a monotonically +/// increasing clock. +/// +/// This is the Dart VM implementation. +double get performanceTimestamp => Timeline.now.toDouble(); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_timeline_web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_timeline_web.dart new file mode 100644 index 0000000000000000000000000000000000000000..133f096cbe9648dff0be88c27b04f125a0966c37 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/_timeline_web.dart @@ -0,0 +1,27 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:js_interop'; + +/// Returns the current timestamp in microseconds from a monotonically +/// increasing clock. +/// +/// This is the web implementation, which uses `window.performance.now` as the +/// source of the timestamp. +/// +/// See: +/// * https://developer.mozilla.org/en-US/docs/Web/API/Performance/now +double get performanceTimestamp => 1000 * _performance.now(); + +@JS() +@staticInterop +class _DomPerformance {} + +@JS('performance') +external _DomPerformance get _performance; + +extension _DomPerformanceExtension on _DomPerformance { + @JS() + external double now(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/annotations.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/annotations.dart new file mode 100644 index 0000000000000000000000000000000000000000..3bc5e023160f2cbb60a33dfdd97f924389b84449 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/annotations.dart @@ -0,0 +1,118 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Examples can assume: +// class Cat { } + +/// A category with which to annotate a class, for documentation +/// purposes. +/// +/// A category is usually represented as a section and a subsection, each +/// of which is a string. The engineering team that owns the library to which +/// the class belongs defines the categories used for classes in that library. +/// For example, the Flutter engineering team has defined categories like +/// "Basic/Buttons" and "Material Design/Buttons" for Flutter widgets. +/// +/// A class can have multiple categories. +/// +/// {@tool snippet} +/// +/// ```dart +/// /// A copper coffee pot, as desired by Ben Turpin. +/// /// ...documentation... +/// @Category(['Pots', 'Coffee']) +/// @Category(['Copper', 'Cookware']) +/// @DocumentationIcon('https://example.com/images/coffee.png') +/// @Summary('A proper cup of coffee is made in a proper copper coffee pot.') +/// class CopperCoffeePot { +/// // ...code... +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [DocumentationIcon], which is used to give the URL to an image that +/// represents the class. +/// * [Summary], which is used to provide a one-line description of a +/// class that overrides the inline documentations' own description. +class Category { + /// Create an annotation to provide a categorization of a class. + const Category(this.sections); + + /// The strings the correspond to the section and subsection of the + /// category represented by this object. + /// + /// By convention, this list usually has two items. The allowed values + /// are defined by the team that owns the library to which the annotated + /// class belongs. + final List sections; +} + +/// A class annotation to provide a URL to an image that represents the class. +/// +/// Each class should only have one [DocumentationIcon]. +/// +/// {@tool snippet} +/// +/// ```dart +/// /// Utility class for beginning a dream-sharing sequence. +/// /// ...documentation... +/// @Category(['Military Technology', 'Experimental']) +/// @DocumentationIcon('https://docs.example.org/icons/top.png') +/// class DreamSharing { +/// // ...code... +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Category], to help place the class in an index. +/// * [Summary], which is used to provide a one-line description of a +/// class that overrides the inline documentations' own description. +class DocumentationIcon { + /// Create an annotation to provide a URL to an image describing a class. + const DocumentationIcon(this.url); + + /// The URL to an image that represents the annotated class. + final String url; +} + +/// An annotation that provides a short description of a class for use +/// in an index. +/// +/// Usually the first paragraph of the documentation for a class can be used +/// for this purpose, but on occasion the first paragraph is either too short +/// or too long for use in isolation, without the remainder of the documentation. +/// +/// {@tool snippet} +/// +/// ```dart +/// /// A famous cat. +/// /// +/// /// Instances of this class can hunt small animals. +/// /// This cat has three legs. +/// @Category(['Animals', 'Cats']) +/// @Category(['Cute', 'Pets']) +/// @DocumentationIcon('https://www.examples.net/docs/images/icons/pillar.jpeg') +/// @Summary('A famous three-legged cat.') +/// class Pillar extends Cat { +/// // ...code... +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Category], to help place the class in an index. +/// * [DocumentationIcon], which is used to give the URL to an image that +/// represents the class. +class Summary { + /// Create an annotation to provide a short description of a class. + const Summary(this.text); + + /// The text of the summary of the annotated class. + final String text; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/assertions.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/assertions.dart new file mode 100644 index 0000000000000000000000000000000000000000..a914609f89e053531652a1ca391073aea7ce2ff1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/assertions.dart @@ -0,0 +1,1296 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:meta/meta.dart'; + +import 'basic_types.dart'; +import 'constants.dart'; +import 'diagnostics.dart'; +import 'print.dart'; +import 'stack_frame.dart'; + +export 'basic_types.dart' show IterableFilter; +export 'diagnostics.dart' show DiagnosticLevel, DiagnosticPropertiesBuilder, DiagnosticsNode, DiagnosticsTreeStyle; +export 'stack_frame.dart' show StackFrame; + +// Examples can assume: +// late String runtimeType; +// late bool draconisAlive; +// late bool draconisAmulet; +// late Diagnosticable draconis; +// void methodThatMayThrow() { } +// class Trace implements StackTrace { late StackTrace vmTrace; } +// class Chain implements StackTrace { Trace toTrace() => Trace(); } + +/// Signature for [FlutterError.onError] handler. +typedef FlutterExceptionHandler = void Function(FlutterErrorDetails details); + +/// Signature for [DiagnosticPropertiesBuilder] transformer. +typedef DiagnosticPropertiesTransformer = Iterable Function(Iterable properties); + +/// Signature for [FlutterErrorDetails.informationCollector] callback +/// and other callbacks that collect information describing an error. +typedef InformationCollector = Iterable Function(); + +/// Signature for a function that demangles [StackTrace] objects into a format +/// that can be parsed by [StackFrame]. +/// +/// See also: +/// +/// * [FlutterError.demangleStackTrace], which shows an example implementation. +typedef StackTraceDemangler = StackTrace Function(StackTrace details); + +/// Partial information from a stack frame for stack filtering purposes. +/// +/// See also: +/// +/// * [RepetitiveStackFrameFilter], which uses this class to compare against [StackFrame]s. +@immutable +class PartialStackFrame { + /// Creates a new [PartialStackFrame] instance. + const PartialStackFrame({ + required this.package, + required this.className, + required this.method, + }); + + /// An `` line in a stack trace. + static const PartialStackFrame asynchronousSuspension = PartialStackFrame( + package: '', + className: '', + method: 'asynchronous suspension', + ); + + /// The package to match, e.g. `package:flutter/src/foundation/assertions.dart`, + /// or `dart:ui/window.dart`. + final Pattern package; + + /// The class name for the method. + /// + /// On web, this is ignored, since class names are not available. + /// + /// On all platforms, top level methods should use the empty string. + final String className; + + /// The method name for this frame line. + /// + /// On web, private methods are wrapped with `[]`. + final String method; + + /// Tests whether the [StackFrame] matches the information in this + /// [PartialStackFrame]. + bool matches(StackFrame stackFrame) { + final String stackFramePackage = '${stackFrame.packageScheme}:${stackFrame.package}/${stackFrame.packagePath}'; + // Ideally this wouldn't be necessary. + // TODO(dnfield): https://github.com/dart-lang/sdk/issues/40117 + if (kIsWeb) { + return package.allMatches(stackFramePackage).isNotEmpty + && stackFrame.method == (method.startsWith('_') ? '[$method]' : method); + } + return package.allMatches(stackFramePackage).isNotEmpty + && stackFrame.method == method + && stackFrame.className == className; + } +} + +/// A class that filters stack frames for additional filtering on +/// [FlutterError.defaultStackFilter]. +abstract class StackFilter { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const StackFilter(); + + /// Filters the list of [StackFrame]s by updating corresponding indices in + /// `reasons`. + /// + /// To elide a frame or number of frames, set the string. + void filter(List stackFrames, List reasons); +} + + +/// A [StackFilter] that filters based on repeating lists of +/// [PartialStackFrame]s. +/// +/// See also: +/// +/// * [FlutterError.addDefaultStackFilter], a method to register additional +/// stack filters for [FlutterError.defaultStackFilter]. +/// * [StackFrame], a class that can help with parsing stack frames. +/// * [PartialStackFrame], a class that helps match partial method information +/// to a stack frame. +class RepetitiveStackFrameFilter extends StackFilter { + /// Creates a new RepetitiveStackFrameFilter. All parameters are required and must not be + /// null. + const RepetitiveStackFrameFilter({ + required this.frames, + required this.replacement, + }); + + /// The shape of this repetitive stack pattern. + final List frames; + + /// The number of frames in this pattern. + int get numFrames => frames.length; + + /// The string to replace the frames with. + /// + /// If the same replacement string is used multiple times in a row, the + /// [FlutterError.defaultStackFilter] will insert a repeat count after this + /// line rather than repeating it. + final String replacement; + + List get _replacements => List.filled(numFrames, replacement); + + @override + void filter(List stackFrames, List reasons) { + for (int index = 0; index < stackFrames.length - numFrames; index += 1) { + if (_matchesFrames(stackFrames.skip(index).take(numFrames).toList())) { + reasons.setRange(index, index + numFrames, _replacements); + index += numFrames - 1; + } + } + } + + bool _matchesFrames(List stackFrames) { + if (stackFrames.length < numFrames) { + return false; + } + for (int index = 0; index < stackFrames.length; index++) { + if (!frames[index].matches(stackFrames[index])) { + return false; + } + } + return true; + } +} + +abstract class _ErrorDiagnostic extends DiagnosticsProperty> { + /// This constructor provides a reliable hook for a kernel transformer to find + /// error messages that need to be rewritten to include object references for + /// interactive display of errors. + _ErrorDiagnostic( + String message, { + DiagnosticsTreeStyle style = DiagnosticsTreeStyle.flat, + DiagnosticLevel level = DiagnosticLevel.info, + }) : super( + null, + [message], + showName: false, + showSeparator: false, + defaultValue: null, + style: style, + level: level, + ); + + /// In debug builds, a kernel transformer rewrites calls to the default + /// constructors for [ErrorSummary], [ErrorDescription], and [ErrorHint] to use + /// this constructor. + // + // ```dart + // _ErrorDiagnostic('Element $element must be $color') + // ``` + // Desugars to: + // ```dart + // _ErrorDiagnostic.fromParts(['Element ', element, ' must be ', color]) + // ``` + // + // Slightly more complex case: + // ```dart + // _ErrorDiagnostic('Element ${element.runtimeType} must be $color') + // ``` + // Desugars to: + //```dart + // _ErrorDiagnostic.fromParts([ + // 'Element ', + // DiagnosticsProperty(null, element, description: element.runtimeType?.toString()), + // ' must be ', + // color, + // ]) + // ``` + _ErrorDiagnostic._fromParts( + List messageParts, { + DiagnosticsTreeStyle style = DiagnosticsTreeStyle.flat, + DiagnosticLevel level = DiagnosticLevel.info, + }) : super( + null, + messageParts, + showName: false, + showSeparator: false, + defaultValue: null, + style: style, + level: level, + ); + + @override + String toString({ + TextTreeConfiguration? parentConfiguration, + DiagnosticLevel minLevel = DiagnosticLevel.info, + }) { + return valueToString(parentConfiguration: parentConfiguration); + } + + @override + List get value => super.value!; + + @override + String valueToString({ TextTreeConfiguration? parentConfiguration }) { + return value.join(); + } +} + +/// An explanation of the problem and its cause, any information that may help +/// track down the problem, background information, etc. +/// +/// Use [ErrorDescription] for any part of an error message where neither +/// [ErrorSummary] or [ErrorHint] is appropriate. +/// +/// In debug builds, values interpolated into the `message` are +/// expanded and placed into [value], which is of type [List]. +/// This allows IDEs to examine values interpolated into error messages. +/// +/// See also: +/// +/// * [ErrorSummary], which provides a short (one line) description of the +/// problem that was detected. +/// * [ErrorHint], which provides specific, non-obvious advice that may be +/// applicable. +/// * [ErrorSpacer], which renders as a blank line. +/// * [FlutterError], which is the most common place to use an +/// [ErrorDescription]. +class ErrorDescription extends _ErrorDiagnostic { + /// A lint enforces that this constructor can only be called with a string + /// literal to match the limitations of the Dart Kernel transformer that + /// optionally extracts out objects referenced using string interpolation in + /// the message passed in. + /// + /// The message will display with the same text regardless of whether the + /// kernel transformer is used. The kernel transformer is required so that + /// debugging tools can provide interactive displays of objects described by + /// the error. + ErrorDescription(super.message) : super(level: DiagnosticLevel.info); + + /// Calls to the default constructor may be rewritten to use this constructor + /// in debug mode using a kernel transformer. + // ignore: unused_element + ErrorDescription._fromParts(super.messageParts) : super._fromParts(level: DiagnosticLevel.info); +} + +/// A short (one line) description of the problem that was detected. +/// +/// Error summaries from the same source location should have little variance, +/// so that they can be recognized as related. For example, they shouldn't +/// include hash codes. +/// +/// A [FlutterError] must start with an [ErrorSummary] and may not contain +/// multiple summaries. +/// +/// In debug builds, values interpolated into the `message` are +/// expanded and placed into [value], which is of type [List]. +/// This allows IDEs to examine values interpolated into error messages. +/// +/// See also: +/// +/// * [ErrorDescription], which provides an explanation of the problem and its +/// cause, any information that may help track down the problem, background +/// information, etc. +/// * [ErrorHint], which provides specific, non-obvious advice that may be +/// applicable. +/// * [FlutterError], which is the most common place to use an [ErrorSummary]. +class ErrorSummary extends _ErrorDiagnostic { + /// A lint enforces that this constructor can only be called with a string + /// literal to match the limitations of the Dart Kernel transformer that + /// optionally extracts out objects referenced using string interpolation in + /// the message passed in. + /// + /// The message will display with the same text regardless of whether the + /// kernel transformer is used. The kernel transformer is required so that + /// debugging tools can provide interactive displays of objects described by + /// the error. + ErrorSummary(super.message) : super(level: DiagnosticLevel.summary); + + /// Calls to the default constructor may be rewritten to use this constructor + /// in debug mode using a kernel transformer. + // ignore: unused_element + ErrorSummary._fromParts(super.messageParts) : super._fromParts(level: DiagnosticLevel.summary); +} + +/// An [ErrorHint] provides specific, non-obvious advice that may be applicable. +/// +/// If your message provides obvious advice that is always applicable, it is an +/// [ErrorDescription] not a hint. +/// +/// In debug builds, values interpolated into the `message` are +/// expanded and placed into [value], which is of type [List]. +/// This allows IDEs to examine values interpolated into error messages. +/// +/// See also: +/// +/// * [ErrorSummary], which provides a short (one line) description of the +/// problem that was detected. +/// * [ErrorDescription], which provides an explanation of the problem and its +/// cause, any information that may help track down the problem, background +/// information, etc. +/// * [ErrorSpacer], which renders as a blank line. +/// * [FlutterError], which is the most common place to use an [ErrorHint]. +class ErrorHint extends _ErrorDiagnostic { + /// A lint enforces that this constructor can only be called with a string + /// literal to match the limitations of the Dart Kernel transformer that + /// optionally extracts out objects referenced using string interpolation in + /// the message passed in. + /// + /// The message will display with the same text regardless of whether the + /// kernel transformer is used. The kernel transformer is required so that + /// debugging tools can provide interactive displays of objects described by + /// the error. + ErrorHint(super.message) : super(level:DiagnosticLevel.hint); + + /// Calls to the default constructor may be rewritten to use this constructor + /// in debug mode using a kernel transformer. + // ignore: unused_element + ErrorHint._fromParts(super.messageParts) : super._fromParts(level:DiagnosticLevel.hint); +} + +/// An [ErrorSpacer] creates an empty [DiagnosticsNode], that can be used to +/// tune the spacing between other [DiagnosticsNode] objects. +class ErrorSpacer extends DiagnosticsProperty { + /// Creates an empty space to insert into a list of [DiagnosticsNode] objects + /// typically within a [FlutterError] object. + ErrorSpacer() : super( + '', + null, + description: '', + showName: false, + ); +} + +/// Class for information provided to [FlutterExceptionHandler] callbacks. +/// +/// {@tool snippet} +/// This is an example of using [FlutterErrorDetails] when calling +/// [FlutterError.reportError]. +/// +/// ```dart +/// void main() { +/// try { +/// // Try to do something! +/// } catch (error) { +/// // Catch & report error. +/// FlutterError.reportError(FlutterErrorDetails( +/// exception: error, +/// library: 'Flutter test framework', +/// context: ErrorSummary('while running async test code'), +/// )); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [FlutterError.onError], which is called whenever the Flutter framework +/// catches an error. +class FlutterErrorDetails with Diagnosticable { + /// Creates a [FlutterErrorDetails] object with the given arguments setting + /// the object's properties. + /// + /// The framework calls this constructor when catching an exception that will + /// subsequently be reported using [FlutterError.onError]. + const FlutterErrorDetails({ + required this.exception, + this.stack, + this.library = 'Flutter framework', + this.context, + this.stackFilter, + this.informationCollector, + this.silent = false, + }); + + /// Creates a copy of the error details but with the given fields replaced + /// with new values. + FlutterErrorDetails copyWith({ + DiagnosticsNode? context, + Object? exception, + InformationCollector? informationCollector, + String? library, + bool? silent, + StackTrace? stack, + IterableFilter? stackFilter, + }) { + return FlutterErrorDetails( + context: context ?? this.context, + exception: exception ?? this.exception, + informationCollector: informationCollector ?? this.informationCollector, + library: library ?? this.library, + silent: silent ?? this.silent, + stack: stack ?? this.stack, + stackFilter: stackFilter ?? this.stackFilter, + ); + } + + /// Transformers to transform [DiagnosticsNode] in [DiagnosticPropertiesBuilder] + /// into a more descriptive form. + /// + /// There are layers that attach certain [DiagnosticsNode] into + /// [FlutterErrorDetails] that require knowledge from other layers to parse. + /// To correctly interpret those [DiagnosticsNode], register transformers in + /// the layers that possess the knowledge. + /// + /// See also: + /// + /// * [WidgetsBinding.initInstances], which registers its transformer. + static final List propertiesTransformers = + []; + + /// The exception. Often this will be an [AssertionError], maybe specifically + /// a [FlutterError]. However, this could be any value at all. + final Object exception; + + /// The stack trace from where the [exception] was thrown (as opposed to where + /// it was caught). + /// + /// StackTrace objects are opaque except for their [toString] function. + /// + /// If this field is not null, then the [stackFilter] callback, if any, will + /// be called with the result of calling [toString] on this object and + /// splitting that result on line breaks. If there's no [stackFilter] + /// callback, then [FlutterError.defaultStackFilter] is used instead. That + /// function expects the stack to be in the format used by + /// [StackTrace.toString]. + final StackTrace? stack; + + /// A human-readable brief name describing the library that caught the error + /// message. This is used by the default error handler in the header dumped to + /// the console. + final String? library; + + /// A [DiagnosticsNode] that provides a human-readable description of where + /// the error was caught (as opposed to where it was thrown). + /// + /// The node, e.g. an [ErrorDescription], should be in a form that will make + /// sense in English when following the word "thrown", as in "thrown while + /// obtaining the image from the network" (for the context "while obtaining + /// the image from the network"). + /// + /// {@tool snippet} + /// This is an example of using and [ErrorDescription] as the + /// [FlutterErrorDetails.context] when calling [FlutterError.reportError]. + /// + /// ```dart + /// void maybeDoSomething() { + /// try { + /// // Try to do something! + /// } catch (error) { + /// // Catch & report error. + /// FlutterError.reportError(FlutterErrorDetails( + /// exception: error, + /// library: 'Flutter test framework', + /// context: ErrorDescription('while dispatching notifications for $runtimeType'), + /// )); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [ErrorDescription], which provides an explanation of the problem and + /// its cause, any information that may help track down the problem, + /// background information, etc. + /// * [ErrorSummary], which provides a short (one line) description of the + /// problem that was detected. + /// * [ErrorHint], which provides specific, non-obvious advice that may be + /// applicable. + /// * [FlutterError], which is the most common place to use + /// [FlutterErrorDetails]. + final DiagnosticsNode? context; + + /// A callback which filters the [stack] trace. Receives an iterable of + /// strings representing the frames encoded in the way that + /// [StackTrace.toString()] provides. Should return an iterable of lines to + /// output for the stack. + /// + /// If this is not provided, then [FlutterError.dumpErrorToConsole] will use + /// [FlutterError.defaultStackFilter] instead. + /// + /// If the [FlutterError.defaultStackFilter] behavior is desired, then the + /// callback should manually call that function. That function expects the + /// incoming list to be in the [StackTrace.toString()] format. The output of + /// that function, however, does not always follow this format. + /// + /// This won't be called if [stack] is null. + final IterableFilter? stackFilter; + + /// A callback which will provide information that could help with debugging + /// the problem. + /// + /// Information collector callbacks can be expensive, so the generated + /// information should be cached by the caller, rather than the callback being + /// called multiple times. + /// + /// The callback is expected to return an iterable of [DiagnosticsNode] objects, + /// typically implemented using `sync*` and `yield`. + /// + /// {@tool snippet} + /// In this example, the information collector returns two pieces of information, + /// one broadly-applicable statement regarding how the error happened, and one + /// giving a specific piece of information that may be useful in some cases but + /// may also be irrelevant most of the time (an argument to the method). + /// + /// ```dart + /// void climbElevator(int pid) { + /// try { + /// // ... + /// } catch (error, stack) { + /// FlutterError.reportError(FlutterErrorDetails( + /// exception: error, + /// stack: stack, + /// informationCollector: () => [ + /// ErrorDescription('This happened while climbing the space elevator.'), + /// ErrorHint('The process ID is: $pid'), + /// ], + /// )); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// The following classes may be of particular use: + /// + /// * [ErrorDescription], for information that is broadly applicable to the + /// situation being described. + /// * [ErrorHint], for specific information that may not always be applicable + /// but can be helpful in certain situations. + /// * [DiagnosticsStackTrace], for reporting stack traces. + /// * [ErrorSpacer], for adding spaces (a blank line) between other items. + /// + /// For objects that implement [Diagnosticable] one may consider providing + /// additional information by yielding the output of the object's + /// [Diagnosticable.toDiagnosticsNode] method. + final InformationCollector? informationCollector; + + /// Whether this error should be ignored by the default error reporting + /// behavior in release mode. + /// + /// If this is false, the default, then the default error handler will always + /// dump this error to the console. + /// + /// If this is true, then the default error handler would only dump this error + /// to the console in debug mode. In release mode, the error is ignored. + /// + /// This is used by certain exception handlers that catch errors that could be + /// triggered by environmental conditions (as opposed to logic errors). For + /// example, the HTTP library sets this flag so as to not report every 404 + /// error to the console on end-user devices, while still allowing a custom + /// error handler to see the errors even in release builds. + final bool silent; + + /// Converts the [exception] to a string. + /// + /// This applies some additional logic to make [AssertionError] exceptions + /// prettier, to handle exceptions that stringify to empty strings, to handle + /// objects that don't inherit from [Exception] or [Error], and so forth. + String exceptionAsString() { + String? longMessage; + if (exception is AssertionError) { + // Regular _AssertionErrors thrown by assert() put the message last, after + // some code snippets. This leads to ugly messages. To avoid this, we move + // the assertion message up to before the code snippets, separated by a + // newline, if we recognize that format is being used. + final Object? message = (exception as AssertionError).message; + final String fullMessage = exception.toString(); + if (message is String && message != fullMessage) { + if (fullMessage.length > message.length) { + final int position = fullMessage.lastIndexOf(message); + if (position == fullMessage.length - message.length && + position > 2 && + fullMessage.substring(position - 2, position) == ': ') { + // Add a linebreak so that the filename at the start of the + // assertion message is always on its own line. + String body = fullMessage.substring(0, position - 2); + final int splitPoint = body.indexOf(' Failed assertion:'); + if (splitPoint >= 0) { + body = '${body.substring(0, splitPoint)}\n${body.substring(splitPoint + 1)}'; + } + longMessage = '${message.trimRight()}\n$body'; + } + } + } + longMessage ??= fullMessage; + } else if (exception is String) { + longMessage = exception as String; + } else if (exception is Error || exception is Exception) { + longMessage = exception.toString(); + } else { + longMessage = ' $exception'; + } + longMessage = longMessage.trimRight(); + if (longMessage.isEmpty) { + longMessage = ' '; + } + return longMessage; + } + + Diagnosticable? _exceptionToDiagnosticable() { + final Object exception = this.exception; + if (exception is FlutterError) { + return exception; + } + if (exception is AssertionError && exception.message is FlutterError) { + return exception.message! as FlutterError; + } + return null; + } + + /// Returns a short (one line) description of the problem that was detected. + /// + /// If the exception contains an [ErrorSummary] that summary is used, + /// otherwise the summary is inferred from the string representation of the + /// exception. + /// + /// In release mode, this always returns a [DiagnosticsNode.message] with a + /// formatted version of the exception. + DiagnosticsNode get summary { + String formatException() => exceptionAsString().split('\n')[0].trimLeft(); + if (kReleaseMode) { + return DiagnosticsNode.message(formatException()); + } + final Diagnosticable? diagnosticable = _exceptionToDiagnosticable(); + DiagnosticsNode? summary; + if (diagnosticable != null) { + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + debugFillProperties(builder); + summary = builder.properties.cast().firstWhere((DiagnosticsNode? node) => node!.level == DiagnosticLevel.summary, orElse: () => null); + } + return summary ?? ErrorSummary(formatException()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final DiagnosticsNode verb = ErrorDescription('thrown${ context != null ? ErrorDescription(" $context") : ""}'); + final Diagnosticable? diagnosticable = _exceptionToDiagnosticable(); + if (exception is num) { + properties.add(ErrorDescription('The number $exception was $verb.')); + } else { + final DiagnosticsNode errorName; + if (exception is AssertionError) { + errorName = ErrorDescription('assertion'); + } else if (exception is String) { + errorName = ErrorDescription('message'); + } else if (exception is Error || exception is Exception) { + errorName = ErrorDescription('${exception.runtimeType}'); + } else { + errorName = ErrorDescription('${exception.runtimeType} object'); + } + properties.add(ErrorDescription('The following $errorName was $verb:')); + if (diagnosticable != null) { + diagnosticable.debugFillProperties(properties); + } else { + // Many exception classes put their type at the head of their message. + // This is redundant with the way we display exceptions, so attempt to + // strip out that header when we see it. + final String prefix = '${exception.runtimeType}: '; + String message = exceptionAsString(); + if (message.startsWith(prefix)) { + message = message.substring(prefix.length); + } + properties.add(ErrorSummary(message)); + } + } + + if (stack != null) { + if (exception is AssertionError && diagnosticable == null) { + // After popping off any dart: stack frames, are there at least two more + // stack frames coming from package flutter? + // + // If not: Error is in user code (user violated assertion in framework). + // If so: Error is in Framework. We either need an assertion higher up + // in the stack, or we've violated our own assertions. + final List stackFrames = StackFrame.fromStackTrace(FlutterError.demangleStackTrace(stack!)) + .skipWhile((StackFrame frame) => frame.packageScheme == 'dart') + .toList(); + final bool ourFault = stackFrames.length >= 2 + && stackFrames[0].package == 'flutter' + && stackFrames[1].package == 'flutter'; + if (ourFault) { + properties.add(ErrorSpacer()); + properties.add(ErrorHint( + 'Either the assertion indicates an error in the framework itself, or we should ' + 'provide substantially more information in this error message to help you determine ' + 'and fix the underlying cause.\n' + 'In either case, please report this assertion by filing a bug on GitHub:\n' + ' https://github.com/flutter/flutter/issues/new?template=2_bug.yml', + )); + } + } + properties.add(ErrorSpacer()); + properties.add(DiagnosticsStackTrace('When the exception was thrown, this was the stack', stack, stackFilter: stackFilter)); + } + if (informationCollector != null) { + properties.add(ErrorSpacer()); + informationCollector!().forEach(properties.add); + } + } + + @override + String toStringShort() { + return library != null ? 'Exception caught by $library' : 'Exception caught'; + } + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return toDiagnosticsNode(style: DiagnosticsTreeStyle.error).toStringDeep(minLevel: minLevel); + } + + @override + DiagnosticsNode toDiagnosticsNode({ String? name, DiagnosticsTreeStyle? style }) { + return _FlutterErrorDetailsNode( + name: name, + value: this, + style: style, + ); + } +} + +/// Error class used to report Flutter-specific assertion failures and +/// contract violations. +/// +/// See also: +/// +/// * , more information about error +/// handling in Flutter. +class FlutterError extends Error with DiagnosticableTreeMixin implements AssertionError { + /// Create an error message from a string. + /// + /// The message may have newlines in it. The first line should be a terse + /// description of the error, e.g. "Incorrect GlobalKey usage" or "setState() + /// or markNeedsBuild() called during build". Subsequent lines should contain + /// substantial additional information, ideally sufficient to develop a + /// correct solution to the problem. + /// + /// In some cases, when a [FlutterError] is reported to the user, only the first + /// line is included. For example, Flutter will typically only fully report + /// the first exception at runtime, displaying only the first line of + /// subsequent errors. + /// + /// All sentences in the error should be correctly punctuated (i.e., + /// do end the error message with a period). + /// + /// This constructor defers to the [FlutterError.fromParts] constructor. + /// The first line is wrapped in an implied [ErrorSummary], and subsequent + /// lines are wrapped in implied [ErrorDescription]s. Consider using the + /// [FlutterError.fromParts] constructor to provide more detail, e.g. + /// using [ErrorHint]s or other [DiagnosticsNode]s. + factory FlutterError(String message) { + final List lines = message.split('\n'); + return FlutterError.fromParts([ + ErrorSummary(lines.first), + ...lines.skip(1).map((String line) => ErrorDescription(line)), + ]); + } + + /// Create an error message from a list of [DiagnosticsNode]s. + /// + /// By convention, there should be exactly one [ErrorSummary] in the list, + /// and it should be the first entry. + /// + /// Other entries are typically [ErrorDescription]s (for material that is + /// always applicable for this error) and [ErrorHint]s (for material that may + /// be sometimes useful, but may not always apply). Other [DiagnosticsNode] + /// subclasses, such as [DiagnosticsStackTrace], may + /// also be used. + /// + /// When using an [ErrorSummary], [ErrorDescription]s, and [ErrorHint]s, in + /// debug builds, values interpolated into the `message` arguments of those + /// classes' constructors are expanded and placed into the + /// [DiagnosticsProperty.value] property of those objects (which is of type + /// [List]). This allows IDEs to examine values interpolated into + /// error messages. + /// + /// Alternatively, to include a specific [Diagnosticable] object into the + /// error message and have the object describe itself in detail (see + /// [DiagnosticsNode.toStringDeep]), consider calling + /// [Diagnosticable.toDiagnosticsNode] on that object and using that as one of + /// the values passed to this constructor. + /// + /// {@tool snippet} + /// In this example, an error is thrown in debug mode if certain conditions + /// are not met. The error message includes a description of an object that + /// implements the [Diagnosticable] interface, `draconis`. + /// + /// ```dart + /// void controlDraconis() { + /// assert(() { + /// if (!draconisAlive || !draconisAmulet) { + /// throw FlutterError.fromParts([ + /// ErrorSummary('Cannot control Draconis in current state.'), + /// ErrorDescription('Draconis can only be controlled while alive and while the amulet is wielded.'), + /// if (!draconisAlive) + /// ErrorHint('Draconis is currently not alive.'), + /// if (!draconisAmulet) + /// ErrorHint('The Amulet of Draconis is currently not wielded.'), + /// draconis.toDiagnosticsNode(name: 'Draconis'), + /// ]); + /// } + /// return true; + /// }()); + /// // ... + /// } + /// ``` + /// {@end-tool} + FlutterError.fromParts(this.diagnostics) : assert(diagnostics.isNotEmpty, FlutterError.fromParts([ErrorSummary('Empty FlutterError')])) { + assert( + diagnostics.first.level == DiagnosticLevel.summary, + FlutterError.fromParts([ + ErrorSummary('FlutterError is missing a summary.'), + ErrorDescription( + 'All FlutterError objects should start with a short (one line) ' + 'summary description of the problem that was detected.', + ), + DiagnosticsProperty('Malformed', this, expandableValue: true, showSeparator: false, style: DiagnosticsTreeStyle.whitespace), + ErrorDescription( + '\nThis error should still help you solve your problem, ' + 'however please also report this malformed error in the ' + 'framework by filing a bug on GitHub:\n' + ' https://github.com/flutter/flutter/issues/new?template=2_bug.yml', + ), + ]), + ); + assert(() { + final Iterable summaries = diagnostics.where((DiagnosticsNode node) => node.level == DiagnosticLevel.summary); + if (summaries.length > 1) { + final List message = [ + ErrorSummary('FlutterError contained multiple error summaries.'), + ErrorDescription( + 'All FlutterError objects should have only a single short ' + '(one line) summary description of the problem that was ' + 'detected.', + ), + DiagnosticsProperty('Malformed', this, expandableValue: true, showSeparator: false, style: DiagnosticsTreeStyle.whitespace), + ErrorDescription('\nThe malformed error has ${summaries.length} summaries.'), + ]; + int i = 1; + for (final DiagnosticsNode summary in summaries) { + message.add(DiagnosticsProperty('Summary $i', summary, expandableValue : true)); + i += 1; + } + message.add(ErrorDescription( + '\nThis error should still help you solve your problem, ' + 'however please also report this malformed error in the ' + 'framework by filing a bug on GitHub:\n' + ' https://github.com/flutter/flutter/issues/new?template=2_bug.yml', + )); + throw FlutterError.fromParts(message); + } + return true; + }()); + } + + /// The information associated with this error, in structured form. + /// + /// The first node is typically an [ErrorSummary] giving a short description + /// of the problem, suitable for an index of errors, a log, etc. + /// + /// Subsequent nodes should give information specific to this error. Typically + /// these will be [ErrorDescription]s or [ErrorHint]s, but they could be other + /// objects also. For instance, an error relating to a timer could include a + /// stack trace of when the timer was scheduled using the + /// [DiagnosticsStackTrace] class. + final List diagnostics; + + /// The message associated with this error. + /// + /// This is generated by serializing the [diagnostics]. + @override + String get message => toString(); + + /// Called whenever the Flutter framework catches an error. + /// + /// The default behavior is to call [presentError]. + /// + /// You can set this to your own function to override this default behavior. + /// For example, you could report all errors to your server. Consider calling + /// [presentError] from your custom error handler in order to see the logs in + /// the console as well. + /// + /// If the error handler throws an exception, it will not be caught by the + /// Flutter framework. + /// + /// Set this to null to silently catch and ignore errors. This is not + /// recommended. + /// + /// Do not call [onError] directly, instead, call [reportError], which + /// forwards to [onError] if it is not null. + /// + /// See also: + /// + /// * , more information about error + /// handling in Flutter. + static FlutterExceptionHandler? onError = presentError; + + /// Called by the Flutter framework before attempting to parse a [StackTrace]. + /// + /// Some [StackTrace] implementations have a different [toString] format from + /// what the framework expects, like ones from `package:stack_trace`. To make + /// sure we can still parse and filter mangled [StackTrace]s, the framework + /// first calls this function to demangle them. + /// + /// This should be set in any environment that could propagate an unusual + /// stack trace to the framework. Otherwise, the default behavior is to assume + /// all stack traces are in a format usually generated by Dart. + /// + /// The following example demangles `package:stack_trace` traces by converting + /// them into VM traces, which the framework is able to parse: + /// + /// ```dart + /// FlutterError.demangleStackTrace = (StackTrace stack) { + /// // Trace and Chain are classes in package:stack_trace + /// if (stack is Trace) { + /// return stack.vmTrace; + /// } + /// if (stack is Chain) { + /// return stack.toTrace().vmTrace; + /// } + /// return stack; + /// }; + /// ``` + static StackTraceDemangler demangleStackTrace = _defaultStackTraceDemangler; + + static StackTrace _defaultStackTraceDemangler(StackTrace stackTrace) => stackTrace; + + /// Called whenever the Flutter framework wants to present an error to the + /// users. + /// + /// The default behavior is to call [dumpErrorToConsole]. + /// + /// Plugins can override how an error is to be presented to the user. For + /// example, the structured errors service extension sets its own method when + /// the extension is enabled. If you want to change how Flutter responds to an + /// error, use [onError] instead. + static FlutterExceptionHandler presentError = dumpErrorToConsole; + + static int _errorCount = 0; + + /// Resets the count of errors used by [dumpErrorToConsole] to decide whether + /// to show a complete error message or an abbreviated one. + /// + /// After this is called, the next error message will be shown in full. + static void resetErrorCount() { + _errorCount = 0; + } + + /// The width to which [dumpErrorToConsole] will wrap lines. + /// + /// This can be used to ensure strings will not exceed the length at which + /// they will wrap, e.g. when placing ASCII art diagrams in messages. + static const int wrapWidth = 100; + + /// Prints the given exception details to the console. + /// + /// The first time this is called, it dumps a very verbose message to the + /// console using [debugPrint]. + /// + /// Subsequent calls only dump the first line of the exception, unless + /// `forceReport` is set to true (in which case it dumps the verbose message). + /// + /// Call [resetErrorCount] to cause this method to go back to acting as if it + /// had not been called before (so the next message is verbose again). + /// + /// The default behavior for the [onError] handler is to call this function. + static void dumpErrorToConsole(FlutterErrorDetails details, { bool forceReport = false }) { + bool isInDebugMode = false; + assert(() { + // In debug mode, we ignore the "silent" flag. + isInDebugMode = true; + return true; + }()); + final bool reportError = isInDebugMode || !details.silent; + if (!reportError && !forceReport) { + return; + } + if (_errorCount == 0 || forceReport) { + // Diagnostics is only available in debug mode. In profile and release modes fallback to plain print. + if (isInDebugMode) { + debugPrint( + TextTreeRenderer( + wrapWidthProperties: wrapWidth, + maxDescendentsTruncatableNode: 5, + ).render(details.toDiagnosticsNode(style: DiagnosticsTreeStyle.error)).trimRight(), + ); + } else { + debugPrintStack( + stackTrace: details.stack, + label: details.exception.toString(), + maxFrames: 100, + ); + } + } else { + debugPrint('Another exception was thrown: ${details.summary}'); + } + _errorCount += 1; + } + + static final List _stackFilters = []; + + /// Adds a stack filtering function to [defaultStackFilter]. + /// + /// For example, the framework adds common patterns of element building to + /// elide tree-walking patterns in the stack trace. + /// + /// Added filters are checked in order of addition. The first matching filter + /// wins, and subsequent filters will not be checked. + static void addDefaultStackFilter(StackFilter filter) { + _stackFilters.add(filter); + } + + /// Converts a stack to a string that is more readable by omitting stack + /// frames that correspond to Dart internals. + /// + /// This is the default filter used by [dumpErrorToConsole] if the + /// [FlutterErrorDetails] object has no [FlutterErrorDetails.stackFilter] + /// callback. + /// + /// This function expects its input to be in the format used by + /// [StackTrace.toString()]. The output of this function is similar to that + /// format but the frame numbers will not be consecutive (frames are elided) + /// and the final line may be prose rather than a stack frame. + static Iterable defaultStackFilter(Iterable frames) { + final Map removedPackagesAndClasses = { + 'dart:async-patch': 0, + 'dart:async': 0, + 'package:stack_trace': 0, + 'class _AssertionError': 0, + 'class _FakeAsync': 0, + 'class _FrameCallbackEntry': 0, + 'class _Timer': 0, + 'class _RawReceivePortImpl': 0, + }; + int skipped = 0; + + final List parsedFrames = StackFrame.fromStackString(frames.join('\n')); + + for (int index = 0; index < parsedFrames.length; index += 1) { + final StackFrame frame = parsedFrames[index]; + final String className = 'class ${frame.className}'; + final String package = '${frame.packageScheme}:${frame.package}'; + if (removedPackagesAndClasses.containsKey(className)) { + skipped += 1; + removedPackagesAndClasses.update(className, (int value) => value + 1); + parsedFrames.removeAt(index); + index -= 1; + } else if (removedPackagesAndClasses.containsKey(package)) { + skipped += 1; + removedPackagesAndClasses.update(package, (int value) => value + 1); + parsedFrames.removeAt(index); + index -= 1; + } + } + final List reasons = List.filled(parsedFrames.length, null); + for (final StackFilter filter in _stackFilters) { + filter.filter(parsedFrames, reasons); + } + + final List result = []; + + // Collapse duplicated reasons. + for (int index = 0; index < parsedFrames.length; index += 1) { + final int start = index; + while (index < reasons.length - 1 && reasons[index] != null && reasons[index + 1] == reasons[index]) { + index++; + } + String suffix = ''; + if (reasons[index] != null) { + if (index != start) { + suffix = ' (${index - start + 2} frames)'; + } else { + suffix = ' (1 frame)'; + } + } + final String resultLine = '${reasons[index] ?? parsedFrames[index].source}$suffix'; + result.add(resultLine); + } + + // Only include packages we actually elided from. + final List where = [ + for (final MapEntry entry in removedPackagesAndClasses.entries) + if (entry.value > 0) + entry.key, + ]..sort(); + if (skipped == 1) { + result.add('(elided one frame from ${where.single})'); + } else if (skipped > 1) { + if (where.length > 1) { + where[where.length - 1] = 'and ${where.last}'; + } + if (where.length > 2) { + result.add('(elided $skipped frames from ${where.join(", ")})'); + } else { + result.add('(elided $skipped frames from ${where.join(" ")})'); + } + } + return result; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + diagnostics.forEach(properties.add); + } + + @override + String toStringShort() => 'FlutterError'; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + if (kReleaseMode) { + final Iterable<_ErrorDiagnostic> errors = diagnostics.whereType<_ErrorDiagnostic>(); + return errors.isNotEmpty ? errors.first.valueToString() : toStringShort(); + } + // Avoid wrapping lines. + final TextTreeRenderer renderer = TextTreeRenderer(wrapWidth: 4000000000); + return diagnostics.map((DiagnosticsNode node) => renderer.render(node).trimRight()).join('\n'); + } + + /// Calls [onError] with the given details, unless it is null. + /// + /// {@tool snippet} + /// When calling this from a `catch` block consider annotating the method + /// containing the `catch` block with + /// `@pragma('vm:notify-debugger-on-exception')` to allow an attached debugger + /// to treat the exception as unhandled. This means instead of executing the + /// `catch` block, the debugger can break at the original source location from + /// which the exception was thrown. + /// + /// ```dart + /// @pragma('vm:notify-debugger-on-exception') + /// void doSomething() { + /// try { + /// methodThatMayThrow(); + /// } catch (exception, stack) { + /// FlutterError.reportError(FlutterErrorDetails( + /// exception: exception, + /// stack: stack, + /// library: 'example library', + /// context: ErrorDescription('while doing something'), + /// )); + /// } + /// } + /// ``` + /// {@end-tool} + static void reportError(FlutterErrorDetails details) { + onError?.call(details); + } +} + +/// Dump the stack to the console using [debugPrint] and +/// [FlutterError.defaultStackFilter]. +/// +/// If the `stackTrace` parameter is null, the [StackTrace.current] is used to +/// obtain the stack. +/// +/// The `maxFrames` argument can be given to limit the stack to the given number +/// of lines before filtering is applied. By default, all stack lines are +/// included. +/// +/// The `label` argument, if present, will be printed before the stack. +void debugPrintStack({StackTrace? stackTrace, String? label, int? maxFrames}) { + if (label != null) { + debugPrint(label); + } + if (stackTrace == null) { + stackTrace = StackTrace.current; + } else { + stackTrace = FlutterError.demangleStackTrace(stackTrace); + } + Iterable lines = stackTrace.toString().trimRight().split('\n'); + if (kIsWeb && lines.isNotEmpty) { + // Remove extra call to StackTrace.current for web platform. + // TODO(ferhat): remove when https://github.com/flutter/flutter/issues/37635 + // is addressed. + lines = lines.skipWhile((String line) { + return line.contains('StackTrace.current') || + line.contains('dart-sdk/lib/_internal') || + line.contains('dart:sdk_internal'); + }); + } + if (maxFrames != null) { + lines = lines.take(maxFrames); + } + debugPrint(FlutterError.defaultStackFilter(lines).join('\n')); +} + +/// Diagnostic with a [StackTrace] [value] suitable for displaying stack traces +/// as part of a [FlutterError] object. +class DiagnosticsStackTrace extends DiagnosticsBlock { + /// Creates a diagnostic for a stack trace. + /// + /// [name] describes a name the stack trace is given, e.g. + /// `When the exception was thrown, this was the stack`. + /// [stackFilter] provides an optional filter to use to filter which frames + /// are included. If no filter is specified, [FlutterError.defaultStackFilter] + /// is used. + /// [showSeparator] indicates whether to include a ':' after the [name]. + DiagnosticsStackTrace( + String name, + StackTrace? stack, { + IterableFilter? stackFilter, + super.showSeparator, + }) : super( + name: name, + value: stack, + properties: _applyStackFilter(stack, stackFilter), + style: DiagnosticsTreeStyle.flat, + allowTruncate: true, + ); + + /// Creates a diagnostic describing a single frame from a StackTrace. + DiagnosticsStackTrace.singleFrame( + String name, { + required String frame, + super.showSeparator, + }) : super( + name: name, + properties: [_createStackFrame(frame)], + style: DiagnosticsTreeStyle.whitespace, + ); + + static List _applyStackFilter( + StackTrace? stack, + IterableFilter? stackFilter, + ) { + if (stack == null) { + return []; + } + final IterableFilter filter = stackFilter ?? FlutterError.defaultStackFilter; + final Iterable frames = filter('${FlutterError.demangleStackTrace(stack)}'.trimRight().split('\n')); + return frames.map(_createStackFrame).toList(); + } + + static DiagnosticsNode _createStackFrame(String frame) { + return DiagnosticsNode.message(frame, allowWrap: false); + } + + @override + bool get allowTruncate => false; +} + +class _FlutterErrorDetailsNode extends DiagnosticableNode { + _FlutterErrorDetailsNode({ + super.name, + required super.value, + required super.style, + }); + + @override + DiagnosticPropertiesBuilder? get builder { + final DiagnosticPropertiesBuilder? builder = super.builder; + if (builder == null) { + return null; + } + Iterable properties = builder.properties; + for (final DiagnosticPropertiesTransformer transformer in FlutterErrorDetails.propertiesTransformers) { + properties = transformer(properties); + } + return DiagnosticPropertiesBuilder.fromProperties(properties.toList()); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/basic_types.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/basic_types.dart new file mode 100644 index 0000000000000000000000000000000000000000..27c9bc9222923032deb61b970673167974ed240a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/basic_types.dart @@ -0,0 +1,250 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; + +// COMMON SIGNATURES + +/// Signature for callbacks that report that an underlying value has changed. +/// +/// See also: +/// +/// * [ValueSetter], for callbacks that report that a value has been set. +typedef ValueChanged = void Function(T value); + +/// Signature for callbacks that report that a value has been set. +/// +/// This is the same signature as [ValueChanged], but is used when the +/// callback is called even if the underlying value has not changed. +/// For example, service extensions use this callback because they +/// call the callback whenever the extension is called with a +/// value, regardless of whether the given value is new or not. +/// +/// See also: +/// +/// * [ValueGetter], the getter equivalent of this signature. +/// * [AsyncValueSetter], an asynchronous version of this signature. +typedef ValueSetter = void Function(T value); + +/// Signature for callbacks that are to report a value on demand. +/// +/// See also: +/// +/// * [ValueSetter], the setter equivalent of this signature. +/// * [AsyncValueGetter], an asynchronous version of this signature. +typedef ValueGetter = T Function(); + +/// Signature for callbacks that filter an iterable. +typedef IterableFilter = Iterable Function(Iterable input); + +/// Signature of callbacks that have no arguments and return no data, but that +/// return a [Future] to indicate when their work is complete. +/// +/// See also: +/// +/// * [VoidCallback], a synchronous version of this signature. +/// * [AsyncValueGetter], a signature for asynchronous getters. +/// * [AsyncValueSetter], a signature for asynchronous setters. +typedef AsyncCallback = Future Function(); + +/// Signature for callbacks that report that a value has been set and return a +/// [Future] that completes when the value has been saved. +/// +/// See also: +/// +/// * [ValueSetter], a synchronous version of this signature. +/// * [AsyncValueGetter], the getter equivalent of this signature. +typedef AsyncValueSetter = Future Function(T value); + +/// Signature for callbacks that are to asynchronously report a value on demand. +/// +/// See also: +/// +/// * [ValueGetter], a synchronous version of this signature. +/// * [AsyncValueSetter], the setter equivalent of this signature. +typedef AsyncValueGetter = Future Function(); + +// LAZY CACHING ITERATOR + +/// A lazy caching version of [Iterable]. +/// +/// This iterable is efficient in the following ways: +/// +/// * It will not walk the given iterator more than you ask for. +/// +/// * If you use it twice (e.g. you check [isNotEmpty], then +/// use [single]), it will only walk the given iterator +/// once. This caching will even work efficiently if you are +/// running two side-by-side iterators on the same iterable. +/// +/// * [toList] uses its EfficientLength variant to create its +/// list quickly. +/// +/// It is inefficient in the following ways: +/// +/// * The first iteration through has caching overhead. +/// +/// * It requires more memory than a non-caching iterator. +/// +/// * The [length] and [toList] properties immediately pre-cache the +/// entire list. Using these fields therefore loses the laziness of +/// the iterable. However, it still gets cached. +/// +/// The caching behavior is propagated to the iterators that are +/// created by [map], [where], [expand], [take], [takeWhile], [skip], +/// and [skipWhile], and is used by the built-in methods that use an +/// iterator like [isNotEmpty] and [single]. +/// +/// Because a CachingIterable only walks the underlying data once, it +/// cannot be used multiple times with the underlying data changing +/// between each use. You must create a new iterable each time. This +/// also applies to any iterables derived from this one, e.g. as +/// returned by `where`. +class CachingIterable extends IterableBase { + /// Creates a [CachingIterable] using the given [Iterator] as the source of + /// data. The iterator must not throw exceptions. + /// + /// Since the argument is an [Iterator], not an [Iterable], it is + /// guaranteed that the underlying data set will only be walked + /// once. If you have an [Iterable], you can pass its [iterator] + /// field as the argument to this constructor. + /// + /// You can this with an existing `sync*` function as follows: + /// + /// ```dart + /// Iterable range(int start, int end) sync* { + /// for (int index = start; index <= end; index += 1) { + /// yield index; + /// } + /// } + /// + /// Iterable i = CachingIterable(range(1, 5).iterator); + /// print(i.length); // walks the list + /// print(i.length); // efficient + /// ``` + /// + /// Beware that this will eagerly evaluate the `range` iterable, and because + /// of that it would be better to just implement `range` as something that + /// returns a `List` to begin with if possible. + CachingIterable(this._prefillIterator); + + final Iterator _prefillIterator; + final List _results = []; + + @override + Iterator get iterator { + return _LazyListIterator(this); + } + + @override + Iterable map(T Function(E e) toElement) { + return CachingIterable(super.map(toElement).iterator); + } + + @override + Iterable where(bool Function(E element) test) { + return CachingIterable(super.where(test).iterator); + } + + @override + Iterable expand(Iterable Function(E element) toElements) { + return CachingIterable(super.expand(toElements).iterator); + } + + @override + Iterable take(int count) { + return CachingIterable(super.take(count).iterator); + } + + @override + Iterable takeWhile(bool Function(E value) test) { + return CachingIterable(super.takeWhile(test).iterator); + } + + @override + Iterable skip(int count) { + return CachingIterable(super.skip(count).iterator); + } + + @override + Iterable skipWhile(bool Function(E value) test) { + return CachingIterable(super.skipWhile(test).iterator); + } + + @override + int get length { + _precacheEntireList(); + return _results.length; + } + + @override + List toList({ bool growable = true }) { + _precacheEntireList(); + return List.of(_results, growable: growable); + } + + void _precacheEntireList() { + while (_fillNext()) { } + } + + bool _fillNext() { + if (!_prefillIterator.moveNext()) { + return false; + } + _results.add(_prefillIterator.current); + return true; + } +} + +class _LazyListIterator implements Iterator { + _LazyListIterator(this._owner) : _index = -1; + + final CachingIterable _owner; + int _index; + + @override + E get current { + assert(_index >= 0); // called "current" before "moveNext()" + if (_index < 0 || _index == _owner._results.length) { + throw StateError('current can not be call after moveNext has returned false'); + } + return _owner._results[_index]; + } + + @override + bool moveNext() { + if (_index >= _owner._results.length) { + return false; + } + _index += 1; + if (_index == _owner._results.length) { + return _owner._fillNext(); + } + return true; + } +} + +/// A factory interface that also reports the type of the created objects. +class Factory { + /// Creates a new factory. + const Factory(this.constructor); + + /// Creates a new object of type T. + final ValueGetter constructor; + + /// The type of the objects created by this factory. + Type get type => T; + + @override + String toString() { + return 'Factory(type: $type)'; + } +} + +/// Linearly interpolate between two `Duration`s. +Duration lerpDuration(Duration a, Duration b, double t) { + return Duration( + microseconds: (a.inMicroseconds + (b.inMicroseconds - a.inMicroseconds) * t).round(), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/binding.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/binding.dart new file mode 100644 index 0000000000000000000000000000000000000000..a663cf971681327895b3c8bd39b1f9f12c06d3b2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/binding.dart @@ -0,0 +1,973 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:convert' show json; +import 'dart:developer' as developer; +import 'dart:io' show exit; +import 'dart:ui' as ui show Brightness, PlatformDispatcher, SingletonFlutterWindow, window; // ignore: deprecated_member_use + +// Before adding any more dart:ui imports, please read the README. + +import 'package:meta/meta.dart'; + +import 'assertions.dart'; +import 'basic_types.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'object.dart'; +import 'platform.dart'; +import 'print.dart'; +import 'service_extensions.dart'; +import 'timeline.dart'; + +export 'dart:ui' show PlatformDispatcher, SingletonFlutterWindow, clampDouble; // ignore: deprecated_member_use + +export 'basic_types.dart' show AsyncCallback, AsyncValueGetter, AsyncValueSetter; + +// Examples can assume: +// mixin BarBinding on BindingBase { } + +/// Signature for service extensions. +/// +/// The returned map must not contain the keys "type" or "method", as +/// they will be replaced before the value is sent to the client. The +/// "type" key will be set to the string `_extensionType` to indicate +/// that this is a return value from a service extension, and the +/// "method" key will be set to the full name of the method. +typedef ServiceExtensionCallback = Future> Function(Map parameters); + +/// Base class for mixins that provide singleton services. +/// +/// The Flutter engine ([dart:ui]) exposes some low-level services, +/// but these are typically not suitable for direct use, for example +/// because they only provide a single callback which an application +/// may wish to multiplex to allow multiple listeners. +/// +/// Bindings provide the glue between these low-level APIs and the +/// higher-level framework APIs. They _bind_ the two together, whence +/// the name. +/// +/// ## Implementing a binding mixin +/// +/// A library would typically create a new binding mixin to expose a +/// feature in [dart:ui]. This is rare in general, but it is something +/// that an alternative framework would do, e.g. if a framework were +/// to replace the [widgets] library with an alternative API but still +/// wished to leverage the [services] and [foundation] libraries. +/// +/// To create a binding mixin, declare a mixin `on` the [BindingBase] class +/// and whatever other bindings the concrete binding must implement for +/// this binding mixin to be useful. +/// +/// The mixin is guaranteed to only be constructed once in the +/// lifetime of the app; this is handled by [initInstances]. +/// +/// A binding mixin must at a minimum implement the following features: +/// +/// * The [initInstances] method, which must call `super.initInstances` and +/// set an `_instance` static field to `this`. +/// * An `instance` static getter, which must return that field using [checkInstance]. +/// +/// In addition, it should implement whatever singleton features the library needs. +/// +/// As a general rule, the less can be placed in the binding, the +/// better. Prefer having APIs that takes objects rather than having +/// them refer to global singletons. Bindings are best limited to +/// exposing features that literally only exist once, for example, the +/// APIs in [dart:ui]. +/// +/// {@tool snippet} +/// +/// Here is a basic example of a binding that implements these features. It relies on +/// another fictional binding called `BarBinding`. +/// +/// ```dart +/// mixin FooBinding on BindingBase, BarBinding { +/// @override +/// void initInstances() { +/// super.initInstances(); +/// _instance = this; +/// // ...binding initialization... +/// } +/// +/// static FooBinding get instance => BindingBase.checkInstance(_instance); +/// static FooBinding? _instance; +/// +/// // ...binding features... +/// } +/// ``` +/// {@end-tool} +/// +/// ## Implementing a binding class +/// +/// The top-most layer used to write the application (e.g. the Flutter +/// [widgets] library) will have a concrete class that inherits from +/// [BindingBase] and uses all the various [BindingBase] mixins (such +/// as [ServicesBinding]). The [widgets] library in Flutter introduces +/// a binding called [WidgetsFlutterBinding]. +/// +/// A binding _class_ should mix in the relevant bindings from each +/// layer that it wishes to expose, and should have an +/// `ensureInitialized` method that constructs the class if that +/// layer's mixin's `_instance` field is null. This allows the binding +/// to be overridden by developers who have more specific needs, while +/// still allowing other code to call `ensureInitialized` when a binding +/// is needed. +/// +/// {@tool snippet} +/// +/// A typical binding class is shown below. The `ensureInitialized` method's +/// return type is the library's binding mixin, rather than the concrete +/// class. +/// +/// ```dart +/// // continuing from previous example... +/// class FooLibraryBinding extends BindingBase with BarBinding, FooBinding { +/// static FooBinding ensureInitialized() { +/// if (FooBinding._instance == null) { +/// FooLibraryBinding(); +/// } +/// return FooBinding.instance; +/// } +/// } +/// ``` +/// {@end-tool} +abstract class BindingBase { + /// Default abstract constructor for bindings. + /// + /// First calls [initInstances] to have bindings initialize their + /// instance pointers and other state, then calls + /// [initServiceExtensions] to have bindings initialize their + /// VM service extensions, if any. + BindingBase() { + if (!kReleaseMode) { + FlutterTimeline.startSync('Framework initialization'); + } + assert(() { + _debugConstructed = true; + return true; + }()); + + assert(_debugInitializedType == null, 'Binding is already initialized to $_debugInitializedType'); + initInstances(); + assert(_debugInitializedType != null); + + assert(!_debugServiceExtensionsRegistered); + initServiceExtensions(); + assert(_debugServiceExtensionsRegistered); + + if (!kReleaseMode) { + developer.postEvent('Flutter.FrameworkInitialization', {}); + FlutterTimeline.finishSync(); + } + } + + bool _debugConstructed = false; + static Type? _debugInitializedType; + static bool _debugServiceExtensionsRegistered = false; + + /// Deprecated. Will be removed in a future version of Flutter. + /// + /// This property has been deprecated to prepare for Flutter's upcoming + /// support for multiple views and multiple windows. + /// + /// It represents the main view for applications where there is only one + /// view, such as applications designed for single-display mobile devices. + /// If the embedder supports multiple views, it points to the first view + /// created which is assumed to be the main view. It throws if no view has + /// been created yet or if the first view has been removed again. + /// + /// The following options exists to migrate code that relies on accessing + /// this deprecated property: + /// + /// If a [BuildContext] is available, consider looking up the current + /// [FlutterView] associated with that context via [View.of]. It gives access + /// to the same functionality as this deprecated property. However, the + /// platform-specific functionality has moved to the [PlatformDispatcher], + /// which may be accessed from the view returned by [View.of] via + /// [FlutterView.platformDispatcher]. Using [View.of] with a [BuildContext] is + /// the preferred option to migrate away from this deprecated [window] + /// property. + /// + /// If no context is available to look up a [FlutterView], the + /// [platformDispatcher] exposed by this binding can be used directly for + /// platform-specific functionality. It also maintains a list of all available + /// [FlutterView]s in [PlatformDispatcher.views] to access view-specific + /// functionality without a context. + /// + /// See also: + /// + /// * [View.of] to access view-specific functionality on the [FlutterView] + /// associated with the provided [BuildContext]. + /// * [FlutterView.platformDispatcher] to access platform-specific + /// functionality from a given [FlutterView]. + /// * [platformDispatcher] on this binding to access the [PlatformDispatcher], + /// which provides platform-specific functionality. + @Deprecated( + 'Look up the current FlutterView from the context via View.of(context) or consult the PlatformDispatcher directly instead. ' + 'Deprecated to prepare for the upcoming multi-window support. ' + 'This feature was deprecated after v3.7.0-32.0.pre.' + ) + ui.SingletonFlutterWindow get window => ui.window; + + /// The [ui.PlatformDispatcher] to which this binding is bound. + /// + /// A number of additional bindings are defined as extensions of + /// [BindingBase], e.g., [ServicesBinding], [RendererBinding], and + /// [WidgetsBinding]. Each of these bindings define behaviors that interact + /// with a [ui.PlatformDispatcher], e.g., [ServicesBinding] registers + /// listeners with the [ChannelBuffers], [RendererBinding] + /// registers [ui.PlatformDispatcher.onMetricsChanged], + /// [ui.PlatformDispatcher.onTextScaleFactorChanged], and [SemanticsBinding] + /// registers [ui.PlatformDispatcher.onSemanticsEnabledChanged], + /// [ui.PlatformDispatcher.onSemanticsActionEvent], and + /// [ui.PlatformDispatcher.onAccessibilityFeaturesChanged] handlers. + /// + /// Each of these other bindings could individually access a + /// [ui.PlatformDispatcher] statically, but that would preclude the ability to + /// test these behaviors with a fake platform dispatcher for verification + /// purposes. Therefore, [BindingBase] exposes this [ui.PlatformDispatcher] + /// for use by other bindings. A subclass of [BindingBase], such as + /// [TestWidgetsFlutterBinding], can override this accessor to return a + /// different [ui.PlatformDispatcher] implementation. + ui.PlatformDispatcher get platformDispatcher => ui.PlatformDispatcher.instance; + + /// The initialization method. Subclasses override this method to hook into + /// the platform and otherwise configure their services. Subclasses must call + /// "super.initInstances()". + /// + /// The binding is not fully initialized when this method runs (for + /// example, other binding mixins may not yet have run their + /// [initInstances] method). For this reason, code in this method + /// should avoid invoking callbacks or synchronously triggering any + /// code that would normally assume that the bindings are ready. + /// + /// {@tool snippet} + /// + /// By convention, if the service is to be provided as a singleton, + /// it should be exposed as `MixinClassName.instance`, a static + /// getter with a non-nullable return type that returns + /// `MixinClassName._instance`, a static field that is set by + /// `initInstances()`. To improve the developer experience, the + /// return value should actually be + /// `BindingBase.checkInstance(_instance)` (see [checkInstance]), as + /// in the example below. + /// + /// ```dart + /// mixin BazBinding on BindingBase { + /// @override + /// void initInstances() { + /// super.initInstances(); + /// _instance = this; + /// // ...binding initialization... + /// } + /// + /// static BazBinding get instance => BindingBase.checkInstance(_instance); + /// static BazBinding? _instance; + /// + /// // ...binding features... + /// } + /// ``` + /// {@end-tool} + @protected + @mustCallSuper + void initInstances() { + assert(_debugInitializedType == null); + assert(() { + _debugInitializedType = runtimeType; + _debugBindingZone = Zone.current; + return true; + }()); + } + + /// A method that shows a useful error message if the given binding + /// instance is not initialized. + /// + /// See [initInstances] for advice on using this method. + /// + /// This method either returns the argument or throws an exception. + /// In release mode it always returns the argument. + /// + /// The type argument `T` should be the kind of binding mixin (e.g. + /// `SchedulerBinding`) that is calling the method. It is used in + /// error messages. + @protected + static T checkInstance(T? instance) { + assert(() { + if (_debugInitializedType == null && instance == null) { + throw FlutterError.fromParts([ + ErrorSummary('Binding has not yet been initialized.'), + ErrorDescription('The "instance" getter on the $T binding mixin is only available once that binding has been initialized.'), + ErrorHint( + 'Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the ' + 'latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method ' + 'is idempotent; calling it multiple times is not harmful. After calling that method, the "instance" getter will ' + 'return the binding.', + ), + ErrorHint( + 'In a test, one can call "TestWidgetsFlutterBinding.ensureInitialized()" as the first line in the test\'s "main()" method ' + 'to initialize the binding.', + ), + ErrorHint( + 'If $T is a custom binding mixin, there must also be a custom binding class, like WidgetsFlutterBinding, ' + 'but that mixes in the selected binding, and that is the class that must be constructed before using the "instance" getter.', + ), + ]); + } + if (instance == null) { + assert(_debugInitializedType == null); + throw FlutterError.fromParts([ + ErrorSummary('Binding mixin instance is null but bindings are already initialized.'), + ErrorDescription( + 'The "instance" property of the $T binding mixin was accessed, but that binding was not initialized when ' + 'the "initInstances()" method was called.', + ), + ErrorHint( + 'This probably indicates that the $T mixin was not mixed into the class that was used to initialize the binding. ' + 'If this is a custom binding mixin, there must also be a custom binding class, like WidgetsFlutterBinding, ' + 'but that mixes in the selected binding. If this is a test binding, check that the binding being initialized ' + 'is the same as the one into which the test binding is mixed.', + ), + ErrorHint( + 'It is also possible that $T does not implement "initInstances()" to assign a value to "instance". See the ' + 'documentation of the BindingBase class for more details.', + ), + ErrorHint( + 'The binding that was initialized was of the type "$_debugInitializedType". ' + ), + ]); + } + try { + if (instance._debugConstructed && _debugInitializedType == null) { + throw FlutterError.fromParts([ + ErrorSummary('Binding initialized without calling initInstances.'), + ErrorDescription('An instance of $T is non-null, but BindingBase.initInstances() has not yet been called.'), + ErrorHint( + 'This could happen because a binding mixin was somehow used outside of the normal binding mechanisms, or because ' + 'the binding\'s initInstances() method did not call "super.initInstances()".', + ), + ErrorHint( + 'This could also happen if some code was invoked that used the binding while the binding was initializing, ' + 'for example if the "initInstances" method invokes a callback. Bindings should not invoke callbacks before ' + '"initInstances" has completed.', + ), + ]); + } + if (!instance._debugConstructed) { + // The state of _debugInitializedType doesn't matter in this failure mode. + throw FlutterError.fromParts([ + ErrorSummary('Binding did not complete initialization.'), + ErrorDescription('An instance of $T is non-null, but the BindingBase() constructor has not yet been called.'), + ErrorHint( + 'This could also happen if some code was invoked that used the binding while the binding was initializing, ' + "for example if the binding's constructor itself invokes a callback. Bindings should not invoke callbacks " + 'before "initInstances" has completed.', + ), + ]); + } + } on NoSuchMethodError { + throw FlutterError.fromParts([ + ErrorSummary('Binding does not extend BindingBase'), + ErrorDescription('An instance of $T was created but the BindingBase constructor was not called.'), + ErrorHint( + 'This could happen because the binding was implemented using "implements" rather than "extends" or "with". ' + 'Concrete binding classes must extend or mix in BindingBase.', + ), + ]); + } + return true; + }()); + return instance!; + } + + /// In debug builds, the type of the current binding, if any, or else null. + /// + /// This may be useful in asserts to verify that the binding has not been initialized + /// before the point in the application code that wants to initialize the binding, or + /// to verify that the binding is the one that is expected. + /// + /// For example, if an application uses [Zone]s to report uncaught exceptions, it may + /// need to ensure that `ensureInitialized()` has not yet been invoked on any binding + /// at the point where it configures the zone and initializes the binding. + /// + /// If this returns null, the binding has not been initialized. + /// + /// If this returns a non-null value, it returns the type of the binding instance. + /// + /// To obtain the binding itself, consider the `instance` getter on the [BindingBase] + /// subclass or mixin. + /// + /// This method only returns a useful value in debug builds. In release builds, the + /// return value is always null; to improve startup performance, the type of the + /// binding is not tracked in release builds. + /// + /// See also: + /// + /// * [BindingBase], whose class documentation describes the conventions for dealing + /// with bindings. + /// * [initInstances], whose documentation details how to create a binding mixin. + static Type? debugBindingType() { + return _debugInitializedType; + } + + Zone? _debugBindingZone; + + /// Whether [debugCheckZone] should throw (true) or just report the error (false). + /// + /// Setting this to true makes it easier to catch cases where the zones are + /// misconfigured, by allowing debuggers to stop at the point of error. + /// + /// Currently this defaults to false, to avoid suddenly breaking applications + /// that are affected by this check but appear to be working today. Applications + /// are encouraged to resolve any issues that cause the [debugCheckZone] message + /// to appear, as even if they appear to be working today, they are likely to be + /// hiding hard-to-find bugs, and are more brittle (likely to collect bugs in + /// the future). + /// + /// To silence the message displayed by [debugCheckZone], ensure that the same + /// zone is used when calling `ensureInitialized()` as when calling the framework + /// in any other context (e.g. via [runApp]). + static bool debugZoneErrorsAreFatal = false; + + /// Checks that the current [Zone] is the same as that which was used + /// to initialize the binding. + /// + /// If the current zone ([Zone.current]) is not the zone that was active when + /// the binding was initialized, then this method generates a [FlutterError] + /// exception with detailed information. The exception is either thrown + /// directly, or reported via [FlutterError.reportError], depending on the + /// value of [BindingBase.debugZoneErrorsAreFatal]. + /// + /// To silence the message displayed by [debugCheckZone], ensure that the same + /// zone is used when calling `ensureInitialized()` as when calling the + /// framework in any other context (e.g. via [runApp]). For example, consider + /// keeping a reference to the zone used to initialize the binding, and using + /// [Zone.run] to use it again when calling into the framework. + /// + /// ## Usage + /// + /// The binding is considered initialized once [BindingBase.initInstances] has + /// run; if this is called before then, it will throw an [AssertionError]. + /// + /// The `entryPoint` parameter is the name of the API that is checking the + /// zones are consistent, for example, `'runApp'`. + /// + /// This function always returns true (if it does not throw). It is expected + /// to be invoked via the binding instance, e.g.: + /// + /// ```dart + /// void startup() { + /// WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized(); + /// assert(binding.debugCheckZone('startup')); + /// // ... + /// } + /// ``` + /// + /// If the binding expects to be used with multiple zones, it should override + /// this method to return true always without throwing. (For example, the + /// bindings used with [flutter_test] do this as they make heavy use of zones + /// to drive the framework with an artificial clock and to catch errors and + /// report them as test failures.) + bool debugCheckZone(String entryPoint) { + assert(() { + assert(_debugBindingZone != null, 'debugCheckZone can only be used after the binding is fully initialized.'); + if (Zone.current != _debugBindingZone) { + final Error message = FlutterError( + 'Zone mismatch.\n' + 'The Flutter bindings were initialized in a different zone than is now being used. ' + 'This will likely cause confusion and bugs as any zone-specific configuration will ' + 'inconsistently use the configuration of the original binding initialization zone ' + 'or this zone based on hard-to-predict factors such as which zone was active when ' + 'a particular callback was set.\n' + 'It is important to use the same zone when calling `ensureInitialized` on the binding ' + 'as when calling `$entryPoint` later.\n' + 'To make this ${ debugZoneErrorsAreFatal ? 'error non-fatal' : 'warning fatal' }, ' + 'set BindingBase.debugZoneErrorsAreFatal to ${!debugZoneErrorsAreFatal} before the ' + 'bindings are initialized (i.e. as the first statement in `void main() { }`).', + ); + if (debugZoneErrorsAreFatal) { + throw message; + } + FlutterError.reportError(FlutterErrorDetails( + exception: message, + stack: StackTrace.current, + context: ErrorDescription('during $entryPoint'), + )); + } + return true; + }()); + return true; + } + + /// Called when the binding is initialized, to register service + /// extensions. + /// + /// Bindings that want to expose service extensions should overload + /// this method to register them using calls to + /// [registerSignalServiceExtension], + /// [registerBoolServiceExtension], + /// [registerNumericServiceExtension], and + /// [registerServiceExtension] (in increasing order of complexity). + /// + /// Implementations of this method must call their superclass + /// implementation. + /// + /// {@macro flutter.foundation.BindingBase.registerServiceExtension} + /// + /// See also: + /// + /// * + @protected + @mustCallSuper + void initServiceExtensions() { + assert(!_debugServiceExtensionsRegistered); + + assert(() { + registerSignalServiceExtension( + name: FoundationServiceExtensions.reassemble.name, + callback: reassembleApplication, + ); + return true; + }()); + + if (!kReleaseMode) { + if (!kIsWeb) { + registerSignalServiceExtension( + name: FoundationServiceExtensions.exit.name, + callback: _exitApplication, + ); + } + // These service extensions are used in profile mode applications. + registerStringServiceExtension( + name: FoundationServiceExtensions.connectedVmServiceUri.name, + getter: () async => connectedVmServiceUri ?? '', + setter: (String uri) async { + connectedVmServiceUri = uri; + }, + ); + registerStringServiceExtension( + name: FoundationServiceExtensions.activeDevToolsServerAddress.name, + getter: () async => activeDevToolsServerAddress ?? '', + setter: (String serverAddress) async { + activeDevToolsServerAddress = serverAddress; + }, + ); + } + + assert(() { + registerServiceExtension( + name: FoundationServiceExtensions.platformOverride.name, + callback: (Map parameters) async { + if (parameters.containsKey('value')) { + final String value = parameters['value']!; + debugDefaultTargetPlatformOverride = null; + for (final TargetPlatform candidate in TargetPlatform.values) { + if (candidate.name == value) { + debugDefaultTargetPlatformOverride = candidate; + break; + } + } + _postExtensionStateChangedEvent( + FoundationServiceExtensions.platformOverride.name, + defaultTargetPlatform.name, + ); + await reassembleApplication(); + } + return { + 'value': defaultTargetPlatform.name, + }; + }, + ); + + registerServiceExtension( + name: FoundationServiceExtensions.brightnessOverride.name, + callback: (Map parameters) async { + if (parameters.containsKey('value')) { + switch (parameters['value']) { + case 'Brightness.light': + debugBrightnessOverride = ui.Brightness.light; + case 'Brightness.dark': + debugBrightnessOverride = ui.Brightness.dark; + default: + debugBrightnessOverride = null; + } + _postExtensionStateChangedEvent( + FoundationServiceExtensions.brightnessOverride.name, + (debugBrightnessOverride ?? platformDispatcher.platformBrightness).toString(), + ); + await reassembleApplication(); + } + return { + 'value': (debugBrightnessOverride ?? platformDispatcher.platformBrightness).toString(), + }; + }, + ); + return true; + }()); + assert(() { + _debugServiceExtensionsRegistered = true; + return true; + }()); + } + + /// Whether [lockEvents] is currently locking events. + /// + /// Binding subclasses that fire events should check this first, and if it is + /// set, queue events instead of firing them. + /// + /// Events should be flushed when [unlocked] is called. + @protected + bool get locked => _lockCount > 0; + int _lockCount = 0; + + /// Locks the dispatching of asynchronous events and callbacks until the + /// callback's future completes. + /// + /// This causes input lag and should therefore be avoided when possible. It is + /// primarily intended for use during non-user-interactive time such as to + /// allow [reassembleApplication] to block input while it walks the tree + /// (which it partially does asynchronously). + /// + /// The [Future] returned by the `callback` argument is returned by [lockEvents]. + /// + /// The [gestures] binding wraps [PlatformDispatcher.onPointerDataPacket] in + /// logic that honors this event locking mechanism. Similarly, tasks queued + /// using [SchedulerBinding.scheduleTask] will only start when events are not + /// [locked]. + @protected + Future lockEvents(Future Function() callback) { + developer.TimelineTask? debugTimelineTask; + if (!kReleaseMode) { + debugTimelineTask = developer.TimelineTask()..start('Lock events'); + } + + _lockCount += 1; + final Future future = callback(); + future.whenComplete(() { + _lockCount -= 1; + if (!locked) { + if (!kReleaseMode) { + debugTimelineTask!.finish(); + } + try { + unlocked(); + } catch (error, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: error, + stack: stack, + library: 'foundation', + context: ErrorDescription('while handling pending events'), + )); + } + } + }); + return future; + } + + /// Called by [lockEvents] when events get unlocked. + /// + /// This should flush any events that were queued while [locked] was true. + @protected + @mustCallSuper + void unlocked() { + assert(!locked); + } + + /// Cause the entire application to redraw, e.g. after a hot reload. + /// + /// This is used by development tools when the application code has changed, + /// to cause the application to pick up any changed code. It can be triggered + /// manually by sending the `ext.flutter.reassemble` service extension signal. + /// + /// This method is very computationally expensive and should not be used in + /// production code. There is never a valid reason to cause the entire + /// application to repaint in production. All aspects of the Flutter framework + /// know how to redraw when necessary. It is only necessary in development + /// when the code is literally changed on the fly (e.g. in hot reload) or when + /// debug flags are being toggled. + /// + /// While this method runs, events are locked (e.g. pointer events are not + /// dispatched). + /// + /// Subclasses (binding classes) should override [performReassemble] to react + /// to this method being called. This method itself should not be overridden. + Future reassembleApplication() { + return lockEvents(performReassemble); + } + + /// This method is called by [reassembleApplication] to actually cause the + /// application to reassemble, e.g. after a hot reload. + /// + /// Bindings are expected to use this method to re-register anything that uses + /// closures, so that they do not keep pointing to old code, and to flush any + /// caches of previously computed values, in case the new code would compute + /// them differently. For example, the rendering layer triggers the entire + /// application to repaint when this is called. + /// + /// Do not call this method directly. Instead, use [reassembleApplication]. + @mustCallSuper + @protected + Future performReassemble() { + FlutterError.resetErrorCount(); + return Future.value(); + } + + /// Registers a service extension method with the given name (full + /// name "ext.flutter.name"), which takes no arguments and returns + /// no value. + /// + /// Calls the `callback` callback when the service extension is called. + /// + /// {@macro flutter.foundation.BindingBase.registerServiceExtension} + @protected + void registerSignalServiceExtension({ + required String name, + required AsyncCallback callback, + }) { + registerServiceExtension( + name: name, + callback: (Map parameters) async { + await callback(); + return {}; + }, + ); + } + + /// Registers a service extension method with the given name (full + /// name "ext.flutter.name"), which takes a single argument + /// "enabled" which can have the value "true" or the value "false" + /// or can be omitted to read the current value. (Any value other + /// than "true" is considered equivalent to "false". Other arguments + /// are ignored.) + /// + /// Calls the `getter` callback to obtain the value when + /// responding to the service extension method being called. + /// + /// Calls the `setter` callback with the new value when the + /// service extension method is called with a new value. + /// + /// {@macro flutter.foundation.BindingBase.registerServiceExtension} + @protected + void registerBoolServiceExtension({ + required String name, + required AsyncValueGetter getter, + required AsyncValueSetter setter, + }) { + registerServiceExtension( + name: name, + callback: (Map parameters) async { + if (parameters.containsKey('enabled')) { + await setter(parameters['enabled'] == 'true'); + _postExtensionStateChangedEvent(name, await getter() ? 'true' : 'false'); + } + return {'enabled': await getter() ? 'true' : 'false'}; + }, + ); + } + + /// Registers a service extension method with the given name (full + /// name "ext.flutter.name"), which takes a single argument with the + /// same name as the method which, if present, must have a value + /// that can be parsed by [double.parse], and can be omitted to read + /// the current value. (Other arguments are ignored.) + /// + /// Calls the `getter` callback to obtain the value when + /// responding to the service extension method being called. + /// + /// Calls the `setter` callback with the new value when the + /// service extension method is called with a new value. + /// + /// {@macro flutter.foundation.BindingBase.registerServiceExtension} + @protected + void registerNumericServiceExtension({ + required String name, + required AsyncValueGetter getter, + required AsyncValueSetter setter, + }) { + registerServiceExtension( + name: name, + callback: (Map parameters) async { + if (parameters.containsKey(name)) { + await setter(double.parse(parameters[name]!)); + _postExtensionStateChangedEvent(name, (await getter()).toString()); + } + return {name: (await getter()).toString()}; + }, + ); + } + + /// Sends an event when a service extension's state is changed. + /// + /// Clients should listen for this event to stay aware of the current service + /// extension state. Any service extension that manages a state should call + /// this method on state change. + /// + /// `value` reflects the newly updated service extension value. + /// + /// This will be called automatically for service extensions registered via + /// [registerBoolServiceExtension], [registerNumericServiceExtension], or + /// [registerStringServiceExtension]. + void _postExtensionStateChangedEvent(String name, dynamic value) { + postEvent( + 'Flutter.ServiceExtensionStateChanged', + { + 'extension': 'ext.flutter.$name', + 'value': value, + }, + ); + } + + /// All events dispatched by a [BindingBase] use this method instead of + /// calling [developer.postEvent] directly so that tests for [BindingBase] + /// can track which events were dispatched by overriding this method. + /// + /// This is unrelated to the events managed by [lockEvents]. + @protected + void postEvent(String eventKind, Map eventData) { + developer.postEvent(eventKind, eventData); + } + + /// Registers a service extension method with the given name (full name + /// "ext.flutter.name"), which optionally takes a single argument with the + /// name "value". If the argument is omitted, the value is to be read, + /// otherwise it is to be set. Returns the current value. + /// + /// Calls the `getter` callback to obtain the value when + /// responding to the service extension method being called. + /// + /// Calls the `setter` callback with the new value when the + /// service extension method is called with a new value. + /// + /// {@macro flutter.foundation.BindingBase.registerServiceExtension} + @protected + void registerStringServiceExtension({ + required String name, + required AsyncValueGetter getter, + required AsyncValueSetter setter, + }) { + registerServiceExtension( + name: name, + callback: (Map parameters) async { + if (parameters.containsKey('value')) { + await setter(parameters['value']!); + _postExtensionStateChangedEvent(name, await getter()); + } + return {'value': await getter()}; + }, + ); + } + + /// Registers a service extension method with the given name (full name + /// "ext.flutter.name"). + /// + /// The given callback is called when the extension method is called. The + /// callback must return a [Future] that either eventually completes to a + /// return value in the form of a name/value map where the values can all be + /// converted to JSON using `json.encode()` (see [JsonEncoder]), or fails. In + /// case of failure, the failure is reported to the remote caller and is + /// dumped to the logs. + /// + /// The returned map will be mutated. + /// + /// {@template flutter.foundation.BindingBase.registerServiceExtension} + /// A registered service extension can only be activated if the vm-service + /// is included in the build, which only happens in debug and profile mode. + /// Although a service extension cannot be used in release mode its code may + /// still be included in the Dart snapshot and blow up binary size if it is + /// not wrapped in a guard that allows the tree shaker to remove it (see + /// sample code below). + /// + /// {@tool snippet} + /// The following code registers a service extension that is only included in + /// debug builds. + /// + /// ```dart + /// void myRegistrationFunction() { + /// assert(() { + /// // Register your service extension here. + /// return true; + /// }()); + /// } + /// ``` + /// {@end-tool} + /// + /// {@tool snippet} + /// A service extension registered with the following code snippet is + /// available in debug and profile mode. + /// + /// ```dart + /// void myOtherRegistrationFunction() { + /// // kReleaseMode is defined in the 'flutter/foundation.dart' package. + /// if (!kReleaseMode) { + /// // Register your service extension here. + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// Both guards ensure that Dart's tree shaker can remove the code for the + /// service extension in release builds. + /// {@endtemplate} + @protected + void registerServiceExtension({ + required String name, + required ServiceExtensionCallback callback, + }) { + final String methodName = 'ext.flutter.$name'; + developer.registerExtension(methodName, (String method, Map parameters) async { + assert(method == methodName); + assert(() { + if (debugInstrumentationEnabled) { + debugPrint('service extension method received: $method($parameters)'); + } + return true; + }()); + + // VM service extensions are handled as "out of band" messages by the VM, + // which means they are handled at various times, generally ASAP. + // Notably, this includes being handled in the middle of microtask loops. + // While this makes sense for some service extensions (e.g. "dump current + // stack trace", which explicitly doesn't want to wait for a loop to + // complete), Flutter extensions need not be handled with such high + // priority. Further, handling them with such high priority exposes us to + // the possibility that they're handled in the middle of a frame, which + // breaks many assertions. As such, we ensure they we run the callbacks + // on the outer event loop here. + await debugInstrumentAction('Wait for outer event loop', () { + return Future.delayed(Duration.zero); + }); + + late Map result; + try { + result = await callback(parameters); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + context: ErrorDescription('during a service extension callback for "$method"'), + )); + return developer.ServiceExtensionResponse.error( + developer.ServiceExtensionResponse.extensionError, + json.encode({ + 'exception': exception.toString(), + 'stack': stack.toString(), + 'method': method, + }), + ); + } + result['type'] = '_extensionType'; + result['method'] = method; + return developer.ServiceExtensionResponse.result(json.encode(result)); + }); + } + + @override + String toString() => '<${objectRuntimeType(this, 'BindingBase')}>'; +} + +/// Terminate the Flutter application. +Future _exitApplication() async { + exit(0); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/bitfield.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/bitfield.dart new file mode 100644 index 0000000000000000000000000000000000000000..0110324442be054a524303d5ca9b7a61543068f6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/bitfield.dart @@ -0,0 +1,48 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '_bitfield_io.dart' + if (dart.library.js_util) '_bitfield_web.dart' as bitfield; + +/// The largest SMI value. +/// +/// See +/// +/// When compiling to JavaScript, this value is not supported since it is +/// larger than the maximum safe 32bit integer. +const int kMaxUnsignedSMI = bitfield.kMaxUnsignedSMI; + +/// A BitField over an enum (or other class whose values implement "index"). +/// Only the first 62 values of the enum can be used as indices. +/// +/// When compiling to JavaScript, this class is not supported. +abstract class BitField { + /// Creates a bit field of all zeros. + /// + /// The given length must be at most 62. + factory BitField(int length) = bitfield.BitField; + + /// Creates a bit field filled with a particular value. + /// + /// If the value argument is true, the bits are filled with ones. Otherwise, + /// the bits are filled with zeros. + /// + /// The given length must be at most 62. + factory BitField.filled(int length, bool value) = bitfield.BitField.filled; + + /// Returns whether the bit with the given index is set to one. + bool operator [](T index); + + /// Sets the bit with the given index to the given value. + /// + /// If value is true, the bit with the given index is set to one. Otherwise, + /// the bit is set to zero. + void operator []=(T index, bool value); + + /// Sets all the bits to the given value. + /// + /// If the value is true, the bits are all set to one. Otherwise, the bits are + /// all set to zero. Defaults to setting all the bits to zero. + void reset([ bool value = false ]); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/capabilities.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/capabilities.dart new file mode 100644 index 0000000000000000000000000000000000000000..d2d6d81b70c7ad3a3544d163c82aff4f588f6e04 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/capabilities.dart @@ -0,0 +1,11 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '_capabilities_io.dart' + if (dart.library.js_util) '_capabilities_web.dart' as capabilities; + +/// Returns true if the application is using CanvasKit. +/// +/// Only to be used for web. +bool get isCanvasKit => capabilities.isCanvasKit; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/change_notifier.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/change_notifier.dart new file mode 100644 index 0000000000000000000000000000000000000000..27ef987ef76b768dd65d2d6a66b27aa367ae7ec2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/change_notifier.dart @@ -0,0 +1,560 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show VoidCallback; + +import 'package:meta/meta.dart'; + +import 'assertions.dart'; +import 'diagnostics.dart'; +import 'memory_allocations.dart'; + +export 'dart:ui' show VoidCallback; + +/// An object that maintains a list of listeners. +/// +/// The listeners are typically used to notify clients that the object has been +/// updated. +/// +/// There are two variants of this interface: +/// +/// * [ValueListenable], an interface that augments the [Listenable] interface +/// with the concept of a _current value_. +/// +/// * [Animation], an interface that augments the [ValueListenable] interface +/// to add the concept of direction (forward or reverse). +/// +/// Many classes in the Flutter API use or implement these interfaces. The +/// following subclasses are especially relevant: +/// +/// * [ChangeNotifier], which can be subclassed or mixed in to create objects +/// that implement the [Listenable] interface. +/// +/// * [ValueNotifier], which implements the [ValueListenable] interface with +/// a mutable value that triggers the notifications when modified. +/// +/// The terms "notify clients", "send notifications", "trigger notifications", +/// and "fire notifications" are used interchangeably. +/// +/// See also: +/// +/// * [AnimatedBuilder], a widget that uses a builder callback to rebuild +/// whenever a given [Listenable] triggers its notifications. This widget is +/// commonly used with [Animation] subclasses, hence its name, but is by no +/// means limited to animations, as it can be used with any [Listenable]. It +/// is a subclass of [AnimatedWidget], which can be used to create widgets +/// that are driven from a [Listenable]. +/// * [ValueListenableBuilder], a widget that uses a builder callback to +/// rebuild whenever a [ValueListenable] object triggers its notifications, +/// providing the builder with the value of the object. +/// * [InheritedNotifier], an abstract superclass for widgets that use a +/// [Listenable]'s notifications to trigger rebuilds in descendant widgets +/// that declare a dependency on them, using the [InheritedWidget] mechanism. +/// * [Listenable.merge], which creates a [Listenable] that triggers +/// notifications whenever any of a list of other [Listenable]s trigger their +/// notifications. +abstract class Listenable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const Listenable(); + + /// Return a [Listenable] that triggers when any of the given [Listenable]s + /// themselves trigger. + /// + /// The list must not be changed after this method has been called. Doing so + /// will lead to memory leaks or exceptions. + /// + /// The list may contain nulls; they are ignored. + factory Listenable.merge(List listenables) = _MergingListenable; + + /// Register a closure to be called when the object notifies its listeners. + void addListener(VoidCallback listener); + + /// Remove a previously registered closure from the list of closures that the + /// object notifies. + void removeListener(VoidCallback listener); +} + +/// An interface for subclasses of [Listenable] that expose a [value]. +/// +/// This interface is implemented by [ValueNotifier] and [Animation], and +/// allows other APIs to accept either of those implementations interchangeably. +/// +/// See also: +/// +/// * [ValueListenableBuilder], a widget that uses a builder callback to +/// rebuild whenever a [ValueListenable] object triggers its notifications, +/// providing the builder with the value of the object. +abstract class ValueListenable extends Listenable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const ValueListenable(); + + /// The current value of the object. When the value changes, the callbacks + /// registered with [addListener] will be invoked. + T get value; +} + +const String _flutterFoundationLibrary = 'package:flutter/foundation.dart'; + +/// A class that can be extended or mixed in that provides a change notification +/// API using [VoidCallback] for notifications. +/// +/// It is O(1) for adding listeners and O(N) for removing listeners and dispatching +/// notifications (where N is the number of listeners). +/// +/// ## Using ChangeNotifier subclasses for data models +/// +/// A data structure can extend or mix in [ChangeNotifier] to implement the +/// [Listenable] interface and thus become usable with widgets that listen for +/// changes to [Listenable]s, such as [ListenableBuilder]. +/// +/// {@tool dartpad} +/// The following example implements a simple counter that utilizes a +/// [ListenableBuilder] to limit rebuilds to only the [Text] widget containing +/// the count. The current count is stored in a [ChangeNotifier] subclass, which +/// rebuilds the [ListenableBuilder]'s contents when its value is changed. +/// +/// ** See code in examples/api/lib/widgets/transitions/listenable_builder.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// In this case, the [ChangeNotifier] subclass encapsulates a list, and notifies +/// the clients any time an item is added to the list. This example only supports +/// adding items; as an exercise, consider adding buttons to remove items from +/// the list as well. +/// +/// ** See code in examples/api/lib/widgets/transitions/listenable_builder.3.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ValueNotifier], which is a [ChangeNotifier] that wraps a single value. +mixin class ChangeNotifier implements Listenable { + int _count = 0; + // The _listeners is intentionally set to a fixed-length _GrowableList instead + // of const []. + // + // The const [] creates an instance of _ImmutableList which would be + // different from fixed-length _GrowableList used elsewhere in this class. + // keeping runtime type the same during the lifetime of this class lets the + // compiler to infer concrete type for this property, and thus improves + // performance. + static final List _emptyListeners = List.filled(0, null); + List _listeners = _emptyListeners; + int _notificationCallStackDepth = 0; + int _reentrantlyRemovedListeners = 0; + bool _debugDisposed = false; + + /// If true, the event [ObjectCreated] for this instance was dispatched to + /// [FlutterMemoryAllocations]. + /// + /// As [ChangedNotifier] is used as mixin, it does not have constructor, + /// so we use [addListener] to dispatch the event. + bool _creationDispatched = false; + + /// Used by subclasses to assert that the [ChangeNotifier] has not yet been + /// disposed. + /// + /// {@tool snippet} + /// The [debugAssertNotDisposed] function should only be called inside of an + /// assert, as in this example. + /// + /// ```dart + /// class MyNotifier with ChangeNotifier { + /// void doUpdate() { + /// assert(ChangeNotifier.debugAssertNotDisposed(this)); + /// // ... + /// } + /// } + /// ``` + /// {@end-tool} + // This is static and not an instance method because too many people try to + // implement ChangeNotifier instead of extending it (and so it is too breaking + // to add a method, especially for debug). + static bool debugAssertNotDisposed(ChangeNotifier notifier) { + assert(() { + if (notifier._debugDisposed) { + throw FlutterError( + 'A ${notifier.runtimeType} was used after being disposed.\n' + 'Once you have called dispose() on a ${notifier.runtimeType}, it ' + 'can no longer be used.', + ); + } + return true; + }()); + return true; + } + + /// Whether any listeners are currently registered. + /// + /// Clients should not depend on this value for their behavior, because having + /// one listener's logic change when another listener happens to start or stop + /// listening will lead to extremely hard-to-track bugs. Subclasses might use + /// this information to determine whether to do any work when there are no + /// listeners, however; for example, resuming a [Stream] when a listener is + /// added and pausing it when a listener is removed. + /// + /// Typically this is used by overriding [addListener], checking if + /// [hasListeners] is false before calling `super.addListener()`, and if so, + /// starting whatever work is needed to determine when to call + /// [notifyListeners]; and similarly, by overriding [removeListener], checking + /// if [hasListeners] is false after calling `super.removeListener()`, and if + /// so, stopping that same work. + /// + /// This method returns false if [dispose] has been called. + @protected + bool get hasListeners => _count > 0; + + /// Dispatches event of the [object] creation to [FlutterMemoryAllocations.instance]. + /// + /// If the event was already dispatched or [kFlutterMemoryAllocationsEnabled] + /// is false, the method is noop. + /// + /// Tools like leak_tracker use the event of object creation to help + /// developers identify the owner of the object, for troubleshooting purposes, + /// by taking stack trace at the moment of the event. + /// + /// But, as [ChangeNotifier] is mixin, it does not have its own constructor. So, it + /// communicates object creation in first `addListener`, that results + /// in the stack trace pointing to `addListener`, not to constructor. + /// + /// To make debugging easier, invoke [ChangeNotifier.maybeDispatchObjectCreation] + /// in constructor of the class. It will help + /// to identify the owner. + /// + /// Make sure to invoke it with condition `if (kFlutterMemoryAllocationsEnabled) ...` + /// so that the method is tree-shaken away when the flag is false. + @protected + static void maybeDispatchObjectCreation(ChangeNotifier object) { + // Tree shaker does not include this method and the class MemoryAllocations + // if kFlutterMemoryAllocationsEnabled is false. + if (kFlutterMemoryAllocationsEnabled && !object._creationDispatched) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: _flutterFoundationLibrary, + className: '$ChangeNotifier', + object: object, + ); + object._creationDispatched = true; + } + } + + /// Register a closure to be called when the object changes. + /// + /// If the given closure is already registered, an additional instance is + /// added, and must be removed the same number of times it is added before it + /// will stop being called. + /// + /// This method must not be called after [dispose] has been called. + /// + /// {@template flutter.foundation.ChangeNotifier.addListener} + /// If a listener is added twice, and is removed once during an iteration + /// (e.g. in response to a notification), it will still be called again. If, + /// on the other hand, it is removed as many times as it was registered, then + /// it will no longer be called. This odd behavior is the result of the + /// [ChangeNotifier] not being able to determine which listener is being + /// removed, since they are identical, therefore it will conservatively still + /// call all the listeners when it knows that any are still registered. + /// + /// This surprising behavior can be unexpectedly observed when registering a + /// listener on two separate objects which are both forwarding all + /// registrations to a common upstream object. + /// {@endtemplate} + /// + /// See also: + /// + /// * [removeListener], which removes a previously registered closure from + /// the list of closures that are notified when the object changes. + @override + void addListener(VoidCallback listener) { + assert(ChangeNotifier.debugAssertNotDisposed(this)); + + if (kFlutterMemoryAllocationsEnabled) { + maybeDispatchObjectCreation(this); + } + + if (_count == _listeners.length) { + if (_count == 0) { + _listeners = List.filled(1, null); + } else { + final List newListeners = + List.filled(_listeners.length * 2, null); + for (int i = 0; i < _count; i++) { + newListeners[i] = _listeners[i]; + } + _listeners = newListeners; + } + } + _listeners[_count++] = listener; + } + + void _removeAt(int index) { + // The list holding the listeners is not growable for performances reasons. + // We still want to shrink this list if a lot of listeners have been added + // and then removed outside a notifyListeners iteration. + // We do this only when the real number of listeners is half the length + // of our list. + _count -= 1; + if (_count * 2 <= _listeners.length) { + final List newListeners = List.filled(_count, null); + + // Listeners before the index are at the same place. + for (int i = 0; i < index; i++) { + newListeners[i] = _listeners[i]; + } + + // Listeners after the index move towards the start of the list. + for (int i = index; i < _count; i++) { + newListeners[i] = _listeners[i + 1]; + } + + _listeners = newListeners; + } else { + // When there are more listeners than half the length of the list, we only + // shift our listeners, so that we avoid to reallocate memory for the + // whole list. + for (int i = index; i < _count; i++) { + _listeners[i] = _listeners[i + 1]; + } + _listeners[_count] = null; + } + } + + /// Remove a previously registered closure from the list of closures that are + /// notified when the object changes. + /// + /// If the given listener is not registered, the call is ignored. + /// + /// This method returns immediately if [dispose] has been called. + /// + /// {@macro flutter.foundation.ChangeNotifier.addListener} + /// + /// See also: + /// + /// * [addListener], which registers a closure to be called when the object + /// changes. + @override + void removeListener(VoidCallback listener) { + // This method is allowed to be called on disposed instances for usability + // reasons. Due to how our frame scheduling logic between render objects and + // overlays, it is common that the owner of this instance would be disposed a + // frame earlier than the listeners. Allowing calls to this method after it + // is disposed makes it easier for listeners to properly clean up. + for (int i = 0; i < _count; i++) { + final VoidCallback? listenerAtIndex = _listeners[i]; + if (listenerAtIndex == listener) { + if (_notificationCallStackDepth > 0) { + // We don't resize the list during notifyListeners iterations + // but we set to null, the listeners we want to remove. We will + // effectively resize the list at the end of all notifyListeners + // iterations. + _listeners[i] = null; + _reentrantlyRemovedListeners++; + } else { + // When we are outside the notifyListeners iterations we can + // effectively shrink the list. + _removeAt(i); + } + break; + } + } + } + + /// Discards any resources used by the object. After this is called, the + /// object is not in a usable state and should be discarded (calls to + /// [addListener] will throw after the object is disposed). + /// + /// This method should only be called by the object's owner. + /// + /// This method does not notify listeners, and clears the listener list once + /// it is called. Consumers of this class must decide on whether to notify + /// listeners or not immediately before disposal. + @mustCallSuper + void dispose() { + assert(ChangeNotifier.debugAssertNotDisposed(this)); + assert( + _notificationCallStackDepth == 0, + 'The "dispose()" method on $this was called during the call to ' + '"notifyListeners()". This is likely to cause errors since it modifies ' + 'the list of listeners while the list is being used.', + ); + assert(() { + _debugDisposed = true; + return true; + }()); + if (kFlutterMemoryAllocationsEnabled && _creationDispatched) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _listeners = _emptyListeners; + _count = 0; + } + + /// Call all the registered listeners. + /// + /// Call this method whenever the object changes, to notify any clients the + /// object may have changed. Listeners that are added during this iteration + /// will not be visited. Listeners that are removed during this iteration will + /// not be visited after they are removed. + /// + /// Exceptions thrown by listeners will be caught and reported using + /// [FlutterError.reportError]. + /// + /// This method must not be called after [dispose] has been called. + /// + /// Surprising behavior can result when reentrantly removing a listener (e.g. + /// in response to a notification) that has been registered multiple times. + /// See the discussion at [removeListener]. + @protected + @visibleForTesting + @pragma('vm:notify-debugger-on-exception') + void notifyListeners() { + assert(ChangeNotifier.debugAssertNotDisposed(this)); + if (_count == 0) { + return; + } + + // To make sure that listeners removed during this iteration are not called, + // we set them to null, but we don't shrink the list right away. + // By doing this, we can continue to iterate on our list until it reaches + // the last listener added before the call to this method. + + // To allow potential listeners to recursively call notifyListener, we track + // the number of times this method is called in _notificationCallStackDepth. + // Once every recursive iteration is finished (i.e. when _notificationCallStackDepth == 0), + // we can safely shrink our list so that it will only contain not null + // listeners. + + _notificationCallStackDepth++; + + final int end = _count; + for (int i = 0; i < end; i++) { + try { + _listeners[i]?.call(); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'foundation library', + context: ErrorDescription('while dispatching notifications for $runtimeType'), + informationCollector: () => [ + DiagnosticsProperty( + 'The $runtimeType sending notification was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + ], + )); + } + } + + _notificationCallStackDepth--; + + if (_notificationCallStackDepth == 0 && _reentrantlyRemovedListeners > 0) { + // We really remove the listeners when all notifications are done. + final int newLength = _count - _reentrantlyRemovedListeners; + if (newLength * 2 <= _listeners.length) { + // As in _removeAt, we only shrink the list when the real number of + // listeners is half the length of our list. + final List newListeners = List.filled(newLength, null); + + int newIndex = 0; + for (int i = 0; i < _count; i++) { + final VoidCallback? listener = _listeners[i]; + if (listener != null) { + newListeners[newIndex++] = listener; + } + } + + _listeners = newListeners; + } else { + // Otherwise we put all the null references at the end. + for (int i = 0; i < newLength; i += 1) { + if (_listeners[i] == null) { + // We swap this item with the next not null item. + int swapIndex = i + 1; + while (_listeners[swapIndex] == null) { + swapIndex += 1; + } + _listeners[i] = _listeners[swapIndex]; + _listeners[swapIndex] = null; + } + } + } + + _reentrantlyRemovedListeners = 0; + _count = newLength; + } + } +} + +class _MergingListenable extends Listenable { + _MergingListenable(this._children); + + final List _children; + + @override + void addListener(VoidCallback listener) { + for (final Listenable? child in _children) { + child?.addListener(listener); + } + } + + @override + void removeListener(VoidCallback listener) { + for (final Listenable? child in _children) { + child?.removeListener(listener); + } + } + + @override + String toString() { + return 'Listenable.merge([${_children.join(", ")}])'; + } +} + +/// A [ChangeNotifier] that holds a single value. +/// +/// When [value] is replaced with something that is not equal to the old +/// value as evaluated by the equality operator ==, this class notifies its +/// listeners. +/// +/// ## Limitations +/// +/// Because this class only notifies listeners when the [value]'s _identity_ +/// changes, listeners will not be notified when mutable state within the +/// value itself changes. +/// +/// For example, a `ValueNotifier>` will not notify its listeners +/// when the _contents_ of the list are changed. +/// +/// As a result, this class is best used with only immutable data types. +/// +/// For mutable data types, consider extending [ChangeNotifier] directly. +class ValueNotifier extends ChangeNotifier implements ValueListenable { + /// Creates a [ChangeNotifier] that wraps this value. + ValueNotifier(this._value) { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + /// The current value stored in this notifier. + /// + /// When the value is replaced with something that is not equal to the old + /// value as evaluated by the equality operator ==, this class notifies its + /// listeners. + @override + T get value => _value; + T _value; + set value(T newValue) { + if (_value == newValue) { + return; + } + _value = newValue; + notifyListeners(); + } + + @override + String toString() => '${describeIdentity(this)}($value)'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/collections.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/collections.dart new file mode 100644 index 0000000000000000000000000000000000000000..e1e1499d856ba45bcbf87f748ec24a3937c8b9f8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/collections.dart @@ -0,0 +1,365 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// TODO(ianh): These should be on the Set and List classes themselves. + +/// Compares two sets for element-by-element equality. +/// +/// Returns true if the sets are both null, or if they are both non-null, have +/// the same length, and contain the same members. Returns false otherwise. +/// Order is not compared. +/// +/// If the elements are maps, lists, sets, or other collections/composite +/// objects, then the contents of those elements are not compared element by +/// element unless their equality operators ([Object.==]) do so. For checking +/// deep equality, consider using the [DeepCollectionEquality] class. +/// +/// See also: +/// +/// * [listEquals], which does something similar for lists. +/// * [mapEquals], which does something similar for maps. +bool setEquals(Set? a, Set? b) { + if (a == null) { + return b == null; + } + if (b == null || a.length != b.length) { + return false; + } + if (identical(a, b)) { + return true; + } + for (final T value in a) { + if (!b.contains(value)) { + return false; + } + } + return true; +} + +/// Compares two lists for element-by-element equality. +/// +/// Returns true if the lists are both null, or if they are both non-null, have +/// the same length, and contain the same members in the same order. Returns +/// false otherwise. +/// +/// If the elements are maps, lists, sets, or other collections/composite +/// objects, then the contents of those elements are not compared element by +/// element unless their equality operators ([Object.==]) do so. For checking +/// deep equality, consider using the [DeepCollectionEquality] class. +/// +/// See also: +/// +/// * [setEquals], which does something similar for sets. +/// * [mapEquals], which does something similar for maps. +bool listEquals(List? a, List? b) { + if (a == null) { + return b == null; + } + if (b == null || a.length != b.length) { + return false; + } + if (identical(a, b)) { + return true; + } + for (int index = 0; index < a.length; index += 1) { + if (a[index] != b[index]) { + return false; + } + } + return true; +} + +/// Compares two maps for element-by-element equality. +/// +/// Returns true if the maps are both null, or if they are both non-null, have +/// the same length, and contain the same keys associated with the same values. +/// Returns false otherwise. +/// +/// If the elements are maps, lists, sets, or other collections/composite +/// objects, then the contents of those elements are not compared element by +/// element unless their equality operators ([Object.==]) do so. For checking +/// deep equality, consider using the [DeepCollectionEquality] class. +/// +/// See also: +/// +/// * [setEquals], which does something similar for sets. +/// * [listEquals], which does something similar for lists. +bool mapEquals(Map? a, Map? b) { + if (a == null) { + return b == null; + } + if (b == null || a.length != b.length) { + return false; + } + if (identical(a, b)) { + return true; + } + for (final T key in a.keys) { + if (!b.containsKey(key) || b[key] != a[key]) { + return false; + } + } + return true; +} + +/// Returns the position of `value` in the `sortedList`, if it exists. +/// +/// Returns `-1` if the `value` is not in the list. Requires the list items +/// to implement [Comparable] and the `sortedList` to already be ordered. +int binarySearch>(List sortedList, T value) { + int min = 0; + int max = sortedList.length; + while (min < max) { + final int mid = min + ((max - min) >> 1); + final T element = sortedList[mid]; + final int comp = element.compareTo(value); + if (comp == 0) { + return mid; + } + if (comp < 0) { + min = mid + 1; + } else { + max = mid; + } + } + return -1; +} + +/// Limit below which merge sort defaults to insertion sort. +const int _kMergeSortLimit = 32; + +/// Sorts a list between `start` (inclusive) and `end` (exclusive) using the +/// merge sort algorithm. +/// +/// If `compare` is omitted, this defaults to calling [Comparable.compareTo] on +/// the objects. If any object is not [Comparable], this throws a [TypeError] +/// (The stack trace may call it `_CastError` or `_TypeError`, but to catch it, +/// use [TypeError]). +/// +/// Merge-sorting works by splitting the job into two parts, sorting each +/// recursively, and then merging the two sorted parts. +/// +/// This takes on the order of `n * log(n)` comparisons and moves to sort `n` +/// elements, but requires extra space of about the same size as the list being +/// sorted. +/// +/// This merge sort is stable: Equal elements end up in the same order as they +/// started in. +/// +/// For small lists (less than 32 elements), [mergeSort] automatically uses an +/// insertion sort instead, as that is more efficient for small lists. The +/// insertion sort is also stable. +void mergeSort( + List list, { + int start = 0, + int? end, + int Function(T, T)? compare, +}) { + end ??= list.length; + compare ??= _defaultCompare(); + + final int length = end - start; + if (length < 2) { + return; + } + if (length < _kMergeSortLimit) { + _insertionSort(list, compare: compare, start: start, end: end); + return; + } + // Special case the first split instead of directly calling _mergeSort, + // because the _mergeSort requires its target to be different from its source, + // and it requires extra space of the same size as the list to sort. This + // split allows us to have only half as much extra space, and it ends up in + // the original place. + final int middle = start + ((end - start) >> 1); + final int firstLength = middle - start; + final int secondLength = end - middle; + // secondLength is always the same as firstLength, or one greater. + final List scratchSpace = List.filled(secondLength, list[start]); + _mergeSort(list, compare, middle, end, scratchSpace, 0); + final int firstTarget = end - firstLength; + _mergeSort(list, compare, start, middle, list, firstTarget); + _merge(compare, list, firstTarget, end, scratchSpace, 0, secondLength, list, start); +} + +/// Returns a [Comparator] that asserts that its first argument is comparable. +Comparator _defaultCompare() { + // If we specify Comparable here, it fails if the type is an int, because + // int isn't a subtype of comparable. Leaving out the type implicitly converts + // it to a num, which is a comparable. + return (T value1, T value2) => (value1 as Comparable).compareTo(value2); +} + +/// Sort a list between `start` (inclusive) and `end` (exclusive) using +/// insertion sort. +/// +/// If `compare` is omitted, this defaults to calling [Comparable.compareTo] on +/// the objects. If any object is not [Comparable], this throws a [TypeError] +/// (The stack trace may call it `_CastError` or `_TypeError`, but to catch it, +/// use [TypeError]). +/// +/// Insertion sort is a simple sorting algorithm. For `n` elements it does on +/// the order of `n * log(n)` comparisons but up to `n` squared moves. The +/// sorting is performed in-place, without using extra memory. +/// +/// For short lists the many moves have less impact than the simple algorithm, +/// and it is often the favored sorting algorithm for short lists. +/// +/// This insertion sort is stable: Equal elements end up in the same order as +/// they started in. +void _insertionSort( + List list, { + int Function(T, T)? compare, + int start = 0, + int? end, +}) { + // If the same method could have both positional and named optional + // parameters, this should be (list, [start, end], {compare}). + compare ??= _defaultCompare(); + end ??= list.length; + + for (int pos = start + 1; pos < end; pos++) { + int min = start; + int max = pos; + final T element = list[pos]; + while (min < max) { + final int mid = min + ((max - min) >> 1); + final int comparison = compare(element, list[mid]); + if (comparison < 0) { + max = mid; + } else { + min = mid + 1; + } + } + list.setRange(min + 1, pos + 1, list, min); + list[min] = element; + } +} + +/// Performs an insertion sort into a potentially different list than the one +/// containing the original values. +/// +/// It will work in-place as well. +void _movingInsertionSort( + List list, + int Function(T, T) compare, + int start, + int end, + List target, + int targetOffset, +) { + final int length = end - start; + if (length == 0) { + return; + } + target[targetOffset] = list[start]; + for (int i = 1; i < length; i++) { + final T element = list[start + i]; + int min = targetOffset; + int max = targetOffset + i; + while (min < max) { + final int mid = min + ((max - min) >> 1); + if (compare(element, target[mid]) < 0) { + max = mid; + } else { + min = mid + 1; + } + } + target.setRange(min + 1, targetOffset + i + 1, target, min); + target[min] = element; + } +} + +/// Sorts `list` from `start` to `end` into `target` at `targetOffset`. +/// +/// The `target` list must be able to contain the range from `start` to `end` +/// after `targetOffset`. +/// +/// Allows target to be the same list as `list`, as long as it's not overlapping +/// the `start..end` range. +void _mergeSort( + List list, + int Function(T, T) compare, + int start, + int end, + List target, + int targetOffset, +) { + final int length = end - start; + if (length < _kMergeSortLimit) { + _movingInsertionSort(list, compare, start, end, target, targetOffset); + return; + } + final int middle = start + (length >> 1); + final int firstLength = middle - start; + final int secondLength = end - middle; + // Here secondLength >= firstLength (differs by at most one). + final int targetMiddle = targetOffset + firstLength; + // Sort the second half into the end of the target area. + _mergeSort(list, compare, middle, end, target, targetMiddle); + // Sort the first half into the end of the source area. + _mergeSort(list, compare, start, middle, list, middle); + // Merge the two parts into the target area. + _merge( + compare, + list, + middle, + middle + firstLength, + target, + targetMiddle, + targetMiddle + secondLength, + target, + targetOffset, + ); +} + +/// Merges two lists into a target list. +/// +/// One of the input lists may be positioned at the end of the target list. +/// +/// For equal object, elements from `firstList` are always preferred. This +/// allows the merge to be stable if the first list contains elements that +/// started out earlier than the ones in `secondList`. +void _merge( + int Function(T, T) compare, + List firstList, + int firstStart, + int firstEnd, + List secondList, + int secondStart, + int secondEnd, + List target, + int targetOffset, +) { + // No empty lists reaches here. + assert(firstStart < firstEnd); + assert(secondStart < secondEnd); + int cursor1 = firstStart; + int cursor2 = secondStart; + T firstElement = firstList[cursor1++]; + T secondElement = secondList[cursor2++]; + while (true) { + if (compare(firstElement, secondElement) <= 0) { + target[targetOffset++] = firstElement; + if (cursor1 == firstEnd) { + // Flushing second list after loop. + break; + } + firstElement = firstList[cursor1++]; + } else { + target[targetOffset++] = secondElement; + if (cursor2 != secondEnd) { + secondElement = secondList[cursor2++]; + continue; + } + // Second list empties first. Flushing first list here. + target[targetOffset++] = firstElement; + target.setRange(targetOffset, targetOffset + (firstEnd - cursor1), firstList, cursor1); + return; + } + } + // First list empties first. Reached by break above. + target[targetOffset++] = secondElement; + target.setRange(targetOffset, targetOffset + (secondEnd - cursor2), secondList, cursor2); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/consolidate_response.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/consolidate_response.dart new file mode 100644 index 0000000000000000000000000000000000000000..126d44b26d01edf83fa71d7e53852c04b9001586 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/consolidate_response.dart @@ -0,0 +1,130 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:convert'; +import 'dart:io'; +import 'dart:typed_data'; + +export 'dart:io' show HttpClientResponse; +export 'dart:typed_data' show Uint8List; + +/// Signature for getting notified when chunks of bytes are received while +/// consolidating the bytes of an [HttpClientResponse] into a [Uint8List]. +/// +/// The `cumulative` parameter will contain the total number of bytes received +/// thus far. If the response has been gzipped, this number will be the number +/// of compressed bytes that have been received _across the wire_. +/// +/// The `total` parameter will contain the _expected_ total number of bytes to +/// be received across the wire (extracted from the value of the +/// `Content-Length` HTTP response header), or null if the size of the response +/// body is not known in advance (this is common for HTTP chunked transfer +/// encoding, which itself is common when a large amount of data is being +/// returned to the client and the total size of the response may not be known +/// until the request has been fully processed). +/// +/// This is used in [consolidateHttpClientResponseBytes]. +typedef BytesReceivedCallback = void Function(int cumulative, int? total); + +/// Efficiently converts the response body of an [HttpClientResponse] into a +/// [Uint8List]. +/// +/// The future returned will forward any error emitted by `response`. +/// +/// The `onBytesReceived` callback, if specified, will be invoked for every +/// chunk of bytes that is received while consolidating the response bytes. +/// If the callback throws an error, processing of the response will halt, and +/// the returned future will complete with the error that was thrown by the +/// callback. For more information on how to interpret the parameters to the +/// callback, see the documentation on [BytesReceivedCallback]. +/// +/// If the `response` is gzipped and the `autoUncompress` parameter is true, +/// this will automatically un-compress the bytes in the returned list if it +/// hasn't already been done via [HttpClient.autoUncompress]. To get compressed +/// bytes from this method (assuming the response is sending compressed bytes), +/// set both [HttpClient.autoUncompress] to false and the `autoUncompress` +/// parameter to false. +Future consolidateHttpClientResponseBytes( + HttpClientResponse response, { + bool autoUncompress = true, + BytesReceivedCallback? onBytesReceived, +}) { + final Completer completer = Completer.sync(); + + final _OutputBuffer output = _OutputBuffer(); + ByteConversionSink sink = output; + int? expectedContentLength = response.contentLength; + if (expectedContentLength == -1) { + expectedContentLength = null; + } + switch (response.compressionState) { + case HttpClientResponseCompressionState.compressed: + if (autoUncompress) { + // We need to un-compress the bytes as they come in. + sink = gzip.decoder.startChunkedConversion(output); + } + case HttpClientResponseCompressionState.decompressed: + // response.contentLength will not match our bytes stream, so we declare + // that we don't know the expected content length. + expectedContentLength = null; + case HttpClientResponseCompressionState.notCompressed: + // Fall-through. + break; + } + + int bytesReceived = 0; + late final StreamSubscription> subscription; + subscription = response.listen((List chunk) { + sink.add(chunk); + if (onBytesReceived != null) { + bytesReceived += chunk.length; + try { + onBytesReceived(bytesReceived, expectedContentLength); + } catch (error, stackTrace) { + completer.completeError(error, stackTrace); + subscription.cancel(); + return; + } + } + }, onDone: () { + sink.close(); + completer.complete(output.bytes); + }, onError: completer.completeError, cancelOnError: true); + + return completer.future; +} + +class _OutputBuffer extends ByteConversionSinkBase { + List>? _chunks = >[]; + int _contentLength = 0; + Uint8List? _bytes; + + @override + void add(List chunk) { + assert(_bytes == null); + _chunks!.add(chunk); + _contentLength += chunk.length; + } + + @override + void close() { + if (_bytes != null) { + // We've already been closed; this is a no-op + return; + } + _bytes = Uint8List(_contentLength); + int offset = 0; + for (final List chunk in _chunks!) { + _bytes!.setRange(offset, offset + chunk.length, chunk); + offset += chunk.length; + } + _chunks = null; + } + + Uint8List get bytes { + assert(_bytes != null); + return _bytes!; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/constants.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/constants.dart new file mode 100644 index 0000000000000000000000000000000000000000..ec42df6425ef2eaa16b0f3d3ae0667cf2ad6f477 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/constants.dart @@ -0,0 +1,80 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// A constant that is true if the application was compiled in release mode. +/// +/// More specifically, this is a constant that is true if the application was +/// compiled in Dart with the '-Ddart.vm.product=true' flag. +/// +/// Since this is a const value, it can be used to indicate to the compiler that +/// a particular block of code will not be executed in release mode, and hence +/// can be removed. +/// +/// Generally it is better to use [kDebugMode] or `assert` to gate code, since +/// using [kReleaseMode] will introduce differences between release and profile +/// builds, which makes performance testing less representative. +/// +/// See also: +/// +/// * [kDebugMode], which is true in debug builds. +/// * [kProfileMode], which is true in profile builds. +const bool kReleaseMode = bool.fromEnvironment('dart.vm.product'); + +/// A constant that is true if the application was compiled in profile mode. +/// +/// More specifically, this is a constant that is true if the application was +/// compiled in Dart with the '-Ddart.vm.profile=true' flag. +/// +/// Since this is a const value, it can be used to indicate to the compiler that +/// a particular block of code will not be executed in profile mode, an hence +/// can be removed. +/// +/// See also: +/// +/// * [kDebugMode], which is true in debug builds. +/// * [kReleaseMode], which is true in release builds. +const bool kProfileMode = bool.fromEnvironment('dart.vm.profile'); + +/// A constant that is true if the application was compiled in debug mode. +/// +/// More specifically, this is a constant that is true if the application was +/// not compiled with '-Ddart.vm.product=true' and '-Ddart.vm.profile=true'. +/// +/// Since this is a const value, it can be used to indicate to the compiler that +/// a particular block of code will not be executed in debug mode, and hence +/// can be removed. +/// +/// An alternative strategy is to use asserts, as in: +/// +/// ```dart +/// assert(() { +/// // ...debug-only code here... +/// return true; +/// }()); +/// ``` +/// +/// See also: +/// +/// * [kReleaseMode], which is true in release builds. +/// * [kProfileMode], which is true in profile builds. +const bool kDebugMode = !kReleaseMode && !kProfileMode; + +/// The epsilon of tolerable double precision error. +/// +/// This is used in various places in the framework to allow for floating point +/// 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. +/// +/// See also: +/// +/// * [defaultTargetPlatform], which is used by themes to find out which +/// platform the application is running on (or, in the case of a web app, +/// which platform the application's browser is running in). Can be overridden +/// in tests with [debugDefaultTargetPlatformOverride]. +/// * [dart:io.Platform], a way to find out the browser's platform that is not +/// overridable in tests. +const bool kIsWeb = bool.fromEnvironment('dart.library.js_util'); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/debug.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/debug.dart new file mode 100644 index 0000000000000000000000000000000000000000..ab9ff30c38ffbfbe1b4ad37a9fcae6dcb097507c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/debug.dart @@ -0,0 +1,123 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show Brightness; + +import 'assertions.dart'; +import 'platform.dart'; +import 'print.dart'; + +export 'dart:ui' show Brightness; + +export 'print.dart' show DebugPrintCallback; + +/// Returns true if none of the foundation library debug variables have been +/// changed. +/// +/// This function is used by the test framework to ensure that debug variables +/// haven't been inadvertently changed. +/// +/// The `debugPrintOverride` argument can be specified to indicate the expected +/// value of the [debugPrint] variable. This is useful for test frameworks that +/// override [debugPrint] themselves and want to check that their own custom +/// value wasn't overridden by a test. +/// +/// See [the foundation library](foundation/foundation-library.html) +/// for a complete list. +bool debugAssertAllFoundationVarsUnset(String reason, { DebugPrintCallback debugPrintOverride = debugPrintThrottled }) { + assert(() { + if (debugPrint != debugPrintOverride || + debugDefaultTargetPlatformOverride != null || + debugDoublePrecision != null || + debugBrightnessOverride != null) { + throw FlutterError(reason); + } + return true; + }()); + return true; +} + +/// Boolean value indicating whether [debugInstrumentAction] will instrument +/// actions in debug builds. +/// +/// The framework does not use [debugInstrumentAction] internally, so this +/// does not enable any additional instrumentation for the framework itself. +/// +/// See also: +/// +/// * [debugProfileBuildsEnabled], which enables additional tracing of builds +/// in [Widget]s. +/// * [debugProfileLayoutsEnabled], which enables additional tracing of layout +/// events in [RenderObject]s. +/// * [debugProfilePaintsEnabled], which enables additional tracing of paint +/// events in [RenderObject]s. +bool debugInstrumentationEnabled = false; + +/// Runs the specified [action], timing how long the action takes in debug +/// builds when [debugInstrumentationEnabled] is true. +/// +/// The instrumentation will be printed to the logs using [debugPrint]. In +/// non-debug builds, or when [debugInstrumentationEnabled] is false, this will +/// run [action] without any instrumentation. +/// +/// Returns the result of running [action]. +/// +/// See also: +/// +/// * [Timeline], which is used to record synchronous tracing events for +/// visualization in Chrome's tracing format. This method does not +/// implicitly add any timeline events. +Future debugInstrumentAction(String description, Future Function() action) async { + bool instrument = false; + assert(() { + instrument = debugInstrumentationEnabled; + return true; + }()); + if (instrument) { + final Stopwatch stopwatch = Stopwatch()..start(); // flutter_ignore: stopwatch (see analyze.dart) + // Ignore context: The framework does not use this function internally so it will not cause flakes. + try { + return await action(); + } finally { + stopwatch.stop(); + debugPrint('Action "$description" took ${stopwatch.elapsed}'); + } + } else { + return action(); + } +} + +/// Configure [debugFormatDouble] using [num.toStringAsPrecision]. +/// +/// Defaults to null, which uses the default logic of [debugFormatDouble]. +int? debugDoublePrecision; + +/// Formats a double to have standard formatting. +/// +/// This behavior can be overridden by [debugDoublePrecision]. +String debugFormatDouble(double? value) { + if (value == null) { + return 'null'; + } + if (debugDoublePrecision != null) { + return value.toStringAsPrecision(debugDoublePrecision!); + } + return value.toStringAsFixed(1); +} + +/// A setting that can be used to override the platform [Brightness] exposed +/// from [BindingBase.platformDispatcher]. +/// +/// See also: +/// +/// * [WidgetsApp], which uses the [debugBrightnessOverride] setting in debug mode +/// to construct a [MediaQueryData]. +ui.Brightness? debugBrightnessOverride; + +/// The address for the active DevTools server used for debugging this +/// application. +String? activeDevToolsServerAddress; + +/// The uri for the connected vm service protocol. +String? connectedVmServiceUri; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/diagnostics.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/diagnostics.dart new file mode 100644 index 0000000000000000000000000000000000000000..a23a9bee34c1b0c27f9bd8a8bd5aeb1a84f72733 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/diagnostics.dart @@ -0,0 +1,3651 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show clampDouble; + +import 'package:meta/meta.dart'; + +import 'assertions.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'object.dart'; + +// Examples can assume: +// late int rows, columns; +// late String _name; +// late bool inherit; +// abstract class ExampleSuperclass with Diagnosticable { } +// late String message; +// late double stepWidth; +// late double scale; +// late double hitTestExtent; +// late double paintExtent; +// late double maxWidth; +// late double progress; +// late int maxLines; +// late Duration duration; +// late int depth; +// late bool primary; +// late bool isCurrent; +// late bool keepAlive; +// late bool obscureText; +// late TextAlign textAlign; +// late ImageRepeat repeat; +// late Widget widget; +// late List boxShadow; +// late Size size; +// late bool hasSize; +// late Matrix4 transform; +// late Color color; +// late Map? handles; +// late DiagnosticsTreeStyle style; +// late IconData icon; +// late double devicePixelRatio; + +/// The various priority levels used to filter which diagnostics are shown and +/// omitted. +/// +/// Trees of Flutter diagnostics can be very large so filtering the diagnostics +/// shown matters. Typically filtering to only show diagnostics with at least +/// level [debug] is appropriate. +/// +/// In release mode, this level may not have any effect, as diagnostics in +/// release mode are compacted or truncated to reduce binary size. +enum DiagnosticLevel { + /// Diagnostics that should not be shown. + /// + /// If a user chooses to display [hidden] diagnostics, they should not expect + /// the diagnostics to be formatted consistently with other diagnostics and + /// they should expect them to sometimes be misleading. For example, + /// [FlagProperty] and [ObjectFlagProperty] have uglier formatting when the + /// property `value` does not match a value with a custom flag + /// description. An example of a misleading diagnostic is a diagnostic for + /// a property that has no effect because some other property of the object is + /// set in a way that causes the hidden property to have no effect. + hidden, + + /// A diagnostic that is likely to be low value but where the diagnostic + /// display is just as high quality as a diagnostic with a higher level. + /// + /// Use this level for diagnostic properties that match their default value + /// and other cases where showing a diagnostic would not add much value such + /// as an [IterableProperty] where the value is empty. + fine, + + /// Diagnostics that should only be shown when performing fine grained + /// debugging of an object. + /// + /// Unlike a [fine] diagnostic, these diagnostics provide important + /// information about the object that is likely to be needed to debug. Used by + /// properties that are important but where the property value is too verbose + /// (e.g. 300+ characters long) to show with a higher diagnostic level. + debug, + + /// Interesting diagnostics that should be typically shown. + info, + + /// Very important diagnostics that indicate problematic property values. + /// + /// For example, use if you would write the property description + /// message in ALL CAPS. + warning, + + /// Diagnostics that provide a hint about best practices. + /// + /// For example, a diagnostic describing best practices for fixing an error. + hint, + + /// Diagnostics that summarize other diagnostics present. + /// + /// For example, use this level for a short one or two line summary + /// describing other diagnostics present. + summary, + + /// Diagnostics that indicate errors or unexpected conditions. + /// + /// For example, use for property values where computing the value throws an + /// exception. + error, + + /// Special level indicating that no diagnostics should be shown. + /// + /// Do not specify this level for diagnostics. This level is only used to + /// filter which diagnostics are shown. + off, +} + +/// Styles for displaying a node in a [DiagnosticsNode] tree. +/// +/// In release mode, these styles may be ignored, as diagnostics are compacted +/// or truncated to save on binary size. +/// +/// See also: +/// +/// * [DiagnosticsNode.toStringDeep], which dumps text art trees for these +/// styles. +enum DiagnosticsTreeStyle { + /// A style that does not display the tree, for release mode. + none, + + /// Sparse style for displaying trees. + /// + /// See also: + /// + /// * [RenderObject], which uses this style. + sparse, + + /// Connects a node to its parent with a dashed line. + /// + /// See also: + /// + /// * [RenderSliverMultiBoxAdaptor], which uses this style to distinguish + /// offstage children from onstage children. + offstage, + + /// Slightly more compact version of the [sparse] style. + /// + /// See also: + /// + /// * [Element], which uses this style. + dense, + + /// Style that enables transitioning from nodes of one style to children of + /// another. + /// + /// See also: + /// + /// * [RenderParagraph], which uses this style to display a [TextSpan] child + /// in a way that is compatible with the [DiagnosticsTreeStyle.sparse] + /// style of the [RenderObject] tree. + transition, + + /// Style for displaying content describing an error. + /// + /// See also: + /// + /// * [FlutterError], which uses this style for the root node in a tree + /// describing an error. + error, + + /// Render the tree just using whitespace without connecting parents to + /// children using lines. + /// + /// See also: + /// + /// * [SliverGeometry], which uses this style. + whitespace, + + /// Render the tree without indenting children at all. + /// + /// See also: + /// + /// * [DiagnosticsStackTrace], which uses this style. + flat, + + /// Render the tree on a single line without showing children. + singleLine, + + /// Render the tree using a style appropriate for properties that are part + /// of an error message. + /// + /// The name is placed on one line with the value and properties placed on + /// the following line. + /// + /// See also: + /// + /// * [singleLine], which displays the same information but keeps the + /// property and value on the same line. + errorProperty, + + /// Render only the immediate properties of a node instead of the full tree. + /// + /// See also: + /// + /// * [DebugOverflowIndicatorMixin], which uses this style to display just + /// the immediate children of a node. + shallow, + + /// Render only the children of a node truncating before the tree becomes too + /// large. + truncateChildren, +} + +/// Configuration specifying how a particular [DiagnosticsTreeStyle] should be +/// rendered as text art. +/// +/// In release mode, these configurations may be ignored, as diagnostics are +/// compacted or truncated to save on binary size. +/// +/// See also: +/// +/// * [sparseTextConfiguration], which is a typical style. +/// * [transitionTextConfiguration], which is an example of a complex tree style. +/// * [DiagnosticsNode.toStringDeep], for code using [TextTreeConfiguration] +/// to render text art for arbitrary trees of [DiagnosticsNode] objects. +class TextTreeConfiguration { + /// Create a configuration object describing how to render a tree as text. + TextTreeConfiguration({ + required this.prefixLineOne, + required this.prefixOtherLines, + required this.prefixLastChildLineOne, + required this.prefixOtherLinesRootNode, + required this.linkCharacter, + required this.propertyPrefixIfChildren, + required this.propertyPrefixNoChildren, + this.lineBreak = '\n', + this.lineBreakProperties = true, + this.afterName = ':', + this.afterDescriptionIfBody = '', + this.afterDescription = '', + this.beforeProperties = '', + this.afterProperties = '', + this.mandatoryAfterProperties = '', + this.propertySeparator = '', + this.bodyIndent = '', + this.footer = '', + this.showChildren = true, + this.addBlankLineIfNoChildren = true, + this.isNameOnOwnLine = false, + this.isBlankLineBetweenPropertiesAndChildren = true, + this.beforeName = '', + this.suffixLineOne = '', + this.mandatoryFooter = '', + }) : childLinkSpace = ' ' * linkCharacter.length; + + /// Prefix to add to the first line to display a child with this style. + final String prefixLineOne; + + /// Suffix to add to end of the first line to make its length match the footer. + final String suffixLineOne; + + /// Prefix to add to other lines to display a child with this style. + /// + /// [prefixOtherLines] should typically be one character shorter than + /// [prefixLineOne] is. + final String prefixOtherLines; + + /// Prefix to add to the first line to display the last child of a node with + /// this style. + final String prefixLastChildLineOne; + + /// Additional prefix to add to other lines of a node if this is the root node + /// of the tree. + final String prefixOtherLinesRootNode; + + /// Prefix to add before each property if the node as children. + /// + /// Plays a similar role to [linkCharacter] except that some configurations + /// intentionally use a different line style than the [linkCharacter]. + final String propertyPrefixIfChildren; + + /// Prefix to add before each property if the node does not have children. + /// + /// This string is typically a whitespace string the same length as + /// [propertyPrefixIfChildren] but can have a different length. + final String propertyPrefixNoChildren; + + /// Character to use to draw line linking parent to child. + /// + /// The first child does not require a line but all subsequent children do + /// with the line drawn immediately before the left edge of the previous + /// sibling. + final String linkCharacter; + + /// Whitespace to draw instead of the childLink character if this node is the + /// last child of its parent so no link line is required. + final String childLinkSpace; + + /// Character(s) to use to separate lines. + /// + /// Typically leave set at the default value of '\n' unless this style needs + /// to treat lines differently as is the case for + /// [singleLineTextConfiguration]. + final String lineBreak; + + /// Whether to place line breaks between properties or to leave all + /// properties on one line. + final bool lineBreakProperties; + + + /// Text added immediately before the name of the node. + /// + /// See [errorTextConfiguration] for an example of using this to achieve a + /// custom line art style. + final String beforeName; + + /// Text added immediately after the name of the node. + /// + /// See [transitionTextConfiguration] for an example of using a value other + /// than ':' to achieve a custom line art style. + final String afterName; + + /// Text to add immediately after the description line of a node with + /// properties and/or children if the node has a body. + final String afterDescriptionIfBody; + + /// Text to add immediately after the description line of a node with + /// properties and/or children. + final String afterDescription; + + /// Optional string to add before the properties of a node. + /// + /// Only displayed if the node has properties. + /// See [singleLineTextConfiguration] for an example of using this field + /// to enclose the property list with parenthesis. + final String beforeProperties; + + /// Optional string to add after the properties of a node. + /// + /// See documentation for [beforeProperties]. + final String afterProperties; + + /// Mandatory string to add after the properties of a node regardless of + /// whether the node has any properties. + final String mandatoryAfterProperties; + + /// Property separator to add between properties. + /// + /// See [singleLineTextConfiguration] for an example of using this field + /// to render properties as a comma separated list. + final String propertySeparator; + + /// Prefix to add to all lines of the body of the tree node. + /// + /// The body is all content in the node other than the name and description. + final String bodyIndent; + + /// Whether the children of a node should be shown. + /// + /// See [singleLineTextConfiguration] for an example of using this field to + /// hide all children of a node. + final bool showChildren; + + /// Whether to add a blank line at the end of the output for a node if it has + /// no children. + /// + /// See [denseTextConfiguration] for an example of setting this to false. + final bool addBlankLineIfNoChildren; + + /// Whether the name should be displayed on the same line as the description. + final bool isNameOnOwnLine; + + /// Footer to add as its own line at the end of a non-root node. + /// + /// See [transitionTextConfiguration] for an example of using footer to draw a box + /// around the node. [footer] is indented the same amount as [prefixOtherLines]. + final String footer; + + /// Footer to add even for root nodes. + final String mandatoryFooter; + + /// Add a blank line between properties and children if both are present. + final bool isBlankLineBetweenPropertiesAndChildren; +} + +/// Default text tree configuration. +/// +/// Example: +/// +/// : +/// │ +/// │ +/// │ ... +/// │ +/// ├─: +/// │ │ +/// │ │ +/// │ │ ... +/// │ │ +/// │ │ +/// │ └─: +/// │ +/// │ +/// │ ... +/// │ +/// │ +/// └─: ' +/// +/// +/// ... +/// +/// +/// See also: +/// +/// * [DiagnosticsTreeStyle.sparse], uses this style for ASCII art display. +final TextTreeConfiguration sparseTextConfiguration = TextTreeConfiguration( + prefixLineOne: '├─', + prefixOtherLines: ' ', + prefixLastChildLineOne: '└─', + linkCharacter: '│', + propertyPrefixIfChildren: '│ ', + propertyPrefixNoChildren: ' ', + prefixOtherLinesRootNode: ' ', +); + +/// Identical to [sparseTextConfiguration] except that the lines connecting +/// parent to children are dashed. +/// +/// Example: +/// +/// : +/// │ +/// │ +/// │ ... +/// │ +/// ├─: +/// ╎ │ +/// ╎ │ +/// ╎ │ ... +/// ╎ │ +/// ╎ │ +/// ╎ └─: +/// ╎ +/// ╎ +/// ╎ ... +/// ╎ +/// ╎ +/// ╎╌: +/// ╎ │ +/// ╎ │ +/// ╎ │ ... +/// ╎ │ +/// ╎ │ +/// ╎ └─: +/// ╎ +/// ╎ +/// ╎ ... +/// ╎ +/// ╎ +/// └╌: ' +/// +/// +/// ... +/// +/// +/// See also: +/// +/// * [DiagnosticsTreeStyle.offstage], uses this style for ASCII art display. +final TextTreeConfiguration dashedTextConfiguration = TextTreeConfiguration( + prefixLineOne: '╎╌', + prefixLastChildLineOne: '└╌', + prefixOtherLines: ' ', + linkCharacter: '╎', + // Intentionally not set as a dashed line as that would make the properties + // look like they were disabled. + propertyPrefixIfChildren: '│ ', + propertyPrefixNoChildren: ' ', + prefixOtherLinesRootNode: ' ', +); + +/// Dense text tree configuration that minimizes horizontal whitespace. +/// +/// Example: +/// +/// : (; ) +/// ├: (, , ) +/// └: (, , ) +/// +/// See also: +/// +/// * [DiagnosticsTreeStyle.dense], uses this style for ASCII art display. +final TextTreeConfiguration denseTextConfiguration = TextTreeConfiguration( + propertySeparator: ', ', + beforeProperties: '(', + afterProperties: ')', + lineBreakProperties: false, + prefixLineOne: '├', + prefixOtherLines: '', + prefixLastChildLineOne: '└', + linkCharacter: '│', + propertyPrefixIfChildren: '│', + propertyPrefixNoChildren: ' ', + prefixOtherLinesRootNode: '', + addBlankLineIfNoChildren: false, + isBlankLineBetweenPropertiesAndChildren: false, +); + +/// Configuration that draws a box around a leaf node. +/// +/// Used by leaf nodes such as [TextSpan] to draw a clear border around the +/// contents of a node. +/// +/// Example: +/// +/// +/// ╞═╦══ ═══ +/// │ ║ : +/// │ ║ +/// │ ║ ... +/// │ ╚═══════════ +/// ╘═╦══ ═══ +/// ║ : +/// ║ +/// ║ ... +/// ╚═══════════ +/// +/// See also: +/// +/// * [DiagnosticsTreeStyle.transition], uses this style for ASCII art display. +final TextTreeConfiguration transitionTextConfiguration = TextTreeConfiguration( + prefixLineOne: '╞═╦══ ', + prefixLastChildLineOne: '╘═╦══ ', + prefixOtherLines: ' ║ ', + footer: ' ╚═══════════', + linkCharacter: '│', + // Subtree boundaries are clear due to the border around the node so omit the + // property prefix. + propertyPrefixIfChildren: '', + propertyPrefixNoChildren: '', + prefixOtherLinesRootNode: '', + afterName: ' ═══', + // Add a colon after the description if the node has a body to make the + // connection between the description and the body clearer. + afterDescriptionIfBody: ':', + // Members are indented an extra two spaces to disambiguate as the description + // is placed within the box instead of along side the name as is the case for + // other styles. + bodyIndent: ' ', + isNameOnOwnLine: true, + // No need to add a blank line as the footer makes the boundary of this + // subtree unambiguous. + addBlankLineIfNoChildren: false, + isBlankLineBetweenPropertiesAndChildren: false, +); + +/// Configuration that draws a box around a node ignoring the connection to the +/// parents. +/// +/// If nested in a tree, this node is best displayed in the property box rather +/// than as a traditional child. +/// +/// Used to draw a decorative box around detailed descriptions of an exception. +/// +/// Example: +/// +/// ══╡ : ╞═════════════════════════════════════ +/// +/// ... +/// ├─: +/// ╎ │ +/// ╎ │ +/// ╎ │ ... +/// ╎ │ +/// ╎ │ +/// ╎ └─: +/// ╎ +/// ╎ +/// ╎ ... +/// ╎ +/// ╎ +/// ╎╌: +/// ╎ │ +/// ╎ │ +/// ╎ │ ... +/// ╎ │ +/// ╎ │ +/// ╎ └─: +/// ╎ +/// ╎ +/// ╎ ... +/// ╎ +/// ╎ +/// └╌: ' +/// ════════════════════════════════════════════════════════════════ +/// +/// See also: +/// +/// * [DiagnosticsTreeStyle.error], uses this style for ASCII art display. +final TextTreeConfiguration errorTextConfiguration = TextTreeConfiguration( + prefixLineOne: '╞═╦', + prefixLastChildLineOne: '╘═╦', + prefixOtherLines: ' ║ ', + footer: ' ╚═══════════', + linkCharacter: '│', + // Subtree boundaries are clear due to the border around the node so omit the + // property prefix. + propertyPrefixIfChildren: '', + propertyPrefixNoChildren: '', + prefixOtherLinesRootNode: '', + beforeName: '══╡ ', + suffixLineOne: ' ╞══', + mandatoryFooter: '═════', + // No need to add a blank line as the footer makes the boundary of this + // subtree unambiguous. + addBlankLineIfNoChildren: false, + isBlankLineBetweenPropertiesAndChildren: false, +); + +/// Whitespace only configuration where children are consistently indented +/// two spaces. +/// +/// Use this style for displaying properties with structured values or for +/// displaying children within a [transitionTextConfiguration] as using a style that +/// draws line art would be visually distracting for those cases. +/// +/// Example: +/// +/// +/// : : +/// +/// +/// : : +/// +/// +/// +/// See also: +/// +/// * [DiagnosticsTreeStyle.whitespace], uses this style for ASCII art display. +final TextTreeConfiguration whitespaceTextConfiguration = TextTreeConfiguration( + prefixLineOne: '', + prefixLastChildLineOne: '', + prefixOtherLines: ' ', + prefixOtherLinesRootNode: ' ', + propertyPrefixIfChildren: '', + propertyPrefixNoChildren: '', + linkCharacter: ' ', + addBlankLineIfNoChildren: false, + // Add a colon after the description and before the properties to link the + // properties to the description line. + afterDescriptionIfBody: ':', + isBlankLineBetweenPropertiesAndChildren: false, +); + +/// Whitespace only configuration where children are not indented. +/// +/// Use this style when indentation is not needed to disambiguate parents from +/// children as in the case of a [DiagnosticsStackTrace]. +/// +/// Example: +/// +/// +/// : : +/// +/// +/// : : +/// +/// +/// +/// See also: +/// +/// * [DiagnosticsTreeStyle.flat], uses this style for ASCII art display. +final TextTreeConfiguration flatTextConfiguration = TextTreeConfiguration( + prefixLineOne: '', + prefixLastChildLineOne: '', + prefixOtherLines: '', + prefixOtherLinesRootNode: '', + propertyPrefixIfChildren: '', + propertyPrefixNoChildren: '', + linkCharacter: '', + addBlankLineIfNoChildren: false, + // Add a colon after the description and before the properties to link the + // properties to the description line. + afterDescriptionIfBody: ':', + isBlankLineBetweenPropertiesAndChildren: false, +); +/// Render a node as a single line omitting children. +/// +/// Example: +/// `: (, , ..., )` +/// +/// See also: +/// +/// * [DiagnosticsTreeStyle.singleLine], uses this style for ASCII art display. +final TextTreeConfiguration singleLineTextConfiguration = TextTreeConfiguration( + propertySeparator: ', ', + beforeProperties: '(', + afterProperties: ')', + prefixLineOne: '', + prefixOtherLines: '', + prefixLastChildLineOne: '', + lineBreak: '', + lineBreakProperties: false, + addBlankLineIfNoChildren: false, + showChildren: false, + propertyPrefixIfChildren: ' ', + propertyPrefixNoChildren: ' ', + linkCharacter: '', + prefixOtherLinesRootNode: '', +); + +/// Render the name on a line followed by the body and properties on the next +/// line omitting the children. +/// +/// Example: +/// +/// : +/// (, , ..., ) +/// +/// See also: +/// +/// * [DiagnosticsTreeStyle.errorProperty], uses this style for ASCII art +/// display. +final TextTreeConfiguration errorPropertyTextConfiguration = TextTreeConfiguration( + propertySeparator: ', ', + beforeProperties: '(', + afterProperties: ')', + prefixLineOne: '', + prefixOtherLines: '', + prefixLastChildLineOne: '', + lineBreakProperties: false, + addBlankLineIfNoChildren: false, + showChildren: false, + propertyPrefixIfChildren: ' ', + propertyPrefixNoChildren: ' ', + linkCharacter: '', + prefixOtherLinesRootNode: '', + isNameOnOwnLine: true, +); + +/// Render a node on multiple lines omitting children. +/// +/// Example: +/// `: +/// +/// +/// ` +/// +/// See also: +/// +/// * [DiagnosticsTreeStyle.shallow] +final TextTreeConfiguration shallowTextConfiguration = TextTreeConfiguration( + prefixLineOne: '', + prefixLastChildLineOne: '', + prefixOtherLines: ' ', + prefixOtherLinesRootNode: ' ', + propertyPrefixIfChildren: '', + propertyPrefixNoChildren: '', + linkCharacter: ' ', + addBlankLineIfNoChildren: false, + // Add a colon after the description and before the properties to link the + // properties to the description line. + afterDescriptionIfBody: ':', + isBlankLineBetweenPropertiesAndChildren: false, + showChildren: false, +); + +enum _WordWrapParseMode { inSpace, inWord, atBreak } + +/// Builder that builds a String with specified prefixes for the first and +/// subsequent lines. +/// +/// Allows for the incremental building of strings using `write*()` methods. +/// The strings are concatenated into a single string with the first line +/// prefixed by [prefixLineOne] and subsequent lines prefixed by +/// [prefixOtherLines]. +class _PrefixedStringBuilder { + _PrefixedStringBuilder({ + required this.prefixLineOne, + required String? prefixOtherLines, + this.wrapWidth, + }) : _prefixOtherLines = prefixOtherLines; + + /// Prefix to add to the first line. + final String prefixLineOne; + + /// Prefix to add to subsequent lines. + /// + /// The prefix can be modified while the string is being built in which case + /// subsequent lines will be added with the modified prefix. + String? get prefixOtherLines => _nextPrefixOtherLines ?? _prefixOtherLines; + String? _prefixOtherLines; + set prefixOtherLines(String? prefix) { + _prefixOtherLines = prefix; + _nextPrefixOtherLines = null; + } + + String? _nextPrefixOtherLines; + void incrementPrefixOtherLines(String suffix, {required bool updateCurrentLine}) { + if (_currentLine.isEmpty || updateCurrentLine) { + _prefixOtherLines = prefixOtherLines! + suffix; + _nextPrefixOtherLines = null; + } else { + _nextPrefixOtherLines = prefixOtherLines! + suffix; + } + } + + final int? wrapWidth; + + /// Buffer containing lines that have already been completely laid out. + final StringBuffer _buffer = StringBuffer(); + /// Buffer containing the current line that has not yet been wrapped. + final StringBuffer _currentLine = StringBuffer(); + /// List of pairs of integers indicating the start and end of each block of + /// text within _currentLine that can be wrapped. + final List _wrappableRanges = []; + + /// Whether the string being built already has more than 1 line. + bool get requiresMultipleLines => _numLines > 1 || (_numLines == 1 && _currentLine.isNotEmpty) || + (_currentLine.length + _getCurrentPrefix(true)!.length > wrapWidth!); + + bool get isCurrentLineEmpty => _currentLine.isEmpty; + + int _numLines = 0; + + void _finalizeLine(bool addTrailingLineBreak) { + final bool firstLine = _buffer.isEmpty; + final String text = _currentLine.toString(); + _currentLine.clear(); + + if (_wrappableRanges.isEmpty) { + // Fast path. There were no wrappable spans of text. + _writeLine( + text, + includeLineBreak: addTrailingLineBreak, + firstLine: firstLine, + ); + return; + } + final Iterable lines = _wordWrapLine( + text, + _wrappableRanges, + wrapWidth!, + startOffset: firstLine ? prefixLineOne.length : _prefixOtherLines!.length, + otherLineOffset: _prefixOtherLines!.length, + ); + int i = 0; + final int length = lines.length; + for (final String line in lines) { + i++; + _writeLine( + line, + includeLineBreak: addTrailingLineBreak || i < length, + firstLine: firstLine, + ); + } + _wrappableRanges.clear(); + } + + /// Wraps the given string at the given width. + /// + /// Wrapping occurs at space characters (U+0020). + /// + /// This is not suitable for use with arbitrary Unicode text. For example, it + /// doesn't implement UAX #14, can't handle ideographic text, doesn't hyphenate, + /// and so forth. It is only intended for formatting error messages. + /// + /// This method wraps a sequence of text where only some spans of text can be + /// used as wrap boundaries. + static Iterable _wordWrapLine(String message, List wrapRanges, int width, { int startOffset = 0, int otherLineOffset = 0}) { + if (message.length + startOffset < width) { + // Nothing to do. The line doesn't wrap. + return [message]; + } + final List wrappedLine = []; + int startForLengthCalculations = -startOffset; + bool addPrefix = false; + int index = 0; + _WordWrapParseMode mode = _WordWrapParseMode.inSpace; + late int lastWordStart; + int? lastWordEnd; + int start = 0; + + int currentChunk = 0; + + // This helper is called with increasing indexes. + bool noWrap(int index) { + while (true) { + if (currentChunk >= wrapRanges.length) { + return true; + } + + if (index < wrapRanges[currentChunk + 1]) { + break; // Found nearest chunk. + } + currentChunk+= 2; + } + return index < wrapRanges[currentChunk]; + } + while (true) { + switch (mode) { + case _WordWrapParseMode.inSpace: // at start of break point (or start of line); can't break until next break + while ((index < message.length) && (message[index] == ' ')) { + index += 1; + } + lastWordStart = index; + mode = _WordWrapParseMode.inWord; + case _WordWrapParseMode.inWord: // looking for a good break point. Treat all text + while ((index < message.length) && (message[index] != ' ' || noWrap(index))) { + index += 1; + } + mode = _WordWrapParseMode.atBreak; + case _WordWrapParseMode.atBreak: // at start of break point + if ((index - startForLengthCalculations > width) || (index == message.length)) { + // we are over the width line, so break + if ((index - startForLengthCalculations <= width) || (lastWordEnd == null)) { + // we should use this point, because either it doesn't actually go over the + // end (last line), or it does, but there was no earlier break point + lastWordEnd = index; + } + final String line = message.substring(start, lastWordEnd); + wrappedLine.add(line); + addPrefix = true; + if (lastWordEnd >= message.length) { + return wrappedLine; + } + // just yielded a line + if (lastWordEnd == index) { + // we broke at current position + // eat all the wrappable spaces, then set our start point + // Even if some of the spaces are not wrappable that is ok. + while ((index < message.length) && (message[index] == ' ')) { + index += 1; + } + start = index; + mode = _WordWrapParseMode.inWord; + } else { + // we broke at the previous break point, and we're at the start of a new one + assert(lastWordStart > lastWordEnd); + start = lastWordStart; + mode = _WordWrapParseMode.atBreak; + } + startForLengthCalculations = start - otherLineOffset; + assert(addPrefix); + lastWordEnd = null; + } else { + // save this break point, we're not yet over the line width + lastWordEnd = index; + // skip to the end of this break point + mode = _WordWrapParseMode.inSpace; + } + } + } + } + + /// Write text ensuring the specified prefixes for the first and subsequent + /// lines. + /// + /// If [allowWrap] is true, the text may be wrapped to stay within the + /// allow `wrapWidth`. + void write(String s, {bool allowWrap = false}) { + if (s.isEmpty) { + return; + } + + final List lines = s.split('\n'); + for (int i = 0; i < lines.length; i += 1) { + if (i > 0) { + _finalizeLine(true); + _updatePrefix(); + } + final String line = lines[i]; + if (line.isNotEmpty) { + if (allowWrap && wrapWidth != null) { + final int wrapStart = _currentLine.length; + final int wrapEnd = wrapStart + line.length; + if (_wrappableRanges.isNotEmpty && _wrappableRanges.last == wrapStart) { + // Extend last range. + _wrappableRanges.last = wrapEnd; + } else { + _wrappableRanges..add(wrapStart)..add(wrapEnd); + } + } + _currentLine.write(line); + } + } + } + void _updatePrefix() { + if (_nextPrefixOtherLines != null) { + _prefixOtherLines = _nextPrefixOtherLines; + _nextPrefixOtherLines = null; + } + } + + void _writeLine( + String line, { + required bool includeLineBreak, + required bool firstLine, + }) { + line = '${_getCurrentPrefix(firstLine)}$line'; + _buffer.write(line.trimRight()); + if (includeLineBreak) { + _buffer.write('\n'); + } + _numLines++; + } + + String? _getCurrentPrefix(bool firstLine) { + return _buffer.isEmpty ? prefixLineOne : _prefixOtherLines; + } + + /// Write lines assuming the lines obey the specified prefixes. Ensures that + /// a newline is added if one is not present. + void writeRawLines(String lines) { + if (lines.isEmpty) { + return; + } + + if (_currentLine.isNotEmpty) { + _finalizeLine(true); + } + assert (_currentLine.isEmpty); + + _buffer.write(lines); + if (!lines.endsWith('\n')) { + _buffer.write('\n'); + } + _numLines++; + _updatePrefix(); + } + + /// Finishes the current line with a stretched version of text. + void writeStretched(String text, int targetLineLength) { + write(text); + final int currentLineLength = _currentLine.length + _getCurrentPrefix(_buffer.isEmpty)!.length; + assert (_currentLine.length > 0); + final int targetLength = targetLineLength - currentLineLength; + if (targetLength > 0) { + assert(text.isNotEmpty); + final String lastChar = text[text.length - 1]; + assert(lastChar != '\n'); + _currentLine.write(lastChar * targetLength); + } + // Mark the entire line as not wrappable. + _wrappableRanges.clear(); + } + + String build() { + if (_currentLine.isNotEmpty) { + _finalizeLine(false); + } + + return _buffer.toString(); + } +} + +class _NoDefaultValue { + const _NoDefaultValue(); +} + +/// Marker object indicating that a [DiagnosticsNode] has no default value. +const Object kNoDefaultValue = _NoDefaultValue(); + +bool _isSingleLine(DiagnosticsTreeStyle? style) { + return style == DiagnosticsTreeStyle.singleLine; +} + +/// Renderer that creates ASCII art representations of trees of +/// [DiagnosticsNode] objects. +/// +/// See also: +/// +/// * [DiagnosticsNode.toStringDeep], which uses a [TextTreeRenderer] to return a +/// string representation of this node and its descendants. +class TextTreeRenderer { + /// Creates a [TextTreeRenderer] object with the given arguments specifying + /// how the tree is rendered. + /// + /// Lines are wrapped to at the maximum of [wrapWidth] and the current indent + /// plus [wrapWidthProperties] characters. This ensures that wrapping does not + /// become too excessive when displaying very deep trees and that wrapping + /// only occurs at the overall [wrapWidth] when the tree is not very indented. + /// If [maxDescendentsTruncatableNode] is specified, [DiagnosticsNode] objects + /// with `allowTruncate` set to `true` are truncated after including + /// [maxDescendentsTruncatableNode] descendants of the node to be truncated. + TextTreeRenderer({ + DiagnosticLevel minLevel = DiagnosticLevel.debug, + int wrapWidth = 100, + int wrapWidthProperties = 65, + int maxDescendentsTruncatableNode = -1, + }) : _minLevel = minLevel, + _wrapWidth = wrapWidth, + _wrapWidthProperties = wrapWidthProperties, + _maxDescendentsTruncatableNode = maxDescendentsTruncatableNode; + + final int _wrapWidth; + final int _wrapWidthProperties; + final DiagnosticLevel _minLevel; + final int _maxDescendentsTruncatableNode; + + /// Text configuration to use to connect this node to a `child`. + /// + /// The singleLine styles are special cased because the connection from the + /// parent to the child should be consistent with the parent's style as the + /// single line style does not provide any meaningful style for how children + /// should be connected to their parents. + TextTreeConfiguration? _childTextConfiguration( + DiagnosticsNode child, + TextTreeConfiguration textStyle, + ) { + final DiagnosticsTreeStyle? childStyle = child.style; + return (_isSingleLine(childStyle) || childStyle == DiagnosticsTreeStyle.errorProperty) ? textStyle : child.textTreeConfiguration; + } + + /// Renders a [node] to a String. + String render( + DiagnosticsNode node, { + String prefixLineOne = '', + String? prefixOtherLines, + TextTreeConfiguration? parentConfiguration, + }) { + if (kReleaseMode) { + return ''; + } else { + return _debugRender( + node, + prefixLineOne: prefixLineOne, + prefixOtherLines: prefixOtherLines, + parentConfiguration: parentConfiguration, + ); + } + } + + String _debugRender( + DiagnosticsNode node, { + String prefixLineOne = '', + String? prefixOtherLines, + TextTreeConfiguration? parentConfiguration, + }) { + final bool isSingleLine = _isSingleLine(node.style) && parentConfiguration?.lineBreakProperties != true; + prefixOtherLines ??= prefixLineOne; + if (node.linePrefix != null) { + prefixLineOne += node.linePrefix!; + prefixOtherLines += node.linePrefix!; + } + + final TextTreeConfiguration config = node.textTreeConfiguration!; + if (prefixOtherLines.isEmpty) { + prefixOtherLines += config.prefixOtherLinesRootNode; + } + + if (node.style == DiagnosticsTreeStyle.truncateChildren) { + // This style is different enough that it isn't worthwhile to reuse the + // existing logic. + final List descendants = []; + const int maxDepth = 5; + int depth = 0; + const int maxLines = 25; + int lines = 0; + void visitor(DiagnosticsNode node) { + for (final DiagnosticsNode child in node.getChildren()) { + if (lines < maxLines) { + depth += 1; + descendants.add('$prefixOtherLines${" " * depth}$child'); + if (depth < maxDepth) { + visitor(child); + } + depth -= 1; + } else if (lines == maxLines) { + descendants.add('$prefixOtherLines ...(descendants list truncated after $lines lines)'); + } + lines += 1; + } + } + visitor(node); + final StringBuffer information = StringBuffer(prefixLineOne); + if (lines > 1) { + information.writeln('This ${node.name} had the following descendants (showing up to depth $maxDepth):'); + } else if (descendants.length == 1) { + information.writeln('This ${node.name} had the following child:'); + } else { + information.writeln('This ${node.name} has no descendants.'); + } + information.writeAll(descendants, '\n'); + return information.toString(); + } + final _PrefixedStringBuilder builder = _PrefixedStringBuilder( + prefixLineOne: prefixLineOne, + prefixOtherLines: prefixOtherLines, + wrapWidth: math.max(_wrapWidth, prefixOtherLines.length + _wrapWidthProperties), + ); + + List children = node.getChildren(); + + String description = node.toDescription(parentConfiguration: parentConfiguration); + if (config.beforeName.isNotEmpty) { + builder.write(config.beforeName); + } + final bool wrapName = !isSingleLine && node.allowNameWrap; + final bool wrapDescription = !isSingleLine && node.allowWrap; + final bool uppercaseTitle = node.style == DiagnosticsTreeStyle.error; + String? name = node.name; + if (uppercaseTitle) { + name = name?.toUpperCase(); + } + if (description.isEmpty) { + if (node.showName && name != null) { + builder.write(name, allowWrap: wrapName); + } + } else { + bool includeName = false; + if (name != null && name.isNotEmpty && node.showName) { + includeName = true; + builder.write(name, allowWrap: wrapName); + if (node.showSeparator) { + builder.write(config.afterName, allowWrap: wrapName); + } + + builder.write( + config.isNameOnOwnLine || description.contains('\n') ? '\n' : ' ', + allowWrap: wrapName, + ); + } + if (!isSingleLine && builder.requiresMultipleLines && !builder.isCurrentLineEmpty) { + // Make sure there is a break between the current line and next one if + // there is not one already. + builder.write('\n'); + } + if (includeName) { + builder.incrementPrefixOtherLines( + children.isEmpty ? config.propertyPrefixNoChildren : config.propertyPrefixIfChildren, + updateCurrentLine: true, + ); + } + + if (uppercaseTitle) { + description = description.toUpperCase(); + } + builder.write(description.trimRight(), allowWrap: wrapDescription); + + if (!includeName) { + builder.incrementPrefixOtherLines( + children.isEmpty ? config.propertyPrefixNoChildren : config.propertyPrefixIfChildren, + updateCurrentLine: false, + ); + } + } + if (config.suffixLineOne.isNotEmpty) { + builder.writeStretched(config.suffixLineOne, builder.wrapWidth!); + } + + final Iterable propertiesIterable = node.getProperties().where( + (DiagnosticsNode n) => !n.isFiltered(_minLevel), + ); + List properties; + if (_maxDescendentsTruncatableNode >= 0 && node.allowTruncate) { + if (propertiesIterable.length < _maxDescendentsTruncatableNode) { + properties = + propertiesIterable.take(_maxDescendentsTruncatableNode).toList(); + properties.add(DiagnosticsNode.message('...')); + } else { + properties = propertiesIterable.toList(); + } + if (_maxDescendentsTruncatableNode < children.length) { + children = children.take(_maxDescendentsTruncatableNode).toList(); + children.add(DiagnosticsNode.message('...')); + } + } else { + properties = propertiesIterable.toList(); + } + + // If the node does not show a separator and there is no description then + // we should not place a separator between the name and the value. + // Essentially in this case the properties are treated a bit like a value. + if ((properties.isNotEmpty || children.isNotEmpty || node.emptyBodyDescription != null) && + (node.showSeparator || description.isNotEmpty)) { + builder.write(config.afterDescriptionIfBody); + } + + if (config.lineBreakProperties) { + builder.write(config.lineBreak); + } + + if (properties.isNotEmpty) { + builder.write(config.beforeProperties); + } + + builder.incrementPrefixOtherLines(config.bodyIndent, updateCurrentLine: false); + + if (node.emptyBodyDescription != null && + properties.isEmpty && + children.isEmpty && + prefixLineOne.isNotEmpty) { + builder.write(node.emptyBodyDescription!); + if (config.lineBreakProperties) { + builder.write(config.lineBreak); + } + } + + for (int i = 0; i < properties.length; ++i) { + final DiagnosticsNode property = properties[i]; + if (i > 0) { + builder.write(config.propertySeparator); + } + + final TextTreeConfiguration propertyStyle = property.textTreeConfiguration!; + if (_isSingleLine(property.style)) { + // We have to treat single line properties slightly differently to deal + // with cases where a single line properties output may not have single + // linebreak. + final String propertyRender = render(property, + prefixLineOne: propertyStyle.prefixLineOne, + prefixOtherLines: '${propertyStyle.childLinkSpace}${propertyStyle.prefixOtherLines}', + parentConfiguration: config, + ); + final List propertyLines = propertyRender.split('\n'); + if (propertyLines.length == 1 && !config.lineBreakProperties) { + builder.write(propertyLines.first); + } else { + builder.write(propertyRender); + if (!propertyRender.endsWith('\n')) { + builder.write('\n'); + } + } + } else { + final String propertyRender = render(property, + prefixLineOne: '${builder.prefixOtherLines}${propertyStyle.prefixLineOne}', + prefixOtherLines: '${builder.prefixOtherLines}${propertyStyle.childLinkSpace}${propertyStyle.prefixOtherLines}', + parentConfiguration: config, + ); + builder.writeRawLines(propertyRender); + } + } + if (properties.isNotEmpty) { + builder.write(config.afterProperties); + } + + builder.write(config.mandatoryAfterProperties); + + if (!config.lineBreakProperties) { + builder.write(config.lineBreak); + } + + final String prefixChildren = config.bodyIndent; + final String prefixChildrenRaw = '$prefixOtherLines$prefixChildren'; + if (children.isEmpty && + config.addBlankLineIfNoChildren && + builder.requiresMultipleLines && + builder.prefixOtherLines!.trimRight().isNotEmpty + ) { + builder.write(config.lineBreak); + } + + if (children.isNotEmpty && config.showChildren) { + if (config.isBlankLineBetweenPropertiesAndChildren && + properties.isNotEmpty && + children.first.textTreeConfiguration!.isBlankLineBetweenPropertiesAndChildren) { + builder.write(config.lineBreak); + } + + builder.prefixOtherLines = prefixOtherLines; + + for (int i = 0; i < children.length; i++) { + final DiagnosticsNode child = children[i]; + final TextTreeConfiguration childConfig = _childTextConfiguration(child, config)!; + if (i == children.length - 1) { + final String lastChildPrefixLineOne = '$prefixChildrenRaw${childConfig.prefixLastChildLineOne}'; + final String childPrefixOtherLines = '$prefixChildrenRaw${childConfig.childLinkSpace}${childConfig.prefixOtherLines}'; + builder.writeRawLines(render( + child, + prefixLineOne: lastChildPrefixLineOne, + prefixOtherLines: childPrefixOtherLines, + parentConfiguration: config, + )); + if (childConfig.footer.isNotEmpty) { + builder.prefixOtherLines = prefixChildrenRaw; + builder.write('${childConfig.childLinkSpace}${childConfig.footer}'); + if (childConfig.mandatoryFooter.isNotEmpty) { + builder.writeStretched( + childConfig.mandatoryFooter, + math.max(builder.wrapWidth!, _wrapWidthProperties + childPrefixOtherLines.length), + ); + } + builder.write(config.lineBreak); + } + } else { + final TextTreeConfiguration nextChildStyle = _childTextConfiguration(children[i + 1], config)!; + final String childPrefixLineOne = '$prefixChildrenRaw${childConfig.prefixLineOne}'; + final String childPrefixOtherLines ='$prefixChildrenRaw${nextChildStyle.linkCharacter}${childConfig.prefixOtherLines}'; + builder.writeRawLines(render( + child, + prefixLineOne: childPrefixLineOne, + prefixOtherLines: childPrefixOtherLines, + parentConfiguration: config, + )); + if (childConfig.footer.isNotEmpty) { + builder.prefixOtherLines = prefixChildrenRaw; + builder.write('${childConfig.linkCharacter}${childConfig.footer}'); + if (childConfig.mandatoryFooter.isNotEmpty) { + builder.writeStretched( + childConfig.mandatoryFooter, + math.max(builder.wrapWidth!, _wrapWidthProperties + childPrefixOtherLines.length), + ); + } + builder.write(config.lineBreak); + } + } + } + } + if (parentConfiguration == null && config.mandatoryFooter.isNotEmpty) { + builder.writeStretched(config.mandatoryFooter, builder.wrapWidth!); + builder.write(config.lineBreak); + } + return builder.build(); + } +} + +/// Defines diagnostics data for a [value]. +/// +/// For debug and profile modes, [DiagnosticsNode] provides a high quality +/// multiline string dump via [toStringDeep]. The core members are the [name], +/// [toDescription], [getProperties], [value], and [getChildren]. All other +/// members exist typically to provide hints for how [toStringDeep] and +/// debugging tools should format output. +/// +/// In release mode, far less information is retained and some information may +/// not print at all. +abstract class DiagnosticsNode { + /// Initializes the object. + /// + /// The [style], [showName], and [showSeparator] arguments must not + /// be null. + DiagnosticsNode({ + required this.name, + this.style, + this.showName = true, + this.showSeparator = true, + this.linePrefix, + }) : assert( + // A name ending with ':' indicates that the user forgot that the ':' will + // be automatically added for them when generating descriptions of the + // property. + name == null || !name.endsWith(':'), + 'Names of diagnostic nodes must not end with colons.\n' + 'name:\n' + ' "$name"', + ); + + /// Diagnostics containing just a string `message` and not a concrete name or + /// value. + /// + /// See also: + /// + /// * [MessageProperty], which is better suited to messages that are to be + /// formatted like a property with a separate name and message. + factory DiagnosticsNode.message( + String message, { + DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine, + DiagnosticLevel level = DiagnosticLevel.info, + bool allowWrap = true, + }) { + return DiagnosticsProperty( + '', + null, + description: message, + style: style, + showName: false, + allowWrap: allowWrap, + level: level, + ); + } + + /// Label describing the [DiagnosticsNode], typically shown before a separator + /// (see [showSeparator]). + /// + /// The name will be omitted if the [showName] property is false. + final String? name; + + /// Returns a description with a short summary of the node itself not + /// including children or properties. + /// + /// `parentConfiguration` specifies how the parent is rendered as text art. + /// For example, if the parent does not line break between properties, the + /// description of a property should also be a single line if possible. + String toDescription({ TextTreeConfiguration? parentConfiguration }); + + /// Whether to show a separator between [name] and description. + /// + /// If false, name and description should be shown with no separation. + /// `:` is typically used as a separator when displaying as text. + final bool showSeparator; + + /// Whether the diagnostic should be filtered due to its [level] being lower + /// than `minLevel`. + /// + /// If `minLevel` is [DiagnosticLevel.hidden] no diagnostics will be filtered. + /// If `minLevel` is [DiagnosticLevel.off] all diagnostics will be filtered. + bool isFiltered(DiagnosticLevel minLevel) => kReleaseMode || level.index < minLevel.index; + + /// Priority level of the diagnostic used to control which diagnostics should + /// be shown and filtered. + /// + /// Typically this only makes sense to set to a different value than + /// [DiagnosticLevel.info] for diagnostics representing properties. Some + /// subclasses have a [level] argument to their constructor which influences + /// the value returned here but other factors also influence it. For example, + /// whether an exception is thrown computing a property value + /// [DiagnosticLevel.error] is returned. + DiagnosticLevel get level => kReleaseMode ? DiagnosticLevel.hidden : DiagnosticLevel.info; + + /// Whether the name of the property should be shown when showing the default + /// view of the tree. + /// + /// This could be set to false (hiding the name) if the value's description + /// will make the name self-evident. + final bool showName; + + /// Prefix to include at the start of each line. + final String? linePrefix; + + /// Description to show if the node has no displayed properties or children. + String? get emptyBodyDescription => null; + + /// The actual object this is diagnostics data for. + Object? get value; + + /// Hint for how the node should be displayed. + final DiagnosticsTreeStyle? style; + + /// Whether to wrap text on onto multiple lines or not. + bool get allowWrap => false; + + /// Whether to wrap the name onto multiple lines or not. + bool get allowNameWrap => false; + + /// Whether to allow truncation when displaying the node and its children. + bool get allowTruncate => false; + + /// Properties of this [DiagnosticsNode]. + /// + /// Properties and children are kept distinct even though they are both + /// [List] because they should be grouped differently. + List getProperties(); + + /// Children of this [DiagnosticsNode]. + /// + /// See also: + /// + /// * [getProperties], which returns the properties of the [DiagnosticsNode] + /// object. + List getChildren(); + + String get _separator => showSeparator ? ':' : ''; + + /// Converts the properties ([getProperties]) of this node to a form useful + /// for [Timeline] event arguments (as in [Timeline.startSync]). + /// + /// Children ([getChildren]) are omitted. + /// + /// This method is only valid in debug builds. In profile builds, this method + /// throws an exception. In release builds it returns null. + /// + /// See also: + /// + /// * [toJsonMap], which converts this node to a structured form intended for + /// data exchange (e.g. with an IDE). + Map? toTimelineArguments() { + if (!kReleaseMode) { + // We don't throw in release builds, to avoid hurting users. We also don't do anything useful. + if (kProfileMode) { + throw FlutterError( + // Parts of this string are searched for verbatim by a test in dev/bots/test.dart. + '$DiagnosticsNode.toTimelineArguments used in non-debug build.\n' + 'The $DiagnosticsNode.toTimelineArguments API is expensive and causes timeline traces ' + 'to be non-representative. As such, it should not be used in profile builds. However, ' + 'this application is compiled in profile mode and yet still invoked the method.' + ); + } + final Map result = {}; + for (final DiagnosticsNode property in getProperties()) { + if (property.name != null) { + result[property.name!] = property.toDescription(parentConfiguration: singleLineTextConfiguration); + } + } + return result; + } + return null; + } + + /// Serialize the node to a JSON map according to the configuration provided + /// in the [DiagnosticsSerializationDelegate]. + /// + /// Subclasses should override if they have additional properties that are + /// useful for the GUI tools that consume this JSON. + /// + /// See also: + /// + /// * [WidgetInspectorService], which forms the bridge between JSON returned + /// by this method and interactive tree views in the Flutter IntelliJ + /// plugin. + @mustCallSuper + Map toJsonMap(DiagnosticsSerializationDelegate delegate) { + Map result = {}; + assert(() { + final bool hasChildren = getChildren().isNotEmpty; + result = { + 'description': toDescription(), + 'type': runtimeType.toString(), + if (name != null) + 'name': name, + if (!showSeparator) + 'showSeparator': showSeparator, + if (level != DiagnosticLevel.info) + 'level': level.name, + if (!showName) + 'showName': showName, + if (emptyBodyDescription != null) + 'emptyBodyDescription': emptyBodyDescription, + if (style != DiagnosticsTreeStyle.sparse) + 'style': style!.name, + if (allowTruncate) + 'allowTruncate': allowTruncate, + if (hasChildren) + 'hasChildren': hasChildren, + if (linePrefix?.isNotEmpty ?? false) + 'linePrefix': linePrefix, + if (!allowWrap) + 'allowWrap': allowWrap, + if (allowNameWrap) + 'allowNameWrap': allowNameWrap, + ...delegate.additionalNodeProperties(this), + if (delegate.includeProperties) + 'properties': toJsonList( + delegate.filterProperties(getProperties(), this), + this, + delegate, + ), + if (delegate.subtreeDepth > 0) + 'children': toJsonList( + delegate.filterChildren(getChildren(), this), + this, + delegate, + ), + }; + return true; + }()); + return result; + } + + /// Serializes a [List] of [DiagnosticsNode]s to a JSON list according to + /// the configuration provided by the [DiagnosticsSerializationDelegate]. + /// + /// The provided `nodes` may be properties or children of the `parent` + /// [DiagnosticsNode]. + static List> toJsonList( + List? nodes, + DiagnosticsNode? parent, + DiagnosticsSerializationDelegate delegate, + ) { + bool truncated = false; + if (nodes == null) { + return const >[]; + } + final int originalNodeCount = nodes.length; + nodes = delegate.truncateNodesList(nodes, parent); + if (nodes.length != originalNodeCount) { + nodes.add(DiagnosticsNode.message('...')); + truncated = true; + } + final List> json = nodes.map>((DiagnosticsNode node) { + return node.toJsonMap(delegate.delegateForNode(node)); + }).toList(); + if (truncated) { + json.last['truncated'] = true; + } + return json; + } + + /// Returns a string representation of this diagnostic that is compatible with + /// the style of the parent if the node is not the root. + /// + /// `parentConfiguration` specifies how the parent is rendered as text art. + /// For example, if the parent places all properties on one line, the + /// [toString] for each property should avoid line breaks if possible. + /// + /// `minLevel` specifies the minimum [DiagnosticLevel] for properties included + /// in the output. + /// + /// In release mode, far less information is retained and some information may + /// not print at all. + @override + String toString({ + TextTreeConfiguration? parentConfiguration, + DiagnosticLevel minLevel = DiagnosticLevel.info, + }) { + String result = super.toString(); + assert(style != null); + assert(() { + if (_isSingleLine(style)) { + result = toStringDeep(parentConfiguration: parentConfiguration, minLevel: minLevel); + } else { + final String description = toDescription(parentConfiguration: parentConfiguration); + + if (name == null || name!.isEmpty || !showName) { + result = description; + } else { + result = description.contains('\n') ? '$name$_separator\n$description' + : '$name$_separator $description'; + } + } + return true; + }()); + return result; + } + + /// Returns a configuration specifying how this object should be rendered + /// as text art. + @protected + TextTreeConfiguration? get textTreeConfiguration { + assert(style != null); + switch (style!) { + case DiagnosticsTreeStyle.none: + return null; + case DiagnosticsTreeStyle.dense: + return denseTextConfiguration; + case DiagnosticsTreeStyle.sparse: + return sparseTextConfiguration; + case DiagnosticsTreeStyle.offstage: + return dashedTextConfiguration; + case DiagnosticsTreeStyle.whitespace: + return whitespaceTextConfiguration; + case DiagnosticsTreeStyle.transition: + return transitionTextConfiguration; + case DiagnosticsTreeStyle.singleLine: + return singleLineTextConfiguration; + case DiagnosticsTreeStyle.errorProperty: + return errorPropertyTextConfiguration; + case DiagnosticsTreeStyle.shallow: + return shallowTextConfiguration; + case DiagnosticsTreeStyle.error: + return errorTextConfiguration; + case DiagnosticsTreeStyle.truncateChildren: + // Truncate children doesn't really need its own text style as the + // rendering is quite custom. + return whitespaceTextConfiguration; + case DiagnosticsTreeStyle.flat: + return flatTextConfiguration; + } + } + + /// Returns a string representation of this node and its descendants. + /// + /// `prefixLineOne` will be added to the front of the first line of the + /// output. `prefixOtherLines` will be added to the front of each other line. + /// If `prefixOtherLines` is null, the `prefixLineOne` is used for every line. + /// By default, there is no prefix. + /// + /// `minLevel` specifies the minimum [DiagnosticLevel] for properties included + /// in the output. + /// + /// The [toStringDeep] method takes other arguments, but those are intended + /// for internal use when recursing to the descendants, and so can be ignored. + /// + /// In release mode, far less information is retained and some information may + /// not print at all. + /// + /// See also: + /// + /// * [toString], for a brief description of the [value] but not its + /// children. + String toStringDeep({ + String prefixLineOne = '', + String? prefixOtherLines, + TextTreeConfiguration? parentConfiguration, + DiagnosticLevel minLevel = DiagnosticLevel.debug, + }) { + String result = ''; + assert(() { + result = TextTreeRenderer( + minLevel: minLevel, + wrapWidth: 65, + ).render( + this, + prefixLineOne: prefixLineOne, + prefixOtherLines: prefixOtherLines, + parentConfiguration: parentConfiguration, + ); + return true; + }()); + return result; + } +} + +/// Debugging message displayed like a property. +/// +/// {@tool snippet} +/// +/// The following two properties are better expressed using this +/// [MessageProperty] class, rather than [StringProperty], as the intent is to +/// show a message with property style display rather than to describe the value +/// of an actual property of the object: +/// +/// ```dart +/// MessageProperty table = MessageProperty('table size', '$columns\u00D7$rows'); +/// MessageProperty usefulness = MessageProperty('usefulness ratio', 'no metrics collected yet (never painted)'); +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// On the other hand, [StringProperty] is better suited when the property has a +/// concrete value that is a string: +/// +/// ```dart +/// StringProperty name = StringProperty('name', _name); +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [DiagnosticsNode.message], which serves the same role for messages +/// without a clear property name. +/// * [StringProperty], which is a better fit for properties with string values. +class MessageProperty extends DiagnosticsProperty { + /// Create a diagnostics property that displays a message. + /// + /// Messages have no concrete [value] (so [value] will return null). The + /// message is stored as the description. + MessageProperty( + String name, + String message, { + DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine, + DiagnosticLevel level = DiagnosticLevel.info, + }) : super(name, null, description: message, style: style, level: level); +} + +/// Property which encloses its string [value] in quotes. +/// +/// See also: +/// +/// * [MessageProperty], which is a better fit for showing a message +/// instead of describing a property with a string value. +class StringProperty extends DiagnosticsProperty { + /// Create a diagnostics property for strings. + StringProperty( + String super.name, + super.value, { + super.description, + super.tooltip, + super.showName, + super.defaultValue, + this.quoted = true, + super.ifEmpty, + super.style, + super.level, + }); + + /// Whether the value is enclosed in double quotes. + final bool quoted; + + @override + Map toJsonMap(DiagnosticsSerializationDelegate delegate) { + final Map json = super.toJsonMap(delegate); + json['quoted'] = quoted; + return json; + } + + @override + String valueToString({ TextTreeConfiguration? parentConfiguration }) { + String? text = _description ?? value; + if (parentConfiguration != null && + !parentConfiguration.lineBreakProperties && + text != null) { + // Escape linebreaks in multiline strings to avoid confusing output when + // the parent of this node is trying to display all properties on the same + // line. + text = text.replaceAll('\n', r'\n'); + } + + if (quoted && text != null) { + // An empty value would not appear empty after being surrounded with + // quotes so we have to handle this case separately. + if (ifEmpty != null && text.isEmpty) { + return ifEmpty!; + } + return '"$text"'; + } + return text.toString(); + } +} + +abstract class _NumProperty extends DiagnosticsProperty { + _NumProperty( + String super.name, + super.value, { + super.ifNull, + this.unit, + super.showName, + super.defaultValue, + super.tooltip, + super.style, + super.level, + }); + + _NumProperty.lazy( + String super.name, + super.computeValue, { + super.ifNull, + this.unit, + super.showName, + super.defaultValue, + super.tooltip, + super.style, + super.level, + }) : super.lazy(); + + @override + Map toJsonMap(DiagnosticsSerializationDelegate delegate) { + final Map json = super.toJsonMap(delegate); + if (unit != null) { + json['unit'] = unit; + } + + json['numberToString'] = numberToString(); + return json; + } + + /// Optional unit the [value] is measured in. + /// + /// Unit must be acceptable to display immediately after a number with no + /// spaces. For example: 'physical pixels per logical pixel' should be a + /// [tooltip] not a [unit]. + final String? unit; + + /// String describing just the numeric [value] without a unit suffix. + String numberToString(); + + @override + String valueToString({ TextTreeConfiguration? parentConfiguration }) { + if (value == null) { + return value.toString(); + } + + return unit != null ? '${numberToString()}$unit' : numberToString(); + } +} +/// Property describing a [double] [value] with an optional [unit] of measurement. +/// +/// Numeric formatting is optimized for debug message readability. +class DoubleProperty extends _NumProperty { + /// If specified, [unit] describes the unit for the [value] (e.g. px). + DoubleProperty( + super.name, + super.value, { + super.ifNull, + super.unit, + super.tooltip, + super.defaultValue, + super.showName, + super.style, + super.level, + }); + + /// Property with a [value] that is computed only when needed. + /// + /// Use if computing the property [value] may throw an exception or is + /// expensive. + DoubleProperty.lazy( + super.name, + super.computeValue, { + super.ifNull, + super.showName, + super.unit, + super.tooltip, + super.defaultValue, + super.level, + }) : super.lazy(); + + @override + String numberToString() => debugFormatDouble(value); +} + +/// An int valued property with an optional unit the value is measured in. +/// +/// Examples of units include 'px' and 'ms'. +class IntProperty extends _NumProperty { + /// Create a diagnostics property for integers. + IntProperty( + super.name, + super.value, { + super.ifNull, + super.showName, + super.unit, + super.defaultValue, + super.style, + super.level, + }); + + @override + String numberToString() => value.toString(); +} + +/// Property which clamps a [double] to between 0 and 1 and formats it as a +/// percentage. +class PercentProperty extends DoubleProperty { + /// Create a diagnostics property for doubles that represent percentages or + /// fractions. + /// + /// Setting [showName] to false is often reasonable for [PercentProperty] + /// objects, as the fact that the property is shown as a percentage tends to + /// be sufficient to disambiguate its meaning. + PercentProperty( + super.name, + super.fraction, { + super.ifNull, + super.showName, + super.tooltip, + super.unit, + super.level, + }); + + @override + String valueToString({ TextTreeConfiguration? parentConfiguration }) { + if (value == null) { + return value.toString(); + } + return unit != null ? '${numberToString()} $unit' : numberToString(); + } + + @override + String numberToString() { + final double? v = value; + if (v == null) { + return value.toString(); + } + return '${(clampDouble(v, 0.0, 1.0) * 100.0).toStringAsFixed(1)}%'; + } +} + +/// Property where the description is either [ifTrue] or [ifFalse] depending on +/// whether [value] is true or false. +/// +/// Using [FlagProperty] instead of [DiagnosticsProperty] can make +/// diagnostics display more polished. For example, given a property named +/// `visible` that is typically true, the following code will return 'hidden' +/// when `visible` is false and nothing when visible is true, in contrast to +/// `visible: true` or `visible: false`. +/// +/// {@tool snippet} +/// +/// ```dart +/// FlagProperty( +/// 'visible', +/// value: true, +/// ifFalse: 'hidden', +/// ) +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// [FlagProperty] should also be used instead of [DiagnosticsProperty] +/// if showing the bool value would not clearly indicate the meaning of the +/// property value. +/// +/// ```dart +/// FlagProperty( +/// 'inherit', +/// value: inherit, +/// ifTrue: '', +/// ifFalse: '', +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [ObjectFlagProperty], which provides similar behavior describing whether +/// a [value] is null. +class FlagProperty extends DiagnosticsProperty { + /// Constructs a FlagProperty with the given descriptions with the specified descriptions. + /// + /// [showName] defaults to false as typically [ifTrue] and [ifFalse] should + /// be descriptions that make the property name redundant. + FlagProperty( + String name, { + required bool? value, + this.ifTrue, + this.ifFalse, + bool showName = false, + Object? defaultValue, + DiagnosticLevel level = DiagnosticLevel.info, + }) : assert(ifTrue != null || ifFalse != null), + super( + name, + value, + showName: showName, + defaultValue: defaultValue, + level: level, + ); + + @override + Map toJsonMap(DiagnosticsSerializationDelegate delegate) { + final Map json = super.toJsonMap(delegate); + if (ifTrue != null) { + json['ifTrue'] = ifTrue; + } + if (ifFalse != null) { + json['ifFalse'] = ifFalse; + } + + return json; + } + + /// Description to use if the property [value] is true. + /// + /// If not specified and [value] equals true the property's priority [level] + /// will be [DiagnosticLevel.hidden]. + final String? ifTrue; + + /// Description to use if the property value is false. + /// + /// If not specified and [value] equals false, the property's priority [level] + /// will be [DiagnosticLevel.hidden]. + final String? ifFalse; + + @override + String valueToString({ TextTreeConfiguration? parentConfiguration }) { + if (value ?? false) { + if (ifTrue != null) { + return ifTrue!; + } + } else if (value == false) { + if (ifFalse != null) { + return ifFalse!; + } + } + return super.valueToString(parentConfiguration: parentConfiguration); + } + + @override + bool get showName { + if (value == null || ((value ?? false) && ifTrue == null) || (!(value ?? true) && ifFalse == null)) { + // We are missing a description for the flag value so we need to show the + // flag name. The property will have DiagnosticLevel.hidden for this case + // so users will not see this property in this case unless they are + // displaying hidden properties. + return true; + } + return super.showName; + } + + @override + DiagnosticLevel get level { + if (value ?? false) { + if (ifTrue == null) { + return DiagnosticLevel.hidden; + } + } + if (value == false) { + if (ifFalse == null) { + return DiagnosticLevel.hidden; + } + } + return super.level; + } +} + +/// Property with an `Iterable` [value] that can be displayed with +/// different [DiagnosticsTreeStyle] for custom rendering. +/// +/// If [style] is [DiagnosticsTreeStyle.singleLine], the iterable is described +/// as a comma separated list, otherwise the iterable is described as a line +/// break separated list. +class IterableProperty extends DiagnosticsProperty> { + /// Create a diagnostics property for iterables (e.g. lists). + /// + /// The [ifEmpty] argument is used to indicate how an iterable [value] with 0 + /// elements is displayed. If [ifEmpty] equals null that indicates that an + /// empty iterable [value] is not interesting to display similar to how + /// [defaultValue] is used to indicate that a specific concrete value is not + /// interesting to display. + IterableProperty( + String super.name, + super.value, { + super.defaultValue, + super.ifNull, + super.ifEmpty = '[]', + super.style, + super.showName, + super.showSeparator, + super.level, + }); + + @override + String valueToString({TextTreeConfiguration? parentConfiguration}) { + if (value == null) { + return value.toString(); + } + + if (value!.isEmpty) { + return ifEmpty ?? '[]'; + } + + final Iterable formattedValues = value!.map((T v) { + if (T == double && v is double) { + return debugFormatDouble(v); + } else { + return v.toString(); + } + }); + + if (parentConfiguration != null && !parentConfiguration.lineBreakProperties) { + // Always display the value as a single line and enclose the iterable + // value in brackets to avoid ambiguity. + return '[${formattedValues.join(', ')}]'; + } + + return formattedValues.join(_isSingleLine(style) ? ', ' : '\n'); + } + + /// Priority level of the diagnostic used to control which diagnostics should + /// be shown and filtered. + /// + /// If [ifEmpty] is null and the [value] is an empty [Iterable] then level + /// [DiagnosticLevel.fine] is returned in a similar way to how an + /// [ObjectFlagProperty] handles when [ifNull] is null and the [value] is + /// null. + @override + DiagnosticLevel get level { + if (ifEmpty == null && value != null && value!.isEmpty && super.level != DiagnosticLevel.hidden) { + return DiagnosticLevel.fine; + } + return super.level; + } + + @override + Map toJsonMap(DiagnosticsSerializationDelegate delegate) { + final Map json = super.toJsonMap(delegate); + if (value != null) { + json['values'] = value!.map((T value) => value.toString()).toList(); + } + return json; + } +} + +/// [DiagnosticsProperty] that has an [Enum] as value. +/// +/// The enum value is displayed with the enum name stripped. For example: +/// [HitTestBehavior.deferToChild] is shown as `deferToChild`. +/// +/// This class can be used with enums and returns the enum's name getter. It +/// can also be used with nullable properties; the null value is represented as +/// `null`. +/// +/// See also: +/// +/// * [DiagnosticsProperty] which documents named parameters common to all +/// [DiagnosticsProperty]. +class EnumProperty extends DiagnosticsProperty { + /// Create a diagnostics property that displays an enum. + /// + /// The [level] argument must also not be null. + EnumProperty( + String super.name, + super.value, { + super.defaultValue, + super.level, + }); + + @override + String valueToString({ TextTreeConfiguration? parentConfiguration }) { + if (value == null) { + return value.toString(); + } + return value!.name; + } +} + +/// A property where the important diagnostic information is primarily whether +/// the [value] is present (non-null) or absent (null), rather than the actual +/// value of the property itself. +/// +/// The [ifPresent] and [ifNull] strings describe the property [value] when it +/// is non-null and null respectively. If one of [ifPresent] or [ifNull] is +/// omitted, that is taken to mean that [level] should be +/// [DiagnosticLevel.hidden] when [value] is non-null or null respectively. +/// +/// This kind of diagnostics property is typically used for opaque +/// values, like closures, where presenting the actual object is of dubious +/// value but where reporting the presence or absence of the value is much more +/// useful. +/// +/// See also: +/// +/// +/// * [FlagsSummary], which provides similar functionality but accepts multiple +/// flags under the same name, and is preferred if there are multiple such +/// values that can fit into a same category (such as "listeners"). +/// * [FlagProperty], which provides similar functionality describing whether +/// a [value] is true or false. +class ObjectFlagProperty extends DiagnosticsProperty { + /// Create a diagnostics property for values that can be present (non-null) or + /// absent (null), but for which the exact value's [Object.toString] + /// representation is not very transparent (e.g. a callback). + /// + /// At least one of [ifPresent] or [ifNull] must be non-null. + ObjectFlagProperty( + String super.name, + super.value, { + this.ifPresent, + super.ifNull, + super.showName = false, + super.level, + }) : assert(ifPresent != null || ifNull != null); + + /// Shorthand constructor to describe whether the property has a value. + /// + /// Only use if prefixing the property name with the word 'has' is a good + /// flag name. + ObjectFlagProperty.has( + String super.name, + super.value, { + super.level, + }) : ifPresent = 'has $name', + super( + showName: false, + ); + + /// Description to use if the property [value] is not null. + /// + /// If the property [value] is not null and [ifPresent] is null, the + /// [level] for the property is [DiagnosticLevel.hidden] and the description + /// from superclass is used. + final String? ifPresent; + + @override + String valueToString({ TextTreeConfiguration? parentConfiguration }) { + if (value != null) { + if (ifPresent != null) { + return ifPresent!; + } + } else { + if (ifNull != null) { + return ifNull!; + } + } + return super.valueToString(parentConfiguration: parentConfiguration); + } + + @override + bool get showName { + if ((value != null && ifPresent == null) || (value == null && ifNull == null)) { + // We are missing a description for the flag value so we need to show the + // flag name. The property will have DiagnosticLevel.hidden for this case + // so users will not see this property in this case unless they are + // displaying hidden properties. + return true; + } + return super.showName; + } + + @override + DiagnosticLevel get level { + if (value != null) { + if (ifPresent == null) { + return DiagnosticLevel.hidden; + } + } else { + if (ifNull == null) { + return DiagnosticLevel.hidden; + } + } + + return super.level; + } + + @override + Map toJsonMap(DiagnosticsSerializationDelegate delegate) { + final Map json = super.toJsonMap(delegate); + if (ifPresent != null) { + json['ifPresent'] = ifPresent; + } + return json; + } +} + +/// A summary of multiple properties, indicating whether each of them is present +/// (non-null) or absent (null). +/// +/// Each entry of [value] is described by its key. The eventual description will +/// be a list of keys of non-null entries. +/// +/// The [ifEmpty] describes the entire collection of [value] when it contains no +/// non-null entries. If [ifEmpty] is omitted, [level] will be +/// [DiagnosticLevel.hidden] when [value] contains no non-null entries. +/// +/// This kind of diagnostics property is typically used for opaque +/// values, like closures, where presenting the actual object is of dubious +/// value but where reporting the presence or absence of the value is much more +/// useful. +/// +/// See also: +/// +/// * [ObjectFlagProperty], which provides similar functionality but accepts +/// only one flag, and is preferred if there is only one entry. +/// * [IterableProperty], which provides similar functionality describing +/// the values a collection of objects. +class FlagsSummary extends DiagnosticsProperty> { + /// Create a summary for multiple properties, indicating whether each of them + /// is present (non-null) or absent (null). + /// + /// The [value], [showName], [showSeparator] and [level] arguments must not be + /// null. + FlagsSummary( + String super.name, + Map super.value, { + super.ifEmpty, + super.showName, + super.showSeparator, + super.level, + }); + + @override + Map get value => super.value!; + + @override + String valueToString({TextTreeConfiguration? parentConfiguration}) { + if (!_hasNonNullEntry() && ifEmpty != null) { + return ifEmpty!; + } + + final Iterable formattedValues = _formattedValues(); + if (parentConfiguration != null && !parentConfiguration.lineBreakProperties) { + // Always display the value as a single line and enclose the iterable + // value in brackets to avoid ambiguity. + return '[${formattedValues.join(', ')}]'; + } + + return formattedValues.join(_isSingleLine(style) ? ', ' : '\n'); + } + + /// Priority level of the diagnostic used to control which diagnostics should + /// be shown and filtered. + /// + /// If [ifEmpty] is null and the [value] contains no non-null entries, then + /// level [DiagnosticLevel.hidden] is returned. + @override + DiagnosticLevel get level { + if (!_hasNonNullEntry() && ifEmpty == null) { + return DiagnosticLevel.hidden; + } + return super.level; + } + + @override + Map toJsonMap(DiagnosticsSerializationDelegate delegate) { + final Map json = super.toJsonMap(delegate); + if (value.isNotEmpty) { + json['values'] = _formattedValues().toList(); + } + return json; + } + + bool _hasNonNullEntry() => value.values.any((T? o) => o != null); + + // An iterable of each entry's description in [value]. + // + // For a non-null value, its description is its key. + // + // For a null value, it is omitted unless `includeEmpty` is true and + // [ifEntryNull] contains a corresponding description. + Iterable _formattedValues() { + return value.entries + .where((MapEntry entry) => entry.value != null) + .map((MapEntry entry) => entry.key); + } +} + +/// Signature for computing the value of a property. +/// +/// May throw exception if accessing the property would throw an exception +/// and callers must handle that case gracefully. For example, accessing a +/// property may trigger an assert that layout constraints were violated. +typedef ComputePropertyValueCallback = T? Function(); + +/// Property with a [value] of type [T]. +/// +/// If the default `value.toString()` does not provide an adequate description +/// of the value, specify `description` defining a custom description. +/// +/// The [showSeparator] property indicates whether a separator should be placed +/// between the property [name] and its [value]. +class DiagnosticsProperty extends DiagnosticsNode { + /// Create a diagnostics property. + /// + /// The [level] argument is just a suggestion and can be overridden if + /// something else about the property causes it to have a lower or higher + /// level. For example, if the property value is null and [missingIfNull] is + /// true, [level] is raised to [DiagnosticLevel.warning]. + DiagnosticsProperty( + String? name, + T? value, { + String? description, + String? ifNull, + this.ifEmpty, + super.showName, + super.showSeparator, + this.defaultValue = kNoDefaultValue, + this.tooltip, + this.missingIfNull = false, + super.linePrefix, + this.expandableValue = false, + this.allowWrap = true, + this.allowNameWrap = true, + DiagnosticsTreeStyle super.style = DiagnosticsTreeStyle.singleLine, + DiagnosticLevel level = DiagnosticLevel.info, + }) : _description = description, + _valueComputed = true, + _value = value, + _computeValue = null, + ifNull = ifNull ?? (missingIfNull ? 'MISSING' : null), + _defaultLevel = level, + super( + name: name, + ); + + /// Property with a [value] that is computed only when needed. + /// + /// Use if computing the property [value] may throw an exception or is + /// expensive. + /// + /// The [level] argument is just a suggestion and can be overridden + /// if something else about the property causes it to have a lower or higher + /// level. For example, if calling `computeValue` throws an exception, [level] + /// will always return [DiagnosticLevel.error]. + DiagnosticsProperty.lazy( + String? name, + ComputePropertyValueCallback computeValue, { + String? description, + String? ifNull, + this.ifEmpty, + super.showName, + super.showSeparator, + this.defaultValue = kNoDefaultValue, + this.tooltip, + this.missingIfNull = false, + this.expandableValue = false, + this.allowWrap = true, + this.allowNameWrap = true, + DiagnosticsTreeStyle super.style = DiagnosticsTreeStyle.singleLine, + DiagnosticLevel level = DiagnosticLevel.info, + }) : assert(defaultValue == kNoDefaultValue || defaultValue is T?), + _description = description, + _valueComputed = false, + _value = null, + _computeValue = computeValue, + _defaultLevel = level, + ifNull = ifNull ?? (missingIfNull ? 'MISSING' : null), + super( + name: name, + ); + + final String? _description; + + /// Whether to expose properties and children of the value as properties and + /// children. + final bool expandableValue; + + @override + final bool allowWrap; + + @override + final bool allowNameWrap; + + @override + Map toJsonMap(DiagnosticsSerializationDelegate delegate) { + final T? v = value; + List>? properties; + if (delegate.expandPropertyValues && delegate.includeProperties && v is Diagnosticable && getProperties().isEmpty) { + // Exclude children for expanded nodes to avoid cycles. + delegate = delegate.copyWith(subtreeDepth: 0, includeProperties: false); + properties = DiagnosticsNode.toJsonList( + delegate.filterProperties(v.toDiagnosticsNode().getProperties(), this), + this, + delegate, + ); + } + final Map json = super.toJsonMap(delegate); + if (properties != null) { + json['properties'] = properties; + } + if (defaultValue != kNoDefaultValue) { + json['defaultValue'] = defaultValue.toString(); + } + if (ifEmpty != null) { + json['ifEmpty'] = ifEmpty; + } + if (ifNull != null) { + json['ifNull'] = ifNull; + } + if (tooltip != null) { + json['tooltip'] = tooltip; + } + json['missingIfNull'] = missingIfNull; + if (exception != null) { + json['exception'] = exception.toString(); + } + json['propertyType'] = propertyType.toString(); + json['defaultLevel'] = _defaultLevel.name; + if (value is Diagnosticable || value is DiagnosticsNode) { + json['isDiagnosticableValue'] = true; + } + if (v is num) { + // TODO(jacob314): Workaround, since JSON.stringify replaces infinity and NaN with null, + // https://github.com/flutter/flutter/issues/39937#issuecomment-529558033) + json['value'] = v.isFinite ? v : v.toString(); + } + if (value is String || value is bool || value == null) { + json['value'] = value; + } + return json; + } + + /// Returns a string representation of the property value. + /// + /// Subclasses should override this method instead of [toDescription] to + /// customize how property values are converted to strings. + /// + /// Overriding this method ensures that behavior controlling how property + /// values are decorated to generate a nice [toDescription] are consistent + /// across all implementations. Debugging tools may also choose to use + /// [valueToString] directly instead of [toDescription]. + /// + /// `parentConfiguration` specifies how the parent is rendered as text art. + /// For example, if the parent places all properties on one line, the value + /// of the property should be displayed without line breaks if possible. + String valueToString({ TextTreeConfiguration? parentConfiguration }) { + final T? v = value; + // DiagnosticableTree values are shown using the shorter toStringShort() + // instead of the longer toString() because the toString() for a + // DiagnosticableTree value is likely too large to be useful. + return v is DiagnosticableTree ? v.toStringShort() : v.toString(); + } + + @override + String toDescription({ TextTreeConfiguration? parentConfiguration }) { + if (_description != null) { + return _addTooltip(_description); + } + + if (exception != null) { + return 'EXCEPTION (${exception.runtimeType})'; + } + + if (ifNull != null && value == null) { + return _addTooltip(ifNull!); + } + + String result = valueToString(parentConfiguration: parentConfiguration); + if (result.isEmpty && ifEmpty != null) { + result = ifEmpty!; + } + return _addTooltip(result); + } + + /// If a [tooltip] is specified, add the tooltip it to the end of `text` + /// enclosing it parenthesis to disambiguate the tooltip from the rest of + /// the text. + String _addTooltip(String text) { + return tooltip == null ? text : '$text ($tooltip)'; + } + + /// Description if the property [value] is null. + final String? ifNull; + + /// Description if the property description would otherwise be empty. + final String? ifEmpty; + + /// Optional tooltip typically describing the property. + /// + /// Example tooltip: 'physical pixels per logical pixel' + /// + /// If present, the tooltip is added in parenthesis after the raw value when + /// generating the string description. + final String? tooltip; + + /// Whether a [value] of null causes the property to have [level] + /// [DiagnosticLevel.warning] warning that the property is missing a [value]. + final bool missingIfNull; + + /// The type of the property [value]. + /// + /// This is determined from the type argument `T` used to instantiate the + /// [DiagnosticsProperty] class. This means that the type is available even if + /// [value] is null, but it also means that the [propertyType] is only as + /// accurate as the type provided when invoking the constructor. + /// + /// Generally, this is only useful for diagnostic tools that should display + /// null values in a manner consistent with the property type. For example, a + /// tool might display a null [Color] value as an empty rectangle instead of + /// the word "null". + Type get propertyType => T; + + /// Returns the value of the property either from cache or by invoking a + /// [ComputePropertyValueCallback]. + /// + /// If an exception is thrown invoking the [ComputePropertyValueCallback], + /// [value] returns null and the exception thrown can be found via the + /// [exception] property. + /// + /// See also: + /// + /// * [valueToString], which converts the property value to a string. + @override + T? get value { + _maybeCacheValue(); + return _value; + } + + T? _value; + + bool _valueComputed; + + Object? _exception; + + /// Exception thrown if accessing the property [value] threw an exception. + /// + /// Returns null if computing the property value did not throw an exception. + Object? get exception { + _maybeCacheValue(); + return _exception; + } + + void _maybeCacheValue() { + if (_valueComputed) { + return; + } + + _valueComputed = true; + assert(_computeValue != null); + try { + _value = _computeValue!(); + } catch (exception) { + // The error is reported to inspector; rethrowing would destroy the + // debugging experience. + _exception = exception; + _value = null; + } + } + + /// The default value of this property, when it has not been set to a specific + /// value. + /// + /// For most [DiagnosticsProperty] classes, if the [value] of the property + /// equals [defaultValue], then the priority [level] of the property is + /// downgraded to [DiagnosticLevel.fine] on the basis that the property value + /// is uninteresting. This is implemented by [isInteresting]. + /// + /// The [defaultValue] is [kNoDefaultValue] by default. Otherwise it must be of + /// type `T?`. + final Object? defaultValue; + + /// Whether to consider the property's value interesting. When a property is + /// uninteresting, its [level] is downgraded to [DiagnosticLevel.fine] + /// regardless of the value provided as the constructor's `level` argument. + bool get isInteresting => defaultValue == kNoDefaultValue || value != defaultValue; + + final DiagnosticLevel _defaultLevel; + + /// Priority level of the diagnostic used to control which diagnostics should + /// be shown and filtered. + /// + /// The property level defaults to the value specified by the [level] + /// constructor argument. The level is raised to [DiagnosticLevel.error] if + /// an [exception] was thrown getting the property [value]. The level is + /// raised to [DiagnosticLevel.warning] if the property [value] is null and + /// the property is not allowed to be null due to [missingIfNull]. The + /// priority level is lowered to [DiagnosticLevel.fine] if the property + /// [value] equals [defaultValue]. + @override + DiagnosticLevel get level { + if (_defaultLevel == DiagnosticLevel.hidden) { + return _defaultLevel; + } + + if (exception != null) { + return DiagnosticLevel.error; + } + + if (value == null && missingIfNull) { + return DiagnosticLevel.warning; + } + + if (!isInteresting) { + return DiagnosticLevel.fine; + } + + return _defaultLevel; + } + + final ComputePropertyValueCallback? _computeValue; + + @override + List getProperties() { + if (expandableValue) { + final T? object = value; + if (object is DiagnosticsNode) { + return object.getProperties(); + } + if (object is Diagnosticable) { + return object.toDiagnosticsNode(style: style).getProperties(); + } + } + return const []; + } + + @override + List getChildren() { + if (expandableValue) { + final T? object = value; + if (object is DiagnosticsNode) { + return object.getChildren(); + } + if (object is Diagnosticable) { + return object.toDiagnosticsNode(style: style).getChildren(); + } + } + return const []; + } +} + +/// [DiagnosticsNode] that lazily calls the associated [Diagnosticable] [value] +/// to implement [getChildren] and [getProperties]. +class DiagnosticableNode extends DiagnosticsNode { + /// Create a diagnostics describing a [Diagnosticable] value. + DiagnosticableNode({ + super.name, + required this.value, + required super.style, + }); + + @override + final T value; + + DiagnosticPropertiesBuilder? _cachedBuilder; + + /// Retrieve the [DiagnosticPropertiesBuilder] of current node. + /// + /// It will cache the result to prevent duplicate operation. + DiagnosticPropertiesBuilder? get builder { + if (kReleaseMode) { + return null; + } else { + assert(() { + if (_cachedBuilder == null) { + _cachedBuilder = DiagnosticPropertiesBuilder(); + value.debugFillProperties(_cachedBuilder!); + } + return true; + }()); + return _cachedBuilder; + } + } + + @override + DiagnosticsTreeStyle get style { + return kReleaseMode ? DiagnosticsTreeStyle.none : super.style ?? builder!.defaultDiagnosticsTreeStyle; + } + + @override + String? get emptyBodyDescription => (kReleaseMode || kProfileMode) ? '' : builder!.emptyBodyDescription; + + @override + List getProperties() => (kReleaseMode || kProfileMode) ? const [] : builder!.properties; + + @override + List getChildren() { + return const[]; + } + + @override + String toDescription({ TextTreeConfiguration? parentConfiguration }) { + String result = ''; + assert(() { + result = value.toStringShort(); + return true; + }()); + return result; + } +} + +/// [DiagnosticsNode] for an instance of [DiagnosticableTree]. +class DiagnosticableTreeNode extends DiagnosticableNode { + /// Creates a [DiagnosticableTreeNode]. + DiagnosticableTreeNode({ + super.name, + required super.value, + required super.style, + }); + + @override + List getChildren() => value.debugDescribeChildren(); +} + +/// Returns a 5 character long hexadecimal string generated from +/// [Object.hashCode]'s 20 least-significant bits. +String shortHash(Object? object) { + return object.hashCode.toUnsigned(20).toRadixString(16).padLeft(5, '0'); +} + +/// Returns a summary of the runtime type and hash code of `object`. +/// +/// See also: +/// +/// * [Object.hashCode], a value used when placing an object in a [Map] or +/// other similar data structure, and which is also used in debug output to +/// distinguish instances of the same class (hash collisions are +/// possible, but rare enough that its use in debug output is useful). +/// * [Object.runtimeType], the [Type] of an object. +String describeIdentity(Object? object) => '${objectRuntimeType(object, '')}#${shortHash(object)}'; + +/// Returns a short description of an enum value. +/// +/// Strips off the enum class name from the `enumEntry.toString()`. +/// +/// For real enums, this is redundant with calling the `name` getter on the enum +/// value (see [EnumName.name]), a feature that was added to Dart 2.15. +/// +/// This function can also be used with classes whose `toString` return a value +/// in the same form as an enum (the class name, a dot, then the value name). +/// For example, it's used with [SemanticsAction], which is written to appear to +/// be an enum but is actually a bespoke class so that the index values can be +/// set as powers of two instead of as sequential integers. +/// +/// {@tool snippet} +/// +/// ```dart +/// enum Day { +/// monday, tuesday, wednesday, thursday, friday, saturday, sunday +/// } +/// +/// void validateDescribeEnum() { +/// assert(Day.monday.toString() == 'Day.monday'); +/// // ignore: deprecated_member_use +/// assert(describeEnum(Day.monday) == 'monday'); +/// assert(Day.monday.name == 'monday'); // preferred for real enums +/// } +/// ``` +/// {@end-tool} +@Deprecated( + 'Use the `name` getter on enums instead. ' + 'This feature was deprecated after v3.14.0-2.0.pre.' +) +String describeEnum(Object enumEntry) { + if (enumEntry is Enum) { + return enumEntry.name; + } + final String description = enumEntry.toString(); + final int indexOfDot = description.indexOf('.'); + assert( + indexOfDot != -1 && indexOfDot < description.length - 1, + 'The provided object "$enumEntry" is not an enum.', + ); + return description.substring(indexOfDot + 1); +} + +/// Builder to accumulate properties and configuration used to assemble a +/// [DiagnosticsNode] from a [Diagnosticable] object. +class DiagnosticPropertiesBuilder { + /// Creates a [DiagnosticPropertiesBuilder] with [properties] initialize to + /// an empty array. + DiagnosticPropertiesBuilder() : properties = []; + + /// Creates a [DiagnosticPropertiesBuilder] with a given [properties]. + DiagnosticPropertiesBuilder.fromProperties(this.properties); + + /// Add a property to the list of properties. + void add(DiagnosticsNode property) { + assert(() { + properties.add(property); + return true; + }()); + } + + /// List of properties accumulated so far. + final List properties; + + /// Default style to use for the [DiagnosticsNode] if no style is specified. + DiagnosticsTreeStyle defaultDiagnosticsTreeStyle = DiagnosticsTreeStyle.sparse; + + /// Description to show if the node has no displayed properties or children. + String? emptyBodyDescription; +} + +// Examples can assume: +// class ExampleSuperclass with Diagnosticable { late String message; late double stepWidth; late double scale; late double paintExtent; late double hitTestExtent; late double paintExtend; late double maxWidth; late bool primary; late double progress; late int maxLines; late Duration duration; late int depth; Iterable? boxShadow; late DiagnosticsTreeStyle style; late bool hasSize; late Matrix4 transform; Map? handles; late Color color; late bool obscureText; late ImageRepeat repeat; late Size size; late Widget widget; late bool isCurrent; late bool keepAlive; late TextAlign textAlign; } + +/// A mixin class for providing string and [DiagnosticsNode] debug +/// representations describing the properties of an object. +/// +/// The string debug representation is generated from the intermediate +/// [DiagnosticsNode] representation. The [DiagnosticsNode] representation is +/// also used by debugging tools displaying interactive trees of objects and +/// properties. +/// +/// See also: +/// +/// * [debugFillProperties], which lists best practices for specifying the +/// properties of a [DiagnosticsNode]. The most common use case is to +/// override [debugFillProperties] defining custom properties for a subclass +/// of [DiagnosticableTreeMixin] using the existing [DiagnosticsProperty] +/// subclasses. +/// * [DiagnosticableTree], which extends this class to also describe the +/// children of a tree structured object. +/// * [DiagnosticableTree.debugDescribeChildren], which lists best practices +/// for describing the children of a [DiagnosticsNode]. Typically the base +/// class already describes the children of a node properly or a node has +/// no children. +/// * [DiagnosticsProperty], which should be used to create leaf diagnostic +/// nodes without properties or children. There are many +/// [DiagnosticsProperty] subclasses to handle common use cases. +mixin Diagnosticable { + /// A brief description of this object, usually just the [runtimeType] and the + /// [hashCode]. + /// + /// See also: + /// + /// * [toString], for a detailed description of the object. + String toStringShort() => describeIdentity(this); + + @override + String toString({ DiagnosticLevel minLevel = DiagnosticLevel.info }) { + String? fullString; + assert(() { + fullString = toDiagnosticsNode(style: DiagnosticsTreeStyle.singleLine).toString(minLevel: minLevel); + return true; + }()); + return fullString ?? toStringShort(); + } + + /// Returns a debug representation of the object that is used by debugging + /// tools and by [DiagnosticsNode.toStringDeep]. + /// + /// Leave [name] as null if there is not a meaningful description of the + /// relationship between the this node and its parent. + /// + /// Typically the [style] argument is only specified to indicate an atypical + /// relationship between the parent and the node. For example, pass + /// [DiagnosticsTreeStyle.offstage] to indicate that a node is offstage. + DiagnosticsNode toDiagnosticsNode({ String? name, DiagnosticsTreeStyle? style }) { + return DiagnosticableNode( + name: name, + value: this, + style: style, + ); + } + + /// Add additional properties associated with the node. + /// + /// {@youtube 560 315 https://www.youtube.com/watch?v=DnC7eT-vh1k} + /// + /// Use the most specific [DiagnosticsProperty] existing subclass to describe + /// each property instead of the [DiagnosticsProperty] base class. There are + /// only a small number of [DiagnosticsProperty] subclasses each covering a + /// common use case. Consider what values a property is relevant for users + /// debugging as users debugging large trees are overloaded with information. + /// Common named parameters in [DiagnosticsNode] subclasses help filter when + /// and how properties are displayed. + /// + /// `defaultValue`, `showName`, `showSeparator`, and `level` keep string + /// representations of diagnostics terse and hide properties when they are not + /// very useful. + /// + /// * Use `defaultValue` any time the default value of a property is + /// uninteresting. For example, specify a default value of null any time + /// a property being null does not indicate an error. + /// * Avoid specifying the `level` parameter unless the result you want + /// cannot be achieved by using the `defaultValue` parameter or using + /// the [ObjectFlagProperty] class to conditionally display the property + /// as a flag. + /// * Specify `showName` and `showSeparator` in rare cases where the string + /// output would look clumsy if they were not set. + /// ```dart + /// DiagnosticsProperty('child(3, 4)', null, ifNull: 'is null', showSeparator: false).toString() + /// ``` + /// Shows using `showSeparator` to get output `child(3, 4) is null` which + /// is more polished than `child(3, 4): is null`. + /// ```dart + /// DiagnosticsProperty('icon', icon, ifNull: '', showName: false).toString() + /// ``` + /// Shows using `showName` to omit the property name as in this context the + /// property name does not add useful information. + /// + /// `ifNull`, `ifEmpty`, `unit`, and `tooltip` make property + /// descriptions clearer. The examples in the code sample below illustrate + /// good uses of all of these parameters. + /// + /// ## DiagnosticsProperty subclasses for primitive types + /// + /// * [StringProperty], which supports automatically enclosing a [String] + /// value in quotes. + /// * [DoubleProperty], which supports specifying a unit of measurement for + /// a [double] value. + /// * [PercentProperty], which clamps a [double] to between 0 and 1 and + /// formats it as a percentage. + /// * [IntProperty], which supports specifying a unit of measurement for an + /// [int] value. + /// * [FlagProperty], which formats a [bool] value as one or more flags. + /// Depending on the use case it is better to format a bool as + /// `DiagnosticsProperty` instead of using [FlagProperty] as the + /// output is more verbose but unambiguous. + /// + /// ## Other important [DiagnosticsProperty] variants + /// + /// * [EnumProperty], which provides terse descriptions of enum values + /// working around limitations of the `toString` implementation for Dart + /// enum types. + /// * [IterableProperty], which handles iterable values with display + /// customizable depending on the [DiagnosticsTreeStyle] used. + /// * [ObjectFlagProperty], which provides terse descriptions of whether a + /// property value is present or not. For example, whether an `onClick` + /// callback is specified or an animation is in progress. + /// * [ColorProperty], which must be used if the property value is + /// a [Color] or one of its subclasses. + /// * [IconDataProperty], which must be used if the property value + /// is of type [IconData]. + /// + /// If none of these subclasses apply, use the [DiagnosticsProperty] + /// constructor or in rare cases create your own [DiagnosticsProperty] + /// subclass as in the case for [TransformProperty] which handles [Matrix4] + /// that represent transforms. Generally any property value with a good + /// `toString` method implementation works fine using [DiagnosticsProperty] + /// directly. + /// + /// {@tool snippet} + /// + /// This example shows best practices for implementing [debugFillProperties] + /// illustrating use of all common [DiagnosticsProperty] subclasses and all + /// common [DiagnosticsProperty] parameters. + /// + /// ```dart + /// class ExampleObject extends ExampleSuperclass { + /// + /// // ...various members and properties... + /// + /// @override + /// void debugFillProperties(DiagnosticPropertiesBuilder properties) { + /// // Always add properties from the base class first. + /// super.debugFillProperties(properties); + /// + /// // Omit the property name 'message' when displaying this String property + /// // as it would just add visual noise. + /// properties.add(StringProperty('message', message, showName: false)); + /// + /// properties.add(DoubleProperty('stepWidth', stepWidth)); + /// + /// // A scale of 1.0 does nothing so should be hidden. + /// properties.add(DoubleProperty('scale', scale, defaultValue: 1.0)); + /// + /// // If the hitTestExtent matches the paintExtent, it is just set to its + /// // default value so is not relevant. + /// properties.add(DoubleProperty('hitTestExtent', hitTestExtent, defaultValue: paintExtent)); + /// + /// // maxWidth of double.infinity indicates the width is unconstrained and + /// // so maxWidth has no impact. + /// properties.add(DoubleProperty('maxWidth', maxWidth, defaultValue: double.infinity)); + /// + /// // Progress is a value between 0 and 1 or null. Showing it as a + /// // percentage makes the meaning clear enough that the name can be + /// // hidden. + /// properties.add(PercentProperty( + /// 'progress', + /// progress, + /// showName: false, + /// ifNull: '', + /// )); + /// + /// // Most text fields have maxLines set to 1. + /// properties.add(IntProperty('maxLines', maxLines, defaultValue: 1)); + /// + /// // Specify the unit as otherwise it would be unclear that time is in + /// // milliseconds. + /// properties.add(IntProperty('duration', duration.inMilliseconds, unit: 'ms')); + /// + /// // Tooltip is used instead of unit for this case as a unit should be a + /// // terse description appropriate to display directly after a number + /// // without a space. + /// properties.add(DoubleProperty( + /// 'device pixel ratio', + /// devicePixelRatio, + /// tooltip: 'physical pixels per logical pixel', + /// )); + /// + /// // Displaying the depth value would be distracting. Instead only display + /// // if the depth value is missing. + /// properties.add(ObjectFlagProperty('depth', depth, ifNull: 'no depth')); + /// + /// // bool flag that is only shown when the value is true. + /// properties.add(FlagProperty('using primary controller', value: primary)); + /// + /// properties.add(FlagProperty( + /// 'isCurrent', + /// value: isCurrent, + /// ifTrue: 'active', + /// ifFalse: 'inactive', + /// )); + /// + /// properties.add(DiagnosticsProperty('keepAlive', keepAlive)); + /// + /// // FlagProperty could have also been used in this case. + /// // This option results in the text "obscureText: true" instead + /// // of "obscureText" which is a bit more verbose but a bit clearer. + /// properties.add(DiagnosticsProperty('obscureText', obscureText, defaultValue: false)); + /// + /// properties.add(EnumProperty('textAlign', textAlign, defaultValue: null)); + /// properties.add(EnumProperty('repeat', repeat, defaultValue: ImageRepeat.noRepeat)); + /// + /// // Warn users when the widget is missing but do not show the value. + /// properties.add(ObjectFlagProperty('widget', widget, ifNull: 'no widget')); + /// + /// properties.add(IterableProperty( + /// 'boxShadow', + /// boxShadow, + /// defaultValue: null, + /// style: style, + /// )); + /// + /// // Getting the value of size throws an exception unless hasSize is true. + /// properties.add(DiagnosticsProperty.lazy( + /// 'size', + /// () => size, + /// description: '${ hasSize ? size : "MISSING" }', + /// )); + /// + /// // If the `toString` method for the property value does not provide a + /// // good terse description, write a DiagnosticsProperty subclass as in + /// // the case of TransformProperty which displays a nice debugging view + /// // of a Matrix4 that represents a transform. + /// properties.add(TransformProperty('transform', transform)); + /// + /// // If the value class has a good `toString` method, use + /// // DiagnosticsProperty. Specifying the value type ensures + /// // that debugging tools always know the type of the field and so can + /// // provide the right UI affordances. For example, in this case even + /// // if color is null, a debugging tool still knows the value is a Color + /// // and can display relevant color related UI. + /// properties.add(DiagnosticsProperty('color', color)); + /// + /// // Use a custom description to generate a more terse summary than the + /// // `toString` method on the map class. + /// properties.add(DiagnosticsProperty>( + /// 'handles', + /// handles, + /// description: handles != null + /// ? '${handles!.length} active client${ handles!.length == 1 ? "" : "s" }' + /// : null, + /// ifNull: 'no notifications ever received', + /// showName: false, + /// )); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// Used by [toDiagnosticsNode] and [toString]. + /// + /// Do not add values, that have lifetime shorter than the object. + @protected + @mustCallSuper + void debugFillProperties(DiagnosticPropertiesBuilder properties) { } +} + +/// A base class for providing string and [DiagnosticsNode] debug +/// representations describing the properties and children of an object. +/// +/// The string debug representation is generated from the intermediate +/// [DiagnosticsNode] representation. The [DiagnosticsNode] representation is +/// also used by debugging tools displaying interactive trees of objects and +/// properties. +/// +/// See also: +/// +/// * [DiagnosticableTreeMixin], a mixin that implements this class. +/// * [Diagnosticable], which should be used instead of this class to +/// provide diagnostics for objects without children. +abstract class DiagnosticableTree with Diagnosticable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const DiagnosticableTree(); + + /// Returns a one-line detailed description of the object. + /// + /// This description is often somewhat long. This includes the same + /// information given by [toStringDeep], but does not recurse to any children. + /// + /// `joiner` specifies the string which is place between each part obtained + /// from [debugFillProperties]. Passing a string such as `'\n '` will result + /// in a multiline string that indents the properties of the object below its + /// name (as per [toString]). + /// + /// `minLevel` specifies the minimum [DiagnosticLevel] for properties included + /// in the output. + /// + /// See also: + /// + /// * [toString], for a brief description of the object. + /// * [toStringDeep], for a description of the subtree rooted at this object. + String toStringShallow({ + String joiner = ', ', + DiagnosticLevel minLevel = DiagnosticLevel.debug, + }) { + String? shallowString; + assert(() { + final StringBuffer result = StringBuffer(); + result.write(toString()); + result.write(joiner); + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + debugFillProperties(builder); + result.write( + builder.properties.where((DiagnosticsNode n) => !n.isFiltered(minLevel)) + .join(joiner), + ); + shallowString = result.toString(); + return true; + }()); + return shallowString ?? toString(); + } + + /// Returns a string representation of this node and its descendants. + /// + /// `prefixLineOne` will be added to the front of the first line of the + /// output. `prefixOtherLines` will be added to the front of each other line. + /// If `prefixOtherLines` is null, the `prefixLineOne` is used for every line. + /// By default, there is no prefix. + /// + /// `minLevel` specifies the minimum [DiagnosticLevel] for properties included + /// in the output. + /// + /// The [toStringDeep] method takes other arguments, but those are intended + /// for internal use when recursing to the descendants, and so can be ignored. + /// + /// See also: + /// + /// * [toString], for a brief description of the object but not its children. + /// * [toStringShallow], for a detailed description of the object but not its + /// children. + String toStringDeep({ + String prefixLineOne = '', + String? prefixOtherLines, + DiagnosticLevel minLevel = DiagnosticLevel.debug, + }) { + return toDiagnosticsNode().toStringDeep(prefixLineOne: prefixLineOne, prefixOtherLines: prefixOtherLines, minLevel: minLevel); + } + + @override + String toStringShort() => describeIdentity(this); + + @override + DiagnosticsNode toDiagnosticsNode({ String? name, DiagnosticsTreeStyle? style }) { + return DiagnosticableTreeNode( + name: name, + value: this, + style: style, + ); + } + + /// Returns a list of [DiagnosticsNode] objects describing this node's + /// children. + /// + /// Children that are offstage should be added with `style` set to + /// [DiagnosticsTreeStyle.offstage] to indicate that they are offstage. + /// + /// The list must not contain any null entries. If there are explicit null + /// children to report, consider [DiagnosticsNode.message] or + /// [DiagnosticsProperty] as possible [DiagnosticsNode] objects to + /// provide. + /// + /// Used by [toStringDeep], [toDiagnosticsNode] and [toStringShallow]. + /// + /// See also: + /// + /// * [RenderTable.debugDescribeChildren], which provides high quality custom + /// descriptions for its child nodes. + @protected + List debugDescribeChildren() => const []; +} + +/// A mixin that helps dump string and [DiagnosticsNode] representations of trees. +/// +/// This mixin is identical to class [DiagnosticableTree]. +mixin DiagnosticableTreeMixin implements DiagnosticableTree { + @override + String toString({ DiagnosticLevel minLevel = DiagnosticLevel.info }) { + return toDiagnosticsNode(style: DiagnosticsTreeStyle.singleLine).toString(minLevel: minLevel); + } + + @override + String toStringShallow({ + String joiner = ', ', + DiagnosticLevel minLevel = DiagnosticLevel.debug, + }) { + String? shallowString; + assert(() { + final StringBuffer result = StringBuffer(); + result.write(toStringShort()); + result.write(joiner); + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + debugFillProperties(builder); + result.write( + builder.properties.where((DiagnosticsNode n) => !n.isFiltered(minLevel)) + .join(joiner), + ); + shallowString = result.toString(); + return true; + }()); + return shallowString ?? toString(); + } + + @override + String toStringDeep({ + String prefixLineOne = '', + String? prefixOtherLines, + DiagnosticLevel minLevel = DiagnosticLevel.debug, + }) { + return toDiagnosticsNode().toStringDeep(prefixLineOne: prefixLineOne, prefixOtherLines: prefixOtherLines, minLevel: minLevel); + } + + @override + String toStringShort() => describeIdentity(this); + + @override + DiagnosticsNode toDiagnosticsNode({ String? name, DiagnosticsTreeStyle? style }) { + return DiagnosticableTreeNode( + name: name, + value: this, + style: style, + ); + } + + @override + List debugDescribeChildren() => const []; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { } +} + + +/// [DiagnosticsNode] that exists mainly to provide a container for other +/// diagnostics that typically lacks a meaningful value of its own. +/// +/// This class is typically used for displaying complex nested error messages. +class DiagnosticsBlock extends DiagnosticsNode { + /// Creates a diagnostic with properties specified by [properties] and + /// children specified by [children]. + DiagnosticsBlock({ + super.name, + DiagnosticsTreeStyle super.style = DiagnosticsTreeStyle.whitespace, + bool showName = true, + super.showSeparator, + super.linePrefix, + this.value, + String? description, + this.level = DiagnosticLevel.info, + this.allowTruncate = false, + List children = const[], + List properties = const [], + }) : _description = description ?? '', + _children = children, + _properties = properties, + super( + showName: showName && name != null, + ); + + final List _children; + final List _properties; + + @override + final DiagnosticLevel level; + + final String _description; + + @override + final Object? value; + + @override + final bool allowTruncate; + + @override + List getChildren() => _children; + + @override + List getProperties() => _properties; + + @override + String toDescription({TextTreeConfiguration? parentConfiguration}) => _description; +} + +/// A delegate that configures how a hierarchy of [DiagnosticsNode]s should be +/// serialized. +/// +/// Implement this class in a subclass to fully configure how [DiagnosticsNode]s +/// get serialized. +abstract class DiagnosticsSerializationDelegate { + /// Creates a simple [DiagnosticsSerializationDelegate] that controls the + /// [subtreeDepth] and whether to [includeProperties]. + /// + /// For additional configuration options, extend + /// [DiagnosticsSerializationDelegate] and provide custom implementations + /// for the methods of this class. + const factory DiagnosticsSerializationDelegate({ + int subtreeDepth, + bool includeProperties, + }) = _DefaultDiagnosticsSerializationDelegate; + + /// Returns a serializable map of additional information that will be included + /// in the serialization of the given [DiagnosticsNode]. + /// + /// This method is called for every [DiagnosticsNode] that's included in + /// the serialization. + Map additionalNodeProperties(DiagnosticsNode node); + + /// Filters the list of [DiagnosticsNode]s that will be included as children + /// for the given `owner` node. + /// + /// The callback may return a subset of the children in the provided list + /// or replace the entire list with new child nodes. + /// + /// See also: + /// + /// * [subtreeDepth], which controls how many levels of children will be + /// included in the serialization. + List filterChildren(List nodes, DiagnosticsNode owner); + + /// Filters the list of [DiagnosticsNode]s that will be included as properties + /// for the given `owner` node. + /// + /// The callback may return a subset of the properties in the provided list + /// or replace the entire list with new property nodes. + /// + /// By default, `nodes` is returned as-is. + /// + /// See also: + /// + /// * [includeProperties], which controls whether properties will be included + /// at all. + List filterProperties(List nodes, DiagnosticsNode owner); + + /// Truncates the given list of [DiagnosticsNode] that will be added to the + /// serialization as children or properties of the `owner` node. + /// + /// The method must return a subset of the provided nodes and may + /// not replace any nodes. While [filterProperties] and [filterChildren] + /// completely hide a node from the serialization, truncating a node will + /// leave a hint in the serialization that there were additional nodes in the + /// result that are not included in the current serialization. + /// + /// By default, `nodes` is returned as-is. + List truncateNodesList(List nodes, DiagnosticsNode? owner); + + /// Returns the [DiagnosticsSerializationDelegate] to be used + /// for adding the provided [DiagnosticsNode] to the serialization. + /// + /// By default, this will return a copy of this delegate, which has the + /// [subtreeDepth] reduced by one. + /// + /// This is called for nodes that will be added to the serialization as + /// property or child of another node. It may return the same delegate if no + /// changes to it are necessary. + DiagnosticsSerializationDelegate delegateForNode(DiagnosticsNode node); + + /// Controls how many levels of children will be included in the serialized + /// hierarchy of [DiagnosticsNode]s. + /// + /// Defaults to zero. + /// + /// See also: + /// + /// * [filterChildren], which provides a way to filter the children that + /// will be included. + int get subtreeDepth; + + /// Whether to include the properties of a [DiagnosticsNode] in the + /// serialization. + /// + /// Defaults to false. + /// + /// See also: + /// + /// * [filterProperties], which provides a way to filter the properties that + /// will be included. + bool get includeProperties; + + /// Whether properties that have a [Diagnosticable] as value should be + /// expanded. + bool get expandPropertyValues; + + /// Creates a copy of this [DiagnosticsSerializationDelegate] with the + /// provided values. + DiagnosticsSerializationDelegate copyWith({ + int subtreeDepth, + bool includeProperties, + }); +} + +class _DefaultDiagnosticsSerializationDelegate implements DiagnosticsSerializationDelegate { + const _DefaultDiagnosticsSerializationDelegate({ + this.includeProperties = false, + this.subtreeDepth = 0, + }); + + @override + Map additionalNodeProperties(DiagnosticsNode node) { + return const {}; + } + + @override + DiagnosticsSerializationDelegate delegateForNode(DiagnosticsNode node) { + return subtreeDepth > 0 ? copyWith(subtreeDepth: subtreeDepth - 1) : this; + } + + @override + bool get expandPropertyValues => false; + + @override + List filterChildren(List nodes, DiagnosticsNode owner) { + return nodes; + } + + @override + List filterProperties(List nodes, DiagnosticsNode owner) { + return nodes; + } + + @override + final bool includeProperties; + + @override + final int subtreeDepth; + + @override + List truncateNodesList(List nodes, DiagnosticsNode? owner) { + return nodes; + } + + @override + DiagnosticsSerializationDelegate copyWith({int? subtreeDepth, bool? includeProperties}) { + return _DefaultDiagnosticsSerializationDelegate( + subtreeDepth: subtreeDepth ?? this.subtreeDepth, + includeProperties: includeProperties ?? this.includeProperties, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/isolates.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/isolates.dart new file mode 100644 index 0000000000000000000000000000000000000000..9c0bae37bcf9df296c652b56027c9ad7b94ade73 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/isolates.dart @@ -0,0 +1,77 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import '_isolates_io.dart' + if (dart.library.js_util) '_isolates_web.dart' as isolates; + +/// Signature for the callback passed to [compute]. +/// +/// {@macro flutter.foundation.compute.callback} +/// +typedef ComputeCallback = FutureOr Function(M message); + +/// The signature of [compute], which spawns an isolate, runs `callback` on +/// that isolate, passes it `message`, and (eventually) returns the value +/// returned by `callback`. +typedef ComputeImpl = Future Function(ComputeCallback callback, M message, { String? debugLabel }); + +/// Asynchronously runs the given [callback] - with the provided [message] - +/// in the background and completes with the result. +/// +/// {@template flutter.foundation.compute.usecase} +/// This is useful for operations that take longer than a few milliseconds, and +/// which would therefore risk skipping frames. For tasks that will only take a +/// few milliseconds, consider [SchedulerBinding.scheduleTask] instead. +/// {@endtemplate} +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=5AxWC49ZMzs} +/// +/// {@tool snippet} +/// The following code uses the [compute] function to check whether a given +/// integer is a prime number. +/// +/// ```dart +/// Future isPrime(int value) { +/// return compute(_calculate, value); +/// } +/// +/// bool _calculate(int value) { +/// if (value == 1) { +/// return false; +/// } +/// for (int i = 2; i < value; ++i) { +/// if (value % i == 0) { +/// return false; +/// } +/// } +/// return true; +/// } +/// ``` +/// {@end-tool} +/// +/// On web platforms this will run [callback] on the current eventloop. +/// On native platforms this will run [callback] in a separate isolate. +/// +/// {@template flutter.foundation.compute.callback} +/// +/// The `callback`, the `message` given to it as well as the result have to be +/// objects that can be sent across isolates (as they may be transitively copied +/// if needed). The majority of objects can be sent across isolates. +/// +/// See [SendPort.send] for more information about exceptions as well as a note +/// of warning about sending closures, which can capture more state than needed. +/// +/// {@endtemplate} +/// +/// On native platforms `await compute(fun, message)` is equivalent to +/// `await Isolate.run(() => fun(message))`. See also [Isolate.run]. +/// +/// The `debugLabel` - if provided - is used as name for the isolate that +/// executes `callback`. [Timeline] events produced by that isolate will have +/// the name associated with them. This is useful when profiling an application. +Future compute(ComputeCallback callback, M message, {String? debugLabel}) { + return isolates.compute(callback, message, debugLabel: debugLabel); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/key.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/key.dart new file mode 100644 index 0000000000000000000000000000000000000000..a14dff9d57491af7a5bd1b06418ae3c5a9c52083 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/key.dart @@ -0,0 +1,116 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:meta/meta.dart'; + +import 'diagnostics.dart'; + +/// A [Key] is an identifier for [Widget]s, [Element]s and [SemanticsNode]s. +/// +/// A new widget will only be used to update an existing element if its key is +/// the same as the key of the current widget associated with the element. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=kn0EOS-ZiIc} +/// +/// Keys must be unique amongst the [Element]s with the same parent. +/// +/// Subclasses of [Key] should either subclass [LocalKey] or [GlobalKey]. +/// +/// See also: +/// +/// * [Widget.key], which discusses how widgets use keys. +@immutable +abstract class Key { + /// Construct a [ValueKey] with the given [String]. + /// + /// This is the simplest way to create keys. + const factory Key(String value) = ValueKey; + + /// Default constructor, used by subclasses. + /// + /// Useful so that subclasses can call us, because the [Key.new] factory + /// constructor shadows the implicit constructor. + @protected + const Key.empty(); +} + +/// A key that is not a [GlobalKey]. +/// +/// Keys must be unique amongst the [Element]s with the same parent. By +/// contrast, [GlobalKey]s must be unique across the entire app. +/// +/// See also: +/// +/// * [Widget.key], which discusses how widgets use keys. +abstract class LocalKey extends Key { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const LocalKey() : super.empty(); +} + +/// A key that is only equal to itself. +/// +/// This cannot be created with a const constructor because that implies that +/// all instantiated keys would be the same instance and therefore not be unique. +class UniqueKey extends LocalKey { + /// Creates a key that is equal only to itself. + /// + /// The key cannot be created with a const constructor because that implies + /// that all instantiated keys would be the same instance and therefore not + /// be unique. + // ignore: prefer_const_constructors_in_immutables , never use const for this class + UniqueKey(); + + @override + String toString() => '[#${shortHash(this)}]'; +} + +/// A key that uses a value of a particular type to identify itself. +/// +/// A [ValueKey] is equal to another [ValueKey] if, and only if, their +/// values are [operator==]. +/// +/// This class can be subclassed to create value keys that will not be equal to +/// other value keys that happen to use the same value. If the subclass is +/// private, this results in a value key type that cannot collide with keys from +/// other sources, which could be useful, for example, if the keys are being +/// used as fallbacks in the same scope as keys supplied from another widget. +/// +/// See also: +/// +/// * [Widget.key], which discusses how widgets use keys. +class ValueKey extends LocalKey { + /// Creates a key that delegates its [operator==] to the given value. + const ValueKey(this.value); + + /// The value to which this key delegates its [operator==] + final T value; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ValueKey + && other.value == value; + } + + @override + int get hashCode => Object.hash(runtimeType, value); + + @override + String toString() { + final String valueString = T == String ? "<'$value'>" : '<$value>'; + // The crazy on the next line is a workaround for + // https://github.com/dart-lang/sdk/issues/33297 + if (runtimeType == _TypeLiteral>().type) { + return '[$valueString]'; + } + return '[$T $valueString]'; + } +} + +class _TypeLiteral { + Type get type => T; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/licenses.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/licenses.dart new file mode 100644 index 0000000000000000000000000000000000000000..f68622bc2820151f4c33c08ffb76b912adf03e87 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/licenses.dart @@ -0,0 +1,326 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:meta/meta.dart' show visibleForTesting; + +/// Signature for callbacks passed to [LicenseRegistry.addLicense]. +typedef LicenseEntryCollector = Stream Function(); + +/// A string that represents one paragraph in a [LicenseEntry]. +/// +/// See [LicenseEntry.paragraphs]. +class LicenseParagraph { + /// Creates a string for a license entry paragraph. + const LicenseParagraph(this.text, this.indent); + + /// The text of the paragraph. Should not have any leading or trailing whitespace. + final String text; + + /// How many steps of indentation the paragraph has. + /// + /// * 0 means the paragraph is not indented. + /// * 1 means the paragraph is indented one unit of indentation. + /// * 2 means the paragraph is indented two units of indentation. + /// + /// ...and so forth. + /// + /// In addition, the special value [centeredIndent] can be used to indicate + /// that rather than being indented, the paragraph is centered. + final int indent; // can be set to centeredIndent + + /// A constant that represents "centered" alignment for [indent]. + static const int centeredIndent = -1; +} + +/// A license that covers part of the application's software or assets, to show +/// in an interface such as the [LicensePage]. +/// +/// For optimal performance, [LicenseEntry] objects should only be created on +/// demand in [LicenseEntryCollector] callbacks passed to +/// [LicenseRegistry.addLicense]. +abstract class LicenseEntry { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const LicenseEntry(); + + /// The names of the packages that this license entry applies to. + Iterable get packages; + + /// The paragraphs of the license, each as a [LicenseParagraph] consisting of + /// a string and some formatting information. Paragraphs can include newline + /// characters, but this is discouraged as it results in ugliness. + Iterable get paragraphs; +} + +enum _LicenseEntryWithLineBreaksParserState { + beforeParagraph, + inParagraph, +} + +/// Variant of [LicenseEntry] for licenses that separate paragraphs with blank +/// lines and that hard-wrap text within paragraphs. Lines that begin with one +/// or more space characters are also assumed to introduce new paragraphs, +/// unless they start with the same number of spaces as the previous line, in +/// which case it's assumed they are a continuation of an indented paragraph. +/// +/// {@tool snippet} +/// +/// For example, the BSD license in this format could be encoded as follows: +/// +/// ```dart +/// void initMyLibrary() { +/// LicenseRegistry.addLicense(() => Stream.value( +/// const LicenseEntryWithLineBreaks(['my_library'], ''' +/// Copyright 2016 The Sample Authors. All rights reserved. +/// +/// Redistribution and use in source and binary forms, with or without +/// modification, are permitted provided that the following conditions are +/// met: +/// +/// * Redistributions of source code must retain the above copyright +/// notice, this list of conditions and the following disclaimer. +/// * Redistributions in binary form must reproduce the above +/// copyright notice, this list of conditions and the following disclaimer +/// in the documentation and/or other materials provided with the +/// distribution. +/// * Neither the name of Example Inc. nor the names of its +/// contributors may be used to endorse or promote products derived from +/// this software without specific prior written permission. +/// +/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +/// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +/// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +/// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +/// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +/// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +/// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +/// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +/// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +/// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +/// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.''', +/// ), +/// )); +/// } +/// ``` +/// {@end-tool} +/// +/// This would result in a license with six [paragraphs], the third, fourth, and +/// fifth being indented one level. +/// +/// ## Performance considerations +/// +/// Computing the paragraphs is relatively expensive. Doing the work for one +/// license per frame is reasonable; doing more at the same time is ill-advised. +/// Consider doing all the work at once using [compute] to move the work to +/// another thread, or spreading the work across multiple frames using +/// [SchedulerBinding.scheduleTask]. +class LicenseEntryWithLineBreaks extends LicenseEntry { + /// Create a license entry for a license whose text is hard-wrapped within + /// paragraphs and has paragraph breaks denoted by blank lines or with + /// indented text. + const LicenseEntryWithLineBreaks(this.packages, this.text); + + @override + final List packages; + + /// The text of the license. + /// + /// The text will be split into paragraphs according to the following + /// conventions: + /// + /// * Lines starting with a different number of space characters than the + /// previous line start a new paragraph, with those spaces removed. + /// * Blank lines start a new paragraph. + /// * Other line breaks are replaced by a single space character. + /// * Leading spaces on a line are removed. + /// + /// For each paragraph, the algorithm attempts (using some rough heuristics) + /// to identify how indented the paragraph is, or whether it is centered. + final String text; + + @override + Iterable get paragraphs { + int lineStart = 0; + int currentPosition = 0; + int lastLineIndent = 0; + int currentLineIndent = 0; + int? currentParagraphIndentation; + _LicenseEntryWithLineBreaksParserState state = _LicenseEntryWithLineBreaksParserState.beforeParagraph; + final List lines = []; + final List result = []; + + void addLine() { + assert(lineStart < currentPosition); + lines.add(text.substring(lineStart, currentPosition)); + } + + LicenseParagraph getParagraph() { + assert(lines.isNotEmpty); + assert(currentParagraphIndentation != null); + final LicenseParagraph result = LicenseParagraph(lines.join(' '), currentParagraphIndentation!); + assert(result.text.trimLeft() == result.text); + assert(result.text.isNotEmpty); + lines.clear(); + return result; + } + + while (currentPosition < text.length) { + switch (state) { + case _LicenseEntryWithLineBreaksParserState.beforeParagraph: + assert(lineStart == currentPosition); + switch (text[currentPosition]) { + case ' ': + lineStart = currentPosition + 1; + currentLineIndent += 1; + state = _LicenseEntryWithLineBreaksParserState.beforeParagraph; + case '\t': + lineStart = currentPosition + 1; + currentLineIndent += 8; + state = _LicenseEntryWithLineBreaksParserState.beforeParagraph; + case '\r': + case '\n': + case '\f': + if (lines.isNotEmpty) { + result.add(getParagraph()); + } + if (text[currentPosition] == '\r' && currentPosition < text.length - 1 + && text[currentPosition + 1] == '\n') { + currentPosition += 1; + } + lastLineIndent = 0; + currentLineIndent = 0; + currentParagraphIndentation = null; + lineStart = currentPosition + 1; + state = _LicenseEntryWithLineBreaksParserState.beforeParagraph; + case '[': + // This is a bit of a hack for the LGPL 2.1, which does something like this: + // + // [this is a + // single paragraph] + // + // ...near the top. + currentLineIndent += 1; + continue startParagraph; + startParagraph: + default: + if (lines.isNotEmpty && currentLineIndent > lastLineIndent) { + result.add(getParagraph()); + currentParagraphIndentation = null; + } + // The following is a wild heuristic for guessing the indentation level. + // It happens to work for common variants of the BSD and LGPL licenses. + if (currentParagraphIndentation == null) { + if (currentLineIndent > 10) { + currentParagraphIndentation = LicenseParagraph.centeredIndent; + } else { + currentParagraphIndentation = currentLineIndent ~/ 3; + } + } + state = _LicenseEntryWithLineBreaksParserState.inParagraph; + } + case _LicenseEntryWithLineBreaksParserState.inParagraph: + switch (text[currentPosition]) { + case '\n': + addLine(); + lastLineIndent = currentLineIndent; + currentLineIndent = 0; + lineStart = currentPosition + 1; + state = _LicenseEntryWithLineBreaksParserState.beforeParagraph; + case '\f': + addLine(); + result.add(getParagraph()); + lastLineIndent = 0; + currentLineIndent = 0; + currentParagraphIndentation = null; + lineStart = currentPosition + 1; + state = _LicenseEntryWithLineBreaksParserState.beforeParagraph; + default: + state = _LicenseEntryWithLineBreaksParserState.inParagraph; + } + } + currentPosition += 1; + } + switch (state) { + case _LicenseEntryWithLineBreaksParserState.beforeParagraph: + if (lines.isNotEmpty) { + result.add(getParagraph()); + } + case _LicenseEntryWithLineBreaksParserState.inParagraph: + addLine(); + result.add(getParagraph()); + } + return result; + } +} + + +/// A registry for packages to add licenses to, so that they can be displayed +/// together in an interface such as the [LicensePage]. +/// +/// Packages can register their licenses using [addLicense]. User interfaces +/// that wish to show all the licenses can obtain them by calling [licenses]. +/// +/// The flutter tool will automatically collect the contents of all the LICENSE +/// files found at the root of each package into a single LICENSE file in the +/// default asset bundle. Each license in that file is separated from the next +/// by a line of eighty hyphens (`-`), and begins with a list of package names +/// that the license applies to, one to a line, separated from the next by a +/// blank line. The `services` package registers a license collector that splits +/// that file and adds each entry to the registry. +/// +/// The LICENSE files in each package can either consist of a single license, or +/// can be in the format described above. In the latter case, each component +/// license and list of package names is merged independently. +/// +/// See also: +/// +/// * [showAboutDialog], which shows a Material-style dialog with information +/// about the application, including a button that shows a [LicensePage] that +/// uses this API to select licenses to show. +/// * [AboutListTile], which is a widget that can be added to a [Drawer]. When +/// tapped it calls [showAboutDialog]. +abstract final class LicenseRegistry { + static List? _collectors; + + /// Adds licenses to the registry. + /// + /// To avoid actually manipulating the licenses unless strictly necessary, + /// licenses are added by adding a closure that returns a list of + /// [LicenseEntry] objects. The closure is only called if [licenses] is itself + /// called; in normal operation, if the user does not request to see the + /// licenses, the closure will not be called. + static void addLicense(LicenseEntryCollector collector) { + _collectors ??= []; + _collectors!.add(collector); + } + + /// Returns the licenses that have been registered. + /// + /// Generating the list of licenses is expensive. + static Stream get licenses { + if (_collectors == null) { + return const Stream.empty(); + } + + late final StreamController controller; + controller = StreamController( + onListen: () async { + for (final LicenseEntryCollector collector in _collectors!) { + await controller.addStream(collector()); + } + await controller.close(); + }, + ); + return controller.stream; + } + + /// Resets the internal state of [LicenseRegistry]. Intended for use in + /// testing. + @visibleForTesting + static void reset() { + _collectors = null; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/memory_allocations.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/memory_allocations.dart new file mode 100644 index 0000000000000000000000000000000000000000..31307a7744da5e3c51ccaca00991ab37665490d9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/memory_allocations.dart @@ -0,0 +1,349 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui; + +import 'assertions.dart'; +import 'constants.dart'; +import 'diagnostics.dart'; + +const bool _kMemoryAllocations = bool.fromEnvironment('flutter.memory_allocations'); + +/// If true, Flutter objects dispatch the memory allocation events. +/// +/// By default, the constant is true for debug mode and false +/// for profile and release modes. +/// To enable the dispatching for release mode, pass the compilation flag +/// `--dart-define=flutter.memory_allocations=true`. +const bool kFlutterMemoryAllocationsEnabled = _kMemoryAllocations || kDebugMode; + +const String _dartUiLibrary = 'dart:ui'; + +class _FieldNames { + static const String eventType = 'eventType'; + static const String libraryName = 'libraryName'; + static const String className = 'className'; +} + +/// A lifecycle event of an object. +abstract class ObjectEvent{ + /// Creates an instance of [ObjectEvent]. + ObjectEvent({ + required this.object, + }); + + /// Reference to the object. + /// + /// The reference should not be stored in any + /// long living place as it will prevent garbage collection. + final Object object; + + /// The representation of the event in a form, acceptable by a + /// pure dart library, that cannot depend on Flutter. + /// + /// The method enables code like: + /// ```dart + /// void myDartMethod(Map> event) {} + /// FlutterMemoryAllocations.instance + /// .addListener((ObjectEvent event) => myDartMethod(event.toMap())); + /// ``` + Map> toMap(); +} + +/// A listener of [ObjectEvent]. +typedef ObjectEventListener = void Function(ObjectEvent event); + +/// An event that describes creation of an object. +class ObjectCreated extends ObjectEvent { + /// Creates an instance of [ObjectCreated]. + ObjectCreated({ + required this.library, + required this.className, + required super.object, + }); + + /// Name of the instrumented library. + /// + /// The format of this parameter should be a library Uri. + /// For example: `'package:flutter/rendering.dart'`. + final String library; + + /// Name of the instrumented class. + final String className; + + @override + Map> toMap() { + return >{object: { + _FieldNames.libraryName: library, + _FieldNames.className: className, + _FieldNames.eventType: 'created', + }}; + } +} + +/// An event that describes disposal of an object. +class ObjectDisposed extends ObjectEvent { + /// Creates an instance of [ObjectDisposed]. + ObjectDisposed({ + required super.object, + }); + + @override + Map> toMap() { + return >{object: { + _FieldNames.eventType: 'disposed', + }}; + } +} + +/// An interface for listening to object lifecycle events. +@Deprecated( + 'Use `FlutterMemoryAllocations` instead. ' + 'The class `MemoryAllocations` will be introduced in a pure Dart library. ' + 'This feature was deprecated after v3.18.0-18.0.pre.' +) +typedef MemoryAllocations = FlutterMemoryAllocations; + +/// An interface for listening to object lifecycle events. +/// +/// If [kFlutterMemoryAllocationsEnabled] is true, +/// [FlutterMemoryAllocations] listens to creation and disposal events +/// for disposable objects in Flutter Framework. +/// To dispatch other events objects, invoke +/// [FlutterMemoryAllocations.dispatchObjectEvent]. +/// +/// Use this class with condition `kFlutterMemoryAllocationsEnabled`, +/// to make sure not to increase size of the application by the code +/// of the class, if memory allocations are disabled. +/// +/// The class is optimized for massive event flow and small number of +/// added or removed listeners. +class FlutterMemoryAllocations { + FlutterMemoryAllocations._(); + + /// The shared instance of [FlutterMemoryAllocations]. + /// + /// Only call this when [kFlutterMemoryAllocationsEnabled] is true. + static final FlutterMemoryAllocations instance = FlutterMemoryAllocations._(); + + /// List of listeners. + /// + /// The elements are nullable, because the listeners should be removable + /// while iterating through the list. + List? _listeners; + + /// Register a listener that is called every time an object event is + /// dispatched. + /// + /// Listeners can be removed with [removeListener]. + /// + /// Only call this when [kFlutterMemoryAllocationsEnabled] is true. + void addListener(ObjectEventListener listener){ + if (!kFlutterMemoryAllocationsEnabled) { + return; + } + if (_listeners == null) { + _listeners = []; + _subscribeToSdkObjects(); + } + _listeners!.add(listener); + } + + /// Number of active notification loops. + /// + /// When equal to zero, we can delete listeners from the list, + /// otherwise should null them. + int _activeDispatchLoops = 0; + + /// If true, listeners were nulled by [removeListener]. + bool _listenersContainNulls = false; + + /// Stop calling the given listener every time an object event is + /// dispatched. + /// + /// Listeners can be added with [addListener]. + /// + /// Only call this when [kFlutterMemoryAllocationsEnabled] is true. + void removeListener(ObjectEventListener listener){ + if (!kFlutterMemoryAllocationsEnabled) { + return; + } + final List? listeners = _listeners; + if (listeners == null) { + return; + } + + if (_activeDispatchLoops > 0) { + // If there are active dispatch loops, listeners.remove + // should not be invoked, as it will + // break the dispatch loops correctness. + for (int i = 0; i < listeners.length; i++) { + if (listeners[i] == listener) { + listeners[i] = null; + _listenersContainNulls = true; + } + } + } else { + listeners.removeWhere((ObjectEventListener? l) => l == listener); + _checkListenersForEmptiness(); + } + } + + void _tryDefragmentListeners() { + if (_activeDispatchLoops > 0 || !_listenersContainNulls) { + return; + } + _listeners?.removeWhere((ObjectEventListener? e) => e == null); + _listenersContainNulls = false; + _checkListenersForEmptiness(); + } + + void _checkListenersForEmptiness() { + if (_listeners?.isEmpty ?? false) { + _listeners = null; + _unSubscribeFromSdkObjects(); + } + } + + /// Return true if there are listeners. + /// + /// If there is no listeners, the app can save on creating the event object. + /// + /// Only call this when [kFlutterMemoryAllocationsEnabled] is true. + bool get hasListeners { + if (!kFlutterMemoryAllocationsEnabled) { + return false; + } + if (_listenersContainNulls) { + return _listeners?.firstWhere((ObjectEventListener? l) => l != null) != null; + } + return _listeners?.isNotEmpty ?? false; + } + + /// Dispatch a new object event to listeners. + /// + /// Exceptions thrown by listeners will be caught and reported using + /// [FlutterError.reportError]. + /// + /// Listeners added during an event dispatching, will start being invoked + /// for next events, but will be skipped for this event. + /// + /// Listeners, removed during an event dispatching, will not be invoked + /// after the removal. + /// + /// Only call this when [kFlutterMemoryAllocationsEnabled] is true. + void dispatchObjectEvent(ObjectEvent event) { + if (!kFlutterMemoryAllocationsEnabled) { + return; + } + final List? listeners = _listeners; + if (listeners == null || listeners.isEmpty) { + return; + } + + _activeDispatchLoops++; + final int end = listeners.length; + for (int i = 0; i < end; i++) { + try { + listeners[i]?.call(event); + } catch (exception, stack) { + final String type = event.object.runtimeType.toString(); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'foundation library', + context: ErrorDescription('MemoryAllocations while ' + 'dispatching notifications for $type'), + informationCollector: () => [ + DiagnosticsProperty( + 'The $type sending notification was', + event.object, + style: DiagnosticsTreeStyle.errorProperty, + ), + ], + )); + } + } + _activeDispatchLoops--; + _tryDefragmentListeners(); + } + + /// Create [ObjectCreated] and invoke [dispatchObjectEvent] if there are listeners. + /// + /// This method is more efficient than [dispatchObjectEvent] if the event object is not created yet. + void dispatchObjectCreated({ + required String library, + required String className, + required Object object, + }) { + if (!hasListeners) { + return; + } + dispatchObjectEvent(ObjectCreated( + library: library, + className: className, + object: object, + )); + } + + /// Create [ObjectDisposed] and invoke [dispatchObjectEvent] if there are listeners. + /// + /// This method is more efficient than [dispatchObjectEvent] if the event object is not created yet. + void dispatchObjectDisposed({required Object object}) { + if (!hasListeners) { + return; + } + dispatchObjectEvent(ObjectDisposed(object: object)); + } + + void _subscribeToSdkObjects() { + assert(ui.Image.onCreate == null); + assert(ui.Image.onDispose == null); + assert(ui.Picture.onCreate == null); + assert(ui.Picture.onDispose == null); + ui.Image.onCreate = _imageOnCreate; + ui.Image.onDispose = _imageOnDispose; + ui.Picture.onCreate = _pictureOnCreate; + ui.Picture.onDispose = _pictureOnDispose; + } + + void _unSubscribeFromSdkObjects() { + assert(ui.Image.onCreate == _imageOnCreate); + assert(ui.Image.onDispose == _imageOnDispose); + assert(ui.Picture.onCreate == _pictureOnCreate); + assert(ui.Picture.onDispose == _pictureOnDispose); + ui.Image.onCreate = null; + ui.Image.onDispose = null; + ui.Picture.onCreate = null; + ui.Picture.onDispose = null; + } + + void _imageOnCreate(ui.Image image) { + dispatchObjectEvent(ObjectCreated( + library: _dartUiLibrary, + className: '${ui.Image}', + object: image, + )); + } + + void _pictureOnCreate(ui.Picture picture) { + dispatchObjectEvent(ObjectCreated( + library: _dartUiLibrary, + className: '${ui.Picture}', + object: picture, + )); + } + + void _imageOnDispose(ui.Image image) { + dispatchObjectEvent(ObjectDisposed( + object: image, + )); + } + + void _pictureOnDispose(ui.Picture picture) { + dispatchObjectEvent(ObjectDisposed( + object: picture, + )); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/node.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/node.dart new file mode 100644 index 0000000000000000000000000000000000000000..a32f30a4818c5a87d327688fc7672a140a7a3dd6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/node.dart @@ -0,0 +1,158 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:meta/meta.dart'; + +// This file gets mutated by //dev/devicelab/bin/tasks/flutter_test_performance.dart +// during device lab performance tests. When editing this file, check to make sure +// that it didn't break that test. + +/// Deprecated. Unused by the framework and will be removed in a future version +/// of Flutter. If needed, inline any required functionality of this class +/// directly in the subclass. +/// +/// An abstract node in a tree. +/// +/// AbstractNode has as notion of depth, attachment, and parent, but does not +/// have a model for children. +/// +/// When a subclass is changing the parent of a child, it should call either +/// `parent.adoptChild(child)` or `parent.dropChild(child)` as appropriate. +/// Subclasses can expose an API for manipulating the tree if desired (e.g. a +/// setter for a `child` property, or an `add()` method to manipulate a list). +/// +/// The current parent node is exposed by the [parent] property. +/// +/// The current attachment state is exposed by [attached]. The root of any tree +/// that is to be considered attached should be manually attached by calling +/// [attach]. Other than that, the [attach] and [detach] methods should not be +/// called directly; attachment is managed automatically by the aforementioned +/// [adoptChild] and [dropChild] methods. +/// +/// Subclasses that have children must override [attach] and [detach] as +/// described in the documentation for those methods. +/// +/// Nodes always have a [depth] greater than their ancestors'. There's no +/// guarantee regarding depth between siblings. The depth of a node is used to +/// ensure that nodes are processed in depth order. The [depth] of a child can +/// be more than one greater than the [depth] of the parent, because the [depth] +/// values are never decreased: all that matters is that it's greater than the +/// parent. Consider a tree with a root node A, a child B, and a grandchild C. +/// Initially, A will have [depth] 0, B [depth] 1, and C [depth] 2. If C is +/// moved to be a child of A, sibling of B, then the numbers won't change. C's +/// [depth] will still be 2. The [depth] is automatically maintained by the +/// [adoptChild] and [dropChild] methods. +@Deprecated( + 'If needed, inline any required functionality of AbstractNode in your class directly. ' + 'This feature was deprecated after v3.12.0-4.0.pre.', +) +class AbstractNode { + /// The depth of this node in the tree. + /// + /// The depth of nodes in a tree monotonically increases as you traverse down + /// the tree. + int get depth => _depth; + int _depth = 0; + + /// Adjust the [depth] of the given [child] to be greater than this node's own + /// [depth]. + /// + /// Only call this method from overrides of [redepthChildren]. + @protected + void redepthChild(AbstractNode child) { + assert(child.owner == owner); + if (child._depth <= _depth) { + child._depth = _depth + 1; + child.redepthChildren(); + } + } + + /// Adjust the [depth] of this node's children, if any. + /// + /// Override this method in subclasses with child nodes to call [redepthChild] + /// for each child. Do not call this method directly. + void redepthChildren() { } + + /// The owner for this node (null if unattached). + /// + /// The entire subtree that this node belongs to will have the same owner. + Object? get owner => _owner; + Object? _owner; + + /// Whether this node is in a tree whose root is attached to something. + /// + /// This becomes true during the call to [attach]. + /// + /// This becomes false during the call to [detach]. + bool get attached => _owner != null; + + /// Mark this node as attached to the given owner. + /// + /// Typically called only from the [parent]'s [attach] method, and by the + /// [owner] to mark the root of a tree as attached. + /// + /// Subclasses with children should override this method to + /// [attach] all their children to the same [owner] + /// after calling the inherited method, as in `super.attach(owner)`. + @mustCallSuper + void attach(covariant Object owner) { + assert(_owner == null); + _owner = owner; + } + + /// Mark this node as detached. + /// + /// Typically called only from the [parent]'s [detach], and by the [owner] to + /// mark the root of a tree as detached. + /// + /// Subclasses with children should override this method to + /// [detach] all their children after calling the inherited method, + /// as in `super.detach()`. + @mustCallSuper + void detach() { + assert(_owner != null); + _owner = null; + assert(parent == null || attached == parent!.attached); + } + + /// The parent of this node in the tree. + AbstractNode? get parent => _parent; + AbstractNode? _parent; + + /// Mark the given node as being a child of this node. + /// + /// Subclasses should call this function when they acquire a new child. + @protected + @mustCallSuper + void adoptChild(covariant AbstractNode child) { + assert(child._parent == null); + assert(() { + AbstractNode node = this; + while (node.parent != null) { + node = node.parent!; + } + assert(node != child); // indicates we are about to create a cycle + return true; + }()); + child._parent = this; + if (attached) { + child.attach(_owner!); + } + redepthChild(child); + } + + /// Disconnect the given node from this node. + /// + /// Subclasses should call this function when they lose a child. + @protected + @mustCallSuper + void dropChild(covariant AbstractNode child) { + assert(child._parent == this); + assert(child.attached == attached); + child._parent = null; + if (attached) { + child.detach(); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/object.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/object.dart new file mode 100644 index 0000000000000000000000000000000000000000..a95d800c59a9445da92448d946b6df84c666c106 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/object.dart @@ -0,0 +1,18 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Framework code should use this method in favor of calling `toString` on +/// [Object.runtimeType]. +/// +/// Calling `toString` on a runtime type is a non-trivial operation that can +/// negatively impact performance. If asserts are enabled, this method will +/// return `object.runtimeType.toString()`; otherwise, it will return the +/// [optimizedValue], which must be a simple constant string. +String objectRuntimeType(Object? object, String optimizedValue) { + assert(() { + optimizedValue = object.runtimeType.toString(); + return true; + }()); + return optimizedValue; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/observer_list.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/observer_list.dart new file mode 100644 index 0000000000000000000000000000000000000000..27878026ee37737be17a3835df10d69f2bdf292d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/observer_list.dart @@ -0,0 +1,140 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; + +/// A list optimized for the observer pattern when there are small numbers of +/// observers. +/// +/// Consider using an [ObserverList] instead of a [List] when the number of +/// [contains] calls dominates the number of [add] and [remove] calls. +/// +/// This class will include in the [iterator] each added item in the order it +/// was added, as many times as it was added. +/// +/// If there will be a large number of observers, consider using +/// [HashedObserverList] instead. It has slightly different iteration semantics, +/// but serves a similar purpose, while being more efficient for large numbers +/// of observers. +/// +/// See also: +/// +/// * [HashedObserverList] for a list that is optimized for larger numbers of +/// observers. +// TODO(ianh): Use DelegatingIterable, possibly moving it from the collection +// package to foundation, or to dart:collection. +class ObserverList extends Iterable { + final List _list = []; + bool _isDirty = false; + late final HashSet _set = HashSet(); + + /// Adds an item to the end of this list. + /// + /// This operation has constant time complexity. + void add(T item) { + _isDirty = true; + _list.add(item); + } + + /// Removes an item from the list. + /// + /// This is O(N) in the number of items in the list. + /// + /// Returns whether the item was present in the list. + bool remove(T item) { + _isDirty = true; + _set.clear(); // Clear the set so that we don't leak items. + return _list.remove(item); + } + + /// Removes all items from the list. + void clear() { + _isDirty = false; + _list.clear(); + _set.clear(); + } + + @override + bool contains(Object? element) { + if (_list.length < 3) { + return _list.contains(element); + } + + if (_isDirty) { + _set.addAll(_list); + _isDirty = false; + } + + return _set.contains(element); + } + + @override + Iterator get iterator => _list.iterator; + + @override + bool get isEmpty => _list.isEmpty; + + @override + bool get isNotEmpty => _list.isNotEmpty; + + @override + List toList({bool growable = true}) { + return _list.toList(growable: growable); + } +} + +/// A list optimized for the observer pattern, but for larger numbers of observers. +/// +/// For small numbers of observers (e.g. less than 10), use [ObserverList] instead. +/// +/// The iteration semantics of the this class are slightly different from +/// [ObserverList]. This class will only return an item once in the [iterator], +/// no matter how many times it was added, although it does require that an item +/// be removed as many times as it was added for it to stop appearing in the +/// [iterator]. It will return them in the order the first instance of an item +/// was originally added. +/// +/// See also: +/// +/// * [ObserverList] for a list that is fast for small numbers of observers. +class HashedObserverList extends Iterable { + final LinkedHashMap _map = LinkedHashMap(); + + /// Adds an item to the end of this list. + /// + /// This has constant time complexity. + void add(T item) { + _map[item] = (_map[item] ?? 0) + 1; + } + + /// Removes an item from the list. + /// + /// This operation has constant time complexity. + /// + /// Returns whether the item was present in the list. + bool remove(T item) { + final int? value = _map[item]; + if (value == null) { + return false; + } + if (value == 1) { + _map.remove(item); + } else { + _map[item] = value - 1; + } + return true; + } + + @override + bool contains(Object? element) => _map.containsKey(element); + + @override + Iterator get iterator => _map.keys.iterator; + + @override + bool get isEmpty => _map.isEmpty; + + @override + bool get isNotEmpty => _map.isNotEmpty; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/persistent_hash_map.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/persistent_hash_map.dart new file mode 100644 index 0000000000000000000000000000000000000000..59bc692beb069e4c03b7b35936de2b098180a9ad --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/persistent_hash_map.dart @@ -0,0 +1,400 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// A collection of key/value pairs which provides efficient retrieval of +/// value by key. +/// +/// This class implements a persistent map: extending this map with a new +/// key/value pair does not modify an existing instance but instead creates a +/// new instance. +/// +/// Unlike [Map], this class does not support `null` as a key value and +/// implements only a functionality needed for a specific use case at the +/// core of the framework. +/// +/// Underlying implementation uses a variation of *hash array mapped trie* +/// data structure with compressed (bitmap indexed) nodes. +/// +/// See also: +/// +/// * [Bagwell, Phil. Ideal hash trees.](https://infoscience.epfl.ch/record/64398); +/// * [Steindorfer, Michael J., and Jurgen J. Vinju. "Optimizing hash-array mapped tries for fast and lean immutable JVM collections."](https://dl.acm.org/doi/abs/10.1145/2814270.2814312); +/// * [Clojure's `PersistentHashMap`](https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentHashMap.java). +/// +class PersistentHashMap { + /// Creates an empty hash map. + const PersistentHashMap.empty() : this._(null); + + const PersistentHashMap._(this._root); + + final _TrieNode? _root; + + /// If this map does not already contain the given [key] to [value] + /// mapping then create a new version of the map which contains + /// all mappings from the current one plus the given [key] to [value] + /// mapping. + PersistentHashMap put(K key, V value) { + final _TrieNode newRoot = + (_root ?? _CompressedNode.empty).put(0, key, key.hashCode, value); + if (newRoot == _root) { + return this; + } + return PersistentHashMap._(newRoot); + } + + /// Returns value associated with the given [key] or `null` if [key] + /// is not in the map. + @pragma('dart2js:as:trust') + V? operator[](K key) { + if (_root == null) { + return null; + } + + // Unfortunately can not use unsafeCast(...) here because it leads + // to worse code generation on VM. + return _root.get(0, key, key.hashCode) as V?; + } +} + +/// Base class for nodes in a hash trie. +/// +/// This trie is keyed by hash code bits using [hashBitsPerLevel] bits +/// at each level. +abstract class _TrieNode { + static const int hashBitsPerLevel = 5; + static const int hashBitsPerLevelMask = (1 << hashBitsPerLevel) - 1; + + @pragma('vm:prefer-inline') + static int trieIndex(int hash, int bitIndex) { + return (hash >>> bitIndex) & hashBitsPerLevelMask; + } + + /// Insert [key] to [value] mapping into the trie using bits from [keyHash] + /// starting at [bitIndex]. + _TrieNode put(int bitIndex, Object key, int keyHash, Object? value); + + /// Lookup a value associated with the given [key] using bits from [keyHash] + /// starting at [bitIndex]. + Object? get(int bitIndex, Object key, int keyHash); +} + +/// A full (uncompressed) node in the trie. +/// +/// It contains an array with `1<<_hashBitsPerLevel` elements which +/// are references to deeper nodes. +class _FullNode extends _TrieNode { + _FullNode(this.descendants); + + static const int numElements = 1 << _TrieNode.hashBitsPerLevel; + + // Caveat: this array is actually List<_TrieNode?> but typing it like that + // will introduce a type check when copying this array. For performance + // reasons we instead omit the type and use (implicit) casts when accessing + // it instead. + final List descendants; + + @override + _TrieNode put(int bitIndex, Object key, int keyHash, Object? value) { + final int index = _TrieNode.trieIndex(keyHash, bitIndex); + final _TrieNode node = _unsafeCast<_TrieNode?>(descendants[index]) ?? _CompressedNode.empty; + final _TrieNode newNode = node.put(bitIndex + _TrieNode.hashBitsPerLevel, key, keyHash, value); + return identical(newNode, node) + ? this + : _FullNode(_copy(descendants)..[index] = newNode); + } + + @override + Object? get(int bitIndex, Object key, int keyHash) { + final int index = _TrieNode.trieIndex(keyHash, bitIndex); + + final _TrieNode? node = _unsafeCast<_TrieNode?>(descendants[index]); + return node?.get(bitIndex + _TrieNode.hashBitsPerLevel, key, keyHash); + } +} + +/// Compressed node in the trie. +/// +/// Instead of storing the full array of outgoing edges this node uses a +/// compressed representation: +/// +/// * [_CompressedNode.occupied] has a bit set for indices which are occupied. +/// * furthermore, each occupied index can either be a `(key, value)` pair +/// representing an actual key/value mapping or a `(null, trieNode)` pair +/// representing a descendant node. +/// +/// Keys and values are stored together in a single array (instead of two +/// parallel arrays) for performance reasons: this improves memory access +/// locality and reduces memory usage (two arrays of length N take slightly +/// more space than one array of length 2*N). +class _CompressedNode extends _TrieNode { + _CompressedNode(this.occupiedIndices, this.keyValuePairs); + _CompressedNode._empty() : this(0, _emptyArray); + + factory _CompressedNode.single(int bitIndex, int keyHash, _TrieNode node) { + final int bit = 1 << _TrieNode.trieIndex(keyHash, bitIndex); + // A single (null, node) pair. + final List keyValuePairs = _makeArray(2) + ..[1] = node; + return _CompressedNode(bit, keyValuePairs); + } + + static final _CompressedNode empty = _CompressedNode._empty(); + + // Caveat: do not replace with [] or const [] this will + // introduce polymorphism in the keyValuePairs field and significantly + // degrade performance on the VM because it will no longer be able to + // devirtualize method calls on keyValuePairs. + static final List _emptyArray = _makeArray(0); + + // This bitmap only uses 32bits due to [_TrieNode.hashBitsPerLevel] being `5`. + final int occupiedIndices; + final List keyValuePairs; + + @override + _TrieNode put(int bitIndex, Object key, int keyHash, Object? value) { + final int bit = 1 << _TrieNode.trieIndex(keyHash, bitIndex); + final int index = _compressedIndex(bit); + + if ((occupiedIndices & bit) != 0) { + // Index is occupied. + final Object? keyOrNull = keyValuePairs[2 * index]; + final Object? valueOrNode = keyValuePairs[2 * index + 1]; + + // Is this a (null, trieNode) pair? + if (identical(keyOrNull, null)) { + final _TrieNode newNode = _unsafeCast<_TrieNode>(valueOrNode).put( + bitIndex + _TrieNode.hashBitsPerLevel, key, keyHash, value); + if (newNode == valueOrNode) { + return this; + } + return _CompressedNode( + occupiedIndices, _copy(keyValuePairs)..[2 * index + 1] = newNode); + } + + if (key == keyOrNull) { + // Found key/value pair with a matching key. If values match + // then avoid doing anything otherwise copy and update. + return identical(value, valueOrNode) + ? this + : _CompressedNode( + occupiedIndices, _copy(keyValuePairs)..[2 * index + 1] = value); + } + + // Two different keys at the same index, resolve collision. + final _TrieNode newNode = _resolveCollision( + bitIndex + _TrieNode.hashBitsPerLevel, + keyOrNull, + valueOrNode, + key, + keyHash, + value); + return _CompressedNode( + occupiedIndices, + _copy(keyValuePairs) + ..[2 * index] = null + ..[2 * index + 1] = newNode); + } else { + // Adding new key/value mapping. + final int occupiedCount = _bitCount(occupiedIndices); + if (occupiedCount >= 16) { + // Too many occupied: inflate compressed node into full node and + // update descendant at the corresponding index. + return _inflate(bitIndex) + ..descendants[_TrieNode.trieIndex(keyHash, bitIndex)] = + _CompressedNode.empty.put( + bitIndex + _TrieNode.hashBitsPerLevel, key, keyHash, value); + } else { + // Grow keyValuePairs by inserting key/value pair at the given + // index. + final int prefixLength = 2 * index; + final int totalLength = 2 * occupiedCount; + final List newKeyValuePairs = _makeArray(totalLength + 2); + for (int srcIndex = 0; srcIndex < prefixLength; srcIndex++) { + newKeyValuePairs[srcIndex] = keyValuePairs[srcIndex]; + } + newKeyValuePairs[prefixLength] = key; + newKeyValuePairs[prefixLength + 1] = value; + for (int srcIndex = prefixLength, dstIndex = prefixLength + 2; + srcIndex < totalLength; + srcIndex++, dstIndex++) { + newKeyValuePairs[dstIndex] = keyValuePairs[srcIndex]; + } + return _CompressedNode(occupiedIndices | bit, newKeyValuePairs); + } + } + } + + @override + Object? get(int bitIndex, Object key, int keyHash) { + final int bit = 1 << _TrieNode.trieIndex(keyHash, bitIndex); + if ((occupiedIndices & bit) == 0) { + return null; + } + final int index = _compressedIndex(bit); + final Object? keyOrNull = keyValuePairs[2 * index]; + final Object? valueOrNode = keyValuePairs[2 * index + 1]; + if (keyOrNull == null) { + final _TrieNode node = _unsafeCast<_TrieNode>(valueOrNode); + return node.get(bitIndex + _TrieNode.hashBitsPerLevel, key, keyHash); + } + if (key == keyOrNull) { + return valueOrNode; + } + return null; + } + + /// Convert this node into an equivalent [_FullNode]. + _FullNode _inflate(int bitIndex) { + final List nodes = _makeArray(_FullNode.numElements); + int srcIndex = 0; + for (int dstIndex = 0; dstIndex < _FullNode.numElements; dstIndex++) { + if (((occupiedIndices >>> dstIndex) & 1) != 0) { + final Object? keyOrNull = keyValuePairs[srcIndex]; + if (keyOrNull == null) { + nodes[dstIndex] = keyValuePairs[srcIndex + 1]; + } else { + nodes[dstIndex] = _CompressedNode.empty.put( + bitIndex + _TrieNode.hashBitsPerLevel, + keyOrNull, + keyValuePairs[srcIndex].hashCode, + keyValuePairs[srcIndex + 1]); + } + srcIndex += 2; + } + } + return _FullNode(nodes); + } + + @pragma('vm:prefer-inline') + int _compressedIndex(int bit) { + return _bitCount(occupiedIndices & (bit - 1)); + } + + static _TrieNode _resolveCollision(int bitIndex, Object existingKey, + Object? existingValue, Object key, int keyHash, Object? value) { + final int existingKeyHash = existingKey.hashCode; + // Check if this is a full hash collision and use _HashCollisionNode + // in this case. + return (existingKeyHash == keyHash) + ? _HashCollisionNode.fromCollision( + keyHash, existingKey, existingValue, key, value) + : _CompressedNode.empty + .put(bitIndex, existingKey, existingKeyHash, existingValue) + .put(bitIndex, key, keyHash, value); + } +} + +/// Trie node representing a full hash collision. +/// +/// Stores a list of key/value pairs (where all keys have the same hash code). +class _HashCollisionNode extends _TrieNode { + _HashCollisionNode(this.hash, this.keyValuePairs); + + factory _HashCollisionNode.fromCollision( + int keyHash, Object keyA, Object? valueA, Object keyB, Object? valueB) { + final List list = _makeArray(4); + list[0] = keyA; + list[1] = valueA; + list[2] = keyB; + list[3] = valueB; + return _HashCollisionNode(keyHash, list); + } + + final int hash; + final List keyValuePairs; + + @override + _TrieNode put(int bitIndex, Object key, int keyHash, Object? val) { + // Is this another full hash collision? + if (keyHash == hash) { + final int index = _indexOf(key); + if (index != -1) { + return identical(keyValuePairs[index + 1], val) + ? this + : _HashCollisionNode( + keyHash, _copy(keyValuePairs)..[index + 1] = val); + } + final int length = keyValuePairs.length; + final List newArray = _makeArray(length + 2); + for (int i = 0; i < length; i++) { + newArray[i] = keyValuePairs[i]; + } + newArray[length] = key; + newArray[length + 1] = val; + return _HashCollisionNode(keyHash, newArray); + } + + // Not a full hash collision, need to introduce a _CompressedNode which + // uses previously unused bits. + return _CompressedNode.single(bitIndex, hash, this) + .put(bitIndex, key, keyHash, val); + } + + @override + Object? get(int bitIndex, Object key, int keyHash) { + final int index = _indexOf(key); + return index < 0 ? null : keyValuePairs[index + 1]; + } + + int _indexOf(Object key) { + final int length = keyValuePairs.length; + for (int i = 0; i < length; i += 2) { + if (key == keyValuePairs[i]) { + return i; + } + } + return -1; + } +} + +/// Returns number of bits set in a 32bit integer. +/// +/// dart2js safe because we work with 32bit integers. +@pragma('vm:prefer-inline') +@pragma('dart2js:tryInline') +int _bitCount(int n) { + assert((n & 0xFFFFFFFF) == n); + n = n - ((n >> 1) & 0x55555555); + n = (n & 0x33333333) + ((n >>> 2) & 0x33333333); + n = (n + (n >> 4)) & 0x0F0F0F0F; + n = n + (n >> 8); + n = n + (n >> 16); + return n & 0x0000003F; +} + +/// Create a copy of the given array. +/// +/// Caveat: do not replace with List.of or similar methods. They are +/// considerably slower. +@pragma('vm:prefer-inline') +@pragma('dart2js:tryInline') +List _copy(List array) { + final List clone = _makeArray(array.length); + for (int j = 0; j < array.length; j++) { + clone[j] = array[j]; + } + return clone; +} + +/// Create a fixed-length array of the given length filled with `null`. +/// +/// We are using fixed length arrays because they are smaller and +/// faster to access on VM. Growable arrays are represented by 2 objects +/// (growable array instance pointing to a fixed array instance) and +/// consequently fixed length arrays are faster to allocated, require less +/// memory and are faster to access (less indirections). +@pragma('vm:prefer-inline') +@pragma('dart2js:tryInline') +List _makeArray(int length) { + return List.filled(length, null); +} + +/// This helper method becomes an no-op when compiled with dart2js on +/// with high level of optimizations enabled. +@pragma('dart2js:tryInline') +@pragma('dart2js:as:trust') +@pragma('vm:prefer-inline') +T _unsafeCast(Object? o) { + return o as T; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/platform.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/platform.dart new file mode 100644 index 0000000000000000000000000000000000000000..60d90b22d773078a5ebb242d1c5222ff5ac08131 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/platform.dart @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '_platform_io.dart' + if (dart.library.js_util) '_platform_web.dart' as platform; + +/// The [TargetPlatform] that matches the platform on which the framework is +/// currently executing. +/// +/// This is the default value of [ThemeData.platform] (hence the name). Widgets +/// from the material library should use [Theme.of] to determine the current +/// platform for styling purposes, rather than using [defaultTargetPlatform]. +/// Widgets and render objects at lower layers that try to emulate the +/// underlying platform can depend on [defaultTargetPlatform] directly. The +/// [dart:io.Platform] object should only be used directly when it's critical to +/// actually know the current platform, without any overrides possible (for +/// example, when a system API is about to be called). +/// +/// In a test environment, the platform returned is [TargetPlatform.android] +/// regardless of the host platform. (Android was chosen because the tests were +/// originally written assuming Android-like behavior, and we added platform +/// adaptations for iOS later). Tests can check iOS behavior by using the +/// platform override APIs (such as [ThemeData.platform] in the material +/// library) or by setting [debugDefaultTargetPlatformOverride]. +/// +/// Tests can also create specific platform tests by and adding a `variant:` +/// argument to the test and using a [TargetPlatformVariant]. +/// +/// See also: +/// +/// * [kIsWeb], a boolean which is true if the application is running on the +/// web, where [defaultTargetPlatform] returns which platform the browser is +/// running on. +// +// When adding support for a new platform (e.g. Windows Phone, Raspberry Pi), +// first create a new value on the [TargetPlatform] enum, then add a rule for +// selecting that platform in `_platform_io.dart` and `_platform_web.dart`. +// +// It would be incorrect to make a platform that isn't supported by +// [TargetPlatform] default to the behavior of another platform, because doing +// that would mean we'd be stuck with that platform forever emulating the other, +// and we'd never be able to introduce dedicated behavior for that platform +// (since doing so would be a big breaking change). +TargetPlatform get defaultTargetPlatform => platform.defaultTargetPlatform; + +/// The platform that user interaction should adapt to target. +/// +/// The [defaultTargetPlatform] getter returns the current platform. +/// +/// When using the "flutter run" command, the "o" key will toggle between +/// values of this enum when updating [debugDefaultTargetPlatformOverride]. +/// This lets one test how the application will work on various platforms +/// without having to switch emulators or physical devices. +// +// When you add values here, make sure to also add them to +// nextPlatform() in flutter_tools/lib/src/resident_runner.dart so that +// the tool can support the new platform for its "o" option. +enum TargetPlatform { + /// Android: + android, + + /// Fuchsia: + fuchsia, + + /// iOS: + iOS, + + /// Linux: + linux, + + /// macOS: + macOS, + + /// Windows: + windows, +} + +/// Override the [defaultTargetPlatform]. +/// +/// Setting this to null returns the [defaultTargetPlatform] to its original +/// value (based on the actual current platform). +/// +/// Generally speaking this override is only useful for tests. To change the +/// platform that widgets resemble, consider using the platform override APIs +/// (such as [ThemeData.platform] in the material library) instead. +/// +/// Setting [debugDefaultTargetPlatformOverride] (as opposed to, say, +/// [ThemeData.platform]) will cause unexpected and undesirable effects. For +/// example, setting this to [TargetPlatform.iOS] when the application is +/// running on Android will cause the TalkBack accessibility tool on Android to +/// be confused because it would be receiving data intended for iOS VoiceOver. +/// Similarly, setting it to [TargetPlatform.android] while on iOS will cause +/// certainly widgets to work assuming the presence of a system-wide back +/// button, which will make those widgets unusable since iOS has no such button. +/// +/// In general, therefore, this property should not be used in release builds. +TargetPlatform? debugDefaultTargetPlatformOverride; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/print.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/print.dart new file mode 100644 index 0000000000000000000000000000000000000000..25b6c8f291708a644df5798e62762b855ae94799 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/print.dart @@ -0,0 +1,194 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file implements debugPrint in terms of print, so avoiding +// calling "print" is sort of a non-starter here... +// ignore_for_file: avoid_print + +import 'dart:async'; +import 'dart:collection'; + +/// Signature for [debugPrint] implementations. +/// +/// If a [wrapWidth] is provided, each line of the [message] is word-wrapped to +/// that width. (Lines may be separated by newline characters, as in '\n'.) +/// +/// By default, this function very crudely attempts to throttle the rate at +/// which messages are sent to avoid data loss on Android. This means that +/// interleaving calls to this function (directly or indirectly via, e.g., +/// [debugDumpRenderTree] or [debugDumpApp]) and to the Dart [print] method can +/// result in out-of-order messages in the logs. +/// +/// The implementation of this function can be replaced by setting the +/// [debugPrint] variable to a new implementation that matches the +/// [DebugPrintCallback] signature. For example, flutter_test does this. +/// +/// The default value is [debugPrintThrottled]. For a version that acts +/// identically but does not throttle, use [debugPrintSynchronously]. +typedef DebugPrintCallback = void Function(String? message, { int? wrapWidth }); + +/// Prints a message to the console, which you can access using the "flutter" +/// tool's "logs" command ("flutter logs"). +/// +/// See also: +/// +/// * [DebugPrintCallback], for function parameters and usage details. +/// * [debugPrintThrottled], the default implementation. +DebugPrintCallback debugPrint = debugPrintThrottled; + +/// Alternative implementation of [debugPrint] that does not throttle. +/// Used by tests. +void debugPrintSynchronously(String? message, { int? wrapWidth }) { + if (message != null && wrapWidth != null) { + print(message.split('\n').expand((String line) => debugWordWrap(line, wrapWidth)).join('\n')); + } else { + print(message); + } +} + +/// Implementation of [debugPrint] that throttles messages. This avoids dropping +/// messages on platforms that rate-limit their logging (for example, Android). +/// +/// If `wrapWidth` is not null, the message is wrapped using [debugWordWrap]. +void debugPrintThrottled(String? message, { int? wrapWidth }) { + final List messageLines = message?.split('\n') ?? ['null']; + if (wrapWidth != null) { + _debugPrintBuffer.addAll(messageLines.expand((String line) => debugWordWrap(line, wrapWidth))); + } else { + _debugPrintBuffer.addAll(messageLines); + } + if (!_debugPrintScheduled) { + _debugPrintTask(); + } +} +int _debugPrintedCharacters = 0; +const int _kDebugPrintCapacity = 12 * 1024; +const Duration _kDebugPrintPauseTime = Duration(seconds: 1); +final Queue _debugPrintBuffer = Queue(); +final Stopwatch _debugPrintStopwatch = Stopwatch(); // flutter_ignore: stopwatch (see analyze.dart) +// Ignore context: This is not used in tests, only for throttled logging. +Completer? _debugPrintCompleter; +bool _debugPrintScheduled = false; +void _debugPrintTask() { + _debugPrintScheduled = false; + if (_debugPrintStopwatch.elapsed > _kDebugPrintPauseTime) { + _debugPrintStopwatch.stop(); + _debugPrintStopwatch.reset(); + _debugPrintedCharacters = 0; + } + while (_debugPrintedCharacters < _kDebugPrintCapacity && _debugPrintBuffer.isNotEmpty) { + final String line = _debugPrintBuffer.removeFirst(); + _debugPrintedCharacters += line.length; // TODO(ianh): Use the UTF-8 byte length instead + print(line); + } + if (_debugPrintBuffer.isNotEmpty) { + _debugPrintScheduled = true; + _debugPrintedCharacters = 0; + Timer(_kDebugPrintPauseTime, _debugPrintTask); + _debugPrintCompleter ??= Completer(); + } else { + _debugPrintStopwatch.start(); + _debugPrintCompleter?.complete(); + _debugPrintCompleter = null; + } +} + +/// A Future that resolves when there is no longer any buffered content being +/// printed by [debugPrintThrottled] (which is the default implementation for +/// [debugPrint], which is used to report errors to the console). +Future get debugPrintDone => _debugPrintCompleter?.future ?? Future.value(); + +final RegExp _indentPattern = RegExp('^ *(?:[-+*] |[0-9]+[.):] )?'); +enum _WordWrapParseMode { inSpace, inWord, atBreak } + +/// Wraps the given string at the given width. +/// +/// The `message` should not contain newlines (`\n`, U+000A). Strings that may +/// contain newlines should be [String.split] before being wrapped. +/// +/// Wrapping occurs at space characters (U+0020). Lines that start with an +/// octothorpe ("#", U+0023) are not wrapped (so for example, Dart stack traces +/// won't be wrapped). +/// +/// Subsequent lines attempt to duplicate the indentation of the first line, for +/// example if the first line starts with multiple spaces. In addition, if a +/// `wrapIndent` argument is provided, each line after the first is prefixed by +/// that string. +/// +/// This is not suitable for use with arbitrary Unicode text. For example, it +/// doesn't implement UAX #14, can't handle ideographic text, doesn't hyphenate, +/// and so forth. It is only intended for formatting error messages. +/// +/// The default [debugPrint] implementation uses this for its line wrapping. +Iterable debugWordWrap(String message, int width, { String wrapIndent = '' }) { + if (message.length < width || message.trimLeft()[0] == '#') { + return [message]; + } + final List wrapped = []; + final Match prefixMatch = _indentPattern.matchAsPrefix(message)!; + final String prefix = wrapIndent + ' ' * prefixMatch.group(0)!.length; + int start = 0; + int startForLengthCalculations = 0; + bool addPrefix = false; + int index = prefix.length; + _WordWrapParseMode mode = _WordWrapParseMode.inSpace; + late int lastWordStart; + int? lastWordEnd; + while (true) { + switch (mode) { + case _WordWrapParseMode.inSpace: // at start of break point (or start of line); can't break until next break + while ((index < message.length) && (message[index] == ' ')) { + index += 1; + } + lastWordStart = index; + mode = _WordWrapParseMode.inWord; + case _WordWrapParseMode.inWord: // looking for a good break point + while ((index < message.length) && (message[index] != ' ')) { + index += 1; + } + mode = _WordWrapParseMode.atBreak; + case _WordWrapParseMode.atBreak: // at start of break point + if ((index - startForLengthCalculations > width) || (index == message.length)) { + // we are over the width line, so break + if ((index - startForLengthCalculations <= width) || (lastWordEnd == null)) { + // we should use this point, because either it doesn't actually go over the + // end (last line), or it does, but there was no earlier break point + lastWordEnd = index; + } + if (addPrefix) { + wrapped.add(prefix + message.substring(start, lastWordEnd)); + } else { + wrapped.add(message.substring(start, lastWordEnd)); + addPrefix = true; + } + if (lastWordEnd >= message.length) { + return wrapped; + } + // just yielded a line + if (lastWordEnd == index) { + // we broke at current position + // eat all the spaces, then set our start point + while ((index < message.length) && (message[index] == ' ')) { + index += 1; + } + start = index; + mode = _WordWrapParseMode.inWord; + } else { + // we broke at the previous break point, and we're at the start of a new one + assert(lastWordStart > lastWordEnd); + start = lastWordStart; + mode = _WordWrapParseMode.atBreak; + } + startForLengthCalculations = start - prefix.length; + assert(addPrefix); + lastWordEnd = null; + } else { + // save this break point, we're not yet over the line width + lastWordEnd = index; + // skip to the end of this break point + mode = _WordWrapParseMode.inSpace; + } + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/serialization.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/serialization.dart new file mode 100644 index 0000000000000000000000000000000000000000..bdeaecc51ad86a6864446e03ac337b3a84f43fe6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/serialization.dart @@ -0,0 +1,270 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:typed_data'; + +export 'dart:typed_data' show ByteData, Endian, Float32List, Float64List, Int32List, Int64List, Uint8List; + +/// Write-only buffer for incrementally building a [ByteData] instance. +/// +/// A WriteBuffer instance can be used only once. Attempts to reuse will result +/// in [StateError]s being thrown. +/// +/// The byte order used is [Endian.host] throughout. +class WriteBuffer { + /// Creates an interface for incrementally building a [ByteData] instance. + /// [startCapacity] determines the start size of the [WriteBuffer] in bytes. + /// The closer that value is to the real size used, the better the + /// performance. + factory WriteBuffer({int startCapacity = 8}) { + assert(startCapacity > 0); + final ByteData eightBytes = ByteData(8); + final Uint8List eightBytesAsList = eightBytes.buffer.asUint8List(); + return WriteBuffer._(Uint8List(startCapacity), eightBytes, eightBytesAsList); + } + + WriteBuffer._(this._buffer, this._eightBytes, this._eightBytesAsList); + + Uint8List _buffer; + int _currentSize = 0; + bool _isDone = false; + final ByteData _eightBytes; + final Uint8List _eightBytesAsList; + static final Uint8List _zeroBuffer = Uint8List(8); + + void _add(int byte) { + if (_currentSize == _buffer.length) { + _resize(); + } + _buffer[_currentSize] = byte; + _currentSize += 1; + } + + void _append(Uint8List other) { + final int newSize = _currentSize + other.length; + if (newSize >= _buffer.length) { + _resize(newSize); + } + _buffer.setRange(_currentSize, newSize, other); + _currentSize += other.length; + } + + void _addAll(Uint8List data, [int start = 0, int? end]) { + final int newEnd = end ?? _eightBytesAsList.length; + final int newSize = _currentSize + (newEnd - start); + if (newSize >= _buffer.length) { + _resize(newSize); + } + _buffer.setRange(_currentSize, newSize, data); + _currentSize = newSize; + } + + void _resize([int? requiredLength]) { + final int doubleLength = _buffer.length * 2; + final int newLength = math.max(requiredLength ?? 0, doubleLength); + final Uint8List newBuffer = Uint8List(newLength); + newBuffer.setRange(0, _buffer.length, _buffer); + _buffer = newBuffer; + } + + /// Write a Uint8 into the buffer. + void putUint8(int byte) { + assert(!_isDone); + _add(byte); + } + + /// Write a Uint16 into the buffer. + void putUint16(int value, {Endian? endian}) { + assert(!_isDone); + _eightBytes.setUint16(0, value, endian ?? Endian.host); + _addAll(_eightBytesAsList, 0, 2); + } + + /// Write a Uint32 into the buffer. + void putUint32(int value, {Endian? endian}) { + assert(!_isDone); + _eightBytes.setUint32(0, value, endian ?? Endian.host); + _addAll(_eightBytesAsList, 0, 4); + } + + /// Write an Int32 into the buffer. + void putInt32(int value, {Endian? endian}) { + assert(!_isDone); + _eightBytes.setInt32(0, value, endian ?? Endian.host); + _addAll(_eightBytesAsList, 0, 4); + } + + /// Write an Int64 into the buffer. + void putInt64(int value, {Endian? endian}) { + assert(!_isDone); + _eightBytes.setInt64(0, value, endian ?? Endian.host); + _addAll(_eightBytesAsList, 0, 8); + } + + /// Write an Float64 into the buffer. + void putFloat64(double value, {Endian? endian}) { + assert(!_isDone); + _alignTo(8); + _eightBytes.setFloat64(0, value, endian ?? Endian.host); + _addAll(_eightBytesAsList); + } + + /// Write all the values from a [Uint8List] into the buffer. + void putUint8List(Uint8List list) { + assert(!_isDone); + _append(list); + } + + /// Write all the values from an [Int32List] into the buffer. + void putInt32List(Int32List list) { + assert(!_isDone); + _alignTo(4); + _append(list.buffer.asUint8List(list.offsetInBytes, 4 * list.length)); + } + + /// Write all the values from an [Int64List] into the buffer. + void putInt64List(Int64List list) { + assert(!_isDone); + _alignTo(8); + _append(list.buffer.asUint8List(list.offsetInBytes, 8 * list.length)); + } + + /// Write all the values from a [Float32List] into the buffer. + void putFloat32List(Float32List list) { + assert(!_isDone); + _alignTo(4); + _append(list.buffer.asUint8List(list.offsetInBytes, 4 * list.length)); + } + + /// Write all the values from a [Float64List] into the buffer. + void putFloat64List(Float64List list) { + assert(!_isDone); + _alignTo(8); + _append(list.buffer.asUint8List(list.offsetInBytes, 8 * list.length)); + } + + void _alignTo(int alignment) { + assert(!_isDone); + final int mod = _currentSize % alignment; + if (mod != 0) { + _addAll(_zeroBuffer, 0, alignment - mod); + } + } + + /// Finalize and return the written [ByteData]. + ByteData done() { + if (_isDone) { + throw StateError('done() must not be called more than once on the same $runtimeType.'); + } + final ByteData result = _buffer.buffer.asByteData(0, _currentSize); + _buffer = Uint8List(0); + _isDone = true; + return result; + } +} + +/// Read-only buffer for reading sequentially from a [ByteData] instance. +/// +/// The byte order used is [Endian.host] throughout. +class ReadBuffer { + /// Creates a [ReadBuffer] for reading from the specified [data]. + ReadBuffer(this.data); + + /// The underlying data being read. + final ByteData data; + + /// The position to read next. + int _position = 0; + + /// Whether the buffer has data remaining to read. + bool get hasRemaining => _position < data.lengthInBytes; + + /// Reads a Uint8 from the buffer. + int getUint8() { + return data.getUint8(_position++); + } + + /// Reads a Uint16 from the buffer. + int getUint16({Endian? endian}) { + final int value = data.getUint16(_position, endian ?? Endian.host); + _position += 2; + return value; + } + + /// Reads a Uint32 from the buffer. + int getUint32({Endian? endian}) { + final int value = data.getUint32(_position, endian ?? Endian.host); + _position += 4; + return value; + } + + /// Reads an Int32 from the buffer. + int getInt32({Endian? endian}) { + final int value = data.getInt32(_position, endian ?? Endian.host); + _position += 4; + return value; + } + + /// Reads an Int64 from the buffer. + int getInt64({Endian? endian}) { + final int value = data.getInt64(_position, endian ?? Endian.host); + _position += 8; + return value; + } + + /// Reads a Float64 from the buffer. + double getFloat64({Endian? endian}) { + _alignTo(8); + final double value = data.getFloat64(_position, endian ?? Endian.host); + _position += 8; + return value; + } + + /// Reads the given number of Uint8s from the buffer. + Uint8List getUint8List(int length) { + final Uint8List list = data.buffer.asUint8List(data.offsetInBytes + _position, length); + _position += length; + return list; + } + + /// Reads the given number of Int32s from the buffer. + Int32List getInt32List(int length) { + _alignTo(4); + final Int32List list = data.buffer.asInt32List(data.offsetInBytes + _position, length); + _position += 4 * length; + return list; + } + + /// Reads the given number of Int64s from the buffer. + Int64List getInt64List(int length) { + _alignTo(8); + final Int64List list = data.buffer.asInt64List(data.offsetInBytes + _position, length); + _position += 8 * length; + return list; + } + + /// Reads the given number of Float32s from the buffer + Float32List getFloat32List(int length) { + _alignTo(4); + final Float32List list = data.buffer.asFloat32List(data.offsetInBytes + _position, length); + _position += 4 * length; + return list; + } + + /// Reads the given number of Float64s from the buffer. + Float64List getFloat64List(int length) { + _alignTo(8); + final Float64List list = data.buffer.asFloat64List(data.offsetInBytes + _position, length); + _position += 8 * length; + return list; + } + + void _alignTo(int alignment) { + final int mod = _position % alignment; + if (mod != 0) { + _position += alignment - mod; + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/service_extensions.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/service_extensions.dart new file mode 100644 index 0000000000000000000000000000000000000000..54d6874d1e76f07c0980be9bad7aaf8561c877bd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/service_extensions.dart @@ -0,0 +1,77 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Service extension constants for the foundation library. +/// +/// These constants will be used when registering service extensions in the +/// framework, and they will also be used by tools and services that call these +/// service extensions. +/// +/// The String value for each of these extension names should be accessed by +/// calling the `.name` property on the enum value. +enum FoundationServiceExtensions { + /// Name of service extension that, when called, will cause the entire + /// application to redraw. + /// + /// See also: + /// + /// * [BindingBase.initServiceExtensions], where the service extension is + /// registered. + reassemble, + + /// Name of service extension that, when called, will terminate the Flutter + /// application. + /// + /// See also: + /// + /// * [BindingBase.initServiceExtensions], where the service extension is + /// registered. + exit, + + /// Name of service extension that, when called, will get or set the value of + /// [connectedVmServiceUri]. + /// + /// See also: + /// + /// * [connectedVmServiceUri], which stores the uri for the connected vm service + /// protocol. + /// * [BindingBase.initServiceExtensions], where the service extension is + /// registered. + connectedVmServiceUri, + + /// Name of service extension that, when called, will get or set the value of + /// [activeDevToolsServerAddress]. + /// + /// See also: + /// + /// * [activeDevToolsServerAddress], which stores the address for the active + /// DevTools server used for debugging this application. + /// * [BindingBase.initServiceExtensions], where the service extension is + /// registered. + activeDevToolsServerAddress, + + + /// Name of service extension that, when called, will change the value of + /// [defaultTargetPlatform], which controls which [TargetPlatform] that the + /// framework will execute for. + /// + /// See also: + /// + /// * [debugDefaultTargetPlatformOverride], which is the flag that this service + /// extension exposes. + /// * [BindingBase.initServiceExtensions], where the service extension is + /// registered. + platformOverride, + + /// Name of service extension that, when called, will override the platform + /// [Brightness]. + /// + /// See also: + /// + /// * [debugBrightnessOverride], which is the flag that this service + /// extension exposes. + /// * [BindingBase.initServiceExtensions], where the service extension is + /// registered. + brightnessOverride, +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/stack_frame.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/stack_frame.dart new file mode 100644 index 0000000000000000000000000000000000000000..b45c82fb731c3183b06e20bbfb73ef214af27d12 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/stack_frame.dart @@ -0,0 +1,319 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:meta/meta.dart'; + +import 'constants.dart'; +import 'object.dart'; + +/// A object representation of a frame from a stack trace. +/// +/// {@tool snippet} +/// +/// This example creates a traversable list of parsed [StackFrame] objects from +/// the current [StackTrace]. +/// +/// ```dart +/// final List currentFrames = StackFrame.fromStackTrace(StackTrace.current); +/// ``` +/// {@end-tool} +@immutable +class StackFrame { + /// Creates a new StackFrame instance. + /// + /// The [className] may be the empty string if there is no class (e.g. for a + /// top level library method). + const StackFrame({ + required this.number, + required this.column, + required this.line, + required this.packageScheme, + required this.package, + required this.packagePath, + this.className = '', + required this.method, + this.isConstructor = false, + required this.source, + }); + + /// A stack frame representing an asynchronous suspension. + static const StackFrame asynchronousSuspension = StackFrame( + number: -1, + column: -1, + line: -1, + method: 'asynchronous suspension', + packageScheme: '', + package: '', + packagePath: '', + source: '', + ); + + /// A stack frame representing a Dart elided stack overflow frame. + static const StackFrame stackOverFlowElision = StackFrame( + number: -1, + column: -1, + line: -1, + method: '...', + packageScheme: '', + package: '', + packagePath: '', + source: '...', + ); + + /// Parses a list of [StackFrame]s from a [StackTrace] object. + /// + /// This is normally useful with [StackTrace.current]. + static List fromStackTrace(StackTrace stack) { + return fromStackString(stack.toString()); + } + + /// Parses a list of [StackFrame]s from the [StackTrace.toString] method. + static List fromStackString(String stack) { + return stack + .trim() + .split('\n') + .where((String line) => line.isNotEmpty) + .map(fromStackTraceLine) + // On the Web in non-debug builds the stack trace includes the exception + // message that precedes the stack trace itself. fromStackTraceLine will + // return null in that case. We will skip it here. + // TODO(polina-c): if one of lines was parsed to null, the entire stack trace + // is in unexpected format and should be returned as is, without partial parsing. + // https://github.com/flutter/flutter/issues/131877 + .whereType() + .toList(); + } + + /// Parses a single [StackFrame] from a line of a [StackTrace]. + /// + /// Returns null if format is not as expected. + static StackFrame? _tryParseWebFrame(String line) { + if (kDebugMode) { + return _tryParseWebDebugFrame(line); + } else { + return _tryParseWebNonDebugFrame(line); + } + } + + /// Parses a single [StackFrame] from a line of a [StackTrace]. + /// + /// Returns null if format is not as expected. + static StackFrame? _tryParseWebDebugFrame(String line) { + // This RegExp is only partially correct for flutter run/test differences. + // https://github.com/flutter/flutter/issues/52685 + final bool hasPackage = line.startsWith('package'); + final RegExp parser = hasPackage + ? RegExp(r'^(package.+) (\d+):(\d+)\s+(.+)$') + : RegExp(r'^(.+) (\d+):(\d+)\s+(.+)$'); + + final Match? match = parser.firstMatch(line); + + if (match == null) { + return null; + } + + String package = ''; + String packageScheme = ''; + String packagePath = ''; + + if (hasPackage) { + packageScheme = 'package'; + final Uri packageUri = Uri.parse(match.group(1)!); + package = packageUri.pathSegments[0]; + packagePath = packageUri.path.replaceFirst('${packageUri.pathSegments[0]}/', ''); + } + + return StackFrame( + number: -1, + packageScheme: packageScheme, + package: package, + packagePath: packagePath, + line: int.parse(match.group(2)!), + column: int.parse(match.group(3)!), + className: '', + method: match.group(4)!, + source: line, + ); + } + + // Non-debug builds do not point to dart code but compiled JavaScript, so + // line numbers are meaningless. We only attempt to parse the class and + // method name, which is more or less readable in profile builds, and + // minified in release builds. + static final RegExp _webNonDebugFramePattern = RegExp(r'^\s*at ([^\s]+).*$'); + + // Parses `line` as a stack frame in profile and release Web builds. If not + // recognized as a stack frame, returns null. + static StackFrame? _tryParseWebNonDebugFrame(String line) { + final Match? match = _webNonDebugFramePattern.firstMatch(line); + if (match == null) { + // On the Web in non-debug builds the stack trace includes the exception + // message that precedes the stack trace itself. Example: + // + // TypeError: Cannot read property 'hello$0' of null + // at _GalleryAppState.build$1 (http://localhost:8080/main.dart.js:149790:13) + // at StatefulElement.build$0 (http://localhost:8080/main.dart.js:129138:37) + // at StatefulElement.performRebuild$0 (http://localhost:8080/main.dart.js:129032:23) + // + // Instead of crashing when a line is not recognized as a stack frame, we + // return null. The caller, such as fromStackString, can then just skip + // this frame. + return null; + } + + final List classAndMethod = match.group(1)!.split('.'); + final String className = classAndMethod.length > 1 ? classAndMethod.first : ''; + final String method = classAndMethod.length > 1 + ? classAndMethod.skip(1).join('.') + : classAndMethod.single; + + return StackFrame( + number: -1, + packageScheme: '', + package: '', + packagePath: '', + line: -1, + column: -1, + className: className, + method: method, + source: line, + ); + } + + /// Parses a single [StackFrame] from a single line of a [StackTrace]. + /// + /// Returns null if format is not as expected. + static StackFrame? fromStackTraceLine(String line) { + if (line == '') { + return asynchronousSuspension; + } else if (line == '...') { + return stackOverFlowElision; + } + + assert( + line != '===== asynchronous gap ===========================', + 'Got a stack frame from package:stack_trace, where a vm or web frame was expected. ' + 'This can happen if FlutterError.demangleStackTrace was not set in an environment ' + 'that propagates non-standard stack traces to the framework, such as during tests.', + ); + + // Web frames. + if (!line.startsWith('#')) { + return _tryParseWebFrame(line); + } + + final RegExp parser = RegExp(r'^#(\d+) +(.+) \((.+?):?(\d+){0,1}:?(\d+){0,1}\)$'); + Match? match = parser.firstMatch(line); + assert(match != null, 'Expected $line to match $parser.'); + match = match!; + + bool isConstructor = false; + String className = ''; + String method = match.group(2)!.replaceAll('.', ''); + if (method.startsWith('new')) { + final List methodParts = method.split(' '); + // Sometimes a web frame will only read "new" and have no class name. + className = methodParts.length > 1 ? method.split(' ')[1] : ''; + method = ''; + if (className.contains('.')) { + final List parts = className.split('.'); + className = parts[0]; + method = parts[1]; + } + isConstructor = true; + } else if (method.contains('.')) { + final List parts = method.split('.'); + className = parts[0]; + method = parts[1]; + } + + final Uri packageUri = Uri.parse(match.group(3)!); + String package = ''; + String packagePath = packageUri.path; + if (packageUri.scheme == 'dart' || packageUri.scheme == 'package') { + package = packageUri.pathSegments[0]; + packagePath = packageUri.path.replaceFirst('${packageUri.pathSegments[0]}/', ''); + } + + return StackFrame( + number: int.parse(match.group(1)!), + className: className, + method: method, + packageScheme: packageUri.scheme, + package: package, + packagePath: packagePath, + line: match.group(4) == null ? -1 : int.parse(match.group(4)!), + column: match.group(5) == null ? -1 : int.parse(match.group(5)!), + isConstructor: isConstructor, + source: line, + ); + } + + /// The original source of this stack frame. + final String source; + + /// The zero-indexed frame number. + /// + /// This value may be -1 to indicate an unknown frame number. + final int number; + + /// The scheme of the package for this frame, e.g. "dart" for + /// dart:core/errors_patch.dart or "package" for + /// package:flutter/src/widgets/text.dart. + /// + /// The path property refers to the source file. + final String packageScheme; + + /// The package for this frame, e.g. "core" for + /// dart:core/errors_patch.dart or "flutter" for + /// package:flutter/src/widgets/text.dart. + final String package; + + /// The path of the file for this frame, e.g. "errors_patch.dart" for + /// dart:core/errors_patch.dart or "src/widgets/text.dart" for + /// package:flutter/src/widgets/text.dart. + final String packagePath; + + /// The source line number. + final int line; + + /// The source column number. + final int column; + + /// The class name, if any, for this frame. + /// + /// This may be null for top level methods in a library or anonymous closure + /// methods. + final String className; + + /// The method name for this frame. + /// + /// This will be an empty string if the stack frame is from the default + /// constructor. + final String method; + + /// Whether or not this was thrown from a constructor. + final bool isConstructor; + + @override + int get hashCode => Object.hash(number, package, line, column, className, method, source); + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is StackFrame + && other.number == number + && other.package == package + && other.line == line + && other.column == column + && other.className == className + && other.method == method + && other.source == source; + } + + @override + String toString() => '${objectRuntimeType(this, 'StackFrame')}(#$number, $packageScheme:$package/$packagePath:$line:$column, className: $className, method: $method)'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/synchronous_future.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/synchronous_future.dart new file mode 100644 index 0000000000000000000000000000000000000000..2b08456c69597a81bb69018db51054633106069e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/synchronous_future.dart @@ -0,0 +1,67 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +/// A [Future] whose [then] implementation calls the callback immediately. +/// +/// This is similar to [Future.value], except that the value is available in +/// the same event-loop iteration. +/// +/// ⚠ This class is useful in cases where you want to expose a single API, where +/// you normally want to have everything execute synchronously, but where on +/// rare occasions you want the ability to switch to an asynchronous model. **In +/// general use of this class should be avoided as it is very difficult to debug +/// such bimodal behavior.** +/// +/// A [SynchronousFuture] will never complete with an error. +class SynchronousFuture implements Future { + /// Creates a synchronous future. + /// + /// See also: + /// + /// * [Future.value] for information about creating a regular + /// [Future] that completes with a value. + SynchronousFuture(this._value); + + final T _value; + + @override + Stream asStream() { + final StreamController controller = StreamController(); + controller.add(_value); + controller.close(); + return controller.stream; + } + + @override + Future catchError(Function onError, { bool Function(Object error)? test }) => Completer().future; + + @override + Future then(FutureOr Function(T value) onValue, { Function? onError }) { + final FutureOr result = onValue(_value); + if (result is Future) { + return result; + } + return SynchronousFuture(result); + } + + @override + Future timeout(Duration timeLimit, { FutureOr Function()? onTimeout }) { + return Future.value(_value).timeout(timeLimit, onTimeout: onTimeout); + } + + @override + Future whenComplete(FutureOr Function() action) { + try { + final FutureOr result = action(); + if (result is Future) { + return result.then((dynamic value) => _value); + } + return this; + } catch (e, stack) { + return Future.error(e, stack); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/timeline.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/timeline.dart new file mode 100644 index 0000000000000000000000000000000000000000..b110ea0cb0f89c75f9fd6130c5ddba160f8de72a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/timeline.dart @@ -0,0 +1,432 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:developer'; +import 'dart:typed_data'; + +import 'package:meta/meta.dart'; + +import '_timeline_io.dart' + if (dart.library.js_util) '_timeline_web.dart' as impl; +import 'constants.dart'; + +/// Measures how long blocks of code take to run. +/// +/// This class can be used as a drop-in replacement for [Timeline] as it +/// provides methods compatible with [Timeline] signature-wise, and it has +/// minimal overhead. +/// +/// Provides [debugReset] and [debugCollect] methods that make it convenient to use in +/// frame-oriented environment where collected metrics can be attributed to a +/// frame, then aggregated into frame statistics, e.g. frame averages. +/// +/// Forwards measurements to [Timeline] so they appear in Flutter DevTools. +abstract final class FlutterTimeline { + static _BlockBuffer _buffer = _BlockBuffer(); + + /// Whether block timings are collected and can be retrieved using the + /// [debugCollect] method. + /// + /// This is always false in release mode. + static bool get debugCollectionEnabled => _collectionEnabled; + + /// Enables metric collection. + /// + /// Metric collection can only be enabled in non-release modes. It is most + /// useful in profile mode where application performance is representative + /// of a deployed application. + /// + /// When disabled, resets collected data by calling [debugReset]. + /// + /// Throws a [StateError] if invoked in release mode. + static set debugCollectionEnabled(bool value) { + if (kReleaseMode) { + throw _createReleaseModeNotSupportedError(); + } + if (value == _collectionEnabled) { + return; + } + _collectionEnabled = value; + debugReset(); + } + + static StateError _createReleaseModeNotSupportedError() { + return StateError('FlutterTimeline metric collection not supported in release mode.'); + } + + static bool _collectionEnabled = false; + + /// Start a synchronous operation labeled `name`. + /// + /// Optionally takes a map of `arguments`. This slice may also optionally be + /// associated with a [Flow] event. This operation must be finished by calling + /// [finishSync] before returning to the event queue. + /// + /// This is a drop-in replacement for [Timeline.startSync]. + static void startSync(String name, { Map? arguments, Flow? flow }) { + Timeline.startSync(name, arguments: arguments, flow: flow); + if (!kReleaseMode && _collectionEnabled) { + _buffer.startSync(name, arguments: arguments, flow: flow); + } + } + + /// Finish the last synchronous operation that was started. + /// + /// This is a drop-in replacement for [Timeline.finishSync]. + static void finishSync() { + Timeline.finishSync(); + if (!kReleaseMode && _collectionEnabled) { + _buffer.finishSync(); + } + } + + /// Emit an instant event. + /// + /// This is a drop-in replacement for [Timeline.instantSync]. + static void instantSync(String name, { Map? arguments }) { + Timeline.instantSync(name, arguments: arguments); + } + + /// A utility method to time a synchronous `function`. Internally calls + /// `function` bracketed by calls to [startSync] and [finishSync]. + /// + /// This is a drop-in replacement for [Timeline.timeSync]. + static T timeSync(String name, TimelineSyncFunction function, + { Map? arguments, Flow? flow }) { + startSync(name, arguments: arguments, flow: flow); + try { + return function(); + } finally { + finishSync(); + } + } + + /// The current time stamp from the clock used by the timeline in + /// microseconds. + /// + /// When run on the Dart VM, uses the same monotonic clock as the embedding + /// API's `Dart_TimelineGetMicros`. + /// + /// When run on the web, uses `window.performance.now`. + /// + /// This is a drop-in replacement for [Timeline.now]. + static int get now => impl.performanceTimestamp.toInt(); + + /// Returns timings collected since [debugCollectionEnabled] was set to true, + /// since the previous [debugCollect], or since the previous [debugReset], + /// whichever was last. + /// + /// Resets the collected timings. + /// + /// This is only meant to be used in non-release modes, typically in profile + /// mode that provides timings close to release mode timings. + static AggregatedTimings debugCollect() { + if (kReleaseMode) { + throw _createReleaseModeNotSupportedError(); + } + if (!_collectionEnabled) { + throw StateError('Timeline metric collection not enabled.'); + } + final AggregatedTimings result = AggregatedTimings(_buffer.computeTimings()); + debugReset(); + return result; + } + + /// Forgets all previously collected timing data. + /// + /// Use this method to scope metrics to a frame, a pointer event, or any + /// other event. To do that, call [debugReset] at the start of the event, then + /// call [debugCollect] at the end of the event. + /// + /// This is only meant to be used in non-release modes. + static void debugReset() { + if (kReleaseMode) { + throw _createReleaseModeNotSupportedError(); + } + _buffer = _BlockBuffer(); + } +} + +/// Provides [start], [end], and [duration] of a named block of code, timed by +/// [FlutterTimeline]. +@immutable +final class TimedBlock { + /// Creates a timed block of code from a [name], [start], and [end]. + /// + /// The [name] should be sufficiently unique and descriptive for someone to + /// easily tell which part of code was measured. + const TimedBlock({ + required this.name, + required this.start, + required this.end, + }) : assert(end >= start, 'The start timestamp must not be greater than the end timestamp.'); + + /// A readable label for a block of code that was measured. + /// + /// This field should be sufficiently unique and descriptive for someone to + /// easily tell which part of code was measured. + final String name; + + /// The timestamp in microseconds that marks the beginning of the measured + /// block of code. + final double start; + + /// The timestamp in microseconds that marks the end of the measured block of + /// code. + final double end; + + /// How long the measured block of code took to execute in microseconds. + double get duration => end - start; + + @override + String toString() { + return 'TimedBlock($name, $start, $end, $duration)'; + } +} + +/// Provides aggregated results for timings collected by [FlutterTimeline]. +@immutable +final class AggregatedTimings { + /// Creates aggregated timings for the provided timed blocks. + AggregatedTimings(this.timedBlocks); + + /// All timed blocks collected between the last reset and [FlutterTimeline.debugCollect]. + final List timedBlocks; + + /// Aggregated timed blocks collected between the last reset and [FlutterTimeline.debugCollect]. + /// + /// Does not guarantee that all code blocks will be reported. Only those that + /// executed since the last reset are listed here. Use [getAggregated] for + /// graceful handling of missing code blocks. + late final List aggregatedBlocks = _computeAggregatedBlocks(); + + List _computeAggregatedBlocks() { + final Map aggregate = {}; + for (final TimedBlock block in timedBlocks) { + final (double, int) previousValue = aggregate.putIfAbsent(block.name, () => (0, 0)); + aggregate[block.name] = (previousValue.$1 + block.duration, previousValue.$2 + 1); + } + return aggregate.entries.map( + (MapEntry entry) { + return AggregatedTimedBlock(name: entry.key, duration: entry.value.$1, count: entry.value.$2); + } + ).toList(); + } + + /// Returns aggregated numbers for a named block of code. + /// + /// If the block in question never executed since the last reset, returns an + /// aggregation with zero duration and count. + AggregatedTimedBlock getAggregated(String name) { + return aggregatedBlocks.singleWhere( + (AggregatedTimedBlock block) => block.name == name, + // Handle the case where there are no recorded blocks of the specified + // type. In this case, the aggregated duration is simply zero, and so is + // the number of occurrences (i.e. count). + orElse: () => AggregatedTimedBlock(name: name, duration: 0, count: 0), + ); + } +} + +/// Aggregates multiple [TimedBlock] objects that share a [name]. +/// +/// It is common for the same block of code to be executed multiple times within +/// a frame. It is useful to combine multiple executions and report the total +/// amount of time attributed to that block of code. +@immutable +final class AggregatedTimedBlock { + /// Creates a timed block of code from a [name] and [duration]. + /// + /// The [name] should be sufficiently unique and descriptive for someone to + /// easily tell which part of code was measured. + const AggregatedTimedBlock({ + required this.name, + required this.duration, + required this.count, + }) : assert(duration >= 0); + + /// A readable label for a block of code that was measured. + /// + /// This field should be sufficiently unique and descriptive for someone to + /// easily tell which part of code was measured. + final String name; + + /// The sum of [TimedBlock.duration] values of aggretaged blocks. + final double duration; + + /// The number of [TimedBlock] objects aggregated. + final int count; + + @override + String toString() { + return 'AggregatedTimedBlock($name, $duration, $count)'; + } +} + +const int _kSliceSize = 500; + +/// A growable list of float64 values with predictable [add] performance. +/// +/// The list is organized into a "chain" of [Float64List]s. The object starts +/// with a `Float64List` "slice". When [add] is called, the value is added to +/// the slice. Once the slice is full, it is moved into the chain, and a new +/// slice is allocated. Slice size is static and therefore its allocation has +/// predictable cost. This is unlike the default [List] implementation, which, +/// when full, doubles its buffer size and copies all old elements into the new +/// buffer, leading to unpredictable performance. This makes it a poor choice +/// for recording performance because buffer reallocation would affect the +/// runtime. +/// +/// The trade-off is that reading values back from the chain is more expensive +/// compared to [List] because it requires iterating over multiple slices. This +/// is a reasonable trade-off for performance metrics, because it is more +/// important to minimize the overhead while recording metrics, than it is when +/// reading them. +final class _Float64ListChain { + _Float64ListChain(); + + final List _chain = []; + Float64List _slice = Float64List(_kSliceSize); + int _pointer = 0; + + int get length => _length; + int _length = 0; + + /// Adds and [element] to this chain. + void add(double element) { + _slice[_pointer] = element; + _pointer += 1; + _length += 1; + if (_pointer >= _kSliceSize) { + _chain.add(_slice); + _slice = Float64List(_kSliceSize); + _pointer = 0; + } + } + + /// Returns all elements added to this chain. + /// + /// This getter is not optimized to be fast. It is assumed that when metrics + /// are read back, they do not affect the timings of the work being + /// benchmarked. + List extractElements() { + final List result = []; + _chain.forEach(result.addAll); + for (int i = 0; i < _pointer; i++) { + result.add(_slice[i]); + } + return result; + } +} + +/// Same as [_Float64ListChain] but for recording string values. +final class _StringListChain { + _StringListChain(); + + final List> _chain = >[]; + List _slice = List.filled(_kSliceSize, null); + int _pointer = 0; + + int get length => _length; + int _length = 0; + + /// Adds and [element] to this chain. + void add(String element) { + _slice[_pointer] = element; + _pointer += 1; + _length += 1; + if (_pointer >= _kSliceSize) { + _chain.add(_slice); + _slice = List.filled(_kSliceSize, null); + _pointer = 0; + } + } + + /// Returns all elements added to this chain. + /// + /// This getter is not optimized to be fast. It is assumed that when metrics + /// are read back, they do not affect the timings of the work being + /// benchmarked. + List extractElements() { + final List result = []; + for (final List slice in _chain) { + for (final String? element in slice) { + result.add(element!); + } + } + for (int i = 0; i < _pointer; i++) { + result.add(_slice[i]!); + } + return result; + } +} + +/// A buffer that records starts and ends of code blocks, and their names. +final class _BlockBuffer { + // Start-finish blocks can be nested. Track this nestedness by stacking the + // start timestamps. Finish timestamps will pop timings from the stack and + // add the (start, finish) tuple to the _block. + static const int _stackDepth = 1000; + static final Float64List _startStack = Float64List(_stackDepth); + static final List _nameStack = List.filled(_stackDepth, null); + static int _stackPointer = 0; + + final _Float64ListChain _starts = _Float64ListChain(); + final _Float64ListChain _finishes = _Float64ListChain(); + final _StringListChain _names = _StringListChain(); + + List computeTimings() { + assert( + _stackPointer == 0, + 'Invalid sequence of `startSync` and `finishSync`.\n' + 'The operation stack was not empty. The following operations are still ' + 'waiting to be finished via the `finishSync` method:\n' + '${List.generate(_stackPointer, (int i) => _nameStack[i]!).join(', ')}' + ); + + final List result = []; + final int length = _finishes.length; + final List starts = _starts.extractElements(); + final List finishes = _finishes.extractElements(); + final List names = _names.extractElements(); + + assert(starts.length == length); + assert(finishes.length == length); + assert(names.length == length); + + for (int i = 0; i < length; i++) { + result.add(TimedBlock( + start: starts[i], + end: finishes[i], + name: names[i], + )); + } + + return result; + } + + void startSync(String name, { Map? arguments, Flow? flow }) { + _startStack[_stackPointer] = impl.performanceTimestamp; + _nameStack[_stackPointer] = name; + _stackPointer += 1; + } + + void finishSync() { + assert( + _stackPointer > 0, + 'Invalid sequence of `startSync` and `finishSync`.\n' + 'Attempted to finish timing a block of code, but there are no pending ' + '`startSync` calls.' + ); + + final double finishTime = impl.performanceTimestamp; + final double startTime = _startStack[_stackPointer - 1]; + final String name = _nameStack[_stackPointer - 1]!; + _stackPointer -= 1; + + _starts.add(startTime); + _finishes.add(finishTime); + _names.add(name); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/unicode.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/unicode.dart new file mode 100644 index 0000000000000000000000000000000000000000..bbfdfafa1f729e5d364d7ce667a107cea81b453b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/foundation/unicode.dart @@ -0,0 +1,97 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Constants for useful Unicode characters. +/// +/// Currently, these characters are all related to bidirectional text. +/// +/// See also: +/// +/// * , which describes the Unicode +/// bidirectional text algorithm. +abstract final class Unicode { + /// `U+202A LEFT-TO-RIGHT EMBEDDING` + /// + /// Treat the following text as embedded left-to-right. + /// + /// Use [PDF] to end the embedding. + static const String LRE = '\u202A'; + + /// `U+202B RIGHT-TO-LEFT EMBEDDING` + /// + /// Treat the following text as embedded right-to-left. + /// + /// Use [PDF] to end the embedding. + static const String RLE = '\u202B'; + + /// `U+202C POP DIRECTIONAL FORMATTING` + /// + /// End the scope of the last [LRE], [RLE], [RLO], or [LRO]. + static const String PDF = '\u202C'; + + /// `U+202A LEFT-TO-RIGHT OVERRIDE` + /// + /// Force following characters to be treated as strong left-to-right characters. + /// + /// For example, this causes Hebrew text to render backwards. + /// + /// Use [PDF] to end the override. + static const String LRO = '\u202D'; + + /// `U+202B RIGHT-TO-LEFT OVERRIDE` + /// + /// Force following characters to be treated as strong right-to-left characters. + /// + /// For example, this causes English text to render backwards. + /// + /// Use [PDF] to end the override. + static const String RLO = '\u202E'; + + /// `U+2066 LEFT-TO-RIGHT ISOLATE` + /// + /// Treat the following text as isolated and left-to-right. + /// + /// Use [PDI] to end the isolated scope. + static const String LRI = '\u2066'; + + /// `U+2067 RIGHT-TO-LEFT ISOLATE` + /// + /// Treat the following text as isolated and right-to-left. + /// + /// Use [PDI] to end the isolated scope. + static const String RLI = '\u2067'; + + /// `U+2068 FIRST STRONG ISOLATE` + /// + /// Treat the following text as isolated and in the direction of its first + /// strong directional character that is not inside a nested isolate. + /// + /// This essentially "auto-detects" the directionality of the text. It is not + /// 100% reliable. For example, Arabic text that starts with an English quote + /// will be detected as LTR, not RTL, which will lead to the text being in a + /// weird order. + /// + /// Use [PDI] to end the isolated scope. + static const String FSI = '\u2068'; + + /// `U+2069 POP DIRECTIONAL ISOLATE` + /// + /// End the scope of the last [LRI], [RLI], or [FSI]. + static const String PDI = '\u2069'; + + /// `U+200E LEFT-TO-RIGHT MARK` + /// + /// Left-to-right zero-width character. + static const String LRM = '\u200E'; + + /// `U+200F RIGHT-TO-LEFT MARK` + /// + /// Right-to-left zero-width non-Arabic character. + static const String RLM = '\u200F'; + + /// `U+061C ARABIC LETTER MARK` + /// + /// Right-to-left zero-width Arabic character. + static const String ALM = '\u061C'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/arena.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/arena.dart new file mode 100644 index 0000000000000000000000000000000000000000..243f0691c79d68d1acf992d0104041f51054222c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/arena.dart @@ -0,0 +1,295 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; + +import 'debug.dart'; + +/// Whether the gesture was accepted or rejected. +enum GestureDisposition { + /// This gesture was accepted as the interpretation of the user's input. + accepted, + + /// This gesture was rejected as the interpretation of the user's input. + rejected, +} + +/// Represents an object participating in an arena. +/// +/// Receives callbacks from the GestureArena to notify the object when it wins +/// or loses a gesture negotiation. Exactly one of [acceptGesture] or +/// [rejectGesture] will be called for each arena this member was added to, +/// regardless of what caused the arena to be resolved. For example, if a +/// member resolves the arena itself, that member still receives an +/// [acceptGesture] callback. +abstract class GestureArenaMember { + /// Called when this member wins the arena for the given pointer id. + void acceptGesture(int pointer); + + /// Called when this member loses the arena for the given pointer id. + void rejectGesture(int pointer); +} + +/// An interface to pass information to an arena. +/// +/// A given [GestureArenaMember] can have multiple entries in multiple arenas +/// with different pointer ids. +class GestureArenaEntry { + GestureArenaEntry._(this._arena, this._pointer, this._member); + + final GestureArenaManager _arena; + final int _pointer; + final GestureArenaMember _member; + + /// Call this member to claim victory (with accepted) or admit defeat (with rejected). + /// + /// It's fine to attempt to resolve a gesture recognizer for an arena that is + /// already resolved. + void resolve(GestureDisposition disposition) { + _arena._resolve(_pointer, _member, disposition); + } +} + +class _GestureArena { + final List members = []; + bool isOpen = true; + bool isHeld = false; + bool hasPendingSweep = false; + + /// If a member attempts to win while the arena is still open, it becomes the + /// "eager winner". We look for an eager winner when closing the arena to new + /// participants, and if there is one, we resolve the arena in its favor at + /// that time. + GestureArenaMember? eagerWinner; + + void add(GestureArenaMember member) { + assert(isOpen); + members.add(member); + } + + @override + String toString() { + final StringBuffer buffer = StringBuffer(); + if (members.isEmpty) { + buffer.write(''); + } else { + buffer.write(members.map((GestureArenaMember member) { + if (member == eagerWinner) { + return '$member (eager winner)'; + } + return '$member'; + }).join(', ')); + } + if (isOpen) { + buffer.write(' [open]'); + } + if (isHeld) { + buffer.write(' [held]'); + } + if (hasPendingSweep) { + buffer.write(' [hasPendingSweep]'); + } + return buffer.toString(); + } +} + +/// Used for disambiguating the meaning of sequences of pointer events. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=Q85LBtBdi0U} +/// +/// The first member to accept or the last member to not reject wins. +/// +/// See for more +/// information about the role this class plays in the gesture system. +/// +/// To debug problems with gestures, consider using +/// [debugPrintGestureArenaDiagnostics]. +class GestureArenaManager { + final Map _arenas = {}; + + /// Adds a new member (e.g., gesture recognizer) to the arena. + GestureArenaEntry add(int pointer, GestureArenaMember member) { + final _GestureArena state = _arenas.putIfAbsent(pointer, () { + assert(_debugLogDiagnostic(pointer, '★ Opening new gesture arena.')); + return _GestureArena(); + }); + state.add(member); + assert(_debugLogDiagnostic(pointer, 'Adding: $member')); + return GestureArenaEntry._(this, pointer, member); + } + + /// Prevents new members from entering the arena. + /// + /// Called after the framework has finished dispatching the pointer down event. + void close(int pointer) { + final _GestureArena? state = _arenas[pointer]; + if (state == null) { + return; // This arena either never existed or has been resolved. + } + state.isOpen = false; + assert(_debugLogDiagnostic(pointer, 'Closing', state)); + _tryToResolveArena(pointer, state); + } + + /// Forces resolution of the arena, giving the win to the first member. + /// + /// Sweep is typically after all the other processing for a [PointerUpEvent] + /// have taken place. It ensures that multiple passive gestures do not cause a + /// stalemate that prevents the user from interacting with the app. + /// + /// Recognizers that wish to delay resolving an arena past [PointerUpEvent] + /// should call [hold] to delay sweep until [release] is called. + /// + /// See also: + /// + /// * [hold] + /// * [release] + void sweep(int pointer) { + final _GestureArena? state = _arenas[pointer]; + if (state == null) { + return; // This arena either never existed or has been resolved. + } + assert(!state.isOpen); + if (state.isHeld) { + state.hasPendingSweep = true; + assert(_debugLogDiagnostic(pointer, 'Delaying sweep', state)); + return; // This arena is being held for a long-lived member. + } + assert(_debugLogDiagnostic(pointer, 'Sweeping', state)); + _arenas.remove(pointer); + if (state.members.isNotEmpty) { + // First member wins. + assert(_debugLogDiagnostic(pointer, 'Winner: ${state.members.first}')); + state.members.first.acceptGesture(pointer); + // Give all the other members the bad news. + for (int i = 1; i < state.members.length; i++) { + state.members[i].rejectGesture(pointer); + } + } + } + + /// Prevents the arena from being swept. + /// + /// Typically, a winner is chosen in an arena after all the other + /// [PointerUpEvent] processing by [sweep]. If a recognizer wishes to delay + /// resolving an arena past [PointerUpEvent], the recognizer can [hold] the + /// arena open using this function. To release such a hold and let the arena + /// resolve, call [release]. + /// + /// See also: + /// + /// * [sweep] + /// * [release] + void hold(int pointer) { + final _GestureArena? state = _arenas[pointer]; + if (state == null) { + return; // This arena either never existed or has been resolved. + } + state.isHeld = true; + assert(_debugLogDiagnostic(pointer, 'Holding', state)); + } + + /// Releases a hold, allowing the arena to be swept. + /// + /// If a sweep was attempted on a held arena, the sweep will be done + /// on release. + /// + /// See also: + /// + /// * [sweep] + /// * [hold] + void release(int pointer) { + final _GestureArena? state = _arenas[pointer]; + if (state == null) { + return; // This arena either never existed or has been resolved. + } + state.isHeld = false; + assert(_debugLogDiagnostic(pointer, 'Releasing', state)); + if (state.hasPendingSweep) { + sweep(pointer); + } + } + + /// Reject or accept a gesture recognizer. + /// + /// This is called by calling [GestureArenaEntry.resolve] on the object returned from [add]. + void _resolve(int pointer, GestureArenaMember member, GestureDisposition disposition) { + final _GestureArena? state = _arenas[pointer]; + if (state == null) { + return; // This arena has already resolved. + } + assert(_debugLogDiagnostic(pointer, '${ disposition == GestureDisposition.accepted ? "Accepting" : "Rejecting" }: $member')); + assert(state.members.contains(member)); + if (disposition == GestureDisposition.rejected) { + state.members.remove(member); + member.rejectGesture(pointer); + if (!state.isOpen) { + _tryToResolveArena(pointer, state); + } + } else { + assert(disposition == GestureDisposition.accepted); + if (state.isOpen) { + state.eagerWinner ??= member; + } else { + assert(_debugLogDiagnostic(pointer, 'Self-declared winner: $member')); + _resolveInFavorOf(pointer, state, member); + } + } + } + + void _tryToResolveArena(int pointer, _GestureArena state) { + assert(_arenas[pointer] == state); + assert(!state.isOpen); + if (state.members.length == 1) { + scheduleMicrotask(() => _resolveByDefault(pointer, state)); + } else if (state.members.isEmpty) { + _arenas.remove(pointer); + assert(_debugLogDiagnostic(pointer, 'Arena empty.')); + } else if (state.eagerWinner != null) { + assert(_debugLogDiagnostic(pointer, 'Eager winner: ${state.eagerWinner}')); + _resolveInFavorOf(pointer, state, state.eagerWinner!); + } + } + + void _resolveByDefault(int pointer, _GestureArena state) { + if (!_arenas.containsKey(pointer)) { + return; // This arena has already resolved. + } + assert(_arenas[pointer] == state); + assert(!state.isOpen); + final List members = state.members; + assert(members.length == 1); + _arenas.remove(pointer); + assert(_debugLogDiagnostic(pointer, 'Default winner: ${state.members.first}')); + state.members.first.acceptGesture(pointer); + } + + void _resolveInFavorOf(int pointer, _GestureArena state, GestureArenaMember member) { + assert(state == _arenas[pointer]); + assert(state.eagerWinner == null || state.eagerWinner == member); + assert(!state.isOpen); + _arenas.remove(pointer); + for (final GestureArenaMember rejectedMember in state.members) { + if (rejectedMember != member) { + rejectedMember.rejectGesture(pointer); + } + } + member.acceptGesture(pointer); + } + + bool _debugLogDiagnostic(int pointer, String message, [ _GestureArena? state ]) { + assert(() { + if (debugPrintGestureArenaDiagnostics) { + final int? count = state?.members.length; + final String s = count != 1 ? 's' : ''; + debugPrint('Gesture arena ${pointer.toString().padRight(4)} ❙ $message${ count != null ? " with $count member$s." : ""}'); + } + return true; + }()); + return true; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/binding.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/binding.dart new file mode 100644 index 0000000000000000000000000000000000000000..25165d31703b9d06a5f40f60664c2e1f69b627bb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/binding.dart @@ -0,0 +1,607 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:collection'; +import 'dart:ui' as ui show PointerDataPacket; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; + +import 'arena.dart'; +import 'converter.dart'; +import 'debug.dart'; +import 'events.dart'; +import 'hit_test.dart'; +import 'pointer_router.dart'; +import 'pointer_signal_resolver.dart'; +import 'resampler.dart'; + +export 'dart:ui' show Offset; + +export 'package:flutter/foundation.dart' show DiagnosticsNode, InformationCollector; + +export 'arena.dart' show GestureArenaManager; +export 'events.dart' show PointerEvent; +export 'hit_test.dart' show HitTestEntry, HitTestResult, HitTestTarget; +export 'pointer_router.dart' show PointerRouter; +export 'pointer_signal_resolver.dart' show PointerSignalResolver; + +typedef _HandleSampleTimeChangedCallback = void Function(); + +/// Class that implements clock used for sampling. +class SamplingClock { + /// Returns current time. + DateTime now() => DateTime.now(); + + /// Returns a new stopwatch that uses the current time as reported by `this`. + /// + /// See also: + /// + /// * [GestureBinding.debugSamplingClock], which is used in tests and + /// debug builds to observe [FakeAsync]. + Stopwatch stopwatch() => Stopwatch(); // flutter_ignore: stopwatch (see analyze.dart) + // Ignore context: This is replaced by debugSampling clock in the test binding. +} + +// Class that handles resampling of touch events for multiple pointer +// devices. +// +// The `samplingInterval` is used to determine the approximate next +// time for resampling. +// SchedulerBinding's `currentSystemFrameTimeStamp` is used to determine +// sample time. +class _Resampler { + _Resampler(this._handlePointerEvent, this._handleSampleTimeChanged, this._samplingInterval); + + // Resamplers used to filter incoming pointer events. + final Map _resamplers = {}; + + // Flag to track if a frame callback has been scheduled. + bool _frameCallbackScheduled = false; + + // Last frame time for resampling. + Duration _frameTime = Duration.zero; + + // Time since `_frameTime` was updated. + Stopwatch _frameTimeAge = Stopwatch(); // flutter_ignore: stopwatch (see analyze.dart) + // Ignore context: This is tested safely outside of FakeAsync. + + // Last sample time and time stamp of last event. + // + // Only used for debugPrint of resampling margin. + Duration _lastSampleTime = Duration.zero; + Duration _lastEventTime = Duration.zero; + + // Callback used to handle pointer events. + final HandleEventCallback _handlePointerEvent; + + // Callback used to handle sample time changes. + final _HandleSampleTimeChangedCallback _handleSampleTimeChanged; + + // Interval used for sampling. + final Duration _samplingInterval; + + // Timer used to schedule resampling. + Timer? _timer; + + // Add `event` for resampling or dispatch it directly if + // not a touch event. + void addOrDispatch(PointerEvent event) { + // Add touch event to resampler or dispatch pointer event directly. + if (event.kind == PointerDeviceKind.touch) { + // Save last event time for debugPrint of resampling margin. + _lastEventTime = event.timeStamp; + + final PointerEventResampler resampler = _resamplers.putIfAbsent( + event.device, + () => PointerEventResampler(), + ); + resampler.addEvent(event); + } else { + _handlePointerEvent(event); + } + } + + // Sample and dispatch events. + // + // The `samplingOffset` is relative to the current frame time, which + // can be in the past when we're not actively resampling. + // + // The `samplingClock` is the clock used to determine frame time age. + void sample(Duration samplingOffset, SamplingClock clock) { + final SchedulerBinding scheduler = SchedulerBinding.instance; + + // Initialize `_frameTime` if needed. This will be used for periodic + // sampling when frame callbacks are not received. + if (_frameTime == Duration.zero) { + _frameTime = Duration(milliseconds: clock.now().millisecondsSinceEpoch); + _frameTimeAge = clock.stopwatch()..start(); + } + + // Schedule periodic resampling if `_timer` is not already active. + if (_timer?.isActive != true) { + _timer = Timer.periodic(_samplingInterval, (_) => _onSampleTimeChanged()); + } + + // Calculate the effective frame time by taking the number + // of sampling intervals since last time `_frameTime` was + // updated into account. This allows us to advance sample + // time without having to receive frame callbacks. + final int samplingIntervalUs = _samplingInterval.inMicroseconds; + final int elapsedIntervals = _frameTimeAge.elapsedMicroseconds ~/ samplingIntervalUs; + final int elapsedUs = elapsedIntervals * samplingIntervalUs; + final Duration frameTime = _frameTime + Duration(microseconds: elapsedUs); + + // Determine sample time by adding the offset to the current + // frame time. This is expected to be in the past and not + // result in any dispatched events unless we're actively + // resampling events. + final Duration sampleTime = frameTime + samplingOffset; + + // Determine next sample time by adding the sampling interval + // to the current sample time. + final Duration nextSampleTime = sampleTime + _samplingInterval; + + // Iterate over active resamplers and sample pointer events for + // current sample time. + for (final PointerEventResampler resampler in _resamplers.values) { + resampler.sample(sampleTime, nextSampleTime, _handlePointerEvent); + } + + // Remove inactive resamplers. + _resamplers.removeWhere((int key, PointerEventResampler resampler) { + return !resampler.hasPendingEvents && !resampler.isDown; + }); + + // Save last sample time for debugPrint of resampling margin. + _lastSampleTime = sampleTime; + + // Early out if another call to `sample` isn't needed. + if (_resamplers.isEmpty) { + _timer!.cancel(); + return; + } + + // Schedule a frame callback if another call to `sample` is needed. + if (!_frameCallbackScheduled) { + _frameCallbackScheduled = true; + // Add a post frame callback as this avoids producing unnecessary + // frames but ensures that sampling phase is adjusted to frame + // time when frames are produced. + scheduler.addPostFrameCallback((_) { + _frameCallbackScheduled = false; + // We use `currentSystemFrameTimeStamp` here as it's critical that + // sample time is in the same clock as the event time stamps, and + // never adjusted or scaled like `currentFrameTimeStamp`. + _frameTime = scheduler.currentSystemFrameTimeStamp; + _frameTimeAge.reset(); + // Reset timer to match phase of latest frame callback. + _timer?.cancel(); + _timer = Timer.periodic(_samplingInterval, (_) => _onSampleTimeChanged()); + // Trigger an immediate sample time change. + _onSampleTimeChanged(); + }, debugLabel: 'Resampler.startTimer'); + } + } + + // Stop all resampling and dispatched any queued events. + void stop() { + for (final PointerEventResampler resampler in _resamplers.values) { + resampler.stop(_handlePointerEvent); + } + _resamplers.clear(); + _frameTime = Duration.zero; + _timer?.cancel(); + } + + void _onSampleTimeChanged() { + assert(() { + if (debugPrintResamplingMargin) { + final Duration resamplingMargin = _lastEventTime - _lastSampleTime; + debugPrint('$resamplingMargin'); + } + return true; + }()); + _handleSampleTimeChanged(); + } +} + +// The default sampling offset. +// +// Sampling offset is relative to presentation time. If we produce frames +// 16.667 ms before presentation and input rate is ~60hz, worst case latency +// is 33.334 ms. This however assumes zero latency from the input driver. +// 4.666 ms margin is added for this. +const Duration _defaultSamplingOffset = Duration(milliseconds: -38); + +// The sampling interval. +// +// Sampling interval is used to determine the approximate time for subsequent +// sampling. This is used to sample events when frame callbacks are not +// being received and decide if early processing of up and removed events +// is appropriate. 16667 us for 60hz sampling interval. +const Duration _samplingInterval = Duration(microseconds: 16667); + +/// A binding for the gesture subsystem. +/// +/// ## Lifecycle of pointer events and the gesture arena +/// +/// ### [PointerDownEvent] +/// +/// When a [PointerDownEvent] is received by the [GestureBinding] (from +/// [dart:ui.PlatformDispatcher.onPointerDataPacket], as interpreted by the +/// [PointerEventConverter]), a [hitTest] is performed to determine which +/// [HitTestTarget] nodes are affected. (Other bindings are expected to +/// implement [hitTest] to defer to [HitTestable] objects. For example, the +/// rendering layer defers to the [RenderView] and the rest of the render object +/// hierarchy.) +/// +/// The affected nodes then are given the event to handle ([dispatchEvent] calls +/// [HitTestTarget.handleEvent] for each affected node). If any have relevant +/// [GestureRecognizer]s, they provide the event to them using +/// [GestureRecognizer.addPointer]. This typically causes the recognizer to +/// register with the [PointerRouter] to receive notifications regarding the +/// pointer in question. +/// +/// Once the hit test and dispatching logic is complete, the event is then +/// passed to the aforementioned [PointerRouter], which passes it to any objects +/// that have registered interest in that event. +/// +/// Finally, the [gestureArena] is closed for the given pointer +/// ([GestureArenaManager.close]), which begins the process of selecting a +/// gesture to win that pointer. +/// +/// ### Other events +/// +/// A pointer that is [PointerEvent.down] may send further events, such as +/// [PointerMoveEvent], [PointerUpEvent], or [PointerCancelEvent]. These are +/// sent to the same [HitTestTarget] nodes as were found when the +/// [PointerDownEvent] was received (even if they have since been disposed; it is +/// the responsibility of those objects to be aware of that possibility). +/// +/// Then, the events are routed to any still-registered entrants in the +/// [PointerRouter]'s table for that pointer. +/// +/// When a [PointerUpEvent] is received, the [GestureArenaManager.sweep] method +/// is invoked to force the gesture arena logic to terminate if necessary. +mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, HitTestTarget { + @override + void initInstances() { + super.initInstances(); + _instance = this; + platformDispatcher.onPointerDataPacket = _handlePointerDataPacket; + } + + /// The singleton instance of this object. + /// + /// Provides access to the features exposed by this mixin. The binding must + /// be initialized before using this getter; this is typically done by calling + /// [runApp] or [WidgetsFlutterBinding.ensureInitialized]. + static GestureBinding get instance => BindingBase.checkInstance(_instance); + static GestureBinding? _instance; + + @override + void unlocked() { + super.unlocked(); + _flushPointerEventQueue(); + } + + final Queue _pendingPointerEvents = Queue(); + + void _handlePointerDataPacket(ui.PointerDataPacket packet) { + // We convert pointer data to logical pixels so that e.g. the touch slop can be + // defined in a device-independent manner. + try { + _pendingPointerEvents.addAll(PointerEventConverter.expand(packet.data, _devicePixelRatioForView)); + if (!locked) { + _flushPointerEventQueue(); + } + } catch (error, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: error, + stack: stack, + library: 'gestures library', + context: ErrorDescription('while handling a pointer data packet'), + )); + } + } + + double? _devicePixelRatioForView(int viewId) { + return platformDispatcher.view(id: viewId)?.devicePixelRatio; + } + + /// Dispatch a [PointerCancelEvent] for the given pointer soon. + /// + /// The pointer event will be dispatched before the next pointer event and + /// before the end of the microtask but not within this function call. + void cancelPointer(int pointer) { + if (_pendingPointerEvents.isEmpty && !locked) { + scheduleMicrotask(_flushPointerEventQueue); + } + _pendingPointerEvents.addFirst(PointerCancelEvent(pointer: pointer)); + } + + void _flushPointerEventQueue() { + assert(!locked); + + while (_pendingPointerEvents.isNotEmpty) { + handlePointerEvent(_pendingPointerEvents.removeFirst()); + } + } + + /// A router that routes all pointer events received from the engine. + final PointerRouter pointerRouter = PointerRouter(); + + /// The gesture arenas used for disambiguating the meaning of sequences of + /// pointer events. + final GestureArenaManager gestureArena = GestureArenaManager(); + + /// The resolver used for determining which widget handles a + /// [PointerSignalEvent]. + final PointerSignalResolver pointerSignalResolver = PointerSignalResolver(); + + /// State for all pointers which are currently down. + /// + /// This map caches the hit test result done when the pointer goes down + /// ([PointerDownEvent] and [PointerPanZoomStartEvent]). This hit test result + /// will be used throughout the entire pointer interaction; that is, the + /// pointer is seen as pointing to the same place even if it has moved away + /// until pointer goes up ([PointerUpEvent] and [PointerPanZoomEndEvent]). + /// This matches the expected gesture interaction with a button, and allows + /// devices that don't support hovering to perform as few hit tests as + /// possible. + /// + /// On the other hand, hovering requires hit testing on almost every frame. + /// This is handled in [RendererBinding] and [MouseTracker], and will ignore + /// the results cached here. + final Map _hitTests = {}; + + /// Dispatch an event to the targets found by a hit test on its position. + /// + /// This method sends the given event to [dispatchEvent] based on event types: + /// + /// * [PointerDownEvent]s and [PointerSignalEvent]s are dispatched to the + /// result of a new [hitTest]. + /// * [PointerUpEvent]s and [PointerMoveEvent]s are dispatched to the result of hit test of the + /// preceding [PointerDownEvent]s. + /// * [PointerHoverEvent]s, [PointerAddedEvent]s, and [PointerRemovedEvent]s + /// are dispatched without a hit test result. + void handlePointerEvent(PointerEvent event) { + assert(!locked); + + if (resamplingEnabled) { + _resampler.addOrDispatch(event); + _resampler.sample(samplingOffset, samplingClock); + return; + } + + // Stop resampler if resampling is not enabled. This is a no-op if + // resampling was never enabled. + _resampler.stop(); + _handlePointerEventImmediately(event); + } + + void _handlePointerEventImmediately(PointerEvent event) { + HitTestResult? hitTestResult; + if (event is PointerDownEvent || event is PointerSignalEvent || event is PointerHoverEvent || event is PointerPanZoomStartEvent) { + assert(!_hitTests.containsKey(event.pointer), 'Pointer of ${event.toString(minLevel: DiagnosticLevel.debug)} unexpectedly has a HitTestResult associated with it.'); + hitTestResult = HitTestResult(); + hitTestInView(hitTestResult, event.position, event.viewId); + if (event is PointerDownEvent || event is PointerPanZoomStartEvent) { + _hitTests[event.pointer] = hitTestResult; + } + assert(() { + if (debugPrintHitTestResults) { + debugPrint('${event.toString(minLevel: DiagnosticLevel.debug)}: $hitTestResult'); + } + return true; + }()); + } else if (event is PointerUpEvent || event is PointerCancelEvent || event is PointerPanZoomEndEvent) { + hitTestResult = _hitTests.remove(event.pointer); + } else if (event.down || event is PointerPanZoomUpdateEvent) { + // Because events that occur with the pointer down (like + // [PointerMoveEvent]s) should be dispatched to the same place that their + // initial PointerDownEvent was, we want to re-use the path we found when + // the pointer went down, rather than do hit detection each time we get + // such an event. + hitTestResult = _hitTests[event.pointer]; + } + assert(() { + if (debugPrintMouseHoverEvents && event is PointerHoverEvent) { + debugPrint('$event'); + } + return true; + }()); + if (hitTestResult != null || + event is PointerAddedEvent || + event is PointerRemovedEvent) { + dispatchEvent(event, hitTestResult); + } + } + + /// Determine which [HitTestTarget] objects are located at a given position in + /// the specified view. + @override // from HitTestable + void hitTestInView(HitTestResult result, Offset position, int viewId) { + result.add(HitTestEntry(this)); + } + + @override // from HitTestable + @Deprecated( + 'Use hitTestInView and specify the view to hit test. ' + 'This feature was deprecated after v3.11.0-20.0.pre.', + ) + void hitTest(HitTestResult result, Offset position) { + hitTestInView(result, position, platformDispatcher.implicitView!.viewId); + } + + /// Dispatch an event to [pointerRouter] and the path of a hit test result. + /// + /// The `event` is routed to [pointerRouter]. If the `hitTestResult` is not + /// null, the event is also sent to every [HitTestTarget] in the entries of the + /// given [HitTestResult]. Any exceptions from the handlers are caught. + /// + /// The `hitTestResult` argument may only be null for [PointerAddedEvent]s or + /// [PointerRemovedEvent]s. + @override // from HitTestDispatcher + @pragma('vm:notify-debugger-on-exception') + void dispatchEvent(PointerEvent event, HitTestResult? hitTestResult) { + assert(!locked); + // No hit test information implies that this is a [PointerAddedEvent] or + // [PointerRemovedEvent]. These events are specially routed here; other + // events will be routed through the `handleEvent` below. + if (hitTestResult == null) { + assert(event is PointerAddedEvent || event is PointerRemovedEvent); + try { + pointerRouter.route(event); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetailsForPointerEventDispatcher( + exception: exception, + stack: stack, + library: 'gesture library', + context: ErrorDescription('while dispatching a non-hit-tested pointer event'), + event: event, + informationCollector: () => [ + DiagnosticsProperty('Event', event, style: DiagnosticsTreeStyle.errorProperty), + ], + )); + } + return; + } + for (final HitTestEntry entry in hitTestResult.path) { + try { + entry.target.handleEvent(event.transformed(entry.transform), entry); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetailsForPointerEventDispatcher( + exception: exception, + stack: stack, + library: 'gesture library', + context: ErrorDescription('while dispatching a pointer event'), + event: event, + hitTestEntry: entry, + informationCollector: () => [ + DiagnosticsProperty('Event', event, style: DiagnosticsTreeStyle.errorProperty), + DiagnosticsProperty('Target', entry.target, style: DiagnosticsTreeStyle.errorProperty), + ], + )); + } + } + } + + @override // from HitTestTarget + void handleEvent(PointerEvent event, HitTestEntry entry) { + pointerRouter.route(event); + if (event is PointerDownEvent || event is PointerPanZoomStartEvent) { + gestureArena.close(event.pointer); + } else if (event is PointerUpEvent || event is PointerPanZoomEndEvent) { + gestureArena.sweep(event.pointer); + } else if (event is PointerSignalEvent) { + pointerSignalResolver.resolve(event); + } + } + + /// Reset states of [GestureBinding]. + /// + /// This clears the hit test records. + /// + /// This is typically called between tests. + @protected + void resetGestureBinding() { + _hitTests.clear(); + } + + void _handleSampleTimeChanged() { + if (!locked) { + if (resamplingEnabled) { + _resampler.sample(samplingOffset, samplingClock); + } + else { + _resampler.stop(); + } + } + } + + /// Overrides the sampling clock for debugging and testing. + /// + /// This value is ignored in non-debug builds. + @protected + SamplingClock? get debugSamplingClock => null; + + /// Provides access to the current [DateTime] and `StopWatch` objects for + /// sampling. + /// + /// Overridden by [debugSamplingClock] for debug builds and testing. Using + /// this object under test will maintain synchronization with [FakeAsync]. + SamplingClock get samplingClock { + SamplingClock value = SamplingClock(); + assert(() { + final SamplingClock? debugValue = debugSamplingClock; + if (debugValue != null) { + value = debugValue; + } + return true; + }()); + return value; + } + + // Resampler used to filter incoming pointer events when resampling + // is enabled. + late final _Resampler _resampler = _Resampler( + _handlePointerEventImmediately, + _handleSampleTimeChanged, + _samplingInterval, + ); + + /// Enable pointer event resampling for touch devices by setting + /// this to true. + /// + /// Resampling results in smoother touch event processing at the + /// cost of some added latency. Devices with low frequency sensors + /// or when the frequency is not a multiple of the display frequency + /// (e.g., 120Hz input and 90Hz display) benefit from this. + /// + /// This is typically set during application initialization but + /// can be adjusted dynamically in case the application only + /// wants resampling for some period of time. + bool resamplingEnabled = false; + + /// Offset relative to current frame time that should be used for + /// resampling. The [samplingOffset] is expected to be negative. + /// Non-negative [samplingOffset] is allowed but will effectively + /// disable resampling. + Duration samplingOffset = _defaultSamplingOffset; +} + +/// Variant of [FlutterErrorDetails] with extra fields for the gesture +/// library's binding's pointer event dispatcher ([GestureBinding.dispatchEvent]). +class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails { + /// Creates a [FlutterErrorDetailsForPointerEventDispatcher] object with the given + /// arguments setting the object's properties. + /// + /// The gesture library calls this constructor when catching an exception + /// that will subsequently be reported using [FlutterError.onError]. + const FlutterErrorDetailsForPointerEventDispatcher({ + required super.exception, + super.stack, + super.library, + super.context, + this.event, + this.hitTestEntry, + super.informationCollector, + super.silent, + }); + + /// The pointer event that was being routed when the exception was raised. + final PointerEvent? event; + + /// The hit test result entry for the object whose handleEvent method threw + /// the exception. May be null if no hit test entry is associated with the + /// event (e.g. [PointerHoverEvent]s, [PointerAddedEvent]s, and + /// [PointerRemovedEvent]s). + /// + /// The target object itself is given by the [HitTestEntry.target] property of + /// the hitTestEntry object. + final HitTestEntry? hitTestEntry; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/constants.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/constants.dart new file mode 100644 index 0000000000000000000000000000000000000000..6d83ad3769b0b277dee5369ce9caf22eb8c40621 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/constants.dart @@ -0,0 +1,105 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Modeled after Android's ViewConfiguration: +// https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewConfiguration.java + +/// The time that must elapse before a tap gesture sends onTapDown, if there's +/// any doubt that the gesture is a tap. +const Duration kPressTimeout = Duration(milliseconds: 100); + +/// Maximum length of time between a tap down and a tap up for the gesture to be +/// considered a tap. (Currently not honored by the TapGestureRecognizer.) +// TODO(ianh): Remove this, or implement a hover-tap gesture recognizer which +// uses this. +const Duration kHoverTapTimeout = Duration(milliseconds: 150); + +/// Maximum distance between the down and up pointers for a tap. (Currently not +/// honored by the [TapGestureRecognizer]; [PrimaryPointerGestureRecognizer], +/// which TapGestureRecognizer inherits from, uses [kTouchSlop].) +// TODO(ianh): Remove this or implement it correctly. +const double kHoverTapSlop = 20.0; // Logical pixels + +/// The time before a long press gesture attempts to win. +const Duration kLongPressTimeout = Duration(milliseconds: 500); + +/// The maximum time from the start of the first tap to the start of the second +/// tap in a double-tap gesture. +// In Android, this is actually the time from the first's up event +// to the second's down event, according to the ViewConfiguration docs. +const Duration kDoubleTapTimeout = Duration(milliseconds: 300); + +/// The minimum time from the end of the first tap to the start of the second +/// tap in a double-tap gesture. +const Duration kDoubleTapMinTime = Duration(milliseconds: 40); + +/// The maximum distance that the first touch in a double-tap gesture can travel +/// before deciding that it is not part of a double-tap gesture. +/// DoubleTapGestureRecognizer also restricts the second touch to this distance. +const double kDoubleTapTouchSlop = kTouchSlop; // Logical pixels + +/// Distance between the initial position of the first touch and the start +/// position of a potential second touch for the second touch to be considered +/// the second touch of a double-tap gesture. +const double kDoubleTapSlop = 100.0; // Logical pixels + +/// The time for which zoom controls (e.g. in a map interface) are to be +/// displayed on the screen, from the moment they were last requested. +const Duration kZoomControlsTimeout = Duration(milliseconds: 3000); + +/// The distance a touch has to travel for the framework to be confident that +/// the gesture is a scroll gesture, or, inversely, the maximum distance that a +/// touch can travel before the framework becomes confident that it is not a +/// tap. +/// +/// A total delta less than or equal to [kTouchSlop] is not considered to be a +/// drag, whereas if the delta is greater than [kTouchSlop] it is considered to +/// be a drag. +// This value was empirically derived. We started at 8.0 and increased it to +// 18.0 after getting complaints that it was too difficult to hit targets. +const double kTouchSlop = 18.0; // Logical pixels + +/// The distance a touch has to travel for the framework to be confident that +/// the gesture is a paging gesture. (Currently not used, because paging uses a +/// regular drag gesture, which uses kTouchSlop.) +// TODO(ianh): Create variants of HorizontalDragGestureRecognizer et al for +// paging, which use this constant. +const double kPagingTouchSlop = kTouchSlop * 2.0; // Logical pixels + +/// The distance a touch has to travel for the framework to be confident that +/// the gesture is a panning gesture. +const double kPanSlop = kTouchSlop * 2.0; // Logical pixels + +/// The distance a touch has to travel for the framework to be confident that +/// the gesture is a scale gesture. +const double kScaleSlop = kTouchSlop; // Logical pixels + +/// The margin around a dialog, popup menu, or other window-like widget inside +/// which we do not consider a tap to dismiss the widget. (Not currently used.) +// TODO(ianh): Make ModalBarrier support this. +const double kWindowTouchSlop = 16.0; // Logical pixels + +/// The minimum velocity for a touch to consider that touch to trigger a fling +/// gesture. +// TODO(ianh): Make sure nobody has their own version of this. +const double kMinFlingVelocity = 50.0; // Logical pixels / second +// const Velocity kMinFlingVelocity = const Velocity(pixelsPerSecond: 50.0); + +/// Drag gesture fling velocities are clipped to this value. +// TODO(ianh): Make sure nobody has their own version of this. +const double kMaxFlingVelocity = 8000.0; // Logical pixels / second + +/// The maximum time from the start of the first tap to the start of the second +/// tap in a jump-tap gesture. +// TODO(ianh): Implement jump-tap gestures. +const Duration kJumpTapTimeout = Duration(milliseconds: 500); + +/// Like [kTouchSlop], but for more precise pointers like mice and trackpads. +const double kPrecisePointerHitSlop = 1.0; // Logical pixels; + +/// Like [kPanSlop], but for more precise pointers like mice and trackpads. +const double kPrecisePointerPanSlop = kPrecisePointerHitSlop * 2.0; // Logical pixels + +/// Like [kScaleSlop], but for more precise pointers like mice and trackpads. +const double kPrecisePointerScaleSlop = kPrecisePointerHitSlop; // Logical pixels diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/converter.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/converter.dart new file mode 100644 index 0000000000000000000000000000000000000000..21095d1e58064d7e4a21253cde6b3bcc6cce7a2c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/converter.dart @@ -0,0 +1,313 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'dart:ui' as ui show PointerChange, PointerData, PointerSignalKind; + +import 'events.dart'; + +export 'dart:ui' show PointerData; + +export 'events.dart' show PointerEvent; + +// Add `kPrimaryButton` to [buttons] when a pointer of certain devices is down. +// +// TODO(tongmu): This patch is supposed to be done by embedders. Patching it +// in framework is a workaround before [PointerEventConverter] is moved to embedders. +// https://github.com/flutter/flutter/issues/30454 +int _synthesiseDownButtons(int buttons, PointerDeviceKind kind) { + switch (kind) { + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + return buttons; + case PointerDeviceKind.touch: + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + return buttons == 0 ? kPrimaryButton : buttons; + case PointerDeviceKind.unknown: + // We have no information about the device but we know we never want + // buttons to be 0 when the pointer is down. + return buttons == 0 ? kPrimaryButton : buttons; + } +} + +/// Signature for a callback that returns the device pixel ratio of a +/// [FlutterView] identified by the provided `viewId`. +/// +/// Returns null if no view with the provided ID exists. +/// +/// Used by [PointerEventConverter.expand]. +/// +/// See also: +/// +/// * [FlutterView.devicePixelRatio] for an explanation of device pixel ratio. +typedef DevicePixelRatioGetter = double? Function(int viewId); + +/// Converts from engine pointer data to framework pointer events. +/// +/// This takes [PointerDataPacket] objects, as received from the engine via +/// [dart:ui.PlatformDispatcher.onPointerDataPacket], and converts them to +/// [PointerEvent] objects. +abstract final class PointerEventConverter { + /// Expand the given packet of pointer data into a sequence of framework + /// pointer events. + /// + /// The `devicePixelRatioForView` is used to obtain the device pixel ratio for + /// the view a particular event occurred in to convert its data from physical + /// coordinates to logical pixels. See the discussion at [PointerEvent] for + /// more details on the [PointerEvent] coordinate space. + static Iterable expand(Iterable data, DevicePixelRatioGetter devicePixelRatioForView) { + return data + .where((ui.PointerData datum) => datum.signalKind != ui.PointerSignalKind.unknown) + .map((ui.PointerData datum) { + final double? devicePixelRatio = devicePixelRatioForView(datum.viewId); + if (devicePixelRatio == null) { + // View doesn't exist anymore. + return null; + } + final Offset position = Offset(datum.physicalX, datum.physicalY) / devicePixelRatio; + final Offset delta = Offset(datum.physicalDeltaX, datum.physicalDeltaY) / devicePixelRatio; + final double radiusMinor = _toLogicalPixels(datum.radiusMinor, devicePixelRatio); + final double radiusMajor = _toLogicalPixels(datum.radiusMajor, devicePixelRatio); + final double radiusMin = _toLogicalPixels(datum.radiusMin, devicePixelRatio); + final double radiusMax = _toLogicalPixels(datum.radiusMax, devicePixelRatio); + final Duration timeStamp = datum.timeStamp; + final PointerDeviceKind kind = datum.kind; + switch (datum.signalKind ?? ui.PointerSignalKind.none) { + case ui.PointerSignalKind.none: + switch (datum.change) { + case ui.PointerChange.add: + return PointerAddedEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + kind: kind, + device: datum.device, + position: position, + obscured: datum.obscured, + pressureMin: datum.pressureMin, + pressureMax: datum.pressureMax, + distance: datum.distance, + distanceMax: datum.distanceMax, + radiusMin: radiusMin, + radiusMax: radiusMax, + orientation: datum.orientation, + tilt: datum.tilt, + embedderId: datum.embedderId, + ); + case ui.PointerChange.hover: + return PointerHoverEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + kind: kind, + device: datum.device, + position: position, + delta: delta, + buttons: datum.buttons, + obscured: datum.obscured, + pressureMin: datum.pressureMin, + pressureMax: datum.pressureMax, + distance: datum.distance, + distanceMax: datum.distanceMax, + size: datum.size, + radiusMajor: radiusMajor, + radiusMinor: radiusMinor, + radiusMin: radiusMin, + radiusMax: radiusMax, + orientation: datum.orientation, + tilt: datum.tilt, + synthesized: datum.synthesized, + embedderId: datum.embedderId, + ); + case ui.PointerChange.down: + return PointerDownEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + pointer: datum.pointerIdentifier, + kind: kind, + device: datum.device, + position: position, + buttons: _synthesiseDownButtons(datum.buttons, kind), + obscured: datum.obscured, + pressure: datum.pressure, + pressureMin: datum.pressureMin, + pressureMax: datum.pressureMax, + distanceMax: datum.distanceMax, + size: datum.size, + radiusMajor: radiusMajor, + radiusMinor: radiusMinor, + radiusMin: radiusMin, + radiusMax: radiusMax, + orientation: datum.orientation, + tilt: datum.tilt, + embedderId: datum.embedderId, + ); + case ui.PointerChange.move: + return PointerMoveEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + pointer: datum.pointerIdentifier, + kind: kind, + device: datum.device, + position: position, + delta: delta, + buttons: _synthesiseDownButtons(datum.buttons, kind), + obscured: datum.obscured, + pressure: datum.pressure, + pressureMin: datum.pressureMin, + pressureMax: datum.pressureMax, + distanceMax: datum.distanceMax, + size: datum.size, + radiusMajor: radiusMajor, + radiusMinor: radiusMinor, + radiusMin: radiusMin, + radiusMax: radiusMax, + orientation: datum.orientation, + tilt: datum.tilt, + platformData: datum.platformData, + synthesized: datum.synthesized, + embedderId: datum.embedderId, + ); + case ui.PointerChange.up: + return PointerUpEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + pointer: datum.pointerIdentifier, + kind: kind, + device: datum.device, + position: position, + buttons: datum.buttons, + obscured: datum.obscured, + pressure: datum.pressure, + pressureMin: datum.pressureMin, + pressureMax: datum.pressureMax, + distance: datum.distance, + distanceMax: datum.distanceMax, + size: datum.size, + radiusMajor: radiusMajor, + radiusMinor: radiusMinor, + radiusMin: radiusMin, + radiusMax: radiusMax, + orientation: datum.orientation, + tilt: datum.tilt, + embedderId: datum.embedderId, + ); + case ui.PointerChange.cancel: + return PointerCancelEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + pointer: datum.pointerIdentifier, + kind: kind, + device: datum.device, + position: position, + buttons: datum.buttons, + obscured: datum.obscured, + pressureMin: datum.pressureMin, + pressureMax: datum.pressureMax, + distance: datum.distance, + distanceMax: datum.distanceMax, + size: datum.size, + radiusMajor: radiusMajor, + radiusMinor: radiusMinor, + radiusMin: radiusMin, + radiusMax: radiusMax, + orientation: datum.orientation, + tilt: datum.tilt, + embedderId: datum.embedderId, + ); + case ui.PointerChange.remove: + return PointerRemovedEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + kind: kind, + device: datum.device, + position: position, + obscured: datum.obscured, + pressureMin: datum.pressureMin, + pressureMax: datum.pressureMax, + distanceMax: datum.distanceMax, + radiusMin: radiusMin, + radiusMax: radiusMax, + embedderId: datum.embedderId, + ); + case ui.PointerChange.panZoomStart: + return PointerPanZoomStartEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + pointer: datum.pointerIdentifier, + device: datum.device, + position: position, + embedderId: datum.embedderId, + synthesized: datum.synthesized, + ); + case ui.PointerChange.panZoomUpdate: + final Offset pan = + Offset(datum.panX, datum.panY) / devicePixelRatio; + final Offset panDelta = + Offset(datum.panDeltaX, datum.panDeltaY) / devicePixelRatio; + return PointerPanZoomUpdateEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + pointer: datum.pointerIdentifier, + device: datum.device, + position: position, + pan: pan, + panDelta: panDelta, + scale: datum.scale, + rotation: datum.rotation, + embedderId: datum.embedderId, + synthesized: datum.synthesized, + ); + case ui.PointerChange.panZoomEnd: + return PointerPanZoomEndEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + pointer: datum.pointerIdentifier, + device: datum.device, + position: position, + embedderId: datum.embedderId, + synthesized: datum.synthesized, + ); + } + case ui.PointerSignalKind.scroll: + if (!datum.scrollDeltaX.isFinite || !datum.scrollDeltaY.isFinite || devicePixelRatio <= 0) { + return null; + } + final Offset scrollDelta = + Offset(datum.scrollDeltaX, datum.scrollDeltaY) / devicePixelRatio; + return PointerScrollEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + kind: kind, + device: datum.device, + position: position, + scrollDelta: scrollDelta, + embedderId: datum.embedderId, + ); + case ui.PointerSignalKind.scrollInertiaCancel: + return PointerScrollInertiaCancelEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + kind: kind, + device: datum.device, + position: position, + embedderId: datum.embedderId, + ); + case ui.PointerSignalKind.scale: + return PointerScaleEvent( + viewId: datum.viewId, + timeStamp: timeStamp, + kind: kind, + device: datum.device, + position: position, + embedderId: datum.embedderId, + scale: datum.scale, + ); + case ui.PointerSignalKind.unknown: + throw StateError('Unreachable'); + } + }).whereType(); + } + + static double _toLogicalPixels(double physicalPixels, double devicePixelRatio) => physicalPixels / devicePixelRatio; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/debug.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/debug.dart new file mode 100644 index 0000000000000000000000000000000000000000..0bc9343e35394ffae522829ad597018962429df8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/debug.dart @@ -0,0 +1,84 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +// Any changes to this file should be reflected in the debugAssertAllGesturesVarsUnset() +// function below. + +/// Whether to print the results of each hit test to the console. +/// +/// When this is set, in debug mode, any time a hit test is triggered by the +/// [GestureBinding] the results are dumped to the console. +/// +/// This has no effect in release builds. +bool debugPrintHitTestResults = false; + +/// Whether to print the details of each mouse hover event to the console. +/// +/// When this is set, in debug mode, any time a mouse hover event is triggered +/// by the [GestureBinding], the results are dumped to the console. +/// +/// This has no effect in release builds, and only applies to mouse hover +/// events. +bool debugPrintMouseHoverEvents = false; + +/// Prints information about gesture recognizers and gesture arenas. +/// +/// This flag only has an effect in debug mode. +/// +/// See also: +/// +/// * [GestureArenaManager], the class that manages gesture arenas. +/// * [debugPrintRecognizerCallbacksTrace], for debugging issues with +/// gesture recognizers. +bool debugPrintGestureArenaDiagnostics = false; + +/// Logs a message every time a gesture recognizer callback is invoked. +/// +/// This flag only has an effect in debug mode. +/// +/// This is specifically used by [GestureRecognizer.invokeCallback]. Gesture +/// recognizers that do not use this method to invoke callbacks may not honor +/// the [debugPrintRecognizerCallbacksTrace] flag. +/// +/// See also: +/// +/// * [debugPrintGestureArenaDiagnostics], for debugging issues with gesture +/// arenas. +bool debugPrintRecognizerCallbacksTrace = false; + +/// Whether to print the resampling margin to the console. +/// +/// When this is set, in debug mode, any time resampling is triggered by the +/// [GestureBinding] the resampling margin is dumped to the console. The +/// resampling margin is the delta between the time of the last received +/// touch event and the current sample time. Positive value indicates that +/// resampling is effective and the resampling offset can potentially be +/// reduced for improved latency. Negative value indicates that resampling +/// is failing and resampling offset needs to be increased for smooth +/// touch event processing. +/// +/// This has no effect in release builds. +bool debugPrintResamplingMargin = false; + +/// Returns true if none of the gestures library debug variables have been changed. +/// +/// This function is used by the test framework to ensure that debug variables +/// haven't been inadvertently changed. +/// +/// See [the gestures library](gestures/gestures-library.html) for a complete +/// list. +bool debugAssertAllGesturesVarsUnset(String reason) { + assert(() { + if (debugPrintHitTestResults || + debugPrintGestureArenaDiagnostics || + debugPrintRecognizerCallbacksTrace || + debugPrintResamplingMargin) { + throw FlutterError(reason); + } + return true; + }()); + return true; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/drag.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/drag.dart new file mode 100644 index 0000000000000000000000000000000000000000..a3ef24c8f9392472818451376f14cea5954761b3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/drag.dart @@ -0,0 +1,31 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'drag_details.dart'; + +export 'drag_details.dart' show DragEndDetails, DragUpdateDetails; + +/// Interface for objects that receive updates about drags. +/// +/// This interface is used in various ways. For example, +/// [MultiDragGestureRecognizer] uses it to update its clients when it +/// recognizes a gesture. Similarly, the scrolling infrastructure in the widgets +/// library uses it to notify the [DragScrollActivity] when the user drags the +/// scrollable. +abstract class Drag { + /// The pointer has moved. + void update(DragUpdateDetails details) { } + + /// The pointer is no longer in contact with the screen. + /// + /// The velocity at which the pointer was moving when it stopped contacting + /// the screen is available in the `details`. + void end(DragEndDetails details) { } + + /// The input from the pointer is no longer directed towards this receiver. + /// + /// For example, the user might have been interrupted by a system-modal dialog + /// in the middle of the drag. + void cancel() { } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/drag_details.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/drag_details.dart new file mode 100644 index 0000000000000000000000000000000000000000..bcf91c3e884b71c5e96aba69440836aed742116d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/drag_details.dart @@ -0,0 +1,242 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'velocity_tracker.dart'; + +export 'dart:ui' show Offset, PointerDeviceKind; + +export 'velocity_tracker.dart' show Velocity; + +/// Details object for callbacks that use [GestureDragDownCallback]. +/// +/// See also: +/// +/// * [DragGestureRecognizer.onDown], which uses [GestureDragDownCallback]. +/// * [DragStartDetails], the details for [GestureDragStartCallback]. +/// * [DragUpdateDetails], the details for [GestureDragUpdateCallback]. +/// * [DragEndDetails], the details for [GestureDragEndCallback]. +class DragDownDetails { + /// Creates details for a [GestureDragDownCallback]. + DragDownDetails({ + this.globalPosition = Offset.zero, + Offset? localPosition, + }) : localPosition = localPosition ?? globalPosition; + + /// The global position at which the pointer contacted the screen. + /// + /// Defaults to the origin if not specified in the constructor. + /// + /// See also: + /// + /// * [localPosition], which is the [globalPosition] transformed to the + /// coordinate space of the event receiver. + final Offset globalPosition; + + /// The local position in the coordinate system of the event receiver at + /// which the pointer contacted the screen. + /// + /// Defaults to [globalPosition] if not specified in the constructor. + final Offset localPosition; + + @override + String toString() => '${objectRuntimeType(this, 'DragDownDetails')}($globalPosition)'; +} + +/// Signature for when a pointer has contacted the screen and might begin to +/// move. +/// +/// The `details` object provides the position of the touch. +/// +/// See [DragGestureRecognizer.onDown]. +typedef GestureDragDownCallback = void Function(DragDownDetails details); + +/// Details object for callbacks that use [GestureDragStartCallback]. +/// +/// See also: +/// +/// * [DragGestureRecognizer.onStart], which uses [GestureDragStartCallback]. +/// * [DragDownDetails], the details for [GestureDragDownCallback]. +/// * [DragUpdateDetails], the details for [GestureDragUpdateCallback]. +/// * [DragEndDetails], the details for [GestureDragEndCallback]. +class DragStartDetails { + /// Creates details for a [GestureDragStartCallback]. + DragStartDetails({ + this.sourceTimeStamp, + this.globalPosition = Offset.zero, + Offset? localPosition, + this.kind, + }) : localPosition = localPosition ?? globalPosition; + + /// Recorded timestamp of the source pointer event that triggered the drag + /// event. + /// + /// Could be null if triggered from proxied events such as accessibility. + final Duration? sourceTimeStamp; + + /// The global position at which the pointer contacted the screen. + /// + /// Defaults to the origin if not specified in the constructor. + /// + /// See also: + /// + /// * [localPosition], which is the [globalPosition] transformed to the + /// coordinate space of the event receiver. + final Offset globalPosition; + + /// The local position in the coordinate system of the event receiver at + /// which the pointer contacted the screen. + /// + /// Defaults to [globalPosition] if not specified in the constructor. + final Offset localPosition; + + /// The kind of the device that initiated the event. + final PointerDeviceKind? kind; + + // TODO(ianh): Expose the current position, so that you can have a no-jump + // drag even when disambiguating (though of course it would lag the finger + // instead). + + @override + String toString() => '${objectRuntimeType(this, 'DragStartDetails')}($globalPosition)'; +} + +/// {@template flutter.gestures.dragdetails.GestureDragStartCallback} +/// Signature for when a pointer has contacted the screen and has begun to move. +/// +/// The `details` object provides the position of the touch when it first +/// touched the surface. +/// {@endtemplate} +/// +/// See [DragGestureRecognizer.onStart]. +typedef GestureDragStartCallback = void Function(DragStartDetails details); + +/// Details object for callbacks that use [GestureDragUpdateCallback]. +/// +/// See also: +/// +/// * [DragGestureRecognizer.onUpdate], which uses [GestureDragUpdateCallback]. +/// * [DragDownDetails], the details for [GestureDragDownCallback]. +/// * [DragStartDetails], the details for [GestureDragStartCallback]. +/// * [DragEndDetails], the details for [GestureDragEndCallback]. +class DragUpdateDetails { + /// Creates details for a [GestureDragUpdateCallback]. + /// + /// If [primaryDelta] is non-null, then its value must match one of the + /// coordinates of [delta] and the other coordinate must be zero. + DragUpdateDetails({ + this.sourceTimeStamp, + this.delta = Offset.zero, + this.primaryDelta, + required this.globalPosition, + Offset? localPosition, + }) : assert( + primaryDelta == null + || (primaryDelta == delta.dx && delta.dy == 0.0) + || (primaryDelta == delta.dy && delta.dx == 0.0), + ), + localPosition = localPosition ?? globalPosition; + + /// Recorded timestamp of the source pointer event that triggered the drag + /// event. + /// + /// Could be null if triggered from proxied events such as accessibility. + final Duration? sourceTimeStamp; + + /// The amount the pointer has moved in the coordinate space of the event + /// receiver since the previous update. + /// + /// If the [GestureDragUpdateCallback] is for a one-dimensional drag (e.g., + /// a horizontal or vertical drag), then this offset contains only the delta + /// in that direction (i.e., the coordinate in the other direction is zero). + /// + /// Defaults to zero if not specified in the constructor. + final Offset delta; + + /// The amount the pointer has moved along the primary axis in the coordinate + /// space of the event receiver since the previous + /// update. + /// + /// If the [GestureDragUpdateCallback] is for a one-dimensional drag (e.g., + /// a horizontal or vertical drag), then this value contains the component of + /// [delta] along the primary axis (e.g., horizontal or vertical, + /// respectively). Otherwise, if the [GestureDragUpdateCallback] is for a + /// two-dimensional drag (e.g., a pan), then this value is null. + /// + /// Defaults to null if not specified in the constructor. + final double? primaryDelta; + + /// The pointer's global position when it triggered this update. + /// + /// See also: + /// + /// * [localPosition], which is the [globalPosition] transformed to the + /// coordinate space of the event receiver. + final Offset globalPosition; + + /// The local position in the coordinate system of the event receiver at + /// which the pointer contacted the screen. + /// + /// Defaults to [globalPosition] if not specified in the constructor. + final Offset localPosition; + + @override + String toString() => '${objectRuntimeType(this, 'DragUpdateDetails')}($delta)'; +} + +/// {@template flutter.gestures.dragdetails.GestureDragUpdateCallback} +/// Signature for when a pointer that is in contact with the screen and moving +/// has moved again. +/// +/// The `details` object provides the position of the touch and the distance it +/// has traveled since the last update. +/// {@endtemplate} +/// +/// See [DragGestureRecognizer.onUpdate]. +typedef GestureDragUpdateCallback = void Function(DragUpdateDetails details); + +/// Details object for callbacks that use [GestureDragEndCallback]. +/// +/// See also: +/// +/// * [DragGestureRecognizer.onEnd], which uses [GestureDragEndCallback]. +/// * [DragDownDetails], the details for [GestureDragDownCallback]. +/// * [DragStartDetails], the details for [GestureDragStartCallback]. +/// * [DragUpdateDetails], the details for [GestureDragUpdateCallback]. +class DragEndDetails { + /// Creates details for a [GestureDragEndCallback]. + /// + /// If [primaryVelocity] is non-null, its value must match one of the + /// coordinates of `velocity.pixelsPerSecond` and the other coordinate + /// must be zero. + DragEndDetails({ + this.velocity = Velocity.zero, + this.primaryVelocity, + }) : assert( + primaryVelocity == null + || (primaryVelocity == velocity.pixelsPerSecond.dx && velocity.pixelsPerSecond.dy == 0) + || (primaryVelocity == velocity.pixelsPerSecond.dy && velocity.pixelsPerSecond.dx == 0), + ); + + /// The velocity the pointer was moving when it stopped contacting the screen. + /// + /// Defaults to zero if not specified in the constructor. + final Velocity velocity; + + /// The velocity the pointer was moving along the primary axis when it stopped + /// contacting the screen, in logical pixels per second. + /// + /// If the [GestureDragEndCallback] is for a one-dimensional drag (e.g., a + /// horizontal or vertical drag), then this value contains the component of + /// [velocity] along the primary axis (e.g., horizontal or vertical, + /// respectively). Otherwise, if the [GestureDragEndCallback] is for a + /// two-dimensional drag (e.g., a pan), then this value is null. + /// + /// Defaults to null if not specified in the constructor. + final double? primaryVelocity; + + @override + String toString() => '${objectRuntimeType(this, 'DragEndDetails')}($velocity)'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/eager.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/eager.dart new file mode 100644 index 0000000000000000000000000000000000000000..7601c761d07c6b7b98323e06670c25dfc49eef60 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/eager.dart @@ -0,0 +1,40 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'recognizer.dart'; + +export 'dart:ui' show PointerDeviceKind; + +export 'events.dart' show PointerDownEvent, PointerEvent; + +/// A gesture recognizer that eagerly claims victory in all gesture arenas. +/// +/// This is typically passed in [AndroidView.gestureRecognizers] in order to immediately dispatch +/// all touch events inside the view bounds to the embedded Android view. +/// See [AndroidView.gestureRecognizers] for more details. +class EagerGestureRecognizer extends OneSequenceGestureRecognizer { + /// Create an eager gesture recognizer. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + EagerGestureRecognizer({ + super.supportedDevices, + super.allowedButtonsFilter, + }); + + @override + void addAllowedPointer(PointerDownEvent event) { + super.addAllowedPointer(event); + resolve(GestureDisposition.accepted); + stopTrackingPointer(event.pointer); + } + + @override + String get debugDescription => 'eager'; + + @override + void didStopTrackingLastPointer(int pointer) { } + + @override + void handleEvent(PointerEvent event) { } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/events.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/events.dart new file mode 100644 index 0000000000000000000000000000000000000000..c78f324e723c288da55398810156473584739acd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/events.dart @@ -0,0 +1,2461 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show Offset, PointerDeviceKind; + +import 'package:flutter/foundation.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'constants.dart'; +import 'gesture_settings.dart'; + +export 'dart:ui' show Offset, PointerDeviceKind; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; +export 'package:vector_math/vector_math_64.dart' show Matrix4; + +export 'gesture_settings.dart' show DeviceGestureSettings; + +/// The bit of [PointerEvent.buttons] that corresponds to a cross-device +/// behavior of "primary operation". +/// +/// More specifically, it includes: +/// +/// * [kTouchContact]: The pointer contacts the touch screen. +/// * [kStylusContact]: The stylus contacts the screen. +/// * [kPrimaryMouseButton]: The primary mouse button. +/// +/// See also: +/// +/// * [kSecondaryButton], which describes a cross-device behavior of +/// "secondary operation". +/// * [kTertiaryButton], which describes a cross-device behavior of +/// "tertiary operation". +const int kPrimaryButton = 0x01; + +/// The bit of [PointerEvent.buttons] that corresponds to a cross-device +/// behavior of "secondary operation". +/// +/// It is equivalent to: +/// +/// * [kPrimaryStylusButton]: The stylus contacts the screen. +/// * [kSecondaryMouseButton]: The secondary mouse button. +/// +/// See also: +/// +/// * [kPrimaryButton], which describes a cross-device behavior of +/// "primary operation". +/// * [kTertiaryButton], which describes a cross-device behavior of +/// "tertiary operation". +const int kSecondaryButton = 0x02; + +/// The bit of [PointerEvent.buttons] that corresponds to the primary mouse button. +/// +/// The primary mouse button is typically the left button on the top of the +/// mouse but can be reconfigured to be a different physical button. +/// +/// See also: +/// +/// * [kPrimaryButton], which has the same value but describes its cross-device +/// concept. +const int kPrimaryMouseButton = kPrimaryButton; + +/// The bit of [PointerEvent.buttons] that corresponds to the secondary mouse button. +/// +/// The secondary mouse button is typically the right button on the top of the +/// mouse but can be reconfigured to be a different physical button. +/// +/// See also: +/// +/// * [kSecondaryButton], which has the same value but describes its cross-device +/// concept. +const int kSecondaryMouseButton = kSecondaryButton; + +/// The bit of [PointerEvent.buttons] that corresponds to when a stylus +/// contacting the screen. +/// +/// See also: +/// +/// * [kPrimaryButton], which has the same value but describes its cross-device +/// concept. +const int kStylusContact = kPrimaryButton; + +/// The bit of [PointerEvent.buttons] that corresponds to the primary stylus button. +/// +/// The primary stylus button is typically the top of the stylus and near the +/// tip but can be reconfigured to be a different physical button. +/// +/// See also: +/// +/// * [kSecondaryButton], which has the same value but describes its cross-device +/// concept. +const int kPrimaryStylusButton = kSecondaryButton; + +/// The bit of [PointerEvent.buttons] that corresponds to a cross-device +/// behavior of "tertiary operation". +/// +/// It is equivalent to: +/// +/// * [kMiddleMouseButton]: The tertiary mouseButton. +/// * [kSecondaryStylusButton]: The secondary button on a stylus. This is considered +/// a tertiary button as the primary button of a stylus already corresponds to a +/// "secondary operation" (where stylus contact is the primary operation). +/// +/// See also: +/// +/// * [kPrimaryButton], which describes a cross-device behavior of +/// "primary operation". +/// * [kSecondaryButton], which describes a cross-device behavior of +/// "secondary operation". +const int kTertiaryButton = 0x04; + +/// The bit of [PointerEvent.buttons] that corresponds to the middle mouse button. +/// +/// The middle mouse button is typically between the left and right buttons on +/// the top of the mouse but can be reconfigured to be a different physical +/// button. +/// +/// See also: +/// +/// * [kTertiaryButton], which has the same value but describes its cross-device +/// concept. +const int kMiddleMouseButton = kTertiaryButton; + +/// The bit of [PointerEvent.buttons] that corresponds to the secondary stylus button. +/// +/// The secondary stylus button is typically on the end of the stylus farthest +/// from the tip but can be reconfigured to be a different physical button. +/// +/// See also: +/// +/// * [kTertiaryButton], which has the same value but describes its cross-device +/// concept. +const int kSecondaryStylusButton = kTertiaryButton; + +/// The bit of [PointerEvent.buttons] that corresponds to the back mouse button. +/// +/// The back mouse button is typically on the left side of the mouse but can be +/// reconfigured to be a different physical button. +const int kBackMouseButton = 0x08; + +/// The bit of [PointerEvent.buttons] that corresponds to the forward mouse button. +/// +/// The forward mouse button is typically on the right side of the mouse but can +/// be reconfigured to be a different physical button. +const int kForwardMouseButton = 0x10; + +/// The bit of [PointerEvent.buttons] that corresponds to the pointer contacting +/// a touch screen. +/// +/// See also: +/// +/// * [kPrimaryButton], which has the same value but describes its cross-device +/// concept. +const int kTouchContact = kPrimaryButton; + +/// The bit of [PointerEvent.buttons] that corresponds to the nth mouse button. +/// +/// The `number` argument can be at most 62 in Flutter for mobile and desktop, +/// and at most 32 on Flutter for web. +/// +/// See [kPrimaryMouseButton], [kSecondaryMouseButton], [kMiddleMouseButton], +/// [kBackMouseButton], and [kForwardMouseButton] for semantic names for some +/// mouse buttons. +int nthMouseButton(int number) => (kPrimaryMouseButton << (number - 1)) & kMaxUnsignedSMI; + +/// The bit of [PointerEvent.buttons] that corresponds to the nth stylus button. +/// +/// The `number` argument can be at most 62 in Flutter for mobile and desktop, +/// and at most 32 on Flutter for web. +/// +/// See [kPrimaryStylusButton] and [kSecondaryStylusButton] for semantic names +/// for some stylus buttons. +int nthStylusButton(int number) => (kPrimaryStylusButton << (number - 1)) & kMaxUnsignedSMI; + +/// Returns the button of `buttons` with the smallest integer. +/// +/// The `buttons` parameter is a bit field where each set bit represents a button. +/// This function returns the set bit closest to the least significant bit. +/// +/// It returns zero when `buttons` is zero. +/// +/// Example: +/// +/// ```dart +/// assert(smallestButton(0x01) == 0x01); +/// assert(smallestButton(0x11) == 0x01); +/// assert(smallestButton(0x10) == 0x10); +/// assert(smallestButton(0) == 0); +/// ``` +/// +/// See also: +/// +/// * [isSingleButton], which checks if a `buttons` contains exactly one button. +int smallestButton(int buttons) => buttons & (-buttons); + +/// Returns whether `buttons` contains one and only one button. +/// +/// The `buttons` parameter is a bit field where each set bit represents a button. +/// This function returns whether there is only one set bit in the given integer. +/// +/// It returns false when `buttons` is zero. +/// +/// Example: +/// +/// ```dart +/// assert(isSingleButton(0x1)); +/// assert(!isSingleButton(0x11)); +/// assert(!isSingleButton(0)); +/// ``` +/// +/// See also: +/// +/// * [smallestButton], which returns the button in a `buttons` bit field with +/// the smallest integer button. +bool isSingleButton(int buttons) => buttons != 0 && (smallestButton(buttons) == buttons); + +/// Base class for touch, stylus, or mouse events. +/// +/// Pointer events operate in the coordinate space of the screen, scaled to +/// logical pixels. Logical pixels approximate a grid with about 38 pixels per +/// centimeter, or 96 pixels per inch. +/// +/// This allows gestures to be recognized independent of the precise hardware +/// characteristics of the device. In particular, features such as touch slop +/// (see [kTouchSlop]) can be defined in terms of roughly physical lengths so +/// that the user can shift their finger by the same distance on a high-density +/// display as on a low-resolution device. +/// +/// For similar reasons, pointer events are not affected by any transforms in +/// the rendering layer. This means that deltas may need to be scaled before +/// being applied to movement within the rendering. For example, if a scrolling +/// list is shown scaled by 2x, the pointer deltas will have to be scaled by the +/// inverse amount if the list is to appear to scroll with the user's finger. +/// +/// See also: +/// +/// * [dart:ui.FlutterView.devicePixelRatio], which defines the device's +/// current resolution. +/// * [Listener], a widget that calls callbacks in response to common pointer +/// events. +@immutable +abstract class PointerEvent with Diagnosticable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const PointerEvent({ + this.viewId = 0, + this.embedderId = 0, + this.timeStamp = Duration.zero, + this.pointer = 0, + this.kind = PointerDeviceKind.touch, + this.device = 0, + this.position = Offset.zero, + this.delta = Offset.zero, + this.buttons = 0, + this.down = false, + this.obscured = false, + this.pressure = 1.0, + this.pressureMin = 1.0, + this.pressureMax = 1.0, + this.distance = 0.0, + this.distanceMax = 0.0, + this.size = 0.0, + this.radiusMajor = 0.0, + this.radiusMinor = 0.0, + this.radiusMin = 0.0, + this.radiusMax = 0.0, + this.orientation = 0.0, + this.tilt = 0.0, + this.platformData = 0, + this.synthesized = false, + this.transform, + this.original, + }); + + /// The ID of the [FlutterView] which this event originated from. + final int viewId; + + /// Unique identifier that ties the [PointerEvent] to the embedder event that created it. + /// + /// No two pointer events can have the same [embedderId] on platforms that set it. + /// This is different from [pointer] identifier - used for hit-testing, + /// whereas [embedderId] is used to identify the platform event. + /// + /// On Android this is ID of the underlying [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent). + final int embedderId; + + /// Time of event dispatch, relative to an arbitrary timeline. + final Duration timeStamp; + + /// Unique identifier for the pointer, not reused. Changes for each new + /// pointer down event. + final int pointer; + + /// The kind of input device for which the event was generated. + final PointerDeviceKind kind; + + /// Unique identifier for the pointing device, reused across interactions. + final int device; + + /// Coordinate of the position of the pointer, in logical pixels in the global + /// coordinate space. + /// + /// See also: + /// + /// * [localPosition], which is the [position] transformed into the local + /// coordinate system of the event receiver. + final Offset position; + + /// The [position] transformed into the event receiver's local coordinate + /// system according to [transform]. + /// + /// If this event has not been transformed, [position] is returned as-is. + /// See also: + /// + /// * [position], which is the position in the global coordinate system of + /// the screen. + Offset get localPosition => position; + + /// Distance in logical pixels that the pointer moved since the last + /// [PointerMoveEvent] or [PointerHoverEvent]. + /// + /// This value is always 0.0 for down, up, and cancel events. + /// + /// See also: + /// + /// * [localDelta], which is the [delta] transformed into the local + /// coordinate space of the event receiver. + final Offset delta; + + /// The [delta] transformed into the event receiver's local coordinate + /// system according to [transform]. + /// + /// If this event has not been transformed, [delta] is returned as-is. + /// + /// See also: + /// + /// * [delta], which is the distance the pointer moved in the global + /// coordinate system of the screen. + Offset get localDelta => delta; + + /// Bit field using the *Button constants such as [kPrimaryMouseButton], + /// [kSecondaryStylusButton], etc. + /// + /// For example, if this has the value 6 and the + /// [kind] is [PointerDeviceKind.invertedStylus], then this indicates an + /// upside-down stylus with both its primary and secondary buttons pressed. + final int buttons; + + /// Set if the pointer is currently down. + /// + /// For touch and stylus pointers, this means the object (finger, pen) is in + /// contact with the input surface. For mice, it means a button is pressed. + final bool down; + + /// Set if an application from a different security domain is in any way + /// obscuring this application's window. + /// + /// This is not currently implemented. + final bool obscured; + + /// The pressure of the touch. + /// + /// This value is a number ranging from 0.0, indicating a touch with no + /// discernible pressure, to 1.0, indicating a touch with "normal" pressure, + /// and possibly beyond, indicating a stronger touch. For devices that do not + /// detect pressure (e.g. mice), returns 1.0. + final double pressure; + + /// The minimum value that [pressure] can return for this pointer. + /// + /// For devices that do not detect pressure (e.g. mice), returns 1.0. + /// This will always be a number less than or equal to 1.0. + final double pressureMin; + + /// The maximum value that [pressure] can return for this pointer. + /// + /// For devices that do not detect pressure (e.g. mice), returns 1.0. + /// This will always be a greater than or equal to 1.0. + final double pressureMax; + + /// The distance of the detected object from the input surface. + /// + /// For instance, this value could be the distance of a stylus or finger + /// from a touch screen, in arbitrary units on an arbitrary (not necessarily + /// linear) scale. If the pointer is down, this is 0.0 by definition. + final double distance; + + /// The minimum value that [distance] can return for this pointer. + /// + /// This value is always 0.0. + double get distanceMin => 0.0; + + /// The maximum value that [distance] can return for this pointer. + /// + /// If this input device cannot detect "hover touch" input events, + /// then this will be 0.0. + final double distanceMax; + + /// The area of the screen being pressed. + /// + /// This value is scaled to a range between 0 and 1. It can be used to + /// determine fat touch events. This value is only set on Android and is + /// a device specific approximation within the range of detectable values. + /// So, for example, the value of 0.1 could mean a touch with the tip of + /// the finger, 0.2 a touch with full finger, and 0.3 the full palm. + /// + /// Because this value uses device-specific range and is uncalibrated, + /// it is of limited use and is primarily retained in order to be able + /// to reconstruct original pointer events for [AndroidView]. + final double size; + + /// The radius of the contact ellipse along the major axis, in logical pixels. + final double radiusMajor; + + /// The radius of the contact ellipse along the minor axis, in logical pixels. + final double radiusMinor; + + /// The minimum value that could be reported for [radiusMajor] and [radiusMinor] + /// for this pointer, in logical pixels. + final double radiusMin; + + /// The maximum value that could be reported for [radiusMajor] and [radiusMinor] + /// for this pointer, in logical pixels. + final double radiusMax; + + /// The orientation angle of the detected object, in radians. + /// + /// For [PointerDeviceKind.touch] events: + /// + /// The angle of the contact ellipse, in radians in the range: + /// + /// -pi/2 < orientation <= pi/2 + /// + /// ...giving the angle of the major axis of the ellipse with the y-axis + /// (negative angles indicating an orientation along the top-left / + /// bottom-right diagonal, positive angles indicating an orientation along the + /// top-right / bottom-left diagonal, and zero indicating an orientation + /// parallel with the y-axis). + /// + /// For [PointerDeviceKind.stylus] and [PointerDeviceKind.invertedStylus] events: + /// + /// The angle of the stylus, in radians in the range: + /// + /// -pi < orientation <= pi + /// + /// ...giving the angle of the axis of the stylus projected onto the input + /// surface, relative to the positive y-axis of that surface (thus 0.0 + /// indicates the stylus, if projected onto that surface, would go from the + /// contact point vertically up in the positive y-axis direction, pi would + /// indicate that the stylus would go down in the negative y-axis direction; + /// pi/4 would indicate that the stylus goes up and to the right, -pi/2 would + /// indicate that the stylus goes to the left, etc). + final double orientation; + + /// The tilt angle of the detected object, in radians. + /// + /// For [PointerDeviceKind.stylus] and [PointerDeviceKind.invertedStylus] events: + /// + /// The angle of the stylus, in radians in the range: + /// + /// 0 <= tilt <= pi/2 + /// + /// ...giving the angle of the axis of the stylus, relative to the axis + /// perpendicular to the input surface (thus 0.0 indicates the stylus is + /// orthogonal to the plane of the input surface, while pi/2 indicates that + /// the stylus is flat on that surface). + final double tilt; + + /// Opaque platform-specific data associated with the event. + final int platformData; + + /// Set if the event was synthesized by Flutter. + /// + /// We occasionally synthesize PointerEvents that aren't exact translations + /// of [PointerData] from the engine to cover small cross-OS discrepancies + /// in pointer behaviors. + /// + /// For instance, on end events, Android always drops any location changes + /// that happened between its reporting intervals when emitting the end events. + /// + /// On iOS, minor incorrect location changes from the previous move events + /// can be reported on end events. We synthesize a [PointerEvent] to cover + /// the difference between the 2 events in that case. + final bool synthesized; + + /// The transformation used to transform this event from the global coordinate + /// space into the coordinate space of the event receiver. + /// + /// This value affects what is returned by [localPosition] and [localDelta]. + /// If this value is null, it is treated as the identity transformation. + /// + /// Unlike a paint transform, this transform usually does not contain any + /// "perspective" components, meaning that the third row and the third column + /// of the matrix should be equal to "0, 0, 1, 0". This ensures that + /// [localPosition] describes the point in the local coordinate system of the + /// event receiver at which the user is actually touching the screen. + /// + /// See also: + /// + /// * [transformed], which transforms this event into a different coordinate + /// space. + final Matrix4? transform; + + /// The original un-transformed [PointerEvent] before any [transform]s were + /// applied. + /// + /// If [transform] is null or the identity transformation this may be null. + /// + /// When multiple event receivers in different coordinate spaces receive an + /// event, they all receive the event transformed to their local coordinate + /// space. The [original] property can be used to determine if all those + /// transformed events actually originated from the same pointer interaction. + final PointerEvent? original; + + /// Transforms the event from the global coordinate space into the coordinate + /// space of an event receiver. + /// + /// The coordinate space of the event receiver is described by `transform`. A + /// null value for `transform` is treated as the identity transformation. + /// + /// The resulting event will store the base event as [original], delegates + /// most properties to [original], except for [localPosition] and [localDelta], + /// which are calculated based on [transform] on first use and cached. + /// + /// The method may return the same object instance if for example the + /// transformation has no effect on the event. Otherwise, the resulting event + /// will be a subclass of, but not exactly, the original event class (e.g. + /// [PointerDownEvent.transformed] may return a subclass of [PointerDownEvent]). + /// + /// Transforms are not commutative, and are based on [original] events. + /// If this method is called on a transformed event, the provided `transform` + /// will override (instead of multiplied onto) the existing [transform] and + /// used to calculate the new [localPosition] and [localDelta]. + PointerEvent transformed(Matrix4? transform); + + /// Creates a copy of event with the specified properties replaced. + /// + /// Calling this method on a transformed event will return a new transformed + /// event based on the current [transform] and the provided properties. + PointerEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }); + + /// Returns the transformation of `position` into the coordinate system + /// described by `transform`. + /// + /// The z-value of `position` is assumed to be 0.0. If `transform` is null, + /// `position` is returned as-is. + static Offset transformPosition(Matrix4? transform, Offset position) { + if (transform == null) { + return position; + } + final Vector3 position3 = Vector3(position.dx, position.dy, 0.0); + final Vector3 transformed3 = transform.perspectiveTransform(position3); + return Offset(transformed3.x, transformed3.y); + } + + /// Transforms `untransformedDelta` into the coordinate system described by + /// `transform`. + /// + /// It uses the provided `untransformedEndPosition` and + /// `transformedEndPosition` of the provided delta to increase accuracy. + /// + /// If `transform` is null, `untransformedDelta` is returned. + static Offset transformDeltaViaPositions({ + required Offset untransformedEndPosition, + Offset? transformedEndPosition, + required Offset untransformedDelta, + required Matrix4? transform, + }) { + if (transform == null) { + return untransformedDelta; + } + // We could transform the delta directly with the transformation matrix. + // While that is mathematically equivalent, in practice we are seeing a + // greater precision error with that approach. Instead, we are transforming + // start and end point of the delta separately and calculate the delta in + // the new space for greater accuracy. + transformedEndPosition ??= transformPosition(transform, untransformedEndPosition); + final Offset transformedStartPosition = transformPosition(transform, untransformedEndPosition - untransformedDelta); + return transformedEndPosition - transformedStartPosition; + } + + /// Removes the "perspective" component from `transform`. + /// + /// When applying the resulting transform matrix to a point with a + /// z-coordinate of zero (which is generally assumed for all points + /// represented by an [Offset]), the other coordinates will get transformed as + /// before, but the new z-coordinate is going to be zero again. This is + /// achieved by setting the third column and third row of the matrix to + /// "0, 0, 1, 0". + static Matrix4 removePerspectiveTransform(Matrix4 transform) { + final Vector4 vector = Vector4(0, 0, 1, 0); + return transform.clone() + ..setColumn(2, vector) + ..setRow(2, vector); + } +} + +// A mixin that adds implementation for [debugFillProperties] and [toStringFull] +// to [PointerEvent]. +mixin _PointerEventDescription on PointerEvent { + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('position', position)); + properties.add(DiagnosticsProperty('localPosition', localPosition, defaultValue: position, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty('delta', delta, defaultValue: Offset.zero, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty('localDelta', localDelta, defaultValue: delta, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty('timeStamp', timeStamp, defaultValue: Duration.zero, level: DiagnosticLevel.debug)); + properties.add(IntProperty('pointer', pointer, level: DiagnosticLevel.debug)); + properties.add(EnumProperty('kind', kind, level: DiagnosticLevel.debug)); + properties.add(IntProperty('device', device, defaultValue: 0, level: DiagnosticLevel.debug)); + properties.add(IntProperty('buttons', buttons, defaultValue: 0, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty('down', down, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('pressure', pressure, defaultValue: 1.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('pressureMin', pressureMin, defaultValue: 1.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('pressureMax', pressureMax, defaultValue: 1.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('distance', distance, defaultValue: 0.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('distanceMin', distanceMin, defaultValue: 0.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('distanceMax', distanceMax, defaultValue: 0.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('size', size, defaultValue: 0.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('radiusMajor', radiusMajor, defaultValue: 0.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('radiusMinor', radiusMinor, defaultValue: 0.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('radiusMin', radiusMin, defaultValue: 0.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('radiusMax', radiusMax, defaultValue: 0.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('orientation', orientation, defaultValue: 0.0, level: DiagnosticLevel.debug)); + properties.add(DoubleProperty('tilt', tilt, defaultValue: 0.0, level: DiagnosticLevel.debug)); + properties.add(IntProperty('platformData', platformData, defaultValue: 0, level: DiagnosticLevel.debug)); + properties.add(FlagProperty('obscured', value: obscured, ifTrue: 'obscured', level: DiagnosticLevel.debug)); + properties.add(FlagProperty('synthesized', value: synthesized, ifTrue: 'synthesized', level: DiagnosticLevel.debug)); + properties.add(IntProperty('embedderId', embedderId, defaultValue: 0, level: DiagnosticLevel.debug)); + properties.add(IntProperty('viewId', viewId, defaultValue: 0, level: DiagnosticLevel.debug)); + } + + /// Returns a complete textual description of this event. + String toStringFull() { + return toString(minLevel: DiagnosticLevel.fine); + } +} + +abstract class _AbstractPointerEvent implements PointerEvent { } + +// The base class for transformed pointer event classes. +// +// A _TransformedPointerEvent stores an [original] event and the [transform] +// matrix. It defers all field getters to the original event, except for +// [localPosition] and [localDelta], which are calculated when first used. +abstract class _TransformedPointerEvent extends _AbstractPointerEvent with Diagnosticable, _PointerEventDescription { + @override + PointerEvent get original; + + @override + Matrix4 get transform; + + @override + int get embedderId => original.embedderId; + + @override + Duration get timeStamp => original.timeStamp; + + @override + int get pointer => original.pointer; + + @override + PointerDeviceKind get kind => original.kind; + + @override + int get device => original.device; + + @override + Offset get position => original.position; + + @override + Offset get delta => original.delta; + + @override + int get buttons => original.buttons; + + @override + bool get down => original.down; + + @override + bool get obscured => original.obscured; + + @override + double get pressure => original.pressure; + + @override + double get pressureMin => original.pressureMin; + + @override + double get pressureMax => original.pressureMax; + + @override + double get distance => original.distance; + + @override + double get distanceMin => 0.0; + + @override + double get distanceMax => original.distanceMax; + + @override + double get size => original.size; + + @override + double get radiusMajor => original.radiusMajor; + + @override + double get radiusMinor => original.radiusMinor; + + @override + double get radiusMin => original.radiusMin; + + @override + double get radiusMax => original.radiusMax; + + @override + double get orientation => original.orientation; + + @override + double get tilt => original.tilt; + + @override + int get platformData => original.platformData; + + @override + bool get synthesized => original.synthesized; + + @override + late final Offset localPosition = PointerEvent.transformPosition(transform, position); + + @override + late final Offset localDelta = PointerEvent.transformDeltaViaPositions( + transform: transform, + untransformedDelta: delta, + untransformedEndPosition: position, + transformedEndPosition: localPosition, + ); + + @override + int get viewId => original.viewId; +} + +mixin _CopyPointerAddedEvent on PointerEvent { + @override + PointerAddedEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerAddedEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + obscured: obscured ?? this.obscured, + pressureMin: pressureMin ?? this.pressureMin, + pressureMax: pressureMax ?? this.pressureMax, + distance: distance ?? this.distance, + distanceMax: distanceMax ?? this.distanceMax, + radiusMin: radiusMin ?? this.radiusMin, + radiusMax: radiusMax ?? this.radiusMax, + orientation: orientation ?? this.orientation, + tilt: tilt ?? this.tilt, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The device has started tracking the pointer. +/// +/// For example, the pointer might be hovering above the device, having not yet +/// made contact with the surface of the device. +class PointerAddedEvent extends PointerEvent with _PointerEventDescription, _CopyPointerAddedEvent { + /// Creates a pointer added event. + const PointerAddedEvent({ + super.viewId, + super.timeStamp, + super.pointer, + super.kind, + super.device, + super.position, + super.obscured, + super.pressureMin, + super.pressureMax, + super.distance, + super.distanceMax, + super.radiusMin, + super.radiusMax, + super.orientation, + super.tilt, + super.embedderId, + }) : super( + pressure: 0.0, + ); + + @override + PointerAddedEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerAddedEvent(original as PointerAddedEvent? ?? this, transform); + } +} + +class _TransformedPointerAddedEvent extends _TransformedPointerEvent with _CopyPointerAddedEvent implements PointerAddedEvent { + _TransformedPointerAddedEvent(this.original, this.transform); + + @override + final PointerAddedEvent original; + + @override + final Matrix4 transform; + + @override + PointerAddedEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerRemovedEvent on PointerEvent { + @override + PointerRemovedEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerRemovedEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + obscured: obscured ?? this.obscured, + pressureMin: pressureMin ?? this.pressureMin, + pressureMax: pressureMax ?? this.pressureMax, + distanceMax: distanceMax ?? this.distanceMax, + radiusMin: radiusMin ?? this.radiusMin, + radiusMax: radiusMax ?? this.radiusMax, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The device is no longer tracking the pointer. +/// +/// For example, the pointer might have drifted out of the device's hover +/// detection range or might have been disconnected from the system entirely. +class PointerRemovedEvent extends PointerEvent with _PointerEventDescription, _CopyPointerRemovedEvent { + /// Creates a pointer removed event. + const PointerRemovedEvent({ + super.viewId, + super.timeStamp, + super.pointer, + super.kind, + super.device, + super.position, + super.obscured, + super.pressureMin, + super.pressureMax, + super.distanceMax, + super.radiusMin, + super.radiusMax, + PointerRemovedEvent? super.original, + super.embedderId, + }) : super( + pressure: 0.0, + ); + + @override + PointerRemovedEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerRemovedEvent(original as PointerRemovedEvent? ?? this, transform); + } +} + +class _TransformedPointerRemovedEvent extends _TransformedPointerEvent with _CopyPointerRemovedEvent implements PointerRemovedEvent { + _TransformedPointerRemovedEvent(this.original, this.transform); + + @override + final PointerRemovedEvent original; + + @override + final Matrix4 transform; + + @override + PointerRemovedEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerHoverEvent on PointerEvent { + @override + PointerHoverEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerHoverEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + delta: delta ?? this.delta, + buttons: buttons ?? this.buttons, + obscured: obscured ?? this.obscured, + pressureMin: pressureMin ?? this.pressureMin, + pressureMax: pressureMax ?? this.pressureMax, + distance: distance ?? this.distance, + distanceMax: distanceMax ?? this.distanceMax, + size: size ?? this.size, + radiusMajor: radiusMajor ?? this.radiusMajor, + radiusMinor: radiusMinor ?? this.radiusMinor, + radiusMin: radiusMin ?? this.radiusMin, + radiusMax: radiusMax ?? this.radiusMax, + orientation: orientation ?? this.orientation, + tilt: tilt ?? this.tilt, + synthesized: synthesized ?? this.synthesized, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The pointer has moved with respect to the device while the pointer is not +/// in contact with the device. +/// +/// See also: +/// +/// * [PointerEnterEvent], which reports when the pointer has entered an +/// object. +/// * [PointerExitEvent], which reports when the pointer has left an object. +/// * [PointerMoveEvent], which reports movement while the pointer is in +/// contact with the device. +/// * [Listener.onPointerHover], which allows callers to be notified of these +/// events in a widget tree. +class PointerHoverEvent extends PointerEvent with _PointerEventDescription, _CopyPointerHoverEvent { + /// Creates a pointer hover event. + const PointerHoverEvent({ + super.viewId, + super.timeStamp, + super.kind, + super.pointer, + super.device, + super.position, + super.delta, + super.buttons, + super.obscured, + super.pressureMin, + super.pressureMax, + super.distance, + super.distanceMax, + super.size, + super.radiusMajor, + super.radiusMinor, + super.radiusMin, + super.radiusMax, + super.orientation, + super.tilt, + super.synthesized, + super.embedderId, + }) : super( + down: false, + pressure: 0.0, + ); + + @override + PointerHoverEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerHoverEvent(original as PointerHoverEvent? ?? this, transform); + } +} + +class _TransformedPointerHoverEvent extends _TransformedPointerEvent with _CopyPointerHoverEvent implements PointerHoverEvent { + _TransformedPointerHoverEvent(this.original, this.transform); + + @override + final PointerHoverEvent original; + + @override + final Matrix4 transform; + + @override + PointerHoverEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerEnterEvent on PointerEvent { + @override + PointerEnterEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerEnterEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + delta: delta ?? this.delta, + buttons: buttons ?? this.buttons, + obscured: obscured ?? this.obscured, + pressureMin: pressureMin ?? this.pressureMin, + pressureMax: pressureMax ?? this.pressureMax, + distance: distance ?? this.distance, + distanceMax: distanceMax ?? this.distanceMax, + size: size ?? this.size, + radiusMajor: radiusMajor ?? this.radiusMajor, + radiusMinor: radiusMinor ?? this.radiusMinor, + radiusMin: radiusMin ?? this.radiusMin, + radiusMax: radiusMax ?? this.radiusMax, + orientation: orientation ?? this.orientation, + tilt: tilt ?? this.tilt, + synthesized: synthesized ?? this.synthesized, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The pointer has moved with respect to the device while the pointer is or is +/// not in contact with the device, and it has entered a target object. +/// +/// See also: +/// +/// * [PointerHoverEvent], which reports when the pointer has moved while +/// within an object. +/// * [PointerExitEvent], which reports when the pointer has left an object. +/// * [PointerMoveEvent], which reports movement while the pointer is in +/// contact with the device. +/// * [MouseRegion.onEnter], which allows callers to be notified of these +/// events in a widget tree. +class PointerEnterEvent extends PointerEvent with _PointerEventDescription, _CopyPointerEnterEvent { + /// Creates a pointer enter event. + const PointerEnterEvent({ + super.viewId, + super.timeStamp, + super.pointer, + super.kind, + super.device, + super.position, + super.delta, + super.buttons, + super.obscured, + super.pressureMin, + super.pressureMax, + super.distance, + super.distanceMax, + super.size, + super.radiusMajor, + super.radiusMinor, + super.radiusMin, + super.radiusMax, + super.orientation, + super.tilt, + super.down, + super.synthesized, + super.embedderId, + }) : // Dart doesn't support comparing enums with == in const contexts yet. + // https://github.com/dart-lang/language/issues/1811 + assert(!identical(kind, PointerDeviceKind.trackpad)), + super( + pressure: 0.0, + ); + + /// Creates an enter event from a [PointerEvent]. + /// + /// This is used by the [MouseTracker] to synthesize enter events. + factory PointerEnterEvent.fromMouseEvent(PointerEvent event) => PointerEnterEvent( + viewId: event.viewId, + timeStamp: event.timeStamp, + pointer: event.pointer, + kind: event.kind, + device: event.device, + position: event.position, + delta: event.delta, + buttons: event.buttons, + obscured: event.obscured, + pressureMin: event.pressureMin, + pressureMax: event.pressureMax, + distance: event.distance, + distanceMax: event.distanceMax, + size: event.size, + radiusMajor: event.radiusMajor, + radiusMinor: event.radiusMinor, + radiusMin: event.radiusMin, + radiusMax: event.radiusMax, + orientation: event.orientation, + tilt: event.tilt, + down: event.down, + synthesized: event.synthesized, + ).transformed(event.transform); + + @override + PointerEnterEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerEnterEvent(original as PointerEnterEvent? ?? this, transform); + } +} + +class _TransformedPointerEnterEvent extends _TransformedPointerEvent with _CopyPointerEnterEvent implements PointerEnterEvent { + _TransformedPointerEnterEvent(this.original, this.transform); + + @override + final PointerEnterEvent original; + + @override + final Matrix4 transform; + + @override + PointerEnterEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerExitEvent on PointerEvent { + @override + PointerExitEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerExitEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + delta: delta ?? this.delta, + buttons: buttons ?? this.buttons, + obscured: obscured ?? this.obscured, + pressureMin: pressureMin ?? this.pressureMin, + pressureMax: pressureMax ?? this.pressureMax, + distance: distance ?? this.distance, + distanceMax: distanceMax ?? this.distanceMax, + size: size ?? this.size, + radiusMajor: radiusMajor ?? this.radiusMajor, + radiusMinor: radiusMinor ?? this.radiusMinor, + radiusMin: radiusMin ?? this.radiusMin, + radiusMax: radiusMax ?? this.radiusMax, + orientation: orientation ?? this.orientation, + tilt: tilt ?? this.tilt, + synthesized: synthesized ?? this.synthesized, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The pointer has moved with respect to the device while the pointer is or is +/// not in contact with the device, and exited a target object. +/// +/// See also: +/// +/// * [PointerHoverEvent], which reports when the pointer has moved while +/// within an object. +/// * [PointerEnterEvent], which reports when the pointer has entered an object. +/// * [PointerMoveEvent], which reports movement while the pointer is in +/// contact with the device. +/// * [MouseRegion.onExit], which allows callers to be notified of these +/// events in a widget tree. +class PointerExitEvent extends PointerEvent with _PointerEventDescription, _CopyPointerExitEvent { + /// Creates a pointer exit event. + const PointerExitEvent({ + super.viewId, + super.timeStamp, + super.kind, + super.pointer, + super.device, + super.position, + super.delta, + super.buttons, + super.obscured, + super.pressureMin, + super.pressureMax, + super.distance, + super.distanceMax, + super.size, + super.radiusMajor, + super.radiusMinor, + super.radiusMin, + super.radiusMax, + super.orientation, + super.tilt, + super.down, + super.synthesized, + super.embedderId, + }) : assert(!identical(kind, PointerDeviceKind.trackpad)), + super( + pressure: 0.0, + ); + + /// Creates an exit event from a [PointerEvent]. + /// + /// This is used by the [MouseTracker] to synthesize exit events. + factory PointerExitEvent.fromMouseEvent(PointerEvent event) => PointerExitEvent( + viewId: event.viewId, + timeStamp: event.timeStamp, + pointer: event.pointer, + kind: event.kind, + device: event.device, + position: event.position, + delta: event.delta, + buttons: event.buttons, + obscured: event.obscured, + pressureMin: event.pressureMin, + pressureMax: event.pressureMax, + distance: event.distance, + distanceMax: event.distanceMax, + size: event.size, + radiusMajor: event.radiusMajor, + radiusMinor: event.radiusMinor, + radiusMin: event.radiusMin, + radiusMax: event.radiusMax, + orientation: event.orientation, + tilt: event.tilt, + down: event.down, + synthesized: event.synthesized, + ).transformed(event.transform); + + @override + PointerExitEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerExitEvent(original as PointerExitEvent? ?? this, transform); + } + +} + +class _TransformedPointerExitEvent extends _TransformedPointerEvent with _CopyPointerExitEvent implements PointerExitEvent { + _TransformedPointerExitEvent(this.original, this.transform); + + @override + final PointerExitEvent original; + + @override + final Matrix4 transform; + + @override + PointerExitEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerDownEvent on PointerEvent { + @override + PointerDownEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerDownEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + pointer: pointer ?? this.pointer, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + buttons: buttons ?? this.buttons, + obscured: obscured ?? this.obscured, + pressure: pressure ?? this.pressure, + pressureMin: pressureMin ?? this.pressureMin, + pressureMax: pressureMax ?? this.pressureMax, + distanceMax: distanceMax ?? this.distanceMax, + size: size ?? this.size, + radiusMajor: radiusMajor ?? this.radiusMajor, + radiusMinor: radiusMinor ?? this.radiusMinor, + radiusMin: radiusMin ?? this.radiusMin, + radiusMax: radiusMax ?? this.radiusMax, + orientation: orientation ?? this.orientation, + tilt: tilt ?? this.tilt, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The pointer has made contact with the device. +/// +/// See also: +/// +/// * [Listener.onPointerDown], which allows callers to be notified of these +/// events in a widget tree. +class PointerDownEvent extends PointerEvent with _PointerEventDescription, _CopyPointerDownEvent { + /// Creates a pointer down event. + const PointerDownEvent({ + super.viewId, + super.timeStamp, + super.pointer, + super.kind, + super.device, + super.position, + super.buttons = kPrimaryButton, + super.obscured, + super.pressure, + super.pressureMin, + super.pressureMax, + super.distanceMax, + super.size, + super.radiusMajor, + super.radiusMinor, + super.radiusMin, + super.radiusMax, + super.orientation, + super.tilt, + super.embedderId, + }) : assert(!identical(kind, PointerDeviceKind.trackpad)), + super( + down: true, + distance: 0.0, + ); + + @override + PointerDownEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerDownEvent(original as PointerDownEvent? ?? this, transform); + } +} + +class _TransformedPointerDownEvent extends _TransformedPointerEvent with _CopyPointerDownEvent implements PointerDownEvent { + _TransformedPointerDownEvent(this.original, this.transform); + + @override + final PointerDownEvent original; + + @override + final Matrix4 transform; + + @override + PointerDownEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerMoveEvent on PointerEvent { + @override + PointerMoveEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerMoveEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + pointer: pointer ?? this.pointer, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + delta: delta ?? this.delta, + buttons: buttons ?? this.buttons, + obscured: obscured ?? this.obscured, + pressure: pressure ?? this.pressure, + pressureMin: pressureMin ?? this.pressureMin, + pressureMax: pressureMax ?? this.pressureMax, + distanceMax: distanceMax ?? this.distanceMax, + size: size ?? this.size, + radiusMajor: radiusMajor ?? this.radiusMajor, + radiusMinor: radiusMinor ?? this.radiusMinor, + radiusMin: radiusMin ?? this.radiusMin, + radiusMax: radiusMax ?? this.radiusMax, + orientation: orientation ?? this.orientation, + tilt: tilt ?? this.tilt, + synthesized: synthesized ?? this.synthesized, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The pointer has moved with respect to the device while the pointer is in +/// contact with the device. +/// +/// See also: +/// +/// * [PointerHoverEvent], which reports movement while the pointer is not in +/// contact with the device. +/// * [Listener.onPointerMove], which allows callers to be notified of these +/// events in a widget tree. +class PointerMoveEvent extends PointerEvent with _PointerEventDescription, _CopyPointerMoveEvent { + /// Creates a pointer move event. + const PointerMoveEvent({ + super.viewId, + super.timeStamp, + super.pointer, + super.kind, + super.device, + super.position, + super.delta, + super.buttons = kPrimaryButton, + super.obscured, + super.pressure, + super.pressureMin, + super.pressureMax, + super.distanceMax, + super.size, + super.radiusMajor, + super.radiusMinor, + super.radiusMin, + super.radiusMax, + super.orientation, + super.tilt, + super.platformData, + super.synthesized, + super.embedderId, + }) : assert(!identical(kind, PointerDeviceKind.trackpad)), + super( + down: true, + distance: 0.0, + ); + + @override + PointerMoveEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + + return _TransformedPointerMoveEvent(original as PointerMoveEvent? ?? this, transform); + } +} + +class _TransformedPointerMoveEvent extends _TransformedPointerEvent with _CopyPointerMoveEvent implements PointerMoveEvent { + _TransformedPointerMoveEvent(this.original, this.transform); + + @override + final PointerMoveEvent original; + + @override + final Matrix4 transform; + + @override + PointerMoveEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerUpEvent on PointerEvent { + @override + PointerUpEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? localPosition, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerUpEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + pointer: pointer ?? this.pointer, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + buttons: buttons ?? this.buttons, + obscured: obscured ?? this.obscured, + pressure: pressure ?? this.pressure, + pressureMin: pressureMin ?? this.pressureMin, + pressureMax: pressureMax ?? this.pressureMax, + distance: distance ?? this.distance, + distanceMax: distanceMax ?? this.distanceMax, + size: size ?? this.size, + radiusMajor: radiusMajor ?? this.radiusMajor, + radiusMinor: radiusMinor ?? this.radiusMinor, + radiusMin: radiusMin ?? this.radiusMin, + radiusMax: radiusMax ?? this.radiusMax, + orientation: orientation ?? this.orientation, + tilt: tilt ?? this.tilt, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The pointer has stopped making contact with the device. +/// +/// See also: +/// +/// * [Listener.onPointerUp], which allows callers to be notified of these +/// events in a widget tree. +class PointerUpEvent extends PointerEvent with _PointerEventDescription, _CopyPointerUpEvent { + /// Creates a pointer up event. + const PointerUpEvent({ + super.viewId, + super.timeStamp, + super.pointer, + super.kind, + super.device, + super.position, + super.buttons, + super.obscured, + // Allow pressure customization here because PointerUpEvent can contain + // non-zero pressure. See https://github.com/flutter/flutter/issues/31340 + super.pressure = 0.0, + super.pressureMin, + super.pressureMax, + super.distance, + super.distanceMax, + super.size, + super.radiusMajor, + super.radiusMinor, + super.radiusMin, + super.radiusMax, + super.orientation, + super.tilt, + super.embedderId, + }) : assert(!identical(kind, PointerDeviceKind.trackpad)), + super( + down: false, + ); + + @override + PointerUpEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerUpEvent(original as PointerUpEvent? ?? this, transform); + } +} + +class _TransformedPointerUpEvent extends _TransformedPointerEvent with _CopyPointerUpEvent implements PointerUpEvent { + _TransformedPointerUpEvent(this.original, this.transform); + + @override + final PointerUpEvent original; + + @override + final Matrix4 transform; + + @override + PointerUpEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +/// An event that corresponds to a discrete pointer signal. +/// +/// Pointer signals are events that originate from the pointer but don't change +/// the state of the pointer itself, and are discrete rather than needing to be +/// interpreted in the context of a series of events. +/// +/// See also: +/// +/// * [Listener.onPointerSignal], which allows callers to be notified of these +/// events in a widget tree. +/// * [PointerSignalResolver], which provides an opt-in mechanism whereby +/// participating agents may disambiguate an event's target. +abstract class PointerSignalEvent extends PointerEvent { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const PointerSignalEvent({ + super.viewId, + super.timeStamp, + super.pointer, + super.kind = PointerDeviceKind.mouse, + super.device, + super.position, + super.embedderId, + }); +} + +mixin _CopyPointerScrollEvent on PointerEvent { + /// The amount to scroll, in logical pixels. + Offset get scrollDelta; + + @override + PointerScrollEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerScrollEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + scrollDelta: scrollDelta, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The pointer issued a scroll event. +/// +/// Scrolling the scroll wheel on a mouse is an example of an event that +/// would create a [PointerScrollEvent]. +/// +/// See also: +/// +/// * [Listener.onPointerSignal], which allows callers to be notified of these +/// events in a widget tree. +/// * [PointerSignalResolver], which provides an opt-in mechanism whereby +/// participating agents may disambiguate an event's target. +class PointerScrollEvent extends PointerSignalEvent with _PointerEventDescription, _CopyPointerScrollEvent { + /// Creates a pointer scroll event. + const PointerScrollEvent({ + super.viewId, + super.timeStamp, + super.kind, + super.device, + super.position, + this.scrollDelta = Offset.zero, + super.embedderId, + }); + + @override + final Offset scrollDelta; + + @override + PointerScrollEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerScrollEvent(original as PointerScrollEvent? ?? this, transform); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('scrollDelta', scrollDelta)); + } +} + +class _TransformedPointerScrollEvent extends _TransformedPointerEvent with _CopyPointerScrollEvent implements PointerScrollEvent { + _TransformedPointerScrollEvent(this.original, this.transform); + + @override + final PointerScrollEvent original; + + @override + final Matrix4 transform; + + @override + Offset get scrollDelta => original.scrollDelta; + + @override + PointerScrollEvent transformed(Matrix4? transform) => original.transformed(transform); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('scrollDelta', scrollDelta)); + } +} + +mixin _CopyPointerScrollInertiaCancelEvent on PointerEvent { + @override + PointerScrollInertiaCancelEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerScrollInertiaCancelEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The pointer issued a scroll-inertia cancel event. +/// +/// Touching the trackpad immediately after a scroll is an example of an event +/// that would create a [PointerScrollInertiaCancelEvent]. +/// +/// See also: +/// +/// * [Listener.onPointerSignal], which allows callers to be notified of these +/// events in a widget tree. +/// * [PointerSignalResolver], which provides an opt-in mechanism whereby +/// participating agents may disambiguate an event's target. +class PointerScrollInertiaCancelEvent extends PointerSignalEvent with _PointerEventDescription, _CopyPointerScrollInertiaCancelEvent { + /// Creates a pointer scroll-inertia cancel event. + const PointerScrollInertiaCancelEvent({ + super.viewId, + super.timeStamp, + super.kind, + super.device, + super.position, + super.embedderId, + }); + + @override + PointerScrollInertiaCancelEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerScrollInertiaCancelEvent(original as PointerScrollInertiaCancelEvent? ?? this, transform); + } +} + +class _TransformedPointerScrollInertiaCancelEvent extends _TransformedPointerEvent with _CopyPointerScrollInertiaCancelEvent implements PointerScrollInertiaCancelEvent { + _TransformedPointerScrollInertiaCancelEvent(this.original, this.transform); + + @override + final PointerScrollInertiaCancelEvent original; + + @override + final Matrix4 transform; + + @override + PointerScrollInertiaCancelEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerScaleEvent on PointerEvent { + /// The scale (zoom factor) of the event. + double get scale; + + @override + PointerScaleEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + double? scale, + }) { + return PointerScaleEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + embedderId: embedderId ?? this.embedderId, + scale: scale ?? this.scale, + ).transformed(transform); + } +} + +/// The pointer issued a scale event. +/// +/// Pinching-to-zoom in the browser is an example of an event +/// that would create a [PointerScaleEvent]. +/// +/// See also: +/// +/// * [Listener.onPointerSignal], which allows callers to be notified of these +/// events in a widget tree. +/// * [PointerSignalResolver], which provides an opt-in mechanism whereby +/// participating agents may disambiguate an event's target. +class PointerScaleEvent extends PointerSignalEvent with _PointerEventDescription, _CopyPointerScaleEvent { + /// Creates a pointer scale event. + const PointerScaleEvent({ + super.viewId, + super.timeStamp, + super.kind, + super.device, + super.position, + super.embedderId, + this.scale = 1.0, + }); + + @override + final double scale; + + @override + PointerScaleEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerScaleEvent(original as PointerScaleEvent? ?? this, transform); + } +} + +class _TransformedPointerScaleEvent extends _TransformedPointerEvent with _CopyPointerScaleEvent implements PointerScaleEvent { + _TransformedPointerScaleEvent(this.original, this.transform); + + @override + final PointerScaleEvent original; + + @override + final Matrix4 transform; + + @override + double get scale => original.scale; + + @override + PointerScaleEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerPanZoomStartEvent on PointerEvent { + @override + PointerPanZoomStartEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + assert(kind == null || identical(kind, PointerDeviceKind.trackpad)); + return PointerPanZoomStartEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + device: device ?? this.device, + position: position ?? this.position, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// A pan/zoom has begun on this pointer. +/// +/// See also: +/// +/// * [Listener.onPointerPanZoomStart], which allows callers to be notified of these +/// events in a widget tree. +class PointerPanZoomStartEvent extends PointerEvent with _PointerEventDescription, _CopyPointerPanZoomStartEvent { + /// Creates a pointer pan/zoom start event. + const PointerPanZoomStartEvent({ + super.viewId, + super.timeStamp, + super.device, + super.pointer, + super.position, + super.embedderId, + super.synthesized, + }) : super(kind: PointerDeviceKind.trackpad); + + @override + PointerPanZoomStartEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerPanZoomStartEvent(original as PointerPanZoomStartEvent? ?? this, transform); + } +} + +class _TransformedPointerPanZoomStartEvent extends _TransformedPointerEvent with _CopyPointerPanZoomStartEvent implements PointerPanZoomStartEvent { + _TransformedPointerPanZoomStartEvent(this.original, this.transform); + + @override + final PointerPanZoomStartEvent original; + + @override + final Matrix4 transform; + + @override + PointerPanZoomStartEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerPanZoomUpdateEvent on PointerEvent { + /// The total pan offset of the pan/zoom. + Offset get pan; + /// The total pan offset of the pan/zoom, transformed into local coordinates. + Offset get localPan; + /// The amount the pan offset changed since the last event. + Offset get panDelta; + /// The amount the pan offset changed since the last event, transformed into local coordinates. + Offset get localPanDelta; + /// The scale (zoom factor) of the pan/zoom. + double get scale; + /// The amount the pan/zoom has rotated in radians so far. + double get rotation; + + @override + PointerPanZoomUpdateEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + Offset? pan, + Offset? localPan, + Offset? panDelta, + Offset? localPanDelta, + double? scale, + double? rotation, + }) { + assert(kind == null || identical(kind, PointerDeviceKind.trackpad)); + return PointerPanZoomUpdateEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + device: device ?? this.device, + position: position ?? this.position, + embedderId: embedderId ?? this.embedderId, + pan: pan ?? this.pan, + panDelta: panDelta ?? this.panDelta, + scale: scale ?? this.scale, + rotation: rotation ?? this.rotation, + ).transformed(transform); + } +} + +/// The active pan/zoom on this pointer has updated. +/// +/// See also: +/// +/// * [Listener.onPointerPanZoomUpdate], which allows callers to be notified of these +/// events in a widget tree. +class PointerPanZoomUpdateEvent extends PointerEvent with _PointerEventDescription, _CopyPointerPanZoomUpdateEvent { + /// Creates a pointer pan/zoom update event. + const PointerPanZoomUpdateEvent({ + super.viewId, + super.timeStamp, + super.device, + super.pointer, + super.position, + super.embedderId, + this.pan = Offset.zero, + this.panDelta = Offset.zero, + this.scale = 1.0, + this.rotation = 0.0, + super.synthesized, + }) : super(kind: PointerDeviceKind.trackpad); + + @override + final Offset pan; + @override + Offset get localPan => pan; + @override + final Offset panDelta; + @override + Offset get localPanDelta => panDelta; + @override + final double scale; + @override + final double rotation; + + @override + PointerPanZoomUpdateEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerPanZoomUpdateEvent(original as PointerPanZoomUpdateEvent? ?? this, transform); + } +} + +class _TransformedPointerPanZoomUpdateEvent extends _TransformedPointerEvent with _CopyPointerPanZoomUpdateEvent implements PointerPanZoomUpdateEvent { + _TransformedPointerPanZoomUpdateEvent(this.original, this.transform); + + @override + Offset get pan => original.pan; + + @override + late final Offset localPan = PointerEvent.transformPosition(transform, pan); + + @override + Offset get panDelta => original.panDelta; + + @override + late final Offset localPanDelta = PointerEvent.transformDeltaViaPositions( + transform: transform, + untransformedDelta: panDelta, + untransformedEndPosition: pan, + transformedEndPosition: localPan, + ); + + @override + double get scale => original.scale; + + @override + double get rotation => original.rotation; + + @override + final PointerPanZoomUpdateEvent original; + + @override + final Matrix4 transform; + + @override + PointerPanZoomUpdateEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerPanZoomEndEvent on PointerEvent { + @override + PointerPanZoomEndEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + assert(kind == null || identical(kind, PointerDeviceKind.trackpad)); + return PointerPanZoomEndEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + device: device ?? this.device, + position: position ?? this.position, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The pan/zoom on this pointer has ended. +/// +/// See also: +/// +/// * [Listener.onPointerPanZoomEnd], which allows callers to be notified of these +/// events in a widget tree. +class PointerPanZoomEndEvent extends PointerEvent with _PointerEventDescription, _CopyPointerPanZoomEndEvent { + /// Creates a pointer pan/zoom end event. + const PointerPanZoomEndEvent({ + super.viewId, + super.timeStamp, + super.device, + super.pointer, + super.position, + super.embedderId, + super.synthesized, + }) : super(kind: PointerDeviceKind.trackpad); + + @override + PointerPanZoomEndEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerPanZoomEndEvent(original as PointerPanZoomEndEvent? ?? this, transform); + } +} + +class _TransformedPointerPanZoomEndEvent extends _TransformedPointerEvent with _CopyPointerPanZoomEndEvent implements PointerPanZoomEndEvent { + _TransformedPointerPanZoomEndEvent(this.original, this.transform); + + @override + final PointerPanZoomEndEvent original; + + @override + final Matrix4 transform; + + @override + PointerPanZoomEndEvent transformed(Matrix4? transform) => original.transformed(transform); +} + +mixin _CopyPointerCancelEvent on PointerEvent { + @override + PointerCancelEvent copyWith({ + int? viewId, + Duration? timeStamp, + int? pointer, + PointerDeviceKind? kind, + int? device, + Offset? position, + Offset? delta, + int? buttons, + bool? obscured, + double? pressure, + double? pressureMin, + double? pressureMax, + double? distance, + double? distanceMax, + double? size, + double? radiusMajor, + double? radiusMinor, + double? radiusMin, + double? radiusMax, + double? orientation, + double? tilt, + bool? synthesized, + int? embedderId, + }) { + return PointerCancelEvent( + viewId: viewId ?? this.viewId, + timeStamp: timeStamp ?? this.timeStamp, + pointer: pointer ?? this.pointer, + kind: kind ?? this.kind, + device: device ?? this.device, + position: position ?? this.position, + buttons: buttons ?? this.buttons, + obscured: obscured ?? this.obscured, + pressureMin: pressureMin ?? this.pressureMin, + pressureMax: pressureMax ?? this.pressureMax, + distance: distance ?? this.distance, + distanceMax: distanceMax ?? this.distanceMax, + size: size ?? this.size, + radiusMajor: radiusMajor ?? this.radiusMajor, + radiusMinor: radiusMinor ?? this.radiusMinor, + radiusMin: radiusMin ?? this.radiusMin, + radiusMax: radiusMax ?? this.radiusMax, + orientation: orientation ?? this.orientation, + tilt: tilt ?? this.tilt, + embedderId: embedderId ?? this.embedderId, + ).transformed(transform); + } +} + +/// The input from the pointer is no longer directed towards this receiver. +/// +/// See also: +/// +/// * [Listener.onPointerCancel], which allows callers to be notified of these +/// events in a widget tree. +class PointerCancelEvent extends PointerEvent with _PointerEventDescription, _CopyPointerCancelEvent { + /// Creates a pointer cancel event. + const PointerCancelEvent({ + super.viewId, + super.timeStamp, + super.pointer, + super.kind, + super.device, + super.position, + super.buttons, + super.obscured, + super.pressureMin, + super.pressureMax, + super.distance, + super.distanceMax, + super.size, + super.radiusMajor, + super.radiusMinor, + super.radiusMin, + super.radiusMax, + super.orientation, + super.tilt, + super.embedderId, + }) : assert(!identical(kind, PointerDeviceKind.trackpad)), + super( + down: false, + pressure: 0.0, + ); + + @override + PointerCancelEvent transformed(Matrix4? transform) { + if (transform == null || transform == this.transform) { + return this; + } + return _TransformedPointerCancelEvent(original as PointerCancelEvent? ?? this, transform); + } +} + +/// Determine the appropriate hit slop pixels based on the [kind] of pointer. +double computeHitSlop(PointerDeviceKind kind, DeviceGestureSettings? settings) { + switch (kind) { + case PointerDeviceKind.mouse: + return kPrecisePointerHitSlop; + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.unknown: + case PointerDeviceKind.touch: + case PointerDeviceKind.trackpad: + return settings?.touchSlop ?? kTouchSlop; + } +} + +/// Determine the appropriate pan slop pixels based on the [kind] of pointer. +double computePanSlop(PointerDeviceKind kind, DeviceGestureSettings? settings) { + switch (kind) { + case PointerDeviceKind.mouse: + return kPrecisePointerPanSlop; + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.unknown: + case PointerDeviceKind.touch: + case PointerDeviceKind.trackpad: + return settings?.panSlop ?? kPanSlop; + } +} + +/// Determine the appropriate scale slop pixels based on the [kind] of pointer. +double computeScaleSlop(PointerDeviceKind kind) { + switch (kind) { + case PointerDeviceKind.mouse: + return kPrecisePointerScaleSlop; + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.unknown: + case PointerDeviceKind.touch: + case PointerDeviceKind.trackpad: + return kScaleSlop; + } +} + +class _TransformedPointerCancelEvent extends _TransformedPointerEvent with _CopyPointerCancelEvent implements PointerCancelEvent { + _TransformedPointerCancelEvent(this.original, this.transform); + + @override + final PointerCancelEvent original; + + @override + final Matrix4 transform; + + @override + PointerCancelEvent transformed(Matrix4? transform) => original.transformed(transform); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/force_press.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/force_press.dart new file mode 100644 index 0000000000000000000000000000000000000000..d17255a8f1988bda3bafb0d9fe7967055194f4ad --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/force_press.dart @@ -0,0 +1,336 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show clampDouble; + +import 'events.dart'; +import 'recognizer.dart'; + +export 'dart:ui' show Offset, PointerDeviceKind; + +export 'events.dart' show PointerDownEvent, PointerEvent; + +enum _ForceState { + // No pointer has touched down and the detector is ready for a pointer down to occur. + ready, + + // A pointer has touched down, but a force press gesture has not yet been detected. + possible, + + // A pointer is down and a force press gesture has been detected. However, if + // the ForcePressGestureRecognizer is the only recognizer in the arena, thus + // accepted as soon as the gesture state is possible, the gesture will not + // yet have started. + accepted, + + // A pointer is down and the gesture has started, ie. the pressure of the pointer + // has just become greater than the ForcePressGestureRecognizer.startPressure. + started, + + // A pointer is down and the pressure of the pointer has just become greater + // than the ForcePressGestureRecognizer.peakPressure. Even after a pointer + // crosses this threshold, onUpdate callbacks will still be sent. + peaked, +} + +/// Details object for callbacks that use [GestureForcePressStartCallback], +/// [GestureForcePressPeakCallback], [GestureForcePressEndCallback] or +/// [GestureForcePressUpdateCallback]. +/// +/// See also: +/// +/// * [ForcePressGestureRecognizer.onStart], [ForcePressGestureRecognizer.onPeak], +/// [ForcePressGestureRecognizer.onEnd], and [ForcePressGestureRecognizer.onUpdate] +/// which use [ForcePressDetails]. +class ForcePressDetails { + /// Creates details for a [GestureForcePressStartCallback], + /// [GestureForcePressPeakCallback] or [GestureForcePressEndCallback]. + ForcePressDetails({ + required this.globalPosition, + Offset? localPosition, + required this.pressure, + }) : localPosition = localPosition ?? globalPosition; + + /// The global position at which the function was called. + final Offset globalPosition; + + /// The local position at which the function was called. + final Offset localPosition; + + /// The pressure of the pointer on the screen. + final double pressure; +} + +/// Signature used by a [ForcePressGestureRecognizer] for when a pointer has +/// pressed with at least [ForcePressGestureRecognizer.startPressure]. +typedef GestureForcePressStartCallback = void Function(ForcePressDetails details); + +/// Signature used by [ForcePressGestureRecognizer] for when a pointer that has +/// pressed with at least [ForcePressGestureRecognizer.peakPressure]. +typedef GestureForcePressPeakCallback = void Function(ForcePressDetails details); + +/// Signature used by [ForcePressGestureRecognizer] during the frames +/// after the triggering of a [ForcePressGestureRecognizer.onStart] callback. +typedef GestureForcePressUpdateCallback = void Function(ForcePressDetails details); + +/// Signature for when the pointer that previously triggered a +/// [ForcePressGestureRecognizer.onStart] callback is no longer in contact +/// with the screen. +typedef GestureForcePressEndCallback = void Function(ForcePressDetails details); + +/// Signature used by [ForcePressGestureRecognizer] for interpolating the raw +/// device pressure to a value in the range `[0, 1]` given the device's pressure +/// min and pressure max. +typedef GestureForceInterpolation = double Function(double pressureMin, double pressureMax, double pressure); + +/// Recognizes a force press on devices that have force sensors. +/// +/// Only the force from a single pointer is used to invoke events. A tap +/// recognizer will win against this recognizer on pointer up as long as the +/// pointer has not pressed with a force greater than +/// [ForcePressGestureRecognizer.startPressure]. A long press recognizer will +/// win when the press down time exceeds the threshold time as long as the +/// pointer's pressure was never greater than +/// [ForcePressGestureRecognizer.startPressure] in that duration. +/// +/// As of November, 2018 iPhone devices of generation 6S and higher have +/// force touch functionality, with the exception of the iPhone XR. In addition, +/// a small handful of Android devices have this functionality as well. +/// +/// Devices with faux screen pressure sensors like the Pixel 2 and 3 will not +/// send any force press related callbacks. +/// +/// Reported pressure will always be in the range 0.0 to 1.0, where 1.0 is +/// maximum pressure and 0.0 is minimum pressure. If using a custom +/// [interpolation] callback, the pressure reported will correspond to that +/// custom curve. +class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { + /// Creates a force press gesture recognizer. + /// + /// The [startPressure] defaults to 0.4, and [peakPressure] defaults to 0.85 + /// where a value of 0.0 is no pressure and a value of 1.0 is maximum pressure. + /// + /// The [startPressure], [peakPressure] and [interpolation] arguments must not + /// be null. The [peakPressure] argument must be greater than [startPressure]. + /// The [interpolation] callback must always return a value in the range 0.0 + /// to 1.0 for values of `pressure` that are between `pressureMin` and + /// `pressureMax`. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + ForcePressGestureRecognizer({ + this.startPressure = 0.4, + this.peakPressure = 0.85, + this.interpolation = _inverseLerp, + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }) : assert(peakPressure > startPressure); + + /// A pointer is in contact with the screen and has just pressed with a force + /// exceeding the [startPressure]. Consequently, if there were other gesture + /// detectors, only the force press gesture will be detected and all others + /// will be rejected. + /// + /// The position of the pointer is provided in the callback's `details` + /// argument, which is a [ForcePressDetails] object. + GestureForcePressStartCallback? onStart; + + /// A pointer is in contact with the screen and is either moving on the plane + /// of the screen, pressing the screen with varying forces or both + /// simultaneously. + /// + /// This callback will be invoked for every pointer event after the invocation + /// of [onStart] and/or [onPeak] and before the invocation of [onEnd], no + /// matter what the pressure is during this time period. The position and + /// pressure of the pointer is provided in the callback's `details` argument, + /// which is a [ForcePressDetails] object. + GestureForcePressUpdateCallback? onUpdate; + + /// A pointer is in contact with the screen and has just pressed with a force + /// exceeding the [peakPressure]. This is an arbitrary second level action + /// threshold and isn't necessarily the maximum possible device pressure + /// (which is 1.0). + /// + /// The position of the pointer is provided in the callback's `details` + /// argument, which is a [ForcePressDetails] object. + GestureForcePressPeakCallback? onPeak; + + /// A pointer is no longer in contact with the screen. + /// + /// The position of the pointer is provided in the callback's `details` + /// argument, which is a [ForcePressDetails] object. + GestureForcePressEndCallback? onEnd; + + /// The pressure of the press required to initiate a force press. + /// + /// A value of 0.0 is no pressure, and 1.0 is maximum pressure. + final double startPressure; + + /// The pressure of the press required to peak a force press. + /// + /// A value of 0.0 is no pressure, and 1.0 is maximum pressure. This value + /// must be greater than [startPressure]. + final double peakPressure; + + /// The function used to convert the raw device pressure values into a value + /// in the range 0.0 to 1.0. + /// + /// The function takes in the device's minimum, maximum and raw touch pressure + /// and returns a value in the range 0.0 to 1.0 denoting the interpolated + /// touch pressure. + /// + /// This function must always return values in the range 0.0 to 1.0 given a + /// pressure that is between the minimum and maximum pressures. It may return + /// `double.NaN` for values that it does not want to support. + /// + /// By default, the function is a linear interpolation; however, changing the + /// function could be useful to accommodate variations in the way different + /// devices respond to pressure, or to change how animations from pressure + /// feedback are rendered. + /// + /// For example, an ease-in curve can be used to determine the interpolated + /// value: + /// + /// ```dart + /// double interpolateWithEasing(double min, double max, double t) { + /// final double lerp = (t - min) / (max - min); + /// return Curves.easeIn.transform(lerp); + /// } + /// ``` + final GestureForceInterpolation interpolation; + + late OffsetPair _lastPosition; + late double _lastPressure; + _ForceState _state = _ForceState.ready; + + @override + void addAllowedPointer(PointerDownEvent event) { + // If the device has a maximum pressure of less than or equal to 1, it + // doesn't have touch pressure sensing capabilities. Do not participate + // in the gesture arena. + if (event.pressureMax <= 1.0) { + resolve(GestureDisposition.rejected); + } else { + super.addAllowedPointer(event); + if (_state == _ForceState.ready) { + _state = _ForceState.possible; + _lastPosition = OffsetPair.fromEventPosition(event); + } + } + } + + @override + void handleEvent(PointerEvent event) { + assert(_state != _ForceState.ready); + // A static pointer with changes in pressure creates PointerMoveEvent events. + if (event is PointerMoveEvent || event is PointerDownEvent) { + final double pressure = interpolation(event.pressureMin, event.pressureMax, event.pressure); + assert( + (pressure >= 0.0 && pressure <= 1.0) || // Interpolated pressure must be between 1.0 and 0.0... + pressure.isNaN, // and interpolation may return NaN for values it doesn't want to support... + ); + + _lastPosition = OffsetPair.fromEventPosition(event); + _lastPressure = pressure; + + if (_state == _ForceState.possible) { + if (pressure > startPressure) { + _state = _ForceState.started; + resolve(GestureDisposition.accepted); + } else if (event.delta.distanceSquared > computeHitSlop(event.kind, gestureSettings)) { + resolve(GestureDisposition.rejected); + } + } + // In case this is the only gesture detector we still don't want to start + // the gesture until the pressure is greater than the startPressure. + if (pressure > startPressure && _state == _ForceState.accepted) { + _state = _ForceState.started; + if (onStart != null) { + invokeCallback('onStart', () => onStart!(ForcePressDetails( + pressure: pressure, + globalPosition: _lastPosition.global, + localPosition: _lastPosition.local, + ))); + } + } + if (onPeak != null && pressure > peakPressure && + (_state == _ForceState.started)) { + _state = _ForceState.peaked; + if (onPeak != null) { + invokeCallback('onPeak', () => onPeak!(ForcePressDetails( + pressure: pressure, + globalPosition: event.position, + localPosition: event.localPosition, + ))); + } + } + if (onUpdate != null && !pressure.isNaN && + (_state == _ForceState.started || _state == _ForceState.peaked)) { + if (onUpdate != null) { + invokeCallback('onUpdate', () => onUpdate!(ForcePressDetails( + pressure: pressure, + globalPosition: event.position, + localPosition: event.localPosition, + ))); + } + } + } + stopTrackingIfPointerNoLongerDown(event); + } + + @override + void acceptGesture(int pointer) { + if (_state == _ForceState.possible) { + _state = _ForceState.accepted; + } + + if (onStart != null && _state == _ForceState.started) { + invokeCallback('onStart', () => onStart!(ForcePressDetails( + pressure: _lastPressure, + globalPosition: _lastPosition.global, + localPosition: _lastPosition.local, + ))); + } + } + + @override + void didStopTrackingLastPointer(int pointer) { + final bool wasAccepted = _state == _ForceState.started || _state == _ForceState.peaked; + if (_state == _ForceState.possible) { + resolve(GestureDisposition.rejected); + return; + } + if (wasAccepted && onEnd != null) { + if (onEnd != null) { + invokeCallback('onEnd', () => onEnd!(ForcePressDetails( + pressure: 0.0, + globalPosition: _lastPosition.global, + localPosition: _lastPosition.local, + ))); + } + } + _state = _ForceState.ready; + } + + @override + void rejectGesture(int pointer) { + stopTrackingPointer(pointer); + didStopTrackingLastPointer(pointer); + } + + static double _inverseLerp(double min, double max, double t) { + assert(min <= max); + double value = (t - min) / (max - min); + + // If the device incorrectly reports a pressure outside of pressureMin + // and pressureMax, we still want this recognizer to respond normally. + if (!value.isNaN) { + value = clampDouble(value, 0.0, 1.0); + } + return value; + } + + @override + String get debugDescription => 'force press'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/gesture_settings.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/gesture_settings.dart new file mode 100644 index 0000000000000000000000000000000000000000..d35a4993e0c6fbdcbbcf544e48c8be4c446cf86b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/gesture_settings.dart @@ -0,0 +1,56 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; + +export 'dart:ui' show FlutterView; + +/// The device specific gesture settings scaled into logical pixels. +/// +/// This configuration can be retrieved from the window, or more commonly from a +/// [MediaQuery] widget. +/// +/// See also: +/// +/// * [ui.GestureSettings], the configuration that this is derived from. +@immutable +class DeviceGestureSettings { + /// Create a new [DeviceGestureSettings] with configured settings in logical + /// pixels. + const DeviceGestureSettings({ + this.touchSlop, + }); + + /// Create a new [DeviceGestureSettings] from the provided [view]. + factory DeviceGestureSettings.fromView(ui.FlutterView view) { + final double? physicalTouchSlop = view.gestureSettings.physicalTouchSlop; + return DeviceGestureSettings( + touchSlop: physicalTouchSlop == null ? null : physicalTouchSlop / view.devicePixelRatio + ); + } + + /// The touch slop value in logical pixels, or `null` if it was not set. + final double? touchSlop; + + /// The touch slop value for pan gestures, in logical pixels, or `null` if it + /// was not set. + double? get panSlop => touchSlop != null ? (touchSlop! * 2) : null; + + @override + int get hashCode => Object.hash(touchSlop, 23); + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is DeviceGestureSettings + && other.touchSlop == touchSlop; + } + + @override + String toString() => 'DeviceGestureSettings(touchSlop: $touchSlop)'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/hit_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/hit_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..b620872044ce0fcae7384e0783ef1e0bfe77a4a6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/hit_test.dart @@ -0,0 +1,288 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'package:flutter/foundation.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'events.dart'; + +export 'dart:ui' show Offset; + +export 'package:vector_math/vector_math_64.dart' show Matrix4; + +export 'events.dart' show PointerEvent; + +/// An object that can hit-test pointers. +abstract interface class HitTestable { + /// Deprecated. Use [hitTestInView] instead. + @Deprecated( + 'Use hitTestInView and specify the view to hit test. ' + 'This feature was deprecated after v3.11.0-20.0.pre.', + ) + void hitTest(HitTestResult result, Offset position); + + /// Fills the provided [HitTestResult] with [HitTestEntry]s for objects that + /// are hit at the given `position` in the view identified by `viewId`. + void hitTestInView(HitTestResult result, Offset position, int viewId); +} + +/// An object that can dispatch events. +abstract interface class HitTestDispatcher { + /// Override this method to dispatch events. + void dispatchEvent(PointerEvent event, HitTestResult result); +} + +/// An object that can handle events. +abstract interface class HitTestTarget { + /// Override this method to receive events. + void handleEvent(PointerEvent event, HitTestEntry entry); +} + +/// Data collected during a hit test about a specific [HitTestTarget]. +/// +/// Subclass this object to pass additional information from the hit test phase +/// to the event propagation phase. +@optionalTypeArgs +class HitTestEntry { + /// Creates a hit test entry. + HitTestEntry(this.target); + + /// The [HitTestTarget] encountered during the hit test. + final T target; + + @override + String toString() => '${describeIdentity(this)}($target)'; + + /// Returns a matrix describing how [PointerEvent]s delivered to this + /// [HitTestEntry] should be transformed from the global coordinate space of + /// the screen to the local coordinate space of [target]. + /// + /// See also: + /// + /// * [BoxHitTestResult.addWithPaintTransform], which is used during hit testing + /// to build up this transform. + Matrix4? get transform => _transform; + Matrix4? _transform; +} + +// A type of data that can be applied to a matrix by left-multiplication. +@immutable +abstract class _TransformPart { + const _TransformPart(); + + // Apply this transform part to `rhs` from the left. + // + // This should work as if this transform part is first converted to a matrix + // and then left-multiplied to `rhs`. + // + // For example, if this transform part is a vector `v1`, whose corresponding + // matrix is `m1 = Matrix4.translation(v1)`, then the result of + // `_VectorTransformPart(v1).multiply(rhs)` should equal to `m1 * rhs`. + Matrix4 multiply(Matrix4 rhs); +} + +class _MatrixTransformPart extends _TransformPart { + const _MatrixTransformPart(this.matrix); + + final Matrix4 matrix; + + @override + Matrix4 multiply(Matrix4 rhs) { + return matrix.multiplied(rhs); + } +} + +class _OffsetTransformPart extends _TransformPart { + const _OffsetTransformPart(this.offset); + + final Offset offset; + + @override + Matrix4 multiply(Matrix4 rhs) { + return rhs.clone()..leftTranslate(offset.dx, offset.dy); + } +} + +/// The result of performing a hit test. +class HitTestResult { + /// Creates an empty hit test result. + HitTestResult() + : _path = [], + _transforms = [Matrix4.identity()], + _localTransforms = <_TransformPart>[]; + + /// Wraps `result` (usually a subtype of [HitTestResult]) to create a + /// generic [HitTestResult]. + /// + /// The [HitTestEntry]s added to the returned [HitTestResult] are also + /// added to the wrapped `result` (both share the same underlying data + /// structure to store [HitTestEntry]s). + HitTestResult.wrap(HitTestResult result) + : _path = result._path, + _transforms = result._transforms, + _localTransforms = result._localTransforms; + + /// An unmodifiable list of [HitTestEntry] objects recorded during the hit test. + /// + /// The first entry in the path is the most specific, typically the one at + /// the leaf of tree being hit tested. Event propagation starts with the most + /// specific (i.e., first) entry and proceeds in order through the path. + Iterable get path => _path; + final List _path; + + // A stack of transform parts. + // + // The transform part stack leading from global to the current object is stored + // in 2 parts: + // + // * `_transforms` are globalized matrices, meaning they have been multiplied + // by the ancestors and are thus relative to the global coordinate space. + // * `_localTransforms` are local transform parts, which are relative to the + // parent's coordinate space. + // + // When new transform parts are added they're appended to `_localTransforms`, + // and are converted to global ones and moved to `_transforms` only when used. + final List _transforms; + final List<_TransformPart> _localTransforms; + + // Globalize all transform parts in `_localTransforms` and move them to + // _transforms. + void _globalizeTransforms() { + if (_localTransforms.isEmpty) { + return; + } + Matrix4 last = _transforms.last; + for (final _TransformPart part in _localTransforms) { + last = part.multiply(last); + _transforms.add(last); + } + _localTransforms.clear(); + } + + Matrix4 get _lastTransform { + _globalizeTransforms(); + assert(_localTransforms.isEmpty); + return _transforms.last; + } + + /// Add a [HitTestEntry] to the path. + /// + /// The new entry is added at the end of the path, which means entries should + /// be added in order from most specific to least specific, typically during an + /// upward walk of the tree being hit tested. + void add(HitTestEntry entry) { + assert(entry._transform == null); + entry._transform = _lastTransform; + _path.add(entry); + } + + /// Pushes a new transform matrix that is to be applied to all future + /// [HitTestEntry]s added via [add] until it is removed via [popTransform]. + /// + /// This method is only to be used by subclasses, which must provide + /// coordinate space specific public wrappers around this function for their + /// users (see [BoxHitTestResult.addWithPaintTransform] for such an example). + /// + /// The provided `transform` matrix should describe how to transform + /// [PointerEvent]s from the coordinate space of the method caller to the + /// coordinate space of its children. In most cases `transform` is derived + /// from running the inverted result of [RenderObject.applyPaintTransform] + /// through [PointerEvent.removePerspectiveTransform] to remove + /// the perspective component. + /// + /// If the provided `transform` is a translation matrix, it is much faster + /// to use [pushOffset] with the translation offset instead. + /// + /// [HitTestable]s need to call this method indirectly through a convenience + /// method defined on a subclass before hit testing a child that does not + /// have the same origin as the parent. After hit testing the child, + /// [popTransform] has to be called to remove the child-specific `transform`. + /// + /// See also: + /// + /// * [pushOffset], which is similar to [pushTransform] but is limited to + /// translations, and is faster in such cases. + /// * [BoxHitTestResult.addWithPaintTransform], which is a public wrapper + /// around this function for hit testing on [RenderBox]s. + @protected + void pushTransform(Matrix4 transform) { + assert( + _debugVectorMoreOrLessEquals(transform.getRow(2), Vector4(0, 0, 1, 0)) && + _debugVectorMoreOrLessEquals(transform.getColumn(2), Vector4(0, 0, 1, 0)), + 'The third row and third column of a transform matrix for pointer ' + 'events must be Vector4(0, 0, 1, 0) to ensure that a transformed ' + 'point is directly under the pointing device. Did you forget to run the paint ' + 'matrix through PointerEvent.removePerspectiveTransform? ' + 'The provided matrix is:\n$transform', + ); + _localTransforms.add(_MatrixTransformPart(transform)); + } + + /// Pushes a new translation offset that is to be applied to all future + /// [HitTestEntry]s added via [add] until it is removed via [popTransform]. + /// + /// This method is only to be used by subclasses, which must provide + /// coordinate space specific public wrappers around this function for their + /// users (see [BoxHitTestResult.addWithPaintOffset] for such an example). + /// + /// The provided `offset` should describe how to transform [PointerEvent]s from + /// the coordinate space of the method caller to the coordinate space of its + /// children. Usually `offset` is the inverse of the offset of the child + /// relative to the parent. + /// + /// [HitTestable]s need to call this method indirectly through a convenience + /// method defined on a subclass before hit testing a child that does not + /// have the same origin as the parent. After hit testing the child, + /// [popTransform] has to be called to remove the child-specific `transform`. + /// + /// See also: + /// + /// * [pushTransform], which is similar to [pushOffset] but allows general + /// transform besides translation. + /// * [BoxHitTestResult.addWithPaintOffset], which is a public wrapper + /// around this function for hit testing on [RenderBox]s. + /// * [SliverHitTestResult.addWithAxisOffset], which is a public wrapper + /// around this function for hit testing on [RenderSliver]s. + @protected + void pushOffset(Offset offset) { + _localTransforms.add(_OffsetTransformPart(offset)); + } + + /// Removes the last transform added via [pushTransform] or [pushOffset]. + /// + /// This method is only to be used by subclasses, which must provide + /// coordinate space specific public wrappers around this function for their + /// users (see [BoxHitTestResult.addWithPaintTransform] for such an example). + /// + /// This method must be called after hit testing is done on a child that + /// required a call to [pushTransform] or [pushOffset]. + /// + /// See also: + /// + /// * [pushTransform] and [pushOffset], which describes the use case of this + /// function pair in more details. + @protected + void popTransform() { + if (_localTransforms.isNotEmpty) { + _localTransforms.removeLast(); + } else { + _transforms.removeLast(); + } + assert(_transforms.isNotEmpty); + } + + bool _debugVectorMoreOrLessEquals(Vector4 a, Vector4 b, { double epsilon = precisionErrorTolerance }) { + bool result = true; + assert(() { + final Vector4 difference = a - b; + result = difference.storage.every((double component) => component.abs() < epsilon); + return true; + }()); + return result; + } + + @override + String toString() => 'HitTestResult(${_path.isEmpty ? "" : _path.join(", ")})'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/long_press.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/long_press.dart new file mode 100644 index 0000000000000000000000000000000000000000..f5fef32b429471b13f4191af9914fc1168238150 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/long_press.dart @@ -0,0 +1,828 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'constants.dart'; +import 'events.dart'; +import 'recognizer.dart'; +import 'velocity_tracker.dart'; + +export 'dart:ui' show Offset, PointerDeviceKind; + +export 'arena.dart' show GestureDisposition; +export 'events.dart' show PointerDownEvent, PointerEvent; +export 'velocity_tracker.dart' show Velocity; + +/// Callback signature for [LongPressGestureRecognizer.onLongPressDown]. +/// +/// Called when a pointer that might cause a long-press has contacted the +/// screen. The position at which the pointer contacted the screen is available +/// in the `details`. +/// +/// See also: +/// +/// * [GestureDetector.onLongPressDown], which matches this signature. +/// * [GestureLongPressStartCallback], the signature that gets called when the +/// pointer has been in contact with the screen long enough to be considered +/// a long-press. +typedef GestureLongPressDownCallback = void Function(LongPressDownDetails details); + +/// Callback signature for [LongPressGestureRecognizer.onLongPressCancel]. +/// +/// Called when the pointer that previously triggered a +/// [GestureLongPressDownCallback] will not end up causing a long-press. +/// +/// See also: +/// +/// * [GestureDetector.onLongPressCancel], which matches this signature. +typedef GestureLongPressCancelCallback = void Function(); + +/// Callback signature for [LongPressGestureRecognizer.onLongPress]. +/// +/// Called when a pointer has remained in contact with the screen at the +/// same location for a long period of time. +/// +/// See also: +/// +/// * [GestureDetector.onLongPress], which matches this signature. +/// * [GestureLongPressStartCallback], which is the same signature but with +/// details of where the long press occurred. +typedef GestureLongPressCallback = void Function(); + +/// Callback signature for [LongPressGestureRecognizer.onLongPressUp]. +/// +/// Called when a pointer stops contacting the screen after a long press +/// gesture was detected. +/// +/// See also: +/// +/// * [GestureDetector.onLongPressUp], which matches this signature. +typedef GestureLongPressUpCallback = void Function(); + +/// Callback signature for [LongPressGestureRecognizer.onLongPressStart]. +/// +/// Called when a pointer has remained in contact with the screen at the +/// same location for a long period of time. Also reports the long press down +/// position. +/// +/// See also: +/// +/// * [GestureDetector.onLongPressStart], which matches this signature. +/// * [GestureLongPressCallback], which is the same signature without the +/// details. +typedef GestureLongPressStartCallback = void Function(LongPressStartDetails details); + +/// Callback signature for [LongPressGestureRecognizer.onLongPressMoveUpdate]. +/// +/// Called when a pointer is moving after being held in contact at the same +/// location for a long period of time. Reports the new position and its offset +/// from the original down position. +/// +/// See also: +/// +/// * [GestureDetector.onLongPressMoveUpdate], which matches this signature. +typedef GestureLongPressMoveUpdateCallback = void Function(LongPressMoveUpdateDetails details); + +/// Callback signature for [LongPressGestureRecognizer.onLongPressEnd]. +/// +/// Called when a pointer stops contacting the screen after a long press +/// gesture was detected. Also reports the position where the pointer stopped +/// contacting the screen. +/// +/// See also: +/// +/// * [GestureDetector.onLongPressEnd], which matches this signature. +typedef GestureLongPressEndCallback = void Function(LongPressEndDetails details); + +/// Details for callbacks that use [GestureLongPressDownCallback]. +/// +/// See also: +/// +/// * [LongPressGestureRecognizer.onLongPressDown], whose callback passes +/// these details. +/// * [LongPressGestureRecognizer.onSecondaryLongPressDown], whose callback +/// passes these details. +/// * [LongPressGestureRecognizer.onTertiaryLongPressDown], whose callback +/// passes these details. +class LongPressDownDetails { + /// Creates the details for a [GestureLongPressDownCallback]. + /// + /// If the `localPosition` argument is not specified, it will default to the + /// global position. + const LongPressDownDetails({ + this.globalPosition = Offset.zero, + Offset? localPosition, + this.kind, + }) : localPosition = localPosition ?? globalPosition; + + /// The global position at which the pointer contacted the screen. + final Offset globalPosition; + + /// The kind of the device that initiated the event. + final PointerDeviceKind? kind; + + /// The local position at which the pointer contacted the screen. + final Offset localPosition; +} + +/// Details for callbacks that use [GestureLongPressStartCallback]. +/// +/// See also: +/// +/// * [LongPressGestureRecognizer.onLongPressStart], which uses [GestureLongPressStartCallback]. +/// * [LongPressMoveUpdateDetails], the details for [GestureLongPressMoveUpdateCallback] +/// * [LongPressEndDetails], the details for [GestureLongPressEndCallback]. +class LongPressStartDetails { + /// Creates the details for a [GestureLongPressStartCallback]. + const LongPressStartDetails({ + this.globalPosition = Offset.zero, + Offset? localPosition, + }) : localPosition = localPosition ?? globalPosition; + + /// The global position at which the pointer initially contacted the screen. + final Offset globalPosition; + + /// The local position at which the pointer initially contacted the screen. + final Offset localPosition; +} + +/// Details for callbacks that use [GestureLongPressMoveUpdateCallback]. +/// +/// See also: +/// +/// * [LongPressGestureRecognizer.onLongPressMoveUpdate], which uses [GestureLongPressMoveUpdateCallback]. +/// * [LongPressEndDetails], the details for [GestureLongPressEndCallback] +/// * [LongPressStartDetails], the details for [GestureLongPressStartCallback]. +class LongPressMoveUpdateDetails { + /// Creates the details for a [GestureLongPressMoveUpdateCallback]. + const LongPressMoveUpdateDetails({ + this.globalPosition = Offset.zero, + Offset? localPosition, + this.offsetFromOrigin = Offset.zero, + Offset? localOffsetFromOrigin, + }) : localPosition = localPosition ?? globalPosition, + localOffsetFromOrigin = localOffsetFromOrigin ?? offsetFromOrigin; + + /// The global position of the pointer when it triggered this update. + final Offset globalPosition; + + /// The local position of the pointer when it triggered this update. + final Offset localPosition; + + /// A delta offset from the point where the long press drag initially contacted + /// the screen to the point where the pointer is currently located (the + /// present [globalPosition]) when this callback is triggered. + final Offset offsetFromOrigin; + + /// A local delta offset from the point where the long press drag initially contacted + /// the screen to the point where the pointer is currently located (the + /// present [localPosition]) when this callback is triggered. + final Offset localOffsetFromOrigin; +} + +/// Details for callbacks that use [GestureLongPressEndCallback]. +/// +/// See also: +/// +/// * [LongPressGestureRecognizer.onLongPressEnd], which uses [GestureLongPressEndCallback]. +/// * [LongPressMoveUpdateDetails], the details for [GestureLongPressMoveUpdateCallback]. +/// * [LongPressStartDetails], the details for [GestureLongPressStartCallback]. +class LongPressEndDetails { + /// Creates the details for a [GestureLongPressEndCallback]. + const LongPressEndDetails({ + this.globalPosition = Offset.zero, + Offset? localPosition, + this.velocity = Velocity.zero, + }) : localPosition = localPosition ?? globalPosition; + + /// The global position at which the pointer lifted from the screen. + final Offset globalPosition; + + /// The local position at which the pointer contacted the screen. + final Offset localPosition; + + /// The pointer's velocity when it stopped contacting the screen. + /// + /// Defaults to zero if not specified in the constructor. + final Velocity velocity; +} + +/// Recognizes when the user has pressed down at the same location for a long +/// period of time. +/// +/// The gesture must not deviate in position from its touch down point for 500ms +/// until it's recognized. Once the gesture is accepted, the finger can be +/// moved, triggering [onLongPressMoveUpdate] callbacks, unless the +/// [postAcceptSlopTolerance] constructor argument is specified. +/// +/// [LongPressGestureRecognizer] may compete on pointer events of +/// [kPrimaryButton], [kSecondaryButton], and/or [kTertiaryButton] if at least +/// one corresponding callback is non-null. If it has no callbacks, it is a no-op. +class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer { + /// Creates a long-press gesture recognizer. + /// + /// Consider assigning the [onLongPressStart] callback after creating this + /// object. + /// + /// The [postAcceptSlopTolerance] argument can be used to specify a maximum + /// allowed distance for the gesture to deviate from the starting point once + /// the long press has triggered. If the gesture deviates past that point, + /// subsequent callbacks ([onLongPressMoveUpdate], [onLongPressUp], + /// [onLongPressEnd]) will stop. Defaults to null, which means the gesture + /// can be moved without limit once the long press is accepted. + /// + /// The [duration] argument can be used to overwrite the default duration + /// after which the long press will be recognized. + /// + /// {@macro flutter.gestures.tap.TapGestureRecognizer.allowedButtonsFilter} + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + LongPressGestureRecognizer({ + Duration? duration, + super.postAcceptSlopTolerance = null, + super.supportedDevices, + super.debugOwner, + AllowedButtonsFilter? allowedButtonsFilter, + }) : super( + deadline: duration ?? kLongPressTimeout, + allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior, + ); + + bool _longPressAccepted = false; + OffsetPair? _longPressOrigin; + // The buttons sent by `PointerDownEvent`. If a `PointerMoveEvent` comes with a + // different set of buttons, the gesture is canceled. + int? _initialButtons; + + // Accept the input if, and only if, a single button is pressed. + static bool _defaultButtonAcceptBehavior(int buttons) => + buttons == kPrimaryButton || + buttons == kSecondaryButton || + buttons == kTertiaryButton; + + /// Called when a pointer has contacted the screen at a particular location + /// with a primary button, which might be the start of a long-press. + /// + /// This triggers after the pointer down event. + /// + /// If this recognizer doesn't win the arena, [onLongPressCancel] is called + /// next. Otherwise, [onLongPressStart] is called next. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [onSecondaryLongPressDown], a similar callback but for a secondary button. + /// * [onTertiaryLongPressDown], a similar callback but for a tertiary button. + /// * [LongPressDownDetails], which is passed as an argument to this callback. + /// * [GestureDetector.onLongPressDown], which exposes this callback in a widget. + GestureLongPressDownCallback? onLongPressDown; + + /// Called when a pointer that previously triggered [onLongPressDown] will + /// not end up causing a long-press. + /// + /// This triggers once the gesture loses the arena if [onLongPressDown] has + /// previously been triggered. + /// + /// If this recognizer wins the arena, [onLongPressStart] and [onLongPress] + /// are called instead. + /// + /// If the gesture is deactivated due to [postAcceptSlopTolerance] having + /// been exceeded, this callback will not be called, since the gesture will + /// have already won the arena at that point. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + GestureLongPressCancelCallback? onLongPressCancel; + + /// Called when a long press gesture by a primary button has been recognized. + /// + /// This is equivalent to (and is called immediately after) [onLongPressStart]. + /// The only difference between the two is that this callback does not + /// contain details of the position at which the pointer initially contacted + /// the screen. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + GestureLongPressCallback? onLongPress; + + /// Called when a long press gesture by a primary button has been recognized. + /// + /// This is equivalent to (and is called immediately before) [onLongPress]. + /// The only difference between the two is that this callback contains + /// details of the position at which the pointer initially contacted the + /// screen, whereas [onLongPress] does not. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [LongPressStartDetails], which is passed as an argument to this callback. + GestureLongPressStartCallback? onLongPressStart; + + /// Called when moving after the long press by a primary button is recognized. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [LongPressMoveUpdateDetails], which is passed as an argument to this + /// callback. + GestureLongPressMoveUpdateCallback? onLongPressMoveUpdate; + + /// Called when the pointer stops contacting the screen after a long-press + /// by a primary button. + /// + /// This is equivalent to (and is called immediately after) [onLongPressEnd]. + /// The only difference between the two is that this callback does not + /// contain details of the state of the pointer when it stopped contacting + /// the screen. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + GestureLongPressUpCallback? onLongPressUp; + + /// Called when the pointer stops contacting the screen after a long-press + /// by a primary button. + /// + /// This is equivalent to (and is called immediately before) [onLongPressUp]. + /// The only difference between the two is that this callback contains + /// details of the state of the pointer when it stopped contacting the + /// screen, whereas [onLongPressUp] does not. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [LongPressEndDetails], which is passed as an argument to this + /// callback. + GestureLongPressEndCallback? onLongPressEnd; + + /// Called when a pointer has contacted the screen at a particular location + /// with a secondary button, which might be the start of a long-press. + /// + /// This triggers after the pointer down event. + /// + /// If this recognizer doesn't win the arena, [onSecondaryLongPressCancel] is + /// called next. Otherwise, [onSecondaryLongPressStart] is called next. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [onLongPressDown], a similar callback but for a primary button. + /// * [onTertiaryLongPressDown], a similar callback but for a tertiary button. + /// * [LongPressDownDetails], which is passed as an argument to this callback. + /// * [GestureDetector.onSecondaryLongPressDown], which exposes this callback + /// in a widget. + GestureLongPressDownCallback? onSecondaryLongPressDown; + + /// Called when a pointer that previously triggered [onSecondaryLongPressDown] + /// will not end up causing a long-press. + /// + /// This triggers once the gesture loses the arena if + /// [onSecondaryLongPressDown] has previously been triggered. + /// + /// If this recognizer wins the arena, [onSecondaryLongPressStart] and + /// [onSecondaryLongPress] are called instead. + /// + /// If the gesture is deactivated due to [postAcceptSlopTolerance] having + /// been exceeded, this callback will not be called, since the gesture will + /// have already won the arena at that point. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + GestureLongPressCancelCallback? onSecondaryLongPressCancel; + + /// Called when a long press gesture by a secondary button has been + /// recognized. + /// + /// This is equivalent to (and is called immediately after) + /// [onSecondaryLongPressStart]. The only difference between the two is that + /// this callback does not contain details of the position at which the + /// pointer initially contacted the screen. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + GestureLongPressCallback? onSecondaryLongPress; + + /// Called when a long press gesture by a secondary button has been recognized. + /// + /// This is equivalent to (and is called immediately before) + /// [onSecondaryLongPress]. The only difference between the two is that this + /// callback contains details of the position at which the pointer initially + /// contacted the screen, whereas [onSecondaryLongPress] does not. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [LongPressStartDetails], which is passed as an argument to this + /// callback. + GestureLongPressStartCallback? onSecondaryLongPressStart; + + /// Called when moving after the long press by a secondary button is + /// recognized. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [LongPressMoveUpdateDetails], which is passed as an argument to this + /// callback. + GestureLongPressMoveUpdateCallback? onSecondaryLongPressMoveUpdate; + + /// Called when the pointer stops contacting the screen after a long-press by + /// a secondary button. + /// + /// This is equivalent to (and is called immediately after) + /// [onSecondaryLongPressEnd]. The only difference between the two is that + /// this callback does not contain details of the state of the pointer when + /// it stopped contacting the screen. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + GestureLongPressUpCallback? onSecondaryLongPressUp; + + /// Called when the pointer stops contacting the screen after a long-press by + /// a secondary button. + /// + /// This is equivalent to (and is called immediately before) + /// [onSecondaryLongPressUp]. The only difference between the two is that + /// this callback contains details of the state of the pointer when it + /// stopped contacting the screen, whereas [onSecondaryLongPressUp] does not. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [LongPressEndDetails], which is passed as an argument to this callback. + GestureLongPressEndCallback? onSecondaryLongPressEnd; + + /// Called when a pointer has contacted the screen at a particular location + /// with a tertiary button, which might be the start of a long-press. + /// + /// This triggers after the pointer down event. + /// + /// If this recognizer doesn't win the arena, [onTertiaryLongPressCancel] is + /// called next. Otherwise, [onTertiaryLongPressStart] is called next. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [onLongPressDown], a similar callback but for a primary button. + /// * [onSecondaryLongPressDown], a similar callback but for a secondary button. + /// * [LongPressDownDetails], which is passed as an argument to this callback. + /// * [GestureDetector.onTertiaryLongPressDown], which exposes this callback + /// in a widget. + GestureLongPressDownCallback? onTertiaryLongPressDown; + + /// Called when a pointer that previously triggered [onTertiaryLongPressDown] + /// will not end up causing a long-press. + /// + /// This triggers once the gesture loses the arena if + /// [onTertiaryLongPressDown] has previously been triggered. + /// + /// If this recognizer wins the arena, [onTertiaryLongPressStart] and + /// [onTertiaryLongPress] are called instead. + /// + /// If the gesture is deactivated due to [postAcceptSlopTolerance] having + /// been exceeded, this callback will not be called, since the gesture will + /// have already won the arena at that point. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + GestureLongPressCancelCallback? onTertiaryLongPressCancel; + + /// Called when a long press gesture by a tertiary button has been + /// recognized. + /// + /// This is equivalent to (and is called immediately after) + /// [onTertiaryLongPressStart]. The only difference between the two is that + /// this callback does not contain details of the position at which the + /// pointer initially contacted the screen. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + GestureLongPressCallback? onTertiaryLongPress; + + /// Called when a long press gesture by a tertiary button has been recognized. + /// + /// This is equivalent to (and is called immediately before) + /// [onTertiaryLongPress]. The only difference between the two is that this + /// callback contains details of the position at which the pointer initially + /// contacted the screen, whereas [onTertiaryLongPress] does not. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [LongPressStartDetails], which is passed as an argument to this + /// callback. + GestureLongPressStartCallback? onTertiaryLongPressStart; + + /// Called when moving after the long press by a tertiary button is + /// recognized. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [LongPressMoveUpdateDetails], which is passed as an argument to this + /// callback. + GestureLongPressMoveUpdateCallback? onTertiaryLongPressMoveUpdate; + + /// Called when the pointer stops contacting the screen after a long-press by + /// a tertiary button. + /// + /// This is equivalent to (and is called immediately after) + /// [onTertiaryLongPressEnd]. The only difference between the two is that + /// this callback does not contain details of the state of the pointer when + /// it stopped contacting the screen. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + GestureLongPressUpCallback? onTertiaryLongPressUp; + + /// Called when the pointer stops contacting the screen after a long-press by + /// a tertiary button. + /// + /// This is equivalent to (and is called immediately before) + /// [onTertiaryLongPressUp]. The only difference between the two is that + /// this callback contains details of the state of the pointer when it + /// stopped contacting the screen, whereas [onTertiaryLongPressUp] does not. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [LongPressEndDetails], which is passed as an argument to this callback. + GestureLongPressEndCallback? onTertiaryLongPressEnd; + + VelocityTracker? _velocityTracker; + + @override + bool isPointerAllowed(PointerDownEvent event) { + switch (event.buttons) { + case kPrimaryButton: + if (onLongPressDown == null && + onLongPressCancel == null && + onLongPressStart == null && + onLongPress == null && + onLongPressMoveUpdate == null && + onLongPressEnd == null && + onLongPressUp == null) { + return false; + } + case kSecondaryButton: + if (onSecondaryLongPressDown == null && + onSecondaryLongPressCancel == null && + onSecondaryLongPressStart == null && + onSecondaryLongPress == null && + onSecondaryLongPressMoveUpdate == null && + onSecondaryLongPressEnd == null && + onSecondaryLongPressUp == null) { + return false; + } + case kTertiaryButton: + if (onTertiaryLongPressDown == null && + onTertiaryLongPressCancel == null && + onTertiaryLongPressStart == null && + onTertiaryLongPress == null && + onTertiaryLongPressMoveUpdate == null && + onTertiaryLongPressEnd == null && + onTertiaryLongPressUp == null) { + return false; + } + default: + return false; + } + return super.isPointerAllowed(event); + } + + @override + void didExceedDeadline() { + // Exceeding the deadline puts the gesture in the accepted state. + resolve(GestureDisposition.accepted); + _longPressAccepted = true; + super.acceptGesture(primaryPointer!); + _checkLongPressStart(); + } + + @override + void handlePrimaryPointer(PointerEvent event) { + if (!event.synthesized) { + if (event is PointerDownEvent) { + _velocityTracker = VelocityTracker.withKind(event.kind); + _velocityTracker!.addPosition(event.timeStamp, event.localPosition); + } + if (event is PointerMoveEvent) { + assert(_velocityTracker != null); + _velocityTracker!.addPosition(event.timeStamp, event.localPosition); + } + } + + if (event is PointerUpEvent) { + if (_longPressAccepted) { + _checkLongPressEnd(event); + } else { + // Pointer is lifted before timeout. + resolve(GestureDisposition.rejected); + } + _reset(); + } else if (event is PointerCancelEvent) { + _checkLongPressCancel(); + _reset(); + } else if (event is PointerDownEvent) { + // The first touch. + _longPressOrigin = OffsetPair.fromEventPosition(event); + _initialButtons = event.buttons; + _checkLongPressDown(event); + } else if (event is PointerMoveEvent) { + if (event.buttons != _initialButtons && !_longPressAccepted) { + resolve(GestureDisposition.rejected); + stopTrackingPointer(primaryPointer!); + } else if (_longPressAccepted) { + _checkLongPressMoveUpdate(event); + } + } + } + + void _checkLongPressDown(PointerDownEvent event) { + assert(_longPressOrigin != null); + final LongPressDownDetails details = LongPressDownDetails( + globalPosition: _longPressOrigin!.global, + localPosition: _longPressOrigin!.local, + kind: getKindForPointer(event.pointer), + ); + switch (_initialButtons) { + case kPrimaryButton: + if (onLongPressDown != null) { + invokeCallback('onLongPressDown', () => onLongPressDown!(details)); + } + case kSecondaryButton: + if (onSecondaryLongPressDown != null) { + invokeCallback('onSecondaryLongPressDown', () => onSecondaryLongPressDown!(details)); + } + case kTertiaryButton: + if (onTertiaryLongPressDown != null) { + invokeCallback('onTertiaryLongPressDown', () => onTertiaryLongPressDown!(details)); + } + default: + assert(false, 'Unhandled button $_initialButtons'); + } + } + + void _checkLongPressCancel() { + if (state == GestureRecognizerState.possible) { + switch (_initialButtons) { + case kPrimaryButton: + if (onLongPressCancel != null) { + invokeCallback('onLongPressCancel', onLongPressCancel!); + } + case kSecondaryButton: + if (onSecondaryLongPressCancel != null) { + invokeCallback('onSecondaryLongPressCancel', onSecondaryLongPressCancel!); + } + case kTertiaryButton: + if (onTertiaryLongPressCancel != null) { + invokeCallback('onTertiaryLongPressCancel', onTertiaryLongPressCancel!); + } + default: + assert(false, 'Unhandled button $_initialButtons'); + } + } + } + + void _checkLongPressStart() { + switch (_initialButtons) { + case kPrimaryButton: + if (onLongPressStart != null) { + final LongPressStartDetails details = LongPressStartDetails( + globalPosition: _longPressOrigin!.global, + localPosition: _longPressOrigin!.local, + ); + invokeCallback('onLongPressStart', () => onLongPressStart!(details)); + } + if (onLongPress != null) { + invokeCallback('onLongPress', onLongPress!); + } + case kSecondaryButton: + if (onSecondaryLongPressStart != null) { + final LongPressStartDetails details = LongPressStartDetails( + globalPosition: _longPressOrigin!.global, + localPosition: _longPressOrigin!.local, + ); + invokeCallback('onSecondaryLongPressStart', () => onSecondaryLongPressStart!(details)); + } + if (onSecondaryLongPress != null) { + invokeCallback('onSecondaryLongPress', onSecondaryLongPress!); + } + case kTertiaryButton: + if (onTertiaryLongPressStart != null) { + final LongPressStartDetails details = LongPressStartDetails( + globalPosition: _longPressOrigin!.global, + localPosition: _longPressOrigin!.local, + ); + invokeCallback('onTertiaryLongPressStart', () => onTertiaryLongPressStart!(details)); + } + if (onTertiaryLongPress != null) { + invokeCallback('onTertiaryLongPress', onTertiaryLongPress!); + } + default: + assert(false, 'Unhandled button $_initialButtons'); + } + } + + void _checkLongPressMoveUpdate(PointerEvent event) { + final LongPressMoveUpdateDetails details = LongPressMoveUpdateDetails( + globalPosition: event.position, + localPosition: event.localPosition, + offsetFromOrigin: event.position - _longPressOrigin!.global, + localOffsetFromOrigin: event.localPosition - _longPressOrigin!.local, + ); + switch (_initialButtons) { + case kPrimaryButton: + if (onLongPressMoveUpdate != null) { + invokeCallback('onLongPressMoveUpdate', () => onLongPressMoveUpdate!(details)); + } + case kSecondaryButton: + if (onSecondaryLongPressMoveUpdate != null) { + invokeCallback('onSecondaryLongPressMoveUpdate', () => onSecondaryLongPressMoveUpdate!(details)); + } + case kTertiaryButton: + if (onTertiaryLongPressMoveUpdate != null) { + invokeCallback('onTertiaryLongPressMoveUpdate', () => onTertiaryLongPressMoveUpdate!(details)); + } + default: + assert(false, 'Unhandled button $_initialButtons'); + } + } + + void _checkLongPressEnd(PointerEvent event) { + final VelocityEstimate? estimate = _velocityTracker!.getVelocityEstimate(); + final Velocity velocity = estimate == null + ? Velocity.zero + : Velocity(pixelsPerSecond: estimate.pixelsPerSecond); + final LongPressEndDetails details = LongPressEndDetails( + globalPosition: event.position, + localPosition: event.localPosition, + velocity: velocity, + ); + + _velocityTracker = null; + switch (_initialButtons) { + case kPrimaryButton: + if (onLongPressEnd != null) { + invokeCallback('onLongPressEnd', () => onLongPressEnd!(details)); + } + if (onLongPressUp != null) { + invokeCallback('onLongPressUp', onLongPressUp!); + } + case kSecondaryButton: + if (onSecondaryLongPressEnd != null) { + invokeCallback('onSecondaryLongPressEnd', () => onSecondaryLongPressEnd!(details)); + } + if (onSecondaryLongPressUp != null) { + invokeCallback('onSecondaryLongPressUp', onSecondaryLongPressUp!); + } + case kTertiaryButton: + if (onTertiaryLongPressEnd != null) { + invokeCallback('onTertiaryLongPressEnd', () => onTertiaryLongPressEnd!(details)); + } + if (onTertiaryLongPressUp != null) { + invokeCallback('onTertiaryLongPressUp', onTertiaryLongPressUp!); + } + default: + assert(false, 'Unhandled button $_initialButtons'); + } + } + + void _reset() { + _longPressAccepted = false; + _longPressOrigin = null; + _initialButtons = null; + _velocityTracker = null; + } + + @override + void resolve(GestureDisposition disposition) { + if (disposition == GestureDisposition.rejected) { + if (_longPressAccepted) { + // This can happen if the gesture has been canceled. For example when + // the buttons have changed. + _reset(); + } else { + _checkLongPressCancel(); + } + } + super.resolve(disposition); + } + + @override + void acceptGesture(int pointer) { + // Winning the arena isn't important here since it may happen from a sweep. + // Explicitly exceeding the deadline puts the gesture in accepted state. + } + + @override + String get debugDescription => 'long press'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/lsq_solver.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/lsq_solver.dart new file mode 100644 index 0000000000000000000000000000000000000000..edd2548e9d81362a780eb872e641ccdc05642555 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/lsq_solver.dart @@ -0,0 +1,212 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +// TODO(abarth): Consider using vector_math. +class _Vector { + _Vector(int size) + : _offset = 0, + _length = size, + _elements = Float64List(size); + + _Vector.fromVOL(List values, int offset, int length) + : _offset = offset, + _length = length, + _elements = values; + + final int _offset; + + final int _length; + + final List _elements; + + double operator [](int i) => _elements[i + _offset]; + void operator []=(int i, double value) { + _elements[i + _offset] = value; + } + + double operator *(_Vector a) { + double result = 0.0; + for (int i = 0; i < _length; i += 1) { + result += this[i] * a[i]; + } + return result; + } + + double norm() => math.sqrt(this * this); +} + +// TODO(abarth): Consider using vector_math. +class _Matrix { + _Matrix(int rows, int cols) + : _columns = cols, + _elements = Float64List(rows * cols); + + final int _columns; + final List _elements; + + double get(int row, int col) => _elements[row * _columns + col]; + void set(int row, int col, double value) { + _elements[row * _columns + col] = value; + } + + _Vector getRow(int row) => _Vector.fromVOL( + _elements, + row * _columns, + _columns, + ); +} + +/// An nth degree polynomial fit to a dataset. +class PolynomialFit { + /// Creates a polynomial fit of the given degree. + /// + /// There are n + 1 coefficients in a fit of degree n. + PolynomialFit(int degree) : coefficients = Float64List(degree + 1); + + /// The polynomial coefficients of the fit. + /// + /// For each `i`, the element `coefficients[i]` is the coefficient of + /// the `i`-th power of the variable. + final List coefficients; + + /// An indicator of the quality of the fit. + /// + /// Larger values indicate greater quality. The value ranges from 0.0 to 1.0. + /// + /// The confidence is defined as the fraction of the dataset's variance + /// that is captured by variance in the fit polynomial. In statistics + /// textbooks this is often called "r-squared". + late double confidence; + + @override + String toString() { + final String coefficientString = + coefficients.map((double c) => c.toStringAsPrecision(3)).toList().toString(); + return '${objectRuntimeType(this, 'PolynomialFit')}($coefficientString, confidence: ${confidence.toStringAsFixed(3)})'; + } +} + +/// Uses the least-squares algorithm to fit a polynomial to a set of data. +class LeastSquaresSolver { + /// Creates a least-squares solver. + LeastSquaresSolver(this.x, this.y, this.w) + : assert(x.length == y.length), + assert(y.length == w.length); + + /// The x-coordinates of each data point. + final List x; + + /// The y-coordinates of each data point. + final List y; + + /// The weight to use for each data point. + final List w; + + /// Fits a polynomial of the given degree to the data points. + /// + /// When there is not enough data to fit a curve null is returned. + PolynomialFit? solve(int degree) { + if (degree > x.length) { + // Not enough data to fit a curve. + return null; + } + + final PolynomialFit result = PolynomialFit(degree); + + // Shorthands for the purpose of notation equivalence to original C++ code. + final int m = x.length; + final int n = degree + 1; + + // Expand the X vector to a matrix A, pre-multiplied by the weights. + final _Matrix a = _Matrix(n, m); + for (int h = 0; h < m; h += 1) { + a.set(0, h, w[h]); + for (int i = 1; i < n; i += 1) { + a.set(i, h, a.get(i - 1, h) * x[h]); + } + } + + // Apply the Gram-Schmidt process to A to obtain its QR decomposition. + + // Orthonormal basis, column-major ordVectorer. + final _Matrix q = _Matrix(n, m); + // Upper triangular matrix, row-major order. + final _Matrix r = _Matrix(n, n); + for (int j = 0; j < n; j += 1) { + for (int h = 0; h < m; h += 1) { + q.set(j, h, a.get(j, h)); + } + for (int i = 0; i < j; i += 1) { + final double dot = q.getRow(j) * q.getRow(i); + for (int h = 0; h < m; h += 1) { + q.set(j, h, q.get(j, h) - dot * q.get(i, h)); + } + } + + final double norm = q.getRow(j).norm(); + if (norm < precisionErrorTolerance) { + // Vectors are linearly dependent or zero so no solution. + return null; + } + + final double inverseNorm = 1.0 / norm; + for (int h = 0; h < m; h += 1) { + q.set(j, h, q.get(j, h) * inverseNorm); + } + for (int i = 0; i < n; i += 1) { + r.set(j, i, i < j ? 0.0 : q.getRow(j) * a.getRow(i)); + } + } + + // Solve R B = Qt W Y to find B. This is easy because R is upper triangular. + // We just work from bottom-right to top-left calculating B's coefficients. + final _Vector wy = _Vector(m); + for (int h = 0; h < m; h += 1) { + wy[h] = y[h] * w[h]; + } + for (int i = n - 1; i >= 0; i -= 1) { + result.coefficients[i] = q.getRow(i) * wy; + for (int j = n - 1; j > i; j -= 1) { + result.coefficients[i] -= r.get(i, j) * result.coefficients[j]; + } + result.coefficients[i] /= r.get(i, i); + } + + // Calculate the coefficient of determination (confidence) as: + // 1 - (sumSquaredError / sumSquaredTotal) + // ...where sumSquaredError is the residual sum of squares (variance of the + // error), and sumSquaredTotal is the total sum of squares (variance of the + // data) where each has been weighted. + double yMean = 0.0; + for (int h = 0; h < m; h += 1) { + yMean += y[h]; + } + yMean /= m; + + double sumSquaredError = 0.0; + double sumSquaredTotal = 0.0; + for (int h = 0; h < m; h += 1) { + double term = 1.0; + double err = y[h] - result.coefficients[0]; + for (int i = 1; i < n; i += 1) { + term *= x[h]; + err -= term * result.coefficients[i]; + } + sumSquaredError += w[h] * w[h] * err * err; + final double v = y[h] - yMean; + sumSquaredTotal += w[h] * w[h] * v * v; + } + + result.confidence = sumSquaredTotal <= precisionErrorTolerance ? 1.0 : + 1.0 - (sumSquaredError / sumSquaredTotal); + + return result; + } + +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/monodrag.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/monodrag.dart new file mode 100644 index 0000000000000000000000000000000000000000..df98a4be1ff95e0b907325709b082116852756de --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/monodrag.dart @@ -0,0 +1,784 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'constants.dart'; +import 'drag_details.dart'; +import 'events.dart'; +import 'recognizer.dart'; +import 'velocity_tracker.dart'; + +export 'dart:ui' show PointerDeviceKind; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; + +export 'drag.dart' show DragEndDetails, DragUpdateDetails; +export 'drag_details.dart' show DragDownDetails, DragStartDetails, DragUpdateDetails, GestureDragDownCallback, GestureDragStartCallback, GestureDragUpdateCallback; +export 'events.dart' show PointerDownEvent, PointerEvent, PointerPanZoomStartEvent; +export 'recognizer.dart' show DragStartBehavior; +export 'velocity_tracker.dart' show VelocityEstimate, VelocityTracker; + +enum _DragState { + ready, + possible, + accepted, +} + +/// {@template flutter.gestures.monodrag.GestureDragEndCallback} +/// Signature for when a pointer that was previously in contact with the screen +/// and moving is no longer in contact with the screen. +/// +/// The velocity at which the pointer was moving when it stopped contacting +/// the screen is available in the `details`. +/// {@endtemplate} +/// +/// Used by [DragGestureRecognizer.onEnd]. +typedef GestureDragEndCallback = void Function(DragEndDetails details); + +/// Signature for when the pointer that previously triggered a +/// [GestureDragDownCallback] did not complete. +/// +/// Used by [DragGestureRecognizer.onCancel]. +typedef GestureDragCancelCallback = void Function(); + +/// Signature for a function that builds a [VelocityTracker]. +/// +/// Used by [DragGestureRecognizer.velocityTrackerBuilder]. +typedef GestureVelocityTrackerBuilder = VelocityTracker Function(PointerEvent event); + +/// Recognizes movement. +/// +/// In contrast to [MultiDragGestureRecognizer], [DragGestureRecognizer] +/// recognizes a single gesture sequence for all the pointers it watches, which +/// means that the recognizer has at most one drag sequence active at any given +/// time regardless of how many pointers are in contact with the screen. +/// +/// [DragGestureRecognizer] is not intended to be used directly. Instead, +/// consider using one of its subclasses to recognize specific types for drag +/// gestures. +/// +/// [DragGestureRecognizer] competes on pointer events only when it has at +/// least one non-null callback. If it has no callbacks, it is a no-op. +/// +/// See also: +/// +/// * [HorizontalDragGestureRecognizer], for left and right drags. +/// * [VerticalDragGestureRecognizer], for up and down drags. +/// * [PanGestureRecognizer], for drags that are not locked to a single axis. +abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { + /// Initialize the object. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + DragGestureRecognizer({ + super.debugOwner, + this.dragStartBehavior = DragStartBehavior.start, + this.multitouchDragStrategy = MultitouchDragStrategy.latestPointer, + this.velocityTrackerBuilder = _defaultBuilder, + this.onlyAcceptDragOnThreshold = false, + super.supportedDevices, + AllowedButtonsFilter? allowedButtonsFilter, + }) : super(allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior); + + static VelocityTracker _defaultBuilder(PointerEvent event) => VelocityTracker.withKind(event.kind); + + // Accept the input if, and only if, [kPrimaryButton] is pressed. + static bool _defaultButtonAcceptBehavior(int buttons) => buttons == kPrimaryButton; + + /// Configure the behavior of offsets passed to [onStart]. + /// + /// If set to [DragStartBehavior.start], the [onStart] callback will be called + /// with the position of the pointer at the time this gesture recognizer won + /// the arena. If [DragStartBehavior.down], [onStart] will be called with + /// the position of the first detected down event for the pointer. When there + /// are no other gestures competing with this gesture in the arena, there's + /// no difference in behavior between the two settings. + /// + /// For more information about the gesture arena: + /// https://flutter.dev/docs/development/ui/advanced/gestures#gesture-disambiguation + /// + /// By default, the drag start behavior is [DragStartBehavior.start]. + /// + /// ## Example: + /// + /// A [HorizontalDragGestureRecognizer] and a [VerticalDragGestureRecognizer] + /// compete with each other. A finger presses down on the screen with + /// offset (500.0, 500.0), and then moves to position (510.0, 500.0) before + /// the [HorizontalDragGestureRecognizer] wins the arena. With + /// [dragStartBehavior] set to [DragStartBehavior.down], the [onStart] + /// callback will be called with position (500.0, 500.0). If it is + /// instead set to [DragStartBehavior.start], [onStart] will be called with + /// position (510.0, 500.0). + DragStartBehavior dragStartBehavior; + + /// {@template flutter.gestures.monodrag.DragGestureRecognizer.multitouchDragStrategy} + /// Configure the multi-finger drag strategy on multi-touch devices. + /// + /// If set to [MultitouchDragStrategy.latestPointer], the drag gesture recognizer + /// will only track the latest active (accepted by this recognizer) pointer, which + /// appears to be only one finger dragging. + /// + /// If set to [MultitouchDragStrategy.sumAllPointers], + /// all active pointers will be tracked together and the scrolling offset + /// is the sum of the offsets of all active pointers + /// {@endtemplate} + /// + /// By default, the strategy is [MultitouchDragStrategy.latestPointer]. + /// + /// See also: + /// + /// * [MultitouchDragStrategy], which defines two different drag strategies for + /// multi-finger drag. + MultitouchDragStrategy multitouchDragStrategy; + + /// A pointer has contacted the screen with a primary button and might begin + /// to move. + /// + /// The position of the pointer is provided in the callback's `details` + /// argument, which is a [DragDownDetails] object. + /// + /// See also: + /// + /// * [allowedButtonsFilter], which decides which button will be allowed. + /// * [DragDownDetails], which is passed as an argument to this callback. + GestureDragDownCallback? onDown; + + /// {@template flutter.gestures.monodrag.DragGestureRecognizer.onStart} + /// A pointer has contacted the screen with a primary button and has begun to + /// move. + /// {@endtemplate} + /// + /// The position of the pointer is provided in the callback's `details` + /// argument, which is a [DragStartDetails] object. The [dragStartBehavior] + /// determines this position. + /// + /// See also: + /// + /// * [allowedButtonsFilter], which decides which button will be allowed. + /// * [DragStartDetails], which is passed as an argument to this callback. + GestureDragStartCallback? onStart; + + /// {@template flutter.gestures.monodrag.DragGestureRecognizer.onUpdate} + /// A pointer that is in contact with the screen with a primary button and + /// moving has moved again. + /// {@endtemplate} + /// + /// The distance traveled by the pointer since the last update is provided in + /// the callback's `details` argument, which is a [DragUpdateDetails] object. + /// + /// If this gesture recognizer recognizes movement on a single axis (a + /// [VerticalDragGestureRecognizer] or [HorizontalDragGestureRecognizer]), + /// then `details` will reflect movement only on that axis and its + /// [DragUpdateDetails.primaryDelta] will be non-null. + /// If this gesture recognizer recognizes movement in all directions + /// (a [PanGestureRecognizer]), then `details` will reflect movement on + /// both axes and its [DragUpdateDetails.primaryDelta] will be null. + /// + /// See also: + /// + /// * [allowedButtonsFilter], which decides which button will be allowed. + /// * [DragUpdateDetails], which is passed as an argument to this callback. + GestureDragUpdateCallback? onUpdate; + + /// {@template flutter.gestures.monodrag.DragGestureRecognizer.onEnd} + /// A pointer that was previously in contact with the screen with a primary + /// button and moving is no longer in contact with the screen and was moving + /// at a specific velocity when it stopped contacting the screen. + /// {@endtemplate} + /// + /// The velocity is provided in the callback's `details` argument, which is a + /// [DragEndDetails] object. + /// + /// If this gesture recognizer recognizes movement on a single axis (a + /// [VerticalDragGestureRecognizer] or [HorizontalDragGestureRecognizer]), + /// then `details` will reflect movement only on that axis and its + /// [DragEndDetails.primaryVelocity] will be non-null. + /// If this gesture recognizer recognizes movement in all directions + /// (a [PanGestureRecognizer]), then `details` will reflect movement on + /// both axes and its [DragEndDetails.primaryVelocity] will be null. + /// + /// See also: + /// + /// * [allowedButtonsFilter], which decides which button will be allowed. + /// * [DragEndDetails], which is passed as an argument to this callback. + GestureDragEndCallback? onEnd; + + /// The pointer that previously triggered [onDown] did not complete. + /// + /// See also: + /// + /// * [allowedButtonsFilter], which decides which button will be allowed. + GestureDragCancelCallback? onCancel; + + /// The minimum distance an input pointer drag must have moved + /// to be considered a fling gesture. + /// + /// This value is typically compared with the distance traveled along the + /// scrolling axis. If null then [kTouchSlop] is used. + double? minFlingDistance; + + /// The minimum velocity for an input pointer drag to be considered fling. + /// + /// This value is typically compared with the magnitude of fling gesture's + /// velocity along the scrolling axis. If null then [kMinFlingVelocity] + /// is used. + double? minFlingVelocity; + + /// Fling velocity magnitudes will be clamped to this value. + /// + /// If null then [kMaxFlingVelocity] is used. + double? maxFlingVelocity; + + /// Whether the drag threshold should be met before dispatching any drag callbacks. + /// + /// The drag threshold is met when the global distance traveled by a pointer has + /// exceeded the defined threshold on the relevant axis, i.e. y-axis for the + /// [VerticalDragGestureRecognizer], x-axis for the [HorizontalDragGestureRecognizer], + /// and the entire plane for [PanGestureRecognizer]. The threshold for both + /// [VerticalDragGestureRecognizer] and [HorizontalDragGestureRecognizer] are + /// calculated by [computeHitSlop], while [computePanSlop] is used for + /// [PanGestureRecognizer]. + /// + /// If true, the drag callbacks will only be dispatched when this recognizer has + /// won the arena and the drag threshold has been met. + /// + /// If false, the drag callbacks will be dispatched immediately when this recognizer + /// has won the arena. + /// + /// This value defaults to false. + bool onlyAcceptDragOnThreshold; + + /// Determines the type of velocity estimation method to use for a potential + /// drag gesture, when a new pointer is added. + /// + /// To estimate the velocity of a gesture, [DragGestureRecognizer] calls + /// [velocityTrackerBuilder] when it starts to track a new pointer in + /// [addAllowedPointer], and add subsequent updates on the pointer to the + /// resulting velocity tracker, until the gesture recognizer stops tracking + /// the pointer. This allows you to specify a different velocity estimation + /// strategy for each allowed pointer added, by changing the type of velocity + /// tracker this [GestureVelocityTrackerBuilder] returns. + /// + /// If left unspecified the default [velocityTrackerBuilder] creates a new + /// [VelocityTracker] for every pointer added. + /// + /// See also: + /// + /// * [VelocityTracker], a velocity tracker that uses least squares estimation + /// on the 20 most recent pointer data samples. It's a well-rounded velocity + /// tracker and is used by default. + /// * [IOSScrollViewFlingVelocityTracker], a specialized velocity tracker for + /// determining the initial fling velocity for a [Scrollable] on iOS, to + /// match the native behavior on that platform. + GestureVelocityTrackerBuilder velocityTrackerBuilder; + + _DragState _state = _DragState.ready; + late OffsetPair _initialPosition; + late OffsetPair _pendingDragOffset; + Duration? _lastPendingEventTimestamp; + + /// When asserts are enabled, returns the last tracked pending event timestamp + /// for this recognizer. + /// + /// Otherwise, returns null. + /// + /// This getter is intended for use in framework unit tests. Applications must + /// not depend on its value. + @visibleForTesting + Duration? get debugLastPendingEventTimestamp { + Duration? lastPendingEventTimestamp; + assert(() { + lastPendingEventTimestamp = _lastPendingEventTimestamp; + return true; + }()); + return lastPendingEventTimestamp; + } + + // The buttons sent by `PointerDownEvent`. If a `PointerMoveEvent` comes with a + // different set of buttons, the gesture is canceled. + int? _initialButtons; + Matrix4? _lastTransform; + + /// Distance moved in the global coordinate space of the screen in drag direction. + /// + /// If drag is only allowed along a defined axis, this value may be negative to + /// differentiate the direction of the drag. + late double _globalDistanceMoved; + + /// Determines if a gesture is a fling or not based on velocity. + /// + /// A fling calls its gesture end callback with a velocity, allowing the + /// provider of the callback to respond by carrying the gesture forward with + /// inertia, for example. + bool isFlingGesture(VelocityEstimate estimate, PointerDeviceKind kind); + + /// Determines if a gesture is a fling or not, and if so its effective velocity. + /// + /// A fling calls its gesture end callback with a velocity, allowing the + /// provider of the callback to respond by carrying the gesture forward with + /// inertia, for example. + DragEndDetails? _considerFling(VelocityEstimate estimate, PointerDeviceKind kind); + + Offset _getDeltaForDetails(Offset delta); + double? _getPrimaryValueFromOffset(Offset value); + bool _hasSufficientGlobalDistanceToAccept(PointerDeviceKind pointerDeviceKind, double? deviceTouchSlop); + bool _hasDragThresholdBeenMet = false; + + final Map _velocityTrackers = {}; + + @override + bool isPointerAllowed(PointerEvent event) { + if (_initialButtons == null) { + if (onDown == null && + onStart == null && + onUpdate == null && + onEnd == null && + onCancel == null) { + return false; + } + } else { + // There can be multiple drags simultaneously. Their effects are combined. + if (event.buttons != _initialButtons) { + return false; + } + } + return super.isPointerAllowed(event as PointerDownEvent); + } + + void _addPointer(PointerEvent event) { + _velocityTrackers[event.pointer] = velocityTrackerBuilder(event); + if (_state == _DragState.ready) { + _state = _DragState.possible; + _initialPosition = OffsetPair(global: event.position, local: event.localPosition); + _pendingDragOffset = OffsetPair.zero; + _globalDistanceMoved = 0.0; + _lastPendingEventTimestamp = event.timeStamp; + _lastTransform = event.transform; + _checkDown(); + } else if (_state == _DragState.accepted) { + resolve(GestureDisposition.accepted); + } + } + + @override + void addAllowedPointer(PointerDownEvent event) { + super.addAllowedPointer(event); + if (_state == _DragState.ready) { + _initialButtons = event.buttons; + } + _addPointer(event); + } + + @override + void addAllowedPointerPanZoom(PointerPanZoomStartEvent event) { + super.addAllowedPointerPanZoom(event); + startTrackingPointer(event.pointer, event.transform); + if (_state == _DragState.ready) { + _initialButtons = kPrimaryButton; + } + _addPointer(event); + } + + bool _shouldTrackMoveEvent(int pointer) { + final bool result; + switch (multitouchDragStrategy) { + case MultitouchDragStrategy.sumAllPointers: + result = true; + case MultitouchDragStrategy.latestPointer: + result = _acceptedActivePointers.length <= 1 || pointer == _acceptedActivePointers.last; + } + return result; + } + + @override + void handleEvent(PointerEvent event) { + assert(_state != _DragState.ready); + if (!event.synthesized && + (event is PointerDownEvent || + event is PointerMoveEvent || + event is PointerPanZoomStartEvent || + event is PointerPanZoomUpdateEvent)) { + final VelocityTracker tracker = _velocityTrackers[event.pointer]!; + if (event is PointerPanZoomStartEvent) { + tracker.addPosition(event.timeStamp, Offset.zero); + } else if (event is PointerPanZoomUpdateEvent) { + tracker.addPosition(event.timeStamp, event.pan); + } else { + tracker.addPosition(event.timeStamp, event.localPosition); + } + } + if (event is PointerMoveEvent && event.buttons != _initialButtons) { + _giveUpPointer(event.pointer); + return; + } + if ((event is PointerMoveEvent || event is PointerPanZoomUpdateEvent) + && _shouldTrackMoveEvent(event.pointer)) { + final Offset delta = (event is PointerMoveEvent) ? event.delta : (event as PointerPanZoomUpdateEvent).panDelta; + final Offset localDelta = (event is PointerMoveEvent) ? event.localDelta : (event as PointerPanZoomUpdateEvent).localPanDelta; + final Offset position = (event is PointerMoveEvent) ? event.position : (event.position + (event as PointerPanZoomUpdateEvent).pan); + final Offset localPosition = (event is PointerMoveEvent) ? event.localPosition : (event.localPosition + (event as PointerPanZoomUpdateEvent).localPan); + if (_state == _DragState.accepted) { + _checkUpdate( + sourceTimeStamp: event.timeStamp, + delta: _getDeltaForDetails(localDelta), + primaryDelta: _getPrimaryValueFromOffset(localDelta), + globalPosition: position, + localPosition: localPosition, + ); + } else { + _pendingDragOffset += OffsetPair(local: localDelta, global: delta); + _lastPendingEventTimestamp = event.timeStamp; + _lastTransform = event.transform; + final Offset movedLocally = _getDeltaForDetails(localDelta); + final Matrix4? localToGlobalTransform = event.transform == null ? null : Matrix4.tryInvert(event.transform!); + _globalDistanceMoved += PointerEvent.transformDeltaViaPositions( + transform: localToGlobalTransform, + untransformedDelta: movedLocally, + untransformedEndPosition: localPosition + ).distance * (_getPrimaryValueFromOffset(movedLocally) ?? 1).sign; + if (_hasSufficientGlobalDistanceToAccept(event.kind, gestureSettings?.touchSlop)) { + _hasDragThresholdBeenMet = true; + if (_acceptedActivePointers.contains(event.pointer)) { + _checkDrag(event.pointer); + } else { + resolve(GestureDisposition.accepted); + } + } + } + } + if (event is PointerUpEvent || event is PointerCancelEvent || event is PointerPanZoomEndEvent) { + _giveUpPointer(event.pointer); + } + } + + final List _acceptedActivePointers = []; + + @override + void acceptGesture(int pointer) { + assert(!_acceptedActivePointers.contains(pointer)); + _acceptedActivePointers.add(pointer); + if (!onlyAcceptDragOnThreshold || _hasDragThresholdBeenMet) { + _checkDrag(pointer); + } + } + + @override + void rejectGesture(int pointer) { + _giveUpPointer(pointer); + } + + @override + void didStopTrackingLastPointer(int pointer) { + assert(_state != _DragState.ready); + switch (_state) { + case _DragState.ready: + break; + + case _DragState.possible: + resolve(GestureDisposition.rejected); + _checkCancel(); + + case _DragState.accepted: + _checkEnd(pointer); + } + _hasDragThresholdBeenMet = false; + _velocityTrackers.clear(); + _initialButtons = null; + _state = _DragState.ready; + } + + void _giveUpPointer(int pointer) { + stopTrackingPointer(pointer); + // If we never accepted the pointer, we reject it since we are no longer + // interested in winning the gesture arena for it. + if (!_acceptedActivePointers.remove(pointer)) { + resolvePointer(pointer, GestureDisposition.rejected); + } + } + + void _checkDown() { + if (onDown != null) { + final DragDownDetails details = DragDownDetails( + globalPosition: _initialPosition.global, + localPosition: _initialPosition.local, + ); + invokeCallback('onDown', () => onDown!(details)); + } + } + + void _checkDrag(int pointer) { + if (_state == _DragState.accepted) { + return; + } + _state = _DragState.accepted; + final OffsetPair delta = _pendingDragOffset; + final Duration? timestamp = _lastPendingEventTimestamp; + final Matrix4? transform = _lastTransform; + final Offset localUpdateDelta; + switch (dragStartBehavior) { + case DragStartBehavior.start: + _initialPosition = _initialPosition + delta; + localUpdateDelta = Offset.zero; + case DragStartBehavior.down: + localUpdateDelta = _getDeltaForDetails(delta.local); + } + _pendingDragOffset = OffsetPair.zero; + _lastPendingEventTimestamp = null; + _lastTransform = null; + _checkStart(timestamp, pointer); + if (localUpdateDelta != Offset.zero && onUpdate != null) { + final Matrix4? localToGlobal = transform != null ? Matrix4.tryInvert(transform) : null; + final Offset correctedLocalPosition = _initialPosition.local + localUpdateDelta; + final Offset globalUpdateDelta = PointerEvent.transformDeltaViaPositions( + untransformedEndPosition: correctedLocalPosition, + untransformedDelta: localUpdateDelta, + transform: localToGlobal, + ); + final OffsetPair updateDelta = OffsetPair(local: localUpdateDelta, global: globalUpdateDelta); + final OffsetPair correctedPosition = _initialPosition + updateDelta; // Only adds delta for down behaviour + _checkUpdate( + sourceTimeStamp: timestamp, + delta: localUpdateDelta, + primaryDelta: _getPrimaryValueFromOffset(localUpdateDelta), + globalPosition: correctedPosition.global, + localPosition: correctedPosition.local, + ); + } + // This acceptGesture might have been called only for one pointer, instead + // of all pointers. Resolve all pointers to `accepted`. This won't cause + // infinite recursion because an accepted pointer won't be accepted again. + resolve(GestureDisposition.accepted); + } + + void _checkStart(Duration? timestamp, int pointer) { + if (onStart != null) { + final DragStartDetails details = DragStartDetails( + sourceTimeStamp: timestamp, + globalPosition: _initialPosition.global, + localPosition: _initialPosition.local, + kind: getKindForPointer(pointer), + ); + invokeCallback('onStart', () => onStart!(details)); + } + } + + void _checkUpdate({ + Duration? sourceTimeStamp, + required Offset delta, + double? primaryDelta, + required Offset globalPosition, + Offset? localPosition, + }) { + if (onUpdate != null) { + final DragUpdateDetails details = DragUpdateDetails( + sourceTimeStamp: sourceTimeStamp, + delta: delta, + primaryDelta: primaryDelta, + globalPosition: globalPosition, + localPosition: localPosition, + ); + invokeCallback('onUpdate', () => onUpdate!(details)); + } + } + + void _checkEnd(int pointer) { + if (onEnd == null) { + return; + } + + final VelocityTracker tracker = _velocityTrackers[pointer]!; + final VelocityEstimate? estimate = tracker.getVelocityEstimate(); + + DragEndDetails? details; + final String Function() debugReport; + if (estimate == null) { + debugReport = () => 'Could not estimate velocity.'; + } else { + details = _considerFling(estimate, tracker.kind); + debugReport = (details != null) + ? () => '$estimate; fling at ${details!.velocity}.' + : () => '$estimate; judged to not be a fling.'; + } + details ??= DragEndDetails(primaryVelocity: 0.0); + + invokeCallback('onEnd', () => onEnd!(details!), debugReport: debugReport); + } + + void _checkCancel() { + if (onCancel != null) { + invokeCallback('onCancel', onCancel!); + } + } + + @override + void dispose() { + _velocityTrackers.clear(); + super.dispose(); + } + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty('start behavior', dragStartBehavior)); + } +} + +/// Recognizes movement in the vertical direction. +/// +/// Used for vertical scrolling. +/// +/// See also: +/// +/// * [HorizontalDragGestureRecognizer], for a similar recognizer but for +/// horizontal movement. +/// * [MultiDragGestureRecognizer], for a family of gesture recognizers that +/// track each touch point independently. +class VerticalDragGestureRecognizer extends DragGestureRecognizer { + /// Create a gesture recognizer for interactions in the vertical axis. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + VerticalDragGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + @override + bool isFlingGesture(VelocityEstimate estimate, PointerDeviceKind kind) { + final double minVelocity = minFlingVelocity ?? kMinFlingVelocity; + final double minDistance = minFlingDistance ?? computeHitSlop(kind, gestureSettings); + return estimate.pixelsPerSecond.dy.abs() > minVelocity && estimate.offset.dy.abs() > minDistance; + } + + @override + DragEndDetails? _considerFling(VelocityEstimate estimate, PointerDeviceKind kind) { + if (!isFlingGesture(estimate, kind)) { + return null; + } + final double maxVelocity = maxFlingVelocity ?? kMaxFlingVelocity; + final double dy = clampDouble(estimate.pixelsPerSecond.dy, -maxVelocity, maxVelocity); + return DragEndDetails( + velocity: Velocity(pixelsPerSecond: Offset(0, dy)), + primaryVelocity: dy, + ); + } + + @override + bool _hasSufficientGlobalDistanceToAccept(PointerDeviceKind pointerDeviceKind, double? deviceTouchSlop) { + return _globalDistanceMoved.abs() > computeHitSlop(pointerDeviceKind, gestureSettings); + } + + @override + Offset _getDeltaForDetails(Offset delta) => Offset(0.0, delta.dy); + + @override + double _getPrimaryValueFromOffset(Offset value) => value.dy; + + @override + String get debugDescription => 'vertical drag'; +} + +/// Recognizes movement in the horizontal direction. +/// +/// Used for horizontal scrolling. +/// +/// See also: +/// +/// * [VerticalDragGestureRecognizer], for a similar recognizer but for +/// vertical movement. +/// * [MultiDragGestureRecognizer], for a family of gesture recognizers that +/// track each touch point independently. +class HorizontalDragGestureRecognizer extends DragGestureRecognizer { + /// Create a gesture recognizer for interactions in the horizontal axis. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + HorizontalDragGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + @override + bool isFlingGesture(VelocityEstimate estimate, PointerDeviceKind kind) { + final double minVelocity = minFlingVelocity ?? kMinFlingVelocity; + final double minDistance = minFlingDistance ?? computeHitSlop(kind, gestureSettings); + return estimate.pixelsPerSecond.dx.abs() > minVelocity && estimate.offset.dx.abs() > minDistance; + } + + @override + DragEndDetails? _considerFling(VelocityEstimate estimate, PointerDeviceKind kind) { + if (!isFlingGesture(estimate, kind)) { + return null; + } + final double maxVelocity = maxFlingVelocity ?? kMaxFlingVelocity; + final double dx = clampDouble(estimate.pixelsPerSecond.dx, -maxVelocity, maxVelocity); + return DragEndDetails( + velocity: Velocity(pixelsPerSecond: Offset(dx, 0)), + primaryVelocity: dx, + ); + } + + @override + bool _hasSufficientGlobalDistanceToAccept(PointerDeviceKind pointerDeviceKind, double? deviceTouchSlop) { + return _globalDistanceMoved.abs() > computeHitSlop(pointerDeviceKind, gestureSettings); + } + + @override + Offset _getDeltaForDetails(Offset delta) => Offset(delta.dx, 0.0); + + @override + double _getPrimaryValueFromOffset(Offset value) => value.dx; + + @override + String get debugDescription => 'horizontal drag'; +} + +/// Recognizes movement both horizontally and vertically. +/// +/// See also: +/// +/// * [ImmediateMultiDragGestureRecognizer], for a similar recognizer that +/// tracks each touch point independently. +/// * [DelayedMultiDragGestureRecognizer], for a similar recognizer that +/// tracks each touch point independently, but that doesn't start until +/// some time has passed. +class PanGestureRecognizer extends DragGestureRecognizer { + /// Create a gesture recognizer for tracking movement on a plane. + PanGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + @override + bool isFlingGesture(VelocityEstimate estimate, PointerDeviceKind kind) { + final double minVelocity = minFlingVelocity ?? kMinFlingVelocity; + final double minDistance = minFlingDistance ?? computeHitSlop(kind, gestureSettings); + return estimate.pixelsPerSecond.distanceSquared > minVelocity * minVelocity + && estimate.offset.distanceSquared > minDistance * minDistance; + } + + @override + DragEndDetails? _considerFling(VelocityEstimate estimate, PointerDeviceKind kind) { + if (!isFlingGesture(estimate, kind)) { + return null; + } + final Velocity velocity = Velocity(pixelsPerSecond: estimate.pixelsPerSecond) + .clampMagnitude(minFlingVelocity ?? kMinFlingVelocity, maxFlingVelocity ?? kMaxFlingVelocity); + return DragEndDetails(velocity: velocity); + } + + @override + bool _hasSufficientGlobalDistanceToAccept(PointerDeviceKind pointerDeviceKind, double? deviceTouchSlop) { + return _globalDistanceMoved.abs() > computePanSlop(pointerDeviceKind, gestureSettings); + } + + @override + Offset _getDeltaForDetails(Offset delta) => delta; + + @override + double? _getPrimaryValueFromOffset(Offset value) => null; + + @override + String get debugDescription => 'pan'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/multidrag.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/multidrag.dart new file mode 100644 index 0000000000000000000000000000000000000000..c58be81889a8f4e7f62f60ad65c94df6cd5a5ccc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/multidrag.dart @@ -0,0 +1,608 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; + +import 'arena.dart'; +import 'binding.dart'; +import 'constants.dart'; +import 'drag.dart'; +import 'drag_details.dart'; +import 'events.dart'; +import 'recognizer.dart'; +import 'velocity_tracker.dart'; + +export 'dart:ui' show Offset, PointerDeviceKind; + +export 'arena.dart' show GestureDisposition; +export 'drag.dart' show Drag; +export 'events.dart' show PointerDownEvent; +export 'gesture_settings.dart' show DeviceGestureSettings; + +/// Signature for when [MultiDragGestureRecognizer] recognizes the start of a drag gesture. +typedef GestureMultiDragStartCallback = Drag? Function(Offset position); + +/// Per-pointer state for a [MultiDragGestureRecognizer]. +/// +/// A [MultiDragGestureRecognizer] tracks each pointer separately. The state for +/// each pointer is a subclass of [MultiDragPointerState]. +abstract class MultiDragPointerState { + /// Creates per-pointer state for a [MultiDragGestureRecognizer]. + MultiDragPointerState(this.initialPosition, this.kind, this.gestureSettings) + : _velocityTracker = VelocityTracker.withKind(kind) { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/gestures.dart', + className: '$MultiDragPointerState', + object: this, + ); + } + } + + /// Device specific gesture configuration that should be preferred over + /// framework constants. + /// + /// These settings are commonly retrieved from a [MediaQuery]. + final DeviceGestureSettings? gestureSettings; + + /// The global coordinates of the pointer when the pointer contacted the screen. + final Offset initialPosition; + + final VelocityTracker _velocityTracker; + + /// The kind of pointer performing the multi-drag gesture. + /// + /// Used by subclasses to determine the appropriate hit slop, for example. + final PointerDeviceKind kind; + + Drag? _client; + + /// The offset of the pointer from the last position that was reported to the client. + /// + /// After the pointer contacts the screen, the pointer might move some + /// distance before this movement will be recognized as a drag. This field + /// accumulates that movement so that we can report it to the client after + /// the drag starts. + Offset? get pendingDelta => _pendingDelta; + Offset? _pendingDelta = Offset.zero; + + Duration? _lastPendingEventTimestamp; + + GestureArenaEntry? _arenaEntry; + void _setArenaEntry(GestureArenaEntry entry) { + assert(_arenaEntry == null); + assert(pendingDelta != null); + assert(_client == null); + _arenaEntry = entry; + } + + /// Resolve this pointer's entry in the [GestureArenaManager] with the given disposition. + @protected + @mustCallSuper + void resolve(GestureDisposition disposition) { + _arenaEntry!.resolve(disposition); + } + + void _move(PointerMoveEvent event) { + assert(_arenaEntry != null); + if (!event.synthesized) { + _velocityTracker.addPosition(event.timeStamp, event.position); + } + if (_client != null) { + assert(pendingDelta == null); + // Call client last to avoid reentrancy. + _client!.update(DragUpdateDetails( + sourceTimeStamp: event.timeStamp, + delta: event.delta, + globalPosition: event.position, + )); + } else { + assert(pendingDelta != null); + _pendingDelta = _pendingDelta! + event.delta; + _lastPendingEventTimestamp = event.timeStamp; + checkForResolutionAfterMove(); + } + } + + /// Override this to call resolve() if the drag should be accepted or rejected. + /// This is called when a pointer movement is received, but only if the gesture + /// has not yet been resolved. + @protected + void checkForResolutionAfterMove() { } + + /// Called when the gesture was accepted. + /// + /// Either immediately or at some future point before the gesture is disposed, + /// call starter(), passing it initialPosition, to start the drag. + @protected + void accepted(GestureMultiDragStartCallback starter); + + /// Called when the gesture was rejected. + /// + /// The [dispose] method will be called immediately following this. + @protected + @mustCallSuper + void rejected() { + assert(_arenaEntry != null); + assert(_client == null); + assert(pendingDelta != null); + _pendingDelta = null; + _lastPendingEventTimestamp = null; + _arenaEntry = null; + } + + void _startDrag(Drag client) { + assert(_arenaEntry != null); + assert(_client == null); + assert(pendingDelta != null); + _client = client; + final DragUpdateDetails details = DragUpdateDetails( + sourceTimeStamp: _lastPendingEventTimestamp, + delta: pendingDelta!, + globalPosition: initialPosition, + ); + _pendingDelta = null; + _lastPendingEventTimestamp = null; + // Call client last to avoid reentrancy. + _client!.update(details); + } + + void _up() { + assert(_arenaEntry != null); + if (_client != null) { + assert(pendingDelta == null); + final DragEndDetails details = DragEndDetails(velocity: _velocityTracker.getVelocity()); + final Drag client = _client!; + _client = null; + // Call client last to avoid reentrancy. + client.end(details); + } else { + assert(pendingDelta != null); + _pendingDelta = null; + _lastPendingEventTimestamp = null; + } + } + + void _cancel() { + assert(_arenaEntry != null); + if (_client != null) { + assert(pendingDelta == null); + final Drag client = _client!; + _client = null; + // Call client last to avoid reentrancy. + client.cancel(); + } else { + assert(pendingDelta != null); + _pendingDelta = null; + _lastPendingEventTimestamp = null; + } + } + + /// Releases any resources used by the object. + @protected + @mustCallSuper + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _arenaEntry?.resolve(GestureDisposition.rejected); + _arenaEntry = null; + assert(() { + _pendingDelta = null; + return true; + }()); + } +} + +/// Recognizes movement on a per-pointer basis. +/// +/// In contrast to [DragGestureRecognizer], [MultiDragGestureRecognizer] watches +/// each pointer separately, which means multiple drags can be recognized +/// concurrently if multiple pointers are in contact with the screen. +/// +/// [MultiDragGestureRecognizer] is not intended to be used directly. Instead, +/// consider using one of its subclasses to recognize specific types for drag +/// gestures. +/// +/// See also: +/// +/// * [ImmediateMultiDragGestureRecognizer], the most straight-forward variant +/// of multi-pointer drag gesture recognizer. +/// * [HorizontalMultiDragGestureRecognizer], which only recognizes drags that +/// start horizontally. +/// * [VerticalMultiDragGestureRecognizer], which only recognizes drags that +/// start vertically. +/// * [DelayedMultiDragGestureRecognizer], which only recognizes drags that +/// start after a long-press gesture. +abstract class MultiDragGestureRecognizer extends GestureRecognizer { + /// Initialize the object. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + MultiDragGestureRecognizer({ + required super.debugOwner, + super.supportedDevices, + AllowedButtonsFilter? allowedButtonsFilter, + }) : super(allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior); + + // Accept the input if, and only if, [kPrimaryButton] is pressed. + static bool _defaultButtonAcceptBehavior(int buttons) => buttons == kPrimaryButton; + + /// Called when this class recognizes the start of a drag gesture. + /// + /// The remaining notifications for this drag gesture are delivered to the + /// [Drag] object returned by this callback. + GestureMultiDragStartCallback? onStart; + + Map? _pointers = {}; + + @override + void addAllowedPointer(PointerDownEvent event) { + assert(_pointers != null); + assert(!_pointers!.containsKey(event.pointer)); + final MultiDragPointerState state = createNewPointerState(event); + _pointers![event.pointer] = state; + GestureBinding.instance.pointerRouter.addRoute(event.pointer, _handleEvent); + state._setArenaEntry(GestureBinding.instance.gestureArena.add(event.pointer, this)); + } + + /// Subclasses should override this method to create per-pointer state + /// objects to track the pointer associated with the given event. + @protected + @factory + MultiDragPointerState createNewPointerState(PointerDownEvent event); + + void _handleEvent(PointerEvent event) { + assert(_pointers != null); + assert(_pointers!.containsKey(event.pointer)); + final MultiDragPointerState state = _pointers![event.pointer]!; + if (event is PointerMoveEvent) { + state._move(event); + // We might be disposed here. + } else if (event is PointerUpEvent) { + assert(event.delta == Offset.zero); + state._up(); + // We might be disposed here. + _removeState(event.pointer); + } else if (event is PointerCancelEvent) { + assert(event.delta == Offset.zero); + state._cancel(); + // We might be disposed here. + _removeState(event.pointer); + } else if (event is! PointerDownEvent) { + // we get the PointerDownEvent that resulted in our addPointer getting called since we + // add ourselves to the pointer router then (before the pointer router has heard of + // the event). + assert(false); + } + } + + @override + void acceptGesture(int pointer) { + assert(_pointers != null); + final MultiDragPointerState? state = _pointers![pointer]; + if (state == null) { + return; // We might already have canceled this drag if the up comes before the accept. + } + state.accepted((Offset initialPosition) => _startDrag(initialPosition, pointer)); + } + + Drag? _startDrag(Offset initialPosition, int pointer) { + assert(_pointers != null); + final MultiDragPointerState state = _pointers![pointer]!; + assert(state._pendingDelta != null); + Drag? drag; + if (onStart != null) { + drag = invokeCallback('onStart', () => onStart!(initialPosition)); + } + if (drag != null) { + state._startDrag(drag); + } else { + _removeState(pointer); + } + return drag; + } + + @override + void rejectGesture(int pointer) { + assert(_pointers != null); + if (_pointers!.containsKey(pointer)) { + final MultiDragPointerState state = _pointers![pointer]!; + state.rejected(); + _removeState(pointer); + } // else we already preemptively forgot about it (e.g. we got an up event) + } + + void _removeState(int pointer) { + if (_pointers == null) { + // We've already been disposed. It's harmless to skip removing the state + // for the given pointer because dispose() has already removed it. + return; + } + assert(_pointers!.containsKey(pointer)); + GestureBinding.instance.pointerRouter.removeRoute(pointer, _handleEvent); + _pointers!.remove(pointer)!.dispose(); + } + + @override + void dispose() { + _pointers!.keys.toList().forEach(_removeState); + assert(_pointers!.isEmpty); + _pointers = null; + super.dispose(); + } +} + +class _ImmediatePointerState extends MultiDragPointerState { + _ImmediatePointerState(super.initialPosition, super.kind, super.gestureSettings); + + @override + void checkForResolutionAfterMove() { + assert(pendingDelta != null); + if (pendingDelta!.distance > computeHitSlop(kind, gestureSettings)) { + resolve(GestureDisposition.accepted); + } + } + + @override + void accepted(GestureMultiDragStartCallback starter) { + starter(initialPosition); + } +} + +/// Recognizes movement both horizontally and vertically on a per-pointer basis. +/// +/// In contrast to [PanGestureRecognizer], [ImmediateMultiDragGestureRecognizer] +/// watches each pointer separately, which means multiple drags can be +/// recognized concurrently if multiple pointers are in contact with the screen. +/// +/// See also: +/// +/// * [PanGestureRecognizer], which recognizes only one drag gesture at a time, +/// regardless of how many fingers are involved. +/// * [HorizontalMultiDragGestureRecognizer], which only recognizes drags that +/// start horizontally. +/// * [VerticalMultiDragGestureRecognizer], which only recognizes drags that +/// start vertically. +/// * [DelayedMultiDragGestureRecognizer], which only recognizes drags that +/// start after a long-press gesture. +class ImmediateMultiDragGestureRecognizer extends MultiDragGestureRecognizer { + /// Create a gesture recognizer for tracking multiple pointers at once. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + ImmediateMultiDragGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + @override + MultiDragPointerState createNewPointerState(PointerDownEvent event) { + return _ImmediatePointerState(event.position, event.kind, gestureSettings); + } + + @override + String get debugDescription => 'multidrag'; +} + + +class _HorizontalPointerState extends MultiDragPointerState { + _HorizontalPointerState(super.initialPosition, super.kind, super.gestureSettings); + + @override + void checkForResolutionAfterMove() { + assert(pendingDelta != null); + if (pendingDelta!.dx.abs() > computeHitSlop(kind, gestureSettings)) { + resolve(GestureDisposition.accepted); + } + } + + @override + void accepted(GestureMultiDragStartCallback starter) { + starter(initialPosition); + } +} + +/// Recognizes movement in the horizontal direction on a per-pointer basis. +/// +/// In contrast to [HorizontalDragGestureRecognizer], +/// [HorizontalMultiDragGestureRecognizer] watches each pointer separately, +/// which means multiple drags can be recognized concurrently if multiple +/// pointers are in contact with the screen. +/// +/// See also: +/// +/// * [HorizontalDragGestureRecognizer], a gesture recognizer that just +/// looks at horizontal movement. +/// * [ImmediateMultiDragGestureRecognizer], a similar recognizer, but without +/// the limitation that the drag must start horizontally. +/// * [VerticalMultiDragGestureRecognizer], which only recognizes drags that +/// start vertically. +class HorizontalMultiDragGestureRecognizer extends MultiDragGestureRecognizer { + /// Create a gesture recognizer for tracking multiple pointers at once + /// but only if they first move horizontally. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + HorizontalMultiDragGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + @override + MultiDragPointerState createNewPointerState(PointerDownEvent event) { + return _HorizontalPointerState(event.position, event.kind, gestureSettings); + } + + @override + String get debugDescription => 'horizontal multidrag'; +} + + +class _VerticalPointerState extends MultiDragPointerState { + _VerticalPointerState(super.initialPosition, super.kind, super.gestureSettings); + + @override + void checkForResolutionAfterMove() { + assert(pendingDelta != null); + if (pendingDelta!.dy.abs() > computeHitSlop(kind, gestureSettings)) { + resolve(GestureDisposition.accepted); + } + } + + @override + void accepted(GestureMultiDragStartCallback starter) { + starter(initialPosition); + } +} + +/// Recognizes movement in the vertical direction on a per-pointer basis. +/// +/// In contrast to [VerticalDragGestureRecognizer], +/// [VerticalMultiDragGestureRecognizer] watches each pointer separately, +/// which means multiple drags can be recognized concurrently if multiple +/// pointers are in contact with the screen. +/// +/// See also: +/// +/// * [VerticalDragGestureRecognizer], a gesture recognizer that just +/// looks at vertical movement. +/// * [ImmediateMultiDragGestureRecognizer], a similar recognizer, but without +/// the limitation that the drag must start vertically. +/// * [HorizontalMultiDragGestureRecognizer], which only recognizes drags that +/// start horizontally. +class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer { + /// Create a gesture recognizer for tracking multiple pointers at once + /// but only if they first move vertically. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + VerticalMultiDragGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + @override + MultiDragPointerState createNewPointerState(PointerDownEvent event) { + return _VerticalPointerState(event.position, event.kind, gestureSettings); + } + + @override + String get debugDescription => 'vertical multidrag'; +} + +class _DelayedPointerState extends MultiDragPointerState { + _DelayedPointerState(super.initialPosition, Duration delay, super.kind, super.gestureSettings) { + _timer = Timer(delay, _delayPassed); + } + + Timer? _timer; + GestureMultiDragStartCallback? _starter; + + void _delayPassed() { + assert(_timer != null); + assert(pendingDelta != null); + assert(pendingDelta!.distance <= computeHitSlop(kind, gestureSettings)); + _timer = null; + if (_starter != null) { + _starter!(initialPosition); + _starter = null; + } else { + resolve(GestureDisposition.accepted); + } + assert(_starter == null); + } + + void _ensureTimerStopped() { + _timer?.cancel(); + _timer = null; + } + + @override + void accepted(GestureMultiDragStartCallback starter) { + assert(_starter == null); + if (_timer == null) { + starter(initialPosition); + } else { + _starter = starter; + } + } + + @override + void checkForResolutionAfterMove() { + if (_timer == null) { + // If we've been accepted by the gesture arena but the pointer moves too + // much before the timer fires, we end up a state where the timer is + // stopped but we keep getting calls to this function because we never + // actually started the drag. In this case, _starter will be non-null + // because we're essentially waiting forever to start the drag. + assert(_starter != null); + return; + } + assert(pendingDelta != null); + if (pendingDelta!.distance > computeHitSlop(kind, gestureSettings)) { + resolve(GestureDisposition.rejected); + _ensureTimerStopped(); + } + } + + @override + void dispose() { + _ensureTimerStopped(); + super.dispose(); + } +} + +/// Recognizes movement both horizontally and vertically on a per-pointer basis +/// after a delay. +/// +/// In contrast to [ImmediateMultiDragGestureRecognizer], +/// [DelayedMultiDragGestureRecognizer] waits for a [delay] before recognizing +/// the drag. If the pointer moves more than [kTouchSlop] before the delay +/// expires, the gesture is not recognized. +/// +/// In contrast to [PanGestureRecognizer], [DelayedMultiDragGestureRecognizer] +/// watches each pointer separately, which means multiple drags can be +/// recognized concurrently if multiple pointers are in contact with the screen. +/// +/// See also: +/// +/// * [ImmediateMultiDragGestureRecognizer], a similar recognizer but without +/// the delay. +/// * [PanGestureRecognizer], which recognizes only one drag gesture at a time, +/// regardless of how many fingers are involved. +class DelayedMultiDragGestureRecognizer extends MultiDragGestureRecognizer { + /// Creates a drag recognizer that works on a per-pointer basis after a delay. + /// + /// In order for a drag to be recognized by this recognizer, the pointer must + /// remain in the same place for [delay] (up to [kTouchSlop]). The [delay] + /// defaults to [kLongPressTimeout] to match [LongPressGestureRecognizer] but + /// can be changed for specific behaviors. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + DelayedMultiDragGestureRecognizer({ + this.delay = kLongPressTimeout, + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + /// The amount of time the pointer must remain in the same place for the drag + /// to be recognized. + final Duration delay; + + @override + MultiDragPointerState createNewPointerState(PointerDownEvent event) { + return _DelayedPointerState(event.position, delay, event.kind, gestureSettings); + } + + @override + String get debugDescription => 'long multidrag'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/multitap.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/multitap.dart new file mode 100644 index 0000000000000000000000000000000000000000..2c9b6f5c318def3ca9b852a61f2de86d6a0b58f9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/multitap.dart @@ -0,0 +1,1015 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'arena.dart'; +import 'binding.dart'; +import 'constants.dart'; +import 'events.dart'; +import 'pointer_router.dart'; +import 'recognizer.dart'; +import 'tap.dart'; + +export 'dart:ui' show Offset, PointerDeviceKind; + +export 'events.dart' show PointerDownEvent; +export 'tap.dart' show GestureTapCancelCallback, GestureTapDownCallback, TapDownDetails, TapUpDetails; + +/// Signature for callback when the user has tapped the screen at the same +/// location twice in quick succession. +/// +/// See also: +/// +/// * [GestureDetector.onDoubleTap], which matches this signature. +typedef GestureDoubleTapCallback = void Function(); + +/// Signature used by [MultiTapGestureRecognizer] for when a pointer that might +/// cause a tap has contacted the screen at a particular location. +typedef GestureMultiTapDownCallback = void Function(int pointer, TapDownDetails details); + +/// Signature used by [MultiTapGestureRecognizer] for when a pointer that will +/// trigger a tap has stopped contacting the screen at a particular location. +typedef GestureMultiTapUpCallback = void Function(int pointer, TapUpDetails details); + +/// Signature used by [MultiTapGestureRecognizer] for when a tap has occurred. +typedef GestureMultiTapCallback = void Function(int pointer); + +/// Signature for when the pointer that previously triggered a +/// [GestureMultiTapDownCallback] will not end up causing a tap. +typedef GestureMultiTapCancelCallback = void Function(int pointer); + +/// CountdownZoned tracks whether the specified duration has elapsed since +/// creation, honoring [Zone]. +class _CountdownZoned { + _CountdownZoned({ required Duration duration }) { + Timer(duration, _onTimeout); + } + + bool _timeout = false; + + bool get timeout => _timeout; + + void _onTimeout() { + _timeout = true; + } +} + +/// TapTracker helps track individual tap sequences as part of a +/// larger gesture. +class _TapTracker { + _TapTracker({ + required PointerDownEvent event, + required this.entry, + required Duration doubleTapMinTime, + required this.gestureSettings, + }) : pointer = event.pointer, + _initialGlobalPosition = event.position, + initialButtons = event.buttons, + _doubleTapMinTimeCountdown = _CountdownZoned(duration: doubleTapMinTime); + + final DeviceGestureSettings? gestureSettings; + final int pointer; + final GestureArenaEntry entry; + final Offset _initialGlobalPosition; + final int initialButtons; + final _CountdownZoned _doubleTapMinTimeCountdown; + + bool _isTrackingPointer = false; + + void startTrackingPointer(PointerRoute route, Matrix4? transform) { + if (!_isTrackingPointer) { + _isTrackingPointer = true; + GestureBinding.instance.pointerRouter.addRoute(pointer, route, transform); + } + } + + void stopTrackingPointer(PointerRoute route) { + if (_isTrackingPointer) { + _isTrackingPointer = false; + GestureBinding.instance.pointerRouter.removeRoute(pointer, route); + } + } + + bool isWithinGlobalTolerance(PointerEvent event, double tolerance) { + final Offset offset = event.position - _initialGlobalPosition; + return offset.distance <= tolerance; + } + + bool hasElapsedMinTime() { + return _doubleTapMinTimeCountdown.timeout; + } + + bool hasSameButton(PointerDownEvent event) { + return event.buttons == initialButtons; + } +} + +/// Recognizes when the user has tapped the screen at the same location twice in +/// quick succession. +/// +/// [DoubleTapGestureRecognizer] competes on pointer events when it +/// has a non-null callback. If it has no callbacks, it is a no-op. +/// +class DoubleTapGestureRecognizer extends GestureRecognizer { + /// Create a gesture recognizer for double taps. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + DoubleTapGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + AllowedButtonsFilter? allowedButtonsFilter, + }) : super(allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior); + + // The default value for [allowedButtonsFilter]. + // Accept the input if, and only if, [kPrimaryButton] is pressed. + static bool _defaultButtonAcceptBehavior(int buttons) => buttons == kPrimaryButton; + + // Implementation notes: + // + // The double tap recognizer can be in one of four states. There's no + // explicit enum for the states, because they are already captured by + // the state of existing fields. Specifically: + // + // 1. Waiting on first tap: In this state, the _trackers list is empty, and + // _firstTap is null. + // 2. First tap in progress: In this state, the _trackers list contains all + // the states for taps that have begun but not completed. This list can + // have more than one entry if two pointers begin to tap. + // 3. Waiting on second tap: In this state, one of the in-progress taps has + // completed successfully. The _trackers list is again empty, and + // _firstTap records the successful tap. + // 4. Second tap in progress: Much like the "first tap in progress" state, but + // _firstTap is non-null. If a tap completes successfully while in this + // state, the callback is called and the state is reset. + // + // There are various other scenarios that cause the state to reset: + // + // - All in-progress taps are rejected (by time, distance, pointercancel, etc) + // - The long timer between taps expires + // - The gesture arena decides we have been rejected wholesale + + /// A pointer has contacted the screen with a primary button at the same + /// location twice in quick succession, which might be the start of a double + /// tap. + /// + /// This triggers immediately after the down event of the second tap. + /// + /// If this recognizer doesn't win the arena, [onDoubleTapCancel] is called + /// next. Otherwise, [onDoubleTap] is called next. + /// + /// See also: + /// + /// * [allowedButtonsFilter], which decides which button will be allowed. + /// * [TapDownDetails], which is passed as an argument to this callback. + /// * [GestureDetector.onDoubleTapDown], which exposes this callback. + GestureTapDownCallback? onDoubleTapDown; + + /// Called when the user has tapped the screen with a primary button at the + /// same location twice in quick succession. + /// + /// This triggers when the pointer stops contacting the device after the + /// second tap. + /// + /// See also: + /// + /// * [allowedButtonsFilter], which decides which button will be allowed. + /// * [GestureDetector.onDoubleTap], which exposes this callback. + GestureDoubleTapCallback? onDoubleTap; + + /// A pointer that previously triggered [onDoubleTapDown] will not end up + /// causing a double tap. + /// + /// This triggers once the gesture loses the arena if [onDoubleTapDown] has + /// previously been triggered. + /// + /// If this recognizer wins the arena, [onDoubleTap] is called instead. + /// + /// See also: + /// + /// * [allowedButtonsFilter], which decides which button will be allowed. + /// * [GestureDetector.onDoubleTapCancel], which exposes this callback. + GestureTapCancelCallback? onDoubleTapCancel; + + Timer? _doubleTapTimer; + _TapTracker? _firstTap; + final Map _trackers = {}; + + @override + bool isPointerAllowed(PointerDownEvent event) { + if (_firstTap == null) { + if (onDoubleTapDown == null && + onDoubleTap == null && + onDoubleTapCancel == null) { + return false; + } + } + + // If second tap is not allowed, reset the state. + final bool isPointerAllowed = super.isPointerAllowed(event); + if (!isPointerAllowed) { + _reset(); + } + return isPointerAllowed; + } + + @override + void addAllowedPointer(PointerDownEvent event) { + if (_firstTap != null) { + if (!_firstTap!.isWithinGlobalTolerance(event, kDoubleTapSlop)) { + // Ignore out-of-bounds second taps. + return; + } else if (!_firstTap!.hasElapsedMinTime() || !_firstTap!.hasSameButton(event)) { + // Restart when the second tap is too close to the first (touch screens + // often detect touches intermittently), or when buttons mismatch. + _reset(); + return _trackTap(event); + } else if (onDoubleTapDown != null) { + final TapDownDetails details = TapDownDetails( + globalPosition: event.position, + localPosition: event.localPosition, + kind: getKindForPointer(event.pointer), + ); + invokeCallback('onDoubleTapDown', () => onDoubleTapDown!(details)); + } + } + _trackTap(event); + } + + void _trackTap(PointerDownEvent event) { + _stopDoubleTapTimer(); + final _TapTracker tracker = _TapTracker( + event: event, + entry: GestureBinding.instance.gestureArena.add(event.pointer, this), + doubleTapMinTime: kDoubleTapMinTime, + gestureSettings: gestureSettings, + ); + _trackers[event.pointer] = tracker; + tracker.startTrackingPointer(_handleEvent, event.transform); + } + + void _handleEvent(PointerEvent event) { + final _TapTracker tracker = _trackers[event.pointer]!; + if (event is PointerUpEvent) { + if (_firstTap == null) { + _registerFirstTap(tracker); + } else { + _registerSecondTap(tracker); + } + } else if (event is PointerMoveEvent) { + if (!tracker.isWithinGlobalTolerance(event, kDoubleTapTouchSlop)) { + _reject(tracker); + } + } else if (event is PointerCancelEvent) { + _reject(tracker); + } + } + + @override + void acceptGesture(int pointer) { } + + @override + void rejectGesture(int pointer) { + _TapTracker? tracker = _trackers[pointer]; + // If tracker isn't in the list, check if this is the first tap tracker + if (tracker == null && + _firstTap != null && + _firstTap!.pointer == pointer) { + tracker = _firstTap; + } + // If tracker is still null, we rejected ourselves already + if (tracker != null) { + _reject(tracker); + } + } + + void _reject(_TapTracker tracker) { + _trackers.remove(tracker.pointer); + tracker.entry.resolve(GestureDisposition.rejected); + _freezeTracker(tracker); + if (_firstTap != null) { + if (tracker == _firstTap) { + _reset(); + } else { + _checkCancel(); + if (_trackers.isEmpty) { + _reset(); + } + } + } + } + + @override + void dispose() { + _reset(); + super.dispose(); + } + + void _reset() { + _stopDoubleTapTimer(); + if (_firstTap != null) { + if (_trackers.isNotEmpty) { + _checkCancel(); + } + // Note, order is important below in order for the resolve -> reject logic + // to work properly. + final _TapTracker tracker = _firstTap!; + _firstTap = null; + _reject(tracker); + GestureBinding.instance.gestureArena.release(tracker.pointer); + } + _clearTrackers(); + } + + void _registerFirstTap(_TapTracker tracker) { + _startDoubleTapTimer(); + GestureBinding.instance.gestureArena.hold(tracker.pointer); + // Note, order is important below in order for the clear -> reject logic to + // work properly. + _freezeTracker(tracker); + _trackers.remove(tracker.pointer); + _clearTrackers(); + _firstTap = tracker; + } + + void _registerSecondTap(_TapTracker tracker) { + _firstTap!.entry.resolve(GestureDisposition.accepted); + tracker.entry.resolve(GestureDisposition.accepted); + _freezeTracker(tracker); + _trackers.remove(tracker.pointer); + _checkUp(tracker.initialButtons); + _reset(); + } + + void _clearTrackers() { + _trackers.values.toList().forEach(_reject); + assert(_trackers.isEmpty); + } + + void _freezeTracker(_TapTracker tracker) { + tracker.stopTrackingPointer(_handleEvent); + } + + void _startDoubleTapTimer() { + _doubleTapTimer ??= Timer(kDoubleTapTimeout, _reset); + } + + void _stopDoubleTapTimer() { + if (_doubleTapTimer != null) { + _doubleTapTimer!.cancel(); + _doubleTapTimer = null; + } + } + + void _checkUp(int buttons) { + if (onDoubleTap != null) { + invokeCallback('onDoubleTap', onDoubleTap!); + } + } + + void _checkCancel() { + if (onDoubleTapCancel != null) { + invokeCallback('onDoubleTapCancel', onDoubleTapCancel!); + } + } + + @override + String get debugDescription => 'double tap'; +} + +/// TapGesture represents a full gesture resulting from a single tap sequence, +/// as part of a [MultiTapGestureRecognizer]. Tap gestures are passive, meaning +/// that they will not preempt any other arena member in play. +class _TapGesture extends _TapTracker { + + _TapGesture({ + required this.gestureRecognizer, + required PointerEvent event, + required Duration longTapDelay, + required super.gestureSettings, + }) : _lastPosition = OffsetPair.fromEventPosition(event), + super( + event: event as PointerDownEvent, + entry: GestureBinding.instance.gestureArena.add(event.pointer, gestureRecognizer), + doubleTapMinTime: kDoubleTapMinTime, + ) { + startTrackingPointer(handleEvent, event.transform); + if (longTapDelay > Duration.zero) { + _timer = Timer(longTapDelay, () { + _timer = null; + gestureRecognizer._dispatchLongTap(event.pointer, _lastPosition); + }); + } + } + + final MultiTapGestureRecognizer gestureRecognizer; + + bool _wonArena = false; + Timer? _timer; + + OffsetPair _lastPosition; + OffsetPair? _finalPosition; + + void handleEvent(PointerEvent event) { + assert(event.pointer == pointer); + if (event is PointerMoveEvent) { + if (!isWithinGlobalTolerance(event, computeHitSlop(event.kind, gestureSettings))) { + cancel(); + } else { + _lastPosition = OffsetPair.fromEventPosition(event); + } + } else if (event is PointerCancelEvent) { + cancel(); + } else if (event is PointerUpEvent) { + stopTrackingPointer(handleEvent); + _finalPosition = OffsetPair.fromEventPosition(event); + _check(); + } + } + + @override + void stopTrackingPointer(PointerRoute route) { + _timer?.cancel(); + _timer = null; + super.stopTrackingPointer(route); + } + + void accept() { + _wonArena = true; + _check(); + } + + void reject() { + stopTrackingPointer(handleEvent); + gestureRecognizer._dispatchCancel(pointer); + } + + void cancel() { + // If we won the arena already, then entry is resolved, so resolving + // again is a no-op. But we still need to clean up our own state. + if (_wonArena) { + reject(); + } else { + entry.resolve(GestureDisposition.rejected); // eventually calls reject() + } + } + + void _check() { + if (_wonArena && _finalPosition != null) { + gestureRecognizer._dispatchTap(pointer, _finalPosition!); + } + } +} + +/// Recognizes taps on a per-pointer basis. +/// +/// [MultiTapGestureRecognizer] considers each sequence of pointer events that +/// could constitute a tap independently of other pointers: For example, down-1, +/// down-2, up-1, up-2 produces two taps, on up-1 and up-2. +/// +/// See also: +/// +/// * [TapGestureRecognizer] +class MultiTapGestureRecognizer extends GestureRecognizer { + /// Creates a multi-tap gesture recognizer. + /// + /// The [longTapDelay] defaults to [Duration.zero], which means + /// [onLongTapDown] is called immediately after [onTapDown]. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + MultiTapGestureRecognizer({ + this.longTapDelay = Duration.zero, + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + /// A pointer that might cause a tap has contacted the screen at a particular + /// location. + GestureMultiTapDownCallback? onTapDown; + + /// A pointer that will trigger a tap has stopped contacting the screen at a + /// particular location. + GestureMultiTapUpCallback? onTapUp; + + /// A tap has occurred. + GestureMultiTapCallback? onTap; + + /// The pointer that previously triggered [onTapDown] will not end up causing + /// a tap. + GestureMultiTapCancelCallback? onTapCancel; + + /// The amount of time between [onTapDown] and [onLongTapDown]. + Duration longTapDelay; + + /// A pointer that might cause a tap is still in contact with the screen at a + /// particular location after [longTapDelay]. + GestureMultiTapDownCallback? onLongTapDown; + + final Map _gestureMap = {}; + + @override + void addAllowedPointer(PointerDownEvent event) { + assert(!_gestureMap.containsKey(event.pointer)); + _gestureMap[event.pointer] = _TapGesture( + gestureRecognizer: this, + event: event, + longTapDelay: longTapDelay, + gestureSettings: gestureSettings, + ); + if (onTapDown != null) { + invokeCallback('onTapDown', () { + onTapDown!(event.pointer, TapDownDetails( + globalPosition: event.position, + localPosition: event.localPosition, + kind: event.kind, + )); + }); + } + } + + @override + void acceptGesture(int pointer) { + assert(_gestureMap.containsKey(pointer)); + _gestureMap[pointer]!.accept(); + } + + @override + void rejectGesture(int pointer) { + assert(_gestureMap.containsKey(pointer)); + _gestureMap[pointer]!.reject(); + assert(!_gestureMap.containsKey(pointer)); + } + + void _dispatchCancel(int pointer) { + assert(_gestureMap.containsKey(pointer)); + _gestureMap.remove(pointer); + if (onTapCancel != null) { + invokeCallback('onTapCancel', () => onTapCancel!(pointer)); + } + } + + void _dispatchTap(int pointer, OffsetPair position) { + assert(_gestureMap.containsKey(pointer)); + _gestureMap.remove(pointer); + if (onTapUp != null) { + invokeCallback('onTapUp', () { + onTapUp!(pointer, TapUpDetails( + kind: getKindForPointer(pointer), + localPosition: position.local, + globalPosition: position.global, + )); + }); + } + if (onTap != null) { + invokeCallback('onTap', () => onTap!(pointer)); + } + } + + void _dispatchLongTap(int pointer, OffsetPair lastPosition) { + assert(_gestureMap.containsKey(pointer)); + if (onLongTapDown != null) { + invokeCallback('onLongTapDown', () { + onLongTapDown!( + pointer, + TapDownDetails( + globalPosition: lastPosition.global, + localPosition: lastPosition.local, + kind: getKindForPointer(pointer), + ), + ); + }); + } + } + + @override + void dispose() { + final List<_TapGesture> localGestures = List<_TapGesture>.of(_gestureMap.values); + for (final _TapGesture gesture in localGestures) { + gesture.cancel(); + } + // Rejection of each gesture should cause it to be removed from our map + assert(_gestureMap.isEmpty); + super.dispose(); + } + + @override + String get debugDescription => 'multitap'; +} + +/// Signature used by [SerialTapGestureRecognizer.onSerialTapDown] for when a +/// pointer that might cause a serial tap has contacted the screen at a +/// particular location. +typedef GestureSerialTapDownCallback = void Function(SerialTapDownDetails details); + +/// Details for [GestureSerialTapDownCallback], such as the tap count within +/// the series. +/// +/// See also: +/// +/// * [SerialTapGestureRecognizer], which passes this information to its +/// [SerialTapGestureRecognizer.onSerialTapDown] callback. +class SerialTapDownDetails { + /// Creates details for a [GestureSerialTapDownCallback]. + /// + /// The `count` argument must be greater than zero. + SerialTapDownDetails({ + this.globalPosition = Offset.zero, + Offset? localPosition, + required this.kind, + this.buttons = 0, + this.count = 1, + }) : assert(count > 0), + localPosition = localPosition ?? globalPosition; + + /// The global position at which the pointer contacted the screen. + final Offset globalPosition; + + /// The local position at which the pointer contacted the screen. + final Offset localPosition; + + /// The kind of the device that initiated the event. + final PointerDeviceKind kind; + + /// Which buttons were pressed when the pointer contacted the screen. + /// + /// See also: + /// + /// * [PointerEvent.buttons], which this field reflects. + final int buttons; + + /// The number of consecutive taps that this "tap down" represents. + /// + /// This value will always be greater than zero. When the first pointer in a + /// possible series contacts the screen, this value will be `1`, the second + /// tap in a double-tap will be `2`, and so on. + /// + /// If a tap is determined to not be in the same series as the tap that + /// preceded it (e.g. because too much time elapsed between the two taps or + /// the two taps had too much distance between them), then this count will + /// reset back to `1`, and a new series will have begun. + final int count; +} + +/// Signature used by [SerialTapGestureRecognizer.onSerialTapCancel] for when a +/// pointer that previously triggered a [GestureSerialTapDownCallback] will not +/// end up completing the serial tap. +typedef GestureSerialTapCancelCallback = void Function(SerialTapCancelDetails details); + +/// Details for [GestureSerialTapCancelCallback], such as the tap count within +/// the series. +/// +/// See also: +/// +/// * [SerialTapGestureRecognizer], which passes this information to its +/// [SerialTapGestureRecognizer.onSerialTapCancel] callback. +class SerialTapCancelDetails { + /// Creates details for a [GestureSerialTapCancelCallback]. + /// + /// The `count` argument must be greater than zero. + SerialTapCancelDetails({ + this.count = 1, + }) : assert(count > 0); + + /// The number of consecutive taps that were in progress when the gesture was + /// interrupted. + /// + /// This number will match the corresponding count that was specified in + /// [SerialTapDownDetails.count] for the tap that is being canceled. See + /// that field for more information on how this count is reported. + final int count; +} + +/// Signature used by [SerialTapGestureRecognizer.onSerialTapUp] for when a +/// pointer that will trigger a serial tap has stopped contacting the screen. +typedef GestureSerialTapUpCallback = void Function(SerialTapUpDetails details); + +/// Details for [GestureSerialTapUpCallback], such as the tap count within +/// the series. +/// +/// See also: +/// +/// * [SerialTapGestureRecognizer], which passes this information to its +/// [SerialTapGestureRecognizer.onSerialTapUp] callback. +class SerialTapUpDetails { + /// Creates details for a [GestureSerialTapUpCallback]. + /// + /// The `count` argument must be greater than zero. + SerialTapUpDetails({ + this.globalPosition = Offset.zero, + Offset? localPosition, + this.kind, + this.count = 1, + }) : assert(count > 0), + localPosition = localPosition ?? globalPosition; + + /// The global position at which the pointer contacted the screen. + final Offset globalPosition; + + /// The local position at which the pointer contacted the screen. + final Offset localPosition; + + /// The kind of the device that initiated the event. + final PointerDeviceKind? kind; + + /// The number of consecutive taps that this tap represents. + /// + /// This value will always be greater than zero. When the first pointer in a + /// possible series completes its tap, this value will be `1`, the second + /// tap in a double-tap will be `2`, and so on. + /// + /// If a tap is determined to not be in the same series as the tap that + /// preceded it (e.g. because too much time elapsed between the two taps or + /// the two taps had too much distance between them), then this count will + /// reset back to `1`, and a new series will have begun. + final int count; +} + +/// Recognizes serial taps (taps in a series). +/// +/// A collection of taps are considered to be _in a series_ if they occur in +/// rapid succession in the same location (within a tolerance). The number of +/// taps in the series is its count. A double-tap, for instance, is a special +/// case of a tap series with a count of two. +/// +/// ### Gesture arena behavior +/// +/// [SerialTapGestureRecognizer] competes on all pointer events (regardless of +/// button). It will declare defeat if it determines that a gesture is not a +/// tap (e.g. if the pointer is dragged too far while it's contacting the +/// screen). It will immediately declare victory for every tap that it +/// recognizes. +/// +/// Each time a pointer contacts the screen, this recognizer will enter that +/// gesture into the arena. This means that this recognizer will yield multiple +/// winning entries in the arena for a single tap series as the series +/// progresses. +/// +/// If this recognizer loses the arena (either by declaring defeat or by +/// another recognizer declaring victory) while the pointer is contacting the +/// screen, it will fire [onSerialTapCancel], and [onSerialTapUp] will not +/// be fired. +/// +/// ### Button behavior +/// +/// A tap series is defined to have the same buttons across all taps. If a tap +/// with a different combination of buttons is delivered in the middle of a +/// series, it will "steal" the series and begin a new series, starting the +/// count over. +/// +/// ### Interleaving tap behavior +/// +/// A tap must be _completed_ in order for a subsequent tap to be considered +/// "in the same series" as that tap. Thus, if tap A is in-progress (the down +/// event has been received, but the corresponding up event has not yet been +/// received), and tap B begins (another pointer contacts the screen), tap A +/// will fire [onSerialTapCancel], and tap B will begin a new series (tap B's +/// [SerialTapDownDetails.count] will be 1). +/// +/// ### Relation to `TapGestureRecognizer` and `DoubleTapGestureRecognizer` +/// +/// [SerialTapGestureRecognizer] fires [onSerialTapDown] and [onSerialTapUp] +/// for every tap that it recognizes (passing the count in the details), +/// regardless of whether that tap is a single-tap, double-tap, etc. This +/// makes it especially useful when you want to respond to every tap in a +/// series. Contrast this with [DoubleTapGestureRecognizer], which only fires +/// if the user completes a double-tap, and [TapGestureRecognizer], which +/// _doesn't_ fire if the recognizer is competing with a +/// `DoubleTapGestureRecognizer`, and the user double-taps. +/// +/// For example, consider a list item that should be _selected_ on the first +/// tap and _cause an edit dialog to open_ on a double-tap. If you use both +/// [TapGestureRecognizer] and [DoubleTapGestureRecognizer], there are a few +/// problems: +/// +/// 1. If the user single-taps the list item, it will not select +/// the list item until after enough time has passed to rule out a +/// double-tap. +/// 2. If the user double-taps the list item, it will not select the list +/// item at all. +/// +/// The solution is to use [SerialTapGestureRecognizer] and use the tap count +/// to either select the list item or open the edit dialog. +/// +/// ### When competing with `TapGestureRecognizer` and `DoubleTapGestureRecognizer` +/// +/// Unlike [TapGestureRecognizer] and [DoubleTapGestureRecognizer], +/// [SerialTapGestureRecognizer] aggressively declares victory when it detects +/// a tap, so when it is competing with those gesture recognizers, it will beat +/// them in the arena, regardless of which recognizer entered the arena first. +class SerialTapGestureRecognizer extends GestureRecognizer { + /// Creates a serial tap gesture recognizer. + SerialTapGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + /// A pointer has contacted the screen at a particular location, which might + /// be the start of a serial tap. + /// + /// If this recognizer loses the arena before the serial tap is completed + /// (either because the gesture does not end up being a tap or because another + /// recognizer wins the arena), [onSerialTapCancel] is called next. Otherwise, + /// [onSerialTapUp] is called next. + /// + /// The [SerialTapDownDetails.count] that is passed to this callback + /// specifies the series tap count. + GestureSerialTapDownCallback? onSerialTapDown; + + /// A pointer that previously triggered [onSerialTapDown] will not end up + /// triggering the corresponding [onSerialTapUp]. + /// + /// If the user completes the serial tap, [onSerialTapUp] is called instead. + /// + /// The [SerialTapCancelDetails.count] that is passed to this callback will + /// match the [SerialTapDownDetails.count] that was passed to the + /// [onSerialTapDown] callback. + GestureSerialTapCancelCallback? onSerialTapCancel; + + /// A pointer has stopped contacting the screen at a particular location, + /// representing a serial tap. + /// + /// If the user didn't complete the tap, or if another recognizer won the + /// arena, then [onSerialTapCancel] is called instead. + /// + /// The [SerialTapUpDetails.count] that is passed to this callback specifies + /// the series tap count and will match the [SerialTapDownDetails.count] that + /// was passed to the [onSerialTapDown] callback. + GestureSerialTapUpCallback? onSerialTapUp; + + Timer? _serialTapTimer; + final List<_TapTracker> _completedTaps = <_TapTracker>[]; + final Map _gestureResolutions = {}; + _TapTracker? _pendingTap; + + /// Indicates whether this recognizer is currently tracking a pointer that's + /// in contact with the screen. + /// + /// If this is true, it implies that [onSerialTapDown] has fired, but neither + /// [onSerialTapCancel] nor [onSerialTapUp] have yet fired. + bool get isTrackingPointer => _pendingTap != null; + + @override + bool isPointerAllowed(PointerDownEvent event) { + if (onSerialTapDown == null && + onSerialTapCancel == null && + onSerialTapUp == null) { + return false; + } + return super.isPointerAllowed(event); + } + + @override + void addAllowedPointer(PointerDownEvent event) { + if ((_completedTaps.isNotEmpty && !_representsSameSeries(_completedTaps.last, event)) + || _pendingTap != null) { + _reset(); + } + _trackTap(event); + } + + bool _representsSameSeries(_TapTracker tap, PointerDownEvent event) { + return tap.hasElapsedMinTime() // touch screens often detect touches intermittently + && tap.hasSameButton(event) + && tap.isWithinGlobalTolerance(event, kDoubleTapSlop); + } + + void _trackTap(PointerDownEvent event) { + _stopSerialTapTimer(); + if (onSerialTapDown != null) { + final SerialTapDownDetails details = SerialTapDownDetails( + globalPosition: event.position, + localPosition: event.localPosition, + kind: getKindForPointer(event.pointer), + buttons: event.buttons, + count: _completedTaps.length + 1, + ); + invokeCallback('onSerialTapDown', () => onSerialTapDown!(details)); + } + final _TapTracker tracker = _TapTracker( + gestureSettings: gestureSettings, + event: event, + entry: GestureBinding.instance.gestureArena.add(event.pointer, this), + doubleTapMinTime: kDoubleTapMinTime, + ); + assert(_pendingTap == null); + _pendingTap = tracker; + tracker.startTrackingPointer(_handleEvent, event.transform); + } + + void _handleEvent(PointerEvent event) { + assert(_pendingTap != null); + assert(_pendingTap!.pointer == event.pointer); + final _TapTracker tracker = _pendingTap!; + if (event is PointerUpEvent) { + _registerTap(event, tracker); + } else if (event is PointerMoveEvent) { + if (!tracker.isWithinGlobalTolerance(event, kDoubleTapTouchSlop)) { + _reset(); + } + } else if (event is PointerCancelEvent) { + _reset(); + } + } + + @override + void acceptGesture(int pointer) { + assert(_pendingTap != null); + assert(_pendingTap!.pointer == pointer); + _gestureResolutions[pointer] = GestureDisposition.accepted; + } + + @override + void rejectGesture(int pointer) { + _gestureResolutions[pointer] = GestureDisposition.rejected; + _reset(); + } + + void _rejectPendingTap() { + assert(_pendingTap != null); + final _TapTracker tracker = _pendingTap!; + _pendingTap = null; + // Order is important here; the `resolve` call can yield a re-entrant + // `reset()`, so we need to check cancel here while we can trust the + // length of our _completedTaps list. + _checkCancel(_completedTaps.length + 1); + if (!_gestureResolutions.containsKey(tracker.pointer)) { + tracker.entry.resolve(GestureDisposition.rejected); + } + _stopTrackingPointer(tracker); + } + + @override + void dispose() { + _reset(); + super.dispose(); + } + + void _reset() { + if (_pendingTap != null) { + _rejectPendingTap(); + } + _pendingTap = null; + _completedTaps.clear(); + _gestureResolutions.clear(); + _stopSerialTapTimer(); + } + + void _registerTap(PointerUpEvent event, _TapTracker tracker) { + assert(tracker == _pendingTap); + assert(tracker.pointer == event.pointer); + _startSerialTapTimer(); + assert(_gestureResolutions[event.pointer] != GestureDisposition.rejected); + if (!_gestureResolutions.containsKey(event.pointer)) { + tracker.entry.resolve(GestureDisposition.accepted); + } + assert(_gestureResolutions[event.pointer] == GestureDisposition.accepted); + _stopTrackingPointer(tracker); + // Note, order is important below in order for the clear -> reject logic to + // work properly. + _pendingTap = null; + _checkUp(event, tracker); + _completedTaps.add(tracker); + } + + void _stopTrackingPointer(_TapTracker tracker) { + tracker.stopTrackingPointer(_handleEvent); + } + + void _startSerialTapTimer() { + _serialTapTimer ??= Timer(kDoubleTapTimeout, _reset); + } + + void _stopSerialTapTimer() { + if (_serialTapTimer != null) { + _serialTapTimer!.cancel(); + _serialTapTimer = null; + } + } + + void _checkUp(PointerUpEvent event, _TapTracker tracker) { + if (onSerialTapUp != null) { + final SerialTapUpDetails details = SerialTapUpDetails( + globalPosition: event.position, + localPosition: event.localPosition, + kind: getKindForPointer(tracker.pointer), + count: _completedTaps.length + 1, + ); + invokeCallback('onSerialTapUp', () => onSerialTapUp!(details)); + } + } + + void _checkCancel(int count) { + if (onSerialTapCancel != null) { + final SerialTapCancelDetails details = SerialTapCancelDetails( + count: count, + ); + invokeCallback('onSerialTapCancel', () => onSerialTapCancel!(details)); + } + } + + @override + String get debugDescription => 'serial tap'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/pointer_router.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/pointer_router.dart new file mode 100644 index 0000000000000000000000000000000000000000..97df90d8280d832b4591fc571c66e256a95311bc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/pointer_router.dart @@ -0,0 +1,147 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'package:flutter/foundation.dart'; + +import 'events.dart'; + +export 'package:vector_math/vector_math_64.dart' show Matrix4; + +export 'events.dart' show PointerEvent; + +/// A callback that receives a [PointerEvent] +typedef PointerRoute = void Function(PointerEvent event); + +/// A routing table for [PointerEvent] events. +class PointerRouter { + final Map> _routeMap = >{}; + final Map _globalRoutes = {}; + + /// Adds a route to the routing table. + /// + /// Whenever this object routes a [PointerEvent] corresponding to + /// pointer, call route. + /// + /// Routes added reentrantly within [PointerRouter.route] will take effect when + /// routing the next event. + void addRoute(int pointer, PointerRoute route, [Matrix4? transform]) { + final Map routes = _routeMap.putIfAbsent( + pointer, + () => {}, + ); + assert(!routes.containsKey(route)); + routes[route] = transform; + } + + /// Removes a route from the routing table. + /// + /// No longer call route when routing a [PointerEvent] corresponding to + /// pointer. Requires that this route was previously added to the router. + /// + /// Routes removed reentrantly within [PointerRouter.route] will take effect + /// immediately. + void removeRoute(int pointer, PointerRoute route) { + assert(_routeMap.containsKey(pointer)); + final Map routes = _routeMap[pointer]!; + assert(routes.containsKey(route)); + routes.remove(route); + if (routes.isEmpty) { + _routeMap.remove(pointer); + } + } + + /// Adds a route to the global entry in the routing table. + /// + /// Whenever this object routes a [PointerEvent], call route. + /// + /// Routes added reentrantly within [PointerRouter.route] will take effect when + /// routing the next event. + void addGlobalRoute(PointerRoute route, [Matrix4? transform]) { + assert(!_globalRoutes.containsKey(route)); + _globalRoutes[route] = transform; + } + + /// Removes a route from the global entry in the routing table. + /// + /// No longer call route when routing a [PointerEvent]. Requires that this + /// route was previously added via [addGlobalRoute]. + /// + /// Routes removed reentrantly within [PointerRouter.route] will take effect + /// immediately. + void removeGlobalRoute(PointerRoute route) { + assert(_globalRoutes.containsKey(route)); + _globalRoutes.remove(route); + } + + /// The number of global routes that have been registered. + /// + /// This is valid in debug builds only. In release builds, this will throw an + /// [UnsupportedError]. + int get debugGlobalRouteCount { + int? count; + assert(() { + count = _globalRoutes.length; + return true; + }()); + if (count != null) { + return count!; + } + throw UnsupportedError('debugGlobalRouteCount is not supported in release builds'); + } + + @pragma('vm:notify-debugger-on-exception') + void _dispatch(PointerEvent event, PointerRoute route, Matrix4? transform) { + try { + event = event.transformed(transform); + route(event); + } catch (exception, stack) { + InformationCollector? collector; + assert(() { + collector = () => [ + DiagnosticsProperty('router', this, level: DiagnosticLevel.debug), + DiagnosticsProperty('route', route, level: DiagnosticLevel.debug), + DiagnosticsProperty('event', event, level: DiagnosticLevel.debug), + ]; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'gesture library', + context: ErrorDescription('while routing a pointer event'), + informationCollector: collector, + )); + } + } + + /// Calls the routes registered for this pointer event. + /// + /// Routes are called in the order in which they were added to the + /// PointerRouter object. + void route(PointerEvent event) { + final Map? routes = _routeMap[event.pointer]; + final Map copiedGlobalRoutes = Map.of(_globalRoutes); + if (routes != null) { + _dispatchEventToRoutes( + event, + routes, + Map.of(routes), + ); + } + _dispatchEventToRoutes(event, _globalRoutes, copiedGlobalRoutes); + } + + void _dispatchEventToRoutes( + PointerEvent event, + Map referenceRoutes, + Map copiedRoutes, + ) { + copiedRoutes.forEach((PointerRoute route, Matrix4? transform) { + if (referenceRoutes.containsKey(route)) { + _dispatch(event, route, transform); + } + }); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/pointer_signal_resolver.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/pointer_signal_resolver.dart new file mode 100644 index 0000000000000000000000000000000000000000..2e4b6709d337193da54facaa0bb63fda07097f02 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/pointer_signal_resolver.dart @@ -0,0 +1,123 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'events.dart'; + +export 'events.dart' show PointerSignalEvent; + +/// The callback to register with a [PointerSignalResolver] to express +/// interest in a pointer signal event. +typedef PointerSignalResolvedCallback = void Function(PointerSignalEvent event); + +bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) { + return (event1.original ?? event1) == (event2.original ?? event2); +} + +/// Mediates disputes over which listener should handle pointer signal events +/// when multiple listeners wish to handle those events. +/// +/// Pointer signals (such as [PointerScrollEvent]) are immediate, so unlike +/// events that participate in the gesture arena, pointer signals always +/// resolve at the end of event dispatch. Yet if objects interested in handling +/// these signal events were to handle them directly, it would cause issues +/// such as multiple [Scrollable] widgets in the widget hierarchy responding +/// to the same mouse wheel event. Using this class, these events will only +/// be dispatched to the first registered handler, which will in turn +/// correspond to the widget that's deepest in the widget hierarchy. +/// +/// To use this class, objects should register their event handler like so: +/// +/// ```dart +/// void handleSignalEvent(PointerSignalEvent event) { +/// GestureBinding.instance.pointerSignalResolver.register(event, (PointerSignalEvent event) { +/// // handle the event... +/// }); +/// } +/// ``` +/// +/// {@tool dartpad} +/// Here is an example that demonstrates the effect of not using the resolver +/// versus using it. +/// +/// When this example is set to _not_ use the resolver, then triggering the +/// mouse wheel over the outer box will cause only the outer box to change +/// color, but triggering the mouse wheel over the inner box will cause _both_ +/// the outer and the inner boxes to change color (because they're both +/// receiving the event). +/// +/// When this example is set to _use_ the resolver, then only the box located +/// directly under the cursor will change color when the mouse wheel is +/// triggered. +/// +/// ** See code in examples/api/lib/gestures/pointer_signal_resolver/pointer_signal_resolver.0.dart ** +/// {@end-tool} +class PointerSignalResolver { + PointerSignalResolvedCallback? _firstRegisteredCallback; + + PointerSignalEvent? _currentEvent; + + /// Registers interest in handling [event]. + /// + /// This method may be called multiple times (typically from different parts + /// of the widget hierarchy) for the same `event`, with different `callback`s, + /// as the event is being dispatched across the tree. Once the dispatching is + /// complete, the [GestureBinding] calls [resolve], and the first registered + /// callback is called. + /// + /// The `callback` is invoked with one argument, the `event`. + /// + /// Once the [register] method has been called with a particular `event`, it + /// must not be called for other `event`s until after [resolve] has been + /// called. Only one event disambiguation can be in flight at a time. In + /// normal use this is achieved by only registering callbacks for an event as + /// it is actively being dispatched (for example, in + /// [Listener.onPointerSignal]). + /// + /// See the documentation for the [PointerSignalResolver] class for an example + /// of using this method. + void register(PointerSignalEvent event, PointerSignalResolvedCallback callback) { + assert(_currentEvent == null || _isSameEvent(_currentEvent!, event)); + if (_firstRegisteredCallback != null) { + return; + } + _currentEvent = event; + _firstRegisteredCallback = callback; + } + + /// Resolves the event, calling the first registered callback if there was + /// one. + /// + /// This is called by the [GestureBinding] after the framework has finished + /// dispatching the pointer signal event. + @pragma('vm:notify-debugger-on-exception') + void resolve(PointerSignalEvent event) { + if (_firstRegisteredCallback == null) { + assert(_currentEvent == null); + return; + } + assert(_isSameEvent(_currentEvent!, event)); + try { + _firstRegisteredCallback!(_currentEvent!); + } catch (exception, stack) { + InformationCollector? collector; + assert(() { + collector = () => [ + DiagnosticsProperty('Event', event, style: DiagnosticsTreeStyle.errorProperty), + ]; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'gesture library', + context: ErrorDescription('while resolving a PointerSignalEvent'), + informationCollector: collector, + )); + } + _firstRegisteredCallback = null; + _currentEvent = null; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/recognizer.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/recognizer.dart new file mode 100644 index 0000000000000000000000000000000000000000..9a9ecb4b9ae0d086240e9b166d01418359485f05 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/recognizer.dart @@ -0,0 +1,804 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'dart:async'; +import 'dart:collection'; + +import 'package:flutter/foundation.dart'; + +import 'arena.dart'; +import 'binding.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'events.dart'; +import 'pointer_router.dart'; +import 'team.dart'; + +export 'dart:ui' show Offset, PointerDeviceKind; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; +export 'package:vector_math/vector_math_64.dart' show Matrix4; + +export 'arena.dart' show GestureDisposition; +export 'events.dart' show PointerDownEvent, PointerEvent, PointerPanZoomStartEvent; +export 'gesture_settings.dart' show DeviceGestureSettings; +export 'team.dart' show GestureArenaTeam; + +/// Generic signature for callbacks passed to +/// [GestureRecognizer.invokeCallback]. This allows the +/// [GestureRecognizer.invokeCallback] mechanism to be generically used with +/// anonymous functions that return objects of particular types. +typedef RecognizerCallback = T Function(); + +/// Configuration of offset passed to [DragStartDetails]. +/// +/// See also: +/// +/// * [DragGestureRecognizer.dragStartBehavior], which gives an example for the +/// different behaviors. +enum DragStartBehavior { + /// Set the initial offset at the position where the first down event was + /// detected. + down, + + /// Set the initial position at the position where this gesture recognizer + /// won the arena. + start, +} + +/// Configuration of multi-finger drag strategy on multi-touch devices. +/// +/// When dragging with only one finger, there's no difference in behavior +/// between the two settings. +/// +/// Used by [DragGestureRecognizer.multitouchDragStrategy]. +enum MultitouchDragStrategy { + /// Only the latest active pointer is tracked by the recognizer. + /// + /// If the tracked pointer is released, the latest of the remaining active + /// pointers will continue to be tracked. + /// + /// This is the behavior typically seen on Android. + latestPointer, + + /// All active pointers will be tracked together. The scrolling offset + /// is the sum of the offsets of all active pointers. + /// + /// When a [Scrollable] drives scrolling by this drag strategy, the scrolling + /// speed will double or triple, depending on how many fingers are dragging + /// at the same time. + sumAllPointers, +} + +/// Signature for `allowedButtonsFilter` in [GestureRecognizer]. +/// Used to filter the input buttons of incoming pointer events. +/// The parameter `buttons` comes from [PointerEvent.buttons]. +typedef AllowedButtonsFilter = bool Function(int buttons); + +/// The base class that all gesture recognizers inherit from. +/// +/// Provides a basic API that can be used by classes that work with +/// gesture recognizers but don't care about the specific details of +/// the gestures recognizers themselves. +/// +/// See also: +/// +/// * [GestureDetector], the widget that is used to detect built-in gestures. +/// * [RawGestureDetector], the widget that is used to detect custom gestures. +/// * [debugPrintRecognizerCallbacksTrace], a flag that can be set to help +/// debug issues with gesture recognizers. +abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableTreeMixin { + /// Initializes the gesture recognizer. + /// + /// The argument is optional and is only used for debug purposes (e.g. in the + /// [toString] serialization). + /// + /// {@template flutter.gestures.GestureRecognizer.supportedDevices} + /// It's possible to limit this recognizer to a specific set of [PointerDeviceKind]s + /// by providing the optional [supportedDevices] argument. If [supportedDevices] is null, + /// the recognizer will accept pointer events from all device kinds. + /// {@endtemplate} + GestureRecognizer({ + this.debugOwner, + this.supportedDevices, + AllowedButtonsFilter? allowedButtonsFilter, + }) : _allowedButtonsFilter = allowedButtonsFilter ?? _defaultButtonAcceptBehavior { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/gestures.dart', + className: '$GestureRecognizer', + object: this, + ); + } + } + + /// The recognizer's owner. + /// + /// This is used in the [toString] serialization to report the object for which + /// this gesture recognizer was created, to aid in debugging. + final Object? debugOwner; + + /// Optional device specific configuration for device gestures that will + /// take precedence over framework defaults. + DeviceGestureSettings? gestureSettings; + + /// The kind of devices that are allowed to be recognized as provided by + /// `supportedDevices` in the constructor, or the currently deprecated `kind`. + /// These cannot both be set. If both are null, events from all device kinds will be + /// tracked and recognized. + Set? supportedDevices; + + /// {@template flutter.gestures.multidrag._allowedButtonsFilter} + /// Called when interaction starts. This limits the dragging behavior + /// for custom clicks (such as scroll click). Its parameter comes + /// from [PointerEvent.buttons]. + /// + /// Due to how [kPrimaryButton], [kSecondaryButton], etc., use integers, + /// bitwise operations can help filter how buttons are pressed. + /// For example, if someone simultaneously presses the primary and secondary + /// buttons, the default behavior will return false. The following code + /// accepts any button press with primary: + /// `(int buttons) => buttons & kPrimaryButton != 0`. + /// + /// When value is `(int buttons) => false`, allow no interactions. + /// When value is `(int buttons) => true`, allow all interactions. + /// + /// Defaults to all buttons. + /// {@endtemplate} + final AllowedButtonsFilter _allowedButtonsFilter; + + // The default value for [allowedButtonsFilter]. + // Accept any input. + static bool _defaultButtonAcceptBehavior(int buttons) => true; + + /// Holds a mapping between pointer IDs and the kind of devices they are + /// coming from. + final Map _pointerToKind = {}; + + /// Registers a new pointer pan/zoom that might be relevant to this gesture + /// detector. + /// + /// A pointer pan/zoom is a stream of events that conveys data covering + /// pan, zoom, and rotate data from a multi-finger trackpad gesture. + /// + /// The owner of this gesture recognizer calls addPointerPanZoom() with the + /// PointerPanZoomStartEvent of each pointer that should be considered for + /// this gesture. + /// + /// It's the GestureRecognizer's responsibility to then add itself + /// to the global pointer router (see [PointerRouter]) to receive + /// subsequent events for this pointer, and to add the pointer to + /// the global gesture arena manager (see [GestureArenaManager]) to track + /// that pointer. + /// + /// This method is called for each and all pointers being added. In + /// most cases, you want to override [addAllowedPointerPanZoom] instead. + void addPointerPanZoom(PointerPanZoomStartEvent event) { + _pointerToKind[event.pointer] = event.kind; + if (isPointerPanZoomAllowed(event)) { + addAllowedPointerPanZoom(event); + } else { + handleNonAllowedPointerPanZoom(event); + } + } + + /// Registers a new pointer pan/zoom that's been checked to be allowed by this + /// gesture recognizer. + /// + /// Subclasses of [GestureRecognizer] are supposed to override this method + /// instead of [addPointerPanZoom] because [addPointerPanZoom] will be called for each + /// pointer being added while [addAllowedPointerPanZoom] is only called for pointers + /// that are allowed by this recognizer. + @protected + void addAllowedPointerPanZoom(PointerPanZoomStartEvent event) { } + + /// Registers a new pointer that might be relevant to this gesture + /// detector. + /// + /// The owner of this gesture recognizer calls addPointer() with the + /// PointerDownEvent of each pointer that should be considered for + /// this gesture. + /// + /// It's the GestureRecognizer's responsibility to then add itself + /// to the global pointer router (see [PointerRouter]) to receive + /// subsequent events for this pointer, and to add the pointer to + /// the global gesture arena manager (see [GestureArenaManager]) to track + /// that pointer. + /// + /// This method is called for each and all pointers being added. In + /// most cases, you want to override [addAllowedPointer] instead. + void addPointer(PointerDownEvent event) { + _pointerToKind[event.pointer] = event.kind; + if (isPointerAllowed(event)) { + addAllowedPointer(event); + } else { + handleNonAllowedPointer(event); + } + } + + /// Registers a new pointer that's been checked to be allowed by this gesture + /// recognizer. + /// + /// Subclasses of [GestureRecognizer] are supposed to override this method + /// instead of [addPointer] because [addPointer] will be called for each + /// pointer being added while [addAllowedPointer] is only called for pointers + /// that are allowed by this recognizer. + @protected + void addAllowedPointer(PointerDownEvent event) { } + + /// Handles a pointer being added that's not allowed by this recognizer. + /// + /// Subclasses can override this method and reject the gesture. + /// + /// See: + /// - [OneSequenceGestureRecognizer.handleNonAllowedPointer]. + @protected + void handleNonAllowedPointer(PointerDownEvent event) { } + + /// Checks whether or not a pointer is allowed to be tracked by this recognizer. + @protected + bool isPointerAllowed(PointerDownEvent event) { + return (supportedDevices == null || + supportedDevices!.contains(event.kind)) && + _allowedButtonsFilter(event.buttons); + } + + /// Handles a pointer pan/zoom being added that's not allowed by this recognizer. + /// + /// Subclasses can override this method and reject the gesture. + @protected + void handleNonAllowedPointerPanZoom(PointerPanZoomStartEvent event) { } + + /// Checks whether or not a pointer pan/zoom is allowed to be tracked by this recognizer. + @protected + bool isPointerPanZoomAllowed(PointerPanZoomStartEvent event) { + return supportedDevices == null || supportedDevices!.contains(event.kind); + } + + /// For a given pointer ID, returns the device kind associated with it. + /// + /// The pointer ID is expected to be a valid one i.e. an event was received + /// with that pointer ID. + @protected + PointerDeviceKind getKindForPointer(int pointer) { + assert(_pointerToKind.containsKey(pointer)); + return _pointerToKind[pointer]!; + } + + /// Releases any resources used by the object. + /// + /// This method is called by the owner of this gesture recognizer + /// when the object is no longer needed (e.g. when a gesture + /// recognizer is being unregistered from a [GestureDetector], the + /// GestureDetector widget calls this method). + @mustCallSuper + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + } + + /// Returns a very short pretty description of the gesture that the + /// recognizer looks for, like 'tap' or 'horizontal drag'. + String get debugDescription; + + /// Invoke a callback provided by the application, catching and logging any + /// exceptions. + /// + /// The `name` argument is ignored except when reporting exceptions. + /// + /// The `debugReport` argument is optional and is used when + /// [debugPrintRecognizerCallbacksTrace] is true. If specified, it must be a + /// callback that returns a string describing useful debugging information, + /// e.g. the arguments passed to the callback. + @protected + @pragma('vm:notify-debugger-on-exception') + T? invokeCallback(String name, RecognizerCallback callback, { String Function()? debugReport }) { + T? result; + try { + assert(() { + if (debugPrintRecognizerCallbacksTrace) { + final String? report = debugReport != null ? debugReport() : null; + // The 19 in the line below is the width of the prefix used by + // _debugLogDiagnostic in arena.dart. + final String prefix = debugPrintGestureArenaDiagnostics ? '${' ' * 19}❙ ' : ''; + debugPrint('$prefix$this calling $name callback.${ (report?.isNotEmpty ?? false) ? " $report" : "" }'); + } + return true; + }()); + result = callback(); + } catch (exception, stack) { + InformationCollector? collector; + assert(() { + collector = () => [ + StringProperty('Handler', name), + DiagnosticsProperty('Recognizer', this, style: DiagnosticsTreeStyle.errorProperty), + ]; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'gesture', + context: ErrorDescription('while handling a gesture'), + informationCollector: collector, + )); + } + return result; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('debugOwner', debugOwner, defaultValue: null)); + } +} + +/// Base class for gesture recognizers that can only recognize one +/// gesture at a time. For example, a single [TapGestureRecognizer] +/// can never recognize two taps happening simultaneously, even if +/// multiple pointers are placed on the same widget. +/// +/// This is in contrast to, for instance, [MultiTapGestureRecognizer], +/// which manages each pointer independently and can consider multiple +/// simultaneous touches to each result in a separate tap. +abstract class OneSequenceGestureRecognizer extends GestureRecognizer { + /// Initialize the object. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + OneSequenceGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + final Map _entries = {}; + final Set _trackedPointers = HashSet(); + + @override + @protected + void addAllowedPointer(PointerDownEvent event) { + startTrackingPointer(event.pointer, event.transform); + } + + @override + @protected + void handleNonAllowedPointer(PointerDownEvent event) { + resolve(GestureDisposition.rejected); + } + + /// Called when a pointer event is routed to this recognizer. + /// + /// This will be called for every pointer event while the pointer is being + /// tracked. Typically, this recognizer will start tracking the pointer in + /// [addAllowedPointer], which means that [handleEvent] will be called + /// starting with the [PointerDownEvent] that was passed to [addAllowedPointer]. + /// + /// See also: + /// + /// * [startTrackingPointer], which causes pointer events to be routed to + /// this recognizer. + /// * [stopTrackingPointer], which stops events from being routed to this + /// recognizer. + /// * [stopTrackingIfPointerNoLongerDown], which conditionally stops events + /// from being routed to this recognizer. + @protected + void handleEvent(PointerEvent event); + + @override + void acceptGesture(int pointer) { } + + @override + void rejectGesture(int pointer) { } + + /// Called when the number of pointers this recognizer is tracking changes from one to zero. + /// + /// The given pointer ID is the ID of the last pointer this recognizer was + /// tracking. + @protected + void didStopTrackingLastPointer(int pointer); + + /// Resolves this recognizer's participation in each gesture arena with the + /// given disposition. + @protected + @mustCallSuper + void resolve(GestureDisposition disposition) { + final List localEntries = List.of(_entries.values); + _entries.clear(); + for (final GestureArenaEntry entry in localEntries) { + entry.resolve(disposition); + } + } + + /// Resolves this recognizer's participation in the given gesture arena with + /// the given disposition. + @protected + @mustCallSuper + void resolvePointer(int pointer, GestureDisposition disposition) { + final GestureArenaEntry? entry = _entries[pointer]; + if (entry != null) { + _entries.remove(pointer); + entry.resolve(disposition); + } + } + + @override + void dispose() { + resolve(GestureDisposition.rejected); + for (final int pointer in _trackedPointers) { + GestureBinding.instance.pointerRouter.removeRoute(pointer, handleEvent); + } + _trackedPointers.clear(); + assert(_entries.isEmpty); + super.dispose(); + } + + /// The team that this recognizer belongs to, if any. + /// + /// If [team] is null, this recognizer competes directly in the + /// [GestureArenaManager] to recognize a sequence of pointer events as a + /// gesture. If [team] is non-null, this recognizer competes in the arena in + /// a group with other recognizers on the same team. + /// + /// A recognizer can be assigned to a team only when it is not participating + /// in the arena. For example, a common time to assign a recognizer to a team + /// is shortly after creating the recognizer. + GestureArenaTeam? get team => _team; + GestureArenaTeam? _team; + /// The [team] can only be set once. + set team(GestureArenaTeam? value) { + assert(value != null); + assert(_entries.isEmpty); + assert(_trackedPointers.isEmpty); + assert(_team == null); + _team = value; + } + + GestureArenaEntry _addPointerToArena(int pointer) { + if (_team != null) { + return _team!.add(pointer, this); + } + return GestureBinding.instance.gestureArena.add(pointer, this); + } + + /// Causes events related to the given pointer ID to be routed to this recognizer. + /// + /// The pointer events are transformed according to `transform` and then delivered + /// to [handleEvent]. The value for the `transform` argument is usually obtained + /// from [PointerDownEvent.transform] to transform the events from the global + /// coordinate space into the coordinate space of the event receiver. It may be + /// null if no transformation is necessary. + /// + /// Use [stopTrackingPointer] to remove the route added by this function. + /// + /// This method also adds this recognizer (or its [team] if it's non-null) to + /// the gesture arena for the specified pointer. + /// + /// This is called by [OneSequenceGestureRecognizer.addAllowedPointer]. + @protected + void startTrackingPointer(int pointer, [Matrix4? transform]) { + GestureBinding.instance.pointerRouter.addRoute(pointer, handleEvent, transform); + _trackedPointers.add(pointer); + // TODO(goderbauer): Enable assert after recognizers properly clean up their defunct `_entries`, see https://github.com/flutter/flutter/issues/117356. + // assert(!_entries.containsKey(pointer)); + _entries[pointer] = _addPointerToArena(pointer); + } + + /// Stops events related to the given pointer ID from being routed to this recognizer. + /// + /// If this function reduces the number of tracked pointers to zero, it will + /// call [didStopTrackingLastPointer] synchronously. + /// + /// Use [startTrackingPointer] to add the routes in the first place. + @protected + void stopTrackingPointer(int pointer) { + if (_trackedPointers.contains(pointer)) { + GestureBinding.instance.pointerRouter.removeRoute(pointer, handleEvent); + _trackedPointers.remove(pointer); + if (_trackedPointers.isEmpty) { + didStopTrackingLastPointer(pointer); + } + } + } + + /// Stops tracking the pointer associated with the given event if the event is + /// a [PointerUpEvent] or a [PointerCancelEvent] event. + @protected + void stopTrackingIfPointerNoLongerDown(PointerEvent event) { + if (event is PointerUpEvent || event is PointerCancelEvent || event is PointerPanZoomEndEvent) { + stopTrackingPointer(event.pointer); + } + } +} + +/// The possible states of a [PrimaryPointerGestureRecognizer]. +/// +/// The recognizer advances from [ready] to [possible] when it starts tracking a +/// primary pointer. Where it advances from there depends on how the gesture is +/// resolved for that pointer: +/// +/// * If the primary pointer is resolved by the gesture winning the arena, the +/// recognizer stays in the [possible] state as long as it continues to track +/// a pointer. +/// * If the primary pointer is resolved by the gesture being rejected and +/// losing the arena, the recognizer's state advances to [defunct]. +/// +/// Once the recognizer has stopped tracking any remaining pointers, the +/// recognizer returns to [ready]. +enum GestureRecognizerState { + /// The recognizer is ready to start recognizing a gesture. + ready, + + /// The sequence of pointer events seen thus far is consistent with the + /// gesture the recognizer is attempting to recognize but the gesture has not + /// been accepted definitively. + possible, + + /// Further pointer events cannot cause this recognizer to recognize the + /// gesture until the recognizer returns to the [ready] state (typically when + /// all the pointers the recognizer is tracking are removed from the screen). + defunct, +} + +/// A base class for gesture recognizers that track a single primary pointer. +/// +/// Gestures based on this class will stop tracking the gesture if the primary +/// pointer travels beyond [preAcceptSlopTolerance] or [postAcceptSlopTolerance] +/// pixels from the original contact point of the gesture. +/// +/// If the [preAcceptSlopTolerance] was breached before the gesture was accepted +/// in the gesture arena, the gesture will be rejected. +abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecognizer { + /// Initializes the [deadline] field during construction of subclasses. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + PrimaryPointerGestureRecognizer({ + this.deadline, + this.preAcceptSlopTolerance = kTouchSlop, + this.postAcceptSlopTolerance = kTouchSlop, + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }) : assert( + preAcceptSlopTolerance == null || preAcceptSlopTolerance >= 0, + 'The preAcceptSlopTolerance must be positive or null', + ), + assert( + postAcceptSlopTolerance == null || postAcceptSlopTolerance >= 0, + 'The postAcceptSlopTolerance must be positive or null', + ); + + /// If non-null, the recognizer will call [didExceedDeadline] after this + /// amount of time has elapsed since starting to track the primary pointer. + /// + /// The [didExceedDeadline] will not be called if the primary pointer is + /// accepted, rejected, or all pointers are up or canceled before [deadline]. + final Duration? deadline; + + /// The maximum distance in logical pixels the gesture is allowed to drift + /// from the initial touch down position before the gesture is accepted. + /// + /// Drifting past the allowed slop amount causes the gesture to be rejected. + /// + /// Can be null to indicate that the gesture can drift for any distance. + /// Defaults to 18 logical pixels. + final double? preAcceptSlopTolerance; + + /// The maximum distance in logical pixels the gesture is allowed to drift + /// after the gesture has been accepted. + /// + /// Drifting past the allowed slop amount causes the gesture to stop tracking + /// and signaling subsequent callbacks. + /// + /// Can be null to indicate that the gesture can drift for any distance. + /// Defaults to 18 logical pixels. + final double? postAcceptSlopTolerance; + + /// The current state of the recognizer. + /// + /// See [GestureRecognizerState] for a description of the states. + GestureRecognizerState get state => _state; + GestureRecognizerState _state = GestureRecognizerState.ready; + + /// The ID of the primary pointer this recognizer is tracking. + /// + /// If this recognizer is no longer tracking any pointers, this field holds + /// the ID of the primary pointer this recognizer was most recently tracking. + /// This enables the recognizer to know which pointer it was most recently + /// tracking when [acceptGesture] or [rejectGesture] is called (which may be + /// called after the recognizer is no longer tracking a pointer if, e.g. + /// [GestureArenaManager.hold] has been called, or if there are other + /// recognizers keeping the arena open). + int? get primaryPointer => _primaryPointer; + int? _primaryPointer; + + /// The location at which the primary pointer contacted the screen. + /// + /// This will only be non-null while this recognizer is tracking at least + /// one pointer. + OffsetPair? get initialPosition => _initialPosition; + OffsetPair? _initialPosition; + + // Whether this pointer is accepted by winning the arena or as defined by + // a subclass calling acceptGesture. + bool _gestureAccepted = false; + Timer? _timer; + + @override + void addAllowedPointer(PointerDownEvent event) { + super.addAllowedPointer(event); + if (state == GestureRecognizerState.ready) { + _state = GestureRecognizerState.possible; + _primaryPointer = event.pointer; + _initialPosition = OffsetPair(local: event.localPosition, global: event.position); + if (deadline != null) { + _timer = Timer(deadline!, () => didExceedDeadlineWithEvent(event)); + } + } + } + + @override + void handleNonAllowedPointer(PointerDownEvent event) { + if (!_gestureAccepted) { + super.handleNonAllowedPointer(event); + } + } + + @override + void handleEvent(PointerEvent event) { + assert(state != GestureRecognizerState.ready); + if (state == GestureRecognizerState.possible && event.pointer == primaryPointer) { + final bool isPreAcceptSlopPastTolerance = + !_gestureAccepted && + preAcceptSlopTolerance != null && + _getGlobalDistance(event) > preAcceptSlopTolerance!; + final bool isPostAcceptSlopPastTolerance = + _gestureAccepted && + postAcceptSlopTolerance != null && + _getGlobalDistance(event) > postAcceptSlopTolerance!; + + if (event is PointerMoveEvent && (isPreAcceptSlopPastTolerance || isPostAcceptSlopPastTolerance)) { + resolve(GestureDisposition.rejected); + stopTrackingPointer(primaryPointer!); + } else { + handlePrimaryPointer(event); + } + } + stopTrackingIfPointerNoLongerDown(event); + } + + /// Override to provide behavior for the primary pointer when the gesture is still possible. + @protected + void handlePrimaryPointer(PointerEvent event); + + /// Override to be notified when [deadline] is exceeded. + /// + /// You must override this method or [didExceedDeadlineWithEvent] if you + /// supply a [deadline]. Subclasses that override this method must _not_ + /// call `super.didExceedDeadline()`. + @protected + void didExceedDeadline() { + assert(deadline == null); + } + + /// Same as [didExceedDeadline] but receives the [event] that initiated the + /// gesture. + /// + /// You must override this method or [didExceedDeadline] if you supply a + /// [deadline]. Subclasses that override this method must _not_ call + /// `super.didExceedDeadlineWithEvent(event)`. + @protected + void didExceedDeadlineWithEvent(PointerDownEvent event) { + didExceedDeadline(); + } + + @override + void acceptGesture(int pointer) { + if (pointer == primaryPointer) { + _stopTimer(); + _gestureAccepted = true; + } + } + + @override + void rejectGesture(int pointer) { + if (pointer == primaryPointer && state == GestureRecognizerState.possible) { + _stopTimer(); + _state = GestureRecognizerState.defunct; + } + } + + @override + void didStopTrackingLastPointer(int pointer) { + assert(state != GestureRecognizerState.ready); + _stopTimer(); + _state = GestureRecognizerState.ready; + _initialPosition = null; + _gestureAccepted = false; + } + + @override + void dispose() { + _stopTimer(); + super.dispose(); + } + + void _stopTimer() { + if (_timer != null) { + _timer!.cancel(); + _timer = null; + } + } + + double _getGlobalDistance(PointerEvent event) { + final Offset offset = event.position - initialPosition!.global; + return offset.distance; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty('state', state)); + } +} + +/// A container for a [local] and [global] [Offset] pair. +/// +/// Usually, the [global] [Offset] is in the coordinate space of the screen +/// after conversion to logical pixels and the [local] offset is the same +/// [Offset], but transformed to a local coordinate space. +@immutable +class OffsetPair { + /// Creates a [OffsetPair] combining a [local] and [global] [Offset]. + const OffsetPair({ + required this.local, + required this.global, + }); + + /// Creates a [OffsetPair] from [PointerEvent.localPosition] and + /// [PointerEvent.position]. + factory OffsetPair.fromEventPosition(PointerEvent event) { + return OffsetPair(local: event.localPosition, global: event.position); + } + + /// Creates a [OffsetPair] from [PointerEvent.localDelta] and + /// [PointerEvent.delta]. + factory OffsetPair.fromEventDelta(PointerEvent event) { + return OffsetPair(local: event.localDelta, global: event.delta); + } + + /// A [OffsetPair] where both [Offset]s are [Offset.zero]. + static const OffsetPair zero = OffsetPair(local: Offset.zero, global: Offset.zero); + + /// The [Offset] in the local coordinate space. + final Offset local; + + /// The [Offset] in the global coordinate space after conversion to logical + /// pixels. + final Offset global; + + /// Adds the `other.global` to [global] and `other.local` to [local]. + OffsetPair operator+(OffsetPair other) { + return OffsetPair( + local: local + other.local, + global: global + other.global, + ); + } + + /// Subtracts the `other.global` from [global] and `other.local` from [local]. + OffsetPair operator-(OffsetPair other) { + return OffsetPair( + local: local - other.local, + global: global - other.global, + ); + } + + @override + String toString() => '${objectRuntimeType(this, 'OffsetPair')}(local: $local, global: $global)'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/resampler.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/resampler.dart new file mode 100644 index 0000000000000000000000000000000000000000..0890097b81d2c5f639d6cd9d65edbd3593fa52ea --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/resampler.dart @@ -0,0 +1,340 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; + +import 'events.dart'; + +export 'events.dart' show PointerEvent; + +/// A callback used by [PointerEventResampler.sample] and +/// [PointerEventResampler.stop] to process a resampled `event`. +typedef HandleEventCallback = void Function(PointerEvent event); + +/// Class for pointer event resampling. +/// +/// An instance of this class can be used to resample one sequence +/// of pointer events. Multiple instances are expected to be used for +/// multi-touch support. The sampling frequency and the sampling +/// offset is determined by the caller. +/// +/// This can be used to get smooth touch event processing at the cost +/// of adding some latency. Devices with low frequency sensors or when +/// the frequency is not a multiple of the display frequency +/// (e.g., 120Hz input and 90Hz display) benefit from this. +/// +/// The following pointer event types are supported: +/// [PointerAddedEvent], [PointerHoverEvent], [PointerDownEvent], +/// [PointerMoveEvent], [PointerCancelEvent], [PointerUpEvent], +/// [PointerRemovedEvent]. +/// +/// Resampling is currently limited to event position and delta. All +/// pointer event types except [PointerAddedEvent] will be resampled. +/// [PointerHoverEvent] and [PointerMoveEvent] will only be generated +/// when the position has changed. +class PointerEventResampler { + // Events queued for processing. + final Queue _queuedEvents = Queue(); + + // Pointer state required for resampling. + PointerEvent? _last; + PointerEvent? _next; + Offset _position = Offset.zero; + bool _isTracked = false; + bool _isDown = false; + int _pointerIdentifier = 0; + int _hasButtons = 0; + + PointerEvent _toHoverEvent( + PointerEvent event, + Offset position, + Offset delta, + Duration timeStamp, + int buttons, + ) { + return PointerHoverEvent( + viewId: event.viewId, + timeStamp: timeStamp, + kind: event.kind, + device: event.device, + position: position, + delta: delta, + buttons: event.buttons, + obscured: event.obscured, + pressureMin: event.pressureMin, + pressureMax: event.pressureMax, + distance: event.distance, + distanceMax: event.distanceMax, + size: event.size, + radiusMajor: event.radiusMajor, + radiusMinor: event.radiusMinor, + radiusMin: event.radiusMin, + radiusMax: event.radiusMax, + orientation: event.orientation, + tilt: event.tilt, + synthesized: event.synthesized, + embedderId: event.embedderId, + ); + } + + PointerEvent _toMoveEvent( + PointerEvent event, + Offset position, + Offset delta, + int pointerIdentifier, + Duration timeStamp, + int buttons, + ) { + return PointerMoveEvent( + viewId: event.viewId, + timeStamp: timeStamp, + pointer: pointerIdentifier, + kind: event.kind, + device: event.device, + position: position, + delta: delta, + buttons: buttons, + obscured: event.obscured, + pressure: event.pressure, + pressureMin: event.pressureMin, + pressureMax: event.pressureMax, + distanceMax: event.distanceMax, + size: event.size, + radiusMajor: event.radiusMajor, + radiusMinor: event.radiusMinor, + radiusMin: event.radiusMin, + radiusMax: event.radiusMax, + orientation: event.orientation, + tilt: event.tilt, + platformData: event.platformData, + synthesized: event.synthesized, + embedderId: event.embedderId, + ); + } + + PointerEvent _toMoveOrHoverEvent( + PointerEvent event, + Offset position, + Offset delta, + int pointerIdentifier, + Duration timeStamp, + bool isDown, + int buttons, + ) { + return isDown + ? _toMoveEvent( + event, position, delta, pointerIdentifier, timeStamp, buttons) + : _toHoverEvent(event, position, delta, timeStamp, buttons); + } + + Offset _positionAt(Duration sampleTime) { + // Use `next` position by default. + double x = _next?.position.dx ?? 0.0; + double y = _next?.position.dy ?? 0.0; + + final Duration nextTimeStamp = _next?.timeStamp ?? Duration.zero; + final Duration lastTimeStamp = _last?.timeStamp ?? Duration.zero; + + // Resample if `next` time stamp is past `sampleTime`. + if (nextTimeStamp > sampleTime && nextTimeStamp > lastTimeStamp) { + final double interval = (nextTimeStamp - lastTimeStamp).inMicroseconds.toDouble(); + final double scalar = (sampleTime - lastTimeStamp).inMicroseconds.toDouble() / interval; + final double lastX = _last?.position.dx ?? 0.0; + final double lastY = _last?.position.dy ?? 0.0; + x = lastX + (x - lastX) * scalar; + y = lastY + (y - lastY) * scalar; + } + + return Offset(x, y); + } + + void _processPointerEvents(Duration sampleTime) { + final Iterator it = _queuedEvents.iterator; + while (it.moveNext()) { + final PointerEvent event = it.current; + + // Update both `last` and `next` pointer event if time stamp is older + // or equal to `sampleTime`. + if (event.timeStamp <= sampleTime || _last == null) { + _last = event; + _next = event; + continue; + } + + // Update only `next` pointer event if time stamp is more recent than + // `sampleTime` and next event is not already more recent. + final Duration nextTimeStamp = _next?.timeStamp ?? Duration.zero; + if (nextTimeStamp < sampleTime) { + _next = event; + break; + } + } + } + + void _dequeueAndSampleNonHoverOrMovePointerEventsUntil( + Duration sampleTime, + Duration nextSampleTime, + HandleEventCallback callback, + ) { + Duration endTime = sampleTime; + // Scan queued events to determine end time. + final Iterator it = _queuedEvents.iterator; + while (it.moveNext()) { + final PointerEvent event = it.current; + + // Potentially stop dispatching events if more recent than `sampleTime`. + if (event.timeStamp > sampleTime) { + // Definitely stop if more recent than `nextSampleTime`. + if (event.timeStamp >= nextSampleTime) { + break; + } + + // Update `endTime` to allow early processing of up and removed + // events as this improves resampling of these events, which is + // important for fling animations. + if (event is PointerUpEvent || event is PointerRemovedEvent) { + endTime = event.timeStamp; + continue; + } + + // Stop if event is not move or hover. + if (event is! PointerMoveEvent && event is! PointerHoverEvent) { + break; + } + } + } + + while (_queuedEvents.isNotEmpty) { + final PointerEvent event = _queuedEvents.first; + + // Stop dispatching events if more recent than `endTime`. + if (event.timeStamp > endTime) { + break; + } + + final bool wasTracked = _isTracked; + final bool wasDown = _isDown; + final int hadButtons = _hasButtons; + + // Update pointer state. + _isTracked = event is! PointerRemovedEvent; + _isDown = event.down; + _hasButtons = event.buttons; + + // Position at `sampleTime`. + final Offset position = _positionAt(sampleTime); + + // Initialize position if we are starting to track this pointer. + if (_isTracked && !wasTracked) { + _position = position; + } + + // Current pointer identifier. + final int pointerIdentifier = event.pointer; + + // Initialize pointer identifier for `move` events. + // Identifier is expected to be the same while `down`. + assert(!wasDown || _pointerIdentifier == pointerIdentifier); + _pointerIdentifier = pointerIdentifier; + + // Skip `move` and `hover` events as they are automatically + // generated when the position has changed. + if (event is! PointerMoveEvent && event is! PointerHoverEvent) { + // Add synthetics `move` or `hover` event if position has changed. + // + // Devices without `hover` events are expected to always have + // `add` and `down` events with the same position and this logic will + // therefore never produce `hover` events. + if (position != _position) { + final Offset delta = position - _position; + callback(_toMoveOrHoverEvent(event, position, delta, + _pointerIdentifier, sampleTime, wasDown, hadButtons)); + _position = position; + } + callback(event.copyWith( + position: position, + delta: Offset.zero, + pointer: pointerIdentifier, + timeStamp: sampleTime, + )); + } + + _queuedEvents.removeFirst(); + } + } + + void _samplePointerPosition( + Duration sampleTime, + HandleEventCallback callback, + ) { + // Position at `sampleTime`. + final Offset position = _positionAt(sampleTime); + + // Add `move` or `hover` events if position has changed. + final PointerEvent? next = _next; + if (position != _position && next != null) { + final Offset delta = position - _position; + callback(_toMoveOrHoverEvent(next, position, delta, _pointerIdentifier, + sampleTime, _isDown, _hasButtons)); + _position = position; + } + } + + /// Enqueue pointer `event` for resampling. + void addEvent(PointerEvent event) { + _queuedEvents.add(event); + } + + /// Dispatch resampled pointer events for the specified `sampleTime` + /// by calling [callback]. + /// + /// This may dispatch multiple events if position is not the only + /// state that has changed since last sample. + /// + /// Calling [callback] must not add or sample events. + /// + /// Positive value for `nextSampleTime` allow early processing of + /// up and removed events. This improves resampling of these events, + /// which is important for fling animations. + void sample( + Duration sampleTime, + Duration nextSampleTime, + HandleEventCallback callback, + ) { + _processPointerEvents(sampleTime); + + // Dequeue and sample pointer events until `sampleTime`. + _dequeueAndSampleNonHoverOrMovePointerEventsUntil(sampleTime, nextSampleTime, callback); + + // Dispatch resampled pointer location event if tracked. + if (_isTracked) { + _samplePointerPosition(sampleTime, callback); + } + } + + /// Stop resampling. + /// + /// This will dispatch pending events by calling [callback] and reset + /// internal state. + void stop(HandleEventCallback callback) { + while (_queuedEvents.isNotEmpty) { + callback(_queuedEvents.removeFirst()); + } + _pointerIdentifier = 0; + _isDown = false; + _isTracked = false; + _position = Offset.zero; + _next = null; + _last = null; + } + + /// Returns `true` if a call to [sample] can dispatch more events. + bool get hasPendingEvents => _queuedEvents.isNotEmpty; + + /// Returns `true` if pointer is currently tracked. + bool get isTracked => _isTracked; + + /// Returns `true` if pointer is currently down. + bool get isDown => _isDown; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/scale.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/scale.dart new file mode 100644 index 0000000000000000000000000000000000000000..b3ec74bb985b89c95b0ece1d52006217a40e3743 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/scale.dart @@ -0,0 +1,804 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'constants.dart'; +import 'events.dart'; +import 'recognizer.dart'; +import 'velocity_tracker.dart'; + +export 'dart:ui' show Offset, PointerDeviceKind; + +export 'events.dart' show PointerDownEvent, PointerEvent, PointerPanZoomStartEvent; +export 'recognizer.dart' show DragStartBehavior; +export 'velocity_tracker.dart' show Velocity; + +/// The default conversion factor when treating mouse scrolling as scaling. +/// +/// The value was arbitrarily chosen to feel natural for most mousewheels on +/// all supported platforms. +const double kDefaultMouseScrollToScaleFactor = 200; + +/// The default conversion factor when treating trackpad scrolling as scaling. +/// +/// This factor matches the default [kDefaultMouseScrollToScaleFactor] of 200 to +/// feel natural for most trackpads, and the convention that scrolling up means +/// zooming in. +const Offset kDefaultTrackpadScrollToScaleFactor = Offset(0, -1/kDefaultMouseScrollToScaleFactor); + +/// The possible states of a [ScaleGestureRecognizer]. +enum _ScaleState { + /// The recognizer is ready to start recognizing a gesture. + ready, + + /// The sequence of pointer events seen thus far is consistent with a scale + /// gesture but the gesture has not been accepted definitively. + possible, + + /// The sequence of pointer events seen thus far has been accepted + /// definitively as a scale gesture. + accepted, + + /// The sequence of pointer events seen thus far has been accepted + /// definitively as a scale gesture and the pointers established a focal point + /// and initial scale. + started, +} + +class _PointerPanZoomData { + _PointerPanZoomData.fromStartEvent( + this.parent, + PointerPanZoomStartEvent event + ) : _position = event.position, + _pan = Offset.zero, + _scale = 1, + _rotation = 0; + + _PointerPanZoomData.fromUpdateEvent( + this.parent, + PointerPanZoomUpdateEvent event + ) : _position = event.position, + _pan = event.pan, + _scale = event.scale, + _rotation = event.rotation; + + final ScaleGestureRecognizer parent; + final Offset _position; + final Offset _pan; + final double _scale; + final double _rotation; + + Offset get focalPoint { + if (parent.trackpadScrollCausesScale) { + return _position; + } + return _position + _pan; + } + + double get scale { + if (parent.trackpadScrollCausesScale) { + return _scale * math.exp( + (_pan.dx * parent.trackpadScrollToScaleFactor.dx) + + (_pan.dy * parent.trackpadScrollToScaleFactor.dy) + ); + } + return _scale; + } + + double get rotation => _rotation; + + @override + String toString() => '_PointerPanZoomData(parent: $parent, _position: $_position, _pan: $_pan, _scale: $_scale, _rotation: $_rotation)'; +} + +/// Details for [GestureScaleStartCallback]. +class ScaleStartDetails { + /// Creates details for [GestureScaleStartCallback]. + ScaleStartDetails({ + this.focalPoint = Offset.zero, + Offset? localFocalPoint, + this.pointerCount = 0, + this.sourceTimeStamp, + }) : localFocalPoint = localFocalPoint ?? focalPoint; + + /// The initial focal point of the pointers in contact with the screen. + /// + /// Reported in global coordinates. + /// + /// See also: + /// + /// * [localFocalPoint], which is the same value reported in local + /// coordinates. + final Offset focalPoint; + + /// The initial focal point of the pointers in contact with the screen. + /// + /// Reported in local coordinates. Defaults to [focalPoint] if not set in the + /// constructor. + /// + /// See also: + /// + /// * [focalPoint], which is the same value reported in global + /// coordinates. + final Offset localFocalPoint; + + /// The number of pointers being tracked by the gesture recognizer. + /// + /// Typically this is the number of fingers being used to pan the widget using the gesture + /// recognizer. + final int pointerCount; + + /// Recorded timestamp of the source pointer event that triggered the scale + /// event. + /// + /// Could be null if triggered from proxied events such as accessibility. + final Duration? sourceTimeStamp; + + @override + String toString() => 'ScaleStartDetails(focalPoint: $focalPoint, localFocalPoint: $localFocalPoint, pointersCount: $pointerCount)'; +} + +/// Details for [GestureScaleUpdateCallback]. +class ScaleUpdateDetails { + /// Creates details for [GestureScaleUpdateCallback]. + /// + /// The [scale], [horizontalScale], and [verticalScale] arguments must be + /// greater than or equal to zero. + ScaleUpdateDetails({ + this.focalPoint = Offset.zero, + Offset? localFocalPoint, + this.scale = 1.0, + this.horizontalScale = 1.0, + this.verticalScale = 1.0, + this.rotation = 0.0, + this.pointerCount = 0, + this.focalPointDelta = Offset.zero, + this.sourceTimeStamp, + }) : assert(scale >= 0.0), + assert(horizontalScale >= 0.0), + assert(verticalScale >= 0.0), + localFocalPoint = localFocalPoint ?? focalPoint; + + /// The amount the gesture's focal point has moved in the coordinate space of + /// the event receiver since the previous update. + /// + /// Defaults to zero if not specified in the constructor. + final Offset focalPointDelta; + + /// The focal point of the pointers in contact with the screen. + /// + /// Reported in global coordinates. + /// + /// See also: + /// + /// * [localFocalPoint], which is the same value reported in local + /// coordinates. + final Offset focalPoint; + + /// The focal point of the pointers in contact with the screen. + /// + /// Reported in local coordinates. Defaults to [focalPoint] if not set in the + /// constructor. + /// + /// See also: + /// + /// * [focalPoint], which is the same value reported in global + /// coordinates. + final Offset localFocalPoint; + + /// The scale implied by the average distance between the pointers in contact + /// with the screen. + /// + /// This value must be greater than or equal to zero. + /// + /// See also: + /// + /// * [horizontalScale], which is the scale along the horizontal axis. + /// * [verticalScale], which is the scale along the vertical axis. + final double scale; + + /// The scale implied by the average distance along the horizontal axis + /// between the pointers in contact with the screen. + /// + /// This value must be greater than or equal to zero. + /// + /// See also: + /// + /// * [scale], which is the general scale implied by the pointers. + /// * [verticalScale], which is the scale along the vertical axis. + final double horizontalScale; + + /// The scale implied by the average distance along the vertical axis + /// between the pointers in contact with the screen. + /// + /// This value must be greater than or equal to zero. + /// + /// See also: + /// + /// * [scale], which is the general scale implied by the pointers. + /// * [horizontalScale], which is the scale along the horizontal axis. + final double verticalScale; + + /// The angle implied by the first two pointers to enter in contact with + /// the screen. + /// + /// Expressed in radians. + final double rotation; + + /// The number of pointers being tracked by the gesture recognizer. + /// + /// Typically this is the number of fingers being used to pan the widget using the gesture + /// recognizer. + final int pointerCount; + + /// Recorded timestamp of the source pointer event that triggered the scale + /// event. + /// + /// Could be null if triggered from proxied events such as accessibility. + final Duration? sourceTimeStamp; + + @override + String toString() => 'ScaleUpdateDetails(' + 'focalPoint: $focalPoint,' + ' localFocalPoint: $localFocalPoint,' + ' scale: $scale,' + ' horizontalScale: $horizontalScale,' + ' verticalScale: $verticalScale,' + ' rotation: $rotation,' + ' pointerCount: $pointerCount,' + ' focalPointDelta: $focalPointDelta,' + ' sourceTimeStamp: $sourceTimeStamp)'; +} + +/// Details for [GestureScaleEndCallback]. +class ScaleEndDetails { + /// Creates details for [GestureScaleEndCallback]. + ScaleEndDetails({ this.velocity = Velocity.zero, this.scaleVelocity = 0, this.pointerCount = 0 }); + + /// The velocity of the last pointer to be lifted off of the screen. + final Velocity velocity; + + /// The final velocity of the scale factor reported by the gesture. + final double scaleVelocity; + + /// The number of pointers being tracked by the gesture recognizer. + /// + /// Typically this is the number of fingers being used to pan the widget using the gesture + /// recognizer. + final int pointerCount; + + @override + String toString() => 'ScaleEndDetails(velocity: $velocity, scaleVelocity: $scaleVelocity, pointerCount: $pointerCount)'; +} + +/// Signature for when the pointers in contact with the screen have established +/// a focal point and initial scale of 1.0. +typedef GestureScaleStartCallback = void Function(ScaleStartDetails details); + +/// Signature for when the pointers in contact with the screen have indicated a +/// new focal point and/or scale. +typedef GestureScaleUpdateCallback = void Function(ScaleUpdateDetails details); + +/// Signature for when the pointers are no longer in contact with the screen. +typedef GestureScaleEndCallback = void Function(ScaleEndDetails details); + +bool _isFlingGesture(Velocity velocity) { + final double speedSquared = velocity.pixelsPerSecond.distanceSquared; + return speedSquared > kMinFlingVelocity * kMinFlingVelocity; +} + + +/// Defines a line between two pointers on screen. +/// +/// [_LineBetweenPointers] is an abstraction of a line between two pointers in +/// contact with the screen. Used to track the rotation of a scale gesture. +class _LineBetweenPointers { + + /// Creates a [_LineBetweenPointers]. None of the [pointerStartLocation], [pointerStartId] + /// [pointerEndLocation] and [pointerEndId] must be null. [pointerStartId] and [pointerEndId] + /// should be different. + _LineBetweenPointers({ + this.pointerStartLocation = Offset.zero, + this.pointerStartId = 0, + this.pointerEndLocation = Offset.zero, + this.pointerEndId = 1, + }) : assert(pointerStartId != pointerEndId); + + // The location and the id of the pointer that marks the start of the line. + final Offset pointerStartLocation; + final int pointerStartId; + + // The location and the id of the pointer that marks the end of the line. + final Offset pointerEndLocation; + final int pointerEndId; + +} + + +/// Recognizes a scale gesture. +/// +/// [ScaleGestureRecognizer] tracks the pointers in contact with the screen and +/// calculates their focal point, indicated scale, and rotation. When a focal +/// point is established, the recognizer calls [onStart]. As the focal point, +/// scale, and rotation change, the recognizer calls [onUpdate]. When the +/// pointers are no longer in contact with the screen, the recognizer calls +/// [onEnd]. +class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { + /// Create a gesture recognizer for interactions intended for scaling content. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + ScaleGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + this.dragStartBehavior = DragStartBehavior.down, + this.trackpadScrollCausesScale = false, + this.trackpadScrollToScaleFactor = kDefaultTrackpadScrollToScaleFactor, + }); + + /// Determines what point is used as the starting point in all calculations + /// involving this gesture. + /// + /// When set to [DragStartBehavior.down], the scale is calculated starting + /// from the position where the pointer first contacted the screen. + /// + /// When set to [DragStartBehavior.start], the scale is calculated starting + /// from the position where the scale gesture began. The scale gesture may + /// begin after the time that the pointer first contacted the screen if there + /// are multiple listeners competing for the gesture. In that case, the + /// gesture arena waits to determine whether or not the gesture is a scale + /// gesture before giving the gesture to this GestureRecognizer. This happens + /// in the case of nested GestureDetectors, for example. + /// + /// Defaults to [DragStartBehavior.down]. + /// + /// See also: + /// + /// * https://flutter.dev/docs/development/ui/advanced/gestures#gesture-disambiguation, + /// which provides more information about the gesture arena. + DragStartBehavior dragStartBehavior; + + /// The pointers in contact with the screen have established a focal point and + /// initial scale of 1.0. + /// + /// This won't be called until the gesture arena has determined that this + /// GestureRecognizer has won the gesture. + /// + /// See also: + /// + /// * https://flutter.dev/docs/development/ui/advanced/gestures#gesture-disambiguation, + /// which provides more information about the gesture arena. + GestureScaleStartCallback? onStart; + + /// The pointers in contact with the screen have indicated a new focal point + /// and/or scale. + GestureScaleUpdateCallback? onUpdate; + + /// The pointers are no longer in contact with the screen. + GestureScaleEndCallback? onEnd; + + _ScaleState _state = _ScaleState.ready; + + Matrix4? _lastTransform; + + /// {@template flutter.gestures.scale.trackpadScrollCausesScale} + /// Whether scrolling up/down on a trackpad should cause scaling instead of + /// panning. + /// + /// Defaults to false. + /// {@endtemplate} + bool trackpadScrollCausesScale; + + /// {@template flutter.gestures.scale.trackpadScrollToScaleFactor} + /// A factor to control the direction and magnitude of scale when converting + /// trackpad scrolling. + /// + /// Incoming trackpad pan offsets will be divided by this factor to get scale + /// values. Increasing this offset will reduce the amount of scaling caused by + /// a fixed amount of trackpad scrolling. + /// + /// Defaults to [kDefaultTrackpadScrollToScaleFactor]. + /// {@endtemplate} + Offset trackpadScrollToScaleFactor; + + /// The number of pointers being tracked by the gesture recognizer. + /// + /// Typically this is the number of fingers being used to pan the widget using the gesture + /// recognizer. + int get pointerCount { + return _pointerPanZooms.length + _pointerQueue.length; + } + + late Offset _initialFocalPoint; + Offset? _currentFocalPoint; + late double _initialSpan; + late double _currentSpan; + late double _initialHorizontalSpan; + late double _currentHorizontalSpan; + late double _initialVerticalSpan; + late double _currentVerticalSpan; + late Offset _localFocalPoint; + _LineBetweenPointers? _initialLine; + _LineBetweenPointers? _currentLine; + final Map _pointerLocations = {}; + final List _pointerQueue = []; // A queue to sort pointers in order of entrance + final Map _velocityTrackers = {}; + VelocityTracker? _scaleVelocityTracker; + late Offset _delta; + final Map _pointerPanZooms = {}; + double _initialPanZoomScaleFactor = 1; + double _initialPanZoomRotationFactor = 0; + Duration? _initialEventTimestamp; + + double get _pointerScaleFactor => _initialSpan > 0.0 ? _currentSpan / _initialSpan : 1.0; + + double get _pointerHorizontalScaleFactor => _initialHorizontalSpan > 0.0 ? _currentHorizontalSpan / _initialHorizontalSpan : 1.0; + + double get _pointerVerticalScaleFactor => _initialVerticalSpan > 0.0 ? _currentVerticalSpan / _initialVerticalSpan : 1.0; + + double get _scaleFactor { + double scale = _pointerScaleFactor; + for (final _PointerPanZoomData p in _pointerPanZooms.values) { + scale *= p.scale / _initialPanZoomScaleFactor; + } + return scale; + } + + double get _horizontalScaleFactor { + double scale = _pointerHorizontalScaleFactor; + for (final _PointerPanZoomData p in _pointerPanZooms.values) { + scale *= p.scale / _initialPanZoomScaleFactor; + } + return scale; + } + + double get _verticalScaleFactor { + double scale = _pointerVerticalScaleFactor; + for (final _PointerPanZoomData p in _pointerPanZooms.values) { + scale *= p.scale / _initialPanZoomScaleFactor; + } + return scale; + } + + double _computeRotationFactor() { + double factor = 0.0; + if (_initialLine != null && _currentLine != null) { + final double fx = _initialLine!.pointerStartLocation.dx; + final double fy = _initialLine!.pointerStartLocation.dy; + final double sx = _initialLine!.pointerEndLocation.dx; + final double sy = _initialLine!.pointerEndLocation.dy; + + final double nfx = _currentLine!.pointerStartLocation.dx; + final double nfy = _currentLine!.pointerStartLocation.dy; + final double nsx = _currentLine!.pointerEndLocation.dx; + final double nsy = _currentLine!.pointerEndLocation.dy; + + final double angle1 = math.atan2(fy - sy, fx - sx); + final double angle2 = math.atan2(nfy - nsy, nfx - nsx); + + factor = angle2 - angle1; + } + for (final _PointerPanZoomData p in _pointerPanZooms.values) { + factor += p.rotation; + } + factor -= _initialPanZoomRotationFactor; + return factor; + } + + @override + void addAllowedPointer(PointerDownEvent event) { + super.addAllowedPointer(event); + _velocityTrackers[event.pointer] = VelocityTracker.withKind(event.kind); + _initialEventTimestamp = event.timeStamp; + if (_state == _ScaleState.ready) { + _state = _ScaleState.possible; + _initialSpan = 0.0; + _currentSpan = 0.0; + _initialHorizontalSpan = 0.0; + _currentHorizontalSpan = 0.0; + _initialVerticalSpan = 0.0; + _currentVerticalSpan = 0.0; + } + } + + @override + bool isPointerPanZoomAllowed(PointerPanZoomStartEvent event) => true; + + @override + void addAllowedPointerPanZoom(PointerPanZoomStartEvent event) { + super.addAllowedPointerPanZoom(event); + startTrackingPointer(event.pointer, event.transform); + _velocityTrackers[event.pointer] = VelocityTracker.withKind(event.kind); + _initialEventTimestamp = event.timeStamp; + if (_state == _ScaleState.ready) { + _state = _ScaleState.possible; + _initialPanZoomScaleFactor = 1.0; + _initialPanZoomRotationFactor = 0.0; + } + } + + @override + void handleEvent(PointerEvent event) { + assert(_state != _ScaleState.ready); + bool didChangeConfiguration = false; + bool shouldStartIfAccepted = false; + if (event is PointerMoveEvent) { + final VelocityTracker tracker = _velocityTrackers[event.pointer]!; + if (!event.synthesized) { + tracker.addPosition(event.timeStamp, event.position); + } + _pointerLocations[event.pointer] = event.position; + shouldStartIfAccepted = true; + _lastTransform = event.transform; + } else if (event is PointerDownEvent) { + _pointerLocations[event.pointer] = event.position; + _pointerQueue.add(event.pointer); + didChangeConfiguration = true; + shouldStartIfAccepted = true; + _lastTransform = event.transform; + } else if (event is PointerUpEvent || event is PointerCancelEvent) { + _pointerLocations.remove(event.pointer); + _pointerQueue.remove(event.pointer); + didChangeConfiguration = true; + _lastTransform = event.transform; + } else if (event is PointerPanZoomStartEvent) { + assert(_pointerPanZooms[event.pointer] == null); + _pointerPanZooms[event.pointer] = _PointerPanZoomData.fromStartEvent(this, event); + didChangeConfiguration = true; + shouldStartIfAccepted = true; + _lastTransform = event.transform; + } else if (event is PointerPanZoomUpdateEvent) { + assert(_pointerPanZooms[event.pointer] != null); + if (!event.synthesized && !trackpadScrollCausesScale) { + _velocityTrackers[event.pointer]!.addPosition(event.timeStamp, event.pan); + } + _pointerPanZooms[event.pointer] = _PointerPanZoomData.fromUpdateEvent(this, event); + _lastTransform = event.transform; + shouldStartIfAccepted = true; + } else if (event is PointerPanZoomEndEvent) { + assert(_pointerPanZooms[event.pointer] != null); + _pointerPanZooms.remove(event.pointer); + didChangeConfiguration = true; + } + + _updateLines(); + _update(); + + if (!didChangeConfiguration || _reconfigure(event.pointer)) { + _advanceStateMachine(shouldStartIfAccepted, event); + } + stopTrackingIfPointerNoLongerDown(event); + } + + void _update() { + final Offset? previousFocalPoint = _currentFocalPoint; + + // Compute the focal point + Offset focalPoint = Offset.zero; + for (final int pointer in _pointerLocations.keys) { + focalPoint += _pointerLocations[pointer]!; + } + for (final _PointerPanZoomData p in _pointerPanZooms.values) { + focalPoint += p.focalPoint; + } + _currentFocalPoint = pointerCount > 0 ? focalPoint / pointerCount.toDouble() : Offset.zero; + + if (previousFocalPoint == null) { + _localFocalPoint = PointerEvent.transformPosition( + _lastTransform, + _currentFocalPoint!, + ); + _delta = Offset.zero; + } else { + final Offset localPreviousFocalPoint = _localFocalPoint; + _localFocalPoint = PointerEvent.transformPosition( + _lastTransform, + _currentFocalPoint!, + ); + _delta = _localFocalPoint - localPreviousFocalPoint; + } + + final int count = _pointerLocations.keys.length; + + Offset pointerFocalPoint = Offset.zero; + for (final int pointer in _pointerLocations.keys) { + pointerFocalPoint += _pointerLocations[pointer]!; + } + if (count > 0) { + pointerFocalPoint = pointerFocalPoint / count.toDouble(); + } + + // Span is the average deviation from focal point. Horizontal and vertical + // spans are the average deviations from the focal point's horizontal and + // vertical coordinates, respectively. + double totalDeviation = 0.0; + double totalHorizontalDeviation = 0.0; + double totalVerticalDeviation = 0.0; + for (final int pointer in _pointerLocations.keys) { + totalDeviation += (pointerFocalPoint - _pointerLocations[pointer]!).distance; + totalHorizontalDeviation += (pointerFocalPoint.dx - _pointerLocations[pointer]!.dx).abs(); + totalVerticalDeviation += (pointerFocalPoint.dy - _pointerLocations[pointer]!.dy).abs(); + } + _currentSpan = count > 0 ? totalDeviation / count : 0.0; + _currentHorizontalSpan = count > 0 ? totalHorizontalDeviation / count : 0.0; + _currentVerticalSpan = count > 0 ? totalVerticalDeviation / count : 0.0; + } + + /// Updates [_initialLine] and [_currentLine] accordingly to the situation of + /// the registered pointers. + void _updateLines() { + final int count = _pointerLocations.keys.length; + assert(_pointerQueue.length >= count); + /// In case of just one pointer registered, reconfigure [_initialLine] + if (count < 2) { + _initialLine = _currentLine; + } else if (_initialLine != null && + _initialLine!.pointerStartId == _pointerQueue[0] && + _initialLine!.pointerEndId == _pointerQueue[1]) { + /// Rotation updated, set the [_currentLine] + _currentLine = _LineBetweenPointers( + pointerStartId: _pointerQueue[0], + pointerStartLocation: _pointerLocations[_pointerQueue[0]]!, + pointerEndId: _pointerQueue[1], + pointerEndLocation: _pointerLocations[_pointerQueue[1]]!, + ); + } else { + /// A new rotation process is on the way, set the [_initialLine] + _initialLine = _LineBetweenPointers( + pointerStartId: _pointerQueue[0], + pointerStartLocation: _pointerLocations[_pointerQueue[0]]!, + pointerEndId: _pointerQueue[1], + pointerEndLocation: _pointerLocations[_pointerQueue[1]]!, + ); + _currentLine = _initialLine; + } + } + + bool _reconfigure(int pointer) { + _initialFocalPoint = _currentFocalPoint!; + _initialSpan = _currentSpan; + _initialLine = _currentLine; + _initialHorizontalSpan = _currentHorizontalSpan; + _initialVerticalSpan = _currentVerticalSpan; + if (_pointerPanZooms.isEmpty) { + _initialPanZoomScaleFactor = 1.0; + _initialPanZoomRotationFactor = 0.0; + } else { + _initialPanZoomScaleFactor = _scaleFactor / _pointerScaleFactor; + _initialPanZoomRotationFactor = _pointerPanZooms.values.map((_PointerPanZoomData x) => x.rotation).reduce((double a, double b) => a + b); + } + if (_state == _ScaleState.started) { + if (onEnd != null) { + final VelocityTracker tracker = _velocityTrackers[pointer]!; + + Velocity velocity = tracker.getVelocity(); + if (_isFlingGesture(velocity)) { + final Offset pixelsPerSecond = velocity.pixelsPerSecond; + if (pixelsPerSecond.distanceSquared > kMaxFlingVelocity * kMaxFlingVelocity) { + velocity = Velocity(pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) * kMaxFlingVelocity); + } + invokeCallback('onEnd', () => onEnd!(ScaleEndDetails(velocity: velocity, scaleVelocity: _scaleVelocityTracker?.getVelocity().pixelsPerSecond.dx ?? -1, pointerCount: pointerCount))); + } else { + invokeCallback('onEnd', () => onEnd!(ScaleEndDetails(scaleVelocity: _scaleVelocityTracker?.getVelocity().pixelsPerSecond.dx ?? -1, pointerCount: pointerCount))); + } + } + _state = _ScaleState.accepted; + _scaleVelocityTracker = VelocityTracker.withKind(PointerDeviceKind.touch); // arbitrary PointerDeviceKind + return false; + } + _scaleVelocityTracker = VelocityTracker.withKind(PointerDeviceKind.touch); // arbitrary PointerDeviceKind + return true; + } + + void _advanceStateMachine(bool shouldStartIfAccepted, PointerEvent event) { + if (_state == _ScaleState.ready) { + _state = _ScaleState.possible; + } + + if (_state == _ScaleState.possible) { + final double spanDelta = (_currentSpan - _initialSpan).abs(); + final double focalPointDelta = (_currentFocalPoint! - _initialFocalPoint).distance; + if (spanDelta > computeScaleSlop(event.kind) || focalPointDelta > computePanSlop(event.kind, gestureSettings) || math.max(_scaleFactor / _pointerScaleFactor, _pointerScaleFactor / _scaleFactor) > 1.05) { + resolve(GestureDisposition.accepted); + } + } else if (_state.index >= _ScaleState.accepted.index) { + resolve(GestureDisposition.accepted); + } + + if (_state == _ScaleState.accepted && shouldStartIfAccepted) { + _initialEventTimestamp = event.timeStamp; + _state = _ScaleState.started; + _dispatchOnStartCallbackIfNeeded(); + } + + if (_state == _ScaleState.started) { + _scaleVelocityTracker?.addPosition(event.timeStamp, Offset(_scaleFactor, 0)); + if (onUpdate != null) { + invokeCallback('onUpdate', () { + onUpdate!(ScaleUpdateDetails( + scale: _scaleFactor, + horizontalScale: _horizontalScaleFactor, + verticalScale: _verticalScaleFactor, + focalPoint: _currentFocalPoint!, + localFocalPoint: _localFocalPoint, + rotation: _computeRotationFactor(), + pointerCount: pointerCount, + focalPointDelta: _delta, + sourceTimeStamp: event.timeStamp + )); + }); + } + } + } + + void _dispatchOnStartCallbackIfNeeded() { + assert(_state == _ScaleState.started); + if (onStart != null) { + invokeCallback('onStart', () { + onStart!(ScaleStartDetails( + focalPoint: _currentFocalPoint!, + localFocalPoint: _localFocalPoint, + pointerCount: pointerCount, + sourceTimeStamp: _initialEventTimestamp, + )); + }); + } + _initialEventTimestamp = null; + } + + @override + void acceptGesture(int pointer) { + if (_state == _ScaleState.possible) { + _state = _ScaleState.started; + _dispatchOnStartCallbackIfNeeded(); + if (dragStartBehavior == DragStartBehavior.start) { + _initialFocalPoint = _currentFocalPoint!; + _initialSpan = _currentSpan; + _initialLine = _currentLine; + _initialHorizontalSpan = _currentHorizontalSpan; + _initialVerticalSpan = _currentVerticalSpan; + if (_pointerPanZooms.isEmpty) { + _initialPanZoomScaleFactor = 1.0; + _initialPanZoomRotationFactor = 0.0; + } else { + _initialPanZoomScaleFactor = _scaleFactor / _pointerScaleFactor; + _initialPanZoomRotationFactor = _pointerPanZooms.values.map((_PointerPanZoomData x) => x.rotation).reduce((double a, double b) => a + b); + } + } + } + } + + @override + void rejectGesture(int pointer) { + _pointerPanZooms.remove(pointer); + _pointerLocations.remove(pointer); + _pointerQueue.remove(pointer); + stopTrackingPointer(pointer); + } + + @override + void didStopTrackingLastPointer(int pointer) { + switch (_state) { + case _ScaleState.possible: + resolve(GestureDisposition.rejected); + case _ScaleState.ready: + assert(false); // We should have not seen a pointer yet + case _ScaleState.accepted: + break; + case _ScaleState.started: + assert(false); // We should be in the accepted state when user is done + } + _state = _ScaleState.ready; + } + + @override + void dispose() { + _velocityTrackers.clear(); + super.dispose(); + } + + @override + String get debugDescription => 'scale'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/tap.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/tap.dart new file mode 100644 index 0000000000000000000000000000000000000000..d522c79911028c9b4d7febc4be3df0f96cc47731 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/tap.dart @@ -0,0 +1,692 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'package:flutter/foundation.dart'; + +import 'arena.dart'; +import 'constants.dart'; +import 'events.dart'; +import 'recognizer.dart'; + +export 'dart:ui' show Offset, PointerDeviceKind; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; +export 'package:vector_math/vector_math_64.dart' show Matrix4; + +export 'arena.dart' show GestureDisposition; +export 'events.dart' show PointerCancelEvent, PointerDownEvent, PointerEvent, PointerUpEvent; + +/// Details for [GestureTapDownCallback], such as position. +/// +/// See also: +/// +/// * [GestureDetector.onTapDown], which receives this information. +/// * [TapGestureRecognizer], which passes this information to one of its callbacks. +class TapDownDetails { + /// Creates details for a [GestureTapDownCallback]. + TapDownDetails({ + this.globalPosition = Offset.zero, + Offset? localPosition, + this.kind, + }) : localPosition = localPosition ?? globalPosition; + + /// The global position at which the pointer contacted the screen. + final Offset globalPosition; + + /// The kind of the device that initiated the event. + final PointerDeviceKind? kind; + + /// The local position at which the pointer contacted the screen. + final Offset localPosition; +} + +/// {@template flutter.gestures.tap.GestureTapDownCallback} +/// Signature for when a pointer that might cause a tap has contacted the +/// screen. +/// +/// The position at which the pointer contacted the screen is available in the +/// `details`. +/// {@endtemplate} +/// +/// See also: +/// +/// * [GestureDetector.onTapDown], which matches this signature. +/// * [TapGestureRecognizer], which uses this signature in one of its callbacks. +typedef GestureTapDownCallback = void Function(TapDownDetails details); + +/// Details for [GestureTapUpCallback], such as position. +/// +/// See also: +/// +/// * [GestureDetector.onTapUp], which receives this information. +/// * [TapGestureRecognizer], which passes this information to one of its callbacks. +class TapUpDetails { + /// Creates a [TapUpDetails] data object. + TapUpDetails({ + required this.kind, + this.globalPosition = Offset.zero, + Offset? localPosition, + }) : localPosition = localPosition ?? globalPosition; + + /// The global position at which the pointer contacted the screen. + final Offset globalPosition; + + /// The local position at which the pointer contacted the screen. + final Offset localPosition; + + /// The kind of the device that initiated the event. + final PointerDeviceKind kind; +} + +/// {@template flutter.gestures.tap.GestureTapUpCallback} +/// Signature for when a pointer that will trigger a tap has stopped contacting +/// the screen. +/// +/// The position at which the pointer stopped contacting the screen is available +/// in the `details`. +/// {@endtemplate} +/// +/// See also: +/// +/// * [GestureDetector.onTapUp], which matches this signature. +/// * [TapGestureRecognizer], which uses this signature in one of its callbacks. +typedef GestureTapUpCallback = void Function(TapUpDetails details); + +/// Signature for when a tap has occurred. +/// +/// See also: +/// +/// * [GestureDetector.onTap], which matches this signature. +/// * [TapGestureRecognizer], which uses this signature in one of its callbacks. +typedef GestureTapCallback = void Function(); + +/// Signature for when the pointer that previously triggered a +/// [GestureTapDownCallback] will not end up causing a tap. +/// +/// See also: +/// +/// * [GestureDetector.onTapCancel], which matches this signature. +/// * [TapGestureRecognizer], which uses this signature in one of its callbacks. +typedef GestureTapCancelCallback = void Function(); + +/// A base class for gesture recognizers that recognize taps. +/// +/// Gesture recognizers take part in gesture arenas to enable potential gestures +/// to be disambiguated from each other. This process is managed by a +/// [GestureArenaManager]. +/// +/// A tap is defined as a sequence of events that starts with a down, followed +/// by optional moves, then ends with an up. All move events must contain the +/// same `buttons` as the down event, and must not be too far from the initial +/// position. The gesture is rejected on any violation, a cancel event, or +/// if any other recognizers wins the arena. It is accepted only when it is the +/// last member of the arena. +/// +/// The [BaseTapGestureRecognizer] considers all the pointers involved in the +/// pointer event sequence as contributing to one gesture. For this reason, +/// extra pointer interactions during a tap sequence are not recognized as +/// additional taps. For example, down-1, down-2, up-1, up-2 produces only one +/// tap on up-1. +/// +/// The [BaseTapGestureRecognizer] can not be directly used, since it does not +/// define which buttons to accept, or what to do when a tap happens. If you +/// want to build a custom tap recognizer, extend this class by overriding +/// [isPointerAllowed] and the handler methods. +/// +/// See also: +/// +/// * [TapGestureRecognizer], a ready-to-use tap recognizer that recognizes +/// taps of the primary button and taps of the secondary button. +/// * [ModalBarrier], a widget that uses a custom tap recognizer that accepts +/// any buttons. +abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer { + /// Creates a tap gesture recognizer. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + BaseTapGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }) + : super(deadline: kPressTimeout); + + bool _sentTapDown = false; + bool _wonArenaForPrimaryPointer = false; + + PointerDownEvent? _down; + PointerUpEvent? _up; + + /// A pointer has contacted the screen, which might be the start of a tap. + /// + /// This triggers after the down event, once a short timeout ([deadline]) has + /// elapsed, or once the gesture has won the arena, whichever comes first. + /// + /// The parameter `down` is the down event of the primary pointer that started + /// the tap sequence. + /// + /// If this recognizer doesn't win the arena, [handleTapCancel] is called next. + /// Otherwise, [handleTapUp] is called next. + @protected + void handleTapDown({ required PointerDownEvent down }); + + /// A pointer has stopped contacting the screen, which is recognized as a tap. + /// + /// This triggers on the up event if the recognizer wins the arena with it + /// or has previously won. + /// + /// The parameter `down` is the down event of the primary pointer that started + /// the tap sequence, and `up` is the up event that ended the tap sequence. + /// + /// If this recognizer doesn't win the arena, [handleTapCancel] is called + /// instead. + @protected + void handleTapUp({ required PointerDownEvent down, required PointerUpEvent up }); + + /// A pointer that previously triggered [handleTapDown] will not end up + /// causing a tap. + /// + /// This triggers once the gesture loses the arena if [handleTapDown] has + /// been previously triggered. + /// + /// The parameter `down` is the down event of the primary pointer that started + /// the tap sequence; `cancel` is the cancel event, which might be null; + /// `reason` is a short description of the cause if `cancel` is null, which + /// can be "forced" if other gestures won the arena, or "spontaneous" + /// otherwise. + /// + /// If this recognizer wins the arena, [handleTapUp] is called instead. + @protected + void handleTapCancel({ required PointerDownEvent down, PointerCancelEvent? cancel, required String reason }); + + @override + void addAllowedPointer(PointerDownEvent event) { + if (state == GestureRecognizerState.ready) { + // If there is no result in the previous gesture arena, + // we ignore them and prepare to accept a new pointer. + if (_down != null && _up != null) { + assert(_down!.pointer == _up!.pointer); + _reset(); + } + + assert(_down == null && _up == null); + // `_down` must be assigned in this method instead of `handlePrimaryPointer`, + // because `acceptGesture` might be called before `handlePrimaryPointer`, + // which relies on `_down` to call `handleTapDown`. + _down = event; + } + if (_down != null) { + // This happens when this tap gesture has been rejected while the pointer + // is down (i.e. due to movement), when another allowed pointer is added, + // in which case all pointers are ignored. The `_down` being null + // means that _reset() has been called, since it is always set at the + // first allowed down event and will not be cleared except for reset(), + super.addAllowedPointer(event); + } + } + + @override + @protected + void startTrackingPointer(int pointer, [Matrix4? transform]) { + // The recognizer should never track any pointers when `_down` is null, + // because calling `_checkDown` in this state will throw exception. + assert(_down != null); + super.startTrackingPointer(pointer, transform); + } + + @override + void handlePrimaryPointer(PointerEvent event) { + if (event is PointerUpEvent) { + _up = event; + _checkUp(); + } else if (event is PointerCancelEvent) { + resolve(GestureDisposition.rejected); + if (_sentTapDown) { + _checkCancel(event, ''); + } + _reset(); + } else if (event.buttons != _down!.buttons) { + resolve(GestureDisposition.rejected); + stopTrackingPointer(primaryPointer!); + } + } + + @override + void resolve(GestureDisposition disposition) { + if (_wonArenaForPrimaryPointer && disposition == GestureDisposition.rejected) { + // This can happen if the gesture has been canceled. For example, when + // the pointer has exceeded the touch slop, the buttons have been changed, + // or if the recognizer is disposed. + assert(_sentTapDown); + _checkCancel(null, 'spontaneous'); + _reset(); + } + super.resolve(disposition); + } + + @override + void didExceedDeadline() { + _checkDown(); + } + + @override + void acceptGesture(int pointer) { + super.acceptGesture(pointer); + if (pointer == primaryPointer) { + _checkDown(); + _wonArenaForPrimaryPointer = true; + _checkUp(); + } + } + + @override + void rejectGesture(int pointer) { + super.rejectGesture(pointer); + if (pointer == primaryPointer) { + // Another gesture won the arena. + assert(state != GestureRecognizerState.possible); + if (_sentTapDown) { + _checkCancel(null, 'forced'); + } + _reset(); + } + } + + void _checkDown() { + if (_sentTapDown) { + return; + } + handleTapDown(down: _down!); + _sentTapDown = true; + } + + void _checkUp() { + if (!_wonArenaForPrimaryPointer || _up == null) { + return; + } + assert(_up!.pointer == _down!.pointer); + handleTapUp(down: _down!, up: _up!); + _reset(); + } + + void _checkCancel(PointerCancelEvent? event, String note) { + handleTapCancel(down: _down!, cancel: event, reason: note); + } + + void _reset() { + _sentTapDown = false; + _wonArenaForPrimaryPointer = false; + _up = null; + _down = null; + } + + @override + String get debugDescription => 'base tap'; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('wonArenaForPrimaryPointer', value: _wonArenaForPrimaryPointer, ifTrue: 'won arena')); + properties.add(DiagnosticsProperty('finalPosition', _up?.position, defaultValue: null)); + properties.add(DiagnosticsProperty('finalLocalPosition', _up?.localPosition, defaultValue: _up?.position)); + properties.add(DiagnosticsProperty('button', _down?.buttons, defaultValue: null)); + properties.add(FlagProperty('sentTapDown', value: _sentTapDown, ifTrue: 'sent tap down')); + } +} + +/// Recognizes taps. +/// +/// Gesture recognizers take part in gesture arenas to enable potential gestures +/// to be disambiguated from each other. This process is managed by a +/// [GestureArenaManager]. +/// +/// [TapGestureRecognizer] considers all the pointers involved in the pointer +/// event sequence as contributing to one gesture. For this reason, extra +/// pointer interactions during a tap sequence are not recognized as additional +/// taps. For example, down-1, down-2, up-1, up-2 produces only one tap on up-1. +/// +/// [TapGestureRecognizer] competes on pointer events of [kPrimaryButton] only +/// when it has at least one non-null `onTap*` callback, on events of +/// [kSecondaryButton] only when it has at least one non-null `onSecondaryTap*` +/// callback, and on events of [kTertiaryButton] only when it has at least +/// one non-null `onTertiaryTap*` callback. If it has no callbacks, it is a +/// no-op. +/// +/// {@template flutter.gestures.tap.TapGestureRecognizer.allowedButtonsFilter} +/// The [allowedButtonsFilter] argument only gives this recognizer the +/// ability to limit the buttons it accepts. It does not provide the +/// ability to recognize any buttons beyond the ones it already accepts: +/// kPrimaryButton, kSecondaryButton or kTertiaryButton. Therefore, a +/// combined value of `kPrimaryButton & kSecondaryButton` would be ignored, +/// but `kPrimaryButton | kSecondaryButton` would be allowed, as long as +/// only one of them is selected at a time. +/// {@endtemplate} +/// +/// See also: +/// +/// * [GestureDetector.onTap], which uses this recognizer. +/// * [MultiTapGestureRecognizer] +class TapGestureRecognizer extends BaseTapGestureRecognizer { + /// Creates a tap gesture recognizer. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + TapGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }); + + /// {@template flutter.gestures.tap.TapGestureRecognizer.onTapDown} + /// A pointer has contacted the screen at a particular location with a primary + /// button, which might be the start of a tap. + /// {@endtemplate} + /// + /// This triggers after the down event, once a short timeout ([deadline]) has + /// elapsed, or once the gestures has won the arena, whichever comes first. + /// + /// If this recognizer doesn't win the arena, [onTapCancel] is called next. + /// Otherwise, [onTapUp] is called next. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [onSecondaryTapDown], a similar callback but for a secondary button. + /// * [onTertiaryTapDown], a similar callback but for a tertiary button. + /// * [TapDownDetails], which is passed as an argument to this callback. + /// * [GestureDetector.onTapDown], which exposes this callback. + GestureTapDownCallback? onTapDown; + + /// {@template flutter.gestures.tap.TapGestureRecognizer.onTapUp} + /// A pointer has stopped contacting the screen at a particular location, + /// which is recognized as a tap of a primary button. + /// {@endtemplate} + /// + /// This triggers on the up event, if the recognizer wins the arena with it + /// or has previously won, immediately followed by [onTap]. + /// + /// If this recognizer doesn't win the arena, [onTapCancel] is called instead. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [onSecondaryTapUp], a similar callback but for a secondary button. + /// * [onTertiaryTapUp], a similar callback but for a tertiary button. + /// * [TapUpDetails], which is passed as an argument to this callback. + /// * [GestureDetector.onTapUp], which exposes this callback. + GestureTapUpCallback? onTapUp; + + /// A pointer has stopped contacting the screen, which is recognized as a tap + /// of a primary button. + /// + /// This triggers on the up event, if the recognizer wins the arena with it + /// or has previously won, immediately following [onTapUp]. + /// + /// If this recognizer doesn't win the arena, [onTapCancel] is called instead. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [onSecondaryTap], a similar callback but for a secondary button. + /// * [onTapUp], which has the same timing but with details. + /// * [GestureDetector.onTap], which exposes this callback. + GestureTapCallback? onTap; + + /// {@template flutter.gestures.tap.TapGestureRecognizer.onTapCancel} + /// A pointer that previously triggered [onTapDown] will not end up causing + /// a tap. + /// {@endtemplate} + /// + /// This triggers once the gesture loses the arena if [onTapDown] has + /// previously been triggered. + /// + /// If this recognizer wins the arena, [onTapUp] and [onTap] are called + /// instead. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [onSecondaryTapCancel], a similar callback but for a secondary button. + /// * [onTertiaryTapCancel], a similar callback but for a tertiary button. + /// * [GestureDetector.onTapCancel], which exposes this callback. + GestureTapCancelCallback? onTapCancel; + + /// {@template flutter.gestures.tap.TapGestureRecognizer.onSecondaryTap} + /// A pointer has stopped contacting the screen, which is recognized as a tap + /// of a secondary button. + /// {@endtemplate} + /// + /// This triggers on the up event, if the recognizer wins the arena with it or + /// has previously won, immediately following [onSecondaryTapUp]. + /// + /// If this recognizer doesn't win the arena, [onSecondaryTapCancel] is called + /// instead. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [onSecondaryTapUp], which has the same timing but with details. + /// * [GestureDetector.onSecondaryTap], which exposes this callback. + GestureTapCallback? onSecondaryTap; + + /// {@template flutter.gestures.tap.TapGestureRecognizer.onSecondaryTapDown} + /// A pointer has contacted the screen at a particular location with a + /// secondary button, which might be the start of a secondary tap. + /// {@endtemplate} + /// + /// This triggers after the down event, once a short timeout ([deadline]) has + /// elapsed, or once the gestures has won the arena, whichever comes first. + /// + /// If this recognizer doesn't win the arena, [onSecondaryTapCancel] is called + /// next. Otherwise, [onSecondaryTapUp] is called next. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [onTapDown], a similar callback but for a primary button. + /// * [onTertiaryTapDown], a similar callback but for a tertiary button. + /// * [TapDownDetails], which is passed as an argument to this callback. + /// * [GestureDetector.onSecondaryTapDown], which exposes this callback. + GestureTapDownCallback? onSecondaryTapDown; + + /// {@template flutter.gestures.tap.TapGestureRecognizer.onSecondaryTapUp} + /// A pointer has stopped contacting the screen at a particular location, + /// which is recognized as a tap of a secondary button. + /// {@endtemplate} + /// + /// This triggers on the up event if the recognizer wins the arena with it + /// or has previously won. + /// + /// If this recognizer doesn't win the arena, [onSecondaryTapCancel] is called + /// instead. + /// + /// See also: + /// + /// * [onSecondaryTap], a handler triggered right after this one that doesn't + /// pass any details about the tap. + /// * [kSecondaryButton], the button this callback responds to. + /// * [onTapUp], a similar callback but for a primary button. + /// * [onTertiaryTapUp], a similar callback but for a tertiary button. + /// * [TapUpDetails], which is passed as an argument to this callback. + /// * [GestureDetector.onSecondaryTapUp], which exposes this callback. + GestureTapUpCallback? onSecondaryTapUp; + + /// {@template flutter.gestures.tap.TapGestureRecognizer.onSecondaryTapCancel} + /// A pointer that previously triggered [onSecondaryTapDown] will not end up + /// causing a tap. + /// {@endtemplate} + /// + /// This triggers once the gesture loses the arena if [onSecondaryTapDown] + /// has previously been triggered. + /// + /// If this recognizer wins the arena, [onSecondaryTapUp] is called instead. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [onTapCancel], a similar callback but for a primary button. + /// * [onTertiaryTapCancel], a similar callback but for a tertiary button. + /// * [GestureDetector.onSecondaryTapCancel], which exposes this callback. + GestureTapCancelCallback? onSecondaryTapCancel; + + /// A pointer has contacted the screen at a particular location with a + /// tertiary button, which might be the start of a tertiary tap. + /// + /// This triggers after the down event, once a short timeout ([deadline]) has + /// elapsed, or once the gestures has won the arena, whichever comes first. + /// + /// If this recognizer doesn't win the arena, [onTertiaryTapCancel] is called + /// next. Otherwise, [onTertiaryTapUp] is called next. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [onTapDown], a similar callback but for a primary button. + /// * [onSecondaryTapDown], a similar callback but for a secondary button. + /// * [TapDownDetails], which is passed as an argument to this callback. + /// * [GestureDetector.onTertiaryTapDown], which exposes this callback. + GestureTapDownCallback? onTertiaryTapDown; + + /// A pointer has stopped contacting the screen at a particular location, + /// which is recognized as a tap of a tertiary button. + /// + /// This triggers on the up event if the recognizer wins the arena with it + /// or has previously won. + /// + /// If this recognizer doesn't win the arena, [onTertiaryTapCancel] is called + /// instead. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [onTapUp], a similar callback but for a primary button. + /// * [onSecondaryTapUp], a similar callback but for a secondary button. + /// * [TapUpDetails], which is passed as an argument to this callback. + /// * [GestureDetector.onTertiaryTapUp], which exposes this callback. + GestureTapUpCallback? onTertiaryTapUp; + + /// A pointer that previously triggered [onTertiaryTapDown] will not end up + /// causing a tap. + /// + /// This triggers once the gesture loses the arena if [onTertiaryTapDown] + /// has previously been triggered. + /// + /// If this recognizer wins the arena, [onTertiaryTapUp] is called instead. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [onTapCancel], a similar callback but for a primary button. + /// * [onSecondaryTapCancel], a similar callback but for a secondary button. + /// * [GestureDetector.onTertiaryTapCancel], which exposes this callback. + GestureTapCancelCallback? onTertiaryTapCancel; + + @override + bool isPointerAllowed(PointerDownEvent event) { + switch (event.buttons) { + case kPrimaryButton: + if (onTapDown == null && + onTap == null && + onTapUp == null && + onTapCancel == null) { + return false; + } + case kSecondaryButton: + if (onSecondaryTap == null && + onSecondaryTapDown == null && + onSecondaryTapUp == null && + onSecondaryTapCancel == null) { + return false; + } + case kTertiaryButton: + if (onTertiaryTapDown == null && + onTertiaryTapUp == null && + onTertiaryTapCancel == null) { + return false; + } + default: + return false; + } + return super.isPointerAllowed(event); + } + + @protected + @override + void handleTapDown({required PointerDownEvent down}) { + final TapDownDetails details = TapDownDetails( + globalPosition: down.position, + localPosition: down.localPosition, + kind: getKindForPointer(down.pointer), + ); + switch (down.buttons) { + case kPrimaryButton: + if (onTapDown != null) { + invokeCallback('onTapDown', () => onTapDown!(details)); + } + case kSecondaryButton: + if (onSecondaryTapDown != null) { + invokeCallback('onSecondaryTapDown', () => onSecondaryTapDown!(details)); + } + case kTertiaryButton: + if (onTertiaryTapDown != null) { + invokeCallback('onTertiaryTapDown', () => onTertiaryTapDown!(details)); + } + default: + } + } + + @protected + @override + void handleTapUp({ required PointerDownEvent down, required PointerUpEvent up}) { + final TapUpDetails details = TapUpDetails( + kind: up.kind, + globalPosition: up.position, + localPosition: up.localPosition, + ); + switch (down.buttons) { + case kPrimaryButton: + if (onTapUp != null) { + invokeCallback('onTapUp', () => onTapUp!(details)); + } + if (onTap != null) { + invokeCallback('onTap', onTap!); + } + case kSecondaryButton: + if (onSecondaryTapUp != null) { + invokeCallback('onSecondaryTapUp', () => onSecondaryTapUp!(details)); + } + if (onSecondaryTap != null) { + invokeCallback('onSecondaryTap', () => onSecondaryTap!()); + } + case kTertiaryButton: + if (onTertiaryTapUp != null) { + invokeCallback('onTertiaryTapUp', () => onTertiaryTapUp!(details)); + } + default: + } + } + + @protected + @override + void handleTapCancel({ required PointerDownEvent down, PointerCancelEvent? cancel, required String reason }) { + final String note = reason == '' ? reason : '$reason '; + switch (down.buttons) { + case kPrimaryButton: + if (onTapCancel != null) { + invokeCallback('${note}onTapCancel', onTapCancel!); + } + case kSecondaryButton: + if (onSecondaryTapCancel != null) { + invokeCallback('${note}onSecondaryTapCancel', onSecondaryTapCancel!); + } + case kTertiaryButton: + if (onTertiaryTapCancel != null) { + invokeCallback('${note}onTertiaryTapCancel', onTertiaryTapCancel!); + } + default: + } + } + + @override + String get debugDescription => 'tap'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/tap_and_drag.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/tap_and_drag.dart new file mode 100644 index 0000000000000000000000000000000000000000..108beaf024ee6b2a82b5fd59a2b2e36114f20278 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/tap_and_drag.dart @@ -0,0 +1,1442 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; + +import 'constants.dart'; +import 'events.dart'; +import 'monodrag.dart'; +import 'recognizer.dart'; +import 'scale.dart'; +import 'tap.dart'; + +// Examples can assume: +// void setState(VoidCallback fn) { } +// late String _last; + +double _getGlobalDistance(PointerEvent event, OffsetPair? originPosition) { + assert(originPosition != null); + final Offset offset = event.position - originPosition!.global; + return offset.distance; +} + +// The possible states of a [BaseTapAndDragGestureRecognizer]. +// +// The recognizer advances from [ready] to [possible] when it starts tracking +// a pointer in [BaseTapAndDragGestureRecognizer.addAllowedPointer]. Where it advances +// from there depends on the sequence of pointer events that is tracked by the +// recognizer, following the initial [PointerDownEvent]: +// +// * If a [PointerUpEvent] has not been tracked, the recognizer stays in the [possible] +// state as long as it continues to track a pointer. +// * If a [PointerMoveEvent] is tracked that has moved a sufficient global distance +// from the initial [PointerDownEvent] and it came before a [PointerUpEvent], then +// this recognizer moves from the [possible] state to [accepted]. +// * If a [PointerUpEvent] is tracked before the pointer has moved a sufficient global +// distance to be considered a drag, then this recognizer moves from the [possible] +// state to [ready]. +// * If a [PointerCancelEvent] is tracked then this recognizer moves from its current +// state to [ready]. +// +// Once the recognizer has stopped tracking any remaining pointers, the recognizer +// returns to the [ready] state. +enum _DragState { + // The recognizer is ready to start recognizing a drag. + ready, + + // The sequence of pointer events seen thus far is consistent with a drag but + // it has not been accepted definitively. + possible, + + // The sequence of pointer events has been accepted definitively as a drag. + accepted, +} + +/// {@macro flutter.gestures.tap.GestureTapDownCallback} +/// +/// The consecutive tap count at the time the pointer contacted the +/// screen is given by [TapDragDownDetails.consecutiveTapCount]. +/// +/// Used by [BaseTapAndDragGestureRecognizer.onTapDown]. +typedef GestureTapDragDownCallback = void Function(TapDragDownDetails details); + +/// Details for [GestureTapDragDownCallback], such as the number of +/// consecutive taps. +/// +/// See also: +/// +/// * [BaseTapAndDragGestureRecognizer], which passes this information to its +/// [BaseTapAndDragGestureRecognizer.onTapDown] callback. +/// * [TapDragUpDetails], the details for [GestureTapDragUpCallback]. +/// * [TapDragStartDetails], the details for [GestureTapDragStartCallback]. +/// * [TapDragUpdateDetails], the details for [GestureTapDragUpdateCallback]. +/// * [TapDragEndDetails], the details for [GestureTapDragEndCallback]. +class TapDragDownDetails with Diagnosticable { + /// Creates details for a [GestureTapDragDownCallback]. + TapDragDownDetails({ + required this.globalPosition, + required this.localPosition, + this.kind, + required this.consecutiveTapCount, + }); + + /// The global position at which the pointer contacted the screen. + final Offset globalPosition; + + /// The local position at which the pointer contacted the screen. + final Offset localPosition; + + /// The kind of the device that initiated the event. + final PointerDeviceKind? kind; + + /// If this tap is in a series of taps, then this value represents + /// the number in the series this tap is. + final int consecutiveTapCount; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('globalPosition', globalPosition)); + properties.add(DiagnosticsProperty('localPosition', localPosition)); + properties.add(DiagnosticsProperty('kind', kind)); + properties.add(DiagnosticsProperty('consecutiveTapCount', consecutiveTapCount)); + } +} + +/// {@macro flutter.gestures.tap.GestureTapUpCallback} +/// +/// The consecutive tap count at the time the pointer contacted the +/// screen is given by [TapDragUpDetails.consecutiveTapCount]. +/// +/// Used by [BaseTapAndDragGestureRecognizer.onTapUp]. +typedef GestureTapDragUpCallback = void Function(TapDragUpDetails details); + +/// Details for [GestureTapDragUpCallback], such as the number of +/// consecutive taps. +/// +/// See also: +/// +/// * [BaseTapAndDragGestureRecognizer], which passes this information to its +/// [BaseTapAndDragGestureRecognizer.onTapUp] callback. +/// * [TapDragDownDetails], the details for [GestureTapDragDownCallback]. +/// * [TapDragStartDetails], the details for [GestureTapDragStartCallback]. +/// * [TapDragUpdateDetails], the details for [GestureTapDragUpdateCallback]. +/// * [TapDragEndDetails], the details for [GestureTapDragEndCallback]. +class TapDragUpDetails with Diagnosticable { + /// Creates details for a [GestureTapDragUpCallback]. + TapDragUpDetails({ + required this.kind, + required this.globalPosition, + required this.localPosition, + required this.consecutiveTapCount, + }); + + /// The global position at which the pointer contacted the screen. + final Offset globalPosition; + + /// The local position at which the pointer contacted the screen. + final Offset localPosition; + + /// The kind of the device that initiated the event. + final PointerDeviceKind kind; + + /// If this tap is in a series of taps, then this value represents + /// the number in the series this tap is. + final int consecutiveTapCount; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('globalPosition', globalPosition)); + properties.add(DiagnosticsProperty('localPosition', localPosition)); + properties.add(DiagnosticsProperty('kind', kind)); + properties.add(DiagnosticsProperty('consecutiveTapCount', consecutiveTapCount)); + } +} + +/// {@macro flutter.gestures.dragdetails.GestureDragStartCallback} +/// +/// The consecutive tap count at the time the pointer contacted the +/// screen is given by [TapDragStartDetails.consecutiveTapCount]. +/// +/// Used by [BaseTapAndDragGestureRecognizer.onDragStart]. +typedef GestureTapDragStartCallback = void Function(TapDragStartDetails details); + +/// Details for [GestureTapDragStartCallback], such as the number of +/// consecutive taps. +/// +/// See also: +/// +/// * [BaseTapAndDragGestureRecognizer], which passes this information to its +/// [BaseTapAndDragGestureRecognizer.onDragStart] callback. +/// * [TapDragDownDetails], the details for [GestureTapDragDownCallback]. +/// * [TapDragUpDetails], the details for [GestureTapDragUpCallback]. +/// * [TapDragUpdateDetails], the details for [GestureTapDragUpdateCallback]. +/// * [TapDragEndDetails], the details for [GestureTapDragEndCallback]. +class TapDragStartDetails with Diagnosticable { + /// Creates details for a [GestureTapDragStartCallback]. + TapDragStartDetails({ + this.sourceTimeStamp, + required this.globalPosition, + required this.localPosition, + this.kind, + required this.consecutiveTapCount, + }); + + /// Recorded timestamp of the source pointer event that triggered the drag + /// event. + /// + /// Could be null if triggered from proxied events such as accessibility. + final Duration? sourceTimeStamp; + + /// The global position at which the pointer contacted the screen. + /// + /// See also: + /// + /// * [localPosition], which is the [globalPosition] transformed to the + /// coordinate space of the event receiver. + final Offset globalPosition; + + /// The local position in the coordinate system of the event receiver at + /// which the pointer contacted the screen. + final Offset localPosition; + + /// The kind of the device that initiated the event. + final PointerDeviceKind? kind; + + /// If this tap is in a series of taps, then this value represents + /// the number in the series this tap is. + final int consecutiveTapCount; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('sourceTimeStamp', sourceTimeStamp)); + properties.add(DiagnosticsProperty('globalPosition', globalPosition)); + properties.add(DiagnosticsProperty('localPosition', localPosition)); + properties.add(DiagnosticsProperty('kind', kind)); + properties.add(DiagnosticsProperty('consecutiveTapCount', consecutiveTapCount)); + } +} + +/// {@macro flutter.gestures.dragdetails.GestureDragUpdateCallback} +/// +/// The consecutive tap count at the time the pointer contacted the +/// screen is given by [TapDragUpdateDetails.consecutiveTapCount]. +/// +/// Used by [BaseTapAndDragGestureRecognizer.onDragUpdate]. +typedef GestureTapDragUpdateCallback = void Function(TapDragUpdateDetails details); + +/// Details for [GestureTapDragUpdateCallback], such as the number of +/// consecutive taps. +/// +/// See also: +/// +/// * [BaseTapAndDragGestureRecognizer], which passes this information to its +/// [BaseTapAndDragGestureRecognizer.onDragUpdate] callback. +/// * [TapDragDownDetails], the details for [GestureTapDragDownCallback]. +/// * [TapDragUpDetails], the details for [GestureTapDragUpCallback]. +/// * [TapDragStartDetails], the details for [GestureTapDragStartCallback]. +/// * [TapDragEndDetails], the details for [GestureTapDragEndCallback]. +class TapDragUpdateDetails with Diagnosticable { + /// Creates details for a [GestureTapDragUpdateCallback]. + /// + /// If [primaryDelta] is non-null, then its value must match one of the + /// coordinates of [delta] and the other coordinate must be zero. + TapDragUpdateDetails({ + this.sourceTimeStamp, + this.delta = Offset.zero, + this.primaryDelta, + required this.globalPosition, + this.kind, + required this.localPosition, + required this.offsetFromOrigin, + required this.localOffsetFromOrigin, + required this.consecutiveTapCount, + }) : assert( + primaryDelta == null + || (primaryDelta == delta.dx && delta.dy == 0.0) + || (primaryDelta == delta.dy && delta.dx == 0.0), + ); + + /// Recorded timestamp of the source pointer event that triggered the drag + /// event. + /// + /// Could be null if triggered from proxied events such as accessibility. + final Duration? sourceTimeStamp; + + /// The amount the pointer has moved in the coordinate space of the event + /// receiver since the previous update. + /// + /// If the [GestureTapDragUpdateCallback] is for a one-dimensional drag (e.g., + /// a horizontal or vertical drag), then this offset contains only the delta + /// in that direction (i.e., the coordinate in the other direction is zero). + /// + /// Defaults to zero if not specified in the constructor. + final Offset delta; + + /// The amount the pointer has moved along the primary axis in the coordinate + /// space of the event receiver since the previous + /// update. + /// + /// If the [GestureTapDragUpdateCallback] is for a one-dimensional drag (e.g., + /// a horizontal or vertical drag), then this value contains the component of + /// [delta] along the primary axis (e.g., horizontal or vertical, + /// respectively). Otherwise, if the [GestureTapDragUpdateCallback] is for a + /// two-dimensional drag (e.g., a pan), then this value is null. + /// + /// Defaults to null if not specified in the constructor. + final double? primaryDelta; + + /// The pointer's global position when it triggered this update. + /// + /// See also: + /// + /// * [localPosition], which is the [globalPosition] transformed to the + /// coordinate space of the event receiver. + final Offset globalPosition; + + /// The local position in the coordinate system of the event receiver at + /// which the pointer contacted the screen. + /// + /// Defaults to [globalPosition] if not specified in the constructor. + final Offset localPosition; + + /// The kind of the device that initiated the event. + final PointerDeviceKind? kind; + + /// A delta offset from the point where the drag initially contacted + /// the screen to the point where the pointer is currently located in global + /// coordinates (the present [globalPosition]) when this callback is triggered. + /// + /// When considering a [GestureRecognizer] that tracks the number of consecutive taps, + /// this offset is associated with the most recent [PointerDownEvent] that occurred. + final Offset offsetFromOrigin; + + /// A local delta offset from the point where the drag initially contacted + /// the screen to the point where the pointer is currently located in local + /// coordinates (the present [localPosition]) when this callback is triggered. + /// + /// When considering a [GestureRecognizer] that tracks the number of consecutive taps, + /// this offset is associated with the most recent [PointerDownEvent] that occurred. + final Offset localOffsetFromOrigin; + + /// If this tap is in a series of taps, then this value represents + /// the number in the series this tap is. + final int consecutiveTapCount; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('sourceTimeStamp', sourceTimeStamp)); + properties.add(DiagnosticsProperty('delta', delta)); + properties.add(DiagnosticsProperty('primaryDelta', primaryDelta)); + properties.add(DiagnosticsProperty('globalPosition', globalPosition)); + properties.add(DiagnosticsProperty('localPosition', localPosition)); + properties.add(DiagnosticsProperty('kind', kind)); + properties.add(DiagnosticsProperty('offsetFromOrigin', offsetFromOrigin)); + properties.add(DiagnosticsProperty('localOffsetFromOrigin', localOffsetFromOrigin)); + properties.add(DiagnosticsProperty('consecutiveTapCount', consecutiveTapCount)); + } +} + +/// {@macro flutter.gestures.monodrag.GestureDragEndCallback} +/// +/// The consecutive tap count at the time the pointer contacted the +/// screen is given by [TapDragEndDetails.consecutiveTapCount]. +/// +/// Used by [BaseTapAndDragGestureRecognizer.onDragEnd]. +typedef GestureTapDragEndCallback = void Function(TapDragEndDetails endDetails); + +/// Details for [GestureTapDragEndCallback], such as the number of +/// consecutive taps. +/// +/// See also: +/// +/// * [BaseTapAndDragGestureRecognizer], which passes this information to its +/// [BaseTapAndDragGestureRecognizer.onDragEnd] callback. +/// * [TapDragDownDetails], the details for [GestureTapDragDownCallback]. +/// * [TapDragUpDetails], the details for [GestureTapDragUpCallback]. +/// * [TapDragStartDetails], the details for [GestureTapDragStartCallback]. +/// * [TapDragUpdateDetails], the details for [GestureTapDragUpdateCallback]. +class TapDragEndDetails with Diagnosticable { + /// Creates details for a [GestureTapDragEndCallback]. + TapDragEndDetails({ + this.velocity = Velocity.zero, + this.primaryVelocity, + required this.consecutiveTapCount, + }) : assert( + primaryVelocity == null + || primaryVelocity == velocity.pixelsPerSecond.dx + || primaryVelocity == velocity.pixelsPerSecond.dy, + ); + + /// The velocity the pointer was moving when it stopped contacting the screen. + /// + /// Defaults to zero if not specified in the constructor. + final Velocity velocity; + + /// The velocity the pointer was moving along the primary axis when it stopped + /// contacting the screen, in logical pixels per second. + /// + /// If the [GestureTapDragEndCallback] is for a one-dimensional drag (e.g., a + /// horizontal or vertical drag), then this value contains the component of + /// [velocity] along the primary axis (e.g., horizontal or vertical, + /// respectively). Otherwise, if the [GestureTapDragEndCallback] is for a + /// two-dimensional drag (e.g., a pan), then this value is null. + /// + /// Defaults to null if not specified in the constructor. + final double? primaryVelocity; + + /// If this tap is in a series of taps, then this value represents + /// the number in the series this tap is. + final int consecutiveTapCount; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty('velocity', velocity)); + properties.add(DiagnosticsProperty('primaryVelocity', primaryVelocity)); + properties.add(DiagnosticsProperty('consecutiveTapCount', consecutiveTapCount)); + } +} + +/// Signature for when the pointer that previously triggered a +/// [GestureTapDragDownCallback] did not complete. +/// +/// Used by [BaseTapAndDragGestureRecognizer.onCancel]. +typedef GestureCancelCallback = void Function(); + +// A mixin for [OneSequenceGestureRecognizer] that tracks the number of taps +// that occur in a series of [PointerEvent]s and the most recent set of +// [LogicalKeyboardKey]s pressed on the most recent tap down. +// +// A tap is tracked as part of a series of taps if: +// +// 1. The elapsed time between when a [PointerUpEvent] and the subsequent +// [PointerDownEvent] does not exceed [kDoubleTapTimeout]. +// 2. The delta between the position tapped in the global coordinate system +// and the position that was tapped previously must be less than or equal +// to [kDoubleTapSlop]. +// +// This mixin's state, i.e. the series of taps being tracked is reset when +// a tap is tracked that does not meet any of the specifications stated above. +mixin _TapStatusTrackerMixin on OneSequenceGestureRecognizer { + // Public state available to [OneSequenceGestureRecognizer]. + + // The [PointerDownEvent] that was most recently tracked in [addAllowedPointer]. + // + // This value will be null if a [PointerDownEvent] has not been tracked yet in + // [addAllowedPointer] or the timer between two taps has elapsed. + // + // This value is only reset when the timer between a [PointerUpEvent] and the + // [PointerDownEvent] times out or when a new [PointerDownEvent] is tracked in + // [addAllowedPointer]. + PointerDownEvent? get currentDown => _down; + + // The [PointerUpEvent] that was most recently tracked in [handleEvent]. + // + // This value will be null if a [PointerUpEvent] has not been tracked yet in + // [handleEvent] or the timer between two taps has elapsed. + // + // This value is only reset when the timer between a [PointerUpEvent] and the + // [PointerDownEvent] times out or when a new [PointerDownEvent] is tracked in + // [addAllowedPointer]. + PointerUpEvent? get currentUp => _up; + + // The number of consecutive taps that the most recently tracked [PointerDownEvent] + // in [currentDown] represents. + // + // This value defaults to zero, meaning a tap series is not currently being tracked. + // + // When this value is greater than zero it means [addAllowedPointer] has run + // and at least one [PointerDownEvent] belongs to the current series of taps + // being tracked. + // + // [addAllowedPointer] will either increment this value by `1` or set the value to `1` + // depending if the new [PointerDownEvent] is determined to be in the same series as the + // tap that preceded it. If too much time has elapsed between two taps, the recognizer has lost + // in the arena, the gesture has been cancelled, or the recognizer is being disposed then + // this value will be set to `0`, and a new series will begin. + int get consecutiveTapCount => _consecutiveTapCount; + + // The upper limit for the [consecutiveTapCount]. When this limit is reached + // all tap related state is reset and a new tap series is tracked. + // + // If this value is null, [consecutiveTapCount] can grow infinitely large. + int? get maxConsecutiveTap; + + // Private tap state tracked. + PointerDownEvent? _down; + PointerUpEvent? _up; + int _consecutiveTapCount = 0; + + OffsetPair? _originPosition; + int? _previousButtons; + + // For timing taps. + Timer? _consecutiveTapTimer; + Offset? _lastTapOffset; + + /// {@template flutter.gestures.selectionrecognizers.BaseTapAndDragGestureRecognizer.onTapTrackStart} + /// Callback used to indicate that a tap tracking has started upon + /// a [PointerDownEvent]. + /// {@endtemplate} + VoidCallback? onTapTrackStart; + + /// {@template flutter.gestures.selectionrecognizers.BaseTapAndDragGestureRecognizer.onTapTrackReset} + /// Callback used to indicate that a tap tracking has been reset which + /// happens on the next [PointerDownEvent] after the timer between two taps + /// elapses, the recognizer loses the arena, the gesture is cancelled or + /// the recognizer is disposed of. + /// {@endtemplate} + + VoidCallback? onTapTrackReset; + + // When tracking a tap, the [consecutiveTapCount] is incremented if the given tap + // falls under the tolerance specifications and reset to 1 if not. + @override + void addAllowedPointer(PointerDownEvent event) { + super.addAllowedPointer(event); + if (_consecutiveTapTimer != null && !_consecutiveTapTimer!.isActive) { + _tapTrackerReset(); + } + if (maxConsecutiveTap == _consecutiveTapCount) { + _tapTrackerReset(); + } + _up = null; + if (_down != null && !_representsSameSeries(event)) { + // The given tap does not match the specifications of the series of taps being tracked, + // reset the tap count and related state. + _consecutiveTapCount = 1; + } else { + _consecutiveTapCount += 1; + } + _consecutiveTapTimerStop(); + // `_down` must be assigned in this method instead of [handleEvent], + // because [acceptGesture] might be called before [handleEvent], + // which may rely on `_down` to initiate a callback. + _trackTap(event); + } + + @override + void handleEvent(PointerEvent event) { + if (event is PointerMoveEvent) { + final double computedSlop = computeHitSlop(event.kind, gestureSettings); + final bool isSlopPastTolerance = _getGlobalDistance(event, _originPosition) > computedSlop; + + if (isSlopPastTolerance) { + _consecutiveTapTimerStop(); + _previousButtons = null; + _lastTapOffset = null; + } + } else if (event is PointerUpEvent) { + _up = event; + if (_down != null) { + _consecutiveTapTimerStop(); + _consecutiveTapTimerStart(); + } + } else if (event is PointerCancelEvent) { + _tapTrackerReset(); + } + } + + @override + void rejectGesture(int pointer) { + _tapTrackerReset(); + } + + @override + void dispose() { + _tapTrackerReset(); + super.dispose(); + } + + void _trackTap(PointerDownEvent event) { + _down = event; + _previousButtons = event.buttons; + _lastTapOffset = event.position; + _originPosition = OffsetPair(local: event.localPosition, global: event.position); + onTapTrackStart?.call(); + } + + bool _hasSameButton(int buttons) { + assert(_previousButtons != null); + if (buttons == _previousButtons!) { + return true; + } else { + return false; + } + } + + bool _isWithinConsecutiveTapTolerance(Offset secondTapOffset) { + if (_lastTapOffset == null) { + return false; + } + + final Offset difference = secondTapOffset - _lastTapOffset!; + return difference.distance <= kDoubleTapSlop; + } + + bool _representsSameSeries(PointerDownEvent event) { + return _consecutiveTapTimer != null + && _isWithinConsecutiveTapTolerance(event.position) + && _hasSameButton(event.buttons); + } + + void _consecutiveTapTimerStart() { + _consecutiveTapTimer ??= Timer(kDoubleTapTimeout, _consecutiveTapTimerTimeout); + } + + void _consecutiveTapTimerStop() { + if (_consecutiveTapTimer != null) { + _consecutiveTapTimer!.cancel(); + _consecutiveTapTimer = null; + } + } + + void _consecutiveTapTimerTimeout() { + // The consecutive tap timer may time out before a tap down/tap up event is + // fired. In this case we should not reset the tap tracker state immediately. + // Instead we should reset the tap tracker on the next call to [addAllowedPointer], + // if the timer is no longer active. + } + + void _tapTrackerReset() { + // The timer has timed out, i.e. the time between a [PointerUpEvent] and the subsequent + // [PointerDownEvent] exceeded the duration of [kDoubleTapTimeout], so the tap belonging + // to the [PointerDownEvent] cannot be considered part of the same tap series as the + // previous [PointerUpEvent]. + _consecutiveTapTimerStop(); + _previousButtons = null; + _originPosition = null; + _lastTapOffset = null; + _consecutiveTapCount = 0; + _down = null; + _up = null; + onTapTrackReset?.call(); + } +} + +/// A base class for gesture recognizers that recognize taps and movements. +/// +/// Takes on the responsibilities of [TapGestureRecognizer] and +/// [DragGestureRecognizer] in one [GestureRecognizer]. +/// +/// ### Gesture arena behavior +/// +/// [BaseTapAndDragGestureRecognizer] competes on the pointer events of +/// [kPrimaryButton] only when it has at least one non-null `onTap*` +/// or `onDrag*` callback. +/// +/// It will declare defeat if it determines that a gesture is not a +/// tap (e.g. if the pointer is dragged too far while it's contacting the +/// screen) or a drag (e.g. if the pointer was not dragged far enough to +/// be considered a drag. +/// +/// This recognizer will not immediately declare victory for every tap that it +/// recognizes, but it declares victory for every drag. +/// +/// The recognizer will declare victory when all other recognizer's in +/// the arena have lost, if the timer of [kPressTimeout] elapses and a tap +/// series greater than 1 is being tracked, or until the pointer has moved +/// a sufficient global distance from the origin to be considered a drag. +/// +/// If this recognizer loses the arena (either by declaring defeat or by +/// another recognizer declaring victory) while the pointer is contacting the +/// screen, it will fire [onCancel] instead of [onTapUp] or [onDragEnd]. +/// +/// ### When competing with `TapGestureRecognizer` and `DragGestureRecognizer` +/// +/// Similar to [TapGestureRecognizer] and [DragGestureRecognizer], +/// [BaseTapAndDragGestureRecognizer] will not aggressively declare victory when it detects +/// a tap, so when it is competing with those gesture recognizers and others it has a chance +/// of losing. +/// +/// When competing against [TapGestureRecognizer], if the pointer does not move past the tap +/// tolerance, then the recognizer that entered the arena first will win. In this case the +/// gesture detected is a tap. If the pointer does travel past the tap tolerance then this +/// recognizer will be declared winner by default. The gesture detected in this case is a drag. +/// +/// When competing against [DragGestureRecognizer], if the pointer does not move a sufficient +/// global distance to be considered a drag, the recognizers will tie in the arena. If the +/// pointer does travel enough distance then the recognizer that entered the arena +/// first will win. The gesture detected in this case is a drag. +/// +/// {@tool dartpad} +/// This example shows how to use the [TapAndPanGestureRecognizer] along with a +/// [RawGestureDetector] to scale a Widget. +/// +/// ** See code in examples/api/lib/gestures/tap_and_drag/tap_and_drag.0.dart ** +/// {@end-tool} +/// +/// {@tool snippet} +/// +/// This example shows how to hook up [TapAndPanGestureRecognizer]s' to nested +/// [RawGestureDetector]s'. It assumes that the code is being used inside a [State] +/// object with a `_last` field that is then displayed as the child of the gesture detector. +/// +/// In this example, if the pointer has moved past the drag threshold, then the +/// the first [TapAndPanGestureRecognizer] instance to receive the [PointerEvent] +/// will win the arena because the recognizer will immediately declare victory. +/// +/// The first one to receive the event in the example will depend on where on both +/// containers the pointer lands first. If your pointer begins in the overlapping +/// area of both containers, then the inner-most widget will receive the event first. +/// If your pointer begins in the yellow container then it will be the first to +/// receive the event. +/// +/// If the pointer has not moved past the drag threshold, then the first recognizer +/// to enter the arena will win (i.e. they both tie and the gesture arena will call +/// [GestureArenaManager.sweep] so the first member of the arena will win). +/// +/// ```dart +/// RawGestureDetector( +/// gestures: { +/// TapAndPanGestureRecognizer: GestureRecognizerFactoryWithHandlers( +/// () => TapAndPanGestureRecognizer(), +/// (TapAndPanGestureRecognizer instance) { +/// instance +/// ..onTapDown = (TapDragDownDetails details) { setState(() { _last = 'down_a'; }); } +/// ..onDragStart = (TapDragStartDetails details) { setState(() { _last = 'drag_start_a'; }); } +/// ..onDragUpdate = (TapDragUpdateDetails details) { setState(() { _last = 'drag_update_a'; }); } +/// ..onDragEnd = (TapDragEndDetails details) { setState(() { _last = 'drag_end_a'; }); } +/// ..onTapUp = (TapDragUpDetails details) { setState(() { _last = 'up_a'; }); } +/// ..onCancel = () { setState(() { _last = 'cancel_a'; }); }; +/// }, +/// ), +/// }, +/// child: Container( +/// width: 300.0, +/// height: 300.0, +/// color: Colors.yellow, +/// alignment: Alignment.center, +/// child: RawGestureDetector( +/// gestures: { +/// TapAndPanGestureRecognizer: GestureRecognizerFactoryWithHandlers( +/// () => TapAndPanGestureRecognizer(), +/// (TapAndPanGestureRecognizer instance) { +/// instance +/// ..onTapDown = (TapDragDownDetails details) { setState(() { _last = 'down_b'; }); } +/// ..onDragStart = (TapDragStartDetails details) { setState(() { _last = 'drag_start_b'; }); } +/// ..onDragUpdate = (TapDragUpdateDetails details) { setState(() { _last = 'drag_update_b'; }); } +/// ..onDragEnd = (TapDragEndDetails details) { setState(() { _last = 'drag_end_b'; }); } +/// ..onTapUp = (TapDragUpDetails details) { setState(() { _last = 'up_b'; }); } +/// ..onCancel = () { setState(() { _last = 'cancel_b'; }); }; +/// }, +/// ), +/// }, +/// child: Container( +/// width: 150.0, +/// height: 150.0, +/// color: Colors.blue, +/// child: Text(_last), +/// ), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +sealed class BaseTapAndDragGestureRecognizer extends OneSequenceGestureRecognizer with _TapStatusTrackerMixin { + /// Creates a tap and drag gesture recognizer. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + BaseTapAndDragGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + super.allowedButtonsFilter, + }) : _deadline = kPressTimeout, + dragStartBehavior = DragStartBehavior.start; + + /// Configure the behavior of offsets passed to [onDragStart]. + /// + /// If set to [DragStartBehavior.start], the [onDragStart] callback will be called + /// with the position of the pointer at the time this gesture recognizer won + /// the arena. If [DragStartBehavior.down], [onDragStart] will be called with + /// the position of the first detected down event for the pointer. When there + /// are no other gestures competing with this gesture in the arena, there's + /// no difference in behavior between the two settings. + /// + /// For more information about the gesture arena: + /// https://flutter.dev/docs/development/ui/advanced/gestures#gesture-disambiguation + /// + /// By default, the drag start behavior is [DragStartBehavior.start]. + /// + /// See also: + /// + /// * [DragGestureRecognizer.dragStartBehavior], which includes more details and an example. + DragStartBehavior dragStartBehavior; + + /// The frequency at which the [onDragUpdate] callback is called. + /// + /// The value defaults to null, meaning there is no delay for [onDragUpdate] callback. + Duration? dragUpdateThrottleFrequency; + + /// An upper bound for the amount of taps that can belong to one tap series. + /// + /// When this limit is reached the series of taps being tracked by this + /// recognizer will be reset. + @override + int? maxConsecutiveTap; + + /// {@macro flutter.gestures.tap.TapGestureRecognizer.onTapDown} + /// + /// This triggers after the down event, once a short timeout ([kPressTimeout]) has + /// elapsed, or once the gestures has won the arena, whichever comes first. + /// + /// The position of the pointer is provided in the callback's `details` + /// argument, which is a [TapDragDownDetails] object. + /// + /// {@template flutter.gestures.selectionrecognizers.BaseTapAndDragGestureRecognizer.tapStatusTrackerData} + /// The number of consecutive taps, and the keys that were pressed on tap down + /// are also provided in the callback's `details` argument. + /// {@endtemplate} + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [TapDragDownDetails], which is passed as an argument to this callback. + GestureTapDragDownCallback? onTapDown; + + /// {@macro flutter.gestures.tap.TapGestureRecognizer.onTapUp} + /// + /// This triggers on the up event, if the recognizer wins the arena with it + /// or has previously won. + /// + /// The position of the pointer is provided in the callback's `details` + /// argument, which is a [TapDragUpDetails] object. + /// + /// {@macro flutter.gestures.selectionrecognizers.BaseTapAndDragGestureRecognizer.tapStatusTrackerData} + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [TapDragUpDetails], which is passed as an argument to this callback. + GestureTapDragUpCallback? onTapUp; + + /// {@macro flutter.gestures.monodrag.DragGestureRecognizer.onStart} + /// + /// The position of the pointer is provided in the callback's `details` + /// argument, which is a [TapDragStartDetails] object. The [dragStartBehavior] + /// determines this position. + /// + /// {@macro flutter.gestures.selectionrecognizers.BaseTapAndDragGestureRecognizer.tapStatusTrackerData} + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [TapDragStartDetails], which is passed as an argument to this callback. + GestureTapDragStartCallback? onDragStart; + + /// {@macro flutter.gestures.monodrag.DragGestureRecognizer.onUpdate} + /// + /// The distance traveled by the pointer since the last update is provided in + /// the callback's `details` argument, which is a [TapDragUpdateDetails] object. + /// + /// {@macro flutter.gestures.selectionrecognizers.BaseTapAndDragGestureRecognizer.tapStatusTrackerData} + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [TapDragUpdateDetails], which is passed as an argument to this callback. + GestureTapDragUpdateCallback? onDragUpdate; + + /// {@macro flutter.gestures.monodrag.DragGestureRecognizer.onEnd} + /// + /// The velocity is provided in the callback's `details` argument, which is a + /// [TapDragEndDetails] object. + /// + /// {@macro flutter.gestures.selectionrecognizers.BaseTapAndDragGestureRecognizer.tapStatusTrackerData} + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [TapDragEndDetails], which is passed as an argument to this callback. + GestureTapDragEndCallback? onDragEnd; + + /// The pointer that previously triggered [onTapDown] did not complete. + /// + /// This is called when a [PointerCancelEvent] is tracked when the [onTapDown] callback + /// was previously called. + /// + /// It may also be called if a [PointerUpEvent] is tracked after the pointer has moved + /// past the tap tolerance but not past the drag tolerance, and the recognizer has not + /// yet won the arena. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + GestureCancelCallback? onCancel; + + // Tap related state. + bool _pastSlopTolerance = false; + bool _sentTapDown = false; + bool _wonArenaForPrimaryPointer = false; + + // Primary pointer being tracked by this recognizer. + int? _primaryPointer; + Timer? _deadlineTimer; + // The recognizer will call [onTapDown] after this amount of time has elapsed + // since starting to track the primary pointer. + // + // [onTapDown] will not be called if the primary pointer is + // accepted, rejected, or all pointers are up or canceled before [_deadline]. + final Duration _deadline; + + // Drag related state. + _DragState _dragState = _DragState.ready; + PointerEvent? _start; + late OffsetPair _initialPosition; + late double _globalDistanceMoved; + late double _globalDistanceMovedAllAxes; + OffsetPair? _correctedPosition; + + // For drag update throttle. + TapDragUpdateDetails? _lastDragUpdateDetails; + Timer? _dragUpdateThrottleTimer; + + final Set _acceptedActivePointers = {}; + + Offset _getDeltaForDetails(Offset delta); + double? _getPrimaryValueFromOffset(Offset value); + bool _hasSufficientGlobalDistanceToAccept(PointerDeviceKind pointerDeviceKind); + + // Drag updates may require throttling to avoid excessive updating, such as for text layouts in text + // fields. The frequency of invocations is controlled by the [dragUpdateThrottleFrequency]. + // + // Once the drag gesture ends, any pending drag update will be fired + // immediately. See [_checkDragEnd]. + void _handleDragUpdateThrottled() { + assert(_lastDragUpdateDetails != null); + if (onDragUpdate != null) { + invokeCallback('onDragUpdate', () => onDragUpdate!(_lastDragUpdateDetails!)); + } + _dragUpdateThrottleTimer = null; + _lastDragUpdateDetails = null; + } + + @override + bool isPointerAllowed(PointerEvent event) { + if (_primaryPointer == null) { + switch (event.buttons) { + case kPrimaryButton: + if (onTapDown == null && + onDragStart == null && + onDragUpdate == null && + onDragEnd == null && + onTapUp == null && + onCancel == null) { + return false; + } + default: + return false; + } + } else { + if (event.pointer != _primaryPointer) { + return false; + } + } + + return super.isPointerAllowed(event as PointerDownEvent); + } + + @override + void addAllowedPointer(PointerDownEvent event) { + if (_dragState == _DragState.ready) { + super.addAllowedPointer(event); + _primaryPointer = event.pointer; + _globalDistanceMoved = 0.0; + _globalDistanceMovedAllAxes = 0.0; + _dragState = _DragState.possible; + _initialPosition = OffsetPair(global: event.position, local: event.localPosition); + _deadlineTimer = Timer(_deadline, () => _didExceedDeadlineWithEvent(event)); + } + } + + @override + void handleNonAllowedPointer(PointerDownEvent event) { + // There can be multiple drags simultaneously. Their effects are combined. + if (event.buttons != kPrimaryButton) { + if (!_wonArenaForPrimaryPointer) { + super.handleNonAllowedPointer(event); + } + } + } + + @override + void acceptGesture(int pointer) { + if (pointer != _primaryPointer) { + return; + } + + _stopDeadlineTimer(); + + assert(!_acceptedActivePointers.contains(pointer)); + _acceptedActivePointers.add(pointer); + + // Called when this recognizer is accepted by the [GestureArena]. + if (currentDown != null) { + _checkTapDown(currentDown!); + } + + _wonArenaForPrimaryPointer = true; + + // resolve(GestureDisposition.accepted) will be called when the [PointerMoveEvent] has + // moved a sufficient global distance. + if (_start != null) { + assert(_dragState == _DragState.accepted); + assert(currentUp == null); + _acceptDrag(_start!); + } + + if (currentUp != null) { + _checkTapUp(currentUp!); + } + } + + @override + void didStopTrackingLastPointer(int pointer) { + switch (_dragState) { + case _DragState.ready: + _checkCancel(); + resolve(GestureDisposition.rejected); + + case _DragState.possible: + if (_pastSlopTolerance) { + // This means the pointer was not accepted as a tap. + if (_wonArenaForPrimaryPointer) { + // If the recognizer has already won the arena for the primary pointer being tracked + // but the pointer has exceeded the tap tolerance, then the pointer is accepted as a + // drag gesture. + if (currentDown != null) { + if (!_acceptedActivePointers.remove(pointer)) { + resolvePointer(pointer, GestureDisposition.rejected); + } + _dragState = _DragState.accepted; + _acceptDrag(currentDown!); + _checkDragEnd(); + } + } else { + _checkCancel(); + resolve(GestureDisposition.rejected); + } + } else { + // The pointer is accepted as a tap. + if (currentUp != null) { + _checkTapUp(currentUp!); + } + } + + case _DragState.accepted: + // For the case when the pointer has been accepted as a drag. + // Meaning [_checkTapDown] and [_checkDragStart] have already ran. + _checkDragEnd(); + } + + _stopDeadlineTimer(); + _dragState = _DragState.ready; + _pastSlopTolerance = false; + } + + @override + void handleEvent(PointerEvent event) { + if (event.pointer != _primaryPointer) { + return; + } + super.handleEvent(event); + if (event is PointerMoveEvent) { + // Receiving a [PointerMoveEvent], does not automatically mean the pointer + // being tracked is doing a drag gesture. There is some drift that can happen + // between the initial [PointerDownEvent] and subsequent [PointerMoveEvent]s. + // Accessing [_pastSlopTolerance] lets us know if our tap has moved past the + // acceptable tolerance. If the pointer does not move past this tolerance than + // it is not considered a drag. + // + // To be recognized as a drag, the [PointerMoveEvent] must also have moved + // a sufficient global distance from the initial [PointerDownEvent] to be + // accepted as a drag. This logic is handled in [_hasSufficientGlobalDistanceToAccept]. + // + // The recognizer will also detect the gesture as a drag when the pointer + // has been accepted and it has moved past the [slopTolerance] but has not moved + // a sufficient global distance from the initial position to be considered a drag. + // In this case since the gesture cannot be a tap, it defaults to a drag. + final double computedSlop = computeHitSlop(event.kind, gestureSettings); + _pastSlopTolerance = _pastSlopTolerance || _getGlobalDistance(event, _initialPosition) > computedSlop; + + if (_dragState == _DragState.accepted) { + _checkDragUpdate(event); + } else if (_dragState == _DragState.possible) { + if (_start == null) { + // Only check for a drag if the start of a drag was not already identified. + _checkDrag(event); + } + + // This can occur when the recognizer is accepted before a [PointerMoveEvent] has been + // received that moves the pointer a sufficient global distance to be considered a drag. + if (_start != null) { + _acceptDrag(_start!); + } + } + } else if (event is PointerUpEvent) { + if (_dragState == _DragState.possible) { + // The drag has not been accepted before a [PointerUpEvent], therefore the recognizer + // attempts to recognize a tap. + stopTrackingIfPointerNoLongerDown(event); + } else if (_dragState == _DragState.accepted) { + _giveUpPointer(event.pointer); + } + } else if (event is PointerCancelEvent) { + _dragState = _DragState.ready; + _giveUpPointer(event.pointer); + } + } + + @override + void rejectGesture(int pointer) { + if (pointer != _primaryPointer) { + return; + } + super.rejectGesture(pointer); + + _stopDeadlineTimer(); + _giveUpPointer(pointer); + _resetTaps(); + _resetDragUpdateThrottle(); + } + + @override + void dispose() { + _stopDeadlineTimer(); + _resetDragUpdateThrottle(); + super.dispose(); + } + + @override + String get debugDescription => 'tap_and_drag'; + + void _acceptDrag(PointerEvent event) { + if (!_wonArenaForPrimaryPointer) { + return; + } + if (dragStartBehavior == DragStartBehavior.start) { + _initialPosition = _initialPosition + OffsetPair(global: event.delta, local: event.localDelta); + } + _checkDragStart(event); + if (event.localDelta != Offset.zero) { + final Matrix4? localToGlobal = event.transform != null ? Matrix4.tryInvert(event.transform!) : null; + final Offset correctedLocalPosition = _initialPosition.local + event.localDelta; + final Offset globalUpdateDelta = PointerEvent.transformDeltaViaPositions( + untransformedEndPosition: correctedLocalPosition, + untransformedDelta: event.localDelta, + transform: localToGlobal, + ); + final OffsetPair updateDelta = OffsetPair(local: event.localDelta, global: globalUpdateDelta); + _correctedPosition = _initialPosition + updateDelta; // Only adds delta for down behaviour + _checkDragUpdate(event); + _correctedPosition = null; + } + } + + void _checkDrag(PointerMoveEvent event) { + final Matrix4? localToGlobalTransform = event.transform == null ? null : Matrix4.tryInvert(event.transform!); + final Offset movedLocally = _getDeltaForDetails(event.localDelta); + _globalDistanceMoved += PointerEvent.transformDeltaViaPositions( + transform: localToGlobalTransform, + untransformedDelta: movedLocally, + untransformedEndPosition: event.localPosition + ).distance * (_getPrimaryValueFromOffset(movedLocally) ?? 1).sign; + _globalDistanceMovedAllAxes += PointerEvent.transformDeltaViaPositions( + transform: localToGlobalTransform, + untransformedDelta: event.localDelta, + untransformedEndPosition: event.localPosition + ).distance * 1.sign; + if (_hasSufficientGlobalDistanceToAccept(event.kind) + || (_wonArenaForPrimaryPointer && _globalDistanceMovedAllAxes.abs() > computePanSlop(event.kind, gestureSettings))) { + _start = event; + _dragState = _DragState.accepted; + if (!_wonArenaForPrimaryPointer) { + resolve(GestureDisposition.accepted); + } + } + } + + void _checkTapDown(PointerDownEvent event) { + if (_sentTapDown) { + return; + } + + final TapDragDownDetails details = TapDragDownDetails( + globalPosition: event.position, + localPosition: event.localPosition, + kind: getKindForPointer(event.pointer), + consecutiveTapCount: consecutiveTapCount, + ); + + if (onTapDown != null) { + invokeCallback('onTapDown', () => onTapDown!(details)); + } + + _sentTapDown = true; + } + + void _checkTapUp(PointerUpEvent event) { + if (!_wonArenaForPrimaryPointer) { + return; + } + + final TapDragUpDetails upDetails = TapDragUpDetails( + kind: event.kind, + globalPosition: event.position, + localPosition: event.localPosition, + consecutiveTapCount: consecutiveTapCount, + ); + + if (onTapUp != null) { + invokeCallback('onTapUp', () => onTapUp!(upDetails)); + } + + _resetTaps(); + if (!_acceptedActivePointers.remove(event.pointer)) { + resolvePointer(event.pointer, GestureDisposition.rejected); + } + } + + void _checkDragStart(PointerEvent event) { + if (onDragStart != null) { + final TapDragStartDetails details = TapDragStartDetails( + sourceTimeStamp: event.timeStamp, + globalPosition: _initialPosition.global, + localPosition: _initialPosition.local, + kind: getKindForPointer(event.pointer), + consecutiveTapCount: consecutiveTapCount, + ); + + invokeCallback('onDragStart', () => onDragStart!(details)); + } + + _start = null; + } + + void _checkDragUpdate(PointerEvent event) { + final Offset globalPosition = _correctedPosition != null ? _correctedPosition!.global : event.position; + final Offset localPosition = _correctedPosition != null ? _correctedPosition!.local : event.localPosition; + + final TapDragUpdateDetails details = TapDragUpdateDetails( + sourceTimeStamp: event.timeStamp, + delta: event.localDelta, + globalPosition: globalPosition, + kind: getKindForPointer(event.pointer), + localPosition: localPosition, + offsetFromOrigin: globalPosition - _initialPosition.global, + localOffsetFromOrigin: localPosition - _initialPosition.local, + consecutiveTapCount: consecutiveTapCount, + ); + + if (dragUpdateThrottleFrequency != null) { + _lastDragUpdateDetails = details; + // Only schedule a new timer if there's not one pending. + _dragUpdateThrottleTimer ??= Timer(dragUpdateThrottleFrequency!, _handleDragUpdateThrottled); + } else { + if (onDragUpdate != null) { + invokeCallback('onDragUpdate', () => onDragUpdate!(details)); + } + } + } + + void _checkDragEnd() { + if (_dragUpdateThrottleTimer != null) { + // If there's already an update scheduled, trigger it immediately and + // cancel the timer. + _dragUpdateThrottleTimer!.cancel(); + _handleDragUpdateThrottled(); + } + + final TapDragEndDetails endDetails = + TapDragEndDetails( + primaryVelocity: 0.0, + consecutiveTapCount: consecutiveTapCount, + ); + + if (onDragEnd != null) { + invokeCallback('onDragEnd', () => onDragEnd!(endDetails)); + } + + _resetTaps(); + _resetDragUpdateThrottle(); + } + + void _checkCancel() { + if (!_sentTapDown) { + // Do not fire tap cancel if [onTapDown] was never called. + return; + } + if (onCancel != null) { + invokeCallback('onCancel', onCancel!); + } + _resetDragUpdateThrottle(); + _resetTaps(); + } + + void _didExceedDeadlineWithEvent(PointerDownEvent event) { + _didExceedDeadline(); + } + + void _didExceedDeadline() { + if (currentDown != null) { + _checkTapDown(currentDown!); + + if (consecutiveTapCount > 1) { + // If our consecutive tap count is greater than 1, i.e. is a double tap or greater, + // then this recognizer declares victory to prevent the [LongPressGestureRecognizer] + // from declaring itself the winner if a double tap is held for too long. + resolve(GestureDisposition.accepted); + } + } + } + + void _giveUpPointer(int pointer) { + stopTrackingPointer(pointer); + // If the pointer was never accepted, then it is rejected since this recognizer is no longer + // interested in winning the gesture arena for it. + if (!_acceptedActivePointers.remove(pointer)) { + resolvePointer(pointer, GestureDisposition.rejected); + } + } + + void _resetTaps() { + _sentTapDown = false; + _wonArenaForPrimaryPointer = false; + _primaryPointer = null; + } + + void _resetDragUpdateThrottle() { + if (dragUpdateThrottleFrequency == null) { + return; + } + _lastDragUpdateDetails = null; + if (_dragUpdateThrottleTimer != null) { + _dragUpdateThrottleTimer!.cancel(); + _dragUpdateThrottleTimer = null; + } + } + + void _stopDeadlineTimer() { + if (_deadlineTimer != null) { + _deadlineTimer!.cancel(); + _deadlineTimer = null; + } + } +} + +/// Recognizes taps along with movement in the horizontal direction. +/// +/// Before this recognizer has won the arena for the primary pointer being tracked, +/// it will only accept a drag on the horizontal axis. If a drag is detected after +/// this recognizer has won the arena then it will accept a drag on any axis. +/// +/// See also: +/// +/// * [BaseTapAndDragGestureRecognizer], for the class that provides the main +/// implementation details of this recognizer. +/// * [TapAndPanGestureRecognizer], for a similar recognizer that accepts a drag +/// on any axis regardless if the recognizer has won the arena for the primary +/// pointer being tracked. +/// * [HorizontalDragGestureRecognizer], for a similar recognizer that only recognizes +/// horizontal movement. +class TapAndHorizontalDragGestureRecognizer extends BaseTapAndDragGestureRecognizer { + /// Create a gesture recognizer for interactions in the horizontal axis. + /// + /// {@macro flutter.gestures.GestureRecognizer.supportedDevices} + TapAndHorizontalDragGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + }); + + @override + bool _hasSufficientGlobalDistanceToAccept(PointerDeviceKind pointerDeviceKind) { + return _globalDistanceMoved.abs() > computeHitSlop(pointerDeviceKind, gestureSettings); + } + + @override + Offset _getDeltaForDetails(Offset delta) => Offset(delta.dx, 0.0); + + @override + double _getPrimaryValueFromOffset(Offset value) => value.dx; + + @override + String get debugDescription => 'tap and horizontal drag'; +} + +/// {@template flutter.gestures.selectionrecognizers.TapAndPanGestureRecognizer} +/// Recognizes taps along with both horizontal and vertical movement. +/// +/// This recognizer will accept a drag on any axis, regardless if it has won the +/// arena for the primary pointer being tracked. +/// +/// See also: +/// +/// * [BaseTapAndDragGestureRecognizer], for the class that provides the main +/// implementation details of this recognizer. +/// * [TapAndHorizontalDragGestureRecognizer], for a similar recognizer that +/// only accepts horizontal drags before it has won the arena for the primary +/// pointer being tracked. +/// * [PanGestureRecognizer], for a similar recognizer that only recognizes +/// movement. +/// {@endtemplate} +class TapAndPanGestureRecognizer extends BaseTapAndDragGestureRecognizer { + /// Create a gesture recognizer for interactions on a plane. + TapAndPanGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + }); + + @override + bool _hasSufficientGlobalDistanceToAccept(PointerDeviceKind pointerDeviceKind) { + return _globalDistanceMoved.abs() > computePanSlop(pointerDeviceKind, gestureSettings); + } + + @override + Offset _getDeltaForDetails(Offset delta) => delta; + + @override + double? _getPrimaryValueFromOffset(Offset value) => null; + + @override + String get debugDescription => 'tap and pan'; +} + +@Deprecated( + 'Use TapAndPanGestureRecognizer instead. ' + 'TapAndPanGestureRecognizer works exactly the same but has a more disambiguated name from BaseTapAndDragGestureRecognizer. ' + 'This feature was deprecated after v3.9.0-19.0.pre.' +) +/// {@macro flutter.gestures.selectionrecognizers.TapAndPanGestureRecognizer} +class TapAndDragGestureRecognizer extends BaseTapAndDragGestureRecognizer { + /// Create a gesture recognizer for interactions on a plane. + @Deprecated( + 'Use TapAndPanGestureRecognizer instead. ' + 'TapAndPanGestureRecognizer works exactly the same but has a more disambiguated name from BaseTapAndDragGestureRecognizer. ' + 'This feature was deprecated after v3.9.0-19.0.pre.' + ) + TapAndDragGestureRecognizer({ + super.debugOwner, + super.supportedDevices, + }); + + @override + bool _hasSufficientGlobalDistanceToAccept(PointerDeviceKind pointerDeviceKind) { + return _globalDistanceMoved.abs() > computePanSlop(pointerDeviceKind, gestureSettings); + } + + @override + Offset _getDeltaForDetails(Offset delta) => delta; + + @override + double? _getPrimaryValueFromOffset(Offset value) => null; + + @override + String get debugDescription => 'tap and pan'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/team.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/team.dart new file mode 100644 index 0000000000000000000000000000000000000000..2216ef6a10e7a4d5a0fc763368f21d6d8f91425d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/team.dart @@ -0,0 +1,157 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'arena.dart'; +import 'binding.dart'; + +export 'arena.dart' show GestureArenaEntry, GestureArenaMember; + +class _CombiningGestureArenaEntry implements GestureArenaEntry { + _CombiningGestureArenaEntry(this._combiner, this._member); + + final _CombiningGestureArenaMember _combiner; + final GestureArenaMember _member; + + @override + void resolve(GestureDisposition disposition) { + _combiner._resolve(_member, disposition); + } +} + +class _CombiningGestureArenaMember extends GestureArenaMember { + _CombiningGestureArenaMember(this._owner, this._pointer); + + final GestureArenaTeam _owner; + final List _members = []; + final int _pointer; + + bool _resolved = false; + GestureArenaMember? _winner; + GestureArenaEntry? _entry; + + @override + void acceptGesture(int pointer) { + assert(_pointer == pointer); + assert(_winner != null || _members.isNotEmpty); + _close(); + _winner ??= _owner.captain ?? _members[0]; + for (final GestureArenaMember member in _members) { + if (member != _winner) { + member.rejectGesture(pointer); + } + } + _winner!.acceptGesture(pointer); + } + + @override + void rejectGesture(int pointer) { + assert(_pointer == pointer); + _close(); + for (final GestureArenaMember member in _members) { + member.rejectGesture(pointer); + } + } + + void _close() { + assert(!_resolved); + _resolved = true; + final _CombiningGestureArenaMember? combiner = _owner._combiners.remove(_pointer); + assert(combiner == this); + } + + GestureArenaEntry _add(int pointer, GestureArenaMember member) { + assert(!_resolved); + assert(_pointer == pointer); + _members.add(member); + _entry ??= GestureBinding.instance.gestureArena.add(pointer, this); + return _CombiningGestureArenaEntry(this, member); + } + + void _resolve(GestureArenaMember member, GestureDisposition disposition) { + if (_resolved) { + return; + } + if (disposition == GestureDisposition.rejected) { + _members.remove(member); + member.rejectGesture(_pointer); + if (_members.isEmpty) { + _entry!.resolve(disposition); + } + } else { + assert(disposition == GestureDisposition.accepted); + _winner ??= _owner.captain ?? member; + _entry!.resolve(disposition); + } + } +} + +/// A group of [GestureArenaMember] objects that are competing as a unit in the +/// [GestureArenaManager]. +/// +/// Normally, a recognizer competes directly in the [GestureArenaManager] to +/// recognize a sequence of pointer events as a gesture. With a +/// [GestureArenaTeam], recognizers can compete in the arena in a group with +/// other recognizers. Arena teams may have a captain which wins the arena on +/// behalf of its team. +/// +/// When gesture recognizers are in a team together without a captain, then once +/// there are no other competing gestures in the arena, the first gesture to +/// have been added to the team automatically wins, instead of the gestures +/// continuing to compete against each other. +/// +/// When gesture recognizers are in a team with a captain, then once one of the +/// team members claims victory or there are no other competing gestures in the +/// arena, the captain wins the arena, and all other team members lose. +/// +/// For example, [Slider] uses a team without a captain to support both a +/// [HorizontalDragGestureRecognizer] and a [TapGestureRecognizer], but without +/// the drag recognizer having to wait until the user has dragged outside the +/// slop region of the tap gesture before triggering. Since they compete as a +/// team, as soon as any other recognizers are out of the arena, the drag +/// recognizer wins, even if the user has not actually dragged yet. On the other +/// hand, if the tap can win outright, before the other recognizers are taken +/// out of the arena (e.g. if the slider is in a vertical scrolling list and the +/// user places their finger on the touch surface then lifts it, so that neither +/// the horizontal nor vertical drag recognizers can claim victory) the tap +/// recognizer still actually wins, despite being in the team. +/// +/// [AndroidView] uses a team with a captain to decide which gestures are +/// forwarded to the native view. For example if we want to forward taps and +/// vertical scrolls to a native Android view, [TapGestureRecognizer]s and +/// [VerticalDragGestureRecognizer] are added to a team with a captain (the +/// captain is set to be a gesture recognizer that never explicitly claims the +/// gesture). +/// +/// The captain allows [AndroidView] to know when any gestures in the team has +/// been recognized (or all other arena members are out), once the captain wins +/// the gesture is forwarded to the Android view. +/// +/// To assign a gesture recognizer to a team, set +/// [OneSequenceGestureRecognizer.team] to an instance of [GestureArenaTeam]. +class GestureArenaTeam { + final Map _combiners = {}; + + /// A member that wins on behalf of the entire team. + /// + /// If not null, when any one of the [GestureArenaTeam] members claims victory + /// the captain accepts the gesture. + /// If null, the member that claims a victory accepts the gesture. + GestureArenaMember? captain; + + /// Adds a new member to the arena on behalf of this team. + /// + /// Used by [GestureRecognizer] subclasses that wish to compete in the arena + /// using this team. + /// + /// To assign a gesture recognizer to a team, see + /// [OneSequenceGestureRecognizer.team]. + GestureArenaEntry add(int pointer, GestureArenaMember member) { + final _CombiningGestureArenaMember combiner = _combiners.putIfAbsent( + pointer, + () => _CombiningGestureArenaMember(this, pointer), + ); + return combiner._add(pointer, member); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart new file mode 100644 index 0000000000000000000000000000000000000000..f448cece1c6ffc0f827968cfbfa5a18b6805a708 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart @@ -0,0 +1,466 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'package:flutter/foundation.dart'; + +import 'binding.dart'; +import 'events.dart'; +import 'lsq_solver.dart'; + +export 'dart:ui' show Offset, PointerDeviceKind; + +/// A velocity in two dimensions. +@immutable +class Velocity { + /// Creates a [Velocity]. + const Velocity({ + required this.pixelsPerSecond, + }); + + /// A velocity that isn't moving at all. + static const Velocity zero = Velocity(pixelsPerSecond: Offset.zero); + + /// The number of pixels per second of velocity in the x and y directions. + final Offset pixelsPerSecond; + + /// Return the negation of a velocity. + Velocity operator -() => Velocity(pixelsPerSecond: -pixelsPerSecond); + + /// Return the difference of two velocities. + Velocity operator -(Velocity other) { + return Velocity(pixelsPerSecond: pixelsPerSecond - other.pixelsPerSecond); + } + + /// Return the sum of two velocities. + Velocity operator +(Velocity other) { + return Velocity(pixelsPerSecond: pixelsPerSecond + other.pixelsPerSecond); + } + + /// Return a velocity whose magnitude has been clamped to [minValue] + /// and [maxValue]. + /// + /// If the magnitude of this Velocity is less than minValue then return a new + /// Velocity with the same direction and with magnitude [minValue]. Similarly, + /// if the magnitude of this Velocity is greater than maxValue then return a + /// new Velocity with the same direction and magnitude [maxValue]. + /// + /// If the magnitude of this Velocity is within the specified bounds then + /// just return this. + Velocity clampMagnitude(double minValue, double maxValue) { + assert(minValue >= 0.0); + assert(maxValue >= 0.0 && maxValue >= minValue); + final double valueSquared = pixelsPerSecond.distanceSquared; + if (valueSquared > maxValue * maxValue) { + return Velocity(pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) * maxValue); + } + if (valueSquared < minValue * minValue) { + return Velocity(pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) * minValue); + } + return this; + } + + @override + bool operator ==(Object other) { + return other is Velocity + && other.pixelsPerSecond == pixelsPerSecond; + } + + @override + int get hashCode => pixelsPerSecond.hashCode; + + @override + String toString() => 'Velocity(${pixelsPerSecond.dx.toStringAsFixed(1)}, ${pixelsPerSecond.dy.toStringAsFixed(1)})'; +} + +/// A two dimensional velocity estimate. +/// +/// VelocityEstimates are computed by [VelocityTracker.getVelocityEstimate]. An +/// estimate's [confidence] measures how well the velocity tracker's position +/// data fit a straight line, [duration] is the time that elapsed between the +/// first and last position sample used to compute the velocity, and [offset] +/// is similarly the difference between the first and last positions. +/// +/// See also: +/// +/// * [VelocityTracker], which computes [VelocityEstimate]s. +/// * [Velocity], which encapsulates (just) a velocity vector and provides some +/// useful velocity operations. +class VelocityEstimate { + /// Creates a dimensional velocity estimate. + const VelocityEstimate({ + required this.pixelsPerSecond, + required this.confidence, + required this.duration, + required this.offset, + }); + + /// The number of pixels per second of velocity in the x and y directions. + final Offset pixelsPerSecond; + + /// A value between 0.0 and 1.0 that indicates how well [VelocityTracker] + /// was able to fit a straight line to its position data. + /// + /// The value of this property is 1.0 for a perfect fit, 0.0 for a poor fit. + final double confidence; + + /// The time that elapsed between the first and last position sample used + /// to compute [pixelsPerSecond]. + final Duration duration; + + /// The difference between the first and last position sample used + /// to compute [pixelsPerSecond]. + final Offset offset; + + @override + String toString() => 'VelocityEstimate(${pixelsPerSecond.dx.toStringAsFixed(1)}, ${pixelsPerSecond.dy.toStringAsFixed(1)}; offset: $offset, duration: $duration, confidence: ${confidence.toStringAsFixed(1)})'; +} + +class _PointAtTime { + const _PointAtTime(this.point, this.time); + + final Duration time; + final Offset point; + + @override + String toString() => '_PointAtTime($point at $time)'; +} + +/// Computes a pointer's velocity based on data from [PointerMoveEvent]s. +/// +/// The input data is provided by calling [addPosition]. Adding data is cheap. +/// +/// To obtain a velocity, call [getVelocity] or [getVelocityEstimate]. This will +/// compute the velocity based on the data added so far. Only call these when +/// you need to use the velocity, as they are comparatively expensive. +/// +/// The quality of the velocity estimation will be better if more data points +/// have been received. +class VelocityTracker { + + /// Create a new velocity tracker for a pointer [kind]. + VelocityTracker.withKind(this.kind); + + static const int _assumePointerMoveStoppedMilliseconds = 40; + static const int _historySize = 20; + static const int _horizonMilliseconds = 100; + static const int _minSampleSize = 3; + + /// The kind of pointer this tracker is for. + final PointerDeviceKind kind; + + // Time difference since the last sample was added + Stopwatch get _sinceLastSample { + _stopwatch ??= GestureBinding.instance.samplingClock.stopwatch(); + return _stopwatch!; + } + Stopwatch? _stopwatch; + + // Circular buffer; current sample at _index. + final List<_PointAtTime?> _samples = List<_PointAtTime?>.filled(_historySize, null); + int _index = 0; + + /// Adds a position as the given time to the tracker. + void addPosition(Duration time, Offset position) { + _sinceLastSample.start(); + _sinceLastSample.reset(); + _index += 1; + if (_index == _historySize) { + _index = 0; + } + _samples[_index] = _PointAtTime(position, time); + } + + /// Returns an estimate of the velocity of the object being tracked by the + /// tracker given the current information available to the tracker. + /// + /// Information is added using [addPosition]. + /// + /// Returns null if there is no data on which to base an estimate. + VelocityEstimate? getVelocityEstimate() { + // Has user recently moved since last sample? + if (_sinceLastSample.elapsedMilliseconds > _assumePointerMoveStoppedMilliseconds) { + return const VelocityEstimate( + pixelsPerSecond: Offset.zero, + confidence: 1.0, + duration: Duration.zero, + offset: Offset.zero, + ); + } + + final List x = []; + final List y = []; + final List w = []; + final List time = []; + int sampleCount = 0; + int index = _index; + + final _PointAtTime? newestSample = _samples[index]; + if (newestSample == null) { + return null; + } + + _PointAtTime previousSample = newestSample; + _PointAtTime oldestSample = newestSample; + + // Starting with the most recent PointAtTime sample, iterate backwards while + // the samples represent continuous motion. + do { + final _PointAtTime? sample = _samples[index]; + if (sample == null) { + break; + } + + final double age = (newestSample.time - sample.time).inMicroseconds.toDouble() / 1000; + final double delta = (sample.time - previousSample.time).inMicroseconds.abs().toDouble() / 1000; + previousSample = sample; + if (age > _horizonMilliseconds || delta > _assumePointerMoveStoppedMilliseconds) { + break; + } + + oldestSample = sample; + final Offset position = sample.point; + x.add(position.dx); + y.add(position.dy); + w.add(1.0); + time.add(-age); + index = (index == 0 ? _historySize : index) - 1; + + sampleCount += 1; + } while (sampleCount < _historySize); + + if (sampleCount >= _minSampleSize) { + final LeastSquaresSolver xSolver = LeastSquaresSolver(time, x, w); + final PolynomialFit? xFit = xSolver.solve(2); + if (xFit != null) { + final LeastSquaresSolver ySolver = LeastSquaresSolver(time, y, w); + final PolynomialFit? yFit = ySolver.solve(2); + if (yFit != null) { + return VelocityEstimate( // convert from pixels/ms to pixels/s + pixelsPerSecond: Offset(xFit.coefficients[1] * 1000, yFit.coefficients[1] * 1000), + confidence: xFit.confidence * yFit.confidence, + duration: newestSample.time - oldestSample.time, + offset: newestSample.point - oldestSample.point, + ); + } + } + } + + // We're unable to make a velocity estimate but we did have at least one + // valid pointer position. + return VelocityEstimate( + pixelsPerSecond: Offset.zero, + confidence: 1.0, + duration: newestSample.time - oldestSample.time, + offset: newestSample.point - oldestSample.point, + ); + } + + /// Computes the velocity of the pointer at the time of the last + /// provided data point. + /// + /// This can be expensive. Only call this when you need the velocity. + /// + /// Returns [Velocity.zero] if there is no data from which to compute an + /// estimate or if the estimated velocity is zero. + Velocity getVelocity() { + final VelocityEstimate? estimate = getVelocityEstimate(); + if (estimate == null || estimate.pixelsPerSecond == Offset.zero) { + return Velocity.zero; + } + return Velocity(pixelsPerSecond: estimate.pixelsPerSecond); + } +} + +/// A [VelocityTracker] subclass that provides a close approximation of iOS +/// scroll view's velocity estimation strategy. +/// +/// The estimated velocity reported by this class is a close approximation of +/// the velocity an iOS scroll view would report with the same +/// [PointerMoveEvent]s, when the touch that initiates a fling is released. +/// +/// This class differs from the [VelocityTracker] class in that it uses weighted +/// average of the latest few velocity samples of the tracked pointer, instead +/// of doing a linear regression on a relatively large amount of data points, to +/// estimate the velocity of the tracked pointer. Adding data points and +/// estimating the velocity are both cheap. +/// +/// To obtain a velocity, call [getVelocity] or [getVelocityEstimate]. The +/// estimated velocity is typically used as the initial flinging velocity of a +/// `Scrollable`, when its drag gesture ends. +/// +/// See also: +/// +/// * [scrollViewWillEndDragging(_:withVelocity:targetContentOffset:)](https://developer.apple.com/documentation/uikit/uiscrollviewdelegate/1619385-scrollviewwillenddragging), +/// the iOS method that reports the fling velocity when the touch is released. +class IOSScrollViewFlingVelocityTracker extends VelocityTracker { + /// Create a new IOSScrollViewFlingVelocityTracker. + IOSScrollViewFlingVelocityTracker(super.kind) : super.withKind(); + + /// The velocity estimation uses at most 4 `_PointAtTime` samples. The extra + /// samples are there to make the `VelocityEstimate.offset` sufficiently large + /// to be recognized as a fling. See + /// `VerticalDragGestureRecognizer.isFlingGesture`. + static const int _sampleSize = 20; + + final List<_PointAtTime?> _touchSamples = List<_PointAtTime?>.filled(_sampleSize, null); + + @override + void addPosition(Duration time, Offset position) { + _sinceLastSample.start(); + _sinceLastSample.reset(); + assert(() { + final _PointAtTime? previousPoint = _touchSamples[_index]; + if (previousPoint == null || previousPoint.time <= time) { + return true; + } + throw FlutterError( + 'The position being added ($position) has a smaller timestamp ($time) ' + 'than its predecessor: $previousPoint.', + ); + }()); + _index = (_index + 1) % _sampleSize; + _touchSamples[_index] = _PointAtTime(position, time); + } + + // Computes the velocity using 2 adjacent points in history. When index = 0, + // it uses the latest point recorded and the point recorded immediately before + // it. The smaller index is, the earlier in history the points used are. + Offset _previousVelocityAt(int index) { + final int endIndex = (_index + index) % _sampleSize; + final int startIndex = (_index + index - 1) % _sampleSize; + final _PointAtTime? end = _touchSamples[endIndex]; + final _PointAtTime? start = _touchSamples[startIndex]; + + if (end == null || start == null) { + return Offset.zero; + } + + final int dt = (end.time - start.time).inMicroseconds; + assert(dt >= 0); + + return dt > 0 + // Convert dt to milliseconds to preserve floating point precision. + ? (end.point - start.point) * 1000 / (dt.toDouble() / 1000) + : Offset.zero; + } + + @override + VelocityEstimate getVelocityEstimate() { + // Has user recently moved since last sample? + if (_sinceLastSample.elapsedMilliseconds > VelocityTracker._assumePointerMoveStoppedMilliseconds) { + return const VelocityEstimate( + pixelsPerSecond: Offset.zero, + confidence: 1.0, + duration: Duration.zero, + offset: Offset.zero, + ); + } + + // The velocity estimated using this expression is an approximation of the + // scroll velocity of an iOS scroll view at the moment the user touch was + // released, not the final velocity of the iOS pan gesture recognizer + // installed on the scroll view would report. Typically in an iOS scroll + // view the velocity values are different between the two, because the + // scroll view usually slows down when the touch is released. + final Offset estimatedVelocity = _previousVelocityAt(-2) * 0.6 + + _previousVelocityAt(-1) * 0.35 + + _previousVelocityAt(0) * 0.05; + + final _PointAtTime? newestSample = _touchSamples[_index]; + _PointAtTime? oldestNonNullSample; + + for (int i = 1; i <= _sampleSize; i += 1) { + oldestNonNullSample = _touchSamples[(_index + i) % _sampleSize]; + if (oldestNonNullSample != null) { + break; + } + } + + if (oldestNonNullSample == null || newestSample == null) { + assert(false, 'There must be at least 1 point in _touchSamples: $_touchSamples'); + return const VelocityEstimate( + pixelsPerSecond: Offset.zero, + confidence: 0.0, + duration: Duration.zero, + offset: Offset.zero, + ); + } else { + return VelocityEstimate( + pixelsPerSecond: estimatedVelocity, + confidence: 1.0, + duration: newestSample.time - oldestNonNullSample.time, + offset: newestSample.point - oldestNonNullSample.point, + ); + } + } +} + +/// A [VelocityTracker] subclass that provides a close approximation of macOS +/// scroll view's velocity estimation strategy. +/// +/// The estimated velocity reported by this class is a close approximation of +/// the velocity a macOS scroll view would report with the same +/// [PointerMoveEvent]s, when the touch that initiates a fling is released. +/// +/// This class differs from the [VelocityTracker] class in that it uses weighted +/// average of the latest few velocity samples of the tracked pointer, instead +/// of doing a linear regression on a relatively large amount of data points, to +/// estimate the velocity of the tracked pointer. Adding data points and +/// estimating the velocity are both cheap. +/// +/// To obtain a velocity, call [getVelocity] or [getVelocityEstimate]. The +/// estimated velocity is typically used as the initial flinging velocity of a +/// `Scrollable`, when its drag gesture ends. +class MacOSScrollViewFlingVelocityTracker extends IOSScrollViewFlingVelocityTracker { + /// Create a new MacOSScrollViewFlingVelocityTracker. + MacOSScrollViewFlingVelocityTracker(super.kind); + + @override + VelocityEstimate getVelocityEstimate() { + // Has user recently moved since last sample? + if (_sinceLastSample.elapsedMilliseconds > VelocityTracker._assumePointerMoveStoppedMilliseconds) { + return const VelocityEstimate( + pixelsPerSecond: Offset.zero, + confidence: 1.0, + duration: Duration.zero, + offset: Offset.zero, + ); + } + + // The velocity estimated using this expression is an approximation of the + // scroll velocity of a macOS scroll view at the moment the user touch was + // released. + final Offset estimatedVelocity = _previousVelocityAt(-2) * 0.15 + + _previousVelocityAt(-1) * 0.65 + + _previousVelocityAt(0) * 0.2; + + final _PointAtTime? newestSample = _touchSamples[_index]; + _PointAtTime? oldestNonNullSample; + + for (int i = 1; i <= IOSScrollViewFlingVelocityTracker._sampleSize; i += 1) { + oldestNonNullSample = _touchSamples[(_index + i) % IOSScrollViewFlingVelocityTracker._sampleSize]; + if (oldestNonNullSample != null) { + break; + } + } + + if (oldestNonNullSample == null || newestSample == null) { + assert(false, 'There must be at least 1 point in _touchSamples: $_touchSamples'); + return const VelocityEstimate( + pixelsPerSecond: Offset.zero, + confidence: 0.0, + duration: Duration.zero, + offset: Offset.zero, + ); + } else { + return VelocityEstimate( + pixelsPerSecond: estimatedVelocity, + confidence: 1.0, + duration: newestSample.time - oldestNonNullSample.time, + offset: newestSample.point - oldestNonNullSample.point, + ); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/about.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/about.dart new file mode 100644 index 0000000000000000000000000000000000000000..76462c8c6033f5e9b791b604396eec6846c63e28 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/about.dart @@ -0,0 +1,1488 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:developer' show Flow, Timeline; +import 'dart:io' show Platform; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/widgets.dart' hide Flow; + +import 'app_bar.dart'; +import 'back_button.dart'; +import 'card.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'dialog.dart'; +import 'divider.dart'; +import 'floating_action_button_location.dart'; +import 'ink_decoration.dart'; +import 'list_tile.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'page.dart'; +import 'page_transitions_theme.dart'; +import 'progress_indicator.dart'; +import 'scaffold.dart'; +import 'scrollbar.dart'; +import 'text_button.dart'; +import 'text_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// BuildContext context; + +/// A [ListTile] that shows an about box. +/// +/// This widget is often added to an app's [Drawer]. When tapped it shows +/// an about box dialog with [showAboutDialog]. +/// +/// The about box will include a button that shows licenses for software used by +/// the application. The licenses shown are those returned by the +/// [LicenseRegistry] API, which can be used to add more licenses to the list. +/// +/// If your application does not have a [Drawer], you should provide an +/// affordance to call [showAboutDialog] or (at least) [showLicensePage]. +/// +/// {@tool dartpad} +/// This sample shows two ways to open [AboutDialog]. The first one +/// uses an [AboutListTile], and the second uses the [showAboutDialog] function. +/// +/// ** See code in examples/api/lib/material/about/about_list_tile.0.dart ** +/// {@end-tool} +class AboutListTile extends StatelessWidget { + /// Creates a list tile for showing an about box. + /// + /// The arguments are all optional. The application name, if omitted, will be + /// derived from the nearest [Title] widget. The version, icon, and legalese + /// values default to the empty string. + const AboutListTile({ + super.key, + this.icon, + this.child, + this.applicationName, + this.applicationVersion, + this.applicationIcon, + this.applicationLegalese, + this.aboutBoxChildren, + this.dense, + }); + + /// The icon to show for this drawer item. + /// + /// By default no icon is shown. + /// + /// This is not necessarily the same as the image shown in the dialog box + /// itself; which is controlled by the [applicationIcon] property. + final Widget? icon; + + /// The label to show on this drawer item. + /// + /// Defaults to a text widget that says "About Foo" where "Foo" is the + /// application name specified by [applicationName]. + final Widget? child; + + /// The name of the application. + /// + /// This string is used in the default label for this drawer item (see + /// [child]) and as the caption of the [AboutDialog] that is shown. + /// + /// Defaults to the value of [Title.title], if a [Title] widget can be found. + /// Otherwise, defaults to [Platform.resolvedExecutable]. + final String? applicationName; + + /// The version of this build of the application. + /// + /// This string is shown under the application name in the [AboutDialog]. + /// + /// Defaults to the empty string. + final String? applicationVersion; + + /// The icon to show next to the application name in the [AboutDialog]. + /// + /// By default no icon is shown. + /// + /// Typically this will be an [ImageIcon] widget. It should honor the + /// [IconTheme]'s [IconThemeData.size]. + /// + /// This is not necessarily the same as the icon shown on the drawer item + /// itself, which is controlled by the [icon] property. + final Widget? applicationIcon; + + /// A string to show in small print in the [AboutDialog]. + /// + /// Typically this is a copyright notice. + /// + /// Defaults to the empty string. + final String? applicationLegalese; + + /// Widgets to add to the [AboutDialog] after the name, version, and legalese. + /// + /// This could include a link to a Web site, some descriptive text, credits, + /// or other information to show in the about box. + /// + /// Defaults to nothing. + final List? aboutBoxChildren; + + /// Whether this list tile is part of a vertically dense list. + /// + /// If this property is null, then its value is based on [ListTileThemeData.dense]. + /// + /// Dense list tiles default to a smaller height. + final bool? dense; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMaterialLocalizations(context)); + return ListTile( + leading: icon, + title: child ?? Text(MaterialLocalizations.of(context).aboutListTileTitle( + applicationName ?? _defaultApplicationName(context), + )), + dense: dense, + onTap: () { + showAboutDialog( + context: context, + applicationName: applicationName, + applicationVersion: applicationVersion, + applicationIcon: applicationIcon, + applicationLegalese: applicationLegalese, + children: aboutBoxChildren, + ); + }, + ); + } +} + +/// Displays an [AboutDialog], which describes the application and provides a +/// button to show licenses for software used by the application. +/// +/// The arguments correspond to the properties on [AboutDialog]. +/// +/// If the application has a [Drawer], consider using [AboutListTile] instead +/// of calling this directly. +/// +/// If you do not need an about box in your application, you should at least +/// provide an affordance to call [showLicensePage]. +/// +/// The licenses shown on the [LicensePage] are those returned by the +/// [LicenseRegistry] API, which can be used to add more licenses to the list. +/// +/// The [context], [barrierDismissible], [barrierColor], [barrierLabel], +/// [useRootNavigator], [routeSettings] and [anchorPoint] arguments are +/// passed to [showDialog], the documentation for which discusses how it is used. +void showAboutDialog({ + required BuildContext context, + String? applicationName, + String? applicationVersion, + Widget? applicationIcon, + String? applicationLegalese, + List? children, + bool barrierDismissible = true, + Color? barrierColor, + String? barrierLabel, + bool useRootNavigator = true, + RouteSettings? routeSettings, + Offset? anchorPoint, +}) { + showDialog( + context: context, + barrierDismissible: barrierDismissible, + barrierColor: barrierColor, + barrierLabel: barrierLabel, + useRootNavigator: useRootNavigator, + builder: (BuildContext context) { + return AboutDialog( + applicationName: applicationName, + applicationVersion: applicationVersion, + applicationIcon: applicationIcon, + applicationLegalese: applicationLegalese, + children: children, + ); + }, + routeSettings: routeSettings, + anchorPoint: anchorPoint, + ); +} + +/// Displays a [LicensePage], which shows licenses for software used by the +/// application. +/// +/// The application arguments correspond to the properties on [LicensePage]. +/// +/// The `context` argument is used to look up the [Navigator] for the page. +/// +/// The `useRootNavigator` argument is used to determine whether to push the +/// page to the [Navigator] furthest from or nearest to the given `context`. It +/// is `false` by default. +/// +/// If the application has a [Drawer], consider using [AboutListTile] instead +/// of calling this directly. +/// +/// The [AboutDialog] shown by [showAboutDialog] includes a button that calls +/// [showLicensePage]. +/// +/// The licenses shown on the [LicensePage] are those returned by the +/// [LicenseRegistry] API, which can be used to add more licenses to the list. +void showLicensePage({ + required BuildContext context, + String? applicationName, + String? applicationVersion, + Widget? applicationIcon, + String? applicationLegalese, + bool useRootNavigator = false, +}) { + Navigator.of(context, rootNavigator: useRootNavigator).push(MaterialPageRoute( + builder: (BuildContext context) => LicensePage( + applicationName: applicationName, + applicationVersion: applicationVersion, + applicationIcon: applicationIcon, + applicationLegalese: applicationLegalese, + ), + )); +} + +/// The amount of vertical space to separate chunks of text. +const double _textVerticalSeparation = 18.0; + +/// An about box. This is a dialog box with the application's icon, name, +/// version number, and copyright, plus a button to show licenses for software +/// used by the application. +/// +/// To show an [AboutDialog], use [showAboutDialog]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=YFCSODyFxbE} +/// +/// If the application has a [Drawer], the [AboutListTile] widget can make the +/// process of showing an about dialog simpler. +/// +/// The [AboutDialog] shown by [showAboutDialog] includes a button that calls +/// [showLicensePage]. +/// +/// The licenses shown on the [LicensePage] are those returned by the +/// [LicenseRegistry] API, which can be used to add more licenses to the list. +class AboutDialog extends StatelessWidget { + /// Creates an about box. + /// + /// The arguments are all optional. The application name, if omitted, will be + /// derived from the nearest [Title] widget. The version, icon, and legalese + /// values default to the empty string. + const AboutDialog({ + super.key, + this.applicationName, + this.applicationVersion, + this.applicationIcon, + this.applicationLegalese, + this.children, + }); + + /// The name of the application. + /// + /// Defaults to the value of [Title.title], if a [Title] widget can be found. + /// Otherwise, defaults to [Platform.resolvedExecutable]. + final String? applicationName; + + /// The version of this build of the application. + /// + /// This string is shown under the application name. + /// + /// Defaults to the empty string. + final String? applicationVersion; + + /// The icon to show next to the application name. + /// + /// By default no icon is shown. + /// + /// Typically this will be an [ImageIcon] widget. It should honor the + /// [IconTheme]'s [IconThemeData.size]. + final Widget? applicationIcon; + + /// A string to show in small print. + /// + /// Typically this is a copyright notice. + /// + /// Defaults to the empty string. + final String? applicationLegalese; + + /// Widgets to add to the dialog box after the name, version, and legalese. + /// + /// This could include a link to a Web site, some descriptive text, credits, + /// or other information to show in the about box. + /// + /// Defaults to nothing. + final List? children; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + final String name = applicationName ?? _defaultApplicationName(context); + final String version = applicationVersion ?? _defaultApplicationVersion(context); + final Widget? icon = applicationIcon ?? _defaultApplicationIcon(context); + final ThemeData themeData = Theme.of(context); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + return AlertDialog( + content: ListBody( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (icon != null) IconTheme(data: themeData.iconTheme, child: icon), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 24.0), + child: ListBody( + children: [ + Text(name, style: themeData.textTheme.headlineSmall), + Text(version, style: themeData.textTheme.bodyMedium), + const SizedBox(height: _textVerticalSeparation), + Text(applicationLegalese ?? '', style: themeData.textTheme.bodySmall), + ], + ), + ), + ), + ], + ), + ...?children, + ], + ), + actions: [ + TextButton( + child: Text( + themeData.useMaterial3 + ? localizations.viewLicensesButtonLabel + : localizations.viewLicensesButtonLabel.toUpperCase() + ), + onPressed: () { + showLicensePage( + context: context, + applicationName: applicationName, + applicationVersion: applicationVersion, + applicationIcon: applicationIcon, + applicationLegalese: applicationLegalese, + ); + }, + ), + TextButton( + child: Text( + themeData.useMaterial3 + ? localizations.closeButtonLabel + : localizations.closeButtonLabel.toUpperCase() + ), + onPressed: () { + Navigator.pop(context); + }, + ), + ], + scrollable: true, + ); + } +} + +/// A page that shows licenses for software used by the application. +/// +/// To show a [LicensePage], use [showLicensePage]. +/// +/// The [AboutDialog] shown by [showAboutDialog] and [AboutListTile] includes +/// a button that calls [showLicensePage]. +/// +/// The licenses shown on the [LicensePage] are those returned by the +/// [LicenseRegistry] API, which can be used to add more licenses to the list. +class LicensePage extends StatefulWidget { + /// Creates a page that shows licenses for software used by the application. + /// + /// The arguments are all optional. The application name, if omitted, will be + /// derived from the nearest [Title] widget. The version and legalese values + /// default to the empty string. + /// + /// The licenses shown on the [LicensePage] are those returned by the + /// [LicenseRegistry] API, which can be used to add more licenses to the list. + const LicensePage({ + super.key, + this.applicationName, + this.applicationVersion, + this.applicationIcon, + this.applicationLegalese, + }); + + /// The name of the application. + /// + /// Defaults to the value of [Title.title], if a [Title] widget can be found. + /// Otherwise, defaults to [Platform.resolvedExecutable]. + final String? applicationName; + + /// The version of this build of the application. + /// + /// This string is shown under the application name. + /// + /// Defaults to the empty string. + final String? applicationVersion; + + /// The icon to show below the application name. + /// + /// By default no icon is shown. + /// + /// Typically this will be an [ImageIcon] widget. It should honor the + /// [IconTheme]'s [IconThemeData.size]. + final Widget? applicationIcon; + + /// A string to show in small print. + /// + /// Typically this is a copyright notice. + /// + /// Defaults to the empty string. + final String? applicationLegalese; + + @override + State createState() => _LicensePageState(); +} + +class _LicensePageState extends State { + final ValueNotifier selectedId = ValueNotifier(null); + + @override + void dispose() { + selectedId.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return _MasterDetailFlow( + detailPageFABlessGutterWidth: _getGutterSize(context), + title: Text(MaterialLocalizations.of(context).licensesPageTitle), + detailPageBuilder: _packageLicensePage, + masterViewBuilder: _packagesView, + ); + } + + Widget _packageLicensePage(BuildContext _, Object? args, ScrollController? scrollController) { + assert(args is _DetailArguments); + final _DetailArguments detailArguments = args! as _DetailArguments; + return _PackageLicensePage( + packageName: detailArguments.packageName, + licenseEntries: detailArguments.licenseEntries, + scrollController: scrollController, + ); + } + + Widget _packagesView(final BuildContext _, final bool isLateral) { + final Widget about = _AboutProgram( + name: widget.applicationName ?? _defaultApplicationName(context), + icon: widget.applicationIcon ?? _defaultApplicationIcon(context), + version: widget.applicationVersion ?? _defaultApplicationVersion(context), + legalese: widget.applicationLegalese, + ); + return _PackagesView( + about: about, + isLateral: isLateral, + selectedId: selectedId, + ); + } +} + +class _AboutProgram extends StatelessWidget { + const _AboutProgram({ + required this.name, + required this.version, + this.icon, + this.legalese, + }); + + final String name; + final String version; + final Widget? icon; + final String? legalese; + + @override + Widget build(BuildContext context) { + return Padding( + padding: EdgeInsets.symmetric( + horizontal: _getGutterSize(context), + vertical: 24.0, + ), + child: Column( + children: [ + Text( + name, + style: Theme.of(context).textTheme.headlineSmall, + textAlign: TextAlign.center, + ), + if (icon != null) + IconTheme(data: Theme.of(context).iconTheme, child: icon!), + if (version != '') + Padding( + padding: const EdgeInsets.only(bottom: _textVerticalSeparation), + child: Text( + version, + style: Theme.of(context).textTheme.bodyMedium, + textAlign: TextAlign.center, + ), + ), + if (legalese != null && legalese != '') + Text( + legalese!, + style: Theme.of(context).textTheme.bodySmall, + textAlign: TextAlign.center, + ), + const SizedBox(height: _textVerticalSeparation), + Text( + 'Powered by Flutter', + style: Theme.of(context).textTheme.bodyMedium, + textAlign: TextAlign.center, + ), + ], + ), + ); + } +} + +class _PackagesView extends StatefulWidget { + const _PackagesView({ + required this.about, + required this.isLateral, + required this.selectedId, + }); + + final Widget about; + final bool isLateral; + final ValueNotifier selectedId; + + @override + _PackagesViewState createState() => _PackagesViewState(); +} + +class _PackagesViewState extends State<_PackagesView> { + final Future<_LicenseData> licenses = LicenseRegistry.licenses + .fold<_LicenseData>( + _LicenseData(), + (_LicenseData prev, LicenseEntry license) => prev..addLicense(license), + ) + .then((_LicenseData licenseData) => licenseData..sortPackages()); + + @override + Widget build(BuildContext context) { + return FutureBuilder<_LicenseData>( + future: licenses, + builder: (BuildContext context, AsyncSnapshot<_LicenseData> snapshot) { + return LayoutBuilder( + key: ValueKey(snapshot.connectionState), + builder: (BuildContext context, BoxConstraints constraints) { + switch (snapshot.connectionState) { + case ConnectionState.done: + if (snapshot.hasError) { + assert(() { + FlutterError.reportError(FlutterErrorDetails( + exception: snapshot.error!, + stack: snapshot.stackTrace, + context: ErrorDescription('while decoding the license file'), + )); + return true; + }()); + return Center(child: Text(snapshot.error.toString())); + } + _initDefaultDetailPage(snapshot.data!, context); + return ValueListenableBuilder( + valueListenable: widget.selectedId, + builder: (BuildContext context, int? selectedId, Widget? _) { + return Center( + child: Material( + color: Theme.of(context).cardColor, + elevation: 4.0, + child: Container( + constraints: BoxConstraints.loose(const Size.fromWidth(600.0)), + child: _packagesList(context, selectedId, snapshot.data!, widget.isLateral), + ), + ), + ); + }, + ); + case ConnectionState.none: + case ConnectionState.active: + case ConnectionState.waiting: + return Material( + color: Theme.of(context).cardColor, + child: Column( + children: [ + widget.about, + const Center(child: CircularProgressIndicator()), + ], + ), + ); + } + }, + ); + }, + ); + } + + void _initDefaultDetailPage(_LicenseData data, BuildContext context) { + if (data.packages.isEmpty) { + return; + } + final String packageName = data.packages[widget.selectedId.value ?? 0]; + final List bindings = data.packageLicenseBindings[packageName]!; + _MasterDetailFlow.of(context).setInitialDetailPage( + _DetailArguments( + packageName, + bindings.map((int i) => data.licenses[i]).toList(growable: false), + ), + ); + } + + Widget _packagesList( + final BuildContext context, + final int? selectedId, + final _LicenseData data, + final bool drawSelection, + ) { + return ListView.builder( + itemCount: data.packages.length + 1, + itemBuilder: (BuildContext context, int index) { + if (index == 0) { + return widget.about; + } + final int packageIndex = index - 1; + final String packageName = data.packages[packageIndex]; + final List bindings = data.packageLicenseBindings[packageName]!; + return _PackageListTile( + packageName: packageName, + index: packageIndex, + isSelected: drawSelection && packageIndex == (selectedId ?? 0), + numberLicenses: bindings.length, + onTap: () { + widget.selectedId.value = packageIndex; + _MasterDetailFlow.of(context).openDetailPage(_DetailArguments( + packageName, + bindings.map((int i) => data.licenses[i]).toList(growable: false), + )); + }, + ); + }, + ); + } +} + +class _PackageListTile extends StatelessWidget { + const _PackageListTile({ + required this.packageName, + this.index, + required this.isSelected, + required this.numberLicenses, + this.onTap, +}); + + final String packageName; + final int? index; + final bool isSelected; + final int numberLicenses; + final GestureTapCallback? onTap; + + @override + Widget build(BuildContext context) { + return Ink( + color: isSelected ? Theme.of(context).highlightColor : Theme.of(context).cardColor, + child: ListTile( + title: Text(packageName), + subtitle: Text(MaterialLocalizations.of(context).licensesPackageDetailText(numberLicenses)), + selected: isSelected, + onTap: onTap, + ), + ); + } +} + +/// This is a collection of licenses and the packages to which they apply. +/// [packageLicenseBindings] records the m+:n+ relationship between the license +/// and packages as a map of package names to license indexes. +class _LicenseData { + final List licenses = []; + final Map> packageLicenseBindings = >{}; + final List packages = []; + + // Special treatment for the first package since it should be the package + // for delivered application. + String? firstPackage; + + void addLicense(LicenseEntry entry) { + // Before the license can be added, we must first record the packages to + // which it belongs. + for (final String package in entry.packages) { + _addPackage(package); + // Bind this license to the package using the next index value. This + // creates a contract that this license must be inserted at this same + // index value. + packageLicenseBindings[package]!.add(licenses.length); + } + licenses.add(entry); // Completion of the contract above. + } + + /// Add a package and initialize package license binding. This is a no-op if + /// the package has been seen before. + void _addPackage(String package) { + if (!packageLicenseBindings.containsKey(package)) { + packageLicenseBindings[package] = []; + firstPackage ??= package; + packages.add(package); + } + } + + /// Sort the packages using some comparison method, or by the default manner, + /// which is to put the application package first, followed by every other + /// package in case-insensitive alphabetical order. + void sortPackages([int Function(String a, String b)? compare]) { + packages.sort(compare ?? (String a, String b) { + // Based on how LicenseRegistry currently behaves, the first package + // returned is the end user application license. This should be + // presented first in the list. So here we make sure that first package + // remains at the front regardless of alphabetical sorting. + if (a == firstPackage) { + return -1; + } + if (b == firstPackage) { + return 1; + } + return a.toLowerCase().compareTo(b.toLowerCase()); + }); + } +} + +@immutable +class _DetailArguments { + const _DetailArguments(this.packageName, this.licenseEntries); + + final String packageName; + final List licenseEntries; + + @override + bool operator ==(final Object other) { + if (other is _DetailArguments) { + return other.packageName == packageName; + } + return other == this; + } + + @override + int get hashCode => Object.hash(packageName, Object.hashAll(licenseEntries)); +} + +class _PackageLicensePage extends StatefulWidget { + const _PackageLicensePage({ + required this.packageName, + required this.licenseEntries, + required this.scrollController, + }); + + final String packageName; + final List licenseEntries; + final ScrollController? scrollController; + + @override + _PackageLicensePageState createState() => _PackageLicensePageState(); +} + +class _PackageLicensePageState extends State<_PackageLicensePage> { + @override + void initState() { + super.initState(); + _initLicenses(); + } + + final List _licenses = []; + bool _loaded = false; + + Future _initLicenses() async { + int debugFlowId = -1; + assert(() { + final Flow flow = Flow.begin(); + Timeline.timeSync('_initLicenses()', () { }, flow: flow); + debugFlowId = flow.id; + return true; + }()); + for (final LicenseEntry license in widget.licenseEntries) { + if (!mounted) { + return; + } + assert(() { + Timeline.timeSync('_initLicenses()', () { }, flow: Flow.step(debugFlowId)); + return true; + }()); + final List paragraphs = + await SchedulerBinding.instance.scheduleTask>( + license.paragraphs.toList, + Priority.animation, + debugLabel: 'License', + ); + if (!mounted) { + return; + } + setState(() { + _licenses.add(const Padding( + padding: EdgeInsets.all(18.0), + child: Divider(), + )); + for (final LicenseParagraph paragraph in paragraphs) { + if (paragraph.indent == LicenseParagraph.centeredIndent) { + _licenses.add(Padding( + padding: const EdgeInsets.only(top: 16.0), + child: Text( + paragraph.text, + style: const TextStyle(fontWeight: FontWeight.bold), + textAlign: TextAlign.center, + ), + )); + } else { + assert(paragraph.indent >= 0); + _licenses.add(Padding( + padding: EdgeInsetsDirectional.only(top: 8.0, start: 16.0 * paragraph.indent), + child: Text(paragraph.text), + )); + } + } + }); + } + setState(() { + _loaded = true; + }); + assert(() { + Timeline.timeSync('Build scheduled', () { }, flow: Flow.end(debugFlowId)); + return true; + }()); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final ThemeData theme = Theme.of(context); + final String title = widget.packageName; + final String subtitle = localizations.licensesPackageDetailText(widget.licenseEntries.length); + final double pad = _getGutterSize(context); + final EdgeInsets padding = EdgeInsets.only(left: pad, right: pad, bottom: pad); + final List listWidgets = [ + ..._licenses, + if (!_loaded) + const Padding( + padding: EdgeInsets.symmetric(vertical: 24.0), + child: Center( + child: CircularProgressIndicator(), + ), + ), + ]; + + final Widget page; + if (widget.scrollController == null) { + page = Scaffold( + appBar: AppBar( + title: _PackageLicensePageTitle( + title: title, + subtitle: subtitle, + theme: theme.useMaterial3 ? theme.textTheme : theme.primaryTextTheme, + titleTextStyle: theme.appBarTheme.titleTextStyle, + foregroundColor: theme.appBarTheme.foregroundColor, + ), + ), + body: Center( + child: Material( + color: theme.cardColor, + elevation: 4.0, + child: Container( + constraints: BoxConstraints.loose(const Size.fromWidth(600.0)), + child: Localizations.override( + locale: const Locale('en', 'US'), + context: context, + child: ScrollConfiguration( + // A Scrollbar is built-in below. + behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false), + child: Scrollbar( + child: ListView( + primary: true, + padding: padding, + children: listWidgets, + ), + ), + ), + ), + ), + ), + ), + ); + } else { + page = CustomScrollView( + controller: widget.scrollController, + slivers: [ + SliverAppBar( + automaticallyImplyLeading: false, + pinned: true, + backgroundColor: theme.cardColor, + title: _PackageLicensePageTitle( + title: title, + subtitle: subtitle, + theme: theme.textTheme, + titleTextStyle: theme.textTheme.titleLarge, + ), + ), + SliverPadding( + padding: padding, + sliver: SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => Localizations.override( + locale: const Locale('en', 'US'), + context: context, + child: listWidgets[index], + ), + childCount: listWidgets.length, + ), + ), + ), + ], + ); + } + return DefaultTextStyle( + style: theme.textTheme.bodySmall!, + child: page, + ); + } +} + +class _PackageLicensePageTitle extends StatelessWidget { + const _PackageLicensePageTitle({ + required this.title, + required this.subtitle, + required this.theme, + this.titleTextStyle, + this.foregroundColor, + }); + + final String title; + final String subtitle; + final TextTheme theme; + final TextStyle? titleTextStyle; + final Color? foregroundColor; + + @override + Widget build(BuildContext context) { + final TextStyle? effectiveTitleTextStyle = titleTextStyle ?? theme.titleLarge; + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(title, style: effectiveTitleTextStyle?.copyWith(color: foregroundColor)), + Text(subtitle, style: theme.titleSmall?.copyWith(color: foregroundColor)), + ], + ); + } +} + +String _defaultApplicationName(BuildContext context) { + // This doesn't handle the case of the application's title dynamically + // changing. In theory, we should make Title expose the current application + // title using an InheritedWidget, and so forth. However, in practice, if + // someone really wants their application title to change dynamically, they + // can provide an explicit applicationName to the widgets defined in this + // file, instead of relying on the default. + final Title? ancestorTitle = context.findAncestorWidgetOfExactType(); + return ancestorTitle?.title ?? Platform.resolvedExecutable.split(Platform.pathSeparator).last; +} + +String _defaultApplicationVersion(BuildContext context) { + // TODO(ianh): Get this from the embedder somehow. + return ''; +} + +Widget? _defaultApplicationIcon(BuildContext context) { + // TODO(ianh): Get this from the embedder somehow. + return null; +} + +const int _materialGutterThreshold = 720; +const double _wideGutterSize = 24.0; +const double _narrowGutterSize = 12.0; + +double _getGutterSize(BuildContext context) => + MediaQuery.sizeOf(context).width >= _materialGutterThreshold ? _wideGutterSize : _narrowGutterSize; + +/// Signature for the builder callback used by [_MasterDetailFlow]. +typedef _MasterViewBuilder = Widget Function(BuildContext context, bool isLateralUI); + +/// Signature for the builder callback used by [_MasterDetailFlow.detailPageBuilder]. +/// +/// scrollController is provided when the page destination is the draggable +/// sheet in the lateral UI. Otherwise, it is null. +typedef _DetailPageBuilder = Widget Function(BuildContext context, Object? arguments, ScrollController? scrollController); + +/// Signature for the builder callback used by [_MasterDetailFlow.actionBuilder]. +/// +/// Builds the actions that go in the app bars constructed for the master and +/// lateral UI pages. actionLevel indicates the intended destination of the +/// return actions. +typedef _ActionBuilder = List<Widget> Function(BuildContext context, _ActionLevel actionLevel); + +/// Describes which type of app bar the actions are intended for. +enum _ActionLevel { + /// Indicates the top app bar in the lateral UI. + top, + + /// Indicates the master view app bar in the lateral UI. + view, +} + +/// Describes which layout will be used by [_MasterDetailFlow]. +enum _LayoutMode { + /// Always use a lateral layout. + lateral, + + /// Always use a nested layout. + nested, +} + +const String _navMaster = 'master'; +const String _navDetail = 'detail'; +enum _Focus { master, detail } + +/// A Master Detail Flow widget. Depending on screen width it builds either a +/// lateral or nested navigation flow between a master view and a detail page. +/// bloc pattern. +/// +/// If focus is on detail view, then switching to nested navigation will +/// populate the navigation history with the master page and the detail page on +/// top. Otherwise the focus is on the master view and just the master page +/// is shown. +class _MasterDetailFlow extends StatefulWidget { + /// Creates a master detail navigation flow which is either nested or + /// lateral depending on screen width. + const _MasterDetailFlow({ + required this.detailPageBuilder, + required this.masterViewBuilder, + this.detailPageFABlessGutterWidth, + this.title, + }); + + /// Builder for the master view for lateral navigation. + /// + /// If [masterPageBuilder] is not supplied the master page required for nested navigation, also + /// builds the master view inside a [Scaffold] with an [AppBar]. + final _MasterViewBuilder masterViewBuilder; + + /// Builder for the detail page. + /// + /// If scrollController == null, the page is intended for nested navigation. The lateral detail + /// page is inside a [DraggableScrollableSheet] and should have a scrollable element that uses + /// the [ScrollController] provided. In fact, it is strongly recommended the entire lateral + /// page is scrollable. + final _DetailPageBuilder detailPageBuilder; + + /// Override the width of the gutter when there is no floating action button. + final double? detailPageFABlessGutterWidth; + + /// The title for the lateral UI [AppBar]. + /// + /// See [AppBar.title]. + final Widget? title; + + @override + _MasterDetailFlowState createState() => _MasterDetailFlowState(); + + // The master detail flow proxy from the closest instance of this class that encloses the given + // context. + // + // Typical usage is as follows: + // + // ```dart + // _MasterDetailFlow.of(context).openDetailPage(arguments); + // ``` + static _MasterDetailFlowProxy of(BuildContext context) { + _PageOpener? pageOpener = context.findAncestorStateOfType<_MasterDetailScaffoldState>(); + pageOpener ??= context.findAncestorStateOfType<_MasterDetailFlowState>(); + assert(() { + if (pageOpener == null) { + throw FlutterError( + 'Master Detail operation requested with a context that does not include a Master Detail ' + 'Flow.\nThe context used to open a detail page from the Master Detail Flow must be ' + 'that of a widget that is a descendant of a Master Detail Flow widget.', + ); + } + return true; + }()); + return _MasterDetailFlowProxy._(pageOpener!); + } +} + +/// Interface for interacting with the [_MasterDetailFlow]. +class _MasterDetailFlowProxy implements _PageOpener { + _MasterDetailFlowProxy._(this._pageOpener); + + final _PageOpener _pageOpener; + + /// Open detail page with arguments. + @override + void openDetailPage(Object arguments) => + _pageOpener.openDetailPage(arguments); + + /// Set the initial page to be open for the lateral layout. This can be set at any time, but + /// will have no effect after any calls to openDetailPage. + @override + void setInitialDetailPage(Object arguments) => + _pageOpener.setInitialDetailPage(arguments); +} + +abstract class _PageOpener { + void openDetailPage(Object arguments); + + void setInitialDetailPage(Object arguments); +} + +const int _materialWideDisplayThreshold = 840; + +class _MasterDetailFlowState extends State<_MasterDetailFlow> implements _PageOpener { + /// Tracks whether focus is on the detail or master views. Determines behavior when switching + /// from lateral to nested navigation. + _Focus focus = _Focus.master; + + /// Cache of arguments passed when opening a detail page. Used when rebuilding. + Object? _cachedDetailArguments; + + /// Record of the layout that was built. + _LayoutMode? _builtLayout; + + /// Key to access navigator in the nested layout. + final GlobalKey<NavigatorState> _navigatorKey = GlobalKey<NavigatorState>(); + + @override + void openDetailPage(Object arguments) { + _cachedDetailArguments = arguments; + if (_builtLayout == _LayoutMode.nested) { + _navigatorKey.currentState!.pushNamed(_navDetail, arguments: arguments); + } else { + focus = _Focus.detail; + } + } + + @override + void setInitialDetailPage(Object arguments) { + _cachedDetailArguments = arguments; + } + + @override + Widget build(BuildContext context) { + return LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) { + final double availableWidth = constraints.maxWidth; + if (availableWidth >= _materialWideDisplayThreshold) { + return _lateralUI(context); + } + return _nestedUI(context); + }); + } + + Widget _nestedUI(BuildContext context) { + _builtLayout = _LayoutMode.nested; + final MaterialPageRoute<void> masterPageRoute = _masterPageRoute(context); + + return NavigatorPopHandler( + onPop: () { + _navigatorKey.currentState!.maybePop(); + }, + child: Navigator( + key: _navigatorKey, + initialRoute: 'initial', + onGenerateInitialRoutes: (NavigatorState navigator, String initialRoute) { + switch (focus) { + case _Focus.master: + return <Route<void>>[masterPageRoute]; + case _Focus.detail: + return <Route<void>>[ + masterPageRoute, + _detailPageRoute(_cachedDetailArguments), + ]; + } + }, + onGenerateRoute: (RouteSettings settings) { + switch (settings.name) { + case _navMaster: + // Matching state to navigation event. + focus = _Focus.master; + return masterPageRoute; + case _navDetail: + // Matching state to navigation event. + focus = _Focus.detail; + // Cache detail page settings. + _cachedDetailArguments = settings.arguments; + return _detailPageRoute(_cachedDetailArguments); + default: + throw Exception('Unknown route ${settings.name}'); + } + }, + ), + ); + } + + MaterialPageRoute<void> _masterPageRoute(BuildContext context) { + return MaterialPageRoute<dynamic>( + builder: (BuildContext c) { + return BlockSemantics( + child: _MasterPage( + leading: Navigator.of(context).canPop() + ? BackButton(onPressed: () { Navigator.of(context).pop(); }) + : null, + title: widget.title, + masterViewBuilder: widget.masterViewBuilder, + ), + ); + }, + ); + } + + MaterialPageRoute<void> _detailPageRoute(Object? arguments) { + return MaterialPageRoute<dynamic>(builder: (BuildContext context) { + return PopScope( + onPopInvoked: (bool didPop) { + // No need for setState() as rebuild happens on navigation pop. + focus = _Focus.master; + }, + child: BlockSemantics(child: widget.detailPageBuilder(context, arguments, null)), + ); + }); + } + + Widget _lateralUI(BuildContext context) { + _builtLayout = _LayoutMode.lateral; + return _MasterDetailScaffold( + actionBuilder: (_, __) => const<Widget>[], + detailPageBuilder: (BuildContext context, Object? args, ScrollController? scrollController) => + widget.detailPageBuilder(context, args ?? _cachedDetailArguments, scrollController), + detailPageFABlessGutterWidth: widget.detailPageFABlessGutterWidth, + initialArguments: _cachedDetailArguments, + masterViewBuilder: (BuildContext context, bool isLateral) => widget.masterViewBuilder(context, isLateral), + title: widget.title, + ); + } +} + +class _MasterPage extends StatelessWidget { + const _MasterPage({ + this.leading, + this.title, + this.masterViewBuilder, + }); + + final _MasterViewBuilder? masterViewBuilder; + final Widget? title; + final Widget? leading; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: title, + leading: leading, + actions: const <Widget>[], + ), + body: masterViewBuilder!(context, false), + ); + } + +} + +const double _kCardElevation = 4.0; +const double _kMasterViewWidth = 320.0; +const double _kDetailPageFABlessGutterWidth = 40.0; +const double _kDetailPageFABGutterWidth = 84.0; + +class _MasterDetailScaffold extends StatefulWidget { + const _MasterDetailScaffold({ + required this.detailPageBuilder, + required this.masterViewBuilder, + this.actionBuilder, + this.initialArguments, + this.title, + this.detailPageFABlessGutterWidth, + }); + + final _MasterViewBuilder masterViewBuilder; + + /// Builder for the detail page. + /// + /// The detail page is inside a [DraggableScrollableSheet] and should have a scrollable element + /// that uses the [ScrollController] provided. In fact, it is strongly recommended the entire + /// lateral page is scrollable. + final _DetailPageBuilder detailPageBuilder; + final _ActionBuilder? actionBuilder; + final Object? initialArguments; + final Widget? title; + final double? detailPageFABlessGutterWidth; + + @override + _MasterDetailScaffoldState createState() => _MasterDetailScaffoldState(); +} + +class _MasterDetailScaffoldState extends State<_MasterDetailScaffold> + implements _PageOpener { + late FloatingActionButtonLocation floatingActionButtonLocation; + late double detailPageFABGutterWidth; + late double detailPageFABlessGutterWidth; + late double masterViewWidth; + + final ValueNotifier<Object?> _detailArguments = ValueNotifier<Object?>(null); + + @override + void initState() { + super.initState(); + detailPageFABlessGutterWidth = widget.detailPageFABlessGutterWidth ?? _kDetailPageFABlessGutterWidth; + detailPageFABGutterWidth = _kDetailPageFABGutterWidth; + masterViewWidth = _kMasterViewWidth; + floatingActionButtonLocation = FloatingActionButtonLocation.endTop; + } + + @override + void dispose() { + _detailArguments.dispose(); + super.dispose(); + } + + @override + void openDetailPage(Object arguments) { + SchedulerBinding.instance.addPostFrameCallback((_) => _detailArguments.value = arguments); + _MasterDetailFlow.of(context).openDetailPage(arguments); + } + + @override + void setInitialDetailPage(Object arguments) { + SchedulerBinding.instance.addPostFrameCallback((_) => _detailArguments.value = arguments); + _MasterDetailFlow.of(context).setInitialDetailPage(arguments); + } + + @override + Widget build(BuildContext context) { + return Stack( + children: <Widget>[ + Scaffold( + floatingActionButtonLocation: floatingActionButtonLocation, + appBar: AppBar( + title: widget.title, + actions: widget.actionBuilder!(context, _ActionLevel.top), + bottom: PreferredSize( + preferredSize: const Size.fromHeight(kToolbarHeight), + child: Row( + children: <Widget>[ + ConstrainedBox( + constraints: BoxConstraints.tightFor(width: masterViewWidth), + child: IconTheme( + data: Theme.of(context).primaryIconTheme, + child: Container( + alignment: AlignmentDirectional.centerEnd, + padding: const EdgeInsets.all(8), + child: OverflowBar( + spacing: 8, + overflowAlignment: OverflowBarAlignment.end, + children: widget.actionBuilder!(context, _ActionLevel.view), + ), + ), + ), + ), + ], + ), + ), + ), + body: Align( + alignment: AlignmentDirectional.centerStart, + child: _masterPanel(context), + ), + ), + // Detail view stacked above main scaffold and master view. + SafeArea( + child: Padding( + padding: EdgeInsetsDirectional.only( + start: masterViewWidth - _kCardElevation, + end: detailPageFABlessGutterWidth, + ), + child: ValueListenableBuilder<Object?>( + valueListenable: _detailArguments, + builder: (BuildContext context, Object? value, Widget? child) { + return AnimatedSwitcher( + transitionBuilder: (Widget child, Animation<double> animation) => + const FadeUpwardsPageTransitionsBuilder().buildTransitions<void>( + null, + null, + animation, + null, + child, + ), + duration: const Duration(milliseconds: 500), + child: Container( + key: ValueKey<Object?>(value ?? widget.initialArguments), + constraints: const BoxConstraints.expand(), + child: _DetailView( + builder: widget.detailPageBuilder, + arguments: value ?? widget.initialArguments, + ), + ), + ); + }, + ), + ), + ), + ], + ); + } + + ConstrainedBox _masterPanel(BuildContext context, {bool needsScaffold = false}) { + return ConstrainedBox( + constraints: BoxConstraints(maxWidth: masterViewWidth), + child: needsScaffold + ? Scaffold( + appBar: AppBar( + title: widget.title, + actions: widget.actionBuilder!(context, _ActionLevel.top), + ), + body: widget.masterViewBuilder(context, true), + ) + : widget.masterViewBuilder(context, true), + ); + } +} + +class _DetailView extends StatelessWidget { + const _DetailView({ + required _DetailPageBuilder builder, + Object? arguments, + }) : _builder = builder, + _arguments = arguments; + + final _DetailPageBuilder _builder; + final Object? _arguments; + + @override + Widget build(BuildContext context) { + if (_arguments == null) { + return const SizedBox.shrink(); + } + final double screenHeight = MediaQuery.sizeOf(context).height; + final double minHeight = (screenHeight - kToolbarHeight) / screenHeight; + + return DraggableScrollableSheet( + initialChildSize: minHeight, + minChildSize: minHeight, + expand: false, + builder: (BuildContext context, ScrollController controller) { + return MouseRegion( + // TODO(TonicArtos): Remove MouseRegion workaround for pointer hover events passing through DraggableScrollableSheet once https://github.com/flutter/flutter/issues/59741 is resolved. + child: Card( + color: Theme.of(context).cardColor, + elevation: _kCardElevation, + clipBehavior: Clip.antiAlias, + margin: const EdgeInsets.fromLTRB(_kCardElevation, 0.0, _kCardElevation, 0.0), + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical(top: Radius.circular(3.0)), + ), + child: _builder( + context, + _arguments, + controller, + ), + ), + ); + }, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/action_buttons.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/action_buttons.dart new file mode 100644 index 0000000000000000000000000000000000000000..7ec0d7d3a2167fcbb90577571560c3a72c40b59c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/action_buttons.dart @@ -0,0 +1,416 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'action_icons_theme.dart'; +import 'button_style.dart'; +import 'debug.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'material_localizations.dart'; +import 'scaffold.dart'; +import 'theme.dart'; + +abstract class _ActionButton extends StatelessWidget { + /// Creates a Material Design icon button. + const _ActionButton({ + super.key, + this.color, + required this.icon, + required this.onPressed, + this.style, + }); + + /// The icon to display inside the button. + final Widget icon; + + /// The callback that is called when the button is tapped + /// or otherwise activated. + /// + /// If this is set to null, the button will do a default action + /// when it is tapped or activated. + final VoidCallback? onPressed; + + /// The color to use for the icon. + /// + /// Defaults to the [IconThemeData.color] specified in the ambient [IconTheme], + /// which usually matches the ambient [Theme]'s [ThemeData.iconTheme]. + final Color? color; + + /// Customizes this icon button's appearance. + /// + /// The [style] is only used for Material 3 [IconButton]s. If [ThemeData.useMaterial3] + /// is set to true, [style] is preferred for icon button customization, and any + /// parameters defined in [style] will override the same parameters in [IconButton]. + /// + /// Null by default. + final ButtonStyle? style; + + /// This returns the appropriate tooltip text for this action button. + String _getTooltip(BuildContext context); + + /// This is the default function that is called when [onPressed] is set + /// to null. + void _onPressedCallback(BuildContext context); + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + return IconButton( + icon: icon, + style: style, + color: color, + tooltip: _getTooltip(context), + onPressed: () { + if (onPressed != null) { + onPressed!(); + } else { + _onPressedCallback(context); + } + }, + ); + } +} + +typedef _ActionIconBuilderCallback = WidgetBuilder? Function(ActionIconThemeData? actionIconTheme); +typedef _ActionIconDataCallback = IconData Function(BuildContext context); +typedef _AndroidSemanticsLabelCallback = String Function(MaterialLocalizations materialLocalization); + +class _ActionIcon extends StatelessWidget { + const _ActionIcon({ + required this.iconBuilderCallback, + required this.getIcon, + required this.getAndroidSemanticsLabel, + }); + + final _ActionIconBuilderCallback iconBuilderCallback; + final _ActionIconDataCallback getIcon; + final _AndroidSemanticsLabelCallback getAndroidSemanticsLabel; + + @override + Widget build(BuildContext context) { + final ActionIconThemeData? actionIconTheme = ActionIconTheme.of(context); + final WidgetBuilder? iconBuilder = iconBuilderCallback(actionIconTheme); + if (iconBuilder != null) { + return iconBuilder(context); + } + + final IconData data = getIcon(context); + final String? semanticsLabel; + // This can't use the platform from Theme because it is the Android OS that + // expects the duplicated tooltip and label. + switch (defaultTargetPlatform) { + case TargetPlatform.android: + semanticsLabel = getAndroidSemanticsLabel(MaterialLocalizations.of(context)); + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + case TargetPlatform.iOS: + case TargetPlatform.macOS: + semanticsLabel = null; + } + + return Icon(data, semanticLabel: semanticsLabel); + } +} + +/// A "back" icon that's appropriate for the current [TargetPlatform]. +/// +/// The current platform is determined by querying for the ambient [Theme]. +/// +/// See also: +/// +/// * [BackButton], an [IconButton] with a [BackButtonIcon] that calls +/// [Navigator.maybePop] to return to the previous route. +/// * [IconButton], which is a more general widget for creating buttons +/// with icons. +/// * [Icon], a Material Design icon. +/// * [ThemeData.platform], which specifies the current platform. +class BackButtonIcon extends StatelessWidget { + /// Creates an icon that shows the appropriate "back" image for + /// the current platform (as obtained from the [Theme]). + const BackButtonIcon({ super.key }); + + @override + Widget build(BuildContext context) { + return _ActionIcon( + iconBuilderCallback: (ActionIconThemeData? actionIconTheme) { + return actionIconTheme?.backButtonIconBuilder; + }, + getIcon: (BuildContext context) { + if (kIsWeb) { + // Always use 'Icons.arrow_back' as a back_button icon in web. + return Icons.arrow_back; + } + switch (Theme.of(context).platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return Icons.arrow_back; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return Icons.arrow_back_ios_new_rounded; + } + }, + getAndroidSemanticsLabel: (MaterialLocalizations materialLocalization) { + return materialLocalization.backButtonTooltip; + }, + ); + } +} + +/// A Material Design back icon button. +/// +/// A [BackButton] is an [IconButton] with a "back" icon appropriate for the +/// current [TargetPlatform]. When pressed, the back button calls +/// [Navigator.maybePop] to return to the previous route unless a custom +/// [onPressed] callback is provided. +/// +/// The [onPressed] callback can, for instance, be used to pop the platform's navigation stack +/// via [SystemNavigator] instead of Flutter's [Navigator] in add-to-app +/// situations. +/// +/// In Material Design 3, both [style]'s [ButtonStyle.iconColor] and [color] are +/// used to override the default icon color of [BackButton]. If both exist, the [ButtonStyle.iconColor] +/// will override [color] for states where [ButtonStyle.foregroundColor] resolves to non-null. +/// +/// When deciding to display a [BackButton], consider using +/// `ModalRoute.of(context)?.canPop` to check whether the current route can be +/// popped. If that value is false (e.g., because the current route is the +/// initial route), the [BackButton] will not have any effect when pressed, +/// which could frustrate the user. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// See also: +/// +/// * [AppBar], which automatically uses a [BackButton] in its +/// [AppBar.leading] slot when the [Scaffold] has no [Drawer] and the +/// current [Route] is not the [Navigator]'s first route. +/// * [BackButtonIcon], which is useful if you need to create a back button +/// that responds differently to being pressed. +/// * [IconButton], which is a more general widget for creating buttons with +/// icons. +/// * [CloseButton], an alternative which may be more appropriate for leaf +/// node pages in the navigation tree. +class BackButton extends _ActionButton { + /// Creates an [IconButton] with the appropriate "back" icon for the current + /// target platform. + const BackButton({ + super.key, + super.color, + super.style, + super.onPressed, + }) : super(icon: const BackButtonIcon()); + + @override + void _onPressedCallback(BuildContext context) => Navigator.maybePop(context); + + @override + String _getTooltip(BuildContext context) { + return MaterialLocalizations.of(context).backButtonTooltip; + } +} + +/// A "close" icon that's appropriate for the current [TargetPlatform]. +/// +/// The current platform is determined by querying for the ambient [Theme]. +/// +/// See also: +/// +/// * [CloseButton], an [IconButton] with a [CloseButtonIcon] that calls +/// [Navigator.maybePop] to return to the previous route. +/// * [IconButton], which is a more general widget for creating buttons +/// with icons. +/// * [Icon], a Material Design icon. +/// * [ThemeData.platform], which specifies the current platform. +class CloseButtonIcon extends StatelessWidget { + /// Creates an icon that shows the appropriate "close" image for + /// the current platform (as obtained from the [Theme]). + const CloseButtonIcon({ super.key }); + + @override + Widget build(BuildContext context) { + return _ActionIcon( + iconBuilderCallback: (ActionIconThemeData? actionIconTheme) { + return actionIconTheme?.closeButtonIconBuilder; + }, + getIcon: (BuildContext context) => Icons.close, + getAndroidSemanticsLabel: (MaterialLocalizations materialLocalization) { + return materialLocalization.closeButtonTooltip; + }, + ); + } +} + +/// A Material Design close icon button. +/// +/// A [CloseButton] is an [IconButton] with a "close" icon. When pressed, the +/// close button calls [Navigator.maybePop] to return to the previous route. +/// +/// The [onPressed] callback can, for instance, be used to pop the platform's navigation stack +/// via [SystemNavigator] instead of Flutter's [Navigator] in add-to-app +/// situations. +/// +/// In Material Design 3, both [style]'s [ButtonStyle.iconColor] and [color] are +/// used to override the default icon color of [CloseButton]. If both exist, the [ButtonStyle.iconColor] +/// will override [color] for states where [ButtonStyle.foregroundColor] resolves to non-null. +/// +/// Use a [CloseButton] instead of a [BackButton] on fullscreen dialogs or +/// pages that may solicit additional actions to close. +/// +/// See also: +/// +/// * [AppBar], which automatically uses a [CloseButton] in its +/// [AppBar.leading] slot when appropriate. +/// * [BackButton], which is more appropriate for middle nodes in the +/// navigation tree or where pages can be popped instantaneously with +/// no user data consequence. +/// * [IconButton], to create other Material Design icon buttons. +class CloseButton extends _ActionButton { + /// Creates a Material Design close icon button. + const CloseButton({ super.key, super.color, super.onPressed, super.style }) + : super(icon: const CloseButtonIcon()); + + @override + void _onPressedCallback(BuildContext context) => Navigator.maybePop(context); + + @override + String _getTooltip(BuildContext context) { + return MaterialLocalizations.of(context).closeButtonTooltip; + } +} + +/// A "drawer" icon that's appropriate for the current [TargetPlatform]. +/// +/// The current platform is determined by querying for the ambient [Theme]. +/// +/// See also: +/// +/// * [DrawerButton], an [IconButton] with a [DrawerButtonIcon] that calls +/// [ScaffoldState.openDrawer] to open the [Scaffold.drawer]. +/// * [EndDrawerButton], an [IconButton] with an [EndDrawerButtonIcon] that +/// calls [ScaffoldState.openEndDrawer] to open the [Scaffold.endDrawer]. +/// * [IconButton], which is a more general widget for creating buttons +/// with icons. +/// * [Icon], a Material Design icon. +/// * [ThemeData.platform], which specifies the current platform. +class DrawerButtonIcon extends StatelessWidget { + /// Creates an icon that shows the appropriate "close" image for + /// the current platform (as obtained from the [Theme]). + const DrawerButtonIcon({ super.key }); + + @override + Widget build(BuildContext context) { + return _ActionIcon( + iconBuilderCallback: (ActionIconThemeData? actionIconTheme) { + return actionIconTheme?.drawerButtonIconBuilder; + }, + getIcon: (BuildContext context) => Icons.menu, + getAndroidSemanticsLabel: (MaterialLocalizations materialLocalization) { + return materialLocalization.openAppDrawerTooltip; + }, + ); + } +} + +/// A Material Design drawer icon button. +/// +/// A [DrawerButton] is an [IconButton] with a "drawer" icon. When pressed, the +/// close button calls [ScaffoldState.openDrawer] to the [Scaffold.drawer]. +/// +/// The default behaviour on press can be overridden with [onPressed]. +/// +/// See also: +/// +/// * [EndDrawerButton], an [IconButton] with an [EndDrawerButtonIcon] that +/// calls [ScaffoldState.openEndDrawer] to open the [Scaffold.endDrawer]. +/// * [IconButton], which is a more general widget for creating buttons +/// with icons. +/// * [Icon], a Material Design icon. +/// * [ThemeData.platform], which specifies the current platform. +class DrawerButton extends _ActionButton { + /// Creates a Material Design drawer icon button. + const DrawerButton({ + super.key, + super.style, + super.onPressed, + }) : super(icon: const DrawerButtonIcon()); + + @override + void _onPressedCallback(BuildContext context) => Scaffold.of(context).openDrawer(); + + @override + String _getTooltip(BuildContext context) { + return MaterialLocalizations.of(context).openAppDrawerTooltip; + } +} + +/// A "end drawer" icon that's appropriate for the current [TargetPlatform]. +/// +/// The current platform is determined by querying for the ambient [Theme]. +/// +/// See also: +/// +/// * [DrawerButton], an [IconButton] with a [DrawerButtonIcon] that calls +/// [ScaffoldState.openDrawer] to open the [Scaffold.drawer]. +/// * [EndDrawerButton], an [IconButton] with an [EndDrawerButtonIcon] that +/// calls [ScaffoldState.openEndDrawer] to open the [Scaffold.endDrawer] +/// * [IconButton], which is a more general widget for creating buttons +/// with icons. +/// * [Icon], a Material Design icon. +/// * [ThemeData.platform], which specifies the current platform. +class EndDrawerButtonIcon extends StatelessWidget { + /// Creates an icon that shows the appropriate "end drawer" image for + /// the current platform (as obtained from the [Theme]). + const EndDrawerButtonIcon({ super.key }); + + @override + Widget build(BuildContext context) { + return _ActionIcon( + iconBuilderCallback: (ActionIconThemeData? actionIconTheme) { + return actionIconTheme?.endDrawerButtonIconBuilder; + }, + getIcon: (BuildContext context) => Icons.menu, + getAndroidSemanticsLabel: (MaterialLocalizations materialLocalization) { + return materialLocalization.openAppDrawerTooltip; + }, + ); + } +} + +/// A Material Design end drawer icon button. +/// +/// A [EndDrawerButton] is an [IconButton] with a "drawer" icon. When pressed, the +/// end drawer button calls [ScaffoldState.openEndDrawer] to open the [Scaffold.endDrawer]. +/// +/// The default behaviour on press can be overridden with [onPressed]. +/// +/// See also: +/// +/// * [DrawerButton], an [IconButton] with a [DrawerButtonIcon] that calls +/// [ScaffoldState.openDrawer] to open a drawer. +/// * [IconButton], which is a more general widget for creating buttons +/// with icons. +/// * [Icon], a Material Design icon. +/// * [ThemeData.platform], which specifies the current platform. +class EndDrawerButton extends _ActionButton { + /// Creates a Material Design end drawer icon button. + const EndDrawerButton({ + super.key, + super.style, + super.onPressed, + }) : super(icon: const EndDrawerButtonIcon()); + + @override + void _onPressedCallback(BuildContext context) => Scaffold.of(context).openEndDrawer(); + + @override + String _getTooltip(BuildContext context) { + return MaterialLocalizations.of(context).openAppDrawerTooltip; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/action_chip.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/action_chip.dart new file mode 100644 index 0000000000000000000000000000000000000000..ab773e90b9ad1b421df3a21588f0b0872f4c14ba --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/action_chip.dart @@ -0,0 +1,319 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/widgets.dart'; + +import 'chip.dart'; +import 'chip_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'debug.dart'; +import 'material_state.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +enum _ChipVariant { flat, elevated } + +/// A Material Design action chip. +/// +/// Action chips are a set of options which trigger an action related to primary +/// content. Action chips should appear dynamically and contextually in a UI. +/// +/// Action chips can be tapped to trigger an action or show progress and +/// confirmation. For Material 3, a disabled state is supported for Action +/// chips and is specified with [onPressed] being null. For previous versions +/// of Material Design, it is recommended to remove the Action chip from +/// the interface entirely rather than display a disabled chip. +/// +/// Action chips are displayed after primary content, such as below a card or +/// persistently at the bottom of a screen. +/// +/// The material button widgets, [ElevatedButton], [TextButton], and +/// [OutlinedButton], are an alternative to action chips, which should appear +/// statically and consistently in a UI. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// {@tool dartpad} +/// This example shows how to create an [ActionChip] with a leading icon. +/// The icon is updated when the [ActionChip] is pressed. +/// +/// ** See code in examples/api/lib/material/action_chip/action_chip.0.dart ** +/// {@end-tool} +/// +/// ## Material Design 3 +/// +/// [ActionChip] can be used for both the Assist and Suggestion chips from +/// Material Design 3. If [ThemeData.useMaterial3] is true, then [ActionChip] +/// will be styled to match the Material Design 3 Assist and Suggestion chips. +/// +/// ### Creating an Assist chip +/// +/// Assist chips are used to provide a quick way to perform an action. +/// To create an Action chip, set the icon property to the icon +/// that represents the action and set the label to the name of the action. +/// +/// +/// ### Creating a Suggestion chip +/// +/// Suggestion chips usually display generated suggestions for the user, +/// like a suggested response to a message. +/// +/// To create a Suggestion chip, set the label to the suggestion +/// and don't set the icon property. +// +/// +/// See also: +/// +/// * [Chip], a chip that displays information and can be deleted. +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [CircleAvatar], which shows images or initials of people. +/// * [Wrap], A widget that displays its children in multiple horizontal or +/// vertical runs. +/// * <https://material.io/design/components/chips.html> +class ActionChip extends StatelessWidget implements ChipAttributes, TappableChipAttributes, DisabledChipAttributes { + /// Create a chip that acts like a button. + /// + /// The [label], [onPressed], [autofocus], and [clipBehavior] arguments must + /// not be null. The [pressElevation] and [elevation] must be null or + /// non-negative. Typically, [pressElevation] is greater than [elevation]. + const ActionChip({ + super.key, + this.avatar, + required this.label, + this.labelStyle, + this.labelPadding, + this.onPressed, + this.pressElevation, + this.tooltip, + this.side, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.color, + this.backgroundColor, + this.disabledColor, + this.padding, + this.visualDensity, + this.materialTapTargetSize, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.iconTheme, + }) : assert(pressElevation == null || pressElevation >= 0.0), + assert(elevation == null || elevation >= 0.0), + _chipVariant = _ChipVariant.flat; + + /// Create an elevated chip that acts like a button. + /// + /// The [label], [onPressed], [autofocus], and [clipBehavior] arguments must + /// not be null. The [pressElevation] and [elevation] must be null or + /// non-negative. Typically, [pressElevation] is greater than [elevation]. + const ActionChip.elevated({ + super.key, + this.avatar, + required this.label, + this.labelStyle, + this.labelPadding, + this.onPressed, + this.pressElevation, + this.tooltip, + this.side, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.color, + this.backgroundColor, + this.disabledColor, + this.padding, + this.visualDensity, + this.materialTapTargetSize, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.iconTheme, + }) : assert(pressElevation == null || pressElevation >= 0.0), + assert(elevation == null || elevation >= 0.0), + _chipVariant = _ChipVariant.elevated; + + @override + final Widget? avatar; + @override + final Widget label; + @override + final TextStyle? labelStyle; + @override + final EdgeInsetsGeometry? labelPadding; + @override + final VoidCallback? onPressed; + @override + final double? pressElevation; + @override + final String? tooltip; + @override + final BorderSide? side; + @override + final OutlinedBorder? shape; + @override + final Clip clipBehavior; + @override + final FocusNode? focusNode; + @override + final bool autofocus; + @override + final MaterialStateProperty<Color?>? color; + @override + final Color? backgroundColor; + @override + final Color? disabledColor; + @override + final EdgeInsetsGeometry? padding; + @override + final VisualDensity? visualDensity; + @override + final MaterialTapTargetSize? materialTapTargetSize; + @override + final double? elevation; + @override + final Color? shadowColor; + @override + final Color? surfaceTintColor; + @override + final IconThemeData? iconTheme; + + @override + bool get isEnabled => onPressed != null; + + final _ChipVariant _chipVariant; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + final ChipThemeData? defaults = Theme.of(context).useMaterial3 + ? _ActionChipDefaultsM3(context, isEnabled, _chipVariant) + : null; + return RawChip( + defaultProperties: defaults, + avatar: avatar, + label: label, + onPressed: onPressed, + pressElevation: pressElevation, + tooltip: tooltip, + labelStyle: labelStyle, + color: color, + backgroundColor: backgroundColor, + side: side, + shape: shape, + clipBehavior: clipBehavior, + focusNode: focusNode, + autofocus: autofocus, + disabledColor: disabledColor, + padding: padding, + visualDensity: visualDensity, + isEnabled: isEnabled, + labelPadding: labelPadding, + materialTapTargetSize: materialTapTargetSize, + elevation: elevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + iconTheme: iconTheme, + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - ActionChip + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _ActionChipDefaultsM3 extends ChipThemeData { + _ActionChipDefaultsM3(this.context, this.isEnabled, this._chipVariant) + : super( + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))), + showCheckmark: true, + ); + + final BuildContext context; + final bool isEnabled; + final _ChipVariant _chipVariant; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + double? get elevation => _chipVariant == _ChipVariant.flat + ? 0.0 + : isEnabled ? 1.0 : 0.0; + + @override + double? get pressElevation => 1.0; + + @override + TextStyle? get labelStyle => _textTheme.labelLarge; + + @override + MaterialStateProperty<Color?>? get color => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _chipVariant == _ChipVariant.flat + ? null + : _colors.onSurface.withOpacity(0.12); + } + return null; + }); + + @override + Color? get shadowColor => _chipVariant == _ChipVariant.flat + ? Colors.transparent + : _colors.shadow; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + Color? get checkmarkColor => null; + + @override + Color? get deleteIconColor => null; + + @override + BorderSide? get side => _chipVariant == _ChipVariant.flat + ? isEnabled + ? BorderSide(color: _colors.outline) + : BorderSide(color: _colors.onSurface.withOpacity(0.12)) + : const BorderSide(color: Colors.transparent); + + @override + IconThemeData? get iconTheme => IconThemeData( + color: isEnabled + ? _colors.primary + : _colors.onSurface, + size: 18.0, + ); + + @override + EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0); + + /// The chip at text scale 1 starts with 8px on each side and as text scaling + /// gets closer to 2 the label padding is linearly interpolated from 8px to 4px. + /// Once the widget has a text scaling of 2 or higher than the label padding + /// remains 4px. + @override + EdgeInsetsGeometry? get labelPadding => EdgeInsets.lerp( + const EdgeInsets.symmetric(horizontal: 8.0), + const EdgeInsets.symmetric(horizontal: 4.0), + clampDouble(MediaQuery.textScalerOf(context).textScaleFactor - 1.0, 0.0, 1.0), + )!; +} + +// END GENERATED TOKEN PROPERTIES - ActionChip diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/action_icons_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/action_icons_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..6c291e6b1ebd25e911c659a75bfb232ce585b013 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/action_icons_theme.dart @@ -0,0 +1,160 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'action_buttons.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// A [ActionIconThemeData] that overrides the default icons of +/// [BackButton], [CloseButton], [DrawerButton], and [EndDrawerButton] with +/// [ActionIconTheme.of] or the overall [Theme]'s [ThemeData.actionIconTheme]. +@immutable +class ActionIconThemeData with Diagnosticable { + /// Creates an [ActionIconThemeData]. + /// + /// The builders [backButtonIconBuilder], [closeButtonIconBuilder], + /// [drawerButtonIconBuilder], [endDrawerButtonIconBuilder] may be null. + const ActionIconThemeData({ this.backButtonIconBuilder, this.closeButtonIconBuilder, this.drawerButtonIconBuilder, this.endDrawerButtonIconBuilder }); + + /// Overrides [BackButtonIcon]'s icon. + /// + /// If [backButtonIconBuilder] is null, then [BackButtonIcon] + /// fallbacks to the platform's default back button icon. + final WidgetBuilder? backButtonIconBuilder; + + /// Overrides [CloseButtonIcon]'s icon. + /// + /// If [closeButtonIconBuilder] is null, then [CloseButtonIcon] + /// fallbacks to the platform's default close button icon. + final WidgetBuilder? closeButtonIconBuilder; + + /// Overrides [DrawerButtonIcon]'s icon. + /// + /// If [drawerButtonIconBuilder] is null, then [DrawerButtonIcon] + /// fallbacks to the platform's default drawer button icon. + final WidgetBuilder? drawerButtonIconBuilder; + + /// Overrides [EndDrawerButtonIcon]'s icon. + /// + /// If [endDrawerButtonIconBuilder] is null, then [EndDrawerButtonIcon] + /// fallbacks to the platform's default end drawer button icon. + final WidgetBuilder? endDrawerButtonIconBuilder; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + ActionIconThemeData copyWith({ + WidgetBuilder? backButtonIconBuilder, + WidgetBuilder? closeButtonIconBuilder, + WidgetBuilder? drawerButtonIconBuilder, + WidgetBuilder? endDrawerButtonIconBuilder, + }) { + return ActionIconThemeData( + backButtonIconBuilder: backButtonIconBuilder ?? this.backButtonIconBuilder, + closeButtonIconBuilder: closeButtonIconBuilder ?? this.closeButtonIconBuilder, + drawerButtonIconBuilder: drawerButtonIconBuilder ?? this.drawerButtonIconBuilder, + endDrawerButtonIconBuilder: endDrawerButtonIconBuilder ?? this.endDrawerButtonIconBuilder, + ); + } + + /// Linearly interpolate between two action icon themes. + static ActionIconThemeData? lerp(ActionIconThemeData? a, ActionIconThemeData? b, double t) { + if (a == null && b == null) { + return null; + } + return ActionIconThemeData( + backButtonIconBuilder: t < 0.5 ? a?.backButtonIconBuilder : b?.backButtonIconBuilder, + closeButtonIconBuilder: t < 0.5 ? a?.closeButtonIconBuilder : b?.closeButtonIconBuilder, + drawerButtonIconBuilder: t < 0.5 ? a?.drawerButtonIconBuilder : b?.drawerButtonIconBuilder, + endDrawerButtonIconBuilder: t < 0.5 ? a?.endDrawerButtonIconBuilder : b?.endDrawerButtonIconBuilder, + ); + } + + @override + int get hashCode { + final List<Object?> values = <Object?>[ + backButtonIconBuilder, + closeButtonIconBuilder, + drawerButtonIconBuilder, + endDrawerButtonIconBuilder, + ]; + return Object.hashAll(values); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ActionIconThemeData + && other.backButtonIconBuilder == backButtonIconBuilder + && other.closeButtonIconBuilder == closeButtonIconBuilder + && other.drawerButtonIconBuilder == drawerButtonIconBuilder + && other.endDrawerButtonIconBuilder == endDrawerButtonIconBuilder; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<WidgetBuilder>('backButtonIconBuilder', backButtonIconBuilder, defaultValue: null)); + properties.add(DiagnosticsProperty<WidgetBuilder>('closeButtonIconBuilder', closeButtonIconBuilder, defaultValue: null)); + properties.add(DiagnosticsProperty<WidgetBuilder>('drawerButtonIconBuilder', drawerButtonIconBuilder, defaultValue: null)); + properties.add(DiagnosticsProperty<WidgetBuilder>('endDrawerButtonIconBuilder', endDrawerButtonIconBuilder, defaultValue: null)); + } +} + +/// An inherited widget that overrides the default icon of [BackButtonIcon], +/// [CloseButtonIcon], [DrawerButtonIcon], and [EndDrawerButtonIcon] in this +/// widget's subtree. +/// +/// {@tool dartpad} +/// This example shows how to define custom builders for drawer and back +/// buttons. +/// +/// ** See code in examples/api/lib/material/action_buttons/action_icon_theme.0.dart ** +/// {@end-tool} +class ActionIconTheme extends InheritedTheme { + /// Creates a theme that overrides the default icon of [BackButtonIcon], + /// [CloseButtonIcon], [DrawerButtonIcon], and [EndDrawerButtonIcon] in this + /// widget's subtree. + const ActionIconTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the default icon overrides for descendant [BackButtonIcon], + /// [CloseButtonIcon], [DrawerButtonIcon], and [EndDrawerButtonIcon] widgets. + final ActionIconThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [ActionIconTheme] widget, then + /// [ThemeData.actionIconTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ActionIconThemeData? theme = ActionIconTheme.of(context); + /// ``` + static ActionIconThemeData? of(BuildContext context) { + final ActionIconTheme? actionIconTheme = context.dependOnInheritedWidgetOfExactType<ActionIconTheme>(); + return actionIconTheme?.data ?? Theme.of(context).actionIconTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return ActionIconTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(ActionIconTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/adaptive_text_selection_toolbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/adaptive_text_selection_toolbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..e1323fa8bd8b43ace19b90fd8935feea2f4bde03 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/adaptive_text_selection_toolbar.dart @@ -0,0 +1,335 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/rendering.dart'; + +import 'debug.dart'; +import 'desktop_text_selection_toolbar.dart'; +import 'desktop_text_selection_toolbar_button.dart'; +import 'material_localizations.dart'; +import 'text_selection_toolbar.dart'; +import 'text_selection_toolbar_text_button.dart'; +import 'theme.dart'; + +/// The default context menu for text selection for the current platform. +/// +/// {@template flutter.material.AdaptiveTextSelectionToolbar.contextMenuBuilders} +/// Typically, this widget would be passed to `contextMenuBuilder` in a +/// supported parent widget, such as: +/// +/// * [EditableText.contextMenuBuilder] +/// * [TextField.contextMenuBuilder] +/// * [CupertinoTextField.contextMenuBuilder] +/// * [SelectionArea.contextMenuBuilder] +/// * [SelectableText.contextMenuBuilder] +/// {@endtemplate} +/// +/// See also: +/// +/// * [EditableText.getEditableButtonItems], which returns the default +/// [ContextMenuButtonItem]s for [EditableText] on the platform. +/// * [AdaptiveTextSelectionToolbar.getAdaptiveButtons], which builds the button +/// Widgets for the current platform given [ContextMenuButtonItem]s. +/// * [CupertinoAdaptiveTextSelectionToolbar], which does the same thing as this +/// widget but only for Cupertino context menus. +/// * [TextSelectionToolbar], the default toolbar for Android. +/// * [DesktopTextSelectionToolbar], the default toolbar for desktop platforms +/// other than MacOS. +/// * [CupertinoTextSelectionToolbar], the default toolbar for iOS. +/// * [CupertinoDesktopTextSelectionToolbar], the default toolbar for MacOS. +class AdaptiveTextSelectionToolbar extends StatelessWidget { + /// Create an instance of [AdaptiveTextSelectionToolbar] with the + /// given [children]. + /// + /// See also: + /// + /// {@template flutter.material.AdaptiveTextSelectionToolbar.buttonItems} + /// * [AdaptiveTextSelectionToolbar.buttonItems], which takes a list of + /// [ContextMenuButtonItem]s instead of [children] widgets. + /// {@endtemplate} + /// {@template flutter.material.AdaptiveTextSelectionToolbar.editable} + /// * [AdaptiveTextSelectionToolbar.editable], which builds the default + /// children for an editable field. + /// {@endtemplate} + /// {@template flutter.material.AdaptiveTextSelectionToolbar.editableText} + /// * [AdaptiveTextSelectionToolbar.editableText], which builds the default + /// children for an [EditableText]. + /// {@endtemplate} + /// {@template flutter.material.AdaptiveTextSelectionToolbar.selectable} + /// * [AdaptiveTextSelectionToolbar.selectable], which builds the default + /// children for content that is selectable but not editable. + /// {@endtemplate} + const AdaptiveTextSelectionToolbar({ + super.key, + required this.children, + required this.anchors, + }) : buttonItems = null; + + /// Create an instance of [AdaptiveTextSelectionToolbar] whose children will + /// be built from the given [buttonItems]. + /// + /// See also: + /// + /// {@template flutter.material.AdaptiveTextSelectionToolbar.new} + /// * [AdaptiveTextSelectionToolbar.new], which takes the children directly as + /// a list of widgets. + /// {@endtemplate} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.editable} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.editableText} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.selectable} + const AdaptiveTextSelectionToolbar.buttonItems({ + super.key, + required this.buttonItems, + required this.anchors, + }) : children = null; + + /// Create an instance of [AdaptiveTextSelectionToolbar] with the default + /// children for an editable field. + /// + /// If a callback is null, then its corresponding button will not be built. + /// + /// See also: + /// + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.new} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.editableText} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.buttonItems} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.selectable} + AdaptiveTextSelectionToolbar.editable({ + super.key, + required ClipboardStatus clipboardStatus, + required VoidCallback? onCopy, + required VoidCallback? onCut, + required VoidCallback? onPaste, + required VoidCallback? onSelectAll, + required VoidCallback? onLookUp, + required VoidCallback? onSearchWeb, + required VoidCallback? onShare, + required VoidCallback? onLiveTextInput, + required this.anchors, + }) : children = null, + buttonItems = EditableText.getEditableButtonItems( + clipboardStatus: clipboardStatus, + onCopy: onCopy, + onCut: onCut, + onPaste: onPaste, + onSelectAll: onSelectAll, + onLookUp: onLookUp, + onSearchWeb: onSearchWeb, + onShare: onShare, + onLiveTextInput: onLiveTextInput + ); + + /// Create an instance of [AdaptiveTextSelectionToolbar] with the default + /// children for an [EditableText]. + /// + /// See also: + /// + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.new} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.editable} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.buttonItems} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.selectable} + AdaptiveTextSelectionToolbar.editableText({ + super.key, + required EditableTextState editableTextState, + }) : children = null, + buttonItems = editableTextState.contextMenuButtonItems, + anchors = editableTextState.contextMenuAnchors; + + /// Create an instance of [AdaptiveTextSelectionToolbar] with the default + /// children for selectable, but not editable, content. + /// + /// See also: + /// + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.new} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.buttonItems} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.editable} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.editableText} + AdaptiveTextSelectionToolbar.selectable({ + super.key, + required VoidCallback onCopy, + required VoidCallback onSelectAll, + required SelectionGeometry selectionGeometry, + required this.anchors, + }) : children = null, + buttonItems = SelectableRegion.getSelectableButtonItems( + selectionGeometry: selectionGeometry, + onCopy: onCopy, + onSelectAll: onSelectAll, + ); + + /// Create an instance of [AdaptiveTextSelectionToolbar] with the default + /// children for a [SelectableRegion]. + /// + /// See also: + /// + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.new} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.buttonItems} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.editable} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.editableText} + /// {@macro flutter.material.AdaptiveTextSelectionToolbar.selectable} + AdaptiveTextSelectionToolbar.selectableRegion({ + super.key, + required SelectableRegionState selectableRegionState, + }) : children = null, + buttonItems = selectableRegionState.contextMenuButtonItems, + anchors = selectableRegionState.contextMenuAnchors; + + /// {@template flutter.material.AdaptiveTextSelectionToolbar.buttonItems} + /// The [ContextMenuButtonItem]s that will be turned into the correct button + /// widgets for the current platform. + /// {@endtemplate} + final List<ContextMenuButtonItem>? buttonItems; + + /// The children of the toolbar, typically buttons. + final List<Widget>? children; + + /// {@template flutter.material.AdaptiveTextSelectionToolbar.anchors} + /// The location on which to anchor the menu. + /// {@endtemplate} + final TextSelectionToolbarAnchors anchors; + + /// Returns the default button label String for the button of the given + /// [ContextMenuButtonType] on any platform. + static String getButtonLabel(BuildContext context, ContextMenuButtonItem buttonItem) { + if (buttonItem.label != null) { + return buttonItem.label!; + } + + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return CupertinoTextSelectionToolbarButton.getButtonLabel( + context, + buttonItem, + ); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + assert(debugCheckHasMaterialLocalizations(context)); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + switch (buttonItem.type) { + case ContextMenuButtonType.cut: + return localizations.cutButtonLabel; + case ContextMenuButtonType.copy: + return localizations.copyButtonLabel; + case ContextMenuButtonType.paste: + return localizations.pasteButtonLabel; + case ContextMenuButtonType.selectAll: + return localizations.selectAllButtonLabel; + case ContextMenuButtonType.delete: + return localizations.deleteButtonTooltip.toUpperCase(); + case ContextMenuButtonType.lookUp: + return localizations.lookUpButtonLabel; + case ContextMenuButtonType.searchWeb: + return localizations.searchWebButtonLabel; + case ContextMenuButtonType.share: + return localizations.shareButtonLabel; + case ContextMenuButtonType.liveTextInput: + return localizations.scanTextButtonLabel; + case ContextMenuButtonType.custom: + return ''; + } + } + } + + /// Returns a List of Widgets generated by turning [buttonItems] into the + /// default context menu buttons for the current platform. + /// + /// This is useful when building a text selection toolbar with the default + /// button appearance for the given platform, but where the toolbar and/or the + /// button actions and labels may be custom. + /// + /// {@tool dartpad} + /// This sample demonstrates how to use `getAdaptiveButtons` to generate + /// default button widgets in a custom toolbar. + /// + /// ** See code in examples/api/lib/material/context_menu/editable_text_toolbar_builder.2.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [CupertinoAdaptiveTextSelectionToolbar.getAdaptiveButtons], which is the + /// Cupertino equivalent of this class and builds only the Cupertino + /// buttons. + static Iterable<Widget> getAdaptiveButtons(BuildContext context, List<ContextMenuButtonItem> buttonItems) { + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + return buttonItems.map((ContextMenuButtonItem buttonItem) { + return CupertinoTextSelectionToolbarButton.buttonItem( + buttonItem: buttonItem, + ); + }); + case TargetPlatform.fuchsia: + case TargetPlatform.android: + final List<Widget> buttons = <Widget>[]; + for (int i = 0; i < buttonItems.length; i++) { + final ContextMenuButtonItem buttonItem = buttonItems[i]; + buttons.add(TextSelectionToolbarTextButton( + padding: TextSelectionToolbarTextButton.getPadding(i, buttonItems.length), + onPressed: buttonItem.onPressed, + child: Text(getButtonLabel(context, buttonItem)), + )); + } + return buttons; + case TargetPlatform.linux: + case TargetPlatform.windows: + return buttonItems.map((ContextMenuButtonItem buttonItem) { + return DesktopTextSelectionToolbarButton.text( + context: context, + onPressed: buttonItem.onPressed, + text: getButtonLabel(context, buttonItem), + ); + }); + case TargetPlatform.macOS: + return buttonItems.map((ContextMenuButtonItem buttonItem) { + return CupertinoDesktopTextSelectionToolbarButton.text( + onPressed: buttonItem.onPressed, + text: getButtonLabel(context, buttonItem), + ); + }); + } + } + + @override + Widget build(BuildContext context) { + // If there aren't any buttons to build, build an empty toolbar. + if ((children != null && children!.isEmpty) + || (buttonItems != null && buttonItems!.isEmpty)) { + return const SizedBox.shrink(); + } + + final List<Widget> resultChildren = children != null + ? children! + : getAdaptiveButtons(context, buttonItems!).toList(); + + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + return CupertinoTextSelectionToolbar( + anchorAbove: anchors.primaryAnchor, + anchorBelow: anchors.secondaryAnchor == null ? anchors.primaryAnchor : anchors.secondaryAnchor!, + children: resultChildren, + ); + case TargetPlatform.android: + return TextSelectionToolbar( + anchorAbove: anchors.primaryAnchor, + anchorBelow: anchors.secondaryAnchor == null ? anchors.primaryAnchor : anchors.secondaryAnchor!, + children: resultChildren, + ); + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return DesktopTextSelectionToolbar( + anchor: anchors.primaryAnchor, + children: resultChildren, + ); + case TargetPlatform.macOS: + return CupertinoDesktopTextSelectionToolbar( + anchor: anchors.primaryAnchor, + children: resultChildren, + ); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons.dart new file mode 100644 index 0000000000000000000000000000000000000000..12ae800e750b23deb40f68afb68bc8b47a8b93be --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons.dart @@ -0,0 +1,38 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Flutter widgets implementing Material Design animated icons. +library material_animated_icons; + +import 'dart:math' as math show pi; +import 'dart:ui' as ui show Canvas, Paint, Path, lerpDouble; + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/widgets.dart'; + +// This package is split into multiple parts to enable a private API that is +// testable. + +// Public API. +part 'animated_icons/animated_icons.dart'; + +// Provides a public interface for referring to the private icon +// implementations. +part 'animated_icons/animated_icons_data.dart'; + +// Generated animated icon data files. +part 'animated_icons/data/add_event.g.dart'; +part 'animated_icons/data/arrow_menu.g.dart'; +part 'animated_icons/data/close_menu.g.dart'; +part 'animated_icons/data/ellipsis_search.g.dart'; +part 'animated_icons/data/event_add.g.dart'; +part 'animated_icons/data/home_menu.g.dart'; +part 'animated_icons/data/list_view.g.dart'; +part 'animated_icons/data/menu_arrow.g.dart'; +part 'animated_icons/data/menu_close.g.dart'; +part 'animated_icons/data/menu_home.g.dart'; +part 'animated_icons/data/pause_play.g.dart'; +part 'animated_icons/data/play_pause.g.dart'; +part 'animated_icons/data/search_ellipsis.g.dart'; +part 'animated_icons/data/view_list.g.dart'; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/animated_icons.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/animated_icons.dart new file mode 100644 index 0000000000000000000000000000000000000000..09feb5eced18d47285d32d8618889a0bb4bd2a10 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/animated_icons.dart @@ -0,0 +1,303 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// TODO(goderbauer): Clean up the part-of hack currently used for testing the private implementation. +part of material_animated_icons; // ignore: use_string_in_part_of_directives + +// The code for drawing animated icons is kept in a private API, as we are not +// yet ready for exposing a public API for (partial) vector graphics support. +// See: https://github.com/flutter/flutter/issues/1831 for details regarding +// generic vector graphics support in Flutter. + +/// Shows an animated icon at a given animation [progress]. +/// +/// The available icons are specified in [AnimatedIcons]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=pJcbh8pbvJs} +/// +/// {@tool dartpad} +/// This example shows how to create an animated icon. The icon is animated +/// forward and reverse in a loop. +/// +/// ** See code in examples/api/lib/material/animated_icon/animated_icon.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Icons], for the list of available static Material Icons. +class AnimatedIcon extends StatelessWidget { + /// Creates an AnimatedIcon. + /// + /// The [size] and [color] default to the value given by the current + /// [IconTheme]. + const AnimatedIcon({ + super.key, + required this.icon, + required this.progress, + this.color, + this.size, + this.semanticLabel, + this.textDirection, + }); + + /// The animation progress for the animated icon. + /// + /// The value is clamped to be between 0 and 1. + /// + /// This determines the actual frame that is displayed. + final Animation<double> progress; + + /// The color to use when drawing the icon. + /// + /// Defaults to the current [IconTheme] color, if any. + /// + /// The given color will be adjusted by the opacity of the current + /// [IconTheme], if any. + /// + /// In material apps, if there is a [Theme] without any [IconTheme]s + /// specified, icon colors default to white if the theme is dark + /// and black if the theme is light. + /// + /// If no [IconTheme] and no [Theme] is specified, icons will default to black. + /// + /// See [Theme] to set the current theme and [ThemeData.brightness] + /// for setting the current theme's brightness. + final Color? color; + + /// The size of the icon in logical pixels. + /// + /// Icons occupy a square with width and height equal to size. + /// + /// Defaults to the current [IconTheme] size. + final double? size; + + /// The icon to display. Available icons are listed in [AnimatedIcons]. + final AnimatedIconData icon; + + /// Semantic label for the icon. + /// + /// Announced in accessibility modes (e.g TalkBack/VoiceOver). + /// This label does not show in the UI. + /// + /// See also: + /// + /// * [SemanticsProperties.label], which is set to [semanticLabel] in the + /// underlying [Semantics] widget. + final String? semanticLabel; + + /// The text direction to use for rendering the icon. + /// + /// If this is null, the ambient [Directionality] is used instead. + /// + /// If the text direction is [TextDirection.rtl], the icon will be mirrored + /// horizontally (e.g back arrow will point right). + final TextDirection? textDirection; + + static ui.Path _pathFactory() => ui.Path(); + + @override + Widget build(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + final _AnimatedIconData iconData = icon as _AnimatedIconData; + final IconThemeData iconTheme = IconTheme.of(context); + assert(iconTheme.isConcrete); + final double iconSize = size ?? iconTheme.size!; + final TextDirection textDirection = this.textDirection ?? Directionality.of(context); + final double iconOpacity = iconTheme.opacity!; + Color iconColor = color ?? iconTheme.color!; + if (iconOpacity != 1.0) { + iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity); + } + return Semantics( + label: semanticLabel, + child: CustomPaint( + size: Size(iconSize, iconSize), + painter: _AnimatedIconPainter( + paths: iconData.paths, + progress: progress, + color: iconColor, + scale: iconSize / iconData.size.width, + shouldMirror: textDirection == TextDirection.rtl && iconData.matchTextDirection, + uiPathFactory: _pathFactory, + ), + ), + ); + } +} + +typedef _UiPathFactory = ui.Path Function(); + +class _AnimatedIconPainter extends CustomPainter { + _AnimatedIconPainter({ + required this.paths, + required this.progress, + required this.color, + required this.scale, + required this.shouldMirror, + required this.uiPathFactory, + }) : super(repaint: progress); + + // This list is assumed to be immutable, changes to the contents of the list + // will not trigger a redraw as shouldRepaint will keep returning false. + final List<_PathFrames> paths; + final Animation<double> progress; + final Color color; + final double scale; + /// If this is true the image will be mirrored horizontally. + final bool shouldMirror; + final _UiPathFactory uiPathFactory; + + @override + void paint(ui.Canvas canvas, Size size) { + // The RenderCustomPaint render object performs canvas.save before invoking + // this and canvas.restore after, so we don't need to do it here. + if (shouldMirror) { + canvas.rotate(math.pi); + canvas.translate(-size.width, -size.height); + } + canvas.scale(scale, scale); + + final double clampedProgress = clampDouble(progress.value, 0.0, 1.0); + for (final _PathFrames path in paths) { + path.paint(canvas, color, uiPathFactory, clampedProgress); + } + } + + + @override + bool shouldRepaint(_AnimatedIconPainter oldDelegate) { + return oldDelegate.progress.value != progress.value + || oldDelegate.color != color + // We are comparing the paths list by reference, assuming the list is + // treated as immutable to be more efficient. + || oldDelegate.paths != paths + || oldDelegate.scale != scale + || oldDelegate.uiPathFactory != uiPathFactory; + } + + @override + bool? hitTest(Offset position) => null; + + @override + bool shouldRebuildSemantics(CustomPainter oldDelegate) => false; + + @override + SemanticsBuilderCallback? get semanticsBuilder => null; +} + +class _PathFrames { + const _PathFrames({ + required this.commands, + required this.opacities, + }); + + final List<_PathCommand> commands; + final List<double> opacities; + + void paint(ui.Canvas canvas, Color color, _UiPathFactory uiPathFactory, double progress) { + final double opacity = _interpolate<double?>(opacities, progress, ui.lerpDouble)!; + final ui.Paint paint = ui.Paint() + ..style = PaintingStyle.fill + ..color = color.withOpacity(color.opacity * opacity); + final ui.Path path = uiPathFactory(); + for (final _PathCommand command in commands) { + command.apply(path, progress); + } + canvas.drawPath(path, paint); + } +} + +/// Paths are being built by a set of commands e.g moveTo, lineTo, etc... +/// +/// _PathCommand instances represents such a command, and can apply it to +/// a given Path. +abstract class _PathCommand { + const _PathCommand(); + + /// Applies the path command to [path]. + /// + /// For example if the object is a [_PathMoveTo] command it will invoke + /// [Path.moveTo] on [path]. + void apply(ui.Path path, double progress); +} + +class _PathMoveTo extends _PathCommand { + const _PathMoveTo(this.points); + + final List<Offset> points; + + @override + void apply(Path path, double progress) { + final Offset offset = _interpolate<Offset?>(points, progress, Offset.lerp)!; + path.moveTo(offset.dx, offset.dy); + } +} + +class _PathCubicTo extends _PathCommand { + const _PathCubicTo(this.controlPoints1, this.controlPoints2, this.targetPoints); + + final List<Offset> controlPoints2; + final List<Offset> controlPoints1; + final List<Offset> targetPoints; + + @override + void apply(Path path, double progress) { + final Offset controlPoint1 = _interpolate<Offset?>(controlPoints1, progress, Offset.lerp)!; + final Offset controlPoint2 = _interpolate<Offset?>(controlPoints2, progress, Offset.lerp)!; + final Offset targetPoint = _interpolate<Offset?>(targetPoints, progress, Offset.lerp)!; + path.cubicTo( + controlPoint1.dx, controlPoint1.dy, + controlPoint2.dx, controlPoint2.dy, + targetPoint.dx, targetPoint.dy, + ); + } +} + +// ignore: unused_element +class _PathLineTo extends _PathCommand { + const _PathLineTo(this.points); + + final List<Offset> points; + + @override + void apply(Path path, double progress) { + final Offset point = _interpolate<Offset?>(points, progress, Offset.lerp)!; + path.lineTo(point.dx, point.dy); + } +} + +class _PathClose extends _PathCommand { + const _PathClose(); + + @override + void apply(Path path, double progress) { + path.close(); + } +} + +/// Interpolates a value given a set of values equally spaced in time. +/// +/// [interpolator] is the interpolation function used to interpolate between 2 +/// points of type T. +/// +/// This is currently done with linear interpolation between every 2 consecutive +/// points. Linear interpolation was smooth enough with the limited set of +/// animations we have tested, so we use it for simplicity. If we find this to +/// not be smooth enough we can try applying spline instead. +/// +/// [progress] is expected to be between 0.0 and 1.0. +T _interpolate<T>(List<T> values, double progress, _Interpolator<T> interpolator) { + assert(progress <= 1.0); + assert(progress >= 0.0); + if (values.length == 1) { + return values[0]; + } + final double targetIdx = ui.lerpDouble(0, values.length -1, progress)!; + final int lowIdx = targetIdx.floor(); + final int highIdx = targetIdx.ceil(); + final double t = targetIdx - lowIdx; + return interpolator(values[lowIdx], values[highIdx], t); +} + +typedef _Interpolator<T> = T Function(T a, T b, double progress); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/animated_icons_data.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/animated_icons_data.dart new file mode 100644 index 0000000000000000000000000000000000000000..538e9f8157f2068d5555e169194ffe1370801bab --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/animated_icons_data.dart @@ -0,0 +1,131 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file serves as the interface between the public and private APIs for +// animated icons. +// The AnimatedIcons class is public and is used to specify available icons, +// while the _AnimatedIconData interface which used to deliver the icon data is +// kept private. + +part of material_animated_icons; // ignore: use_string_in_part_of_directives + +/// Identifier for the supported Material Design animated icons. +/// +/// Use with [AnimatedIcon] class to show specific animated icons. +/// +/// {@tool dartpad} +/// This example shows how to create an animated icon. The icon is animated +/// forward and reverse in a loop. +/// +/// ** See code in examples/api/lib/material/animated_icon/animated_icons_data.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Icons], for the list of available static Material Icons. +abstract final class AnimatedIcons { + /// The Material Design add to event icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/add_event.mp4} + static const AnimatedIconData add_event = _$add_event; + + /// The Material Design arrow to menu icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/arrow_menu.mp4} + static const AnimatedIconData arrow_menu = _$arrow_menu; + + /// The Material Design close to menu icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/close_menu.mp4} + static const AnimatedIconData close_menu = _$close_menu; + + /// The Material Design ellipsis to search icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/ellipsis_search.mp4} + static const AnimatedIconData ellipsis_search = _$ellipsis_search; + + /// The Material Design event to add icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/event_add.mp4} + static const AnimatedIconData event_add = _$event_add; + + /// The Material Design home to menu icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/home_menu.mp4} + static const AnimatedIconData home_menu = _$home_menu; + + /// The Material Design list to view icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/list_view.mp4} + static const AnimatedIconData list_view = _$list_view; + + /// The Material Design menu to arrow icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/menu_arrow.mp4} + static const AnimatedIconData menu_arrow = _$menu_arrow; + + /// The Material Design menu to close icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/menu_close.mp4} + static const AnimatedIconData menu_close = _$menu_close; + + /// The Material Design menu to home icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/menu_home.mp4} + static const AnimatedIconData menu_home = _$menu_home; + + /// The Material Design pause to play icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/pause_play.mp4} + static const AnimatedIconData pause_play = _$pause_play; + + /// The Material Design play to pause icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/play_pause.mp4} + static const AnimatedIconData play_pause = _$play_pause; + + /// The Material Design search to ellipsis icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/search_ellipsis.mp4} + static const AnimatedIconData search_ellipsis = _$search_ellipsis; + + /// The Material Design view to list icon animation. + /// + /// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/view_list.mp4} + static const AnimatedIconData view_list = _$view_list; +} + +/// Vector graphics data for icons used by [AnimatedIcon]. +/// +/// Instances of this class are currently opaque because we have not committed to a specific +/// animated vector graphics format. +/// +/// See also: +/// +/// * [AnimatedIcons], a class that contains constants that implement this interface. +abstract class AnimatedIconData { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const AnimatedIconData(); + + /// Whether this icon should be mirrored horizontally when text direction is + /// right-to-left. + /// + /// See also: + /// + /// * [TextDirection], which discusses concerns regarding reading direction + /// in Flutter. + /// * [Directionality], a widget which determines the ambient directionality. + bool get matchTextDirection; +} + +class _AnimatedIconData extends AnimatedIconData { + const _AnimatedIconData(this.size, this.paths, {this.matchTextDirection = false}); + + final Size size; + final List<_PathFrames> paths; + + @override + final bool matchTextDirection; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/add_event.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/add_event.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..88d4600bf93e834c98e10f0c19ee334a1ceb11c7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/add_event.g.dart @@ -0,0 +1,3308 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$add_event = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.190476190476, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(18.192636718749995, 24.891542968750002), + Offset(18.175135177837678, 24.768938846121223), + Offset(18.131762833609578, 24.290016731469834), + Offset(18.189398131863207, 23.129814344209493), + Offset(19.14691116775322, 20.688226165351878), + Offset(22.277081692306755, 18.381965826572245), + Offset(25.153850173498547, 18.208885778660576), + Offset(26.987657743646544, 18.810016196193768), + Offset(28.229748817157525, 19.528141401396265), + Offset(29.223774647225785, 20.19509758103034), + Offset(30.007739613111152, 20.830494962200966), + Offset(30.626964119061235, 21.41670003990219), + Offset(31.072971936868854, 21.941254300113602), + Offset(31.381936148538408, 22.388826086603757), + Offset(31.595631995844528, 22.75496752966676), + Offset(31.74362009537025, 23.04237991891895), + Offset(31.845995957897536, 23.25665695166987), + Offset(31.916063614634442, 23.404284579714346), + Offset(31.962512649081546, 23.491750839098724), + Offset(31.99086595053382, 23.525019467195833), + Offset(32.00558109744533, 23.528032986218715), + Offset(32.01015625, 23.52890625), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.192636718749995, 24.891542968750002), + Offset(18.175135177837678, 24.768938846121223), + Offset(18.131762833609578, 24.290016731469834), + Offset(18.189398131863207, 23.129814344209493), + Offset(19.14691116775322, 20.688226165351878), + Offset(22.277081692306755, 18.381965826572245), + Offset(25.153850173498547, 18.208885778660576), + Offset(26.987657743646544, 18.810016196193768), + Offset(28.229748817157525, 19.528141401396265), + Offset(29.223774647225785, 20.19509758103034), + Offset(30.007739613111152, 20.830494962200966), + Offset(30.626964119061235, 21.41670003990219), + Offset(31.072971936868854, 21.941254300113602), + Offset(31.381936148538408, 22.388826086603757), + Offset(31.595631995844528, 22.75496752966676), + Offset(31.74362009537025, 23.04237991891895), + Offset(31.845995957897536, 23.25665695166987), + Offset(31.916063614634442, 23.404284579714346), + Offset(31.962512649081546, 23.491750839098724), + Offset(31.99086595053382, 23.525019467195833), + Offset(32.00558109744533, 23.528032986218715), + Offset(32.01015625, 23.52890625), + ], + <Offset>[ + Offset(23.992636718749996, 24.891542968750002), + Offset(23.97384664920713, 24.89118970218503), + Offset(23.901054413892187, 24.886065942257186), + Offset(23.728661104347875, 24.849281041083934), + Offset(23.386158286870817, 24.64660763547994), + Offset(23.116959480006564, 24.121768211366486), + Offset(23.169707830342585, 23.691656086157646), + Offset(23.322360298939, 23.45580690452118), + Offset(23.48231873652916, 23.34351072659664), + Offset(23.629082531765302, 23.319033616339574), + Offset(23.74394094991015, 23.337067196646014), + Offset(23.829253355825543, 23.374789989582887), + Offset(23.889084353557546, 23.411693680396755), + Offset(23.930803165274646, 23.442370323371723), + Offset(23.960074268764437, 23.466992025443258), + Offset(23.980512394929132, 23.486331772113996), + Offset(23.994442088149636, 23.50119509189468), + Offset(24.003391328945682, 23.512265882811025), + Offset(24.008386840165617, 23.520115789343254), + Offset(24.010119497846063, 23.52522637938814), + Offset(24.010150449065325, 23.528032986218715), + Offset(24.01015625, 23.52890625), + ], + <Offset>[ + Offset(23.992636718749996, 24.891542968750002), + Offset(23.97384664920713, 24.89118970218503), + Offset(23.901054413892187, 24.886065942257186), + Offset(23.728661104347875, 24.849281041083934), + Offset(23.386158286870817, 24.64660763547994), + Offset(23.116959480006564, 24.121768211366486), + Offset(23.169707830342585, 23.691656086157646), + Offset(23.322360298939, 23.45580690452118), + Offset(23.48231873652916, 23.34351072659664), + Offset(23.629082531765302, 23.319033616339574), + Offset(23.74394094991015, 23.337067196646014), + Offset(23.829253355825543, 23.374789989582887), + Offset(23.889084353557546, 23.411693680396755), + Offset(23.930803165274646, 23.442370323371723), + Offset(23.960074268764437, 23.466992025443258), + Offset(23.980512394929132, 23.486331772113996), + Offset(23.994442088149636, 23.50119509189468), + Offset(24.003391328945682, 23.512265882811025), + Offset(24.008386840165617, 23.520115789343254), + Offset(24.010119497846063, 23.52522637938814), + Offset(24.010150449065325, 23.528032986218715), + Offset(24.01015625, 23.52890625), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(23.992636718749996, 24.891542968750002), + Offset(23.97384664920713, 24.89118970218503), + Offset(23.901054413892187, 24.886065942257186), + Offset(23.728661104347875, 24.849281041083934), + Offset(23.386158286870817, 24.64660763547994), + Offset(23.116959480006564, 24.121768211366486), + Offset(23.169707830342585, 23.691656086157646), + Offset(23.322360298939, 23.45580690452118), + Offset(23.48231873652916, 23.34351072659664), + Offset(23.629082531765302, 23.319033616339574), + Offset(23.74394094991015, 23.337067196646014), + Offset(23.829253355825543, 23.374789989582887), + Offset(23.889084353557546, 23.411693680396755), + Offset(23.930803165274646, 23.442370323371723), + Offset(23.960074268764437, 23.466992025443258), + Offset(23.980512394929132, 23.486331772113996), + Offset(23.994442088149636, 23.50119509189468), + Offset(24.003391328945682, 23.512265882811025), + Offset(24.008386840165617, 23.520115789343254), + Offset(24.010119497846063, 23.52522637938814), + Offset(24.010150449065325, 23.528032986218715), + Offset(24.01015625, 23.52890625), + ], + <Offset>[ + Offset(23.992636718749996, 19.091542968750005), + Offset(24.096097505270937, 19.09247823081558), + Offset(24.497103624679536, 19.11677436197458), + Offset(25.448127801222316, 19.310018068599263), + Offset(27.344539756998877, 20.407360516362342), + Offset(28.85676186480081, 23.281890423666677), + Offset(28.652478137839655, 25.675798429313613), + Offset(27.968151007266407, 27.121104349228723), + Offset(27.29768806172953, 28.090940807225007), + Offset(26.753018567074538, 28.913725731800056), + Offset(26.250513184355196, 29.600865859847012), + Offset(25.78734330550624, 30.17250075281858), + Offset(25.359523733840703, 30.595581263708063), + Offset(24.984347402042612, 30.89350330663548), + Offset(24.672098764540934, 31.102549752523352), + Offset(24.424464248124174, 31.249439472555114), + Offset(24.238980228374444, 31.352748961642575), + Offset(24.11137263204236, 31.424938168499786), + Offset(24.036751790410147, 31.47424159825918), + Offset(24.010326410038374, 31.505972832075898), + Offset(24.010150449065325, 31.523463634598716), + Offset(24.01015625, 31.52890625), + ], + <Offset>[ + Offset(23.992636718749996, 19.091542968750005), + Offset(24.096097505270937, 19.09247823081558), + Offset(24.497103624679536, 19.11677436197458), + Offset(25.448127801222316, 19.310018068599263), + Offset(27.344539756998877, 20.407360516362342), + Offset(28.85676186480081, 23.281890423666677), + Offset(28.652478137839655, 25.675798429313613), + Offset(27.968151007266407, 27.121104349228723), + Offset(27.29768806172953, 28.090940807225007), + Offset(26.753018567074538, 28.913725731800056), + Offset(26.250513184355196, 29.600865859847012), + Offset(25.78734330550624, 30.17250075281858), + Offset(25.359523733840703, 30.595581263708063), + Offset(24.984347402042612, 30.89350330663548), + Offset(24.672098764540934, 31.102549752523352), + Offset(24.424464248124174, 31.249439472555114), + Offset(24.238980228374444, 31.352748961642575), + Offset(24.11137263204236, 31.424938168499786), + Offset(24.036751790410147, 31.47424159825918), + Offset(24.010326410038374, 31.505972832075898), + Offset(24.010150449065325, 31.523463634598716), + Offset(24.01015625, 31.52890625), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(23.992636718749996, 19.091542968750005), + Offset(24.096097505270937, 19.09247823081558), + Offset(24.497103624679536, 19.11677436197458), + Offset(25.448127801222316, 19.310018068599263), + Offset(27.344539756998877, 20.407360516362342), + Offset(28.85676186480081, 23.281890423666677), + Offset(28.652478137839655, 25.675798429313613), + Offset(27.968151007266407, 27.121104349228723), + Offset(27.29768806172953, 28.090940807225007), + Offset(26.753018567074538, 28.913725731800056), + Offset(26.250513184355196, 29.600865859847012), + Offset(25.78734330550624, 30.17250075281858), + Offset(25.359523733840703, 30.595581263708063), + Offset(24.984347402042612, 30.89350330663548), + Offset(24.672098764540934, 31.102549752523352), + Offset(24.424464248124174, 31.249439472555114), + Offset(24.238980228374444, 31.352748961642575), + Offset(24.11137263204236, 31.424938168499786), + Offset(24.036751790410147, 31.47424159825918), + Offset(24.010326410038374, 31.505972832075898), + Offset(24.010150449065325, 31.523463634598716), + Offset(24.01015625, 31.52890625), + ], + <Offset>[ + Offset(18.19263671875, 19.091542968750005), + Offset(18.297386033901486, 18.970227374751772), + Offset(18.72781204439693, 18.52072515118723), + Offset(19.90886482873765, 17.59055137172482), + Offset(23.10529263788128, 16.448979046234285), + Offset(28.016884077101, 17.542088038872436), + Offset(30.636620480995617, 20.19302812181654), + Offset(31.63344845197395, 22.475313640901312), + Offset(32.0451181423579, 24.275571482024635), + Offset(32.34771068253502, 25.78978969649082), + Offset(32.5143118475562, 27.094293625401967), + Offset(32.58505406874193, 28.21441080313788), + Offset(32.54341131715201, 29.12514188342491), + Offset(32.43548038530638, 29.83995906986752), + Offset(32.307656491621024, 30.39052525674685), + Offset(32.18757194856529, 30.80548761936007), + Offset(32.09053409812234, 31.10821082141777), + Offset(32.024044917731125, 31.316956865403107), + Offset(31.990877599326076, 31.44587664801465), + Offset(31.991072862726128, 31.505765919883586), + Offset(32.00558109744533, 31.523463634598716), + Offset(32.01015625, 31.52890625), + ], + <Offset>[ + Offset(18.19263671875, 19.091542968750005), + Offset(18.297386033901486, 18.970227374751772), + Offset(18.72781204439693, 18.52072515118723), + Offset(19.90886482873765, 17.59055137172482), + Offset(23.10529263788128, 16.448979046234285), + Offset(28.016884077101, 17.542088038872436), + Offset(30.636620480995617, 20.19302812181654), + Offset(31.63344845197395, 22.475313640901312), + Offset(32.0451181423579, 24.275571482024635), + Offset(32.34771068253502, 25.78978969649082), + Offset(32.5143118475562, 27.094293625401967), + Offset(32.58505406874193, 28.21441080313788), + Offset(32.54341131715201, 29.12514188342491), + Offset(32.43548038530638, 29.83995906986752), + Offset(32.307656491621024, 30.39052525674685), + Offset(32.18757194856529, 30.80548761936007), + Offset(32.09053409812234, 31.10821082141777), + Offset(32.024044917731125, 31.316956865403107), + Offset(31.990877599326076, 31.44587664801465), + Offset(31.991072862726128, 31.505765919883586), + Offset(32.00558109744533, 31.523463634598716), + Offset(32.01015625, 31.52890625), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.19263671875, 19.091542968750005), + Offset(18.297386033901486, 18.970227374751772), + Offset(18.72781204439693, 18.52072515118723), + Offset(19.90886482873765, 17.59055137172482), + Offset(23.10529263788128, 16.448979046234285), + Offset(28.016884077101, 17.542088038872436), + Offset(30.636620480995617, 20.19302812181654), + Offset(31.63344845197395, 22.475313640901312), + Offset(32.0451181423579, 24.275571482024635), + Offset(32.34771068253502, 25.78978969649082), + Offset(32.5143118475562, 27.094293625401967), + Offset(32.58505406874193, 28.21441080313788), + Offset(32.54341131715201, 29.12514188342491), + Offset(32.43548038530638, 29.83995906986752), + Offset(32.307656491621024, 30.39052525674685), + Offset(32.18757194856529, 30.80548761936007), + Offset(32.09053409812234, 31.10821082141777), + Offset(32.024044917731125, 31.316956865403107), + Offset(31.990877599326076, 31.44587664801465), + Offset(31.991072862726128, 31.505765919883586), + Offset(32.00558109744533, 31.523463634598716), + Offset(32.01015625, 31.52890625), + ], + <Offset>[ + Offset(18.192636718749995, 24.891542968750002), + Offset(18.175135177837678, 24.768938846121223), + Offset(18.131762833609578, 24.290016731469834), + Offset(18.189398131863207, 23.129814344209493), + Offset(19.14691116775322, 20.688226165351878), + Offset(22.277081692306755, 18.381965826572245), + Offset(25.153850173498547, 18.208885778660576), + Offset(26.987657743646544, 18.810016196193768), + Offset(28.229748817157525, 19.528141401396265), + Offset(29.223774647225785, 20.19509758103034), + Offset(30.007739613111152, 20.830494962200966), + Offset(30.626964119061235, 21.41670003990219), + Offset(31.072971936868854, 21.941254300113602), + Offset(31.381936148538408, 22.388826086603757), + Offset(31.595631995844528, 22.75496752966676), + Offset(31.74362009537025, 23.04237991891895), + Offset(31.845995957897536, 23.25665695166987), + Offset(31.916063614634442, 23.404284579714346), + Offset(31.962512649081546, 23.491750839098724), + Offset(31.99086595053382, 23.525019467195833), + Offset(32.00558109744533, 23.528032986218715), + Offset(32.01015625, 23.52890625), + ], + <Offset>[ + Offset(18.192636718749995, 24.891542968750002), + Offset(18.175135177837678, 24.768938846121223), + Offset(18.131762833609578, 24.290016731469834), + Offset(18.189398131863207, 23.129814344209493), + Offset(19.14691116775322, 20.688226165351878), + Offset(22.277081692306755, 18.381965826572245), + Offset(25.153850173498547, 18.208885778660576), + Offset(26.987657743646544, 18.810016196193768), + Offset(28.229748817157525, 19.528141401396265), + Offset(29.223774647225785, 20.19509758103034), + Offset(30.007739613111152, 20.830494962200966), + Offset(30.626964119061235, 21.41670003990219), + Offset(31.072971936868854, 21.941254300113602), + Offset(31.381936148538408, 22.388826086603757), + Offset(31.595631995844528, 22.75496752966676), + Offset(31.74362009537025, 23.04237991891895), + Offset(31.845995957897536, 23.25665695166987), + Offset(31.916063614634442, 23.404284579714346), + Offset(31.962512649081546, 23.491750839098724), + Offset(31.99086595053382, 23.525019467195833), + Offset(32.00558109744533, 23.528032986218715), + Offset(32.01015625, 23.52890625), + ], + ), + _PathClose( + ), + _PathMoveTo( + <Offset>[ + Offset(19.359999999999996, 37.6), + Offset(19.07437364316861, 37.499177937670424), + Offset(17.986934103582882, 37.051154681687954), + Offset(15.536736677617021, 35.61304326763691), + Offset(11.326880236819443, 30.7735984135526), + Offset(9.869566263871294, 21.377480537283333), + Offset(12.74113193535829, 14.964919748422403), + Offset(16.0704913221344, 11.713990403514046), + Offset(18.914329388866914, 9.893901895554396), + Offset(21.25283585091745, 8.565246523821894), + Offset(23.25484407901928, 7.610299138856277), + Offset(24.968395165544187, 6.916249550797959), + Offset(26.405174995011652, 6.49649745011436), + Offset(27.573815336148815, 6.274596001300022), + Offset(28.49870054201158, 6.167904420613963), + Offset(29.208394245687987, 6.121885514098405), + Offset(29.729906624130507, 6.1022310660712105), + Offset(30.08688450541718, 6.08845659062094), + Offset(30.299438656814726, 6.069069138689281), + Offset(30.384131484923635, 6.038341565542824), + Offset(30.396344518703998, 6.009138703240001), + Offset(30.4, 6.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(19.359999999999996, 37.6), + Offset(19.07437364316861, 37.499177937670424), + Offset(17.986934103582882, 37.051154681687954), + Offset(15.536736677617021, 35.61304326763691), + Offset(11.326880236819443, 30.7735984135526), + Offset(9.869566263871294, 21.377480537283333), + Offset(12.74113193535829, 14.964919748422403), + Offset(16.0704913221344, 11.713990403514046), + Offset(18.914329388866914, 9.893901895554396), + Offset(21.25283585091745, 8.565246523821894), + Offset(23.25484407901928, 7.610299138856277), + Offset(24.968395165544187, 6.916249550797959), + Offset(26.405174995011652, 6.49649745011436), + Offset(27.573815336148815, 6.274596001300022), + Offset(28.49870054201158, 6.167904420613963), + Offset(29.208394245687987, 6.121885514098405), + Offset(29.729906624130507, 6.1022310660712105), + Offset(30.08688450541718, 6.08845659062094), + Offset(30.299438656814726, 6.069069138689281), + Offset(30.384131484923635, 6.038341565542824), + Offset(30.396344518703998, 6.009138703240001), + Offset(30.4, 6.0), + ], + <Offset>[ + Offset(19.359999999999996, 35.28), + Offset(19.123273985594132, 35.179693349122644), + Offset(18.225353787897824, 34.74343804957491), + Offset(16.224523356366795, 33.397338078643045), + Offset(12.910232824870667, 29.077899565905565), + Offset(12.165487217788991, 21.04152942220341), + Offset(14.934240058357119, 15.758576685684787), + Offset(17.928807605465366, 13.180109381397063), + Offset(20.440477118947065, 11.792873927805745), + Offset(22.502410265041142, 10.803123370006087), + Offset(24.2574729727973, 10.115818604136678), + Offset(25.751631145416468, 9.635333856092236), + Offset(26.993350747124914, 9.370052483438883), + Offset(27.995233030856, 9.255049194605526), + Offset(28.78351034032218, 9.222127511445999), + Offset(29.385974986966005, 9.227128594274852), + Offset(29.82772188022043, 9.24285261397037), + Offset(30.130077026655854, 9.253525504896444), + Offset(30.310784636912537, 9.250719462255653), + Offset(30.384214249800557, 9.230640146617926), + Offset(30.396344518703998, 9.207310962592), + Offset(30.4, 9.2), + ], + <Offset>[ + Offset(19.359999999999996, 35.28), + Offset(19.123273985594132, 35.179693349122644), + Offset(18.225353787897824, 34.74343804957491), + Offset(16.224523356366795, 33.397338078643045), + Offset(12.910232824870667, 29.077899565905565), + Offset(12.165487217788991, 21.04152942220341), + Offset(14.934240058357119, 15.758576685684787), + Offset(17.928807605465366, 13.180109381397063), + Offset(20.440477118947065, 11.792873927805745), + Offset(22.502410265041142, 10.803123370006087), + Offset(24.2574729727973, 10.115818604136678), + Offset(25.751631145416468, 9.635333856092236), + Offset(26.993350747124914, 9.370052483438883), + Offset(27.995233030856, 9.255049194605526), + Offset(28.78351034032218, 9.222127511445999), + Offset(29.385974986966005, 9.227128594274852), + Offset(29.82772188022043, 9.24285261397037), + Offset(30.130077026655854, 9.253525504896444), + Offset(30.310784636912537, 9.250719462255653), + Offset(30.384214249800557, 9.230640146617926), + Offset(30.396344518703998, 9.207310962592), + Offset(30.4, 9.2), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(19.359999999999996, 35.28), + Offset(19.123273985594132, 35.179693349122644), + Offset(18.225353787897824, 34.74343804957491), + Offset(16.224523356366795, 33.397338078643045), + Offset(12.910232824870667, 29.077899565905565), + Offset(12.165487217788991, 21.04152942220341), + Offset(14.934240058357119, 15.758576685684787), + Offset(17.928807605465366, 13.180109381397063), + Offset(20.440477118947065, 11.792873927805745), + Offset(22.502410265041142, 10.803123370006087), + Offset(24.2574729727973, 10.115818604136678), + Offset(25.751631145416468, 9.635333856092236), + Offset(26.993350747124914, 9.370052483438883), + Offset(27.995233030856, 9.255049194605526), + Offset(28.78351034032218, 9.222127511445999), + Offset(29.385974986966005, 9.227128594274852), + Offset(29.82772188022043, 9.24285261397037), + Offset(30.130077026655854, 9.253525504896444), + Offset(30.310784636912537, 9.250719462255653), + Offset(30.384214249800557, 9.230640146617926), + Offset(30.396344518703998, 9.207310962592), + Offset(30.4, 9.2), + ], + <Offset>[ + Offset(28.639999999999993, 35.28), + Offset(28.401212339785253, 35.37529471882475), + Offset(27.45622031634999, 35.69711678683468), + Offset(25.08734411234227, 36.14848479364215), + Offset(19.693028215458817, 35.41130991811046), + Offset(13.509291678108683, 30.2252132378742), + Offset(11.759612309307578, 24.5310091776801), + Offset(12.064331693933298, 20.613374514720917), + Offset(12.844588989941675, 17.897464848126344), + Offset(13.550902880304374, 15.801421026500861), + Offset(14.235395111675697, 14.126334179248751), + Offset(14.875293924239358, 12.768277775581351), + Offset(15.499130613826821, 11.722755491891931), + Offset(16.07342025763398, 10.94071997343427), + Offset(16.566617976994035, 10.361366704688399), + Offset(16.965002666260215, 9.937451559386922), + Offset(17.26523568862379, 9.63411363833006), + Offset(17.469801369553835, 9.426295589851133), + Offset(17.584183342647055, 9.296103382646901), + Offset(17.61501992550015, 9.23097120612562), + Offset(17.603655481296002, 9.207310962592), + Offset(17.6, 9.2), + ], + <Offset>[ + Offset(28.639999999999993, 35.28), + Offset(28.401212339785253, 35.37529471882475), + Offset(27.45622031634999, 35.69711678683468), + Offset(25.08734411234227, 36.14848479364215), + Offset(19.693028215458817, 35.41130991811046), + Offset(13.509291678108683, 30.2252132378742), + Offset(11.759612309307578, 24.5310091776801), + Offset(12.064331693933298, 20.613374514720917), + Offset(12.844588989941675, 17.897464848126344), + Offset(13.550902880304374, 15.801421026500861), + Offset(14.235395111675697, 14.126334179248751), + Offset(14.875293924239358, 12.768277775581351), + Offset(15.499130613826821, 11.722755491891931), + Offset(16.07342025763398, 10.94071997343427), + Offset(16.566617976994035, 10.361366704688399), + Offset(16.965002666260215, 9.937451559386922), + Offset(17.26523568862379, 9.63411363833006), + Offset(17.469801369553835, 9.426295589851133), + Offset(17.584183342647055, 9.296103382646901), + Offset(17.61501992550015, 9.23097120612562), + Offset(17.603655481296002, 9.207310962592), + Offset(17.6, 9.2), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(28.639999999999993, 35.28), + Offset(28.401212339785253, 35.37529471882475), + Offset(27.45622031634999, 35.69711678683468), + Offset(25.08734411234227, 36.14848479364215), + Offset(19.693028215458817, 35.41130991811046), + Offset(13.509291678108683, 30.2252132378742), + Offset(11.759612309307578, 24.5310091776801), + Offset(12.064331693933298, 20.613374514720917), + Offset(12.844588989941675, 17.897464848126344), + Offset(13.550902880304374, 15.801421026500861), + Offset(14.235395111675697, 14.126334179248751), + Offset(14.875293924239358, 12.768277775581351), + Offset(15.499130613826821, 11.722755491891931), + Offset(16.07342025763398, 10.94071997343427), + Offset(16.566617976994035, 10.361366704688399), + Offset(16.965002666260215, 9.937451559386922), + Offset(17.26523568862379, 9.63411363833006), + Offset(17.469801369553835, 9.426295589851133), + Offset(17.584183342647055, 9.296103382646901), + Offset(17.61501992550015, 9.23097120612562), + Offset(17.603655481296002, 9.207310962592), + Offset(17.6, 9.2), + ], + <Offset>[ + Offset(28.639999999999993, 37.6), + Offset(28.35231199735973, 37.69477930737253), + Offset(27.21780063203505, 38.00483341894772), + Offset(24.39955743359249, 38.36418998263601), + Offset(18.109675627407594, 37.1070087657575), + Offset(11.213370724190986, 30.561164352954123), + Offset(9.566504186308748, 23.737352240417717), + Offset(10.206015410602333, 19.1472555368379), + Offset(11.318441259861526, 15.998492815874997), + Offset(12.301328466180678, 13.563544180316669), + Offset(13.232766217897677, 11.62081471396835), + Offset(14.092057944367081, 10.049193470287074), + Offset(14.91095486171356, 8.849200458567408), + Offset(15.652002562926794, 7.960266780128766), + Offset(16.281808178683434, 7.307143613856363), + Offset(16.787421924982198, 6.832208479210475), + Offset(17.167420432533866, 6.4934920904309), + Offset(17.426608848315166, 6.261226675575628), + Offset(17.572837362549244, 6.11445305908053), + Offset(17.614937160623228, 6.038672625050518), + Offset(17.603655481296002, 6.009138703240001), + Offset(17.6, 6.0), + ], + <Offset>[ + Offset(28.639999999999993, 37.6), + Offset(28.35231199735973, 37.69477930737253), + Offset(27.21780063203505, 38.00483341894772), + Offset(24.39955743359249, 38.36418998263601), + Offset(18.109675627407594, 37.1070087657575), + Offset(11.213370724190986, 30.561164352954123), + Offset(9.566504186308748, 23.737352240417717), + Offset(10.206015410602333, 19.1472555368379), + Offset(11.318441259861526, 15.998492815874997), + Offset(12.301328466180678, 13.563544180316669), + Offset(13.232766217897677, 11.62081471396835), + Offset(14.092057944367081, 10.049193470287074), + Offset(14.91095486171356, 8.849200458567408), + Offset(15.652002562926794, 7.960266780128766), + Offset(16.281808178683434, 7.307143613856363), + Offset(16.787421924982198, 6.832208479210475), + Offset(17.167420432533866, 6.4934920904309), + Offset(17.426608848315166, 6.261226675575628), + Offset(17.572837362549244, 6.11445305908053), + Offset(17.614937160623228, 6.038672625050518), + Offset(17.603655481296002, 6.009138703240001), + Offset(17.6, 6.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(28.639999999999993, 37.6), + Offset(28.35231199735973, 37.69477930737253), + Offset(27.21780063203505, 38.00483341894772), + Offset(24.39955743359249, 38.36418998263601), + Offset(18.109675627407594, 37.1070087657575), + Offset(11.213370724190986, 30.561164352954123), + Offset(9.566504186308748, 23.737352240417717), + Offset(10.206015410602333, 19.1472555368379), + Offset(11.318441259861526, 15.998492815874997), + Offset(12.301328466180678, 13.563544180316669), + Offset(13.232766217897677, 11.62081471396835), + Offset(14.092057944367081, 10.049193470287074), + Offset(14.91095486171356, 8.849200458567408), + Offset(15.652002562926794, 7.960266780128766), + Offset(16.281808178683434, 7.307143613856363), + Offset(16.787421924982198, 6.832208479210475), + Offset(17.167420432533866, 6.4934920904309), + Offset(17.426608848315166, 6.261226675575628), + Offset(17.572837362549244, 6.11445305908053), + Offset(17.614937160623228, 6.038672625050518), + Offset(17.603655481296002, 6.009138703240001), + Offset(17.6, 6.0), + ], + <Offset>[ + Offset(30.959999999999994, 37.6), + Offset(30.67179658590751, 37.74367964979805), + Offset(29.525517264148096, 38.24325310326266), + Offset(26.61526262258636, 39.051976661385794), + Offset(19.80537447505463, 38.69036135380872), + Offset(11.54932183927091, 32.857085306871824), + Offset(8.772847249046361, 25.930460363416543), + Offset(8.739896432719314, 21.005571820168864), + Offset(9.419469227610179, 17.524640545955144), + Offset(10.063451619996487, 14.813118594440363), + Offset(10.727246752617276, 12.62344360774637), + Offset(11.372973639072804, 10.832429450159353), + Offset(12.037399828389036, 9.43737621068067), + Offset(12.671549369621289, 8.381684474835954), + Offset(13.227585087851399, 7.591953412166962), + Offset(13.68217884480575, 7.009789220488495), + Offset(14.026798884634708, 6.591307346520823), + Offset(14.26153993403966, 6.304419196814299), + Offset(14.391187038982872, 6.125799039178341), + Offset(14.422638579548124, 6.0387553899274415), + Offset(14.405483221944, 6.009138703240001), + Offset(14.399999999999999, 6.0), + ], + <Offset>[ + Offset(30.959999999999994, 37.6), + Offset(30.67179658590751, 37.74367964979805), + Offset(29.525517264148096, 38.24325310326266), + Offset(26.61526262258636, 39.051976661385794), + Offset(19.80537447505463, 38.69036135380872), + Offset(11.54932183927091, 32.857085306871824), + Offset(8.772847249046361, 25.930460363416543), + Offset(8.739896432719314, 21.005571820168864), + Offset(9.419469227610179, 17.524640545955144), + Offset(10.063451619996487, 14.813118594440363), + Offset(10.727246752617276, 12.62344360774637), + Offset(11.372973639072804, 10.832429450159353), + Offset(12.037399828389036, 9.43737621068067), + Offset(12.671549369621289, 8.381684474835954), + Offset(13.227585087851399, 7.591953412166962), + Offset(13.68217884480575, 7.009789220488495), + Offset(14.026798884634708, 6.591307346520823), + Offset(14.26153993403966, 6.304419196814299), + Offset(14.391187038982872, 6.125799039178341), + Offset(14.422638579548124, 6.0387553899274415), + Offset(14.405483221944, 6.009138703240001), + Offset(14.399999999999999, 6.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(30.959999999999994, 37.6), + Offset(30.67179658590751, 37.74367964979805), + Offset(29.525517264148096, 38.24325310326266), + Offset(26.61526262258636, 39.051976661385794), + Offset(19.80537447505463, 38.69036135380872), + Offset(11.54932183927091, 32.857085306871824), + Offset(8.772847249046361, 25.930460363416543), + Offset(8.739896432719314, 21.005571820168864), + Offset(9.419469227610179, 17.524640545955144), + Offset(10.063451619996487, 14.813118594440363), + Offset(10.727246752617276, 12.62344360774637), + Offset(11.372973639072804, 10.832429450159353), + Offset(12.037399828389036, 9.43737621068067), + Offset(12.671549369621289, 8.381684474835954), + Offset(13.227585087851399, 7.591953412166962), + Offset(13.68217884480575, 7.009789220488495), + Offset(14.026798884634708, 6.591307346520823), + Offset(14.26153993403966, 6.304419196814299), + Offset(14.391187038982872, 6.125799039178341), + Offset(14.422638579548124, 6.0387553899274415), + Offset(14.405483221944, 6.009138703240001), + Offset(14.399999999999999, 6.0), + ], + <Offset>[ + Offset(30.959999999999994, 35.28), + Offset(30.720696928333034, 35.424195061250266), + Offset(29.763936948463037, 35.93553647114962), + Offset(27.303049301336138, 36.83627147239193), + Offset(21.388727063105854, 36.99466250616168), + Offset(13.845242793188607, 32.521134191791894), + Offset(10.96595537204519, 26.72411730067893), + Offset(10.598212716050279, 22.47169079805188), + Offset(10.945616957690326, 19.423612578206495), + Offset(11.313026034120181, 17.050995440624554), + Offset(11.729875646395296, 15.128963073026771), + Offset(12.156209618945082, 13.55151375545363), + Offset(12.625575580502298, 12.310931244005193), + Offset(13.092967064328475, 11.362137668141457), + Offset(13.512394886161998, 10.646176502998998), + Offset(13.859759586083767, 10.115032300664941), + Offset(14.124614140724631, 9.731928894419983), + Offset(14.304732455278332, 9.469488111089804), + Offset(14.402533019080684, 9.307449362744713), + Offset(14.422721344425048, 9.231053971002543), + Offset(14.405483221944, 9.207310962592), + Offset(14.399999999999999, 9.2), + ], + <Offset>[ + Offset(30.959999999999994, 35.28), + Offset(30.720696928333034, 35.424195061250266), + Offset(29.763936948463037, 35.93553647114962), + Offset(27.303049301336138, 36.83627147239193), + Offset(21.388727063105854, 36.99466250616168), + Offset(13.845242793188607, 32.521134191791894), + Offset(10.96595537204519, 26.72411730067893), + Offset(10.598212716050279, 22.47169079805188), + Offset(10.945616957690326, 19.423612578206495), + Offset(11.313026034120181, 17.050995440624554), + Offset(11.729875646395296, 15.128963073026771), + Offset(12.156209618945082, 13.55151375545363), + Offset(12.625575580502298, 12.310931244005193), + Offset(13.092967064328475, 11.362137668141457), + Offset(13.512394886161998, 10.646176502998998), + Offset(13.859759586083767, 10.115032300664941), + Offset(14.124614140724631, 9.731928894419983), + Offset(14.304732455278332, 9.469488111089804), + Offset(14.402533019080684, 9.307449362744713), + Offset(14.422721344425048, 9.231053971002543), + Offset(14.405483221944, 9.207310962592), + Offset(14.399999999999999, 9.2), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(30.959999999999994, 35.28), + Offset(30.720696928333034, 35.424195061250266), + Offset(29.763936948463037, 35.93553647114962), + Offset(27.303049301336138, 36.83627147239193), + Offset(21.388727063105854, 36.99466250616168), + Offset(13.845242793188607, 32.521134191791894), + Offset(10.96595537204519, 26.72411730067893), + Offset(10.598212716050279, 22.47169079805188), + Offset(10.945616957690326, 19.423612578206495), + Offset(11.313026034120181, 17.050995440624554), + Offset(11.729875646395296, 15.128963073026771), + Offset(12.156209618945082, 13.55151375545363), + Offset(12.625575580502298, 12.310931244005193), + Offset(13.092967064328475, 11.362137668141457), + Offset(13.512394886161998, 10.646176502998998), + Offset(13.859759586083767, 10.115032300664941), + Offset(14.124614140724631, 9.731928894419983), + Offset(14.304732455278332, 9.469488111089804), + Offset(14.402533019080684, 9.307449362744713), + Offset(14.422721344425048, 9.231053971002543), + Offset(14.405483221944, 9.207310962592), + Offset(14.399999999999999, 9.2), + ], + <Offset>[ + Offset(32.11999999999999, 35.28), + Offset(31.880439222606924, 35.44864523246303), + Offset(30.917795264519558, 36.05474631330709), + Offset(28.41090189583307, 37.180164811766815), + Offset(22.236576486929373, 37.786338800187295), + Offset(14.013218350728568, 33.669094668750745), + Offset(10.569126903413999, 27.820671362178345), + Offset(9.86515322710877, 23.400848939717363), + Offset(9.996130941564655, 20.18668644324657), + Offset(10.194087611028085, 17.675782647686404), + Offset(10.477115913755096, 15.63027751991578), + Offset(10.796667466297944, 13.94313174538977), + Offset(11.188798063840036, 12.605019120061824), + Offset(11.602740467675723, 11.57284651549505), + Offset(11.98528334074598, 10.788581402154296), + Offset(12.307138045995544, 10.20382267130395), + Offset(12.55430336677505, 9.780836522464943), + Offset(12.72219799814058, 9.49108437170914), + Offset(12.811707857297497, 9.313122352793618), + Offset(12.826572053887496, 9.231095353441006), + Offset(12.806397092268, 9.207310962592), + Offset(12.799999999999999, 9.2), + ], + <Offset>[ + Offset(32.11999999999999, 35.28), + Offset(31.880439222606924, 35.44864523246303), + Offset(30.917795264519558, 36.05474631330709), + Offset(28.41090189583307, 37.180164811766815), + Offset(22.236576486929373, 37.786338800187295), + Offset(14.013218350728568, 33.669094668750745), + Offset(10.569126903413999, 27.820671362178345), + Offset(9.86515322710877, 23.400848939717363), + Offset(9.996130941564655, 20.18668644324657), + Offset(10.194087611028085, 17.675782647686404), + Offset(10.477115913755096, 15.63027751991578), + Offset(10.796667466297944, 13.94313174538977), + Offset(11.188798063840036, 12.605019120061824), + Offset(11.602740467675723, 11.57284651549505), + Offset(11.98528334074598, 10.788581402154296), + Offset(12.307138045995544, 10.20382267130395), + Offset(12.55430336677505, 9.780836522464943), + Offset(12.72219799814058, 9.49108437170914), + Offset(12.811707857297497, 9.313122352793618), + Offset(12.826572053887496, 9.231095353441006), + Offset(12.806397092268, 9.207310962592), + Offset(12.799999999999999, 9.2), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(33.40180389404459, 35.28), + Offset(33.161958350959075, 35.47566275373077), + Offset(32.19281257718938, 36.186473589070786), + Offset(29.635082731741335, 37.56016810620365), + Offset(23.17345294642977, 38.66114376269145), + Offset(14.198831905693254, 34.93759484941898), + Offset(10.130630113449154, 29.032367281195906), + Offset(9.055120030995347, 24.427571805381206), + Offset(8.946945706382945, 21.029885625705216), + Offset(8.957656897307762, 18.366174608859787), + Offset(9.09281220375468, 16.18423166660815), + Offset(9.294368823728218, 14.37587093890534), + Offset(9.601154084759504, 12.929987210338286), + Offset(9.95603507578061, 11.805680499156674), + Offset(10.297819956647084, 10.945939293764894), + Offset(10.591486032148467, 10.301936328923558), + Offset(10.819104690129567, 9.834879615634355), + Offset(10.973492110538054, 9.51494831219075), + Offset(11.053840713230413, 9.319391025841519), + Offset(11.062821729674083, 9.231141081174425), + Offset(11.039401550947822, 9.207310962592), + Offset(11.031994628903998, 9.2), + ], + <Offset>[ + Offset(34.428397521973196, 34.24180389404461), + Offset(34.21020673189347, 34.4593355607496), + Offset(33.32066325711653, 35.25927432509759), + Offset(30.923309576566957, 36.87298746940196), + Offset(24.632342654683864, 38.60295054594897), + Offset(15.374910124648133, 35.80319600547601), + Offset(10.760851302536071, 30.35797174936804), + Offset(9.23795982776596, 25.90595743850577), + Offset(8.789604345416578, 22.554988601644673), + Offset(8.52658499233495, 19.920553987514175), + Offset(8.43280146906967, 17.749107953581934), + Offset(8.441678273181578, 15.93923637150114), + Offset(8.59282153680617, 14.476164419419169), + Offset(8.82577643484907, 13.325904473016532), + Offset(9.073786534329603, 12.438726553996867), + Offset(9.296891581635101, 11.770106385528296), + Offset(9.473160444080882, 11.283585469050152), + Offset(9.592286389851099, 10.950423910880021), + Offset(9.651046490767305, 10.748194770371416), + Offset(9.650275412603275, 10.659725961266831), + Offset(9.624219110228523, 10.638487680623824), + Offset(9.616003417967999, 10.631994628904), + ], + <Offset>[ + Offset(34.428397521973196, 32.96), + Offset(34.23722425316121, 33.17781643239746), + Offset(33.45239053288022, 33.984257012427776), + Offset(31.303312871003797, 35.648806633493706), + Offset(25.507147617188025, 37.666074086448575), + Offset(16.643410305316365, 35.61758245051132), + Offset(11.972547221553633, 30.79646853933288), + Offset(10.264682693429805, 26.71599063461919), + Offset(9.632803527875225, 23.60417383682638), + Offset(9.216976953508334, 21.156984701234496), + Offset(8.98675561576204, 19.133411663582347), + Offset(8.87441746669715, 17.441535014070865), + Offset(8.917789627082632, 16.063808398499702), + Offset(9.058610418510696, 14.972609864911643), + Offset(9.2311444259402, 14.126189938095761), + Offset(9.395005239254708, 13.48575839937537), + Offset(9.527203537250292, 13.018784145695633), + Offset(9.616150330332708, 12.699129798482545), + Offset(9.657315163815205, 12.5060619144385), + Offset(9.650321140336693, 12.423476285480243), + Offset(9.624219110228523, 12.405483221944), + Offset(9.616003417967999, 12.399999999999999), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(34.428397521973196, 32.96), + Offset(34.23722425316121, 33.17781643239746), + Offset(33.45239053288022, 33.984257012427776), + Offset(31.303312871003797, 35.648806633493706), + Offset(25.507147617188025, 37.666074086448575), + Offset(16.643410305316365, 35.61758245051132), + Offset(11.972547221553633, 30.79646853933288), + Offset(10.264682693429805, 26.71599063461919), + Offset(9.632803527875225, 23.60417383682638), + Offset(9.216976953508334, 21.156984701234496), + Offset(8.98675561576204, 19.133411663582347), + Offset(8.87441746669715, 17.441535014070865), + Offset(8.917789627082632, 16.063808398499702), + Offset(9.058610418510696, 14.972609864911643), + Offset(9.2311444259402, 14.126189938095761), + Offset(9.395005239254708, 13.48575839937537), + Offset(9.527203537250292, 13.018784145695633), + Offset(9.616150330332708, 12.699129798482545), + Offset(9.657315163815205, 12.5060619144385), + Offset(9.650321140336693, 12.423476285480243), + Offset(9.624219110228523, 12.405483221944), + Offset(9.616003417967999, 12.399999999999999), + ], + <Offset>[ + Offset(34.440000000000516, 16.720000000000006), + Offset(34.591126550559416, 16.94166886650632), + Offset(35.132869371152644, 17.831432940717747), + Offset(36.128900514825645, 20.142309978565798), + Offset(36.59909603898658, 25.80410060706257), + Offset(32.71653709715015, 33.277406702029566), + Offset(27.320334950142062, 36.36303498327675), + Offset(23.26556451587313, 36.98811704611288), + Offset(20.306340749954074, 36.90461043133784), + Offset(17.95280607783294, 36.82837183128392), + Offset(15.99262759869828, 36.67706213593723), + Offset(14.343470999981285, 36.47904216761644), + Offset(13.020649047420964, 36.181635138771405), + Offset(11.99362883202704, 35.83788975664637), + Offset(11.209538636398053, 35.50717592712125), + Offset(10.622540896042542, 35.22334805399359), + Offset(10.196203867594564, 35.003624161748164), + Offset(9.902669253773741, 34.854828207151854), + Offset(9.720825374512906, 34.7776709214224), + Offset(9.634935591827066, 34.76956676691874), + Offset(9.608224832915282, 34.792689037407996), + Offset(9.59999999999928, 34.8), + ], + <Offset>[ + Offset(34.440000000000516, 16.720000000000006), + Offset(34.591126550559416, 16.94166886650632), + Offset(35.132869371152644, 17.831432940717747), + Offset(36.128900514825645, 20.142309978565798), + Offset(36.59909603898658, 25.80410060706257), + Offset(32.71653709715015, 33.277406702029566), + Offset(27.320334950142062, 36.36303498327675), + Offset(23.26556451587313, 36.98811704611288), + Offset(20.306340749954074, 36.90461043133784), + Offset(17.95280607783294, 36.82837183128392), + Offset(15.99262759869828, 36.67706213593723), + Offset(14.343470999981285, 36.47904216761644), + Offset(13.020649047420964, 36.181635138771405), + Offset(11.99362883202704, 35.83788975664637), + Offset(11.209538636398053, 35.50717592712125), + Offset(10.622540896042542, 35.22334805399359), + Offset(10.196203867594564, 35.003624161748164), + Offset(9.902669253773741, 34.854828207151854), + Offset(9.720825374512906, 34.7776709214224), + Offset(9.634935591827066, 34.76956676691874), + Offset(9.608224832915282, 34.792689037407996), + Offset(9.59999999999928, 34.8), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(34.440000000000516, 15.438196105955406), + Offset(34.61814407182715, 15.660149738154173), + Offset(35.264596646916345, 16.556415628047922), + Offset(36.50890380926249, 18.918129142657538), + Offset(37.473901001490745, 24.867224147562176), + Offset(33.98503727781838, 33.091793147064884), + Offset(28.532030869159623, 36.80153177324159), + Offset(24.292287381536976, 37.798150242226306), + Offset(21.149539932412726, 37.95379566651955), + Offset(18.643198039006325, 38.06480254500424), + Offset(16.546581745390647, 38.061365845937644), + Offset(14.776210193496857, 37.98134081018617), + Offset(13.345617137697426, 37.76927911785194), + Offset(12.226462815688665, 37.48459514854148), + Offset(11.366896528008649, 37.19463931122015), + Offset(10.72065455366215, 36.93900006784067), + Offset(10.250246960763974, 36.73882283839365), + Offset(9.92653319425535, 36.60353409475438), + Offset(9.727094047560806, 36.53553806548948), + Offset(9.634981319560485, 36.53331709113216), + Offset(9.608224832915282, 36.55968457872818), + Offset(9.59999999999928, 36.568005371096), + ], + <Offset>[ + Offset(33.401803894045116, 14.400000000000006), + Offset(33.602061432789306, 14.600301456800754), + Offset(34.33858973602437, 15.417023900053458), + Offset(35.825162840489824, 17.618821405258995), + Offset(37.42362623889116, 23.39985413386847), + Offset(34.862120490952606, 31.914034813700184), + Offset(29.868603220438434, 36.17527971655787), + Offset(25.77996658097369, 37.62264260632878), + Offset(22.682275277103862, 38.12063391596769), + Offset(20.203826624420508, 38.5070662245178), + Offset(18.116472247756285, 38.73390685413197), + Offset(16.343492642578116, 38.847629686554015), + Offset(14.894735853778217, 38.79198251025913), + Offset(13.748794328144617, 38.62975923890631), + Offset(12.861108141441791, 38.43394711125329), + Offset(12.18971270364993, 38.249124050511625), + Offset(11.699441994938162, 38.10047354672682), + Offset(11.362224801685391, 38.0005685406703), + Offset(11.155954534110002, 37.954243937938855), + Offset(11.063566613565678, 37.96182831085034), + Offset(11.039401550947105, 37.99086129676), + Offset(11.031994628903279, 38.0), + ], + <Offset>[ + Offset(32.120000000000516, 14.400000000000006), + Offset(32.32054230443716, 14.573283935533016), + Offset(33.06357242335454, 15.285296624289762), + Offset(34.60098200458155, 17.238818110822155), + Offset(36.48674977939076, 22.52504917136431), + Offset(34.67650693598792, 30.64553463303195), + Offset(30.30710001040328, 34.96358379754031), + Offset(26.58999977708711, 36.59591974066494), + Offset(23.731460512285572, 37.27743473350904), + Offset(21.440257338140828, 37.81667426334442), + Offset(19.500775957756698, 38.17995270743961), + Offset(17.84579128514784, 38.41489049303844), + Offset(16.482379832858747, 38.46701441998266), + Offset(15.39549972003973, 38.39692525524468), + Offset(14.548571525540689, 38.27658921964269), + Offset(13.905364717497006, 38.15101039289202), + Offset(13.434640671583647, 38.046430453557406), + Offset(13.110930689287915, 37.97670460018869), + Offset(12.913821678177088, 37.94797526489096), + Offset(12.827316937779091, 37.96178258311692), + Offset(12.806397092267282, 37.99086129676), + Offset(12.79999999999928, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(32.120000000000516, 14.400000000000006), + Offset(32.32054230443716, 14.573283935533016), + Offset(33.06357242335454, 15.285296624289762), + Offset(34.60098200458155, 17.238818110822155), + Offset(36.48674977939076, 22.52504917136431), + Offset(34.67650693598792, 30.64553463303195), + Offset(30.30710001040328, 34.96358379754031), + Offset(26.58999977708711, 36.59591974066494), + Offset(23.731460512285572, 37.27743473350904), + Offset(21.440257338140828, 37.81667426334442), + Offset(19.500775957756698, 38.17995270743961), + Offset(17.84579128514784, 38.41489049303844), + Offset(16.482379832858747, 38.46701441998266), + Offset(15.39549972003973, 38.39692525524468), + Offset(14.548571525540689, 38.27658921964269), + Offset(13.905364717497006, 38.15101039289202), + Offset(13.434640671583647, 38.046430453557406), + Offset(13.110930689287915, 37.97670460018869), + Offset(12.913821678177088, 37.94797526489096), + Offset(12.827316937779091, 37.96178258311692), + Offset(12.806397092267282, 37.99086129676), + Offset(12.79999999999928, 38.0), + ], + <Offset>[ + Offset(15.88000000000052, 14.400000000000002), + Offset(16.0841501846027, 14.23098153855435), + Offset(16.909555998563246, 13.616358834085176), + Offset(19.091045681624482, 12.424311359573721), + Offset(24.616857845861503, 11.441581055005743), + Offset(32.32484913042846, 14.574087955608066), + Offset(35.862698571239974, 19.611826936548507), + Offset(36.85283262226824, 23.587705757348193), + Offset(37.024264738045005, 26.59440062294799), + Offset(37.105395261430175, 29.069653364478558), + Offset(37.039412214719505, 31.16155045099348), + Offset(36.87938142220778, 32.932238633932485), + Offset(36.59726506613041, 34.34978415518983), + Offset(36.25867207317826, 35.44700139229438), + Offset(35.92813316136494, 36.28292063146849), + Offset(35.64206627873214, 36.90794520394589), + Offset(35.41899150687777, 37.36172366092795), + Offset(35.26641308921645, 37.674356951517986), + Offset(35.185373943141684, 37.868553404206274), + Offset(35.1734070053048, 37.961203228978455), + Offset(35.19360290773128, 37.99086129676), + Offset(35.19999999999928, 38.0), + ], + <Offset>[ + Offset(15.88000000000052, 14.400000000000002), + Offset(16.0841501846027, 14.23098153855435), + Offset(16.909555998563246, 13.616358834085176), + Offset(19.091045681624482, 12.424311359573721), + Offset(24.616857845861503, 11.441581055005743), + Offset(32.32484913042846, 14.574087955608066), + Offset(35.862698571239974, 19.611826936548507), + Offset(36.85283262226824, 23.587705757348193), + Offset(37.024264738045005, 26.59440062294799), + Offset(37.105395261430175, 29.069653364478558), + Offset(37.039412214719505, 31.16155045099348), + Offset(36.87938142220778, 32.932238633932485), + Offset(36.59726506613041, 34.34978415518983), + Offset(36.25867207317826, 35.44700139229438), + Offset(35.92813316136494, 36.28292063146849), + Offset(35.64206627873214, 36.90794520394589), + Offset(35.41899150687777, 37.36172366092795), + Offset(35.26641308921645, 37.674356951517986), + Offset(35.185373943141684, 37.868553404206274), + Offset(35.1734070053048, 37.961203228978455), + Offset(35.19360290773128, 37.99086129676), + Offset(35.19999999999928, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(14.59819610595592, 14.400000000000002), + Offset(14.802631056250549, 14.203964017286612), + Offset(15.634538685893425, 13.484631558321478), + Offset(17.866864845716222, 12.044308065136882), + Offset(23.679981386361106, 10.56677609250158), + Offset(32.13923557546377, 13.305587774939834), + Offset(36.30119536120482, 18.400131017530946), + Offset(37.66286581838166, 22.560982891684347), + Offset(38.073449973226715, 25.751201440489343), + Offset(38.3418259751505, 28.379261403305176), + Offset(38.423715924719914, 30.60759630430111), + Offset(38.381680064777505, 32.49949944041691), + Offset(38.184909045210944, 34.02481606491337), + Offset(37.90537746507338, 35.21416740863276), + Offset(37.615596545463845, 36.1255627398579), + Offset(37.35771829257922, 36.80983154632628), + Offset(37.15419018352325, 37.30768056775854), + Offset(37.01511897681897, 37.650493011036374), + Offset(36.94324108720877, 37.862284731158375), + Offset(36.937157329518215, 37.96115750124504), + Offset(36.96059844905146, 37.99086129676), + Offset(36.96800537109528, 38.0), + ], + <Offset>[ + Offset(13.560000000000521, 15.438196105955402), + Offset(13.74278277489713, 15.22004665632446), + Offset(14.49514695789896, 14.410638469213454), + Offset(16.56755710831768, 12.72804903390955), + Offset(22.212611372667403, 10.617050855101162), + Offset(30.96147724209907, 12.428504561805607), + Offset(35.67494330452109, 17.06355866625214), + Offset(37.48735818248413, 21.073303692247634), + Offset(38.24028822267485, 24.218466095798203), + Offset(38.78408965466406, 26.818632817890993), + Offset(39.09625693291425, 29.037705801935473), + Offset(39.24796894114535, 30.932216991335657), + Offset(39.20761243761814, 32.475697348832576), + Offset(39.05054155543821, 33.691835896176805), + Offset(38.854904345496976, 34.631351126424754), + Offset(38.66784227525018, 35.340773396338506), + Offset(38.51584089185641, 35.85848553358435), + Offset(38.41215342273489, 36.21480140360634), + Offset(38.36194695965814, 36.43342424460918), + Offset(38.3656685492364, 36.532572207239845), + Offset(38.39177516708328, 36.55968457872818), + Offset(38.39999999999928, 36.568005371096), + ], + <Offset>[ + Offset(13.560000000000521, 16.720000000000002), + Offset(13.715765253629392, 16.501565784676608), + Offset(14.363419682135264, 15.685655781883277), + Offset(16.18755381388084, 13.952229869817812), + Offset(21.337806410163243, 11.553927314601557), + Offset(29.692977061430838, 12.614118116770292), + Offset(34.463247385503536, 16.625061876287294), + Offset(36.46063531682029, 20.26327049613421), + Offset(37.3970890402162, 23.169280860616492), + Offset(38.093697693490675, 25.582202104170673), + Offset(38.54230278622188, 27.65340209193506), + Offset(38.81522974762978, 29.42991834876593), + Offset(38.882644347341675, 30.888053369752043), + Offset(38.81770757177658, 32.045130504281694), + Offset(38.69754645388638, 32.943887742325856), + Offset(38.56972861763057, 33.62512138249143), + Offset(38.461797798687, 34.12328685693886), + Offset(38.38828948225328, 34.46609551600381), + Offset(38.35567828661024, 34.67555710054209), + Offset(38.36562282150298, 34.76882188302643), + Offset(38.39177516708328, 34.792689037407996), + Offset(38.39999999999928, 34.8), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(13.560000000000521, 16.720000000000002), + Offset(13.715765253629392, 16.501565784676608), + Offset(14.363419682135264, 15.685655781883277), + Offset(16.18755381388084, 13.952229869817812), + Offset(21.337806410163243, 11.553927314601557), + Offset(29.692977061430838, 12.614118116770292), + Offset(34.463247385503536, 16.625061876287294), + Offset(36.46063531682029, 20.26327049613421), + Offset(37.3970890402162, 23.169280860616492), + Offset(38.093697693490675, 25.582202104170673), + Offset(38.54230278622188, 27.65340209193506), + Offset(38.81522974762978, 29.42991834876593), + Offset(38.882644347341675, 30.888053369752043), + Offset(38.81770757177658, 32.045130504281694), + Offset(38.69754645388638, 32.943887742325856), + Offset(38.56972861763057, 33.62512138249143), + Offset(38.461797798687, 34.12328685693886), + Offset(38.38828948225328, 34.46609551600381), + Offset(38.35567828661024, 34.67555710054209), + Offset(38.36562282150298, 34.76882188302643), + Offset(38.39177516708328, 34.792689037407996), + Offset(38.39999999999928, 34.8), + ], + <Offset>[ + Offset(13.56000000000052, 32.96), + Offset(13.373462856650727, 32.73795790451107), + Offset(12.694481891930677, 31.839672206674575), + Offset(11.373047062632402, 29.462166192774887), + Offset(10.254338293804675, 23.423819248130823), + Offset(13.621530384006954, 14.965775922329756), + Offset(19.111490524511733, 11.069463315450594), + Offset(23.452421333503544, 10.000437650953089), + Offset(26.714054929655155, 9.876476634857061), + Offset(29.346676794624816, 9.917064180881326), + Offset(31.523900529775755, 10.114765834972257), + Offset(33.33257788852383, 10.396328211705992), + Offset(34.76541408254884, 10.773168136480383), + Offset(35.86778370882628, 11.181958151143158), + Offset(36.70387786571219, 11.5643261065016), + Offset(37.32666342868444, 11.888419821256292), + Offset(37.777091006057546, 12.138936021644747), + Offset(38.085941833582574, 12.31061311607528), + Offset(38.27625642592556, 12.404004835577497), + Offset(38.365043467364515, 12.422731815500718), + Offset(38.39177516708328, 12.405483221944), + Offset(38.39999999999928, 12.399999999999999), + ], + <Offset>[ + Offset(13.56000000000052, 32.96), + Offset(13.373462856650727, 32.73795790451107), + Offset(12.694481891930677, 31.839672206674575), + Offset(11.373047062632402, 29.462166192774887), + Offset(10.254338293804675, 23.423819248130823), + Offset(13.621530384006954, 14.965775922329756), + Offset(19.111490524511733, 11.069463315450594), + Offset(23.452421333503544, 10.000437650953089), + Offset(26.714054929655155, 9.876476634857061), + Offset(29.346676794624816, 9.917064180881326), + Offset(31.523900529775755, 10.114765834972257), + Offset(33.33257788852383, 10.396328211705992), + Offset(34.76541408254884, 10.773168136480383), + Offset(35.86778370882628, 11.181958151143158), + Offset(36.70387786571219, 11.5643261065016), + Offset(37.32666342868444, 11.888419821256292), + Offset(37.777091006057546, 12.138936021644747), + Offset(38.085941833582574, 12.31061311607528), + Offset(38.27625642592556, 12.404004835577497), + Offset(38.365043467364515, 12.422731815500718), + Offset(38.39177516708328, 12.405483221944), + Offset(38.39999999999928, 12.399999999999999), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(13.560000000000517, 34.2418038940446), + Offset(13.34644533538299, 34.01947703286322), + Offset(12.56275461616698, 33.114689519344395), + Offset(10.993043768195564, 30.686347028683148), + Offset(9.379533331300514, 24.360695707631216), + Offset(12.353030203338722, 15.151389477294442), + Offset(17.899794605494172, 10.630966525485752), + Offset(22.425698467839702, 9.190404454839666), + Offset(25.870855747196508, 8.827291399675353), + Offset(28.65628483345143, 8.680633467161003), + Offset(30.969946383083386, 8.730462124971844), + Offset(32.899838695008256, 8.894029569136269), + Offset(34.44044599227237, 9.18552415739985), + Offset(35.63494972516465, 9.535252759248047), + Offset(36.546519974101585, 9.876862722402706), + Offset(37.228549771064834, 10.172767807409217), + Offset(37.723047912888134, 10.403737344999264), + Offset(38.06207789310096, 10.561907228472755), + Offset(38.26998775287766, 10.646137691510413), + Offset(38.3649977396311, 10.658981491287307), + Offset(38.39177516708328, 10.638487680623824), + Offset(38.39999999999928, 10.631994628904), + ], + <Offset>[ + Offset(14.598196105955916, 35.28), + Offset(14.362527974420836, 35.07932531421663), + Offset(13.488761527058955, 34.25408124733886), + Offset(11.676784736968232, 31.985654766081694), + Offset(9.429808093900096, 25.828065721324922), + Offset(11.475946990204495, 16.329147810659144), + Offset(16.56322225421536, 11.257218582169475), + Offset(20.938019268402986, 9.365912090737192), + Offset(24.338120402505368, 8.660453150227216), + Offset(27.09565624803725, 8.238369787647443), + Offset(29.40005588071775, 8.057921116777507), + Offset(31.332556245926995, 8.027740692768422), + Offset(32.89132727619159, 8.16282076499266), + Offset(34.112618212708696, 8.390088668883216), + Offset(35.05230836066845, 8.637554922369567), + Offset(35.75949162107706, 8.862643824738257), + Offset(36.273852878713946, 9.042086636666099), + Offset(36.626386285670925, 9.164872782556836), + Offset(36.84112726632846, 9.227431819061039), + Offset(36.936412445625905, 9.230470271569121), + Offset(36.96059844905146, 9.207310962592), + Offset(36.96800537109528, 9.2), + ], + <Offset>[ + Offset(15.880000000000516, 35.28), + Offset(15.644047102772983, 35.10634283548437), + Offset(14.763778839728777, 34.385808523102554), + Offset(12.900965572876494, 32.365658060518534), + Offset(10.36668455340049, 26.702870683829083), + Offset(11.66156054516918, 17.597647991327378), + Offset(16.12472546425052, 12.468914501187037), + Offset(20.127986072289563, 10.392634956401036), + Offset(23.288935167323658, 9.503652332685864), + Offset(25.859225534316927, 8.928761748820826), + Offset(28.015752170717334, 8.611875263469875), + Offset(29.83025760335727, 8.460479886283995), + Offset(31.303683297111053, 8.487788855269121), + Offset(32.465912820813585, 8.62292265254484), + Offset(33.36484497656955, 8.794912813980165), + Offset(34.04383960722998, 8.960757482357865), + Offset(34.538654202068464, 9.096129729835509), + Offset(34.8776803980684, 9.188736723038446), + Offset(35.08326012226138, 9.233700492108937), + Offset(35.17266212141249, 9.23051599930254), + Offset(35.19360290773128, 9.207310962592), + Offset(35.19999999999928, 9.2), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(15.880000000000516, 35.28), + Offset(15.644047102772983, 35.10634283548437), + Offset(14.763778839728777, 34.385808523102554), + Offset(12.900965572876494, 32.365658060518534), + Offset(10.36668455340049, 26.702870683829083), + Offset(11.66156054516918, 17.597647991327378), + Offset(16.12472546425052, 12.468914501187037), + Offset(20.127986072289563, 10.392634956401036), + Offset(23.288935167323658, 9.503652332685864), + Offset(25.859225534316927, 8.928761748820826), + Offset(28.015752170717334, 8.611875263469875), + Offset(29.83025760335727, 8.460479886283995), + Offset(31.303683297111053, 8.487788855269121), + Offset(32.465912820813585, 8.62292265254484), + Offset(33.36484497656955, 8.794912813980165), + Offset(34.04383960722998, 8.960757482357865), + Offset(34.538654202068464, 9.096129729835509), + Offset(34.8776803980684, 9.188736723038446), + Offset(35.08326012226138, 9.233700492108937), + Offset(35.17266212141249, 9.23051599930254), + Offset(35.19360290773128, 9.207310962592), + Offset(35.19999999999928, 9.2), + ], + <Offset>[ + Offset(17.040000000000518, 35.28), + Offset(16.803789397046874, 35.13079300669713), + Offset(15.9176371557853, 34.50501836526003), + Offset(14.008818167373427, 32.70955139989342), + Offset(11.21453397722401, 27.494546977854696), + Offset(11.829536102709142, 18.74560846828623), + Offset(15.727896995619327, 13.565468562686451), + Offset(19.394926583348056, 11.321793098066518), + Offset(22.339449151197982, 10.266726197725939), + Offset(24.74028711122483, 9.553548955882674), + Offset(26.762992438077134, 9.113189710358885), + Offset(28.47071545071013, 8.852097876220133), + Offset(29.86690578044879, 8.781876731325752), + Offset(30.975686224160835, 8.833631499898434), + Offset(31.83773343115353, 8.937317713135464), + Offset(32.49121806714176, 9.049547852996874), + Offset(32.968343428118885, 9.14503735788047), + Offset(33.295145940930645, 9.210332983657782), + Offset(33.49243496047819, 9.239373482157845), + Offset(33.57651283087494, 9.230557381741002), + Offset(33.59451677805528, 9.207310962592), + Offset(33.599999999999284, 9.2), + ], + <Offset>[ + Offset(17.040000000000518, 35.28), + Offset(16.803789397046874, 35.13079300669713), + Offset(15.9176371557853, 34.50501836526003), + Offset(14.008818167373427, 32.70955139989342), + Offset(11.21453397722401, 27.494546977854696), + Offset(11.829536102709142, 18.74560846828623), + Offset(15.727896995619327, 13.565468562686451), + Offset(19.394926583348056, 11.321793098066518), + Offset(22.339449151197982, 10.266726197725939), + Offset(24.74028711122483, 9.553548955882674), + Offset(26.762992438077134, 9.113189710358885), + Offset(28.47071545071013, 8.852097876220133), + Offset(29.86690578044879, 8.781876731325752), + Offset(30.975686224160835, 8.833631499898434), + Offset(31.83773343115353, 8.937317713135464), + Offset(32.49121806714176, 9.049547852996874), + Offset(32.968343428118885, 9.14503735788047), + Offset(33.295145940930645, 9.210332983657782), + Offset(33.49243496047819, 9.239373482157845), + Offset(33.57651283087494, 9.230557381741002), + Offset(33.59451677805528, 9.207310962592), + Offset(33.599999999999284, 9.2), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(17.040000000000518, 35.28), + Offset(16.803789397046874, 35.13079300669713), + Offset(15.9176371557853, 34.50501836526003), + Offset(14.008818167373427, 32.70955139989342), + Offset(11.21453397722401, 27.494546977854696), + Offset(11.829536102709142, 18.74560846828623), + Offset(15.727896995619327, 13.565468562686451), + Offset(19.394926583348056, 11.321793098066518), + Offset(22.339449151197982, 10.266726197725939), + Offset(24.74028711122483, 9.553548955882674), + Offset(26.762992438077134, 9.113189710358885), + Offset(28.47071545071013, 8.852097876220133), + Offset(29.86690578044879, 8.781876731325752), + Offset(30.975686224160835, 8.833631499898434), + Offset(31.83773343115353, 8.937317713135464), + Offset(32.49121806714176, 9.049547852996874), + Offset(32.968343428118885, 9.14503735788047), + Offset(33.295145940930645, 9.210332983657782), + Offset(33.49243496047819, 9.239373482157845), + Offset(33.57651283087494, 9.230557381741002), + Offset(33.59451677805528, 9.207310962592), + Offset(33.599999999999284, 9.2), + ], + <Offset>[ + Offset(17.040000000000518, 37.6), + Offset(16.75488905462135, 37.45027759524491), + Offset(15.67921747147036, 36.81273499737307), + Offset(13.321031488623651, 34.92525658888729), + Offset(9.631181389172786, 29.190245825501734), + Offset(9.533615148791444, 19.08155958336615), + Offset(13.534788872620497, 12.771811625424068), + Offset(17.53661030001709, 9.855674120183501), + Offset(20.813301421117835, 8.36775416547459), + Offset(23.490712697101138, 7.315672109698481), + Offset(25.760363544299118, 6.607670245078484), + Offset(27.687479470837854, 6.133013570925856), + Offset(29.27873002833553, 5.908321698001231), + Offset(30.554268529453648, 5.85317830659293), + Offset(31.55292363284293, 5.883094622303428), + Offset(32.31363732586374, 5.944304772820427), + Offset(32.87052817202896, 6.00441580998131), + Offset(33.25195341969197, 6.045264069382277), + Offset(33.481088980380385, 6.0577231585914735), + Offset(33.57643006599802, 6.038258800665901), + Offset(33.59451677805528, 6.009138703240001), + Offset(33.599999999999284, 6.0), + ], + <Offset>[ + Offset(17.040000000000518, 37.6), + Offset(16.75488905462135, 37.45027759524491), + Offset(15.67921747147036, 36.81273499737307), + Offset(13.321031488623651, 34.92525658888729), + Offset(9.631181389172786, 29.190245825501734), + Offset(9.533615148791444, 19.08155958336615), + Offset(13.534788872620497, 12.771811625424068), + Offset(17.53661030001709, 9.855674120183501), + Offset(20.813301421117835, 8.36775416547459), + Offset(23.490712697101138, 7.315672109698481), + Offset(25.760363544299118, 6.607670245078484), + Offset(27.687479470837854, 6.133013570925856), + Offset(29.27873002833553, 5.908321698001231), + Offset(30.554268529453648, 5.85317830659293), + Offset(31.55292363284293, 5.883094622303428), + Offset(32.31363732586374, 5.944304772820427), + Offset(32.87052817202896, 6.00441580998131), + Offset(33.25195341969197, 6.045264069382277), + Offset(33.481088980380385, 6.0577231585914735), + Offset(33.57643006599802, 6.038258800665901), + Offset(33.59451677805528, 6.009138703240001), + Offset(33.599999999999284, 6.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(17.040000000000518, 37.6), + Offset(16.75488905462135, 37.45027759524491), + Offset(15.67921747147036, 36.81273499737307), + Offset(13.321031488623651, 34.92525658888729), + Offset(9.631181389172786, 29.190245825501734), + Offset(9.533615148791444, 19.08155958336615), + Offset(13.534788872620497, 12.771811625424068), + Offset(17.53661030001709, 9.855674120183501), + Offset(20.813301421117835, 8.36775416547459), + Offset(23.490712697101138, 7.315672109698481), + Offset(25.760363544299118, 6.607670245078484), + Offset(27.687479470837854, 6.133013570925856), + Offset(29.27873002833553, 5.908321698001231), + Offset(30.554268529453648, 5.85317830659293), + Offset(31.55292363284293, 5.883094622303428), + Offset(32.31363732586374, 5.944304772820427), + Offset(32.87052817202896, 6.00441580998131), + Offset(33.25195341969197, 6.045264069382277), + Offset(33.481088980380385, 6.0577231585914735), + Offset(33.57643006599802, 6.038258800665901), + Offset(33.59451677805528, 6.009138703240001), + Offset(33.599999999999284, 6.0), + ], + <Offset>[ + Offset(19.360000000000518, 37.6), + Offset(19.07437364316913, 37.49917793767044), + Offset(17.9869341035834, 37.05115468168801), + Offset(15.536736677617519, 35.61304326763707), + Offset(11.326880236819823, 30.773598413552957), + Offset(9.869566263871368, 21.377480537283848), + Offset(12.741131935358112, 14.964919748422895), + Offset(16.070491322134075, 11.713990403514464), + Offset(18.914329388866488, 9.893901895554741), + Offset(21.252835850916945, 8.565246523822175), + Offset(23.254844079018717, 7.610299138856501), + Offset(24.968395165543576, 6.916249550798135), + Offset(26.405174995011006, 6.496497450114491), + Offset(27.573815336148144, 6.274596001300116), + Offset(28.498700542010894, 6.167904420614027), + Offset(29.208394245687288, 6.1218855140984445), + Offset(29.7299066241298, 6.102231066071232), + Offset(30.08688450541647, 6.08845659062095), + Offset(30.29943865681401, 6.069069138689285), + Offset(30.384131484922918, 6.038341565542824), + Offset(30.39634451870328, 6.009138703240001), + Offset(30.39999999999928, 6.0), + ], + <Offset>[ + Offset(19.360000000000518, 37.6), + Offset(19.07437364316913, 37.49917793767044), + Offset(17.9869341035834, 37.05115468168801), + Offset(15.536736677617519, 35.61304326763707), + Offset(11.326880236819823, 30.773598413552957), + Offset(9.869566263871368, 21.377480537283848), + Offset(12.741131935358112, 14.964919748422895), + Offset(16.070491322134075, 11.713990403514464), + Offset(18.914329388866488, 9.893901895554741), + Offset(21.252835850916945, 8.565246523822175), + Offset(23.254844079018717, 7.610299138856501), + Offset(24.968395165543576, 6.916249550798135), + Offset(26.405174995011006, 6.496497450114491), + Offset(27.573815336148144, 6.274596001300116), + Offset(28.498700542010894, 6.167904420614027), + Offset(29.208394245687288, 6.1218855140984445), + Offset(29.7299066241298, 6.102231066071232), + Offset(30.08688450541647, 6.08845659062095), + Offset(30.29943865681401, 6.069069138689285), + Offset(30.384131484922918, 6.038341565542824), + Offset(30.39634451870328, 6.009138703240001), + Offset(30.39999999999928, 6.0), + ], + ), + _PathClose( + ), + _PathMoveTo( + <Offset>[ + Offset(15.879999999999999, 16.720000000000002), + Offset(16.035249842176654, 16.55046612710212), + Offset(16.671136314247786, 15.924075466198163), + Offset(18.403259002874208, 14.640016548567434), + Offset(23.0335052578099, 13.137279902652425), + Offset(30.028928176510686, 14.910039070687475), + Offset(33.66959044824132, 18.81816999928563), + Offset(34.9945163389376, 22.121586779464756), + Offset(35.49811700796528, 24.6954285906963), + Offset(35.85582084730699, 26.831776518294085), + Offset(36.03678332094205, 28.656030985712853), + Offset(36.09614544233611, 30.213154328638034), + Offset(36.0090893140178, 31.476229121865174), + Offset(35.83725437847175, 32.46654819898878), + Offset(35.64332336305503, 33.22869754063639), + Offset(35.46448553745482, 33.80270212376941), + Offset(35.32117625078855, 34.22110211302876), + Offset(35.22322056797849, 34.50928803724247), + Offset(35.17402796304459, 34.6869030806399), + Offset(35.1733242404286, 34.768904647903355), + Offset(35.193602907732, 34.792689037407996), + Offset(35.2, 34.8), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(15.879999999999999, 16.720000000000002), + Offset(16.035249842176654, 16.55046612710212), + Offset(16.671136314247786, 15.924075466198163), + Offset(18.403259002874208, 14.640016548567434), + Offset(23.0335052578099, 13.137279902652425), + Offset(30.028928176510686, 14.910039070687475), + Offset(33.66959044824132, 18.81816999928563), + Offset(34.9945163389376, 22.121586779464756), + Offset(35.49811700796528, 24.6954285906963), + Offset(35.85582084730699, 26.831776518294085), + Offset(36.03678332094205, 28.656030985712853), + Offset(36.09614544233611, 30.213154328638034), + Offset(36.0090893140178, 31.476229121865174), + Offset(35.83725437847175, 32.46654819898878), + Offset(35.64332336305503, 33.22869754063639), + Offset(35.46448553745482, 33.80270212376941), + Offset(35.32117625078855, 34.22110211302876), + Offset(35.22322056797849, 34.50928803724247), + Offset(35.17402796304459, 34.6869030806399), + Offset(35.1733242404286, 34.768904647903355), + Offset(35.193602907732, 34.792689037407996), + Offset(35.2, 34.8), + ], + <Offset>[ + Offset(32.12, 16.720000000000006), + Offset(32.27164196201112, 16.892768524080786), + Offset(32.82515273903908, 17.59301325640275), + Offset(33.91319532583128, 19.454523299815868), + Offset(34.90339719133917, 24.22074801901099), + Offset(32.380585982070144, 30.981485748111357), + Offset(28.113991887404627, 34.16992686027743), + Offset(24.731683493756478, 35.1298007627815), + Offset(22.20531278220585, 35.37846270125735), + Offset(20.190682924017636, 35.57879741715995), + Offset(18.498147063979243, 35.67443324215898), + Offset(17.062555305276174, 35.69580618774398), + Offset(15.894204080746132, 35.59345938665801), + Offset(14.974082025333214, 35.41647206193909), + Offset(14.263761727230776, 35.22236612881059), + Offset(13.727783976219687, 35.045767312715526), + Offset(13.33682541549443, 34.90580890565822), + Offset(13.067738168049956, 34.811635685913174), + Offset(12.902475698079991, 34.766324941324584), + Offset(12.827234172902884, 34.76948400204182), + Offset(12.806397092268, 34.792689037407996), + Offset(12.799999999999999, 34.8), + ], + <Offset>[ + Offset(32.12, 16.720000000000006), + Offset(32.27164196201112, 16.892768524080786), + Offset(32.82515273903908, 17.59301325640275), + Offset(33.91319532583128, 19.454523299815868), + Offset(34.90339719133917, 24.22074801901099), + Offset(32.380585982070144, 30.981485748111357), + Offset(28.113991887404627, 34.16992686027743), + Offset(24.731683493756478, 35.1298007627815), + Offset(22.20531278220585, 35.37846270125735), + Offset(20.190682924017636, 35.57879741715995), + Offset(18.498147063979243, 35.67443324215898), + Offset(17.062555305276174, 35.69580618774398), + Offset(15.894204080746132, 35.59345938665801), + Offset(14.974082025333214, 35.41647206193909), + Offset(14.263761727230776, 35.22236612881059), + Offset(13.727783976219687, 35.045767312715526), + Offset(13.33682541549443, 34.90580890565822), + Offset(13.067738168049956, 34.811635685913174), + Offset(12.902475698079991, 34.766324941324584), + Offset(12.827234172902884, 34.76948400204182), + Offset(12.806397092268, 34.792689037407996), + Offset(12.799999999999999, 34.8), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(32.12, 16.720000000000006), + Offset(32.27164196201112, 16.892768524080786), + Offset(32.82515273903908, 17.59301325640275), + Offset(33.91319532583128, 19.454523299815868), + Offset(34.90339719133917, 24.22074801901099), + Offset(32.380585982070144, 30.981485748111357), + Offset(28.113991887404627, 34.16992686027743), + Offset(24.731683493756478, 35.1298007627815), + Offset(22.20531278220585, 35.37846270125735), + Offset(20.190682924017636, 35.57879741715995), + Offset(18.498147063979243, 35.67443324215898), + Offset(17.062555305276174, 35.69580618774398), + Offset(15.894204080746132, 35.59345938665801), + Offset(14.974082025333214, 35.41647206193909), + Offset(14.263761727230776, 35.22236612881059), + Offset(13.727783976219687, 35.045767312715526), + Offset(13.33682541549443, 34.90580890565822), + Offset(13.067738168049956, 34.811635685913174), + Offset(12.902475698079991, 34.766324941324584), + Offset(12.827234172902884, 34.76948400204182), + Offset(12.806397092268, 34.792689037407996), + Offset(12.799999999999999, 34.8), + ], + <Offset>[ + Offset(32.12, 29.480000000000004), + Offset(32.00269007867074, 29.64993376109358), + Offset(31.51384447530691, 30.285454733024483), + Offset(30.130368592707512, 31.640901839282144), + Offset(26.194957957057433, 33.5470916810697), + Offset(19.753020735522814, 32.82921688105094), + Offset(16.051897210911072, 29.804813705334308), + Offset(14.51094393543618, 27.066146384424904), + Offset(13.811500266765027, 24.934116523874938), + Offset(13.31802364633732, 23.270474763146886), + Offset(12.983688148200141, 21.89407618311678), + Offset(12.754757415978641, 20.740842508625462), + Offset(12.65923744412319, 19.788906703373133), + Offset(12.656284704443689, 19.023979498758813), + Offset(12.697307836522478, 18.424139129234387), + Offset(12.751089899190589, 17.966930371745068), + Offset(12.798841506999857, 17.632390392212844), + Offset(12.83017930123726, 17.403756657397903), + Offset(12.840072807542027, 17.267248161709546), + Offset(12.826778966079804, 17.21184180612876), + Offset(12.806397092268, 17.202741610971998), + Offset(12.799999999999999, 17.2), + ], + <Offset>[ + Offset(32.12, 29.480000000000004), + Offset(32.00269007867074, 29.64993376109358), + Offset(31.51384447530691, 30.285454733024483), + Offset(30.130368592707512, 31.640901839282144), + Offset(26.194957957057433, 33.5470916810697), + Offset(19.753020735522814, 32.82921688105094), + Offset(16.051897210911072, 29.804813705334308), + Offset(14.51094393543618, 27.066146384424904), + Offset(13.811500266765027, 24.934116523874938), + Offset(13.31802364633732, 23.270474763146886), + Offset(12.983688148200141, 21.89407618311678), + Offset(12.754757415978641, 20.740842508625462), + Offset(12.65923744412319, 19.788906703373133), + Offset(12.656284704443689, 19.023979498758813), + Offset(12.697307836522478, 18.424139129234387), + Offset(12.751089899190589, 17.966930371745068), + Offset(12.798841506999857, 17.632390392212844), + Offset(12.83017930123726, 17.403756657397903), + Offset(12.840072807542027, 17.267248161709546), + Offset(12.826778966079804, 17.21184180612876), + Offset(12.806397092268, 17.202741610971998), + Offset(12.799999999999999, 17.2), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(32.12, 29.480000000000004), + Offset(32.00269007867074, 29.64993376109358), + Offset(31.51384447530691, 30.285454733024483), + Offset(30.130368592707512, 31.640901839282144), + Offset(26.194957957057433, 33.5470916810697), + Offset(19.753020735522814, 32.82921688105094), + Offset(16.051897210911072, 29.804813705334308), + Offset(14.51094393543618, 27.066146384424904), + Offset(13.811500266765027, 24.934116523874938), + Offset(13.31802364633732, 23.270474763146886), + Offset(12.983688148200141, 21.89407618311678), + Offset(12.754757415978641, 20.740842508625462), + Offset(12.65923744412319, 19.788906703373133), + Offset(12.656284704443689, 19.023979498758813), + Offset(12.697307836522478, 18.424139129234387), + Offset(12.751089899190589, 17.966930371745068), + Offset(12.798841506999857, 17.632390392212844), + Offset(12.83017930123726, 17.403756657397903), + Offset(12.840072807542027, 17.267248161709546), + Offset(12.826778966079804, 17.21184180612876), + Offset(12.806397092268, 17.202741610971998), + Offset(12.799999999999999, 17.2), + ], + <Offset>[ + Offset(15.879999999999997, 29.480000000000004), + Offset(15.766297958836272, 29.30763136411491), + Offset(15.359828050515612, 28.6165169428199), + Offset(14.620432269750436, 26.826395088033706), + Offset(14.325066023528167, 22.463623564711135), + Offset(17.401362929963348, 16.757770203627054), + Offset(21.607495771747768, 14.453056844342509), + Offset(24.7737767806173, 14.057932401108161), + Offset(27.10430449252446, 14.251082413313888), + Offset(28.983161569626667, 14.523453864281027), + Offset(30.522324405162944, 14.87567392667065), + Offset(31.78834755303858, 15.258190649519511), + Offset(32.77412267739486, 15.671676438580297), + Offset(33.51945705758222, 16.074055635808506), + Offset(34.076869472346736, 16.430470541060192), + Offset(34.487791460425726, 16.723865182798942), + Offset(34.78319234229397, 16.947683599583385), + Offset(34.98566170116579, 17.1014090087272), + Offset(35.11162507250663, 17.187826301024863), + Offset(35.17286903360552, 17.211262451990294), + Offset(35.193602907732, 17.202741610971998), + Offset(35.2, 17.2), + ], + <Offset>[ + Offset(15.879999999999997, 29.480000000000004), + Offset(15.766297958836272, 29.30763136411491), + Offset(15.359828050515612, 28.6165169428199), + Offset(14.620432269750436, 26.826395088033706), + Offset(14.325066023528167, 22.463623564711135), + Offset(17.401362929963348, 16.757770203627054), + Offset(21.607495771747768, 14.453056844342509), + Offset(24.7737767806173, 14.057932401108161), + Offset(27.10430449252446, 14.251082413313888), + Offset(28.983161569626667, 14.523453864281027), + Offset(30.522324405162944, 14.87567392667065), + Offset(31.78834755303858, 15.258190649519511), + Offset(32.77412267739486, 15.671676438580297), + Offset(33.51945705758222, 16.074055635808506), + Offset(34.076869472346736, 16.430470541060192), + Offset(34.487791460425726, 16.723865182798942), + Offset(34.78319234229397, 16.947683599583385), + Offset(34.98566170116579, 17.1014090087272), + Offset(35.11162507250663, 17.187826301024863), + Offset(35.17286903360552, 17.211262451990294), + Offset(35.193602907732, 17.202741610971998), + Offset(35.2, 17.2), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(15.879999999999997, 29.480000000000004), + Offset(15.766297958836272, 29.30763136411491), + Offset(15.359828050515612, 28.6165169428199), + Offset(14.620432269750436, 26.826395088033706), + Offset(14.325066023528167, 22.463623564711135), + Offset(17.401362929963348, 16.757770203627054), + Offset(21.607495771747768, 14.453056844342509), + Offset(24.7737767806173, 14.057932401108161), + Offset(27.10430449252446, 14.251082413313888), + Offset(28.983161569626667, 14.523453864281027), + Offset(30.522324405162944, 14.87567392667065), + Offset(31.78834755303858, 15.258190649519511), + Offset(32.77412267739486, 15.671676438580297), + Offset(33.51945705758222, 16.074055635808506), + Offset(34.076869472346736, 16.430470541060192), + Offset(34.487791460425726, 16.723865182798942), + Offset(34.78319234229397, 16.947683599583385), + Offset(34.98566170116579, 17.1014090087272), + Offset(35.11162507250663, 17.187826301024863), + Offset(35.17286903360552, 17.211262451990294), + Offset(35.193602907732, 17.202741610971998), + Offset(35.2, 17.2), + ], + <Offset>[ + Offset(15.879999999999999, 16.720000000000002), + Offset(16.035249842176654, 16.55046612710212), + Offset(16.671136314247786, 15.924075466198163), + Offset(18.403259002874208, 14.640016548567434), + Offset(23.0335052578099, 13.137279902652425), + Offset(30.028928176510686, 14.910039070687475), + Offset(33.66959044824132, 18.81816999928563), + Offset(34.9945163389376, 22.121586779464756), + Offset(35.49811700796528, 24.6954285906963), + Offset(35.85582084730699, 26.831776518294085), + Offset(36.03678332094205, 28.656030985712853), + Offset(36.09614544233611, 30.213154328638034), + Offset(36.0090893140178, 31.476229121865174), + Offset(35.83725437847175, 32.46654819898878), + Offset(35.64332336305503, 33.22869754063639), + Offset(35.46448553745482, 33.80270212376941), + Offset(35.32117625078855, 34.22110211302876), + Offset(35.22322056797849, 34.50928803724247), + Offset(35.17402796304459, 34.6869030806399), + Offset(35.1733242404286, 34.768904647903355), + Offset(35.193602907732, 34.792689037407996), + Offset(35.2, 34.8), + ], + <Offset>[ + Offset(15.879999999999999, 16.720000000000002), + Offset(16.035249842176654, 16.55046612710212), + Offset(16.671136314247786, 15.924075466198163), + Offset(18.403259002874208, 14.640016548567434), + Offset(23.0335052578099, 13.137279902652425), + Offset(30.028928176510686, 14.910039070687475), + Offset(33.66959044824132, 18.81816999928563), + Offset(34.9945163389376, 22.121586779464756), + Offset(35.49811700796528, 24.6954285906963), + Offset(35.85582084730699, 26.831776518294085), + Offset(36.03678332094205, 28.656030985712853), + Offset(36.09614544233611, 30.213154328638034), + Offset(36.0090893140178, 31.476229121865174), + Offset(35.83725437847175, 32.46654819898878), + Offset(35.64332336305503, 33.22869754063639), + Offset(35.46448553745482, 33.80270212376941), + Offset(35.32117625078855, 34.22110211302876), + Offset(35.22322056797849, 34.50928803724247), + Offset(35.17402796304459, 34.6869030806399), + Offset(35.1733242404286, 34.768904647903355), + Offset(35.193602907732, 34.792689037407996), + Offset(35.2, 34.8), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(38.0, 22.0), + Offset(38.039045226086195, 22.295532593474903), + Offset(38.131410438884686, 23.449328584561677), + Offset(37.96355431181625, 26.240346174357384), + Offset(35.597624587569385, 32.092904541992695), + Offset(28.005894824414142, 37.5629202849435), + Offset(21.11658608929624, 37.84506858847438), + Offset(16.898690234114245, 36.22993865924664), + Offset(14.340278644035072, 34.329074659673786), + Offset(12.751502851764192, 32.57154081283703), + Offset(11.745130152351626, 31.05819842574568), + Offset(11.10059480478027, 29.797011782766905), + Offset(10.68542515781559, 28.766770056534085), + Offset(10.41788407761968, 27.940320681241946), + Offset(10.246172947866903, 27.291237065301104), + Offset(10.137024991031543, 26.79605506038706), + Offset(10.06904541544619, 26.434852020780554), + Offset(10.028594148271123, 26.190848814107472), + Offset(10.007221106846284, 26.049911912085946), + Offset(10.000051857547207, 26.00036296922149), + Offset(10.0, 26.0), + Offset(10.0, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.0, 22.0), + Offset(38.039045226086195, 22.295532593474903), + Offset(38.131410438884686, 23.449328584561677), + Offset(37.96355431181625, 26.240346174357384), + Offset(35.597624587569385, 32.092904541992695), + Offset(28.005894824414142, 37.5629202849435), + Offset(21.11658608929624, 37.84506858847438), + Offset(16.898690234114245, 36.22993865924664), + Offset(14.340278644035072, 34.329074659673786), + Offset(12.751502851764192, 32.57154081283703), + Offset(11.745130152351626, 31.05819842574568), + Offset(11.10059480478027, 29.797011782766905), + Offset(10.68542515781559, 28.766770056534085), + Offset(10.41788407761968, 27.940320681241946), + Offset(10.246172947866903, 27.291237065301104), + Offset(10.137024991031543, 26.79605506038706), + Offset(10.06904541544619, 26.434852020780554), + Offset(10.028594148271123, 26.190848814107472), + Offset(10.007221106846284, 26.049911912085946), + Offset(10.000051857547207, 26.00036296922149), + Offset(10.0, 26.0), + Offset(10.0, 26.0), + ], + <Offset>[ + Offset(38.0, 26.0), + Offset(37.95473429086978, 26.294643953040044), + Offset(37.72034201765203, 27.428150364066923), + Offset(36.77771521052353, 30.06052753469164), + Offset(32.86770633230866, 35.01652324483241), + Offset(24.048041351653396, 38.14205402438172), + Offset(17.355303440951563, 36.48390994993835), + Offset(13.758359800160616, 33.75237437842877), + Offset(11.83452659356501, 31.211189693616653), + Offset(10.801411310099256, 29.079099978817517), + Offset(10.259029387048772, 27.34450693137431), + Offset(9.993407713414326, 25.953297856794705), + Offset(9.883312535673422, 24.848018298461085), + Offset(9.857878923767148, 23.97971539572578), + Offset(9.874779651667918, 23.308516008091793), + Offset(9.908648574481903, 22.80257985546041), + Offset(9.94452503300979, 22.436790656274262), + Offset(9.974012714390186, 22.191221223059088), + Offset(9.992956927188366, 22.049937345519467), + Offset(9.999948151863302, 22.000362970565853), + Offset(10.0, 22.0), + Offset(10.0, 22.0), + ], + <Offset>[ + Offset(38.0, 26.0), + Offset(37.95473429086978, 26.294643953040044), + Offset(37.72034201765203, 27.428150364066923), + Offset(36.77771521052353, 30.06052753469164), + Offset(32.86770633230866, 35.01652324483241), + Offset(24.048041351653396, 38.14205402438172), + Offset(17.355303440951563, 36.48390994993835), + Offset(13.758359800160616, 33.75237437842877), + Offset(11.83452659356501, 31.211189693616653), + Offset(10.801411310099256, 29.079099978817517), + Offset(10.259029387048772, 27.34450693137431), + Offset(9.993407713414326, 25.953297856794705), + Offset(9.883312535673422, 24.848018298461085), + Offset(9.857878923767148, 23.97971539572578), + Offset(9.874779651667918, 23.308516008091793), + Offset(9.908648574481903, 22.80257985546041), + Offset(9.94452503300979, 22.436790656274262), + Offset(9.974012714390186, 22.191221223059088), + Offset(9.992956927188366, 22.049937345519467), + Offset(9.999948151863302, 22.000362970565853), + Offset(10.0, 22.0), + Offset(10.0, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.0, 26.0), + Offset(37.95473429086978, 26.294643953040044), + Offset(37.72034201765203, 27.428150364066923), + Offset(36.77771521052353, 30.06052753469164), + Offset(32.86770633230866, 35.01652324483241), + Offset(24.048041351653396, 38.14205402438172), + Offset(17.355303440951563, 36.48390994993835), + Offset(13.758359800160616, 33.75237437842877), + Offset(11.83452659356501, 31.211189693616653), + Offset(10.801411310099256, 29.079099978817517), + Offset(10.259029387048772, 27.34450693137431), + Offset(9.993407713414326, 25.953297856794705), + Offset(9.883312535673422, 24.848018298461085), + Offset(9.857878923767148, 23.97971539572578), + Offset(9.874779651667918, 23.308516008091793), + Offset(9.908648574481903, 22.80257985546041), + Offset(9.94452503300979, 22.436790656274262), + Offset(9.974012714390186, 22.191221223059088), + Offset(9.992956927188366, 22.049937345519467), + Offset(9.999948151863302, 22.000362970565853), + Offset(10.0, 22.0), + Offset(10.0, 22.0), + ], + <Offset>[ + Offset(10.0, 26.0), + Offset(9.960954773913805, 25.704467406525104), + Offset(9.86858956111531, 24.55067141543833), + Offset(10.036445688183749, 21.759653825642616), + Offset(12.402375412430613, 15.907095458007305), + Offset(19.994105175585858, 10.437079715056495), + Offset(26.88341391070376, 10.154931411525617), + Offset(31.101309765885755, 11.770061340753355), + Offset(33.659721355964926, 13.670925340326216), + Offset(35.24849714823581, 15.428459187162975), + Offset(36.254869847648365, 16.94180157425432), + Offset(36.89940519521972, 18.202988217233095), + Offset(37.31457484218441, 19.233229943465915), + Offset(37.58211592238032, 20.059679318758054), + Offset(37.7538270521331, 20.708762934698896), + Offset(37.86297500896845, 21.20394493961294), + Offset(37.93095458455382, 21.565147979219446), + Offset(37.971405851728875, 21.809151185892528), + Offset(37.99277889315371, 21.950088087914054), + Offset(37.999948142452794, 21.99963703077851), + Offset(38.0, 22.0), + Offset(38.0, 22.0), + ], + <Offset>[ + Offset(10.0, 26.0), + Offset(9.960954773913805, 25.704467406525104), + Offset(9.86858956111531, 24.55067141543833), + Offset(10.036445688183749, 21.759653825642616), + Offset(12.402375412430613, 15.907095458007305), + Offset(19.994105175585858, 10.437079715056495), + Offset(26.88341391070376, 10.154931411525617), + Offset(31.101309765885755, 11.770061340753355), + Offset(33.659721355964926, 13.670925340326216), + Offset(35.24849714823581, 15.428459187162975), + Offset(36.254869847648365, 16.94180157425432), + Offset(36.89940519521972, 18.202988217233095), + Offset(37.31457484218441, 19.233229943465915), + Offset(37.58211592238032, 20.059679318758054), + Offset(37.7538270521331, 20.708762934698896), + Offset(37.86297500896845, 21.20394493961294), + Offset(37.93095458455382, 21.565147979219446), + Offset(37.971405851728875, 21.809151185892528), + Offset(37.99277889315371, 21.950088087914054), + Offset(37.999948142452794, 21.99963703077851), + Offset(38.0, 22.0), + Offset(38.0, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.0, 26.0), + Offset(9.960954773913805, 25.704467406525104), + Offset(9.86858956111531, 24.55067141543833), + Offset(10.036445688183749, 21.759653825642616), + Offset(12.402375412430613, 15.907095458007305), + Offset(19.994105175585858, 10.437079715056495), + Offset(26.88341391070376, 10.154931411525617), + Offset(31.101309765885755, 11.770061340753355), + Offset(33.659721355964926, 13.670925340326216), + Offset(35.24849714823581, 15.428459187162975), + Offset(36.254869847648365, 16.94180157425432), + Offset(36.89940519521972, 18.202988217233095), + Offset(37.31457484218441, 19.233229943465915), + Offset(37.58211592238032, 20.059679318758054), + Offset(37.7538270521331, 20.708762934698896), + Offset(37.86297500896845, 21.20394493961294), + Offset(37.93095458455382, 21.565147979219446), + Offset(37.971405851728875, 21.809151185892528), + Offset(37.99277889315371, 21.950088087914054), + Offset(37.999948142452794, 21.99963703077851), + Offset(38.0, 22.0), + Offset(38.0, 22.0), + ], + <Offset>[ + Offset(10.0, 22.0), + Offset(10.045265709130224, 21.705356046959963), + Offset(10.279657982347967, 20.571849635933084), + Offset(11.222284789476467, 17.93947246530836), + Offset(15.132293667691345, 12.983476755167583), + Offset(23.951958648346604, 9.857945975618275), + Offset(30.644696559048437, 11.516090050061646), + Offset(34.24164019983938, 14.247625621571231), + Offset(36.16547340643499, 16.788810306383347), + Offset(37.19858868990075, 18.920900021182483), + Offset(37.74097061295122, 20.65549306862569), + Offset(38.006592286585665, 22.046702143205295), + Offset(38.116687464326574, 23.151981701538915), + Offset(38.142121076232854, 24.02028460427422), + Offset(38.12522034833208, 24.691483991908207), + Offset(38.09135142551809, 25.19742014453959), + Offset(38.05547496699022, 25.563209343725738), + Offset(38.025987285609816, 25.808778776940912), + Offset(38.00704307281163, 25.950062654480533), + Offset(38.0000518481367, 25.999637029434147), + Offset(38.0, 26.0), + Offset(38.0, 26.0), + ], + <Offset>[ + Offset(10.0, 22.0), + Offset(10.045265709130224, 21.705356046959963), + Offset(10.279657982347967, 20.571849635933084), + Offset(11.222284789476467, 17.93947246530836), + Offset(15.132293667691345, 12.983476755167583), + Offset(23.951958648346604, 9.857945975618275), + Offset(30.644696559048437, 11.516090050061646), + Offset(34.24164019983938, 14.247625621571231), + Offset(36.16547340643499, 16.788810306383347), + Offset(37.19858868990075, 18.920900021182483), + Offset(37.74097061295122, 20.65549306862569), + Offset(38.006592286585665, 22.046702143205295), + Offset(38.116687464326574, 23.151981701538915), + Offset(38.142121076232854, 24.02028460427422), + Offset(38.12522034833208, 24.691483991908207), + Offset(38.09135142551809, 25.19742014453959), + Offset(38.05547496699022, 25.563209343725738), + Offset(38.025987285609816, 25.808778776940912), + Offset(38.00704307281163, 25.950062654480533), + Offset(38.0000518481367, 25.999637029434147), + Offset(38.0, 26.0), + Offset(38.0, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.0, 22.0), + Offset(10.045265709130224, 21.705356046959963), + Offset(10.279657982347967, 20.571849635933084), + Offset(11.222284789476467, 17.93947246530836), + Offset(15.132293667691345, 12.983476755167583), + Offset(23.951958648346604, 9.857945975618275), + Offset(30.644696559048437, 11.516090050061646), + Offset(34.24164019983938, 14.247625621571231), + Offset(36.16547340643499, 16.788810306383347), + Offset(37.19858868990075, 18.920900021182483), + Offset(37.74097061295122, 20.65549306862569), + Offset(38.006592286585665, 22.046702143205295), + Offset(38.116687464326574, 23.151981701538915), + Offset(38.142121076232854, 24.02028460427422), + Offset(38.12522034833208, 24.691483991908207), + Offset(38.09135142551809, 25.19742014453959), + Offset(38.05547496699022, 25.563209343725738), + Offset(38.025987285609816, 25.808778776940912), + Offset(38.00704307281163, 25.950062654480533), + Offset(38.0000518481367, 25.999637029434147), + Offset(38.0, 26.0), + Offset(38.0, 26.0), + ], + <Offset>[ + Offset(38.0, 22.0), + Offset(38.039045226086195, 22.295532593474903), + Offset(38.131410438884686, 23.449328584561677), + Offset(37.96355431181625, 26.240346174357384), + Offset(35.597624587569385, 32.092904541992695), + Offset(28.005894824414142, 37.5629202849435), + Offset(21.11658608929624, 37.84506858847438), + Offset(16.898690234114245, 36.22993865924664), + Offset(14.340278644035072, 34.329074659673786), + Offset(12.751502851764192, 32.57154081283703), + Offset(11.745130152351626, 31.05819842574568), + Offset(11.10059480478027, 29.797011782766905), + Offset(10.68542515781559, 28.766770056534085), + Offset(10.41788407761968, 27.940320681241946), + Offset(10.246172947866903, 27.291237065301104), + Offset(10.137024991031543, 26.79605506038706), + Offset(10.06904541544619, 26.434852020780554), + Offset(10.028594148271123, 26.190848814107472), + Offset(10.007221106846284, 26.049911912085946), + Offset(10.000051857547207, 26.00036296922149), + Offset(10.0, 26.0), + Offset(10.0, 26.0), + ], + <Offset>[ + Offset(38.0, 22.0), + Offset(38.039045226086195, 22.295532593474903), + Offset(38.131410438884686, 23.449328584561677), + Offset(37.96355431181625, 26.240346174357384), + Offset(35.597624587569385, 32.092904541992695), + Offset(28.005894824414142, 37.5629202849435), + Offset(21.11658608929624, 37.84506858847438), + Offset(16.898690234114245, 36.22993865924664), + Offset(14.340278644035072, 34.329074659673786), + Offset(12.751502851764192, 32.57154081283703), + Offset(11.745130152351626, 31.05819842574568), + Offset(11.10059480478027, 29.797011782766905), + Offset(10.68542515781559, 28.766770056534085), + Offset(10.41788407761968, 27.940320681241946), + Offset(10.246172947866903, 27.291237065301104), + Offset(10.137024991031543, 26.79605506038706), + Offset(10.06904541544619, 26.434852020780554), + Offset(10.028594148271123, 26.190848814107472), + Offset(10.007221106846284, 26.049911912085946), + Offset(10.000051857547207, 26.00036296922149), + Offset(10.0, 26.0), + Offset(10.0, 26.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(26.0, 38.0), + Offset(25.7044674065251, 38.0390452260862), + Offset(24.550671415438327, 38.13141043888469), + Offset(21.759653825642616, 37.96355431181625), + Offset(15.907095458007305, 35.597624587569385), + Offset(10.437079715056495, 28.005894824414142), + Offset(10.154931411525617, 21.11658608929624), + Offset(11.770061340753355, 16.898690234114245), + Offset(13.670925340326216, 14.340278644035072), + Offset(15.428459187162979, 12.751502851764188), + Offset(16.941801574254317, 11.74513015235163), + Offset(18.20298821723309, 11.100594804780274), + Offset(19.233229943465915, 10.68542515781559), + Offset(20.059679318758054, 10.41788407761968), + Offset(20.708762934698896, 10.246172947866903), + Offset(21.203944939612935, 10.137024991031547), + Offset(21.565147979219454, 10.069045415446187), + Offset(21.809151185892528, 10.028594148271123), + Offset(21.950088087914054, 10.007221106846284), + Offset(21.99963703077851, 10.000051857547207), + Offset(22.0, 10.0), + Offset(22.0, 10.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.0, 38.0), + Offset(25.7044674065251, 38.0390452260862), + Offset(24.550671415438327, 38.13141043888469), + Offset(21.759653825642616, 37.96355431181625), + Offset(15.907095458007305, 35.597624587569385), + Offset(10.437079715056495, 28.005894824414142), + Offset(10.154931411525617, 21.11658608929624), + Offset(11.770061340753355, 16.898690234114245), + Offset(13.670925340326216, 14.340278644035072), + Offset(15.428459187162979, 12.751502851764188), + Offset(16.941801574254317, 11.74513015235163), + Offset(18.20298821723309, 11.100594804780274), + Offset(19.233229943465915, 10.68542515781559), + Offset(20.059679318758054, 10.41788407761968), + Offset(20.708762934698896, 10.246172947866903), + Offset(21.203944939612935, 10.137024991031547), + Offset(21.565147979219454, 10.069045415446187), + Offset(21.809151185892528, 10.028594148271123), + Offset(21.950088087914054, 10.007221106846284), + Offset(21.99963703077851, 10.000051857547207), + Offset(22.0, 10.0), + Offset(22.0, 10.0), + ], + <Offset>[ + Offset(22.0, 38.0), + Offset(21.70535604695996, 37.95473429086978), + Offset(20.571849635933077, 37.72034201765204), + Offset(17.93947246530836, 36.77771521052353), + Offset(12.983476755167583, 32.86770633230866), + Offset(9.857945975618275, 24.048041351653396), + Offset(11.516090050061646, 17.355303440951563), + Offset(14.247625621571231, 13.758359800160616), + Offset(16.788810306383347, 11.83452659356501), + Offset(18.920900021182486, 10.801411310099253), + Offset(20.655493068625688, 10.259029387048775), + Offset(22.04670214320529, 9.99340771341433), + Offset(23.151981701538915, 9.883312535673422), + Offset(24.02028460427422, 9.857878923767148), + Offset(24.691483991908207, 9.874779651667918), + Offset(25.197420144539585, 9.908648574481907), + Offset(25.56320934372574, 9.944525033009786), + Offset(25.808778776940912, 9.974012714390186), + Offset(25.950062654480533, 9.992956927188366), + Offset(25.999637029434147, 9.999948151863302), + Offset(26.0, 10.0), + Offset(26.0, 10.0), + ], + <Offset>[ + Offset(22.0, 38.0), + Offset(21.70535604695996, 37.95473429086978), + Offset(20.571849635933077, 37.72034201765204), + Offset(17.93947246530836, 36.77771521052353), + Offset(12.983476755167583, 32.86770633230866), + Offset(9.857945975618275, 24.048041351653396), + Offset(11.516090050061646, 17.355303440951563), + Offset(14.247625621571231, 13.758359800160616), + Offset(16.788810306383347, 11.83452659356501), + Offset(18.920900021182486, 10.801411310099253), + Offset(20.655493068625688, 10.259029387048775), + Offset(22.04670214320529, 9.99340771341433), + Offset(23.151981701538915, 9.883312535673422), + Offset(24.02028460427422, 9.857878923767148), + Offset(24.691483991908207, 9.874779651667918), + Offset(25.197420144539585, 9.908648574481907), + Offset(25.56320934372574, 9.944525033009786), + Offset(25.808778776940912, 9.974012714390186), + Offset(25.950062654480533, 9.992956927188366), + Offset(25.999637029434147, 9.999948151863302), + Offset(26.0, 10.0), + Offset(26.0, 10.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(22.0, 38.0), + Offset(21.70535604695996, 37.95473429086978), + Offset(20.571849635933077, 37.72034201765204), + Offset(17.93947246530836, 36.77771521052353), + Offset(12.983476755167583, 32.86770633230866), + Offset(9.857945975618275, 24.048041351653396), + Offset(11.516090050061646, 17.355303440951563), + Offset(14.247625621571231, 13.758359800160616), + Offset(16.788810306383347, 11.83452659356501), + Offset(18.920900021182486, 10.801411310099253), + Offset(20.655493068625688, 10.259029387048775), + Offset(22.04670214320529, 9.99340771341433), + Offset(23.151981701538915, 9.883312535673422), + Offset(24.02028460427422, 9.857878923767148), + Offset(24.691483991908207, 9.874779651667918), + Offset(25.197420144539585, 9.908648574481907), + Offset(25.56320934372574, 9.944525033009786), + Offset(25.808778776940912, 9.974012714390186), + Offset(25.950062654480533, 9.992956927188366), + Offset(25.999637029434147, 9.999948151863302), + Offset(26.0, 10.0), + Offset(26.0, 10.0), + ], + <Offset>[ + Offset(22.0, 10.0), + Offset(22.2955325934749, 9.960954773913809), + Offset(23.449328584561673, 9.868589561115314), + Offset(26.240346174357384, 10.036445688183749), + Offset(32.092904541992695, 12.402375412430613), + Offset(37.5629202849435, 19.994105175585858), + Offset(37.84506858847438, 26.88341391070376), + Offset(36.22993865924664, 31.101309765885755), + Offset(34.329074659673786, 33.659721355964926), + Offset(32.57154081283703, 35.24849714823581), + Offset(31.058198425745676, 36.25486984764837), + Offset(29.7970117827669, 36.89940519521973), + Offset(28.766770056534085, 37.31457484218441), + Offset(27.940320681241946, 37.58211592238032), + Offset(27.291237065301104, 37.7538270521331), + Offset(26.796055060387058, 37.862975008968455), + Offset(26.434852020780554, 37.93095458455382), + Offset(26.190848814107472, 37.971405851728875), + Offset(26.049911912085946, 37.99277889315371), + Offset(26.00036296922149, 37.999948142452794), + Offset(26.0, 38.0), + Offset(26.0, 38.0), + ], + <Offset>[ + Offset(22.0, 10.0), + Offset(22.2955325934749, 9.960954773913809), + Offset(23.449328584561673, 9.868589561115314), + Offset(26.240346174357384, 10.036445688183749), + Offset(32.092904541992695, 12.402375412430613), + Offset(37.5629202849435, 19.994105175585858), + Offset(37.84506858847438, 26.88341391070376), + Offset(36.22993865924664, 31.101309765885755), + Offset(34.329074659673786, 33.659721355964926), + Offset(32.57154081283703, 35.24849714823581), + Offset(31.058198425745676, 36.25486984764837), + Offset(29.7970117827669, 36.89940519521973), + Offset(28.766770056534085, 37.31457484218441), + Offset(27.940320681241946, 37.58211592238032), + Offset(27.291237065301104, 37.7538270521331), + Offset(26.796055060387058, 37.862975008968455), + Offset(26.434852020780554, 37.93095458455382), + Offset(26.190848814107472, 37.971405851728875), + Offset(26.049911912085946, 37.99277889315371), + Offset(26.00036296922149, 37.999948142452794), + Offset(26.0, 38.0), + Offset(26.0, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(22.0, 10.0), + Offset(22.2955325934749, 9.960954773913809), + Offset(23.449328584561673, 9.868589561115314), + Offset(26.240346174357384, 10.036445688183749), + Offset(32.092904541992695, 12.402375412430613), + Offset(37.5629202849435, 19.994105175585858), + Offset(37.84506858847438, 26.88341391070376), + Offset(36.22993865924664, 31.101309765885755), + Offset(34.329074659673786, 33.659721355964926), + Offset(32.57154081283703, 35.24849714823581), + Offset(31.058198425745676, 36.25486984764837), + Offset(29.7970117827669, 36.89940519521973), + Offset(28.766770056534085, 37.31457484218441), + Offset(27.940320681241946, 37.58211592238032), + Offset(27.291237065301104, 37.7538270521331), + Offset(26.796055060387058, 37.862975008968455), + Offset(26.434852020780554, 37.93095458455382), + Offset(26.190848814107472, 37.971405851728875), + Offset(26.049911912085946, 37.99277889315371), + Offset(26.00036296922149, 37.999948142452794), + Offset(26.0, 38.0), + Offset(26.0, 38.0), + ], + <Offset>[ + Offset(26.0, 10.0), + Offset(26.29464395304004, 10.045265709130227), + Offset(27.428150364066923, 10.27965798234797), + Offset(30.06052753469164, 11.222284789476467), + Offset(35.01652324483241, 15.132293667691345), + Offset(38.14205402438172, 23.951958648346604), + Offset(36.48390994993835, 30.644696559048437), + Offset(33.75237437842877, 34.24164019983938), + Offset(31.211189693616653, 36.16547340643499), + Offset(29.07909997881752, 37.198588689900745), + Offset(27.344506931374305, 37.74097061295122), + Offset(25.953297856794702, 38.00659228658567), + Offset(24.848018298461085, 38.116687464326574), + Offset(23.97971539572578, 38.142121076232854), + Offset(23.308516008091793, 38.12522034833208), + Offset(22.802579855460408, 38.09135142551809), + Offset(22.436790656274265, 38.05547496699022), + Offset(22.191221223059088, 38.025987285609816), + Offset(22.049937345519467, 38.00704307281163), + Offset(22.000362970565853, 38.0000518481367), + Offset(22.0, 38.0), + Offset(22.0, 38.0), + ], + <Offset>[ + Offset(26.0, 10.0), + Offset(26.29464395304004, 10.045265709130227), + Offset(27.428150364066923, 10.27965798234797), + Offset(30.06052753469164, 11.222284789476467), + Offset(35.01652324483241, 15.132293667691345), + Offset(38.14205402438172, 23.951958648346604), + Offset(36.48390994993835, 30.644696559048437), + Offset(33.75237437842877, 34.24164019983938), + Offset(31.211189693616653, 36.16547340643499), + Offset(29.07909997881752, 37.198588689900745), + Offset(27.344506931374305, 37.74097061295122), + Offset(25.953297856794702, 38.00659228658567), + Offset(24.848018298461085, 38.116687464326574), + Offset(23.97971539572578, 38.142121076232854), + Offset(23.308516008091793, 38.12522034833208), + Offset(22.802579855460408, 38.09135142551809), + Offset(22.436790656274265, 38.05547496699022), + Offset(22.191221223059088, 38.025987285609816), + Offset(22.049937345519467, 38.00704307281163), + Offset(22.000362970565853, 38.0000518481367), + Offset(22.0, 38.0), + Offset(22.0, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.0, 10.0), + Offset(26.29464395304004, 10.045265709130227), + Offset(27.428150364066923, 10.27965798234797), + Offset(30.06052753469164, 11.222284789476467), + Offset(35.01652324483241, 15.132293667691345), + Offset(38.14205402438172, 23.951958648346604), + Offset(36.48390994993835, 30.644696559048437), + Offset(33.75237437842877, 34.24164019983938), + Offset(31.211189693616653, 36.16547340643499), + Offset(29.07909997881752, 37.198588689900745), + Offset(27.344506931374305, 37.74097061295122), + Offset(25.953297856794702, 38.00659228658567), + Offset(24.848018298461085, 38.116687464326574), + Offset(23.97971539572578, 38.142121076232854), + Offset(23.308516008091793, 38.12522034833208), + Offset(22.802579855460408, 38.09135142551809), + Offset(22.436790656274265, 38.05547496699022), + Offset(22.191221223059088, 38.025987285609816), + Offset(22.049937345519467, 38.00704307281163), + Offset(22.000362970565853, 38.0000518481367), + Offset(22.0, 38.0), + Offset(22.0, 38.0), + ], + <Offset>[ + Offset(26.0, 38.0), + Offset(25.7044674065251, 38.0390452260862), + Offset(24.550671415438327, 38.13141043888469), + Offset(21.759653825642616, 37.96355431181625), + Offset(15.907095458007305, 35.597624587569385), + Offset(10.437079715056495, 28.005894824414142), + Offset(10.154931411525617, 21.11658608929624), + Offset(11.770061340753355, 16.898690234114245), + Offset(13.670925340326216, 14.340278644035072), + Offset(15.428459187162979, 12.751502851764188), + Offset(16.941801574254317, 11.74513015235163), + Offset(18.20298821723309, 11.100594804780274), + Offset(19.233229943465915, 10.68542515781559), + Offset(20.059679318758054, 10.41788407761968), + Offset(20.708762934698896, 10.246172947866903), + Offset(21.203944939612935, 10.137024991031547), + Offset(21.565147979219454, 10.069045415446187), + Offset(21.809151185892528, 10.028594148271123), + Offset(21.950088087914054, 10.007221106846284), + Offset(21.99963703077851, 10.000051857547207), + Offset(22.0, 10.0), + Offset(22.0, 10.0), + ], + <Offset>[ + Offset(26.0, 38.0), + Offset(25.7044674065251, 38.0390452260862), + Offset(24.550671415438327, 38.13141043888469), + Offset(21.759653825642616, 37.96355431181625), + Offset(15.907095458007305, 35.597624587569385), + Offset(10.437079715056495, 28.005894824414142), + Offset(10.154931411525617, 21.11658608929624), + Offset(11.770061340753355, 16.898690234114245), + Offset(13.670925340326216, 14.340278644035072), + Offset(15.428459187162979, 12.751502851764188), + Offset(16.941801574254317, 11.74513015235163), + Offset(18.20298821723309, 11.100594804780274), + Offset(19.233229943465915, 10.68542515781559), + Offset(20.059679318758054, 10.41788407761968), + Offset(20.708762934698896, 10.246172947866903), + Offset(21.203944939612935, 10.137024991031547), + Offset(21.565147979219454, 10.069045415446187), + Offset(21.809151185892528, 10.028594148271123), + Offset(21.950088087914054, 10.007221106846284), + Offset(21.99963703077851, 10.000051857547207), + Offset(22.0, 10.0), + Offset(22.0, 10.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 0.857142857143, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(38.0, 22.0), + Offset(38.039045226086195, 22.295532593474903), + Offset(38.131410438884686, 23.449328584561677), + Offset(37.96355431181625, 26.240346174357384), + Offset(35.597624587569385, 32.092904541992695), + Offset(28.005894824414142, 37.5629202849435), + Offset(21.11658608929624, 37.84506858847438), + Offset(16.898690234114245, 36.22993865924664), + Offset(14.340278644035072, 34.329074659673786), + Offset(12.751502851764192, 32.57154081283703), + Offset(11.745130152351626, 31.05819842574568), + Offset(11.10059480478027, 29.797011782766905), + Offset(10.68542515781559, 28.766770056534085), + Offset(10.41788407761968, 27.940320681241946), + Offset(10.246172947866903, 27.291237065301104), + Offset(10.137024991031543, 26.79605506038706), + Offset(10.06904541544619, 26.434852020780554), + Offset(10.028594148271123, 26.190848814107472), + Offset(10.007221106846284, 26.049911912085946), + Offset(10.000051857547207, 26.00036296922149), + Offset(10.0, 26.0), + Offset(10.0, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.0, 22.0), + Offset(38.039045226086195, 22.295532593474903), + Offset(38.131410438884686, 23.449328584561677), + Offset(37.96355431181625, 26.240346174357384), + Offset(35.597624587569385, 32.092904541992695), + Offset(28.005894824414142, 37.5629202849435), + Offset(21.11658608929624, 37.84506858847438), + Offset(16.898690234114245, 36.22993865924664), + Offset(14.340278644035072, 34.329074659673786), + Offset(12.751502851764192, 32.57154081283703), + Offset(11.745130152351626, 31.05819842574568), + Offset(11.10059480478027, 29.797011782766905), + Offset(10.68542515781559, 28.766770056534085), + Offset(10.41788407761968, 27.940320681241946), + Offset(10.246172947866903, 27.291237065301104), + Offset(10.137024991031543, 26.79605506038706), + Offset(10.06904541544619, 26.434852020780554), + Offset(10.028594148271123, 26.190848814107472), + Offset(10.007221106846284, 26.049911912085946), + Offset(10.000051857547207, 26.00036296922149), + Offset(10.0, 26.0), + Offset(10.0, 26.0), + ], + <Offset>[ + Offset(38.0, 26.0), + Offset(37.95473429086978, 26.294643953040044), + Offset(37.72034201765203, 27.428150364066923), + Offset(36.77771521052353, 30.06052753469164), + Offset(32.86770633230866, 35.01652324483241), + Offset(24.048041351653396, 38.14205402438172), + Offset(17.355303440951563, 36.48390994993835), + Offset(13.758359800160616, 33.75237437842877), + Offset(11.83452659356501, 31.211189693616653), + Offset(10.801411310099256, 29.079099978817517), + Offset(10.259029387048772, 27.34450693137431), + Offset(9.993407713414326, 25.953297856794705), + Offset(9.883312535673422, 24.848018298461085), + Offset(9.857878923767148, 23.97971539572578), + Offset(9.874779651667918, 23.308516008091793), + Offset(9.908648574481903, 22.80257985546041), + Offset(9.94452503300979, 22.436790656274262), + Offset(9.974012714390186, 22.191221223059088), + Offset(9.992956927188366, 22.049937345519467), + Offset(9.999948151863302, 22.000362970565853), + Offset(10.0, 22.0), + Offset(10.0, 22.0), + ], + <Offset>[ + Offset(38.0, 26.0), + Offset(37.95473429086978, 26.294643953040044), + Offset(37.72034201765203, 27.428150364066923), + Offset(36.77771521052353, 30.06052753469164), + Offset(32.86770633230866, 35.01652324483241), + Offset(24.048041351653396, 38.14205402438172), + Offset(17.355303440951563, 36.48390994993835), + Offset(13.758359800160616, 33.75237437842877), + Offset(11.83452659356501, 31.211189693616653), + Offset(10.801411310099256, 29.079099978817517), + Offset(10.259029387048772, 27.34450693137431), + Offset(9.993407713414326, 25.953297856794705), + Offset(9.883312535673422, 24.848018298461085), + Offset(9.857878923767148, 23.97971539572578), + Offset(9.874779651667918, 23.308516008091793), + Offset(9.908648574481903, 22.80257985546041), + Offset(9.94452503300979, 22.436790656274262), + Offset(9.974012714390186, 22.191221223059088), + Offset(9.992956927188366, 22.049937345519467), + Offset(9.999948151863302, 22.000362970565853), + Offset(10.0, 22.0), + Offset(10.0, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.0, 26.0), + Offset(37.95473429086978, 26.294643953040044), + Offset(37.72034201765203, 27.428150364066923), + Offset(36.77771521052353, 30.06052753469164), + Offset(32.86770633230866, 35.01652324483241), + Offset(24.048041351653396, 38.14205402438172), + Offset(17.355303440951563, 36.48390994993835), + Offset(13.758359800160616, 33.75237437842877), + Offset(11.83452659356501, 31.211189693616653), + Offset(10.801411310099256, 29.079099978817517), + Offset(10.259029387048772, 27.34450693137431), + Offset(9.993407713414326, 25.953297856794705), + Offset(9.883312535673422, 24.848018298461085), + Offset(9.857878923767148, 23.97971539572578), + Offset(9.874779651667918, 23.308516008091793), + Offset(9.908648574481903, 22.80257985546041), + Offset(9.94452503300979, 22.436790656274262), + Offset(9.974012714390186, 22.191221223059088), + Offset(9.992956927188366, 22.049937345519467), + Offset(9.999948151863302, 22.000362970565853), + Offset(10.0, 22.0), + Offset(10.0, 22.0), + ], + <Offset>[ + Offset(10.0, 26.0), + Offset(9.960954773913805, 25.704467406525104), + Offset(9.86858956111531, 24.55067141543833), + Offset(10.036445688183749, 21.759653825642616), + Offset(12.402375412430613, 15.907095458007305), + Offset(19.994105175585858, 10.437079715056495), + Offset(26.88341391070376, 10.154931411525617), + Offset(31.101309765885755, 11.770061340753355), + Offset(33.659721355964926, 13.670925340326216), + Offset(35.24849714823581, 15.428459187162975), + Offset(36.254869847648365, 16.94180157425432), + Offset(36.89940519521972, 18.202988217233095), + Offset(37.31457484218441, 19.233229943465915), + Offset(37.58211592238032, 20.059679318758054), + Offset(37.7538270521331, 20.708762934698896), + Offset(37.86297500896845, 21.20394493961294), + Offset(37.93095458455382, 21.565147979219446), + Offset(37.971405851728875, 21.809151185892528), + Offset(37.99277889315371, 21.950088087914054), + Offset(37.999948142452794, 21.99963703077851), + Offset(38.0, 22.0), + Offset(38.0, 22.0), + ], + <Offset>[ + Offset(10.0, 26.0), + Offset(9.960954773913805, 25.704467406525104), + Offset(9.86858956111531, 24.55067141543833), + Offset(10.036445688183749, 21.759653825642616), + Offset(12.402375412430613, 15.907095458007305), + Offset(19.994105175585858, 10.437079715056495), + Offset(26.88341391070376, 10.154931411525617), + Offset(31.101309765885755, 11.770061340753355), + Offset(33.659721355964926, 13.670925340326216), + Offset(35.24849714823581, 15.428459187162975), + Offset(36.254869847648365, 16.94180157425432), + Offset(36.89940519521972, 18.202988217233095), + Offset(37.31457484218441, 19.233229943465915), + Offset(37.58211592238032, 20.059679318758054), + Offset(37.7538270521331, 20.708762934698896), + Offset(37.86297500896845, 21.20394493961294), + Offset(37.93095458455382, 21.565147979219446), + Offset(37.971405851728875, 21.809151185892528), + Offset(37.99277889315371, 21.950088087914054), + Offset(37.999948142452794, 21.99963703077851), + Offset(38.0, 22.0), + Offset(38.0, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.0, 26.0), + Offset(9.960954773913805, 25.704467406525104), + Offset(9.86858956111531, 24.55067141543833), + Offset(10.036445688183749, 21.759653825642616), + Offset(12.402375412430613, 15.907095458007305), + Offset(19.994105175585858, 10.437079715056495), + Offset(26.88341391070376, 10.154931411525617), + Offset(31.101309765885755, 11.770061340753355), + Offset(33.659721355964926, 13.670925340326216), + Offset(35.24849714823581, 15.428459187162975), + Offset(36.254869847648365, 16.94180157425432), + Offset(36.89940519521972, 18.202988217233095), + Offset(37.31457484218441, 19.233229943465915), + Offset(37.58211592238032, 20.059679318758054), + Offset(37.7538270521331, 20.708762934698896), + Offset(37.86297500896845, 21.20394493961294), + Offset(37.93095458455382, 21.565147979219446), + Offset(37.971405851728875, 21.809151185892528), + Offset(37.99277889315371, 21.950088087914054), + Offset(37.999948142452794, 21.99963703077851), + Offset(38.0, 22.0), + Offset(38.0, 22.0), + ], + <Offset>[ + Offset(10.0, 22.0), + Offset(10.045265709130224, 21.705356046959963), + Offset(10.279657982347967, 20.571849635933084), + Offset(11.222284789476467, 17.93947246530836), + Offset(15.132293667691345, 12.983476755167583), + Offset(23.951958648346604, 9.857945975618275), + Offset(30.644696559048437, 11.516090050061646), + Offset(34.24164019983938, 14.247625621571231), + Offset(36.16547340643499, 16.788810306383347), + Offset(37.19858868990075, 18.920900021182483), + Offset(37.74097061295122, 20.65549306862569), + Offset(38.006592286585665, 22.046702143205295), + Offset(38.116687464326574, 23.151981701538915), + Offset(38.142121076232854, 24.02028460427422), + Offset(38.12522034833208, 24.691483991908207), + Offset(38.09135142551809, 25.19742014453959), + Offset(38.05547496699022, 25.563209343725738), + Offset(38.025987285609816, 25.808778776940912), + Offset(38.00704307281163, 25.950062654480533), + Offset(38.0000518481367, 25.999637029434147), + Offset(38.0, 26.0), + Offset(38.0, 26.0), + ], + <Offset>[ + Offset(10.0, 22.0), + Offset(10.045265709130224, 21.705356046959963), + Offset(10.279657982347967, 20.571849635933084), + Offset(11.222284789476467, 17.93947246530836), + Offset(15.132293667691345, 12.983476755167583), + Offset(23.951958648346604, 9.857945975618275), + Offset(30.644696559048437, 11.516090050061646), + Offset(34.24164019983938, 14.247625621571231), + Offset(36.16547340643499, 16.788810306383347), + Offset(37.19858868990075, 18.920900021182483), + Offset(37.74097061295122, 20.65549306862569), + Offset(38.006592286585665, 22.046702143205295), + Offset(38.116687464326574, 23.151981701538915), + Offset(38.142121076232854, 24.02028460427422), + Offset(38.12522034833208, 24.691483991908207), + Offset(38.09135142551809, 25.19742014453959), + Offset(38.05547496699022, 25.563209343725738), + Offset(38.025987285609816, 25.808778776940912), + Offset(38.00704307281163, 25.950062654480533), + Offset(38.0000518481367, 25.999637029434147), + Offset(38.0, 26.0), + Offset(38.0, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.0, 22.0), + Offset(10.045265709130224, 21.705356046959963), + Offset(10.279657982347967, 20.571849635933084), + Offset(11.222284789476467, 17.93947246530836), + Offset(15.132293667691345, 12.983476755167583), + Offset(23.951958648346604, 9.857945975618275), + Offset(30.644696559048437, 11.516090050061646), + Offset(34.24164019983938, 14.247625621571231), + Offset(36.16547340643499, 16.788810306383347), + Offset(37.19858868990075, 18.920900021182483), + Offset(37.74097061295122, 20.65549306862569), + Offset(38.006592286585665, 22.046702143205295), + Offset(38.116687464326574, 23.151981701538915), + Offset(38.142121076232854, 24.02028460427422), + Offset(38.12522034833208, 24.691483991908207), + Offset(38.09135142551809, 25.19742014453959), + Offset(38.05547496699022, 25.563209343725738), + Offset(38.025987285609816, 25.808778776940912), + Offset(38.00704307281163, 25.950062654480533), + Offset(38.0000518481367, 25.999637029434147), + Offset(38.0, 26.0), + Offset(38.0, 26.0), + ], + <Offset>[ + Offset(38.0, 22.0), + Offset(38.039045226086195, 22.295532593474903), + Offset(38.131410438884686, 23.449328584561677), + Offset(37.96355431181625, 26.240346174357384), + Offset(35.597624587569385, 32.092904541992695), + Offset(28.005894824414142, 37.5629202849435), + Offset(21.11658608929624, 37.84506858847438), + Offset(16.898690234114245, 36.22993865924664), + Offset(14.340278644035072, 34.329074659673786), + Offset(12.751502851764192, 32.57154081283703), + Offset(11.745130152351626, 31.05819842574568), + Offset(11.10059480478027, 29.797011782766905), + Offset(10.68542515781559, 28.766770056534085), + Offset(10.41788407761968, 27.940320681241946), + Offset(10.246172947866903, 27.291237065301104), + Offset(10.137024991031543, 26.79605506038706), + Offset(10.06904541544619, 26.434852020780554), + Offset(10.028594148271123, 26.190848814107472), + Offset(10.007221106846284, 26.049911912085946), + Offset(10.000051857547207, 26.00036296922149), + Offset(10.0, 26.0), + Offset(10.0, 26.0), + ], + <Offset>[ + Offset(38.0, 22.0), + Offset(38.039045226086195, 22.295532593474903), + Offset(38.131410438884686, 23.449328584561677), + Offset(37.96355431181625, 26.240346174357384), + Offset(35.597624587569385, 32.092904541992695), + Offset(28.005894824414142, 37.5629202849435), + Offset(21.11658608929624, 37.84506858847438), + Offset(16.898690234114245, 36.22993865924664), + Offset(14.340278644035072, 34.329074659673786), + Offset(12.751502851764192, 32.57154081283703), + Offset(11.745130152351626, 31.05819842574568), + Offset(11.10059480478027, 29.797011782766905), + Offset(10.68542515781559, 28.766770056534085), + Offset(10.41788407761968, 27.940320681241946), + Offset(10.246172947866903, 27.291237065301104), + Offset(10.137024991031543, 26.79605506038706), + Offset(10.06904541544619, 26.434852020780554), + Offset(10.028594148271123, 26.190848814107472), + Offset(10.007221106846284, 26.049911912085946), + Offset(10.000051857547207, 26.00036296922149), + Offset(10.0, 26.0), + Offset(10.0, 26.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 0.857142857143, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(26.0, 38.0), + Offset(25.7044674065251, 38.0390452260862), + Offset(24.550671415438327, 38.13141043888469), + Offset(21.759653825642616, 37.96355431181625), + Offset(15.907095458007305, 35.597624587569385), + Offset(10.437079715056495, 28.005894824414142), + Offset(10.154931411525617, 21.11658608929624), + Offset(11.770061340753355, 16.898690234114245), + Offset(13.670925340326216, 14.340278644035072), + Offset(15.428459187162979, 12.751502851764188), + Offset(16.941801574254317, 11.74513015235163), + Offset(18.20298821723309, 11.100594804780274), + Offset(19.233229943465915, 10.68542515781559), + Offset(20.059679318758054, 10.41788407761968), + Offset(20.708762934698896, 10.246172947866903), + Offset(21.203944939612935, 10.137024991031547), + Offset(21.565147979219454, 10.069045415446187), + Offset(21.809151185892528, 10.028594148271123), + Offset(21.950088087914054, 10.007221106846284), + Offset(21.99963703077851, 10.000051857547207), + Offset(22.0, 10.0), + Offset(22.0, 10.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.0, 38.0), + Offset(25.7044674065251, 38.0390452260862), + Offset(24.550671415438327, 38.13141043888469), + Offset(21.759653825642616, 37.96355431181625), + Offset(15.907095458007305, 35.597624587569385), + Offset(10.437079715056495, 28.005894824414142), + Offset(10.154931411525617, 21.11658608929624), + Offset(11.770061340753355, 16.898690234114245), + Offset(13.670925340326216, 14.340278644035072), + Offset(15.428459187162979, 12.751502851764188), + Offset(16.941801574254317, 11.74513015235163), + Offset(18.20298821723309, 11.100594804780274), + Offset(19.233229943465915, 10.68542515781559), + Offset(20.059679318758054, 10.41788407761968), + Offset(20.708762934698896, 10.246172947866903), + Offset(21.203944939612935, 10.137024991031547), + Offset(21.565147979219454, 10.069045415446187), + Offset(21.809151185892528, 10.028594148271123), + Offset(21.950088087914054, 10.007221106846284), + Offset(21.99963703077851, 10.000051857547207), + Offset(22.0, 10.0), + Offset(22.0, 10.0), + ], + <Offset>[ + Offset(22.0, 38.0), + Offset(21.70535604695996, 37.95473429086978), + Offset(20.571849635933077, 37.72034201765204), + Offset(17.93947246530836, 36.77771521052353), + Offset(12.983476755167583, 32.86770633230866), + Offset(9.857945975618275, 24.048041351653396), + Offset(11.516090050061646, 17.355303440951563), + Offset(14.247625621571231, 13.758359800160616), + Offset(16.788810306383347, 11.83452659356501), + Offset(18.920900021182486, 10.801411310099253), + Offset(20.655493068625688, 10.259029387048775), + Offset(22.04670214320529, 9.99340771341433), + Offset(23.151981701538915, 9.883312535673422), + Offset(24.02028460427422, 9.857878923767148), + Offset(24.691483991908207, 9.874779651667918), + Offset(25.197420144539585, 9.908648574481907), + Offset(25.56320934372574, 9.944525033009786), + Offset(25.808778776940912, 9.974012714390186), + Offset(25.950062654480533, 9.992956927188366), + Offset(25.999637029434147, 9.999948151863302), + Offset(26.0, 10.0), + Offset(26.0, 10.0), + ], + <Offset>[ + Offset(22.0, 38.0), + Offset(21.70535604695996, 37.95473429086978), + Offset(20.571849635933077, 37.72034201765204), + Offset(17.93947246530836, 36.77771521052353), + Offset(12.983476755167583, 32.86770633230866), + Offset(9.857945975618275, 24.048041351653396), + Offset(11.516090050061646, 17.355303440951563), + Offset(14.247625621571231, 13.758359800160616), + Offset(16.788810306383347, 11.83452659356501), + Offset(18.920900021182486, 10.801411310099253), + Offset(20.655493068625688, 10.259029387048775), + Offset(22.04670214320529, 9.99340771341433), + Offset(23.151981701538915, 9.883312535673422), + Offset(24.02028460427422, 9.857878923767148), + Offset(24.691483991908207, 9.874779651667918), + Offset(25.197420144539585, 9.908648574481907), + Offset(25.56320934372574, 9.944525033009786), + Offset(25.808778776940912, 9.974012714390186), + Offset(25.950062654480533, 9.992956927188366), + Offset(25.999637029434147, 9.999948151863302), + Offset(26.0, 10.0), + Offset(26.0, 10.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(22.0, 38.0), + Offset(21.70535604695996, 37.95473429086978), + Offset(20.571849635933077, 37.72034201765204), + Offset(17.93947246530836, 36.77771521052353), + Offset(12.983476755167583, 32.86770633230866), + Offset(9.857945975618275, 24.048041351653396), + Offset(11.516090050061646, 17.355303440951563), + Offset(14.247625621571231, 13.758359800160616), + Offset(16.788810306383347, 11.83452659356501), + Offset(18.920900021182486, 10.801411310099253), + Offset(20.655493068625688, 10.259029387048775), + Offset(22.04670214320529, 9.99340771341433), + Offset(23.151981701538915, 9.883312535673422), + Offset(24.02028460427422, 9.857878923767148), + Offset(24.691483991908207, 9.874779651667918), + Offset(25.197420144539585, 9.908648574481907), + Offset(25.56320934372574, 9.944525033009786), + Offset(25.808778776940912, 9.974012714390186), + Offset(25.950062654480533, 9.992956927188366), + Offset(25.999637029434147, 9.999948151863302), + Offset(26.0, 10.0), + Offset(26.0, 10.0), + ], + <Offset>[ + Offset(22.0, 10.0), + Offset(22.2955325934749, 9.960954773913809), + Offset(23.449328584561673, 9.868589561115314), + Offset(26.240346174357384, 10.036445688183749), + Offset(32.092904541992695, 12.402375412430613), + Offset(37.5629202849435, 19.994105175585858), + Offset(37.84506858847438, 26.88341391070376), + Offset(36.22993865924664, 31.101309765885755), + Offset(34.329074659673786, 33.659721355964926), + Offset(32.57154081283703, 35.24849714823581), + Offset(31.058198425745676, 36.25486984764837), + Offset(29.7970117827669, 36.89940519521973), + Offset(28.766770056534085, 37.31457484218441), + Offset(27.940320681241946, 37.58211592238032), + Offset(27.291237065301104, 37.7538270521331), + Offset(26.796055060387058, 37.862975008968455), + Offset(26.434852020780554, 37.93095458455382), + Offset(26.190848814107472, 37.971405851728875), + Offset(26.049911912085946, 37.99277889315371), + Offset(26.00036296922149, 37.999948142452794), + Offset(26.0, 38.0), + Offset(26.0, 38.0), + ], + <Offset>[ + Offset(22.0, 10.0), + Offset(22.2955325934749, 9.960954773913809), + Offset(23.449328584561673, 9.868589561115314), + Offset(26.240346174357384, 10.036445688183749), + Offset(32.092904541992695, 12.402375412430613), + Offset(37.5629202849435, 19.994105175585858), + Offset(37.84506858847438, 26.88341391070376), + Offset(36.22993865924664, 31.101309765885755), + Offset(34.329074659673786, 33.659721355964926), + Offset(32.57154081283703, 35.24849714823581), + Offset(31.058198425745676, 36.25486984764837), + Offset(29.7970117827669, 36.89940519521973), + Offset(28.766770056534085, 37.31457484218441), + Offset(27.940320681241946, 37.58211592238032), + Offset(27.291237065301104, 37.7538270521331), + Offset(26.796055060387058, 37.862975008968455), + Offset(26.434852020780554, 37.93095458455382), + Offset(26.190848814107472, 37.971405851728875), + Offset(26.049911912085946, 37.99277889315371), + Offset(26.00036296922149, 37.999948142452794), + Offset(26.0, 38.0), + Offset(26.0, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(22.0, 10.0), + Offset(22.2955325934749, 9.960954773913809), + Offset(23.449328584561673, 9.868589561115314), + Offset(26.240346174357384, 10.036445688183749), + Offset(32.092904541992695, 12.402375412430613), + Offset(37.5629202849435, 19.994105175585858), + Offset(37.84506858847438, 26.88341391070376), + Offset(36.22993865924664, 31.101309765885755), + Offset(34.329074659673786, 33.659721355964926), + Offset(32.57154081283703, 35.24849714823581), + Offset(31.058198425745676, 36.25486984764837), + Offset(29.7970117827669, 36.89940519521973), + Offset(28.766770056534085, 37.31457484218441), + Offset(27.940320681241946, 37.58211592238032), + Offset(27.291237065301104, 37.7538270521331), + Offset(26.796055060387058, 37.862975008968455), + Offset(26.434852020780554, 37.93095458455382), + Offset(26.190848814107472, 37.971405851728875), + Offset(26.049911912085946, 37.99277889315371), + Offset(26.00036296922149, 37.999948142452794), + Offset(26.0, 38.0), + Offset(26.0, 38.0), + ], + <Offset>[ + Offset(26.0, 10.0), + Offset(26.29464395304004, 10.045265709130227), + Offset(27.428150364066923, 10.27965798234797), + Offset(30.06052753469164, 11.222284789476467), + Offset(35.01652324483241, 15.132293667691345), + Offset(38.14205402438172, 23.951958648346604), + Offset(36.48390994993835, 30.644696559048437), + Offset(33.75237437842877, 34.24164019983938), + Offset(31.211189693616653, 36.16547340643499), + Offset(29.07909997881752, 37.198588689900745), + Offset(27.344506931374305, 37.74097061295122), + Offset(25.953297856794702, 38.00659228658567), + Offset(24.848018298461085, 38.116687464326574), + Offset(23.97971539572578, 38.142121076232854), + Offset(23.308516008091793, 38.12522034833208), + Offset(22.802579855460408, 38.09135142551809), + Offset(22.436790656274265, 38.05547496699022), + Offset(22.191221223059088, 38.025987285609816), + Offset(22.049937345519467, 38.00704307281163), + Offset(22.000362970565853, 38.0000518481367), + Offset(22.0, 38.0), + Offset(22.0, 38.0), + ], + <Offset>[ + Offset(26.0, 10.0), + Offset(26.29464395304004, 10.045265709130227), + Offset(27.428150364066923, 10.27965798234797), + Offset(30.06052753469164, 11.222284789476467), + Offset(35.01652324483241, 15.132293667691345), + Offset(38.14205402438172, 23.951958648346604), + Offset(36.48390994993835, 30.644696559048437), + Offset(33.75237437842877, 34.24164019983938), + Offset(31.211189693616653, 36.16547340643499), + Offset(29.07909997881752, 37.198588689900745), + Offset(27.344506931374305, 37.74097061295122), + Offset(25.953297856794702, 38.00659228658567), + Offset(24.848018298461085, 38.116687464326574), + Offset(23.97971539572578, 38.142121076232854), + Offset(23.308516008091793, 38.12522034833208), + Offset(22.802579855460408, 38.09135142551809), + Offset(22.436790656274265, 38.05547496699022), + Offset(22.191221223059088, 38.025987285609816), + Offset(22.049937345519467, 38.00704307281163), + Offset(22.000362970565853, 38.0000518481367), + Offset(22.0, 38.0), + Offset(22.0, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.0, 10.0), + Offset(26.29464395304004, 10.045265709130227), + Offset(27.428150364066923, 10.27965798234797), + Offset(30.06052753469164, 11.222284789476467), + Offset(35.01652324483241, 15.132293667691345), + Offset(38.14205402438172, 23.951958648346604), + Offset(36.48390994993835, 30.644696559048437), + Offset(33.75237437842877, 34.24164019983938), + Offset(31.211189693616653, 36.16547340643499), + Offset(29.07909997881752, 37.198588689900745), + Offset(27.344506931374305, 37.74097061295122), + Offset(25.953297856794702, 38.00659228658567), + Offset(24.848018298461085, 38.116687464326574), + Offset(23.97971539572578, 38.142121076232854), + Offset(23.308516008091793, 38.12522034833208), + Offset(22.802579855460408, 38.09135142551809), + Offset(22.436790656274265, 38.05547496699022), + Offset(22.191221223059088, 38.025987285609816), + Offset(22.049937345519467, 38.00704307281163), + Offset(22.000362970565853, 38.0000518481367), + Offset(22.0, 38.0), + Offset(22.0, 38.0), + ], + <Offset>[ + Offset(26.0, 38.0), + Offset(25.7044674065251, 38.0390452260862), + Offset(24.550671415438327, 38.13141043888469), + Offset(21.759653825642616, 37.96355431181625), + Offset(15.907095458007305, 35.597624587569385), + Offset(10.437079715056495, 28.005894824414142), + Offset(10.154931411525617, 21.11658608929624), + Offset(11.770061340753355, 16.898690234114245), + Offset(13.670925340326216, 14.340278644035072), + Offset(15.428459187162979, 12.751502851764188), + Offset(16.941801574254317, 11.74513015235163), + Offset(18.20298821723309, 11.100594804780274), + Offset(19.233229943465915, 10.68542515781559), + Offset(20.059679318758054, 10.41788407761968), + Offset(20.708762934698896, 10.246172947866903), + Offset(21.203944939612935, 10.137024991031547), + Offset(21.565147979219454, 10.069045415446187), + Offset(21.809151185892528, 10.028594148271123), + Offset(21.950088087914054, 10.007221106846284), + Offset(21.99963703077851, 10.000051857547207), + Offset(22.0, 10.0), + Offset(22.0, 10.0), + ], + <Offset>[ + Offset(26.0, 38.0), + Offset(25.7044674065251, 38.0390452260862), + Offset(24.550671415438327, 38.13141043888469), + Offset(21.759653825642616, 37.96355431181625), + Offset(15.907095458007305, 35.597624587569385), + Offset(10.437079715056495, 28.005894824414142), + Offset(10.154931411525617, 21.11658608929624), + Offset(11.770061340753355, 16.898690234114245), + Offset(13.670925340326216, 14.340278644035072), + Offset(15.428459187162979, 12.751502851764188), + Offset(16.941801574254317, 11.74513015235163), + Offset(18.20298821723309, 11.100594804780274), + Offset(19.233229943465915, 10.68542515781559), + Offset(20.059679318758054, 10.41788407761968), + Offset(20.708762934698896, 10.246172947866903), + Offset(21.203944939612935, 10.137024991031547), + Offset(21.565147979219454, 10.069045415446187), + Offset(21.809151185892528, 10.028594148271123), + Offset(21.950088087914054, 10.007221106846284), + Offset(21.99963703077851, 10.000051857547207), + Offset(22.0, 10.0), + Offset(22.0, 10.0), + ], + ), + _PathClose( + ), + ], + ), + ], +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/arrow_menu.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/arrow_menu.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..549c8703d0e032364c3dcbcf17823e66aacff1a4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/arrow_menu.g.dart @@ -0,0 +1,1027 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$arrow_menu = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(39.94921875, 22.0), + Offset(39.999299444085175, 22.321134814951655), + Offset(40.123697128128484, 23.4571221977224), + Offset(40.127941008338254, 25.772984385261328), + Offset(39.36673145070893, 29.679631356759792), + Offset(36.03000494036236, 35.505984938867314), + Offset(30.483797891740366, 39.621714579092405), + Offset(23.719442126984134, 41.17597729654657), + Offset(17.808469902722187, 40.26388356552361), + Offset(13.571377486425117, 38.15001206462978), + Offset(10.73996518894534, 35.74540806580379), + Offset(8.908677157504997, 33.47648684184537), + Offset(7.746937054898215, 31.506333856475468), + Offset(7.021336564573183, 29.876779670456198), + Offset(6.575233382277915, 28.57846974488041), + Offset(6.306002369153553, 27.58317306758941), + Offset(6.147597126684428, 26.85785338221681), + Offset(6.058558318339831, 26.3706514388743), + Offset(6.013954859968965, 26.093012124442712), + Offset(6.000028695609693, 26.000194701816614), + Offset(6.0, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(39.94921875, 22.0), + Offset(39.999299444085175, 22.321134814951655), + Offset(40.123697128128484, 23.4571221977224), + Offset(40.127941008338254, 25.772984385261328), + Offset(39.36673145070893, 29.679631356759792), + Offset(36.03000494036236, 35.505984938867314), + Offset(30.483797891740366, 39.621714579092405), + Offset(23.719442126984134, 41.17597729654657), + Offset(17.808469902722187, 40.26388356552361), + Offset(13.571377486425117, 38.15001206462978), + Offset(10.73996518894534, 35.74540806580379), + Offset(8.908677157504997, 33.47648684184537), + Offset(7.746937054898215, 31.506333856475468), + Offset(7.021336564573183, 29.876779670456198), + Offset(6.575233382277915, 28.57846974488041), + Offset(6.306002369153553, 27.58317306758941), + Offset(6.147597126684428, 26.85785338221681), + Offset(6.058558318339831, 26.3706514388743), + Offset(6.013954859968965, 26.093012124442712), + Offset(6.000028695609693, 26.000194701816614), + Offset(6.0, 26.0), + ], + <Offset>[ + Offset(12.562500000000004, 21.999999999999996), + Offset(12.563028263179644, 21.76974679627851), + Offset(12.601915221773575, 20.955868783506492), + Offset(12.859988895862408, 19.29992503795225), + Offset(13.868967368048864, 16.521093282496043), + Offset(17.119246052043927, 12.463158561907132), + Offset(22.085512547276693, 9.843640931525094), + Offset(27.97135871762438, 9.40112844480027), + Offset(33.018872763119475, 10.9710702242868), + Offset(36.55408111158449, 13.438130103560162), + Offset(38.838028231283474, 16.033718047868426), + Offset(40.24471329470705, 18.407336125221466), + Offset(41.07692592252046, 20.434907268146556), + Offset(41.54755362886814, 22.095337098743826), + Offset(41.7985009918588, 23.40952601819154), + Offset(41.921690170757245, 24.41237661448199), + Offset(41.975185653795926, 25.14085315878499), + Offset(41.994340767445394, 25.629108510947514), + Offset(41.999299914344064, 25.906972804802937), + Offset(41.99999903720365, 25.999805298117412), + Offset(42.0, 26.0), + ], + <Offset>[ + Offset(12.562500000000004, 21.999999999999996), + Offset(12.563028263179644, 21.76974679627851), + Offset(12.601915221773575, 20.955868783506492), + Offset(12.859988895862408, 19.29992503795225), + Offset(13.868967368048864, 16.521093282496043), + Offset(17.119246052043927, 12.463158561907132), + Offset(22.085512547276693, 9.843640931525094), + Offset(27.97135871762438, 9.40112844480027), + Offset(33.018872763119475, 10.9710702242868), + Offset(36.55408111158449, 13.438130103560162), + Offset(38.838028231283474, 16.033718047868426), + Offset(40.24471329470705, 18.407336125221466), + Offset(41.07692592252046, 20.434907268146556), + Offset(41.54755362886814, 22.095337098743826), + Offset(41.7985009918588, 23.40952601819154), + Offset(41.921690170757245, 24.41237661448199), + Offset(41.975185653795926, 25.14085315878499), + Offset(41.994340767445394, 25.629108510947514), + Offset(41.999299914344064, 25.906972804802937), + Offset(41.99999903720365, 25.999805298117412), + Offset(42.0, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.562500000000004, 21.999999999999996), + Offset(12.563028263179644, 21.76974679627851), + Offset(12.601915221773575, 20.955868783506492), + Offset(12.859988895862408, 19.29992503795225), + Offset(13.868967368048864, 16.521093282496043), + Offset(17.119246052043927, 12.463158561907132), + Offset(22.085512547276693, 9.843640931525094), + Offset(27.97135871762438, 9.40112844480027), + Offset(33.018872763119475, 10.9710702242868), + Offset(36.55408111158449, 13.438130103560162), + Offset(38.838028231283474, 16.033718047868426), + Offset(40.24471329470705, 18.407336125221466), + Offset(41.07692592252046, 20.434907268146556), + Offset(41.54755362886814, 22.095337098743826), + Offset(41.7985009918588, 23.40952601819154), + Offset(41.921690170757245, 24.41237661448199), + Offset(41.975185653795926, 25.14085315878499), + Offset(41.994340767445394, 25.629108510947514), + Offset(41.999299914344064, 25.906972804802937), + Offset(41.99999903720365, 25.999805298117412), + Offset(42.0, 26.0), + ], + <Offset>[ + Offset(12.562500000000004, 25.999999999999996), + Offset(12.482656306166858, 25.76893925832956), + Offset(12.239876568700678, 24.939451092644983), + Offset(11.936115204605002, 23.191770024922107), + Offset(12.03457162794638, 20.07566671241613), + Offset(14.027204238592981, 15.000731698561715), + Offset(18.235691601462104, 10.929402730985391), + Offset(24.00669715972937, 8.870601601606145), + Offset(29.46892180503868, 9.127744915172523), + Offset(33.625033100689926, 10.714038007122415), + Offset(36.54081321903698, 12.759148887275034), + Offset(38.511185280577465, 14.802494849349817), + Offset(39.815969078409935, 16.638858290947915), + Offset(40.668101748647686, 18.193214036822702), + Offset(41.21772917473674, 19.451912583754474), + Offset(41.566980772751144, 20.42813499995029), + Offset(41.783709535999954, 21.145438675115766), + Offset(41.9118174384751, 21.629959864025817), + Offset(41.978620736948194, 21.907026258707322), + Offset(41.99995577009031, 21.99980529835142), + Offset(42.0, 22.0), + ], + <Offset>[ + Offset(12.562500000000004, 25.999999999999996), + Offset(12.482656306166858, 25.76893925832956), + Offset(12.239876568700678, 24.939451092644983), + Offset(11.936115204605002, 23.191770024922107), + Offset(12.03457162794638, 20.07566671241613), + Offset(14.027204238592981, 15.000731698561715), + Offset(18.235691601462104, 10.929402730985391), + Offset(24.00669715972937, 8.870601601606145), + Offset(29.46892180503868, 9.127744915172523), + Offset(33.625033100689926, 10.714038007122415), + Offset(36.54081321903698, 12.759148887275034), + Offset(38.511185280577465, 14.802494849349817), + Offset(39.815969078409935, 16.638858290947915), + Offset(40.668101748647686, 18.193214036822702), + Offset(41.21772917473674, 19.451912583754474), + Offset(41.566980772751144, 20.42813499995029), + Offset(41.783709535999954, 21.145438675115766), + Offset(41.9118174384751, 21.629959864025817), + Offset(41.978620736948194, 21.907026258707322), + Offset(41.99995577009031, 21.99980529835142), + Offset(42.0, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.562500000000004, 25.999999999999996), + Offset(12.482656306166858, 25.76893925832956), + Offset(12.239876568700678, 24.939451092644983), + Offset(11.936115204605002, 23.191770024922107), + Offset(12.03457162794638, 20.07566671241613), + Offset(14.027204238592981, 15.000731698561715), + Offset(18.235691601462104, 10.929402730985391), + Offset(24.00669715972937, 8.870601601606145), + Offset(29.46892180503868, 9.127744915172523), + Offset(33.625033100689926, 10.714038007122415), + Offset(36.54081321903698, 12.759148887275034), + Offset(38.511185280577465, 14.802494849349817), + Offset(39.815969078409935, 16.638858290947915), + Offset(40.668101748647686, 18.193214036822702), + Offset(41.21772917473674, 19.451912583754474), + Offset(41.566980772751144, 20.42813499995029), + Offset(41.783709535999954, 21.145438675115766), + Offset(41.9118174384751, 21.629959864025817), + Offset(41.978620736948194, 21.907026258707322), + Offset(41.99995577009031, 21.99980529835142), + Offset(42.0, 22.0), + ], + <Offset>[ + Offset(39.94921875, 26.0), + Offset(39.91892748707239, 26.320327277002704), + Offset(39.76165847505559, 27.44070450686089), + Offset(39.204067317080856, 29.66482937223119), + Offset(37.532335710606446, 33.23420478667988), + Offset(32.93796312691141, 38.04355807552189), + Offset(26.633976945925774, 40.7074763785527), + Offset(19.754780569089124, 40.645450453352446), + Offset(14.258518944641395, 38.42055825640933), + Offset(10.642329475530556, 35.42591996819203), + Offset(8.442750176698839, 32.47083890521039), + Offset(7.175149143375414, 29.871645565973722), + Offset(6.485980210787691, 27.710284879276827), + Offset(6.141884684352732, 25.97465660853507), + Offset(5.994461565155852, 24.620856310443347), + Offset(5.951292971147453, 23.598931453057713), + Offset(5.956121008888456, 22.862438898547587), + Offset(5.976034989369527, 22.3715027919526), + Offset(5.9932756825730955, 22.093065578347097), + Offset(5.999985428496359, 22.00019470205062), + Offset(6.0, 22.0), + ], + <Offset>[ + Offset(39.94921875, 26.0), + Offset(39.91892748707239, 26.320327277002704), + Offset(39.76165847505559, 27.44070450686089), + Offset(39.204067317080856, 29.66482937223119), + Offset(37.532335710606446, 33.23420478667988), + Offset(32.93796312691141, 38.04355807552189), + Offset(26.633976945925774, 40.7074763785527), + Offset(19.754780569089124, 40.645450453352446), + Offset(14.258518944641395, 38.42055825640933), + Offset(10.642329475530556, 35.42591996819203), + Offset(8.442750176698839, 32.47083890521039), + Offset(7.175149143375414, 29.871645565973722), + Offset(6.485980210787691, 27.710284879276827), + Offset(6.141884684352732, 25.97465660853507), + Offset(5.994461565155852, 24.620856310443347), + Offset(5.951292971147453, 23.598931453057713), + Offset(5.956121008888456, 22.862438898547587), + Offset(5.976034989369527, 22.3715027919526), + Offset(5.9932756825730955, 22.093065578347097), + Offset(5.999985428496359, 22.00019470205062), + Offset(6.0, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(39.94921875, 26.0), + Offset(39.91892748707239, 26.320327277002704), + Offset(39.76165847505559, 27.44070450686089), + Offset(39.204067317080856, 29.66482937223119), + Offset(37.532335710606446, 33.23420478667988), + Offset(32.93796312691141, 38.04355807552189), + Offset(26.633976945925774, 40.7074763785527), + Offset(19.754780569089124, 40.645450453352446), + Offset(14.258518944641395, 38.42055825640933), + Offset(10.642329475530556, 35.42591996819203), + Offset(8.442750176698839, 32.47083890521039), + Offset(7.175149143375414, 29.871645565973722), + Offset(6.485980210787691, 27.710284879276827), + Offset(6.141884684352732, 25.97465660853507), + Offset(5.994461565155852, 24.620856310443347), + Offset(5.951292971147453, 23.598931453057713), + Offset(5.956121008888456, 22.862438898547587), + Offset(5.976034989369527, 22.3715027919526), + Offset(5.9932756825730955, 22.093065578347097), + Offset(5.999985428496359, 22.00019470205062), + Offset(6.0, 22.0), + ], + <Offset>[ + Offset(39.94921875, 22.0), + Offset(39.999299444085175, 22.321134814951655), + Offset(40.123697128128484, 23.4571221977224), + Offset(40.127941008338254, 25.772984385261328), + Offset(39.36673145070893, 29.679631356759792), + Offset(36.03000494036236, 35.505984938867314), + Offset(30.483797891740366, 39.621714579092405), + Offset(23.719442126984134, 41.17597729654657), + Offset(17.808469902722187, 40.26388356552361), + Offset(13.571377486425117, 38.15001206462978), + Offset(10.73996518894534, 35.74540806580379), + Offset(8.908677157504997, 33.47648684184537), + Offset(7.746937054898215, 31.506333856475468), + Offset(7.021336564573183, 29.876779670456198), + Offset(6.575233382277915, 28.57846974488041), + Offset(6.306002369153553, 27.58317306758941), + Offset(6.147597126684428, 26.85785338221681), + Offset(6.058558318339831, 26.3706514388743), + Offset(6.013954859968965, 26.093012124442712), + Offset(6.000028695609693, 26.000194701816614), + Offset(6.0, 26.0), + ], + <Offset>[ + Offset(39.94921875, 22.0), + Offset(39.999299444085175, 22.321134814951655), + Offset(40.123697128128484, 23.4571221977224), + Offset(40.127941008338254, 25.772984385261328), + Offset(39.36673145070893, 29.679631356759792), + Offset(36.03000494036236, 35.505984938867314), + Offset(30.483797891740366, 39.621714579092405), + Offset(23.719442126984134, 41.17597729654657), + Offset(17.808469902722187, 40.26388356552361), + Offset(13.571377486425117, 38.15001206462978), + Offset(10.73996518894534, 35.74540806580379), + Offset(8.908677157504997, 33.47648684184537), + Offset(7.746937054898215, 31.506333856475468), + Offset(7.021336564573183, 29.876779670456198), + Offset(6.575233382277915, 28.57846974488041), + Offset(6.306002369153553, 27.58317306758941), + Offset(6.147597126684428, 26.85785338221681), + Offset(6.058558318339831, 26.3706514388743), + Offset(6.013954859968965, 26.093012124442712), + Offset(6.000028695609693, 26.000194701816614), + Offset(6.0, 26.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(24.00120242935725, 7.98287044589657), + Offset(24.475307447859166, 8.003617986907148), + Offset(26.126659093516306, 8.177690670193112), + Offset(29.352785593371877, 8.997654274881697), + Offset(34.261760845645924, 11.73586028864448), + Offset(39.689530947675216, 19.233828052194387), + Offset(40.483245113546566, 28.57182115613015), + Offset(36.43819118187483, 37.011448735029944), + Offset(29.990575804517718, 41.869715613211284), + Offset(23.79684347484401, 43.53566841500789), + Offset(18.750267725016194, 43.37984126279926), + Offset(14.90588210305647, 42.37202895863352), + Offset(12.06653769423517, 41.068216372655385), + Offset(10.005013565343445, 39.76135295541911), + Offset(8.528791010746735, 38.595867902966916), + Offset(7.490777665658619, 37.63578444828991), + Offset(6.783719048719078, 36.90231589146764), + Offset(6.331695603851976, 36.39438332503497), + Offset(6.082250821137091, 36.09960487240796), + Offset(6.000171486902083, 36.000208945476956), + Offset(6.0, 36.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(24.00120242935725, 7.98287044589657), + Offset(24.475307447859166, 8.003617986907148), + Offset(26.126659093516306, 8.177690670193112), + Offset(29.352785593371877, 8.997654274881697), + Offset(34.261760845645924, 11.73586028864448), + Offset(39.689530947675216, 19.233828052194387), + Offset(40.483245113546566, 28.57182115613015), + Offset(36.43819118187483, 37.011448735029944), + Offset(29.990575804517718, 41.869715613211284), + Offset(23.79684347484401, 43.53566841500789), + Offset(18.750267725016194, 43.37984126279926), + Offset(14.90588210305647, 42.37202895863352), + Offset(12.06653769423517, 41.068216372655385), + Offset(10.005013565343445, 39.76135295541911), + Offset(8.528791010746735, 38.595867902966916), + Offset(7.490777665658619, 37.63578444828991), + Offset(6.783719048719078, 36.90231589146764), + Offset(6.331695603851976, 36.39438332503497), + Offset(6.082250821137091, 36.09960487240796), + Offset(6.000171486902083, 36.000208945476956), + Offset(6.0, 36.0), + ], + <Offset>[ + Offset(8.389135783884633, 23.59493709136918), + Offset(8.411539419733579, 23.280020314446016), + Offset(8.535460203545142, 22.174793784450976), + Offset(9.004955277979905, 19.95721448439121), + Offset(10.506583157969082, 16.301391783224325), + Offset(15.00736732713968, 11.07994257565777), + Offset(21.799606746441338, 7.957602889938901), + Offset(29.78681308270101, 8.138822767869717), + Offset(36.3635225612393, 11.3666818389531), + Offset(40.53777507406921, 15.843550126760437), + Offset(42.771588169072636, 20.33326716415372), + Offset(43.71871364987625, 24.29568645796705), + Offset(43.90383296365319, 27.574365631376406), + Offset(43.68696452483883, 30.181901809762802), + Offset(43.29833346247236, 32.192150096307955), + Offset(42.87820947711742, 33.69183670134356), + Offset(42.5074211611244, 34.76136730547495), + Offset(42.22832709352211, 35.46839060016271), + Offset(42.058590816793185, 35.86711275140609), + Offset(42.00012355171139, 35.99972219110006), + Offset(42.0, 36.0), + ], + <Offset>[ + Offset(8.389135783884633, 23.59493709136918), + Offset(8.411539419733579, 23.280020314446016), + Offset(8.535460203545142, 22.174793784450976), + Offset(9.004955277979905, 19.95721448439121), + Offset(10.506583157969082, 16.301391783224325), + Offset(15.00736732713968, 11.07994257565777), + Offset(21.799606746441338, 7.957602889938901), + Offset(29.78681308270101, 8.138822767869717), + Offset(36.3635225612393, 11.3666818389531), + Offset(40.53777507406921, 15.843550126760437), + Offset(42.771588169072636, 20.33326716415372), + Offset(43.71871364987625, 24.29568645796705), + Offset(43.90383296365319, 27.574365631376406), + Offset(43.68696452483883, 30.181901809762802), + Offset(43.29833346247236, 32.192150096307955), + Offset(42.87820947711742, 33.69183670134356), + Offset(42.5074211611244, 34.76136730547495), + Offset(42.22832709352211, 35.46839060016271), + Offset(42.058590816793185, 35.86711275140609), + Offset(42.00012355171139, 35.99972219110006), + Offset(42.0, 36.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(8.389135783884633, 23.59493709136918), + Offset(8.411539419733579, 23.280020314446016), + Offset(8.535460203545142, 22.174793784450976), + Offset(9.004955277979905, 19.95721448439121), + Offset(10.506583157969082, 16.301391783224325), + Offset(15.00736732713968, 11.07994257565777), + Offset(21.799606746441338, 7.957602889938901), + Offset(29.78681308270101, 8.138822767869717), + Offset(36.3635225612393, 11.3666818389531), + Offset(40.53777507406921, 15.843550126760437), + Offset(42.771588169072636, 20.33326716415372), + Offset(43.71871364987625, 24.29568645796705), + Offset(43.90383296365319, 27.574365631376406), + Offset(43.68696452483883, 30.181901809762802), + Offset(43.29833346247236, 32.192150096307955), + Offset(42.87820947711742, 33.69183670134356), + Offset(42.5074211611244, 34.76136730547495), + Offset(42.22832709352211, 35.46839060016271), + Offset(42.058590816793185, 35.86711275140609), + Offset(42.00012355171139, 35.99972219110006), + Offset(42.0, 36.0), + ], + <Offset>[ + Offset(11.217562908630821, 26.423364216115367), + Offset(11.168037593988725, 26.178591999833156), + Offset(11.026001684399013, 25.304842207741935), + Offset(10.901761927954412, 23.478879507162752), + Offset(11.261530717110908, 20.229502548330856), + Offset(13.752640365544114, 14.878055298029915), + Offset(18.8358022450215, 10.643838709326973), + Offset(25.888907364460923, 9.03678212759111), + Offset(32.44806665065668, 10.54863232194106), + Offset(37.11467529624949, 13.774157000481484), + Offset(40.00232975553069, 17.44688398809633), + Offset(41.592943181014675, 20.907309278000795), + Offset(42.34289639575017, 23.891503017731534), + Offset(42.59272365615382, 26.334482295166104), + Offset(42.57381482854062, 28.258313197161566), + Offset(42.4351505629611, 29.71645007881405), + Offset(42.26812747456164, 30.76853140456803), + Offset(42.125177049114, 31.469720812803587), + Offset(42.03274190981708, 31.867196273027055), + Offset(42.00006946781973, 31.999722191465697), + Offset(42.0, 32.0), + ], + <Offset>[ + Offset(11.217562908630821, 26.423364216115367), + Offset(11.168037593988725, 26.178591999833156), + Offset(11.026001684399013, 25.304842207741935), + Offset(10.901761927954412, 23.478879507162752), + Offset(11.261530717110908, 20.229502548330856), + Offset(13.752640365544114, 14.878055298029915), + Offset(18.8358022450215, 10.643838709326973), + Offset(25.888907364460923, 9.03678212759111), + Offset(32.44806665065668, 10.54863232194106), + Offset(37.11467529624949, 13.774157000481484), + Offset(40.00232975553069, 17.44688398809633), + Offset(41.592943181014675, 20.907309278000795), + Offset(42.34289639575017, 23.891503017731534), + Offset(42.59272365615382, 26.334482295166104), + Offset(42.57381482854062, 28.258313197161566), + Offset(42.4351505629611, 29.71645007881405), + Offset(42.26812747456164, 30.76853140456803), + Offset(42.125177049114, 31.469720812803587), + Offset(42.03274190981708, 31.867196273027055), + Offset(42.00006946781973, 31.999722191465697), + Offset(42.0, 32.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(11.217562908630821, 26.423364216115367), + Offset(11.168037593988725, 26.178591999833156), + Offset(11.026001684399013, 25.304842207741935), + Offset(10.901761927954412, 23.478879507162752), + Offset(11.261530717110908, 20.229502548330856), + Offset(13.752640365544114, 14.878055298029915), + Offset(18.8358022450215, 10.643838709326973), + Offset(25.888907364460923, 9.03678212759111), + Offset(32.44806665065668, 10.54863232194106), + Offset(37.11467529624949, 13.774157000481484), + Offset(40.00232975553069, 17.44688398809633), + Offset(41.592943181014675, 20.907309278000795), + Offset(42.34289639575017, 23.891503017731534), + Offset(42.59272365615382, 26.334482295166104), + Offset(42.57381482854062, 28.258313197161566), + Offset(42.4351505629611, 29.71645007881405), + Offset(42.26812747456164, 30.76853140456803), + Offset(42.125177049114, 31.469720812803587), + Offset(42.03274190981708, 31.867196273027055), + Offset(42.00006946781973, 31.999722191465697), + Offset(42.0, 32.0), + ], + <Offset>[ + Offset(26.829629554103438, 10.811297570642758), + Offset(27.231805622114308, 10.902189672294288), + Offset(28.61720057437018, 11.307739093484066), + Offset(31.249592243346385, 12.519319297653237), + Offset(35.01670840478775, 15.663971053751007), + Offset(38.43480398607965, 23.031940774566532), + Offset(37.51944061212673, 31.258056975518222), + Offset(32.54028546363474, 37.909408094751335), + Offset(26.0751198939351, 41.05166609619924), + Offset(20.373743697024292, 41.46627528872894), + Offset(15.981009311474246, 40.49345808674188), + Offset(12.780111634194903, 38.983651778667266), + Offset(10.505601126332149, 37.38535375901051), + Offset(8.910772696658444, 35.91393344082242), + Offset(7.804272376814996, 34.66203100382052), + Offset(7.047718751502295, 33.6603978257604), + Offset(6.544425362156314, 32.90947999056071), + Offset(6.228545559443866, 32.39571353767585), + Offset(6.056401914160979, 32.099688394028924), + Offset(6.000117403010417, 32.00020894584259), + Offset(6.0, 32.0), + ], + <Offset>[ + Offset(26.829629554103438, 10.811297570642758), + Offset(27.231805622114308, 10.902189672294288), + Offset(28.61720057437018, 11.307739093484066), + Offset(31.249592243346385, 12.519319297653237), + Offset(35.01670840478775, 15.663971053751007), + Offset(38.43480398607965, 23.031940774566532), + Offset(37.51944061212673, 31.258056975518222), + Offset(32.54028546363474, 37.909408094751335), + Offset(26.0751198939351, 41.05166609619924), + Offset(20.373743697024292, 41.46627528872894), + Offset(15.981009311474246, 40.49345808674188), + Offset(12.780111634194903, 38.983651778667266), + Offset(10.505601126332149, 37.38535375901051), + Offset(8.910772696658444, 35.91393344082242), + Offset(7.804272376814996, 34.66203100382052), + Offset(7.047718751502295, 33.6603978257604), + Offset(6.544425362156314, 32.90947999056071), + Offset(6.228545559443866, 32.39571353767585), + Offset(6.056401914160979, 32.099688394028924), + Offset(6.000117403010417, 32.00020894584259), + Offset(6.0, 32.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.829629554103438, 10.811297570642758), + Offset(27.231805622114308, 10.902189672294288), + Offset(28.61720057437018, 11.307739093484066), + Offset(31.249592243346385, 12.519319297653237), + Offset(35.01670840478775, 15.663971053751007), + Offset(38.43480398607965, 23.031940774566532), + Offset(37.51944061212673, 31.258056975518222), + Offset(32.54028546363474, 37.909408094751335), + Offset(26.0751198939351, 41.05166609619924), + Offset(20.373743697024292, 41.46627528872894), + Offset(15.981009311474246, 40.49345808674188), + Offset(12.780111634194903, 38.983651778667266), + Offset(10.505601126332149, 37.38535375901051), + Offset(8.910772696658444, 35.91393344082242), + Offset(7.804272376814996, 34.66203100382052), + Offset(7.047718751502295, 33.6603978257604), + Offset(6.544425362156314, 32.90947999056071), + Offset(6.228545559443866, 32.39571353767585), + Offset(6.056401914160979, 32.099688394028924), + Offset(6.000117403010417, 32.00020894584259), + Offset(6.0, 32.0), + ], + <Offset>[ + Offset(24.00120242935725, 7.98287044589657), + Offset(24.475307447859166, 8.003617986907148), + Offset(26.126659093516306, 8.177690670193112), + Offset(29.352785593371877, 8.997654274881697), + Offset(34.261760845645924, 11.73586028864448), + Offset(39.689530947675216, 19.233828052194387), + Offset(40.483245113546566, 28.57182115613015), + Offset(36.43819118187483, 37.011448735029944), + Offset(29.990575804517718, 41.869715613211284), + Offset(23.79684347484401, 43.53566841500789), + Offset(18.750267725016194, 43.37984126279926), + Offset(14.90588210305647, 42.37202895863352), + Offset(12.06653769423517, 41.068216372655385), + Offset(10.005013565343445, 39.76135295541911), + Offset(8.528791010746735, 38.595867902966916), + Offset(7.490777665658619, 37.63578444828991), + Offset(6.783719048719078, 36.90231589146764), + Offset(6.331695603851976, 36.39438332503497), + Offset(6.082250821137091, 36.09960487240796), + Offset(6.000171486902083, 36.000208945476956), + Offset(6.0, 36.0), + ], + <Offset>[ + Offset(24.00120242935725, 7.98287044589657), + Offset(24.475307447859166, 8.003617986907148), + Offset(26.126659093516306, 8.177690670193112), + Offset(29.352785593371877, 8.997654274881697), + Offset(34.261760845645924, 11.73586028864448), + Offset(39.689530947675216, 19.233828052194387), + Offset(40.483245113546566, 28.57182115613015), + Offset(36.43819118187483, 37.011448735029944), + Offset(29.990575804517718, 41.869715613211284), + Offset(23.79684347484401, 43.53566841500789), + Offset(18.750267725016194, 43.37984126279926), + Offset(14.90588210305647, 42.37202895863352), + Offset(12.06653769423517, 41.068216372655385), + Offset(10.005013565343445, 39.76135295541911), + Offset(8.528791010746735, 38.595867902966916), + Offset(7.490777665658619, 37.63578444828991), + Offset(6.783719048719078, 36.90231589146764), + Offset(6.331695603851976, 36.39438332503497), + Offset(6.082250821137091, 36.09960487240796), + Offset(6.000171486902083, 36.000208945476956), + Offset(6.0, 36.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(26.829629554103434, 37.188702429357235), + Offset(26.70295401712204, 37.21708146835027), + Offset(26.253437940457104, 37.31668297706097), + Offset(25.316159296509255, 37.51407939114749), + Offset(23.588416071597663, 37.80897683895165), + Offset(20.234451203252327, 37.9685842890323), + Offset(16.265106286835728, 37.25239920809595), + Offset(12.10312127594884, 35.1746313573166), + Offset(8.858593681675742, 32.111920483700914), + Offset(6.842177615689938, 28.881561047964333), + Offset(5.761956468124708, 25.926691322240227), + Offset(5.290469810431201, 23.40907221160189), + Offset(5.178751382636996, 21.349132840198116), + Offset(5.258916359304976, 19.710667345993283), + Offset(5.423821188616003, 18.440676377623248), + Offset(5.607765949538116, 17.48625665894383), + Offset(5.772423819137188, 16.80059820468561), + Offset(5.897326348355019, 16.34455713877282), + Offset(5.973614735709873, 16.086271507697752), + Offset(5.9999443342489265, 16.000180457509614), + Offset(6.0, 16.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.829629554103434, 37.188702429357235), + Offset(26.70295401712204, 37.21708146835027), + Offset(26.253437940457104, 37.31668297706097), + Offset(25.316159296509255, 37.51407939114749), + Offset(23.588416071597663, 37.80897683895165), + Offset(20.234451203252327, 37.9685842890323), + Offset(16.265106286835728, 37.25239920809595), + Offset(12.10312127594884, 35.1746313573166), + Offset(8.858593681675742, 32.111920483700914), + Offset(6.842177615689938, 28.881561047964333), + Offset(5.761956468124708, 25.926691322240227), + Offset(5.290469810431201, 23.40907221160189), + Offset(5.178751382636996, 21.349132840198116), + Offset(5.258916359304976, 19.710667345993283), + Offset(5.423821188616003, 18.440676377623248), + Offset(5.607765949538116, 17.48625665894383), + Offset(5.772423819137188, 16.80059820468561), + Offset(5.897326348355019, 16.34455713877282), + Offset(5.973614735709873, 16.086271507697752), + Offset(5.9999443342489265, 16.000180457509614), + Offset(6.0, 16.0), + ], + <Offset>[ + Offset(11.2175487664952, 21.576649926020245), + Offset(11.26591566746795, 21.307620185014063), + Offset(11.473792301821605, 20.377637880770784), + Offset(12.06502589368821, 18.578567196580664), + Offset(13.54646415229777, 15.801892832848761), + Offset(17.052481673761243, 12.16993860231353), + Offset(21.42462731807053, 9.9137145270952), + Offset(26.111676903911107, 9.066591789474842), + Offset(30.142827978195022, 9.351628521416771), + Offset(33.249292834290536, 10.17924910714327), + Offset(35.60828563949723, 11.183386110908502), + Offset(37.40014550074941, 12.188459616498097), + Offset(38.76213503811523, 13.111795882844753), + Offset(39.793775377370764, 13.915564474413902), + Offset(40.567255045797005, 14.584805428587808), + Offset(41.13536943122808, 15.116774671440997), + Offset(41.537143495419784, 15.5155379179047), + Offset(41.801600251554405, 15.788922082526666), + Offset(41.95043550915973, 15.946775613712157), + Offset(41.99989640116428, 15.999888404883473), + Offset(42.0, 16.0), + ], + <Offset>[ + Offset(11.2175487664952, 21.576649926020245), + Offset(11.26591566746795, 21.307620185014063), + Offset(11.473792301821605, 20.377637880770784), + Offset(12.06502589368821, 18.578567196580664), + Offset(13.54646415229777, 15.801892832848761), + Offset(17.052481673761243, 12.16993860231353), + Offset(21.42462731807053, 9.9137145270952), + Offset(26.111676903911107, 9.066591789474842), + Offset(30.142827978195022, 9.351628521416771), + Offset(33.249292834290536, 10.17924910714327), + Offset(35.60828563949723, 11.183386110908502), + Offset(37.40014550074941, 12.188459616498097), + Offset(38.76213503811523, 13.111795882844753), + Offset(39.793775377370764, 13.915564474413902), + Offset(40.567255045797005, 14.584805428587808), + Offset(41.13536943122808, 15.116774671440997), + Offset(41.537143495419784, 15.5155379179047), + Offset(41.801600251554405, 15.788922082526666), + Offset(41.95043550915973, 15.946775613712157), + Offset(41.99989640116428, 15.999888404883473), + Offset(42.0, 16.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(11.2175487664952, 21.576649926020245), + Offset(11.26591566746795, 21.307620185014063), + Offset(11.473792301821605, 20.377637880770784), + Offset(12.06502589368821, 18.578567196580664), + Offset(13.54646415229777, 15.801892832848761), + Offset(17.052481673761243, 12.16993860231353), + Offset(21.42462731807053, 9.9137145270952), + Offset(26.111676903911107, 9.066591789474842), + Offset(30.142827978195022, 9.351628521416771), + Offset(33.249292834290536, 10.17924910714327), + Offset(35.60828563949723, 11.183386110908502), + Offset(37.40014550074941, 12.188459616498097), + Offset(38.76213503811523, 13.111795882844753), + Offset(39.793775377370764, 13.915564474413902), + Offset(40.567255045797005, 14.584805428587808), + Offset(41.13536943122808, 15.116774671440997), + Offset(41.537143495419784, 15.5155379179047), + Offset(41.801600251554405, 15.788922082526666), + Offset(41.95043550915973, 15.946775613712157), + Offset(41.99989640116428, 15.999888404883473), + Offset(42.0, 16.0), + ], + <Offset>[ + Offset(8.38912164174901, 24.405077050766437), + Offset(8.395184821848037, 24.09310118692493), + Offset(8.459782153583708, 23.007417876572518), + Offset(8.787794358833729, 20.871982437428983), + Offset(9.907414129760891, 17.4624092987335), + Offset(13.082563535366404, 12.659581303110395), + Offset(17.494014200747685, 9.171905574648836), + Offset(22.5870000408063, 7.175387672861925), + Offset(27.221252362148654, 6.6195238529014375), + Offset(30.937448027657968, 6.914992133489694), + Offset(33.83674155554175, 7.597074418012536), + Offset(36.08060605872299, 8.412374916582504), + Offset(37.809259485732085, 9.226949916571378), + Offset(39.13181277597566, 9.970719038360135), + Offset(40.13100060158848, 10.608666338979862), + Offset(40.8691843334897, 11.125641311887346), + Offset(41.393512389333864, 11.518117486505904), + Offset(41.739705833610245, 11.789400976065625), + Offset(41.934926095887384, 11.946805681562672), + Offset(41.99986395082928, 11.999888405015101), + Offset(42.0, 12.0), + ], + <Offset>[ + Offset(8.38912164174901, 24.405077050766437), + Offset(8.395184821848037, 24.09310118692493), + Offset(8.459782153583708, 23.007417876572518), + Offset(8.787794358833729, 20.871982437428983), + Offset(9.907414129760891, 17.4624092987335), + Offset(13.082563535366404, 12.659581303110395), + Offset(17.494014200747685, 9.171905574648836), + Offset(22.5870000408063, 7.175387672861925), + Offset(27.221252362148654, 6.6195238529014375), + Offset(30.937448027657968, 6.914992133489694), + Offset(33.83674155554175, 7.597074418012536), + Offset(36.08060605872299, 8.412374916582504), + Offset(37.809259485732085, 9.226949916571378), + Offset(39.13181277597566, 9.970719038360135), + Offset(40.13100060158848, 10.608666338979862), + Offset(40.8691843334897, 11.125641311887346), + Offset(41.393512389333864, 11.518117486505904), + Offset(41.739705833610245, 11.789400976065625), + Offset(41.934926095887384, 11.946805681562672), + Offset(41.99986395082928, 11.999888405015101), + Offset(42.0, 12.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(8.38912164174901, 24.405077050766437), + Offset(8.395184821848037, 24.09310118692493), + Offset(8.459782153583708, 23.007417876572518), + Offset(8.787794358833729, 20.871982437428983), + Offset(9.907414129760891, 17.4624092987335), + Offset(13.082563535366404, 12.659581303110395), + Offset(17.494014200747685, 9.171905574648836), + Offset(22.5870000408063, 7.175387672861925), + Offset(27.221252362148654, 6.6195238529014375), + Offset(30.937448027657968, 6.914992133489694), + Offset(33.83674155554175, 7.597074418012536), + Offset(36.08060605872299, 8.412374916582504), + Offset(37.809259485732085, 9.226949916571378), + Offset(39.13181277597566, 9.970719038360135), + Offset(40.13100060158848, 10.608666338979862), + Offset(40.8691843334897, 11.125641311887346), + Offset(41.393512389333864, 11.518117486505904), + Offset(41.739705833610245, 11.789400976065625), + Offset(41.934926095887384, 11.946805681562672), + Offset(41.99986395082928, 11.999888405015101), + Offset(42.0, 12.0), + ], + <Offset>[ + Offset(24.001202429357242, 40.01712955410343), + Offset(23.83222317150212, 40.00256247026114), + Offset(23.23942779221921, 39.946462972862705), + Offset(22.038927761654776, 39.80749463199581), + Offset(19.949366049060785, 39.46949330483639), + Offset(16.264533064857485, 38.458226989829164), + Offset(12.33449316951288, 36.51059025564959), + Offset(8.578444412844032, 33.28342724070369), + Offset(5.937018065629374, 29.37981581518558), + Offset(4.53033280905737, 25.617304074310752), + Offset(3.9904123841692254, 22.340379629344262), + Offset(3.9709303684047867, 19.632987511686302), + Offset(4.225875830253855, 17.46428687392474), + Offset(4.596953757909873, 15.765821909939516), + Offset(4.987566744407481, 14.464537288015299), + Offset(5.341580851799733, 13.495123299390182), + Offset(5.628792713051272, 12.803177773286812), + Offset(5.835431930410859, 12.34503603231178), + Offset(5.958105322437522, 12.08630157554827), + Offset(5.999911883913924, 12.000180457641243), + Offset(6.0, 12.0), + ], + <Offset>[ + Offset(24.001202429357242, 40.01712955410343), + Offset(23.83222317150212, 40.00256247026114), + Offset(23.23942779221921, 39.946462972862705), + Offset(22.038927761654776, 39.80749463199581), + Offset(19.949366049060785, 39.46949330483639), + Offset(16.264533064857485, 38.458226989829164), + Offset(12.33449316951288, 36.51059025564959), + Offset(8.578444412844032, 33.28342724070369), + Offset(5.937018065629374, 29.37981581518558), + Offset(4.53033280905737, 25.617304074310752), + Offset(3.9904123841692254, 22.340379629344262), + Offset(3.9709303684047867, 19.632987511686302), + Offset(4.225875830253855, 17.46428687392474), + Offset(4.596953757909873, 15.765821909939516), + Offset(4.987566744407481, 14.464537288015299), + Offset(5.341580851799733, 13.495123299390182), + Offset(5.628792713051272, 12.803177773286812), + Offset(5.835431930410859, 12.34503603231178), + Offset(5.958105322437522, 12.08630157554827), + Offset(5.999911883913924, 12.000180457641243), + Offset(6.0, 12.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(24.001202429357242, 40.01712955410343), + Offset(23.83222317150212, 40.00256247026114), + Offset(23.23942779221921, 39.946462972862705), + Offset(22.038927761654776, 39.80749463199581), + Offset(19.949366049060785, 39.46949330483639), + Offset(16.264533064857485, 38.458226989829164), + Offset(12.33449316951288, 36.51059025564959), + Offset(8.578444412844032, 33.28342724070369), + Offset(5.937018065629374, 29.37981581518558), + Offset(4.53033280905737, 25.617304074310752), + Offset(3.9904123841692254, 22.340379629344262), + Offset(3.9709303684047867, 19.632987511686302), + Offset(4.225875830253855, 17.46428687392474), + Offset(4.596953757909873, 15.765821909939516), + Offset(4.987566744407481, 14.464537288015299), + Offset(5.341580851799733, 13.495123299390182), + Offset(5.628792713051272, 12.803177773286812), + Offset(5.835431930410859, 12.34503603231178), + Offset(5.958105322437522, 12.08630157554827), + Offset(5.999911883913924, 12.000180457641243), + Offset(6.0, 12.0), + ], + <Offset>[ + Offset(26.829629554103434, 37.188702429357235), + Offset(26.70295401712204, 37.21708146835027), + Offset(26.253437940457104, 37.31668297706097), + Offset(25.316159296509255, 37.51407939114749), + Offset(23.588416071597663, 37.80897683895165), + Offset(20.234451203252327, 37.9685842890323), + Offset(16.265106286835728, 37.25239920809595), + Offset(12.10312127594884, 35.1746313573166), + Offset(8.858593681675742, 32.111920483700914), + Offset(6.842177615689938, 28.881561047964333), + Offset(5.761956468124708, 25.926691322240227), + Offset(5.290469810431201, 23.40907221160189), + Offset(5.178751382636996, 21.349132840198116), + Offset(5.258916359304976, 19.710667345993283), + Offset(5.423821188616003, 18.440676377623248), + Offset(5.607765949538116, 17.48625665894383), + Offset(5.772423819137188, 16.80059820468561), + Offset(5.897326348355019, 16.34455713877282), + Offset(5.973614735709873, 16.086271507697752), + Offset(5.9999443342489265, 16.000180457509614), + Offset(6.0, 16.0), + ], + <Offset>[ + Offset(26.829629554103434, 37.188702429357235), + Offset(26.70295401712204, 37.21708146835027), + Offset(26.253437940457104, 37.31668297706097), + Offset(25.316159296509255, 37.51407939114749), + Offset(23.588416071597663, 37.80897683895165), + Offset(20.234451203252327, 37.9685842890323), + Offset(16.265106286835728, 37.25239920809595), + Offset(12.10312127594884, 35.1746313573166), + Offset(8.858593681675742, 32.111920483700914), + Offset(6.842177615689938, 28.881561047964333), + Offset(5.761956468124708, 25.926691322240227), + Offset(5.290469810431201, 23.40907221160189), + Offset(5.178751382636996, 21.349132840198116), + Offset(5.258916359304976, 19.710667345993283), + Offset(5.423821188616003, 18.440676377623248), + Offset(5.607765949538116, 17.48625665894383), + Offset(5.772423819137188, 16.80059820468561), + Offset(5.897326348355019, 16.34455713877282), + Offset(5.973614735709873, 16.086271507697752), + Offset(5.9999443342489265, 16.000180457509614), + Offset(6.0, 16.0), + ], + ), + _PathClose( + ), + ], + ), + ], + matchTextDirection: true, +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/close_menu.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/close_menu.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..311a74534b0e6f4fb84e19224a803aa8b61803c5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/close_menu.g.dart @@ -0,0 +1,1026 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$close_menu = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(24.0, 26.0), + Offset(23.959814021491162, 25.999596231025475), + Offset(23.818980673456252, 25.99179115456858), + Offset(23.538063154364504, 25.945922493483316), + Offset(23.08280212993325, 25.77728671495204), + Offset(22.453979093274526, 25.26878656832729), + Offset(22.075089527092704, 24.54288089973015), + Offset(22.262051805115647, 21.908449654595582), + Offset(24.88919842700383, 17.94756272667581), + Offset(28.423231797685485, 16.307213722363326), + Offset(31.75801074104301, 16.114437816710378), + Offset(34.549940992662854, 16.70741310193702), + Offset(36.75456537179234, 17.655783514919893), + Offset(38.441715273516245, 18.694992104934485), + Offset(39.70097192738563, 19.67449366114299), + Offset(40.617793553920194, 20.51263931960471), + Offset(41.26084924113239, 21.170496215429807), + Offset(41.68247655138362, 21.634692364647904), + Offset(41.92023728365015, 21.90732809306482), + Offset(41.99983686928147, 21.999805299557877), + Offset(42.0, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(24.0, 26.0), + Offset(23.959814021491162, 25.999596231025475), + Offset(23.818980673456252, 25.99179115456858), + Offset(23.538063154364504, 25.945922493483316), + Offset(23.08280212993325, 25.77728671495204), + Offset(22.453979093274526, 25.26878656832729), + Offset(22.075089527092704, 24.54288089973015), + Offset(22.262051805115647, 21.908449654595582), + Offset(24.88919842700383, 17.94756272667581), + Offset(28.423231797685485, 16.307213722363326), + Offset(31.75801074104301, 16.114437816710378), + Offset(34.549940992662854, 16.70741310193702), + Offset(36.75456537179234, 17.655783514919893), + Offset(38.441715273516245, 18.694992104934485), + Offset(39.70097192738563, 19.67449366114299), + Offset(40.617793553920194, 20.51263931960471), + Offset(41.26084924113239, 21.170496215429807), + Offset(41.68247655138362, 21.634692364647904), + Offset(41.92023728365015, 21.90732809306482), + Offset(41.99983686928147, 21.999805299557877), + Offset(42.0, 22.0), + ], + <Offset>[ + Offset(24.0, 26.0), + Offset(23.959814021491162, 25.999596231025475), + Offset(23.818980673456252, 25.99179115456858), + Offset(23.538063154364504, 25.945922493483316), + Offset(23.08280212993325, 25.77728671495204), + Offset(22.453979093274526, 25.26878656832729), + Offset(22.075089527092704, 24.54288089973015), + Offset(21.773286636989344, 25.561023502210293), + Offset(19.560850614934246, 28.209111964173573), + Offset(16.64772019146621, 28.96869418114919), + Offset(13.944774246803789, 28.61099302263078), + Offset(11.716530993310267, 27.687745622141946), + Offset(9.984477784090515, 26.54816750788367), + Offset(8.678832846158931, 25.4028848331679), + Offset(7.7182562555573995, 24.367892904410397), + Offset(7.027497048073013, 23.503119065863647), + Offset(6.547674641076508, 22.834089300900743), + Offset(6.235000119645385, 22.366158988430406), + Offset(6.059083538826545, 22.092725360840227), + Offset(6.000119863487498, 22.00019470067613), + Offset(5.9999999999999964, 22.000000000000007), + ], + <Offset>[ + Offset(24.0, 26.0), + Offset(23.959814021491162, 25.999596231025475), + Offset(23.818980673456252, 25.99179115456858), + Offset(23.538063154364504, 25.945922493483316), + Offset(23.08280212993325, 25.77728671495204), + Offset(22.453979093274526, 25.26878656832729), + Offset(22.075089527092704, 24.54288089973015), + Offset(21.773286636989344, 25.561023502210293), + Offset(19.560850614934246, 28.209111964173573), + Offset(16.64772019146621, 28.96869418114919), + Offset(13.944774246803789, 28.61099302263078), + Offset(11.716530993310267, 27.687745622141946), + Offset(9.984477784090515, 26.54816750788367), + Offset(8.678832846158931, 25.4028848331679), + Offset(7.7182562555573995, 24.367892904410397), + Offset(7.027497048073013, 23.503119065863647), + Offset(6.547674641076508, 22.834089300900743), + Offset(6.235000119645385, 22.366158988430406), + Offset(6.059083538826545, 22.092725360840227), + Offset(6.000119863487498, 22.00019470067613), + Offset(5.9999999999999964, 22.000000000000007), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(24.0, 26.0), + Offset(23.959814021491162, 25.999596231025475), + Offset(23.818980673456252, 25.99179115456858), + Offset(23.538063154364504, 25.945922493483316), + Offset(23.08280212993325, 25.77728671495204), + Offset(22.453979093274526, 25.26878656832729), + Offset(22.075089527092704, 24.54288089973015), + Offset(21.773286636989344, 25.561023502210293), + Offset(19.560850614934246, 28.209111964173573), + Offset(16.64772019146621, 28.96869418114919), + Offset(13.944774246803789, 28.61099302263078), + Offset(11.716530993310267, 27.687745622141946), + Offset(9.984477784090515, 26.54816750788367), + Offset(8.678832846158931, 25.4028848331679), + Offset(7.7182562555573995, 24.367892904410397), + Offset(7.027497048073013, 23.503119065863647), + Offset(6.547674641076508, 22.834089300900743), + Offset(6.235000119645385, 22.366158988430406), + Offset(6.059083538826545, 22.092725360840227), + Offset(6.000119863487498, 22.00019470067613), + Offset(5.9999999999999964, 22.000000000000007), + ], + <Offset>[ + Offset(24.0, 22.0), + Offset(24.040185978508838, 22.000403768974525), + Offset(24.181019326543748, 22.00820884543142), + Offset(24.461936845635496, 22.054077506516684), + Offset(24.91719787006675, 22.22271328504796), + Offset(25.546020906725474, 22.73121343167271), + Offset(25.924910472907296, 23.45711910026985), + Offset(25.737948194884353, 26.091550345404418), + Offset(23.110801573005386, 30.05243727330644), + Offset(19.576768202341754, 31.692786277607382), + Offset(16.24198925903886, 31.88556218323219), + Offset(13.450059007427265, 31.292586898019646), + Offset(11.245434628207665, 30.344216485080107), + Offset(9.558284726386193, 29.305007895087492), + Offset(8.29902807271331, 28.325506338842494), + Offset(7.38220644607981, 27.487360680395284), + Offset(6.7391507588675985, 26.8295037845702), + Offset(6.3175234486163845, 26.36530763535209), + Offset(6.079762716249856, 26.0926719069357), + Offset(6.000163130618532, 26.000194700442123), + Offset(5.9999999999999964, 26.000000000000007), + ], + <Offset>[ + Offset(24.0, 22.0), + Offset(24.040185978508838, 22.000403768974525), + Offset(24.181019326543748, 22.00820884543142), + Offset(24.461936845635496, 22.054077506516684), + Offset(24.91719787006675, 22.22271328504796), + Offset(25.546020906725474, 22.73121343167271), + Offset(25.924910472907296, 23.45711910026985), + Offset(25.737948194884353, 26.091550345404418), + Offset(23.110801573005386, 30.05243727330644), + Offset(19.576768202341754, 31.692786277607382), + Offset(16.24198925903886, 31.88556218323219), + Offset(13.450059007427265, 31.292586898019646), + Offset(11.245434628207665, 30.344216485080107), + Offset(9.558284726386193, 29.305007895087492), + Offset(8.29902807271331, 28.325506338842494), + Offset(7.38220644607981, 27.487360680395284), + Offset(6.7391507588675985, 26.8295037845702), + Offset(6.3175234486163845, 26.36530763535209), + Offset(6.079762716249856, 26.0926719069357), + Offset(6.000163130618532, 26.000194700442123), + Offset(5.9999999999999964, 26.000000000000007), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(24.0, 22.0), + Offset(24.040185978508838, 22.000403768974525), + Offset(24.181019326543748, 22.00820884543142), + Offset(24.461936845635496, 22.054077506516684), + Offset(24.91719787006675, 22.22271328504796), + Offset(25.546020906725474, 22.73121343167271), + Offset(25.924910472907296, 23.45711910026985), + Offset(25.737948194884353, 26.091550345404418), + Offset(23.110801573005386, 30.05243727330644), + Offset(19.576768202341754, 31.692786277607382), + Offset(16.24198925903886, 31.88556218323219), + Offset(13.450059007427265, 31.292586898019646), + Offset(11.245434628207665, 30.344216485080107), + Offset(9.558284726386193, 29.305007895087492), + Offset(8.29902807271331, 28.325506338842494), + Offset(7.38220644607981, 27.487360680395284), + Offset(6.7391507588675985, 26.8295037845702), + Offset(6.3175234486163845, 26.36530763535209), + Offset(6.079762716249856, 26.0926719069357), + Offset(6.000163130618532, 26.000194700442123), + Offset(5.9999999999999964, 26.000000000000007), + ], + <Offset>[ + Offset(24.0, 22.0), + Offset(24.040185978508838, 22.000403768974525), + Offset(24.181019326543748, 22.00820884543142), + Offset(24.461936845635496, 22.054077506516684), + Offset(24.91719787006675, 22.22271328504796), + Offset(25.546020906725474, 22.73121343167271), + Offset(25.924910472907296, 23.45711910026985), + Offset(26.226713363010656, 22.438976497789707), + Offset(28.439149385074973, 19.790888035808678), + Offset(31.352279808561033, 19.031305818821522), + Offset(34.05522575327808, 19.389006977311787), + Offset(36.28346900677985, 20.312254377814725), + Offset(38.015522215909485, 21.45183249211633), + Offset(39.32116715374351, 22.597115166854078), + Offset(40.281743744541544, 23.632107095575087), + Offset(40.972502951927, 24.496880934136346), + Offset(41.45232535892349, 25.165910699099264), + Offset(41.76499988035462, 25.633841011569586), + Offset(41.940916461073456, 25.907274639160292), + Offset(41.9998801364125, 25.99980529932387), + Offset(42.0, 26.0), + ], + <Offset>[ + Offset(24.0, 22.0), + Offset(24.040185978508838, 22.000403768974525), + Offset(24.181019326543748, 22.00820884543142), + Offset(24.461936845635496, 22.054077506516684), + Offset(24.91719787006675, 22.22271328504796), + Offset(25.546020906725474, 22.73121343167271), + Offset(25.924910472907296, 23.45711910026985), + Offset(26.226713363010656, 22.438976497789707), + Offset(28.439149385074973, 19.790888035808678), + Offset(31.352279808561033, 19.031305818821522), + Offset(34.05522575327808, 19.389006977311787), + Offset(36.28346900677985, 20.312254377814725), + Offset(38.015522215909485, 21.45183249211633), + Offset(39.32116715374351, 22.597115166854078), + Offset(40.281743744541544, 23.632107095575087), + Offset(40.972502951927, 24.496880934136346), + Offset(41.45232535892349, 25.165910699099264), + Offset(41.76499988035462, 25.633841011569586), + Offset(41.940916461073456, 25.907274639160292), + Offset(41.9998801364125, 25.99980529932387), + Offset(42.0, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(24.0, 22.0), + Offset(24.040185978508838, 22.000403768974525), + Offset(24.181019326543748, 22.00820884543142), + Offset(24.461936845635496, 22.054077506516684), + Offset(24.91719787006675, 22.22271328504796), + Offset(25.546020906725474, 22.73121343167271), + Offset(25.924910472907296, 23.45711910026985), + Offset(26.226713363010656, 22.438976497789707), + Offset(28.439149385074973, 19.790888035808678), + Offset(31.352279808561033, 19.031305818821522), + Offset(34.05522575327808, 19.389006977311787), + Offset(36.28346900677985, 20.312254377814725), + Offset(38.015522215909485, 21.45183249211633), + Offset(39.32116715374351, 22.597115166854078), + Offset(40.281743744541544, 23.632107095575087), + Offset(40.972502951927, 24.496880934136346), + Offset(41.45232535892349, 25.165910699099264), + Offset(41.76499988035462, 25.633841011569586), + Offset(41.940916461073456, 25.907274639160292), + Offset(41.9998801364125, 25.99980529932387), + Offset(42.0, 26.0), + ], + <Offset>[ + Offset(24.0, 26.0), + Offset(23.959814021491162, 25.999596231025475), + Offset(23.818980673456252, 25.99179115456858), + Offset(23.538063154364504, 25.945922493483316), + Offset(23.08280212993325, 25.77728671495204), + Offset(22.453979093274526, 25.26878656832729), + Offset(22.075089527092704, 24.54288089973015), + Offset(22.262051805115647, 21.908449654595582), + Offset(24.88919842700383, 17.94756272667581), + Offset(28.423231797685485, 16.307213722363326), + Offset(31.75801074104301, 16.114437816710378), + Offset(34.549940992662854, 16.70741310193702), + Offset(36.75456537179234, 17.655783514919893), + Offset(38.441715273516245, 18.694992104934485), + Offset(39.70097192738563, 19.67449366114299), + Offset(40.617793553920194, 20.51263931960471), + Offset(41.26084924113239, 21.170496215429807), + Offset(41.68247655138362, 21.634692364647904), + Offset(41.92023728365015, 21.90732809306482), + Offset(41.99983686928147, 21.999805299557877), + Offset(42.0, 22.0), + ], + <Offset>[ + Offset(24.0, 26.0), + Offset(23.959814021491162, 25.999596231025475), + Offset(23.818980673456252, 25.99179115456858), + Offset(23.538063154364504, 25.945922493483316), + Offset(23.08280212993325, 25.77728671495204), + Offset(22.453979093274526, 25.26878656832729), + Offset(22.075089527092704, 24.54288089973015), + Offset(22.262051805115647, 21.908449654595582), + Offset(24.88919842700383, 17.94756272667581), + Offset(28.423231797685485, 16.307213722363326), + Offset(31.75801074104301, 16.114437816710378), + Offset(34.549940992662854, 16.70741310193702), + Offset(36.75456537179234, 17.655783514919893), + Offset(38.441715273516245, 18.694992104934485), + Offset(39.70097192738563, 19.67449366114299), + Offset(40.617793553920194, 20.51263931960471), + Offset(41.26084924113239, 21.170496215429807), + Offset(41.68247655138362, 21.634692364647904), + Offset(41.92023728365015, 21.90732809306482), + Offset(41.99983686928147, 21.999805299557877), + Offset(42.0, 22.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(9.857864376269049, 12.68629150101524), + Offset(10.0286848752889, 12.538401058257541), + Offset(10.632873267418944, 12.039156238673812), + Offset(11.869661541953974, 11.120999908012887), + Offset(14.01269232753313, 9.802147761233421), + Offset(17.63755687713399, 8.1644208393319), + Offset(21.40270587697591, 7.061028351517436), + Offset(25.372566440386116, 6.474033586994366), + Offset(29.043281052671396, 6.480169426635232), + Offset(32.12573791953512, 6.935455570385773), + Offset(34.627918413389764, 7.642591727654583), + Offset(36.617140423267614, 8.447772996169093), + Offset(38.17478812826869, 9.24831138340156), + Offset(39.37733102863164, 9.981782438812019), + Offset(40.28991005711473, 10.613640055506202), + Offset(40.96529784286365, 11.127522886831306), + Offset(41.445182774971684, 11.518668960278076), + Offset(41.761944370115955, 11.789503608737085), + Offset(41.94049711880572, 11.94681212872769), + Offset(41.99987560677617, 11.999888404963674), + Offset(42.0, 12.000000000000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(9.857864376269049, 12.68629150101524), + Offset(10.0286848752889, 12.538401058257541), + Offset(10.632873267418944, 12.039156238673812), + Offset(11.869661541953974, 11.120999908012887), + Offset(14.01269232753313, 9.802147761233421), + Offset(17.63755687713399, 8.1644208393319), + Offset(21.40270587697591, 7.061028351517436), + Offset(25.372566440386116, 6.474033586994366), + Offset(29.043281052671396, 6.480169426635232), + Offset(32.12573791953512, 6.935455570385773), + Offset(34.627918413389764, 7.642591727654583), + Offset(36.617140423267614, 8.447772996169093), + Offset(38.17478812826869, 9.24831138340156), + Offset(39.37733102863164, 9.981782438812019), + Offset(40.28991005711473, 10.613640055506202), + Offset(40.96529784286365, 11.127522886831306), + Offset(41.445182774971684, 11.518668960278076), + Offset(41.761944370115955, 11.789503608737085), + Offset(41.94049711880572, 11.94681212872769), + Offset(41.99987560677617, 11.999888404963674), + Offset(42.0, 12.000000000000002), + ], + <Offset>[ + Offset(35.31370849898477, 38.14213562373095), + Offset(35.09801389245515, 38.37497866886739), + Offset(34.30089322953512, 39.165247572901634), + Offset(32.51039870948586, 40.61608372177527), + Offset(28.957340520209982, 42.55359796419574), + Offset(22.04434118430577, 43.893684084885464), + Offset(14.726425304958642, 42.43654640742306), + Offset(8.351729390869856, 38.19612535493764), + Offset(4.454339035895707, 32.774349970923794), + Offset(2.747425156507667, 27.742058829873816), + Offset(2.3511131772704275, 23.586488483141284), + Offset(2.632378123985845, 20.323627974288197), + Offset(3.211174431823274, 17.82419135491087), + Offset(3.873722104158137, 15.939445851429909), + Offset(4.5046582506767905, 14.539930053688956), + Offset(5.04509760688121, 13.523188766482994), + Offset(5.468398892380936, 12.81134891500736), + Offset(5.766254411966681, 12.346553370240805), + Offset(5.940767729461317, 12.086396848425768), + Offset(5.999875607960821, 12.000180458137994), + Offset(5.9999999999999964, 12.000000000000005), + ], + <Offset>[ + Offset(35.31370849898477, 38.14213562373095), + Offset(35.09801389245515, 38.37497866886739), + Offset(34.30089322953512, 39.165247572901634), + Offset(32.51039870948586, 40.61608372177527), + Offset(28.957340520209982, 42.55359796419574), + Offset(22.04434118430577, 43.893684084885464), + Offset(14.726425304958642, 42.43654640742306), + Offset(8.351729390869856, 38.19612535493764), + Offset(4.454339035895707, 32.774349970923794), + Offset(2.747425156507667, 27.742058829873816), + Offset(2.3511131772704275, 23.586488483141284), + Offset(2.632378123985845, 20.323627974288197), + Offset(3.211174431823274, 17.82419135491087), + Offset(3.873722104158137, 15.939445851429909), + Offset(4.5046582506767905, 14.539930053688956), + Offset(5.04509760688121, 13.523188766482994), + Offset(5.468398892380936, 12.81134891500736), + Offset(5.766254411966681, 12.346553370240805), + Offset(5.940767729461317, 12.086396848425768), + Offset(5.999875607960821, 12.000180458137994), + Offset(5.9999999999999964, 12.000000000000005), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.31370849898477, 38.14213562373095), + Offset(35.09801389245515, 38.37497866886739), + Offset(34.30089322953512, 39.165247572901634), + Offset(32.51039870948586, 40.61608372177527), + Offset(28.957340520209982, 42.55359796419574), + Offset(22.04434118430577, 43.893684084885464), + Offset(14.726425304958642, 42.43654640742306), + Offset(8.351729390869856, 38.19612535493764), + Offset(4.454339035895707, 32.774349970923794), + Offset(2.747425156507667, 27.742058829873816), + Offset(2.3511131772704275, 23.586488483141284), + Offset(2.632378123985845, 20.323627974288197), + Offset(3.211174431823274, 17.82419135491087), + Offset(3.873722104158137, 15.939445851429909), + Offset(4.5046582506767905, 14.539930053688956), + Offset(5.04509760688121, 13.523188766482994), + Offset(5.468398892380936, 12.81134891500736), + Offset(5.766254411966681, 12.346553370240805), + Offset(5.940767729461317, 12.086396848425768), + Offset(5.999875607960821, 12.000180458137994), + Offset(5.9999999999999964, 12.000000000000005), + ], + <Offset>[ + Offset(38.14213562373095, 35.31370849898476), + Offset(37.96874473807846, 35.58949766696003), + Offset(37.314903377782656, 36.53546757711095), + Offset(35.78763024434835, 38.32266848093839), + Offset(32.59639054276135, 40.89308149834275), + Offset(26.01425932270061, 43.4040413840886), + Offset(18.657038422281488, 43.17835535986942), + Offset(11.876406253974665, 40.08732947155056), + Offset(7.375914651927772, 35.506454639454425), + Offset(5.059269963117448, 31.006315803543533), + Offset(4.122657261213394, 27.17280017604343), + Offset(3.9519175659990786, 24.099712674208394), + Offset(4.164049984213197, 21.709037321182585), + Offset(4.535684705560126, 19.884291287482522), + Offset(4.940912694919316, 18.516069143293173), + Offset(5.3112827046202895, 17.514322126036596), + Offset(5.612029998461967, 16.80876934640633), + Offset(5.828148829911537, 16.346074476701837), + Offset(5.9562771427611025, 16.086366780575148), + Offset(5.9999080583135225, 16.000180458006366), + Offset(5.9999999999999964, 16.000000000000007), + ], + <Offset>[ + Offset(38.14213562373095, 35.31370849898476), + Offset(37.96874473807846, 35.58949766696003), + Offset(37.314903377782656, 36.53546757711095), + Offset(35.78763024434835, 38.32266848093839), + Offset(32.59639054276135, 40.89308149834275), + Offset(26.01425932270061, 43.4040413840886), + Offset(18.657038422281488, 43.17835535986942), + Offset(11.876406253974665, 40.08732947155056), + Offset(7.375914651927772, 35.506454639454425), + Offset(5.059269963117448, 31.006315803543533), + Offset(4.122657261213394, 27.17280017604343), + Offset(3.9519175659990786, 24.099712674208394), + Offset(4.164049984213197, 21.709037321182585), + Offset(4.535684705560126, 19.884291287482522), + Offset(4.940912694919316, 18.516069143293173), + Offset(5.3112827046202895, 17.514322126036596), + Offset(5.612029998461967, 16.80876934640633), + Offset(5.828148829911537, 16.346074476701837), + Offset(5.9562771427611025, 16.086366780575148), + Offset(5.9999080583135225, 16.000180458006366), + Offset(5.9999999999999964, 16.000000000000007), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.14213562373095, 35.31370849898476), + Offset(37.96874473807846, 35.58949766696003), + Offset(37.314903377782656, 36.53546757711095), + Offset(35.78763024434835, 38.32266848093839), + Offset(32.59639054276135, 40.89308149834275), + Offset(26.01425932270061, 43.4040413840886), + Offset(18.657038422281488, 43.17835535986942), + Offset(11.876406253974665, 40.08732947155056), + Offset(7.375914651927772, 35.506454639454425), + Offset(5.059269963117448, 31.006315803543533), + Offset(4.122657261213394, 27.17280017604343), + Offset(3.9519175659990786, 24.099712674208394), + Offset(4.164049984213197, 21.709037321182585), + Offset(4.535684705560126, 19.884291287482522), + Offset(4.940912694919316, 18.516069143293173), + Offset(5.3112827046202895, 17.514322126036596), + Offset(5.612029998461967, 16.80876934640633), + Offset(5.828148829911537, 16.346074476701837), + Offset(5.9562771427611025, 16.086366780575148), + Offset(5.9999080583135225, 16.000180458006366), + Offset(5.9999999999999964, 16.000000000000007), + ], + <Offset>[ + Offset(12.68629150101524, 9.857864376269049), + Offset(12.899415720912216, 9.75292005635018), + Offset(13.64688341566648, 9.409376242883125), + Offset(15.146893076816461, 8.82758466717601), + Offset(17.651742350084497, 8.141631295380437), + Offset(21.607475015528827, 7.674778138535036), + Offset(25.333318994298757, 7.802837303963798), + Offset(28.897243303490924, 8.365237703607285), + Offset(31.96485666870346, 9.212274095165863), + Offset(34.437582726144896, 10.19971254405549), + Offset(36.399462497332735, 11.228903420556733), + Offset(37.93667986528085, 12.22385769608929), + Offset(39.127663680658614, 13.133157349673274), + Offset(40.039293630033626, 13.926627874864629), + Offset(40.72616450135726, 14.58977914511042), + Offset(41.231482940602724, 15.118656246384909), + Offset(41.588813881052715, 15.516089391677047), + Offset(41.82383878806081, 15.789024715198115), + Offset(41.956006532105505, 15.946782060877066), + Offset(41.99990805712887, 15.999888404832046), + Offset(42.0, 16.0), + ], + <Offset>[ + Offset(12.68629150101524, 9.857864376269049), + Offset(12.899415720912216, 9.75292005635018), + Offset(13.64688341566648, 9.409376242883125), + Offset(15.146893076816461, 8.82758466717601), + Offset(17.651742350084497, 8.141631295380437), + Offset(21.607475015528827, 7.674778138535036), + Offset(25.333318994298757, 7.802837303963798), + Offset(28.897243303490924, 8.365237703607285), + Offset(31.96485666870346, 9.212274095165863), + Offset(34.437582726144896, 10.19971254405549), + Offset(36.399462497332735, 11.228903420556733), + Offset(37.93667986528085, 12.22385769608929), + Offset(39.127663680658614, 13.133157349673274), + Offset(40.039293630033626, 13.926627874864629), + Offset(40.72616450135726, 14.58977914511042), + Offset(41.231482940602724, 15.118656246384909), + Offset(41.588813881052715, 15.516089391677047), + Offset(41.82383878806081, 15.789024715198115), + Offset(41.956006532105505, 15.946782060877066), + Offset(41.99990805712887, 15.999888404832046), + Offset(42.0, 16.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.68629150101524, 9.857864376269049), + Offset(12.899415720912216, 9.75292005635018), + Offset(13.64688341566648, 9.409376242883125), + Offset(15.146893076816461, 8.82758466717601), + Offset(17.651742350084497, 8.141631295380437), + Offset(21.607475015528827, 7.674778138535036), + Offset(25.333318994298757, 7.802837303963798), + Offset(28.897243303490924, 8.365237703607285), + Offset(31.96485666870346, 9.212274095165863), + Offset(34.437582726144896, 10.19971254405549), + Offset(36.399462497332735, 11.228903420556733), + Offset(37.93667986528085, 12.22385769608929), + Offset(39.127663680658614, 13.133157349673274), + Offset(40.039293630033626, 13.926627874864629), + Offset(40.72616450135726, 14.58977914511042), + Offset(41.231482940602724, 15.118656246384909), + Offset(41.588813881052715, 15.516089391677047), + Offset(41.82383878806081, 15.789024715198115), + Offset(41.956006532105505, 15.946782060877066), + Offset(41.99990805712887, 15.999888404832046), + Offset(42.0, 16.0), + ], + <Offset>[ + Offset(9.857864376269049, 12.68629150101524), + Offset(10.0286848752889, 12.538401058257541), + Offset(10.632873267418944, 12.039156238673812), + Offset(11.869661541953974, 11.120999908012887), + Offset(14.01269232753313, 9.802147761233421), + Offset(17.63755687713399, 8.1644208393319), + Offset(21.40270587697591, 7.061028351517436), + Offset(25.372566440386116, 6.474033586994366), + Offset(29.043281052671396, 6.480169426635232), + Offset(32.12573791953512, 6.935455570385773), + Offset(34.627918413389764, 7.642591727654583), + Offset(36.617140423267614, 8.447772996169093), + Offset(38.17478812826869, 9.24831138340156), + Offset(39.37733102863164, 9.981782438812019), + Offset(40.28991005711473, 10.613640055506202), + Offset(40.96529784286365, 11.127522886831306), + Offset(41.445182774971684, 11.518668960278076), + Offset(41.761944370115955, 11.789503608737085), + Offset(41.94049711880572, 11.94681212872769), + Offset(41.99987560677617, 11.999888404963674), + Offset(42.0, 12.000000000000002), + ], + <Offset>[ + Offset(9.857864376269049, 12.68629150101524), + Offset(10.0286848752889, 12.538401058257541), + Offset(10.632873267418944, 12.039156238673812), + Offset(11.869661541953974, 11.120999908012887), + Offset(14.01269232753313, 9.802147761233421), + Offset(17.63755687713399, 8.1644208393319), + Offset(21.40270587697591, 7.061028351517436), + Offset(25.372566440386116, 6.474033586994366), + Offset(29.043281052671396, 6.480169426635232), + Offset(32.12573791953512, 6.935455570385773), + Offset(34.627918413389764, 7.642591727654583), + Offset(36.617140423267614, 8.447772996169093), + Offset(38.17478812826869, 9.24831138340156), + Offset(39.37733102863164, 9.981782438812019), + Offset(40.28991005711473, 10.613640055506202), + Offset(40.96529784286365, 11.127522886831306), + Offset(41.445182774971684, 11.518668960278076), + Offset(41.761944370115955, 11.789503608737085), + Offset(41.94049711880572, 11.94681212872769), + Offset(41.99987560677617, 11.999888404963674), + Offset(42.0, 12.000000000000002), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(12.686291501015244, 38.14213562373095), + Offset(12.335961696184835, 37.78957826421869), + Offset(11.186164512970027, 36.485148967548454), + Offset(9.272264829328229, 33.57462824174341), + Offset(7.396433901397504, 28.01370476875244), + Offset(8.455221168610253, 18.46855392229577), + Offset(14.400164412415048, 10.886305797611346), + Offset(23.385743674953297, 7.627722418507858), + Offset(31.513897019057687, 8.97811161083639), + Offset(37.00821523813391, 12.590468749760188), + Offset(40.228807248234226, 16.687449599224042), + Offset(41.900283080823314, 20.466101465000598), + Offset(42.622994421193994, 23.65567978529433), + Offset(42.809759514234806, 26.219169470442615), + Offset(42.724595353131164, 28.207893098186), + Offset(42.529420070562, 29.69761906859474), + Offset(42.319508324086705, 30.763041306693708), + Offset(42.1473924208978, 31.468700863761335), + Offset(42.038312568419684, 31.86713222464318), + Offset(42.00008112385512, 31.999722191105658), + Offset(42.0, 32.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.686291501015244, 38.14213562373095), + Offset(12.335961696184835, 37.78957826421869), + Offset(11.186164512970027, 36.485148967548454), + Offset(9.272264829328229, 33.57462824174341), + Offset(7.396433901397504, 28.01370476875244), + Offset(8.455221168610253, 18.46855392229577), + Offset(14.400164412415048, 10.886305797611346), + Offset(23.385743674953297, 7.627722418507858), + Offset(31.513897019057687, 8.97811161083639), + Offset(37.00821523813391, 12.590468749760188), + Offset(40.228807248234226, 16.687449599224042), + Offset(41.900283080823314, 20.466101465000598), + Offset(42.622994421193994, 23.65567978529433), + Offset(42.809759514234806, 26.219169470442615), + Offset(42.724595353131164, 28.207893098186), + Offset(42.529420070562, 29.69761906859474), + Offset(42.319508324086705, 30.763041306693708), + Offset(42.1473924208978, 31.468700863761335), + Offset(42.038312568419684, 31.86713222464318), + Offset(42.00008112385512, 31.999722191105658), + Offset(42.0, 32.0), + ], + <Offset>[ + Offset(38.14213562373096, 12.686291501015244), + Offset(38.423106864699406, 12.98109469595424), + Offset(39.356600322670786, 14.070275639966862), + Offset(40.967250034331684, 16.50336839208347), + Offset(42.74943078741556, 21.21917673678452), + Offset(42.63823566995957, 29.761096576655866), + Offset(38.576286786907716, 37.560546310389874), + Offset(31.46737791244584, 42.70887388266861), + Offset(24.151451365764814, 44.21721480604141), + Offset(18.383677101408267, 43.39836675000767), + Offset(14.25135866363073, 41.61077532101089), + Offset(11.404888461060231, 39.59803568464825), + Offset(9.477230898414673, 37.70410889647938), + Offset(8.1829838828817, 36.06733728866804), + Offset(7.320063260869414, 34.72856080387442), + Offset(6.750940467797069, 33.68514929600791), + Offset(6.383985215921761, 32.91668448571468), + Offset(6.159364334665909, 32.39705126344063), + Offset(6.0390642630099585, 32.09977238767511), + Offset(6.000081127145819, 32.000208946289966), + Offset(5.9999999999999964, 32.00000000000001), + ], + <Offset>[ + Offset(38.14213562373096, 12.686291501015244), + Offset(38.423106864699406, 12.98109469595424), + Offset(39.356600322670786, 14.070275639966862), + Offset(40.967250034331684, 16.50336839208347), + Offset(42.74943078741556, 21.21917673678452), + Offset(42.63823566995957, 29.761096576655866), + Offset(38.576286786907716, 37.560546310389874), + Offset(31.46737791244584, 42.70887388266861), + Offset(24.151451365764814, 44.21721480604141), + Offset(18.383677101408267, 43.39836675000767), + Offset(14.25135866363073, 41.61077532101089), + Offset(11.404888461060231, 39.59803568464825), + Offset(9.477230898414673, 37.70410889647938), + Offset(8.1829838828817, 36.06733728866804), + Offset(7.320063260869414, 34.72856080387442), + Offset(6.750940467797069, 33.68514929600791), + Offset(6.383985215921761, 32.91668448571468), + Offset(6.159364334665909, 32.39705126344063), + Offset(6.0390642630099585, 32.09977238767511), + Offset(6.000081127145819, 32.000208946289966), + Offset(5.9999999999999964, 32.00000000000001), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.14213562373096, 12.686291501015244), + Offset(38.423106864699406, 12.98109469595424), + Offset(39.356600322670786, 14.070275639966862), + Offset(40.967250034331684, 16.50336839208347), + Offset(42.74943078741556, 21.21917673678452), + Offset(42.63823566995957, 29.761096576655866), + Offset(38.576286786907716, 37.560546310389874), + Offset(31.46737791244584, 42.70887388266861), + Offset(24.151451365764814, 44.21721480604141), + Offset(18.383677101408267, 43.39836675000767), + Offset(14.25135866363073, 41.61077532101089), + Offset(11.404888461060231, 39.59803568464825), + Offset(9.477230898414673, 37.70410889647938), + Offset(8.1829838828817, 36.06733728866804), + Offset(7.320063260869414, 34.72856080387442), + Offset(6.750940467797069, 33.68514929600791), + Offset(6.383985215921761, 32.91668448571468), + Offset(6.159364334665909, 32.39705126344063), + Offset(6.0390642630099585, 32.09977238767511), + Offset(6.000081127145819, 32.000208946289966), + Offset(5.9999999999999964, 32.00000000000001), + ], + <Offset>[ + Offset(35.31370849898477, 9.857864376269053), + Offset(35.6666086904478, 10.082523010563733), + Offset(36.86605884182839, 10.940227216666777), + Offset(39.07044338436947, 12.981703369305308), + Offset(41.99448322830801, 17.2910659716714), + Offset(43.892962631555136, 25.96298385428372), + Offset(41.540091288327545, 34.8743104910018), + Offset(35.36528363068592, 41.81091452294722), + Offset(28.066907276343148, 45.035264323073946), + Offset(21.806776879213544, 45.46775987631051), + Offset(17.0206170771626, 44.49715849707795), + Offset(13.530658929909972, 42.986412864621926), + Offset(11.038167466324122, 41.386971510121526), + Offset(9.277224751573414, 39.91475680326283), + Offset(8.044581894834794, 38.66239770301462), + Offset(7.193999381954086, 37.66053591853735), + Offset(6.6232789024796475, 36.90952038662189), + Offset(6.2625143790747195, 36.39572105079973), + Offset(6.064913170013508, 36.09968886605397), + Offset(6.000135211055188, 36.00020894592433), + Offset(5.9999999999999964, 36.00000000000001), + ], + <Offset>[ + Offset(35.31370849898477, 9.857864376269053), + Offset(35.6666086904478, 10.082523010563733), + Offset(36.86605884182839, 10.940227216666777), + Offset(39.07044338436947, 12.981703369305308), + Offset(41.99448322830801, 17.2910659716714), + Offset(43.892962631555136, 25.96298385428372), + Offset(41.540091288327545, 34.8743104910018), + Offset(35.36528363068592, 41.81091452294722), + Offset(28.066907276343148, 45.035264323073946), + Offset(21.806776879213544, 45.46775987631051), + Offset(17.0206170771626, 44.49715849707795), + Offset(13.530658929909972, 42.986412864621926), + Offset(11.038167466324122, 41.386971510121526), + Offset(9.277224751573414, 39.91475680326283), + Offset(8.044581894834794, 38.66239770301462), + Offset(7.193999381954086, 37.66053591853735), + Offset(6.6232789024796475, 36.90952038662189), + Offset(6.2625143790747195, 36.39572105079973), + Offset(6.064913170013508, 36.09968886605397), + Offset(6.000135211055188, 36.00020894592433), + Offset(5.9999999999999964, 36.00000000000001), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.31370849898477, 9.857864376269053), + Offset(35.6666086904478, 10.082523010563733), + Offset(36.86605884182839, 10.940227216666777), + Offset(39.07044338436947, 12.981703369305308), + Offset(41.99448322830801, 17.2910659716714), + Offset(43.892962631555136, 25.96298385428372), + Offset(41.540091288327545, 34.8743104910018), + Offset(35.36528363068592, 41.81091452294722), + Offset(28.066907276343148, 45.035264323073946), + Offset(21.806776879213544, 45.46775987631051), + Offset(17.0206170771626, 44.49715849707795), + Offset(13.530658929909972, 42.986412864621926), + Offset(11.038167466324122, 41.386971510121526), + Offset(9.277224751573414, 39.91475680326283), + Offset(8.044581894834794, 38.66239770301462), + Offset(7.193999381954086, 37.66053591853735), + Offset(6.6232789024796475, 36.90952038662189), + Offset(6.2625143790747195, 36.39572105079973), + Offset(6.064913170013508, 36.09968886605397), + Offset(6.000135211055188, 36.00020894592433), + Offset(5.9999999999999964, 36.00000000000001), + ], + <Offset>[ + Offset(9.857864376269053, 35.31370849898477), + Offset(9.579463521933231, 34.89100657882818), + Offset(8.695623032127628, 33.35510054424837), + Offset(7.375458179366014, 30.052963218965253), + Offset(6.641486342289959, 24.085594003639322), + Offset(9.70994813020582, 14.670441199923623), + Offset(17.36396891383488, 8.200069978223272), + Offset(27.283649393193382, 6.729763058786467), + Offset(35.429352929636025, 9.796161127868931), + Offset(40.431315015939184, 14.659861876063037), + Offset(42.99806566176609, 19.573832775291095), + Offset(44.02605354967305, 23.854478644974275), + Offset(44.183930989103445, 27.338542398936475), + Offset(43.90400038292652, 30.066588985037402), + Offset(43.44911398709654, 32.141729997326195), + Offset(42.97247898471902, 33.673005691124175), + Offset(42.55880201064459, 34.75587720760092), + Offset(42.25054246530661, 35.46737065112043), + Offset(42.064161475423234, 35.867048703022036), + Offset(42.00013520776449, 35.99972219074003), + Offset(42.0, 36.0), + ], + <Offset>[ + Offset(9.857864376269053, 35.31370849898477), + Offset(9.579463521933231, 34.89100657882818), + Offset(8.695623032127628, 33.35510054424837), + Offset(7.375458179366014, 30.052963218965253), + Offset(6.641486342289959, 24.085594003639322), + Offset(9.70994813020582, 14.670441199923623), + Offset(17.36396891383488, 8.200069978223272), + Offset(27.283649393193382, 6.729763058786467), + Offset(35.429352929636025, 9.796161127868931), + Offset(40.431315015939184, 14.659861876063037), + Offset(42.99806566176609, 19.573832775291095), + Offset(44.02605354967305, 23.854478644974275), + Offset(44.183930989103445, 27.338542398936475), + Offset(43.90400038292652, 30.066588985037402), + Offset(43.44911398709654, 32.141729997326195), + Offset(42.97247898471902, 33.673005691124175), + Offset(42.55880201064459, 34.75587720760092), + Offset(42.25054246530661, 35.46737065112043), + Offset(42.064161475423234, 35.867048703022036), + Offset(42.00013520776449, 35.99972219074003), + Offset(42.0, 36.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(9.857864376269053, 35.31370849898477), + Offset(9.579463521933231, 34.89100657882818), + Offset(8.695623032127628, 33.35510054424837), + Offset(7.375458179366014, 30.052963218965253), + Offset(6.641486342289959, 24.085594003639322), + Offset(9.70994813020582, 14.670441199923623), + Offset(17.36396891383488, 8.200069978223272), + Offset(27.283649393193382, 6.729763058786467), + Offset(35.429352929636025, 9.796161127868931), + Offset(40.431315015939184, 14.659861876063037), + Offset(42.99806566176609, 19.573832775291095), + Offset(44.02605354967305, 23.854478644974275), + Offset(44.183930989103445, 27.338542398936475), + Offset(43.90400038292652, 30.066588985037402), + Offset(43.44911398709654, 32.141729997326195), + Offset(42.97247898471902, 33.673005691124175), + Offset(42.55880201064459, 34.75587720760092), + Offset(42.25054246530661, 35.46737065112043), + Offset(42.064161475423234, 35.867048703022036), + Offset(42.00013520776449, 35.99972219074003), + Offset(42.0, 36.0), + ], + <Offset>[ + Offset(12.686291501015244, 38.14213562373095), + Offset(12.335961696184835, 37.78957826421869), + Offset(11.186164512970027, 36.485148967548454), + Offset(9.272264829328229, 33.57462824174341), + Offset(7.396433901397504, 28.01370476875244), + Offset(8.455221168610253, 18.46855392229577), + Offset(14.400164412415048, 10.886305797611346), + Offset(23.385743674953297, 7.627722418507858), + Offset(31.513897019057687, 8.97811161083639), + Offset(37.00821523813391, 12.590468749760188), + Offset(40.228807248234226, 16.687449599224042), + Offset(41.900283080823314, 20.466101465000598), + Offset(42.622994421193994, 23.65567978529433), + Offset(42.809759514234806, 26.219169470442615), + Offset(42.724595353131164, 28.207893098186), + Offset(42.529420070562, 29.69761906859474), + Offset(42.319508324086705, 30.763041306693708), + Offset(42.1473924208978, 31.468700863761335), + Offset(42.038312568419684, 31.86713222464318), + Offset(42.00008112385512, 31.999722191105658), + Offset(42.0, 32.0), + ], + <Offset>[ + Offset(12.686291501015244, 38.14213562373095), + Offset(12.335961696184835, 37.78957826421869), + Offset(11.186164512970027, 36.485148967548454), + Offset(9.272264829328229, 33.57462824174341), + Offset(7.396433901397504, 28.01370476875244), + Offset(8.455221168610253, 18.46855392229577), + Offset(14.400164412415048, 10.886305797611346), + Offset(23.385743674953297, 7.627722418507858), + Offset(31.513897019057687, 8.97811161083639), + Offset(37.00821523813391, 12.590468749760188), + Offset(40.228807248234226, 16.687449599224042), + Offset(41.900283080823314, 20.466101465000598), + Offset(42.622994421193994, 23.65567978529433), + Offset(42.809759514234806, 26.219169470442615), + Offset(42.724595353131164, 28.207893098186), + Offset(42.529420070562, 29.69761906859474), + Offset(42.319508324086705, 30.763041306693708), + Offset(42.1473924208978, 31.468700863761335), + Offset(42.038312568419684, 31.86713222464318), + Offset(42.00008112385512, 31.999722191105658), + Offset(42.0, 32.0), + ], + ), + _PathClose( + ), + ], + ), + ], +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/ellipsis_search.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/ellipsis_search.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..9f539c6c8de980e7c755c1eb558da3522696c7c3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/ellipsis_search.g.dart @@ -0,0 +1,5267 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$ellipsis_search = _AnimatedIconData( + Size(96.0, 96.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(57.62369742449878, 56.510753652468935), + Offset(57.50386046799878, 56.38647829016894), + Offset(57.38402351149878, 56.26220292786894), + Offset(57.26418655499878, 56.13792756556894), + Offset(57.144349598398776, 56.01365220316894), + Offset(57.02451264189878, 55.88937684086894), + Offset(56.90467568539878, 55.76510147856894), + Offset(56.78483872889878, 55.64082611626894), + Offset(56.66500177229878, 55.516550753968936), + Offset(56.54516481579878, 55.39227539166894), + Offset(56.42532785929878, 55.26800002926894), + Offset(56.30549090279878, 55.143724666968936), + Offset(56.18565394629878, 55.01944930466894), + Offset(56.06581698969878, 54.895173942368935), + Offset(55.94598003319878, 54.77089858006894), + Offset(55.89372930109525, 54.63379537519879), + Offset(55.99467401074788, 54.46761572737509), + Offset(56.09561872053984, 54.30143607948509), + Offset(56.19656343029247, 54.13525643166141), + Offset(56.297508139945094, 53.969076783837714), + Offset(56.398452849697726, 53.80289713591403), + Offset(56.49939755945036, 53.63671748809034), + Offset(56.297960835674125, 53.25914221256317), + Offset(55.78881270857159, 52.69340023656423), + Offset(56.006714995568615, 52.88005225271881), + Offset(56.182356492271566, 53.03050427381422), + Offset(56.32344115337003, 53.15135539844181), + Offset(56.43452394733299, 53.246507348148306), + Offset(56.52071628832435, 53.320338487990085), + Offset(56.5859271296418, 53.37619717205798), + Offset(56.63368824673307, 53.417108669232874), + Offset(56.66699682004896, 53.44564032188472), + Offset(56.68847407317482, 53.46403743305161), + Offset(56.70040259814858, 53.474255238779065), + Offset(56.70477862272339, 53.478003679517734), + Offset(56.70335264548873, 53.47678220759329), + Offset(56.69766279856795, 53.471908365221054), + Offset(56.689065722138324, 53.46454423118308), + Offset(56.678761173675056, 53.45571750075846), + Offset(56.667817449874256, 53.44634326178278), + Offset(56.657150392580974, 53.43720601142315), + Offset(56.64761589840118, 53.429038898603), + Offset(56.639944407998925, 53.42246760846087), + Offset(56.63479944561546, 53.418060506474255), + Offset(56.632765532511705, 53.416318285285435), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(59.11722254046772, 54.78101039685442), + Offset(58.99738558396772, 54.65673503455442), + Offset(58.877548627467725, 54.532459672254426), + Offset(58.75771167096772, 54.40818430995442), + Offset(58.63787471436772, 54.28390894755442), + Offset(58.518037757867724, 54.159633585254426), + Offset(58.39820080136772, 54.03535822295442), + Offset(58.27836384486772, 53.911082860654425), + Offset(58.15852688826772, 53.78680749835442), + Offset(58.03868993176772, 53.66253213605442), + Offset(57.918852975267725, 53.538256773654425), + Offset(57.79901601876772, 53.41398141135442), + Offset(57.67917906226772, 53.28970604905442), + Offset(57.559342105667724, 53.16543068675442), + Offset(57.43950514916772, 53.04115532445442), + Offset(57.485490128564514, 52.790279302768965), + Offset(57.907338162449705, 52.252441786684095), + Offset(58.32918619648207, 51.71460427052383), + Offset(58.75103423046726, 51.176766754438965), + Offset(59.17288226435245, 50.63892923835408), + Offset(59.59473029833764, 50.101091722169215), + Offset(60.01657833232283, 49.56325420608434), + Offset(60.01932238869081, 48.94920461646341), + Offset(59.563472601893324, 48.32173455588634), + Offset(59.82481548777557, 48.45807534383447), + Offset(60.035472549991965, 48.56797368582478), + Offset(60.204683589459826, 48.656249922511655), + Offset(60.33791164477868, 48.72575408359739), + Offset(60.441287132232546, 48.77968436513692), + Offset(60.51949828685408, 48.820486587135186), + Offset(60.57678097234404, 48.850370570581376), + Offset(60.61672988153154, 48.871211642026296), + Offset(60.64248880031156, 48.88464989297123), + Offset(60.65679537406957, 48.892113534204164), + Offset(60.66204379484951, 48.89485159926458), + Offset(60.66033353741787, 48.89395936971321), + Offset(60.65350937308716, 48.890399250068874), + Offset(60.643198399323495, 48.885020085900294), + Offset(60.630839555044176, 48.87857256175406), + Offset(60.617714110608446, 48.87172510757334), + Offset(60.60492048840596, 48.86505076277184), + Offset(60.593485215014766, 48.85908505921234), + Offset(60.58428435040535, 48.85428503136227), + Offset(60.57811369779046, 48.85106584428997), + Offset(60.575674307513765, 48.84979323114302), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + ], + <Offset>[ + Offset(60.01637695941208, 52.53311272229554), + Offset(59.896540002912076, 52.408837359995545), + Offset(59.77670304641208, 52.28456199769555), + Offset(59.65686608991208, 52.160286635395536), + Offset(59.537029133312075, 52.03601127299554), + Offset(59.41719217681208, 51.91173591069554), + Offset(59.29735522031208, 51.78746054839554), + Offset(59.177518263812075, 51.663185186095546), + Offset(59.05768130721208, 51.538909823795535), + Offset(58.937844350712076, 51.41463446149554), + Offset(58.81800739421208, 51.29035909909554), + Offset(58.69817043771208, 51.16608373679554), + Offset(58.57833348121208, 51.041808374495545), + Offset(58.45849652461208, 50.917533012195534), + Offset(58.33865956811208, 50.79325764989554), + Offset(58.44378588577579, 50.39452751777087), + Offset(59.058828957998486, 49.37369990758731), + Offset(59.673872030373076, 48.35287229731656), + Offset(60.28891510269577, 47.332044687133006), + Offset(60.90395817491846, 46.31121707694944), + Offset(61.51900124724116, 45.290389466665886), + Offset(62.13404431956385, 44.26956185648232), + Offset(62.259712355426515, 43.348200728562944), + Offset(61.83595003585357, 42.64051158499319), + Offset(62.12344568343471, 42.711470130505994), + Offset(62.35518334223874, 42.76866670842857), + Offset(62.54132744639319, 42.81461006443314), + Offset(62.68788772451427, 42.85078349611087), + Offset(62.80160806784497, 42.87885150418633), + Offset(62.88764586631069, 42.90008701536577), + Offset(62.95066086939573, 42.91564013069819), + Offset(62.9946074933042, 42.92648686364521), + Offset(63.02294412474014, 42.933480799617264), + Offset(63.038682367138975, 42.93736525073486), + Offset(63.04445600098332, 42.9387902763426), + Offset(63.042574596918385, 42.938325915587605), + Offset(63.03506753378623, 42.936473051777625), + Offset(63.02372473381152, 42.93367346647948), + Offset(63.010129131515164, 42.93031785336868), + Offset(62.99569021485936, 42.92675409672298), + Offset(62.981616326115095, 42.92328043483138), + Offset(62.969036717078595, 42.92017558518285), + Offset(62.958915115642, 42.91767741130702), + Offset(62.952126961590935, 42.916001985810205), + Offset(62.94944345985745, 42.91533965446192), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + ], + <Offset>[ + Offset(60.01637695941208, 50.07184435071208), + Offset(59.896540002912076, 49.94756898841208), + Offset(59.77670304641208, 49.82329362611208), + Offset(59.65686608991208, 49.69901826381208), + Offset(59.537029133312075, 49.57474290141208), + Offset(59.41719217681208, 49.45046753911208), + Offset(59.29735522031208, 49.32619217681208), + Offset(59.177518263812075, 49.20191681451208), + Offset(59.05768130721208, 49.07764145221208), + Offset(58.937844350712076, 48.95336608991208), + Offset(58.81800739421208, 48.82909072751208), + Offset(58.69817043771208, 48.70481536521208), + Offset(58.57833348121208, 48.58054000291208), + Offset(58.45849652461208, 48.456264640612076), + Offset(58.33865956811208, 48.33198927831208), + Offset(58.44378588577579, 47.77137070715779), + Offset(59.058828957998486, 46.22170752948048), + Offset(59.673872030373076, 44.67204435170307), + Offset(60.28891510269577, 43.12238117402577), + Offset(60.90395817491846, 41.57271799634846), + Offset(61.51900124724116, 40.023054818571154), + Offset(62.13404431956385, 38.47339164089385), + Offset(62.259712355426515, 37.21554892931651), + Offset(61.83595003585357, 36.42002629848357), + Offset(62.12344568343471, 36.4193965118447), + Offset(62.35518334223874, 36.41888886839874), + Offset(62.54132744639319, 36.41848110198319), + Offset(62.68788772451427, 36.41816004771427), + Offset(62.80160806784497, 36.41791093245497), + Offset(62.88764586631069, 36.4177224584507), + Offset(62.95066086939573, 36.417584418075734), + Offset(62.9946074933042, 36.4174881488042), + Offset(63.02294412474014, 36.41742607471014), + Offset(63.038682367138975, 36.41739159858898), + Offset(63.04445600098332, 36.417378950893315), + Offset(63.042574596918385, 36.41738307228838), + Offset(63.03506753378623, 36.41739951722624), + Offset(63.02372473381152, 36.417424364711515), + Offset(63.010129131515164, 36.417454147175164), + Offset(62.99569021485936, 36.41748577699936), + Offset(62.981616326115095, 36.41751660719509), + Offset(62.969036717078595, 36.4175441640286), + Offset(62.958915115642, 36.41756633636199), + Offset(62.952126961590935, 36.41758120646094), + Offset(62.94944345985745, 36.41758708492745), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(60.01637695941208, 44.60068993176772), + Offset(59.896540002912076, 44.47641456946772), + Offset(59.77670304641208, 44.352139207167724), + Offset(59.65686608991208, 44.22786384486772), + Offset(59.537029133312075, 44.10358848246772), + Offset(59.41719217681208, 43.979313120167724), + Offset(59.29735522031208, 43.85503775786772), + Offset(59.177518263812075, 43.73076239556772), + Offset(59.05768130721208, 43.60648703326772), + Offset(58.937844350712076, 43.48221167096772), + Offset(58.81800739421208, 43.35793630856772), + Offset(58.69817043771208, 43.23366094626772), + Offset(58.57833348121208, 43.10938558396772), + Offset(58.45849652461208, 42.98511022166772), + Offset(58.33865956811208, 42.86083485936772), + Offset(58.44378588577579, 41.94035441423051), + Offset(59.058828957998486, 39.2151424482157), + Offset(59.673872030373076, 36.48993048207206), + Offset(60.28891510269577, 33.76471851605726), + Offset(60.90395817491846, 31.039506550042443), + Offset(61.51900124724116, 28.314294583927637), + Offset(62.13404431956385, 25.58908261791283), + Offset(62.259712355426515, 23.5832748633608), + Offset(61.83595003585357, 22.59250713958332), + Offset(62.12344568343471, 22.432743621605564), + Offset(62.35518334223874, 22.303965242071957), + Offset(62.54132744639319, 22.20052354762982), + Offset(62.68788772451427, 22.11907888637867), + Offset(62.80160806784497, 22.05588362666254), + Offset(62.88764586631069, 22.00807176767408), + Offset(62.95066086939573, 21.973053851184037), + Offset(62.9946074933042, 21.948632378031544), + Offset(63.02294412474014, 21.932885496421555), + Offset(63.038682367138975, 21.92413963541956), + Offset(63.04445600098332, 21.920931183179505), + Offset(63.042574596918385, 21.92197669372786), + Offset(63.03506753378623, 21.926148425807156), + Offset(63.02372473381152, 21.93245170602349), + Offset(63.010129131515164, 21.940006885624168), + Offset(62.99569021485936, 21.94803070142844), + Offset(62.981616326115095, 21.955851668445952), + Offset(62.969036717078595, 21.962842252864764), + Offset(62.958915115642, 21.968466903765343), + Offset(62.952126961590935, 21.972239132600446), + Offset(62.94944345985745, 21.973730374923758), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + ], + <Offset>[ + Offset(55.58154300555442, 40.16584435071208), + Offset(55.46170604905442, 40.04156898841208), + Offset(55.341869092554425, 39.917293626112084), + Offset(55.22203213605442, 39.79301826381208), + Offset(55.10219517945442, 39.66874290141208), + Offset(54.982358222954424, 39.544467539112084), + Offset(54.86252126645442, 39.42019217681208), + Offset(54.74268430995442, 39.29591681451208), + Offset(54.62284735335442, 39.17164145221208), + Offset(54.50301039685442, 39.04736608991208), + Offset(54.383173440354426, 38.92309072751208), + Offset(54.263336483854424, 38.79881536521208), + Offset(54.14349952735442, 38.67454000291208), + Offset(54.023662570754425, 38.55026464061208), + Offset(53.90382561425442, 38.42598927831208), + Offset(53.717253409954964, 37.21380954643979), + Offset(53.3794146437701, 33.53571324376249), + Offset(53.04157587771383, 29.857616940933074), + Offset(52.70373711162896, 26.17952063825577), + Offset(52.36589834544409, 22.50142433557846), + Offset(52.028059579359216, 18.823328032801157), + Offset(51.69022081327434, 15.145231730123854), + Offset(51.209599844133415, 12.533133381006508), + Offset(50.627574843376344, 11.384102561113572), + Offset(50.786079126264475, 11.095347340254705), + Offset(50.91384249150479, 10.86259439455874), + Offset(51.01646887208166, 10.675634757573192), + Offset(51.09727159719739, 10.528432370914274), + Offset(51.159968760166926, 10.414213797064974), + Offset(51.207403772355185, 10.327799050590698), + Offset(51.24214568222138, 10.264507966755737), + Offset(51.266374668526296, 10.220368804304208), + Offset(51.281997435281234, 10.191908024680146), + Offset(51.29067436255417, 10.176100830038976), + Offset(51.29385752619458, 10.170301900803324), + Offset(51.29282025622321, 10.172191547658386), + Offset(51.288681405188875, 10.179731500666236), + Offset(51.282427806600296, 10.19112399561152), + Offset(51.27493217593407, 10.204779162835159), + Offset(51.26697160279334, 10.219281339139357), + Offset(51.25921227961184, 10.233416888275087), + Offset(51.25227679406234, 10.246051610978604), + Offset(51.24669647592227, 10.256217557081996), + Offset(51.242953979299976, 10.263035451330936), + Offset(51.24147449075302, 10.265730709997449), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + ], + <Offset>[ + Offset(50.11037695941208, 40.16584435071208), + Offset(49.99054000291208, 40.04156898841208), + Offset(49.87070304641208, 39.917293626112084), + Offset(49.75086608991208, 39.79301826381208), + Offset(49.631029133312076, 39.66874290141208), + Offset(49.51119217681208, 39.544467539112084), + Offset(49.39135522031208, 39.42019217681208), + Offset(49.27151826381208, 39.29591681451208), + Offset(49.15168130721208, 39.17164145221208), + Offset(49.03184435071208, 39.04736608991208), + Offset(48.91200739421208, 38.92309072751208), + Offset(48.79217043771208, 38.79881536521208), + Offset(48.67233348121208, 38.67454000291208), + Offset(48.55249652461208, 38.55026464061208), + Offset(48.43265956811208, 38.42598927831208), + Offset(47.886224725057794, 37.21380954643979), + Offset(46.37283467228049, 33.53571324376249), + Offset(44.859444619603074, 29.857616940933074), + Offset(43.346054566925766, 26.17952063825577), + Offset(41.83266451414846, 22.50142433557846), + Offset(40.31927446147115, 18.823328032801157), + Offset(38.80588440879385, 15.145231730123854), + Offset(37.57729680711651, 12.533133381006508), + Offset(36.80002629848357, 11.384102561113572), + Offset(36.799396511844705, 11.095347340254705), + Offset(36.79888886839874, 10.86259439455874), + Offset(36.798481101983185, 10.675634757573192), + Offset(36.798160047714276, 10.528432370914274), + Offset(36.79791093245497, 10.414213797064974), + Offset(36.79772245845069, 10.327799050590698), + Offset(36.79758441807573, 10.264507966755737), + Offset(36.797488148804206, 10.220368804304208), + Offset(36.797426074710145, 10.191908024680146), + Offset(36.79739159858897, 10.176100830038976), + Offset(36.79737895089332, 10.170301900803324), + Offset(36.79738307228838, 10.172191547658386), + Offset(36.79739951722624, 10.179731500666236), + Offset(36.79742436471152, 10.19112399561152), + Offset(36.79745414717516, 10.204779162835159), + Offset(36.79748577699936, 10.219281339139357), + Offset(36.79751660719509, 10.233416888275087), + Offset(36.7975441640286, 10.246051610978604), + Offset(36.797566336361996, 10.256217557081996), + Offset(36.79758120646093, 10.263035451330936), + Offset(36.79758708492745, 10.265730709997449), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.63922254046772, 40.16584435071208), + Offset(44.51938558396772, 40.04156898841208), + Offset(44.39954862746772, 39.917293626112084), + Offset(44.27971167096772, 39.79301826381208), + Offset(44.15987471436772, 39.66874290141208), + Offset(44.04003775786772, 39.544467539112084), + Offset(43.92020080136772, 39.42019217681208), + Offset(43.80036384486772, 39.29591681451208), + Offset(43.68052688826772, 39.17164145221208), + Offset(43.56068993176772, 39.04736608991208), + Offset(43.440852975267724, 38.92309072751208), + Offset(43.32101601876772, 38.79881536521208), + Offset(43.20117906226772, 38.67454000291208), + Offset(43.08134210566772, 38.55026464061208), + Offset(42.96150514916772, 38.42598927831208), + Offset(42.05520843213051, 37.21380954643979), + Offset(39.36626959101571, 33.53571324376249), + Offset(36.677330749972064, 29.857616940933074), + Offset(33.988391908957254, 26.17952063825577), + Offset(31.299453067842446, 22.50142433557846), + Offset(28.610514226827636, 18.823328032801157), + Offset(25.92157538581283, 15.145231730123854), + Offset(23.945022741160805, 12.533133381006508), + Offset(22.97250713958332, 11.384102561113572), + Offset(22.812743621605566, 11.095347340254705), + Offset(22.68396524207196, 10.86259439455874), + Offset(22.580523547629824, 10.675634757573192), + Offset(22.499078886378673, 10.528432370914274), + Offset(22.43588362666254, 10.414213797064974), + Offset(22.38807176767408, 10.327799050590698), + Offset(22.35305385118404, 10.264507966755737), + Offset(22.328632378031546, 10.220368804304208), + Offset(22.312885496421558, 10.191908024680146), + Offset(22.304139635419563, 10.176100830038976), + Offset(22.300931183179507, 10.170301900803324), + Offset(22.301976693727863, 10.172191547658386), + Offset(22.30614842580716, 10.179731500666236), + Offset(22.31245170602349, 10.19112399561152), + Offset(22.32000688562417, 10.204779162835159), + Offset(22.328030701428442, 10.219281339139357), + Offset(22.335851668445954, 10.233416888275087), + Offset(22.342842252864767, 10.246051610978604), + Offset(22.348466903765345, 10.256217557081996), + Offset(22.35223913260045, 10.263035451330936), + Offset(22.35373037492376, 10.265730709997449), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + ], + <Offset>[ + Offset(40.20437695941208, 44.60068993176772), + Offset(40.08454000291208, 44.47641456946772), + Offset(39.96470304641208, 44.352139207167724), + Offset(39.84486608991208, 44.22786384486772), + Offset(39.72502913331208, 44.10358848246772), + Offset(39.60519217681208, 43.979313120167724), + Offset(39.48535522031208, 43.85503775786772), + Offset(39.36551826381208, 43.73076239556772), + Offset(39.24568130721208, 43.60648703326772), + Offset(39.12584435071208, 43.48221167096772), + Offset(39.006007394212084, 43.35793630856772), + Offset(38.88617043771208, 43.23366094626772), + Offset(38.76633348121208, 43.10938558396772), + Offset(38.64649652461208, 42.98511022166772), + Offset(38.52665956811208, 42.86083485936772), + Offset(37.32866356433979, 41.94035441423051), + Offset(33.686840386562494, 39.2151424482157), + Offset(30.045017208833077, 36.48993048207207), + Offset(26.403194031155767, 33.764718516057265), + Offset(22.761370853378462, 31.03950655004245), + Offset(19.119547675701156, 28.314294583927644), + Offset(15.477724498023854, 25.589082617912837), + Offset(12.894881258806514, 23.583274863360806), + Offset(11.764102561113575, 22.592507139583326), + Offset(11.475347340254707, 22.43274362160557), + Offset(11.242594394558743, 22.303965242071964), + Offset(11.055634757573195, 22.200523547629828), + Offset(10.908432370914277, 22.119078886378677), + Offset(10.794213797064977, 22.055883626662546), + Offset(10.707799050590701, 22.008071767674085), + Offset(10.64450796675574, 21.973053851184044), + Offset(10.60036880430421, 21.94863237803155), + Offset(10.571908024680148, 21.932885496421562), + Offset(10.556100830038979, 21.924139635419568), + Offset(10.550301900803326, 21.920931183179516), + Offset(10.552191547658389, 21.921976693727867), + Offset(10.559731500666238, 21.926148425807163), + Offset(10.571123995611522, 21.932451706023496), + Offset(10.584779162835162, 21.94000688562418), + Offset(10.59928133913936, 21.948030701428447), + Offset(10.61341688827509, 21.95585166844596), + Offset(10.626051610978607, 21.96284225286477), + Offset(10.636217557081999, 21.96846690376535), + Offset(10.643035451330938, 21.972239132600453), + Offset(10.645730709997451, 21.973730374923765), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + ], + <Offset>[ + Offset(40.20437695941208, 50.07184435071208), + Offset(40.08454000291208, 49.94756898841208), + Offset(39.96470304641208, 49.82329362611208), + Offset(39.84486608991208, 49.69901826381208), + Offset(39.72502913331208, 49.57474290141208), + Offset(39.60519217681208, 49.45046753911208), + Offset(39.48535522031208, 49.32619217681208), + Offset(39.36551826381208, 49.20191681451208), + Offset(39.24568130721208, 49.07764145221208), + Offset(39.12584435071208, 48.95336608991208), + Offset(39.006007394212084, 48.82909072751208), + Offset(38.88617043771208, 48.70481536521208), + Offset(38.76633348121208, 48.58054000291208), + Offset(38.64649652461208, 48.456264640612076), + Offset(38.52665956811208, 48.33198927831208), + Offset(37.32866356433979, 47.77137070715779), + Offset(33.686840386562494, 46.22170752948048), + Offset(30.045017208833077, 44.67204435170307), + Offset(26.403194031155767, 43.122381174025776), + Offset(22.761370853378462, 41.57271799634846), + Offset(19.119547675701156, 40.023054818571154), + Offset(15.477724498023854, 38.47339164089385), + Offset(12.894881258806514, 37.21554892931651), + Offset(11.764102561113575, 36.42002629848357), + Offset(11.475347340254707, 36.41939651184471), + Offset(11.242594394558743, 36.41888886839874), + Offset(11.055634757573195, 36.41848110198319), + Offset(10.908432370914277, 36.418160047714274), + Offset(10.794213797064977, 36.41791093245497), + Offset(10.707799050590701, 36.4177224584507), + Offset(10.64450796675574, 36.417584418075734), + Offset(10.60036880430421, 36.4174881488042), + Offset(10.571908024680148, 36.41742607471014), + Offset(10.556100830038979, 36.41739159858898), + Offset(10.550301900803326, 36.41737895089332), + Offset(10.552191547658389, 36.41738307228839), + Offset(10.559731500666238, 36.41739951722624), + Offset(10.571123995611522, 36.41742436471152), + Offset(10.584779162835162, 36.417454147175164), + Offset(10.59928133913936, 36.41748577699936), + Offset(10.61341688827509, 36.4175166071951), + Offset(10.626051610978607, 36.4175441640286), + Offset(10.636217557081999, 36.417566336362), + Offset(10.643035451330938, 36.41758120646094), + Offset(10.645730709997451, 36.41758708492745), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(40.20437695941208, 55.54301039685442), + Offset(40.08454000291208, 55.41873503455442), + Offset(39.96470304641208, 55.294459672254426), + Offset(39.84486608991208, 55.17018430995442), + Offset(39.72502913331208, 55.04590894755442), + Offset(39.60519217681208, 54.921633585254426), + Offset(39.48535522031208, 54.79735822295442), + Offset(39.36551826381208, 54.673082860654425), + Offset(39.24568130721208, 54.54880749835442), + Offset(39.12584435071208, 54.424532136054424), + Offset(39.006007394212084, 54.300256773654425), + Offset(38.88617043771208, 54.17598141135442), + Offset(38.76633348121208, 54.051706049054424), + Offset(38.64649652461208, 53.92743068675442), + Offset(38.52665956811208, 53.80315532445442), + Offset(37.32866356433979, 53.60239939205497), + Offset(33.686840386562494, 53.2282875009701), + Offset(30.045017208833077, 52.854175609813836), + Offset(26.403194031155767, 52.480063718728964), + Offset(22.761370853378462, 52.105951827644084), + Offset(19.119547675701156, 51.73183993645922), + Offset(15.477724498023854, 51.357728045374344), + Offset(12.894881258806514, 50.847851966333415), + Offset(11.764102561113575, 50.24757484337634), + Offset(11.475347340254707, 50.40607912626448), + Offset(11.242594394558743, 50.53384249150479), + Offset(11.055634757573195, 50.636468872081664), + Offset(10.908432370914277, 50.717271597197396), + Offset(10.794213797064977, 50.77996876016692), + Offset(10.707799050590701, 50.82740377235519), + Offset(10.64450796675574, 50.86214568222138), + Offset(10.60036880430421, 50.8863746685263), + Offset(10.571908024680148, 50.90199743528123), + Offset(10.556100830038979, 50.91067436255417), + Offset(10.550301900803326, 50.913857526194576), + Offset(10.552191547658389, 50.91282025622321), + Offset(10.559731500666238, 50.90868140518888), + Offset(10.571123995611522, 50.9024278066003), + Offset(10.584779162835162, 50.894932175934066), + Offset(10.59928133913936, 50.886971602793345), + Offset(10.61341688827509, 50.87921227961184), + Offset(10.626051610978607, 50.872276794062344), + Offset(10.636217557081999, 50.866696475922275), + Offset(10.643035451330938, 50.862953979299974), + Offset(10.645730709997451, 50.861474490753025), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + ], + <Offset>[ + Offset(44.63922254046772, 59.97784435071208), + Offset(44.51938558396772, 59.853568988412086), + Offset(44.39954862746772, 59.72929362611209), + Offset(44.27971167096772, 59.605018263812084), + Offset(44.15987471436772, 59.480742901412086), + Offset(44.04003775786772, 59.35646753911209), + Offset(43.92020080136772, 59.232192176812084), + Offset(43.80036384486772, 59.10791681451209), + Offset(43.68052688826772, 58.98364145221208), + Offset(43.56068993176772, 58.859366089912086), + Offset(43.440852975267724, 58.73509072751209), + Offset(43.32101601876772, 58.61081536521208), + Offset(43.20117906226772, 58.486540002912086), + Offset(43.08134210566772, 58.36226464061208), + Offset(42.96150514916772, 58.237989278312085), + Offset(42.05520843213051, 58.328931867875795), + Offset(39.36626959101571, 58.907701815198486), + Offset(36.67733074997207, 59.48647176247307), + Offset(33.98839190895726, 60.06524170979577), + Offset(31.299453067842453, 60.644011657118455), + Offset(28.610514226827643, 61.22278160434116), + Offset(25.921575385812837, 61.80155155166385), + Offset(23.945022741160813, 61.897964477626516), + Offset(22.97250713958333, 61.455950035853576), + Offset(22.812743621605573, 61.74344568343471), + Offset(22.683965242071967, 61.975183342238736), + Offset(22.58052354762983, 62.16132744639319), + Offset(22.49907888637868, 62.30788772451427), + Offset(22.435883626662548, 62.42160806784497), + Offset(22.388071767674088, 62.507645866310696), + Offset(22.353053851184047, 62.57066086939574), + Offset(22.328632378031553, 62.614607493304206), + Offset(22.312885496421565, 62.64294412474014), + Offset(22.30413963541957, 62.65868236713898), + Offset(22.300931183179518, 62.66445600098332), + Offset(22.30197669372787, 62.66257459691839), + Offset(22.306148425807166, 62.65506753378624), + Offset(22.3124517060235, 62.643724733811524), + Offset(22.32000688562418, 62.63012913151516), + Offset(22.32803070142845, 62.615690214859356), + Offset(22.33585166844596, 62.60161632611509), + Offset(22.342842252864774, 62.5890367170786), + Offset(22.348466903765352, 62.578915115642), + Offset(22.352239132600456, 62.57212696159094), + Offset(22.353730374923767, 62.56944345985745), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + ], + <Offset>[ + Offset(50.11037695941208, 59.97784435071208), + Offset(49.99054000291208, 59.853568988412086), + Offset(49.87070304641208, 59.72929362611209), + Offset(49.75086608991208, 59.605018263812084), + Offset(49.631029133312076, 59.480742901412086), + Offset(49.51119217681208, 59.35646753911209), + Offset(49.39135522031208, 59.232192176812084), + Offset(49.27151826381208, 59.10791681451209), + Offset(49.15168130721208, 58.98364145221208), + Offset(49.03184435071208, 58.859366089912086), + Offset(48.91200739421208, 58.73509072751209), + Offset(48.79217043771208, 58.61081536521208), + Offset(48.67233348121208, 58.486540002912086), + Offset(48.55249652461208, 58.36226464061208), + Offset(48.43265956811208, 58.237989278312085), + Offset(47.886224725057794, 58.328931867875795), + Offset(46.37283467228049, 58.907701815198486), + Offset(44.859444619603074, 59.48647176247307), + Offset(43.34605456692577, 60.06524170979577), + Offset(41.83266451414846, 60.644011657118455), + Offset(40.31927446147115, 61.22278160434116), + Offset(38.80588440879385, 61.80155155166385), + Offset(37.57729680711652, 61.897964477626516), + Offset(36.80002629848357, 61.455950035853576), + Offset(36.799396511844705, 61.74344568343471), + Offset(36.79888886839874, 61.975183342238736), + Offset(36.79848110198319, 62.16132744639319), + Offset(36.798160047714276, 62.30788772451427), + Offset(36.797910932454975, 62.42160806784497), + Offset(36.7977224584507, 62.507645866310696), + Offset(36.797584418075736, 62.57066086939574), + Offset(36.797488148804206, 62.614607493304206), + Offset(36.797426074710145, 62.64294412474014), + Offset(36.79739159858898, 62.65868236713898), + Offset(36.797378950893325, 62.66445600098332), + Offset(36.79738307228839, 62.66257459691839), + Offset(36.79739951722624, 62.65506753378624), + Offset(36.797424364711524, 62.643724733811524), + Offset(36.797454147175166, 62.63012913151516), + Offset(36.797485776999366, 62.615690214859356), + Offset(36.79751660719509, 62.60161632611509), + Offset(36.79754416402861, 62.5890367170786), + Offset(36.797566336361996, 62.578915115642), + Offset(36.79758120646094, 62.57212696159094), + Offset(36.79758708492745, 62.56944345985745), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(52.571645330995544, 59.97784435071208), + Offset(52.45180837449554, 59.853568988412086), + Offset(52.33197141799555, 59.72929362611209), + Offset(52.212134461495545, 59.605018263812084), + Offset(52.09229750489554, 59.480742901412086), + Offset(51.972460548395546, 59.35646753911209), + Offset(51.852623591895544, 59.232192176812084), + Offset(51.73278663539554, 59.10791681451209), + Offset(51.612949678795545, 58.98364145221208), + Offset(51.49311272229554, 58.859366089912086), + Offset(51.37327576579555, 58.73509072751209), + Offset(51.253438809295545, 58.61081536521208), + Offset(51.13360185279554, 58.486540002912086), + Offset(51.013764896195546, 58.36226464061208), + Offset(50.893927939695544, 58.237989278312085), + Offset(50.509381535670876, 58.328931867875795), + Offset(49.524827050387316, 58.907701815198486), + Offset(48.54027256521657, 59.48647176247307), + Offset(47.55571808003301, 60.06524170979577), + Offset(46.57116359474944, 60.644011657118455), + Offset(45.586609109565885, 61.22278160434116), + Offset(44.602054624382326, 61.80155155166385), + Offset(43.70994860636296, 61.897964477626516), + Offset(43.0205115849932, 61.455950035853576), + Offset(43.091470130506, 61.74344568343471), + Offset(43.14866670842858, 61.975183342238736), + Offset(43.19461006443314, 62.16132744639319), + Offset(43.23078349611088, 62.30788772451427), + Offset(43.25885150418633, 62.42160806784497), + Offset(43.28008701536578, 62.507645866310696), + Offset(43.295640130698196, 62.57066086939574), + Offset(43.30648686364522, 62.614607493304206), + Offset(43.313480799617274, 62.64294412474014), + Offset(43.317365250734866, 62.65868236713898), + Offset(43.31879027634261, 62.66445600098332), + Offset(43.318325915587614, 62.66257459691839), + Offset(43.31647305177763, 62.65506753378624), + Offset(43.313673466479486, 62.643724733811524), + Offset(43.31031785336869, 62.63012913151516), + Offset(43.30675409672299, 62.615690214859356), + Offset(43.30328043483139, 62.60161632611509), + Offset(43.300175585182856, 62.5890367170786), + Offset(43.29767741130703, 62.578915115642), + Offset(43.296001985810214, 62.57212696159094), + Offset(43.29533965446193, 62.56944345985745), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + ], + <Offset>[ + Offset(54.81954300555442, 59.07868993176772), + Offset(54.69970604905442, 58.95441456946772), + Offset(54.579869092554425, 58.830139207167726), + Offset(54.46003213605442, 58.70586384486772), + Offset(54.34019517945442, 58.58158848246772), + Offset(54.220358222954424, 58.457313120167726), + Offset(54.10052126645442, 58.33303775786772), + Offset(53.98068430995442, 58.208762395567724), + Offset(53.86084735335442, 58.08448703326772), + Offset(53.74101039685442, 57.96021167096772), + Offset(53.621173440354426, 57.835936308567724), + Offset(53.50133648385442, 57.71166094626772), + Offset(53.38149952735442, 57.58738558396772), + Offset(53.261662570754424, 57.46311022166772), + Offset(53.14182561425442, 57.33883485936772), + Offset(52.905133320668966, 57.37063611066451), + Offset(52.4035689294841, 57.756211019649704), + Offset(51.90200453842384, 58.14178592858207), + Offset(51.40044014733896, 58.527360837567265), + Offset(50.89887575615409, 58.91293574655245), + Offset(50.397311365069214, 59.298510655437646), + Offset(49.895746973984345, 59.68408556442283), + Offset(49.31095249426342, 59.657574510890804), + Offset(48.70173455588635, 59.18347260189332), + Offset(48.83807534383448, 59.44481548777557), + Offset(48.94797368582479, 59.65547254999196), + Offset(49.036249922511665, 59.82468358945982), + Offset(49.1057540835974, 59.957911644778676), + Offset(49.159684365136926, 60.06128713223254), + Offset(49.20048658713519, 60.13949828685408), + Offset(49.230370570581385, 60.196780972344044), + Offset(49.2512116420263, 60.236729881531545), + Offset(49.264649892971235, 60.26248880031156), + Offset(49.27211353420417, 60.276795374069565), + Offset(49.27485159926458, 60.28204379484951), + Offset(49.27395936971321, 60.28033353741787), + Offset(49.27039925006888, 60.273509373087165), + Offset(49.265020085900304, 60.2631983993235), + Offset(49.25857256175407, 60.25083955504418), + Offset(49.25172510757334, 60.237714110608444), + Offset(49.24505076277185, 60.22492048840596), + Offset(49.23908505921234, 60.21348521501477), + Offset(49.234285031362276, 60.204284350405345), + Offset(49.23106584428998, 60.198113697790454), + Offset(49.22979323114302, 60.19567430751376), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + ], + <Offset>[ + Offset(56.549286261168945, 57.59279225720884), + Offset(56.42944930466894, 57.468516894908845), + Offset(56.30961234816895, 57.34424153260885), + Offset(56.189775391668945, 57.219966170308844), + Offset(56.06993843506894, 57.095690807908845), + Offset(55.950101478568946, 56.97141544560885), + Offset(55.830264522068944, 56.847140083308844), + Offset(55.71042756556894, 56.72286472100885), + Offset(55.590590608968945, 56.59858935870884), + Offset(55.47075365246894, 56.474313996408846), + Offset(55.35091669596895, 56.35003863400885), + Offset(55.231079739468946, 56.22576327170884), + Offset(55.111242782968944, 56.101487909408846), + Offset(54.99140582636895, 55.97721254710884), + Offset(54.871568869868945, 55.852937184808845), + Offset(54.74864939309879, 55.78700441495241), + Offset(54.6187428701751, 55.85331485483892), + Offset(54.4888363473851, 55.9196252946648), + Offset(54.358929824561415, 55.985935734551305), + Offset(54.22902330163772, 56.052246174437805), + Offset(54.09911677881403, 56.11855661422432), + Offset(53.96921025599034, 56.18486705411082), + Offset(53.620890090363176, 55.95521797286034), + Offset(53.07340023656424, 55.42808991849018), + Offset(53.26005225271882, 55.64621405687709), + Offset(53.410504273814226, 55.82203437827575), + Offset(53.53135539844182, 55.9632626809513), + Offset(53.62650734814831, 56.07445857089216), + Offset(53.700338487990095, 56.16073866631195), + Offset(53.75619717205799, 56.226015900304674), + Offset(53.79710866923288, 56.27382564410085), + Offset(53.82564032188473, 56.307168129650464), + Offset(53.84403743305162, 56.328667249267596), + Offset(53.85425523877907, 56.34060791895026), + Offset(53.85800367951774, 56.34498839885754), + Offset(53.8567822075933, 56.34356096980227), + Offset(53.85190836522106, 56.337865329915914), + Offset(53.84454423118309, 56.32925950060268), + Offset(53.83571750075847, 56.31894446083879), + Offset(53.82634326178278, 56.30798959497809), + Offset(53.81720601142316, 56.29731167730551), + Offset(53.809038898603006, 56.28776747583528), + Offset(53.80246760846087, 56.2800881749101), + Offset(53.79806050647426, 56.274937974320686), + Offset(53.79631828528544, 56.27290199044266), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(56.549286261168945, 57.59279225720884), + Offset(56.42944930466894, 57.468516894908845), + Offset(56.30961234816895, 57.34424153260885), + Offset(56.189775391668945, 57.219966170308844), + Offset(56.06993843506894, 57.095690807908845), + Offset(55.950101478568946, 56.97141544560885), + Offset(55.830264522068944, 56.847140083308844), + Offset(55.71042756556894, 56.72286472100885), + Offset(55.590590608968945, 56.59858935870884), + Offset(55.47075365246894, 56.474313996408846), + Offset(55.35091669596895, 56.35003863400885), + Offset(55.231079739468946, 56.22576327170884), + Offset(55.111242782968944, 56.101487909408846), + Offset(54.99140582636895, 55.97721254710884), + Offset(54.871568869868945, 55.852937184808845), + Offset(54.74864939309879, 55.78700441495241), + Offset(54.6187428701751, 55.85331485483892), + Offset(54.4888363473851, 55.9196252946648), + Offset(54.358929824561415, 55.985935734551305), + Offset(54.22902330163772, 56.052246174437805), + Offset(54.09911677881403, 56.11855661422432), + Offset(53.96921025599034, 56.18486705411082), + Offset(53.620890090363176, 55.95521797286034), + Offset(53.07340023656424, 55.42808991849018), + Offset(53.26005225271882, 55.64621405687709), + Offset(53.410504273814226, 55.82203437827575), + Offset(53.53135539844182, 55.9632626809513), + Offset(53.62650734814831, 56.07445857089216), + Offset(53.700338487990095, 56.16073866631195), + Offset(53.75619717205799, 56.226015900304674), + Offset(53.79710866923288, 56.27382564410085), + Offset(53.82564032188473, 56.307168129650464), + Offset(53.84403743305162, 56.328667249267596), + Offset(53.85425523877907, 56.34060791895026), + Offset(53.85800367951774, 56.34498839885754), + Offset(53.8567822075933, 56.34356096980227), + Offset(53.85190836522106, 56.337865329915914), + Offset(53.84454423118309, 56.32925950060268), + Offset(53.83571750075847, 56.31894446083879), + Offset(53.82634326178278, 56.30798959497809), + Offset(53.81720601142316, 56.29731167730551), + Offset(53.809038898603006, 56.28776747583528), + Offset(53.80246760846087, 56.2800881749101), + Offset(53.79806050647426, 56.274937974320686), + Offset(53.79631828528544, 56.27290199044266), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + ], + <Offset>[ + Offset(57.62369742449878, 56.51075365246894), + Offset(57.50386046799878, 56.386478290168945), + Offset(57.38402351149878, 56.26220292786895), + Offset(57.26418655499878, 56.137927565568944), + Offset(57.144349598398776, 56.013652203168945), + Offset(57.02451264189878, 55.88937684086895), + Offset(56.90467568539878, 55.765101478568944), + Offset(56.78483872889878, 55.64082611626895), + Offset(56.66500177229878, 55.51655075396894), + Offset(56.54516481579878, 55.392275391668946), + Offset(56.42532785929878, 55.26800002926895), + Offset(56.30549090279878, 55.14372466696894), + Offset(56.18565394629878, 55.019449304668946), + Offset(56.06581698969878, 54.89517394236894), + Offset(55.94598003319878, 54.770898580068945), + Offset(55.89372930109525, 54.63379537519879), + Offset(55.994674010747886, 54.46761572737509), + Offset(56.09561872053984, 54.3014360794851), + Offset(56.19656343029247, 54.13525643166142), + Offset(56.2975081399451, 53.969076783837714), + Offset(56.398452849697726, 53.80289713591403), + Offset(56.49939755945036, 53.63671748809034), + Offset(56.297960835674125, 53.25914221256317), + Offset(55.7888127085716, 52.69340023656424), + Offset(56.006714995568615, 52.88005225271882), + Offset(56.182356492271566, 53.03050427381422), + Offset(56.32344115337003, 53.151355398441815), + Offset(56.43452394733299, 53.246507348148306), + Offset(56.52071628832435, 53.32033848799009), + Offset(56.5859271296418, 53.376197172057985), + Offset(56.63368824673307, 53.417108669232874), + Offset(56.66699682004896, 53.445640321884724), + Offset(56.68847407317482, 53.464037433051615), + Offset(56.700402598148585, 53.474255238779065), + Offset(56.70477862272339, 53.47800367951774), + Offset(56.703352645488735, 53.476782207593295), + Offset(56.697662798567954, 53.471908365221054), + Offset(56.689065722138324, 53.46454423118309), + Offset(56.678761173675056, 53.45571750075847), + Offset(56.66781744987426, 53.446343261782786), + Offset(56.65715039258098, 53.43720601142316), + Offset(56.64761589840118, 53.429038898603004), + Offset(56.639944407998925, 53.42246760846087), + Offset(56.634799445615464, 53.418060506474255), + Offset(56.632765532511705, 53.416318285285435), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + ], + <Offset>[ + Offset(57.62369742449878, 56.51075365246894), + Offset(57.50386046799878, 56.386478290168945), + Offset(57.38402351149878, 56.26220292786895), + Offset(57.26418655499878, 56.137927565568944), + Offset(57.144349598398776, 56.013652203168945), + Offset(57.02451264189878, 55.88937684086895), + Offset(56.90467568539878, 55.765101478568944), + Offset(56.78483872889878, 55.64082611626895), + Offset(56.66500177229878, 55.51655075396894), + Offset(56.54516481579878, 55.392275391668946), + Offset(56.42532785929878, 55.26800002926895), + Offset(56.30549090279878, 55.14372466696894), + Offset(56.18565394629878, 55.019449304668946), + Offset(56.06581698969878, 54.89517394236894), + Offset(55.94598003319878, 54.770898580068945), + Offset(55.89372930109525, 54.63379537519879), + Offset(55.994674010747886, 54.46761572737509), + Offset(56.09561872053984, 54.3014360794851), + Offset(56.19656343029247, 54.13525643166142), + Offset(56.2975081399451, 53.969076783837714), + Offset(56.398452849697726, 53.80289713591403), + Offset(56.49939755945036, 53.63671748809034), + Offset(56.297960835674125, 53.25914221256317), + Offset(55.7888127085716, 52.69340023656424), + Offset(56.006714995568615, 52.88005225271882), + Offset(56.182356492271566, 53.03050427381422), + Offset(56.32344115337003, 53.151355398441815), + Offset(56.43452394733299, 53.246507348148306), + Offset(56.52071628832435, 53.32033848799009), + Offset(56.5859271296418, 53.376197172057985), + Offset(56.63368824673307, 53.417108669232874), + Offset(56.66699682004896, 53.445640321884724), + Offset(56.68847407317482, 53.464037433051615), + Offset(56.700402598148585, 53.474255238779065), + Offset(56.70477862272339, 53.47800367951774), + Offset(56.703352645488735, 53.476782207593295), + Offset(56.697662798567954, 53.471908365221054), + Offset(56.689065722138324, 53.46454423118309), + Offset(56.678761173675056, 53.45571750075847), + Offset(56.66781744987426, 53.446343261782786), + Offset(56.65715039258098, 53.43720601142316), + Offset(56.64761589840118, 53.429038898603004), + Offset(56.639944407998925, 53.42246760846087), + Offset(56.634799445615464, 53.418060506474255), + Offset(56.632765532511705, 53.416318285285435), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + ], + ), + _PathClose( + ), + _PathMoveTo( + <Offset>[ + Offset(50.11037695941208, 50.11515566052058), + Offset(49.99054000291208, 49.99088029822058), + Offset(49.87070304641208, 49.866604935920584), + Offset(49.75086608991208, 49.74232957362058), + Offset(49.631029133312076, 49.61805421122058), + Offset(49.51119217681208, 49.493778848920584), + Offset(49.39135522031208, 49.36950348662058), + Offset(49.27151826381208, 49.24522812432058), + Offset(49.15168130721208, 49.12095276202058), + Offset(49.03184435071208, 48.99667739972058), + Offset(48.91200739421208, 48.87240203732058), + Offset(48.79217043771208, 48.74812667502058), + Offset(48.67233348121208, 48.62385131272058), + Offset(48.55249652461208, 48.49957595042058), + Offset(48.43265956811208, 48.37530058812058), + Offset(47.886224725057794, 48.02143406108567), + Offset(46.37283467228049, 47.32255270277091), + Offset(44.859444619603074, 46.89224005129487), + Offset(43.346054566925766, 46.73049610683733), + Offset(41.83266451414846, 46.83732086930855), + Offset(40.31927446147115, 47.21271433859731), + Offset(38.80588440879385, 47.856676514909296), + Offset(37.57729680711651, 48.70078707684129), + Offset(36.80002629848357, 49.649293275456884), + Offset(36.799396511844705, 51.39862444641657), + Offset(36.79888886839874, 52.36567493589737), + Offset(36.798481101983185, 52.561543433342045), + Offset(36.798160047714276, 52.73365619281698), + Offset(36.79791093245497, 52.88590941777883), + Offset(36.79772245845069, 53.021274808915365), + Offset(36.79758441807573, 53.14247036493895), + Offset(36.797488148804206, 53.25181934443066), + Offset(36.797426074710145, 53.351374286002354), + Offset(36.79739159858897, 53.44294120991781), + Offset(36.79737895089332, 53.52811757525859), + Offset(36.79738307228838, 53.60832148263455), + Offset(36.79739951722624, 53.68481556964314), + Offset(36.79742436471152, 53.7587295593099), + Offset(36.79745414717516, 53.83107808312845), + Offset(36.79748577699936, 53.90277982470875), + Offset(36.79751660719509, 53.97463627018816), + Offset(36.7975441640286, 54.047410713622526), + Offset(36.797566336361996, 54.121768596383546), + Offset(36.79758120646093, 54.19832738700239), + Offset(36.79758708492745, 54.27764432912612), + Offset(36.79758712071989, 54.35877252649494), + Offset(36.79758712071989, 54.439911871108684), + Offset(36.79758712071989, 54.52105121572243), + Offset(36.79758712071989, 54.522707120719886), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(50.08645981463666, 50.11515566052058), + Offset(49.96662285813666, 49.99088029822058), + Offset(49.846785901636665, 49.866604935920584), + Offset(49.72694894513666, 49.74232957362058), + Offset(49.60711198853666, 49.61805421122058), + Offset(49.48727503203666, 49.493778848920584), + Offset(49.36743807553666, 49.36950348662058), + Offset(49.24760111903666, 49.24522812432058), + Offset(49.12776416243666, 49.12095276202058), + Offset(49.00792720593666, 48.99667739972058), + Offset(48.888090249436665, 48.87240203732058), + Offset(48.76825329293666, 48.74812667502058), + Offset(48.64841633643666, 48.62385131272058), + Offset(48.528579379836664, 48.49957595042058), + Offset(48.40874242333666, 48.37530058812058), + Offset(47.748134816992604, 48.02143406108567), + Offset(45.764925398174555, 47.32255270277091), + Offset(43.63340675157196, 46.89224005129487), + Offset(41.35357887709607, 46.73049610683733), + Offset(38.92544177464233, 46.83732086930855), + Offset(36.34899544441074, 47.21271433859731), + Offset(33.624239886301304, 47.856676514909296), + Offset(31.234909988934966, 48.70078707684129), + Offset(29.494550483270046, 49.649293275456884), + Offset(28.52755585328232, 51.39862444641657), + Offset(27.99274184675299, 52.36567493589737), + Offset(27.883944986437346, 52.561543433342045), + Offset(27.788401120897287, 52.73365619281698), + Offset(27.703935759159105, 52.88590941777883), + Offset(27.628890333495022, 53.021274808915365), + Offset(27.561748066907615, 53.14247036493895), + Offset(27.50121256374279, 53.25181934443066), + Offset(27.446138611583994, 53.351374286002354), + Offset(27.39551864926441, 53.44294120991781), + Offset(27.348461571724304, 53.52811757525859), + Offset(27.30417642143305, 53.60832148263455), + Offset(27.261959043201006, 53.68481556964314), + Offset(27.22117949399494, 53.7587295593099), + Offset(27.181272090318803, 53.83107808312845), + Offset(27.141724722671132, 53.90277982470875), + Offset(27.102090684257846, 53.97463627018816), + Offset(27.061944627502523, 54.047410713622526), + Offset(27.020915803873248, 54.121768596383546), + Offset(26.978660256499385, 54.19832738700239), + Offset(26.934867640331532, 54.27764432912612), + Offset(26.890065739866895, 54.35877252649494), + Offset(26.845257628088735, 54.439911871108684), + Offset(26.80044951631057, 54.52105121572243), + Offset(26.79953506506211, 54.522707120719886), + ], + <Offset>[ + Offset(50.06706564959764, 50.095761495481554), + Offset(49.947228693097635, 49.97148613318156), + Offset(49.82739173659764, 49.84721077088156), + Offset(49.70755478009764, 49.722935408581556), + Offset(49.587717823497634, 49.59866004618156), + Offset(49.46788086699764, 49.47438468388156), + Offset(49.34804391049764, 49.350109321581556), + Offset(49.228206953997635, 49.22583395928156), + Offset(49.10836999739764, 49.101558596981555), + Offset(48.988533040897636, 48.97728323468156), + Offset(48.86869608439764, 48.85300787228156), + Offset(48.74885912789764, 48.728732509981555), + Offset(48.62902217139764, 48.60445714768156), + Offset(48.50918521479764, 48.48018178538155), + Offset(48.38934825829764, 48.35590642308156), + Offset(47.63616175837963, 47.909461002472696), + Offset(45.27199148434817, 46.82961878894062), + Offset(42.63925301353386, 45.89808631326019), + Offset(39.73794634587201, 45.11486357561327), + Offset(36.56807148124825, 44.47995057591447), + Offset(33.12962841986258, 43.993347314049146), + Offset(29.42261716161499, 43.65505379022298), + Offset(26.09208026716689, 43.55795735507321), + Offset(23.57078423835929, 43.725527030546125), + Offset(21.82019681522399, 44.69126540835824), + Offset(20.852132118393076, 45.225065207537455), + Offset(20.655446961021294, 45.333045407926), + Offset(20.48269090511957, 45.42794597703926), + Offset(20.329938213814554, 45.511911872434275), + Offset(20.194194600945227, 45.58657907636557), + Offset(20.07272166098446, 45.653443959015796), + Offset(19.9631788172331, 45.71378559792097), + Offset(19.86349838492615, 45.76873405934452), + Offset(19.771861154060407, 45.81928371469362), + Offset(19.686658130182877, 45.86631413371717), + Offset(19.606461097044544, 45.91060615824605), + Offset(19.529998528318746, 45.95285505476088), + Offset(19.456132860826976, 45.993682926121764), + Offset(19.38384252924341, 46.033648522053056), + Offset(19.312202675685725, 46.07325777772334), + Offset(19.240406520613522, 46.11295210654384), + Offset(19.167685822801204, 46.1531519089212), + Offset(19.093370918660103, 46.19422371115027), + Offset(19.016840503908618, 46.236507634411616), + Offset(18.93753395574349, 46.28031064453808), + Offset(18.856404467546696, 46.325111254174736), + Offset(18.775263760542785, 46.369918003542615), + Offset(18.69412305351876, 46.41472475293062), + Offset(18.692467120719886, 46.41563917637766), + ], + <Offset>[ + Offset(50.06706564959764, 50.07184435070614), + Offset(49.947228693097635, 49.94756898840614), + Offset(49.82739173659764, 49.82329362610614), + Offset(49.70755478009764, 49.69901826380614), + Offset(49.587717823497634, 49.57474290140614), + Offset(49.46788086699764, 49.45046753910614), + Offset(49.34804391049764, 49.32619217680614), + Offset(49.228206953997635, 49.20191681450614), + Offset(49.10836999739764, 49.07764145220614), + Offset(48.988533040897636, 48.95336608990614), + Offset(48.86869608439764, 48.82909072750614), + Offset(48.74885912789764, 48.70481536520614), + Offset(48.62902217139764, 48.58054000290614), + Offset(48.50918521479764, 48.456264640606136), + Offset(48.38934825829764, 48.33198927830614), + Offset(47.63616175837963, 47.7713707071586), + Offset(45.27199148434817, 46.22170752947073), + Offset(42.63925301353386, 44.672044351691675), + Offset(39.73794634587201, 43.12238117401274), + Offset(36.56807148124825, 41.572717996339655), + Offset(33.12962841986258, 40.02305481856121), + Offset(29.42261716161499, 38.47339164088308), + Offset(26.09208026716689, 37.21554892929752), + Offset(23.57078423835929, 36.42002629846431), + Offset(21.82019681522399, 36.41939651182523), + Offset(20.852132118393076, 36.41888886837908), + Offset(20.655446961021294, 36.41848110196339), + Offset(20.48269090511957, 36.41816004771427), + Offset(20.329938213814554, 36.41791093245497), + Offset(20.194194600945227, 36.4177224584507), + Offset(20.07272166098446, 36.41758441807573), + Offset(19.9631788172331, 36.4174881488042), + Offset(19.86349838492615, 36.417426074710136), + Offset(19.771861154060407, 36.41739159858898), + Offset(19.686658130182877, 36.417378950893315), + Offset(19.606461097044544, 36.41738307228839), + Offset(19.529998528318746, 36.41739951720605), + Offset(19.456132860826976, 36.41742436469134), + Offset(19.38384252924341, 36.417454147155), + Offset(19.312202675685725, 36.417485776979206), + Offset(19.240406520613522, 36.417516607174946), + Offset(19.167685822801204, 36.41754416400846), + Offset(19.093370918660103, 36.41756633636199), + Offset(19.016840503908618, 36.41758120646094), + Offset(18.93753395574349, 36.41758708492745), + Offset(18.856404467546696, 36.41758712071989), + Offset(18.775263760542785, 36.41758712071989), + Offset(18.69412305351876, 36.41758712071989), + Offset(18.692467120719886, 36.41758712071989), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(50.06706564959764, 50.04792720593072), + Offset(49.947228693097635, 49.92365184363072), + Offset(49.82739173659764, 49.799376481330725), + Offset(49.70755478009764, 49.675101119030714), + Offset(49.587717823497634, 49.550825756630715), + Offset(49.46788086699764, 49.42655039433072), + Offset(49.34804391049764, 49.30227503203072), + Offset(49.228206953997635, 49.177999669730724), + Offset(49.10836999739764, 49.05372430743071), + Offset(48.988533040897636, 48.929448945130716), + Offset(48.86869608439764, 48.80517358273072), + Offset(48.74885912789764, 48.68089822043072), + Offset(48.62902217139764, 48.55662285813072), + Offset(48.50918521479764, 48.43234749583071), + Offset(48.38934825829764, 48.308072133530715), + Offset(47.63616175837963, 47.63328079909341), + Offset(45.27199148434817, 45.61379825536479), + Offset(42.63925301353386, 43.44600648366056), + Offset(39.73794634587201, 41.12990548418304), + Offset(36.56807148124825, 38.66549525683352), + Offset(33.12962841986258, 36.05277580150079), + Offset(29.42261716161499, 33.29174711839053), + Offset(26.09208026716689, 30.873162111115967), + Offset(23.57078423835929, 29.11455048325078), + Offset(21.82019681522399, 28.147555853262837), + Offset(20.852132118393076, 27.612742525999973), + Offset(20.655446961021294, 27.50394701174588), + Offset(20.48269090511957, 27.408404506536804), + Offset(20.329938213814554, 27.323940514395186), + Offset(20.194194600945227, 27.2488964636637), + Offset(20.07272166098446, 27.181755574389616), + Offset(19.9631788172331, 27.121221448636877), + Offset(19.86349838492615, 27.066148872338097), + Offset(19.771861154060407, 27.015530283259928), + Offset(19.686658130182877, 26.968474575656916), + Offset(19.606461097044544, 26.924190791705026), + Offset(19.529998528318746, 26.88197477619479), + Offset(19.456132860826976, 26.841196586461674), + Offset(19.38384252924341, 26.80129053948502), + Offset(19.312202675685725, 26.761744526458134), + Offset(19.240406520613522, 26.72211184147367), + Offset(19.167685822801204, 26.68196713796564), + Offset(19.093370918660103, 26.64093966853734), + Offset(19.016840503908618, 26.598685477488807), + Offset(18.93753395574349, 26.5548942211387), + Offset(18.856404467546696, 26.5100936830677), + Offset(18.775263760542785, 26.465286933679703), + Offset(18.69412305351876, 26.42048018431182), + Offset(18.692467120719886, 26.419565760864774), + ], + <Offset>[ + Offset(50.08645981463666, 50.02853304089169), + Offset(49.96662285813666, 49.90425767859169), + Offset(49.846785901636665, 49.779982316291694), + Offset(49.72694894513666, 49.6557069539917), + Offset(49.60711198853666, 49.5314315915917), + Offset(49.48727503203666, 49.4071562292917), + Offset(49.36743807553666, 49.28288086699169), + Offset(49.24760111903666, 49.15860550469169), + Offset(49.12776416243666, 49.034330142391696), + Offset(49.00792720593666, 48.9100547800917), + Offset(48.888090249436665, 48.7857794176917), + Offset(48.76825329293666, 48.66150405539169), + Offset(48.64841633643666, 48.53722869309169), + Offset(48.528579379836664, 48.412953330791694), + Offset(48.40874242333666, 48.2886779684917), + Offset(47.748134816992604, 47.521307740480445), + Offset(45.76492539817846, 45.1208643415384), + Offset(43.63340675156854, 42.45185274562246), + Offset(41.35357887709607, 39.51427295295898), + Offset(38.92544177464233, 36.30812496343945), + Offset(36.34899544441074, 32.83340877695263), + Offset(33.624239886301304, 29.090124393704222), + Offset(31.234909988934966, 25.730332389347893), + Offset(29.494550483270046, 23.19078423834003), + Offset(28.52755585328232, 21.440196815204512), + Offset(27.99274184675299, 20.472132118373413), + Offset(27.883944986437346, 20.275446961001492), + Offset(27.788401120897287, 20.102690905119566), + Offset(27.703935759159105, 19.94993821381455), + Offset(27.628890333495022, 19.814194600945225), + Offset(27.56174806690762, 19.692721660984457), + Offset(27.50121256374279, 19.583178817233097), + Offset(27.446138611583994, 19.483498384926143), + Offset(27.395518649284597, 19.391861154060404), + Offset(27.348461571724304, 19.306658130182875), + Offset(27.30417642143305, 19.22646109704454), + Offset(27.261959043201006, 19.14999852829856), + Offset(27.22117949401511, 19.076132860806798), + Offset(27.1812720903188, 19.003842529223242), + Offset(27.141724722671132, 18.93220267566557), + Offset(27.102090684257846, 18.860406520593376), + Offset(27.061944627502523, 18.787685822781068), + Offset(27.020915803893374, 18.7133709186601), + Offset(26.978660256499385, 18.636840503908616), + Offset(26.934867640331532, 18.557533955743487), + Offset(26.890065739866895, 18.476404467546697), + Offset(26.84525762810885, 18.395263760542782), + Offset(26.80044951631057, 18.314123053518756), + Offset(26.79953506506211, 18.312467120719884), + ], + <Offset>[ + Offset(50.11037695941208, 50.02853304089169), + Offset(49.99054000291208, 49.90425767859169), + Offset(49.87070304641208, 49.779982316291694), + Offset(49.75086608991208, 49.6557069539917), + Offset(49.631029133312076, 49.5314315915917), + Offset(49.51119217681208, 49.4071562292917), + Offset(49.39135522031208, 49.28288086699169), + Offset(49.27151826381208, 49.15860550469169), + Offset(49.15168130721208, 49.034330142391696), + Offset(49.03184435071208, 48.9100547800917), + Offset(48.91200739421208, 48.7857794176917), + Offset(48.79217043771208, 48.66150405539169), + Offset(48.67233348121208, 48.53722869309169), + Offset(48.55249652461208, 48.412953330791694), + Offset(48.43265956811208, 48.2886779684917), + Offset(47.886224725057794, 47.521307740480445), + Offset(46.37283467228049, 45.1208643415384), + Offset(44.859444619603074, 42.45185274562246), + Offset(43.346054566925766, 39.51427295295898), + Offset(41.83266451414846, 36.30812496343945), + Offset(40.31927446147115, 32.83340877695263), + Offset(38.80588440879385, 29.090124393704222), + Offset(37.57729680711652, 25.730332389347893), + Offset(36.80002629848357, 23.19078423834003), + Offset(36.799396511844705, 21.440196815204512), + Offset(36.79888886839874, 20.472132118373413), + Offset(36.798481101983185, 20.275446961001492), + Offset(36.798160047714276, 20.102690905119566), + Offset(36.79791093245497, 19.94993821381455), + Offset(36.79772245845069, 19.814194600945225), + Offset(36.79758441807573, 19.692721660984457), + Offset(36.797488148804206, 19.583178817233097), + Offset(36.797426074710145, 19.483498384926143), + Offset(36.79739159858897, 19.391861154060404), + Offset(36.79737895089332, 19.306658130182875), + Offset(36.79738307228838, 19.22646109704454), + Offset(36.79739951722624, 19.14999852829856), + Offset(36.79742436471152, 19.076132860806798), + Offset(36.79745414717516, 19.003842529223242), + Offset(36.79748577699936, 18.93220267566557), + Offset(36.79751660719509, 18.860406520593376), + Offset(36.7975441640286, 18.787685822781068), + Offset(36.797566336361996, 18.7133709186601), + Offset(36.79758120646093, 18.636840503908616), + Offset(36.79758708492745, 18.557533955743487), + Offset(36.79758712071989, 18.476404467546697), + Offset(36.79758712071989, 18.395263760542782), + Offset(36.79758712071989, 18.314123053518756), + Offset(36.79758712071989, 18.312467120719884), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(50.1342941041875, 50.02853304089169), + Offset(50.014457147687494, 49.90425767859169), + Offset(49.8946201911875, 49.779982316291694), + Offset(49.7747832346875, 49.6557069539917), + Offset(49.65494627808749, 49.5314315915917), + Offset(49.5351093215875, 49.4071562292917), + Offset(49.415272365087496, 49.28288086699169), + Offset(49.295435408587494, 49.15860550469169), + Offset(49.1755984519875, 49.034330142391696), + Offset(49.055761495487495, 48.9100547800917), + Offset(48.9359245389875, 48.7857794176917), + Offset(48.8160875824875, 48.66150405539169), + Offset(48.696250625987496, 48.53722869309169), + Offset(48.5764136693875, 48.412953330791694), + Offset(48.4565767128875, 48.2886779684917), + Offset(48.02431502037189, 47.521307740480445), + Offset(46.98074593174941, 45.1208643415384), + Offset(46.08548658116816, 42.45185274562246), + Offset(45.338536968526306, 39.51427295295898), + Offset(44.73989709372328, 36.30812496343945), + Offset(44.28956695695909, 32.83340877695263), + Offset(43.9875465581158, 29.090124393704222), + Offset(43.91970523287322, 25.730332389347893), + Offset(44.10552703056539, 23.19078423834003), + Offset(45.07126540837772, 21.440196815204512), + Offset(45.60506520753746, 20.472132118373413), + Offset(45.7130454079458, 20.275446961001492), + Offset(45.80794597703926, 20.102690905119566), + Offset(45.89191187243428, 19.94993821381455), + Offset(45.96657907636557, 19.814194600945225), + Offset(46.0334439590158, 19.692721660984457), + Offset(46.09378559792097, 19.583178817233097), + Offset(46.14873405934452, 19.483498384926143), + Offset(46.19928371471381, 19.391861154060404), + Offset(46.24631413371717, 19.306658130182875), + Offset(46.29060615824605, 19.22646109704454), + Offset(46.332855054781064, 19.14999852829856), + Offset(46.37368292614194, 19.076132860806798), + Offset(46.41364852205306, 19.003842529223242), + Offset(46.453257777743495, 18.93220267566557), + Offset(46.492952106563976, 18.860406520593376), + Offset(46.533151908941335, 18.787685822781068), + Offset(46.574223711150275, 18.7133709186601), + Offset(46.61650763441162, 18.636840503908616), + Offset(46.66031064453808, 18.557533955743487), + Offset(46.70511125417474, 18.476404467546697), + Offset(46.74991800356274, 18.395263760542782), + Offset(46.79472475293062, 18.314123053518756), + Offset(46.79563917637766, 18.312467120719884), + ], + <Offset>[ + Offset(50.15368826922652, 50.04792720593072), + Offset(50.033851312726526, 49.92365184363072), + Offset(49.91401435622653, 49.799376481330725), + Offset(49.79417739972652, 49.675101119030714), + Offset(49.674340443126525, 49.550825756630715), + Offset(49.55450348662653, 49.42655039433072), + Offset(49.43466653012652, 49.30227503203072), + Offset(49.314829573626525, 49.177999669730724), + Offset(49.19499261702653, 49.05372430743071), + Offset(49.07515566052652, 48.929448945130716), + Offset(48.955318704026524, 48.80517358273072), + Offset(48.83548174752653, 48.68089822043072), + Offset(48.71564479102652, 48.55662285813072), + Offset(48.59580783442652, 48.43234749583071), + Offset(48.47597087792653, 48.308072133530715), + Offset(48.136288078984855, 47.63328079909341), + Offset(47.473679845580676, 45.61379825536869), + Offset(47.07964031920627, 43.44600648365714), + Offset(46.95416949975036, 41.12990548418304), + Offset(47.097267387117355, 38.66549525683352), + Offset(47.508933981507255, 36.05277580150079), + Offset(48.18916928282006, 33.29174711839053), + Offset(49.06253495466028, 30.873162111115967), + Offset(50.02929327547615, 29.114550483250788), + Offset(51.77862444643605, 28.14755585326284), + Offset(52.74567493591703, 27.612742526019634), + Offset(52.94154343336185, 27.50394701174588), + Offset(53.11365619281698, 27.408404506536808), + Offset(53.26590941777883, 27.323940514375185), + Offset(53.40127480891536, 27.24889646368377), + Offset(53.522470364938954, 27.18175557438962), + Offset(53.63181934443066, 27.121221448636877), + Offset(53.731374286002364, 27.066148872338097), + Offset(53.822941209917815, 27.015530283280118), + Offset(53.9081175752586, 26.968474575656916), + Offset(53.988321482634554, 26.924190791684836), + Offset(54.064815569663324, 26.88197477619479), + Offset(54.13872955933007, 26.841196586461674), + Offset(54.211078083148614, 26.801290539485016), + Offset(54.282779824728905, 26.761744526458138), + Offset(54.3546362702083, 26.72211184147367), + Offset(54.42741071364266, 26.681967137945506), + Offset(54.50176859638355, 26.640939668537342), + Offset(54.57832738700239, 26.598685477488804), + Offset(54.65764432912613, 26.5548942211387), + Offset(54.73877252649494, 26.510093683047582), + Offset(54.81991187110869, 26.46528693369982), + Offset(54.90105121572243, 26.42048018431182), + Offset(54.90270712071989, 26.419565760864774), + ], + <Offset>[ + Offset(50.15368826922652, 50.07184435070614), + Offset(50.033851312726526, 49.94756898840614), + Offset(49.91401435622653, 49.82329362610614), + Offset(49.79417739972652, 49.69901826380614), + Offset(49.674340443126525, 49.57474290140614), + Offset(49.55450348662653, 49.45046753910614), + Offset(49.43466653012652, 49.32619217680614), + Offset(49.314829573626525, 49.20191681450614), + Offset(49.19499261702653, 49.07764145220614), + Offset(49.07515566052652, 48.95336608990614), + Offset(48.955318704026524, 48.82909072750614), + Offset(48.83548174752653, 48.70481536520614), + Offset(48.71564479102652, 48.58054000290614), + Offset(48.59580783442652, 48.456264640606136), + Offset(48.47597087792653, 48.33198927830614), + Offset(48.136288078984855, 47.7713707071586), + Offset(47.473679845580676, 46.22170752947072), + Offset(47.07964031920627, 44.672044351691675), + Offset(46.95416949975036, 43.12238117401274), + Offset(47.097267387117355, 41.572717996339655), + Offset(47.508933981507255, 40.02305481856121), + Offset(48.18916928282006, 38.47339164088308), + Offset(49.06253495466028, 37.21554892929752), + Offset(50.02929327547615, 36.42002629846431), + Offset(51.77862444643605, 36.41939651182523), + Offset(52.74567493591703, 36.41888886837908), + Offset(52.94154343336185, 36.41848110196339), + Offset(53.11365619281698, 36.41816004771427), + Offset(53.26590941777883, 36.41791093245497), + Offset(53.40127480891536, 36.4177224584507), + Offset(53.522470364938954, 36.417584418075734), + Offset(53.63181934443066, 36.4174881488042), + Offset(53.731374286002364, 36.417426074710136), + Offset(53.822941209917815, 36.41739159858898), + Offset(53.9081175752586, 36.417378950893315), + Offset(53.988321482634554, 36.41738307228838), + Offset(54.064815569663324, 36.41739951720605), + Offset(54.13872955933007, 36.41742436469134), + Offset(54.211078083148614, 36.417454147155), + Offset(54.282779824728905, 36.417485776979206), + Offset(54.3546362702083, 36.417516607174946), + Offset(54.42741071364266, 36.41754416400846), + Offset(54.50176859638355, 36.41756633636199), + Offset(54.57832738700239, 36.41758120646094), + Offset(54.65764432912613, 36.41758708492745), + Offset(54.73877252649494, 36.41758712071989), + Offset(54.81991187110869, 36.41758712071989), + Offset(54.90105121572243, 36.41758712071989), + Offset(54.90270712071989, 36.41758712071989), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(50.15368826922652, 50.095761495481554), + Offset(50.033851312726526, 49.97148613318156), + Offset(49.91401435622653, 49.84721077088156), + Offset(49.79417739972652, 49.722935408581556), + Offset(49.674340443126525, 49.59866004618156), + Offset(49.55450348662653, 49.47438468388156), + Offset(49.43466653012652, 49.350109321581556), + Offset(49.314829573626525, 49.22583395928156), + Offset(49.19499261702653, 49.101558596981555), + Offset(49.07515566052652, 48.97728323468156), + Offset(48.955318704026524, 48.85300787228156), + Offset(48.83548174752653, 48.728732509981555), + Offset(48.71564479102652, 48.60445714768156), + Offset(48.59580783442652, 48.48018178538155), + Offset(48.47597087792653, 48.35590642308156), + Offset(48.136288078984855, 47.909461002472696), + Offset(47.473679845580676, 46.82961878893964), + Offset(47.07964031920627, 45.89808631325676), + Offset(46.95416949975036, 45.11486357561327), + Offset(47.097267387117355, 44.47995057591447), + Offset(47.508933981507255, 43.993347314049146), + Offset(48.18916928282006, 43.65505379020504), + Offset(49.06253495466028, 43.55795735505423), + Offset(50.02929327547615, 43.725527030546125), + Offset(51.77862444643605, 44.69126540835824), + Offset(52.74567493591703, 45.225065207517794), + Offset(52.94154343336185, 45.333045407926), + Offset(53.11365619281698, 45.42794597703926), + Offset(53.26590941777883, 45.511911872434275), + Offset(53.40127480891536, 45.58657907636557), + Offset(53.522470364938954, 45.653443959015796), + Offset(53.63181934443066, 45.71378559792097), + Offset(53.731374286002364, 45.76873405934451), + Offset(53.822941209917815, 45.819283714713805), + Offset(53.9081175752586, 45.86631413371717), + Offset(53.988321482634554, 45.91060615824605), + Offset(54.064815569663324, 45.95285505476088), + Offset(54.13872955933007, 45.993682926121764), + Offset(54.211078083148614, 46.03364852203289), + Offset(54.282779824728905, 46.07325777772334), + Offset(54.3546362702083, 46.11295210654383), + Offset(54.42741071364266, 46.1531519089212), + Offset(54.50176859638355, 46.19422371115027), + Offset(54.57832738700239, 46.236507634411616), + Offset(54.65764432912613, 46.280310644538076), + Offset(54.73877252649494, 46.32511125417474), + Offset(54.81991187110869, 46.36991800356274), + Offset(54.90105121572243, 46.41472475293062), + Offset(54.90270712071989, 46.41563917637766), + ], + <Offset>[ + Offset(50.1342941041875, 50.11515566052058), + Offset(50.014457147687494, 49.99088029822058), + Offset(49.8946201911875, 49.866604935920584), + Offset(49.7747832346875, 49.74232957362058), + Offset(49.65494627808749, 49.61805421122058), + Offset(49.5351093215875, 49.493778848920584), + Offset(49.415272365087496, 49.36950348662058), + Offset(49.295435408587494, 49.24522812432058), + Offset(49.1755984519875, 49.12095276202058), + Offset(49.055761495487495, 48.99667739972058), + Offset(48.9359245389875, 48.87240203732058), + Offset(48.8160875824875, 48.74812667502058), + Offset(48.696250625987496, 48.62385131272058), + Offset(48.5764136693875, 48.49957595042058), + Offset(48.4565767128875, 48.37530058812058), + Offset(48.02431502037189, 48.02143406108567), + Offset(46.980745931750384, 47.32255270277091), + Offset(46.08548658117158, 46.89224005129487), + Offset(45.3385369685263, 46.73049610683733), + Offset(44.73989709372328, 46.83732086930855), + Offset(44.28956695695909, 47.21271433859731), + Offset(43.98754655813375, 47.856676514909296), + Offset(43.919705232892206, 48.70078707684129), + Offset(44.10552703056539, 49.649293275456884), + Offset(45.07126540837772, 51.39862444641657), + Offset(45.60506520755712, 52.36567493589737), + Offset(45.7130454079458, 52.56154343334205), + Offset(45.80794597703926, 52.73365619281698), + Offset(45.89191187243428, 52.88590941777883), + Offset(45.96657907636557, 53.021274808915365), + Offset(46.0334439590158, 53.14247036493895), + Offset(46.09378559792097, 53.25181934443066), + Offset(46.14873405934452, 53.351374286002354), + Offset(46.19928371469362, 53.44294120991781), + Offset(46.24631413371717, 53.5281175752586), + Offset(46.29060615824605, 53.60832148263455), + Offset(46.332855054781064, 53.68481556964314), + Offset(46.373682926141946, 53.7587295593099), + Offset(46.413648522073224, 53.83107808312845), + Offset(46.453257777743495, 53.90277982470875), + Offset(46.49295210656398, 53.97463627018816), + Offset(46.533151908941335, 54.04741071362252), + Offset(46.574223711150275, 54.121768596383546), + Offset(46.61650763441162, 54.19832738700239), + Offset(46.660310644538086, 54.27764432912612), + Offset(46.70511125417474, 54.35877252649494), + Offset(46.74991800354262, 54.439911871108684), + Offset(46.79472475293062, 54.52105121572244), + Offset(46.79563917637766, 54.522707120719886), + ], + <Offset>[ + Offset(50.11037695941208, 50.11515566052058), + Offset(49.99054000291208, 49.99088029822058), + Offset(49.87070304641208, 49.866604935920584), + Offset(49.75086608991208, 49.74232957362058), + Offset(49.631029133312076, 49.61805421122058), + Offset(49.51119217681208, 49.493778848920584), + Offset(49.39135522031208, 49.36950348662058), + Offset(49.27151826381208, 49.24522812432058), + Offset(49.15168130721208, 49.12095276202058), + Offset(49.03184435071208, 48.99667739972058), + Offset(48.91200739421208, 48.87240203732058), + Offset(48.79217043771208, 48.74812667502058), + Offset(48.67233348121208, 48.62385131272058), + Offset(48.55249652461208, 48.49957595042058), + Offset(48.43265956811208, 48.37530058812058), + Offset(47.886224725057794, 48.02143406108567), + Offset(46.37283467228049, 47.32255270277091), + Offset(44.859444619603074, 46.89224005129487), + Offset(43.346054566925766, 46.73049610683733), + Offset(41.83266451414846, 46.83732086930855), + Offset(40.31927446147115, 47.21271433859731), + Offset(38.80588440879385, 47.856676514909296), + Offset(37.57729680711652, 48.70078707684129), + Offset(36.80002629848357, 49.649293275456884), + Offset(36.799396511844705, 51.39862444641657), + Offset(36.79888886839874, 52.36567493589737), + Offset(36.798481101983185, 52.56154343334205), + Offset(36.798160047714276, 52.73365619281698), + Offset(36.79791093245497, 52.88590941777883), + Offset(36.79772245845069, 53.021274808915365), + Offset(36.79758441807573, 53.14247036493895), + Offset(36.797488148804206, 53.25181934443066), + Offset(36.797426074710145, 53.351374286002354), + Offset(36.79739159858897, 53.44294120991781), + Offset(36.79737895089332, 53.5281175752586), + Offset(36.79738307228838, 53.60832148263455), + Offset(36.79739951722624, 53.68481556964314), + Offset(36.79742436471152, 53.7587295593099), + Offset(36.79745414717516, 53.83107808312845), + Offset(36.79748577699936, 53.90277982470875), + Offset(36.79751660719509, 53.97463627018816), + Offset(36.7975441640286, 54.04741071362252), + Offset(36.797566336361996, 54.121768596383546), + Offset(36.79758120646093, 54.19832738700239), + Offset(36.79758708492745, 54.27764432912612), + Offset(36.79758712071989, 54.35877252649494), + Offset(36.79758712071989, 54.439911871108684), + Offset(36.79758712071989, 54.52105121572244), + Offset(36.79758712071989, 54.522707120719886), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + ], + <Offset>[ + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + ], + <Offset>[ + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + ], + <Offset>[ + Offset(56.04837809389354, 52.900684331474906), + Offset(56.030300891829654, 52.8847340126718), + Offset(56.01222368976779, 52.86878369386669), + Offset(55.9941464877039, 52.85283337506358), + Offset(55.976069285642026, 52.83688305626048), + Offset(55.95799208358016, 52.820932737455365), + Offset(55.93991488151627, 52.80498241865226), + Offset(55.921837679454406, 52.78903209984916), + Offset(55.90376047739254, 52.77308178104404), + Offset(55.88568327532865, 52.757131462240935), + Offset(55.86760607326678, 52.741181143437835), + Offset(55.84952887120491, 52.72523082463272), + Offset(55.831451669141025, 52.70928050582962), + Offset(55.81337446707916, 52.69333018702651), + Offset(55.79529726501527, 52.6773798682214), + Offset(55.78900433275297, 52.672562732506236), + Offset(55.80942241203834, 52.69298081179161), + Offset(55.829840491323715, 52.713398891074974), + Offset(55.850258570607075, 52.73381697036035), + Offset(55.87067664989245, 52.75423504964572), + Offset(55.89109472917782, 52.77465312892909), + Offset(55.91151280846119, 52.795071208214466), + Offset(55.93193088774657, 52.81548928749984), + Offset(55.952348967031945, 52.8359073667832), + Offset(55.972767046315305, 52.856325446068574), + Offset(55.997486569314425, 52.87878031963378), + Offset(56.02633547827809, 52.9031905157102), + Offset(56.05518438724176, 52.9276007117846), + Offset(56.084033296203415, 52.952010907861016), + Offset(56.11288220516708, 52.97642110393542), + Offset(56.14173111413075, 53.00083130001184), + Offset(56.170580023094416, 53.025241496086245), + Offset(56.19942893205808, 53.04965169216266), + Offset(56.22827784102175, 53.07406188823707), + Offset(56.25712674998542, 53.098472084313485), + Offset(56.285975658949084, 53.122882280387884), + Offset(56.31482456791073, 53.1472924764643), + Offset(56.3436734768744, 53.17170267253871), + Offset(56.37252238583807, 53.196112868615124), + Offset(56.401371294801734, 53.22052306468953), + Offset(56.4302202037654, 53.24493326076595), + Offset(56.45906911272907, 53.26934345684035), + Offset(56.487918021692735, 53.29375365291677), + Offset(56.51676693065439, 53.318163848991176), + Offset(56.54561583961806, 53.342574045067586), + Offset(56.574464748581725, 53.36698424114199), + Offset(56.60331365754539, 53.39139443721841), + Offset(56.63216256650906, 53.415804633292815), + Offset(56.632751319752806, 53.41630280056001), + ], + <Offset>[ + Offset(56.04837809389354, 52.900684331474906), + Offset(56.030300891829654, 52.8847340126718), + Offset(56.01222368976779, 52.86878369386669), + Offset(55.9941464877039, 52.85283337506358), + Offset(55.976069285642026, 52.83688305626048), + Offset(55.95799208358016, 52.820932737455365), + Offset(55.93991488151627, 52.80498241865226), + Offset(55.921837679454406, 52.78903209984916), + Offset(55.90376047739254, 52.77308178104404), + Offset(55.88568327532865, 52.757131462240935), + Offset(55.86760607326678, 52.741181143437835), + Offset(55.84952887120491, 52.72523082463272), + Offset(55.831451669141025, 52.70928050582962), + Offset(55.81337446707916, 52.69333018702651), + Offset(55.79529726501527, 52.6773798682214), + Offset(55.78900433275297, 52.672562732506236), + Offset(55.80942241203834, 52.69298081179161), + Offset(55.829840491323715, 52.713398891074974), + Offset(55.850258570607075, 52.73381697036035), + Offset(55.87067664989245, 52.75423504964572), + Offset(55.89109472917782, 52.77465312892909), + Offset(55.91151280846119, 52.795071208214466), + Offset(55.93193088774657, 52.81548928749984), + Offset(55.952348967031945, 52.8359073667832), + Offset(55.972767046315305, 52.856325446068574), + Offset(55.997486569314425, 52.87878031963378), + Offset(56.02633547827809, 52.9031905157102), + Offset(56.05518438724176, 52.9276007117846), + Offset(56.084033296203415, 52.952010907861016), + Offset(56.11288220516708, 52.97642110393542), + Offset(56.14173111413075, 53.00083130001184), + Offset(56.170580023094416, 53.025241496086245), + Offset(56.19942893205808, 53.04965169216266), + Offset(56.22827784102175, 53.07406188823707), + Offset(56.25712674998542, 53.098472084313485), + Offset(56.285975658949084, 53.122882280387884), + Offset(56.31482456791073, 53.1472924764643), + Offset(56.3436734768744, 53.17170267253871), + Offset(56.37252238583807, 53.196112868615124), + Offset(56.401371294801734, 53.22052306468953), + Offset(56.4302202037654, 53.24493326076595), + Offset(56.45906911272907, 53.26934345684035), + Offset(56.487918021692735, 53.29375365291677), + Offset(56.51676693065439, 53.318163848991176), + Offset(56.54561583961806, 53.342574045067586), + Offset(56.574464748581725, 53.36698424114199), + Offset(56.60331365754539, 53.39139443721841), + Offset(56.63216256650906, 53.415804633292815), + Offset(56.632751319752806, 53.41630280056001), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(56.04837809389354, 52.9006440978749), + Offset(56.030300891829654, 52.8846937790718), + Offset(56.01222368976779, 52.868743460266685), + Offset(55.9941464877039, 52.85279314146358), + Offset(55.976069285642026, 52.83684282266048), + Offset(55.95799208358016, 52.82089250385536), + Offset(55.93991488151627, 52.80494218505226), + Offset(55.921837679454406, 52.788991866249155), + Offset(55.90376047739254, 52.773041547444045), + Offset(55.88568327532865, 52.75709122864094), + Offset(55.86760607326678, 52.74114090983784), + Offset(55.84952887120491, 52.72519059103272), + Offset(55.831451669141025, 52.709240272229614), + Offset(55.81337446707916, 52.693289953426515), + Offset(55.79529726501527, 52.6773396346214), + Offset(55.78900433275297, 52.67252249890623), + Offset(55.80942241203834, 52.69294057819161), + Offset(55.829840491323715, 52.71335865747497), + Offset(55.850258570607075, 52.73377673676035), + Offset(55.87067664989245, 52.754194816045725), + Offset(55.89109472917782, 52.774612895329085), + Offset(55.91151280846119, 52.79503097461446), + Offset(55.93193088774657, 52.81544905389984), + Offset(55.952348967031945, 52.8358671331832), + Offset(55.972767046315305, 52.85628521246858), + Offset(55.997486569314425, 52.87874008603378), + Offset(56.02633547827809, 52.9031502821102), + Offset(56.05518438724176, 52.9275604781846), + Offset(56.084033296203415, 52.95197067426102), + Offset(56.11288220516708, 52.976380870335426), + Offset(56.14173111413075, 53.00079106641184), + Offset(56.170580023094416, 53.02520126248624), + Offset(56.19942893205808, 53.049611458562666), + Offset(56.22827784102175, 53.074021654637065), + Offset(56.25712674998542, 53.09843185071348), + Offset(56.285975658949084, 53.12284204678789), + Offset(56.31482456791073, 53.147252242864305), + Offset(56.3436734768744, 53.17166243893871), + Offset(56.37252238583807, 53.19607263501513), + Offset(56.401371294801734, 53.22048283108953), + Offset(56.4302202037654, 53.24489302716594), + Offset(56.45906911272907, 53.26930322324035), + Offset(56.487918021692735, 53.29371341931677), + Offset(56.51676693065439, 53.31812361539117), + Offset(56.54561583961806, 53.34253381146759), + Offset(56.574464748581725, 53.366944007541996), + Offset(56.60331365754539, 53.39135420361841), + Offset(56.63216256650906, 53.41576439969282), + Offset(56.632751319752806, 53.41626256696001), + ], + <Offset>[ + Offset(53.21193262270276, 55.75726624798824), + Offset(53.193855420638876, 55.741315929185134), + Offset(53.17577821857701, 55.725365610380024), + Offset(53.15770101651312, 55.70941529157692), + Offset(53.139623814451255, 55.69346497277382), + Offset(53.12154661238938, 55.6775146539687), + Offset(53.1034694103255, 55.6615643351656), + Offset(53.08539220826363, 55.645614016362494), + Offset(53.06731500620175, 55.629663697557376), + Offset(53.049237804137874, 55.61371337875428), + Offset(53.031160602076, 55.59776305995117), + Offset(53.01308340001413, 55.58181274114605), + Offset(52.99500619795025, 55.56586242234295), + Offset(52.97692899588838, 55.549912103539846), + Offset(52.95885179382449, 55.533961784734736), + Offset(52.95255886156219, 55.52914464901957), + Offset(52.97297694084756, 55.54956272830495), + Offset(52.99339502013294, 55.56998080758831), + Offset(53.013813099416296, 55.590398886873686), + Offset(53.034231178701674, 55.610816966159064), + Offset(53.05464925798705, 55.63123504544242), + Offset(53.07506733727041, 55.6516531247278), + Offset(53.09548541655579, 55.67207120401317), + Offset(53.11590349584117, 55.69248928329654), + Offset(53.136321575124526, 55.712907362581916), + Offset(53.16104109812365, 55.73536223614712), + Offset(53.189890007087314, 55.759772432223535), + Offset(53.21873891605098, 55.78418262829794), + Offset(53.24758782501264, 55.80859282437436), + Offset(53.276436733976304, 55.83300302044876), + Offset(53.30528564293997, 55.857413216525174), + Offset(53.33413455190364, 55.88182341259958), + Offset(53.362983460867305, 55.906233608676), + Offset(53.39183236983097, 55.9306438047504), + Offset(53.42068127879464, 55.95505400082682), + Offset(53.449530187758306, 55.979464196901226), + Offset(53.47837909671996, 56.00387439297764), + Offset(53.50722800568363, 56.02828458905205), + Offset(53.53607691464729, 56.052694785128466), + Offset(53.56492582361096, 56.077104981202865), + Offset(53.59377473257462, 56.10151517727928), + Offset(53.6226236415383, 56.12592537335369), + Offset(53.65147255050196, 56.150335569430105), + Offset(53.68032145946361, 56.17474576550451), + Offset(53.70917036842728, 56.19915596158093), + Offset(53.73801927739095, 56.22356615765533), + Offset(53.766868186354614, 56.247976353731744), + Offset(53.79571709531828, 56.27238654980615), + Offset(53.79630584856203, 56.272884717073346), + ], + <Offset>[ + Offset(53.21190192690009, 55.75726624798824), + Offset(53.19382472483621, 55.741315929185134), + Offset(53.17574752277434, 55.725365610380024), + Offset(53.15767032071045, 55.70941529157692), + Offset(53.139593118648584, 55.69346497277382), + Offset(53.121515916586716, 55.6775146539687), + Offset(53.10343871452283, 55.6615643351656), + Offset(53.08536151246096, 55.645614016362494), + Offset(53.06728431039909, 55.629663697557376), + Offset(53.04920710833521, 55.61371337875428), + Offset(53.031129906273335, 55.59776305995117), + Offset(53.01305270421147, 55.58181274114605), + Offset(52.99497550214758, 55.56586242234295), + Offset(52.97689830008571, 55.549912103539846), + Offset(52.95882109802183, 55.533961784734736), + Offset(52.95252816575952, 55.52914464901957), + Offset(52.972946245044895, 55.54956272830495), + Offset(52.993364324330265, 55.56998080758831), + Offset(53.01378240361363, 55.590398886873686), + Offset(53.03420048289901, 55.610816966159064), + Offset(53.05461856218438, 55.63123504544242), + Offset(53.07503664146775, 55.6516531247278), + Offset(53.095454720753125, 55.67207120401317), + Offset(53.115872800038495, 55.69248928329654), + Offset(53.13629087932186, 55.712907362581916), + Offset(53.161010402320976, 55.73536223614712), + Offset(53.18985931128464, 55.759772432223535), + Offset(53.21870822024831, 55.78418262829794), + Offset(53.247557129209966, 55.80859282437436), + Offset(53.27640603817363, 55.83300302044876), + Offset(53.3052549471373, 55.857413216525174), + Offset(53.33410385610097, 55.88182341259958), + Offset(53.362952765064634, 55.906233608676), + Offset(53.3918016740283, 55.9306438047504), + Offset(53.42065058299197, 55.95505400082682), + Offset(53.449499491955635, 55.979464196901226), + Offset(53.47834840091729, 56.00387439297764), + Offset(53.50719730988096, 56.02828458905205), + Offset(53.536046218844625, 56.052694785128466), + Offset(53.56489512780829, 56.077104981202865), + Offset(53.59374403677196, 56.10151517727928), + Offset(53.622592945735626, 56.12592537335369), + Offset(53.65144185469929, 56.150335569430105), + Offset(53.68029076366095, 56.17474576550451), + Offset(53.709139672624616, 56.19915596158093), + Offset(53.73798858158828, 56.22356615765533), + Offset(53.76683749055195, 56.247976353731744), + Offset(53.79568639951562, 56.27238654980615), + Offset(53.796275152759364, 56.272884717073346), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(53.21190192690009, 55.75722601438824), + Offset(53.19382472483621, 55.74127569558514), + Offset(53.17574752277434, 55.72532537678002), + Offset(53.15767032071045, 55.70937505797692), + Offset(53.139593118648584, 55.693424739173814), + Offset(53.121515916586716, 55.677474420368696), + Offset(53.10343871452283, 55.6615241015656), + Offset(53.08536151246096, 55.6455737827625), + Offset(53.06728431039909, 55.62962346395738), + Offset(53.04920710833521, 55.61367314515427), + Offset(53.031129906273335, 55.59772282635117), + Offset(53.01305270421147, 55.581772507546056), + Offset(52.99497550214758, 55.565822188742956), + Offset(52.97689830008571, 55.54987186993985), + Offset(52.95882109802183, 55.53392155113473), + Offset(52.95252816575952, 55.52910441541957), + Offset(52.972946245044895, 55.549522494704945), + Offset(52.993364324330265, 55.56994057398831), + Offset(53.01378240361363, 55.59035865327368), + Offset(53.03420048289901, 55.61077673255906), + Offset(53.05461856218438, 55.63119481184242), + Offset(53.07503664146775, 55.6516128911278), + Offset(53.095454720753125, 55.672030970413175), + Offset(53.115872800038495, 55.692449049696535), + Offset(53.13629087932186, 55.71286712898191), + Offset(53.161010402320976, 55.73532200254712), + Offset(53.18985931128464, 55.75973219862353), + Offset(53.21870822024831, 55.78414239469794), + Offset(53.247557129209966, 55.808552590774354), + Offset(53.27640603817363, 55.83296278684876), + Offset(53.3052549471373, 55.85737298292518), + Offset(53.33410385610097, 55.881783178999584), + Offset(53.362952765064634, 55.906193375076), + Offset(53.3918016740283, 55.9306035711504), + Offset(53.42065058299197, 55.955013767226816), + Offset(53.449499491955635, 55.97942396330122), + Offset(53.47834840091729, 56.00383415937764), + Offset(53.50719730988096, 56.028244355452046), + Offset(53.536046218844625, 56.05265455152846), + Offset(53.56489512780829, 56.07706474760286), + Offset(53.59374403677196, 56.101474943679285), + Offset(53.622592945735626, 56.125885139753684), + Offset(53.65144185469929, 56.15029533583011), + Offset(53.68029076366095, 56.17470553190451), + Offset(53.709139672624616, 56.199115727980924), + Offset(53.73798858158828, 56.22352592405533), + Offset(53.76683749055195, 56.24793612013175), + Offset(53.79568639951562, 56.27234631620615), + Offset(53.796275152759364, 56.27284448347334), + ], + <Offset>[ + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856235894), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856235894), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + ], + <Offset>[ + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856235894), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856235894), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + ], + <Offset>[ + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243940005), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + ], + <Offset>[ + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243940005), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243940005), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + ], + <Offset>[ + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.53659283720165), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.5785472078895, 61.10082674001624), + Offset(57.412981276788415, 62.9439908225431), + Offset(59.24741534567123, 64.7871549050921), + Offset(61.081849414574165, 66.63031898762097), + Offset(62.91628348345698, 68.47348307014985), + Offset(64.75071755235992, 70.31664715269883), + Offset(66.58515162124274, 72.15981123522772), + Offset(68.41958569014567, 74.00297531775661), + Offset(70.2540197590285, 75.84613940028547), + Offset(72.08845382793142, 77.68930348283448), + Offset(73.03297916605787, 78.63832439892204), + Offset(73.12319212266141, 78.72896787526297), + Offset(73.21340507924484, 78.81961135158377), + Offset(73.30361803584839, 78.9102548279046), + Offset(73.39383099245194, 79.0008983042254), + Offset(73.48404394903537, 79.09154178054621), + Offset(73.5742569056389, 79.18218525686703), + Offset(73.66446986222233, 79.27282873318785), + Offset(73.75468281882588, 79.36347220952878), + Offset(73.84489577542942, 79.45411568584959), + Offset(73.93510873201285, 79.5447591621704), + Offset(74.0253216886164, 79.6354026384912), + Offset(74.11553464521995, 79.72604611481202), + Offset(74.20574760180338, 79.81668959113284), + Offset(74.29596055840692, 79.90733306745365), + Offset(74.38617351501047, 79.99797654379458), + Offset(74.4763864715939, 80.0886200201154), + Offset(74.56659942819743, 80.1792634964362), + Offset(74.65681238478088, 80.26990697275701), + Offset(74.74702534138441, 80.36055044907783), + Offset(74.83723829798797, 80.45119392539866), + Offset(74.9274512545714, 80.54183740171945), + Offset(75.01766421117493, 80.63248087806039), + Offset(75.0195052919199, 80.63433074491833), + ], + <Offset>[ + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.53659283720165), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.5785472078895, 61.10082674001624), + Offset(57.412981276788415, 62.9439908225431), + Offset(59.24741534567123, 64.7871549050921), + Offset(61.081849414574165, 66.63031898762097), + Offset(62.91628348345698, 68.47348307014985), + Offset(64.75071755235992, 70.31664715269883), + Offset(66.58515162124274, 72.15981123522772), + Offset(68.41958569014567, 74.00297531775661), + Offset(70.2540197590285, 75.84613940028547), + Offset(72.08845382793142, 77.68930348283448), + Offset(73.03297916605787, 78.63832439892204), + Offset(73.12319212266141, 78.72896787526297), + Offset(73.21340507924484, 78.81961135158377), + Offset(73.30361803584839, 78.9102548279046), + Offset(73.39383099245194, 79.0008983042254), + Offset(73.48404394903537, 79.09154178054621), + Offset(73.5742569056389, 79.18218525686703), + Offset(73.66446986222233, 79.27282873318785), + Offset(73.75468281882588, 79.36347220952878), + Offset(73.84489577542942, 79.45411568584959), + Offset(73.93510873201285, 79.5447591621704), + Offset(74.0253216886164, 79.6354026384912), + Offset(74.11553464521995, 79.72604611481202), + Offset(74.20574760180338, 79.81668959113284), + Offset(74.29596055840692, 79.90733306745365), + Offset(74.38617351501047, 79.99797654379458), + Offset(74.4763864715939, 80.0886200201154), + Offset(74.56659942819743, 80.1792634964362), + Offset(74.65681238478088, 80.26990697275701), + Offset(74.74702534138441, 80.36055044907783), + Offset(74.83723829798797, 80.45119392539866), + Offset(74.9274512545714, 80.54183740171945), + Offset(75.01766421117493, 80.63248087806039), + Offset(75.0195052919199, 80.63433074491833), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.53659283720165), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.5785472078895, 61.10082674001624), + Offset(57.412981276788415, 62.9439908225431), + Offset(59.24741534567123, 64.7871549050921), + Offset(61.081849414574165, 66.63031898762097), + Offset(62.91628348345698, 68.47348307014985), + Offset(64.75071755235992, 70.31664715269883), + Offset(66.58515162124274, 72.15981123522772), + Offset(68.41958569014567, 74.00297531775661), + Offset(70.2540197590285, 75.84613940028547), + Offset(72.08845382793142, 77.68930348283448), + Offset(73.03297916605787, 78.63832439892204), + Offset(73.12319212266141, 78.72896787526297), + Offset(73.21340507924484, 78.81961135158377), + Offset(73.30361803584839, 78.9102548279046), + Offset(73.39383099245194, 79.0008983042254), + Offset(73.48404394903537, 79.09154178054621), + Offset(73.5742569056389, 79.18218525686703), + Offset(73.66446986222233, 79.27282873318785), + Offset(73.75468281882588, 79.36347220952878), + Offset(73.84489577542942, 79.45411568584959), + Offset(73.93510873201285, 79.5447591621704), + Offset(74.0253216886164, 79.6354026384912), + Offset(74.11553464521995, 79.72604611481202), + Offset(74.20574760180338, 79.81668959113284), + Offset(74.29596055840692, 79.90733306745365), + Offset(74.38617351501047, 79.99797654379458), + Offset(74.4763864715939, 80.0886200201154), + Offset(74.56659942819743, 80.1792634964362), + Offset(74.65681238478088, 80.26990697275701), + Offset(74.74702534138441, 80.36055044907783), + Offset(74.83723829798797, 80.45119392539866), + Offset(74.9274512545714, 80.54183740171945), + Offset(75.01766421117493, 80.63248087806039), + Offset(75.0195052919199, 80.63433074491833), + ], + <Offset>[ + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.54176433622131), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.57337474962035, 55.105999198285396), + Offset(63.407805684985675, 56.94916641434585), + Offset(65.24223662033491, 58.79233363042842), + Offset(67.07666755572437, 60.63550084647077), + Offset(68.9110984910736, 62.47866806253323), + Offset(70.74552942644296, 64.32183527861581), + Offset(72.57996036179219, 66.16500249467828), + Offset(74.41439129716153, 68.00816971074073), + Offset(76.24882223253088, 69.85133692678309), + Offset(78.08325316790022, 71.69450414286567), + Offset(79.02777766633133, 72.64352589864858), + Offset(79.11799198534516, 72.73416801257923), + Offset(79.20820630433886, 72.82481012648977), + Offset(79.29842062333256, 72.91545224042041), + Offset(79.38863494234639, 73.00609435433094), + Offset(79.47884926134012, 73.09673646824147), + Offset(79.56906358035394, 73.18737858215201), + Offset(79.65927789932752, 73.27802069608266), + Offset(79.74949221834135, 73.36866281001332), + Offset(79.83970653735517, 73.45930492392384), + Offset(79.92992085632878, 73.5499470378545), + Offset(80.0201351753426, 73.64058915176503), + Offset(80.11034949435643, 73.73123126567556), + Offset(80.20056381333, 73.82187337960622), + Offset(80.29077813234383, 73.91251549351674), + Offset(80.38099245135766, 74.00315760744739), + Offset(80.47120677033126, 74.09379972137803), + Offset(80.56142108934507, 74.18444183528857), + Offset(80.65163540833879, 74.2750839491991), + Offset(80.74184972735262, 74.36572606310963), + Offset(80.83206404634632, 74.45636817704029), + Offset(80.92227836534002, 74.54701029095082), + Offset(81.01249268435384, 74.63765240488146), + Offset(81.01433379290023, 74.639502243938), + ], + <Offset>[ + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.54176433622131), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.57337474962035, 55.105999198285396), + Offset(63.407805684985675, 56.94916641434585), + Offset(65.24223662033491, 58.79233363042842), + Offset(67.07666755572437, 60.63550084647077), + Offset(68.9110984910736, 62.47866806253323), + Offset(70.74552942644296, 64.32183527861581), + Offset(72.57996036179219, 66.16500249467828), + Offset(74.41439129716153, 68.00816971074073), + Offset(76.24882223253088, 69.85133692678309), + Offset(78.08325316790022, 71.69450414286567), + Offset(79.02777766633133, 72.64352589864858), + Offset(79.11799198534516, 72.73416801257923), + Offset(79.20820630433886, 72.82481012648977), + Offset(79.29842062333256, 72.91545224042041), + Offset(79.38863494234639, 73.00609435433094), + Offset(79.47884926134012, 73.09673646824147), + Offset(79.56906358035394, 73.18737858215201), + Offset(79.65927789932752, 73.27802069608266), + Offset(79.74949221834135, 73.36866281001332), + Offset(79.83970653735517, 73.45930492392384), + Offset(79.92992085632878, 73.5499470378545), + Offset(80.0201351753426, 73.64058915176503), + Offset(80.11034949435643, 73.73123126567556), + Offset(80.20056381333, 73.82187337960622), + Offset(80.29077813234383, 73.91251549351674), + Offset(80.38099245135766, 74.00315760744739), + Offset(80.47120677033126, 74.09379972137803), + Offset(80.56142108934507, 74.18444183528857), + Offset(80.65163540833879, 74.2750839491991), + Offset(80.74184972735262, 74.36572606310963), + Offset(80.83206404634632, 74.45636817704029), + Offset(80.92227836534002, 74.54701029095082), + Offset(81.01249268435384, 74.63765240488146), + Offset(81.01433379290023, 74.639502243938), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.54176433622131), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.57337474962035, 55.105999198285396), + Offset(63.407805684985675, 56.94916641434585), + Offset(65.24223662033491, 58.79233363042842), + Offset(67.07666755572437, 60.63550084647077), + Offset(68.9110984910736, 62.47866806253323), + Offset(70.74552942644296, 64.32183527861581), + Offset(72.57996036179219, 66.16500249467828), + Offset(74.41439129716153, 68.00816971074073), + Offset(76.24882223253088, 69.85133692678309), + Offset(78.08325316790022, 71.69450414286567), + Offset(79.02777766633133, 72.64352589864858), + Offset(79.11799198534516, 72.73416801257923), + Offset(79.20820630433886, 72.82481012648977), + Offset(79.29842062333256, 72.91545224042041), + Offset(79.38863494234639, 73.00609435433094), + Offset(79.47884926134012, 73.09673646824147), + Offset(79.56906358035394, 73.18737858215201), + Offset(79.65927789932752, 73.27802069608266), + Offset(79.74949221834135, 73.36866281001332), + Offset(79.83970653735517, 73.45930492392384), + Offset(79.92992085632878, 73.5499470378545), + Offset(80.0201351753426, 73.64058915176503), + Offset(80.11034949435643, 73.73123126567556), + Offset(80.20056381333, 73.82187337960622), + Offset(80.29077813234383, 73.91251549351674), + Offset(80.38099245135766, 74.00315760744739), + Offset(80.47120677033126, 74.09379972137803), + Offset(80.56142108934507, 74.18444183528857), + Offset(80.65163540833879, 74.2750839491991), + Offset(80.74184972735262, 74.36572606310963), + Offset(80.83206404634632, 74.45636817704029), + Offset(80.92227836534002, 74.54701029095082), + Offset(81.01249268435384, 74.63765240488146), + Offset(81.01433379290023, 74.639502243938), + ], + <Offset>[ + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.522702243936166), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.937745291917885, 54.52270224394), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529189977, 54.52270224395811), + Offset(60.93774529194001, 54.52270224393799), + Offset(60.937745291919896, 54.522702243937985), + Offset(60.937745291919896, 54.52270224395811), + Offset(60.93774529189977, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224391788), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529191989, 54.52270224395811), + Offset(60.93774529191989, 54.522702243937985), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529194001, 54.52270224391787), + Offset(60.93774529189977, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529194001, 54.52270224393799), + Offset(60.93774529189978, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529194002, 54.52270224393799), + Offset(60.93774529189978, 54.52270224393799), + Offset(60.937745291919896, 54.522702243938), + Offset(60.93774529194001, 54.52270224393799), + Offset(60.93774529189978, 54.52270224395811), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224391788), + Offset(60.937745291919896, 54.522702243938), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + ], + <Offset>[ + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.522702243936166), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.937745291917885, 54.52270224394), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529189977, 54.52270224395811), + Offset(60.93774529194001, 54.52270224393799), + Offset(60.937745291919896, 54.522702243937985), + Offset(60.937745291919896, 54.522702243937985), + Offset(60.93774529189977, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224391788), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529191989, 54.52270224395811), + Offset(60.93774529191989, 54.522702243937985), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529194001, 54.52270224391787), + Offset(60.93774529189977, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529194001, 54.52270224393799), + Offset(60.93774529189978, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529194002, 54.52270224393799), + Offset(60.93774529189978, 54.52270224393799), + Offset(60.937745291919896, 54.522702243938), + Offset(60.93774529194001, 54.52270224393799), + Offset(60.93774529189978, 54.52270224395811), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224391788), + Offset(60.937745291919896, 54.522702243938), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.920754690484827), + Offset(48.0, 32.45354569710999), + Offset(48.0, 33.98010729644093), + Offset(48.0, 37.048746193280394), + Offset(48.0, 43.18831617722788), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.920754690484827), + Offset(52.445826306158004, 32.45354569710999), + Offset(52.445826306158004, 33.98010729644093), + Offset(52.445826306158004, 37.048746193280394), + Offset(52.445826306158004, 43.18831617722788), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + ], + <Offset>[ + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.319830300840163), + Offset(56.04672, 28.852621307465323), + Offset(56.04672, 30.379182906796263), + Offset(56.04672, 33.44782180363573), + Offset(56.04672, 39.587391787583215), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + ], + <Offset>[ + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.874034690484827), + Offset(56.04672, 24.406825697109987), + Offset(56.04672, 25.933387296440927), + Offset(56.04672, 29.002026193280393), + Offset(56.04672, 35.14159617722788), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.428208384326826), + Offset(56.04672, 19.960999390951986), + Offset(56.04672, 21.487560990282926), + Offset(56.04672, 24.556199887122393), + Offset(56.04672, 30.69576987106988), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + ], + <Offset>[ + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.827314690484826), + Offset(52.445826306158004, 16.360105697109987), + Offset(52.445826306158004, 17.886667296440926), + Offset(52.445826306158004, 20.955306193280393), + Offset(52.445826306158004, 27.09487617722788), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + ], + <Offset>[ + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.827314690484826), + Offset(48.0, 16.360105697109987), + Offset(48.0, 17.886667296440926), + Offset(48.0, 20.955306193280393), + Offset(48.0, 27.09487617722788), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.827314690484826), + Offset(43.554173693841996, 16.360105697109987), + Offset(43.554173693841996, 17.886667296440926), + Offset(43.554173693841996, 20.955306193280393), + Offset(43.554173693841996, 27.09487617722788), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + ], + <Offset>[ + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.428208384326826), + Offset(39.95328, 19.960999390951986), + Offset(39.95328, 21.487560990282926), + Offset(39.95328, 24.556199887122393), + Offset(39.95328, 30.69576987106988), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + ], + <Offset>[ + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.874034690484827), + Offset(39.95328, 24.406825697109987), + Offset(39.95328, 25.933387296440927), + Offset(39.95328, 29.002026193280393), + Offset(39.95328, 35.14159617722788), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.319830300840163), + Offset(39.95328, 28.852621307465323), + Offset(39.95328, 30.379182906796263), + Offset(39.95328, 33.44782180363573), + Offset(39.95328, 39.587391787583215), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + ], + <Offset>[ + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.920754690484827), + Offset(43.554173693841996, 32.45354569710999), + Offset(43.554173693841996, 33.98010729644093), + Offset(43.554173693841996, 37.048746193280394), + Offset(43.554173693841996, 43.18831617722788), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + ], + <Offset>[ + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.920754690484827), + Offset(48.0, 32.45354569710999), + Offset(48.0, 33.98010729644093), + Offset(48.0, 37.048746193280394), + Offset(48.0, 43.18831617722788), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + ], + <Offset>[ + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + ], + <Offset>[ + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + ], + <Offset>[ + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + ], + <Offset>[ + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + ], + <Offset>[ + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + ], + <Offset>[ + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + ], + <Offset>[ + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + ], + <Offset>[ + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.07926469426482), + Offset(48.0, 63.5472012869485), + Offset(48.0, 62.02272441694872), + Offset(48.0, 58.958276167797024), + Offset(48.0, 52.827090609197995), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.07926469426482), + Offset(43.554173693841996, 63.5472012869485), + Offset(43.554173693841996, 62.02272441694872), + Offset(43.554173693841996, 58.958276167797024), + Offset(43.554173693841996, 52.827090609197995), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + ], + <Offset>[ + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.68018908390948), + Offset(39.95328, 67.14812567659317), + Offset(39.95328, 65.62364880659338), + Offset(39.95328, 62.559200557441685), + Offset(39.95328, 56.428014998842656), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + ], + <Offset>[ + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.12598469426482), + Offset(39.95328, 71.5939212869485), + Offset(39.95328, 70.06944441694873), + Offset(39.95328, 67.00499616779703), + Offset(39.95328, 60.873810609197996), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.57181100042281), + Offset(39.95328, 76.0397475931065), + Offset(39.95328, 74.51527072310672), + Offset(39.95328, 71.45082247395503), + Offset(39.95328, 65.319636915356), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + ], + <Offset>[ + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.17270469426481), + Offset(43.554173693841996, 79.6406412869485), + Offset(43.554173693841996, 78.11616441694872), + Offset(43.554173693841996, 75.05171616779703), + Offset(43.554173693841996, 68.920530609198), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + ], + <Offset>[ + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.17270469426481), + Offset(48.0, 79.6406412869485), + Offset(48.0, 78.11616441694872), + Offset(48.0, 75.05171616779703), + Offset(48.0, 68.920530609198), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.17270469426481), + Offset(52.445826306158004, 79.6406412869485), + Offset(52.445826306158004, 78.11616441694872), + Offset(52.445826306158004, 75.05171616779703), + Offset(52.445826306158004, 68.920530609198), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + ], + <Offset>[ + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.57181100042281), + Offset(56.04672, 76.0397475931065), + Offset(56.04672, 74.51527072310672), + Offset(56.04672, 71.45082247395503), + Offset(56.04672, 65.319636915356), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + ], + <Offset>[ + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.12598469426482), + Offset(56.04672, 71.5939212869485), + Offset(56.04672, 70.06944441694873), + Offset(56.04672, 67.00499616779703), + Offset(56.04672, 60.873810609197996), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.68018908390948), + Offset(56.04672, 67.14812567659317), + Offset(56.04672, 65.62364880659338), + Offset(56.04672, 62.559200557441685), + Offset(56.04672, 56.428014998842656), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + ], + <Offset>[ + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.07926469426482), + Offset(52.445826306158004, 63.5472012869485), + Offset(52.445826306158004, 62.02272441694872), + Offset(52.445826306158004, 58.958276167797024), + Offset(52.445826306158004, 52.827090609197995), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + ], + <Offset>[ + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.07926469426482), + Offset(48.0, 63.5472012869485), + Offset(48.0, 62.02272441694872), + Offset(48.0, 58.958276167797024), + Offset(48.0, 52.827090609197995), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + ], + ), + _PathClose( + ), + ], + ), + ], +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/event_add.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/event_add.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..1b64f8998fd170aa8b0215e08c89b1789136b7a7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/event_add.g.dart @@ -0,0 +1,3308 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$event_add = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.761904761905, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(32.01015625, 23.52890625), + Offset(32.01015329719101, 23.53062658538017), + Offset(31.908309754160946, 24.86045986263573), + Offset(29.93347206506402, 28.868314694169428), + Offset(26.259363778077685, 30.74028679651635), + Offset(23.62410382175968, 30.58943972916481), + Offset(21.925014841592773, 29.92755775441251), + Offset(20.79646278990295, 29.175637008874478), + Offset(20.023435215871057, 28.454097084853878), + Offset(19.478915461565702, 27.800711501947685), + Offset(19.08488578667808, 27.224748870271775), + Offset(18.794354809526837, 26.724256833788246), + Offset(18.590826530804044, 26.293721762918267), + Offset(18.45085412812233, 25.930620946266075), + Offset(18.35542242952162, 25.63066280891873), + Offset(18.291196017351787, 25.38919913375952), + Offset(18.248665479323506, 25.201028049969374), + Offset(18.221259589085008, 25.06135592936411), + Offset(18.204520556081953, 24.965782149690927), + Offset(18.19555633054043, 24.91035753064884), + Offset(18.192643234510292, 24.891585410299637), + Offset(18.192636718750002, 24.891542968750002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(32.01015625, 23.52890625), + Offset(32.01015329719101, 23.53062658538017), + Offset(31.908309754160946, 24.86045986263573), + Offset(29.93347206506402, 28.868314694169428), + Offset(26.259363778077685, 30.74028679651635), + Offset(23.62410382175968, 30.58943972916481), + Offset(21.925014841592773, 29.92755775441251), + Offset(20.79646278990295, 29.175637008874478), + Offset(20.023435215871057, 28.454097084853878), + Offset(19.478915461565702, 27.800711501947685), + Offset(19.08488578667808, 27.224748870271775), + Offset(18.794354809526837, 26.724256833788246), + Offset(18.590826530804044, 26.293721762918267), + Offset(18.45085412812233, 25.930620946266075), + Offset(18.35542242952162, 25.63066280891873), + Offset(18.291196017351787, 25.38919913375952), + Offset(18.248665479323506, 25.201028049969374), + Offset(18.221259589085008, 25.06135592936411), + Offset(18.204520556081953, 24.965782149690927), + Offset(18.19555633054043, 24.91035753064884), + Offset(18.192643234510292, 24.891585410299637), + Offset(18.192636718750002, 24.891542968750002), + ], + <Offset>[ + Offset(24.01015625, 23.52890625), + Offset(24.010258478063488, 23.528888402424656), + Offset(24.091555200930664, 23.52418084688126), + Offset(24.377115816859927, 23.6152417705347), + Offset(24.633459690010874, 23.859538100350317), + Offset(24.736069637313253, 24.1352514457875), + Offset(24.72116824601048, 24.371795772576675), + Offset(24.648015807099657, 24.549452838288758), + Offset(24.55323690381452, 24.674789163937373), + Offset(24.455385525488182, 24.759322859315567), + Offset(24.363483168967523, 24.813428460885813), + Offset(24.28176718778124, 24.845878439805734), + Offset(24.21233699329442, 24.865919213504945), + Offset(24.154550207153598, 24.87807591728), + Offset(24.107302586424357, 24.885092784958154), + Offset(24.06957428023968, 24.88885460147735), + Offset(24.040355338731057, 24.890659603706283), + Offset(24.01876825740043, 24.89137581050446), + Offset(24.004045682792036, 24.891564195943896), + Offset(23.995525876462455, 24.89156214884712), + Offset(23.9926432343554, 24.891543022538777), + Offset(23.99263671875, 24.89154296875), + ], + <Offset>[ + Offset(24.01015625, 23.52890625), + Offset(24.010258478063488, 23.528888402424656), + Offset(24.091555200930664, 23.52418084688126), + Offset(24.377115816859927, 23.6152417705347), + Offset(24.633459690010874, 23.859538100350317), + Offset(24.736069637313253, 24.1352514457875), + Offset(24.72116824601048, 24.371795772576675), + Offset(24.648015807099657, 24.549452838288758), + Offset(24.55323690381452, 24.674789163937373), + Offset(24.455385525488182, 24.759322859315567), + Offset(24.363483168967523, 24.813428460885813), + Offset(24.28176718778124, 24.845878439805734), + Offset(24.21233699329442, 24.865919213504945), + Offset(24.154550207153598, 24.87807591728), + Offset(24.107302586424357, 24.885092784958154), + Offset(24.06957428023968, 24.88885460147735), + Offset(24.040355338731057, 24.890659603706283), + Offset(24.01876825740043, 24.89137581050446), + Offset(24.004045682792036, 24.891564195943896), + Offset(23.995525876462455, 24.89156214884712), + Offset(23.9926432343554, 24.891543022538777), + Offset(23.99263671875, 24.89154296875), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(24.01015625, 23.52890625), + Offset(24.010258478063488, 23.528888402424656), + Offset(24.091555200930664, 23.52418084688126), + Offset(24.377115816859927, 23.6152417705347), + Offset(24.633459690010874, 23.859538100350317), + Offset(24.736069637313253, 24.1352514457875), + Offset(24.72116824601048, 24.371795772576675), + Offset(24.648015807099657, 24.549452838288758), + Offset(24.55323690381452, 24.674789163937373), + Offset(24.455385525488182, 24.759322859315567), + Offset(24.363483168967523, 24.813428460885813), + Offset(24.28176718778124, 24.845878439805734), + Offset(24.21233699329442, 24.865919213504945), + Offset(24.154550207153598, 24.87807591728), + Offset(24.107302586424357, 24.885092784958154), + Offset(24.06957428023968, 24.88885460147735), + Offset(24.040355338731057, 24.890659603706283), + Offset(24.01876825740043, 24.89137581050446), + Offset(24.004045682792036, 24.891564195943896), + Offset(23.995525876462455, 24.89156214884712), + Offset(23.9926432343554, 24.891543022538777), + Offset(23.99263671875, 24.89154296875), + ], + <Offset>[ + Offset(24.01015625, 31.52890625), + Offset(24.008520295107978, 31.528783221552175), + Offset(22.755276185176193, 31.340935400111544), + Offset(19.124042893225194, 29.17159801873879), + Offset(17.752710993844843, 25.48544218841713), + Offset(18.281881353935944, 23.023285630233925), + Offset(19.165406264174642, 21.57564236815897), + Offset(20.021831636513937, 20.69789982109205), + Offset(20.773928982898013, 20.14498747599391), + Offset(21.41399688285607, 19.782852795393087), + Offset(21.95216275958156, 19.534831078596365), + Offset(22.40338879379873, 19.358466061551326), + Offset(22.7845344438811, 19.244408751014564), + Offset(23.10200517816752, 19.174379838248726), + Offset(23.36173256246378, 19.133212628055418), + Offset(23.569229747957515, 19.110476338589457), + Offset(23.729986892467963, 19.098969744298735), + Offset(23.84878813854078, 19.09386714218904), + Offset(23.929827729045, 19.092039069233813), + Offset(23.976730494660732, 19.091592602925097), + Offset(23.99260084659454, 19.09154302269367), + Offset(23.99263671875, 19.09154296875), + ], + <Offset>[ + Offset(24.01015625, 31.52890625), + Offset(24.008520295107978, 31.528783221552175), + Offset(22.755276185176193, 31.340935400111544), + Offset(19.124042893225194, 29.17159801873879), + Offset(17.752710993844843, 25.48544218841713), + Offset(18.281881353935944, 23.023285630233925), + Offset(19.165406264174642, 21.57564236815897), + Offset(20.021831636513937, 20.69789982109205), + Offset(20.773928982898013, 20.14498747599391), + Offset(21.41399688285607, 19.782852795393087), + Offset(21.95216275958156, 19.534831078596365), + Offset(22.40338879379873, 19.358466061551326), + Offset(22.7845344438811, 19.244408751014564), + Offset(23.10200517816752, 19.174379838248726), + Offset(23.36173256246378, 19.133212628055418), + Offset(23.569229747957515, 19.110476338589457), + Offset(23.729986892467963, 19.098969744298735), + Offset(23.84878813854078, 19.09386714218904), + Offset(23.929827729045, 19.092039069233813), + Offset(23.976730494660732, 19.091592602925097), + Offset(23.99260084659454, 19.09154302269367), + Offset(23.99263671875, 19.09154296875), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(24.01015625, 31.52890625), + Offset(24.008520295107978, 31.528783221552175), + Offset(22.755276185176193, 31.340935400111544), + Offset(19.124042893225194, 29.17159801873879), + Offset(17.752710993844843, 25.48544218841713), + Offset(18.281881353935944, 23.023285630233925), + Offset(19.165406264174642, 21.57564236815897), + Offset(20.021831636513937, 20.69789982109205), + Offset(20.773928982898013, 20.14498747599391), + Offset(21.41399688285607, 19.782852795393087), + Offset(21.95216275958156, 19.534831078596365), + Offset(22.40338879379873, 19.358466061551326), + Offset(22.7845344438811, 19.244408751014564), + Offset(23.10200517816752, 19.174379838248726), + Offset(23.36173256246378, 19.133212628055418), + Offset(23.569229747957515, 19.110476338589457), + Offset(23.729986892467963, 19.098969744298735), + Offset(23.84878813854078, 19.09386714218904), + Offset(23.929827729045, 19.092039069233813), + Offset(23.976730494660732, 19.091592602925097), + Offset(23.99260084659454, 19.09154302269367), + Offset(23.99263671875, 19.09154296875), + ], + <Offset>[ + Offset(32.01015625, 31.52890625), + Offset(32.0084151142355, 31.530521404507688), + Offset(30.572030738406475, 32.67721441586602), + Offset(24.68039914142929, 34.424670942373524), + Offset(19.378615081911654, 32.36619088458316), + Offset(17.16991553838237, 29.477473913611234), + Offset(16.369252859756937, 27.131404349994806), + Offset(16.17027861931723, 25.32408399167777), + Offset(16.244127294954552, 23.924295396910416), + Offset(16.437526818933584, 22.824241438025204), + Offset(16.673565377292114, 21.94615148798233), + Offset(16.915976415544325, 21.236844455533838), + Offset(17.16302398139072, 20.67221130042789), + Offset(17.39830909913625, 20.226924867234807), + Offset(17.609852405561046, 19.878782652015996), + Offset(17.79085148506962, 19.61082087087162), + Offset(17.938297033060415, 19.409338190561826), + Offset(18.05127947022536, 19.26384726104869), + Offset(18.13030260233492, 19.166257022980844), + Offset(18.17676094873871, 19.11038798472682), + Offset(18.192600846749432, 19.091585410454528), + Offset(18.19263671875, 19.09154296875), + ], + <Offset>[ + Offset(32.01015625, 31.52890625), + Offset(32.0084151142355, 31.530521404507688), + Offset(30.572030738406475, 32.67721441586602), + Offset(24.68039914142929, 34.424670942373524), + Offset(19.378615081911654, 32.36619088458316), + Offset(17.16991553838237, 29.477473913611234), + Offset(16.369252859756937, 27.131404349994806), + Offset(16.17027861931723, 25.32408399167777), + Offset(16.244127294954552, 23.924295396910416), + Offset(16.437526818933584, 22.824241438025204), + Offset(16.673565377292114, 21.94615148798233), + Offset(16.915976415544325, 21.236844455533838), + Offset(17.16302398139072, 20.67221130042789), + Offset(17.39830909913625, 20.226924867234807), + Offset(17.609852405561046, 19.878782652015996), + Offset(17.79085148506962, 19.61082087087162), + Offset(17.938297033060415, 19.409338190561826), + Offset(18.05127947022536, 19.26384726104869), + Offset(18.13030260233492, 19.166257022980844), + Offset(18.17676094873871, 19.11038798472682), + Offset(18.192600846749432, 19.091585410454528), + Offset(18.19263671875, 19.09154296875), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(32.01015625, 31.52890625), + Offset(32.0084151142355, 31.530521404507688), + Offset(30.572030738406475, 32.67721441586602), + Offset(24.68039914142929, 34.424670942373524), + Offset(19.378615081911654, 32.36619088458316), + Offset(17.16991553838237, 29.477473913611234), + Offset(16.369252859756937, 27.131404349994806), + Offset(16.17027861931723, 25.32408399167777), + Offset(16.244127294954552, 23.924295396910416), + Offset(16.437526818933584, 22.824241438025204), + Offset(16.673565377292114, 21.94615148798233), + Offset(16.915976415544325, 21.236844455533838), + Offset(17.16302398139072, 20.67221130042789), + Offset(17.39830909913625, 20.226924867234807), + Offset(17.609852405561046, 19.878782652015996), + Offset(17.79085148506962, 19.61082087087162), + Offset(17.938297033060415, 19.409338190561826), + Offset(18.05127947022536, 19.26384726104869), + Offset(18.13030260233492, 19.166257022980844), + Offset(18.17676094873871, 19.11038798472682), + Offset(18.192600846749432, 19.091585410454528), + Offset(18.19263671875, 19.09154296875), + ], + <Offset>[ + Offset(32.01015625, 23.52890625), + Offset(32.01015329719101, 23.53062658538017), + Offset(31.908309754160946, 24.86045986263573), + Offset(29.93347206506402, 28.868314694169428), + Offset(26.259363778077685, 30.74028679651635), + Offset(23.62410382175968, 30.58943972916481), + Offset(21.925014841592773, 29.92755775441251), + Offset(20.79646278990295, 29.175637008874478), + Offset(20.023435215871057, 28.454097084853878), + Offset(19.478915461565702, 27.800711501947685), + Offset(19.08488578667808, 27.224748870271775), + Offset(18.794354809526837, 26.724256833788246), + Offset(18.590826530804044, 26.293721762918267), + Offset(18.45085412812233, 25.930620946266075), + Offset(18.35542242952162, 25.63066280891873), + Offset(18.291196017351787, 25.38919913375952), + Offset(18.248665479323506, 25.201028049969374), + Offset(18.221259589085008, 25.06135592936411), + Offset(18.204520556081953, 24.965782149690927), + Offset(18.19555633054043, 24.91035753064884), + Offset(18.192643234510292, 24.891585410299637), + Offset(18.192636718750002, 24.891542968750002), + ], + <Offset>[ + Offset(32.01015625, 23.52890625), + Offset(32.01015329719101, 23.53062658538017), + Offset(31.908309754160946, 24.86045986263573), + Offset(29.93347206506402, 28.868314694169428), + Offset(26.259363778077685, 30.74028679651635), + Offset(23.62410382175968, 30.58943972916481), + Offset(21.925014841592773, 29.92755775441251), + Offset(20.79646278990295, 29.175637008874478), + Offset(20.023435215871057, 28.454097084853878), + Offset(19.478915461565702, 27.800711501947685), + Offset(19.08488578667808, 27.224748870271775), + Offset(18.794354809526837, 26.724256833788246), + Offset(18.590826530804044, 26.293721762918267), + Offset(18.45085412812233, 25.930620946266075), + Offset(18.35542242952162, 25.63066280891873), + Offset(18.291196017351787, 25.38919913375952), + Offset(18.248665479323506, 25.201028049969374), + Offset(18.221259589085008, 25.06135592936411), + Offset(18.204520556081953, 24.965782149690927), + Offset(18.19555633054043, 24.91035753064884), + Offset(18.192643234510292, 24.891585410299637), + Offset(18.192636718750002, 24.891542968750002), + ], + ), + _PathClose( + ), + _PathMoveTo( + <Offset>[ + Offset(30.4, 6.0), + Offset(30.403826772654973, 6.001600955318109), + Offset(33.26297392821128, 7.464112893661335), + Offset(40.3252246978808, 15.636425198410986), + Offset(41.008618677528034, 25.792861690388108), + Offset(37.989766327618334, 31.726851345525642), + Offset(34.66109919246733, 34.936041005423874), + Offset(31.70815663793754, 36.68371605880273), + Offset(29.216038057712375, 37.618746191043186), + Offset(27.14455430692518, 38.09258228629963), + Offset(25.430782781823723, 38.305428372486986), + Offset(24.014543572941673, 38.36973863661014), + Offset(22.850742435528595, 38.323714848128795), + Offset(21.905079756466474, 38.2162199326415), + Offset(21.146729034109512, 38.08362328363005), + Offset(20.550519051592694, 37.94957638018356), + Offset(20.09440860715983, 37.82880891010404), + Offset(19.760567137156492, 37.73014235182733), + Offset(19.53440820396981, 37.65826086700748), + Offset(19.40409629300435, 37.614964895879226), + Offset(19.360099392114897, 37.60003390984549), + Offset(19.360000000000003, 37.6), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(30.4, 6.0), + Offset(30.403826772654973, 6.001600955318109), + Offset(33.26297392821128, 7.464112893661335), + Offset(40.3252246978808, 15.636425198410986), + Offset(41.008618677528034, 25.792861690388108), + Offset(37.989766327618334, 31.726851345525642), + Offset(34.66109919246733, 34.936041005423874), + Offset(31.70815663793754, 36.68371605880273), + Offset(29.216038057712375, 37.618746191043186), + Offset(27.14455430692518, 38.09258228629963), + Offset(25.430782781823723, 38.305428372486986), + Offset(24.014543572941673, 38.36973863661014), + Offset(22.850742435528595, 38.323714848128795), + Offset(21.905079756466474, 38.2162199326415), + Offset(21.146729034109512, 38.08362328363005), + Offset(20.550519051592694, 37.94957638018356), + Offset(20.09440860715983, 37.82880891010404), + Offset(19.760567137156492, 37.73014235182733), + Offset(19.53440820396981, 37.65826086700748), + Offset(19.40409629300435, 37.614964895879226), + Offset(19.360099392114897, 37.60003390984549), + Offset(19.360000000000003, 37.6), + ], + <Offset>[ + Offset(30.4, 9.2), + Offset(30.40313149947277, 9.201558882969117), + Offset(32.7284623219095, 10.590814714953448), + Offset(38.22399552842691, 17.858967697692623), + Offset(38.25631919906162, 26.44322332561483), + Offset(35.40809101426741, 31.282065019304213), + Offset(32.438794399733, 33.81757964365679), + Offset(29.857682969703255, 35.14309485192405), + Offset(27.704314889345774, 35.8068255158658), + Offset(25.92799884987233, 36.101994260730635), + Offset(24.466254618069335, 36.19398941957121), + Offset(23.263192215348667, 36.174773685308374), + Offset(22.279621415763266, 36.07511066313264), + Offset(21.484061744872044, 35.93474150102899), + Offset(20.84850102452528, 35.782871220868955), + Offset(20.35038123867983, 35.6382250750284), + Offset(19.970261228654596, 35.512132966341014), + Offset(19.692575089612635, 35.41113888450116), + Offset(19.504721022470996, 35.338450816323444), + Offset(19.39657814028366, 35.29497707751041), + Offset(19.360082437010554, 35.28003390990745), + Offset(19.36, 35.28), + ], + <Offset>[ + Offset(30.4, 9.2), + Offset(30.40313149947277, 9.201558882969117), + Offset(32.7284623219095, 10.590814714953448), + Offset(38.22399552842691, 17.858967697692623), + Offset(38.25631919906162, 26.44322332561483), + Offset(35.40809101426741, 31.282065019304213), + Offset(32.438794399733, 33.81757964365679), + Offset(29.857682969703255, 35.14309485192405), + Offset(27.704314889345774, 35.8068255158658), + Offset(25.92799884987233, 36.101994260730635), + Offset(24.466254618069335, 36.19398941957121), + Offset(23.263192215348667, 36.174773685308374), + Offset(22.279621415763266, 36.07511066313264), + Offset(21.484061744872044, 35.93474150102899), + Offset(20.84850102452528, 35.782871220868955), + Offset(20.35038123867983, 35.6382250750284), + Offset(19.970261228654596, 35.512132966341014), + Offset(19.692575089612635, 35.41113888450116), + Offset(19.504721022470996, 35.338450816323444), + Offset(19.39657814028366, 35.29497707751041), + Offset(19.360082437010554, 35.28003390990745), + Offset(19.36, 35.28), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(30.4, 9.2), + Offset(30.40313149947277, 9.201558882969117), + Offset(32.7284623219095, 10.590814714953448), + Offset(38.22399552842691, 17.858967697692623), + Offset(38.25631919906162, 26.44322332561483), + Offset(35.40809101426741, 31.282065019304213), + Offset(32.438794399733, 33.81757964365679), + Offset(29.857682969703255, 35.14309485192405), + Offset(27.704314889345774, 35.8068255158658), + Offset(25.92799884987233, 36.101994260730635), + Offset(24.466254618069335, 36.19398941957121), + Offset(23.263192215348667, 36.174773685308374), + Offset(22.279621415763266, 36.07511066313264), + Offset(21.484061744872044, 35.93474150102899), + Offset(20.84850102452528, 35.782871220868955), + Offset(20.35038123867983, 35.6382250750284), + Offset(19.970261228654596, 35.512132966341014), + Offset(19.692575089612635, 35.41113888450116), + Offset(19.504721022470996, 35.338450816323444), + Offset(19.39657814028366, 35.29497707751041), + Offset(19.360082437010554, 35.28003390990745), + Offset(19.36, 35.28), + ], + <Offset>[ + Offset(17.6, 9.2), + Offset(17.60329978886874, 9.1987777902403), + Offset(20.22165503674104, 8.452768289746293), + Offset(29.333825531300356, 9.454051019877056), + Offset(35.65487265815472, 15.434025411749177), + Offset(37.18723631915313, 20.955363765900515), + Offset(36.912639846801326, 24.928360472719458), + Offset(36.02016779721799, 27.741200178986897), + Offset(34.95199759005531, 29.759932842399394), + Offset(33.8903509521483, 31.235772432519248), + Offset(32.91201042973245, 32.335876764553674), + Offset(32.04305202055572, 33.16936825493635), + Offset(31.274038155747874, 33.790626584071326), + Offset(30.609975471322077, 34.250669454651266), + Offset(30.051509275569657, 34.589959182532034), + Offset(29.595786459300463, 34.83767382337693), + Offset(29.236965003706672, 35.01554345232007), + Offset(28.96858895891731, 35.13917069432573), + Offset(28.78396122520713, 35.21970209032819), + Offset(28.6765294137589, 35.264904466627655), + Offset(28.640082436762725, 35.279966089490074), + Offset(28.64, 35.28), + ], + <Offset>[ + Offset(17.6, 9.2), + Offset(17.60329978886874, 9.1987777902403), + Offset(20.22165503674104, 8.452768289746293), + Offset(29.333825531300356, 9.454051019877056), + Offset(35.65487265815472, 15.434025411749177), + Offset(37.18723631915313, 20.955363765900515), + Offset(36.912639846801326, 24.928360472719458), + Offset(36.02016779721799, 27.741200178986897), + Offset(34.95199759005531, 29.759932842399394), + Offset(33.8903509521483, 31.235772432519248), + Offset(32.91201042973245, 32.335876764553674), + Offset(32.04305202055572, 33.16936825493635), + Offset(31.274038155747874, 33.790626584071326), + Offset(30.609975471322077, 34.250669454651266), + Offset(30.051509275569657, 34.589959182532034), + Offset(29.595786459300463, 34.83767382337693), + Offset(29.236965003706672, 35.01554345232007), + Offset(28.96858895891731, 35.13917069432573), + Offset(28.78396122520713, 35.21970209032819), + Offset(28.6765294137589, 35.264904466627655), + Offset(28.640082436762725, 35.279966089490074), + Offset(28.64, 35.28), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(17.6, 9.2), + Offset(17.60329978886874, 9.1987777902403), + Offset(20.22165503674104, 8.452768289746293), + Offset(29.333825531300356, 9.454051019877056), + Offset(35.65487265815472, 15.434025411749177), + Offset(37.18723631915313, 20.955363765900515), + Offset(36.912639846801326, 24.928360472719458), + Offset(36.02016779721799, 27.741200178986897), + Offset(34.95199759005531, 29.759932842399394), + Offset(33.8903509521483, 31.235772432519248), + Offset(32.91201042973245, 32.335876764553674), + Offset(32.04305202055572, 33.16936825493635), + Offset(31.274038155747874, 33.790626584071326), + Offset(30.609975471322077, 34.250669454651266), + Offset(30.051509275569657, 34.589959182532034), + Offset(29.595786459300463, 34.83767382337693), + Offset(29.236965003706672, 35.01554345232007), + Offset(28.96858895891731, 35.13917069432573), + Offset(28.78396122520713, 35.21970209032819), + Offset(28.6765294137589, 35.264904466627655), + Offset(28.640082436762725, 35.279966089490074), + Offset(28.64, 35.28), + ], + <Offset>[ + Offset(17.6, 6.0), + Offset(17.60399506205094, 5.99881986258929), + Offset(20.75616664304283, 5.326066468454183), + Offset(31.43505470075425, 7.231508520595419), + Offset(38.40717213662114, 14.783663776522452), + Offset(39.76891163250406, 21.400150092121944), + Offset(39.13494463953566, 26.04682183448654), + Offset(37.87064146545227, 29.28182138586558), + Offset(36.463720758421914, 31.571853517576777), + Offset(35.106906409201144, 33.22636045808824), + Offset(33.876538593486835, 34.44731571746945), + Offset(32.79440337814872, 35.364333206238115), + Offset(31.845159175513203, 36.03923076906747), + Offset(31.030993482916507, 36.53214788626377), + Offset(30.349737285153886, 36.890711245293126), + Offset(29.795924272213327, 37.14902512853209), + Offset(29.36111238221191, 37.33221939608309), + Offset(29.03658100646117, 37.4581741616519), + Offset(28.81364840670594, 37.539512141012224), + Offset(28.684047566479585, 37.58489228499647), + Offset(28.64009939186707, 37.59996608942812), + Offset(28.64, 37.6), + ], + <Offset>[ + Offset(17.6, 6.0), + Offset(17.60399506205094, 5.99881986258929), + Offset(20.75616664304283, 5.326066468454183), + Offset(31.43505470075425, 7.231508520595419), + Offset(38.40717213662114, 14.783663776522452), + Offset(39.76891163250406, 21.400150092121944), + Offset(39.13494463953566, 26.04682183448654), + Offset(37.87064146545227, 29.28182138586558), + Offset(36.463720758421914, 31.571853517576777), + Offset(35.106906409201144, 33.22636045808824), + Offset(33.876538593486835, 34.44731571746945), + Offset(32.79440337814872, 35.364333206238115), + Offset(31.845159175513203, 36.03923076906747), + Offset(31.030993482916507, 36.53214788626377), + Offset(30.349737285153886, 36.890711245293126), + Offset(29.795924272213327, 37.14902512853209), + Offset(29.36111238221191, 37.33221939608309), + Offset(29.03658100646117, 37.4581741616519), + Offset(28.81364840670594, 37.539512141012224), + Offset(28.684047566479585, 37.58489228499647), + Offset(28.64009939186707, 37.59996608942812), + Offset(28.64, 37.6), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(17.6, 6.0), + Offset(17.60399506205094, 5.99881986258929), + Offset(20.75616664304283, 5.326066468454183), + Offset(31.43505470075425, 7.231508520595419), + Offset(38.40717213662114, 14.783663776522452), + Offset(39.76891163250406, 21.400150092121944), + Offset(39.13494463953566, 26.04682183448654), + Offset(37.87064146545227, 29.28182138586558), + Offset(36.463720758421914, 31.571853517576777), + Offset(35.106906409201144, 33.22636045808824), + Offset(33.876538593486835, 34.44731571746945), + Offset(32.79440337814872, 35.364333206238115), + Offset(31.845159175513203, 36.03923076906747), + Offset(31.030993482916507, 36.53214788626377), + Offset(30.349737285153886, 36.890711245293126), + Offset(29.795924272213327, 37.14902512853209), + Offset(29.36111238221191, 37.33221939608309), + Offset(29.03658100646117, 37.4581741616519), + Offset(28.81364840670594, 37.539512141012224), + Offset(28.684047566479585, 37.58489228499647), + Offset(28.64009939186707, 37.59996608942812), + Offset(28.64, 37.6), + ], + <Offset>[ + Offset(14.399999999999999, 6.0), + Offset(14.404037134399934, 5.998124589407087), + Offset(17.629464821750716, 4.791554862152392), + Offset(29.212512201472613, 5.130279351141528), + Offset(37.75681050139441, 12.03136429805604), + Offset(40.21369795872548, 18.81847477877102), + Offset(40.25340600130274, 23.824517041752205), + Offset(39.411262672330956, 27.43134771763129), + Offset(38.2756414335993, 30.060130349210176), + Offset(37.09749443477014, 32.009805001035396), + Offset(35.98797754640261, 33.48278755371506), + Offset(34.989368329450485, 34.61298184864511), + Offset(34.09376336050936, 35.468109749302144), + Offset(33.31247191452901, 36.111129874669345), + Offset(32.650489347914984, 36.5924832357089), + Offset(32.10727557736848, 36.948887315619224), + Offset(31.67778832597493, 37.20807201757785), + Offset(31.35558447378734, 37.390182114108036), + Offset(31.133458457389974, 37.50982495951341), + Offset(31.004035384848397, 37.57737413227578), + Offset(30.960099391805116, 37.59994913432378), + Offset(30.96, 37.6), + ], + <Offset>[ + Offset(14.399999999999999, 6.0), + Offset(14.404037134399934, 5.998124589407087), + Offset(17.629464821750716, 4.791554862152392), + Offset(29.212512201472613, 5.130279351141528), + Offset(37.75681050139441, 12.03136429805604), + Offset(40.21369795872548, 18.81847477877102), + Offset(40.25340600130274, 23.824517041752205), + Offset(39.411262672330956, 27.43134771763129), + Offset(38.2756414335993, 30.060130349210176), + Offset(37.09749443477014, 32.009805001035396), + Offset(35.98797754640261, 33.48278755371506), + Offset(34.989368329450485, 34.61298184864511), + Offset(34.09376336050936, 35.468109749302144), + Offset(33.31247191452901, 36.111129874669345), + Offset(32.650489347914984, 36.5924832357089), + Offset(32.10727557736848, 36.948887315619224), + Offset(31.67778832597493, 37.20807201757785), + Offset(31.35558447378734, 37.390182114108036), + Offset(31.133458457389974, 37.50982495951341), + Offset(31.004035384848397, 37.57737413227578), + Offset(30.960099391805116, 37.59994913432378), + Offset(30.96, 37.6), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(14.399999999999999, 6.0), + Offset(14.404037134399934, 5.998124589407087), + Offset(17.629464821750716, 4.791554862152392), + Offset(29.212512201472613, 5.130279351141528), + Offset(37.75681050139441, 12.03136429805604), + Offset(40.21369795872548, 18.81847477877102), + Offset(40.25340600130274, 23.824517041752205), + Offset(39.411262672330956, 27.43134771763129), + Offset(38.2756414335993, 30.060130349210176), + Offset(37.09749443477014, 32.009805001035396), + Offset(35.98797754640261, 33.48278755371506), + Offset(34.989368329450485, 34.61298184864511), + Offset(34.09376336050936, 35.468109749302144), + Offset(33.31247191452901, 36.111129874669345), + Offset(32.650489347914984, 36.5924832357089), + Offset(32.10727557736848, 36.948887315619224), + Offset(31.67778832597493, 37.20807201757785), + Offset(31.35558447378734, 37.390182114108036), + Offset(31.133458457389974, 37.50982495951341), + Offset(31.004035384848397, 37.57737413227578), + Offset(30.960099391805116, 37.59994913432378), + Offset(30.96, 37.6), + ], + <Offset>[ + Offset(14.399999999999999, 9.2), + Offset(14.40334186121773, 9.198082517058094), + Offset(17.09495321544893, 7.918256683444506), + Offset(27.11128303201872, 7.3528218504231635), + Offset(35.004511022928, 12.681725933282765), + Offset(37.63202264537456, 18.37368845254959), + Offset(38.03110120856841, 22.706055679985123), + Offset(37.56078900409667, 25.890726510752607), + Offset(36.7639182652327, 28.248209674032793), + Offset(35.88093897771729, 30.019216975466403), + Offset(35.023449382648224, 31.371348600799287), + Offset(34.238016971857476, 32.41801689734335), + Offset(33.52264234074403, 33.21950556430599), + Offset(32.891453902934586, 33.82965144305683), + Offset(32.35226133833075, 34.2917311729478), + Offset(31.90713776445562, 34.63753601046407), + Offset(31.55364094746969, 34.89139607381483), + Offset(31.287592426243478, 35.07117864678187), + Offset(31.10377127589116, 35.19001490882938), + Offset(30.996517232127708, 35.25738631390697), + Offset(30.96008243670077, 35.27994913438573), + Offset(30.96, 35.28), + ], + <Offset>[ + Offset(14.399999999999999, 9.2), + Offset(14.40334186121773, 9.198082517058094), + Offset(17.09495321544893, 7.918256683444506), + Offset(27.11128303201872, 7.3528218504231635), + Offset(35.004511022928, 12.681725933282765), + Offset(37.63202264537456, 18.37368845254959), + Offset(38.03110120856841, 22.706055679985123), + Offset(37.56078900409667, 25.890726510752607), + Offset(36.7639182652327, 28.248209674032793), + Offset(35.88093897771729, 30.019216975466403), + Offset(35.023449382648224, 31.371348600799287), + Offset(34.238016971857476, 32.41801689734335), + Offset(33.52264234074403, 33.21950556430599), + Offset(32.891453902934586, 33.82965144305683), + Offset(32.35226133833075, 34.2917311729478), + Offset(31.90713776445562, 34.63753601046407), + Offset(31.55364094746969, 34.89139607381483), + Offset(31.287592426243478, 35.07117864678187), + Offset(31.10377127589116, 35.19001490882938), + Offset(30.996517232127708, 35.25738631390697), + Offset(30.96008243670077, 35.27994913438573), + Offset(30.96, 35.28), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(14.399999999999999, 9.2), + Offset(14.40334186121773, 9.198082517058094), + Offset(17.09495321544893, 7.918256683444506), + Offset(27.11128303201872, 7.3528218504231635), + Offset(35.004511022928, 12.681725933282765), + Offset(37.63202264537456, 18.37368845254959), + Offset(38.03110120856841, 22.706055679985123), + Offset(37.56078900409667, 25.890726510752607), + Offset(36.7639182652327, 28.248209674032793), + Offset(35.88093897771729, 30.019216975466403), + Offset(35.023449382648224, 31.371348600799287), + Offset(34.238016971857476, 32.41801689734335), + Offset(33.52264234074403, 33.21950556430599), + Offset(32.891453902934586, 33.82965144305683), + Offset(32.35226133833075, 34.2917311729478), + Offset(31.90713776445562, 34.63753601046407), + Offset(31.55364094746969, 34.89139607381483), + Offset(31.287592426243478, 35.07117864678187), + Offset(31.10377127589116, 35.19001490882938), + Offset(30.996517232127708, 35.25738631390697), + Offset(30.96008243670077, 35.27994913438573), + Offset(30.96, 35.28), + ], + <Offset>[ + Offset(12.799999999999999, 9.2), + Offset(12.803362897392224, 9.197734880466992), + Offset(15.531602304802872, 7.651000880293612), + Offset(26.0000117823779, 6.302207265696218), + Offset(34.67933020531464, 11.305576194049557), + Offset(37.85441580848527, 17.08285079587413), + Offset(38.590331889451946, 21.594903283617956), + Offset(38.33109960753601, 24.965489676635464), + Offset(37.669878602821385, 27.49234808984949), + Offset(36.87623299050179, 29.41093924693998), + Offset(36.07916885910612, 30.889084518922097), + Offset(35.33549944750836, 32.042341218546845), + Offset(34.646944433242105, 32.93394505442333), + Offset(34.032193118740835, 33.61914243725962), + Offset(33.502637369711294, 34.14261716815569), + Offset(33.0628134170332, 34.53746710400763), + Offset(32.7119789193512, 34.82932238456221), + Offset(32.44709415990656, 35.03718262300993), + Offset(32.263676301233176, 35.175171318079975), + Offset(32.15651114131211, 35.253627237546624), + Offset(32.12008243666979, 35.27994065683356), + Offset(32.120000000000005, 35.28), + ], + <Offset>[ + Offset(12.799999999999999, 9.2), + Offset(12.803362897392224, 9.197734880466992), + Offset(15.531602304802872, 7.651000880293612), + Offset(26.0000117823779, 6.302207265696218), + Offset(34.67933020531464, 11.305576194049557), + Offset(37.85441580848527, 17.08285079587413), + Offset(38.590331889451946, 21.594903283617956), + Offset(38.33109960753601, 24.965489676635464), + Offset(37.669878602821385, 27.49234808984949), + Offset(36.87623299050179, 29.41093924693998), + Offset(36.07916885910612, 30.889084518922097), + Offset(35.33549944750836, 32.042341218546845), + Offset(34.646944433242105, 32.93394505442333), + Offset(34.032193118740835, 33.61914243725962), + Offset(33.502637369711294, 34.14261716815569), + Offset(33.0628134170332, 34.53746710400763), + Offset(32.7119789193512, 34.82932238456221), + Offset(32.44709415990656, 35.03718262300993), + Offset(32.263676301233176, 35.175171318079975), + Offset(32.15651114131211, 35.253627237546624), + Offset(32.12008243666979, 35.27994065683356), + Offset(32.120000000000005, 35.28), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(11.031994628903998, 9.2), + Offset(11.035380771339659, 9.197350740866831), + Offset(13.80409430047159, 7.355682320651514), + Offset(24.772053321059442, 5.141274622728069), + Offset(34.320004310241, 9.784926112551638), + Offset(38.10016100028201, 15.656470851989635), + Offset(39.20828366912931, 20.36707615556587), + Offset(39.18229541021911, 23.94309986897611), + Offset(38.670967817106856, 26.657118501948734), + Offset(37.976036215765966, 28.738790314969485), + Offset(37.24574242457374, 30.35618108951862), + Offset(36.54822126727992, 31.627218332357877), + Offset(35.88930201966152, 32.61839973239491), + Offset(35.29271378159415, 33.38652927918864), + Offset(34.773806746124365, 33.97784569229438), + Offset(34.33983889265947, 34.42689062644846), + Offset(33.99194626674555, 34.76073074956073), + Offset(33.72834746797622, 34.99961690261951), + Offset(33.545375247961886, 35.15876910047291), + Offset(33.438308304985036, 35.24947344554947), + Offset(33.40188633068016, 35.27993128910995), + Offset(33.401803894044605, 35.28), + ], + <Offset>[ + Offset(9.616003417967999, 10.631994628904), + Offset(9.61909704372049, 10.629018885991774), + Offset(12.181344285634644, 8.518356219904028), + Offset(22.84828784303791, 5.2060705244071706), + Offset(32.80057167595657, 8.858076892900925), + Offset(37.14168235852622, 14.315045482191389), + Offset(38.70872208508259, 18.883202806434653), + Offset(39.03593220224475, 22.434844949065443), + Offset(38.79624415881739, 25.177353691127), + Offset(38.31245942468365, 27.309683066288713), + Offset(37.74842362764679, 28.984514638765333), + Offset(37.18325875817459, 30.31250428874126), + Offset(36.6287274978085, 31.35943365120302), + Offset(36.11385686779049, 32.17927219665962), + Offset(35.65842668096787, 32.816297930813164), + Offset(35.27304416151989, 33.30400436440065), + Offset(34.96151326541533, 33.66908727918451), + Offset(34.72407380578028, 33.931780449070615), + Offset(34.55859985994813, 34.10752150024265), + Offset(34.46153218185176, 34.2079560289239), + Offset(34.42847237120061, 34.241727680595176), + Offset(34.4283975219732, 34.241803894044594), + ], + <Offset>[ + Offset(9.616003417967999, 12.399999999999999), + Offset(9.61871290412033, 12.397001012044338), + Offset(11.886025725992546, 10.245864224235309), + Offset(21.68735520006976, 6.434028985725625), + Offset(31.279921594458653, 9.217402787974557), + Offset(35.71530241464173, 14.069300290394656), + Offset(37.4808949570305, 18.265251026757294), + Offset(38.01354239458539, 21.58364914638235), + Offset(37.96101457091663, 24.176264476841528), + Offset(37.64031049271316, 26.209879841024538), + Offset(37.21552019824331, 27.817941073297703), + Offset(36.76813587198562, 29.0997824689697), + Offset(36.313182175780085, 30.117076064783603), + Offset(35.88124370971952, 30.918751533806304), + Offset(35.49365520510656, 31.545128554400094), + Offset(35.16246768396071, 32.02697888877437), + Offset(34.892921630413845, 32.38911993179016), + Offset(34.68650808538985, 32.65052714100095), + Offset(34.542197642341065, 32.825822553513945), + Offset(34.4573783898546, 32.92615886525098), + Offset(34.428463003477, 32.9599237865848), + Offset(34.428397521973196, 32.96), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(9.616003417967999, 12.399999999999999), + Offset(9.61871290412033, 12.397001012044338), + Offset(11.886025725992546, 10.245864224235309), + Offset(21.68735520006976, 6.434028985725625), + Offset(31.279921594458653, 9.217402787974557), + Offset(35.71530241464173, 14.069300290394656), + Offset(37.4808949570305, 18.265251026757294), + Offset(38.01354239458539, 21.58364914638235), + Offset(37.96101457091663, 24.176264476841528), + Offset(37.64031049271316, 26.209879841024538), + Offset(37.21552019824331, 27.817941073297703), + Offset(36.76813587198562, 29.0997824689697), + Offset(36.313182175780085, 30.117076064783603), + Offset(35.88124370971952, 30.918751533806304), + Offset(35.49365520510656, 31.545128554400094), + Offset(35.16246768396071, 32.02697888877437), + Offset(34.892921630413845, 32.38911993179016), + Offset(34.68650808538985, 32.65052714100095), + Offset(34.542197642341065, 32.825822553513945), + Offset(34.4573783898546, 32.92615886525098), + Offset(34.428463003477, 32.9599237865848), + Offset(34.428397521973196, 32.96), + ], + <Offset>[ + Offset(9.59999999999928, 34.8), + Offset(9.59784278428286, 34.79670302849285), + Offset(8.12880763309575, 32.13010384432861), + Offset(6.967635927464624, 21.981318090494952), + Offset(12.01057274235646, 13.75616979739632), + Offset(17.64579962789941, 10.942884872751186), + Offset(21.93035490934461, 10.42490759674647), + Offset(25.067931468540735, 10.790046353371297), + Offset(27.388013931066364, 11.485259520063472), + Offset(29.134377359648454, 12.26967958533492), + Offset(30.47438250198729, 13.033044731841269), + Offset(31.519653538066578, 13.731270250539573), + Offset(32.32658046011612, 14.373990554688655), + Offset(32.945527457598416, 14.946296972765026), + Offset(33.41756535579906, 15.438372656482638), + Offset(33.77306221888595, 15.846518849853458), + Offset(34.035475835072845, 16.171767455952793), + Offset(34.22216124688238, 16.41716283685671), + Offset(34.34598889992722, 16.58700373110889), + Offset(34.416353737915934, 16.68620653787546), + Offset(34.43994679577361, 16.719923702224868), + Offset(34.440000000000516, 16.72), + ], + <Offset>[ + Offset(9.59999999999928, 34.8), + Offset(9.59784278428286, 34.79670302849285), + Offset(8.12880763309575, 32.13010384432861), + Offset(6.967635927464624, 21.981318090494952), + Offset(12.01057274235646, 13.75616979739632), + Offset(17.64579962789941, 10.942884872751186), + Offset(21.93035490934461, 10.42490759674647), + Offset(25.067931468540735, 10.790046353371297), + Offset(27.388013931066364, 11.485259520063472), + Offset(29.134377359648454, 12.26967958533492), + Offset(30.47438250198729, 13.033044731841269), + Offset(31.519653538066578, 13.731270250539573), + Offset(32.32658046011612, 14.373990554688655), + Offset(32.945527457598416, 14.946296972765026), + Offset(33.41756535579906, 15.438372656482638), + Offset(33.77306221888595, 15.846518849853458), + Offset(34.035475835072845, 16.171767455952793), + Offset(34.22216124688238, 16.41716283685671), + Offset(34.34598889992722, 16.58700373110889), + Offset(34.416353737915934, 16.68620653787546), + Offset(34.43994679577361, 16.719923702224868), + Offset(34.440000000000516, 16.72), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(9.59999999999928, 36.568005371096), + Offset(9.5974586446827, 36.564685154545415), + Offset(7.833489073453652, 33.857611848659886), + Offset(5.8067032844964785, 23.20927655181341), + Offset(10.489922660858541, 14.115495692469953), + Offset(16.219419684014916, 10.697139680954454), + Offset(20.70252778129252, 9.806955817069111), + Offset(24.045541660881376, 9.938850550688198), + Offset(26.55278434316561, 10.484170305778001), + Offset(28.46222842767796, 11.169876360070745), + Offset(29.941479072583817, 11.866471166373643), + Offset(31.10453065187761, 12.518548430768014), + Offset(32.011035138087706, 13.131632968269235), + Offset(32.71291429952744, 13.685776309911715), + Offset(33.252793879937755, 14.16720328006957), + Offset(33.662485741326776, 14.569493374227186), + Offset(33.96688420007136, 14.891800108558444), + Offset(34.184595526491954, 15.135909528787048), + Offset(34.32958668232016, 15.305304784380185), + Offset(34.41219994591878, 15.404409374202539), + Offset(34.43993742805, 15.438119808214498), + Offset(34.440000000000516, 15.438196105955399), + ], + <Offset>[ + Offset(11.031994628903279, 38.0), + Offset(11.029123312699099, 37.9969720897259), + Offset(8.99348984375479, 35.49599871228041), + Offset(5.860990795973912, 25.144157116262335), + Offset(9.549309004043138, 15.638180829591539), + Offset(14.86508318012379, 11.653393915996185), + Offset(19.207540534520554, 10.300923899661631), + Offset(22.52803239611086, 10.077509007067547), + Offset(25.06545930180785, 10.349832425351934), + Offset(27.02703710229079, 10.82349808484828), + Offset(28.564988950784752, 11.353230513276403), + Offset(29.786059048943372, 11.872533770641846), + Offset(30.74921284177406, 12.380962067429417), + Offset(31.503551677244786, 12.853223394675975), + Offset(32.089754659866806, 13.271077127444466), + Offset(32.538598576444194, 13.624728880051993), + Offset(32.87461986019893, 13.910647255693526), + Offset(33.11641904008201, 14.128585696683976), + Offset(33.27819061447309, 14.280478644316606), + Offset(33.37064493049935, 14.369583080230184), + Offset(33.40173373474159, 14.399931289667558), + Offset(33.401803894045116, 14.399999999999999), + ], + <Offset>[ + Offset(12.79999999999928, 38.0), + Offset(12.797105438751665, 37.997356229326066), + Offset(10.720997848086075, 35.79131727192251), + Offset(7.08894925729237, 26.305089759230484), + Offset(9.90863489911677, 17.15883091108946), + Offset(14.619337988327057, 13.07977385988068), + Offset(18.589588754843195, 11.528751027713723), + Offset(21.676836593427762, 11.099898814726902), + Offset(24.064370087522377, 11.18506201325269), + Offset(25.927233877026616, 11.495647016818776), + Offset(27.398415385317126, 11.886133942679876), + Offset(28.573337229171813, 12.287656656830816), + Offset(29.50685525535464, 12.696507389457834), + Offset(30.243031014391473, 13.085836552746947), + Offset(30.818585283453736, 13.435848603305775), + Offset(31.26157310081792, 13.735305357611166), + Offset(31.594652512804586, 13.97923889069501), + Offset(31.83516573201235, 14.166151417074401), + Offset(31.99649166774438, 14.29688086192367), + Offset(32.08884776682643, 14.37373687222734), + Offset(32.119929840731224, 14.399940657391166), + Offset(32.120000000000516, 14.399999999999999), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.79999999999928, 38.0), + Offset(12.797105438751665, 37.997356229326066), + Offset(10.720997848086075, 35.79131727192251), + Offset(7.08894925729237, 26.305089759230484), + Offset(9.90863489911677, 17.15883091108946), + Offset(14.619337988327057, 13.07977385988068), + Offset(18.589588754843195, 11.528751027713723), + Offset(21.676836593427762, 11.099898814726902), + Offset(24.064370087522377, 11.18506201325269), + Offset(25.927233877026616, 11.495647016818776), + Offset(27.398415385317126, 11.886133942679876), + Offset(28.573337229171813, 12.287656656830816), + Offset(29.50685525535464, 12.696507389457834), + Offset(30.243031014391473, 13.085836552746947), + Offset(30.818585283453736, 13.435848603305775), + Offset(31.26157310081792, 13.735305357611166), + Offset(31.594652512804586, 13.97923889069501), + Offset(31.83516573201235, 14.166151417074401), + Offset(31.99649166774438, 14.29688086192367), + Offset(32.08884776682643, 14.37373687222734), + Offset(32.119929840731224, 14.399940657391166), + Offset(32.120000000000516, 14.399999999999999), + ], + <Offset>[ + Offset(35.19999999999928, 38.0), + Offset(35.19681093230872, 38.0022231416015), + Offset(32.60791059713087, 39.532898516035026), + Offset(22.646746752263834, 41.013693945407724), + Offset(14.461166345703841, 36.42492726035435), + Offset(11.505833704777048, 31.15150105333715), + Offset(10.760359222473623, 27.08488457685406), + Offset(10.892488145276982, 24.053214492366923), + Offset(11.380925361280685, 21.767124191818905), + Offset(11.99311769804367, 20.0115352161887), + Offset(12.618342714906678, 18.63783108896057), + Offset(13.208582570059477, 17.547116159981847), + Offset(13.766625960381576, 16.694354527815143), + Offset(14.272681993103916, 16.032962633907964), + Offset(14.713320844126082, 15.523444670395389), + Offset(15.082113964731814, 15.13627004800123), + Offset(15.377920906463453, 14.84827054023167), + Offset(15.602141460729166, 14.642095749881417), + Offset(15.75782131295615, 14.504691132415362), + Offset(15.84893303824477, 14.426363941272161), + Offset(15.879929841164916, 14.400059343121573), + Offset(15.88000000000052, 14.400000000000002), + ], + <Offset>[ + Offset(35.19999999999928, 38.0), + Offset(35.19681093230872, 38.0022231416015), + Offset(32.60791059713087, 39.532898516035026), + Offset(22.646746752263834, 41.013693945407724), + Offset(14.461166345703841, 36.42492726035435), + Offset(11.505833704777048, 31.15150105333715), + Offset(10.760359222473623, 27.08488457685406), + Offset(10.892488145276982, 24.053214492366923), + Offset(11.380925361280685, 21.767124191818905), + Offset(11.99311769804367, 20.0115352161887), + Offset(12.618342714906678, 18.63783108896057), + Offset(13.208582570059477, 17.547116159981847), + Offset(13.766625960381576, 16.694354527815143), + Offset(14.272681993103916, 16.032962633907964), + Offset(14.713320844126082, 15.523444670395389), + Offset(15.082113964731814, 15.13627004800123), + Offset(15.377920906463453, 14.84827054023167), + Offset(15.602141460729166, 14.642095749881417), + Offset(15.75782131295615, 14.504691132415362), + Offset(15.84893303824477, 14.426363941272161), + Offset(15.879929841164916, 14.400059343121573), + Offset(15.88000000000052, 14.400000000000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(36.96800537109528, 38.0), + Offset(36.96479305836129, 38.00260728120166), + Offset(34.33541860146215, 39.828217075677124), + Offset(23.874705213582292, 42.17462658837587), + Offset(14.820492240777476, 37.94557734185227), + Offset(11.260088512980314, 32.57788099722164), + Offset(10.142407442796266, 28.31271170490615), + Offset(10.041292342593884, 25.075604300026278), + Offset(10.379836146995213, 22.60235377971966), + Offset(10.893314472779496, 20.683684148159198), + Offset(11.45176914943905, 19.170734518364043), + Offset(11.99586075028792, 17.962239046170815), + Offset(12.524268373962157, 17.009899849843556), + Offset(13.012161330250605, 16.26557579197894), + Offset(13.442151467713014, 15.688216146256698), + Offset(13.805088489105541, 15.246846525560404), + Offset(14.097953559069104, 14.916862175233152), + Offset(14.320888152659505, 14.679661470271842), + Offset(14.476122366227445, 14.521093350022426), + Offset(14.567135874571848, 14.430517733269317), + Offset(14.598125947154546, 14.400068710845181), + Offset(14.59819610595592, 14.400000000000002), + ], + <Offset>[ + Offset(38.39999999999928, 36.568005371096), + Offset(38.39707999354177, 36.57094261318526), + Offset(35.97380546508267, 38.668216305375985), + Offset(25.809585778031217, 42.120339076898446), + Offset(16.34317737789906, 38.88619099866767), + Offset(12.216342748022047, 33.93221750111277), + Offset(10.636375525388786, 29.80769895167812), + Offset(10.17995079897323, 26.593113564796795), + Offset(10.245498266569147, 24.08967882107742), + Offset(10.54693619755703, 22.118875473546364), + Offset(10.938528496341814, 20.547224640163105), + Offset(11.34984609016175, 19.280710649105057), + Offset(11.773597473122338, 18.271722146157202), + Offset(12.179608415014865, 17.474938414261594), + Offset(12.546025315087908, 16.851255366327646), + Offset(12.860323994930349, 16.370733690442982), + Offset(13.116800706204186, 16.009126515105578), + Offset(13.313564320556432, 15.747837956681783), + Offset(13.451296226163867, 15.572489417869503), + Offset(13.532309580599492, 15.472072748688737), + Offset(13.559937428607608, 15.43827240415359), + Offset(13.560000000000521, 15.438196105955402), + ], + <Offset>[ + Offset(38.39999999999928, 34.8), + Offset(38.39746413314193, 34.802960487132694), + Offset(36.26912402472477, 36.9407083010447), + Offset(26.970518420999362, 40.89238061557998), + Offset(17.86382745939698, 38.52686510359404), + Offset(13.642722691906542, 34.1779626929095), + Offset(11.864202653440877, 30.425650731355475), + Offset(11.202340606632587, 27.444309367479892), + Offset(11.080727854469902, 25.090768035362892), + Offset(11.219085129527524, 23.218678698810542), + Offset(11.471431925745287, 21.713798205630734), + Offset(11.764968976350719, 20.493432468876616), + Offset(12.089142795150753, 19.514079732576622), + Offset(12.412221573085839, 18.735459077114903), + Offset(12.710796790949217, 18.122424742740712), + Offset(12.970900472489523, 17.647759166069257), + Offset(13.18539234120567, 17.289093862499925), + Offset(13.351130040946858, 17.029091264751443), + Offset(13.46769844377093, 16.85418836459821), + Offset(13.536463372596648, 16.753869912361658), + Offset(13.559946796331216, 16.72007629816396), + Offset(13.560000000000521, 16.720000000000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.39999999999928, 34.8), + Offset(38.39746413314193, 34.802960487132694), + Offset(36.26912402472477, 36.9407083010447), + Offset(26.970518420999362, 40.89238061557998), + Offset(17.86382745939698, 38.52686510359404), + Offset(13.642722691906542, 34.1779626929095), + Offset(11.864202653440877, 30.425650731355475), + Offset(11.202340606632587, 27.444309367479892), + Offset(11.080727854469902, 25.090768035362892), + Offset(11.219085129527524, 23.218678698810542), + Offset(11.471431925745287, 21.713798205630734), + Offset(11.764968976350719, 20.493432468876616), + Offset(12.089142795150753, 19.514079732576622), + Offset(12.412221573085839, 18.735459077114903), + Offset(12.710796790949217, 18.122424742740712), + Offset(12.970900472489523, 17.647759166069257), + Offset(13.18539234120567, 17.289093862499925), + Offset(13.351130040946858, 17.029091264751443), + Offset(13.46769844377093, 16.85418836459821), + Offset(13.536463372596648, 16.753869912361658), + Offset(13.559946796331216, 16.72007629816396), + Offset(13.560000000000521, 16.720000000000002), + ], + <Offset>[ + Offset(38.39999999999928, 12.399999999999999), + Offset(38.40233104541737, 12.403254993575636), + Offset(40.010705268837285, 15.05379555199991), + Offset(41.67912260717661, 25.33458312060852), + Offset(37.12992380866187, 33.974333657006966), + Offset(31.71444988536301, 37.29146697645951), + Offset(27.420336202581215, 38.25488026372505), + Offset(24.155656284272606, 38.22865781563067), + Offset(21.662790033036117, 37.77421276160458), + Offset(19.734973328897453, 37.15279487779348), + Offset(18.223129072025984, 36.49387087604118), + Offset(17.02442847950175, 35.858187127988955), + Offset(16.086989933508065, 35.25430902754969), + Offset(15.359347654246855, 34.705808098402464), + Offset(14.798392858038833, 34.227689182068374), + Offset(14.371865162879587, 33.82721830215536), + Offset(14.05442399074233, 33.50582546884106), + Offset(13.827074373753874, 33.26211553603463), + Offset(13.675508714262623, 33.09285871938644), + Offset(13.589090441641469, 32.993784640943325), + Offset(13.56006548206162, 32.96007629773027), + Offset(13.560000000000523, 32.96), + ], + <Offset>[ + Offset(38.39999999999928, 12.399999999999999), + Offset(38.40233104541737, 12.403254993575636), + Offset(40.010705268837285, 15.05379555199991), + Offset(41.67912260717661, 25.33458312060852), + Offset(37.12992380866187, 33.974333657006966), + Offset(31.71444988536301, 37.29146697645951), + Offset(27.420336202581215, 38.25488026372505), + Offset(24.155656284272606, 38.22865781563067), + Offset(21.662790033036117, 37.77421276160458), + Offset(19.734973328897453, 37.15279487779348), + Offset(18.223129072025984, 36.49387087604118), + Offset(17.02442847950175, 35.858187127988955), + Offset(16.086989933508065, 35.25430902754969), + Offset(15.359347654246855, 34.705808098402464), + Offset(14.798392858038833, 34.227689182068374), + Offset(14.371865162879587, 33.82721830215536), + Offset(14.05442399074233, 33.50582546884106), + Offset(13.827074373753874, 33.26211553603463), + Offset(13.675508714262623, 33.09285871938644), + Offset(13.589090441641469, 32.993784640943325), + Offset(13.56006548206162, 32.96007629773027), + Offset(13.560000000000523, 32.96), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.39999999999928, 10.631994628904), + Offset(38.40271518501753, 10.635272867523073), + Offset(40.30602382847938, 13.32628754766863), + Offset(42.84005525014476, 24.106624659290063), + Offset(38.65057389015979, 33.61500776193334), + Offset(33.14082982924751, 37.53721216825625), + Offset(28.648163330633302, 38.872832043402404), + Offset(25.17804609193196, 39.07985361831377), + Offset(22.498019620936873, 38.77530197589005), + Offset(20.407122260867947, 38.252598103057665), + Offset(18.756032501429452, 37.66044444150881), + Offset(17.439551365690722, 37.07090894776051), + Offset(16.402535255536478, 36.496666613969104), + Offset(15.591960812317827, 35.966328761255774), + Offset(14.96316433390014, 35.49885855848144), + Offset(14.48244164043876, 35.10424377778163), + Offset(14.123015625743813, 34.78579281623541), + Offset(13.864640094144299, 34.543368844104286), + Offset(13.691910931869685, 34.374557666115145), + Offset(13.593244233638625, 34.275581804616245), + Offset(13.560074849785229, 34.241880191740634), + Offset(13.560000000000525, 34.2418038940446), + ], + <Offset>[ + Offset(36.96800537109528, 9.2), + Offset(36.97105051700113, 9.202985932342585), + Offset(39.146023058178244, 11.687900684048108), + Offset(42.78576773866732, 22.171744094841138), + Offset(39.5911875469752, 32.09232262481175), + Offset(34.49516633313863, 36.58095793321451), + Offset(30.143150577405272, 38.37886396080988), + Offset(26.695555356702478, 38.941195161934424), + Offset(23.985344662294633, 38.90963985631612), + Offset(21.842313586255116, 38.59897637828013), + Offset(20.132522623228514, 38.17368509460604), + Offset(18.75802296862496, 37.71692360788668), + Offset(17.664357551850124, 37.247337514808926), + Offset(16.801323434600484, 36.79888167649151), + Offset(16.126203553971088, 36.394984711106545), + Offset(15.606328805321338, 36.04900827195683), + Offset(15.215279965616238, 35.76694566910032), + Offset(14.93281658055424, 35.55069267620736), + Offset(14.743306999716763, 35.39938380617872), + Offset(14.634799249058046, 35.3104080985886), + Offset(14.598278543093638, 35.28006871028757), + Offset(14.598196105955923, 35.28), + ], + <Offset>[ + Offset(35.19999999999928, 9.2), + Offset(35.20306839094856, 9.202601792742424), + Offset(37.41851505384696, 11.39258212440601), + Offset(41.557809277348866, 21.01081145187299), + Offset(39.23186165190157, 30.57167254331383), + Offset(34.74091152493536, 35.15457798933002), + Offset(30.761102357082628, 37.151036832757796), + Offset(27.54675115938558, 37.918805354275065), + Offset(24.986433876580104, 38.07441026841536), + Offset(22.94211681151929, 37.92682744630963), + Offset(21.299096188696144, 37.640781665202574), + Offset(19.970744788396516, 37.30180072169771), + Offset(18.906715138269544, 36.931792192780506), + Offset(18.061844097453793, 36.56626851842054), + Offset(17.397372930384158, 36.23021323524523), + Offset(16.88335428094761, 35.93843179439765), + Offset(16.495247313010587, 35.69835403409884), + Offset(16.214069888623904, 35.51312695581694), + Offset(16.025005946445468, 35.38298158857166), + Offset(15.916596412730968, 35.30625430659144), + Offset(15.880082437104008, 35.280059342563966), + Offset(15.880000000000523, 35.28), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.19999999999928, 9.2), + Offset(35.20306839094856, 9.202601792742424), + Offset(37.41851505384696, 11.39258212440601), + Offset(41.557809277348866, 21.01081145187299), + Offset(39.23186165190157, 30.57167254331383), + Offset(34.74091152493536, 35.15457798933002), + Offset(30.761102357082628, 37.151036832757796), + Offset(27.54675115938558, 37.918805354275065), + Offset(24.986433876580104, 38.07441026841536), + Offset(22.94211681151929, 37.92682744630963), + Offset(21.299096188696144, 37.640781665202574), + Offset(19.970744788396516, 37.30180072169771), + Offset(18.906715138269544, 36.931792192780506), + Offset(18.061844097453793, 36.56626851842054), + Offset(17.397372930384158, 36.23021323524523), + Offset(16.88335428094761, 35.93843179439765), + Offset(16.495247313010587, 35.69835403409884), + Offset(16.214069888623904, 35.51312695581694), + Offset(16.025005946445468, 35.38298158857166), + Offset(15.916596412730968, 35.30625430659144), + Offset(15.880082437104008, 35.280059342563966), + Offset(15.880000000000523, 35.28), + ], + <Offset>[ + Offset(33.599999999999284, 9.2), + Offset(33.60308942712306, 9.202254156151323), + Offset(35.85516414320091, 11.125326321255116), + Offset(40.446538027708044, 19.960196867146045), + Offset(38.9066808342882, 29.195522804080625), + Offset(34.96330468804608, 33.86374033265456), + Offset(31.320333037966172, 36.03988443639063), + Offset(28.31706176282492, 36.99356852015792), + Offset(25.892394214168796, 37.31854868423206), + Offset(23.93741082430379, 37.31854971778321), + Offset(22.35481566515403, 37.15851758332538), + Offset(21.068227264047398, 36.926125042901205), + Offset(20.03101723076762, 36.64623168289785), + Offset(19.20258331326005, 36.35575951262332), + Offset(18.547748961764704, 36.08109923045312), + Offset(18.039029933525192, 35.83836288794122), + Offset(17.653585284892095, 35.63628034484623), + Offset(17.37357162228699, 35.47913093204501), + Offset(17.184910971787485, 35.36813799782225), + Offset(17.076590321915372, 35.3024952302311), + Offset(17.040082437073032, 35.280050865011795), + Offset(17.04000000000052, 35.28), + ], + <Offset>[ + Offset(33.599999999999284, 9.2), + Offset(33.60308942712306, 9.202254156151323), + Offset(35.85516414320091, 11.125326321255116), + Offset(40.446538027708044, 19.960196867146045), + Offset(38.9066808342882, 29.195522804080625), + Offset(34.96330468804608, 33.86374033265456), + Offset(31.320333037966172, 36.03988443639063), + Offset(28.31706176282492, 36.99356852015792), + Offset(25.892394214168796, 37.31854868423206), + Offset(23.93741082430379, 37.31854971778321), + Offset(22.35481566515403, 37.15851758332538), + Offset(21.068227264047398, 36.926125042901205), + Offset(20.03101723076762, 36.64623168289785), + Offset(19.20258331326005, 36.35575951262332), + Offset(18.547748961764704, 36.08109923045312), + Offset(18.039029933525192, 35.83836288794122), + Offset(17.653585284892095, 35.63628034484623), + Offset(17.37357162228699, 35.47913093204501), + Offset(17.184910971787485, 35.36813799782225), + Offset(17.076590321915372, 35.3024952302311), + Offset(17.040082437073032, 35.280050865011795), + Offset(17.04000000000052, 35.28), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(33.599999999999284, 9.2), + Offset(33.60308942712306, 9.202254156151323), + Offset(35.85516414320091, 11.125326321255116), + Offset(40.446538027708044, 19.960196867146045), + Offset(38.9066808342882, 29.195522804080625), + Offset(34.96330468804608, 33.86374033265456), + Offset(31.320333037966172, 36.03988443639063), + Offset(28.31706176282492, 36.99356852015792), + Offset(25.892394214168796, 37.31854868423206), + Offset(23.93741082430379, 37.31854971778321), + Offset(22.35481566515403, 37.15851758332538), + Offset(21.068227264047398, 36.926125042901205), + Offset(20.03101723076762, 36.64623168289785), + Offset(19.20258331326005, 36.35575951262332), + Offset(18.547748961764704, 36.08109923045312), + Offset(18.039029933525192, 35.83836288794122), + Offset(17.653585284892095, 35.63628034484623), + Offset(17.37357162228699, 35.47913093204501), + Offset(17.184910971787485, 35.36813799782225), + Offset(17.076590321915372, 35.3024952302311), + Offset(17.040082437073032, 35.280050865011795), + Offset(17.04000000000052, 35.28), + ], + <Offset>[ + Offset(33.599999999999284, 6.0), + Offset(33.60378470030526, 6.002296228500315), + Offset(36.38967574950269, 7.998624499963004), + Offset(42.54776719716194, 17.73765436786441), + Offset(41.658980312754615, 28.5451611688539), + Offset(37.54498000139701, 34.308526658875984), + Offset(33.54263783070051, 37.15834579815771), + Offset(30.167535431059207, 38.534189727036605), + Offset(27.404117382535397, 39.130469359409446), + Offset(25.153966281356634, 39.3091377433522), + Offset(23.319343828908416, 39.26995653624116), + Offset(21.819578621640403, 39.12108999420297), + Offset(20.60213825053295, 38.894835867893995), + Offset(19.62360132485448, 38.637237944235835), + Offset(18.845976971348936, 38.38185129321421), + Offset(18.239167746438056, 38.14971419309638), + Offset(17.777732663397334, 37.95295628860924), + Offset(17.441563669830845, 37.79813439937118), + Offset(17.214598153286296, 37.687948048506286), + Offset(17.08410847463606, 37.62248304859991), + Offset(17.040099392177375, 37.600050864949836), + Offset(17.040000000000525, 37.6), + ], + <Offset>[ + Offset(33.599999999999284, 6.0), + Offset(33.60378470030526, 6.002296228500315), + Offset(36.38967574950269, 7.998624499963004), + Offset(42.54776719716194, 17.73765436786441), + Offset(41.658980312754615, 28.5451611688539), + Offset(37.54498000139701, 34.308526658875984), + Offset(33.54263783070051, 37.15834579815771), + Offset(30.167535431059207, 38.534189727036605), + Offset(27.404117382535397, 39.130469359409446), + Offset(25.153966281356634, 39.3091377433522), + Offset(23.319343828908416, 39.26995653624116), + Offset(21.819578621640403, 39.12108999420297), + Offset(20.60213825053295, 38.894835867893995), + Offset(19.62360132485448, 38.637237944235835), + Offset(18.845976971348936, 38.38185129321421), + Offset(18.239167746438056, 38.14971419309638), + Offset(17.777732663397334, 37.95295628860924), + Offset(17.441563669830845, 37.79813439937118), + Offset(17.214598153286296, 37.687948048506286), + Offset(17.08410847463606, 37.62248304859991), + Offset(17.040099392177375, 37.600050864949836), + Offset(17.040000000000525, 37.6), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(33.599999999999284, 6.0), + Offset(33.60378470030526, 6.002296228500315), + Offset(36.38967574950269, 7.998624499963004), + Offset(42.54776719716194, 17.73765436786441), + Offset(41.658980312754615, 28.5451611688539), + Offset(37.54498000139701, 34.308526658875984), + Offset(33.54263783070051, 37.15834579815771), + Offset(30.167535431059207, 38.534189727036605), + Offset(27.404117382535397, 39.130469359409446), + Offset(25.153966281356634, 39.3091377433522), + Offset(23.319343828908416, 39.26995653624116), + Offset(21.819578621640403, 39.12108999420297), + Offset(20.60213825053295, 38.894835867893995), + Offset(19.62360132485448, 38.637237944235835), + Offset(18.845976971348936, 38.38185129321421), + Offset(18.239167746438056, 38.14971419309638), + Offset(17.777732663397334, 37.95295628860924), + Offset(17.441563669830845, 37.79813439937118), + Offset(17.214598153286296, 37.687948048506286), + Offset(17.08410847463606, 37.62248304859991), + Offset(17.040099392177375, 37.600050864949836), + Offset(17.040000000000525, 37.6), + ], + <Offset>[ + Offset(30.39999999999928, 6.0), + Offset(30.403826772654256, 6.001600955318109), + Offset(33.262973928210585, 7.464112893661214), + Offset(40.3252246978803, 15.636425198410514), + Offset(41.00861867752789, 25.79286169038749), + Offset(37.98976632761843, 31.726851345525063), + Offset(34.66109919246759, 34.93604100542338), + Offset(31.70815663793789, 36.68371605880232), + Offset(29.216038057712783, 37.618746191042845), + Offset(27.144554306925627, 38.092582286299354), + Offset(25.430782781824195, 38.30542837248677), + Offset(24.014543572942166, 38.369738636609966), + Offset(22.850742435529103, 38.32371484812867), + Offset(21.90507975646699, 38.2162199326414), + Offset(21.146729034110027, 38.08362328362998), + Offset(20.550519051593216, 37.949576380183515), + Offset(20.094408607160354, 37.82880891010401), + Offset(19.760567137157015, 37.73014235182732), + Offset(19.53440820397033, 37.65826086700747), + Offset(19.40409629300487, 37.61496489587922), + Offset(19.360099392115416, 37.60003390984549), + Offset(19.360000000000525, 37.6), + ], + <Offset>[ + Offset(30.39999999999928, 6.0), + Offset(30.403826772654256, 6.001600955318109), + Offset(33.262973928210585, 7.464112893661214), + Offset(40.3252246978803, 15.636425198410514), + Offset(41.00861867752789, 25.79286169038749), + Offset(37.98976632761843, 31.726851345525063), + Offset(34.66109919246759, 34.93604100542338), + Offset(31.70815663793789, 36.68371605880232), + Offset(29.216038057712783, 37.618746191042845), + Offset(27.144554306925627, 38.092582286299354), + Offset(25.430782781824195, 38.30542837248677), + Offset(24.014543572942166, 38.369738636609966), + Offset(22.850742435529103, 38.32371484812867), + Offset(21.90507975646699, 38.2162199326414), + Offset(21.146729034110027, 38.08362328362998), + Offset(20.550519051593216, 37.949576380183515), + Offset(20.094408607160354, 37.82880891010401), + Offset(19.760567137157015, 37.73014235182732), + Offset(19.53440820397033, 37.65826086700747), + Offset(19.40409629300487, 37.61496489587922), + Offset(19.360099392115416, 37.60003390984549), + Offset(19.360000000000525, 37.6), + ], + ), + _PathClose( + ), + _PathMoveTo( + <Offset>[ + Offset(35.2, 34.8), + Offset(35.19750620549164, 34.80226521395049), + Offset(33.142422203433355, 36.40619669474303), + Offset(24.747975921718226, 38.79115144612656), + Offset(17.213465824170402, 35.77456562512825), + Offset(14.087509018127873, 31.596287379559158), + Offset(12.982664015207707, 28.20334593862164), + Offset(12.742961813510924, 25.59383569924602), + Offset(12.89264852964688, 23.57904486699663), + Offset(13.20967315509607, 22.002123241757968), + Offset(13.58287087866059, 20.749270041876564), + Offset(13.959933927651988, 19.74208111128378), + Offset(14.3377469801464, 18.94295871281142), + Offset(14.693700004697835, 18.31444106552057), + Offset(15.011548853709796, 17.824196733156548), + Offset(15.282251777644161, 17.447621353156435), + Offset(15.50206828496817, 17.16494648399472), + Offset(15.670133508272507, 16.961099217207604), + Offset(15.78750849445444, 16.8245011830994), + Offset(15.856451190964936, 16.746351759640973), + Offset(15.879946796268738, 16.720059343059617), + Offset(15.879999999999999, 16.720000000000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.2, 34.8), + Offset(35.19750620549164, 34.80226521395049), + Offset(33.142422203433355, 36.40619669474303), + Offset(24.747975921718226, 38.79115144612656), + Offset(17.213465824170402, 35.77456562512825), + Offset(14.087509018127873, 31.596287379559158), + Offset(12.982664015207707, 28.20334593862164), + Offset(12.742961813510924, 25.59383569924602), + Offset(12.89264852964688, 23.57904486699663), + Offset(13.20967315509607, 22.002123241757968), + Offset(13.58287087866059, 20.749270041876564), + Offset(13.959933927651988, 19.74208111128378), + Offset(14.3377469801464, 18.94295871281142), + Offset(14.693700004697835, 18.31444106552057), + Offset(15.011548853709796, 17.824196733156548), + Offset(15.282251777644161, 17.447621353156435), + Offset(15.50206828496817, 17.16494648399472), + Offset(15.670133508272507, 16.961099217207604), + Offset(15.78750849445444, 16.8245011830994), + Offset(15.856451190964936, 16.746351759640973), + Offset(15.879946796268738, 16.720059343059617), + Offset(15.879999999999999, 16.720000000000002), + ], + <Offset>[ + Offset(12.799999999999999, 34.8), + Offset(12.797800711934586, 34.79739830167506), + Offset(11.255509454388564, 32.66461545063052), + Offset(9.190178426746762, 24.08254725994932), + Offset(12.660934377583331, 16.50846927586335), + Offset(17.201013301677882, 13.52456018610269), + Offset(20.811893547577277, 12.647212389481304), + Offset(23.527310261661704, 12.640520021606001), + Offset(25.576093255888573, 12.996982688430414), + Offset(27.143789334079017, 13.48623504238804), + Offset(28.362943549071037, 13.997572895595871), + Offset(29.324688586764324, 14.482621608132748), + Offset(30.077976275119465, 14.945111574454113), + Offset(30.664049025985392, 15.367314984359552), + Offset(31.116813293037453, 15.736600666066936), + Offset(31.46171091373027, 16.046656662766367), + Offset(31.718799891309303, 16.29591483445806), + Offset(31.903157779555688, 16.485154884400586), + Offset(32.02617884924267, 16.61669091260771), + Offset(32.0963659195466, 16.69372469059615), + Offset(32.11994679583504, 16.71994065732921), + Offset(32.12, 16.72), + ], + <Offset>[ + Offset(12.799999999999999, 34.8), + Offset(12.797800711934586, 34.79739830167506), + Offset(11.255509454388564, 32.66461545063052), + Offset(9.190178426746762, 24.08254725994932), + Offset(12.660934377583331, 16.50846927586335), + Offset(17.201013301677882, 13.52456018610269), + Offset(20.811893547577277, 12.647212389481304), + Offset(23.527310261661704, 12.640520021606001), + Offset(25.576093255888573, 12.996982688430414), + Offset(27.143789334079017, 13.48623504238804), + Offset(28.362943549071037, 13.997572895595871), + Offset(29.324688586764324, 14.482621608132748), + Offset(30.077976275119465, 14.945111574454113), + Offset(30.664049025985392, 15.367314984359552), + Offset(31.116813293037453, 15.736600666066936), + Offset(31.46171091373027, 16.046656662766367), + Offset(31.718799891309303, 16.29591483445806), + Offset(31.903157779555688, 16.485154884400586), + Offset(32.02617884924267, 16.61669091260771), + Offset(32.0963659195466, 16.69372469059615), + Offset(32.11994679583504, 16.71994065732921), + Offset(32.12, 16.72), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.799999999999999, 34.8), + Offset(12.797800711934586, 34.79739830167506), + Offset(11.255509454388564, 32.66461545063052), + Offset(9.190178426746762, 24.08254725994932), + Offset(12.660934377583331, 16.50846927586335), + Offset(17.201013301677882, 13.52456018610269), + Offset(20.811893547577277, 12.647212389481304), + Offset(23.527310261661704, 12.640520021606001), + Offset(25.576093255888573, 12.996982688430414), + Offset(27.143789334079017, 13.48623504238804), + Offset(28.362943549071037, 13.997572895595871), + Offset(29.324688586764324, 14.482621608132748), + Offset(30.077976275119465, 14.945111574454113), + Offset(30.664049025985392, 15.367314984359552), + Offset(31.116813293037453, 15.736600666066936), + Offset(31.46171091373027, 16.046656662766367), + Offset(31.718799891309303, 16.29591483445806), + Offset(31.903157779555688, 16.485154884400586), + Offset(32.02617884924267, 16.61669091260771), + Offset(32.0963659195466, 16.69372469059615), + Offset(32.11994679583504, 16.71994065732921), + Offset(32.12, 16.72), + ], + <Offset>[ + Offset(12.799999999999999, 17.2), + Offset(12.801624714436713, 17.19762969959451), + Offset(14.195323289048401, 15.467755433523894), + Offset(20.74693885874317, 11.858563513900311), + Offset(27.798581509148605, 12.931480282116368), + Offset(31.400227525107965, 15.970884980320555), + Offset(33.03456990761612, 18.79874987920025), + Offset(33.70491543695029, 21.113936659438757), + Offset(33.89057068190488, 22.962546401906028), + Offset(33.83484434786968, 24.434469183017498), + Offset(33.667848449720154, 25.61048713663265), + Offset(33.45712105352585, 26.55492884029244), + Offset(33.219141883828776, 27.31243459193295), + Offset(32.97964808975476, 27.915446358228348), + Offset(32.75706734575072, 28.390737011252952), + Offset(32.562468884751034, 28.759088841119738), + Offset(32.40161047308811, 29.037632525154663), + Offset(32.277114041046914, 29.239673954694513), + Offset(32.189458347486145, 29.375646191369892), + Offset(32.13771575951039, 29.453657691624603), + Offset(32.12004004890893, 29.47994065698845), + Offset(32.12, 29.479999999999997), + ], + <Offset>[ + Offset(12.799999999999999, 17.2), + Offset(12.801624714436713, 17.19762969959451), + Offset(14.195323289048401, 15.467755433523894), + Offset(20.74693885874317, 11.858563513900311), + Offset(27.798581509148605, 12.931480282116368), + Offset(31.400227525107965, 15.970884980320555), + Offset(33.03456990761612, 18.79874987920025), + Offset(33.70491543695029, 21.113936659438757), + Offset(33.89057068190488, 22.962546401906028), + Offset(33.83484434786968, 24.434469183017498), + Offset(33.667848449720154, 25.61048713663265), + Offset(33.45712105352585, 26.55492884029244), + Offset(33.219141883828776, 27.31243459193295), + Offset(32.97964808975476, 27.915446358228348), + Offset(32.75706734575072, 28.390737011252952), + Offset(32.562468884751034, 28.759088841119738), + Offset(32.40161047308811, 29.037632525154663), + Offset(32.277114041046914, 29.239673954694513), + Offset(32.189458347486145, 29.375646191369892), + Offset(32.13771575951039, 29.453657691624603), + Offset(32.12004004890893, 29.47994065698845), + Offset(32.12, 29.479999999999997), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.799999999999999, 17.2), + Offset(12.801624714436713, 17.19762969959451), + Offset(14.195323289048401, 15.467755433523894), + Offset(20.74693885874317, 11.858563513900311), + Offset(27.798581509148605, 12.931480282116368), + Offset(31.400227525107965, 15.970884980320555), + Offset(33.03456990761612, 18.79874987920025), + Offset(33.70491543695029, 21.113936659438757), + Offset(33.89057068190488, 22.962546401906028), + Offset(33.83484434786968, 24.434469183017498), + Offset(33.667848449720154, 25.61048713663265), + Offset(33.45712105352585, 26.55492884029244), + Offset(33.219141883828776, 27.31243459193295), + Offset(32.97964808975476, 27.915446358228348), + Offset(32.75706734575072, 28.390737011252952), + Offset(32.562468884751034, 28.759088841119738), + Offset(32.40161047308811, 29.037632525154663), + Offset(32.277114041046914, 29.239673954694513), + Offset(32.189458347486145, 29.375646191369892), + Offset(32.13771575951039, 29.453657691624603), + Offset(32.12004004890893, 29.47994065698845), + Offset(32.12, 29.479999999999997), + ], + <Offset>[ + Offset(35.2, 17.2), + Offset(35.20133020799377, 17.202496611869943), + Offset(36.08223603809319, 19.20933667763641), + Offset(36.30473635371463, 26.567167700077555), + Offset(32.35111295573567, 32.19757663138127), + Offset(28.286723241557954, 34.04261217377702), + Offset(25.205340375246543, 34.35488342834059), + Offset(22.92056698879951, 34.06725233707878), + Offset(21.20712595566319, 33.54460858047224), + Offset(19.90072816888673, 32.95035738238742), + Offset(18.887775779309706, 32.36218428291335), + Offset(18.092366394413514, 31.814388343443472), + Offset(17.478912588855714, 31.310281730290257), + Offset(17.009299068467204, 30.862572439389364), + Offset(16.651802906423065, 30.478333078342565), + Offset(16.383009748664925, 30.160053531509803), + Offset(16.184878866746974, 29.906664174691322), + Offset(16.044089769763733, 29.71561828750153), + Offset(15.950787992697913, 29.583456461861584), + Offset(15.897801030928724, 29.506284760669423), + Offset(15.880040049342629, 29.480059342718857), + Offset(15.88, 29.48), + ], + <Offset>[ + Offset(35.2, 17.2), + Offset(35.20133020799377, 17.202496611869943), + Offset(36.08223603809319, 19.20933667763641), + Offset(36.30473635371463, 26.567167700077555), + Offset(32.35111295573567, 32.19757663138127), + Offset(28.286723241557954, 34.04261217377702), + Offset(25.205340375246543, 34.35488342834059), + Offset(22.92056698879951, 34.06725233707878), + Offset(21.20712595566319, 33.54460858047224), + Offset(19.90072816888673, 32.95035738238742), + Offset(18.887775779309706, 32.36218428291335), + Offset(18.092366394413514, 31.814388343443472), + Offset(17.478912588855714, 31.310281730290257), + Offset(17.009299068467204, 30.862572439389364), + Offset(16.651802906423065, 30.478333078342565), + Offset(16.383009748664925, 30.160053531509803), + Offset(16.184878866746974, 29.906664174691322), + Offset(16.044089769763733, 29.71561828750153), + Offset(15.950787992697913, 29.583456461861584), + Offset(15.897801030928724, 29.506284760669423), + Offset(15.880040049342629, 29.480059342718857), + Offset(15.88, 29.48), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.2, 17.2), + Offset(35.20133020799377, 17.202496611869943), + Offset(36.08223603809319, 19.20933667763641), + Offset(36.30473635371463, 26.567167700077555), + Offset(32.35111295573567, 32.19757663138127), + Offset(28.286723241557954, 34.04261217377702), + Offset(25.205340375246543, 34.35488342834059), + Offset(22.92056698879951, 34.06725233707878), + Offset(21.20712595566319, 33.54460858047224), + Offset(19.90072816888673, 32.95035738238742), + Offset(18.887775779309706, 32.36218428291335), + Offset(18.092366394413514, 31.814388343443472), + Offset(17.478912588855714, 31.310281730290257), + Offset(17.009299068467204, 30.862572439389364), + Offset(16.651802906423065, 30.478333078342565), + Offset(16.383009748664925, 30.160053531509803), + Offset(16.184878866746974, 29.906664174691322), + Offset(16.044089769763733, 29.71561828750153), + Offset(15.950787992697913, 29.583456461861584), + Offset(15.897801030928724, 29.506284760669423), + Offset(15.880040049342629, 29.480059342718857), + Offset(15.88, 29.48), + ], + <Offset>[ + Offset(35.2, 34.8), + Offset(35.19750620549164, 34.80226521395049), + Offset(33.142422203433355, 36.40619669474303), + Offset(24.747975921718226, 38.79115144612656), + Offset(17.213465824170402, 35.77456562512825), + Offset(14.087509018127873, 31.596287379559158), + Offset(12.982664015207707, 28.20334593862164), + Offset(12.742961813510924, 25.59383569924602), + Offset(12.89264852964688, 23.57904486699663), + Offset(13.20967315509607, 22.002123241757968), + Offset(13.58287087866059, 20.749270041876564), + Offset(13.959933927651988, 19.74208111128378), + Offset(14.3377469801464, 18.94295871281142), + Offset(14.693700004697835, 18.31444106552057), + Offset(15.011548853709796, 17.824196733156548), + Offset(15.282251777644161, 17.447621353156435), + Offset(15.50206828496817, 17.16494648399472), + Offset(15.670133508272507, 16.961099217207604), + Offset(15.78750849445444, 16.8245011830994), + Offset(15.856451190964936, 16.746351759640973), + Offset(15.879946796268738, 16.720059343059617), + Offset(15.879999999999999, 16.720000000000002), + ], + <Offset>[ + Offset(35.2, 34.8), + Offset(35.19750620549164, 34.80226521395049), + Offset(33.142422203433355, 36.40619669474303), + Offset(24.747975921718226, 38.79115144612656), + Offset(17.213465824170402, 35.77456562512825), + Offset(14.087509018127873, 31.596287379559158), + Offset(12.982664015207707, 28.20334593862164), + Offset(12.742961813510924, 25.59383569924602), + Offset(12.89264852964688, 23.57904486699663), + Offset(13.20967315509607, 22.002123241757968), + Offset(13.58287087866059, 20.749270041876564), + Offset(13.959933927651988, 19.74208111128378), + Offset(14.3377469801464, 18.94295871281142), + Offset(14.693700004697835, 18.31444106552057), + Offset(15.011548853709796, 17.824196733156548), + Offset(15.282251777644161, 17.447621353156435), + Offset(15.50206828496817, 17.16494648399472), + Offset(15.670133508272507, 16.961099217207604), + Offset(15.78750849445444, 16.8245011830994), + Offset(15.856451190964936, 16.746351759640973), + Offset(15.879946796268738, 16.720059343059617), + Offset(15.879999999999999, 16.720000000000002), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.285714285714, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(10.0, 26.0), + Offset(9.999565779019244, 25.996958092697728), + Offset(9.863179258510144, 23.612315433654864), + Offset(12.452761639331678, 15.835363679752177), + Offset(18.834098352379797, 10.835142987213462), + Offset(24.406021200709937, 9.863694019137322), + Offset(28.507374325508763, 10.595389722571399), + Offset(31.42060810506175, 11.961122338395), + Offset(33.46861178272727, 13.495458557937988), + Offset(34.90276563764392, 14.992797246058515), + Offset(35.90322109391197, 16.36368363741724), + Offset(36.59776146682701, 17.573772022023455), + Offset(37.07681747862736, 18.615128169522876), + Offset(37.40459569801132, 19.492582316574545), + Offset(37.626755542882265, 20.216941267370075), + Offset(37.77527700273555, 20.799727590047226), + Offset(37.87291743778957, 21.253700350603722), + Offset(37.93537260667183, 21.590562241264497), + Offset(37.973261356283984, 21.821016964503688), + Offset(37.99344532401808, 21.954642338436525), + Offset(37.99998538315687, 21.999897684768573), + Offset(38.0, 21.999999999999993), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.0, 26.0), + Offset(9.999565779019244, 25.996958092697728), + Offset(9.863179258510144, 23.612315433654864), + Offset(12.452761639331678, 15.835363679752177), + Offset(18.834098352379797, 10.835142987213462), + Offset(24.406021200709937, 9.863694019137322), + Offset(28.507374325508763, 10.595389722571399), + Offset(31.42060810506175, 11.961122338395), + Offset(33.46861178272727, 13.495458557937988), + Offset(34.90276563764392, 14.992797246058515), + Offset(35.90322109391197, 16.36368363741724), + Offset(36.59776146682701, 17.573772022023455), + Offset(37.07681747862736, 18.615128169522876), + Offset(37.40459569801132, 19.492582316574545), + Offset(37.626755542882265, 20.216941267370075), + Offset(37.77527700273555, 20.799727590047226), + Offset(37.87291743778957, 21.253700350603722), + Offset(37.93537260667183, 21.590562241264497), + Offset(37.973261356283984, 21.821016964503688), + Offset(37.99344532401808, 21.954642338436525), + Offset(37.99998538315687, 21.999897684768573), + Offset(38.0, 21.999999999999993), + ], + <Offset>[ + Offset(10.0, 22.0), + Offset(10.000434881903109, 21.996958187115208), + Offset(10.537203766746376, 19.66951300869151), + Offset(15.2007493434278, 12.928722391574958), + Offset(22.726894381864838, 9.915284806391266), + Offset(28.34794602732309, 10.54283219457061), + Offset(32.08037023016842, 12.393638944810997), + Offset(34.49466952610868, 14.52044771427649), + Offset(36.03113891519555, 16.566851514784105), + Offset(36.98867178324178, 18.40585973475647), + Offset(37.56526083167866, 20.0020381982159), + Offset(37.893194841987366, 21.35819435185408), + Offset(38.06150889201586, 22.492031936757623), + Offset(38.13048882144999, 23.426165819354733), + Offset(38.14094176630335, 24.183755168682307), + Offset(38.12034219741291, 24.78481604721129), + Offset(38.086964642108946, 25.247969219160655), + Offset(38.052600274850896, 25.58884408148203), + Offset(38.02444615197159, 25.820689465683056), + Offset(38.00640765629513, 25.954621335624125), + Offset(38.000014616095385, 25.999897684661754), + Offset(38.0, 25.999999999999993), + ], + <Offset>[ + Offset(10.0, 22.0), + Offset(10.000434881903109, 21.996958187115208), + Offset(10.537203766746376, 19.66951300869151), + Offset(15.2007493434278, 12.928722391574958), + Offset(22.726894381864838, 9.915284806391266), + Offset(28.34794602732309, 10.54283219457061), + Offset(32.08037023016842, 12.393638944810997), + Offset(34.49466952610868, 14.52044771427649), + Offset(36.03113891519555, 16.566851514784105), + Offset(36.98867178324178, 18.40585973475647), + Offset(37.56526083167866, 20.0020381982159), + Offset(37.893194841987366, 21.35819435185408), + Offset(38.06150889201586, 22.492031936757623), + Offset(38.13048882144999, 23.426165819354733), + Offset(38.14094176630335, 24.183755168682307), + Offset(38.12034219741291, 24.78481604721129), + Offset(38.086964642108946, 25.247969219160655), + Offset(38.052600274850896, 25.58884408148203), + Offset(38.02444615197159, 25.820689465683056), + Offset(38.00640765629513, 25.954621335624125), + Offset(38.000014616095385, 25.999897684661754), + Offset(38.0, 25.999999999999993), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.0, 22.0), + Offset(10.000434881903109, 21.996958187115208), + Offset(10.537203766746376, 19.66951300869151), + Offset(15.2007493434278, 12.928722391574958), + Offset(22.726894381864838, 9.915284806391266), + Offset(28.34794602732309, 10.54283219457061), + Offset(32.08037023016842, 12.393638944810997), + Offset(34.49466952610868, 14.52044771427649), + Offset(36.03113891519555, 16.566851514784105), + Offset(36.98867178324178, 18.40585973475647), + Offset(37.56526083167866, 20.0020381982159), + Offset(37.893194841987366, 21.35819435185408), + Offset(38.06150889201586, 22.492031936757623), + Offset(38.13048882144999, 23.426165819354733), + Offset(38.14094176630335, 24.183755168682307), + Offset(38.12034219741291, 24.78481604721129), + Offset(38.086964642108946, 25.247969219160655), + Offset(38.052600274850896, 25.58884408148203), + Offset(38.02444615197159, 25.820689465683056), + Offset(38.00640765629513, 25.954621335624125), + Offset(38.000014616095385, 25.999897684661754), + Offset(38.0, 25.999999999999993), + ], + <Offset>[ + Offset(38.0, 22.0), + Offset(38.00043422098076, 22.003041907302272), + Offset(38.136820741489856, 24.387684566345136), + Offset(35.547238360668324, 32.16463632024782), + Offset(29.165901647620203, 37.16485701278654), + Offset(23.59397879929007, 38.13630598086269), + Offset(19.492625674491244, 37.4046102774286), + Offset(16.57939189493825, 36.038877661605), + Offset(14.531388217272726, 34.50454144206201), + Offset(13.097234362356085, 33.007202753941485), + Offset(12.096778906088034, 31.63631636258276), + Offset(11.402238533172989, 30.426227977976552), + Offset(10.923182521372642, 29.384871830477124), + Offset(10.595404301988683, 28.507417683425455), + Offset(10.373244457117737, 27.783058732629918), + Offset(10.224722997264447, 27.20027240995278), + Offset(10.12708256221043, 26.746299649396278), + Offset(10.064627393328172, 26.40943775873551), + Offset(10.026738643716017, 26.17898303549632), + Offset(10.006554675981915, 26.045357661563475), + Offset(10.000014616843135, 26.00010231523142), + Offset(10.0, 26.0), + ], + <Offset>[ + Offset(38.0, 22.0), + Offset(38.00043422098076, 22.003041907302272), + Offset(38.136820741489856, 24.387684566345136), + Offset(35.547238360668324, 32.16463632024782), + Offset(29.165901647620203, 37.16485701278654), + Offset(23.59397879929007, 38.13630598086269), + Offset(19.492625674491244, 37.4046102774286), + Offset(16.57939189493825, 36.038877661605), + Offset(14.531388217272726, 34.50454144206201), + Offset(13.097234362356085, 33.007202753941485), + Offset(12.096778906088034, 31.63631636258276), + Offset(11.402238533172989, 30.426227977976552), + Offset(10.923182521372642, 29.384871830477124), + Offset(10.595404301988683, 28.507417683425455), + Offset(10.373244457117737, 27.783058732629918), + Offset(10.224722997264447, 27.20027240995278), + Offset(10.12708256221043, 26.746299649396278), + Offset(10.064627393328172, 26.40943775873551), + Offset(10.026738643716017, 26.17898303549632), + Offset(10.006554675981915, 26.045357661563475), + Offset(10.000014616843135, 26.00010231523142), + Offset(10.0, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.0, 22.0), + Offset(38.00043422098076, 22.003041907302272), + Offset(38.136820741489856, 24.387684566345136), + Offset(35.547238360668324, 32.16463632024782), + Offset(29.165901647620203, 37.16485701278654), + Offset(23.59397879929007, 38.13630598086269), + Offset(19.492625674491244, 37.4046102774286), + Offset(16.57939189493825, 36.038877661605), + Offset(14.531388217272726, 34.50454144206201), + Offset(13.097234362356085, 33.007202753941485), + Offset(12.096778906088034, 31.63631636258276), + Offset(11.402238533172989, 30.426227977976552), + Offset(10.923182521372642, 29.384871830477124), + Offset(10.595404301988683, 28.507417683425455), + Offset(10.373244457117737, 27.783058732629918), + Offset(10.224722997264447, 27.20027240995278), + Offset(10.12708256221043, 26.746299649396278), + Offset(10.064627393328172, 26.40943775873551), + Offset(10.026738643716017, 26.17898303549632), + Offset(10.006554675981915, 26.045357661563475), + Offset(10.000014616843135, 26.00010231523142), + Offset(10.0, 26.0), + ], + <Offset>[ + Offset(38.0, 26.0), + Offset(37.99956511809689, 26.003041812884792), + Offset(37.46279623325363, 28.33048699130849), + Offset(32.7992506565722, 35.07127760842504), + Offset(25.273105618135162, 38.08471519360873), + Offset(19.652053972676917, 37.4571678054294), + Offset(15.919629769831586, 35.606361055189005), + Offset(13.50533047389132, 33.479552285723514), + Offset(11.968861084804454, 31.433148485215895), + Offset(11.011328216758224, 29.59414026524353), + Offset(10.43473916832134, 27.9979618017841), + Offset(10.106805158012635, 26.641805648145926), + Offset(9.938491107984142, 25.507968063242377), + Offset(9.86951117855001, 24.573834180645267), + Offset(9.859058233696649, 23.816244831317686), + Offset(9.87965780258709, 23.215183952788717), + Offset(9.913035357891056, 22.752030780839345), + Offset(9.947399725149102, 22.411155918517977), + Offset(9.97555384802841, 22.17931053431695), + Offset(9.993592343704867, 22.045378664375875), + Offset(9.999985383904612, 22.00010231533824), + Offset(10.0, 22.0), + ], + <Offset>[ + Offset(38.0, 26.0), + Offset(37.99956511809689, 26.003041812884792), + Offset(37.46279623325363, 28.33048699130849), + Offset(32.7992506565722, 35.07127760842504), + Offset(25.273105618135162, 38.08471519360873), + Offset(19.652053972676917, 37.4571678054294), + Offset(15.919629769831586, 35.606361055189005), + Offset(13.50533047389132, 33.479552285723514), + Offset(11.968861084804454, 31.433148485215895), + Offset(11.011328216758224, 29.59414026524353), + Offset(10.43473916832134, 27.9979618017841), + Offset(10.106805158012635, 26.641805648145926), + Offset(9.938491107984142, 25.507968063242377), + Offset(9.86951117855001, 24.573834180645267), + Offset(9.859058233696649, 23.816244831317686), + Offset(9.87965780258709, 23.215183952788717), + Offset(9.913035357891056, 22.752030780839345), + Offset(9.947399725149102, 22.411155918517977), + Offset(9.97555384802841, 22.17931053431695), + Offset(9.993592343704867, 22.045378664375875), + Offset(9.999985383904612, 22.00010231533824), + Offset(10.0, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.0, 26.0), + Offset(37.99956511809689, 26.003041812884792), + Offset(37.46279623325363, 28.33048699130849), + Offset(32.7992506565722, 35.07127760842504), + Offset(25.273105618135162, 38.08471519360873), + Offset(19.652053972676917, 37.4571678054294), + Offset(15.919629769831586, 35.606361055189005), + Offset(13.50533047389132, 33.479552285723514), + Offset(11.968861084804454, 31.433148485215895), + Offset(11.011328216758224, 29.59414026524353), + Offset(10.43473916832134, 27.9979618017841), + Offset(10.106805158012635, 26.641805648145926), + Offset(9.938491107984142, 25.507968063242377), + Offset(9.86951117855001, 24.573834180645267), + Offset(9.859058233696649, 23.816244831317686), + Offset(9.87965780258709, 23.215183952788717), + Offset(9.913035357891056, 22.752030780839345), + Offset(9.947399725149102, 22.411155918517977), + Offset(9.97555384802841, 22.17931053431695), + Offset(9.993592343704867, 22.045378664375875), + Offset(9.999985383904612, 22.00010231533824), + Offset(10.0, 22.0), + ], + <Offset>[ + Offset(10.0, 26.0), + Offset(9.999565779019244, 25.996958092697728), + Offset(9.863179258510144, 23.612315433654864), + Offset(12.452761639331678, 15.835363679752177), + Offset(18.834098352379797, 10.835142987213462), + Offset(24.406021200709937, 9.863694019137322), + Offset(28.507374325508763, 10.595389722571399), + Offset(31.42060810506175, 11.961122338395), + Offset(33.46861178272727, 13.495458557937988), + Offset(34.90276563764392, 14.992797246058515), + Offset(35.90322109391197, 16.36368363741724), + Offset(36.59776146682701, 17.573772022023455), + Offset(37.07681747862736, 18.615128169522876), + Offset(37.40459569801132, 19.492582316574545), + Offset(37.626755542882265, 20.216941267370075), + Offset(37.77527700273555, 20.799727590047226), + Offset(37.87291743778957, 21.253700350603722), + Offset(37.93537260667183, 21.590562241264497), + Offset(37.973261356283984, 21.821016964503688), + Offset(37.99344532401808, 21.954642338436525), + Offset(37.99998538315687, 21.999897684768573), + Offset(38.0, 21.999999999999993), + ], + <Offset>[ + Offset(10.0, 26.0), + Offset(9.999565779019244, 25.996958092697728), + Offset(9.863179258510144, 23.612315433654864), + Offset(12.452761639331678, 15.835363679752177), + Offset(18.834098352379797, 10.835142987213462), + Offset(24.406021200709937, 9.863694019137322), + Offset(28.507374325508763, 10.595389722571399), + Offset(31.42060810506175, 11.961122338395), + Offset(33.46861178272727, 13.495458557937988), + Offset(34.90276563764392, 14.992797246058515), + Offset(35.90322109391197, 16.36368363741724), + Offset(36.59776146682701, 17.573772022023455), + Offset(37.07681747862736, 18.615128169522876), + Offset(37.40459569801132, 19.492582316574545), + Offset(37.626755542882265, 20.216941267370075), + Offset(37.77527700273555, 20.799727590047226), + Offset(37.87291743778957, 21.253700350603722), + Offset(37.93537260667183, 21.590562241264497), + Offset(37.973261356283984, 21.821016964503688), + Offset(37.99344532401808, 21.954642338436525), + Offset(37.99998538315687, 21.999897684768573), + Offset(38.0, 21.999999999999993), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.285714285714, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(22.0, 10.0), + Offset(22.003041907302272, 9.999565779019244), + Offset(24.387684566345136, 9.863179258510144), + Offset(32.16463632024782, 12.452761639331678), + Offset(37.16485701278654, 18.834098352379797), + Offset(38.13630598086269, 24.406021200709937), + Offset(37.4046102774286, 28.50737432550876), + Offset(36.038877661605, 31.42060810506175), + Offset(34.50454144206201, 33.46861178272727), + Offset(33.007202753941485, 34.90276563764392), + Offset(31.63631636258276, 35.90322109391197), + Offset(30.426227977976545, 36.597761466827016), + Offset(29.384871830477124, 37.07681747862736), + Offset(28.507417683425455, 37.40459569801132), + Offset(27.78305873262992, 37.62675554288226), + Offset(27.20027240995278, 37.77527700273556), + Offset(26.746299649396278, 37.87291743778957), + Offset(26.409437758735507, 37.935372606671834), + Offset(26.178983035496316, 37.973261356283984), + Offset(26.045357661563475, 37.99344532401808), + Offset(26.000102315231423, 37.99998538315686), + Offset(26.000000000000004, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(22.0, 10.0), + Offset(22.003041907302272, 9.999565779019244), + Offset(24.387684566345136, 9.863179258510144), + Offset(32.16463632024782, 12.452761639331678), + Offset(37.16485701278654, 18.834098352379797), + Offset(38.13630598086269, 24.406021200709937), + Offset(37.4046102774286, 28.50737432550876), + Offset(36.038877661605, 31.42060810506175), + Offset(34.50454144206201, 33.46861178272727), + Offset(33.007202753941485, 34.90276563764392), + Offset(31.63631636258276, 35.90322109391197), + Offset(30.426227977976545, 36.597761466827016), + Offset(29.384871830477124, 37.07681747862736), + Offset(28.507417683425455, 37.40459569801132), + Offset(27.78305873262992, 37.62675554288226), + Offset(27.20027240995278, 37.77527700273556), + Offset(26.746299649396278, 37.87291743778957), + Offset(26.409437758735507, 37.935372606671834), + Offset(26.178983035496316, 37.973261356283984), + Offset(26.045357661563475, 37.99344532401808), + Offset(26.000102315231423, 37.99998538315686), + Offset(26.000000000000004, 38.0), + ], + <Offset>[ + Offset(26.0, 10.0), + Offset(26.003041812884792, 10.000434881903109), + Offset(28.33048699130849, 10.537203766746376), + Offset(35.07127760842504, 15.2007493434278), + Offset(38.08471519360873, 22.726894381864838), + Offset(37.4571678054294, 28.34794602732309), + Offset(35.606361055189005, 32.08037023016842), + Offset(33.479552285723514, 34.49466952610868), + Offset(31.433148485215895, 36.03113891519555), + Offset(29.59414026524353, 36.98867178324178), + Offset(27.9979618017841, 37.56526083167866), + Offset(26.641805648145922, 37.893194841987366), + Offset(25.507968063242377, 38.06150889201586), + Offset(24.573834180645267, 38.13048882144999), + Offset(23.81624483131769, 38.14094176630335), + Offset(23.215183952788713, 38.12034219741291), + Offset(22.752030780839345, 38.086964642108946), + Offset(22.411155918517974, 38.0526002748509), + Offset(22.179310534316947, 38.024446151971595), + Offset(22.045378664375875, 38.00640765629513), + Offset(22.000102315338243, 38.000014616095385), + Offset(22.000000000000004, 38.0), + ], + <Offset>[ + Offset(26.0, 10.0), + Offset(26.003041812884792, 10.000434881903109), + Offset(28.33048699130849, 10.537203766746376), + Offset(35.07127760842504, 15.2007493434278), + Offset(38.08471519360873, 22.726894381864838), + Offset(37.4571678054294, 28.34794602732309), + Offset(35.606361055189005, 32.08037023016842), + Offset(33.479552285723514, 34.49466952610868), + Offset(31.433148485215895, 36.03113891519555), + Offset(29.59414026524353, 36.98867178324178), + Offset(27.9979618017841, 37.56526083167866), + Offset(26.641805648145922, 37.893194841987366), + Offset(25.507968063242377, 38.06150889201586), + Offset(24.573834180645267, 38.13048882144999), + Offset(23.81624483131769, 38.14094176630335), + Offset(23.215183952788713, 38.12034219741291), + Offset(22.752030780839345, 38.086964642108946), + Offset(22.411155918517974, 38.0526002748509), + Offset(22.179310534316947, 38.024446151971595), + Offset(22.045378664375875, 38.00640765629513), + Offset(22.000102315338243, 38.000014616095385), + Offset(22.000000000000004, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.0, 10.0), + Offset(26.003041812884792, 10.000434881903109), + Offset(28.33048699130849, 10.537203766746376), + Offset(35.07127760842504, 15.2007493434278), + Offset(38.08471519360873, 22.726894381864838), + Offset(37.4571678054294, 28.34794602732309), + Offset(35.606361055189005, 32.08037023016842), + Offset(33.479552285723514, 34.49466952610868), + Offset(31.433148485215895, 36.03113891519555), + Offset(29.59414026524353, 36.98867178324178), + Offset(27.9979618017841, 37.56526083167866), + Offset(26.641805648145922, 37.893194841987366), + Offset(25.507968063242377, 38.06150889201586), + Offset(24.573834180645267, 38.13048882144999), + Offset(23.81624483131769, 38.14094176630335), + Offset(23.215183952788713, 38.12034219741291), + Offset(22.752030780839345, 38.086964642108946), + Offset(22.411155918517974, 38.0526002748509), + Offset(22.179310534316947, 38.024446151971595), + Offset(22.045378664375875, 38.00640765629513), + Offset(22.000102315338243, 38.000014616095385), + Offset(22.000000000000004, 38.0), + ], + <Offset>[ + Offset(26.0, 38.0), + Offset(25.996958092697728, 38.00043422098076), + Offset(23.612315433654864, 38.136820741489856), + Offset(15.835363679752177, 35.547238360668324), + Offset(10.835142987213462, 29.165901647620203), + Offset(9.863694019137322, 23.59397879929007), + Offset(10.595389722571403, 19.49262567449124), + Offset(11.961122338395, 16.57939189493825), + Offset(13.495458557937988, 14.531388217272726), + Offset(14.992797246058515, 13.097234362356085), + Offset(16.36368363741724, 12.096778906088034), + Offset(17.573772022023455, 11.402238533172993), + Offset(18.615128169522876, 10.923182521372642), + Offset(19.492582316574545, 10.595404301988683), + Offset(20.21694126737008, 10.373244457117734), + Offset(20.79972759004722, 10.22472299726445), + Offset(21.253700350603722, 10.12708256221043), + Offset(21.590562241264493, 10.064627393328175), + Offset(21.821016964503684, 10.02673864371602), + Offset(21.954642338436525, 10.006554675981915), + Offset(21.999897684768577, 10.000014616843131), + Offset(21.999999999999996, 9.999999999999996), + ], + <Offset>[ + Offset(26.0, 38.0), + Offset(25.996958092697728, 38.00043422098076), + Offset(23.612315433654864, 38.136820741489856), + Offset(15.835363679752177, 35.547238360668324), + Offset(10.835142987213462, 29.165901647620203), + Offset(9.863694019137322, 23.59397879929007), + Offset(10.595389722571403, 19.49262567449124), + Offset(11.961122338395, 16.57939189493825), + Offset(13.495458557937988, 14.531388217272726), + Offset(14.992797246058515, 13.097234362356085), + Offset(16.36368363741724, 12.096778906088034), + Offset(17.573772022023455, 11.402238533172993), + Offset(18.615128169522876, 10.923182521372642), + Offset(19.492582316574545, 10.595404301988683), + Offset(20.21694126737008, 10.373244457117734), + Offset(20.79972759004722, 10.22472299726445), + Offset(21.253700350603722, 10.12708256221043), + Offset(21.590562241264493, 10.064627393328175), + Offset(21.821016964503684, 10.02673864371602), + Offset(21.954642338436525, 10.006554675981915), + Offset(21.999897684768577, 10.000014616843131), + Offset(21.999999999999996, 9.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.0, 38.0), + Offset(25.996958092697728, 38.00043422098076), + Offset(23.612315433654864, 38.136820741489856), + Offset(15.835363679752177, 35.547238360668324), + Offset(10.835142987213462, 29.165901647620203), + Offset(9.863694019137322, 23.59397879929007), + Offset(10.595389722571403, 19.49262567449124), + Offset(11.961122338395, 16.57939189493825), + Offset(13.495458557937988, 14.531388217272726), + Offset(14.992797246058515, 13.097234362356085), + Offset(16.36368363741724, 12.096778906088034), + Offset(17.573772022023455, 11.402238533172993), + Offset(18.615128169522876, 10.923182521372642), + Offset(19.492582316574545, 10.595404301988683), + Offset(20.21694126737008, 10.373244457117734), + Offset(20.79972759004722, 10.22472299726445), + Offset(21.253700350603722, 10.12708256221043), + Offset(21.590562241264493, 10.064627393328175), + Offset(21.821016964503684, 10.02673864371602), + Offset(21.954642338436525, 10.006554675981915), + Offset(21.999897684768577, 10.000014616843131), + Offset(21.999999999999996, 9.999999999999996), + ], + <Offset>[ + Offset(22.0, 38.0), + Offset(21.996958187115208, 37.99956511809689), + Offset(19.66951300869151, 37.46279623325363), + Offset(12.928722391574958, 32.7992506565722), + Offset(9.915284806391266, 25.273105618135162), + Offset(10.54283219457061, 19.652053972676917), + Offset(12.393638944811, 15.919629769831582), + Offset(14.52044771427649, 13.50533047389132), + Offset(16.566851514784105, 11.968861084804454), + Offset(18.40585973475647, 11.011328216758224), + Offset(20.0020381982159, 10.43473916832134), + Offset(21.358194351854078, 10.106805158012639), + Offset(22.492031936757623, 9.938491107984142), + Offset(23.426165819354733, 9.86951117855001), + Offset(24.18375516868231, 9.859058233696645), + Offset(24.784816047211287, 9.879657802587094), + Offset(25.247969219160655, 9.913035357891056), + Offset(25.588844081482026, 9.947399725149106), + Offset(25.820689465683053, 9.975553848028413), + Offset(25.954621335624125, 9.993592343704867), + Offset(25.999897684661757, 9.999985383904608), + Offset(25.999999999999996, 9.999999999999996), + ], + <Offset>[ + Offset(22.0, 38.0), + Offset(21.996958187115208, 37.99956511809689), + Offset(19.66951300869151, 37.46279623325363), + Offset(12.928722391574958, 32.7992506565722), + Offset(9.915284806391266, 25.273105618135162), + Offset(10.54283219457061, 19.652053972676917), + Offset(12.393638944811, 15.919629769831582), + Offset(14.52044771427649, 13.50533047389132), + Offset(16.566851514784105, 11.968861084804454), + Offset(18.40585973475647, 11.011328216758224), + Offset(20.0020381982159, 10.43473916832134), + Offset(21.358194351854078, 10.106805158012639), + Offset(22.492031936757623, 9.938491107984142), + Offset(23.426165819354733, 9.86951117855001), + Offset(24.18375516868231, 9.859058233696645), + Offset(24.784816047211287, 9.879657802587094), + Offset(25.247969219160655, 9.913035357891056), + Offset(25.588844081482026, 9.947399725149106), + Offset(25.820689465683053, 9.975553848028413), + Offset(25.954621335624125, 9.993592343704867), + Offset(25.999897684661757, 9.999985383904608), + Offset(25.999999999999996, 9.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(22.0, 38.0), + Offset(21.996958187115208, 37.99956511809689), + Offset(19.66951300869151, 37.46279623325363), + Offset(12.928722391574958, 32.7992506565722), + Offset(9.915284806391266, 25.273105618135162), + Offset(10.54283219457061, 19.652053972676917), + Offset(12.393638944811, 15.919629769831582), + Offset(14.52044771427649, 13.50533047389132), + Offset(16.566851514784105, 11.968861084804454), + Offset(18.40585973475647, 11.011328216758224), + Offset(20.0020381982159, 10.43473916832134), + Offset(21.358194351854078, 10.106805158012639), + Offset(22.492031936757623, 9.938491107984142), + Offset(23.426165819354733, 9.86951117855001), + Offset(24.18375516868231, 9.859058233696645), + Offset(24.784816047211287, 9.879657802587094), + Offset(25.247969219160655, 9.913035357891056), + Offset(25.588844081482026, 9.947399725149106), + Offset(25.820689465683053, 9.975553848028413), + Offset(25.954621335624125, 9.993592343704867), + Offset(25.999897684661757, 9.999985383904608), + Offset(25.999999999999996, 9.999999999999996), + ], + <Offset>[ + Offset(22.0, 10.0), + Offset(22.003041907302272, 9.999565779019244), + Offset(24.387684566345136, 9.863179258510144), + Offset(32.16463632024782, 12.452761639331678), + Offset(37.16485701278654, 18.834098352379797), + Offset(38.13630598086269, 24.406021200709937), + Offset(37.4046102774286, 28.50737432550876), + Offset(36.038877661605, 31.42060810506175), + Offset(34.50454144206201, 33.46861178272727), + Offset(33.007202753941485, 34.90276563764392), + Offset(31.63631636258276, 35.90322109391197), + Offset(30.426227977976545, 36.597761466827016), + Offset(29.384871830477124, 37.07681747862736), + Offset(28.507417683425455, 37.40459569801132), + Offset(27.78305873262992, 37.62675554288226), + Offset(27.20027240995278, 37.77527700273556), + Offset(26.746299649396278, 37.87291743778957), + Offset(26.409437758735507, 37.935372606671834), + Offset(26.178983035496316, 37.973261356283984), + Offset(26.045357661563475, 37.99344532401808), + Offset(26.000102315231423, 37.99998538315686), + Offset(26.000000000000004, 38.0), + ], + <Offset>[ + Offset(22.0, 10.0), + Offset(22.003041907302272, 9.999565779019244), + Offset(24.387684566345136, 9.863179258510144), + Offset(32.16463632024782, 12.452761639331678), + Offset(37.16485701278654, 18.834098352379797), + Offset(38.13630598086269, 24.406021200709937), + Offset(37.4046102774286, 28.50737432550876), + Offset(36.038877661605, 31.42060810506175), + Offset(34.50454144206201, 33.46861178272727), + Offset(33.007202753941485, 34.90276563764392), + Offset(31.63631636258276, 35.90322109391197), + Offset(30.426227977976545, 36.597761466827016), + Offset(29.384871830477124, 37.07681747862736), + Offset(28.507417683425455, 37.40459569801132), + Offset(27.78305873262992, 37.62675554288226), + Offset(27.20027240995278, 37.77527700273556), + Offset(26.746299649396278, 37.87291743778957), + Offset(26.409437758735507, 37.935372606671834), + Offset(26.178983035496316, 37.973261356283984), + Offset(26.045357661563475, 37.99344532401808), + Offset(26.000102315231423, 37.99998538315686), + Offset(26.000000000000004, 38.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(10.0, 26.0), + Offset(9.999565779019244, 25.996958092697728), + Offset(9.863179258510144, 23.612315433654864), + Offset(12.452761639331678, 15.835363679752177), + Offset(18.834098352379797, 10.835142987213462), + Offset(24.406021200709937, 9.863694019137322), + Offset(28.507374325508763, 10.595389722571399), + Offset(31.42060810506175, 11.961122338395), + Offset(33.46861178272727, 13.495458557937988), + Offset(34.90276563764392, 14.992797246058515), + Offset(35.90322109391197, 16.36368363741724), + Offset(36.59776146682701, 17.573772022023455), + Offset(37.07681747862736, 18.615128169522876), + Offset(37.40459569801132, 19.492582316574545), + Offset(37.626755542882265, 20.216941267370075), + Offset(37.77527700273555, 20.799727590047226), + Offset(37.87291743778957, 21.253700350603722), + Offset(37.93537260667183, 21.590562241264497), + Offset(37.973261356283984, 21.821016964503688), + Offset(37.99344532401808, 21.954642338436525), + Offset(37.99998538315687, 21.999897684768573), + Offset(38.0, 21.999999999999993), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.0, 26.0), + Offset(9.999565779019244, 25.996958092697728), + Offset(9.863179258510144, 23.612315433654864), + Offset(12.452761639331678, 15.835363679752177), + Offset(18.834098352379797, 10.835142987213462), + Offset(24.406021200709937, 9.863694019137322), + Offset(28.507374325508763, 10.595389722571399), + Offset(31.42060810506175, 11.961122338395), + Offset(33.46861178272727, 13.495458557937988), + Offset(34.90276563764392, 14.992797246058515), + Offset(35.90322109391197, 16.36368363741724), + Offset(36.59776146682701, 17.573772022023455), + Offset(37.07681747862736, 18.615128169522876), + Offset(37.40459569801132, 19.492582316574545), + Offset(37.626755542882265, 20.216941267370075), + Offset(37.77527700273555, 20.799727590047226), + Offset(37.87291743778957, 21.253700350603722), + Offset(37.93537260667183, 21.590562241264497), + Offset(37.973261356283984, 21.821016964503688), + Offset(37.99344532401808, 21.954642338436525), + Offset(37.99998538315687, 21.999897684768573), + Offset(38.0, 21.999999999999993), + ], + <Offset>[ + Offset(10.0, 22.0), + Offset(10.000434881903109, 21.996958187115208), + Offset(10.537203766746376, 19.66951300869151), + Offset(15.2007493434278, 12.928722391574958), + Offset(22.726894381864838, 9.915284806391266), + Offset(28.34794602732309, 10.54283219457061), + Offset(32.08037023016842, 12.393638944810997), + Offset(34.49466952610868, 14.52044771427649), + Offset(36.03113891519555, 16.566851514784105), + Offset(36.98867178324178, 18.40585973475647), + Offset(37.56526083167866, 20.0020381982159), + Offset(37.893194841987366, 21.35819435185408), + Offset(38.06150889201586, 22.492031936757623), + Offset(38.13048882144999, 23.426165819354733), + Offset(38.14094176630335, 24.183755168682307), + Offset(38.12034219741291, 24.78481604721129), + Offset(38.086964642108946, 25.247969219160655), + Offset(38.052600274850896, 25.58884408148203), + Offset(38.02444615197159, 25.820689465683056), + Offset(38.00640765629513, 25.954621335624125), + Offset(38.000014616095385, 25.999897684661754), + Offset(38.0, 25.999999999999993), + ], + <Offset>[ + Offset(10.0, 22.0), + Offset(10.000434881903109, 21.996958187115208), + Offset(10.537203766746376, 19.66951300869151), + Offset(15.2007493434278, 12.928722391574958), + Offset(22.726894381864838, 9.915284806391266), + Offset(28.34794602732309, 10.54283219457061), + Offset(32.08037023016842, 12.393638944810997), + Offset(34.49466952610868, 14.52044771427649), + Offset(36.03113891519555, 16.566851514784105), + Offset(36.98867178324178, 18.40585973475647), + Offset(37.56526083167866, 20.0020381982159), + Offset(37.893194841987366, 21.35819435185408), + Offset(38.06150889201586, 22.492031936757623), + Offset(38.13048882144999, 23.426165819354733), + Offset(38.14094176630335, 24.183755168682307), + Offset(38.12034219741291, 24.78481604721129), + Offset(38.086964642108946, 25.247969219160655), + Offset(38.052600274850896, 25.58884408148203), + Offset(38.02444615197159, 25.820689465683056), + Offset(38.00640765629513, 25.954621335624125), + Offset(38.000014616095385, 25.999897684661754), + Offset(38.0, 25.999999999999993), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.0, 22.0), + Offset(10.000434881903109, 21.996958187115208), + Offset(10.537203766746376, 19.66951300869151), + Offset(15.2007493434278, 12.928722391574958), + Offset(22.726894381864838, 9.915284806391266), + Offset(28.34794602732309, 10.54283219457061), + Offset(32.08037023016842, 12.393638944810997), + Offset(34.49466952610868, 14.52044771427649), + Offset(36.03113891519555, 16.566851514784105), + Offset(36.98867178324178, 18.40585973475647), + Offset(37.56526083167866, 20.0020381982159), + Offset(37.893194841987366, 21.35819435185408), + Offset(38.06150889201586, 22.492031936757623), + Offset(38.13048882144999, 23.426165819354733), + Offset(38.14094176630335, 24.183755168682307), + Offset(38.12034219741291, 24.78481604721129), + Offset(38.086964642108946, 25.247969219160655), + Offset(38.052600274850896, 25.58884408148203), + Offset(38.02444615197159, 25.820689465683056), + Offset(38.00640765629513, 25.954621335624125), + Offset(38.000014616095385, 25.999897684661754), + Offset(38.0, 25.999999999999993), + ], + <Offset>[ + Offset(38.0, 22.0), + Offset(38.00043422098076, 22.003041907302272), + Offset(38.136820741489856, 24.387684566345136), + Offset(35.547238360668324, 32.16463632024782), + Offset(29.165901647620203, 37.16485701278654), + Offset(23.59397879929007, 38.13630598086269), + Offset(19.492625674491244, 37.4046102774286), + Offset(16.57939189493825, 36.038877661605), + Offset(14.531388217272726, 34.50454144206201), + Offset(13.097234362356085, 33.007202753941485), + Offset(12.096778906088034, 31.63631636258276), + Offset(11.402238533172989, 30.426227977976552), + Offset(10.923182521372642, 29.384871830477124), + Offset(10.595404301988683, 28.507417683425455), + Offset(10.373244457117737, 27.783058732629918), + Offset(10.224722997264447, 27.20027240995278), + Offset(10.12708256221043, 26.746299649396278), + Offset(10.064627393328172, 26.40943775873551), + Offset(10.026738643716017, 26.17898303549632), + Offset(10.006554675981915, 26.045357661563475), + Offset(10.000014616843135, 26.00010231523142), + Offset(10.0, 26.0), + ], + <Offset>[ + Offset(38.0, 22.0), + Offset(38.00043422098076, 22.003041907302272), + Offset(38.136820741489856, 24.387684566345136), + Offset(35.547238360668324, 32.16463632024782), + Offset(29.165901647620203, 37.16485701278654), + Offset(23.59397879929007, 38.13630598086269), + Offset(19.492625674491244, 37.4046102774286), + Offset(16.57939189493825, 36.038877661605), + Offset(14.531388217272726, 34.50454144206201), + Offset(13.097234362356085, 33.007202753941485), + Offset(12.096778906088034, 31.63631636258276), + Offset(11.402238533172989, 30.426227977976552), + Offset(10.923182521372642, 29.384871830477124), + Offset(10.595404301988683, 28.507417683425455), + Offset(10.373244457117737, 27.783058732629918), + Offset(10.224722997264447, 27.20027240995278), + Offset(10.12708256221043, 26.746299649396278), + Offset(10.064627393328172, 26.40943775873551), + Offset(10.026738643716017, 26.17898303549632), + Offset(10.006554675981915, 26.045357661563475), + Offset(10.000014616843135, 26.00010231523142), + Offset(10.0, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.0, 22.0), + Offset(38.00043422098076, 22.003041907302272), + Offset(38.136820741489856, 24.387684566345136), + Offset(35.547238360668324, 32.16463632024782), + Offset(29.165901647620203, 37.16485701278654), + Offset(23.59397879929007, 38.13630598086269), + Offset(19.492625674491244, 37.4046102774286), + Offset(16.57939189493825, 36.038877661605), + Offset(14.531388217272726, 34.50454144206201), + Offset(13.097234362356085, 33.007202753941485), + Offset(12.096778906088034, 31.63631636258276), + Offset(11.402238533172989, 30.426227977976552), + Offset(10.923182521372642, 29.384871830477124), + Offset(10.595404301988683, 28.507417683425455), + Offset(10.373244457117737, 27.783058732629918), + Offset(10.224722997264447, 27.20027240995278), + Offset(10.12708256221043, 26.746299649396278), + Offset(10.064627393328172, 26.40943775873551), + Offset(10.026738643716017, 26.17898303549632), + Offset(10.006554675981915, 26.045357661563475), + Offset(10.000014616843135, 26.00010231523142), + Offset(10.0, 26.0), + ], + <Offset>[ + Offset(38.0, 26.0), + Offset(37.99956511809689, 26.003041812884792), + Offset(37.46279623325363, 28.33048699130849), + Offset(32.7992506565722, 35.07127760842504), + Offset(25.273105618135162, 38.08471519360873), + Offset(19.652053972676917, 37.4571678054294), + Offset(15.919629769831586, 35.606361055189005), + Offset(13.50533047389132, 33.479552285723514), + Offset(11.968861084804454, 31.433148485215895), + Offset(11.011328216758224, 29.59414026524353), + Offset(10.43473916832134, 27.9979618017841), + Offset(10.106805158012635, 26.641805648145926), + Offset(9.938491107984142, 25.507968063242377), + Offset(9.86951117855001, 24.573834180645267), + Offset(9.859058233696649, 23.816244831317686), + Offset(9.87965780258709, 23.215183952788717), + Offset(9.913035357891056, 22.752030780839345), + Offset(9.947399725149102, 22.411155918517977), + Offset(9.97555384802841, 22.17931053431695), + Offset(9.993592343704867, 22.045378664375875), + Offset(9.999985383904612, 22.00010231533824), + Offset(10.0, 22.0), + ], + <Offset>[ + Offset(38.0, 26.0), + Offset(37.99956511809689, 26.003041812884792), + Offset(37.46279623325363, 28.33048699130849), + Offset(32.7992506565722, 35.07127760842504), + Offset(25.273105618135162, 38.08471519360873), + Offset(19.652053972676917, 37.4571678054294), + Offset(15.919629769831586, 35.606361055189005), + Offset(13.50533047389132, 33.479552285723514), + Offset(11.968861084804454, 31.433148485215895), + Offset(11.011328216758224, 29.59414026524353), + Offset(10.43473916832134, 27.9979618017841), + Offset(10.106805158012635, 26.641805648145926), + Offset(9.938491107984142, 25.507968063242377), + Offset(9.86951117855001, 24.573834180645267), + Offset(9.859058233696649, 23.816244831317686), + Offset(9.87965780258709, 23.215183952788717), + Offset(9.913035357891056, 22.752030780839345), + Offset(9.947399725149102, 22.411155918517977), + Offset(9.97555384802841, 22.17931053431695), + Offset(9.993592343704867, 22.045378664375875), + Offset(9.999985383904612, 22.00010231533824), + Offset(10.0, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.0, 26.0), + Offset(37.99956511809689, 26.003041812884792), + Offset(37.46279623325363, 28.33048699130849), + Offset(32.7992506565722, 35.07127760842504), + Offset(25.273105618135162, 38.08471519360873), + Offset(19.652053972676917, 37.4571678054294), + Offset(15.919629769831586, 35.606361055189005), + Offset(13.50533047389132, 33.479552285723514), + Offset(11.968861084804454, 31.433148485215895), + Offset(11.011328216758224, 29.59414026524353), + Offset(10.43473916832134, 27.9979618017841), + Offset(10.106805158012635, 26.641805648145926), + Offset(9.938491107984142, 25.507968063242377), + Offset(9.86951117855001, 24.573834180645267), + Offset(9.859058233696649, 23.816244831317686), + Offset(9.87965780258709, 23.215183952788717), + Offset(9.913035357891056, 22.752030780839345), + Offset(9.947399725149102, 22.411155918517977), + Offset(9.97555384802841, 22.17931053431695), + Offset(9.993592343704867, 22.045378664375875), + Offset(9.999985383904612, 22.00010231533824), + Offset(10.0, 22.0), + ], + <Offset>[ + Offset(10.0, 26.0), + Offset(9.999565779019244, 25.996958092697728), + Offset(9.863179258510144, 23.612315433654864), + Offset(12.452761639331678, 15.835363679752177), + Offset(18.834098352379797, 10.835142987213462), + Offset(24.406021200709937, 9.863694019137322), + Offset(28.507374325508763, 10.595389722571399), + Offset(31.42060810506175, 11.961122338395), + Offset(33.46861178272727, 13.495458557937988), + Offset(34.90276563764392, 14.992797246058515), + Offset(35.90322109391197, 16.36368363741724), + Offset(36.59776146682701, 17.573772022023455), + Offset(37.07681747862736, 18.615128169522876), + Offset(37.40459569801132, 19.492582316574545), + Offset(37.626755542882265, 20.216941267370075), + Offset(37.77527700273555, 20.799727590047226), + Offset(37.87291743778957, 21.253700350603722), + Offset(37.93537260667183, 21.590562241264497), + Offset(37.973261356283984, 21.821016964503688), + Offset(37.99344532401808, 21.954642338436525), + Offset(37.99998538315687, 21.999897684768573), + Offset(38.0, 21.999999999999993), + ], + <Offset>[ + Offset(10.0, 26.0), + Offset(9.999565779019244, 25.996958092697728), + Offset(9.863179258510144, 23.612315433654864), + Offset(12.452761639331678, 15.835363679752177), + Offset(18.834098352379797, 10.835142987213462), + Offset(24.406021200709937, 9.863694019137322), + Offset(28.507374325508763, 10.595389722571399), + Offset(31.42060810506175, 11.961122338395), + Offset(33.46861178272727, 13.495458557937988), + Offset(34.90276563764392, 14.992797246058515), + Offset(35.90322109391197, 16.36368363741724), + Offset(36.59776146682701, 17.573772022023455), + Offset(37.07681747862736, 18.615128169522876), + Offset(37.40459569801132, 19.492582316574545), + Offset(37.626755542882265, 20.216941267370075), + Offset(37.77527700273555, 20.799727590047226), + Offset(37.87291743778957, 21.253700350603722), + Offset(37.93537260667183, 21.590562241264497), + Offset(37.973261356283984, 21.821016964503688), + Offset(37.99344532401808, 21.954642338436525), + Offset(37.99998538315687, 21.999897684768573), + Offset(38.0, 21.999999999999993), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(22.0, 10.0), + Offset(22.003041907302272, 9.999565779019244), + Offset(24.387684566345136, 9.863179258510144), + Offset(32.16463632024782, 12.452761639331678), + Offset(37.16485701278654, 18.834098352379797), + Offset(38.13630598086269, 24.406021200709937), + Offset(37.4046102774286, 28.50737432550876), + Offset(36.038877661605, 31.42060810506175), + Offset(34.50454144206201, 33.46861178272727), + Offset(33.007202753941485, 34.90276563764392), + Offset(31.63631636258276, 35.90322109391197), + Offset(30.426227977976545, 36.597761466827016), + Offset(29.384871830477124, 37.07681747862736), + Offset(28.507417683425455, 37.40459569801132), + Offset(27.78305873262992, 37.62675554288226), + Offset(27.20027240995278, 37.77527700273556), + Offset(26.746299649396278, 37.87291743778957), + Offset(26.409437758735507, 37.935372606671834), + Offset(26.178983035496316, 37.973261356283984), + Offset(26.045357661563475, 37.99344532401808), + Offset(26.000102315231423, 37.99998538315686), + Offset(26.000000000000004, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(22.0, 10.0), + Offset(22.003041907302272, 9.999565779019244), + Offset(24.387684566345136, 9.863179258510144), + Offset(32.16463632024782, 12.452761639331678), + Offset(37.16485701278654, 18.834098352379797), + Offset(38.13630598086269, 24.406021200709937), + Offset(37.4046102774286, 28.50737432550876), + Offset(36.038877661605, 31.42060810506175), + Offset(34.50454144206201, 33.46861178272727), + Offset(33.007202753941485, 34.90276563764392), + Offset(31.63631636258276, 35.90322109391197), + Offset(30.426227977976545, 36.597761466827016), + Offset(29.384871830477124, 37.07681747862736), + Offset(28.507417683425455, 37.40459569801132), + Offset(27.78305873262992, 37.62675554288226), + Offset(27.20027240995278, 37.77527700273556), + Offset(26.746299649396278, 37.87291743778957), + Offset(26.409437758735507, 37.935372606671834), + Offset(26.178983035496316, 37.973261356283984), + Offset(26.045357661563475, 37.99344532401808), + Offset(26.000102315231423, 37.99998538315686), + Offset(26.000000000000004, 38.0), + ], + <Offset>[ + Offset(26.0, 10.0), + Offset(26.003041812884792, 10.000434881903109), + Offset(28.33048699130849, 10.537203766746376), + Offset(35.07127760842504, 15.2007493434278), + Offset(38.08471519360873, 22.726894381864838), + Offset(37.4571678054294, 28.34794602732309), + Offset(35.606361055189005, 32.08037023016842), + Offset(33.479552285723514, 34.49466952610868), + Offset(31.433148485215895, 36.03113891519555), + Offset(29.59414026524353, 36.98867178324178), + Offset(27.9979618017841, 37.56526083167866), + Offset(26.641805648145922, 37.893194841987366), + Offset(25.507968063242377, 38.06150889201586), + Offset(24.573834180645267, 38.13048882144999), + Offset(23.81624483131769, 38.14094176630335), + Offset(23.215183952788713, 38.12034219741291), + Offset(22.752030780839345, 38.086964642108946), + Offset(22.411155918517974, 38.0526002748509), + Offset(22.179310534316947, 38.024446151971595), + Offset(22.045378664375875, 38.00640765629513), + Offset(22.000102315338243, 38.000014616095385), + Offset(22.000000000000004, 38.0), + ], + <Offset>[ + Offset(26.0, 10.0), + Offset(26.003041812884792, 10.000434881903109), + Offset(28.33048699130849, 10.537203766746376), + Offset(35.07127760842504, 15.2007493434278), + Offset(38.08471519360873, 22.726894381864838), + Offset(37.4571678054294, 28.34794602732309), + Offset(35.606361055189005, 32.08037023016842), + Offset(33.479552285723514, 34.49466952610868), + Offset(31.433148485215895, 36.03113891519555), + Offset(29.59414026524353, 36.98867178324178), + Offset(27.9979618017841, 37.56526083167866), + Offset(26.641805648145922, 37.893194841987366), + Offset(25.507968063242377, 38.06150889201586), + Offset(24.573834180645267, 38.13048882144999), + Offset(23.81624483131769, 38.14094176630335), + Offset(23.215183952788713, 38.12034219741291), + Offset(22.752030780839345, 38.086964642108946), + Offset(22.411155918517974, 38.0526002748509), + Offset(22.179310534316947, 38.024446151971595), + Offset(22.045378664375875, 38.00640765629513), + Offset(22.000102315338243, 38.000014616095385), + Offset(22.000000000000004, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.0, 10.0), + Offset(26.003041812884792, 10.000434881903109), + Offset(28.33048699130849, 10.537203766746376), + Offset(35.07127760842504, 15.2007493434278), + Offset(38.08471519360873, 22.726894381864838), + Offset(37.4571678054294, 28.34794602732309), + Offset(35.606361055189005, 32.08037023016842), + Offset(33.479552285723514, 34.49466952610868), + Offset(31.433148485215895, 36.03113891519555), + Offset(29.59414026524353, 36.98867178324178), + Offset(27.9979618017841, 37.56526083167866), + Offset(26.641805648145922, 37.893194841987366), + Offset(25.507968063242377, 38.06150889201586), + Offset(24.573834180645267, 38.13048882144999), + Offset(23.81624483131769, 38.14094176630335), + Offset(23.215183952788713, 38.12034219741291), + Offset(22.752030780839345, 38.086964642108946), + Offset(22.411155918517974, 38.0526002748509), + Offset(22.179310534316947, 38.024446151971595), + Offset(22.045378664375875, 38.00640765629513), + Offset(22.000102315338243, 38.000014616095385), + Offset(22.000000000000004, 38.0), + ], + <Offset>[ + Offset(26.0, 38.0), + Offset(25.996958092697728, 38.00043422098076), + Offset(23.612315433654864, 38.136820741489856), + Offset(15.835363679752177, 35.547238360668324), + Offset(10.835142987213462, 29.165901647620203), + Offset(9.863694019137322, 23.59397879929007), + Offset(10.595389722571403, 19.49262567449124), + Offset(11.961122338395, 16.57939189493825), + Offset(13.495458557937988, 14.531388217272726), + Offset(14.992797246058515, 13.097234362356085), + Offset(16.36368363741724, 12.096778906088034), + Offset(17.573772022023455, 11.402238533172993), + Offset(18.615128169522876, 10.923182521372642), + Offset(19.492582316574545, 10.595404301988683), + Offset(20.21694126737008, 10.373244457117734), + Offset(20.79972759004722, 10.22472299726445), + Offset(21.253700350603722, 10.12708256221043), + Offset(21.590562241264493, 10.064627393328175), + Offset(21.821016964503684, 10.02673864371602), + Offset(21.954642338436525, 10.006554675981915), + Offset(21.999897684768577, 10.000014616843131), + Offset(21.999999999999996, 9.999999999999996), + ], + <Offset>[ + Offset(26.0, 38.0), + Offset(25.996958092697728, 38.00043422098076), + Offset(23.612315433654864, 38.136820741489856), + Offset(15.835363679752177, 35.547238360668324), + Offset(10.835142987213462, 29.165901647620203), + Offset(9.863694019137322, 23.59397879929007), + Offset(10.595389722571403, 19.49262567449124), + Offset(11.961122338395, 16.57939189493825), + Offset(13.495458557937988, 14.531388217272726), + Offset(14.992797246058515, 13.097234362356085), + Offset(16.36368363741724, 12.096778906088034), + Offset(17.573772022023455, 11.402238533172993), + Offset(18.615128169522876, 10.923182521372642), + Offset(19.492582316574545, 10.595404301988683), + Offset(20.21694126737008, 10.373244457117734), + Offset(20.79972759004722, 10.22472299726445), + Offset(21.253700350603722, 10.12708256221043), + Offset(21.590562241264493, 10.064627393328175), + Offset(21.821016964503684, 10.02673864371602), + Offset(21.954642338436525, 10.006554675981915), + Offset(21.999897684768577, 10.000014616843131), + Offset(21.999999999999996, 9.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.0, 38.0), + Offset(25.996958092697728, 38.00043422098076), + Offset(23.612315433654864, 38.136820741489856), + Offset(15.835363679752177, 35.547238360668324), + Offset(10.835142987213462, 29.165901647620203), + Offset(9.863694019137322, 23.59397879929007), + Offset(10.595389722571403, 19.49262567449124), + Offset(11.961122338395, 16.57939189493825), + Offset(13.495458557937988, 14.531388217272726), + Offset(14.992797246058515, 13.097234362356085), + Offset(16.36368363741724, 12.096778906088034), + Offset(17.573772022023455, 11.402238533172993), + Offset(18.615128169522876, 10.923182521372642), + Offset(19.492582316574545, 10.595404301988683), + Offset(20.21694126737008, 10.373244457117734), + Offset(20.79972759004722, 10.22472299726445), + Offset(21.253700350603722, 10.12708256221043), + Offset(21.590562241264493, 10.064627393328175), + Offset(21.821016964503684, 10.02673864371602), + Offset(21.954642338436525, 10.006554675981915), + Offset(21.999897684768577, 10.000014616843131), + Offset(21.999999999999996, 9.999999999999996), + ], + <Offset>[ + Offset(22.0, 38.0), + Offset(21.996958187115208, 37.99956511809689), + Offset(19.66951300869151, 37.46279623325363), + Offset(12.928722391574958, 32.7992506565722), + Offset(9.915284806391266, 25.273105618135162), + Offset(10.54283219457061, 19.652053972676917), + Offset(12.393638944811, 15.919629769831582), + Offset(14.52044771427649, 13.50533047389132), + Offset(16.566851514784105, 11.968861084804454), + Offset(18.40585973475647, 11.011328216758224), + Offset(20.0020381982159, 10.43473916832134), + Offset(21.358194351854078, 10.106805158012639), + Offset(22.492031936757623, 9.938491107984142), + Offset(23.426165819354733, 9.86951117855001), + Offset(24.18375516868231, 9.859058233696645), + Offset(24.784816047211287, 9.879657802587094), + Offset(25.247969219160655, 9.913035357891056), + Offset(25.588844081482026, 9.947399725149106), + Offset(25.820689465683053, 9.975553848028413), + Offset(25.954621335624125, 9.993592343704867), + Offset(25.999897684661757, 9.999985383904608), + Offset(25.999999999999996, 9.999999999999996), + ], + <Offset>[ + Offset(22.0, 38.0), + Offset(21.996958187115208, 37.99956511809689), + Offset(19.66951300869151, 37.46279623325363), + Offset(12.928722391574958, 32.7992506565722), + Offset(9.915284806391266, 25.273105618135162), + Offset(10.54283219457061, 19.652053972676917), + Offset(12.393638944811, 15.919629769831582), + Offset(14.52044771427649, 13.50533047389132), + Offset(16.566851514784105, 11.968861084804454), + Offset(18.40585973475647, 11.011328216758224), + Offset(20.0020381982159, 10.43473916832134), + Offset(21.358194351854078, 10.106805158012639), + Offset(22.492031936757623, 9.938491107984142), + Offset(23.426165819354733, 9.86951117855001), + Offset(24.18375516868231, 9.859058233696645), + Offset(24.784816047211287, 9.879657802587094), + Offset(25.247969219160655, 9.913035357891056), + Offset(25.588844081482026, 9.947399725149106), + Offset(25.820689465683053, 9.975553848028413), + Offset(25.954621335624125, 9.993592343704867), + Offset(25.999897684661757, 9.999985383904608), + Offset(25.999999999999996, 9.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(22.0, 38.0), + Offset(21.996958187115208, 37.99956511809689), + Offset(19.66951300869151, 37.46279623325363), + Offset(12.928722391574958, 32.7992506565722), + Offset(9.915284806391266, 25.273105618135162), + Offset(10.54283219457061, 19.652053972676917), + Offset(12.393638944811, 15.919629769831582), + Offset(14.52044771427649, 13.50533047389132), + Offset(16.566851514784105, 11.968861084804454), + Offset(18.40585973475647, 11.011328216758224), + Offset(20.0020381982159, 10.43473916832134), + Offset(21.358194351854078, 10.106805158012639), + Offset(22.492031936757623, 9.938491107984142), + Offset(23.426165819354733, 9.86951117855001), + Offset(24.18375516868231, 9.859058233696645), + Offset(24.784816047211287, 9.879657802587094), + Offset(25.247969219160655, 9.913035357891056), + Offset(25.588844081482026, 9.947399725149106), + Offset(25.820689465683053, 9.975553848028413), + Offset(25.954621335624125, 9.993592343704867), + Offset(25.999897684661757, 9.999985383904608), + Offset(25.999999999999996, 9.999999999999996), + ], + <Offset>[ + Offset(22.0, 10.0), + Offset(22.003041907302272, 9.999565779019244), + Offset(24.387684566345136, 9.863179258510144), + Offset(32.16463632024782, 12.452761639331678), + Offset(37.16485701278654, 18.834098352379797), + Offset(38.13630598086269, 24.406021200709937), + Offset(37.4046102774286, 28.50737432550876), + Offset(36.038877661605, 31.42060810506175), + Offset(34.50454144206201, 33.46861178272727), + Offset(33.007202753941485, 34.90276563764392), + Offset(31.63631636258276, 35.90322109391197), + Offset(30.426227977976545, 36.597761466827016), + Offset(29.384871830477124, 37.07681747862736), + Offset(28.507417683425455, 37.40459569801132), + Offset(27.78305873262992, 37.62675554288226), + Offset(27.20027240995278, 37.77527700273556), + Offset(26.746299649396278, 37.87291743778957), + Offset(26.409437758735507, 37.935372606671834), + Offset(26.178983035496316, 37.973261356283984), + Offset(26.045357661563475, 37.99344532401808), + Offset(26.000102315231423, 37.99998538315686), + Offset(26.000000000000004, 38.0), + ], + <Offset>[ + Offset(22.0, 10.0), + Offset(22.003041907302272, 9.999565779019244), + Offset(24.387684566345136, 9.863179258510144), + Offset(32.16463632024782, 12.452761639331678), + Offset(37.16485701278654, 18.834098352379797), + Offset(38.13630598086269, 24.406021200709937), + Offset(37.4046102774286, 28.50737432550876), + Offset(36.038877661605, 31.42060810506175), + Offset(34.50454144206201, 33.46861178272727), + Offset(33.007202753941485, 34.90276563764392), + Offset(31.63631636258276, 35.90322109391197), + Offset(30.426227977976545, 36.597761466827016), + Offset(29.384871830477124, 37.07681747862736), + Offset(28.507417683425455, 37.40459569801132), + Offset(27.78305873262992, 37.62675554288226), + Offset(27.20027240995278, 37.77527700273556), + Offset(26.746299649396278, 37.87291743778957), + Offset(26.409437758735507, 37.935372606671834), + Offset(26.178983035496316, 37.973261356283984), + Offset(26.045357661563475, 37.99344532401808), + Offset(26.000102315231423, 37.99998538315686), + Offset(26.000000000000004, 38.0), + ], + ), + _PathClose( + ), + ], + ), + ], +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/home_menu.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/home_menu.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..559c45311f4ab6e17f96a31230634052730345ff --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/home_menu.g.dart @@ -0,0 +1,1702 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$home_menu = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.634146341463, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(41.961602748986124, 36.01074618636323), + Offset(41.61012274691143, 36.52041429443682), + Offset(40.73074694162982, 37.67330625857439), + Offset(38.95361640675702, 39.597004636313734), + Offset(35.56126879040947, 42.254157368159426), + Offset(29.45217770721976, 44.90815523939214), + Offset(20.31425476555182, 45.290666483987), + Offset(11.333081294378362, 41.505038353879655), + Offset(5.639760014140567, 35.39204919789558), + Offset(3.1052482171005202, 29.50332128779013), + Offset(2.404116971035613, 24.703586146049652), + Offset(2.598975684223376, 21.02118219738726), + Offset(3.169562607312212, 18.258042555457294), + Offset(3.8457725409130035, 16.209986341924132), + Offset(4.491857018848872, 14.709706425920167), + Offset(5.042760982134354, 13.631765527094924), + Offset(5.471212748718976, 12.884189626374933), + Offset(5.770140143051716, 12.400456609777674), + Offset(5.943251827328922, 12.132774431470317), + Offset(5.999943741061273, 12.046959719775653), + Offset(5.9999999999999964, 12.046875000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(41.961602748986124, 36.01074618636323), + Offset(41.61012274691143, 36.52041429443682), + Offset(40.73074694162982, 37.67330625857439), + Offset(38.95361640675702, 39.597004636313734), + Offset(35.56126879040947, 42.254157368159426), + Offset(29.45217770721976, 44.90815523939214), + Offset(20.31425476555182, 45.290666483987), + Offset(11.333081294378362, 41.505038353879655), + Offset(5.639760014140567, 35.39204919789558), + Offset(3.1052482171005202, 29.50332128779013), + Offset(2.404116971035613, 24.703586146049652), + Offset(2.598975684223376, 21.02118219738726), + Offset(3.169562607312212, 18.258042555457294), + Offset(3.8457725409130035, 16.209986341924132), + Offset(4.491857018848872, 14.709706425920167), + Offset(5.042760982134354, 13.631765527094924), + Offset(5.471212748718976, 12.884189626374933), + Offset(5.770140143051716, 12.400456609777674), + Offset(5.943251827328922, 12.132774431470317), + Offset(5.999943741061273, 12.046959719775653), + Offset(5.9999999999999964, 12.046875000000004), + ], + <Offset>[ + Offset(41.97427088111201, 32.057641484479724), + Offset(41.73604180244445, 32.56929525585058), + Offset(41.121377806968006, 33.73952883824795), + Offset(39.81729775857236, 35.739382079848234), + Offset(37.1732602008072, 38.64463095068733), + Offset(32.08695737071304, 41.96110020250069), + Offset(23.93217304852415, 43.69759882586336), + Offset(15.2830121061518, 41.66392148019527), + Offset(9.234232376942689, 37.03733509970011), + Offset(6.058741440847815, 32.130881951771805), + Offset(4.6970485662914285, 27.923782097401467), + Offset(4.310954600883996, 24.584372545170346), + Offset(4.402665831815483, 22.013925101989418), + Offset(4.698295162721713, 20.070090284168355), + Offset(5.0503340012927325, 18.62318323378621), + Offset(5.38119368862878, 17.57037702974403), + Offset(5.652345022660288, 16.833162703639687), + Offset(5.847293032367528, 16.35282864404965), + Offset(5.962087095621268, 16.085854559458284), + Offset(5.999962347024592, 16.000084719731866), + Offset(5.9999999999999964, 16.000000000000004), + ], + <Offset>[ + Offset(41.97427088111201, 32.057641484479724), + Offset(41.73604180244445, 32.56929525585058), + Offset(41.121377806968006, 33.73952883824795), + Offset(39.81729775857236, 35.739382079848234), + Offset(37.1732602008072, 38.64463095068733), + Offset(32.08695737071304, 41.96110020250069), + Offset(23.93217304852415, 43.69759882586336), + Offset(15.2830121061518, 41.66392148019527), + Offset(9.234232376942689, 37.03733509970011), + Offset(6.058741440847815, 32.130881951771805), + Offset(4.6970485662914285, 27.923782097401467), + Offset(4.310954600883996, 24.584372545170346), + Offset(4.402665831815483, 22.013925101989418), + Offset(4.698295162721713, 20.070090284168355), + Offset(5.0503340012927325, 18.62318323378621), + Offset(5.38119368862878, 17.57037702974403), + Offset(5.652345022660288, 16.833162703639687), + Offset(5.847293032367528, 16.35282864404965), + Offset(5.962087095621268, 16.085854559458284), + Offset(5.999962347024592, 16.000084719731866), + Offset(5.9999999999999964, 16.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(41.97427088111201, 32.057641484479724), + Offset(41.73604180244445, 32.56929525585058), + Offset(41.121377806968006, 33.73952883824795), + Offset(39.81729775857236, 35.739382079848234), + Offset(37.1732602008072, 38.64463095068733), + Offset(32.08695737071304, 41.96110020250069), + Offset(23.93217304852415, 43.69759882586336), + Offset(15.2830121061518, 41.66392148019527), + Offset(9.234232376942689, 37.03733509970011), + Offset(6.058741440847815, 32.130881951771805), + Offset(4.6970485662914285, 27.923782097401467), + Offset(4.310954600883996, 24.584372545170346), + Offset(4.402665831815483, 22.013925101989418), + Offset(4.698295162721713, 20.070090284168355), + Offset(5.0503340012927325, 18.62318323378621), + Offset(5.38119368862878, 17.57037702974403), + Offset(5.652345022660288, 16.833162703639687), + Offset(5.847293032367528, 16.35282864404965), + Offset(5.962087095621268, 16.085854559458284), + Offset(5.999962347024592, 16.000084719731866), + Offset(5.9999999999999964, 16.000000000000004), + ], + <Offset>[ + Offset(5.9744557303626635, 31.942276360297758), + Offset(5.75430953010175, 31.42258575407952), + Offset(5.297570785497186, 30.182163171294633), + Offset(4.687011710760039, 27.874078385846133), + Offset(4.3023160669901515, 23.964677553231365), + Offset(5.248954188903129, 17.96690121163705), + Offset(9.424552952409986, 10.750232327965165), + Offset(16.729916149753336, 5.693010055981826), + Offset(24.217389364126984, 4.303484017106875), + Offset(29.987199029044564, 5.234248009029647), + Offset(34.02246940389847, 7.042697530328738), + Offset(36.75992915144614, 8.993860987913147), + Offset(38.606434160708815, 10.7844000851691), + Offset(39.851178494463575, 12.30640601283526), + Offset(40.68926904209655, 13.537290081412095), + Offset(41.24902334121195, 14.488365346885672), + Offset(41.61453462747447, 15.183641916442898), + Offset(41.840435984789025, 15.650218932651905), + Offset(41.96167845880022, 15.914327056906625), + Offset(41.99996234662585, 15.999915280445354), + Offset(42.0, 15.999999999999996), + ], + <Offset>[ + Offset(5.9744557303626635, 31.942276360297758), + Offset(5.75430953010175, 31.42258575407952), + Offset(5.297570785497186, 30.182163171294633), + Offset(4.687011710760039, 27.874078385846133), + Offset(4.3023160669901515, 23.964677553231365), + Offset(5.248954188903129, 17.96690121163705), + Offset(9.424552952409986, 10.750232327965165), + Offset(16.729916149753336, 5.693010055981826), + Offset(24.217389364126984, 4.303484017106875), + Offset(29.987199029044564, 5.234248009029647), + Offset(34.02246940389847, 7.042697530328738), + Offset(36.75992915144614, 8.993860987913147), + Offset(38.606434160708815, 10.7844000851691), + Offset(39.851178494463575, 12.30640601283526), + Offset(40.68926904209655, 13.537290081412095), + Offset(41.24902334121195, 14.488365346885672), + Offset(41.61453462747447, 15.183641916442898), + Offset(41.840435984789025, 15.650218932651905), + Offset(41.96167845880022, 15.914327056906625), + Offset(41.99996234662585, 15.999915280445354), + Offset(42.0, 15.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(5.9744557303626635, 31.942276360297758), + Offset(5.75430953010175, 31.42258575407952), + Offset(5.297570785497186, 30.182163171294633), + Offset(4.687011710760039, 27.874078385846133), + Offset(4.3023160669901515, 23.964677553231365), + Offset(5.248954188903129, 17.96690121163705), + Offset(9.424552952409986, 10.750232327965165), + Offset(16.729916149753336, 5.693010055981826), + Offset(24.217389364126984, 4.303484017106875), + Offset(29.987199029044564, 5.234248009029647), + Offset(34.02246940389847, 7.042697530328738), + Offset(36.75992915144614, 8.993860987913147), + Offset(38.606434160708815, 10.7844000851691), + Offset(39.851178494463575, 12.30640601283526), + Offset(40.68926904209655, 13.537290081412095), + Offset(41.24902334121195, 14.488365346885672), + Offset(41.61453462747447, 15.183641916442898), + Offset(41.840435984789025, 15.650218932651905), + Offset(41.96167845880022, 15.914327056906625), + Offset(41.99996234662585, 15.999915280445354), + Offset(42.0, 15.999999999999996), + ], + <Offset>[ + Offset(5.96181263407102, 35.88756860229611), + Offset(5.628639326457137, 35.36589625701638), + Offset(4.907711917916583, 34.10816632794454), + Offset(3.825037239086633, 31.72407718231862), + Offset(2.6935104103679173, 27.567070519285533), + Offset(2.6193815998436385, 20.90813202908801), + Offset(5.813784705570013, 12.34015163103323), + Offset(12.787791525354942, 5.534440927939556), + Offset(20.630020701646604, 2.66144966846797), + Offset(27.039542748427206, 2.6118801526843), + Offset(31.73406929400877, 3.8288656025961956), + Offset(35.05133359232832, 5.4377125182877375), + Offset(37.37576789909982, 7.035940231416685), + Offset(39.00034069997069, 8.453930734508514), + Offset(40.13189576910416, 9.631547417435115), + Offset(40.91125947405842, 10.557537661435477), + Offset(41.43376032245399, 11.242473133797246), + Offset(41.76343557153906, 11.705657910305364), + Offset(41.94288041435826, 11.969059340238793), + Offset(41.9999437774332, 12.054602780489052), + Offset(42.0, 12.054687499999996), + ], + <Offset>[ + Offset(5.96181263407102, 35.88756860229611), + Offset(5.628639326457137, 35.36589625701638), + Offset(4.907711917916583, 34.10816632794454), + Offset(3.825037239086633, 31.72407718231862), + Offset(2.6935104103679173, 27.567070519285533), + Offset(2.6193815998436385, 20.90813202908801), + Offset(5.813784705570013, 12.34015163103323), + Offset(12.787791525354942, 5.534440927939556), + Offset(20.630020701646604, 2.66144966846797), + Offset(27.039542748427206, 2.6118801526843), + Offset(31.73406929400877, 3.8288656025961956), + Offset(35.05133359232832, 5.4377125182877375), + Offset(37.37576789909982, 7.035940231416685), + Offset(39.00034069997069, 8.453930734508514), + Offset(40.13189576910416, 9.631547417435115), + Offset(40.91125947405842, 10.557537661435477), + Offset(41.43376032245399, 11.242473133797246), + Offset(41.76343557153906, 11.705657910305364), + Offset(41.94288041435826, 11.969059340238793), + Offset(41.9999437774332, 12.054602780489052), + Offset(42.0, 12.054687499999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(5.96181263407102, 35.88756860229611), + Offset(5.628639326457137, 35.36589625701638), + Offset(4.907711917916583, 34.10816632794454), + Offset(3.825037239086633, 31.72407718231862), + Offset(2.6935104103679173, 27.567070519285533), + Offset(2.6193815998436385, 20.90813202908801), + Offset(5.813784705570013, 12.34015163103323), + Offset(12.787791525354942, 5.534440927939556), + Offset(20.630020701646604, 2.66144966846797), + Offset(27.039542748427206, 2.6118801526843), + Offset(31.73406929400877, 3.8288656025961956), + Offset(35.05133359232832, 5.4377125182877375), + Offset(37.37576789909982, 7.035940231416685), + Offset(39.00034069997069, 8.453930734508514), + Offset(40.13189576910416, 9.631547417435115), + Offset(40.91125947405842, 10.557537661435477), + Offset(41.43376032245399, 11.242473133797246), + Offset(41.76343557153906, 11.705657910305364), + Offset(41.94288041435826, 11.969059340238793), + Offset(41.9999437774332, 12.054602780489052), + Offset(42.0, 12.054687499999996), + ], + <Offset>[ + Offset(41.961602748986124, 36.01074618636323), + Offset(41.61012274691143, 36.52041429443682), + Offset(40.73074694162982, 37.67330625857439), + Offset(38.95361640675702, 39.597004636313734), + Offset(35.56126879040947, 42.254157368159426), + Offset(29.45217770721976, 44.90815523939214), + Offset(20.31425476555182, 45.290666483987), + Offset(11.333081294378362, 41.505038353879655), + Offset(5.639760014140567, 35.39204919789558), + Offset(3.1052482171005202, 29.50332128779013), + Offset(2.404116971035613, 24.703586146049652), + Offset(2.598975684223376, 21.02118219738726), + Offset(3.169562607312212, 18.258042555457294), + Offset(3.8457725409130035, 16.209986341924132), + Offset(4.491857018848872, 14.709706425920167), + Offset(5.042760982134354, 13.631765527094924), + Offset(5.471212748718976, 12.884189626374933), + Offset(5.770140143051716, 12.400456609777674), + Offset(5.943251827328922, 12.132774431470317), + Offset(5.999943741061273, 12.046959719775653), + Offset(5.9999999999999964, 12.046875000000004), + ], + <Offset>[ + Offset(41.961602748986124, 36.01074618636323), + Offset(41.61012274691143, 36.52041429443682), + Offset(40.73074694162982, 37.67330625857439), + Offset(38.95361640675702, 39.597004636313734), + Offset(35.56126879040947, 42.254157368159426), + Offset(29.45217770721976, 44.90815523939214), + Offset(20.31425476555182, 45.290666483987), + Offset(11.333081294378362, 41.505038353879655), + Offset(5.639760014140567, 35.39204919789558), + Offset(3.1052482171005202, 29.50332128779013), + Offset(2.404116971035613, 24.703586146049652), + Offset(2.598975684223376, 21.02118219738726), + Offset(3.169562607312212, 18.258042555457294), + Offset(3.8457725409130035, 16.209986341924132), + Offset(4.491857018848872, 14.709706425920167), + Offset(5.042760982134354, 13.631765527094924), + Offset(5.471212748718976, 12.884189626374933), + Offset(5.770140143051716, 12.400456609777674), + Offset(5.943251827328922, 12.132774431470317), + Offset(5.999943741061273, 12.046959719775653), + Offset(5.9999999999999964, 12.046875000000004), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(38.005915505011714, 22.044873132716152), + Offset(38.49527667048537, 22.460937675484836), + Offset(39.29605291379161, 23.509087727219047), + Offset(40.090934628235715, 25.55307837508503), + Offset(40.245484311889584, 29.064745081245363), + Offset(38.450753318138695, 34.23676198345152), + Offset(33.0728907045072, 39.641976680762035), + Offset(25.27493194621109, 42.06583927008458), + Offset(18.326968788774145, 41.199323151695744), + Offset(13.530028647165079, 38.7776757262709), + Offset(10.497349834922744, 36.06973233007009), + Offset(8.641652255677663, 33.59797658699316), + Offset(7.521978336487795, 31.514971860015343), + Offset(6.854874126980906, 29.834780098541096), + Offset(6.463082099174432, 28.52288741178727), + Offset(6.237308044978324, 27.533663044350465), + Offset(6.1105452413260615, 26.82265981608807), + Offset(6.04246239664468, 26.35092390861118), + Offset(6.009733624107838, 26.085741049230215), + Offset(6.000009413493068, 26.000084719621103), + Offset(6.0, 26.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.005915505011714, 22.044873132716152), + Offset(38.49527667048537, 22.460937675484836), + Offset(39.29605291379161, 23.509087727219047), + Offset(40.090934628235715, 25.55307837508503), + Offset(40.245484311889584, 29.064745081245363), + Offset(38.450753318138695, 34.23676198345152), + Offset(33.0728907045072, 39.641976680762035), + Offset(25.27493194621109, 42.06583927008458), + Offset(18.326968788774145, 41.199323151695744), + Offset(13.530028647165079, 38.7776757262709), + Offset(10.497349834922744, 36.06973233007009), + Offset(8.641652255677663, 33.59797658699316), + Offset(7.521978336487795, 31.514971860015343), + Offset(6.854874126980906, 29.834780098541096), + Offset(6.463082099174432, 28.52288741178727), + Offset(6.237308044978324, 27.533663044350465), + Offset(6.1105452413260615, 26.82265981608807), + Offset(6.04246239664468, 26.35092390861118), + Offset(6.009733624107838, 26.085741049230215), + Offset(6.000009413493068, 26.000084719621103), + Offset(6.0, 26.000000000000004), + ], + <Offset>[ + Offset(10.006902842119626, 21.955147406089473), + Offset(9.632135496378087, 21.541092072032644), + Offset(9.099209938092097, 20.510489270395304), + Offset(8.782988004431196, 18.54355650849138), + Offset(9.385621621161075, 15.282927792774965), + Offset(12.215268791957268, 10.781237663014041), + Offset(18.587927795299567, 6.746065530872357), + Offset(26.721835989812625, 6.094927845871137), + Offset(33.31012577595844, 8.46547206910251), + Offset(37.45848623536183, 11.881041783528742), + Offset(39.822770672529785, 15.188647762997359), + Offset(41.090626806239804, 18.007465029735965), + Offset(41.72574666538112, 20.285446843195025), + Offset(42.007757458722764, 22.071095827208), + Offset(42.102017139978244, 23.436994259413154), + Offset(42.10513769756149, 24.451651361492107), + Offset(42.07273484614025, 25.17313902889128), + Offset(42.03560534906618, 25.64831419721343), + Offset(42.00932498728679, 25.914213546678557), + Offset(42.000009413094325, 25.99991528033459), + Offset(42.0, 25.999999999999996), + ], + <Offset>[ + Offset(10.006902842119626, 21.955147406089473), + Offset(9.632135496378087, 21.541092072032644), + Offset(9.099209938092097, 20.510489270395304), + Offset(8.782988004431196, 18.54355650849138), + Offset(9.385621621161075, 15.282927792774965), + Offset(12.215268791957268, 10.781237663014041), + Offset(18.587927795299567, 6.746065530872357), + Offset(26.721835989812625, 6.094927845871137), + Offset(33.31012577595844, 8.46547206910251), + Offset(37.45848623536183, 11.881041783528742), + Offset(39.822770672529785, 15.188647762997359), + Offset(41.090626806239804, 18.007465029735965), + Offset(41.72574666538112, 20.285446843195025), + Offset(42.007757458722764, 22.071095827208), + Offset(42.102017139978244, 23.436994259413154), + Offset(42.10513769756149, 24.451651361492107), + Offset(42.07273484614025, 25.17313902889128), + Offset(42.03560534906618, 25.64831419721343), + Offset(42.00932498728679, 25.914213546678557), + Offset(42.000009413094325, 25.99991528033459), + Offset(42.0, 25.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.006902842119626, 21.955147406089473), + Offset(9.632135496378087, 21.541092072032644), + Offset(9.099209938092097, 20.510489270395304), + Offset(8.782988004431196, 18.54355650849138), + Offset(9.385621621161075, 15.282927792774965), + Offset(12.215268791957268, 10.781237663014041), + Offset(18.587927795299567, 6.746065530872357), + Offset(26.721835989812625, 6.094927845871137), + Offset(33.31012577595844, 8.46547206910251), + Offset(37.45848623536183, 11.881041783528742), + Offset(39.822770672529785, 15.188647762997359), + Offset(41.090626806239804, 18.007465029735965), + Offset(41.72574666538112, 20.285446843195025), + Offset(42.007757458722764, 22.071095827208), + Offset(42.102017139978244, 23.436994259413154), + Offset(42.10513769756149, 24.451651361492107), + Offset(42.07273484614025, 25.17313902889128), + Offset(42.03560534906618, 25.64831419721343), + Offset(42.00932498728679, 25.914213546678557), + Offset(42.000009413094325, 25.99991528033459), + Offset(42.0, 25.999999999999996), + ], + <Offset>[ + Offset(9.991126102962665, 26.878296385119686), + Offset(9.478546725862362, 26.36043822046848), + Offset(8.639473946578361, 25.14017735498227), + Offset(7.81032131475563, 22.887960789223563), + Offset(7.650884598609569, 19.167302777578165), + Offset(9.48709191219624, 13.832759399890797), + Offset(14.921172139995065, 8.360637610125773), + Offset(22.72506805378891, 5.934160729915408), + Offset(29.673031211225855, 6.800676848304256), + Offset(34.46997135283492, 9.222324273729102), + Offset(37.502650165077256, 11.930267669929911), + Offset(39.35834774432234, 14.402023413006837), + Offset(40.47802166351221, 16.485028139984657), + Offset(41.1451258730191, 18.165219901458904), + Offset(41.53691790082557, 19.47711258821273), + Offset(41.76269195502168, 20.466336955649535), + Offset(41.889454758673935, 21.17734018391193), + Offset(41.95753760335532, 21.64907609138882), + Offset(41.99026637589216, 21.914258950769785), + Offset(41.99999058650693, 21.999915280378897), + Offset(42.0, 21.999999999999996), + ], + <Offset>[ + Offset(9.991126102962665, 26.878296385119686), + Offset(9.478546725862362, 26.36043822046848), + Offset(8.639473946578361, 25.14017735498227), + Offset(7.81032131475563, 22.887960789223563), + Offset(7.650884598609569, 19.167302777578165), + Offset(9.48709191219624, 13.832759399890797), + Offset(14.921172139995065, 8.360637610125773), + Offset(22.72506805378891, 5.934160729915408), + Offset(29.673031211225855, 6.800676848304256), + Offset(34.46997135283492, 9.222324273729102), + Offset(37.502650165077256, 11.930267669929911), + Offset(39.35834774432234, 14.402023413006837), + Offset(40.47802166351221, 16.485028139984657), + Offset(41.1451258730191, 18.165219901458904), + Offset(41.53691790082557, 19.47711258821273), + Offset(41.76269195502168, 20.466336955649535), + Offset(41.889454758673935, 21.17734018391193), + Offset(41.95753760335532, 21.64907609138882), + Offset(41.99026637589216, 21.914258950769785), + Offset(41.99999058650693, 21.999915280378897), + Offset(42.0, 21.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(9.991126102962665, 26.878296385119686), + Offset(9.478546725862362, 26.36043822046848), + Offset(8.639473946578361, 25.14017735498227), + Offset(7.81032131475563, 22.887960789223563), + Offset(7.650884598609569, 19.167302777578165), + Offset(9.48709191219624, 13.832759399890797), + Offset(14.921172139995065, 8.360637610125773), + Offset(22.72506805378891, 5.934160729915408), + Offset(29.673031211225855, 6.800676848304256), + Offset(34.46997135283492, 9.222324273729102), + Offset(37.502650165077256, 11.930267669929911), + Offset(39.35834774432234, 14.402023413006837), + Offset(40.47802166351221, 16.485028139984657), + Offset(41.1451258730191, 18.165219901458904), + Offset(41.53691790082557, 19.47711258821273), + Offset(41.76269195502168, 20.466336955649535), + Offset(41.889454758673935, 21.17734018391193), + Offset(41.95753760335532, 21.64907609138882), + Offset(41.99026637589216, 21.914258950769785), + Offset(41.99999058650693, 21.999915280378897), + Offset(42.0, 21.999999999999996), + ], + <Offset>[ + Offset(37.99013876585475, 26.968022111746365), + Offset(38.34168789996964, 27.280283823920673), + Offset(38.83631692227788, 28.138775811806013), + Offset(39.118267938560145, 29.897482655817214), + Offset(38.51074728933807, 32.949120066048565), + Offset(35.722576438377665, 37.28828372032828), + Offset(29.406135049202696, 41.25654876001545), + Offset(21.278164010187375, 41.90507215412886), + Offset(14.689874224041562, 39.53452793089749), + Offset(10.541513764638172, 36.118958216471256), + Offset(8.177229327470219, 32.81135223700264), + Offset(6.909373193760196, 29.992534970264035), + Offset(6.274253334618873, 27.714553156804975), + Offset(5.992242541277232, 25.928904172792), + Offset(5.897982860021752, 24.563005740586846), + Offset(5.894862302438508, 23.548348638507893), + Offset(5.927265153859754, 22.82686097110872), + Offset(5.964394650933819, 22.35168580278657), + Offset(5.990675012713211, 22.085786453321443), + Offset(5.999990586905675, 22.00008471966541), + Offset(6.0, 22.000000000000004), + ], + <Offset>[ + Offset(37.99013876585475, 26.968022111746365), + Offset(38.34168789996964, 27.280283823920673), + Offset(38.83631692227788, 28.138775811806013), + Offset(39.118267938560145, 29.897482655817214), + Offset(38.51074728933807, 32.949120066048565), + Offset(35.722576438377665, 37.28828372032828), + Offset(29.406135049202696, 41.25654876001545), + Offset(21.278164010187375, 41.90507215412886), + Offset(14.689874224041562, 39.53452793089749), + Offset(10.541513764638172, 36.118958216471256), + Offset(8.177229327470219, 32.81135223700264), + Offset(6.909373193760196, 29.992534970264035), + Offset(6.274253334618873, 27.714553156804975), + Offset(5.992242541277232, 25.928904172792), + Offset(5.897982860021752, 24.563005740586846), + Offset(5.894862302438508, 23.548348638507893), + Offset(5.927265153859754, 22.82686097110872), + Offset(5.964394650933819, 22.35168580278657), + Offset(5.990675012713211, 22.085786453321443), + Offset(5.999990586905675, 22.00008471966541), + Offset(6.0, 22.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(37.99013876585475, 26.968022111746365), + Offset(38.34168789996964, 27.280283823920673), + Offset(38.83631692227788, 28.138775811806013), + Offset(39.118267938560145, 29.897482655817214), + Offset(38.51074728933807, 32.949120066048565), + Offset(35.722576438377665, 37.28828372032828), + Offset(29.406135049202696, 41.25654876001545), + Offset(21.278164010187375, 41.90507215412886), + Offset(14.689874224041562, 39.53452793089749), + Offset(10.541513764638172, 36.118958216471256), + Offset(8.177229327470219, 32.81135223700264), + Offset(6.909373193760196, 29.992534970264035), + Offset(6.274253334618873, 27.714553156804975), + Offset(5.992242541277232, 25.928904172792), + Offset(5.897982860021752, 24.563005740586846), + Offset(5.894862302438508, 23.548348638507893), + Offset(5.927265153859754, 22.82686097110872), + Offset(5.964394650933819, 22.35168580278657), + Offset(5.990675012713211, 22.085786453321443), + Offset(5.999990586905675, 22.00008471966541), + Offset(6.0, 22.000000000000004), + ], + <Offset>[ + Offset(38.005915505011714, 22.044873132716152), + Offset(38.49527667048537, 22.460937675484836), + Offset(39.29605291379161, 23.509087727219047), + Offset(40.090934628235715, 25.55307837508503), + Offset(40.245484311889584, 29.064745081245363), + Offset(38.450753318138695, 34.23676198345152), + Offset(33.0728907045072, 39.641976680762035), + Offset(25.27493194621109, 42.06583927008458), + Offset(18.326968788774145, 41.199323151695744), + Offset(13.530028647165079, 38.7776757262709), + Offset(10.497349834922744, 36.06973233007009), + Offset(8.641652255677663, 33.59797658699316), + Offset(7.521978336487795, 31.514971860015343), + Offset(6.854874126980906, 29.834780098541096), + Offset(6.463082099174432, 28.52288741178727), + Offset(6.237308044978324, 27.533663044350465), + Offset(6.1105452413260615, 26.82265981608807), + Offset(6.04246239664468, 26.35092390861118), + Offset(6.009733624107838, 26.085741049230215), + Offset(6.000009413493068, 26.000084719621103), + Offset(6.0, 26.000000000000004), + ], + <Offset>[ + Offset(38.005915505011714, 22.044873132716152), + Offset(38.49527667048537, 22.460937675484836), + Offset(39.29605291379161, 23.509087727219047), + Offset(40.090934628235715, 25.55307837508503), + Offset(40.245484311889584, 29.064745081245363), + Offset(38.450753318138695, 34.23676198345152), + Offset(33.0728907045072, 39.641976680762035), + Offset(25.27493194621109, 42.06583927008458), + Offset(18.326968788774145, 41.199323151695744), + Offset(13.530028647165079, 38.7776757262709), + Offset(10.497349834922744, 36.06973233007009), + Offset(8.641652255677663, 33.59797658699316), + Offset(7.521978336487795, 31.514971860015343), + Offset(6.854874126980906, 29.834780098541096), + Offset(6.463082099174432, 28.52288741178727), + Offset(6.237308044978324, 27.533663044350465), + Offset(6.1105452413260615, 26.82265981608807), + Offset(6.04246239664468, 26.35092390861118), + Offset(6.009733624107838, 26.085741049230215), + Offset(6.000009413493068, 26.000084719621103), + Offset(6.0, 26.000000000000004), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(20.176179763180997, 21.987735903833876), + Offset(20.55193618727129, 21.88909752977205), + Offset(21.227655124257208, 21.71486474263169), + Offset(22.13567600845661, 21.53308372554798), + Offset(23.226514419921436, 21.464181986077985), + Offset(24.4102783754196, 21.684041595886637), + Offset(25.440842849032627, 22.309300738195095), + Offset(26.03642252837242, 23.134721894037483), + Offset(26.21244881576038, 23.97183703919535), + Offset(26.123327546035636, 24.622256415770117), + Offset(25.931014482213666, 25.0802342265462), + Offset(25.71921080582189, 25.392852152910002), + Offset(25.5230666408985, 25.604989383797584), + Offset(25.3554718074648, 25.748833638139686), + Offset(25.21948374988762, 25.846234627148135), + Offset(25.114174554400172, 25.911632280813432), + Offset(25.037072414338468, 25.95453414453137), + Offset(24.98527999526863, 25.9811477091939), + Offset(24.955944954391757, 25.995467904751596), + Offset(24.946435804885212, 25.999995545483056), + Offset(24.946426391602, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(20.176179763180997, 21.987735903833876), + Offset(20.55193618727129, 21.88909752977205), + Offset(21.227655124257208, 21.71486474263169), + Offset(22.13567600845661, 21.53308372554798), + Offset(23.226514419921436, 21.464181986077985), + Offset(24.4102783754196, 21.684041595886637), + Offset(25.440842849032627, 22.309300738195095), + Offset(26.03642252837242, 23.134721894037483), + Offset(26.21244881576038, 23.97183703919535), + Offset(26.123327546035636, 24.622256415770117), + Offset(25.931014482213666, 25.0802342265462), + Offset(25.71921080582189, 25.392852152910002), + Offset(25.5230666408985, 25.604989383797584), + Offset(25.3554718074648, 25.748833638139686), + Offset(25.21948374988762, 25.846234627148135), + Offset(25.114174554400172, 25.911632280813432), + Offset(25.037072414338468, 25.95453414453137), + Offset(24.98527999526863, 25.9811477091939), + Offset(24.955944954391757, 25.995467904751596), + Offset(24.946435804885212, 25.999995545483056), + Offset(24.946426391602, 26.0), + ], + <Offset>[ + Offset(10.006902842149625, 21.95514740608957), + Offset(9.632135496348102, 21.541092072031688), + Offset(9.099209938111999, 20.510489270397283), + Offset(8.78298800447023, 18.543556508500117), + Offset(9.385621621133684, 15.282927792762731), + Offset(12.215268791942359, 10.781237663000711), + Offset(18.58792779526773, 6.746065530800053), + Offset(26.721835989812707, 6.094927845869137), + Offset(33.31012577595927, 8.465472069100691), + Offset(37.458486235363154, 11.881041783527248), + Offset(39.82277067253141, 15.1886477629962), + Offset(41.09062680624161, 18.007465029735098), + Offset(41.72574666538303, 20.2854468431944), + Offset(42.007757458724726, 22.07109582720757), + Offset(42.10201713998023, 23.43699425941287), + Offset(42.105137697563485, 24.451651361491937), + Offset(42.07273484614225, 25.173139028891192), + Offset(42.03560534906818, 25.64831419721339), + Offset(42.00932498728879, 25.91421354667855), + Offset(42.00000941309632, 25.99991528033459), + Offset(42.000000000002004, 25.999999999999996), + ], + <Offset>[ + Offset(10.006902842149625, 21.95514740608957), + Offset(9.632135496348102, 21.541092072031688), + Offset(9.099209938111999, 20.510489270397283), + Offset(8.78298800447023, 18.543556508500117), + Offset(9.385621621133684, 15.282927792762731), + Offset(12.215268791942359, 10.781237663000711), + Offset(18.58792779526773, 6.746065530800053), + Offset(26.721835989812707, 6.094927845869137), + Offset(33.31012577595927, 8.465472069100691), + Offset(37.458486235363154, 11.881041783527248), + Offset(39.82277067253141, 15.1886477629962), + Offset(41.09062680624161, 18.007465029735098), + Offset(41.72574666538303, 20.2854468431944), + Offset(42.007757458724726, 22.07109582720757), + Offset(42.10201713998023, 23.43699425941287), + Offset(42.105137697563485, 24.451651361491937), + Offset(42.07273484614225, 25.173139028891192), + Offset(42.03560534906818, 25.64831419721339), + Offset(42.00932498728879, 25.91421354667855), + Offset(42.00000941309632, 25.99991528033459), + Offset(42.000000000002004, 25.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.006902842149625, 21.95514740608957), + Offset(9.632135496348102, 21.541092072031688), + Offset(9.099209938111999, 20.510489270397283), + Offset(8.78298800447023, 18.543556508500117), + Offset(9.385621621133684, 15.282927792762731), + Offset(12.215268791942359, 10.781237663000711), + Offset(18.58792779526773, 6.746065530800053), + Offset(26.721835989812707, 6.094927845869137), + Offset(33.31012577595927, 8.465472069100691), + Offset(37.458486235363154, 11.881041783527248), + Offset(39.82277067253141, 15.1886477629962), + Offset(41.09062680624161, 18.007465029735098), + Offset(41.72574666538303, 20.2854468431944), + Offset(42.007757458724726, 22.07109582720757), + Offset(42.10201713998023, 23.43699425941287), + Offset(42.105137697563485, 24.451651361491937), + Offset(42.07273484614225, 25.173139028891192), + Offset(42.03560534906818, 25.64831419721339), + Offset(42.00932498728879, 25.91421354667855), + Offset(42.00000941309632, 25.99991528033459), + Offset(42.000000000002004, 25.999999999999996), + ], + <Offset>[ + Offset(9.950103066904006, 39.679580365751406), + Offset(9.115564488520917, 37.75018397768418), + Offset(7.7454464103988485, 34.143319828138715), + Offset(6.441070390954248, 29.003703867586243), + Offset(6.213866824197122, 22.385033086525855), + Offset(8.625212439492824, 14.796789248890494), + Offset(14.838843583186215, 8.396889109087798), + Offset(22.72506805378899, 5.934160729913408), + Offset(29.67303121122669, 6.800676848302437), + Offset(34.469971352836254, 9.222324273727608), + Offset(37.50265016507888, 11.930267669928751), + Offset(39.35834774432414, 14.40202341300597), + Offset(40.478021663514106, 16.48502813998403), + Offset(41.145125873021044, 18.165219901458475), + Offset(41.53691790082755, 19.47711258821245), + Offset(41.76269195502367, 20.46633695564936), + Offset(41.88945475867594, 21.177340183911838), + Offset(41.95753760335732, 21.649076091388782), + Offset(41.990266375894166, 21.914258950769778), + Offset(41.99999058650893, 21.999915280378897), + Offset(42.000000000002004, 21.999999999999996), + ], + <Offset>[ + Offset(9.950103066904006, 39.679580365751406), + Offset(9.115564488520917, 37.75018397768418), + Offset(7.7454464103988485, 34.143319828138715), + Offset(6.441070390954248, 29.003703867586243), + Offset(6.213866824197122, 22.385033086525855), + Offset(8.625212439492824, 14.796789248890494), + Offset(14.838843583186215, 8.396889109087798), + Offset(22.72506805378899, 5.934160729913408), + Offset(29.67303121122669, 6.800676848302437), + Offset(34.469971352836254, 9.222324273727608), + Offset(37.50265016507888, 11.930267669928751), + Offset(39.35834774432414, 14.40202341300597), + Offset(40.478021663514106, 16.48502813998403), + Offset(41.145125873021044, 18.165219901458475), + Offset(41.53691790082755, 19.47711258821245), + Offset(41.76269195502367, 20.46633695564936), + Offset(41.88945475867594, 21.177340183911838), + Offset(41.95753760335732, 21.649076091388782), + Offset(41.990266375894166, 21.914258950769778), + Offset(41.99999058650893, 21.999915280378897), + Offset(42.000000000002004, 21.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(9.950103066904006, 39.679580365751406), + Offset(9.115564488520917, 37.75018397768418), + Offset(7.7454464103988485, 34.143319828138715), + Offset(6.441070390954248, 29.003703867586243), + Offset(6.213866824197122, 22.385033086525855), + Offset(8.625212439492824, 14.796789248890494), + Offset(14.838843583186215, 8.396889109087798), + Offset(22.72506805378899, 5.934160729913408), + Offset(29.67303121122669, 6.800676848302437), + Offset(34.469971352836254, 9.222324273727608), + Offset(37.50265016507888, 11.930267669928751), + Offset(39.35834774432414, 14.40202341300597), + Offset(40.478021663514106, 16.48502813998403), + Offset(41.145125873021044, 18.165219901458475), + Offset(41.53691790082755, 19.47711258821245), + Offset(41.76269195502367, 20.46633695564936), + Offset(41.88945475867594, 21.177340183911838), + Offset(41.95753760335732, 21.649076091388782), + Offset(41.990266375894166, 21.914258950769778), + Offset(41.99999058650893, 21.999915280378897), + Offset(42.000000000002004, 21.999999999999996), + ], + <Offset>[ + Offset(20.119379987935375, 39.71216886349571), + Offset(20.035365179444106, 38.098189435424544), + Offset(19.873891596544055, 35.347695300373125), + Offset(19.793758394940628, 31.993231084634104), + Offset(20.054759622984875, 28.566287279841106), + Offset(20.820222022970064, 25.699593181776418), + Offset(21.69175863695111, 23.96012431648284), + Offset(22.0396545923487, 22.973954778081758), + Offset(22.575354251027797, 22.307041818397096), + Offset(23.13481266350873, 21.963538905970477), + Offset(23.61089397476114, 21.82185413347875), + Offset(23.986931743904425, 21.787410536180875), + Offset(24.275341639029573, 21.804570680587215), + Offset(24.49284022176112, 21.842957712390593), + Offset(24.65438451073494, 21.88635295594771), + Offset(24.771728811860356, 21.926317874970856), + Offset(24.853792326872156, 21.958735299552014), + Offset(24.90721224955777, 21.981909603369285), + Offset(24.93688634299713, 21.995513308842824), + Offset(24.946416978297822, 21.99999554552736), + Offset(24.946426391602, 22.0), + ], + <Offset>[ + Offset(20.119379987935375, 39.71216886349571), + Offset(20.035365179444106, 38.098189435424544), + Offset(19.873891596544055, 35.347695300373125), + Offset(19.793758394940628, 31.993231084634104), + Offset(20.054759622984875, 28.566287279841106), + Offset(20.820222022970064, 25.699593181776418), + Offset(21.69175863695111, 23.96012431648284), + Offset(22.0396545923487, 22.973954778081758), + Offset(22.575354251027797, 22.307041818397096), + Offset(23.13481266350873, 21.963538905970477), + Offset(23.61089397476114, 21.82185413347875), + Offset(23.986931743904425, 21.787410536180875), + Offset(24.275341639029573, 21.804570680587215), + Offset(24.49284022176112, 21.842957712390593), + Offset(24.65438451073494, 21.88635295594771), + Offset(24.771728811860356, 21.926317874970856), + Offset(24.853792326872156, 21.958735299552014), + Offset(24.90721224955777, 21.981909603369285), + Offset(24.93688634299713, 21.995513308842824), + Offset(24.946416978297822, 21.99999554552736), + Offset(24.946426391602, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(20.119379987935375, 39.71216886349571), + Offset(20.035365179444106, 38.098189435424544), + Offset(19.873891596544055, 35.347695300373125), + Offset(19.793758394940628, 31.993231084634104), + Offset(20.054759622984875, 28.566287279841106), + Offset(20.820222022970064, 25.699593181776418), + Offset(21.69175863695111, 23.96012431648284), + Offset(22.0396545923487, 22.973954778081758), + Offset(22.575354251027797, 22.307041818397096), + Offset(23.13481266350873, 21.963538905970477), + Offset(23.61089397476114, 21.82185413347875), + Offset(23.986931743904425, 21.787410536180875), + Offset(24.275341639029573, 21.804570680587215), + Offset(24.49284022176112, 21.842957712390593), + Offset(24.65438451073494, 21.88635295594771), + Offset(24.771728811860356, 21.926317874970856), + Offset(24.853792326872156, 21.958735299552014), + Offset(24.90721224955777, 21.981909603369285), + Offset(24.93688634299713, 21.995513308842824), + Offset(24.946416978297822, 21.99999554552736), + Offset(24.946426391602, 22.0), + ], + <Offset>[ + Offset(20.176179763180997, 21.987735903833876), + Offset(20.55193618727129, 21.88909752977205), + Offset(21.227655124257208, 21.71486474263169), + Offset(22.13567600845661, 21.53308372554798), + Offset(23.226514419921436, 21.464181986077985), + Offset(24.410278375419598, 21.684041595886633), + Offset(25.440842849032627, 22.309300738195095), + Offset(26.03642252837242, 23.134721894037487), + Offset(26.21244881576038, 23.971837039195353), + Offset(26.123327546035632, 24.622256415770117), + Offset(25.931014482213666, 25.0802342265462), + Offset(25.71921080582189, 25.392852152910002), + Offset(25.5230666408985, 25.604989383797584), + Offset(25.3554718074648, 25.748833638139686), + Offset(25.21948374988762, 25.846234627148135), + Offset(25.114174554400172, 25.911632280813432), + Offset(25.037072414338468, 25.95453414453137), + Offset(24.98527999526863, 25.9811477091939), + Offset(24.955944954391757, 25.995467904751596), + Offset(24.946435804885212, 25.999995545483056), + Offset(24.946426391602, 26.0), + ], + <Offset>[ + Offset(20.176179763180997, 21.987735903833876), + Offset(20.55193618727129, 21.88909752977205), + Offset(21.227655124257208, 21.71486474263169), + Offset(22.13567600845661, 21.53308372554798), + Offset(23.226514419921436, 21.464181986077985), + Offset(24.410278375419598, 21.684041595886633), + Offset(25.440842849032627, 22.309300738195095), + Offset(26.03642252837242, 23.134721894037487), + Offset(26.21244881576038, 23.971837039195353), + Offset(26.123327546035632, 24.622256415770117), + Offset(25.931014482213666, 25.0802342265462), + Offset(25.71921080582189, 25.392852152910002), + Offset(25.5230666408985, 25.604989383797584), + Offset(25.3554718074648, 25.748833638139686), + Offset(25.21948374988762, 25.846234627148135), + Offset(25.114174554400172, 25.911632280813432), + Offset(25.037072414338468, 25.95453414453137), + Offset(24.98527999526863, 25.9811477091939), + Offset(24.955944954391757, 25.995467904751596), + Offset(24.946435804885212, 25.999995545483056), + Offset(24.946426391602, 26.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(27.83663858395034, 22.012284634971753), + Offset(27.57547597959216, 22.112932217745428), + Offset(27.1676077276265, 22.304712254982665), + Offset(26.73824662421029, 22.56355115802843), + Offset(26.404591513129226, 22.883490887942344), + Offset(26.255743734676358, 23.33395805057893), + Offset(26.21997565073384, 24.078741473347776), + Offset(25.9603454076513, 25.02604522191824), + Offset(25.424645748972203, 25.692958181602904), + Offset(24.865187336491275, 26.036461094029523), + Offset(24.38910602523886, 26.17814586652125), + Offset(24.013068256095575, 26.212589463819125), + Offset(23.724658360970427, 26.195429319412785), + Offset(23.50715977823888, 26.157042287609407), + Offset(23.34561548926506, 26.11364704405229), + Offset(23.228271188139644, 26.073682125029144), + Offset(23.14620767312784, 26.041264700447986), + Offset(23.092787750442234, 26.018090396630715), + Offset(23.063113657002866, 26.004486691157176), + Offset(23.053583021702178, 26.00000445447264), + Offset(23.053573608398, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(27.83663858395034, 22.012284634971753), + Offset(27.57547597959216, 22.112932217745428), + Offset(27.1676077276265, 22.304712254982665), + Offset(26.73824662421029, 22.56355115802843), + Offset(26.404591513129226, 22.883490887942344), + Offset(26.255743734676358, 23.33395805057893), + Offset(26.21997565073384, 24.078741473347776), + Offset(25.9603454076513, 25.02604522191824), + Offset(25.424645748972203, 25.692958181602904), + Offset(24.865187336491275, 26.036461094029523), + Offset(24.38910602523886, 26.17814586652125), + Offset(24.013068256095575, 26.212589463819125), + Offset(23.724658360970427, 26.195429319412785), + Offset(23.50715977823888, 26.157042287609407), + Offset(23.34561548926506, 26.11364704405229), + Offset(23.228271188139644, 26.073682125029144), + Offset(23.14620767312784, 26.041264700447986), + Offset(23.092787750442234, 26.018090396630715), + Offset(23.063113657002866, 26.004486691157176), + Offset(23.053583021702178, 26.00000445447264), + Offset(23.053573608398, 26.0), + ], + <Offset>[ + Offset(38.00591550498171, 22.044873132716056), + Offset(38.49527667051535, 22.460937675485788), + Offset(39.29605291377171, 23.50908772721707), + Offset(40.09093462819668, 25.55307837507629), + Offset(40.245484311916975, 29.0647450812576), + Offset(38.4507533181536, 34.23676198346485), + Offset(33.07289070449873, 39.64197668074282), + Offset(25.27493194621101, 42.065839270086585), + Offset(18.32696878877331, 41.19932315169756), + Offset(13.530028647163753, 38.77767572627239), + Offset(10.497349834921115, 36.06973233007125), + Offset(8.641652255675858, 33.59797658699403), + Offset(7.521978336485894, 31.51497186001597), + Offset(6.854874126978952, 29.834780098541525), + Offset(6.463082099172453, 28.52288741178755), + Offset(6.237308044976331, 27.53366304435064), + Offset(6.110545241324058, 26.822659816088162), + Offset(6.042462396642684, 26.350923908611218), + Offset(6.009733624105834, 26.085741049230222), + Offset(6.0000094134910675, 26.000084719621103), + Offset(5.999999999998, 26.000000000000004), + ], + <Offset>[ + Offset(38.00591550498171, 22.044873132716056), + Offset(38.49527667051535, 22.460937675485788), + Offset(39.29605291377171, 23.50908772721707), + Offset(40.09093462819668, 25.55307837507629), + Offset(40.245484311916975, 29.0647450812576), + Offset(38.4507533181536, 34.23676198346485), + Offset(33.07289070449873, 39.64197668074282), + Offset(25.27493194621101, 42.065839270086585), + Offset(18.32696878877331, 41.19932315169756), + Offset(13.530028647163753, 38.77767572627239), + Offset(10.497349834921115, 36.06973233007125), + Offset(8.641652255675858, 33.59797658699403), + Offset(7.521978336485894, 31.51497186001597), + Offset(6.854874126978952, 29.834780098541525), + Offset(6.463082099172453, 28.52288741178755), + Offset(6.237308044976331, 27.53366304435064), + Offset(6.110545241324058, 26.822659816088162), + Offset(6.042462396642684, 26.350923908611218), + Offset(6.009733624105834, 26.085741049230222), + Offset(6.0000094134910675, 26.000084719621103), + Offset(5.999999999998, 26.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.00591550498171, 22.044873132716056), + Offset(38.49527667051535, 22.460937675485788), + Offset(39.29605291377171, 23.50908772721707), + Offset(40.09093462819668, 25.55307837507629), + Offset(40.245484311916975, 29.0647450812576), + Offset(38.4507533181536, 34.23676198346485), + Offset(33.07289070449873, 39.64197668074282), + Offset(25.27493194621101, 42.065839270086585), + Offset(18.32696878877331, 41.19932315169756), + Offset(13.530028647163753, 38.77767572627239), + Offset(10.497349834921115, 36.06973233007125), + Offset(8.641652255675858, 33.59797658699403), + Offset(7.521978336485894, 31.51497186001597), + Offset(6.854874126978952, 29.834780098541525), + Offset(6.463082099172453, 28.52288741178755), + Offset(6.237308044976331, 27.53366304435064), + Offset(6.110545241324058, 26.822659816088162), + Offset(6.042462396642684, 26.350923908611218), + Offset(6.009733624105834, 26.085741049230222), + Offset(6.0000094134910675, 26.000084719621103), + Offset(5.999999999998, 26.000000000000004), + ], + <Offset>[ + Offset(37.94911572973609, 39.76930609237789), + Offset(37.978705662688164, 38.67002958113828), + Offset(37.94228938605856, 37.14191828495851), + Offset(37.74901701468069, 36.01322573416242), + Offset(37.073729514980414, 36.166850375020715), + Offset(34.860696965704065, 38.25231356935464), + Offset(29.32380649241722, 41.29280025903057), + Offset(21.278164010187293, 41.90507215413086), + Offset(14.689874224040729, 39.53452793089931), + Offset(10.541513764636846, 36.11895821647275), + Offset(8.17722932746859, 32.8113522370038), + Offset(6.909373193758391, 29.992534970264902), + Offset(6.274253334616972, 27.7145531568056), + Offset(5.992242541275278, 25.92890417279243), + Offset(5.8979828600197735, 24.56300574058713), + Offset(5.894862302436515, 23.548348638508063), + Offset(5.92726515385775, 22.826860971108808), + Offset(5.964394650931823, 22.35168580278661), + Offset(5.990675012711208, 22.08578645332145), + Offset(5.9999905869036745, 22.00008471966541), + Offset(5.999999999998, 22.000000000000004), + ], + <Offset>[ + Offset(37.94911572973609, 39.76930609237789), + Offset(37.978705662688164, 38.67002958113828), + Offset(37.94228938605856, 37.14191828495851), + Offset(37.74901701468069, 36.01322573416242), + Offset(37.073729514980414, 36.166850375020715), + Offset(34.860696965704065, 38.25231356935464), + Offset(29.32380649241722, 41.29280025903057), + Offset(21.278164010187293, 41.90507215413086), + Offset(14.689874224040729, 39.53452793089931), + Offset(10.541513764636846, 36.11895821647275), + Offset(8.17722932746859, 32.8113522370038), + Offset(6.909373193758391, 29.992534970264902), + Offset(6.274253334616972, 27.7145531568056), + Offset(5.992242541275278, 25.92890417279243), + Offset(5.8979828600197735, 24.56300574058713), + Offset(5.894862302436515, 23.548348638508063), + Offset(5.92726515385775, 22.826860971108808), + Offset(5.964394650931823, 22.35168580278661), + Offset(5.990675012711208, 22.08578645332145), + Offset(5.9999905869036745, 22.00008471966541), + Offset(5.999999999998, 22.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(37.94911572973609, 39.76930609237789), + Offset(37.978705662688164, 38.67002958113828), + Offset(37.94228938605856, 37.14191828495851), + Offset(37.74901701468069, 36.01322573416242), + Offset(37.073729514980414, 36.166850375020715), + Offset(34.860696965704065, 38.25231356935464), + Offset(29.32380649241722, 41.29280025903057), + Offset(21.278164010187293, 41.90507215413086), + Offset(14.689874224040729, 39.53452793089931), + Offset(10.541513764636846, 36.11895821647275), + Offset(8.17722932746859, 32.8113522370038), + Offset(6.909373193758391, 29.992534970264902), + Offset(6.274253334616972, 27.7145531568056), + Offset(5.992242541275278, 25.92890417279243), + Offset(5.8979828600197735, 24.56300574058713), + Offset(5.894862302436515, 23.548348638508063), + Offset(5.92726515385775, 22.826860971108808), + Offset(5.964394650931823, 22.35168580278661), + Offset(5.990675012711208, 22.08578645332145), + Offset(5.9999905869036745, 22.00008471966541), + Offset(5.999999999998, 22.000000000000004), + ], + <Offset>[ + Offset(27.779838808704717, 39.73671759463359), + Offset(27.058904971764974, 38.322024123397924), + Offset(25.813844199913348, 35.937542812724104), + Offset(24.396329010694313, 33.02369851711455), + Offset(23.23283671619266, 29.985596181705468), + Offset(22.665687382226825, 27.349509636468714), + Offset(22.470891438652323, 25.72956505163552), + Offset(21.96357747162758, 24.86527810596251), + Offset(21.78755118423962, 24.028162960804647), + Offset(21.876672453964368, 23.377743584229883), + Offset(22.068985517786334, 22.9197657734538), + Offset(22.28078919417811, 22.607147847089998), + Offset(22.4769333591015, 22.395010616202416), + Offset(22.6445281925352, 22.251166361860314), + Offset(22.78051625011238, 22.153765372851865), + Offset(22.885825445599828, 22.088367719186568), + Offset(22.96292758566153, 22.04546585546863), + Offset(23.014720004731373, 22.0188522908061), + Offset(23.04405504560824, 22.004532095248404), + Offset(23.053564195114788, 22.000004454516944), + Offset(23.053573608398, 22.0), + ], + <Offset>[ + Offset(27.779838808704717, 39.73671759463359), + Offset(27.058904971764974, 38.322024123397924), + Offset(25.813844199913348, 35.937542812724104), + Offset(24.396329010694313, 33.02369851711455), + Offset(23.23283671619266, 29.985596181705468), + Offset(22.665687382226825, 27.349509636468714), + Offset(22.470891438652323, 25.72956505163552), + Offset(21.96357747162758, 24.86527810596251), + Offset(21.78755118423962, 24.028162960804647), + Offset(21.876672453964368, 23.377743584229883), + Offset(22.068985517786334, 22.9197657734538), + Offset(22.28078919417811, 22.607147847089998), + Offset(22.4769333591015, 22.395010616202416), + Offset(22.6445281925352, 22.251166361860314), + Offset(22.78051625011238, 22.153765372851865), + Offset(22.885825445599828, 22.088367719186568), + Offset(22.96292758566153, 22.04546585546863), + Offset(23.014720004731373, 22.0188522908061), + Offset(23.04405504560824, 22.004532095248404), + Offset(23.053564195114788, 22.000004454516944), + Offset(23.053573608398, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(27.779838808704717, 39.73671759463359), + Offset(27.058904971764974, 38.322024123397924), + Offset(25.813844199913348, 35.937542812724104), + Offset(24.396329010694313, 33.02369851711455), + Offset(23.23283671619266, 29.985596181705468), + Offset(22.665687382226825, 27.349509636468714), + Offset(22.470891438652323, 25.72956505163552), + Offset(21.96357747162758, 24.86527810596251), + Offset(21.78755118423962, 24.028162960804647), + Offset(21.876672453964368, 23.377743584229883), + Offset(22.068985517786334, 22.9197657734538), + Offset(22.28078919417811, 22.607147847089998), + Offset(22.4769333591015, 22.395010616202416), + Offset(22.6445281925352, 22.251166361860314), + Offset(22.78051625011238, 22.153765372851865), + Offset(22.885825445599828, 22.088367719186568), + Offset(22.96292758566153, 22.04546585546863), + Offset(23.014720004731373, 22.0188522908061), + Offset(23.04405504560824, 22.004532095248404), + Offset(23.053564195114788, 22.000004454516944), + Offset(23.053573608398, 22.0), + ], + <Offset>[ + Offset(27.83663858395034, 22.012284634971753), + Offset(27.57547597959216, 22.112932217745428), + Offset(27.1676077276265, 22.304712254982665), + Offset(26.738246624210294, 22.56355115802843), + Offset(26.404591513129223, 22.883490887942344), + Offset(26.25574373467636, 23.333958050578932), + Offset(26.21997565073384, 24.078741473347776), + Offset(25.9603454076513, 25.02604522191824), + Offset(25.424645748972203, 25.692958181602904), + Offset(24.865187336491275, 26.036461094029523), + Offset(24.38910602523886, 26.17814586652125), + Offset(24.013068256095575, 26.212589463819125), + Offset(23.724658360970427, 26.195429319412785), + Offset(23.50715977823888, 26.157042287609407), + Offset(23.34561548926506, 26.11364704405229), + Offset(23.228271188139644, 26.073682125029144), + Offset(23.14620767312784, 26.041264700447986), + Offset(23.092787750442234, 26.018090396630715), + Offset(23.063113657002866, 26.004486691157176), + Offset(23.053583021702178, 26.00000445447264), + Offset(23.053573608398, 26.0), + ], + <Offset>[ + Offset(27.83663858395034, 22.012284634971753), + Offset(27.57547597959216, 22.112932217745428), + Offset(27.1676077276265, 22.304712254982665), + Offset(26.738246624210294, 22.56355115802843), + Offset(26.404591513129223, 22.883490887942344), + Offset(26.25574373467636, 23.333958050578932), + Offset(26.21997565073384, 24.078741473347776), + Offset(25.9603454076513, 25.02604522191824), + Offset(25.424645748972203, 25.692958181602904), + Offset(24.865187336491275, 26.036461094029523), + Offset(24.38910602523886, 26.17814586652125), + Offset(24.013068256095575, 26.212589463819125), + Offset(23.724658360970427, 26.195429319412785), + Offset(23.50715977823888, 26.157042287609407), + Offset(23.34561548926506, 26.11364704405229), + Offset(23.228271188139644, 26.073682125029144), + Offset(23.14620767312784, 26.041264700447986), + Offset(23.092787750442234, 26.018090396630715), + Offset(23.063113657002866, 26.004486691157176), + Offset(23.053583021702178, 26.00000445447264), + Offset(23.053573608398, 26.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(23.684125337085877, 6.32904503029285), + Offset(24.757855588582725, 6.522328815913423), + Offset(27.574407323116677, 7.305175651642309), + Offset(34.29718691345236, 10.565460438397327), + Offset(42.96465562696383, 18.312204872266342), + Offset(45.05615687407709, 26.45166424954756), + Offset(42.23233332042143, 35.60390079418309), + Offset(35.26685178627038, 42.467757059973906), + Offset(27.4197052006056, 45.36131120369138), + Offset(21.001315853482343, 45.424469500769995), + Offset(16.29765110355406, 44.215682562738714), + Offset(12.97234991047133, 42.61158062881598), + Offset(10.641290841160107, 41.016018618041265), + Offset(9.0114530912401, 39.59946991291384), + Offset(7.875830197056132, 38.422591589788325), + Offset(7.093422401327867, 37.49694905895691), + Offset(6.568745459991835, 36.81215692853645), + Offset(6.237631760921833, 36.34901917317271), + Offset(6.057380152594408, 36.08562753900215), + Offset(6.000056479961543, 36.00008471951035), + Offset(6.0000000000000036, 36.00000000000001), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(23.684125337085877, 6.32904503029285), + Offset(24.757855588582725, 6.522328815913423), + Offset(27.574407323116677, 7.305175651642309), + Offset(34.29718691345236, 10.565460438397327), + Offset(42.96465562696383, 18.312204872266342), + Offset(45.05615687407709, 26.45166424954756), + Offset(42.23233332042143, 35.60390079418309), + Offset(35.26685178627038, 42.467757059973906), + Offset(27.4197052006056, 45.36131120369138), + Offset(21.001315853482343, 45.424469500769995), + Offset(16.29765110355406, 44.215682562738714), + Offset(12.97234991047133, 42.61158062881598), + Offset(10.641290841160107, 41.016018618041265), + Offset(9.0114530912401, 39.59946991291384), + Offset(7.875830197056132, 38.422591589788325), + Offset(7.093422401327867, 37.49694905895691), + Offset(6.568745459991835, 36.81215692853645), + Offset(6.237631760921833, 36.34901917317271), + Offset(6.057380152594408, 36.08562753900215), + Offset(6.000056479961543, 36.00008471951035), + Offset(6.0000000000000036, 36.00000000000001), + ], + <Offset>[ + Offset(23.689243079011977, 6.329061430625194), + Offset(23.64011618905085, 6.48670734054237), + Offset(23.133765296901146, 6.8642122589514845), + Offset(19.98658162330333, 7.361465557774245), + Offset(15.467378257263233, 6.032096680033179), + Offset(19.194942220379907, 3.3307514773626146), + Offset(27.75047360634506, 2.715037120490525), + Offset(36.713755829871914, 6.4968456357604545), + Offset(42.40286218778989, 12.627460121098146), + Offset(44.92977344167909, 18.52783555802784), + Offset(45.6230719411611, 23.334597995665984), + Offset(45.42132446103347, 27.02106907155878), + Offset(44.84505917005344, 29.786493601220947), + Offset(44.16433642298196, 31.835785641580745), + Offset(43.51476523785995, 33.33669843741421), + Offset(42.96125205391104, 34.41493737609855), + Offset(42.530935064806016, 35.16263614133967), + Offset(42.23077471334334, 35.64640946177496), + Offset(42.056971515773355, 35.91410003645049), + Offset(42.0000564795628, 35.99991528022383), + Offset(42.0, 35.99999999999999), + ], + <Offset>[ + Offset(23.689243079011977, 6.329061430625194), + Offset(23.64011618905085, 6.48670734054237), + Offset(23.133765296901146, 6.8642122589514845), + Offset(19.98658162330333, 7.361465557774245), + Offset(15.467378257263233, 6.032096680033179), + Offset(19.194942220379907, 3.3307514773626146), + Offset(27.75047360634506, 2.715037120490525), + Offset(36.713755829871914, 6.4968456357604545), + Offset(42.40286218778989, 12.627460121098146), + Offset(44.92977344167909, 18.52783555802784), + Offset(45.6230719411611, 23.334597995665984), + Offset(45.42132446103347, 27.02106907155878), + Offset(44.84505917005344, 29.786493601220947), + Offset(44.16433642298196, 31.835785641580745), + Offset(43.51476523785995, 33.33669843741421), + Offset(42.96125205391104, 34.41493737609855), + Offset(42.530935064806016, 35.16263614133967), + Offset(42.23077471334334, 35.64640946177496), + Offset(42.056971515773355, 35.91410003645049), + Offset(42.0000564795628, 35.99991528022383), + Offset(42.0, 35.99999999999999), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(23.689243079011977, 6.329061430625194), + Offset(23.64011618905085, 6.48670734054237), + Offset(23.133765296901146, 6.8642122589514845), + Offset(19.98658162330333, 7.361465557774245), + Offset(15.467378257263233, 6.032096680033179), + Offset(19.194942220379907, 3.3307514773626146), + Offset(27.75047360634506, 2.715037120490525), + Offset(36.713755829871914, 6.4968456357604545), + Offset(42.40286218778989, 12.627460121098146), + Offset(44.92977344167909, 18.52783555802784), + Offset(45.6230719411611, 23.334597995665984), + Offset(45.42132446103347, 27.02106907155878), + Offset(44.84505917005344, 29.786493601220947), + Offset(44.16433642298196, 31.835785641580745), + Offset(43.51476523785995, 33.33669843741421), + Offset(42.96125205391104, 34.41493737609855), + Offset(42.530935064806016, 35.16263614133967), + Offset(42.23077471334334, 35.64640946177496), + Offset(42.056971515773355, 35.91410003645049), + Offset(42.0000564795628, 35.99991528022383), + Offset(42.0, 35.99999999999999), + ], + <Offset>[ + Offset(4.256210085244433, 23.724986123422013), + Offset(4.334340540250139, 22.918290544448126), + Offset(4.683893395049303, 20.897955670871653), + Offset(6.165631658910659, 16.538261784200643), + Offset(10.04725752347015, 10.401464969282092), + Offset(15.676813589860602, 6.207875011618711), + Offset(24.053924042171055, 4.3051387362291464), + Offset(32.7169878938482, 6.336078519804726), + Offset(38.76576762305731, 10.962664900299892), + Offset(41.94125855915219, 15.869118048228197), + Offset(43.30295143370857, 20.076217902598536), + Offset(43.689045399116004, 23.415627454829654), + Offset(43.59733416818452, 25.98607489801058), + Offset(43.30170483727829, 27.92990971583165), + Offset(42.94966599870727, 29.37681676621379), + Offset(42.618806311371216, 30.429622970255974), + Offset(42.347654977339715, 31.166837296360313), + Offset(42.15270696763247, 31.64717135595035), + Offset(42.03791290437873, 31.914145440541716), + Offset(42.00003765297541, 31.999915280268137), + Offset(42.0, 31.999999999999996), + ], + <Offset>[ + Offset(4.256210085244433, 23.724986123422013), + Offset(4.334340540250139, 22.918290544448126), + Offset(4.683893395049303, 20.897955670871653), + Offset(6.165631658910659, 16.538261784200643), + Offset(10.04725752347015, 10.401464969282092), + Offset(15.676813589860602, 6.207875011618711), + Offset(24.053924042171055, 4.3051387362291464), + Offset(32.7169878938482, 6.336078519804726), + Offset(38.76576762305731, 10.962664900299892), + Offset(41.94125855915219, 15.869118048228197), + Offset(43.30295143370857, 20.076217902598536), + Offset(43.689045399116004, 23.415627454829654), + Offset(43.59733416818452, 25.98607489801058), + Offset(43.30170483727829, 27.92990971583165), + Offset(42.94966599870727, 29.37681676621379), + Offset(42.618806311371216, 30.429622970255974), + Offset(42.347654977339715, 31.166837296360313), + Offset(42.15270696763247, 31.64717135595035), + Offset(42.03791290437873, 31.914145440541716), + Offset(42.00003765297541, 31.999915280268137), + Offset(42.0, 31.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(4.256210085244433, 23.724986123422013), + Offset(4.334340540250139, 22.918290544448126), + Offset(4.683893395049303, 20.897955670871653), + Offset(6.165631658910659, 16.538261784200643), + Offset(10.04725752347015, 10.401464969282092), + Offset(15.676813589860602, 6.207875011618711), + Offset(24.053924042171055, 4.3051387362291464), + Offset(32.7169878938482, 6.336078519804726), + Offset(38.76576762305731, 10.962664900299892), + Offset(41.94125855915219, 15.869118048228197), + Offset(43.30295143370857, 20.076217902598536), + Offset(43.689045399116004, 23.415627454829654), + Offset(43.59733416818452, 25.98607489801058), + Offset(43.30170483727829, 27.92990971583165), + Offset(42.94966599870727, 29.37681676621379), + Offset(42.618806311371216, 30.429622970255974), + Offset(42.347654977339715, 31.166837296360313), + Offset(42.15270696763247, 31.64717135595035), + Offset(42.03791290437873, 31.914145440541716), + Offset(42.00003765297541, 31.999915280268137), + Offset(42.0, 31.999999999999996), + ], + <Offset>[ + Offset(43.99436998801117, 23.85233115929924), + Offset(43.935955265272696, 24.180362852333243), + Offset(43.76617309606209, 24.778893280638325), + Offset(43.45759773349659, 24.887543031835328), + Offset(43.476142398493316, 25.33059113299948), + Offset(42.61623543783426, 30.292746160199744), + Offset(38.56421880483555, 37.258579505338574), + Offset(31.270083850246664, 42.30698994401817), + Offset(23.782610635873013, 43.696515982893125), + Offset(18.012800970955436, 42.76575199097035), + Offset(13.977530596101534, 40.95730246967126), + Offset(11.240070848553863, 39.00613901208685), + Offset(9.393565839291185, 37.2155999148309), + Offset(8.148821505536425, 35.693593987164746), + Offset(7.310730957903452, 34.462709918587905), + Offset(6.750976658788051, 33.51163465311433), + Offset(6.385465372525527, 32.8163580835571), + Offset(6.159564015210972, 32.3497810673481), + Offset(6.038321541199782, 32.08567294309337), + Offset(6.00003765337415, 32.00008471955465), + Offset(6.0000000000000036, 32.00000000000001), + ], + <Offset>[ + Offset(43.99436998801117, 23.85233115929924), + Offset(43.935955265272696, 24.180362852333243), + Offset(43.76617309606209, 24.778893280638325), + Offset(43.45759773349659, 24.887543031835328), + Offset(43.476142398493316, 25.33059113299948), + Offset(42.61623543783426, 30.292746160199744), + Offset(38.56421880483555, 37.258579505338574), + Offset(31.270083850246664, 42.30698994401817), + Offset(23.782610635873013, 43.696515982893125), + Offset(18.012800970955436, 42.76575199097035), + Offset(13.977530596101534, 40.95730246967126), + Offset(11.240070848553863, 39.00613901208685), + Offset(9.393565839291185, 37.2155999148309), + Offset(8.148821505536425, 35.693593987164746), + Offset(7.310730957903452, 34.462709918587905), + Offset(6.750976658788051, 33.51163465311433), + Offset(6.385465372525527, 32.8163580835571), + Offset(6.159564015210972, 32.3497810673481), + Offset(6.038321541199782, 32.08567294309337), + Offset(6.00003765337415, 32.00008471955465), + Offset(6.0000000000000036, 32.00000000000001), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(43.99436998801117, 23.85233115929924), + Offset(43.935955265272696, 24.180362852333243), + Offset(43.76617309606209, 24.778893280638325), + Offset(43.45759773349659, 24.887543031835328), + Offset(43.476142398493316, 25.33059113299948), + Offset(42.61623543783426, 30.292746160199744), + Offset(38.56421880483555, 37.258579505338574), + Offset(31.270083850246664, 42.30698994401817), + Offset(23.782610635873013, 43.696515982893125), + Offset(18.012800970955436, 42.76575199097035), + Offset(13.977530596101534, 40.95730246967126), + Offset(11.240070848553863, 39.00613901208685), + Offset(9.393565839291185, 37.2155999148309), + Offset(8.148821505536425, 35.693593987164746), + Offset(7.310730957903452, 34.462709918587905), + Offset(6.750976658788051, 33.51163465311433), + Offset(6.385465372525527, 32.8163580835571), + Offset(6.159564015210972, 32.3497810673481), + Offset(6.038321541199782, 32.08567294309337), + Offset(6.00003765337415, 32.00008471955465), + Offset(6.0000000000000036, 32.00000000000001), + ], + <Offset>[ + Offset(23.684125337090187, 6.329045030292864), + Offset(24.757855588602716, 6.52232881591406), + Offset(27.574407323047023, 7.305175651635392), + Offset(34.29718691345236, 10.565460438397327), + Offset(42.96465562689078, 18.312204872233718), + Offset(45.05615687408604, 26.45166424955556), + Offset(42.232333320435735, 35.60390079421558), + Offset(35.26685178627038, 42.467757059973906), + Offset(27.4197052006056, 45.36131120369138), + Offset(21.001315853482343, 45.424469500769995), + Offset(16.29765110355406, 44.215682562738714), + Offset(12.97234991047133, 42.61158062881598), + Offset(10.641290841160107, 41.016018618041265), + Offset(9.0114530912401, 39.59946991291384), + Offset(7.875830197056132, 38.422591589788325), + Offset(7.093422401327867, 37.49694905895691), + Offset(6.568745459991835, 36.81215692853645), + Offset(6.237631760921833, 36.34901917317271), + Offset(6.057380152594408, 36.08562753900215), + Offset(6.000056479961543, 36.00008471951035), + Offset(6.0000000000000036, 36.00000000000001), + ], + <Offset>[ + Offset(23.684125337090187, 6.329045030292864), + Offset(24.757855588602716, 6.52232881591406), + Offset(27.574407323047023, 7.305175651635392), + Offset(34.29718691345236, 10.565460438397327), + Offset(42.96465562689078, 18.312204872233718), + Offset(45.05615687408604, 26.45166424955556), + Offset(42.232333320435735, 35.60390079421558), + Offset(35.26685178627038, 42.467757059973906), + Offset(27.4197052006056, 45.36131120369138), + Offset(21.001315853482343, 45.424469500769995), + Offset(16.29765110355406, 44.215682562738714), + Offset(12.97234991047133, 42.61158062881598), + Offset(10.641290841160107, 41.016018618041265), + Offset(9.0114530912401, 39.59946991291384), + Offset(7.875830197056132, 38.422591589788325), + Offset(7.093422401327867, 37.49694905895691), + Offset(6.568745459991835, 36.81215692853645), + Offset(6.237631760921833, 36.34901917317271), + Offset(6.057380152594408, 36.08562753900215), + Offset(6.000056479961543, 36.00008471951035), + Offset(6.0000000000000036, 36.00000000000001), + ], + ), + _PathClose( + ), + ], + ), + ], +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/list_view.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/list_view.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..25d544ce90aafc4f99840c0611737733cfa04ee7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/list_view.g.dart @@ -0,0 +1,3901 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$list_view = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.878048780488, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(3.3000000000000016, 35.5), + Offset(3.1872491552817053, 35.294662556963694), + Offset(2.803584610041825, 34.55708172822131), + Offset(2.086762034690722, 32.974965285488736), + Offset(1.0562543947134673, 29.85871467131613), + Offset(0.3277056784121384, 23.397935591386524), + Offset(5.068384450186188, 9.77558673709007), + Offset(19.142440865906075, 0.8236301535641601), + Offset(28.4986244695124, 0.7512929847205392), + Offset(34.03339705415398, 2.550735594111994), + Offset(37.52630261515188, 4.563458703685585), + Offset(39.83951862260312, 6.397453314812415), + Offset(41.420680465862844, 7.960676694252207), + Offset(42.52292959864048, 9.247336542718527), + Offset(43.29857028685616, 10.277566364406328), + Offset(43.843675623946226, 11.078369385731442), + Offset(44.22049532021145, 11.67638165937833), + Offset(44.47040673191611, 12.096116254351111), + Offset(44.62108022189184, 12.359078623996243), + Offset(44.69110902782625, 12.484010802427473), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.3000000000000016, 35.5), + Offset(3.1872491552817053, 35.294662556963694), + Offset(2.803584610041825, 34.55708172822131), + Offset(2.086762034690722, 32.974965285488736), + Offset(1.0562543947134673, 29.85871467131613), + Offset(0.3277056784121384, 23.397935591386524), + Offset(5.068384450186188, 9.77558673709007), + Offset(19.142440865906075, 0.8236301535641601), + Offset(28.4986244695124, 0.7512929847205392), + Offset(34.03339705415398, 2.550735594111994), + Offset(37.52630261515188, 4.563458703685585), + Offset(39.83951862260312, 6.397453314812415), + Offset(41.420680465862844, 7.960676694252207), + Offset(42.52292959864048, 9.247336542718527), + Offset(43.29857028685616, 10.277566364406328), + Offset(43.843675623946226, 11.078369385731442), + Offset(44.22049532021145, 11.67638165937833), + Offset(44.47040673191611, 12.096116254351111), + Offset(44.62108022189184, 12.359078623996243), + Offset(44.69110902782625, 12.484010802427473), + ], + <Offset>[ + Offset(7.900000000000001, 35.5), + Offset(7.787024068249312, 35.34016805150932), + Offset(7.398927009112204, 34.7640315658779), + Offset(6.654572753845953, 33.51820117713304), + Offset(5.505071070263646, 31.02834289744042), + Offset(4.290730713340881, 25.733408257149932), + Offset(6.941261311200804, 13.977054607189284), + Offset(17.78085941259789, 5.217500423156466), + Offset(25.541432860040533, 4.274788093964937), + Offset(30.30609713874217, 5.246516620191658), + Offset(33.39574733179454, 6.587937167668043), + Offset(35.489171433369805, 7.892270806391144), + Offset(36.94930799941936, 9.040874947505337), + Offset(37.985765755731585, 10.005059620498354), + Offset(38.72688536686231, 10.787171105652785), + Offset(39.254973101552665, 11.400563676461365), + Offset(39.62422079973953, 11.861477668143195), + Offset(39.87129202785027, 12.186360028903175), + Offset(40.02118722421174, 12.390453931063687), + Offset(40.091110400688535, 12.487564720144858), + ], + <Offset>[ + Offset(7.900000000000001, 35.5), + Offset(7.787024068249312, 35.34016805150932), + Offset(7.398927009112204, 34.7640315658779), + Offset(6.654572753845953, 33.51820117713304), + Offset(5.505071070263646, 31.02834289744042), + Offset(4.290730713340881, 25.733408257149932), + Offset(6.941261311200804, 13.977054607189284), + Offset(17.78085941259789, 5.217500423156466), + Offset(25.541432860040533, 4.274788093964937), + Offset(30.30609713874217, 5.246516620191658), + Offset(33.39574733179454, 6.587937167668043), + Offset(35.489171433369805, 7.892270806391144), + Offset(36.94930799941936, 9.040874947505337), + Offset(37.985765755731585, 10.005059620498354), + Offset(38.72688536686231, 10.787171105652785), + Offset(39.254973101552665, 11.400563676461365), + Offset(39.62422079973953, 11.861477668143195), + Offset(39.87129202785027, 12.186360028903175), + Offset(40.02118722421174, 12.390453931063687), + Offset(40.091110400688535, 12.487564720144858), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(7.900000000000001, 35.5), + Offset(7.787024068249312, 35.34016805150932), + Offset(7.398927009112204, 34.7640315658779), + Offset(6.654572753845953, 33.51820117713304), + Offset(5.505071070263646, 31.02834289744042), + Offset(4.290730713340881, 25.733408257149932), + Offset(6.941261311200804, 13.977054607189284), + Offset(17.78085941259789, 5.217500423156466), + Offset(25.541432860040533, 4.274788093964937), + Offset(30.30609713874217, 5.246516620191658), + Offset(33.39574733179454, 6.587937167668043), + Offset(35.489171433369805, 7.892270806391144), + Offset(36.94930799941936, 9.040874947505337), + Offset(37.985765755731585, 10.005059620498354), + Offset(38.72688536686231, 10.787171105652785), + Offset(39.254973101552665, 11.400563676461365), + Offset(39.62422079973953, 11.861477668143195), + Offset(39.87129202785027, 12.186360028903175), + Offset(40.02118722421174, 12.390453931063687), + Offset(40.091110400688535, 12.487564720144858), + ], + <Offset>[ + Offset(7.900000000000001, 30.900000000000002), + Offset(7.832529562794939, 30.740393138541712), + Offset(7.605876846768791, 30.168689166807518), + Offset(7.19780864549025, 28.950390457977804), + Offset(6.674699296387938, 26.57952622189024), + Offset(6.626203379104288, 21.770383222221188), + Offset(11.14272918130002, 12.104177746174667), + Offset(22.174729682190197, 6.579081876464652), + Offset(29.06492796928493, 7.231979703436803), + Offset(33.00187816482183, 8.973816535603465), + Offset(35.420225795777, 10.718492451025382), + Offset(36.983988924948534, 12.242617995624466), + Offset(38.02950625267249, 13.51224741394882), + Offset(38.743488833511414, 14.542223463407256), + Offset(39.23649010810877, 15.358856025646629), + Offset(39.57716739228259, 15.989266198854928), + Offset(39.8093168085044, 16.457752188615107), + Offset(39.96153580240233, 16.785474732969014), + Offset(40.052562531279186, 16.990346928743786), + Offset(40.094664318405925, 17.087563347282572), + ], + <Offset>[ + Offset(7.900000000000001, 30.900000000000002), + Offset(7.832529562794939, 30.740393138541712), + Offset(7.605876846768791, 30.168689166807518), + Offset(7.19780864549025, 28.950390457977804), + Offset(6.674699296387938, 26.57952622189024), + Offset(6.626203379104288, 21.770383222221188), + Offset(11.14272918130002, 12.104177746174667), + Offset(22.174729682190197, 6.579081876464652), + Offset(29.06492796928493, 7.231979703436803), + Offset(33.00187816482183, 8.973816535603465), + Offset(35.420225795777, 10.718492451025382), + Offset(36.983988924948534, 12.242617995624466), + Offset(38.02950625267249, 13.51224741394882), + Offset(38.743488833511414, 14.542223463407256), + Offset(39.23649010810877, 15.358856025646629), + Offset(39.57716739228259, 15.989266198854928), + Offset(39.8093168085044, 16.457752188615107), + Offset(39.96153580240233, 16.785474732969014), + Offset(40.052562531279186, 16.990346928743786), + Offset(40.094664318405925, 17.087563347282572), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(7.900000000000001, 30.900000000000002), + Offset(7.832529562794939, 30.740393138541712), + Offset(7.605876846768791, 30.168689166807518), + Offset(7.19780864549025, 28.950390457977804), + Offset(6.674699296387938, 26.57952622189024), + Offset(6.626203379104288, 21.770383222221188), + Offset(11.14272918130002, 12.104177746174667), + Offset(22.174729682190197, 6.579081876464652), + Offset(29.06492796928493, 7.231979703436803), + Offset(33.00187816482183, 8.973816535603465), + Offset(35.420225795777, 10.718492451025382), + Offset(36.983988924948534, 12.242617995624466), + Offset(38.02950625267249, 13.51224741394882), + Offset(38.743488833511414, 14.542223463407256), + Offset(39.23649010810877, 15.358856025646629), + Offset(39.57716739228259, 15.989266198854928), + Offset(39.8093168085044, 16.457752188615107), + Offset(39.96153580240233, 16.785474732969014), + Offset(40.052562531279186, 16.990346928743786), + Offset(40.094664318405925, 17.087563347282572), + ], + <Offset>[ + Offset(3.3000000000000016, 30.900000000000002), + Offset(3.2327546498273323, 30.694887643996086), + Offset(3.0105344476984124, 29.96173932915093), + Offset(2.6299979263350193, 28.407154566333507), + Offset(2.2258826208377593, 25.40989799576595), + Offset(2.663178344175545, 19.43491055645778), + Offset(9.269852320285402, 7.902709876075453), + Offset(23.53631113549838, 2.185211606872347), + Offset(32.0221195787568, 3.708484594192405), + Offset(36.729178080233645, 6.278035509523802), + Offset(39.55078107913434, 8.694013987042924), + Offset(41.33433611418185, 10.747800504045737), + Offset(42.500878719115974, 12.43204916069569), + Offset(43.28065267642031, 13.784500385627428), + Offset(43.80817502810262, 14.849251284400172), + Offset(44.16586991467615, 15.667071908125004), + Offset(44.405591328976314, 16.272656179850244), + Offset(44.56065050646817, 16.695230958416946), + Offset(44.65245552895929, 16.95897162167634), + Offset(44.69466294554364, 17.084009429565185), + ], + <Offset>[ + Offset(3.3000000000000016, 30.900000000000002), + Offset(3.2327546498273323, 30.694887643996086), + Offset(3.0105344476984124, 29.96173932915093), + Offset(2.6299979263350193, 28.407154566333507), + Offset(2.2258826208377593, 25.40989799576595), + Offset(2.663178344175545, 19.43491055645778), + Offset(9.269852320285402, 7.902709876075453), + Offset(23.53631113549838, 2.185211606872347), + Offset(32.0221195787568, 3.708484594192405), + Offset(36.729178080233645, 6.278035509523802), + Offset(39.55078107913434, 8.694013987042924), + Offset(41.33433611418185, 10.747800504045737), + Offset(42.500878719115974, 12.43204916069569), + Offset(43.28065267642031, 13.784500385627428), + Offset(43.80817502810262, 14.849251284400172), + Offset(44.16586991467615, 15.667071908125004), + Offset(44.405591328976314, 16.272656179850244), + Offset(44.56065050646817, 16.695230958416946), + Offset(44.65245552895929, 16.95897162167634), + Offset(44.69466294554364, 17.084009429565185), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.3000000000000016, 30.900000000000002), + Offset(3.2327546498273323, 30.694887643996086), + Offset(3.0105344476984124, 29.96173932915093), + Offset(2.6299979263350193, 28.407154566333507), + Offset(2.2258826208377593, 25.40989799576595), + Offset(2.663178344175545, 19.43491055645778), + Offset(9.269852320285402, 7.902709876075453), + Offset(23.53631113549838, 2.185211606872347), + Offset(32.0221195787568, 3.708484594192405), + Offset(36.729178080233645, 6.278035509523802), + Offset(39.55078107913434, 8.694013987042924), + Offset(41.33433611418185, 10.747800504045737), + Offset(42.500878719115974, 12.43204916069569), + Offset(43.28065267642031, 13.784500385627428), + Offset(43.80817502810262, 14.849251284400172), + Offset(44.16586991467615, 15.667071908125004), + Offset(44.405591328976314, 16.272656179850244), + Offset(44.56065050646817, 16.695230958416946), + Offset(44.65245552895929, 16.95897162167634), + Offset(44.69466294554364, 17.084009429565185), + ], + <Offset>[ + Offset(3.3000000000000016, 35.5), + Offset(3.1872491552817053, 35.294662556963694), + Offset(2.803584610041825, 34.55708172822131), + Offset(2.086762034690722, 32.974965285488736), + Offset(1.0562543947134673, 29.85871467131613), + Offset(0.3277056784121384, 23.397935591386524), + Offset(5.068384450186188, 9.77558673709007), + Offset(19.142440865906075, 0.8236301535641601), + Offset(28.4986244695124, 0.7512929847205392), + Offset(34.03339705415398, 2.550735594111994), + Offset(37.52630261515188, 4.563458703685585), + Offset(39.83951862260312, 6.397453314812415), + Offset(41.420680465862844, 7.960676694252207), + Offset(42.52292959864048, 9.247336542718527), + Offset(43.29857028685616, 10.277566364406328), + Offset(43.843675623946226, 11.078369385731442), + Offset(44.22049532021145, 11.67638165937833), + Offset(44.47040673191611, 12.096116254351111), + Offset(44.62108022189184, 12.359078623996243), + Offset(44.69110902782625, 12.484010802427473), + ], + <Offset>[ + Offset(3.3000000000000016, 35.5), + Offset(3.1872491552817053, 35.294662556963694), + Offset(2.803584610041825, 34.55708172822131), + Offset(2.086762034690722, 32.974965285488736), + Offset(1.0562543947134673, 29.85871467131613), + Offset(0.3277056784121384, 23.397935591386524), + Offset(5.068384450186188, 9.77558673709007), + Offset(19.142440865906075, 0.8236301535641601), + Offset(28.4986244695124, 0.7512929847205392), + Offset(34.03339705415398, 2.550735594111994), + Offset(37.52630261515188, 4.563458703685585), + Offset(39.83951862260312, 6.397453314812415), + Offset(41.420680465862844, 7.960676694252207), + Offset(42.52292959864048, 9.247336542718527), + Offset(43.29857028685616, 10.277566364406328), + Offset(43.843675623946226, 11.078369385731442), + Offset(44.22049532021145, 11.67638165937833), + Offset(44.47040673191611, 12.096116254351111), + Offset(44.62108022189184, 12.359078623996243), + Offset(44.69110902782625, 12.484010802427473), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.878048780488, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(3.3000000000000016, 17.1), + Offset(3.3692711334642134, 16.89556290509327), + Offset(3.631383960668174, 16.17571213193979), + Offset(4.25970560126791, 14.703722408867815), + Offset(5.734767299210637, 12.063447969115414), + Offset(9.669596341465768, 7.545835451671554), + Offset(21.874255930583047, 2.2840792930316054), + Offset(36.7179219442753, 6.269955966796905), + Offset(42.592604906489996, 12.580059422608004), + Offset(44.81652115847264, 17.459935255759223), + Offset(45.624216471081716, 21.085679837114938), + Offset(45.81878858891804, 23.798842071745703), + Offset(45.74147347887537, 25.84616656002614), + Offset(45.55382190975979, 27.395991914354134), + Offset(45.33698925184199, 28.564306044381702), + Offset(45.13245278686591, 29.433179475305685), + Offset(44.960879355270905, 30.061479741265988), + Offset(44.831381830124364, 30.492575070614457), + Offset(44.74658145016162, 30.758650614716647), + Offset(44.7053246986958, 30.884005310978335), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.3000000000000016, 17.1), + Offset(3.3692711334642134, 16.89556290509327), + Offset(3.631383960668174, 16.17571213193979), + Offset(4.25970560126791, 14.703722408867815), + Offset(5.734767299210637, 12.063447969115414), + Offset(9.669596341465768, 7.545835451671554), + Offset(21.874255930583047, 2.2840792930316054), + Offset(36.7179219442753, 6.269955966796905), + Offset(42.592604906489996, 12.580059422608004), + Offset(44.81652115847264, 17.459935255759223), + Offset(45.624216471081716, 21.085679837114938), + Offset(45.81878858891804, 23.798842071745703), + Offset(45.74147347887537, 25.84616656002614), + Offset(45.55382190975979, 27.395991914354134), + Offset(45.33698925184199, 28.564306044381702), + Offset(45.13245278686591, 29.433179475305685), + Offset(44.960879355270905, 30.061479741265988), + Offset(44.831381830124364, 30.492575070614457), + Offset(44.74658145016162, 30.758650614716647), + Offset(44.7053246986958, 30.884005310978335), + ], + <Offset>[ + Offset(7.900000000000001, 17.1), + Offset(7.96904604643182, 16.941068399638898), + Offset(8.226726359738553, 16.382661969596377), + Offset(8.82751632042314, 15.246958300512112), + Offset(10.183583974760815, 13.233076195239708), + Offset(13.63262137639451, 9.88130811743496), + Offset(23.747132791597664, 6.48554716313082), + Offset(35.35634049096711, 10.66382623638921), + Offset(39.63541329701813, 16.103554531852403), + Offset(41.08922124306083, 20.155716281838888), + Offset(41.49366118772438, 23.1101583010974), + Offset(41.46844139968472, 25.293659563324432), + Offset(41.27010101243189, 26.92636481327927), + Offset(41.016658066850894, 28.15371499213396), + Offset(40.76530433184814, 29.07391078562816), + Offset(40.54375026447235, 29.75537376603561), + Offset(40.36460483479899, 30.24657575003085), + Offset(40.232267126058524, 30.582818845166525), + Offset(40.14668845248152, 30.790025921784093), + Offset(40.10532607155808, 30.88755922869572), + ], + <Offset>[ + Offset(7.900000000000001, 17.1), + Offset(7.96904604643182, 16.941068399638898), + Offset(8.226726359738553, 16.382661969596377), + Offset(8.82751632042314, 15.246958300512112), + Offset(10.183583974760815, 13.233076195239708), + Offset(13.63262137639451, 9.88130811743496), + Offset(23.747132791597664, 6.48554716313082), + Offset(35.35634049096711, 10.66382623638921), + Offset(39.63541329701813, 16.103554531852403), + Offset(41.08922124306083, 20.155716281838888), + Offset(41.49366118772438, 23.1101583010974), + Offset(41.46844139968472, 25.293659563324432), + Offset(41.27010101243189, 26.92636481327927), + Offset(41.016658066850894, 28.15371499213396), + Offset(40.76530433184814, 29.07391078562816), + Offset(40.54375026447235, 29.75537376603561), + Offset(40.36460483479899, 30.24657575003085), + Offset(40.232267126058524, 30.582818845166525), + Offset(40.14668845248152, 30.790025921784093), + Offset(40.10532607155808, 30.88755922869572), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(7.900000000000001, 17.1), + Offset(7.96904604643182, 16.941068399638898), + Offset(8.226726359738553, 16.382661969596377), + Offset(8.82751632042314, 15.246958300512112), + Offset(10.183583974760815, 13.233076195239708), + Offset(13.63262137639451, 9.88130811743496), + Offset(23.747132791597664, 6.48554716313082), + Offset(35.35634049096711, 10.66382623638921), + Offset(39.63541329701813, 16.103554531852403), + Offset(41.08922124306083, 20.155716281838888), + Offset(41.49366118772438, 23.1101583010974), + Offset(41.46844139968472, 25.293659563324432), + Offset(41.27010101243189, 26.92636481327927), + Offset(41.016658066850894, 28.15371499213396), + Offset(40.76530433184814, 29.07391078562816), + Offset(40.54375026447235, 29.75537376603561), + Offset(40.36460483479899, 30.24657575003085), + Offset(40.232267126058524, 30.582818845166525), + Offset(40.14668845248152, 30.790025921784093), + Offset(40.10532607155808, 30.88755922869572), + ], + <Offset>[ + Offset(7.900000000000001, 12.5), + Offset(8.014551540977447, 12.34129348667129), + Offset(8.43367619739514, 11.787319570526), + Offset(9.370752212067437, 10.679147581356883), + Offset(11.353212200885107, 8.78425951968953), + Offset(15.968094042157917, 5.918283082506218), + Offset(27.94860066169688, 4.6126703021162045), + Offset(39.75021076055942, 12.025407689697397), + Offset(43.158908406262526, 19.060746141324266), + Offset(43.78500226914049, 23.883016197250694), + Offset(43.51813965170684, 27.24071358445474), + Offset(42.96325889126345, 29.644006752557758), + Offset(42.35029926568502, 31.397737279722755), + Offset(41.77438114463072, 32.69087883504286), + Offset(41.2749090730946, 33.64559570562201), + Offset(40.865944555202276, 34.34407628842917), + Offset(40.549700843563855, 34.842850270502765), + Offset(40.32251090061059, 35.18193354923236), + Offset(40.17806375954897, 35.38991891946419), + Offset(40.10887998927547, 35.48755785583344), + ], + <Offset>[ + Offset(7.900000000000001, 12.5), + Offset(8.014551540977447, 12.34129348667129), + Offset(8.43367619739514, 11.787319570526), + Offset(9.370752212067437, 10.679147581356883), + Offset(11.353212200885107, 8.78425951968953), + Offset(15.968094042157917, 5.918283082506218), + Offset(27.94860066169688, 4.6126703021162045), + Offset(39.75021076055942, 12.025407689697397), + Offset(43.158908406262526, 19.060746141324266), + Offset(43.78500226914049, 23.883016197250694), + Offset(43.51813965170684, 27.24071358445474), + Offset(42.96325889126345, 29.644006752557758), + Offset(42.35029926568502, 31.397737279722755), + Offset(41.77438114463072, 32.69087883504286), + Offset(41.2749090730946, 33.64559570562201), + Offset(40.865944555202276, 34.34407628842917), + Offset(40.549700843563855, 34.842850270502765), + Offset(40.32251090061059, 35.18193354923236), + Offset(40.17806375954897, 35.38991891946419), + Offset(40.10887998927547, 35.48755785583344), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(7.900000000000001, 12.5), + Offset(8.014551540977447, 12.34129348667129), + Offset(8.43367619739514, 11.787319570526), + Offset(9.370752212067437, 10.679147581356883), + Offset(11.353212200885107, 8.78425951968953), + Offset(15.968094042157917, 5.918283082506218), + Offset(27.94860066169688, 4.6126703021162045), + Offset(39.75021076055942, 12.025407689697397), + Offset(43.158908406262526, 19.060746141324266), + Offset(43.78500226914049, 23.883016197250694), + Offset(43.51813965170684, 27.24071358445474), + Offset(42.96325889126345, 29.644006752557758), + Offset(42.35029926568502, 31.397737279722755), + Offset(41.77438114463072, 32.69087883504286), + Offset(41.2749090730946, 33.64559570562201), + Offset(40.865944555202276, 34.34407628842917), + Offset(40.549700843563855, 34.842850270502765), + Offset(40.32251090061059, 35.18193354923236), + Offset(40.17806375954897, 35.38991891946419), + Offset(40.10887998927547, 35.48755785583344), + ], + <Offset>[ + Offset(3.3000000000000016, 12.5), + Offset(3.4147766280098404, 12.295787992125664), + Offset(3.8383337983247614, 11.580369732869412), + Offset(4.802941492912208, 10.135911689712586), + Offset(6.904395525334929, 7.614631293565236), + Offset(12.005069007229174, 3.5828104167428108), + Offset(26.075723800682262, 0.4112024320169896), + Offset(41.1117922138676, 7.631537420105092), + Offset(46.11610001573439, 15.537251032079869), + Offset(47.512302184552304, 21.18723517117103), + Offset(47.64869493506418, 25.216235120472277), + Offset(47.31360608049677, 28.14918926097903), + Offset(46.8216717321285, 30.317539026469625), + Offset(46.31154498753962, 31.933155757263034), + Offset(45.84659399308845, 33.13599096437555), + Offset(45.45464707759584, 34.021881997699246), + Offset(45.14597536403577, 34.6577542617379), + Offset(44.92162560467643, 35.0916897746803), + Offset(44.77795675722907, 35.358543612396744), + Offset(44.70887861641319, 35.48400393811605), + ], + <Offset>[ + Offset(3.3000000000000016, 12.5), + Offset(3.4147766280098404, 12.295787992125664), + Offset(3.8383337983247614, 11.580369732869412), + Offset(4.802941492912208, 10.135911689712586), + Offset(6.904395525334929, 7.614631293565236), + Offset(12.005069007229174, 3.5828104167428108), + Offset(26.075723800682262, 0.4112024320169896), + Offset(41.1117922138676, 7.631537420105092), + Offset(46.11610001573439, 15.537251032079869), + Offset(47.512302184552304, 21.18723517117103), + Offset(47.64869493506418, 25.216235120472277), + Offset(47.31360608049677, 28.14918926097903), + Offset(46.8216717321285, 30.317539026469625), + Offset(46.31154498753962, 31.933155757263034), + Offset(45.84659399308845, 33.13599096437555), + Offset(45.45464707759584, 34.021881997699246), + Offset(45.14597536403577, 34.6577542617379), + Offset(44.92162560467643, 35.0916897746803), + Offset(44.77795675722907, 35.358543612396744), + Offset(44.70887861641319, 35.48400393811605), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.3000000000000016, 12.5), + Offset(3.4147766280098404, 12.295787992125664), + Offset(3.8383337983247614, 11.580369732869412), + Offset(4.802941492912208, 10.135911689712586), + Offset(6.904395525334929, 7.614631293565236), + Offset(12.005069007229174, 3.5828104167428108), + Offset(26.075723800682262, 0.4112024320169896), + Offset(41.1117922138676, 7.631537420105092), + Offset(46.11610001573439, 15.537251032079869), + Offset(47.512302184552304, 21.18723517117103), + Offset(47.64869493506418, 25.216235120472277), + Offset(47.31360608049677, 28.14918926097903), + Offset(46.8216717321285, 30.317539026469625), + Offset(46.31154498753962, 31.933155757263034), + Offset(45.84659399308845, 33.13599096437555), + Offset(45.45464707759584, 34.021881997699246), + Offset(45.14597536403577, 34.6577542617379), + Offset(44.92162560467643, 35.0916897746803), + Offset(44.77795675722907, 35.358543612396744), + Offset(44.70887861641319, 35.48400393811605), + ], + <Offset>[ + Offset(3.3000000000000016, 17.1), + Offset(3.3692711334642134, 16.89556290509327), + Offset(3.631383960668174, 16.17571213193979), + Offset(4.25970560126791, 14.703722408867815), + Offset(5.734767299210637, 12.063447969115414), + Offset(9.669596341465768, 7.545835451671554), + Offset(21.874255930583047, 2.2840792930316054), + Offset(36.7179219442753, 6.269955966796905), + Offset(42.592604906489996, 12.580059422608004), + Offset(44.81652115847264, 17.459935255759223), + Offset(45.624216471081716, 21.085679837114938), + Offset(45.81878858891804, 23.798842071745703), + Offset(45.74147347887537, 25.84616656002614), + Offset(45.55382190975979, 27.395991914354134), + Offset(45.33698925184199, 28.564306044381702), + Offset(45.13245278686591, 29.433179475305685), + Offset(44.960879355270905, 30.061479741265988), + Offset(44.831381830124364, 30.492575070614457), + Offset(44.74658145016162, 30.758650614716647), + Offset(44.7053246986958, 30.884005310978335), + ], + <Offset>[ + Offset(3.3000000000000016, 17.1), + Offset(3.3692711334642134, 16.89556290509327), + Offset(3.631383960668174, 16.17571213193979), + Offset(4.25970560126791, 14.703722408867815), + Offset(5.734767299210637, 12.063447969115414), + Offset(9.669596341465768, 7.545835451671554), + Offset(21.874255930583047, 2.2840792930316054), + Offset(36.7179219442753, 6.269955966796905), + Offset(42.592604906489996, 12.580059422608004), + Offset(44.81652115847264, 17.459935255759223), + Offset(45.624216471081716, 21.085679837114938), + Offset(45.81878858891804, 23.798842071745703), + Offset(45.74147347887537, 25.84616656002614), + Offset(45.55382190975979, 27.395991914354134), + Offset(45.33698925184199, 28.564306044381702), + Offset(45.13245278686591, 29.433179475305685), + Offset(44.960879355270905, 30.061479741265988), + Offset(44.831381830124364, 30.492575070614457), + Offset(44.74658145016162, 30.758650614716647), + Offset(44.7053246986958, 30.884005310978335), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.878048780488, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(3.3000000000000016, 26.3), + Offset(3.2782601443729593, 26.095112731028483), + Offset(3.217484285354999, 25.366396930080548), + Offset(3.1732338179793156, 23.839343847178277), + Offset(3.3955108469620523, 20.961081320215772), + Offset(4.998651009938952, 15.471885521529039), + Offset(13.471320190384617, 6.029833015060841), + Offset(27.930181405090686, 3.5467930601805335), + Offset(35.545614688001194, 6.665676203664274), + Offset(39.42495910631331, 10.005335424935609), + Offset(41.57525954311679, 12.824569270400263), + Offset(42.82915360576058, 15.098147693279058), + Offset(43.58107697236911, 16.903421627139174), + Offset(44.03837575420013, 18.32166422853633), + Offset(44.31777976934908, 19.420936204394014), + Offset(44.48806420540607, 20.25577443051856), + Offset(44.59068733774117, 20.86893070032216), + Offset(44.650894281020236, 21.294345662482787), + Offset(44.68383083602673, 21.558864619356445), + Offset(44.698216863261024, 21.684008056702904), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.3000000000000016, 26.3), + Offset(3.2782601443729593, 26.095112731028483), + Offset(3.217484285354999, 25.366396930080548), + Offset(3.1732338179793156, 23.839343847178277), + Offset(3.3955108469620523, 20.961081320215772), + Offset(4.998651009938952, 15.471885521529039), + Offset(13.471320190384617, 6.029833015060841), + Offset(27.930181405090686, 3.5467930601805335), + Offset(35.545614688001194, 6.665676203664274), + Offset(39.42495910631331, 10.005335424935609), + Offset(41.57525954311679, 12.824569270400263), + Offset(42.82915360576058, 15.098147693279058), + Offset(43.58107697236911, 16.903421627139174), + Offset(44.03837575420013, 18.32166422853633), + Offset(44.31777976934908, 19.420936204394014), + Offset(44.48806420540607, 20.25577443051856), + Offset(44.59068733774117, 20.86893070032216), + Offset(44.650894281020236, 21.294345662482787), + Offset(44.68383083602673, 21.558864619356445), + Offset(44.698216863261024, 21.684008056702904), + ], + <Offset>[ + Offset(7.900000000000001, 26.3), + Offset(7.878035057340566, 26.14061822557411), + Offset(7.812826684425378, 25.573346767737135), + Offset(7.741044537134545, 24.382579738822574), + Offset(7.844327522512231, 22.130709546340064), + Offset(8.961676044867694, 17.807358187292447), + Offset(15.344197051399235, 10.231300885160056), + Offset(26.568599951782502, 7.940663329772839), + Offset(32.58842307852933, 10.189171312908673), + Offset(35.6976591909015, 12.701116451015272), + Offset(37.444704259759455, 14.84904773438272), + Offset(38.47880641652726, 16.592965184857785), + Offset(39.10970450592563, 17.983619880392304), + Offset(39.501211911291236, 19.079387306316157), + Offset(39.74609484935523, 19.930540945640473), + Offset(39.89936168301251, 20.577968721248485), + Offset(39.99441281726926, 21.054026709087022), + Offset(40.051779576954395, 21.384589437034855), + Offset(40.08393783834663, 21.59023992642389), + Offset(40.09821823612331, 21.68756197442029), + ], + <Offset>[ + Offset(7.900000000000001, 26.3), + Offset(7.878035057340566, 26.14061822557411), + Offset(7.812826684425378, 25.573346767737135), + Offset(7.741044537134545, 24.382579738822574), + Offset(7.844327522512231, 22.130709546340064), + Offset(8.961676044867694, 17.807358187292447), + Offset(15.344197051399235, 10.231300885160056), + Offset(26.568599951782502, 7.940663329772839), + Offset(32.58842307852933, 10.189171312908673), + Offset(35.6976591909015, 12.701116451015272), + Offset(37.444704259759455, 14.84904773438272), + Offset(38.47880641652726, 16.592965184857785), + Offset(39.10970450592563, 17.983619880392304), + Offset(39.501211911291236, 19.079387306316157), + Offset(39.74609484935523, 19.930540945640473), + Offset(39.89936168301251, 20.577968721248485), + Offset(39.99441281726926, 21.054026709087022), + Offset(40.051779576954395, 21.384589437034855), + Offset(40.08393783834663, 21.59023992642389), + Offset(40.09821823612331, 21.68756197442029), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(7.900000000000001, 26.3), + Offset(7.878035057340566, 26.14061822557411), + Offset(7.812826684425378, 25.573346767737135), + Offset(7.741044537134545, 24.382579738822574), + Offset(7.844327522512231, 22.130709546340064), + Offset(8.961676044867694, 17.807358187292447), + Offset(15.344197051399235, 10.231300885160056), + Offset(26.568599951782502, 7.940663329772839), + Offset(32.58842307852933, 10.189171312908673), + Offset(35.6976591909015, 12.701116451015272), + Offset(37.444704259759455, 14.84904773438272), + Offset(38.47880641652726, 16.592965184857785), + Offset(39.10970450592563, 17.983619880392304), + Offset(39.501211911291236, 19.079387306316157), + Offset(39.74609484935523, 19.930540945640473), + Offset(39.89936168301251, 20.577968721248485), + Offset(39.99441281726926, 21.054026709087022), + Offset(40.051779576954395, 21.384589437034855), + Offset(40.08393783834663, 21.59023992642389), + Offset(40.09821823612331, 21.68756197442029), + ], + <Offset>[ + Offset(7.900000000000001, 21.7), + Offset(7.923540551886193, 21.5408433126065), + Offset(8.019776522081965, 20.97800436866676), + Offset(8.284280428778843, 19.814769019667345), + Offset(9.013955748636523, 17.681892870789884), + Offset(11.2971487106311, 13.844333152363703), + Offset(19.54566492149845, 8.358424024145439), + Offset(30.962470221374808, 9.302244783081026), + Offset(36.111918187773725, 13.146362922380538), + Offset(38.39344021698116, 16.42841636642708), + Offset(39.469182723741916, 18.97960301774006), + Offset(39.97362390810599, 20.94331237409111), + Offset(40.18990275917876, 22.454992346835787), + Offset(40.258934989071065, 23.616551149225057), + Offset(40.25569959060169, 24.50222586563432), + Offset(40.22155597374243, 25.166671243642046), + Offset(40.17950882603412, 25.650301229558934), + Offset(40.14202335150646, 25.98370414110069), + Offset(40.11531314541408, 26.190132924103988), + Offset(40.1017721538407, 26.287560601558003), + ], + <Offset>[ + Offset(7.900000000000001, 21.7), + Offset(7.923540551886193, 21.5408433126065), + Offset(8.019776522081965, 20.97800436866676), + Offset(8.284280428778843, 19.814769019667345), + Offset(9.013955748636523, 17.681892870789884), + Offset(11.2971487106311, 13.844333152363703), + Offset(19.54566492149845, 8.358424024145439), + Offset(30.962470221374808, 9.302244783081026), + Offset(36.111918187773725, 13.146362922380538), + Offset(38.39344021698116, 16.42841636642708), + Offset(39.469182723741916, 18.97960301774006), + Offset(39.97362390810599, 20.94331237409111), + Offset(40.18990275917876, 22.454992346835787), + Offset(40.258934989071065, 23.616551149225057), + Offset(40.25569959060169, 24.50222586563432), + Offset(40.22155597374243, 25.166671243642046), + Offset(40.17950882603412, 25.650301229558934), + Offset(40.14202335150646, 25.98370414110069), + Offset(40.11531314541408, 26.190132924103988), + Offset(40.1017721538407, 26.287560601558003), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(7.900000000000001, 21.7), + Offset(7.923540551886193, 21.5408433126065), + Offset(8.019776522081965, 20.97800436866676), + Offset(8.284280428778843, 19.814769019667345), + Offset(9.013955748636523, 17.681892870789884), + Offset(11.2971487106311, 13.844333152363703), + Offset(19.54566492149845, 8.358424024145439), + Offset(30.962470221374808, 9.302244783081026), + Offset(36.111918187773725, 13.146362922380538), + Offset(38.39344021698116, 16.42841636642708), + Offset(39.469182723741916, 18.97960301774006), + Offset(39.97362390810599, 20.94331237409111), + Offset(40.18990275917876, 22.454992346835787), + Offset(40.258934989071065, 23.616551149225057), + Offset(40.25569959060169, 24.50222586563432), + Offset(40.22155597374243, 25.166671243642046), + Offset(40.17950882603412, 25.650301229558934), + Offset(40.14202335150646, 25.98370414110069), + Offset(40.11531314541408, 26.190132924103988), + Offset(40.1017721538407, 26.287560601558003), + ], + <Offset>[ + Offset(3.3000000000000016, 21.7), + Offset(3.3237656389185863, 21.495337818060875), + Offset(3.4244341230115865, 20.771054531010172), + Offset(3.716469709623613, 19.271533128023048), + Offset(4.565139073086344, 16.512264644665592), + Offset(7.334123675702358, 11.508860486600296), + Offset(17.672788060483832, 4.156956154046225), + Offset(32.32405167468299, 4.90837451348872), + Offset(39.06910979724559, 9.62286781313614), + Offset(42.120740132392974, 13.732635340347416), + Offset(43.599738007099255, 16.9551245537576), + Offset(44.32397109733931, 19.44849488251238), + Offset(44.66127522562224, 21.374794093582658), + Offset(44.79609883197996, 22.85882807144523), + Offset(44.827384510595536, 23.99262112438786), + Offset(44.810258496135994, 24.84447695291212), + Offset(44.77578334650604, 25.465205220794072), + Offset(44.7411380555723, 25.893460366548624), + Offset(44.71520614309418, 26.158757617036542), + Offset(44.701770780978414, 26.284006683840616), + ], + <Offset>[ + Offset(3.3000000000000016, 21.7), + Offset(3.3237656389185863, 21.495337818060875), + Offset(3.4244341230115865, 20.771054531010172), + Offset(3.716469709623613, 19.271533128023048), + Offset(4.565139073086344, 16.512264644665592), + Offset(7.334123675702358, 11.508860486600296), + Offset(17.672788060483832, 4.156956154046225), + Offset(32.32405167468299, 4.90837451348872), + Offset(39.06910979724559, 9.62286781313614), + Offset(42.120740132392974, 13.732635340347416), + Offset(43.599738007099255, 16.9551245537576), + Offset(44.32397109733931, 19.44849488251238), + Offset(44.66127522562224, 21.374794093582658), + Offset(44.79609883197996, 22.85882807144523), + Offset(44.827384510595536, 23.99262112438786), + Offset(44.810258496135994, 24.84447695291212), + Offset(44.77578334650604, 25.465205220794072), + Offset(44.7411380555723, 25.893460366548624), + Offset(44.71520614309418, 26.158757617036542), + Offset(44.701770780978414, 26.284006683840616), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.3000000000000016, 21.7), + Offset(3.3237656389185863, 21.495337818060875), + Offset(3.4244341230115865, 20.771054531010172), + Offset(3.716469709623613, 19.271533128023048), + Offset(4.565139073086344, 16.512264644665592), + Offset(7.334123675702358, 11.508860486600296), + Offset(17.672788060483832, 4.156956154046225), + Offset(32.32405167468299, 4.90837451348872), + Offset(39.06910979724559, 9.62286781313614), + Offset(42.120740132392974, 13.732635340347416), + Offset(43.599738007099255, 16.9551245537576), + Offset(44.32397109733931, 19.44849488251238), + Offset(44.66127522562224, 21.374794093582658), + Offset(44.79609883197996, 22.85882807144523), + Offset(44.827384510595536, 23.99262112438786), + Offset(44.810258496135994, 24.84447695291212), + Offset(44.77578334650604, 25.465205220794072), + Offset(44.7411380555723, 25.893460366548624), + Offset(44.71520614309418, 26.158757617036542), + Offset(44.701770780978414, 26.284006683840616), + ], + <Offset>[ + Offset(3.3000000000000016, 26.3), + Offset(3.2782601443729593, 26.095112731028483), + Offset(3.217484285354999, 25.366396930080548), + Offset(3.1732338179793156, 23.839343847178277), + Offset(3.3955108469620523, 20.961081320215772), + Offset(4.998651009938952, 15.471885521529039), + Offset(13.471320190384617, 6.029833015060841), + Offset(27.930181405090686, 3.5467930601805335), + Offset(35.545614688001194, 6.665676203664274), + Offset(39.42495910631331, 10.005335424935609), + Offset(41.57525954311679, 12.824569270400263), + Offset(42.82915360576058, 15.098147693279058), + Offset(43.58107697236911, 16.903421627139174), + Offset(44.03837575420013, 18.32166422853633), + Offset(44.31777976934908, 19.420936204394014), + Offset(44.48806420540607, 20.25577443051856), + Offset(44.59068733774117, 20.86893070032216), + Offset(44.650894281020236, 21.294345662482787), + Offset(44.68383083602673, 21.558864619356445), + Offset(44.698216863261024, 21.684008056702904), + ], + <Offset>[ + Offset(3.3000000000000016, 26.3), + Offset(3.2782601443729593, 26.095112731028483), + Offset(3.217484285354999, 25.366396930080548), + Offset(3.1732338179793156, 23.839343847178277), + Offset(3.3955108469620523, 20.961081320215772), + Offset(4.998651009938952, 15.471885521529039), + Offset(13.471320190384617, 6.029833015060841), + Offset(27.930181405090686, 3.5467930601805335), + Offset(35.545614688001194, 6.665676203664274), + Offset(39.42495910631331, 10.005335424935609), + Offset(41.57525954311679, 12.824569270400263), + Offset(42.82915360576058, 15.098147693279058), + Offset(43.58107697236911, 16.903421627139174), + Offset(44.03837575420013, 18.32166422853633), + Offset(44.31777976934908, 19.420936204394014), + Offset(44.48806420540607, 20.25577443051856), + Offset(44.59068733774117, 20.86893070032216), + Offset(44.650894281020236, 21.294345662482787), + Offset(44.68383083602673, 21.558864619356445), + Offset(44.698216863261024, 21.684008056702904), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.878048780488, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(12.5, 35.5), + Offset(12.386798981216916, 35.38567354605495), + Offset(11.994269408182586, 34.97098140353448), + Offset(11.222383473001184, 34.06143706877733), + Offset(9.953887745813823, 32.19797112356471), + Offset(8.253755748269624, 28.068880922913333), + Offset(8.81413817221542, 18.1785224772885), + Offset(16.419277959289705, 9.611370692748771), + Offset(22.584241250568667, 7.798283203209337), + Offset(26.57879722333036, 7.942297646271321), + Offset(29.2651920484372, 8.612415631650505), + Offset(31.13882424413648, 9.387088297969871), + Offset(32.47793553297588, 10.121073200758469), + Offset(33.44860191282268, 10.762782698278183), + Offset(34.15520044686847, 11.296775846899239), + Offset(34.666270579159104, 11.72275796719129), + Offset(35.027946279267624, 12.046573676908062), + Offset(35.27217732378443, 12.276603803455243), + Offset(35.42129422653164, 12.421829238131133), + Offset(35.49111177355083, 12.491118637862245), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.5, 35.5), + Offset(12.386798981216916, 35.38567354605495), + Offset(11.994269408182586, 34.97098140353448), + Offset(11.222383473001184, 34.06143706877733), + Offset(9.953887745813823, 32.19797112356471), + Offset(8.253755748269624, 28.068880922913333), + Offset(8.81413817221542, 18.1785224772885), + Offset(16.419277959289705, 9.611370692748771), + Offset(22.584241250568667, 7.798283203209337), + Offset(26.57879722333036, 7.942297646271321), + Offset(29.2651920484372, 8.612415631650505), + Offset(31.13882424413648, 9.387088297969871), + Offset(32.47793553297588, 10.121073200758469), + Offset(33.44860191282268, 10.762782698278183), + Offset(34.15520044686847, 11.296775846899239), + Offset(34.666270579159104, 11.72275796719129), + Offset(35.027946279267624, 12.046573676908062), + Offset(35.27217732378443, 12.276603803455243), + Offset(35.42129422653164, 12.421829238131133), + Offset(35.49111177355083, 12.491118637862245), + ], + <Offset>[ + Offset(44.699999999999996, 35.5), + Offset(44.58522337199017, 35.70421200787435), + Offset(44.161666201675246, 36.41963026713059), + Offset(43.197058507087796, 37.86408831028741), + Offset(41.09560447466507, 40.38536870643476), + Offset(35.994930992770826, 44.41718958325718), + Offset(21.92427619931773, 47.58879756798301), + Offset(6.8882077861324005, 40.36846257989491), + Offset(1.8838999842656072, 32.46274896792012), + Offset(0.4876978154477065, 26.81276482882897), + Offset(0.3513050649358309, 22.783764879527716), + Offset(0.6863939195032227, 19.85081073902098), + Offset(1.1783282678714926, 17.682460973530382), + Offset(1.6884550124603805, 16.066844242736977), + Offset(2.1534060069115526, 14.864009035624443), + Offset(2.5453529224041667, 13.978118002300755), + Offset(2.854024635964233, 13.34224573826211), + Offset(3.0783743953235785, 12.9083102253197), + Offset(3.222043242770944, 12.641456387603249), + Offset(3.2911213835868267, 12.515996061883946), + ], + <Offset>[ + Offset(44.699999999999996, 35.5), + Offset(44.58522337199017, 35.70421200787435), + Offset(44.161666201675246, 36.41963026713059), + Offset(43.197058507087796, 37.86408831028741), + Offset(41.09560447466507, 40.38536870643476), + Offset(35.994930992770826, 44.41718958325718), + Offset(21.92427619931773, 47.58879756798301), + Offset(6.8882077861324005, 40.36846257989491), + Offset(1.8838999842656072, 32.46274896792012), + Offset(0.4876978154477065, 26.81276482882897), + Offset(0.3513050649358309, 22.783764879527716), + Offset(0.6863939195032227, 19.85081073902098), + Offset(1.1783282678714926, 17.682460973530382), + Offset(1.6884550124603805, 16.066844242736977), + Offset(2.1534060069115526, 14.864009035624443), + Offset(2.5453529224041667, 13.978118002300755), + Offset(2.854024635964233, 13.34224573826211), + Offset(3.0783743953235785, 12.9083102253197), + Offset(3.222043242770944, 12.641456387603249), + Offset(3.2911213835868267, 12.515996061883946), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.699999999999996, 35.5), + Offset(44.58522337199017, 35.70421200787435), + Offset(44.161666201675246, 36.41963026713059), + Offset(43.197058507087796, 37.86408831028741), + Offset(41.09560447466507, 40.38536870643476), + Offset(35.994930992770826, 44.41718958325718), + Offset(21.92427619931773, 47.58879756798301), + Offset(6.8882077861324005, 40.36846257989491), + Offset(1.8838999842656072, 32.46274896792012), + Offset(0.4876978154477065, 26.81276482882897), + Offset(0.3513050649358309, 22.783764879527716), + Offset(0.6863939195032227, 19.85081073902098), + Offset(1.1783282678714926, 17.682460973530382), + Offset(1.6884550124603805, 16.066844242736977), + Offset(2.1534060069115526, 14.864009035624443), + Offset(2.5453529224041667, 13.978118002300755), + Offset(2.854024635964233, 13.34224573826211), + Offset(3.0783743953235785, 12.9083102253197), + Offset(3.222043242770944, 12.641456387603249), + Offset(3.2911213835868267, 12.515996061883946), + ], + <Offset>[ + Offset(44.699999999999996, 30.900000000000002), + Offset(44.63072886653579, 31.104437094906736), + Offset(44.368616039331826, 31.82428786806021), + Offset(43.74029439873209, 33.296277591132174), + Offset(42.26523270078937, 35.936552030884584), + Offset(38.33040365853423, 40.454164548328436), + Offset(26.125744069416946, 45.71592070696839), + Offset(11.282078055724707, 41.73004403320309), + Offset(5.407395093510004, 35.41994057739199), + Offset(3.1834788415273714, 30.54006474424078), + Offset(2.375783528918289, 26.914320162885055), + Offset(2.181211411081952, 24.2011579282543), + Offset(2.2585265211246224, 22.153833439973866), + Offset(2.446178090240206, 20.604008085645876), + Offset(2.66301074815801, 19.43569395561829), + Offset(2.8675472131340918, 18.566820524694318), + Offset(3.0391206447290973, 17.938520258734023), + Offset(3.168618169875643, 17.507424929385536), + Offset(3.2534185498383863, 17.24134938528335), + Offset(3.29467530130421, 17.11599468902166), + ], + <Offset>[ + Offset(44.699999999999996, 30.900000000000002), + Offset(44.63072886653579, 31.104437094906736), + Offset(44.368616039331826, 31.82428786806021), + Offset(43.74029439873209, 33.296277591132174), + Offset(42.26523270078937, 35.936552030884584), + Offset(38.33040365853423, 40.454164548328436), + Offset(26.125744069416946, 45.71592070696839), + Offset(11.282078055724707, 41.73004403320309), + Offset(5.407395093510004, 35.41994057739199), + Offset(3.1834788415273714, 30.54006474424078), + Offset(2.375783528918289, 26.914320162885055), + Offset(2.181211411081952, 24.2011579282543), + Offset(2.2585265211246224, 22.153833439973866), + Offset(2.446178090240206, 20.604008085645876), + Offset(2.66301074815801, 19.43569395561829), + Offset(2.8675472131340918, 18.566820524694318), + Offset(3.0391206447290973, 17.938520258734023), + Offset(3.168618169875643, 17.507424929385536), + Offset(3.2534185498383863, 17.24134938528335), + Offset(3.29467530130421, 17.11599468902166), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.699999999999996, 30.900000000000002), + Offset(44.63072886653579, 31.104437094906736), + Offset(44.368616039331826, 31.82428786806021), + Offset(43.74029439873209, 33.296277591132174), + Offset(42.26523270078937, 35.936552030884584), + Offset(38.33040365853423, 40.454164548328436), + Offset(26.125744069416946, 45.71592070696839), + Offset(11.282078055724707, 41.73004403320309), + Offset(5.407395093510004, 35.41994057739199), + Offset(3.1834788415273714, 30.54006474424078), + Offset(2.375783528918289, 26.914320162885055), + Offset(2.181211411081952, 24.2011579282543), + Offset(2.2585265211246224, 22.153833439973866), + Offset(2.446178090240206, 20.604008085645876), + Offset(2.66301074815801, 19.43569395561829), + Offset(2.8675472131340918, 18.566820524694318), + Offset(3.0391206447290973, 17.938520258734023), + Offset(3.168618169875643, 17.507424929385536), + Offset(3.2534185498383863, 17.24134938528335), + Offset(3.29467530130421, 17.11599468902166), + ], + <Offset>[ + Offset(12.5, 30.900000000000002), + Offset(12.432304475762546, 30.785898633087346), + Offset(12.201219245839173, 30.3756390044641), + Offset(11.765619364645481, 29.493626349622097), + Offset(11.123515971938117, 27.749154448014536), + Offset(10.589228414033032, 24.10585588798459), + Offset(13.015606042314635, 16.305645616273882), + Offset(20.81314822888201, 10.972952146056956), + Offset(26.107736359813064, 10.755474812681204), + Offset(29.274578249410023, 11.66959756168313), + Offset(31.28967051241966, 12.742970915007843), + Offset(32.63364173571521, 13.737435487203195), + Offset(33.55813378622901, 14.592445667201952), + Offset(34.20632499060251, 15.299946541187085), + Offset(34.664805188114926, 15.868460766893085), + Offset(34.98846486988903, 16.311460489584853), + Offset(35.21304228803248, 16.642848197379976), + Offset(35.3624210983365, 16.87571850752108), + Offset(35.452669533599085, 17.021722235811232), + Offset(35.49466569126821, 17.09111726499996), + ], + <Offset>[ + Offset(12.5, 30.900000000000002), + Offset(12.432304475762546, 30.785898633087346), + Offset(12.201219245839173, 30.3756390044641), + Offset(11.765619364645481, 29.493626349622097), + Offset(11.123515971938117, 27.749154448014536), + Offset(10.589228414033032, 24.10585588798459), + Offset(13.015606042314635, 16.305645616273882), + Offset(20.81314822888201, 10.972952146056956), + Offset(26.107736359813064, 10.755474812681204), + Offset(29.274578249410023, 11.66959756168313), + Offset(31.28967051241966, 12.742970915007843), + Offset(32.63364173571521, 13.737435487203195), + Offset(33.55813378622901, 14.592445667201952), + Offset(34.20632499060251, 15.299946541187085), + Offset(34.664805188114926, 15.868460766893085), + Offset(34.98846486988903, 16.311460489584853), + Offset(35.21304228803248, 16.642848197379976), + Offset(35.3624210983365, 16.87571850752108), + Offset(35.452669533599085, 17.021722235811232), + Offset(35.49466569126821, 17.09111726499996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.5, 30.900000000000002), + Offset(12.432304475762546, 30.785898633087346), + Offset(12.201219245839173, 30.3756390044641), + Offset(11.765619364645481, 29.493626349622097), + Offset(11.123515971938117, 27.749154448014536), + Offset(10.589228414033032, 24.10585588798459), + Offset(13.015606042314635, 16.305645616273882), + Offset(20.81314822888201, 10.972952146056956), + Offset(26.107736359813064, 10.755474812681204), + Offset(29.274578249410023, 11.66959756168313), + Offset(31.28967051241966, 12.742970915007843), + Offset(32.63364173571521, 13.737435487203195), + Offset(33.55813378622901, 14.592445667201952), + Offset(34.20632499060251, 15.299946541187085), + Offset(34.664805188114926, 15.868460766893085), + Offset(34.98846486988903, 16.311460489584853), + Offset(35.21304228803248, 16.642848197379976), + Offset(35.3624210983365, 16.87571850752108), + Offset(35.452669533599085, 17.021722235811232), + Offset(35.49466569126821, 17.09111726499996), + ], + <Offset>[ + Offset(12.5, 35.5), + Offset(12.386798981216916, 35.38567354605495), + Offset(11.994269408182586, 34.97098140353448), + Offset(11.222383473001184, 34.06143706877733), + Offset(9.953887745813823, 32.19797112356471), + Offset(8.253755748269624, 28.068880922913333), + Offset(8.81413817221542, 18.1785224772885), + Offset(16.419277959289705, 9.611370692748771), + Offset(22.584241250568667, 7.798283203209337), + Offset(26.57879722333036, 7.942297646271321), + Offset(29.2651920484372, 8.612415631650505), + Offset(31.13882424413648, 9.387088297969871), + Offset(32.47793553297588, 10.121073200758469), + Offset(33.44860191282268, 10.762782698278183), + Offset(34.15520044686847, 11.296775846899239), + Offset(34.666270579159104, 11.72275796719129), + Offset(35.027946279267624, 12.046573676908062), + Offset(35.27217732378443, 12.276603803455243), + Offset(35.42129422653164, 12.421829238131133), + Offset(35.49111177355083, 12.491118637862245), + ], + <Offset>[ + Offset(12.5, 35.5), + Offset(12.386798981216916, 35.38567354605495), + Offset(11.994269408182586, 34.97098140353448), + Offset(11.222383473001184, 34.06143706877733), + Offset(9.953887745813823, 32.19797112356471), + Offset(8.253755748269624, 28.068880922913333), + Offset(8.81413817221542, 18.1785224772885), + Offset(16.419277959289705, 9.611370692748771), + Offset(22.584241250568667, 7.798283203209337), + Offset(26.57879722333036, 7.942297646271321), + Offset(29.2651920484372, 8.612415631650505), + Offset(31.13882424413648, 9.387088297969871), + Offset(32.47793553297588, 10.121073200758469), + Offset(33.44860191282268, 10.762782698278183), + Offset(34.15520044686847, 11.296775846899239), + Offset(34.666270579159104, 11.72275796719129), + Offset(35.027946279267624, 12.046573676908062), + Offset(35.27217732378443, 12.276603803455243), + Offset(35.42129422653164, 12.421829238131133), + Offset(35.49111177355083, 12.491118637862245), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.878048780488, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(12.5, 17.1), + Offset(12.568820959399424, 16.986573894184524), + Offset(12.822068758808932, 16.589611807252965), + Offset(13.395327039578369, 15.790194192156408), + Offset(14.632400650310995, 14.402704421364), + Offset(17.59564641132325, 12.216780783198363), + Offset(25.620009652612282, 10.687015033230036), + Offset(33.99475903765893, 15.057696505981518), + Offset(36.67822168754626, 19.6270496410968), + Offset(37.361921327649014, 22.851497307918553), + Offset(37.36310590436704, 25.13463676507986), + Offset(37.118094210451396, 26.788477054903165), + Offset(36.7987285459884, 28.0065630665324), + Offset(36.479494223942, 28.91143806991379), + Offset(36.1936194118543, 29.58351552687462), + Offset(35.95504774207879, 30.077568056765532), + Offset(35.76833031432708, 30.43167175879571), + Offset(35.63315242199269, 30.673062619718593), + Offset(35.54679545480142, 30.821401228851528), + Offset(35.50532744442037, 30.891113146413097), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.5, 17.1), + Offset(12.568820959399424, 16.986573894184524), + Offset(12.822068758808932, 16.589611807252965), + Offset(13.395327039578369, 15.790194192156408), + Offset(14.632400650310995, 14.402704421364), + Offset(17.59564641132325, 12.216780783198363), + Offset(25.620009652612282, 10.687015033230036), + Offset(33.99475903765893, 15.057696505981518), + Offset(36.67822168754626, 19.6270496410968), + Offset(37.361921327649014, 22.851497307918553), + Offset(37.36310590436704, 25.13463676507986), + Offset(37.118094210451396, 26.788477054903165), + Offset(36.7987285459884, 28.0065630665324), + Offset(36.479494223942, 28.91143806991379), + Offset(36.1936194118543, 29.58351552687462), + Offset(35.95504774207879, 30.077568056765532), + Offset(35.76833031432708, 30.43167175879571), + Offset(35.63315242199269, 30.673062619718593), + Offset(35.54679545480142, 30.821401228851528), + Offset(35.50532744442037, 30.891113146413097), + ], + <Offset>[ + Offset(44.699999999999996, 17.1), + Offset(44.76724535017267, 17.305112356003914), + Offset(44.98946555230159, 18.038260670849073), + Offset(45.37000207366498, 19.592845433666486), + Offset(45.77411737916225, 22.590102004234048), + Offset(45.33682165582445, 28.565089443542213), + Offset(38.7301476797146, 40.09729012392454), + Offset(24.463688864501623, 45.81478839312766), + Offset(15.977880421243203, 44.29151540580759), + Offset(11.270821919766366, 41.7219644904762), + Offset(8.44921892086567, 39.30598601295708), + Offset(6.665663885818139, 37.25219949595427), + Offset(5.499121280884019, 35.56795083930431), + Offset(4.71934732357969, 34.21549961437258), + Offset(4.191824971897383, 33.150748715599825), + Offset(3.83413008532386, 32.332928091875), + Offset(3.5944086710236895, 31.727343820149756), + Offset(3.439349493531836, 31.30476904158305), + Offset(3.3475444710407203, 31.041028378323645), + Offset(3.3053370544563663, 30.9159905704348), + ], + <Offset>[ + Offset(44.699999999999996, 17.1), + Offset(44.76724535017267, 17.305112356003914), + Offset(44.98946555230159, 18.038260670849073), + Offset(45.37000207366498, 19.592845433666486), + Offset(45.77411737916225, 22.590102004234048), + Offset(45.33682165582445, 28.565089443542213), + Offset(38.7301476797146, 40.09729012392454), + Offset(24.463688864501623, 45.81478839312766), + Offset(15.977880421243203, 44.29151540580759), + Offset(11.270821919766366, 41.7219644904762), + Offset(8.44921892086567, 39.30598601295708), + Offset(6.665663885818139, 37.25219949595427), + Offset(5.499121280884019, 35.56795083930431), + Offset(4.71934732357969, 34.21549961437258), + Offset(4.191824971897383, 33.150748715599825), + Offset(3.83413008532386, 32.332928091875), + Offset(3.5944086710236895, 31.727343820149756), + Offset(3.439349493531836, 31.30476904158305), + Offset(3.3475444710407203, 31.041028378323645), + Offset(3.3053370544563663, 30.9159905704348), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.699999999999996, 17.1), + Offset(44.76724535017267, 17.305112356003914), + Offset(44.98946555230159, 18.038260670849073), + Offset(45.37000207366498, 19.592845433666486), + Offset(45.77411737916225, 22.590102004234048), + Offset(45.33682165582445, 28.565089443542213), + Offset(38.7301476797146, 40.09729012392454), + Offset(24.463688864501623, 45.81478839312766), + Offset(15.977880421243203, 44.29151540580759), + Offset(11.270821919766366, 41.7219644904762), + Offset(8.44921892086567, 39.30598601295708), + Offset(6.665663885818139, 37.25219949595427), + Offset(5.499121280884019, 35.56795083930431), + Offset(4.71934732357969, 34.21549961437258), + Offset(4.191824971897383, 33.150748715599825), + Offset(3.83413008532386, 32.332928091875), + Offset(3.5944086710236895, 31.727343820149756), + Offset(3.439349493531836, 31.30476904158305), + Offset(3.3475444710407203, 31.041028378323645), + Offset(3.3053370544563663, 30.9159905704348), + ], + <Offset>[ + Offset(44.699999999999996, 12.5), + Offset(44.8127508447183, 12.705337443036306), + Offset(45.196415389958176, 13.442918271778694), + Offset(45.91323796530928, 15.025034714511255), + Offset(46.94374560528654, 18.14128532868387), + Offset(47.67229432158786, 24.60206440861347), + Offset(42.93161554981381, 38.22441326290992), + Offset(28.85755913409393, 47.17636984643584), + Offset(19.5013755304876, 47.24870701527945), + Offset(13.96660294584603, 45.449264405888016), + Offset(10.473697384848128, 43.43654129631442), + Offset(8.160481377396868, 41.60254668518759), + Offset(6.579319534137149, 40.03932330574779), + Offset(5.477070401359516, 38.75266345728148), + Offset(4.70142971314384, 37.722433635593674), + Offset(4.156324376053785, 36.92163061426856), + Offset(3.7795046797885536, 36.32361834062167), + Offset(3.5295932680839, 35.90388374564888), + Offset(3.3789197781081626, 35.640921376003746), + Offset(3.3088909721737494, 35.515989197572516), + ], + <Offset>[ + Offset(44.699999999999996, 12.5), + Offset(44.8127508447183, 12.705337443036306), + Offset(45.196415389958176, 13.442918271778694), + Offset(45.91323796530928, 15.025034714511255), + Offset(46.94374560528654, 18.14128532868387), + Offset(47.67229432158786, 24.60206440861347), + Offset(42.93161554981381, 38.22441326290992), + Offset(28.85755913409393, 47.17636984643584), + Offset(19.5013755304876, 47.24870701527945), + Offset(13.96660294584603, 45.449264405888016), + Offset(10.473697384848128, 43.43654129631442), + Offset(8.160481377396868, 41.60254668518759), + Offset(6.579319534137149, 40.03932330574779), + Offset(5.477070401359516, 38.75266345728148), + Offset(4.70142971314384, 37.722433635593674), + Offset(4.156324376053785, 36.92163061426856), + Offset(3.7795046797885536, 36.32361834062167), + Offset(3.5295932680839, 35.90388374564888), + Offset(3.3789197781081626, 35.640921376003746), + Offset(3.3088909721737494, 35.515989197572516), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.699999999999996, 12.5), + Offset(44.8127508447183, 12.705337443036306), + Offset(45.196415389958176, 13.442918271778694), + Offset(45.91323796530928, 15.025034714511255), + Offset(46.94374560528654, 18.14128532868387), + Offset(47.67229432158786, 24.60206440861347), + Offset(42.93161554981381, 38.22441326290992), + Offset(28.85755913409393, 47.17636984643584), + Offset(19.5013755304876, 47.24870701527945), + Offset(13.96660294584603, 45.449264405888016), + Offset(10.473697384848128, 43.43654129631442), + Offset(8.160481377396868, 41.60254668518759), + Offset(6.579319534137149, 40.03932330574779), + Offset(5.477070401359516, 38.75266345728148), + Offset(4.70142971314384, 37.722433635593674), + Offset(4.156324376053785, 36.92163061426856), + Offset(3.7795046797885536, 36.32361834062167), + Offset(3.5295932680839, 35.90388374564888), + Offset(3.3789197781081626, 35.640921376003746), + Offset(3.3088909721737494, 35.515989197572516), + ], + <Offset>[ + Offset(12.5, 12.5), + Offset(12.614326453945054, 12.386798981216916), + Offset(13.02901859646552, 11.994269408182586), + Offset(13.938562931222666, 11.222383473001177), + Offset(15.802028876435289, 9.953887745813823), + Offset(19.931119077086663, 8.25375574826962), + Offset(29.821477522711497, 8.814138172215419), + Offset(38.388629307251236, 16.4192779592897), + Offset(40.20171679679066, 22.584241250568667), + Offset(40.057702353728686, 26.578797223330362), + Offset(39.3875843683495, 29.2651920484372), + Offset(38.612911702030125, 31.138824244136487), + Offset(37.87892679924153, 32.477935532975884), + Offset(37.23721730172182, 33.44860191282269), + Offset(36.703224153100756, 34.15520044686847), + Offset(36.277242032808715, 34.6662705791591), + Offset(35.953426323091946, 35.027946279267624), + Offset(35.723396196544755, 35.272177323784426), + Offset(35.57817076186886, 35.42129422653163), + Offset(35.50888136213775, 35.49111177355081), + ], + <Offset>[ + Offset(12.5, 12.5), + Offset(12.614326453945054, 12.386798981216916), + Offset(13.02901859646552, 11.994269408182586), + Offset(13.938562931222666, 11.222383473001177), + Offset(15.802028876435289, 9.953887745813823), + Offset(19.931119077086663, 8.25375574826962), + Offset(29.821477522711497, 8.814138172215419), + Offset(38.388629307251236, 16.4192779592897), + Offset(40.20171679679066, 22.584241250568667), + Offset(40.057702353728686, 26.578797223330362), + Offset(39.3875843683495, 29.2651920484372), + Offset(38.612911702030125, 31.138824244136487), + Offset(37.87892679924153, 32.477935532975884), + Offset(37.23721730172182, 33.44860191282269), + Offset(36.703224153100756, 34.15520044686847), + Offset(36.277242032808715, 34.6662705791591), + Offset(35.953426323091946, 35.027946279267624), + Offset(35.723396196544755, 35.272177323784426), + Offset(35.57817076186886, 35.42129422653163), + Offset(35.50888136213775, 35.49111177355081), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.5, 12.5), + Offset(12.614326453945054, 12.386798981216916), + Offset(13.02901859646552, 11.994269408182586), + Offset(13.938562931222666, 11.222383473001177), + Offset(15.802028876435289, 9.953887745813823), + Offset(19.931119077086663, 8.25375574826962), + Offset(29.821477522711497, 8.814138172215419), + Offset(38.388629307251236, 16.4192779592897), + Offset(40.20171679679066, 22.584241250568667), + Offset(40.057702353728686, 26.578797223330362), + Offset(39.3875843683495, 29.2651920484372), + Offset(38.612911702030125, 31.138824244136487), + Offset(37.87892679924153, 32.477935532975884), + Offset(37.23721730172182, 33.44860191282269), + Offset(36.703224153100756, 34.15520044686847), + Offset(36.277242032808715, 34.6662705791591), + Offset(35.953426323091946, 35.027946279267624), + Offset(35.723396196544755, 35.272177323784426), + Offset(35.57817076186886, 35.42129422653163), + Offset(35.50888136213775, 35.49111177355081), + ], + <Offset>[ + Offset(12.5, 17.1), + Offset(12.568820959399424, 16.986573894184524), + Offset(12.822068758808932, 16.589611807252965), + Offset(13.395327039578369, 15.790194192156408), + Offset(14.632400650310995, 14.402704421364), + Offset(17.59564641132325, 12.216780783198363), + Offset(25.620009652612282, 10.687015033230036), + Offset(33.99475903765893, 15.057696505981518), + Offset(36.67822168754626, 19.6270496410968), + Offset(37.361921327649014, 22.851497307918553), + Offset(37.36310590436704, 25.13463676507986), + Offset(37.118094210451396, 26.788477054903165), + Offset(36.7987285459884, 28.0065630665324), + Offset(36.479494223942, 28.91143806991379), + Offset(36.1936194118543, 29.58351552687462), + Offset(35.95504774207879, 30.077568056765532), + Offset(35.76833031432708, 30.43167175879571), + Offset(35.63315242199269, 30.673062619718593), + Offset(35.54679545480142, 30.821401228851528), + Offset(35.50532744442037, 30.891113146413097), + ], + <Offset>[ + Offset(12.5, 17.1), + Offset(12.568820959399424, 16.986573894184524), + Offset(12.822068758808932, 16.589611807252965), + Offset(13.395327039578369, 15.790194192156408), + Offset(14.632400650310995, 14.402704421364), + Offset(17.59564641132325, 12.216780783198363), + Offset(25.620009652612282, 10.687015033230036), + Offset(33.99475903765893, 15.057696505981518), + Offset(36.67822168754626, 19.6270496410968), + Offset(37.361921327649014, 22.851497307918553), + Offset(37.36310590436704, 25.13463676507986), + Offset(37.118094210451396, 26.788477054903165), + Offset(36.7987285459884, 28.0065630665324), + Offset(36.479494223942, 28.91143806991379), + Offset(36.1936194118543, 29.58351552687462), + Offset(35.95504774207879, 30.077568056765532), + Offset(35.76833031432708, 30.43167175879571), + Offset(35.63315242199269, 30.673062619718593), + Offset(35.54679545480142, 30.821401228851528), + Offset(35.50532744442037, 30.891113146413097), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.878048780488, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(12.5, 26.3), + Offset(12.477809970308172, 26.186123720119735), + Offset(12.40816908349576, 25.780296605393723), + Offset(12.308855256289778, 24.925815630466868), + Offset(12.293144198062407, 23.30033777246436), + Offset(12.924701079796437, 20.14283085305585), + Offset(17.217073912413852, 14.432768755259271), + Offset(25.207018498474316, 12.334533599365145), + Offset(29.631231469057468, 13.71266642215307), + Offset(31.970359275489688, 15.396897477094935), + Offset(33.314148976402116, 16.873526198365184), + Offset(34.12845922729394, 18.087782676436515), + Offset(34.638332039482144, 19.063818133645434), + Offset(34.96404806838234, 19.837110384095983), + Offset(35.17440992936138, 20.44014568688693), + Offset(35.31065916061894, 20.900163011978407), + Offset(35.398138296797356, 21.239122717851885), + Offset(35.45266487288856, 21.47483321158692), + Offset(35.484044840666535, 21.62161523349133), + Offset(35.4982196089856, 21.691115892137674), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.5, 26.3), + Offset(12.477809970308172, 26.186123720119735), + Offset(12.40816908349576, 25.780296605393723), + Offset(12.308855256289778, 24.925815630466868), + Offset(12.293144198062407, 23.30033777246436), + Offset(12.924701079796437, 20.14283085305585), + Offset(17.217073912413852, 14.432768755259271), + Offset(25.207018498474316, 12.334533599365145), + Offset(29.631231469057468, 13.71266642215307), + Offset(31.970359275489688, 15.396897477094935), + Offset(33.314148976402116, 16.873526198365184), + Offset(34.12845922729394, 18.087782676436515), + Offset(34.638332039482144, 19.063818133645434), + Offset(34.96404806838234, 19.837110384095983), + Offset(35.17440992936138, 20.44014568688693), + Offset(35.31065916061894, 20.900163011978407), + Offset(35.398138296797356, 21.239122717851885), + Offset(35.45266487288856, 21.47483321158692), + Offset(35.484044840666535, 21.62161523349133), + Offset(35.4982196089856, 21.691115892137674), + ], + <Offset>[ + Offset(44.699999999999996, 26.3), + Offset(44.67623436108142, 26.504662181939125), + Offset(44.57556587698842, 27.22894546898983), + Offset(44.28353029037639, 28.72846687197695), + Offset(43.43486092691366, 31.487735355334408), + Offset(40.665876324297635, 36.4911395133997), + Offset(30.32721193951616, 43.84304384595377), + Offset(15.675948325317012, 43.09162548651128), + Offset(8.930890202754409, 38.37713218686386), + Offset(5.879259867607036, 34.267364659652586), + Offset(4.400261992900747, 31.044875446242393), + Offset(3.676028902660681, 28.551505117487622), + Offset(3.3387247743777593, 26.62520590641735), + Offset(3.2039011680200318, 25.141171928554776), + Offset(3.172615489404464, 24.007378875612137), + Offset(3.18974150386401, 23.155523047087872), + Offset(3.224216653493965, 22.53479477920593), + Offset(3.258861944427707, 22.106539633451376), + Offset(3.2847938569058357, 21.841242382963447), + Offset(3.2982292190216, 21.715993316159373), + ], + <Offset>[ + Offset(44.699999999999996, 26.3), + Offset(44.67623436108142, 26.504662181939125), + Offset(44.57556587698842, 27.22894546898983), + Offset(44.28353029037639, 28.72846687197695), + Offset(43.43486092691366, 31.487735355334408), + Offset(40.665876324297635, 36.4911395133997), + Offset(30.32721193951616, 43.84304384595377), + Offset(15.675948325317012, 43.09162548651128), + Offset(8.930890202754409, 38.37713218686386), + Offset(5.879259867607036, 34.267364659652586), + Offset(4.400261992900747, 31.044875446242393), + Offset(3.676028902660681, 28.551505117487622), + Offset(3.3387247743777593, 26.62520590641735), + Offset(3.2039011680200318, 25.141171928554776), + Offset(3.172615489404464, 24.007378875612137), + Offset(3.18974150386401, 23.155523047087872), + Offset(3.224216653493965, 22.53479477920593), + Offset(3.258861944427707, 22.106539633451376), + Offset(3.2847938569058357, 21.841242382963447), + Offset(3.2982292190216, 21.715993316159373), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.699999999999996, 26.3), + Offset(44.67623436108142, 26.504662181939125), + Offset(44.57556587698842, 27.22894546898983), + Offset(44.28353029037639, 28.72846687197695), + Offset(43.43486092691366, 31.487735355334408), + Offset(40.665876324297635, 36.4911395133997), + Offset(30.32721193951616, 43.84304384595377), + Offset(15.675948325317012, 43.09162548651128), + Offset(8.930890202754409, 38.37713218686386), + Offset(5.879259867607036, 34.267364659652586), + Offset(4.400261992900747, 31.044875446242393), + Offset(3.676028902660681, 28.551505117487622), + Offset(3.3387247743777593, 26.62520590641735), + Offset(3.2039011680200318, 25.141171928554776), + Offset(3.172615489404464, 24.007378875612137), + Offset(3.18974150386401, 23.155523047087872), + Offset(3.224216653493965, 22.53479477920593), + Offset(3.258861944427707, 22.106539633451376), + Offset(3.2847938569058357, 21.841242382963447), + Offset(3.2982292190216, 21.715993316159373), + ], + <Offset>[ + Offset(44.699999999999996, 21.7), + Offset(44.72173985562705, 21.904887268971517), + Offset(44.782515714645, 22.633603069919452), + Offset(44.82676618202069, 24.16065615282172), + Offset(44.60448915303795, 27.03891867978423), + Offset(43.00134899006105, 32.528114478470954), + Offset(34.528679809615376, 41.970166984939155), + Offset(20.069818594909318, 44.45320693981947), + Offset(12.454385311998806, 41.334323796335724), + Offset(8.575040893686701, 37.99466457506439), + Offset(6.424740456883205, 35.17543072959973), + Offset(5.17084639423941, 32.90185230672094), + Offset(4.418923027630889, 31.096578372860833), + Offset(3.9616242457998574, 29.678335771463676), + Offset(3.6822202306509215, 28.579063795605983), + Offset(3.511935794593935, 27.744225569481436), + Offset(3.409312662258829, 27.131069299677847), + Offset(3.3491057189797715, 26.70565433751721), + Offset(3.316169163973278, 26.441135380643548), + Offset(3.301783136738983, 26.315991943297085), + ], + <Offset>[ + Offset(44.699999999999996, 21.7), + Offset(44.72173985562705, 21.904887268971517), + Offset(44.782515714645, 22.633603069919452), + Offset(44.82676618202069, 24.16065615282172), + Offset(44.60448915303795, 27.03891867978423), + Offset(43.00134899006105, 32.528114478470954), + Offset(34.528679809615376, 41.970166984939155), + Offset(20.069818594909318, 44.45320693981947), + Offset(12.454385311998806, 41.334323796335724), + Offset(8.575040893686701, 37.99466457506439), + Offset(6.424740456883205, 35.17543072959973), + Offset(5.17084639423941, 32.90185230672094), + Offset(4.418923027630889, 31.096578372860833), + Offset(3.9616242457998574, 29.678335771463676), + Offset(3.6822202306509215, 28.579063795605983), + Offset(3.511935794593935, 27.744225569481436), + Offset(3.409312662258829, 27.131069299677847), + Offset(3.3491057189797715, 26.70565433751721), + Offset(3.316169163973278, 26.441135380643548), + Offset(3.301783136738983, 26.315991943297085), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.699999999999996, 21.7), + Offset(44.72173985562705, 21.904887268971517), + Offset(44.782515714645, 22.633603069919452), + Offset(44.82676618202069, 24.16065615282172), + Offset(44.60448915303795, 27.03891867978423), + Offset(43.00134899006105, 32.528114478470954), + Offset(34.528679809615376, 41.970166984939155), + Offset(20.069818594909318, 44.45320693981947), + Offset(12.454385311998806, 41.334323796335724), + Offset(8.575040893686701, 37.99466457506439), + Offset(6.424740456883205, 35.17543072959973), + Offset(5.17084639423941, 32.90185230672094), + Offset(4.418923027630889, 31.096578372860833), + Offset(3.9616242457998574, 29.678335771463676), + Offset(3.6822202306509215, 28.579063795605983), + Offset(3.511935794593935, 27.744225569481436), + Offset(3.409312662258829, 27.131069299677847), + Offset(3.3491057189797715, 26.70565433751721), + Offset(3.316169163973278, 26.441135380643548), + Offset(3.301783136738983, 26.315991943297085), + ], + <Offset>[ + Offset(12.5, 21.7), + Offset(12.523315464853802, 21.586348807152127), + Offset(12.615118921152348, 21.184954206323344), + Offset(12.852091147934075, 20.35800491131164), + Offset(13.462772424186701, 18.851521096914183), + Offset(15.260173745559845, 16.179805818127107), + Offset(21.418541782513067, 12.559891894244654), + Offset(29.60088876806662, 13.69611505267333), + Offset(33.15472657830186, 16.669858031624937), + Offset(34.66614030156936, 19.124197392506744), + Offset(35.33862744038458, 21.004081481722523), + Offset(35.62327671887267, 22.438129865669836), + Offset(35.718530292735274, 23.535190600088917), + Offset(35.72177114616216, 24.374274227004882), + Offset(35.68401467060784, 25.011830606880775), + Offset(35.632853451348865, 25.48886553437197), + Offset(35.583234305562215, 25.8353972383238), + Offset(35.542908647440626, 26.073947915652752), + Offset(35.51542014773398, 26.22150823117143), + Offset(35.50177352670298, 26.291114519275386), + ], + <Offset>[ + Offset(12.5, 21.7), + Offset(12.523315464853802, 21.586348807152127), + Offset(12.615118921152348, 21.184954206323344), + Offset(12.852091147934075, 20.35800491131164), + Offset(13.462772424186701, 18.851521096914183), + Offset(15.260173745559845, 16.179805818127107), + Offset(21.418541782513067, 12.559891894244654), + Offset(29.60088876806662, 13.69611505267333), + Offset(33.15472657830186, 16.669858031624937), + Offset(34.66614030156936, 19.124197392506744), + Offset(35.33862744038458, 21.004081481722523), + Offset(35.62327671887267, 22.438129865669836), + Offset(35.718530292735274, 23.535190600088917), + Offset(35.72177114616216, 24.374274227004882), + Offset(35.68401467060784, 25.011830606880775), + Offset(35.632853451348865, 25.48886553437197), + Offset(35.583234305562215, 25.8353972383238), + Offset(35.542908647440626, 26.073947915652752), + Offset(35.51542014773398, 26.22150823117143), + Offset(35.50177352670298, 26.291114519275386), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.5, 21.7), + Offset(12.523315464853802, 21.586348807152127), + Offset(12.615118921152348, 21.184954206323344), + Offset(12.852091147934075, 20.35800491131164), + Offset(13.462772424186701, 18.851521096914183), + Offset(15.260173745559845, 16.179805818127107), + Offset(21.418541782513067, 12.559891894244654), + Offset(29.60088876806662, 13.69611505267333), + Offset(33.15472657830186, 16.669858031624937), + Offset(34.66614030156936, 19.124197392506744), + Offset(35.33862744038458, 21.004081481722523), + Offset(35.62327671887267, 22.438129865669836), + Offset(35.718530292735274, 23.535190600088917), + Offset(35.72177114616216, 24.374274227004882), + Offset(35.68401467060784, 25.011830606880775), + Offset(35.632853451348865, 25.48886553437197), + Offset(35.583234305562215, 25.8353972383238), + Offset(35.542908647440626, 26.073947915652752), + Offset(35.51542014773398, 26.22150823117143), + Offset(35.50177352670298, 26.291114519275386), + ], + <Offset>[ + Offset(12.5, 26.3), + Offset(12.477809970308172, 26.186123720119735), + Offset(12.40816908349576, 25.780296605393723), + Offset(12.308855256289778, 24.925815630466868), + Offset(12.293144198062407, 23.30033777246436), + Offset(12.924701079796437, 20.14283085305585), + Offset(17.217073912413852, 14.432768755259271), + Offset(25.207018498474316, 12.334533599365145), + Offset(29.631231469057468, 13.71266642215307), + Offset(31.970359275489688, 15.396897477094935), + Offset(33.314148976402116, 16.873526198365184), + Offset(34.12845922729394, 18.087782676436515), + Offset(34.638332039482144, 19.063818133645434), + Offset(34.96404806838234, 19.837110384095983), + Offset(35.17440992936138, 20.44014568688693), + Offset(35.31065916061894, 20.900163011978407), + Offset(35.398138296797356, 21.239122717851885), + Offset(35.45266487288856, 21.47483321158692), + Offset(35.484044840666535, 21.62161523349133), + Offset(35.4982196089856, 21.691115892137674), + ], + <Offset>[ + Offset(12.5, 26.3), + Offset(12.477809970308172, 26.186123720119735), + Offset(12.40816908349576, 25.780296605393723), + Offset(12.308855256289778, 24.925815630466868), + Offset(12.293144198062407, 23.30033777246436), + Offset(12.924701079796437, 20.14283085305585), + Offset(17.217073912413852, 14.432768755259271), + Offset(25.207018498474316, 12.334533599365145), + Offset(29.631231469057468, 13.71266642215307), + Offset(31.970359275489688, 15.396897477094935), + Offset(33.314148976402116, 16.873526198365184), + Offset(34.12845922729394, 18.087782676436515), + Offset(34.638332039482144, 19.063818133645434), + Offset(34.96404806838234, 19.837110384095983), + Offset(35.17440992936138, 20.44014568688693), + Offset(35.31065916061894, 20.900163011978407), + Offset(35.398138296797356, 21.239122717851885), + Offset(35.45266487288856, 21.47483321158692), + Offset(35.484044840666535, 21.62161523349133), + Offset(35.4982196089856, 21.691115892137674), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.146341463415, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(18.039538499999995, 12.930571500000006), + Offset(18.149334465395803, 12.872149290550801), + Offset(18.543577170010774, 12.67362376971493), + Offset(19.38848933269092, 12.304132440263823), + Offset(21.0500251098891, 11.778829975926628), + Offset(24.4849959176686, 11.43667565110878), + Offset(31.716380432411114, 14.006619703548635), + Offset(36.563833612934715, 21.53883416894973), + Offset(36.92848913752976, 26.678594000151676), + Offset(36.41588677676291, 30.008169262247456), + Offset(35.68873044963835, 32.36483086720799), + Offset(34.89395296392378, 34.0653568909929), + Offset(34.11750536482414, 35.28323166524228), + Offset(33.42442890399698, 36.15784461978932), + Offset(32.840093239206396, 36.785183822829495), + Offset(32.36951533303179, 37.23048479128569), + Offset(32.00877148413249, 37.538392723203316), + Offset(31.749801205381853, 37.7397340593929), + Offset(31.58332657425492, 37.85607615398918), + Offset(31.500705947534364, 37.904137673197035), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.039538499999995, 12.930571500000006), + Offset(18.149334465395803, 12.872149290550801), + Offset(18.543577170010774, 12.67362376971493), + Offset(19.38848933269092, 12.304132440263823), + Offset(21.0500251098891, 11.778829975926628), + Offset(24.4849959176686, 11.43667565110878), + Offset(31.716380432411114, 14.006619703548635), + Offset(36.563833612934715, 21.53883416894973), + Offset(36.92848913752976, 26.678594000151676), + Offset(36.41588677676291, 30.008169262247456), + Offset(35.68873044963835, 32.36483086720799), + Offset(34.89395296392378, 34.0653568909929), + Offset(34.11750536482414, 35.28323166524228), + Offset(33.42442890399698, 36.15784461978932), + Offset(32.840093239206396, 36.785183822829495), + Offset(32.36951533303179, 37.23048479128569), + Offset(32.00877148413249, 37.538392723203316), + Offset(31.749801205381853, 37.7397340593929), + Offset(31.58332657425492, 37.85607615398918), + Offset(31.500705947534364, 37.904137673197035), + ], + <Offset>[ + Offset(9.524593499999996, 12.930571500000006), + Offset(9.63480611837429, 12.787915207234757), + Offset(10.037253738651572, 12.290544098974763), + Offset(10.933129105730652, 11.298562062138357), + Offset(12.814931782195051, 9.613760407253604), + Offset(17.148837885012377, 7.11336292762574), + Offset(28.234762045851944, 6.196224855085145), + Offset(39.13042441508561, 13.256357206311968), + Offset(42.67716555792793, 19.829043505343183), + Offset(43.985492641283884, 24.533428745633444), + Offset(44.43019441391232, 28.080441886710624), + Offset(44.394288300179475, 30.80095825365075), + Offset(44.09477826399472, 32.872912945700186), + Offset(43.700712499650194, 34.44166739898953), + Offset(43.302847476418705, 35.61890284347735), + Offset(42.94671302192797, 36.48781021374379), + Offset(42.653748813975184, 37.109710143785925), + Offset(42.43168887555528, 37.5301341853464), + Offset(42.28113740093583, 37.78310769585204), + Offset(42.20064775415372, 37.89587099404257), + ], + <Offset>[ + Offset(9.524593499999996, 12.930571500000006), + Offset(9.63480611837429, 12.787915207234757), + Offset(10.037253738651572, 12.290544098974763), + Offset(10.933129105730652, 11.298562062138357), + Offset(12.814931782195051, 9.613760407253604), + Offset(17.148837885012377, 7.11336292762574), + Offset(28.234762045851944, 6.196224855085145), + Offset(39.13042441508561, 13.256357206311968), + Offset(42.67716555792793, 19.829043505343183), + Offset(43.985492641283884, 24.533428745633444), + Offset(44.43019441391232, 28.080441886710624), + Offset(44.394288300179475, 30.80095825365075), + Offset(44.09477826399472, 32.872912945700186), + Offset(43.700712499650194, 34.44166739898953), + Offset(43.302847476418705, 35.61890284347735), + Offset(42.94671302192797, 36.48781021374379), + Offset(42.653748813975184, 37.109710143785925), + Offset(42.43168887555528, 37.5301341853464), + Offset(42.28113740093583, 37.78310769585204), + Offset(42.20064775415372, 37.89587099404257), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(9.524593499999996, 12.930571500000006), + Offset(9.63480611837429, 12.787915207234757), + Offset(10.037253738651572, 12.290544098974763), + Offset(10.933129105730652, 11.298562062138357), + Offset(12.814931782195051, 9.613760407253604), + Offset(17.148837885012377, 7.11336292762574), + Offset(28.234762045851944, 6.196224855085145), + Offset(39.13042441508561, 13.256357206311968), + Offset(42.67716555792793, 19.829043505343183), + Offset(43.985492641283884, 24.533428745633444), + Offset(44.43019441391232, 28.080441886710624), + Offset(44.394288300179475, 30.80095825365075), + Offset(44.09477826399472, 32.872912945700186), + Offset(43.700712499650194, 34.44166739898953), + Offset(43.302847476418705, 35.61890284347735), + Offset(42.94671302192797, 36.48781021374379), + Offset(42.653748813975184, 37.109710143785925), + Offset(42.43168887555528, 37.5301341853464), + Offset(42.28113740093583, 37.78310769585204), + Offset(42.20064775415372, 37.89587099404257), + ], + <Offset>[ + Offset(9.524593499999998, 23.148505500000006), + Offset(9.533725218395034, 23.005349223660573), + Offset(9.577558133763372, 22.498132216605804), + Offset(9.726444651980092, 21.44499433449068), + Offset(10.216848299787422, 19.495872400486462), + Offset(11.960862616832728, 15.916752566813207), + Offset(18.862288227695757, 10.374166918956151), + Offset(29.191452059920294, 10.176448243730892), + Offset(34.457704964157735, 12.93063180086538), + Offset(37.415804021347064, 15.449901708208273), + Offset(39.288927637315474, 17.590685129581864), + Offset(40.4770099353689, 19.400555850143917), + Offset(41.202395800544195, 20.900185466695486), + Offset(41.64129983469044, 22.110127084205665), + Offset(41.90331030119613, 23.06359775882259), + Offset(42.055503528877686, 23.79517298706838), + Offset(42.13932971867431, 24.335737347974696), + Offset(42.18016902669948, 24.711868981138284), + Offset(42.19357525117126, 24.945734703834944), + Offset(42.19072773916836, 25.055940826099334), + ], + <Offset>[ + Offset(9.524593499999998, 23.148505500000006), + Offset(9.533725218395034, 23.005349223660573), + Offset(9.577558133763372, 22.498132216605804), + Offset(9.726444651980092, 21.44499433449068), + Offset(10.216848299787422, 19.495872400486462), + Offset(11.960862616832728, 15.916752566813207), + Offset(18.862288227695757, 10.374166918956151), + Offset(29.191452059920294, 10.176448243730892), + Offset(34.457704964157735, 12.93063180086538), + Offset(37.415804021347064, 15.449901708208273), + Offset(39.288927637315474, 17.590685129581864), + Offset(40.4770099353689, 19.400555850143917), + Offset(41.202395800544195, 20.900185466695486), + Offset(41.64129983469044, 22.110127084205665), + Offset(41.90331030119613, 23.06359775882259), + Offset(42.055503528877686, 23.79517298706838), + Offset(42.13932971867431, 24.335737347974696), + Offset(42.18016902669948, 24.711868981138284), + Offset(42.19357525117126, 24.945734703834944), + Offset(42.19072773916836, 25.055940826099334), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(9.524593499999998, 23.148505500000006), + Offset(9.533725218395034, 23.005349223660573), + Offset(9.577558133763372, 22.498132216605804), + Offset(9.726444651980092, 21.44499433449068), + Offset(10.216848299787422, 19.495872400486462), + Offset(11.960862616832728, 15.916752566813207), + Offset(18.862288227695757, 10.374166918956151), + Offset(29.191452059920294, 10.176448243730892), + Offset(34.457704964157735, 12.93063180086538), + Offset(37.415804021347064, 15.449901708208273), + Offset(39.288927637315474, 17.590685129581864), + Offset(40.4770099353689, 19.400555850143917), + Offset(41.202395800544195, 20.900185466695486), + Offset(41.64129983469044, 22.110127084205665), + Offset(41.90331030119613, 23.06359775882259), + Offset(42.055503528877686, 23.79517298706838), + Offset(42.13932971867431, 24.335737347974696), + Offset(42.18016902669948, 24.711868981138284), + Offset(42.19357525117126, 24.945734703834944), + Offset(42.19072773916836, 25.055940826099334), + ], + <Offset>[ + Offset(18.0395385, 23.148505500000006), + Offset(18.048253565416548, 23.089583306976618), + Offset(18.083881565122574, 22.88121188734597), + Offset(18.181804878940362, 22.450564712616142), + Offset(18.45194162748147, 21.660941969159484), + Offset(19.29702064948895, 20.240065290296247), + Offset(22.343906614254927, 18.18456176741964), + Offset(26.6248612577694, 18.458925206368654), + Offset(28.709028543759565, 19.78018229567387), + Offset(29.84619815682609, 20.924642224822286), + Offset(30.547463673041506, 21.875074110079233), + Offset(30.976674599113203, 22.664954487486067), + Offset(31.225122901373616, 23.310504186237587), + Offset(31.365016239037228, 23.82630430500546), + Offset(31.440556063983824, 24.229878738174733), + Offset(31.47830583998151, 24.53784756461028), + Offset(31.49435238883162, 24.76441992739209), + Offset(31.498281356526046, 24.921468855184788), + Offset(31.495764424490346, 25.018703161972084), + Offset(31.490785932549, 25.064207505253805), + ], + <Offset>[ + Offset(18.0395385, 23.148505500000006), + Offset(18.048253565416548, 23.089583306976618), + Offset(18.083881565122574, 22.88121188734597), + Offset(18.181804878940362, 22.450564712616142), + Offset(18.45194162748147, 21.660941969159484), + Offset(19.29702064948895, 20.240065290296247), + Offset(22.343906614254927, 18.18456176741964), + Offset(26.6248612577694, 18.458925206368654), + Offset(28.709028543759565, 19.78018229567387), + Offset(29.84619815682609, 20.924642224822286), + Offset(30.547463673041506, 21.875074110079233), + Offset(30.976674599113203, 22.664954487486067), + Offset(31.225122901373616, 23.310504186237587), + Offset(31.365016239037228, 23.82630430500546), + Offset(31.440556063983824, 24.229878738174733), + Offset(31.47830583998151, 24.53784756461028), + Offset(31.49435238883162, 24.76441992739209), + Offset(31.498281356526046, 24.921468855184788), + Offset(31.495764424490346, 25.018703161972084), + Offset(31.490785932549, 25.064207505253805), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.0395385, 23.148505500000006), + Offset(18.048253565416548, 23.089583306976618), + Offset(18.083881565122574, 22.88121188734597), + Offset(18.181804878940362, 22.450564712616142), + Offset(18.45194162748147, 21.660941969159484), + Offset(19.29702064948895, 20.240065290296247), + Offset(22.343906614254927, 18.18456176741964), + Offset(26.6248612577694, 18.458925206368654), + Offset(28.709028543759565, 19.78018229567387), + Offset(29.84619815682609, 20.924642224822286), + Offset(30.547463673041506, 21.875074110079233), + Offset(30.976674599113203, 22.664954487486067), + Offset(31.225122901373616, 23.310504186237587), + Offset(31.365016239037228, 23.82630430500546), + Offset(31.440556063983824, 24.229878738174733), + Offset(31.47830583998151, 24.53784756461028), + Offset(31.49435238883162, 24.76441992739209), + Offset(31.498281356526046, 24.921468855184788), + Offset(31.495764424490346, 25.018703161972084), + Offset(31.490785932549, 25.064207505253805), + ], + <Offset>[ + Offset(18.039538499999995, 12.930571500000006), + Offset(18.149334465395803, 12.872149290550801), + Offset(18.543577170010774, 12.67362376971493), + Offset(19.38848933269092, 12.304132440263823), + Offset(21.0500251098891, 11.778829975926628), + Offset(24.4849959176686, 11.43667565110878), + Offset(31.716380432411114, 14.006619703548635), + Offset(36.563833612934715, 21.53883416894973), + Offset(36.92848913752976, 26.678594000151676), + Offset(36.41588677676291, 30.008169262247456), + Offset(35.68873044963835, 32.36483086720799), + Offset(34.89395296392378, 34.0653568909929), + Offset(34.11750536482414, 35.28323166524228), + Offset(33.42442890399698, 36.15784461978932), + Offset(32.840093239206396, 36.785183822829495), + Offset(32.36951533303179, 37.23048479128569), + Offset(32.00877148413249, 37.538392723203316), + Offset(31.749801205381853, 37.7397340593929), + Offset(31.58332657425492, 37.85607615398918), + Offset(31.500705947534364, 37.904137673197035), + ], + <Offset>[ + Offset(18.039538499999995, 12.930571500000006), + Offset(18.149334465395803, 12.872149290550801), + Offset(18.543577170010774, 12.67362376971493), + Offset(19.38848933269092, 12.304132440263823), + Offset(21.0500251098891, 11.778829975926628), + Offset(24.4849959176686, 11.43667565110878), + Offset(31.716380432411114, 14.006619703548635), + Offset(36.563833612934715, 21.53883416894973), + Offset(36.92848913752976, 26.678594000151676), + Offset(36.41588677676291, 30.008169262247456), + Offset(35.68873044963835, 32.36483086720799), + Offset(34.89395296392378, 34.0653568909929), + Offset(34.11750536482414, 35.28323166524228), + Offset(33.42442890399698, 36.15784461978932), + Offset(32.840093239206396, 36.785183822829495), + Offset(32.36951533303179, 37.23048479128569), + Offset(32.00877148413249, 37.538392723203316), + Offset(31.749801205381853, 37.7397340593929), + Offset(31.58332657425492, 37.85607615398918), + Offset(31.500705947534364, 37.904137673197035), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.146341463415, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(38.4754065, 24.8514945), + Offset(38.466274781604966, 24.99465077633943), + Offset(38.42244186623663, 25.501867783394207), + Offset(38.27355534801991, 26.555005665509313), + Offset(37.78315170021258, 28.504127599513545), + Offset(36.03913738316727, 32.08324743318679), + Offset(29.137711772304243, 37.62583308104385), + Offset(18.8085479400797, 37.8235517562691), + Offset(13.542295035842265, 35.06936819913462), + Offset(10.58419597865294, 32.55009829179173), + Offset(8.71107236268452, 30.409314870418136), + Offset(7.522990064631102, 28.599444149856083), + Offset(6.797604199455802, 27.099814533304514), + Offset(6.358700165309552, 25.889872915794328), + Offset(6.096689698803871, 24.93640224117742), + Offset(5.94449647112231, 24.204827012931613), + Offset(5.860670281325686, 23.6642626520253), + Offset(5.819830973300516, 23.288131018861716), + Offset(5.806424748828734, 23.05426529616505), + Offset(5.809272260831642, 22.944059173900662), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.4754065, 24.8514945), + Offset(38.466274781604966, 24.99465077633943), + Offset(38.42244186623663, 25.501867783394207), + Offset(38.27355534801991, 26.555005665509313), + Offset(37.78315170021258, 28.504127599513545), + Offset(36.03913738316727, 32.08324743318679), + Offset(29.137711772304243, 37.62583308104385), + Offset(18.8085479400797, 37.8235517562691), + Offset(13.542295035842265, 35.06936819913462), + Offset(10.58419597865294, 32.55009829179173), + Offset(8.71107236268452, 30.409314870418136), + Offset(7.522990064631102, 28.599444149856083), + Offset(6.797604199455802, 27.099814533304514), + Offset(6.358700165309552, 25.889872915794328), + Offset(6.096689698803871, 24.93640224117742), + Offset(5.94449647112231, 24.204827012931613), + Offset(5.860670281325686, 23.6642626520253), + Offset(5.819830973300516, 23.288131018861716), + Offset(5.806424748828734, 23.05426529616505), + Offset(5.809272260831642, 22.944059173900662), + ], + <Offset>[ + Offset(29.9604615, 24.8514945), + Offset(29.951746434583455, 24.910416693023386), + Offset(29.91611843487743, 25.11878811265404), + Offset(29.818195121059638, 25.54943528738385), + Offset(29.54805837251853, 26.339058030840523), + Offset(28.702979350511054, 27.759934709703753), + Offset(25.656093385745073, 29.81543823258036), + Offset(21.375138742230593, 29.54107479363134), + Offset(19.290971456240435, 28.21981770432613), + Offset(18.153801843173916, 27.07535777517771), + Offset(17.452536326958487, 26.124925889920767), + Offset(17.023325400886797, 25.335045512513933), + Offset(16.774877098626384, 24.689495813762413), + Offset(16.63498376096277, 24.17369569499453), + Offset(16.559443936016173, 23.770121261825274), + Offset(16.521694160018484, 23.46215243538971), + Offset(16.505647611168378, 23.235580072607906), + Offset(16.501718643473946, 23.078531144815212), + Offset(16.504235575509647, 22.98129683802791), + Offset(16.509214067451, 22.93579249474619), + ], + <Offset>[ + Offset(29.9604615, 24.8514945), + Offset(29.951746434583455, 24.910416693023386), + Offset(29.91611843487743, 25.11878811265404), + Offset(29.818195121059638, 25.54943528738385), + Offset(29.54805837251853, 26.339058030840523), + Offset(28.702979350511054, 27.759934709703753), + Offset(25.656093385745073, 29.81543823258036), + Offset(21.375138742230593, 29.54107479363134), + Offset(19.290971456240435, 28.21981770432613), + Offset(18.153801843173916, 27.07535777517771), + Offset(17.452536326958487, 26.124925889920767), + Offset(17.023325400886797, 25.335045512513933), + Offset(16.774877098626384, 24.689495813762413), + Offset(16.63498376096277, 24.17369569499453), + Offset(16.559443936016173, 23.770121261825274), + Offset(16.521694160018484, 23.46215243538971), + Offset(16.505647611168378, 23.235580072607906), + Offset(16.501718643473946, 23.078531144815212), + Offset(16.504235575509647, 22.98129683802791), + Offset(16.509214067451, 22.93579249474619), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(29.9604615, 24.8514945), + Offset(29.951746434583455, 24.910416693023386), + Offset(29.91611843487743, 25.11878811265404), + Offset(29.818195121059638, 25.54943528738385), + Offset(29.54805837251853, 26.339058030840523), + Offset(28.702979350511054, 27.759934709703753), + Offset(25.656093385745073, 29.81543823258036), + Offset(21.375138742230593, 29.54107479363134), + Offset(19.290971456240435, 28.21981770432613), + Offset(18.153801843173916, 27.07535777517771), + Offset(17.452536326958487, 26.124925889920767), + Offset(17.023325400886797, 25.335045512513933), + Offset(16.774877098626384, 24.689495813762413), + Offset(16.63498376096277, 24.17369569499453), + Offset(16.559443936016173, 23.770121261825274), + Offset(16.521694160018484, 23.46215243538971), + Offset(16.505647611168378, 23.235580072607906), + Offset(16.501718643473946, 23.078531144815212), + Offset(16.504235575509647, 22.98129683802791), + Offset(16.509214067451, 22.93579249474619), + ], + <Offset>[ + Offset(29.9604615, 35.0694285), + Offset(29.8506655346042, 35.1278507094492), + Offset(29.45642282998923, 35.326376230285085), + Offset(28.61151066730908, 35.69586755973617), + Offset(26.9499748901109, 36.22117002407338), + Offset(23.515004082331405, 36.56332434889122), + Offset(16.283619567588886, 33.99338029645136), + Offset(11.43616638706528, 26.461165831050263), + Offset(11.071510862470241, 21.321405999848324), + Offset(11.5841132232371, 17.99183073775254), + Offset(12.311269550361642, 15.635169132792008), + Offset(13.10604703607622, 13.934643109007098), + Offset(13.882494635175863, 12.716768334757713), + Offset(14.575571096003015, 11.84215538021067), + Offset(15.159906760793596, 11.214816177170512), + Offset(15.630484666968204, 10.7695152087143), + Offset(15.991228515867505, 10.461607276796677), + Offset(16.250198794618143, 10.260265940607095), + Offset(16.416673425745074, 10.143923846010813), + Offset(16.49929405246564, 10.095862326802958), + ], + <Offset>[ + Offset(29.9604615, 35.0694285), + Offset(29.8506655346042, 35.1278507094492), + Offset(29.45642282998923, 35.326376230285085), + Offset(28.61151066730908, 35.69586755973617), + Offset(26.9499748901109, 36.22117002407338), + Offset(23.515004082331405, 36.56332434889122), + Offset(16.283619567588886, 33.99338029645136), + Offset(11.43616638706528, 26.461165831050263), + Offset(11.071510862470241, 21.321405999848324), + Offset(11.5841132232371, 17.99183073775254), + Offset(12.311269550361642, 15.635169132792008), + Offset(13.10604703607622, 13.934643109007098), + Offset(13.882494635175863, 12.716768334757713), + Offset(14.575571096003015, 11.84215538021067), + Offset(15.159906760793596, 11.214816177170512), + Offset(15.630484666968204, 10.7695152087143), + Offset(15.991228515867505, 10.461607276796677), + Offset(16.250198794618143, 10.260265940607095), + Offset(16.416673425745074, 10.143923846010813), + Offset(16.49929405246564, 10.095862326802958), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(29.9604615, 35.0694285), + Offset(29.8506655346042, 35.1278507094492), + Offset(29.45642282998923, 35.326376230285085), + Offset(28.61151066730908, 35.69586755973617), + Offset(26.9499748901109, 36.22117002407338), + Offset(23.515004082331405, 36.56332434889122), + Offset(16.283619567588886, 33.99338029645136), + Offset(11.43616638706528, 26.461165831050263), + Offset(11.071510862470241, 21.321405999848324), + Offset(11.5841132232371, 17.99183073775254), + Offset(12.311269550361642, 15.635169132792008), + Offset(13.10604703607622, 13.934643109007098), + Offset(13.882494635175863, 12.716768334757713), + Offset(14.575571096003015, 11.84215538021067), + Offset(15.159906760793596, 11.214816177170512), + Offset(15.630484666968204, 10.7695152087143), + Offset(15.991228515867505, 10.461607276796677), + Offset(16.250198794618143, 10.260265940607095), + Offset(16.416673425745074, 10.143923846010813), + Offset(16.49929405246564, 10.095862326802958), + ], + <Offset>[ + Offset(38.4754065, 35.0694285), + Offset(38.365193881625714, 35.212084792765246), + Offset(37.96274626134843, 35.70945590102525), + Offset(37.06687089426935, 36.701437937861634), + Offset(35.18506821780495, 38.386239592746406), + Offset(30.851162114987627, 40.886637072374256), + Offset(19.765237954148056, 41.80377514491485), + Offset(8.869575584914383, 34.743642793688025), + Offset(5.3228344420720735, 28.170956494656817), + Offset(4.0145073587161235, 23.466571254366553), + Offset(3.5698055860876767, 19.919558113289376), + Offset(3.6057116998205245, 17.19904174634925), + Offset(3.90522173600528, 15.127087054299814), + Offset(4.299287500349799, 13.558332601010466), + Offset(4.697152523581295, 12.381097156522657), + Offset(5.053286978072029, 11.5121897862562), + Offset(5.346251186024813, 10.890289856214071), + Offset(5.568311124444711, 10.469865814653598), + Offset(5.7188625990641615, 10.216892304147956), + Offset(5.799352245846278, 10.104129005957429), + ], + <Offset>[ + Offset(38.4754065, 35.0694285), + Offset(38.365193881625714, 35.212084792765246), + Offset(37.96274626134843, 35.70945590102525), + Offset(37.06687089426935, 36.701437937861634), + Offset(35.18506821780495, 38.386239592746406), + Offset(30.851162114987627, 40.886637072374256), + Offset(19.765237954148056, 41.80377514491485), + Offset(8.869575584914383, 34.743642793688025), + Offset(5.3228344420720735, 28.170956494656817), + Offset(4.0145073587161235, 23.466571254366553), + Offset(3.5698055860876767, 19.919558113289376), + Offset(3.6057116998205245, 17.19904174634925), + Offset(3.90522173600528, 15.127087054299814), + Offset(4.299287500349799, 13.558332601010466), + Offset(4.697152523581295, 12.381097156522657), + Offset(5.053286978072029, 11.5121897862562), + Offset(5.346251186024813, 10.890289856214071), + Offset(5.568311124444711, 10.469865814653598), + Offset(5.7188625990641615, 10.216892304147956), + Offset(5.799352245846278, 10.104129005957429), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.4754065, 35.0694285), + Offset(38.365193881625714, 35.212084792765246), + Offset(37.96274626134843, 35.70945590102525), + Offset(37.06687089426935, 36.701437937861634), + Offset(35.18506821780495, 38.386239592746406), + Offset(30.851162114987627, 40.886637072374256), + Offset(19.765237954148056, 41.80377514491485), + Offset(8.869575584914383, 34.743642793688025), + Offset(5.3228344420720735, 28.170956494656817), + Offset(4.0145073587161235, 23.466571254366553), + Offset(3.5698055860876767, 19.919558113289376), + Offset(3.6057116998205245, 17.19904174634925), + Offset(3.90522173600528, 15.127087054299814), + Offset(4.299287500349799, 13.558332601010466), + Offset(4.697152523581295, 12.381097156522657), + Offset(5.053286978072029, 11.5121897862562), + Offset(5.346251186024813, 10.890289856214071), + Offset(5.568311124444711, 10.469865814653598), + Offset(5.7188625990641615, 10.216892304147956), + Offset(5.799352245846278, 10.104129005957429), + ], + <Offset>[ + Offset(38.4754065, 24.8514945), + Offset(38.466274781604966, 24.99465077633943), + Offset(38.42244186623663, 25.501867783394207), + Offset(38.27355534801991, 26.555005665509313), + Offset(37.78315170021258, 28.504127599513545), + Offset(36.03913738316727, 32.08324743318679), + Offset(29.137711772304243, 37.62583308104385), + Offset(18.8085479400797, 37.8235517562691), + Offset(13.542295035842265, 35.06936819913462), + Offset(10.58419597865294, 32.55009829179173), + Offset(8.71107236268452, 30.409314870418136), + Offset(7.522990064631102, 28.599444149856083), + Offset(6.797604199455802, 27.099814533304514), + Offset(6.358700165309552, 25.889872915794328), + Offset(6.096689698803871, 24.93640224117742), + Offset(5.94449647112231, 24.204827012931613), + Offset(5.860670281325686, 23.6642626520253), + Offset(5.819830973300516, 23.288131018861716), + Offset(5.806424748828734, 23.05426529616505), + Offset(5.809272260831642, 22.944059173900662), + ], + <Offset>[ + Offset(38.4754065, 24.8514945), + Offset(38.466274781604966, 24.99465077633943), + Offset(38.42244186623663, 25.501867783394207), + Offset(38.27355534801991, 26.555005665509313), + Offset(37.78315170021258, 28.504127599513545), + Offset(36.03913738316727, 32.08324743318679), + Offset(29.137711772304243, 37.62583308104385), + Offset(18.8085479400797, 37.8235517562691), + Offset(13.542295035842265, 35.06936819913462), + Offset(10.58419597865294, 32.55009829179173), + Offset(8.71107236268452, 30.409314870418136), + Offset(7.522990064631102, 28.599444149856083), + Offset(6.797604199455802, 27.099814533304514), + Offset(6.358700165309552, 25.889872915794328), + Offset(6.096689698803871, 24.93640224117742), + Offset(5.94449647112231, 24.204827012931613), + Offset(5.860670281325686, 23.6642626520253), + Offset(5.819830973300516, 23.288131018861716), + Offset(5.806424748828734, 23.05426529616505), + Offset(5.809272260831642, 22.944059173900662), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.146341463415, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(28.2574725, 24.8514945), + Offset(28.248840765179153, 24.893569876360175), + Offset(28.214853748605588, 25.042172178506007), + Offset(28.12712307566759, 25.34832121175876), + Offset(27.90103970697972, 25.90604411710592), + Offset(27.235747743979807, 26.895272165007142), + Offset(24.959769708433235, 28.253359262887663), + Offset(21.888456902660778, 27.88457940110379), + Offset(20.440706740320067, 26.84990760536443), + Offset(19.66772301607811, 25.980409671854908), + Offset(19.20082911981328, 25.26804809382129), + Offset(18.92339246813794, 24.682165785045505), + Offset(18.770331678460497, 24.207432069853994), + Offset(18.690240480093415, 23.830460250834577), + Offset(18.651994783458633, 23.536865065954846), + Offset(18.637133697797722, 23.313617519881333), + Offset(18.634643077136914, 23.149843556724427), + Offset(18.638096177508633, 23.03661117000591), + Offset(18.643797740845827, 22.966703146400476), + Offset(18.649202428774874, 22.9341391589153), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(28.2574725, 24.8514945), + Offset(28.248840765179153, 24.893569876360175), + Offset(28.214853748605588, 25.042172178506007), + Offset(28.12712307566759, 25.34832121175876), + Offset(27.90103970697972, 25.90604411710592), + Offset(27.235747743979807, 26.895272165007142), + Offset(24.959769708433235, 28.253359262887663), + Offset(21.888456902660778, 27.88457940110379), + Offset(20.440706740320067, 26.84990760536443), + Offset(19.66772301607811, 25.980409671854908), + Offset(19.20082911981328, 25.26804809382129), + Offset(18.92339246813794, 24.682165785045505), + Offset(18.770331678460497, 24.207432069853994), + Offset(18.690240480093415, 23.830460250834577), + Offset(18.651994783458633, 23.536865065954846), + Offset(18.637133697797722, 23.313617519881333), + Offset(18.634643077136914, 23.149843556724427), + Offset(18.638096177508633, 23.03661117000591), + Offset(18.643797740845827, 22.966703146400476), + Offset(18.649202428774874, 22.9341391589153), + ], + <Offset>[ + Offset(19.7425275, 24.8514945), + Offset(19.73431241815764, 24.80933579304413), + Offset(19.708530317246385, 24.65909250776584), + Offset(19.67176284870732, 24.34275083363329), + Offset(19.66594637928567, 23.740974548432895), + Offset(19.899589711323586, 22.5719594415241), + Offset(21.478151321874066, 20.442964414424175), + Offset(24.455047704811673, 19.602102438466027), + Offset(26.189383160718236, 20.00035711055594), + Offset(27.237328880599087, 20.505669155240895), + Offset(27.942293084087247, 20.983659113323917), + Offset(28.423727804393636, 21.417767147703355), + Offset(28.74760457763108, 21.797113350311893), + Offset(28.96652407574663, 22.11428303003478), + Offset(29.114749020670935, 22.3705840866027), + Offset(29.2143313866939, 22.570942942339432), + Offset(29.279620406979603, 22.721160977307033), + Offset(29.319983847682064, 22.827011295959405), + Offset(29.34160856752674, 22.893734688263336), + Offset(29.349144235394235, 22.92587247976083), + ], + <Offset>[ + Offset(19.7425275, 24.8514945), + Offset(19.73431241815764, 24.80933579304413), + Offset(19.708530317246385, 24.65909250776584), + Offset(19.67176284870732, 24.34275083363329), + Offset(19.66594637928567, 23.740974548432895), + Offset(19.899589711323586, 22.5719594415241), + Offset(21.478151321874066, 20.442964414424175), + Offset(24.455047704811673, 19.602102438466027), + Offset(26.189383160718236, 20.00035711055594), + Offset(27.237328880599087, 20.505669155240895), + Offset(27.942293084087247, 20.983659113323917), + Offset(28.423727804393636, 21.417767147703355), + Offset(28.74760457763108, 21.797113350311893), + Offset(28.96652407574663, 22.11428303003478), + Offset(29.114749020670935, 22.3705840866027), + Offset(29.2143313866939, 22.570942942339432), + Offset(29.279620406979603, 22.721160977307033), + Offset(29.319983847682064, 22.827011295959405), + Offset(29.34160856752674, 22.893734688263336), + Offset(29.349144235394235, 22.92587247976083), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(19.7425275, 24.8514945), + Offset(19.73431241815764, 24.80933579304413), + Offset(19.708530317246385, 24.65909250776584), + Offset(19.67176284870732, 24.34275083363329), + Offset(19.66594637928567, 23.740974548432895), + Offset(19.899589711323586, 22.5719594415241), + Offset(21.478151321874066, 20.442964414424175), + Offset(24.455047704811673, 19.602102438466027), + Offset(26.189383160718236, 20.00035711055594), + Offset(27.237328880599087, 20.505669155240895), + Offset(27.942293084087247, 20.983659113323917), + Offset(28.423727804393636, 21.417767147703355), + Offset(28.74760457763108, 21.797113350311893), + Offset(28.96652407574663, 22.11428303003478), + Offset(29.114749020670935, 22.3705840866027), + Offset(29.2143313866939, 22.570942942339432), + Offset(29.279620406979603, 22.721160977307033), + Offset(29.319983847682064, 22.827011295959405), + Offset(29.34160856752674, 22.893734688263336), + Offset(29.349144235394235, 22.92587247976083), + ], + <Offset>[ + Offset(19.7425275, 35.0694285), + Offset(19.633231518178384, 35.02676980946995), + Offset(19.248834712358185, 34.86668062539688), + Offset(18.465078394956763, 34.48918310598561), + Offset(17.067862896878044, 33.62308654166575), + Offset(14.711614443143937, 31.375349080711565), + Offset(12.105677503717876, 24.620906478295183), + Offset(14.516075349646359, 16.52219347588495), + Offset(17.969922566948043, 13.101945406078135), + Offset(20.66764026066227, 11.422142117815724), + Offset(22.8010263074904, 10.49390235619516), + Offset(24.506449439583058, 10.01736474419652), + Offset(25.85522211418056, 9.824385871307193), + Offset(26.907111410786875, 9.782742715250919), + Offset(27.71521184544836, 9.815279001947939), + Offset(28.323121893643616, 9.87830571566402), + Offset(28.76520131167873, 9.947188181495804), + Offset(29.068463998826257, 10.008746091751288), + Offset(29.25404641776217, 10.05636169624624), + Offset(29.33922422040887, 10.085942311817597), + ], + <Offset>[ + Offset(19.7425275, 35.0694285), + Offset(19.633231518178384, 35.02676980946995), + Offset(19.248834712358185, 34.86668062539688), + Offset(18.465078394956763, 34.48918310598561), + Offset(17.067862896878044, 33.62308654166575), + Offset(14.711614443143937, 31.375349080711565), + Offset(12.105677503717876, 24.620906478295183), + Offset(14.516075349646359, 16.52219347588495), + Offset(17.969922566948043, 13.101945406078135), + Offset(20.66764026066227, 11.422142117815724), + Offset(22.8010263074904, 10.49390235619516), + Offset(24.506449439583058, 10.01736474419652), + Offset(25.85522211418056, 9.824385871307193), + Offset(26.907111410786875, 9.782742715250919), + Offset(27.71521184544836, 9.815279001947939), + Offset(28.323121893643616, 9.87830571566402), + Offset(28.76520131167873, 9.947188181495804), + Offset(29.068463998826257, 10.008746091751288), + Offset(29.25404641776217, 10.05636169624624), + Offset(29.33922422040887, 10.085942311817597), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(19.7425275, 35.0694285), + Offset(19.633231518178384, 35.02676980946995), + Offset(19.248834712358185, 34.86668062539688), + Offset(18.465078394956763, 34.48918310598561), + Offset(17.067862896878044, 33.62308654166575), + Offset(14.711614443143937, 31.375349080711565), + Offset(12.105677503717876, 24.620906478295183), + Offset(14.516075349646359, 16.52219347588495), + Offset(17.969922566948043, 13.101945406078135), + Offset(20.66764026066227, 11.422142117815724), + Offset(22.8010263074904, 10.49390235619516), + Offset(24.506449439583058, 10.01736474419652), + Offset(25.85522211418056, 9.824385871307193), + Offset(26.907111410786875, 9.782742715250919), + Offset(27.71521184544836, 9.815279001947939), + Offset(28.323121893643616, 9.87830571566402), + Offset(28.76520131167873, 9.947188181495804), + Offset(29.068463998826257, 10.008746091751288), + Offset(29.25404641776217, 10.05636169624624), + Offset(29.33922422040887, 10.085942311817597), + ], + <Offset>[ + Offset(28.2574725, 35.0694285), + Offset(28.147759865199898, 35.111003892785995), + Offset(27.755158143717388, 35.24976029613705), + Offset(26.920438621917032, 35.49475348411108), + Offset(25.302956224572092, 35.788156110338775), + Offset(22.04777247580016, 35.69866180419461), + Offset(15.58729589027705, 32.43130132675867), + Offset(11.949484547495462, 24.804670438522713), + Offset(12.221246146549875, 19.951495900886627), + Offset(13.098034396141294, 16.896882634429737), + Offset(14.059562343216436, 14.778291336692531), + Offset(15.006114103327363, 13.28176338153867), + Offset(15.877949215009977, 12.234704590849294), + Offset(16.63082781513366, 11.498919936050715), + Offset(17.252457608236057, 10.981559981300084), + Offset(17.74592420474744, 10.620980293205921), + Offset(18.12022398183604, 10.375870760913198), + Offset(18.386576328652826, 10.218345965797791), + Offset(18.556235591081254, 10.129330154383384), + Offset(18.63928241378951, 10.094208990972067), + ], + <Offset>[ + Offset(28.2574725, 35.0694285), + Offset(28.147759865199898, 35.111003892785995), + Offset(27.755158143717388, 35.24976029613705), + Offset(26.920438621917032, 35.49475348411108), + Offset(25.302956224572092, 35.788156110338775), + Offset(22.04777247580016, 35.69866180419461), + Offset(15.58729589027705, 32.43130132675867), + Offset(11.949484547495462, 24.804670438522713), + Offset(12.221246146549875, 19.951495900886627), + Offset(13.098034396141294, 16.896882634429737), + Offset(14.059562343216436, 14.778291336692531), + Offset(15.006114103327363, 13.28176338153867), + Offset(15.877949215009977, 12.234704590849294), + Offset(16.63082781513366, 11.498919936050715), + Offset(17.252457608236057, 10.981559981300084), + Offset(17.74592420474744, 10.620980293205921), + Offset(18.12022398183604, 10.375870760913198), + Offset(18.386576328652826, 10.218345965797791), + Offset(18.556235591081254, 10.129330154383384), + Offset(18.63928241378951, 10.094208990972067), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(28.2574725, 35.0694285), + Offset(28.147759865199898, 35.111003892785995), + Offset(27.755158143717388, 35.24976029613705), + Offset(26.920438621917032, 35.49475348411108), + Offset(25.302956224572092, 35.788156110338775), + Offset(22.04777247580016, 35.69866180419461), + Offset(15.58729589027705, 32.43130132675867), + Offset(11.949484547495462, 24.804670438522713), + Offset(12.221246146549875, 19.951495900886627), + Offset(13.098034396141294, 16.896882634429737), + Offset(14.059562343216436, 14.778291336692531), + Offset(15.006114103327363, 13.28176338153867), + Offset(15.877949215009977, 12.234704590849294), + Offset(16.63082781513366, 11.498919936050715), + Offset(17.252457608236057, 10.981559981300084), + Offset(17.74592420474744, 10.620980293205921), + Offset(18.12022398183604, 10.375870760913198), + Offset(18.386576328652826, 10.218345965797791), + Offset(18.556235591081254, 10.129330154383384), + Offset(18.63928241378951, 10.094208990972067), + ], + <Offset>[ + Offset(28.2574725, 24.8514945), + Offset(28.248840765179153, 24.893569876360175), + Offset(28.214853748605588, 25.042172178506007), + Offset(28.12712307566759, 25.34832121175876), + Offset(27.90103970697972, 25.90604411710592), + Offset(27.235747743979807, 26.895272165007142), + Offset(24.959769708433235, 28.253359262887663), + Offset(21.888456902660778, 27.88457940110379), + Offset(20.440706740320067, 26.84990760536443), + Offset(19.66772301607811, 25.980409671854908), + Offset(19.20082911981328, 25.26804809382129), + Offset(18.92339246813794, 24.682165785045505), + Offset(18.770331678460497, 24.207432069853994), + Offset(18.690240480093415, 23.830460250834577), + Offset(18.651994783458633, 23.536865065954846), + Offset(18.637133697797722, 23.313617519881333), + Offset(18.634643077136914, 23.149843556724427), + Offset(18.638096177508633, 23.03661117000591), + Offset(18.643797740845827, 22.966703146400476), + Offset(18.649202428774874, 22.9341391589153), + ], + <Offset>[ + Offset(28.2574725, 24.8514945), + Offset(28.248840765179153, 24.893569876360175), + Offset(28.214853748605588, 25.042172178506007), + Offset(28.12712307566759, 25.34832121175876), + Offset(27.90103970697972, 25.90604411710592), + Offset(27.235747743979807, 26.895272165007142), + Offset(24.959769708433235, 28.253359262887663), + Offset(21.888456902660778, 27.88457940110379), + Offset(20.440706740320067, 26.84990760536443), + Offset(19.66772301607811, 25.980409671854908), + Offset(19.20082911981328, 25.26804809382129), + Offset(18.92339246813794, 24.682165785045505), + Offset(18.770331678460497, 24.207432069853994), + Offset(18.690240480093415, 23.830460250834577), + Offset(18.651994783458633, 23.536865065954846), + Offset(18.637133697797722, 23.313617519881333), + Offset(18.634643077136914, 23.149843556724427), + Offset(18.638096177508633, 23.03661117000591), + Offset(18.643797740845827, 22.966703146400476), + Offset(18.649202428774874, 22.9341391589153), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.146341463415, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(18.0395385, 24.851494500000005), + Offset(18.03140674875334, 24.79248897638092), + Offset(18.007265630974544, 24.58247657361781), + Offset(17.98069080331527, 24.141636758008197), + Offset(18.018927713746866, 23.30796063469829), + Offset(18.432358104792343, 21.707296896827494), + Offset(20.78182764456223, 18.880885444731472), + Offset(24.96836586524185, 17.945607045938473), + Offset(27.339118444797872, 18.63044701159424), + Offset(28.751250053503288, 19.41072105191809), + Offset(29.690585876942034, 20.12678131722444), + Offset(30.323794871644772, 20.764887420234924), + Offset(30.7430591574652, 21.315049606403473), + Offset(31.021780794877273, 21.771047585874822), + Offset(31.20729986811339, 22.13732789073227), + Offset(31.32977092447313, 22.42240802683105), + Offset(31.408615872948143, 22.635424461423554), + Offset(31.456361381716757, 22.785091321150105), + Offset(31.48117073286292, 22.87914099663591), + Offset(31.489132596718107, 22.924219143929935), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.0395385, 24.851494500000005), + Offset(18.03140674875334, 24.79248897638092), + Offset(18.007265630974544, 24.58247657361781), + Offset(17.98069080331527, 24.141636758008197), + Offset(18.018927713746866, 23.30796063469829), + Offset(18.432358104792343, 21.707296896827494), + Offset(20.78182764456223, 18.880885444731472), + Offset(24.96836586524185, 17.945607045938473), + Offset(27.339118444797872, 18.63044701159424), + Offset(28.751250053503288, 19.41072105191809), + Offset(29.690585876942034, 20.12678131722444), + Offset(30.323794871644772, 20.764887420234924), + Offset(30.7430591574652, 21.315049606403473), + Offset(31.021780794877273, 21.771047585874822), + Offset(31.20729986811339, 22.13732789073227), + Offset(31.32977092447313, 22.42240802683105), + Offset(31.408615872948143, 22.635424461423554), + Offset(31.456361381716757, 22.785091321150105), + Offset(31.48117073286292, 22.87914099663591), + Offset(31.489132596718107, 22.924219143929935), + ], + <Offset>[ + Offset(9.5245935, 24.851494500000005), + Offset(9.516878401731827, 24.708254893064876), + Offset(9.500942199615341, 24.199396902877645), + Offset(9.525330576355001, 23.136066379882735), + Offset(9.783834386052819, 21.142891066025268), + Offset(11.09620007213612, 17.383984173344455), + Offset(17.300209258003058, 11.070490596267984), + Offset(27.534956667392745, 9.663130083300711), + Offset(33.08779486519604, 11.780896516785745), + Offset(36.320855918024264, 13.935980535304076), + Offset(38.432049841216, 15.842392336727073), + Offset(39.82413020790047, 17.500488782892777), + Offset(40.72033205663578, 18.904730886861373), + Offset(41.298064390530485, 20.054870365075026), + Offset(41.67005410532569, 20.971046911380125), + Offset(41.90696861336931, 21.67973344928915), + Offset(42.053593202790836, 22.20674188200616), + Offset(42.138249051890185, 22.5754914471036), + Offset(42.178981559543836, 22.806172538498764), + Offset(42.189074403337465, 22.915952464775465), + ], + <Offset>[ + Offset(9.5245935, 24.851494500000005), + Offset(9.516878401731827, 24.708254893064876), + Offset(9.500942199615341, 24.199396902877645), + Offset(9.525330576355001, 23.136066379882735), + Offset(9.783834386052819, 21.142891066025268), + Offset(11.09620007213612, 17.383984173344455), + Offset(17.300209258003058, 11.070490596267984), + Offset(27.534956667392745, 9.663130083300711), + Offset(33.08779486519604, 11.780896516785745), + Offset(36.320855918024264, 13.935980535304076), + Offset(38.432049841216, 15.842392336727073), + Offset(39.82413020790047, 17.500488782892777), + Offset(40.72033205663578, 18.904730886861373), + Offset(41.298064390530485, 20.054870365075026), + Offset(41.67005410532569, 20.971046911380125), + Offset(41.90696861336931, 21.67973344928915), + Offset(42.053593202790836, 22.20674188200616), + Offset(42.138249051890185, 22.5754914471036), + Offset(42.178981559543836, 22.806172538498764), + Offset(42.189074403337465, 22.915952464775465), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(9.5245935, 24.851494500000005), + Offset(9.516878401731827, 24.708254893064876), + Offset(9.500942199615341, 24.199396902877645), + Offset(9.525330576355001, 23.136066379882735), + Offset(9.783834386052819, 21.142891066025268), + Offset(11.09620007213612, 17.383984173344455), + Offset(17.300209258003058, 11.070490596267984), + Offset(27.534956667392745, 9.663130083300711), + Offset(33.08779486519604, 11.780896516785745), + Offset(36.320855918024264, 13.935980535304076), + Offset(38.432049841216, 15.842392336727073), + Offset(39.82413020790047, 17.500488782892777), + Offset(40.72033205663578, 18.904730886861373), + Offset(41.298064390530485, 20.054870365075026), + Offset(41.67005410532569, 20.971046911380125), + Offset(41.90696861336931, 21.67973344928915), + Offset(42.053593202790836, 22.20674188200616), + Offset(42.138249051890185, 22.5754914471036), + Offset(42.178981559543836, 22.806172538498764), + Offset(42.189074403337465, 22.915952464775465), + ], + <Offset>[ + Offset(9.524593500000002, 35.06942850000001), + Offset(9.415797501752571, 34.92568890949069), + Offset(9.041246594727141, 34.406985020508685), + Offset(8.318646122604441, 33.282498652235056), + Offset(7.185750903645189, 31.025003059258125), + Offset(5.908224803956472, 26.187373812531924), + Offset(7.92773543984687, 15.24843266013899), + Offset(17.59598431222743, 6.583221120719635), + Offset(24.868334271425848, 4.882484812307943), + Offset(29.75116729808745, 4.852453497878906), + Offset(33.290783064619156, 5.352635579598315), + Offset(35.90685184308989, 6.1000863793859414), + Offset(37.82794959318526, 6.932003407856674), + Offset(39.23865172557073, 7.723330050291165), + Offset(40.27051693010311, 8.415741826725363), + Offset(41.015759120319025, 8.987096222613737), + Offset(41.53917410748996, 9.43276908619493), + Offset(41.886729203034385, 9.757226242895484), + Offset(42.09141940977926, 9.968799546481671), + Offset(42.1791543883521, 10.076022296832232), + ], + <Offset>[ + Offset(9.524593500000002, 35.06942850000001), + Offset(9.415797501752571, 34.92568890949069), + Offset(9.041246594727141, 34.406985020508685), + Offset(8.318646122604441, 33.282498652235056), + Offset(7.185750903645189, 31.025003059258125), + Offset(5.908224803956472, 26.187373812531924), + Offset(7.92773543984687, 15.24843266013899), + Offset(17.59598431222743, 6.583221120719635), + Offset(24.868334271425848, 4.882484812307943), + Offset(29.75116729808745, 4.852453497878906), + Offset(33.290783064619156, 5.352635579598315), + Offset(35.90685184308989, 6.1000863793859414), + Offset(37.82794959318526, 6.932003407856674), + Offset(39.23865172557073, 7.723330050291165), + Offset(40.27051693010311, 8.415741826725363), + Offset(41.015759120319025, 8.987096222613737), + Offset(41.53917410748996, 9.43276908619493), + Offset(41.886729203034385, 9.757226242895484), + Offset(42.09141940977926, 9.968799546481671), + Offset(42.1791543883521, 10.076022296832232), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(9.524593500000002, 35.06942850000001), + Offset(9.415797501752571, 34.92568890949069), + Offset(9.041246594727141, 34.406985020508685), + Offset(8.318646122604441, 33.282498652235056), + Offset(7.185750903645189, 31.025003059258125), + Offset(5.908224803956472, 26.187373812531924), + Offset(7.92773543984687, 15.24843266013899), + Offset(17.59598431222743, 6.583221120719635), + Offset(24.868334271425848, 4.882484812307943), + Offset(29.75116729808745, 4.852453497878906), + Offset(33.290783064619156, 5.352635579598315), + Offset(35.90685184308989, 6.1000863793859414), + Offset(37.82794959318526, 6.932003407856674), + Offset(39.23865172557073, 7.723330050291165), + Offset(40.27051693010311, 8.415741826725363), + Offset(41.015759120319025, 8.987096222613737), + Offset(41.53917410748996, 9.43276908619493), + Offset(41.886729203034385, 9.757226242895484), + Offset(42.09141940977926, 9.968799546481671), + Offset(42.1791543883521, 10.076022296832232), + ], + <Offset>[ + Offset(18.0395385, 35.0694285), + Offset(17.930325848774086, 35.009922992806736), + Offset(17.547570026086344, 34.79006469124885), + Offset(16.77400634956471, 34.28806903036052), + Offset(15.420844231339236, 33.190072627931144), + Offset(13.244382836612694, 30.510686536014962), + Offset(11.409353826406043, 23.05882750860248), + Offset(15.029393510076535, 14.865698083357398), + Offset(19.119657851027682, 11.732035307116437), + Offset(22.181561433566472, 10.327194014492921), + Offset(24.549319100345187, 9.637024560095686), + Offset(26.406516506834194, 9.36448501672809), + Offset(27.85067669401468, 9.342322127398774), + Offset(28.962368129917518, 9.43950727109096), + Offset(29.807762692890815, 9.582022806077507), + Offset(30.438561431422848, 9.729770800155638), + Offset(30.89419677764727, 9.861451665612325), + Offset(31.20484153286095, 9.966826116941988), + Offset(31.39360858309835, 10.041768004618815), + Offset(31.479212581732742, 10.084288975986702), + ], + <Offset>[ + Offset(18.0395385, 35.0694285), + Offset(17.930325848774086, 35.009922992806736), + Offset(17.547570026086344, 34.79006469124885), + Offset(16.77400634956471, 34.28806903036052), + Offset(15.420844231339236, 33.190072627931144), + Offset(13.244382836612694, 30.510686536014962), + Offset(11.409353826406043, 23.05882750860248), + Offset(15.029393510076535, 14.865698083357398), + Offset(19.119657851027682, 11.732035307116437), + Offset(22.181561433566472, 10.327194014492921), + Offset(24.549319100345187, 9.637024560095686), + Offset(26.406516506834194, 9.36448501672809), + Offset(27.85067669401468, 9.342322127398774), + Offset(28.962368129917518, 9.43950727109096), + Offset(29.807762692890815, 9.582022806077507), + Offset(30.438561431422848, 9.729770800155638), + Offset(30.89419677764727, 9.861451665612325), + Offset(31.20484153286095, 9.966826116941988), + Offset(31.39360858309835, 10.041768004618815), + Offset(31.479212581732742, 10.084288975986702), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.0395385, 35.0694285), + Offset(17.930325848774086, 35.009922992806736), + Offset(17.547570026086344, 34.79006469124885), + Offset(16.77400634956471, 34.28806903036052), + Offset(15.420844231339236, 33.190072627931144), + Offset(13.244382836612694, 30.510686536014962), + Offset(11.409353826406043, 23.05882750860248), + Offset(15.029393510076535, 14.865698083357398), + Offset(19.119657851027682, 11.732035307116437), + Offset(22.181561433566472, 10.327194014492921), + Offset(24.549319100345187, 9.637024560095686), + Offset(26.406516506834194, 9.36448501672809), + Offset(27.85067669401468, 9.342322127398774), + Offset(28.962368129917518, 9.43950727109096), + Offset(29.807762692890815, 9.582022806077507), + Offset(30.438561431422848, 9.729770800155638), + Offset(30.89419677764727, 9.861451665612325), + Offset(31.20484153286095, 9.966826116941988), + Offset(31.39360858309835, 10.041768004618815), + Offset(31.479212581732742, 10.084288975986702), + ], + <Offset>[ + Offset(18.0395385, 24.851494500000005), + Offset(18.03140674875334, 24.79248897638092), + Offset(18.007265630974544, 24.58247657361781), + Offset(17.98069080331527, 24.141636758008197), + Offset(18.018927713746866, 23.30796063469829), + Offset(18.432358104792343, 21.707296896827494), + Offset(20.78182764456223, 18.880885444731472), + Offset(24.96836586524185, 17.945607045938473), + Offset(27.339118444797872, 18.63044701159424), + Offset(28.751250053503288, 19.41072105191809), + Offset(29.690585876942034, 20.12678131722444), + Offset(30.323794871644772, 20.764887420234924), + Offset(30.7430591574652, 21.315049606403473), + Offset(31.021780794877273, 21.771047585874822), + Offset(31.20729986811339, 22.13732789073227), + Offset(31.32977092447313, 22.42240802683105), + Offset(31.408615872948143, 22.635424461423554), + Offset(31.456361381716757, 22.785091321150105), + Offset(31.48117073286292, 22.87914099663591), + Offset(31.489132596718107, 22.924219143929935), + ], + <Offset>[ + Offset(18.0395385, 24.851494500000005), + Offset(18.03140674875334, 24.79248897638092), + Offset(18.007265630974544, 24.58247657361781), + Offset(17.98069080331527, 24.141636758008197), + Offset(18.018927713746866, 23.30796063469829), + Offset(18.432358104792343, 21.707296896827494), + Offset(20.78182764456223, 18.880885444731472), + Offset(24.96836586524185, 17.945607045938473), + Offset(27.339118444797872, 18.63044701159424), + Offset(28.751250053503288, 19.41072105191809), + Offset(29.690585876942034, 20.12678131722444), + Offset(30.323794871644772, 20.764887420234924), + Offset(30.7430591574652, 21.315049606403473), + Offset(31.021780794877273, 21.771047585874822), + Offset(31.20729986811339, 22.13732789073227), + Offset(31.32977092447313, 22.42240802683105), + Offset(31.408615872948143, 22.635424461423554), + Offset(31.456361381716757, 22.785091321150105), + Offset(31.48117073286292, 22.87914099663591), + Offset(31.489132596718107, 22.924219143929935), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.146341463415, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(38.4754065, 12.930571500000003), + Offset(38.58420249824743, 13.074311090509312), + Offset(38.958753405272866, 13.593014979491326), + Offset(39.681353877395566, 14.717501347764943), + Offset(40.81424909635481, 16.97499694074188), + Offset(42.09177519604353, 21.812626187468076), + Offset(40.07226456015313, 32.75156733986101), + Offset(30.404015687772564, 41.41677887928036), + Offset(23.131665728574156, 43.11751518769206), + Offset(18.248832701912562, 43.147546502121095), + Offset(14.709216935380839, 42.647364420401686), + Offset(12.093148156910111, 41.89991362061406), + Offset(10.17205040681474, 41.06799659214333), + Offset(8.761348274429261, 40.276669949708825), + Offset(7.729483069896876, 39.58425817327465), + Offset(6.984240879680973, 39.012903777386256), + Offset(6.460825892510038, 38.56723091380506), + Offset(6.1132707969656215, 38.242773757104516), + Offset(5.908580590220735, 38.03120045351832), + Offset(5.820845611647898, 37.923977703167765), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.4754065, 12.930571500000003), + Offset(38.58420249824743, 13.074311090509312), + Offset(38.958753405272866, 13.593014979491326), + Offset(39.681353877395566, 14.717501347764943), + Offset(40.81424909635481, 16.97499694074188), + Offset(42.09177519604353, 21.812626187468076), + Offset(40.07226456015313, 32.75156733986101), + Offset(30.404015687772564, 41.41677887928036), + Offset(23.131665728574156, 43.11751518769206), + Offset(18.248832701912562, 43.147546502121095), + Offset(14.709216935380839, 42.647364420401686), + Offset(12.093148156910111, 41.89991362061406), + Offset(10.17205040681474, 41.06799659214333), + Offset(8.761348274429261, 40.276669949708825), + Offset(7.729483069896876, 39.58425817327465), + Offset(6.984240879680973, 39.012903777386256), + Offset(6.460825892510038, 38.56723091380506), + Offset(6.1132707969656215, 38.242773757104516), + Offset(5.908580590220735, 38.03120045351832), + Offset(5.820845611647898, 37.923977703167765), + ], + <Offset>[ + Offset(29.9604615, 12.930571500000003), + Offset(30.069674151225918, 12.990077007193268), + Offset(30.452429973913663, 13.20993530875116), + Offset(31.225993650435292, 13.711930969639477), + Offset(32.57915576866076, 14.80992737206886), + Offset(34.755617163387306, 17.489313463985035), + Offset(36.59064617359396, 24.94117249139752), + Offset(32.970606489923455, 33.1343019166426), + Offset(28.880342148972325, 36.26796469288357), + Offset(25.81843856643354, 37.672805985507075), + Offset(23.450680899654806, 38.36297543990432), + Offset(21.593483493165806, 38.63551498327191), + Offset(20.149323305985323, 38.657677872601234), + Offset(19.03763187008248, 38.56049272890903), + Offset(18.192237307109178, 38.417977193922496), + Offset(17.56143856857715, 38.27022919984435), + Offset(17.10580322235273, 38.13854833438767), + Offset(16.795158467139053, 38.03317388305801), + Offset(16.606391416901644, 37.95823199538118), + Offset(16.520787418267258, 37.9157110240133), + ], + <Offset>[ + Offset(29.9604615, 12.930571500000003), + Offset(30.069674151225918, 12.990077007193268), + Offset(30.452429973913663, 13.20993530875116), + Offset(31.225993650435292, 13.711930969639477), + Offset(32.57915576866076, 14.80992737206886), + Offset(34.755617163387306, 17.489313463985035), + Offset(36.59064617359396, 24.94117249139752), + Offset(32.970606489923455, 33.1343019166426), + Offset(28.880342148972325, 36.26796469288357), + Offset(25.81843856643354, 37.672805985507075), + Offset(23.450680899654806, 38.36297543990432), + Offset(21.593483493165806, 38.63551498327191), + Offset(20.149323305985323, 38.657677872601234), + Offset(19.03763187008248, 38.56049272890903), + Offset(18.192237307109178, 38.417977193922496), + Offset(17.56143856857715, 38.27022919984435), + Offset(17.10580322235273, 38.13854833438767), + Offset(16.795158467139053, 38.03317388305801), + Offset(16.606391416901644, 37.95823199538118), + Offset(16.520787418267258, 37.9157110240133), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(29.9604615, 12.930571500000003), + Offset(30.069674151225918, 12.990077007193268), + Offset(30.452429973913663, 13.20993530875116), + Offset(31.225993650435292, 13.711930969639477), + Offset(32.57915576866076, 14.80992737206886), + Offset(34.755617163387306, 17.489313463985035), + Offset(36.59064617359396, 24.94117249139752), + Offset(32.970606489923455, 33.1343019166426), + Offset(28.880342148972325, 36.26796469288357), + Offset(25.81843856643354, 37.672805985507075), + Offset(23.450680899654806, 38.36297543990432), + Offset(21.593483493165806, 38.63551498327191), + Offset(20.149323305985323, 38.657677872601234), + Offset(19.03763187008248, 38.56049272890903), + Offset(18.192237307109178, 38.417977193922496), + Offset(17.56143856857715, 38.27022919984435), + Offset(17.10580322235273, 38.13854833438767), + Offset(16.795158467139053, 38.03317388305801), + Offset(16.606391416901644, 37.95823199538118), + Offset(16.520787418267258, 37.9157110240133), + ], + <Offset>[ + Offset(29.9604615, 23.148505500000002), + Offset(29.968593251246663, 23.207511023619084), + Offset(29.992734369025463, 23.4175234263822), + Offset(30.019309196684734, 23.858363241991796), + Offset(29.98107228625313, 24.692039365301717), + Offset(29.567641895207657, 26.2927031031725), + Offset(27.218172355437773, 29.119114555268528), + Offset(23.031634134758143, 30.054392954061523), + Offset(20.66088155520213, 29.369552988405765), + Offset(19.248749946496723, 28.58927894808191), + Offset(18.30941412305796, 27.87321868277556), + Offset(17.676205128355228, 27.235112579765072), + Offset(17.256940842534803, 26.684950393596534), + Offset(16.978219205122727, 26.228952414125168), + Offset(16.7927001318866, 25.862672109267738), + Offset(16.67022907552687, 25.57759197316894), + Offset(16.591384127051857, 25.364575538576442), + Offset(16.543638618283246, 25.21490867884989), + Offset(16.518829267137072, 25.12085900336409), + Offset(16.510867403281896, 25.075780856070065), + ], + <Offset>[ + Offset(29.9604615, 23.148505500000002), + Offset(29.968593251246663, 23.207511023619084), + Offset(29.992734369025463, 23.4175234263822), + Offset(30.019309196684734, 23.858363241991796), + Offset(29.98107228625313, 24.692039365301717), + Offset(29.567641895207657, 26.2927031031725), + Offset(27.218172355437773, 29.119114555268528), + Offset(23.031634134758143, 30.054392954061523), + Offset(20.66088155520213, 29.369552988405765), + Offset(19.248749946496723, 28.58927894808191), + Offset(18.30941412305796, 27.87321868277556), + Offset(17.676205128355228, 27.235112579765072), + Offset(17.256940842534803, 26.684950393596534), + Offset(16.978219205122727, 26.228952414125168), + Offset(16.7927001318866, 25.862672109267738), + Offset(16.67022907552687, 25.57759197316894), + Offset(16.591384127051857, 25.364575538576442), + Offset(16.543638618283246, 25.21490867884989), + Offset(16.518829267137072, 25.12085900336409), + Offset(16.510867403281896, 25.075780856070065), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(29.9604615, 23.148505500000002), + Offset(29.968593251246663, 23.207511023619084), + Offset(29.992734369025463, 23.4175234263822), + Offset(30.019309196684734, 23.858363241991796), + Offset(29.98107228625313, 24.692039365301717), + Offset(29.567641895207657, 26.2927031031725), + Offset(27.218172355437773, 29.119114555268528), + Offset(23.031634134758143, 30.054392954061523), + Offset(20.66088155520213, 29.369552988405765), + Offset(19.248749946496723, 28.58927894808191), + Offset(18.30941412305796, 27.87321868277556), + Offset(17.676205128355228, 27.235112579765072), + Offset(17.256940842534803, 26.684950393596534), + Offset(16.978219205122727, 26.228952414125168), + Offset(16.7927001318866, 25.862672109267738), + Offset(16.67022907552687, 25.57759197316894), + Offset(16.591384127051857, 25.364575538576442), + Offset(16.543638618283246, 25.21490867884989), + Offset(16.518829267137072, 25.12085900336409), + Offset(16.510867403281896, 25.075780856070065), + ], + <Offset>[ + Offset(38.4754065, 23.148505500000002), + Offset(38.48312159826818, 23.291745106935128), + Offset(38.49905780038466, 23.800603097122366), + Offset(38.474669423645004, 24.863933620117265), + Offset(38.216165613947176, 26.85710893397474), + Offset(36.90379992786388, 30.61601582665554), + Offset(30.699790741996942, 36.92950940373201), + Offset(20.465043332607248, 38.336869916699285), + Offset(14.912205134803964, 36.219103483214255), + Offset(11.679144081975746, 34.064019464695924), + Offset(9.567950158783995, 32.15760766327293), + Offset(8.175869792099533, 30.499511217107223), + Offset(7.2796679433642195, 29.095269113138635), + Offset(6.701935609469508, 27.945129634924964), + Offset(6.3299458946742995, 27.028953088619883), + Offset(6.093031386630692, 26.32026655071084), + Offset(5.946406797209165, 25.793258117993837), + Offset(5.861750948109816, 25.424508552896395), + Offset(5.821018440456163, 25.19382746150123), + Offset(5.810925596662535, 25.084047535224535), + ], + <Offset>[ + Offset(38.4754065, 23.148505500000002), + Offset(38.48312159826818, 23.291745106935128), + Offset(38.49905780038466, 23.800603097122366), + Offset(38.474669423645004, 24.863933620117265), + Offset(38.216165613947176, 26.85710893397474), + Offset(36.90379992786388, 30.61601582665554), + Offset(30.699790741996942, 36.92950940373201), + Offset(20.465043332607248, 38.336869916699285), + Offset(14.912205134803964, 36.219103483214255), + Offset(11.679144081975746, 34.064019464695924), + Offset(9.567950158783995, 32.15760766327293), + Offset(8.175869792099533, 30.499511217107223), + Offset(7.2796679433642195, 29.095269113138635), + Offset(6.701935609469508, 27.945129634924964), + Offset(6.3299458946742995, 27.028953088619883), + Offset(6.093031386630692, 26.32026655071084), + Offset(5.946406797209165, 25.793258117993837), + Offset(5.861750948109816, 25.424508552896395), + Offset(5.821018440456163, 25.19382746150123), + Offset(5.810925596662535, 25.084047535224535), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(38.4754065, 23.148505500000002), + Offset(38.48312159826818, 23.291745106935128), + Offset(38.49905780038466, 23.800603097122366), + Offset(38.474669423645004, 24.863933620117265), + Offset(38.216165613947176, 26.85710893397474), + Offset(36.90379992786388, 30.61601582665554), + Offset(30.699790741996942, 36.92950940373201), + Offset(20.465043332607248, 38.336869916699285), + Offset(14.912205134803964, 36.219103483214255), + Offset(11.679144081975746, 34.064019464695924), + Offset(9.567950158783995, 32.15760766327293), + Offset(8.175869792099533, 30.499511217107223), + Offset(7.2796679433642195, 29.095269113138635), + Offset(6.701935609469508, 27.945129634924964), + Offset(6.3299458946742995, 27.028953088619883), + Offset(6.093031386630692, 26.32026655071084), + Offset(5.946406797209165, 25.793258117993837), + Offset(5.861750948109816, 25.424508552896395), + Offset(5.821018440456163, 25.19382746150123), + Offset(5.810925596662535, 25.084047535224535), + ], + <Offset>[ + Offset(38.4754065, 12.930571500000003), + Offset(38.58420249824743, 13.074311090509312), + Offset(38.958753405272866, 13.593014979491326), + Offset(39.681353877395566, 14.717501347764943), + Offset(40.81424909635481, 16.97499694074188), + Offset(42.09177519604353, 21.812626187468076), + Offset(40.07226456015313, 32.75156733986101), + Offset(30.404015687772564, 41.41677887928036), + Offset(23.131665728574156, 43.11751518769206), + Offset(18.248832701912562, 43.147546502121095), + Offset(14.709216935380839, 42.647364420401686), + Offset(12.093148156910111, 41.89991362061406), + Offset(10.17205040681474, 41.06799659214333), + Offset(8.761348274429261, 40.276669949708825), + Offset(7.729483069896876, 39.58425817327465), + Offset(6.984240879680973, 39.012903777386256), + Offset(6.460825892510038, 38.56723091380506), + Offset(6.1132707969656215, 38.242773757104516), + Offset(5.908580590220735, 38.03120045351832), + Offset(5.820845611647898, 37.923977703167765), + ], + <Offset>[ + Offset(38.4754065, 12.930571500000003), + Offset(38.58420249824743, 13.074311090509312), + Offset(38.958753405272866, 13.593014979491326), + Offset(39.681353877395566, 14.717501347764943), + Offset(40.81424909635481, 16.97499694074188), + Offset(42.09177519604353, 21.812626187468076), + Offset(40.07226456015313, 32.75156733986101), + Offset(30.404015687772564, 41.41677887928036), + Offset(23.131665728574156, 43.11751518769206), + Offset(18.248832701912562, 43.147546502121095), + Offset(14.709216935380839, 42.647364420401686), + Offset(12.093148156910111, 41.89991362061406), + Offset(10.17205040681474, 41.06799659214333), + Offset(8.761348274429261, 40.276669949708825), + Offset(7.729483069896876, 39.58425817327465), + Offset(6.984240879680973, 39.012903777386256), + Offset(6.460825892510038, 38.56723091380506), + Offset(6.1132707969656215, 38.242773757104516), + Offset(5.908580590220735, 38.03120045351832), + Offset(5.820845611647898, 37.923977703167765), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.146341463415, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(28.257472499999995, 12.930571500000006), + Offset(28.366768481821616, 12.973230190530057), + Offset(28.75116528764182, 13.133319374603126), + Offset(29.53492160504324, 13.510816894014384), + Offset(30.932137103121953, 14.376913458334252), + Offset(33.28838555685606, 16.624650919288428), + Offset(35.89432249628212, 23.37909352170482), + Offset(33.48392465035364, 31.477806524115046), + Offset(30.030077433051954, 34.89805459392186), + Offset(27.33235973933773, 36.577857882184276), + Offset(25.1989736925096, 37.50609764380484), + Offset(23.49355056041695, 37.98263525580348), + Offset(22.14477788581944, 38.17561412869281), + Offset(21.092888589213125, 38.217257284749074), + Offset(20.284788154551638, 38.18472099805207), + Offset(19.676878106356384, 38.12169428433597), + Offset(19.234798688321266, 38.052811818504196), + Offset(18.93153600117374, 37.99125390824871), + Offset(18.74595358223783, 37.94363830375375), + Offset(18.66077577959113, 37.914057688182396), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(28.257472499999995, 12.930571500000006), + Offset(28.366768481821616, 12.973230190530057), + Offset(28.75116528764182, 13.133319374603126), + Offset(29.53492160504324, 13.510816894014384), + Offset(30.932137103121953, 14.376913458334252), + Offset(33.28838555685606, 16.624650919288428), + Offset(35.89432249628212, 23.37909352170482), + Offset(33.48392465035364, 31.477806524115046), + Offset(30.030077433051954, 34.89805459392186), + Offset(27.33235973933773, 36.577857882184276), + Offset(25.1989736925096, 37.50609764380484), + Offset(23.49355056041695, 37.98263525580348), + Offset(22.14477788581944, 38.17561412869281), + Offset(21.092888589213125, 38.217257284749074), + Offset(20.284788154551638, 38.18472099805207), + Offset(19.676878106356384, 38.12169428433597), + Offset(19.234798688321266, 38.052811818504196), + Offset(18.93153600117374, 37.99125390824871), + Offset(18.74595358223783, 37.94363830375375), + Offset(18.66077577959113, 37.914057688182396), + ], + <Offset>[ + Offset(19.742527499999994, 12.930571500000006), + Offset(19.852240134800102, 12.888996107214012), + Offset(20.244841856282616, 12.75023970386296), + Offset(21.07956137808297, 12.505246515888919), + Offset(22.697043775427904, 12.211843889661228), + Offset(25.95222752419984, 12.30133819580539), + Offset(32.41270410972295, 15.568698673241332), + Offset(36.05051545250454, 23.195329561477283), + Offset(35.77875385345012, 28.048504099113373), + Offset(34.901965603858706, 31.10311736557026), + Offset(33.940437656783566, 33.221708663307474), + Offset(32.993885896672644, 34.71823661846133), + Offset(32.12205078499002, 35.7652954091507), + Offset(31.369172184866343, 36.50108006394928), + Offset(30.74754239176394, 37.01844001869992), + Offset(30.25407579525256, 37.379019706794075), + Offset(29.879776018163955, 37.6241292390868), + Offset(29.61342367134717, 37.781654034202205), + Offset(29.44376440891874, 37.87066984561661), + Offset(29.36071758621049, 37.90579100902793), + ], + <Offset>[ + Offset(19.742527499999994, 12.930571500000006), + Offset(19.852240134800102, 12.888996107214012), + Offset(20.244841856282616, 12.75023970386296), + Offset(21.07956137808297, 12.505246515888919), + Offset(22.697043775427904, 12.211843889661228), + Offset(25.95222752419984, 12.30133819580539), + Offset(32.41270410972295, 15.568698673241332), + Offset(36.05051545250454, 23.195329561477283), + Offset(35.77875385345012, 28.048504099113373), + Offset(34.901965603858706, 31.10311736557026), + Offset(33.940437656783566, 33.221708663307474), + Offset(32.993885896672644, 34.71823661846133), + Offset(32.12205078499002, 35.7652954091507), + Offset(31.369172184866343, 36.50108006394928), + Offset(30.74754239176394, 37.01844001869992), + Offset(30.25407579525256, 37.379019706794075), + Offset(29.879776018163955, 37.6241292390868), + Offset(29.61342367134717, 37.781654034202205), + Offset(29.44376440891874, 37.87066984561661), + Offset(29.36071758621049, 37.90579100902793), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(19.742527499999994, 12.930571500000006), + Offset(19.852240134800102, 12.888996107214012), + Offset(20.244841856282616, 12.75023970386296), + Offset(21.07956137808297, 12.505246515888919), + Offset(22.697043775427904, 12.211843889661228), + Offset(25.95222752419984, 12.30133819580539), + Offset(32.41270410972295, 15.568698673241332), + Offset(36.05051545250454, 23.195329561477283), + Offset(35.77875385345012, 28.048504099113373), + Offset(34.901965603858706, 31.10311736557026), + Offset(33.940437656783566, 33.221708663307474), + Offset(32.993885896672644, 34.71823661846133), + Offset(32.12205078499002, 35.7652954091507), + Offset(31.369172184866343, 36.50108006394928), + Offset(30.74754239176394, 37.01844001869992), + Offset(30.25407579525256, 37.379019706794075), + Offset(29.879776018163955, 37.6241292390868), + Offset(29.61342367134717, 37.781654034202205), + Offset(29.44376440891874, 37.87066984561661), + Offset(29.36071758621049, 37.90579100902793), + ], + <Offset>[ + Offset(19.742527499999998, 23.148505500000006), + Offset(19.751159234820847, 23.10643012363983), + Offset(19.785146251394416, 22.957827821494), + Offset(19.872876924332413, 22.65167878824124), + Offset(20.098960293020276, 22.093955882894086), + Offset(20.764252256020193, 21.104727834992858), + Offset(23.040230291566765, 19.74664073711234), + Offset(26.111543097339222, 20.115420598896208), + Offset(27.55929325967993, 21.15009239463557), + Offset(28.33227698392189, 22.01959032814509), + Offset(28.79917088018672, 22.731951906178715), + Offset(29.076607531862066, 23.317834214954495), + Offset(29.229668321539503, 23.792567930146006), + Offset(29.309759519906592, 24.16953974916542), + Offset(29.348005216541363, 24.46313493404516), + Offset(29.362866302202278, 24.686382480118663), + Offset(29.365356922863082, 24.85015644327557), + Offset(29.361903822491364, 24.96338882999409), + Offset(29.356202259154166, 25.033296853599516), + Offset(29.350797571225126, 25.065860841084696), + ], + <Offset>[ + Offset(19.742527499999998, 23.148505500000006), + Offset(19.751159234820847, 23.10643012363983), + Offset(19.785146251394416, 22.957827821494), + Offset(19.872876924332413, 22.65167878824124), + Offset(20.098960293020276, 22.093955882894086), + Offset(20.764252256020193, 21.104727834992858), + Offset(23.040230291566765, 19.74664073711234), + Offset(26.111543097339222, 20.115420598896208), + Offset(27.55929325967993, 21.15009239463557), + Offset(28.33227698392189, 22.01959032814509), + Offset(28.79917088018672, 22.731951906178715), + Offset(29.076607531862066, 23.317834214954495), + Offset(29.229668321539503, 23.792567930146006), + Offset(29.309759519906592, 24.16953974916542), + Offset(29.348005216541363, 24.46313493404516), + Offset(29.362866302202278, 24.686382480118663), + Offset(29.365356922863082, 24.85015644327557), + Offset(29.361903822491364, 24.96338882999409), + Offset(29.356202259154166, 25.033296853599516), + Offset(29.350797571225126, 25.065860841084696), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(19.742527499999998, 23.148505500000006), + Offset(19.751159234820847, 23.10643012363983), + Offset(19.785146251394416, 22.957827821494), + Offset(19.872876924332413, 22.65167878824124), + Offset(20.098960293020276, 22.093955882894086), + Offset(20.764252256020193, 21.104727834992858), + Offset(23.040230291566765, 19.74664073711234), + Offset(26.111543097339222, 20.115420598896208), + Offset(27.55929325967993, 21.15009239463557), + Offset(28.33227698392189, 22.01959032814509), + Offset(28.79917088018672, 22.731951906178715), + Offset(29.076607531862066, 23.317834214954495), + Offset(29.229668321539503, 23.792567930146006), + Offset(29.309759519906592, 24.16953974916542), + Offset(29.348005216541363, 24.46313493404516), + Offset(29.362866302202278, 24.686382480118663), + Offset(29.365356922863082, 24.85015644327557), + Offset(29.361903822491364, 24.96338882999409), + Offset(29.356202259154166, 25.033296853599516), + Offset(29.350797571225126, 25.065860841084696), + ], + <Offset>[ + Offset(28.2574725, 23.148505500000006), + Offset(28.26568758184236, 23.190664206955873), + Offset(28.29146968275362, 23.340907492234166), + Offset(28.328237151292683, 23.657249166366704), + Offset(28.334053620714325, 24.25902545156711), + Offset(28.100410288676414, 25.428040558475896), + Offset(26.521848678125934, 27.55703558557583), + Offset(23.544952295188327, 28.39789756153397), + Offset(21.810616839281764, 27.99964288944406), + Offset(20.762671119400913, 27.4943308447591), + Offset(20.057706915912753, 27.016340886676083), + Offset(19.57627219560637, 26.582232852296645), + Offset(19.25239542236892, 26.202886649688107), + Offset(19.033475924253374, 25.885716969965216), + Offset(18.88525097932906, 25.629415913397306), + Offset(18.7856686133061, 25.429057057660565), + Offset(18.720379593020393, 25.278839022692964), + Offset(18.680016152317933, 25.172988704040595), + Offset(18.65839143247326, 25.106265311736657), + Offset(18.650855764605765, 25.074127520239166), + ], + <Offset>[ + Offset(28.2574725, 23.148505500000006), + Offset(28.26568758184236, 23.190664206955873), + Offset(28.29146968275362, 23.340907492234166), + Offset(28.328237151292683, 23.657249166366704), + Offset(28.334053620714325, 24.25902545156711), + Offset(28.100410288676414, 25.428040558475896), + Offset(26.521848678125934, 27.55703558557583), + Offset(23.544952295188327, 28.39789756153397), + Offset(21.810616839281764, 27.99964288944406), + Offset(20.762671119400913, 27.4943308447591), + Offset(20.057706915912753, 27.016340886676083), + Offset(19.57627219560637, 26.582232852296645), + Offset(19.25239542236892, 26.202886649688107), + Offset(19.033475924253374, 25.885716969965216), + Offset(18.88525097932906, 25.629415913397306), + Offset(18.7856686133061, 25.429057057660565), + Offset(18.720379593020393, 25.278839022692964), + Offset(18.680016152317933, 25.172988704040595), + Offset(18.65839143247326, 25.106265311736657), + Offset(18.650855764605765, 25.074127520239166), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(28.2574725, 23.148505500000006), + Offset(28.26568758184236, 23.190664206955873), + Offset(28.29146968275362, 23.340907492234166), + Offset(28.328237151292683, 23.657249166366704), + Offset(28.334053620714325, 24.25902545156711), + Offset(28.100410288676414, 25.428040558475896), + Offset(26.521848678125934, 27.55703558557583), + Offset(23.544952295188327, 28.39789756153397), + Offset(21.810616839281764, 27.99964288944406), + Offset(20.762671119400913, 27.4943308447591), + Offset(20.057706915912753, 27.016340886676083), + Offset(19.57627219560637, 26.582232852296645), + Offset(19.25239542236892, 26.202886649688107), + Offset(19.033475924253374, 25.885716969965216), + Offset(18.88525097932906, 25.629415913397306), + Offset(18.7856686133061, 25.429057057660565), + Offset(18.720379593020393, 25.278839022692964), + Offset(18.680016152317933, 25.172988704040595), + Offset(18.65839143247326, 25.106265311736657), + Offset(18.650855764605765, 25.074127520239166), + ], + <Offset>[ + Offset(28.257472499999995, 12.930571500000006), + Offset(28.366768481821616, 12.973230190530057), + Offset(28.75116528764182, 13.133319374603126), + Offset(29.53492160504324, 13.510816894014384), + Offset(30.932137103121953, 14.376913458334252), + Offset(33.28838555685606, 16.624650919288428), + Offset(35.89432249628212, 23.37909352170482), + Offset(33.48392465035364, 31.477806524115046), + Offset(30.030077433051954, 34.89805459392186), + Offset(27.33235973933773, 36.577857882184276), + Offset(25.1989736925096, 37.50609764380484), + Offset(23.49355056041695, 37.98263525580348), + Offset(22.14477788581944, 38.17561412869281), + Offset(21.092888589213125, 38.217257284749074), + Offset(20.284788154551638, 38.18472099805207), + Offset(19.676878106356384, 38.12169428433597), + Offset(19.234798688321266, 38.052811818504196), + Offset(18.93153600117374, 37.99125390824871), + Offset(18.74595358223783, 37.94363830375375), + Offset(18.66077577959113, 37.914057688182396), + ], + <Offset>[ + Offset(28.257472499999995, 12.930571500000006), + Offset(28.366768481821616, 12.973230190530057), + Offset(28.75116528764182, 13.133319374603126), + Offset(29.53492160504324, 13.510816894014384), + Offset(30.932137103121953, 14.376913458334252), + Offset(33.28838555685606, 16.624650919288428), + Offset(35.89432249628212, 23.37909352170482), + Offset(33.48392465035364, 31.477806524115046), + Offset(30.030077433051954, 34.89805459392186), + Offset(27.33235973933773, 36.577857882184276), + Offset(25.1989736925096, 37.50609764380484), + Offset(23.49355056041695, 37.98263525580348), + Offset(22.14477788581944, 38.17561412869281), + Offset(21.092888589213125, 38.217257284749074), + Offset(20.284788154551638, 38.18472099805207), + Offset(19.676878106356384, 38.12169428433597), + Offset(19.234798688321266, 38.052811818504196), + Offset(18.93153600117374, 37.99125390824871), + Offset(18.74595358223783, 37.94363830375375), + Offset(18.66077577959113, 37.914057688182396), + ], + ), + _PathClose( + ), + ], + ), + ], + matchTextDirection: true, +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/menu_arrow.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/menu_arrow.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..4717a9361575405bd915914d6013f7fd2daebb90 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/menu_arrow.g.dart @@ -0,0 +1,1027 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$menu_arrow = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(6.0, 26.0), + Offset(5.976562557689849, 25.638185989482512), + Offset(5.951781669661045, 24.367972149512962), + Offset(6.172793116155802, 21.823631861702058), + Offset(7.363587976838016, 17.665129222832853), + Offset(11.400806749308899, 11.800457098273661), + Offset(17.41878573585796, 8.03287301910486), + Offset(24.257523532175192, 6.996159828679087), + Offset(29.90338248135665, 8.291042849526), + Offset(33.76252909490214, 10.56619705548221), + Offset(36.23501636298456, 12.973675163618006), + Offset(37.77053540180521, 15.158665125787222), + Offset(38.70420448893307, 17.008159945496722), + Offset(39.260392038988186, 18.5104805430827), + Offset(39.58393261852967, 19.691668944482075), + Offset(39.766765502294305, 20.58840471665747), + Offset(39.866421084642994, 21.237322746452932), + Offset(39.91802804639694, 21.671102155152063), + Offset(39.94204075298555, 21.917555098992118), + Offset(39.94920417650143, 21.999827480806236), + Offset(39.94921875, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 26.0), + Offset(5.976562557689849, 25.638185989482512), + Offset(5.951781669661045, 24.367972149512962), + Offset(6.172793116155802, 21.823631861702058), + Offset(7.363587976838016, 17.665129222832853), + Offset(11.400806749308899, 11.800457098273661), + Offset(17.41878573585796, 8.03287301910486), + Offset(24.257523532175192, 6.996159828679087), + Offset(29.90338248135665, 8.291042849526), + Offset(33.76252909490214, 10.56619705548221), + Offset(36.23501636298456, 12.973675163618006), + Offset(37.77053540180521, 15.158665125787222), + Offset(38.70420448893307, 17.008159945496722), + Offset(39.260392038988186, 18.5104805430827), + Offset(39.58393261852967, 19.691668944482075), + Offset(39.766765502294305, 20.58840471665747), + Offset(39.866421084642994, 21.237322746452932), + Offset(39.91802804639694, 21.671102155152063), + Offset(39.94204075298555, 21.917555098992118), + Offset(39.94920417650143, 21.999827480806236), + Offset(39.94921875, 22.0), + ], + <Offset>[ + Offset(42.0, 26.0), + Offset(41.91421333157091, 26.360426629492423), + Offset(41.55655262500356, 27.60382930516768), + Offset(40.57766190556539, 29.99090297157744), + Offset(38.19401046368096, 33.57567286235671), + Offset(32.70215654116029, 37.756226919427284), + Offset(26.22621984436523, 39.26167875408963), + Offset(20.102351173097617, 38.04803275423973), + Offset(15.903199608216863, 35.25316524725598), + Offset(13.57741782841064, 32.27000071222682), + Offset(12.442030802775209, 29.665215617986277), + Offset(11.981806515947115, 27.560177578292762), + Offset(11.879421136842055, 25.918712565594948), + Offset(11.95091483982305, 24.66543021784112), + Offset(12.092167805674123, 23.72603017548901), + Offset(12.245452640806768, 23.03857447590349), + Offset(12.379956070248545, 22.554583229506296), + Offset(12.480582865035407, 22.237279988168645), + Offset(12.541514124262473, 22.059212079933666), + Offset(12.562455771803593, 22.000123717314214), + Offset(12.562499999999996, 22.000000000000004), + ], + <Offset>[ + Offset(42.0, 26.0), + Offset(41.91421333157091, 26.360426629492423), + Offset(41.55655262500356, 27.60382930516768), + Offset(40.57766190556539, 29.99090297157744), + Offset(38.19401046368096, 33.57567286235671), + Offset(32.70215654116029, 37.756226919427284), + Offset(26.22621984436523, 39.26167875408963), + Offset(20.102351173097617, 38.04803275423973), + Offset(15.903199608216863, 35.25316524725598), + Offset(13.57741782841064, 32.27000071222682), + Offset(12.442030802775209, 29.665215617986277), + Offset(11.981806515947115, 27.560177578292762), + Offset(11.879421136842055, 25.918712565594948), + Offset(11.95091483982305, 24.66543021784112), + Offset(12.092167805674123, 23.72603017548901), + Offset(12.245452640806768, 23.03857447590349), + Offset(12.379956070248545, 22.554583229506296), + Offset(12.480582865035407, 22.237279988168645), + Offset(12.541514124262473, 22.059212079933666), + Offset(12.562455771803593, 22.000123717314214), + Offset(12.562499999999996, 22.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 26.0), + Offset(41.91421333157091, 26.360426629492423), + Offset(41.55655262500356, 27.60382930516768), + Offset(40.57766190556539, 29.99090297157744), + Offset(38.19401046368096, 33.57567286235671), + Offset(32.70215654116029, 37.756226919427284), + Offset(26.22621984436523, 39.26167875408963), + Offset(20.102351173097617, 38.04803275423973), + Offset(15.903199608216863, 35.25316524725598), + Offset(13.57741782841064, 32.27000071222682), + Offset(12.442030802775209, 29.665215617986277), + Offset(11.981806515947115, 27.560177578292762), + Offset(11.879421136842055, 25.918712565594948), + Offset(11.95091483982305, 24.66543021784112), + Offset(12.092167805674123, 23.72603017548901), + Offset(12.245452640806768, 23.03857447590349), + Offset(12.379956070248545, 22.554583229506296), + Offset(12.480582865035407, 22.237279988168645), + Offset(12.541514124262473, 22.059212079933666), + Offset(12.562455771803593, 22.000123717314214), + Offset(12.562499999999996, 22.000000000000004), + ], + <Offset>[ + Offset(42.0, 22.0), + Offset(41.99458528858859, 22.361234167441474), + Offset(41.91859127809106, 23.620246996030513), + Offset(41.501535596836376, 26.09905798461081), + Offset(40.02840620381446, 30.021099432452637), + Offset(35.79419835461124, 35.2186537827727), + Offset(30.076040790179817, 38.175916954629336), + Offset(24.067012730992623, 38.57855959743385), + Offset(19.453150566288006, 37.096490556388844), + Offset(16.506465839286186, 34.99409280868502), + Offset(14.73924581501028, 32.939784778587686), + Offset(13.715334530064114, 31.165018854170466), + Offset(13.140377980959201, 29.714761542791386), + Offset(12.83036672005031, 28.56755327976071), + Offset(12.672939622830032, 27.683643609921106), + Offset(12.600162038813565, 27.02281609043513), + Offset(12.571432188039635, 26.54999771317575), + Offset(12.56310619400641, 26.23642863509033), + Offset(12.562193301685781, 26.059158626029138), + Offset(12.562499038934627, 26.000123717080207), + Offset(12.562499999999996, 26.000000000000004), + ], + <Offset>[ + Offset(42.0, 22.0), + Offset(41.99458528858859, 22.361234167441474), + Offset(41.91859127809106, 23.620246996030513), + Offset(41.501535596836376, 26.09905798461081), + Offset(40.02840620381446, 30.021099432452637), + Offset(35.79419835461124, 35.2186537827727), + Offset(30.076040790179817, 38.175916954629336), + Offset(24.067012730992623, 38.57855959743385), + Offset(19.453150566288006, 37.096490556388844), + Offset(16.506465839286186, 34.99409280868502), + Offset(14.73924581501028, 32.939784778587686), + Offset(13.715334530064114, 31.165018854170466), + Offset(13.140377980959201, 29.714761542791386), + Offset(12.83036672005031, 28.56755327976071), + Offset(12.672939622830032, 27.683643609921106), + Offset(12.600162038813565, 27.02281609043513), + Offset(12.571432188039635, 26.54999771317575), + Offset(12.56310619400641, 26.23642863509033), + Offset(12.562193301685781, 26.059158626029138), + Offset(12.562499038934627, 26.000123717080207), + Offset(12.562499999999996, 26.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 22.0), + Offset(41.99458528858859, 22.361234167441474), + Offset(41.91859127809106, 23.620246996030513), + Offset(41.501535596836376, 26.09905798461081), + Offset(40.02840620381446, 30.021099432452637), + Offset(35.79419835461124, 35.2186537827727), + Offset(30.076040790179817, 38.175916954629336), + Offset(24.067012730992623, 38.57855959743385), + Offset(19.453150566288006, 37.096490556388844), + Offset(16.506465839286186, 34.99409280868502), + Offset(14.73924581501028, 32.939784778587686), + Offset(13.715334530064114, 31.165018854170466), + Offset(13.140377980959201, 29.714761542791386), + Offset(12.83036672005031, 28.56755327976071), + Offset(12.672939622830032, 27.683643609921106), + Offset(12.600162038813565, 27.02281609043513), + Offset(12.571432188039635, 26.54999771317575), + Offset(12.56310619400641, 26.23642863509033), + Offset(12.562193301685781, 26.059158626029138), + Offset(12.562499038934627, 26.000123717080207), + Offset(12.562499999999996, 26.000000000000004), + ], + <Offset>[ + Offset(6.0, 22.0), + Offset(6.056934514707525, 21.63899352743156), + Offset(6.3138203227485405, 20.384389840375796), + Offset(7.096666807426793, 17.931786874735423), + Offset(9.197983716971518, 14.110555792928775), + Offset(14.492848562759846, 9.262883961619078), + Offset(21.26860668167255, 6.947111219644562), + Offset(28.222185090070198, 7.526686671873211), + Offset(33.453333439427794, 10.134368158658866), + Offset(36.69157710577769, 13.290289151940406), + Offset(38.53223137521963, 16.248244324219414), + Offset(39.50406341592221, 18.763506401664923), + Offset(39.965161333050226, 20.80420892269316), + Offset(40.139843919215444, 22.41260360500229), + Offset(40.164704435685586, 23.649282378914172), + Offset(40.1214749003011, 24.572646331189105), + Offset(40.057897202434084, 25.232737230122385), + Offset(40.00055137536795, 25.670250802073745), + Offset(39.96271993040885, 25.917501645087587), + Offset(39.949247443632466, 25.99982748057223), + Offset(39.94921875, 26.0), + ], + <Offset>[ + Offset(6.0, 22.0), + Offset(6.056934514707525, 21.63899352743156), + Offset(6.3138203227485405, 20.384389840375796), + Offset(7.096666807426793, 17.931786874735423), + Offset(9.197983716971518, 14.110555792928775), + Offset(14.492848562759846, 9.262883961619078), + Offset(21.26860668167255, 6.947111219644562), + Offset(28.222185090070198, 7.526686671873211), + Offset(33.453333439427794, 10.134368158658866), + Offset(36.69157710577769, 13.290289151940406), + Offset(38.53223137521963, 16.248244324219414), + Offset(39.50406341592221, 18.763506401664923), + Offset(39.965161333050226, 20.80420892269316), + Offset(40.139843919215444, 22.41260360500229), + Offset(40.164704435685586, 23.649282378914172), + Offset(40.1214749003011, 24.572646331189105), + Offset(40.057897202434084, 25.232737230122385), + Offset(40.00055137536795, 25.670250802073745), + Offset(39.96271993040885, 25.917501645087587), + Offset(39.949247443632466, 25.99982748057223), + Offset(39.94921875, 26.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 22.0), + Offset(6.056934514707525, 21.63899352743156), + Offset(6.3138203227485405, 20.384389840375796), + Offset(7.096666807426793, 17.931786874735423), + Offset(9.197983716971518, 14.110555792928775), + Offset(14.492848562759846, 9.262883961619078), + Offset(21.26860668167255, 6.947111219644562), + Offset(28.222185090070198, 7.526686671873211), + Offset(33.453333439427794, 10.134368158658866), + Offset(36.69157710577769, 13.290289151940406), + Offset(38.53223137521963, 16.248244324219414), + Offset(39.50406341592221, 18.763506401664923), + Offset(39.965161333050226, 20.80420892269316), + Offset(40.139843919215444, 22.41260360500229), + Offset(40.164704435685586, 23.649282378914172), + Offset(40.1214749003011, 24.572646331189105), + Offset(40.057897202434084, 25.232737230122385), + Offset(40.00055137536795, 25.670250802073745), + Offset(39.96271993040885, 25.917501645087587), + Offset(39.949247443632466, 25.99982748057223), + Offset(39.94921875, 26.0), + ], + <Offset>[ + Offset(6.0, 26.0), + Offset(5.976562557689849, 25.638185989482512), + Offset(5.951781669661045, 24.367972149512962), + Offset(6.172793116155802, 21.823631861702058), + Offset(7.363587976838016, 17.665129222832853), + Offset(11.400806749308899, 11.800457098273661), + Offset(17.41878573585796, 8.03287301910486), + Offset(24.257523532175192, 6.996159828679087), + Offset(29.90338248135665, 8.291042849526), + Offset(33.76252909490214, 10.56619705548221), + Offset(36.23501636298456, 12.973675163618006), + Offset(37.77053540180521, 15.158665125787222), + Offset(38.70420448893307, 17.008159945496722), + Offset(39.260392038988186, 18.5104805430827), + Offset(39.58393261852967, 19.691668944482075), + Offset(39.766765502294305, 20.58840471665747), + Offset(39.866421084642994, 21.237322746452932), + Offset(39.91802804639694, 21.671102155152063), + Offset(39.94204075298555, 21.917555098992118), + Offset(39.94920417650143, 21.999827480806236), + Offset(39.94921875, 22.0), + ], + <Offset>[ + Offset(6.0, 26.0), + Offset(5.976562557689849, 25.638185989482512), + Offset(5.951781669661045, 24.367972149512962), + Offset(6.172793116155802, 21.823631861702058), + Offset(7.363587976838016, 17.665129222832853), + Offset(11.400806749308899, 11.800457098273661), + Offset(17.41878573585796, 8.03287301910486), + Offset(24.257523532175192, 6.996159828679087), + Offset(29.90338248135665, 8.291042849526), + Offset(33.76252909490214, 10.56619705548221), + Offset(36.23501636298456, 12.973675163618006), + Offset(37.77053540180521, 15.158665125787222), + Offset(38.70420448893307, 17.008159945496722), + Offset(39.260392038988186, 18.5104805430827), + Offset(39.58393261852967, 19.691668944482075), + Offset(39.766765502294305, 20.58840471665747), + Offset(39.866421084642994, 21.237322746452932), + Offset(39.91802804639694, 21.671102155152063), + Offset(39.94204075298555, 21.917555098992118), + Offset(39.94920417650143, 21.999827480806236), + Offset(39.94921875, 22.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(6.0, 36.0), + Offset(5.8396336833594695, 35.66398057820908), + Offset(5.329309336374063, 34.47365089829387), + Offset(4.546341863759643, 32.03857491308836), + Offset(3.9472816617934896, 27.893335303194206), + Offset(4.788314785722232, 21.470485758169694), + Offset(7.406922551234356, 16.186721598040453), + Offset(10.987511722222681, 12.449414121983239), + Offset(14.290737577882037, 10.382465570533384), + Offset(16.84152025666389, 9.340052761292668), + Offset(18.753361861843203, 8.79207829497377), + Offset(20.19495897321279, 8.483469022255434), + Offset(21.293826339887335, 8.297708512391797), + Offset(22.135385178177998, 8.180000583359465), + Offset(22.776244370552647, 8.102975309903787), + Offset(23.25488929254563, 8.051973096906334), + Offset(23.598629725699347, 8.018606137477462), + Offset(23.827700643867974, 7.99783596371886), + Offset(23.95771797811348, 7.986559676107813), + Offset(24.001111438945117, 7.982878122631195), + Offset(24.001202429357242, 7.98287044589657), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 36.0), + Offset(5.8396336833594695, 35.66398057820908), + Offset(5.329309336374063, 34.47365089829387), + Offset(4.546341863759643, 32.03857491308836), + Offset(3.9472816617934896, 27.893335303194206), + Offset(4.788314785722232, 21.470485758169694), + Offset(7.406922551234356, 16.186721598040453), + Offset(10.987511722222681, 12.449414121983239), + Offset(14.290737577882037, 10.382465570533384), + Offset(16.84152025666389, 9.340052761292668), + Offset(18.753361861843203, 8.79207829497377), + Offset(20.19495897321279, 8.483469022255434), + Offset(21.293826339887335, 8.297708512391797), + Offset(22.135385178177998, 8.180000583359465), + Offset(22.776244370552647, 8.102975309903787), + Offset(23.25488929254563, 8.051973096906334), + Offset(23.598629725699347, 8.018606137477462), + Offset(23.827700643867974, 7.99783596371886), + Offset(23.95771797811348, 7.986559676107813), + Offset(24.001111438945117, 7.982878122631195), + Offset(24.001202429357242, 7.98287044589657), + ], + <Offset>[ + Offset(42.0, 36.0), + Offset(41.7493389152824, 36.20520796529164), + Offset(40.85819701033384, 36.89246335931071), + Offset(39.01294315759756, 38.1256246432051), + Offset(35.758514239960064, 39.76970128020763), + Offset(30.180134511403956, 41.28645636464381), + Offset(24.56603417073137, 41.32925393403815), + Offset(19.271926095830622, 39.91690773672663), + Offset(15.201959304751512, 37.5726832793895), + Offset(12.456295622648877, 35.01429311055303), + Offset(10.686459838185314, 32.608514843335385), + Offset(9.579921816288039, 30.502293804851334), + Offset(8.90802993167501, 28.734147272525124), + Offset(8.513791284564158, 27.294928344333726), + Offset(8.292240475325507, 26.156988797411067), + Offset(8.174465865426919, 25.287693028463128), + Offset(8.11616441641861, 24.655137447505503), + Offset(8.089821190085125, 24.230473791307258), + Offset(8.079382709319852, 23.988506993748523), + Offset(8.076631388780909, 23.907616552409003), + Offset(8.076626005900048, 23.907446869353766), + ], + <Offset>[ + Offset(42.0, 36.0), + Offset(41.7493389152824, 36.20520796529164), + Offset(40.85819701033384, 36.89246335931071), + Offset(39.01294315759756, 38.1256246432051), + Offset(35.758514239960064, 39.76970128020763), + Offset(30.180134511403956, 41.28645636464381), + Offset(24.56603417073137, 41.32925393403815), + Offset(19.271926095830622, 39.91690773672663), + Offset(15.201959304751512, 37.5726832793895), + Offset(12.456295622648877, 35.01429311055303), + Offset(10.686459838185314, 32.608514843335385), + Offset(9.579921816288039, 30.502293804851334), + Offset(8.90802993167501, 28.734147272525124), + Offset(8.513791284564158, 27.294928344333726), + Offset(8.292240475325507, 26.156988797411067), + Offset(8.174465865426919, 25.287693028463128), + Offset(8.11616441641861, 24.655137447505503), + Offset(8.089821190085125, 24.230473791307258), + Offset(8.079382709319852, 23.988506993748523), + Offset(8.076631388780909, 23.907616552409003), + Offset(8.076626005900048, 23.907446869353766), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 36.0), + Offset(41.7493389152824, 36.20520796529164), + Offset(40.85819701033384, 36.89246335931071), + Offset(39.01294315759756, 38.1256246432051), + Offset(35.758514239960064, 39.76970128020763), + Offset(30.180134511403956, 41.28645636464381), + Offset(24.56603417073137, 41.32925393403815), + Offset(19.271926095830622, 39.91690773672663), + Offset(15.201959304751512, 37.5726832793895), + Offset(12.456295622648877, 35.01429311055303), + Offset(10.686459838185314, 32.608514843335385), + Offset(9.579921816288039, 30.502293804851334), + Offset(8.90802993167501, 28.734147272525124), + Offset(8.513791284564158, 27.294928344333726), + Offset(8.292240475325507, 26.156988797411067), + Offset(8.174465865426919, 25.287693028463128), + Offset(8.11616441641861, 24.655137447505503), + Offset(8.089821190085125, 24.230473791307258), + Offset(8.079382709319852, 23.988506993748523), + Offset(8.076631388780909, 23.907616552409003), + Offset(8.076626005900048, 23.907446869353766), + ], + <Offset>[ + Offset(42.0, 32.0), + Offset(41.803966700752746, 32.205577011286266), + Offset(41.104447603276626, 32.89996903899956), + Offset(39.64402995767152, 34.17517788052204), + Offset(37.031973302731046, 35.97545970343111), + Offset(32.44508133022271, 37.98012671725157), + Offset(27.6644042246058, 38.77327245743646), + Offset(22.963108117227325, 38.302914175295534), + Offset(19.18039906547299, 36.862333955479784), + Offset(16.509090720567585, 35.04434211490934), + Offset(14.703380298498667, 33.21759365821649), + Offset(13.512146444284534, 31.556733263561572), + Offset(12.740174664860898, 30.12862517729895), + Offset(12.248059307884624, 28.947244716051806), + Offset(11.939734974297815, 28.002595790430043), + Offset(11.750425410476474, 27.27521551305395), + Offset(11.637314290474384, 26.742992599694542), + Offset(11.572897732210654, 26.384358993735816), + Offset(11.54031155133882, 26.17955109507089), + Offset(11.530083003283234, 26.111009046369567), + Offset(11.530061897030713, 26.110865227715482), + ], + <Offset>[ + Offset(42.0, 32.0), + Offset(41.803966700752746, 32.205577011286266), + Offset(41.104447603276626, 32.89996903899956), + Offset(39.64402995767152, 34.17517788052204), + Offset(37.031973302731046, 35.97545970343111), + Offset(32.44508133022271, 37.98012671725157), + Offset(27.6644042246058, 38.77327245743646), + Offset(22.963108117227325, 38.302914175295534), + Offset(19.18039906547299, 36.862333955479784), + Offset(16.509090720567585, 35.04434211490934), + Offset(14.703380298498667, 33.21759365821649), + Offset(13.512146444284534, 31.556733263561572), + Offset(12.740174664860898, 30.12862517729895), + Offset(12.248059307884624, 28.947244716051806), + Offset(11.939734974297815, 28.002595790430043), + Offset(11.750425410476474, 27.27521551305395), + Offset(11.637314290474384, 26.742992599694542), + Offset(11.572897732210654, 26.384358993735816), + Offset(11.54031155133882, 26.17955109507089), + Offset(11.530083003283234, 26.111009046369567), + Offset(11.530061897030713, 26.110865227715482), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 32.0), + Offset(41.803966700752746, 32.205577011286266), + Offset(41.104447603276626, 32.89996903899956), + Offset(39.64402995767152, 34.17517788052204), + Offset(37.031973302731046, 35.97545970343111), + Offset(32.44508133022271, 37.98012671725157), + Offset(27.6644042246058, 38.77327245743646), + Offset(22.963108117227325, 38.302914175295534), + Offset(19.18039906547299, 36.862333955479784), + Offset(16.509090720567585, 35.04434211490934), + Offset(14.703380298498667, 33.21759365821649), + Offset(13.512146444284534, 31.556733263561572), + Offset(12.740174664860898, 30.12862517729895), + Offset(12.248059307884624, 28.947244716051806), + Offset(11.939734974297815, 28.002595790430043), + Offset(11.750425410476474, 27.27521551305395), + Offset(11.637314290474384, 26.742992599694542), + Offset(11.572897732210654, 26.384358993735816), + Offset(11.54031155133882, 26.17955109507089), + Offset(11.530083003283234, 26.111009046369567), + Offset(11.530061897030713, 26.110865227715482), + ], + <Offset>[ + Offset(6.0, 32.0), + Offset(5.899914425897517, 31.66443482499171), + Offset(5.601001082666045, 30.482888615847468), + Offset(5.242005036683729, 28.09953280239226), + Offset(5.346316156571252, 24.145975901906155), + Offset(7.249241148069178, 18.317100047682345), + Offset(10.710823881370487, 13.931896549234073), + Offset(14.817117889097364, 11.294374466111893), + Offset(18.288493245756, 10.248489378687303), + Offset(20.784419638077317, 10.013509863155594), + Offset(22.541938014255397, 10.075312777589325), + Offset(23.798109358346892, 10.220508832423288), + Offset(24.71461203122786, 10.370924674281323), + Offset(25.392890381083, 10.501349297587215), + Offset(25.896277759611298, 10.60605174724228), + Offset(26.265268043339944, 10.685909272436422), + Offset(26.526795349038366, 10.74364670273436), + Offset(26.699555102368272, 10.782158496973931), + Offset(26.79709065296033, 10.80399872839147), + Offset(26.829561509459538, 10.811282301423006), + Offset(26.829629554119695, 10.811297570626497), + ], + <Offset>[ + Offset(6.0, 32.0), + Offset(5.899914425897517, 31.66443482499171), + Offset(5.601001082666045, 30.482888615847468), + Offset(5.242005036683729, 28.09953280239226), + Offset(5.346316156571252, 24.145975901906155), + Offset(7.249241148069178, 18.317100047682345), + Offset(10.710823881370487, 13.931896549234073), + Offset(14.817117889097364, 11.294374466111893), + Offset(18.288493245756, 10.248489378687303), + Offset(20.784419638077317, 10.013509863155594), + Offset(22.541938014255397, 10.075312777589325), + Offset(23.798109358346892, 10.220508832423288), + Offset(24.71461203122786, 10.370924674281323), + Offset(25.392890381083, 10.501349297587215), + Offset(25.896277759611298, 10.60605174724228), + Offset(26.265268043339944, 10.685909272436422), + Offset(26.526795349038366, 10.74364670273436), + Offset(26.699555102368272, 10.782158496973931), + Offset(26.79709065296033, 10.80399872839147), + Offset(26.829561509459538, 10.811282301423006), + Offset(26.829629554119695, 10.811297570626497), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 32.0), + Offset(5.899914425897517, 31.66443482499171), + Offset(5.601001082666045, 30.482888615847468), + Offset(5.242005036683729, 28.09953280239226), + Offset(5.346316156571252, 24.145975901906155), + Offset(7.249241148069178, 18.317100047682345), + Offset(10.710823881370487, 13.931896549234073), + Offset(14.817117889097364, 11.294374466111893), + Offset(18.288493245756, 10.248489378687303), + Offset(20.784419638077317, 10.013509863155594), + Offset(22.541938014255397, 10.075312777589325), + Offset(23.798109358346892, 10.220508832423288), + Offset(24.71461203122786, 10.370924674281323), + Offset(25.392890381083, 10.501349297587215), + Offset(25.896277759611298, 10.60605174724228), + Offset(26.265268043339944, 10.685909272436422), + Offset(26.526795349038366, 10.74364670273436), + Offset(26.699555102368272, 10.782158496973931), + Offset(26.79709065296033, 10.80399872839147), + Offset(26.829561509459538, 10.811282301423006), + Offset(26.829629554119695, 10.811297570626497), + ], + <Offset>[ + Offset(6.0, 36.0), + Offset(5.839633683308566, 35.66398057820831), + Offset(5.329309336323984, 34.47365089829046), + Offset(4.546341863735712, 32.03857491308413), + Offset(3.947281661825336, 27.893335303206097), + Offset(4.788314785746671, 21.47048575818877), + Offset(7.406922551270995, 16.18672159809414), + Offset(10.98751172223972, 12.449414122039723), + Offset(14.290737577881032, 10.382465570503403), + Offset(16.841520256655304, 9.340052761342939), + Offset(18.753361861827802, 8.792078295019234), + Offset(20.194958973207576, 8.483469022266245), + Offset(21.293826339889407, 8.297708512388375), + Offset(22.13538517817335, 8.180000583365981), + Offset(22.776244370563283, 8.102975309890528), + Offset(23.25488929251534, 8.051973096940955), + Offset(23.598629725644848, 8.018606137536025), + Offset(23.82770064384222, 7.997835963745423), + Offset(23.957717978081078, 7.986559676140466), + Offset(24.001111438940168, 7.982878122636148), + Offset(24.001202429373503, 7.982870445880305), + ], + <Offset>[ + Offset(6.0, 36.0), + Offset(5.839633683308566, 35.66398057820831), + Offset(5.329309336323984, 34.47365089829046), + Offset(4.546341863735712, 32.03857491308413), + Offset(3.947281661825336, 27.893335303206097), + Offset(4.788314785746671, 21.47048575818877), + Offset(7.406922551270995, 16.18672159809414), + Offset(10.98751172223972, 12.449414122039723), + Offset(14.290737577881032, 10.382465570503403), + Offset(16.841520256655304, 9.340052761342939), + Offset(18.753361861827802, 8.792078295019234), + Offset(20.194958973207576, 8.483469022266245), + Offset(21.293826339889407, 8.297708512388375), + Offset(22.13538517817335, 8.180000583365981), + Offset(22.776244370563283, 8.102975309890528), + Offset(23.25488929251534, 8.051973096940955), + Offset(23.598629725644848, 8.018606137536025), + Offset(23.82770064384222, 7.997835963745423), + Offset(23.957717978081078, 7.986559676140466), + Offset(24.001111438940168, 7.982878122636148), + Offset(24.001202429373503, 7.982870445880305), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(6.0, 16.0), + Offset(6.222470088677106, 15.614531066984553), + Offset(7.071161725316092, 14.306422712262563), + Offset(9.085869786142727, 11.907139949336411), + Offset(13.311519331212619, 8.711520321213257), + Offset(21.694206315186374, 6.462423500731354), + Offset(30.07031570748504, 8.471955170698632), + Offset(36.20036889900587, 14.155750775196541), + Offset(38.533897479983715, 20.76099122996903), + Offset(38.182626701431914, 26.194302454359914), + Offset(36.59711302702814, 30.110286603895076), + Offset(34.63761335058528, 32.76106836363335), + Offset(32.7272901891386, 34.4927008221791), + Offset(31.04869117038896, 35.596105690451935), + Offset(29.664526028757855, 36.28441549314729), + Offset(28.581655311555835, 36.70452225851578), + Offset(27.782897949107628, 36.95396775456513), + Offset(27.242531133855476, 37.09522522130338), + Offset(26.933380541033216, 37.166375518103024), + Offset(26.82984682779076, 37.188656481991416), + Offset(26.829629554103434, 37.18870242935725), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 16.0), + Offset(6.222470088677106, 15.614531066984553), + Offset(7.071161725316092, 14.306422712262563), + Offset(9.085869786142727, 11.907139949336411), + Offset(13.311519331212619, 8.711520321213257), + Offset(21.694206315186374, 6.462423500731354), + Offset(30.07031570748504, 8.471955170698632), + Offset(36.20036889900587, 14.155750775196541), + Offset(38.533897479983715, 20.76099122996903), + Offset(38.182626701431914, 26.194302454359914), + Offset(36.59711302702814, 30.110286603895076), + Offset(34.63761335058528, 32.76106836363335), + Offset(32.7272901891386, 34.4927008221791), + Offset(31.04869117038896, 35.596105690451935), + Offset(29.664526028757855, 36.28441549314729), + Offset(28.581655311555835, 36.70452225851578), + Offset(27.782897949107628, 36.95396775456513), + Offset(27.242531133855476, 37.09522522130338), + Offset(26.933380541033216, 37.166375518103024), + Offset(26.82984682779076, 37.188656481991416), + Offset(26.829629554103434, 37.18870242935725), + ], + <Offset>[ + Offset(42.0, 16.0), + Offset(42.119273441095075, 16.516374018071716), + Offset(42.428662704565184, 18.32937541467259), + Offset(42.54812490043565, 21.94159775950881), + Offset(41.3111285319893, 27.683594454682137), + Offset(36.06395079582478, 35.01020271691918), + Offset(28.59459512599702, 38.51093769070532), + Offset(21.239886122259133, 38.07233071493643), + Offset(16.251628495692138, 35.34156866251391), + Offset(13.527101819238178, 32.27103394597236), + Offset(12.16858814546228, 29.604397296366464), + Offset(11.548946515009288, 27.474331231158473), + Offset(11.311114637013635, 25.826563435488687), + Offset(11.262012546535352, 24.572239162454554), + Offset(11.298221100690522, 23.63118177535833), + Offset(11.364474416879979, 22.940254245947138), + Offset(11.431638843687892, 22.451805922237554), + Offset(11.485090012547001, 22.130328573710905), + Offset(11.518417313485447, 21.949395273355513), + Offset(11.530012405933167, 21.889264075838188), + Offset(11.53003696527787, 21.889138124802937), + ], + <Offset>[ + Offset(42.0, 16.0), + Offset(42.119273441095075, 16.516374018071716), + Offset(42.428662704565184, 18.32937541467259), + Offset(42.54812490043565, 21.94159775950881), + Offset(41.3111285319893, 27.683594454682137), + Offset(36.06395079582478, 35.01020271691918), + Offset(28.59459512599702, 38.51093769070532), + Offset(21.239886122259133, 38.07233071493643), + Offset(16.251628495692138, 35.34156866251391), + Offset(13.527101819238178, 32.27103394597236), + Offset(12.16858814546228, 29.604397296366464), + Offset(11.548946515009288, 27.474331231158473), + Offset(11.311114637013635, 25.826563435488687), + Offset(11.262012546535352, 24.572239162454554), + Offset(11.298221100690522, 23.63118177535833), + Offset(11.364474416879979, 22.940254245947138), + Offset(11.431638843687892, 22.451805922237554), + Offset(11.485090012547001, 22.130328573710905), + Offset(11.518417313485447, 21.949395273355513), + Offset(11.530012405933167, 21.889264075838188), + Offset(11.53003696527787, 21.889138124802937), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 16.0), + Offset(42.119273441095075, 16.516374018071716), + Offset(42.428662704565184, 18.32937541467259), + Offset(42.54812490043565, 21.94159775950881), + Offset(41.3111285319893, 27.683594454682137), + Offset(36.06395079582478, 35.01020271691918), + Offset(28.59459512599702, 38.51093769070532), + Offset(21.239886122259133, 38.07233071493643), + Offset(16.251628495692138, 35.34156866251391), + Offset(13.527101819238178, 32.27103394597236), + Offset(12.16858814546228, 29.604397296366464), + Offset(11.548946515009288, 27.474331231158473), + Offset(11.311114637013635, 25.826563435488687), + Offset(11.262012546535352, 24.572239162454554), + Offset(11.298221100690522, 23.63118177535833), + Offset(11.364474416879979, 22.940254245947138), + Offset(11.431638843687892, 22.451805922237554), + Offset(11.485090012547001, 22.130328573710905), + Offset(11.518417313485447, 21.949395273355513), + Offset(11.530012405933167, 21.889264075838188), + Offset(11.53003696527787, 21.889138124802937), + ], + <Offset>[ + Offset(42.0, 12.0), + Offset(42.22538630246601, 12.517777761542249), + Offset(42.90619853384615, 14.357900907446863), + Offset(43.759884509852945, 18.128995147835514), + Offset(43.66585885175813, 24.44736028078141), + Offset(39.74861752085834, 33.43380529842439), + Offset(32.57188683977151, 39.07136996422343), + Offset(24.376857043988256, 40.600018479197814), + Offset(17.959269400168804, 39.004426856660785), + Offset(13.850567169499653, 36.311009998593796), + Offset(11.374155956344177, 33.58880277176081), + Offset(9.917496515696001, 31.204288894581083), + Offset(9.07498759074148, 29.236785710939074), + Offset(8.597571742452605, 27.666692096657314), + Offset(8.334783321442917, 26.44693980672826), + Offset(8.195874559699876, 25.52824222288586), + Offset(8.126295299747222, 24.866824239052814), + Offset(8.093843447379264, 24.426077640310794), + Offset(8.080338503727083, 24.17611706018137), + Offset(8.076619249177135, 24.092742069165425), + Offset(8.07661186374038, 24.09256727275783), + ], + <Offset>[ + Offset(42.0, 12.0), + Offset(42.22538630246601, 12.517777761542249), + Offset(42.90619853384615, 14.357900907446863), + Offset(43.759884509852945, 18.128995147835514), + Offset(43.66585885175813, 24.44736028078141), + Offset(39.74861752085834, 33.43380529842439), + Offset(32.57188683977151, 39.07136996422343), + Offset(24.376857043988256, 40.600018479197814), + Offset(17.959269400168804, 39.004426856660785), + Offset(13.850567169499653, 36.311009998593796), + Offset(11.374155956344177, 33.58880277176081), + Offset(9.917496515696001, 31.204288894581083), + Offset(9.07498759074148, 29.236785710939074), + Offset(8.597571742452605, 27.666692096657314), + Offset(8.334783321442917, 26.44693980672826), + Offset(8.195874559699876, 25.52824222288586), + Offset(8.126295299747222, 24.866824239052814), + Offset(8.093843447379264, 24.426077640310794), + Offset(8.080338503727083, 24.17611706018137), + Offset(8.076619249177135, 24.092742069165425), + Offset(8.07661186374038, 24.09256727275783), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 12.0), + Offset(42.22538630246601, 12.517777761542249), + Offset(42.90619853384615, 14.357900907446863), + Offset(43.759884509852945, 18.128995147835514), + Offset(43.66585885175813, 24.44736028078141), + Offset(39.74861752085834, 33.43380529842439), + Offset(32.57188683977151, 39.07136996422343), + Offset(24.376857043988256, 40.600018479197814), + Offset(17.959269400168804, 39.004426856660785), + Offset(13.850567169499653, 36.311009998593796), + Offset(11.374155956344177, 33.58880277176081), + Offset(9.917496515696001, 31.204288894581083), + Offset(9.07498759074148, 29.236785710939074), + Offset(8.597571742452605, 27.666692096657314), + Offset(8.334783321442917, 26.44693980672826), + Offset(8.195874559699876, 25.52824222288586), + Offset(8.126295299747222, 24.866824239052814), + Offset(8.093843447379264, 24.426077640310794), + Offset(8.080338503727083, 24.17611706018137), + Offset(8.076619249177135, 24.092742069165425), + Offset(8.07661186374038, 24.09256727275783), + ], + <Offset>[ + Offset(6.0, 12.0), + Offset(6.3229312318803075, 11.61579282114921), + Offset(7.523361420980265, 10.332065476778915), + Offset(10.234818160108134, 8.075701885898315), + Offset(15.555284551985588, 5.400098023461183), + Offset(25.267103519984172, 4.663978182144188), + Offset(34.065497532306516, 8.668225867992323), + Offset(39.59155761731576, 16.27703318845691), + Offset(40.72409454498984, 24.108085016590273), + Offset(39.139841854472834, 30.0780814324673), + Offset(36.514293313228855, 34.10942912386185), + Offset(33.744815583253256, 36.6601595585975), + Offset(31.226861893018718, 38.20062678263231), + Offset(29.10189988007002, 39.09038725780428), + Offset(27.3951953205187, 39.57837027981981), + Offset(26.083922435637483, 39.82883505984612), + Offset(25.128742795932077, 39.94653528477588), + Offset(24.487982707377697, 39.99564983955995), + Offset(24.123290412440365, 40.013021521592925), + Offset(24.001457946431486, 40.017121849607435), + Offset(24.001202429333205, 40.017129554079396), + ], + <Offset>[ + Offset(6.0, 12.0), + Offset(6.3229312318803075, 11.61579282114921), + Offset(7.523361420980265, 10.332065476778915), + Offset(10.234818160108134, 8.075701885898315), + Offset(15.555284551985588, 5.400098023461183), + Offset(25.267103519984172, 4.663978182144188), + Offset(34.065497532306516, 8.668225867992323), + Offset(39.59155761731576, 16.27703318845691), + Offset(40.72409454498984, 24.108085016590273), + Offset(39.139841854472834, 30.0780814324673), + Offset(36.514293313228855, 34.10942912386185), + Offset(33.744815583253256, 36.6601595585975), + Offset(31.226861893018718, 38.20062678263231), + Offset(29.10189988007002, 39.09038725780428), + Offset(27.3951953205187, 39.57837027981981), + Offset(26.083922435637483, 39.82883505984612), + Offset(25.128742795932077, 39.94653528477588), + Offset(24.487982707377697, 39.99564983955995), + Offset(24.123290412440365, 40.013021521592925), + Offset(24.001457946431486, 40.017121849607435), + Offset(24.001202429333205, 40.017129554079396), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 12.0), + Offset(6.3229312318803075, 11.61579282114921), + Offset(7.523361420980265, 10.332065476778915), + Offset(10.234818160108134, 8.075701885898315), + Offset(15.555284551985588, 5.400098023461183), + Offset(25.267103519984172, 4.663978182144188), + Offset(34.065497532306516, 8.668225867992323), + Offset(39.59155761731576, 16.27703318845691), + Offset(40.72409454498984, 24.108085016590273), + Offset(39.139841854472834, 30.0780814324673), + Offset(36.514293313228855, 34.10942912386185), + Offset(33.744815583253256, 36.6601595585975), + Offset(31.226861893018718, 38.20062678263231), + Offset(29.10189988007002, 39.09038725780428), + Offset(27.3951953205187, 39.57837027981981), + Offset(26.083922435637483, 39.82883505984612), + Offset(25.128742795932077, 39.94653528477588), + Offset(24.487982707377697, 39.99564983955995), + Offset(24.123290412440365, 40.013021521592925), + Offset(24.001457946431486, 40.017121849607435), + Offset(24.001202429333205, 40.017129554079396), + ], + <Offset>[ + Offset(6.0, 16.0), + Offset(6.22247008872931, 15.614531066985863), + Offset(7.071161725356028, 14.306422712267109), + Offset(9.085869786222908, 11.907139949360454), + Offset(13.311519331206826, 8.711520321209331), + Offset(21.69420631520211, 6.462423500762615), + Offset(30.070315707485825, 8.471955170682651), + Offset(36.20036889903345, 14.155750775152455), + Offset(38.53389748002304, 20.760991229943293), + Offset(38.18262670145813, 26.194302454353455), + Offset(36.597113027065134, 30.110286603895844), + Offset(34.63761335066132, 32.761068363650764), + Offset(32.72729018913396, 34.49270082217723), + Offset(31.048691170407302, 35.59610569046216), + Offset(29.66452602881138, 36.28441549318417), + Offset(28.58165531160348, 36.70452225855387), + Offset(27.78289794916673, 36.95396775461755), + Offset(27.24253113386635, 37.09522522131371), + Offset(26.933380541051008, 37.16637551812059), + Offset(26.829846827821875, 37.18865648202253), + Offset(26.829629554079393, 37.188702429333205), + ], + <Offset>[ + Offset(6.0, 16.0), + Offset(6.22247008872931, 15.614531066985863), + Offset(7.071161725356028, 14.306422712267109), + Offset(9.085869786222908, 11.907139949360454), + Offset(13.311519331206826, 8.711520321209331), + Offset(21.69420631520211, 6.462423500762615), + Offset(30.070315707485825, 8.471955170682651), + Offset(36.20036889903345, 14.155750775152455), + Offset(38.53389748002304, 20.760991229943293), + Offset(38.18262670145813, 26.194302454353455), + Offset(36.597113027065134, 30.110286603895844), + Offset(34.63761335066132, 32.761068363650764), + Offset(32.72729018913396, 34.49270082217723), + Offset(31.048691170407302, 35.59610569046216), + Offset(29.66452602881138, 36.28441549318417), + Offset(28.58165531160348, 36.70452225855387), + Offset(27.78289794916673, 36.95396775461755), + Offset(27.24253113386635, 37.09522522131371), + Offset(26.933380541051008, 37.16637551812059), + Offset(26.829846827821875, 37.18865648202253), + Offset(26.829629554079393, 37.188702429333205), + ], + ), + _PathClose( + ), + ], + ), + ], + matchTextDirection: true, +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/menu_close.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/menu_close.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..27d3408a91169333ccd5e1b666c5e51e4a0d5e17 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/menu_close.g.dart @@ -0,0 +1,1026 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$menu_close = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(6.0, 26.0), + Offset(6.667958372815065, 25.652081003354123), + Offset(8.330956385969174, 24.584197933972426), + Offset(10.795082531480682, 22.920903618043887), + Offset(14.118850428921743, 21.151292868049936), + Offset(18.25264983114299, 20.14945205026408), + Offset(21.311663261847183, 21.835975547204264), + Offset(22.017669221052497, 23.734736578402938), + Offset(22.22502452096443, 23.078337345433567), + Offset(22.535475994562226, 22.637953951770903), + Offset(22.851392493882464, 22.362715419699295), + Offset(23.1332359929415, 22.197579362061152), + Offset(23.369521577941427, 22.101975511401783), + Offset(23.560274059886364, 22.048938469040202), + Offset(23.709614091422043, 22.02119328278395), + Offset(23.822645300996605, 22.00787919273418), + Offset(23.90426194110445, 22.002292758165275), + Offset(23.958738335514504, 22.000425676539155), + Offset(23.989660411288344, 22.000026726952264), + Offset(23.999978366434483, 22.000000000117), + Offset(23.999999999999996, 22.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 26.0), + Offset(6.667958372815065, 25.652081003354123), + Offset(8.330956385969174, 24.584197933972426), + Offset(10.795082531480682, 22.920903618043887), + Offset(14.118850428921743, 21.151292868049936), + Offset(18.25264983114299, 20.14945205026408), + Offset(21.311663261847183, 21.835975547204264), + Offset(22.017669221052497, 23.734736578402938), + Offset(22.22502452096443, 23.078337345433567), + Offset(22.535475994562226, 22.637953951770903), + Offset(22.851392493882464, 22.362715419699295), + Offset(23.1332359929415, 22.197579362061152), + Offset(23.369521577941427, 22.101975511401783), + Offset(23.560274059886364, 22.048938469040202), + Offset(23.709614091422043, 22.02119328278395), + Offset(23.822645300996605, 22.00787919273418), + Offset(23.90426194110445, 22.002292758165275), + Offset(23.958738335514504, 22.000425676539155), + Offset(23.989660411288344, 22.000026726952264), + Offset(23.999978366434483, 22.000000000117), + Offset(23.999999999999996, 22.000000000000004), + ], + <Offset>[ + Offset(42.0, 26.0), + Offset(41.25166967016726, 26.34711145869683), + Offset(39.30700496104292, 27.399384375173792), + Offset(36.28104377724833, 28.970941368922745), + Offset(32.04675383085589, 30.403280561808284), + Offset(26.655308355431437, 30.38812108642142), + Offset(22.838515792338228, 27.24978625225603), + Offset(22.017669221052497, 23.734736578402938), + Offset(22.22502452096443, 23.078337345433567), + Offset(22.535475994562226, 22.637953951770903), + Offset(22.851392493882464, 22.362715419699295), + Offset(23.1332359929415, 22.197579362061152), + Offset(23.369521577941427, 22.101975511401783), + Offset(23.560274059886364, 22.048938469040202), + Offset(23.709614091422043, 22.02119328278395), + Offset(23.822645300996605, 22.00787919273418), + Offset(23.90426194110445, 22.002292758165275), + Offset(23.958738335514504, 22.000425676539155), + Offset(23.989660411288344, 22.000026726952264), + Offset(23.999978366434483, 22.000000000117), + Offset(23.999999999999996, 22.000000000000004), + ], + <Offset>[ + Offset(42.0, 26.0), + Offset(41.25166967016726, 26.34711145869683), + Offset(39.30700496104292, 27.399384375173792), + Offset(36.28104377724833, 28.970941368922745), + Offset(32.04675383085589, 30.403280561808284), + Offset(26.655308355431437, 30.38812108642142), + Offset(22.838515792338228, 27.24978625225603), + Offset(22.017669221052497, 23.734736578402938), + Offset(22.22502452096443, 23.078337345433567), + Offset(22.535475994562226, 22.637953951770903), + Offset(22.851392493882464, 22.362715419699295), + Offset(23.1332359929415, 22.197579362061152), + Offset(23.369521577941427, 22.101975511401783), + Offset(23.560274059886364, 22.048938469040202), + Offset(23.709614091422043, 22.02119328278395), + Offset(23.822645300996605, 22.00787919273418), + Offset(23.90426194110445, 22.002292758165275), + Offset(23.958738335514504, 22.000425676539155), + Offset(23.989660411288344, 22.000026726952264), + Offset(23.999978366434483, 22.000000000117), + Offset(23.999999999999996, 22.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 26.0), + Offset(41.25166967016726, 26.34711145869683), + Offset(39.30700496104292, 27.399384375173792), + Offset(36.28104377724833, 28.970941368922745), + Offset(32.04675383085589, 30.403280561808284), + Offset(26.655308355431437, 30.38812108642142), + Offset(22.838515792338228, 27.24978625225603), + Offset(22.017669221052497, 23.734736578402938), + Offset(22.22502452096443, 23.078337345433567), + Offset(22.535475994562226, 22.637953951770903), + Offset(22.851392493882464, 22.362715419699295), + Offset(23.1332359929415, 22.197579362061152), + Offset(23.369521577941427, 22.101975511401783), + Offset(23.560274059886364, 22.048938469040202), + Offset(23.709614091422043, 22.02119328278395), + Offset(23.822645300996605, 22.00787919273418), + Offset(23.90426194110445, 22.002292758165275), + Offset(23.958738335514504, 22.000425676539155), + Offset(23.989660411288344, 22.000026726952264), + Offset(23.999978366434483, 22.000000000117), + Offset(23.999999999999996, 22.000000000000004), + ], + <Offset>[ + Offset(42.0, 22.0), + Offset(41.332041627184935, 22.347918996645877), + Offset(39.669043614130416, 23.415802066036626), + Offset(37.20491746851932, 25.079096381956113), + Offset(33.88114957098939, 26.848707131904206), + Offset(29.747350168882384, 27.85054794976684), + Offset(26.688336738152817, 26.164024452795736), + Offset(25.982330778947503, 24.265263421597062), + Offset(25.77497547903557, 24.921662654566433), + Offset(25.464524005437774, 25.362046048229097), + Offset(25.148607506117536, 25.637284580300705), + Offset(24.8667640070585, 25.802420637938855), + Offset(24.630478422058573, 25.898024488598217), + Offset(24.43972594011363, 25.95106153095979), + Offset(24.290385908577957, 25.97880671721605), + Offset(24.177354699003402, 25.992120807265813), + Offset(24.09573805889554, 25.997707241834732), + Offset(24.041261664485504, 25.999574323460838), + Offset(24.010339588711656, 25.999973273047736), + Offset(24.000021633565517, 25.999999999883), + Offset(23.999999999999996, 26.000000000000004), + ], + <Offset>[ + Offset(42.0, 22.0), + Offset(41.332041627184935, 22.347918996645877), + Offset(39.669043614130416, 23.415802066036626), + Offset(37.20491746851932, 25.079096381956113), + Offset(33.88114957098939, 26.848707131904206), + Offset(29.747350168882384, 27.85054794976684), + Offset(26.688336738152817, 26.164024452795736), + Offset(25.982330778947503, 24.265263421597062), + Offset(25.77497547903557, 24.921662654566433), + Offset(25.464524005437774, 25.362046048229097), + Offset(25.148607506117536, 25.637284580300705), + Offset(24.8667640070585, 25.802420637938855), + Offset(24.630478422058573, 25.898024488598217), + Offset(24.43972594011363, 25.95106153095979), + Offset(24.290385908577957, 25.97880671721605), + Offset(24.177354699003402, 25.992120807265813), + Offset(24.09573805889554, 25.997707241834732), + Offset(24.041261664485504, 25.999574323460838), + Offset(24.010339588711656, 25.999973273047736), + Offset(24.000021633565517, 25.999999999883), + Offset(23.999999999999996, 26.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 22.0), + Offset(41.332041627184935, 22.347918996645877), + Offset(39.669043614130416, 23.415802066036626), + Offset(37.20491746851932, 25.079096381956113), + Offset(33.88114957098939, 26.848707131904206), + Offset(29.747350168882384, 27.85054794976684), + Offset(26.688336738152817, 26.164024452795736), + Offset(25.982330778947503, 24.265263421597062), + Offset(25.77497547903557, 24.921662654566433), + Offset(25.464524005437774, 25.362046048229097), + Offset(25.148607506117536, 25.637284580300705), + Offset(24.8667640070585, 25.802420637938855), + Offset(24.630478422058573, 25.898024488598217), + Offset(24.43972594011363, 25.95106153095979), + Offset(24.290385908577957, 25.97880671721605), + Offset(24.177354699003402, 25.992120807265813), + Offset(24.09573805889554, 25.997707241834732), + Offset(24.041261664485504, 25.999574323460838), + Offset(24.010339588711656, 25.999973273047736), + Offset(24.000021633565517, 25.999999999883), + Offset(23.999999999999996, 26.000000000000004), + ], + <Offset>[ + Offset(6.0, 22.0), + Offset(6.74833032983274, 21.65288854130317), + Offset(8.692995039056669, 20.60061562483526), + Offset(11.718956222751673, 19.029058631077255), + Offset(15.953246169055248, 17.596719438145858), + Offset(21.344691644593937, 17.6118789136095), + Offset(25.161484207661772, 20.75021374774397), + Offset(25.982330778947503, 24.265263421597062), + Offset(25.77497547903557, 24.921662654566433), + Offset(25.464524005437774, 25.362046048229097), + Offset(25.148607506117536, 25.637284580300705), + Offset(24.8667640070585, 25.802420637938855), + Offset(24.630478422058573, 25.898024488598217), + Offset(24.43972594011363, 25.95106153095979), + Offset(24.290385908577957, 25.97880671721605), + Offset(24.177354699003402, 25.992120807265813), + Offset(24.09573805889554, 25.997707241834732), + Offset(24.041261664485504, 25.999574323460838), + Offset(24.010339588711656, 25.999973273047736), + Offset(24.000021633565517, 25.999999999883), + Offset(23.999999999999996, 26.000000000000004), + ], + <Offset>[ + Offset(6.0, 22.0), + Offset(6.74833032983274, 21.65288854130317), + Offset(8.692995039056669, 20.60061562483526), + Offset(11.718956222751673, 19.029058631077255), + Offset(15.953246169055248, 17.596719438145858), + Offset(21.344691644593937, 17.6118789136095), + Offset(25.161484207661772, 20.75021374774397), + Offset(25.982330778947503, 24.265263421597062), + Offset(25.77497547903557, 24.921662654566433), + Offset(25.464524005437774, 25.362046048229097), + Offset(25.148607506117536, 25.637284580300705), + Offset(24.8667640070585, 25.802420637938855), + Offset(24.630478422058573, 25.898024488598217), + Offset(24.43972594011363, 25.95106153095979), + Offset(24.290385908577957, 25.97880671721605), + Offset(24.177354699003402, 25.992120807265813), + Offset(24.09573805889554, 25.997707241834732), + Offset(24.041261664485504, 25.999574323460838), + Offset(24.010339588711656, 25.999973273047736), + Offset(24.000021633565517, 25.999999999883), + Offset(23.999999999999996, 26.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 22.0), + Offset(6.74833032983274, 21.65288854130317), + Offset(8.692995039056669, 20.60061562483526), + Offset(11.718956222751673, 19.029058631077255), + Offset(15.953246169055248, 17.596719438145858), + Offset(21.344691644593937, 17.6118789136095), + Offset(25.161484207661772, 20.75021374774397), + Offset(25.982330778947503, 24.265263421597062), + Offset(25.77497547903557, 24.921662654566433), + Offset(25.464524005437774, 25.362046048229097), + Offset(25.148607506117536, 25.637284580300705), + Offset(24.8667640070585, 25.802420637938855), + Offset(24.630478422058573, 25.898024488598217), + Offset(24.43972594011363, 25.95106153095979), + Offset(24.290385908577957, 25.97880671721605), + Offset(24.177354699003402, 25.992120807265813), + Offset(24.09573805889554, 25.997707241834732), + Offset(24.041261664485504, 25.999574323460838), + Offset(24.010339588711656, 25.999973273047736), + Offset(24.000021633565517, 25.999999999883), + Offset(23.999999999999996, 26.000000000000004), + ], + <Offset>[ + Offset(6.0, 26.0), + Offset(6.667958372815065, 25.652081003354123), + Offset(8.330956385969174, 24.584197933972426), + Offset(10.795082531480682, 22.920903618043887), + Offset(14.118850428921743, 21.151292868049936), + Offset(18.25264983114299, 20.14945205026408), + Offset(21.311663261847183, 21.835975547204264), + Offset(22.017669221052497, 23.734736578402938), + Offset(22.22502452096443, 23.078337345433567), + Offset(22.535475994562226, 22.637953951770903), + Offset(22.851392493882464, 22.362715419699295), + Offset(23.1332359929415, 22.197579362061152), + Offset(23.369521577941427, 22.101975511401783), + Offset(23.560274059886364, 22.048938469040202), + Offset(23.709614091422043, 22.02119328278395), + Offset(23.822645300996605, 22.00787919273418), + Offset(23.90426194110445, 22.002292758165275), + Offset(23.958738335514504, 22.000425676539155), + Offset(23.989660411288344, 22.000026726952264), + Offset(23.999978366434483, 22.000000000117), + Offset(23.999999999999996, 22.000000000000004), + ], + <Offset>[ + Offset(6.0, 26.0), + Offset(6.667958372815065, 25.652081003354123), + Offset(8.330956385969174, 24.584197933972426), + Offset(10.795082531480682, 22.920903618043887), + Offset(14.118850428921743, 21.151292868049936), + Offset(18.25264983114299, 20.14945205026408), + Offset(21.311663261847183, 21.835975547204264), + Offset(22.017669221052497, 23.734736578402938), + Offset(22.22502452096443, 23.078337345433567), + Offset(22.535475994562226, 22.637953951770903), + Offset(22.851392493882464, 22.362715419699295), + Offset(23.1332359929415, 22.197579362061152), + Offset(23.369521577941427, 22.101975511401783), + Offset(23.560274059886364, 22.048938469040202), + Offset(23.709614091422043, 22.02119328278395), + Offset(23.822645300996605, 22.00787919273418), + Offset(23.90426194110445, 22.002292758165275), + Offset(23.958738335514504, 22.000425676539155), + Offset(23.989660411288344, 22.000026726952264), + Offset(23.999978366434483, 22.000000000117), + Offset(23.999999999999996, 22.000000000000004), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(6.0, 36.0), + Offset(5.755802622931704, 35.48132577125743), + Offset(5.010307637171476, 33.62392385238556), + Offset(4.045724406149144, 29.753229622188503), + Offset(4.0861862642629525, 23.09758660034176), + Offset(8.564534830281378, 13.380886967716135), + Offset(17.231202711318005, 7.518259082609372), + Offset(27.314036258810987, 7.072010923819601), + Offset(34.88234825995056, 10.868941008448914), + Offset(39.083273856489825, 15.969526394266794), + Offset(40.919225828875916, 20.778998598927743), + Offset(41.3739602310385, 24.78219833097991), + Offset(41.11406980357167, 27.929167557007872), + Offset(40.542525130544135, 30.325075504900447), + Offset(39.89012097509991, 32.10612260851932), + Offset(39.28321027503917, 33.39611499843784), + Offset(38.78633478113526, 34.295159061960966), + Offset(38.427830072911185, 34.87959495005215), + Offset(38.21486700558917, 35.20562675712161), + Offset(38.14228859445484, 35.31348285156429), + Offset(38.14213562373095, 35.31370849898477), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 36.0), + Offset(5.755802622931704, 35.48132577125743), + Offset(5.010307637171476, 33.62392385238556), + Offset(4.045724406149144, 29.753229622188503), + Offset(4.0861862642629525, 23.09758660034176), + Offset(8.564534830281378, 13.380886967716135), + Offset(17.231202711318005, 7.518259082609372), + Offset(27.314036258810987, 7.072010923819601), + Offset(34.88234825995056, 10.868941008448914), + Offset(39.083273856489825, 15.969526394266794), + Offset(40.919225828875916, 20.778998598927743), + Offset(41.3739602310385, 24.78219833097991), + Offset(41.11406980357167, 27.929167557007872), + Offset(40.542525130544135, 30.325075504900447), + Offset(39.89012097509991, 32.10612260851932), + Offset(39.28321027503917, 33.39611499843784), + Offset(38.78633478113526, 34.295159061960966), + Offset(38.427830072911185, 34.87959495005215), + Offset(38.21486700558917, 35.20562675712161), + Offset(38.14228859445484, 35.31348285156429), + Offset(38.14213562373095, 35.31370849898477), + ], + <Offset>[ + Offset(42.0, 36.0), + Offset(41.74444683546158, 36.38547605961641), + Offset(40.779522756565214, 37.69372111300368), + Offset(38.528666977308376, 40.09376498715554), + Offset(33.888986943996294, 43.29147358735062), + Offset(24.750542697847216, 45.53696181075469), + Offset(15.464766435530956, 43.474895505995576), + Offset(8.222494539070887, 37.592709388360404), + Offset(4.758504180127748, 30.580714593150105), + Offset(4.129263053465191, 24.58446277139909), + Offset(4.926943149181838, 20.033621174401183), + Offset(6.282139476517855, 16.74701842430737), + Offset(7.742736159475957, 14.425312891970705), + Offset(9.093991024465053, 12.803953891864928), + Offset(10.244527895379168, 11.682146233885181), + Offset(11.164395063408941, 10.916519114743828), + Offset(11.853227009710306, 10.407762682849047), + Offset(12.32400850869499, 10.088659111654252), + Offset(12.595052974338124, 9.914815599625843), + Offset(12.68610028619067, 9.857982919050801), + Offset(12.68629150101523, 9.85786437626906), + ], + <Offset>[ + Offset(42.0, 36.0), + Offset(41.74444683546158, 36.38547605961641), + Offset(40.779522756565214, 37.69372111300368), + Offset(38.528666977308376, 40.09376498715554), + Offset(33.888986943996294, 43.29147358735062), + Offset(24.750542697847216, 45.53696181075469), + Offset(15.464766435530956, 43.474895505995576), + Offset(8.222494539070887, 37.592709388360404), + Offset(4.758504180127748, 30.580714593150105), + Offset(4.129263053465191, 24.58446277139909), + Offset(4.926943149181838, 20.033621174401183), + Offset(6.282139476517855, 16.74701842430737), + Offset(7.742736159475957, 14.425312891970705), + Offset(9.093991024465053, 12.803953891864928), + Offset(10.244527895379168, 11.682146233885181), + Offset(11.164395063408941, 10.916519114743828), + Offset(11.853227009710306, 10.407762682849047), + Offset(12.32400850869499, 10.088659111654252), + Offset(12.595052974338124, 9.914815599625843), + Offset(12.68610028619067, 9.857982919050801), + Offset(12.68629150101523, 9.85786437626906), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 36.0), + Offset(41.74444683546158, 36.38547605961641), + Offset(40.779522756565214, 37.69372111300368), + Offset(38.528666977308376, 40.09376498715554), + Offset(33.888986943996294, 43.29147358735062), + Offset(24.750542697847216, 45.53696181075469), + Offset(15.464766435530956, 43.474895505995576), + Offset(8.222494539070887, 37.592709388360404), + Offset(4.758504180127748, 30.580714593150105), + Offset(4.129263053465191, 24.58446277139909), + Offset(4.926943149181838, 20.033621174401183), + Offset(6.282139476517855, 16.74701842430737), + Offset(7.742736159475957, 14.425312891970705), + Offset(9.093991024465053, 12.803953891864928), + Offset(10.244527895379168, 11.682146233885181), + Offset(11.164395063408941, 10.916519114743828), + Offset(11.853227009710306, 10.407762682849047), + Offset(12.32400850869499, 10.088659111654252), + Offset(12.595052974338124, 9.914815599625843), + Offset(12.68610028619067, 9.857982919050801), + Offset(12.68629150101523, 9.85786437626906), + ], + <Offset>[ + Offset(42.0, 32.0), + Offset(41.84490797861258, 32.38673781377975), + Offset(41.231722452189445, 33.71936387751549), + Offset(39.67761535119361, 36.262326923693394), + Offset(36.132752164775056, 39.98005128960247), + Offset(28.323439902629275, 43.73851649213626), + Offset(19.459948260351645, 43.67116620330525), + Offset(11.613683257353195, 39.71399180166486), + Offset(6.948701245094547, 33.927808379797085), + Offset(5.086478206479892, 28.468241749512934), + Offset(4.844123435345551, 24.032763694367194), + Offset(5.389341709109795, 20.646109619254112), + Offset(6.242307863360715, 18.133238852425784), + Offset(7.147199734127774, 16.29823545920705), + Offset(7.975197187086486, 14.976101020520819), + Offset(8.66666218744294, 14.040831916036076), + Offset(9.199071856475648, 13.400330213007376), + Offset(9.569460082206334, 12.989083729900493), + Offset(9.784962845727483, 12.76146160309818), + Offset(9.857711404800284, 12.68644828663571), + Offset(9.857864376269042, 12.686291501015248), + ], + <Offset>[ + Offset(42.0, 32.0), + Offset(41.84490797861258, 32.38673781377975), + Offset(41.231722452189445, 33.71936387751549), + Offset(39.67761535119361, 36.262326923693394), + Offset(36.132752164775056, 39.98005128960247), + Offset(28.323439902629275, 43.73851649213626), + Offset(19.459948260351645, 43.67116620330525), + Offset(11.613683257353195, 39.71399180166486), + Offset(6.948701245094547, 33.927808379797085), + Offset(5.086478206479892, 28.468241749512934), + Offset(4.844123435345551, 24.032763694367194), + Offset(5.389341709109795, 20.646109619254112), + Offset(6.242307863360715, 18.133238852425784), + Offset(7.147199734127774, 16.29823545920705), + Offset(7.975197187086486, 14.976101020520819), + Offset(8.66666218744294, 14.040831916036076), + Offset(9.199071856475648, 13.400330213007376), + Offset(9.569460082206334, 12.989083729900493), + Offset(9.784962845727483, 12.76146160309818), + Offset(9.857711404800284, 12.68644828663571), + Offset(9.857864376269042, 12.686291501015248), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 32.0), + Offset(41.84490797861258, 32.38673781377975), + Offset(41.231722452189445, 33.71936387751549), + Offset(39.67761535119361, 36.262326923693394), + Offset(36.132752164775056, 39.98005128960247), + Offset(28.323439902629275, 43.73851649213626), + Offset(19.459948260351645, 43.67116620330525), + Offset(11.613683257353195, 39.71399180166486), + Offset(6.948701245094547, 33.927808379797085), + Offset(5.086478206479892, 28.468241749512934), + Offset(4.844123435345551, 24.032763694367194), + Offset(5.389341709109795, 20.646109619254112), + Offset(6.242307863360715, 18.133238852425784), + Offset(7.147199734127774, 16.29823545920705), + Offset(7.975197187086486, 14.976101020520819), + Offset(8.66666218744294, 14.040831916036076), + Offset(9.199071856475648, 13.400330213007376), + Offset(9.569460082206334, 12.989083729900493), + Offset(9.784962845727483, 12.76146160309818), + Offset(9.857711404800284, 12.68644828663571), + Offset(9.857864376269042, 12.686291501015248), + ], + <Offset>[ + Offset(6.0, 32.0), + Offset(5.8562637660827015, 31.482587525420783), + Offset(5.462507332795713, 29.649566616897364), + Offset(5.19467278003437, 25.921791558726365), + Offset(6.329951485041715, 19.786164302593612), + Offset(12.137432035063437, 11.58244164909771), + Offset(21.226384536138692, 7.714529779919044), + Offset(30.7052249770933, 9.193293337124057), + Offset(37.072545324917364, 14.216034795095894), + Offset(40.040489009504526, 19.85330537238064), + Offset(40.83640611503963, 24.77814111889375), + Offset(40.48116246363044, 28.68128952592665), + Offset(39.61364150745642, 31.63709351746295), + Offset(38.59573384020686, 33.81935707224257), + Offset(37.620790266807234, 35.40007739515496), + Offset(36.78547739907316, 36.520427799730086), + Offset(36.1321796279006, 37.28772659211929), + Offset(35.67328164642253, 37.78001956829839), + Offset(35.40477687697853, 38.05227276059395), + Offset(35.31389971306446, 38.1419482191492), + Offset(35.31370849898476, 38.14213562373095), + ], + <Offset>[ + Offset(6.0, 32.0), + Offset(5.8562637660827015, 31.482587525420783), + Offset(5.462507332795713, 29.649566616897364), + Offset(5.19467278003437, 25.921791558726365), + Offset(6.329951485041715, 19.786164302593612), + Offset(12.137432035063437, 11.58244164909771), + Offset(21.226384536138692, 7.714529779919044), + Offset(30.7052249770933, 9.193293337124057), + Offset(37.072545324917364, 14.216034795095894), + Offset(40.040489009504526, 19.85330537238064), + Offset(40.83640611503963, 24.77814111889375), + Offset(40.48116246363044, 28.68128952592665), + Offset(39.61364150745642, 31.63709351746295), + Offset(38.59573384020686, 33.81935707224257), + Offset(37.620790266807234, 35.40007739515496), + Offset(36.78547739907316, 36.520427799730086), + Offset(36.1321796279006, 37.28772659211929), + Offset(35.67328164642253, 37.78001956829839), + Offset(35.40477687697853, 38.05227276059395), + Offset(35.31389971306446, 38.1419482191492), + Offset(35.31370849898476, 38.14213562373095), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 32.0), + Offset(5.8562637660827015, 31.482587525420783), + Offset(5.462507332795713, 29.649566616897364), + Offset(5.19467278003437, 25.921791558726365), + Offset(6.329951485041715, 19.786164302593612), + Offset(12.137432035063437, 11.58244164909771), + Offset(21.226384536138692, 7.714529779919044), + Offset(30.7052249770933, 9.193293337124057), + Offset(37.072545324917364, 14.216034795095894), + Offset(40.040489009504526, 19.85330537238064), + Offset(40.83640611503963, 24.77814111889375), + Offset(40.48116246363044, 28.68128952592665), + Offset(39.61364150745642, 31.63709351746295), + Offset(38.59573384020686, 33.81935707224257), + Offset(37.620790266807234, 35.40007739515496), + Offset(36.78547739907316, 36.520427799730086), + Offset(36.1321796279006, 37.28772659211929), + Offset(35.67328164642253, 37.78001956829839), + Offset(35.40477687697853, 38.05227276059395), + Offset(35.31389971306446, 38.1419482191492), + Offset(35.31370849898476, 38.14213562373095), + ], + <Offset>[ + Offset(6.0, 36.0), + Offset(5.755802622931704, 35.48132577125743), + Offset(5.010307637171476, 33.62392385238556), + Offset(4.045724406149144, 29.753229622188503), + Offset(4.0861862642629525, 23.09758660034176), + Offset(8.564534830281378, 13.380886967716135), + Offset(17.231202711318005, 7.518259082609372), + Offset(27.314036258810987, 7.072010923819601), + Offset(34.88234825995056, 10.868941008448914), + Offset(39.083273856489825, 15.969526394266794), + Offset(40.919225828875916, 20.778998598927743), + Offset(41.3739602310385, 24.78219833097991), + Offset(41.11406980357167, 27.929167557007872), + Offset(40.542525130544135, 30.325075504900447), + Offset(39.89012097509991, 32.10612260851932), + Offset(39.28321027503917, 33.39611499843784), + Offset(38.78633478113526, 34.295159061960966), + Offset(38.427830072911185, 34.87959495005215), + Offset(38.21486700558917, 35.20562675712161), + Offset(38.14228859445484, 35.31348285156429), + Offset(38.14213562373095, 35.31370849898477), + ], + <Offset>[ + Offset(6.0, 36.0), + Offset(5.755802622931704, 35.48132577125743), + Offset(5.010307637171476, 33.62392385238556), + Offset(4.045724406149144, 29.753229622188503), + Offset(4.0861862642629525, 23.09758660034176), + Offset(8.564534830281378, 13.380886967716135), + Offset(17.231202711318005, 7.518259082609372), + Offset(27.314036258810987, 7.072010923819601), + Offset(34.88234825995056, 10.868941008448914), + Offset(39.083273856489825, 15.969526394266794), + Offset(40.919225828875916, 20.778998598927743), + Offset(41.3739602310385, 24.78219833097991), + Offset(41.11406980357167, 27.929167557007872), + Offset(40.542525130544135, 30.325075504900447), + Offset(39.89012097509991, 32.10612260851932), + Offset(39.28321027503917, 33.39611499843784), + Offset(38.78633478113526, 34.295159061960966), + Offset(38.427830072911185, 34.87959495005215), + Offset(38.21486700558917, 35.20562675712161), + Offset(38.14228859445484, 35.31348285156429), + Offset(38.14213562373095, 35.31370849898477), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(6.0, 16.0), + Offset(6.1715484384586965, 15.794477742439435), + Offset(6.7847088111550455, 15.101124417731686), + Offset(8.064809036741185, 13.831258504138926), + Offset(10.327896232258308, 12.039205529321242), + Offset(14.135313755104503, 9.942822494875724), + Offset(17.85576112924513, 8.665143896025008), + Offset(21.423658706813853, 7.951290714362276), + Offset(24.4827045503675, 7.678712896347676), + Offset(26.97423123596107, 7.701340160804744), + Offset(28.998592463240865, 7.903908926143316), + Offset(30.63345298306288, 8.203149386677556), + Offset(31.940891049382852, 8.538653103313674), + Offset(32.972454180204764, 8.86889674774221), + Offset(33.77116819246568, 9.167199716087978), + Offset(34.37258718307626, 9.41785407630459), + Offset(34.80589641289028, 9.612989774645834), + Offset(35.09487909270652, 9.750154330042164), + Offset(35.25887447203158, 9.830559256807962), + Offset(35.31359376965362, 9.857807024169409), + Offset(35.313708498984745, 9.85786437626905), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 16.0), + Offset(6.1715484384586965, 15.794477742439435), + Offset(6.7847088111550455, 15.101124417731686), + Offset(8.064809036741185, 13.831258504138926), + Offset(10.327896232258308, 12.039205529321242), + Offset(14.135313755104503, 9.942822494875724), + Offset(17.85576112924513, 8.665143896025008), + Offset(21.423658706813853, 7.951290714362276), + Offset(24.4827045503675, 7.678712896347676), + Offset(26.97423123596107, 7.701340160804744), + Offset(28.998592463240865, 7.903908926143316), + Offset(30.63345298306288, 8.203149386677556), + Offset(31.940891049382852, 8.538653103313674), + Offset(32.972454180204764, 8.86889674774221), + Offset(33.77116819246568, 9.167199716087978), + Offset(34.37258718307626, 9.41785407630459), + Offset(34.80589641289028, 9.612989774645834), + Offset(35.09487909270652, 9.750154330042164), + Offset(35.25887447203158, 9.830559256807962), + Offset(35.31359376965362, 9.857807024169409), + Offset(35.313708498984745, 9.85786437626905), + ], + <Offset>[ + Offset(42.0, 16.0), + Offset(42.16746021740808, 16.33700442573998), + Offset(42.70156935314198, 17.546350134810247), + Offset(43.51618803296806, 20.092227060671057), + Offset(44.054130843957765, 24.630515982034453), + Offset(42.51578514966233, 32.09115975577829), + Offset(38.14918656898573, 38.40025586692044), + Offset(31.819015610164328, 42.4177462160811), + Offset(25.688490276712407, 43.658513907222414), + Offset(20.913117319647185, 43.18743459360287), + Offset(17.449482120110062, 42.00109429799166), + Offset(15.000094691649505, 40.63150285293139), + Offset(13.281945592346325, 39.325724325359715), + Offset(12.08031575221366, 38.18644357392904), + Offset(11.243480256299911, 37.247500217520134), + Offset(10.667161603617046, 36.51126283372602), + Offset(10.280531326105294, 35.9664803851875), + Offset(10.035976293649936, 35.59684445677665), + Offset(9.901923001772541, 35.38491333072124), + Offset(9.857956160571883, 35.31385765884373), + Offset(9.857864376269035, 35.31370849898477), + ], + <Offset>[ + Offset(42.0, 16.0), + Offset(42.16746021740808, 16.33700442573998), + Offset(42.70156935314198, 17.546350134810247), + Offset(43.51618803296806, 20.092227060671057), + Offset(44.054130843957765, 24.630515982034453), + Offset(42.51578514966233, 32.09115975577829), + Offset(38.14918656898573, 38.40025586692044), + Offset(31.819015610164328, 42.4177462160811), + Offset(25.688490276712407, 43.658513907222414), + Offset(20.913117319647185, 43.18743459360287), + Offset(17.449482120110062, 42.00109429799166), + Offset(15.000094691649505, 40.63150285293139), + Offset(13.281945592346325, 39.325724325359715), + Offset(12.08031575221366, 38.18644357392904), + Offset(11.243480256299911, 37.247500217520134), + Offset(10.667161603617046, 36.51126283372602), + Offset(10.280531326105294, 35.9664803851875), + Offset(10.035976293649936, 35.59684445677665), + Offset(9.901923001772541, 35.38491333072124), + Offset(9.857956160571883, 35.31385765884373), + Offset(9.857864376269035, 35.31370849898477), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 16.0), + Offset(42.16746021740808, 16.33700442573998), + Offset(42.70156935314198, 17.546350134810247), + Offset(43.51618803296806, 20.092227060671057), + Offset(44.054130843957765, 24.630515982034453), + Offset(42.51578514966233, 32.09115975577829), + Offset(38.14918656898573, 38.40025586692044), + Offset(31.819015610164328, 42.4177462160811), + Offset(25.688490276712407, 43.658513907222414), + Offset(20.913117319647185, 43.18743459360287), + Offset(17.449482120110062, 42.00109429799166), + Offset(15.000094691649505, 40.63150285293139), + Offset(13.281945592346325, 39.325724325359715), + Offset(12.08031575221366, 38.18644357392904), + Offset(11.243480256299911, 37.247500217520134), + Offset(10.667161603617046, 36.51126283372602), + Offset(10.280531326105294, 35.9664803851875), + Offset(10.035976293649936, 35.59684445677665), + Offset(9.901923001772541, 35.38491333072124), + Offset(9.857956160571883, 35.31385765884373), + Offset(9.857864376269035, 35.31370849898477), + ], + <Offset>[ + Offset(42.0, 12.0), + Offset(42.227740959997035, 12.33745867252338), + Offset(42.973261099484034, 13.555587852367255), + Offset(44.211851205916076, 16.153184949979185), + Offset(45.453165338703684, 20.883156580734514), + Offset(44.97671151198483, 28.937774045271865), + Offset(41.453087899085226, 36.14543081806037), + Offset(35.64862177702197, 41.26270656015326), + Offset(29.68624594458738, 43.52453771540631), + Offset(24.8560167010692, 43.86089169541553), + Offset(21.238058272537653, 43.28432878056175), + Offset(18.60324507678882, 42.368542663088434), + Offset(16.702731283684777, 41.398940487252666), + Offset(15.33782095512331, 40.50779228815028), + Offset(14.363513645347927, 39.750576654871885), + Offset(13.67754035444165, 39.145199009221486), + Offset(13.208696949498814, 38.691520950385836), + Offset(12.90783075217599, 38.38116699000516), + Offset(12.741295676651793, 38.202352382972244), + Offset(12.68640623109125, 38.14226183763059), + Offset(12.686291501015226, 38.14213562373095), + ], + <Offset>[ + Offset(42.0, 12.0), + Offset(42.227740959997035, 12.33745867252338), + Offset(42.973261099484034, 13.555587852367255), + Offset(44.211851205916076, 16.153184949979185), + Offset(45.453165338703684, 20.883156580734514), + Offset(44.97671151198483, 28.937774045271865), + Offset(41.453087899085226, 36.14543081806037), + Offset(35.64862177702197, 41.26270656015326), + Offset(29.68624594458738, 43.52453771540631), + Offset(24.8560167010692, 43.86089169541553), + Offset(21.238058272537653, 43.28432878056175), + Offset(18.60324507678882, 42.368542663088434), + Offset(16.702731283684777, 41.398940487252666), + Offset(15.33782095512331, 40.50779228815028), + Offset(14.363513645347927, 39.750576654871885), + Offset(13.67754035444165, 39.145199009221486), + Offset(13.208696949498814, 38.691520950385836), + Offset(12.90783075217599, 38.38116699000516), + Offset(12.741295676651793, 38.202352382972244), + Offset(12.68640623109125, 38.14226183763059), + Offset(12.686291501015226, 38.14213562373095), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 12.0), + Offset(42.227740959997035, 12.33745867252338), + Offset(42.973261099484034, 13.555587852367255), + Offset(44.211851205916076, 16.153184949979185), + Offset(45.453165338703684, 20.883156580734514), + Offset(44.97671151198483, 28.937774045271865), + Offset(41.453087899085226, 36.14543081806037), + Offset(35.64862177702197, 41.26270656015326), + Offset(29.68624594458738, 43.52453771540631), + Offset(24.8560167010692, 43.86089169541553), + Offset(21.238058272537653, 43.28432878056175), + Offset(18.60324507678882, 42.368542663088434), + Offset(16.702731283684777, 41.398940487252666), + Offset(15.33782095512331, 40.50779228815028), + Offset(14.363513645347927, 39.750576654871885), + Offset(13.67754035444165, 39.145199009221486), + Offset(13.208696949498814, 38.691520950385836), + Offset(12.90783075217599, 38.38116699000516), + Offset(12.741295676651793, 38.202352382972244), + Offset(12.68640623109125, 38.14226183763059), + Offset(12.686291501015226, 38.14213562373095), + ], + <Offset>[ + Offset(6.0, 12.0), + Offset(6.231829181047647, 11.794931989222837), + Offset(7.056400557497106, 11.110362135288694), + Offset(8.7604722096892, 9.89221639344705), + Offset(11.726930727004222, 8.291846128021302), + Offset(16.596240117427012, 6.7894367843693), + Offset(21.159662459344624, 6.4103188471649375), + Offset(25.253264873671498, 6.796251058434446), + Offset(28.48046021824247, 7.5447367045315765), + Offset(30.917130617383087, 8.374797262617399), + Offset(32.78716861566846, 9.187143408713407), + Offset(34.236603368202196, 9.940189196834599), + Offset(35.3616767407213, 10.611869265206622), + Offset(36.22995938311441, 11.190245461963444), + Offset(36.8912015815137, 11.67027615343973), + Offset(37.38296593390086, 12.051790251800059), + Offset(37.734062036283795, 12.338030339844167), + Offset(37.96673355123257, 12.534476863270674), + Offset(38.09824714691083, 12.647998309058966), + Offset(38.14204384017299, 12.686211202956269), + Offset(38.14213562373094, 12.68629150101524), + ], + <Offset>[ + Offset(6.0, 12.0), + Offset(6.231829181047647, 11.794931989222837), + Offset(7.056400557497106, 11.110362135288694), + Offset(8.7604722096892, 9.89221639344705), + Offset(11.726930727004222, 8.291846128021302), + Offset(16.596240117427012, 6.7894367843693), + Offset(21.159662459344624, 6.4103188471649375), + Offset(25.253264873671498, 6.796251058434446), + Offset(28.48046021824247, 7.5447367045315765), + Offset(30.917130617383087, 8.374797262617399), + Offset(32.78716861566846, 9.187143408713407), + Offset(34.236603368202196, 9.940189196834599), + Offset(35.3616767407213, 10.611869265206622), + Offset(36.22995938311441, 11.190245461963444), + Offset(36.8912015815137, 11.67027615343973), + Offset(37.38296593390086, 12.051790251800059), + Offset(37.734062036283795, 12.338030339844167), + Offset(37.96673355123257, 12.534476863270674), + Offset(38.09824714691083, 12.647998309058966), + Offset(38.14204384017299, 12.686211202956269), + Offset(38.14213562373094, 12.68629150101524), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 12.0), + Offset(6.231829181047647, 11.794931989222837), + Offset(7.056400557497106, 11.110362135288694), + Offset(8.7604722096892, 9.89221639344705), + Offset(11.726930727004222, 8.291846128021302), + Offset(16.596240117427012, 6.7894367843693), + Offset(21.159662459344624, 6.4103188471649375), + Offset(25.253264873671498, 6.796251058434446), + Offset(28.48046021824247, 7.5447367045315765), + Offset(30.917130617383087, 8.374797262617399), + Offset(32.78716861566846, 9.187143408713407), + Offset(34.236603368202196, 9.940189196834599), + Offset(35.3616767407213, 10.611869265206622), + Offset(36.22995938311441, 11.190245461963444), + Offset(36.8912015815137, 11.67027615343973), + Offset(37.38296593390086, 12.051790251800059), + Offset(37.734062036283795, 12.338030339844167), + Offset(37.96673355123257, 12.534476863270674), + Offset(38.09824714691083, 12.647998309058966), + Offset(38.14204384017299, 12.686211202956269), + Offset(38.14213562373094, 12.68629150101524), + ], + <Offset>[ + Offset(6.0, 16.0), + Offset(6.1715484384586965, 15.794477742439435), + Offset(6.7847088111550455, 15.101124417731686), + Offset(8.064809036741185, 13.831258504138926), + Offset(10.327896232258308, 12.039205529321242), + Offset(14.135313755104503, 9.942822494875724), + Offset(17.85576112924513, 8.665143896025008), + Offset(21.423658706813853, 7.951290714362276), + Offset(24.4827045503675, 7.678712896347676), + Offset(26.97423123596107, 7.701340160804744), + Offset(28.998592463240865, 7.903908926143316), + Offset(30.63345298306288, 8.203149386677556), + Offset(31.940891049382852, 8.538653103313674), + Offset(32.972454180204764, 8.86889674774221), + Offset(33.77116819246568, 9.167199716087978), + Offset(34.37258718307626, 9.41785407630459), + Offset(34.80589641289028, 9.612989774645834), + Offset(35.09487909270652, 9.750154330042164), + Offset(35.25887447203158, 9.830559256807962), + Offset(35.31359376965362, 9.857807024169409), + Offset(35.313708498984745, 9.85786437626905), + ], + <Offset>[ + Offset(6.0, 16.0), + Offset(6.1715484384586965, 15.794477742439435), + Offset(6.7847088111550455, 15.101124417731686), + Offset(8.064809036741185, 13.831258504138926), + Offset(10.327896232258308, 12.039205529321242), + Offset(14.135313755104503, 9.942822494875724), + Offset(17.85576112924513, 8.665143896025008), + Offset(21.423658706813853, 7.951290714362276), + Offset(24.4827045503675, 7.678712896347676), + Offset(26.97423123596107, 7.701340160804744), + Offset(28.998592463240865, 7.903908926143316), + Offset(30.63345298306288, 8.203149386677556), + Offset(31.940891049382852, 8.538653103313674), + Offset(32.972454180204764, 8.86889674774221), + Offset(33.77116819246568, 9.167199716087978), + Offset(34.37258718307626, 9.41785407630459), + Offset(34.80589641289028, 9.612989774645834), + Offset(35.09487909270652, 9.750154330042164), + Offset(35.25887447203158, 9.830559256807962), + Offset(35.31359376965362, 9.857807024169409), + Offset(35.313708498984745, 9.85786437626905), + ], + ), + _PathClose( + ), + ], + ), + ], +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/menu_home.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/menu_home.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..53c3ec78d06dcc77b3799de5710b67c52352a17f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/menu_home.g.dart @@ -0,0 +1,1702 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$menu_home = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.853658536585, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(6.0, 12.046875), + Offset(6.1618805351617105, 11.806612807600084), + Offset(6.781939829118144, 10.945667339250278), + Offset(8.288913455339518, 9.166289848732603), + Offset(11.935042610511557, 6.074766376544677), + Offset(23.256788788206386, 2.4054443351966768), + Offset(36.24002084790047, 6.193846936842682), + Offset(43.02277578355333, 13.752502805353782), + Offset(45.18366429152893, 19.742117374864932), + Offset(45.60696992064962, 24.126681150009468), + Offset(45.345679612709475, 27.35248551632729), + Offset(44.82758462670622, 29.752296574674826), + Offset(44.24395862249675, 31.553763072552943), + Offset(43.684466559586255, 32.91061016598502), + Offset(43.191063930200144, 33.928759363213324), + Offset(42.78156545517243, 34.68316415294171), + Offset(42.461367454866235, 35.22742664024267), + Offset(42.229341109216534, 35.60035861469174), + Offset(42.08077400509552, 35.830587840098524), + Offset(42.00921658628339, 35.93923428088923), + Offset(42.0, 35.953125), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 12.046875), + Offset(6.1618805351617105, 11.806612807600084), + Offset(6.781939829118144, 10.945667339250278), + Offset(8.288913455339518, 9.166289848732603), + Offset(11.935042610511557, 6.074766376544677), + Offset(23.256788788206386, 2.4054443351966768), + Offset(36.24002084790047, 6.193846936842682), + Offset(43.02277578355333, 13.752502805353782), + Offset(45.18366429152893, 19.742117374864932), + Offset(45.60696992064962, 24.126681150009468), + Offset(45.345679612709475, 27.35248551632729), + Offset(44.82758462670622, 29.752296574674826), + Offset(44.24395862249675, 31.553763072552943), + Offset(43.684466559586255, 32.91061016598502), + Offset(43.191063930200144, 33.928759363213324), + Offset(42.78156545517243, 34.68316415294171), + Offset(42.461367454866235, 35.22742664024267), + Offset(42.229341109216534, 35.60035861469174), + Offset(42.08077400509552, 35.830587840098524), + Offset(42.00921658628339, 35.93923428088923), + Offset(42.0, 35.953125), + ], + <Offset>[ + Offset(6.0, 16.0), + Offset(6.108878658535886, 15.759382477932412), + Offset(6.534966570751962, 14.8910699138017), + Offset(7.618227825115078, 13.06210530265691), + Offset(10.424159957469506, 9.727769370570497), + Offset(20.040805554226083, 4.704280802712924), + Offset(32.287403394427514, 6.130502385964199), + Offset(39.5356887387035, 11.890401517221083), + Offset(42.39074647053927, 16.944474204118634), + Offset(43.43945637458355, 20.820764893773518), + Offset(43.696252373988955, 23.759911640985017), + Offset(43.59634590360605, 25.995802401597533), + Offset(43.34634769806003, 27.703893997641842), + Offset(43.050276896752194, 29.008687468496074), + Offset(42.76198609923806, 29.998989715943665), + Offset(42.5089105957515, 30.739453134971555), + Offset(42.30406998921387, 31.277432365193103), + Offset(42.152364969347445, 31.64798313410847), + Offset(42.05392318847743, 31.87755403057046), + Offset(42.00616671483272, 31.986110457391014), + Offset(42.0, 31.999999999999996), + ], + <Offset>[ + Offset(6.0, 16.0), + Offset(6.108878658535886, 15.759382477932412), + Offset(6.534966570751962, 14.8910699138017), + Offset(7.618227825115078, 13.06210530265691), + Offset(10.424159957469506, 9.727769370570497), + Offset(20.040805554226083, 4.704280802712924), + Offset(32.287403394427514, 6.130502385964199), + Offset(39.5356887387035, 11.890401517221083), + Offset(42.39074647053927, 16.944474204118634), + Offset(43.43945637458355, 20.820764893773518), + Offset(43.696252373988955, 23.759911640985017), + Offset(43.59634590360605, 25.995802401597533), + Offset(43.34634769806003, 27.703893997641842), + Offset(43.050276896752194, 29.008687468496074), + Offset(42.76198609923806, 29.998989715943665), + Offset(42.5089105957515, 30.739453134971555), + Offset(42.30406998921387, 31.277432365193103), + Offset(42.152364969347445, 31.64798313410847), + Offset(42.05392318847743, 31.87755403057046), + Offset(42.00616671483272, 31.986110457391014), + Offset(42.0, 31.999999999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 16.0), + Offset(6.108878658535886, 15.759382477932412), + Offset(6.534966570751962, 14.8910699138017), + Offset(7.618227825115078, 13.06210530265691), + Offset(10.424159957469506, 9.727769370570497), + Offset(20.040805554226083, 4.704280802712924), + Offset(32.287403394427514, 6.130502385964199), + Offset(39.5356887387035, 11.890401517221083), + Offset(42.39074647053927, 16.944474204118634), + Offset(43.43945637458355, 20.820764893773518), + Offset(43.696252373988955, 23.759911640985017), + Offset(43.59634590360605, 25.995802401597533), + Offset(43.34634769806003, 27.703893997641842), + Offset(43.050276896752194, 29.008687468496074), + Offset(42.76198609923806, 29.998989715943665), + Offset(42.5089105957515, 30.739453134971555), + Offset(42.30406998921387, 31.277432365193103), + Offset(42.152364969347445, 31.64798313410847), + Offset(42.05392318847743, 31.87755403057046), + Offset(42.00616671483272, 31.986110457391014), + Offset(42.0, 31.999999999999996), + ], + <Offset>[ + Offset(42.0, 16.0), + Offset(42.10564277096942, 16.24205569431935), + Offset(42.46464060935464, 17.140186069041555), + Offset(43.096325871919824, 19.169851120985427), + Offset(43.691033073024805, 23.4869536891827), + Offset(40.975664135876016, 33.99133760544266), + Offset(31.710542346111218, 42.12588030217638), + Offset(22.578054873653144, 43.64632464502351), + Offset(16.913395223901084, 42.37879301660944), + Offset(13.333404776292529, 40.559702483244706), + Offset(10.979690283915431, 38.78078262126988), + Offset(9.387007663408092, 37.208347927379336), + Offset(8.286670430885419, 35.8781847877691), + Offset(7.516561896694743, 34.78407475375168), + Offset(6.974676742284352, 33.906481109369096), + Offset(6.594641088228872, 33.222444423927385), + Offset(6.332580622754584, 32.709896242122134), + Offset(6.159190632336145, 32.348983237896554), + Offset(6.054753634514366, 32.12207688230202), + Offset(6.00617742890433, 32.01388478079939), + Offset(6.0, 32.0), + ], + <Offset>[ + Offset(42.0, 16.0), + Offset(42.10564277096942, 16.24205569431935), + Offset(42.46464060935464, 17.140186069041555), + Offset(43.096325871919824, 19.169851120985427), + Offset(43.691033073024805, 23.4869536891827), + Offset(40.975664135876016, 33.99133760544266), + Offset(31.710542346111218, 42.12588030217638), + Offset(22.578054873653144, 43.64632464502351), + Offset(16.913395223901084, 42.37879301660944), + Offset(13.333404776292529, 40.559702483244706), + Offset(10.979690283915431, 38.78078262126988), + Offset(9.387007663408092, 37.208347927379336), + Offset(8.286670430885419, 35.8781847877691), + Offset(7.516561896694743, 34.78407475375168), + Offset(6.974676742284352, 33.906481109369096), + Offset(6.594641088228872, 33.222444423927385), + Offset(6.332580622754584, 32.709896242122134), + Offset(6.159190632336145, 32.348983237896554), + Offset(6.054753634514366, 32.12207688230202), + Offset(6.00617742890433, 32.01388478079939), + Offset(6.0, 32.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 16.0), + Offset(42.10564277096942, 16.24205569431935), + Offset(42.46464060935464, 17.140186069041555), + Offset(43.096325871919824, 19.169851120985427), + Offset(43.691033073024805, 23.4869536891827), + Offset(40.975664135876016, 33.99133760544266), + Offset(31.710542346111218, 42.12588030217638), + Offset(22.578054873653144, 43.64632464502351), + Offset(16.913395223901084, 42.37879301660944), + Offset(13.333404776292529, 40.559702483244706), + Offset(10.979690283915431, 38.78078262126988), + Offset(9.387007663408092, 37.208347927379336), + Offset(8.286670430885419, 35.8781847877691), + Offset(7.516561896694743, 34.78407475375168), + Offset(6.974676742284352, 33.906481109369096), + Offset(6.594641088228872, 33.222444423927385), + Offset(6.332580622754584, 32.709896242122134), + Offset(6.159190632336145, 32.348983237896554), + Offset(6.054753634514366, 32.12207688230202), + Offset(6.00617742890433, 32.01388478079939), + Offset(6.0, 32.0), + ], + <Offset>[ + Offset(42.0, 12.0546875), + Offset(42.15853990080349, 12.297097821754479), + Offset(42.711125778277406, 13.202580732779758), + Offset(43.765686036471884, 15.281734907088639), + Offset(45.19892979196993, 19.841170068662862), + Offset(44.185291671765455, 31.697044293000552), + Offset(35.65534830264055, 42.18909966619542), + Offset(26.058250442129758, 45.50474589108481), + Offset(19.700793444454007, 45.170907248283115), + Offset(15.496634698749768, 43.85908530814422), + Offset(12.625857785010018, 42.366256548241914), + Offset(10.615813108399369, 40.957418198928806), + Offset(9.18250742068886, 39.72044542577326), + Offset(8.14949822027419, 38.6782861415618), + Offset(7.402906593343346, 37.82848441346233), + Offset(6.866757104054109, 37.15836154660511), + Offset(6.489567223850322, 36.65208420437516), + Offset(6.236014645446598, 36.2935476997435), + Offset(6.081551386277482, 36.0672983720484), + Offset(6.009221272941055, 35.9591961066227), + Offset(6.0, 35.9453125), + ], + <Offset>[ + Offset(42.0, 12.0546875), + Offset(42.15853990080349, 12.297097821754479), + Offset(42.711125778277406, 13.202580732779758), + Offset(43.765686036471884, 15.281734907088639), + Offset(45.19892979196993, 19.841170068662862), + Offset(44.185291671765455, 31.697044293000552), + Offset(35.65534830264055, 42.18909966619542), + Offset(26.058250442129758, 45.50474589108481), + Offset(19.700793444454007, 45.170907248283115), + Offset(15.496634698749768, 43.85908530814422), + Offset(12.625857785010018, 42.366256548241914), + Offset(10.615813108399369, 40.957418198928806), + Offset(9.18250742068886, 39.72044542577326), + Offset(8.14949822027419, 38.6782861415618), + Offset(7.402906593343346, 37.82848441346233), + Offset(6.866757104054109, 37.15836154660511), + Offset(6.489567223850322, 36.65208420437516), + Offset(6.236014645446598, 36.2935476997435), + Offset(6.081551386277482, 36.0672983720484), + Offset(6.009221272941055, 35.9591961066227), + Offset(6.0, 35.9453125), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 12.0546875), + Offset(42.15853990080349, 12.297097821754479), + Offset(42.711125778277406, 13.202580732779758), + Offset(43.765686036471884, 15.281734907088639), + Offset(45.19892979196993, 19.841170068662862), + Offset(44.185291671765455, 31.697044293000552), + Offset(35.65534830264055, 42.18909966619542), + Offset(26.058250442129758, 45.50474589108481), + Offset(19.700793444454007, 45.170907248283115), + Offset(15.496634698749768, 43.85908530814422), + Offset(12.625857785010018, 42.366256548241914), + Offset(10.615813108399369, 40.957418198928806), + Offset(9.18250742068886, 39.72044542577326), + Offset(8.14949822027419, 38.6782861415618), + Offset(7.402906593343346, 37.82848441346233), + Offset(6.866757104054109, 37.15836154660511), + Offset(6.489567223850322, 36.65208420437516), + Offset(6.236014645446598, 36.2935476997435), + Offset(6.081551386277482, 36.0672983720484), + Offset(6.009221272941055, 35.9591961066227), + Offset(6.0, 35.9453125), + ], + <Offset>[ + Offset(6.0, 12.046875), + Offset(6.1618805351617105, 11.806612807600084), + Offset(6.781939829118144, 10.945667339250278), + Offset(8.288913455339518, 9.166289848732603), + Offset(11.935042610511557, 6.074766376544677), + Offset(23.256788788206386, 2.4054443351966768), + Offset(36.24002084790047, 6.193846936842682), + Offset(43.02277578355333, 13.752502805353782), + Offset(45.18366429152893, 19.742117374864932), + Offset(45.60696992064962, 24.126681150009468), + Offset(45.345679612709475, 27.35248551632729), + Offset(44.82758462670622, 29.752296574674826), + Offset(44.24395862249675, 31.553763072552943), + Offset(43.684466559586255, 32.91061016598502), + Offset(43.191063930200144, 33.928759363213324), + Offset(42.78156545517243, 34.68316415294171), + Offset(42.461367454866235, 35.22742664024267), + Offset(42.229341109216534, 35.60035861469174), + Offset(42.08077400509552, 35.830587840098524), + Offset(42.00921658628339, 35.93923428088923), + Offset(42.0, 35.953125), + ], + <Offset>[ + Offset(6.0, 12.046875), + Offset(6.1618805351617105, 11.806612807600084), + Offset(6.781939829118144, 10.945667339250278), + Offset(8.288913455339518, 9.166289848732603), + Offset(11.935042610511557, 6.074766376544677), + Offset(23.256788788206386, 2.4054443351966768), + Offset(36.24002084790047, 6.193846936842682), + Offset(43.02277578355333, 13.752502805353782), + Offset(45.18366429152893, 19.742117374864932), + Offset(45.60696992064962, 24.126681150009468), + Offset(45.345679612709475, 27.35248551632729), + Offset(44.82758462670622, 29.752296574674826), + Offset(44.24395862249675, 31.553763072552943), + Offset(43.684466559586255, 32.91061016598502), + Offset(43.191063930200144, 33.928759363213324), + Offset(42.78156545517243, 34.68316415294171), + Offset(42.461367454866235, 35.22742664024267), + Offset(42.229341109216534, 35.60035861469174), + Offset(42.08077400509552, 35.830587840098524), + Offset(42.00921658628339, 35.93923428088923), + Offset(42.0, 35.953125), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(6.0, 26.0), + Offset(5.97480276509507, 25.758483620275058), + Offset(5.9102120831853355, 24.871534924524667), + Offset(5.921631764468266, 22.91713253788045), + Offset(6.602164313410562, 18.968567458224747), + Offset(11.905511997912269, 10.519519297615686), + Offset(22.288325077287325, 5.992865842523692), + Offset(30.404134439557254, 7.761342935335598), + Offset(33.61929906828942, 11.570908914742331), + Offset(35.25300243452185, 14.230458757139374), + Offset(36.21471762947331, 16.191242561808075), + Offset(36.803975496328306, 17.698645771806415), + Offset(37.18416968837589, 18.87242179985836), + Offset(37.445620479790264, 19.788403617209426), + Offset(37.63807337154698, 20.499019999728493), + Offset(37.76636524119959, 21.043465830420356), + Offset(37.84688070253245, 21.447001555066198), + Offset(37.895912975403306, 21.728985066095305), + Offset(37.92359388763603, 21.905378434612928), + Offset(37.93595283405028, 21.98924768876775), + Offset(37.9375, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 26.0), + Offset(5.97480276509507, 25.758483620275058), + Offset(5.9102120831853355, 24.871534924524667), + Offset(5.921631764468266, 22.91713253788045), + Offset(6.602164313410562, 18.968567458224747), + Offset(11.905511997912269, 10.519519297615686), + Offset(22.288325077287325, 5.992865842523692), + Offset(30.404134439557254, 7.761342935335598), + Offset(33.61929906828942, 11.570908914742331), + Offset(35.25300243452185, 14.230458757139374), + Offset(36.21471762947331, 16.191242561808075), + Offset(36.803975496328306, 17.698645771806415), + Offset(37.18416968837589, 18.87242179985836), + Offset(37.445620479790264, 19.788403617209426), + Offset(37.63807337154698, 20.499019999728493), + Offset(37.76636524119959, 21.043465830420356), + Offset(37.84688070253245, 21.447001555066198), + Offset(37.895912975403306, 21.728985066095305), + Offset(37.92359388763603, 21.905378434612928), + Offset(37.93595283405028, 21.98924768876775), + Offset(37.9375, 22.0), + ], + <Offset>[ + Offset(42.0, 26.0), + Offset(41.9715668775286, 26.241156836662), + Offset(41.83988612178801, 27.12065107976452), + Offset(41.39972981127301, 29.024878356208966), + Offset(39.86903742896586, 32.72775177683695), + Offset(32.840370579562205, 39.80657610034542), + Offset(21.712188487576384, 41.94303848554115), + Offset(14.06742965730648, 38.354475524191464), + Offset(11.554665508171254, 33.598274280005), + Offset(10.55378227775913, 30.424424398606067), + Offset(10.116296706050587, 28.1735838726282), + Offset(9.950186111823127, 26.50031664598051), + Offset(9.907575779387743, 25.232058503788906), + Offset(9.912669821946713, 24.26340582721259), + Offset(9.927760918072412, 23.52461229394332), + Offset(9.95774683780533, 22.966059779854906), + Offset(9.993956644475434, 22.556166293104994), + Offset(10.026198124175803, 22.27177334090344), + Offset(10.04923690661602, 22.094713837168957), + Offset(10.060961130015452, 22.01075350168465), + Offset(10.0625, 22.0), + ], + <Offset>[ + Offset(42.0, 26.0), + Offset(41.9715668775286, 26.241156836662), + Offset(41.83988612178801, 27.12065107976452), + Offset(41.39972981127301, 29.024878356208966), + Offset(39.86903742896586, 32.72775177683695), + Offset(32.840370579562205, 39.80657610034542), + Offset(21.712188487576384, 41.94303848554115), + Offset(14.06742965730648, 38.354475524191464), + Offset(11.554665508171254, 33.598274280005), + Offset(10.55378227775913, 30.424424398606067), + Offset(10.116296706050587, 28.1735838726282), + Offset(9.950186111823127, 26.50031664598051), + Offset(9.907575779387743, 25.232058503788906), + Offset(9.912669821946713, 24.26340582721259), + Offset(9.927760918072412, 23.52461229394332), + Offset(9.95774683780533, 22.966059779854906), + Offset(9.993956644475434, 22.556166293104994), + Offset(10.026198124175803, 22.27177334090344), + Offset(10.04923690661602, 22.094713837168957), + Offset(10.060961130015452, 22.01075350168465), + Offset(10.0625, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 26.0), + Offset(41.9715668775286, 26.241156836662), + Offset(41.83988612178801, 27.12065107976452), + Offset(41.39972981127301, 29.024878356208966), + Offset(39.86903742896586, 32.72775177683695), + Offset(32.840370579562205, 39.80657610034542), + Offset(21.712188487576384, 41.94303848554115), + Offset(14.06742965730648, 38.354475524191464), + Offset(11.554665508171254, 33.598274280005), + Offset(10.55378227775913, 30.424424398606067), + Offset(10.116296706050587, 28.1735838726282), + Offset(9.950186111823127, 26.50031664598051), + Offset(9.907575779387743, 25.232058503788906), + Offset(9.912669821946713, 24.26340582721259), + Offset(9.927760918072412, 23.52461229394332), + Offset(9.95774683780533, 22.966059779854906), + Offset(9.993956644475434, 22.556166293104994), + Offset(10.026198124175803, 22.27177334090344), + Offset(10.04923690661602, 22.094713837168957), + Offset(10.060961130015452, 22.01075350168465), + Offset(10.0625, 22.0), + ], + <Offset>[ + Offset(42.0, 22.0), + Offset(42.02519723490493, 22.241516379724942), + Offset(42.089787916814664, 23.128465075475333), + Offset(42.078368235531734, 25.08286746211955), + Offset(41.39783568658944, 29.031432541775253), + Offset(36.09448800208773, 37.48048070238431), + Offset(25.716890915777384, 42.00721774895393), + Offset(17.730033699513, 40.31030272815691), + Offset(14.773810944920879, 36.822866202860226), + Offset(13.156032790251274, 34.39340640919596), + Offset(12.13588194777422, 32.57238911127051), + Offset(11.474202347993174, 31.15007140388232), + Offset(11.025213475416908, 30.025626279936134), + Offset(10.704423952068467, 29.134761499184584), + Offset(10.46368421682347, 28.432941181442178), + Offset(10.298295990283647, 27.89180160467138), + Offset(10.190423044262575, 27.48975598051868), + Offset(10.12234223563285, 27.208337182264366), + Offset(10.082773894961147, 27.032099939188196), + Offset(10.064770455621808, 26.94825203221997), + Offset(10.0625, 26.9375), + ], + <Offset>[ + Offset(42.0, 22.0), + Offset(42.02519723490493, 22.241516379724942), + Offset(42.089787916814664, 23.128465075475333), + Offset(42.078368235531734, 25.08286746211955), + Offset(41.39783568658944, 29.031432541775253), + Offset(36.09448800208773, 37.48048070238431), + Offset(25.716890915777384, 42.00721774895393), + Offset(17.730033699513, 40.31030272815691), + Offset(14.773810944920879, 36.822866202860226), + Offset(13.156032790251274, 34.39340640919596), + Offset(12.13588194777422, 32.57238911127051), + Offset(11.474202347993174, 31.15007140388232), + Offset(11.025213475416908, 30.025626279936134), + Offset(10.704423952068467, 29.134761499184584), + Offset(10.46368421682347, 28.432941181442178), + Offset(10.298295990283647, 27.89180160467138), + Offset(10.190423044262575, 27.48975598051868), + Offset(10.12234223563285, 27.208337182264366), + Offset(10.082773894961147, 27.032099939188196), + Offset(10.064770455621808, 26.94825203221997), + Offset(10.0625, 26.9375), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 22.0), + Offset(42.02519723490493, 22.241516379724942), + Offset(42.089787916814664, 23.128465075475333), + Offset(42.078368235531734, 25.08286746211955), + Offset(41.39783568658944, 29.031432541775253), + Offset(36.09448800208773, 37.48048070238431), + Offset(25.716890915777384, 42.00721774895393), + Offset(17.730033699513, 40.31030272815691), + Offset(14.773810944920879, 36.822866202860226), + Offset(13.156032790251274, 34.39340640919596), + Offset(12.13588194777422, 32.57238911127051), + Offset(11.474202347993174, 31.15007140388232), + Offset(11.025213475416908, 30.025626279936134), + Offset(10.704423952068467, 29.134761499184584), + Offset(10.46368421682347, 28.432941181442178), + Offset(10.298295990283647, 27.89180160467138), + Offset(10.190423044262575, 27.48975598051868), + Offset(10.12234223563285, 27.208337182264366), + Offset(10.082773894961147, 27.032099939188196), + Offset(10.064770455621808, 26.94825203221997), + Offset(10.0625, 26.9375), + ], + <Offset>[ + Offset(6.0, 22.0), + Offset(6.028433122471398, 21.758843163338), + Offset(6.1601138782119875, 20.87934892023548), + Offset(6.600270188726988, 18.975121643791034), + Offset(8.13096257103414, 15.272248223163048), + Offset(15.159629420437794, 8.193423899654581), + Offset(26.293027505488325, 6.057045105936464), + Offset(34.06673848176378, 9.717170139301047), + Offset(36.83844450503905, 14.79550083759756), + Offset(37.855252947013994, 18.199440767729264), + Offset(38.234302871196945, 20.590047800450385), + Offset(38.327991732498354, 22.348400529708222), + Offset(38.30180738440505, 23.665989576005586), + Offset(38.23737460991202, 24.659759289181423), + Offset(38.17399667029804, 25.40734888722735), + Offset(38.106914393677904, 25.96920765523683), + Offset(38.04334710231959, 26.380591242479884), + Offset(37.992057086860356, 26.66554890745623), + Offset(37.95713087598116, 26.842764536632167), + Offset(37.93976215965664, 26.92674621930307), + Offset(37.9375, 26.9375), + ], + <Offset>[ + Offset(6.0, 22.0), + Offset(6.028433122471398, 21.758843163338), + Offset(6.1601138782119875, 20.87934892023548), + Offset(6.600270188726988, 18.975121643791034), + Offset(8.13096257103414, 15.272248223163048), + Offset(15.159629420437794, 8.193423899654581), + Offset(26.293027505488325, 6.057045105936464), + Offset(34.06673848176378, 9.717170139301047), + Offset(36.83844450503905, 14.79550083759756), + Offset(37.855252947013994, 18.199440767729264), + Offset(38.234302871196945, 20.590047800450385), + Offset(38.327991732498354, 22.348400529708222), + Offset(38.30180738440505, 23.665989576005586), + Offset(38.23737460991202, 24.659759289181423), + Offset(38.17399667029804, 25.40734888722735), + Offset(38.106914393677904, 25.96920765523683), + Offset(38.04334710231959, 26.380591242479884), + Offset(37.992057086860356, 26.66554890745623), + Offset(37.95713087598116, 26.842764536632167), + Offset(37.93976215965664, 26.92674621930307), + Offset(37.9375, 26.9375), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 22.0), + Offset(6.028433122471398, 21.758843163338), + Offset(6.1601138782119875, 20.87934892023548), + Offset(6.600270188726988, 18.975121643791034), + Offset(8.13096257103414, 15.272248223163048), + Offset(15.159629420437794, 8.193423899654581), + Offset(26.293027505488325, 6.057045105936464), + Offset(34.06673848176378, 9.717170139301047), + Offset(36.83844450503905, 14.79550083759756), + Offset(37.855252947013994, 18.199440767729264), + Offset(38.234302871196945, 20.590047800450385), + Offset(38.327991732498354, 22.348400529708222), + Offset(38.30180738440505, 23.665989576005586), + Offset(38.23737460991202, 24.659759289181423), + Offset(38.17399667029804, 25.40734888722735), + Offset(38.106914393677904, 25.96920765523683), + Offset(38.04334710231959, 26.380591242479884), + Offset(37.992057086860356, 26.66554890745623), + Offset(37.95713087598116, 26.842764536632167), + Offset(37.93976215965664, 26.92674621930307), + Offset(37.9375, 26.9375), + ], + <Offset>[ + Offset(6.0, 26.0), + Offset(5.97480276509507, 25.758483620275058), + Offset(5.9102120831853355, 24.871534924524667), + Offset(5.921631764468266, 22.91713253788045), + Offset(6.602164313410562, 18.968567458224747), + Offset(11.905511997912269, 10.519519297615686), + Offset(22.288325077287325, 5.992865842523692), + Offset(30.404134439557254, 7.761342935335598), + Offset(33.61929906828942, 11.570908914742331), + Offset(35.25300243452185, 14.230458757139374), + Offset(36.21471762947331, 16.191242561808075), + Offset(36.803975496328306, 17.698645771806415), + Offset(37.18416968837589, 18.87242179985836), + Offset(37.445620479790264, 19.788403617209426), + Offset(37.63807337154698, 20.499019999728493), + Offset(37.76636524119959, 21.043465830420356), + Offset(37.84688070253245, 21.447001555066198), + Offset(37.895912975403306, 21.728985066095305), + Offset(37.92359388763603, 21.905378434612928), + Offset(37.93595283405028, 21.98924768876775), + Offset(37.9375, 22.0), + ], + <Offset>[ + Offset(6.0, 26.0), + Offset(5.97480276509507, 25.758483620275058), + Offset(5.9102120831853355, 24.871534924524667), + Offset(5.921631764468266, 22.91713253788045), + Offset(6.602164313410562, 18.968567458224747), + Offset(11.905511997912269, 10.519519297615686), + Offset(22.288325077287325, 5.992865842523692), + Offset(30.404134439557254, 7.761342935335598), + Offset(33.61929906828942, 11.570908914742331), + Offset(35.25300243452185, 14.230458757139374), + Offset(36.21471762947331, 16.191242561808075), + Offset(36.803975496328306, 17.698645771806415), + Offset(37.18416968837589, 18.87242179985836), + Offset(37.445620479790264, 19.788403617209426), + Offset(37.63807337154698, 20.499019999728493), + Offset(37.76636524119959, 21.043465830420356), + Offset(37.84688070253245, 21.447001555066198), + Offset(37.895912975403306, 21.728985066095305), + Offset(37.92359388763603, 21.905378434612928), + Offset(37.93595283405028, 21.98924768876775), + Offset(37.9375, 22.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(24.946426391602, 26.0), + Offset(24.919526142652916, 26.01250952487153), + Offset(24.81962665114753, 26.055221415675078), + Offset(24.593386574407845, 26.131575775813122), + Offset(24.112549450730533, 26.21086569759901), + Offset(23.26102990202604, 26.40544929256212), + Offset(21.93030078929294, 28.333115001580325), + Offset(20.21574669997896, 26.840753449152132), + Offset(19.702668556230993, 25.46403358899737), + Offset(19.57851450097965, 24.507387236351565), + Offset(19.59742184955703, 23.820597237404847), + Offset(19.672638738964572, 23.313659191847616), + Offset(19.76421128572404, 22.933948220939197), + Offset(19.85318172952868, 22.647748525973807), + Offset(19.930810929304265, 22.432414178767115), + Offset(19.99628397445662, 22.272029228601628), + Offset(20.048487526419784, 22.155772744171706), + Offset(20.086790256569586, 22.07583407578212), + Offset(20.111504785414724, 22.026366303959268), + Offset(20.12345813528363, 22.002990192537517), + Offset(20.125, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(24.946426391602, 26.0), + Offset(24.919526142652916, 26.01250952487153), + Offset(24.81962665114753, 26.055221415675078), + Offset(24.593386574407845, 26.131575775813122), + Offset(24.112549450730533, 26.21086569759901), + Offset(23.26102990202604, 26.40544929256212), + Offset(21.93030078929294, 28.333115001580325), + Offset(20.21574669997896, 26.840753449152132), + Offset(19.702668556230993, 25.46403358899737), + Offset(19.57851450097965, 24.507387236351565), + Offset(19.59742184955703, 23.820597237404847), + Offset(19.672638738964572, 23.313659191847616), + Offset(19.76421128572404, 22.933948220939197), + Offset(19.85318172952868, 22.647748525973807), + Offset(19.930810929304265, 22.432414178767115), + Offset(19.99628397445662, 22.272029228601628), + Offset(20.048487526419784, 22.155772744171706), + Offset(20.086790256569586, 22.07583407578212), + Offset(20.111504785414724, 22.026366303959268), + Offset(20.12345813528363, 22.002990192537517), + Offset(20.125, 22.0), + ], + <Offset>[ + Offset(42.000000000002004, 26.0), + Offset(41.971566877530606, 26.241156836662025), + Offset(41.83988612179001, 27.120651079764645), + Offset(41.39972981127498, 29.024878356209307), + Offset(39.86903742895662, 32.72775177683313), + Offset(32.84037057959128, 39.806576100386096), + Offset(21.712188487577507, 41.94303848547116), + Offset(14.067429657339456, 38.35447552412971), + Offset(11.554665508114638, 33.59827428006152), + Offset(10.553782277809306, 30.424424398573166), + Offset(10.11629670607785, 28.173583872615687), + Offset(9.950186111889643, 26.50031664595871), + Offset(9.907575779455914, 25.23205850377301), + Offset(9.912669821848008, 24.263405827228635), + Offset(9.927760918072412, 23.52461229394332), + Offset(9.95774683780533, 22.966059779854906), + Offset(9.993956644475434, 22.556166293104994), + Offset(10.026198124175803, 22.27177334090344), + Offset(10.04923690661602, 22.094713837168957), + Offset(10.060961130015452, 22.01075350168465), + Offset(10.0625, 22.0), + ], + <Offset>[ + Offset(42.000000000002004, 26.0), + Offset(41.971566877530606, 26.241156836662025), + Offset(41.83988612179001, 27.120651079764645), + Offset(41.39972981127498, 29.024878356209307), + Offset(39.86903742895662, 32.72775177683313), + Offset(32.84037057959128, 39.806576100386096), + Offset(21.712188487577507, 41.94303848547116), + Offset(14.067429657339456, 38.35447552412971), + Offset(11.554665508114638, 33.59827428006152), + Offset(10.553782277809306, 30.424424398573166), + Offset(10.11629670607785, 28.173583872615687), + Offset(9.950186111889643, 26.50031664595871), + Offset(9.907575779455914, 25.23205850377301), + Offset(9.912669821848008, 24.263405827228635), + Offset(9.927760918072412, 23.52461229394332), + Offset(9.95774683780533, 22.966059779854906), + Offset(9.993956644475434, 22.556166293104994), + Offset(10.026198124175803, 22.27177334090344), + Offset(10.04923690661602, 22.094713837168957), + Offset(10.060961130015452, 22.01075350168465), + Offset(10.0625, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.000000000002004, 26.0), + Offset(41.971566877530606, 26.241156836662025), + Offset(41.83988612179001, 27.120651079764645), + Offset(41.39972981127498, 29.024878356209307), + Offset(39.86903742895662, 32.72775177683313), + Offset(32.84037057959128, 39.806576100386096), + Offset(21.712188487577507, 41.94303848547116), + Offset(14.067429657339456, 38.35447552412971), + Offset(11.554665508114638, 33.59827428006152), + Offset(10.553782277809306, 30.424424398573166), + Offset(10.11629670607785, 28.173583872615687), + Offset(9.950186111889643, 26.50031664595871), + Offset(9.907575779455914, 25.23205850377301), + Offset(9.912669821848008, 24.263405827228635), + Offset(9.927760918072412, 23.52461229394332), + Offset(9.95774683780533, 22.966059779854906), + Offset(9.993956644475434, 22.556166293104994), + Offset(10.026198124175803, 22.27177334090344), + Offset(10.04923690661602, 22.094713837168957), + Offset(10.060961130015452, 22.01075350168465), + Offset(10.0625, 22.0), + ], + <Offset>[ + Offset(42.000000000002004, 22.0), + Offset(42.025197234906926, 22.241516379724967), + Offset(42.08978791681666, 23.128465075475457), + Offset(42.0783682355337, 25.08286746211989), + Offset(41.397835686580194, 29.03143254177143), + Offset(36.094488002116805, 37.48048070242499), + Offset(25.789219352940048, 42.00837688265331), + Offset(19.59049856191341, 41.30378926060276), + Offset(20.224936460436354, 42.28321450135585), + Offset(18.827987907130577, 43.04433671564179), + Offset(16.997529418949235, 43.161414977908365), + Offset(15.331601790632021, 42.918949572968955), + Offset(13.928660013420258, 42.478559653106245), + Offset(12.785040072364048, 41.93598444668365), + Offset(11.87472277556043, 41.35613622700879), + Offset(11.194931733517697, 40.86084337127677), + Offset(10.707701666486946, 40.479460473962305), + Offset(10.375481162000769, 40.20587235951845), + Offset(10.171073813641986, 40.03180005589708), + Offset(10.074800072408165, 39.948248163249666), + Offset(10.062500000000002, 39.9375), + ], + <Offset>[ + Offset(42.000000000002004, 22.0), + Offset(42.025197234906926, 22.241516379724967), + Offset(42.08978791681666, 23.128465075475457), + Offset(42.0783682355337, 25.08286746211989), + Offset(41.397835686580194, 29.03143254177143), + Offset(36.094488002116805, 37.48048070242499), + Offset(25.789219352940048, 42.00837688265331), + Offset(19.59049856191341, 41.30378926060276), + Offset(20.224936460436354, 42.28321450135585), + Offset(18.827987907130577, 43.04433671564179), + Offset(16.997529418949235, 43.161414977908365), + Offset(15.331601790632021, 42.918949572968955), + Offset(13.928660013420258, 42.478559653106245), + Offset(12.785040072364048, 41.93598444668365), + Offset(11.87472277556043, 41.35613622700879), + Offset(11.194931733517697, 40.86084337127677), + Offset(10.707701666486946, 40.479460473962305), + Offset(10.375481162000769, 40.20587235951845), + Offset(10.171073813641986, 40.03180005589708), + Offset(10.074800072408165, 39.948248163249666), + Offset(10.062500000000002, 39.9375), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.000000000002004, 22.0), + Offset(42.025197234906926, 22.241516379724967), + Offset(42.08978791681666, 23.128465075475457), + Offset(42.0783682355337, 25.08286746211989), + Offset(41.397835686580194, 29.03143254177143), + Offset(36.094488002116805, 37.48048070242499), + Offset(25.789219352940048, 42.00837688265331), + Offset(19.59049856191341, 41.30378926060276), + Offset(20.224936460436354, 42.28321450135585), + Offset(18.827987907130577, 43.04433671564179), + Offset(16.997529418949235, 43.161414977908365), + Offset(15.331601790632021, 42.918949572968955), + Offset(13.928660013420258, 42.478559653106245), + Offset(12.785040072364048, 41.93598444668365), + Offset(11.87472277556043, 41.35613622700879), + Offset(11.194931733517697, 40.86084337127677), + Offset(10.707701666486946, 40.479460473962305), + Offset(10.375481162000769, 40.20587235951845), + Offset(10.171073813641986, 40.03180005589708), + Offset(10.074800072408165, 39.948248163249666), + Offset(10.062500000000002, 39.9375), + ], + <Offset>[ + Offset(24.946426391602, 22.0), + Offset(24.97315650002924, 22.01286906793447), + Offset(25.06952844617418, 22.06303541138589), + Offset(25.272024998666566, 22.189564881723705), + Offset(25.64134770835411, 22.51454646253731), + Offset(26.515147324551563, 24.079353894601017), + Offset(26.00733165465548, 28.39845339876247), + Offset(25.738815604552915, 29.790067185625176), + Offset(28.372939508552708, 34.1489738102917), + Offset(27.852720130300924, 37.12729955342019), + Offset(26.47865456242841, 38.80842834269753), + Offset(25.05405441770695, 39.73229211885786), + Offset(23.785295519688383, 40.180449370272434), + Offset(22.72555198004472, 40.32032714542882), + Offset(21.87777278679228, 40.26393811183259), + Offset(21.233468870168988, 40.166812820023495), + Offset(20.762232548431296, 40.079066925029025), + Offset(20.436073294394554, 40.00993309439713), + Offset(20.23334169244069, 39.96345252268739), + Offset(20.137297077676344, 39.940484854102536), + Offset(20.125, 39.9375), + ], + <Offset>[ + Offset(24.946426391602, 22.0), + Offset(24.97315650002924, 22.01286906793447), + Offset(25.06952844617418, 22.06303541138589), + Offset(25.272024998666566, 22.189564881723705), + Offset(25.64134770835411, 22.51454646253731), + Offset(26.515147324551563, 24.079353894601017), + Offset(26.00733165465548, 28.39845339876247), + Offset(25.738815604552915, 29.790067185625176), + Offset(28.372939508552708, 34.1489738102917), + Offset(27.852720130300924, 37.12729955342019), + Offset(26.47865456242841, 38.80842834269753), + Offset(25.05405441770695, 39.73229211885786), + Offset(23.785295519688383, 40.180449370272434), + Offset(22.72555198004472, 40.32032714542882), + Offset(21.87777278679228, 40.26393811183259), + Offset(21.233468870168988, 40.166812820023495), + Offset(20.762232548431296, 40.079066925029025), + Offset(20.436073294394554, 40.00993309439713), + Offset(20.23334169244069, 39.96345252268739), + Offset(20.137297077676344, 39.940484854102536), + Offset(20.125, 39.9375), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(24.946426391602, 22.0), + Offset(24.97315650002924, 22.01286906793447), + Offset(25.06952844617418, 22.06303541138589), + Offset(25.272024998666566, 22.189564881723705), + Offset(25.64134770835411, 22.51454646253731), + Offset(26.515147324551563, 24.079353894601017), + Offset(26.00733165465548, 28.39845339876247), + Offset(25.738815604552915, 29.790067185625176), + Offset(28.372939508552708, 34.1489738102917), + Offset(27.852720130300924, 37.12729955342019), + Offset(26.47865456242841, 38.80842834269753), + Offset(25.05405441770695, 39.73229211885786), + Offset(23.785295519688383, 40.180449370272434), + Offset(22.72555198004472, 40.32032714542882), + Offset(21.87777278679228, 40.26393811183259), + Offset(21.233468870168988, 40.166812820023495), + Offset(20.762232548431296, 40.079066925029025), + Offset(20.436073294394554, 40.00993309439713), + Offset(20.23334169244069, 39.96345252268739), + Offset(20.137297077676344, 39.940484854102536), + Offset(20.125, 39.9375), + ], + <Offset>[ + Offset(24.946426391602, 26.0), + Offset(24.919526142652916, 26.01250952487153), + Offset(24.81962665114753, 26.055221415675078), + Offset(24.59338657440784, 26.131575775813122), + Offset(24.112549450730533, 26.21086569759901), + Offset(23.26102990202604, 26.405449292562118), + Offset(21.93030078929294, 28.333115001580325), + Offset(20.21574669997896, 26.840753449152132), + Offset(19.702668556230993, 25.46403358899737), + Offset(19.57851450097965, 24.507387236351565), + Offset(19.597421849557026, 23.820597237404847), + Offset(19.672638738964572, 23.313659191847616), + Offset(19.76421128572404, 22.933948220939197), + Offset(19.853181729528682, 22.647748525973807), + Offset(19.930810929304265, 22.432414178767115), + Offset(19.99628397445662, 22.272029228601628), + Offset(20.048487526419784, 22.155772744171706), + Offset(20.086790256569586, 22.07583407578212), + Offset(20.111504785414724, 22.026366303959268), + Offset(20.12345813528363, 22.002990192537517), + Offset(20.125, 22.0), + ], + <Offset>[ + Offset(24.946426391602, 26.0), + Offset(24.919526142652916, 26.01250952487153), + Offset(24.81962665114753, 26.055221415675078), + Offset(24.59338657440784, 26.131575775813122), + Offset(24.112549450730533, 26.21086569759901), + Offset(23.26102990202604, 26.405449292562118), + Offset(21.93030078929294, 28.333115001580325), + Offset(20.21574669997896, 26.840753449152132), + Offset(19.702668556230993, 25.46403358899737), + Offset(19.57851450097965, 24.507387236351565), + Offset(19.597421849557026, 23.820597237404847), + Offset(19.672638738964572, 23.313659191847616), + Offset(19.76421128572404, 22.933948220939197), + Offset(19.853181729528682, 22.647748525973807), + Offset(19.930810929304265, 22.432414178767115), + Offset(19.99628397445662, 22.272029228601628), + Offset(20.048487526419784, 22.155772744171706), + Offset(20.086790256569586, 22.07583407578212), + Offset(20.111504785414724, 22.026366303959268), + Offset(20.12345813528363, 22.002990192537517), + Offset(20.125, 22.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(23.053573608398, 26.0), + Offset(23.026843499970756, 25.98713093206553), + Offset(22.930471553825814, 25.93696458861411), + Offset(22.727975001333434, 25.810435118276295), + Offset(22.35865229164589, 25.48545353746269), + Offset(21.484852675448433, 23.920646105398983), + Offset(22.070212775572372, 19.602789326384535), + Offset(24.25581739693188, 19.275065010286717), + Offset(25.471296020158917, 19.70514960582061), + Offset(26.22827021130133, 20.147495919393876), + Offset(26.733592485966874, 20.544229197031424), + Offset(27.081522869281894, 20.885303225908167), + Offset(27.327534182039592, 21.170532082708068), + Offset(27.505108572109584, 21.404060918464253), + Offset(27.63502336031513, 21.591218114904695), + Offset(27.72782810454829, 21.737496381673637), + Offset(27.7923498205881, 21.847395103999485), + Offset(27.83532084300952, 21.924924331216626), + Offset(27.861326008837327, 21.973725967822613), + Offset(27.873455828782106, 21.997010997914884), + Offset(27.875, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(23.053573608398, 26.0), + Offset(23.026843499970756, 25.98713093206553), + Offset(22.930471553825814, 25.93696458861411), + Offset(22.727975001333434, 25.810435118276295), + Offset(22.35865229164589, 25.48545353746269), + Offset(21.484852675448433, 23.920646105398983), + Offset(22.070212775572372, 19.602789326384535), + Offset(24.25581739693188, 19.275065010286717), + Offset(25.471296020158917, 19.70514960582061), + Offset(26.22827021130133, 20.147495919393876), + Offset(26.733592485966874, 20.544229197031424), + Offset(27.081522869281894, 20.885303225908167), + Offset(27.327534182039592, 21.170532082708068), + Offset(27.505108572109584, 21.404060918464253), + Offset(27.63502336031513, 21.591218114904695), + Offset(27.72782810454829, 21.737496381673637), + Offset(27.7923498205881, 21.847395103999485), + Offset(27.83532084300952, 21.924924331216626), + Offset(27.861326008837327, 21.973725967822613), + Offset(27.873455828782106, 21.997010997914884), + Offset(27.875, 22.0), + ], + <Offset>[ + Offset(5.999999999998, 26.0), + Offset(5.974802765093067, 25.758483620275033), + Offset(5.910212083183335, 24.871534924524543), + Offset(5.921631764466294, 22.91713253788011), + Offset(6.602164313419802, 18.96856745822857), + Offset(11.905511997883192, 10.519519297575007), + Offset(22.288325077287805, 5.992865842493696), + Offset(30.404134439571386, 7.761342935309134), + Offset(33.61929906827527, 11.570908914756462), + Offset(35.253002434471675, 14.230458757172274), + Offset(36.21471762944605, 16.191242561820587), + Offset(36.80397549635682, 17.698645771797075), + Offset(37.18416968830772, 18.872421799874253), + Offset(37.44562047979026, 19.788403617209426), + Offset(37.63807337154698, 20.499019999728493), + Offset(37.76636524119958, 21.043465830420356), + Offset(37.84688070253245, 21.447001555066198), + Offset(37.895912975403306, 21.728985066095305), + Offset(37.92359388763603, 21.905378434612928), + Offset(37.93595283405028, 21.98924768876775), + Offset(37.9375, 22.0), + ], + <Offset>[ + Offset(5.999999999998, 26.0), + Offset(5.974802765093067, 25.758483620275033), + Offset(5.910212083183335, 24.871534924524543), + Offset(5.921631764466294, 22.91713253788011), + Offset(6.602164313419802, 18.96856745822857), + Offset(11.905511997883192, 10.519519297575007), + Offset(22.288325077287805, 5.992865842493696), + Offset(30.404134439571386, 7.761342935309134), + Offset(33.61929906827527, 11.570908914756462), + Offset(35.253002434471675, 14.230458757172274), + Offset(36.21471762944605, 16.191242561820587), + Offset(36.80397549635682, 17.698645771797075), + Offset(37.18416968830772, 18.872421799874253), + Offset(37.44562047979026, 19.788403617209426), + Offset(37.63807337154698, 20.499019999728493), + Offset(37.76636524119958, 21.043465830420356), + Offset(37.84688070253245, 21.447001555066198), + Offset(37.895912975403306, 21.728985066095305), + Offset(37.92359388763603, 21.905378434612928), + Offset(37.93595283405028, 21.98924768876775), + Offset(37.9375, 22.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(5.999999999998, 26.0), + Offset(5.974802765093067, 25.758483620275033), + Offset(5.910212083183335, 24.871534924524543), + Offset(5.921631764466294, 22.91713253788011), + Offset(6.602164313419802, 18.96856745822857), + Offset(11.905511997883192, 10.519519297575007), + Offset(22.288325077287805, 5.992865842493696), + Offset(30.404134439571386, 7.761342935309134), + Offset(33.61929906827527, 11.570908914756462), + Offset(35.253002434471675, 14.230458757172274), + Offset(36.21471762944605, 16.191242561820587), + Offset(36.80397549635682, 17.698645771797075), + Offset(37.18416968830772, 18.872421799874253), + Offset(37.44562047979026, 19.788403617209426), + Offset(37.63807337154698, 20.499019999728493), + Offset(37.76636524119958, 21.043465830420356), + Offset(37.84688070253245, 21.447001555066198), + Offset(37.895912975403306, 21.728985066095305), + Offset(37.92359388763603, 21.905378434612928), + Offset(37.93595283405028, 21.98924768876775), + Offset(37.9375, 22.0), + ], + <Offset>[ + Offset(5.999999999998, 22.0), + Offset(6.028433122469394, 21.758843163337975), + Offset(6.160113878209987, 20.879348920235355), + Offset(6.600270188725016, 18.975121643790693), + Offset(8.13096257104338, 15.27224822316687), + Offset(15.159629420408717, 8.193423899613903), + Offset(26.365355942650346, 6.058204239675842), + Offset(35.92720334414534, 10.710656671782182), + Offset(42.28957002059698, 20.25584913605079), + Offset(43.52720806379294, 26.850371074240893), + Offset(43.09595034231744, 31.17907366711327), + Offset(42.1853911750992, 34.117278698807326), + Offset(41.205253922272064, 36.11892294920749), + Offset(40.3179907303063, 37.46098223666444), + Offset(39.585035229035, 38.330543932793965), + Offset(39.00355013691195, 38.93824942184222), + Offset(38.56062572454396, 39.37029573592351), + Offset(38.24519601322827, 39.66308408471031), + Offset(38.045430794661996, 39.842464653341054), + Offset(37.949791776443, 39.926742350332766), + Offset(37.9375, 39.9375), + ], + <Offset>[ + Offset(5.999999999998, 22.0), + Offset(6.028433122469394, 21.758843163337975), + Offset(6.160113878209987, 20.879348920235355), + Offset(6.600270188725016, 18.975121643790693), + Offset(8.13096257104338, 15.27224822316687), + Offset(15.159629420408717, 8.193423899613903), + Offset(26.365355942650346, 6.058204239675842), + Offset(35.92720334414534, 10.710656671782182), + Offset(42.28957002059698, 20.25584913605079), + Offset(43.52720806379294, 26.850371074240893), + Offset(43.09595034231744, 31.17907366711327), + Offset(42.1853911750992, 34.117278698807326), + Offset(41.205253922272064, 36.11892294920749), + Offset(40.3179907303063, 37.46098223666444), + Offset(39.585035229035, 38.330543932793965), + Offset(39.00355013691195, 38.93824942184222), + Offset(38.56062572454396, 39.37029573592351), + Offset(38.24519601322827, 39.66308408471031), + Offset(38.045430794661996, 39.842464653341054), + Offset(37.949791776443, 39.926742350332766), + Offset(37.9375, 39.9375), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(5.999999999998, 22.0), + Offset(6.028433122469394, 21.758843163337975), + Offset(6.160113878209987, 20.879348920235355), + Offset(6.600270188725016, 18.975121643790693), + Offset(8.13096257104338, 15.27224822316687), + Offset(15.159629420408717, 8.193423899613903), + Offset(26.365355942650346, 6.058204239675842), + Offset(35.92720334414534, 10.710656671782182), + Offset(42.28957002059698, 20.25584913605079), + Offset(43.52720806379294, 26.850371074240893), + Offset(43.09595034231744, 31.17907366711327), + Offset(42.1853911750992, 34.117278698807326), + Offset(41.205253922272064, 36.11892294920749), + Offset(40.3179907303063, 37.46098223666444), + Offset(39.585035229035, 38.330543932793965), + Offset(39.00355013691195, 38.93824942184222), + Offset(38.56062572454396, 39.37029573592351), + Offset(38.24519601322827, 39.66308408471031), + Offset(38.045430794661996, 39.842464653341054), + Offset(37.949791776443, 39.926742350332766), + Offset(37.9375, 39.9375), + ], + <Offset>[ + Offset(23.053573608398, 22.0), + Offset(23.08047385734708, 21.98749047512847), + Offset(23.180373348852466, 21.944778584324922), + Offset(23.40661342559216, 21.868424224186878), + Offset(23.887450549269467, 21.78913430240099), + Offset(24.73897009797396, 21.594550707437882), + Offset(26.147243640934914, 19.66812772356668), + Offset(29.778886301505835, 22.224378746759765), + Offset(34.14156697248063, 28.39008982711494), + Offset(34.5024758406226, 32.767408236462494), + Offset(33.614825198838254, 35.532060302324105), + Offset(32.46293854802427, 37.30393615291841), + Offset(31.348618416003937, 38.417033232041305), + Offset(30.377478822625626, 39.07663953791927), + Offset(29.58198521780315, 39.42274204797017), + Offset(28.96501300026066, 39.6322799730955), + Offset(28.506094842599616, 39.7706892848568), + Offset(28.184603880834484, 39.85902334983163), + Offset(27.983162915863293, 39.910812186550736), + Offset(27.88729477117482, 39.934505659479896), + Offset(27.875, 39.9375), + ], + <Offset>[ + Offset(23.053573608398, 22.0), + Offset(23.08047385734708, 21.98749047512847), + Offset(23.180373348852466, 21.944778584324922), + Offset(23.40661342559216, 21.868424224186878), + Offset(23.887450549269467, 21.78913430240099), + Offset(24.73897009797396, 21.594550707437882), + Offset(26.147243640934914, 19.66812772356668), + Offset(29.778886301505835, 22.224378746759765), + Offset(34.14156697248063, 28.39008982711494), + Offset(34.5024758406226, 32.767408236462494), + Offset(33.614825198838254, 35.532060302324105), + Offset(32.46293854802427, 37.30393615291841), + Offset(31.348618416003937, 38.417033232041305), + Offset(30.377478822625626, 39.07663953791927), + Offset(29.58198521780315, 39.42274204797017), + Offset(28.96501300026066, 39.6322799730955), + Offset(28.506094842599616, 39.7706892848568), + Offset(28.184603880834484, 39.85902334983163), + Offset(27.983162915863293, 39.910812186550736), + Offset(27.88729477117482, 39.934505659479896), + Offset(27.875, 39.9375), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(23.053573608398, 22.0), + Offset(23.08047385734708, 21.98749047512847), + Offset(23.180373348852466, 21.944778584324922), + Offset(23.40661342559216, 21.868424224186878), + Offset(23.887450549269467, 21.78913430240099), + Offset(24.73897009797396, 21.594550707437882), + Offset(26.147243640934914, 19.66812772356668), + Offset(29.778886301505835, 22.224378746759765), + Offset(34.14156697248063, 28.39008982711494), + Offset(34.5024758406226, 32.767408236462494), + Offset(33.614825198838254, 35.532060302324105), + Offset(32.46293854802427, 37.30393615291841), + Offset(31.348618416003937, 38.417033232041305), + Offset(30.377478822625626, 39.07663953791927), + Offset(29.58198521780315, 39.42274204797017), + Offset(28.96501300026066, 39.6322799730955), + Offset(28.506094842599616, 39.7706892848568), + Offset(28.184603880834484, 39.85902334983163), + Offset(27.983162915863293, 39.910812186550736), + Offset(27.88729477117482, 39.934505659479896), + Offset(27.875, 39.9375), + ], + <Offset>[ + Offset(23.053573608398, 26.0), + Offset(23.026843499970756, 25.98713093206553), + Offset(22.930471553825818, 25.93696458861411), + Offset(22.727975001333434, 25.810435118276295), + Offset(22.35865229164589, 25.48545353746269), + Offset(21.484852675448437, 23.920646105398983), + Offset(22.070212775572372, 19.602789326384535), + Offset(24.25581739693188, 19.275065010286717), + Offset(25.471296020158917, 19.70514960582061), + Offset(26.22827021130133, 20.147495919393876), + Offset(26.733592485966874, 20.544229197031424), + Offset(27.081522869281894, 20.885303225908167), + Offset(27.327534182039592, 21.170532082708068), + Offset(27.505108572109584, 21.404060918464253), + Offset(27.63502336031513, 21.591218114904695), + Offset(27.72782810454829, 21.737496381673637), + Offset(27.7923498205881, 21.847395103999485), + Offset(27.83532084300952, 21.924924331216626), + Offset(27.861326008837327, 21.973725967822613), + Offset(27.873455828782106, 21.997010997914884), + Offset(27.875, 22.0), + ], + <Offset>[ + Offset(23.053573608398, 26.0), + Offset(23.026843499970756, 25.98713093206553), + Offset(22.930471553825818, 25.93696458861411), + Offset(22.727975001333434, 25.810435118276295), + Offset(22.35865229164589, 25.48545353746269), + Offset(21.484852675448437, 23.920646105398983), + Offset(22.070212775572372, 19.602789326384535), + Offset(24.25581739693188, 19.275065010286717), + Offset(25.471296020158917, 19.70514960582061), + Offset(26.22827021130133, 20.147495919393876), + Offset(26.733592485966874, 20.544229197031424), + Offset(27.081522869281894, 20.885303225908167), + Offset(27.327534182039592, 21.170532082708068), + Offset(27.505108572109584, 21.404060918464253), + Offset(27.63502336031513, 21.591218114904695), + Offset(27.72782810454829, 21.737496381673637), + Offset(27.7923498205881, 21.847395103999485), + Offset(27.83532084300952, 21.924924331216626), + Offset(27.861326008837327, 21.973725967822613), + Offset(27.873455828782106, 21.997010997914884), + Offset(27.875, 22.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(6.0, 36.0), + Offset(5.840726871654255, 35.757584762617704), + Offset(5.285457595618709, 34.85199993524763), + Offset(4.227525983784449, 32.77342417727839), + Offset(3.5264717596110557, 28.827211071001663), + Offset(6.517886449942477, 24.591045888519158), + Offset(7.520599639567256, 20.429019310226224), + Offset(9.337441251165988, 14.915299719515282), + Offset(11.67955424234765, 11.532962037598704), + Offset(14.02683296676815, 9.419579743902961), + Offset(16.229456854531474, 8.105002459199046), + Offset(18.082743777434697, 7.3261172370029986), + Offset(19.565347960385694, 6.872065247520328), + Offset(20.738317895220952, 6.610528546128252), + Offset(21.653024624707548, 6.463637943249828), + Offset(22.351393858266118, 6.3842574556990765), + Offset(22.866855439990758, 6.343605379246371), + Offset(23.22597898795316, 6.324220552672472), + Offset(23.450183580341104, 6.315826581309215), + Offset(23.556666562733803, 6.312836771798083), + Offset(23.5703125, 6.312499999999998), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 36.0), + Offset(5.840726871654255, 35.757584762617704), + Offset(5.285457595618709, 34.85199993524763), + Offset(4.227525983784449, 32.77342417727839), + Offset(3.5264717596110557, 28.827211071001663), + Offset(6.517886449942477, 24.591045888519158), + Offset(7.520599639567256, 20.429019310226224), + Offset(9.337441251165988, 14.915299719515282), + Offset(11.67955424234765, 11.532962037598704), + Offset(14.02683296676815, 9.419579743902961), + Offset(16.229456854531474, 8.105002459199046), + Offset(18.082743777434697, 7.3261172370029986), + Offset(19.565347960385694, 6.872065247520328), + Offset(20.738317895220952, 6.610528546128252), + Offset(21.653024624707548, 6.463637943249828), + Offset(22.351393858266118, 6.3842574556990765), + Offset(22.866855439990758, 6.343605379246371), + Offset(23.22597898795316, 6.324220552672472), + Offset(23.450183580341104, 6.315826581309215), + Offset(23.556666562733803, 6.312836771798083), + Offset(23.5703125, 6.312499999999998), + ], + <Offset>[ + Offset(42.0, 36.0), + Offset(41.837490984087786, 36.240257979004646), + Offset(41.215131634221386, 37.10111609048749), + Offset(39.70046993008684, 38.880282689423), + Offset(35.11680046930425, 41.89297634122701), + Offset(17.977223307522138, 40.62221458070813), + Offset(7.4051530249760695, 27.632737664041155), + Offset(7.974125419949719, 17.46832999953845), + Offset(11.043336185217218, 12.16810549276672), + Offset(13.987438256258187, 9.445408761353912), + Offset(16.335956080085097, 8.056106394810097), + Offset(18.194102300352007, 7.289618065369594), + Offset(19.679474513989774, 6.845456228021216), + Offset(20.85398754040343, 6.5917284573090615), + Offset(21.76951977235388, 6.450918244703521), + Offset(22.468302287652584, 6.376174801763673), + Offset(22.98395013193887, 6.338942410896992), + Offset(23.343144268998117, 6.321938651292953), + Offset(23.56736837706624, 6.315030608484569), + Offset(23.673854027857267, 6.312746360589072), + Offset(23.6875, 6.312499999999998), + ], + <Offset>[ + Offset(42.0, 36.0), + Offset(41.837490984087786, 36.240257979004646), + Offset(41.215131634221386, 37.10111609048749), + Offset(39.70046993008684, 38.880282689423), + Offset(35.11680046930425, 41.89297634122701), + Offset(17.977223307522138, 40.62221458070813), + Offset(7.4051530249760695, 27.632737664041155), + Offset(7.974125419949719, 17.46832999953845), + Offset(11.043336185217218, 12.16810549276672), + Offset(13.987438256258187, 9.445408761353912), + Offset(16.335956080085097, 8.056106394810097), + Offset(18.194102300352007, 7.289618065369594), + Offset(19.679474513989774, 6.845456228021216), + Offset(20.85398754040343, 6.5917284573090615), + Offset(21.76951977235388, 6.450918244703521), + Offset(22.468302287652584, 6.376174801763673), + Offset(22.98395013193887, 6.338942410896992), + Offset(23.343144268998117, 6.321938651292953), + Offset(23.56736837706624, 6.315030608484569), + Offset(23.673854027857267, 6.312746360589072), + Offset(23.6875, 6.312499999999998), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 36.0), + Offset(41.837490984087786, 36.240257979004646), + Offset(41.215131634221386, 37.10111609048749), + Offset(39.70046993008684, 38.880282689423), + Offset(35.11680046930425, 41.89297634122701), + Offset(17.977223307522138, 40.62221458070813), + Offset(7.4051530249760695, 27.632737664041155), + Offset(7.974125419949719, 17.46832999953845), + Offset(11.043336185217218, 12.16810549276672), + Offset(13.987438256258187, 9.445408761353912), + Offset(16.335956080085097, 8.056106394810097), + Offset(18.194102300352007, 7.289618065369594), + Offset(19.679474513989774, 6.845456228021216), + Offset(20.85398754040343, 6.5917284573090615), + Offset(21.76951977235388, 6.450918244703521), + Offset(22.468302287652584, 6.376174801763673), + Offset(22.98395013193887, 6.338942410896992), + Offset(23.343144268998117, 6.321938651292953), + Offset(23.56736837706624, 6.315030608484569), + Offset(23.673854027857267, 6.312746360589072), + Offset(23.6875, 6.312499999999998), + ], + <Offset>[ + Offset(42.0, 32.0), + Offset(41.891121341464114, 32.24061752206759), + Offset(41.46503342924804, 33.1089300861983), + Offset(40.382213841518244, 34.93682280811562), + Offset(37.807067599374584, 37.94317621909476), + Offset(31.28569346733829, 41.88836406262549), + Offset(21.918156356601166, 43.36435943014172), + Offset(14.025584375723557, 40.89778062244908), + Offset(9.769920092960579, 37.63050924159487), + Offset(7.367850012815694, 34.638113152492416), + Offset(5.973096817006795, 32.07021795746492), + Offset(5.173978263055725, 29.973153422615376), + Offset(4.723297068059789, 28.301904267150505), + Offset(4.475728989802221, 26.983370203369095), + Offset(4.346332932330473, 25.957300958770094), + Offset(4.284100454437475, 25.175143122894923), + Offset(4.258180500986249, 24.598514092031586), + Offset(4.250093592349071, 24.197111996156252), + Offset(4.24918203540361, 23.946652278620284), + Offset(4.2498612199243055, 23.82773735822788), + Offset(4.25, 23.8125), + ], + <Offset>[ + Offset(42.0, 32.0), + Offset(41.891121341464114, 32.24061752206759), + Offset(41.46503342924804, 33.1089300861983), + Offset(40.382213841518244, 34.93682280811562), + Offset(37.807067599374584, 37.94317621909476), + Offset(31.28569346733829, 41.88836406262549), + Offset(21.918156356601166, 43.36435943014172), + Offset(14.025584375723557, 40.89778062244908), + Offset(9.769920092960579, 37.63050924159487), + Offset(7.367850012815694, 34.638113152492416), + Offset(5.973096817006795, 32.07021795746492), + Offset(5.173978263055725, 29.973153422615376), + Offset(4.723297068059789, 28.301904267150505), + Offset(4.475728989802221, 26.983370203369095), + Offset(4.346332932330473, 25.957300958770094), + Offset(4.284100454437475, 25.175143122894923), + Offset(4.258180500986249, 24.598514092031586), + Offset(4.250093592349071, 24.197111996156252), + Offset(4.24918203540361, 23.946652278620284), + Offset(4.2498612199243055, 23.82773735822788), + Offset(4.25, 23.8125), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.0, 32.0), + Offset(41.891121341464114, 32.24061752206759), + Offset(41.46503342924804, 33.1089300861983), + Offset(40.382213841518244, 34.93682280811562), + Offset(37.807067599374584, 37.94317621909476), + Offset(31.28569346733829, 41.88836406262549), + Offset(21.918156356601166, 43.36435943014172), + Offset(14.025584375723557, 40.89778062244908), + Offset(9.769920092960579, 37.63050924159487), + Offset(7.367850012815694, 34.638113152492416), + Offset(5.973096817006795, 32.07021795746492), + Offset(5.173978263055725, 29.973153422615376), + Offset(4.723297068059789, 28.301904267150505), + Offset(4.475728989802221, 26.983370203369095), + Offset(4.346332932330473, 25.957300958770094), + Offset(4.284100454437475, 25.175143122894923), + Offset(4.258180500986249, 24.598514092031586), + Offset(4.250093592349071, 24.197111996156252), + Offset(4.24918203540361, 23.946652278620284), + Offset(4.2498612199243055, 23.82773735822788), + Offset(4.25, 23.8125), + ], + <Offset>[ + Offset(6.0, 32.0), + Offset(5.894357229030582, 31.757944305680645), + Offset(5.535359390645361, 30.859813930958445), + Offset(4.903580651262228, 28.82898486195736), + Offset(4.366121086699318, 24.111995114141347), + Offset(9.36700394742377, 11.224965859696677), + Offset(22.54292545773696, 4.379581429626963), + Offset(32.60235573940598, 6.109759600029818), + Offset(37.826493474762316, 9.62132472038408), + Offset(40.59568298818934, 12.852389468570193), + Offset(42.097634124796315, 15.484672916733718), + Offset(42.946789236607636, 17.592634404564635), + Offset(43.43502405056509, 19.276124853051655), + Offset(43.71087263569899, 20.606380075899363), + Offset(43.86148701396686, 21.64277921186285), + Offset(43.93943970232704, 22.43350690800619), + Offset(43.97670000978504, 23.016835227922453), + Offset(43.992556922799054, 23.423091048223576), + Offset(43.99826508457116, 23.676658296500023), + Offset(43.99984938980357, 23.797069876131136), + Offset(44.0, 23.812499999999996), + ], + <Offset>[ + Offset(6.0, 32.0), + Offset(5.894357229030582, 31.757944305680645), + Offset(5.535359390645361, 30.859813930958445), + Offset(4.903580651262228, 28.82898486195736), + Offset(4.366121086699318, 24.111995114141347), + Offset(9.36700394742377, 11.224965859696677), + Offset(22.54292545773696, 4.379581429626963), + Offset(32.60235573940598, 6.109759600029818), + Offset(37.826493474762316, 9.62132472038408), + Offset(40.59568298818934, 12.852389468570193), + Offset(42.097634124796315, 15.484672916733718), + Offset(42.946789236607636, 17.592634404564635), + Offset(43.43502405056509, 19.276124853051655), + Offset(43.71087263569899, 20.606380075899363), + Offset(43.86148701396686, 21.64277921186285), + Offset(43.93943970232704, 22.43350690800619), + Offset(43.97670000978504, 23.016835227922453), + Offset(43.992556922799054, 23.423091048223576), + Offset(43.99826508457116, 23.676658296500023), + Offset(43.99984938980357, 23.797069876131136), + Offset(44.0, 23.812499999999996), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(6.0, 32.0), + Offset(5.894357229030582, 31.757944305680645), + Offset(5.535359390645361, 30.859813930958445), + Offset(4.903580651262228, 28.82898486195736), + Offset(4.366121086699318, 24.111995114141347), + Offset(9.36700394742377, 11.224965859696677), + Offset(22.54292545773696, 4.379581429626963), + Offset(32.60235573940598, 6.109759600029818), + Offset(37.826493474762316, 9.62132472038408), + Offset(40.59568298818934, 12.852389468570193), + Offset(42.097634124796315, 15.484672916733718), + Offset(42.946789236607636, 17.592634404564635), + Offset(43.43502405056509, 19.276124853051655), + Offset(43.71087263569899, 20.606380075899363), + Offset(43.86148701396686, 21.64277921186285), + Offset(43.93943970232704, 22.43350690800619), + Offset(43.97670000978504, 23.016835227922453), + Offset(43.992556922799054, 23.423091048223576), + Offset(43.99826508457116, 23.676658296500023), + Offset(43.99984938980357, 23.797069876131136), + Offset(44.0, 23.812499999999996), + ], + <Offset>[ + Offset(6.0, 36.0), + Offset(5.840726871654255, 35.757584762617704), + Offset(5.285457595618709, 34.85199993524763), + Offset(4.227525983824194, 32.773424177285236), + Offset(3.526471759568551, 28.827211070984085), + Offset(6.517886449901766, 24.591045888462205), + Offset(7.520599639566615, 20.429019310266217), + Offset(9.337441251161277, 14.915299719524107), + Offset(11.679554242336327, 11.53296203761001), + Offset(14.02683296675945, 9.419579743908663), + Offset(16.229456854531474, 8.105002459199046), + Offset(18.082743777434697, 7.3261172370029986), + Offset(19.565347960385694, 6.872065247520328), + Offset(20.738317895220952, 6.610528546128252), + Offset(21.653024624707548, 6.463637943249828), + Offset(22.351393858266118, 6.3842574556990765), + Offset(22.866855439990758, 6.343605379246371), + Offset(23.22597898795316, 6.324220552672472), + Offset(23.450183580341104, 6.315826581309215), + Offset(23.556666562733803, 6.312836771798083), + Offset(23.5703125, 6.312499999999998), + ], + <Offset>[ + Offset(6.0, 36.0), + Offset(5.840726871654255, 35.757584762617704), + Offset(5.285457595618709, 34.85199993524763), + Offset(4.227525983824194, 32.773424177285236), + Offset(3.526471759568551, 28.827211070984085), + Offset(6.517886449901766, 24.591045888462205), + Offset(7.520599639566615, 20.429019310266217), + Offset(9.337441251161277, 14.915299719524107), + Offset(11.679554242336327, 11.53296203761001), + Offset(14.02683296675945, 9.419579743908663), + Offset(16.229456854531474, 8.105002459199046), + Offset(18.082743777434697, 7.3261172370029986), + Offset(19.565347960385694, 6.872065247520328), + Offset(20.738317895220952, 6.610528546128252), + Offset(21.653024624707548, 6.463637943249828), + Offset(22.351393858266118, 6.3842574556990765), + Offset(22.866855439990758, 6.343605379246371), + Offset(23.22597898795316, 6.324220552672472), + Offset(23.450183580341104, 6.315826581309215), + Offset(23.556666562733803, 6.312836771798083), + Offset(23.5703125, 6.312499999999998), + ], + ), + _PathClose( + ), + ], + ), + ], +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/pause_play.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/pause_play.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..2d9d9266384087f151688329189415b80f29da78 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/pause_play.g.dart @@ -0,0 +1,816 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$pause_play = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(12.0, 38.0), + Offset(11.702518567871357, 37.66537647364598), + Offset(10.658516625352865, 36.33928535710834), + Offset(8.824010134196683, 33.09051115695809), + Offset(7.183618981881198, 27.281162329416798), + Offset(7.4961448079806345, 21.476581828368367), + Offset(9.111297618374987, 17.041890063132637), + Offset(10.944617318451954, 14.273857051215758), + Offset(12.539001321903285, 12.570685504133255), + Offset(13.794958189315498, 11.511449771679523), + Offset(14.725226220617056, 10.84845238497297), + Offset(15.369630177419687, 10.439047154098617), + Offset(15.770227104208459, 10.200145460041224), + Offset(15.977727112935135, 10.078681424879498), + Offset(16.046646118566024, 10.039192889334426), + Offset(16.046875, 10.039062500000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.0, 38.0), + Offset(11.702518567871357, 37.66537647364598), + Offset(10.658516625352865, 36.33928535710834), + Offset(8.824010134196683, 33.09051115695809), + Offset(7.183618981881198, 27.281162329416798), + Offset(7.4961448079806345, 21.476581828368367), + Offset(9.111297618374987, 17.041890063132637), + Offset(10.944617318451954, 14.273857051215758), + Offset(12.539001321903285, 12.570685504133255), + Offset(13.794958189315498, 11.511449771679523), + Offset(14.725226220617056, 10.84845238497297), + Offset(15.369630177419687, 10.439047154098617), + Offset(15.770227104208459, 10.200145460041224), + Offset(15.977727112935135, 10.078681424879498), + Offset(16.046646118566024, 10.039192889334426), + Offset(16.046875, 10.039062500000002), + ], + <Offset>[ + Offset(20.0, 38.0), + Offset(19.80052916638957, 37.82094858440343), + Offset(19.11164196247534, 37.113338636628065), + Offset(17.966685507002932, 35.41245490387412), + Offset(16.388368582775627, 32.64921363804367), + Offset(15.647464737031132, 29.978925368550197), + Offset(15.429304294338682, 27.901717576585412), + Offset(15.521061545777922, 26.541981731286498), + Offset(15.686957461206134, 25.650190745693187), + Offset(15.84005263487414, 25.05047803281999), + Offset(15.953666440217397, 24.63834819764938), + Offset(16.022300799535966, 24.35280207511846), + Offset(16.047681038809458, 24.15758118207667), + Offset(16.04697282889272, 24.039447195772148), + Offset(16.046875001068816, 24.00013038745822), + Offset(16.046875, 24.0), + ], + <Offset>[ + Offset(20.0, 38.0), + Offset(19.80052916638957, 37.82094858440343), + Offset(19.11164196247534, 37.113338636628065), + Offset(17.966685507002932, 35.41245490387412), + Offset(16.388368582775627, 32.64921363804367), + Offset(15.647464737031132, 29.978925368550197), + Offset(15.429304294338682, 27.901717576585412), + Offset(15.521061545777922, 26.541981731286498), + Offset(15.686957461206134, 25.650190745693187), + Offset(15.84005263487414, 25.05047803281999), + Offset(15.953666440217397, 24.63834819764938), + Offset(16.022300799535966, 24.35280207511846), + Offset(16.047681038809458, 24.15758118207667), + Offset(16.04697282889272, 24.039447195772148), + Offset(16.046875001068816, 24.00013038745822), + Offset(16.046875, 24.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(20.0, 38.0), + Offset(19.80052916638957, 37.82094858440343), + Offset(19.11164196247534, 37.113338636628065), + Offset(17.966685507002932, 35.41245490387412), + Offset(16.388368582775627, 32.64921363804367), + Offset(15.647464737031132, 29.978925368550197), + Offset(15.429304294338682, 27.901717576585412), + Offset(15.521061545777922, 26.541981731286498), + Offset(15.686957461206134, 25.650190745693187), + Offset(15.84005263487414, 25.05047803281999), + Offset(15.953666440217397, 24.63834819764938), + Offset(16.022300799535966, 24.35280207511846), + Offset(16.047681038809458, 24.15758118207667), + Offset(16.04697282889272, 24.039447195772148), + Offset(16.046875001068816, 24.00013038745822), + Offset(16.046875, 24.0), + ], + <Offset>[ + Offset(20.0, 10.0), + Offset(20.336398367184067, 9.927295626138141), + Offset(21.61961776538543, 9.72474102274872), + Offset(24.500250707242675, 9.686480391272799), + Offset(29.133385987204207, 10.794971358676317), + Offset(33.085276289027, 13.261042804636414), + Offset(35.61934940727931, 16.155597331715125), + Offset(36.90120687325454, 18.566431660274624), + Offset(37.51766973937702, 20.39600693122759), + Offset(37.80131897673813, 21.733189454430033), + Offset(37.922586409468074, 22.681298975667566), + Offset(37.96809580639086, 23.323362088481808), + Offset(37.98160482507013, 23.72156603022978), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + <Offset>[ + Offset(20.0, 10.0), + Offset(20.336398367184067, 9.927295626138141), + Offset(21.61961776538543, 9.72474102274872), + Offset(24.500250707242675, 9.686480391272799), + Offset(29.133385987204207, 10.794971358676317), + Offset(33.085276289027, 13.261042804636414), + Offset(35.61934940727931, 16.155597331715125), + Offset(36.90120687325454, 18.566431660274624), + Offset(37.51766973937702, 20.39600693122759), + Offset(37.80131897673813, 21.733189454430033), + Offset(37.922586409468074, 22.681298975667566), + Offset(37.96809580639086, 23.323362088481808), + Offset(37.98160482507013, 23.72156603022978), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(20.0, 10.0), + Offset(20.336398367184067, 9.927295626138141), + Offset(21.61961776538543, 9.72474102274872), + Offset(24.500250707242675, 9.686480391272799), + Offset(29.133385987204207, 10.794971358676317), + Offset(33.085276289027, 13.261042804636414), + Offset(35.61934940727931, 16.155597331715125), + Offset(36.90120687325454, 18.566431660274624), + Offset(37.51766973937702, 20.39600693122759), + Offset(37.80131897673813, 21.733189454430033), + Offset(37.922586409468074, 22.681298975667566), + Offset(37.96809580639086, 23.323362088481808), + Offset(37.98160482507013, 23.72156603022978), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + <Offset>[ + Offset(12.0, 10.0), + Offset(12.471392106978678, 9.776199797090369), + Offset(14.305807236043629, 9.055014880021247), + Offset(18.610309025181536, 8.190625764405059), + Offset(25.30150028462865, 8.56028166562692), + Offset(31.058306963326036, 11.146785273031004), + Offset(34.676551168058815, 14.535050411928939), + Offset(36.494518178468795, 17.476216776016784), + Offset(37.358155554762675, 19.733238289785056), + Offset(37.747534126472296, 21.37712051621949), + Offset(37.90872109014562, 22.525653380696408), + Offset(37.966090830555, 23.280619636994825), + Offset(37.98158497072831, 23.720567249296572), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + <Offset>[ + Offset(12.0, 10.0), + Offset(12.471392106978678, 9.776199797090369), + Offset(14.305807236043629, 9.055014880021247), + Offset(18.610309025181536, 8.190625764405059), + Offset(25.30150028462865, 8.56028166562692), + Offset(31.058306963326036, 11.146785273031004), + Offset(34.676551168058815, 14.535050411928939), + Offset(36.494518178468795, 17.476216776016784), + Offset(37.358155554762675, 19.733238289785056), + Offset(37.747534126472296, 21.37712051621949), + Offset(37.90872109014562, 22.525653380696408), + Offset(37.966090830555, 23.280619636994825), + Offset(37.98158497072831, 23.720567249296572), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(12.0, 10.0), + Offset(12.471392106978678, 9.776199797090369), + Offset(14.305807236043629, 9.055014880021247), + Offset(18.610309025181536, 8.190625764405059), + Offset(25.30150028462865, 8.56028166562692), + Offset(31.058306963326036, 11.146785273031004), + Offset(34.676551168058815, 14.535050411928939), + Offset(36.494518178468795, 17.476216776016784), + Offset(37.358155554762675, 19.733238289785056), + Offset(37.747534126472296, 21.37712051621949), + Offset(37.90872109014562, 22.525653380696408), + Offset(37.966090830555, 23.280619636994825), + Offset(37.98158497072831, 23.720567249296572), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + <Offset>[ + Offset(12.0, 38.0), + Offset(11.702518567871357, 37.66537647364598), + Offset(10.658516625352863, 36.33928535710834), + Offset(8.824010134196683, 33.09051115695809), + Offset(7.1836189818552825, 27.281162329401685), + Offset(7.496144808015238, 21.476581828404456), + Offset(9.111297618380014, 17.04189006314128), + Offset(10.944617318448458, 14.273857051206388), + Offset(12.53900132190984, 12.570685504160476), + Offset(13.794958189310869, 11.511449771648872), + Offset(14.725226220612885, 10.848452384926155), + Offset(15.369630177421872, 10.439047154145166), + Offset(15.770227104207432, 10.2001454599895), + Offset(15.977727112935135, 10.078681424879498), + Offset(16.046646118566024, 10.039192889334426), + Offset(16.046875, 10.039062500000002), + ], + <Offset>[ + Offset(12.0, 38.0), + Offset(11.702518567871357, 37.66537647364598), + Offset(10.658516625352863, 36.33928535710834), + Offset(8.824010134196683, 33.09051115695809), + Offset(7.1836189818552825, 27.281162329401685), + Offset(7.496144808015238, 21.476581828404456), + Offset(9.111297618380014, 17.04189006314128), + Offset(10.944617318448458, 14.273857051206388), + Offset(12.53900132190984, 12.570685504160476), + Offset(13.794958189310869, 11.511449771648872), + Offset(14.725226220612885, 10.848452384926155), + Offset(15.369630177421872, 10.439047154145166), + Offset(15.770227104207432, 10.2001454599895), + Offset(15.977727112935135, 10.078681424879498), + Offset(16.046646118566024, 10.039192889334426), + Offset(16.046875, 10.039062500000002), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(28.0, 10.0), + Offset(28.201404627403626, 10.078391455203436), + Offset(28.933428294762216, 10.394467165488965), + Offset(30.390192389339767, 11.182335018165535), + Offset(32.965271689797355, 13.029661051643949), + Offset(35.1122456147493, 15.375300336193657), + Offset(36.562147646495, 17.776144251469397), + Offset(37.30789556803902, 19.656646544522257), + Offset(37.67718392397584, 21.05877557270265), + Offset(37.8551038269895, 22.089258392661982), + Offset(37.936451728823435, 22.836944570678963), + Offset(37.970100782170086, 23.366104539917995), + Offset(37.98162467944151, 23.722564811170674), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(28.0, 10.0), + Offset(28.201404627403626, 10.078391455203436), + Offset(28.933428294762216, 10.394467165488965), + Offset(30.390192389339767, 11.182335018165535), + Offset(32.965271689797355, 13.029661051643949), + Offset(35.1122456147493, 15.375300336193657), + Offset(36.562147646495, 17.776144251469397), + Offset(37.30789556803902, 19.656646544522257), + Offset(37.67718392397584, 21.05877557270265), + Offset(37.8551038269895, 22.089258392661982), + Offset(37.936451728823435, 22.836944570678963), + Offset(37.970100782170086, 23.366104539917995), + Offset(37.98162467944151, 23.722564811170674), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + <Offset>[ + Offset(28.0, 38.0), + Offset(27.665535426609125, 37.97204441346873), + Offset(26.425452491852123, 37.78306477936831), + Offset(23.856627189100024, 36.90830953076686), + Offset(20.220254285368775, 34.883903331011304), + Offset(17.674434062753434, 32.09318290010744), + Offset(16.372102533554372, 29.522264496339687), + Offset(15.927750240562414, 27.632196615534127), + Offset(15.84647164580496, 26.31295938716825), + Offset(15.893837485125506, 25.406546971051934), + Offset(15.967531759572758, 24.79399379266078), + Offset(16.024305775315185, 24.395544526554644), + Offset(16.04770089318083, 24.15857996301756), + Offset(16.04697282889272, 24.039447195772148), + Offset(16.046875001068816, 24.00013038745822), + Offset(16.046875, 24.0), + ], + <Offset>[ + Offset(28.0, 38.0), + Offset(27.665535426609125, 37.97204441346873), + Offset(26.425452491852123, 37.78306477936831), + Offset(23.856627189100024, 36.90830953076686), + Offset(20.220254285368775, 34.883903331011304), + Offset(17.674434062753434, 32.09318290010744), + Offset(16.372102533554372, 29.522264496339687), + Offset(15.927750240562414, 27.632196615534127), + Offset(15.84647164580496, 26.31295938716825), + Offset(15.893837485125506, 25.406546971051934), + Offset(15.967531759572758, 24.79399379266078), + Offset(16.024305775315185, 24.395544526554644), + Offset(16.04770089318083, 24.15857996301756), + Offset(16.04697282889272, 24.039447195772148), + Offset(16.046875001068816, 24.00013038745822), + Offset(16.046875, 24.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(28.0, 38.0), + Offset(27.665535426609125, 37.97204441346873), + Offset(26.425452491852123, 37.78306477936831), + Offset(23.856627189100024, 36.90830953076686), + Offset(20.220254285368775, 34.883903331011304), + Offset(17.674434062753434, 32.09318290010744), + Offset(16.372102533554372, 29.522264496339687), + Offset(15.927750240562414, 27.632196615534127), + Offset(15.84647164580496, 26.31295938716825), + Offset(15.893837485125506, 25.406546971051934), + Offset(15.967531759572758, 24.79399379266078), + Offset(16.024305775315185, 24.395544526554644), + Offset(16.04770089318083, 24.15857996301756), + Offset(16.04697282889272, 24.039447195772148), + Offset(16.046875001068816, 24.00013038745822), + Offset(16.046875, 24.0), + ], + <Offset>[ + Offset(36.0, 38.0), + Offset(35.76354602512734, 38.127616524226184), + Offset(34.8785778289746, 38.55711805888804), + Offset(32.999302561906276, 39.23025327768289), + Offset(29.425003886263205, 40.25195463963817), + Offset(25.82575399180393, 40.59552644028928), + Offset(22.690109209518063, 40.382092009792466), + Offset(20.504194467888382, 39.90032129560486), + Offset(18.99442778510781, 39.39246462872818), + Offset(17.93893193068415, 38.9455752321924), + Offset(17.195971979173102, 38.583889605337184), + Offset(16.676976397431464, 38.30929944757449), + Offset(16.325154827781827, 38.116015685053), + Offset(16.11621854485031, 38.00021296666479), + Offset(16.047103883571605, 37.96106788558201), + Offset(16.046875, 37.9609375), + ], + <Offset>[ + Offset(36.0, 38.0), + Offset(35.76354602512734, 38.127616524226184), + Offset(34.8785778289746, 38.55711805888804), + Offset(32.999302561906276, 39.23025327768289), + Offset(29.425003886263205, 40.25195463963817), + Offset(25.82575399180393, 40.59552644028928), + Offset(22.690109209518063, 40.382092009792466), + Offset(20.504194467888382, 39.90032129560486), + Offset(18.99442778510781, 39.39246462872818), + Offset(17.93893193068415, 38.9455752321924), + Offset(17.195971979173102, 38.583889605337184), + Offset(16.676976397431464, 38.30929944757449), + Offset(16.325154827781827, 38.116015685053), + Offset(16.11621854485031, 38.00021296666479), + Offset(16.047103883571605, 37.96106788558201), + Offset(16.046875, 37.9609375), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(36.0, 38.0), + Offset(35.76354602512734, 38.127616524226184), + Offset(34.8785778289746, 38.55711805888804), + Offset(32.999302561906276, 39.23025327768289), + Offset(29.425003886263205, 40.25195463963817), + Offset(25.82575399180393, 40.59552644028928), + Offset(22.690109209518063, 40.382092009792466), + Offset(20.504194467888382, 39.90032129560486), + Offset(18.99442778510781, 39.39246462872818), + Offset(17.93893193068415, 38.9455752321924), + Offset(17.195971979173102, 38.583889605337184), + Offset(16.676976397431464, 38.30929944757449), + Offset(16.325154827781827, 38.116015685053), + Offset(16.11621854485031, 38.00021296666479), + Offset(16.047103883571605, 37.96106788558201), + Offset(16.046875, 37.9609375), + ], + <Offset>[ + Offset(36.0, 10.0), + Offset(36.06641088760902, 10.22948728425121), + Offset(36.247238824104016, 11.064193308216439), + Offset(36.28013407140091, 12.678189645033275), + Offset(36.797157392346996, 15.26435074467823), + Offset(37.13921494048486, 17.48955786783516), + Offset(37.50494588572052, 19.396691171264223), + Offset(37.71458426282127, 20.746861428770725), + Offset(37.836698108596735, 21.721544214172404), + Offset(37.9088886772507, 22.445327330841877), + Offset(37.95031704814173, 22.992590165603303), + Offset(37.972105758008134, 23.40884699145153), + Offset(37.981644533782294, 23.72356359205216), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + <Offset>[ + Offset(36.0, 10.0), + Offset(36.06641088760902, 10.22948728425121), + Offset(36.247238824104016, 11.064193308216439), + Offset(36.28013407140091, 12.678189645033275), + Offset(36.797157392346996, 15.26435074467823), + Offset(37.13921494048486, 17.48955786783516), + Offset(37.50494588572052, 19.396691171264223), + Offset(37.71458426282127, 20.746861428770725), + Offset(37.836698108596735, 21.721544214172404), + Offset(37.9088886772507, 22.445327330841877), + Offset(37.95031704814173, 22.992590165603303), + Offset(37.972105758008134, 23.40884699145153), + Offset(37.981644533782294, 23.72356359205216), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(36.0, 10.0), + Offset(36.06641088760902, 10.22948728425121), + Offset(36.247238824104016, 11.064193308216439), + Offset(36.28013407140091, 12.678189645033275), + Offset(36.797157392346996, 15.26435074467823), + Offset(37.13921494048486, 17.48955786783516), + Offset(37.50494588572052, 19.396691171264223), + Offset(37.71458426282127, 20.746861428770725), + Offset(37.836698108596735, 21.721544214172404), + Offset(37.9088886772507, 22.445327330841877), + Offset(37.95031704814173, 22.992590165603303), + Offset(37.972105758008134, 23.40884699145153), + Offset(37.981644533782294, 23.72356359205216), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + <Offset>[ + Offset(28.0, 10.0), + Offset(28.201404627403626, 10.078391455203436), + Offset(28.933428294762216, 10.394467165488965), + Offset(30.390192389339767, 11.182335018165535), + Offset(32.965271689771434, 13.029661051628835), + Offset(35.1122456147839, 15.37530033622975), + Offset(36.56214764650002, 17.776144251478037), + Offset(37.30789556803553, 19.656646544512885), + Offset(37.6771839239824, 21.058775572729875), + Offset(37.855103826984866, 22.08925839263133), + Offset(37.936451728819264, 22.83694457063215), + Offset(37.97010078217227, 23.366104539964546), + Offset(37.98162467944048, 23.72256481111895), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + <Offset>[ + Offset(28.0, 10.0), + Offset(28.201404627403626, 10.078391455203436), + Offset(28.933428294762216, 10.394467165488965), + Offset(30.390192389339767, 11.182335018165535), + Offset(32.965271689771434, 13.029661051628835), + Offset(35.1122456147839, 15.37530033622975), + Offset(36.56214764650002, 17.776144251478037), + Offset(37.30789556803553, 19.656646544512885), + Offset(37.6771839239824, 21.058775572729875), + Offset(37.855103826984866, 22.08925839263133), + Offset(37.936451728819264, 22.83694457063215), + Offset(37.97010078217227, 23.366104539964546), + Offset(37.98162467944048, 23.72256481111895), + Offset(37.98420298259533, 23.93063803493896), + Offset(37.98437499812064, 23.99977073325126), + Offset(37.984375, 24.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.4, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(25.9803619385, 10.0808715820312), + Offset(26.24734975266162, 10.121477441291603), + Offset(27.241376275815597, 10.319449968588765), + Offset(29.345667299377446, 10.996623113678018), + Offset(32.72280163575925, 12.973817480806794), + Offset(35.41804029052999, 15.796810056618218), + Offset(36.783888674275296, 18.8537388815253), + Offset(36.76701249453052, 21.35111747744179), + Offset(36.26390281517317, 23.085253769933463), + Offset(35.55535514851543, 24.257370049664456), + Offset(34.77089367166791, 25.028704643469656), + Offset(33.96889356105216, 25.514915651546502), + Offset(33.73686027995342, 25.787198268946305), + Offset(33.7091203242374, 25.93222884083115), + Offset(33.69944957998795, 25.98020292120046), + Offset(33.69941711426, 25.9803619385), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(25.9803619385, 10.0808715820312), + Offset(26.24734975266162, 10.121477441291603), + Offset(27.241376275815597, 10.319449968588765), + Offset(29.345667299377446, 10.996623113678018), + Offset(32.72280163575925, 12.973817480806794), + Offset(35.41804029052999, 15.796810056618218), + Offset(36.783888674275296, 18.8537388815253), + Offset(36.76701249453052, 21.35111747744179), + Offset(36.26390281517317, 23.085253769933463), + Offset(35.55535514851543, 24.257370049664456), + Offset(34.77089367166791, 25.028704643469656), + Offset(33.96889356105216, 25.514915651546502), + Offset(33.73686027995342, 25.787198268946305), + Offset(33.7091203242374, 25.93222884083115), + Offset(33.69944957998795, 25.98020292120046), + Offset(33.69941711426, 25.9803619385), + ], + <Offset>[ + Offset(21.71524047854, 10.08666992187495), + Offset(21.982903763348478, 10.045351931852684), + Offset(22.99349608666543, 9.936293880836264), + Offset(25.21035246628397, 9.952369351341783), + Offset(29.035517231913246, 10.830169092168797), + Offset(32.462182698221135, 12.722041677870582), + Offset(34.6342053830667, 15.169969772143412), + Offset(35.27135627354946, 17.356833870551508), + Offset(35.261093097185864, 18.9396949456921), + Offset(34.91382519935541, 20.040769389846336), + Offset(34.38827629668238, 20.780777793707646), + Offset(33.765232522395, 21.254657700831064), + Offset(33.64837008011561, 21.522993253407158), + Offset(33.68424238621404, 21.667178311445102), + Offset(33.695656510950016, 21.71508152285272), + Offset(33.69569396972875, 21.71524047854), + ], + <Offset>[ + Offset(21.71524047854, 10.08666992187495), + Offset(21.982903763348478, 10.045351931852684), + Offset(22.99349608666543, 9.936293880836264), + Offset(25.21035246628397, 9.952369351341783), + Offset(29.035517231913246, 10.830169092168797), + Offset(32.462182698221135, 12.722041677870582), + Offset(34.6342053830667, 15.169969772143412), + Offset(35.27135627354946, 17.356833870551508), + Offset(35.261093097185864, 18.9396949456921), + Offset(34.91382519935541, 20.040769389846336), + Offset(34.38827629668238, 20.780777793707646), + Offset(33.765232522395, 21.254657700831064), + Offset(33.64837008011561, 21.522993253407158), + Offset(33.68424238621404, 21.667178311445102), + Offset(33.695656510950016, 21.71508152285272), + Offset(33.69569396972875, 21.71524047854), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(21.71524047854, 10.08666992187495), + Offset(21.982903763348478, 10.045351931852684), + Offset(22.99349608666543, 9.936293880836264), + Offset(25.21035246628397, 9.952369351341783), + Offset(29.035517231913246, 10.830169092168797), + Offset(32.462182698221135, 12.722041677870582), + Offset(34.6342053830667, 15.169969772143412), + Offset(35.27135627354946, 17.356833870551508), + Offset(35.261093097185864, 18.9396949456921), + Offset(34.91382519935541, 20.040769389846336), + Offset(34.38827629668238, 20.780777793707646), + Offset(33.765232522395, 21.254657700831064), + Offset(33.64837008011561, 21.522993253407158), + Offset(33.68424238621404, 21.667178311445102), + Offset(33.695656510950016, 21.71508152285272), + Offset(33.69569396972875, 21.71524047854), + ], + <Offset>[ + Offset(20.38534545901, 33.58843994137495), + Offset(20.201841309352226, 33.51724216990988), + Offset(19.52604939723053, 33.21887595990057), + Offset(18.136339024380444, 32.40365324862053), + Offset(16.04712654551591, 30.461865967119433), + Offset(14.577060238240236, 28.0264269776442), + Offset(13.994487095033097, 25.634345790525074), + Offset(14.153634069120049, 23.79893867630368), + Offset(14.553527226932179, 22.528826743801503), + Offset(15.025384555247236, 21.662436101573526), + Offset(15.497710938825563, 21.080134472962335), + Offset(15.942008679892364, 20.700182681641447), + Offset(16.112739485629255, 20.479547499155572), + Offset(16.16612590845245, 20.362297297739467), + Offset(16.184204863198634, 20.323614463660565), + Offset(16.18426513672875, 20.323486328150004), + ], + <Offset>[ + Offset(20.38534545901, 33.58843994137495), + Offset(20.201841309352226, 33.51724216990988), + Offset(19.52604939723053, 33.21887595990057), + Offset(18.136339024380444, 32.40365324862053), + Offset(16.04712654551591, 30.461865967119433), + Offset(14.577060238240236, 28.0264269776442), + Offset(13.994487095033097, 25.634345790525074), + Offset(14.153634069120049, 23.79893867630368), + Offset(14.553527226932179, 22.528826743801503), + Offset(15.025384555247236, 21.662436101573526), + Offset(15.497710938825563, 21.080134472962335), + Offset(15.942008679892364, 20.700182681641447), + Offset(16.112739485629255, 20.479547499155572), + Offset(16.16612590845245, 20.362297297739467), + Offset(16.184204863198634, 20.323614463660565), + Offset(16.18426513672875, 20.323486328150004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(20.38534545901, 33.58843994137495), + Offset(20.201841309352226, 33.51724216990988), + Offset(19.52604939723053, 33.21887595990057), + Offset(18.136339024380444, 32.40365324862053), + Offset(16.04712654551591, 30.461865967119433), + Offset(14.577060238240236, 28.0264269776442), + Offset(13.994487095033097, 25.634345790525074), + Offset(14.153634069120049, 23.79893867630368), + Offset(14.553527226932179, 22.528826743801503), + Offset(15.025384555247236, 21.662436101573526), + Offset(15.497710938825563, 21.080134472962335), + Offset(15.942008679892364, 20.700182681641447), + Offset(16.112739485629255, 20.479547499155572), + Offset(16.16612590845245, 20.362297297739467), + Offset(16.184204863198634, 20.323614463660565), + Offset(16.18426513672875, 20.323486328150004), + ], + <Offset>[ + Offset(26.45292663577, 33.61682128903115), + Offset(26.267757982058896, 33.66216200032068), + Offset(25.565762818520753, 33.800433030319155), + Offset(24.010240085864943, 33.92471641540826), + Offset(21.274220812328387, 33.54307228337337), + Offset(18.755635225924188, 32.42595626039356), + Offset(17.02173119623894, 30.892872384129042), + Offset(16.25004855832711, 29.492905492037444), + Offset(15.94990552834042, 28.433591685898556), + Offset(15.909598267598703, 27.665285725985097), + Offset(16.015710329110547, 27.125598624037742), + Offset(16.207680408412312, 26.761973499405), + Offset(16.21513039026629, 26.546291998077596), + Offset(16.178017367555142, 26.42989412892011), + Offset(16.166100602771248, 26.391195938046174), + Offset(16.16606140137715, 26.391067504910005), + ], + <Offset>[ + Offset(26.45292663577, 33.61682128903125), + Offset(26.267757982058896, 33.66216200032078), + Offset(25.565762818520742, 33.800433030319255), + Offset(24.010240085864922, 33.924716415408355), + Offset(21.274220812328338, 33.543072283373455), + Offset(18.75563522592411, 32.42595626039363), + Offset(17.02173119623894, 30.892872384129042), + Offset(16.25004855832711, 29.492905492037444), + Offset(15.94990552834032, 28.433591685898577), + Offset(15.909598267598604, 27.66528572598511), + Offset(16.015710329110444, 27.12559862403775), + Offset(16.207680408412212, 26.761973499405002), + Offset(16.21513039026629, 26.546291998077596), + Offset(16.178017367555142, 26.42989412892011), + Offset(16.166100602771248, 26.391195938046174), + Offset(16.16606140137715, 26.391067504910005), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.45292663577, 33.61682128903125), + Offset(26.267757982058896, 33.66216200032078), + Offset(25.565762818520742, 33.800433030319255), + Offset(24.010240085864922, 33.924716415408355), + Offset(21.274220812328338, 33.543072283373455), + Offset(18.75563522592411, 32.42595626039363), + Offset(17.02173119623894, 30.892872384129042), + Offset(16.25004855832711, 29.492905492037444), + Offset(15.94990552834032, 28.433591685898577), + Offset(15.909598267598604, 27.66528572598511), + Offset(16.015710329110444, 27.12559862403775), + Offset(16.207680408412212, 26.761973499405002), + Offset(16.21513039026629, 26.546291998077596), + Offset(16.178017367555142, 26.42989412892011), + Offset(16.166100602771248, 26.391195938046174), + Offset(16.16606140137715, 26.391067504910005), + ], + <Offset>[ + Offset(25.980361938504004, 10.08087158203125), + Offset(26.24734975266562, 10.121477441291729), + Offset(27.241376275819576, 10.319449968589181), + Offset(29.34566729938131, 10.996623113679052), + Offset(32.72280163576268, 12.973817480808854), + Offset(35.418040290532716, 15.796810056621142), + Offset(36.78388867431184, 18.85373888150635), + Offset(36.7670124944848, 21.351117477459912), + Offset(36.26390281513503, 23.08525376994367), + Offset(35.55535514848602, 24.2573700496689), + Offset(34.770893671747466, 25.028704643461566), + Offset(33.968893561041796, 25.51491565154599), + Offset(33.73686027997065, 25.787198268949965), + Offset(33.70912032425456, 25.93222884083507), + Offset(33.6994495800051, 25.98020292120446), + Offset(33.69941711427715, 25.980361938504004), + ], + <Offset>[ + Offset(25.980361938504004, 10.08087158203125), + Offset(26.24734975266562, 10.121477441291729), + Offset(27.241376275819576, 10.319449968589181), + Offset(29.34566729938131, 10.996623113679052), + Offset(32.72280163576268, 12.973817480808854), + Offset(35.418040290532716, 15.796810056621142), + Offset(36.78388867431184, 18.85373888150635), + Offset(36.7670124944848, 21.351117477459912), + Offset(36.26390281513503, 23.08525376994367), + Offset(35.55535514848602, 24.2573700496689), + Offset(34.770893671747466, 25.028704643461566), + Offset(33.968893561041796, 25.51491565154599), + Offset(33.73686027997065, 25.787198268949965), + Offset(33.70912032425456, 25.93222884083507), + Offset(33.6994495800051, 25.98020292120446), + Offset(33.69941711427715, 25.980361938504004), + ], + ), + _PathClose( + ), + ], + ), + ], +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/play_pause.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/play_pause.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..71fa1939fee14d9c3777805c5bf8b1bf71710634 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/play_pause.g.dart @@ -0,0 +1,816 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$play_pause = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(16.046875, 10.039062500000002), + Offset(16.316498427194905, 9.888877552610037), + Offset(17.350168694919763, 9.372654593279519), + Offset(19.411307079826894, 8.531523285503246), + Offset(22.581365240485308, 7.589125591600418), + Offset(25.499178877190392, 6.946027752843147), + Offset(28.464059662259196, 6.878006546805963), + Offset(30.817518246129985, 7.278084288616373), + Offset(32.55729037951853, 7.8522502852455425), + Offset(33.815177617779455, 8.44633949301522), + Offset(34.712260860180656, 8.99474841944718), + Offset(35.33082450786742, 9.453096000457315), + Offset(35.71938467416858, 9.764269500343072), + Offset(35.93041292728106, 9.940652668613495), + Offset(35.999770475547926, 9.999803268019111), + Offset(36.0, 10.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(16.046875, 10.039062500000002), + Offset(16.316498427194905, 9.888877552610037), + Offset(17.350168694919763, 9.372654593279519), + Offset(19.411307079826894, 8.531523285503246), + Offset(22.581365240485308, 7.589125591600418), + Offset(25.499178877190392, 6.946027752843147), + Offset(28.464059662259196, 6.878006546805963), + Offset(30.817518246129985, 7.278084288616373), + Offset(32.55729037951853, 7.8522502852455425), + Offset(33.815177617779455, 8.44633949301522), + Offset(34.712260860180656, 8.99474841944718), + Offset(35.33082450786742, 9.453096000457315), + Offset(35.71938467416858, 9.764269500343072), + Offset(35.93041292728106, 9.940652668613495), + Offset(35.999770475547926, 9.999803268019111), + Offset(36.0, 10.0), + ], + <Offset>[ + Offset(16.046875, 24.0), + Offset(16.048342217256838, 23.847239495401816), + Offset(16.077346902872737, 23.272630763824544), + Offset(16.048056811677085, 21.774352893256555), + Offset(16.312852147291277, 18.33792251536507), + Offset(17.783803270262858, 14.342870123090869), + Offset(20.317723014778526, 11.617364447163006), + Offset(22.6612333095366, 10.320666923510533), + Offset(24.489055761050455, 9.794101160418514), + Offset(25.820333134665205, 9.653975058221658), + Offset(26.739449095852216, 9.704987479092615), + Offset(27.339611564620206, 9.827950233030684), + Offset(27.720964836869285, 9.92326668993185), + Offset(27.930511332768496, 9.98033236260651), + Offset(27.999770476623045, 9.999934423927339), + Offset(27.999999999999996, 10.0), + ], + <Offset>[ + Offset(16.046875, 24.0), + Offset(16.048342217256838, 23.847239495401816), + Offset(16.077346902872737, 23.272630763824544), + Offset(16.048056811677085, 21.774352893256555), + Offset(16.312852147291277, 18.33792251536507), + Offset(17.783803270262858, 14.342870123090869), + Offset(20.317723014778526, 11.617364447163006), + Offset(22.6612333095366, 10.320666923510533), + Offset(24.489055761050455, 9.794101160418514), + Offset(25.820333134665205, 9.653975058221658), + Offset(26.739449095852216, 9.704987479092615), + Offset(27.339611564620206, 9.827950233030684), + Offset(27.720964836869285, 9.92326668993185), + Offset(27.930511332768496, 9.98033236260651), + Offset(27.999770476623045, 9.999934423927339), + Offset(27.999999999999996, 10.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(16.046875, 24.0), + Offset(16.048342217256838, 23.847239495401816), + Offset(16.077346902872737, 23.272630763824544), + Offset(16.048056811677085, 21.774352893256555), + Offset(16.312852147291277, 18.33792251536507), + Offset(17.783803270262858, 14.342870123090869), + Offset(20.317723014778526, 11.617364447163006), + Offset(22.6612333095366, 10.320666923510533), + Offset(24.489055761050455, 9.794101160418514), + Offset(25.820333134665205, 9.653975058221658), + Offset(26.739449095852216, 9.704987479092615), + Offset(27.339611564620206, 9.827950233030684), + Offset(27.720964836869285, 9.92326668993185), + Offset(27.930511332768496, 9.98033236260651), + Offset(27.999770476623045, 9.999934423927339), + Offset(27.999999999999996, 10.0), + ], + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92629019604922, 25.273340032354483), + Offset(37.60401862920776, 27.24886978355857), + Offset(36.59673961336577, 30.16713606026377), + Offset(35.26901818749416, 32.58105797429066), + Offset(33.66938906523204, 34.56713290494057), + Offset(32.196778918797094, 35.8827095523761), + Offset(30.969894470496282, 36.721466129987085), + Offset(29.989349224706995, 37.25388702486493), + Offset(29.223528593231507, 37.59010302049878), + Offset(28.651601378627003, 37.79719553439594), + Offset(28.27745500043001, 37.91773612047938), + Offset(28.069390261744058, 37.979987943400474), + Offset(28.000229522301836, 37.99993442016443), + Offset(28.0, 38.0), + ], + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92629019604922, 25.273340032354483), + Offset(37.60401862920776, 27.24886978355857), + Offset(36.59673961336577, 30.16713606026377), + Offset(35.26901818749416, 32.58105797429066), + Offset(33.66938906523204, 34.56713290494057), + Offset(32.196778918797094, 35.8827095523761), + Offset(30.969894470496282, 36.721466129987085), + Offset(29.989349224706995, 37.25388702486493), + Offset(29.223528593231507, 37.59010302049878), + Offset(28.651601378627003, 37.79719553439594), + Offset(28.27745500043001, 37.91773612047938), + Offset(28.069390261744058, 37.979987943400474), + Offset(28.000229522301836, 37.99993442016443), + Offset(28.0, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92629019604922, 25.273340032354483), + Offset(37.60401862920776, 27.24886978355857), + Offset(36.59673961336577, 30.16713606026377), + Offset(35.26901818749416, 32.58105797429066), + Offset(33.66938906523204, 34.56713290494057), + Offset(32.196778918797094, 35.8827095523761), + Offset(30.969894470496282, 36.721466129987085), + Offset(29.989349224706995, 37.25388702486493), + Offset(29.223528593231507, 37.59010302049878), + Offset(28.651601378627003, 37.79719553439594), + Offset(28.27745500043001, 37.91773612047938), + Offset(28.069390261744058, 37.979987943400474), + Offset(28.000229522301836, 37.99993442016443), + Offset(28.0, 38.0), + ], + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92663369548548, 25.26958881281347), + Offset(37.702366207906195, 26.86162526614268), + Offset(37.62294586290445, 28.407471142252255), + Offset(38.43944238184115, 29.541526367903558), + Offset(38.93163276984633, 31.5056762828673), + Offset(38.80537374713073, 33.4174700441868), + Offset(38.35814295213548, 34.94327332096457), + Offset(37.78610517302408, 36.076173087300646), + Offset(37.186112675124534, 36.8807750697281), + Offset(36.64281432187422, 37.42234130182257), + Offset(36.275874837729305, 37.7587389308906), + Offset(36.06929185625662, 37.94030824940746), + Offset(36.00022952122672, 37.9998032642562), + Offset(36.0, 38.0), + ], + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92663369548548, 25.26958881281347), + Offset(37.702366207906195, 26.86162526614268), + Offset(37.62294586290445, 28.407471142252255), + Offset(38.43944238184115, 29.541526367903558), + Offset(38.93163276984633, 31.5056762828673), + Offset(38.80537374713073, 33.4174700441868), + Offset(38.35814295213548, 34.94327332096457), + Offset(37.78610517302408, 36.076173087300646), + Offset(37.186112675124534, 36.8807750697281), + Offset(36.64281432187422, 37.42234130182257), + Offset(36.275874837729305, 37.7587389308906), + Offset(36.06929185625662, 37.94030824940746), + Offset(36.00022952122672, 37.9998032642562), + Offset(36.0, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92663369548548, 25.26958881281347), + Offset(37.702366207906195, 26.86162526614268), + Offset(37.62294586290445, 28.407471142252255), + Offset(38.43944238184115, 29.541526367903558), + Offset(38.93163276984633, 31.5056762828673), + Offset(38.80537374713073, 33.4174700441868), + Offset(38.35814295213548, 34.94327332096457), + Offset(37.78610517302408, 36.076173087300646), + Offset(37.186112675124534, 36.8807750697281), + Offset(36.64281432187422, 37.42234130182257), + Offset(36.275874837729305, 37.7587389308906), + Offset(36.06929185625662, 37.94030824940746), + Offset(36.00022952122672, 37.9998032642562), + Offset(36.0, 38.0), + ], + <Offset>[ + Offset(16.046875, 10.039062500000002), + Offset(16.316498427194905, 9.888877552610037), + Offset(17.35016869491465, 9.372654593335355), + Offset(19.411307079839695, 8.531523285452844), + Offset(22.58136524050546, 7.589125591565864), + Offset(25.499178877175954, 6.946027752856988), + Offset(28.464059662259196, 6.878006546805963), + Offset(30.817518246129985, 7.278084288616373), + Offset(32.55729037951755, 7.852250285245777), + Offset(33.81517761778539, 8.446339493014325), + Offset(34.71226086018563, 8.994748419446736), + Offset(35.33082450786742, 9.453096000457315), + Offset(35.71938467416858, 9.764269500343072), + Offset(35.93041292728106, 9.940652668613495), + Offset(35.999770475547926, 9.999803268019111), + Offset(36.0, 10.0), + ], + <Offset>[ + Offset(16.046875, 10.039062500000002), + Offset(16.316498427194905, 9.888877552610037), + Offset(17.35016869491465, 9.372654593335355), + Offset(19.411307079839695, 8.531523285452844), + Offset(22.58136524050546, 7.589125591565864), + Offset(25.499178877175954, 6.946027752856988), + Offset(28.464059662259196, 6.878006546805963), + Offset(30.817518246129985, 7.278084288616373), + Offset(32.55729037951755, 7.852250285245777), + Offset(33.81517761778539, 8.446339493014325), + Offset(34.71226086018563, 8.994748419446736), + Offset(35.33082450786742, 9.453096000457315), + Offset(35.71938467416858, 9.764269500343072), + Offset(35.93041292728106, 9.940652668613495), + Offset(35.999770475547926, 9.999803268019111), + Offset(36.0, 10.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.925946696573504, 25.277091251817644), + Offset(37.50567105053561, 27.636114300999704), + Offset(35.57053336387648, 31.926800978315658), + Offset(32.09859399311199, 35.6205895806324), + Offset(28.407145360613207, 37.6285895270458), + Offset(25.588184090469714, 38.34794906057932), + Offset(23.581645988882627, 38.49965893899394), + Offset(22.19259327642332, 38.43160096243417), + Offset(21.26094464377359, 38.29943245748053), + Offset(20.660388435379787, 38.17204976696931), + Offset(20.279035163130715, 38.07673331006816), + Offset(20.069488667231496, 38.01966763739349), + Offset(20.000229523376955, 38.00006557607266), + Offset(20.0, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.925946696573504, 25.277091251817644), + Offset(37.50567105053561, 27.636114300999704), + Offset(35.57053336387648, 31.926800978315658), + Offset(32.09859399311199, 35.6205895806324), + Offset(28.407145360613207, 37.6285895270458), + Offset(25.588184090469714, 38.34794906057932), + Offset(23.581645988882627, 38.49965893899394), + Offset(22.19259327642332, 38.43160096243417), + Offset(21.26094464377359, 38.29943245748053), + Offset(20.660388435379787, 38.17204976696931), + Offset(20.279035163130715, 38.07673331006816), + Offset(20.069488667231496, 38.01966763739349), + Offset(20.000229523376955, 38.00006557607266), + Offset(20.0, 38.0), + ], + <Offset>[ + Offset(16.046875, 24.0), + Offset(16.048342217256838, 23.847239495401816), + Offset(16.077003403397015, 23.276381983287706), + Offset(15.949709233004938, 22.161597410697688), + Offset(15.286645897801982, 20.097587433416958), + Offset(14.613379075880687, 17.38240172943261), + Offset(15.05547931015969, 14.678821069268237), + Offset(16.052638481209218, 12.785906431713748), + Offset(17.100807279436804, 11.57229396942536), + Offset(18.02357718638153, 10.831688995790898), + Offset(18.7768651463943, 10.414316916074366), + Offset(19.34839862137299, 10.202804465604057), + Offset(19.722544999569994, 10.082263879520628), + Offset(19.93060973825594, 10.02001205659953), + Offset(19.99977047769816, 10.000065579835564), + Offset(19.999999999999996, 10.000000000000004), + ], + <Offset>[ + Offset(16.046875, 24.0), + Offset(16.048342217256838, 23.847239495401816), + Offset(16.077003403397015, 23.276381983287706), + Offset(15.949709233004938, 22.161597410697688), + Offset(15.286645897801982, 20.097587433416958), + Offset(14.613379075880687, 17.38240172943261), + Offset(15.05547931015969, 14.678821069268237), + Offset(16.052638481209218, 12.785906431713748), + Offset(17.100807279436804, 11.57229396942536), + Offset(18.02357718638153, 10.831688995790898), + Offset(18.7768651463943, 10.414316916074366), + Offset(19.34839862137299, 10.202804465604057), + Offset(19.722544999569994, 10.082263879520628), + Offset(19.93060973825594, 10.02001205659953), + Offset(19.99977047769816, 10.000065579835564), + Offset(19.999999999999996, 10.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(16.046875, 24.0), + Offset(16.048342217256838, 23.847239495401816), + Offset(16.077003403397015, 23.276381983287706), + Offset(15.949709233004938, 22.161597410697688), + Offset(15.286645897801982, 20.097587433416958), + Offset(14.613379075880687, 17.38240172943261), + Offset(15.05547931015969, 14.678821069268237), + Offset(16.052638481209218, 12.785906431713748), + Offset(17.100807279436804, 11.57229396942536), + Offset(18.02357718638153, 10.831688995790898), + Offset(18.7768651463943, 10.414316916074366), + Offset(19.34839862137299, 10.202804465604057), + Offset(19.722544999569994, 10.082263879520628), + Offset(19.93060973825594, 10.02001205659953), + Offset(19.99977047769816, 10.000065579835564), + Offset(19.999999999999996, 10.000000000000004), + ], + <Offset>[ + Offset(16.046875, 37.9609375), + Offset(15.780186007318768, 37.8056014381936), + Offset(14.804181611349989, 37.17635815383272), + Offset(12.58645896485513, 35.404427018450995), + Offset(9.018132804607959, 30.846384357181606), + Offset(6.898003468953149, 24.77924409968033), + Offset(6.909142662679017, 19.41817896962528), + Offset(7.8963535446158275, 15.828489066607908), + Offset(9.032572660968736, 13.51414484459833), + Offset(10.02873270326728, 12.039324560997336), + Offset(10.80405338206586, 11.124555975719801), + Offset(11.357185678125777, 10.577658698177427), + Offset(11.724125162270699, 10.241261069109406), + Offset(11.930708143743377, 10.059691750592545), + Offset(11.999770478773279, 10.000196735743792), + Offset(11.999999999999996, 10.000000000000004), + ], + <Offset>[ + Offset(16.046875, 37.9609375), + Offset(15.780186007318768, 37.8056014381936), + Offset(14.804181611349989, 37.17635815383272), + Offset(12.58645896485513, 35.404427018450995), + Offset(9.018132804607959, 30.846384357181606), + Offset(6.898003468953149, 24.77924409968033), + Offset(6.909142662679017, 19.41817896962528), + Offset(7.8963535446158275, 15.828489066607908), + Offset(9.032572660968736, 13.51414484459833), + Offset(10.02873270326728, 12.039324560997336), + Offset(10.80405338206586, 11.124555975719801), + Offset(11.357185678125777, 10.577658698177427), + Offset(11.724125162270699, 10.241261069109406), + Offset(11.930708143743377, 10.059691750592545), + Offset(11.999770478773279, 10.000196735743792), + Offset(11.999999999999996, 10.000000000000004), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(16.046875, 37.9609375), + Offset(15.780186007318768, 37.8056014381936), + Offset(14.804181611349989, 37.17635815383272), + Offset(12.58645896485513, 35.404427018450995), + Offset(9.018132804607959, 30.846384357181606), + Offset(6.898003468953149, 24.77924409968033), + Offset(6.909142662679017, 19.41817896962528), + Offset(7.8963535446158275, 15.828489066607908), + Offset(9.032572660968736, 13.51414484459833), + Offset(10.02873270326728, 12.039324560997336), + Offset(10.80405338206586, 11.124555975719801), + Offset(11.357185678125777, 10.577658698177427), + Offset(11.724125162270699, 10.241261069109406), + Offset(11.930708143743377, 10.059691750592545), + Offset(11.999770478773279, 10.000196735743792), + Offset(11.999999999999996, 10.000000000000004), + ], + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92560319713213, 25.28084247141449), + Offset(37.40732347184997, 28.02335881836519), + Offset(34.544327114357955, 33.68646589629262), + Offset(28.928169798750567, 38.66012118703334), + Offset(23.144901655998915, 40.69004614911907), + Offset(18.979589262136074, 40.81318856876862), + Offset(16.193397507242462, 40.27785174801669), + Offset(14.395837328112165, 39.60931489999756), + Offset(13.298360561885538, 39.008760408250765), + Offset(12.669175492132574, 38.546903999542685), + Offset(12.280615325831423, 38.23573049965694), + Offset(12.069587072718935, 38.05934733138651), + Offset(12.000229524452074, 38.00019673198088), + Offset(12.0, 38.0), + ], + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92560319713213, 25.28084247141449), + Offset(37.40732347184997, 28.02335881836519), + Offset(34.544327114357955, 33.68646589629262), + Offset(28.928169798750567, 38.66012118703334), + Offset(23.144901655998915, 40.69004614911907), + Offset(18.979589262136074, 40.81318856876862), + Offset(16.193397507242462, 40.27785174801669), + Offset(14.395837328112165, 39.60931489999756), + Offset(13.298360561885538, 39.008760408250765), + Offset(12.669175492132574, 38.546903999542685), + Offset(12.280615325831423, 38.23573049965694), + Offset(12.069587072718935, 38.05934733138651), + Offset(12.000229524452074, 38.00019673198088), + Offset(12.0, 38.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92560319713213, 25.28084247141449), + Offset(37.40732347184997, 28.02335881836519), + Offset(34.544327114357955, 33.68646589629262), + Offset(28.928169798750567, 38.66012118703334), + Offset(23.144901655998915, 40.69004614911907), + Offset(18.979589262136074, 40.81318856876862), + Offset(16.193397507242462, 40.27785174801669), + Offset(14.395837328112165, 39.60931489999756), + Offset(13.298360561885538, 39.008760408250765), + Offset(12.669175492132574, 38.546903999542685), + Offset(12.280615325831423, 38.23573049965694), + Offset(12.069587072718935, 38.05934733138651), + Offset(12.000229524452074, 38.00019673198088), + Offset(12.0, 38.0), + ], + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92594669656839, 25.27709125187348), + Offset(37.50567105054841, 27.636114300949302), + Offset(35.57053336389663, 31.9268009782811), + Offset(32.09859399309755, 35.62058958064624), + Offset(28.407145360613207, 37.628589527045804), + Offset(25.588184090469714, 38.34794906057932), + Offset(23.58164598888166, 38.49965893899417), + Offset(22.192593276429257, 38.43160096243327), + Offset(21.260944643778565, 38.29943245748009), + Offset(20.660388435379787, 38.17204976696931), + Offset(20.279035163130715, 38.07673331006816), + Offset(20.069488667231496, 38.01966763739349), + Offset(20.000229523376955, 38.00006557607266), + Offset(20.0, 38.0), + ], + <Offset>[ + Offset(37.984375, 24.0), + Offset(37.98179511896882, 24.268606388242382), + Offset(37.92594669656839, 25.27709125187348), + Offset(37.50567105054841, 27.636114300949302), + Offset(35.57053336389663, 31.9268009782811), + Offset(32.09859399309755, 35.62058958064624), + Offset(28.407145360613207, 37.628589527045804), + Offset(25.588184090469714, 38.34794906057932), + Offset(23.58164598888166, 38.49965893899417), + Offset(22.192593276429257, 38.43160096243327), + Offset(21.260944643778565, 38.29943245748009), + Offset(20.660388435379787, 38.17204976696931), + Offset(20.279035163130715, 38.07673331006816), + Offset(20.069488667231496, 38.01966763739349), + Offset(20.000229523376955, 38.00006557607266), + Offset(20.0, 38.0), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 0.733333333333, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(36.21875, 24.387283325200002), + Offset(36.858953419818775, 24.63439009154731), + Offset(37.42714268809582, 25.618428032998864), + Offset(37.46673246436919, 27.957602694496682), + Offset(35.51445214909996, 31.937043103050268), + Offset(32.888668544302234, 34.79679735028506), + Offset(30.100083850883422, 36.58444430738925), + Offset(27.884884986535624, 37.434542424473584), + Offset(26.23678799810123, 37.80492814052796), + Offset(25.03902259291319, 37.946314694750235), + Offset(24.185908910024594, 37.98372980970255), + Offset(23.59896217337824, 37.97921421880389), + Offset(23.221743554700737, 37.96329396736102), + Offset(23.013561704380457, 37.95013265178958), + Offset(22.94461033630511, 37.9450856638228), + Offset(22.9443817139, 37.945068359375), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(36.21875, 24.387283325200002), + Offset(36.858953419818775, 24.63439009154731), + Offset(37.42714268809582, 25.618428032998864), + Offset(37.46673246436919, 27.957602694496682), + Offset(35.51445214909996, 31.937043103050268), + Offset(32.888668544302234, 34.79679735028506), + Offset(30.100083850883422, 36.58444430738925), + Offset(27.884884986535624, 37.434542424473584), + Offset(26.23678799810123, 37.80492814052796), + Offset(25.03902259291319, 37.946314694750235), + Offset(24.185908910024594, 37.98372980970255), + Offset(23.59896217337824, 37.97921421880389), + Offset(23.221743554700737, 37.96329396736102), + Offset(23.013561704380457, 37.95013265178958), + Offset(22.94461033630511, 37.9450856638228), + Offset(22.9443817139, 37.945068359375), + ], + <Offset>[ + Offset(36.1819000244141, 23.597152709966), + Offset(36.8358384608093, 23.843669618675563), + Offset(37.45961204802207, 24.827964901265894), + Offset(37.71106940406011, 26.916549745564488), + Offset(36.67279396166709, 30.08280087402087), + Offset(34.51215067847019, 33.33246277147643), + Offset(32.022419367141104, 35.54300484126963), + Offset(29.955608739426065, 36.73306317469314), + Offset(28.376981306736234, 37.3582262261251), + Offset(27.209745307333925, 37.68567529681684), + Offset(26.368492376458054, 37.856060664218916), + Offset(25.784980483216092, 37.94324273411291), + Offset(25.407936267815487, 37.98634651128109), + Offset(25.199167384595825, 38.0057906185826), + Offset(25.129914160588893, 38.01154763962766), + Offset(25.129684448280003, 38.0115661621094), + ], + <Offset>[ + Offset(36.1819000244141, 23.597152709966), + Offset(36.8358384608093, 23.843669618675563), + Offset(37.45961204802207, 24.827964901265894), + Offset(37.71106940406011, 26.916549745564488), + Offset(36.67279396166709, 30.08280087402087), + Offset(34.51215067847019, 33.33246277147643), + Offset(32.022419367141104, 35.54300484126963), + Offset(29.955608739426065, 36.73306317469314), + Offset(28.376981306736234, 37.3582262261251), + Offset(27.209745307333925, 37.68567529681684), + Offset(26.368492376458054, 37.856060664218916), + Offset(25.784980483216092, 37.94324273411291), + Offset(25.407936267815487, 37.98634651128109), + Offset(25.199167384595825, 38.0057906185826), + Offset(25.129914160588893, 38.01154763962766), + Offset(25.129684448280003, 38.0115661621094), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(36.1819000244141, 23.597152709966), + Offset(36.8358384608093, 23.843669618675563), + Offset(37.45961204802207, 24.827964901265894), + Offset(37.71106940406011, 26.916549745564488), + Offset(36.67279396166709, 30.08280087402087), + Offset(34.51215067847019, 33.33246277147643), + Offset(32.022419367141104, 35.54300484126963), + Offset(29.955608739426065, 36.73306317469314), + Offset(28.376981306736234, 37.3582262261251), + Offset(27.209745307333925, 37.68567529681684), + Offset(26.368492376458054, 37.856060664218916), + Offset(25.784980483216092, 37.94324273411291), + Offset(25.407936267815487, 37.98634651128109), + Offset(25.199167384595825, 38.0057906185826), + Offset(25.129914160588893, 38.01154763962766), + Offset(25.129684448280003, 38.0115661621094), + ], + <Offset>[ + Offset(16.1149902344141, 22.955383300786004), + Offset(15.997629933953313, 22.801455805116497), + Offset(15.966446205406928, 22.215379763234004), + Offset(16.088459709151728, 20.876736411055298), + Offset(16.769441289779344, 18.37084947089115), + Offset(18.595653610551377, 16.59990844352802), + Offset(20.48764499639903, 15.536450078720307), + Offset(21.968961727208672, 15.064497861016925), + Offset(23.06110116092593, 14.884804779309462), + Offset(23.849967628988242, 14.837805654268031), + Offset(24.40943781230773, 14.84572910499329), + Offset(24.793207208324446, 14.870972819299066), + Offset(25.03935354219434, 14.895712045654406), + Offset(25.1750322217718, 14.912227213496571), + Offset(25.21994388130627, 14.918147112632923), + Offset(25.220092773475297, 14.9181671142094), + ], + <Offset>[ + Offset(16.170043945314102, 22.942321777349), + Offset(16.055083258838646, 22.789495616149246), + Offset(16.026762188208856, 22.207786731939372), + Offset(16.150920741832245, 20.879123319500057), + Offset(16.82882476693832, 18.390360508490243), + Offset(18.647384744725734, 16.634993592875272), + Offset(20.52967353640347, 15.58271755944683), + Offset(22.002563841255288, 15.117204368008782), + Offset(23.0881035089048, 14.941178098808251), + Offset(23.872012376061566, 14.896295884855345), + Offset(24.42787166552447, 14.90545574061985), + Offset(24.80911858591767, 14.931420366898372), + Offset(25.053627357583, 14.956567087696417), + Offset(25.188396770682292, 14.973288385939487), + Offset(25.233006406883348, 14.979273607487709), + Offset(25.233154296913, 14.9792938232094), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(16.225097656251602, 22.9292602539115), + Offset(16.112536583755883, 22.7775354271821), + Offset(16.087078170937534, 22.200193700637527), + Offset(16.213381774594694, 20.88151022796511), + Offset(16.888208244083728, 18.409871546081646), + Offset(18.699115878889145, 16.67007874221141), + Offset(20.571702076399895, 15.628985040159975), + Offset(22.03616595529626, 15.16991087498609), + Offset(23.115105856879826, 14.997551418291916), + Offset(23.894057123132363, 14.954786115427265), + Offset(24.446305518739628, 14.965182376230889), + Offset(24.825029963509966, 14.9918679144821), + Offset(25.067901172971148, 15.017422129722831), + Offset(25.201761319592507, 15.034349558366799), + Offset(25.24606893246022, 15.040400102326899), + Offset(25.2462158203505, 15.0404205321938), + ], + <Offset>[ + Offset(16.172653198243793, 25.050704956059), + Offset(16.017298096111325, 24.897541931224776), + Offset(15.837305455486472, 24.307642370134865), + Offset(15.617771431142284, 23.034739327639596), + Offset(15.534079923477577, 20.72510957725349), + Offset(16.76065281331448, 18.52381863579275), + Offset(18.25163791556585, 16.97482787617967), + Offset(19.521978435885586, 16.104176237124552), + Offset(20.506617505527394, 15.621874388004521), + Offset(21.24147683283453, 15.352037236477383), + Offset(21.774425023577333, 15.199799658679147), + Offset(22.14565785051594, 15.114161535583197), + Offset(22.386204205776483, 15.067342323943635), + Offset(22.519618086537456, 15.044265557010121), + Offset(22.563909453457644, 15.037056623787358), + Offset(22.564056396523, 15.0370330810219), + ], + <Offset>[ + Offset(16.172653198243804, 25.050704956059), + Offset(16.017298096111343, 24.89754193122478), + Offset(15.837305455486483, 24.307642370134865), + Offset(15.617771431142284, 23.034739327639596), + Offset(15.534079923477577, 20.72510957725349), + Offset(16.76065281331448, 18.52381863579275), + Offset(18.25163791556585, 16.97482787617967), + Offset(19.521978435885586, 16.104176237124552), + Offset(20.506617505527394, 15.621874388004521), + Offset(21.24147683283453, 15.352037236477383), + Offset(21.774425023577333, 15.199799658679147), + Offset(22.14565785051594, 15.114161535583197), + Offset(22.386204205776483, 15.067342323943635), + Offset(22.519618086537456, 15.044265557010121), + Offset(22.563909453457644, 15.037056623787358), + Offset(22.564056396523, 15.0370330810219), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(16.172653198243804, 25.050704956059), + Offset(16.017298096111343, 24.89754193122478), + Offset(15.837305455486483, 24.307642370134865), + Offset(15.617771431142284, 23.034739327639596), + Offset(15.534079923477577, 20.72510957725349), + Offset(16.76065281331448, 18.52381863579275), + Offset(18.25163791556585, 16.97482787617967), + Offset(19.521978435885586, 16.104176237124552), + Offset(20.506617505527394, 15.621874388004521), + Offset(21.24147683283453, 15.352037236477383), + Offset(21.774425023577333, 15.199799658679147), + Offset(22.14565785051594, 15.114161535583197), + Offset(22.386204205776483, 15.067342323943635), + Offset(22.519618086537456, 15.044265557010121), + Offset(22.563909453457644, 15.037056623787358), + Offset(22.564056396523, 15.0370330810219), + ], + <Offset>[ + Offset(36.218750000043805, 24.387283325200002), + Offset(36.858953419751415, 24.634390091546017), + Offset(37.42714268811728, 25.61842803300083), + Offset(37.46673246430412, 27.95760269448635), + Offset(35.51445214905712, 31.937043103018333), + Offset(32.88866854426982, 34.79679735024258), + Offset(30.100083850861907, 36.584444307340334), + Offset(27.884884986522685, 37.434542424421736), + Offset(26.23678799809464, 37.80492814047493), + Offset(25.039022592911195, 37.94631469469684), + Offset(24.185908910025862, 37.983729809649134), + Offset(23.59896217338175, 37.97921421875057), + Offset(23.221743554705682, 37.96329396730781), + Offset(23.0135617043862, 37.95013265173645), + Offset(22.94461033631111, 37.9450856637697), + Offset(22.944381713906004, 37.9450683593219), + ], + <Offset>[ + Offset(36.218750000043805, 24.387283325200002), + Offset(36.858953419751415, 24.634390091546017), + Offset(37.42714268811728, 25.61842803300083), + Offset(37.46673246430412, 27.95760269448635), + Offset(35.51445214905712, 31.937043103018333), + Offset(32.88866854426982, 34.79679735024258), + Offset(30.100083850861907, 36.584444307340334), + Offset(27.884884986522685, 37.434542424421736), + Offset(26.23678799809464, 37.80492814047493), + Offset(25.039022592911195, 37.94631469469684), + Offset(24.185908910025862, 37.983729809649134), + Offset(23.59896217338175, 37.97921421875057), + Offset(23.221743554705682, 37.96329396730781), + Offset(23.0135617043862, 37.95013265173645), + Offset(22.94461033631111, 37.9450856637697), + Offset(22.944381713906004, 37.9450683593219), + ], + ), + _PathClose( + ), + ], + ), + ], +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/search_ellipsis.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/search_ellipsis.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..6760e2a592b5a3f647d7271dc1cca970b8e45eb2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/search_ellipsis.g.dart @@ -0,0 +1,5267 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$search_ellipsis = _AnimatedIconData( + Size(96.0, 96.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(56.63275314854877, 53.416307677358), + Offset(57.069606004928445, 53.86609044856987), + Offset(59.09460654800288, 55.971023159415935), + Offset(60.89239811736094, 57.88133187802052), + Offset(62.39435194501161, 59.538230172598404), + Offset(63.48463970399173, 60.8425011369294), + Offset(63.932061433030945, 61.59610215538352), + Offset(63.07663991080549, 61.23370607747795), + Offset(59.89718017699878, 58.88057174806894), + Offset(61.21880612019878, 60.239014522068935), + Offset(61.09896916359878, 60.11473915976894), + Offset(60.97913220709878, 59.99046379736894), + Offset(60.85929525059878, 59.866188435068935), + Offset(60.73945829409878, 59.74191307276894), + Offset(60.61962133759878, 59.61763771046894), + Offset(60.49978438099878, 59.49336234816894), + Offset(60.37994742449878, 59.36908698586894), + Offset(60.26011046799878, 59.24481162346894), + Offset(60.140273511498776, 59.12053626116894), + Offset(60.02043655499878, 58.99626089886894), + Offset(59.90059959839878, 58.871985536568936), + Offset(59.78076264189878, 58.74771017426894), + Offset(59.66092568539878, 58.62343481186894), + Offset(59.54108872889878, 58.499159449568936), + Offset(59.42125177229878, 58.37488408726894), + Offset(59.30141481579878, 58.250608724968934), + Offset(59.18157785929878, 58.12633336266894), + Offset(59.06174090279878, 58.00205800026894), + Offset(58.94190394629878, 57.877782637968934), + Offset(58.822066989698776, 57.75350727566894), + Offset(58.70223003319878, 57.62923191336894), + Offset(58.58239307669878, 57.504956551068936), + Offset(58.46255612019878, 57.38068118876894), + Offset(58.34271916359878, 57.25640582636894), + Offset(58.22288220709878, 57.132130464068936), + Offset(58.10304525059878, 57.00785510176894), + Offset(57.98320829409878, 56.883579739468935), + Offset(57.86337133759878, 56.75930437716894), + Offset(57.74353438099878, 56.63502901476894), + Offset(57.62369742449878, 56.510753652468935), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(60.57565945470678, 48.849785482535665), + Offset(61.01177894139154, 49.30041761427725), + Offset(63.01014446522872, 51.43619797836744), + Offset(64.73600505254888, 53.42981438943695), + Offset(66.10705023046606, 55.238326039262105), + Offset(66.98436034991653, 56.78925950135372), + Offset(67.09064385091588, 57.93795367416795), + Offset(65.63435166794956, 58.2714628487421), + Offset(61.39070529296772, 57.15082849245442), + Offset(62.71233123616772, 58.50927126645442), + Offset(62.592494279567724, 58.38499590415442), + Offset(62.47265732306772, 58.260720541754424), + Offset(62.35282036656772, 58.13644517945442), + Offset(62.232983410067725, 58.01216981715442), + Offset(62.11314645356772, 57.887894454854425), + Offset(61.993309496967726, 57.76361909255442), + Offset(61.87347254046772, 57.639343730254424), + Offset(61.75363558396772, 57.515068367854425), + Offset(61.63379862746772, 57.39079300555442), + Offset(61.513961670967724, 57.266517643254424), + Offset(61.39412471436772, 57.14224228095442), + Offset(61.274287757867725, 57.01796691865442), + Offset(61.15445080136772, 56.893691556254424), + Offset(61.03461384486772, 56.76941619395442), + Offset(60.914776888267724, 56.64514083165442), + Offset(60.79493993176772, 56.52086546935442), + Offset(60.67510297526772, 56.39659010705442), + Offset(60.555266018767725, 56.27231474465442), + Offset(60.43542906226772, 56.14803938235442), + Offset(60.31559210566772, 56.02376402005442), + Offset(60.195755149167724, 55.899488657754425), + Offset(60.07591819266772, 55.77521329545442), + Offset(59.95608123616772, 55.650937933154424), + Offset(59.83624427956772, 55.526662570754425), + Offset(59.71640732306772, 55.40238720845442), + Offset(59.596570366567725, 55.278111846154424), + Offset(59.47673341006772, 55.15383648385442), + Offset(59.35689645356772, 55.02956112155442), + Offset(59.237059496967724, 54.905285759154424), + Offset(59.11722254046772, 54.78101039685442), + ], + <Offset>[ + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(62.94942712071989, 42.915335621700216), + Offset(63.38510509316773, 43.36707154474344), + Offset(65.36743540273916, 45.5429401518535), + Offset(67.04999102004787, 47.644819547939385), + Offset(68.34222460676555, 49.6503611948963), + Offset(69.09131472932955, 51.52184630725002), + Offset(68.99222107132888, 53.18398603334939), + Offset(67.17418370976294, 54.42186283224286), + Offset(62.28985971191208, 54.90293081789554), + Offset(63.61148565511208, 56.261373591895534), + Offset(63.49164869851208, 56.13709822959554), + Offset(63.37181174201208, 56.01282286719554), + Offset(63.251974785512076, 55.88854750489554), + Offset(63.13213782901208, 55.764272142595544), + Offset(63.01230087251208, 55.63999678029555), + Offset(62.89246391591208, 55.515721417995536), + Offset(62.77262695941208, 55.39144605569554), + Offset(62.65279000291208, 55.26717069329554), + Offset(62.532953046412075, 55.14289533099554), + Offset(62.41311608991208, 55.018619968695546), + Offset(62.293279133312076, 54.894344606395535), + Offset(62.17344217681208, 54.77006924409554), + Offset(62.05360522031208, 54.64579388169554), + Offset(61.93376826381208, 54.52151851939554), + Offset(61.81393130721208, 54.397243157095545), + Offset(61.69409435071208, 54.272967794795534), + Offset(61.574257394212076, 54.14869243249554), + Offset(61.45442043771208, 54.02441707009554), + Offset(61.33458348121208, 53.90014170779554), + Offset(61.214746524612075, 53.775866345495544), + Offset(61.09490956811208, 53.65159098319555), + Offset(60.97507261161208, 53.527315620895536), + Offset(60.855235655112075, 53.40304025859554), + Offset(60.73539869851208, 53.27876489619554), + Offset(60.615561742012076, 53.15448953389554), + Offset(60.49572478551208, 53.030214171595546), + Offset(60.37588782901208, 52.905938809295534), + Offset(60.25605087251208, 52.78166344699554), + Offset(60.13621391591208, 52.65738808459554), + Offset(60.01637695941208, 52.53311272229554), + ], + <Offset>[ + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(62.94942712071989, 36.41758712071989), + Offset(63.38510509316773, 36.87053160705772), + Offset(65.36743540273916, 39.09029363766916), + Offset(67.04999102004787, 41.31071235333787), + Offset(68.34222460676555, 43.531986106645554), + Offset(69.09131472932955, 45.754449667519545), + Offset(68.99222107132888, 47.97877125586888), + Offset(67.17418370976294, 50.206858354462945), + Offset(62.28985971191208, 52.44166244631208), + Offset(63.61148565511208, 53.800105220312076), + Offset(63.49164869851208, 53.67582985801208), + Offset(63.37181174201208, 53.55155449561208), + Offset(63.251974785512076, 53.42727913331208), + Offset(63.13213782901208, 53.30300377101208), + Offset(63.01230087251208, 53.17872840871208), + Offset(62.89246391591208, 53.05445304641208), + Offset(62.77262695941208, 52.93017768411208), + Offset(62.65279000291208, 52.80590232171208), + Offset(62.532953046412075, 52.68162695941208), + Offset(62.41311608991208, 52.55735159711208), + Offset(62.293279133312076, 52.43307623481208), + Offset(62.17344217681208, 52.30880087251208), + Offset(62.05360522031208, 52.18452551011208), + Offset(61.93376826381208, 52.06025014781208), + Offset(61.81393130721208, 51.93597478551208), + Offset(61.69409435071208, 51.811699423212076), + Offset(61.574257394212076, 51.68742406091208), + Offset(61.45442043771208, 51.56314869851208), + Offset(61.33458348121208, 51.438873336212076), + Offset(61.214746524612075, 51.31459797391208), + Offset(61.09490956811208, 51.19032261161208), + Offset(60.97507261161208, 51.06604724931208), + Offset(60.855235655112075, 50.94177188701208), + Offset(60.73539869851208, 50.81749652461208), + Offset(60.615561742012076, 50.69322116231208), + Offset(60.49572478551208, 50.56894580001208), + Offset(60.37588782901208, 50.44467043771208), + Offset(60.25605087251208, 50.32039507541208), + Offset(60.13621391591208, 50.19611971301208), + Offset(60.01637695941208, 50.07184435071208), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(62.94942712071989, 21.97373945470677), + Offset(63.38510509316773, 22.429370456861527), + Offset(65.36743540273916, 24.74670319561872), + Offset(67.04999102004787, 27.230623010818878), + Offset(68.34222460676555, 29.931447747106052), + Offset(69.09131472932955, 32.934101437486525), + Offset(68.99222107132888, 36.408097305735886), + Offset(67.17418370976294, 40.83732326404956), + Offset(62.28985971191208, 46.97050802736772), + Offset(63.61148565511208, 48.32895080136772), + Offset(63.49164869851208, 48.20467543906772), + Offset(63.37181174201208, 48.08040007666772), + Offset(63.251974785512076, 47.95612471436772), + Offset(63.13213782901208, 47.83184935206772), + Offset(63.01230087251208, 47.707573989767724), + Offset(62.89246391591208, 47.58329862746772), + Offset(62.77262695941208, 47.45902326516772), + Offset(62.65279000291208, 47.334747902767724), + Offset(62.532953046412075, 47.21047254046772), + Offset(62.41311608991208, 47.08619717816772), + Offset(62.293279133312076, 46.96192181586772), + Offset(62.17344217681208, 46.83764645356772), + Offset(62.05360522031208, 46.71337109116772), + Offset(61.93376826381208, 46.58909572886772), + Offset(61.81393130721208, 46.46482036656772), + Offset(61.69409435071208, 46.34054500426772), + Offset(61.574257394212076, 46.21626964196772), + Offset(61.45442043771208, 46.09199427956772), + Offset(61.33458348121208, 45.96771891726772), + Offset(61.214746524612075, 45.84344355496772), + Offset(61.09490956811208, 45.71916819266772), + Offset(60.97507261161208, 45.59489283036772), + Offset(60.855235655112075, 45.47061746806772), + Offset(60.73539869851208, 45.34634210566772), + Offset(60.615561742012076, 45.22206674336772), + Offset(60.49572478551208, 45.09779138106772), + Offset(60.37588782901208, 44.97351601876772), + Offset(60.25605087251208, 44.84924065646772), + Offset(60.13621391591208, 44.72496529406772), + Offset(60.01637695941208, 44.60068993176772), + ], + <Offset>[ + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.241465482535666, 10.265747120719887), + Offset(51.67932110354725, 10.723555777147723), + Offset(53.74074073435744, 13.11997804449917), + Offset(55.636886306106945, 15.817488374127876), + Offset(57.3178365729021, 18.90703080962556), + Offset(58.69933686192372, 22.542096324509547), + Offset(59.61321003018795, 27.02906167480888), + Offset(59.5793821068421, 33.242501749162955), + Offset(57.855025758054424, 42.53566244631208), + Offset(59.17665170125442, 43.89410522031208), + Offset(59.056814744654424, 43.76982985801208), + Offset(58.93697778815442, 43.64555449561208), + Offset(58.81714083165442, 43.52127913331208), + Offset(58.697303875154425, 43.39700377101208), + Offset(58.57746691865442, 43.272728408712084), + Offset(58.457629962054426, 43.14845304641208), + Offset(58.337793005554424, 43.02417768411208), + Offset(58.21795604905442, 42.899902321712084), + Offset(58.09811909255442, 42.77562695941208), + Offset(57.978282136054425, 42.65135159711208), + Offset(57.85844517945442, 42.52707623481208), + Offset(57.738608222954426, 42.40280087251208), + Offset(57.618771266454424, 42.27852551011208), + Offset(57.49893430995442, 42.15425014781208), + Offset(57.379097353354425, 42.02997478551208), + Offset(57.25926039685442, 41.90569942321208), + Offset(57.13942344035442, 41.78142406091208), + Offset(57.019586483854425, 41.65714869851208), + Offset(56.89974952735442, 41.53287333621208), + Offset(56.77991257075442, 41.40859797391208), + Offset(56.660075614254424, 41.28432261161208), + Offset(56.54023865775442, 41.16004724931208), + Offset(56.42040170125442, 41.03577188701208), + Offset(56.30056474465442, 40.91149652461208), + Offset(56.18072778815442, 40.78722116231208), + Offset(56.060890831654426, 40.66294580001208), + Offset(55.941053875154424, 40.53867043771208), + Offset(55.82121691865442, 40.41439507541208), + Offset(55.701379962054425, 40.29011971301208), + Offset(55.58154300555442, 40.16584435071208), + ], + <Offset>[ + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(36.79758712071989, 10.265747120719887), + Offset(37.238129263257726, 10.723555777147723), + Offset(39.39711980956916, 13.11997804449917), + Offset(41.55676704083787, 15.817488374127876), + Offset(43.717269309745554, 18.90703080962556), + Offset(45.878961386319546, 22.542096324509547), + Offset(48.04251149026888, 27.02906167480888), + Offset(50.209827104462946, 33.242501749162955), + Offset(52.38385971191208, 42.53566244631208), + Offset(53.70548565511208, 43.89410522031208), + Offset(53.58564869851208, 43.76982985801208), + Offset(53.46581174201208, 43.64555449561208), + Offset(53.34597478551208, 43.52127913331208), + Offset(53.22613782901208, 43.39700377101208), + Offset(53.10630087251208, 43.272728408712084), + Offset(52.98646391591208, 43.14845304641208), + Offset(52.86662695941208, 43.02417768411208), + Offset(52.74679000291208, 42.899902321712084), + Offset(52.626953046412076, 42.77562695941208), + Offset(52.50711608991208, 42.65135159711208), + Offset(52.38727913331208, 42.52707623481208), + Offset(52.26744217681208, 42.40280087251208), + Offset(52.14760522031208, 42.27852551011208), + Offset(52.02776826381208, 42.15425014781208), + Offset(51.90793130721208, 42.02997478551208), + Offset(51.78809435071208, 41.90569942321208), + Offset(51.66825739421208, 41.78142406091208), + Offset(51.54842043771208, 41.65714869851208), + Offset(51.42858348121208, 41.53287333621208), + Offset(51.308746524612076, 41.40859797391208), + Offset(51.18890956811208, 41.28432261161208), + Offset(51.06907261161208, 41.16004724931208), + Offset(50.949235655112076, 41.03577188701208), + Offset(50.82939869851208, 40.91149652461208), + Offset(50.70956174201208, 40.78722116231208), + Offset(50.58972478551208, 40.66294580001208), + Offset(50.46988782901208, 40.53867043771208), + Offset(50.35005087251208, 40.41439507541208), + Offset(50.23021391591208, 40.29011971301208), + Offset(50.11037695941208, 40.16584435071208), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.353739454706773, 10.265747120719887), + Offset(22.79696811306153, 10.723555777147723), + Offset(25.05352936751872, 13.11997804449917), + Offset(27.476677698318877, 15.817488374127876), + Offset(30.11673095020605, 18.90703080962556), + Offset(33.058613156286526, 22.542096324509547), + Offset(36.47183754013589, 27.02906167480888), + Offset(40.84029201404956, 33.242501749162955), + Offset(46.91270529296772, 42.53566244631208), + Offset(48.23433123616772, 43.89410522031208), + Offset(48.11449427956772, 43.76982985801208), + Offset(47.99465732306772, 43.64555449561208), + Offset(47.87482036656772, 43.52127913331208), + Offset(47.75498341006772, 43.39700377101208), + Offset(47.63514645356772, 43.272728408712084), + Offset(47.515309496967724, 43.14845304641208), + Offset(47.39547254046772, 43.02417768411208), + Offset(47.27563558396772, 42.899902321712084), + Offset(47.15579862746772, 42.77562695941208), + Offset(47.03596167096772, 42.65135159711208), + Offset(46.91612471436772, 42.52707623481208), + Offset(46.796287757867724, 42.40280087251208), + Offset(46.67645080136772, 42.27852551011208), + Offset(46.55661384486772, 42.15425014781208), + Offset(46.43677688826772, 42.02997478551208), + Offset(46.31693993176772, 41.90569942321208), + Offset(46.19710297526772, 41.78142406091208), + Offset(46.07726601876772, 41.65714869851208), + Offset(45.95742906226772, 41.53287333621208), + Offset(45.83759210566772, 41.40859797391208), + Offset(45.71775514916772, 41.28432261161208), + Offset(45.59791819266772, 41.16004724931208), + Offset(45.47808123616772, 41.03577188701208), + Offset(45.35824427956772, 40.91149652461208), + Offset(45.23840732306772, 40.78722116231208), + Offset(45.118570366567724, 40.66294580001208), + Offset(44.99873341006772, 40.53867043771208), + Offset(44.87889645356772, 40.41439507541208), + Offset(44.75905949696772, 40.29011971301208), + Offset(44.63922254046772, 40.16584435071208), + ], + <Offset>[ + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(10.64574712071989, 21.973739454706777), + Offset(11.091153433347728, 22.429370456861534), + Offset(13.42680421639917, 24.74670319561873), + Offset(16.063543061627875, 27.230623010818885), + Offset(19.09231401272556, 29.93144774710606), + Offset(22.666608043309548, 32.93410143748653), + Offset(27.09280190920888, 36.40809730573589), + Offset(33.24547049916295, 40.83732326404956), + Offset(42.47785971191208, 46.97050802736772), + Offset(43.79948565511208, 48.32895080136772), + Offset(43.67964869851208, 48.20467543906772), + Offset(43.55981174201208, 48.08040007666772), + Offset(43.43997478551208, 47.95612471436772), + Offset(43.32013782901208, 47.83184935206772), + Offset(43.20030087251208, 47.707573989767724), + Offset(43.080463915912084, 47.58329862746772), + Offset(42.96062695941208, 47.45902326516772), + Offset(42.84079000291208, 47.334747902767724), + Offset(42.72095304641208, 47.21047254046772), + Offset(42.60111608991208, 47.08619717816772), + Offset(42.48127913331208, 46.96192181586772), + Offset(42.36144217681208, 46.83764645356772), + Offset(42.24160522031208, 46.71337109116772), + Offset(42.12176826381208, 46.58909572886772), + Offset(42.00193130721208, 46.46482036656772), + Offset(41.88209435071208, 46.34054500426772), + Offset(41.76225739421208, 46.21626964196772), + Offset(41.64242043771208, 46.09199427956772), + Offset(41.52258348121208, 45.96771891726772), + Offset(41.40274652461208, 45.84344355496772), + Offset(41.28290956811208, 45.71916819266772), + Offset(41.16307261161208, 45.59489283036772), + Offset(41.04323565511208, 45.47061746806772), + Offset(40.92339869851208, 45.34634210566772), + Offset(40.80356174201208, 45.22206674336772), + Offset(40.683724785512084, 45.09779138106772), + Offset(40.56388782901208, 44.97351601876772), + Offset(40.44405087251208, 44.84924065646772), + Offset(40.32421391591208, 44.72496529406772), + Offset(40.20437695941208, 44.60068993176772), + ], + <Offset>[ + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(10.64574712071989, 36.41758712071989), + Offset(11.091153433347728, 36.87053160705773), + Offset(13.42680421639917, 39.09029363766917), + Offset(16.063543061627875, 41.31071235333788), + Offset(19.09231401272556, 43.53198610664556), + Offset(22.666608043309548, 45.75444966751955), + Offset(27.09280190920888, 47.97877125586888), + Offset(33.24547049916295, 50.20685835446295), + Offset(42.47785971191208, 52.44166244631208), + Offset(43.79948565511208, 53.800105220312076), + Offset(43.67964869851208, 53.67582985801208), + Offset(43.55981174201208, 53.55155449561208), + Offset(43.43997478551208, 53.42727913331208), + Offset(43.32013782901208, 53.30300377101208), + Offset(43.20030087251208, 53.17872840871208), + Offset(43.080463915912084, 53.05445304641208), + Offset(42.96062695941208, 52.93017768411208), + Offset(42.84079000291208, 52.80590232171208), + Offset(42.72095304641208, 52.68162695941208), + Offset(42.60111608991208, 52.55735159711208), + Offset(42.48127913331208, 52.43307623481208), + Offset(42.36144217681208, 52.30880087251208), + Offset(42.24160522031208, 52.18452551011208), + Offset(42.12176826381208, 52.06025014781208), + Offset(42.00193130721208, 51.93597478551208), + Offset(41.88209435071208, 51.811699423212076), + Offset(41.76225739421208, 51.68742406091208), + Offset(41.64242043771208, 51.56314869851208), + Offset(41.52258348121208, 51.438873336212076), + Offset(41.40274652461208, 51.31459797391208), + Offset(41.28290956811208, 51.19032261161208), + Offset(41.16307261161208, 51.06604724931208), + Offset(41.04323565511208, 50.94177188701208), + Offset(40.92339869851208, 50.81749652461208), + Offset(40.80356174201208, 50.69322116231208), + Offset(40.683724785512084, 50.56894580001208), + Offset(40.56388782901208, 50.44467043771208), + Offset(40.44405087251208, 50.32039507541208), + Offset(40.32421391591208, 50.19611971301208), + Offset(40.20437695941208, 50.07184435071208), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(10.64574712071989, 50.861465482535664), + Offset(11.091153433347728, 51.311723447347255), + Offset(13.42680421639917, 53.433914562457446), + Offset(16.063543061627875, 55.39083161860695), + Offset(19.09231401272556, 57.13255336980211), + Offset(22.666608043309548, 58.574825143123725), + Offset(27.09280190920888, 59.54946979578796), + Offset(33.24547049916295, 59.5764133568421), + Offset(42.47785971191208, 57.91282849245442), + Offset(43.79948565511208, 59.27127126645442), + Offset(43.67964869851208, 59.14699590415442), + Offset(43.55981174201208, 59.022720541754424), + Offset(43.43997478551208, 58.89844517945442), + Offset(43.32013782901208, 58.77416981715442), + Offset(43.20030087251208, 58.649894454854426), + Offset(43.080463915912084, 58.52561909255442), + Offset(42.96062695941208, 58.401343730254425), + Offset(42.84079000291208, 58.277068367854426), + Offset(42.72095304641208, 58.15279300555442), + Offset(42.60111608991208, 58.028517643254425), + Offset(42.48127913331208, 57.90424228095442), + Offset(42.36144217681208, 57.779966918654424), + Offset(42.24160522031208, 57.655691556254425), + Offset(42.12176826381208, 57.53141619395442), + Offset(42.00193130721208, 57.407140831654424), + Offset(41.88209435071208, 57.28286546935442), + Offset(41.76225739421208, 57.15859010705442), + Offset(41.64242043771208, 57.034314744654424), + Offset(41.52258348121208, 56.91003938235442), + Offset(41.40274652461208, 56.78576402005442), + Offset(41.28290956811208, 56.661488657754425), + Offset(41.16307261161208, 56.53721329545442), + Offset(41.04323565511208, 56.412937933154424), + Offset(40.92339869851208, 56.288662570754425), + Offset(40.80356174201208, 56.16438720845442), + Offset(40.683724785512084, 56.040111846154424), + Offset(40.56388782901208, 55.91583648385442), + Offset(40.44405087251208, 55.79156112155442), + Offset(40.32421391591208, 55.667285759154424), + Offset(40.20437695941208, 55.54301039685442), + ], + <Offset>[ + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.35373945470678, 62.569427120719894), + Offset(22.79696811306154, 63.01750743696773), + Offset(25.053529367518728, 65.06060923083916), + Offset(27.476677698318884, 66.80393633254788), + Offset(30.11673095020606, 68.15694140366556), + Offset(33.05861315628653, 68.96680301052955), + Offset(36.471837540135894, 68.92848083692888), + Offset(40.84029201404956, 67.17121495976295), + Offset(46.91270529296772, 62.347662446312086), + Offset(48.23433123616772, 63.70610522031208), + Offset(48.11449427956772, 63.581829858012085), + Offset(47.99465732306772, 63.45755449561209), + Offset(47.87482036656772, 63.33327913331208), + Offset(47.75498341006772, 63.209003771012085), + Offset(47.63514645356772, 63.08472840871209), + Offset(47.515309496967724, 62.960453046412084), + Offset(47.39547254046772, 62.83617768411209), + Offset(47.27563558396772, 62.71190232171209), + Offset(47.15579862746772, 62.587626959412084), + Offset(47.03596167096772, 62.46335159711209), + Offset(46.91612471436772, 62.33907623481208), + Offset(46.796287757867724, 62.214800872512086), + Offset(46.67645080136772, 62.09052551011209), + Offset(46.55661384486772, 61.96625014781208), + Offset(46.43677688826772, 61.841974785512086), + Offset(46.31693993176772, 61.71769942321208), + Offset(46.19710297526772, 61.593424060912085), + Offset(46.07726601876772, 61.469148698512086), + Offset(45.95742906226772, 61.34487333621208), + Offset(45.83759210566772, 61.220597973912085), + Offset(45.71775514916772, 61.09632261161209), + Offset(45.59791819266772, 60.972047249312084), + Offset(45.47808123616772, 60.84777188701209), + Offset(45.35824427956772, 60.72349652461209), + Offset(45.23840732306772, 60.599221162312084), + Offset(45.118570366567724, 60.47494580001209), + Offset(44.99873341006772, 60.35067043771208), + Offset(44.87889645356772, 60.226395075412086), + Offset(44.75905949696772, 60.10211971301209), + Offset(44.63922254046772, 59.97784435071208), + ], + <Offset>[ + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(36.79758712071989, 62.569427120719894), + Offset(37.23812926325773, 63.01750743696773), + Offset(39.39711980956917, 65.06060923083916), + Offset(41.556767040837876, 66.80393633254788), + Offset(43.71726930974556, 68.15694140366556), + Offset(45.878961386319546, 68.96680301052955), + Offset(48.04251149026888, 68.92848083692888), + Offset(50.20982710446295, 67.17121495976295), + Offset(52.38385971191208, 62.347662446312086), + Offset(53.70548565511208, 63.70610522031208), + Offset(53.58564869851208, 63.581829858012085), + Offset(53.46581174201208, 63.45755449561209), + Offset(53.34597478551208, 63.33327913331208), + Offset(53.22613782901208, 63.209003771012085), + Offset(53.10630087251208, 63.08472840871209), + Offset(52.98646391591208, 62.960453046412084), + Offset(52.86662695941208, 62.83617768411209), + Offset(52.74679000291208, 62.71190232171209), + Offset(52.626953046412076, 62.587626959412084), + Offset(52.50711608991208, 62.46335159711209), + Offset(52.38727913331208, 62.33907623481208), + Offset(52.26744217681208, 62.214800872512086), + Offset(52.14760522031208, 62.09052551011209), + Offset(52.02776826381208, 61.96625014781208), + Offset(51.90793130721208, 61.841974785512086), + Offset(51.78809435071208, 61.71769942321208), + Offset(51.66825739421208, 61.593424060912085), + Offset(51.54842043771208, 61.469148698512086), + Offset(51.42858348121208, 61.34487333621208), + Offset(51.308746524612076, 61.220597973912085), + Offset(51.18890956811208, 61.09632261161209), + Offset(51.06907261161208, 60.972047249312084), + Offset(50.949235655112076, 60.84777188701209), + Offset(50.82939869851208, 60.72349652461209), + Offset(50.70956174201208, 60.599221162312084), + Offset(50.58972478551208, 60.47494580001209), + Offset(50.46988782901208, 60.35067043771208), + Offset(50.35005087251208, 60.226395075412086), + Offset(50.23021391591208, 60.10211971301209), + Offset(50.11037695941208, 59.97784435071208), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.295335621700225, 62.569427120719894), + Offset(43.73466920094344, 63.01750743696773), + Offset(45.84976632375351, 65.06060923083916), + Offset(47.89087423543939, 66.80393633254788), + Offset(49.835644397996305, 68.15694140366556), + Offset(51.646358026050024, 68.96680301052955), + Offset(53.24772626774939, 68.92848083692888), + Offset(54.42483158224287, 67.17121495976295), + Offset(54.845128083495545, 62.347662446312086), + Offset(56.16675402669554, 63.70610522031208), + Offset(56.046917070095546, 63.581829858012085), + Offset(55.927080113595544, 63.45755449561209), + Offset(55.80724315709554, 63.33327913331208), + Offset(55.68740620059555, 63.209003771012085), + Offset(55.567569244095544, 63.08472840871209), + Offset(55.44773228749555, 62.960453046412084), + Offset(55.327895330995545, 62.83617768411209), + Offset(55.20805837449554, 62.71190232171209), + Offset(55.08822141799554, 62.587626959412084), + Offset(54.968384461495546, 62.46335159711209), + Offset(54.84854750489554, 62.33907623481208), + Offset(54.72871054839555, 62.214800872512086), + Offset(54.608873591895545, 62.09052551011209), + Offset(54.48903663539554, 61.96625014781208), + Offset(54.369199678795546, 61.841974785512086), + Offset(54.249362722295544, 61.71769942321208), + Offset(54.12952576579554, 61.593424060912085), + Offset(54.00968880929555, 61.469148698512086), + Offset(53.889851852795545, 61.34487333621208), + Offset(53.77001489619554, 61.220597973912085), + Offset(53.650177939695546, 61.09632261161209), + Offset(53.53034098319554, 60.972047249312084), + Offset(53.41050402669554, 60.84777188701209), + Offset(53.290667070095544, 60.72349652461209), + Offset(53.17083011359554, 60.599221162312084), + Offset(53.05099315709555, 60.47494580001209), + Offset(52.931156200595545, 60.35067043771208), + Offset(52.81131924409554, 60.226395075412086), + Offset(52.691482287495546, 60.10211971301209), + Offset(52.571645330995544, 59.97784435071208), + ], + <Offset>[ + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.22978548253567, 60.19565945470678), + Offset(49.668015270477255, 60.644181285191536), + Offset(51.743024150267445, 62.70331829332873), + Offset(53.67586907693695, 64.48995036504888), + Offset(55.423609242362105, 65.92176702736606), + Offset(56.91377122015372, 66.85984863111653), + Offset(58.00169390856796, 67.0269036165159), + Offset(58.274431598742105, 65.63138291794957), + Offset(57.093025758054424, 61.44850802736772), + Offset(58.41465170125442, 62.80695080136772), + Offset(58.294814744654424, 62.68267543906772), + Offset(58.17497778815442, 62.55840007666772), + Offset(58.05514083165442, 62.43412471436772), + Offset(57.935303875154425, 62.30984935206772), + Offset(57.81546691865442, 62.185573989767725), + Offset(57.695629962054426, 62.06129862746772), + Offset(57.575793005554424, 61.937023265167724), + Offset(57.45595604905442, 61.812747902767725), + Offset(57.33611909255442, 61.68847254046772), + Offset(57.216282136054424, 61.564197178167724), + Offset(57.09644517945442, 61.43992181586772), + Offset(56.976608222954425, 61.31564645356772), + Offset(56.85677126645442, 61.191371091167724), + Offset(56.73693430995442, 61.06709572886772), + Offset(56.617097353354424, 60.94282036656772), + Offset(56.49726039685442, 60.81854500426772), + Offset(56.37742344035442, 60.69426964196772), + Offset(56.257586483854425, 60.56999427956772), + Offset(56.13774952735442, 60.44571891726772), + Offset(56.01791257075442, 60.32144355496772), + Offset(55.898075614254424, 60.197168192667725), + Offset(55.77823865775442, 60.07289283036772), + Offset(55.65840170125442, 59.948617468067724), + Offset(55.53856474465442, 59.824342105667725), + Offset(55.41872778815442, 59.70006674336772), + Offset(55.298890831654425, 59.575791381067724), + Offset(55.17905387515442, 59.45151601876772), + Offset(55.05921691865442, 59.32724065646772), + Offset(54.939379962054424, 59.202965294067724), + Offset(54.81954300555442, 59.07868993176772), + ], + <Offset>[ + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(54.233688104769875, 56.72214104872773), + Offset(56.27784933131594, 58.80777705090479), + Offset(58.127386565520524, 60.66597275272132), + Offset(59.7235133756984, 62.22802951354025), + Offset(60.96701285572941, 63.37800107878284), + Offset(61.65984238978352, 63.88445209731733), + Offset(61.23667482747795, 63.08673340955032), + Offset(58.822769013668946, 59.962610352808845), + Offset(60.14439495686894, 61.32105312680884), + Offset(60.02455800026895, 61.196777764508845), + Offset(59.904721043768944, 61.072502402108846), + Offset(59.78488408726894, 60.94822703980884), + Offset(59.66504713076895, 60.823951677508845), + Offset(59.545210174268945, 60.69967631520885), + Offset(59.42537321766895, 60.57540095290884), + Offset(59.305536261168946, 60.45112559060885), + Offset(59.185699304668944, 60.32685022820885), + Offset(59.06586234816894, 60.20257486590884), + Offset(58.94602539166895, 60.07829950360885), + Offset(58.82618843506894, 59.95402414130884), + Offset(58.70635147856895, 59.829748779008845), + Offset(58.586514522068946, 59.70547341660885), + Offset(58.46667756556894, 59.58119805430884), + Offset(58.34684060896895, 59.456922692008845), + Offset(58.227003652468944, 59.33264732970884), + Offset(58.10716669596894, 59.208371967408844), + Offset(57.98732973946895, 59.084096605008845), + Offset(57.867492782968945, 58.95982124270884), + Offset(57.74765582636894, 58.835545880408844), + Offset(57.627818869868946, 58.71127051810885), + Offset(57.507981913368944, 58.58699515580884), + Offset(57.38814495686894, 58.462719793508846), + Offset(57.268308000268945, 58.33844443110885), + Offset(57.14847104376894, 58.21416906880884), + Offset(57.02863408726895, 58.089893706508846), + Offset(56.908797130768946, 57.96561834420884), + Offset(56.788960174268944, 57.841342981908845), + Offset(56.66912321766895, 57.717067619508846), + Offset(56.549286261168945, 57.59279225720884), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(53.796307677358, 56.272889593871334), + Offset(54.233688104769875, 56.72214104872773), + Offset(56.27784933131594, 58.80777705090479), + Offset(58.127386565520524, 60.66597275272132), + Offset(59.7235133756984, 62.22802951354025), + Offset(60.96701285572941, 63.37800107878284), + Offset(61.65984238978352, 63.88445209731733), + Offset(61.23667482747795, 63.08673340955032), + Offset(58.822769013668946, 59.962610352808845), + Offset(60.14439495686894, 61.32105312680884), + Offset(60.02455800026895, 61.196777764508845), + Offset(59.904721043768944, 61.072502402108846), + Offset(59.78488408726894, 60.94822703980884), + Offset(59.66504713076895, 60.823951677508845), + Offset(59.545210174268945, 60.69967631520885), + Offset(59.42537321766895, 60.57540095290884), + Offset(59.305536261168946, 60.45112559060885), + Offset(59.185699304668944, 60.32685022820885), + Offset(59.06586234816894, 60.20257486590884), + Offset(58.94602539166895, 60.07829950360885), + Offset(58.82618843506894, 59.95402414130884), + Offset(58.70635147856895, 59.829748779008845), + Offset(58.586514522068946, 59.70547341660885), + Offset(58.46667756556894, 59.58119805430884), + Offset(58.34684060896895, 59.456922692008845), + Offset(58.227003652468944, 59.33264732970884), + Offset(58.10716669596894, 59.208371967408844), + Offset(57.98732973946895, 59.084096605008845), + Offset(57.867492782968945, 58.95982124270884), + Offset(57.74765582636894, 58.835545880408844), + Offset(57.627818869868946, 58.71127051810885), + Offset(57.507981913368944, 58.58699515580884), + Offset(57.38814495686894, 58.462719793508846), + Offset(57.268308000268945, 58.33844443110885), + Offset(57.14847104376894, 58.21416906880884), + Offset(57.02863408726895, 58.089893706508846), + Offset(56.908797130768946, 57.96561834420884), + Offset(56.788960174268944, 57.841342981908845), + Offset(56.66912321766895, 57.717067619508846), + Offset(56.549286261168945, 57.59279225720884), + ], + <Offset>[ + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(57.069606004928445, 53.86609044856987), + Offset(59.094606548002886, 55.97102315941594), + Offset(60.89239811736094, 57.881331878020525), + Offset(62.39435194501161, 59.538230172598404), + Offset(63.48463970399174, 60.8425011369294), + Offset(63.932061433030945, 61.59610215538352), + Offset(63.07663991080549, 61.23370607747795), + Offset(59.89718017699878, 58.880571748068945), + Offset(61.21880612019878, 60.23901452206894), + Offset(61.09896916359878, 60.114739159768945), + Offset(60.97913220709878, 59.990463797368946), + Offset(60.85929525059878, 59.86618843506894), + Offset(60.73945829409878, 59.741913072768945), + Offset(60.61962133759878, 59.61763771046895), + Offset(60.49978438099878, 59.493362348168944), + Offset(60.37994742449878, 59.36908698586895), + Offset(60.26011046799878, 59.24481162346895), + Offset(60.140273511498776, 59.120536261168944), + Offset(60.02043655499878, 58.99626089886895), + Offset(59.90059959839878, 58.87198553656894), + Offset(59.78076264189878, 58.747710174268946), + Offset(59.66092568539878, 58.62343481186895), + Offset(59.54108872889878, 58.49915944956894), + Offset(59.42125177229878, 58.374884087268946), + Offset(59.30141481579878, 58.25060872496894), + Offset(59.18157785929878, 58.126333362668944), + Offset(59.06174090279878, 58.002058000268946), + Offset(58.94190394629878, 57.87778263796894), + Offset(58.822066989698776, 57.753507275668944), + Offset(58.70223003319878, 57.62923191336895), + Offset(58.58239307669878, 57.50495655106894), + Offset(58.46255612019878, 57.380681188768946), + Offset(58.34271916359878, 57.25640582636895), + Offset(58.22288220709878, 57.13213046406894), + Offset(58.10304525059878, 57.007855101768946), + Offset(57.98320829409878, 56.88357973946894), + Offset(57.86337133759878, 56.759304377168945), + Offset(57.74353438099878, 56.635029014768946), + Offset(57.62369742449878, 56.51075365246894), + ], + <Offset>[ + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(56.63275314854878, 53.416307677358), + Offset(57.069606004928445, 53.86609044856987), + Offset(59.094606548002886, 55.97102315941594), + Offset(60.89239811736094, 57.881331878020525), + Offset(62.39435194501161, 59.538230172598404), + Offset(63.48463970399174, 60.8425011369294), + Offset(63.932061433030945, 61.59610215538352), + Offset(63.07663991080549, 61.23370607747795), + Offset(59.89718017699878, 58.880571748068945), + Offset(61.21880612019878, 60.23901452206894), + Offset(61.09896916359878, 60.114739159768945), + Offset(60.97913220709878, 59.990463797368946), + Offset(60.85929525059878, 59.86618843506894), + Offset(60.73945829409878, 59.741913072768945), + Offset(60.61962133759878, 59.61763771046895), + Offset(60.49978438099878, 59.493362348168944), + Offset(60.37994742449878, 59.36908698586895), + Offset(60.26011046799878, 59.24481162346895), + Offset(60.140273511498776, 59.120536261168944), + Offset(60.02043655499878, 58.99626089886895), + Offset(59.90059959839878, 58.87198553656894), + Offset(59.78076264189878, 58.747710174268946), + Offset(59.66092568539878, 58.62343481186895), + Offset(59.54108872889878, 58.49915944956894), + Offset(59.42125177229878, 58.374884087268946), + Offset(59.30141481579878, 58.25060872496894), + Offset(59.18157785929878, 58.126333362668944), + Offset(59.06174090279878, 58.002058000268946), + Offset(58.94190394629878, 57.87778263796894), + Offset(58.822066989698776, 57.753507275668944), + Offset(58.70223003319878, 57.62923191336895), + Offset(58.58239307669878, 57.50495655106894), + Offset(58.46255612019878, 57.380681188768946), + Offset(58.34271916359878, 57.25640582636895), + Offset(58.22288220709878, 57.13213046406894), + Offset(58.10304525059878, 57.007855101768946), + Offset(57.98320829409878, 56.88357973946894), + Offset(57.86337133759878, 56.759304377168945), + Offset(57.74353438099878, 56.635029014768946), + Offset(57.62369742449878, 56.51075365246894), + ], + ), + _PathClose( + ), + _PathMoveTo( + <Offset>[ + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(37.238129263257726, 54.34772049679427), + Offset(39.39711980956916, 53.40971455122347), + Offset(41.55676704083787, 52.38323260637452), + Offset(43.717269309745554, 51.34517214659979), + Offset(45.878961386319546, 50.4025549847652), + Offset(48.04251149026888, 49.72174872023579), + Offset(50.209827104462946, 50.28103042236462), + Offset(52.38385971191208, 52.48497375612058), + Offset(53.70548565511208, 53.84341653012058), + Offset(53.58564869851208, 53.71914116782058), + Offset(53.46581174201208, 53.59486580542058), + Offset(53.34597478551208, 53.47059044312058), + Offset(53.22613782901208, 53.34631508082058), + Offset(53.10630087251208, 53.222039718520584), + Offset(52.98646391591208, 53.09776435622058), + Offset(52.86662695941208, 52.97348899392058), + Offset(52.74679000291208, 52.849213631520584), + Offset(52.626953046412076, 52.72493826922058), + Offset(52.50711608991208, 52.60066290692058), + Offset(52.38727913331208, 52.47638754462058), + Offset(52.26744217681208, 52.35211218232058), + Offset(52.14760522031208, 52.22783681992058), + Offset(52.02776826381208, 52.10356145762058), + Offset(51.90793130721208, 51.97928609532058), + Offset(51.78809435071208, 51.85501073302058), + Offset(51.66825739421208, 51.73073537072058), + Offset(51.54842043771208, 51.60646000832058), + Offset(51.42858348121208, 51.48218464602058), + Offset(51.308746524612076, 51.35790928372058), + Offset(51.18890956811208, 51.233633921420584), + Offset(51.06907261161208, 51.10935855912058), + Offset(50.949235655112076, 50.98508319682058), + Offset(50.82939869851208, 50.860807834420584), + Offset(50.70956174201208, 50.73653247212058), + Offset(50.58972478551208, 50.61225710982058), + Offset(50.46988782901208, 50.48798174752058), + Offset(50.35005087251208, 50.36370638522058), + Offset(50.23021391591208, 50.23943102282058), + Offset(50.11037695941208, 50.11515566052058), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(26.79953506506211, 54.522707120719886), + Offset(26.79953506506211, 54.522707120719886), + Offset(26.79953506506211, 54.522707120719886), + Offset(26.79953506506211, 54.522707120719886), + Offset(26.79953506506211, 54.522707120719886), + Offset(26.79953506506211, 54.522707120719886), + Offset(26.79953506506211, 54.522707120719886), + Offset(26.79953506506211, 54.522707120719886), + Offset(26.79953506506211, 54.522707120719886), + Offset(26.79953506506211, 54.522707120719886), + Offset(27.586834836005405, 54.34772049679427), + Offset(31.489615606172315, 53.40971455122347), + Offset(35.442274116666454, 52.38323260637452), + Offset(39.402653738040314, 51.34517214659979), + Offset(43.31217425963652, 50.4025549847652), + Offset(47.08000098098459, 49.72174872023579), + Offset(50.16886819340391, 50.28103042236462), + Offset(52.35994256713666, 52.48497375612058), + Offset(53.68156851033666, 53.84341653012058), + Offset(53.561731553736664, 53.71914116782058), + Offset(53.44189459723666, 53.59486580542058), + Offset(53.32205764073666, 53.47059044312058), + Offset(53.202220684236664, 53.34631508082058), + Offset(53.08238372773666, 53.222039718520584), + Offset(52.962546771136665, 53.09776435622058), + Offset(52.84270981463666, 52.97348899392058), + Offset(52.72287285813666, 52.849213631520584), + Offset(52.60303590163666, 52.72493826922058), + Offset(52.483198945136664, 52.60066290692058), + Offset(52.36336198853666, 52.47638754462058), + Offset(52.243525032036665, 52.35211218232058), + Offset(52.12368807553666, 52.22783681992058), + Offset(52.00385111903666, 52.10356145762058), + Offset(51.884014162436664, 51.97928609532058), + Offset(51.76417720593666, 51.85501073302058), + Offset(51.64434024943666, 51.73073537072058), + Offset(51.524503292936664, 51.60646000832058), + Offset(51.40466633643666, 51.48218464602058), + Offset(51.28482937983666, 51.35790928372058), + Offset(51.16499242333666, 51.233633921420584), + Offset(51.04515546683666, 51.10935855912058), + Offset(50.92531851033666, 50.98508319682058), + Offset(50.80548155373666, 50.860807834420584), + Offset(50.68564459723666, 50.73653247212058), + Offset(50.565807640736665, 50.61225710982058), + Offset(50.44597068423666, 50.48798174752058), + Offset(50.32613372773666, 50.36370638522058), + Offset(50.206296771136664, 50.23943102282058), + Offset(50.08645981463666, 50.11515566052058), + ], + <Offset>[ + Offset(18.692467120719886, 46.41563917637766), + Offset(18.692467120719886, 46.41563917637766), + Offset(18.692467120719886, 46.41563917637766), + Offset(18.692467120719886, 46.41563917637766), + Offset(18.692467120719886, 46.41563917637766), + Offset(18.692467120719886, 46.41563917637766), + Offset(18.692467120719886, 46.41563917637766), + Offset(18.692467120719886, 46.41563917637766), + Offset(18.692467120719886, 46.41563917637766), + Offset(18.692467120719886, 46.41563917637766), + Offset(19.76094037350107, 46.52182603428993), + Offset(25.077698896014848, 46.99779784106601), + Offset(30.48424678780122, 47.42520527750929), + Offset(35.90408326978374, 47.84660167834321), + Offset(41.23085606905603, 48.32123679418471), + Offset(46.299534025885855, 48.94128176514349), + Offset(50.13565503655109, 50.247817265511806), + Offset(52.34054840209764, 52.46557959108156), + Offset(53.662174345297636, 53.824022365081554), + Offset(53.54233738869764, 53.69974700278156), + Offset(53.42250043219764, 53.57547164038156), + Offset(53.302663475697635, 53.451196278081554), + Offset(53.18282651919764, 53.32692091578156), + Offset(53.06298956269764, 53.20264555348156), + Offset(52.94315260609764, 53.078370191181556), + Offset(52.82331564959764, 52.95409482888156), + Offset(52.70347869309764, 52.82981946648156), + Offset(52.583641736597635, 52.705544104181556), + Offset(52.46380478009764, 52.58126874188156), + Offset(52.343967823497636, 52.456993379581554), + Offset(52.22413086699764, 52.33271801728156), + Offset(52.10429391049764, 52.20844265488156), + Offset(51.984456953997636, 52.084167292581554), + Offset(51.86461999739764, 51.95989193028156), + Offset(51.74478304089764, 51.83561656798155), + Offset(51.624946084397635, 51.711341205681556), + Offset(51.50510912789764, 51.58706584328156), + Offset(51.38527217139764, 51.46279048098155), + Offset(51.265435214797634, 51.338515118681556), + Offset(51.14559825829764, 51.21423975638156), + Offset(51.02576130179764, 51.089964394081555), + Offset(50.905924345297635, 50.96568903178156), + Offset(50.78608738869764, 50.84141366938156), + Offset(50.666250432197636, 50.717138307081555), + Offset(50.54641347569764, 50.59286294478156), + Offset(50.42657651919764, 50.468587582481554), + Offset(50.306739562697636, 50.34431222018156), + Offset(50.18690260609764, 50.22003685778156), + Offset(50.06706564959764, 50.095761495481554), + ], + <Offset>[ + Offset(18.692467120719886, 36.41758712071989), + Offset(18.692467120719886, 36.41758712071989), + Offset(18.692467120719886, 36.41758712071989), + Offset(18.692467120719886, 36.41758712071989), + Offset(18.692467120719886, 36.41758712071989), + Offset(18.692467120719886, 36.41758712071989), + Offset(18.692467120719886, 36.41758712071989), + Offset(18.692467120719886, 36.41758712071989), + Offset(18.692467120719886, 36.41758712071989), + Offset(18.692467120719886, 36.41758712071989), + Offset(19.76094037350107, 36.87053160703761), + Offset(25.077698896014848, 39.09029363766916), + Offset(30.48424678780122, 41.31071235333787), + Offset(35.90408326978374, 43.53198610663798), + Offset(41.23085606905603, 45.75444966750169), + Offset(46.299534025885855, 47.97877125585276), + Offset(50.13565503655109, 50.20685835445277), + Offset(52.34054840209764, 52.44166244630614), + Offset(53.662174345297636, 53.800105220306136), + Offset(53.54233738869764, 53.67582985800614), + Offset(53.42250043219764, 53.55155449560614), + Offset(53.302663475697635, 53.427279133306136), + Offset(53.18282651919764, 53.30300377100614), + Offset(53.06298956269764, 53.17872840870614), + Offset(52.94315260609764, 53.05445304640614), + Offset(52.82331564959764, 52.93017768410614), + Offset(52.70347869309764, 52.80590232170614), + Offset(52.583641736597635, 52.68162695940614), + Offset(52.46380478009764, 52.55735159710614), + Offset(52.343967823497636, 52.43307623480614), + Offset(52.22413086699764, 52.30880087250614), + Offset(52.10429391049764, 52.18452551010614), + Offset(51.984456953997636, 52.06025014780614), + Offset(51.86461999739764, 51.93597478550614), + Offset(51.74478304089764, 51.811699423206136), + Offset(51.624946084397635, 51.68742406090614), + Offset(51.50510912789764, 51.56314869850614), + Offset(51.38527217139764, 51.438873336206136), + Offset(51.265435214797634, 51.31459797390614), + Offset(51.14559825829764, 51.19032261160614), + Offset(51.02576130179764, 51.06604724930614), + Offset(50.905924345297635, 50.94177188700614), + Offset(50.78608738869764, 50.81749652460614), + Offset(50.666250432197636, 50.69322116230614), + Offset(50.54641347569764, 50.56894580000614), + Offset(50.42657651919764, 50.44467043770614), + Offset(50.306739562697636, 50.32039507540614), + Offset(50.18690260609764, 50.19611971300614), + Offset(50.06706564959764, 50.07184435070614), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.692467120719886, 26.419565760864774), + Offset(18.692467120719886, 26.419565760864774), + Offset(18.692467120719886, 26.419565760864774), + Offset(18.692467120719886, 26.419565760864774), + Offset(18.692467120719886, 26.419565760864774), + Offset(18.692467120719886, 26.419565760864774), + Offset(18.692467120719886, 26.419565760864774), + Offset(18.692467120719886, 26.419565760864774), + Offset(18.692467120719886, 26.419565760864774), + Offset(18.692467120719886, 26.419565760864774), + Offset(19.76094037350107, 27.219266804248566), + Offset(25.077698896014848, 31.18281367228795), + Offset(30.48424678780122, 35.1962381308779), + Offset(35.90408326978374, 39.21738368206378), + Offset(41.23085606905603, 43.187670298244306), + Offset(46.299534025885855, 47.016263564148105), + Offset(50.13565503655109, 50.165899443393734), + Offset(52.34054840209764, 52.417745301530715), + Offset(53.662174345297636, 53.77618807553071), + Offset(53.54233738869764, 53.651912713230715), + Offset(53.42250043219764, 53.527637350830716), + Offset(53.302663475697635, 53.40336198853072), + Offset(53.18282651919764, 53.27908662623072), + Offset(53.06298956269764, 53.154811263930725), + Offset(52.94315260609764, 53.030535901630714), + Offset(52.82331564959764, 52.90626053933072), + Offset(52.70347869309764, 52.78198517693072), + Offset(52.583641736597635, 52.65770981463072), + Offset(52.46380478009764, 52.533434452330724), + Offset(52.343967823497636, 52.40915909003071), + Offset(52.22413086699764, 52.284883727730715), + Offset(52.10429391049764, 52.16060836533072), + Offset(51.984456953997636, 52.03633300303072), + Offset(51.86461999739764, 51.91205764073072), + Offset(51.74478304089764, 51.78778227843071), + Offset(51.624946084397635, 51.663506916130714), + Offset(51.50510912789764, 51.539231553730716), + Offset(51.38527217139764, 51.41495619143072), + Offset(51.265435214797634, 51.29068082913072), + Offset(51.14559825829764, 51.166405466830724), + Offset(51.02576130179764, 51.04213010453071), + Offset(50.905924345297635, 50.917854742230716), + Offset(50.78608738869764, 50.79357937983072), + Offset(50.666250432197636, 50.66930401753072), + Offset(50.54641347569764, 50.54502865523072), + Offset(50.42657651919764, 50.42075329293071), + Offset(50.306739562697636, 50.296477930630715), + Offset(50.18690260609764, 50.172202568230716), + Offset(50.06706564959764, 50.04792720593072), + ], + <Offset>[ + Offset(26.79953506506211, 18.312467120719884), + Offset(26.79953506506211, 18.312467120719884), + Offset(26.79953506506211, 18.312467120719884), + Offset(26.79953506506211, 18.312467120719884), + Offset(26.79953506506211, 18.312467120719884), + Offset(26.79953506506211, 18.312467120719884), + Offset(26.79953506506211, 18.312467120719884), + Offset(26.79953506506211, 18.312467120719884), + Offset(26.79953506506211, 18.312467120719884), + Offset(26.79953506506211, 18.312467120719884), + Offset(27.58683483600541, 19.393342717280955), + Offset(31.489615606172315, 24.77087272411485), + Offset(35.442274116666454, 30.23819210030122), + Offset(39.40265373804032, 35.71880006667617), + Offset(43.31217425963652, 41.106344350238174), + Offset(47.08000098097815, 46.23579379146974), + Offset(50.16886819340391, 50.13268628654091), + Offset(52.35994256713666, 52.3983511364917), + Offset(53.68156851033666, 53.756793910491695), + Offset(53.561731553736664, 53.6325185481917), + Offset(53.44189459723666, 53.5082431857917), + Offset(53.32205764073666, 53.38396782349169), + Offset(53.202220684236664, 53.25969246119169), + Offset(53.08238372773666, 53.13541709889169), + Offset(52.962546771136665, 53.011141736591696), + Offset(52.84270981463666, 52.8868663742917), + Offset(52.72287285813666, 52.7625910118917), + Offset(52.60303590163666, 52.63831564959169), + Offset(52.483198945136664, 52.51404028729169), + Offset(52.36336198853666, 52.389764924991695), + Offset(52.243525032036665, 52.2654895626917), + Offset(52.12368807553666, 52.1412142002917), + Offset(52.00385111903666, 52.01693883799169), + Offset(51.884014162436664, 51.89266347569169), + Offset(51.76417720593666, 51.768388113391694), + Offset(51.64434024943666, 51.6441127510917), + Offset(51.524503292936664, 51.5198373886917), + Offset(51.40466633643666, 51.39556202639169), + Offset(51.28482937983666, 51.27128666409169), + Offset(51.16499242333666, 51.14701130179169), + Offset(51.04515546683666, 51.022735939491696), + Offset(50.92531851033666, 50.8984605771917), + Offset(50.80548155373666, 50.7741852147917), + Offset(50.68564459723666, 50.64990985249169), + Offset(50.565807640736665, 50.52563449019169), + Offset(50.44597068423666, 50.401359127891695), + Offset(50.32613372773666, 50.2770837655917), + Offset(50.206296771136664, 50.1528084031917), + Offset(50.08645981463666, 50.02853304089169), + ], + <Offset>[ + Offset(36.79758712071989, 18.312467120719884), + Offset(36.79758712071989, 18.312467120719884), + Offset(36.79758712071989, 18.312467120719884), + Offset(36.79758712071989, 18.312467120719884), + Offset(36.79758712071989, 18.312467120719884), + Offset(36.79758712071989, 18.312467120719884), + Offset(36.79758712071989, 18.312467120719884), + Offset(36.79758712071989, 18.312467120719884), + Offset(36.79758712071989, 18.312467120719884), + Offset(36.79758712071989, 18.312467120719884), + Offset(37.238129263257726, 19.393342717280955), + Offset(39.39711980956916, 24.77087272411485), + Offset(41.55676704083787, 30.23819210030122), + Offset(43.717269309745554, 35.71880006667617), + Offset(45.878961386319546, 41.106344350238174), + Offset(48.04251149026888, 46.23579379146974), + Offset(50.209827104462946, 50.13268628654091), + Offset(52.38385971191208, 52.3983511364917), + Offset(53.70548565511208, 53.756793910491695), + Offset(53.58564869851208, 53.6325185481917), + Offset(53.46581174201208, 53.5082431857917), + Offset(53.34597478551208, 53.38396782349169), + Offset(53.22613782901208, 53.25969246119169), + Offset(53.10630087251208, 53.13541709889169), + Offset(52.98646391591208, 53.011141736591696), + Offset(52.86662695941208, 52.8868663742917), + Offset(52.74679000291208, 52.7625910118917), + Offset(52.626953046412076, 52.63831564959169), + Offset(52.50711608991208, 52.51404028729169), + Offset(52.38727913331208, 52.389764924991695), + Offset(52.26744217681208, 52.2654895626917), + Offset(52.14760522031208, 52.1412142002917), + Offset(52.02776826381208, 52.01693883799169), + Offset(51.90793130721208, 51.89266347569169), + Offset(51.78809435071208, 51.768388113391694), + Offset(51.66825739421208, 51.6441127510917), + Offset(51.54842043771208, 51.5198373886917), + Offset(51.42858348121208, 51.39556202639169), + Offset(51.308746524612076, 51.27128666409169), + Offset(51.18890956811208, 51.14701130179169), + Offset(51.06907261161208, 51.022735939491696), + Offset(50.949235655112076, 50.8984605771917), + Offset(50.82939869851208, 50.7741852147917), + Offset(50.70956174201208, 50.64990985249169), + Offset(50.58972478551208, 50.52563449019169), + Offset(50.46988782901208, 50.401359127891695), + Offset(50.35005087251208, 50.2770837655917), + Offset(50.23021391591208, 50.1528084031917), + Offset(50.11037695941208, 50.02853304089169), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(46.79563917637766, 18.312467120719884), + Offset(46.79563917637766, 18.312467120719884), + Offset(46.79563917637766, 18.312467120719884), + Offset(46.79563917637766, 18.312467120719884), + Offset(46.79563917637766, 18.312467120719884), + Offset(46.79563917637766, 18.312467120719884), + Offset(46.79563917637766, 18.312467120719884), + Offset(46.79563917637766, 18.312467120719884), + Offset(46.79563917637766, 18.312467120719884), + Offset(46.79563917637766, 18.312467120719884), + Offset(46.88942369051005, 19.393342717280955), + Offset(47.30462401296601, 24.77087272411485), + Offset(47.67125996500929, 30.23819210030122), + Offset(48.031884881450786, 35.71880006667617), + Offset(48.44574851300257, 41.106344350238174), + Offset(49.005021999553165, 46.23579379146974), + Offset(50.25078601552198, 50.13268628654091), + Offset(52.4077768566875, 52.3983511364917), + Offset(53.729402799887495, 53.756793910491695), + Offset(53.6095658432875, 53.6325185481917), + Offset(53.489728886787496, 53.5082431857917), + Offset(53.369891930287494, 53.38396782349169), + Offset(53.2500549737875, 53.25969246119169), + Offset(53.1302180172875, 53.13541709889169), + Offset(53.0103810606875, 53.011141736591696), + Offset(52.8905441041875, 52.8868663742917), + Offset(52.770707147687496, 52.7625910118917), + Offset(52.650870191187494, 52.63831564959169), + Offset(52.5310332346875, 52.51404028729169), + Offset(52.411196278087495, 52.389764924991695), + Offset(52.2913593215875, 52.2654895626917), + Offset(52.1715223650875, 52.1412142002917), + Offset(52.051685408587495, 52.01693883799169), + Offset(51.9318484519875, 51.89266347569169), + Offset(51.812011495487496, 51.768388113391694), + Offset(51.692174538987494, 51.6441127510917), + Offset(51.5723375824875, 51.5198373886917), + Offset(51.4525006259875, 51.39556202639169), + Offset(51.33266366938749, 51.27128666409169), + Offset(51.2128267128875, 51.14701130179169), + Offset(51.092989756387496, 51.022735939491696), + Offset(50.973152799887494, 50.8984605771917), + Offset(50.8533158432875, 50.7741852147917), + Offset(50.733478886787495, 50.64990985249169), + Offset(50.6136419302875, 50.52563449019169), + Offset(50.4938049737875, 50.401359127891695), + Offset(50.373968017287496, 50.2770837655917), + Offset(50.2541310606875, 50.1528084031917), + Offset(50.1342941041875, 50.02853304089169), + ], + <Offset>[ + Offset(54.90270712071989, 26.419565760864774), + Offset(54.90270712071989, 26.419565760864774), + Offset(54.90270712071989, 26.419565760864774), + Offset(54.90270712071989, 26.419565760864774), + Offset(54.90270712071989, 26.419565760864774), + Offset(54.90270712071989, 26.419565760864774), + Offset(54.90270712071989, 26.419565760864774), + Offset(54.90270712071989, 26.419565760864774), + Offset(54.90270712071989, 26.419565760864774), + Offset(54.90270712071989, 26.419565760864774), + Offset(54.71531815301439, 27.21926680424857), + Offset(53.71654072312347, 31.18281367228795), + Offset(52.62928729387452, 35.1962381308779), + Offset(51.53045534970737, 39.21738368206378), + Offset(50.52706670358306, 43.187670298244306), + Offset(49.7854889546519, 47.01626356414165), + Offset(50.283999172374806, 50.165899443393734), + Offset(52.42717102172652, 52.417745301530715), + Offset(53.74879696492653, 53.77618807553071), + Offset(53.62896000832653, 53.651912713230715), + Offset(53.50912305182652, 53.527637350830716), + Offset(53.389286095326526, 53.40336198853072), + Offset(53.26944913882653, 53.27908662623072), + Offset(53.14961218232652, 53.154811263930725), + Offset(53.029775225726524, 53.030535901630714), + Offset(52.90993826922653, 52.90626053933072), + Offset(52.79010131272652, 52.78198517693072), + Offset(52.670264356226525, 52.65770981463072), + Offset(52.55042739972653, 52.533434452330724), + Offset(52.43059044312652, 52.40915909003071), + Offset(52.310753486626524, 52.284883727730715), + Offset(52.19091653012653, 52.16060836533072), + Offset(52.07107957362652, 52.03633300303072), + Offset(51.95124261702652, 51.91205764073072), + Offset(51.83140566052653, 51.78778227843071), + Offset(51.71156870402652, 51.663506916130714), + Offset(51.591731747526524, 51.539231553730716), + Offset(51.47189479102653, 51.41495619143072), + Offset(51.35205783442652, 51.29068082913072), + Offset(51.23222087792652, 51.166405466830724), + Offset(51.11238392142653, 51.04213010453071), + Offset(50.99254696492652, 50.917854742230716), + Offset(50.87271000832652, 50.79357937983072), + Offset(50.752873051826526, 50.66930401753072), + Offset(50.63303609532653, 50.54502865523072), + Offset(50.51319913882652, 50.42075329293071), + Offset(50.39336218232653, 50.296477930630715), + Offset(50.27352522572653, 50.172202568230716), + Offset(50.15368826922652, 50.04792720593072), + ], + <Offset>[ + Offset(54.90270712071989, 36.41758712071989), + Offset(54.90270712071989, 36.41758712071989), + Offset(54.90270712071989, 36.41758712071989), + Offset(54.90270712071989, 36.41758712071989), + Offset(54.90270712071989, 36.41758712071989), + Offset(54.90270712071989, 36.41758712071989), + Offset(54.90270712071989, 36.41758712071989), + Offset(54.90270712071989, 36.41758712071989), + Offset(54.90270712071989, 36.41758712071989), + Offset(54.90270712071989, 36.41758712071989), + Offset(54.71531815301439, 36.87053160703761), + Offset(53.71654072312347, 39.09029363766916), + Offset(52.62928729387452, 41.31071235333787), + Offset(51.53045534970737, 43.53198610663798), + Offset(50.52706670358306, 45.75444966750169), + Offset(49.7854889546519, 47.97877125585276), + Offset(50.283999172374806, 50.20685835445277), + Offset(52.42717102172652, 52.44166244630614), + Offset(53.74879696492653, 53.800105220306136), + Offset(53.62896000832653, 53.67582985800614), + Offset(53.50912305182652, 53.55155449560614), + Offset(53.389286095326526, 53.427279133306136), + Offset(53.26944913882653, 53.30300377100614), + Offset(53.14961218232652, 53.17872840870614), + Offset(53.029775225726524, 53.05445304640614), + Offset(52.90993826922653, 52.93017768410614), + Offset(52.79010131272652, 52.80590232170614), + Offset(52.670264356226525, 52.68162695940614), + Offset(52.55042739972653, 52.55735159710614), + Offset(52.43059044312652, 52.43307623480614), + Offset(52.310753486626524, 52.30880087250614), + Offset(52.19091653012653, 52.18452551010614), + Offset(52.07107957362652, 52.06025014780614), + Offset(51.95124261702652, 51.93597478550614), + Offset(51.83140566052653, 51.811699423206136), + Offset(51.71156870402652, 51.68742406090614), + Offset(51.591731747526524, 51.56314869850614), + Offset(51.47189479102653, 51.438873336206136), + Offset(51.35205783442652, 51.31459797390614), + Offset(51.23222087792652, 51.19032261160614), + Offset(51.11238392142653, 51.06604724930614), + Offset(50.99254696492652, 50.94177188700614), + Offset(50.87271000832652, 50.81749652460614), + Offset(50.752873051826526, 50.69322116230614), + Offset(50.63303609532653, 50.56894580000614), + Offset(50.51319913882652, 50.44467043770614), + Offset(50.39336218232653, 50.32039507540614), + Offset(50.27352522572653, 50.19611971300614), + Offset(50.15368826922652, 50.07184435070614), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(54.90270712071989, 46.41563917637766), + Offset(54.90270712071989, 46.41563917637766), + Offset(54.90270712071989, 46.41563917637766), + Offset(54.90270712071989, 46.41563917637766), + Offset(54.90270712071989, 46.41563917637766), + Offset(54.90270712071989, 46.41563917637766), + Offset(54.90270712071989, 46.41563917637766), + Offset(54.90270712071989, 46.41563917637766), + Offset(54.90270712071989, 46.41563917637766), + Offset(54.90270712071989, 46.41563917637766), + Offset(54.71531815301439, 46.52182603428994), + Offset(53.71654072312347, 46.99779784106601), + Offset(52.62928729387452, 47.42520527750929), + Offset(51.53045534970737, 47.84660167834321), + Offset(50.52706670358306, 48.32123679418471), + Offset(49.7854889546519, 48.94128176513705), + Offset(50.283999172374806, 50.247817265511806), + Offset(52.42717102172652, 52.46557959108156), + Offset(53.74879696492653, 53.824022365081554), + Offset(53.62896000832653, 53.69974700278156), + Offset(53.50912305182652, 53.57547164038156), + Offset(53.389286095326526, 53.451196278081554), + Offset(53.26944913882653, 53.32692091578156), + Offset(53.14961218232652, 53.20264555348156), + Offset(53.029775225726524, 53.078370191181556), + Offset(52.90993826922653, 52.95409482888156), + Offset(52.79010131272652, 52.82981946648156), + Offset(52.670264356226525, 52.705544104181556), + Offset(52.55042739972653, 52.58126874188156), + Offset(52.43059044312652, 52.456993379581554), + Offset(52.310753486626524, 52.33271801728156), + Offset(52.19091653012653, 52.20844265488156), + Offset(52.07107957362652, 52.084167292581554), + Offset(51.95124261702652, 51.95989193028156), + Offset(51.83140566052653, 51.83561656798155), + Offset(51.71156870402652, 51.711341205681556), + Offset(51.591731747526524, 51.58706584328156), + Offset(51.47189479102653, 51.46279048098155), + Offset(51.35205783442652, 51.338515118681556), + Offset(51.23222087792652, 51.21423975638156), + Offset(51.11238392142653, 51.089964394081555), + Offset(50.99254696492652, 50.96568903178156), + Offset(50.87271000832652, 50.84141366938156), + Offset(50.752873051826526, 50.717138307081555), + Offset(50.63303609532653, 50.59286294478156), + Offset(50.51319913882652, 50.468587582481554), + Offset(50.39336218232653, 50.34431222018156), + Offset(50.27352522572653, 50.22003685778156), + Offset(50.15368826922652, 50.095761495481554), + ], + <Offset>[ + Offset(46.79563917637766, 54.522707120719886), + Offset(46.79563917637766, 54.522707120719886), + Offset(46.79563917637766, 54.522707120719886), + Offset(46.79563917637766, 54.522707120719886), + Offset(46.79563917637766, 54.522707120719886), + Offset(46.79563917637766, 54.522707120719886), + Offset(46.79563917637766, 54.522707120719886), + Offset(46.79563917637766, 54.522707120719886), + Offset(46.79563917637766, 54.522707120719886), + Offset(46.79563917637766, 54.522707120719886), + Offset(46.88942369051005, 54.34772049679427), + Offset(47.30462401296601, 53.40971455122347), + Offset(47.67125996500929, 52.38323260637452), + Offset(48.031884881450786, 51.34517214659979), + Offset(48.44574851300257, 50.4025549847652), + Offset(49.00502199955961, 49.72174872023579), + Offset(50.25078601552198, 50.28103042236462), + Offset(52.4077768566875, 52.48497375612058), + Offset(53.729402799887495, 53.84341653012058), + Offset(53.6095658432875, 53.71914116782058), + Offset(53.489728886787496, 53.59486580542058), + Offset(53.369891930287494, 53.47059044312058), + Offset(53.2500549737875, 53.34631508082058), + Offset(53.1302180172875, 53.222039718520584), + Offset(53.0103810606875, 53.09776435622058), + Offset(52.8905441041875, 52.97348899392058), + Offset(52.770707147687496, 52.849213631520584), + Offset(52.650870191187494, 52.72493826922058), + Offset(52.5310332346875, 52.60066290692058), + Offset(52.411196278087495, 52.47638754462058), + Offset(52.2913593215875, 52.35211218232058), + Offset(52.1715223650875, 52.22783681992058), + Offset(52.051685408587495, 52.10356145762058), + Offset(51.9318484519875, 51.97928609532058), + Offset(51.812011495487496, 51.85501073302058), + Offset(51.692174538987494, 51.73073537072058), + Offset(51.5723375824875, 51.60646000832058), + Offset(51.4525006259875, 51.48218464602058), + Offset(51.33266366938749, 51.35790928372058), + Offset(51.2128267128875, 51.233633921420584), + Offset(51.092989756387496, 51.10935855912058), + Offset(50.973152799887494, 50.98508319682058), + Offset(50.8533158432875, 50.860807834420584), + Offset(50.733478886787495, 50.73653247212058), + Offset(50.6136419302875, 50.61225710982058), + Offset(50.4938049737875, 50.48798174752058), + Offset(50.373968017287496, 50.36370638522058), + Offset(50.2541310606875, 50.23943102282058), + Offset(50.1342941041875, 50.11515566052058), + ], + <Offset>[ + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(36.79758712071989, 54.522707120719886), + Offset(37.238129263257726, 54.34772049679427), + Offset(39.39711980956916, 53.40971455122347), + Offset(41.55676704083787, 52.38323260637452), + Offset(43.717269309745554, 51.34517214659979), + Offset(45.878961386319546, 50.4025549847652), + Offset(48.04251149026888, 49.72174872023579), + Offset(50.209827104462946, 50.28103042236462), + Offset(52.38385971191208, 52.48497375612058), + Offset(53.70548565511208, 53.84341653012058), + Offset(53.58564869851208, 53.71914116782058), + Offset(53.46581174201208, 53.59486580542058), + Offset(53.34597478551208, 53.47059044312058), + Offset(53.22613782901208, 53.34631508082058), + Offset(53.10630087251208, 53.222039718520584), + Offset(52.98646391591208, 53.09776435622058), + Offset(52.86662695941208, 52.97348899392058), + Offset(52.74679000291208, 52.849213631520584), + Offset(52.626953046412076, 52.72493826922058), + Offset(52.50711608991208, 52.60066290692058), + Offset(52.38727913331208, 52.47638754462058), + Offset(52.26744217681208, 52.35211218232058), + Offset(52.14760522031208, 52.22783681992058), + Offset(52.02776826381208, 52.10356145762058), + Offset(51.90793130721208, 51.97928609532058), + Offset(51.78809435071208, 51.85501073302058), + Offset(51.66825739421208, 51.73073537072058), + Offset(51.54842043771208, 51.60646000832058), + Offset(51.42858348121208, 51.48218464602058), + Offset(51.308746524612076, 51.35790928372058), + Offset(51.18890956811208, 51.233633921420584), + Offset(51.06907261161208, 51.10935855912058), + Offset(50.949235655112076, 50.98508319682058), + Offset(50.82939869851208, 50.860807834420584), + Offset(50.70956174201208, 50.73653247212058), + Offset(50.58972478551208, 50.61225710982058), + Offset(50.46988782901208, 50.48798174752058), + Offset(50.35005087251208, 50.36370638522058), + Offset(50.23021391591208, 50.23943102282058), + Offset(50.11037695941208, 50.11515566052058), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + Offset(60.937745291919896, 54.52270224391989), + ], + <Offset>[ + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + ], + <Offset>[ + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + Offset(57.739181458913336, 54.52270224391989), + ], + <Offset>[ + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.39144480852299, 53.174996289330196), + Offset(56.43397725114974, 53.217528731956946), + Offset(56.47650969377649, 53.2600611745837), + Offset(56.51904213640324, 53.30259361721045), + Offset(56.561574579029994, 53.3451260598372), + Offset(56.604107021656745, 53.38765850246395), + Offset(56.62684855989554, 53.41109453319635), + Offset(56.60877135783367, 53.39514421439123), + Offset(56.5906941557718, 53.37919389558813), + Offset(56.572616953707914, 53.363243576785024), + Offset(56.55453975164605, 53.347293257979906), + Offset(56.53646254958216, 53.33134293917681), + Offset(56.518385347520294, 53.3153926203737), + Offset(56.50030814545842, 53.29944230156859), + Offset(56.48223094339454, 53.28349198276548), + Offset(56.464153741332666, 53.267541663962376), + Offset(56.44607653927079, 53.251591345157266), + Offset(56.42799933720691, 53.23564102635416), + Offset(56.40992213514504, 53.21969070755106), + Offset(56.39184493308116, 53.20374038874594), + Offset(56.373767731019285, 53.187790069942835), + Offset(56.35569052895741, 53.171839751139736), + Offset(56.33761332689353, 53.15588943233462), + Offset(56.31953612483166, 53.13993911353152), + Offset(56.30145892276979, 53.12398879472841), + Offset(56.283381720705904, 53.108038475923294), + Offset(56.26530451864404, 53.092088157120195), + Offset(56.24722731658217, 53.07613783831709), + Offset(56.22915011451828, 53.06018751951198), + Offset(56.211072912456416, 53.04423720070887), + Offset(56.19299571039253, 53.02828688190577), + Offset(56.174918508330656, 53.012336563100654), + Offset(56.15684130626879, 52.996386244297554), + Offset(56.1387641042049, 52.98043592549445), + Offset(56.120686902143035, 52.96448560668933), + Offset(56.10260970008116, 52.94853528788623), + Offset(56.08453249801728, 52.93258496908312), + Offset(56.06645529595541, 52.916634650278006), + Offset(56.04837809389354, 52.900684331474906), + ], + <Offset>[ + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.3827647181903, 53.16631619899751), + Offset(56.39144480852299, 53.174996289330196), + Offset(56.43397725114974, 53.217528731956946), + Offset(56.47650969377649, 53.2600611745837), + Offset(56.51904213640324, 53.30259361721045), + Offset(56.561574579029994, 53.3451260598372), + Offset(56.604107021656745, 53.38765850246395), + Offset(56.62684855989554, 53.41109453319635), + Offset(56.60877135783367, 53.39514421439123), + Offset(56.5906941557718, 53.37919389558813), + Offset(56.572616953707914, 53.363243576785024), + Offset(56.55453975164605, 53.347293257979906), + Offset(56.53646254958216, 53.33134293917681), + Offset(56.518385347520294, 53.3153926203737), + Offset(56.50030814545842, 53.29944230156859), + Offset(56.48223094339454, 53.28349198276548), + Offset(56.464153741332666, 53.267541663962376), + Offset(56.44607653927079, 53.251591345157266), + Offset(56.42799933720691, 53.23564102635416), + Offset(56.40992213514504, 53.21969070755106), + Offset(56.39184493308116, 53.20374038874594), + Offset(56.373767731019285, 53.187790069942835), + Offset(56.35569052895741, 53.171839751139736), + Offset(56.33761332689353, 53.15588943233462), + Offset(56.31953612483166, 53.13993911353152), + Offset(56.30145892276979, 53.12398879472841), + Offset(56.283381720705904, 53.108038475923294), + Offset(56.26530451864404, 53.092088157120195), + Offset(56.24722731658217, 53.07613783831709), + Offset(56.22915011451828, 53.06018751951198), + Offset(56.211072912456416, 53.04423720070887), + Offset(56.19299571039253, 53.02828688190577), + Offset(56.174918508330656, 53.012336563100654), + Offset(56.15684130626879, 52.996386244297554), + Offset(56.1387641042049, 52.98043592549445), + Offset(56.120686902143035, 52.96448560668933), + Offset(56.10260970008116, 52.94853528788623), + Offset(56.08453249801728, 52.93258496908312), + Offset(56.06645529595541, 52.916634650278006), + Offset(56.04837809389354, 52.900684331474906), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(56.3827647181903, 53.16627596539751), + Offset(56.3827647181903, 53.16627596539751), + Offset(56.3827647181903, 53.16627596539751), + Offset(56.3827647181903, 53.16627596539751), + Offset(56.3827647181903, 53.16627596539751), + Offset(56.3827647181903, 53.16627596539751), + Offset(56.3827647181903, 53.16627596539751), + Offset(56.3827647181903, 53.16627596539751), + Offset(56.3827647181903, 53.16627596539751), + Offset(56.3827647181903, 53.16627596539751), + Offset(56.39144480852299, 53.1749560557302), + Offset(56.43397725114974, 53.21748849835695), + Offset(56.47650969377649, 53.2600209409837), + Offset(56.51904213640324, 53.302553383610444), + Offset(56.561574579029994, 53.345085826237195), + Offset(56.604107021656745, 53.387618268863946), + Offset(56.62684855989554, 53.411054299596344), + Offset(56.60877135783367, 53.395103980791234), + Offset(56.5906941557718, 53.37915366198813), + Offset(56.572616953707914, 53.36320334318502), + Offset(56.55453975164605, 53.34725302437991), + Offset(56.53646254958216, 53.3313027055768), + Offset(56.518385347520294, 53.315352386773704), + Offset(56.50030814545842, 53.299402067968586), + Offset(56.48223094339454, 53.28345174916548), + Offset(56.464153741332666, 53.26750143036238), + Offset(56.44607653927079, 53.25155111155726), + Offset(56.42799933720691, 53.23560079275416), + Offset(56.40992213514504, 53.219650473951056), + Offset(56.39184493308116, 53.20370015514594), + Offset(56.373767731019285, 53.18774983634284), + Offset(56.35569052895741, 53.17179951753973), + Offset(56.33761332689353, 53.15584919873462), + Offset(56.31953612483166, 53.139898879931515), + Offset(56.30145892276979, 53.123948561128415), + Offset(56.283381720705904, 53.1079982423233), + Offset(56.26530451864404, 53.0920479235202), + Offset(56.24722731658217, 53.07609760471709), + Offset(56.22915011451828, 53.060147285911974), + Offset(56.211072912456416, 53.044196967108874), + Offset(56.19299571039253, 53.02824664830577), + Offset(56.174918508330656, 53.01229632950065), + Offset(56.15684130626879, 52.99634601069755), + Offset(56.1387641042049, 52.980395691894444), + Offset(56.120686902143035, 52.96444537308933), + Offset(56.10260970008116, 52.94849505428623), + Offset(56.08453249801728, 52.93254473548313), + Offset(56.06645529595541, 52.91659441667801), + Offset(56.04837809389354, 52.9006440978749), + ], + <Offset>[ + Offset(53.54631924699953, 56.02289811551084), + Offset(53.54631924699953, 56.02289811551084), + Offset(53.54631924699953, 56.02289811551084), + Offset(53.54631924699953, 56.02289811551084), + Offset(53.54631924699953, 56.02289811551084), + Offset(53.54631924699953, 56.02289811551084), + Offset(53.54631924699953, 56.02289811551084), + Offset(53.54631924699953, 56.02289811551084), + Offset(53.54631924699953, 56.02289811551084), + Offset(53.54631924699953, 56.02289811551084), + Offset(53.55499933733222, 56.03157820584353), + Offset(53.59753177995896, 56.07411064847028), + Offset(53.64006422258572, 56.11664309109703), + Offset(53.682596665212465, 56.15917553372378), + Offset(53.725129107839216, 56.201707976350534), + Offset(53.76766155046597, 56.244240418977284), + Offset(53.790403088704764, 56.26767644970968), + Offset(53.77232588664289, 56.251726130904565), + Offset(53.75424868458102, 56.235775812101465), + Offset(53.736171482517136, 56.21982549329836), + Offset(53.71809428045527, 56.20387517449325), + Offset(53.70001707839138, 56.18792485569014), + Offset(53.68193987632951, 56.171974536887035), + Offset(53.66386267426764, 56.156024218081924), + Offset(53.645785472203755, 56.14007389927882), + Offset(53.62770827014189, 56.12412358047571), + Offset(53.60963106808002, 56.1081732616706), + Offset(53.591553866016135, 56.092222942867494), + Offset(53.57347666395426, 56.076272624064394), + Offset(53.55539946189038, 56.06032230525928), + Offset(53.53732225982851, 56.04437198645618), + Offset(53.51924505776664, 56.02842166765307), + Offset(53.501167855702754, 56.01247134884795), + Offset(53.483090653640886, 55.99652103004485), + Offset(53.46501345157901, 55.980570711241754), + Offset(53.44693624951513, 55.964620392436636), + Offset(53.42885904745326, 55.94867007363353), + Offset(53.41078184539139, 55.93271975483043), + Offset(53.392704643327505, 55.91676943602531), + Offset(53.37462744126564, 55.90081911722221), + Offset(53.35655023920175, 55.884868798419106), + Offset(53.33847303713988, 55.86891847961399), + Offset(53.32039583507801, 55.85296816081089), + Offset(53.302318633014124, 55.83701784200778), + Offset(53.28424143095226, 55.821067523202665), + Offset(53.26616422889038, 55.805117204399565), + Offset(53.248087026826504, 55.78916688559646), + Offset(53.23000982476463, 55.77321656679135), + Offset(53.21193262270276, 55.75726624798824), + ], + <Offset>[ + Offset(53.54628855119686, 56.02289811551084), + Offset(53.54628855119686, 56.02289811551084), + Offset(53.54628855119686, 56.02289811551084), + Offset(53.54628855119686, 56.02289811551084), + Offset(53.54628855119686, 56.02289811551084), + Offset(53.54628855119686, 56.02289811551084), + Offset(53.54628855119686, 56.02289811551084), + Offset(53.54628855119686, 56.02289811551084), + Offset(53.54628855119686, 56.02289811551084), + Offset(53.54628855119686, 56.02289811551084), + Offset(53.55496864152955, 56.03157820584353), + Offset(53.5975010841563, 56.07411064847028), + Offset(53.64003352678305, 56.11664309109703), + Offset(53.6825659694098, 56.15917553372378), + Offset(53.72509841203655, 56.201707976350534), + Offset(53.7676308546633, 56.244240418977284), + Offset(53.79037239290209, 56.26767644970968), + Offset(53.772295190840225, 56.251726130904565), + Offset(53.75421798877835, 56.235775812101465), + Offset(53.73614078671447, 56.21982549329836), + Offset(53.7180635846526, 56.20387517449325), + Offset(53.69998638258872, 56.18792485569014), + Offset(53.681909180526844, 56.171974536887035), + Offset(53.66383197846497, 56.156024218081924), + Offset(53.64575477640109, 56.14007389927882), + Offset(53.62767757433922, 56.12412358047571), + Offset(53.60960037227735, 56.1081732616706), + Offset(53.59152317021346, 56.092222942867494), + Offset(53.573445968151596, 56.076272624064394), + Offset(53.55536876608771, 56.06032230525928), + Offset(53.53729156402584, 56.04437198645618), + Offset(53.51921436196397, 56.02842166765307), + Offset(53.50113715990009, 56.01247134884795), + Offset(53.483059957838215, 55.99652103004485), + Offset(53.46498275577635, 55.980570711241754), + Offset(53.44690555371246, 55.964620392436636), + Offset(53.428828351650594, 55.94867007363353), + Offset(53.41075114958872, 55.93271975483043), + Offset(53.392673947524834, 55.91676943602531), + Offset(53.374596745462966, 55.90081911722221), + Offset(53.35651954339908, 55.884868798419106), + Offset(53.33844234133721, 55.86891847961399), + Offset(53.32036513927534, 55.85296816081089), + Offset(53.30228793721146, 55.83701784200778), + Offset(53.284210735149586, 55.821067523202665), + Offset(53.26613353308772, 55.805117204399565), + Offset(53.24805633102383, 55.78916688559646), + Offset(53.229979128961965, 55.77321656679135), + Offset(53.21190192690009, 55.75726624798824), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(53.54628855119686, 56.022857881910845), + Offset(53.54628855119686, 56.022857881910845), + Offset(53.54628855119686, 56.022857881910845), + Offset(53.54628855119686, 56.022857881910845), + Offset(53.54628855119686, 56.022857881910845), + Offset(53.54628855119686, 56.022857881910845), + Offset(53.54628855119686, 56.022857881910845), + Offset(53.54628855119686, 56.022857881910845), + Offset(53.54628855119686, 56.022857881910845), + Offset(53.54628855119686, 56.022857881910845), + Offset(53.55496864152955, 56.031537972243534), + Offset(53.5975010841563, 56.074070414870285), + Offset(53.64003352678305, 56.116602857497035), + Offset(53.6825659694098, 56.159135300123786), + Offset(53.72509841203655, 56.20166774275054), + Offset(53.7676308546633, 56.24420018537729), + Offset(53.79037239290209, 56.26763621610968), + Offset(53.772295190840225, 56.25168589730457), + Offset(53.75421798877835, 56.23573557850146), + Offset(53.73614078671447, 56.21978525969836), + Offset(53.7180635846526, 56.203834940893245), + Offset(53.69998638258872, 56.18788462209014), + Offset(53.681909180526844, 56.17193430328704), + Offset(53.66383197846497, 56.15598398448192), + Offset(53.64575477640109, 56.14003366567882), + Offset(53.62767757433922, 56.124083346875715), + Offset(53.60960037227735, 56.1081330280706), + Offset(53.59152317021346, 56.0921827092675), + Offset(53.573445968151596, 56.0762323904644), + Offset(53.55536876608771, 56.06028207165928), + Offset(53.53729156402584, 56.04433175285617), + Offset(53.51921436196397, 56.028381434053074), + Offset(53.50113715990009, 56.012431115247956), + Offset(53.483059957838215, 55.99648079644485), + Offset(53.46498275577635, 55.98053047764175), + Offset(53.44690555371246, 55.96458015883663), + Offset(53.428828351650594, 55.94862984003353), + Offset(53.41075114958872, 55.932679521230426), + Offset(53.392673947524834, 55.916729202425316), + Offset(53.374596745462966, 55.90077888362221), + Offset(53.35651954339908, 55.8848285648191), + Offset(53.33844234133721, 55.86887824601399), + Offset(53.32036513927534, 55.852927927210885), + Offset(53.30228793721146, 55.83697760840778), + Offset(53.284210735149586, 55.82102728960267), + Offset(53.26613353308772, 55.80507697079956), + Offset(53.24805633102383, 55.78912665199646), + Offset(53.229979128961965, 55.773176333191344), + Offset(53.21190192690009, 55.75722601438824), + ], + <Offset>[ + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + ], + <Offset>[ + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291921905, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291921905, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.379314856233876), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.37931485623388), + Offset(54.902705291919894, 57.379314856233876), + ], + <Offset>[ + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291921905, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + ], + <Offset>[ + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291921905, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291921905, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + Offset(54.902705291919894, 60.557742243937994), + ], + <Offset>[ + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(74.32497336367568, 79.93649262312883), + Offset(70.92176691523076, 76.5170858263241), + Offset(67.51856046678586, 73.09767902951937), + Offset(64.11535401834094, 69.67827223271463), + Offset(60.71214756989602, 66.25886543593002), + Offset(57.30894112147122, 62.83945863912528), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.01698575823052, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + ], + <Offset>[ + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(74.32497336367568, 79.93649262312883), + Offset(70.92176691523076, 76.5170858263241), + Offset(67.51856046678586, 73.09767902951937), + Offset(64.11535401834094, 69.67827223271463), + Offset(60.71214756989602, 66.25886543593002), + Offset(57.30894112147122, 62.83945863912528), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.01698575823052, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(75.0195052919199, 80.63433074491833), + Offset(74.32497336367568, 79.93649262312883), + Offset(70.92176691523076, 76.5170858263241), + Offset(67.51856046678586, 73.09767902951937), + Offset(64.11535401834094, 69.67827223271463), + Offset(60.71214756989602, 66.25886543593002), + Offset(57.30894112147122, 62.83945863912528), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.01698575823052, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + Offset(55.016985758228515, 60.536592837199635), + ], + <Offset>[ + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(80.31980186465601, 73.9416641221485), + Offset(76.9165954162111, 70.52225732534376), + Offset(73.51338896776619, 67.10285052853904), + Offset(70.11018251932127, 63.6834437317343), + Offset(66.70697607087635, 60.26403693494969), + Offset(63.30376962245156, 56.84463013814495), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425921086, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + ], + <Offset>[ + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(80.31980186465601, 73.9416641221485), + Offset(76.9165954162111, 70.52225732534376), + Offset(73.51338896776619, 67.10285052853904), + Offset(70.11018251932127, 63.6834437317343), + Offset(66.70697607087635, 60.26403693494969), + Offset(63.30376962245156, 56.84463013814495), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425921086, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(81.01433379290023, 74.639502243938), + Offset(80.31980186465601, 73.9416641221485), + Offset(76.9165954162111, 70.52225732534376), + Offset(73.51338896776619, 67.10285052853904), + Offset(70.11018251932127, 63.6834437317343), + Offset(66.70697607087635, 60.26403693494969), + Offset(63.30376962245156, 56.84463013814495), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425921086, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + Offset(61.01181425920885, 54.5417643362193), + ], + <Offset>[ + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529194001, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224391788), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529194001, 54.52270224393799), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192572, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + ], + <Offset>[ + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529191989, 54.52270224393799), + Offset(60.93774529194001, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.937745291919896, 54.52270224391788), + Offset(60.937745291919896, 54.52270224393799), + Offset(60.93774529194001, 54.52270224393799), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192572, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + Offset(60.93774529192372, 54.52270224393415), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 54.754867779413956), + Offset(48.0, 51.604258802513954), + Offset(48.0, 48.45364982561395), + Offset(48.0, 45.30304084871395), + Offset(48.0, 42.15243187181395), + Offset(48.0, 39.00182289491395), + Offset(48.0, 35.85121391801395), + Offset(48.0, 34.05512107195435), + Offset(48.0, 33.540905901349916), + Offset(48.0, 33.12129231086275), + Offset(48.0, 32.781503706824346), + Offset(48.0, 32.50949551311259), + Offset(48.0, 32.29485026134325), + Offset(48.0, 32.1283960707288), + Offset(48.0, 32.00233286349681), + Offset(48.0, 31.909924001704802), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 55.9765324848), + Offset(52.445826306158004, 54.754867779413956), + Offset(52.445826306158004, 51.604258802513954), + Offset(52.445826306158004, 48.45364982561395), + Offset(52.445826306158004, 45.30304084871395), + Offset(52.445826306158004, 42.15243187181395), + Offset(52.445826306158004, 39.00182289491395), + Offset(52.445826306158004, 35.85121391801395), + Offset(52.445826306158004, 34.05512107195435), + Offset(52.445826306158004, 33.540905901349916), + Offset(52.445826306158004, 33.12129231086275), + Offset(52.445826306158004, 32.781503706824346), + Offset(52.445826306158004, 32.50949551311259), + Offset(52.445826306158004, 32.29485026134325), + Offset(52.445826306158004, 32.1283960707288), + Offset(52.445826306158004, 32.00233286349681), + Offset(52.445826306158004, 31.909924001704802), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + Offset(52.445826306158004, 31.90656), + ], + <Offset>[ + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 52.37560809515534), + Offset(56.04672, 51.153943389769296), + Offset(56.04672, 48.00333441286929), + Offset(56.04672, 44.85272543596929), + Offset(56.04672, 41.70211645906929), + Offset(56.04672, 38.551507482169285), + Offset(56.04672, 35.40089850526928), + Offset(56.04672, 32.25028952836928), + Offset(56.04672, 30.45419668230969), + Offset(56.04672, 29.939981511705252), + Offset(56.04672, 29.520367921218085), + Offset(56.04672, 29.18057931717968), + Offset(56.04672, 28.908571123467926), + Offset(56.04672, 28.693925871698585), + Offset(56.04672, 28.527471681084133), + Offset(56.04672, 28.401408473852147), + Offset(56.04672, 28.308999612060138), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + Offset(56.04672, 28.305635610355335), + ], + <Offset>[ + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 47.9298124848), + Offset(56.04672, 46.708147779413956), + Offset(56.04672, 43.55753880251395), + Offset(56.04672, 40.40692982561395), + Offset(56.04672, 37.25632084871395), + Offset(56.04672, 34.10571187181395), + Offset(56.04672, 30.95510289491395), + Offset(56.04672, 27.804493918013947), + Offset(56.04672, 26.008401071954353), + Offset(56.04672, 25.494185901349915), + Offset(56.04672, 25.07457231086275), + Offset(56.04672, 24.734783706824345), + Offset(56.04672, 24.46277551311259), + Offset(56.04672, 24.24813026134325), + Offset(56.04672, 24.081676070728797), + Offset(56.04672, 23.95561286349681), + Offset(56.04672, 23.8632040017048), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + Offset(56.04672, 23.85984), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 43.483986178642), + Offset(56.04672, 42.26232147325595), + Offset(56.04672, 39.11171249635595), + Offset(56.04672, 35.961103519455946), + Offset(56.04672, 32.810494542555944), + Offset(56.04672, 29.65988556565595), + Offset(56.04672, 26.50927658875595), + Offset(56.04672, 23.358667611855946), + Offset(56.04672, 21.562574765796352), + Offset(56.04672, 21.048359595191915), + Offset(56.04672, 20.628746004704748), + Offset(56.04672, 20.288957400666344), + Offset(56.04672, 20.01694920695459), + Offset(56.04672, 19.80230395518525), + Offset(56.04672, 19.635849764570796), + Offset(56.04672, 19.50978655733881), + Offset(56.04672, 19.4173776955468), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + Offset(56.04672, 19.414013693841998), + ], + <Offset>[ + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 39.8830924848), + Offset(52.445826306158004, 38.661427779413955), + Offset(52.445826306158004, 35.51081880251395), + Offset(52.445826306158004, 32.36020982561395), + Offset(52.445826306158004, 29.209600848713947), + Offset(52.445826306158004, 26.05899187181395), + Offset(52.445826306158004, 22.90838289491395), + Offset(52.445826306158004, 19.757773918013946), + Offset(52.445826306158004, 17.961681071954352), + Offset(52.445826306158004, 17.447465901349915), + Offset(52.445826306158004, 17.027852310862748), + Offset(52.445826306158004, 16.688063706824344), + Offset(52.445826306158004, 16.41605551311259), + Offset(52.445826306158004, 16.20141026134325), + Offset(52.445826306158004, 16.034956070728796), + Offset(52.445826306158004, 15.90889286349681), + Offset(52.445826306158004, 15.8164840017048), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + Offset(52.445826306158004, 15.813119999999998), + ], + <Offset>[ + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 39.8830924848), + Offset(48.0, 38.661427779413955), + Offset(48.0, 35.51081880251395), + Offset(48.0, 32.36020982561395), + Offset(48.0, 29.209600848713947), + Offset(48.0, 26.05899187181395), + Offset(48.0, 22.90838289491395), + Offset(48.0, 19.757773918013946), + Offset(48.0, 17.961681071954352), + Offset(48.0, 17.447465901349915), + Offset(48.0, 17.027852310862748), + Offset(48.0, 16.688063706824344), + Offset(48.0, 16.41605551311259), + Offset(48.0, 16.20141026134325), + Offset(48.0, 16.034956070728796), + Offset(48.0, 15.90889286349681), + Offset(48.0, 15.8164840017048), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + Offset(48.0, 15.813119999999998), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 39.8830924848), + Offset(43.554173693841996, 38.661427779413955), + Offset(43.554173693841996, 35.51081880251395), + Offset(43.554173693841996, 32.36020982561395), + Offset(43.554173693841996, 29.209600848713947), + Offset(43.554173693841996, 26.05899187181395), + Offset(43.554173693841996, 22.90838289491395), + Offset(43.554173693841996, 19.757773918013946), + Offset(43.554173693841996, 17.961681071954352), + Offset(43.554173693841996, 17.447465901349915), + Offset(43.554173693841996, 17.027852310862748), + Offset(43.554173693841996, 16.688063706824344), + Offset(43.554173693841996, 16.41605551311259), + Offset(43.554173693841996, 16.20141026134325), + Offset(43.554173693841996, 16.034956070728796), + Offset(43.554173693841996, 15.90889286349681), + Offset(43.554173693841996, 15.8164840017048), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + Offset(43.554173693841996, 15.813119999999998), + ], + <Offset>[ + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 43.483986178642), + Offset(39.95328, 42.26232147325595), + Offset(39.95328, 39.11171249635595), + Offset(39.95328, 35.961103519455946), + Offset(39.95328, 32.810494542555944), + Offset(39.95328, 29.65988556565595), + Offset(39.95328, 26.50927658875595), + Offset(39.95328, 23.358667611855946), + Offset(39.95328, 21.562574765796352), + Offset(39.95328, 21.048359595191915), + Offset(39.95328, 20.628746004704748), + Offset(39.95328, 20.288957400666344), + Offset(39.95328, 20.01694920695459), + Offset(39.95328, 19.80230395518525), + Offset(39.95328, 19.635849764570796), + Offset(39.95328, 19.50978655733881), + Offset(39.95328, 19.4173776955468), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + Offset(39.95328, 19.414013693841998), + ], + <Offset>[ + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 47.9298124848), + Offset(39.95328, 46.708147779413956), + Offset(39.95328, 43.55753880251395), + Offset(39.95328, 40.40692982561395), + Offset(39.95328, 37.25632084871395), + Offset(39.95328, 34.10571187181395), + Offset(39.95328, 30.95510289491395), + Offset(39.95328, 27.804493918013947), + Offset(39.95328, 26.008401071954353), + Offset(39.95328, 25.494185901349915), + Offset(39.95328, 25.07457231086275), + Offset(39.95328, 24.734783706824345), + Offset(39.95328, 24.46277551311259), + Offset(39.95328, 24.24813026134325), + Offset(39.95328, 24.081676070728797), + Offset(39.95328, 23.95561286349681), + Offset(39.95328, 23.8632040017048), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + Offset(39.95328, 23.85984), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 52.37560809515534), + Offset(39.95328, 51.153943389769296), + Offset(39.95328, 48.00333441286929), + Offset(39.95328, 44.85272543596929), + Offset(39.95328, 41.70211645906929), + Offset(39.95328, 38.551507482169285), + Offset(39.95328, 35.40089850526928), + Offset(39.95328, 32.25028952836928), + Offset(39.95328, 30.45419668230969), + Offset(39.95328, 29.939981511705252), + Offset(39.95328, 29.520367921218085), + Offset(39.95328, 29.18057931717968), + Offset(39.95328, 28.908571123467926), + Offset(39.95328, 28.693925871698585), + Offset(39.95328, 28.527471681084133), + Offset(39.95328, 28.401408473852147), + Offset(39.95328, 28.308999612060138), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + Offset(39.95328, 28.305635610355335), + ], + <Offset>[ + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 55.9765324848), + Offset(43.554173693841996, 54.754867779413956), + Offset(43.554173693841996, 51.604258802513954), + Offset(43.554173693841996, 48.45364982561395), + Offset(43.554173693841996, 45.30304084871395), + Offset(43.554173693841996, 42.15243187181395), + Offset(43.554173693841996, 39.00182289491395), + Offset(43.554173693841996, 35.85121391801395), + Offset(43.554173693841996, 34.05512107195435), + Offset(43.554173693841996, 33.540905901349916), + Offset(43.554173693841996, 33.12129231086275), + Offset(43.554173693841996, 32.781503706824346), + Offset(43.554173693841996, 32.50949551311259), + Offset(43.554173693841996, 32.29485026134325), + Offset(43.554173693841996, 32.1283960707288), + Offset(43.554173693841996, 32.00233286349681), + Offset(43.554173693841996, 31.909924001704802), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + Offset(43.554173693841996, 31.90656), + ], + <Offset>[ + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 55.9765324848), + Offset(48.0, 54.754867779413956), + Offset(48.0, 51.604258802513954), + Offset(48.0, 48.45364982561395), + Offset(48.0, 45.30304084871395), + Offset(48.0, 42.15243187181395), + Offset(48.0, 39.00182289491395), + Offset(48.0, 35.85121391801395), + Offset(48.0, 34.05512107195435), + Offset(48.0, 33.540905901349916), + Offset(48.0, 33.12129231086275), + Offset(48.0, 32.781503706824346), + Offset(48.0, 32.50949551311259), + Offset(48.0, 32.29485026134325), + Offset(48.0, 32.1283960707288), + Offset(48.0, 32.00233286349681), + Offset(48.0, 31.909924001704802), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + Offset(48.0, 31.90656), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + Offset(43.554173693841996, 39.95328), + ], + <Offset>[ + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + Offset(39.95328, 43.554173693841996), + ], + <Offset>[ + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + Offset(39.95328, 48.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + Offset(39.95328, 52.445826306158004), + ], + <Offset>[ + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + Offset(43.554173693841996, 56.04672), + ], + <Offset>[ + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + Offset(48.0, 56.04672), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + Offset(52.445826306158004, 56.04672), + ], + <Offset>[ + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + Offset(56.04672, 52.445826306158004), + ], + <Offset>[ + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + Offset(56.04672, 48.0), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + Offset(56.04672, 43.554173693841996), + ], + <Offset>[ + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + Offset(52.445826306158004, 39.95328), + ], + <Offset>[ + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + Offset(48.0, 39.95328), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 41.2763342754), + Offset(48.0, 44.422639514400004), + Offset(48.0, 47.568944753400004), + Offset(48.0, 50.715249992400004), + Offset(48.0, 53.861555231400004), + Offset(48.0, 57.0078604704), + Offset(48.0, 60.154165709400004), + Offset(48.0, 61.94780621836377), + Offset(48.0, 62.46132080048674), + Offset(48.0, 62.88036269183587), + Offset(48.0, 63.219688353387404), + Offset(48.0, 63.491325951788546), + Offset(48.0, 63.70567876161293), + Offset(48.0, 63.87190616809776), + Offset(48.0, 63.997797621511204), + Offset(48.0, 64.09008058170691), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 40.0563383664), + Offset(43.554173693841996, 41.2763342754), + Offset(43.554173693841996, 44.422639514400004), + Offset(43.554173693841996, 47.568944753400004), + Offset(43.554173693841996, 50.715249992400004), + Offset(43.554173693841996, 53.861555231400004), + Offset(43.554173693841996, 57.0078604704), + Offset(43.554173693841996, 60.154165709400004), + Offset(43.554173693841996, 61.94780621836377), + Offset(43.554173693841996, 62.46132080048674), + Offset(43.554173693841996, 62.88036269183587), + Offset(43.554173693841996, 63.219688353387404), + Offset(43.554173693841996, 63.491325951788546), + Offset(43.554173693841996, 63.70567876161293), + Offset(43.554173693841996, 63.87190616809776), + Offset(43.554173693841996, 63.997797621511204), + Offset(43.554173693841996, 64.09008058170691), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + Offset(43.554173693841996, 64.09344), + ], + <Offset>[ + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 43.65726275604466), + Offset(39.95328, 44.877258665044664), + Offset(39.95328, 48.023563904044664), + Offset(39.95328, 51.169869143044664), + Offset(39.95328, 54.316174382044665), + Offset(39.95328, 57.462479621044665), + Offset(39.95328, 60.608784860044665), + Offset(39.95328, 63.755090099044665), + Offset(39.95328, 65.54873060800844), + Offset(39.95328, 66.0622451901314), + Offset(39.95328, 66.48128708148053), + Offset(39.95328, 66.82061274303207), + Offset(39.95328, 67.09225034143321), + Offset(39.95328, 67.30660315125759), + Offset(39.95328, 67.47283055774243), + Offset(39.95328, 67.59872201115587), + Offset(39.95328, 67.69100497135157), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + Offset(39.95328, 67.69436438964466), + ], + <Offset>[ + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 48.1030583664), + Offset(39.95328, 49.3230542754), + Offset(39.95328, 52.4693595144), + Offset(39.95328, 55.6156647534), + Offset(39.95328, 58.761969992400005), + Offset(39.95328, 61.908275231400005), + Offset(39.95328, 65.0545804704), + Offset(39.95328, 68.20088570940001), + Offset(39.95328, 69.99452621836377), + Offset(39.95328, 70.50804080048674), + Offset(39.95328, 70.92708269183586), + Offset(39.95328, 71.2664083533874), + Offset(39.95328, 71.53804595178855), + Offset(39.95328, 71.75239876161294), + Offset(39.95328, 71.91862616809776), + Offset(39.95328, 72.0445176215112), + Offset(39.95328, 72.13680058170692), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + Offset(39.95328, 72.14016000000001), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 52.548884672558), + Offset(39.95328, 53.768880581558), + Offset(39.95328, 56.915185820558), + Offset(39.95328, 60.061491059558), + Offset(39.95328, 63.20779629855801), + Offset(39.95328, 66.35410153755801), + Offset(39.95328, 69.500406776558), + Offset(39.95328, 72.64671201555801), + Offset(39.95328, 74.44035252452177), + Offset(39.95328, 74.95386710664474), + Offset(39.95328, 75.37290899799387), + Offset(39.95328, 75.7122346595454), + Offset(39.95328, 75.98387225794654), + Offset(39.95328, 76.19822506777093), + Offset(39.95328, 76.36445247425576), + Offset(39.95328, 76.4903439276692), + Offset(39.95328, 76.58262688786492), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + Offset(39.95328, 76.585986306158), + ], + <Offset>[ + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 56.1497783664), + Offset(43.554173693841996, 57.369774275400005), + Offset(43.554173693841996, 60.516079514400005), + Offset(43.554173693841996, 63.662384753400005), + Offset(43.554173693841996, 66.8086899924), + Offset(43.554173693841996, 69.9549952314), + Offset(43.554173693841996, 73.10130047039999), + Offset(43.554173693841996, 76.2476057094), + Offset(43.554173693841996, 78.04124621836377), + Offset(43.554173693841996, 78.55476080048675), + Offset(43.554173693841996, 78.97380269183587), + Offset(43.554173693841996, 79.31312835338741), + Offset(43.554173693841996, 79.58476595178854), + Offset(43.554173693841996, 79.79911876161293), + Offset(43.554173693841996, 79.96534616809777), + Offset(43.554173693841996, 80.0912376215112), + Offset(43.554173693841996, 80.18352058170692), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + Offset(43.554173693841996, 80.18688), + ], + <Offset>[ + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 56.1497783664), + Offset(48.0, 57.369774275400005), + Offset(48.0, 60.516079514400005), + Offset(48.0, 63.662384753400005), + Offset(48.0, 66.8086899924), + Offset(48.0, 69.9549952314), + Offset(48.0, 73.10130047039999), + Offset(48.0, 76.2476057094), + Offset(48.0, 78.04124621836377), + Offset(48.0, 78.55476080048675), + Offset(48.0, 78.97380269183587), + Offset(48.0, 79.31312835338741), + Offset(48.0, 79.58476595178854), + Offset(48.0, 79.79911876161293), + Offset(48.0, 79.96534616809777), + Offset(48.0, 80.0912376215112), + Offset(48.0, 80.18352058170692), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + Offset(48.0, 80.18688), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 56.1497783664), + Offset(52.445826306158004, 57.369774275400005), + Offset(52.445826306158004, 60.516079514400005), + Offset(52.445826306158004, 63.662384753400005), + Offset(52.445826306158004, 66.8086899924), + Offset(52.445826306158004, 69.9549952314), + Offset(52.445826306158004, 73.10130047039999), + Offset(52.445826306158004, 76.2476057094), + Offset(52.445826306158004, 78.04124621836377), + Offset(52.445826306158004, 78.55476080048675), + Offset(52.445826306158004, 78.97380269183587), + Offset(52.445826306158004, 79.31312835338741), + Offset(52.445826306158004, 79.58476595178854), + Offset(52.445826306158004, 79.79911876161293), + Offset(52.445826306158004, 79.96534616809777), + Offset(52.445826306158004, 80.0912376215112), + Offset(52.445826306158004, 80.18352058170692), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + Offset(52.445826306158004, 80.18688), + ], + <Offset>[ + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 52.548884672558), + Offset(56.04672, 53.768880581558), + Offset(56.04672, 56.915185820558), + Offset(56.04672, 60.061491059558), + Offset(56.04672, 63.20779629855801), + Offset(56.04672, 66.35410153755801), + Offset(56.04672, 69.500406776558), + Offset(56.04672, 72.64671201555801), + Offset(56.04672, 74.44035252452177), + Offset(56.04672, 74.95386710664474), + Offset(56.04672, 75.37290899799387), + Offset(56.04672, 75.7122346595454), + Offset(56.04672, 75.98387225794654), + Offset(56.04672, 76.19822506777093), + Offset(56.04672, 76.36445247425576), + Offset(56.04672, 76.4903439276692), + Offset(56.04672, 76.58262688786492), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + Offset(56.04672, 76.585986306158), + ], + <Offset>[ + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 48.1030583664), + Offset(56.04672, 49.3230542754), + Offset(56.04672, 52.4693595144), + Offset(56.04672, 55.6156647534), + Offset(56.04672, 58.761969992400005), + Offset(56.04672, 61.908275231400005), + Offset(56.04672, 65.0545804704), + Offset(56.04672, 68.20088570940001), + Offset(56.04672, 69.99452621836377), + Offset(56.04672, 70.50804080048674), + Offset(56.04672, 70.92708269183586), + Offset(56.04672, 71.2664083533874), + Offset(56.04672, 71.53804595178855), + Offset(56.04672, 71.75239876161294), + Offset(56.04672, 71.91862616809776), + Offset(56.04672, 72.0445176215112), + Offset(56.04672, 72.13680058170692), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + Offset(56.04672, 72.14016000000001), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 43.65726275604466), + Offset(56.04672, 44.877258665044664), + Offset(56.04672, 48.023563904044664), + Offset(56.04672, 51.169869143044664), + Offset(56.04672, 54.316174382044665), + Offset(56.04672, 57.462479621044665), + Offset(56.04672, 60.608784860044665), + Offset(56.04672, 63.755090099044665), + Offset(56.04672, 65.54873060800844), + Offset(56.04672, 66.0622451901314), + Offset(56.04672, 66.48128708148053), + Offset(56.04672, 66.82061274303207), + Offset(56.04672, 67.09225034143321), + Offset(56.04672, 67.30660315125759), + Offset(56.04672, 67.47283055774243), + Offset(56.04672, 67.59872201115587), + Offset(56.04672, 67.69100497135157), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + Offset(56.04672, 67.69436438964466), + ], + <Offset>[ + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 40.0563383664), + Offset(52.445826306158004, 41.2763342754), + Offset(52.445826306158004, 44.422639514400004), + Offset(52.445826306158004, 47.568944753400004), + Offset(52.445826306158004, 50.715249992400004), + Offset(52.445826306158004, 53.861555231400004), + Offset(52.445826306158004, 57.0078604704), + Offset(52.445826306158004, 60.154165709400004), + Offset(52.445826306158004, 61.94780621836377), + Offset(52.445826306158004, 62.46132080048674), + Offset(52.445826306158004, 62.88036269183587), + Offset(52.445826306158004, 63.219688353387404), + Offset(52.445826306158004, 63.491325951788546), + Offset(52.445826306158004, 63.70567876161293), + Offset(52.445826306158004, 63.87190616809776), + Offset(52.445826306158004, 63.997797621511204), + Offset(52.445826306158004, 64.09008058170691), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + Offset(52.445826306158004, 64.09344), + ], + <Offset>[ + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 40.0563383664), + Offset(48.0, 41.2763342754), + Offset(48.0, 44.422639514400004), + Offset(48.0, 47.568944753400004), + Offset(48.0, 50.715249992400004), + Offset(48.0, 53.861555231400004), + Offset(48.0, 57.0078604704), + Offset(48.0, 60.154165709400004), + Offset(48.0, 61.94780621836377), + Offset(48.0, 62.46132080048674), + Offset(48.0, 62.88036269183587), + Offset(48.0, 63.219688353387404), + Offset(48.0, 63.491325951788546), + Offset(48.0, 63.70567876161293), + Offset(48.0, 63.87190616809776), + Offset(48.0, 63.997797621511204), + Offset(48.0, 64.09008058170691), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + Offset(48.0, 64.09344), + ], + ), + _PathClose( + ), + ], + ), + ], +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/view_list.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/view_list.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..65ec982b5b8bfada72c0c9620bd79d30b4933991 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/animated_icons/data/view_list.g.dart @@ -0,0 +1,4237 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// AUTOGENERATED FILE DO NOT EDIT! +// This file was generated by vitool. +part of material_animated_icons; // ignore: use_string_in_part_of_directives +const _AnimatedIconData _$view_list = _AnimatedIconData( + Size(48.0, 48.0), + <_PathFrames>[ + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.634146341463, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(44.69110902782625, 12.484010802427473), + Offset(44.91169585808795, 12.889600531986844), + Offset(45.905579651564764, 15.006358905929599), + Offset(46.93099203454209, 18.091564986244922), + Offset(47.57487910345822, 21.7717551172888), + Offset(47.611090562906426, 25.804550478715143), + Offset(46.90934109732998, 29.991835318680575), + Offset(45.41657507137544, 34.10298531188382), + Offset(43.12531983681261, 37.96288441331596), + Offset(40.11875918372392, 41.34720733654602), + Offset(36.52311532698831, 44.097551654541164), + Offset(32.469796235554185, 46.11340208398952), + Offset(28.106936276731332, 47.32108647595278), + Offset(23.593982433468472, 47.67646826990182), + Offset(19.205125831976975, 47.18941960707135), + Offset(15.060647386344348, 45.9277900128747), + Offset(11.36456649310902, 44.027127105327324), + Offset(8.242362271905536, 41.67588337906012), + Offset(5.7867901900563705, 39.13337333243891), + Offset(4.073681185543615, 36.793819543226384), + Offset(3.3006450057068637, 35.50116093358544), + Offset(3.3000000000000016, 35.5), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.69110902782625, 12.484010802427473), + Offset(44.91169585808795, 12.889600531986844), + Offset(45.905579651564764, 15.006358905929599), + Offset(46.93099203454209, 18.091564986244922), + Offset(47.57487910345822, 21.7717551172888), + Offset(47.611090562906426, 25.804550478715143), + Offset(46.90934109732998, 29.991835318680575), + Offset(45.41657507137544, 34.10298531188382), + Offset(43.12531983681261, 37.96288441331596), + Offset(40.11875918372392, 41.34720733654602), + Offset(36.52311532698831, 44.097551654541164), + Offset(32.469796235554185, 46.11340208398952), + Offset(28.106936276731332, 47.32108647595278), + Offset(23.593982433468472, 47.67646826990182), + Offset(19.205125831976975, 47.18941960707135), + Offset(15.060647386344348, 45.9277900128747), + Offset(11.36456649310902, 44.027127105327324), + Offset(8.242362271905536, 41.67588337906012), + Offset(5.7867901900563705, 39.13337333243891), + Offset(4.073681185543615, 36.793819543226384), + Offset(3.3006450057068637, 35.50116093358544), + Offset(3.3000000000000016, 35.5), + ], + <Offset>[ + Offset(40.091110400688535, 12.487564720144858), + Offset(40.3125022719963, 12.803470643716631), + Offset(41.33730753204713, 14.467016860435445), + Offset(42.479650461341066, 16.931583004189925), + Offset(43.36138596487936, 19.926091125347472), + Offset(43.771900701159595, 23.27065600469687), + Offset(43.58434311086645, 26.813095255382933), + Offset(42.73290999433846, 30.366952422000203), + Offset(41.194877262006315, 33.787553113242254), + Offset(39.018140391822314, 36.880817488479344), + Offset(36.292544012456446, 39.503333889903196), + Offset(33.117698958194936, 41.55925868901449), + Offset(29.60963450105552, 42.973455161476714), + Offset(25.896557894757017, 43.69423946619505), + Offset(22.20703084230837, 43.70394025568405), + Offset(18.647310095538202, 43.04753818178802), + Offset(15.399557758932708, 41.81831622960108), + Offset(12.585723714323475, 40.16088787394561), + Offset(10.307276132541034, 38.28178255994396), + Offset(8.664359809057567, 36.50112554668383), + Offset(7.900644998472249, 35.500902944325), + Offset(7.900000000000001, 35.5), + ], + <Offset>[ + Offset(40.091110400688535, 12.487564720144858), + Offset(40.3125022719963, 12.803470643716631), + Offset(41.33730753204713, 14.467016860435445), + Offset(42.479650461341066, 16.931583004189925), + Offset(43.36138596487936, 19.926091125347472), + Offset(43.771900701159595, 23.27065600469687), + Offset(43.58434311086645, 26.813095255382933), + Offset(42.73290999433846, 30.366952422000203), + Offset(41.194877262006315, 33.787553113242254), + Offset(39.018140391822314, 36.880817488479344), + Offset(36.292544012456446, 39.503333889903196), + Offset(33.117698958194936, 41.55925868901449), + Offset(29.60963450105552, 42.973455161476714), + Offset(25.896557894757017, 43.69423946619505), + Offset(22.20703084230837, 43.70394025568405), + Offset(18.647310095538202, 43.04753818178802), + Offset(15.399557758932708, 41.81831622960108), + Offset(12.585723714323475, 40.16088787394561), + Offset(10.307276132541034, 38.28178255994396), + Offset(8.664359809057567, 36.50112554668383), + Offset(7.900644998472249, 35.500902944325), + Offset(7.900000000000001, 35.5), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(40.091110400688535, 12.487564720144858), + Offset(40.3125022719963, 12.803470643716631), + Offset(41.33730753204713, 14.467016860435445), + Offset(42.479650461341066, 16.931583004189925), + Offset(43.36138596487936, 19.926091125347472), + Offset(43.771900701159595, 23.27065600469687), + Offset(43.58434311086645, 26.813095255382933), + Offset(42.73290999433846, 30.366952422000203), + Offset(41.194877262006315, 33.787553113242254), + Offset(39.018140391822314, 36.880817488479344), + Offset(36.292544012456446, 39.503333889903196), + Offset(33.117698958194936, 41.55925868901449), + Offset(29.60963450105552, 42.973455161476714), + Offset(25.896557894757017, 43.69423946619505), + Offset(22.20703084230837, 43.70394025568405), + Offset(18.647310095538202, 43.04753818178802), + Offset(15.399557758932708, 41.81831622960108), + Offset(12.585723714323475, 40.16088787394561), + Offset(10.307276132541034, 38.28178255994396), + Offset(8.664359809057567, 36.50112554668383), + Offset(7.900644998472249, 35.500902944325), + Offset(7.900000000000001, 35.5), + ], + <Offset>[ + Offset(40.094664318405925, 17.087563347282572), + Offset(40.22637238372609, 17.40266422980828), + Offset(40.79796548655297, 19.035288979953084), + Offset(41.31966847928607, 21.38292457739095), + Offset(41.51572197293803, 24.13958426392634), + Offset(41.23800622714133, 27.109845866443706), + Offset(40.40560304756881, 30.13809324184646), + Offset(38.996877104454846, 33.05061749903718), + Offset(37.01954596193261, 35.717995688048546), + Offset(34.55175054375564, 37.98143628038095), + Offset(31.69832624781848, 39.73390520443506), + Offset(28.563555563219907, 40.91135596637374), + Offset(25.26200318657945, 41.47075693715253), + Offset(21.914329091050245, 41.3916640049065), + Offset(18.72155149092107, 40.702035245352654), + Offset(15.767058264451522, 39.46087547259416), + Offset(13.190746883206462, 37.78332496377739), + Offset(11.070728209208971, 35.817526431527675), + Offset(9.455685360046092, 33.761296617459294), + Offset(8.37166581251501, 31.91044692316988), + Offset(7.90038700921181, 30.900902951559615), + Offset(7.900000000000001, 30.900000000000002), + ], + <Offset>[ + Offset(40.094664318405925, 17.087563347282572), + Offset(40.22637238372609, 17.40266422980828), + Offset(40.79796548655297, 19.035288979953084), + Offset(41.31966847928607, 21.38292457739095), + Offset(41.51572197293803, 24.13958426392634), + Offset(41.23800622714133, 27.109845866443706), + Offset(40.40560304756881, 30.13809324184646), + Offset(38.996877104454846, 33.05061749903718), + Offset(37.01954596193261, 35.717995688048546), + Offset(34.55175054375564, 37.98143628038095), + Offset(31.69832624781848, 39.73390520443506), + Offset(28.563555563219907, 40.91135596637374), + Offset(25.26200318657945, 41.47075693715253), + Offset(21.914329091050245, 41.3916640049065), + Offset(18.72155149092107, 40.702035245352654), + Offset(15.767058264451522, 39.46087547259416), + Offset(13.190746883206462, 37.78332496377739), + Offset(11.070728209208971, 35.817526431527675), + Offset(9.455685360046092, 33.761296617459294), + Offset(8.37166581251501, 31.91044692316988), + Offset(7.90038700921181, 30.900902951559615), + Offset(7.900000000000001, 30.900000000000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(40.094664318405925, 17.087563347282572), + Offset(40.22637238372609, 17.40266422980828), + Offset(40.79796548655297, 19.035288979953084), + Offset(41.31966847928607, 21.38292457739095), + Offset(41.51572197293803, 24.13958426392634), + Offset(41.23800622714133, 27.109845866443706), + Offset(40.40560304756881, 30.13809324184646), + Offset(38.996877104454846, 33.05061749903718), + Offset(37.01954596193261, 35.717995688048546), + Offset(34.55175054375564, 37.98143628038095), + Offset(31.69832624781848, 39.73390520443506), + Offset(28.563555563219907, 40.91135596637374), + Offset(25.26200318657945, 41.47075693715253), + Offset(21.914329091050245, 41.3916640049065), + Offset(18.72155149092107, 40.702035245352654), + Offset(15.767058264451522, 39.46087547259416), + Offset(13.190746883206462, 37.78332496377739), + Offset(11.070728209208971, 35.817526431527675), + Offset(9.455685360046092, 33.761296617459294), + Offset(8.37166581251501, 31.91044692316988), + Offset(7.90038700921181, 30.900902951559615), + Offset(7.900000000000001, 30.900000000000002), + ], + <Offset>[ + Offset(44.69466294554364, 17.084009429565185), + Offset(44.82556596981774, 17.488794118078495), + Offset(45.366237606070605, 19.57463102544724), + Offset(45.7710100524871, 22.542906559445946), + Offset(45.72921511151689, 25.98524825586767), + Offset(45.07719608888816, 29.643740340461978), + Offset(43.73060103403234, 33.3168333051441), + Offset(41.68054218149182, 36.7866503889208), + Offset(38.9499885367389, 39.893326988122254), + Offset(35.65236933565724, 42.44782612844762), + Offset(31.928897562350347, 44.32812296907303), + Offset(27.915652840579153, 45.46549936134877), + Offset(23.75930496225526, 45.8183882516286), + Offset(19.6117536297617, 45.37389280861327), + Offset(15.719646480589672, 44.18751459673995), + Offset(12.180395555257666, 42.34112730368084), + Offset(9.155755617382773, 39.99213583950363), + Offset(6.7273667667910315, 37.33252193664218), + Offset(4.935199417561428, 34.61288738995424), + Offset(3.7809871890010585, 32.20314091971243), + Offset(3.3003870164464253, 30.901160940820056), + Offset(3.3000000000000016, 30.900000000000002), + ], + <Offset>[ + Offset(44.69466294554364, 17.084009429565185), + Offset(44.82556596981774, 17.488794118078495), + Offset(45.366237606070605, 19.57463102544724), + Offset(45.7710100524871, 22.542906559445946), + Offset(45.72921511151689, 25.98524825586767), + Offset(45.07719608888816, 29.643740340461978), + Offset(43.73060103403234, 33.3168333051441), + Offset(41.68054218149182, 36.7866503889208), + Offset(38.9499885367389, 39.893326988122254), + Offset(35.65236933565724, 42.44782612844762), + Offset(31.928897562350347, 44.32812296907303), + Offset(27.915652840579153, 45.46549936134877), + Offset(23.75930496225526, 45.8183882516286), + Offset(19.6117536297617, 45.37389280861327), + Offset(15.719646480589672, 44.18751459673995), + Offset(12.180395555257666, 42.34112730368084), + Offset(9.155755617382773, 39.99213583950363), + Offset(6.7273667667910315, 37.33252193664218), + Offset(4.935199417561428, 34.61288738995424), + Offset(3.7809871890010585, 32.20314091971243), + Offset(3.3003870164464253, 30.901160940820056), + Offset(3.3000000000000016, 30.900000000000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.69466294554364, 17.084009429565185), + Offset(44.82556596981774, 17.488794118078495), + Offset(45.366237606070605, 19.57463102544724), + Offset(45.7710100524871, 22.542906559445946), + Offset(45.72921511151689, 25.98524825586767), + Offset(45.07719608888816, 29.643740340461978), + Offset(43.73060103403234, 33.3168333051441), + Offset(41.68054218149182, 36.7866503889208), + Offset(38.9499885367389, 39.893326988122254), + Offset(35.65236933565724, 42.44782612844762), + Offset(31.928897562350347, 44.32812296907303), + Offset(27.915652840579153, 45.46549936134877), + Offset(23.75930496225526, 45.8183882516286), + Offset(19.6117536297617, 45.37389280861327), + Offset(15.719646480589672, 44.18751459673995), + Offset(12.180395555257666, 42.34112730368084), + Offset(9.155755617382773, 39.99213583950363), + Offset(6.7273667667910315, 37.33252193664218), + Offset(4.935199417561428, 34.61288738995424), + Offset(3.7809871890010585, 32.20314091971243), + Offset(3.3003870164464253, 30.901160940820056), + Offset(3.3000000000000016, 30.900000000000002), + ], + <Offset>[ + Offset(44.69110902782625, 12.484010802427473), + Offset(44.91169585808795, 12.889600531986844), + Offset(45.905579651564764, 15.006358905929599), + Offset(46.93099203454209, 18.091564986244922), + Offset(47.57487910345822, 21.7717551172888), + Offset(47.611090562906426, 25.804550478715143), + Offset(46.90934109732998, 29.991835318680575), + Offset(45.41657507137544, 34.10298531188382), + Offset(43.12531983681261, 37.96288441331596), + Offset(40.11875918372392, 41.34720733654602), + Offset(36.52311532698831, 44.097551654541164), + Offset(32.469796235554185, 46.11340208398952), + Offset(28.106936276731332, 47.32108647595278), + Offset(23.593982433468472, 47.67646826990182), + Offset(19.205125831976975, 47.18941960707135), + Offset(15.060647386344348, 45.9277900128747), + Offset(11.36456649310902, 44.027127105327324), + Offset(8.242362271905536, 41.67588337906012), + Offset(5.7867901900563705, 39.13337333243891), + Offset(4.073681185543615, 36.793819543226384), + Offset(3.3006450057068637, 35.50116093358544), + Offset(3.3000000000000016, 35.5), + ], + <Offset>[ + Offset(44.69110902782625, 12.484010802427473), + Offset(44.91169585808795, 12.889600531986844), + Offset(45.905579651564764, 15.006358905929599), + Offset(46.93099203454209, 18.091564986244922), + Offset(47.57487910345822, 21.7717551172888), + Offset(47.611090562906426, 25.804550478715143), + Offset(46.90934109732998, 29.991835318680575), + Offset(45.41657507137544, 34.10298531188382), + Offset(43.12531983681261, 37.96288441331596), + Offset(40.11875918372392, 41.34720733654602), + Offset(36.52311532698831, 44.097551654541164), + Offset(32.469796235554185, 46.11340208398952), + Offset(28.106936276731332, 47.32108647595278), + Offset(23.593982433468472, 47.67646826990182), + Offset(19.205125831976975, 47.18941960707135), + Offset(15.060647386344348, 45.9277900128747), + Offset(11.36456649310902, 44.027127105327324), + Offset(8.242362271905536, 41.67588337906012), + Offset(5.7867901900563705, 39.13337333243891), + Offset(4.073681185543615, 36.793819543226384), + Offset(3.3006450057068637, 35.50116093358544), + Offset(3.3000000000000016, 35.5), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.634146341463, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(44.7053246986958, 30.884005310978335), + Offset(44.567176305007095, 31.28637487635344), + Offset(43.74821146958815, 33.27944738400016), + Offset(42.29106410632212, 35.896931279049014), + Offset(40.19222313569291, 38.62572767160428), + Offset(37.47551266683334, 41.16130992570247), + Offset(34.19438084413941, 43.291827264534675), + Offset(30.472443511840986, 44.83764562003173), + Offset(26.423994636517765, 45.684654712541146), + Offset(22.25319979145722, 45.749682504152446), + Offset(18.146244268436455, 45.01983691266863), + Offset(14.253222655654064, 43.5217911934265), + Offset(10.71641101882705, 41.31029357865603), + Offset(7.665067218641396, 38.46616642474764), + Offset(5.263208426427763, 35.18179956574576), + Offset(3.5396400619976247, 31.581139176099278), + Offset(2.529322990204036, 27.887162042032575), + Offset(2.1823802514475172, 24.302437609388363), + Offset(2.3804271000766017, 21.051429562500246), + Offset(2.902905199373388, 18.43110504917058), + Offset(3.2996130486651083, 17.1011609625239), + Offset(3.3000000000000016, 17.1), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.7053246986958, 30.884005310978335), + Offset(44.567176305007095, 31.28637487635344), + Offset(43.74821146958815, 33.27944738400016), + Offset(42.29106410632212, 35.896931279049014), + Offset(40.19222313569291, 38.62572767160428), + Offset(37.47551266683334, 41.16130992570247), + Offset(34.19438084413941, 43.291827264534675), + Offset(30.472443511840986, 44.83764562003173), + Offset(26.423994636517765, 45.684654712541146), + Offset(22.25319979145722, 45.749682504152446), + Offset(18.146244268436455, 45.01983691266863), + Offset(14.253222655654064, 43.5217911934265), + Offset(10.71641101882705, 41.31029357865603), + Offset(7.665067218641396, 38.46616642474764), + Offset(5.263208426427763, 35.18179956574576), + Offset(3.5396400619976247, 31.581139176099278), + Offset(2.529322990204036, 27.887162042032575), + Offset(2.1823802514475172, 24.302437609388363), + Offset(2.3804271000766017, 21.051429562500246), + Offset(2.902905199373388, 18.43110504917058), + Offset(3.2996130486651083, 17.1011609625239), + Offset(3.3000000000000016, 17.1), + ], + <Offset>[ + Offset(40.10532607155808, 30.88755922869572), + Offset(39.967982718915444, 31.200244988083227), + Offset(39.17993935007051, 32.740105338506), + Offset(37.83972253312109, 34.73694929699402), + Offset(35.978729997114044, 36.78006367966295), + Offset(33.63632280508651, 38.6274154516842), + Offset(30.869382857675884, 40.113087201237036), + Offset(27.788778434804005, 41.10161273014811), + Offset(24.49355206171147, 41.50932341246744), + Offset(21.152580999555614, 41.28329265608577), + Offset(17.915672953904586, 40.42561914803066), + Offset(14.901125378294816, 38.96764779845147), + Offset(12.219109243151237, 36.96266226417996), + Offset(9.96764267992994, 34.48393762104087), + Offset(8.26511343675916, 31.69632021435846), + Offset(7.126302771191481, 28.7008873450126), + Offset(6.564314256027725, 25.678351166306328), + Offset(6.525741693865457, 22.787442104273858), + Offset(6.900913042561266, 20.199838790005305), + Offset(7.49358382288734, 18.138411052628022), + Offset(7.899613041430493, 17.10090297326346), + Offset(7.900000000000001, 17.1), + ], + <Offset>[ + Offset(40.10532607155808, 30.88755922869572), + Offset(39.967982718915444, 31.200244988083227), + Offset(39.17993935007051, 32.740105338506), + Offset(37.83972253312109, 34.73694929699402), + Offset(35.978729997114044, 36.78006367966295), + Offset(33.63632280508651, 38.6274154516842), + Offset(30.869382857675884, 40.113087201237036), + Offset(27.788778434804005, 41.10161273014811), + Offset(24.49355206171147, 41.50932341246744), + Offset(21.152580999555614, 41.28329265608577), + Offset(17.915672953904586, 40.42561914803066), + Offset(14.901125378294816, 38.96764779845147), + Offset(12.219109243151237, 36.96266226417996), + Offset(9.96764267992994, 34.48393762104087), + Offset(8.26511343675916, 31.69632021435846), + Offset(7.126302771191481, 28.7008873450126), + Offset(6.564314256027725, 25.678351166306328), + Offset(6.525741693865457, 22.787442104273858), + Offset(6.900913042561266, 20.199838790005305), + Offset(7.49358382288734, 18.138411052628022), + Offset(7.899613041430493, 17.10090297326346), + Offset(7.900000000000001, 17.1), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(40.10532607155808, 30.88755922869572), + Offset(39.967982718915444, 31.200244988083227), + Offset(39.17993935007051, 32.740105338506), + Offset(37.83972253312109, 34.73694929699402), + Offset(35.978729997114044, 36.78006367966295), + Offset(33.63632280508651, 38.6274154516842), + Offset(30.869382857675884, 40.113087201237036), + Offset(27.788778434804005, 41.10161273014811), + Offset(24.49355206171147, 41.50932341246744), + Offset(21.152580999555614, 41.28329265608577), + Offset(17.915672953904586, 40.42561914803066), + Offset(14.901125378294816, 38.96764779845147), + Offset(12.219109243151237, 36.96266226417996), + Offset(9.96764267992994, 34.48393762104087), + Offset(8.26511343675916, 31.69632021435846), + Offset(7.126302771191481, 28.7008873450126), + Offset(6.564314256027725, 25.678351166306328), + Offset(6.525741693865457, 22.787442104273858), + Offset(6.900913042561266, 20.199838790005305), + Offset(7.49358382288734, 18.138411052628022), + Offset(7.899613041430493, 17.10090297326346), + Offset(7.900000000000001, 17.1), + ], + <Offset>[ + Offset(40.10887998927547, 35.48755785583344), + Offset(39.88185283064523, 35.79943857417488), + Offset(38.64059730457635, 37.308377458023635), + Offset(36.6797405510661, 39.18829087019505), + Offset(34.13306600517272, 40.993556818241814), + Offset(31.102428331068236, 42.46660531343103), + Offset(27.690642794378242, 43.438085187700565), + Offset(24.05274554492039, 43.78527780718509), + Offset(20.318220761637757, 43.43976598727373), + Offset(16.68619115148894, 42.38391144798737), + Offset(13.321455189266624, 40.65619046256253), + Offset(10.346981983319786, 38.31974507581072), + Offset(7.871477928675166, 35.45996403985578), + Offset(5.985413876223171, 32.181362159752325), + Offset(4.779634085371857, 28.694415204027067), + Offset(4.2460509401048, 25.114224635818744), + Offset(4.355503380301478, 21.64335990048264), + Offset(5.010746188750952, 18.44408066185592), + Offset(6.049322270066323, 15.67935284752064), + Offset(7.200889826344783, 13.547732429114072), + Offset(7.899355052170055, 12.500902980498076), + Offset(7.900000000000001, 12.5), + ], + <Offset>[ + Offset(40.10887998927547, 35.48755785583344), + Offset(39.88185283064523, 35.79943857417488), + Offset(38.64059730457635, 37.308377458023635), + Offset(36.6797405510661, 39.18829087019505), + Offset(34.13306600517272, 40.993556818241814), + Offset(31.102428331068236, 42.46660531343103), + Offset(27.690642794378242, 43.438085187700565), + Offset(24.05274554492039, 43.78527780718509), + Offset(20.318220761637757, 43.43976598727373), + Offset(16.68619115148894, 42.38391144798737), + Offset(13.321455189266624, 40.65619046256253), + Offset(10.346981983319786, 38.31974507581072), + Offset(7.871477928675166, 35.45996403985578), + Offset(5.985413876223171, 32.181362159752325), + Offset(4.779634085371857, 28.694415204027067), + Offset(4.2460509401048, 25.114224635818744), + Offset(4.355503380301478, 21.64335990048264), + Offset(5.010746188750952, 18.44408066185592), + Offset(6.049322270066323, 15.67935284752064), + Offset(7.200889826344783, 13.547732429114072), + Offset(7.899355052170055, 12.500902980498076), + Offset(7.900000000000001, 12.5), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(40.10887998927547, 35.48755785583344), + Offset(39.88185283064523, 35.79943857417488), + Offset(38.64059730457635, 37.308377458023635), + Offset(36.6797405510661, 39.18829087019505), + Offset(34.13306600517272, 40.993556818241814), + Offset(31.102428331068236, 42.46660531343103), + Offset(27.690642794378242, 43.438085187700565), + Offset(24.05274554492039, 43.78527780718509), + Offset(20.318220761637757, 43.43976598727373), + Offset(16.68619115148894, 42.38391144798737), + Offset(13.321455189266624, 40.65619046256253), + Offset(10.346981983319786, 38.31974507581072), + Offset(7.871477928675166, 35.45996403985578), + Offset(5.985413876223171, 32.181362159752325), + Offset(4.779634085371857, 28.694415204027067), + Offset(4.2460509401048, 25.114224635818744), + Offset(4.355503380301478, 21.64335990048264), + Offset(5.010746188750952, 18.44408066185592), + Offset(6.049322270066323, 15.67935284752064), + Offset(7.200889826344783, 13.547732429114072), + Offset(7.899355052170055, 12.500902980498076), + Offset(7.900000000000001, 12.5), + ], + <Offset>[ + Offset(44.70887861641319, 35.48400393811605), + Offset(44.48104641673688, 35.88556846244509), + Offset(43.20886942409399, 37.847719503517794), + Offset(41.131082124267124, 40.34827285225004), + Offset(38.34655914375159, 42.83922081018314), + Offset(34.94161819281507, 45.0004997874493), + Offset(31.015640780841768, 46.616825250998204), + Offset(26.736410621957372, 47.52131069706871), + Offset(22.248663336444054, 47.61509728734744), + Offset(17.786809943390548, 46.85030129605405), + Offset(13.55202650379849, 45.250408227200495), + Offset(9.699079260679033, 42.87388847078575), + Offset(6.3687797043509775, 39.807595354331845), + Offset(3.682838414934627, 36.16359096345909), + Offset(1.77772907504046, 32.179894555414364), + Offset(0.6593882309109436, 27.99447646690542), + Offset(0.32051211447779027, 23.852170776208887), + Offset(0.6673847463330125, 19.959076166970426), + Offset(1.5288363275816592, 16.53094362001558), + Offset(2.6102112028308313, 13.840426425656629), + Offset(3.29935505940467, 12.501160969758514), + Offset(3.3000000000000016, 12.5), + ], + <Offset>[ + Offset(44.70887861641319, 35.48400393811605), + Offset(44.48104641673688, 35.88556846244509), + Offset(43.20886942409399, 37.847719503517794), + Offset(41.131082124267124, 40.34827285225004), + Offset(38.34655914375159, 42.83922081018314), + Offset(34.94161819281507, 45.0004997874493), + Offset(31.015640780841768, 46.616825250998204), + Offset(26.736410621957372, 47.52131069706871), + Offset(22.248663336444054, 47.61509728734744), + Offset(17.786809943390548, 46.85030129605405), + Offset(13.55202650379849, 45.250408227200495), + Offset(9.699079260679033, 42.87388847078575), + Offset(6.3687797043509775, 39.807595354331845), + Offset(3.682838414934627, 36.16359096345909), + Offset(1.77772907504046, 32.179894555414364), + Offset(0.6593882309109436, 27.99447646690542), + Offset(0.32051211447779027, 23.852170776208887), + Offset(0.6673847463330125, 19.959076166970426), + Offset(1.5288363275816592, 16.53094362001558), + Offset(2.6102112028308313, 13.840426425656629), + Offset(3.29935505940467, 12.501160969758514), + Offset(3.3000000000000016, 12.5), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.70887861641319, 35.48400393811605), + Offset(44.48104641673688, 35.88556846244509), + Offset(43.20886942409399, 37.847719503517794), + Offset(41.131082124267124, 40.34827285225004), + Offset(38.34655914375159, 42.83922081018314), + Offset(34.94161819281507, 45.0004997874493), + Offset(31.015640780841768, 46.616825250998204), + Offset(26.736410621957372, 47.52131069706871), + Offset(22.248663336444054, 47.61509728734744), + Offset(17.786809943390548, 46.85030129605405), + Offset(13.55202650379849, 45.250408227200495), + Offset(9.699079260679033, 42.87388847078575), + Offset(6.3687797043509775, 39.807595354331845), + Offset(3.682838414934627, 36.16359096345909), + Offset(1.77772907504046, 32.179894555414364), + Offset(0.6593882309109436, 27.99447646690542), + Offset(0.32051211447779027, 23.852170776208887), + Offset(0.6673847463330125, 19.959076166970426), + Offset(1.5288363275816592, 16.53094362001558), + Offset(2.6102112028308313, 13.840426425656629), + Offset(3.29935505940467, 12.501160969758514), + Offset(3.3000000000000016, 12.5), + ], + <Offset>[ + Offset(44.7053246986958, 30.884005310978335), + Offset(44.567176305007095, 31.28637487635344), + Offset(43.74821146958815, 33.27944738400016), + Offset(42.29106410632212, 35.896931279049014), + Offset(40.19222313569291, 38.62572767160428), + Offset(37.47551266683334, 41.16130992570247), + Offset(34.19438084413941, 43.291827264534675), + Offset(30.472443511840986, 44.83764562003173), + Offset(26.423994636517765, 45.684654712541146), + Offset(22.25319979145722, 45.749682504152446), + Offset(18.146244268436455, 45.01983691266863), + Offset(14.253222655654064, 43.5217911934265), + Offset(10.71641101882705, 41.31029357865603), + Offset(7.665067218641396, 38.46616642474764), + Offset(5.263208426427763, 35.18179956574576), + Offset(3.5396400619976247, 31.581139176099278), + Offset(2.529322990204036, 27.887162042032575), + Offset(2.1823802514475172, 24.302437609388363), + Offset(2.3804271000766017, 21.051429562500246), + Offset(2.902905199373388, 18.43110504917058), + Offset(3.2996130486651083, 17.1011609625239), + Offset(3.3000000000000016, 17.1), + ], + <Offset>[ + Offset(44.7053246986958, 30.884005310978335), + Offset(44.567176305007095, 31.28637487635344), + Offset(43.74821146958815, 33.27944738400016), + Offset(42.29106410632212, 35.896931279049014), + Offset(40.19222313569291, 38.62572767160428), + Offset(37.47551266683334, 41.16130992570247), + Offset(34.19438084413941, 43.291827264534675), + Offset(30.472443511840986, 44.83764562003173), + Offset(26.423994636517765, 45.684654712541146), + Offset(22.25319979145722, 45.749682504152446), + Offset(18.146244268436455, 45.01983691266863), + Offset(14.253222655654064, 43.5217911934265), + Offset(10.71641101882705, 41.31029357865603), + Offset(7.665067218641396, 38.46616642474764), + Offset(5.263208426427763, 35.18179956574576), + Offset(3.5396400619976247, 31.581139176099278), + Offset(2.529322990204036, 27.887162042032575), + Offset(2.1823802514475172, 24.302437609388363), + Offset(2.3804271000766017, 21.051429562500246), + Offset(2.902905199373388, 18.43110504917058), + Offset(3.2996130486651083, 17.1011609625239), + Offset(3.3000000000000016, 17.1), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.634146341463, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(44.698216863261024, 21.684008056702904), + Offset(44.739436081547524, 22.08798770417014), + Offset(44.82689556057646, 24.14290314496488), + Offset(44.611028070432106, 26.99424813264697), + Offset(43.88355111957557, 30.19874139444654), + Offset(42.54330161486988, 33.482930202208806), + Offset(40.55186097073469, 36.64183129160762), + Offset(37.94450929160821, 39.470315465957775), + Offset(34.77465723666519, 41.823769562928554), + Offset(31.18597948759057, 43.548444920349226), + Offset(27.334679797712376, 44.5586942836049), + Offset(23.361509445604124, 44.81759663870801), + Offset(19.41167364777919, 44.315690027304406), + Offset(15.629524826054936, 43.07131734732473), + Offset(12.234167129202369, 41.18560958640855), + Offset(9.300143724170985, 38.754464594487), + Offset(6.946944741656527, 35.95714457367995), + Offset(5.2123712616765285, 32.989160494224244), + Offset(4.0836086450664855, 30.092401447469573), + Offset(3.4882931924585017, 27.61246229619848), + Offset(3.300129027185985, 26.30116094805467), + Offset(3.3000000000000016, 26.3), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.698216863261024, 21.684008056702904), + Offset(44.739436081547524, 22.08798770417014), + Offset(44.82689556057646, 24.14290314496488), + Offset(44.611028070432106, 26.99424813264697), + Offset(43.88355111957557, 30.19874139444654), + Offset(42.54330161486988, 33.482930202208806), + Offset(40.55186097073469, 36.64183129160762), + Offset(37.94450929160821, 39.470315465957775), + Offset(34.77465723666519, 41.823769562928554), + Offset(31.18597948759057, 43.548444920349226), + Offset(27.334679797712376, 44.5586942836049), + Offset(23.361509445604124, 44.81759663870801), + Offset(19.41167364777919, 44.315690027304406), + Offset(15.629524826054936, 43.07131734732473), + Offset(12.234167129202369, 41.18560958640855), + Offset(9.300143724170985, 38.754464594487), + Offset(6.946944741656527, 35.95714457367995), + Offset(5.2123712616765285, 32.989160494224244), + Offset(4.0836086450664855, 30.092401447469573), + Offset(3.4882931924585017, 27.61246229619848), + Offset(3.300129027185985, 26.30116094805467), + Offset(3.3000000000000016, 26.3), + ], + <Offset>[ + Offset(40.09821823612331, 21.68756197442029), + Offset(40.14024249545587, 22.001857815899925), + Offset(40.25862344105882, 23.603561099470724), + Offset(40.15968649723108, 25.834266150591972), + Offset(39.6700579809967, 28.35307740250521), + Offset(38.70411175312305, 30.949035728190534), + Offset(37.22686298427116, 33.463091228309985), + Offset(35.260844214571236, 35.73428257607416), + Offset(32.84421466185889, 37.64843826285484), + Offset(30.085360695688962, 39.08205507228256), + Offset(27.10410848318051, 39.96447651896693), + Offset(24.00941216824488, 40.26345324373298), + Offset(20.914371872103377, 39.96805871282834), + Offset(17.93210028734348, 39.08908854361796), + Offset(15.236072139533766, 37.700130235021255), + Offset(12.88680643336484, 35.874212763400315), + Offset(10.981936007480215, 33.748333697953704), + Offset(9.555732704094467, 31.474164989109738), + Offset(8.604094587551149, 29.240810674974632), + Offset(8.078971815972453, 27.319768299655923), + Offset(7.90012901995137, 26.300902958794232), + Offset(7.900000000000001, 26.3), + ], + <Offset>[ + Offset(40.09821823612331, 21.68756197442029), + Offset(40.14024249545587, 22.001857815899925), + Offset(40.25862344105882, 23.603561099470724), + Offset(40.15968649723108, 25.834266150591972), + Offset(39.6700579809967, 28.35307740250521), + Offset(38.70411175312305, 30.949035728190534), + Offset(37.22686298427116, 33.463091228309985), + Offset(35.260844214571236, 35.73428257607416), + Offset(32.84421466185889, 37.64843826285484), + Offset(30.085360695688962, 39.08205507228256), + Offset(27.10410848318051, 39.96447651896693), + Offset(24.00941216824488, 40.26345324373298), + Offset(20.914371872103377, 39.96805871282834), + Offset(17.93210028734348, 39.08908854361796), + Offset(15.236072139533766, 37.700130235021255), + Offset(12.88680643336484, 35.874212763400315), + Offset(10.981936007480215, 33.748333697953704), + Offset(9.555732704094467, 31.474164989109738), + Offset(8.604094587551149, 29.240810674974632), + Offset(8.078971815972453, 27.319768299655923), + Offset(7.90012901995137, 26.300902958794232), + Offset(7.900000000000001, 26.3), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(40.09821823612331, 21.68756197442029), + Offset(40.14024249545587, 22.001857815899925), + Offset(40.25862344105882, 23.603561099470724), + Offset(40.15968649723108, 25.834266150591972), + Offset(39.6700579809967, 28.35307740250521), + Offset(38.70411175312305, 30.949035728190534), + Offset(37.22686298427116, 33.463091228309985), + Offset(35.260844214571236, 35.73428257607416), + Offset(32.84421466185889, 37.64843826285484), + Offset(30.085360695688962, 39.08205507228256), + Offset(27.10410848318051, 39.96447651896693), + Offset(24.00941216824488, 40.26345324373298), + Offset(20.914371872103377, 39.96805871282834), + Offset(17.93210028734348, 39.08908854361796), + Offset(15.236072139533766, 37.700130235021255), + Offset(12.88680643336484, 35.874212763400315), + Offset(10.981936007480215, 33.748333697953704), + Offset(9.555732704094467, 31.474164989109738), + Offset(8.604094587551149, 29.240810674974632), + Offset(8.078971815972453, 27.319768299655923), + Offset(7.90012901995137, 26.300902958794232), + Offset(7.900000000000001, 26.3), + ], + <Offset>[ + Offset(40.1017721538407, 26.287560601558003), + Offset(40.05411260718566, 26.601051401991576), + Offset(39.719281395564664, 28.171833218988365), + Offset(38.999704515176084, 30.285607723792996), + Offset(37.82439398905538, 32.566570541084076), + Offset(36.17021727910478, 34.78822558993737), + Offset(34.04812292097352, 36.788089214773514), + Offset(31.52481132468762, 38.417947653111135), + Offset(28.66888336178518, 39.57888083766114), + Offset(25.61897084762229, 40.18267386418417), + Offset(22.50989071854255, 40.1950478334988), + Offset(19.455268773269847, 39.61555052109223), + Offset(16.566740557627305, 38.46536048850415), + Offset(13.94987148363671, 36.786513082329414), + Offset(11.750592788146463, 34.69822522468986), + Offset(10.00655460227816, 32.287550054206456), + Offset(8.773125131753968, 29.713342432130013), + Offset(8.040737198979963, 27.130803546691798), + Offset(7.7525038150562064, 24.720324732489967), + Offset(7.7862778194298965, 22.729089676141975), + Offset(7.899871030690932, 21.700902966028845), + Offset(7.900000000000001, 21.7), + ], + <Offset>[ + Offset(40.1017721538407, 26.287560601558003), + Offset(40.05411260718566, 26.601051401991576), + Offset(39.719281395564664, 28.171833218988365), + Offset(38.999704515176084, 30.285607723792996), + Offset(37.82439398905538, 32.566570541084076), + Offset(36.17021727910478, 34.78822558993737), + Offset(34.04812292097352, 36.788089214773514), + Offset(31.52481132468762, 38.417947653111135), + Offset(28.66888336178518, 39.57888083766114), + Offset(25.61897084762229, 40.18267386418417), + Offset(22.50989071854255, 40.1950478334988), + Offset(19.455268773269847, 39.61555052109223), + Offset(16.566740557627305, 38.46536048850415), + Offset(13.94987148363671, 36.786513082329414), + Offset(11.750592788146463, 34.69822522468986), + Offset(10.00655460227816, 32.287550054206456), + Offset(8.773125131753968, 29.713342432130013), + Offset(8.040737198979963, 27.130803546691798), + Offset(7.7525038150562064, 24.720324732489967), + Offset(7.7862778194298965, 22.729089676141975), + Offset(7.899871030690932, 21.700902966028845), + Offset(7.900000000000001, 21.7), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(40.1017721538407, 26.287560601558003), + Offset(40.05411260718566, 26.601051401991576), + Offset(39.719281395564664, 28.171833218988365), + Offset(38.999704515176084, 30.285607723792996), + Offset(37.82439398905538, 32.566570541084076), + Offset(36.17021727910478, 34.78822558993737), + Offset(34.04812292097352, 36.788089214773514), + Offset(31.52481132468762, 38.417947653111135), + Offset(28.66888336178518, 39.57888083766114), + Offset(25.61897084762229, 40.18267386418417), + Offset(22.50989071854255, 40.1950478334988), + Offset(19.455268773269847, 39.61555052109223), + Offset(16.566740557627305, 38.46536048850415), + Offset(13.94987148363671, 36.786513082329414), + Offset(11.750592788146463, 34.69822522468986), + Offset(10.00655460227816, 32.287550054206456), + Offset(8.773125131753968, 29.713342432130013), + Offset(8.040737198979963, 27.130803546691798), + Offset(7.7525038150562064, 24.720324732489967), + Offset(7.7862778194298965, 22.729089676141975), + Offset(7.899871030690932, 21.700902966028845), + Offset(7.900000000000001, 21.7), + ], + <Offset>[ + Offset(44.701770780978414, 26.284006683840616), + Offset(44.65330619327731, 26.68718129026179), + Offset(44.2875535150823, 28.71117526448252), + Offset(43.45104608837711, 31.445589705847993), + Offset(42.03788712763425, 34.412234533025405), + Offset(40.009407140851614, 37.32212006395564), + Offset(37.37312090743705, 39.96682927807115), + Offset(34.208476401724596, 42.15398054299475), + Offset(30.599325936591477, 43.754212137734854), + Offset(26.719589639523896, 44.649063712250836), + Offset(22.740462033074415, 44.789265598136765), + Offset(18.807366050629092, 44.16969391606726), + Offset(15.064042333303117, 42.81299180298022), + Offset(11.647296022348167, 40.76874188603618), + Offset(8.748687777815066, 38.183704576077155), + Offset(6.419891893084303, 35.16780188529314), + Offset(4.73813386593028, 31.92215330785626), + Offset(3.6973757565620238, 28.6457990518063), + Offset(3.2320178725715425, 25.571915504984908), + Offset(3.195599195915945, 23.02178367268453), + Offset(3.2998710379255467, 21.701160955289282), + Offset(3.3000000000000016, 21.7), + ], + <Offset>[ + Offset(44.701770780978414, 26.284006683840616), + Offset(44.65330619327731, 26.68718129026179), + Offset(44.2875535150823, 28.71117526448252), + Offset(43.45104608837711, 31.445589705847993), + Offset(42.03788712763425, 34.412234533025405), + Offset(40.009407140851614, 37.32212006395564), + Offset(37.37312090743705, 39.96682927807115), + Offset(34.208476401724596, 42.15398054299475), + Offset(30.599325936591477, 43.754212137734854), + Offset(26.719589639523896, 44.649063712250836), + Offset(22.740462033074415, 44.789265598136765), + Offset(18.807366050629092, 44.16969391606726), + Offset(15.064042333303117, 42.81299180298022), + Offset(11.647296022348167, 40.76874188603618), + Offset(8.748687777815066, 38.183704576077155), + Offset(6.419891893084303, 35.16780188529314), + Offset(4.73813386593028, 31.92215330785626), + Offset(3.6973757565620238, 28.6457990518063), + Offset(3.2320178725715425, 25.571915504984908), + Offset(3.195599195915945, 23.02178367268453), + Offset(3.2998710379255467, 21.701160955289282), + Offset(3.3000000000000016, 21.7), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(44.701770780978414, 26.284006683840616), + Offset(44.65330619327731, 26.68718129026179), + Offset(44.2875535150823, 28.71117526448252), + Offset(43.45104608837711, 31.445589705847993), + Offset(42.03788712763425, 34.412234533025405), + Offset(40.009407140851614, 37.32212006395564), + Offset(37.37312090743705, 39.96682927807115), + Offset(34.208476401724596, 42.15398054299475), + Offset(30.599325936591477, 43.754212137734854), + Offset(26.719589639523896, 44.649063712250836), + Offset(22.740462033074415, 44.789265598136765), + Offset(18.807366050629092, 44.16969391606726), + Offset(15.064042333303117, 42.81299180298022), + Offset(11.647296022348167, 40.76874188603618), + Offset(8.748687777815066, 38.183704576077155), + Offset(6.419891893084303, 35.16780188529314), + Offset(4.73813386593028, 31.92215330785626), + Offset(3.6973757565620238, 28.6457990518063), + Offset(3.2320178725715425, 25.571915504984908), + Offset(3.195599195915945, 23.02178367268453), + Offset(3.2998710379255467, 21.701160955289282), + Offset(3.3000000000000016, 21.7), + ], + <Offset>[ + Offset(44.698216863261024, 21.684008056702904), + Offset(44.739436081547524, 22.08798770417014), + Offset(44.82689556057646, 24.14290314496488), + Offset(44.611028070432106, 26.99424813264697), + Offset(43.88355111957557, 30.19874139444654), + Offset(42.54330161486988, 33.482930202208806), + Offset(40.55186097073469, 36.64183129160762), + Offset(37.94450929160821, 39.470315465957775), + Offset(34.77465723666519, 41.823769562928554), + Offset(31.18597948759057, 43.548444920349226), + Offset(27.334679797712376, 44.5586942836049), + Offset(23.361509445604124, 44.81759663870801), + Offset(19.41167364777919, 44.315690027304406), + Offset(15.629524826054936, 43.07131734732473), + Offset(12.234167129202369, 41.18560958640855), + Offset(9.300143724170985, 38.754464594487), + Offset(6.946944741656527, 35.95714457367995), + Offset(5.2123712616765285, 32.989160494224244), + Offset(4.0836086450664855, 30.092401447469573), + Offset(3.4882931924585017, 27.61246229619848), + Offset(3.300129027185985, 26.30116094805467), + Offset(3.3000000000000016, 26.3), + ], + <Offset>[ + Offset(44.698216863261024, 21.684008056702904), + Offset(44.739436081547524, 22.08798770417014), + Offset(44.82689556057646, 24.14290314496488), + Offset(44.611028070432106, 26.99424813264697), + Offset(43.88355111957557, 30.19874139444654), + Offset(42.54330161486988, 33.482930202208806), + Offset(40.55186097073469, 36.64183129160762), + Offset(37.94450929160821, 39.470315465957775), + Offset(34.77465723666519, 41.823769562928554), + Offset(31.18597948759057, 43.548444920349226), + Offset(27.334679797712376, 44.5586942836049), + Offset(23.361509445604124, 44.81759663870801), + Offset(19.41167364777919, 44.315690027304406), + Offset(15.629524826054936, 43.07131734732473), + Offset(12.234167129202369, 41.18560958640855), + Offset(9.300143724170985, 38.754464594487), + Offset(6.946944741656527, 35.95714457367995), + Offset(5.2123712616765285, 32.989160494224244), + Offset(4.0836086450664855, 30.092401447469573), + Offset(3.4882931924585017, 27.61246229619848), + Offset(3.300129027185985, 26.30116094805467), + Offset(3.3000000000000016, 26.3), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.634146341463, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(35.49111177355083, 12.491118637862245), + Offset(35.71330868590466, 12.717340755446422), + Offset(36.76903541252949, 13.927674814941295), + Offset(38.028308888140046, 15.771601022134929), + Offset(39.14789282630049, 18.080427133406147), + Offset(39.93271083941276, 20.736761530678603), + Offset(40.25934512440292, 23.63435519208529), + Offset(40.04924491730148, 26.630919532116586), + Offset(39.264434687200016, 29.612221813168535), + Offset(37.917521599920704, 32.41442764041267), + Offset(36.061972697924574, 34.909116125265236), + Offset(33.765601680835694, 37.005115294039456), + Offset(31.112332725379705, 38.625823847000646), + Offset(28.199133356045557, 39.71201066248828), + Offset(25.20893585263977, 40.21846090429675), + Offset(22.23397280473206, 40.167286350701346), + Offset(19.4345490247564, 39.60950535387484), + Offset(16.929085156741415, 38.64589236883111), + Offset(14.827762075025696, 37.430191787449026), + Offset(13.255038432571515, 36.20843155014127), + Offset(12.500644991237632, 35.50064495506456), + Offset(12.5, 35.5), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.49111177355083, 12.491118637862245), + Offset(35.71330868590466, 12.717340755446422), + Offset(36.76903541252949, 13.927674814941295), + Offset(38.028308888140046, 15.771601022134929), + Offset(39.14789282630049, 18.080427133406147), + Offset(39.93271083941276, 20.736761530678603), + Offset(40.25934512440292, 23.63435519208529), + Offset(40.04924491730148, 26.630919532116586), + Offset(39.264434687200016, 29.612221813168535), + Offset(37.917521599920704, 32.41442764041267), + Offset(36.061972697924574, 34.909116125265236), + Offset(33.765601680835694, 37.005115294039456), + Offset(31.112332725379705, 38.625823847000646), + Offset(28.199133356045557, 39.71201066248828), + Offset(25.20893585263977, 40.21846090429675), + Offset(22.23397280473206, 40.167286350701346), + Offset(19.4345490247564, 39.60950535387484), + Offset(16.929085156741415, 38.64589236883111), + Offset(14.827762075025696, 37.430191787449026), + Offset(13.255038432571515, 36.20843155014127), + Offset(12.500644991237632, 35.50064495506456), + Offset(12.5, 35.5), + ], + <Offset>[ + Offset(3.2911213835868267, 12.515996061883946), + Offset(3.5189535832631194, 12.114431537554925), + Offset(4.791130575906015, 10.152280496482213), + Offset(6.868917875732878, 7.651727147749964), + Offset(9.653440856248416, 5.16077918981685), + Offset(13.05838180718493, 2.9995002125507035), + Offset(16.984359219158236, 1.3831747490018031), + Offset(21.26358937804263, 0.47868930293129175), + Offset(25.751336663555943, 0.38490271265255416), + Offset(30.21319005660945, 1.1496987039459512), + Offset(34.44797349620151, 2.7495917727994907), + Offset(38.30092073932097, 5.126111529214247), + Offset(41.63122029564902, 8.192404645668148), + Offset(44.317161585065364, 11.836409036540893), + Offset(46.222270924959545, 15.820105444585629), + Offset(47.34061176908905, 20.005523533094575), + Offset(47.67948788552222, 24.147829223791117), + Offset(47.33261525366699, 28.040923833029577), + Offset(46.47116367241834, 31.469056379984426), + Offset(45.389788797169174, 34.15957357434337), + Offset(44.700644940595325, 35.49883903024149), + Offset(44.699999999999996, 35.5), + ], + <Offset>[ + Offset(3.2911213835868267, 12.515996061883946), + Offset(3.5189535832631194, 12.114431537554925), + Offset(4.791130575906015, 10.152280496482213), + Offset(6.868917875732878, 7.651727147749964), + Offset(9.653440856248416, 5.16077918981685), + Offset(13.05838180718493, 2.9995002125507035), + Offset(16.984359219158236, 1.3831747490018031), + Offset(21.26358937804263, 0.47868930293129175), + Offset(25.751336663555943, 0.38490271265255416), + Offset(30.21319005660945, 1.1496987039459512), + Offset(34.44797349620151, 2.7495917727994907), + Offset(38.30092073932097, 5.126111529214247), + Offset(41.63122029564902, 8.192404645668148), + Offset(44.317161585065364, 11.836409036540893), + Offset(46.222270924959545, 15.820105444585629), + Offset(47.34061176908905, 20.005523533094575), + Offset(47.67948788552222, 24.147829223791117), + Offset(47.33261525366699, 28.040923833029577), + Offset(46.47116367241834, 31.469056379984426), + Offset(45.389788797169174, 34.15957357434337), + Offset(44.700644940595325, 35.49883903024149), + Offset(44.699999999999996, 35.5), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.2911213835868267, 12.515996061883946), + Offset(3.5189535832631194, 12.114431537554925), + Offset(4.791130575906015, 10.152280496482213), + Offset(6.868917875732878, 7.651727147749964), + Offset(9.653440856248416, 5.16077918981685), + Offset(13.05838180718493, 2.9995002125507035), + Offset(16.984359219158236, 1.3831747490018031), + Offset(21.26358937804263, 0.47868930293129175), + Offset(25.751336663555943, 0.38490271265255416), + Offset(30.21319005660945, 1.1496987039459512), + Offset(34.44797349620151, 2.7495917727994907), + Offset(38.30092073932097, 5.126111529214247), + Offset(41.63122029564902, 8.192404645668148), + Offset(44.317161585065364, 11.836409036540893), + Offset(46.222270924959545, 15.820105444585629), + Offset(47.34061176908905, 20.005523533094575), + Offset(47.67948788552222, 24.147829223791117), + Offset(47.33261525366699, 28.040923833029577), + Offset(46.47116367241834, 31.469056379984426), + Offset(45.389788797169174, 34.15957357434337), + Offset(44.700644940595325, 35.49883903024149), + Offset(44.699999999999996, 35.5), + ], + <Offset>[ + Offset(3.29467530130421, 17.11599468902166), + Offset(3.432823694992905, 16.713625123646572), + Offset(4.2517885304118614, 14.720552615999853), + Offset(5.708935893677882, 12.103068720950988), + Offset(7.807776864307087, 9.374272328395719), + Offset(10.524487333166658, 6.838690074297536), + Offset(13.805619155860596, 4.708172735465329), + Offset(17.52755648815902, 3.162354379968269), + Offset(21.57600536348223, 2.3153452874588503), + Offset(25.746800208542776, 2.2503174958475576), + Offset(29.853755731563552, 2.9801630873313556), + Offset(33.74677734434594, 4.478208806573495), + Offset(37.28358898117295, 6.68970642134396), + Offset(40.334932781358596, 9.533833575252348), + Offset(42.73679157357225, 12.81820043425423), + Offset(44.46035993800237, 16.41886082390072), + Offset(45.47067700979597, 20.11283795796743), + Offset(45.81761974855248, 23.697562390611637), + Offset(45.619572899923405, 26.94857043749976), + Offset(45.097094800626614, 29.568894950829417), + Offset(44.70038695133489, 30.898839037476105), + Offset(44.699999999999996, 30.900000000000002), + ], + <Offset>[ + Offset(3.29467530130421, 17.11599468902166), + Offset(3.432823694992905, 16.713625123646572), + Offset(4.2517885304118614, 14.720552615999853), + Offset(5.708935893677882, 12.103068720950988), + Offset(7.807776864307087, 9.374272328395719), + Offset(10.524487333166658, 6.838690074297536), + Offset(13.805619155860596, 4.708172735465329), + Offset(17.52755648815902, 3.162354379968269), + Offset(21.57600536348223, 2.3153452874588503), + Offset(25.746800208542776, 2.2503174958475576), + Offset(29.853755731563552, 2.9801630873313556), + Offset(33.74677734434594, 4.478208806573495), + Offset(37.28358898117295, 6.68970642134396), + Offset(40.334932781358596, 9.533833575252348), + Offset(42.73679157357225, 12.81820043425423), + Offset(44.46035993800237, 16.41886082390072), + Offset(45.47067700979597, 20.11283795796743), + Offset(45.81761974855248, 23.697562390611637), + Offset(45.619572899923405, 26.94857043749976), + Offset(45.097094800626614, 29.568894950829417), + Offset(44.70038695133489, 30.898839037476105), + Offset(44.699999999999996, 30.900000000000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.29467530130421, 17.11599468902166), + Offset(3.432823694992905, 16.713625123646572), + Offset(4.2517885304118614, 14.720552615999853), + Offset(5.708935893677882, 12.103068720950988), + Offset(7.807776864307087, 9.374272328395719), + Offset(10.524487333166658, 6.838690074297536), + Offset(13.805619155860596, 4.708172735465329), + Offset(17.52755648815902, 3.162354379968269), + Offset(21.57600536348223, 2.3153452874588503), + Offset(25.746800208542776, 2.2503174958475576), + Offset(29.853755731563552, 2.9801630873313556), + Offset(33.74677734434594, 4.478208806573495), + Offset(37.28358898117295, 6.68970642134396), + Offset(40.334932781358596, 9.533833575252348), + Offset(42.73679157357225, 12.81820043425423), + Offset(44.46035993800237, 16.41886082390072), + Offset(45.47067700979597, 20.11283795796743), + Offset(45.81761974855248, 23.697562390611637), + Offset(45.619572899923405, 26.94857043749976), + Offset(45.097094800626614, 29.568894950829417), + Offset(44.70038695133489, 30.898839037476105), + Offset(44.699999999999996, 30.900000000000002), + ], + <Offset>[ + Offset(35.49466569126821, 17.09111726499996), + Offset(35.62717879763444, 17.31653434153807), + Offset(36.22969336703533, 18.495946934458935), + Offset(36.86832690608505, 20.22294259533595), + Offset(37.30222883435916, 22.293920271985016), + Offset(37.39881636539449, 24.575951392425434), + Offset(37.08060506110528, 26.959353178548817), + Offset(36.31321202741787, 29.314584609153563), + Offset(35.08910338712631, 31.54266438797483), + Offset(33.45113175185403, 33.51504643231427), + Offset(31.46775493328661, 35.1396874397971), + Offset(29.21145828586066, 36.357212571398705), + Offset(26.764701410903633, 37.123125622676454), + Offset(24.21690455233879, 37.409435201199734), + Offset(21.72345650125247, 37.21655589396535), + Offset(19.353720973645377, 36.580623641507486), + Offset(17.225738149030153, 35.574514088051146), + Offset(15.414089651626908, 34.30253092641317), + Offset(13.976171302530755, 32.90970584496436), + Offset(12.962344436028957, 31.61775292662732), + Offset(12.500387001977192, 30.900644962299175), + Offset(12.5, 30.900000000000002), + ], + <Offset>[ + Offset(35.49466569126821, 17.09111726499996), + Offset(35.62717879763444, 17.31653434153807), + Offset(36.22969336703533, 18.495946934458935), + Offset(36.86832690608505, 20.22294259533595), + Offset(37.30222883435916, 22.293920271985016), + Offset(37.39881636539449, 24.575951392425434), + Offset(37.08060506110528, 26.959353178548817), + Offset(36.31321202741787, 29.314584609153563), + Offset(35.08910338712631, 31.54266438797483), + Offset(33.45113175185403, 33.51504643231427), + Offset(31.46775493328661, 35.1396874397971), + Offset(29.21145828586066, 36.357212571398705), + Offset(26.764701410903633, 37.123125622676454), + Offset(24.21690455233879, 37.409435201199734), + Offset(21.72345650125247, 37.21655589396535), + Offset(19.353720973645377, 36.580623641507486), + Offset(17.225738149030153, 35.574514088051146), + Offset(15.414089651626908, 34.30253092641317), + Offset(13.976171302530755, 32.90970584496436), + Offset(12.962344436028957, 31.61775292662732), + Offset(12.500387001977192, 30.900644962299175), + Offset(12.5, 30.900000000000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.49466569126821, 17.09111726499996), + Offset(35.62717879763444, 17.31653434153807), + Offset(36.22969336703533, 18.495946934458935), + Offset(36.86832690608505, 20.22294259533595), + Offset(37.30222883435916, 22.293920271985016), + Offset(37.39881636539449, 24.575951392425434), + Offset(37.08060506110528, 26.959353178548817), + Offset(36.31321202741787, 29.314584609153563), + Offset(35.08910338712631, 31.54266438797483), + Offset(33.45113175185403, 33.51504643231427), + Offset(31.46775493328661, 35.1396874397971), + Offset(29.21145828586066, 36.357212571398705), + Offset(26.764701410903633, 37.123125622676454), + Offset(24.21690455233879, 37.409435201199734), + Offset(21.72345650125247, 37.21655589396535), + Offset(19.353720973645377, 36.580623641507486), + Offset(17.225738149030153, 35.574514088051146), + Offset(15.414089651626908, 34.30253092641317), + Offset(13.976171302530755, 32.90970584496436), + Offset(12.962344436028957, 31.61775292662732), + Offset(12.500387001977192, 30.900644962299175), + Offset(12.5, 30.900000000000002), + ], + <Offset>[ + Offset(35.49111177355083, 12.491118637862245), + Offset(35.71330868590466, 12.717340755446422), + Offset(36.76903541252949, 13.927674814941295), + Offset(38.028308888140046, 15.771601022134929), + Offset(39.14789282630049, 18.080427133406147), + Offset(39.93271083941276, 20.736761530678603), + Offset(40.25934512440292, 23.63435519208529), + Offset(40.04924491730148, 26.630919532116586), + Offset(39.264434687200016, 29.612221813168535), + Offset(37.917521599920704, 32.41442764041267), + Offset(36.061972697924574, 34.909116125265236), + Offset(33.765601680835694, 37.005115294039456), + Offset(31.112332725379705, 38.625823847000646), + Offset(28.199133356045557, 39.71201066248828), + Offset(25.20893585263977, 40.21846090429675), + Offset(22.23397280473206, 40.167286350701346), + Offset(19.4345490247564, 39.60950535387484), + Offset(16.929085156741415, 38.64589236883111), + Offset(14.827762075025696, 37.430191787449026), + Offset(13.255038432571515, 36.20843155014127), + Offset(12.500644991237632, 35.50064495506456), + Offset(12.5, 35.5), + ], + <Offset>[ + Offset(35.49111177355083, 12.491118637862245), + Offset(35.71330868590466, 12.717340755446422), + Offset(36.76903541252949, 13.927674814941295), + Offset(38.028308888140046, 15.771601022134929), + Offset(39.14789282630049, 18.080427133406147), + Offset(39.93271083941276, 20.736761530678603), + Offset(40.25934512440292, 23.63435519208529), + Offset(40.04924491730148, 26.630919532116586), + Offset(39.264434687200016, 29.612221813168535), + Offset(37.917521599920704, 32.41442764041267), + Offset(36.061972697924574, 34.909116125265236), + Offset(33.765601680835694, 37.005115294039456), + Offset(31.112332725379705, 38.625823847000646), + Offset(28.199133356045557, 39.71201066248828), + Offset(25.20893585263977, 40.21846090429675), + Offset(22.23397280473206, 40.167286350701346), + Offset(19.4345490247564, 39.60950535387484), + Offset(16.929085156741415, 38.64589236883111), + Offset(14.827762075025696, 37.430191787449026), + Offset(13.255038432571515, 36.20843155014127), + Offset(12.500644991237632, 35.50064495506456), + Offset(12.5, 35.5), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.634146341463, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(35.50532744442037, 30.891113146413097), + Offset(35.3687891328238, 31.114115099813013), + Offset(34.61166723055287, 32.200763293011846), + Offset(33.38838095992007, 33.576967314939026), + Offset(31.76523685853518, 34.93439968772162), + Offset(29.797132943339673, 36.093520977665925), + Offset(27.54438487121236, 36.9343471379394), + Offset(25.105113357767024, 37.3655798402645), + Offset(22.563109486905173, 37.333992112393716), + Offset(20.051962207654007, 36.816902808019094), + Offset(17.68510163937272, 35.8314013833927), + Offset(15.549028100935569, 34.41350440347644), + Offset(13.721807467475426, 32.61503094970389), + Offset(12.270218141218486, 30.5017088173341), + Offset(11.267018447090559, 28.21084086297116), + Offset(10.71296548038534, 25.820635513925914), + Offset(10.599305521851413, 23.469540290580085), + Offset(10.869103136283398, 21.272446599159352), + Offset(11.421398985045926, 19.348248017510365), + Offset(12.084262446401288, 17.84571705608547), + Offset(12.499613034195878, 17.100644984003022), + Offset(12.5, 17.1), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.50532744442037, 30.891113146413097), + Offset(35.3687891328238, 31.114115099813013), + Offset(34.61166723055287, 32.200763293011846), + Offset(33.38838095992007, 33.576967314939026), + Offset(31.76523685853518, 34.93439968772162), + Offset(29.797132943339673, 36.093520977665925), + Offset(27.54438487121236, 36.9343471379394), + Offset(25.105113357767024, 37.3655798402645), + Offset(22.563109486905173, 37.333992112393716), + Offset(20.051962207654007, 36.816902808019094), + Offset(17.68510163937272, 35.8314013833927), + Offset(15.549028100935569, 34.41350440347644), + Offset(13.721807467475426, 32.61503094970389), + Offset(12.270218141218486, 30.5017088173341), + Offset(11.267018447090559, 28.21084086297116), + Offset(10.71296548038534, 25.820635513925914), + Offset(10.599305521851413, 23.469540290580085), + Offset(10.869103136283398, 21.272446599159352), + Offset(11.421398985045926, 19.348248017510365), + Offset(12.084262446401288, 17.84571705608547), + Offset(12.499613034195878, 17.100644984003022), + Offset(12.5, 17.1), + ], + <Offset>[ + Offset(3.3053370544563663, 30.9159905704348), + Offset(3.174434030182262, 30.511205881921516), + Offset(2.6337623939293966, 28.42536897455276), + Offset(2.2289899475128987, 25.45709344055406), + Offset(2.270784888483103, 22.014751744132322), + Offset(2.922803911111842, 18.35625965953803), + Offset(4.269398965967673, 14.683166694855906), + Offset(6.3194578185081784, 11.213349611079208), + Offset(9.0500114632611, 8.106673011877739), + Offset(12.347630664342756, 5.552173871552384), + Offset(16.071102437649664, 3.6718770309269573), + Offset(20.084347159420847, 2.534500638651229), + Offset(24.240695037744743, 2.181611748371399), + Offset(28.388246370238292, 2.6261071913867156), + Offset(32.28035351941033, 3.812485403260041), + Offset(35.81960444474234, 5.658872696319149), + Offset(38.844244382617234, 8.007864160496363), + Offset(41.27263323320897, 10.667478063357821), + Offset(43.06480058243858, 13.387112610045765), + Offset(44.21901281099895, 15.796859080287568), + Offset(44.69961298355358, 17.09883905917995), + Offset(44.699999999999996, 17.1), + ], + <Offset>[ + Offset(3.3053370544563663, 30.9159905704348), + Offset(3.174434030182262, 30.511205881921516), + Offset(2.6337623939293966, 28.42536897455276), + Offset(2.2289899475128987, 25.45709344055406), + Offset(2.270784888483103, 22.014751744132322), + Offset(2.922803911111842, 18.35625965953803), + Offset(4.269398965967673, 14.683166694855906), + Offset(6.3194578185081784, 11.213349611079208), + Offset(9.0500114632611, 8.106673011877739), + Offset(12.347630664342756, 5.552173871552384), + Offset(16.071102437649664, 3.6718770309269573), + Offset(20.084347159420847, 2.534500638651229), + Offset(24.240695037744743, 2.181611748371399), + Offset(28.388246370238292, 2.6261071913867156), + Offset(32.28035351941033, 3.812485403260041), + Offset(35.81960444474234, 5.658872696319149), + Offset(38.844244382617234, 8.007864160496363), + Offset(41.27263323320897, 10.667478063357821), + Offset(43.06480058243858, 13.387112610045765), + Offset(44.21901281099895, 15.796859080287568), + Offset(44.69961298355358, 17.09883905917995), + Offset(44.699999999999996, 17.1), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.3053370544563663, 30.9159905704348), + Offset(3.174434030182262, 30.511205881921516), + Offset(2.6337623939293966, 28.42536897455276), + Offset(2.2289899475128987, 25.45709344055406), + Offset(2.270784888483103, 22.014751744132322), + Offset(2.922803911111842, 18.35625965953803), + Offset(4.269398965967673, 14.683166694855906), + Offset(6.3194578185081784, 11.213349611079208), + Offset(9.0500114632611, 8.106673011877739), + Offset(12.347630664342756, 5.552173871552384), + Offset(16.071102437649664, 3.6718770309269573), + Offset(20.084347159420847, 2.534500638651229), + Offset(24.240695037744743, 2.181611748371399), + Offset(28.388246370238292, 2.6261071913867156), + Offset(32.28035351941033, 3.812485403260041), + Offset(35.81960444474234, 5.658872696319149), + Offset(38.844244382617234, 8.007864160496363), + Offset(41.27263323320897, 10.667478063357821), + Offset(43.06480058243858, 13.387112610045765), + Offset(44.21901281099895, 15.796859080287568), + Offset(44.69961298355358, 17.09883905917995), + Offset(44.699999999999996, 17.1), + ], + <Offset>[ + Offset(3.3088909721737494, 35.515989197572516), + Offset(3.0883041419120474, 35.11039946801316), + Offset(2.094420348435243, 32.9936410940704), + Offset(1.069007965457903, 29.90843501375508), + Offset(0.4251208965417739, 26.22824488271119), + Offset(0.3889094370935702, 22.19544952128486), + Offset(1.0906589026700306, 18.008164681319432), + Offset(2.5834249286245647, 13.897014688116185), + Offset(4.874680163187389, 10.037115586684035), + Offset(7.881240816276082, 6.65279266345399), + Offset(11.4768846730117, 3.902448345458822), + Offset(15.530203764445819, 1.8865979160104764), + Offset(19.89306372326867, 0.6789135240472106), + Offset(24.406017566531524, 0.32353173009817127), + Offset(28.794874168023036, 0.8105803929286424), + Offset(32.93935261365566, 2.0722099871252926), + Offset(36.63543350689098, 3.9728728946726743), + Offset(39.757637728094466, 6.324116620939881), + Offset(42.213209809943635, 8.866626667561102), + Offset(43.92631881445639, 11.206180456773618), + Offset(44.69935499429313, 12.498839066414565), + Offset(44.699999999999996, 12.5), + ], + <Offset>[ + Offset(3.3088909721737494, 35.515989197572516), + Offset(3.0883041419120474, 35.11039946801316), + Offset(2.094420348435243, 32.9936410940704), + Offset(1.069007965457903, 29.90843501375508), + Offset(0.4251208965417739, 26.22824488271119), + Offset(0.3889094370935702, 22.19544952128486), + Offset(1.0906589026700306, 18.008164681319432), + Offset(2.5834249286245647, 13.897014688116185), + Offset(4.874680163187389, 10.037115586684035), + Offset(7.881240816276082, 6.65279266345399), + Offset(11.4768846730117, 3.902448345458822), + Offset(15.530203764445819, 1.8865979160104764), + Offset(19.89306372326867, 0.6789135240472106), + Offset(24.406017566531524, 0.32353173009817127), + Offset(28.794874168023036, 0.8105803929286424), + Offset(32.93935261365566, 2.0722099871252926), + Offset(36.63543350689098, 3.9728728946726743), + Offset(39.757637728094466, 6.324116620939881), + Offset(42.213209809943635, 8.866626667561102), + Offset(43.92631881445639, 11.206180456773618), + Offset(44.69935499429313, 12.498839066414565), + Offset(44.699999999999996, 12.5), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.3088909721737494, 35.515989197572516), + Offset(3.0883041419120474, 35.11039946801316), + Offset(2.094420348435243, 32.9936410940704), + Offset(1.069007965457903, 29.90843501375508), + Offset(0.4251208965417739, 26.22824488271119), + Offset(0.3889094370935702, 22.19544952128486), + Offset(1.0906589026700306, 18.008164681319432), + Offset(2.5834249286245647, 13.897014688116185), + Offset(4.874680163187389, 10.037115586684035), + Offset(7.881240816276082, 6.65279266345399), + Offset(11.4768846730117, 3.902448345458822), + Offset(15.530203764445819, 1.8865979160104764), + Offset(19.89306372326867, 0.6789135240472106), + Offset(24.406017566531524, 0.32353173009817127), + Offset(28.794874168023036, 0.8105803929286424), + Offset(32.93935261365566, 2.0722099871252926), + Offset(36.63543350689098, 3.9728728946726743), + Offset(39.757637728094466, 6.324116620939881), + Offset(42.213209809943635, 8.866626667561102), + Offset(43.92631881445639, 11.206180456773618), + Offset(44.69935499429313, 12.498839066414565), + Offset(44.699999999999996, 12.5), + ], + <Offset>[ + Offset(35.50888136213775, 35.49111177355081), + Offset(35.282659244553585, 35.713308685904664), + Offset(34.072325185058716, 36.76903541252948), + Offset(32.22839897786507, 38.028308888140046), + Offset(29.91957286659385, 39.14789282630049), + Offset(27.2632384693214, 39.93271083941276), + Offset(24.365644807914713, 40.25934512440292), + Offset(21.369080467883414, 40.04924491730148), + Offset(18.38777818683146, 39.264434687200016), + Offset(15.585572359587335, 37.917521599920704), + Offset(13.09088387473476, 36.06197269792457), + Offset(10.99488470596054, 33.76560168083569), + Offset(9.374176152999356, 31.112332725379705), + Offset(8.287989337511718, 28.199133356045557), + Offset(7.781539095703257, 25.208935852639762), + Offset(7.8327136492986575, 22.233972804732062), + Offset(8.390494646125166, 19.434549024756393), + Offset(9.354107631168892, 16.929085156741415), + Offset(10.569808212550985, 14.8277620750257), + Offset(11.79156844985873, 13.255038432571517), + Offset(12.499355044935438, 12.500644991237637), + Offset(12.5, 12.5), + ], + <Offset>[ + Offset(35.50888136213775, 35.49111177355081), + Offset(35.282659244553585, 35.713308685904664), + Offset(34.072325185058716, 36.76903541252948), + Offset(32.22839897786507, 38.028308888140046), + Offset(29.91957286659385, 39.14789282630049), + Offset(27.2632384693214, 39.93271083941276), + Offset(24.365644807914713, 40.25934512440292), + Offset(21.369080467883414, 40.04924491730148), + Offset(18.38777818683146, 39.264434687200016), + Offset(15.585572359587335, 37.917521599920704), + Offset(13.09088387473476, 36.06197269792457), + Offset(10.99488470596054, 33.76560168083569), + Offset(9.374176152999356, 31.112332725379705), + Offset(8.287989337511718, 28.199133356045557), + Offset(7.781539095703257, 25.208935852639762), + Offset(7.8327136492986575, 22.233972804732062), + Offset(8.390494646125166, 19.434549024756393), + Offset(9.354107631168892, 16.929085156741415), + Offset(10.569808212550985, 14.8277620750257), + Offset(11.79156844985873, 13.255038432571517), + Offset(12.499355044935438, 12.500644991237637), + Offset(12.5, 12.5), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.50888136213775, 35.49111177355081), + Offset(35.282659244553585, 35.713308685904664), + Offset(34.072325185058716, 36.76903541252948), + Offset(32.22839897786507, 38.028308888140046), + Offset(29.91957286659385, 39.14789282630049), + Offset(27.2632384693214, 39.93271083941276), + Offset(24.365644807914713, 40.25934512440292), + Offset(21.369080467883414, 40.04924491730148), + Offset(18.38777818683146, 39.264434687200016), + Offset(15.585572359587335, 37.917521599920704), + Offset(13.09088387473476, 36.06197269792457), + Offset(10.99488470596054, 33.76560168083569), + Offset(9.374176152999356, 31.112332725379705), + Offset(8.287989337511718, 28.199133356045557), + Offset(7.781539095703257, 25.208935852639762), + Offset(7.8327136492986575, 22.233972804732062), + Offset(8.390494646125166, 19.434549024756393), + Offset(9.354107631168892, 16.929085156741415), + Offset(10.569808212550985, 14.8277620750257), + Offset(11.79156844985873, 13.255038432571517), + Offset(12.499355044935438, 12.500644991237637), + Offset(12.5, 12.5), + ], + <Offset>[ + Offset(35.50532744442037, 30.891113146413097), + Offset(35.3687891328238, 31.114115099813013), + Offset(34.61166723055287, 32.200763293011846), + Offset(33.38838095992007, 33.576967314939026), + Offset(31.76523685853518, 34.93439968772162), + Offset(29.797132943339673, 36.093520977665925), + Offset(27.54438487121236, 36.9343471379394), + Offset(25.105113357767024, 37.3655798402645), + Offset(22.563109486905173, 37.333992112393716), + Offset(20.051962207654007, 36.816902808019094), + Offset(17.68510163937272, 35.8314013833927), + Offset(15.549028100935569, 34.41350440347644), + Offset(13.721807467475426, 32.61503094970389), + Offset(12.270218141218486, 30.5017088173341), + Offset(11.267018447090559, 28.21084086297116), + Offset(10.71296548038534, 25.820635513925914), + Offset(10.599305521851413, 23.469540290580085), + Offset(10.869103136283398, 21.272446599159352), + Offset(11.421398985045926, 19.348248017510365), + Offset(12.084262446401288, 17.84571705608547), + Offset(12.499613034195878, 17.100644984003022), + Offset(12.5, 17.1), + ], + <Offset>[ + Offset(35.50532744442037, 30.891113146413097), + Offset(35.3687891328238, 31.114115099813013), + Offset(34.61166723055287, 32.200763293011846), + Offset(33.38838095992007, 33.576967314939026), + Offset(31.76523685853518, 34.93439968772162), + Offset(29.797132943339673, 36.093520977665925), + Offset(27.54438487121236, 36.9343471379394), + Offset(25.105113357767024, 37.3655798402645), + Offset(22.563109486905173, 37.333992112393716), + Offset(20.051962207654007, 36.816902808019094), + Offset(17.68510163937272, 35.8314013833927), + Offset(15.549028100935569, 34.41350440347644), + Offset(13.721807467475426, 32.61503094970389), + Offset(12.270218141218486, 30.5017088173341), + Offset(11.267018447090559, 28.21084086297116), + Offset(10.71296548038534, 25.820635513925914), + Offset(10.599305521851413, 23.469540290580085), + Offset(10.869103136283398, 21.272446599159352), + Offset(11.421398985045926, 19.348248017510365), + Offset(12.084262446401288, 17.84571705608547), + Offset(12.499613034195878, 17.100644984003022), + Offset(12.5, 17.1), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.634146341463, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(35.4982196089856, 21.691115892137674), + Offset(35.54104890936423, 21.915727927629714), + Offset(35.69035132154117, 23.06421905397657), + Offset(35.70834492403006, 24.67428416853698), + Offset(35.45656484241783, 26.507413410563885), + Offset(34.86492189137621, 28.415141254172266), + Offset(33.901864997807635, 30.284351165012342), + Offset(32.57717913753425, 31.99824968619054), + Offset(30.913772087052596, 33.47310696278113), + Offset(28.984741903787356, 34.61566522421589), + Offset(26.873537168648646, 35.370258754328965), + Offset(24.65731489088563, 35.709309848757954), + Offset(22.41707009642756, 35.62042739835226), + Offset(20.23467574863202, 35.10685973991119), + Offset(18.23797714986516, 34.21465088363395), + Offset(16.473469142558695, 32.99396093231363), + Offset(15.016927273303907, 31.53952282222746), + Offset(13.899094146512402, 29.959169483995232), + Offset(13.124580530035814, 28.389219902479688), + Offset(12.669650439486402, 27.027074303113366), + Offset(12.500129012716759, 26.300644969533792), + Offset(12.5, 26.3), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.4982196089856, 21.691115892137674), + Offset(35.54104890936423, 21.915727927629714), + Offset(35.69035132154117, 23.06421905397657), + Offset(35.70834492403006, 24.67428416853698), + Offset(35.45656484241783, 26.507413410563885), + Offset(34.86492189137621, 28.415141254172266), + Offset(33.901864997807635, 30.284351165012342), + Offset(32.57717913753425, 31.99824968619054), + Offset(30.913772087052596, 33.47310696278113), + Offset(28.984741903787356, 34.61566522421589), + Offset(26.873537168648646, 35.370258754328965), + Offset(24.65731489088563, 35.709309848757954), + Offset(22.41707009642756, 35.62042739835226), + Offset(20.23467574863202, 35.10685973991119), + Offset(18.23797714986516, 34.21465088363395), + Offset(16.473469142558695, 32.99396093231363), + Offset(15.016927273303907, 31.53952282222746), + Offset(13.899094146512402, 29.959169483995232), + Offset(13.124580530035814, 28.389219902479688), + Offset(12.669650439486402, 27.027074303113366), + Offset(12.500129012716759, 26.300644969533792), + Offset(12.5, 26.3), + ], + <Offset>[ + Offset(3.2982292190216, 21.715993316159373), + Offset(3.3466938067226906, 21.312818709738217), + Offset(3.712446484917704, 19.288824735517487), + Offset(4.5489539116228865, 16.554410294152014), + Offset(5.962112872365758, 13.587765466974588), + Offset(7.990592859148386, 10.677879936044366), + Offset(10.626879092562953, 8.033170721928855), + Offset(13.791523598275406, 5.846019457005246), + Offset(17.400674063408523, 4.245787862265146), + Offset(21.280410360476104, 3.350936287749171), + Offset(25.25953796692559, 3.2107344018632205), + Offset(29.192633949370908, 3.8303060839327383), + Offset(32.93595766669688, 5.187008197019772), + Offset(36.35270397765183, 7.231258113963804), + Offset(39.251312222184936, 9.816295423922835), + Offset(41.58010810691569, 12.832198114706863), + Offset(43.26186613406972, 16.07784669214374), + Offset(44.302624243437975, 19.354200948193697), + Offset(44.76798212742847, 22.428084495015092), + Offset(44.80440080408406, 24.978216327315465), + Offset(44.70012896207446, 26.29883904471072), + Offset(44.699999999999996, 26.3), + ], + <Offset>[ + Offset(3.2982292190216, 21.715993316159373), + Offset(3.3466938067226906, 21.312818709738217), + Offset(3.712446484917704, 19.288824735517487), + Offset(4.5489539116228865, 16.554410294152014), + Offset(5.962112872365758, 13.587765466974588), + Offset(7.990592859148386, 10.677879936044366), + Offset(10.626879092562953, 8.033170721928855), + Offset(13.791523598275406, 5.846019457005246), + Offset(17.400674063408523, 4.245787862265146), + Offset(21.280410360476104, 3.350936287749171), + Offset(25.25953796692559, 3.2107344018632205), + Offset(29.192633949370908, 3.8303060839327383), + Offset(32.93595766669688, 5.187008197019772), + Offset(36.35270397765183, 7.231258113963804), + Offset(39.251312222184936, 9.816295423922835), + Offset(41.58010810691569, 12.832198114706863), + Offset(43.26186613406972, 16.07784669214374), + Offset(44.302624243437975, 19.354200948193697), + Offset(44.76798212742847, 22.428084495015092), + Offset(44.80440080408406, 24.978216327315465), + Offset(44.70012896207446, 26.29883904471072), + Offset(44.699999999999996, 26.3), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.2982292190216, 21.715993316159373), + Offset(3.3466938067226906, 21.312818709738217), + Offset(3.712446484917704, 19.288824735517487), + Offset(4.5489539116228865, 16.554410294152014), + Offset(5.962112872365758, 13.587765466974588), + Offset(7.990592859148386, 10.677879936044366), + Offset(10.626879092562953, 8.033170721928855), + Offset(13.791523598275406, 5.846019457005246), + Offset(17.400674063408523, 4.245787862265146), + Offset(21.280410360476104, 3.350936287749171), + Offset(25.25953796692559, 3.2107344018632205), + Offset(29.192633949370908, 3.8303060839327383), + Offset(32.93595766669688, 5.187008197019772), + Offset(36.35270397765183, 7.231258113963804), + Offset(39.251312222184936, 9.816295423922835), + Offset(41.58010810691569, 12.832198114706863), + Offset(43.26186613406972, 16.07784669214374), + Offset(44.302624243437975, 19.354200948193697), + Offset(44.76798212742847, 22.428084495015092), + Offset(44.80440080408406, 24.978216327315465), + Offset(44.70012896207446, 26.29883904471072), + Offset(44.699999999999996, 26.3), + ], + <Offset>[ + Offset(3.301783136738983, 26.315991943297085), + Offset(3.260563918452476, 25.912012295829864), + Offset(3.1731044394235504, 23.857096855035127), + Offset(3.388971929567891, 21.005751867353034), + Offset(4.116448880424429, 17.801258605553457), + Offset(5.456698385130114, 14.517069797791198), + Offset(7.448139029265311, 11.35816870839238), + Offset(10.055490708391792, 8.529684534042223), + Offset(13.225342763334812, 6.1762304370714425), + Offset(16.81402051240943, 4.4515550796507775), + Offset(20.665320202287624, 3.4413057163950853), + Offset(24.63849055439588, 3.1824033612919855), + Offset(28.588326352220808, 3.6843099726955835), + Offset(32.37047517394506, 4.92868265267526), + Offset(35.76583287079764, 6.814390413591436), + Offset(38.699856275829006, 9.245535405513007), + Offset(41.05305525834348, 12.042855426320052), + Offset(42.78762873832347, 15.010839505775758), + Offset(43.91639135493352, 17.90759855253043), + Offset(44.5117068075415, 20.387537703801513), + Offset(44.69987097281401, 21.698839051945335), + Offset(44.699999999999996, 21.7), + ], + <Offset>[ + Offset(3.301783136738983, 26.315991943297085), + Offset(3.260563918452476, 25.912012295829864), + Offset(3.1731044394235504, 23.857096855035127), + Offset(3.388971929567891, 21.005751867353034), + Offset(4.116448880424429, 17.801258605553457), + Offset(5.456698385130114, 14.517069797791198), + Offset(7.448139029265311, 11.35816870839238), + Offset(10.055490708391792, 8.529684534042223), + Offset(13.225342763334812, 6.1762304370714425), + Offset(16.81402051240943, 4.4515550796507775), + Offset(20.665320202287624, 3.4413057163950853), + Offset(24.63849055439588, 3.1824033612919855), + Offset(28.588326352220808, 3.6843099726955835), + Offset(32.37047517394506, 4.92868265267526), + Offset(35.76583287079764, 6.814390413591436), + Offset(38.699856275829006, 9.245535405513007), + Offset(41.05305525834348, 12.042855426320052), + Offset(42.78762873832347, 15.010839505775758), + Offset(43.91639135493352, 17.90759855253043), + Offset(44.5117068075415, 20.387537703801513), + Offset(44.69987097281401, 21.698839051945335), + Offset(44.699999999999996, 21.7), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(3.301783136738983, 26.315991943297085), + Offset(3.260563918452476, 25.912012295829864), + Offset(3.1731044394235504, 23.857096855035127), + Offset(3.388971929567891, 21.005751867353034), + Offset(4.116448880424429, 17.801258605553457), + Offset(5.456698385130114, 14.517069797791198), + Offset(7.448139029265311, 11.35816870839238), + Offset(10.055490708391792, 8.529684534042223), + Offset(13.225342763334812, 6.1762304370714425), + Offset(16.81402051240943, 4.4515550796507775), + Offset(20.665320202287624, 3.4413057163950853), + Offset(24.63849055439588, 3.1824033612919855), + Offset(28.588326352220808, 3.6843099726955835), + Offset(32.37047517394506, 4.92868265267526), + Offset(35.76583287079764, 6.814390413591436), + Offset(38.699856275829006, 9.245535405513007), + Offset(41.05305525834348, 12.042855426320052), + Offset(42.78762873832347, 15.010839505775758), + Offset(43.91639135493352, 17.90759855253043), + Offset(44.5117068075415, 20.387537703801513), + Offset(44.69987097281401, 21.698839051945335), + Offset(44.699999999999996, 21.7), + ], + <Offset>[ + Offset(35.50177352670298, 26.291114519275386), + Offset(35.454919021094014, 26.51492151372136), + Offset(35.15100927604702, 27.63249117349421), + Offset(34.54836294197506, 29.125625741738), + Offset(33.610900850476504, 30.720906549142754), + Offset(32.331027417357944, 32.2543311159191), + Offset(30.723124934509997, 33.60934915147587), + Offset(28.84114624765064, 34.68191476322752), + Offset(26.738440786978884, 35.40354953758742), + Offset(24.518352055720683, 35.71628401611749), + Offset(22.279319404010682, 35.60083006886083), + Offset(20.1031714959106, 35.061407126117196), + Offset(18.06943878195149, 34.11772917402808), + Offset(16.252446944925254, 32.804284278622646), + Offset(14.75249779847786, 31.212745873302556), + Offset(13.593217311472014, 29.407298223119774), + Offset(12.80811639757766, 27.504531556403773), + Offset(12.384098641397896, 25.615808041577292), + Offset(12.272989757540874, 23.868733959995026), + Offset(12.376956442943843, 22.436395679599414), + Offset(12.499871023456318, 21.700644976768405), + Offset(12.5, 21.7), + ], + <Offset>[ + Offset(35.50177352670298, 26.291114519275386), + Offset(35.454919021094014, 26.51492151372136), + Offset(35.15100927604702, 27.63249117349421), + Offset(34.54836294197506, 29.125625741738), + Offset(33.610900850476504, 30.720906549142754), + Offset(32.331027417357944, 32.2543311159191), + Offset(30.723124934509997, 33.60934915147587), + Offset(28.84114624765064, 34.68191476322752), + Offset(26.738440786978884, 35.40354953758742), + Offset(24.518352055720683, 35.71628401611749), + Offset(22.279319404010682, 35.60083006886083), + Offset(20.1031714959106, 35.061407126117196), + Offset(18.06943878195149, 34.11772917402808), + Offset(16.252446944925254, 32.804284278622646), + Offset(14.75249779847786, 31.212745873302556), + Offset(13.593217311472014, 29.407298223119774), + Offset(12.80811639757766, 27.504531556403773), + Offset(12.384098641397896, 25.615808041577292), + Offset(12.272989757540874, 23.868733959995026), + Offset(12.376956442943843, 22.436395679599414), + Offset(12.499871023456318, 21.700644976768405), + Offset(12.5, 21.7), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(35.50177352670298, 26.291114519275386), + Offset(35.454919021094014, 26.51492151372136), + Offset(35.15100927604702, 27.63249117349421), + Offset(34.54836294197506, 29.125625741738), + Offset(33.610900850476504, 30.720906549142754), + Offset(32.331027417357944, 32.2543311159191), + Offset(30.723124934509997, 33.60934915147587), + Offset(28.84114624765064, 34.68191476322752), + Offset(26.738440786978884, 35.40354953758742), + Offset(24.518352055720683, 35.71628401611749), + Offset(22.279319404010682, 35.60083006886083), + Offset(20.1031714959106, 35.061407126117196), + Offset(18.06943878195149, 34.11772917402808), + Offset(16.252446944925254, 32.804284278622646), + Offset(14.75249779847786, 31.212745873302556), + Offset(13.593217311472014, 29.407298223119774), + Offset(12.80811639757766, 27.504531556403773), + Offset(12.384098641397896, 25.615808041577292), + Offset(12.272989757540874, 23.868733959995026), + Offset(12.376956442943843, 22.436395679599414), + Offset(12.499871023456318, 21.700644976768405), + Offset(12.5, 21.7), + ], + <Offset>[ + Offset(35.4982196089856, 21.691115892137674), + Offset(35.54104890936423, 21.915727927629714), + Offset(35.69035132154117, 23.06421905397657), + Offset(35.70834492403006, 24.67428416853698), + Offset(35.45656484241783, 26.507413410563885), + Offset(34.86492189137621, 28.415141254172266), + Offset(33.901864997807635, 30.284351165012342), + Offset(32.57717913753425, 31.99824968619054), + Offset(30.913772087052596, 33.47310696278113), + Offset(28.984741903787356, 34.61566522421589), + Offset(26.873537168648646, 35.370258754328965), + Offset(24.65731489088563, 35.709309848757954), + Offset(22.41707009642756, 35.62042739835226), + Offset(20.23467574863202, 35.10685973991119), + Offset(18.23797714986516, 34.21465088363395), + Offset(16.473469142558695, 32.99396093231363), + Offset(15.016927273303907, 31.53952282222746), + Offset(13.899094146512402, 29.959169483995232), + Offset(13.124580530035814, 28.389219902479688), + Offset(12.669650439486402, 27.027074303113366), + Offset(12.500129012716759, 26.300644969533792), + Offset(12.5, 26.3), + ], + <Offset>[ + Offset(35.4982196089856, 21.691115892137674), + Offset(35.54104890936423, 21.915727927629714), + Offset(35.69035132154117, 23.06421905397657), + Offset(35.70834492403006, 24.67428416853698), + Offset(35.45656484241783, 26.507413410563885), + Offset(34.86492189137621, 28.415141254172266), + Offset(33.901864997807635, 30.284351165012342), + Offset(32.57717913753425, 31.99824968619054), + Offset(30.913772087052596, 33.47310696278113), + Offset(28.984741903787356, 34.61566522421589), + Offset(26.873537168648646, 35.370258754328965), + Offset(24.65731489088563, 35.709309848757954), + Offset(22.41707009642756, 35.62042739835226), + Offset(20.23467574863202, 35.10685973991119), + Offset(18.23797714986516, 34.21465088363395), + Offset(16.473469142558695, 32.99396093231363), + Offset(15.016927273303907, 31.53952282222746), + Offset(13.899094146512402, 29.959169483995232), + Offset(13.124580530035814, 28.389219902479688), + Offset(12.669650439486402, 27.027074303113366), + Offset(12.500129012716759, 26.300644969533792), + Offset(12.5, 26.3), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.390243902439, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(31.500705947534364, 37.904137673197035), + Offset(31.224359596665288, 38.04026654278025), + Offset(29.77500721437707, 38.610257636892996), + Offset(27.671279110116373, 39.06613773120253), + Offset(25.221379281133324, 39.03073015693383), + Offset(22.702260300479338, 38.4714008591571), + Offset(20.28270034295162, 37.48547892474107), + Offset(18.054569997652198, 36.18517574943152), + Offset(16.048128541632522, 34.59627819756455), + Offset(14.343114833822348, 32.739119933221964), + Offset(12.99519031795477, 30.657890586626984), + Offset(12.038214592605321, 28.40198375080891), + Offset(11.498734264325233, 26.032323169068647), + Offset(11.392995785033866, 23.617840044802506), + Offset(11.712187869419232, 21.29019602644484), + Offset(12.42139313017819, 19.101094337832414), + Offset(13.45637301051034, 17.152279319649516), + Offset(14.726397156564566, 15.511205096609956), + Offset(16.093303132855745, 14.22536480165701), + Offset(17.347278595340214, 13.332261414827599), + Offset(18.038917684662923, 12.930905807638549), + Offset(18.039538499999995, 12.930571500000006), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(31.500705947534364, 37.904137673197035), + Offset(31.224359596665288, 38.04026654278025), + Offset(29.77500721437707, 38.610257636892996), + Offset(27.671279110116373, 39.06613773120253), + Offset(25.221379281133324, 39.03073015693383), + Offset(22.702260300479338, 38.4714008591571), + Offset(20.28270034295162, 37.48547892474107), + Offset(18.054569997652198, 36.18517574943152), + Offset(16.048128541632522, 34.59627819756455), + Offset(14.343114833822348, 32.739119933221964), + Offset(12.99519031795477, 30.657890586626984), + Offset(12.038214592605321, 28.40198375080891), + Offset(11.498734264325233, 26.032323169068647), + Offset(11.392995785033866, 23.617840044802506), + Offset(11.712187869419232, 21.29019602644484), + Offset(12.42139313017819, 19.101094337832414), + Offset(13.45637301051034, 17.152279319649516), + Offset(14.726397156564566, 15.511205096609956), + Offset(16.093303132855745, 14.22536480165701), + Offset(17.347278595340214, 13.332261414827599), + Offset(18.038917684662923, 12.930905807638549), + Offset(18.039538499999995, 12.930571500000006), + ], + <Offset>[ + Offset(42.20064775415372, 37.89587099404257), + Offset(41.91674410275704, 38.2405046640102), + Offset(40.34190628686553, 39.857813126404416), + Offset(37.83452426041213, 41.714593496656875), + Offset(34.57684474021924, 43.1287659571083), + Offset(30.91528934967189, 43.89206242373822), + Offset(27.130871371497264, 44.03241690707209), + Offset(23.411876177751978, 43.64328677129125), + Offset(19.813656815016323, 42.74069454351543), + Offset(16.453681942475647, 41.30395235032578), + Offset(13.431837558864594, 39.35824654869015), + Offset(10.822310505850872, 36.948639555937035), + Offset(8.696502202314639, 34.13978724004353), + Offset(7.116981614284766, 31.013066425911557), + Offset(6.150621971699855, 27.74766987427346), + Offset(5.782126079860243, 24.43272505675491), + Offset(5.987301553125755, 21.240953911434477), + Offset(6.686509374540779, 18.31557540123979), + Offset(7.725544616870944, 15.801723190853087), + Offset(8.849588162319126, 13.874059954477616), + Offset(9.523972698054738, 12.931383365108815), + Offset(9.524593499999996, 12.930571500000006), + ], + <Offset>[ + Offset(42.20064775415372, 37.89587099404257), + Offset(41.91674410275704, 38.2405046640102), + Offset(40.34190628686553, 39.857813126404416), + Offset(37.83452426041213, 41.714593496656875), + Offset(34.57684474021924, 43.1287659571083), + Offset(30.91528934967189, 43.89206242373822), + Offset(27.130871371497264, 44.03241690707209), + Offset(23.411876177751978, 43.64328677129125), + Offset(19.813656815016323, 42.74069454351543), + Offset(16.453681942475647, 41.30395235032578), + Offset(13.431837558864594, 39.35824654869015), + Offset(10.822310505850872, 36.948639555937035), + Offset(8.696502202314639, 34.13978724004353), + Offset(7.116981614284766, 31.013066425911557), + Offset(6.150621971699855, 27.74766987427346), + Offset(5.782126079860243, 24.43272505675491), + Offset(5.987301553125755, 21.240953911434477), + Offset(6.686509374540779, 18.31557540123979), + Offset(7.725544616870944, 15.801723190853087), + Offset(8.849588162319126, 13.874059954477616), + Offset(9.523972698054738, 12.931383365108815), + Offset(9.524593499999996, 12.930571500000006), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.20064775415372, 37.89587099404257), + Offset(41.91674410275704, 38.2405046640102), + Offset(40.34190628686553, 39.857813126404416), + Offset(37.83452426041213, 41.714593496656875), + Offset(34.57684474021924, 43.1287659571083), + Offset(30.91528934967189, 43.89206242373822), + Offset(27.130871371497264, 44.03241690707209), + Offset(23.411876177751978, 43.64328677129125), + Offset(19.813656815016323, 42.74069454351543), + Offset(16.453681942475647, 41.30395235032578), + Offset(13.431837558864594, 39.35824654869015), + Offset(10.822310505850872, 36.948639555937035), + Offset(8.696502202314639, 34.13978724004353), + Offset(7.116981614284766, 31.013066425911557), + Offset(6.150621971699855, 27.74766987427346), + Offset(5.782126079860243, 24.43272505675491), + Offset(5.987301553125755, 21.240953911434477), + Offset(6.686509374540779, 18.31557540123979), + Offset(7.725544616870944, 15.801723190853087), + Offset(8.849588162319126, 13.874059954477616), + Offset(9.523972698054738, 12.931383365108815), + Offset(9.524593499999996, 12.930571500000006), + ], + <Offset>[ + Offset(42.19072773916836, 25.055940826099334), + Offset(42.15702984823299, 25.409643256700093), + Offset(41.838972874279236, 27.177534239418264), + Offset(41.01267117895735, 29.518699316301966), + Offset(39.49448770042861, 31.902207406205207), + Offset(37.42008322716923, 34.036427564707154), + Offset(34.987196950294496, 35.814611672817314), + Offset(32.36160940398365, 37.21451935517152), + Offset(29.58695643015737, 38.22206061545487), + Offset(26.731480843000227, 38.77127181994182), + Offset(23.87226471334039, 38.83426985959836), + Offset(21.07829747200463, 38.407724460042374), + Offset(18.4254590874845, 37.50246571445624), + Offset(15.991253271615628, 36.144283430810475), + Offset(13.899590589094196, 34.421548951536714), + Offset(12.180082942567237, 32.39984551713645), + Offset(10.893711063267709, 30.203839660295976), + Offset(10.05175374009658, 27.963440739668336), + Offset(9.617174683906235, 25.84303341003485), + Offset(9.499746409899146, 24.07128847410292), + Offset(9.52454576701906, 23.149317349038636), + Offset(9.524593499999998, 23.148505500000006), + ], + <Offset>[ + Offset(42.19072773916836, 25.055940826099334), + Offset(42.15702984823299, 25.409643256700093), + Offset(41.838972874279236, 27.177534239418264), + Offset(41.01267117895735, 29.518699316301966), + Offset(39.49448770042861, 31.902207406205207), + Offset(37.42008322716923, 34.036427564707154), + Offset(34.987196950294496, 35.814611672817314), + Offset(32.36160940398365, 37.21451935517152), + Offset(29.58695643015737, 38.22206061545487), + Offset(26.731480843000227, 38.77127181994182), + Offset(23.87226471334039, 38.83426985959836), + Offset(21.07829747200463, 38.407724460042374), + Offset(18.4254590874845, 37.50246571445624), + Offset(15.991253271615628, 36.144283430810475), + Offset(13.899590589094196, 34.421548951536714), + Offset(12.180082942567237, 32.39984551713645), + Offset(10.893711063267709, 30.203839660295976), + Offset(10.05175374009658, 27.963440739668336), + Offset(9.617174683906235, 25.84303341003485), + Offset(9.499746409899146, 24.07128847410292), + Offset(9.52454576701906, 23.149317349038636), + Offset(9.524593499999998, 23.148505500000006), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.19072773916836, 25.055940826099334), + Offset(42.15702984823299, 25.409643256700093), + Offset(41.838972874279236, 27.177534239418264), + Offset(41.01267117895735, 29.518699316301966), + Offset(39.49448770042861, 31.902207406205207), + Offset(37.42008322716923, 34.036427564707154), + Offset(34.987196950294496, 35.814611672817314), + Offset(32.36160940398365, 37.21451935517152), + Offset(29.58695643015737, 38.22206061545487), + Offset(26.731480843000227, 38.77127181994182), + Offset(23.87226471334039, 38.83426985959836), + Offset(21.07829747200463, 38.407724460042374), + Offset(18.4254590874845, 37.50246571445624), + Offset(15.991253271615628, 36.144283430810475), + Offset(13.899590589094196, 34.421548951536714), + Offset(12.180082942567237, 32.39984551713645), + Offset(10.893711063267709, 30.203839660295976), + Offset(10.05175374009658, 27.963440739668336), + Offset(9.617174683906235, 25.84303341003485), + Offset(9.499746409899146, 24.07128847410292), + Offset(9.52454576701906, 23.149317349038636), + Offset(9.524593499999998, 23.148505500000006), + ], + <Offset>[ + Offset(31.490785932549, 25.064207505253805), + Offset(31.46464534214123, 25.209405135470142), + Offset(31.272073801790775, 25.92997874990684), + Offset(30.84942602866159, 26.87024355084762), + Offset(30.139022241342694, 27.80417160603073), + Offset(29.207054177976676, 28.615766000126037), + Offset(28.139025921748853, 29.26767369048629), + Offset(27.004303223883873, 29.75640833331179), + Offset(25.82142815677357, 30.077644269503992), + Offset(24.620913734346928, 30.206439402838008), + Offset(23.435617472430565, 30.133913897535194), + Offset(22.294201558759077, 29.861068654914245), + Offset(21.227691149495094, 29.395001643481358), + Offset(20.267267442364727, 28.749057049701424), + Offset(19.46115648681357, 27.964075103708094), + Offset(18.819349992885186, 27.06821479821395), + Offset(18.362782520652296, 26.115165068511015), + Offset(18.091641522120366, 25.1590704350385), + Offset(17.984933199891035, 24.26667502083877), + Offset(17.997436842920234, 23.529489934452904), + Offset(18.039490753627245, 23.14883979156837), + Offset(18.0395385, 23.148505500000006), + ], + <Offset>[ + Offset(31.490785932549, 25.064207505253805), + Offset(31.46464534214123, 25.209405135470142), + Offset(31.272073801790775, 25.92997874990684), + Offset(30.84942602866159, 26.87024355084762), + Offset(30.139022241342694, 27.80417160603073), + Offset(29.207054177976676, 28.615766000126037), + Offset(28.139025921748853, 29.26767369048629), + Offset(27.004303223883873, 29.75640833331179), + Offset(25.82142815677357, 30.077644269503992), + Offset(24.620913734346928, 30.206439402838008), + Offset(23.435617472430565, 30.133913897535194), + Offset(22.294201558759077, 29.861068654914245), + Offset(21.227691149495094, 29.395001643481358), + Offset(20.267267442364727, 28.749057049701424), + Offset(19.46115648681357, 27.964075103708094), + Offset(18.819349992885186, 27.06821479821395), + Offset(18.362782520652296, 26.115165068511015), + Offset(18.091641522120366, 25.1590704350385), + Offset(17.984933199891035, 24.26667502083877), + Offset(17.997436842920234, 23.529489934452904), + Offset(18.039490753627245, 23.14883979156837), + Offset(18.0395385, 23.148505500000006), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(31.490785932549, 25.064207505253805), + Offset(31.46464534214123, 25.209405135470142), + Offset(31.272073801790775, 25.92997874990684), + Offset(30.84942602866159, 26.87024355084762), + Offset(30.139022241342694, 27.80417160603073), + Offset(29.207054177976676, 28.615766000126037), + Offset(28.139025921748853, 29.26767369048629), + Offset(27.004303223883873, 29.75640833331179), + Offset(25.82142815677357, 30.077644269503992), + Offset(24.620913734346928, 30.206439402838008), + Offset(23.435617472430565, 30.133913897535194), + Offset(22.294201558759077, 29.861068654914245), + Offset(21.227691149495094, 29.395001643481358), + Offset(20.267267442364727, 28.749057049701424), + Offset(19.46115648681357, 27.964075103708094), + Offset(18.819349992885186, 27.06821479821395), + Offset(18.362782520652296, 26.115165068511015), + Offset(18.091641522120366, 25.1590704350385), + Offset(17.984933199891035, 24.26667502083877), + Offset(17.997436842920234, 23.529489934452904), + Offset(18.039490753627245, 23.14883979156837), + Offset(18.0395385, 23.148505500000006), + ], + <Offset>[ + Offset(31.500705947534364, 37.904137673197035), + Offset(31.224359596665288, 38.04026654278025), + Offset(29.77500721437707, 38.610257636892996), + Offset(27.671279110116373, 39.06613773120253), + Offset(25.221379281133324, 39.03073015693383), + Offset(22.702260300479338, 38.4714008591571), + Offset(20.28270034295162, 37.48547892474107), + Offset(18.054569997652198, 36.18517574943152), + Offset(16.048128541632522, 34.59627819756455), + Offset(14.343114833822348, 32.739119933221964), + Offset(12.99519031795477, 30.657890586626984), + Offset(12.038214592605321, 28.40198375080891), + Offset(11.498734264325233, 26.032323169068647), + Offset(11.392995785033866, 23.617840044802506), + Offset(11.712187869419232, 21.29019602644484), + Offset(12.42139313017819, 19.101094337832414), + Offset(13.45637301051034, 17.152279319649516), + Offset(14.726397156564566, 15.511205096609956), + Offset(16.093303132855745, 14.22536480165701), + Offset(17.347278595340214, 13.332261414827599), + Offset(18.038917684662923, 12.930905807638549), + Offset(18.039538499999995, 12.930571500000006), + ], + <Offset>[ + Offset(31.500705947534364, 37.904137673197035), + Offset(31.224359596665288, 38.04026654278025), + Offset(29.77500721437707, 38.610257636892996), + Offset(27.671279110116373, 39.06613773120253), + Offset(25.221379281133324, 39.03073015693383), + Offset(22.702260300479338, 38.4714008591571), + Offset(20.28270034295162, 37.48547892474107), + Offset(18.054569997652198, 36.18517574943152), + Offset(16.048128541632522, 34.59627819756455), + Offset(14.343114833822348, 32.739119933221964), + Offset(12.99519031795477, 30.657890586626984), + Offset(12.038214592605321, 28.40198375080891), + Offset(11.498734264325233, 26.032323169068647), + Offset(11.392995785033866, 23.617840044802506), + Offset(11.712187869419232, 21.29019602644484), + Offset(12.42139313017819, 19.101094337832414), + Offset(13.45637301051034, 17.152279319649516), + Offset(14.726397156564566, 15.511205096609956), + Offset(16.093303132855745, 14.22536480165701), + Offset(17.347278595340214, 13.332261414827599), + Offset(18.038917684662923, 12.930905807638549), + Offset(18.039538499999995, 12.930571500000006), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.390243902439, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(5.809272260831642, 22.944059173900662), + Offset(5.842970151767011, 22.590356743299907), + Offset(6.161027125720756, 20.822465760581736), + Offset(6.987328821042649, 18.48130068369803), + Offset(8.505512299571395, 16.097792593794804), + Offset(10.579916772830773, 13.963572435292853), + Offset(13.012803049705509, 12.18538832718269), + Offset(15.638390596016343, 10.785480644828485), + Offset(18.413043569842625, 9.77793938454513), + Offset(21.26851915699977, 9.228728180058184), + Offset(24.12773528665962, 9.165730140401642), + Offset(26.92170252799538, 9.592275539957622), + Offset(29.5745409125155, 10.497534285543754), + Offset(32.008746728384374, 11.855716569189521), + Offset(34.100409410905804, 13.578451048463291), + Offset(35.819917057432754, 15.600154482863552), + Offset(37.10628893673229, 17.796160339704027), + Offset(37.94824625990342, 20.03655926033166), + Offset(38.38282531609377, 22.156966589965144), + Offset(38.50025359010085, 23.928711525897086), + Offset(38.47545423298094, 24.850682650961364), + Offset(38.4754065, 24.8514945), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(5.809272260831642, 22.944059173900662), + Offset(5.842970151767011, 22.590356743299907), + Offset(6.161027125720756, 20.822465760581736), + Offset(6.987328821042649, 18.48130068369803), + Offset(8.505512299571395, 16.097792593794804), + Offset(10.579916772830773, 13.963572435292853), + Offset(13.012803049705509, 12.18538832718269), + Offset(15.638390596016343, 10.785480644828485), + Offset(18.413043569842625, 9.77793938454513), + Offset(21.26851915699977, 9.228728180058184), + Offset(24.12773528665962, 9.165730140401642), + Offset(26.92170252799538, 9.592275539957622), + Offset(29.5745409125155, 10.497534285543754), + Offset(32.008746728384374, 11.855716569189521), + Offset(34.100409410905804, 13.578451048463291), + Offset(35.819917057432754, 15.600154482863552), + Offset(37.10628893673229, 17.796160339704027), + Offset(37.94824625990342, 20.03655926033166), + Offset(38.38282531609377, 22.156966589965144), + Offset(38.50025359010085, 23.928711525897086), + Offset(38.47545423298094, 24.850682650961364), + Offset(38.4754065, 24.8514945), + ], + <Offset>[ + Offset(16.509214067451, 22.93579249474619), + Offset(16.53535465785877, 22.790594864529858), + Offset(16.727926198209218, 22.07002125009316), + Offset(17.150573971338403, 21.129756449152378), + Offset(17.86097775865731, 20.19582839396928), + Offset(18.792945822023324, 19.38423399987397), + Offset(19.860974078251154, 18.732326309513716), + Offset(20.995696776116127, 18.24359166668821), + Offset(22.178571843226425, 17.922355730496008), + Offset(23.379086265653072, 17.793560597162), + Offset(24.564382527569446, 17.866086102464806), + Offset(25.70579844124093, 18.13893134508575), + Offset(26.772308850504906, 18.60499835651864), + Offset(27.732732557635273, 19.250942950298572), + Offset(28.53884351318643, 20.03592489629191), + Offset(29.180650007114806, 20.93178520178605), + Offset(29.637217479347704, 21.88483493148899), + Offset(29.908358477879634, 22.840929564961495), + Offset(30.015066800108972, 23.733324979161225), + Offset(30.00256315707976, 24.470510065547103), + Offset(29.960509246372755, 24.85116020843163), + Offset(29.9604615, 24.8514945), + ], + <Offset>[ + Offset(16.509214067451, 22.93579249474619), + Offset(16.53535465785877, 22.790594864529858), + Offset(16.727926198209218, 22.07002125009316), + Offset(17.150573971338403, 21.129756449152378), + Offset(17.86097775865731, 20.19582839396928), + Offset(18.792945822023324, 19.38423399987397), + Offset(19.860974078251154, 18.732326309513716), + Offset(20.995696776116127, 18.24359166668821), + Offset(22.178571843226425, 17.922355730496008), + Offset(23.379086265653072, 17.793560597162), + Offset(24.564382527569446, 17.866086102464806), + Offset(25.70579844124093, 18.13893134508575), + Offset(26.772308850504906, 18.60499835651864), + Offset(27.732732557635273, 19.250942950298572), + Offset(28.53884351318643, 20.03592489629191), + Offset(29.180650007114806, 20.93178520178605), + Offset(29.637217479347704, 21.88483493148899), + Offset(29.908358477879634, 22.840929564961495), + Offset(30.015066800108972, 23.733324979161225), + Offset(30.00256315707976, 24.470510065547103), + Offset(29.960509246372755, 24.85116020843163), + Offset(29.9604615, 24.8514945), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(16.509214067451, 22.93579249474619), + Offset(16.53535465785877, 22.790594864529858), + Offset(16.727926198209218, 22.07002125009316), + Offset(17.150573971338403, 21.129756449152378), + Offset(17.86097775865731, 20.19582839396928), + Offset(18.792945822023324, 19.38423399987397), + Offset(19.860974078251154, 18.732326309513716), + Offset(20.995696776116127, 18.24359166668821), + Offset(22.178571843226425, 17.922355730496008), + Offset(23.379086265653072, 17.793560597162), + Offset(24.564382527569446, 17.866086102464806), + Offset(25.70579844124093, 18.13893134508575), + Offset(26.772308850504906, 18.60499835651864), + Offset(27.732732557635273, 19.250942950298572), + Offset(28.53884351318643, 20.03592489629191), + Offset(29.180650007114806, 20.93178520178605), + Offset(29.637217479347704, 21.88483493148899), + Offset(29.908358477879634, 22.840929564961495), + Offset(30.015066800108972, 23.733324979161225), + Offset(30.00256315707976, 24.470510065547103), + Offset(29.960509246372755, 24.85116020843163), + Offset(29.9604615, 24.8514945), + ], + <Offset>[ + Offset(16.49929405246564, 10.095862326802958), + Offset(16.775640403334712, 9.95973345721975), + Offset(18.224992785622923, 9.389742363107004), + Offset(20.328720889883623, 8.93386226879747), + Offset(22.778620718866684, 8.969269843066183), + Offset(25.297739699520662, 9.528599140842907), + Offset(27.717299657048386, 10.514521075258944), + Offset(29.9454300023478, 11.814824250568474), + Offset(31.951871458367474, 13.403721802435447), + Offset(33.656885166177645, 15.26088006677804), + Offset(35.00480968204524, 17.342109413373016), + Offset(35.961785407394686, 19.59801624919109), + Offset(36.501265735674764, 21.96767683093135), + Offset(36.60700421496613, 24.38215995519749), + Offset(36.28781213058077, 26.70980397355516), + Offset(35.578606869821805, 28.898905662167586), + Offset(34.54362698948966, 30.847720680350488), + Offset(33.273602843435434, 32.48879490339004), + Offset(31.906696867144262, 33.774635198342985), + Offset(30.65272140465978, 34.66773858517241), + Offset(29.961082315337077, 35.069094192361455), + Offset(29.9604615, 35.0694285), + ], + <Offset>[ + Offset(16.49929405246564, 10.095862326802958), + Offset(16.775640403334712, 9.95973345721975), + Offset(18.224992785622923, 9.389742363107004), + Offset(20.328720889883623, 8.93386226879747), + Offset(22.778620718866684, 8.969269843066183), + Offset(25.297739699520662, 9.528599140842907), + Offset(27.717299657048386, 10.514521075258944), + Offset(29.9454300023478, 11.814824250568474), + Offset(31.951871458367474, 13.403721802435447), + Offset(33.656885166177645, 15.26088006677804), + Offset(35.00480968204524, 17.342109413373016), + Offset(35.961785407394686, 19.59801624919109), + Offset(36.501265735674764, 21.96767683093135), + Offset(36.60700421496613, 24.38215995519749), + Offset(36.28781213058077, 26.70980397355516), + Offset(35.578606869821805, 28.898905662167586), + Offset(34.54362698948966, 30.847720680350488), + Offset(33.273602843435434, 32.48879490339004), + Offset(31.906696867144262, 33.774635198342985), + Offset(30.65272140465978, 34.66773858517241), + Offset(29.961082315337077, 35.069094192361455), + Offset(29.9604615, 35.0694285), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(16.49929405246564, 10.095862326802958), + Offset(16.775640403334712, 9.95973345721975), + Offset(18.224992785622923, 9.389742363107004), + Offset(20.328720889883623, 8.93386226879747), + Offset(22.778620718866684, 8.969269843066183), + Offset(25.297739699520662, 9.528599140842907), + Offset(27.717299657048386, 10.514521075258944), + Offset(29.9454300023478, 11.814824250568474), + Offset(31.951871458367474, 13.403721802435447), + Offset(33.656885166177645, 15.26088006677804), + Offset(35.00480968204524, 17.342109413373016), + Offset(35.961785407394686, 19.59801624919109), + Offset(36.501265735674764, 21.96767683093135), + Offset(36.60700421496613, 24.38215995519749), + Offset(36.28781213058077, 26.70980397355516), + Offset(35.578606869821805, 28.898905662167586), + Offset(34.54362698948966, 30.847720680350488), + Offset(33.273602843435434, 32.48879490339004), + Offset(31.906696867144262, 33.774635198342985), + Offset(30.65272140465978, 34.66773858517241), + Offset(29.961082315337077, 35.069094192361455), + Offset(29.9604615, 35.0694285), + ], + <Offset>[ + Offset(5.799352245846278, 10.104129005957429), + Offset(6.083255897242955, 9.759495335989797), + Offset(7.658093713134462, 8.14218687359558), + Offset(10.165475739587867, 6.285406503343122), + Offset(13.423155259780767, 4.871234042891707), + Offset(17.08471065032811, 4.107937576261792), + Offset(20.869128628502743, 3.9675830929279154), + Offset(24.588123822248015, 4.356713228708747), + Offset(28.186343184983674, 5.2593054564845705), + Offset(31.546318057524346, 6.696047649674224), + Offset(34.56816244113542, 8.641753451309853), + Offset(37.177689494149135, 11.051360444062961), + Offset(39.30349779768536, 13.860212759956465), + Offset(40.88301838571523, 16.98693357408844), + Offset(41.849378028300144, 20.252330125726544), + Offset(42.21787392013975, 23.56727494324509), + Offset(42.012698446874246, 26.759046088565526), + Offset(41.313490625459224, 29.684424598760206), + Offset(40.274455383129066, 32.198276809146904), + Offset(39.15041183768086, 34.12594004552239), + Offset(38.476027301945265, 35.068616634891185), + Offset(38.4754065, 35.0694285), + ], + <Offset>[ + Offset(5.799352245846278, 10.104129005957429), + Offset(6.083255897242955, 9.759495335989797), + Offset(7.658093713134462, 8.14218687359558), + Offset(10.165475739587867, 6.285406503343122), + Offset(13.423155259780767, 4.871234042891707), + Offset(17.08471065032811, 4.107937576261792), + Offset(20.869128628502743, 3.9675830929279154), + Offset(24.588123822248015, 4.356713228708747), + Offset(28.186343184983674, 5.2593054564845705), + Offset(31.546318057524346, 6.696047649674224), + Offset(34.56816244113542, 8.641753451309853), + Offset(37.177689494149135, 11.051360444062961), + Offset(39.30349779768536, 13.860212759956465), + Offset(40.88301838571523, 16.98693357408844), + Offset(41.849378028300144, 20.252330125726544), + Offset(42.21787392013975, 23.56727494324509), + Offset(42.012698446874246, 26.759046088565526), + Offset(41.313490625459224, 29.684424598760206), + Offset(40.274455383129066, 32.198276809146904), + Offset(39.15041183768086, 34.12594004552239), + Offset(38.476027301945265, 35.068616634891185), + Offset(38.4754065, 35.0694285), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(5.799352245846278, 10.104129005957429), + Offset(6.083255897242955, 9.759495335989797), + Offset(7.658093713134462, 8.14218687359558), + Offset(10.165475739587867, 6.285406503343122), + Offset(13.423155259780767, 4.871234042891707), + Offset(17.08471065032811, 4.107937576261792), + Offset(20.869128628502743, 3.9675830929279154), + Offset(24.588123822248015, 4.356713228708747), + Offset(28.186343184983674, 5.2593054564845705), + Offset(31.546318057524346, 6.696047649674224), + Offset(34.56816244113542, 8.641753451309853), + Offset(37.177689494149135, 11.051360444062961), + Offset(39.30349779768536, 13.860212759956465), + Offset(40.88301838571523, 16.98693357408844), + Offset(41.849378028300144, 20.252330125726544), + Offset(42.21787392013975, 23.56727494324509), + Offset(42.012698446874246, 26.759046088565526), + Offset(41.313490625459224, 29.684424598760206), + Offset(40.274455383129066, 32.198276809146904), + Offset(39.15041183768086, 34.12594004552239), + Offset(38.476027301945265, 35.068616634891185), + Offset(38.4754065, 35.0694285), + ], + <Offset>[ + Offset(5.809272260831642, 22.944059173900662), + Offset(5.842970151767011, 22.590356743299907), + Offset(6.161027125720756, 20.822465760581736), + Offset(6.987328821042649, 18.48130068369803), + Offset(8.505512299571395, 16.097792593794804), + Offset(10.579916772830773, 13.963572435292853), + Offset(13.012803049705509, 12.18538832718269), + Offset(15.638390596016343, 10.785480644828485), + Offset(18.413043569842625, 9.77793938454513), + Offset(21.26851915699977, 9.228728180058184), + Offset(24.12773528665962, 9.165730140401642), + Offset(26.92170252799538, 9.592275539957622), + Offset(29.5745409125155, 10.497534285543754), + Offset(32.008746728384374, 11.855716569189521), + Offset(34.100409410905804, 13.578451048463291), + Offset(35.819917057432754, 15.600154482863552), + Offset(37.10628893673229, 17.796160339704027), + Offset(37.94824625990342, 20.03655926033166), + Offset(38.38282531609377, 22.156966589965144), + Offset(38.50025359010085, 23.928711525897086), + Offset(38.47545423298094, 24.850682650961364), + Offset(38.4754065, 24.8514945), + ], + <Offset>[ + Offset(5.809272260831642, 22.944059173900662), + Offset(5.842970151767011, 22.590356743299907), + Offset(6.161027125720756, 20.822465760581736), + Offset(6.987328821042649, 18.48130068369803), + Offset(8.505512299571395, 16.097792593794804), + Offset(10.579916772830773, 13.963572435292853), + Offset(13.012803049705509, 12.18538832718269), + Offset(15.638390596016343, 10.785480644828485), + Offset(18.413043569842625, 9.77793938454513), + Offset(21.26851915699977, 9.228728180058184), + Offset(24.12773528665962, 9.165730140401642), + Offset(26.92170252799538, 9.592275539957622), + Offset(29.5745409125155, 10.497534285543754), + Offset(32.008746728384374, 11.855716569189521), + Offset(34.100409410905804, 13.578451048463291), + Offset(35.819917057432754, 15.600154482863552), + Offset(37.10628893673229, 17.796160339704027), + Offset(37.94824625990342, 20.03655926033166), + Offset(38.38282531609377, 22.156966589965144), + Offset(38.50025359010085, 23.928711525897086), + Offset(38.47545423298094, 24.850682650961364), + Offset(38.4754065, 24.8514945), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.390243902439, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(18.649202428774874, 22.9341391589153), + Offset(18.67383155907712, 22.83064248877585), + Offset(18.841306012706912, 22.31953234799544), + Offset(19.183223001397558, 21.65944760224325), + Offset(19.732070850474493, 21.015435554004174), + Offset(20.435551631861834, 20.468366312790188), + Offset(21.23060828396028, 20.041713905979922), + Offset(22.06715801213608, 19.735213871060157), + Offset(22.931677497903188, 19.55123899968618), + Offset(23.801199687383725, 19.506527080582764), + Offset(24.651711975751407, 19.606157294877438), + Offset(25.46261762389004, 19.84826250611138), + Offset(26.211862438102788, 20.22649117071362), + Offset(26.877529723485452, 20.729988226520383), + Offset(27.426530333642553, 21.327419665857633), + Offset(27.852796597051224, 21.998111345570546), + Offset(28.14340318787079, 22.70256984984598), + Offset(28.300380921474876, 23.40180362588746), + Offset(28.341515096912012, 24.048596657000438), + Offset(28.30302507047554, 24.578869773477106), + Offset(28.25752024905112, 24.851255719925685), + Offset(28.2574725, 24.8514945), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.649202428774874, 22.9341391589153), + Offset(18.67383155907712, 22.83064248877585), + Offset(18.841306012706912, 22.31953234799544), + Offset(19.183223001397558, 21.65944760224325), + Offset(19.732070850474493, 21.015435554004174), + Offset(20.435551631861834, 20.468366312790188), + Offset(21.23060828396028, 20.041713905979922), + Offset(22.06715801213608, 19.735213871060157), + Offset(22.931677497903188, 19.55123899968618), + Offset(23.801199687383725, 19.506527080582764), + Offset(24.651711975751407, 19.606157294877438), + Offset(25.46261762389004, 19.84826250611138), + Offset(26.211862438102788, 20.22649117071362), + Offset(26.877529723485452, 20.729988226520383), + Offset(27.426530333642553, 21.327419665857633), + Offset(27.852796597051224, 21.998111345570546), + Offset(28.14340318787079, 22.70256984984598), + Offset(28.300380921474876, 23.40180362588746), + Offset(28.341515096912012, 24.048596657000438), + Offset(28.30302507047554, 24.578869773477106), + Offset(28.25752024905112, 24.851255719925685), + Offset(28.2574725, 24.8514945), + ], + <Offset>[ + Offset(29.349144235394235, 22.92587247976083), + Offset(29.366216065168874, 23.030880610005802), + Offset(29.408205085195373, 23.567087837506865), + Offset(29.346468151693315, 24.307903367697598), + Offset(29.087536309560406, 25.11347135417865), + Offset(28.648580681054387, 25.889027877371305), + Offset(28.078779312505926, 26.58865188831095), + Offset(27.42446419223586, 27.193324892919883), + Offset(26.69720577128699, 27.695655345637057), + Offset(25.91176679603703, 28.07135949768658), + Offset(25.08835921666123, 28.3065132569406), + Offset(24.24671353713559, 28.394918311239508), + Offset(23.409630376092196, 28.333955241688503), + Offset(22.601515552736352, 28.125214607629434), + Offset(21.864964435923177, 27.78489351368625), + Offset(21.213529546733277, 27.329742064493043), + Offset(20.6743317304862, 26.79124444163094), + Offset(20.26049313945109, 26.206173930517295), + Offset(19.973756580927212, 25.62495504619652), + Offset(19.805334637454454, 25.120668313127123), + Offset(19.742575262442934, 24.85173327739595), + Offset(19.7425275, 24.8514945), + ], + <Offset>[ + Offset(29.349144235394235, 22.92587247976083), + Offset(29.366216065168874, 23.030880610005802), + Offset(29.408205085195373, 23.567087837506865), + Offset(29.346468151693315, 24.307903367697598), + Offset(29.087536309560406, 25.11347135417865), + Offset(28.648580681054387, 25.889027877371305), + Offset(28.078779312505926, 26.58865188831095), + Offset(27.42446419223586, 27.193324892919883), + Offset(26.69720577128699, 27.695655345637057), + Offset(25.91176679603703, 28.07135949768658), + Offset(25.08835921666123, 28.3065132569406), + Offset(24.24671353713559, 28.394918311239508), + Offset(23.409630376092196, 28.333955241688503), + Offset(22.601515552736352, 28.125214607629434), + Offset(21.864964435923177, 27.78489351368625), + Offset(21.213529546733277, 27.329742064493043), + Offset(20.6743317304862, 26.79124444163094), + Offset(20.26049313945109, 26.206173930517295), + Offset(19.973756580927212, 25.62495504619652), + Offset(19.805334637454454, 25.120668313127123), + Offset(19.742575262442934, 24.85173327739595), + Offset(19.7425275, 24.8514945), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(29.349144235394235, 22.92587247976083), + Offset(29.366216065168874, 23.030880610005802), + Offset(29.408205085195373, 23.567087837506865), + Offset(29.346468151693315, 24.307903367697598), + Offset(29.087536309560406, 25.11347135417865), + Offset(28.648580681054387, 25.889027877371305), + Offset(28.078779312505926, 26.58865188831095), + Offset(27.42446419223586, 27.193324892919883), + Offset(26.69720577128699, 27.695655345637057), + Offset(25.91176679603703, 28.07135949768658), + Offset(25.08835921666123, 28.3065132569406), + Offset(24.24671353713559, 28.394918311239508), + Offset(23.409630376092196, 28.333955241688503), + Offset(22.601515552736352, 28.125214607629434), + Offset(21.864964435923177, 27.78489351368625), + Offset(21.213529546733277, 27.329742064493043), + Offset(20.6743317304862, 26.79124444163094), + Offset(20.26049313945109, 26.206173930517295), + Offset(19.973756580927212, 25.62495504619652), + Offset(19.805334637454454, 25.120668313127123), + Offset(19.742575262442934, 24.85173327739595), + Offset(19.7425275, 24.8514945), + ], + <Offset>[ + Offset(29.33922422040887, 10.085942311817597), + Offset(29.60650181064482, 10.200019202695694), + Offset(30.90527167260908, 10.88680895052071), + Offset(32.52461507023853, 12.11200918734269), + Offset(34.005179269769776, 13.886912803275553), + Offset(35.153374558551725, 16.03339301834024), + Offset(35.93510489130316, 18.370846654056177), + Offset(36.37419741846753, 20.764557476800146), + Offset(36.47050538642804, 23.177021417576494), + Offset(36.1895656965616, 25.538678967302616), + Offset(35.52878637113702, 27.782536567848812), + Offset(34.50270050328935, 29.854003215344843), + Offset(33.13858726126206, 31.696633716101214), + Offset(31.475787210067217, 33.25643161252835), + Offset(29.613933053317517, 34.4587725909495), + Offset(27.611486409440268, 35.29686252487458), + Offset(25.580741240628157, 35.75413019049244), + Offset(23.62573750500689, 35.85403926894584), + Offset(21.865386647962502, 35.66626526537828), + Offset(20.455492885034474, 35.317896832752425), + Offset(19.743148331407255, 35.069667261325776), + Offset(19.7425275, 35.0694285), + ], + <Offset>[ + Offset(29.33922422040887, 10.085942311817597), + Offset(29.60650181064482, 10.200019202695694), + Offset(30.90527167260908, 10.88680895052071), + Offset(32.52461507023853, 12.11200918734269), + Offset(34.005179269769776, 13.886912803275553), + Offset(35.153374558551725, 16.03339301834024), + Offset(35.93510489130316, 18.370846654056177), + Offset(36.37419741846753, 20.764557476800146), + Offset(36.47050538642804, 23.177021417576494), + Offset(36.1895656965616, 25.538678967302616), + Offset(35.52878637113702, 27.782536567848812), + Offset(34.50270050328935, 29.854003215344843), + Offset(33.13858726126206, 31.696633716101214), + Offset(31.475787210067217, 33.25643161252835), + Offset(29.613933053317517, 34.4587725909495), + Offset(27.611486409440268, 35.29686252487458), + Offset(25.580741240628157, 35.75413019049244), + Offset(23.62573750500689, 35.85403926894584), + Offset(21.865386647962502, 35.66626526537828), + Offset(20.455492885034474, 35.317896832752425), + Offset(19.743148331407255, 35.069667261325776), + Offset(19.7425275, 35.0694285), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(29.33922422040887, 10.085942311817597), + Offset(29.60650181064482, 10.200019202695694), + Offset(30.90527167260908, 10.88680895052071), + Offset(32.52461507023853, 12.11200918734269), + Offset(34.005179269769776, 13.886912803275553), + Offset(35.153374558551725, 16.03339301834024), + Offset(35.93510489130316, 18.370846654056177), + Offset(36.37419741846753, 20.764557476800146), + Offset(36.47050538642804, 23.177021417576494), + Offset(36.1895656965616, 25.538678967302616), + Offset(35.52878637113702, 27.782536567848812), + Offset(34.50270050328935, 29.854003215344843), + Offset(33.13858726126206, 31.696633716101214), + Offset(31.475787210067217, 33.25643161252835), + Offset(29.613933053317517, 34.4587725909495), + Offset(27.611486409440268, 35.29686252487458), + Offset(25.580741240628157, 35.75413019049244), + Offset(23.62573750500689, 35.85403926894584), + Offset(21.865386647962502, 35.66626526537828), + Offset(20.455492885034474, 35.317896832752425), + Offset(19.743148331407255, 35.069667261325776), + Offset(19.7425275, 35.0694285), + ], + <Offset>[ + Offset(18.63928241378951, 10.094208990972067), + Offset(18.914117304553063, 9.999781081465741), + Offset(20.338372600120618, 9.639253461009286), + Offset(22.361369919942774, 9.463553421888342), + Offset(24.649713810683863, 9.788877003101078), + Offset(26.940345509359172, 10.612731453759126), + Offset(29.086933862757515, 11.823908671725148), + Offset(31.016891238367755, 13.306446454940419), + Offset(32.70497711304424, 15.03260507162562), + Offset(34.0789985879083, 16.9738465501988), + Offset(35.0921391302272, 19.08218060578565), + Offset(35.718604590043796, 21.307347410216714), + Offset(35.94081932327265, 23.58916964512633), + Offset(35.75180138081632, 25.8612052314193), + Offset(35.17549895103689, 28.001298743120884), + Offset(34.250753459758215, 29.965231805952083), + Offset(33.049812698012744, 31.665455598707478), + Offset(31.665625287030675, 33.049668964316005), + Offset(30.233145163947302, 34.0899068761822), + Offset(28.95318331805556, 34.776098293102415), + Offset(28.25809331801544, 35.06918970385551), + Offset(28.2574725, 35.0694285), + ], + <Offset>[ + Offset(18.63928241378951, 10.094208990972067), + Offset(18.914117304553063, 9.999781081465741), + Offset(20.338372600120618, 9.639253461009286), + Offset(22.361369919942774, 9.463553421888342), + Offset(24.649713810683863, 9.788877003101078), + Offset(26.940345509359172, 10.612731453759126), + Offset(29.086933862757515, 11.823908671725148), + Offset(31.016891238367755, 13.306446454940419), + Offset(32.70497711304424, 15.03260507162562), + Offset(34.0789985879083, 16.9738465501988), + Offset(35.0921391302272, 19.08218060578565), + Offset(35.718604590043796, 21.307347410216714), + Offset(35.94081932327265, 23.58916964512633), + Offset(35.75180138081632, 25.8612052314193), + Offset(35.17549895103689, 28.001298743120884), + Offset(34.250753459758215, 29.965231805952083), + Offset(33.049812698012744, 31.665455598707478), + Offset(31.665625287030675, 33.049668964316005), + Offset(30.233145163947302, 34.0899068761822), + Offset(28.95318331805556, 34.776098293102415), + Offset(28.25809331801544, 35.06918970385551), + Offset(28.2574725, 35.0694285), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.63928241378951, 10.094208990972067), + Offset(18.914117304553063, 9.999781081465741), + Offset(20.338372600120618, 9.639253461009286), + Offset(22.361369919942774, 9.463553421888342), + Offset(24.649713810683863, 9.788877003101078), + Offset(26.940345509359172, 10.612731453759126), + Offset(29.086933862757515, 11.823908671725148), + Offset(31.016891238367755, 13.306446454940419), + Offset(32.70497711304424, 15.03260507162562), + Offset(34.0789985879083, 16.9738465501988), + Offset(35.0921391302272, 19.08218060578565), + Offset(35.718604590043796, 21.307347410216714), + Offset(35.94081932327265, 23.58916964512633), + Offset(35.75180138081632, 25.8612052314193), + Offset(35.17549895103689, 28.001298743120884), + Offset(34.250753459758215, 29.965231805952083), + Offset(33.049812698012744, 31.665455598707478), + Offset(31.665625287030675, 33.049668964316005), + Offset(30.233145163947302, 34.0899068761822), + Offset(28.95318331805556, 34.776098293102415), + Offset(28.25809331801544, 35.06918970385551), + Offset(28.2574725, 35.0694285), + ], + <Offset>[ + Offset(18.649202428774874, 22.9341391589153), + Offset(18.67383155907712, 22.83064248877585), + Offset(18.841306012706912, 22.31953234799544), + Offset(19.183223001397558, 21.65944760224325), + Offset(19.732070850474493, 21.015435554004174), + Offset(20.435551631861834, 20.468366312790188), + Offset(21.23060828396028, 20.041713905979922), + Offset(22.06715801213608, 19.735213871060157), + Offset(22.931677497903188, 19.55123899968618), + Offset(23.801199687383725, 19.506527080582764), + Offset(24.651711975751407, 19.606157294877438), + Offset(25.46261762389004, 19.84826250611138), + Offset(26.211862438102788, 20.22649117071362), + Offset(26.877529723485452, 20.729988226520383), + Offset(27.426530333642553, 21.327419665857633), + Offset(27.852796597051224, 21.998111345570546), + Offset(28.14340318787079, 22.70256984984598), + Offset(28.300380921474876, 23.40180362588746), + Offset(28.341515096912012, 24.048596657000438), + Offset(28.30302507047554, 24.578869773477106), + Offset(28.25752024905112, 24.851255719925685), + Offset(28.2574725, 24.8514945), + ], + <Offset>[ + Offset(18.649202428774874, 22.9341391589153), + Offset(18.67383155907712, 22.83064248877585), + Offset(18.841306012706912, 22.31953234799544), + Offset(19.183223001397558, 21.65944760224325), + Offset(19.732070850474493, 21.015435554004174), + Offset(20.435551631861834, 20.468366312790188), + Offset(21.23060828396028, 20.041713905979922), + Offset(22.06715801213608, 19.735213871060157), + Offset(22.931677497903188, 19.55123899968618), + Offset(23.801199687383725, 19.506527080582764), + Offset(24.651711975751407, 19.606157294877438), + Offset(25.46261762389004, 19.84826250611138), + Offset(26.211862438102788, 20.22649117071362), + Offset(26.877529723485452, 20.729988226520383), + Offset(27.426530333642553, 21.327419665857633), + Offset(27.852796597051224, 21.998111345570546), + Offset(28.14340318787079, 22.70256984984598), + Offset(28.300380921474876, 23.40180362588746), + Offset(28.341515096912012, 24.048596657000438), + Offset(28.30302507047554, 24.578869773477106), + Offset(28.25752024905112, 24.851255719925685), + Offset(28.2574725, 24.8514945), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.390243902439, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(31.489132596718107, 22.924219143929935), + Offset(31.504692966387218, 23.070928234251795), + Offset(31.52158489969306, 23.816598935409147), + Offset(31.379117181752463, 24.837594520788468), + Offset(30.958629401377593, 25.933078514213545), + Offset(30.291186490892898, 26.97316019028753), + Offset(29.448413518215055, 27.898039484777154), + Offset(28.495925428255816, 28.68494709729183), + Offset(27.450311425963747, 29.324538614827237), + Offset(26.33388021776769, 29.784325981107337), + Offset(25.175688664843197, 30.046584449353226), + Offset(24.0035327197847, 30.10424947226514), + Offset(22.849183963690074, 29.955448055883483), + Offset(21.746312718586534, 29.604259883851242), + Offset(20.7526512563793, 29.076388283251973), + Offset(19.885676136669687, 28.39606820827754), + Offset(19.180517439009286, 27.608979359987934), + Offset(18.65251558304633, 26.76704799144326), + Offset(18.300204877730252, 25.940226724035732), + Offset(18.105796550850236, 25.229028021057122), + Offset(18.039586265121297, 24.851828788890007), + Offset(18.0395385, 24.851494500000005), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(31.489132596718107, 22.924219143929935), + Offset(31.504692966387218, 23.070928234251795), + Offset(31.52158489969306, 23.816598935409147), + Offset(31.379117181752463, 24.837594520788468), + Offset(30.958629401377593, 25.933078514213545), + Offset(30.291186490892898, 26.97316019028753), + Offset(29.448413518215055, 27.898039484777154), + Offset(28.495925428255816, 28.68494709729183), + Offset(27.450311425963747, 29.324538614827237), + Offset(26.33388021776769, 29.784325981107337), + Offset(25.175688664843197, 30.046584449353226), + Offset(24.0035327197847, 30.10424947226514), + Offset(22.849183963690074, 29.955448055883483), + Offset(21.746312718586534, 29.604259883851242), + Offset(20.7526512563793, 29.076388283251973), + Offset(19.885676136669687, 28.39606820827754), + Offset(19.180517439009286, 27.608979359987934), + Offset(18.65251558304633, 26.76704799144326), + Offset(18.300204877730252, 25.940226724035732), + Offset(18.105796550850236, 25.229028021057122), + Offset(18.039586265121297, 24.851828788890007), + Offset(18.0395385, 24.851494500000005), + ], + <Offset>[ + Offset(42.189074403337465, 22.915952464775465), + Offset(42.19707747247897, 23.271166355481746), + Offset(42.08848397218152, 25.06415442492057), + Offset(41.54236233204822, 27.486050286242815), + Offset(40.314094860463506, 30.03111431438802), + Offset(38.504215540085454, 32.39382175486865), + Offset(36.2965845467607, 34.44497746710818), + Offset(33.8532316083556, 36.143058119151554), + Offset(31.215839699347548, 37.46895496077811), + Offset(28.444447326420992, 38.34915839821115), + Offset(25.61233590575302, 38.74694041141639), + Offset(22.787628633030252, 38.650905277393264), + Offset(20.046951901679478, 38.062912126858365), + Offset(17.470298547837437, 36.99948626496029), + Offset(15.191085358659922, 35.53386213108059), + Offset(13.246409086351742, 33.72769892720004), + Offset(11.711445981624701, 31.697653951772896), + Offset(10.612627801022544, 29.571418296073094), + Offset(9.932446361745452, 27.516585113231805), + Offset(9.608106117829148, 25.77082656070714), + Offset(9.524641278513112, 24.852306346360272), + Offset(9.5245935, 24.851494500000005), + ], + <Offset>[ + Offset(42.189074403337465, 22.915952464775465), + Offset(42.19707747247897, 23.271166355481746), + Offset(42.08848397218152, 25.06415442492057), + Offset(41.54236233204822, 27.486050286242815), + Offset(40.314094860463506, 30.03111431438802), + Offset(38.504215540085454, 32.39382175486865), + Offset(36.2965845467607, 34.44497746710818), + Offset(33.8532316083556, 36.143058119151554), + Offset(31.215839699347548, 37.46895496077811), + Offset(28.444447326420992, 38.34915839821115), + Offset(25.61233590575302, 38.74694041141639), + Offset(22.787628633030252, 38.650905277393264), + Offset(20.046951901679478, 38.062912126858365), + Offset(17.470298547837437, 36.99948626496029), + Offset(15.191085358659922, 35.53386213108059), + Offset(13.246409086351742, 33.72769892720004), + Offset(11.711445981624701, 31.697653951772896), + Offset(10.612627801022544, 29.571418296073094), + Offset(9.932446361745452, 27.516585113231805), + Offset(9.608106117829148, 25.77082656070714), + Offset(9.524641278513112, 24.852306346360272), + Offset(9.5245935, 24.851494500000005), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.189074403337465, 22.915952464775465), + Offset(42.19707747247897, 23.271166355481746), + Offset(42.08848397218152, 25.06415442492057), + Offset(41.54236233204822, 27.486050286242815), + Offset(40.314094860463506, 30.03111431438802), + Offset(38.504215540085454, 32.39382175486865), + Offset(36.2965845467607, 34.44497746710818), + Offset(33.8532316083556, 36.143058119151554), + Offset(31.215839699347548, 37.46895496077811), + Offset(28.444447326420992, 38.34915839821115), + Offset(25.61233590575302, 38.74694041141639), + Offset(22.787628633030252, 38.650905277393264), + Offset(20.046951901679478, 38.062912126858365), + Offset(17.470298547837437, 36.99948626496029), + Offset(15.191085358659922, 35.53386213108059), + Offset(13.246409086351742, 33.72769892720004), + Offset(11.711445981624701, 31.697653951772896), + Offset(10.612627801022544, 29.571418296073094), + Offset(9.932446361745452, 27.516585113231805), + Offset(9.608106117829148, 25.77082656070714), + Offset(9.524641278513112, 24.852306346360272), + Offset(9.5245935, 24.851494500000005), + ], + <Offset>[ + Offset(42.1791543883521, 10.076022296832232), + Offset(42.43736321795492, 10.440304948171638), + Offset(43.58555055959523, 12.383875537934415), + Offset(44.72050925059344, 15.290156105887906), + Offset(45.231737820672876, 18.804555763484924), + Offset(45.00900941758279, 22.538186895837583), + Offset(44.15291012555793, 26.22717223285341), + Offset(42.80296483458727, 29.714290703031818), + Offset(40.9891393144886, 32.950321032717554), + Offset(38.72224622694557, 35.816477867827196), + Offset(36.05276306022881, 38.2229637223246), + Offset(33.04361559918401, 40.1099901814986), + Offset(29.775908786849342, 41.42559060127108), + Offset(26.3445702051683, 42.13070326985921), + Offset(22.940053976054262, 42.20774120834385), + Offset(19.644365949058738, 41.694819387581575), + Offset(16.617855491766655, 40.660539700634395), + Offset(13.977872166578344, 39.219283634501636), + Offset(11.824076428780742, 37.557895332413565), + Offset(10.258264365409168, 35.96805508033244), + Offset(9.525214347477434, 35.0702403302901), + Offset(9.524593500000002, 35.06942850000001), + ], + <Offset>[ + Offset(42.1791543883521, 10.076022296832232), + Offset(42.43736321795492, 10.440304948171638), + Offset(43.58555055959523, 12.383875537934415), + Offset(44.72050925059344, 15.290156105887906), + Offset(45.231737820672876, 18.804555763484924), + Offset(45.00900941758279, 22.538186895837583), + Offset(44.15291012555793, 26.22717223285341), + Offset(42.80296483458727, 29.714290703031818), + Offset(40.9891393144886, 32.950321032717554), + Offset(38.72224622694557, 35.816477867827196), + Offset(36.05276306022881, 38.2229637223246), + Offset(33.04361559918401, 40.1099901814986), + Offset(29.775908786849342, 41.42559060127108), + Offset(26.3445702051683, 42.13070326985921), + Offset(22.940053976054262, 42.20774120834385), + Offset(19.644365949058738, 41.694819387581575), + Offset(16.617855491766655, 40.660539700634395), + Offset(13.977872166578344, 39.219283634501636), + Offset(11.824076428780742, 37.557895332413565), + Offset(10.258264365409168, 35.96805508033244), + Offset(9.525214347477434, 35.0702403302901), + Offset(9.524593500000002, 35.06942850000001), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(42.1791543883521, 10.076022296832232), + Offset(42.43736321795492, 10.440304948171638), + Offset(43.58555055959523, 12.383875537934415), + Offset(44.72050925059344, 15.290156105887906), + Offset(45.231737820672876, 18.804555763484924), + Offset(45.00900941758279, 22.538186895837583), + Offset(44.15291012555793, 26.22717223285341), + Offset(42.80296483458727, 29.714290703031818), + Offset(40.9891393144886, 32.950321032717554), + Offset(38.72224622694557, 35.816477867827196), + Offset(36.05276306022881, 38.2229637223246), + Offset(33.04361559918401, 40.1099901814986), + Offset(29.775908786849342, 41.42559060127108), + Offset(26.3445702051683, 42.13070326985921), + Offset(22.940053976054262, 42.20774120834385), + Offset(19.644365949058738, 41.694819387581575), + Offset(16.617855491766655, 40.660539700634395), + Offset(13.977872166578344, 39.219283634501636), + Offset(11.824076428780742, 37.557895332413565), + Offset(10.258264365409168, 35.96805508033244), + Offset(9.525214347477434, 35.0702403302901), + Offset(9.524593500000002, 35.06942850000001), + ], + <Offset>[ + Offset(31.479212581732742, 10.084288975986702), + Offset(31.744978711863162, 10.240066826941685), + Offset(33.018651487106766, 11.136320048422991), + Offset(34.55726410029768, 12.641700340433559), + Offset(35.87627236158696, 14.706519963310448), + Offset(36.79598036839023, 17.117525331256466), + Offset(37.30473909701229, 19.680234250522382), + Offset(37.44565865448749, 22.256179681172092), + Offset(37.223611041104796, 24.805904686766674), + Offset(36.611679118292265, 27.25164545072338), + Offset(35.61611581931899, 29.522607760261437), + Offset(34.25951968593846, 31.563334376370474), + Offset(32.57814084885994, 33.3181265302962), + Offset(30.620584375917396, 34.73547688875016), + Offset(28.501619873773638, 35.75026736051523), + Offset(26.283632999376685, 36.36318866865908), + Offset(24.08692694915124, 36.57186510884944), + Offset(22.01775994860213, 36.41491332987181), + Offset(20.191834944765542, 35.98153694321749), + Offset(18.755954798430256, 35.42625654068243), + Offset(18.04015933408562, 35.06976277281983), + Offset(18.0395385, 35.0694285), + ], + <Offset>[ + Offset(31.479212581732742, 10.084288975986702), + Offset(31.744978711863162, 10.240066826941685), + Offset(33.018651487106766, 11.136320048422991), + Offset(34.55726410029768, 12.641700340433559), + Offset(35.87627236158696, 14.706519963310448), + Offset(36.79598036839023, 17.117525331256466), + Offset(37.30473909701229, 19.680234250522382), + Offset(37.44565865448749, 22.256179681172092), + Offset(37.223611041104796, 24.805904686766674), + Offset(36.611679118292265, 27.25164545072338), + Offset(35.61611581931899, 29.522607760261437), + Offset(34.25951968593846, 31.563334376370474), + Offset(32.57814084885994, 33.3181265302962), + Offset(30.620584375917396, 34.73547688875016), + Offset(28.501619873773638, 35.75026736051523), + Offset(26.283632999376685, 36.36318866865908), + Offset(24.08692694915124, 36.57186510884944), + Offset(22.01775994860213, 36.41491332987181), + Offset(20.191834944765542, 35.98153694321749), + Offset(18.755954798430256, 35.42625654068243), + Offset(18.04015933408562, 35.06976277281983), + Offset(18.0395385, 35.0694285), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(31.479212581732742, 10.084288975986702), + Offset(31.744978711863162, 10.240066826941685), + Offset(33.018651487106766, 11.136320048422991), + Offset(34.55726410029768, 12.641700340433559), + Offset(35.87627236158696, 14.706519963310448), + Offset(36.79598036839023, 17.117525331256466), + Offset(37.30473909701229, 19.680234250522382), + Offset(37.44565865448749, 22.256179681172092), + Offset(37.223611041104796, 24.805904686766674), + Offset(36.611679118292265, 27.25164545072338), + Offset(35.61611581931899, 29.522607760261437), + Offset(34.25951968593846, 31.563334376370474), + Offset(32.57814084885994, 33.3181265302962), + Offset(30.620584375917396, 34.73547688875016), + Offset(28.501619873773638, 35.75026736051523), + Offset(26.283632999376685, 36.36318866865908), + Offset(24.08692694915124, 36.57186510884944), + Offset(22.01775994860213, 36.41491332987181), + Offset(20.191834944765542, 35.98153694321749), + Offset(18.755954798430256, 35.42625654068243), + Offset(18.04015933408562, 35.06976277281983), + Offset(18.0395385, 35.0694285), + ], + <Offset>[ + Offset(31.489132596718107, 22.924219143929935), + Offset(31.504692966387218, 23.070928234251795), + Offset(31.52158489969306, 23.816598935409147), + Offset(31.379117181752463, 24.837594520788468), + Offset(30.958629401377593, 25.933078514213545), + Offset(30.291186490892898, 26.97316019028753), + Offset(29.448413518215055, 27.898039484777154), + Offset(28.495925428255816, 28.68494709729183), + Offset(27.450311425963747, 29.324538614827237), + Offset(26.33388021776769, 29.784325981107337), + Offset(25.175688664843197, 30.046584449353226), + Offset(24.0035327197847, 30.10424947226514), + Offset(22.849183963690074, 29.955448055883483), + Offset(21.746312718586534, 29.604259883851242), + Offset(20.7526512563793, 29.076388283251973), + Offset(19.885676136669687, 28.39606820827754), + Offset(19.180517439009286, 27.608979359987934), + Offset(18.65251558304633, 26.76704799144326), + Offset(18.300204877730252, 25.940226724035732), + Offset(18.105796550850236, 25.229028021057122), + Offset(18.039586265121297, 24.851828788890007), + Offset(18.0395385, 24.851494500000005), + ], + <Offset>[ + Offset(31.489132596718107, 22.924219143929935), + Offset(31.504692966387218, 23.070928234251795), + Offset(31.52158489969306, 23.816598935409147), + Offset(31.379117181752463, 24.837594520788468), + Offset(30.958629401377593, 25.933078514213545), + Offset(30.291186490892898, 26.97316019028753), + Offset(29.448413518215055, 27.898039484777154), + Offset(28.495925428255816, 28.68494709729183), + Offset(27.450311425963747, 29.324538614827237), + Offset(26.33388021776769, 29.784325981107337), + Offset(25.175688664843197, 30.046584449353226), + Offset(24.0035327197847, 30.10424947226514), + Offset(22.849183963690074, 29.955448055883483), + Offset(21.746312718586534, 29.604259883851242), + Offset(20.7526512563793, 29.076388283251973), + Offset(19.885676136669687, 28.39606820827754), + Offset(19.180517439009286, 27.608979359987934), + Offset(18.65251558304633, 26.76704799144326), + Offset(18.300204877730252, 25.940226724035732), + Offset(18.105796550850236, 25.229028021057122), + Offset(18.039586265121297, 24.851828788890007), + Offset(18.0395385, 24.851494500000005), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.390243902439, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(5.820845611647898, 37.923977703167765), + Offset(5.562636782045075, 37.55969505182836), + Offset(4.414449440404765, 35.616124462065585), + Offset(3.279490749406561, 32.70984389411209), + Offset(2.7682621793271274, 29.195444236515087), + Offset(2.990990582417215, 25.461813104162424), + Offset(3.8470898744420694, 21.77282776714659), + Offset(5.197035165412721, 18.285709296968175), + Offset(7.010860685511399, 15.049678967282448), + Offset(9.277753773054428, 12.183522132172802), + Offset(11.947236939771194, 9.777036277675393), + Offset(14.956384400815995, 7.8900098185013965), + Offset(18.22409121315066, 6.574409398728922), + Offset(21.6554297948317, 5.869296730140784), + Offset(25.05994602394574, 5.792258791656161), + Offset(28.35563405094127, 6.305180612418426), + Offset(31.382144508233342, 7.339460299365608), + Offset(34.022127833421656, 8.780716365498357), + Offset(36.175923571219265, 10.44210466758643), + Offset(37.741735634590825, 12.031944919667563), + Offset(38.47478565252257, 12.929759669709906), + Offset(38.4754065, 12.930571500000003), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(5.820845611647898, 37.923977703167765), + Offset(5.562636782045075, 37.55969505182836), + Offset(4.414449440404765, 35.616124462065585), + Offset(3.279490749406561, 32.70984389411209), + Offset(2.7682621793271274, 29.195444236515087), + Offset(2.990990582417215, 25.461813104162424), + Offset(3.8470898744420694, 21.77282776714659), + Offset(5.197035165412721, 18.285709296968175), + Offset(7.010860685511399, 15.049678967282448), + Offset(9.277753773054428, 12.183522132172802), + Offset(11.947236939771194, 9.777036277675393), + Offset(14.956384400815995, 7.8900098185013965), + Offset(18.22409121315066, 6.574409398728922), + Offset(21.6554297948317, 5.869296730140784), + Offset(25.05994602394574, 5.792258791656161), + Offset(28.35563405094127, 6.305180612418426), + Offset(31.382144508233342, 7.339460299365608), + Offset(34.022127833421656, 8.780716365498357), + Offset(36.175923571219265, 10.44210466758643), + Offset(37.741735634590825, 12.031944919667563), + Offset(38.47478565252257, 12.929759669709906), + Offset(38.4754065, 12.930571500000003), + ], + <Offset>[ + Offset(16.520787418267258, 37.9157110240133), + Offset(16.25502128813683, 37.759933173058315), + Offset(14.981348512893227, 36.863679951577005), + Offset(13.442735899702317, 35.35829965956644), + Offset(12.123727638413042, 33.29348003668956), + Offset(11.204019631609766, 30.88247466874354), + Offset(10.695260902987714, 28.319765749477618), + Offset(10.554341345512503, 25.7438203188279), + Offset(10.7763889588952, 23.194095313233326), + Offset(11.38832088170773, 20.74835454927662), + Offset(12.383884180681019, 18.477392239738556), + Offset(13.740480314061546, 16.436665623629526), + Offset(15.421859151140067, 14.681873469703806), + Offset(17.379415624082604, 13.264523111249835), + Offset(19.498380126226365, 12.249732639484778), + Offset(21.716367000623322, 11.636811331340922), + Offset(23.91307305084876, 11.42813489115057), + Offset(25.98224005139787, 11.585086670128192), + Offset(27.808165055234465, 12.018463056782506), + Offset(29.244045201569737, 12.57374345931758), + Offset(29.95984066591438, 12.930237227180172), + Offset(29.9604615, 12.930571500000003), + ], + <Offset>[ + Offset(16.520787418267258, 37.9157110240133), + Offset(16.25502128813683, 37.759933173058315), + Offset(14.981348512893227, 36.863679951577005), + Offset(13.442735899702317, 35.35829965956644), + Offset(12.123727638413042, 33.29348003668956), + Offset(11.204019631609766, 30.88247466874354), + Offset(10.695260902987714, 28.319765749477618), + Offset(10.554341345512503, 25.7438203188279), + Offset(10.7763889588952, 23.194095313233326), + Offset(11.38832088170773, 20.74835454927662), + Offset(12.383884180681019, 18.477392239738556), + Offset(13.740480314061546, 16.436665623629526), + Offset(15.421859151140067, 14.681873469703806), + Offset(17.379415624082604, 13.264523111249835), + Offset(19.498380126226365, 12.249732639484778), + Offset(21.716367000623322, 11.636811331340922), + Offset(23.91307305084876, 11.42813489115057), + Offset(25.98224005139787, 11.585086670128192), + Offset(27.808165055234465, 12.018463056782506), + Offset(29.244045201569737, 12.57374345931758), + Offset(29.95984066591438, 12.930237227180172), + Offset(29.9604615, 12.930571500000003), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(16.520787418267258, 37.9157110240133), + Offset(16.25502128813683, 37.759933173058315), + Offset(14.981348512893227, 36.863679951577005), + Offset(13.442735899702317, 35.35829965956644), + Offset(12.123727638413042, 33.29348003668956), + Offset(11.204019631609766, 30.88247466874354), + Offset(10.695260902987714, 28.319765749477618), + Offset(10.554341345512503, 25.7438203188279), + Offset(10.7763889588952, 23.194095313233326), + Offset(11.38832088170773, 20.74835454927662), + Offset(12.383884180681019, 18.477392239738556), + Offset(13.740480314061546, 16.436665623629526), + Offset(15.421859151140067, 14.681873469703806), + Offset(17.379415624082604, 13.264523111249835), + Offset(19.498380126226365, 12.249732639484778), + Offset(21.716367000623322, 11.636811331340922), + Offset(23.91307305084876, 11.42813489115057), + Offset(25.98224005139787, 11.585086670128192), + Offset(27.808165055234465, 12.018463056782506), + Offset(29.244045201569737, 12.57374345931758), + Offset(29.95984066591438, 12.930237227180172), + Offset(29.9604615, 12.930571500000003), + ], + <Offset>[ + Offset(16.510867403281896, 25.075780856070065), + Offset(16.495307033612775, 24.929071765748205), + Offset(16.478415100306933, 24.183401064590853), + Offset(16.620882818247537, 23.16240547921153), + Offset(17.041370598622414, 22.066921485786466), + Offset(17.708813509107102, 21.026839809712477), + Offset(18.55158648178495, 20.101960515222846), + Offset(19.504074571744177, 19.315052902708164), + Offset(20.54968857403625, 18.675461385172763), + Offset(21.666119782232308, 18.215674018892656), + Offset(22.824311335156814, 17.95341555064677), + Offset(23.996467280215303, 17.89575052773486), + Offset(25.15081603630993, 18.04455194411652), + Offset(26.253687281413466, 18.39574011614875), + Offset(27.247348743620705, 18.923611716748034), + Offset(28.114323863330313, 19.60393179172246), + Offset(28.81948256099071, 20.39102064001207), + Offset(29.34748441695367, 21.232952008556737), + Offset(29.699795122269755, 22.059773275964268), + Offset(29.894203449149757, 22.770971978942885), + Offset(29.960413734878703, 23.148171211109993), + Offset(29.9604615, 23.148505500000002), + ], + <Offset>[ + Offset(16.510867403281896, 25.075780856070065), + Offset(16.495307033612775, 24.929071765748205), + Offset(16.478415100306933, 24.183401064590853), + Offset(16.620882818247537, 23.16240547921153), + Offset(17.041370598622414, 22.066921485786466), + Offset(17.708813509107102, 21.026839809712477), + Offset(18.55158648178495, 20.101960515222846), + Offset(19.504074571744177, 19.315052902708164), + Offset(20.54968857403625, 18.675461385172763), + Offset(21.666119782232308, 18.215674018892656), + Offset(22.824311335156814, 17.95341555064677), + Offset(23.996467280215303, 17.89575052773486), + Offset(25.15081603630993, 18.04455194411652), + Offset(26.253687281413466, 18.39574011614875), + Offset(27.247348743620705, 18.923611716748034), + Offset(28.114323863330313, 19.60393179172246), + Offset(28.81948256099071, 20.39102064001207), + Offset(29.34748441695367, 21.232952008556737), + Offset(29.699795122269755, 22.059773275964268), + Offset(29.894203449149757, 22.770971978942885), + Offset(29.960413734878703, 23.148171211109993), + Offset(29.9604615, 23.148505500000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(16.510867403281896, 25.075780856070065), + Offset(16.495307033612775, 24.929071765748205), + Offset(16.478415100306933, 24.183401064590853), + Offset(16.620882818247537, 23.16240547921153), + Offset(17.041370598622414, 22.066921485786466), + Offset(17.708813509107102, 21.026839809712477), + Offset(18.55158648178495, 20.101960515222846), + Offset(19.504074571744177, 19.315052902708164), + Offset(20.54968857403625, 18.675461385172763), + Offset(21.666119782232308, 18.215674018892656), + Offset(22.824311335156814, 17.95341555064677), + Offset(23.996467280215303, 17.89575052773486), + Offset(25.15081603630993, 18.04455194411652), + Offset(26.253687281413466, 18.39574011614875), + Offset(27.247348743620705, 18.923611716748034), + Offset(28.114323863330313, 19.60393179172246), + Offset(28.81948256099071, 20.39102064001207), + Offset(29.34748441695367, 21.232952008556737), + Offset(29.699795122269755, 22.059773275964268), + Offset(29.894203449149757, 22.770971978942885), + Offset(29.960413734878703, 23.148171211109993), + Offset(29.9604615, 23.148505500000002), + ], + <Offset>[ + Offset(5.810925596662535, 25.084047535224535), + Offset(5.8029225275210194, 24.728833644518254), + Offset(5.911516027818471, 22.93584557507943), + Offset(6.457637667951779, 20.51394971375718), + Offset(7.6859051395365, 17.96888568561199), + Offset(9.495784459914551, 15.606178245131362), + Offset(11.703415453239304, 13.555022532891817), + Offset(14.146768391644395, 11.856941880848437), + Offset(16.78416030065245, 10.531045039221889), + Offset(19.555552673579008, 9.650841601788843), + Offset(22.38766409424699, 9.253059588583607), + Offset(25.21237136696975, 9.349094722606733), + Offset(27.953048098320522, 9.937087873141635), + Offset(30.529701452162563, 11.000513735039702), + Offset(32.80891464134008, 12.466137868919416), + Offset(34.75359091364826, 14.272301072799962), + Offset(36.288554018375294, 16.302346048227108), + Offset(37.38737219897746, 18.428581703926902), + Offset(38.06755363825456, 20.483414886768188), + Offset(38.39189388217084, 22.229173439292868), + Offset(38.475358721486884, 23.147693653639728), + Offset(38.4754065, 23.148505500000002), + ], + <Offset>[ + Offset(5.810925596662535, 25.084047535224535), + Offset(5.8029225275210194, 24.728833644518254), + Offset(5.911516027818471, 22.93584557507943), + Offset(6.457637667951779, 20.51394971375718), + Offset(7.6859051395365, 17.96888568561199), + Offset(9.495784459914551, 15.606178245131362), + Offset(11.703415453239304, 13.555022532891817), + Offset(14.146768391644395, 11.856941880848437), + Offset(16.78416030065245, 10.531045039221889), + Offset(19.555552673579008, 9.650841601788843), + Offset(22.38766409424699, 9.253059588583607), + Offset(25.21237136696975, 9.349094722606733), + Offset(27.953048098320522, 9.937087873141635), + Offset(30.529701452162563, 11.000513735039702), + Offset(32.80891464134008, 12.466137868919416), + Offset(34.75359091364826, 14.272301072799962), + Offset(36.288554018375294, 16.302346048227108), + Offset(37.38737219897746, 18.428581703926902), + Offset(38.06755363825456, 20.483414886768188), + Offset(38.39189388217084, 22.229173439292868), + Offset(38.475358721486884, 23.147693653639728), + Offset(38.4754065, 23.148505500000002), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(5.810925596662535, 25.084047535224535), + Offset(5.8029225275210194, 24.728833644518254), + Offset(5.911516027818471, 22.93584557507943), + Offset(6.457637667951779, 20.51394971375718), + Offset(7.6859051395365, 17.96888568561199), + Offset(9.495784459914551, 15.606178245131362), + Offset(11.703415453239304, 13.555022532891817), + Offset(14.146768391644395, 11.856941880848437), + Offset(16.78416030065245, 10.531045039221889), + Offset(19.555552673579008, 9.650841601788843), + Offset(22.38766409424699, 9.253059588583607), + Offset(25.21237136696975, 9.349094722606733), + Offset(27.953048098320522, 9.937087873141635), + Offset(30.529701452162563, 11.000513735039702), + Offset(32.80891464134008, 12.466137868919416), + Offset(34.75359091364826, 14.272301072799962), + Offset(36.288554018375294, 16.302346048227108), + Offset(37.38737219897746, 18.428581703926902), + Offset(38.06755363825456, 20.483414886768188), + Offset(38.39189388217084, 22.229173439292868), + Offset(38.475358721486884, 23.147693653639728), + Offset(38.4754065, 23.148505500000002), + ], + <Offset>[ + Offset(5.820845611647898, 37.923977703167765), + Offset(5.562636782045075, 37.55969505182836), + Offset(4.414449440404765, 35.616124462065585), + Offset(3.279490749406561, 32.70984389411209), + Offset(2.7682621793271274, 29.195444236515087), + Offset(2.990990582417215, 25.461813104162424), + Offset(3.8470898744420694, 21.77282776714659), + Offset(5.197035165412721, 18.285709296968175), + Offset(7.010860685511399, 15.049678967282448), + Offset(9.277753773054428, 12.183522132172802), + Offset(11.947236939771194, 9.777036277675393), + Offset(14.956384400815995, 7.8900098185013965), + Offset(18.22409121315066, 6.574409398728922), + Offset(21.6554297948317, 5.869296730140784), + Offset(25.05994602394574, 5.792258791656161), + Offset(28.35563405094127, 6.305180612418426), + Offset(31.382144508233342, 7.339460299365608), + Offset(34.022127833421656, 8.780716365498357), + Offset(36.175923571219265, 10.44210466758643), + Offset(37.741735634590825, 12.031944919667563), + Offset(38.47478565252257, 12.929759669709906), + Offset(38.4754065, 12.930571500000003), + ], + <Offset>[ + Offset(5.820845611647898, 37.923977703167765), + Offset(5.562636782045075, 37.55969505182836), + Offset(4.414449440404765, 35.616124462065585), + Offset(3.279490749406561, 32.70984389411209), + Offset(2.7682621793271274, 29.195444236515087), + Offset(2.990990582417215, 25.461813104162424), + Offset(3.8470898744420694, 21.77282776714659), + Offset(5.197035165412721, 18.285709296968175), + Offset(7.010860685511399, 15.049678967282448), + Offset(9.277753773054428, 12.183522132172802), + Offset(11.947236939771194, 9.777036277675393), + Offset(14.956384400815995, 7.8900098185013965), + Offset(18.22409121315066, 6.574409398728922), + Offset(21.6554297948317, 5.869296730140784), + Offset(25.05994602394574, 5.792258791656161), + Offset(28.35563405094127, 6.305180612418426), + Offset(31.382144508233342, 7.339460299365608), + Offset(34.022127833421656, 8.780716365498357), + Offset(36.175923571219265, 10.44210466758643), + Offset(37.741735634590825, 12.031944919667563), + Offset(38.47478565252257, 12.929759669709906), + Offset(38.4754065, 12.930571500000003), + ], + ), + _PathClose( + ), + ], + ), + _PathFrames( + opacities: <double>[ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 0.390243902439, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + ], + commands: <_PathCommand>[ + _PathMoveTo( + <Offset>[ + Offset(18.66077577959113, 37.914057688182396), + Offset(18.393498189355185, 37.79998079730431), + Offset(17.09472832739092, 37.11319104947929), + Offset(15.475384929761471, 35.88799081265731), + Offset(13.994820730230222, 34.11308719672446), + Offset(12.846625441448277, 31.966606981659766), + Offset(12.064895108696843, 29.629153345943823), + Offset(11.625802581532461, 27.235442523199854), + Offset(11.529494613571963, 24.822978582423502), + Offset(11.810434303438388, 22.461321032697384), + Offset(12.47121362886298, 20.217463432151188), + Offset(13.49729949671066, 18.145996784655154), + Offset(14.861412738737947, 16.303366283898786), + Offset(16.52421278993278, 14.743568387471647), + Offset(18.38606694668249, 13.541227409050501), + Offset(20.388513590559725, 12.70313747512542), + Offset(22.419258759371843, 12.24586980950756), + Offset(24.37426249499311, 12.145960731054156), + Offset(26.134613352037505, 12.33373473462172), + Offset(27.54450711496552, 12.682103167247583), + Offset(28.256851668592745, 12.930332738674227), + Offset(28.257472499999995, 12.930571500000006), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.66077577959113, 37.914057688182396), + Offset(18.393498189355185, 37.79998079730431), + Offset(17.09472832739092, 37.11319104947929), + Offset(15.475384929761471, 35.88799081265731), + Offset(13.994820730230222, 34.11308719672446), + Offset(12.846625441448277, 31.966606981659766), + Offset(12.064895108696843, 29.629153345943823), + Offset(11.625802581532461, 27.235442523199854), + Offset(11.529494613571963, 24.822978582423502), + Offset(11.810434303438388, 22.461321032697384), + Offset(12.47121362886298, 20.217463432151188), + Offset(13.49729949671066, 18.145996784655154), + Offset(14.861412738737947, 16.303366283898786), + Offset(16.52421278993278, 14.743568387471647), + Offset(18.38606694668249, 13.541227409050501), + Offset(20.388513590559725, 12.70313747512542), + Offset(22.419258759371843, 12.24586980950756), + Offset(24.37426249499311, 12.145960731054156), + Offset(26.134613352037505, 12.33373473462172), + Offset(27.54450711496552, 12.682103167247583), + Offset(28.256851668592745, 12.930332738674227), + Offset(28.257472499999995, 12.930571500000006), + ], + <Offset>[ + Offset(29.36071758621049, 37.90579100902793), + Offset(29.08588269544694, 38.00021891853426), + Offset(27.661627399879382, 38.36074653899071), + Offset(25.638630080057226, 38.53644657811165), + Offset(23.350286189316137, 38.211122996898936), + Offset(21.059654490640828, 37.38726854624088), + Offset(18.913066137242488, 36.17609132827485), + Offset(16.983108761632245, 34.69355354505958), + Offset(15.295022886955763, 32.967394928374375), + Offset(13.92100141209169, 31.0261534498012), + Offset(12.907860869772804, 28.91781939421435), + Offset(12.281395409956211, 26.692652589783282), + Offset(12.059180676727353, 24.41083035487367), + Offset(12.24819861918368, 22.1387947685807), + Offset(12.824501048963114, 19.99870125687912), + Offset(13.74924654024178, 18.034768194047917), + Offset(14.950187301987258, 16.334544401292522), + Offset(16.334374712969325, 14.950331035683991), + Offset(17.766854836052705, 13.910093123817797), + Offset(19.04681668194443, 13.2239017068976), + Offset(19.74190668198456, 12.930810296144493), + Offset(19.742527499999994, 12.930571500000006), + ], + <Offset>[ + Offset(29.36071758621049, 37.90579100902793), + Offset(29.08588269544694, 38.00021891853426), + Offset(27.661627399879382, 38.36074653899071), + Offset(25.638630080057226, 38.53644657811165), + Offset(23.350286189316137, 38.211122996898936), + Offset(21.059654490640828, 37.38726854624088), + Offset(18.913066137242488, 36.17609132827485), + Offset(16.983108761632245, 34.69355354505958), + Offset(15.295022886955763, 32.967394928374375), + Offset(13.92100141209169, 31.0261534498012), + Offset(12.907860869772804, 28.91781939421435), + Offset(12.281395409956211, 26.692652589783282), + Offset(12.059180676727353, 24.41083035487367), + Offset(12.24819861918368, 22.1387947685807), + Offset(12.824501048963114, 19.99870125687912), + Offset(13.74924654024178, 18.034768194047917), + Offset(14.950187301987258, 16.334544401292522), + Offset(16.334374712969325, 14.950331035683991), + Offset(17.766854836052705, 13.910093123817797), + Offset(19.04681668194443, 13.2239017068976), + Offset(19.74190668198456, 12.930810296144493), + Offset(19.742527499999994, 12.930571500000006), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(29.36071758621049, 37.90579100902793), + Offset(29.08588269544694, 38.00021891853426), + Offset(27.661627399879382, 38.36074653899071), + Offset(25.638630080057226, 38.53644657811165), + Offset(23.350286189316137, 38.211122996898936), + Offset(21.059654490640828, 37.38726854624088), + Offset(18.913066137242488, 36.17609132827485), + Offset(16.983108761632245, 34.69355354505958), + Offset(15.295022886955763, 32.967394928374375), + Offset(13.92100141209169, 31.0261534498012), + Offset(12.907860869772804, 28.91781939421435), + Offset(12.281395409956211, 26.692652589783282), + Offset(12.059180676727353, 24.41083035487367), + Offset(12.24819861918368, 22.1387947685807), + Offset(12.824501048963114, 19.99870125687912), + Offset(13.74924654024178, 18.034768194047917), + Offset(14.950187301987258, 16.334544401292522), + Offset(16.334374712969325, 14.950331035683991), + Offset(17.766854836052705, 13.910093123817797), + Offset(19.04681668194443, 13.2239017068976), + Offset(19.74190668198456, 12.930810296144493), + Offset(19.742527499999994, 12.930571500000006), + ], + <Offset>[ + Offset(29.350797571225126, 25.065860841084696), + Offset(29.326168440922885, 25.16935751122415), + Offset(29.158693987293088, 25.68046765200456), + Offset(28.816776998602446, 26.340552397756746), + Offset(28.267929149525507, 26.984564445995836), + Offset(27.564448368138166, 27.53163368720982), + Offset(26.76939171603972, 27.958286094020078), + Offset(25.932841987863917, 28.264786128939843), + Offset(25.068322502096812, 28.448761000313816), + Offset(24.198800312616267, 28.493472919417236), + Offset(23.3482880242486, 28.393842705122562), + Offset(22.537382376109967, 28.151737493888618), + Offset(21.788137561897216, 27.77350882928638), + Offset(21.122470276514544, 27.270011773479617), + Offset(20.573469666357454, 26.672580334142374), + Offset(20.147203402948776, 26.001888654429454), + Offset(19.85659681212921, 25.29743015015402), + Offset(19.699619078525124, 24.598196374112536), + Offset(19.658484903087995, 23.951403342999555), + Offset(19.69697492952445, 23.421130226522905), + Offset(19.74247975094888, 23.148744280074315), + Offset(19.742527499999998, 23.148505500000006), + ], + <Offset>[ + Offset(29.350797571225126, 25.065860841084696), + Offset(29.326168440922885, 25.16935751122415), + Offset(29.158693987293088, 25.68046765200456), + Offset(28.816776998602446, 26.340552397756746), + Offset(28.267929149525507, 26.984564445995836), + Offset(27.564448368138166, 27.53163368720982), + Offset(26.76939171603972, 27.958286094020078), + Offset(25.932841987863917, 28.264786128939843), + Offset(25.068322502096812, 28.448761000313816), + Offset(24.198800312616267, 28.493472919417236), + Offset(23.3482880242486, 28.393842705122562), + Offset(22.537382376109967, 28.151737493888618), + Offset(21.788137561897216, 27.77350882928638), + Offset(21.122470276514544, 27.270011773479617), + Offset(20.573469666357454, 26.672580334142374), + Offset(20.147203402948776, 26.001888654429454), + Offset(19.85659681212921, 25.29743015015402), + Offset(19.699619078525124, 24.598196374112536), + Offset(19.658484903087995, 23.951403342999555), + Offset(19.69697492952445, 23.421130226522905), + Offset(19.74247975094888, 23.148744280074315), + Offset(19.742527499999998, 23.148505500000006), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(29.350797571225126, 25.065860841084696), + Offset(29.326168440922885, 25.16935751122415), + Offset(29.158693987293088, 25.68046765200456), + Offset(28.816776998602446, 26.340552397756746), + Offset(28.267929149525507, 26.984564445995836), + Offset(27.564448368138166, 27.53163368720982), + Offset(26.76939171603972, 27.958286094020078), + Offset(25.932841987863917, 28.264786128939843), + Offset(25.068322502096812, 28.448761000313816), + Offset(24.198800312616267, 28.493472919417236), + Offset(23.3482880242486, 28.393842705122562), + Offset(22.537382376109967, 28.151737493888618), + Offset(21.788137561897216, 27.77350882928638), + Offset(21.122470276514544, 27.270011773479617), + Offset(20.573469666357454, 26.672580334142374), + Offset(20.147203402948776, 26.001888654429454), + Offset(19.85659681212921, 25.29743015015402), + Offset(19.699619078525124, 24.598196374112536), + Offset(19.658484903087995, 23.951403342999555), + Offset(19.69697492952445, 23.421130226522905), + Offset(19.74247975094888, 23.148744280074315), + Offset(19.742527499999998, 23.148505500000006), + ], + <Offset>[ + Offset(18.650855764605765, 25.074127520239166), + Offset(18.63378393483113, 24.969119389994198), + Offset(18.591794914804627, 24.432912162493135), + Offset(18.65353184830669, 23.6920966323024), + Offset(18.912463690439594, 22.88652864582136), + Offset(19.351419318945613, 22.110972122628702), + Offset(19.921220687494078, 21.41134811168905), + Offset(20.575535807764133, 20.806675107080117), + Offset(21.30279422871301, 20.304344654362943), + Offset(22.088233203962965, 19.92864050231342), + Offset(22.911640783338775, 19.6934867430594), + Offset(23.753286462864416, 19.60508168876049), + Offset(24.59036962390781, 19.666044758311497), + Offset(25.39848444726364, 19.874785392370566), + Offset(26.13503556407683, 20.215106486313754), + Offset(26.786470453266723, 20.670257935506957), + Offset(27.3256682695138, 21.20875555836906), + Offset(27.73950686054891, 21.7938260694827), + Offset(28.026243419072795, 22.37504495380348), + Offset(28.19466536254554, 22.879331686872888), + Offset(28.257424737557066, 23.14826672260405), + Offset(28.2574725, 23.148505500000006), + ], + <Offset>[ + Offset(18.650855764605765, 25.074127520239166), + Offset(18.63378393483113, 24.969119389994198), + Offset(18.591794914804627, 24.432912162493135), + Offset(18.65353184830669, 23.6920966323024), + Offset(18.912463690439594, 22.88652864582136), + Offset(19.351419318945613, 22.110972122628702), + Offset(19.921220687494078, 21.41134811168905), + Offset(20.575535807764133, 20.806675107080117), + Offset(21.30279422871301, 20.304344654362943), + Offset(22.088233203962965, 19.92864050231342), + Offset(22.911640783338775, 19.6934867430594), + Offset(23.753286462864416, 19.60508168876049), + Offset(24.59036962390781, 19.666044758311497), + Offset(25.39848444726364, 19.874785392370566), + Offset(26.13503556407683, 20.215106486313754), + Offset(26.786470453266723, 20.670257935506957), + Offset(27.3256682695138, 21.20875555836906), + Offset(27.73950686054891, 21.7938260694827), + Offset(28.026243419072795, 22.37504495380348), + Offset(28.19466536254554, 22.879331686872888), + Offset(28.257424737557066, 23.14826672260405), + Offset(28.2574725, 23.148505500000006), + ], + ), + _PathCubicTo( + <Offset>[ + Offset(18.650855764605765, 25.074127520239166), + Offset(18.63378393483113, 24.969119389994198), + Offset(18.591794914804627, 24.432912162493135), + Offset(18.65353184830669, 23.6920966323024), + Offset(18.912463690439594, 22.88652864582136), + Offset(19.351419318945613, 22.110972122628702), + Offset(19.921220687494078, 21.41134811168905), + Offset(20.575535807764133, 20.806675107080117), + Offset(21.30279422871301, 20.304344654362943), + Offset(22.088233203962965, 19.92864050231342), + Offset(22.911640783338775, 19.6934867430594), + Offset(23.753286462864416, 19.60508168876049), + Offset(24.59036962390781, 19.666044758311497), + Offset(25.39848444726364, 19.874785392370566), + Offset(26.13503556407683, 20.215106486313754), + Offset(26.786470453266723, 20.670257935506957), + Offset(27.3256682695138, 21.20875555836906), + Offset(27.73950686054891, 21.7938260694827), + Offset(28.026243419072795, 22.37504495380348), + Offset(28.19466536254554, 22.879331686872888), + Offset(28.257424737557066, 23.14826672260405), + Offset(28.2574725, 23.148505500000006), + ], + <Offset>[ + Offset(18.66077577959113, 37.914057688182396), + Offset(18.393498189355185, 37.79998079730431), + Offset(17.09472832739092, 37.11319104947929), + Offset(15.475384929761471, 35.88799081265731), + Offset(13.994820730230222, 34.11308719672446), + Offset(12.846625441448277, 31.966606981659766), + Offset(12.064895108696843, 29.629153345943823), + Offset(11.625802581532461, 27.235442523199854), + Offset(11.529494613571963, 24.822978582423502), + Offset(11.810434303438388, 22.461321032697384), + Offset(12.47121362886298, 20.217463432151188), + Offset(13.49729949671066, 18.145996784655154), + Offset(14.861412738737947, 16.303366283898786), + Offset(16.52421278993278, 14.743568387471647), + Offset(18.38606694668249, 13.541227409050501), + Offset(20.388513590559725, 12.70313747512542), + Offset(22.419258759371843, 12.24586980950756), + Offset(24.37426249499311, 12.145960731054156), + Offset(26.134613352037505, 12.33373473462172), + Offset(27.54450711496552, 12.682103167247583), + Offset(28.256851668592745, 12.930332738674227), + Offset(28.257472499999995, 12.930571500000006), + ], + <Offset>[ + Offset(18.66077577959113, 37.914057688182396), + Offset(18.393498189355185, 37.79998079730431), + Offset(17.09472832739092, 37.11319104947929), + Offset(15.475384929761471, 35.88799081265731), + Offset(13.994820730230222, 34.11308719672446), + Offset(12.846625441448277, 31.966606981659766), + Offset(12.064895108696843, 29.629153345943823), + Offset(11.625802581532461, 27.235442523199854), + Offset(11.529494613571963, 24.822978582423502), + Offset(11.810434303438388, 22.461321032697384), + Offset(12.47121362886298, 20.217463432151188), + Offset(13.49729949671066, 18.145996784655154), + Offset(14.861412738737947, 16.303366283898786), + Offset(16.52421278993278, 14.743568387471647), + Offset(18.38606694668249, 13.541227409050501), + Offset(20.388513590559725, 12.70313747512542), + Offset(22.419258759371843, 12.24586980950756), + Offset(24.37426249499311, 12.145960731054156), + Offset(26.134613352037505, 12.33373473462172), + Offset(27.54450711496552, 12.682103167247583), + Offset(28.256851668592745, 12.930332738674227), + Offset(28.257472499999995, 12.930571500000006), + ], + ), + _PathClose( + ), + ], + ), + ], + matchTextDirection: true, +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/app.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/app.dart new file mode 100644 index 0000000000000000000000000000000000000000..9bcb7174e9b607cc9ed0dc025b2d74072df1f8bb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/app.dart @@ -0,0 +1,1111 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'arc.dart'; +import 'colors.dart'; +import 'floating_action_button.dart'; +import 'icons.dart'; +import 'material_localizations.dart'; +import 'page.dart'; +import 'scaffold.dart' show ScaffoldMessenger, ScaffoldMessengerState; +import 'scrollbar.dart'; +import 'theme.dart'; +import 'tooltip.dart'; + +// Examples can assume: +// typedef GlobalWidgetsLocalizations = DefaultWidgetsLocalizations; +// typedef GlobalMaterialLocalizations = DefaultMaterialLocalizations; + +/// [MaterialApp] uses this [TextStyle] as its [DefaultTextStyle] to encourage +/// developers to be intentional about their [DefaultTextStyle]. +/// +/// In Material Design, most [Text] widgets are contained in [Material] widgets, +/// which sets a specific [DefaultTextStyle]. If you're seeing text that uses +/// this text style, consider putting your text in a [Material] widget (or +/// another widget that sets a [DefaultTextStyle]). +const TextStyle _errorTextStyle = TextStyle( + color: Color(0xD0FF0000), + fontFamily: 'monospace', + fontSize: 48.0, + fontWeight: FontWeight.w900, + decoration: TextDecoration.underline, + decorationColor: Color(0xFFFFFF00), + decorationStyle: TextDecorationStyle.double, + debugLabel: 'fallback style; consider putting your text in a Material', +); + +/// Describes which theme will be used by [MaterialApp]. +enum ThemeMode { + /// Use either the light or dark theme based on what the user has selected in + /// the system settings. + system, + + /// Always use the light mode regardless of system preference. + light, + + /// Always use the dark mode (if available) regardless of system preference. + dark, +} + +/// An application that uses Material Design. +/// +/// A convenience widget that wraps a number of widgets that are commonly +/// required for Material Design applications. It builds upon a [WidgetsApp] by +/// adding material-design specific functionality, such as [AnimatedTheme] and +/// [GridPaper]. +/// +/// [MaterialApp] configures its [WidgetsApp.textStyle] with an ugly red/yellow +/// text style that's intended to warn the developer that their app hasn't defined +/// a default text style. Typically the app's [Scaffold] builds a [Material] widget +/// whose default [Material.textStyle] defines the text style for the entire scaffold. +/// +/// The [MaterialApp] configures the top-level [Navigator] to search for routes +/// in the following order: +/// +/// 1. For the `/` route, the [home] property, if non-null, is used. +/// +/// 2. Otherwise, the [routes] table is used, if it has an entry for the route. +/// +/// 3. Otherwise, [onGenerateRoute] is called, if provided. It should return a +/// non-null value for any _valid_ route not handled by [home] and [routes]. +/// +/// 4. Finally if all else fails [onUnknownRoute] is called. +/// +/// If a [Navigator] is created, at least one of these options must handle the +/// `/` route, since it is used when an invalid [initialRoute] is specified on +/// startup (e.g. by another application launching this one with an intent on +/// Android; see [dart:ui.PlatformDispatcher.defaultRouteName]). +/// +/// This widget also configures the observer of the top-level [Navigator] (if +/// any) to perform [Hero] animations. +/// +/// {@template flutter.material.MaterialApp.defaultSelectionStyle} +/// The [MaterialApp] automatically creates a [DefaultSelectionStyle]. It uses +/// the colors in the [ThemeData.textSelectionTheme] if they are not null; +/// otherwise, the [MaterialApp] sets [DefaultSelectionStyle.selectionColor] to +/// [ColorScheme.primary] with 0.4 opacity and +/// [DefaultSelectionStyle.cursorColor] to [ColorScheme.primary]. +/// {@endtemplate} +/// +/// If [home], [routes], [onGenerateRoute], and [onUnknownRoute] are all null, +/// and [builder] is not null, then no [Navigator] is created. +/// +/// {@tool snippet} +/// This example shows how to create a [MaterialApp] that disables the "debug" +/// banner with a [home] route that will be displayed when the app is launched. +/// +/// ![The MaterialApp displays a Scaffold ](https://flutter.github.io/assets-for-api-docs/assets/material/basic_material_app.png) +/// +/// ```dart +/// MaterialApp( +/// home: Scaffold( +/// appBar: AppBar( +/// title: const Text('Home'), +/// ), +/// ), +/// debugShowCheckedModeBanner: false, +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// This example shows how to create a [MaterialApp] that uses the [routes] +/// `Map` to define the "home" route and an "about" route. +/// +/// ```dart +/// MaterialApp( +/// routes: <String, WidgetBuilder>{ +/// '/': (BuildContext context) { +/// return Scaffold( +/// appBar: AppBar( +/// title: const Text('Home Route'), +/// ), +/// ); +/// }, +/// '/about': (BuildContext context) { +/// return Scaffold( +/// appBar: AppBar( +/// title: const Text('About Route'), +/// ), +/// ); +/// } +/// }, +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// This example shows how to create a [MaterialApp] that defines a [theme] that +/// will be used for material widgets in the app. +/// +/// ![The MaterialApp displays a Scaffold with a dark background and a blue / grey AppBar at the top](https://flutter.github.io/assets-for-api-docs/assets/material/theme_material_app.png) +/// +/// ```dart +/// MaterialApp( +/// theme: ThemeData( +/// brightness: Brightness.dark, +/// primaryColor: Colors.blueGrey +/// ), +/// home: Scaffold( +/// appBar: AppBar( +/// title: const Text('MaterialApp Theme'), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Troubleshooting +/// +/// ### Why is my app's text red with yellow underlines? +/// +/// [Text] widgets that lack a [Material] ancestor will be rendered with an ugly +/// red/yellow text style. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/material_app_unspecified_textstyle.png) +/// +/// The typical fix is to give the widget a [Scaffold] ancestor. The [Scaffold] creates +/// a [Material] widget that defines its default text style. +/// +/// ```dart +/// const MaterialApp( +/// title: 'Material App', +/// home: Scaffold( +/// body: Center( +/// child: Text('Hello World'), +/// ), +/// ), +/// ) +/// ``` +/// +/// See also: +/// +/// * [Scaffold], which provides standard app elements like an [AppBar] and a [Drawer]. +/// * [Navigator], which is used to manage the app's stack of pages. +/// * [MaterialPageRoute], which defines an app page that transitions in a material-specific way. +/// * [WidgetsApp], which defines the basic app elements but does not depend on the material library. +/// * The Flutter Internationalization Tutorial, +/// <https://flutter.dev/tutorials/internationalization/>. +class MaterialApp extends StatefulWidget { + /// Creates a MaterialApp. + /// + /// At least one of [home], [routes], [onGenerateRoute], or [builder] must be + /// non-null. If only [routes] is given, it must include an entry for the + /// [Navigator.defaultRouteName] (`/`), since that is the route used when the + /// application is launched with an intent that specifies an otherwise + /// unsupported route. + /// + /// This class creates an instance of [WidgetsApp]. + const MaterialApp({ + super.key, + this.navigatorKey, + this.scaffoldMessengerKey, + this.home, + Map<String, WidgetBuilder> this.routes = const <String, WidgetBuilder>{}, + this.initialRoute, + this.onGenerateRoute, + this.onGenerateInitialRoutes, + this.onUnknownRoute, + this.onNavigationNotification, + List<NavigatorObserver> this.navigatorObservers = const <NavigatorObserver>[], + this.builder, + this.title = '', + this.onGenerateTitle, + this.color, + this.theme, + this.darkTheme, + this.highContrastTheme, + this.highContrastDarkTheme, + this.themeMode = ThemeMode.system, + this.themeAnimationDuration = kThemeAnimationDuration, + this.themeAnimationCurve = Curves.linear, + this.locale, + this.localizationsDelegates, + this.localeListResolutionCallback, + this.localeResolutionCallback, + this.supportedLocales = const <Locale>[Locale('en', 'US')], + this.debugShowMaterialGrid = false, + this.showPerformanceOverlay = false, + this.checkerboardRasterCacheImages = false, + this.checkerboardOffscreenLayers = false, + this.showSemanticsDebugger = false, + this.debugShowCheckedModeBanner = true, + this.shortcuts, + this.actions, + this.restorationScopeId, + this.scrollBehavior, + @Deprecated( + 'Remove this parameter as it is now ignored. ' + 'MaterialApp never introduces its own MediaQuery; the View widget takes care of that. ' + 'This feature was deprecated after v3.7.0-29.0.pre.' + ) + this.useInheritedMediaQuery = false, + this.themeAnimationStyle, + }) : routeInformationProvider = null, + routeInformationParser = null, + routerDelegate = null, + backButtonDispatcher = null, + routerConfig = null; + + /// Creates a [MaterialApp] that uses the [Router] instead of a [Navigator]. + /// + /// {@macro flutter.widgets.WidgetsApp.router} + const MaterialApp.router({ + super.key, + this.scaffoldMessengerKey, + this.routeInformationProvider, + this.routeInformationParser, + this.routerDelegate, + this.routerConfig, + this.backButtonDispatcher, + this.builder, + this.title = '', + this.onGenerateTitle, + this.onNavigationNotification, + this.color, + this.theme, + this.darkTheme, + this.highContrastTheme, + this.highContrastDarkTheme, + this.themeMode = ThemeMode.system, + this.themeAnimationDuration = kThemeAnimationDuration, + this.themeAnimationCurve = Curves.linear, + this.locale, + this.localizationsDelegates, + this.localeListResolutionCallback, + this.localeResolutionCallback, + this.supportedLocales = const <Locale>[Locale('en', 'US')], + this.debugShowMaterialGrid = false, + this.showPerformanceOverlay = false, + this.checkerboardRasterCacheImages = false, + this.checkerboardOffscreenLayers = false, + this.showSemanticsDebugger = false, + this.debugShowCheckedModeBanner = true, + this.shortcuts, + this.actions, + this.restorationScopeId, + this.scrollBehavior, + @Deprecated( + 'Remove this parameter as it is now ignored. ' + 'MaterialApp never introduces its own MediaQuery; the View widget takes care of that. ' + 'This feature was deprecated after v3.7.0-29.0.pre.' + ) + this.useInheritedMediaQuery = false, + this.themeAnimationStyle, + }) : assert(routerDelegate != null || routerConfig != null), + navigatorObservers = null, + navigatorKey = null, + onGenerateRoute = null, + home = null, + onGenerateInitialRoutes = null, + onUnknownRoute = null, + routes = null, + initialRoute = null; + + /// {@macro flutter.widgets.widgetsApp.navigatorKey} + final GlobalKey<NavigatorState>? navigatorKey; + + /// A key to use when building the [ScaffoldMessenger]. + /// + /// If a [scaffoldMessengerKey] is specified, the [ScaffoldMessenger] can be + /// directly manipulated without first obtaining it from a [BuildContext] via + /// [ScaffoldMessenger.of]: from the [scaffoldMessengerKey], use the + /// [GlobalKey.currentState] getter. + final GlobalKey<ScaffoldMessengerState>? scaffoldMessengerKey; + + /// {@macro flutter.widgets.widgetsApp.home} + final Widget? home; + + /// The application's top-level routing table. + /// + /// When a named route is pushed with [Navigator.pushNamed], the route name is + /// looked up in this map. If the name is present, the associated + /// [widgets.WidgetBuilder] is used to construct a [MaterialPageRoute] that + /// performs an appropriate transition, including [Hero] animations, to the + /// new route. + /// + /// {@macro flutter.widgets.widgetsApp.routes} + final Map<String, WidgetBuilder>? routes; + + /// {@macro flutter.widgets.widgetsApp.initialRoute} + final String? initialRoute; + + /// {@macro flutter.widgets.widgetsApp.onGenerateRoute} + final RouteFactory? onGenerateRoute; + + /// {@macro flutter.widgets.widgetsApp.onGenerateInitialRoutes} + final InitialRouteListFactory? onGenerateInitialRoutes; + + /// {@macro flutter.widgets.widgetsApp.onUnknownRoute} + final RouteFactory? onUnknownRoute; + + /// {@macro flutter.widgets.widgetsApp.onNavigationNotification} + final NotificationListenerCallback<NavigationNotification>? onNavigationNotification; + + /// {@macro flutter.widgets.widgetsApp.navigatorObservers} + final List<NavigatorObserver>? navigatorObservers; + + /// {@macro flutter.widgets.widgetsApp.routeInformationProvider} + final RouteInformationProvider? routeInformationProvider; + + /// {@macro flutter.widgets.widgetsApp.routeInformationParser} + final RouteInformationParser<Object>? routeInformationParser; + + /// {@macro flutter.widgets.widgetsApp.routerDelegate} + final RouterDelegate<Object>? routerDelegate; + + /// {@macro flutter.widgets.widgetsApp.backButtonDispatcher} + final BackButtonDispatcher? backButtonDispatcher; + + /// {@macro flutter.widgets.widgetsApp.routerConfig} + final RouterConfig<Object>? routerConfig; + + /// {@macro flutter.widgets.widgetsApp.builder} + /// + /// Material specific features such as [showDialog] and [showMenu], and widgets + /// such as [Tooltip], [PopupMenuButton], also require a [Navigator] to properly + /// function. + final TransitionBuilder? builder; + + /// {@macro flutter.widgets.widgetsApp.title} + /// + /// This value is passed unmodified to [WidgetsApp.title]. + final String title; + + /// {@macro flutter.widgets.widgetsApp.onGenerateTitle} + /// + /// This value is passed unmodified to [WidgetsApp.onGenerateTitle]. + final GenerateAppTitle? onGenerateTitle; + + /// Default visual properties, like colors fonts and shapes, for this app's + /// material widgets. + /// + /// A second [darkTheme] [ThemeData] value, which is used to provide a dark + /// version of the user interface can also be specified. [themeMode] will + /// control which theme will be used if a [darkTheme] is provided. + /// + /// The default value of this property is the value of [ThemeData.light()]. + /// + /// See also: + /// + /// * [themeMode], which controls which theme to use. + /// * [MediaQueryData.platformBrightness], which indicates the platform's + /// desired brightness and is used to automatically toggle between [theme] + /// and [darkTheme] in [MaterialApp]. + /// * [ThemeData.brightness], which indicates the [Brightness] of a theme's + /// colors. + final ThemeData? theme; + + /// The [ThemeData] to use when a 'dark mode' is requested by the system. + /// + /// Some host platforms allow the users to select a system-wide 'dark mode', + /// or the application may want to offer the user the ability to choose a + /// dark theme just for this application. This is theme that will be used for + /// such cases. [themeMode] will control which theme will be used. + /// + /// This theme should have a [ThemeData.brightness] set to [Brightness.dark]. + /// + /// Uses [theme] instead when null. Defaults to the value of + /// [ThemeData.light()] when both [darkTheme] and [theme] are null. + /// + /// See also: + /// + /// * [themeMode], which controls which theme to use. + /// * [MediaQueryData.platformBrightness], which indicates the platform's + /// desired brightness and is used to automatically toggle between [theme] + /// and [darkTheme] in [MaterialApp]. + /// * [ThemeData.brightness], which is typically set to the value of + /// [MediaQueryData.platformBrightness]. + final ThemeData? darkTheme; + + /// The [ThemeData] to use when 'high contrast' is requested by the system. + /// + /// Some host platforms (for example, iOS) allow the users to increase + /// contrast through an accessibility setting. + /// + /// Uses [theme] instead when null. + /// + /// See also: + /// + /// * [MediaQueryData.highContrast], which indicates the platform's + /// desire to increase contrast. + final ThemeData? highContrastTheme; + + /// The [ThemeData] to use when a 'dark mode' and 'high contrast' is requested + /// by the system. + /// + /// Some host platforms (for example, iOS) allow the users to increase + /// contrast through an accessibility setting. + /// + /// This theme should have a [ThemeData.brightness] set to [Brightness.dark]. + /// + /// Uses [darkTheme] instead when null. + /// + /// See also: + /// + /// * [MediaQueryData.highContrast], which indicates the platform's + /// desire to increase contrast. + final ThemeData? highContrastDarkTheme; + + /// Determines which theme will be used by the application if both [theme] + /// and [darkTheme] are provided. + /// + /// If set to [ThemeMode.system], the choice of which theme to use will + /// be based on the user's system preferences. If the [MediaQuery.platformBrightnessOf] + /// is [Brightness.light], [theme] will be used. If it is [Brightness.dark], + /// [darkTheme] will be used (unless it is null, in which case [theme] + /// will be used. + /// + /// If set to [ThemeMode.light] the [theme] will always be used, + /// regardless of the user's system preference. + /// + /// If set to [ThemeMode.dark] the [darkTheme] will be used + /// regardless of the user's system preference. If [darkTheme] is null + /// then it will fallback to using [theme]. + /// + /// The default value is [ThemeMode.system]. + /// + /// See also: + /// + /// * [theme], which is used when a light mode is selected. + /// * [darkTheme], which is used when a dark mode is selected. + /// * [ThemeData.brightness], which indicates to various parts of the + /// system what kind of theme is being used. + final ThemeMode? themeMode; + + /// The duration of animated theme changes. + /// + /// When the theme changes (either by the [theme], [darkTheme] or [themeMode] + /// parameters changing) it is animated to the new theme over time. + /// The [themeAnimationDuration] determines how long this animation takes. + /// + /// To have the theme change immediately, you can set this to [Duration.zero]. + /// + /// The default is [kThemeAnimationDuration]. + /// + /// See also: + /// [themeAnimationCurve], which defines the curve used for the animation. + final Duration themeAnimationDuration; + + /// The curve to apply when animating theme changes. + /// + /// The default is [Curves.linear]. + /// + /// This is ignored if [themeAnimationDuration] is [Duration.zero]. + /// + /// See also: + /// [themeAnimationDuration], which defines how long the animation is. + final Curve themeAnimationCurve; + + /// {@macro flutter.widgets.widgetsApp.color} + final Color? color; + + /// {@macro flutter.widgets.widgetsApp.locale} + final Locale? locale; + + /// {@macro flutter.widgets.widgetsApp.localizationsDelegates} + /// + /// Internationalized apps that require translations for one of the locales + /// listed in [GlobalMaterialLocalizations] should specify this parameter + /// and list the [supportedLocales] that the application can handle. + /// + /// ```dart + /// // The GlobalMaterialLocalizations and GlobalWidgetsLocalizations + /// // classes require the following import: + /// // import 'package:flutter_localizations/flutter_localizations.dart'; + /// + /// const MaterialApp( + /// localizationsDelegates: <LocalizationsDelegate<Object>>[ + /// // ... app-specific localization delegate(s) here + /// GlobalMaterialLocalizations.delegate, + /// GlobalWidgetsLocalizations.delegate, + /// ], + /// supportedLocales: <Locale>[ + /// Locale('en', 'US'), // English + /// Locale('he', 'IL'), // Hebrew + /// // ... other locales the app supports + /// ], + /// // ... + /// ) + /// ``` + /// + /// ## Adding localizations for a new locale + /// + /// The information that follows applies to the unusual case of an app + /// adding translations for a language not already supported by + /// [GlobalMaterialLocalizations]. + /// + /// Delegates that produce [WidgetsLocalizations] and [MaterialLocalizations] + /// are included automatically. Apps can provide their own versions of these + /// localizations by creating implementations of + /// [LocalizationsDelegate<WidgetsLocalizations>] or + /// [LocalizationsDelegate<MaterialLocalizations>] whose load methods return + /// custom versions of [WidgetsLocalizations] or [MaterialLocalizations]. + /// + /// For example: to add support to [MaterialLocalizations] for a locale it + /// doesn't already support, say `const Locale('foo', 'BR')`, one first + /// creates a subclass of [MaterialLocalizations] that provides the + /// translations: + /// + /// ```dart + /// class FooLocalizations extends MaterialLocalizations { + /// FooLocalizations(); + /// @override + /// String get okButtonLabel => 'foo'; + /// // ... + /// // lots of other getters and methods to override! + /// } + /// ``` + /// + /// One must then create a [LocalizationsDelegate] subclass that can provide + /// an instance of the [MaterialLocalizations] subclass. In this case, this is + /// essentially just a method that constructs a `FooLocalizations` object. A + /// [SynchronousFuture] is used here because no asynchronous work takes place + /// upon "loading" the localizations object. + /// + /// ```dart + /// // continuing from previous example... + /// class FooLocalizationsDelegate extends LocalizationsDelegate<MaterialLocalizations> { + /// const FooLocalizationsDelegate(); + /// @override + /// bool isSupported(Locale locale) { + /// return locale == const Locale('foo', 'BR'); + /// } + /// @override + /// Future<FooLocalizations> load(Locale locale) { + /// assert(locale == const Locale('foo', 'BR')); + /// return SynchronousFuture<FooLocalizations>(FooLocalizations()); + /// } + /// @override + /// bool shouldReload(FooLocalizationsDelegate old) => false; + /// } + /// ``` + /// + /// Constructing a [MaterialApp] with a `FooLocalizationsDelegate` overrides + /// the automatically included delegate for [MaterialLocalizations] because + /// only the first delegate of each [LocalizationsDelegate.type] is used and + /// the automatically included delegates are added to the end of the app's + /// [localizationsDelegates] list. + /// + /// ```dart + /// // continuing from previous example... + /// const MaterialApp( + /// localizationsDelegates: <LocalizationsDelegate<Object>>[ + /// FooLocalizationsDelegate(), + /// ], + /// // ... + /// ) + /// ``` + /// See also: + /// + /// * [supportedLocales], which must be specified along with + /// [localizationsDelegates]. + /// * [GlobalMaterialLocalizations], a [localizationsDelegates] value + /// which provides material localizations for many languages. + /// * The Flutter Internationalization Tutorial, + /// <https://flutter.dev/tutorials/internationalization/>. + final Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates; + + /// {@macro flutter.widgets.widgetsApp.localeListResolutionCallback} + /// + /// This callback is passed along to the [WidgetsApp] built by this widget. + final LocaleListResolutionCallback? localeListResolutionCallback; + + /// {@macro flutter.widgets.LocaleResolutionCallback} + /// + /// This callback is passed along to the [WidgetsApp] built by this widget. + final LocaleResolutionCallback? localeResolutionCallback; + + /// {@macro flutter.widgets.widgetsApp.supportedLocales} + /// + /// It is passed along unmodified to the [WidgetsApp] built by this widget. + /// + /// See also: + /// + /// * [localizationsDelegates], which must be specified for localized + /// applications. + /// * [GlobalMaterialLocalizations], a [localizationsDelegates] value + /// which provides material localizations for many languages. + /// * The Flutter Internationalization Tutorial, + /// <https://flutter.dev/tutorials/internationalization/>. + final Iterable<Locale> supportedLocales; + + /// Turns on a performance overlay. + /// + /// See also: + /// + /// * <https://flutter.dev/debugging/#performance-overlay> + final bool showPerformanceOverlay; + + /// Turns on checkerboarding of raster cache images. + final bool checkerboardRasterCacheImages; + + /// Turns on checkerboarding of layers rendered to offscreen bitmaps. + final bool checkerboardOffscreenLayers; + + /// Turns on an overlay that shows the accessibility information + /// reported by the framework. + final bool showSemanticsDebugger; + + /// {@macro flutter.widgets.widgetsApp.debugShowCheckedModeBanner} + final bool debugShowCheckedModeBanner; + + /// {@macro flutter.widgets.widgetsApp.shortcuts} + /// {@tool snippet} + /// This example shows how to add a single shortcut for + /// [LogicalKeyboardKey.select] to the default shortcuts without needing to + /// add your own [Shortcuts] widget. + /// + /// Alternatively, you could insert a [Shortcuts] widget with just the mapping + /// you want to add between the [WidgetsApp] and its child and get the same + /// effect. + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return WidgetsApp( + /// shortcuts: <ShortcutActivator, Intent>{ + /// ... WidgetsApp.defaultShortcuts, + /// const SingleActivator(LogicalKeyboardKey.select): const ActivateIntent(), + /// }, + /// color: const Color(0xFFFF0000), + /// builder: (BuildContext context, Widget? child) { + /// return const Placeholder(); + /// }, + /// ); + /// } + /// ``` + /// {@end-tool} + /// {@macro flutter.widgets.widgetsApp.shortcuts.seeAlso} + final Map<ShortcutActivator, Intent>? shortcuts; + + /// {@macro flutter.widgets.widgetsApp.actions} + /// {@tool snippet} + /// This example shows how to add a single action handling an + /// [ActivateAction] to the default actions without needing to + /// add your own [Actions] widget. + /// + /// Alternatively, you could insert a [Actions] widget with just the mapping + /// you want to add between the [WidgetsApp] and its child and get the same + /// effect. + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return WidgetsApp( + /// actions: <Type, Action<Intent>>{ + /// ... WidgetsApp.defaultActions, + /// ActivateAction: CallbackAction<Intent>( + /// onInvoke: (Intent intent) { + /// // Do something here... + /// return null; + /// }, + /// ), + /// }, + /// color: const Color(0xFFFF0000), + /// builder: (BuildContext context, Widget? child) { + /// return const Placeholder(); + /// }, + /// ); + /// } + /// ``` + /// {@end-tool} + /// {@macro flutter.widgets.widgetsApp.actions.seeAlso} + final Map<Type, Action<Intent>>? actions; + + /// {@macro flutter.widgets.widgetsApp.restorationScopeId} + final String? restorationScopeId; + + /// {@template flutter.material.materialApp.scrollBehavior} + /// The default [ScrollBehavior] for the application. + /// + /// [ScrollBehavior]s describe how [Scrollable] widgets behave. Providing + /// a [ScrollBehavior] can set the default [ScrollPhysics] across + /// an application, and manage [Scrollable] decorations like [Scrollbar]s and + /// [GlowingOverscrollIndicator]s. + /// {@endtemplate} + /// + /// When null, defaults to [MaterialScrollBehavior]. + /// + /// See also: + /// + /// * [ScrollConfiguration], which controls how [Scrollable] widgets behave + /// in a subtree. + final ScrollBehavior? scrollBehavior; + + /// Turns on a [GridPaper] overlay that paints a baseline grid + /// Material apps. + /// + /// Only available in debug mode. + /// + /// See also: + /// + /// * <https://material.io/design/layout/spacing-methods.html> + final bool debugShowMaterialGrid; + + /// {@macro flutter.widgets.widgetsApp.useInheritedMediaQuery} + @Deprecated( + 'This setting is now ignored. ' + 'MaterialApp never introduces its own MediaQuery; the View widget takes care of that. ' + 'This feature was deprecated after v3.7.0-29.0.pre.' + ) + final bool useInheritedMediaQuery; + + /// Used to override the theme animation curve and duration. + /// + /// If [AnimationStyle.duration] is provided, it will be used to override + /// the theme animation duration in the underlying [AnimatedTheme] widget. + /// If it is null, then [themeAnimationDuration] will be used. Otherwise, + /// defaults to 200ms. + /// + /// If [AnimationStyle.curve] is provided, it will be used to override + /// the theme animation curve in the underlying [AnimatedTheme] widget. + /// If it is null, then [themeAnimationCurve] will be used. Otherwise, + /// defaults to [Curves.linear]. + /// + /// To disable the theme animation, use [AnimationStyle.noAnimation]. + /// + /// {@tool dartpad} + /// This sample showcases how to override the theme animation curve and + /// duration in the [MaterialApp] widget using [AnimationStyle]. + /// + /// ** See code in examples/api/lib/material/app/app.0.dart ** + /// {@end-tool} + final AnimationStyle? themeAnimationStyle; + + @override + State<MaterialApp> createState() => _MaterialAppState(); + + /// The [HeroController] used for Material page transitions. + /// + /// Used by the [MaterialApp]. + static HeroController createMaterialHeroController() { + return HeroController( + createRectTween: (Rect? begin, Rect? end) { + return MaterialRectArcTween(begin: begin, end: end); + }, + ); + } +} + +/// Describes how [Scrollable] widgets behave for [MaterialApp]s. +/// +/// {@macro flutter.widgets.scrollBehavior} +/// +/// Setting a [MaterialScrollBehavior] will apply a +/// [GlowingOverscrollIndicator] to [Scrollable] descendants when executing on +/// [TargetPlatform.android] and [TargetPlatform.fuchsia]. +/// +/// When using the desktop platform, if the [Scrollable] widget scrolls in the +/// [Axis.vertical], a [Scrollbar] is applied. +/// +/// If the scroll direction is [Axis.horizontal] scroll views are less +/// discoverable, so consider adding a Scrollbar in these cases, either directly +/// or through the [buildScrollbar] method. +/// +/// [ThemeData.useMaterial3] specifies the +/// overscroll indicator that is used on [TargetPlatform.android], which +/// defaults to true, resulting in a [StretchingOverscrollIndicator]. Setting +/// [ThemeData.useMaterial3] to false will instead use a +/// [GlowingOverscrollIndicator]. +/// +/// See also: +/// +/// * [ScrollBehavior], the default scrolling behavior extended by this class. +class MaterialScrollBehavior extends ScrollBehavior { + /// Creates a MaterialScrollBehavior that decorates [Scrollable]s with + /// [StretchingOverscrollIndicator]s and [Scrollbar]s based on the current + /// platform and provided [ScrollableDetails]. + /// + /// [ThemeData.useMaterial3] specifies the + /// overscroll indicator that is used on [TargetPlatform.android], which + /// defaults to true, resulting in a [StretchingOverscrollIndicator]. Setting + /// [ThemeData.useMaterial3] to false will instead use a + /// [GlowingOverscrollIndicator]. + const MaterialScrollBehavior(); + + @override + TargetPlatform getPlatform(BuildContext context) => Theme.of(context).platform; + + @override + Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) { + // When modifying this function, consider modifying the implementation in + // the base class ScrollBehavior as well. + switch (axisDirectionToAxis(details.direction)) { + case Axis.horizontal: + return child; + case Axis.vertical: + switch (getPlatform(context)) { + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + assert(details.controller != null); + return Scrollbar( + controller: details.controller, + child: child, + ); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + return child; + } + } + } + + @override + Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) { + // When modifying this function, consider modifying the implementation in + // the base class ScrollBehavior as well. + final AndroidOverscrollIndicator indicator = Theme.of(context).useMaterial3 + ? AndroidOverscrollIndicator.stretch + : AndroidOverscrollIndicator.glow; + switch (getPlatform(context)) { + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return child; + case TargetPlatform.android: + switch (indicator) { + case AndroidOverscrollIndicator.stretch: + return StretchingOverscrollIndicator( + axisDirection: details.direction, + clipBehavior: details.clipBehavior ?? Clip.hardEdge, + child: child, + ); + case AndroidOverscrollIndicator.glow: + break; + } + case TargetPlatform.fuchsia: + break; + } + return GlowingOverscrollIndicator( + axisDirection: details.direction, + color: Theme.of(context).colorScheme.secondary, + child: child, + ); + } +} + +class _MaterialAppState extends State<MaterialApp> { + late HeroController _heroController; + + bool get _usesRouter => widget.routerDelegate != null || widget.routerConfig != null; + + @override + void initState() { + super.initState(); + _heroController = MaterialApp.createMaterialHeroController(); + } + + @override + void dispose() { + _heroController.dispose(); + super.dispose(); + } + + // Combine the Localizations for Material with the ones contributed + // by the localizationsDelegates parameter, if any. Only the first delegate + // of a particular LocalizationsDelegate.type is loaded so the + // localizationsDelegate parameter can be used to override + // _MaterialLocalizationsDelegate. + Iterable<LocalizationsDelegate<dynamic>> get _localizationsDelegates { + return <LocalizationsDelegate<dynamic>>[ + if (widget.localizationsDelegates != null) + ...widget.localizationsDelegates!, + DefaultMaterialLocalizations.delegate, + DefaultCupertinoLocalizations.delegate, + ]; + } + + Widget _inspectorSelectButtonBuilder(BuildContext context, VoidCallback onPressed) { + return FloatingActionButton( + onPressed: onPressed, + mini: true, + child: const Icon(Icons.search), + ); + } + + ThemeData _themeBuilder(BuildContext context) { + ThemeData? theme; + // Resolve which theme to use based on brightness and high contrast. + final ThemeMode mode = widget.themeMode ?? ThemeMode.system; + final Brightness platformBrightness = MediaQuery.platformBrightnessOf(context); + final bool useDarkTheme = mode == ThemeMode.dark + || (mode == ThemeMode.system && platformBrightness == ui.Brightness.dark); + final bool highContrast = MediaQuery.highContrastOf(context); + if (useDarkTheme && highContrast && widget.highContrastDarkTheme != null) { + theme = widget.highContrastDarkTheme; + } else if (useDarkTheme && widget.darkTheme != null) { + theme = widget.darkTheme; + } else if (highContrast && widget.highContrastTheme != null) { + theme = widget.highContrastTheme; + } + theme ??= widget.theme ?? ThemeData.light(); + return theme; + } + + Widget _materialBuilder(BuildContext context, Widget? child) { + final ThemeData theme = _themeBuilder(context); + final Color effectiveSelectionColor = theme.textSelectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40); + final Color effectiveCursorColor = theme.textSelectionTheme.cursorColor ?? theme.colorScheme.primary; + + Widget childWidget = child ?? const SizedBox.shrink(); + + if (widget.themeAnimationStyle != AnimationStyle.noAnimation) { + if (widget.builder != null) { + childWidget = Builder( + builder: (BuildContext context) { + // Why are we surrounding a builder with a builder? + // + // The widget.builder may contain code that invokes + // Theme.of(), which should return the theme we selected + // above in AnimatedTheme. However, if we invoke + // widget.builder() directly as the child of AnimatedTheme + // then there is no Context separating them, and the + // widget.builder() will not find the theme. Therefore, we + // surround widget.builder with yet another builder so that + // a context separates them and Theme.of() correctly + // resolves to the theme we passed to AnimatedTheme. + return widget.builder!(context, child); + }, + ); + } + childWidget = AnimatedTheme( + data: theme, + duration: widget.themeAnimationStyle?.duration ?? widget.themeAnimationDuration, + curve: widget.themeAnimationStyle?.curve ?? widget.themeAnimationCurve, + child: childWidget, + ); + } else { + childWidget = Theme( + data: theme, + child: childWidget, + ); + } + + return ScaffoldMessenger( + key: widget.scaffoldMessengerKey, + child: DefaultSelectionStyle( + selectionColor: effectiveSelectionColor, + cursorColor: effectiveCursorColor, + child: childWidget, + ), + ); + } + + Widget _buildWidgetApp(BuildContext context) { + // The color property is always pulled from the light theme, even if dark + // mode is activated. This was done to simplify the technical details + // of switching themes and it was deemed acceptable because this color + // property is only used on old Android OSes to color the app bar in + // Android's switcher UI. + // + // blue is the primary color of the default theme. + final Color materialColor = widget.color ?? widget.theme?.primaryColor ?? Colors.blue; + if (_usesRouter) { + return WidgetsApp.router( + key: GlobalObjectKey(this), + routeInformationProvider: widget.routeInformationProvider, + routeInformationParser: widget.routeInformationParser, + routerDelegate: widget.routerDelegate, + routerConfig: widget.routerConfig, + backButtonDispatcher: widget.backButtonDispatcher, + builder: _materialBuilder, + title: widget.title, + onGenerateTitle: widget.onGenerateTitle, + textStyle: _errorTextStyle, + color: materialColor, + locale: widget.locale, + localizationsDelegates: _localizationsDelegates, + localeResolutionCallback: widget.localeResolutionCallback, + localeListResolutionCallback: widget.localeListResolutionCallback, + supportedLocales: widget.supportedLocales, + showPerformanceOverlay: widget.showPerformanceOverlay, + checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages, + checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers, + showSemanticsDebugger: widget.showSemanticsDebugger, + debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner, + inspectorSelectButtonBuilder: _inspectorSelectButtonBuilder, + shortcuts: widget.shortcuts, + actions: widget.actions, + restorationScopeId: widget.restorationScopeId, + ); + } + + return WidgetsApp( + key: GlobalObjectKey(this), + navigatorKey: widget.navigatorKey, + navigatorObservers: widget.navigatorObservers!, + pageRouteBuilder: <T>(RouteSettings settings, WidgetBuilder builder) { + return MaterialPageRoute<T>(settings: settings, builder: builder); + }, + home: widget.home, + routes: widget.routes!, + initialRoute: widget.initialRoute, + onGenerateRoute: widget.onGenerateRoute, + onGenerateInitialRoutes: widget.onGenerateInitialRoutes, + onUnknownRoute: widget.onUnknownRoute, + onNavigationNotification: widget.onNavigationNotification, + builder: _materialBuilder, + title: widget.title, + onGenerateTitle: widget.onGenerateTitle, + textStyle: _errorTextStyle, + color: materialColor, + locale: widget.locale, + localizationsDelegates: _localizationsDelegates, + localeResolutionCallback: widget.localeResolutionCallback, + localeListResolutionCallback: widget.localeListResolutionCallback, + supportedLocales: widget.supportedLocales, + showPerformanceOverlay: widget.showPerformanceOverlay, + checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages, + checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers, + showSemanticsDebugger: widget.showSemanticsDebugger, + debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner, + inspectorSelectButtonBuilder: _inspectorSelectButtonBuilder, + shortcuts: widget.shortcuts, + actions: widget.actions, + restorationScopeId: widget.restorationScopeId, + ); + } + + @override + Widget build(BuildContext context) { + Widget result = _buildWidgetApp(context); + result = Focus( + canRequestFocus: false, + onKeyEvent: (FocusNode node, KeyEvent event) { + if ((event is! KeyDownEvent && event is! KeyRepeatEvent) || + event.logicalKey != LogicalKeyboardKey.escape) { + return KeyEventResult.ignored; + } + return Tooltip.dismissAllToolTips() ? KeyEventResult.handled : KeyEventResult.ignored; + }, + child: result, + ); + assert(() { + if (widget.debugShowMaterialGrid) { + result = GridPaper( + color: const Color(0xE0F9BBE0), + interval: 8.0, + subdivisions: 1, + child: result, + ); + } + return true; + }()); + + return ScrollConfiguration( + behavior: widget.scrollBehavior ?? const MaterialScrollBehavior(), + child: HeroControllerScope( + controller: _heroController, + child: result, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/app_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/app_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..8fcbc5435c642178b134729853939be6684f64cf --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/app_bar.dart @@ -0,0 +1,2405 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'action_buttons.dart'; +import 'app_bar_theme.dart'; +import 'button_style.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'flexible_space_bar.dart'; +import 'icon_button.dart'; +import 'icon_button_theme.dart'; +import 'icons.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'scaffold.dart'; +import 'tabs.dart'; +import 'text_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// late String _logoAsset; +// double _myToolbarHeight = 250.0; + +typedef _FlexibleConfigBuilder = _ScrollUnderFlexibleConfig Function(BuildContext); + +const double _kLeadingWidth = kToolbarHeight; // So the leading button is square. +const double _kMaxTitleTextScaleFactor = 1.34; // TODO(perc): Add link to Material spec when available, https://github.com/flutter/flutter/issues/58769. + +enum _SliverAppVariant { small, medium, large } + +// Bottom justify the toolbarHeight child which may overflow the top. +class _ToolbarContainerLayout extends SingleChildLayoutDelegate { + const _ToolbarContainerLayout(this.toolbarHeight); + + final double toolbarHeight; + + @override + BoxConstraints getConstraintsForChild(BoxConstraints constraints) { + return constraints.tighten(height: toolbarHeight); + } + + @override + Size getSize(BoxConstraints constraints) { + return Size(constraints.maxWidth, toolbarHeight); + } + + @override + Offset getPositionForChild(Size size, Size childSize) { + return Offset(0.0, size.height - childSize.height); + } + + @override + bool shouldRelayout(_ToolbarContainerLayout oldDelegate) => + toolbarHeight != oldDelegate.toolbarHeight; +} + +class _PreferredAppBarSize extends Size { + _PreferredAppBarSize(this.toolbarHeight, this.bottomHeight) + : super.fromHeight((toolbarHeight ?? kToolbarHeight) + (bottomHeight ?? 0)); + + final double? toolbarHeight; + final double? bottomHeight; +} + +/// A Material Design app bar. +/// +/// An app bar consists of a toolbar and potentially other widgets, such as a +/// [TabBar] and a [FlexibleSpaceBar]. App bars typically expose one or more +/// common [actions] with [IconButton]s which are optionally followed by a +/// [PopupMenuButton] for less common operations (sometimes called the "overflow +/// menu"). +/// +/// App bars are typically used in the [Scaffold.appBar] property, which places +/// the app bar as a fixed-height widget at the top of the screen. For a scrollable +/// app bar, see [SliverAppBar], which embeds an [AppBar] in a sliver for use in +/// a [CustomScrollView]. +/// +/// The AppBar displays the toolbar widgets, [leading], [title], and [actions], +/// above the [bottom] (if any). The [bottom] is usually used for a [TabBar]. If +/// a [flexibleSpace] widget is specified then it is stacked behind the toolbar +/// and the bottom widget. The following diagram shows where each of these slots +/// appears in the toolbar when the writing language is left-to-right (e.g. +/// English): +/// +/// The [AppBar] insets its content based on the ambient [MediaQuery]'s padding, +/// to avoid system UI intrusions. It's taken care of by [Scaffold] when used in +/// the [Scaffold.appBar] property. When animating an [AppBar], unexpected +/// [MediaQuery] changes (as is common in [Hero] animations) may cause the content +/// to suddenly jump. Wrap the [AppBar] in a [MediaQuery] widget, and adjust its +/// padding such that the animation is smooth. +/// +/// ![The leading widget is in the top left, the actions are in the top right, +/// the title is between them. The bottom is, naturally, at the bottom, and the +/// flexibleSpace is behind all of them.](https://flutter.github.io/assets-for-api-docs/assets/material/app_bar.png) +/// +/// If the [leading] widget is omitted, but the [AppBar] is in a [Scaffold] with +/// a [Drawer], then a button will be inserted to open the drawer. Otherwise, if +/// the nearest [Navigator] has any previous routes, a [BackButton] is inserted +/// instead. This behavior can be turned off by setting the [automaticallyImplyLeading] +/// to false. In that case a null leading widget will result in the middle/title widget +/// stretching to start. +/// +/// {@tool dartpad} +/// This sample shows an [AppBar] with two simple actions. The first action +/// opens a [SnackBar], while the second action navigates to a new page. +/// +/// ** See code in examples/api/lib/material/app_bar/app_bar.0.dart ** +/// {@end-tool} +/// +/// Material Design 3 introduced new types of app bar. +/// {@tool dartpad} +/// This sample shows the creation of an [AppBar] widget with the [shadowColor] and +/// [scrolledUnderElevation] properties set, as described in: +/// https://m3.material.io/components/top-app-bar/overview +/// +/// ** See code in examples/api/lib/material/app_bar/app_bar.1.dart ** +/// {@end-tool} +/// +/// ## Troubleshooting +/// +/// ### Why don't my TextButton actions appear? +/// +/// If the app bar's [actions] contains [TextButton]s, they will not +/// be visible if their foreground (text) color is the same as the +/// app bar's background color. +/// +/// In Material v2 (i.e., when [ThemeData.useMaterial3] is false), +/// the default app bar [backgroundColor] is the overall theme's +/// [ColorScheme.primary] if the overall theme's brightness is +/// [Brightness.light]. Unfortunately this is the same as the default +/// [ButtonStyle.foregroundColor] for [TextButton] for light themes. +/// In this case a preferable text button foreground color is +/// [ColorScheme.onPrimary], a color that contrasts nicely with +/// [ColorScheme.primary]. To remedy the problem, override +/// [TextButton.style]: +/// +/// {@tool dartpad} +/// This sample shows an [AppBar] with two action buttons with their primary +/// color set to [ColorScheme.onPrimary]. +/// +/// ** See code in examples/api/lib/material/app_bar/app_bar.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to listen to a nested Scrollable's scroll notification +/// in a nested scroll view using the [notificationPredicate] property and use it +/// to make [scrolledUnderElevation] take effect. +/// +/// ** See code in examples/api/lib/material/app_bar/app_bar.3.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Scaffold], which displays the [AppBar] in its [Scaffold.appBar] slot. +/// * [SliverAppBar], which uses [AppBar] to provide a flexible app bar that +/// can be used in a [CustomScrollView]. +/// * [TabBar], which is typically placed in the [bottom] slot of the [AppBar] +/// if the screen has multiple pages arranged in tabs. +/// * [IconButton], which is used with [actions] to show buttons on the app bar. +/// * [PopupMenuButton], to show a popup menu on the app bar, via [actions]. +/// * [FlexibleSpaceBar], which is used with [flexibleSpace] when the app bar +/// can expand and collapse. +/// * <https://material.io/design/components/app-bars-top.html> +/// * <https://m3.material.io/components/top-app-bar> +/// * Cookbook: [Place a floating app bar above a list](https://flutter.dev/docs/cookbook/lists/floating-app-bar) +class AppBar extends StatefulWidget implements PreferredSizeWidget { + /// Creates a Material Design app bar. + /// + /// If [elevation] is specified, it must be non-negative. + /// + /// Typically used in the [Scaffold.appBar] property. + AppBar({ + super.key, + this.leading, + this.automaticallyImplyLeading = true, + this.title, + this.actions, + this.flexibleSpace, + this.bottom, + this.elevation, + this.scrolledUnderElevation, + this.notificationPredicate = defaultScrollNotificationPredicate, + this.shadowColor, + this.surfaceTintColor, + this.shape, + this.backgroundColor, + this.foregroundColor, + this.iconTheme, + this.actionsIconTheme, + this.primary = true, + this.centerTitle, + this.excludeHeaderSemantics = false, + this.titleSpacing, + this.toolbarOpacity = 1.0, + this.bottomOpacity = 1.0, + this.toolbarHeight, + this.leadingWidth, + this.toolbarTextStyle, + this.titleTextStyle, + this.systemOverlayStyle, + this.forceMaterialTransparency = false, + this.clipBehavior, + }) : assert(elevation == null || elevation >= 0.0), + preferredSize = _PreferredAppBarSize(toolbarHeight, bottom?.preferredSize.height); + + /// Used by [Scaffold] to compute its [AppBar]'s overall height. The returned value is + /// the same `preferredSize.height` unless [AppBar.toolbarHeight] was null and + /// `AppBarTheme.of(context).toolbarHeight` is non-null. In that case the + /// return value is the sum of the theme's toolbar height and the height of + /// the app bar's [AppBar.bottom] widget. + static double preferredHeightFor(BuildContext context, Size preferredSize) { + if (preferredSize is _PreferredAppBarSize && preferredSize.toolbarHeight == null) { + return (AppBarTheme.of(context).toolbarHeight ?? kToolbarHeight) + (preferredSize.bottomHeight ?? 0); + } + return preferredSize.height; + } + + /// {@template flutter.material.appbar.leading} + /// A widget to display before the toolbar's [title]. + /// + /// Typically the [leading] widget is an [Icon] or an [IconButton]. + /// + /// Becomes the leading component of the [NavigationToolbar] built + /// by this widget. The [leading] widget's width and height are constrained to + /// be no bigger than [leadingWidth] and [toolbarHeight] respectively. + /// + /// If this is null and [automaticallyImplyLeading] is set to true, the + /// [AppBar] will imply an appropriate widget. For example, if the [AppBar] is + /// in a [Scaffold] that also has a [Drawer], the [Scaffold] will fill this + /// widget with an [IconButton] that opens the drawer (using [Icons.menu]). If + /// there's no [Drawer] and the parent [Navigator] can go back, the [AppBar] + /// will use a [BackButton] that calls [Navigator.maybePop]. + /// {@endtemplate} + /// + /// {@tool snippet} + /// + /// The following code shows how the drawer button could be manually specified + /// instead of relying on [automaticallyImplyLeading]: + /// + /// ```dart + /// AppBar( + /// leading: Builder( + /// builder: (BuildContext context) { + /// return IconButton( + /// icon: const Icon(Icons.menu), + /// onPressed: () { Scaffold.of(context).openDrawer(); }, + /// tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip, + /// ); + /// }, + /// ), + /// ) + /// ``` + /// {@end-tool} + /// + /// The [Builder] is used in this example to ensure that the `context` refers + /// to that part of the subtree. That way this code snippet can be used even + /// inside the very code that is creating the [Scaffold] (in which case, + /// without the [Builder], the `context` wouldn't be able to see the + /// [Scaffold], since it would refer to an ancestor of that widget). + /// + /// See also: + /// + /// * [Scaffold.appBar], in which an [AppBar] is usually placed. + /// * [Scaffold.drawer], in which the [Drawer] is usually placed. + final Widget? leading; + + /// {@template flutter.material.appbar.automaticallyImplyLeading} + /// Controls whether we should try to imply the leading widget if null. + /// + /// If true and [AppBar.leading] is null, automatically try to deduce what the leading + /// widget should be. If false and [AppBar.leading] is null, leading space is given to [AppBar.title]. + /// If leading widget is not null, this parameter has no effect. + /// {@endtemplate} + final bool automaticallyImplyLeading; + + /// {@template flutter.material.appbar.title} + /// The primary widget displayed in the app bar. + /// + /// Becomes the middle component of the [NavigationToolbar] built by this widget. + /// + /// Typically a [Text] widget that contains a description of the current + /// contents of the app. + /// {@endtemplate} + /// + /// The [title]'s width is constrained to fit within the remaining space + /// between the toolbar's [leading] and [actions] widgets. Its height is + /// _not_ constrained. The [title] is vertically centered and clipped to fit + /// within the toolbar, whose height is [toolbarHeight]. Typically this + /// isn't noticeable because a simple [Text] [title] will fit within the + /// toolbar by default. On the other hand, it is noticeable when a + /// widget with an intrinsic height that is greater than [toolbarHeight] + /// is used as the [title]. For example, when the height of an Image used + /// as the [title] exceeds [toolbarHeight], it will be centered and + /// clipped (top and bottom), which may be undesirable. In cases like this + /// the height of the [title] widget can be constrained. For example: + /// + /// ```dart + /// MaterialApp( + /// home: Scaffold( + /// appBar: AppBar( + /// title: SizedBox( + /// height: _myToolbarHeight, + /// child: Image.asset(_logoAsset), + /// ), + /// toolbarHeight: _myToolbarHeight, + /// ), + /// ), + /// ) + /// ``` + final Widget? title; + + /// {@template flutter.material.appbar.actions} + /// A list of Widgets to display in a row after the [title] widget. + /// + /// Typically these widgets are [IconButton]s representing common operations. + /// For less common operations, consider using a [PopupMenuButton] as the + /// last action. + /// + /// The [actions] become the trailing component of the [NavigationToolbar] built + /// by this widget. The height of each action is constrained to be no bigger + /// than the [toolbarHeight]. + /// + /// To avoid having the last action covered by the debug banner, you may want + /// to set the [MaterialApp.debugShowCheckedModeBanner] to false. + /// {@endtemplate} + /// + /// {@tool snippet} + /// + /// ```dart + /// Scaffold( + /// body: CustomScrollView( + /// primary: true, + /// slivers: <Widget>[ + /// SliverAppBar( + /// title: const Text('Hello World'), + /// actions: <Widget>[ + /// IconButton( + /// icon: const Icon(Icons.shopping_cart), + /// tooltip: 'Open shopping cart', + /// onPressed: () { + /// // handle the press + /// }, + /// ), + /// ], + /// ), + /// // ...rest of body... + /// ], + /// ), + /// ) + /// ``` + /// {@end-tool} + final List<Widget>? actions; + + /// {@template flutter.material.appbar.flexibleSpace} + /// This widget is stacked behind the toolbar and the tab bar. Its height will + /// be the same as the app bar's overall height. + /// + /// A flexible space isn't actually flexible unless the [AppBar]'s container + /// changes the [AppBar]'s size. A [SliverAppBar] in a [CustomScrollView] + /// changes the [AppBar]'s height when scrolled. + /// + /// Typically a [FlexibleSpaceBar]. See [FlexibleSpaceBar] for details. + /// {@endtemplate} + final Widget? flexibleSpace; + + /// {@template flutter.material.appbar.bottom} + /// This widget appears across the bottom of the app bar. + /// + /// Typically a [TabBar]. Only widgets that implement [PreferredSizeWidget] can + /// be used at the bottom of an app bar. + /// {@endtemplate} + /// + /// See also: + /// + /// * [PreferredSize], which can be used to give an arbitrary widget a preferred size. + final PreferredSizeWidget? bottom; + + /// {@template flutter.material.appbar.elevation} + /// The z-coordinate at which to place this app bar relative to its parent. + /// + /// This property controls the size of the shadow below the app bar if + /// [shadowColor] is not null. + /// + /// If [surfaceTintColor] is not null then it will apply a surface tint overlay + /// to the background color (see [Material.surfaceTintColor] for more + /// detail). + /// + /// The value must be non-negative. + /// + /// If this property is null, then [AppBarTheme.elevation] of + /// [ThemeData.appBarTheme] is used. If that is also null, the + /// default value is 4. + /// {@endtemplate} + /// + /// See also: + /// + /// * [scrolledUnderElevation], which will be used when the app bar has + /// something scrolled underneath it. + /// * [shadowColor], which is the color of the shadow below the app bar. + /// * [surfaceTintColor], which determines the elevation overlay that will + /// be applied to the background of the app bar. + /// * [shape], which defines the shape of the app bar's [Material] and its + /// shadow. + final double? elevation; + + /// {@template flutter.material.appbar.scrolledUnderElevation} + /// The elevation that will be used if this app bar has something + /// scrolled underneath it. + /// + /// If non-null then it [AppBarTheme.scrolledUnderElevation] of + /// [ThemeData.appBarTheme] will be used. If that is also null then [elevation] + /// will be used. + /// + /// The value must be non-negative. + /// + /// {@endtemplate} + /// + /// See also: + /// * [elevation], which will be used if there is no content scrolled under + /// the app bar. + /// * [shadowColor], which is the color of the shadow below the app bar. + /// * [surfaceTintColor], which determines the elevation overlay that will + /// be applied to the background of the app bar. + /// * [shape], which defines the shape of the app bar's [Material] and its + /// shadow. + final double? scrolledUnderElevation; + + /// A check that specifies which child's [ScrollNotification]s should be + /// listened to. + /// + /// By default, checks whether `notification.depth == 0`. Set it to something + /// else for more complicated layouts. + final ScrollNotificationPredicate notificationPredicate; + + /// {@template flutter.material.appbar.shadowColor} + /// The color of the shadow below the app bar. + /// + /// If this property is null, then [AppBarTheme.shadowColor] of + /// [ThemeData.appBarTheme] is used. If that is also null, the default value + /// is fully opaque black. + /// {@endtemplate} + /// + /// See also: + /// + /// * [elevation], which defines the size of the shadow below the app bar. + /// * [shape], which defines the shape of the app bar and its shadow. + final Color? shadowColor; + + /// {@template flutter.material.appbar.surfaceTintColor} + /// The color of the surface tint overlay applied to the app bar's + /// background color to indicate elevation. + /// + /// If null no overlay will be applied. + /// {@endtemplate} + /// + /// See also: + /// * [Material.surfaceTintColor], which described this feature in more detail. + final Color? surfaceTintColor; + + /// {@template flutter.material.appbar.shape} + /// The shape of the app bar's [Material] as well as its shadow. + /// + /// If this property is null, then [AppBarTheme.shape] of + /// [ThemeData.appBarTheme] is used. Both properties default to null. + /// If both properties are null then the shape of the app bar's [Material] + /// is just a simple rectangle. + /// + /// A shadow is only displayed if the [elevation] is greater than + /// zero. + /// {@endtemplate} + /// + /// See also: + /// + /// * [elevation], which defines the size of the shadow below the app bar. + /// * [shadowColor], which is the color of the shadow below the app bar. + final ShapeBorder? shape; + + /// {@template flutter.material.appbar.backgroundColor} + /// The fill color to use for an app bar's [Material]. + /// + /// If null, then the [AppBarTheme.backgroundColor] is used. If that value is also + /// null, then [AppBar] uses the overall theme's [ColorScheme.primary] if the + /// overall theme's brightness is [Brightness.light], and [ColorScheme.surface] + /// if the overall theme's brightness is [Brightness.dark]. + /// + /// If this color is a [MaterialStateColor] it will be resolved against + /// [MaterialState.scrolledUnder] when the content of the app's + /// primary scrollable overlaps the app bar. + /// {@endtemplate} + /// + /// See also: + /// + /// * [foregroundColor], which specifies the color for icons and text within + /// the app bar. + /// * [Theme.of], which returns the current overall Material theme as + /// a [ThemeData]. + /// * [ThemeData.colorScheme], the thirteen colors that most Material widget + /// default colors are based on. + /// * [ColorScheme.brightness], which indicates if the overall [Theme] + /// is light or dark. + final Color? backgroundColor; + + /// {@template flutter.material.appbar.foregroundColor} + /// The default color for [Text] and [Icon]s within the app bar. + /// + /// If null, then [AppBarTheme.foregroundColor] is used. If that + /// value is also null, then [AppBar] uses the overall theme's + /// [ColorScheme.onPrimary] if the overall theme's brightness is + /// [Brightness.light], and [ColorScheme.onSurface] if the overall + /// theme's brightness is [Brightness.dark]. + /// + /// This color is used to configure [DefaultTextStyle] that contains + /// the toolbar's children, and the default [IconTheme] widgets that + /// are created if [iconTheme] and [actionsIconTheme] are null. + /// {@endtemplate} + /// + /// See also: + /// + /// * [backgroundColor], which specifies the app bar's background color. + /// * [Theme.of], which returns the current overall Material theme as + /// a [ThemeData]. + /// * [ThemeData.colorScheme], the thirteen colors that most Material widget + /// default colors are based on. + /// * [ColorScheme.brightness], which indicates if the overall [Theme] + /// is light or dark. + final Color? foregroundColor; + + /// {@template flutter.material.appbar.iconTheme} + /// The color, opacity, and size to use for toolbar icons. + /// + /// If this property is null, then a copy of [ThemeData.iconTheme] + /// is used, with the [IconThemeData.color] set to the + /// app bar's [foregroundColor]. + /// {@endtemplate} + /// + /// See also: + /// + /// * [actionsIconTheme], which defines the appearance of icons in + /// the [actions] list. + final IconThemeData? iconTheme; + + /// {@template flutter.material.appbar.actionsIconTheme} + /// The color, opacity, and size to use for the icons that appear in the app + /// bar's [actions]. + /// + /// This property should only be used when the [actions] should be + /// themed differently than the icon that appears in the app bar's [leading] + /// widget. + /// + /// If this property is null, then [AppBarTheme.actionsIconTheme] of + /// [ThemeData.appBarTheme] is used. If that is also null, then the value of + /// [iconTheme] is used. + /// {@endtemplate} + /// + /// See also: + /// + /// * [iconTheme], which defines the appearance of all of the toolbar icons. + final IconThemeData? actionsIconTheme; + + /// {@template flutter.material.appbar.primary} + /// Whether this app bar is being displayed at the top of the screen. + /// + /// If true, the app bar's toolbar elements and [bottom] widget will be + /// padded on top by the height of the system status bar. The layout + /// of the [flexibleSpace] is not affected by the [primary] property. + /// {@endtemplate} + final bool primary; + + /// {@template flutter.material.appbar.centerTitle} + /// Whether the title should be centered. + /// + /// If this property is null, then [AppBarTheme.centerTitle] of + /// [ThemeData.appBarTheme] is used. If that is also null, then value is + /// adapted to the current [TargetPlatform]. + /// {@endtemplate} + final bool? centerTitle; + + /// {@template flutter.material.appbar.excludeHeaderSemantics} + /// Whether the title should be wrapped with header [Semantics]. + /// + /// Defaults to false. + /// {@endtemplate} + final bool excludeHeaderSemantics; + + /// {@template flutter.material.appbar.titleSpacing} + /// The spacing around [title] content on the horizontal axis. This spacing is + /// applied even if there is no [leading] content or [actions]. If you want + /// [title] to take all the space available, set this value to 0.0. + /// + /// If this property is null, then [AppBarTheme.titleSpacing] of + /// [ThemeData.appBarTheme] is used. If that is also null, then the + /// default value is [NavigationToolbar.kMiddleSpacing]. + /// {@endtemplate} + final double? titleSpacing; + + /// {@template flutter.material.appbar.toolbarOpacity} + /// How opaque the toolbar part of the app bar is. + /// + /// A value of 1.0 is fully opaque, and a value of 0.0 is fully transparent. + /// + /// Typically, this value is not changed from its default value (1.0). It is + /// used by [SliverAppBar] to animate the opacity of the toolbar when the app + /// bar is scrolled. + /// {@endtemplate} + final double toolbarOpacity; + + /// {@template flutter.material.appbar.bottomOpacity} + /// How opaque the bottom part of the app bar is. + /// + /// A value of 1.0 is fully opaque, and a value of 0.0 is fully transparent. + /// + /// Typically, this value is not changed from its default value (1.0). It is + /// used by [SliverAppBar] to animate the opacity of the toolbar when the app + /// bar is scrolled. + /// {@endtemplate} + final double bottomOpacity; + + /// {@template flutter.material.appbar.preferredSize} + /// A size whose height is the sum of [toolbarHeight] and the [bottom] widget's + /// preferred height. + /// + /// [Scaffold] uses this size to set its app bar's height. + /// {@endtemplate} + @override + final Size preferredSize; + + /// {@template flutter.material.appbar.toolbarHeight} + /// Defines the height of the toolbar component of an [AppBar]. + /// + /// By default, the value of [toolbarHeight] is [kToolbarHeight]. + /// {@endtemplate} + final double? toolbarHeight; + + /// {@template flutter.material.appbar.leadingWidth} + /// Defines the width of [AppBar.leading] widget. + /// + /// By default, the value of [AppBar.leadingWidth] is 56.0. + /// {@endtemplate} + final double? leadingWidth; + + /// {@template flutter.material.appbar.toolbarTextStyle} + /// The default text style for the AppBar's [leading], and + /// [actions] widgets, but not its [title]. + /// + /// If this property is null, then [AppBarTheme.toolbarTextStyle] of + /// [ThemeData.appBarTheme] is used. If that is also null, the default + /// value is a copy of the overall theme's [TextTheme.bodyMedium] + /// [TextStyle], with color set to the app bar's [foregroundColor]. + /// {@endtemplate} + /// + /// See also: + /// + /// * [titleTextStyle], which overrides the default text style for the [title]. + /// * [DefaultTextStyle], which overrides the default text style for all of the + /// widgets in a subtree. + final TextStyle? toolbarTextStyle; + + /// {@template flutter.material.appbar.titleTextStyle} + /// The default text style for the AppBar's [title] widget. + /// + /// If this property is null, then [AppBarTheme.titleTextStyle] of + /// [ThemeData.appBarTheme] is used. If that is also null, the default + /// value is a copy of the overall theme's [TextTheme.titleLarge] + /// [TextStyle], with color set to the app bar's [foregroundColor]. + /// {@endtemplate} + /// + /// See also: + /// + /// * [toolbarTextStyle], which is the default text style for the AppBar's + /// [title], [leading], and [actions] widgets, also known as the + /// AppBar's "toolbar". + /// * [DefaultTextStyle], which overrides the default text style for all of the + /// widgets in a subtree. + final TextStyle? titleTextStyle; + + /// {@template flutter.material.appbar.systemOverlayStyle} + /// Specifies the style to use for the system overlays (e.g. the status bar on + /// Android or iOS, the system navigation bar on Android). + /// + /// If this property is null, then [AppBarTheme.systemOverlayStyle] of + /// [ThemeData.appBarTheme] is used. If that is also null, an appropriate + /// [SystemUiOverlayStyle] is calculated based on the [backgroundColor]. + /// + /// The AppBar's descendants are built within a + /// `AnnotatedRegion<SystemUiOverlayStyle>` widget, which causes + /// [SystemChrome.setSystemUIOverlayStyle] to be called + /// automatically. Apps should not enclose an AppBar with their + /// own [AnnotatedRegion]. + /// {@endtemplate} + // + /// See also: + /// + /// * [AnnotatedRegion], for placing [SystemUiOverlayStyle] in the layer tree. + /// * [SystemChrome.setSystemUIOverlayStyle], the imperative API for setting + /// system overlays style. + final SystemUiOverlayStyle? systemOverlayStyle; + + /// {@template flutter.material.appbar.forceMaterialTransparency} + /// Forces the AppBar's Material widget type to be [MaterialType.transparency] + /// (instead of Material's default type). + /// + /// This will remove the visual display of [backgroundColor] and [elevation], + /// and affect other characteristics of the AppBar's Material widget. + /// + /// Provided for cases where the app bar is to be transparent, and gestures + /// must pass through the app bar to widgets beneath the app bar (i.e. with + /// [Scaffold.extendBodyBehindAppBar] set to true). + /// + /// Defaults to false. + /// {@endtemplate} + final bool forceMaterialTransparency; + + /// {@macro flutter.material.Material.clipBehavior} + final Clip? clipBehavior; + + bool _getEffectiveCenterTitle(ThemeData theme) { + bool platformCenter() { + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return false; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return actions == null || actions!.length < 2; + } + } + + return centerTitle + ?? theme.appBarTheme.centerTitle + ?? platformCenter(); + } + + @override + State<AppBar> createState() => _AppBarState(); +} + +class _AppBarState extends State<AppBar> { + ScrollNotificationObserverState? _scrollNotificationObserver; + bool _scrolledUnder = false; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _scrollNotificationObserver?.removeListener(_handleScrollNotification); + _scrollNotificationObserver = ScrollNotificationObserver.maybeOf(context); + _scrollNotificationObserver?.addListener(_handleScrollNotification); + } + + @override + void dispose() { + if (_scrollNotificationObserver != null) { + _scrollNotificationObserver!.removeListener(_handleScrollNotification); + _scrollNotificationObserver = null; + } + super.dispose(); + } + + void _handleScrollNotification(ScrollNotification notification) { + if (notification is ScrollUpdateNotification && widget.notificationPredicate(notification)) { + final bool oldScrolledUnder = _scrolledUnder; + final ScrollMetrics metrics = notification.metrics; + switch (metrics.axisDirection) { + case AxisDirection.up: + // Scroll view is reversed + _scrolledUnder = metrics.extentAfter > 0; + case AxisDirection.down: + _scrolledUnder = metrics.extentBefore > 0; + case AxisDirection.right: + case AxisDirection.left: + // Scrolled under is only supported in the vertical axis, and should + // not be altered based on horizontal notifications of the same + // predicate since it could be a 2D scroller. + break; + } + + if (_scrolledUnder != oldScrolledUnder) { + setState(() { + // React to a change in MaterialState.scrolledUnder + }); + } + } + } + + Color _resolveColor(Set<MaterialState> states, Color? widgetColor, Color? themeColor, Color defaultColor) { + return MaterialStateProperty.resolveAs<Color?>(widgetColor, states) + ?? MaterialStateProperty.resolveAs<Color?>(themeColor, states) + ?? MaterialStateProperty.resolveAs<Color>(defaultColor, states); + } + + SystemUiOverlayStyle _systemOverlayStyleForBrightness(Brightness brightness, [Color? backgroundColor]) { + final SystemUiOverlayStyle style = brightness == Brightness.dark + ? SystemUiOverlayStyle.light + : SystemUiOverlayStyle.dark; + // For backward compatibility, create an overlay style without system navigation bar settings. + return SystemUiOverlayStyle( + statusBarColor: backgroundColor, + statusBarBrightness: style.statusBarBrightness, + statusBarIconBrightness: style.statusBarIconBrightness, + systemStatusBarContrastEnforced: style.systemStatusBarContrastEnforced, + ); + } + + @override + Widget build(BuildContext context) { + assert(!widget.primary || debugCheckHasMediaQuery(context)); + assert(debugCheckHasMaterialLocalizations(context)); + final ThemeData theme = Theme.of(context); + final IconButtonThemeData iconButtonTheme = IconButtonTheme.of(context); + final AppBarTheme appBarTheme = AppBarTheme.of(context); + final AppBarTheme defaults = theme.useMaterial3 ? _AppBarDefaultsM3(context) : _AppBarDefaultsM2(context); + final ScaffoldState? scaffold = Scaffold.maybeOf(context); + final ModalRoute<dynamic>? parentRoute = ModalRoute.of(context); + + final FlexibleSpaceBarSettings? settings = context.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>(); + final Set<MaterialState> states = <MaterialState>{ + if (settings?.isScrolledUnder ?? _scrolledUnder) MaterialState.scrolledUnder, + }; + + final bool hasDrawer = scaffold?.hasDrawer ?? false; + final bool hasEndDrawer = scaffold?.hasEndDrawer ?? false; + final bool useCloseButton = parentRoute is PageRoute<dynamic> && parentRoute.fullscreenDialog; + + final double toolbarHeight = widget.toolbarHeight ?? appBarTheme.toolbarHeight ?? kToolbarHeight; + + final Color backgroundColor = _resolveColor( + states, + widget.backgroundColor, + appBarTheme.backgroundColor, + defaults.backgroundColor!, + ); + + final Color foregroundColor = widget.foregroundColor + ?? appBarTheme.foregroundColor + ?? defaults.foregroundColor!; + + final double elevation = widget.elevation + ?? appBarTheme.elevation + ?? defaults.elevation!; + + final double effectiveElevation = states.contains(MaterialState.scrolledUnder) + ? widget.scrolledUnderElevation + ?? appBarTheme.scrolledUnderElevation + ?? defaults.scrolledUnderElevation + ?? elevation + : elevation; + + IconThemeData overallIconTheme = widget.iconTheme + ?? appBarTheme.iconTheme + ?? defaults.iconTheme!.copyWith(color: foregroundColor); + + final Color? actionForegroundColor = widget.foregroundColor + ?? appBarTheme.foregroundColor; + IconThemeData actionsIconTheme = widget.actionsIconTheme + ?? appBarTheme.actionsIconTheme + ?? widget.iconTheme + ?? appBarTheme.iconTheme + ?? defaults.actionsIconTheme?.copyWith(color: actionForegroundColor) + ?? overallIconTheme; + + TextStyle? toolbarTextStyle = widget.toolbarTextStyle + ?? appBarTheme.toolbarTextStyle + ?? defaults.toolbarTextStyle?.copyWith(color: foregroundColor); + + TextStyle? titleTextStyle = widget.titleTextStyle + ?? appBarTheme.titleTextStyle + ?? defaults.titleTextStyle?.copyWith(color: foregroundColor); + + if (widget.toolbarOpacity != 1.0) { + final double opacity = const Interval(0.25, 1.0, curve: Curves.fastOutSlowIn).transform(widget.toolbarOpacity); + if (titleTextStyle?.color != null) { + titleTextStyle = titleTextStyle!.copyWith(color: titleTextStyle.color!.withOpacity(opacity)); + } + if (toolbarTextStyle?.color != null) { + toolbarTextStyle = toolbarTextStyle!.copyWith(color: toolbarTextStyle.color!.withOpacity(opacity)); + } + overallIconTheme = overallIconTheme.copyWith( + opacity: opacity * (overallIconTheme.opacity ?? 1.0), + ); + actionsIconTheme = actionsIconTheme.copyWith( + opacity: opacity * (actionsIconTheme.opacity ?? 1.0), + ); + } + + Widget? leading = widget.leading; + if (leading == null && widget.automaticallyImplyLeading) { + if (hasDrawer) { + leading = DrawerButton( + style: IconButton.styleFrom(iconSize: overallIconTheme.size ?? 24), + ); + } else if (parentRoute?.impliesAppBarDismissal ?? false) { + leading = useCloseButton ? const CloseButton() : const BackButton(); + } + } + if (leading != null) { + if (theme.useMaterial3) { + final IconButtonThemeData effectiveIconButtonTheme; + + // This comparison is to check if there is a custom [overallIconTheme]. If true, it means that no + // custom [overallIconTheme] is provided, so [iconButtonTheme] is applied. Otherwise, we generate + // a new [IconButtonThemeData] based on the values from [overallIconTheme]. If [iconButtonTheme] only + // has null values, the default [overallIconTheme] will be applied below by [IconTheme.merge] + if (overallIconTheme == defaults.iconTheme) { + effectiveIconButtonTheme = iconButtonTheme; + } else { + // The [IconButton.styleFrom] method is used to generate a correct [overlayColor] based on the [foregroundColor]. + final ButtonStyle leadingIconButtonStyle = IconButton.styleFrom( + foregroundColor: overallIconTheme.color, + iconSize: overallIconTheme.size, + ); + + effectiveIconButtonTheme = IconButtonThemeData( + style: iconButtonTheme.style?.copyWith( + foregroundColor: leadingIconButtonStyle.foregroundColor, + overlayColor: leadingIconButtonStyle.overlayColor, + iconSize: leadingIconButtonStyle.iconSize, + ) + ); + } + + leading = IconButtonTheme( + data: effectiveIconButtonTheme, + child: leading is IconButton ? Center(child: leading) : leading, + ); + + // Based on the Material Design 3 specs, the leading IconButton should have + // a size of 48x48, and a highlight size of 40x40. Users can also put other + // type of widgets on leading with the original config. + leading = ConstrainedBox( + constraints: BoxConstraints.tightFor(width: widget.leadingWidth ?? _kLeadingWidth), + child: leading, + ); + } else { + leading = ConstrainedBox( + constraints: BoxConstraints.tightFor(width: widget.leadingWidth ?? _kLeadingWidth), + child: leading, + ); + } + } + + Widget? title = widget.title; + if (title != null) { + title = _AppBarTitleBox(child: title); + if (!widget.excludeHeaderSemantics) { + title = Semantics( + namesRoute: switch (theme.platform) { + TargetPlatform.android || TargetPlatform.fuchsia || TargetPlatform.linux || TargetPlatform.windows => true, + TargetPlatform.iOS || TargetPlatform.macOS => null, + }, + header: true, + child: title, + ); + } + + title = DefaultTextStyle( + style: titleTextStyle!, + softWrap: false, + overflow: TextOverflow.ellipsis, + child: title, + ); + + // Set maximum text scale factor to [_kMaxTitleTextScaleFactor] for the + // title to keep the visual hierarchy the same even with larger font + // sizes. To opt out, wrap the [title] widget in a [MediaQuery] widget + // with a different `TextScaler`. + title = MediaQuery.withClampedTextScaling( + maxScaleFactor: _kMaxTitleTextScaleFactor, + child: title, + ); + } + + Widget? actions; + if (widget.actions != null && widget.actions!.isNotEmpty) { + actions = Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: theme.useMaterial3 ? CrossAxisAlignment.center : CrossAxisAlignment.stretch, + children: widget.actions!, + ); + } else if (hasEndDrawer) { + actions = EndDrawerButton( + style: IconButton.styleFrom(iconSize: overallIconTheme.size ?? 24), + ); + } + + // Allow the trailing actions to have their own theme if necessary. + if (actions != null) { + final IconButtonThemeData effectiveActionsIconButtonTheme; + if (actionsIconTheme == defaults.actionsIconTheme) { + effectiveActionsIconButtonTheme = iconButtonTheme; + } else { + final ButtonStyle actionsIconButtonStyle = IconButton.styleFrom( + foregroundColor: actionsIconTheme.color, + iconSize: actionsIconTheme.size, + ); + + effectiveActionsIconButtonTheme = IconButtonThemeData( + style: iconButtonTheme.style?.copyWith( + foregroundColor: actionsIconButtonStyle.foregroundColor, + overlayColor: actionsIconButtonStyle.overlayColor, + iconSize: actionsIconButtonStyle.iconSize, + ) + ); + } + + actions = IconButtonTheme( + data: effectiveActionsIconButtonTheme, + child: IconTheme.merge( + data: actionsIconTheme, + child: actions, + ), + ); + } + + final Widget toolbar = NavigationToolbar( + leading: leading, + middle: title, + trailing: actions, + centerMiddle: widget._getEffectiveCenterTitle(theme), + middleSpacing: widget.titleSpacing ?? appBarTheme.titleSpacing ?? NavigationToolbar.kMiddleSpacing, + ); + + // If the toolbar is allocated less than toolbarHeight make it + // appear to scroll upwards within its shrinking container. + Widget appBar = ClipRect( + clipBehavior: widget.clipBehavior ?? Clip.hardEdge, + child: CustomSingleChildLayout( + delegate: _ToolbarContainerLayout(toolbarHeight), + child: IconTheme.merge( + data: overallIconTheme, + child: DefaultTextStyle( + style: toolbarTextStyle!, + child: toolbar, + ), + ), + ), + ); + if (widget.bottom != null) { + appBar = Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: <Widget>[ + Flexible( + child: ConstrainedBox( + constraints: BoxConstraints(maxHeight: toolbarHeight), + child: appBar, + ), + ), + if (widget.bottomOpacity == 1.0) + widget.bottom! + else + Opacity( + opacity: const Interval(0.25, 1.0, curve: Curves.fastOutSlowIn).transform(widget.bottomOpacity), + child: widget.bottom, + ), + ], + ); + } + + // The padding applies to the toolbar and tabbar, not the flexible space. + if (widget.primary) { + appBar = SafeArea( + bottom: false, + child: appBar, + ); + } + + appBar = Align( + alignment: Alignment.topCenter, + child: appBar, + ); + + if (widget.flexibleSpace != null) { + appBar = Stack( + fit: StackFit.passthrough, + children: <Widget>[ + Semantics( + sortKey: const OrdinalSortKey(1.0), + explicitChildNodes: true, + child: widget.flexibleSpace, + ), + Semantics( + sortKey: const OrdinalSortKey(0.0), + explicitChildNodes: true, + // Creates a material widget to prevent the flexibleSpace from + // obscuring the ink splashes produced by appBar children. + child: Material( + type: MaterialType.transparency, + child: appBar, + ), + ), + ], + ); + } + + final SystemUiOverlayStyle overlayStyle = widget.systemOverlayStyle + ?? appBarTheme.systemOverlayStyle + ?? defaults.systemOverlayStyle + ?? _systemOverlayStyleForBrightness( + ThemeData.estimateBrightnessForColor(backgroundColor), + // Make the status bar transparent for M3 so the elevation overlay + // color is picked up by the statusbar. + theme.useMaterial3 ? const Color(0x00000000) : null, + ); + + return Semantics( + container: true, + child: AnnotatedRegion<SystemUiOverlayStyle>( + value: overlayStyle, + child: Material( + color: backgroundColor, + elevation: effectiveElevation, + type: widget.forceMaterialTransparency + ? MaterialType.transparency + : MaterialType.canvas, + shadowColor: widget.shadowColor + ?? appBarTheme.shadowColor + ?? defaults.shadowColor, + surfaceTintColor: widget.surfaceTintColor + ?? appBarTheme.surfaceTintColor + ?? defaults.surfaceTintColor, + shape: widget.shape ?? appBarTheme.shape ?? defaults.shape, + child: Semantics( + explicitChildNodes: true, + child: appBar, + ), + ), + ), + ); + } +} + +class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { + _SliverAppBarDelegate({ + required this.leading, + required this.automaticallyImplyLeading, + required this.title, + required this.actions, + required this.flexibleSpace, + required this.bottom, + required this.elevation, + required this.scrolledUnderElevation, + required this.shadowColor, + required this.surfaceTintColor, + required this.forceElevated, + required this.backgroundColor, + required this.foregroundColor, + required this.iconTheme, + required this.actionsIconTheme, + required this.primary, + required this.centerTitle, + required this.excludeHeaderSemantics, + required this.titleSpacing, + required this.expandedHeight, + required this.collapsedHeight, + required this.topPadding, + required this.floating, + required this.pinned, + required this.vsync, + required this.snapConfiguration, + required this.stretchConfiguration, + required this.showOnScreenConfiguration, + required this.shape, + required this.toolbarHeight, + required this.leadingWidth, + required this.toolbarTextStyle, + required this.titleTextStyle, + required this.systemOverlayStyle, + required this.forceMaterialTransparency, + required this.clipBehavior, + required this.variant, + }) : assert(primary || topPadding == 0.0), + _bottomHeight = bottom?.preferredSize.height ?? 0.0; + + final Widget? leading; + final bool automaticallyImplyLeading; + final Widget? title; + final List<Widget>? actions; + final Widget? flexibleSpace; + final PreferredSizeWidget? bottom; + final double? elevation; + final double? scrolledUnderElevation; + final Color? shadowColor; + final Color? surfaceTintColor; + final bool forceElevated; + final Color? backgroundColor; + final Color? foregroundColor; + final IconThemeData? iconTheme; + final IconThemeData? actionsIconTheme; + final bool primary; + final bool? centerTitle; + final bool excludeHeaderSemantics; + final double? titleSpacing; + final double? expandedHeight; + final double collapsedHeight; + final double topPadding; + final bool floating; + final bool pinned; + final ShapeBorder? shape; + final double? toolbarHeight; + final double? leadingWidth; + final TextStyle? toolbarTextStyle; + final TextStyle? titleTextStyle; + final SystemUiOverlayStyle? systemOverlayStyle; + final double _bottomHeight; + final bool forceMaterialTransparency; + final Clip? clipBehavior; + final _SliverAppVariant variant; + + @override + double get minExtent => collapsedHeight; + + @override + double get maxExtent => math.max(topPadding + (expandedHeight ?? (toolbarHeight ?? kToolbarHeight) + _bottomHeight), minExtent); + + @override + final TickerProvider vsync; + + @override + final FloatingHeaderSnapConfiguration? snapConfiguration; + + @override + final OverScrollHeaderStretchConfiguration? stretchConfiguration; + + @override + final PersistentHeaderShowOnScreenConfiguration? showOnScreenConfiguration; + + @override + Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) { + final double visibleMainHeight = maxExtent - shrinkOffset - topPadding; + final double extraToolbarHeight = math.max(minExtent - _bottomHeight - topPadding - (toolbarHeight ?? kToolbarHeight), 0.0); + final double visibleToolbarHeight = visibleMainHeight - _bottomHeight - extraToolbarHeight; + + final bool isScrolledUnder = overlapsContent || forceElevated || (pinned && shrinkOffset > maxExtent - minExtent); + final bool isPinnedWithOpacityFade = pinned && floating && bottom != null && extraToolbarHeight == 0.0; + final double toolbarOpacity = !pinned || isPinnedWithOpacityFade + ? clampDouble(visibleToolbarHeight / (toolbarHeight ?? kToolbarHeight), 0.0, 1.0) + : 1.0; + final Widget? effectiveTitle = switch (variant) { + _SliverAppVariant.small => title, + _SliverAppVariant.medium || _SliverAppVariant.large => AnimatedOpacity( + opacity: isScrolledUnder ? 1 : 0, + duration: const Duration(milliseconds: 500), + curve: const Cubic(0.2, 0.0, 0.0, 1.0), + child: title, + ), + }; + + final Widget appBar = FlexibleSpaceBar.createSettings( + minExtent: minExtent, + maxExtent: maxExtent, + currentExtent: math.max(minExtent, maxExtent - shrinkOffset), + toolbarOpacity: toolbarOpacity, + isScrolledUnder: isScrolledUnder, + hasLeading: leading != null || automaticallyImplyLeading, + child: AppBar( + clipBehavior: clipBehavior, + leading: leading, + automaticallyImplyLeading: automaticallyImplyLeading, + title: effectiveTitle, + actions: actions, + flexibleSpace: (title == null && flexibleSpace != null && !excludeHeaderSemantics) + ? Semantics( + header: true, + child: flexibleSpace, + ) + : flexibleSpace, + bottom: bottom, + elevation: isScrolledUnder ? elevation : 0.0, + scrolledUnderElevation: scrolledUnderElevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + backgroundColor: backgroundColor, + foregroundColor: foregroundColor, + iconTheme: iconTheme, + actionsIconTheme: actionsIconTheme, + primary: primary, + centerTitle: centerTitle, + excludeHeaderSemantics: excludeHeaderSemantics, + titleSpacing: titleSpacing, + shape: shape, + toolbarOpacity: toolbarOpacity, + bottomOpacity: pinned ? 1.0 : clampDouble(visibleMainHeight / _bottomHeight, 0.0, 1.0), + toolbarHeight: toolbarHeight, + leadingWidth: leadingWidth, + toolbarTextStyle: toolbarTextStyle, + titleTextStyle: titleTextStyle, + systemOverlayStyle: systemOverlayStyle, + forceMaterialTransparency: forceMaterialTransparency, + ), + ); + return appBar; + } + + @override + bool shouldRebuild(covariant _SliverAppBarDelegate oldDelegate) { + return leading != oldDelegate.leading + || automaticallyImplyLeading != oldDelegate.automaticallyImplyLeading + || title != oldDelegate.title + || actions != oldDelegate.actions + || flexibleSpace != oldDelegate.flexibleSpace + || bottom != oldDelegate.bottom + || _bottomHeight != oldDelegate._bottomHeight + || elevation != oldDelegate.elevation + || shadowColor != oldDelegate.shadowColor + || backgroundColor != oldDelegate.backgroundColor + || foregroundColor != oldDelegate.foregroundColor + || iconTheme != oldDelegate.iconTheme + || actionsIconTheme != oldDelegate.actionsIconTheme + || primary != oldDelegate.primary + || centerTitle != oldDelegate.centerTitle + || titleSpacing != oldDelegate.titleSpacing + || expandedHeight != oldDelegate.expandedHeight + || topPadding != oldDelegate.topPadding + || pinned != oldDelegate.pinned + || floating != oldDelegate.floating + || vsync != oldDelegate.vsync + || snapConfiguration != oldDelegate.snapConfiguration + || stretchConfiguration != oldDelegate.stretchConfiguration + || showOnScreenConfiguration != oldDelegate.showOnScreenConfiguration + || forceElevated != oldDelegate.forceElevated + || toolbarHeight != oldDelegate.toolbarHeight + || leadingWidth != oldDelegate.leadingWidth + || toolbarTextStyle != oldDelegate.toolbarTextStyle + || titleTextStyle != oldDelegate.titleTextStyle + || systemOverlayStyle != oldDelegate.systemOverlayStyle + || forceMaterialTransparency != oldDelegate.forceMaterialTransparency; + } + + @override + String toString() { + return '${describeIdentity(this)}(topPadding: ${topPadding.toStringAsFixed(1)}, bottomHeight: ${_bottomHeight.toStringAsFixed(1)}, ...)'; + } +} + +/// A Material Design app bar that integrates with a [CustomScrollView]. +/// +/// An app bar consists of a toolbar and potentially other widgets, such as a +/// [TabBar] and a [FlexibleSpaceBar]. App bars typically expose one or more +/// common actions with [IconButton]s which are optionally followed by a +/// [PopupMenuButton] for less common operations. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=R9C5KMJKluE} +/// +/// Sliver app bars are typically used as the first child of a +/// [CustomScrollView], which lets the app bar integrate with the scroll view so +/// that it can vary in height according to the scroll offset or float above the +/// other content in the scroll view. For a fixed-height app bar at the top of +/// the screen see [AppBar], which is used in the [Scaffold.appBar] slot. +/// +/// The AppBar displays the toolbar widgets, [leading], [title], and +/// [actions], above the [bottom] (if any). If a [flexibleSpace] widget is +/// specified then it is stacked behind the toolbar and the bottom widget. +/// +/// {@tool snippet} +/// +/// This is an example that could be included in a [CustomScrollView]'s +/// [CustomScrollView.slivers] list: +/// +/// ```dart +/// SliverAppBar( +/// expandedHeight: 150.0, +/// flexibleSpace: const FlexibleSpaceBar( +/// title: Text('Available seats'), +/// ), +/// actions: <Widget>[ +/// IconButton( +/// icon: const Icon(Icons.add_circle), +/// tooltip: 'Add new entry', +/// onPressed: () { /* ... */ }, +/// ), +/// ] +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool dartpad} +/// Here is an example of [SliverAppBar] when using [stretch] and [onStretchTrigger]. +/// +/// ** See code in examples/api/lib/material/app_bar/sliver_app_bar.4.dart ** +/// {@end-tool} +/// +/// +/// {@tool dartpad} +/// This sample shows a [SliverAppBar] and it's behavior when using the +/// [pinned], [snap] and [floating] parameters. +/// +/// ** See code in examples/api/lib/material/app_bar/sliver_app_bar.1.dart ** +/// {@end-tool} +/// +/// ## Animated Examples +/// +/// The following animations show how app bars with different configurations +/// behave when a user scrolls up and then down again. +/// +/// * App bar with [floating]: false, [pinned]: false, [snap]: false: +/// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar.mp4} +/// +/// * App bar with [floating]: true, [pinned]: false, [snap]: false: +/// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_floating.mp4} +/// +/// * App bar with [floating]: true, [pinned]: false, [snap]: true: +/// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_floating_snap.mp4} +/// +/// * App bar with [floating]: true, [pinned]: true, [snap]: false: +/// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_pinned_floating.mp4} +/// +/// * App bar with [floating]: true, [pinned]: true, [snap]: true: +/// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_pinned_floating_snap.mp4} +/// +/// * App bar with [floating]: false, [pinned]: true, [snap]: false: +/// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_pinned.mp4} +/// +/// The property [snap] can only be set to true if [floating] is also true. +/// +/// See also: +/// +/// * [CustomScrollView], which integrates the [SliverAppBar] into its +/// scrolling. +/// * [AppBar], which is a fixed-height app bar for use in [Scaffold.appBar]. +/// * [TabBar], which is typically placed in the [bottom] slot of the [AppBar] +/// if the screen has multiple pages arranged in tabs. +/// * [IconButton], which is used with [actions] to show buttons on the app bar. +/// * [PopupMenuButton], to show a popup menu on the app bar, via [actions]. +/// * [FlexibleSpaceBar], which is used with [flexibleSpace] when the app bar +/// can expand and collapse. +/// * <https://material.io/design/components/app-bars-top.html> +class SliverAppBar extends StatefulWidget { + /// Creates a Material Design app bar that can be placed in a [CustomScrollView]. + const SliverAppBar({ + super.key, + this.leading, + this.automaticallyImplyLeading = true, + this.title, + this.actions, + this.flexibleSpace, + this.bottom, + this.elevation, + this.scrolledUnderElevation, + this.shadowColor, + this.surfaceTintColor, + this.forceElevated = false, + this.backgroundColor, + this.foregroundColor, + this.iconTheme, + this.actionsIconTheme, + this.primary = true, + this.centerTitle, + this.excludeHeaderSemantics = false, + this.titleSpacing, + this.collapsedHeight, + this.expandedHeight, + this.floating = false, + this.pinned = false, + this.snap = false, + this.stretch = false, + this.stretchTriggerOffset = 100.0, + this.onStretchTrigger, + this.shape, + this.toolbarHeight = kToolbarHeight, + this.leadingWidth, + this.toolbarTextStyle, + this.titleTextStyle, + this.systemOverlayStyle, + this.forceMaterialTransparency = false, + this.clipBehavior, + }) : assert(floating || !snap, 'The "snap" argument only makes sense for floating app bars.'), + assert(stretchTriggerOffset > 0.0), + assert( + collapsedHeight == null || collapsedHeight >= toolbarHeight, + 'The "collapsedHeight" argument has to be larger than or equal to [toolbarHeight].', + ), + _variant = _SliverAppVariant.small; + + /// Creates a Material Design medium top app bar that can be placed + /// in a [CustomScrollView]. + /// + /// Returns a [SliverAppBar] configured with appropriate defaults + /// for a medium top app bar as defined in Material 3. It starts fully + /// expanded with the title in an area underneath the main row of icons. + /// When the [CustomScrollView] is scrolled, the title will be scrolled + /// under the main row. When it is fully collapsed, a smaller version of the + /// title will fade in on the main row. The reverse will happen if it is + /// expanded again. + /// + /// {@tool dartpad} + /// This sample shows how to use [SliverAppBar.medium] in a [CustomScrollView]. + /// + /// ** See code in examples/api/lib/material/app_bar/sliver_app_bar.2.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [AppBar], for a small or center-aligned top app bar. + /// * [SliverAppBar.large], for a large top app bar. + /// * https://m3.material.io/components/top-app-bar/overview, the Material 3 + /// app bar specification. + const SliverAppBar.medium({ + super.key, + this.leading, + this.automaticallyImplyLeading = true, + this.title, + this.actions, + this.flexibleSpace, + this.bottom, + this.elevation, + this.scrolledUnderElevation, + this.shadowColor, + this.surfaceTintColor, + this.forceElevated = false, + this.backgroundColor, + this.foregroundColor, + this.iconTheme, + this.actionsIconTheme, + this.primary = true, + this.centerTitle, + this.excludeHeaderSemantics = false, + this.titleSpacing, + this.collapsedHeight, + this.expandedHeight, + this.floating = false, + this.pinned = true, + this.snap = false, + this.stretch = false, + this.stretchTriggerOffset = 100.0, + this.onStretchTrigger, + this.shape, + this.toolbarHeight = _MediumScrollUnderFlexibleConfig.collapsedHeight, + this.leadingWidth, + this.toolbarTextStyle, + this.titleTextStyle, + this.systemOverlayStyle, + this.forceMaterialTransparency = false, + this.clipBehavior, + }) : assert(floating || !snap, 'The "snap" argument only makes sense for floating app bars.'), + assert(stretchTriggerOffset > 0.0), + assert( + collapsedHeight == null || collapsedHeight >= toolbarHeight, + 'The "collapsedHeight" argument has to be larger than or equal to [toolbarHeight].', + ), + _variant = _SliverAppVariant.medium; + + /// Creates a Material Design large top app bar that can be placed + /// in a [CustomScrollView]. + /// + /// Returns a [SliverAppBar] configured with appropriate defaults + /// for a large top app bar as defined in Material 3. It starts fully + /// expanded with the title in an area underneath the main row of icons. + /// When the [CustomScrollView] is scrolled, the title will be scrolled + /// under the main row. When it is fully collapsed, a smaller version of the + /// title will fade in on the main row. The reverse will happen if it is + /// expanded again. + /// + /// {@tool dartpad} + /// This sample shows how to use [SliverAppBar.large] in a [CustomScrollView]. + /// + /// ** See code in examples/api/lib/material/app_bar/sliver_app_bar.3.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [AppBar], for a small or center-aligned top app bar. + /// * [SliverAppBar.medium], for a medium top app bar. + /// * https://m3.material.io/components/top-app-bar/overview, the Material 3 + /// app bar specification. + const SliverAppBar.large({ + super.key, + this.leading, + this.automaticallyImplyLeading = true, + this.title, + this.actions, + this.flexibleSpace, + this.bottom, + this.elevation, + this.scrolledUnderElevation, + this.shadowColor, + this.surfaceTintColor, + this.forceElevated = false, + this.backgroundColor, + this.foregroundColor, + this.iconTheme, + this.actionsIconTheme, + this.primary = true, + this.centerTitle, + this.excludeHeaderSemantics = false, + this.titleSpacing, + this.collapsedHeight, + this.expandedHeight, + this.floating = false, + this.pinned = true, + this.snap = false, + this.stretch = false, + this.stretchTriggerOffset = 100.0, + this.onStretchTrigger, + this.shape, + this.toolbarHeight = _LargeScrollUnderFlexibleConfig.collapsedHeight, + this.leadingWidth, + this.toolbarTextStyle, + this.titleTextStyle, + this.systemOverlayStyle, + this.forceMaterialTransparency = false, + this.clipBehavior, + }) : assert(floating || !snap, 'The "snap" argument only makes sense for floating app bars.'), + assert(stretchTriggerOffset > 0.0), + assert( + collapsedHeight == null || collapsedHeight >= toolbarHeight, + 'The "collapsedHeight" argument has to be larger than or equal to [toolbarHeight].', + ), + _variant = _SliverAppVariant.large; + + /// {@macro flutter.material.appbar.leading} + /// + /// This property is used to configure an [AppBar]. + final Widget? leading; + + /// {@macro flutter.material.appbar.automaticallyImplyLeading} + /// + /// This property is used to configure an [AppBar]. + final bool automaticallyImplyLeading; + + /// {@macro flutter.material.appbar.title} + /// + /// This property is used to configure an [AppBar]. + final Widget? title; + + /// {@macro flutter.material.appbar.actions} + /// + /// This property is used to configure an [AppBar]. + final List<Widget>? actions; + + /// {@macro flutter.material.appbar.flexibleSpace} + /// + /// This property is used to configure an [AppBar]. + final Widget? flexibleSpace; + + /// {@macro flutter.material.appbar.bottom} + /// + /// This property is used to configure an [AppBar]. + final PreferredSizeWidget? bottom; + + /// {@macro flutter.material.appbar.elevation} + /// + /// This property is used to configure an [AppBar]. + final double? elevation; + + /// {@macro flutter.material.appbar.scrolledUnderElevation} + /// + /// This property is used to configure an [AppBar]. + final double? scrolledUnderElevation; + + /// {@macro flutter.material.appbar.shadowColor} + /// + /// This property is used to configure an [AppBar]. + final Color? shadowColor; + + /// {@macro flutter.material.appbar.surfaceTintColor} + /// + /// This property is used to configure an [AppBar]. + final Color? surfaceTintColor; + + /// Whether to show the shadow appropriate for the [elevation] even if the + /// content is not scrolled under the [AppBar]. + /// + /// Defaults to false, meaning that the [elevation] is only applied when the + /// [AppBar] is being displayed over content that is scrolled under it. + /// + /// When set to true, the [elevation] is applied regardless. + /// + /// Ignored when [elevation] is zero. + final bool forceElevated; + + /// {@macro flutter.material.appbar.backgroundColor} + /// + /// This property is used to configure an [AppBar]. + final Color? backgroundColor; + + /// {@macro flutter.material.appbar.foregroundColor} + /// + /// This property is used to configure an [AppBar]. + final Color? foregroundColor; + + /// {@macro flutter.material.appbar.iconTheme} + /// + /// This property is used to configure an [AppBar]. + final IconThemeData? iconTheme; + + /// {@macro flutter.material.appbar.actionsIconTheme} + /// + /// This property is used to configure an [AppBar]. + final IconThemeData? actionsIconTheme; + + /// {@macro flutter.material.appbar.primary} + /// + /// This property is used to configure an [AppBar]. + final bool primary; + + /// {@macro flutter.material.appbar.centerTitle} + /// + /// This property is used to configure an [AppBar]. + final bool? centerTitle; + + /// {@macro flutter.material.appbar.excludeHeaderSemantics} + /// + /// This property is used to configure an [AppBar]. + final bool excludeHeaderSemantics; + + /// {@macro flutter.material.appbar.titleSpacing} + /// + /// This property is used to configure an [AppBar]. + final double? titleSpacing; + + /// Defines the height of the app bar when it is collapsed. + /// + /// By default, the collapsed height is [toolbarHeight]. If [bottom] widget is + /// specified, then its height from [PreferredSizeWidget.preferredSize] is + /// added to the height. If [primary] is true, then the [MediaQuery] top + /// padding, [EdgeInsets.top] of [MediaQueryData.padding], is added as well. + /// + /// If [pinned] and [floating] are true, with [bottom] set, the default + /// collapsed height is only the height of [PreferredSizeWidget.preferredSize] + /// with the [MediaQuery] top padding. + final double? collapsedHeight; + + /// The size of the app bar when it is fully expanded. + /// + /// By default, the total height of the toolbar and the bottom widget (if + /// any). If a [flexibleSpace] widget is specified this height should be big + /// enough to accommodate whatever that widget contains. + /// + /// This does not include the status bar height (which will be automatically + /// included if [primary] is true). + final double? expandedHeight; + + /// Whether the app bar should become visible as soon as the user scrolls + /// towards the app bar. + /// + /// Otherwise, the user will need to scroll near the top of the scroll view to + /// reveal the app bar. + /// + /// If [snap] is true then a scroll that exposes the app bar will trigger an + /// animation that slides the entire app bar into view. Similarly if a scroll + /// dismisses the app bar, the animation will slide it completely out of view. + /// + /// ## Animated Examples + /// + /// The following animations show how the app bar changes its scrolling + /// behavior based on the value of this property. + /// + /// * App bar with [floating] set to false: + /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar.mp4} + /// * App bar with [floating] set to true: + /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_floating.mp4} + /// + /// See also: + /// + /// * [SliverAppBar] for more animated examples of how this property changes the + /// behavior of the app bar in combination with [pinned] and [snap]. + final bool floating; + + /// Whether the app bar should remain visible at the start of the scroll view. + /// + /// The app bar can still expand and contract as the user scrolls, but it will + /// remain visible rather than being scrolled out of view. + /// + /// ## Animated Examples + /// + /// The following animations show how the app bar changes its scrolling + /// behavior based on the value of this property. + /// + /// * App bar with [pinned] set to false: + /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar.mp4} + /// * App bar with [pinned] set to true: + /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_pinned.mp4} + /// + /// See also: + /// + /// * [SliverAppBar] for more animated examples of how this property changes the + /// behavior of the app bar in combination with [floating]. + final bool pinned; + + /// {@macro flutter.material.appbar.shape} + /// + /// This property is used to configure an [AppBar]. + final ShapeBorder? shape; + + /// If [snap] and [floating] are true then the floating app bar will "snap" + /// into view. + /// + /// If [snap] is true then a scroll that exposes the floating app bar will + /// trigger an animation that slides the entire app bar into view. Similarly + /// if a scroll dismisses the app bar, the animation will slide the app bar + /// completely out of view. Additionally, setting [snap] to true will fully + /// expand the floating app bar when the framework tries to reveal the + /// contents of the app bar by calling [RenderObject.showOnScreen]. For + /// example, when a [TextField] in the floating app bar gains focus, if [snap] + /// is true, the framework will always fully expand the floating app bar, in + /// order to reveal the focused [TextField]. + /// + /// Snapping only applies when the app bar is floating, not when the app bar + /// appears at the top of its scroll view. + /// + /// ## Animated Examples + /// + /// The following animations show how the app bar changes its scrolling + /// behavior based on the value of this property. + /// + /// * App bar with [snap] set to false: + /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_floating.mp4} + /// * App bar with [snap] set to true: + /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_floating_snap.mp4} + /// + /// See also: + /// + /// * [SliverAppBar] for more animated examples of how this property changes the + /// behavior of the app bar in combination with [pinned] and [floating]. + final bool snap; + + /// Whether the app bar should stretch to fill the over-scroll area. + /// + /// The app bar can still expand and contract as the user scrolls, but it will + /// also stretch when the user over-scrolls. + final bool stretch; + + /// The offset of overscroll required to activate [onStretchTrigger]. + /// + /// This defaults to 100.0. + final double stretchTriggerOffset; + + /// The callback function to be executed when a user over-scrolls to the + /// offset specified by [stretchTriggerOffset]. + final AsyncCallback? onStretchTrigger; + + /// {@macro flutter.material.appbar.toolbarHeight} + /// + /// This property is used to configure an [AppBar]. + final double toolbarHeight; + + /// {@macro flutter.material.appbar.leadingWidth} + /// + /// This property is used to configure an [AppBar]. + final double? leadingWidth; + + /// {@macro flutter.material.appbar.toolbarTextStyle} + /// + /// This property is used to configure an [AppBar]. + final TextStyle? toolbarTextStyle; + + /// {@macro flutter.material.appbar.titleTextStyle} + /// + /// This property is used to configure an [AppBar]. + final TextStyle? titleTextStyle; + + /// {@macro flutter.material.appbar.systemOverlayStyle} + /// + /// This property is used to configure an [AppBar]. + final SystemUiOverlayStyle? systemOverlayStyle; + + /// {@macro flutter.material.appbar.forceMaterialTransparency} + /// + /// This property is used to configure an [AppBar]. + final bool forceMaterialTransparency; + + /// {@macro flutter.material.Material.clipBehavior} + final Clip? clipBehavior; + + final _SliverAppVariant _variant; + + @override + State<SliverAppBar> createState() => _SliverAppBarState(); +} + +// This class is only Stateful because it owns the TickerProvider used +// by the floating appbar snap animation (via FloatingHeaderSnapConfiguration). +class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMixin { + FloatingHeaderSnapConfiguration? _snapConfiguration; + OverScrollHeaderStretchConfiguration? _stretchConfiguration; + PersistentHeaderShowOnScreenConfiguration? _showOnScreenConfiguration; + + void _updateSnapConfiguration() { + if (widget.snap && widget.floating) { + _snapConfiguration = FloatingHeaderSnapConfiguration( + curve: Curves.easeOut, + duration: const Duration(milliseconds: 200), + ); + } else { + _snapConfiguration = null; + } + + _showOnScreenConfiguration = widget.floating & widget.snap + ? const PersistentHeaderShowOnScreenConfiguration(minShowOnScreenExtent: double.infinity) + : null; + } + + void _updateStretchConfiguration() { + if (widget.stretch) { + _stretchConfiguration = OverScrollHeaderStretchConfiguration( + stretchTriggerOffset: widget.stretchTriggerOffset, + onStretchTrigger: widget.onStretchTrigger, + ); + } else { + _stretchConfiguration = null; + } + } + + @override + void initState() { + super.initState(); + _updateSnapConfiguration(); + _updateStretchConfiguration(); + } + + @override + void didUpdateWidget(SliverAppBar oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.snap != oldWidget.snap || widget.floating != oldWidget.floating) { + _updateSnapConfiguration(); + } + if (widget.stretch != oldWidget.stretch) { + _updateStretchConfiguration(); + } + } + + @override + Widget build(BuildContext context) { + assert(!widget.primary || debugCheckHasMediaQuery(context)); + final double bottomHeight = widget.bottom?.preferredSize.height ?? 0.0; + final double topPadding = widget.primary ? MediaQuery.paddingOf(context).top : 0.0; + final double collapsedHeight = (widget.pinned && widget.floating && widget.bottom != null) + ? (widget.collapsedHeight ?? 0.0) + bottomHeight + topPadding + : (widget.collapsedHeight ?? widget.toolbarHeight) + bottomHeight + topPadding; + final double? effectiveExpandedHeight; + final double effectiveCollapsedHeight; + final Widget? effectiveFlexibleSpace; + switch (widget._variant) { + case _SliverAppVariant.small: + effectiveExpandedHeight = widget.expandedHeight; + effectiveCollapsedHeight = collapsedHeight; + effectiveFlexibleSpace = widget.flexibleSpace; + case _SliverAppVariant.medium: + effectiveExpandedHeight = widget.expandedHeight + ?? _MediumScrollUnderFlexibleConfig.expandedHeight + bottomHeight; + effectiveCollapsedHeight = widget.collapsedHeight + ?? topPadding + _MediumScrollUnderFlexibleConfig.collapsedHeight + bottomHeight; + effectiveFlexibleSpace = widget.flexibleSpace ?? _ScrollUnderFlexibleSpace( + title: widget.title, + foregroundColor: widget.foregroundColor, + configBuilder: _MediumScrollUnderFlexibleConfig.new, + titleTextStyle: widget.titleTextStyle, + bottomHeight: bottomHeight, + ); + case _SliverAppVariant.large: + effectiveExpandedHeight = widget.expandedHeight + ?? _LargeScrollUnderFlexibleConfig.expandedHeight + bottomHeight; + effectiveCollapsedHeight = widget.collapsedHeight + ?? topPadding + _LargeScrollUnderFlexibleConfig.collapsedHeight + bottomHeight; + effectiveFlexibleSpace = widget.flexibleSpace ?? _ScrollUnderFlexibleSpace( + title: widget.title, + foregroundColor: widget.foregroundColor, + configBuilder: _LargeScrollUnderFlexibleConfig.new, + titleTextStyle: widget.titleTextStyle, + bottomHeight: bottomHeight, + ); + } + + return MediaQuery.removePadding( + context: context, + removeBottom: true, + child: SliverPersistentHeader( + floating: widget.floating, + pinned: widget.pinned, + delegate: _SliverAppBarDelegate( + vsync: this, + leading: widget.leading, + automaticallyImplyLeading: widget.automaticallyImplyLeading, + title: widget.title, + actions: widget.actions, + flexibleSpace: effectiveFlexibleSpace, + bottom: widget.bottom, + elevation: widget.elevation, + scrolledUnderElevation: widget.scrolledUnderElevation, + shadowColor: widget.shadowColor, + surfaceTintColor: widget.surfaceTintColor, + forceElevated: widget.forceElevated, + backgroundColor: widget.backgroundColor, + foregroundColor: widget.foregroundColor, + iconTheme: widget.iconTheme, + actionsIconTheme: widget.actionsIconTheme, + primary: widget.primary, + centerTitle: widget.centerTitle, + excludeHeaderSemantics: widget.excludeHeaderSemantics, + titleSpacing: widget.titleSpacing, + expandedHeight: effectiveExpandedHeight, + collapsedHeight: effectiveCollapsedHeight, + topPadding: topPadding, + floating: widget.floating, + pinned: widget.pinned, + shape: widget.shape, + snapConfiguration: _snapConfiguration, + stretchConfiguration: _stretchConfiguration, + showOnScreenConfiguration: _showOnScreenConfiguration, + toolbarHeight: widget.toolbarHeight, + leadingWidth: widget.leadingWidth, + toolbarTextStyle: widget.toolbarTextStyle, + titleTextStyle: widget.titleTextStyle, + systemOverlayStyle: widget.systemOverlayStyle, + forceMaterialTransparency: widget.forceMaterialTransparency, + clipBehavior: widget.clipBehavior, + variant: widget._variant, + ), + ), + ); + } +} + +// Layout the AppBar's title with unconstrained height, vertically +// center it within its (NavigationToolbar) parent, and allow the +// parent to constrain the title's actual height. +class _AppBarTitleBox extends SingleChildRenderObjectWidget { + const _AppBarTitleBox({ required Widget super.child }); + + @override + _RenderAppBarTitleBox createRenderObject(BuildContext context) { + return _RenderAppBarTitleBox( + textDirection: Directionality.of(context), + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderAppBarTitleBox renderObject) { + renderObject.textDirection = Directionality.of(context); + } +} + +class _RenderAppBarTitleBox extends RenderAligningShiftedBox { + _RenderAppBarTitleBox({ + super.textDirection, + }) : super(alignment: Alignment.center); + + @override + Size computeDryLayout(BoxConstraints constraints) { + final BoxConstraints innerConstraints = constraints.copyWith(maxHeight: double.infinity); + final Size childSize = child!.getDryLayout(innerConstraints); + return constraints.constrain(childSize); + } + + @override + void performLayout() { + final BoxConstraints innerConstraints = constraints.copyWith(maxHeight: double.infinity); + child!.layout(innerConstraints, parentUsesSize: true); + size = constraints.constrain(child!.size); + alignChild(); + } +} + +class _ScrollUnderFlexibleSpace extends StatelessWidget { + const _ScrollUnderFlexibleSpace({ + this.title, + this.foregroundColor, + required this.configBuilder, + this.titleTextStyle, + required this.bottomHeight, + }); + + final Widget? title; + final Color? foregroundColor; + final _FlexibleConfigBuilder configBuilder; + final TextStyle? titleTextStyle; + final double bottomHeight; + + @override + Widget build(BuildContext context) { + late final AppBarTheme appBarTheme = AppBarTheme.of(context); + late final AppBarTheme defaults = Theme.of(context).useMaterial3 ? _AppBarDefaultsM3(context) : _AppBarDefaultsM2(context); + final FlexibleSpaceBarSettings settings = context.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>()!; + final _ScrollUnderFlexibleConfig config = configBuilder(context); + assert( + config.expandedTitlePadding.isNonNegative, + 'The _ExpandedTitleWithPadding widget assumes that the expanded title padding is non-negative. ' + 'Update its implementation to handle negative padding.', + ); + + final TextStyle? expandedTextStyle = titleTextStyle + ?? appBarTheme.titleTextStyle + ?? config.expandedTextStyle?.copyWith(color: foregroundColor ?? appBarTheme.foregroundColor ?? defaults.foregroundColor); + + final Widget? expandedTitle = switch ((title, expandedTextStyle)) { + (null, _) => null, + (final Widget title, null) => title, + (final Widget title, final TextStyle textStyle) => DefaultTextStyle(style: textStyle, child: title), + }; + + final EdgeInsets resolvedTitlePadding = config.expandedTitlePadding.resolve(Directionality.of(context)); + final EdgeInsetsGeometry expandedTitlePadding = bottomHeight > 0 + ? resolvedTitlePadding.copyWith(bottom: 0) + : resolvedTitlePadding; + + // Set maximum text scale factor to [_kMaxTitleTextScaleFactor] for the + // title to keep the visual hierarchy the same even with larger font + // sizes. To opt out, wrap the [title] widget in a [MediaQuery] widget + // with a different TextScaler. + // TODO(tahatesser): Add link to Material spec when available, https://github.com/flutter/flutter/issues/58769. + return MediaQuery.withClampedTextScaling( + maxScaleFactor: _kMaxTitleTextScaleFactor, + // This column will assume the full height of the parent Stack. + child: Column( + children: <Widget>[ + Padding(padding: EdgeInsets.only(top: settings.minExtent - bottomHeight)), + Flexible( + child: ClipRect( + child: _ExpandedTitleWithPadding( + padding: expandedTitlePadding, + maxExtent: settings.maxExtent - settings.minExtent, + child: expandedTitle, + ), + ), + ), + // Reserve space for AppBar.bottom, which is a sibling of this widget, + // on the parent Stack. + if (bottomHeight > 0) Padding(padding: EdgeInsets.only(bottom: bottomHeight)), + ], + ), + ); + } +} + +// A widget that bottom-start aligns its child (the expanded title widget), and +// insets the child according to the specified padding. +// +// This widget gives the child an infinite max height constraint, and will also +// attempt to vertically limit the child's bounding box (not including the +// padding) to within the y range [0, maxExtent], to make sure the child is +// visible when the AppBar is fully expanded. +class _ExpandedTitleWithPadding extends SingleChildRenderObjectWidget { + const _ExpandedTitleWithPadding({ + required this.padding, + required this.maxExtent, + super.child, + }); + + final EdgeInsetsGeometry padding; + final double maxExtent; + + @override + _RenderExpandedTitleBox createRenderObject(BuildContext context) { + final TextDirection textDirection = Directionality.of(context); + return _RenderExpandedTitleBox( + padding.resolve(textDirection), + AlignmentDirectional.bottomStart.resolve(textDirection), + maxExtent, + null, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderExpandedTitleBox renderObject) { + final TextDirection textDirection = Directionality.of(context); + renderObject + ..padding = padding.resolve(textDirection) + ..titleAlignment = AlignmentDirectional.bottomStart.resolve(textDirection) + ..maxExtent = maxExtent; + } +} + +class _RenderExpandedTitleBox extends RenderShiftedBox { + _RenderExpandedTitleBox(this._padding, this._titleAlignment, this._maxExtent, super.child); + + EdgeInsets get padding => _padding; + EdgeInsets _padding; + set padding(EdgeInsets value) { + if (_padding == value) { + return; + } + assert(value.isNonNegative); + _padding = value; + markNeedsLayout(); + } + + Alignment get titleAlignment => _titleAlignment; + Alignment _titleAlignment; + set titleAlignment(Alignment value) { + if (_titleAlignment == value) { + return; + } + _titleAlignment = value; + markNeedsLayout(); + } + + double get maxExtent => _maxExtent; + double _maxExtent; + set maxExtent(double value) { + if (_maxExtent == value) { + return; + } + _maxExtent = value; + markNeedsLayout(); + } + + @override + double computeMaxIntrinsicHeight(double width) { + final RenderBox? child = this.child; + return child == null ? 0.0 : child.getMaxIntrinsicHeight(math.max(0, width - padding.horizontal)) + padding.vertical; + } + + @override + double computeMaxIntrinsicWidth(double height) { + final RenderBox? child = this.child; + return child == null ? 0.0 : child.getMaxIntrinsicWidth(double.infinity) + padding.horizontal; + } + + @override + double computeMinIntrinsicHeight(double width) { + final RenderBox? child = this.child; + return child == null ? 0.0 : child.getMinIntrinsicHeight(math.max(0, width - padding.horizontal)) + padding.vertical; + } + + @override + double computeMinIntrinsicWidth(double height) { + final RenderBox? child = this.child; + return child == null ? 0.0 : child.getMinIntrinsicWidth(double.infinity) + padding.horizontal; + } + + Size _computeSize(BoxConstraints constraints, ChildLayouter layoutChild) { + final RenderBox? child = this.child; + if (child == null) { + return Size.zero; + } + layoutChild(child, constraints.widthConstraints().deflate(padding)); + return constraints.biggest; + } + + @override + Size computeDryLayout(BoxConstraints constraints) => _computeSize(constraints, ChildLayoutHelper.dryLayoutChild); + + @override + void performLayout() { + final RenderBox? child = this.child; + if (child == null) { + this.size = constraints.smallest; + return; + } + final Size size = this.size = _computeSize(constraints, ChildLayoutHelper.layoutChild); + final Size childSize = child.size; + + assert(padding.isNonNegative); + assert(titleAlignment.y == 1.0); + // yAdjustment is the minimum additional y offset to shift the child in + // the visible vertical space when AppBar is fully expanded. The goal is to + // prevent the expanded title from being clipped when the expanded title + // widget + the bottom padding is too tall to fit in the flexible space (the + // top padding is basically ignored since the expanded title is + // bottom-aligned). + final double yAdjustment = clampDouble(childSize.height + padding.bottom - maxExtent, 0, padding.bottom); + final double offsetY = size.height - childSize.height - padding.bottom + yAdjustment; + final double offsetX = (titleAlignment.x + 1) / 2 * (size.width - padding.horizontal - childSize.width) + padding.left; + + final BoxParentData childParentData = child.parentData! as BoxParentData; + childParentData.offset = Offset(offsetX, offsetY); + } +} + +mixin _ScrollUnderFlexibleConfig { + TextStyle? get collapsedTextStyle; + TextStyle? get expandedTextStyle; + EdgeInsetsGeometry get expandedTitlePadding; +} + +// Hand coded defaults based on Material Design 2. +class _AppBarDefaultsM2 extends AppBarTheme { + _AppBarDefaultsM2(this.context) + : super( + elevation: 4.0, + shadowColor: const Color(0xFF000000), + titleSpacing: NavigationToolbar.kMiddleSpacing, + toolbarHeight: kToolbarHeight, + ); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + + @override + Color? get backgroundColor => _colors.brightness == Brightness.dark ? _colors.surface : _colors.primary; + + @override + Color? get foregroundColor => _colors.brightness == Brightness.dark ? _colors.onSurface : _colors.onPrimary; + + @override + IconThemeData? get iconTheme => _theme.iconTheme; + + @override + TextStyle? get toolbarTextStyle => _theme.textTheme.bodyMedium; + + @override + TextStyle? get titleTextStyle => _theme.textTheme.titleLarge; +} + +// BEGIN GENERATED TOKEN PROPERTIES - AppBar + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _AppBarDefaultsM3 extends AppBarTheme { + _AppBarDefaultsM3(this.context) + : super( + elevation: 0.0, + scrolledUnderElevation: 3.0, + titleSpacing: NavigationToolbar.kMiddleSpacing, + toolbarHeight: 64.0, + ); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + late final TextTheme _textTheme = _theme.textTheme; + + @override + Color? get backgroundColor => _colors.surface; + + @override + Color? get foregroundColor => _colors.onSurface; + + @override + Color? get shadowColor => Colors.transparent; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + IconThemeData? get iconTheme => IconThemeData( + color: _colors.onSurface, + size: 24.0, + ); + + @override + IconThemeData? get actionsIconTheme => IconThemeData( + color: _colors.onSurfaceVariant, + size: 24.0, + ); + + @override + TextStyle? get toolbarTextStyle => _textTheme.bodyMedium; + + @override + TextStyle? get titleTextStyle => _textTheme.titleLarge; +} + +// Variant configuration +class _MediumScrollUnderFlexibleConfig with _ScrollUnderFlexibleConfig { + _MediumScrollUnderFlexibleConfig(this.context); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + late final TextTheme _textTheme = _theme.textTheme; + + static const double collapsedHeight = 64.0; + static const double expandedHeight = 112.0; + + @override + TextStyle? get collapsedTextStyle => + _textTheme.titleLarge?.apply(color: _colors.onSurface); + + @override + TextStyle? get expandedTextStyle => + _textTheme.headlineSmall?.apply(color: _colors.onSurface); + + @override + EdgeInsetsGeometry get expandedTitlePadding => const EdgeInsets.fromLTRB(16, 0, 16, 20); +} + +class _LargeScrollUnderFlexibleConfig with _ScrollUnderFlexibleConfig { + _LargeScrollUnderFlexibleConfig(this.context); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + late final TextTheme _textTheme = _theme.textTheme; + + static const double collapsedHeight = 64.0; + static const double expandedHeight = 152.0; + + @override + TextStyle? get collapsedTextStyle => + _textTheme.titleLarge?.apply(color: _colors.onSurface); + + @override + TextStyle? get expandedTextStyle => + _textTheme.headlineMedium?.apply(color: _colors.onSurface); + + @override + EdgeInsetsGeometry get expandedTitlePadding => const EdgeInsets.fromLTRB(16, 0, 16, 28); +} + +// END GENERATED TOKEN PROPERTIES - AppBar diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/app_bar_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/app_bar_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..c8528b5d7d99a25727f30253fe1169acae30ddc7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/app_bar_theme.dart @@ -0,0 +1,290 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +/// Overrides the default values of visual properties for descendant +/// [AppBar] widgets. +/// +/// Descendant widgets obtain the current [AppBarTheme] object with +/// `AppBarTheme.of(context)`. Instances of [AppBarTheme] can be customized +/// with [AppBarTheme.copyWith]. +/// +/// Typically an [AppBarTheme] is specified as part of the overall [Theme] with +/// [ThemeData.appBarTheme]. +/// +/// All [AppBarTheme] properties are `null` by default. When null, the [AppBar] +/// compute its own default values, typically based on the overall theme's +/// [ThemeData.colorScheme], [ThemeData.textTheme], and [ThemeData.iconTheme]. +@immutable +class AppBarTheme with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.appBarTheme]. + const AppBarTheme({ + Color? color, + Color? backgroundColor, + this.foregroundColor, + this.elevation, + this.scrolledUnderElevation, + this.shadowColor, + this.surfaceTintColor, + this.shape, + this.iconTheme, + this.actionsIconTheme, + this.centerTitle, + this.titleSpacing, + this.toolbarHeight, + this.toolbarTextStyle, + this.titleTextStyle, + this.systemOverlayStyle, + }) : assert( + color == null || backgroundColor == null, + 'The color and backgroundColor parameters mean the same thing. Only specify one.', + ), + backgroundColor = backgroundColor ?? color; + + /// Overrides the default value of [AppBar.backgroundColor] in all + /// descendant [AppBar] widgets. + /// + /// See also: + /// + /// * [foregroundColor], which overrides the default value of + /// [AppBar.foregroundColor] in all descendant [AppBar] widgets. + final Color? backgroundColor; + + /// Overrides the default value of [AppBar.foregroundColor] in all + /// descendant [AppBar] widgets. + /// + /// See also: + /// + /// * [backgroundColor], which overrides the default value of + /// [AppBar.backgroundColor] in all descendant [AppBar] widgets. + final Color? foregroundColor; + + /// Overrides the default value of [AppBar.elevation] in all + /// descendant [AppBar] widgets. + final double? elevation; + + /// Overrides the default value of [AppBar.scrolledUnderElevation] in all + /// descendant [AppBar] widgets. + final double? scrolledUnderElevation; + + /// Overrides the default value of [AppBar.shadowColor] in all + /// descendant [AppBar] widgets. + final Color? shadowColor; + + /// Overrides the default value of [AppBar.surfaceTintColor] in all + /// descendant [AppBar] widgets. + final Color? surfaceTintColor; + + /// Overrides the default value of [AppBar.shape] in all + /// descendant [AppBar] widgets. + final ShapeBorder? shape; + + /// Overrides the default value of [AppBar.iconTheme] in all + /// descendant [AppBar] widgets. + /// + /// See also: + /// + /// * [actionsIconTheme], which overrides the default value of + /// [AppBar.actionsIconTheme] in all descendant [AppBar] widgets. + /// * [foregroundColor], which overrides the default value + /// [AppBar.foregroundColor] in all descendant [AppBar] widgets. + final IconThemeData? iconTheme; + + /// Overrides the default value of [AppBar.actionsIconTheme] in all + /// descendant [AppBar] widgets. + /// + /// See also: + /// + /// * [iconTheme], which overrides the default value of + /// [AppBar.iconTheme] in all descendant [AppBar] widgets. + /// * [foregroundColor], which overrides the default value + /// [AppBar.foregroundColor] in all descendant [AppBar] widgets. + final IconThemeData? actionsIconTheme; + + /// Overrides the default value of [AppBar.centerTitle] + /// property in all descendant [AppBar] widgets. + final bool? centerTitle; + + /// Overrides the default value of the obsolete [AppBar.titleSpacing] + /// property in all descendant [AppBar] widgets. + /// + /// If null, [AppBar] uses default value of [NavigationToolbar.kMiddleSpacing]. + final double? titleSpacing; + + /// Overrides the default value of the [AppBar.toolbarHeight] + /// property in all descendant [AppBar] widgets. + /// + /// See also: + /// + /// * [AppBar.preferredHeightFor], which computes the overall + /// height of an AppBar widget, taking this value into account. + final double? toolbarHeight; + + /// Overrides the default value of the obsolete [AppBar.toolbarTextStyle] + /// property in all descendant [AppBar] widgets. + /// + /// See also: + /// + /// * [titleTextStyle], which overrides the default of [AppBar.titleTextStyle] + /// in all descendant [AppBar] widgets. + final TextStyle? toolbarTextStyle; + + /// Overrides the default value of [AppBar.titleTextStyle] + /// property in all descendant [AppBar] widgets. + /// + /// See also: + /// + /// * [toolbarTextStyle], which overrides the default of [AppBar.toolbarTextStyle] + /// in all descendant [AppBar] widgets. + final TextStyle? titleTextStyle; + + /// Overrides the default value of [AppBar.systemOverlayStyle] + /// property in all descendant [AppBar] widgets. + final SystemUiOverlayStyle? systemOverlayStyle; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + AppBarTheme copyWith({ + IconThemeData? actionsIconTheme, + Color? color, + Color? backgroundColor, + Color? foregroundColor, + double? elevation, + double? scrolledUnderElevation, + Color? shadowColor, + Color? surfaceTintColor, + ShapeBorder? shape, + IconThemeData? iconTheme, + bool? centerTitle, + double? titleSpacing, + double? toolbarHeight, + TextStyle? toolbarTextStyle, + TextStyle? titleTextStyle, + SystemUiOverlayStyle? systemOverlayStyle, + }) { + assert( + color == null || backgroundColor == null, + 'The color and backgroundColor parameters mean the same thing. Only specify one.', + ); + return AppBarTheme( + backgroundColor: backgroundColor ?? color ?? this.backgroundColor, + foregroundColor: foregroundColor ?? this.foregroundColor, + elevation: elevation ?? this.elevation, + scrolledUnderElevation: scrolledUnderElevation ?? this.scrolledUnderElevation, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + shape: shape ?? this.shape, + iconTheme: iconTheme ?? this.iconTheme, + actionsIconTheme: actionsIconTheme ?? this.actionsIconTheme, + centerTitle: centerTitle ?? this.centerTitle, + titleSpacing: titleSpacing ?? this.titleSpacing, + toolbarHeight: toolbarHeight ?? this.toolbarHeight, + toolbarTextStyle: toolbarTextStyle ?? this.toolbarTextStyle, + titleTextStyle: titleTextStyle ?? this.titleTextStyle, + systemOverlayStyle: systemOverlayStyle ?? this.systemOverlayStyle, + ); + } + + /// The [ThemeData.appBarTheme] property of the ambient [Theme]. + static AppBarTheme of(BuildContext context) { + return Theme.of(context).appBarTheme; + } + + /// Linearly interpolate between two AppBar themes. + /// + /// {@macro dart.ui.shadow.lerp} + static AppBarTheme lerp(AppBarTheme? a, AppBarTheme? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return AppBarTheme( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + scrolledUnderElevation: lerpDouble(a?.scrolledUnderElevation, b?.scrolledUnderElevation, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + iconTheme: IconThemeData.lerp(a?.iconTheme, b?.iconTheme, t), + actionsIconTheme: IconThemeData.lerp(a?.actionsIconTheme, b?.actionsIconTheme, t), + centerTitle: t < 0.5 ? a?.centerTitle : b?.centerTitle, + titleSpacing: lerpDouble(a?.titleSpacing, b?.titleSpacing, t), + toolbarHeight: lerpDouble(a?.toolbarHeight, b?.toolbarHeight, t), + toolbarTextStyle: TextStyle.lerp(a?.toolbarTextStyle, b?.toolbarTextStyle, t), + titleTextStyle: TextStyle.lerp(a?.titleTextStyle, b?.titleTextStyle, t), + systemOverlayStyle: t < 0.5 ? a?.systemOverlayStyle : b?.systemOverlayStyle, + ); + } + + @override + int get hashCode => Object.hash( + backgroundColor, + foregroundColor, + elevation, + scrolledUnderElevation, + shadowColor, + surfaceTintColor, + shape, + iconTheme, + actionsIconTheme, + centerTitle, + titleSpacing, + toolbarHeight, + toolbarTextStyle, + titleTextStyle, + systemOverlayStyle, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is AppBarTheme + && other.backgroundColor == backgroundColor + && other.foregroundColor == foregroundColor + && other.elevation == elevation + && other.scrolledUnderElevation == scrolledUnderElevation + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.shape == shape + && other.iconTheme == iconTheme + && other.actionsIconTheme == actionsIconTheme + && other.centerTitle == centerTitle + && other.titleSpacing == titleSpacing + && other.toolbarHeight == toolbarHeight + && other.toolbarTextStyle == toolbarTextStyle + && other.titleTextStyle == titleTextStyle + && other.systemOverlayStyle == systemOverlayStyle; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null)); + properties.add(DiagnosticsProperty<double>('scrolledUnderElevation', scrolledUnderElevation, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<IconThemeData>('iconTheme', iconTheme, defaultValue: null)); + properties.add(DiagnosticsProperty<IconThemeData>('actionsIconTheme', actionsIconTheme, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('centerTitle', centerTitle, defaultValue: null)); + properties.add(DiagnosticsProperty<double>('titleSpacing', titleSpacing, defaultValue: null)); + properties.add(DiagnosticsProperty<double>('toolbarHeight', toolbarHeight, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('toolbarTextStyle', toolbarTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('titleTextStyle', titleTextStyle, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/arc.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/arc.dart new file mode 100644 index 0000000000000000000000000000000000000000..d194d08c159ecab5730cda790ad80e626e019a1a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/arc.dart @@ -0,0 +1,441 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; + +// How close the begin and end points must be to an axis to be considered +// vertical or horizontal. +const double _kOnAxisDelta = 2.0; + +/// A [Tween] that interpolates an [Offset] along a circular arc. +/// +/// This class specializes the interpolation of [Tween<Offset>] so that instead +/// of a straight line, the intermediate points follow the arc of a circle in a +/// manner consistent with Material Design principles. +/// +/// The arc's radius is related to the bounding box that contains the [begin] +/// and [end] points. If the bounding box is taller than it is wide, then the +/// center of the circle will be horizontally aligned with the end point. +/// Otherwise the center of the circle will be aligned with the begin point. +/// The arc's sweep is always less than or equal to 90 degrees. +/// +/// See also: +/// +/// * [Tween], for a discussion on how to use interpolation objects. +/// * [MaterialRectArcTween], which extends this concept to interpolating [Rect]s. +class MaterialPointArcTween extends Tween<Offset> { + /// Creates a [Tween] for animating [Offset]s along a circular arc. + /// + /// The [begin] and [end] properties must be non-null before the tween is + /// first used, but the arguments can be null if the values are going to be + /// filled in later. + MaterialPointArcTween({ + super.begin, + super.end, + }); + + bool _dirty = true; + + void _initialize() { + assert(this.begin != null); + assert(this.end != null); + + final Offset begin = this.begin!; + final Offset end = this.end!; + + // An explanation with a diagram can be found at https://goo.gl/vMSdRg + final Offset delta = end - begin; + final double deltaX = delta.dx.abs(); + final double deltaY = delta.dy.abs(); + final double distanceFromAtoB = delta.distance; + final Offset c = Offset(end.dx, begin.dy); + + double sweepAngle() => 2.0 * math.asin(distanceFromAtoB / (2.0 * _radius!)); + + if (deltaX > _kOnAxisDelta && deltaY > _kOnAxisDelta) { + if (deltaX < deltaY) { + _radius = distanceFromAtoB * distanceFromAtoB / (c - begin).distance / 2.0; + _center = Offset(end.dx + _radius! * (begin.dx - end.dx).sign, end.dy); + if (begin.dx < end.dx) { + _beginAngle = sweepAngle() * (begin.dy - end.dy).sign; + _endAngle = 0.0; + } else { + _beginAngle = math.pi + sweepAngle() * (end.dy - begin.dy).sign; + _endAngle = math.pi; + } + } else { + _radius = distanceFromAtoB * distanceFromAtoB / (c - end).distance / 2.0; + _center = Offset(begin.dx, begin.dy + (end.dy - begin.dy).sign * _radius!); + if (begin.dy < end.dy) { + _beginAngle = -math.pi / 2.0; + _endAngle = _beginAngle! + sweepAngle() * (end.dx - begin.dx).sign; + } else { + _beginAngle = math.pi / 2.0; + _endAngle = _beginAngle! + sweepAngle() * (begin.dx - end.dx).sign; + } + } + assert(_beginAngle != null); + assert(_endAngle != null); + } else { + _beginAngle = null; + _endAngle = null; + } + _dirty = false; + } + + /// The center of the circular arc, null if [begin] and [end] are horizontally or + /// vertically aligned, or if either is null. + Offset? get center { + if (begin == null || end == null) { + return null; + } + if (_dirty) { + _initialize(); + } + return _center; + } + Offset? _center; + + /// The radius of the circular arc, null if [begin] and [end] are horizontally or + /// vertically aligned, or if either is null. + double? get radius { + if (begin == null || end == null) { + return null; + } + if (_dirty) { + _initialize(); + } + return _radius; + } + double? _radius; + + /// The beginning of the arc's sweep in radians, measured from the positive x + /// axis. Positive angles turn clockwise. + /// + /// This will be null if [begin] and [end] are horizontally or vertically + /// aligned, or if either is null. + double? get beginAngle { + if (begin == null || end == null) { + return null; + } + if (_dirty) { + _initialize(); + } + return _beginAngle; + } + double? _beginAngle; + + /// The end of the arc's sweep in radians, measured from the positive x axis. + /// Positive angles turn clockwise. + /// + /// This will be null if [begin] and [end] are horizontally or vertically + /// aligned, or if either is null. + double? get endAngle { + if (begin == null || end == null) { + return null; + } + if (_dirty) { + _initialize(); + } + return _beginAngle; + } + double? _endAngle; + + @override + set begin(Offset? value) { + if (value != begin) { + super.begin = value; + _dirty = true; + } + } + + @override + set end(Offset? value) { + if (value != end) { + super.end = value; + _dirty = true; + } + } + + @override + Offset lerp(double t) { + if (_dirty) { + _initialize(); + } + if (t == 0.0) { + return begin!; + } + if (t == 1.0) { + return end!; + } + if (_beginAngle == null || _endAngle == null) { + return Offset.lerp(begin, end, t)!; + } + final double angle = lerpDouble(_beginAngle, _endAngle, t)!; + final double x = math.cos(angle) * _radius!; + final double y = math.sin(angle) * _radius!; + return _center! + Offset(x, y); + } + + @override + String toString() { + return '${objectRuntimeType(this, 'MaterialPointArcTween')}($begin \u2192 $end; center=$center, radius=$radius, beginAngle=$beginAngle, endAngle=$endAngle)'; + } +} + +enum _CornerId { + topLeft, + topRight, + bottomLeft, + bottomRight +} + +class _Diagonal { + const _Diagonal(this.beginId, this.endId); + final _CornerId beginId; + final _CornerId endId; +} + +const List<_Diagonal> _allDiagonals = <_Diagonal>[ + _Diagonal(_CornerId.topLeft, _CornerId.bottomRight), + _Diagonal(_CornerId.bottomRight, _CornerId.topLeft), + _Diagonal(_CornerId.topRight, _CornerId.bottomLeft), + _Diagonal(_CornerId.bottomLeft, _CornerId.topRight), +]; + +typedef _KeyFunc<T> = double Function(T input); + +// Select the element for which the key function returns the maximum value. +T _maxBy<T>(Iterable<T> input, _KeyFunc<T> keyFunc) { + late T maxValue; + double? maxKey; + for (final T value in input) { + final double key = keyFunc(value); + if (maxKey == null || key > maxKey) { + maxValue = value; + maxKey = key; + } + } + return maxValue; +} + +/// A [Tween] that interpolates a [Rect] by having its opposite corners follow +/// circular arcs. +/// +/// This class specializes the interpolation of [Tween<Rect>] so that instead of +/// growing or shrinking linearly, opposite corners of the rectangle follow arcs +/// in a manner consistent with Material Design principles. +/// +/// Specifically, the rectangle corners whose diagonals are closest to the overall +/// direction of the animation follow arcs defined with [MaterialPointArcTween]. +/// +/// See also: +/// +/// * [MaterialRectCenterArcTween], which interpolates a rect along a circular +/// arc between the begin and end [Rect]'s centers. +/// * [Tween], for a discussion on how to use interpolation objects. +/// * [MaterialPointArcTween], the analog for [Offset] interpolation. +/// * [RectTween], which does a linear rectangle interpolation. +/// * [Hero.createRectTween], which can be used to specify the tween that defines +/// a hero's path. +class MaterialRectArcTween extends RectTween { + /// Creates a [Tween] for animating [Rect]s along a circular arc. + /// + /// The [begin] and [end] properties must be non-null before the tween is + /// first used, but the arguments can be null if the values are going to be + /// filled in later. + MaterialRectArcTween({ + super.begin, + super.end, + }); + + bool _dirty = true; + + void _initialize() { + assert(begin != null); + assert(end != null); + final Offset centersVector = end!.center - begin!.center; + final _Diagonal diagonal = _maxBy<_Diagonal>(_allDiagonals, (_Diagonal d) => _diagonalSupport(centersVector, d)); + _beginArc = MaterialPointArcTween( + begin: _cornerFor(begin!, diagonal.beginId), + end: _cornerFor(end!, diagonal.beginId), + ); + _endArc = MaterialPointArcTween( + begin: _cornerFor(begin!, diagonal.endId), + end: _cornerFor(end!, diagonal.endId), + ); + _dirty = false; + } + + double _diagonalSupport(Offset centersVector, _Diagonal diagonal) { + final Offset delta = _cornerFor(begin!, diagonal.endId) - _cornerFor(begin!, diagonal.beginId); + final double length = delta.distance; + return centersVector.dx * delta.dx / length + centersVector.dy * delta.dy / length; + } + + Offset _cornerFor(Rect rect, _CornerId id) { + switch (id) { + case _CornerId.topLeft: return rect.topLeft; + case _CornerId.topRight: return rect.topRight; + case _CornerId.bottomLeft: return rect.bottomLeft; + case _CornerId.bottomRight: return rect.bottomRight; + } + } + + /// The path of the corresponding [begin], [end] rectangle corners that lead + /// the animation. + MaterialPointArcTween? get beginArc { + if (begin == null) { + return null; + } + if (_dirty) { + _initialize(); + } + return _beginArc; + } + late MaterialPointArcTween _beginArc; + + /// The path of the corresponding [begin], [end] rectangle corners that trail + /// the animation. + MaterialPointArcTween? get endArc { + if (end == null) { + return null; + } + if (_dirty) { + _initialize(); + } + return _endArc; + } + late MaterialPointArcTween _endArc; + + @override + set begin(Rect? value) { + if (value != begin) { + super.begin = value; + _dirty = true; + } + } + + @override + set end(Rect? value) { + if (value != end) { + super.end = value; + _dirty = true; + } + } + + @override + Rect lerp(double t) { + if (_dirty) { + _initialize(); + } + if (t == 0.0) { + return begin!; + } + if (t == 1.0) { + return end!; + } + return Rect.fromPoints(_beginArc.lerp(t), _endArc.lerp(t)); + } + + @override + String toString() { + return '${objectRuntimeType(this, 'MaterialRectArcTween')}($begin \u2192 $end; beginArc=$beginArc, endArc=$endArc)'; + } +} + +/// A [Tween] that interpolates a [Rect] by moving it along a circular arc from +/// [begin]'s [Rect.center] to [end]'s [Rect.center] while interpolating the +/// rectangle's width and height. +/// +/// The arc that defines that center of the interpolated rectangle as it morphs +/// from [begin] to [end] is a [MaterialPointArcTween]. +/// +/// See also: +/// +/// * [MaterialRectArcTween], A [Tween] that interpolates a [Rect] by having +/// its opposite corners follow circular arcs. +/// * [Tween], for a discussion on how to use interpolation objects. +/// * [MaterialPointArcTween], the analog for [Offset] interpolation. +/// * [RectTween], which does a linear rectangle interpolation. +/// * [Hero.createRectTween], which can be used to specify the tween that defines +/// a hero's path. +class MaterialRectCenterArcTween extends RectTween { + /// Creates a [Tween] for animating [Rect]s along a circular arc. + /// + /// The [begin] and [end] properties must be non-null before the tween is + /// first used, but the arguments can be null if the values are going to be + /// filled in later. + MaterialRectCenterArcTween({ + super.begin, + super.end, + }); + + bool _dirty = true; + + void _initialize() { + assert(begin != null); + assert(end != null); + _centerArc = MaterialPointArcTween( + begin: begin!.center, + end: end!.center, + ); + _dirty = false; + } + + /// If [begin] and [end] are non-null, returns a tween that interpolates along + /// a circular arc between [begin]'s [Rect.center] and [end]'s [Rect.center]. + MaterialPointArcTween? get centerArc { + if (begin == null || end == null) { + return null; + } + if (_dirty) { + _initialize(); + } + return _centerArc; + } + late MaterialPointArcTween _centerArc; + + @override + set begin(Rect? value) { + if (value != begin) { + super.begin = value; + _dirty = true; + } + } + + @override + set end(Rect? value) { + if (value != end) { + super.end = value; + _dirty = true; + } + } + + @override + Rect lerp(double t) { + if (_dirty) { + _initialize(); + } + if (t == 0.0) { + return begin!; + } + if (t == 1.0) { + return end!; + } + final Offset center = _centerArc.lerp(t); + final double width = lerpDouble(begin!.width, end!.width, t)!; + final double height = lerpDouble(begin!.height, end!.height, t)!; + return Rect.fromLTWH(center.dx - width / 2.0, center.dy - height / 2.0, width, height); + } + + @override + String toString() { + return '${objectRuntimeType(this, 'MaterialRectCenterArcTween')}($begin \u2192 $end; centerArc=$centerArc)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/autocomplete.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/autocomplete.dart new file mode 100644 index 0000000000000000000000000000000000000000..aea1276e0bb4066e912065facb8c26be6d61c49f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/autocomplete.dart @@ -0,0 +1,220 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/scheduler.dart'; +import 'package:flutter/widgets.dart'; + +import 'ink_well.dart'; +import 'material.dart'; +import 'text_form_field.dart'; +import 'theme.dart'; + +/// {@macro flutter.widgets.RawAutocomplete.RawAutocomplete} +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=-Nny8kzW380} +/// +/// {@tool dartpad} +/// This example shows how to create a very basic Autocomplete widget using the +/// default UI. +/// +/// ** See code in examples/api/lib/material/autocomplete/autocomplete.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to create an Autocomplete widget with a custom type. +/// Try searching with text from the name or email field. +/// +/// ** See code in examples/api/lib/material/autocomplete/autocomplete.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to create an Autocomplete widget whose options are +/// fetched over the network. +/// +/// ** See code in examples/api/lib/material/autocomplete/autocomplete.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to create an Autocomplete widget whose options are +/// fetched over the network. It uses debouncing to wait to perform the network +/// request until after the user finishes typing. +/// +/// ** See code in examples/api/lib/material/autocomplete/autocomplete.3.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to create an Autocomplete widget whose options are +/// fetched over the network. It includes both debouncing and error handling, so +/// that failed network requests show an error to the user and can be recovered +/// from. Try toggling the network Switch widget to simulate going offline. +/// +/// ** See code in examples/api/lib/material/autocomplete/autocomplete.4.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [RawAutocomplete], which is what Autocomplete is built upon, and which +/// contains more detailed examples. +class Autocomplete<T extends Object> extends StatelessWidget { + /// Creates an instance of [Autocomplete]. + const Autocomplete({ + super.key, + required this.optionsBuilder, + this.displayStringForOption = RawAutocomplete.defaultStringForOption, + this.fieldViewBuilder = _defaultFieldViewBuilder, + this.onSelected, + this.optionsMaxHeight = 200.0, + this.optionsViewBuilder, + this.optionsViewOpenDirection = OptionsViewOpenDirection.down, + this.initialValue, + }); + + /// {@macro flutter.widgets.RawAutocomplete.displayStringForOption} + final AutocompleteOptionToString<T> displayStringForOption; + + /// {@macro flutter.widgets.RawAutocomplete.fieldViewBuilder} + /// + /// If not provided, will build a standard Material-style text field by + /// default. + final AutocompleteFieldViewBuilder fieldViewBuilder; + + /// {@macro flutter.widgets.RawAutocomplete.onSelected} + final AutocompleteOnSelected<T>? onSelected; + + /// {@macro flutter.widgets.RawAutocomplete.optionsBuilder} + final AutocompleteOptionsBuilder<T> optionsBuilder; + + /// {@macro flutter.widgets.RawAutocomplete.optionsViewBuilder} + /// + /// If not provided, will build a standard Material-style list of results by + /// default. + final AutocompleteOptionsViewBuilder<T>? optionsViewBuilder; + + /// {@macro flutter.widgets.RawAutocomplete.optionsViewOpenDirection} + final OptionsViewOpenDirection optionsViewOpenDirection; + + /// The maximum height used for the default Material options list widget. + /// + /// When [optionsViewBuilder] is `null`, this property sets the maximum height + /// that the options widget can occupy. + /// + /// The default value is set to 200. + final double optionsMaxHeight; + + /// {@macro flutter.widgets.RawAutocomplete.initialValue} + final TextEditingValue? initialValue; + + static Widget _defaultFieldViewBuilder(BuildContext context, TextEditingController textEditingController, FocusNode focusNode, VoidCallback onFieldSubmitted) { + return _AutocompleteField( + focusNode: focusNode, + textEditingController: textEditingController, + onFieldSubmitted: onFieldSubmitted, + ); + } + + @override + Widget build(BuildContext context) { + return RawAutocomplete<T>( + displayStringForOption: displayStringForOption, + fieldViewBuilder: fieldViewBuilder, + initialValue: initialValue, + optionsBuilder: optionsBuilder, + optionsViewOpenDirection: optionsViewOpenDirection, + optionsViewBuilder: optionsViewBuilder ?? (BuildContext context, AutocompleteOnSelected<T> onSelected, Iterable<T> options) { + return _AutocompleteOptions<T>( + displayStringForOption: displayStringForOption, + onSelected: onSelected, + options: options, + maxOptionsHeight: optionsMaxHeight, + ); + }, + onSelected: onSelected, + ); + } +} + +// The default Material-style Autocomplete text field. +class _AutocompleteField extends StatelessWidget { + const _AutocompleteField({ + required this.focusNode, + required this.textEditingController, + required this.onFieldSubmitted, + }); + + final FocusNode focusNode; + + final VoidCallback onFieldSubmitted; + + final TextEditingController textEditingController; + + @override + Widget build(BuildContext context) { + return TextFormField( + controller: textEditingController, + focusNode: focusNode, + onFieldSubmitted: (String value) { + onFieldSubmitted(); + }, + ); + } +} + +// The default Material-style Autocomplete options. +class _AutocompleteOptions<T extends Object> extends StatelessWidget { + const _AutocompleteOptions({ + super.key, + required this.displayStringForOption, + required this.onSelected, + required this.options, + required this.maxOptionsHeight, + }); + + final AutocompleteOptionToString<T> displayStringForOption; + + final AutocompleteOnSelected<T> onSelected; + + final Iterable<T> options; + final double maxOptionsHeight; + + @override + Widget build(BuildContext context) { + return Align( + alignment: Alignment.topLeft, + child: Material( + elevation: 4.0, + child: ConstrainedBox( + constraints: BoxConstraints(maxHeight: maxOptionsHeight), + child: ListView.builder( + padding: EdgeInsets.zero, + shrinkWrap: true, + itemCount: options.length, + itemBuilder: (BuildContext context, int index) { + final T option = options.elementAt(index); + return InkWell( + onTap: () { + onSelected(option); + }, + child: Builder( + builder: (BuildContext context) { + final bool highlight = AutocompleteHighlightedOption.of(context) == index; + if (highlight) { + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + Scrollable.ensureVisible(context, alignment: 0.5); + }, debugLabel: 'AutocompleteOptions.ensureVisible'); + } + return Container( + color: highlight ? Theme.of(context).focusColor : null, + padding: const EdgeInsets.all(16.0), + child: Text(displayStringForOption(option)), + ); + } + ), + ); + }, + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/back_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/back_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..95f4b97216e0a3d2e060769fe55b3608d6384c72 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/back_button.dart @@ -0,0 +1,5 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'action_buttons.dart' show BackButton, BackButtonIcon, CloseButton, CloseButtonIcon; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/badge.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/badge.dart new file mode 100644 index 0000000000000000000000000000000000000000..aa2ec80a4489b301313d4f46f4c2ca0dde7f6d2a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/badge.dart @@ -0,0 +1,312 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'badge_theme.dart'; +import 'color_scheme.dart'; +import 'theme.dart'; + +/// A Material Design "badge". +/// +/// A badge's [label] conveys a small amount of information about its +/// [child], like a count or status. If the label is null then this is +/// a "small" badge that's displayed as a [smallSize] diameter filled +/// circle. Otherwise this is a [StadiumBorder] shaped "large" badge +/// with height [largeSize]. +/// +/// Badges are typically used to decorate the icon within a +/// BottomNavigationBarItem] or a [NavigationRailDestination] +/// or a button's icon, as in [TextButton.icon]. The badge's default +/// configuration is intended to work well with a default sized (24) +/// [Icon]. +class Badge extends StatelessWidget { + /// Create a Badge that stacks [label] on top of [child]. + /// + /// If [label] is null then just a filled circle is displayed. Otherwise + /// the [label] is displayed within a [StadiumBorder] shaped area. + const Badge({ + super.key, + this.backgroundColor, + this.textColor, + this.smallSize, + this.largeSize, + this.textStyle, + this.padding, + this.alignment, + this.offset, + this.label, + this.isLabelVisible = true, + this.child, + }); + + /// Convenience constructor for creating a badge with a numeric + /// label with 1-3 digits based on [count]. + /// + /// Initializes [label] with a [Text] widget that contains [count]. + /// If [count] is greater than 999, then the label is '999+'. + Badge.count({ + super.key, + this.backgroundColor, + this.textColor, + this.smallSize, + this.largeSize, + this.textStyle, + this.padding, + this.alignment, + this.offset, + required int count, + this.isLabelVisible = true, + this.child, + }) : label = Text(count > 999 ? '999+' : '$count'); + + /// The badge's fill color. + /// + /// Defaults to the [BadgeTheme]'s background color, or + /// [ColorScheme.errorColor] if the theme value is null. + final Color? backgroundColor; + + /// The color of the badge's [label] text. + /// + /// This color overrides the color of the label's [textStyle]. + /// + /// Defaults to the [BadgeTheme]'s foreground color, or + /// [ColorScheme.onError] if the theme value is null. + final Color? textColor; + + /// The diameter of the badge if [label] is null. + /// + /// Defaults to the [BadgeTheme]'s small size, or 6 if the theme value + /// is null. + final double? smallSize; + + /// The badge's height if [label] is non-null. + /// + /// Defaults to the [BadgeTheme]'s large size, or 16 if the theme value + /// is null. If the default value is overridden then it may be useful to + /// also override [padding] and [alignment]. + final double? largeSize; + + /// The [DefaultTextStyle] for the badge's label. + /// + /// The text style's color is overwritten by the [textColor]. + /// + /// This value is only used if [label] is non-null. + /// + /// Defaults to the [BadgeTheme]'s text style, or the overall theme's + /// [TextTheme.labelSmall] if the badge theme's value is null. If + /// the default text style is overridden then it may be useful to + /// also override [largeSize], [padding], and [alignment]. + final TextStyle? textStyle; + + /// The padding added to the badge's label. + /// + /// This value is only used if [label] is non-null. + /// + /// Defaults to the [BadgeTheme]'s padding, or 4 pixels on the + /// left and right if the theme's value is null. + final EdgeInsetsGeometry? padding; + + /// Combined with [offset] to determine the location of the [label] + /// relative to the [child]. + /// + /// The alignment positions the label in the same way a child of an + /// [Align] widget is positioned, except that, the alignment is + /// resolved as if the label was a [largeSize] square and [offset] + /// is added to the result. + /// + /// This value is only used if [label] is non-null. + /// + /// Defaults to the [BadgeTheme]'s alignment, or + /// [AlignmentDirectional.topEnd] if the theme's value is null. + final AlignmentGeometry? alignment; + + /// Combined with [alignment] to determine the location of the [label] + /// relative to the [child]. + /// + /// This value is only used if [label] is non-null. + /// + /// Defaults to the [BadgeTheme]'s offset, or + /// if the theme's value is null then `Offset(4, -4)` for + /// [TextDirection.ltr] or `Offset(-4, -4)` for [TextDirection.rtl]. + final Offset? offset; + + /// The badge's content, typically a [Text] widget that contains 1 to 4 + /// characters. + /// + /// If the label is null then this is a "small" badge that's + /// displayed as a [smallSize] diameter filled circle. Otherwise + /// this is a [StadiumBorder] shaped "large" badge with height [largeSize]. + final Widget? label; + + /// If false, the badge's [label] is not included. + /// + /// This flag is true by default. It's intended to make it convenient + /// to create a badge that's only shown under certain conditions. + final bool isLabelVisible; + + /// The widget that the badge is stacked on top of. + /// + /// Typically this is an default sized [Icon] that's part of a + /// [BottomNavigationBarItem] or a [NavigationRailDestination]. + final Widget? child; + + @override + Widget build(BuildContext context) { + if (!isLabelVisible) { + return child ?? const SizedBox(); + } + + final BadgeThemeData badgeTheme = BadgeTheme.of(context); + final BadgeThemeData defaults = _BadgeDefaultsM3(context); + final double effectiveSmallSize = smallSize ?? badgeTheme.smallSize ?? defaults.smallSize!; + final double effectiveLargeSize = largeSize ?? badgeTheme.largeSize ?? defaults.largeSize!; + + final Widget badge = DefaultTextStyle( + style: (textStyle ?? badgeTheme.textStyle ?? defaults.textStyle!).copyWith( + color: textColor ?? badgeTheme.textColor ?? defaults.textColor!, + ), + child: IntrinsicWidth( + child: Container( + height: label == null ? effectiveSmallSize : effectiveLargeSize, + clipBehavior: Clip.antiAlias, + decoration: ShapeDecoration( + color: backgroundColor ?? badgeTheme.backgroundColor ?? defaults.backgroundColor!, + shape: const StadiumBorder(), + ), + padding: label == null ? null : (padding ?? badgeTheme.padding ?? defaults.padding!), + alignment: label == null ? null : Alignment.center, + child: label ?? SizedBox(width: effectiveSmallSize, height: effectiveSmallSize), + ), + ), + ); + + if (child == null) { + return badge; + } + + final AlignmentGeometry effectiveAlignment = alignment ?? badgeTheme.alignment ?? defaults.alignment!; + final TextDirection textDirection = Directionality.of(context); + final Offset defaultOffset = textDirection == TextDirection.ltr ? const Offset(4, -4) : const Offset(-4, -4); + final Offset effectiveOffset = offset ?? badgeTheme.offset ?? defaultOffset; + + return + Stack( + clipBehavior: Clip.none, + children: <Widget>[ + child!, + Positioned.fill( + child: _Badge( + alignment: effectiveAlignment, + offset: label == null ? Offset.zero : effectiveOffset, + textDirection: textDirection, + child: badge, + ), + ), + ], + ); + } +} + +class _Badge extends SingleChildRenderObjectWidget { + const _Badge({ + required this.alignment, + required this.offset, + required this.textDirection, + super.child, // the badge + }); + + final AlignmentGeometry alignment; + final Offset offset; + final TextDirection textDirection; + + @override + _RenderBadge createRenderObject(BuildContext context) { + return _RenderBadge( + alignment: alignment, + offset: offset, + textDirection: Directionality.maybeOf(context), + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderBadge renderObject) { + renderObject + ..alignment = alignment + ..offset = offset + ..textDirection = Directionality.maybeOf(context); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(DiagnosticsProperty<Offset>('offset', offset)); + } +} + +class _RenderBadge extends RenderAligningShiftedBox { + _RenderBadge({ + super.textDirection, + super.alignment, + required Offset offset, + }) : _offset = offset; + + Offset get offset => _offset; + Offset _offset; + set offset(Offset value) { + if (_offset == value) { + return; + } + _offset = value; + markNeedsLayout(); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + assert(constraints.hasBoundedWidth); + assert(constraints.hasBoundedHeight); + size = constraints.biggest; + + child!.layout(const BoxConstraints(), parentUsesSize: true); + final double badgeSize = child!.size.height; + final Alignment resolvedAlignment = alignment.resolve(textDirection); + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = offset + resolvedAlignment.alongOffset(Offset(size.width - badgeSize, size.height - badgeSize)); + } +} + + +// BEGIN GENERATED TOKEN PROPERTIES - Badge + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _BadgeDefaultsM3 extends BadgeThemeData { + _BadgeDefaultsM3(this.context) : super( + smallSize: 6.0, + largeSize: 16.0, + padding: const EdgeInsets.symmetric(horizontal: 4), + alignment: AlignmentDirectional.topEnd, + ); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + + @override + Color? get backgroundColor => _colors.error; + + @override + Color? get textColor => _colors.onError; + + @override + TextStyle? get textStyle => Theme.of(context).textTheme.labelSmall; +} + +// END GENERATED TOKEN PROPERTIES - Badge diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/badge_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/badge_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..385d4f8ce4b7dabe484a1082d0706eecfa0271cd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/badge_theme.dart @@ -0,0 +1,196 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + + +// Examples can assume: +// late BuildContext context; + +/// Overrides the default properties values for descendant [Badge] widgets. +/// +/// Descendant widgets obtain the current [BadgeThemeData] object +/// using `BadgeTheme.of(context)`. Instances of [BadgeThemeData] can +/// be customized with [BadgeThemeData.copyWith]. +/// +/// Typically a [BadgeThemeData] is specified as part of the +/// overall [Theme] with [ThemeData.badgeTheme]. +/// +/// All [BadgeThemeData] properties are `null` by default. +/// When null, the [Badge] will use the values from [ThemeData] +/// if they exist, otherwise it will provide its own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class BadgeThemeData with Diagnosticable { + /// Creates the set of color, style, and size properties used to configure [Badge]. + const BadgeThemeData({ + this.backgroundColor, + this.textColor, + this.smallSize, + this.largeSize, + this.textStyle, + this.padding, + this.alignment, + this.offset, + }); + + /// Overrides the default value for [Badge.backgroundColor]. + final Color? backgroundColor; + + /// Overrides the default value for [Badge.textColor]. + final Color? textColor; + + /// Overrides the default value for [Badge.smallSize]. + final double? smallSize; + + /// Overrides the default value for [Badge.largeSize]. + final double? largeSize; + + /// Overrides the default value for [Badge.textStyle]. + final TextStyle? textStyle; + + /// Overrides the default value for [Badge.padding]. + final EdgeInsetsGeometry? padding; + + /// Overrides the default value for [Badge.alignment]. + final AlignmentGeometry? alignment; + + /// Overrides the default value for [Badge.offset]. + final Offset? offset; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + BadgeThemeData copyWith({ + Color? backgroundColor, + Color? textColor, + double? smallSize, + double? largeSize, + TextStyle? textStyle, + EdgeInsetsGeometry? padding, + AlignmentGeometry? alignment, + Offset? offset, + }) { + return BadgeThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + textColor: textColor ?? this.textColor, + smallSize: smallSize ?? this.smallSize, + largeSize: largeSize ?? this.largeSize, + textStyle: textStyle ?? this.textStyle, + padding: padding ?? this.padding, + alignment: alignment ?? this.alignment, + offset: offset ?? this.offset, + ); + } + + /// Linearly interpolate between two [Badge] themes. + static BadgeThemeData lerp(BadgeThemeData? a, BadgeThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return BadgeThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + textColor: Color.lerp(a?.textColor, b?.textColor, t), + smallSize: lerpDouble(a?.smallSize, b?.smallSize, t), + largeSize: lerpDouble(a?.largeSize, b?.largeSize, t), + textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t), + padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t), + alignment: AlignmentGeometry.lerp(a?.alignment, b?.alignment, t), + offset: Offset.lerp(a?.offset, b?.offset, t), + ); + } + + @override + int get hashCode => Object.hash( + backgroundColor, + textColor, + smallSize, + largeSize, + textStyle, + padding, + alignment, + offset, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is BadgeThemeData + && other.backgroundColor == backgroundColor + && other.textColor == textColor + && other.smallSize == smallSize + && other.largeSize == largeSize + && other.textStyle == textStyle + && other.padding == padding + && other.alignment == alignment + && other.offset == offset; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(ColorProperty('textColor', textColor, defaultValue: null)); + properties.add(DoubleProperty('smallSize', smallSize, defaultValue: null)); + properties.add(DoubleProperty('largeSize', largeSize, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('textStyle', textStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: null)); + properties.add(DiagnosticsProperty<Offset>('offset', offset, defaultValue: null)); + } +} + +/// An inherited widget that overrides the default color style, and size +/// parameters for [Badge]s in this widget's subtree. +/// +/// Values specified here override the defaults for [Badge] properties which +/// are not given an explicit non-null value. +class BadgeTheme extends InheritedTheme { + /// Creates a theme that overrides the default color parameters for [Badge]s + /// in this widget's subtree. + const BadgeTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the default color and size overrides for descendant [Badge] widgets. + final BadgeThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [BadgeTheme] widget, then + /// [ThemeData.badgeTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// BadgeThemeData theme = BadgeTheme.of(context); + /// ``` + static BadgeThemeData of(BuildContext context) { + final BadgeTheme? badgeTheme = context.dependOnInheritedWidgetOfExactType<BadgeTheme>(); + return badgeTheme?.data ?? Theme.of(context).badgeTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return BadgeTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(BadgeTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/banner.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/banner.dart new file mode 100644 index 0000000000000000000000000000000000000000..3573a10863291db7f14c8de74d7a68b503ba81f3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/banner.dart @@ -0,0 +1,487 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'banner_theme.dart'; +import 'color_scheme.dart'; +import 'divider.dart'; +import 'material.dart'; +import 'scaffold.dart'; +import 'text_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +const Duration _materialBannerTransitionDuration = Duration(milliseconds: 250); +const Curve _materialBannerHeightCurve = Curves.fastOutSlowIn; + +/// Specify how a [MaterialBanner] was closed. +/// +/// The [ScaffoldMessengerState.showMaterialBanner] function returns a +/// [ScaffoldFeatureController]. The value of the controller's closed property +/// is a Future that resolves to a MaterialBannerClosedReason. Applications that need +/// to know how a [MaterialBanner] was closed can use this value. +/// +/// Example: +/// +/// ```dart +/// ScaffoldMessenger.of(context).showMaterialBanner( +/// const MaterialBanner( +/// content: Text('Message...'), +/// actions: <Widget>[ +/// // ... +/// ], +/// ) +/// ).closed.then((MaterialBannerClosedReason reason) { +/// // ... +/// }); +/// ``` +enum MaterialBannerClosedReason { + /// The material banner was closed through a [SemanticsAction.dismiss]. + dismiss, + + /// The material banner was closed by a user's swipe. + swipe, + + /// The material banner was closed by the [ScaffoldFeatureController] close callback + /// or by calling [ScaffoldMessengerState.hideCurrentMaterialBanner] directly. + hide, + + /// The material banner was closed by a call to [ScaffoldMessengerState.removeCurrentMaterialBanner]. + remove, +} + +/// A Material Design banner. +/// +/// A banner displays an important, succinct message, and provides actions for +/// users to address (or dismiss the banner). A user action is required for it +/// to be dismissed. +/// +/// Banners should be displayed at the top of the screen, below a top app bar. +/// They are persistent and non-modal, allowing the user to either ignore them or +/// interact with them at any time. +/// +/// {@tool dartpad} +/// Banners placed directly into the widget tree are static. +/// +/// ** See code in examples/api/lib/material/banner/material_banner.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// MaterialBanner's can also be presented through a [ScaffoldMessenger]. +/// Here is an example where ScaffoldMessengerState.showMaterialBanner() is used to show the MaterialBanner. +/// +/// ** See code in examples/api/lib/material/banner/material_banner.1.dart ** +/// {@end-tool} +/// +/// The [actions] will be placed beside the [content] if there is only one. +/// Otherwise, the [actions] will be placed below the [content]. Use +/// [forceActionsBelow] to override this behavior. +/// +/// If the [actions] placed below the [content], they will be laid out in a row. +/// If there isn't sufficient room to display everything, they are laid out +/// in a column instead. +/// +/// The [actions] and [content] must be provided. An optional leading widget +/// (typically an [Image]) can also be provided. The [contentTextStyle] and +/// [backgroundColor] can be provided to customize the banner. +/// +/// This widget is unrelated to the widgets library [Banner] widget. +class MaterialBanner extends StatefulWidget { + /// Creates a [MaterialBanner]. + /// + /// The length of the [actions] list must not be empty. The [elevation] must + /// be null or non-negative. + const MaterialBanner({ + super.key, + required this.content, + this.contentTextStyle, + required this.actions, + this.elevation, + this.leading, + this.backgroundColor, + this.surfaceTintColor, + this.shadowColor, + this.dividerColor, + this.padding, + this.margin, + this.leadingPadding, + this.forceActionsBelow = false, + this.overflowAlignment = OverflowBarAlignment.end, + this.animation, + this.onVisible, + }) : assert(elevation == null || elevation >= 0.0); + + /// The content of the [MaterialBanner]. + /// + /// Typically a [Text] widget. + final Widget content; + + /// Style for the text in the [content] of the [MaterialBanner]. + /// + /// If `null`, [MaterialBannerThemeData.contentTextStyle] is used. If that is + /// also `null`, [TextTheme.bodyMedium] of [ThemeData.textTheme] is used. + final TextStyle? contentTextStyle; + + /// The set of actions that are displayed at the bottom or trailing side of + /// the [MaterialBanner]. + /// + /// Typically this is a list of [TextButton] widgets. + final List<Widget> actions; + + /// The z-coordinate at which to place the material banner. + /// + /// This controls the size of the shadow below the material banner. + /// + /// Defines the banner's [Material.elevation]. + /// + /// If this property is null, then [MaterialBannerThemeData.elevation] of + /// [ThemeData.bannerTheme] is used, if that is also null, the default value is 0. + /// If the elevation is 0, the [Scaffold]'s body will be pushed down by the + /// MaterialBanner when used with [ScaffoldMessenger]. + final double? elevation; + + /// The (optional) leading widget of the [MaterialBanner]. + /// + /// Typically an [Icon] widget. + final Widget? leading; + + /// The color of the surface of this [MaterialBanner]. + /// + /// If `null`, [MaterialBannerThemeData.backgroundColor] is used. If that is + /// also `null`, [ColorScheme.surface] of [ThemeData.colorScheme] is used. + final Color? backgroundColor; + + /// The color used as an overlay on [backgroundColor] to indicate elevation. + /// + /// If null, [MaterialBannerThemeData.surfaceTintColor] is used. If that + /// is also null, the default value is [ColorScheme.surfaceTint]. + /// + /// See [Material.surfaceTintColor] for more details on how this + /// overlay is applied. + final Color? surfaceTintColor; + + /// The color of the shadow below the [MaterialBanner]. + /// + /// If this property is null, then [MaterialBannerThemeData.shadowColor] of + /// [ThemeData.bannerTheme] is used. If that is also null, the default value + /// is null. + final Color? shadowColor; + + /// The color of the divider. + /// + /// If this property is null, then [MaterialBannerThemeData.dividerColor] of + /// [ThemeData.bannerTheme] is used. If that is also null, the default value + /// is [ColorScheme.surfaceVariant]. + final Color? dividerColor; + + /// The amount of space by which to inset the [content]. + /// + /// If the [actions] are below the [content], this defaults to + /// `EdgeInsetsDirectional.only(start: 16.0, top: 24.0, end: 16.0, bottom: 4.0)`. + /// + /// If the [actions] are trailing the [content], this defaults to + /// `EdgeInsetsDirectional.only(start: 16.0, top: 2.0)`. + final EdgeInsetsGeometry? padding; + + /// Empty space to surround the [MaterialBanner]. + /// + /// If the [margin] is null then this defaults to + /// 0 if the banner's [elevation] is 0, 10 otherwise. + final EdgeInsetsGeometry? margin; + + /// The amount of space by which to inset the [leading] widget. + /// + /// This defaults to `EdgeInsetsDirectional.only(end: 16.0)`. + final EdgeInsetsGeometry? leadingPadding; + + /// An override to force the [actions] to be below the [content] regardless of + /// how many there are. + /// + /// If this is true, the [actions] will be placed below the [content]. If + /// this is false, the [actions] will be placed on the trailing side of the + /// [content] if [actions]'s length is 1 and below the [content] if greater + /// than 1. + /// + /// Defaults to false. + final bool forceActionsBelow; + + /// The horizontal alignment of the [actions] when the [actions] laid out in a column. + /// + /// Defaults to [OverflowBarAlignment.end]. + final OverflowBarAlignment overflowAlignment; + + /// The animation driving the entrance and exit of the material banner when presented by the [ScaffoldMessenger]. + final Animation<double>? animation; + + /// Called the first time that the material banner is visible within a [Scaffold] when presented by the [ScaffoldMessenger]. + final VoidCallback? onVisible; + + // API for ScaffoldMessengerState.showMaterialBanner(): + + /// Creates an animation controller useful for driving a [MaterialBanner]'s entrance and exit animation. + static AnimationController createAnimationController({ required TickerProvider vsync }) { + return AnimationController( + duration: _materialBannerTransitionDuration, + debugLabel: 'MaterialBanner', + vsync: vsync, + ); + } + + /// Creates a copy of this material banner but with the animation replaced with the given animation. + /// + /// If the original material banner lacks a key, the newly created material banner will + /// use the given fallback key. + MaterialBanner withAnimation(Animation<double> newAnimation, { Key? fallbackKey }) { + return MaterialBanner( + key: key ?? fallbackKey, + content: content, + contentTextStyle: contentTextStyle, + actions: actions, + elevation: elevation, + leading: leading, + backgroundColor: backgroundColor, + surfaceTintColor: surfaceTintColor, + shadowColor: shadowColor, + dividerColor: dividerColor, + padding: padding, + margin: margin, + leadingPadding: leadingPadding, + forceActionsBelow: forceActionsBelow, + overflowAlignment: overflowAlignment, + animation: newAnimation, + onVisible: onVisible, + ); + } + + @override + State<MaterialBanner> createState() => _MaterialBannerState(); +} + +class _MaterialBannerState extends State<MaterialBanner> { + bool _wasVisible = false; + + @override + void initState() { + super.initState(); + widget.animation?.addStatusListener(_onAnimationStatusChanged); + } + + @override + void didUpdateWidget(MaterialBanner oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.animation != oldWidget.animation) { + oldWidget.animation?.removeStatusListener(_onAnimationStatusChanged); + widget.animation?.addStatusListener(_onAnimationStatusChanged); + } + } + + @override + void dispose() { + widget.animation?.removeStatusListener(_onAnimationStatusChanged); + super.dispose(); + } + + void _onAnimationStatusChanged(AnimationStatus animationStatus) { + switch (animationStatus) { + case AnimationStatus.dismissed: + case AnimationStatus.forward: + case AnimationStatus.reverse: + break; + case AnimationStatus.completed: + if (widget.onVisible != null && !_wasVisible) { + widget.onVisible!(); + } + _wasVisible = true; + } + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final bool accessibleNavigation = MediaQuery.accessibleNavigationOf(context); + + assert(widget.actions.isNotEmpty); + + final ThemeData theme = Theme.of(context); + final MaterialBannerThemeData bannerTheme = MaterialBannerTheme.of(context); + final MaterialBannerThemeData defaults = theme.useMaterial3 ? _BannerDefaultsM3(context) : _BannerDefaultsM2(context); + + final bool isSingleRow = widget.actions.length == 1 && !widget.forceActionsBelow; + final EdgeInsetsGeometry padding = widget.padding ?? bannerTheme.padding ?? (isSingleRow + ? const EdgeInsetsDirectional.only(start: 16.0, top: 2.0) + : const EdgeInsetsDirectional.only(start: 16.0, top: 24.0, end: 16.0, bottom: 4.0)); + final EdgeInsetsGeometry leadingPadding = widget.leadingPadding + ?? bannerTheme.leadingPadding + ?? const EdgeInsetsDirectional.only(end: 16.0); + + final Widget actionsBar = Container( + alignment: AlignmentDirectional.centerEnd, + constraints: const BoxConstraints(minHeight: 52.0), + padding: const EdgeInsets.symmetric(horizontal: 8), + child: OverflowBar( + overflowAlignment: widget.overflowAlignment, + spacing: 8, + children: widget.actions, + ), + ); + + final double elevation = widget.elevation ?? bannerTheme.elevation ?? 0.0; + final EdgeInsetsGeometry margin = widget.margin ?? EdgeInsets.only(bottom: elevation > 0 ? 10.0 : 0.0); + final Color backgroundColor = widget.backgroundColor + ?? bannerTheme.backgroundColor + ?? defaults.backgroundColor!; + final Color? surfaceTintColor = widget.surfaceTintColor + ?? bannerTheme.surfaceTintColor + ?? defaults.surfaceTintColor; + final Color? shadowColor = widget.shadowColor + ?? bannerTheme.shadowColor; + final Color? dividerColor = widget.dividerColor + ?? bannerTheme.dividerColor + ?? defaults.dividerColor; + final TextStyle? textStyle = widget.contentTextStyle + ?? bannerTheme.contentTextStyle + ?? defaults.contentTextStyle; + + Widget materialBanner = Container( + margin: margin, + child: Material( + elevation: elevation, + color: backgroundColor, + surfaceTintColor: surfaceTintColor, + shadowColor: shadowColor, + child: Column( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + Padding( + padding: padding, + child: Row( + children: <Widget>[ + if (widget.leading != null) + Padding( + padding: leadingPadding, + child: widget.leading, + ), + Expanded( + child: DefaultTextStyle( + style: textStyle!, + child: widget.content, + ), + ), + if (isSingleRow) + actionsBar, + ], + ), + ), + if (!isSingleRow) + actionsBar, + if (elevation == 0) + Divider(height: 0, color: dividerColor), + ], + ), + ), + ); + + // This provides a static banner for backwards compatibility. + if (widget.animation == null) { + return materialBanner; + } + + materialBanner = SafeArea( + child: materialBanner, + ); + + final CurvedAnimation heightAnimation = CurvedAnimation(parent: widget.animation!, curve: _materialBannerHeightCurve); + final Animation<Offset> slideOutAnimation = Tween<Offset>( + begin: const Offset(0.0, -1.0), + end: Offset.zero, + ).animate(CurvedAnimation( + parent: widget.animation!, + curve: const Threshold(0.0), + )); + + materialBanner = Semantics( + container: true, + liveRegion: true, + onDismiss: () { + ScaffoldMessenger.of(context).removeCurrentMaterialBanner(reason: MaterialBannerClosedReason.dismiss); + }, + child: accessibleNavigation + ? materialBanner + : SlideTransition( + position: slideOutAnimation, + child: materialBanner, + ), + ); + + final Widget materialBannerTransition; + if (accessibleNavigation) { + materialBannerTransition = materialBanner; + } else { + materialBannerTransition = AnimatedBuilder( + animation: heightAnimation, + builder: (BuildContext context, Widget? child) { + return Align( + alignment: AlignmentDirectional.bottomStart, + heightFactor: heightAnimation.value, + child: child, + ); + }, + child: materialBanner, + ); + } + + return Hero( + tag: '<MaterialBanner Hero tag - ${widget.content}>', + child: ClipRect(child: materialBannerTransition), + ); + } +} + +class _BannerDefaultsM2 extends MaterialBannerThemeData { + _BannerDefaultsM2(this.context) + : _theme = Theme.of(context), + super(elevation: 0.0); + + final BuildContext context; + final ThemeData _theme; + + @override + Color? get backgroundColor => _theme.colorScheme.surface; + + @override + TextStyle? get contentTextStyle => _theme.textTheme.bodyMedium; +} + +// BEGIN GENERATED TOKEN PROPERTIES - Banner + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _BannerDefaultsM3 extends MaterialBannerThemeData { + _BannerDefaultsM3(this.context) + : super(elevation: 1.0); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + Color? get backgroundColor => _colors.surface; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + Color? get dividerColor => _colors.outlineVariant; + + @override + TextStyle? get contentTextStyle => _textTheme.bodyMedium; +} + +// END GENERATED TOKEN PROPERTIES - Banner diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/banner_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/banner_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..8792204ef8380afb180e6d53cfbaf912da7d6075 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/banner_theme.dart @@ -0,0 +1,199 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines the visual properties of [MaterialBanner] widgets. +/// +/// Descendant widgets obtain the current [MaterialBannerThemeData] object using +/// `MaterialBannerTheme.of(context)`. Instances of [MaterialBannerThemeData] +/// can be customized with [MaterialBannerThemeData.copyWith]. +/// +/// Typically a [MaterialBannerThemeData] is specified as part of the overall +/// [Theme] with [ThemeData.bannerTheme]. +/// +/// All [MaterialBannerThemeData] properties are `null` by default. When null, +/// the [MaterialBanner] will provide its own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class MaterialBannerThemeData with Diagnosticable { + + /// Creates a theme that can be used for [MaterialBannerTheme] or + /// [ThemeData.bannerTheme]. + const MaterialBannerThemeData({ + this.backgroundColor, + this.surfaceTintColor, + this.shadowColor, + this.dividerColor, + this.contentTextStyle, + this.elevation, + this.padding, + this.leadingPadding, + }); + + /// The background color of a [MaterialBanner]. + final Color? backgroundColor; + + /// Overrides the default value of [MaterialBanner.surfaceTintColor]. + final Color? surfaceTintColor; + + /// Overrides the default value of [MaterialBanner.shadowColor]. + final Color? shadowColor; + + /// Overrides the default value of [MaterialBanner.dividerColor]. + final Color? dividerColor; + + /// Used to configure the [DefaultTextStyle] for the [MaterialBanner.content] + /// widget. + final TextStyle? contentTextStyle; + + /// Default value for [MaterialBanner.elevation]. + // + // If null, MaterialBanner uses a default of 0.0. + final double? elevation; + + /// The amount of space by which to inset [MaterialBanner.content]. + final EdgeInsetsGeometry? padding; + + /// The amount of space by which to inset [MaterialBanner.leading]. + final EdgeInsetsGeometry? leadingPadding; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + MaterialBannerThemeData copyWith({ + Color? backgroundColor, + Color? surfaceTintColor, + Color? shadowColor, + Color? dividerColor, + TextStyle? contentTextStyle, + double? elevation, + EdgeInsetsGeometry? padding, + EdgeInsetsGeometry? leadingPadding, + }) { + return MaterialBannerThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + shadowColor: shadowColor ?? this.shadowColor, + dividerColor: dividerColor ?? this.dividerColor, + contentTextStyle: contentTextStyle ?? this.contentTextStyle, + elevation: elevation ?? this.elevation, + padding: padding ?? this.padding, + leadingPadding: leadingPadding ?? this.leadingPadding, + ); + } + + /// Linearly interpolate between two Banner themes. + /// + /// {@macro dart.ui.shadow.lerp} + static MaterialBannerThemeData lerp(MaterialBannerThemeData? a, MaterialBannerThemeData? b, double t) { + return MaterialBannerThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + dividerColor: Color.lerp(a?.dividerColor, b?.dividerColor, t), + contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t), + leadingPadding: EdgeInsetsGeometry.lerp(a?.leadingPadding, b?.leadingPadding, t), + ); + } + + @override + int get hashCode => Object.hash( + backgroundColor, + surfaceTintColor, + shadowColor, + dividerColor, + contentTextStyle, + elevation, + padding, + leadingPadding, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is MaterialBannerThemeData + && other.backgroundColor == backgroundColor + && other.surfaceTintColor == surfaceTintColor + && other.shadowColor == shadowColor + && other.dividerColor == dividerColor + && other.contentTextStyle == contentTextStyle + && other.elevation == elevation + && other.padding == padding + && other.leadingPadding == leadingPadding; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('dividerColor', dividerColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('contentTextStyle', contentTextStyle, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('leadingPadding', leadingPadding, defaultValue: null)); + } +} + +/// An inherited widget that defines the configuration for +/// [MaterialBanner]s in this widget's subtree. +/// +/// Values specified here are used for [MaterialBanner] properties that are not +/// given an explicit non-null value. +class MaterialBannerTheme extends InheritedTheme { + /// Creates a banner theme that controls the configurations for + /// [MaterialBanner]s in its widget subtree. + const MaterialBannerTheme({ + super.key, + this.data, + required super.child, + }); + + /// The properties for descendant [MaterialBanner] widgets. + final MaterialBannerThemeData? data; + + /// The closest instance of this class's [data] value that encloses the given + /// context. + /// + /// If there is no ancestor, it returns [ThemeData.bannerTheme]. Applications + /// can assume that the returned value will not be null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// MaterialBannerThemeData theme = MaterialBannerTheme.of(context); + /// ``` + static MaterialBannerThemeData of(BuildContext context) { + final MaterialBannerTheme? bannerTheme = context.dependOnInheritedWidgetOfExactType<MaterialBannerTheme>(); + return bannerTheme?.data ?? Theme.of(context).bannerTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return MaterialBannerTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(MaterialBannerTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_app_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_app_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..430c717e5c53f1dbebdf6f8e3280f85a2c404307 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_app_bar.dart @@ -0,0 +1,320 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'bottom_app_bar_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'elevation_overlay.dart'; +import 'material.dart'; +import 'scaffold.dart'; +import 'theme.dart'; + +// Examples can assume: +// late Widget bottomAppBarContents; + +/// A container that is typically used with [Scaffold.bottomNavigationBar]. +/// +/// Typically used with a [Scaffold] and a [FloatingActionButton]. +/// +/// {@tool snippet} +/// ```dart +/// Scaffold( +/// bottomNavigationBar: BottomAppBar( +/// color: Colors.white, +/// child: bottomAppBarContents, +/// ), +/// floatingActionButton: const FloatingActionButton(onPressed: null), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows the [BottomAppBar], which can be configured to have a notch using the +/// [BottomAppBar.shape] property. This also includes an optional [FloatingActionButton], which illustrates +/// the [FloatingActionButtonLocation]s in relation to the [BottomAppBar]. +/// +/// ** See code in examples/api/lib/material/bottom_app_bar/bottom_app_bar.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows Material 3 [BottomAppBar] with its expected look and behaviors. +/// +/// This also includes an optional [FloatingActionButton], which illustrates +/// the [FloatingActionButtonLocation.endContained]. +/// +/// ** See code in examples/api/lib/material/bottom_app_bar/bottom_app_bar.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [NotchedShape] which calculates the notch for a notched [BottomAppBar]. +/// * [FloatingActionButton] which the [BottomAppBar] makes a notch for. +/// * [AppBar] for a toolbar that is shown at the top of the screen. +class BottomAppBar extends StatefulWidget { + /// Creates a bottom application bar. + /// + /// The [clipBehavior] argument defaults to [Clip.none]. + /// Additionally, [elevation] must be non-negative. + /// + /// If [color], [elevation], or [shape] are null, their [BottomAppBarTheme] values will be used. + /// If the corresponding [BottomAppBarTheme] property is null, then the default + /// specified in the property's documentation will be used. + const BottomAppBar({ + super.key, + this.color, + this.elevation, + this.shape, + this.clipBehavior = Clip.none, + this.notchMargin = 4.0, + this.child, + this.padding, + this.surfaceTintColor, + this.shadowColor, + this.height, + }) : assert(elevation == null || elevation >= 0.0); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + /// + /// Typically the child will be a [Row] whose first child + /// is an [IconButton] with the [Icons.menu] icon. + final Widget? child; + + /// The amount of space to surround the child inside the bounds of the [BottomAppBar]. + /// + /// In Material 3 the padding will default to `EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0)` + /// Otherwise the value will default to EdgeInsets.zero. + final EdgeInsetsGeometry? padding; + + /// The bottom app bar's background color. + /// + /// If this property is null then [BottomAppBarTheme.color] of + /// [ThemeData.bottomAppBarTheme] is used. If that's null then + /// [ThemeData.bottomAppBarColor] is used. + final Color? color; + + /// The z-coordinate at which to place this bottom app bar relative to its + /// parent. + /// + /// This controls the size of the shadow below the bottom app bar. The + /// value is non-negative. + /// + /// If this property is null then [BottomAppBarTheme.elevation] of + /// [ThemeData.bottomAppBarTheme] is used. If that's null and + /// [ThemeData.useMaterial3] is true, than the default value is 3 else is 8. + final double? elevation; + + /// The notch that is made for the floating action button. + /// + /// If this property is null then [BottomAppBarTheme.shape] of + /// [ThemeData.bottomAppBarTheme] is used. If that's null then the shape will + /// be rectangular with no notch. + final NotchedShape? shape; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// The margin between the [FloatingActionButton] and the [BottomAppBar]'s + /// notch. + /// + /// Not used if [shape] is null. + final double notchMargin; + + /// A custom color for the Material 3 surface-tint elevation effect. + /// + /// In Material 3, a "surface tint" with an opacity related to [elevation] + /// will be applied to the [BottomAppBar]'s background. + /// Use this property to override the default color of that tint. + /// + /// If this property is null, then [BottomAppBarTheme.surfaceTintColor] + /// of [ThemeData.bottomAppBarTheme] is used. + /// If that is also null, [ColorScheme.surfaceTint] is used. + /// + /// Ignored if [ThemeData.useMaterial3] is false. + /// + /// The default is null. + /// + /// See [Material.surfaceTintColor] for more details on how this overlay is applied. + final Color? surfaceTintColor; + + /// The color of the shadow below the app bar. + /// + /// If this property is null, then [BottomAppBarTheme.shadowColor] of + /// [ThemeData.bottomAppBarTheme] is used. If that is also null, the default value + /// is fully opaque black for Material 2, and transparent for Material 3. + /// + /// See also: + /// + /// * [elevation], which defines the size of the shadow below the app bar. + /// * [shape], which defines the shape of the app bar and its shadow. + final Color? shadowColor; + + /// The double value used to indicate the height of the [BottomAppBar]. + /// + /// If this is null, the default value is the minimum in relation to the content, + /// unless [ThemeData.useMaterial3] is true, in which case it defaults to 80.0. + final double? height; + + @override + State createState() => _BottomAppBarState(); +} + +class _BottomAppBarState extends State<BottomAppBar> { + late ValueListenable<ScaffoldGeometry> geometryListenable; + final GlobalKey materialKey = GlobalKey(); + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + geometryListenable = Scaffold.geometryOf(context); + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final bool isMaterial3 = theme.useMaterial3; + final BottomAppBarTheme babTheme = BottomAppBarTheme.of(context); + final BottomAppBarTheme defaults = isMaterial3 ? _BottomAppBarDefaultsM3(context) : _BottomAppBarDefaultsM2(context); + + final bool hasFab = Scaffold.of(context).hasFloatingActionButton; + final NotchedShape? notchedShape = widget.shape ?? babTheme.shape ?? defaults.shape; + final CustomClipper<Path> clipper = notchedShape != null && hasFab + ? _BottomAppBarClipper( + geometry: geometryListenable, + shape: notchedShape, + materialKey: materialKey, + notchMargin: widget.notchMargin, + ) + : const ShapeBorderClipper(shape: RoundedRectangleBorder()); + final double elevation = widget.elevation ?? babTheme.elevation ?? defaults.elevation!; + final double? height = widget.height ?? babTheme.height ?? defaults.height; + final Color color = widget.color ?? babTheme.color ?? defaults.color!; + final Color surfaceTintColor = widget.surfaceTintColor ?? babTheme.surfaceTintColor ?? defaults.surfaceTintColor!; + final Color effectiveColor = isMaterial3 + ? ElevationOverlay.applySurfaceTint(color, surfaceTintColor, elevation) + : ElevationOverlay.applyOverlay(context, color, elevation); + final Color shadowColor = widget.shadowColor ?? babTheme.shadowColor ?? defaults.shadowColor!; + + final Widget child = SizedBox( + height: height, + child: Padding( + padding: widget.padding ?? babTheme.padding ?? (isMaterial3 ? const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0) : EdgeInsets.zero), + child: widget.child, + ), + ); + + final Material material = Material( + key: materialKey, + type: MaterialType.transparency, + child: SafeArea(child: child), + ); + + return PhysicalShape( + clipper: clipper, + elevation: elevation, + shadowColor: shadowColor, + color: effectiveColor, + clipBehavior: widget.clipBehavior, + child: material, + ); + } +} + +class _BottomAppBarClipper extends CustomClipper<Path> { + const _BottomAppBarClipper({ + required this.geometry, + required this.shape, + required this.materialKey, + required this.notchMargin, + }) : super(reclip: geometry); + + final ValueListenable<ScaffoldGeometry> geometry; + final NotchedShape shape; + final GlobalKey materialKey; + final double notchMargin; + + // Returns the top of the BottomAppBar in global coordinates. + // + // If the Scaffold's bottomNavigationBar was specified, then we can use its + // geometry value, otherwise we compute the location based on the AppBar's + // Material widget. + double get bottomNavigationBarTop { + final double? bottomNavigationBarTop = geometry.value.bottomNavigationBarTop; + if (bottomNavigationBarTop != null) { + return bottomNavigationBarTop; + } + final RenderBox? box = materialKey.currentContext?.findRenderObject() as RenderBox?; + return box?.localToGlobal(Offset.zero).dy ?? 0; + } + + @override + Path getClip(Size size) { + // button is the floating action button's bounding rectangle in the + // coordinate system whose origin is at the appBar's top left corner, + // or null if there is no floating action button. + final Rect? button = geometry.value.floatingActionButtonArea?.translate(0.0, bottomNavigationBarTop * -1.0); + return shape.getOuterPath(Offset.zero & size, button?.inflate(notchMargin)); + } + + @override + bool shouldReclip(_BottomAppBarClipper oldClipper) { + return oldClipper.geometry != geometry + || oldClipper.shape != shape + || oldClipper.notchMargin != notchMargin; + } +} + +class _BottomAppBarDefaultsM2 extends BottomAppBarTheme { + const _BottomAppBarDefaultsM2(this.context) + : super( + elevation: 8.0, + ); + + final BuildContext context; + + @override + Color? get color => Theme.of(context).bottomAppBarColor; + + @override + Color? get surfaceTintColor => Theme.of(context).colorScheme.surfaceTint; + + @override + Color get shadowColor => const Color(0xFF000000); +} + +// BEGIN GENERATED TOKEN PROPERTIES - BottomAppBar + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _BottomAppBarDefaultsM3 extends BottomAppBarTheme { + _BottomAppBarDefaultsM3(this.context) + : super( + elevation: 3.0, + height: 80.0, + shape: const AutomaticNotchedShape(RoundedRectangleBorder()), + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + Color? get color => _colors.surface; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + Color? get shadowColor => Colors.transparent; +} + +// END GENERATED TOKEN PROPERTIES - BottomAppBar diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_app_bar_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_app_bar_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..d2516e647a413f93346e6f1a03ba648a5d24f26f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_app_bar_theme.dart @@ -0,0 +1,153 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +/// Defines default property values for descendant [BottomAppBar] widgets. +/// +/// Descendant widgets obtain the current [BottomAppBarTheme] object using +/// `BottomAppBarTheme.of(context)`. Instances of [BottomAppBarTheme] can be +/// customized with [BottomAppBarTheme.copyWith]. +/// +/// Typically a [BottomAppBarTheme] is specified as part of the overall [Theme] +/// with [ThemeData.bottomAppBarTheme]. +/// +/// All [BottomAppBarTheme] properties are `null` by default. When null, the +/// [BottomAppBar] constructor provides defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class BottomAppBarTheme with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.bottomAppBarTheme]. + const BottomAppBarTheme({ + this.color, + this.elevation, + this.shape, + this.height, + this.surfaceTintColor, + this.shadowColor, + this.padding, + }); + + /// Overrides the default value for [BottomAppBar.color]. + /// + /// If null, [BottomAppBar] uses [ThemeData.bottomAppBarColor]. + final Color? color; + + /// Overrides the default value for [BottomAppBar.elevation]. + final double? elevation; + + /// Overrides the default value for [BottomAppBar.shape]. + final NotchedShape? shape; + + /// Overrides the default value for [BottomAppBar.height]. + final double? height; + + /// Overrides the default value for [BottomAppBar.surfaceTintColor]. + /// + /// If null, [BottomAppBar] will not display an overlay color. + /// + /// See [Material.surfaceTintColor] for more details. + final Color? surfaceTintColor; + + /// Overrides the default value for [BottomAppBar.shadowColor]. + final Color? shadowColor; + + /// Overrides the default value for [BottomAppBar.padding]. + final EdgeInsetsGeometry? padding; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + BottomAppBarTheme copyWith({ + Color? color, + double? elevation, + NotchedShape? shape, + double? height, + Color? surfaceTintColor, + Color? shadowColor, + EdgeInsetsGeometry? padding, + }) { + return BottomAppBarTheme( + color: color ?? this.color, + elevation: elevation ?? this.elevation, + shape: shape ?? this.shape, + height: height ?? this.height, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + shadowColor: shadowColor ?? this.shadowColor, + padding: padding ?? this.padding, + ); + } + + /// The [ThemeData.bottomAppBarTheme] property of the ambient [Theme]. + static BottomAppBarTheme of(BuildContext context) { + return Theme.of(context).bottomAppBarTheme; + } + + /// Linearly interpolate between two BAB themes. + /// + /// {@macro dart.ui.shadow.lerp} + static BottomAppBarTheme lerp(BottomAppBarTheme? a, BottomAppBarTheme? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return BottomAppBarTheme( + color: Color.lerp(a?.color, b?.color, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + shape: t < 0.5 ? a?.shape : b?.shape, + height: lerpDouble(a?.height, b?.height, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t), + ); + } + + @override + int get hashCode => Object.hash( + color, + elevation, + shape, + height, + surfaceTintColor, + shadowColor, + padding, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is BottomAppBarTheme + && other.color == color + && other.elevation == elevation + && other.shape == shape + && other.height == height + && other.surfaceTintColor == surfaceTintColor + && other.shadowColor == shadowColor + && other.padding == padding; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null)); + properties.add(DiagnosticsProperty<NotchedShape>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<double>('height', height, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_navigation_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..8df5612eb3c590e0cca2884e5783ca75161b75f3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -0,0 +1,1331 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection' show Queue; +import 'dart:math' as math; + +import 'package:flutter/widgets.dart'; +import 'package:vector_math/vector_math_64.dart' show Vector3; + +import 'bottom_navigation_bar_theme.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'theme.dart'; +import 'tooltip.dart'; + +/// Defines the layout and behavior of a [BottomNavigationBar]. +/// +/// For a sample on how to use these, please see [BottomNavigationBar]. +/// See also: +/// +/// * [BottomNavigationBar] +/// * [BottomNavigationBarItem] +/// * <https://material.io/design/components/bottom-navigation.html#specs> +enum BottomNavigationBarType { + /// The [BottomNavigationBar]'s [BottomNavigationBarItem]s have fixed width. + fixed, + + /// The location and size of the [BottomNavigationBar] [BottomNavigationBarItem]s + /// animate and labels fade in when they are tapped. + shifting, +} + +/// Refines the layout of a [BottomNavigationBar] when the enclosing +/// [MediaQueryData.orientation] is [Orientation.landscape]. +enum BottomNavigationBarLandscapeLayout { + /// If the enclosing [MediaQueryData.orientation] is + /// [Orientation.landscape] then the navigation bar's items are + /// evenly spaced and spread out across the available width. Each + /// item's label and icon are arranged in a column. + spread, + + /// If the enclosing [MediaQueryData.orientation] is + /// [Orientation.landscape] then the navigation bar's items are + /// evenly spaced in a row but only consume as much width as they + /// would in portrait orientation. The row of items is centered within + /// the available width. Each item's label and icon are arranged + /// in a column. + centered, + + /// If the enclosing [MediaQueryData.orientation] is + /// [Orientation.landscape] then the navigation bar's items are + /// evenly spaced and each item's icon and label are lined up in a + /// row instead of a column. + linear, +} + + +/// A material widget that's displayed at the bottom of an app for selecting +/// among a small number of views, typically between three and five. +/// +/// There is an updated version of this component, [NavigationBar], that's +/// preferred for new applications and applications that are configured +/// for Material 3 (see [ThemeData.useMaterial3]). +/// +/// The bottom navigation bar consists of multiple items in the form of +/// text labels, icons, or both, laid out on top of a piece of material. It +/// provides quick navigation between the top-level views of an app. For larger +/// screens, side navigation may be a better fit. +/// +/// A bottom navigation bar is usually used in conjunction with a [Scaffold], +/// where it is provided as the [Scaffold.bottomNavigationBar] argument. +/// +/// The bottom navigation bar's [type] changes how its [items] are displayed. +/// If not specified, then it's automatically set to +/// [BottomNavigationBarType.fixed] when there are less than four items, and +/// [BottomNavigationBarType.shifting] otherwise. +/// +/// The length of [items] must be at least two and each item's icon and +/// label must not be null. +/// +/// * [BottomNavigationBarType.fixed], the default when there are less than +/// four [items]. The selected item is rendered with the +/// [selectedItemColor] if it's non-null, otherwise the theme's +/// [ColorScheme.primary] color is used for [Brightness.light] themes +/// and [ColorScheme.secondary] for [Brightness.dark] themes. +/// If [backgroundColor] is null, The +/// navigation bar's background color defaults to the [Material] background +/// color, [ThemeData.canvasColor] (essentially opaque white). +/// * [BottomNavigationBarType.shifting], the default when there are four +/// or more [items]. If [selectedItemColor] is null, all items are rendered +/// in white. The navigation bar's background color is the same as the +/// [BottomNavigationBarItem.backgroundColor] of the selected item. In this +/// case it's assumed that each item will have a different background color +/// and that background color will contrast well with white. +/// +/// ## Updating to [NavigationBar] +/// +/// The [NavigationBar] widget's visuals +/// are a little bit different, see the Material 3 spec at +/// <https://m3.material.io/components/navigation-bar/overview> for +/// more details. +/// +/// The [NavigationBar] widget's API is also slightly different. +/// To update from [BottomNavigationBar] to [NavigationBar], you will +/// need to make the following changes. +/// +/// 1. Instead of using [BottomNavigationBar.items], which +/// takes a list of [BottomNavigationBarItem]s, use +/// [NavigationBar.destinations], which takes a list of widgets. +/// Usually, you use a list of [NavigationDestination] widgets. +/// Just like [BottomNavigationBarItem]s, [NavigationDestination]s +/// have a label and icon field. +/// +/// 2. Instead of using [BottomNavigationBar.onTap], +/// use [NavigationBar.onDestinationSelected], which is also +/// a callback that is called when the user taps on a +/// navigation bar item. +/// +/// 3. Instead of using [BottomNavigationBar.currentIndex], +/// use [NavigationBar.selectedIndex], which is also an integer +/// that represents the index of the selected destination. +/// +/// 4. You may also need to make changes to the styling of the +/// [NavigationBar], see the properties in the [NavigationBar] +/// constructor for more details. +/// +/// ## Using [BottomNavigationBar] +/// +/// {@tool dartpad} +/// This example shows a [BottomNavigationBar] as it is used within a [Scaffold] +/// widget. The [BottomNavigationBar] has three [BottomNavigationBarItem] +/// widgets, which means it defaults to [BottomNavigationBarType.fixed], and +/// the [currentIndex] is set to index 0. The selected item is +/// amber. The `_onItemTapped` function changes the selected item's index +/// and displays a corresponding message in the center of the [Scaffold]. +/// +/// ** See code in examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how you would migrate the above [BottomNavigationBar] +/// to the new [NavigationBar]. +/// +/// ** See code in examples/api/lib/material/navigation_bar/navigation_bar.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows a [BottomNavigationBar] as it is used within a [Scaffold] +/// widget. The [BottomNavigationBar] has four [BottomNavigationBarItem] +/// widgets, which means it defaults to [BottomNavigationBarType.shifting], and +/// the [currentIndex] is set to index 0. The selected item is amber in color. +/// With each [BottomNavigationBarItem] widget, backgroundColor property is +/// also defined, which changes the background color of [BottomNavigationBar], +/// when that item is selected. The `_onItemTapped` function changes the +/// selected item's index and displays a corresponding message in the center of +/// the [Scaffold]. +/// +/// ** See code in examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows [BottomNavigationBar] used in a [Scaffold] Widget with +/// different interaction patterns. Tapping twice on the first [BottomNavigationBarItem] +/// uses the [ScrollController] to animate the [ListView] to the top. The second +/// [BottomNavigationBarItem] shows a Modal Dialog. +/// +/// ** See code in examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.2.dart ** +/// {@end-tool} +/// See also: +/// +/// * [BottomNavigationBarItem] +/// * [Scaffold] +/// * <https://material.io/design/components/bottom-navigation.html> +/// * [NavigationBar], this widget's replacement in Material Design 3. +class BottomNavigationBar extends StatefulWidget { + /// Creates a bottom navigation bar which is typically used as a + /// [Scaffold]'s [Scaffold.bottomNavigationBar] argument. + /// + /// The length of [items] must be at least two and each item's icon and label + /// must not be null. + /// + /// If [type] is null then [BottomNavigationBarType.fixed] is used when there + /// are two or three [items], [BottomNavigationBarType.shifting] otherwise. + /// + /// The [iconSize], [selectedFontSize], [unselectedFontSize], and [elevation] + /// arguments must be non-negative. + /// + /// If [selectedLabelStyle].color and [unselectedLabelStyle].color values + /// are non-null, they will be used instead of [selectedItemColor] and + /// [unselectedItemColor]. + /// + /// If custom [IconThemeData]s are used, you must provide both + /// [selectedIconTheme] and [unselectedIconTheme], and both + /// [IconThemeData.color] and [IconThemeData.size] must be set. + /// + /// If [useLegacyColorScheme] is set to `false` + /// [selectedIconTheme] values will be used instead of [iconSize] and [selectedItemColor] for selected icons. + /// [unselectedIconTheme] values will be used instead of [iconSize] and [unselectedItemColor] for unselected icons. + /// + /// + /// If both [selectedLabelStyle].fontSize and [selectedFontSize] are set, + /// [selectedLabelStyle].fontSize will be used. + /// + /// Only one of [selectedItemColor] and [fixedColor] can be specified. The + /// former is preferred, [fixedColor] only exists for the sake of + /// backwards compatibility. + /// + /// If [showSelectedLabels] is `null`, [BottomNavigationBarThemeData.showSelectedLabels] + /// is used. If [BottomNavigationBarThemeData.showSelectedLabels] is null, + /// then [showSelectedLabels] defaults to `true`. + /// + /// If [showUnselectedLabels] is `null`, [BottomNavigationBarThemeData.showUnselectedLabels] + /// is used. If [BottomNavigationBarThemeData.showSelectedLabels] is null, + /// then [showUnselectedLabels] defaults to `true` when [type] is + /// [BottomNavigationBarType.fixed] and `false` when [type] is + /// [BottomNavigationBarType.shifting]. + BottomNavigationBar({ + super.key, + required this.items, + this.onTap, + this.currentIndex = 0, + this.elevation, + this.type, + Color? fixedColor, + this.backgroundColor, + this.iconSize = 24.0, + Color? selectedItemColor, + this.unselectedItemColor, + this.selectedIconTheme, + this.unselectedIconTheme, + this.selectedFontSize = 14.0, + this.unselectedFontSize = 12.0, + this.selectedLabelStyle, + this.unselectedLabelStyle, + this.showSelectedLabels, + this.showUnselectedLabels, + this.mouseCursor, + this.enableFeedback, + this.landscapeLayout, + this.useLegacyColorScheme = true, + }) : assert(items.length >= 2), + assert( + items.every((BottomNavigationBarItem item) => item.label != null), + 'Every item must have a non-null label', + ), + assert(0 <= currentIndex && currentIndex < items.length), + assert(elevation == null || elevation >= 0.0), + assert(iconSize >= 0.0), + assert( + selectedItemColor == null || fixedColor == null, + 'Either selectedItemColor or fixedColor can be specified, but not both', + ), + assert(selectedFontSize >= 0.0), + assert(unselectedFontSize >= 0.0), + selectedItemColor = selectedItemColor ?? fixedColor; + + /// Defines the appearance of the button items that are arrayed within the + /// bottom navigation bar. + final List<BottomNavigationBarItem> items; + + /// Called when one of the [items] is tapped. + /// + /// The stateful widget that creates the bottom navigation bar needs to keep + /// track of the index of the selected [BottomNavigationBarItem] and call + /// `setState` to rebuild the bottom navigation bar with the new [currentIndex]. + final ValueChanged<int>? onTap; + + /// The index into [items] for the current active [BottomNavigationBarItem]. + final int currentIndex; + + /// The z-coordinate of this [BottomNavigationBar]. + /// + /// If null, defaults to `8.0`. + /// + /// {@macro flutter.material.material.elevation} + final double? elevation; + + /// Defines the layout and behavior of a [BottomNavigationBar]. + /// + /// See documentation for [BottomNavigationBarType] for information on the + /// meaning of different types. + final BottomNavigationBarType? type; + + /// The value of [selectedItemColor]. + /// + /// This getter only exists for backwards compatibility, the + /// [selectedItemColor] property is preferred. + Color? get fixedColor => selectedItemColor; + + /// The color of the [BottomNavigationBar] itself. + /// + /// If [type] is [BottomNavigationBarType.shifting] and the + /// [items] have [BottomNavigationBarItem.backgroundColor] set, the [items]' + /// backgroundColor will splash and overwrite this color. + final Color? backgroundColor; + + /// The size of all of the [BottomNavigationBarItem] icons. + /// + /// See [BottomNavigationBarItem.icon] for more information. + final double iconSize; + + /// The color of the selected [BottomNavigationBarItem.icon] and + /// [BottomNavigationBarItem.label]. + /// + /// If null then the [ThemeData.primaryColor] is used. + final Color? selectedItemColor; + + /// The color of the unselected [BottomNavigationBarItem.icon] and + /// [BottomNavigationBarItem.label]s. + /// + /// If null then the [ThemeData.unselectedWidgetColor]'s color is used. + final Color? unselectedItemColor; + + /// The size, opacity, and color of the icon in the currently selected + /// [BottomNavigationBarItem.icon]. + /// + /// If this is not provided, the size will default to [iconSize], the color + /// will default to [selectedItemColor]. + /// + /// It this field is provided, it must contain non-null [IconThemeData.size] + /// and [IconThemeData.color] properties. Also, if this field is supplied, + /// [unselectedIconTheme] must be provided. + final IconThemeData? selectedIconTheme; + + /// The size, opacity, and color of the icon in the currently unselected + /// [BottomNavigationBarItem.icon]s. + /// + /// If this is not provided, the size will default to [iconSize], the color + /// will default to [unselectedItemColor]. + /// + /// It this field is provided, it must contain non-null [IconThemeData.size] + /// and [IconThemeData.color] properties. Also, if this field is supplied, + /// [selectedIconTheme] must be provided. + final IconThemeData? unselectedIconTheme; + + /// The [TextStyle] of the [BottomNavigationBarItem] labels when they are + /// selected. + final TextStyle? selectedLabelStyle; + + /// The [TextStyle] of the [BottomNavigationBarItem] labels when they are not + /// selected. + final TextStyle? unselectedLabelStyle; + + /// The font size of the [BottomNavigationBarItem] labels when they are selected. + /// + /// If [TextStyle.fontSize] of [selectedLabelStyle] is non-null, it will be + /// used instead of this. + /// + /// Defaults to `14.0`. + final double selectedFontSize; + + /// The font size of the [BottomNavigationBarItem] labels when they are not + /// selected. + /// + /// If [TextStyle.fontSize] of [unselectedLabelStyle] is non-null, it will be + /// used instead of this. + /// + /// Defaults to `12.0`. + final double unselectedFontSize; + + /// Whether the labels are shown for the unselected [BottomNavigationBarItem]s. + final bool? showUnselectedLabels; + + /// Whether the labels are shown for the selected [BottomNavigationBarItem]. + final bool? showSelectedLabels; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// items. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.selected]. + /// + /// If null, then the value of [BottomNavigationBarThemeData.mouseCursor] is used. If + /// that is also null, then [MaterialStateMouseCursor.clickable] is used. + /// + /// See also: + /// + /// * [MaterialStateMouseCursor], which can be used to create a [MouseCursor] + /// that is also a [MaterialStateProperty<MouseCursor>]. + final MouseCursor? mouseCursor; + + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + /// The arrangement of the bar's [items] when the enclosing + /// [MediaQueryData.orientation] is [Orientation.landscape]. + /// + /// The following alternatives are supported: + /// + /// * [BottomNavigationBarLandscapeLayout.spread] - the items are + /// evenly spaced and spread out across the available width. Each + /// item's label and icon are arranged in a column. + /// * [BottomNavigationBarLandscapeLayout.centered] - the items are + /// evenly spaced in a row but only consume as much width as they + /// would in portrait orientation. The row of items is centered within + /// the available width. Each item's label and icon are arranged + /// in a column. + /// * [BottomNavigationBarLandscapeLayout.linear] - the items are + /// evenly spaced and each item's icon and label are lined up in a + /// row instead of a column. + /// + /// If this property is null, then the value of the enclosing + /// [BottomNavigationBarThemeData.landscapeLayout is used. If that + /// property is also null, then + /// [BottomNavigationBarLandscapeLayout.spread] is used. + /// + /// This property is null by default. + /// + /// See also: + /// + /// * [ThemeData.bottomNavigationBarTheme] - which can be used to specify + /// bottom navigation bar defaults for an entire application. + /// * [BottomNavigationBarTheme] - which can be used to specify + /// bottom navigation bar defaults for a widget subtree. + /// * [MediaQuery.orientationOf] - which can be used to determine the current + /// orientation. + final BottomNavigationBarLandscapeLayout? landscapeLayout; + + /// This flag is controlling how [BottomNavigationBar] is going to use + /// the colors provided by the [selectedIconTheme], [unselectedIconTheme], + /// [selectedItemColor], [unselectedItemColor]. + /// The default value is `true` as the new theming logic is a breaking change. + /// To opt-in the new theming logic set the flag to `false` + final bool useLegacyColorScheme; + + @override + State<BottomNavigationBar> createState() => _BottomNavigationBarState(); +} + +// This represents a single tile in the bottom navigation bar. It is intended +// to go into a flex container. +class _BottomNavigationTile extends StatelessWidget { + const _BottomNavigationTile( + this.type, + this.item, + this.animation, + this.iconSize, { + super.key, + this.onTap, + this.labelColorTween, + this.iconColorTween, + this.flex, + this.selected = false, + required this.selectedLabelStyle, + required this.unselectedLabelStyle, + required this.selectedIconTheme, + required this.unselectedIconTheme, + required this.showSelectedLabels, + required this.showUnselectedLabels, + this.indexLabel, + required this.mouseCursor, + required this.enableFeedback, + required this.layout, + }); + + final BottomNavigationBarType type; + final BottomNavigationBarItem item; + final Animation<double> animation; + final double iconSize; + final VoidCallback? onTap; + final ColorTween? labelColorTween; + final ColorTween? iconColorTween; + final double? flex; + final bool selected; + final IconThemeData? selectedIconTheme; + final IconThemeData? unselectedIconTheme; + final TextStyle selectedLabelStyle; + final TextStyle unselectedLabelStyle; + final String? indexLabel; + final bool showSelectedLabels; + final bool showUnselectedLabels; + final MouseCursor mouseCursor; + final bool enableFeedback; + final BottomNavigationBarLandscapeLayout layout; + + @override + Widget build(BuildContext context) { + // In order to use the flex container to grow the tile during animation, we + // need to divide the changes in flex allotment into smaller pieces to + // produce smooth animation. We do this by multiplying the flex value + // (which is an integer) by a large number. + final int size; + + final double selectedFontSize = selectedLabelStyle.fontSize!; + + final double selectedIconSize = selectedIconTheme?.size ?? iconSize; + final double unselectedIconSize = unselectedIconTheme?.size ?? iconSize; + + // The amount that the selected icon is bigger than the unselected icons, + // (or zero if the selected icon is not bigger than the unselected icons). + final double selectedIconDiff = math.max(selectedIconSize - unselectedIconSize, 0); + // The amount that the unselected icons are bigger than the selected icon, + // (or zero if the unselected icons are not any bigger than the selected icon). + final double unselectedIconDiff = math.max(unselectedIconSize - selectedIconSize, 0); + + // The effective tool tip message to be shown on the BottomNavigationBarItem. + final String? effectiveTooltip = item.tooltip == '' ? null : item.tooltip; + + // Defines the padding for the animating icons + labels. + // + // The animations go from "Unselected": + // ======= + // | <-- Padding equal to the text height + 1/2 selectedIconDiff. + // | ☆ + // | text <-- Invisible text + padding equal to 1/2 selectedIconDiff. + // ======= + // + // To "Selected": + // + // ======= + // | <-- Padding equal to 1/2 text height + 1/2 unselectedIconDiff. + // | ☆ + // | text + // | <-- Padding equal to 1/2 text height + 1/2 unselectedIconDiff. + // ======= + double bottomPadding; + double topPadding; + if (showSelectedLabels && !showUnselectedLabels) { + bottomPadding = Tween<double>( + begin: selectedIconDiff / 2.0, + end: selectedFontSize / 2.0 - unselectedIconDiff / 2.0, + ).evaluate(animation); + topPadding = Tween<double>( + begin: selectedFontSize + selectedIconDiff / 2.0, + end: selectedFontSize / 2.0 - unselectedIconDiff / 2.0, + ).evaluate(animation); + } else if (!showSelectedLabels && !showUnselectedLabels) { + bottomPadding = Tween<double>( + begin: selectedIconDiff / 2.0, + end: unselectedIconDiff / 2.0, + ).evaluate(animation); + topPadding = Tween<double>( + begin: selectedFontSize + selectedIconDiff / 2.0, + end: selectedFontSize + unselectedIconDiff / 2.0, + ).evaluate(animation); + } else { + bottomPadding = Tween<double>( + begin: selectedFontSize / 2.0 + selectedIconDiff / 2.0, + end: selectedFontSize / 2.0 + unselectedIconDiff / 2.0, + ).evaluate(animation); + topPadding = Tween<double>( + begin: selectedFontSize / 2.0 + selectedIconDiff / 2.0, + end: selectedFontSize / 2.0 + unselectedIconDiff / 2.0, + ).evaluate(animation); + } + + switch (type) { + case BottomNavigationBarType.fixed: + size = 1; + case BottomNavigationBarType.shifting: + size = (flex! * 1000.0).round(); + } + + Widget result = InkResponse( + onTap: onTap, + mouseCursor: mouseCursor, + enableFeedback: enableFeedback, + child: Padding( + padding: EdgeInsets.only(top: topPadding, bottom: bottomPadding), + child: _Tile( + layout: layout, + icon: _TileIcon( + colorTween: iconColorTween!, + animation: animation, + iconSize: iconSize, + selected: selected, + item: item, + selectedIconTheme: selectedIconTheme, + unselectedIconTheme: unselectedIconTheme, + ), + label: _Label( + colorTween: labelColorTween!, + animation: animation, + item: item, + selectedLabelStyle: selectedLabelStyle, + unselectedLabelStyle: unselectedLabelStyle, + showSelectedLabels: showSelectedLabels, + showUnselectedLabels: showUnselectedLabels, + ), + ), + ), + ); + + if (effectiveTooltip != null) { + result = Tooltip( + message: effectiveTooltip, + preferBelow: false, + verticalOffset: selectedIconSize + selectedFontSize, + excludeFromSemantics: true, + child: result, + ); + } + + result = Semantics( + selected: selected, + container: true, + child: Stack( + children: <Widget>[ + result, + Semantics( + label: indexLabel, + ), + ], + ), + ); + + return Expanded( + flex: size, + child: result, + ); + } +} + + +// If the orientation is landscape and layout is +// BottomNavigationBarLandscapeLayout.linear then return a +// icon-space-label row, where space is 8 pixels. Otherwise return a +// icon-label column. +class _Tile extends StatelessWidget { + const _Tile({ + required this.layout, + required this.icon, + required this.label + }); + + final BottomNavigationBarLandscapeLayout layout; + final Widget icon; + final Widget label; + + @override + Widget build(BuildContext context) { + if (MediaQuery.orientationOf(context) == Orientation.landscape && layout == BottomNavigationBarLandscapeLayout.linear) { + return Align( + heightFactor: 1, + child: Row( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + icon, + const SizedBox(width: 8), + // Flexible lets the overflow property of + // label to work and IntrinsicWidth gives label a + // resonable width preventing extra space before it. + Flexible(child: IntrinsicWidth(child: label)) + ], + ), + ); + } + return Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisSize: MainAxisSize.min, + children: <Widget>[icon, label], + ); + } +} + +class _TileIcon extends StatelessWidget { + const _TileIcon({ + required this.colorTween, + required this.animation, + required this.iconSize, + required this.selected, + required this.item, + required this.selectedIconTheme, + required this.unselectedIconTheme, + }); + + final ColorTween colorTween; + final Animation<double> animation; + final double iconSize; + final bool selected; + final BottomNavigationBarItem item; + final IconThemeData? selectedIconTheme; + final IconThemeData? unselectedIconTheme; + + @override + Widget build(BuildContext context) { + final Color? iconColor = colorTween.evaluate(animation); + final IconThemeData defaultIconTheme = IconThemeData( + color: iconColor, + size: iconSize, + ); + final IconThemeData iconThemeData = IconThemeData.lerp( + defaultIconTheme.merge(unselectedIconTheme), + defaultIconTheme.merge(selectedIconTheme), + animation.value, + ); + + return Align( + alignment: Alignment.topCenter, + heightFactor: 1.0, + child: IconTheme( + data: iconThemeData, + child: selected ? item.activeIcon : item.icon, + ), + ); + } +} + +class _Label extends StatelessWidget { + const _Label({ + required this.colorTween, + required this.animation, + required this.item, + required this.selectedLabelStyle, + required this.unselectedLabelStyle, + required this.showSelectedLabels, + required this.showUnselectedLabels, + }); + + final ColorTween colorTween; + final Animation<double> animation; + final BottomNavigationBarItem item; + final TextStyle selectedLabelStyle; + final TextStyle unselectedLabelStyle; + final bool showSelectedLabels; + final bool showUnselectedLabels; + + @override + Widget build(BuildContext context) { + final double? selectedFontSize = selectedLabelStyle.fontSize; + final double? unselectedFontSize = unselectedLabelStyle.fontSize; + + final TextStyle customStyle = TextStyle.lerp( + unselectedLabelStyle, + selectedLabelStyle, + animation.value, + )!; + Widget text = DefaultTextStyle.merge( + style: customStyle.copyWith( + fontSize: selectedFontSize, + color: colorTween.evaluate(animation), + ), + // The font size should grow here when active, but because of the way + // font rendering works, it doesn't grow smoothly if we just animate + // the font size, so we use a transform instead. + child: Transform( + transform: Matrix4.diagonal3( + Vector3.all( + Tween<double>( + begin: unselectedFontSize! / selectedFontSize!, + end: 1.0, + ).evaluate(animation), + ), + ), + alignment: Alignment.bottomCenter, + child: Text(item.label!), + ), + ); + + if (!showUnselectedLabels && !showSelectedLabels) { + // Never show any labels. + text = Visibility.maintain( + visible: false, + child: text, + ); + } else if (!showUnselectedLabels) { + // Fade selected labels in. + text = FadeTransition( + alwaysIncludeSemantics: true, + opacity: animation, + child: text, + ); + } else if (!showSelectedLabels) { + // Fade selected labels out. + text = FadeTransition( + alwaysIncludeSemantics: true, + opacity: Tween<double>(begin: 1.0, end: 0.0).animate(animation), + child: text, + ); + } + + text = Align( + alignment: Alignment.bottomCenter, + heightFactor: 1.0, + child: Container(child: text), + ); + + if (item.label != null) { + // Do not grow text in bottom navigation bar when we can show a tooltip + // instead. + text = MediaQuery.withClampedTextScaling( + maxScaleFactor: 1.0, + child: text, + ); + } + + return text; + } +} + +class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerProviderStateMixin { + List<AnimationController> _controllers = <AnimationController>[]; + late List<CurvedAnimation> _animations; + + // A queue of color splashes currently being animated. + final Queue<_Circle> _circles = Queue<_Circle>(); + + // Last splash circle's color, and the final color of the control after + // animation is complete. + Color? _backgroundColor; + + static final Animatable<double> _flexTween = Tween<double>(begin: 1.0, end: 1.5); + + void _resetState() { + for (final AnimationController controller in _controllers) { + controller.dispose(); + } + for (final _Circle circle in _circles) { + circle.dispose(); + } + _circles.clear(); + + _controllers = List<AnimationController>.generate(widget.items.length, (int index) { + return AnimationController( + duration: kThemeAnimationDuration, + vsync: this, + )..addListener(_rebuild); + }); + _animations = List<CurvedAnimation>.generate(widget.items.length, (int index) { + return CurvedAnimation( + parent: _controllers[index], + curve: Curves.fastOutSlowIn, + reverseCurve: Curves.fastOutSlowIn.flipped, + ); + }); + _controllers[widget.currentIndex].value = 1.0; + _backgroundColor = widget.items[widget.currentIndex].backgroundColor; + } + + // Computes the default value for the [type] parameter. + // + // If type is provided, it is returned. Next, if the bottom navigation bar + // theme provides a type, it is used. Finally, the default behavior will be + // [BottomNavigationBarType.fixed] for 3 or fewer items, and + // [BottomNavigationBarType.shifting] is used for 4+ items. + BottomNavigationBarType get _effectiveType { + return widget.type + ?? BottomNavigationBarTheme.of(context).type + ?? (widget.items.length <= 3 ? BottomNavigationBarType.fixed : BottomNavigationBarType.shifting); + } + + // Computes the default value for the [showUnselected] parameter. + // + // Unselected labels are shown by default for [BottomNavigationBarType.fixed], + // and hidden by default for [BottomNavigationBarType.shifting]. + bool get _defaultShowUnselected { + switch (_effectiveType) { + case BottomNavigationBarType.shifting: + return false; + case BottomNavigationBarType.fixed: + return true; + } + } + + @override + void initState() { + super.initState(); + _resetState(); + } + + void _rebuild() { + setState(() { + // Rebuilding when any of the controllers tick, i.e. when the items are + // animated. + }); + } + + @override + void dispose() { + for (final AnimationController controller in _controllers) { + controller.dispose(); + } + for (final _Circle circle in _circles) { + circle.dispose(); + } + super.dispose(); + } + + double _evaluateFlex(Animation<double> animation) => _flexTween.evaluate(animation); + + void _pushCircle(int index) { + if (widget.items[index].backgroundColor != null) { + _circles.add( + _Circle( + state: this, + index: index, + color: widget.items[index].backgroundColor!, + vsync: this, + )..controller.addStatusListener( + (AnimationStatus status) { + switch (status) { + case AnimationStatus.completed: + setState(() { + final _Circle circle = _circles.removeFirst(); + _backgroundColor = circle.color; + circle.dispose(); + }); + case AnimationStatus.dismissed: + case AnimationStatus.forward: + case AnimationStatus.reverse: + break; + } + }, + ), + ); + } + } + + @override + void didUpdateWidget(BottomNavigationBar oldWidget) { + super.didUpdateWidget(oldWidget); + + // No animated segue if the length of the items list changes. + if (widget.items.length != oldWidget.items.length) { + _resetState(); + return; + } + + if (widget.currentIndex != oldWidget.currentIndex) { + switch (_effectiveType) { + case BottomNavigationBarType.fixed: + break; + case BottomNavigationBarType.shifting: + _pushCircle(widget.currentIndex); + } + _controllers[oldWidget.currentIndex].reverse(); + _controllers[widget.currentIndex].forward(); + } else { + if (_backgroundColor != widget.items[widget.currentIndex].backgroundColor) { + _backgroundColor = widget.items[widget.currentIndex].backgroundColor; + } + } + } + + // If the given [TextStyle] has a non-null `fontSize`, it should be used. + // Otherwise, the [selectedFontSize] parameter should be used. + static TextStyle _effectiveTextStyle(TextStyle? textStyle, double fontSize) { + textStyle ??= const TextStyle(); + // Prefer the font size on textStyle if present. + return textStyle.fontSize == null ? textStyle.copyWith(fontSize: fontSize) : textStyle; + } + + // If [IconThemeData] is provided, it should be used. + // Otherwise, the [IconThemeData]'s color should be selectedItemColor + // or unselectedItemColor. + static IconThemeData _effectiveIconTheme(IconThemeData? iconTheme, Color? itemColor) { + // Prefer the iconTheme over itemColor if present. + return iconTheme ?? IconThemeData(color: itemColor); + } + + + List<Widget> _createTiles(BottomNavigationBarLandscapeLayout layout) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + + final ThemeData themeData = Theme.of(context); + final BottomNavigationBarThemeData bottomTheme = BottomNavigationBarTheme.of(context); + + final Color themeColor; + switch (themeData.brightness) { + case Brightness.light: + themeColor = themeData.colorScheme.primary; + case Brightness.dark: + themeColor = themeData.colorScheme.secondary; + } + + final TextStyle effectiveSelectedLabelStyle = + _effectiveTextStyle( + widget.selectedLabelStyle + ?? bottomTheme.selectedLabelStyle, + widget.selectedFontSize, + ); + + final TextStyle effectiveUnselectedLabelStyle = + _effectiveTextStyle( + widget.unselectedLabelStyle + ?? bottomTheme.unselectedLabelStyle, + widget.unselectedFontSize, + ); + + final IconThemeData effectiveSelectedIconTheme = + _effectiveIconTheme( + widget.selectedIconTheme + ?? bottomTheme.selectedIconTheme, + widget.selectedItemColor + ?? bottomTheme.selectedItemColor + ?? themeColor + ); + + final IconThemeData effectiveUnselectedIconTheme = + _effectiveIconTheme( + widget.unselectedIconTheme + ?? bottomTheme.unselectedIconTheme, + widget.unselectedItemColor + ?? bottomTheme.unselectedItemColor + ?? themeData.unselectedWidgetColor + ); + + + final ColorTween colorTween; + switch (_effectiveType) { + case BottomNavigationBarType.fixed: + colorTween = ColorTween( + begin: widget.unselectedItemColor + ?? bottomTheme.unselectedItemColor + ?? themeData.unselectedWidgetColor, + end: widget.selectedItemColor + ?? bottomTheme.selectedItemColor + ?? widget.fixedColor + ?? themeColor, + ); + case BottomNavigationBarType.shifting: + colorTween = ColorTween( + begin: widget.unselectedItemColor + ?? bottomTheme.unselectedItemColor + ?? themeData.colorScheme.surface, + end: widget.selectedItemColor + ?? bottomTheme.selectedItemColor + ?? themeData.colorScheme.surface, + ); + } + + final ColorTween labelColorTween; + switch (_effectiveType) { + case BottomNavigationBarType.fixed: + labelColorTween = ColorTween( + begin: effectiveUnselectedLabelStyle.color + ?? widget.unselectedItemColor + ?? bottomTheme.unselectedItemColor + ?? themeData.unselectedWidgetColor, + end: effectiveSelectedLabelStyle.color + ?? widget.selectedItemColor + ?? bottomTheme.selectedItemColor + ?? widget.fixedColor + ?? themeColor, + ); + case BottomNavigationBarType.shifting: + labelColorTween = ColorTween( + begin: effectiveUnselectedLabelStyle.color + ?? widget.unselectedItemColor + ?? bottomTheme.unselectedItemColor + ?? themeData.colorScheme.surface, + end: effectiveSelectedLabelStyle.color + ?? widget.selectedItemColor + ?? bottomTheme.selectedItemColor + ?? themeColor, + ); + } + + final ColorTween iconColorTween; + switch (_effectiveType) { + case BottomNavigationBarType.fixed: + iconColorTween = ColorTween( + begin: effectiveSelectedIconTheme.color + ?? widget.unselectedItemColor + ?? bottomTheme.unselectedItemColor + ?? themeData.unselectedWidgetColor, + end: effectiveUnselectedIconTheme.color + ?? widget.selectedItemColor + ?? bottomTheme.selectedItemColor + ?? widget.fixedColor + ?? themeColor, + ); + case BottomNavigationBarType.shifting: + iconColorTween = ColorTween( + begin: effectiveUnselectedIconTheme.color + ?? widget.unselectedItemColor + ?? bottomTheme.unselectedItemColor + ?? themeData.colorScheme.surface, + end: effectiveSelectedIconTheme.color + ?? widget.selectedItemColor + ?? bottomTheme.selectedItemColor + ?? themeColor, + ); + } + + final List<Widget> tiles = <Widget>[]; + for (int i = 0; i < widget.items.length; i++) { + final Set<MaterialState> states = <MaterialState>{ + if (i == widget.currentIndex) MaterialState.selected, + }; + + final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor?>(widget.mouseCursor, states) + ?? bottomTheme.mouseCursor?.resolve(states) + ?? MaterialStateMouseCursor.clickable.resolve(states); + + tiles.add(_BottomNavigationTile( + _effectiveType, + widget.items[i], + _animations[i], + widget.iconSize, + key: widget.items[i].key, + selectedIconTheme: widget.useLegacyColorScheme ? widget.selectedIconTheme ?? bottomTheme.selectedIconTheme : effectiveSelectedIconTheme, + unselectedIconTheme: widget.useLegacyColorScheme ? widget.unselectedIconTheme ?? bottomTheme.unselectedIconTheme : effectiveUnselectedIconTheme, + selectedLabelStyle: effectiveSelectedLabelStyle, + unselectedLabelStyle: effectiveUnselectedLabelStyle, + enableFeedback: widget.enableFeedback ?? bottomTheme.enableFeedback ?? true, + onTap: () { + widget.onTap?.call(i); + }, + labelColorTween: widget.useLegacyColorScheme ? colorTween : labelColorTween, + iconColorTween: widget.useLegacyColorScheme ? colorTween : iconColorTween, + flex: _evaluateFlex(_animations[i]), + selected: i == widget.currentIndex, + showSelectedLabels: widget.showSelectedLabels ?? bottomTheme.showSelectedLabels ?? true, + showUnselectedLabels: widget.showUnselectedLabels ?? bottomTheme.showUnselectedLabels ?? _defaultShowUnselected, + indexLabel: localizations.tabLabel(tabIndex: i + 1, tabCount: widget.items.length), + mouseCursor: effectiveMouseCursor, + layout: layout, + )); + } + return tiles; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + assert(debugCheckHasMaterialLocalizations(context)); + assert(debugCheckHasMediaQuery(context)); + assert(debugCheckHasOverlay(context)); + + final BottomNavigationBarThemeData bottomTheme = BottomNavigationBarTheme.of(context); + final BottomNavigationBarLandscapeLayout layout = widget.landscapeLayout + ?? bottomTheme.landscapeLayout + ?? BottomNavigationBarLandscapeLayout.spread; + final double additionalBottomPadding = MediaQuery.viewPaddingOf(context).bottom; + + Color? backgroundColor; + switch (_effectiveType) { + case BottomNavigationBarType.fixed: + backgroundColor = widget.backgroundColor ?? bottomTheme.backgroundColor; + case BottomNavigationBarType.shifting: + backgroundColor = _backgroundColor; + } + + return Semantics( + explicitChildNodes: true, + child: _Bar( + layout: layout, + elevation: widget.elevation ?? bottomTheme.elevation ?? 8.0, + color: backgroundColor, + child: ConstrainedBox( + constraints: BoxConstraints(minHeight: kBottomNavigationBarHeight + additionalBottomPadding), + child: CustomPaint( + painter: _RadialPainter( + circles: _circles.toList(), + textDirection: Directionality.of(context), + ), + child: Material( // Splashes. + type: MaterialType.transparency, + child: Padding( + padding: EdgeInsets.only(bottom: additionalBottomPadding), + child: MediaQuery.removePadding( + context: context, + removeBottom: true, + child: DefaultTextStyle.merge( + overflow: TextOverflow.ellipsis, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: _createTiles(layout), + ), + ), + ), + ), + ), + ), + ), + ), + ); + } +} + +// Optionally center a Material child for landscape layouts when layout is +// BottomNavigationBarLandscapeLayout.centered +class _Bar extends StatelessWidget { + const _Bar({ + required this.child, + required this.layout, + required this.elevation, + required this.color, + }); + + final Widget child; + final BottomNavigationBarLandscapeLayout layout; + final double elevation; + final Color? color; + + @override + Widget build(BuildContext context) { + Widget alignedChild = child; + if (MediaQuery.orientationOf(context) == Orientation.landscape && layout == BottomNavigationBarLandscapeLayout.centered) { + alignedChild = Align( + alignment: Alignment.bottomCenter, + heightFactor: 1, + child: SizedBox( + width: MediaQuery.sizeOf(context).height, + child: child, + ), + ); + } + return Material( + elevation: elevation, + color: color, + child: alignedChild, + ); + } +} + +// Describes an animating color splash circle. +class _Circle { + _Circle({ + required this.state, + required this.index, + required this.color, + required TickerProvider vsync, + }) { + controller = AnimationController( + duration: kThemeAnimationDuration, + vsync: vsync, + ); + animation = CurvedAnimation( + parent: controller, + curve: Curves.fastOutSlowIn, + ); + controller.forward(); + } + + final _BottomNavigationBarState state; + final int index; + final Color color; + late AnimationController controller; + late CurvedAnimation animation; + + double get horizontalLeadingOffset { + double weightSum(Iterable<Animation<double>> animations) { + // We're adding flex values instead of animation values to produce correct + // ratios. + return animations.map<double>(state._evaluateFlex).fold<double>(0.0, (double sum, double value) => sum + value); + } + + final double allWeights = weightSum(state._animations); + // These weights sum to the start edge of the indexed item. + final double leadingWeights = weightSum(state._animations.sublist(0, index)); + + // Add half of its flex value in order to get to the center. + return (leadingWeights + state._evaluateFlex(state._animations[index]) / 2.0) / allWeights; + } + + void dispose() { + controller.dispose(); + } +} + +// Paints the animating color splash circles. +class _RadialPainter extends CustomPainter { + _RadialPainter({ + required this.circles, + required this.textDirection, + }); + + final List<_Circle> circles; + final TextDirection textDirection; + + // Computes the maximum radius attainable such that at least one of the + // bounding rectangle's corners touches the edge of the circle. Drawing a + // circle larger than this radius is not needed, since there is no perceivable + // difference within the cropped rectangle. + static double _maxRadius(Offset center, Size size) { + final double maxX = math.max(center.dx, size.width - center.dx); + final double maxY = math.max(center.dy, size.height - center.dy); + return math.sqrt(maxX * maxX + maxY * maxY); + } + + @override + bool shouldRepaint(_RadialPainter oldPainter) { + if (textDirection != oldPainter.textDirection) { + return true; + } + if (circles == oldPainter.circles) { + return false; + } + if (circles.length != oldPainter.circles.length) { + return true; + } + for (int i = 0; i < circles.length; i += 1) { + if (circles[i] != oldPainter.circles[i]) { + return true; + } + } + return false; + } + + @override + void paint(Canvas canvas, Size size) { + for (final _Circle circle in circles) { + final Paint paint = Paint()..color = circle.color; + final Rect rect = Rect.fromLTWH(0.0, 0.0, size.width, size.height); + canvas.clipRect(rect); + final double leftFraction; + switch (textDirection) { + case TextDirection.rtl: + leftFraction = 1.0 - circle.horizontalLeadingOffset; + case TextDirection.ltr: + leftFraction = circle.horizontalLeadingOffset; + } + final Offset center = Offset(leftFraction * size.width, size.height / 2.0); + final Tween<double> radiusTween = Tween<double>( + begin: 0.0, + end: _maxRadius(center, size), + ); + canvas.drawCircle( + center, + radiusTween.transform(circle.animation.value), + paint, + ); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..d60fa6b016d8d679a6bd99fa3feaf0802b19894e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart @@ -0,0 +1,303 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'bottom_navigation_bar.dart'; +import 'material_state.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [BottomNavigationBar] +/// widgets. +/// +/// Descendant widgets obtain the current [BottomNavigationBarThemeData] object +/// using `BottomNavigationBarTheme.of(context)`. Instances of +/// [BottomNavigationBarThemeData] can be customized with +/// [BottomNavigationBarThemeData.copyWith]. +/// +/// Typically a [BottomNavigationBarThemeData] is specified as part of the +/// overall [Theme] with [ThemeData.bottomNavigationBarTheme]. +/// +/// All [BottomNavigationBarThemeData] properties are `null` by default. When +/// null, the [BottomNavigationBar]'s build method provides defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class BottomNavigationBarThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.bottomNavigationBarTheme]. + const BottomNavigationBarThemeData({ + this.backgroundColor, + this.elevation, + this.selectedIconTheme, + this.unselectedIconTheme, + this.selectedItemColor, + this.unselectedItemColor, + this.selectedLabelStyle, + this.unselectedLabelStyle, + this.showSelectedLabels, + this.showUnselectedLabels, + this.type, + this.enableFeedback, + this.landscapeLayout, + this.mouseCursor, + }); + + /// The color of the [BottomNavigationBar] itself. + /// + /// See [BottomNavigationBar.backgroundColor]. + final Color? backgroundColor; + + /// The z-coordinate of the [BottomNavigationBar]. + /// + /// See [BottomNavigationBar.elevation]. + final double? elevation; + + /// The size, opacity, and color of the icon in the currently selected + /// [BottomNavigationBarItem.icon]. + /// + /// If [BottomNavigationBar.selectedIconTheme] is non-null on the widget, + /// the whole [IconThemeData] from the widget will be used over this + /// [selectedIconTheme]. + /// + /// See [BottomNavigationBar.selectedIconTheme]. + final IconThemeData? selectedIconTheme; + + /// The size, opacity, and color of the icon in the currently unselected + /// [BottomNavigationBarItem.icon]s. + /// + /// If [BottomNavigationBar.unselectedIconTheme] is non-null on the widget, + /// the whole [IconThemeData] from the widget will be used over this + /// [unselectedIconTheme]. + /// + /// See [BottomNavigationBar.unselectedIconTheme]. + final IconThemeData? unselectedIconTheme; + + /// The color of the selected [BottomNavigationBarItem.icon] and + /// [BottomNavigationBarItem.label]. + /// + /// See [BottomNavigationBar.selectedItemColor]. + final Color? selectedItemColor; + + /// The color of the unselected [BottomNavigationBarItem.icon] and + /// [BottomNavigationBarItem.label]s. + /// + /// See [BottomNavigationBar.unselectedItemColor]. + final Color? unselectedItemColor; + + /// The [TextStyle] of the [BottomNavigationBarItem] labels when they are + /// selected. + /// + /// See [BottomNavigationBar.selectedLabelStyle]. + final TextStyle? selectedLabelStyle; + + /// The [TextStyle] of the [BottomNavigationBarItem] labels when they are not + /// selected. + /// + /// See [BottomNavigationBar.unselectedLabelStyle]. + final TextStyle? unselectedLabelStyle; + + /// Whether the labels are shown for the selected [BottomNavigationBarItem]. + /// + /// See [BottomNavigationBar.showSelectedLabels]. + final bool? showSelectedLabels; + + /// Whether the labels are shown for the unselected [BottomNavigationBarItem]s. + /// + /// See [BottomNavigationBar.showUnselectedLabels]. + final bool? showUnselectedLabels; + + /// Defines the layout and behavior of a [BottomNavigationBar]. + /// + /// See [BottomNavigationBar.type]. + final BottomNavigationBarType? type; + + /// If specified, defines the feedback property for [BottomNavigationBar]. + /// + /// If [BottomNavigationBar.enableFeedback] is provided, [enableFeedback] is ignored. + final bool? enableFeedback; + + /// If non-null, overrides the [BottomNavigationBar.landscapeLayout] property. + final BottomNavigationBarLandscapeLayout? landscapeLayout; + + /// If specified, overrides the default value of [BottomNavigationBar.mouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + BottomNavigationBarThemeData copyWith({ + Color? backgroundColor, + double? elevation, + IconThemeData? selectedIconTheme, + IconThemeData? unselectedIconTheme, + Color? selectedItemColor, + Color? unselectedItemColor, + TextStyle? selectedLabelStyle, + TextStyle? unselectedLabelStyle, + bool? showSelectedLabels, + bool? showUnselectedLabels, + BottomNavigationBarType? type, + bool? enableFeedback, + BottomNavigationBarLandscapeLayout? landscapeLayout, + MaterialStateProperty<MouseCursor?>? mouseCursor, + }) { + return BottomNavigationBarThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + elevation: elevation ?? this.elevation, + selectedIconTheme: selectedIconTheme ?? this.selectedIconTheme, + unselectedIconTheme: unselectedIconTheme ?? this.unselectedIconTheme, + selectedItemColor: selectedItemColor ?? this.selectedItemColor, + unselectedItemColor: unselectedItemColor ?? this.unselectedItemColor, + selectedLabelStyle: selectedLabelStyle ?? this.selectedLabelStyle, + unselectedLabelStyle: unselectedLabelStyle ?? this.unselectedLabelStyle, + showSelectedLabels: showSelectedLabels ?? this.showSelectedLabels, + showUnselectedLabels: showUnselectedLabels ?? this.showUnselectedLabels, + type: type ?? this.type, + enableFeedback: enableFeedback ?? this.enableFeedback, + landscapeLayout: landscapeLayout ?? this.landscapeLayout, + mouseCursor: mouseCursor ?? this.mouseCursor, + ); + } + + /// Linearly interpolate between two [BottomNavigationBarThemeData]. + /// + /// {@macro dart.ui.shadow.lerp} + static BottomNavigationBarThemeData lerp(BottomNavigationBarThemeData? a, BottomNavigationBarThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return BottomNavigationBarThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + selectedIconTheme: IconThemeData.lerp(a?.selectedIconTheme, b?.selectedIconTheme, t), + unselectedIconTheme: IconThemeData.lerp(a?.unselectedIconTheme, b?.unselectedIconTheme, t), + selectedItemColor: Color.lerp(a?.selectedItemColor, b?.selectedItemColor, t), + unselectedItemColor: Color.lerp(a?.unselectedItemColor, b?.unselectedItemColor, t), + selectedLabelStyle: TextStyle.lerp(a?.selectedLabelStyle, b?.selectedLabelStyle, t), + unselectedLabelStyle: TextStyle.lerp(a?.unselectedLabelStyle, b?.unselectedLabelStyle, t), + showSelectedLabels: t < 0.5 ? a?.showSelectedLabels : b?.showSelectedLabels, + showUnselectedLabels: t < 0.5 ? a?.showUnselectedLabels : b?.showUnselectedLabels, + type: t < 0.5 ? a?.type : b?.type, + enableFeedback: t < 0.5 ? a?.enableFeedback : b?.enableFeedback, + landscapeLayout: t < 0.5 ? a?.landscapeLayout : b?.landscapeLayout, + mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, + ); + } + + @override + int get hashCode => Object.hash( + backgroundColor, + elevation, + selectedIconTheme, + unselectedIconTheme, + selectedItemColor, + unselectedItemColor, + selectedLabelStyle, + unselectedLabelStyle, + showSelectedLabels, + showUnselectedLabels, + type, + enableFeedback, + landscapeLayout, + mouseCursor, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is BottomNavigationBarThemeData + && other.backgroundColor == backgroundColor + && other.elevation == elevation + && other.selectedIconTheme == selectedIconTheme + && other.unselectedIconTheme == unselectedIconTheme + && other.selectedItemColor == selectedItemColor + && other.unselectedItemColor == unselectedItemColor + && other.selectedLabelStyle == selectedLabelStyle + && other.unselectedLabelStyle == unselectedLabelStyle + && other.showSelectedLabels == showSelectedLabels + && other.showUnselectedLabels == showUnselectedLabels + && other.type == type + && other.enableFeedback == enableFeedback + && other.landscapeLayout == landscapeLayout + && other.mouseCursor == mouseCursor; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(DiagnosticsProperty<IconThemeData>('selectedIconTheme', selectedIconTheme, defaultValue: null)); + properties.add(DiagnosticsProperty<IconThemeData>('unselectedIconTheme', unselectedIconTheme, defaultValue: null)); + properties.add(ColorProperty('selectedItemColor', selectedItemColor, defaultValue: null)); + properties.add(ColorProperty('unselectedItemColor', unselectedItemColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('selectedLabelStyle', selectedLabelStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('unselectedLabelStyle', unselectedLabelStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('showSelectedLabels', showSelectedLabels, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('showUnselectedLabels', showUnselectedLabels, defaultValue: null)); + properties.add(DiagnosticsProperty<BottomNavigationBarType>('type', type, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('enableFeedback', enableFeedback, defaultValue: null)); + properties.add(DiagnosticsProperty<BottomNavigationBarLandscapeLayout>('landscapeLayout', landscapeLayout, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null)); + } +} + +/// Applies a bottom navigation bar theme to descendant [BottomNavigationBar] +/// widgets. +/// +/// Descendant widgets obtain the current theme's [BottomNavigationBarTheme] +/// object using [BottomNavigationBarTheme.of]. When a widget uses +/// [BottomNavigationBarTheme.of], it is automatically rebuilt if the theme +/// later changes. +/// +/// A bottom navigation theme can be specified as part of the overall Material +/// theme using [ThemeData.bottomNavigationBarTheme]. +/// +/// See also: +/// +/// * [BottomNavigationBarThemeData], which describes the actual configuration +/// of a bottom navigation bar theme. +class BottomNavigationBarTheme extends InheritedWidget { + /// Constructs a bottom navigation bar theme that configures all descendant + /// [BottomNavigationBar] widgets. + const BottomNavigationBarTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties used for all descendant [BottomNavigationBar] widgets. + final BottomNavigationBarThemeData data; + + /// Returns the configuration [data] from the closest + /// [BottomNavigationBarTheme] ancestor. If there is no ancestor, it returns + /// [ThemeData.bottomNavigationBarTheme]. Applications can assume that the + /// returned value will not be null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// BottomNavigationBarThemeData theme = BottomNavigationBarTheme.of(context); + /// ``` + static BottomNavigationBarThemeData of(BuildContext context) { + final BottomNavigationBarTheme? bottomNavTheme = context.dependOnInheritedWidgetOfExactType<BottomNavigationBarTheme>(); + return bottomNavTheme?.data ?? Theme.of(context).bottomNavigationBarTheme; + } + + @override + bool updateShouldNotify(BottomNavigationBarTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_sheet.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_sheet.dart new file mode 100644 index 0000000000000000000000000000000000000000..6e4f2f9ab773790e063d676c9a646e38da1e84f7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_sheet.dart @@ -0,0 +1,1424 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'bottom_sheet_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'curves.dart'; +import 'debug.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'scaffold.dart'; +import 'theme.dart'; + +const Duration _bottomSheetEnterDuration = Duration(milliseconds: 250); +const Duration _bottomSheetExitDuration = Duration(milliseconds: 200); +const Curve _modalBottomSheetCurve = decelerateEasing; +const double _minFlingVelocity = 700.0; +const double _closeProgressThreshold = 0.5; +const double _defaultScrollControlDisabledMaxHeightRatio = 9.0 / 16.0; + +/// A callback for when the user begins dragging the bottom sheet. +/// +/// Used by [BottomSheet.onDragStart]. +typedef BottomSheetDragStartHandler = void Function(DragStartDetails details); + +/// A callback for when the user stops dragging the bottom sheet. +/// +/// Used by [BottomSheet.onDragEnd]. +typedef BottomSheetDragEndHandler = void Function( + DragEndDetails details, { + required bool isClosing, +}); + +/// A Material Design bottom sheet. +/// +/// There are two kinds of bottom sheets in Material Design: +/// +/// * _Persistent_. A persistent bottom sheet shows information that +/// supplements the primary content of the app. A persistent bottom sheet +/// remains visible even when the user interacts with other parts of the app. +/// Persistent bottom sheets can be created and displayed with the +/// [ScaffoldState.showBottomSheet] function or by specifying the +/// [Scaffold.bottomSheet] constructor parameter. +/// +/// * _Modal_. A modal bottom sheet is an alternative to a menu or a dialog and +/// prevents the user from interacting with the rest of the app. Modal bottom +/// sheets can be created and displayed with the [showModalBottomSheet] +/// function. +/// +/// The [BottomSheet] widget itself is rarely used directly. Instead, prefer to +/// create a persistent bottom sheet with [ScaffoldState.showBottomSheet] or +/// [Scaffold.bottomSheet], and a modal bottom sheet with [showModalBottomSheet]. +/// +/// See also: +/// +/// * [showBottomSheet] and [ScaffoldState.showBottomSheet], for showing +/// non-modal "persistent" bottom sheets. +/// * [showModalBottomSheet], which can be used to display a modal bottom +/// sheet. +/// * [BottomSheetThemeData], which can be used to customize the default +/// bottom sheet property values. +/// * The Material 2 spec at <https://m2.material.io/components/sheets-bottom>. +/// * The Material 3 spec at <https://m3.material.io/components/bottom-sheets/overview>. +class BottomSheet extends StatefulWidget { + /// Creates a bottom sheet. + /// + /// Typically, bottom sheets are created implicitly by + /// [ScaffoldState.showBottomSheet], for persistent bottom sheets, or by + /// [showModalBottomSheet], for modal bottom sheets. + const BottomSheet({ + super.key, + this.animationController, + this.enableDrag = true, + this.showDragHandle, + this.dragHandleColor, + this.dragHandleSize, + this.onDragStart, + this.onDragEnd, + this.backgroundColor, + this.shadowColor, + this.elevation, + this.shape, + this.clipBehavior, + this.constraints, + required this.onClosing, + required this.builder, + }) : assert(elevation == null || elevation >= 0.0); + + /// The animation controller that controls the bottom sheet's entrance and + /// exit animations. + /// + /// The BottomSheet widget will manipulate the position of this animation, it + /// is not just a passive observer. + final AnimationController? animationController; + + /// Called when the bottom sheet begins to close. + /// + /// A bottom sheet might be prevented from closing (e.g., by user + /// interaction) even after this callback is called. For this reason, this + /// callback might be call multiple times for a given bottom sheet. + final VoidCallback onClosing; + + /// A builder for the contents of the sheet. + /// + /// The bottom sheet will wrap the widget produced by this builder in a + /// [Material] widget. + final WidgetBuilder builder; + + /// If true, the bottom sheet can be dragged up and down and dismissed by + /// swiping downwards. + /// + /// If [showDragHandle] is true, this only applies to the content below the drag handle, + /// because the drag handle is always draggable. + /// + /// Default is true. + /// + /// If this is true, the [animationController] must not be null. + /// Use [BottomSheet.createAnimationController] to create one, or provide + /// another AnimationController. + final bool enableDrag; + + /// Specifies whether a drag handle is shown. + /// + /// The drag handle appears at the top of the bottom sheet. The default color is + /// [ColorScheme.onSurfaceVariant] with an opacity of 0.4 and can be customized + /// using [dragHandleColor]. The default size is `Size(32,4)` and can be customized + /// with [dragHandleSize]. + /// + /// If null, then the value of [BottomSheetThemeData.showDragHandle] is used. If + /// that is also null, defaults to false. + /// + /// If this is true, the [animationController] must not be null. + /// Use [BottomSheet.createAnimationController] to create one, or provide + /// another AnimationController. + final bool? showDragHandle; + + /// The bottom sheet drag handle's color. + /// + /// Defaults to [BottomSheetThemeData.dragHandleColor]. + /// If that is also null, defaults to [ColorScheme.onSurfaceVariant] + /// with an opacity of 0.4. + final Color? dragHandleColor; + + /// Defaults to [BottomSheetThemeData.dragHandleSize]. + /// If that is also null, defaults to Size(32, 4). + final Size? dragHandleSize; + + /// Called when the user begins dragging the bottom sheet vertically, if + /// [enableDrag] is true. + /// + /// Would typically be used to change the bottom sheet animation curve so + /// that it tracks the user's finger accurately. + final BottomSheetDragStartHandler? onDragStart; + + /// Called when the user stops dragging the bottom sheet, if [enableDrag] + /// is true. + /// + /// Would typically be used to reset the bottom sheet animation curve, so + /// that it animates non-linearly. Called before [onClosing] if the bottom + /// sheet is closing. + final BottomSheetDragEndHandler? onDragEnd; + + /// The bottom sheet's background color. + /// + /// Defines the bottom sheet's [Material.color]. + /// + /// Defaults to null and falls back to [Material]'s default. + final Color? backgroundColor; + + /// The color of the shadow below the sheet. + /// + /// If this property is null, then [BottomSheetThemeData.shadowColor] of + /// [ThemeData.bottomSheetTheme] is used. If that is also null, the default value + /// is transparent. + /// + /// See also: + /// + /// * [elevation], which defines the size of the shadow below the sheet. + /// * [shape], which defines the shape of the sheet and its shadow. + final Color? shadowColor; + + /// The z-coordinate at which to place this material relative to its parent. + /// + /// This controls the size of the shadow below the material. + /// + /// Defaults to 0. The value is non-negative. + final double? elevation; + + /// The shape of the bottom sheet. + /// + /// Defines the bottom sheet's [Material.shape]. + /// + /// Defaults to null and falls back to [Material]'s default. + final ShapeBorder? shape; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defines the bottom sheet's [Material.clipBehavior]. + /// + /// Use this property to enable clipping of content when the bottom sheet has + /// a custom [shape] and the content can extend past this shape. For example, + /// a bottom sheet with rounded corners and an edge-to-edge [Image] at the + /// top. + /// + /// If this property is null then [BottomSheetThemeData.clipBehavior] of + /// [ThemeData.bottomSheetTheme] is used. If that's null then the behavior + /// will be [Clip.none]. + final Clip? clipBehavior; + + /// Defines minimum and maximum sizes for a [BottomSheet]. + /// + /// If null, then the ambient [ThemeData.bottomSheetTheme]'s + /// [BottomSheetThemeData.constraints] will be used. If that + /// is null and [ThemeData.useMaterial3] is true, then the bottom sheet + /// will have a max width of 640dp. If [ThemeData.useMaterial3] is false, then + /// the bottom sheet's size will be constrained by its parent + /// (usually a [Scaffold]). In this case, consider limiting the width by + /// setting smaller constraints for large screens. + /// + /// If constraints are specified (either in this property or in the + /// theme), the bottom sheet will be aligned to the bottom-center of + /// the available space. Otherwise, no alignment is applied. + final BoxConstraints? constraints; + + @override + State<BottomSheet> createState() => _BottomSheetState(); + + /// Creates an [AnimationController] suitable for a + /// [BottomSheet.animationController]. + /// + /// This API available as a convenience for a Material compliant bottom sheet + /// animation. If alternative animation durations are required, a different + /// animation controller could be provided. + static AnimationController createAnimationController(TickerProvider vsync) { + return AnimationController( + duration: _bottomSheetEnterDuration, + reverseDuration: _bottomSheetExitDuration, + debugLabel: 'BottomSheet', + vsync: vsync, + ); + } +} + +class _BottomSheetState extends State<BottomSheet> { + + final GlobalKey _childKey = GlobalKey(debugLabel: 'BottomSheet child'); + + double get _childHeight { + final RenderBox renderBox = _childKey.currentContext!.findRenderObject()! as RenderBox; + return renderBox.size.height; + } + + bool get _dismissUnderway => widget.animationController!.status == AnimationStatus.reverse; + + Set<MaterialState> dragHandleMaterialState = <MaterialState>{}; + + void _handleDragStart(DragStartDetails details) { + setState(() { + dragHandleMaterialState.add(MaterialState.dragged); + }); + widget.onDragStart?.call(details); + } + + void _handleDragUpdate(DragUpdateDetails details) { + assert( + (widget.enableDrag || (widget.showDragHandle?? false)) && widget.animationController != null, + "'BottomSheet.animationController' cannot be null when 'BottomSheet.enableDrag' or 'BottomSheet.showDragHandle' is true. " + "Use 'BottomSheet.createAnimationController' to create one, or provide another AnimationController.", + ); + if (_dismissUnderway) { + return; + } + widget.animationController!.value -= details.primaryDelta! / _childHeight; + } + + void _handleDragEnd(DragEndDetails details) { + assert( + (widget.enableDrag || (widget.showDragHandle?? false)) && widget.animationController != null, + "'BottomSheet.animationController' cannot be null when 'BottomSheet.enableDrag' or 'BottomSheet.showDragHandle' is true. " + "Use 'BottomSheet.createAnimationController' to create one, or provide another AnimationController.", + ); + if (_dismissUnderway) { + return; + } + setState(() { + dragHandleMaterialState.remove(MaterialState.dragged); + }); + bool isClosing = false; + if (details.velocity.pixelsPerSecond.dy > _minFlingVelocity) { + final double flingVelocity = -details.velocity.pixelsPerSecond.dy / _childHeight; + if (widget.animationController!.value > 0.0) { + widget.animationController!.fling(velocity: flingVelocity); + } + if (flingVelocity < 0.0) { + isClosing = true; + } + } else if (widget.animationController!.value < _closeProgressThreshold) { + if (widget.animationController!.value > 0.0) { + widget.animationController!.fling(velocity: -1.0); + } + isClosing = true; + } else { + widget.animationController!.forward(); + } + + widget.onDragEnd?.call( + details, + isClosing: isClosing, + ); + + if (isClosing) { + widget.onClosing(); + } + } + + bool extentChanged(DraggableScrollableNotification notification) { + if (notification.extent == notification.minExtent && notification.shouldCloseOnMinExtent) { + widget.onClosing(); + } + return false; + } + + void _handleDragHandleHover(bool hovering) { + if (hovering != dragHandleMaterialState.contains(MaterialState.hovered)) { + setState(() { + if (hovering){ + dragHandleMaterialState.add(MaterialState.hovered); + } + else{ + dragHandleMaterialState.remove(MaterialState.hovered); + } + }); + } + } + + @override + Widget build(BuildContext context) { + final BottomSheetThemeData bottomSheetTheme = Theme.of(context).bottomSheetTheme; + final bool useMaterial3 = Theme.of(context).useMaterial3; + final BottomSheetThemeData defaults = useMaterial3 ? _BottomSheetDefaultsM3(context) : const BottomSheetThemeData(); + final BoxConstraints? constraints = widget.constraints ?? bottomSheetTheme.constraints ?? defaults.constraints; + final Color? color = widget.backgroundColor ?? bottomSheetTheme.backgroundColor ?? defaults.backgroundColor; + final Color? surfaceTintColor = bottomSheetTheme.surfaceTintColor ?? defaults.surfaceTintColor; + final Color? shadowColor = widget.shadowColor ?? bottomSheetTheme.shadowColor ?? defaults.shadowColor; + final double elevation = widget.elevation ?? bottomSheetTheme.elevation ?? defaults.elevation ?? 0; + final ShapeBorder? shape = widget.shape ?? bottomSheetTheme.shape ?? defaults.shape; + final Clip clipBehavior = widget.clipBehavior ?? bottomSheetTheme.clipBehavior ?? Clip.none; + final bool showDragHandle = widget.showDragHandle ?? (widget.enableDrag && (bottomSheetTheme.showDragHandle ?? false)); + + Widget? dragHandle; + if (showDragHandle){ + dragHandle = _DragHandle( + onSemanticsTap: widget.onClosing, + handleHover: _handleDragHandleHover, + materialState: dragHandleMaterialState, + dragHandleColor: widget.dragHandleColor, + dragHandleSize: widget.dragHandleSize, + ); + // Only add [_BottomSheetGestureDetector] to the drag handle when the rest of the + // bottom sheet is not draggable. If the whole bottom sheet is draggable, + // no need to add it. + if (!widget.enableDrag) { + dragHandle = _BottomSheetGestureDetector( + onVerticalDragStart: _handleDragStart, + onVerticalDragUpdate: _handleDragUpdate, + onVerticalDragEnd: _handleDragEnd, + child: dragHandle, + ); + } + } + + Widget bottomSheet = Material( + key: _childKey, + color: color, + elevation: elevation, + surfaceTintColor: surfaceTintColor, + shadowColor: shadowColor, + shape: shape, + clipBehavior: clipBehavior, + child: NotificationListener<DraggableScrollableNotification>( + onNotification: extentChanged, + child: !showDragHandle + ? widget.builder(context) + : Stack( + alignment: Alignment.topCenter, + children: <Widget>[ + dragHandle!, + Padding( + padding: const EdgeInsets.only(top: kMinInteractiveDimension), + child: widget.builder(context), + ), + ], + ), + ), + ); + + if (constraints != null) { + bottomSheet = Align( + alignment: Alignment.bottomCenter, + heightFactor: 1.0, + child: ConstrainedBox( + constraints: constraints, + child: bottomSheet, + ), + ); + } + + return !widget.enableDrag ? bottomSheet : _BottomSheetGestureDetector( + onVerticalDragStart: _handleDragStart, + onVerticalDragUpdate: _handleDragUpdate, + onVerticalDragEnd: _handleDragEnd, + child: bottomSheet, + ); + } +} + +// PERSISTENT BOTTOM SHEETS + +// See scaffold.dart + +typedef _SizeChangeCallback<Size> = void Function(Size size); + +class _DragHandle extends StatelessWidget { + const _DragHandle({ + required this.onSemanticsTap, + required this.handleHover, + required this.materialState, + this.dragHandleColor, + this.dragHandleSize, + }); + + final VoidCallback? onSemanticsTap; + final ValueChanged<bool> handleHover; + final Set<MaterialState> materialState; + final Color? dragHandleColor; + final Size? dragHandleSize; + + @override + Widget build(BuildContext context) { + final BottomSheetThemeData bottomSheetTheme = Theme.of(context).bottomSheetTheme; + final BottomSheetThemeData m3Defaults = _BottomSheetDefaultsM3(context); + final Size handleSize = dragHandleSize ?? bottomSheetTheme.dragHandleSize ?? m3Defaults.dragHandleSize!; + + return MouseRegion( + onEnter: (PointerEnterEvent event) => handleHover(true), + onExit: (PointerExitEvent event) => handleHover(false), + child: Semantics( + label: MaterialLocalizations.of(context).modalBarrierDismissLabel, + container: true, + onTap: onSemanticsTap, + child: SizedBox( + height: kMinInteractiveDimension, + width: kMinInteractiveDimension, + child: Center( + child: Container( + height: handleSize.height, + width: handleSize.width, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(handleSize.height/2), + color: MaterialStateProperty.resolveAs<Color?>(dragHandleColor, materialState) + ?? MaterialStateProperty.resolveAs<Color?>(bottomSheetTheme.dragHandleColor, materialState) + ?? m3Defaults.dragHandleColor, + ), + ), + ), + ), + ), + ); + } +} + +class _BottomSheetLayoutWithSizeListener extends SingleChildRenderObjectWidget { + const _BottomSheetLayoutWithSizeListener({ + required this.onChildSizeChanged, + required this.animationValue, + required this.isScrollControlled, + required this.scrollControlDisabledMaxHeightRatio, + super.child, + }); + + final _SizeChangeCallback<Size> onChildSizeChanged; + final double animationValue; + final bool isScrollControlled; + final double scrollControlDisabledMaxHeightRatio; + + @override + _RenderBottomSheetLayoutWithSizeListener createRenderObject(BuildContext context) { + return _RenderBottomSheetLayoutWithSizeListener( + onChildSizeChanged: onChildSizeChanged, + animationValue: animationValue, + isScrollControlled: isScrollControlled, + scrollControlDisabledMaxHeightRatio: scrollControlDisabledMaxHeightRatio, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderBottomSheetLayoutWithSizeListener renderObject) { + renderObject.onChildSizeChanged = onChildSizeChanged; + renderObject.animationValue = animationValue; + renderObject.isScrollControlled = isScrollControlled; + renderObject.scrollControlDisabledMaxHeightRatio = scrollControlDisabledMaxHeightRatio; + } +} + +class _RenderBottomSheetLayoutWithSizeListener extends RenderShiftedBox { + _RenderBottomSheetLayoutWithSizeListener({ + RenderBox? child, + required _SizeChangeCallback<Size> onChildSizeChanged, + required double animationValue, + required bool isScrollControlled, + required double scrollControlDisabledMaxHeightRatio, + }) : _onChildSizeChanged = onChildSizeChanged, + _animationValue = animationValue, + _isScrollControlled = isScrollControlled, + _scrollControlDisabledMaxHeightRatio = scrollControlDisabledMaxHeightRatio, + super(child); + + Size _lastSize = Size.zero; + + _SizeChangeCallback<Size> get onChildSizeChanged => _onChildSizeChanged; + _SizeChangeCallback<Size> _onChildSizeChanged; + set onChildSizeChanged(_SizeChangeCallback<Size> newCallback) { + if (_onChildSizeChanged == newCallback) { + return; + } + + _onChildSizeChanged = newCallback; + markNeedsLayout(); + } + + double get animationValue => _animationValue; + double _animationValue; + set animationValue(double newValue) { + if (_animationValue == newValue) { + return; + } + + _animationValue = newValue; + markNeedsLayout(); + } + + bool get isScrollControlled => _isScrollControlled; + bool _isScrollControlled; + set isScrollControlled(bool newValue) { + if (_isScrollControlled == newValue) { + return; + } + + _isScrollControlled = newValue; + markNeedsLayout(); + } + + double get scrollControlDisabledMaxHeightRatio => _scrollControlDisabledMaxHeightRatio; + double _scrollControlDisabledMaxHeightRatio; + set scrollControlDisabledMaxHeightRatio(double newValue) { + if (_scrollControlDisabledMaxHeightRatio == newValue) { + return; + } + + _scrollControlDisabledMaxHeightRatio = newValue; + markNeedsLayout(); + } + + Size _getSize(BoxConstraints constraints) { + return constraints.constrain(constraints.biggest); + } + + @override + double computeMinIntrinsicWidth(double height) { + final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width; + if (width.isFinite) { + return width; + } + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width; + if (width.isFinite) { + return width; + } + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height; + if (height.isFinite) { + return height; + } + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height; + if (height.isFinite) { + return height; + } + return 0.0; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return _getSize(constraints); + } + + BoxConstraints _getConstraintsForChild(BoxConstraints constraints) { + return BoxConstraints( + minWidth: constraints.maxWidth, + maxWidth: constraints.maxWidth, + maxHeight: isScrollControlled + ? constraints.maxHeight + : constraints.maxHeight * scrollControlDisabledMaxHeightRatio, + ); + } + + Offset _getPositionForChild(Size size, Size childSize) { + return Offset(0.0, size.height - childSize.height * animationValue); + } + + @override + void performLayout() { + size = _getSize(constraints); + if (child != null) { + final BoxConstraints childConstraints = _getConstraintsForChild(constraints); + assert(childConstraints.debugAssertIsValid(isAppliedConstraint: true)); + child!.layout(childConstraints, parentUsesSize: !childConstraints.isTight); + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = _getPositionForChild(size, childConstraints.isTight ? childConstraints.smallest : child!.size); + final Size childSize = childConstraints.isTight ? childConstraints.smallest : child!.size; + + if (_lastSize != childSize) { + _lastSize = childSize; + _onChildSizeChanged.call(_lastSize); + } + } + } +} + +class _ModalBottomSheet<T> extends StatefulWidget { + const _ModalBottomSheet({ + super.key, + required this.route, + this.backgroundColor, + this.elevation, + this.shape, + this.clipBehavior, + this.constraints, + this.isScrollControlled = false, + this.scrollControlDisabledMaxHeightRatio = _defaultScrollControlDisabledMaxHeightRatio, + this.enableDrag = true, + this.showDragHandle = false, + }); + + final ModalBottomSheetRoute<T> route; + final bool isScrollControlled; + final double scrollControlDisabledMaxHeightRatio; + final Color? backgroundColor; + final double? elevation; + final ShapeBorder? shape; + final Clip? clipBehavior; + final BoxConstraints? constraints; + final bool enableDrag; + final bool showDragHandle; + + @override + _ModalBottomSheetState<T> createState() => _ModalBottomSheetState<T>(); +} + +class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { + ParametricCurve<double> animationCurve = _modalBottomSheetCurve; + + String _getRouteLabel(MaterialLocalizations localizations) { + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return ''; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return localizations.dialogLabel; + } + } + + EdgeInsets _getNewClipDetails(Size topLayerSize) { + return EdgeInsets.fromLTRB(0, 0, 0, topLayerSize.height); + } + + void handleDragStart(DragStartDetails details) { + // Allow the bottom sheet to track the user's finger accurately. + animationCurve = Curves.linear; + } + + void handleDragEnd(DragEndDetails details, {bool? isClosing}) { + // Allow the bottom sheet to animate smoothly from its current position. + animationCurve = _BottomSheetSuspendedCurve( + widget.route.animation!.value, + curve: _modalBottomSheetCurve, + ); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + assert(debugCheckHasMaterialLocalizations(context)); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final String routeLabel = _getRouteLabel(localizations); + + return AnimatedBuilder( + animation: widget.route.animation!, + child: BottomSheet( + animationController: widget.route._animationController, + onClosing: () { + if (widget.route.isCurrent) { + Navigator.pop(context); + } + }, + builder: widget.route.builder, + backgroundColor: widget.backgroundColor, + elevation: widget.elevation, + shape: widget.shape, + clipBehavior: widget.clipBehavior, + constraints: widget.constraints, + enableDrag: widget.enableDrag, + showDragHandle: widget.showDragHandle, + onDragStart: handleDragStart, + onDragEnd: handleDragEnd, + ), + builder: (BuildContext context, Widget? child) { + final double animationValue = animationCurve.transform( + widget.route.animation!.value, + ); + return Semantics( + scopesRoute: true, + namesRoute: true, + label: routeLabel, + explicitChildNodes: true, + child: ClipRect( + child: _BottomSheetLayoutWithSizeListener( + onChildSizeChanged: (Size size) { + widget.route._didChangeBarrierSemanticsClip( + _getNewClipDetails(size), + ); + }, + animationValue: animationValue, + isScrollControlled: widget.isScrollControlled, + scrollControlDisabledMaxHeightRatio: widget.scrollControlDisabledMaxHeightRatio, + child: child, + ), + ), + ); + }, + ); + } +} + +/// A route that represents a Material Design modal bottom sheet. +/// +/// {@template flutter.material.ModalBottomSheetRoute} +/// A modal bottom sheet is an alternative to a menu or a dialog and prevents +/// the user from interacting with the rest of the app. +/// +/// A closely related widget is a persistent bottom sheet, which shows +/// information that supplements the primary content of the app without +/// preventing the user from interacting with the app. Persistent bottom sheets +/// can be created and displayed with the [showBottomSheet] function or the +/// [ScaffoldState.showBottomSheet] method. +/// +/// The [isScrollControlled] parameter specifies whether this is a route for +/// a bottom sheet that will utilize [DraggableScrollableSheet]. Consider +/// setting this parameter to true if this bottom sheet has +/// a scrollable child, such as a [ListView] or a [GridView], +/// to have the bottom sheet be draggable. +/// +/// The [isDismissible] parameter specifies whether the bottom sheet will be +/// dismissed when user taps on the scrim. +/// +/// The [enableDrag] parameter specifies whether the bottom sheet can be +/// dragged up and down and dismissed by swiping downwards. +/// +/// The [useSafeArea] parameter specifies whether the sheet will avoid system +/// intrusions on the top, left, and right. If false, no [SafeArea] is added; +/// and [MediaQuery.removePadding] is applied to the top, +/// so that system intrusions at the top will not be avoided by a [SafeArea] +/// inside the bottom sheet either. +/// Defaults to false. +/// +/// The optional [backgroundColor], [elevation], [shape], [clipBehavior], +/// [constraints] and [transitionAnimationController] +/// parameters can be passed in to customize the appearance and behavior of +/// modal bottom sheets (see the documentation for these on [BottomSheet] +/// for more details). +/// +/// The [transitionAnimationController] controls the bottom sheet's entrance and +/// exit animations. It's up to the owner of the controller to call +/// [AnimationController.dispose] when the controller is no longer needed. +/// +/// The optional `settings` parameter sets the [RouteSettings] of the modal bottom sheet +/// sheet. This is particularly useful in the case that a user wants to observe +/// [PopupRoute]s within a [NavigatorObserver]. +/// {@endtemplate} +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// See also: +/// +/// * [showModalBottomSheet], which is a way to display a ModalBottomSheetRoute. +/// * [BottomSheet], which becomes the parent of the widget returned by the +/// function passed as the `builder` argument to [showModalBottomSheet]. +/// * [showBottomSheet] and [ScaffoldState.showBottomSheet], for showing +/// non-modal bottom sheets. +/// * [DraggableScrollableSheet], creates a bottom sheet that grows +/// and then becomes scrollable once it reaches its maximum size. +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +/// * The Material 2 spec at <https://m2.material.io/components/sheets-bottom>. +/// * The Material 3 spec at <https://m3.material.io/components/bottom-sheets/overview>. +class ModalBottomSheetRoute<T> extends PopupRoute<T> { + /// A modal bottom sheet route. + ModalBottomSheetRoute({ + required this.builder, + this.capturedThemes, + this.barrierLabel, + this.barrierOnTapHint, + this.backgroundColor, + this.elevation, + this.shape, + this.clipBehavior, + this.constraints, + this.modalBarrierColor, + this.isDismissible = true, + this.enableDrag = true, + this.showDragHandle, + required this.isScrollControlled, + this.scrollControlDisabledMaxHeightRatio = _defaultScrollControlDisabledMaxHeightRatio, + super.settings, + this.transitionAnimationController, + this.anchorPoint, + this.useSafeArea = false, + }); + + /// A builder for the contents of the sheet. + /// + /// The bottom sheet will wrap the widget produced by this builder in a + /// [Material] widget. + final WidgetBuilder builder; + + /// Stores a list of captured [InheritedTheme]s that are wrapped around the + /// bottom sheet. + /// + /// Consider setting this attribute when the [ModalBottomSheetRoute] + /// is created through [Navigator.push] and its friends. + final CapturedThemes? capturedThemes; + + /// Specifies whether this is a route for a bottom sheet that will utilize + /// [DraggableScrollableSheet]. + /// + /// Consider setting this parameter to true if this bottom sheet has + /// a scrollable child, such as a [ListView] or a [GridView], + /// to have the bottom sheet be draggable. + final bool isScrollControlled; + + /// The max height constraint ratio for the bottom sheet + /// when [isScrollControlled] set to false, + /// no ratio will be applied when [isScrollControlled] set to true. + /// + /// Defaults to 9 / 16. + final double scrollControlDisabledMaxHeightRatio; + + /// The bottom sheet's background color. + /// + /// Defines the bottom sheet's [Material.color]. + /// + /// If this property is not provided, it falls back to [Material]'s default. + final Color? backgroundColor; + + /// The z-coordinate at which to place this material relative to its parent. + /// + /// This controls the size of the shadow below the material. + /// + /// Defaults to 0, must not be negative. + final double? elevation; + + /// The shape of the bottom sheet. + /// + /// Defines the bottom sheet's [Material.shape]. + /// + /// If this property is not provided, it falls back to [Material]'s default. + final ShapeBorder? shape; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defines the bottom sheet's [Material.clipBehavior]. + /// + /// Use this property to enable clipping of content when the bottom sheet has + /// a custom [shape] and the content can extend past this shape. For example, + /// a bottom sheet with rounded corners and an edge-to-edge [Image] at the + /// top. + /// + /// If this property is null, the [BottomSheetThemeData.clipBehavior] of + /// [ThemeData.bottomSheetTheme] is used. If that's null, the behavior defaults to [Clip.none] + /// will be [Clip.none]. + final Clip? clipBehavior; + + /// Defines minimum and maximum sizes for a [BottomSheet]. + /// + /// If null, the ambient [ThemeData.bottomSheetTheme]'s + /// [BottomSheetThemeData.constraints] will be used. If that + /// is null and [ThemeData.useMaterial3] is true, then the bottom sheet + /// will have a max width of 640dp. If [ThemeData.useMaterial3] is false, then + /// the bottom sheet's size will be constrained by its parent + /// (usually a [Scaffold]). In this case, consider limiting the width by + /// setting smaller constraints for large screens. + /// + /// If constraints are specified (either in this property or in the + /// theme), the bottom sheet will be aligned to the bottom-center of + /// the available space. Otherwise, no alignment is applied. + final BoxConstraints? constraints; + + /// Specifies the color of the modal barrier that darkens everything below the + /// bottom sheet. + /// + /// Defaults to `Colors.black54` if not provided. + final Color? modalBarrierColor; + + /// Specifies whether the bottom sheet will be dismissed + /// when user taps on the scrim. + /// + /// If true, the bottom sheet will be dismissed when user taps on the scrim. + /// + /// Defaults to true. + final bool isDismissible; + + /// Specifies whether the bottom sheet can be dragged up and down + /// and dismissed by swiping downwards. + /// + /// If true, the bottom sheet can be dragged up and down and dismissed by + /// swiping downwards. + /// + /// This applies to the content below the drag handle, if showDragHandle is true. + /// + /// Defaults is true. + final bool enableDrag; + + /// Specifies whether a drag handle is shown. + /// + /// The drag handle appears at the top of the bottom sheet. The default color is + /// [ColorScheme.onSurfaceVariant] with an opacity of 0.4 and can be customized + /// using dragHandleColor. The default size is `Size(32,4)` and can be customized + /// with dragHandleSize. + /// + /// If null, then the value of [BottomSheetThemeData.showDragHandle] is used. If + /// that is also null, defaults to false. + final bool? showDragHandle; + + /// The animation controller that controls the bottom sheet's entrance and + /// exit animations. + /// + /// The BottomSheet widget will manipulate the position of this animation, it + /// is not just a passive observer. + final AnimationController? transitionAnimationController; + + /// {@macro flutter.widgets.DisplayFeatureSubScreen.anchorPoint} + final Offset? anchorPoint; + + /// Whether to avoid system intrusions on the top, left, and right. + /// + /// If true, a [SafeArea] is inserted to keep the bottom sheet away from + /// system intrusions at the top, left, and right sides of the screen. + /// + /// If false, the bottom sheet will extend through any system intrusions + /// at the top, left, and right. + /// + /// If false, then moreover [MediaQuery.removePadding] will be used + /// to remove top padding, so that a [SafeArea] widget inside the bottom + /// sheet will have no effect at the top edge. If this is undesired, consider + /// setting [useSafeArea] to true. Alternatively, wrap the [SafeArea] in a + /// [MediaQuery] that restates an ambient [MediaQueryData] from outside [builder]. + /// + /// In either case, the bottom sheet extends all the way to the bottom of + /// the screen, including any system intrusions. + /// + /// The default is false. + final bool useSafeArea; + + /// {@template flutter.material.ModalBottomSheetRoute.barrierOnTapHint} + /// The semantic hint text that informs users what will happen if they + /// tap on the widget. Announced in the format of 'Double tap to ...'. + /// + /// If the field is null, the default hint will be used, which results in + /// announcement of 'Double tap to activate'. + /// {@endtemplate} + /// + /// See also: + /// + /// * [barrierDismissible], which controls the behavior of the barrier when + /// tapped. + /// * [ModalBarrier], which uses this field as onTapHint when it has an onTap action. + final String? barrierOnTapHint; + + final ValueNotifier<EdgeInsets> _clipDetailsNotifier = ValueNotifier<EdgeInsets>(EdgeInsets.zero); + + @override + void dispose() { + _clipDetailsNotifier.dispose(); + super.dispose(); + } + + /// Updates the details regarding how the [SemanticsNode.rect] (focus) of + /// the barrier for this [ModalBottomSheetRoute] should be clipped. + /// + /// returns true if the clipDetails did change and false otherwise. + bool _didChangeBarrierSemanticsClip(EdgeInsets newClipDetails) { + if (_clipDetailsNotifier.value == newClipDetails) { + return false; + } + _clipDetailsNotifier.value = newClipDetails; + return true; + } + + @override + Duration get transitionDuration => _bottomSheetEnterDuration; + + @override + Duration get reverseTransitionDuration => _bottomSheetExitDuration; + + @override + bool get barrierDismissible => isDismissible; + + @override + final String? barrierLabel; + + @override + Color get barrierColor => modalBarrierColor ?? Colors.black54; + + AnimationController? _animationController; + + @override + AnimationController createAnimationController() { + assert(_animationController == null); + if (transitionAnimationController != null) { + _animationController = transitionAnimationController; + willDisposeAnimationController = false; + } else { + _animationController = BottomSheet.createAnimationController(navigator!); + } + return _animationController!; + } + + @override + Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { + final Widget content = DisplayFeatureSubScreen( + anchorPoint: anchorPoint, + child: Builder( + builder: (BuildContext context) { + final BottomSheetThemeData sheetTheme = Theme.of(context).bottomSheetTheme; + final BottomSheetThemeData defaults = Theme.of(context).useMaterial3 ? _BottomSheetDefaultsM3(context) : const BottomSheetThemeData(); + return _ModalBottomSheet<T>( + route: this, + backgroundColor: backgroundColor ?? sheetTheme.modalBackgroundColor ?? sheetTheme.backgroundColor ?? defaults.backgroundColor, + elevation: elevation ?? sheetTheme.modalElevation ?? sheetTheme.elevation ?? defaults.modalElevation, + shape: shape, + clipBehavior: clipBehavior, + constraints: constraints, + isScrollControlled: isScrollControlled, + scrollControlDisabledMaxHeightRatio: scrollControlDisabledMaxHeightRatio, + enableDrag: enableDrag, + showDragHandle: showDragHandle ?? (enableDrag && (sheetTheme.showDragHandle ?? false)), + ); + }, + ), + ); + + final Widget bottomSheet = useSafeArea + ? SafeArea(bottom: false, child: content) + : MediaQuery.removePadding( + context: context, + removeTop: true, + child: content, + ); + + return capturedThemes?.wrap(bottomSheet) ?? bottomSheet; + } + + @override + Widget buildModalBarrier() { + if (barrierColor.alpha != 0 && !offstage) { // changedInternalState is called if barrierColor or offstage updates + assert(barrierColor != barrierColor.withOpacity(0.0)); + final Animation<Color?> color = animation!.drive( + ColorTween( + begin: barrierColor.withOpacity(0.0), + end: barrierColor, // changedInternalState is called if barrierColor updates + ).chain(CurveTween(curve: barrierCurve)), // changedInternalState is called if barrierCurve updates + ); + return AnimatedModalBarrier( + color: color, + dismissible: barrierDismissible, // changedInternalState is called if barrierDismissible updates + semanticsLabel: barrierLabel, // changedInternalState is called if barrierLabel updates + barrierSemanticsDismissible: semanticsDismissible, + clipDetailsNotifier: _clipDetailsNotifier, + semanticsOnTapHint: barrierOnTapHint, + ); + } else { + return ModalBarrier( + dismissible: barrierDismissible, // changedInternalState is called if barrierDismissible updates + semanticsLabel: barrierLabel, // changedInternalState is called if barrierLabel updates + barrierSemanticsDismissible: semanticsDismissible, + clipDetailsNotifier: _clipDetailsNotifier, + semanticsOnTapHint: barrierOnTapHint, + ); + } + } +} + +// TODO(guidezpl): Look into making this public. A copy of this class is in +// scaffold.dart, for now, https://github.com/flutter/flutter/issues/51627 +/// A curve that progresses linearly until a specified [startingPoint], at which +/// point [curve] will begin. Unlike [Interval], [curve] will not start at zero, +/// but will use [startingPoint] as the Y position. +/// +/// For example, if [startingPoint] is set to `0.5`, and [curve] is set to +/// [Curves.easeOut], then the bottom-left quarter of the curve will be a +/// straight line, and the top-right quarter will contain the entire contents of +/// [Curves.easeOut]. +/// +/// This is useful in situations where a widget must track the user's finger +/// (which requires a linear animation), and afterwards can be flung using a +/// curve specified with the [curve] argument, after the finger is released. In +/// such a case, the value of [startingPoint] would be the progress of the +/// animation at the time when the finger was released. +class _BottomSheetSuspendedCurve extends ParametricCurve<double> { + /// Creates a suspended curve. + const _BottomSheetSuspendedCurve( + this.startingPoint, { + this.curve = Curves.easeOutCubic, + }); + + /// The progress value at which [curve] should begin. + final double startingPoint; + + /// The curve to use when [startingPoint] is reached. + /// + /// This defaults to [Curves.easeOutCubic]. + final Curve curve; + + @override + double transform(double t) { + assert(t >= 0.0 && t <= 1.0); + assert(startingPoint >= 0.0 && startingPoint <= 1.0); + + if (t < startingPoint) { + return t; + } + + if (t == 1.0) { + return t; + } + + final double curveProgress = (t - startingPoint) / (1 - startingPoint); + final double transformed = curve.transform(curveProgress); + return lerpDouble(startingPoint, 1, transformed)!; + } + + @override + String toString() { + return '${describeIdentity(this)}($startingPoint, $curve)'; + } +} + +/// Shows a modal Material Design bottom sheet. +/// +/// {@macro flutter.material.ModalBottomSheetRoute} +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// The `context` argument is used to look up the [Navigator] and [Theme] for +/// the bottom sheet. It is only used when the method is called. Its +/// corresponding widget can be safely removed from the tree before the bottom +/// sheet is closed. +/// +/// The `useRootNavigator` parameter ensures that the root navigator is used to +/// display the [BottomSheet] when set to `true`. This is useful in the case +/// that a modal [BottomSheet] needs to be displayed above all other content +/// but the caller is inside another [Navigator]. +/// +/// Returns a `Future` that resolves to the value (if any) that was passed to +/// [Navigator.pop] when the modal bottom sheet was closed. +/// +/// The 'barrierLabel' parameter can be used to set a custom barrierlabel. +/// Will default to modalBarrierDismissLabel of context if not set. +/// +/// {@tool dartpad} +/// This example demonstrates how to use [showModalBottomSheet] to display a +/// bottom sheet that obscures the content behind it when a user taps a button. +/// It also demonstrates how to close the bottom sheet using the [Navigator] +/// when a user taps on a button inside the bottom sheet. +/// +/// ** See code in examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of [showModalBottomSheet], as described in: +/// https://m3.material.io/components/bottom-sheets/overview +/// +/// ** See code in examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [BottomSheet], which becomes the parent of the widget returned by the +/// function passed as the `builder` argument to [showModalBottomSheet]. +/// * [showBottomSheet] and [ScaffoldState.showBottomSheet], for showing +/// non-modal bottom sheets. +/// * [DraggableScrollableSheet], creates a bottom sheet that grows +/// and then becomes scrollable once it reaches its maximum size. +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +/// * The Material 2 spec at <https://m2.material.io/components/sheets-bottom>. +/// * The Material 3 spec at <https://m3.material.io/components/bottom-sheets/overview>. +Future<T?> showModalBottomSheet<T>({ + required BuildContext context, + required WidgetBuilder builder, + Color? backgroundColor, + String? barrierLabel, + double? elevation, + ShapeBorder? shape, + Clip? clipBehavior, + BoxConstraints? constraints, + Color? barrierColor, + bool isScrollControlled = false, + double scrollControlDisabledMaxHeightRatio = _defaultScrollControlDisabledMaxHeightRatio, + bool useRootNavigator = false, + bool isDismissible = true, + bool enableDrag = true, + bool? showDragHandle, + bool useSafeArea = false, + RouteSettings? routeSettings, + AnimationController? transitionAnimationController, + Offset? anchorPoint, +}) { + assert(debugCheckHasMediaQuery(context)); + assert(debugCheckHasMaterialLocalizations(context)); + + final NavigatorState navigator = Navigator.of(context, rootNavigator: useRootNavigator); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + return navigator.push(ModalBottomSheetRoute<T>( + builder: builder, + capturedThemes: InheritedTheme.capture(from: context, to: navigator.context), + isScrollControlled: isScrollControlled, + scrollControlDisabledMaxHeightRatio: scrollControlDisabledMaxHeightRatio, + barrierLabel: barrierLabel ?? localizations.scrimLabel, + barrierOnTapHint: localizations.scrimOnTapHint(localizations.bottomSheetLabel), + backgroundColor: backgroundColor, + elevation: elevation, + shape: shape, + clipBehavior: clipBehavior, + constraints: constraints, + isDismissible: isDismissible, + modalBarrierColor: barrierColor ?? Theme.of(context).bottomSheetTheme.modalBarrierColor, + enableDrag: enableDrag, + showDragHandle: showDragHandle, + settings: routeSettings, + transitionAnimationController: transitionAnimationController, + anchorPoint: anchorPoint, + useSafeArea: useSafeArea, + )); +} + +/// Shows a Material Design bottom sheet in the nearest [Scaffold] ancestor. To +/// show a persistent bottom sheet, use the [Scaffold.bottomSheet]. +/// +/// Returns a controller that can be used to close and otherwise manipulate the +/// bottom sheet. +/// +/// The optional [backgroundColor], [elevation], [shape], [clipBehavior], +/// [constraints] and [transitionAnimationController] +/// parameters can be passed in to customize the appearance and behavior of +/// persistent bottom sheets (see the documentation for these on [BottomSheet] +/// for more details). +/// +/// The [enableDrag] parameter specifies whether the bottom sheet can be +/// dragged up and down and dismissed by swiping downwards. +/// +/// To rebuild the bottom sheet (e.g. if it is stateful), call +/// [PersistentBottomSheetController.setState] on the controller returned by +/// this method. +/// +/// The new bottom sheet becomes a [LocalHistoryEntry] for the enclosing +/// [ModalRoute] and a back button is added to the app bar of the [Scaffold] +/// that closes the bottom sheet. +/// +/// To create a persistent bottom sheet that is not a [LocalHistoryEntry] and +/// does not add a back button to the enclosing Scaffold's app bar, use the +/// [Scaffold.bottomSheet] constructor parameter. +/// +/// A closely related widget is a modal bottom sheet, which is an alternative +/// to a menu or a dialog and prevents the user from interacting with the rest +/// of the app. Modal bottom sheets can be created and displayed with the +/// [showModalBottomSheet] function. +/// +/// The `context` argument is used to look up the [Scaffold] for the bottom +/// sheet. It is only used when the method is called. Its corresponding widget +/// can be safely removed from the tree before the bottom sheet is closed. +/// +/// See also: +/// +/// * [BottomSheet], which becomes the parent of the widget returned by the +/// `builder`. +/// * [showModalBottomSheet], which can be used to display a modal bottom +/// sheet. +/// * [Scaffold.of], for information about how to obtain the [BuildContext]. +/// * The Material 2 spec at <https://m2.material.io/components/sheets-bottom>. +/// * The Material 3 spec at <https://m3.material.io/components/bottom-sheets/overview>. +PersistentBottomSheetController showBottomSheet({ + required BuildContext context, + required WidgetBuilder builder, + Color? backgroundColor, + double? elevation, + ShapeBorder? shape, + Clip? clipBehavior, + BoxConstraints? constraints, + bool? enableDrag, + AnimationController? transitionAnimationController, +}) { + assert(debugCheckHasScaffold(context)); + + return Scaffold.of(context).showBottomSheet( + builder, + backgroundColor: backgroundColor, + elevation: elevation, + shape: shape, + clipBehavior: clipBehavior, + constraints: constraints, + enableDrag: enableDrag, + transitionAnimationController: transitionAnimationController, + ); +} + +class _BottomSheetGestureDetector extends StatelessWidget { + const _BottomSheetGestureDetector({ + required this.child, + required this.onVerticalDragStart, + required this.onVerticalDragUpdate, + required this.onVerticalDragEnd, + }); + + final Widget child; + final GestureDragStartCallback onVerticalDragStart; + final GestureDragUpdateCallback onVerticalDragUpdate; + final GestureDragEndCallback onVerticalDragEnd; + + @override + Widget build(BuildContext context) { + return RawGestureDetector( + excludeFromSemantics: true, + gestures: <Type, GestureRecognizerFactory<GestureRecognizer>>{ + VerticalDragGestureRecognizer : GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>( + () => VerticalDragGestureRecognizer(debugOwner: this), + (VerticalDragGestureRecognizer instance) { + instance + ..onStart = onVerticalDragStart + ..onUpdate = onVerticalDragUpdate + ..onEnd = onVerticalDragEnd + ..onlyAcceptDragOnThreshold = true; + }, + ), + }, + child: child, + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - BottomSheet + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _BottomSheetDefaultsM3 extends BottomSheetThemeData { + _BottomSheetDefaultsM3(this.context) + : super( + elevation: 1.0, + modalElevation: 1.0, + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(28.0))), + constraints: const BoxConstraints(maxWidth: 640), + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + Color? get backgroundColor => _colors.surface; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + Color? get shadowColor => Colors.transparent; + + @override + Color? get dragHandleColor => _colors.onSurfaceVariant.withOpacity(0.4); + + @override + Size? get dragHandleSize => const Size(32, 4); + + @override + BoxConstraints? get constraints => const BoxConstraints(maxWidth: 640.0); +} + +// END GENERATED TOKEN PROPERTIES - BottomSheet diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_sheet_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_sheet_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..ea6c28fbfa06b6d26837ca2d5f25f90541765644 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/bottom_sheet_theme.dart @@ -0,0 +1,223 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +/// Defines default property values for [BottomSheet]'s [Material]. +/// +/// Descendant widgets obtain the current [BottomSheetThemeData] object +/// using `Theme.of(context).bottomSheetTheme`. Instances of +/// [BottomSheetThemeData] can be customized with +/// [BottomSheetThemeData.copyWith]. +/// +/// Typically a [BottomSheetThemeData] is specified as part of the +/// overall [Theme] with [ThemeData.bottomSheetTheme]. +/// +/// All [BottomSheetThemeData] properties are `null` by default. +/// When null, the [BottomSheet] will provide its own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class BottomSheetThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.bottomSheetTheme]. + const BottomSheetThemeData({ + this.backgroundColor, + this.surfaceTintColor, + this.elevation, + this.modalBackgroundColor, + this.modalBarrierColor, + this.shadowColor, + this.modalElevation, + this.shape, + this.showDragHandle, + this.dragHandleColor, + this.dragHandleSize, + this.clipBehavior, + this.constraints, + }); + + /// Overrides the default value for [BottomSheet.backgroundColor]. + /// + /// If null, [BottomSheet] defaults to [Material]'s default. + final Color? backgroundColor; + + /// Overrides the default value for surfaceTintColor. + /// + /// If null, [BottomSheet] will not display an overlay color. + /// + /// See [Material.surfaceTintColor] for more details. + final Color? surfaceTintColor; + + /// Overrides the default value for [BottomSheet.elevation]. + /// + /// {@macro flutter.material.material.elevation} + /// + /// If null, [BottomSheet] defaults to 0.0. + final double? elevation; + + /// Value for [BottomSheet.backgroundColor] when the Bottom sheet is presented + /// as a modal bottom sheet. + final Color? modalBackgroundColor; + + /// Overrides the default value for barrier color when the Bottom sheet is presented as + /// a modal bottom sheet. + final Color? modalBarrierColor; + + /// Overrides the default value for [BottomSheet.shadowColor]. + final Color? shadowColor; + + /// Value for [BottomSheet.elevation] when the Bottom sheet is presented as a + /// modal bottom sheet. + final double? modalElevation; + + /// Overrides the default value for [BottomSheet.shape]. + /// + /// If null, no overriding shape is specified for [BottomSheet], so the + /// [BottomSheet] is rectangular. + final ShapeBorder? shape; + + /// Overrides the default value for [BottomSheet.showDragHandle]. + final bool? showDragHandle; + + /// Overrides the default value for [BottomSheet.dragHandleColor]. + final Color? dragHandleColor; + + /// Overrides the default value for [BottomSheet.dragHandleSize]. + final Size? dragHandleSize; + + /// Overrides the default value for [BottomSheet.clipBehavior]. + /// + /// If null, [BottomSheet] uses [Clip.none]. + final Clip? clipBehavior; + + /// Constrains the size of the [BottomSheet]. + /// + /// If null, the bottom sheet's size will be unconstrained. + final BoxConstraints? constraints; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + BottomSheetThemeData copyWith({ + Color? backgroundColor, + Color? surfaceTintColor, + double? elevation, + Color? modalBackgroundColor, + Color? modalBarrierColor, + Color? shadowColor, + double? modalElevation, + ShapeBorder? shape, + bool? showDragHandle, + Color? dragHandleColor, + Size? dragHandleSize, + Clip? clipBehavior, + BoxConstraints? constraints, + }) { + return BottomSheetThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + elevation: elevation ?? this.elevation, + modalBackgroundColor: modalBackgroundColor ?? this.modalBackgroundColor, + modalBarrierColor: modalBarrierColor ?? this.modalBarrierColor, + shadowColor: shadowColor ?? this.shadowColor, + modalElevation: modalElevation ?? this.modalElevation, + shape: shape ?? this.shape, + showDragHandle: showDragHandle ?? this.showDragHandle, + dragHandleColor: dragHandleColor ?? this.dragHandleColor, + dragHandleSize: dragHandleSize ?? this.dragHandleSize, + clipBehavior: clipBehavior ?? this.clipBehavior, + constraints: constraints ?? this.constraints, + ); + } + + /// Linearly interpolate between two bottom sheet themes. + /// + /// If both arguments are null then null is returned. + /// + /// {@macro dart.ui.shadow.lerp} + static BottomSheetThemeData? lerp(BottomSheetThemeData? a, BottomSheetThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return BottomSheetThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + modalBackgroundColor: Color.lerp(a?.modalBackgroundColor, b?.modalBackgroundColor, t), + modalBarrierColor: Color.lerp(a?.modalBarrierColor, b?.modalBarrierColor, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + modalElevation: lerpDouble(a?.modalElevation, b?.modalElevation, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + showDragHandle: t < 0.5 ? a?.showDragHandle : b?.showDragHandle, + dragHandleColor: Color.lerp(a?.dragHandleColor, b?.dragHandleColor, t), + dragHandleSize: Size.lerp(a?.dragHandleSize, b?.dragHandleSize, t), + clipBehavior: t < 0.5 ? a?.clipBehavior : b?.clipBehavior, + constraints: BoxConstraints.lerp(a?.constraints, b?.constraints, t), + ); + } + + @override + int get hashCode => Object.hash( + backgroundColor, + surfaceTintColor, + elevation, + modalBackgroundColor, + modalBarrierColor, + shadowColor, + modalElevation, + shape, + showDragHandle, + dragHandleColor, + dragHandleSize, + clipBehavior, + constraints, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is BottomSheetThemeData + && other.backgroundColor == backgroundColor + && other.surfaceTintColor == surfaceTintColor + && other.elevation == elevation + && other.modalBackgroundColor == modalBackgroundColor + && other.shadowColor == shadowColor + && other.modalBarrierColor == modalBarrierColor + && other.modalElevation == modalElevation + && other.shape == shape + && other.showDragHandle == showDragHandle + && other.dragHandleColor == dragHandleColor + && other.dragHandleSize == dragHandleSize + && other.clipBehavior == clipBehavior + && other.constraints == constraints; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(ColorProperty('modalBackgroundColor', modalBackgroundColor, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('modalBarrierColor', modalBarrierColor, defaultValue: null)); + properties.add(DoubleProperty('modalElevation', modalElevation, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('showDragHandle', showDragHandle, defaultValue: null)); + properties.add(ColorProperty('dragHandleColor', dragHandleColor, defaultValue: null)); + properties.add(DiagnosticsProperty<Size>('dragHandleSize', dragHandleSize, defaultValue: null)); + properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior, defaultValue: null)); + properties.add(DiagnosticsProperty<BoxConstraints>('constraints', constraints, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button.dart new file mode 100644 index 0000000000000000000000000000000000000000..eefabb4918f0c7e73e7f02a8986135a5a6e227a2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button.dart @@ -0,0 +1,545 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_theme.dart'; +import 'constants.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'material_state_mixin.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +/// Creates a button based on [Semantics], [Material], and [InkWell] +/// widgets. +/// +/// This class does not use the current [Theme] or [ButtonTheme] to +/// compute default values for unspecified parameters. It's intended to +/// be used for custom Material buttons that optionally incorporate defaults +/// from the themes or from app-specific sources. +/// +/// This class is planned to be deprecated in a future release, see +/// [ButtonStyleButton], the base class of [ElevatedButton], [FilledButton], +/// [OutlinedButton] and [TextButton]. +/// +/// See also: +/// +/// * [ElevatedButton], a filled button whose material elevates when pressed. +/// * [FilledButton], a filled button that doesn't elevate when pressed. +/// * [FilledButton.tonal], a filled button variant that uses a secondary fill color. +/// * [OutlinedButton], a button with an outlined border and no fill color. +/// * [TextButton], a button with no outline or fill color. +@Category(<String>['Material', 'Button']) +class RawMaterialButton extends StatefulWidget { + /// Create a button based on [Semantics], [Material], and [InkWell] widgets. + /// + /// The [elevation], [focusElevation], [hoverElevation], [highlightElevation], + /// and [disabledElevation] parameters must be non-negative. + const RawMaterialButton({ + super.key, + required this.onPressed, + this.onLongPress, + this.onHighlightChanged, + this.mouseCursor, + this.textStyle, + this.fillColor, + this.focusColor, + this.hoverColor, + this.highlightColor, + this.splashColor, + this.elevation = 2.0, + this.focusElevation = 4.0, + this.hoverElevation = 4.0, + this.highlightElevation = 8.0, + this.disabledElevation = 0.0, + this.padding = EdgeInsets.zero, + this.visualDensity = VisualDensity.standard, + this.constraints = const BoxConstraints(minWidth: 88.0, minHeight: 36.0), + this.shape = const RoundedRectangleBorder(), + this.animationDuration = kThemeChangeDuration, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + MaterialTapTargetSize? materialTapTargetSize, + this.child, + this.enableFeedback = true, + }) : materialTapTargetSize = materialTapTargetSize ?? MaterialTapTargetSize.padded, + assert(elevation >= 0.0), + assert(focusElevation >= 0.0), + assert(hoverElevation >= 0.0), + assert(highlightElevation >= 0.0), + assert(disabledElevation >= 0.0); + + /// Called when the button is tapped or otherwise activated. + /// + /// If this callback and [onLongPress] are null, then the button will be disabled. + /// + /// See also: + /// + /// * [enabled], which is true if the button is enabled. + final VoidCallback? onPressed; + + /// Called when the button is long-pressed. + /// + /// If this callback and [onPressed] are null, then the button will be disabled. + /// + /// See also: + /// + /// * [enabled], which is true if the button is enabled. + final VoidCallback? onLongPress; + + /// Called by the underlying [InkWell] widget's [InkWell.onHighlightChanged] + /// callback. + /// + /// If [onPressed] changes from null to non-null while a gesture is ongoing, + /// this can fire during the build phase (in which case calling + /// [State.setState] is not allowed). + final ValueChanged<bool>? onHighlightChanged; + + /// {@template flutter.material.RawMaterialButton.mouseCursor} + /// The cursor for a mouse pointer when it enters or is hovering over the + /// button. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.pressed]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// {@endtemplate} + /// + /// If this property is null, [MaterialStateMouseCursor.clickable] will be used. + final MouseCursor? mouseCursor; + + /// Defines the default text style, with [Material.textStyle], for the + /// button's [child]. + /// + /// If [TextStyle.color] is a [MaterialStateProperty<Color>], [MaterialStateProperty.resolve] + /// is used for the following [MaterialState]s: + /// + /// * [MaterialState.pressed]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + final TextStyle? textStyle; + + /// The color of the button's [Material]. + final Color? fillColor; + + /// The color for the button's [Material] when it has the input focus. + final Color? focusColor; + + /// The color for the button's [Material] when a pointer is hovering over it. + final Color? hoverColor; + + /// The highlight color for the button's [InkWell]. + final Color? highlightColor; + + /// The splash color for the button's [InkWell]. + final Color? splashColor; + + /// The elevation for the button's [Material] when the button + /// is [enabled] but not pressed. + /// + /// Defaults to 2.0. The value is always non-negative. + /// + /// See also: + /// + /// * [highlightElevation], the default elevation. + /// * [hoverElevation], the elevation when a pointer is hovering over the + /// button. + /// * [focusElevation], the elevation when the button is focused. + /// * [disabledElevation], the elevation when the button is disabled. + final double elevation; + + /// The elevation for the button's [Material] when the button + /// is [enabled] and a pointer is hovering over it. + /// + /// Defaults to 4.0. The value is always non-negative. + /// + /// If the button is [enabled], and being pressed (in the highlighted state), + /// then the [highlightElevation] take precedence over the [hoverElevation]. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [focusElevation], the elevation when the button is focused. + /// * [disabledElevation], the elevation when the button is disabled. + /// * [highlightElevation], the elevation when the button is pressed. + final double hoverElevation; + + /// The elevation for the button's [Material] when the button + /// is [enabled] and has the input focus. + /// + /// Defaults to 4.0. The value is always non-negative. + /// + /// If the button is [enabled], and being pressed (in the highlighted state), + /// or a mouse cursor is hovering over the button, then the [hoverElevation] + /// and [highlightElevation] take precedence over the [focusElevation]. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [hoverElevation], the elevation when a pointer is hovering over the + /// button. + /// * [disabledElevation], the elevation when the button is disabled. + /// * [highlightElevation], the elevation when the button is pressed. + final double focusElevation; + + /// The elevation for the button's [Material] when the button + /// is [enabled] and pressed. + /// + /// Defaults to 8.0. The value is always non-negative. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [hoverElevation], the elevation when a pointer is hovering over the + /// button. + /// * [focusElevation], the elevation when the button is focused. + /// * [disabledElevation], the elevation when the button is disabled. + final double highlightElevation; + + /// The elevation for the button's [Material] when the button + /// is not [enabled]. + /// + /// Defaults to 0.0. The value is always non-negative. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [hoverElevation], the elevation when a pointer is hovering over the + /// button. + /// * [focusElevation], the elevation when the button is focused. + /// * [highlightElevation], the elevation when the button is pressed. + final double disabledElevation; + + /// The internal padding for the button's [child]. + final EdgeInsetsGeometry padding; + + /// Defines how compact the button's layout will be. + /// + /// {@macro flutter.material.themedata.visualDensity} + /// + /// See also: + /// + /// * [ThemeData.visualDensity], which specifies the [visualDensity] for all widgets + /// within a [Theme]. + final VisualDensity visualDensity; + + /// Defines the button's size. + /// + /// Typically used to constrain the button's minimum size. + final BoxConstraints constraints; + + /// The shape of the button's [Material]. + /// + /// The button's highlight and splash are clipped to this shape. If the + /// button has an elevation, then its drop shadow is defined by this shape. + /// + /// If [shape] is a [MaterialStateProperty<ShapeBorder>], [MaterialStateProperty.resolve] + /// is used for the following [MaterialState]s: + /// + /// * [MaterialState.pressed]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + final ShapeBorder shape; + + /// Defines the duration of animated changes for [shape] and [elevation]. + /// + /// The default value is [kThemeChangeDuration]. + final Duration animationDuration; + + /// Typically the button's label. + final Widget? child; + + /// Whether the button is enabled or disabled. + /// + /// Buttons are disabled by default. To enable a button, set its [onPressed] + /// or [onLongPress] properties to a non-null value. + bool get enabled => onPressed != null || onLongPress != null; + + /// Configures the minimum size of the tap target. + /// + /// Defaults to [MaterialTapTargetSize.padded]. + /// + /// See also: + /// + /// * [MaterialTapTargetSize], for a description of how this affects tap targets. + final MaterialTapTargetSize materialTapTargetSize; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool enableFeedback; + + @override + State<RawMaterialButton> createState() => _RawMaterialButtonState(); +} + +class _RawMaterialButtonState extends State<RawMaterialButton> with MaterialStateMixin { + + @override + void initState() { + super.initState(); + setMaterialState(MaterialState.disabled, !widget.enabled); + } + + @override + void didUpdateWidget(RawMaterialButton oldWidget) { + super.didUpdateWidget(oldWidget); + setMaterialState(MaterialState.disabled, !widget.enabled); + // If the button is disabled while a press gesture is currently ongoing, + // InkWell makes a call to handleHighlightChanged. This causes an exception + // because it calls setState in the middle of a build. To preempt this, we + // manually update pressed to false when this situation occurs. + if (isDisabled && isPressed) { + removeMaterialState(MaterialState.pressed); + } + } + + double get _effectiveElevation { + // These conditionals are in order of precedence, so be careful about + // reorganizing them. + if (isDisabled) { + return widget.disabledElevation; + } + if (isPressed) { + return widget.highlightElevation; + } + if (isHovered) { + return widget.hoverElevation; + } + if (isFocused) { + return widget.focusElevation; + } + return widget.elevation; + } + + @override + Widget build(BuildContext context) { + final Color? effectiveTextColor = MaterialStateProperty.resolveAs<Color?>(widget.textStyle?.color, materialStates); + final ShapeBorder? effectiveShape = MaterialStateProperty.resolveAs<ShapeBorder?>(widget.shape, materialStates); + final Offset densityAdjustment = widget.visualDensity.baseSizeAdjustment; + final BoxConstraints effectiveConstraints = widget.visualDensity.effectiveConstraints(widget.constraints); + final MouseCursor? effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor?>( + widget.mouseCursor ?? MaterialStateMouseCursor.clickable, + materialStates, + ); + final EdgeInsetsGeometry padding = widget.padding.add( + EdgeInsets.only( + left: densityAdjustment.dx, + top: densityAdjustment.dy, + right: densityAdjustment.dx, + bottom: densityAdjustment.dy, + ), + ).clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity); + + + final Widget result = ConstrainedBox( + constraints: effectiveConstraints, + child: Material( + elevation: _effectiveElevation, + textStyle: widget.textStyle?.copyWith(color: effectiveTextColor), + shape: effectiveShape, + color: widget.fillColor, + // For compatibility during the M3 migration the default shadow needs to be passed. + shadowColor: Theme.of(context).useMaterial3 ? Theme.of(context).shadowColor : null, + type: widget.fillColor == null ? MaterialType.transparency : MaterialType.button, + animationDuration: widget.animationDuration, + clipBehavior: widget.clipBehavior, + child: InkWell( + focusNode: widget.focusNode, + canRequestFocus: widget.enabled, + onFocusChange: updateMaterialState(MaterialState.focused), + autofocus: widget.autofocus, + onHighlightChanged: updateMaterialState(MaterialState.pressed, onChanged: widget.onHighlightChanged), + splashColor: widget.splashColor, + highlightColor: widget.highlightColor, + focusColor: widget.focusColor, + hoverColor: widget.hoverColor, + onHover: updateMaterialState(MaterialState.hovered), + onTap: widget.onPressed, + onLongPress: widget.onLongPress, + enableFeedback: widget.enableFeedback, + customBorder: effectiveShape, + mouseCursor: effectiveMouseCursor, + child: IconTheme.merge( + data: IconThemeData(color: effectiveTextColor), + child: Container( + padding: padding, + child: Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: widget.child, + ), + ), + ), + ), + ), + ); + final Size minSize; + switch (widget.materialTapTargetSize) { + case MaterialTapTargetSize.padded: + minSize = Size( + kMinInteractiveDimension + densityAdjustment.dx, + kMinInteractiveDimension + densityAdjustment.dy, + ); + assert(minSize.width >= 0.0); + assert(minSize.height >= 0.0); + case MaterialTapTargetSize.shrinkWrap: + minSize = Size.zero; + } + + return Semantics( + container: true, + button: true, + enabled: widget.enabled, + child: _InputPadding( + minSize: minSize, + child: result, + ), + ); + } +} + +/// A widget to pad the area around a [MaterialButton]'s inner [Material]. +/// +/// Redirect taps that occur in the padded area around the child to the center +/// of the child. This increases the size of the button and the button's +/// "tap target", but not its material or its ink splashes. +class _InputPadding extends SingleChildRenderObjectWidget { + const _InputPadding({ + super.child, + required this.minSize, + }); + + final Size minSize; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderInputPadding(minSize); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderInputPadding renderObject) { + renderObject.minSize = minSize; + } +} + +class _RenderInputPadding extends RenderShiftedBox { + _RenderInputPadding(this._minSize, [RenderBox? child]) : super(child); + + Size get minSize => _minSize; + Size _minSize; + set minSize(Size value) { + if (_minSize == value) { + return; + } + _minSize = value; + markNeedsLayout(); + } + + @override + double computeMinIntrinsicWidth(double height) { + if (child != null) { + return math.max(child!.getMinIntrinsicWidth(height), minSize.width); + } + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + if (child != null) { + return math.max(child!.getMinIntrinsicHeight(width), minSize.height); + } + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (child != null) { + return math.max(child!.getMaxIntrinsicWidth(height), minSize.width); + } + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (child != null) { + return math.max(child!.getMaxIntrinsicHeight(width), minSize.height); + } + return 0.0; + } + + Size _computeSize({required BoxConstraints constraints, required ChildLayouter layoutChild}) { + if (child != null) { + final Size childSize = layoutChild(child!, constraints); + final double height = math.max(childSize.width, minSize.width); + final double width = math.max(childSize.height, minSize.height); + return constraints.constrain(Size(height, width)); + } + return Size.zero; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.dryLayoutChild, + ); + } + + @override + void performLayout() { + size = _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.layoutChild, + ); + if (child != null) { + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = Alignment.center.alongOffset(size - child!.size as Offset); + } + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (super.hitTest(result, position: position)) { + return true; + } + final Offset center = child!.size.center(Offset.zero); + return result.addWithRawTransform( + transform: MatrixUtils.forceToPoint(center), + position: center, + hitTest: (BoxHitTestResult result, Offset position) { + assert(position == center); + return child!.hitTest(result, position: center); + }, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..e3e36ec80f59c32c616365dc23129374b4102802 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_bar.dart @@ -0,0 +1,449 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_bar_theme.dart'; +import 'button_theme.dart'; +import 'dialog.dart'; + +/// An end-aligned row of buttons, laying out into a column if there is not +/// enough horizontal space. +/// +/// ## Updating to [OverflowBar] +/// +/// [ButtonBar] has been replace by a more efficient widget, [OverflowBar]. +/// +/// ```dart +/// // Before +/// ButtonBar( +/// alignment: MainAxisAlignment.spaceEvenly, +/// children: <Widget>[ +/// TextButton( child: const Text('Button 1'), onPressed: () {}), +/// TextButton( child: const Text('Button 2'), onPressed: () {}), +/// TextButton( child: const Text('Button 3'), onPressed: () {}), +/// ], +/// ); +/// ``` +/// ```dart +/// // After +/// OverflowBar( +/// alignment: MainAxisAlignment.spaceEvenly, +/// children: <Widget>[ +/// TextButton( child: const Text('Button 1'), onPressed: () {}), +/// TextButton( child: const Text('Button 2'), onPressed: () {}), +/// TextButton( child: const Text('Button 3'), onPressed: () {}), +/// ], +/// ); +/// ``` +/// +/// See the [OverflowBar] documentation for more details. +/// +/// ## Using [ButtonBar] +/// +/// Places the buttons horizontally according to the [buttonPadding]. The +/// children are laid out in a [Row] with [MainAxisAlignment.end]. When the +/// [Directionality] is [TextDirection.ltr], the button bar's children are +/// right justified and the last child becomes the rightmost child. When the +/// [Directionality] [TextDirection.rtl] the children are left justified and +/// the last child becomes the leftmost child. +/// +/// If the button bar's width exceeds the maximum width constraint on the +/// widget, it aligns its buttons in a column. The key difference here +/// is that the [MainAxisAlignment] will then be treated as a +/// cross-axis/horizontal alignment. For example, if the buttons overflow and +/// [ButtonBar.alignment] was set to [MainAxisAlignment.start], the buttons would +/// align to the horizontal start of the button bar. +/// +/// The [ButtonBar] can be configured with a [ButtonBarTheme]. For any null +/// property on the ButtonBar, the surrounding ButtonBarTheme's property +/// will be used instead. If the ButtonBarTheme's property is null +/// as well, the property will default to a value described in the field +/// documentation below. +/// +/// The [children] are wrapped in a [ButtonTheme] that is a copy of the +/// surrounding ButtonTheme with the button properties overridden by the +/// properties of the ButtonBar as described above. These properties include +/// [buttonTextTheme], [buttonMinWidth], [buttonHeight], [buttonPadding], +/// and [buttonAlignedDropdown]. +/// +/// Used by [Dialog] to arrange the actions at the bottom of the dialog. +/// +/// See also: +/// +/// * [TextButton], a simple flat button without a shadow. +/// * [ElevatedButton], a filled button whose material elevates when pressed. +/// * [OutlinedButton], a [TextButton] with a border outline. +/// * [Card], at the bottom of which it is common to place a [ButtonBar]. +/// * [Dialog], which uses a [ButtonBar] for its actions. +/// * [ButtonBarTheme], which configures the [ButtonBar]. +class ButtonBar extends StatelessWidget { + /// Creates a button bar. + /// + /// Both [buttonMinWidth] and [buttonHeight] must be non-negative if they + /// are not null. + const ButtonBar({ + super.key, + this.alignment, + this.mainAxisSize, + this.buttonTextTheme, + this.buttonMinWidth, + this.buttonHeight, + this.buttonPadding, + this.buttonAlignedDropdown, + this.layoutBehavior, + this.overflowDirection, + this.overflowButtonSpacing, + this.children = const <Widget>[], + }) : assert(buttonMinWidth == null || buttonMinWidth >= 0.0), + assert(buttonHeight == null || buttonHeight >= 0.0), + assert(overflowButtonSpacing == null || overflowButtonSpacing >= 0.0); + + /// How the children should be placed along the horizontal axis. + /// + /// If null then it will use [ButtonBarThemeData.alignment]. If that is null, + /// it will default to [MainAxisAlignment.end]. + final MainAxisAlignment? alignment; + + /// How much horizontal space is available. See [Row.mainAxisSize]. + /// + /// If null then it will use the surrounding [ButtonBarThemeData.mainAxisSize]. + /// If that is null, it will default to [MainAxisSize.max]. + final MainAxisSize? mainAxisSize; + + /// Overrides the surrounding [ButtonBarThemeData.buttonTextTheme] to define a + /// button's base colors, size, internal padding and shape. + /// + /// If null then it will use the surrounding + /// [ButtonBarThemeData.buttonTextTheme]. If that is null, it will default to + /// [ButtonTextTheme.primary]. + final ButtonTextTheme? buttonTextTheme; + + /// Overrides the surrounding [ButtonThemeData.minWidth] to define a button's + /// minimum width. + /// + /// If null then it will use the surrounding [ButtonBarThemeData.buttonMinWidth]. + /// If that is null, it will default to 64.0 logical pixels. + final double? buttonMinWidth; + + /// Overrides the surrounding [ButtonThemeData.height] to define a button's + /// minimum height. + /// + /// If null then it will use the surrounding [ButtonBarThemeData.buttonHeight]. + /// If that is null, it will default to 36.0 logical pixels. + final double? buttonHeight; + + /// Overrides the surrounding [ButtonThemeData.padding] to define the padding + /// for a button's child (typically the button's label). + /// + /// If null then it will use the surrounding [ButtonBarThemeData.buttonPadding]. + /// If that is null, it will default to 8.0 logical pixels on the left + /// and right. + final EdgeInsetsGeometry? buttonPadding; + + /// Overrides the surrounding [ButtonThemeData.alignedDropdown] to define whether + /// a [DropdownButton] menu's width will match the button's width. + /// + /// If null then it will use the surrounding [ButtonBarThemeData.buttonAlignedDropdown]. + /// If that is null, it will default to false. + final bool? buttonAlignedDropdown; + + /// Defines whether a [ButtonBar] should size itself with a minimum size + /// constraint or with padding. + /// + /// Overrides the surrounding [ButtonThemeData.layoutBehavior]. + /// + /// If null then it will use the surrounding [ButtonBarThemeData.layoutBehavior]. + /// If that is null, it will default [ButtonBarLayoutBehavior.padded]. + final ButtonBarLayoutBehavior? layoutBehavior; + + /// Defines the vertical direction of a [ButtonBar]'s children if it + /// overflows. + /// + /// If [children] do not fit into a single row, then they + /// are arranged in a column. The first action is at the top of the + /// column if this property is set to [VerticalDirection.down], since it + /// "starts" at the top and "ends" at the bottom. On the other hand, + /// the first action will be at the bottom of the column if this + /// property is set to [VerticalDirection.up], since it "starts" at the + /// bottom and "ends" at the top. + /// + /// If null then it will use the surrounding + /// [ButtonBarThemeData.overflowDirection]. If that is null, it will + /// default to [VerticalDirection.down]. + final VerticalDirection? overflowDirection; + + /// The spacing between buttons when the button bar overflows. + /// + /// If the [children] do not fit into a single row, they are arranged into a + /// column. This parameter provides additional vertical space in between + /// buttons when it does overflow. + /// + /// The button spacing may appear to be more than the value provided. This is + /// because most buttons adhere to the [MaterialTapTargetSize] of 48px. So, + /// even though a button might visually be 36px in height, it might still take + /// up to 48px vertically. + /// + /// If null then no spacing will be added in between buttons in + /// an overflow state. + final double? overflowButtonSpacing; + + /// The buttons to arrange horizontally. + /// + /// Typically [ElevatedButton] or [TextButton] widgets. + final List<Widget> children; + + @override + Widget build(BuildContext context) { + final ButtonThemeData parentButtonTheme = ButtonTheme.of(context); + final ButtonBarThemeData barTheme = ButtonBarTheme.of(context); + + final ButtonThemeData buttonTheme = parentButtonTheme.copyWith( + textTheme: buttonTextTheme ?? barTheme.buttonTextTheme ?? ButtonTextTheme.primary, + minWidth: buttonMinWidth ?? barTheme.buttonMinWidth ?? 64.0, + height: buttonHeight ?? barTheme.buttonHeight ?? 36.0, + padding: buttonPadding ?? barTheme.buttonPadding ?? const EdgeInsets.symmetric(horizontal: 8.0), + alignedDropdown: buttonAlignedDropdown ?? barTheme.buttonAlignedDropdown ?? false, + layoutBehavior: layoutBehavior ?? barTheme.layoutBehavior ?? ButtonBarLayoutBehavior.padded, + ); + + // We divide by 4.0 because we want half of the average of the left and right padding. + final double paddingUnit = buttonTheme.padding.horizontal / 4.0; + final Widget child = ButtonTheme.fromButtonThemeData( + data: buttonTheme, + child: _ButtonBarRow( + mainAxisAlignment: alignment ?? barTheme.alignment ?? MainAxisAlignment.end, + mainAxisSize: mainAxisSize ?? barTheme.mainAxisSize ?? MainAxisSize.max, + overflowDirection: overflowDirection ?? barTheme.overflowDirection ?? VerticalDirection.down, + overflowButtonSpacing: overflowButtonSpacing, + children: children.map<Widget>((Widget child) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: paddingUnit), + child: child, + ); + }).toList(), + ), + ); + switch (buttonTheme.layoutBehavior) { + case ButtonBarLayoutBehavior.padded: + return Padding( + padding: EdgeInsets.symmetric( + vertical: 2.0 * paddingUnit, + horizontal: paddingUnit, + ), + child: child, + ); + case ButtonBarLayoutBehavior.constrained: + return Container( + padding: EdgeInsets.symmetric(horizontal: paddingUnit), + constraints: const BoxConstraints(minHeight: 52.0), + alignment: Alignment.center, + child: child, + ); + } + } +} + +/// Attempts to display buttons in a row, but displays them in a column if +/// there is not enough horizontal space. +/// +/// It first attempts to lay out its buttons as though there were no +/// maximum width constraints on the widget. If the button bar's width is +/// less than the maximum width constraints of the widget, it then lays +/// out the widget as though it were placed in a [Row]. +/// +/// However, if the button bar's width exceeds the maximum width constraint on +/// the widget, it then aligns its buttons in a column. The key difference here +/// is that the [MainAxisAlignment] will then be treated as a +/// cross-axis/horizontal alignment. For example, if the buttons overflow and +/// [ButtonBar.alignment] was set to [MainAxisAlignment.start], the column of +/// buttons would align to the horizontal start of the button bar. +class _ButtonBarRow extends Flex { + /// Creates a button bar that attempts to display in a row, but displays in + /// a column if there is insufficient horizontal space. + const _ButtonBarRow({ + required super.children, + super.mainAxisSize, + super.mainAxisAlignment, + VerticalDirection overflowDirection = VerticalDirection.down, + this.overflowButtonSpacing, + }) : super( + direction: Axis.horizontal, + verticalDirection: overflowDirection, + ); + + final double? overflowButtonSpacing; + + @override + _RenderButtonBarRow createRenderObject(BuildContext context) { + return _RenderButtonBarRow( + direction: direction, + mainAxisAlignment: mainAxisAlignment, + mainAxisSize: mainAxisSize, + crossAxisAlignment: crossAxisAlignment, + textDirection: getEffectiveTextDirection(context)!, + verticalDirection: verticalDirection, + textBaseline: textBaseline, + overflowButtonSpacing: overflowButtonSpacing, + ); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderButtonBarRow renderObject) { + renderObject + ..direction = direction + ..mainAxisAlignment = mainAxisAlignment + ..mainAxisSize = mainAxisSize + ..crossAxisAlignment = crossAxisAlignment + ..textDirection = getEffectiveTextDirection(context) + ..verticalDirection = verticalDirection + ..textBaseline = textBaseline + ..overflowButtonSpacing = overflowButtonSpacing; + } +} + +/// Attempts to display buttons in a row, but displays them in a column if +/// there is not enough horizontal space. +/// +/// It first attempts to lay out its buttons as though there were no +/// maximum width constraints on the widget. If the button bar's width is +/// less than the maximum width constraints of the widget, it then lays +/// out the widget as though it were placed in a [Row]. +/// +/// However, if the button bar's width exceeds the maximum width constraint on +/// the widget, it then aligns its buttons in a column. The key difference here +/// is that the [MainAxisAlignment] will then be treated as a +/// cross-axis/horizontal alignment. For example, if the buttons overflow and +/// [ButtonBar.alignment] was set to [MainAxisAlignment.start], the buttons would +/// align to the horizontal start of the button bar. +class _RenderButtonBarRow extends RenderFlex { + /// Creates a button bar that attempts to display in a row, but displays in + /// a column if there is insufficient horizontal space. + _RenderButtonBarRow({ + super.direction, + super.mainAxisSize, + super.mainAxisAlignment, + super.crossAxisAlignment, + required TextDirection super.textDirection, + super.verticalDirection, + super.textBaseline, + this.overflowButtonSpacing, + }) : assert(overflowButtonSpacing == null || overflowButtonSpacing >= 0); + + bool _hasCheckedLayoutWidth = false; + double? overflowButtonSpacing; + + @override + BoxConstraints get constraints { + if (_hasCheckedLayoutWidth) { + return super.constraints; + } + return super.constraints.copyWith(maxWidth: double.infinity); + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + final Size size = super.computeDryLayout(constraints.copyWith(maxWidth: double.infinity)); + if (size.width <= constraints.maxWidth) { + return super.computeDryLayout(constraints); + } + double currentHeight = 0.0; + RenderBox? child = firstChild; + while (child != null) { + final BoxConstraints childConstraints = constraints.copyWith(minWidth: 0.0); + final Size childSize = child.getDryLayout(childConstraints); + currentHeight += childSize.height; + child = childAfter(child); + if (overflowButtonSpacing != null && child != null) { + currentHeight += overflowButtonSpacing!; + } + } + return constraints.constrain(Size(constraints.maxWidth, currentHeight)); + } + + @override + void performLayout() { + // Set check layout width to false in reload or update cases. + _hasCheckedLayoutWidth = false; + + // Perform layout to ensure that button bar knows how wide it would + // ideally want to be. + super.performLayout(); + _hasCheckedLayoutWidth = true; + + // If the button bar is constrained by width and it overflows, set the + // buttons to align vertically. Otherwise, lay out the button bar + // horizontally. + if (size.width <= constraints.maxWidth) { + // A second performLayout is required to ensure that the original maximum + // width constraints are used. The original perform layout call assumes + // a maximum width constraint of infinity. + super.performLayout(); + } else { + final BoxConstraints childConstraints = constraints.copyWith(minWidth: 0.0); + RenderBox? child; + double currentHeight = 0.0; + switch (verticalDirection) { + case VerticalDirection.down: + child = firstChild; + case VerticalDirection.up: + child = lastChild; + } + + while (child != null) { + final FlexParentData childParentData = child.parentData! as FlexParentData; + + // Lay out the child with the button bar's original constraints, but + // with minimum width set to zero. + child.layout(childConstraints, parentUsesSize: true); + + // Set the cross axis alignment for the column to match the main axis + // alignment for a row. For [MainAxisAlignment.spaceAround], + // [MainAxisAlignment.spaceBetween] and [MainAxisAlignment.spaceEvenly] + // cases, use [MainAxisAlignment.start]. + switch (textDirection!) { + case TextDirection.ltr: + switch (mainAxisAlignment) { + case MainAxisAlignment.center: + final double midpoint = (constraints.maxWidth - child.size.width) / 2.0; + childParentData.offset = Offset(midpoint, currentHeight); + case MainAxisAlignment.end: + childParentData.offset = Offset(constraints.maxWidth - child.size.width, currentHeight); + case MainAxisAlignment.spaceAround: + case MainAxisAlignment.spaceBetween: + case MainAxisAlignment.spaceEvenly: + case MainAxisAlignment.start: + childParentData.offset = Offset(0, currentHeight); + } + case TextDirection.rtl: + switch (mainAxisAlignment) { + case MainAxisAlignment.center: + final double midpoint = constraints.maxWidth / 2.0 - child.size.width / 2.0; + childParentData.offset = Offset(midpoint, currentHeight); + case MainAxisAlignment.end: + childParentData.offset = Offset(0, currentHeight); + case MainAxisAlignment.spaceAround: + case MainAxisAlignment.spaceBetween: + case MainAxisAlignment.spaceEvenly: + case MainAxisAlignment.start: + childParentData.offset = Offset(constraints.maxWidth - child.size.width, currentHeight); + } + } + currentHeight += child.size.height; + switch (verticalDirection) { + case VerticalDirection.down: + child = childParentData.nextSibling; + case VerticalDirection.up: + child = childParentData.previousSibling; + } + + if (overflowButtonSpacing != null && child != null) { + currentHeight += overflowButtonSpacing!; + } + } + size = constraints.constrain(Size(constraints.maxWidth, currentHeight)); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_bar_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_bar_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..b5bf1ddfb82982d94a3c0f1dfa496fefd96088a5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_bar_theme.dart @@ -0,0 +1,261 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines the visual properties of [ButtonBar] widgets. +/// +/// Used by [ButtonBarTheme] to control the visual properties of [ButtonBar] +/// instances in a widget subtree. +/// +/// To obtain this configuration, use [ButtonBarTheme.of] to access the closest +/// ancestor [ButtonBarTheme] of the current [BuildContext]. +/// +/// See also: +/// +/// * [ButtonBarTheme], an [InheritedWidget] that propagates the theme down +/// its subtree. +/// * [ButtonBar], which uses this to configure itself and its children +/// button widgets. +@immutable +class ButtonBarThemeData with Diagnosticable { + /// Constructs the set of properties used to configure [ButtonBar] widgets. + /// + /// Both [buttonMinWidth] and [buttonHeight] must be non-negative if they + /// are not null. + const ButtonBarThemeData({ + this.alignment, + this.mainAxisSize, + this.buttonTextTheme, + this.buttonMinWidth, + this.buttonHeight, + this.buttonPadding, + this.buttonAlignedDropdown, + this.layoutBehavior, + this.overflowDirection, + }) : assert(buttonMinWidth == null || buttonMinWidth >= 0.0), + assert(buttonHeight == null || buttonHeight >= 0.0); + + /// How the children should be placed along the horizontal axis. + final MainAxisAlignment? alignment; + + /// How much horizontal space is available. See [Row.mainAxisSize]. + final MainAxisSize? mainAxisSize; + + /// Defines a [ButtonBar] button's base colors, and the defaults for + /// the button's minimum size, internal padding, and shape. + /// + /// This will override the surrounding [ButtonThemeData.textTheme] setting + /// for buttons contained in the [ButtonBar]. + /// + /// Despite the name, this property is not a [TextTheme], its value is not a + /// collection of [TextStyle]s. + final ButtonTextTheme? buttonTextTheme; + + /// The minimum width for [ButtonBar] buttons. + /// + /// This will override the surrounding [ButtonThemeData.minWidth] setting + /// for buttons contained in the [ButtonBar]. + /// + /// The actual horizontal space allocated for a button's child is + /// at least this value less the theme's horizontal [ButtonThemeData.padding]. + final double? buttonMinWidth; + + /// The minimum height for [ButtonBar] buttons. + /// + /// This will override the surrounding [ButtonThemeData.height] setting + /// for buttons contained in the [ButtonBar]. + final double? buttonHeight; + + /// Padding for a [ButtonBar] button's child (typically the button's label). + /// + /// This will override the surrounding [ButtonThemeData.padding] setting + /// for buttons contained in the [ButtonBar]. + final EdgeInsetsGeometry? buttonPadding; + + /// If true, then a [DropdownButton] menu's width will match the [ButtonBar] + /// button's width. + /// + /// If false, then the dropdown's menu will be wider than + /// its button. In either case the dropdown button will line up the leading + /// edge of the menu's value with the leading edge of the values + /// displayed by the menu items. + /// + /// This will override the surrounding [ButtonThemeData.alignedDropdown] setting + /// for buttons contained in the [ButtonBar]. + /// + /// This property only affects [DropdownButton] contained in a [ButtonBar] + /// and its menu. + final bool? buttonAlignedDropdown; + + /// Defines whether a [ButtonBar] should size itself with a minimum size + /// constraint or with padding. + final ButtonBarLayoutBehavior? layoutBehavior; + + /// Defines the vertical direction of a [ButtonBar]'s children if it + /// overflows. + /// + /// If the [ButtonBar]'s children do not fit into a single row, then they + /// are arranged in a column. The first action is at the top of the + /// column if this property is set to [VerticalDirection.down], since it + /// "starts" at the top and "ends" at the bottom. On the other hand, + /// the first action will be at the bottom of the column if this + /// property is set to [VerticalDirection.up], since it "starts" at the + /// bottom and "ends" at the top. + final VerticalDirection? overflowDirection; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + ButtonBarThemeData copyWith({ + MainAxisAlignment? alignment, + MainAxisSize? mainAxisSize, + ButtonTextTheme? buttonTextTheme, + double? buttonMinWidth, + double? buttonHeight, + EdgeInsetsGeometry? buttonPadding, + bool? buttonAlignedDropdown, + ButtonBarLayoutBehavior? layoutBehavior, + VerticalDirection? overflowDirection, + }) { + return ButtonBarThemeData( + alignment: alignment ?? this.alignment, + mainAxisSize: mainAxisSize ?? this.mainAxisSize, + buttonTextTheme: buttonTextTheme ?? this.buttonTextTheme, + buttonMinWidth: buttonMinWidth ?? this.buttonMinWidth, + buttonHeight: buttonHeight ?? this.buttonHeight, + buttonPadding: buttonPadding ?? this.buttonPadding, + buttonAlignedDropdown: buttonAlignedDropdown ?? this.buttonAlignedDropdown, + layoutBehavior: layoutBehavior ?? this.layoutBehavior, + overflowDirection: overflowDirection ?? this.overflowDirection, + ); + } + + /// Linearly interpolate between two button bar themes. + /// + /// If both arguments are null, then null is returned. + /// + /// {@macro dart.ui.shadow.lerp} + static ButtonBarThemeData? lerp(ButtonBarThemeData? a, ButtonBarThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return ButtonBarThemeData( + alignment: t < 0.5 ? a?.alignment : b?.alignment, + mainAxisSize: t < 0.5 ? a?.mainAxisSize : b?.mainAxisSize, + buttonTextTheme: t < 0.5 ? a?.buttonTextTheme : b?.buttonTextTheme, + buttonMinWidth: lerpDouble(a?.buttonMinWidth, b?.buttonMinWidth, t), + buttonHeight: lerpDouble(a?.buttonHeight, b?.buttonHeight, t), + buttonPadding: EdgeInsetsGeometry.lerp(a?.buttonPadding, b?.buttonPadding, t), + buttonAlignedDropdown: t < 0.5 ? a?.buttonAlignedDropdown : b?.buttonAlignedDropdown, + layoutBehavior: t < 0.5 ? a?.layoutBehavior : b?.layoutBehavior, + overflowDirection: t < 0.5 ? a?.overflowDirection : b?.overflowDirection, + ); + } + + @override + int get hashCode => Object.hash( + alignment, + mainAxisSize, + buttonTextTheme, + buttonMinWidth, + buttonHeight, + buttonPadding, + buttonAlignedDropdown, + layoutBehavior, + overflowDirection, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ButtonBarThemeData + && other.alignment == alignment + && other.mainAxisSize == mainAxisSize + && other.buttonTextTheme == buttonTextTheme + && other.buttonMinWidth == buttonMinWidth + && other.buttonHeight == buttonHeight + && other.buttonPadding == buttonPadding + && other.buttonAlignedDropdown == buttonAlignedDropdown + && other.layoutBehavior == layoutBehavior + && other.overflowDirection == overflowDirection; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MainAxisAlignment>('alignment', alignment, defaultValue: null)); + properties.add(DiagnosticsProperty<MainAxisSize>('mainAxisSize', mainAxisSize, defaultValue: null)); + properties.add(DiagnosticsProperty<ButtonTextTheme>('textTheme', buttonTextTheme, defaultValue: null)); + properties.add(DoubleProperty('minWidth', buttonMinWidth, defaultValue: null)); + properties.add(DoubleProperty('height', buttonHeight, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', buttonPadding, defaultValue: null)); + properties.add(FlagProperty( + 'buttonAlignedDropdown', + value: buttonAlignedDropdown, + ifTrue: 'dropdown width matches button', + )); + properties.add(DiagnosticsProperty<ButtonBarLayoutBehavior>('layoutBehavior', layoutBehavior, defaultValue: null)); + properties.add(DiagnosticsProperty<VerticalDirection>('overflowDirection', overflowDirection, defaultValue: null)); + } +} + +/// Applies a button bar theme to descendant [ButtonBar] widgets. +/// +/// A button bar theme describes the layout and properties for the buttons +/// contained in a [ButtonBar]. +/// +/// Descendant widgets obtain the current theme's [ButtonBarTheme] object using +/// [ButtonBarTheme.of]. When a widget uses [ButtonBarTheme.of], it is automatically +/// rebuilt if the theme later changes. +/// +/// A button bar theme can be specified as part of the overall Material theme +/// using [ThemeData.buttonBarTheme]. +/// +/// See also: +/// +/// * [ButtonBarThemeData], which describes the actual configuration of a button +/// bar theme. +class ButtonBarTheme extends InheritedWidget { + /// Constructs a button bar theme that configures all descendant [ButtonBar] + /// widgets. + const ButtonBarTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties used for all descendant [ButtonBar] widgets. + final ButtonBarThemeData data; + + /// Returns the configuration [data] from the closest [ButtonBarTheme] + /// ancestor. If there is no ancestor, it returns [ThemeData.buttonBarTheme]. + /// Applications can assume that the returned value will not be null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ButtonBarThemeData theme = ButtonBarTheme.of(context); + /// ``` + static ButtonBarThemeData of(BuildContext context) { + final ButtonBarTheme? buttonBarTheme = context.dependOnInheritedWidgetOfExactType<ButtonBarTheme>(); + return buttonBarTheme?.data ?? Theme.of(context).buttonBarTheme; + } + + @override + bool updateShouldNotify(ButtonBarTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_style.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_style.dart new file mode 100644 index 0000000000000000000000000000000000000000..701071dff48c3b57b2e1e26ed6bd89f305f24c4b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_style.dart @@ -0,0 +1,555 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'ink_well.dart'; +import 'material_state.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// late BuildContext context; +// typedef MyAppHome = Placeholder; + +/// The visual properties that most buttons have in common. +/// +/// Buttons and their themes have a ButtonStyle property which defines the visual +/// properties whose default values are to be overridden. The default values are +/// defined by the individual button widgets and are typically based on overall +/// theme's [ThemeData.colorScheme] and [ThemeData.textTheme]. +/// +/// All of the ButtonStyle properties are null by default. +/// +/// Many of the ButtonStyle properties are [MaterialStateProperty] objects which +/// resolve to different values depending on the button's state. For example +/// the [Color] properties are defined with `MaterialStateProperty<Color>` and +/// can resolve to different colors depending on if the button is pressed, +/// hovered, focused, disabled, etc. +/// +/// These properties can override the default value for just one state or all of +/// them. For example to create a [ElevatedButton] whose background color is the +/// color scheme’s primary color with 50% opacity, but only when the button is +/// pressed, one could write: +/// +/// ```dart +/// ElevatedButton( +/// style: ButtonStyle( +/// backgroundColor: MaterialStateProperty.resolveWith<Color?>( +/// (Set<MaterialState> states) { +/// if (states.contains(MaterialState.pressed)) { +/// return Theme.of(context).colorScheme.primary.withOpacity(0.5); +/// } +/// return null; // Use the component's default. +/// }, +/// ), +/// ), +/// child: const Text('Fly me to the moon'), +/// onPressed: () { +/// // ... +/// }, +/// ), +/// ``` +/// +/// In this case the background color for all other button states would fallback +/// to the ElevatedButton’s default values. To unconditionally set the button's +/// [backgroundColor] for all states one could write: +/// +/// ```dart +/// ElevatedButton( +/// style: const ButtonStyle( +/// backgroundColor: MaterialStatePropertyAll<Color>(Colors.green), +/// ), +/// child: const Text('Let me play among the stars'), +/// onPressed: () { +/// // ... +/// }, +/// ), +/// ``` +/// +/// Configuring a ButtonStyle directly makes it possible to very +/// precisely control the button’s visual attributes for all states. +/// This level of control is typically required when a custom +/// “branded” look and feel is desirable. However, in many cases it’s +/// useful to make relatively sweeping changes based on a few initial +/// parameters with simple values. The button styleFrom() methods +/// enable such sweeping changes. See for example: +/// [ElevatedButton.styleFrom], [FilledButton.styleFrom], +/// [OutlinedButton.styleFrom], [TextButton.styleFrom]. +/// +/// For example, to override the default text and icon colors for a +/// [TextButton], as well as its overlay color, with all of the +/// standard opacity adjustments for the pressed, focused, and +/// hovered states, one could write: +/// +/// ```dart +/// TextButton( +/// style: TextButton.styleFrom(foregroundColor: Colors.green), +/// child: const Text('Let me see what spring is like'), +/// onPressed: () { +/// // ... +/// }, +/// ), +/// ``` +/// +/// To configure all of the application's text buttons in the same +/// way, specify the overall theme's `textButtonTheme`: +/// +/// ```dart +/// MaterialApp( +/// theme: ThemeData( +/// textButtonTheme: TextButtonThemeData( +/// style: TextButton.styleFrom(foregroundColor: Colors.green), +/// ), +/// ), +/// home: const MyAppHome(), +/// ), +/// ``` +/// +/// ## Material 3 button types +/// +/// Material Design 3 specifies five types of common buttons. Flutter provides +/// support for these using the following button classes: +/// <style>table,td,th { border-collapse: collapse; padding: 0.45em; } td { border: 1px solid }</style> +/// +/// | Type | Flutter implementation | +/// | :----------- | :---------------------- | +/// | Elevated | [ElevatedButton] | +/// | Filled | [FilledButton] | +/// | Filled Tonal | [FilledButton.tonal] | +/// | Outlined | [OutlinedButton] | +/// | Text | [TextButton] | +/// +/// {@tool dartpad} +/// This sample shows how to create each of the Material 3 button types with Flutter. +/// +/// ** See code in examples/api/lib/material/button_style/button_style.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ElevatedButtonTheme], the theme for [ElevatedButton]s. +/// * [FilledButtonTheme], the theme for [FilledButton]s. +/// * [OutlinedButtonTheme], the theme for [OutlinedButton]s. +/// * [TextButtonTheme], the theme for [TextButton]s. +@immutable +class ButtonStyle with Diagnosticable { + /// Create a [ButtonStyle]. + const ButtonStyle({ + this.textStyle, + this.backgroundColor, + this.foregroundColor, + this.overlayColor, + this.shadowColor, + this.surfaceTintColor, + this.elevation, + this.padding, + this.minimumSize, + this.fixedSize, + this.maximumSize, + this.iconColor, + this.iconSize, + this.side, + this.shape, + this.mouseCursor, + this.visualDensity, + this.tapTargetSize, + this.animationDuration, + this.enableFeedback, + this.alignment, + this.splashFactory, + }); + + /// The style for a button's [Text] widget descendants. + /// + /// The color of the [textStyle] is typically not used directly, the + /// [foregroundColor] is used instead. + final MaterialStateProperty<TextStyle?>? textStyle; + + /// The button's background fill color. + final MaterialStateProperty<Color?>? backgroundColor; + + /// The color for the button's [Text] and [Icon] widget descendants. + /// + /// This color is typically used instead of the color of the [textStyle]. All + /// of the components that compute defaults from [ButtonStyle] values + /// compute a default [foregroundColor] and use that instead of the + /// [textStyle]'s color. + final MaterialStateProperty<Color?>? foregroundColor; + + /// The highlight color that's typically used to indicate that + /// the button is focused, hovered, or pressed. + final MaterialStateProperty<Color?>? overlayColor; + + /// The shadow color of the button's [Material]. + /// + /// The material's elevation shadow can be difficult to see for + /// dark themes, so by default the button classes add a + /// semi-transparent overlay to indicate elevation. See + /// [ThemeData.applyElevationOverlayColor]. + final MaterialStateProperty<Color?>? shadowColor; + + /// The surface tint color of the button's [Material]. + /// + /// See [Material.surfaceTintColor] for more details. + final MaterialStateProperty<Color?>? surfaceTintColor; + + /// The elevation of the button's [Material]. + final MaterialStateProperty<double?>? elevation; + + /// The padding between the button's boundary and its child. + final MaterialStateProperty<EdgeInsetsGeometry?>? padding; + + /// The minimum size of the button itself. + /// + /// The size of the rectangle the button lies within may be larger + /// per [tapTargetSize]. + /// + /// This value must be less than or equal to [maximumSize]. + final MaterialStateProperty<Size?>? minimumSize; + + /// The button's size. + /// + /// This size is still constrained by the style's [minimumSize] + /// and [maximumSize]. Fixed size dimensions whose value is + /// [double.infinity] are ignored. + /// + /// To specify buttons with a fixed width and the default height use + /// `fixedSize: Size.fromWidth(320)`. Similarly, to specify a fixed + /// height and the default width use `fixedSize: Size.fromHeight(100)`. + final MaterialStateProperty<Size?>? fixedSize; + + /// The maximum size of the button itself. + /// + /// A [Size.infinite] or null value for this property means that + /// the button's maximum size is not constrained. + /// + /// This value must be greater than or equal to [minimumSize]. + final MaterialStateProperty<Size?>? maximumSize; + + /// The icon's color inside of the button. + /// + /// If this is null, the icon color will be [foregroundColor]. + final MaterialStateProperty<Color?>? iconColor; + + /// The icon's size inside of the button. + final MaterialStateProperty<double?>? iconSize; + + /// The color and weight of the button's outline. + /// + /// This value is combined with [shape] to create a shape decorated + /// with an outline. + final MaterialStateProperty<BorderSide?>? side; + + /// The shape of the button's underlying [Material]. + /// + /// This shape is combined with [side] to create a shape decorated + /// with an outline. + final MaterialStateProperty<OutlinedBorder?>? shape; + + /// The cursor for a mouse pointer when it enters or is hovering over + /// this button's [InkWell]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// Defines how compact the button's layout will be. + /// + /// {@macro flutter.material.themedata.visualDensity} + /// + /// See also: + /// + /// * [ThemeData.visualDensity], which specifies the [visualDensity] for all widgets + /// within a [Theme]. + final VisualDensity? visualDensity; + + /// Configures the minimum size of the area within which the button may be pressed. + /// + /// If the [tapTargetSize] is larger than [minimumSize], the button will include + /// a transparent margin that responds to taps. + /// + /// Always defaults to [ThemeData.materialTapTargetSize]. + final MaterialTapTargetSize? tapTargetSize; + + /// Defines the duration of animated changes for [shape] and [elevation]. + /// + /// Typically the component default value is [kThemeChangeDuration]. + final Duration? animationDuration; + + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// Typically the component default value is true. + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + /// The alignment of the button's child. + /// + /// Typically buttons are sized to be just big enough to contain the child and its + /// padding. If the button's size is constrained to a fixed size, for example by + /// enclosing it with a [SizedBox], this property defines how the child is aligned + /// within the available space. + /// + /// Always defaults to [Alignment.center]. + final AlignmentGeometry? alignment; + + /// Creates the [InkWell] splash factory, which defines the appearance of + /// "ink" splashes that occur in response to taps. + /// + /// Use [NoSplash.splashFactory] to defeat ink splash rendering. For example: + /// ```dart + /// ElevatedButton( + /// style: ElevatedButton.styleFrom( + /// splashFactory: NoSplash.splashFactory, + /// ), + /// onPressed: () { }, + /// child: const Text('No Splash'), + /// ) + /// ``` + final InteractiveInkFeatureFactory? splashFactory; + + /// Returns a copy of this ButtonStyle with the given fields replaced with + /// the new values. + ButtonStyle copyWith({ + MaterialStateProperty<TextStyle?>? textStyle, + MaterialStateProperty<Color?>? backgroundColor, + MaterialStateProperty<Color?>? foregroundColor, + MaterialStateProperty<Color?>? overlayColor, + MaterialStateProperty<Color?>? shadowColor, + MaterialStateProperty<Color?>? surfaceTintColor, + MaterialStateProperty<double?>? elevation, + MaterialStateProperty<EdgeInsetsGeometry?>? padding, + MaterialStateProperty<Size?>? minimumSize, + MaterialStateProperty<Size?>? fixedSize, + MaterialStateProperty<Size?>? maximumSize, + MaterialStateProperty<Color?>? iconColor, + MaterialStateProperty<double?>? iconSize, + MaterialStateProperty<BorderSide?>? side, + MaterialStateProperty<OutlinedBorder?>? shape, + MaterialStateProperty<MouseCursor?>? mouseCursor, + VisualDensity? visualDensity, + MaterialTapTargetSize? tapTargetSize, + Duration? animationDuration, + bool? enableFeedback, + AlignmentGeometry? alignment, + InteractiveInkFeatureFactory? splashFactory, + }) { + return ButtonStyle( + textStyle: textStyle ?? this.textStyle, + backgroundColor: backgroundColor ?? this.backgroundColor, + foregroundColor: foregroundColor ?? this.foregroundColor, + overlayColor: overlayColor ?? this.overlayColor, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + elevation: elevation ?? this.elevation, + padding: padding ?? this.padding, + minimumSize: minimumSize ?? this.minimumSize, + fixedSize: fixedSize ?? this.fixedSize, + maximumSize: maximumSize ?? this.maximumSize, + iconColor: iconColor ?? this.iconColor, + iconSize: iconSize ?? this.iconSize, + side: side ?? this.side, + shape: shape ?? this.shape, + mouseCursor: mouseCursor ?? this.mouseCursor, + visualDensity: visualDensity ?? this.visualDensity, + tapTargetSize: tapTargetSize ?? this.tapTargetSize, + animationDuration: animationDuration ?? this.animationDuration, + enableFeedback: enableFeedback ?? this.enableFeedback, + alignment: alignment ?? this.alignment, + splashFactory: splashFactory ?? this.splashFactory, + ); + } + + /// Returns a copy of this ButtonStyle where the non-null fields in [style] + /// have replaced the corresponding null fields in this ButtonStyle. + /// + /// In other words, [style] is used to fill in unspecified (null) fields + /// this ButtonStyle. + ButtonStyle merge(ButtonStyle? style) { + if (style == null) { + return this; + } + return copyWith( + textStyle: textStyle ?? style.textStyle, + backgroundColor: backgroundColor ?? style.backgroundColor, + foregroundColor: foregroundColor ?? style.foregroundColor, + overlayColor: overlayColor ?? style.overlayColor, + shadowColor: shadowColor ?? style.shadowColor, + surfaceTintColor: surfaceTintColor ?? style.surfaceTintColor, + elevation: elevation ?? style.elevation, + padding: padding ?? style.padding, + minimumSize: minimumSize ?? style.minimumSize, + fixedSize: fixedSize ?? style.fixedSize, + maximumSize: maximumSize ?? style.maximumSize, + iconColor: iconColor ?? style.iconColor, + iconSize: iconSize ?? style.iconSize, + side: side ?? style.side, + shape: shape ?? style.shape, + mouseCursor: mouseCursor ?? style.mouseCursor, + visualDensity: visualDensity ?? style.visualDensity, + tapTargetSize: tapTargetSize ?? style.tapTargetSize, + animationDuration: animationDuration ?? style.animationDuration, + enableFeedback: enableFeedback ?? style.enableFeedback, + alignment: alignment ?? style.alignment, + splashFactory: splashFactory ?? style.splashFactory, + ); + } + + @override + int get hashCode { + final List<Object?> values = <Object?>[ + textStyle, + backgroundColor, + foregroundColor, + overlayColor, + shadowColor, + surfaceTintColor, + elevation, + padding, + minimumSize, + fixedSize, + maximumSize, + iconColor, + iconSize, + side, + shape, + mouseCursor, + visualDensity, + tapTargetSize, + animationDuration, + enableFeedback, + alignment, + splashFactory, + ]; + return Object.hashAll(values); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ButtonStyle + && other.textStyle == textStyle + && other.backgroundColor == backgroundColor + && other.foregroundColor == foregroundColor + && other.overlayColor == overlayColor + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.elevation == elevation + && other.padding == padding + && other.minimumSize == minimumSize + && other.fixedSize == fixedSize + && other.maximumSize == maximumSize + && other.iconColor == iconColor + && other.iconSize == iconSize + && other.side == side + && other.shape == shape + && other.mouseCursor == mouseCursor + && other.visualDensity == visualDensity + && other.tapTargetSize == tapTargetSize + && other.animationDuration == animationDuration + && other.enableFeedback == enableFeedback + && other.alignment == alignment + && other.splashFactory == splashFactory; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MaterialStateProperty<TextStyle?>>('textStyle', textStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('foregroundColor', foregroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('overlayColor', overlayColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('shadowColor', shadowColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('elevation', elevation, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<EdgeInsetsGeometry?>>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('minimumSize', minimumSize, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('fixedSize', fixedSize, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('maximumSize', maximumSize, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('iconColor', iconColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('iconSize', iconSize, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<BorderSide?>>('side', side, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<OutlinedBorder?>>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null)); + properties.add(DiagnosticsProperty<VisualDensity>('visualDensity', visualDensity, defaultValue: null)); + properties.add(EnumProperty<MaterialTapTargetSize>('tapTargetSize', tapTargetSize, defaultValue: null)); + properties.add(DiagnosticsProperty<Duration>('animationDuration', animationDuration, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('enableFeedback', enableFeedback, defaultValue: null)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: null)); + } + + /// Linearly interpolate between two [ButtonStyle]s. + static ButtonStyle? lerp(ButtonStyle? a, ButtonStyle? b, double t) { + if (identical(a, b)) { + return a; + } + return ButtonStyle( + textStyle: MaterialStateProperty.lerp<TextStyle?>(a?.textStyle, b?.textStyle, t, TextStyle.lerp), + backgroundColor: MaterialStateProperty.lerp<Color?>(a?.backgroundColor, b?.backgroundColor, t, Color.lerp), + foregroundColor: MaterialStateProperty.lerp<Color?>(a?.foregroundColor, b?.foregroundColor, t, Color.lerp), + overlayColor: MaterialStateProperty.lerp<Color?>(a?.overlayColor, b?.overlayColor, t, Color.lerp), + shadowColor: MaterialStateProperty.lerp<Color?>(a?.shadowColor, b?.shadowColor, t, Color.lerp), + surfaceTintColor: MaterialStateProperty.lerp<Color?>(a?.surfaceTintColor, b?.surfaceTintColor, t, Color.lerp), + elevation: MaterialStateProperty.lerp<double?>(a?.elevation, b?.elevation, t, lerpDouble), + padding: MaterialStateProperty.lerp<EdgeInsetsGeometry?>(a?.padding, b?.padding, t, EdgeInsetsGeometry.lerp), + minimumSize: MaterialStateProperty.lerp<Size?>(a?.minimumSize, b?.minimumSize, t, Size.lerp), + fixedSize: MaterialStateProperty.lerp<Size?>(a?.fixedSize, b?.fixedSize, t, Size.lerp), + maximumSize: MaterialStateProperty.lerp<Size?>(a?.maximumSize, b?.maximumSize, t, Size.lerp), + iconColor: MaterialStateProperty.lerp<Color?>(a?.iconColor, b?.iconColor, t, Color.lerp), + iconSize: MaterialStateProperty.lerp<double?>(a?.iconSize, b?.iconSize, t, lerpDouble), + side: _lerpSides(a?.side, b?.side, t), + shape: MaterialStateProperty.lerp<OutlinedBorder?>(a?.shape, b?.shape, t, OutlinedBorder.lerp), + mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, + visualDensity: t < 0.5 ? a?.visualDensity : b?.visualDensity, + tapTargetSize: t < 0.5 ? a?.tapTargetSize : b?.tapTargetSize, + animationDuration: t < 0.5 ? a?.animationDuration : b?.animationDuration, + enableFeedback: t < 0.5 ? a?.enableFeedback : b?.enableFeedback, + alignment: AlignmentGeometry.lerp(a?.alignment, b?.alignment, t), + splashFactory: t < 0.5 ? a?.splashFactory : b?.splashFactory, + ); + } + + // Special case because BorderSide.lerp() doesn't support null arguments + static MaterialStateProperty<BorderSide?>? _lerpSides(MaterialStateProperty<BorderSide?>? a, MaterialStateProperty<BorderSide?>? b, double t) { + if (a == null && b == null) { + return null; + } + return _LerpSides(a, b, t); + } +} + +class _LerpSides implements MaterialStateProperty<BorderSide?> { + const _LerpSides(this.a, this.b, this.t); + + final MaterialStateProperty<BorderSide?>? a; + final MaterialStateProperty<BorderSide?>? b; + final double t; + + @override + BorderSide? resolve(Set<MaterialState> states) { + final BorderSide? resolvedA = a?.resolve(states); + final BorderSide? resolvedB = b?.resolve(states); + if (resolvedA == null && resolvedB == null) { + return null; + } + if (resolvedA == null) { + return BorderSide.lerp(BorderSide(width: 0, color: resolvedB!.color.withAlpha(0)), resolvedB, t); + } + if (resolvedB == null) { + return BorderSide.lerp(resolvedA, BorderSide(width: 0, color: resolvedA.color.withAlpha(0)), t); + } + return BorderSide.lerp(resolvedA, resolvedB, t); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_style_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_style_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..e51d5a17172fbbe8e2a4a733b2d444aa2838c69d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_style_button.dart @@ -0,0 +1,581 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'theme_data.dart'; + +/// The base [StatefulWidget] class for buttons whose style is defined by a [ButtonStyle] object. +/// +/// Concrete subclasses must override [defaultStyleOf] and [themeStyleOf]. +/// +/// See also: +/// * [ElevatedButton], a filled button whose material elevates when pressed. +/// * [FilledButton], a filled button that doesn't elevate when pressed. +/// * [FilledButton.tonal], a filled button variant that uses a secondary fill color. +/// * [OutlinedButton], a button with an outlined border and no fill color. +/// * [TextButton], a button with no outline or fill color. +/// * <https://m3.material.io/components/buttons/overview>, an overview of each of +/// the Material Design button types and how they should be used in designs. +abstract class ButtonStyleButton extends StatefulWidget { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const ButtonStyleButton({ + super.key, + required this.onPressed, + required this.onLongPress, + required this.onHover, + required this.onFocusChange, + required this.style, + required this.focusNode, + required this.autofocus, + required this.clipBehavior, + this.statesController, + this.isSemanticButton = true, + required this.child, + }); + + /// Called when the button is tapped or otherwise activated. + /// + /// If this callback and [onLongPress] are null, then the button will be disabled. + /// + /// See also: + /// + /// * [enabled], which is true if the button is enabled. + final VoidCallback? onPressed; + + /// Called when the button is long-pressed. + /// + /// If this callback and [onPressed] are null, then the button will be disabled. + /// + /// See also: + /// + /// * [enabled], which is true if the button is enabled. + final VoidCallback? onLongPress; + + /// Called when a pointer enters or exits the button response area. + /// + /// The value passed to the callback is true if a pointer has entered this + /// part of the material and false if a pointer has exited this part of the + /// material. + final ValueChanged<bool>? onHover; + + /// Handler called when the focus changes. + /// + /// Called with true if this widget's node gains focus, and false if it loses + /// focus. + final ValueChanged<bool>? onFocusChange; + + /// Customizes this button's appearance. + /// + /// Non-null properties of this style override the corresponding + /// properties in [themeStyleOf] and [defaultStyleOf]. [MaterialStateProperty]s + /// that resolve to non-null values will similarly override the corresponding + /// [MaterialStateProperty]s in [themeStyleOf] and [defaultStyleOf]. + /// + /// Null by default. + final ButtonStyle? style; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@macro flutter.material.inkwell.statesController} + final MaterialStatesController? statesController; + + /// Determine whether this subtree represents a button. + /// + /// If this is null, the screen reader will not announce "button" when this + /// is focused. This is useful for [MenuItemButton] and [SubmenuButton] when we + /// traverse the menu system. + /// + /// Defaults to true. + final bool? isSemanticButton; + + /// Typically the button's label. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// Returns a non-null [ButtonStyle] that's based primarily on the [Theme]'s + /// [ThemeData.textTheme] and [ThemeData.colorScheme]. + /// + /// The returned style can be overridden by the [style] parameter and + /// by the style returned by [themeStyleOf]. For example the default + /// style of the [TextButton] subclass can be overridden with its + /// [TextButton.style] constructor parameter, or with a + /// [TextButtonTheme]. + /// + /// Concrete button subclasses should return a ButtonStyle that + /// has no null properties, and where all of the [MaterialStateProperty] + /// properties resolve to non-null values. + /// + /// See also: + /// + /// * [themeStyleOf], Returns the ButtonStyle of this button's component theme. + @protected + ButtonStyle defaultStyleOf(BuildContext context); + + /// Returns the ButtonStyle that belongs to the button's component theme. + /// + /// The returned style can be overridden by the [style] parameter. + /// + /// Concrete button subclasses should return the ButtonStyle for the + /// nearest subclass-specific inherited theme, and if no such theme + /// exists, then the same value from the overall [Theme]. + /// + /// See also: + /// + /// * [defaultStyleOf], Returns the default [ButtonStyle] for this button. + @protected + ButtonStyle? themeStyleOf(BuildContext context); + + /// Whether the button is enabled or disabled. + /// + /// Buttons are disabled by default. To enable a button, set its [onPressed] + /// or [onLongPress] properties to a non-null value. + bool get enabled => onPressed != null || onLongPress != null; + + @override + State<ButtonStyleButton> createState() => _ButtonStyleState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('enabled', value: enabled, ifFalse: 'disabled')); + properties.add(DiagnosticsProperty<ButtonStyle>('style', style, defaultValue: null)); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null)); + } + + /// Returns null if [value] is null, otherwise `MaterialStatePropertyAll<T>(value)`. + /// + /// A convenience method for subclasses. + static MaterialStateProperty<T>? allOrNull<T>(T? value) => value == null ? null : MaterialStatePropertyAll<T>(value); + + /// A convenience method used by subclasses in the framework, that returns an + /// interpolated value based on the [fontSizeMultiplier] parameter: + /// + /// * 0 - 1 [geometry1x] + /// * 1 - 2 lerp([geometry1x], [geometry2x], [fontSizeMultiplier] - 1) + /// * 2 - 3 lerp([geometry2x], [geometry3x], [fontSizeMultiplier] - 2) + /// * otherwise [geometry3x] + /// + /// This method is used by the framework for estimating the default paddings to + /// use on a button with a text label, when the system text scaling setting + /// changes. It's usually supplied with empirical [geometry1x], [geometry2x], + /// [geometry3x] values adjusted for different system text scaling values, when + /// the unscaled font size is set to 14.0 (the default [TextTheme.labelLarge] + /// value). + /// + /// The `fontSizeMultiplier` argument, for historical reasons, is the default + /// font size specified in the [ButtonStyle], scaled by the ambient font + /// scaler, then divided by 14.0 (the default font size used in buttons). + static EdgeInsetsGeometry scaledPadding( + EdgeInsetsGeometry geometry1x, + EdgeInsetsGeometry geometry2x, + EdgeInsetsGeometry geometry3x, + double fontSizeMultiplier, + ) { + return switch (fontSizeMultiplier) { + <= 1 => geometry1x, + < 2 => EdgeInsetsGeometry.lerp(geometry1x, geometry2x, fontSizeMultiplier - 1)!, + < 3 => EdgeInsetsGeometry.lerp(geometry2x, geometry3x, fontSizeMultiplier - 2)!, + _ => geometry3x, + }; + } +} + +/// The base [State] class for buttons whose style is defined by a [ButtonStyle] object. +/// +/// See also: +/// +/// * [ButtonStyleButton], the [StatefulWidget] subclass for which this class is the [State]. +/// * [ElevatedButton], a filled button whose material elevates when pressed. +/// * [FilledButton], a filled ButtonStyleButton that doesn't elevate when pressed. +/// * [OutlinedButton], similar to [TextButton], but with an outline. +/// * [TextButton], a simple button without a shadow. +class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStateMixin { + AnimationController? controller; + double? elevation; + Color? backgroundColor; + MaterialStatesController? internalStatesController; + + void handleStatesControllerChange() { + // Force a rebuild to resolve MaterialStateProperty properties + setState(() { }); + } + + MaterialStatesController get statesController => widget.statesController ?? internalStatesController!; + + void initStatesController() { + if (widget.statesController == null) { + internalStatesController = MaterialStatesController(); + } + statesController.update(MaterialState.disabled, !widget.enabled); + statesController.addListener(handleStatesControllerChange); + } + + @override + void initState() { + super.initState(); + initStatesController(); + } + + @override + void didUpdateWidget(ButtonStyleButton oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.statesController != oldWidget.statesController) { + oldWidget.statesController?.removeListener(handleStatesControllerChange); + if (widget.statesController != null) { + internalStatesController?.dispose(); + internalStatesController = null; + } + initStatesController(); + } + if (widget.enabled != oldWidget.enabled) { + statesController.update(MaterialState.disabled, !widget.enabled); + if (!widget.enabled) { + // The button may have been disabled while a press gesture is currently underway. + statesController.update(MaterialState.pressed, false); + } + } + } + + @override + void dispose() { + statesController.removeListener(handleStatesControllerChange); + internalStatesController?.dispose(); + controller?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final ButtonStyle? widgetStyle = widget.style; + final ButtonStyle? themeStyle = widget.themeStyleOf(context); + final ButtonStyle defaultStyle = widget.defaultStyleOf(context); + + T? effectiveValue<T>(T? Function(ButtonStyle? style) getProperty) { + final T? widgetValue = getProperty(widgetStyle); + final T? themeValue = getProperty(themeStyle); + final T? defaultValue = getProperty(defaultStyle); + return widgetValue ?? themeValue ?? defaultValue; + } + + T? resolve<T>(MaterialStateProperty<T>? Function(ButtonStyle? style) getProperty) { + return effectiveValue( + (ButtonStyle? style) { + return getProperty(style)?.resolve(statesController.value); + }, + ); + } + + final double? resolvedElevation = resolve<double?>((ButtonStyle? style) => style?.elevation); + final TextStyle? resolvedTextStyle = resolve<TextStyle?>((ButtonStyle? style) => style?.textStyle); + Color? resolvedBackgroundColor = resolve<Color?>((ButtonStyle? style) => style?.backgroundColor); + final Color? resolvedForegroundColor = resolve<Color?>((ButtonStyle? style) => style?.foregroundColor); + final Color? resolvedShadowColor = resolve<Color?>((ButtonStyle? style) => style?.shadowColor); + final Color? resolvedSurfaceTintColor = resolve<Color?>((ButtonStyle? style) => style?.surfaceTintColor); + final EdgeInsetsGeometry? resolvedPadding = resolve<EdgeInsetsGeometry?>((ButtonStyle? style) => style?.padding); + final Size? resolvedMinimumSize = resolve<Size?>((ButtonStyle? style) => style?.minimumSize); + final Size? resolvedFixedSize = resolve<Size?>((ButtonStyle? style) => style?.fixedSize); + final Size? resolvedMaximumSize = resolve<Size?>((ButtonStyle? style) => style?.maximumSize); + final Color? resolvedIconColor = resolve<Color?>((ButtonStyle? style) => style?.iconColor); + final double? resolvedIconSize = resolve<double?>((ButtonStyle? style) => style?.iconSize); + final BorderSide? resolvedSide = resolve<BorderSide?>((ButtonStyle? style) => style?.side); + final OutlinedBorder? resolvedShape = resolve<OutlinedBorder?>((ButtonStyle? style) => style?.shape); + + final MaterialStateMouseCursor mouseCursor = _MouseCursor( + (Set<MaterialState> states) => effectiveValue((ButtonStyle? style) => style?.mouseCursor?.resolve(states)), + ); + + final MaterialStateProperty<Color?> overlayColor = MaterialStateProperty.resolveWith<Color?>( + (Set<MaterialState> states) => effectiveValue((ButtonStyle? style) => style?.overlayColor?.resolve(states)), + ); + + final VisualDensity? resolvedVisualDensity = effectiveValue((ButtonStyle? style) => style?.visualDensity); + final MaterialTapTargetSize? resolvedTapTargetSize = effectiveValue((ButtonStyle? style) => style?.tapTargetSize); + final Duration? resolvedAnimationDuration = effectiveValue((ButtonStyle? style) => style?.animationDuration); + final bool? resolvedEnableFeedback = effectiveValue((ButtonStyle? style) => style?.enableFeedback); + final AlignmentGeometry? resolvedAlignment = effectiveValue((ButtonStyle? style) => style?.alignment); + final Offset densityAdjustment = resolvedVisualDensity!.baseSizeAdjustment; + final InteractiveInkFeatureFactory? resolvedSplashFactory = effectiveValue((ButtonStyle? style) => style?.splashFactory); + + BoxConstraints effectiveConstraints = resolvedVisualDensity.effectiveConstraints( + BoxConstraints( + minWidth: resolvedMinimumSize!.width, + minHeight: resolvedMinimumSize.height, + maxWidth: resolvedMaximumSize!.width, + maxHeight: resolvedMaximumSize.height, + ), + ); + if (resolvedFixedSize != null) { + final Size size = effectiveConstraints.constrain(resolvedFixedSize); + if (size.width.isFinite) { + effectiveConstraints = effectiveConstraints.copyWith( + minWidth: size.width, + maxWidth: size.width, + ); + } + if (size.height.isFinite) { + effectiveConstraints = effectiveConstraints.copyWith( + minHeight: size.height, + maxHeight: size.height, + ); + } + } + + // Per the Material Design team: don't allow the VisualDensity + // adjustment to reduce the width of the left/right padding. If we + // did, VisualDensity.compact, the default for desktop/web, would + // reduce the horizontal padding to zero. + final double dy = densityAdjustment.dy; + final double dx = math.max(0, densityAdjustment.dx); + final EdgeInsetsGeometry padding = resolvedPadding! + .add(EdgeInsets.fromLTRB(dx, dy, dx, dy)) + .clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity); + + // If an opaque button's background is becoming translucent while its + // elevation is changing, change the elevation first. Material implicitly + // animates its elevation but not its color. SKIA renders non-zero + // elevations as a shadow colored fill behind the Material's background. + if (resolvedAnimationDuration! > Duration.zero + && elevation != null + && backgroundColor != null + && elevation != resolvedElevation + && backgroundColor!.value != resolvedBackgroundColor!.value + && backgroundColor!.opacity == 1 + && resolvedBackgroundColor.opacity < 1 + && resolvedElevation == 0) { + if (controller?.duration != resolvedAnimationDuration) { + controller?.dispose(); + controller = AnimationController( + duration: resolvedAnimationDuration, + vsync: this, + ) + ..addStatusListener((AnimationStatus status) { + if (status == AnimationStatus.completed) { + setState(() { }); // Rebuild with the final background color. + } + }); + } + resolvedBackgroundColor = backgroundColor; // Defer changing the background color. + controller!.value = 0; + controller!.forward(); + } + elevation = resolvedElevation; + backgroundColor = resolvedBackgroundColor; + + final Widget result = ConstrainedBox( + constraints: effectiveConstraints, + child: Material( + elevation: resolvedElevation!, + textStyle: resolvedTextStyle?.copyWith(color: resolvedForegroundColor), + shape: resolvedShape!.copyWith(side: resolvedSide), + color: resolvedBackgroundColor, + shadowColor: resolvedShadowColor, + surfaceTintColor: resolvedSurfaceTintColor, + type: resolvedBackgroundColor == null ? MaterialType.transparency : MaterialType.button, + animationDuration: resolvedAnimationDuration, + clipBehavior: widget.clipBehavior, + child: InkWell( + onTap: widget.onPressed, + onLongPress: widget.onLongPress, + onHover: widget.onHover, + mouseCursor: mouseCursor, + enableFeedback: resolvedEnableFeedback, + focusNode: widget.focusNode, + canRequestFocus: widget.enabled, + onFocusChange: widget.onFocusChange, + autofocus: widget.autofocus, + splashFactory: resolvedSplashFactory, + overlayColor: overlayColor, + highlightColor: Colors.transparent, + customBorder: resolvedShape.copyWith(side: resolvedSide), + statesController: statesController, + child: IconTheme.merge( + data: IconThemeData(color: resolvedIconColor ?? resolvedForegroundColor, size: resolvedIconSize), + child: Padding( + padding: padding, + child: Align( + alignment: resolvedAlignment!, + widthFactor: 1.0, + heightFactor: 1.0, + child: widget.child, + ), + ), + ), + ), + ), + ); + + final Size minSize; + switch (resolvedTapTargetSize!) { + case MaterialTapTargetSize.padded: + minSize = Size( + kMinInteractiveDimension + densityAdjustment.dx, + kMinInteractiveDimension + densityAdjustment.dy, + ); + assert(minSize.width >= 0.0); + assert(minSize.height >= 0.0); + case MaterialTapTargetSize.shrinkWrap: + minSize = Size.zero; + } + + return Semantics( + container: true, + button: widget.isSemanticButton, + enabled: widget.enabled, + child: _InputPadding( + minSize: minSize, + child: result, + ), + ); + } +} + +class _MouseCursor extends MaterialStateMouseCursor { + const _MouseCursor(this.resolveCallback); + + final MaterialPropertyResolver<MouseCursor?> resolveCallback; + + @override + MouseCursor resolve(Set<MaterialState> states) => resolveCallback(states)!; + + @override + String get debugDescription => 'ButtonStyleButton_MouseCursor'; +} + +/// A widget to pad the area around a [ButtonStyleButton]'s inner [Material]. +/// +/// Redirect taps that occur in the padded area around the child to the center +/// of the child. This increases the size of the button and the button's +/// "tap target", but not its material or its ink splashes. +class _InputPadding extends SingleChildRenderObjectWidget { + const _InputPadding({ + super.child, + required this.minSize, + }); + + final Size minSize; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderInputPadding(minSize); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderInputPadding renderObject) { + renderObject.minSize = minSize; + } +} + +class _RenderInputPadding extends RenderShiftedBox { + _RenderInputPadding(this._minSize, [RenderBox? child]) : super(child); + + Size get minSize => _minSize; + Size _minSize; + set minSize(Size value) { + if (_minSize == value) { + return; + } + _minSize = value; + markNeedsLayout(); + } + + @override + double computeMinIntrinsicWidth(double height) { + if (child != null) { + return math.max(child!.getMinIntrinsicWidth(height), minSize.width); + } + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + if (child != null) { + return math.max(child!.getMinIntrinsicHeight(width), minSize.height); + } + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (child != null) { + return math.max(child!.getMaxIntrinsicWidth(height), minSize.width); + } + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (child != null) { + return math.max(child!.getMaxIntrinsicHeight(width), minSize.height); + } + return 0.0; + } + + Size _computeSize({required BoxConstraints constraints, required ChildLayouter layoutChild}) { + if (child != null) { + final Size childSize = layoutChild(child!, constraints); + final double height = math.max(childSize.width, minSize.width); + final double width = math.max(childSize.height, minSize.height); + return constraints.constrain(Size(height, width)); + } + return Size.zero; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.dryLayoutChild, + ); + } + + @override + void performLayout() { + size = _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.layoutChild, + ); + if (child != null) { + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = Alignment.center.alongOffset(size - child!.size as Offset); + } + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (super.hitTest(result, position: position)) { + return true; + } + final Offset center = child!.size.center(Offset.zero); + return result.addWithRawTransform( + transform: MatrixUtils.forceToPoint(center), + position: center, + hitTest: (BoxHitTestResult result, Offset position) { + assert(position == center); + return child!.hitTest(result, position: center); + }, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..e41ea025e58c01ad80c042de82e57c86e07e5239 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/button_theme.dart @@ -0,0 +1,784 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'material_button.dart'; +import 'material_state.dart'; +import 'theme.dart'; +import 'theme_data.dart' show MaterialTapTargetSize; + +// Examples can assume: +// late BuildContext context; + +/// Used with [ButtonTheme] and [ButtonThemeData] to define a button's base +/// colors, and the defaults for the button's minimum size, internal padding, +/// and shape. +enum ButtonTextTheme { + /// Button text is black or white depending on [ThemeData.brightness]. + normal, + + /// Button text is [ColorScheme.secondary]. + accent, + + /// Button text is based on [ThemeData.primaryColor]. + primary, +} + +/// Used with [ButtonTheme] and [ButtonThemeData] to define how the button bar +/// should size itself with either constraints or internal padding. +enum ButtonBarLayoutBehavior { + /// Button bars will be constrained to a minimum height of 52. + /// + /// This setting is require to create button bars which conform to the + /// Material Design specification. + constrained, + + /// Button bars will calculate their padding from the button theme padding. + padded, +} + +/// Used with [ButtonThemeData] to configure the color and geometry of buttons. +/// +/// This class is planned to be deprecated in a future release. +/// Please use one or more of these buttons and associated themes instead: +/// +/// * [ElevatedButton], [ElevatedButtonTheme], [ElevatedButtonThemeData], +/// * [FilledButton], [FilledButtonTheme], [FilledButtonThemeData], +/// * [OutlinedButton], [OutlinedButtonTheme], [OutlinedButtonThemeData] +/// * [TextButton], [TextButtonTheme], [TextButtonThemeData], +/// +/// A button theme can be specified as part of the overall Material theme +/// using [ThemeData.buttonTheme]. The Material theme's button theme data +/// can be overridden with [ButtonTheme]. +/// +/// The actual appearance of buttons depends on the button theme, the +/// button's enabled state, its elevation (if any), and the overall [Theme]. +/// +/// See also: +/// +/// * [RawMaterialButton], which can be used to configure a button that doesn't +/// depend on any inherited themes. +class ButtonTheme extends InheritedTheme { + /// Creates a button theme. + ButtonTheme({ + super.key, + ButtonTextTheme textTheme = ButtonTextTheme.normal, + ButtonBarLayoutBehavior layoutBehavior = ButtonBarLayoutBehavior.padded, + double minWidth = 88.0, + double height = 36.0, + EdgeInsetsGeometry? padding, + ShapeBorder? shape, + bool alignedDropdown = false, + Color? buttonColor, + Color? disabledColor, + Color? focusColor, + Color? hoverColor, + Color? highlightColor, + Color? splashColor, + ColorScheme? colorScheme, + MaterialTapTargetSize? materialTapTargetSize, + required super.child, + }) : assert(minWidth >= 0.0), + assert(height >= 0.0), + data = ButtonThemeData( + textTheme: textTheme, + minWidth: minWidth, + height: height, + padding: padding, + shape: shape, + alignedDropdown: alignedDropdown, + layoutBehavior: layoutBehavior, + buttonColor: buttonColor, + disabledColor: disabledColor, + focusColor: focusColor, + hoverColor: hoverColor, + highlightColor: highlightColor, + splashColor: splashColor, + colorScheme: colorScheme, + materialTapTargetSize: materialTapTargetSize, + ); + + /// Creates a button theme from [data]. + const ButtonTheme.fromButtonThemeData({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the color and geometry of buttons. + final ButtonThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ButtonThemeData theme = ButtonTheme.of(context); + /// ``` + static ButtonThemeData of(BuildContext context) { + final ButtonTheme? inheritedButtonTheme = context.dependOnInheritedWidgetOfExactType<ButtonTheme>(); + ButtonThemeData? buttonTheme = inheritedButtonTheme?.data; + if (buttonTheme?.colorScheme == null) { // if buttonTheme or buttonTheme.colorScheme is null + final ThemeData theme = Theme.of(context); + buttonTheme ??= theme.buttonTheme; + if (buttonTheme.colorScheme == null) { + buttonTheme = buttonTheme.copyWith( + colorScheme: theme.buttonTheme.colorScheme ?? theme.colorScheme, + ); + assert(buttonTheme.colorScheme != null); + } + } + return buttonTheme!; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return ButtonTheme.fromButtonThemeData(data: data, child: child); + } + + @override + bool updateShouldNotify(ButtonTheme oldWidget) => data != oldWidget.data; +} + +/// Used with [ButtonTheme] to configure the color and geometry of buttons. +/// +/// This class is planned to be deprecated in a future release. +/// Please use one or more of these buttons and associated themes instead: +/// +/// * [TextButton], [TextButtonTheme], [TextButtonThemeData], +/// * [ElevatedButton], [ElevatedButtonTheme], [ElevatedButtonThemeData], +/// * [OutlinedButton], [OutlinedButtonTheme], [OutlinedButtonThemeData] +/// +/// A button theme can be specified as part of the overall Material theme +/// using [ThemeData.buttonTheme]. The Material theme's button theme data +/// can be overridden with [ButtonTheme]. +@immutable +class ButtonThemeData with Diagnosticable { + /// Create a button theme object that can be used with [ButtonTheme] + /// or [ThemeData]. + /// + /// The [minWidth] and [height] parameters must greater than or equal to zero. + /// + /// The ButtonTheme's methods that have a [MaterialButton] parameter and + /// have a name with a `get` prefix are used to configure a + /// [RawMaterialButton]. + const ButtonThemeData({ + this.textTheme = ButtonTextTheme.normal, + this.minWidth = 88.0, + this.height = 36.0, + EdgeInsetsGeometry? padding, + ShapeBorder? shape, + this.layoutBehavior = ButtonBarLayoutBehavior.padded, + this.alignedDropdown = false, + Color? buttonColor, + Color? disabledColor, + Color? focusColor, + Color? hoverColor, + Color? highlightColor, + Color? splashColor, + this.colorScheme, + MaterialTapTargetSize? materialTapTargetSize, + }) : assert(minWidth >= 0.0), + assert(height >= 0.0), + _buttonColor = buttonColor, + _disabledColor = disabledColor, + _focusColor = focusColor, + _hoverColor = hoverColor, + _highlightColor = highlightColor, + _splashColor = splashColor, + _padding = padding, + _shape = shape, + _materialTapTargetSize = materialTapTargetSize; + + /// The minimum width for buttons. + /// + /// The actual horizontal space allocated for a button's child is + /// at least this value less the theme's horizontal [padding]. + /// + /// Defaults to 88.0 logical pixels. + final double minWidth; + + /// The minimum height for buttons. + /// + /// Defaults to 36.0 logical pixels. + final double height; + + /// Defines a button's base colors, and the defaults for the button's minimum + /// size, internal padding, and shape. + /// + /// Despite the name, this property is not a [TextTheme], its value is not a + /// collection of [TextStyle]s. + final ButtonTextTheme textTheme; + + /// Defines whether a [ButtonBar] should size itself with a minimum size + /// constraint or with padding. + /// + /// Defaults to [ButtonBarLayoutBehavior.padded]. + final ButtonBarLayoutBehavior layoutBehavior; + + /// Convenience that returns [minWidth] and [height] as a + /// [BoxConstraints] object. + BoxConstraints get constraints { + return BoxConstraints( + minWidth: minWidth, + minHeight: height, + ); + } + + /// Padding for a button's child (typically the button's label). + /// + /// Defaults to 24.0 on the left and right if [textTheme] is + /// [ButtonTextTheme.primary], 16.0 on the left and right otherwise. + /// + /// See also: + /// + /// * [getPadding], which is used to calculate padding for the [button]'s + /// child (typically the button's label). + EdgeInsetsGeometry get padding { + if (_padding != null) { + return _padding; + } + switch (textTheme) { + case ButtonTextTheme.normal: + case ButtonTextTheme.accent: + return const EdgeInsets.symmetric(horizontal: 16.0); + case ButtonTextTheme.primary: + return const EdgeInsets.symmetric(horizontal: 24.0); + } + } + final EdgeInsetsGeometry? _padding; + + /// The shape of a button's material. + /// + /// The button's highlight and splash are clipped to this shape. If the + /// button has an elevation, then its drop shadow is defined by this + /// shape as well. + /// + /// Defaults to a rounded rectangle with circular corner radii of 4.0 if + /// [textTheme] is [ButtonTextTheme.primary], a rounded rectangle with + /// circular corner radii of 2.0 otherwise. + /// + /// See also: + /// + /// * [getShape], which is used to calculate the shape of the [button]'s + /// [Material]. + ShapeBorder get shape { + if (_shape != null) { + return _shape; + } + switch (textTheme) { + case ButtonTextTheme.normal: + case ButtonTextTheme.accent: + return const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(2.0)), + ); + case ButtonTextTheme.primary: + return const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(4.0)), + ); + } + } + final ShapeBorder? _shape; + + /// If true, then a [DropdownButton] menu's width will match the button's + /// width. + /// + /// If false (the default), then the dropdown's menu will be wider than + /// its button. In either case the dropdown button will line up the leading + /// edge of the menu's value with the leading edge of the values + /// displayed by the menu items. + /// + /// This property only affects [DropdownButton] and its menu. + final bool alignedDropdown; + + /// The background fill color. + /// + /// This property is null by default. + /// + /// If the button is in the focused, hovering, or highlighted state, then the + /// [focusColor], [hoverColor], or [highlightColor] will take precedence over + /// the [buttonColor]. + /// + /// See also: + /// + /// * [getFillColor], which is used to compute the background fill color. + final Color? _buttonColor; + + /// The background fill color when disabled. + /// + /// This property is null by default. + /// + /// See also: + /// + /// * [getDisabledFillColor], which is to compute background fill color for + /// disabled state. + final Color? _disabledColor; + + /// The fill color of the button when it has the input focus. + /// + /// This property is null by default. + /// + /// If the button is in the hovering or highlighted state, then the [hoverColor] + /// or [highlightColor] will take precedence over the [focusColor]. + /// + /// See also: + /// + /// * [getFocusColor], which is used to compute the fill color of the button + /// when it has input focus. + final Color? _focusColor; + + /// The fill color of the button when a pointer is hovering over it. + /// + /// This property is null by default. + /// + /// If the button is in the highlighted state, then the [highlightColor] will + /// take precedence over the [hoverColor]. + /// + /// See also: + /// + /// * [getHoverColor], which is used to compute the fill color of the button + /// when it has input focus. + final Color? _hoverColor; + + /// The color of the overlay that appears when a button is pressed. + /// + /// This property is null by default. + /// + /// See also: + /// + /// * [getHighlightColor], which is used to compute the color of the overlay + /// that appears when the [button] is pressed. + final Color? _highlightColor; + + /// The color of the ink "splash" overlay that appears when a button is tapped. + /// + /// This property is null by default. + /// + /// See also: + /// + /// * [getSplashColor], which is used to compute the color of the ink + /// "splash" overlay that appears when the (enabled) [button] is tapped. + final Color? _splashColor; + + /// A set of thirteen colors that can be used to derive the button theme's + /// colors. + /// + /// This property was added much later than the theme's set of highly specific + /// colors, like [ThemeData.highlightColor] and [ThemeData.splashColor] etc. + /// + /// The colors for new button classes can be defined exclusively in terms of + /// [colorScheme]. When it's possible, the existing buttons will (continue to) + /// gradually migrate to it. + final ColorScheme? colorScheme; + + // The minimum size of a button's tap target. + // + // This property is null by default. + final MaterialTapTargetSize? _materialTapTargetSize; + + /// The [button]'s overall brightness. + /// + /// Returns the button's [MaterialButton.colorBrightness] if it is non-null, + /// otherwise the color scheme's [ColorScheme.brightness] is returned. + Brightness getBrightness(MaterialButton button) { + return button.colorBrightness ?? colorScheme!.brightness; + } + + /// Defines the [button]'s base colors, and the defaults for the button's + /// minimum size, internal padding, and shape. + /// + /// Despite the name, this property is not the [TextTheme] whose + /// [TextTheme.button] is used as the button text's [TextStyle]. + ButtonTextTheme getTextTheme(MaterialButton button) => button.textTheme ?? textTheme; + + /// The foreground color of the [button]'s text and icon when + /// [MaterialButton.onPressed] is null (when MaterialButton.enabled is false). + /// + /// Returns the button's [MaterialButton.disabledColor] if it is non-null. + /// Otherwise the color scheme's [ColorScheme.onSurface] color is returned + /// with its opacity set to 0.38. + /// + /// If [MaterialButton.textColor] is a [MaterialStateProperty<Color>], it will be + /// used as the `disabledTextColor`. It will be resolved in the [MaterialState.disabled] state. + Color getDisabledTextColor(MaterialButton button) { + return button.textColor ?? button.disabledTextColor ?? colorScheme!.onSurface.withOpacity(0.38); + } + + /// The [button]'s background color when [MaterialButton.onPressed] is null + /// (when [MaterialButton.enabled] is false). + /// + /// Returns the button's [MaterialButton.disabledColor] if it is non-null. + /// + /// Otherwise the value of the `disabledColor` constructor parameter + /// is returned, if it is non-null. + /// + /// Otherwise the color scheme's [ColorScheme.onSurface] color is returned + /// with its opacity set to 0.38. + Color getDisabledFillColor(MaterialButton button) { + return button.disabledColor ?? _disabledColor ?? colorScheme!.onSurface.withOpacity(0.38); + } + + /// The button's background fill color or null for buttons that don't have + /// a background color. + /// + /// Returns [MaterialButton.color] if it is non-null and the button + /// is enabled. + /// + /// Otherwise, returns [MaterialButton.disabledColor] if it is non-null and + /// the button is disabled. + /// + /// Otherwise the fill color depends on the value of [getTextTheme]. + /// + /// * [ButtonTextTheme.normal] or [ButtonTextTheme.accent], the + /// color scheme's [ColorScheme.primary] color if the [button] is enabled + /// the value of [getDisabledFillColor] otherwise. + /// * [ButtonTextTheme.primary], if the [button] is enabled then the value + /// of the `buttonColor` constructor parameter if it is non-null, + /// otherwise the color scheme's ColorScheme.primary color. If the button + /// is not enabled then the colorScheme's [ColorScheme.onSurface] color + /// with opacity 0.12. + Color? getFillColor(MaterialButton button) { + final Color? fillColor = button.enabled ? button.color : button.disabledColor; + if (fillColor != null) { + return fillColor; + } + + if (button.runtimeType == MaterialButton) { + return null; + } + + if (button.enabled && _buttonColor != null) { + return _buttonColor; + } + + switch (getTextTheme(button)) { + case ButtonTextTheme.normal: + case ButtonTextTheme.accent: + return button.enabled ? colorScheme!.primary : getDisabledFillColor(button); + case ButtonTextTheme.primary: + return button.enabled + ? _buttonColor ?? colorScheme!.primary + : colorScheme!.onSurface.withOpacity(0.12); + } + } + + /// The foreground color of the [button]'s text and icon. + /// + /// If [button] is not [MaterialButton.enabled], the value of + /// [getDisabledTextColor] is returned. If the button is enabled and + /// [MaterialButton.textColor] is non-null, then [MaterialButton.textColor] + /// is returned. + /// + /// Otherwise the text color depends on the value of [getTextTheme] + /// and [getBrightness]. + /// + /// * [ButtonTextTheme.normal]: [Colors.white] is used if [getBrightness] + /// resolves to [Brightness.dark]. [Colors.black87] is used if + /// [getBrightness] resolves to [Brightness.light]. + /// * [ButtonTextTheme.accent]: [ColorScheme.secondary] of [colorScheme]. + /// * [ButtonTextTheme.primary]: If [getFillColor] is dark then [Colors.white], + /// otherwise [Colors.black]. + Color getTextColor(MaterialButton button) { + if (!button.enabled) { + return getDisabledTextColor(button); + } + + if (button.textColor != null) { + return button.textColor!; + } + + switch (getTextTheme(button)) { + case ButtonTextTheme.normal: + return getBrightness(button) == Brightness.dark ? Colors.white : Colors.black87; + + case ButtonTextTheme.accent: + return colorScheme!.secondary; + + case ButtonTextTheme.primary: + final Color? fillColor = getFillColor(button); + final bool fillIsDark = fillColor != null + ? ThemeData.estimateBrightnessForColor(fillColor) == Brightness.dark + : getBrightness(button) == Brightness.dark; + return fillIsDark ? Colors.white : Colors.black; + } + } + + /// The color of the ink "splash" overlay that appears when the (enabled) + /// [button] is tapped. + /// + /// Returns the button's [MaterialButton.splashColor] if it is non-null. + /// + /// Otherwise, returns the value of the `splashColor` constructor parameter + /// it is non-null. + /// + /// Otherwise, returns the value of the `splashColor` constructor parameter + /// if it is non-null and [getTextTheme] is not [ButtonTextTheme.primary]. + /// + /// Otherwise, returns [getTextColor] with an opacity of 0.12. + Color getSplashColor(MaterialButton button) { + if (button.splashColor != null) { + return button.splashColor!; + } + + if (_splashColor != null) { + switch (getTextTheme(button)) { + case ButtonTextTheme.normal: + case ButtonTextTheme.accent: + return _splashColor; + case ButtonTextTheme.primary: + break; + } + } + + return getTextColor(button).withOpacity(0.12); + } + + /// The fill color of the button when it has input focus. + /// + /// Returns the button's [MaterialButton.focusColor] if it is non-null. + /// Otherwise the focus color depends on [getTextTheme]: + /// + /// * [ButtonTextTheme.normal], [ButtonTextTheme.accent]: returns the + /// value of the `focusColor` constructor parameter if it is non-null, + /// otherwise the value of [getTextColor] with opacity 0.12. + /// * [ButtonTextTheme.primary], returns [Colors.transparent]. + Color getFocusColor(MaterialButton button) { + return button.focusColor ?? _focusColor ?? getTextColor(button).withOpacity(0.12); + } + + /// The fill color of the button when it has input focus. + /// + /// Returns the button's [MaterialButton.focusColor] if it is non-null. + /// Otherwise the focus color depends on [getTextTheme]: + /// + /// * [ButtonTextTheme.normal], [ButtonTextTheme.accent], + /// [ButtonTextTheme.primary]: returns the value of the `focusColor` + /// constructor parameter if it is non-null, otherwise the value of + /// [getTextColor] with opacity 0.04. + Color getHoverColor(MaterialButton button) { + return button.hoverColor ?? _hoverColor ?? getTextColor(button).withOpacity(0.04); + } + + /// The color of the overlay that appears when the [button] is pressed. + /// + /// Returns the button's [MaterialButton.highlightColor] if it is non-null. + /// Otherwise the highlight color depends on [getTextTheme]: + /// + /// * [ButtonTextTheme.normal], [ButtonTextTheme.accent]: returns the + /// value of the `highlightColor` constructor parameter if it is non-null, + /// otherwise the value of [getTextColor] with opacity 0.16. + /// * [ButtonTextTheme.primary], returns [Colors.transparent]. + Color getHighlightColor(MaterialButton button) { + if (button.highlightColor != null) { + return button.highlightColor!; + } + + switch (getTextTheme(button)) { + case ButtonTextTheme.normal: + case ButtonTextTheme.accent: + return _highlightColor ?? getTextColor(button).withOpacity(0.16); + case ButtonTextTheme.primary: + return Colors.transparent; + } + } + + /// The [button]'s elevation when it is enabled and has not been pressed. + /// + /// Returns the button's [MaterialButton.elevation] if it is non-null, + /// otherwise it is 2.0. + double getElevation(MaterialButton button) => button.elevation ?? 2.0; + + /// The [button]'s elevation when it is enabled and has focus. + /// + /// Returns the button's [MaterialButton.focusElevation] if it is non-null, + /// otherwise the highlight elevation is 4.0. + double getFocusElevation(MaterialButton button) => button.focusElevation ?? 4.0; + + /// The [button]'s elevation when it is enabled and has focus. + /// + /// Returns the button's [MaterialButton.hoverElevation] if it is non-null, + /// otherwise the highlight elevation is 4.0. + double getHoverElevation(MaterialButton button) => button.hoverElevation ?? 4.0; + + /// The [button]'s elevation when it is enabled and has been pressed. + /// + /// Returns the button's [MaterialButton.highlightElevation] if it is non-null, + /// otherwise the highlight elevation is 8.0. + double getHighlightElevation(MaterialButton button) => button.highlightElevation ?? 8.0; + + /// The [button]'s elevation when [MaterialButton.onPressed] is null (when + /// MaterialButton.enabled is false). + /// + /// Returns the button's [MaterialButton.elevation] if it is non-null. + /// + /// Otherwise the disabled elevation is 0.0. + double getDisabledElevation(MaterialButton button) => button.disabledElevation ?? 0.0; + + /// Padding for the [button]'s child (typically the button's label). + /// + /// Returns the button's [MaterialButton.padding] if it is non-null, + /// otherwise, returns the `padding` of the constructor parameter if it is + /// non-null. + /// + /// Otherwise, returns horizontal padding of 24.0 on the left and right if + /// [getTextTheme] is [ButtonTextTheme.primary], 16.0 on the left and right + /// otherwise. + EdgeInsetsGeometry getPadding(MaterialButton button) { + if (button.padding != null) { + return button.padding!; + } + + if (_padding != null) { + return _padding; + } + + switch (getTextTheme(button)) { + case ButtonTextTheme.normal: + case ButtonTextTheme.accent: + return const EdgeInsets.symmetric(horizontal: 16.0); + case ButtonTextTheme.primary: + return const EdgeInsets.symmetric(horizontal: 24.0); + } + } + + /// The shape of the [button]'s [Material]. + /// + /// Returns the button's [MaterialButton.shape] if it is non-null, otherwise + /// [shape] is returned. + ShapeBorder getShape(MaterialButton button) => button.shape ?? shape; + + /// The duration of the [button]'s highlight animation. + /// + /// Returns the button's [MaterialButton.animationDuration] it if is non-null, + /// otherwise 200ms. + Duration getAnimationDuration(MaterialButton button) { + return button.animationDuration ?? kThemeChangeDuration; + } + + /// The [BoxConstraints] that the define the [button]'s size. + /// + /// By default this method just returns [constraints]. Subclasses + /// could override this method to return a value that was, + /// for example, based on the button's type. + BoxConstraints getConstraints(MaterialButton button) => constraints; + + /// The minimum size of the [button]'s tap target. + /// + /// Returns the button's [MaterialButton.materialTapTargetSize] if it is non-null. + /// + /// Otherwise the value of the `materialTapTargetSize` constructor + /// parameter is returned if that's non-null. + /// + /// Otherwise [MaterialTapTargetSize.padded] is returned. + MaterialTapTargetSize getMaterialTapTargetSize(MaterialButton button) { + return button.materialTapTargetSize ?? _materialTapTargetSize ?? MaterialTapTargetSize.padded; + } + + /// Creates a copy of this button theme data object with the matching fields + /// replaced with the non-null parameter values. + ButtonThemeData copyWith({ + ButtonTextTheme? textTheme, + ButtonBarLayoutBehavior? layoutBehavior, + double? minWidth, + double? height, + EdgeInsetsGeometry? padding, + ShapeBorder? shape, + bool? alignedDropdown, + Color? buttonColor, + Color? disabledColor, + Color? focusColor, + Color? hoverColor, + Color? highlightColor, + Color? splashColor, + ColorScheme? colorScheme, + MaterialTapTargetSize? materialTapTargetSize, + }) { + return ButtonThemeData( + textTheme: textTheme ?? this.textTheme, + layoutBehavior: layoutBehavior ?? this.layoutBehavior, + minWidth: minWidth ?? this.minWidth, + height: height ?? this.height, + padding: padding ?? this.padding, + shape: shape ?? this.shape, + alignedDropdown: alignedDropdown ?? this.alignedDropdown, + buttonColor: buttonColor ?? _buttonColor, + disabledColor: disabledColor ?? _disabledColor, + focusColor: focusColor ?? _focusColor, + hoverColor: hoverColor ?? _hoverColor, + highlightColor: highlightColor ?? _highlightColor, + splashColor: splashColor ?? _splashColor, + colorScheme: colorScheme ?? this.colorScheme, + materialTapTargetSize: materialTapTargetSize ?? _materialTapTargetSize, + ); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ButtonThemeData + && other.textTheme == textTheme + && other.minWidth == minWidth + && other.height == height + && other.padding == padding + && other.shape == shape + && other.alignedDropdown == alignedDropdown + && other._buttonColor == _buttonColor + && other._disabledColor == _disabledColor + && other._focusColor == _focusColor + && other._hoverColor == _hoverColor + && other._highlightColor == _highlightColor + && other._splashColor == _splashColor + && other.colorScheme == colorScheme + && other._materialTapTargetSize == _materialTapTargetSize; + } + + @override + int get hashCode => Object.hash( + textTheme, + minWidth, + height, + padding, + shape, + alignedDropdown, + _buttonColor, + _disabledColor, + _focusColor, + _hoverColor, + _highlightColor, + _splashColor, + colorScheme, + _materialTapTargetSize, + ); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + const ButtonThemeData defaultTheme = ButtonThemeData(); + properties.add(EnumProperty<ButtonTextTheme>('textTheme', textTheme, defaultValue: defaultTheme.textTheme)); + properties.add(DoubleProperty('minWidth', minWidth, defaultValue: defaultTheme.minWidth)); + properties.add(DoubleProperty('height', height, defaultValue: defaultTheme.height)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: defaultTheme.padding)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: defaultTheme.shape)); + properties.add(FlagProperty('alignedDropdown', + value: alignedDropdown, + defaultValue: defaultTheme.alignedDropdown, + ifTrue: 'dropdown width matches button', + )); + properties.add(ColorProperty('buttonColor', _buttonColor, defaultValue: null)); + properties.add(ColorProperty('disabledColor', _disabledColor, defaultValue: null)); + properties.add(ColorProperty('focusColor', _focusColor, defaultValue: null)); + properties.add(ColorProperty('hoverColor', _hoverColor, defaultValue: null)); + properties.add(ColorProperty('highlightColor', _highlightColor, defaultValue: null)); + properties.add(ColorProperty('splashColor', _splashColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ColorScheme>('colorScheme', colorScheme, defaultValue: defaultTheme.colorScheme)); + properties.add(DiagnosticsProperty<MaterialTapTargetSize>('materialTapTargetSize', _materialTapTargetSize, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/calendar_date_picker.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/calendar_date_picker.dart new file mode 100644 index 0000000000000000000000000000000000000000..e3cefd4775429e4bf61643333ba0fc947c8b477a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/calendar_date_picker.dart @@ -0,0 +1,1368 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'color_scheme.dart'; +import 'date.dart'; +import 'date_picker_theme.dart'; +import 'debug.dart'; +import 'divider.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'text_theme.dart'; +import 'theme.dart'; + +const Duration _monthScrollDuration = Duration(milliseconds: 200); + +const double _dayPickerRowHeight = 42.0; +const int _maxDayPickerRowCount = 6; // A 31 day month that starts on Saturday. +// One extra row for the day-of-week header. +const double _maxDayPickerHeight = _dayPickerRowHeight * (_maxDayPickerRowCount + 1); +const double _monthPickerHorizontalPadding = 8.0; + +const int _yearPickerColumnCount = 3; +const double _yearPickerPadding = 16.0; +const double _yearPickerRowHeight = 52.0; +const double _yearPickerRowSpacing = 8.0; + +const double _subHeaderHeight = 52.0; +const double _monthNavButtonsWidth = 108.0; + +/// Displays a grid of days for a given month and allows the user to select a +/// date. +/// +/// Days are arranged in a rectangular grid with one column for each day of the +/// week. Controls are provided to change the year and month that the grid is +/// showing. +/// +/// The calendar picker widget is rarely used directly. Instead, consider using +/// [showDatePicker], which will create a dialog that uses this as well as +/// provides a text entry option. +/// +/// See also: +/// +/// * [showDatePicker], which creates a Dialog that contains a +/// [CalendarDatePicker] and provides an optional compact view where the +/// user can enter a date as a line of text. +/// * [showTimePicker], which shows a dialog that contains a Material Design +/// time picker. +/// +class CalendarDatePicker extends StatefulWidget { + /// Creates a calendar date picker. + /// + /// It will display a grid of days for the [initialDate]'s month, or, if that + /// is null, the [currentDate]'s month. The day indicated by [initialDate] will + /// be selected if it is not null. + /// + /// The optional [onDisplayedMonthChanged] callback can be used to track + /// the currently displayed month. + /// + /// The user interface provides a way to change the year of the month being + /// displayed. By default it will show the day grid, but this can be changed + /// to start in the year selection interface with [initialCalendarMode] set + /// to [DatePickerMode.year]. + /// + /// The [lastDate] must be after or equal to [firstDate]. + /// + /// The [initialDate], if provided, must be between [firstDate] and [lastDate] + /// or equal to one of them. + /// + /// The [currentDate] represents the current day (i.e. today). This + /// date will be highlighted in the day grid. If null, the date of + /// `DateTime.now()` will be used. + /// + /// If [selectableDayPredicate] and [initialDate] are both non-null, + /// [selectableDayPredicate] must return `true` for the [initialDate]. + CalendarDatePicker({ + super.key, + required DateTime? initialDate, + required DateTime firstDate, + required DateTime lastDate, + DateTime? currentDate, + required this.onDateChanged, + this.onDisplayedMonthChanged, + this.initialCalendarMode = DatePickerMode.day, + this.selectableDayPredicate, + }) : initialDate = initialDate == null ? null : DateUtils.dateOnly(initialDate), + firstDate = DateUtils.dateOnly(firstDate), + lastDate = DateUtils.dateOnly(lastDate), + currentDate = DateUtils.dateOnly(currentDate ?? DateTime.now()) { + assert( + !this.lastDate.isBefore(this.firstDate), + 'lastDate ${this.lastDate} must be on or after firstDate ${this.firstDate}.', + ); + assert( + this.initialDate == null || !this.initialDate!.isBefore(this.firstDate), + 'initialDate ${this.initialDate} must be on or after firstDate ${this.firstDate}.', + ); + assert( + this.initialDate == null || !this.initialDate!.isAfter(this.lastDate), + 'initialDate ${this.initialDate} must be on or before lastDate ${this.lastDate}.', + ); + assert( + selectableDayPredicate == null || this.initialDate == null || selectableDayPredicate!(this.initialDate!), + 'Provided initialDate ${this.initialDate} must satisfy provided selectableDayPredicate.', + ); + } + + /// The initially selected [DateTime] that the picker should display. + /// + /// Subsequently changing this has no effect. To change the selected date, + /// change the [key] to create a new instance of the [CalendarDatePicker], and + /// provide that widget the new [initialDate]. This will reset the widget's + /// interactive state. + final DateTime? initialDate; + + /// The earliest allowable [DateTime] that the user can select. + final DateTime firstDate; + + /// The latest allowable [DateTime] that the user can select. + final DateTime lastDate; + + /// The [DateTime] representing today. It will be highlighted in the day grid. + final DateTime currentDate; + + /// Called when the user selects a date in the picker. + final ValueChanged<DateTime> onDateChanged; + + /// Called when the user navigates to a new month/year in the picker. + final ValueChanged<DateTime>? onDisplayedMonthChanged; + + /// The initial display of the calendar picker. + /// + /// Subsequently changing this has no effect. To change the calendar mode, + /// change the [key] to create a new instance of the [CalendarDatePicker], and + /// provide that widget a new [initialCalendarMode]. This will reset the + /// widget's interactive state. + final DatePickerMode initialCalendarMode; + + /// Function to provide full control over which dates in the calendar can be selected. + final SelectableDayPredicate? selectableDayPredicate; + + @override + State<CalendarDatePicker> createState() => _CalendarDatePickerState(); +} + +class _CalendarDatePickerState extends State<CalendarDatePicker> { + bool _announcedInitialDate = false; + late DatePickerMode _mode; + late DateTime _currentDisplayedMonthDate; + DateTime? _selectedDate; + final GlobalKey _monthPickerKey = GlobalKey(); + final GlobalKey _yearPickerKey = GlobalKey(); + late MaterialLocalizations _localizations; + late TextDirection _textDirection; + + @override + void initState() { + super.initState(); + _mode = widget.initialCalendarMode; + final DateTime currentDisplayedDate = widget.initialDate ?? widget.currentDate; + _currentDisplayedMonthDate = DateTime(currentDisplayedDate.year, currentDisplayedDate.month); + if (widget.initialDate != null) { + _selectedDate = widget.initialDate; + } + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMaterialLocalizations(context)); + assert(debugCheckHasDirectionality(context)); + _localizations = MaterialLocalizations.of(context); + _textDirection = Directionality.of(context); + if (!_announcedInitialDate && widget.initialDate != null) { + assert(_selectedDate != null); + _announcedInitialDate = true; + final bool isToday = DateUtils.isSameDay(widget.currentDate, _selectedDate); + final String semanticLabelSuffix = isToday ? ', ${_localizations.currentDateLabel}' : ''; + SemanticsService.announce( + '${_localizations.formatFullDate(_selectedDate!)}$semanticLabelSuffix', + _textDirection, + ); + } + } + + void _vibrate() { + switch (Theme.of(context).platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + HapticFeedback.vibrate(); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + break; + } + } + + void _handleModeChanged(DatePickerMode mode) { + _vibrate(); + setState(() { + _mode = mode; + if (_selectedDate != null) { + if (_mode == DatePickerMode.day) { + SemanticsService.announce( + _localizations.formatMonthYear(_selectedDate!), + _textDirection, + ); + } else { + SemanticsService.announce( + _localizations.formatYear(_selectedDate!), + _textDirection, + ); + } + } + }); + } + + void _handleMonthChanged(DateTime date) { + setState(() { + if (_currentDisplayedMonthDate.year != date.year || _currentDisplayedMonthDate.month != date.month) { + _currentDisplayedMonthDate = DateTime(date.year, date.month); + widget.onDisplayedMonthChanged?.call(_currentDisplayedMonthDate); + } + }); + } + + void _handleYearChanged(DateTime value) { + _vibrate(); + + final int daysInMonth = DateUtils.getDaysInMonth(value.year, value.month); + final int preferredDay = math.min(_selectedDate?.day ?? 1, daysInMonth); + value = value.copyWith(day: preferredDay); + + if (value.isBefore(widget.firstDate)) { + value = widget.firstDate; + } else if (value.isAfter(widget.lastDate)) { + value = widget.lastDate; + } + + setState(() { + _mode = DatePickerMode.day; + _handleMonthChanged(value); + + if (_isSelectable(value)) { + _selectedDate = value; + widget.onDateChanged(_selectedDate!); + } + }); + } + + void _handleDayChanged(DateTime value) { + _vibrate(); + setState(() { + _selectedDate = value; + widget.onDateChanged(_selectedDate!); + }); + } + + bool _isSelectable(DateTime date) { + return widget.selectableDayPredicate == null || widget.selectableDayPredicate!.call(date); + } + + Widget _buildPicker() { + switch (_mode) { + case DatePickerMode.day: + return _MonthPicker( + key: _monthPickerKey, + initialMonth: _currentDisplayedMonthDate, + currentDate: widget.currentDate, + firstDate: widget.firstDate, + lastDate: widget.lastDate, + selectedDate: _selectedDate, + onChanged: _handleDayChanged, + onDisplayedMonthChanged: _handleMonthChanged, + selectableDayPredicate: widget.selectableDayPredicate, + ); + case DatePickerMode.year: + return Padding( + padding: const EdgeInsets.only(top: _subHeaderHeight), + child: YearPicker( + key: _yearPickerKey, + currentDate: widget.currentDate, + firstDate: widget.firstDate, + lastDate: widget.lastDate, + selectedDate: _currentDisplayedMonthDate, + onChanged: _handleYearChanged, + ), + ); + } + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMaterialLocalizations(context)); + assert(debugCheckHasDirectionality(context)); + return Stack( + children: <Widget>[ + SizedBox( + height: _subHeaderHeight + _maxDayPickerHeight, + child: _buildPicker(), + ), + // Put the mode toggle button on top so that it won't be covered up by the _MonthPicker + _DatePickerModeToggleButton( + mode: _mode, + title: _localizations.formatMonthYear(_currentDisplayedMonthDate), + onTitlePressed: () { + // Toggle the day/year mode. + _handleModeChanged(_mode == DatePickerMode.day ? DatePickerMode.year : DatePickerMode.day); + }, + ), + ], + ); + } +} + +/// A button that used to toggle the [DatePickerMode] for a date picker. +/// +/// This appears above the calendar grid and allows the user to toggle the +/// [DatePickerMode] to display either the calendar view or the year list. +class _DatePickerModeToggleButton extends StatefulWidget { + const _DatePickerModeToggleButton({ + required this.mode, + required this.title, + required this.onTitlePressed, + }); + + /// The current display of the calendar picker. + final DatePickerMode mode; + + /// The text that displays the current month/year being viewed. + final String title; + + /// The callback when the title is pressed. + final VoidCallback onTitlePressed; + + @override + _DatePickerModeToggleButtonState createState() => _DatePickerModeToggleButtonState(); +} + +class _DatePickerModeToggleButtonState extends State<_DatePickerModeToggleButton> with SingleTickerProviderStateMixin { + late AnimationController _controller; + + @override + void initState() { + super.initState(); + _controller = AnimationController( + value: widget.mode == DatePickerMode.year ? 0.5 : 0, + upperBound: 0.5, + duration: const Duration(milliseconds: 200), + vsync: this, + ); + } + + @override + void didUpdateWidget(_DatePickerModeToggleButton oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.mode == widget.mode) { + return; + } + + if (widget.mode == DatePickerMode.year) { + _controller.forward(); + } else { + _controller.reverse(); + } + } + + @override + Widget build(BuildContext context) { + final ColorScheme colorScheme = Theme.of(context).colorScheme; + final TextTheme textTheme = Theme.of(context).textTheme; + final Color controlColor = colorScheme.onSurface.withOpacity(0.60); + + return Container( + padding: const EdgeInsetsDirectional.only(start: 16, end: 4), + height: _subHeaderHeight, + child: Row( + children: <Widget>[ + Flexible( + child: Semantics( + label: MaterialLocalizations.of(context).selectYearSemanticsLabel, + excludeSemantics: true, + button: true, + child: SizedBox( + height: _subHeaderHeight, + child: InkWell( + onTap: widget.onTitlePressed, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: Row( + children: <Widget>[ + Flexible( + child: Text( + widget.title, + overflow: TextOverflow.ellipsis, + style: textTheme.titleSmall?.copyWith( + color: controlColor, + ), + ), + ), + RotationTransition( + turns: _controller, + child: Icon( + Icons.arrow_drop_down, + color: controlColor, + ), + ), + ], + ), + ), + ), + ), + ), + ), + if (widget.mode == DatePickerMode.day) + // Give space for the prev/next month buttons that are underneath this row + const SizedBox(width: _monthNavButtonsWidth), + ], + ), + ); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } +} + +class _MonthPicker extends StatefulWidget { + /// Creates a month picker. + _MonthPicker({ + super.key, + required this.initialMonth, + required this.currentDate, + required this.firstDate, + required this.lastDate, + required this.selectedDate, + required this.onChanged, + required this.onDisplayedMonthChanged, + this.selectableDayPredicate, + }) : assert(!firstDate.isAfter(lastDate)), + assert(selectedDate == null || !selectedDate.isBefore(firstDate)), + assert(selectedDate == null || !selectedDate.isAfter(lastDate)); + + /// The initial month to display. + /// + /// Subsequently changing this has no effect. To change the selected month, + /// change the [key] to create a new instance of the [_MonthPicker], and + /// provide that widget the new [initialMonth]. This will reset the widget's + /// interactive state. + final DateTime initialMonth; + + /// The current date. + /// + /// This date is subtly highlighted in the picker. + final DateTime currentDate; + + /// The earliest date the user is permitted to pick. + /// + /// This date must be on or before the [lastDate]. + final DateTime firstDate; + + /// The latest date the user is permitted to pick. + /// + /// This date must be on or after the [firstDate]. + final DateTime lastDate; + + /// The currently selected date. + /// + /// This date is highlighted in the picker. + final DateTime? selectedDate; + + /// Called when the user picks a day. + final ValueChanged<DateTime> onChanged; + + /// Called when the user navigates to a new month. + final ValueChanged<DateTime> onDisplayedMonthChanged; + + /// Optional user supplied predicate function to customize selectable days. + final SelectableDayPredicate? selectableDayPredicate; + + @override + _MonthPickerState createState() => _MonthPickerState(); +} + +class _MonthPickerState extends State<_MonthPicker> { + final GlobalKey _pageViewKey = GlobalKey(); + late DateTime _currentMonth; + late PageController _pageController; + late MaterialLocalizations _localizations; + late TextDirection _textDirection; + Map<ShortcutActivator, Intent>? _shortcutMap; + Map<Type, Action<Intent>>? _actionMap; + late FocusNode _dayGridFocus; + DateTime? _focusedDay; + + @override + void initState() { + super.initState(); + _currentMonth = widget.initialMonth; + _pageController = PageController(initialPage: DateUtils.monthDelta(widget.firstDate, _currentMonth)); + _shortcutMap = const <ShortcutActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.arrowLeft): DirectionalFocusIntent(TraversalDirection.left), + SingleActivator(LogicalKeyboardKey.arrowRight): DirectionalFocusIntent(TraversalDirection.right), + SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent(TraversalDirection.down), + SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent(TraversalDirection.up), + }; + _actionMap = <Type, Action<Intent>>{ + NextFocusIntent: CallbackAction<NextFocusIntent>(onInvoke: _handleGridNextFocus), + PreviousFocusIntent: CallbackAction<PreviousFocusIntent>(onInvoke: _handleGridPreviousFocus), + DirectionalFocusIntent: CallbackAction<DirectionalFocusIntent>(onInvoke: _handleDirectionFocus), + }; + _dayGridFocus = FocusNode(debugLabel: 'Day Grid'); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _localizations = MaterialLocalizations.of(context); + _textDirection = Directionality.of(context); + } + + @override + void dispose() { + _pageController.dispose(); + _dayGridFocus.dispose(); + super.dispose(); + } + + void _handleDateSelected(DateTime selectedDate) { + _focusedDay = selectedDate; + widget.onChanged(selectedDate); + } + + void _handleMonthPageChanged(int monthPage) { + setState(() { + final DateTime monthDate = DateUtils.addMonthsToMonthDate(widget.firstDate, monthPage); + if (!DateUtils.isSameMonth(_currentMonth, monthDate)) { + _currentMonth = DateTime(monthDate.year, monthDate.month); + widget.onDisplayedMonthChanged(_currentMonth); + if (_focusedDay != null && !DateUtils.isSameMonth(_focusedDay, _currentMonth)) { + // We have navigated to a new month with the grid focused, but the + // focused day is not in this month. Choose a new one trying to keep + // the same day of the month. + _focusedDay = _focusableDayForMonth(_currentMonth, _focusedDay!.day); + } + SemanticsService.announce( + _localizations.formatMonthYear(_currentMonth), + _textDirection, + ); + } + }); + } + + /// Returns a focusable date for the given month. + /// + /// If the preferredDay is available in the month it will be returned, + /// otherwise the first selectable day in the month will be returned. If + /// no dates are selectable in the month, then it will return null. + DateTime? _focusableDayForMonth(DateTime month, int preferredDay) { + final int daysInMonth = DateUtils.getDaysInMonth(month.year, month.month); + + // Can we use the preferred day in this month? + if (preferredDay <= daysInMonth) { + final DateTime newFocus = DateTime(month.year, month.month, preferredDay); + if (_isSelectable(newFocus)) { + return newFocus; + } + } + + // Start at the 1st and take the first selectable date. + for (int day = 1; day <= daysInMonth; day++) { + final DateTime newFocus = DateTime(month.year, month.month, day); + if (_isSelectable(newFocus)) { + return newFocus; + } + } + return null; + } + + /// Navigate to the next month. + void _handleNextMonth() { + if (!_isDisplayingLastMonth) { + _pageController.nextPage( + duration: _monthScrollDuration, + curve: Curves.ease, + ); + } + } + + /// Navigate to the previous month. + void _handlePreviousMonth() { + if (!_isDisplayingFirstMonth) { + _pageController.previousPage( + duration: _monthScrollDuration, + curve: Curves.ease, + ); + } + } + + /// Navigate to the given month. + void _showMonth(DateTime month, { bool jump = false}) { + final int monthPage = DateUtils.monthDelta(widget.firstDate, month); + if (jump) { + _pageController.jumpToPage(monthPage); + } else { + _pageController.animateToPage( + monthPage, + duration: _monthScrollDuration, + curve: Curves.ease, + ); + } + } + + /// True if the earliest allowable month is displayed. + bool get _isDisplayingFirstMonth { + return !_currentMonth.isAfter( + DateTime(widget.firstDate.year, widget.firstDate.month), + ); + } + + /// True if the latest allowable month is displayed. + bool get _isDisplayingLastMonth { + return !_currentMonth.isBefore( + DateTime(widget.lastDate.year, widget.lastDate.month), + ); + } + + /// Handler for when the overall day grid obtains or loses focus. + void _handleGridFocusChange(bool focused) { + setState(() { + if (focused && _focusedDay == null) { + if (DateUtils.isSameMonth(widget.selectedDate, _currentMonth)) { + _focusedDay = widget.selectedDate; + } else if (DateUtils.isSameMonth(widget.currentDate, _currentMonth)) { + _focusedDay = _focusableDayForMonth(_currentMonth, widget.currentDate.day); + } else { + _focusedDay = _focusableDayForMonth(_currentMonth, 1); + } + } + }); + } + + /// Move focus to the next element after the day grid. + void _handleGridNextFocus(NextFocusIntent intent) { + _dayGridFocus.requestFocus(); + _dayGridFocus.nextFocus(); + } + + /// Move focus to the previous element before the day grid. + void _handleGridPreviousFocus(PreviousFocusIntent intent) { + _dayGridFocus.requestFocus(); + _dayGridFocus.previousFocus(); + } + + /// Move the internal focus date in the direction of the given intent. + /// + /// This will attempt to move the focused day to the next selectable day in + /// the given direction. If the new date is not in the current month, then + /// the page view will be scrolled to show the new date's month. + /// + /// For horizontal directions, it will move forward or backward a day (depending + /// on the current [TextDirection]). For vertical directions it will move up and + /// down a week at a time. + void _handleDirectionFocus(DirectionalFocusIntent intent) { + assert(_focusedDay != null); + setState(() { + final DateTime? nextDate = _nextDateInDirection(_focusedDay!, intent.direction); + if (nextDate != null) { + _focusedDay = nextDate; + if (!DateUtils.isSameMonth(_focusedDay, _currentMonth)) { + _showMonth(_focusedDay!); + } + } + }); + } + + static const Map<TraversalDirection, int> _directionOffset = <TraversalDirection, int>{ + TraversalDirection.up: -DateTime.daysPerWeek, + TraversalDirection.right: 1, + TraversalDirection.down: DateTime.daysPerWeek, + TraversalDirection.left: -1, + }; + + int _dayDirectionOffset(TraversalDirection traversalDirection, TextDirection textDirection) { + // Swap left and right if the text direction if RTL + if (textDirection == TextDirection.rtl) { + if (traversalDirection == TraversalDirection.left) { + traversalDirection = TraversalDirection.right; + } else if (traversalDirection == TraversalDirection.right) { + traversalDirection = TraversalDirection.left; + } + } + return _directionOffset[traversalDirection]!; + } + + DateTime? _nextDateInDirection(DateTime date, TraversalDirection direction) { + final TextDirection textDirection = Directionality.of(context); + DateTime nextDate = DateUtils.addDaysToDate(date, _dayDirectionOffset(direction, textDirection)); + while (!nextDate.isBefore(widget.firstDate) && !nextDate.isAfter(widget.lastDate)) { + if (_isSelectable(nextDate)) { + return nextDate; + } + nextDate = DateUtils.addDaysToDate(nextDate, _dayDirectionOffset(direction, textDirection)); + } + return null; + } + + bool _isSelectable(DateTime date) { + return widget.selectableDayPredicate == null || widget.selectableDayPredicate!.call(date); + } + + Widget _buildItems(BuildContext context, int index) { + final DateTime month = DateUtils.addMonthsToMonthDate(widget.firstDate, index); + return _DayPicker( + key: ValueKey<DateTime>(month), + selectedDate: widget.selectedDate, + currentDate: widget.currentDate, + onChanged: _handleDateSelected, + firstDate: widget.firstDate, + lastDate: widget.lastDate, + displayedMonth: month, + selectableDayPredicate: widget.selectableDayPredicate, + ); + } + + @override + Widget build(BuildContext context) { + final Color controlColor = Theme.of(context).colorScheme.onSurface.withOpacity(0.60); + + return Semantics( + child: Column( + children: <Widget>[ + Container( + padding: const EdgeInsetsDirectional.only(start: 16, end: 4), + height: _subHeaderHeight, + child: Row( + children: <Widget>[ + const Spacer(), + IconButton( + icon: const Icon(Icons.chevron_left), + color: controlColor, + tooltip: _isDisplayingFirstMonth ? null : _localizations.previousMonthTooltip, + onPressed: _isDisplayingFirstMonth ? null : _handlePreviousMonth, + ), + IconButton( + icon: const Icon(Icons.chevron_right), + color: controlColor, + tooltip: _isDisplayingLastMonth ? null : _localizations.nextMonthTooltip, + onPressed: _isDisplayingLastMonth ? null : _handleNextMonth, + ), + ], + ), + ), + Expanded( + child: FocusableActionDetector( + shortcuts: _shortcutMap, + actions: _actionMap, + focusNode: _dayGridFocus, + onFocusChange: _handleGridFocusChange, + child: _FocusedDate( + date: _dayGridFocus.hasFocus ? _focusedDay : null, + child: PageView.builder( + key: _pageViewKey, + controller: _pageController, + itemBuilder: _buildItems, + itemCount: DateUtils.monthDelta(widget.firstDate, widget.lastDate) + 1, + onPageChanged: _handleMonthPageChanged, + ), + ), + ), + ), + ], + ), + ); + } +} + +/// InheritedWidget indicating what the current focused date is for its children. +/// +/// This is used by the [_MonthPicker] to let its children [_DayPicker]s know +/// what the currently focused date (if any) should be. +class _FocusedDate extends InheritedWidget { + const _FocusedDate({ + required super.child, + this.date, + }); + + final DateTime? date; + + @override + bool updateShouldNotify(_FocusedDate oldWidget) { + return !DateUtils.isSameDay(date, oldWidget.date); + } + + static DateTime? maybeOf(BuildContext context) { + final _FocusedDate? focusedDate = context.dependOnInheritedWidgetOfExactType<_FocusedDate>(); + return focusedDate?.date; + } +} + +/// Displays the days of a given month and allows choosing a day. +/// +/// The days are arranged in a rectangular grid with one column for each day of +/// the week. +class _DayPicker extends StatefulWidget { + /// Creates a day picker. + _DayPicker({ + super.key, + required this.currentDate, + required this.displayedMonth, + required this.firstDate, + required this.lastDate, + required this.selectedDate, + required this.onChanged, + this.selectableDayPredicate, + }) : assert(!firstDate.isAfter(lastDate)), + assert(selectedDate == null || !selectedDate.isBefore(firstDate)), + assert(selectedDate == null || !selectedDate.isAfter(lastDate)); + + /// The currently selected date. + /// + /// This date is highlighted in the picker. + final DateTime? selectedDate; + + /// The current date at the time the picker is displayed. + final DateTime currentDate; + + /// Called when the user picks a day. + final ValueChanged<DateTime> onChanged; + + /// The earliest date the user is permitted to pick. + /// + /// This date must be on or before the [lastDate]. + final DateTime firstDate; + + /// The latest date the user is permitted to pick. + /// + /// This date must be on or after the [firstDate]. + final DateTime lastDate; + + /// The month whose days are displayed by this picker. + final DateTime displayedMonth; + + /// Optional user supplied predicate function to customize selectable days. + final SelectableDayPredicate? selectableDayPredicate; + + @override + _DayPickerState createState() => _DayPickerState(); +} + +class _DayPickerState extends State<_DayPicker> { + + /// List of [FocusNode]s, one for each day of the month. + late List<FocusNode> _dayFocusNodes; + + @override + void initState() { + super.initState(); + final int daysInMonth = DateUtils.getDaysInMonth(widget.displayedMonth.year, widget.displayedMonth.month); + _dayFocusNodes = List<FocusNode>.generate( + daysInMonth, + (int index) => FocusNode(skipTraversal: true, debugLabel: 'Day ${index + 1}'), + ); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + // Check to see if the focused date is in this month, if so focus it. + final DateTime? focusedDate = _FocusedDate.maybeOf(context); + if (focusedDate != null && DateUtils.isSameMonth(widget.displayedMonth, focusedDate)) { + _dayFocusNodes[focusedDate.day - 1].requestFocus(); + } + } + + @override + void dispose() { + for (final FocusNode node in _dayFocusNodes) { + node.dispose(); + } + super.dispose(); + } + + /// Builds widgets showing abbreviated days of week. The first widget in the + /// returned list corresponds to the first day of week for the current locale. + /// + /// Examples: + /// + /// ┌ Sunday is the first day of week in the US (en_US) + /// | + /// S M T W T F S ← the returned list contains these widgets + /// _ _ _ _ _ 1 2 + /// 3 4 5 6 7 8 9 + /// + /// ┌ But it's Monday in the UK (en_GB) + /// | + /// M T W T F S S ← the returned list contains these widgets + /// _ _ _ _ 1 2 3 + /// 4 5 6 7 8 9 10 + /// + List<Widget> _dayHeaders(TextStyle? headerStyle, MaterialLocalizations localizations) { + final List<Widget> result = <Widget>[]; + for (int i = localizations.firstDayOfWeekIndex; result.length < DateTime.daysPerWeek; i = (i + 1) % DateTime.daysPerWeek) { + final String weekday = localizations.narrowWeekdays[i]; + result.add(ExcludeSemantics( + child: Center(child: Text(weekday, style: headerStyle)), + )); + } + return result; + } + + @override + Widget build(BuildContext context) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final DatePickerThemeData datePickerTheme = DatePickerTheme.of(context); + final DatePickerThemeData defaults = DatePickerTheme.defaults(context); + final TextStyle? weekdayStyle = datePickerTheme.weekdayStyle ?? defaults.weekdayStyle; + + final int year = widget.displayedMonth.year; + final int month = widget.displayedMonth.month; + + final int daysInMonth = DateUtils.getDaysInMonth(year, month); + final int dayOffset = DateUtils.firstDayOffset(year, month, localizations); + + final List<Widget> dayItems = _dayHeaders(weekdayStyle, localizations); + // 1-based day of month, e.g. 1-31 for January, and 1-29 for February on + // a leap year. + int day = -dayOffset; + while (day < daysInMonth) { + day++; + if (day < 1) { + dayItems.add(Container()); + } else { + final DateTime dayToBuild = DateTime(year, month, day); + final bool isDisabled = + dayToBuild.isAfter(widget.lastDate) || + dayToBuild.isBefore(widget.firstDate) || + (widget.selectableDayPredicate != null && !widget.selectableDayPredicate!(dayToBuild)); + final bool isSelectedDay = DateUtils.isSameDay(widget.selectedDate, dayToBuild); + final bool isToday = DateUtils.isSameDay(widget.currentDate, dayToBuild); + + dayItems.add( + _Day( + dayToBuild, + key: ValueKey<DateTime>(dayToBuild), + isDisabled: isDisabled, + isSelectedDay: isSelectedDay, + isToday: isToday, + onChanged: widget.onChanged, + focusNode: _dayFocusNodes[day - 1], + ), + ); + } + } + + return Padding( + padding: const EdgeInsets.symmetric( + horizontal: _monthPickerHorizontalPadding, + ), + child: GridView.custom( + physics: const ClampingScrollPhysics(), + gridDelegate: _dayPickerGridDelegate, + childrenDelegate: SliverChildListDelegate( + dayItems, + addRepaintBoundaries: false, + ), + ), + ); + } +} + +class _Day extends StatefulWidget { + const _Day( + this.day, { + super.key, + required this.isDisabled, + required this.isSelectedDay, + required this.isToday, + required this.onChanged, + required this.focusNode, + }); + + final DateTime day; + final bool isDisabled; + final bool isSelectedDay; + final bool isToday; + final ValueChanged<DateTime> onChanged; + final FocusNode? focusNode; + + @override + State<_Day> createState() => _DayState(); +} + +class _DayState extends State<_Day> { + final MaterialStatesController _statesController = MaterialStatesController(); + + @override + Widget build(BuildContext context) { + final DatePickerThemeData defaults = DatePickerTheme.defaults(context); + final DatePickerThemeData datePickerTheme = DatePickerTheme.of(context); + final TextStyle? dayStyle = datePickerTheme.dayStyle ?? defaults.dayStyle; + T? effectiveValue<T>(T? Function(DatePickerThemeData? theme) getProperty) { + return getProperty(datePickerTheme) ?? getProperty(defaults); + } + + T? resolve<T>(MaterialStateProperty<T>? Function(DatePickerThemeData? theme) getProperty, Set<MaterialState> states) { + return effectiveValue( + (DatePickerThemeData? theme) { + return getProperty(theme)?.resolve(states); + }, + ); + } + + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final String semanticLabelSuffix = widget.isToday ? ', ${localizations.currentDateLabel}' : ''; + + final Set<MaterialState> states = <MaterialState>{ + if (widget.isDisabled) MaterialState.disabled, + if (widget.isSelectedDay) MaterialState.selected, + }; + + _statesController.value = states; + + final Color? dayForegroundColor = resolve<Color?>((DatePickerThemeData? theme) => widget.isToday ? theme?.todayForegroundColor : theme?.dayForegroundColor, states); + final Color? dayBackgroundColor = resolve<Color?>((DatePickerThemeData? theme) => widget.isToday ? theme?.todayBackgroundColor : theme?.dayBackgroundColor, states); + final MaterialStateProperty<Color?> dayOverlayColor = MaterialStateProperty.resolveWith<Color?>( + (Set<MaterialState> states) => effectiveValue((DatePickerThemeData? theme) => theme?.dayOverlayColor?.resolve(states)), + ); + final BoxDecoration decoration = widget.isToday + ? BoxDecoration( + color: dayBackgroundColor, + border: Border.fromBorderSide( + (datePickerTheme.todayBorder ?? defaults.todayBorder!) + .copyWith(color: dayForegroundColor) + ), + shape: BoxShape.circle, + ) + : BoxDecoration( + color: dayBackgroundColor, + shape: BoxShape.circle, + ); + + Widget dayWidget = Container( + decoration: decoration, + child: Center( + child: Text(localizations.formatDecimal(widget.day.day), style: dayStyle?.apply(color: dayForegroundColor)), + ), + ); + + if (widget.isDisabled) { + dayWidget = ExcludeSemantics( + child: dayWidget, + ); + } else { + dayWidget = InkResponse( + focusNode: widget.focusNode, + onTap: () => widget.onChanged(widget.day), + radius: _dayPickerRowHeight / 2 + 4, + statesController: _statesController, + overlayColor: dayOverlayColor, + child: Semantics( + // We want the day of month to be spoken first irrespective of the + // locale-specific preferences or TextDirection. This is because + // an accessibility user is more likely to be interested in the + // day of month before the rest of the date, as they are looking + // for the day of month. To do that we prepend day of month to the + // formatted full date. + label: '${localizations.formatDecimal(widget.day.day)}, ${localizations.formatFullDate(widget.day)}$semanticLabelSuffix', + // Set button to true to make the date selectable. + button: true, + selected: widget.isSelectedDay, + excludeSemantics: true, + child: dayWidget, + ), + ); + } + + return dayWidget; + } + + @override + void dispose() { + _statesController.dispose(); + super.dispose(); + } +} + +class _DayPickerGridDelegate extends SliverGridDelegate { + const _DayPickerGridDelegate(); + + @override + SliverGridLayout getLayout(SliverConstraints constraints) { + const int columnCount = DateTime.daysPerWeek; + final double tileWidth = constraints.crossAxisExtent / columnCount; + final double tileHeight = math.min( + _dayPickerRowHeight, + constraints.viewportMainAxisExtent / (_maxDayPickerRowCount + 1), + ); + return SliverGridRegularTileLayout( + childCrossAxisExtent: tileWidth, + childMainAxisExtent: tileHeight, + crossAxisCount: columnCount, + crossAxisStride: tileWidth, + mainAxisStride: tileHeight, + reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), + ); + } + + @override + bool shouldRelayout(_DayPickerGridDelegate oldDelegate) => false; +} + +const _DayPickerGridDelegate _dayPickerGridDelegate = _DayPickerGridDelegate(); + +/// A scrollable grid of years to allow picking a year. +/// +/// The year picker widget is rarely used directly. Instead, consider using +/// [CalendarDatePicker], or [showDatePicker] which create full date pickers. +/// +/// See also: +/// +/// * [CalendarDatePicker], which provides a Material Design date picker +/// interface. +/// +/// * [showDatePicker], which shows a dialog containing a Material Design +/// date picker. +/// +class YearPicker extends StatefulWidget { + /// Creates a year picker. + /// + /// The [lastDate] must be after the [firstDate]. + YearPicker({ + super.key, + DateTime? currentDate, + required this.firstDate, + required this.lastDate, + @Deprecated( + 'This parameter has no effect and can be removed. Previously it controlled ' + 'the month that was used in "onChanged" when a new year was selected, but ' + 'now that role is filled by "selectedDate" instead. ' + 'This feature was deprecated after v3.13.0-0.3.pre.' + ) + DateTime? initialDate, + required this.selectedDate, + required this.onChanged, + this.dragStartBehavior = DragStartBehavior.start, + }) : assert(!firstDate.isAfter(lastDate)), + currentDate = DateUtils.dateOnly(currentDate ?? DateTime.now()); + + /// The current date. + /// + /// This date is subtly highlighted in the picker. + final DateTime currentDate; + + /// The earliest date the user is permitted to pick. + final DateTime firstDate; + + /// The latest date the user is permitted to pick. + final DateTime lastDate; + + /// The currently selected date. + /// + /// This date is highlighted in the picker. + final DateTime? selectedDate; + + /// Called when the user picks a year. + final ValueChanged<DateTime> onChanged; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + @override + State<YearPicker> createState() => _YearPickerState(); +} + +class _YearPickerState extends State<YearPicker> { + ScrollController? _scrollController; + final MaterialStatesController _statesController = MaterialStatesController(); + + // The approximate number of years necessary to fill the available space. + static const int minYears = 18; + + @override + void initState() { + super.initState(); + _scrollController = ScrollController(initialScrollOffset: _scrollOffsetForYear(widget.selectedDate ?? widget.firstDate)); + } + + @override + void dispose() { + _scrollController?.dispose(); + _statesController.dispose(); + super.dispose(); + } + + @override + void didUpdateWidget(YearPicker oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.selectedDate != oldWidget.selectedDate && widget.selectedDate != null) { + _scrollController!.jumpTo(_scrollOffsetForYear(widget.selectedDate!)); + } + } + + double _scrollOffsetForYear(DateTime date) { + final int initialYearIndex = date.year - widget.firstDate.year; + final int initialYearRow = initialYearIndex ~/ _yearPickerColumnCount; + // Move the offset down by 2 rows to approximately center it. + final int centeredYearRow = initialYearRow - 2; + return _itemCount < minYears ? 0 : centeredYearRow * _yearPickerRowHeight; + } + + Widget _buildYearItem(BuildContext context, int index) { + final DatePickerThemeData datePickerTheme = DatePickerTheme.of(context); + final DatePickerThemeData defaults = DatePickerTheme.defaults(context); + + T? effectiveValue<T>(T? Function(DatePickerThemeData? theme) getProperty) { + return getProperty(datePickerTheme) ?? getProperty(defaults); + } + + T? resolve<T>(MaterialStateProperty<T>? Function(DatePickerThemeData? theme) getProperty, Set<MaterialState> states) { + return effectiveValue( + (DatePickerThemeData? theme) { + return getProperty(theme)?.resolve(states); + }, + ); + } + + // Backfill the _YearPicker with disabled years if necessary. + final int offset = _itemCount < minYears ? (minYears - _itemCount) ~/ 2 : 0; + final int year = widget.firstDate.year + index - offset; + final bool isSelected = year == widget.selectedDate?.year; + final bool isCurrentYear = year == widget.currentDate.year; + final bool isDisabled = year < widget.firstDate.year || year > widget.lastDate.year; + const double decorationHeight = 36.0; + const double decorationWidth = 72.0; + + final Set<MaterialState> states = <MaterialState>{ + if (isDisabled) MaterialState.disabled, + if (isSelected) MaterialState.selected, + }; + + final Color? textColor = resolve<Color?>((DatePickerThemeData? theme) => isCurrentYear ? theme?.todayForegroundColor : theme?.yearForegroundColor, states); + final Color? background = resolve<Color?>((DatePickerThemeData? theme) => isCurrentYear ? theme?.todayBackgroundColor : theme?.yearBackgroundColor, states); + final MaterialStateProperty<Color?> overlayColor = + MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) => + effectiveValue((DatePickerThemeData? theme) => theme?.yearOverlayColor?.resolve(states)), + ); + + BoxBorder? border; + if (isCurrentYear) { + final BorderSide? todayBorder = datePickerTheme.todayBorder ?? defaults.todayBorder; + if (todayBorder != null) { + border = Border.fromBorderSide(todayBorder.copyWith(color: textColor)); + } + } + final BoxDecoration decoration = BoxDecoration( + border: border, + color: background, + borderRadius: BorderRadius.circular(decorationHeight / 2), + ); + + final TextStyle? itemStyle = (datePickerTheme.yearStyle ?? defaults.yearStyle)?.apply(color: textColor); + Widget yearItem = Center( + child: Container( + decoration: decoration, + height: decorationHeight, + width: decorationWidth, + child: Center( + child: Semantics( + selected: isSelected, + button: true, + child: Text(year.toString(), style: itemStyle), + ), + ), + ), + ); + + if (isDisabled) { + yearItem = ExcludeSemantics( + child: yearItem, + ); + } else { + DateTime date = DateTime(year, widget.selectedDate?.month ?? DateTime.january); + if (date.isBefore(DateTime(widget.firstDate.year, widget.firstDate.month))) { + // Ignore firstDate.day because we're just working in years and months here. + assert(date.year == widget.firstDate.year); + date = DateTime(year, widget.firstDate.month); + } else if (date.isAfter(widget.lastDate)) { + // No need to ignore the day here because it can only be bigger than what we care about. + assert(date.year == widget.lastDate.year); + date = DateTime(year, widget.lastDate.month); + } + _statesController.value = states; + yearItem = InkWell( + key: ValueKey<int>(year), + onTap: () => widget.onChanged(date), + statesController: _statesController, + overlayColor: overlayColor, + child: yearItem, + ); + } + + return yearItem; + } + + int get _itemCount { + return widget.lastDate.year - widget.firstDate.year + 1; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + return Column( + children: <Widget>[ + const Divider(), + Expanded( + child: GridView.builder( + controller: _scrollController, + dragStartBehavior: widget.dragStartBehavior, + gridDelegate: _yearPickerGridDelegate, + itemBuilder: _buildYearItem, + itemCount: math.max(_itemCount, minYears), + padding: const EdgeInsets.symmetric(horizontal: _yearPickerPadding), + ), + ), + const Divider(), + ], + ); + } +} + +class _YearPickerGridDelegate extends SliverGridDelegate { + const _YearPickerGridDelegate(); + + @override + SliverGridLayout getLayout(SliverConstraints constraints) { + final double tileWidth = + (constraints.crossAxisExtent - (_yearPickerColumnCount - 1) * _yearPickerRowSpacing) / _yearPickerColumnCount; + return SliverGridRegularTileLayout( + childCrossAxisExtent: tileWidth, + childMainAxisExtent: _yearPickerRowHeight, + crossAxisCount: _yearPickerColumnCount, + crossAxisStride: tileWidth + _yearPickerRowSpacing, + mainAxisStride: _yearPickerRowHeight, + reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), + ); + } + + @override + bool shouldRelayout(_YearPickerGridDelegate oldDelegate) => false; +} + +const _YearPickerGridDelegate _yearPickerGridDelegate = _YearPickerGridDelegate(); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/card.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/card.dart new file mode 100644 index 0000000000000000000000000000000000000000..cf23410d988c682f26b131d4fccce4db5a852360 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/card.dart @@ -0,0 +1,373 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'card_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'material.dart'; +import 'theme.dart'; + +enum _CardVariant { elevated, filled, outlined } + +/// A Material Design card: a panel with slightly rounded corners and an +/// elevation shadow. +/// +/// A card is a sheet of [Material] used to represent some related information, +/// for example an album, a geographical location, a meal, contact details, etc. +/// +/// This is what it looks like when run: +/// +/// ![A card with a slight shadow, consisting of two rows, one with an icon and +/// some text describing a musical, and the other with buttons for buying +/// tickets or listening to the show.](https://flutter.github.io/assets-for-api-docs/assets/material/card.png) +/// +/// {@tool dartpad} +/// This sample shows creation of a [Card] widget that shows album information +/// and two actions. +/// +/// ** See code in examples/api/lib/material/card/card.0.dart ** +/// {@end-tool} +/// +/// Sometimes the primary action area of a card is the card itself. Cards can be +/// one large touch target that shows a detail screen when tapped. +/// +/// {@tool dartpad} +/// This sample shows creation of a [Card] widget that can be tapped. When +/// tapped this [Card]'s [InkWell] displays an "ink splash" that fills the +/// entire card. +/// +/// ** See code in examples/api/lib/material/card/card.1.dart ** +/// {@end-tool} +/// +/// Material Design 3 introduced new types of cards. The default [Card] is the +/// elevated card. To create a filled card, use [Card.filled]; to create a outlined +/// card, use [Card.outlined]. +/// {@tool dartpad} +/// This sample shows creation of [Card] widgets for elevated, filled and +/// outlined types, as described in: https://m3.material.io/components/cards/overview +/// +/// ** See code in examples/api/lib/material/card/card.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListTile], to display icons and text in a card. +/// * [showDialog], to display a modal card. +/// * <https://material.io/design/components/cards.html> +/// * <https://m3.material.io/components/cards> +class Card extends StatelessWidget { + /// Creates a Material Design card. + /// + /// The [elevation] must be null or non-negative. + const Card({ + super.key, + this.color, + this.shadowColor, + this.surfaceTintColor, + this.elevation, + this.shape, + this.borderOnForeground = true, + this.margin, + this.clipBehavior, + this.child, + this.semanticContainer = true, + }) : assert(elevation == null || elevation >= 0.0), + _variant = _CardVariant.elevated; + + /// Create a filled variant of Card. + /// + /// Filled cards provide subtle separation from the background. This has less + /// emphasis than elevated(default) or outlined cards. + const Card.filled({ + super.key, + this.color, + this.shadowColor, + this.surfaceTintColor, + this.elevation, + this.shape, + this.borderOnForeground = true, + this.margin, + this.clipBehavior, + this.child, + this.semanticContainer = true, + }) : assert(elevation == null || elevation >= 0.0), + _variant = _CardVariant.filled; + + /// Create an outlined variant of Card. + /// + /// Outlined cards have a visual boundary around the container. This can + /// provide greater emphasis than the other types. + const Card.outlined({ + super.key, + this.color, + this.shadowColor, + this.surfaceTintColor, + this.elevation, + this.shape, + this.borderOnForeground = true, + this.margin, + this.clipBehavior, + this.child, + this.semanticContainer = true, + }) : assert(elevation == null || elevation >= 0.0), + _variant = _CardVariant.outlined; + + /// The card's background color. + /// + /// Defines the card's [Material.color]. + /// + /// In Material 3, [surfaceTintColor] is drawn on top of this color + /// when the card is elevated. This might make the appearance of + /// the card slightly different than in Material 2. To disable this + /// feature, set [surfaceTintColor] to [Colors.transparent]. + /// See [Material.surfaceTintColor] for more details. + /// + /// If this property is null then the ambient [CardTheme.color] is used. If that is null, + /// and [ThemeData.useMaterial3] is true, then [ColorScheme.surface] of + /// [ThemeData.colorScheme] is used. Otherwise, [ThemeData.cardColor] is used. + final Color? color; + + /// The color to paint the shadow below the card. + /// + /// If null then the ambient [CardTheme]'s shadowColor is used. + /// If that's null too, then the overall theme's [ThemeData.shadowColor] + /// (default black) is used. + final Color? shadowColor; + + /// The color used as an overlay on [color] to indicate elevation. + /// + /// If this is null, no overlay will be applied. Otherwise this color + /// will be composited on top of [color] with an opacity related + /// to [elevation] and used to paint the background of the card. + /// + /// The default is null. + /// + /// See [Material.surfaceTintColor] for more details on how this + /// overlay is applied. + final Color? surfaceTintColor; + + /// The z-coordinate at which to place this card. This controls the size of + /// the shadow below the card. + /// + /// Defines the card's [Material.elevation]. + /// + /// If this property is null then [CardTheme.elevation] of + /// [ThemeData.cardTheme] is used. If that's null, the default value is 1.0. + final double? elevation; + + /// The shape of the card's [Material]. + /// + /// Defines the card's [Material.shape]. + /// + /// If this property is null then [CardTheme.shape] of [ThemeData.cardTheme] + /// is used. If that's null then the shape will be a [RoundedRectangleBorder] + /// with a circular corner radius of 12.0 and if [ThemeData.useMaterial3] is + /// false, then the circular corner radius will be 4.0. + final ShapeBorder? shape; + + /// Whether to paint the [shape] border in front of the [child]. + /// + /// The default value is true. + /// If false, the border will be painted behind the [child]. + final bool borderOnForeground; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// If this property is null then [CardTheme.clipBehavior] of + /// [ThemeData.cardTheme] is used. If that's null then the behavior will be [Clip.none]. + final Clip? clipBehavior; + + /// The empty space that surrounds the card. + /// + /// Defines the card's outer [Container.margin]. + /// + /// If this property is null then [CardTheme.margin] of + /// [ThemeData.cardTheme] is used. If that's null, the default margin is 4.0 + /// logical pixels on all sides: `EdgeInsets.all(4.0)`. + final EdgeInsetsGeometry? margin; + + /// Whether this widget represents a single semantic container, or if false + /// a collection of individual semantic nodes. + /// + /// Defaults to true. + /// + /// Setting this flag to true will attempt to merge all child semantics into + /// this node. Setting this flag to false will force all child semantic nodes + /// to be explicit. + /// + /// This flag should be false if the card contains multiple different types + /// of content. + final bool semanticContainer; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + final _CardVariant _variant; + + @override + Widget build(BuildContext context) { + final CardTheme cardTheme = CardTheme.of(context); + final CardTheme defaults; + if (Theme.of(context).useMaterial3) { + switch (_variant) { + case _CardVariant.elevated: + defaults = _CardDefaultsM3(context); + case _CardVariant.filled: + defaults = _FilledCardDefaultsM3(context); + case _CardVariant.outlined: + defaults = _OutlinedCardDefaultsM3(context); + } + } else { + defaults = _CardDefaultsM2(context); + } + + return Semantics( + container: semanticContainer, + child: Container( + margin: margin ?? cardTheme.margin ?? defaults.margin!, + child: Material( + type: MaterialType.card, + color: color ?? cardTheme.color ?? defaults.color, + shadowColor: shadowColor ?? cardTheme.shadowColor ?? defaults.shadowColor, + surfaceTintColor: surfaceTintColor ?? cardTheme.surfaceTintColor ?? defaults.surfaceTintColor, + elevation: elevation ?? cardTheme.elevation ?? defaults.elevation!, + shape: shape ?? cardTheme.shape ?? defaults.shape, + borderOnForeground: borderOnForeground, + clipBehavior: clipBehavior ?? cardTheme.clipBehavior ?? defaults.clipBehavior!, + child: Semantics( + explicitChildNodes: !semanticContainer, + child: child, + ), + ), + ), + ); + } +} + +// Hand coded defaults based on Material Design 2. +class _CardDefaultsM2 extends CardTheme { + const _CardDefaultsM2(this.context) + : super( + clipBehavior: Clip.none, + elevation: 1.0, + margin: const EdgeInsets.all(4.0), + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(4.0)), + ) + ); + + final BuildContext context; + + @override + Color? get color => Theme.of(context).cardColor; + + @override + Color? get shadowColor => Theme.of(context).shadowColor; +} + +// BEGIN GENERATED TOKEN PROPERTIES - Card + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _CardDefaultsM3 extends CardTheme { + _CardDefaultsM3(this.context) + : super( + clipBehavior: Clip.none, + elevation: 1.0, + margin: const EdgeInsets.all(4.0), + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + Color? get color => _colors.surface; + + @override + Color? get shadowColor => _colors.shadow; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + ShapeBorder? get shape =>const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))); +} + +// END GENERATED TOKEN PROPERTIES - Card + +// BEGIN GENERATED TOKEN PROPERTIES - FilledCard + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _FilledCardDefaultsM3 extends CardTheme { + _FilledCardDefaultsM3(this.context) + : super( + clipBehavior: Clip.none, + elevation: 0.0, + margin: const EdgeInsets.all(4.0), + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + Color? get color => _colors.surfaceVariant; + + @override + Color? get shadowColor => _colors.shadow; + + @override + Color? get surfaceTintColor => Colors.transparent; + + @override + ShapeBorder? get shape =>const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))); +} + +// END GENERATED TOKEN PROPERTIES - FilledCard + +// BEGIN GENERATED TOKEN PROPERTIES - OutlinedCard + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _OutlinedCardDefaultsM3 extends CardTheme { + _OutlinedCardDefaultsM3(this.context) + : super( + clipBehavior: Clip.none, + elevation: 0.0, + margin: const EdgeInsets.all(4.0), + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + Color? get color => _colors.surface; + + @override + Color? get shadowColor => _colors.shadow; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + ShapeBorder? get shape => + const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))).copyWith( + side: BorderSide(color: _colors.outlineVariant) + ); +} + +// END GENERATED TOKEN PROPERTIES - OutlinedCard diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/card_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/card_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..dc54666cd04480a6ea783bf579ed7c9f0142108c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/card_theme.dart @@ -0,0 +1,170 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +/// Defines default property values for descendant [Card] widgets. +/// +/// Descendant widgets obtain the current [CardTheme] object using +/// `CardTheme.of(context)`. Instances of [CardTheme] can be +/// customized with [CardTheme.copyWith]. +/// +/// Typically a [CardTheme] is specified as part of the overall [Theme] +/// with [ThemeData.cardTheme]. +/// +/// All [CardTheme] properties are `null` by default. When null, the [Card] +/// will use the values from [ThemeData] if they exist, otherwise it will +/// provide its own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class CardTheme with Diagnosticable { + + /// Creates a theme that can be used for [ThemeData.cardTheme]. + /// + /// The [elevation] must be null or non-negative. + const CardTheme({ + this.clipBehavior, + this.color, + this.shadowColor, + this.surfaceTintColor, + this.elevation, + this.margin, + this.shape, + }) : assert(elevation == null || elevation >= 0.0); + + /// Overrides the default value for [Card.clipBehavior]. + /// + /// If null, [Card] uses [Clip.none]. + final Clip? clipBehavior; + + /// Overrides the default value for [Card.color]. + /// + /// If null, [Card] uses [ThemeData.cardColor]. + final Color? color; + + /// Overrides the default value for [Card.shadowColor]. + /// + /// If null, [Card] defaults to fully opaque black. + final Color? shadowColor; + + /// Overrides the default value for [Card.surfaceTintColor]. + /// + /// If null, [Card] will not display an overlay color. + /// + /// See [Material.surfaceTintColor] for more details. + final Color? surfaceTintColor; + + /// Overrides the default value for [Card.elevation]. + /// + /// If null, [Card] uses a default of 1.0. + final double? elevation; + + /// Overrides the default value for [Card.margin]. + /// + /// If null, [Card] uses a default margin of 4.0 logical pixels on all sides: + /// `EdgeInsets.all(4.0)`. + final EdgeInsetsGeometry? margin; + + /// Overrides the default value for [Card.shape]. + /// + /// If null, [Card] then uses a [RoundedRectangleBorder] with a circular + /// corner radius of 12.0 and if [ThemeData.useMaterial3] is false, + /// then the circular corner radius will be 4.0. + final ShapeBorder? shape; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + CardTheme copyWith({ + Clip? clipBehavior, + Color? color, + Color? shadowColor, + Color? surfaceTintColor, + double? elevation, + EdgeInsetsGeometry? margin, + ShapeBorder? shape, + }) { + return CardTheme( + clipBehavior: clipBehavior ?? this.clipBehavior, + color: color ?? this.color, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + elevation: elevation ?? this.elevation, + margin: margin ?? this.margin, + shape: shape ?? this.shape, + ); + } + + /// The [ThemeData.cardTheme] property of the ambient [Theme]. + static CardTheme of(BuildContext context) { + return Theme.of(context).cardTheme; + } + + /// Linearly interpolate between two Card themes. + /// + /// {@macro dart.ui.shadow.lerp} + static CardTheme lerp(CardTheme? a, CardTheme? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return CardTheme( + clipBehavior: t < 0.5 ? a?.clipBehavior : b?.clipBehavior, + color: Color.lerp(a?.color, b?.color, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + margin: EdgeInsetsGeometry.lerp(a?.margin, b?.margin, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + ); + } + + @override + int get hashCode => Object.hash( + clipBehavior, + color, + shadowColor, + surfaceTintColor, + elevation, + margin, + shape, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is CardTheme + && other.clipBehavior == clipBehavior + && other.color == color + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.elevation == elevation + && other.margin == margin + && other.shape == shape; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior, defaultValue: null)); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('margin', margin, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/carousel.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/carousel.dart new file mode 100644 index 0000000000000000000000000000000000000000..1a0e58678887bc6eb4913974e74d04135920acf4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/carousel.dart @@ -0,0 +1,750 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'theme.dart'; + +/// A Material Design carousel widget. +/// +/// The [CarouselView] present a scrollable list of items, each of which can dynamically +/// change size based on the chosen layout. +/// +/// This widget supports uncontained carousel layout. It shows items that scroll +/// to the edge of the container, behaving similarly to a [ListView] where all +/// children are a uniform size. +/// +/// The [CarouselController] is used to control the [CarouselController.initialItem]. +/// +/// The [CarouselView.itemExtent] property must be non-null and defines the base +/// size of items. While items typically maintain this size, the first and last +/// visible items may be slightly compressed during scrolling. The [shrinkExtent] +/// property controls the minimum allowable size for these compressed items. +/// +/// {@tool dartpad} +/// Here is an example of [CarouselView] to show the uncontained layout. Each carousel +/// item has the same size but can be "squished" to the [shrinkExtent] when they +/// are show on the view and out of view. +/// +/// ** See code in examples/api/lib/material/carousel/carousel.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CarouselController], which controls the first visible item in the carousel. +/// * [PageView], which is a scrollable list that works page by page. +class CarouselView extends StatefulWidget { + /// Creates a Material Design carousel. + const CarouselView({ + super.key, + this.padding, + this.backgroundColor, + this.elevation, + this.shape, + this.overlayColor, + this.itemSnapping = false, + this.shrinkExtent = 0.0, + this.controller, + this.scrollDirection = Axis.horizontal, + this.reverse = false, + this.onTap, + required this.itemExtent, + required this.children, + }); + + /// The amount of space to surround each carousel item with. + /// + /// Defaults to [EdgeInsets.all] of 4 pixels. + final EdgeInsets? padding; + + /// The background color for each carousel item. + /// + /// Defaults to [ColorScheme.surface]. + final Color? backgroundColor; + + /// The z-coordinate of each carousel item. + /// + /// Defaults to 0.0. + final double? elevation; + + /// The shape of each carousel item's [Material]. + /// + /// Defines each item's [Material.shape]. + /// + /// Defaults to a [RoundedRectangleBorder] with a circular corner radius + /// of 28.0. + final ShapeBorder? shape; + + /// The highlight color to indicate the carousel items are in pressed, hovered + /// or focused states. + /// + /// The default values are: + /// * [WidgetState.pressed] - [ColorScheme.onSurface] with an opacity of 0.1 + /// * [WidgetState.hovered] - [ColorScheme.onSurface] with an opacity of 0.08 + /// * [WidgetState.focused] - [ColorScheme.onSurface] with an opacity of 0.1 + final WidgetStateProperty<Color?>? overlayColor; + + /// The minimum allowable extent (size) in the main axis for carousel items + /// during scrolling transitions. + /// + /// As the carousel scrolls, the first visible item is pinned and gradually + /// shrinks until it reaches this minimum extent before scrolling off-screen. + /// Similarly, the last visible item enters the viewport at this minimum size + /// and expands to its full [itemExtent]. + /// + /// In cases where the remaining viewport space for the last visible item is + /// larger than the defined [shrinkExtent], the [shrinkExtent] is dynamically + /// adjusted to match this remaining space, ensuring a smooth size transition. + /// + /// Defaults to 0.0. Setting to 0.0 allows items to shrink/expand completely, + /// transitioning between 0.0 and the full [itemExtent]. In cases where the + /// remaining viewport space for the last visible item is larger than the + /// defined [shrinkExtent], the [shrinkExtent] is dynamically adjusted to match + /// this remaining space, ensuring a smooth size transition. + final double shrinkExtent; + + /// Whether the carousel should keep scrolling to the next/previous items to + /// maintain the original layout. + /// + /// Defaults to false. + final bool itemSnapping; + + /// An object that can be used to control the position to which this scroll + /// view is scrolled. + final CarouselController? controller; + + /// The [Axis] along which the scroll view's offset increases with each item. + /// + /// Defaults to [Axis.horizontal]. + final Axis scrollDirection; + + /// Whether the carousel list scrolls in the reading direction. + /// + /// For example, if the reading direction is left-to-right and + /// [scrollDirection] is [Axis.horizontal], then the carousel scrolls from + /// left to right when [reverse] is false and from right to left when + /// [reverse] is true. + /// + /// Similarly, if [scrollDirection] is [Axis.vertical], then the carousel view + /// scrolls from top to bottom when [reverse] is false and from bottom to top + /// when [reverse] is true. + /// + /// Defaults to false. + final bool reverse; + + /// Called when one of the [children] is tapped. + final ValueChanged<int>? onTap; + + /// The extent the children are forced to have in the main axis. + /// + /// The item extent should not exceed the available space that the carousel + /// occupies to ensure at least one item is fully visible. + /// + /// This must be non-null. + final double itemExtent; + + /// The child widgets for the carousel. + final List<Widget> children; + + @override + State<CarouselView> createState() => _CarouselViewState(); +} + +class _CarouselViewState extends State<CarouselView> { + late double _itemExtent; + CarouselController? _internalController; + CarouselController get _controller => widget.controller ?? _internalController!; + + @override + void initState() { + super.initState(); + if (widget.controller == null) { + _internalController = CarouselController(); + } + _controller._attach(this); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _itemExtent = widget.itemExtent; + } + + @override + void didUpdateWidget(covariant CarouselView oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.controller != oldWidget.controller) { + oldWidget.controller?._detach(this); + if (widget.controller != null) { + _internalController?._detach(this); + _internalController = null; + widget.controller?._attach(this); + } else { // widget.controller == null && oldWidget.controller != null + assert(_internalController == null); + _internalController = CarouselController(); + _controller._attach(this); + } + } + if (widget.itemExtent != oldWidget.itemExtent) { + _itemExtent = widget.itemExtent; + } + } + + @override + void dispose() { + _controller._detach(this); + _internalController?.dispose(); + super.dispose(); + } + + AxisDirection _getDirection(BuildContext context) { + switch (widget.scrollDirection) { + case Axis.horizontal: + assert(debugCheckHasDirectionality(context)); + final TextDirection textDirection = Directionality.of(context); + final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection); + return widget.reverse ? flipAxisDirection(axisDirection) : axisDirection; + case Axis.vertical: + return widget.reverse ? AxisDirection.up : AxisDirection.down; + } + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final AxisDirection axisDirection = _getDirection(context); + final ScrollPhysics physics = widget.itemSnapping + ? const CarouselScrollPhysics() + : ScrollConfiguration.of(context).getScrollPhysics(context); + final EdgeInsets effectivePadding = widget.padding ?? const EdgeInsets.all(4.0); + final Color effectiveBackgroundColor = widget.backgroundColor ?? Theme.of(context).colorScheme.surface; + final double effectiveElevation = widget.elevation ?? 0.0; + final ShapeBorder effectiveShape = widget.shape + ?? const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(28.0)) + ); + + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + final double mainAxisExtent = switch (widget.scrollDirection) { + Axis.horizontal => constraints.maxWidth, + Axis.vertical => constraints.maxHeight, + }; + _itemExtent = clampDouble(_itemExtent, 0, mainAxisExtent); + + return Scrollable( + axisDirection: axisDirection, + controller: _controller, + physics: physics, + viewportBuilder: (BuildContext context, ViewportOffset position) { + return Viewport( + cacheExtent: 0.0, + cacheExtentStyle: CacheExtentStyle.viewport, + axisDirection: axisDirection, + offset: position, + clipBehavior: Clip.antiAlias, + slivers: <Widget>[ + _SliverFixedExtentCarousel( + itemExtent: _itemExtent, + minExtent: widget.shrinkExtent, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return Padding( + padding: effectivePadding, + child: Material( + clipBehavior: Clip.antiAlias, + color: effectiveBackgroundColor, + elevation: effectiveElevation, + shape: effectiveShape, + child: Stack( + fit: StackFit.expand, + children: <Widget>[ + widget.children.elementAt(index), + Material( + color: Colors.transparent, + child: InkWell( + onTap: () { + widget.onTap?.call(index); + }, + overlayColor: widget.overlayColor ?? WidgetStateProperty.resolveWith((Set<WidgetState> states) { + if (states.contains(WidgetState.pressed)) { + return theme.colorScheme.onSurface.withOpacity(0.1); + } + if (states.contains(WidgetState.hovered)) { + return theme.colorScheme.onSurface.withOpacity(0.08); + } + if (states.contains(WidgetState.focused)) { + return theme.colorScheme.onSurface.withOpacity(0.1); + } + return null; + }), + ), + ), + ], + ), + ), + ); + }, + childCount: widget.children.length, + ), + ), + ], + ); + }, + ); + } + ); + } +} + +/// A sliver that displays its box children in a linear array with a fixed extent +/// per item. +/// +/// _To learn more about slivers, see [CustomScrollView.slivers]._ +/// +/// This sliver list arranges its children in a line along the main axis starting +/// at offset zero and without gaps. Each child is constrained to a fixed extent +/// along the main axis and the [SliverConstraints.crossAxisExtent] +/// along the cross axis. The difference between this and a list view with a fixed +/// extent is the first item and last item can be squished a little during scrolling +/// transition. This compression is controlled by the `minExtent` property and +/// aligns with the [Material Design Carousel specifications] +/// (https://m3.material.io/components/carousel/guidelines#96c5c157-fe5b-4ee3-a9b4-72bf8efab7e9). +class _SliverFixedExtentCarousel extends SliverMultiBoxAdaptorWidget { + const _SliverFixedExtentCarousel({ + required super.delegate, + required this.minExtent, + required this.itemExtent, + }); + + final double itemExtent; + final double minExtent; + + @override + RenderSliverFixedExtentBoxAdaptor createRenderObject(BuildContext context) { + final SliverMultiBoxAdaptorElement element = context as SliverMultiBoxAdaptorElement; + return _RenderSliverFixedExtentCarousel( + childManager: element, + minExtent: minExtent, + maxExtent: itemExtent, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderSliverFixedExtentCarousel renderObject) { + renderObject.maxExtent = itemExtent; + renderObject.minExtent = itemExtent; + } +} + +class _RenderSliverFixedExtentCarousel extends RenderSliverFixedExtentBoxAdaptor { + _RenderSliverFixedExtentCarousel({ + required super.childManager, + required double maxExtent, + required double minExtent, + }) : _maxExtent = maxExtent, + _minExtent = minExtent; + + double get maxExtent => _maxExtent; + double _maxExtent; + set maxExtent(double value) { + if (_maxExtent == value) { + return; + } + _maxExtent = value; + markNeedsLayout(); + } + + double get minExtent => _minExtent; + double _minExtent; + set minExtent(double value) { + if (_minExtent == value) { + return; + } + _minExtent = value; + markNeedsLayout(); + } + + // This implements the [itemExtentBuilder] callback. + double _buildItemExtent(int index, SliverLayoutDimensions currentLayoutDimensions) { + final int firstVisibleIndex = (constraints.scrollOffset / maxExtent).floor(); + + // Calculate how many items have been completely scroll off screen. + final int offscreenItems = (constraints.scrollOffset / maxExtent).floor(); + + // If an item is partially off screen and partially on screen, + // `constraints.scrollOffset` must be greater than + // `offscreenItems * maxExtent`, so the difference between these two is how + // much the current first visible item is off screen. + final double offscreenExtent = constraints.scrollOffset - offscreenItems * maxExtent; + + // If there is not enough space to place the last visible item but the remaining + // space is larger than `minExtent`, the extent for last item should be at + // least the remaining extent to ensure a smooth size transition. + final double effectiveMinExtent = math.max(constraints.remainingPaintExtent % maxExtent, minExtent); + + // Two special cases are the first and last visible items. Other items' extent + // should all return `maxExtent`. + if (index == firstVisibleIndex) { + final double effectiveExtent = maxExtent - offscreenExtent; + return math.max(effectiveExtent, effectiveMinExtent); + } + + final double scrollOffsetForLastIndex = constraints.scrollOffset + constraints.remainingPaintExtent; + if (index == getMaxChildIndexForScrollOffset(scrollOffsetForLastIndex, maxExtent)) { + return clampDouble(scrollOffsetForLastIndex - maxExtent * index, effectiveMinExtent, maxExtent); + } + + return maxExtent; + } + + late SliverLayoutDimensions _currentLayoutDimensions; + + @override + void performLayout() { + _currentLayoutDimensions = SliverLayoutDimensions( + scrollOffset: constraints.scrollOffset, + precedingScrollExtent: constraints.precedingScrollExtent, + viewportMainAxisExtent: constraints.viewportMainAxisExtent, + crossAxisExtent: constraints.crossAxisExtent, + ); + super.performLayout(); + } + + /// The layout offset for the child with the given index. + @override + double indexToLayoutOffset( + @Deprecated( + 'The itemExtent is already available within the scope of this function. ' + 'This feature was deprecated after v3.20.0-7.0.pre.' + ) + double itemExtent, + int index, + ) { + final int firstVisibleIndex = (constraints.scrollOffset / maxExtent).floor(); + + // If there is not enough space to place the last visible item but the remaining + // space is larger than `minExtent`, the extent for last item should be at + // least the remaining extent to make sure a smooth size transition. + final double effectiveMinExtent = math.max(constraints.remainingPaintExtent % maxExtent, minExtent); + if (index == firstVisibleIndex) { + final double firstVisibleItemExtent = _buildItemExtent(index, _currentLayoutDimensions); + + // If the first item is squished to be less than `effectievMinExtent`, + // then it should stop changinng its size and should start to scroll off screen. + if (firstVisibleItemExtent <= effectiveMinExtent) { + return maxExtent * index - effectiveMinExtent + maxExtent; + } + return constraints.scrollOffset; + } + return maxExtent * index; + } + + /// The minimum child index that is visible at the given scroll offset. + @override + int getMinChildIndexForScrollOffset( + double scrollOffset, + @Deprecated( + 'The itemExtent is already available within the scope of this function. ' + 'This feature was deprecated after v3.20.0-7.0.pre.' + ) + double itemExtent, + ) { + final int firstVisibleIndex = (constraints.scrollOffset / maxExtent).floor(); + return math.max(firstVisibleIndex, 0); + } + + /// The maximum child index that is visible at the given scroll offset. + @override + int getMaxChildIndexForScrollOffset( + double scrollOffset, + @Deprecated( + 'The itemExtent is already available within the scope of this function. ' + 'This feature was deprecated after v3.20.0-7.0.pre.' + ) + double itemExtent, + ) { + if (maxExtent > 0.0) { + final double actual = scrollOffset / maxExtent - 1; + final int round = actual.round(); + if ((actual * maxExtent - round * maxExtent).abs() < precisionErrorTolerance) { + return math.max(0, round); + } + return math.max(0, actual.ceil()); + } + return 0; + } + + @override + double? get itemExtent => null; + + @override + ItemExtentBuilder? get itemExtentBuilder => _buildItemExtent; +} + +/// Scroll physics used by a [CarouselView]. +/// +/// These physics cause the carousel item to snap to item boundaries. +/// +/// See also: +/// +/// * [ScrollPhysics], the base class which defines the API for scrolling +/// physics. +/// * [PageScrollPhysics], scroll physics used by a [PageView]. +class CarouselScrollPhysics extends ScrollPhysics { + /// Creates physics for a [CarouselView]. + const CarouselScrollPhysics({super.parent}); + + @override + CarouselScrollPhysics applyTo(ScrollPhysics? ancestor) { + return CarouselScrollPhysics(parent: buildParent(ancestor)); + } + + double _getTargetPixels( + _CarouselPosition position, + Tolerance tolerance, + double velocity, + ) { + double fraction; + fraction = position.itemExtent! / position.viewportDimension; + + final double itemWidth = position.viewportDimension * fraction; + + final double actual = math.max(0.0, position.pixels) / itemWidth; + final double round = actual.roundToDouble(); + double item; + if ((actual - round).abs() < precisionErrorTolerance) { + item = round; + } else { + item = actual; + } + if (velocity < -tolerance.velocity) { + item -= 0.5; + } else if (velocity > tolerance.velocity) { + item += 0.5; + } + return item.roundToDouble() * itemWidth; + } + + @override + Simulation? createBallisticSimulation( + ScrollMetrics position, + double velocity, + ) { + assert( + position is _CarouselPosition, + 'CarouselScrollPhysics can only be used with Scrollables that uses ' + 'the CarouselController', + ); + + final _CarouselPosition metrics = position as _CarouselPosition; + if ((velocity <= 0.0 && metrics.pixels <= metrics.minScrollExtent) || + (velocity >= 0.0 && metrics.pixels >= metrics.maxScrollExtent)) { + return super.createBallisticSimulation(metrics, velocity); + } + + final Tolerance tolerance = toleranceFor(metrics); + final double target = _getTargetPixels(metrics, tolerance, velocity); + if (target != metrics.pixels) { + return ScrollSpringSimulation( + spring, + metrics.pixels, + target, + velocity, + tolerance: tolerance, + ); + } + return null; + } + + @override + bool get allowImplicitScrolling => true; +} + +/// Metrics for a [CarouselView]. +class _CarouselMetrics extends FixedScrollMetrics { + /// Creates an immutable snapshot of values associated with a [CarouselView]. + _CarouselMetrics({ + required super.minScrollExtent, + required super.maxScrollExtent, + required super.pixels, + required super.viewportDimension, + required super.axisDirection, + this.itemExtent, + required super.devicePixelRatio, + }); + + /// Extent for the carousel item. + /// + /// Used to compute the first item from the current [pixels]. + final double? itemExtent; + + @override + _CarouselMetrics copyWith({ + double? minScrollExtent, + double? maxScrollExtent, + double? pixels, + double? viewportDimension, + AxisDirection? axisDirection, + double? itemExtent, + double? devicePixelRatio, + }) { + return _CarouselMetrics( + minScrollExtent: minScrollExtent ?? (hasContentDimensions ? this.minScrollExtent : null), + maxScrollExtent: maxScrollExtent ?? (hasContentDimensions ? this.maxScrollExtent : null), + pixels: pixels ?? (hasPixels ? this.pixels : null), + viewportDimension: viewportDimension ?? (hasViewportDimension ? this.viewportDimension : null), + axisDirection: axisDirection ?? this.axisDirection, + itemExtent: itemExtent ?? this.itemExtent, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + ); + } +} + +class _CarouselPosition extends ScrollPositionWithSingleContext implements _CarouselMetrics { + _CarouselPosition({ + required super.physics, + required super.context, + this.initialItem = 0, + required this.itemExtent, + super.oldPosition, + }) : _itemToShowOnStartup = initialItem.toDouble(), + super( + initialPixels: null + ); + + final int initialItem; + final double _itemToShowOnStartup; + // When the viewport has a zero-size, the item can not + // be retrieved by `getItemFromPixels`, so we need to cache the item + // for use when resizing the viewport to non-zero next time. + double? _cachedItem; + + @override + double? itemExtent; + + double getItemFromPixels(double pixels, double viewportDimension) { + assert(viewportDimension > 0.0); + final double fraction = itemExtent! / viewportDimension; + + final double actual = math.max(0.0, pixels) / (viewportDimension * fraction); + final double round = actual.roundToDouble(); + if ((actual - round).abs() < precisionErrorTolerance) { + return round; + } + return actual; + } + + double getPixelsFromItem(double item) { + final double fraction = itemExtent! / viewportDimension; + + return item * viewportDimension * fraction; + } + + @override + bool applyViewportDimension(double viewportDimension) { + final double? oldViewportDimensions = hasViewportDimension ? this.viewportDimension : null; + if (viewportDimension == oldViewportDimensions) { + return true; + } + final bool result = super.applyViewportDimension(viewportDimension); + final double? oldPixels = hasPixels ? pixels : null; + double item; + if (oldPixels == null) { + item = _itemToShowOnStartup; + } else if (oldViewportDimensions == 0.0) { + // If resize from zero, we should use the _cachedItem to recover the state. + item = _cachedItem!; + } else { + item = getItemFromPixels(oldPixels, oldViewportDimensions!); + } + final double newPixels = getPixelsFromItem(item); + // If the viewportDimension is zero, cache the item + // in case the viewport is resized to be non-zero. + _cachedItem = (viewportDimension == 0.0) ? item : null; + + if (newPixels != oldPixels) { + correctPixels(newPixels); + return false; + } + return result; + } + + @override + _CarouselMetrics copyWith({ + double? minScrollExtent, + double? maxScrollExtent, + double? pixels, + double? viewportDimension, + AxisDirection? axisDirection, + double? itemExtent, + List<int>? layoutWeights, + double? devicePixelRatio, + }) { + return _CarouselMetrics( + minScrollExtent: minScrollExtent ?? (hasContentDimensions ? this.minScrollExtent : null), + maxScrollExtent: maxScrollExtent ?? (hasContentDimensions ? this.maxScrollExtent : null), + pixels: pixels ?? (hasPixels ? this.pixels : null), + viewportDimension: viewportDimension ?? (hasViewportDimension ? this.viewportDimension : null), + axisDirection: axisDirection ?? this.axisDirection, + itemExtent: itemExtent ?? this.itemExtent, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + ); + } +} + +/// A controller for [CarouselView]. +/// +/// Using a carousel controller helps to show the first visible item on the +/// carousel list. +class CarouselController extends ScrollController { + /// Creates a carousel controller. + CarouselController({ + this.initialItem = 0, + }); + + /// The item that expands to the maximum size when first creating the [CarouselView]. + final int initialItem; + + _CarouselViewState? _carouselState; + + // ignore: use_setters_to_change_properties + void _attach(_CarouselViewState anchor) { + _carouselState = anchor; + } + + void _detach(_CarouselViewState anchor) { + if (_carouselState == anchor) { + _carouselState = null; + } + } + + @override + ScrollPosition createScrollPosition(ScrollPhysics physics, ScrollContext context, ScrollPosition? oldPosition) { + assert(_carouselState != null); + final double itemExtent = _carouselState!._itemExtent; + + return _CarouselPosition( + physics: physics, + context: context, + initialItem: initialItem, + itemExtent: itemExtent, + oldPosition: oldPosition, + ); + } + + @override + void attach(ScrollPosition position) { + super.attach(position); + final _CarouselPosition carouselPosition = position as _CarouselPosition; + carouselPosition.itemExtent = _carouselState!._itemExtent; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/checkbox.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/checkbox.dart new file mode 100644 index 0000000000000000000000000000000000000000..c6bd10b8a15d16281fdfee7b0beea8eab37c54bb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/checkbox.dart @@ -0,0 +1,1030 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; + +import 'checkbox_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'material_state.dart'; +import 'theme.dart'; +import 'theme_data.dart'; +import 'toggleable.dart'; + +// Examples can assume: +// bool _throwShotAway = false; +// late StateSetter setState; + +enum _CheckboxType { material, adaptive } + +/// A Material Design checkbox. +/// +/// The checkbox itself does not maintain any state. Instead, when the state of +/// the checkbox changes, the widget calls the [onChanged] callback. Most +/// widgets that use a checkbox will listen for the [onChanged] callback and +/// rebuild the checkbox with a new [value] to update the visual appearance of +/// the checkbox. +/// +/// The checkbox can optionally display three values - true, false, and null - +/// if [tristate] is true. When [value] is null a dash is displayed. By default +/// [tristate] is false and the checkbox's [value] must be true or false. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// {@tool dartpad} +/// This example shows how you can override the default theme of +/// a [Checkbox] with a [MaterialStateProperty]. +/// In this example, the checkbox's color will be `Colors.blue` when the [Checkbox] +/// is being pressed, hovered, or focused. Otherwise, the checkbox's color will +/// be `Colors.red`. +/// +/// ** See code in examples/api/lib/material/checkbox/checkbox.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows what the checkbox error state looks like. +/// +/// ** See code in examples/api/lib/material/checkbox/checkbox.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CheckboxListTile], which combines this widget with a [ListTile] so that +/// you can give the checkbox a label. +/// * [Switch], a widget with semantics similar to [Checkbox]. +/// * [Radio], for selecting among a set of explicit values. +/// * [Slider], for selecting a value in a range. +/// * <https://material.io/design/components/selection-controls.html#checkboxes> +/// * <https://material.io/design/components/lists.html#types> +class Checkbox extends StatefulWidget { + /// Creates a Material Design checkbox. + /// + /// The checkbox itself does not maintain any state. Instead, when the state of + /// the checkbox changes, the widget calls the [onChanged] callback. Most + /// widgets that use a checkbox will listen for the [onChanged] callback and + /// rebuild the checkbox with a new [value] to update the visual appearance of + /// the checkbox. + /// + /// The following arguments are required: + /// + /// * [value], which determines whether the checkbox is checked. The [value] + /// can only be null if [tristate] is true. + /// * [onChanged], which is called when the value of the checkbox should + /// change. It can be set to null to disable the checkbox. + const Checkbox({ + super.key, + required this.value, + this.tristate = false, + required this.onChanged, + this.mouseCursor, + this.activeColor, + this.fillColor, + this.checkColor, + this.focusColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.materialTapTargetSize, + this.visualDensity, + this.focusNode, + this.autofocus = false, + this.shape, + this.side, + this.isError = false, + this.semanticLabel, + }) : _checkboxType = _CheckboxType.material, + assert(tristate || value != null); + + /// Creates an adaptive [Checkbox] based on whether the target platform is iOS + /// or macOS, following Material design's + /// [Cross-platform guidelines](https://material.io/design/platform-guidance/cross-platform-adaptation.html). + /// + /// On iOS and macOS, this constructor creates a [CupertinoCheckbox], which has + /// matching functionality and presentation as Material checkboxes, and are the + /// graphics expected on iOS. On other platforms, this creates a Material + /// design [Checkbox]. + /// + /// If a [CupertinoCheckbox] is created, the following parameters are ignored: + /// [mouseCursor], [fillColor], [hoverColor], [overlayColor], [splashRadius], + /// [materialTapTargetSize], [visualDensity], [isError]. However, [shape] and + /// [side] will still affect the [CupertinoCheckbox] and should be handled if + /// native fidelity is important. + /// + /// The target platform is based on the current [Theme]: [ThemeData.platform]. + const Checkbox.adaptive({ + super.key, + required this.value, + this.tristate = false, + required this.onChanged, + this.mouseCursor, + this.activeColor, + this.fillColor, + this.checkColor, + this.focusColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.materialTapTargetSize, + this.visualDensity, + this.focusNode, + this.autofocus = false, + this.shape, + this.side, + this.isError = false, + this.semanticLabel, + }) : _checkboxType = _CheckboxType.adaptive, + assert(tristate || value != null); + + /// Whether this checkbox is checked. + /// + /// When [tristate] is true, a value of null corresponds to the mixed state. + /// When [tristate] is false, this value must not be null. + final bool? value; + + /// Called when the value of the checkbox should change. + /// + /// The checkbox passes the new value to the callback but does not actually + /// change state until the parent widget rebuilds the checkbox with the new + /// value. + /// + /// If this callback is null, the checkbox will be displayed as disabled + /// and will not respond to input gestures. + /// + /// When the checkbox is tapped, if [tristate] is false (the default) then + /// the [onChanged] callback will be applied to `!value`. If [tristate] is + /// true this callback cycle from false to true to null. + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// Checkbox( + /// value: _throwShotAway, + /// onChanged: (bool? newValue) { + /// setState(() { + /// _throwShotAway = newValue!; + /// }); + /// }, + /// ) + /// ``` + final ValueChanged<bool?>? onChanged; + + /// {@template flutter.material.checkbox.mouseCursor} + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// {@endtemplate} + /// + /// When [value] is null and [tristate] is true, [MaterialState.selected] is + /// included as a state. + /// + /// If null, then the value of [CheckboxThemeData.mouseCursor] is used. If + /// that is also null, then [MaterialStateMouseCursor.clickable] is used. + /// + /// See also: + /// + /// * [MaterialStateMouseCursor], a [MouseCursor] that implements + /// `MaterialStateProperty` which is used in APIs that need to accept + /// either a [MouseCursor] or a [MaterialStateProperty<MouseCursor>]. + final MouseCursor? mouseCursor; + + /// The color to use when this checkbox is checked. + /// + /// Defaults to [ColorScheme.secondary]. + /// + /// If [fillColor] returns a non-null color in the [MaterialState.selected] + /// state, it will be used instead of this color. + final Color? activeColor; + + /// {@template flutter.material.checkbox.fillColor} + /// The color that fills the checkbox, in all [MaterialState]s. + /// + /// Resolves in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [fillColor] based on the current [MaterialState] + /// of the [Checkbox], providing a different [Color] when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Checkbox( + /// value: true, + /// onChanged: (_){}, + /// fillColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) { + /// if (states.contains(MaterialState.disabled)) { + /// return Colors.orange.withOpacity(.32); + /// } + /// return Colors.orange; + /// }) + /// ) + /// ``` + /// {@end-tool} + /// {@endtemplate} + /// + /// If null, then the value of [activeColor] is used in the selected + /// state. If that is also null, the value of [CheckboxThemeData.fillColor] + /// is used. If that is also null, then [ThemeData.disabledColor] is used in + /// the disabled state, [ColorScheme.secondary] is used in the + /// selected state, and [ThemeData.unselectedWidgetColor] is used in the + /// default state. + final MaterialStateProperty<Color?>? fillColor; + + /// {@template flutter.material.checkbox.checkColor} + /// The color to use for the check icon when this checkbox is checked. + /// {@endtemplate} + /// + /// If null, then the value of [CheckboxThemeData.checkColor] is used. If + /// that is also null, then Color(0xFFFFFFFF) is used. + final Color? checkColor; + + /// If true the checkbox's [value] can be true, false, or null. + /// + /// [Checkbox] displays a dash when its value is null. + /// + /// When a tri-state checkbox ([tristate] is true) is tapped, its [onChanged] + /// callback will be applied to true if the current value is false, to null if + /// value is true, and to false if value is null (i.e. it cycles through false + /// => true => null => false when tapped). + /// + /// If tristate is false (the default), [value] must not be null. + final bool tristate; + + /// {@template flutter.material.checkbox.materialTapTargetSize} + /// Configures the minimum size of the tap target. + /// {@endtemplate} + /// + /// If null, then the value of [CheckboxThemeData.materialTapTargetSize] is + /// used. If that is also null, then the value of + /// [ThemeData.materialTapTargetSize] is used. + /// + /// See also: + /// + /// * [MaterialTapTargetSize], for a description of how this affects tap targets. + final MaterialTapTargetSize? materialTapTargetSize; + + /// {@template flutter.material.checkbox.visualDensity} + /// Defines how compact the checkbox's layout will be. + /// {@endtemplate} + /// + /// {@macro flutter.material.themedata.visualDensity} + /// + /// If null, then the value of [CheckboxThemeData.visualDensity] is used. If + /// that is also null, then the value of [ThemeData.visualDensity] is used. + /// + /// See also: + /// + /// * [ThemeData.visualDensity], which specifies the [visualDensity] for all + /// widgets within a [Theme]. + final VisualDensity? visualDensity; + + /// The color for the checkbox's [Material] when it has the input focus. + /// + /// If [overlayColor] returns a non-null color in the [MaterialState.focused] + /// state, it will be used instead. + /// + /// If null, then the value of [CheckboxThemeData.overlayColor] is used in the + /// focused state. If that is also null, then the value of + /// [ThemeData.focusColor] is used. + final Color? focusColor; + + /// {@template flutter.material.checkbox.hoverColor} + /// The color for the checkbox's [Material] when a pointer is hovering over it. + /// + /// If [overlayColor] returns a non-null color in the [MaterialState.hovered] + /// state, it will be used instead. + /// {@endtemplate} + /// + /// If null, then the value of [CheckboxThemeData.overlayColor] is used in the + /// hovered state. If that is also null, then the value of + /// [ThemeData.hoverColor] is used. + final Color? hoverColor; + + /// {@template flutter.material.checkbox.overlayColor} + /// The color for the checkbox's [Material]. + /// + /// Resolves in the following states: + /// * [MaterialState.pressed]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// {@endtemplate} + /// + /// If null, then the value of [activeColor] with alpha + /// [kRadialReactionAlpha], [focusColor] and [hoverColor] is used in the + /// pressed, focused and hovered state. If that is also null, + /// the value of [CheckboxThemeData.overlayColor] is used. If that is + /// also null, then the value of [ColorScheme.secondary] with alpha + /// [kRadialReactionAlpha], [ThemeData.focusColor] and [ThemeData.hoverColor] + /// is used in the pressed, focused and hovered state. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@template flutter.material.checkbox.splashRadius} + /// The splash radius of the circular [Material] ink response. + /// {@endtemplate} + /// + /// If null, then the value of [CheckboxThemeData.splashRadius] is used. If + /// that is also null, then [kRadialReactionRadius] is used. + final double? splashRadius; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@template flutter.material.checkbox.shape} + /// The shape of the checkbox's [Material]. + /// {@endtemplate} + /// + /// If this property is null then [CheckboxThemeData.shape] of [ThemeData.checkboxTheme] + /// is used. If that's null then the shape will be a [RoundedRectangleBorder] + /// with a circular corner radius of 1.0 in Material 2, and 2.0 in Material 3. + final OutlinedBorder? shape; + + /// {@template flutter.material.checkbox.side} + /// The color and width of the checkbox's border. + /// + /// This property can be a [MaterialStateBorderSide] that can + /// specify different border color and widths depending on the + /// checkbox's state. + /// + /// Resolves in the following states: + /// * [MaterialState.pressed]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// * [MaterialState.error]. + /// + /// If this property is not a [MaterialStateBorderSide] and it is + /// non-null, then it is only rendered when the checkbox's value is + /// false. The difference in interpretation is for backwards + /// compatibility. + /// {@endtemplate} + /// + /// If this property is null, then [CheckboxThemeData.side] of + /// [ThemeData.checkboxTheme] is used. If that is also null, then the side + /// will be width 2. + final BorderSide? side; + + /// {@template flutter.material.checkbox.isError} + /// True if this checkbox wants to show an error state. + /// + /// The checkbox will have different default container color and check color when + /// this is true. This is only used when [ThemeData.useMaterial3] is set to true. + /// {@endtemplate} + /// + /// Defaults to false. + final bool isError; + + /// {@template flutter.material.checkbox.semanticLabel} + /// The semantic label for the checkobox that will be announced by screen readers. + /// + /// This is announced in accessibility modes (e.g TalkBack/VoiceOver). + /// + /// This label does not show in the UI. + /// {@endtemplate} + final String? semanticLabel; + + /// The width of a checkbox widget. + static const double width = 18.0; + + final _CheckboxType _checkboxType; + + @override + State<Checkbox> createState() => _CheckboxState(); +} + +class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin, ToggleableStateMixin { + final _CheckboxPainter _painter = _CheckboxPainter(); + bool? _previousValue; + + @override + void initState() { + super.initState(); + _previousValue = widget.value; + } + + @override + void didUpdateWidget(Checkbox oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.value != widget.value) { + _previousValue = oldWidget.value; + animateToValue(); + } + } + + @override + void dispose() { + _painter.dispose(); + super.dispose(); + } + + @override + ValueChanged<bool?>? get onChanged => widget.onChanged; + + @override + bool get tristate => widget.tristate; + + @override + bool? get value => widget.value; + + MaterialStateProperty<Color?> get _widgetFillColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return null; + } + if (states.contains(MaterialState.selected)) { + return widget.activeColor; + } + return null; + }); + } + + BorderSide? _resolveSide(BorderSide? side, Set<MaterialState> states) { + if (side is MaterialStateBorderSide) { + return MaterialStateProperty.resolveAs<BorderSide?>(side, states); + } + if (!states.contains(MaterialState.selected)) { + return side; + } + return null; + } + + @override + Widget build(BuildContext context) { + switch (widget._checkboxType) { + case _CheckboxType.material: + break; + + case _CheckboxType.adaptive: + final ThemeData theme = Theme.of(context); + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + break; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return CupertinoCheckbox( + value: value, + tristate: tristate, + onChanged: onChanged, + activeColor: widget.activeColor, + checkColor: widget.checkColor, + focusColor: widget.focusColor, + focusNode: widget.focusNode, + autofocus: widget.autofocus, + side: widget.side, + shape: widget.shape, + ); + } + } + + assert(debugCheckHasMaterial(context)); + final CheckboxThemeData checkboxTheme = CheckboxTheme.of(context); + final CheckboxThemeData defaults = Theme.of(context).useMaterial3 + ? _CheckboxDefaultsM3(context) + : _CheckboxDefaultsM2(context); + final MaterialTapTargetSize effectiveMaterialTapTargetSize = widget.materialTapTargetSize + ?? checkboxTheme.materialTapTargetSize + ?? defaults.materialTapTargetSize!; + final VisualDensity effectiveVisualDensity = widget.visualDensity + ?? checkboxTheme.visualDensity + ?? defaults.visualDensity!; + Size size; + switch (effectiveMaterialTapTargetSize) { + case MaterialTapTargetSize.padded: + size = const Size(kMinInteractiveDimension, kMinInteractiveDimension); + case MaterialTapTargetSize.shrinkWrap: + size = const Size(kMinInteractiveDimension - 8.0, kMinInteractiveDimension - 8.0); + } + size += effectiveVisualDensity.baseSizeAdjustment; + + final MaterialStateProperty<MouseCursor> effectiveMouseCursor = MaterialStateProperty.resolveWith<MouseCursor>((Set<MaterialState> states) { + return MaterialStateProperty.resolveAs<MouseCursor?>(widget.mouseCursor, states) + ?? checkboxTheme.mouseCursor?.resolve(states) + ?? MaterialStateMouseCursor.clickable.resolve(states); + }); + + // Colors need to be resolved in selected and non selected states separately + final Set<MaterialState> activeStates = states..add(MaterialState.selected); + final Set<MaterialState> inactiveStates = states..remove(MaterialState.selected); + if (widget.isError) { + activeStates.add(MaterialState.error); + inactiveStates.add(MaterialState.error); + } + final Color? activeColor = widget.fillColor?.resolve(activeStates) + ?? _widgetFillColor.resolve(activeStates) + ?? checkboxTheme.fillColor?.resolve(activeStates); + final Color effectiveActiveColor = activeColor + ?? defaults.fillColor!.resolve(activeStates)!; + final Color? inactiveColor = widget.fillColor?.resolve(inactiveStates) + ?? _widgetFillColor.resolve(inactiveStates) + ?? checkboxTheme.fillColor?.resolve(inactiveStates); + final Color effectiveInactiveColor = inactiveColor + ?? defaults.fillColor!.resolve(inactiveStates)!; + + final BorderSide activeSide = _resolveSide(widget.side, activeStates) + ?? _resolveSide(checkboxTheme.side, activeStates) + ?? _resolveSide(defaults.side, activeStates)!; + final BorderSide inactiveSide = _resolveSide(widget.side, inactiveStates) + ?? _resolveSide(checkboxTheme.side, inactiveStates) + ?? _resolveSide(defaults.side, inactiveStates)!; + + final Set<MaterialState> focusedStates = states..add(MaterialState.focused); + if (widget.isError) { + focusedStates.add(MaterialState.error); + } + Color effectiveFocusOverlayColor = widget.overlayColor?.resolve(focusedStates) + ?? widget.focusColor + ?? checkboxTheme.overlayColor?.resolve(focusedStates) + ?? defaults.overlayColor!.resolve(focusedStates)!; + + final Set<MaterialState> hoveredStates = states..add(MaterialState.hovered); + if (widget.isError) { + hoveredStates.add(MaterialState.error); + } + Color effectiveHoverOverlayColor = widget.overlayColor?.resolve(hoveredStates) + ?? widget.hoverColor + ?? checkboxTheme.overlayColor?.resolve(hoveredStates) + ?? defaults.overlayColor!.resolve(hoveredStates)!; + + final Set<MaterialState> activePressedStates = activeStates..add(MaterialState.pressed); + final Color effectiveActivePressedOverlayColor = widget.overlayColor?.resolve(activePressedStates) + ?? checkboxTheme.overlayColor?.resolve(activePressedStates) + ?? activeColor?.withAlpha(kRadialReactionAlpha) + ?? defaults.overlayColor!.resolve(activePressedStates)!; + + final Set<MaterialState> inactivePressedStates = inactiveStates..add(MaterialState.pressed); + final Color effectiveInactivePressedOverlayColor = widget.overlayColor?.resolve(inactivePressedStates) + ?? checkboxTheme.overlayColor?.resolve(inactivePressedStates) + ?? inactiveColor?.withAlpha(kRadialReactionAlpha) + ?? defaults.overlayColor!.resolve(inactivePressedStates)!; + + if (downPosition != null) { + effectiveHoverOverlayColor = states.contains(MaterialState.selected) + ? effectiveActivePressedOverlayColor + : effectiveInactivePressedOverlayColor; + effectiveFocusOverlayColor = states.contains(MaterialState.selected) + ? effectiveActivePressedOverlayColor + : effectiveInactivePressedOverlayColor; + } + + final Set<MaterialState> checkStates = widget.isError ? (states..add(MaterialState.error)) : states; + final Color effectiveCheckColor = widget.checkColor + ?? checkboxTheme.checkColor?.resolve(checkStates) + ?? defaults.checkColor!.resolve(checkStates)!; + + final double effectiveSplashRadius = widget.splashRadius + ?? checkboxTheme.splashRadius + ?? defaults.splashRadius!; + + return Semantics( + label: widget.semanticLabel, + checked: widget.value ?? false, + mixed: widget.tristate ? widget.value == null : null, + child: buildToggleable( + mouseCursor: effectiveMouseCursor, + focusNode: widget.focusNode, + autofocus: widget.autofocus, + size: size, + painter: _painter + ..position = position + ..reaction = reaction + ..reactionFocusFade = reactionFocusFade + ..reactionHoverFade = reactionHoverFade + ..inactiveReactionColor = effectiveInactivePressedOverlayColor + ..reactionColor = effectiveActivePressedOverlayColor + ..hoverColor = effectiveHoverOverlayColor + ..focusColor = effectiveFocusOverlayColor + ..splashRadius = effectiveSplashRadius + ..downPosition = downPosition + ..isFocused = states.contains(MaterialState.focused) + ..isHovered = states.contains(MaterialState.hovered) + ..activeColor = effectiveActiveColor + ..inactiveColor = effectiveInactiveColor + ..checkColor = effectiveCheckColor + ..value = value + ..previousValue = _previousValue + ..shape = widget.shape ?? checkboxTheme.shape ?? defaults.shape! + ..activeSide = activeSide + ..inactiveSide = inactiveSide, + ), + ); + } +} + +const double _kEdgeSize = Checkbox.width; +const double _kStrokeWidth = 2.0; + +class _CheckboxPainter extends ToggleablePainter { + Color get checkColor => _checkColor!; + Color? _checkColor; + set checkColor(Color value) { + if (_checkColor == value) { + return; + } + _checkColor = value; + notifyListeners(); + } + + bool? get value => _value; + bool? _value; + set value(bool? value) { + if (_value == value) { + return; + } + _value = value; + notifyListeners(); + } + + bool? get previousValue => _previousValue; + bool? _previousValue; + set previousValue(bool? value) { + if (_previousValue == value) { + return; + } + _previousValue = value; + notifyListeners(); + } + + OutlinedBorder get shape => _shape!; + OutlinedBorder? _shape; + set shape(OutlinedBorder value) { + if (_shape == value) { + return; + } + _shape = value; + notifyListeners(); + } + + BorderSide get activeSide => _activeSide!; + BorderSide? _activeSide; + set activeSide(BorderSide value) { + if (_activeSide == value) { + return; + } + _activeSide = value; + notifyListeners(); + } + + BorderSide get inactiveSide => _inactiveSide!; + BorderSide? _inactiveSide; + set inactiveSide(BorderSide value) { + if (_inactiveSide == value) { + return; + } + _inactiveSide = value; + notifyListeners(); + } + + // The square outer bounds of the checkbox at t, with the specified origin. + // At t == 0.0, the outer rect's size is _kEdgeSize (Checkbox.width) + // At t == 0.5, .. is _kEdgeSize - _kStrokeWidth + // At t == 1.0, .. is _kEdgeSize + Rect _outerRectAt(Offset origin, double t) { + final double inset = 1.0 - (t - 0.5).abs() * 2.0; + final double size = _kEdgeSize - inset * _kStrokeWidth; + final Rect rect = Rect.fromLTWH(origin.dx + inset, origin.dy + inset, size, size); + return rect; + } + + // The checkbox's fill color + Color _colorAt(double t) { + // As t goes from 0.0 to 0.25, animate from the inactiveColor to activeColor. + return t >= 0.25 ? activeColor : Color.lerp(inactiveColor, activeColor, t * 4.0)!; + } + + // White stroke used to paint the check and dash. + Paint _createStrokePaint() { + return Paint() + ..color = checkColor + ..style = PaintingStyle.stroke + ..strokeWidth = _kStrokeWidth; + } + + void _drawBox(Canvas canvas, Rect outer, Paint paint, BorderSide? side) { + canvas.drawPath(shape.getOuterPath(outer), paint); + if (side != null) { + shape.copyWith(side: side).paint(canvas, outer); + } + } + + void _drawCheck(Canvas canvas, Offset origin, double t, Paint paint) { + assert(t >= 0.0 && t <= 1.0); + // As t goes from 0.0 to 1.0, animate the two check mark strokes from the + // short side to the long side. + final Path path = Path(); + const Offset start = Offset(_kEdgeSize * 0.15, _kEdgeSize * 0.45); + const Offset mid = Offset(_kEdgeSize * 0.4, _kEdgeSize * 0.7); + const Offset end = Offset(_kEdgeSize * 0.85, _kEdgeSize * 0.25); + if (t < 0.5) { + final double strokeT = t * 2.0; + final Offset drawMid = Offset.lerp(start, mid, strokeT)!; + path.moveTo(origin.dx + start.dx, origin.dy + start.dy); + path.lineTo(origin.dx + drawMid.dx, origin.dy + drawMid.dy); + } else { + final double strokeT = (t - 0.5) * 2.0; + final Offset drawEnd = Offset.lerp(mid, end, strokeT)!; + path.moveTo(origin.dx + start.dx, origin.dy + start.dy); + path.lineTo(origin.dx + mid.dx, origin.dy + mid.dy); + path.lineTo(origin.dx + drawEnd.dx, origin.dy + drawEnd.dy); + } + canvas.drawPath(path, paint); + } + + void _drawDash(Canvas canvas, Offset origin, double t, Paint paint) { + assert(t >= 0.0 && t <= 1.0); + // As t goes from 0.0 to 1.0, animate the horizontal line from the + // mid point outwards. + const Offset start = Offset(_kEdgeSize * 0.2, _kEdgeSize * 0.5); + const Offset mid = Offset(_kEdgeSize * 0.5, _kEdgeSize * 0.5); + const Offset end = Offset(_kEdgeSize * 0.8, _kEdgeSize * 0.5); + final Offset drawStart = Offset.lerp(start, mid, 1.0 - t)!; + final Offset drawEnd = Offset.lerp(mid, end, t)!; + canvas.drawLine(origin + drawStart, origin + drawEnd, paint); + } + + @override + void paint(Canvas canvas, Size size) { + paintRadialReaction(canvas: canvas, origin: size.center(Offset.zero)); + + final Paint strokePaint = _createStrokePaint(); + final Offset origin = size / 2.0 - const Size.square(_kEdgeSize) / 2.0 as Offset; + final AnimationStatus status = position.status; + final double tNormalized = status == AnimationStatus.forward || status == AnimationStatus.completed + ? position.value + : 1.0 - position.value; + + // Four cases: false to null, false to true, null to false, true to false + if (previousValue == false || value == false) { + final double t = value == false ? 1.0 - tNormalized : tNormalized; + final Rect outer = _outerRectAt(origin, t); + final Paint paint = Paint()..color = _colorAt(t); + + if (t <= 0.5) { + final BorderSide border = BorderSide.lerp(inactiveSide, activeSide, t); + _drawBox(canvas, outer, paint, border); + } else { + _drawBox(canvas, outer, paint, activeSide); + final double tShrink = (t - 0.5) * 2.0; + if (previousValue == null || value == null) { + _drawDash(canvas, origin, tShrink, strokePaint); + } else { + _drawCheck(canvas, origin, tShrink, strokePaint); + } + } + } else { // Two cases: null to true, true to null + final Rect outer = _outerRectAt(origin, 1.0); + final Paint paint = Paint() ..color = _colorAt(1.0); + + _drawBox(canvas, outer, paint, activeSide); + if (tNormalized <= 0.5) { + final double tShrink = 1.0 - tNormalized * 2.0; + if (previousValue ?? false) { + _drawCheck(canvas, origin, tShrink, strokePaint); + } else { + _drawDash(canvas, origin, tShrink, strokePaint); + } + } else { + final double tExpand = (tNormalized - 0.5) * 2.0; + if (value ?? false) { + _drawCheck(canvas, origin, tExpand, strokePaint); + } else { + _drawDash(canvas, origin, tExpand, strokePaint); + } + } + } + } +} + +// Hand coded defaults based on Material Design 2. +class _CheckboxDefaultsM2 extends CheckboxThemeData { + _CheckboxDefaultsM2(BuildContext context) + : _theme = Theme.of(context), + _colors = Theme.of(context).colorScheme; + + final ThemeData _theme; + final ColorScheme _colors; + + @override + MaterialStateBorderSide? get side { + return MaterialStateBorderSide.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + if (states.contains(MaterialState.selected)) { + return const BorderSide(width: 2.0, color: Colors.transparent); + } + return BorderSide(width: 2.0, color: _theme.disabledColor); + } + if (states.contains(MaterialState.selected)) { + return const BorderSide(width: 2.0, color: Colors.transparent); + } + return BorderSide(width: 2.0, color: _theme.unselectedWidgetColor); + }); + } + + @override + MaterialStateProperty<Color> get fillColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + if (states.contains(MaterialState.selected)) { + return _theme.disabledColor; + } + return Colors.transparent; + } + if (states.contains(MaterialState.selected)) { + return _colors.secondary; + } + return Colors.transparent; + }); + } + + @override + MaterialStateProperty<Color> get checkColor { + return MaterialStateProperty.all<Color>(const Color(0xFFFFFFFF)); + } + + @override + MaterialStateProperty<Color?> get overlayColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return fillColor.resolve(states).withAlpha(kRadialReactionAlpha); + } + if (states.contains(MaterialState.hovered)) { + return _theme.hoverColor; + } + if (states.contains(MaterialState.focused)) { + return _theme.focusColor; + } + return Colors.transparent; + }); + } + + @override + double get splashRadius => kRadialReactionRadius; + + @override + MaterialTapTargetSize get materialTapTargetSize => _theme.materialTapTargetSize; + + @override + VisualDensity get visualDensity => _theme.visualDensity; + + @override + OutlinedBorder get shape => const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(1.0)), + ); +} + +// BEGIN GENERATED TOKEN PROPERTIES - Checkbox + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _CheckboxDefaultsM3 extends CheckboxThemeData { + _CheckboxDefaultsM3(BuildContext context) + : _theme = Theme.of(context), + _colors = Theme.of(context).colorScheme; + + final ThemeData _theme; + final ColorScheme _colors; + + @override + MaterialStateBorderSide? get side { + return MaterialStateBorderSide.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + if (states.contains(MaterialState.selected)) { + return const BorderSide(width: 2.0, color: Colors.transparent); + } + return BorderSide(width: 2.0, color: _colors.onSurface.withOpacity(0.38)); + } + if (states.contains(MaterialState.selected)) { + return const BorderSide(width: 0.0, color: Colors.transparent); + } + if (states.contains(MaterialState.error)) { + return BorderSide(width: 2.0, color: _colors.error); + } + if (states.contains(MaterialState.pressed)) { + return BorderSide(width: 2.0, color: _colors.onSurface); + } + if (states.contains(MaterialState.hovered)) { + return BorderSide(width: 2.0, color: _colors.onSurface); + } + if (states.contains(MaterialState.focused)) { + return BorderSide(width: 2.0, color: _colors.onSurface); + } + return BorderSide(width: 2.0, color: _colors.onSurfaceVariant); + }); + } + + @override + MaterialStateProperty<Color> get fillColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + if (states.contains(MaterialState.selected)) { + return _colors.onSurface.withOpacity(0.38); + } + return Colors.transparent; + } + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.error)) { + return _colors.error; + } + return _colors.primary; + } + return Colors.transparent; + }); + } + + @override + MaterialStateProperty<Color> get checkColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + if (states.contains(MaterialState.selected)) { + return _colors.surface; + } + return Colors.transparent; // No icons available when the checkbox is unselected. + } + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.error)) { + return _colors.onError; + } + return _colors.onPrimary; + } + return Colors.transparent; // No icons available when the checkbox is unselected. + }); + } + + @override + MaterialStateProperty<Color> get overlayColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.error)) { + if (states.contains(MaterialState.pressed)) { + return _colors.error.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.error.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.error.withOpacity(0.12); + } + } + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.primary.withOpacity(0.12); + } + return Colors.transparent; + } + if (states.contains(MaterialState.pressed)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface.withOpacity(0.12); + } + return Colors.transparent; + }); + } + + @override + double get splashRadius => 40.0 / 2; + + @override + MaterialTapTargetSize get materialTapTargetSize => _theme.materialTapTargetSize; + + @override + VisualDensity get visualDensity => _theme.visualDensity; + + @override + OutlinedBorder get shape => const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(2.0)), + ); +} + +// END GENERATED TOKEN PROPERTIES - Checkbox diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/checkbox_list_tile.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/checkbox_list_tile.dart new file mode 100644 index 0000000000000000000000000000000000000000..76dc4265e4c3b673cdfd976cc2c3449c3526cd0d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/checkbox_list_tile.dart @@ -0,0 +1,559 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'checkbox.dart'; +import 'checkbox_theme.dart'; +import 'list_tile.dart'; +import 'list_tile_theme.dart'; +import 'material_state.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// late bool? _throwShotAway; +// void setState(VoidCallback fn) { } + +enum _CheckboxType { material, adaptive } + +/// A [ListTile] with a [Checkbox]. In other words, a checkbox with a label. +/// +/// The entire list tile is interactive: tapping anywhere in the tile toggles +/// the checkbox. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=RkSqPAn9szs} +/// +/// The [value], [onChanged], [activeColor] and [checkColor] properties of this widget are +/// identical to the similarly-named properties on the [Checkbox] widget. +/// +/// The [title], [subtitle], [isThreeLine], [dense], and [contentPadding] properties are like +/// those of the same name on [ListTile]. +/// +/// The [selected] property on this widget is similar to the [ListTile.selected] +/// property. This tile's [activeColor] is used for the selected item's text color, or +/// the theme's [CheckboxThemeData.overlayColor] if [activeColor] is null. +/// +/// This widget does not coordinate the [selected] state and the [value] state; to have the list tile +/// appear selected when the checkbox is checked, pass the same value to both. +/// +/// The checkbox is shown on the right by default in left-to-right languages +/// (i.e. the trailing edge). This can be changed using [controlAffinity]. The +/// [secondary] widget is placed on the opposite side. This maps to the +/// [ListTile.leading] and [ListTile.trailing] properties of [ListTile]. +/// +/// This widget requires a [Material] widget ancestor in the tree to paint +/// itself on, which is typically provided by the app's [Scaffold]. +/// The [tileColor], and [selectedTileColor] are not painted by the +/// [CheckboxListTile] itself but by the [Material] widget ancestor. +/// In this case, one can wrap a [Material] widget around the [CheckboxListTile], +/// e.g.: +/// +/// {@tool snippet} +/// ```dart +/// ColoredBox( +/// color: Colors.green, +/// child: Material( +/// child: CheckboxListTile( +/// tileColor: Colors.red, +/// title: const Text('CheckboxListTile with red background'), +/// value: true, +/// onChanged:(bool? value) { }, +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Performance considerations when wrapping [CheckboxListTile] with [Material] +/// +/// Wrapping a large number of [CheckboxListTile]s individually with [Material]s +/// is expensive. Consider only wrapping the [CheckboxListTile]s that require it +/// or include a common [Material] ancestor where possible. +/// +/// To show the [CheckboxListTile] as disabled, pass null as the [onChanged] +/// callback. +/// +/// {@tool dartpad} +/// ![CheckboxListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile.png) +/// +/// This widget shows a checkbox that, when checked, slows down all animations +/// (including the animation of the checkbox itself getting checked!). +/// +/// This sample requires that you also import 'package:flutter/scheduler.dart', +/// so that you can reference [timeDilation]. +/// +/// ** See code in examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample demonstrates how [CheckboxListTile] positions the checkbox widget +/// relative to the text in different configurations. +/// +/// ** See code in examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.1.dart ** +/// {@end-tool} +/// +/// ## Semantics in CheckboxListTile +/// +/// Since the entirety of the CheckboxListTile is interactive, it should represent +/// itself as a single interactive entity. +/// +/// To do so, a CheckboxListTile widget wraps its children with a [MergeSemantics] +/// widget. [MergeSemantics] will attempt to merge its descendant [Semantics] +/// nodes into one node in the semantics tree. Therefore, CheckboxListTile will +/// throw an error if any of its children requires its own [Semantics] node. +/// +/// For example, you cannot nest a [RichText] widget as a descendant of +/// CheckboxListTile. [RichText] has an embedded gesture recognizer that +/// requires its own [Semantics] node, which directly conflicts with +/// CheckboxListTile's desire to merge all its descendants' semantic nodes +/// into one. Therefore, it may be necessary to create a custom radio tile +/// widget to accommodate similar use cases. +/// +/// {@tool dartpad} +/// ![Checkbox list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_semantics.png) +/// +/// Here is an example of a custom labeled checkbox widget, called +/// LinkedLabelCheckbox, that includes an interactive [RichText] widget that +/// handles tap gestures. +/// +/// ** See code in examples/api/lib/material/checkbox_list_tile/custom_labeled_checkbox.0.dart ** +/// {@end-tool} +/// +/// ## CheckboxListTile isn't exactly what I want +/// +/// If the way CheckboxListTile pads and positions its elements isn't quite +/// what you're looking for, you can create custom labeled checkbox widgets by +/// combining [Checkbox] with other widgets, such as [Text], [Padding] and +/// [InkWell]. +/// +/// {@tool dartpad} +/// ![Custom checkbox list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_custom.png) +/// +/// Here is an example of a custom LabeledCheckbox widget, but you can easily +/// make your own configurable widget. +/// +/// ** See code in examples/api/lib/material/checkbox_list_tile/custom_labeled_checkbox.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListTileTheme], which can be used to affect the style of list tiles, +/// including checkbox list tiles. +/// * [RadioListTile], a similar widget for radio buttons. +/// * [SwitchListTile], a similar widget for switches. +/// * [ListTile] and [Checkbox], the widgets from which this widget is made. +class CheckboxListTile extends StatelessWidget { + /// Creates a combination of a list tile and a checkbox. + /// + /// The checkbox tile itself does not maintain any state. Instead, when the + /// state of the checkbox changes, the widget calls the [onChanged] callback. + /// Most widgets that use a checkbox will listen for the [onChanged] callback + /// and rebuild the checkbox tile with a new [value] to update the visual + /// appearance of the checkbox. + /// + /// The following arguments are required: + /// + /// * [value], which determines whether the checkbox is checked. The [value] + /// can only be null if [tristate] is true. + /// * [onChanged], which is called when the value of the checkbox should + /// change. It can be set to null to disable the checkbox. + const CheckboxListTile({ + super.key, + required this.value, + required this.onChanged, + this.mouseCursor, + this.activeColor, + this.fillColor, + this.checkColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.materialTapTargetSize, + this.visualDensity, + this.focusNode, + this.autofocus = false, + this.shape, + this.side, + this.isError = false, + this.enabled, + this.tileColor, + this.title, + this.subtitle, + this.isThreeLine = false, + this.dense, + this.secondary, + this.selected = false, + this.controlAffinity = ListTileControlAffinity.platform, + this.contentPadding, + this.tristate = false, + this.checkboxShape, + this.selectedTileColor, + this.onFocusChange, + this.enableFeedback, + this.checkboxSemanticLabel, + }) : _checkboxType = _CheckboxType.material, + assert(tristate || value != null), + assert(!isThreeLine || subtitle != null); + + /// Creates a combination of a list tile and a platform adaptive checkbox. + /// + /// The checkbox uses [Checkbox.adaptive] to show a [CupertinoCheckbox] for + /// iOS platforms, or [Checkbox] for all others. + /// + /// All other properties are the same as [CheckboxListTile]. + const CheckboxListTile.adaptive({ + super.key, + required this.value, + required this.onChanged, + this.mouseCursor, + this.activeColor, + this.fillColor, + this.checkColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.materialTapTargetSize, + this.visualDensity, + this.focusNode, + this.autofocus = false, + this.shape, + this.side, + this.isError = false, + this.enabled, + this.tileColor, + this.title, + this.subtitle, + this.isThreeLine = false, + this.dense, + this.secondary, + this.selected = false, + this.controlAffinity = ListTileControlAffinity.platform, + this.contentPadding, + this.tristate = false, + this.checkboxShape, + this.selectedTileColor, + this.onFocusChange, + this.enableFeedback, + this.checkboxSemanticLabel, + }) : _checkboxType = _CheckboxType.adaptive, + assert(tristate || value != null), + assert(!isThreeLine || subtitle != null); + + /// Whether this checkbox is checked. + final bool? value; + + /// Called when the value of the checkbox should change. + /// + /// The checkbox passes the new value to the callback but does not actually + /// change state until the parent widget rebuilds the checkbox tile with the + /// new value. + /// + /// If null, the checkbox will be displayed as disabled. + /// + /// {@tool snippet} + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// CheckboxListTile( + /// value: _throwShotAway, + /// onChanged: (bool? newValue) { + /// setState(() { + /// _throwShotAway = newValue; + /// }); + /// }, + /// title: const Text('Throw away your shot'), + /// ) + /// ``` + /// {@end-tool} + final ValueChanged<bool?>? onChanged; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.disabled]. + /// + /// If null, then the value of [CheckboxThemeData.mouseCursor] is used. If + /// that is also null, then [MaterialStateMouseCursor.clickable] is used. + final MouseCursor? mouseCursor; + + /// The color to use when this checkbox is checked. + /// + /// Defaults to [ColorScheme.secondary] of the current [Theme]. + final Color? activeColor; + + /// The color that fills the checkbox. + /// + /// Resolves in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.disabled]. + /// + /// If null, then the value of [activeColor] is used in the selected + /// state. If that is also null, the value of [CheckboxThemeData.fillColor] + /// is used. If that is also null, then the default value is used. + final MaterialStateProperty<Color?>? fillColor; + + /// The color to use for the check icon when this checkbox is checked. + /// + /// Defaults to Color(0xFFFFFFFF). + final Color? checkColor; + + /// {@macro flutter.material.checkbox.hoverColor} + final Color? hoverColor; + + /// The color for the checkbox's [Material]. + /// + /// Resolves in the following states: + /// * [MaterialState.pressed]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// + /// If null, then the value of [activeColor] with alpha [kRadialReactionAlpha] + /// and [hoverColor] is used in the pressed and hovered state. If that is also null, + /// the value of [CheckboxThemeData.overlayColor] is used. If that is also null, + /// then the default value is used in the pressed and hovered state. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@macro flutter.material.checkbox.splashRadius} + /// + /// If null, then the value of [CheckboxThemeData.splashRadius] is used. If + /// that is also null, then [kRadialReactionRadius] is used. + final double? splashRadius; + + /// {@macro flutter.material.checkbox.materialTapTargetSize} + /// + /// Defaults to [MaterialTapTargetSize.shrinkWrap]. + final MaterialTapTargetSize? materialTapTargetSize; + + /// Defines how compact the list tile's layout will be. + /// + /// {@macro flutter.material.themedata.visualDensity} + final VisualDensity? visualDensity; + + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@macro flutter.material.ListTile.shape} + final ShapeBorder? shape; + + /// {@macro flutter.material.checkbox.side} + /// + /// The given value is passed directly to [Checkbox.side]. + /// + /// If this property is null, then [CheckboxThemeData.side] of + /// [ThemeData.checkboxTheme] is used. If that is also null, then the side + /// will be width 2. + final BorderSide? side; + + /// {@macro flutter.material.checkbox.isError} + /// + /// Defaults to false. + final bool isError; + + /// {@macro flutter.material.ListTile.tileColor} + final Color? tileColor; + + /// The primary content of the list tile. + /// + /// Typically a [Text] widget. + final Widget? title; + + /// Additional content displayed below the title. + /// + /// Typically a [Text] widget. + final Widget? subtitle; + + /// A widget to display on the opposite side of the tile from the checkbox. + /// + /// Typically an [Icon] widget. + final Widget? secondary; + + /// Whether this list tile is intended to display three lines of text. + /// + /// If false, the list tile is treated as having one line if the subtitle is + /// null and treated as having two lines if the subtitle is non-null. + final bool isThreeLine; + + /// Whether this list tile is part of a vertically dense list. + /// + /// If this property is null then its value is based on [ListTileThemeData.dense]. + final bool? dense; + + /// Whether to render icons and text in the [activeColor]. + /// + /// No effort is made to automatically coordinate the [selected] state and the + /// [value] state. To have the list tile appear selected when the checkbox is + /// checked, pass the same value to both. + /// + /// Normally, this property is left to its default value, false. + final bool selected; + + /// Where to place the control relative to the text. + final ListTileControlAffinity controlAffinity; + + /// Defines insets surrounding the tile's contents. + /// + /// This value will surround the [Checkbox], [title], [subtitle], and [secondary] + /// widgets in [CheckboxListTile]. + /// + /// When the value is null, the [contentPadding] is `EdgeInsets.symmetric(horizontal: 16.0)`. + final EdgeInsetsGeometry? contentPadding; + + /// If true the checkbox's [value] can be true, false, or null. + /// + /// Checkbox displays a dash when its value is null. + /// + /// When a tri-state checkbox ([tristate] is true) is tapped, its [onChanged] + /// callback will be applied to true if the current value is false, to null if + /// value is true, and to false if value is null (i.e. it cycles through false + /// => true => null => false when tapped). + /// + /// If tristate is false (the default), [value] must not be null. + final bool tristate; + + /// {@macro flutter.material.checkbox.shape} + /// + /// If this property is null then [CheckboxThemeData.shape] of [ThemeData.checkboxTheme] + /// is used. If that's null then the shape will be a [RoundedRectangleBorder] + /// with a circular corner radius of 1.0. + final OutlinedBorder? checkboxShape; + + /// If non-null, defines the background color when [CheckboxListTile.selected] is true. + final Color? selectedTileColor; + + /// {@macro flutter.material.inkwell.onFocusChange} + final ValueChanged<bool>? onFocusChange; + + /// {@macro flutter.material.ListTile.enableFeedback} + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + /// Whether the CheckboxListTile is interactive. + /// + /// If false, this list tile is styled with the disabled color from the + /// current [Theme] and the [ListTile.onTap] callback is + /// inoperative. + final bool? enabled; + + /// {@macro flutter.material.checkbox.semanticLabel} + final String? checkboxSemanticLabel; + + final _CheckboxType _checkboxType; + + void _handleValueChange() { + assert(onChanged != null); + switch (value) { + case false: + onChanged!(true); + case true: + onChanged!(tristate ? null : false); + case null: + onChanged!(false); + } + } + + @override + Widget build(BuildContext context) { + final Widget control; + + switch (_checkboxType) { + case _CheckboxType.material: + control = Checkbox( + value: value, + onChanged: enabled ?? true ? onChanged : null, + mouseCursor: mouseCursor, + activeColor: activeColor, + fillColor: fillColor, + checkColor: checkColor, + hoverColor: hoverColor, + overlayColor: overlayColor, + splashRadius: splashRadius, + materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap, + autofocus: autofocus, + tristate: tristate, + shape: checkboxShape, + side: side, + isError: isError, + semanticLabel: checkboxSemanticLabel, + ); + case _CheckboxType.adaptive: + control = Checkbox.adaptive( + value: value, + onChanged: enabled ?? true ? onChanged : null, + mouseCursor: mouseCursor, + activeColor: activeColor, + fillColor: fillColor, + checkColor: checkColor, + hoverColor: hoverColor, + overlayColor: overlayColor, + splashRadius: splashRadius, + materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap, + autofocus: autofocus, + tristate: tristate, + shape: checkboxShape, + side: side, + isError: isError, + semanticLabel: checkboxSemanticLabel, + ); + } + + Widget? leading, trailing; + switch (controlAffinity) { + case ListTileControlAffinity.leading: + leading = control; + trailing = secondary; + case ListTileControlAffinity.trailing: + case ListTileControlAffinity.platform: + leading = secondary; + trailing = control; + } + final ThemeData theme = Theme.of(context); + final CheckboxThemeData checkboxTheme = CheckboxTheme.of(context); + final Set<MaterialState> states = <MaterialState>{ + if (selected) MaterialState.selected, + }; + final Color effectiveActiveColor = activeColor + ?? checkboxTheme.fillColor?.resolve(states) + ?? theme.colorScheme.secondary; + return MergeSemantics( + child: ListTile( + selectedColor: effectiveActiveColor, + leading: leading, + title: title, + subtitle: subtitle, + trailing: trailing, + isThreeLine: isThreeLine, + dense: dense, + enabled: enabled ?? onChanged != null, + onTap: onChanged != null ? _handleValueChange : null, + selected: selected, + autofocus: autofocus, + contentPadding: contentPadding, + shape: shape, + selectedTileColor: selectedTileColor, + tileColor: tileColor, + visualDensity: visualDensity, + focusNode: focusNode, + onFocusChange: onFocusChange, + enableFeedback: enableFeedback, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/checkbox_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/checkbox_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..293f6ddb790f4740fd48ccee399533a2b78943db --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/checkbox_theme.dart @@ -0,0 +1,248 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [Checkbox] widgets. +/// +/// Descendant widgets obtain the current [CheckboxThemeData] object using +/// `CheckboxTheme.of(context)`. Instances of [CheckboxThemeData] can be +/// customized with [CheckboxThemeData.copyWith]. +/// +/// Typically a [CheckboxThemeData] is specified as part of the overall [Theme] +/// with [ThemeData.checkboxTheme]. +/// +/// All [CheckboxThemeData] properties are `null` by default. When null, the +/// [Checkbox] will use the values from [ThemeData] if they exist, otherwise it +/// will provide its own defaults based on the overall [Theme]'s colorScheme. +/// See the individual [Checkbox] properties for details. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class CheckboxThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.checkboxTheme]. + const CheckboxThemeData({ + this.mouseCursor, + this.fillColor, + this.checkColor, + this.overlayColor, + this.splashRadius, + this.materialTapTargetSize, + this.visualDensity, + this.shape, + this.side, + }); + + /// {@macro flutter.material.checkbox.mouseCursor} + /// + /// If specified, overrides the default value of [Checkbox.mouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// {@macro flutter.material.checkbox.fillColor} + /// + /// If specified, overrides the default value of [Checkbox.fillColor]. + final MaterialStateProperty<Color?>? fillColor; + + /// {@macro flutter.material.checkbox.checkColor} + /// + /// Resolves in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// + /// If specified, overrides the default value of [Checkbox.checkColor]. + final MaterialStateProperty<Color?>? checkColor; + + /// {@macro flutter.material.checkbox.overlayColor} + /// + /// If specified, overrides the default value of [Checkbox.overlayColor]. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@macro flutter.material.checkbox.splashRadius} + /// + /// If specified, overrides the default value of [Checkbox.splashRadius]. + final double? splashRadius; + + /// {@macro flutter.material.checkbox.materialTapTargetSize} + /// + /// If specified, overrides the default value of + /// [Checkbox.materialTapTargetSize]. + final MaterialTapTargetSize? materialTapTargetSize; + + /// {@macro flutter.material.checkbox.visualDensity} + /// + /// If specified, overrides the default value of [Checkbox.visualDensity]. + final VisualDensity? visualDensity; + + /// {@macro flutter.material.checkbox.shape} + /// + /// If specified, overrides the default value of [Checkbox.shape]. + final OutlinedBorder? shape; + + /// {@macro flutter.material.checkbox.side} + /// + /// If specified, overrides the default value of [Checkbox.side]. + final BorderSide? side; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + CheckboxThemeData copyWith({ + MaterialStateProperty<MouseCursor?>? mouseCursor, + MaterialStateProperty<Color?>? fillColor, + MaterialStateProperty<Color?>? checkColor, + MaterialStateProperty<Color?>? overlayColor, + double? splashRadius, + MaterialTapTargetSize? materialTapTargetSize, + VisualDensity? visualDensity, + OutlinedBorder? shape, + BorderSide? side, + }) { + return CheckboxThemeData( + mouseCursor: mouseCursor ?? this.mouseCursor, + fillColor: fillColor ?? this.fillColor, + checkColor: checkColor ?? this.checkColor, + overlayColor: overlayColor ?? this.overlayColor, + splashRadius: splashRadius ?? this.splashRadius, + materialTapTargetSize: materialTapTargetSize ?? this.materialTapTargetSize, + visualDensity: visualDensity ?? this.visualDensity, + shape: shape ?? this.shape, + side: side ?? this.side, + ); + } + + /// Linearly interpolate between two [CheckboxThemeData]s. + /// + /// {@macro dart.ui.shadow.lerp} + static CheckboxThemeData lerp(CheckboxThemeData? a, CheckboxThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return CheckboxThemeData( + mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, + fillColor: MaterialStateProperty.lerp<Color?>(a?.fillColor, b?.fillColor, t, Color.lerp), + checkColor: MaterialStateProperty.lerp<Color?>(a?.checkColor, b?.checkColor, t, Color.lerp), + overlayColor: MaterialStateProperty.lerp<Color?>(a?.overlayColor, b?.overlayColor, t, Color.lerp), + splashRadius: lerpDouble(a?.splashRadius, b?.splashRadius, t), + materialTapTargetSize: t < 0.5 ? a?.materialTapTargetSize : b?.materialTapTargetSize, + visualDensity: t < 0.5 ? a?.visualDensity : b?.visualDensity, + shape: ShapeBorder.lerp(a?.shape, b?.shape, t) as OutlinedBorder?, + side: _lerpSides(a?.side, b?.side, t), + ); + } + + @override + int get hashCode => Object.hash( + mouseCursor, + fillColor, + checkColor, + overlayColor, + splashRadius, + materialTapTargetSize, + visualDensity, + shape, + side, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is CheckboxThemeData + && other.mouseCursor == mouseCursor + && other.fillColor == fillColor + && other.checkColor == checkColor + && other.overlayColor == overlayColor + && other.splashRadius == splashRadius + && other.materialTapTargetSize == materialTapTargetSize + && other.visualDensity == visualDensity + && other.shape == shape + && other.side == side; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('fillColor', fillColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('checkColor', checkColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('overlayColor', overlayColor, defaultValue: null)); + properties.add(DoubleProperty('splashRadius', splashRadius, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialTapTargetSize>('materialTapTargetSize', materialTapTargetSize, defaultValue: null)); + properties.add(DiagnosticsProperty<VisualDensity>('visualDensity', visualDensity, defaultValue: null)); + properties.add(DiagnosticsProperty<OutlinedBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<BorderSide>('side', side, defaultValue: null)); + } + + // Special case because BorderSide.lerp() doesn't support null arguments + static BorderSide? _lerpSides(BorderSide? a, BorderSide? b, double t) { + if (a == null || b == null) { + return null; + } + if (identical(a, b)) { + return a; + } + return BorderSide.lerp(a, b, t); + } +} + +/// Applies a checkbox theme to descendant [Checkbox] widgets. +/// +/// Descendant widgets obtain the current theme's [CheckboxTheme] object using +/// [CheckboxTheme.of]. When a widget uses [CheckboxTheme.of], it is +/// automatically rebuilt if the theme later changes. +/// +/// A checkbox theme can be specified as part of the overall Material theme +/// using [ThemeData.checkboxTheme]. +/// +/// See also: +/// +/// * [CheckboxThemeData], which describes the actual configuration of a +/// checkbox theme. +class CheckboxTheme extends InheritedWidget { + /// Constructs a checkbox theme that configures all descendant [Checkbox] + /// widgets. + const CheckboxTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties used for all descendant [Checkbox] widgets. + final CheckboxThemeData data; + + /// Returns the configuration [data] from the closest [CheckboxTheme] + /// ancestor. If there is no ancestor, it returns [ThemeData.checkboxTheme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// CheckboxThemeData theme = CheckboxTheme.of(context); + /// ``` + static CheckboxThemeData of(BuildContext context) { + final CheckboxTheme? checkboxTheme = context.dependOnInheritedWidgetOfExactType<CheckboxTheme>(); + return checkboxTheme?.data ?? Theme.of(context).checkboxTheme; + } + + @override + bool updateShouldNotify(CheckboxTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/chip.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/chip.dart new file mode 100644 index 0000000000000000000000000000000000000000..6033d766a0cdedc2bd6704892d9f8f7239e51c7e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/chip.dart @@ -0,0 +1,2330 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'chip_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'icons.dart'; +import 'ink_decoration.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'material_state_mixin.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; +import 'tooltip.dart'; + +// Some design constants +const double _kChipHeight = 32.0; +const double _kDeleteIconSize = 18.0; + +const int _kCheckmarkAlpha = 0xde; // 87% +const int _kDisabledAlpha = 0x61; // 38% +const double _kCheckmarkStrokeWidth = 2.0; + +const Duration _kSelectDuration = Duration(milliseconds: 195); +const Duration _kCheckmarkDuration = Duration(milliseconds: 150); +const Duration _kCheckmarkReverseDuration = Duration(milliseconds: 50); +const Duration _kDrawerDuration = Duration(milliseconds: 150); +const Duration _kReverseDrawerDuration = Duration(milliseconds: 100); +const Duration _kDisableDuration = Duration(milliseconds: 75); + +const Color _kSelectScrimColor = Color(0x60191919); +const Icon _kDefaultDeleteIcon = Icon(Icons.cancel, size: _kDeleteIconSize); + +/// An interface defining the base attributes for a Material Design chip. +/// +/// Chips are compact elements that represent an attribute, text, entity, or +/// action. +/// +/// The defaults mentioned in the documentation for each attribute are what +/// the implementing classes typically use for defaults (but this class doesn't +/// provide or enforce them). +/// +/// See also: +/// +/// * [Chip], a chip that displays information and can be deleted. +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [FilterChip], uses tags or descriptive words as a way to filter content. +/// * [ActionChip], represents an action related to primary content. +/// * <https://material.io/design/components/chips.html> +abstract interface class ChipAttributes { + /// The primary content of the chip. + /// + /// Typically a [Text] widget. + Widget get label; + + /// A widget to display prior to the chip's label. + /// + /// Typically a [CircleAvatar] widget. + Widget? get avatar; + + /// The style to be applied to the chip's label. + /// + /// If this is null and [ThemeData.useMaterial3] is true, then + /// [TextTheme.labelLarge] is used. Otherwise, [TextTheme.bodyLarge] + /// is used. + // + /// This only has an effect on widgets that respect the [DefaultTextStyle], + /// such as [Text]. + /// + /// If [TextStyle.color] is a [MaterialStateProperty<Color>], [MaterialStateProperty.resolve] + /// is used for the following [MaterialState]s: + /// + /// * [MaterialState.disabled]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.pressed]. + TextStyle? get labelStyle; + + /// The color and weight of the chip's outline. + /// + /// Defaults to the border side in the ambient [ChipThemeData]. If the theme + /// border side resolves to null and [ThemeData.useMaterial3] is true, then + /// [BorderSide] with a [ColorScheme.outline] color is used when the chip is + /// enabled, and [BorderSide] with a [ColorScheme.onSurface] color with an + /// opacity of 0.12 is used when the chip is disabled. Otherwise, it defaults + /// to null. + /// + /// This value is combined with [shape] to create a shape decorated with an + /// outline. To omit the outline entirely, pass [BorderSide.none] to [side]. + /// + /// If it is a [MaterialStateBorderSide], [MaterialStateProperty.resolve] is + /// used for the following [MaterialState]s: + /// + /// * [MaterialState.disabled]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.pressed]. + BorderSide? get side; + + /// The [OutlinedBorder] to draw around the chip. + /// + /// Defaults to the shape in the ambient [ChipThemeData]. If the theme + /// shape resolves to null and [ThemeData.useMaterial3] is true, then + /// [RoundedRectangleBorder] with a circular border radius of 8.0 is used. + /// Otherwise, [StadiumBorder] is used. + /// + /// This shape is combined with [side] to create a shape decorated with an + /// outline. To omit the outline entirely, pass [BorderSide.none] to [side]. + /// + /// If it is a [MaterialStateOutlinedBorder], [MaterialStateProperty.resolve] + /// is used for the following [MaterialState]s: + /// + /// * [MaterialState.disabled]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.pressed]. + OutlinedBorder? get shape; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + Clip get clipBehavior; + + /// {@macro flutter.widgets.Focus.focusNode} + FocusNode? get focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + bool get autofocus; + + /// The color that fills the chip, in all [MaterialState]s. + /// + /// Defaults to null. + /// + /// Resolves in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.disabled]. + MaterialStateProperty<Color?>? get color; + + /// Color to be used for the unselected, enabled chip's background. + /// + /// The default is light grey. + Color? get backgroundColor; + + /// The padding between the contents of the chip and the outside [shape]. + /// + /// If this is null and [ThemeData.useMaterial3] is true, then + /// a padding of 8.0 logical pixels on all sides is used. Otherwise, + /// it defaults to a padding of 4.0 logical pixels on all sides. + EdgeInsetsGeometry? get padding; + + /// Defines how compact the chip's layout will be. + /// + /// Chips are unaffected by horizontal density changes. + /// + /// {@macro flutter.material.themedata.visualDensity} + /// + /// See also: + /// + /// * [ThemeData.visualDensity], which specifies the [visualDensity] for all + /// widgets within a [Theme]. + VisualDensity? get visualDensity; + + /// The padding around the [label] widget. + /// + /// By default, this is 4 logical pixels at the beginning and the end of the + /// label, and zero on top and bottom. + EdgeInsetsGeometry? get labelPadding; + + /// Configures the minimum size of the tap target. + /// + /// Defaults to [ThemeData.materialTapTargetSize]. + /// + /// See also: + /// + /// * [MaterialTapTargetSize], for a description of how this affects tap targets. + MaterialTapTargetSize? get materialTapTargetSize; + + /// Elevation to be applied on the chip relative to its parent. + /// + /// This controls the size of the shadow below the chip. + /// + /// Defaults to 0. The value is always non-negative. + double? get elevation; + + /// Color of the chip's shadow when the elevation is greater than 0. + /// + /// If this is null and [ThemeData.useMaterial3] is true, then + /// [Colors.transparent] color is used. Otherwise, it defaults to null. + Color? get shadowColor; + + /// Color of the chip's surface tint overlay when its elevation is + /// greater than 0. + /// + /// If this is null and [ThemeData.useMaterial3] is true, then + /// [ColorScheme.surfaceTint] color is used. Otherwise, it defaults + /// to null. + Color? get surfaceTintColor; + + /// Theme used for all icons in the chip. + /// + /// If this is null and [ThemeData.useMaterial3] is true, then [IconThemeData] + /// with a [ColorScheme.primary] color and a size of 18.0 is used when + /// the chip is enabled, and [IconThemeData] with a [ColorScheme.onSurface] + /// color and a size of 18.0 is used when the chip is disabled. Otherwise, + /// it defaults to null. + IconThemeData? get iconTheme; +} + +/// An interface for Material Design chips that can be deleted. +/// +/// The defaults mentioned in the documentation for each attribute are what +/// the implementing classes typically use for defaults (but this class doesn't +/// provide or enforce them). +/// +/// See also: +/// +/// * [Chip], a chip that displays information and can be deleted. +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * <https://material.io/design/components/chips.html> +abstract interface class DeletableChipAttributes { + /// The icon displayed when [onDeleted] is set. + /// + /// Defaults to an [Icon] widget set to use [Icons.cancel]. + Widget? get deleteIcon; + + /// Called when the user taps the [deleteIcon] to delete the chip. + /// + /// If null, the delete button will not appear on the chip. + /// + /// The chip will not automatically remove itself: this just tells the app + /// that the user tapped the delete button. In order to delete the chip, you + /// have to do something similar to the following sample: + /// + /// {@tool dartpad} + /// This sample shows how to use [onDeleted] to remove an entry when the + /// delete button is tapped. + /// + /// ** See code in examples/api/lib/material/chip/deletable_chip_attributes.on_deleted.0.dart ** + /// {@end-tool} + VoidCallback? get onDeleted; + + /// Used to define the delete icon's color with an [IconTheme] that + /// contains the icon. + /// + /// The default is `Color(0xde000000)` + /// (slightly transparent black) for light themes, and `Color(0xdeffffff)` + /// (slightly transparent white) for dark themes. + /// + /// The delete icon appears if [DeletableChipAttributes.onDeleted] is + /// non-null. + Color? get deleteIconColor; + + /// The message to be used for the chip's delete button tooltip. + /// + /// If provided with an empty string, the tooltip of the delete button will be + /// disabled. + /// + /// If null, the default [MaterialLocalizations.deleteButtonTooltip] will be + /// used. + String? get deleteButtonTooltipMessage; +} + +/// An interface for Material Design chips that can have check marks. +/// +/// The defaults mentioned in the documentation for each attribute are what +/// the implementing classes typically use for defaults (but this class doesn't +/// provide or enforce them). +/// +/// See also: +/// +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [FilterChip], uses tags or descriptive words as a way to filter content. +/// * <https://material.io/design/components/chips.html> +abstract interface class CheckmarkableChipAttributes { + /// Whether or not to show a check mark when + /// [SelectableChipAttributes.selected] is true. + /// + /// Defaults to true. + bool? get showCheckmark; + + /// [Color] of the chip's check mark when a check mark is visible. + /// + /// This will override the color set by the platform's brightness setting. + /// + /// If null, it will defer to a color selected by the platform's brightness + /// setting. + Color? get checkmarkColor; +} + +/// An interface for Material Design chips that can be selected. +/// +/// The defaults mentioned in the documentation for each attribute are what +/// the implementing classes typically use for defaults (but this class doesn't +/// provide or enforce them). +/// +/// See also: +/// +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [FilterChip], uses tags or descriptive words as a way to filter content. +/// * <https://material.io/design/components/chips.html> +abstract interface class SelectableChipAttributes { + /// Whether or not this chip is selected. + /// + /// If [onSelected] is not null, this value will be used to determine if the + /// select check mark will be shown or not. + /// + /// Defaults to false. + bool get selected; + + /// Called when the chip should change between selected and de-selected + /// states. + /// + /// When the chip is tapped, then the [onSelected] callback, if set, will be + /// applied to `!selected` (see [selected]). + /// + /// The chip passes the new value to the callback but does not actually + /// change state until the parent widget rebuilds the chip with the new + /// value. + /// + /// The callback provided to [onSelected] should update the state of the + /// parent [StatefulWidget] using the [State.setState] method, so that the + /// parent gets rebuilt. + /// + /// The [onSelected] and [TappableChipAttributes.onPressed] callbacks must not + /// both be specified at the same time. + /// + /// {@tool snippet} + /// + /// A [StatefulWidget] that illustrates use of onSelected in an [InputChip]. + /// + /// ```dart + /// class Wood extends StatefulWidget { + /// const Wood({super.key}); + /// + /// @override + /// State<StatefulWidget> createState() => WoodState(); + /// } + /// + /// class WoodState extends State<Wood> { + /// bool _useChisel = false; + /// + /// @override + /// Widget build(BuildContext context) { + /// return InputChip( + /// label: const Text('Use Chisel'), + /// selected: _useChisel, + /// onSelected: (bool newValue) { + /// setState(() { + /// _useChisel = newValue; + /// }); + /// }, + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + ValueChanged<bool>? get onSelected; + + /// Elevation to be applied on the chip relative to its parent during the + /// press motion. + /// + /// This controls the size of the shadow below the chip. + /// + /// Defaults to 8. The value is always non-negative. + double? get pressElevation; + + /// Color to be used for the chip's background, indicating that it is + /// selected. + /// + /// The chip is selected when [selected] is true. + Color? get selectedColor; + + /// Color of the chip's shadow when the elevation is greater than 0 and the + /// chip is selected. + /// + /// The default is [Colors.black]. + Color? get selectedShadowColor; + + /// Tooltip string to be used for the body area (where the label and avatar + /// are) of the chip. + String? get tooltip; + + /// The shape of the translucent highlight painted over the avatar when the + /// [selected] property is true. + /// + /// Only the outer path of the shape is used. + /// + /// Defaults to [CircleBorder]. + ShapeBorder get avatarBorder; +} + +/// An interface for Material Design chips that can be enabled and disabled. +/// +/// The defaults mentioned in the documentation for each attribute are what +/// the implementing classes typically use for defaults (but this class doesn't +/// provide or enforce them). +/// +/// See also: +/// +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [FilterChip], uses tags or descriptive words as a way to filter content. +/// * <https://material.io/design/components/chips.html> +abstract interface class DisabledChipAttributes { + /// Whether or not this chip is enabled for input. + /// + /// If this is true, but all of the user action callbacks are null (i.e. + /// [SelectableChipAttributes.onSelected], [TappableChipAttributes.onPressed], + /// and [DeletableChipAttributes.onDeleted]), then the + /// control will still be shown as disabled. + /// + /// This is typically used if you want the chip to be disabled, but also show + /// a delete button. + /// + /// For classes which don't have this as a constructor argument, [isEnabled] + /// returns true if their user action callback is set. + /// + /// Defaults to true. + bool get isEnabled; + + /// The color used for the chip's background to indicate that it is not + /// enabled. + /// + /// The chip is disabled when [isEnabled] is false, or all three of + /// [SelectableChipAttributes.onSelected], [TappableChipAttributes.onPressed], + /// and [DeletableChipAttributes.onDeleted] are null. + /// + /// It defaults to [Colors.black38]. + Color? get disabledColor; +} + +/// An interface for Material Design chips that can be tapped. +/// +/// The defaults mentioned in the documentation for each attribute are what +/// the implementing classes typically use for defaults (but this class doesn't +/// provide or enforce them). +/// +/// See also: +/// +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [FilterChip], uses tags or descriptive words as a way to filter content. +/// * [ActionChip], represents an action related to primary content. +/// * <https://material.io/design/components/chips.html> +abstract interface class TappableChipAttributes { + /// Called when the user taps the chip. + /// + /// If [onPressed] is set, then this callback will be called when the user + /// taps on the label or avatar parts of the chip. If [onPressed] is null, + /// then the chip will be disabled. + /// + /// {@tool snippet} + /// + /// ```dart + /// class Blacksmith extends StatelessWidget { + /// const Blacksmith({super.key}); + /// + /// void startHammering() { + /// print('bang bang bang'); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// return InputChip( + /// label: const Text('Apply Hammer'), + /// onPressed: startHammering, + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + VoidCallback? get onPressed; + + /// Elevation to be applied on the chip relative to its parent during the + /// press motion. + /// + /// This controls the size of the shadow below the chip. + /// + /// Defaults to 8. The value is always non-negative. + double? get pressElevation; + + /// Tooltip string to be used for the body area (where the label and avatar + /// are) of the chip. + String? get tooltip; +} + +/// A Material Design chip. +/// +/// Chips are compact elements that represent an attribute, text, entity, or +/// action. +/// +/// Supplying a non-null [onDeleted] callback will cause the chip to include a +/// button for deleting the chip. +/// +/// Its ancestors must include [Material], [MediaQuery], [Directionality], and +/// [MaterialLocalizations]. Typically all of these widgets are provided by +/// [MaterialApp] and [Scaffold]. The [label] and [clipBehavior] arguments must +/// not be null. +/// +/// {@tool snippet} +/// +/// ```dart +/// Chip( +/// avatar: CircleAvatar( +/// backgroundColor: Colors.grey.shade800, +/// child: const Text('AB'), +/// ), +/// label: const Text('Aaron Burr'), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [FilterChip], uses tags or descriptive words as a way to filter content. +/// * [ActionChip], represents an action related to primary content. +/// * [CircleAvatar], which shows images or initials of entities. +/// * [Wrap], A widget that displays its children in multiple horizontal or +/// vertical runs. +/// * <https://material.io/design/components/chips.html> +class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttributes { + /// Creates a Material Design chip. + /// + /// The [elevation] must be null or non-negative. + const Chip({ + super.key, + this.avatar, + required this.label, + this.labelStyle, + this.labelPadding, + this.deleteIcon, + this.onDeleted, + this.deleteIconColor, + this.deleteButtonTooltipMessage, + this.side, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.color, + this.backgroundColor, + this.padding, + this.visualDensity, + this.materialTapTargetSize, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.iconTheme, + }) : assert(elevation == null || elevation >= 0.0); + + @override + final Widget? avatar; + @override + final Widget label; + @override + final TextStyle? labelStyle; + @override + final EdgeInsetsGeometry? labelPadding; + @override + final BorderSide? side; + @override + final OutlinedBorder? shape; + @override + final Clip clipBehavior; + @override + final FocusNode? focusNode; + @override + final bool autofocus; + @override + final MaterialStateProperty<Color?>? color; + @override + final Color? backgroundColor; + @override + final EdgeInsetsGeometry? padding; + @override + final VisualDensity? visualDensity; + @override + final Widget? deleteIcon; + @override + final VoidCallback? onDeleted; + @override + final Color? deleteIconColor; + @override + final String? deleteButtonTooltipMessage; + @override + final MaterialTapTargetSize? materialTapTargetSize; + @override + final double? elevation; + @override + final Color? shadowColor; + @override + final Color? surfaceTintColor; + @override + final IconThemeData? iconTheme; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + return RawChip( + avatar: avatar, + label: label, + labelStyle: labelStyle, + labelPadding: labelPadding, + deleteIcon: deleteIcon, + onDeleted: onDeleted, + deleteIconColor: deleteIconColor, + deleteButtonTooltipMessage: deleteButtonTooltipMessage, + tapEnabled: false, + side: side, + shape: shape, + clipBehavior: clipBehavior, + focusNode: focusNode, + autofocus: autofocus, + color: color, + backgroundColor: backgroundColor, + padding: padding, + visualDensity: visualDensity, + materialTapTargetSize: materialTapTargetSize, + elevation: elevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + iconTheme: iconTheme, + ); + } +} + +/// A raw Material Design chip. +/// +/// This serves as the basis for all of the chip widget types to aggregate. +/// It is typically not created directly, one of the other chip types +/// that are appropriate for the use case are used instead: +/// +/// * [Chip] a simple chip that can only display information and be deleted. +/// * [InputChip] represents a complex piece of information, such as an entity +/// (person, place, or thing) or conversational text, in a compact form. +/// * [ChoiceChip] allows a single selection from a set of options. +/// * [FilterChip] a chip that uses tags or descriptive words as a way to +/// filter content. +/// * [ActionChip]s display a set of actions related to primary content. +/// +/// Raw chips are typically only used if you want to create your own custom chip +/// type. +/// +/// Raw chips can be selected by setting [onSelected], deleted by setting +/// [onDeleted], and pushed like a button with [onPressed]. They have a [label], +/// and they can have a leading icon (see [avatar]) and a trailing icon +/// ([deleteIcon]). Colors and padding can be customized. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// See also: +/// +/// * [CircleAvatar], which shows images or initials of people. +/// * [Wrap], A widget that displays its children in multiple horizontal or +/// vertical runs. +/// * <https://material.io/design/components/chips.html> +class RawChip extends StatefulWidget + implements + ChipAttributes, + DeletableChipAttributes, + SelectableChipAttributes, + CheckmarkableChipAttributes, + DisabledChipAttributes, + TappableChipAttributes { + /// Creates a RawChip. + /// + /// The [onPressed] and [onSelected] callbacks must not both be specified at + /// the same time. + /// + /// The [pressElevation] and [elevation] must be null or non-negative. + /// Typically, [pressElevation] is greater than [elevation]. + const RawChip({ + super.key, + this.defaultProperties, + this.avatar, + required this.label, + this.labelStyle, + this.padding, + this.visualDensity, + this.labelPadding, + Widget? deleteIcon, + this.onDeleted, + this.deleteIconColor, + this.deleteButtonTooltipMessage, + this.onPressed, + this.onSelected, + this.pressElevation, + this.tapEnabled = true, + this.selected = false, + this.isEnabled = true, + this.disabledColor, + this.selectedColor, + this.tooltip, + this.side, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.color, + this.backgroundColor, + this.materialTapTargetSize, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.iconTheme, + this.selectedShadowColor, + this.showCheckmark, + this.checkmarkColor, + this.avatarBorder = const CircleBorder(), + }) : assert(pressElevation == null || pressElevation >= 0.0), + assert(elevation == null || elevation >= 0.0), + deleteIcon = deleteIcon ?? _kDefaultDeleteIcon; + + /// Defines the defaults for the chip properties if + /// they are not specified elsewhere. + /// + /// If null then [ChipThemeData.fromDefaults] will be used + /// for the default properties. + final ChipThemeData? defaultProperties; + + @override + final Widget? avatar; + @override + final Widget label; + @override + final TextStyle? labelStyle; + @override + final EdgeInsetsGeometry? labelPadding; + @override + final Widget deleteIcon; + @override + final VoidCallback? onDeleted; + @override + final Color? deleteIconColor; + @override + final String? deleteButtonTooltipMessage; + @override + final ValueChanged<bool>? onSelected; + @override + final VoidCallback? onPressed; + @override + final double? pressElevation; + @override + final bool selected; + @override + final bool isEnabled; + @override + final Color? disabledColor; + @override + final Color? selectedColor; + @override + final String? tooltip; + @override + final BorderSide? side; + @override + final OutlinedBorder? shape; + @override + final Clip clipBehavior; + @override + final FocusNode? focusNode; + @override + final bool autofocus; + @override + final MaterialStateProperty<Color?>? color; + @override + final Color? backgroundColor; + @override + final EdgeInsetsGeometry? padding; + @override + final VisualDensity? visualDensity; + @override + final MaterialTapTargetSize? materialTapTargetSize; + @override + final double? elevation; + @override + final Color? shadowColor; + @override + final Color? surfaceTintColor; + @override + final IconThemeData? iconTheme; + @override + final Color? selectedShadowColor; + @override + final bool? showCheckmark; + @override + final Color? checkmarkColor; + @override + final ShapeBorder avatarBorder; + + /// If set, this indicates that the chip should be disabled if all of the + /// tap callbacks ([onSelected], [onPressed]) are null. + /// + /// For example, the [Chip] class sets this to false because it can't be + /// disabled, even if no callbacks are set on it, since it is used for + /// displaying information only. + /// + /// Defaults to true. + final bool tapEnabled; + + @override + State<RawChip> createState() => _RawChipState(); +} + +class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProviderStateMixin<RawChip> { + static const Duration pressedAnimationDuration = Duration(milliseconds: 75); + + late AnimationController selectController; + late AnimationController avatarDrawerController; + late AnimationController deleteDrawerController; + late AnimationController enableController; + late Animation<double> checkmarkAnimation; + late Animation<double> avatarDrawerAnimation; + late Animation<double> deleteDrawerAnimation; + late Animation<double> enableAnimation; + late Animation<double> selectionFade; + + bool get hasDeleteButton => widget.onDeleted != null; + bool get hasAvatar => widget.avatar != null; + + bool get canTap { + return widget.isEnabled + && widget.tapEnabled + && (widget.onPressed != null || widget.onSelected != null); + } + + bool _isTapping = false; + bool get isTapping => canTap && _isTapping; + + @override + void initState() { + assert(widget.onSelected == null || widget.onPressed == null); + super.initState(); + setMaterialState(MaterialState.disabled, !widget.isEnabled); + setMaterialState(MaterialState.selected, widget.selected); + selectController = AnimationController( + duration: _kSelectDuration, + value: widget.selected ? 1.0 : 0.0, + vsync: this, + ); + selectionFade = CurvedAnimation( + parent: selectController, + curve: Curves.fastOutSlowIn, + ); + avatarDrawerController = AnimationController( + duration: _kDrawerDuration, + value: hasAvatar || widget.selected ? 1.0 : 0.0, + vsync: this, + ); + deleteDrawerController = AnimationController( + duration: _kDrawerDuration, + value: hasDeleteButton ? 1.0 : 0.0, + vsync: this, + ); + enableController = AnimationController( + duration: _kDisableDuration, + value: widget.isEnabled ? 1.0 : 0.0, + vsync: this, + ); + + // These will delay the start of some animations, and/or reduce their + // length compared to the overall select animation, using Intervals. + final double checkmarkPercentage = _kCheckmarkDuration.inMilliseconds / + _kSelectDuration.inMilliseconds; + final double checkmarkReversePercentage = _kCheckmarkReverseDuration.inMilliseconds / + _kSelectDuration.inMilliseconds; + final double avatarDrawerReversePercentage = _kReverseDrawerDuration.inMilliseconds / + _kSelectDuration.inMilliseconds; + checkmarkAnimation = CurvedAnimation( + parent: selectController, + curve: Interval(1.0 - checkmarkPercentage, 1.0, curve: Curves.fastOutSlowIn), + reverseCurve: Interval( + 1.0 - checkmarkReversePercentage, + 1.0, + curve: Curves.fastOutSlowIn, + ), + ); + deleteDrawerAnimation = CurvedAnimation( + parent: deleteDrawerController, + curve: Curves.fastOutSlowIn, + ); + avatarDrawerAnimation = CurvedAnimation( + parent: avatarDrawerController, + curve: Curves.fastOutSlowIn, + reverseCurve: Interval( + 1.0 - avatarDrawerReversePercentage, + 1.0, + curve: Curves.fastOutSlowIn, + ), + ); + enableAnimation = CurvedAnimation( + parent: enableController, + curve: Curves.fastOutSlowIn, + ); + } + + @override + void dispose() { + selectController.dispose(); + avatarDrawerController.dispose(); + deleteDrawerController.dispose(); + enableController.dispose(); + super.dispose(); + } + + void _handleTapDown(TapDownDetails details) { + if (!canTap) { + return; + } + setMaterialState(MaterialState.pressed, true); + setState(() { + _isTapping = true; + }); + } + + void _handleTapCancel() { + if (!canTap) { + return; + } + setMaterialState(MaterialState.pressed, false); + setState(() { + _isTapping = false; + }); + } + + void _handleTap() { + if (!canTap) { + return; + } + setMaterialState(MaterialState.pressed, false); + setState(() { + _isTapping = false; + }); + // Only one of these can be set, so only one will be called. + widget.onSelected?.call(!widget.selected); + widget.onPressed?.call(); + } + + OutlinedBorder _getShape(ThemeData theme, ChipThemeData chipTheme, ChipThemeData chipDefaults) { + final BorderSide? resolvedSide = MaterialStateProperty.resolveAs<BorderSide?>(widget.side, materialStates) + ?? MaterialStateProperty.resolveAs<BorderSide?>(chipTheme.side, materialStates); + final OutlinedBorder resolvedShape = MaterialStateProperty.resolveAs<OutlinedBorder?>(widget.shape, materialStates) + ?? MaterialStateProperty.resolveAs<OutlinedBorder?>(chipTheme.shape, materialStates) + ?? MaterialStateProperty.resolveAs<OutlinedBorder?>(chipDefaults.shape, materialStates) + // TODO(tahatesser): Remove this fallback when Material 2 is deprecated. + ?? const StadiumBorder(); + // If the side is provided, shape uses the provided side. + if (resolvedSide != null) { + return resolvedShape.copyWith(side: resolvedSide); + } + // If the side is not provided and the shape's side is not [BorderSide.none], + // then the shape's side is used. Otherwise, the default side is used. + return resolvedShape.side != BorderSide.none + ? resolvedShape + : resolvedShape.copyWith(side: chipDefaults.side); + } + + Color? resolveColor({ + MaterialStateProperty<Color?>? color, + Color? selectedColor, + Color? backgroundColor, + Color? disabledColor, + MaterialStateProperty<Color?>? defaultColor, + }) { + return _IndividualOverrides( + color: color, + selectedColor: selectedColor, + backgroundColor: backgroundColor, + disabledColor: disabledColor, + ).resolve(materialStates) ?? defaultColor?.resolve(materialStates); + } + + /// Picks between three different colors, depending upon the state of two + /// different animations. + Color? _getBackgroundColor(ThemeData theme, ChipThemeData chipTheme, ChipThemeData chipDefaults) { + if (theme.useMaterial3) { + final Color? disabledColor = resolveColor( + color: widget.color ?? chipTheme.color, + disabledColor: widget.disabledColor ?? chipTheme.disabledColor, + defaultColor: chipDefaults.color, + ); + final Color? backgroundColor = resolveColor( + color: widget.color ?? chipTheme.color, + backgroundColor: widget.backgroundColor ?? chipTheme.backgroundColor, + defaultColor: chipDefaults.color, + ); + final Color? selectedColor = resolveColor( + color: widget.color ?? chipTheme.color, + selectedColor: widget.selectedColor ?? chipTheme.selectedColor, + defaultColor: chipDefaults.color, + ); + final ColorTween backgroundTween = ColorTween( + begin: disabledColor, + end: backgroundColor, + ); + final ColorTween selectTween = ColorTween( + begin: backgroundTween.evaluate(enableController), + end: selectedColor, + ); + return selectTween.evaluate(selectionFade); + } else { + final ColorTween backgroundTween = ColorTween( + begin: widget.disabledColor + ?? chipTheme.disabledColor + ?? theme.disabledColor, + end: widget.backgroundColor + ?? chipTheme.backgroundColor + ?? theme.chipTheme.backgroundColor + ?? chipDefaults.backgroundColor, + ); + final ColorTween selectTween = ColorTween( + begin: backgroundTween.evaluate(enableController), + end: widget.selectedColor + ?? chipTheme.selectedColor + ?? theme.chipTheme.selectedColor + ?? chipDefaults.selectedColor, + ); + return selectTween.evaluate(selectionFade); + } + } + + @override + void didUpdateWidget(RawChip oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.isEnabled != widget.isEnabled) { + setState(() { + setMaterialState(MaterialState.disabled, !widget.isEnabled); + if (widget.isEnabled) { + enableController.forward(); + } else { + enableController.reverse(); + } + }); + } + if (oldWidget.avatar != widget.avatar || oldWidget.selected != widget.selected) { + setState(() { + if (hasAvatar || widget.selected) { + avatarDrawerController.forward(); + } else { + avatarDrawerController.reverse(); + } + }); + } + if (oldWidget.selected != widget.selected) { + setState(() { + setMaterialState(MaterialState.selected, widget.selected); + if (widget.selected) { + selectController.forward(); + } else { + selectController.reverse(); + } + }); + } + if (oldWidget.onDeleted != widget.onDeleted) { + setState(() { + if (hasDeleteButton) { + deleteDrawerController.forward(); + } else { + deleteDrawerController.reverse(); + } + }); + } + } + + Widget? _wrapWithTooltip({String? tooltip, bool enabled = true, Widget? child}) { + if (child == null || !enabled || tooltip == null) { + return child; + } + return Tooltip( + message: tooltip, + child: child, + ); + } + + Widget? _buildDeleteIcon( + BuildContext context, + ThemeData theme, + ChipThemeData chipTheme, + ChipThemeData chipDefaults, + ) { + if (!hasDeleteButton) { + return null; + } + return Semantics( + container: true, + button: true, + child: _wrapWithTooltip( + tooltip: widget.deleteButtonTooltipMessage + ?? MaterialLocalizations.of(context).deleteButtonTooltip, + enabled: widget.onDeleted != null, + child: InkWell( + // Radius should be slightly less than the full size of the chip. + radius: (_kChipHeight + (widget.padding?.vertical ?? 0.0)) * .45, + // Keeps the splash from being constrained to the icon alone. + splashFactory: _UnconstrainedInkSplashFactory(Theme.of(context).splashFactory), + onTap: widget.isEnabled ? widget.onDeleted : null, + child: IconTheme( + data: theme.iconTheme.copyWith( + color: widget.deleteIconColor + ?? chipTheme.deleteIconColor + ?? theme.chipTheme.deleteIconColor + ?? chipDefaults.deleteIconColor, + ), + child: widget.deleteIcon, + ), + ), + ), + ); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMediaQuery(context)); + assert(debugCheckHasDirectionality(context)); + assert(debugCheckHasMaterialLocalizations(context)); + + /// The chip at text scale 1 starts with 8px on each side and as text scaling + /// gets closer to 2 the label padding is linearly interpolated from 8px to 4px. + /// Once the widget has a text scaling of 2 or higher than the label padding + /// remains 4px. + final EdgeInsetsGeometry defaultLabelPadding = EdgeInsets.lerp( + const EdgeInsets.symmetric(horizontal: 8.0), + const EdgeInsets.symmetric(horizontal: 4.0), + clampDouble(MediaQuery.textScalerOf(context).textScaleFactor - 1.0, 0.0, 1.0), + )!; + + final ThemeData theme = Theme.of(context); + final ChipThemeData chipTheme = ChipTheme.of(context); + final Brightness brightness = chipTheme.brightness ?? theme.brightness; + final ChipThemeData chipDefaults = widget.defaultProperties ?? + (theme.useMaterial3 + ? _ChipDefaultsM3(context, widget.isEnabled) + : ChipThemeData.fromDefaults( + brightness: brightness, + secondaryColor: brightness == Brightness.dark ? Colors.tealAccent[200]! : theme.primaryColor, + labelStyle: theme.textTheme.bodyLarge!, + ) + ); + final TextDirection? textDirection = Directionality.maybeOf(context); + final OutlinedBorder resolvedShape = _getShape(theme, chipTheme, chipDefaults); + + final double elevation = widget.elevation + ?? chipTheme.elevation + ?? chipDefaults.elevation + ?? 0; + final double pressElevation = widget.pressElevation + ?? chipTheme.pressElevation + ?? chipDefaults.pressElevation + ?? 0; + final Color? shadowColor = widget.shadowColor + ?? chipTheme.shadowColor + ?? chipDefaults.shadowColor; + final Color? surfaceTintColor = widget.surfaceTintColor + ?? chipTheme.surfaceTintColor + ?? chipDefaults.surfaceTintColor; + final Color? selectedShadowColor = widget.selectedShadowColor + ?? chipTheme.selectedShadowColor + ?? chipDefaults.selectedShadowColor; + final Color? checkmarkColor = widget.checkmarkColor + ?? chipTheme.checkmarkColor + ?? chipDefaults.checkmarkColor; + final bool showCheckmark = widget.showCheckmark + ?? chipTheme.showCheckmark + ?? chipDefaults.showCheckmark!; + final EdgeInsetsGeometry padding = widget.padding + ?? chipTheme.padding + ?? chipDefaults.padding!; + // Widget's label style is merged with this below. + final TextStyle labelStyle = chipTheme.labelStyle + ?? chipDefaults.labelStyle!; + final EdgeInsetsGeometry labelPadding = widget.labelPadding + ?? chipTheme.labelPadding + ?? chipDefaults.labelPadding + ?? defaultLabelPadding; + final IconThemeData? iconTheme = widget.iconTheme + ?? chipTheme.iconTheme + ?? chipDefaults.iconTheme; + + final TextStyle effectiveLabelStyle = labelStyle.merge(widget.labelStyle); + final Color? resolvedLabelColor = MaterialStateProperty.resolveAs<Color?>(effectiveLabelStyle.color, materialStates); + final TextStyle resolvedLabelStyle = effectiveLabelStyle.copyWith(color: resolvedLabelColor); + final Widget? avatar = iconTheme != null && hasAvatar + ? IconTheme.merge( + data: theme.useMaterial3 ? chipDefaults.iconTheme!.merge(iconTheme) : iconTheme, + child: widget.avatar!, + ) + : widget.avatar; + + Widget result = Material( + elevation: isTapping ? pressElevation : elevation, + shadowColor: widget.selected ? selectedShadowColor : shadowColor, + surfaceTintColor: surfaceTintColor, + animationDuration: pressedAnimationDuration, + shape: resolvedShape, + clipBehavior: widget.clipBehavior, + child: InkWell( + onFocusChange: updateMaterialState(MaterialState.focused), + focusNode: widget.focusNode, + autofocus: widget.autofocus, + canRequestFocus: widget.isEnabled, + onTap: canTap ? _handleTap : null, + onTapDown: canTap ? _handleTapDown : null, + onTapCancel: canTap ? _handleTapCancel : null, + onHover: canTap ? updateMaterialState(MaterialState.hovered) : null, + customBorder: resolvedShape, + child: AnimatedBuilder( + animation: Listenable.merge(<Listenable>[selectController, enableController]), + builder: (BuildContext context, Widget? child) { + return Ink( + decoration: ShapeDecoration( + shape: resolvedShape, + color: _getBackgroundColor(theme, chipTheme, chipDefaults), + ), + child: child, + ); + }, + child: _wrapWithTooltip( + tooltip: widget.tooltip, + enabled: widget.onPressed != null || widget.onSelected != null, + child: _ChipRenderWidget( + theme: _ChipRenderTheme( + label: DefaultTextStyle( + overflow: TextOverflow.fade, + textAlign: TextAlign.start, + maxLines: 1, + softWrap: false, + style: resolvedLabelStyle, + child: widget.label, + ), + avatar: AnimatedSwitcher( + duration: _kDrawerDuration, + switchInCurve: Curves.fastOutSlowIn, + child: avatar, + ), + deleteIcon: AnimatedSwitcher( + duration: _kDrawerDuration, + switchInCurve: Curves.fastOutSlowIn, + child: _buildDeleteIcon(context, theme, chipTheme, chipDefaults), + ), + brightness: brightness, + padding: padding.resolve(textDirection), + visualDensity: widget.visualDensity ?? theme.visualDensity, + labelPadding: labelPadding.resolve(textDirection), + showAvatar: hasAvatar, + showCheckmark: showCheckmark, + checkmarkColor: checkmarkColor, + canTapBody: canTap, + ), + value: widget.selected, + checkmarkAnimation: checkmarkAnimation, + enableAnimation: enableAnimation, + avatarDrawerAnimation: avatarDrawerAnimation, + deleteDrawerAnimation: deleteDrawerAnimation, + isEnabled: widget.isEnabled, + avatarBorder: widget.avatarBorder, + ), + ), + ), + ), + ); + + final BoxConstraints constraints; + final Offset densityAdjustment = (widget.visualDensity ?? theme.visualDensity).baseSizeAdjustment; + switch (widget.materialTapTargetSize ?? theme.materialTapTargetSize) { + case MaterialTapTargetSize.padded: + constraints = BoxConstraints( + minWidth: kMinInteractiveDimension + densityAdjustment.dx, + minHeight: kMinInteractiveDimension + densityAdjustment.dy, + ); + case MaterialTapTargetSize.shrinkWrap: + constraints = const BoxConstraints(); + } + result = _ChipRedirectingHitDetectionWidget( + constraints: constraints, + child: Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: result, + ), + ); + return Semantics( + button: widget.tapEnabled, + container: true, + selected: widget.selected, + enabled: widget.tapEnabled ? canTap : null, + child: result, + ); + } +} + +class _IndividualOverrides extends MaterialStateProperty<Color?> { + _IndividualOverrides({ + this.color, + this.backgroundColor, + this.selectedColor, + this.disabledColor, + }); + + final MaterialStateProperty<Color?>? color; + final Color? backgroundColor; + final Color? selectedColor; + final Color? disabledColor; + + @override + Color? resolve(Set<MaterialState> states) { + if (color != null) { + return color!.resolve(states); + } + if (states.contains(MaterialState.selected) && states.contains(MaterialState.disabled)) { + return selectedColor; + } + if (states.contains(MaterialState.disabled)) { + return disabledColor; + } + if (states.contains(MaterialState.selected)) { + return selectedColor; + } + return backgroundColor; + } +} + +/// Redirects the [buttonRect.dy] passed to [RenderBox.hitTest] to the vertical +/// center of the widget. +/// +/// The primary purpose of this widget is to allow padding around the [RawChip] +/// to trigger the child ink feature without increasing the size of the material. +class _ChipRedirectingHitDetectionWidget extends SingleChildRenderObjectWidget { + const _ChipRedirectingHitDetectionWidget({ + super.child, + required this.constraints, + }); + + final BoxConstraints constraints; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderChipRedirectingHitDetection(constraints); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderChipRedirectingHitDetection renderObject) { + renderObject.additionalConstraints = constraints; + } +} + +class _RenderChipRedirectingHitDetection extends RenderConstrainedBox { + _RenderChipRedirectingHitDetection(BoxConstraints additionalConstraints) : super(additionalConstraints: additionalConstraints); + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (!size.contains(position)) { + return false; + } + // Only redirects hit detection which occurs above and below the render object. + // In order to make this assumption true, I have removed the minimum width + // constraints, since any reasonable chip would be at least that wide. + final Offset offset = Offset(position.dx, size.height / 2); + return result.addWithRawTransform( + transform: MatrixUtils.forceToPoint(offset), + position: position, + hitTest: (BoxHitTestResult result, Offset position) { + assert(position == offset); + return child!.hitTest(result, position: offset); + }, + ); + } +} + +class _ChipRenderWidget extends SlottedMultiChildRenderObjectWidget<_ChipSlot, RenderBox> { + const _ChipRenderWidget({ + required this.theme, + this.value, + this.isEnabled, + required this.checkmarkAnimation, + required this.avatarDrawerAnimation, + required this.deleteDrawerAnimation, + required this.enableAnimation, + this.avatarBorder, + }); + + final _ChipRenderTheme theme; + final bool? value; + final bool? isEnabled; + final Animation<double> checkmarkAnimation; + final Animation<double> avatarDrawerAnimation; + final Animation<double> deleteDrawerAnimation; + final Animation<double> enableAnimation; + final ShapeBorder? avatarBorder; + + @override + Iterable<_ChipSlot> get slots => _ChipSlot.values; + + @override + Widget? childForSlot(_ChipSlot slot) { + switch (slot) { + case _ChipSlot.label: + return theme.label; + case _ChipSlot.avatar: + return theme.avatar; + case _ChipSlot.deleteIcon: + return theme.deleteIcon; + } + } + + @override + void updateRenderObject(BuildContext context, _RenderChip renderObject) { + renderObject + ..theme = theme + ..textDirection = Directionality.of(context) + ..value = value + ..isEnabled = isEnabled + ..checkmarkAnimation = checkmarkAnimation + ..avatarDrawerAnimation = avatarDrawerAnimation + ..deleteDrawerAnimation = deleteDrawerAnimation + ..enableAnimation = enableAnimation + ..avatarBorder = avatarBorder; + } + + @override + SlottedContainerRenderObjectMixin<_ChipSlot, RenderBox> createRenderObject(BuildContext context) { + return _RenderChip( + theme: theme, + textDirection: Directionality.of(context), + value: value, + isEnabled: isEnabled, + checkmarkAnimation: checkmarkAnimation, + avatarDrawerAnimation: avatarDrawerAnimation, + deleteDrawerAnimation: deleteDrawerAnimation, + enableAnimation: enableAnimation, + avatarBorder: avatarBorder, + ); + } +} + +enum _ChipSlot { + label, + avatar, + deleteIcon, +} + +@immutable +class _ChipRenderTheme { + const _ChipRenderTheme({ + required this.avatar, + required this.label, + required this.deleteIcon, + required this.brightness, + required this.padding, + required this.visualDensity, + required this.labelPadding, + required this.showAvatar, + required this.showCheckmark, + required this.checkmarkColor, + required this.canTapBody, + }); + + final Widget avatar; + final Widget label; + final Widget deleteIcon; + final Brightness brightness; + final EdgeInsets padding; + final VisualDensity visualDensity; + final EdgeInsets labelPadding; + final bool showAvatar; + final bool showCheckmark; + final Color? checkmarkColor; + final bool canTapBody; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is _ChipRenderTheme + && other.avatar == avatar + && other.label == label + && other.deleteIcon == deleteIcon + && other.brightness == brightness + && other.padding == padding + && other.labelPadding == labelPadding + && other.showAvatar == showAvatar + && other.showCheckmark == showCheckmark + && other.checkmarkColor == checkmarkColor + && other.canTapBody == canTapBody; + } + + @override + int get hashCode => Object.hash( + avatar, + label, + deleteIcon, + brightness, + padding, + labelPadding, + showAvatar, + showCheckmark, + checkmarkColor, + canTapBody, + ); +} + +class _RenderChip extends RenderBox with SlottedContainerRenderObjectMixin<_ChipSlot, RenderBox> { + _RenderChip({ + required _ChipRenderTheme theme, + required TextDirection textDirection, + this.value, + this.isEnabled, + required this.checkmarkAnimation, + required this.avatarDrawerAnimation, + required this.deleteDrawerAnimation, + required this.enableAnimation, + this.avatarBorder, + }) : _theme = theme, + _textDirection = textDirection; + + bool? value; + bool? isEnabled; + late Rect _deleteButtonRect; + late Rect _pressRect; + Animation<double> checkmarkAnimation; + Animation<double> avatarDrawerAnimation; + Animation<double> deleteDrawerAnimation; + Animation<double> enableAnimation; + ShapeBorder? avatarBorder; + + RenderBox? get avatar => childForSlot(_ChipSlot.avatar); + RenderBox? get deleteIcon => childForSlot(_ChipSlot.deleteIcon); + RenderBox? get label => childForSlot(_ChipSlot.label); + + _ChipRenderTheme get theme => _theme; + _ChipRenderTheme _theme; + set theme(_ChipRenderTheme value) { + if (_theme == value) { + return; + } + _theme = value; + markNeedsLayout(); + } + + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsLayout(); + } + + // The returned list is ordered for hit testing. + @override + Iterable<RenderBox> get children { + return <RenderBox>[ + if (avatar != null) + avatar!, + if (label != null) + label!, + if (deleteIcon != null) + deleteIcon!, + ]; + } + + bool get isDrawingCheckmark => theme.showCheckmark && !checkmarkAnimation.isDismissed; + bool get deleteIconShowing => !deleteDrawerAnimation.isDismissed; + + @override + bool get sizedByParent => false; + + static double _minWidth(RenderBox? box, double height) { + return box == null ? 0.0 : box.getMinIntrinsicWidth(height); + } + + static double _maxWidth(RenderBox? box, double height) { + return box == null ? 0.0 : box.getMaxIntrinsicWidth(height); + } + + static double _minHeight(RenderBox? box, double width) { + return box == null ? 0.0 : box.getMinIntrinsicHeight(width); + } + + static Size _boxSize(RenderBox? box) => box == null ? Size.zero : box.size; + + static Rect _boxRect(RenderBox? box) => box == null ? Rect.zero : _boxParentData(box).offset & box.size; + + static BoxParentData _boxParentData(RenderBox box) => box.parentData! as BoxParentData; + + @override + double computeMinIntrinsicWidth(double height) { + // The overall padding isn't affected by missing avatar or delete icon + // because we add the padding regardless to give extra padding for the label + // when they're missing. + final double overallPadding = theme.padding.horizontal + + theme.labelPadding.horizontal; + return overallPadding + + _minWidth(avatar, height) + + _minWidth(label, height) + + _minWidth(deleteIcon, height); + } + + @override + double computeMaxIntrinsicWidth(double height) { + final double overallPadding = theme.padding.horizontal + + theme.labelPadding.horizontal; + return overallPadding + + _maxWidth(avatar, height) + + _maxWidth(label, height) + + _maxWidth(deleteIcon, height); + } + + @override + double computeMinIntrinsicHeight(double width) { + return math.max( + _kChipHeight, + theme.padding.vertical + theme.labelPadding.vertical + _minHeight(label, width), + ); + } + + @override + double computeMaxIntrinsicHeight(double width) => computeMinIntrinsicHeight(width); + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + // The baseline of this widget is the baseline of the label. + return label!.getDistanceToActualBaseline(baseline); + } + + Size _layoutLabel(BoxConstraints contentConstraints, double iconSizes, Size size, Size rawSize, [ChildLayouter layoutChild = ChildLayoutHelper.layoutChild]) { + // Now that we know the label height and the width of the icons, we can + // determine how much to shrink the width constraints for the "real" layout. + if (contentConstraints.maxWidth.isFinite) { + final double maxWidth = math.max( + 0.0, + contentConstraints.maxWidth + - iconSizes + - theme.labelPadding.horizontal + - theme.padding.horizontal, + ); + final Size updatedSize = layoutChild( + label!, + BoxConstraints( + maxWidth: maxWidth, + minHeight: rawSize.height, + maxHeight: size.height, + ), + ); + + return Size( + updatedSize.width + theme.labelPadding.horizontal, + updatedSize.height + theme.labelPadding.vertical, + ); + } + + final Size updatedSize = layoutChild( + label!, + BoxConstraints( + minHeight: rawSize.height, + maxHeight: size.height, + maxWidth: size.width, + ), + ); + + return Size( + updatedSize.width + theme.labelPadding.horizontal, + updatedSize.height + theme.labelPadding.vertical, + ); + } + + Size _layoutAvatar(BoxConstraints contentConstraints, double contentSize, [ChildLayouter layoutChild = ChildLayoutHelper.layoutChild]) { + final double requestedSize = math.max(0.0, contentSize); + final BoxConstraints avatarConstraints = BoxConstraints.tightFor( + width: requestedSize, + height: requestedSize, + ); + final Size avatarBoxSize = layoutChild(avatar!, avatarConstraints); + if (!theme.showCheckmark && !theme.showAvatar) { + return Size(0.0, contentSize); + } + double avatarWidth = 0.0; + double avatarHeight = 0.0; + if (theme.showAvatar) { + avatarWidth += avatarDrawerAnimation.value * avatarBoxSize.width; + } else { + avatarWidth += avatarDrawerAnimation.value * contentSize; + } + avatarHeight += avatarBoxSize.height; + return Size(avatarWidth, avatarHeight); + } + + Size _layoutDeleteIcon(BoxConstraints contentConstraints, double contentSize, [ChildLayouter layoutChild = ChildLayoutHelper.layoutChild]) { + final double requestedSize = math.max(0.0, contentSize); + final BoxConstraints deleteIconConstraints = BoxConstraints.tightFor( + width: requestedSize, + height: requestedSize, + ); + final Size boxSize = layoutChild(deleteIcon!, deleteIconConstraints); + if (!deleteIconShowing) { + return Size(0.0, contentSize); + } + double deleteIconWidth = 0.0; + double deleteIconHeight = 0.0; + deleteIconWidth += deleteDrawerAnimation.value * boxSize.width; + deleteIconHeight += boxSize.height; + return Size(deleteIconWidth, deleteIconHeight); + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (!size.contains(position)) { + return false; + } + final bool hitIsOnDeleteIcon = deleteIcon != null && _hitIsOnDeleteIcon( + padding: theme.padding, + labelPadding: theme.labelPadding, + tapPosition: position, + chipSize: size, + deleteButtonSize: deleteIcon!.size, + textDirection: textDirection!, + ); + final RenderBox? hitTestChild = hitIsOnDeleteIcon + ? (deleteIcon ?? label ?? avatar) + : (label ?? avatar); + + if (hitTestChild != null) { + final Offset center = hitTestChild.size.center(Offset.zero); + return result.addWithRawTransform( + transform: MatrixUtils.forceToPoint(center), + position: position, + hitTest: (BoxHitTestResult result, Offset position) { + assert(position == center); + return hitTestChild.hitTest(result, position: center); + }, + ); + } + return false; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return _computeSizes(constraints, ChildLayoutHelper.dryLayoutChild).size; + } + + _ChipSizes _computeSizes(BoxConstraints constraints, ChildLayouter layoutChild) { + final BoxConstraints contentConstraints = constraints.loosen(); + // Find out the height of the label within the constraints. + final Offset densityAdjustment = Offset(0.0, theme.visualDensity.baseSizeAdjustment.dy / 2.0); + final Size rawLabelSize = layoutChild(label!, contentConstraints); + final double contentSize = math.max( + _kChipHeight - theme.padding.vertical + theme.labelPadding.vertical, + rawLabelSize.height + theme.labelPadding.vertical, + ); + final Size avatarSize = _layoutAvatar(contentConstraints, contentSize, layoutChild); + final Size deleteIconSize = _layoutDeleteIcon(contentConstraints, contentSize, layoutChild); + final Size labelSize = _layoutLabel( + contentConstraints, + avatarSize.width + deleteIconSize.width, + Size(rawLabelSize.width, contentSize), + rawLabelSize, + layoutChild, + ); + + // This is the overall size of the content: it doesn't include + // theme.padding, that is added in at the end. + final Size overallSize = Size( + avatarSize.width + labelSize.width + deleteIconSize.width, + contentSize, + ) + densityAdjustment; + final Size paddedSize = Size( + overallSize.width + theme.padding.horizontal, + overallSize.height + theme.padding.vertical, + ); + + return _ChipSizes( + size: constraints.constrain(paddedSize), + overall: overallSize, + content: contentSize, + densityAdjustment: densityAdjustment, + avatar: avatarSize, + label: labelSize, + deleteIcon: deleteIconSize, + ); + } + + @override + void performLayout() { + final _ChipSizes sizes = _computeSizes(constraints, ChildLayoutHelper.layoutChild); + + // Now we have all of the dimensions. Place the children where they belong. + + const double left = 0.0; + final double right = sizes.overall.width; + + Offset centerLayout(Size boxSize, double x) { + assert(sizes.content >= boxSize.height); + switch (textDirection!) { + case TextDirection.rtl: + return Offset(x - boxSize.width, (sizes.content - boxSize.height + sizes.densityAdjustment.dy) / 2.0); + case TextDirection.ltr: + return Offset(x, (sizes.content - boxSize.height + sizes.densityAdjustment.dy) / 2.0); + } + } + + // These are the offsets to the upper left corners of the boxes (including + // the child's padding) containing the children, for each child, but not + // including the overall padding. + Offset avatarOffset = Offset.zero; + Offset labelOffset = Offset.zero; + Offset deleteIconOffset = Offset.zero; + switch (textDirection!) { + case TextDirection.rtl: + double start = right; + if (theme.showCheckmark || theme.showAvatar) { + avatarOffset = centerLayout(sizes.avatar, start); + start -= sizes.avatar.width; + } + labelOffset = centerLayout(sizes.label, start); + start -= sizes.label.width; + if (deleteIconShowing) { + _deleteButtonRect = Rect.fromLTWH( + 0.0, + 0.0, + sizes.deleteIcon.width + theme.padding.right, + sizes.overall.height + theme.padding.vertical, + ); + deleteIconOffset = centerLayout(sizes.deleteIcon, start); + } else { + _deleteButtonRect = Rect.zero; + } + start -= sizes.deleteIcon.width; + if (theme.canTapBody) { + _pressRect = Rect.fromLTWH( + _deleteButtonRect.width, + 0.0, + sizes.overall.width - _deleteButtonRect.width + theme.padding.horizontal, + sizes.overall.height + theme.padding.vertical, + ); + } else { + _pressRect = Rect.zero; + } + case TextDirection.ltr: + double start = left; + if (theme.showCheckmark || theme.showAvatar) { + avatarOffset = centerLayout(sizes.avatar, start - _boxSize(avatar).width + sizes.avatar.width); + start += sizes.avatar.width; + } + labelOffset = centerLayout(sizes.label, start); + start += sizes.label.width; + if (theme.canTapBody) { + _pressRect = Rect.fromLTWH( + 0.0, + 0.0, + deleteIconShowing + ? start + theme.padding.left + : sizes.overall.width + theme.padding.horizontal, + sizes.overall.height + theme.padding.vertical, + ); + } else { + _pressRect = Rect.zero; + } + start -= _boxSize(deleteIcon).width - sizes.deleteIcon.width; + if (deleteIconShowing) { + deleteIconOffset = centerLayout(sizes.deleteIcon, start); + _deleteButtonRect = Rect.fromLTWH( + start + theme.padding.left, + 0.0, + sizes.deleteIcon.width + theme.padding.right, + sizes.overall.height + theme.padding.vertical, + ); + } else { + _deleteButtonRect = Rect.zero; + } + } + // Center the label vertically. + labelOffset = labelOffset + + Offset( + 0.0, + ((sizes.label.height - theme.labelPadding.vertical) - _boxSize(label).height) / 2.0, + ); + _boxParentData(avatar!).offset = theme.padding.topLeft + avatarOffset; + _boxParentData(label!).offset = theme.padding.topLeft + labelOffset + theme.labelPadding.topLeft; + _boxParentData(deleteIcon!).offset = theme.padding.topLeft + deleteIconOffset; + final Size paddedSize = Size( + sizes.overall.width + theme.padding.horizontal, + sizes.overall.height + theme.padding.vertical, + ); + size = constraints.constrain(paddedSize); + assert( + size.height == constraints.constrainHeight(paddedSize.height), + "Constrained height ${size.height} doesn't match expected height " + '${constraints.constrainWidth(paddedSize.height)}', + ); + assert( + size.width == constraints.constrainWidth(paddedSize.width), + "Constrained width ${size.width} doesn't match expected width " + '${constraints.constrainWidth(paddedSize.width)}', + ); + } + + static final ColorTween selectionScrimTween = ColorTween( + begin: Colors.transparent, + end: _kSelectScrimColor, + ); + + Color get _disabledColor { + if (enableAnimation.isCompleted) { + return Colors.white; + } + final ColorTween enableTween; + switch (theme.brightness) { + case Brightness.light: + enableTween = ColorTween( + begin: Colors.white.withAlpha(_kDisabledAlpha), + end: Colors.white, + ); + case Brightness.dark: + enableTween = ColorTween( + begin: Colors.black.withAlpha(_kDisabledAlpha), + end: Colors.black, + ); + } + return enableTween.evaluate(enableAnimation)!; + } + + void _paintCheck(Canvas canvas, Offset origin, double size) { + Color? paintColor; + if (theme.checkmarkColor != null) { + paintColor = theme.checkmarkColor; + } else { + switch (theme.brightness) { + case Brightness.light: + paintColor = theme.showAvatar ? Colors.white : Colors.black.withAlpha(_kCheckmarkAlpha); + case Brightness.dark: + paintColor = theme.showAvatar ? Colors.black : Colors.white.withAlpha(_kCheckmarkAlpha); + } + } + + final ColorTween fadeTween = ColorTween(begin: Colors.transparent, end: paintColor); + + paintColor = checkmarkAnimation.status == AnimationStatus.reverse + ? fadeTween.evaluate(checkmarkAnimation) + : paintColor; + + final Paint paint = Paint() + ..color = paintColor! + ..style = PaintingStyle.stroke + ..strokeWidth = _kCheckmarkStrokeWidth * (avatar != null ? avatar!.size.height / 24.0 : 1.0); + final double t = checkmarkAnimation.status == AnimationStatus.reverse + ? 1.0 + : checkmarkAnimation.value; + if (t == 0.0) { + // Nothing to draw. + return; + } + assert(t > 0.0 && t <= 1.0); + // As t goes from 0.0 to 1.0, animate the two check mark strokes from the + // short side to the long side. + final Path path = Path(); + final Offset start = Offset(size * 0.15, size * 0.45); + final Offset mid = Offset(size * 0.4, size * 0.7); + final Offset end = Offset(size * 0.85, size * 0.25); + if (t < 0.5) { + final double strokeT = t * 2.0; + final Offset drawMid = Offset.lerp(start, mid, strokeT)!; + path.moveTo(origin.dx + start.dx, origin.dy + start.dy); + path.lineTo(origin.dx + drawMid.dx, origin.dy + drawMid.dy); + } else { + final double strokeT = (t - 0.5) * 2.0; + final Offset drawEnd = Offset.lerp(mid, end, strokeT)!; + path.moveTo(origin.dx + start.dx, origin.dy + start.dy); + path.lineTo(origin.dx + mid.dx, origin.dy + mid.dy); + path.lineTo(origin.dx + drawEnd.dx, origin.dy + drawEnd.dy); + } + canvas.drawPath(path, paint); + } + + void _paintSelectionOverlay(PaintingContext context, Offset offset) { + if (isDrawingCheckmark) { + if (theme.showAvatar) { + final Rect avatarRect = _boxRect(avatar).shift(offset); + final Paint darkenPaint = Paint() + ..color = selectionScrimTween.evaluate(checkmarkAnimation)! + ..blendMode = BlendMode.srcATop; + final Path path = avatarBorder!.getOuterPath(avatarRect); + context.canvas.drawPath(path, darkenPaint); + } + // Need to make the check mark be a little smaller than the avatar. + final double checkSize = avatar!.size.height * 0.75; + final Offset checkOffset = _boxParentData(avatar!).offset + + Offset(avatar!.size.height * 0.125, avatar!.size.height * 0.125); + _paintCheck(context.canvas, offset + checkOffset, checkSize); + } + } + + final LayerHandle<OpacityLayer> _avatarOpacityLayerHandler = LayerHandle<OpacityLayer>(); + + void _paintAvatar(PaintingContext context, Offset offset) { + void paintWithOverlay(PaintingContext context, Offset offset) { + context.paintChild(avatar!, _boxParentData(avatar!).offset + offset); + _paintSelectionOverlay(context, offset); + } + + if (!theme.showAvatar && avatarDrawerAnimation.isDismissed) { + _avatarOpacityLayerHandler.layer = null; + return; + } + final Color disabledColor = _disabledColor; + final int disabledColorAlpha = disabledColor.alpha; + if (needsCompositing) { + _avatarOpacityLayerHandler.layer = context.pushOpacity(offset, disabledColorAlpha, paintWithOverlay, oldLayer: _avatarOpacityLayerHandler.layer); + } else { + _avatarOpacityLayerHandler.layer = null; + if (disabledColorAlpha != 0xff) { + context.canvas.saveLayer( + _boxRect(avatar).shift(offset).inflate(20.0), + Paint()..color = disabledColor, + ); + } + paintWithOverlay(context, offset); + if (disabledColorAlpha != 0xff) { + context.canvas.restore(); + } + } + } + + final LayerHandle<OpacityLayer> _labelOpacityLayerHandler = LayerHandle<OpacityLayer>(); + final LayerHandle<OpacityLayer> _deleteIconOpacityLayerHandler = LayerHandle<OpacityLayer>(); + + void _paintChild(PaintingContext context, Offset offset, RenderBox? child, {required bool isDeleteIcon}) { + if (child == null) { + _labelOpacityLayerHandler.layer = null; + _deleteIconOpacityLayerHandler.layer = null; + return; + } + final int disabledColorAlpha = _disabledColor.alpha; + if (!enableAnimation.isCompleted) { + if (needsCompositing) { + _labelOpacityLayerHandler.layer = context.pushOpacity( + offset, + disabledColorAlpha, + (PaintingContext context, Offset offset) { + context.paintChild(child, _boxParentData(child).offset + offset); + }, + oldLayer: _labelOpacityLayerHandler.layer, + ); + if (isDeleteIcon) { + _deleteIconOpacityLayerHandler.layer = context.pushOpacity( + offset, + disabledColorAlpha, + (PaintingContext context, Offset offset) { + context.paintChild(child, _boxParentData(child).offset + offset); + }, + oldLayer: _deleteIconOpacityLayerHandler.layer, + ); + } + } else { + _labelOpacityLayerHandler.layer = null; + _deleteIconOpacityLayerHandler.layer = null; + final Rect childRect = _boxRect(child).shift(offset); + context.canvas.saveLayer(childRect.inflate(20.0), Paint()..color = _disabledColor); + context.paintChild(child, _boxParentData(child).offset + offset); + context.canvas.restore(); + } + } else { + context.paintChild(child, _boxParentData(child).offset + offset); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + checkmarkAnimation.addListener(markNeedsPaint); + avatarDrawerAnimation.addListener(markNeedsLayout); + deleteDrawerAnimation.addListener(markNeedsLayout); + enableAnimation.addListener(markNeedsPaint); + } + + @override + void detach() { + checkmarkAnimation.removeListener(markNeedsPaint); + avatarDrawerAnimation.removeListener(markNeedsLayout); + deleteDrawerAnimation.removeListener(markNeedsLayout); + enableAnimation.removeListener(markNeedsPaint); + super.detach(); + } + + @override + void dispose() { + _labelOpacityLayerHandler.layer = null; + _deleteIconOpacityLayerHandler.layer = null; + _avatarOpacityLayerHandler.layer = null; + super.dispose(); + } + + @override + void paint(PaintingContext context, Offset offset) { + _paintAvatar(context, offset); + if (deleteIconShowing) { + _paintChild(context, offset, deleteIcon, isDeleteIcon: true); + } + _paintChild(context, offset, label, isDeleteIcon: false); + } + + // Set this to true to have outlines of the tap targets drawn over + // the chip. This should never be checked in while set to 'true'. + static const bool _debugShowTapTargetOutlines = false; + + @override + void debugPaint(PaintingContext context, Offset offset) { + assert(!_debugShowTapTargetOutlines || () { + // Draws a rect around the tap targets to help with visualizing where + // they really are. + final Paint outlinePaint = Paint() + ..color = const Color(0xff800000) + ..strokeWidth = 1.0 + ..style = PaintingStyle.stroke; + if (deleteIconShowing) { + context.canvas.drawRect(_deleteButtonRect.shift(offset), outlinePaint); + } + context.canvas.drawRect( + _pressRect.shift(offset), + outlinePaint..color = const Color(0xff008000), + ); + return true; + }()); + } + + @override + bool hitTestSelf(Offset position) => _deleteButtonRect.contains(position) || _pressRect.contains(position); +} + +class _ChipSizes { + _ChipSizes({ + required this.size, + required this.overall, + required this.content, + required this.avatar, + required this.label, + required this.deleteIcon, + required this.densityAdjustment, +}); + final Size size; + final Size overall; + final double content; + final Size avatar; + final Size label; + final Size deleteIcon; + final Offset densityAdjustment; +} + +class _UnconstrainedInkSplashFactory extends InteractiveInkFeatureFactory { + const _UnconstrainedInkSplashFactory(this.parentFactory); + + final InteractiveInkFeatureFactory parentFactory; + + @override + InteractiveInkFeature create({ + required MaterialInkController controller, + required RenderBox referenceBox, + required Offset position, + required Color color, + required TextDirection textDirection, + bool containedInkWell = false, + RectCallback? rectCallback, + BorderRadius? borderRadius, + ShapeBorder? customBorder, + double? radius, + VoidCallback? onRemoved, + }) { + return parentFactory.create( + controller: controller, + referenceBox: referenceBox, + position: position, + color: color, + rectCallback: rectCallback, + borderRadius: borderRadius, + customBorder: customBorder, + radius: radius, + onRemoved: onRemoved, + textDirection: textDirection, + ); + } +} + +bool _hitIsOnDeleteIcon({ + required EdgeInsetsGeometry padding, + required EdgeInsetsGeometry labelPadding, + required Offset tapPosition, + required Size chipSize, + required Size deleteButtonSize, + required TextDirection textDirection, +}) { + // The chipSize includes the padding, so we need to deflate the size and adjust the + // tap position to account for the padding. + final EdgeInsets resolvedPadding = padding.resolve(textDirection); + final Size deflatedSize = resolvedPadding.deflateSize(chipSize); + final Offset adjustedPosition = tapPosition - Offset(resolvedPadding.left, resolvedPadding.top); + // The delete button hit area should be at least the width of the delete + // button and right label padding, but, if there's room, up to 24 pixels + // from the center of the delete icon (corresponding to part of a 48x48 square + // that Material would prefer for touch targets), but no more than approximately + // half of the overall size of the chip when the chip is small. + // + // This isn't affected by materialTapTargetSize because it only applies to the + // width of the tappable region within the chip, not outside of the chip, + // which is handled elsewhere. Also because delete buttons aren't specified to + // be used on touch devices, only desktop devices. + + // Max out at not quite half, so that tests that tap on the center of a small + // chip will still hit the chip, not the delete button. + final double accessibleDeleteButtonWidth = math.min( + deflatedSize.width * 0.499, + math.min(labelPadding.resolve(textDirection).right + deleteButtonSize.width, 24.0 + deleteButtonSize.width / 2.0), + ); + switch (textDirection) { + case TextDirection.ltr: + return adjustedPosition.dx >= deflatedSize.width - accessibleDeleteButtonWidth; + case TextDirection.rtl: + return adjustedPosition.dx <= accessibleDeleteButtonWidth; + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - Chip + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _ChipDefaultsM3 extends ChipThemeData { + _ChipDefaultsM3(this.context, this.isEnabled) + : super( + elevation: 0.0, + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))), + showCheckmark: true, + ); + + final BuildContext context; + final bool isEnabled; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + TextStyle? get labelStyle => _textTheme.labelLarge; + + @override + MaterialStateProperty<Color?>? get color => null; // Subclasses override this getter + + @override + Color? get shadowColor => Colors.transparent; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + Color? get checkmarkColor => null; + + @override + Color? get deleteIconColor => null; + + @override + BorderSide? get side => isEnabled + ? BorderSide(color: _colors.outline) + : BorderSide(color: _colors.onSurface.withOpacity(0.12)); + + @override + IconThemeData? get iconTheme => IconThemeData( + color: isEnabled + ? _colors.primary + : _colors.onSurface, + size: 18.0, + ); + + @override + EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0); + + /// The chip at text scale 1 starts with 8px on each side and as text scaling + /// gets closer to 2, the label padding is linearly interpolated from 8px to 4px. + /// Once the widget has a text scaling of 2 or higher than the label padding + /// remains 4px. + @override + EdgeInsetsGeometry? get labelPadding => EdgeInsets.lerp( + const EdgeInsets.symmetric(horizontal: 8.0), + const EdgeInsets.symmetric(horizontal: 4.0), + clampDouble(MediaQuery.textScalerOf(context).textScaleFactor - 1.0, 0.0, 1.0), + )!; +} + +// END GENERATED TOKEN PROPERTIES - Chip diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/chip_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/chip_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..44aa0b0016bb942776309521ba83776a5d6e4d1c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/chip_theme.dart @@ -0,0 +1,627 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'material_state.dart'; +import 'theme.dart'; + +/// Applies a chip theme to descendant [RawChip]-based widgets, like [Chip], +/// [InputChip], [ChoiceChip], [FilterChip], and [ActionChip]. +/// +/// A chip theme describes the color, shape and text styles for the chips it is +/// applied to. +/// +/// Descendant widgets obtain the current theme's [ChipThemeData] object using +/// [ChipTheme.of]. When a widget uses [ChipTheme.of], it is automatically +/// rebuilt if the theme later changes. +/// +/// The [ThemeData] object given by the [Theme.of] call also contains a default +/// [ThemeData.chipTheme] that can be customized by copying it (using +/// [ChipThemeData.copyWith]). +/// +/// See also: +/// +/// * [Chip], a chip that displays information and can be deleted. +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [FilterChip], uses tags or descriptive words as a way to filter content. +/// * [ActionChip], represents an action related to primary content. +/// * [ChipThemeData], which describes the actual configuration of a chip +/// theme. +/// * [ThemeData], which describes the overall theme information for the +/// application. +class ChipTheme extends InheritedTheme { + /// Applies the given theme [data] to [child]. + const ChipTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the color, shape, and text style values for descendant chip + /// widgets. + final ChipThemeData data; + + /// Returns the data from the closest [ChipTheme] instance that encloses + /// the given context. + /// + /// Defaults to the ambient [ThemeData.chipTheme] if there is no + /// [ChipTheme] in the given build context. + /// + /// {@tool snippet} + /// + /// ```dart + /// class Spaceship extends StatelessWidget { + /// const Spaceship({super.key}); + /// + /// @override + /// Widget build(BuildContext context) { + /// return ChipTheme( + /// data: ChipTheme.of(context).copyWith(backgroundColor: Colors.red), + /// child: ActionChip( + /// label: const Text('Launch'), + /// onPressed: () { print('We have liftoff!'); }, + /// ), + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [ChipThemeData], which describes the actual configuration of a chip + /// theme. + static ChipThemeData of(BuildContext context) { + final ChipTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<ChipTheme>(); + return inheritedTheme?.data ?? Theme.of(context).chipTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return ChipTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(ChipTheme oldWidget) => data != oldWidget.data; +} + +/// Holds the color, shape, and text styles for a Material Design chip theme. +/// +/// Use this class to configure a [ChipTheme] widget, or to set the +/// [ThemeData.chipTheme] for a [Theme] widget. +/// +/// To obtain the current ambient chip theme, use [ChipTheme.of]. +/// +/// The parts of a chip are: +/// +/// * The "avatar", which is a widget that appears at the beginning of the +/// chip. This is typically a [CircleAvatar] widget. +/// * The "label", which is the widget displayed in the center of the chip. +/// Typically this is a [Text] widget. +/// * The "delete icon", which is a widget that appears at the end of the chip. +/// * The chip is disabled when it is not accepting user input. Only some chips +/// have a disabled state: [ActionChip], [ChoiceChip], [FilterChip], and +/// [InputChip]. +/// +/// The simplest way to create a ChipThemeData is to use [copyWith] on the one +/// you get from [ChipTheme.of], or create an entirely new one with +/// [ChipThemeData.fromDefaults]. +/// +/// {@tool snippet} +/// +/// ```dart +/// class CarColor extends StatefulWidget { +/// const CarColor({super.key}); +/// +/// @override +/// State createState() => _CarColorState(); +/// } +/// +/// class _CarColorState extends State<CarColor> { +/// Color _color = Colors.red; +/// +/// @override +/// Widget build(BuildContext context) { +/// return ChipTheme( +/// data: ChipTheme.of(context).copyWith(backgroundColor: Colors.lightBlue), +/// child: ChoiceChip( +/// label: const Text('Light Blue'), +/// onSelected: (bool value) { +/// setState(() { +/// _color = value ? Colors.lightBlue : Colors.red; +/// }); +/// }, +/// selected: _color == Colors.lightBlue, +/// ), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Chip], a chip that displays information and can be deleted. +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [FilterChip], uses tags or descriptive words as a way to filter content. +/// * [ActionChip], represents an action related to primary content. +/// * [CircleAvatar], which shows images or initials of entities. +/// * [Wrap], A widget that displays its children in multiple horizontal or +/// vertical runs. +/// * [ChipTheme] widget, which can override the chip theme of its +/// children. +/// * [Theme] widget, which performs a similar function to [ChipTheme], +/// but for overall themes. +/// * [ThemeData], which has a default [ChipThemeData]. +@immutable +class ChipThemeData with Diagnosticable { + /// Create a [ChipThemeData] given a set of exact values. All the values + /// must be specified except for [shadowColor], [selectedShadowColor], + /// [elevation], and [pressElevation], which may be null. + /// + /// This will rarely be used directly. It is used by [lerp] to + /// create intermediate themes based on two themes. + const ChipThemeData({ + this.color, + this.backgroundColor, + this.deleteIconColor, + this.disabledColor, + this.selectedColor, + this.secondarySelectedColor, + this.shadowColor, + this.surfaceTintColor, + this.selectedShadowColor, + this.showCheckmark, + this.checkmarkColor, + this.labelPadding, + this.padding, + this.side, + this.shape, + this.labelStyle, + this.secondaryLabelStyle, + this.brightness, + this.elevation, + this.pressElevation, + this.iconTheme, + }); + + /// Generates a ChipThemeData from a brightness, a primary color, and a text + /// style. + /// + /// The [brightness] is used to select a primary color from the default + /// values. + /// + /// The optional [primaryColor] is used as the base color for the other + /// colors. The opacity of the [primaryColor] is ignored. If a [primaryColor] + /// is specified, then the [brightness] is ignored, and the theme brightness + /// is determined from the [primaryColor]. + /// + /// Only one of [primaryColor] or [brightness] may be specified. + /// + /// The [secondaryColor] is used for the selection colors needed by + /// [ChoiceChip]. + /// + /// This is used to generate the default chip theme for a [ThemeData]. + factory ChipThemeData.fromDefaults({ + Brightness? brightness, + Color? primaryColor, + required Color secondaryColor, + required TextStyle labelStyle, + }) { + assert(primaryColor != null || brightness != null, 'One of primaryColor or brightness must be specified'); + assert(primaryColor == null || brightness == null, 'Only one of primaryColor or brightness may be specified'); + + if (primaryColor != null) { + brightness = ThemeData.estimateBrightnessForColor(primaryColor); + } + + // These are Material Design defaults, and are used to derive + // component Colors (with opacity) from base colors. + const int backgroundAlpha = 0x1f; // 12% + const int deleteIconAlpha = 0xde; // 87% + const int disabledAlpha = 0x0c; // 38% * 12% = 5% + const int selectAlpha = 0x3d; // 12% + 12% = 24% + const int textLabelAlpha = 0xde; // 87% + const EdgeInsetsGeometry padding = EdgeInsets.all(4.0); + + primaryColor = primaryColor ?? (brightness == Brightness.light ? Colors.black : Colors.white); + final Color backgroundColor = primaryColor.withAlpha(backgroundAlpha); + final Color deleteIconColor = primaryColor.withAlpha(deleteIconAlpha); + final Color disabledColor = primaryColor.withAlpha(disabledAlpha); + final Color selectedColor = primaryColor.withAlpha(selectAlpha); + final Color secondarySelectedColor = secondaryColor.withAlpha(selectAlpha); + final TextStyle secondaryLabelStyle = labelStyle.copyWith( + color: secondaryColor.withAlpha(textLabelAlpha), + ); + labelStyle = labelStyle.copyWith(color: primaryColor.withAlpha(textLabelAlpha)); + + return ChipThemeData( + backgroundColor: backgroundColor, + deleteIconColor: deleteIconColor, + disabledColor: disabledColor, + selectedColor: selectedColor, + secondarySelectedColor: secondarySelectedColor, + shadowColor: Colors.black, + selectedShadowColor: Colors.black, + showCheckmark: true, + padding: padding, + labelStyle: labelStyle, + secondaryLabelStyle: secondaryLabelStyle, + brightness: brightness, + elevation: 0.0, + pressElevation: 8.0, + ); + } + + /// Overrides the default for [ChipAttributes.color]. + /// + /// This property applies to [ActionChip], [Chip], [ChoiceChip], + /// [FilterChip], [InputChip], [RawChip]. + final MaterialStateProperty<Color?>? color; + + /// Overrides the default for [ChipAttributes.backgroundColor] + /// which is used for unselected, enabled chip backgrounds. + /// + /// This property applies to [ActionChip], [Chip], [ChoiceChip], + /// [FilterChip], [InputChip], [RawChip]. + final Color? backgroundColor; + + /// Overrides the default for [DeletableChipAttributes.deleteIconColor]. + /// + /// This property applies to [Chip], [InputChip], [RawChip]. + final Color? deleteIconColor; + + /// Overrides the default for + /// [DisabledChipAttributes.disabledColor], the background color + /// which indicates that the chip is not enabled. + /// + /// This property applies to [ActionChip], [ChoiceChip], + /// [FilterChip], [InputChip], and [RawChip]. + final Color? disabledColor; + + /// Overrides the default for + /// [SelectableChipAttributes.selectedColor], the background color + /// that indicates that the chip is selected. + /// + /// This property applies to [ChoiceChip], [FilterChip], + /// [InputChip], [RawChip]. + final Color? selectedColor; + + /// Overrides the default for [ChoiceChip.selectedColor], the + /// background color that indicates that the chip is selected. + final Color? secondarySelectedColor; + + /// Overrides the default for [ChipAttributes.shadowColor], the + /// Color of the chip's shadow when its elevation is greater than 0. + /// + /// This property applies to [ActionChip], [Chip], [ChoiceChip], + /// [FilterChip], [InputChip], [RawChip]. + final Color? shadowColor; + + /// Overrides the default for [ChipAttributes.surfaceTintColor], the + /// Color of the chip's surface tint overlay when its elevation is + /// greater than 0. + /// + /// This property applies to [ActionChip], [Chip], [ChoiceChip], + /// [FilterChip], [InputChip], [RawChip]. + final Color? surfaceTintColor; + + /// Overrides the default for + /// [SelectableChipAttributes.selectedShadowColor], the Color of the + /// chip's shadow when its elevation is greater than 0 and the chip + /// is selected. + /// + /// This property applies to [ChoiceChip], [FilterChip], + /// [InputChip], [RawChip]. + final Color? selectedShadowColor; + + /// Overrides the default for + /// [CheckmarkableChipAttributes.showCheckmark], which indicates if + /// a check mark should be shown. + /// + /// This property applies to [FilterChip], [InputChip], [RawChip]. + final bool? showCheckmark; + + /// Overrides the default for + /// [CheckmarkableChipAttributes.checkmarkColor]. + /// + /// This property applies to [FilterChip], [InputChip], [RawChip]. + final Color? checkmarkColor; + + /// Overrides the default for [ChipAttributes.labelPadding], + /// the padding around the chip's label widget. + /// + /// This property applies to [ActionChip], [Chip], [ChoiceChip], + /// [FilterChip], [InputChip], [RawChip]. + final EdgeInsetsGeometry? labelPadding; + + /// Overrides the default for [ChipAttributes.padding], + /// the padding between the contents of the chip and the outside [shape]. + /// + /// This property applies to [ActionChip], [Chip], [ChoiceChip], + /// [FilterChip], [InputChip], [RawChip]. + final EdgeInsetsGeometry? padding; + + /// Overrides the default for [ChipAttributes.side], + /// the color and weight of the chip's outline. + /// + /// This value is combined with [shape] to create a shape decorated with an + /// outline. If it is a [MaterialStateBorderSide], + /// [MaterialStateProperty.resolve] is used for the following + /// [MaterialState]s: + /// + /// * [MaterialState.disabled]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.pressed]. + /// + /// This property applies to [ActionChip], [Chip], [ChoiceChip], + /// [FilterChip], [InputChip], [RawChip]. + final BorderSide? side; + + /// Overrides the default for [ChipAttributes.shape], + /// the shape of border to draw around the chip. + /// + /// This shape is combined with [side] to create a shape decorated with an + /// outline. If it is a [MaterialStateOutlinedBorder], + /// [MaterialStateProperty.resolve] is used for the following + /// [MaterialState]s: + /// + /// * [MaterialState.disabled]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.pressed]. + /// + /// This property applies to [ActionChip], [Chip], [ChoiceChip], + /// [FilterChip], [InputChip], [RawChip]. + final OutlinedBorder? shape; + + /// Overrides the default for [ChipAttributes.labelStyle], + /// the style of the [DefaultTextStyle] that contains the + /// chip's label. + /// + /// This only has an effect on label widgets that respect the + /// [DefaultTextStyle], such as [Text]. + /// + /// This property applies to [ActionChip], [Chip], + /// [FilterChip], [InputChip], [RawChip]. + final TextStyle? labelStyle; + + /// Overrides the default for [ChoiceChip.labelStyle], + /// the style of the [DefaultTextStyle] that contains the + /// chip's label. + /// + /// This only has an effect on label widgets that respect the + /// [DefaultTextStyle], such as [Text]. + final TextStyle? secondaryLabelStyle; + + /// Overrides the default value for all chips which affects various base + /// material color choices in the chip rendering. + final Brightness? brightness; + + /// Overrides the default for [ChipAttributes.elevation], + /// the elevation of the chip's [Material]. + /// + /// This property applies to [ActionChip], [Chip], [ChoiceChip], + /// [FilterChip], [InputChip], [RawChip]. + final double? elevation; + + /// Overrides the default for [TappableChipAttributes.pressElevation], + /// the elevation of the chip's [Material] during a "press" or tap down. + /// + /// This property applies to [ActionChip], [InputChip], [RawChip]. + final double? pressElevation; + + /// Overrides the default for [ChipAttributes.iconTheme], + /// the theme used for all icons in the chip. + /// + /// This property applies to [ActionChip], [Chip], [ChoiceChip], + /// [FilterChip], [InputChip], [RawChip]. + final IconThemeData? iconTheme; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + ChipThemeData copyWith({ + MaterialStateProperty<Color?>? color, + Color? backgroundColor, + Color? deleteIconColor, + Color? disabledColor, + Color? selectedColor, + Color? secondarySelectedColor, + Color? shadowColor, + Color? surfaceTintColor, + Color? selectedShadowColor, + bool? showCheckmark, + Color? checkmarkColor, + EdgeInsetsGeometry? labelPadding, + EdgeInsetsGeometry? padding, + BorderSide? side, + OutlinedBorder? shape, + TextStyle? labelStyle, + TextStyle? secondaryLabelStyle, + Brightness? brightness, + double? elevation, + double? pressElevation, + IconThemeData? iconTheme, + }) { + return ChipThemeData( + color: color ?? this.color, + backgroundColor: backgroundColor ?? this.backgroundColor, + deleteIconColor: deleteIconColor ?? this.deleteIconColor, + disabledColor: disabledColor ?? this.disabledColor, + selectedColor: selectedColor ?? this.selectedColor, + secondarySelectedColor: secondarySelectedColor ?? this.secondarySelectedColor, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + selectedShadowColor: selectedShadowColor ?? this.selectedShadowColor, + showCheckmark: showCheckmark ?? this.showCheckmark, + checkmarkColor: checkmarkColor ?? this.checkmarkColor, + labelPadding: labelPadding ?? this.labelPadding, + padding: padding ?? this.padding, + side: side ?? this.side, + shape: shape ?? this.shape, + labelStyle: labelStyle ?? this.labelStyle, + secondaryLabelStyle: secondaryLabelStyle ?? this.secondaryLabelStyle, + brightness: brightness ?? this.brightness, + elevation: elevation ?? this.elevation, + pressElevation: pressElevation ?? this.pressElevation, + iconTheme: iconTheme ?? this.iconTheme, + ); + } + + /// Linearly interpolate between two chip themes. + /// + /// {@macro dart.ui.shadow.lerp} + static ChipThemeData? lerp(ChipThemeData? a, ChipThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return ChipThemeData( + color: MaterialStateProperty.lerp<Color?>(a?.color, b?.color, t, Color.lerp), + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + deleteIconColor: Color.lerp(a?.deleteIconColor, b?.deleteIconColor, t), + disabledColor: Color.lerp(a?.disabledColor, b?.disabledColor, t), + selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t), + secondarySelectedColor: Color.lerp(a?.secondarySelectedColor, b?.secondarySelectedColor, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + selectedShadowColor: Color.lerp(a?.selectedShadowColor, b?.selectedShadowColor, t), + showCheckmark: t < 0.5 ? a?.showCheckmark ?? true : b?.showCheckmark ?? true, + checkmarkColor: Color.lerp(a?.checkmarkColor, b?.checkmarkColor, t), + labelPadding: EdgeInsetsGeometry.lerp(a?.labelPadding, b?.labelPadding, t), + padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t), + side: _lerpSides(a?.side, b?.side, t), + shape: _lerpShapes(a?.shape, b?.shape, t), + labelStyle: TextStyle.lerp(a?.labelStyle, b?.labelStyle, t), + secondaryLabelStyle: TextStyle.lerp(a?.secondaryLabelStyle, b?.secondaryLabelStyle, t), + brightness: t < 0.5 ? a?.brightness ?? Brightness.light : b?.brightness ?? Brightness.light, + elevation: lerpDouble(a?.elevation, b?.elevation, t), + pressElevation: lerpDouble(a?.pressElevation, b?.pressElevation, t), + iconTheme: a?.iconTheme != null || b?.iconTheme != null + ? IconThemeData.lerp(a?.iconTheme, b?.iconTheme, t) + : null, + ); + } + + // Special case because BorderSide.lerp() doesn't support null arguments. + static BorderSide? _lerpSides(BorderSide? a, BorderSide? b, double t) { + if (a == null && b == null) { + return null; + } + if (a == null) { + return BorderSide.lerp(BorderSide(width: 0, color: b!.color.withAlpha(0)), b, t); + } + if (b == null) { + return BorderSide.lerp(BorderSide(width: 0, color: a.color.withAlpha(0)), a, t); + } + return BorderSide.lerp(a, b, t); + } + + // TODO(perclasson): OutlinedBorder needs a lerp method - https://github.com/flutter/flutter/issues/60555. + static OutlinedBorder? _lerpShapes(OutlinedBorder? a, OutlinedBorder? b, double t) { + if (a == null && b == null) { + return null; + } + return ShapeBorder.lerp(a, b, t) as OutlinedBorder?; + } + + @override + int get hashCode => Object.hashAll(<Object?>[ + color, + backgroundColor, + deleteIconColor, + disabledColor, + selectedColor, + secondarySelectedColor, + shadowColor, + surfaceTintColor, + selectedShadowColor, + showCheckmark, + checkmarkColor, + labelPadding, + padding, + side, + shape, + labelStyle, + secondaryLabelStyle, + brightness, + elevation, + pressElevation, + iconTheme, + ]); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ChipThemeData + && other.color == color + && other.backgroundColor == backgroundColor + && other.deleteIconColor == deleteIconColor + && other.disabledColor == disabledColor + && other.selectedColor == selectedColor + && other.secondarySelectedColor == secondarySelectedColor + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.selectedShadowColor == selectedShadowColor + && other.showCheckmark == showCheckmark + && other.checkmarkColor == checkmarkColor + && other.labelPadding == labelPadding + && other.padding == padding + && other.side == side + && other.shape == shape + && other.labelStyle == labelStyle + && other.secondaryLabelStyle == secondaryLabelStyle + && other.brightness == brightness + && other.elevation == elevation + && other.pressElevation == pressElevation + && other.iconTheme == iconTheme; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('color', color, defaultValue: null)); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(ColorProperty('deleteIconColor', deleteIconColor, defaultValue: null)); + properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: null)); + properties.add(ColorProperty('selectedColor', selectedColor, defaultValue: null)); + properties.add(ColorProperty('secondarySelectedColor', secondarySelectedColor, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(ColorProperty('selectedShadowColor', selectedShadowColor, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('showCheckmark', showCheckmark, defaultValue: null)); + properties.add(ColorProperty('checkMarkColor', checkmarkColor, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('labelPadding', labelPadding, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<BorderSide>('side', side, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('labelStyle', labelStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('secondaryLabelStyle', secondaryLabelStyle, defaultValue: null)); + properties.add(EnumProperty<Brightness>('brightness', brightness, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(DoubleProperty('pressElevation', pressElevation, defaultValue: null)); + properties.add(DiagnosticsProperty<IconThemeData>('iconTheme', iconTheme, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/choice_chip.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/choice_chip.dart new file mode 100644 index 0000000000000000000000000000000000000000..873d554199b908301836847b8f3360b97149e405 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/choice_chip.dart @@ -0,0 +1,344 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/widgets.dart'; + +import 'chip.dart'; +import 'chip_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'debug.dart'; +import 'material_state.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +enum _ChipVariant { flat, elevated } + +/// A Material Design choice chip. +/// +/// [ChoiceChip]s represent a single choice from a set. Choice chips contain +/// related descriptive text or categories. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// {@tool dartpad} +/// This example shows how to create [ChoiceChip]s with [onSelected]. When the +/// user taps, the chip will be selected. +/// +/// ** See code in examples/api/lib/material/choice_chip/choice_chip.0.dart ** +/// {@end-tool} +/// +/// ## Material Design 3 +/// +/// [ChoiceChip] can be used for single select Filter chips from +/// Material Design 3. If [ThemeData.useMaterial3] is true, then [ChoiceChip] +/// will be styled to match the Material Design 3 specification for Filter +/// chips. Use [FilterChip] for multiple select Filter chips. +/// +/// See also: +/// +/// * [Chip], a chip that displays information and can be deleted. +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [FilterChip], uses tags or descriptive words as a way to filter content. +/// * [ActionChip], represents an action related to primary content. +/// * [CircleAvatar], which shows images or initials of people. +/// * [Wrap], A widget that displays its children in multiple horizontal or +/// vertical runs. +/// * <https://material.io/design/components/chips.html> +class ChoiceChip extends StatelessWidget + implements + ChipAttributes, + SelectableChipAttributes, + CheckmarkableChipAttributes, + DisabledChipAttributes { + /// Create a chip that acts like a radio button. + /// + /// The [label], [selected], [autofocus], and [clipBehavior] arguments must + /// not be null. The [pressElevation] and [elevation] must be null or + /// non-negative. Typically, [pressElevation] is greater than [elevation]. + const ChoiceChip({ + super.key, + this.avatar, + required this.label, + this.labelStyle, + this.labelPadding, + this.onSelected, + this.pressElevation, + required this.selected, + this.selectedColor, + this.disabledColor, + this.tooltip, + this.side, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.color, + this.backgroundColor, + this.padding, + this.visualDensity, + this.materialTapTargetSize, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.iconTheme, + this.selectedShadowColor, + this.showCheckmark, + this.checkmarkColor, + this.avatarBorder = const CircleBorder(), + }) : assert(pressElevation == null || pressElevation >= 0.0), + assert(elevation == null || elevation >= 0.0), + _chipVariant = _ChipVariant.flat; + + /// Create an elevated chip that acts like a radio button. + /// + /// The [label], [selected], [autofocus], and [clipBehavior] arguments must + /// not be null. The [pressElevation] and [elevation] must be null or + /// non-negative. Typically, [pressElevation] is greater than [elevation]. + const ChoiceChip.elevated({ + super.key, + this.avatar, + required this.label, + this.labelStyle, + this.labelPadding, + this.onSelected, + this.pressElevation, + required this.selected, + this.selectedColor, + this.disabledColor, + this.tooltip, + this.side, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.color, + this.backgroundColor, + this.padding, + this.visualDensity, + this.materialTapTargetSize, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.iconTheme, + this.selectedShadowColor, + this.showCheckmark, + this.checkmarkColor, + this.avatarBorder = const CircleBorder(), + }) : assert(pressElevation == null || pressElevation >= 0.0), + assert(elevation == null || elevation >= 0.0), + _chipVariant = _ChipVariant.elevated; + + @override + final Widget? avatar; + @override + final Widget label; + @override + final TextStyle? labelStyle; + @override + final EdgeInsetsGeometry? labelPadding; + @override + final ValueChanged<bool>? onSelected; + @override + final double? pressElevation; + @override + final bool selected; + @override + final Color? disabledColor; + @override + final Color? selectedColor; + @override + final String? tooltip; + @override + final BorderSide? side; + @override + final OutlinedBorder? shape; + @override + final Clip clipBehavior; + @override + final FocusNode? focusNode; + @override + final bool autofocus; + @override + final MaterialStateProperty<Color?>? color; + @override + final Color? backgroundColor; + @override + final EdgeInsetsGeometry? padding; + @override + final VisualDensity? visualDensity; + @override + final MaterialTapTargetSize? materialTapTargetSize; + @override + final double? elevation; + @override + final Color? shadowColor; + @override + final Color? surfaceTintColor; + @override + final Color? selectedShadowColor; + @override + final bool? showCheckmark; + @override + final Color? checkmarkColor; + @override + final ShapeBorder avatarBorder; + @override + final IconThemeData? iconTheme; + + @override + bool get isEnabled => onSelected != null; + + final _ChipVariant _chipVariant; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + final ChipThemeData chipTheme = ChipTheme.of(context); + final ChipThemeData? defaults = Theme.of(context).useMaterial3 + ? _ChoiceChipDefaultsM3(context, isEnabled, selected, _chipVariant) + : null; + return RawChip( + defaultProperties: defaults, + avatar: avatar, + label: label, + labelStyle: labelStyle ?? (selected ? chipTheme.secondaryLabelStyle : null), + labelPadding: labelPadding, + onSelected: onSelected, + pressElevation: pressElevation, + selected: selected, + showCheckmark: showCheckmark ?? chipTheme.showCheckmark ?? Theme.of(context).useMaterial3, + checkmarkColor: checkmarkColor, + tooltip: tooltip, + side: side, + shape: shape, + clipBehavior: clipBehavior, + focusNode: focusNode, + autofocus: autofocus, + disabledColor: disabledColor, + selectedColor: selectedColor ?? chipTheme.secondarySelectedColor, + color: color, + backgroundColor: backgroundColor, + padding: padding, + visualDensity: visualDensity, + isEnabled: isEnabled, + materialTapTargetSize: materialTapTargetSize, + elevation: elevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + selectedShadowColor: selectedShadowColor, + avatarBorder: avatarBorder, + iconTheme: iconTheme, + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - ChoiceChip + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _ChoiceChipDefaultsM3 extends ChipThemeData { + _ChoiceChipDefaultsM3( + this.context, + this.isEnabled, + this.isSelected, + this._chipVariant, + ) : super( + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))), + showCheckmark: true, + ); + + final BuildContext context; + final bool isEnabled; + final bool isSelected; + final _ChipVariant _chipVariant; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + double? get elevation => _chipVariant == _ChipVariant.flat + ? 0.0 + : isEnabled ? 1.0 : 0.0; + + @override + double? get pressElevation => 1.0; + + @override + TextStyle? get labelStyle => _textTheme.labelLarge; + + @override + MaterialStateProperty<Color?>? get color => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected) && states.contains(MaterialState.disabled)) { + return _chipVariant == _ChipVariant.flat + ? _colors.onSurface.withOpacity(0.12) + : _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.disabled)) { + return _chipVariant == _ChipVariant.flat + ? null + : _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.selected)) { + return _chipVariant == _ChipVariant.flat + ? _colors.secondaryContainer + : _colors.secondaryContainer; + } + return _chipVariant == _ChipVariant.flat + ? null + : null; + }); + + @override + Color? get shadowColor => _chipVariant == _ChipVariant.flat + ? Colors.transparent + : _colors.shadow; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + Color? get checkmarkColor => _colors.onSecondaryContainer; + + @override + Color? get deleteIconColor => _colors.onSecondaryContainer; + + @override + BorderSide? get side => _chipVariant == _ChipVariant.flat && !isSelected + ? isEnabled + ? BorderSide(color: _colors.outline) + : BorderSide(color: _colors.onSurface.withOpacity(0.12)) + : const BorderSide(color: Colors.transparent); + + @override + IconThemeData? get iconTheme => IconThemeData( + color: isEnabled + ? null + : _colors.onSurface, + size: 18.0, + ); + + @override + EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0); + + /// The chip at text scale 1 starts with 8px on each side and as text scaling + /// gets closer to 2 the label padding is linearly interpolated from 8px to 4px. + /// Once the widget has a text scaling of 2 or higher than the label padding + /// remains 4px. + @override + EdgeInsetsGeometry? get labelPadding => EdgeInsets.lerp( + const EdgeInsets.symmetric(horizontal: 8.0), + const EdgeInsets.symmetric(horizontal: 4.0), + clampDouble(MediaQuery.textScalerOf(context).textScaleFactor - 1.0, 0.0, 1.0), + )!; +} + +// END GENERATED TOKEN PROPERTIES - ChoiceChip diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/circle_avatar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/circle_avatar.dart new file mode 100644 index 0000000000000000000000000000000000000000..3f7c9584ff0cb0a27e78e753451ae97b1c1a7d7b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/circle_avatar.dart @@ -0,0 +1,269 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'constants.dart'; +import 'theme.dart'; + +// Examples can assume: +// late String userAvatarUrl; + +/// A circle that represents a user. +/// +/// Typically used with a user's profile image, or, in the absence of +/// such an image, the user's initials. A given user's initials should +/// always be paired with the same background color, for consistency. +/// +/// If [foregroundImage] fails then [backgroundImage] is used. If +/// [backgroundImage] fails too, [backgroundColor] is used. +/// +/// The [onBackgroundImageError] parameter must be null if the [backgroundImage] +/// is null. +/// The [onForegroundImageError] parameter must be null if the [foregroundImage] +/// is null. +/// +/// {@tool snippet} +/// +/// If the avatar is to have an image, the image should be specified in the +/// [backgroundImage] property: +/// +/// ```dart +/// CircleAvatar( +/// backgroundImage: NetworkImage(userAvatarUrl), +/// ) +/// ``` +/// {@end-tool} +/// +/// The image will be cropped to have a circle shape. +/// +/// {@tool snippet} +/// +/// If the avatar is to just have the user's initials, they are typically +/// provided using a [Text] widget as the [child] and a [backgroundColor]: +/// +/// ```dart +/// CircleAvatar( +/// backgroundColor: Colors.brown.shade800, +/// child: const Text('AH'), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Chip], for representing users or concepts in long form. +/// * [ListTile], which can combine an icon (such as a [CircleAvatar]) with +/// some text for a fixed height list entry. +/// * <https://material.io/design/components/chips.html#input-chips> +class CircleAvatar extends StatelessWidget { + /// Creates a circle that represents a user. + const CircleAvatar({ + super.key, + this.child, + this.backgroundColor, + this.backgroundImage, + this.foregroundImage, + this.onBackgroundImageError, + this.onForegroundImageError, + this.foregroundColor, + this.radius, + this.minRadius, + this.maxRadius, + }) : assert(radius == null || (minRadius == null && maxRadius == null)), + assert(backgroundImage != null || onBackgroundImageError == null), + assert(foregroundImage != null || onForegroundImageError== null); + + /// The widget below this widget in the tree. + /// + /// Typically a [Text] widget. If the [CircleAvatar] is to have an image, use + /// [backgroundImage] instead. + final Widget? child; + + /// The color with which to fill the circle. Changing the background + /// color will cause the avatar to animate to the new color. + /// + /// If a [backgroundColor] is not specified and [ThemeData.useMaterial3] is true, + /// [ColorScheme.primaryContainer] will be used, otherwise the theme's + /// [ThemeData.primaryColorLight] is used with dark foreground colors, and + /// [ThemeData.primaryColorDark] with light foreground colors. + final Color? backgroundColor; + + /// The default text color for text in the circle. + /// + /// Defaults to the primary text theme color if no [backgroundColor] is + /// specified. + /// + /// If a [foregroundColor] is not specified and [ThemeData.useMaterial3] is true, + /// [ColorScheme.onPrimaryContainer] will be used, otherwise the theme's + /// [ThemeData.primaryColorLight] for dark background colors, and + /// [ThemeData.primaryColorDark] for light background colors. + final Color? foregroundColor; + + /// The background image of the circle. Changing the background + /// image will cause the avatar to animate to the new image. + /// + /// Typically used as a fallback image for [foregroundImage]. + /// + /// If the [CircleAvatar] is to have the user's initials, use [child] instead. + final ImageProvider? backgroundImage; + + /// The foreground image of the circle. + /// + /// Typically used as profile image. For fallback use [backgroundImage]. + final ImageProvider? foregroundImage; + + /// An optional error callback for errors emitted when loading + /// [backgroundImage]. + final ImageErrorListener? onBackgroundImageError; + + /// An optional error callback for errors emitted when loading + /// [foregroundImage]. + final ImageErrorListener? onForegroundImageError; + + /// The size of the avatar, expressed as the radius (half the diameter). + /// + /// If [radius] is specified, then neither [minRadius] nor [maxRadius] may be + /// specified. Specifying [radius] is equivalent to specifying a [minRadius] + /// and [maxRadius], both with the value of [radius]. + /// + /// If neither [minRadius] nor [maxRadius] are specified, defaults to 20 + /// logical pixels. This is the appropriate size for use with + /// [ListTile.leading]. + /// + /// Changes to the [radius] are animated (including changing from an explicit + /// [radius] to a [minRadius]/[maxRadius] pair or vice versa). + final double? radius; + + /// The minimum size of the avatar, expressed as the radius (half the + /// diameter). + /// + /// If [minRadius] is specified, then [radius] must not also be specified. + /// + /// Defaults to zero. + /// + /// Constraint changes are animated, but size changes due to the environment + /// itself changing are not. For example, changing the [minRadius] from 10 to + /// 20 when the [CircleAvatar] is in an unconstrained environment will cause + /// the avatar to animate from a 20 pixel diameter to a 40 pixel diameter. + /// However, if the [minRadius] is 40 and the [CircleAvatar] has a parent + /// [SizedBox] whose size changes instantaneously from 20 pixels to 40 pixels, + /// the size will snap to 40 pixels instantly. + final double? minRadius; + + /// The maximum size of the avatar, expressed as the radius (half the + /// diameter). + /// + /// If [maxRadius] is specified, then [radius] must not also be specified. + /// + /// Defaults to [double.infinity]. + /// + /// Constraint changes are animated, but size changes due to the environment + /// itself changing are not. For example, changing the [maxRadius] from 10 to + /// 20 when the [CircleAvatar] is in an unconstrained environment will cause + /// the avatar to animate from a 20 pixel diameter to a 40 pixel diameter. + /// However, if the [maxRadius] is 40 and the [CircleAvatar] has a parent + /// [SizedBox] whose size changes instantaneously from 20 pixels to 40 pixels, + /// the size will snap to 40 pixels instantly. + final double? maxRadius; + + // The default radius if nothing is specified. + static const double _defaultRadius = 20.0; + + // The default min if only the max is specified. + static const double _defaultMinRadius = 0.0; + + // The default max if only the min is specified. + static const double _defaultMaxRadius = double.infinity; + + double get _minDiameter { + if (radius == null && minRadius == null && maxRadius == null) { + return _defaultRadius * 2.0; + } + return 2.0 * (radius ?? minRadius ?? _defaultMinRadius); + } + + double get _maxDiameter { + if (radius == null && minRadius == null && maxRadius == null) { + return _defaultRadius * 2.0; + } + return 2.0 * (radius ?? maxRadius ?? _defaultMaxRadius); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final ThemeData theme = Theme.of(context); + final Color? effectiveForegroundColor = foregroundColor + ?? (theme.useMaterial3 ? theme.colorScheme.onPrimaryContainer : null); + final TextStyle effectiveTextStyle = theme.useMaterial3 + ? theme.textTheme.titleMedium! + : theme.primaryTextTheme.titleMedium!; + TextStyle textStyle = effectiveTextStyle.copyWith(color: effectiveForegroundColor); + Color? effectiveBackgroundColor = backgroundColor + ?? (theme.useMaterial3 ? theme.colorScheme.primaryContainer : null); + if (effectiveBackgroundColor == null) { + switch (ThemeData.estimateBrightnessForColor(textStyle.color!)) { + case Brightness.dark: + effectiveBackgroundColor = theme.primaryColorLight; + case Brightness.light: + effectiveBackgroundColor = theme.primaryColorDark; + } + } else if (effectiveForegroundColor == null) { + switch (ThemeData.estimateBrightnessForColor(backgroundColor!)) { + case Brightness.dark: + textStyle = textStyle.copyWith(color: theme.primaryColorLight); + case Brightness.light: + textStyle = textStyle.copyWith(color: theme.primaryColorDark); + } + } + final double minDiameter = _minDiameter; + final double maxDiameter = _maxDiameter; + return AnimatedContainer( + constraints: BoxConstraints( + minHeight: minDiameter, + minWidth: minDiameter, + maxWidth: maxDiameter, + maxHeight: maxDiameter, + ), + duration: kThemeChangeDuration, + decoration: BoxDecoration( + color: effectiveBackgroundColor, + image: backgroundImage != null + ? DecorationImage( + image: backgroundImage!, + onError: onBackgroundImageError, + fit: BoxFit.cover, + ) + : null, + shape: BoxShape.circle, + ), + foregroundDecoration: foregroundImage != null + ? BoxDecoration( + image: DecorationImage( + image: foregroundImage!, + onError: onForegroundImageError, + fit: BoxFit.cover, + ), + shape: BoxShape.circle, + ) + : null, + child: child == null + ? null + : Center( + // Need to disable text scaling here so that the text doesn't + // escape the avatar when the textScaleFactor is large. + child: MediaQuery.withNoTextScaling( + child: IconTheme( + data: theme.iconTheme.copyWith(color: textStyle.color), + child: DefaultTextStyle( + style: textStyle, + child: child!, + ), + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/color_scheme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/color_scheme.dart new file mode 100644 index 0000000000000000000000000000000000000000..2ee1d0c0831840454270e6dde015f658648392ed --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/color_scheme.dart @@ -0,0 +1,1196 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; +import 'package:material_color_utilities/material_color_utilities.dart'; + +import 'colors.dart'; +import 'theme_data.dart'; + +/// {@template flutter.material.color_scheme.ColorScheme} +/// A set of 30 colors based on the +/// [Material spec](https://m3.material.io/styles/color/the-color-system/color-roles) +/// that can be used to configure the color properties of most components. +/// {@endtemplate} +/// +/// ### Colors in Material 3 +/// +/// {@macro flutter.material.colors.colorRoles} +/// +/// The main accent color groups in the scheme are [primary], [secondary], +/// and [tertiary]. +/// +/// * Primary colors are used for key components across the UI, such as the FAB, +/// prominent buttons, and active states. +/// +/// * Secondary colors are used for less prominent components in the UI, such as +/// filter chips, while expanding the opportunity for color expression. +/// +/// * Tertiary colors are used for contrasting accents that can be used to +/// balance primary and secondary colors or bring heightened attention to +/// an element, such as an input field. The tertiary colors are left +/// for makers to use at their discretion and are intended to support +/// broader color expression in products. +/// +/// The remaining colors of the scheme are composed of neutral colors used for +/// backgrounds and surfaces, as well as specific colors for errors, dividers +/// and shadows. +/// +/// Many of the colors have matching 'on' colors, which are used for drawing +/// content on top of the matching color. For example, if something is using +/// [primary] for a background color, [onPrimary] would be used to paint text +/// and icons on top of it. For this reason, the 'on' colors should have a +/// contrast ratio with their matching colors of at least 4.5:1 in order to +/// be readable. +/// +/// ### Setting Colors in Flutter +/// +///{@macro flutter.material.colors.settingColors} +// +@immutable +class ColorScheme with Diagnosticable { + /// Create a ColorScheme instance from the given colors. + /// + /// [ColorScheme.fromSeed] can be used as a simpler way to create a full + /// color scheme derived from a single seed color. + /// + /// For the color parameters that are nullable, it is still recommended + /// that applications provide values for them. They are only nullable due + /// to backwards compatibility concerns. + /// + /// If a color is not provided, the closest fallback color from the given + /// colors will be used for it (e.g. [primaryContainer] will default + /// to [primary]). Material Design 3 makes use of these colors for many + /// component defaults, so for the best results the application should + /// supply colors for all the parameters. An easy way to ensure this is to + /// use [ColorScheme.fromSeed] to generate a full set of colors. + /// + /// During the migration to Material Design 3, if an app's + /// [ThemeData.useMaterial3] is false, then components will only + /// use the following colors for defaults: + /// + /// * [primary] + /// * [onPrimary] + /// * [secondary] + /// * [onSecondary] + /// * [error] + /// * [onError] + /// * [background] + /// * [onBackground] + /// * [surface] + /// * [onSurface] + const ColorScheme({ + required this.brightness, + required this.primary, + required this.onPrimary, + Color? primaryContainer, + Color? onPrimaryContainer, + required this.secondary, + required this.onSecondary, + Color? secondaryContainer, + Color? onSecondaryContainer, + Color? tertiary, + Color? onTertiary, + Color? tertiaryContainer, + Color? onTertiaryContainer, + required this.error, + required this.onError, + Color? errorContainer, + Color? onErrorContainer, + required this.background, + required this.onBackground, + required this.surface, + required this.onSurface, + Color? surfaceVariant, + Color? onSurfaceVariant, + Color? outline, + Color? outlineVariant, + Color? shadow, + Color? scrim, + Color? inverseSurface, + Color? onInverseSurface, + Color? inversePrimary, + Color? surfaceTint, + }) : _primaryContainer = primaryContainer, + _onPrimaryContainer = onPrimaryContainer, + _secondaryContainer = secondaryContainer, + _onSecondaryContainer = onSecondaryContainer, + _tertiary = tertiary, + _onTertiary = onTertiary, + _tertiaryContainer = tertiaryContainer, + _onTertiaryContainer = onTertiaryContainer, + _errorContainer = errorContainer, + _onErrorContainer = onErrorContainer, + _surfaceVariant = surfaceVariant, + _onSurfaceVariant = onSurfaceVariant, + _outline = outline, + _outlineVariant = outlineVariant, + _shadow = shadow, + _scrim = scrim, + _inverseSurface = inverseSurface, + _onInverseSurface = onInverseSurface, + _inversePrimary = inversePrimary, + _surfaceTint = surfaceTint; + + /// Generate a [ColorScheme] derived from the given `seedColor`. + /// + /// Using the seedColor as a starting point, a set of tonal palettes are + /// constructed. These tonal palettes are based on the Material 3 Color + /// system and provide all the needed colors for a [ColorScheme]. These + /// colors are designed to work well together and meet contrast + /// requirements for accessibility. + /// + /// If any of the optional color parameters are non-null they will be + /// used in place of the generated colors for that field in the resulting + /// color scheme. This allows apps to override specific colors for their + /// needs. + /// + /// Given the nature of the algorithm, the seedColor may not wind up as + /// one of the ColorScheme colors. + /// + /// See also: + /// + /// * <https://m3.material.io/styles/color/the-color-system/color-roles>, the + /// Material 3 Color system specification. + /// * <https://pub.dev/packages/material_color_utilities>, the package + /// used to generate the tonal palettes needed for the scheme. + factory ColorScheme.fromSeed({ + required Color seedColor, + Brightness brightness = Brightness.light, + Color? primary, + Color? onPrimary, + Color? primaryContainer, + Color? onPrimaryContainer, + Color? secondary, + Color? onSecondary, + Color? secondaryContainer, + Color? onSecondaryContainer, + Color? tertiary, + Color? onTertiary, + Color? tertiaryContainer, + Color? onTertiaryContainer, + Color? error, + Color? onError, + Color? errorContainer, + Color? onErrorContainer, + Color? outline, + Color? outlineVariant, + Color? background, + Color? onBackground, + Color? surface, + Color? onSurface, + Color? surfaceVariant, + Color? onSurfaceVariant, + Color? inverseSurface, + Color? onInverseSurface, + Color? inversePrimary, + Color? shadow, + Color? scrim, + Color? surfaceTint, + }) { + final Scheme scheme; + switch (brightness) { + case Brightness.light: + scheme = Scheme.light(seedColor.value); + case Brightness.dark: + scheme = Scheme.dark(seedColor.value); + } + return ColorScheme( + primary: primary ?? Color(scheme.primary), + onPrimary: onPrimary ?? Color(scheme.onPrimary), + primaryContainer: primaryContainer ?? Color(scheme.primaryContainer), + onPrimaryContainer: onPrimaryContainer ?? Color(scheme.onPrimaryContainer), + secondary: secondary ?? Color(scheme.secondary), + onSecondary: onSecondary ?? Color(scheme.onSecondary), + secondaryContainer: secondaryContainer ?? Color(scheme.secondaryContainer), + onSecondaryContainer: onSecondaryContainer ?? Color(scheme.onSecondaryContainer), + tertiary: tertiary ?? Color(scheme.tertiary), + onTertiary: onTertiary ?? Color(scheme.onTertiary), + tertiaryContainer: tertiaryContainer ?? Color(scheme.tertiaryContainer), + onTertiaryContainer: onTertiaryContainer ?? Color(scheme.onTertiaryContainer), + error: error ?? Color(scheme.error), + onError: onError ?? Color(scheme.onError), + errorContainer: errorContainer ?? Color(scheme.errorContainer), + onErrorContainer: onErrorContainer ?? Color(scheme.onErrorContainer), + outline: outline ?? Color(scheme.outline), + outlineVariant: outlineVariant ?? Color(scheme.outlineVariant), + background: background ?? Color(scheme.background), + onBackground: onBackground ?? Color(scheme.onBackground), + surface: surface ?? Color(scheme.surface), + onSurface: onSurface ?? Color(scheme.onSurface), + surfaceVariant: surfaceVariant ?? Color(scheme.surfaceVariant), + onSurfaceVariant: onSurfaceVariant ?? Color(scheme.onSurfaceVariant), + inverseSurface: inverseSurface ?? Color(scheme.inverseSurface), + onInverseSurface: onInverseSurface ?? Color(scheme.inverseOnSurface), + inversePrimary: inversePrimary ?? Color(scheme.inversePrimary), + shadow: shadow ?? Color(scheme.shadow), + scrim: scrim ?? Color(scheme.scrim), + surfaceTint: surfaceTint ?? Color(scheme.primary), + brightness: brightness, + ); + } + + /// Create a light ColorScheme based on a purple primary color that matches the + /// [baseline Material 2 color scheme](https://material.io/design/color/the-color-system.html#color-theme-creation). + /// + /// This constructor shouldn't be used to update the Material 3 color scheme. + /// + /// For Material 3, use [ColorScheme.fromSeed] to create a color scheme + /// from a single seed color based on the Material 3 color system. + /// + /// {@tool snippet} + /// This example demonstrates how to create a color scheme similar to [ColorScheme.light] + /// using the [ColorScheme.fromSeed] constructor: + /// + /// ```dart + /// colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xff6200ee)).copyWith( + /// primaryContainer: const Color(0xff6200ee), + /// onPrimaryContainer: Colors.white, + /// secondaryContainer: const Color(0xff03dac6), + /// onSecondaryContainer: Colors.black, + /// error: const Color(0xffb00020), + /// onError: Colors.white, + /// ), + /// ``` + /// {@end-tool} + const ColorScheme.light({ + this.brightness = Brightness.light, + this.primary = const Color(0xff6200ee), + this.onPrimary = Colors.white, + Color? primaryContainer, + Color? onPrimaryContainer, + this.secondary = const Color(0xff03dac6), + this.onSecondary = Colors.black, + Color? secondaryContainer, + Color? onSecondaryContainer, + Color? tertiary, + Color? onTertiary, + Color? tertiaryContainer, + Color? onTertiaryContainer, + this.error = const Color(0xffb00020), + this.onError = Colors.white, + Color? errorContainer, + Color? onErrorContainer, + this.background = Colors.white, + this.onBackground = Colors.black, + this.surface = Colors.white, + this.onSurface = Colors.black, + Color? surfaceVariant, + Color? onSurfaceVariant, + Color? outline, + Color? outlineVariant, + Color? shadow, + Color? scrim, + Color? inverseSurface, + Color? onInverseSurface, + Color? inversePrimary, + Color? surfaceTint, + }) : _primaryContainer = primaryContainer, + _onPrimaryContainer = onPrimaryContainer, + _secondaryContainer = secondaryContainer, + _onSecondaryContainer = onSecondaryContainer, + _tertiary = tertiary, + _onTertiary = onTertiary, + _tertiaryContainer = tertiaryContainer, + _onTertiaryContainer = onTertiaryContainer, + _errorContainer = errorContainer, + _onErrorContainer = onErrorContainer, + _surfaceVariant = surfaceVariant, + _onSurfaceVariant = onSurfaceVariant, + _outline = outline, + _outlineVariant = outlineVariant, + _shadow = shadow, + _scrim = scrim, + _inverseSurface = inverseSurface, + _onInverseSurface = onInverseSurface, + _inversePrimary = inversePrimary, + _surfaceTint = surfaceTint; + + /// Create the dark color scheme that matches the + /// [baseline Material 2 color scheme](https://material.io/design/color/dark-theme.html#ui-application). + /// + /// This constructor shouldn't be used to update the Material 3 color scheme. + /// + /// For Material 3, use [ColorScheme.fromSeed] to create a color scheme + /// from a single seed color based on the Material 3 color system. + /// Override the `brightness` property of [ColorScheme.fromSeed] to create a + /// dark color scheme. + /// + /// {@tool snippet} + /// This example demonstrates how to create a color scheme similar to [ColorScheme.dark] + /// using the [ColorScheme.fromSeed] constructor: + /// + /// ```dart + /// colorScheme: ColorScheme.fromSeed( + /// seedColor: const Color(0xffbb86fc), + /// brightness: Brightness.dark, + /// ).copyWith( + /// primaryContainer: const Color(0xffbb86fc), + /// onPrimaryContainer: Colors.black, + /// secondaryContainer: const Color(0xff03dac6), + /// onSecondaryContainer: Colors.black, + /// error: const Color(0xffcf6679), + /// onError: Colors.black, + /// ), + /// ``` + /// {@end-tool} + const ColorScheme.dark({ + this.brightness = Brightness.dark, + this.primary = const Color(0xffbb86fc), + this.onPrimary = Colors.black, + Color? primaryContainer, + Color? onPrimaryContainer, + this.secondary = const Color(0xff03dac6), + this.onSecondary = Colors.black, + Color? secondaryContainer, + Color? onSecondaryContainer, + Color? tertiary, + Color? onTertiary, + Color? tertiaryContainer, + Color? onTertiaryContainer, + this.error = const Color(0xffcf6679), + this.onError = Colors.black, + Color? errorContainer, + Color? onErrorContainer, + this.background = const Color(0xff121212), + this.onBackground = Colors.white, + this.surface = const Color(0xff121212), + this.onSurface = Colors.white, + Color? surfaceVariant, + Color? onSurfaceVariant, + Color? outline, + Color? outlineVariant, + Color? shadow, + Color? scrim, + Color? inverseSurface, + Color? onInverseSurface, + Color? inversePrimary, + Color? surfaceTint, + }) : _primaryContainer = primaryContainer, + _onPrimaryContainer = onPrimaryContainer, + _secondaryContainer = secondaryContainer, + _onSecondaryContainer = onSecondaryContainer, + _tertiary = tertiary, + _onTertiary = onTertiary, + _tertiaryContainer = tertiaryContainer, + _onTertiaryContainer = onTertiaryContainer, + _errorContainer = errorContainer, + _onErrorContainer = onErrorContainer, + _surfaceVariant = surfaceVariant, + _onSurfaceVariant = onSurfaceVariant, + _outline = outline, + _outlineVariant = outlineVariant, + _shadow = shadow, + _scrim = scrim, + _inverseSurface = inverseSurface, + _onInverseSurface = onInverseSurface, + _inversePrimary = inversePrimary, + _surfaceTint = surfaceTint; + + /// Create a high contrast ColorScheme based on a purple primary color that + /// matches the [baseline Material 2 color scheme](https://material.io/design/color/the-color-system.html#color-theme-creation). + /// + /// This constructor shouldn't be used to update the Material 3 color scheme. + /// + /// For Material 3, use [ColorScheme.fromSeed] to create a color scheme + /// from a single seed color based on the Material 3 color system. + /// + /// {@tool snippet} + /// This example demonstrates how to create a color scheme similar to [ColorScheme.highContrastLight] + /// using the [ColorScheme.fromSeed] constructor: + /// + /// ```dart + /// colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xff0000ba)).copyWith( + /// primaryContainer: const Color(0xff0000ba), + /// onPrimaryContainer: Colors.white, + /// secondaryContainer: const Color(0xff66fff9), + /// onSecondaryContainer: Colors.black, + /// error: const Color(0xff790000), + /// onError: Colors.white, + /// ), + /// ``` + /// {@end-tool} + const ColorScheme.highContrastLight({ + this.brightness = Brightness.light, + this.primary = const Color(0xff0000ba), + this.onPrimary = Colors.white, + Color? primaryContainer, + Color? onPrimaryContainer, + this.secondary = const Color(0xff66fff9), + this.onSecondary = Colors.black, + Color? secondaryContainer, + Color? onSecondaryContainer, + Color? tertiary, + Color? onTertiary, + Color? tertiaryContainer, + Color? onTertiaryContainer, + this.error = const Color(0xff790000), + this.onError = Colors.white, + Color? errorContainer, + Color? onErrorContainer, + this.background = Colors.white, + this.onBackground = Colors.black, + this.surface = Colors.white, + this.onSurface = Colors.black, + Color? surfaceVariant, + Color? onSurfaceVariant, + Color? outline, + Color? outlineVariant, + Color? shadow, + Color? scrim, + Color? inverseSurface, + Color? onInverseSurface, + Color? inversePrimary, + Color? surfaceTint, + }) : _primaryContainer = primaryContainer, + _onPrimaryContainer = onPrimaryContainer, + _secondaryContainer = secondaryContainer, + _onSecondaryContainer = onSecondaryContainer, + _tertiary = tertiary, + _onTertiary = onTertiary, + _tertiaryContainer = tertiaryContainer, + _onTertiaryContainer = onTertiaryContainer, + _errorContainer = errorContainer, + _onErrorContainer = onErrorContainer, + _surfaceVariant = surfaceVariant, + _onSurfaceVariant = onSurfaceVariant, + _outline = outline, + _outlineVariant = outlineVariant, + _shadow = shadow, + _scrim = scrim, + _inverseSurface = inverseSurface, + _onInverseSurface = onInverseSurface, + _inversePrimary = inversePrimary, + _surfaceTint = surfaceTint; + + /// Create a high contrast ColorScheme based on the dark + /// [baseline Material 2 color scheme](https://material.io/design/color/dark-theme.html#ui-application). + /// + /// This constructor shouldn't be used to update the Material 3 color scheme. + /// + /// For Material 3, use [ColorScheme.fromSeed] to create a color scheme + /// from a single seed color based on the Material 3 color system. + /// Override the `brightness` property of [ColorScheme.fromSeed] to create a + /// dark color scheme. + /// + /// {@tool snippet} + /// This example demonstrates how to create a color scheme similar to [ColorScheme.highContrastDark] + /// using the [ColorScheme.fromSeed] constructor: + /// + /// ```dart + /// colorScheme: ColorScheme.fromSeed( + /// seedColor: const Color(0xffefb7ff), + /// brightness: Brightness.dark, + /// ).copyWith( + /// primaryContainer: const Color(0xffefb7ff), + /// onPrimaryContainer: Colors.black, + /// secondaryContainer: const Color(0xff66fff9), + /// onSecondaryContainer: Colors.black, + /// error: const Color(0xff9b374d), + /// onError: Colors.white, + /// ), + /// ``` + /// {@end-tool} + const ColorScheme.highContrastDark({ + this.brightness = Brightness.dark, + this.primary = const Color(0xffefb7ff), + this.onPrimary = Colors.black, + Color? primaryContainer, + Color? onPrimaryContainer, + this.secondary = const Color(0xff66fff9), + this.onSecondary = Colors.black, + Color? secondaryContainer, + Color? onSecondaryContainer, + Color? tertiary, + Color? onTertiary, + Color? tertiaryContainer, + Color? onTertiaryContainer, + this.error = const Color(0xff9b374d), + this.onError = Colors.black, + Color? errorContainer, + Color? onErrorContainer, + this.background = const Color(0xff121212), + this.onBackground = Colors.white, + this.surface = const Color(0xff121212), + this.onSurface = Colors.white, + Color? surfaceVariant, + Color? onSurfaceVariant, + Color? outline, + Color? outlineVariant, + Color? shadow, + Color? scrim, + Color? inverseSurface, + Color? onInverseSurface, + Color? inversePrimary, + Color? surfaceTint, + }) : _primaryContainer = primaryContainer, + _onPrimaryContainer = onPrimaryContainer, + _secondaryContainer = secondaryContainer, + _onSecondaryContainer = onSecondaryContainer, + _tertiary = tertiary, + _onTertiary = onTertiary, + _tertiaryContainer = tertiaryContainer, + _onTertiaryContainer = onTertiaryContainer, + _errorContainer = errorContainer, + _onErrorContainer = onErrorContainer, + _surfaceVariant = surfaceVariant, + _onSurfaceVariant = onSurfaceVariant, + _outline = outline, + _outlineVariant = outlineVariant, + _shadow = shadow, + _scrim = scrim, + _inverseSurface = inverseSurface, + _onInverseSurface = onInverseSurface, + _inversePrimary = inversePrimary, + _surfaceTint = surfaceTint; + + /// Creates a color scheme from a [MaterialColor] swatch. + /// + /// In Material 3, this constructor is ignored by [ThemeData] when creating + /// its default color scheme. Instead, [ThemeData] uses [ColorScheme.fromSeed] + /// to create its default color scheme. This constructor shouldn't be used + /// to update the Material 3 color scheme. It will be phased out gradually; + /// see https://github.com/flutter/flutter/issues/120064 for more details. + /// + /// If [ThemeData.useMaterial3] is false, then this constructor is used by + /// [ThemeData] to create its default color scheme. + factory ColorScheme.fromSwatch({ + MaterialColor primarySwatch = Colors.blue, + Color? accentColor, + Color? cardColor, + Color? backgroundColor, + Color? errorColor, + Brightness brightness = Brightness.light, + }) { + final bool isDark = brightness == Brightness.dark; + final bool primaryIsDark = _brightnessFor(primarySwatch) == Brightness.dark; + final Color secondary = accentColor ?? (isDark ? Colors.tealAccent[200]! : primarySwatch); + final bool secondaryIsDark = _brightnessFor(secondary) == Brightness.dark; + + return ColorScheme( + primary: primarySwatch, + secondary: secondary, + surface: cardColor ?? (isDark ? Colors.grey[800]! : Colors.white), + background: backgroundColor ?? (isDark ? Colors.grey[700]! : primarySwatch[200]!), + error: errorColor ?? Colors.red[700]!, + onPrimary: primaryIsDark ? Colors.white : Colors.black, + onSecondary: secondaryIsDark ? Colors.white : Colors.black, + onSurface: isDark ? Colors.white : Colors.black, + onBackground: primaryIsDark ? Colors.white : Colors.black, + onError: isDark ? Colors.black : Colors.white, + brightness: brightness, + ); + } + + static Brightness _brightnessFor(Color color) => ThemeData.estimateBrightnessForColor(color); + + /// The overall brightness of this color scheme. + final Brightness brightness; + + /// The color displayed most frequently across your app’s screens and components. + final Color primary; + + /// A color that's clearly legible when drawn on [primary]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [primary] and [onPrimary] of at least 4.5:1 is recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + final Color onPrimary; + + final Color? _primaryContainer; + /// A color used for elements needing less emphasis than [primary]. + Color get primaryContainer => _primaryContainer ?? primary; + + final Color? _onPrimaryContainer; + /// A color that's clearly legible when drawn on [primaryContainer]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [primaryContainer] and [onPrimaryContainer] of at least 4.5:1 + /// is recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + Color get onPrimaryContainer => _onPrimaryContainer ?? onPrimary; + + /// An accent color used for less prominent components in the UI, such as + /// filter chips, while expanding the opportunity for color expression. + final Color secondary; + + /// A color that's clearly legible when drawn on [secondary]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [secondary] and [onSecondary] of at least 4.5:1 is recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + final Color onSecondary; + + final Color? _secondaryContainer; + /// A color used for elements needing less emphasis than [secondary]. + Color get secondaryContainer => _secondaryContainer ?? secondary; + + final Color? _onSecondaryContainer; + /// A color that's clearly legible when drawn on [secondaryContainer]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [secondaryContainer] and [onSecondaryContainer] of at least 4.5:1 is + /// recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + Color get onSecondaryContainer => _onSecondaryContainer ?? onSecondary; + + final Color? _tertiary; + /// A color used as a contrasting accent that can balance [primary] + /// and [secondary] colors or bring heightened attention to an element, + /// such as an input field. + Color get tertiary => _tertiary ?? secondary; + + final Color? _onTertiary; + /// A color that's clearly legible when drawn on [tertiary]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [tertiary] and [onTertiary] of at least 4.5:1 is recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + Color get onTertiary => _onTertiary ?? onSecondary; + + final Color? _tertiaryContainer; + /// A color used for elements needing less emphasis than [tertiary]. + Color get tertiaryContainer => _tertiaryContainer ?? tertiary; + + final Color? _onTertiaryContainer; + /// A color that's clearly legible when drawn on [tertiaryContainer]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [tertiaryContainer] and [onTertiaryContainer] of at least 4.5:1 is + /// recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + Color get onTertiaryContainer => _onTertiaryContainer ?? onTertiary; + + /// The color to use for input validation errors, e.g. for + /// [InputDecoration.errorText]. + final Color error; + + /// A color that's clearly legible when drawn on [error]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [error] and [onError] of at least 4.5:1 is recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + final Color onError; + + final Color? _errorContainer; + /// A color used for error elements needing less emphasis than [error]. + Color get errorContainer => _errorContainer ?? error; + + final Color? _onErrorContainer; + /// A color that's clearly legible when drawn on [errorContainer]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [errorContainer] and [onErrorContainer] of at least 4.5:1 is + /// recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + Color get onErrorContainer => _onErrorContainer ?? onError; + + /// A color that typically appears behind scrollable content. + final Color background; + + /// A color that's clearly legible when drawn on [background]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [background] and [onBackground] of at least 4.5:1 is recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + final Color onBackground; + + /// The background color for widgets like [Card]. + final Color surface; + + /// A color that's clearly legible when drawn on [surface]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [surface] and [onSurface] of at least 4.5:1 is recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + final Color onSurface; + + final Color? _surfaceVariant; + /// A color variant of [surface] that can be used for differentiation against + /// a component using [surface]. + Color get surfaceVariant => _surfaceVariant ?? surface; + + final Color? _onSurfaceVariant; + /// A color that's clearly legible when drawn on [surfaceVariant]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [surfaceVariant] and [onSurfaceVariant] of at least 4.5:1 is + /// recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + Color get onSurfaceVariant => _onSurfaceVariant ?? onSurface; + + final Color? _outline; + /// A utility color that creates boundaries and emphasis to improve usability. + Color get outline => _outline ?? onBackground; + + final Color? _outlineVariant; + /// A utility color that creates boundaries for decorative elements when a + /// 3:1 contrast isn’t required, such as for dividers or decorative elements. + Color get outlineVariant => _outlineVariant ?? onBackground; + + final Color? _shadow; + /// A color use to paint the drop shadows of elevated components. + Color get shadow => _shadow ?? const Color(0xff000000); + + final Color? _scrim; + /// A color use to paint the scrim around of modal components. + Color get scrim => _scrim ?? const Color(0xff000000); + + final Color? _inverseSurface; + /// A surface color used for displaying the reverse of what’s seen in the + /// surrounding UI, for example in a SnackBar to bring attention to + /// an alert. + Color get inverseSurface => _inverseSurface ?? onSurface; + + final Color? _onInverseSurface; + /// A color that's clearly legible when drawn on [inverseSurface]. + /// + /// To ensure that an app is accessible, a contrast ratio between + /// [inverseSurface] and [onInverseSurface] of at least 4.5:1 is + /// recommended. See + /// <https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html>. + Color get onInverseSurface => _onInverseSurface ?? surface; + + final Color? _inversePrimary; + /// An accent color used for displaying a highlight color on [inverseSurface] + /// backgrounds, like button text in a SnackBar. + Color get inversePrimary => _inversePrimary ?? onPrimary; + + final Color? _surfaceTint; + /// A color used as an overlay on a surface color to indicate a component's + /// elevation. + Color get surfaceTint => _surfaceTint ?? primary; + + /// Creates a copy of this color scheme with the given fields + /// replaced by the non-null parameter values. + ColorScheme copyWith({ + Brightness? brightness, + Color? primary, + Color? onPrimary, + Color? primaryContainer, + Color? onPrimaryContainer, + Color? secondary, + Color? onSecondary, + Color? secondaryContainer, + Color? onSecondaryContainer, + Color? tertiary, + Color? onTertiary, + Color? tertiaryContainer, + Color? onTertiaryContainer, + Color? error, + Color? onError, + Color? errorContainer, + Color? onErrorContainer, + Color? background, + Color? onBackground, + Color? surface, + Color? onSurface, + Color? surfaceVariant, + Color? onSurfaceVariant, + Color? outline, + Color? outlineVariant, + Color? shadow, + Color? scrim, + Color? inverseSurface, + Color? onInverseSurface, + Color? inversePrimary, + Color? surfaceTint, + }) { + return ColorScheme( + brightness: brightness ?? this.brightness, + primary : primary ?? this.primary, + onPrimary : onPrimary ?? this.onPrimary, + primaryContainer : primaryContainer ?? this.primaryContainer, + onPrimaryContainer : onPrimaryContainer ?? this.onPrimaryContainer, + secondary : secondary ?? this.secondary, + onSecondary : onSecondary ?? this.onSecondary, + secondaryContainer : secondaryContainer ?? this.secondaryContainer, + onSecondaryContainer : onSecondaryContainer ?? this.onSecondaryContainer, + tertiary : tertiary ?? this.tertiary, + onTertiary : onTertiary ?? this.onTertiary, + tertiaryContainer : tertiaryContainer ?? this.tertiaryContainer, + onTertiaryContainer : onTertiaryContainer ?? this.onTertiaryContainer, + error : error ?? this.error, + onError : onError ?? this.onError, + errorContainer : errorContainer ?? this.errorContainer, + onErrorContainer : onErrorContainer ?? this.onErrorContainer, + background : background ?? this.background, + onBackground : onBackground ?? this.onBackground, + surface : surface ?? this.surface, + onSurface : onSurface ?? this.onSurface, + surfaceVariant : surfaceVariant ?? this.surfaceVariant, + onSurfaceVariant : onSurfaceVariant ?? this.onSurfaceVariant, + outline : outline ?? this.outline, + outlineVariant : outlineVariant ?? this.outlineVariant, + shadow : shadow ?? this.shadow, + scrim : scrim ?? this.scrim, + inverseSurface : inverseSurface ?? this.inverseSurface, + onInverseSurface : onInverseSurface ?? this.onInverseSurface, + inversePrimary : inversePrimary ?? this.inversePrimary, + surfaceTint: surfaceTint ?? this.surfaceTint, + ); + } + + /// Linearly interpolate between two [ColorScheme] objects. + /// + /// {@macro dart.ui.shadow.lerp} + static ColorScheme lerp(ColorScheme a, ColorScheme b, double t) { + if (identical(a, b)) { + return a; + } + return ColorScheme( + brightness: t < 0.5 ? a.brightness : b.brightness, + primary: Color.lerp(a.primary, b.primary, t)!, + onPrimary: Color.lerp(a.onPrimary, b.onPrimary, t)!, + primaryContainer: Color.lerp(a.primaryContainer, b.primaryContainer, t), + onPrimaryContainer: Color.lerp(a.onPrimaryContainer, b.onPrimaryContainer, t), + secondary: Color.lerp(a.secondary, b.secondary, t)!, + onSecondary: Color.lerp(a.onSecondary, b.onSecondary, t)!, + secondaryContainer: Color.lerp(a.secondaryContainer, b.secondaryContainer, t), + onSecondaryContainer: Color.lerp(a.onSecondaryContainer, b.onSecondaryContainer, t), + tertiary: Color.lerp(a.tertiary, b.tertiary, t), + onTertiary: Color.lerp(a.onTertiary, b.onTertiary, t), + tertiaryContainer: Color.lerp(a.tertiaryContainer, b.tertiaryContainer, t), + onTertiaryContainer: Color.lerp(a.onTertiaryContainer, b.onTertiaryContainer, t), + error: Color.lerp(a.error, b.error, t)!, + onError: Color.lerp(a.onError, b.onError, t)!, + errorContainer: Color.lerp(a.errorContainer, b.errorContainer, t), + onErrorContainer: Color.lerp(a.onErrorContainer, b.onErrorContainer, t), + background: Color.lerp(a.background, b.background, t)!, + onBackground: Color.lerp(a.onBackground, b.onBackground, t)!, + surface: Color.lerp(a.surface, b.surface, t)!, + onSurface: Color.lerp(a.onSurface, b.onSurface, t)!, + surfaceVariant: Color.lerp(a.surfaceVariant, b.surfaceVariant, t), + onSurfaceVariant: Color.lerp(a.onSurfaceVariant, b.onSurfaceVariant, t), + outline: Color.lerp(a.outline, b.outline, t), + outlineVariant: Color.lerp(a.outlineVariant, b.outlineVariant, t), + shadow: Color.lerp(a.shadow, b.shadow, t), + scrim: Color.lerp(a.scrim, b.scrim, t), + inverseSurface: Color.lerp(a.inverseSurface, b.inverseSurface, t), + onInverseSurface: Color.lerp(a.onInverseSurface, b.onInverseSurface, t), + inversePrimary: Color.lerp(a.inversePrimary, b.inversePrimary, t), + surfaceTint: Color.lerp(a.surfaceTint, b.surfaceTint, t), + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ColorScheme + && other.brightness == brightness + && other.primary == primary + && other.onPrimary == onPrimary + && other.primaryContainer == primaryContainer + && other.onPrimaryContainer == onPrimaryContainer + && other.secondary == secondary + && other.onSecondary == onSecondary + && other.secondaryContainer == secondaryContainer + && other.onSecondaryContainer == onSecondaryContainer + && other.tertiary == tertiary + && other.onTertiary == onTertiary + && other.tertiaryContainer == tertiaryContainer + && other.onTertiaryContainer == onTertiaryContainer + && other.error == error + && other.onError == onError + && other.errorContainer == errorContainer + && other.onErrorContainer == onErrorContainer + && other.background == background + && other.onBackground == onBackground + && other.surface == surface + && other.onSurface == onSurface + && other.surfaceVariant == surfaceVariant + && other.onSurfaceVariant == onSurfaceVariant + && other.outline == outline + && other.outlineVariant == outlineVariant + && other.shadow == shadow + && other.scrim == scrim + && other.inverseSurface == inverseSurface + && other.onInverseSurface == onInverseSurface + && other.inversePrimary == inversePrimary + && other.surfaceTint == surfaceTint; + } + + @override + int get hashCode => Object.hash( + brightness, + primary, + onPrimary, + primaryContainer, + onPrimaryContainer, + secondary, + onSecondary, + secondaryContainer, + onSecondaryContainer, + tertiary, + onTertiary, + tertiaryContainer, + onTertiaryContainer, + error, + onError, + errorContainer, + onErrorContainer, + background, + onBackground, + Object.hash( + surface, + onSurface, + surfaceVariant, + onSurfaceVariant, + outline, + outlineVariant, + shadow, + scrim, + inverseSurface, + onInverseSurface, + inversePrimary, + surfaceTint, + ), + ); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + const ColorScheme defaultScheme = ColorScheme.light(); + properties.add(DiagnosticsProperty<Brightness>('brightness', brightness, defaultValue: defaultScheme.brightness)); + properties.add(ColorProperty('primary', primary, defaultValue: defaultScheme.primary)); + properties.add(ColorProperty('onPrimary', onPrimary, defaultValue: defaultScheme.onPrimary)); + properties.add(ColorProperty('primaryContainer', primaryContainer, defaultValue: defaultScheme.primaryContainer)); + properties.add(ColorProperty('onPrimaryContainer', onPrimaryContainer, defaultValue: defaultScheme.onPrimaryContainer)); + properties.add(ColorProperty('secondary', secondary, defaultValue: defaultScheme.secondary)); + properties.add(ColorProperty('onSecondary', onSecondary, defaultValue: defaultScheme.onSecondary)); + properties.add(ColorProperty('secondaryContainer', secondaryContainer, defaultValue: defaultScheme.secondaryContainer)); + properties.add(ColorProperty('onSecondaryContainer', onSecondaryContainer, defaultValue: defaultScheme.onSecondaryContainer)); + properties.add(ColorProperty('tertiary', tertiary, defaultValue: defaultScheme.tertiary)); + properties.add(ColorProperty('onTertiary', onTertiary, defaultValue: defaultScheme.onTertiary)); + properties.add(ColorProperty('tertiaryContainer', tertiaryContainer, defaultValue: defaultScheme.tertiaryContainer)); + properties.add(ColorProperty('onTertiaryContainer', onTertiaryContainer, defaultValue: defaultScheme.onTertiaryContainer)); + properties.add(ColorProperty('error', error, defaultValue: defaultScheme.error)); + properties.add(ColorProperty('onError', onError, defaultValue: defaultScheme.onError)); + properties.add(ColorProperty('errorContainer', errorContainer, defaultValue: defaultScheme.errorContainer)); + properties.add(ColorProperty('onErrorContainer', onErrorContainer, defaultValue: defaultScheme.onErrorContainer)); + properties.add(ColorProperty('background', background, defaultValue: defaultScheme.background)); + properties.add(ColorProperty('onBackground', onBackground, defaultValue: defaultScheme.onBackground)); + properties.add(ColorProperty('surface', surface, defaultValue: defaultScheme.surface)); + properties.add(ColorProperty('onSurface', onSurface, defaultValue: defaultScheme.onSurface)); + properties.add(ColorProperty('surfaceVariant', surfaceVariant, defaultValue: defaultScheme.surfaceVariant)); + properties.add(ColorProperty('onSurfaceVariant', onSurfaceVariant, defaultValue: defaultScheme.onSurfaceVariant)); + properties.add(ColorProperty('outline', outline, defaultValue: defaultScheme.outline)); + properties.add(ColorProperty('outlineVariant', outlineVariant, defaultValue: defaultScheme.outlineVariant)); + properties.add(ColorProperty('shadow', shadow, defaultValue: defaultScheme.shadow)); + properties.add(ColorProperty('scrim', scrim, defaultValue: defaultScheme.scrim)); + properties.add(ColorProperty('inverseSurface', inverseSurface, defaultValue: defaultScheme.inverseSurface)); + properties.add(ColorProperty('onInverseSurface', onInverseSurface, defaultValue: defaultScheme.onInverseSurface)); + properties.add(ColorProperty('inversePrimary', inversePrimary, defaultValue: defaultScheme.inversePrimary)); + properties.add(ColorProperty('surfaceTint', surfaceTint, defaultValue: defaultScheme.surfaceTint)); + } + + /// Generate a [ColorScheme] derived from the given `imageProvider`. + /// + /// Material Color Utilities extracts the dominant color from the + /// supplied [ImageProvider]. Using this color, a [ColorScheme] is generated + /// with harmonious colors that meet contrast requirements for accessibility. + /// + /// If any of the optional color parameters are non-null, they will be + /// used in place of the generated colors for that field in the resulting + /// [ColorScheme]. This allows apps to override specific colors for their + /// needs. + /// + /// Given the nature of the algorithm, the most dominant color of the + /// `imageProvider` may not wind up as one of the [ColorScheme] colors. + /// + /// The provided image will be scaled down to a maximum size of 112x112 pixels + /// during color extraction. + /// + /// {@tool dartpad} + /// This sample shows how to use [ColorScheme.fromImageProvider] to create + /// content-based dynamic color schemes. + /// + /// ** See code in examples/api/lib/material/color_scheme/dynamic_content_color.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [M3 Guidelines: Dynamic color from content](https://m3.material.io/styles/color/dynamic-color/user-generated-color#8af550b9-a19e-4e9f-bb0a-7f611fed5d0f) + /// * <https://pub.dev/packages/dynamic_color>, a package to create + /// [ColorScheme]s based on a platform's implementation of dynamic color. + /// * <https://m3.material.io/styles/color/the-color-system/color-roles>, the + /// Material 3 Color system specification. + /// * <https://pub.dev/packages/material_color_utilities>, the package + /// used to algorithmically determine the dominant color and to generate + /// the [ColorScheme]. + static Future<ColorScheme> fromImageProvider({ + required ImageProvider provider, + Brightness brightness = Brightness.light, + Color? primary, + Color? onPrimary, + Color? primaryContainer, + Color? onPrimaryContainer, + Color? secondary, + Color? onSecondary, + Color? secondaryContainer, + Color? onSecondaryContainer, + Color? tertiary, + Color? onTertiary, + Color? tertiaryContainer, + Color? onTertiaryContainer, + Color? error, + Color? onError, + Color? errorContainer, + Color? onErrorContainer, + Color? outline, + Color? outlineVariant, + Color? background, + Color? onBackground, + Color? surface, + Color? onSurface, + Color? surfaceVariant, + Color? onSurfaceVariant, + Color? inverseSurface, + Color? onInverseSurface, + Color? inversePrimary, + Color? shadow, + Color? scrim, + Color? surfaceTint, + }) async { + // Extract dominant colors from image. + final QuantizerResult quantizerResult = + await _extractColorsFromImageProvider(provider); + final Map<int, int> colorToCount = quantizerResult.colorToCount.map( + (int key, int value) => MapEntry<int, int>(_getArgbFromAbgr(key), value), + ); + + // Score colors for color scheme suitability. + final List<int> scoredResults = Score.score(colorToCount, desired: 1); + final ui.Color baseColor = Color(scoredResults.first); + + final Scheme scheme; + switch (brightness) { + case Brightness.light: + scheme = Scheme.light(baseColor.value); + case Brightness.dark: + scheme = Scheme.dark(baseColor.value); + } + + return ColorScheme(primary: primary ?? Color(scheme.primary), + onPrimary: onPrimary ?? Color(scheme.onPrimary), + primaryContainer: primaryContainer ?? Color(scheme.primaryContainer), + onPrimaryContainer: onPrimaryContainer ?? Color(scheme.onPrimaryContainer), + secondary: secondary ?? Color(scheme.secondary), + onSecondary: onSecondary ?? Color(scheme.onSecondary), + secondaryContainer: secondaryContainer ?? Color(scheme.secondaryContainer), + onSecondaryContainer: onSecondaryContainer ?? Color(scheme.onSecondaryContainer), + tertiary: tertiary ?? Color(scheme.tertiary), + onTertiary: onTertiary ?? Color(scheme.onTertiary), + tertiaryContainer: tertiaryContainer ?? Color(scheme.tertiaryContainer), + onTertiaryContainer: onTertiaryContainer ?? Color(scheme.onTertiaryContainer), + error: error ?? Color(scheme.error), + onError: onError ?? Color(scheme.onError), + errorContainer: errorContainer ?? Color(scheme.errorContainer), + onErrorContainer: onErrorContainer ?? Color(scheme.onErrorContainer), + outline: outline ?? Color(scheme.outline), + outlineVariant: outlineVariant ?? Color(scheme.outlineVariant), + background: background ?? Color(scheme.background), + onBackground: onBackground ?? Color(scheme.onBackground), + surface: surface ?? Color(scheme.surface), + onSurface: onSurface ?? Color(scheme.onSurface), + surfaceVariant: surfaceVariant ?? Color(scheme.surfaceVariant), + onSurfaceVariant: onSurfaceVariant ?? Color(scheme.onSurfaceVariant), + inverseSurface: inverseSurface ?? Color(scheme.inverseSurface), + onInverseSurface: onInverseSurface ?? Color(scheme.inverseOnSurface), + inversePrimary: inversePrimary ?? Color(scheme.inversePrimary), + shadow: shadow ?? Color(scheme.shadow), + scrim: scrim ?? Color(scheme.scrim), + surfaceTint: surfaceTint ?? Color(scheme.primary), + brightness: brightness, + ); + } + + // ColorScheme.fromImageProvider() utilities. + + // Extracts bytes from an [ImageProvider] and returns a [QuantizerResult] + // containing the most dominant colors. + static Future<QuantizerResult> _extractColorsFromImageProvider(ImageProvider imageProvider) async { + final ui.Image scaledImage = await _imageProviderToScaled(imageProvider); + final ByteData? imageBytes = await scaledImage.toByteData(); + + final QuantizerResult quantizerResult = await QuantizerCelebi().quantize( + imageBytes!.buffer.asUint32List(), + 128, + returnInputPixelToClusterPixel: true, + ); + return quantizerResult; + } + + // Scale image size down to reduce computation time of color extraction. + static Future<ui.Image> _imageProviderToScaled(ImageProvider imageProvider) async { + const double maxDimension = 112.0; + final ImageStream stream = imageProvider.resolve( + const ImageConfiguration(size: Size(maxDimension, maxDimension))); + final Completer<ui.Image> imageCompleter = Completer<ui.Image>(); + late ImageStreamListener listener; + late ui.Image scaledImage; + Timer? loadFailureTimeout; + + listener = ImageStreamListener((ImageInfo info, bool sync) async { + loadFailureTimeout?.cancel(); + stream.removeListener(listener); + final ui.Image image = info.image; + final int width = image.width; + final int height = image.height; + double paintWidth = width.toDouble(); + double paintHeight = height.toDouble(); + assert(width > 0 && height > 0); + + final bool rescale = width > maxDimension || height > maxDimension; + if (rescale) { + paintWidth = (width > height) ? maxDimension : (maxDimension / height) * width; + paintHeight = (height > width) ? maxDimension : (maxDimension / width) * height; + } + final ui.PictureRecorder pictureRecorder = ui.PictureRecorder(); + final Canvas canvas = Canvas(pictureRecorder); + paintImage( + canvas: canvas, + rect: Rect.fromLTRB(0, 0, paintWidth, paintHeight), + image: image, + filterQuality: FilterQuality.none); + + final ui.Picture picture = pictureRecorder.endRecording(); + scaledImage = await picture.toImage(paintWidth.toInt(), paintHeight.toInt()); + imageCompleter.complete(info.image); + }, onError: (Object exception, StackTrace? stackTrace) { + stream.removeListener(listener); + throw Exception('Failed to render image: $exception'); + }); + + loadFailureTimeout = Timer(const Duration(seconds: 5), () { + stream.removeListener(listener); + imageCompleter.completeError( + TimeoutException('Timeout occurred trying to load image')); + }); + + stream.addListener(listener); + await imageCompleter.future; + return scaledImage; + } + + // Converts AABBGGRR color int to AARRGGBB format. + static int _getArgbFromAbgr(int abgr) { + const int exceptRMask = 0xFF00FFFF; + const int onlyRMask = ~exceptRMask; + const int exceptBMask = 0xFFFFFF00; + const int onlyBMask = ~exceptBMask; + final int r = (abgr & onlyRMask) >> 16; + final int b = abgr & onlyBMask; + return (abgr & exceptRMask & exceptBMask) | (b << 16) | r; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/colors.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/colors.dart new file mode 100644 index 0000000000000000000000000000000000000000..2fadbd844ed667f3d02124368fc8c5de5431e1d5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/colors.dart @@ -0,0 +1,2005 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/painting.dart'; + +/// Defines a single color as well a color swatch with ten shades of the color. +/// +/// The color's shades are referred to by index. The greater the index, the +/// darker the color. There are 10 valid indices: 50, 100, 200, ..., 900. +/// The value of this color should the same the value of index 500 and [shade500]. +/// +/// ## Updating to [ColorScheme] +/// +/// The [ColorScheme] is preferred for +/// representing colors in applications that are configured +/// for Material 3 (see [ThemeData.useMaterial3]). +/// For more information on colors in Material 3 see +/// the spec at <https://m3.material.io/styles/color/the-color-system>. +/// +///{@template flutter.material.colors.colorRoles} +/// In Material 3, colors are represented using color roles and +/// corresponding tokens. Each property in the [ColorScheme] class +/// represents one color role as defined in the spec above. +/// {@endtemplate} +/// +/// ### Material 3 Colors in Flutter +/// +///{@template flutter.material.colors.settingColors} +/// Flutter's Material widgets can be assigned colors at the widget level +/// using widget properties, +/// or at the app level using theme classes. +/// +/// For example, you can set the background of the [AppBar] by +/// setting the [AppBar.backgroundColor] to a specific [Color] value. +/// +/// To globally set the AppBar background color for your app, you +/// can set the [ThemeData.appBarTheme] property for your [MaterialApp] +/// using the [ThemeData] class. You can also override +/// the default appearance of all the [AppBar]s in a widget subtree by +/// placing the [AppBarTheme] at the root of the subtree. +/// +/// Alternatively, you can set the [ThemeData.colorScheme] property +/// to a custom [ColorScheme]. This creates a unified [ColorScheme] to be +/// used across the app. The [AppBar.backgroundColor] uses the +/// [ColorScheme.surface] by default. +///{@endtemplate} +/// +/// ### Migrating from [MaterialColor] to [ColorScheme] +/// +/// In most cases, there are new properties in Flutter widgets that +/// accept a [ColorScheme] instead of a [MaterialColor]. +/// +/// For example, you may have previously constructed a [ThemeData] +/// using a primarySwatch: +/// +/// ```dart +/// ThemeData( +/// primarySwatch: Colors.amber, +/// ) +/// ``` +/// +/// In Material 3, you can use the [ColorScheme] class to +/// construct a [ThemeData] with the same color palette +/// by using the [ColorScheme.fromSeed] constructor: +/// +/// ```dart +/// ThemeData( +/// colorScheme: ColorScheme.fromSeed(seedColor: Colors.amber), +/// ) +/// ``` +/// +/// The [ColorScheme.fromSeed] constructor +/// will generate a set of tonal palettes, +/// which are used to create the color scheme. +/// +/// Alternatively you can use the [ColorScheme.fromSwatch] constructor: +/// +/// ```dart +/// ThemeData( +/// colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.amber), +/// ) +/// ``` +/// +/// The [ColorScheme.fromSwatch] constructor will +/// create the color scheme directly from the specific +/// color values used in the [MaterialColor]. +/// +/// +/// See also: +/// +/// * [Colors], which defines all of the standard material colors. +class MaterialColor extends ColorSwatch<int> { + /// Creates a color swatch with a variety of shades. + /// + /// The `primary` argument should be the 32 bit ARGB value of one of the + /// values in the swatch, as would be passed to the [Color.new] constructor + /// for that same color, and as is exposed by [value]. (This is distinct from + /// the specific index of the color in the swatch.) + const MaterialColor(super.primary, super.swatch); + + /// The lightest shade. + Color get shade50 => this[50]!; + + /// The second lightest shade. + Color get shade100 => this[100]!; + + /// The third lightest shade. + Color get shade200 => this[200]!; + + /// The fourth lightest shade. + Color get shade300 => this[300]!; + + /// The fifth lightest shade. + Color get shade400 => this[400]!; + + /// The default shade. + Color get shade500 => this[500]!; + + /// The fourth darkest shade. + Color get shade600 => this[600]!; + + /// The third darkest shade. + Color get shade700 => this[700]!; + + /// The second darkest shade. + Color get shade800 => this[800]!; + + /// The darkest shade. + Color get shade900 => this[900]!; +} + +/// Defines a single accent color as well a swatch of four shades of the +/// accent color. +/// +/// The color's shades are referred to by index, the colors with smaller +/// indices are lighter, larger indices are darker. There are four valid +/// indices: 100, 200, 400, and 700. The value of this color should be the +/// same as the value of index 200 and [shade200]. +/// +/// See also: +/// +/// * [Colors], which defines all of the standard material colors. +/// * <https://material.io/go/design-theming#color-color-schemes> +class MaterialAccentColor extends ColorSwatch<int> { + /// Creates a color swatch with a variety of shades appropriate for accent + /// colors. + const MaterialAccentColor(super.primary, super.swatch); + + /// The lightest shade. + Color get shade100 => this[100]!; + + /// The default shade. + Color get shade200 => this[200]!; + + /// The second darkest shade. + Color get shade400 => this[400]!; + + /// The darkest shade. + Color get shade700 => this[700]!; +} + +/// [Color] and [ColorSwatch] constants which represent Material design's +/// [color palette](https://material.io/design/color/). +/// +/// Instead of using an absolute color from these palettes, consider using +/// [Theme.of] to obtain the local [ThemeData.colorScheme], which defines +/// the colors that most of the Material components use by default. +/// +/// +/// Most swatches have colors from 100 to 900 in increments of one hundred, plus +/// the color 50. The smaller the number, the more pale the color. The greater +/// the number, the darker the color. The accent swatches (e.g. [redAccent]) only +/// have the values 100, 200, 400, and 700. +/// +/// In addition, a series of blacks and whites with common opacities are +/// available. For example, [black54] is a pure black with 54% opacity. +/// +/// {@tool snippet} +/// +/// To select a specific color from one of the swatches, index into the swatch +/// using an integer for the specific color desired, as follows: +/// +/// ```dart +/// Color selection = Colors.green[400]!; // Selects a mid-range green. +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// Each [ColorSwatch] constant is a color and can used directly. For example: +/// +/// ```dart +/// Container( +/// color: Colors.blue, // same as Colors.blue[500] or Colors.blue.shade500 +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Color palettes +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pink.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pinkAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.red.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.redAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrange.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrangeAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orange.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orangeAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amber.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amberAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellow.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellowAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lime.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.limeAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreen.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreenAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.green.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.greenAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.teal.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.tealAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyan.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyanAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlue.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlueAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blue.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigo.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigoAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purple.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purpleAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurple.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurpleAccent.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueGrey.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.brown.png) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.grey.png) +/// +/// ## Blacks and whites +/// +/// These colors are identified by their transparency. The low transparency +/// levels (e.g. [Colors.white12] and [Colors.white10]) are very hard to see and +/// should be avoided in general. They are intended for very subtle effects. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blacks.png) +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.whites.png) +/// +/// The [Colors.transparent] color isn't shown here because it is entirely +/// invisible! +/// +/// See also: +/// +/// * Cookbook: [Use themes to share colors and font styles](https://flutter.dev/docs/cookbook/design/themes) +abstract final class Colors { + /// Completely invisible. + static const Color transparent = Color(0x00000000); + + /// Completely opaque black. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blacks.png) + /// + /// See also: + /// + /// * [black87], [black54], [black45], [black38], [black26], [black12], which + /// are variants on this color but with different opacities. + /// * [white], a solid white color. + /// * [transparent], a fully-transparent color. + static const Color black = Color(0xFF000000); + + /// Black with 87% opacity. + /// + /// This is a good contrasting color for text in light themes. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blacks.png) + /// + /// See also: + /// + /// * [Typography.black], which uses this color for its text styles. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + /// * [black], [black54], [black45], [black38], [black26], [black12], which + /// are variants on this color but with different opacities. + static const Color black87 = Color(0xDD000000); + + /// Black with 54% opacity. + /// + /// This is a color commonly used for headings in light themes. It's also used + /// as the mask color behind dialogs. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blacks.png) + /// + /// See also: + /// + /// * [Typography.black], which uses this color for its text styles. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + /// * [black], [black87], [black45], [black38], [black26], [black12], which + /// are variants on this color but with different opacities. + static const Color black54 = Color(0x8A000000); + + /// Black with 45% opacity. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blacks.png) + /// + /// See also: + /// + /// * [black], [black87], [black54], [black38], [black26], [black12], which + /// are variants on this color but with different opacities. + static const Color black45 = Color(0x73000000); + + /// Black with 38% opacity. + /// + /// For light themes, i.e. when the Theme's [ThemeData.brightness] is + /// [Brightness.light], this color is used for disabled icons and for + /// placeholder text in [DataTable]. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blacks.png) + /// + /// See also: + /// + /// * [black], [black87], [black54], [black45], [black26], [black12], which + /// are variants on this color but with different opacities. + static const Color black38 = Color(0x61000000); + + /// Black with 26% opacity. + /// + /// Used for disabled radio buttons and the text of disabled flat buttons in light themes. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blacks.png) + /// + /// See also: + /// + /// * [ThemeData.disabledColor], which uses this color by default in light themes. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + /// * [black], [black87], [black54], [black45], [black38], [black12], which + /// are variants on this color but with different opacities. + static const Color black26 = Color(0x42000000); + + /// Black with 12% opacity. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blacks.png) + /// + /// Used for the background of disabled raised buttons in light themes. + /// + /// See also: + /// + /// * [black], [black87], [black54], [black45], [black38], [black26], which + /// are variants on this color but with different opacities. + static const Color black12 = Color(0x1F000000); + + /// Completely opaque white. + /// + /// This is a good contrasting color for the [ThemeData.primaryColor] in the + /// dark theme. See [ThemeData.brightness]. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.whites.png) + /// + /// See also: + /// + /// * [Typography.white], which uses this color for its text styles. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + /// * [white70], [white60], [white54], [white38], [white30], [white12], + /// [white10], which are variants on this color but with different + /// opacities. + /// * [black], a solid black color. + /// * [transparent], a fully-transparent color. + static const Color white = Color(0xFFFFFFFF); + + /// White with 70% opacity. + /// + /// This is a color commonly used for headings in dark themes. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.whites.png) + /// + /// See also: + /// + /// * [Typography.white], which uses this color for its text styles. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + /// * [white], [white60], [white54], [white38], [white30], [white12], + /// [white10], which are variants on this color but with different + /// opacities. + static const Color white70 = Color(0xB3FFFFFF); + + /// White with 60% opacity. + /// + /// Used for medium-emphasis text and hint text when [ThemeData.brightness] is + /// set to [Brightness.dark]. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.whites.png) + /// + /// See also: + /// + /// * [ExpandIcon], which uses this color for dark themes. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + /// * [white], [white54], [white30], [white38], [white12], [white10], which + /// are variants on this color but with different opacities. + static const Color white60 = Color(0x99FFFFFF); + + /// White with 54% opacity. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.whites.png) + /// + /// See also: + /// + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + /// * [white], [white60], [white38], [white30], [white12], [white10], which + /// are variants on this color but with different opacities. + static const Color white54 = Color(0x8AFFFFFF); + + /// White with 38% opacity. + /// + /// Used for disabled radio buttons and the text of disabled flat buttons in dark themes. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.whites.png) + /// + /// See also: + /// + /// * [ThemeData.disabledColor], which uses this color by default in dark themes. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + /// * [white], [white60], [white54], [white70], [white30], [white12], + /// [white10], which are variants on this color but with different + /// opacities. + static const Color white38 = Color(0x62FFFFFF); + + /// White with 30% opacity. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.whites.png) + /// + /// See also: + /// + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + /// * [white], [white60], [white54], [white70], [white38], [white12], + /// [white10], which are variants on this color but with different + /// opacities. + static const Color white30 = Color(0x4DFFFFFF); + + /// White with 24% opacity. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.whites.png) + /// + /// Used for the splash color for filled buttons. + /// + /// See also: + /// + /// * [white], [white60], [white54], [white70], [white38], [white30], + /// [white10], which are variants on this color + /// but with different opacities. + static const Color white24 = Color(0x3DFFFFFF); + + /// White with 12% opacity. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.whites.png) + /// + /// Used for the background of disabled raised buttons in dark themes. + /// + /// See also: + /// + /// * [white], [white60], [white54], [white70], [white38], [white30], + /// [white10], which are variants on this color but with different + /// opacities. + static const Color white12 = Color(0x1FFFFFFF); + + /// White with 10% opacity. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.whites.png) + /// + /// See also: + /// + /// * [white], [white60], [white54], [white70], [white38], [white30], + /// [white12], which are variants on this color + /// but with different opacities. + /// * [transparent], a fully-transparent color, not far from this one. + static const Color white10 = Color(0x1AFFFFFF); + + /// The red primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.red.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.redAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrangeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pink.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pinkAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.red[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [redAccent], the corresponding accent colors. + /// * [deepOrange] and [pink], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor red = MaterialColor( + _redPrimaryValue, + <int, Color>{ + 50: Color(0xFFFFEBEE), + 100: Color(0xFFFFCDD2), + 200: Color(0xFFEF9A9A), + 300: Color(0xFFE57373), + 400: Color(0xFFEF5350), + 500: Color(_redPrimaryValue), + 600: Color(0xFFE53935), + 700: Color(0xFFD32F2F), + 800: Color(0xFFC62828), + 900: Color(0xFFB71C1C), + }, + ); + static const int _redPrimaryValue = 0xFFF44336; + + /// The red accent swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.red.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.redAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrangeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pink.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pinkAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.redAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [red], the corresponding primary colors. + /// * [deepOrangeAccent] and [pinkAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor redAccent = MaterialAccentColor( + _redAccentValue, + <int, Color>{ + 100: Color(0xFFFF8A80), + 200: Color(_redAccentValue), + 400: Color(0xFFFF1744), + 700: Color(0xFFD50000), + }, + ); + static const int _redAccentValue = 0xFFFF5252; + + /// The pink primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pink.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pinkAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.red.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.redAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purpleAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.pink[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [pinkAccent], the corresponding accent colors. + /// * [red] and [purple], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor pink = MaterialColor( + _pinkPrimaryValue, + <int, Color>{ + 50: Color(0xFFFCE4EC), + 100: Color(0xFFF8BBD0), + 200: Color(0xFFF48FB1), + 300: Color(0xFFF06292), + 400: Color(0xFFEC407A), + 500: Color(_pinkPrimaryValue), + 600: Color(0xFFD81B60), + 700: Color(0xFFC2185B), + 800: Color(0xFFAD1457), + 900: Color(0xFF880E4F), + }, + ); + static const int _pinkPrimaryValue = 0xFFE91E63; + + /// The pink accent color swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pink.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pinkAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.red.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.redAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purpleAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.pinkAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [pink], the corresponding primary colors. + /// * [redAccent] and [purpleAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor pinkAccent = MaterialAccentColor( + _pinkAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFFF80AB), + 200: Color(_pinkAccentPrimaryValue), + 400: Color(0xFFF50057), + 700: Color(0xFFC51162), + }, + ); + static const int _pinkAccentPrimaryValue = 0xFFFF4081; + + /// The purple primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purpleAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurpleAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pink.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pinkAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.purple[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [purpleAccent], the corresponding accent colors. + /// * [deepPurple] and [pink], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor purple = MaterialColor( + _purplePrimaryValue, + <int, Color>{ + 50: Color(0xFFF3E5F5), + 100: Color(0xFFE1BEE7), + 200: Color(0xFFCE93D8), + 300: Color(0xFFBA68C8), + 400: Color(0xFFAB47BC), + 500: Color(_purplePrimaryValue), + 600: Color(0xFF8E24AA), + 700: Color(0xFF7B1FA2), + 800: Color(0xFF6A1B9A), + 900: Color(0xFF4A148C), + }, + ); + static const int _purplePrimaryValue = 0xFF9C27B0; + + /// The purple accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purpleAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurpleAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pink.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.pinkAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.purpleAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [purple], the corresponding primary colors. + /// * [deepPurpleAccent] and [pinkAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor purpleAccent = MaterialAccentColor( + _purpleAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFEA80FC), + 200: Color(_purpleAccentPrimaryValue), + 400: Color(0xFFD500F9), + 700: Color(0xFFAA00FF), + }, + ); + static const int _purpleAccentPrimaryValue = 0xFFE040FB; + + /// The deep purple primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurpleAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purpleAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigo.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigoAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.deepPurple[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [deepPurpleAccent], the corresponding accent colors. + /// * [purple] and [indigo], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor deepPurple = MaterialColor( + _deepPurplePrimaryValue, + <int, Color>{ + 50: Color(0xFFEDE7F6), + 100: Color(0xFFD1C4E9), + 200: Color(0xFFB39DDB), + 300: Color(0xFF9575CD), + 400: Color(0xFF7E57C2), + 500: Color(_deepPurplePrimaryValue), + 600: Color(0xFF5E35B1), + 700: Color(0xFF512DA8), + 800: Color(0xFF4527A0), + 900: Color(0xFF311B92), + }, + ); + static const int _deepPurplePrimaryValue = 0xFF673AB7; + + /// The deep purple accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurpleAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.purpleAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigo.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigoAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.deepPurpleAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [deepPurple], the corresponding primary colors. + /// * [purpleAccent] and [indigoAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor deepPurpleAccent = MaterialAccentColor( + _deepPurpleAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFB388FF), + 200: Color(_deepPurpleAccentPrimaryValue), + 400: Color(0xFF651FFF), + 700: Color(0xFF6200EA), + }, + ); + static const int _deepPurpleAccentPrimaryValue = 0xFF7C4DFF; + + /// The indigo primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigo.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigoAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurpleAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.indigo[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [indigoAccent], the corresponding accent colors. + /// * [blue] and [deepPurple], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor indigo = MaterialColor( + _indigoPrimaryValue, + <int, Color>{ + 50: Color(0xFFE8EAF6), + 100: Color(0xFFC5CAE9), + 200: Color(0xFF9FA8DA), + 300: Color(0xFF7986CB), + 400: Color(0xFF5C6BC0), + 500: Color(_indigoPrimaryValue), + 600: Color(0xFF3949AB), + 700: Color(0xFF303F9F), + 800: Color(0xFF283593), + 900: Color(0xFF1A237E), + }, + ); + static const int _indigoPrimaryValue = 0xFF3F51B5; + + /// The indigo accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigo.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigoAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurple.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepPurpleAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.indigoAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [indigo], the corresponding primary colors. + /// * [blueAccent] and [deepPurpleAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor indigoAccent = MaterialAccentColor( + _indigoAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFF8C9EFF), + 200: Color(_indigoAccentPrimaryValue), + 400: Color(0xFF3D5AFE), + 700: Color(0xFF304FFE), + }, + ); + static const int _indigoAccentPrimaryValue = 0xFF536DFE; + + /// The blue primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigo.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigoAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueGrey.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.blue[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [blueAccent], the corresponding accent colors. + /// * [indigo], [lightBlue], and [blueGrey], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor blue = MaterialColor( + _bluePrimaryValue, + <int, Color>{ + 50: Color(0xFFE3F2FD), + 100: Color(0xFFBBDEFB), + 200: Color(0xFF90CAF9), + 300: Color(0xFF64B5F6), + 400: Color(0xFF42A5F5), + 500: Color(_bluePrimaryValue), + 600: Color(0xFF1E88E5), + 700: Color(0xFF1976D2), + 800: Color(0xFF1565C0), + 900: Color(0xFF0D47A1), + }, + ); + static const int _bluePrimaryValue = 0xFF2196F3; + + /// The blue accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigo.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.indigoAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlueAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.blueAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [blue], the corresponding primary colors. + /// * [indigoAccent] and [lightBlueAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor blueAccent = MaterialAccentColor( + _blueAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFF82B1FF), + 200: Color(_blueAccentPrimaryValue), + 400: Color(0xFF2979FF), + 700: Color(0xFF2962FF), + }, + ); + static const int _blueAccentPrimaryValue = 0xFF448AFF; + + /// The light blue primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyan.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyanAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.lightBlue[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [lightBlueAccent], the corresponding accent colors. + /// * [blue] and [cyan], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor lightBlue = MaterialColor( + _lightBluePrimaryValue, + <int, Color>{ + 50: Color(0xFFE1F5FE), + 100: Color(0xFFB3E5FC), + 200: Color(0xFF81D4FA), + 300: Color(0xFF4FC3F7), + 400: Color(0xFF29B6F6), + 500: Color(_lightBluePrimaryValue), + 600: Color(0xFF039BE5), + 700: Color(0xFF0288D1), + 800: Color(0xFF0277BD), + 900: Color(0xFF01579B), + }, + ); + static const int _lightBluePrimaryValue = 0xFF03A9F4; + + /// The light blue accent swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyan.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyanAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.lightBlueAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [lightBlue], the corresponding primary colors. + /// * [blueAccent] and [cyanAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor lightBlueAccent = MaterialAccentColor( + _lightBlueAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFF80D8FF), + 200: Color(_lightBlueAccentPrimaryValue), + 400: Color(0xFF00B0FF), + 700: Color(0xFF0091EA), + }, + ); + static const int _lightBlueAccentPrimaryValue = 0xFF40C4FF; + + /// The cyan primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyan.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyanAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.teal.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.tealAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueGrey.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.cyan[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [cyanAccent], the corresponding accent colors. + /// * [lightBlue], [teal], and [blueGrey], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor cyan = MaterialColor( + _cyanPrimaryValue, + <int, Color>{ + 50: Color(0xFFE0F7FA), + 100: Color(0xFFB2EBF2), + 200: Color(0xFF80DEEA), + 300: Color(0xFF4DD0E1), + 400: Color(0xFF26C6DA), + 500: Color(_cyanPrimaryValue), + 600: Color(0xFF00ACC1), + 700: Color(0xFF0097A7), + 800: Color(0xFF00838F), + 900: Color(0xFF006064), + }, + ); + static const int _cyanPrimaryValue = 0xFF00BCD4; + + /// The cyan accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyan.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyanAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlue.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightBlueAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.teal.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.tealAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.cyanAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [cyan], the corresponding primary colors. + /// * [lightBlueAccent] and [tealAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor cyanAccent = MaterialAccentColor( + _cyanAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFF84FFFF), + 200: Color(_cyanAccentPrimaryValue), + 400: Color(0xFF00E5FF), + 700: Color(0xFF00B8D4), + }, + ); + static const int _cyanAccentPrimaryValue = 0xFF18FFFF; + + /// The teal primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.teal.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.tealAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.green.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.greenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyan.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyanAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.teal[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [tealAccent], the corresponding accent colors. + /// * [green] and [cyan], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor teal = MaterialColor( + _tealPrimaryValue, + <int, Color>{ + 50: Color(0xFFE0F2F1), + 100: Color(0xFFB2DFDB), + 200: Color(0xFF80CBC4), + 300: Color(0xFF4DB6AC), + 400: Color(0xFF26A69A), + 500: Color(_tealPrimaryValue), + 600: Color(0xFF00897B), + 700: Color(0xFF00796B), + 800: Color(0xFF00695C), + 900: Color(0xFF004D40), + }, + ); + static const int _tealPrimaryValue = 0xFF009688; + + /// The teal accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.teal.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.tealAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.green.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.greenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyan.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyanAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.tealAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [teal], the corresponding primary colors. + /// * [greenAccent] and [cyanAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor tealAccent = MaterialAccentColor( + _tealAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFA7FFEB), + 200: Color(_tealAccentPrimaryValue), + 400: Color(0xFF1DE9B6), + 700: Color(0xFF00BFA5), + }, + ); + static const int _tealAccentPrimaryValue = 0xFF64FFDA; + + /// The green primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.green.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.greenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.teal.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.tealAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreen.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lime.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.limeAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.green[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [greenAccent], the corresponding accent colors. + /// * [teal], [lightGreen], and [lime], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor green = MaterialColor( + _greenPrimaryValue, + <int, Color>{ + 50: Color(0xFFE8F5E9), + 100: Color(0xFFC8E6C9), + 200: Color(0xFFA5D6A7), + 300: Color(0xFF81C784), + 400: Color(0xFF66BB6A), + 500: Color(_greenPrimaryValue), + 600: Color(0xFF43A047), + 700: Color(0xFF388E3C), + 800: Color(0xFF2E7D32), + 900: Color(0xFF1B5E20), + }, + ); + static const int _greenPrimaryValue = 0xFF4CAF50; + + /// The green accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.green.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.greenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.teal.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.tealAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreen.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lime.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.limeAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.greenAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [green], the corresponding primary colors. + /// * [tealAccent], [lightGreenAccent], and [limeAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor greenAccent = MaterialAccentColor( + _greenAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFB9F6CA), + 200: Color(_greenAccentPrimaryValue), + 400: Color(0xFF00E676), + 700: Color(0xFF00C853), + }, + ); + static const int _greenAccentPrimaryValue = 0xFF69F0AE; + + /// The light green primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreen.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.green.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.greenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lime.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.limeAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.lightGreen[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [lightGreenAccent], the corresponding accent colors. + /// * [green] and [lime], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor lightGreen = MaterialColor( + _lightGreenPrimaryValue, + <int, Color>{ + 50: Color(0xFFF1F8E9), + 100: Color(0xFFDCEDC8), + 200: Color(0xFFC5E1A5), + 300: Color(0xFFAED581), + 400: Color(0xFF9CCC65), + 500: Color(_lightGreenPrimaryValue), + 600: Color(0xFF7CB342), + 700: Color(0xFF689F38), + 800: Color(0xFF558B2F), + 900: Color(0xFF33691E), + }, + ); + static const int _lightGreenPrimaryValue = 0xFF8BC34A; + + /// The light green accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreen.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.green.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.greenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lime.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.limeAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.lightGreenAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [lightGreen], the corresponding primary colors. + /// * [greenAccent] and [limeAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor lightGreenAccent = MaterialAccentColor( + _lightGreenAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFCCFF90), + 200: Color(_lightGreenAccentPrimaryValue), + 400: Color(0xFF76FF03), + 700: Color(0xFF64DD17), + }, + ); + static const int _lightGreenAccentPrimaryValue = 0xFFB2FF59; + + /// The lime primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lime.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.limeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreen.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellow.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellowAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.lime[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [limeAccent], the corresponding accent colors. + /// * [lightGreen] and [yellow], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor lime = MaterialColor( + _limePrimaryValue, + <int, Color>{ + 50: Color(0xFFF9FBE7), + 100: Color(0xFFF0F4C3), + 200: Color(0xFFE6EE9C), + 300: Color(0xFFDCE775), + 400: Color(0xFFD4E157), + 500: Color(_limePrimaryValue), + 600: Color(0xFFC0CA33), + 700: Color(0xFFAFB42B), + 800: Color(0xFF9E9D24), + 900: Color(0xFF827717), + }, + ); + static const int _limePrimaryValue = 0xFFCDDC39; + + /// The lime accent primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lime.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.limeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreen.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lightGreenAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellow.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellowAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.limeAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [lime], the corresponding primary colors. + /// * [lightGreenAccent] and [yellowAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor limeAccent = MaterialAccentColor( + _limeAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFF4FF81), + 200: Color(_limeAccentPrimaryValue), + 400: Color(0xFFC6FF00), + 700: Color(0xFFAEEA00), + }, + ); + static const int _limeAccentPrimaryValue = 0xFFEEFF41; + + /// The yellow primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellow.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellowAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lime.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.limeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amber.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amberAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.yellow[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [yellowAccent], the corresponding accent colors. + /// * [lime] and [amber], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor yellow = MaterialColor( + _yellowPrimaryValue, + <int, Color>{ + 50: Color(0xFFFFFDE7), + 100: Color(0xFFFFF9C4), + 200: Color(0xFFFFF59D), + 300: Color(0xFFFFF176), + 400: Color(0xFFFFEE58), + 500: Color(_yellowPrimaryValue), + 600: Color(0xFFFDD835), + 700: Color(0xFFFBC02D), + 800: Color(0xFFF9A825), + 900: Color(0xFFF57F17), + }, + ); + static const int _yellowPrimaryValue = 0xFFFFEB3B; + + /// The yellow accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellow.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellowAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.lime.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.limeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amber.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amberAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.yellowAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [yellow], the corresponding primary colors. + /// * [limeAccent] and [amberAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor yellowAccent = MaterialAccentColor( + _yellowAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFFFFF8D), + 200: Color(_yellowAccentPrimaryValue), + 400: Color(0xFFFFEA00), + 700: Color(0xFFFFD600), + }, + ); + static const int _yellowAccentPrimaryValue = 0xFFFFFF00; + + /// The amber primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amber.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amberAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellow.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellowAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orangeAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.amber[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [amberAccent], the corresponding accent colors. + /// * [yellow] and [orange], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor amber = MaterialColor( + _amberPrimaryValue, + <int, Color>{ + 50: Color(0xFFFFF8E1), + 100: Color(0xFFFFECB3), + 200: Color(0xFFFFE082), + 300: Color(0xFFFFD54F), + 400: Color(0xFFFFCA28), + 500: Color(_amberPrimaryValue), + 600: Color(0xFFFFB300), + 700: Color(0xFFFFA000), + 800: Color(0xFFFF8F00), + 900: Color(0xFFFF6F00), + }, + ); + static const int _amberPrimaryValue = 0xFFFFC107; + + /// The amber accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amber.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amberAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellow.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.yellowAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orangeAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.amberAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [amber], the corresponding primary colors. + /// * [yellowAccent] and [orangeAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor amberAccent = MaterialAccentColor( + _amberAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFFFE57F), + 200: Color(_amberAccentPrimaryValue), + 400: Color(0xFFFFC400), + 700: Color(0xFFFFAB00), + }, + ); + static const int _amberAccentPrimaryValue = 0xFFFFD740; + + /// The orange primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orangeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amber.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amberAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrangeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.brown.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.orange[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [orangeAccent], the corresponding accent colors. + /// * [amber], [deepOrange], and [brown], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor orange = MaterialColor( + _orangePrimaryValue, + <int, Color>{ + 50: Color(0xFFFFF3E0), + 100: Color(0xFFFFE0B2), + 200: Color(0xFFFFCC80), + 300: Color(0xFFFFB74D), + 400: Color(0xFFFFA726), + 500: Color(_orangePrimaryValue), + 600: Color(0xFFFB8C00), + 700: Color(0xFFF57C00), + 800: Color(0xFFEF6C00), + 900: Color(0xFFE65100), + }, + ); + static const int _orangePrimaryValue = 0xFFFF9800; + + /// The orange accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orangeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amber.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.amberAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrangeAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.orangeAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [orange], the corresponding primary colors. + /// * [amberAccent] and [deepOrangeAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor orangeAccent = MaterialAccentColor( + _orangeAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFFFD180), + 200: Color(_orangeAccentPrimaryValue), + 400: Color(0xFFFF9100), + 700: Color(0xFFFF6D00), + }, + ); + static const int _orangeAccentPrimaryValue = 0xFFFFAB40; + + /// The deep orange primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrangeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orangeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.red.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.redAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.brown.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.deepOrange[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [deepOrangeAccent], the corresponding accent colors. + /// * [orange], [red], and [brown], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor deepOrange = MaterialColor( + _deepOrangePrimaryValue, + <int, Color>{ + 50: Color(0xFFFBE9E7), + 100: Color(0xFFFFCCBC), + 200: Color(0xFFFFAB91), + 300: Color(0xFFFF8A65), + 400: Color(0xFFFF7043), + 500: Color(_deepOrangePrimaryValue), + 600: Color(0xFFF4511E), + 700: Color(0xFFE64A19), + 800: Color(0xFFD84315), + 900: Color(0xFFBF360C), + }, + ); + static const int _deepOrangePrimaryValue = 0xFFFF5722; + + /// The deep orange accent color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.deepOrangeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orange.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orangeAccent.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.red.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.redAccent.png) + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.deepOrangeAccent[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [deepOrange], the corresponding primary colors. + /// * [orangeAccent] [redAccent], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialAccentColor deepOrangeAccent = MaterialAccentColor( + _deepOrangeAccentPrimaryValue, + <int, Color>{ + 100: Color(0xFFFF9E80), + 200: Color(_deepOrangeAccentPrimaryValue), + 400: Color(0xFFFF3D00), + 700: Color(0xFFDD2C00), + }, + ); + static const int _deepOrangeAccentPrimaryValue = 0xFFFF6E40; + + /// The brown primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.brown.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.orange.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueGrey.png) + /// + /// This swatch has no corresponding accent color and swatch. + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.brown[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [orange] and [blueGrey], vaguely similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor brown = MaterialColor( + _brownPrimaryValue, + <int, Color>{ + 50: Color(0xFFEFEBE9), + 100: Color(0xFFD7CCC8), + 200: Color(0xFFBCAAA4), + 300: Color(0xFFA1887F), + 400: Color(0xFF8D6E63), + 500: Color(_brownPrimaryValue), + 600: Color(0xFF6D4C41), + 700: Color(0xFF5D4037), + 800: Color(0xFF4E342E), + 900: Color(0xFF3E2723), + }, + ); + static const int _brownPrimaryValue = 0xFF795548; + + /// The grey primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.grey.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueGrey.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.brown.png) + /// + /// This swatch has no corresponding accent swatch. + /// + /// This swatch, in addition to the values 50 and 100 to 900 in 100 + /// increments, also features the special values 350 and 850. The 350 value is + /// used for raised button while pressed in light themes, and 850 is used for + /// the background color of the dark theme. See [ThemeData.brightness]. + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.grey[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [blueGrey] and [brown], somewhat similar colors. + /// * [black], [black87], [black54], [black45], [black38], [black26], [black12], which + /// provide a different approach to showing shades of grey. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor grey = MaterialColor( + _greyPrimaryValue, + <int, Color>{ + 50: Color(0xFFFAFAFA), + 100: Color(0xFFF5F5F5), + 200: Color(0xFFEEEEEE), + 300: Color(0xFFE0E0E0), + 350: Color(0xFFD6D6D6), // only for raised button while pressed in light theme + 400: Color(0xFFBDBDBD), + 500: Color(_greyPrimaryValue), + 600: Color(0xFF757575), + 700: Color(0xFF616161), + 800: Color(0xFF424242), + 850: Color(0xFF303030), // only for background color in dark theme + 900: Color(0xFF212121), + }, + ); + static const int _greyPrimaryValue = 0xFF9E9E9E; + + /// The blue-grey primary color and swatch. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blueGrey.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.grey.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.cyan.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/Colors.blue.png) + /// + /// This swatch has no corresponding accent swatch. + /// + /// {@tool snippet} + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.blueGrey[400], + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [grey], [cyan], and [blue], similar colors. + /// * [Theme.of], which allows you to select colors from the current theme + /// rather than hard-coding colors in your build methods. + static const MaterialColor blueGrey = MaterialColor( + _blueGreyPrimaryValue, + <int, Color>{ + 50: Color(0xFFECEFF1), + 100: Color(0xFFCFD8DC), + 200: Color(0xFFB0BEC5), + 300: Color(0xFF90A4AE), + 400: Color(0xFF78909C), + 500: Color(_blueGreyPrimaryValue), + 600: Color(0xFF546E7A), + 700: Color(0xFF455A64), + 800: Color(0xFF37474F), + 900: Color(0xFF263238), + }, + ); + static const int _blueGreyPrimaryValue = 0xFF607D8B; + + /// The Material Design primary color swatches, excluding grey. + static const List<MaterialColor> primaries = <MaterialColor>[ + red, + pink, + purple, + deepPurple, + indigo, + blue, + lightBlue, + cyan, + teal, + green, + lightGreen, + lime, + yellow, + amber, + orange, + deepOrange, + brown, + // The grey swatch is intentionally omitted because when picking a color + // randomly from this list to colorize an application, picking grey suddenly + // makes the app look disabled. + blueGrey, + ]; + + /// The Material Design accent color swatches. + static const List<MaterialAccentColor> accents = <MaterialAccentColor>[ + redAccent, + pinkAccent, + purpleAccent, + deepPurpleAccent, + indigoAccent, + blueAccent, + lightBlueAccent, + cyanAccent, + tealAccent, + greenAccent, + lightGreenAccent, + limeAccent, + yellowAccent, + amberAccent, + orangeAccent, + deepOrangeAccent, + ]; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/constants.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/constants.dart new file mode 100644 index 0000000000000000000000000000000000000000..ce5fb3256bbeef0ac071559ed8e132d585b349aa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/constants.dart @@ -0,0 +1,61 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/painting.dart'; + +/// The minimum dimension of any interactive region according to Material +/// guidelines. +/// +/// This is used to avoid small regions that are hard for the user to interact +/// with. It applies to both dimensions of a region, so a square of size +/// kMinInteractiveDimension x kMinInteractiveDimension is the smallest +/// acceptable region that should respond to gestures. +/// +/// See also: +/// +/// * [kMinInteractiveDimensionCupertino] +/// * The Material spec on touch targets at <https://material.io/design/usability/accessibility.html#layout-typography>. +const double kMinInteractiveDimension = 48.0; + +/// The height of the toolbar component of the [AppBar]. +const double kToolbarHeight = 56.0; + +/// The height of the bottom navigation bar. +const double kBottomNavigationBarHeight = 56.0; + +/// The height of a tab bar containing text. +const double kTextTabBarHeight = kMinInteractiveDimension; + +/// The amount of time theme change animations should last. +const Duration kThemeChangeDuration = Duration(milliseconds: 200); + +/// The default radius of a circular material ink response in logical pixels. +const double kRadialReactionRadius = 20.0; + +/// The amount of time a circular material ink response should take to expand to its full size. +const Duration kRadialReactionDuration = Duration(milliseconds: 100); + +/// The value of the alpha channel to use when drawing a circular material ink response. +const int kRadialReactionAlpha = 0x1F; + +/// The duration of the horizontal scroll animation that occurs when a tab is tapped. +const Duration kTabScrollDuration = Duration(milliseconds: 300); + +/// The horizontal padding included by [Tab]s. +const EdgeInsets kTabLabelPadding = EdgeInsets.symmetric(horizontal: 16.0); + +/// The padding added around material list items. +const EdgeInsets kMaterialListPadding = EdgeInsets.symmetric(vertical: 8.0); + +/// The default color for [ThemeData.iconTheme] when [ThemeData.brightness] is +/// [Brightness.dark]. This color is used in [IconButton] to detect whether +/// [IconTheme.of(context).color] is the same as the default color of [ThemeData.iconTheme]. +// ignore: prefer_const_constructors +final Color kDefaultIconLightColor = Color(0xFFFFFFFF); + +/// The default color for [ThemeData.iconTheme] when [ThemeData.brightness] is +/// [Brightness.light]. This color is used in [IconButton] to detect whether +/// [IconTheme.of(context).color] is the same as the default color of [ThemeData.iconTheme]. +// ignore: prefer_const_constructors +final Color kDefaultIconDarkColor = Color(0xDD000000); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/curves.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/curves.dart new file mode 100644 index 0000000000000000000000000000000000000000..c267e3771ee424cc0820fd8da891fdc502a32c5e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/curves.dart @@ -0,0 +1,38 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/animation.dart'; + +// The easing curves of the Material Library + +// TODO(guidezpl): deprecate the three curves below once customers (packages/plugins) are migrated + +/// The standard easing curve in the Material specification. +/// +/// Elements that begin and end at rest use standard easing. +/// They speed up quickly and slow down gradually, in order +/// to emphasize the end of the transition. +/// +/// See also: +/// * <https://material.io/design/motion/speed.html#easing> +const Curve standardEasing = Curves.fastOutSlowIn; + +/// The accelerate easing curve in the Material specification. +/// +/// Elements exiting a screen use acceleration easing, +/// where they start at rest and end at peak velocity. +/// +/// See also: +/// * <https://material.io/design/motion/speed.html#easing> +const Curve accelerateEasing = Cubic(0.4, 0.0, 1.0, 1.0); + +/// The decelerate easing curve in the Material specification. +/// +/// Incoming elements are animated using deceleration easing, +/// which starts a transition at peak velocity (the fastest +/// point of an element’s movement) and ends at rest. +/// +/// See also: +/// * <https://material.io/design/motion/speed.html#easing> +const Curve decelerateEasing = Cubic(0.0, 0.0, 0.2, 1.0); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/data_table.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/data_table.dart new file mode 100644 index 0000000000000000000000000000000000000000..e1add455280dc12aeabf6c9e9b9ebde39805fdb7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/data_table.dart @@ -0,0 +1,1378 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'checkbox.dart'; +import 'constants.dart'; +import 'data_table_theme.dart'; +import 'debug.dart'; +import 'divider.dart'; +import 'dropdown.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'theme.dart'; +import 'tooltip.dart'; + +// Examples can assume: +// late BuildContext context; +// late List<DataColumn> _columns; +// late List<DataRow> _rows; + +/// Signature for [DataColumn.onSort] callback. +typedef DataColumnSortCallback = void Function(int columnIndex, bool ascending); + +/// Column configuration for a [DataTable]. +/// +/// One column configuration must be provided for each column to +/// display in the table. The list of [DataColumn] objects is passed +/// as the `columns` argument to the [DataTable.new] constructor. +@immutable +class DataColumn { + /// Creates the configuration for a column of a [DataTable]. + const DataColumn({ + required this.label, + this.tooltip, + this.numeric = false, + this.onSort, + this.mouseCursor, + }); + + /// The column heading. + /// + /// Typically, this will be a [Text] widget. It could also be an + /// [Icon] (typically using size 18), or a [Row] with an icon and + /// some text. + /// + /// The [label] is placed within a [Row] along with the + /// sort indicator (if applicable). By default, [label] only occupy minimal + /// space. It is recommended to place the label content in an [Expanded] or + /// [Flexible] as [label] to control how the content flexes. Otherwise, + /// an exception will occur when the available space is insufficient. + /// + /// By default, [DefaultTextStyle.softWrap] of this subtree will be set to false. + /// Use [DefaultTextStyle.merge] to override it if needed. + /// + /// The label should not include the sort indicator. + final Widget label; + + /// The column heading's tooltip. + /// + /// This is a longer description of the column heading, for cases + /// where the heading might have been abbreviated to keep the column + /// width to a reasonable size. + final String? tooltip; + + /// Whether this column represents numeric data or not. + /// + /// The contents of cells of columns containing numeric data are + /// right-aligned. + final bool numeric; + + /// Called when the user asks to sort the table using this column. + /// + /// If null, the column will not be considered sortable. + /// + /// See [DataTable.sortColumnIndex] and [DataTable.sortAscending]. + final DataColumnSortCallback? onSort; + + bool get _debugInteractive => onSort != null; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// heading row. + /// + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.disabled]. + /// + /// If this is null, then the value of [DataTableThemeData.headingCellCursor] + /// is used. If that's null, then [MaterialStateMouseCursor.clickable] is used. + /// + /// See also: + /// * [MaterialStateMouseCursor], which can be used to create a [MouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; +} + +/// Row configuration and cell data for a [DataTable]. +/// +/// One row configuration must be provided for each row to +/// display in the table. The list of [DataRow] objects is passed +/// as the `rows` argument to the [DataTable.new] constructor. +/// +/// The data for this row of the table is provided in the [cells] +/// property of the [DataRow] object. +@immutable +class DataRow { + /// Creates the configuration for a row of a [DataTable]. + const DataRow({ + this.key, + this.selected = false, + this.onSelectChanged, + this.onLongPress, + this.color, + this.mouseCursor, + required this.cells, + }); + + /// Creates the configuration for a row of a [DataTable], deriving + /// the key from a row index. + DataRow.byIndex({ + int? index, + this.selected = false, + this.onSelectChanged, + this.onLongPress, + this.color, + this.mouseCursor, + required this.cells, + }) : key = ValueKey<int?>(index); + + /// A [Key] that uniquely identifies this row. This is used to + /// ensure that if a row is added or removed, any stateful widgets + /// related to this row (e.g. an in-progress checkbox animation) + /// remain on the right row visually. + /// + /// If the table never changes once created, no key is necessary. + final LocalKey? key; + + /// Called when the user selects or unselects a selectable row. + /// + /// If this is not null, then the row is selectable. The current + /// selection state of the row is given by [selected]. + /// + /// If any row is selectable, then the table's heading row will have + /// a checkbox that can be checked to select all selectable rows + /// (and which is checked if all the rows are selected), and each + /// subsequent row will have a checkbox to toggle just that row. + /// + /// A row whose [onSelectChanged] callback is null is ignored for + /// the purposes of determining the state of the "all" checkbox, + /// and its checkbox is disabled. + /// + /// If a [DataCell] in the row has its [DataCell.onTap] callback defined, + /// that callback behavior overrides the gesture behavior of the row for + /// that particular cell. + final ValueChanged<bool?>? onSelectChanged; + + /// Called if the row is long-pressed. + /// + /// If a [DataCell] in the row has its [DataCell.onTap], [DataCell.onDoubleTap], + /// [DataCell.onLongPress], [DataCell.onTapCancel] or [DataCell.onTapDown] callback defined, + /// that callback behavior overrides the gesture behavior of the row for + /// that particular cell. + final GestureLongPressCallback? onLongPress; + + /// Whether the row is selected. + /// + /// If [onSelectChanged] is non-null for any row in the table, then + /// a checkbox is shown at the start of each row. If the row is + /// selected (true), the checkbox will be checked and the row will + /// be highlighted. + /// + /// Otherwise, the checkbox, if present, will not be checked. + final bool selected; + + /// The data for this row. + /// + /// There must be exactly as many cells as there are columns in the + /// table. + final List<DataCell> cells; + + /// The color for the row. + /// + /// By default, the color is transparent unless selected. Selected rows has + /// a grey translucent color. + /// + /// The effective color can depend on the [MaterialState] state, if the + /// row is selected, pressed, hovered, focused, disabled or enabled. The + /// color is painted as an overlay to the row. To make sure that the row's + /// [InkWell] is visible (when pressed, hovered and focused), it is + /// recommended to use a translucent color. + /// + /// ```dart + /// DataRow( + /// color: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) { + /// if (states.contains(MaterialState.selected)) { + /// return Theme.of(context).colorScheme.primary.withOpacity(0.08); + /// } + /// return null; // Use the default value. + /// }), + /// cells: const <DataCell>[ + /// // ... + /// ], + /// ) + /// ``` + /// + /// See also: + /// + /// * The Material Design specification for overlay colors and how they + /// match a component's state: + /// <https://material.io/design/interaction/states.html#anatomy>. + final MaterialStateProperty<Color?>? color; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// data row. + /// + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.selected]. + /// + /// If this is null, then the value of [DataTableThemeData.dataRowCursor] + /// is used. If that's null, then [MaterialStateMouseCursor.clickable] is used. + /// + /// See also: + /// * [MaterialStateMouseCursor], which can be used to create a [MouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + bool get _debugInteractive => onSelectChanged != null || cells.any((DataCell cell) => cell._debugInteractive); +} + +/// The data for a cell of a [DataTable]. +/// +/// One list of [DataCell] objects must be provided for each [DataRow] +/// in the [DataTable], in the new [DataRow] constructor's `cells` +/// argument. +@immutable +class DataCell { + /// Creates an object to hold the data for a cell in a [DataTable]. + /// + /// The first argument is the widget to show for the cell, typically + /// a [Text] or [DropdownButton] widget. + /// + /// If the cell has no data, then a [Text] widget with placeholder + /// text should be provided instead, and then the [placeholder] + /// argument should be set to true. + const DataCell( + this.child, { + this.placeholder = false, + this.showEditIcon = false, + this.onTap, + this.onLongPress, + this.onTapDown, + this.onDoubleTap, + this.onTapCancel, + }); + + /// A cell that has no content and has zero width and height. + static const DataCell empty = DataCell(SizedBox.shrink()); + + /// The data for the row. + /// + /// Typically a [Text] widget or a [DropdownButton] widget. + /// + /// If the cell has no data, then a [Text] widget with placeholder + /// text should be provided instead, and [placeholder] should be set + /// to true. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// Whether the [child] is actually a placeholder. + /// + /// If this is true, the default text style for the cell is changed + /// to be appropriate for placeholder text. + final bool placeholder; + + /// Whether to show an edit icon at the end of the cell. + /// + /// This does not make the cell actually editable; the caller must + /// implement editing behavior if desired (initiated from the + /// [onTap] callback). + /// + /// If this is set, [onTap] should also be set, otherwise tapping + /// the icon will have no effect. + final bool showEditIcon; + + /// Called if the cell is tapped. + /// + /// If non-null, tapping the cell will call this callback. If + /// null (including [onDoubleTap], [onLongPress], [onTapCancel] and [onTapDown]), + /// tapping the cell will attempt to select the row (if + /// [DataRow.onSelectChanged] is provided). + final GestureTapCallback? onTap; + + /// Called when the cell is double tapped. + /// + /// If non-null, tapping the cell will call this callback. If + /// null (including [onTap], [onLongPress], [onTapCancel] and [onTapDown]), + /// tapping the cell will attempt to select the row (if + /// [DataRow.onSelectChanged] is provided). + final GestureTapCallback? onDoubleTap; + + /// Called if the cell is long-pressed. + /// + /// If non-null, tapping the cell will invoke this callback. If + /// null (including [onDoubleTap], [onTap], [onTapCancel] and [onTapDown]), + /// tapping the cell will attempt to select the row (if + /// [DataRow.onSelectChanged] is provided). + final GestureLongPressCallback? onLongPress; + + /// Called if the cell is tapped down. + /// + /// If non-null, tapping the cell will call this callback. If + /// null (including [onTap] [onDoubleTap], [onLongPress] and [onTapCancel]), + /// tapping the cell will attempt to select the row (if + /// [DataRow.onSelectChanged] is provided). + final GestureTapDownCallback? onTapDown; + + /// Called if the user cancels a tap was started on cell. + /// + /// If non-null, canceling the tap gesture will invoke this callback. + /// If null (including [onTap], [onDoubleTap] and [onLongPress]), + /// tapping the cell will attempt to select the + /// row (if [DataRow.onSelectChanged] is provided). + final GestureTapCancelCallback? onTapCancel; + + bool get _debugInteractive => onTap != null || + onDoubleTap != null || + onLongPress != null || + onTapDown != null || + onTapCancel != null; +} + +/// A Material Design data table. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ktTajqbhIcY} +/// +/// Displaying data in a table is expensive, because to lay out the +/// table all the data must be measured twice, once to negotiate the +/// dimensions to use for each column, and once to actually lay out +/// the table given the results of the negotiation. +/// +/// For this reason, if you have a lot of data (say, more than a dozen +/// rows with a dozen columns, though the precise limits depend on the +/// target device), it is suggested that you use a +/// [PaginatedDataTable] which automatically splits the data into +/// multiple pages. +/// +/// ## Performance considerations when wrapping [DataTable] with [SingleChildScrollView] +/// +/// Wrapping a [DataTable] with [SingleChildScrollView] is expensive as [SingleChildScrollView] +/// mounts and paints the entire [DataTable] even when only some rows are visible. If scrolling in +/// one direction is necessary, then consider using a [CustomScrollView], otherwise use [PaginatedDataTable] +/// to split the data into smaller pages. +/// +/// {@tool dartpad} +/// This sample shows how to display a [DataTable] with three columns: name, age, and +/// role. The columns are defined by three [DataColumn] objects. The table +/// contains three rows of data for three example users, the data for which +/// is defined by three [DataRow] objects. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/data_table.png) +/// +/// ** See code in examples/api/lib/material/data_table/data_table.0.dart ** +/// {@end-tool} +/// +/// +/// {@tool dartpad} +/// This sample shows how to display a [DataTable] with alternate colors per +/// row, and a custom color for when the row is selected. +/// +/// ** See code in examples/api/lib/material/data_table/data_table.1.dart ** +/// {@end-tool} +/// +/// [DataTable] can be sorted on the basis of any column in [columns] in +/// ascending or descending order. If [sortColumnIndex] is non-null, then the +/// table will be sorted by the values in the specified column. The boolean +/// [sortAscending] flag controls the sort order. +/// +/// See also: +/// +/// * [DataColumn], which describes a column in the data table. +/// * [DataRow], which contains the data for a row in the data table. +/// * [DataCell], which contains the data for a single cell in the data table. +/// * [PaginatedDataTable], which shows part of the data in a data table and +/// provides controls for paging through the remainder of the data. +/// * <https://material.io/design/components/data-tables.html> +class DataTable extends StatelessWidget { + /// Creates a widget describing a data table. + /// + /// The [columns] argument must be a list of as many [DataColumn] + /// objects as the table is to have columns, ignoring the leading + /// checkbox column if any. The [columns] argument must have a + /// length greater than zero. + /// + /// The [rows] argument must be a list of as many [DataRow] objects + /// as the table is to have rows, ignoring the leading heading row + /// that contains the column headings (derived from the [columns] + /// argument). There may be zero rows, but the rows argument must + /// not be null. + /// + /// Each [DataRow] object in [rows] must have as many [DataCell] + /// objects in the [DataRow.cells] list as the table has columns. + /// + /// If the table is sorted, the column that provides the current + /// primary key should be specified by index in [sortColumnIndex], 0 + /// meaning the first column in [columns], 1 being the next one, and + /// so forth. + /// + /// The actual sort order can be specified using [sortAscending]; if + /// the sort order is ascending, this should be true (the default), + /// otherwise it should be false. + DataTable({ + super.key, + required this.columns, + this.sortColumnIndex, + this.sortAscending = true, + this.onSelectAll, + this.decoration, + this.dataRowColor, + @Deprecated( + 'Migrate to use dataRowMinHeight and dataRowMaxHeight instead. ' + 'This feature was deprecated after v3.7.0-5.0.pre.', + ) + double? dataRowHeight, + double? dataRowMinHeight, + double? dataRowMaxHeight, + this.dataTextStyle, + this.headingRowColor, + this.headingRowHeight, + this.headingTextStyle, + this.horizontalMargin, + this.columnSpacing, + this.showCheckboxColumn = true, + this.showBottomBorder = false, + this.dividerThickness, + required this.rows, + this.checkboxHorizontalMargin, + this.border, + this.clipBehavior = Clip.none, + }) : assert(columns.isNotEmpty), + assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)), + assert(!rows.any((DataRow row) => row.cells.length != columns.length), 'All rows must have the same number of cells as there are header cells (${columns.length})'), + assert(dividerThickness == null || dividerThickness >= 0), + assert(dataRowMinHeight == null || dataRowMaxHeight == null || dataRowMaxHeight >= dataRowMinHeight), + assert(dataRowHeight == null || (dataRowMinHeight == null && dataRowMaxHeight == null), + 'dataRowHeight ($dataRowHeight) must not be set if dataRowMinHeight ($dataRowMinHeight) or dataRowMaxHeight ($dataRowMaxHeight) are set.'), + dataRowMinHeight = dataRowHeight ?? dataRowMinHeight, + dataRowMaxHeight = dataRowHeight ?? dataRowMaxHeight, + _onlyTextColumn = _initOnlyTextColumn(columns); + + /// The configuration and labels for the columns in the table. + final List<DataColumn> columns; + + /// The current primary sort key's column. + /// + /// If non-null, indicates that the indicated column is the column + /// by which the data is sorted. The number must correspond to the + /// index of the relevant column in [columns]. + /// + /// Setting this will cause the relevant column to have a sort + /// indicator displayed. + /// + /// When this is null, it implies that the table's sort order does + /// not correspond to any of the columns. + /// + /// The direction of the sort is specified using [sortAscending]. + final int? sortColumnIndex; + + /// Whether the column mentioned in [sortColumnIndex], if any, is sorted + /// in ascending order. + /// + /// If true, the order is ascending (meaning the rows with the + /// smallest values for the current sort column are first in the + /// table). + /// + /// If false, the order is descending (meaning the rows with the + /// smallest values for the current sort column are last in the + /// table). + /// + /// Ascending order is represented by an upwards-facing arrow. + final bool sortAscending; + + /// Invoked when the user selects or unselects every row, using the + /// checkbox in the heading row. + /// + /// If this is null, then the [DataRow.onSelectChanged] callback of + /// every row in the table is invoked appropriately instead. + /// + /// To control whether a particular row is selectable or not, see + /// [DataRow.onSelectChanged]. This callback is only relevant if any + /// row is selectable. + final ValueSetter<bool?>? onSelectAll; + + /// {@template flutter.material.dataTable.decoration} + /// The background and border decoration for the table. + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.decoration] is used. By default there is no + /// decoration. + final Decoration? decoration; + + /// {@template flutter.material.dataTable.dataRowColor} + /// The background color for the data rows. + /// + /// The effective background color can be made to depend on the + /// [MaterialState] state, i.e. if the row is selected, pressed, hovered, + /// focused, disabled or enabled. The color is painted as an overlay to the + /// row. To make sure that the row's [InkWell] is visible (when pressed, + /// hovered and focused), it is recommended to use a translucent background + /// color. + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.dataRowColor] is used. By default, the + /// background color is transparent unless selected. Selected rows have a grey + /// translucent color. To set a different color for individual rows, see + /// [DataRow.color]. + /// + /// {@template flutter.material.DataTable.dataRowColor} + /// ```dart + /// DataTable( + /// dataRowColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) { + /// if (states.contains(MaterialState.selected)) { + /// return Theme.of(context).colorScheme.primary.withOpacity(0.08); + /// } + /// return null; // Use the default value. + /// }), + /// columns: _columns, + /// rows: _rows, + /// ) + /// ``` + /// + /// See also: + /// + /// * The Material Design specification for overlay colors and how they + /// match a component's state: + /// <https://material.io/design/interaction/states.html#anatomy>. + /// {@endtemplate} + final MaterialStateProperty<Color?>? dataRowColor; + + /// {@template flutter.material.dataTable.dataRowHeight} + /// The height of each row (excluding the row that contains column headings). + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.dataRowHeight] is used. This value defaults + /// to [kMinInteractiveDimension] to adhere to the Material Design + /// specifications. + @Deprecated( + 'Migrate to use dataRowMinHeight and dataRowMaxHeight instead. ' + 'This feature was deprecated after v3.7.0-5.0.pre.', + ) + double? get dataRowHeight => dataRowMinHeight == dataRowMaxHeight ? dataRowMinHeight : null; + + /// {@template flutter.material.dataTable.dataRowMinHeight} + /// The minimum height of each row (excluding the row that contains column headings). + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.dataRowMinHeight] is used. This value defaults + /// to [kMinInteractiveDimension] to adhere to the Material Design + /// specifications. + final double? dataRowMinHeight; + + /// {@template flutter.material.dataTable.dataRowMaxHeight} + /// The maximum height of each row (excluding the row that contains column headings). + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.dataRowMaxHeight] is used. This value defaults + /// to [kMinInteractiveDimension] to adhere to the Material Design + /// specifications. + final double? dataRowMaxHeight; + + /// {@template flutter.material.dataTable.dataTextStyle} + /// The text style for data rows. + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.dataTextStyle] is used. By default, the text + /// style is [TextTheme.bodyMedium]. + final TextStyle? dataTextStyle; + + /// {@template flutter.material.dataTable.headingRowColor} + /// The background color for the heading row. + /// + /// The effective background color can be made to depend on the + /// [MaterialState] state, i.e. if the row is pressed, hovered, focused when + /// sorted. The color is painted as an overlay to the row. To make sure that + /// the row's [InkWell] is visible (when pressed, hovered and focused), it is + /// recommended to use a translucent color. + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.headingRowColor] is used. + /// + /// {@template flutter.material.DataTable.headingRowColor} + /// ```dart + /// DataTable( + /// columns: _columns, + /// rows: _rows, + /// headingRowColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) { + /// if (states.contains(MaterialState.hovered)) { + /// return Theme.of(context).colorScheme.primary.withOpacity(0.08); + /// } + /// return null; // Use the default value. + /// }), + /// ) + /// ``` + /// + /// See also: + /// + /// * The Material Design specification for overlay colors and how they + /// match a component's state: + /// <https://material.io/design/interaction/states.html#anatomy>. + /// {@endtemplate} + final MaterialStateProperty<Color?>? headingRowColor; + + /// {@template flutter.material.dataTable.headingRowHeight} + /// The height of the heading row. + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.headingRowHeight] is used. This value + /// defaults to 56.0 to adhere to the Material Design specifications. + final double? headingRowHeight; + + /// {@template flutter.material.dataTable.headingTextStyle} + /// The text style for the heading row. + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.headingTextStyle] is used. By default, the + /// text style is [TextTheme.titleSmall]. + final TextStyle? headingTextStyle; + + /// {@template flutter.material.dataTable.horizontalMargin} + /// The horizontal margin between the edges of the table and the content + /// in the first and last cells of each row. + /// + /// When a checkbox is displayed, it is also the margin between the checkbox + /// the content in the first data column. + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.horizontalMargin] is used. This value + /// defaults to 24.0 to adhere to the Material Design specifications. + /// + /// If [checkboxHorizontalMargin] is null, then [horizontalMargin] is also the + /// margin between the edge of the table and the checkbox, as well as the + /// margin between the checkbox and the content in the first data column. + final double? horizontalMargin; + + /// {@template flutter.material.dataTable.columnSpacing} + /// The horizontal margin between the contents of each data column. + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.columnSpacing] is used. This value defaults + /// to 56.0 to adhere to the Material Design specifications. + final double? columnSpacing; + + /// {@template flutter.material.dataTable.showCheckboxColumn} + /// Whether the widget should display checkboxes for selectable rows. + /// + /// If true, a [Checkbox] will be placed at the beginning of each row that is + /// selectable. However, if [DataRow.onSelectChanged] is not set for any row, + /// checkboxes will not be placed, even if this value is true. + /// + /// If false, all rows will not display a [Checkbox]. + /// {@endtemplate} + final bool showCheckboxColumn; + + /// The data to show in each row (excluding the row that contains + /// the column headings). + /// + /// The list may be empty. + final List<DataRow> rows; + + /// {@template flutter.material.dataTable.dividerThickness} + /// The width of the divider that appears between [TableRow]s. + /// + /// Must be greater than or equal to zero. + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.dividerThickness] is used. This value + /// defaults to 1.0. + final double? dividerThickness; + + /// Whether a border at the bottom of the table is displayed. + /// + /// By default, a border is not shown at the bottom to allow for a border + /// around the table defined by [decoration]. + final bool showBottomBorder; + + /// {@template flutter.material.dataTable.checkboxHorizontalMargin} + /// Horizontal margin around the checkbox, if it is displayed. + /// {@endtemplate} + /// + /// If null, [DataTableThemeData.checkboxHorizontalMargin] is used. If that is + /// also null, then [horizontalMargin] is used as the margin between the edge + /// of the table and the checkbox, as well as the margin between the checkbox + /// and the content in the first data column. This value defaults to 24.0. + final double? checkboxHorizontalMargin; + + /// The style to use when painting the boundary and interior divisions of the table. + final TableBorder? border; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// This can be used to clip the content within the border of the [DataTable]. + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + // Set by the constructor to the index of the only Column that is + // non-numeric, if there is exactly one, otherwise null. + final int? _onlyTextColumn; + static int? _initOnlyTextColumn(List<DataColumn> columns) { + int? result; + for (int index = 0; index < columns.length; index += 1) { + final DataColumn column = columns[index]; + if (!column.numeric) { + if (result != null) { + return null; + } + result = index; + } + } + return result; + } + + bool get _debugInteractive { + return columns.any((DataColumn column) => column._debugInteractive) + || rows.any((DataRow row) => row._debugInteractive); + } + + static final LocalKey _headingRowKey = UniqueKey(); + + void _handleSelectAll(bool? checked, bool someChecked) { + // If some checkboxes are checked, all checkboxes are selected. Otherwise, + // use the new checked value but default to false if it's null. + final bool effectiveChecked = someChecked || (checked ?? false); + if (onSelectAll != null) { + onSelectAll!(effectiveChecked); + } else { + for (final DataRow row in rows) { + if (row.onSelectChanged != null && row.selected != effectiveChecked) { + row.onSelectChanged!(effectiveChecked); + } + } + } + } + + /// The default height of the heading row. + static const double _headingRowHeight = 56.0; + + /// The default horizontal margin between the edges of the table and the content + /// in the first and last cells of each row. + static const double _horizontalMargin = 24.0; + + /// The default horizontal margin between the contents of each data column. + static const double _columnSpacing = 56.0; + + /// The default padding between the heading content and sort arrow. + static const double _sortArrowPadding = 2.0; + + /// The default divider thickness. + static const double _dividerThickness = 1.0; + + static const Duration _sortArrowAnimationDuration = Duration(milliseconds: 150); + + Widget _buildCheckbox({ + required BuildContext context, + required bool? checked, + required VoidCallback? onRowTap, + required ValueChanged<bool?>? onCheckboxChanged, + required MaterialStateProperty<Color?>? overlayColor, + required bool tristate, + MouseCursor? rowMouseCursor, + }) { + final ThemeData themeData = Theme.of(context); + final double effectiveHorizontalMargin = horizontalMargin + ?? themeData.dataTableTheme.horizontalMargin + ?? _horizontalMargin; + final double effectiveCheckboxHorizontalMarginStart = checkboxHorizontalMargin + ?? themeData.dataTableTheme.checkboxHorizontalMargin + ?? effectiveHorizontalMargin; + final double effectiveCheckboxHorizontalMarginEnd = checkboxHorizontalMargin + ?? themeData.dataTableTheme.checkboxHorizontalMargin + ?? effectiveHorizontalMargin / 2.0; + Widget contents = Semantics( + container: true, + child: Padding( + padding: EdgeInsetsDirectional.only( + start: effectiveCheckboxHorizontalMarginStart, + end: effectiveCheckboxHorizontalMarginEnd, + ), + child: Center( + child: Checkbox( + value: checked, + onChanged: onCheckboxChanged, + tristate: tristate, + ), + ), + ), + ); + if (onRowTap != null) { + contents = TableRowInkWell( + onTap: onRowTap, + overlayColor: overlayColor, + mouseCursor: rowMouseCursor, + child: contents, + ); + } + return TableCell( + verticalAlignment: TableCellVerticalAlignment.fill, + child: contents, + ); + } + + Widget _buildHeadingCell({ + required BuildContext context, + required EdgeInsetsGeometry padding, + required Widget label, + required String? tooltip, + required bool numeric, + required VoidCallback? onSort, + required bool sorted, + required bool ascending, + required MaterialStateProperty<Color?>? overlayColor, + required MouseCursor? mouseCursor, + }) { + final ThemeData themeData = Theme.of(context); + final DataTableThemeData dataTableTheme = DataTableTheme.of(context); + label = Row( + textDirection: numeric ? TextDirection.rtl : null, + children: <Widget>[ + label, + if (onSort != null) + ...<Widget>[ + _SortArrow( + visible: sorted, + up: sorted ? ascending : null, + duration: _sortArrowAnimationDuration, + ), + const SizedBox(width: _sortArrowPadding), + ], + ], + ); + + final TextStyle effectiveHeadingTextStyle = headingTextStyle + ?? dataTableTheme.headingTextStyle + ?? themeData.dataTableTheme.headingTextStyle + ?? themeData.textTheme.titleSmall!; + final double effectiveHeadingRowHeight = headingRowHeight + ?? dataTableTheme.headingRowHeight + ?? themeData.dataTableTheme.headingRowHeight + ?? _headingRowHeight; + label = Container( + padding: padding, + height: effectiveHeadingRowHeight, + alignment: numeric ? Alignment.centerRight : AlignmentDirectional.centerStart, + child: AnimatedDefaultTextStyle( + style: DefaultTextStyle.of(context).style.merge(effectiveHeadingTextStyle), + softWrap: false, + duration: _sortArrowAnimationDuration, + child: label, + ), + ); + if (tooltip != null) { + label = Tooltip( + message: tooltip, + child: label, + ); + } + + // TODO(dkwingsmt): Only wrap Inkwell if onSort != null. Blocked by + // https://github.com/flutter/flutter/issues/51152 + label = InkWell( + onTap: onSort, + overlayColor: overlayColor, + mouseCursor: mouseCursor, + child: label, + ); + return label; + } + + Widget _buildDataCell({ + required BuildContext context, + required EdgeInsetsGeometry padding, + required Widget label, + required bool numeric, + required bool placeholder, + required bool showEditIcon, + required GestureTapCallback? onTap, + required VoidCallback? onSelectChanged, + required GestureTapCallback? onDoubleTap, + required GestureLongPressCallback? onLongPress, + required GestureTapDownCallback? onTapDown, + required GestureTapCancelCallback? onTapCancel, + required MaterialStateProperty<Color?>? overlayColor, + required GestureLongPressCallback? onRowLongPress, + required MouseCursor? mouseCursor, + }) { + final ThemeData themeData = Theme.of(context); + final DataTableThemeData dataTableTheme = DataTableTheme.of(context); + if (showEditIcon) { + const Widget icon = Icon(Icons.edit, size: 18.0); + label = Expanded(child: label); + label = Row( + textDirection: numeric ? TextDirection.rtl : null, + children: <Widget>[ label, icon ], + ); + } + + final TextStyle effectiveDataTextStyle = dataTextStyle + ?? dataTableTheme.dataTextStyle + ?? themeData.dataTableTheme.dataTextStyle + ?? themeData.textTheme.bodyMedium!; + final double effectiveDataRowMinHeight = dataRowMinHeight + ?? dataTableTheme.dataRowMinHeight + ?? themeData.dataTableTheme.dataRowMinHeight + ?? kMinInteractiveDimension; + final double effectiveDataRowMaxHeight = dataRowMaxHeight + ?? dataTableTheme.dataRowMaxHeight + ?? themeData.dataTableTheme.dataRowMaxHeight + ?? kMinInteractiveDimension; + label = Container( + padding: padding, + constraints: BoxConstraints(minHeight: effectiveDataRowMinHeight, maxHeight: effectiveDataRowMaxHeight), + alignment: numeric ? Alignment.centerRight : AlignmentDirectional.centerStart, + child: DefaultTextStyle( + style: DefaultTextStyle.of(context).style + .merge(effectiveDataTextStyle) + .copyWith(color: placeholder ? effectiveDataTextStyle.color!.withOpacity(0.6) : null), + child: DropdownButtonHideUnderline(child: label), + ), + ); + if (onTap != null || + onDoubleTap != null || + onLongPress != null || + onTapDown != null || + onTapCancel != null) { + label = InkWell( + onTap: onTap, + onDoubleTap: onDoubleTap, + onLongPress: onLongPress, + onTapCancel: onTapCancel, + onTapDown: onTapDown, + overlayColor: overlayColor, + child: label, + ); + } else if (onSelectChanged != null || onRowLongPress != null) { + label = TableRowInkWell( + onTap: onSelectChanged, + onLongPress: onRowLongPress, + overlayColor: overlayColor, + mouseCursor: mouseCursor, + child: label, + ); + } + return label; + } + + @override + Widget build(BuildContext context) { + assert(!_debugInteractive || debugCheckHasMaterial(context)); + + final ThemeData theme = Theme.of(context); + final DataTableThemeData dataTableTheme = DataTableTheme.of(context); + final MaterialStateProperty<Color?>? effectiveHeadingRowColor = headingRowColor + ?? dataTableTheme.headingRowColor + ?? theme.dataTableTheme.headingRowColor; + final MaterialStateProperty<Color?>? effectiveDataRowColor = dataRowColor + ?? dataTableTheme.dataRowColor + ?? theme.dataTableTheme.dataRowColor; + final MaterialStateProperty<Color?> defaultRowColor = MaterialStateProperty.resolveWith( + (Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return theme.colorScheme.primary.withOpacity(0.08); + } + return null; + }, + ); + final bool anyRowSelectable = rows.any((DataRow row) => row.onSelectChanged != null); + final bool displayCheckboxColumn = showCheckboxColumn && anyRowSelectable; + final Iterable<DataRow> rowsWithCheckbox = displayCheckboxColumn ? + rows.where((DataRow row) => row.onSelectChanged != null) : <DataRow>[]; + final Iterable<DataRow> rowsChecked = rowsWithCheckbox.where((DataRow row) => row.selected); + final bool allChecked = displayCheckboxColumn && rowsChecked.length == rowsWithCheckbox.length; + final bool anyChecked = displayCheckboxColumn && rowsChecked.isNotEmpty; + final bool someChecked = anyChecked && !allChecked; + final double effectiveHorizontalMargin = horizontalMargin + ?? dataTableTheme.horizontalMargin + ?? theme.dataTableTheme.horizontalMargin + ?? _horizontalMargin; + final double effectiveCheckboxHorizontalMarginStart = checkboxHorizontalMargin + ?? dataTableTheme.checkboxHorizontalMargin + ?? theme.dataTableTheme.checkboxHorizontalMargin + ?? effectiveHorizontalMargin; + final double effectiveCheckboxHorizontalMarginEnd = checkboxHorizontalMargin + ?? dataTableTheme.checkboxHorizontalMargin + ?? theme.dataTableTheme.checkboxHorizontalMargin + ?? effectiveHorizontalMargin / 2.0; + final double effectiveColumnSpacing = columnSpacing + ?? dataTableTheme.columnSpacing + ?? theme.dataTableTheme.columnSpacing + ?? _columnSpacing; + + final List<TableColumnWidth> tableColumns = List<TableColumnWidth>.filled(columns.length + (displayCheckboxColumn ? 1 : 0), const _NullTableColumnWidth()); + final List<TableRow> tableRows = List<TableRow>.generate( + rows.length + 1, // the +1 is for the header row + (int index) { + final bool isSelected = index > 0 && rows[index - 1].selected; + final bool isDisabled = index > 0 && anyRowSelectable && rows[index - 1].onSelectChanged == null; + final Set<MaterialState> states = <MaterialState>{ + if (isSelected) + MaterialState.selected, + if (isDisabled) + MaterialState.disabled, + }; + final Color? resolvedDataRowColor = index > 0 ? (rows[index - 1].color ?? effectiveDataRowColor)?.resolve(states) : null; + final Color? resolvedHeadingRowColor = effectiveHeadingRowColor?.resolve(<MaterialState>{}); + final Color? rowColor = index > 0 ? resolvedDataRowColor : resolvedHeadingRowColor; + final BorderSide borderSide = Divider.createBorderSide( + context, + width: dividerThickness + ?? dataTableTheme.dividerThickness + ?? theme.dataTableTheme.dividerThickness + ?? _dividerThickness, + ); + final Border? border = showBottomBorder + ? Border(bottom: borderSide) + : index == 0 ? null : Border(top: borderSide); + return TableRow( + key: index == 0 ? _headingRowKey : rows[index - 1].key, + decoration: BoxDecoration( + border: border, + color: rowColor ?? defaultRowColor.resolve(states), + ), + children: List<Widget>.filled(tableColumns.length, const _NullWidget()), + ); + }, + ); + + int rowIndex; + + int displayColumnIndex = 0; + if (displayCheckboxColumn) { + tableColumns[0] = FixedColumnWidth(effectiveCheckboxHorizontalMarginStart + Checkbox.width + effectiveCheckboxHorizontalMarginEnd); + tableRows[0].children[0] = _buildCheckbox( + context: context, + checked: someChecked ? null : allChecked, + onRowTap: null, + onCheckboxChanged: (bool? checked) => _handleSelectAll(checked, someChecked), + overlayColor: null, + tristate: true, + ); + rowIndex = 1; + for (final DataRow row in rows) { + final Set<MaterialState> states = <MaterialState>{ + if (row.selected) + MaterialState.selected, + }; + tableRows[rowIndex].children[0] = _buildCheckbox( + context: context, + checked: row.selected, + onRowTap: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected), + onCheckboxChanged: row.onSelectChanged, + overlayColor: row.color ?? effectiveDataRowColor, + rowMouseCursor: row.mouseCursor?.resolve(states) ?? dataTableTheme.dataRowCursor?.resolve(states), + tristate: false, + ); + rowIndex += 1; + } + displayColumnIndex += 1; + } + + for (int dataColumnIndex = 0; dataColumnIndex < columns.length; dataColumnIndex += 1) { + final DataColumn column = columns[dataColumnIndex]; + + final double paddingStart; + if (dataColumnIndex == 0 && displayCheckboxColumn && checkboxHorizontalMargin != null) { + paddingStart = effectiveHorizontalMargin; + } else if (dataColumnIndex == 0 && displayCheckboxColumn) { + paddingStart = effectiveHorizontalMargin / 2.0; + } else if (dataColumnIndex == 0 && !displayCheckboxColumn) { + paddingStart = effectiveHorizontalMargin; + } else { + paddingStart = effectiveColumnSpacing / 2.0; + } + + final double paddingEnd; + if (dataColumnIndex == columns.length - 1) { + paddingEnd = effectiveHorizontalMargin; + } else { + paddingEnd = effectiveColumnSpacing / 2.0; + } + + final EdgeInsetsDirectional padding = EdgeInsetsDirectional.only( + start: paddingStart, + end: paddingEnd, + ); + if (dataColumnIndex == _onlyTextColumn) { + tableColumns[displayColumnIndex] = const IntrinsicColumnWidth(flex: 1.0); + } else { + tableColumns[displayColumnIndex] = const IntrinsicColumnWidth(); + } + final Set<MaterialState> headerStates = <MaterialState>{ + if (column.onSort == null) + MaterialState.disabled, + }; + tableRows[0].children[displayColumnIndex] = _buildHeadingCell( + context: context, + padding: padding, + label: column.label, + tooltip: column.tooltip, + numeric: column.numeric, + onSort: column.onSort != null ? () => column.onSort!(dataColumnIndex, sortColumnIndex != dataColumnIndex || !sortAscending) : null, + sorted: dataColumnIndex == sortColumnIndex, + ascending: sortAscending, + overlayColor: effectiveHeadingRowColor, + mouseCursor: column.mouseCursor?.resolve(headerStates) ?? dataTableTheme.headingCellCursor?.resolve(headerStates), + ); + rowIndex = 1; + for (final DataRow row in rows) { + final Set<MaterialState> states = <MaterialState>{ + if (row.selected) + MaterialState.selected, + }; + final DataCell cell = row.cells[dataColumnIndex]; + tableRows[rowIndex].children[displayColumnIndex] = _buildDataCell( + context: context, + padding: padding, + label: cell.child, + numeric: column.numeric, + placeholder: cell.placeholder, + showEditIcon: cell.showEditIcon, + onTap: cell.onTap, + onDoubleTap: cell.onDoubleTap, + onLongPress: cell.onLongPress, + onTapCancel: cell.onTapCancel, + onTapDown: cell.onTapDown, + onSelectChanged: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected), + overlayColor: row.color ?? effectiveDataRowColor, + onRowLongPress: row.onLongPress, + mouseCursor: row.mouseCursor?.resolve(states) ?? dataTableTheme.dataRowCursor?.resolve(states), + ); + rowIndex += 1; + } + displayColumnIndex += 1; + } + + return Container( + decoration: decoration ?? dataTableTheme.decoration ?? theme.dataTableTheme.decoration, + child: Material( + type: MaterialType.transparency, + borderRadius: border?.borderRadius, + clipBehavior: clipBehavior, + child: Table( + columnWidths: tableColumns.asMap(), + defaultVerticalAlignment: TableCellVerticalAlignment.middle, + children: tableRows, + border: border, + ), + ), + ); + } +} + +/// A rectangular area of a Material that responds to touch but clips +/// its ink splashes to the current table row of the nearest table. +/// +/// Must have an ancestor [Material] widget in which to cause ink +/// reactions and an ancestor [Table] widget to establish a row. +/// +/// The [TableRowInkWell] must be in the same coordinate space (modulo +/// translations) as the [Table]. If it's rotated or scaled or +/// otherwise transformed, it will not be able to describe the +/// rectangle of the row in its own coordinate system as a [Rect], and +/// thus the splash will not occur. (In general, this is easy to +/// achieve: just put the [TableRowInkWell] as the direct child of the +/// [Table], and put the other contents of the cell inside it.) +/// +/// See also: +/// +/// * [DataTable], which makes use of [TableRowInkWell] when +/// [DataRow.onSelectChanged] is defined and [DataCell.onTap] +/// is not. +class TableRowInkWell extends InkResponse { + /// Creates an ink well for a table row. + const TableRowInkWell({ + super.key, + super.child, + super.onTap, + super.onDoubleTap, + super.onLongPress, + super.onHighlightChanged, + super.onSecondaryTap, + super.onSecondaryTapDown, + super.overlayColor, + super.mouseCursor, + }) : super( + containedInkWell: true, + highlightShape: BoxShape.rectangle, + ); + + @override + RectCallback getRectCallback(RenderBox referenceBox) { + return () { + RenderObject cell = referenceBox; + RenderObject? table = cell.parent; + final Matrix4 transform = Matrix4.identity(); + while (table is RenderObject && table is! RenderTable) { + table.applyPaintTransform(cell, transform); + assert(table == cell.parent); + cell = table; + table = table.parent; + } + if (table is RenderTable) { + final TableCellParentData cellParentData = cell.parentData! as TableCellParentData; + assert(cellParentData.y != null); + final Rect rect = table.getRowBox(cellParentData.y!); + // The rect is in the table's coordinate space. We need to change it to the + // TableRowInkWell's coordinate space. + table.applyPaintTransform(cell, transform); + final Offset? offset = MatrixUtils.getAsTranslation(transform); + if (offset != null) { + return rect.shift(-offset); + } + } + return Rect.zero; + }; + } + + @override + bool debugCheckContext(BuildContext context) { + assert(debugCheckHasTable(context)); + return super.debugCheckContext(context); + } +} + +class _SortArrow extends StatefulWidget { + const _SortArrow({ + required this.visible, + required this.up, + required this.duration, + }); + + final bool visible; + + final bool? up; + + final Duration duration; + + @override + _SortArrowState createState() => _SortArrowState(); +} + +class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin { + late AnimationController _opacityController; + late Animation<double> _opacityAnimation; + + late AnimationController _orientationController; + late Animation<double> _orientationAnimation; + double _orientationOffset = 0.0; + + bool? _up; + + static final Animatable<double> _turnTween = Tween<double>(begin: 0.0, end: math.pi) + .chain(CurveTween(curve: Curves.easeIn)); + + @override + void initState() { + super.initState(); + _up = widget.up; + _opacityAnimation = CurvedAnimation( + parent: _opacityController = AnimationController( + duration: widget.duration, + vsync: this, + ), + curve: Curves.fastOutSlowIn, + ) + ..addListener(_rebuild); + _opacityController.value = widget.visible ? 1.0 : 0.0; + _orientationController = AnimationController( + duration: widget.duration, + vsync: this, + ); + _orientationAnimation = _orientationController.drive(_turnTween) + ..addListener(_rebuild) + ..addStatusListener(_resetOrientationAnimation); + if (widget.visible) { + _orientationOffset = widget.up! ? 0.0 : math.pi; + } + } + + void _rebuild() { + setState(() { + // The animations changed, so we need to rebuild. + }); + } + + void _resetOrientationAnimation(AnimationStatus status) { + if (status == AnimationStatus.completed) { + assert(_orientationAnimation.value == math.pi); + _orientationOffset += math.pi; + _orientationController.value = 0.0; // TODO(ianh): This triggers a pointless rebuild. + } + } + + @override + void didUpdateWidget(_SortArrow oldWidget) { + super.didUpdateWidget(oldWidget); + bool skipArrow = false; + final bool? newUp = widget.up ?? _up; + if (oldWidget.visible != widget.visible) { + if (widget.visible && (_opacityController.status == AnimationStatus.dismissed)) { + _orientationController.stop(); + _orientationController.value = 0.0; + _orientationOffset = newUp! ? 0.0 : math.pi; + skipArrow = true; + } + if (widget.visible) { + _opacityController.forward(); + } else { + _opacityController.reverse(); + } + } + if ((_up != newUp) && !skipArrow) { + if (_orientationController.status == AnimationStatus.dismissed) { + _orientationController.forward(); + } else { + _orientationController.reverse(); + } + } + _up = newUp; + } + + @override + void dispose() { + _opacityController.dispose(); + _orientationController.dispose(); + super.dispose(); + } + + static const double _arrowIconBaselineOffset = -1.5; + static const double _arrowIconSize = 16.0; + + @override + Widget build(BuildContext context) { + return FadeTransition( + opacity: _opacityAnimation, + child: Transform( + transform: Matrix4.rotationZ(_orientationOffset + _orientationAnimation.value) + ..setTranslationRaw(0.0, _arrowIconBaselineOffset, 0.0), + alignment: Alignment.center, + child: const Icon( + Icons.arrow_upward, + size: _arrowIconSize, + ), + ), + ); + } +} + +class _NullTableColumnWidth extends TableColumnWidth { + const _NullTableColumnWidth(); + + @override + double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) => throw UnimplementedError(); + + @override + double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) => throw UnimplementedError(); +} + +class _NullWidget extends Widget { + const _NullWidget(); + + @override + Element createElement() => throw UnimplementedError(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/data_table_source.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/data_table_source.dart new file mode 100644 index 0000000000000000000000000000000000000000..7b51441f96f27fa98886d187d37c7cf13a8398d0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/data_table_source.dart @@ -0,0 +1,75 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'data_table.dart'; + +/// A data source for obtaining row data for [PaginatedDataTable] objects. +/// +/// A data table source provides two main pieces of information: +/// +/// * The number of rows in the data table ([rowCount]). +/// * The data for each row (indexed from `0` to `rowCount - 1`). +/// +/// It also provides a listener API ([addListener]/[removeListener]) so that +/// consumers of the data can be notified when it changes. When the data +/// changes, call [notifyListeners] to send the notifications. +/// +/// DataTableSource objects are expected to be long-lived, not recreated with +/// each build. +/// +/// If a [DataTableSource] is used with a [PaginatedDataTable] that supports +/// sortable columns (see [DataColumn.onSort] and +/// [PaginatedDataTable.sortColumnIndex]), the rows reported by the data source +/// must be reported in the sorted order. +abstract class DataTableSource extends ChangeNotifier { + /// Called to obtain the data about a particular row. + /// + /// Rows should be keyed so that state can be maintained when the data source + /// is sorted (e.g. in response to [DataColumn.onSort]). Keys should be + /// consistent for a given [DataRow] regardless of the sort order (i.e. the + /// key represents the data's identity, not the row position). + /// + /// The [DataRow.byIndex] constructor provides a convenient way to construct + /// [DataRow] objects for this method's purposes without having to worry about + /// independently keying each row. The index passed to that constructor is the + /// index of the underlying data, which is different than the `index` + /// parameter for [getRow], which represents the _sorted_ position. + /// + /// If the given index does not correspond to a row, or if no data is yet + /// available for a row, then return null. The row will be left blank and a + /// loading indicator will be displayed over the table. Once data is available + /// or once it is firmly established that the row index in question is beyond + /// the end of the table, call [notifyListeners]. (See [rowCount].) + /// + /// If the underlying data changes, call [notifyListeners]. + DataRow? getRow(int index); + + /// Called to obtain the number of rows to tell the user are available. + /// + /// If [isRowCountApproximate] is false, then this must be an accurate number, + /// and [getRow] must return a non-null value for all indices in the range 0 + /// to one less than the row count. + /// + /// If [isRowCountApproximate] is true, then the user will be allowed to + /// attempt to display rows up to this [rowCount], and the display will + /// indicate that the count is approximate. The row count should therefore be + /// greater than the actual number of rows if at all possible. + /// + /// If the row count changes, call [notifyListeners]. + int get rowCount; + + /// Called to establish if [rowCount] is a precise number or might be an + /// over-estimate. If this returns true (i.e. the count is approximate), and + /// then later the exact number becomes available, then call + /// [notifyListeners]. + bool get isRowCountApproximate; + + /// Called to obtain the number of rows that are currently selected. + /// + /// If the selected row count changes, call [notifyListeners]. + /// + /// Selected rows are those whose [DataRow.selected] property is set to true. + int get selectedRowCount; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/data_table_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/data_table_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..fb2bb96b00565635f5d2e27236fc30833910363b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/data_table_theme.dart @@ -0,0 +1,293 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [DataTable] +/// widgets. +/// +/// Descendant widgets obtain the current [DataTableThemeData] object +/// using `DataTableTheme.of(context)`. Instances of +/// [DataTableThemeData] can be customized with +/// [DataTableThemeData.copyWith]. +/// +/// Typically a [DataTableThemeData] is specified as part of the +/// overall [Theme] with [ThemeData.dataTableTheme]. +/// +/// All [DataTableThemeData] properties are `null` by default. When +/// null, the [DataTable] will use the values from [ThemeData] if they exist, +/// otherwise it will provide its own defaults based on the overall [Theme]'s +/// textTheme and colorScheme. See the individual [DataTable] properties for +/// details. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class DataTableThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.dataTableTheme]. + const DataTableThemeData({ + this.decoration, + this.dataRowColor, + @Deprecated( + 'Migrate to use dataRowMinHeight and dataRowMaxHeight instead. ' + 'This feature was deprecated after v3.7.0-5.0.pre.', + ) + double? dataRowHeight, + double? dataRowMinHeight, + double? dataRowMaxHeight, + this.dataTextStyle, + this.headingRowColor, + this.headingRowHeight, + this.headingTextStyle, + this.horizontalMargin, + this.columnSpacing, + this.dividerThickness, + this.checkboxHorizontalMargin, + this.headingCellCursor, + this.dataRowCursor, + }) : assert(dataRowMinHeight == null || dataRowMaxHeight == null || dataRowMaxHeight >= dataRowMinHeight), + assert(dataRowHeight == null || (dataRowMinHeight == null && dataRowMaxHeight == null), + 'dataRowHeight ($dataRowHeight) must not be set if dataRowMinHeight ($dataRowMinHeight) or dataRowMaxHeight ($dataRowMaxHeight) are set.'), + dataRowMinHeight = dataRowHeight ?? dataRowMinHeight, + dataRowMaxHeight = dataRowHeight ?? dataRowMaxHeight; + + /// {@macro flutter.material.dataTable.decoration} + final Decoration? decoration; + + /// {@macro flutter.material.dataTable.dataRowColor} + /// {@macro flutter.material.DataTable.dataRowColor} + final MaterialStateProperty<Color?>? dataRowColor; + + /// {@macro flutter.material.dataTable.dataRowHeight} + @Deprecated( + 'Migrate to use dataRowMinHeight and dataRowMaxHeight instead. ' + 'This feature was deprecated after v3.7.0-5.0.pre.', + ) + double? get dataRowHeight => dataRowMinHeight == dataRowMaxHeight ? dataRowMinHeight : null; + + /// {@macro flutter.material.dataTable.dataRowMinHeight} + final double? dataRowMinHeight; + + /// {@macro flutter.material.dataTable.dataRowMaxHeight} + final double? dataRowMaxHeight; + + /// {@macro flutter.material.dataTable.dataTextStyle} + final TextStyle? dataTextStyle; + + /// {@macro flutter.material.dataTable.headingRowColor} + /// {@macro flutter.material.DataTable.headingRowColor} + final MaterialStateProperty<Color?>? headingRowColor; + + /// {@macro flutter.material.dataTable.headingRowHeight} + final double? headingRowHeight; + + /// {@macro flutter.material.dataTable.headingTextStyle} + final TextStyle? headingTextStyle; + + /// {@macro flutter.material.dataTable.horizontalMargin} + final double? horizontalMargin; + + /// {@macro flutter.material.dataTable.columnSpacing} + final double? columnSpacing; + + /// {@macro flutter.material.dataTable.dividerThickness} + final double? dividerThickness; + + /// {@macro flutter.material.dataTable.checkboxHorizontalMargin} + final double? checkboxHorizontalMargin; + + /// If specified, overrides the default value of [DataColumn.mouseCursor]. + final MaterialStateProperty<MouseCursor?>? headingCellCursor; + + /// If specified, overrides the default value of [DataRow.mouseCursor]. + final MaterialStateProperty<MouseCursor?>? dataRowCursor; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + DataTableThemeData copyWith({ + Decoration? decoration, + MaterialStateProperty<Color?>? dataRowColor, + @Deprecated( + 'Migrate to use dataRowMinHeight and dataRowMaxHeight instead. ' + 'This feature was deprecated after v3.7.0-5.0.pre.', + ) + double? dataRowHeight, + double? dataRowMinHeight, + double? dataRowMaxHeight, + TextStyle? dataTextStyle, + MaterialStateProperty<Color?>? headingRowColor, + double? headingRowHeight, + TextStyle? headingTextStyle, + double? horizontalMargin, + double? columnSpacing, + double? dividerThickness, + double? checkboxHorizontalMargin, + MaterialStateProperty<MouseCursor?>? headingCellCursor, + MaterialStateProperty<MouseCursor?>? dataRowCursor, + }) { + assert(dataRowHeight == null || (dataRowMinHeight == null && dataRowMaxHeight == null), + 'dataRowHeight ($dataRowHeight) must not be set if dataRowMinHeight ($dataRowMinHeight) or dataRowMaxHeight ($dataRowMaxHeight) are set.'); + dataRowMinHeight = dataRowHeight ?? dataRowMinHeight; + dataRowMaxHeight = dataRowHeight ?? dataRowMaxHeight; + + return DataTableThemeData( + decoration: decoration ?? this.decoration, + dataRowColor: dataRowColor ?? this.dataRowColor, + dataRowMinHeight: dataRowMinHeight ?? this.dataRowMinHeight, + dataRowMaxHeight: dataRowMaxHeight ?? this.dataRowMaxHeight, + dataTextStyle: dataTextStyle ?? this.dataTextStyle, + headingRowColor: headingRowColor ?? this.headingRowColor, + headingRowHeight: headingRowHeight ?? this.headingRowHeight, + headingTextStyle: headingTextStyle ?? this.headingTextStyle, + horizontalMargin: horizontalMargin ?? this.horizontalMargin, + columnSpacing: columnSpacing ?? this.columnSpacing, + dividerThickness: dividerThickness ?? this.dividerThickness, + checkboxHorizontalMargin: checkboxHorizontalMargin ?? this.checkboxHorizontalMargin, + headingCellCursor: headingCellCursor ?? this.headingCellCursor, + dataRowCursor: dataRowCursor ?? this.dataRowCursor, + ); + } + + /// Linearly interpolate between two [DataTableThemeData]s. + /// + /// {@macro dart.ui.shadow.lerp} + static DataTableThemeData lerp(DataTableThemeData a, DataTableThemeData b, double t) { + if (identical(a, b)) { + return a; + } + return DataTableThemeData( + decoration: Decoration.lerp(a.decoration, b.decoration, t), + dataRowColor: MaterialStateProperty.lerp<Color?>(a.dataRowColor, b.dataRowColor, t, Color.lerp), + dataRowMinHeight: lerpDouble(a.dataRowMinHeight, b.dataRowMinHeight, t), + dataRowMaxHeight: lerpDouble(a.dataRowMaxHeight, b.dataRowMaxHeight, t), + dataTextStyle: TextStyle.lerp(a.dataTextStyle, b.dataTextStyle, t), + headingRowColor: MaterialStateProperty.lerp<Color?>(a.headingRowColor, b.headingRowColor, t, Color.lerp), + headingRowHeight: lerpDouble(a.headingRowHeight, b.headingRowHeight, t), + headingTextStyle: TextStyle.lerp(a.headingTextStyle, b.headingTextStyle, t), + horizontalMargin: lerpDouble(a.horizontalMargin, b.horizontalMargin, t), + columnSpacing: lerpDouble(a.columnSpacing, b.columnSpacing, t), + dividerThickness: lerpDouble(a.dividerThickness, b.dividerThickness, t), + checkboxHorizontalMargin: lerpDouble(a.checkboxHorizontalMargin, b.checkboxHorizontalMargin, t), + headingCellCursor: t < 0.5 ? a.headingCellCursor : b.headingCellCursor, + dataRowCursor: t < 0.5 ? a.dataRowCursor : b.dataRowCursor, + ); + } + + @override + int get hashCode => Object.hash( + decoration, + dataRowColor, + dataRowMinHeight, + dataRowMaxHeight, + dataTextStyle, + headingRowColor, + headingRowHeight, + headingTextStyle, + horizontalMargin, + columnSpacing, + dividerThickness, + checkboxHorizontalMargin, + headingCellCursor, + dataRowCursor, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is DataTableThemeData + && other.decoration == decoration + && other.dataRowColor == dataRowColor + && other.dataRowMinHeight == dataRowMinHeight + && other.dataRowMaxHeight == dataRowMaxHeight + && other.dataTextStyle == dataTextStyle + && other.headingRowColor == headingRowColor + && other.headingRowHeight == headingRowHeight + && other.headingTextStyle == headingTextStyle + && other.horizontalMargin == horizontalMargin + && other.columnSpacing == columnSpacing + && other.dividerThickness == dividerThickness + && other.checkboxHorizontalMargin == checkboxHorizontalMargin + && other.headingCellCursor == headingCellCursor + && other.dataRowCursor == dataRowCursor; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Decoration>('decoration', decoration, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('dataRowColor', dataRowColor, defaultValue: null)); + properties.add(DoubleProperty('dataRowMinHeight', dataRowMinHeight, defaultValue: null)); + properties.add(DoubleProperty('dataRowMaxHeight', dataRowMaxHeight, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('dataTextStyle', dataTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('headingRowColor', headingRowColor, defaultValue: null)); + properties.add(DoubleProperty('headingRowHeight', headingRowHeight, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('headingTextStyle', headingTextStyle, defaultValue: null)); + properties.add(DoubleProperty('horizontalMargin', horizontalMargin, defaultValue: null)); + properties.add(DoubleProperty('columnSpacing', columnSpacing, defaultValue: null)); + properties.add(DoubleProperty('dividerThickness', dividerThickness, defaultValue: null)); + properties.add(DoubleProperty('checkboxHorizontalMargin', checkboxHorizontalMargin, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>?>('headingCellCursor', headingCellCursor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>?>('dataRowCursor', dataRowCursor, defaultValue: null)); + } +} + +/// Applies a data table theme to descendant [DataTable] widgets. +/// +/// Descendant widgets obtain the current theme's [DataTableTheme] object using +/// [DataTableTheme.of]. When a widget uses [DataTableTheme.of], it is +/// automatically rebuilt if the theme later changes. +/// +/// A data table theme can be specified as part of the overall Material +/// theme using [ThemeData.dataTableTheme]. +/// +/// See also: +/// +/// * [DataTableThemeData], which describes the actual configuration +/// of a data table theme. +class DataTableTheme extends InheritedWidget { + /// Constructs a data table theme that configures all descendant + /// [DataTable] widgets. + const DataTableTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties used for all descendant [DataTable] widgets. + final DataTableThemeData data; + + /// Returns the configuration [data] from the closest + /// [DataTableTheme] ancestor. If there is no ancestor, it returns + /// [ThemeData.dataTableTheme]. Applications can assume that the + /// returned value will not be null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// DataTableThemeData theme = DataTableTheme.of(context); + /// ``` + static DataTableThemeData of(BuildContext context) { + final DataTableTheme? dataTableTheme = context.dependOnInheritedWidgetOfExactType<DataTableTheme>(); + return dataTableTheme?.data ?? Theme.of(context).dataTableTheme; + } + + @override + bool updateShouldNotify(DataTableTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/date.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/date.dart new file mode 100644 index 0000000000000000000000000000000000000000..b6e00827b7272e0ce72515e7dd075e44bd81552f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/date.dart @@ -0,0 +1,239 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'material_localizations.dart'; + +/// Utility functions for working with dates. +abstract final class DateUtils { + /// Returns a [DateTime] with the date of the original, but time set to + /// midnight. + static DateTime dateOnly(DateTime date) { + return DateTime(date.year, date.month, date.day); + } + + /// Returns a [DateTimeRange] with the dates of the original, but with times + /// set to midnight. + /// + /// See also: + /// * [dateOnly], which does the same thing for a single date. + static DateTimeRange datesOnly(DateTimeRange range) { + return DateTimeRange(start: dateOnly(range.start), end: dateOnly(range.end)); + } + + /// Returns true if the two [DateTime] objects have the same day, month, and + /// year, or are both null. + static bool isSameDay(DateTime? dateA, DateTime? dateB) { + return + dateA?.year == dateB?.year && + dateA?.month == dateB?.month && + dateA?.day == dateB?.day; + } + + /// Returns true if the two [DateTime] objects have the same month and + /// year, or are both null. + static bool isSameMonth(DateTime? dateA, DateTime? dateB) { + return + dateA?.year == dateB?.year && + dateA?.month == dateB?.month; + } + + /// Determines the number of months between two [DateTime] objects. + /// + /// For example: + /// + /// ```dart + /// DateTime date1 = DateTime(2019, 6, 15); + /// DateTime date2 = DateTime(2020, 1, 15); + /// int delta = DateUtils.monthDelta(date1, date2); + /// ``` + /// + /// The value for `delta` would be `7`. + static int monthDelta(DateTime startDate, DateTime endDate) { + return (endDate.year - startDate.year) * 12 + endDate.month - startDate.month; + } + + /// Returns a [DateTime] that is [monthDate] with the added number + /// of months and the day set to 1 and time set to midnight. + /// + /// For example: + /// + /// ```dart + /// DateTime date = DateTime(2019, 1, 15); + /// DateTime futureDate = DateUtils.addMonthsToMonthDate(date, 3); + /// ``` + /// + /// `date` would be January 15, 2019. + /// `futureDate` would be April 1, 2019 since it adds 3 months. + static DateTime addMonthsToMonthDate(DateTime monthDate, int monthsToAdd) { + return DateTime(monthDate.year, monthDate.month + monthsToAdd); + } + + /// Returns a [DateTime] with the added number of days and time set to + /// midnight. + static DateTime addDaysToDate(DateTime date, int days) { + return DateTime(date.year, date.month, date.day + days); + } + + /// Computes the offset from the first day of the week that the first day of + /// the [month] falls on. + /// + /// For example, September 1, 2017 falls on a Friday, which in the calendar + /// localized for United States English appears as: + /// + /// S M T W T F S + /// _ _ _ _ _ 1 2 + /// + /// The offset for the first day of the months is the number of leading blanks + /// in the calendar, i.e. 5. + /// + /// The same date localized for the Russian calendar has a different offset, + /// because the first day of week is Monday rather than Sunday: + /// + /// M T W T F S S + /// _ _ _ _ 1 2 3 + /// + /// So the offset is 4, rather than 5. + /// + /// This code consolidates the following: + /// + /// - [DateTime.weekday] provides a 1-based index into days of week, with 1 + /// falling on Monday. + /// - [MaterialLocalizations.firstDayOfWeekIndex] provides a 0-based index + /// into the [MaterialLocalizations.narrowWeekdays] list. + /// - [MaterialLocalizations.narrowWeekdays] list provides localized names of + /// days of week, always starting with Sunday and ending with Saturday. + static int firstDayOffset(int year, int month, MaterialLocalizations localizations) { + // 0-based day of week for the month and year, with 0 representing Monday. + final int weekdayFromMonday = DateTime(year, month).weekday - 1; + + // 0-based start of week depending on the locale, with 0 representing Sunday. + int firstDayOfWeekIndex = localizations.firstDayOfWeekIndex; + + // firstDayOfWeekIndex recomputed to be Monday-based, in order to compare with + // weekdayFromMonday. + firstDayOfWeekIndex = (firstDayOfWeekIndex - 1) % 7; + + // Number of days between the first day of week appearing on the calendar, + // and the day corresponding to the first of the month. + return (weekdayFromMonday - firstDayOfWeekIndex) % 7; + } + + /// Returns the number of days in a month, according to the proleptic + /// Gregorian calendar. + /// + /// This applies the leap year logic introduced by the Gregorian reforms of + /// 1582. It will not give valid results for dates prior to that time. + static int getDaysInMonth(int year, int month) { + if (month == DateTime.february) { + final bool isLeapYear = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0); + return isLeapYear ? 29 : 28; + } + const List<int> daysInMonth = <int>[31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + return daysInMonth[month - 1]; + } +} + +/// Mode of date entry method for the date picker dialog. +/// +/// In [calendar] mode, a calendar grid is displayed and the user taps the +/// day they wish to select. In [input] mode a TextField] is displayed and +/// the user types in the date they wish to select. +/// +/// [calendarOnly] and [inputOnly] are variants of the above that don't +/// allow the user to change to the mode. +/// +/// See also: +/// +/// * [showDatePicker] and [showDateRangePicker], which use this to control +/// the initial entry mode of their dialogs. +enum DatePickerEntryMode { + /// User picks a date from calendar grid. Can switch to [input] by activating + /// a mode button in the dialog. + calendar, + + /// User can input the date by typing it into a text field. + /// + /// Can switch to [calendar] by activating a mode button in the dialog. + input, + + /// User can only pick a date from calendar grid. + /// + /// There is no user interface to switch to another mode. + calendarOnly, + + /// User can only input the date by typing it into a text field. + /// + /// There is no user interface to switch to another mode. + inputOnly, +} + +/// Initial display of a calendar date picker. +/// +/// Either a grid of available years or a monthly calendar. +/// +/// See also: +/// +/// * [showDatePicker], which shows a dialog that contains a Material Design +/// date picker. +/// * [CalendarDatePicker], widget which implements the Material Design date picker. +enum DatePickerMode { + /// Choosing a month and day. + day, + + /// Choosing a year. + year, +} + +/// Signature for predicating dates for enabled date selections. +/// +/// See [showDatePicker], which has a [SelectableDayPredicate] parameter used +/// to specify allowable days in the date picker. +typedef SelectableDayPredicate = bool Function(DateTime day); + +/// Encapsulates a start and end [DateTime] that represent the range of dates. +/// +/// The range includes the [start] and [end] dates. The [start] and [end] dates +/// may be equal to indicate a date range of a single day. The [start] date must +/// not be after the [end] date. +/// +/// See also: +/// * [showDateRangePicker], which displays a dialog that allows the user to +/// select a date range. +@immutable +class DateTimeRange { + /// Creates a date range for the given start and end [DateTime]. + DateTimeRange({ + required this.start, + required this.end, + }) : assert(!start.isAfter(end)); + + /// The start of the range of dates. + final DateTime start; + + /// The end of the range of dates. + final DateTime end; + + /// Returns a [Duration] of the time between [start] and [end]. + /// + /// See [DateTime.difference] for more details. + Duration get duration => end.difference(start); + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is DateTimeRange + && other.start == start + && other.end == end; + } + + @override + int get hashCode => Object.hash(start, end); + + @override + String toString() => '$start - $end'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/date_picker.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/date_picker.dart new file mode 100644 index 0000000000000000000000000000000000000000..9681370a5281aedac2ae7e46476524d9683e2b55 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/date_picker.dart @@ -0,0 +1,3173 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'app_bar.dart'; +import 'back_button.dart'; +import 'button_style.dart'; +import 'calendar_date_picker.dart'; +import 'color_scheme.dart'; +import 'date.dart'; +import 'date_picker_theme.dart'; +import 'debug.dart'; +import 'dialog.dart'; +import 'dialog_theme.dart'; +import 'divider.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'input_border.dart'; +import 'input_date_picker_form_field.dart'; +import 'input_decorator.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'scaffold.dart'; +import 'text_button.dart'; +import 'text_field.dart'; +import 'text_theme.dart'; +import 'theme.dart'; + +// The M3 sizes are coming from the tokens, but are hand coded, +// as the current token DB does not contain landscape versions. +const Size _calendarPortraitDialogSizeM2 = Size(330.0, 518.0); +const Size _calendarPortraitDialogSizeM3 = Size(328.0, 512.0); +const Size _calendarLandscapeDialogSize = Size(496.0, 346.0); +const Size _inputPortraitDialogSizeM2 = Size(330.0, 270.0); +const Size _inputPortraitDialogSizeM3 = Size(328.0, 270.0); +const Size _inputLandscapeDialogSize = Size(496, 160.0); +const Size _inputRangeLandscapeDialogSize = Size(496, 164.0); +const Duration _dialogSizeAnimationDuration = Duration(milliseconds: 200); +const double _inputFormPortraitHeight = 98.0; +const double _inputFormLandscapeHeight = 108.0; +const double _kMaxTextScaleFactor = 1.3; + +/// Shows a dialog containing a Material Design date picker. +/// +/// The returned [Future] resolves to the date selected by the user when the +/// user confirms the dialog. If the user cancels the dialog, null is returned. +/// +/// When the date picker is first displayed, if [initialDate] is not null, it +/// will show the month of [initialDate], with [initialDate] selected. Otherwise +/// it will show the [currentDate]'s month. +/// +/// The [firstDate] is the earliest allowable date. The [lastDate] is the latest +/// allowable date. If [initialDate] is not null, it must either fall between +/// these dates, or be equal to one of them. For each of these [DateTime] +/// parameters, only their dates are considered. Their time fields are ignored. +/// They must all be non-null. +/// +/// The [currentDate] represents the current day (i.e. today). This +/// date will be highlighted in the day grid. If null, the date of +/// [DateTime.now] will be used. +/// +/// An optional [initialEntryMode] argument can be used to display the date +/// picker in the [DatePickerEntryMode.calendar] (a calendar month grid) +/// or [DatePickerEntryMode.input] (a text input field) mode. +/// It defaults to [DatePickerEntryMode.calendar]. +/// +/// {@template flutter.material.date_picker.switchToInputEntryModeIcon} +/// An optional [switchToInputEntryModeIcon] argument can be used to +/// display a custom Icon in the corner of the dialog +/// when [DatePickerEntryMode] is [DatePickerEntryMode.calendar]. Clicking on +/// icon changes the [DatePickerEntryMode] to [DatePickerEntryMode.input]. +/// If null, `Icon(useMaterial3 ? Icons.edit_outlined : Icons.edit)` is used. +/// {@endtemplate} +/// +/// {@template flutter.material.date_picker.switchToCalendarEntryModeIcon} +/// An optional [switchToCalendarEntryModeIcon] argument can be used to +/// display a custom Icon in the corner of the dialog +/// when [DatePickerEntryMode] is [DatePickerEntryMode.input]. Clicking on +/// icon changes the [DatePickerEntryMode] to [DatePickerEntryMode.calendar]. +/// If null, `Icon(Icons.calendar_today)` is used. +/// {@endtemplate} +/// +/// An optional [selectableDayPredicate] function can be passed in to only allow +/// certain days for selection. If provided, only the days that +/// [selectableDayPredicate] returns true for will be selectable. For example, +/// this can be used to only allow weekdays for selection. If provided, it must +/// return true for [initialDate]. +/// +/// The following optional string parameters allow you to override the default +/// text used for various parts of the dialog: +/// +/// * [helpText], label displayed at the top of the dialog. +/// * [cancelText], label on the cancel button. +/// * [confirmText], label on the ok button. +/// * [errorFormatText], message used when the input text isn't in a proper date format. +/// * [errorInvalidText], message used when the input text isn't a selectable date. +/// * [fieldHintText], text used to prompt the user when no text has been entered in the field. +/// * [fieldLabelText], label for the date text input field. +/// +/// An optional [locale] argument can be used to set the locale for the date +/// picker. It defaults to the ambient locale provided by [Localizations]. +/// +/// An optional [textDirection] argument can be used to set the text direction +/// ([TextDirection.ltr] or [TextDirection.rtl]) for the date picker. It +/// defaults to the ambient text direction provided by [Directionality]. If both +/// [locale] and [textDirection] are non-null, [textDirection] overrides the +/// direction chosen for the [locale]. +/// +/// The [context], [barrierDismissible], [barrierColor], [barrierLabel], +/// [useRootNavigator] and [routeSettings] arguments are passed to [showDialog], +/// the documentation for which discusses how it is used. +/// +/// The [builder] parameter can be used to wrap the dialog widget +/// to add inherited widgets like [Theme]. +/// +/// An optional [initialDatePickerMode] argument can be used to have the +/// calendar date picker initially appear in the [DatePickerMode.year] or +/// [DatePickerMode.day] mode. It defaults to [DatePickerMode.day]. +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// ### State Restoration +/// +/// Using this method will not enable state restoration for the date picker. +/// In order to enable state restoration for a date picker, use +/// [Navigator.restorablePush] or [Navigator.restorablePushNamed] with +/// [DatePickerDialog]. +/// +/// For more information about state restoration, see [RestorationManager]. +/// +/// {@macro flutter.widgets.RestorationManager} +/// +/// {@tool dartpad} +/// This sample demonstrates how to create a restorable Material date picker. +/// This is accomplished by enabling state restoration by specifying +/// [MaterialApp.restorationScopeId] and using [Navigator.restorablePush] to +/// push [DatePickerDialog] when the button is tapped. +/// +/// ** See code in examples/api/lib/material/date_picker/show_date_picker.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [showDateRangePicker], which shows a Material Design date range picker +/// used to select a range of dates. +/// * [CalendarDatePicker], which provides the calendar grid used by the date picker dialog. +/// * [InputDatePickerFormField], which provides a text input field for entering dates. +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +/// * [showTimePicker], which shows a dialog that contains a Material Design time picker. +Future<DateTime?> showDatePicker({ + required BuildContext context, + DateTime? initialDate, + required DateTime firstDate, + required DateTime lastDate, + DateTime? currentDate, + DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar, + SelectableDayPredicate? selectableDayPredicate, + String? helpText, + String? cancelText, + String? confirmText, + Locale? locale, + bool barrierDismissible = true, + Color? barrierColor, + String? barrierLabel, + bool useRootNavigator = true, + RouteSettings? routeSettings, + TextDirection? textDirection, + TransitionBuilder? builder, + DatePickerMode initialDatePickerMode = DatePickerMode.day, + String? errorFormatText, + String? errorInvalidText, + String? fieldHintText, + String? fieldLabelText, + TextInputType? keyboardType, + Offset? anchorPoint, + final ValueChanged<DatePickerEntryMode>? onDatePickerModeChange, + final Icon? switchToInputEntryModeIcon, + final Icon? switchToCalendarEntryModeIcon, +}) async { + initialDate = initialDate == null ? null : DateUtils.dateOnly(initialDate); + firstDate = DateUtils.dateOnly(firstDate); + lastDate = DateUtils.dateOnly(lastDate); + assert( + !lastDate.isBefore(firstDate), + 'lastDate $lastDate must be on or after firstDate $firstDate.', + ); + assert( + initialDate == null || !initialDate.isBefore(firstDate), + 'initialDate $initialDate must be on or after firstDate $firstDate.', + ); + assert( + initialDate == null || !initialDate.isAfter(lastDate), + 'initialDate $initialDate must be on or before lastDate $lastDate.', + ); + assert( + selectableDayPredicate == null || initialDate == null || selectableDayPredicate(initialDate), + 'Provided initialDate $initialDate must satisfy provided selectableDayPredicate.', + ); + assert(debugCheckHasMaterialLocalizations(context)); + + Widget dialog = DatePickerDialog( + initialDate: initialDate, + firstDate: firstDate, + lastDate: lastDate, + currentDate: currentDate, + initialEntryMode: initialEntryMode, + selectableDayPredicate: selectableDayPredicate, + helpText: helpText, + cancelText: cancelText, + confirmText: confirmText, + initialCalendarMode: initialDatePickerMode, + errorFormatText: errorFormatText, + errorInvalidText: errorInvalidText, + fieldHintText: fieldHintText, + fieldLabelText: fieldLabelText, + keyboardType: keyboardType, + onDatePickerModeChange: onDatePickerModeChange, + switchToInputEntryModeIcon: switchToInputEntryModeIcon, + switchToCalendarEntryModeIcon: switchToCalendarEntryModeIcon, + ); + + if (textDirection != null) { + dialog = Directionality( + textDirection: textDirection, + child: dialog, + ); + } + + if (locale != null) { + dialog = Localizations.override( + context: context, + locale: locale, + child: dialog, + ); + } + + return showDialog<DateTime>( + context: context, + barrierDismissible: barrierDismissible, + barrierColor: barrierColor, + barrierLabel: barrierLabel, + useRootNavigator: useRootNavigator, + routeSettings: routeSettings, + builder: (BuildContext context) { + return builder == null ? dialog : builder(context, dialog); + }, + anchorPoint: anchorPoint, + ); +} + +/// A Material-style date picker dialog. +/// +/// It is used internally by [showDatePicker] or can be directly pushed +/// onto the [Navigator] stack to enable state restoration. See +/// [showDatePicker] for a state restoration app example. +/// +/// See also: +/// +/// * [showDatePicker], which is a way to display the date picker. +class DatePickerDialog extends StatefulWidget { + /// A Material-style date picker dialog. + DatePickerDialog({ + super.key, + DateTime? initialDate, + required DateTime firstDate, + required DateTime lastDate, + DateTime? currentDate, + this.initialEntryMode = DatePickerEntryMode.calendar, + this.selectableDayPredicate, + this.cancelText, + this.confirmText, + this.helpText, + this.initialCalendarMode = DatePickerMode.day, + this.errorFormatText, + this.errorInvalidText, + this.fieldHintText, + this.fieldLabelText, + this.keyboardType, + this.restorationId, + this.onDatePickerModeChange, + this.switchToInputEntryModeIcon, + this.switchToCalendarEntryModeIcon, + }) : initialDate = initialDate == null ? null : DateUtils.dateOnly(initialDate), + firstDate = DateUtils.dateOnly(firstDate), + lastDate = DateUtils.dateOnly(lastDate), + currentDate = DateUtils.dateOnly(currentDate ?? DateTime.now()) { + assert( + !this.lastDate.isBefore(this.firstDate), + 'lastDate ${this.lastDate} must be on or after firstDate ${this.firstDate}.', + ); + assert( + initialDate == null || !this.initialDate!.isBefore(this.firstDate), + 'initialDate ${this.initialDate} must be on or after firstDate ${this.firstDate}.', + ); + assert( + initialDate == null || !this.initialDate!.isAfter(this.lastDate), + 'initialDate ${this.initialDate} must be on or before lastDate ${this.lastDate}.', + ); + assert( + selectableDayPredicate == null || initialDate == null || selectableDayPredicate!(this.initialDate!), + 'Provided initialDate ${this.initialDate} must satisfy provided selectableDayPredicate', + ); + } + + /// The initially selected [DateTime] that the picker should display. + /// + /// If this is null, there is no selected date. A date must be selected to + /// submit the dialog. + final DateTime? initialDate; + + /// The earliest allowable [DateTime] that the user can select. + final DateTime firstDate; + + /// The latest allowable [DateTime] that the user can select. + final DateTime lastDate; + + /// The [DateTime] representing today. It will be highlighted in the day grid. + final DateTime currentDate; + + /// The initial mode of date entry method for the date picker dialog. + /// + /// See [DatePickerEntryMode] for more details on the different data entry + /// modes available. + final DatePickerEntryMode initialEntryMode; + + /// Function to provide full control over which [DateTime] can be selected. + final SelectableDayPredicate? selectableDayPredicate; + + /// The text that is displayed on the cancel button. + final String? cancelText; + + /// The text that is displayed on the confirm button. + final String? confirmText; + + /// The text that is displayed at the top of the header. + /// + /// This is used to indicate to the user what they are selecting a date for. + final String? helpText; + + /// The initial display of the calendar picker. + final DatePickerMode initialCalendarMode; + + /// The error text displayed if the entered date is not in the correct format. + final String? errorFormatText; + + /// The error text displayed if the date is not valid. + /// + /// A date is not valid if it is earlier than [firstDate], later than + /// [lastDate], or doesn't pass the [selectableDayPredicate]. + final String? errorInvalidText; + + /// The hint text displayed in the [TextField]. + /// + /// If this is null, it will default to the date format string. For example, + /// 'mm/dd/yyyy' for en_US. + final String? fieldHintText; + + /// The label text displayed in the [TextField]. + /// + /// If this is null, it will default to the words representing the date format + /// string. For example, 'Month, Day, Year' for en_US. + final String? fieldLabelText; + + /// {@template flutter.material.datePickerDialog} + /// The keyboard type of the [TextField]. + /// + /// If this is null, it will default to [TextInputType.datetime] + /// {@endtemplate} + final TextInputType? keyboardType; + + /// Restoration ID to save and restore the state of the [DatePickerDialog]. + /// + /// If it is non-null, the date picker will persist and restore the + /// date selected on the dialog. + /// + /// The state of this widget is persisted in a [RestorationBucket] claimed + /// from the surrounding [RestorationScope] using the provided restoration ID. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + final String? restorationId; + + + /// Called when the [DatePickerDialog] is toggled between + /// [DatePickerEntryMode.calendar],[DatePickerEntryMode.input]. + /// + /// An example of how this callback might be used is an app that saves the + /// user's preferred entry mode and uses it to initialize the + /// `initialEntryMode` parameter the next time the date picker is shown. + final ValueChanged<DatePickerEntryMode>? onDatePickerModeChange; + + /// {@macro flutter.material.date_picker.switchToInputEntryModeIcon} + final Icon? switchToInputEntryModeIcon; + + /// {@macro flutter.material.date_picker.switchToCalendarEntryModeIcon} + final Icon? switchToCalendarEntryModeIcon; + + @override + State<DatePickerDialog> createState() => _DatePickerDialogState(); +} + +class _DatePickerDialogState extends State<DatePickerDialog> with RestorationMixin { + late final RestorableDateTimeN _selectedDate = RestorableDateTimeN(widget.initialDate); + late final _RestorableDatePickerEntryMode _entryMode = _RestorableDatePickerEntryMode(widget.initialEntryMode); + final _RestorableAutovalidateMode _autovalidateMode = _RestorableAutovalidateMode(AutovalidateMode.disabled); + + @override + void dispose() { + _selectedDate.dispose(); + _entryMode.dispose(); + _autovalidateMode.dispose(); + super.dispose(); + } + + @override + String? get restorationId => widget.restorationId; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_selectedDate, 'selected_date'); + registerForRestoration(_autovalidateMode, 'autovalidateMode'); + registerForRestoration(_entryMode, 'calendar_entry_mode'); + } + + final GlobalKey _calendarPickerKey = GlobalKey(); + final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); + + void _handleOk() { + if (_entryMode.value == DatePickerEntryMode.input || _entryMode.value == DatePickerEntryMode.inputOnly) { + final FormState form = _formKey.currentState!; + if (!form.validate()) { + setState(() => _autovalidateMode.value = AutovalidateMode.always); + return; + } + form.save(); + } + Navigator.pop(context, _selectedDate.value); + } + + void _handleCancel() { + Navigator.pop(context); + } + + void _handleOnDatePickerModeChange() { + widget.onDatePickerModeChange?.call(_entryMode.value); + } + + void _handleEntryModeToggle() { + setState(() { + switch (_entryMode.value) { + case DatePickerEntryMode.calendar: + _autovalidateMode.value = AutovalidateMode.disabled; + _entryMode.value = DatePickerEntryMode.input; + _handleOnDatePickerModeChange(); + case DatePickerEntryMode.input: + _formKey.currentState!.save(); + _entryMode.value = DatePickerEntryMode.calendar; + _handleOnDatePickerModeChange(); + case DatePickerEntryMode.calendarOnly: + case DatePickerEntryMode.inputOnly: + assert(false, 'Can not change entry mode from ${_entryMode.value}'); + } + }); + } + + void _handleDateChanged(DateTime date) { + setState(() { + _selectedDate.value = date; + }); + } + + Size _dialogSize(BuildContext context) { + final bool useMaterial3 = Theme.of(context).useMaterial3; + final Orientation orientation = MediaQuery.orientationOf(context); + + switch (_entryMode.value) { + case DatePickerEntryMode.calendar: + case DatePickerEntryMode.calendarOnly: + switch (orientation) { + case Orientation.portrait: + return useMaterial3 ? _calendarPortraitDialogSizeM3 : _calendarPortraitDialogSizeM2; + case Orientation.landscape: + return _calendarLandscapeDialogSize; + } + case DatePickerEntryMode.input: + case DatePickerEntryMode.inputOnly: + switch (orientation) { + case Orientation.portrait: + return useMaterial3 ? _inputPortraitDialogSizeM3 : _inputPortraitDialogSizeM2; + case Orientation.landscape: + return _inputLandscapeDialogSize; + } + } + } + + static const Map<ShortcutActivator, Intent> _formShortcutMap = <ShortcutActivator, Intent>{ + // Pressing enter on the field will move focus to the next field or control. + SingleActivator(LogicalKeyboardKey.enter): NextFocusIntent(), + }; + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final bool useMaterial3 = theme.useMaterial3; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final Orientation orientation = MediaQuery.orientationOf(context); + final DatePickerThemeData datePickerTheme = DatePickerTheme.of(context); + final DatePickerThemeData defaults = DatePickerTheme.defaults(context); + final TextTheme textTheme = theme.textTheme; + + // There's no M3 spec for a landscape layout input (not calendar) + // date picker. To ensure that the date displayed in the input + // date picker's header fits in landscape mode, we override the M3 + // default here. + TextStyle? headlineStyle; + if (useMaterial3) { + headlineStyle = datePickerTheme.headerHeadlineStyle ?? defaults.headerHeadlineStyle; + switch (_entryMode.value) { + case DatePickerEntryMode.input: + case DatePickerEntryMode.inputOnly: + if (orientation == Orientation.landscape) { + headlineStyle = textTheme.headlineSmall; + } + case DatePickerEntryMode.calendar: + case DatePickerEntryMode.calendarOnly: + // M3 default is OK. + } + } else { + headlineStyle = orientation == Orientation.landscape ? textTheme.headlineSmall : textTheme.headlineMedium; + } + final Color? headerForegroundColor = datePickerTheme.headerForegroundColor ?? defaults.headerForegroundColor; + headlineStyle = headlineStyle?.copyWith(color: headerForegroundColor); + + final Widget actions = Container( + alignment: AlignmentDirectional.centerEnd, + constraints: const BoxConstraints(minHeight: 52.0), + padding: const EdgeInsets.symmetric(horizontal: 8), + child: OverflowBar( + spacing: 8, + children: <Widget>[ + TextButton( + style: datePickerTheme.cancelButtonStyle ?? defaults.cancelButtonStyle, + onPressed: _handleCancel, + child: Text(widget.cancelText ?? ( + useMaterial3 + ? localizations.cancelButtonLabel + : localizations.cancelButtonLabel.toUpperCase() + )), + ), + TextButton( + style: datePickerTheme.confirmButtonStyle ?? defaults.confirmButtonStyle, + onPressed: _handleOk, + child: Text(widget.confirmText ?? localizations.okButtonLabel), + ), + ], + ), + ); + + CalendarDatePicker calendarDatePicker() { + return CalendarDatePicker( + key: _calendarPickerKey, + initialDate: _selectedDate.value, + firstDate: widget.firstDate, + lastDate: widget.lastDate, + currentDate: widget.currentDate, + onDateChanged: _handleDateChanged, + selectableDayPredicate: widget.selectableDayPredicate, + initialCalendarMode: widget.initialCalendarMode, + ); + } + + Form inputDatePicker() { + return Form( + key: _formKey, + autovalidateMode: _autovalidateMode.value, + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 24), + height: orientation == Orientation.portrait ? _inputFormPortraitHeight : _inputFormLandscapeHeight, + child: Shortcuts( + shortcuts: _formShortcutMap, + child: Column( + children: <Widget>[ + const Spacer(), + InputDatePickerFormField( + initialDate: _selectedDate.value, + firstDate: widget.firstDate, + lastDate: widget.lastDate, + onDateSubmitted: _handleDateChanged, + onDateSaved: _handleDateChanged, + selectableDayPredicate: widget.selectableDayPredicate, + errorFormatText: widget.errorFormatText, + errorInvalidText: widget.errorInvalidText, + fieldHintText: widget.fieldHintText, + fieldLabelText: widget.fieldLabelText, + keyboardType: widget.keyboardType, + autofocus: true, + ), + const Spacer(), + ], + ), + ), + ), + ); + } + + final Widget picker; + final Widget? entryModeButton; + switch (_entryMode.value) { + case DatePickerEntryMode.calendar: + picker = calendarDatePicker(); + entryModeButton = IconButton( + icon: widget.switchToInputEntryModeIcon ?? Icon(useMaterial3 ? Icons.edit_outlined : Icons.edit), + color: headerForegroundColor, + tooltip: localizations.inputDateModeButtonLabel, + onPressed: _handleEntryModeToggle, + ); + + case DatePickerEntryMode.calendarOnly: + picker = calendarDatePicker(); + entryModeButton = null; + + case DatePickerEntryMode.input: + picker = inputDatePicker(); + entryModeButton = IconButton( + icon: widget.switchToCalendarEntryModeIcon ?? const Icon(Icons.calendar_today), + color: headerForegroundColor, + tooltip: localizations.calendarModeButtonLabel, + onPressed: _handleEntryModeToggle, + ); + + case DatePickerEntryMode.inputOnly: + picker = inputDatePicker(); + entryModeButton = null; + } + + final Widget header = _DatePickerHeader( + helpText: widget.helpText ?? ( + useMaterial3 + ? localizations.datePickerHelpText + : localizations.datePickerHelpText.toUpperCase() + ), + titleText: _selectedDate.value == null ? '' : localizations.formatMediumDate(_selectedDate.value!), + titleStyle: headlineStyle, + orientation: orientation, + isShort: orientation == Orientation.landscape, + entryModeButton: entryModeButton, + ); + + // Constrain the textScaleFactor to the largest supported value to prevent + // layout issues. + final double textScaleFactor = MediaQuery.textScalerOf(context).clamp(maxScaleFactor: _kMaxTextScaleFactor).textScaleFactor; + final Size dialogSize = _dialogSize(context) * textScaleFactor; + final DialogTheme dialogTheme = theme.dialogTheme; + return Dialog( + backgroundColor: datePickerTheme.backgroundColor ?? defaults.backgroundColor, + elevation: useMaterial3 + ? datePickerTheme.elevation ?? defaults.elevation! + : datePickerTheme.elevation ?? dialogTheme.elevation ?? 24, + shadowColor: datePickerTheme.shadowColor ?? defaults.shadowColor, + surfaceTintColor: datePickerTheme.surfaceTintColor ?? defaults.surfaceTintColor, + shape: useMaterial3 + ? datePickerTheme.shape ?? defaults.shape + : datePickerTheme.shape ?? dialogTheme.shape ?? defaults.shape, + insetPadding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0), + clipBehavior: Clip.antiAlias, + child: AnimatedContainer( + width: dialogSize.width, + height: dialogSize.height, + duration: _dialogSizeAnimationDuration, + curve: Curves.easeIn, + child: MediaQuery.withClampedTextScaling( + // Constrain the textScaleFactor to the largest supported value to prevent + // layout issues. + maxScaleFactor: _kMaxTextScaleFactor, + child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) { + final Size portraitDialogSize = useMaterial3 ? _inputPortraitDialogSizeM3 : _inputPortraitDialogSizeM2; + // Make sure the portrait dialog can fit the contents comfortably when + // resized from the landscape dialog. + final bool isFullyPortrait = constraints.maxHeight >= math.min(dialogSize.height, portraitDialogSize.height); + + switch (orientation) { + case Orientation.portrait: + return Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + header, + if (useMaterial3) Divider(height: 0, color: datePickerTheme.dividerColor), + if (isFullyPortrait) ...<Widget>[ + Expanded(child: picker), + actions, + ], + ], + ); + case Orientation.landscape: + return Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + header, + if (useMaterial3) VerticalDivider(width: 0, color: datePickerTheme.dividerColor), + Flexible( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + Expanded(child: picker), + actions, + ], + ), + ), + ], + ); + } + }), + ), + ), + ); + } +} + +// A restorable [DatePickerEntryMode] value. +// +// This serializes each entry as a unique `int` value. +class _RestorableDatePickerEntryMode extends RestorableValue<DatePickerEntryMode> { + _RestorableDatePickerEntryMode( + DatePickerEntryMode defaultValue, + ) : _defaultValue = defaultValue; + + final DatePickerEntryMode _defaultValue; + + @override + DatePickerEntryMode createDefaultValue() => _defaultValue; + + @override + void didUpdateValue(DatePickerEntryMode? oldValue) { + assert(debugIsSerializableForRestoration(value.index)); + notifyListeners(); + } + + @override + DatePickerEntryMode fromPrimitives(Object? data) => DatePickerEntryMode.values[data! as int]; + + @override + Object? toPrimitives() => value.index; +} + +// A restorable [AutovalidateMode] value. +// +// This serializes each entry as a unique `int` value. +class _RestorableAutovalidateMode extends RestorableValue<AutovalidateMode> { + _RestorableAutovalidateMode( + AutovalidateMode defaultValue, + ) : _defaultValue = defaultValue; + + final AutovalidateMode _defaultValue; + + @override + AutovalidateMode createDefaultValue() => _defaultValue; + + @override + void didUpdateValue(AutovalidateMode? oldValue) { + assert(debugIsSerializableForRestoration(value.index)); + notifyListeners(); + } + + @override + AutovalidateMode fromPrimitives(Object? data) => AutovalidateMode.values[data! as int]; + + @override + Object? toPrimitives() => value.index; +} + +/// Re-usable widget that displays the selected date (in large font) and the +/// help text above it. +/// +/// These types include: +/// +/// * Single Date picker with calendar mode. +/// * Single Date picker with text input mode. +/// * Date Range picker with text input mode. +/// +/// [helpText], [orientation], [icon], [onIconPressed] are required and must be +/// non-null. +class _DatePickerHeader extends StatelessWidget { + + /// Creates a header for use in a date picker dialog. + const _DatePickerHeader({ + required this.helpText, + required this.titleText, + this.titleSemanticsLabel, + required this.titleStyle, + required this.orientation, + this.isShort = false, + this.entryModeButton, + }); + + static const double _datePickerHeaderLandscapeWidth = 152.0; + static const double _datePickerHeaderPortraitHeight = 120.0; + static const double _headerPaddingLandscape = 16.0; + + /// The text that is displayed at the top of the header. + /// + /// This is used to indicate to the user what they are selecting a date for. + final String helpText; + + /// The text that is displayed at the center of the header. + final String titleText; + + /// The semantic label associated with the [titleText]. + final String? titleSemanticsLabel; + + /// The [TextStyle] that the title text is displayed with. + final TextStyle? titleStyle; + + /// The orientation is used to decide how to layout its children. + final Orientation orientation; + + /// Indicates the header is being displayed in a shorter/narrower context. + /// + /// This will be used to tighten up the space between the help text and date + /// text if `true`. Additionally, it will use a smaller typography style if + /// `true`. + /// + /// This is necessary for displaying the manual input mode in + /// landscape orientation, in order to account for the keyboard height. + final bool isShort; + + final Widget? entryModeButton; + + @override + Widget build(BuildContext context) { + final DatePickerThemeData themeData = DatePickerTheme.of(context); + final DatePickerThemeData defaults = DatePickerTheme.defaults(context); + final Color? backgroundColor = themeData.headerBackgroundColor ?? defaults.headerBackgroundColor; + final Color? foregroundColor = themeData.headerForegroundColor ?? defaults.headerForegroundColor; + final TextStyle? helpStyle = (themeData.headerHelpStyle ?? defaults.headerHelpStyle)?.copyWith( + color: foregroundColor, + ); + + final Text help = Text( + helpText, + style: helpStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ); + final Text title = Text( + titleText, + semanticsLabel: titleSemanticsLabel ?? titleText, + style: titleStyle, + maxLines: orientation == Orientation.portrait ? 1 : 2, + overflow: TextOverflow.ellipsis, + ); + + switch (orientation) { + case Orientation.portrait: + return SizedBox( + height: _datePickerHeaderPortraitHeight, + child: Material( + color: backgroundColor, + child: Padding( + padding: const EdgeInsetsDirectional.only( + start: 24, + end: 12, + bottom: 12, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + const SizedBox(height: 16), + help, + const Flexible(child: SizedBox(height: 38)), + Row( + children: <Widget>[ + Expanded(child: title), + if (entryModeButton != null) + entryModeButton!, + ], + ), + ], + ), + ), + ), + ); + case Orientation.landscape: + return SizedBox( + width: _datePickerHeaderLandscapeWidth, + child: Material( + color: backgroundColor, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + const SizedBox(height: 16), + Padding( + padding: const EdgeInsets.symmetric( + horizontal: _headerPaddingLandscape, + ), + child: help, + ), + SizedBox(height: isShort ? 16 : 56), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: _headerPaddingLandscape, + ), + child: title, + ), + ), + if (entryModeButton != null) + Padding( + padding: const EdgeInsets.symmetric(horizontal: 4), + child: entryModeButton, + ), + ], + ), + ), + ); + } + } +} + +/// Shows a full screen modal dialog containing a Material Design date range +/// picker. +/// +/// The returned [Future] resolves to the [DateTimeRange] selected by the user +/// when the user saves their selection. If the user cancels the dialog, null is +/// returned. +/// +/// If [initialDateRange] is non-null, then it will be used as the initially +/// selected date range. If it is provided, `initialDateRange.start` must be +/// before or on `initialDateRange.end`. +/// +/// The [firstDate] is the earliest allowable date. The [lastDate] is the latest +/// allowable date. +/// +/// If an initial date range is provided, `initialDateRange.start` +/// and `initialDateRange.end` must both fall between or on [firstDate] and +/// [lastDate]. For all of these [DateTime] values, only their dates are +/// considered. Their time fields are ignored. +/// +/// The [currentDate] represents the current day (i.e. today). This +/// date will be highlighted in the day grid. If null, the date of +/// `DateTime.now()` will be used. +/// +/// An optional [initialEntryMode] argument can be used to display the date +/// picker in the [DatePickerEntryMode.calendar] (a scrollable calendar month +/// grid) or [DatePickerEntryMode.input] (two text input fields) mode. +/// It defaults to [DatePickerEntryMode.calendar]. +/// +/// {@macro flutter.material.date_picker.switchToInputEntryModeIcon} +/// +/// {@macro flutter.material.date_picker.switchToCalendarEntryModeIcon} +/// +/// The following optional string parameters allow you to override the default +/// text used for various parts of the dialog: +/// +/// * [helpText], the label displayed at the top of the dialog. +/// * [cancelText], the label on the cancel button for the text input mode. +/// * [confirmText],the label on the ok button for the text input mode. +/// * [saveText], the label on the save button for the fullscreen calendar +/// mode. +/// * [errorFormatText], the message used when an input text isn't in a proper +/// date format. +/// * [errorInvalidText], the message used when an input text isn't a +/// selectable date. +/// * [errorInvalidRangeText], the message used when the date range is +/// invalid (e.g. start date is after end date). +/// * [fieldStartHintText], the text used to prompt the user when no text has +/// been entered in the start field. +/// * [fieldEndHintText], the text used to prompt the user when no text has +/// been entered in the end field. +/// * [fieldStartLabelText], the label for the start date text input field. +/// * [fieldEndLabelText], the label for the end date text input field. +/// +/// An optional [locale] argument can be used to set the locale for the date +/// picker. It defaults to the ambient locale provided by [Localizations]. +/// +/// An optional [textDirection] argument can be used to set the text direction +/// ([TextDirection.ltr] or [TextDirection.rtl]) for the date picker. It +/// defaults to the ambient text direction provided by [Directionality]. If both +/// [locale] and [textDirection] are non-null, [textDirection] overrides the +/// direction chosen for the [locale]. +/// +/// The [context], [barrierDismissible], [barrierColor], [barrierLabel], +/// [useRootNavigator] and [routeSettings] arguments are passed to [showDialog], +/// the documentation for which discusses how it is used. +/// +/// The [builder] parameter can be used to wrap the dialog widget +/// to add inherited widgets like [Theme]. +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// ### State Restoration +/// +/// Using this method will not enable state restoration for the date range picker. +/// In order to enable state restoration for a date range picker, use +/// [Navigator.restorablePush] or [Navigator.restorablePushNamed] with +/// [DateRangePickerDialog]. +/// +/// For more information about state restoration, see [RestorationManager]. +/// +/// {@macro flutter.widgets.RestorationManager} +/// +/// {@tool sample} +/// This sample demonstrates how to create a restorable Material date range picker. +/// This is accomplished by enabling state restoration by specifying +/// [MaterialApp.restorationScopeId] and using [Navigator.restorablePush] to +/// push [DateRangePickerDialog] when the button is tapped. +/// +/// ** See code in examples/api/lib/material/date_picker/show_date_range_picker.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [showDatePicker], which shows a Material Design date picker used to +/// select a single date. +/// * [DateTimeRange], which is used to describe a date range. +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +Future<DateTimeRange?> showDateRangePicker({ + required BuildContext context, + DateTimeRange? initialDateRange, + required DateTime firstDate, + required DateTime lastDate, + DateTime? currentDate, + DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar, + String? helpText, + String? cancelText, + String? confirmText, + String? saveText, + String? errorFormatText, + String? errorInvalidText, + String? errorInvalidRangeText, + String? fieldStartHintText, + String? fieldEndHintText, + String? fieldStartLabelText, + String? fieldEndLabelText, + Locale? locale, + bool barrierDismissible = true, + Color? barrierColor, + String? barrierLabel, + bool useRootNavigator = true, + RouteSettings? routeSettings, + TextDirection? textDirection, + TransitionBuilder? builder, + Offset? anchorPoint, + TextInputType keyboardType = TextInputType.datetime, + final Icon? switchToInputEntryModeIcon, + final Icon? switchToCalendarEntryModeIcon, +}) async { + assert( + initialDateRange == null || !initialDateRange.start.isAfter(initialDateRange.end), + "initialDateRange's start date must not be after it's end date.", + ); + initialDateRange = initialDateRange == null ? null : DateUtils.datesOnly(initialDateRange); + firstDate = DateUtils.dateOnly(firstDate); + lastDate = DateUtils.dateOnly(lastDate); + assert( + !lastDate.isBefore(firstDate), + 'lastDate $lastDate must be on or after firstDate $firstDate.', + ); + assert( + initialDateRange == null || !initialDateRange.start.isBefore(firstDate), + "initialDateRange's start date must be on or after firstDate $firstDate.", + ); + assert( + initialDateRange == null || !initialDateRange.end.isBefore(firstDate), + "initialDateRange's end date must be on or after firstDate $firstDate.", + ); + assert( + initialDateRange == null || !initialDateRange.start.isAfter(lastDate), + "initialDateRange's start date must be on or before lastDate $lastDate.", + ); + assert( + initialDateRange == null || !initialDateRange.end.isAfter(lastDate), + "initialDateRange's end date must be on or before lastDate $lastDate.", + ); + currentDate = DateUtils.dateOnly(currentDate ?? DateTime.now()); + assert(debugCheckHasMaterialLocalizations(context)); + + Widget dialog = DateRangePickerDialog( + initialDateRange: initialDateRange, + firstDate: firstDate, + lastDate: lastDate, + currentDate: currentDate, + initialEntryMode: initialEntryMode, + helpText: helpText, + cancelText: cancelText, + confirmText: confirmText, + saveText: saveText, + errorFormatText: errorFormatText, + errorInvalidText: errorInvalidText, + errorInvalidRangeText: errorInvalidRangeText, + fieldStartHintText: fieldStartHintText, + fieldEndHintText: fieldEndHintText, + fieldStartLabelText: fieldStartLabelText, + fieldEndLabelText: fieldEndLabelText, + keyboardType: keyboardType, + switchToInputEntryModeIcon: switchToInputEntryModeIcon, + switchToCalendarEntryModeIcon: switchToCalendarEntryModeIcon, + ); + + if (textDirection != null) { + dialog = Directionality( + textDirection: textDirection, + child: dialog, + ); + } + + if (locale != null) { + dialog = Localizations.override( + context: context, + locale: locale, + child: dialog, + ); + } + + return showDialog<DateTimeRange>( + context: context, + barrierDismissible: barrierDismissible, + barrierColor: barrierColor, + barrierLabel: barrierLabel, + useRootNavigator: useRootNavigator, + routeSettings: routeSettings, + useSafeArea: false, + builder: (BuildContext context) { + return builder == null ? dialog : builder(context, dialog); + }, + anchorPoint: anchorPoint, + ); +} + +/// Returns a locale-appropriate string to describe the start of a date range. +/// +/// If `startDate` is null, then it defaults to 'Start Date', otherwise if it +/// is in the same year as the `endDate` then it will use the short month +/// day format (i.e. 'Jan 21'). Otherwise it will return the short date format +/// (i.e. 'Jan 21, 2020'). +String _formatRangeStartDate(MaterialLocalizations localizations, DateTime? startDate, DateTime? endDate) { + return startDate == null + ? localizations.dateRangeStartLabel + : (endDate == null || startDate.year == endDate.year) + ? localizations.formatShortMonthDay(startDate) + : localizations.formatShortDate(startDate); +} + +/// Returns an locale-appropriate string to describe the end of a date range. +/// +/// If `endDate` is null, then it defaults to 'End Date', otherwise if it +/// is in the same year as the `startDate` and the `currentDate` then it will +/// just use the short month day format (i.e. 'Jan 21'), otherwise it will +/// include the year (i.e. 'Jan 21, 2020'). +String _formatRangeEndDate(MaterialLocalizations localizations, DateTime? startDate, DateTime? endDate, DateTime currentDate) { + return endDate == null + ? localizations.dateRangeEndLabel + : (startDate != null && startDate.year == endDate.year && startDate.year == currentDate.year) + ? localizations.formatShortMonthDay(endDate) + : localizations.formatShortDate(endDate); +} + +/// A Material-style date range picker dialog. +/// +/// It is used internally by [showDateRangePicker] or can be directly pushed +/// onto the [Navigator] stack to enable state restoration. See +/// [showDateRangePicker] for a state restoration app example. +/// +/// See also: +/// +/// * [showDateRangePicker], which is a way to display the date picker. +class DateRangePickerDialog extends StatefulWidget { + /// A Material-style date range picker dialog. + const DateRangePickerDialog({ + super.key, + this.initialDateRange, + required this.firstDate, + required this.lastDate, + this.currentDate, + this.initialEntryMode = DatePickerEntryMode.calendar, + this.helpText, + this.cancelText, + this.confirmText, + this.saveText, + this.errorInvalidRangeText, + this.errorFormatText, + this.errorInvalidText, + this.fieldStartHintText, + this.fieldEndHintText, + this.fieldStartLabelText, + this.fieldEndLabelText, + this.keyboardType = TextInputType.datetime, + this.restorationId, + this.switchToInputEntryModeIcon, + this.switchToCalendarEntryModeIcon, + }); + + /// The date range that the date range picker starts with when it opens. + /// + /// If an initial date range is provided, `initialDateRange.start` + /// and `initialDateRange.end` must both fall between or on [firstDate] and + /// [lastDate]. For all of these [DateTime] values, only their dates are + /// considered. Their time fields are ignored. + /// + /// If [initialDateRange] is non-null, then it will be used as the initially + /// selected date range. If it is provided, `initialDateRange.start` must be + /// before or on `initialDateRange.end`. + final DateTimeRange? initialDateRange; + + /// The earliest allowable date on the date range. + final DateTime firstDate; + + /// The latest allowable date on the date range. + final DateTime lastDate; + + /// The [currentDate] represents the current day (i.e. today). + /// + /// This date will be highlighted in the day grid. + /// + /// If `null`, the date of `DateTime.now()` will be used. + final DateTime? currentDate; + + /// The initial date range picker entry mode. + /// + /// The date range has two main modes: [DatePickerEntryMode.calendar] (a + /// scrollable calendar month grid) or [DatePickerEntryMode.input] (two text + /// input fields) mode. + /// + /// It defaults to [DatePickerEntryMode.calendar]. + final DatePickerEntryMode initialEntryMode; + + /// The label on the cancel button for the text input mode. + /// + /// If null, the localized value of + /// [MaterialLocalizations.cancelButtonLabel] is used. + final String? cancelText; + + /// The label on the "OK" button for the text input mode. + /// + /// If null, the localized value of + /// [MaterialLocalizations.okButtonLabel] is used. + final String? confirmText; + + /// The label on the save button for the fullscreen calendar mode. + /// + /// If null, the localized value of + /// [MaterialLocalizations.saveButtonLabel] is used. + final String? saveText; + + /// The label displayed at the top of the dialog. + /// + /// If null, the localized value of + /// [MaterialLocalizations.dateRangePickerHelpText] is used. + final String? helpText; + + /// The message used when the date range is invalid (e.g. start date is after + /// end date). + /// + /// If null, the localized value of + /// [MaterialLocalizations.invalidDateRangeLabel] is used. + final String? errorInvalidRangeText; + + /// The message used when an input text isn't in a proper date format. + /// + /// If null, the localized value of + /// [MaterialLocalizations.invalidDateFormatLabel] is used. + final String? errorFormatText; + + /// The message used when an input text isn't a selectable date. + /// + /// If null, the localized value of + /// [MaterialLocalizations.dateOutOfRangeLabel] is used. + final String? errorInvalidText; + + /// The text used to prompt the user when no text has been entered in the + /// start field. + /// + /// If null, the localized value of + /// [MaterialLocalizations.dateHelpText] is used. + final String? fieldStartHintText; + + /// The text used to prompt the user when no text has been entered in the + /// end field. + /// + /// If null, the localized value of [MaterialLocalizations.dateHelpText] is + /// used. + final String? fieldEndHintText; + + /// The label for the start date text input field. + /// + /// If null, the localized value of [MaterialLocalizations.dateRangeStartLabel] + /// is used. + final String? fieldStartLabelText; + + /// The label for the end date text input field. + /// + /// If null, the localized value of [MaterialLocalizations.dateRangeEndLabel] + /// is used. + final String? fieldEndLabelText; + + /// {@macro flutter.material.datePickerDialog} + final TextInputType keyboardType; + + /// Restoration ID to save and restore the state of the [DateRangePickerDialog]. + /// + /// If it is non-null, the date range picker will persist and restore the + /// date range selected on the dialog. + /// + /// The state of this widget is persisted in a [RestorationBucket] claimed + /// from the surrounding [RestorationScope] using the provided restoration ID. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + final String? restorationId; + + /// {@macro flutter.material.date_picker.switchToInputEntryModeIcon} + final Icon? switchToInputEntryModeIcon; + + /// {@macro flutter.material.date_picker.switchToCalendarEntryModeIcon} + final Icon? switchToCalendarEntryModeIcon; + + @override + State<DateRangePickerDialog> createState() => _DateRangePickerDialogState(); +} + +class _DateRangePickerDialogState extends State<DateRangePickerDialog> with RestorationMixin { + late final _RestorableDatePickerEntryMode _entryMode = _RestorableDatePickerEntryMode(widget.initialEntryMode); + late final RestorableDateTimeN _selectedStart = RestorableDateTimeN(widget.initialDateRange?.start); + late final RestorableDateTimeN _selectedEnd = RestorableDateTimeN(widget.initialDateRange?.end); + final RestorableBool _autoValidate = RestorableBool(false); + final GlobalKey _calendarPickerKey = GlobalKey(); + final GlobalKey<_InputDateRangePickerState> _inputPickerKey = GlobalKey<_InputDateRangePickerState>(); + + @override + String? get restorationId => widget.restorationId; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_entryMode, 'entry_mode'); + registerForRestoration(_selectedStart, 'selected_start'); + registerForRestoration(_selectedEnd, 'selected_end'); + registerForRestoration(_autoValidate, 'autovalidate'); + } + + @override + void dispose() { + _entryMode.dispose(); + _selectedStart.dispose(); + _selectedEnd.dispose(); + _autoValidate.dispose(); + super.dispose(); + } + + void _handleOk() { + if (_entryMode.value == DatePickerEntryMode.input || _entryMode.value == DatePickerEntryMode.inputOnly) { + final _InputDateRangePickerState picker = _inputPickerKey.currentState!; + if (!picker.validate()) { + setState(() { + _autoValidate.value = true; + }); + return; + } + } + final DateTimeRange? selectedRange = _hasSelectedDateRange + ? DateTimeRange(start: _selectedStart.value!, end: _selectedEnd.value!) + : null; + + Navigator.pop(context, selectedRange); + } + + void _handleCancel() { + Navigator.pop(context); + } + + void _handleEntryModeToggle() { + setState(() { + switch (_entryMode.value) { + case DatePickerEntryMode.calendar: + _autoValidate.value = false; + _entryMode.value = DatePickerEntryMode.input; + + case DatePickerEntryMode.input: + // Validate the range dates + if (_selectedStart.value != null && + (_selectedStart.value!.isBefore(widget.firstDate) || _selectedStart.value!.isAfter(widget.lastDate))) { + _selectedStart.value = null; + // With no valid start date, having an end date makes no sense for the UI. + _selectedEnd.value = null; + } + if (_selectedEnd.value != null && + (_selectedEnd.value!.isBefore(widget.firstDate) || _selectedEnd.value!.isAfter(widget.lastDate))) { + _selectedEnd.value = null; + } + // If invalid range (start after end), then just use the start date + if (_selectedStart.value != null && _selectedEnd.value != null && _selectedStart.value!.isAfter(_selectedEnd.value!)) { + _selectedEnd.value = null; + } + _entryMode.value = DatePickerEntryMode.calendar; + + case DatePickerEntryMode.calendarOnly: + case DatePickerEntryMode.inputOnly: + assert(false, 'Can not change entry mode from $_entryMode'); + } + }); + } + + void _handleStartDateChanged(DateTime? date) { + setState(() => _selectedStart.value = date); + } + + void _handleEndDateChanged(DateTime? date) { + setState(() => _selectedEnd.value = date); + } + + bool get _hasSelectedDateRange => _selectedStart.value != null && _selectedEnd.value != null; + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final bool useMaterial3 = theme.useMaterial3; + final Orientation orientation = MediaQuery.orientationOf(context); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final DatePickerThemeData datePickerTheme = DatePickerTheme.of(context); + final DatePickerThemeData defaults = DatePickerTheme.defaults(context); + + final Widget contents; + final Size size; + final double? elevation; + final Color? shadowColor; + final Color? surfaceTintColor; + final ShapeBorder? shape; + final EdgeInsets insetPadding; + final bool showEntryModeButton = + _entryMode.value == DatePickerEntryMode.calendar || + _entryMode.value == DatePickerEntryMode.input; + switch (_entryMode.value) { + case DatePickerEntryMode.calendar: + case DatePickerEntryMode.calendarOnly: + contents = _CalendarRangePickerDialog( + key: _calendarPickerKey, + selectedStartDate: _selectedStart.value, + selectedEndDate: _selectedEnd.value, + firstDate: widget.firstDate, + lastDate: widget.lastDate, + currentDate: widget.currentDate, + onStartDateChanged: _handleStartDateChanged, + onEndDateChanged: _handleEndDateChanged, + onConfirm: _hasSelectedDateRange ? _handleOk : null, + onCancel: _handleCancel, + entryModeButton: showEntryModeButton + ? IconButton( + icon: widget.switchToInputEntryModeIcon ?? Icon(useMaterial3 ? Icons.edit_outlined : Icons.edit), + padding: EdgeInsets.zero, + tooltip: localizations.inputDateModeButtonLabel, + onPressed: _handleEntryModeToggle, + ) + : null, + confirmText: widget.saveText ?? ( + useMaterial3 + ? localizations.saveButtonLabel + : localizations.saveButtonLabel.toUpperCase() + ), + helpText: widget.helpText ?? ( + useMaterial3 + ? localizations.dateRangePickerHelpText + : localizations.dateRangePickerHelpText.toUpperCase() + ), + ); + size = MediaQuery.sizeOf(context); + insetPadding = EdgeInsets.zero; + elevation = datePickerTheme.rangePickerElevation ?? defaults.rangePickerElevation!; + shadowColor = datePickerTheme.rangePickerShadowColor ?? defaults.rangePickerShadowColor!; + surfaceTintColor = datePickerTheme.rangePickerSurfaceTintColor ?? defaults.rangePickerSurfaceTintColor!; + shape = datePickerTheme.rangePickerShape ?? defaults.rangePickerShape; + + case DatePickerEntryMode.input: + case DatePickerEntryMode.inputOnly: + contents = _InputDateRangePickerDialog( + selectedStartDate: _selectedStart.value, + selectedEndDate: _selectedEnd.value, + currentDate: widget.currentDate, + picker: Container( + padding: const EdgeInsets.symmetric(horizontal: 24), + height: orientation == Orientation.portrait + ? _inputFormPortraitHeight + : _inputFormLandscapeHeight, + child: Column( + children: <Widget>[ + const Spacer(), + _InputDateRangePicker( + key: _inputPickerKey, + initialStartDate: _selectedStart.value, + initialEndDate: _selectedEnd.value, + firstDate: widget.firstDate, + lastDate: widget.lastDate, + onStartDateChanged: _handleStartDateChanged, + onEndDateChanged: _handleEndDateChanged, + autofocus: true, + autovalidate: _autoValidate.value, + helpText: widget.helpText, + errorInvalidRangeText: widget.errorInvalidRangeText, + errorFormatText: widget.errorFormatText, + errorInvalidText: widget.errorInvalidText, + fieldStartHintText: widget.fieldStartHintText, + fieldEndHintText: widget.fieldEndHintText, + fieldStartLabelText: widget.fieldStartLabelText, + fieldEndLabelText: widget.fieldEndLabelText, + keyboardType: widget.keyboardType, + ), + const Spacer(), + ], + ), + ), + onConfirm: _handleOk, + onCancel: _handleCancel, + entryModeButton: showEntryModeButton + ? IconButton( + icon: widget.switchToCalendarEntryModeIcon ?? const Icon(Icons.calendar_today), + padding: EdgeInsets.zero, + tooltip: localizations.calendarModeButtonLabel, + onPressed: _handleEntryModeToggle, + ) + : null, + confirmText: widget.confirmText ?? localizations.okButtonLabel, + cancelText: widget.cancelText ?? ( + useMaterial3 + ? localizations.cancelButtonLabel + : localizations.cancelButtonLabel.toUpperCase() + ), + helpText: widget.helpText ?? ( + useMaterial3 + ? localizations.dateRangePickerHelpText + : localizations.dateRangePickerHelpText.toUpperCase() + ), + ); + final DialogTheme dialogTheme = theme.dialogTheme; + size = orientation == Orientation.portrait + ? (useMaterial3 ? _inputPortraitDialogSizeM3 : _inputPortraitDialogSizeM2) + : _inputRangeLandscapeDialogSize; + elevation = useMaterial3 + ? datePickerTheme.elevation ?? defaults.elevation! + : datePickerTheme.elevation ?? dialogTheme.elevation ?? 24; + shadowColor = datePickerTheme.shadowColor ?? defaults.shadowColor; + surfaceTintColor = datePickerTheme.surfaceTintColor ?? defaults.surfaceTintColor; + shape = useMaterial3 + ? datePickerTheme.shape ?? defaults.shape + : datePickerTheme.shape ?? dialogTheme.shape ?? defaults.shape; + + insetPadding = const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0); + } + + return Dialog( + insetPadding: insetPadding, + backgroundColor: datePickerTheme.backgroundColor ?? defaults.backgroundColor, + elevation: elevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + shape: shape, + clipBehavior: Clip.antiAlias, + child: AnimatedContainer( + width: size.width, + height: size.height, + duration: _dialogSizeAnimationDuration, + curve: Curves.easeIn, + child: MediaQuery.withClampedTextScaling( + maxScaleFactor: _kMaxTextScaleFactor, + child: Builder(builder: (BuildContext context) { + return contents; + }), + ), + ), + ); + } +} + +class _CalendarRangePickerDialog extends StatelessWidget { + const _CalendarRangePickerDialog({ + super.key, + required this.selectedStartDate, + required this.selectedEndDate, + required this.firstDate, + required this.lastDate, + required this.currentDate, + required this.onStartDateChanged, + required this.onEndDateChanged, + required this.onConfirm, + required this.onCancel, + required this.confirmText, + required this.helpText, + this.entryModeButton, + }); + + final DateTime? selectedStartDate; + final DateTime? selectedEndDate; + final DateTime firstDate; + final DateTime lastDate; + final DateTime? currentDate; + final ValueChanged<DateTime> onStartDateChanged; + final ValueChanged<DateTime?> onEndDateChanged; + final VoidCallback? onConfirm; + final VoidCallback? onCancel; + final String confirmText; + final String helpText; + final Widget? entryModeButton; + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final bool useMaterial3 = theme.useMaterial3; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final Orientation orientation = MediaQuery.orientationOf(context); + final DatePickerThemeData themeData = DatePickerTheme.of(context); + final DatePickerThemeData defaults = DatePickerTheme.defaults(context); + final Color? dialogBackground = themeData.rangePickerBackgroundColor ?? defaults.rangePickerBackgroundColor; + final Color? headerBackground = themeData.rangePickerHeaderBackgroundColor ?? defaults.rangePickerHeaderBackgroundColor; + final Color? headerForeground = themeData.rangePickerHeaderForegroundColor ?? defaults.rangePickerHeaderForegroundColor; + final Color? headerDisabledForeground = headerForeground?.withOpacity(0.38); + final TextStyle? headlineStyle = themeData.rangePickerHeaderHeadlineStyle ?? defaults.rangePickerHeaderHeadlineStyle; + final TextStyle? headlineHelpStyle = (themeData.rangePickerHeaderHelpStyle ?? defaults.rangePickerHeaderHelpStyle)?.apply(color: headerForeground); + final String startDateText = _formatRangeStartDate(localizations, selectedStartDate, selectedEndDate); + final String endDateText = _formatRangeEndDate(localizations, selectedStartDate, selectedEndDate, DateTime.now()); + final TextStyle? startDateStyle = headlineStyle?.apply( + color: selectedStartDate != null ? headerForeground : headerDisabledForeground, + ); + final TextStyle? endDateStyle = headlineStyle?.apply( + color: selectedEndDate != null ? headerForeground : headerDisabledForeground, + ); + final ButtonStyle buttonStyle = TextButton.styleFrom( + foregroundColor: headerForeground, + disabledForegroundColor: headerDisabledForeground + ); + final IconThemeData iconTheme = IconThemeData(color: headerForeground); + + return SafeArea( + top: false, + left: false, + right: false, + child: Scaffold( + appBar: AppBar( + iconTheme: iconTheme, + actionsIconTheme: iconTheme, + elevation: useMaterial3 ? 0 : null, + scrolledUnderElevation: useMaterial3 ? 0 : null, + backgroundColor: useMaterial3 ? headerBackground : null, + leading: CloseButton( + onPressed: onCancel, + ), + actions: <Widget>[ + if (orientation == Orientation.landscape && entryModeButton != null) + entryModeButton!, + TextButton( + style: buttonStyle, + onPressed: onConfirm, + child: Text(confirmText), + ), + const SizedBox(width: 8), + ], + bottom: PreferredSize( + preferredSize: const Size(double.infinity, 64), + child: Row(children: <Widget>[ + SizedBox(width: MediaQuery.sizeOf(context).width < 360 ? 42 : 72), + Expanded( + child: Semantics( + label: '$helpText $startDateText to $endDateText', + excludeSemantics: true, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Text(helpText, style: headlineHelpStyle), + const SizedBox(height: 8), + Row( + children: <Widget>[ + Text( + startDateText, + style: startDateStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + Text(' – ', style: startDateStyle, + ), + Flexible( + child: Text( + endDateText, + style: endDateStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ), + ], + ), + const SizedBox(height: 16), + ], + ), + ), + ), + if (orientation == Orientation.portrait && entryModeButton != null) + Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: IconTheme( + data: iconTheme, + child: entryModeButton!, + ), + ), + ]), + ), + ), + backgroundColor: dialogBackground, + body: _CalendarDateRangePicker( + initialStartDate: selectedStartDate, + initialEndDate: selectedEndDate, + firstDate: firstDate, + lastDate: lastDate, + currentDate: currentDate, + onStartDateChanged: onStartDateChanged, + onEndDateChanged: onEndDateChanged, + ), + ), + ); + } +} + +const Duration _monthScrollDuration = Duration(milliseconds: 200); + +const double _monthItemHeaderHeight = 58.0; +const double _monthItemFooterHeight = 12.0; +const double _monthItemRowHeight = 42.0; +const double _monthItemSpaceBetweenRows = 8.0; +const double _horizontalPadding = 8.0; +const double _maxCalendarWidthLandscape = 384.0; +const double _maxCalendarWidthPortrait = 480.0; + +/// Displays a scrollable calendar grid that allows a user to select a range +/// of dates. +class _CalendarDateRangePicker extends StatefulWidget { + /// Creates a scrollable calendar grid for picking date ranges. + _CalendarDateRangePicker({ + DateTime? initialStartDate, + DateTime? initialEndDate, + required DateTime firstDate, + required DateTime lastDate, + DateTime? currentDate, + required this.onStartDateChanged, + required this.onEndDateChanged, + }) : initialStartDate = initialStartDate != null ? DateUtils.dateOnly(initialStartDate) : null, + initialEndDate = initialEndDate != null ? DateUtils.dateOnly(initialEndDate) : null, + firstDate = DateUtils.dateOnly(firstDate), + lastDate = DateUtils.dateOnly(lastDate), + currentDate = DateUtils.dateOnly(currentDate ?? DateTime.now()) { + assert( + this.initialStartDate == null || this.initialEndDate == null || !this.initialStartDate!.isAfter(initialEndDate!), + 'initialStartDate must be on or before initialEndDate.', + ); + assert( + !this.lastDate.isBefore(this.firstDate), + 'firstDate must be on or before lastDate.', + ); + } + + /// The [DateTime] that represents the start of the initial date range selection. + final DateTime? initialStartDate; + + /// The [DateTime] that represents the end of the initial date range selection. + final DateTime? initialEndDate; + + /// The earliest allowable [DateTime] that the user can select. + final DateTime firstDate; + + /// The latest allowable [DateTime] that the user can select. + final DateTime lastDate; + + /// The [DateTime] representing today. It will be highlighted in the day grid. + final DateTime currentDate; + + /// Called when the user changes the start date of the selected range. + final ValueChanged<DateTime>? onStartDateChanged; + + /// Called when the user changes the end date of the selected range. + final ValueChanged<DateTime?>? onEndDateChanged; + + @override + _CalendarDateRangePickerState createState() => _CalendarDateRangePickerState(); +} + +class _CalendarDateRangePickerState extends State<_CalendarDateRangePicker> { + final GlobalKey _scrollViewKey = GlobalKey(); + DateTime? _startDate; + DateTime? _endDate; + int _initialMonthIndex = 0; + late ScrollController _controller; + late bool _showWeekBottomDivider; + + @override + void initState() { + super.initState(); + _controller = ScrollController(); + _controller.addListener(_scrollListener); + + _startDate = widget.initialStartDate; + _endDate = widget.initialEndDate; + + // Calculate the index for the initially displayed month. This is needed to + // divide the list of months into two `SliverList`s. + final DateTime initialDate = widget.initialStartDate ?? widget.currentDate; + if (!initialDate.isBefore(widget.firstDate) && + !initialDate.isAfter(widget.lastDate)) { + _initialMonthIndex = DateUtils.monthDelta(widget.firstDate, initialDate); + } + + _showWeekBottomDivider = _initialMonthIndex != 0; + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + void _scrollListener() { + if (_controller.offset <= _controller.position.minScrollExtent) { + setState(() { + _showWeekBottomDivider = false; + }); + } else if (!_showWeekBottomDivider) { + setState(() { + _showWeekBottomDivider = true; + }); + } + } + + int get _numberOfMonths => DateUtils.monthDelta(widget.firstDate, widget.lastDate) + 1; + + void _vibrate() { + switch (Theme.of(context).platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + HapticFeedback.vibrate(); + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + break; + } + } + + // This updates the selected date range using this logic: + // + // * From the unselected state, selecting one date creates the start date. + // * If the next selection is before the start date, reset date range and + // set the start date to that selection. + // * If the next selection is on or after the start date, set the end date + // to that selection. + // * After both start and end dates are selected, any subsequent selection + // resets the date range and sets start date to that selection. + void _updateSelection(DateTime date) { + _vibrate(); + setState(() { + if (_startDate != null && _endDate == null && !date.isBefore(_startDate!)) { + _endDate = date; + widget.onEndDateChanged?.call(_endDate); + } else { + _startDate = date; + widget.onStartDateChanged?.call(_startDate!); + if (_endDate != null) { + _endDate = null; + widget.onEndDateChanged?.call(_endDate); + } + } + }); + } + + Widget _buildMonthItem(BuildContext context, int index, bool beforeInitialMonth) { + final int monthIndex = beforeInitialMonth + ? _initialMonthIndex - index - 1 + : _initialMonthIndex + index; + final DateTime month = DateUtils.addMonthsToMonthDate(widget.firstDate, monthIndex); + return _MonthItem( + selectedDateStart: _startDate, + selectedDateEnd: _endDate, + currentDate: widget.currentDate, + firstDate: widget.firstDate, + lastDate: widget.lastDate, + displayedMonth: month, + onChanged: _updateSelection, + ); + } + + @override + Widget build(BuildContext context) { + const Key sliverAfterKey = Key('sliverAfterKey'); + + return Column( + children: <Widget>[ + const _DayHeaders(), + if (_showWeekBottomDivider) const Divider(height: 0), + Expanded( + child: _CalendarKeyboardNavigator( + firstDate: widget.firstDate, + lastDate: widget.lastDate, + initialFocusedDay: _startDate ?? widget.initialStartDate ?? widget.currentDate, + // In order to prevent performance issues when displaying the + // correct initial month, 2 `SliverList`s are used to split the + // months. The first item in the second SliverList is the initial + // month to be displayed. + child: CustomScrollView( + key: _scrollViewKey, + controller: _controller, + center: sliverAfterKey, + slivers: <Widget>[ + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => _buildMonthItem(context, index, true), + childCount: _initialMonthIndex, + ), + ), + SliverList( + key: sliverAfterKey, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => _buildMonthItem(context, index, false), + childCount: _numberOfMonths - _initialMonthIndex, + ), + ), + ], + ), + ), + ), + ], + ); + } +} + +class _CalendarKeyboardNavigator extends StatefulWidget { + const _CalendarKeyboardNavigator({ + required this.child, + required this.firstDate, + required this.lastDate, + required this.initialFocusedDay, + }); + + final Widget child; + final DateTime firstDate; + final DateTime lastDate; + final DateTime initialFocusedDay; + + @override + _CalendarKeyboardNavigatorState createState() => _CalendarKeyboardNavigatorState(); +} + +class _CalendarKeyboardNavigatorState extends State<_CalendarKeyboardNavigator> { + + final Map<ShortcutActivator, Intent> _shortcutMap = const <ShortcutActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.arrowLeft): DirectionalFocusIntent(TraversalDirection.left), + SingleActivator(LogicalKeyboardKey.arrowRight): DirectionalFocusIntent(TraversalDirection.right), + SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent(TraversalDirection.down), + SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent(TraversalDirection.up), + }; + late Map<Type, Action<Intent>> _actionMap; + late FocusNode _dayGridFocus; + TraversalDirection? _dayTraversalDirection; + DateTime? _focusedDay; + + @override + void initState() { + super.initState(); + + _actionMap = <Type, Action<Intent>>{ + NextFocusIntent: CallbackAction<NextFocusIntent>(onInvoke: _handleGridNextFocus), + PreviousFocusIntent: CallbackAction<PreviousFocusIntent>(onInvoke: _handleGridPreviousFocus), + DirectionalFocusIntent: CallbackAction<DirectionalFocusIntent>(onInvoke: _handleDirectionFocus), + }; + _dayGridFocus = FocusNode(debugLabel: 'Day Grid'); + } + + @override + void dispose() { + _dayGridFocus.dispose(); + super.dispose(); + } + + void _handleGridFocusChange(bool focused) { + setState(() { + if (focused) { + _focusedDay ??= widget.initialFocusedDay; + } + }); + } + + /// Move focus to the next element after the day grid. + void _handleGridNextFocus(NextFocusIntent intent) { + _dayGridFocus.requestFocus(); + _dayGridFocus.nextFocus(); + } + + /// Move focus to the previous element before the day grid. + void _handleGridPreviousFocus(PreviousFocusIntent intent) { + _dayGridFocus.requestFocus(); + _dayGridFocus.previousFocus(); + } + + /// Move the internal focus date in the direction of the given intent. + /// + /// This will attempt to move the focused day to the next selectable day in + /// the given direction. If the new date is not in the current month, then + /// the page view will be scrolled to show the new date's month. + /// + /// For horizontal directions, it will move forward or backward a day (depending + /// on the current [TextDirection]). For vertical directions it will move up and + /// down a week at a time. + void _handleDirectionFocus(DirectionalFocusIntent intent) { + assert(_focusedDay != null); + setState(() { + final DateTime? nextDate = _nextDateInDirection(_focusedDay!, intent.direction); + if (nextDate != null) { + _focusedDay = nextDate; + _dayTraversalDirection = intent.direction; + } + }); + } + + static const Map<TraversalDirection, int> _directionOffset = <TraversalDirection, int>{ + TraversalDirection.up: -DateTime.daysPerWeek, + TraversalDirection.right: 1, + TraversalDirection.down: DateTime.daysPerWeek, + TraversalDirection.left: -1, + }; + + int _dayDirectionOffset(TraversalDirection traversalDirection, TextDirection textDirection) { + // Swap left and right if the text direction if RTL + if (textDirection == TextDirection.rtl) { + if (traversalDirection == TraversalDirection.left) { + traversalDirection = TraversalDirection.right; + } else if (traversalDirection == TraversalDirection.right) { + traversalDirection = TraversalDirection.left; + } + } + return _directionOffset[traversalDirection]!; + } + + DateTime? _nextDateInDirection(DateTime date, TraversalDirection direction) { + final TextDirection textDirection = Directionality.of(context); + final DateTime nextDate = DateUtils.addDaysToDate(date, _dayDirectionOffset(direction, textDirection)); + if (!nextDate.isBefore(widget.firstDate) && !nextDate.isAfter(widget.lastDate)) { + return nextDate; + } + return null; + } + + @override + Widget build(BuildContext context) { + return FocusableActionDetector( + shortcuts: _shortcutMap, + actions: _actionMap, + focusNode: _dayGridFocus, + onFocusChange: _handleGridFocusChange, + child: _FocusedDate( + date: _dayGridFocus.hasFocus ? _focusedDay : null, + scrollDirection: _dayGridFocus.hasFocus ? _dayTraversalDirection : null, + child: widget.child, + ), + ); + } +} + +/// InheritedWidget indicating what the current focused date is for its children. +/// +/// This is used by the [_MonthPicker] to let its children [_DayPicker]s know +/// what the currently focused date (if any) should be. +class _FocusedDate extends InheritedWidget { + const _FocusedDate({ + required super.child, + this.date, + this.scrollDirection, + }); + + final DateTime? date; + final TraversalDirection? scrollDirection; + + @override + bool updateShouldNotify(_FocusedDate oldWidget) { + return !DateUtils.isSameDay(date, oldWidget.date) || scrollDirection != oldWidget.scrollDirection; + } + + static _FocusedDate? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<_FocusedDate>(); + } +} + +class _DayHeaders extends StatelessWidget { + const _DayHeaders(); + + /// Builds widgets showing abbreviated days of week. The first widget in the + /// returned list corresponds to the first day of week for the current locale. + /// + /// Examples: + /// + /// ┌ Sunday is the first day of week in the US (en_US) + /// | + /// S M T W T F S ← the returned list contains these widgets + /// _ _ _ _ _ 1 2 + /// 3 4 5 6 7 8 9 + /// + /// ┌ But it's Monday in the UK (en_GB) + /// | + /// M T W T F S S ← the returned list contains these widgets + /// _ _ _ _ 1 2 3 + /// 4 5 6 7 8 9 10 + /// + List<Widget> _getDayHeaders(TextStyle headerStyle, MaterialLocalizations localizations) { + final List<Widget> result = <Widget>[]; + for (int i = localizations.firstDayOfWeekIndex; result.length < DateTime.daysPerWeek; i = (i + 1) % DateTime.daysPerWeek) { + final String weekday = localizations.narrowWeekdays[i]; + result.add(ExcludeSemantics( + child: Center(child: Text(weekday, style: headerStyle)), + )); + } + return result; + } + + @override + Widget build(BuildContext context) { + final ThemeData themeData = Theme.of(context); + final ColorScheme colorScheme = themeData.colorScheme; + final TextStyle textStyle = themeData.textTheme.titleSmall!.apply(color: colorScheme.onSurface); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final List<Widget> labels = _getDayHeaders(textStyle, localizations); + + // Add leading and trailing containers for edges of the custom grid layout. + labels.insert(0, Container()); + labels.add(Container()); + + return Container( + constraints: BoxConstraints( + maxWidth: MediaQuery.orientationOf(context) == Orientation.landscape + ? _maxCalendarWidthLandscape + : _maxCalendarWidthPortrait, + maxHeight: _monthItemRowHeight, + ), + child: GridView.custom( + shrinkWrap: true, + gridDelegate: _monthItemGridDelegate, + childrenDelegate: SliverChildListDelegate( + labels, + addRepaintBoundaries: false, + ), + ), + ); + } +} + +class _MonthItemGridDelegate extends SliverGridDelegate { + const _MonthItemGridDelegate(); + + @override + SliverGridLayout getLayout(SliverConstraints constraints) { + final double tileWidth = (constraints.crossAxisExtent - 2 * _horizontalPadding) / DateTime.daysPerWeek; + return _MonthSliverGridLayout( + crossAxisCount: DateTime.daysPerWeek + 2, + dayChildWidth: tileWidth, + edgeChildWidth: _horizontalPadding, + reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), + ); + } + + @override + bool shouldRelayout(_MonthItemGridDelegate oldDelegate) => false; +} + +const _MonthItemGridDelegate _monthItemGridDelegate = _MonthItemGridDelegate(); + +class _MonthSliverGridLayout extends SliverGridLayout { + /// Creates a layout that uses equally sized and spaced tiles for each day of + /// the week and an additional edge tile for padding at the start and end of + /// each row. + /// + /// This is necessary to facilitate the painting of the range highlight + /// correctly. + const _MonthSliverGridLayout({ + required this.crossAxisCount, + required this.dayChildWidth, + required this.edgeChildWidth, + required this.reverseCrossAxis, + }) : assert(crossAxisCount > 0), + assert(dayChildWidth >= 0), + assert(edgeChildWidth >= 0); + + /// The number of children in the cross axis. + final int crossAxisCount; + + /// The width in logical pixels of the day child widgets. + final double dayChildWidth; + + /// The width in logical pixels of the edge child widgets. + final double edgeChildWidth; + + /// Whether the children should be placed in the opposite order of increasing + /// coordinates in the cross axis. + /// + /// For example, if the cross axis is horizontal, the children are placed from + /// left to right when [reverseCrossAxis] is false and from right to left when + /// [reverseCrossAxis] is true. + /// + /// Typically set to the return value of [axisDirectionIsReversed] applied to + /// the [SliverConstraints.crossAxisDirection]. + final bool reverseCrossAxis; + + /// The number of logical pixels from the leading edge of one row to the + /// leading edge of the next row. + double get _rowHeight { + return _monthItemRowHeight + _monthItemSpaceBetweenRows; + } + + /// The height in logical pixels of the children widgets. + double get _childHeight { + return _monthItemRowHeight; + } + + @override + int getMinChildIndexForScrollOffset(double scrollOffset) { + return crossAxisCount * (scrollOffset ~/ _rowHeight); + } + + @override + int getMaxChildIndexForScrollOffset(double scrollOffset) { + final int mainAxisCount = (scrollOffset / _rowHeight).ceil(); + return math.max(0, crossAxisCount * mainAxisCount - 1); + } + + double _getCrossAxisOffset(double crossAxisStart, bool isPadding) { + if (reverseCrossAxis) { + return + ((crossAxisCount - 2) * dayChildWidth + 2 * edgeChildWidth) - + crossAxisStart - + (isPadding ? edgeChildWidth : dayChildWidth); + } + return crossAxisStart; + } + + @override + SliverGridGeometry getGeometryForChildIndex(int index) { + final int adjustedIndex = index % crossAxisCount; + final bool isEdge = adjustedIndex == 0 || adjustedIndex == crossAxisCount - 1; + final double crossAxisStart = math.max(0, (adjustedIndex - 1) * dayChildWidth + edgeChildWidth); + + return SliverGridGeometry( + scrollOffset: (index ~/ crossAxisCount) * _rowHeight, + crossAxisOffset: _getCrossAxisOffset(crossAxisStart, isEdge), + mainAxisExtent: _childHeight, + crossAxisExtent: isEdge ? edgeChildWidth : dayChildWidth, + ); + } + + @override + double computeMaxScrollOffset(int childCount) { + assert(childCount >= 0); + final int mainAxisCount = ((childCount - 1) ~/ crossAxisCount) + 1; + final double mainAxisSpacing = _rowHeight - _childHeight; + return _rowHeight * mainAxisCount - mainAxisSpacing; + } +} + +/// Displays the days of a given month and allows choosing a date range. +/// +/// The days are arranged in a rectangular grid with one column for each day of +/// the week. +class _MonthItem extends StatefulWidget { + /// Creates a month item. + _MonthItem({ + required this.selectedDateStart, + required this.selectedDateEnd, + required this.currentDate, + required this.onChanged, + required this.firstDate, + required this.lastDate, + required this.displayedMonth, + }) : assert(!firstDate.isAfter(lastDate)), + assert(selectedDateStart == null || !selectedDateStart.isBefore(firstDate)), + assert(selectedDateEnd == null || !selectedDateEnd.isBefore(firstDate)), + assert(selectedDateStart == null || !selectedDateStart.isAfter(lastDate)), + assert(selectedDateEnd == null || !selectedDateEnd.isAfter(lastDate)), + assert(selectedDateStart == null || selectedDateEnd == null || !selectedDateStart.isAfter(selectedDateEnd)); + + /// The currently selected start date. + /// + /// This date is highlighted in the picker. + final DateTime? selectedDateStart; + + /// The currently selected end date. + /// + /// This date is highlighted in the picker. + final DateTime? selectedDateEnd; + + /// The current date at the time the picker is displayed. + final DateTime currentDate; + + /// Called when the user picks a day. + final ValueChanged<DateTime> onChanged; + + /// The earliest date the user is permitted to pick. + final DateTime firstDate; + + /// The latest date the user is permitted to pick. + final DateTime lastDate; + + /// The month whose days are displayed by this picker. + final DateTime displayedMonth; + + @override + _MonthItemState createState() => _MonthItemState(); +} + +class _MonthItemState extends State<_MonthItem> { + /// List of [FocusNode]s, one for each day of the month. + late List<FocusNode> _dayFocusNodes; + + @override + void initState() { + super.initState(); + final int daysInMonth = DateUtils.getDaysInMonth(widget.displayedMonth.year, widget.displayedMonth.month); + _dayFocusNodes = List<FocusNode>.generate( + daysInMonth, + (int index) => FocusNode(skipTraversal: true, debugLabel: 'Day ${index + 1}'), + ); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + // Check to see if the focused date is in this month, if so focus it. + final DateTime? focusedDate = _FocusedDate.maybeOf(context)?.date; + if (focusedDate != null && DateUtils.isSameMonth(widget.displayedMonth, focusedDate)) { + _dayFocusNodes[focusedDate.day - 1].requestFocus(); + } + } + + @override + void dispose() { + for (final FocusNode node in _dayFocusNodes) { + node.dispose(); + } + super.dispose(); + } + + Color _highlightColor(BuildContext context) { + return DatePickerTheme.of(context).rangeSelectionBackgroundColor + ?? DatePickerTheme.defaults(context).rangeSelectionBackgroundColor!; + } + + void _dayFocusChanged(bool focused) { + if (focused) { + final TraversalDirection? focusDirection = _FocusedDate.maybeOf(context)?.scrollDirection; + if (focusDirection != null) { + ScrollPositionAlignmentPolicy policy = ScrollPositionAlignmentPolicy.explicit; + switch (focusDirection) { + case TraversalDirection.up: + case TraversalDirection.left: + policy = ScrollPositionAlignmentPolicy.keepVisibleAtStart; + case TraversalDirection.right: + case TraversalDirection.down: + policy = ScrollPositionAlignmentPolicy.keepVisibleAtEnd; + } + Scrollable.ensureVisible(primaryFocus!.context!, + duration: _monthScrollDuration, + alignmentPolicy: policy, + ); + } + } + } + + Widget _buildDayItem(BuildContext context, DateTime dayToBuild, int firstDayOffset, int daysInMonth) { + final int day = dayToBuild.day; + + final bool isDisabled = dayToBuild.isAfter(widget.lastDate) || dayToBuild.isBefore(widget.firstDate); + final bool isRangeSelected = widget.selectedDateStart != null && widget.selectedDateEnd != null; + final bool isSelectedDayStart = widget.selectedDateStart != null && dayToBuild.isAtSameMomentAs(widget.selectedDateStart!); + final bool isSelectedDayEnd = widget.selectedDateEnd != null && dayToBuild.isAtSameMomentAs(widget.selectedDateEnd!); + final bool isInRange = isRangeSelected && + dayToBuild.isAfter(widget.selectedDateStart!) && + dayToBuild.isBefore(widget.selectedDateEnd!); + final bool isOneDayRange = isRangeSelected && widget.selectedDateStart == widget.selectedDateEnd; + final bool isToday = DateUtils.isSameDay(widget.currentDate, dayToBuild); + + return _DayItem( + day: dayToBuild, + focusNode: _dayFocusNodes[day - 1], + onChanged: widget.onChanged, + onFocusChange: _dayFocusChanged, + highlightColor: _highlightColor(context), + isDisabled: isDisabled, + isRangeSelected: isRangeSelected, + isSelectedDayStart: isSelectedDayStart, + isSelectedDayEnd: isSelectedDayEnd, + isInRange: isInRange, + isOneDayRange: isOneDayRange, + isToday: isToday, + ); + } + + Widget _buildEdgeContainer(BuildContext context, bool isHighlighted) { + return Container(color: isHighlighted ? _highlightColor(context) : null); + } + + @override + Widget build(BuildContext context) { + final ThemeData themeData = Theme.of(context); + final TextTheme textTheme = themeData.textTheme; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final int year = widget.displayedMonth.year; + final int month = widget.displayedMonth.month; + final int daysInMonth = DateUtils.getDaysInMonth(year, month); + final int dayOffset = DateUtils.firstDayOffset(year, month, localizations); + final int weeks = ((daysInMonth + dayOffset) / DateTime.daysPerWeek).ceil(); + final double gridHeight = weeks * _monthItemRowHeight + (weeks - 1) * _monthItemSpaceBetweenRows; + final List<Widget> dayItems = <Widget>[]; + + // 1-based day of month, e.g. 1-31 for January, and 1-29 for February on + // a leap year. + for (int day = 0 - dayOffset + 1; day <= daysInMonth; day += 1) { + if (day < 1) { + dayItems.add(Container()); + } else { + final DateTime dayToBuild = DateTime(year, month, day); + final Widget dayItem = _buildDayItem( + context, + dayToBuild, + dayOffset, + daysInMonth, + ); + dayItems.add(dayItem); + } + } + + // Add the leading/trailing edge containers to each week in order to + // correctly extend the range highlight. + final List<Widget> paddedDayItems = <Widget>[]; + for (int i = 0; i < weeks; i++) { + final int start = i * DateTime.daysPerWeek; + final int end = math.min( + start + DateTime.daysPerWeek, + dayItems.length, + ); + final List<Widget> weekList = dayItems.sublist(start, end); + + final DateTime dateAfterLeadingPadding = DateTime(year, month, start - dayOffset + 1); + // Only color the edge container if it is after the start date and + // on/before the end date. + final bool isLeadingInRange = + !(dayOffset > 0 && i == 0) && + widget.selectedDateStart != null && + widget.selectedDateEnd != null && + dateAfterLeadingPadding.isAfter(widget.selectedDateStart!) && + !dateAfterLeadingPadding.isAfter(widget.selectedDateEnd!); + weekList.insert(0, _buildEdgeContainer(context, isLeadingInRange)); + + // Only add a trailing edge container if it is for a full week and not a + // partial week. + if (end < dayItems.length || (end == dayItems.length && dayItems.length % DateTime.daysPerWeek == 0)) { + final DateTime dateBeforeTrailingPadding = + DateTime(year, month, end - dayOffset); + // Only color the edge container if it is on/after the start date and + // before the end date. + final bool isTrailingInRange = + widget.selectedDateStart != null && + widget.selectedDateEnd != null && + !dateBeforeTrailingPadding.isBefore(widget.selectedDateStart!) && + dateBeforeTrailingPadding.isBefore(widget.selectedDateEnd!); + weekList.add(_buildEdgeContainer(context, isTrailingInRange)); + } + + paddedDayItems.addAll(weekList); + } + + final double maxWidth = MediaQuery.orientationOf(context) == Orientation.landscape + ? _maxCalendarWidthLandscape + : _maxCalendarWidthPortrait; + return Column( + children: <Widget>[ + Container( + constraints: BoxConstraints(maxWidth: maxWidth), + height: _monthItemHeaderHeight, + padding: const EdgeInsets.symmetric(horizontal: 16), + alignment: AlignmentDirectional.centerStart, + child: ExcludeSemantics( + child: Text( + localizations.formatMonthYear(widget.displayedMonth), + style: textTheme.bodyMedium!.apply(color: themeData.colorScheme.onSurface), + ), + ), + ), + Container( + constraints: BoxConstraints( + maxWidth: maxWidth, + maxHeight: gridHeight, + ), + child: GridView.custom( + physics: const NeverScrollableScrollPhysics(), + gridDelegate: _monthItemGridDelegate, + childrenDelegate: SliverChildListDelegate( + paddedDayItems, + addRepaintBoundaries: false, + ), + ), + ), + const SizedBox(height: _monthItemFooterHeight), + ], + ); + } +} + +class _DayItem extends StatefulWidget { + const _DayItem({ + required this.day, + required this.focusNode, + required this.onChanged, + required this.onFocusChange, + required this.highlightColor, + required this.isDisabled, + required this.isRangeSelected, + required this.isSelectedDayStart, + required this.isSelectedDayEnd, + required this.isInRange, + required this.isOneDayRange, + required this.isToday, + }); + + final DateTime day; + + final FocusNode focusNode; + + final ValueChanged<DateTime> onChanged; + + final ValueChanged<bool> onFocusChange; + + final Color highlightColor; + + final bool isDisabled; + + final bool isRangeSelected; + + final bool isSelectedDayStart; + + final bool isSelectedDayEnd; + + final bool isInRange; + + final bool isOneDayRange; + + final bool isToday; + + @override + State<_DayItem> createState() => _DayItemState(); +} + +class _DayItemState extends State<_DayItem> { + final MaterialStatesController _statesController = MaterialStatesController(); + + @override + void dispose() { + _statesController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final ColorScheme colorScheme = theme.colorScheme; + final TextTheme textTheme = theme.textTheme; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final DatePickerThemeData datePickerTheme = DatePickerTheme.of(context); + final DatePickerThemeData defaults = DatePickerTheme.defaults(context); + final TextDirection textDirection = Directionality.of(context); + final Color highlightColor = widget.highlightColor; + + BoxDecoration? decoration; + TextStyle? itemStyle = textTheme.bodyMedium; + + T? effectiveValue<T>(T? Function(DatePickerThemeData? theme) getProperty) { + return getProperty(datePickerTheme) ?? getProperty(defaults); + } + + T? resolve<T>(MaterialStateProperty<T>? Function(DatePickerThemeData? theme) getProperty, Set<MaterialState> states) { + return effectiveValue( + (DatePickerThemeData? theme) { + return getProperty(theme)?.resolve(states); + }, + ); + } + + final Set<MaterialState> states = <MaterialState>{ + if (widget.isDisabled) MaterialState.disabled, + if (widget.isSelectedDayStart || widget.isSelectedDayEnd) MaterialState.selected, + }; + + _statesController.value = states; + + final Color? dayForegroundColor = resolve<Color?>((DatePickerThemeData? theme) => theme?.dayForegroundColor, states); + final Color? dayBackgroundColor = resolve<Color?>((DatePickerThemeData? theme) => theme?.dayBackgroundColor, states); + final MaterialStateProperty<Color?> dayOverlayColor = MaterialStateProperty.resolveWith<Color?>( + (Set<MaterialState> states) => effectiveValue( + (DatePickerThemeData? theme) => widget.isInRange + ? theme?.rangeSelectionOverlayColor?.resolve(states) + : theme?.dayOverlayColor?.resolve(states), + ) + ); + + _HighlightPainter? highlightPainter; + + if (widget.isSelectedDayStart || widget.isSelectedDayEnd) { + // The selected start and end dates gets a circle background + // highlight, and a contrasting text color. + itemStyle = textTheme.bodyMedium?.apply(color: dayForegroundColor); + decoration = BoxDecoration( + color: dayBackgroundColor, + shape: BoxShape.circle, + ); + + if (widget.isRangeSelected && !widget.isOneDayRange) { + final _HighlightPainterStyle style = widget.isSelectedDayStart + ? _HighlightPainterStyle.highlightTrailing + : _HighlightPainterStyle.highlightLeading; + highlightPainter = _HighlightPainter( + color: highlightColor, + style: style, + textDirection: textDirection, + ); + } + } else if (widget.isInRange) { + // The days within the range get a light background highlight. + highlightPainter = _HighlightPainter( + color: highlightColor, + style: _HighlightPainterStyle.highlightAll, + textDirection: textDirection, + ); + } else if (widget.isDisabled) { + itemStyle = textTheme.bodyMedium?.apply(color: colorScheme.onSurface.withOpacity(0.38)); + } else if (widget.isToday) { + // The current day gets a different text color and a circle stroke + // border. + itemStyle = textTheme.bodyMedium?.apply(color: colorScheme.primary); + decoration = BoxDecoration( + border: Border.all(color: colorScheme.primary), + shape: BoxShape.circle, + ); + } + + final String dayText = localizations.formatDecimal(widget.day.day); + + // We want the day of month to be spoken first irrespective of the + // locale-specific preferences or TextDirection. This is because + // an accessibility user is more likely to be interested in the + // day of month before the rest of the date, as they are looking + // for the day of month. To do that we prepend day of month to the + // formatted full date. + final String semanticLabelSuffix = widget.isToday ? ', ${localizations.currentDateLabel}' : ''; + String semanticLabel = '$dayText, ${localizations.formatFullDate(widget.day)}$semanticLabelSuffix'; + if (widget.isSelectedDayStart) { + semanticLabel = localizations.dateRangeStartDateSemanticLabel(semanticLabel); + } else if (widget.isSelectedDayEnd) { + semanticLabel = localizations.dateRangeEndDateSemanticLabel(semanticLabel); + } + + Widget dayWidget = Container( + decoration: decoration, + child: Center( + child: Semantics( + label: semanticLabel, + selected: widget.isSelectedDayStart || widget.isSelectedDayEnd, + child: ExcludeSemantics( + child: Text(dayText, style: itemStyle), + ), + ), + ), + ); + + if (highlightPainter != null) { + dayWidget = CustomPaint( + painter: highlightPainter, + child: dayWidget, + ); + } + + if (!widget.isDisabled) { + dayWidget = InkResponse( + focusNode: widget.focusNode, + onTap: () => widget.onChanged(widget.day), + radius: _monthItemRowHeight / 2 + 4, + statesController: _statesController, + overlayColor: dayOverlayColor, + onFocusChange: widget.onFocusChange, + child: dayWidget, + ); + } + + return dayWidget; + } +} + +/// Determines which style to use to paint the highlight. +enum _HighlightPainterStyle { + /// Paints nothing. + none, + + /// Paints a rectangle that occupies the leading half of the space. + highlightLeading, + + /// Paints a rectangle that occupies the trailing half of the space. + highlightTrailing, + + /// Paints a rectangle that occupies all available space. + highlightAll, +} + +/// This custom painter will add a background highlight to its child. +/// +/// This highlight will be drawn depending on the [style], [color], and +/// [textDirection] supplied. It will either paint a rectangle on the +/// left/right, a full rectangle, or nothing at all. This logic is determined by +/// a combination of the [style] and [textDirection]. +class _HighlightPainter extends CustomPainter { + _HighlightPainter({ + required this.color, + this.style = _HighlightPainterStyle.none, + this.textDirection, + }); + + final Color color; + final _HighlightPainterStyle style; + final TextDirection? textDirection; + + @override + void paint(Canvas canvas, Size size) { + if (style == _HighlightPainterStyle.none) { + return; + } + + final Paint paint = Paint() + ..color = color + ..style = PaintingStyle.fill; + + final Rect rectLeft = Rect.fromLTWH(0, 0, size.width / 2, size.height); + final Rect rectRight = Rect.fromLTWH(size.width / 2, 0, size.width / 2, size.height); + + switch (style) { + case _HighlightPainterStyle.highlightTrailing: + canvas.drawRect( + textDirection == TextDirection.ltr ? rectRight : rectLeft, + paint, + ); + case _HighlightPainterStyle.highlightLeading: + canvas.drawRect( + textDirection == TextDirection.ltr ? rectLeft : rectRight, + paint, + ); + case _HighlightPainterStyle.highlightAll: + canvas.drawRect( + Rect.fromLTWH(0, 0, size.width, size.height), + paint, + ); + case _HighlightPainterStyle.none: + break; + } + } + + @override + bool shouldRepaint(CustomPainter oldDelegate) => false; +} + +class _InputDateRangePickerDialog extends StatelessWidget { + const _InputDateRangePickerDialog({ + required this.selectedStartDate, + required this.selectedEndDate, + required this.currentDate, + required this.picker, + required this.onConfirm, + required this.onCancel, + required this.confirmText, + required this.cancelText, + required this.helpText, + required this.entryModeButton, + }); + + final DateTime? selectedStartDate; + final DateTime? selectedEndDate; + final DateTime? currentDate; + final Widget picker; + final VoidCallback onConfirm; + final VoidCallback onCancel; + final String? confirmText; + final String? cancelText; + final String? helpText; + final Widget? entryModeButton; + + String _formatDateRange(BuildContext context, DateTime? start, DateTime? end, DateTime now) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final String startText = _formatRangeStartDate(localizations, start, end); + final String endText = _formatRangeEndDate(localizations, start, end, now); + if (start == null || end == null) { + return localizations.unspecifiedDateRange; + } + if (Directionality.of(context) == TextDirection.ltr) { + return '$startText – $endText'; + } else { + return '$endText – $startText'; + } + } + + @override + Widget build(BuildContext context) { + final bool useMaterial3 = Theme.of(context).useMaterial3; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final Orientation orientation = MediaQuery.orientationOf(context); + final DatePickerThemeData datePickerTheme = DatePickerTheme.of(context); + final DatePickerThemeData defaults = DatePickerTheme.defaults(context); + + // There's no M3 spec for a landscape layout input (not calendar) + // date range picker. To ensure that the date range displayed in the + // input date range picker's header fits in landscape mode, we override + // the M3 default here. + TextStyle? headlineStyle = (orientation == Orientation.portrait) + ? datePickerTheme.headerHeadlineStyle ?? defaults.headerHeadlineStyle + : Theme.of(context).textTheme.headlineSmall; + + final Color? headerForegroundColor = datePickerTheme.headerForegroundColor ?? defaults.headerForegroundColor; + headlineStyle = headlineStyle?.copyWith(color: headerForegroundColor); + + final String dateText = _formatDateRange(context, selectedStartDate, selectedEndDate, currentDate!); + final String semanticDateText = selectedStartDate != null && selectedEndDate != null + ? '${localizations.formatMediumDate(selectedStartDate!)} – ${localizations.formatMediumDate(selectedEndDate!)}' + : ''; + + final Widget header = _DatePickerHeader( + helpText: helpText ?? ( + useMaterial3 + ? localizations.dateRangePickerHelpText + : localizations.dateRangePickerHelpText.toUpperCase() + ), + titleText: dateText, + titleSemanticsLabel: semanticDateText, + titleStyle: headlineStyle, + orientation: orientation, + isShort: orientation == Orientation.landscape, + entryModeButton: entryModeButton, + ); + + final Widget actions = Container( + alignment: AlignmentDirectional.centerEnd, + constraints: const BoxConstraints(minHeight: 52.0), + padding: const EdgeInsets.symmetric(horizontal: 8), + child: OverflowBar( + spacing: 8, + children: <Widget>[ + TextButton( + onPressed: onCancel, + child: Text(cancelText ?? ( + useMaterial3 + ? localizations.cancelButtonLabel + : localizations.cancelButtonLabel.toUpperCase() + )), + ), + TextButton( + onPressed: onConfirm, + child: Text(confirmText ?? localizations.okButtonLabel), + ), + ], + ), + ); + + final double textScaleFactor = MediaQuery.textScalerOf(context).clamp(maxScaleFactor: _kMaxTextScaleFactor).textScaleFactor; + final Size dialogSize = (useMaterial3 ? _inputPortraitDialogSizeM3 : _inputPortraitDialogSizeM2) * textScaleFactor; + switch (orientation) { + case Orientation.portrait: + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + final Size portraitDialogSize = useMaterial3 ? _inputPortraitDialogSizeM3 : _inputPortraitDialogSizeM2; + // Make sure the portrait dialog can fit the contents comfortably when + // resized from the landscape dialog. + final bool isFullyPortrait = constraints.maxHeight >= math.min(dialogSize.height, portraitDialogSize.height); + + return Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + header, + if (isFullyPortrait) ...<Widget>[ + Expanded(child: picker), + actions, + ], + ], + ); + } + ); + + case Orientation.landscape: + return Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + header, + Flexible( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + Expanded(child: picker), + actions, + ], + ), + ), + ], + ); + } + } +} + +/// Provides a pair of text fields that allow the user to enter the start and +/// end dates that represent a range of dates. +class _InputDateRangePicker extends StatefulWidget { + /// Creates a row with two text fields configured to accept the start and end dates + /// of a date range. + _InputDateRangePicker({ + super.key, + DateTime? initialStartDate, + DateTime? initialEndDate, + required DateTime firstDate, + required DateTime lastDate, + required this.onStartDateChanged, + required this.onEndDateChanged, + this.helpText, + this.errorFormatText, + this.errorInvalidText, + this.errorInvalidRangeText, + this.fieldStartHintText, + this.fieldEndHintText, + this.fieldStartLabelText, + this.fieldEndLabelText, + this.autofocus = false, + this.autovalidate = false, + this.keyboardType = TextInputType.datetime, + }) : initialStartDate = initialStartDate == null ? null : DateUtils.dateOnly(initialStartDate), + initialEndDate = initialEndDate == null ? null : DateUtils.dateOnly(initialEndDate), + firstDate = DateUtils.dateOnly(firstDate), + lastDate = DateUtils.dateOnly(lastDate); + + /// The [DateTime] that represents the start of the initial date range selection. + final DateTime? initialStartDate; + + /// The [DateTime] that represents the end of the initial date range selection. + final DateTime? initialEndDate; + + /// The earliest allowable [DateTime] that the user can select. + final DateTime firstDate; + + /// The latest allowable [DateTime] that the user can select. + final DateTime lastDate; + + /// Called when the user changes the start date of the selected range. + final ValueChanged<DateTime?>? onStartDateChanged; + + /// Called when the user changes the end date of the selected range. + final ValueChanged<DateTime?>? onEndDateChanged; + + /// The text that is displayed at the top of the header. + /// + /// This is used to indicate to the user what they are selecting a date for. + final String? helpText; + + /// Error text used to indicate the text in a field is not a valid date. + final String? errorFormatText; + + /// Error text used to indicate the date in a field is not in the valid range + /// of [firstDate] - [lastDate]. + final String? errorInvalidText; + + /// Error text used to indicate the dates given don't form a valid date + /// range (i.e. the start date is after the end date). + final String? errorInvalidRangeText; + + /// Hint text shown when the start date field is empty. + final String? fieldStartHintText; + + /// Hint text shown when the end date field is empty. + final String? fieldEndHintText; + + /// Label used for the start date field. + final String? fieldStartLabelText; + + /// Label used for the end date field. + final String? fieldEndLabelText; + + /// {@macro flutter.widgets.editableText.autofocus} + final bool autofocus; + + /// If true, the date fields will validate and update their error text + /// immediately after every change. Otherwise, you must call + /// [_InputDateRangePickerState.validate] to validate. + final bool autovalidate; + + /// {@macro flutter.material.datePickerDialog} + final TextInputType keyboardType; + + @override + _InputDateRangePickerState createState() => _InputDateRangePickerState(); +} + +/// The current state of an [_InputDateRangePicker]. Can be used to +/// [validate] the date field entries. +class _InputDateRangePickerState extends State<_InputDateRangePicker> { + late String _startInputText; + late String _endInputText; + DateTime? _startDate; + DateTime? _endDate; + late TextEditingController _startController; + late TextEditingController _endController; + String? _startErrorText; + String? _endErrorText; + bool _autoSelected = false; + + @override + void initState() { + super.initState(); + _startDate = widget.initialStartDate; + _startController = TextEditingController(); + _endDate = widget.initialEndDate; + _endController = TextEditingController(); + } + + @override + void dispose() { + _startController.dispose(); + _endController.dispose(); + super.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + if (_startDate != null) { + _startInputText = localizations.formatCompactDate(_startDate!); + final bool selectText = widget.autofocus && !_autoSelected; + _updateController(_startController, _startInputText, selectText); + _autoSelected = selectText; + } + + if (_endDate != null) { + _endInputText = localizations.formatCompactDate(_endDate!); + _updateController(_endController, _endInputText, false); + } + } + + /// Validates that the text in the start and end fields represent a valid + /// date range. + /// + /// Will return true if the range is valid. If not, it will + /// return false and display an appropriate error message under one of the + /// text fields. + bool validate() { + String? startError = _validateDate(_startDate); + final String? endError = _validateDate(_endDate); + if (startError == null && endError == null) { + if (_startDate!.isAfter(_endDate!)) { + startError = widget.errorInvalidRangeText ?? MaterialLocalizations.of(context).invalidDateRangeLabel; + } + } + setState(() { + _startErrorText = startError; + _endErrorText = endError; + }); + return startError == null && endError == null; + } + + DateTime? _parseDate(String? text) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + return localizations.parseCompactDate(text); + } + + String? _validateDate(DateTime? date) { + if (date == null) { + return widget.errorFormatText ?? MaterialLocalizations.of(context).invalidDateFormatLabel; + } else if (date.isBefore(widget.firstDate) || date.isAfter(widget.lastDate)) { + return widget.errorInvalidText ?? MaterialLocalizations.of(context).dateOutOfRangeLabel; + } + return null; + } + + void _updateController(TextEditingController controller, String text, bool selectText) { + TextEditingValue textEditingValue = controller.value.copyWith(text: text); + if (selectText) { + textEditingValue = textEditingValue.copyWith(selection: TextSelection( + baseOffset: 0, + extentOffset: text.length, + )); + } + controller.value = textEditingValue; + } + + void _handleStartChanged(String text) { + setState(() { + _startInputText = text; + _startDate = _parseDate(text); + widget.onStartDateChanged?.call(_startDate); + }); + if (widget.autovalidate) { + validate(); + } + } + + void _handleEndChanged(String text) { + setState(() { + _endInputText = text; + _endDate = _parseDate(text); + widget.onEndDateChanged?.call(_endDate); + }); + if (widget.autovalidate) { + validate(); + } + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final bool useMaterial3 = theme.useMaterial3; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final InputDecorationTheme inputTheme = theme.inputDecorationTheme; + final InputBorder inputBorder = inputTheme.border + ?? (useMaterial3 ? const OutlineInputBorder() : const UnderlineInputBorder()); + + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Expanded( + child: TextField( + controller: _startController, + decoration: InputDecoration( + border: inputBorder, + filled: inputTheme.filled, + hintText: widget.fieldStartHintText ?? localizations.dateHelpText, + labelText: widget.fieldStartLabelText ?? localizations.dateRangeStartLabel, + errorText: _startErrorText, + ), + keyboardType: widget.keyboardType, + onChanged: _handleStartChanged, + autofocus: widget.autofocus, + ), + ), + const SizedBox(width: 8), + Expanded( + child: TextField( + controller: _endController, + decoration: InputDecoration( + border: inputBorder, + filled: inputTheme.filled, + hintText: widget.fieldEndHintText ?? localizations.dateHelpText, + labelText: widget.fieldEndLabelText ?? localizations.dateRangeEndLabel, + errorText: _endErrorText, + ), + keyboardType: widget.keyboardType, + onChanged: _handleEndChanged, + ), + ), + ], + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/date_picker_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/date_picker_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..d2c75856b384101472d14682c85342aaca7245f3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/date_picker_theme.dart @@ -0,0 +1,1040 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'input_decorator.dart'; +import 'material_state.dart'; +import 'text_button.dart'; +import 'text_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Overrides the default values of visual properties for descendant +/// [DatePickerDialog] widgets. +/// +/// Descendant widgets obtain the current [DatePickerThemeData] object with +/// [DatePickerTheme.of]. Instances of [DatePickerTheme] can +/// be customized with [DatePickerThemeData.copyWith]. +/// +/// Typically a [DatePickerTheme] is specified as part of the overall +/// [Theme] with [ThemeData.datePickerTheme]. +/// +/// All [DatePickerThemeData] properties are null by default. When null, +/// the [DatePickerDialog] computes its own default values, typically based on +/// the overall theme's [ThemeData.colorScheme], [ThemeData.textTheme], and +/// [ThemeData.iconTheme]. +@immutable +class DatePickerThemeData with Diagnosticable { + /// Creates a [DatePickerThemeData] that can be used to override default properties + /// in a [DatePickerTheme] widget. + const DatePickerThemeData({ + this.backgroundColor, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.shape, + this.headerBackgroundColor, + this.headerForegroundColor, + this.headerHeadlineStyle, + this.headerHelpStyle, + this.weekdayStyle, + this.dayStyle, + this.dayForegroundColor, + this.dayBackgroundColor, + this.dayOverlayColor, + this.todayForegroundColor, + this.todayBackgroundColor, + this.todayBorder, + this.yearStyle, + this.yearForegroundColor, + this.yearBackgroundColor, + this.yearOverlayColor, + this.rangePickerBackgroundColor, + this.rangePickerElevation, + this.rangePickerShadowColor, + this.rangePickerSurfaceTintColor, + this.rangePickerShape, + this.rangePickerHeaderBackgroundColor, + this.rangePickerHeaderForegroundColor, + this.rangePickerHeaderHeadlineStyle, + this.rangePickerHeaderHelpStyle, + this.rangeSelectionBackgroundColor, + this.rangeSelectionOverlayColor, + this.dividerColor, + this.inputDecorationTheme, + this.cancelButtonStyle, + this.confirmButtonStyle, + }); + + /// Overrides the default value of [Dialog.backgroundColor]. + final Color? backgroundColor; + + /// Overrides the default value of [Dialog.elevation]. + /// + /// See also: + /// [Material.elevation], which explains how elevation is related to a component's shadow. + final double? elevation; + + /// Overrides the default value of [Dialog.shadowColor]. + /// + /// See also: + /// [Material.shadowColor], which explains how the shadow is rendered. + final Color? shadowColor; + + /// Overrides the default value of [Dialog.surfaceTintColor]. + /// + /// See also: + /// [Material.surfaceTintColor], which explains how this color is related to + /// [elevation] and [backgroundColor]. + final Color? surfaceTintColor; + + /// Overrides the default value of [Dialog.shape]. + /// + /// If [elevation] is greater than zero then a shadow is shown and the shadow's + /// shape mirrors the shape of the dialog. + final ShapeBorder? shape; + + /// Overrides the header's default background fill color. + /// + /// The dialog's header displays the currently selected date. + final Color? headerBackgroundColor; + + /// Overrides the header's default color used for text labels and icons. + /// + /// The dialog's header displays the currently selected date. + /// + /// This is used instead of the [TextStyle.color] property of [headerHeadlineStyle] + /// and [headerHelpStyle]. + final Color? headerForegroundColor; + + /// Overrides the header's default headline text style. + /// + /// The dialog's header displays the currently selected date. + /// + /// The [TextStyle.color] of the [headerHeadlineStyle] is not used, + /// [headerForegroundColor] is used instead. + final TextStyle? headerHeadlineStyle; + + /// Overrides the header's default help text style. + /// + /// The help text (also referred to as "supporting text" in the Material + /// spec) is usually a prompt to the user at the top of the header + /// (i.e. 'Select date'). + /// + /// The [TextStyle.color] of the [headerHelpStyle] is not used, + /// [headerForegroundColor] is used instead. + /// + /// See also: + /// [DatePickerDialog.helpText], which specifies the help text. + final TextStyle? headerHelpStyle; + + /// Overrides the default text style used for the row of weekday + /// labels at the top of the date picker grid. + final TextStyle? weekdayStyle; + + /// Overrides the default text style used for each individual day + /// label in the grid of the date picker. + /// + /// The [TextStyle.color] of the [dayStyle] is not used, + /// [dayForegroundColor] is used instead. + final TextStyle? dayStyle; + + /// Overrides the default color used to paint the day labels in the + /// grid of the date picker. + /// + /// This will be used instead of the color provided in [dayStyle]. + final MaterialStateProperty<Color?>? dayForegroundColor; + + /// Overrides the default color used to paint the background of the + /// day labels in the grid of the date picker. + final MaterialStateProperty<Color?>? dayBackgroundColor; + + /// Overrides the default highlight color that's typically used to + /// indicate that a day in the grid is focused, hovered, or pressed. + final MaterialStateProperty<Color?>? dayOverlayColor; + + /// Overrides the default color used to paint the + /// [DatePickerDialog.currentDate] label in the grid of the dialog's + /// [CalendarDatePicker] and the corresponding year in the dialog's + /// [YearPicker]. + /// + /// This will be used instead of the [TextStyle.color] provided in [dayStyle]. + final MaterialStateProperty<Color?>? todayForegroundColor; + + /// Overrides the default color used to paint the background of the + /// [DatePickerDialog.currentDate] label in the grid of the date picker. + final MaterialStateProperty<Color?>? todayBackgroundColor; + + /// Overrides the border used to paint the + /// [DatePickerDialog.currentDate] label in the grid of the date + /// picker. + /// + /// The border side's [BorderSide.color] is not used, + /// [todayForegroundColor] is used instead. + final BorderSide? todayBorder; + + /// Overrides the default text style used to paint each of the year + /// entries in the year selector of the date picker. + /// + /// The [TextStyle.color] of the [yearStyle] is not used, + /// [yearForegroundColor] is used instead. + final TextStyle? yearStyle; + + /// Overrides the default color used to paint the year labels in the year + /// selector of the date picker. + /// + /// This will be used instead of the color provided in [yearStyle]. + final MaterialStateProperty<Color?>? yearForegroundColor; + + /// Overrides the default color used to paint the background of the + /// year labels in the year selector of the of the date picker. + final MaterialStateProperty<Color?>? yearBackgroundColor; + + /// Overrides the default highlight color that's typically used to + /// indicate that a year in the year selector is focused, hovered, + /// or pressed. + final MaterialStateProperty<Color?>? yearOverlayColor; + + /// Overrides the default [Scaffold.backgroundColor] for + /// [DateRangePickerDialog]. + final Color? rangePickerBackgroundColor; + + /// Overrides the default elevation of the full screen + /// [DateRangePickerDialog]. + /// + /// See also: + /// [Material.elevation], which explains how elevation is related to a component's shadow. + final double? rangePickerElevation; + + /// Overrides the color of the shadow painted below a full screen + /// [DateRangePickerDialog]. + /// + /// See also: + /// [Material.shadowColor], which explains how the shadow is rendered. + final Color? rangePickerShadowColor; + + /// Overrides the default color of the surface tint overlay applied + /// to the [backgroundColor] of a full screen + /// [DateRangePickerDialog]'s to indicate elevation. + /// + /// See also: + /// [Material.surfaceTintColor], which explains how this color is related to + /// [elevation]. + final Color? rangePickerSurfaceTintColor; + + /// Overrides the default overall shape of a full screen + /// [DateRangePickerDialog]. + /// + /// If [elevation] is greater than zero then a shadow is shown and the shadow's + /// shape mirrors the shape of the dialog. + /// + /// [Material.surfaceTintColor], which explains how this color is related to + /// [elevation]. + final ShapeBorder? rangePickerShape; + + /// Overrides the default background fill color for [DateRangePickerDialog]. + /// + /// The dialog's header displays the currently selected date range. + final Color? rangePickerHeaderBackgroundColor; + + /// Overrides the default color used for text labels and icons in + /// the header of a full screen [DateRangePickerDialog] + /// + /// The dialog's header displays the currently selected date range. + /// + /// This is used instead of any colors provided by + /// [rangePickerHeaderHeadlineStyle] or [rangePickerHeaderHelpStyle]. + final Color? rangePickerHeaderForegroundColor; + + /// Overrides the default text style used for the headline text in + /// the header of a full screen [DateRangePickerDialog]. + /// + /// The dialog's header displays the currently selected date range. + /// + /// The [TextStyle.color] of [rangePickerHeaderHeadlineStyle] is not used, + /// [rangePickerHeaderForegroundColor] is used instead. + final TextStyle? rangePickerHeaderHeadlineStyle; + + /// Overrides the default text style used for the help text of the + /// header of a full screen [DateRangePickerDialog]. + /// + /// The help text (also referred to as "supporting text" in the Material + /// spec) is usually a prompt to the user at the top of the header + /// (i.e. 'Select date'). + /// + /// The [TextStyle.color] of the [rangePickerHeaderHelpStyle] is not used, + /// [rangePickerHeaderForegroundColor] is used instead. + /// + /// See also: + /// [DateRangePickerDialog.helpText], which specifies the help text. + final TextStyle? rangePickerHeaderHelpStyle; + + /// Overrides the default background color used to paint days + /// selected between the start and end dates in a + /// [DateRangePickerDialog]. + final Color? rangeSelectionBackgroundColor; + + /// Overrides the default highlight color that's typically used to + /// indicate that a date in the selected range of a + /// [DateRangePickerDialog] is focused, hovered, or pressed. + final MaterialStateProperty<Color?>? rangeSelectionOverlayColor; + + /// Overrides the default color used to paint the horizontal divider + /// below the header text when dialog is in in portrait orientation + /// and vertical divider when the dialog is in landscape orientation. + final Color? dividerColor; + + /// Overrides the [InputDatePickerFormField]'s input decoration theme. + /// If this is null, [ThemeData.inputDecorationTheme] is used instead. + final InputDecorationTheme? inputDecorationTheme; + + /// Overrides the default style of the cancel button of a [DatePickerDialog]. + final ButtonStyle? cancelButtonStyle; + + /// Overrides the default style of the confirm (OK) button of a [DatePickerDialog]. + final ButtonStyle? confirmButtonStyle; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + DatePickerThemeData copyWith({ + Color? backgroundColor, + double? elevation, + Color? shadowColor, + Color? surfaceTintColor, + ShapeBorder? shape, + Color? headerBackgroundColor, + Color? headerForegroundColor, + TextStyle? headerHeadlineStyle, + TextStyle? headerHelpStyle, + TextStyle? weekdayStyle, + TextStyle? dayStyle, + MaterialStateProperty<Color?>? dayForegroundColor, + MaterialStateProperty<Color?>? dayBackgroundColor, + MaterialStateProperty<Color?>? dayOverlayColor, + MaterialStateProperty<Color?>? todayForegroundColor, + MaterialStateProperty<Color?>? todayBackgroundColor, + BorderSide? todayBorder, + TextStyle? yearStyle, + MaterialStateProperty<Color?>? yearForegroundColor, + MaterialStateProperty<Color?>? yearBackgroundColor, + MaterialStateProperty<Color?>? yearOverlayColor, + Color? rangePickerBackgroundColor, + double? rangePickerElevation, + Color? rangePickerShadowColor, + Color? rangePickerSurfaceTintColor, + ShapeBorder? rangePickerShape, + Color? rangePickerHeaderBackgroundColor, + Color? rangePickerHeaderForegroundColor, + TextStyle? rangePickerHeaderHeadlineStyle, + TextStyle? rangePickerHeaderHelpStyle, + Color? rangeSelectionBackgroundColor, + MaterialStateProperty<Color?>? rangeSelectionOverlayColor, + Color? dividerColor, + InputDecorationTheme? inputDecorationTheme, + ButtonStyle? cancelButtonStyle, + ButtonStyle? confirmButtonStyle, + }) { + return DatePickerThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + elevation: elevation ?? this.elevation, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + shape: shape ?? this.shape, + headerBackgroundColor: headerBackgroundColor ?? this.headerBackgroundColor, + headerForegroundColor: headerForegroundColor ?? this.headerForegroundColor, + headerHeadlineStyle: headerHeadlineStyle ?? this.headerHeadlineStyle, + headerHelpStyle: headerHelpStyle ?? this.headerHelpStyle, + weekdayStyle: weekdayStyle ?? this.weekdayStyle, + dayStyle: dayStyle ?? this.dayStyle, + dayForegroundColor: dayForegroundColor ?? this.dayForegroundColor, + dayBackgroundColor: dayBackgroundColor ?? this.dayBackgroundColor, + dayOverlayColor: dayOverlayColor ?? this.dayOverlayColor, + todayForegroundColor: todayForegroundColor ?? this.todayForegroundColor, + todayBackgroundColor: todayBackgroundColor ?? this.todayBackgroundColor, + todayBorder: todayBorder ?? this.todayBorder, + yearStyle: yearStyle ?? this.yearStyle, + yearForegroundColor: yearForegroundColor ?? this.yearForegroundColor, + yearBackgroundColor: yearBackgroundColor ?? this.yearBackgroundColor, + yearOverlayColor: yearOverlayColor ?? this.yearOverlayColor, + rangePickerBackgroundColor: rangePickerBackgroundColor ?? this.rangePickerBackgroundColor, + rangePickerElevation: rangePickerElevation ?? this.rangePickerElevation, + rangePickerShadowColor: rangePickerShadowColor ?? this.rangePickerShadowColor, + rangePickerSurfaceTintColor: rangePickerSurfaceTintColor ?? this.rangePickerSurfaceTintColor, + rangePickerShape: rangePickerShape ?? this.rangePickerShape, + rangePickerHeaderBackgroundColor: rangePickerHeaderBackgroundColor ?? this.rangePickerHeaderBackgroundColor, + rangePickerHeaderForegroundColor: rangePickerHeaderForegroundColor ?? this.rangePickerHeaderForegroundColor, + rangePickerHeaderHeadlineStyle: rangePickerHeaderHeadlineStyle ?? this.rangePickerHeaderHeadlineStyle, + rangePickerHeaderHelpStyle: rangePickerHeaderHelpStyle ?? this.rangePickerHeaderHelpStyle, + rangeSelectionBackgroundColor: rangeSelectionBackgroundColor ?? this.rangeSelectionBackgroundColor, + rangeSelectionOverlayColor: rangeSelectionOverlayColor ?? this.rangeSelectionOverlayColor, + dividerColor: dividerColor ?? this.dividerColor, + inputDecorationTheme: inputDecorationTheme ?? this.inputDecorationTheme, + cancelButtonStyle: cancelButtonStyle ?? this.cancelButtonStyle, + confirmButtonStyle: confirmButtonStyle ?? this.confirmButtonStyle, + ); + } + + /// Linearly interpolates between two [DatePickerThemeData]. + static DatePickerThemeData lerp(DatePickerThemeData? a, DatePickerThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return DatePickerThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + headerBackgroundColor: Color.lerp(a?.headerBackgroundColor, b?.headerBackgroundColor, t), + headerForegroundColor: Color.lerp(a?.headerForegroundColor, b?.headerForegroundColor, t), + headerHeadlineStyle: TextStyle.lerp(a?.headerHeadlineStyle, b?.headerHeadlineStyle, t), + headerHelpStyle: TextStyle.lerp(a?.headerHelpStyle, b?.headerHelpStyle, t), + weekdayStyle: TextStyle.lerp(a?.weekdayStyle, b?.weekdayStyle, t), + dayStyle: TextStyle.lerp(a?.dayStyle, b?.dayStyle, t), + dayForegroundColor: MaterialStateProperty.lerp<Color?>(a?.dayForegroundColor, b?.dayForegroundColor, t, Color.lerp), + dayBackgroundColor: MaterialStateProperty.lerp<Color?>(a?.dayBackgroundColor, b?.dayBackgroundColor, t, Color.lerp), + dayOverlayColor: MaterialStateProperty.lerp<Color?>(a?.dayOverlayColor, b?.dayOverlayColor, t, Color.lerp), + todayForegroundColor: MaterialStateProperty.lerp<Color?>(a?.todayForegroundColor, b?.todayForegroundColor, t, Color.lerp), + todayBackgroundColor: MaterialStateProperty.lerp<Color?>(a?.todayBackgroundColor, b?.todayBackgroundColor, t, Color.lerp), + todayBorder: _lerpBorderSide(a?.todayBorder, b?.todayBorder, t), + yearStyle: TextStyle.lerp(a?.yearStyle, b?.yearStyle, t), + yearForegroundColor: MaterialStateProperty.lerp<Color?>(a?.yearForegroundColor, b?.yearForegroundColor, t, Color.lerp), + yearBackgroundColor: MaterialStateProperty.lerp<Color?>(a?.yearBackgroundColor, b?.yearBackgroundColor, t, Color.lerp), + yearOverlayColor: MaterialStateProperty.lerp<Color?>(a?.yearOverlayColor, b?.yearOverlayColor, t, Color.lerp), + rangePickerBackgroundColor: Color.lerp(a?.rangePickerBackgroundColor, b?.rangePickerBackgroundColor, t), + rangePickerElevation: lerpDouble(a?.rangePickerElevation, b?.rangePickerElevation, t), + rangePickerShadowColor: Color.lerp(a?.rangePickerShadowColor, b?.rangePickerShadowColor, t), + rangePickerSurfaceTintColor: Color.lerp(a?.rangePickerSurfaceTintColor, b?.rangePickerSurfaceTintColor, t), + rangePickerShape: ShapeBorder.lerp(a?.rangePickerShape, b?.rangePickerShape, t), + rangePickerHeaderBackgroundColor: Color.lerp(a?.rangePickerHeaderBackgroundColor, b?.rangePickerHeaderBackgroundColor, t), + rangePickerHeaderForegroundColor: Color.lerp(a?.rangePickerHeaderForegroundColor, b?.rangePickerHeaderForegroundColor, t), + rangePickerHeaderHeadlineStyle: TextStyle.lerp(a?.rangePickerHeaderHeadlineStyle, b?.rangePickerHeaderHeadlineStyle, t), + rangePickerHeaderHelpStyle: TextStyle.lerp(a?.rangePickerHeaderHelpStyle, b?.rangePickerHeaderHelpStyle, t), + rangeSelectionBackgroundColor: Color.lerp(a?.rangeSelectionBackgroundColor, b?.rangeSelectionBackgroundColor, t), + rangeSelectionOverlayColor: MaterialStateProperty.lerp<Color?>(a?.rangeSelectionOverlayColor, b?.rangeSelectionOverlayColor, t, Color.lerp), + dividerColor: Color.lerp(a?.dividerColor, b?.dividerColor, t), + inputDecorationTheme: t < 0.5 ? a?.inputDecorationTheme : b?.inputDecorationTheme, + cancelButtonStyle: ButtonStyle.lerp(a?.cancelButtonStyle, b?.cancelButtonStyle, t), + confirmButtonStyle: ButtonStyle.lerp(a?.confirmButtonStyle, b?.confirmButtonStyle, t), + ); + } + + static BorderSide? _lerpBorderSide(BorderSide? a, BorderSide? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return BorderSide.lerp(BorderSide(width: 0, color: b!.color.withAlpha(0)), b, t); + } + return BorderSide.lerp(a, BorderSide(width: 0, color: a.color.withAlpha(0)), t); + } + + @override + int get hashCode => Object.hashAll(<Object?>[ + backgroundColor, + elevation, + shadowColor, + surfaceTintColor, + shape, + headerBackgroundColor, + headerForegroundColor, + headerHeadlineStyle, + headerHelpStyle, + weekdayStyle, + dayStyle, + dayForegroundColor, + dayBackgroundColor, + dayOverlayColor, + todayForegroundColor, + todayBackgroundColor, + todayBorder, + yearStyle, + yearForegroundColor, + yearBackgroundColor, + yearOverlayColor, + rangePickerBackgroundColor, + rangePickerElevation, + rangePickerShadowColor, + rangePickerSurfaceTintColor, + rangePickerShape, + rangePickerHeaderBackgroundColor, + rangePickerHeaderForegroundColor, + rangePickerHeaderHeadlineStyle, + rangePickerHeaderHelpStyle, + rangeSelectionBackgroundColor, + rangeSelectionOverlayColor, + dividerColor, + inputDecorationTheme, + cancelButtonStyle, + confirmButtonStyle, + ]); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is DatePickerThemeData + && other.backgroundColor == backgroundColor + && other.elevation == elevation + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.shape == shape + && other.headerBackgroundColor == headerBackgroundColor + && other.headerForegroundColor == headerForegroundColor + && other.headerHeadlineStyle == headerHeadlineStyle + && other.headerHelpStyle == headerHelpStyle + && other.weekdayStyle == weekdayStyle + && other.dayStyle == dayStyle + && other.dayForegroundColor == dayForegroundColor + && other.dayBackgroundColor == dayBackgroundColor + && other.dayOverlayColor == dayOverlayColor + && other.todayForegroundColor == todayForegroundColor + && other.todayBackgroundColor == todayBackgroundColor + && other.todayBorder == todayBorder + && other.yearStyle == yearStyle + && other.yearForegroundColor == yearForegroundColor + && other.yearBackgroundColor == yearBackgroundColor + && other.yearOverlayColor == yearOverlayColor + && other.rangePickerBackgroundColor == rangePickerBackgroundColor + && other.rangePickerElevation == rangePickerElevation + && other.rangePickerShadowColor == rangePickerShadowColor + && other.rangePickerSurfaceTintColor == rangePickerSurfaceTintColor + && other.rangePickerShape == rangePickerShape + && other.rangePickerHeaderBackgroundColor == rangePickerHeaderBackgroundColor + && other.rangePickerHeaderForegroundColor == rangePickerHeaderForegroundColor + && other.rangePickerHeaderHeadlineStyle == rangePickerHeaderHeadlineStyle + && other.rangePickerHeaderHelpStyle == rangePickerHeaderHelpStyle + && other.rangeSelectionBackgroundColor == rangeSelectionBackgroundColor + && other.rangeSelectionOverlayColor == rangeSelectionOverlayColor + && other.dividerColor == dividerColor + && other.inputDecorationTheme == inputDecorationTheme + && other.cancelButtonStyle == cancelButtonStyle + && other.confirmButtonStyle == confirmButtonStyle; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(ColorProperty('headerBackgroundColor', headerBackgroundColor, defaultValue: null)); + properties.add(ColorProperty('headerForegroundColor', headerForegroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('headerHeadlineStyle', headerHeadlineStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('headerHelpStyle', headerHelpStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('weekDayStyle', weekdayStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('dayStyle', dayStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('dayForegroundColor', dayForegroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('dayBackgroundColor', dayBackgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('dayOverlayColor', dayOverlayColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('todayForegroundColor', todayForegroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('todayBackgroundColor', todayBackgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<BorderSide?>('todayBorder', todayBorder, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('yearStyle', yearStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('yearForegroundColor', yearForegroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('yearBackgroundColor', yearBackgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('yearOverlayColor', yearOverlayColor, defaultValue: null)); + properties.add(ColorProperty('rangePickerBackgroundColor', rangePickerBackgroundColor, defaultValue: null)); + properties.add(DoubleProperty('rangePickerElevation', rangePickerElevation, defaultValue: null)); + properties.add(ColorProperty('rangePickerShadowColor', rangePickerShadowColor, defaultValue: null)); + properties.add(ColorProperty('rangePickerSurfaceTintColor', rangePickerSurfaceTintColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('rangePickerShape', rangePickerShape, defaultValue: null)); + properties.add(ColorProperty('rangePickerHeaderBackgroundColor', rangePickerHeaderBackgroundColor, defaultValue: null)); + properties.add(ColorProperty('rangePickerHeaderForegroundColor', rangePickerHeaderForegroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('rangePickerHeaderHeadlineStyle', rangePickerHeaderHeadlineStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('rangePickerHeaderHelpStyle', rangePickerHeaderHelpStyle, defaultValue: null)); + properties.add(ColorProperty('rangeSelectionBackgroundColor', rangeSelectionBackgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('rangeSelectionOverlayColor', rangeSelectionOverlayColor, defaultValue: null)); + properties.add(ColorProperty('dividerColor', dividerColor, defaultValue: null)); + properties.add(DiagnosticsProperty<InputDecorationTheme>('inputDecorationTheme', inputDecorationTheme, defaultValue: null)); + properties.add(DiagnosticsProperty<ButtonStyle>('cancelButtonStyle', cancelButtonStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<ButtonStyle>('confirmButtonStyle', confirmButtonStyle, defaultValue: null)); + } +} + +/// An inherited widget that defines the visual properties for +/// [DatePickerDialog]s in this widget's subtree. +/// +/// Values specified here are used for [DatePickerDialog] properties that are not +/// given an explicit non-null value. +class DatePickerTheme extends InheritedTheme { + /// Creates a [DatePickerTheme] that controls visual parameters for + /// descendent [DatePickerDialog]s. + const DatePickerTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the visual properties used by descendant [DatePickerDialog] + /// widgets. + final DatePickerThemeData data; + + /// The [data] from the closest instance of this class that encloses the given + /// context. + /// + /// If there is no [DatePickerTheme] in scope, this will return + /// [ThemeData.datePickerTheme] from the ambient [Theme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// DatePickerThemeData theme = DatePickerTheme.of(context); + /// ``` + /// + /// See also: + /// + /// * [maybeOf], which returns null if it doesn't find a + /// [DatePickerTheme] ancestor. + /// * [defaults], which will return the default properties used when no + /// other [DatePickerTheme] has been provided. + static DatePickerThemeData of(BuildContext context) { + return maybeOf(context) ?? Theme.of(context).datePickerTheme; + } + + /// The data from the closest instance of this class that encloses the given + /// context, if any. + /// + /// Use this function if you want to allow situations where no + /// [DatePickerTheme] is in scope. Prefer using [DatePickerTheme.of] + /// in situations where a [DatePickerThemeData] is expected to be + /// non-null. + /// + /// If there is no [DatePickerTheme] in scope, then this function will + /// return null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// DatePickerThemeData? theme = DatePickerTheme.maybeOf(context); + /// if (theme == null) { + /// // Do something else instead. + /// } + /// ``` + /// + /// See also: + /// + /// * [of], which will return [ThemeData.datePickerTheme] if it doesn't + /// find a [DatePickerTheme] ancestor, instead of returning null. + /// * [defaults], which will return the default properties used when no + /// other [DatePickerTheme] has been provided. + static DatePickerThemeData? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<DatePickerTheme>()?.data; + } + + /// A DatePickerThemeData used as the default properties for date pickers. + /// + /// This is only used for properties not already specified in the ambient + /// [DatePickerTheme.of]. + /// + /// See also: + /// + /// * [of], which will return [ThemeData.datePickerTheme] if it doesn't + /// find a [DatePickerTheme] ancestor, instead of returning null. + /// * [maybeOf], which returns null if it doesn't find a + /// [DatePickerTheme] ancestor. + static DatePickerThemeData defaults(BuildContext context) { + return Theme.of(context).useMaterial3 + ? _DatePickerDefaultsM3(context) + : _DatePickerDefaultsM2(context); + } + + @override + Widget wrap(BuildContext context, Widget child) { + return DatePickerTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(DatePickerTheme oldWidget) => data != oldWidget.data; +} + +// Hand coded defaults based on Material Design 2. +class _DatePickerDefaultsM2 extends DatePickerThemeData { + _DatePickerDefaultsM2(this.context) + : super( + elevation: 24.0, + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))), + rangePickerElevation: 0.0, + rangePickerShape: const RoundedRectangleBorder(), + ); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + late final TextTheme _textTheme = _theme.textTheme; + late final bool _isDark = _colors.brightness == Brightness.dark; + + @override + Color? get headerBackgroundColor => _isDark ? _colors.surface : _colors.primary; + + @override + ButtonStyle get cancelButtonStyle { + return TextButton.styleFrom(); + } + + @override + ButtonStyle get confirmButtonStyle { + return TextButton.styleFrom(); + } + + @override + Color? get headerForegroundColor => _isDark ? _colors.onSurface : _colors.onPrimary; + + @override + TextStyle? get headerHeadlineStyle => _textTheme.headlineSmall; + + @override + TextStyle? get headerHelpStyle => _textTheme.labelSmall; + + @override + TextStyle? get weekdayStyle => _textTheme.bodySmall?.apply( + color: _colors.onSurface.withOpacity(0.60), + ); + + @override + TextStyle? get dayStyle => _textTheme.bodySmall; + + @override + MaterialStateProperty<Color?>? get dayForegroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.onPrimary; + } else if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + return _colors.onSurface; + }); + + @override + MaterialStateProperty<Color?>? get dayBackgroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.primary; + } + return null; + }); + + @override + MaterialStateProperty<Color?>? get dayOverlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onPrimary.withOpacity(0.38); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onPrimary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onPrimary.withOpacity(0.12); + } + } else { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurfaceVariant.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + } + return null; + }); + + @override + MaterialStateProperty<Color?>? get todayForegroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.onPrimary; + } else if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + return _colors.primary; + }); + + @override + MaterialStateProperty<Color?>? get todayBackgroundColor => dayBackgroundColor; + + @override + BorderSide? get todayBorder => BorderSide(color: _colors.primary); + + @override + TextStyle? get yearStyle => _textTheme.bodyLarge; + + @override + Color? get rangePickerBackgroundColor => _colors.surface; + + @override + Color? get rangePickerShadowColor => Colors.transparent; + + @override + Color? get rangePickerSurfaceTintColor => Colors.transparent; + + @override + Color? get rangePickerHeaderBackgroundColor => _isDark ? _colors.surface : _colors.primary; + + @override + Color? get rangePickerHeaderForegroundColor => _isDark ? _colors.onSurface : _colors.onPrimary; + + @override + TextStyle? get rangePickerHeaderHeadlineStyle => _textTheme.headlineSmall; + + @override + TextStyle? get rangePickerHeaderHelpStyle => _textTheme.labelSmall; + + @override + Color? get rangeSelectionBackgroundColor => _colors.primary.withOpacity(0.12); + + @override + MaterialStateProperty<Color?>? get rangeSelectionOverlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onPrimary.withOpacity(0.38); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onPrimary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onPrimary.withOpacity(0.12); + } + } else { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurfaceVariant.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + } + return null; + }); +} + +// BEGIN GENERATED TOKEN PROPERTIES - DatePicker + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _DatePickerDefaultsM3 extends DatePickerThemeData { + _DatePickerDefaultsM3(this.context) + : super( + elevation: 6.0, + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0))), + rangePickerElevation: 0.0, + rangePickerShape: const RoundedRectangleBorder(), + ); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + late final TextTheme _textTheme = _theme.textTheme; + + @override + Color? get backgroundColor => _colors.surface; + + @override + ButtonStyle get cancelButtonStyle { + return TextButton.styleFrom(); + } + + @override + ButtonStyle get confirmButtonStyle { + return TextButton.styleFrom(); + } + + @override + Color? get shadowColor => Colors.transparent; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + Color? get headerBackgroundColor => Colors.transparent; + + @override + Color? get headerForegroundColor => _colors.onSurfaceVariant; + + @override + TextStyle? get headerHeadlineStyle => _textTheme.headlineLarge; + + @override + TextStyle? get headerHelpStyle => _textTheme.labelLarge; + + @override + TextStyle? get weekdayStyle => _textTheme.bodyLarge?.apply( + color: _colors.onSurface, + ); + + @override + TextStyle? get dayStyle => _textTheme.bodyLarge; + + @override + MaterialStateProperty<Color?>? get dayForegroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.onPrimary; + } else if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + return _colors.onSurface; + }); + + @override + MaterialStateProperty<Color?>? get dayBackgroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.primary; + } + return null; + }); + + @override + MaterialStateProperty<Color?>? get dayOverlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onPrimary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onPrimary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onPrimary.withOpacity(0.12); + } + } else { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurfaceVariant.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + } + return null; + }); + + @override + MaterialStateProperty<Color?>? get todayForegroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.onPrimary; + } else if (states.contains(MaterialState.disabled)) { + return _colors.primary.withOpacity(0.38); + } + return _colors.primary; + }); + + @override + MaterialStateProperty<Color?>? get todayBackgroundColor => dayBackgroundColor; + + @override + BorderSide? get todayBorder => BorderSide(color: _colors.primary); + + @override + TextStyle? get yearStyle => _textTheme.bodyLarge; + + @override + MaterialStateProperty<Color?>? get yearForegroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.onPrimary; + } else if (states.contains(MaterialState.disabled)) { + return _colors.onSurfaceVariant.withOpacity(0.38); + } + return _colors.onSurfaceVariant; + }); + + @override + MaterialStateProperty<Color?>? get yearBackgroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.primary; + } + return null; + }); + + @override + MaterialStateProperty<Color?>? get yearOverlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onPrimary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onPrimary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onPrimary.withOpacity(0.12); + } + } else { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurfaceVariant.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + } + return null; + }); + + @override + Color? get rangePickerShadowColor => Colors.transparent; + + @override + Color? get rangePickerSurfaceTintColor => Colors.transparent; + + @override + Color? get rangeSelectionBackgroundColor => _colors.secondaryContainer; + + @override + MaterialStateProperty<Color?>? get rangeSelectionOverlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return _colors.onPrimaryContainer.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onPrimaryContainer.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onPrimaryContainer.withOpacity(0.12); + } + return null; + }); + + @override + Color? get rangePickerHeaderBackgroundColor => Colors.transparent; + + @override + Color? get rangePickerHeaderForegroundColor => _colors.onSurfaceVariant; + + @override + TextStyle? get rangePickerHeaderHeadlineStyle => _textTheme.titleLarge; + + @override + TextStyle? get rangePickerHeaderHelpStyle => _textTheme.titleSmall; +} + +// END GENERATED TOKEN PROPERTIES - DatePicker diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/debug.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/debug.dart new file mode 100644 index 0000000000000000000000000000000000000000..dbd43a75ae0c3c5b98946772dc75e5247ff7d66f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/debug.dart @@ -0,0 +1,189 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'material.dart'; +import 'material_localizations.dart'; +import 'scaffold.dart' show Scaffold, ScaffoldMessenger; + +// Examples can assume: +// late BuildContext context; + +/// Asserts that the given context has a [Material] ancestor within the closest +/// [LookupBoundary]. +/// +/// Used by many Material Design widgets to make sure that they are +/// only used in contexts where they can print ink onto some material. +/// +/// To call this function, use the following pattern, typically in the +/// relevant Widget's build method: +/// +/// ```dart +/// assert(debugCheckHasMaterial(context)); +/// ``` +/// +/// Always place this before any early returns, so that the invariant is checked +/// in all cases. This prevents bugs from hiding until a particular codepath is +/// hit. +/// +/// This method can be expensive (it walks the element tree). +/// +/// Does nothing if asserts are disabled. Always returns true. +bool debugCheckHasMaterial(BuildContext context) { + assert(() { + if (LookupBoundary.findAncestorWidgetOfExactType<Material>(context) == null) { + final bool hiddenByBoundary = LookupBoundary.debugIsHidingAncestorWidgetOfExactType<Material>(context); + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('No Material widget found${hiddenByBoundary ? ' within the closest LookupBoundary' : ''}.'), + if (hiddenByBoundary) + ErrorDescription( + 'There is an ancestor Material widget, but it is hidden by a LookupBoundary.' + ), + ErrorDescription( + '${context.widget.runtimeType} widgets require a Material ' + 'widget ancestor within the closest LookupBoundary.\n' + 'In Material Design, most widgets are conceptually "printed" on ' + "a sheet of material. In Flutter's material library, that " + 'material is represented by the Material widget. It is the ' + 'Material widget that renders ink splashes, for instance. ' + 'Because of this, many material library widgets require that ' + 'there be a Material widget in the tree above them.', + ), + ErrorHint( + 'To introduce a Material widget, you can either directly ' + 'include one, or use a widget that contains Material itself, ' + 'such as a Card, Dialog, Drawer, or Scaffold.', + ), + ...context.describeMissingAncestor(expectedAncestorType: Material), + ]); + } + return true; + }()); + return true; +} + +/// Asserts that the given context has a [Localizations] ancestor that contains +/// a [MaterialLocalizations] delegate. +/// +/// Used by many Material Design widgets to make sure that they are +/// only used in contexts where they have access to localizations. +/// +/// To call this function, use the following pattern, typically in the +/// relevant Widget's build method: +/// +/// ```dart +/// assert(debugCheckHasMaterialLocalizations(context)); +/// ``` +/// +/// Always place this before any early returns, so that the invariant is checked +/// in all cases. This prevents bugs from hiding until a particular codepath is +/// hit. +/// +/// This function has the side-effect of establishing an inheritance +/// relationship with the nearest [Localizations] widget (see +/// [BuildContext.dependOnInheritedWidgetOfExactType]). This is ok if the caller +/// always also calls [Localizations.of] or [Localizations.localeOf]. +/// +/// Does nothing if asserts are disabled. Always returns true. +bool debugCheckHasMaterialLocalizations(BuildContext context) { + assert(() { + if (Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('No MaterialLocalizations found.'), + ErrorDescription( + '${context.widget.runtimeType} widgets require MaterialLocalizations ' + 'to be provided by a Localizations widget ancestor.', + ), + ErrorDescription( + 'The material library uses Localizations to generate messages, ' + 'labels, and abbreviations.', + ), + ErrorHint( + 'To introduce a MaterialLocalizations, either use a ' + 'MaterialApp at the root of your application to include them ' + 'automatically, or add a Localization widget with a ' + 'MaterialLocalizations delegate.', + ), + ...context.describeMissingAncestor(expectedAncestorType: MaterialLocalizations), + ]); + } + return true; + }()); + return true; +} + +/// Asserts that the given context has a [Scaffold] ancestor. +/// +/// Used by various widgets to make sure that they are only used in an +/// appropriate context. +/// +/// To invoke this function, use the following pattern, typically in the +/// relevant Widget's build method: +/// +/// ```dart +/// assert(debugCheckHasScaffold(context)); +/// ``` +/// +/// Always place this before any early returns, so that the invariant is checked +/// in all cases. This prevents bugs from hiding until a particular codepath is +/// hit. +/// +/// This method can be expensive (it walks the element tree). +/// +/// Does nothing if asserts are disabled. Always returns true. +bool debugCheckHasScaffold(BuildContext context) { + assert(() { + if (context.widget is! Scaffold && context.findAncestorWidgetOfExactType<Scaffold>() == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('No Scaffold widget found.'), + ErrorDescription('${context.widget.runtimeType} widgets require a Scaffold widget ancestor.'), + ...context.describeMissingAncestor(expectedAncestorType: Scaffold), + ErrorHint( + 'Typically, the Scaffold widget is introduced by the MaterialApp or ' + 'WidgetsApp widget at the top of your application widget tree.', + ), + ]); + } + return true; + }()); + return true; +} + +/// Asserts that the given context has a [ScaffoldMessenger] ancestor. +/// +/// Used by various widgets to make sure that they are only used in an +/// appropriate context. +/// +/// To invoke this function, use the following pattern, typically in the +/// relevant Widget's build method: +/// +/// ```dart +/// assert(debugCheckHasScaffoldMessenger(context)); +/// ``` +/// +/// Always place this before any early returns, so that the invariant is checked +/// in all cases. This prevents bugs from hiding until a particular codepath is +/// hit. +/// +/// This method can be expensive (it walks the element tree). +/// +/// Does nothing if asserts are disabled. Always returns true. +bool debugCheckHasScaffoldMessenger(BuildContext context) { + assert(() { + if (context.findAncestorWidgetOfExactType<ScaffoldMessenger>() == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('No ScaffoldMessenger widget found.'), + ErrorDescription('${context.widget.runtimeType} widgets require a ScaffoldMessenger widget ancestor.'), + ...context.describeMissingAncestor(expectedAncestorType: ScaffoldMessenger), + ErrorHint( + 'Typically, the ScaffoldMessenger widget is introduced by the MaterialApp ' + 'at the top of your application widget tree.', + ), + ]); + } + return true; + }()); + return true; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/desktop_text_selection.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/desktop_text_selection.dart new file mode 100644 index 0000000000000000000000000000000000000000..58a372547565a959406955b5a87f8a5aa3058008 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/desktop_text_selection.dart @@ -0,0 +1,226 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show ValueListenable, clampDouble; +import 'package:flutter/widgets.dart'; + +import 'debug.dart'; +import 'desktop_text_selection_toolbar.dart'; +import 'desktop_text_selection_toolbar_button.dart'; +import 'material_localizations.dart'; + +/// Desktop Material styled text selection handle controls. +/// +/// Specifically does not manage the toolbar, which is left to +/// [EditableText.contextMenuBuilder]. +class _DesktopTextSelectionHandleControls extends DesktopTextSelectionControls with TextSelectionHandleControls { +} + +/// Desktop Material styled text selection controls. +/// +/// The [desktopTextSelectionControls] global variable has a +/// suitable instance of this class. +class DesktopTextSelectionControls extends TextSelectionControls { + /// Desktop has no text selection handles. + @override + Size getHandleSize(double textLineHeight) { + return Size.zero; + } + + /// Builder for the Material-style desktop copy/paste text selection toolbar. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + Widget buildToolbar( + BuildContext context, + Rect globalEditableRegion, + double textLineHeight, + Offset selectionMidpoint, + List<TextSelectionPoint> endpoints, + TextSelectionDelegate delegate, + ValueListenable<ClipboardStatus>? clipboardStatus, + Offset? lastSecondaryTapDownPosition, + ) { + return _DesktopTextSelectionControlsToolbar( + clipboardStatus: clipboardStatus, + endpoints: endpoints, + globalEditableRegion: globalEditableRegion, + handleCut: canCut(delegate) ? () => handleCut(delegate) : null, + handleCopy: canCopy(delegate) ? () => handleCopy(delegate) : null, + handlePaste: canPaste(delegate) ? () => handlePaste(delegate) : null, + handleSelectAll: canSelectAll(delegate) ? () => handleSelectAll(delegate) : null, + selectionMidpoint: selectionMidpoint, + lastSecondaryTapDownPosition: lastSecondaryTapDownPosition, + textLineHeight: textLineHeight, + ); + } + + /// Builds the text selection handles, but desktop has none. + @override + Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textLineHeight, [VoidCallback? onTap]) { + return const SizedBox.shrink(); + } + + /// Gets the position for the text selection handles, but desktop has none. + @override + Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) { + return Offset.zero; + } + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + bool canSelectAll(TextSelectionDelegate delegate) { + // Allow SelectAll when selection is not collapsed, unless everything has + // already been selected. Same behavior as Android. + final TextEditingValue value = delegate.textEditingValue; + return delegate.selectAllEnabled && + value.text.isNotEmpty && + !(value.selection.start == 0 && value.selection.end == value.text.length); + } + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + void handleSelectAll(TextSelectionDelegate delegate) { + super.handleSelectAll(delegate); + delegate.hideToolbar(); + } +} + +// TODO(justinmc): Deprecate this after TextSelectionControls.buildToolbar is +// deleted, when users should migrate back to desktopTextSelectionControls. +// See https://github.com/flutter/flutter/pull/124262 +/// Desktop text selection handle controls that loosely follow Material design +/// conventions. +final TextSelectionControls desktopTextSelectionHandleControls = + _DesktopTextSelectionHandleControls(); + +/// Desktop text selection controls that loosely follow Material design +/// conventions. +final TextSelectionControls desktopTextSelectionControls = + DesktopTextSelectionControls(); + +// Generates the child that's passed into DesktopTextSelectionToolbar. +class _DesktopTextSelectionControlsToolbar extends StatefulWidget { + const _DesktopTextSelectionControlsToolbar({ + required this.clipboardStatus, + required this.endpoints, + required this.globalEditableRegion, + required this.handleCopy, + required this.handleCut, + required this.handlePaste, + required this.handleSelectAll, + required this.selectionMidpoint, + required this.textLineHeight, + required this.lastSecondaryTapDownPosition, + }); + + final ValueListenable<ClipboardStatus>? clipboardStatus; + final List<TextSelectionPoint> endpoints; + final Rect globalEditableRegion; + final VoidCallback? handleCopy; + final VoidCallback? handleCut; + final VoidCallback? handlePaste; + final VoidCallback? handleSelectAll; + final Offset? lastSecondaryTapDownPosition; + final Offset selectionMidpoint; + final double textLineHeight; + + @override + _DesktopTextSelectionControlsToolbarState createState() => _DesktopTextSelectionControlsToolbarState(); +} + +class _DesktopTextSelectionControlsToolbarState extends State<_DesktopTextSelectionControlsToolbar> { + void _onChangedClipboardStatus() { + setState(() { + // Inform the widget that the value of clipboardStatus has changed. + }); + } + + @override + void initState() { + super.initState(); + widget.clipboardStatus?.addListener(_onChangedClipboardStatus); + } + + @override + void didUpdateWidget(_DesktopTextSelectionControlsToolbar oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.clipboardStatus != widget.clipboardStatus) { + oldWidget.clipboardStatus?.removeListener(_onChangedClipboardStatus); + widget.clipboardStatus?.addListener(_onChangedClipboardStatus); + } + } + + @override + void dispose() { + widget.clipboardStatus?.removeListener(_onChangedClipboardStatus); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + assert(debugCheckHasMediaQuery(context)); + + // Don't render the menu until the state of the clipboard is known. + if (widget.handlePaste != null && widget.clipboardStatus?.value == ClipboardStatus.unknown) { + return const SizedBox.shrink(); + } + + final EdgeInsets mediaQueryPadding = MediaQuery.paddingOf(context); + final Offset midpointAnchor = Offset( + clampDouble(widget.selectionMidpoint.dx - widget.globalEditableRegion.left, + mediaQueryPadding.left, + MediaQuery.sizeOf(context).width - mediaQueryPadding.right, + ), + widget.selectionMidpoint.dy - widget.globalEditableRegion.top, + ); + + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final List<Widget> items = <Widget>[]; + + void addToolbarButton( + String text, + VoidCallback onPressed, + ) { + items.add(DesktopTextSelectionToolbarButton.text( + context: context, + onPressed: onPressed, + text: text, + )); + } + + if (widget.handleCut != null) { + addToolbarButton(localizations.cutButtonLabel, widget.handleCut!); + } + if (widget.handleCopy != null) { + addToolbarButton(localizations.copyButtonLabel, widget.handleCopy!); + } + if (widget.handlePaste != null + && widget.clipboardStatus?.value == ClipboardStatus.pasteable) { + addToolbarButton(localizations.pasteButtonLabel, widget.handlePaste!); + } + if (widget.handleSelectAll != null) { + addToolbarButton(localizations.selectAllButtonLabel, widget.handleSelectAll!); + } + + // If there is no option available, build an empty widget. + if (items.isEmpty) { + return const SizedBox.shrink(); + } + + return DesktopTextSelectionToolbar( + anchor: widget.lastSecondaryTapDownPosition ?? midpointAnchor, + children: items, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/desktop_text_selection_toolbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/desktop_text_selection_toolbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..df69b455600112160c974052bf2793e0ef8dd7b2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/desktop_text_selection_toolbar.dart @@ -0,0 +1,92 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'material.dart'; +import 'text_selection_toolbar.dart'; + +// These values were measured from a screenshot of TextEdit on macOS 10.15.7 on +// a Macbook Pro. +const double _kToolbarScreenPadding = 8.0; +const double _kToolbarWidth = 222.0; + +/// A Material-style desktop text selection toolbar. +/// +/// Typically displays buttons for text manipulation, e.g. copying and pasting +/// text. +/// +/// Tries to position its top left corner as closely as possible to [anchor] +/// while remaining fully inside the viewport. +/// +/// See also: +/// +/// * [AdaptiveTextSelectionToolbar], which builds the toolbar for the current +/// platform. +/// * [TextSelectionToolbar], which is similar, but builds an Android-style +/// toolbar. +class DesktopTextSelectionToolbar extends StatelessWidget { + /// Creates a const instance of DesktopTextSelectionToolbar. + const DesktopTextSelectionToolbar({ + super.key, + required this.anchor, + required this.children, + }) : assert(children.length > 0); + + /// {@template flutter.material.DesktopTextSelectionToolbar.anchor} + /// The point where the toolbar will attempt to position itself as closely as + /// possible. + /// {@endtemplate} + final Offset anchor; + + /// {@macro flutter.material.TextSelectionToolbar.children} + /// + /// See also: + /// * [DesktopTextSelectionToolbarButton], which builds a default + /// Material-style desktop text selection toolbar text button. + final List<Widget> children; + + // Builds a desktop toolbar in the Material style. + static Widget _defaultToolbarBuilder(BuildContext context, Widget child) { + return SizedBox( + width: _kToolbarWidth, + child: Material( + borderRadius: const BorderRadius.all(Radius.circular(7.0)), + clipBehavior: Clip.antiAlias, + elevation: 1.0, + type: MaterialType.card, + child: child, + ), + ); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + + final double paddingAbove = MediaQuery.paddingOf(context).top + _kToolbarScreenPadding; + final Offset localAdjustment = Offset(_kToolbarScreenPadding, paddingAbove); + + return Padding( + padding: EdgeInsets.fromLTRB( + _kToolbarScreenPadding, + paddingAbove, + _kToolbarScreenPadding, + _kToolbarScreenPadding, + ), + child: CustomSingleChildLayout( + delegate: DesktopTextSelectionToolbarLayoutDelegate( + anchor: anchor - localAdjustment, + ), + child: _defaultToolbarBuilder( + context, + Column( + mainAxisSize: MainAxisSize.min, + children: children, + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/desktop_text_selection_toolbar_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/desktop_text_selection_toolbar_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..48a8e09b2ec442a20997605b5928d62647aac33f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/desktop_text_selection_toolbar_button.dart @@ -0,0 +1,83 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'constants.dart'; +import 'text_button.dart'; +import 'theme.dart'; + +const TextStyle _kToolbarButtonFontStyle = TextStyle( + inherit: false, + fontSize: 14.0, + letterSpacing: -0.15, + fontWeight: FontWeight.w400, +); + +const EdgeInsets _kToolbarButtonPadding = EdgeInsets.fromLTRB( + 20.0, + 0.0, + 20.0, + 3.0, +); + +/// A [TextButton] for the Material desktop text selection toolbar. +class DesktopTextSelectionToolbarButton extends StatelessWidget { + /// Creates an instance of DesktopTextSelectionToolbarButton. + const DesktopTextSelectionToolbarButton({ + super.key, + required this.onPressed, + required this.child, + }); + + /// Create an instance of [DesktopTextSelectionToolbarButton] whose child is + /// a [Text] widget in the style of the Material text selection toolbar. + DesktopTextSelectionToolbarButton.text({ + super.key, + required BuildContext context, + required this.onPressed, + required String text, + }) : child = Text( + text, + overflow: TextOverflow.ellipsis, + style: _kToolbarButtonFontStyle.copyWith( + color: Theme.of(context).colorScheme.brightness == Brightness.dark + ? Colors.white + : Colors.black87, + ), + ); + + /// {@macro flutter.material.TextSelectionToolbarTextButton.onPressed} + final VoidCallback? onPressed; + + /// {@macro flutter.material.TextSelectionToolbarTextButton.child} + final Widget child; + + @override + Widget build(BuildContext context) { + // TODO(hansmuller): Should be colorScheme.onSurface + final ThemeData theme = Theme.of(context); + final bool isDark = theme.colorScheme.brightness == Brightness.dark; + final Color foregroundColor = isDark ? Colors.white : Colors.black87; + + return SizedBox( + width: double.infinity, + child: TextButton( + style: TextButton.styleFrom( + alignment: Alignment.centerLeft, + enabledMouseCursor: SystemMouseCursors.basic, + disabledMouseCursor: SystemMouseCursors.basic, + foregroundColor: foregroundColor, + shape: const RoundedRectangleBorder(), + minimumSize: const Size(kMinInteractiveDimension, 36.0), + padding: _kToolbarButtonPadding, + ), + onPressed: onPressed, + child: child, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dialog.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dialog.dart new file mode 100644 index 0000000000000000000000000000000000000000..a9ca87452c81391f40110675441471c7336ecabb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dialog.dart @@ -0,0 +1,1680 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show clampDouble, lerpDouble; + +import 'package:flutter/cupertino.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'debug.dart'; +import 'dialog_theme.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// enum Department { treasury, state } +// late BuildContext context; + +const EdgeInsets _defaultInsetPadding = EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0); + +/// A Material Design dialog. +/// +/// This dialog widget does not have any opinion about the contents of the +/// dialog. Rather than using this widget directly, consider using [AlertDialog] +/// or [SimpleDialog], which implement specific kinds of Material Design +/// dialogs. +/// +/// {@tool dartpad} +/// This sample shows the creation of [Dialog] and [Dialog.fullscreen] widgets. +/// +/// ** See code in examples/api/lib/material/dialog/dialog.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AlertDialog], for dialogs that have a message and some buttons. +/// * [SimpleDialog], for dialogs that offer a variety of options. +/// * [showDialog], which actually displays the dialog and returns its result. +/// * <https://material.io/design/components/dialogs.html> +class Dialog extends StatelessWidget { + /// Creates a dialog. + /// + /// Typically used in conjunction with [showDialog]. + const Dialog({ + super.key, + this.backgroundColor, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.insetAnimationDuration = const Duration(milliseconds: 100), + this.insetAnimationCurve = Curves.decelerate, + this.insetPadding = _defaultInsetPadding, + this.clipBehavior = Clip.none, + this.shape, + this.alignment, + this.child, + }) : assert(elevation == null || elevation >= 0.0), + _fullscreen = false; + + /// Creates a fullscreen dialog. + /// + /// Typically used in conjunction with [showDialog]. + const Dialog.fullscreen({ + super.key, + this.backgroundColor, + this.insetAnimationDuration = Duration.zero, + this.insetAnimationCurve = Curves.decelerate, + this.child, + }) : elevation = 0, + shadowColor = null, + surfaceTintColor = null, + insetPadding = EdgeInsets.zero, + clipBehavior = Clip.none, + shape = null, + alignment = null, + _fullscreen = true; + + /// {@template flutter.material.dialog.backgroundColor} + /// The background color of the surface of this [Dialog]. + /// + /// This sets the [Material.color] on this [Dialog]'s [Material]. + /// + /// If `null`, [ThemeData.dialogBackgroundColor] is used. + /// {@endtemplate} + final Color? backgroundColor; + + /// {@template flutter.material.dialog.elevation} + /// The z-coordinate of this [Dialog]. + /// + /// Controls how far above the parent the dialog will appear. Elevation is + /// represented by a drop shadow if [shadowColor] is non null, + /// and a surface tint overlay on the background color if [surfaceTintColor] is + /// non null. + /// + /// If null then [DialogTheme.elevation] is used, and if that is null then + /// the elevation will match the Material Design specification for Dialogs. + /// + /// See also: + /// * [Material.elevation], which describes how [elevation] effects the + /// drop shadow or surface tint overlay. + /// * [shadowColor], color of the drop shadow used to indicate the elevation. + /// * [surfaceTintColor], color of an overlay on top of the background + /// color used to indicate the elevation. + /// * <https://m3.material.io/components/dialogs/overview>, the Material + /// Design specification for dialogs. + /// {@endtemplate} + final double? elevation; + + /// {@template flutter.material.dialog.shadowColor} + /// The color used to paint a drop shadow under the dialog's [Material], + /// which reflects the dialog's [elevation]. + /// + /// If null and [ThemeData.useMaterial3] is true then no drop shadow will + /// be rendered. + /// + /// If null and [ThemeData.useMaterial3] is false then it will default to + /// [ThemeData.shadowColor]. + /// + /// See also: + /// * [Material.shadowColor], which describes how the drop shadow is painted. + /// * [elevation], which affects how the drop shadow is painted. + /// * [surfaceTintColor], which can be used to indicate elevation through + /// tinting the background color. + /// {@endtemplate} + final Color? shadowColor; + + /// {@template flutter.material.dialog.surfaceTintColor} + /// The color used as a surface tint overlay on the dialog's background color, + /// which reflects the dialog's [elevation]. + /// + /// If [ThemeData.useMaterial3] is false property has no effect. + /// + /// If null and [ThemeData.useMaterial3] is true then [ThemeData]'s + /// [ColorScheme.surfaceTint] will be used. + /// + /// To disable this feature, set [surfaceTintColor] to [Colors.transparent]. + /// + /// See also: + /// * [Material.surfaceTintColor], which describes how the surface tint will + /// be applied to the background color of the dialog. + /// * [elevation], which affects the opacity of the surface tint. + /// * [shadowColor], which can be used to indicate elevation through + /// a drop shadow. + /// {@endtemplate} + final Color? surfaceTintColor; + + /// {@template flutter.material.dialog.insetAnimationDuration} + /// The duration of the animation to show when the system keyboard intrudes + /// into the space that the dialog is placed in. + /// + /// Defaults to 100 milliseconds when [Dialog] is used, and [Duration.zero] + /// when [Dialog.fullscreen] is used. + /// {@endtemplate} + final Duration insetAnimationDuration; + + /// {@template flutter.material.dialog.insetAnimationCurve} + /// The curve to use for the animation shown when the system keyboard intrudes + /// into the space that the dialog is placed in. + /// + /// Defaults to [Curves.decelerate]. + /// {@endtemplate} + final Curve insetAnimationCurve; + + /// {@template flutter.material.dialog.insetPadding} + /// The amount of padding added to [MediaQueryData.viewInsets] on the outside + /// of the dialog. This defines the minimum space between the screen's edges + /// and the dialog. + /// + /// Defaults to `EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0)`. + /// {@endtemplate} + final EdgeInsets? insetPadding; + + /// {@template flutter.material.dialog.clipBehavior} + /// Controls how the contents of the dialog are clipped (or not) to the given + /// [shape]. + /// + /// See the enum [Clip] for details of all possible options and their common + /// use cases. + /// + /// Defaults to [Clip.none]. + /// {@endtemplate} + final Clip clipBehavior; + + /// {@template flutter.material.dialog.shape} + /// The shape of this dialog's border. + /// + /// Defines the dialog's [Material.shape]. + /// + /// The default shape is a [RoundedRectangleBorder] with a radius of 4.0 + /// {@endtemplate} + final ShapeBorder? shape; + + /// {@template flutter.material.dialog.alignment} + /// How to align the [Dialog]. + /// + /// If null, then [DialogTheme.alignment] is used. If that is also null, the + /// default is [Alignment.center]. + /// {@endtemplate} + final AlignmentGeometry? alignment; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// This value is used to determine if this is a fullscreen dialog. + final bool _fullscreen; + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final DialogTheme dialogTheme = DialogTheme.of(context); + final EdgeInsets effectivePadding = MediaQuery.viewInsetsOf(context) + (insetPadding ?? EdgeInsets.zero); + final DialogTheme defaults = theme.useMaterial3 + ? (_fullscreen ? _DialogFullscreenDefaultsM3(context) : _DialogDefaultsM3(context)) + : _DialogDefaultsM2(context); + + Widget dialogChild; + + if (_fullscreen) { + dialogChild = Material( + color: backgroundColor ?? dialogTheme.backgroundColor ?? defaults.backgroundColor, + child: child, + ); + } else { + dialogChild = Align( + alignment: alignment ?? dialogTheme.alignment ?? defaults.alignment!, + child: ConstrainedBox( + constraints: const BoxConstraints(minWidth: 280.0), + child: Material( + color: backgroundColor ?? dialogTheme.backgroundColor ?? Theme.of(context).dialogBackgroundColor, + elevation: elevation ?? dialogTheme.elevation ?? defaults.elevation!, + shadowColor: shadowColor ?? dialogTheme.shadowColor ?? defaults.shadowColor, + surfaceTintColor: surfaceTintColor ?? dialogTheme.surfaceTintColor ?? defaults.surfaceTintColor, + shape: shape ?? dialogTheme.shape ?? defaults.shape!, + type: MaterialType.card, + clipBehavior: clipBehavior, + child: child, + ), + ), + ); + } + + return AnimatedPadding( + padding: effectivePadding, + duration: insetAnimationDuration, + curve: insetAnimationCurve, + child: MediaQuery.removeViewInsets( + removeLeft: true, + removeTop: true, + removeRight: true, + removeBottom: true, + context: context, + child: dialogChild, + ), + ); + } +} + +/// A Material Design alert dialog. +/// +/// An alert dialog (also known as a basic dialog) informs the user about +/// situations that require acknowledgment. An alert dialog has an optional +/// title and an optional list of actions. The title is displayed above the +/// content and the actions are displayed below the content. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=75CsnyRXf5I} +/// +/// For dialogs that offer the user a choice between several options, consider +/// using a [SimpleDialog]. +/// +/// Typically passed as the child widget to [showDialog], which displays the +/// dialog. +/// +/// {@animation 350 622 https://flutter.github.io/assets-for-api-docs/assets/material/alert_dialog.mp4} +/// +/// {@tool snippet} +/// +/// This snippet shows a method in a [State] which, when called, displays a dialog box +/// and returns a [Future] that completes when the dialog is dismissed. +/// +/// ```dart +/// Future<void> _showMyDialog() async { +/// return showDialog<void>( +/// context: context, +/// barrierDismissible: false, // user must tap button! +/// builder: (BuildContext context) { +/// return AlertDialog( +/// title: const Text('AlertDialog Title'), +/// content: const SingleChildScrollView( +/// child: ListBody( +/// children: <Widget>[ +/// Text('This is a demo alert dialog.'), +/// Text('Would you like to approve of this message?'), +/// ], +/// ), +/// ), +/// actions: <Widget>[ +/// TextButton( +/// child: const Text('Approve'), +/// onPressed: () { +/// Navigator.of(context).pop(); +/// }, +/// ), +/// ], +/// ); +/// }, +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// {@tool dartpad} +/// This demo shows a [TextButton] which when pressed, calls [showDialog]. When called, this method +/// displays a Material dialog above the current contents of the app and returns +/// a [Future] that completes when the dialog is dismissed. +/// +/// ** See code in examples/api/lib/material/dialog/alert_dialog.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of [AlertDialog], as described in: +/// https://m3.material.io/components/dialogs/overview +/// +/// ** See code in examples/api/lib/material/dialog/alert_dialog.1.dart ** +/// {@end-tool} +/// +/// ## Alert dialogs and scrolling +/// +/// By default, alert dialogs size themselves to contain their children. +/// +/// If the content is too large to fit on the screen vertically, the dialog will +/// display the title and actions, and let the _[content]_ overflow. This is +/// rarely desired. Consider using a scrolling widget for [content], such as +/// [SingleChildScrollView], to avoid overflow. +/// +/// Because the dialog attempts to size itself to the contents, the [content] +/// must support reporting its intrinsic dimensions. In particular, this means +/// that lazily-rendered widgets such as [ListView], [GridView], and +/// [CustomScrollView], will not work in an [AlertDialog] unless they are +/// wrapped in a widget that forces a particular size (e.g. a [SizedBox]). +/// +/// For finer-grained control over the sizing of a dialog, consider using +/// [Dialog] directly. +/// +/// See also: +/// +/// * [SimpleDialog], which handles the scrolling of the contents but has no [actions]. +/// * [Dialog], on which [AlertDialog] and [SimpleDialog] are based. +/// * [CupertinoAlertDialog], an iOS-styled alert dialog. +/// * [showDialog], which actually displays the dialog and returns its result. +/// * <https://material.io/design/components/dialogs.html#alert-dialog> +/// * <https://m3.material.io/components/dialogs> +class AlertDialog extends StatelessWidget { + /// Creates an alert dialog. + /// + /// Typically used in conjunction with [showDialog]. + /// + /// The [titlePadding] and [contentPadding] default to null, which implies a + /// default that depends on the values of the other properties. See the + /// documentation of [titlePadding] and [contentPadding] for details. + const AlertDialog({ + super.key, + this.icon, + this.iconPadding, + this.iconColor, + this.title, + this.titlePadding, + this.titleTextStyle, + this.content, + this.contentPadding, + this.contentTextStyle, + this.actions, + this.actionsPadding, + this.actionsAlignment, + this.actionsOverflowAlignment, + this.actionsOverflowDirection, + this.actionsOverflowButtonSpacing, + this.buttonPadding, + this.backgroundColor, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.semanticLabel, + this.insetPadding = _defaultInsetPadding, + this.clipBehavior = Clip.none, + this.shape, + this.alignment, + this.scrollable = false, + }); + + /// Creates an adaptive [AlertDialog] based on whether the target platform is + /// iOS or macOS, following Material design's + /// [Cross-platform guidelines](https://material.io/design/platform-guidance/cross-platform-adaptation.html). + /// + /// On iOS and macOS, this constructor creates a [CupertinoAlertDialog]. On + /// other platforms, this creates a Material design [AlertDialog]. + /// + /// Typically passed as a child of [showAdaptiveDialog], which will display + /// the alert differently based on platform. + /// + /// If a [CupertinoAlertDialog] is created only these parameters are used: + /// [title], [content], [actions], [scrollController], + /// [actionScrollController], [insetAnimationDuration], and + /// [insetAnimationCurve]. If a material [AlertDialog] is created, + /// [scrollController], [actionScrollController], [insetAnimationDuration], + /// and [insetAnimationCurve] are ignored. + /// + /// The target platform is based on the current [Theme]: [ThemeData.platform]. + /// + /// {@tool dartpad} + /// This demo shows a [TextButton] which when pressed, calls [showAdaptiveDialog]. + /// When called, this method displays an adaptive dialog above the current + /// contents of the app, with different behaviors depending on target platform. + /// + /// [CupertinoDialogAction] is conditionally used as the child to show more + /// platform specific design. + /// + /// ** See code in examples/api/lib/material/dialog/adaptive_alert_dialog.0.dart ** + /// {@end-tool} + const factory AlertDialog.adaptive({ + Key? key, + Widget? icon, + EdgeInsetsGeometry? iconPadding, + Color? iconColor, + Widget? title, + EdgeInsetsGeometry? titlePadding, + TextStyle? titleTextStyle, + Widget? content, + EdgeInsetsGeometry? contentPadding, + TextStyle? contentTextStyle, + List<Widget>? actions, + EdgeInsetsGeometry? actionsPadding, + MainAxisAlignment? actionsAlignment, + OverflowBarAlignment? actionsOverflowAlignment, + VerticalDirection? actionsOverflowDirection, + double? actionsOverflowButtonSpacing, + EdgeInsetsGeometry? buttonPadding, + Color? backgroundColor, + double? elevation, + Color? shadowColor, + Color? surfaceTintColor, + String? semanticLabel, + EdgeInsets insetPadding, + Clip clipBehavior, + ShapeBorder? shape, + AlignmentGeometry? alignment, + bool scrollable, + ScrollController? scrollController, + ScrollController? actionScrollController, + Duration insetAnimationDuration, + Curve insetAnimationCurve, + }) = _AdaptiveAlertDialog; + + /// An optional icon to display at the top of the dialog. + /// + /// Typically, an [Icon] widget. Providing an icon centers the [title]'s text. + final Widget? icon; + + /// Color for the [Icon] in the [icon] of this [AlertDialog]. + /// + /// If null, [DialogTheme.iconColor] is used. If that is null, defaults to + /// color scheme's [ColorScheme.secondary] if [ThemeData.useMaterial3] is + /// true, black otherwise. + final Color? iconColor; + + /// Padding around the [icon]. + /// + /// If there is no [icon], no padding will be provided. Otherwise, this + /// padding is used. + /// + /// This property defaults to providing 24 pixels on the top, left, and right + /// of the [icon]. If [title] is _not_ null, 16 pixels of bottom padding is + /// added to separate the [icon] from the [title]. If the [title] is null and + /// [content] is _not_ null, then no bottom padding is provided (but see + /// [contentPadding]). In any other case 24 pixels of bottom padding is + /// added. + final EdgeInsetsGeometry? iconPadding; + + /// The (optional) title of the dialog is displayed in a large font at the top + /// of the dialog, below the (optional) [icon]. + /// + /// Typically a [Text] widget. + final Widget? title; + + /// Padding around the title. + /// + /// If there is no title, no padding will be provided. Otherwise, this padding + /// is used. + /// + /// This property defaults to providing 24 pixels on the top, left, and right + /// of the title. If the [content] is not null, then no bottom padding is + /// provided (but see [contentPadding]). If it _is_ null, then an extra 20 + /// pixels of bottom padding is added to separate the [title] from the + /// [actions]. + final EdgeInsetsGeometry? titlePadding; + + /// Style for the text in the [title] of this [AlertDialog]. + /// + /// If null, [DialogTheme.titleTextStyle] is used. If that's null, defaults to + /// [TextTheme.titleLarge] of [ThemeData.textTheme]. + final TextStyle? titleTextStyle; + + /// The (optional) content of the dialog is displayed in the center of the + /// dialog in a lighter font. + /// + /// Typically this is a [SingleChildScrollView] that contains the dialog's + /// message. As noted in the [AlertDialog] documentation, it's important + /// to use a [SingleChildScrollView] if there's any risk that the content + /// will not fit, as the contents will otherwise overflow the dialog. + /// + /// The [content] must support reporting its intrinsic dimensions. In + /// particular, [ListView], [GridView], and [CustomScrollView] cannot be used + /// here unless they are first wrapped in a widget that itself can report + /// intrinsic dimensions, such as a [SizedBox]. + final Widget? content; + + /// Padding around the content. + /// + /// If there is no [content], no padding will be provided. Otherwise, this + /// padding is used. + /// + /// This property defaults to providing a padding of 20 pixels above the + /// [content] to separate the [content] from the [title], and 24 pixels on the + /// left, right, and bottom to separate the [content] from the other edges of + /// the dialog. + /// + /// If [ThemeData.useMaterial3] is true, the top padding separating the + /// content from the title defaults to 16 pixels instead of 20 pixels. + final EdgeInsetsGeometry? contentPadding; + + /// Style for the text in the [content] of this [AlertDialog]. + /// + /// If null, [DialogTheme.contentTextStyle] is used. If that's null, defaults + /// to [TextTheme.titleMedium] of [ThemeData.textTheme]. + final TextStyle? contentTextStyle; + + /// The (optional) set of actions that are displayed at the bottom of the + /// dialog with an [OverflowBar]. + /// + /// Typically this is a list of [TextButton] widgets. It is recommended to + /// set the [Text.textAlign] to [TextAlign.end] for the [Text] within the + /// [TextButton], so that buttons whose labels wrap to an extra line align + /// with the overall [OverflowBar]'s alignment within the dialog. + /// + /// If the [title] is not null but the [content] _is_ null, then an extra 20 + /// pixels of padding is added above the [OverflowBar] to separate the [title] + /// from the [actions]. + final List<Widget>? actions; + + /// Padding around the set of [actions] at the bottom of the dialog. + /// + /// Typically used to provide padding to the button bar between the button bar + /// and the edges of the dialog. + /// + /// The [buttonPadding] may contribute to the padding on the edges of + /// [actions] as well. + /// + /// If there are no [actions], then no padding will be included. + /// + /// {@tool snippet} + /// This is an example of a set of actions aligned with the content widget. + /// ```dart + /// AlertDialog( + /// title: const Text('Title'), + /// content: Container(width: 200, height: 200, color: Colors.green), + /// actions: <Widget>[ + /// ElevatedButton(onPressed: () {}, child: const Text('Button 1')), + /// ElevatedButton(onPressed: () {}, child: const Text('Button 2')), + /// ], + /// actionsPadding: const EdgeInsets.symmetric(horizontal: 8.0), + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [OverflowBar], which [actions] configures to lay itself out. + final EdgeInsetsGeometry? actionsPadding; + + /// Defines the horizontal layout of the [actions] according to the same + /// rules as for [Row.mainAxisAlignment]. + /// + /// This parameter is passed along to the dialog's [OverflowBar]. + /// + /// If this parameter is null (the default) then [MainAxisAlignment.end] + /// is used. + final MainAxisAlignment? actionsAlignment; + + /// The horizontal alignment of [actions] within the vertical + /// "overflow" layout. + /// + /// If the dialog's [actions] do not fit into a single row, then they + /// are arranged in a column. This parameter controls the horizontal + /// alignment of widgets in the case of an overflow. + /// + /// If this parameter is null (the default) then [OverflowBarAlignment.end] + /// is used. + /// + /// See also: + /// + /// * [OverflowBar], which [actions] configures to lay itself out. + final OverflowBarAlignment? actionsOverflowAlignment; + + /// The vertical direction of [actions] if the children overflow + /// horizontally. + /// + /// If the dialog's [actions] do not fit into a single row, then they + /// are arranged in a column. The first action is at the top of the + /// column if this property is set to [VerticalDirection.down], since it + /// "starts" at the top and "ends" at the bottom. On the other hand, + /// the first action will be at the bottom of the column if this + /// property is set to [VerticalDirection.up], since it "starts" at the + /// bottom and "ends" at the top. + /// + /// See also: + /// + /// * [OverflowBar], which [actions] configures to lay itself out. + final VerticalDirection? actionsOverflowDirection; + + /// The spacing between [actions] when the [OverflowBar] switches to a column + /// layout because the actions don't fit horizontally. + /// + /// If the widgets in [actions] do not fit into a single row, they are + /// arranged into a column. This parameter provides additional vertical space + /// between buttons when it does overflow. + /// + /// The button spacing may appear to be more than the value provided. This is + /// because most buttons adhere to the [MaterialTapTargetSize] of 48px. So, + /// even though a button might visually be 36px in height, it might still take + /// up to 48px vertically. + /// + /// If null then no spacing will be added in between buttons in an overflow + /// state. + final double? actionsOverflowButtonSpacing; + + /// The padding that surrounds each button in [actions]. + /// + /// This is different from [actionsPadding], which defines the padding + /// between the entire button bar and the edges of the dialog. + /// + /// If this property is null, then it will default to + /// 8.0 logical pixels on the left and right. + final EdgeInsetsGeometry? buttonPadding; + + /// {@macro flutter.material.dialog.backgroundColor} + final Color? backgroundColor; + + /// {@macro flutter.material.dialog.elevation} + final double? elevation; + + /// {@macro flutter.material.dialog.shadowColor} + final Color? shadowColor; + + /// {@macro flutter.material.dialog.surfaceTintColor} + final Color? surfaceTintColor; + + /// The semantic label of the dialog used by accessibility frameworks to + /// announce screen transitions when the dialog is opened and closed. + /// + /// In iOS, if this label is not provided, a semantic label will be inferred + /// from the [title] if it is not null. + /// + /// In Android, if this label is not provided, the dialog will use the + /// [MaterialLocalizations.alertDialogLabel] as its label. + /// + /// See also: + /// + /// * [SemanticsConfiguration.namesRoute], for a description of how this + /// value is used. + final String? semanticLabel; + + /// {@macro flutter.material.dialog.insetPadding} + final EdgeInsets insetPadding; + + /// {@macro flutter.material.dialog.clipBehavior} + final Clip clipBehavior; + + /// {@macro flutter.material.dialog.shape} + final ShapeBorder? shape; + + /// {@macro flutter.material.dialog.alignment} + final AlignmentGeometry? alignment; + + /// Determines whether the [title] and [content] widgets are wrapped in a + /// scrollable. + /// + /// This configuration is used when the [title] and [content] are expected + /// to overflow. Both [title] and [content] are wrapped in a scroll view, + /// allowing all overflowed content to be visible while still showing the + /// button bar. + final bool scrollable; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + final ThemeData theme = Theme.of(context); + + final DialogTheme dialogTheme = DialogTheme.of(context); + final DialogTheme defaults = theme.useMaterial3 ? _DialogDefaultsM3(context) : _DialogDefaultsM2(context); + + String? label = semanticLabel; + switch (theme.platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + break; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + label ??= MaterialLocalizations.of(context).alertDialogLabel; + } + + // The paddingScaleFactor is used to adjust the padding of Dialog's + // children. + final double paddingScaleFactor = _paddingScaleFactor(MediaQuery.textScalerOf(context).textScaleFactor); + final TextDirection? textDirection = Directionality.maybeOf(context); + + Widget? iconWidget; + Widget? titleWidget; + Widget? contentWidget; + Widget? actionsWidget; + + if (icon != null) { + final bool belowIsTitle = title != null; + final bool belowIsContent = !belowIsTitle && content != null; + final EdgeInsets defaultIconPadding = EdgeInsets.only( + left: 24.0, + top: 24.0, + right: 24.0, + bottom: belowIsTitle ? 16.0 : belowIsContent ? 0.0 : 24.0, + ); + final EdgeInsets effectiveIconPadding = iconPadding?.resolve(textDirection) ?? defaultIconPadding; + iconWidget = Padding( + padding: EdgeInsets.only( + left: effectiveIconPadding.left * paddingScaleFactor, + right: effectiveIconPadding.right * paddingScaleFactor, + top: effectiveIconPadding.top * paddingScaleFactor, + bottom: effectiveIconPadding.bottom, + ), + child: IconTheme( + data: IconThemeData( + color: iconColor ?? dialogTheme.iconColor ?? defaults.iconColor, + ), + child: icon!, + ), + ); + } + + if (title != null) { + final EdgeInsets defaultTitlePadding = EdgeInsets.only( + left: 24.0, + top: icon == null ? 24.0 : 0.0, + right: 24.0, + bottom: content == null ? 20.0 : 0.0, + ); + final EdgeInsets effectiveTitlePadding = titlePadding?.resolve(textDirection) ?? defaultTitlePadding; + titleWidget = Padding( + padding: EdgeInsets.only( + left: effectiveTitlePadding.left * paddingScaleFactor, + right: effectiveTitlePadding.right * paddingScaleFactor, + top: icon == null ? effectiveTitlePadding.top * paddingScaleFactor : effectiveTitlePadding.top, + bottom: effectiveTitlePadding.bottom, + ), + child: DefaultTextStyle( + style: titleTextStyle ?? dialogTheme.titleTextStyle ?? defaults.titleTextStyle!, + textAlign: icon == null ? TextAlign.start : TextAlign.center, + child: Semantics( + // For iOS platform, the focus always lands on the title. + // Set nameRoute to false to avoid title being announce twice. + namesRoute: label == null && theme.platform != TargetPlatform.iOS, + container: true, + child: title, + ), + ), + ); + } + + if (content != null) { + final EdgeInsets defaultContentPadding = EdgeInsets.only( + left: 24.0, + top: theme.useMaterial3 ? 16.0 : 20.0, + right: 24.0, + bottom: 24.0, + ); + final EdgeInsets effectiveContentPadding = contentPadding?.resolve(textDirection) ?? defaultContentPadding; + contentWidget = Padding( + padding: EdgeInsets.only( + left: effectiveContentPadding.left * paddingScaleFactor, + right: effectiveContentPadding.right * paddingScaleFactor, + top: title == null && icon == null + ? effectiveContentPadding.top * paddingScaleFactor + : effectiveContentPadding.top, + bottom: effectiveContentPadding.bottom, + ), + child: DefaultTextStyle( + style: contentTextStyle ?? dialogTheme.contentTextStyle ?? defaults.contentTextStyle!, + child: Semantics( + container: true, + child: content, + ), + ), + ); + } + + if (actions != null) { + final double spacing = (buttonPadding?.horizontal ?? 16) / 2; + actionsWidget = Padding( + padding: actionsPadding ?? dialogTheme.actionsPadding ?? ( + theme.useMaterial3 ? defaults.actionsPadding! : defaults.actionsPadding!.add(EdgeInsets.all(spacing)) + ), + child: OverflowBar( + alignment: actionsAlignment ?? MainAxisAlignment.end, + spacing: spacing, + overflowAlignment: actionsOverflowAlignment ?? OverflowBarAlignment.end, + overflowDirection: actionsOverflowDirection ?? VerticalDirection.down, + overflowSpacing: actionsOverflowButtonSpacing ?? 0, + children: actions!, + ), + ); + } + + List<Widget> columnChildren; + if (scrollable) { + columnChildren = <Widget>[ + if (title != null || content != null) + Flexible( + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + if (icon != null) iconWidget!, + if (title != null) titleWidget!, + if (content != null) contentWidget!, + ], + ), + ), + ), + if (actions != null) + actionsWidget!, + ]; + } else { + columnChildren = <Widget>[ + if (icon != null) iconWidget!, + if (title != null) titleWidget!, + if (content != null) Flexible(child: contentWidget!), + if (actions != null) actionsWidget!, + ]; + } + + Widget dialogChild = IntrinsicWidth( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: columnChildren, + ), + ); + + if (label != null) { + dialogChild = Semantics( + scopesRoute: true, + explicitChildNodes: true, + namesRoute: true, + label: label, + child: dialogChild, + ); + } + + return Dialog( + backgroundColor: backgroundColor, + elevation: elevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + insetPadding: insetPadding, + clipBehavior: clipBehavior, + shape: shape, + alignment: alignment, + child: dialogChild, + ); + } +} + +class _AdaptiveAlertDialog extends AlertDialog { + const _AdaptiveAlertDialog({ + super.key, + super.icon, + super.iconPadding, + super.iconColor, + super.title, + super.titlePadding, + super.titleTextStyle, + super.content, + super.contentPadding, + super.contentTextStyle, + super.actions, + super.actionsPadding, + super.actionsAlignment, + super.actionsOverflowAlignment, + super.actionsOverflowDirection, + super.actionsOverflowButtonSpacing, + super.buttonPadding, + super.backgroundColor, + super.elevation, + super.shadowColor, + super.surfaceTintColor, + super.semanticLabel, + super.insetPadding = _defaultInsetPadding, + super.clipBehavior = Clip.none, + super.shape, + super.alignment, + super.scrollable = false, + this.scrollController, + this.actionScrollController, + this.insetAnimationDuration = const Duration(milliseconds: 100), + this.insetAnimationCurve = Curves.decelerate, + }); + + final ScrollController? scrollController; + final ScrollController? actionScrollController; + final Duration insetAnimationDuration; + final Curve insetAnimationCurve; + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + break; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return CupertinoAlertDialog( + title: title, + content: content, + actions: actions ?? <Widget>[], + scrollController: scrollController, + actionScrollController: actionScrollController, + insetAnimationDuration: insetAnimationDuration, + insetAnimationCurve: insetAnimationCurve, + ); + } + return super.build(context); + } +} + +/// An option used in a [SimpleDialog]. +/// +/// A simple dialog offers the user a choice between several options. This +/// widget is commonly used to represent each of the options. If the user +/// selects this option, the widget will call the [onPressed] callback, which +/// typically uses [Navigator.pop] to close the dialog. +/// +/// The padding on a [SimpleDialogOption] is configured to combine with the +/// default [SimpleDialog.contentPadding] so that each option ends up 8 pixels +/// from the other vertically, with 20 pixels of spacing between the dialog's +/// title and the first option, and 24 pixels of spacing between the last option +/// and the bottom of the dialog. +/// +/// {@tool snippet} +/// +/// ```dart +/// SimpleDialogOption( +/// onPressed: () { Navigator.pop(context, Department.treasury); }, +/// child: const Text('Treasury department'), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [SimpleDialog], for a dialog in which to use this widget. +/// * [showDialog], which actually displays the dialog and returns its result. +/// * [TextButton], which are commonly used as actions in other kinds of +/// dialogs, such as [AlertDialog]s. +/// * <https://material.io/design/components/dialogs.html#simple-dialog> +class SimpleDialogOption extends StatelessWidget { + /// Creates an option for a [SimpleDialog]. + const SimpleDialogOption({ + super.key, + this.onPressed, + this.padding, + this.child, + }); + + /// The callback that is called when this option is selected. + /// + /// If this is set to null, the option cannot be selected. + /// + /// When used in a [SimpleDialog], this will typically call [Navigator.pop] + /// with a value for [showDialog] to complete its future with. + final VoidCallback? onPressed; + + /// The widget below this widget in the tree. + /// + /// Typically a [Text] widget. + final Widget? child; + + /// The amount of space to surround the [child] with. + /// + /// Defaults to EdgeInsets.symmetric(vertical: 8.0, horizontal: 24.0). + final EdgeInsets? padding; + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: onPressed, + child: Padding( + padding: padding ?? const EdgeInsets.symmetric(vertical: 8.0, horizontal: 24.0), + child: child, + ), + ); + } +} + +/// A simple Material Design dialog. +/// +/// A simple dialog offers the user a choice between several options. A simple +/// dialog has an optional title that is displayed above the choices. +/// +/// Choices are normally represented using [SimpleDialogOption] widgets. If +/// other widgets are used, see [contentPadding] for notes regarding the +/// conventions for obtaining the spacing expected by Material Design. +/// +/// For dialogs that inform the user about a situation, consider using an +/// [AlertDialog]. +/// +/// Typically passed as the child widget to [showDialog], which displays the +/// dialog. +/// +/// {@animation 350 622 https://flutter.github.io/assets-for-api-docs/assets/material/simple_dialog.mp4} +/// +/// {@tool snippet} +/// +/// In this example, the user is asked to select between two options. These +/// options are represented as an enum. The [showDialog] method here returns +/// a [Future] that completes to a value of that enum. If the user cancels +/// the dialog (e.g. by hitting the back button on Android, or tapping on the +/// mask behind the dialog) then the future completes with the null value. +/// +/// The return value in this example is used as the index for a switch statement. +/// One advantage of using an enum as the return value and then using that to +/// drive a switch statement is that the analyzer will flag any switch statement +/// that doesn't mention every value in the enum. +/// +/// ```dart +/// Future<void> _askedToLead() async { +/// switch (await showDialog<Department>( +/// context: context, +/// builder: (BuildContext context) { +/// return SimpleDialog( +/// title: const Text('Select assignment'), +/// children: <Widget>[ +/// SimpleDialogOption( +/// onPressed: () { Navigator.pop(context, Department.treasury); }, +/// child: const Text('Treasury department'), +/// ), +/// SimpleDialogOption( +/// onPressed: () { Navigator.pop(context, Department.state); }, +/// child: const Text('State department'), +/// ), +/// ], +/// ); +/// } +/// )) { +/// case Department.treasury: +/// // Let's go. +/// // ... +/// break; +/// case Department.state: +/// // ... +/// break; +/// case null: +/// // dialog dismissed +/// break; +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [SimpleDialogOption], which are options used in this type of dialog. +/// * [AlertDialog], for dialogs that have a row of buttons below the body. +/// * [Dialog], on which [SimpleDialog] and [AlertDialog] are based. +/// * [showDialog], which actually displays the dialog and returns its result. +/// * <https://material.io/design/components/dialogs.html#simple-dialog> +class SimpleDialog extends StatelessWidget { + /// Creates a simple dialog. + /// + /// Typically used in conjunction with [showDialog]. + const SimpleDialog({ + super.key, + this.title, + this.titlePadding = const EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 0.0), + this.titleTextStyle, + this.children, + this.contentPadding = const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0), + this.backgroundColor, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.semanticLabel, + this.insetPadding = _defaultInsetPadding, + this.clipBehavior = Clip.none, + this.shape, + this.alignment, + }); + + /// The (optional) title of the dialog is displayed in a large font at the top + /// of the dialog. + /// + /// Typically a [Text] widget. + final Widget? title; + + /// Padding around the title. + /// + /// If there is no title, no padding will be provided. + /// + /// By default, this provides the recommend Material Design padding of 24 + /// pixels around the left, top, and right edges of the title. + /// + /// See [contentPadding] for the conventions regarding padding between the + /// [title] and the [children]. + final EdgeInsetsGeometry titlePadding; + + /// Style for the text in the [title] of this [SimpleDialog]. + /// + /// If null, [DialogTheme.titleTextStyle] is used. If that's null, defaults to + /// [TextTheme.titleLarge] of [ThemeData.textTheme]. + final TextStyle? titleTextStyle; + + /// The (optional) content of the dialog is displayed in a + /// [SingleChildScrollView] underneath the title. + /// + /// Typically a list of [SimpleDialogOption]s. + final List<Widget>? children; + + /// Padding around the content. + /// + /// By default, this is 12 pixels on the top and 16 pixels on the bottom. This + /// is intended to be combined with children that have 24 pixels of padding on + /// the left and right, and 8 pixels of padding on the top and bottom, so that + /// the content ends up being indented 20 pixels from the title, 24 pixels + /// from the bottom, and 24 pixels from the sides. + /// + /// The [SimpleDialogOption] widget uses such padding. + /// + /// If there is no [title], the [contentPadding] should be adjusted so that + /// the top padding ends up being 24 pixels. + final EdgeInsetsGeometry contentPadding; + + /// {@macro flutter.material.dialog.backgroundColor} + final Color? backgroundColor; + + /// {@macro flutter.material.dialog.elevation} + final double? elevation; + + /// {@macro flutter.material.dialog.shadowColor} + final Color? shadowColor; + + /// {@macro flutter.material.dialog.surfaceTintColor} + final Color? surfaceTintColor; + + /// The semantic label of the dialog used by accessibility frameworks to + /// announce screen transitions when the dialog is opened and closed. + /// + /// If this label is not provided, a semantic label will be inferred from the + /// [title] if it is not null. If there is no title, the label will be taken + /// from [MaterialLocalizations.dialogLabel]. + /// + /// See also: + /// + /// * [SemanticsConfiguration.namesRoute], for a description of how this + /// value is used. + final String? semanticLabel; + + /// {@macro flutter.material.dialog.insetPadding} + final EdgeInsets insetPadding; + + /// {@macro flutter.material.dialog.clipBehavior} + final Clip clipBehavior; + + /// {@macro flutter.material.dialog.shape} + final ShapeBorder? shape; + + /// {@macro flutter.material.dialog.shape} + final AlignmentGeometry? alignment; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + final ThemeData theme = Theme.of(context); + + String? label = semanticLabel; + switch (theme.platform) { + case TargetPlatform.macOS: + case TargetPlatform.iOS: + break; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + label ??= MaterialLocalizations.of(context).dialogLabel; + } + + // The paddingScaleFactor is used to adjust the padding of Dialog + // children. + final double paddingScaleFactor = _paddingScaleFactor(MediaQuery.textScalerOf(context).textScaleFactor); + final TextDirection? textDirection = Directionality.maybeOf(context); + + Widget? titleWidget; + if (title != null) { + final EdgeInsets effectiveTitlePadding = titlePadding.resolve(textDirection); + titleWidget = Padding( + padding: EdgeInsets.only( + left: effectiveTitlePadding.left * paddingScaleFactor, + right: effectiveTitlePadding.right * paddingScaleFactor, + top: effectiveTitlePadding.top * paddingScaleFactor, + bottom: children == null ? effectiveTitlePadding.bottom * paddingScaleFactor : effectiveTitlePadding.bottom, + ), + child: DefaultTextStyle( + style: titleTextStyle ?? DialogTheme.of(context).titleTextStyle ?? theme.textTheme.titleLarge!, + child: Semantics( + // For iOS platform, the focus always lands on the title. + // Set nameRoute to false to avoid title being announce twice. + namesRoute: label == null && theme.platform != TargetPlatform.iOS, + container: true, + child: title, + ), + ), + ); + } + + Widget? contentWidget; + if (children != null) { + final EdgeInsets effectiveContentPadding = contentPadding.resolve(textDirection); + contentWidget = Flexible( + child: SingleChildScrollView( + padding: EdgeInsets.only( + left: effectiveContentPadding.left * paddingScaleFactor, + right: effectiveContentPadding.right * paddingScaleFactor, + top: title == null ? effectiveContentPadding.top * paddingScaleFactor : effectiveContentPadding.top, + bottom: effectiveContentPadding.bottom * paddingScaleFactor, + ), + child: ListBody(children: children!), + ), + ); + } + + Widget dialogChild = IntrinsicWidth( + stepWidth: 56.0, + child: ConstrainedBox( + constraints: const BoxConstraints(minWidth: 280.0), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + if (title != null) titleWidget!, + if (children != null) contentWidget!, + ], + ), + ), + ); + + if (label != null) { + dialogChild = Semantics( + scopesRoute: true, + explicitChildNodes: true, + namesRoute: true, + label: label, + child: dialogChild, + ); + } + return Dialog( + backgroundColor: backgroundColor, + elevation: elevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + insetPadding: insetPadding, + clipBehavior: clipBehavior, + shape: shape, + alignment: alignment, + child: dialogChild, + ); + } +} + +Widget _buildMaterialDialogTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) { + return FadeTransition( + opacity: CurvedAnimation( + parent: animation, + curve: Curves.easeOut, + ), + child: child, + ); +} + +/// Displays a Material dialog above the current contents of the app, with +/// Material entrance and exit animations, modal barrier color, and modal +/// barrier behavior (dialog is dismissible with a tap on the barrier). +/// +/// This function takes a `builder` which typically builds a [Dialog] widget. +/// Content below the dialog is dimmed with a [ModalBarrier]. The widget +/// returned by the `builder` does not share a context with the location that +/// [showDialog] is originally called from. Use a [StatefulBuilder] or a +/// custom [StatefulWidget] if the dialog needs to update dynamically. +/// +/// The `context` argument is used to look up the [Navigator] and [Theme] for +/// the dialog. It is only used when the method is called. Its corresponding +/// widget can be safely removed from the tree before the dialog is closed. +/// +/// The `barrierDismissible` argument is used to indicate whether tapping on the +/// barrier will dismiss the dialog. It is `true` by default and can not be `null`. +/// +/// The `barrierColor` argument is used to specify the color of the modal +/// barrier that darkens everything below the dialog. If `null` the default color +/// `Colors.black54` is used. +/// +/// The `useSafeArea` argument is used to indicate if the dialog should only +/// display in 'safe' areas of the screen not used by the operating system +/// (see [SafeArea] for more details). It is `true` by default, which means +/// the dialog will not overlap operating system areas. If it is set to `false` +/// the dialog will only be constrained by the screen size. It can not be `null`. +/// +/// The `useRootNavigator` argument is used to determine whether to push the +/// dialog to the [Navigator] furthest from or nearest to the given `context`. +/// By default, `useRootNavigator` is `true` and the dialog route created by +/// this method is pushed to the root navigator. It can not be `null`. +/// +/// The `routeSettings` argument is passed to [showGeneralDialog], +/// see [RouteSettings] for details. +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// If the application has multiple [Navigator] objects, it may be necessary to +/// call `Navigator.of(context, rootNavigator: true).pop(result)` to close the +/// dialog rather than just `Navigator.pop(context, result)`. +/// +/// Returns a [Future] that resolves to the value (if any) that was passed to +/// [Navigator.pop] when the dialog was closed. +/// +/// {@tool dartpad} +/// This sample demonstrates how to use [showDialog] to display a dialog box. +/// +/// ** See code in examples/api/lib/material/dialog/show_dialog.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of [showDialog], as described in: +/// https://m3.material.io/components/dialogs/overview +/// +/// ** See code in examples/api/lib/material/dialog/show_dialog.1.dart ** +/// {@end-tool} +/// +/// ### State Restoration in Dialogs +/// +/// Using this method will not enable state restoration for the dialog. In order +/// to enable state restoration for a dialog, use [Navigator.restorablePush] +/// or [Navigator.restorablePushNamed] with [DialogRoute]. +/// +/// For more information about state restoration, see [RestorationManager]. +/// +/// {@tool dartpad} +/// This sample demonstrates how to create a restorable Material dialog. This is +/// accomplished by enabling state restoration by specifying +/// [MaterialApp.restorationScopeId] and using [Navigator.restorablePush] to +/// push [DialogRoute] when the button is tapped. +/// +/// {@macro flutter.widgets.RestorationManager} +/// +/// If not null, `traversalEdgeBehavior` argument specifies the transfer of +/// focus beyond the first and the last items of the dialog route. By default, +/// uses [TraversalEdgeBehavior.closedLoop], because it's typical for dialogs +/// to allow users to cycle through widgets inside it without leaving the +/// dialog. +/// +/// ** See code in examples/api/lib/material/dialog/show_dialog.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AlertDialog], for dialogs that have a row of buttons below a body. +/// * [SimpleDialog], which handles the scrolling of the contents and does +/// not show buttons below its body. +/// * [Dialog], on which [SimpleDialog] and [AlertDialog] are based. +/// * [showCupertinoDialog], which displays an iOS-style dialog. +/// * [showGeneralDialog], which allows for customization of the dialog popup. +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +/// * <https://material.io/design/components/dialogs.html> +/// * <https://m3.material.io/components/dialogs> +Future<T?> showDialog<T>({ + required BuildContext context, + required WidgetBuilder builder, + bool barrierDismissible = true, + Color? barrierColor, + String? barrierLabel, + bool useSafeArea = true, + bool useRootNavigator = true, + RouteSettings? routeSettings, + Offset? anchorPoint, + TraversalEdgeBehavior? traversalEdgeBehavior, +}) { + assert(_debugIsActive(context)); + assert(debugCheckHasMaterialLocalizations(context)); + + final CapturedThemes themes = InheritedTheme.capture( + from: context, + to: Navigator.of( + context, + rootNavigator: useRootNavigator, + ).context, + ); + + return Navigator.of(context, rootNavigator: useRootNavigator).push<T>(DialogRoute<T>( + context: context, + builder: builder, + barrierColor: barrierColor ?? Colors.black54, + barrierDismissible: barrierDismissible, + barrierLabel: barrierLabel, + useSafeArea: useSafeArea, + settings: routeSettings, + themes: themes, + anchorPoint: anchorPoint, + traversalEdgeBehavior: traversalEdgeBehavior ?? TraversalEdgeBehavior.closedLoop, + )); +} + +/// Displays either a Material or Cupertino dialog depending on platform. +/// +/// On most platforms this function will act the same as [showDialog], except +/// for iOS and macOS, in which case it will act the same as +/// [showCupertinoDialog]. +/// +/// On Cupertino platforms, [barrierColor], [useSafeArea], and +/// [traversalEdgeBehavior] are ignored. +Future<T?> showAdaptiveDialog<T>({ + required BuildContext context, + required WidgetBuilder builder, + bool? barrierDismissible, + Color? barrierColor, + String? barrierLabel, + bool useSafeArea = true, + bool useRootNavigator = true, + RouteSettings? routeSettings, + Offset? anchorPoint, + TraversalEdgeBehavior? traversalEdgeBehavior, +}) { + final ThemeData theme = Theme.of(context); + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return showDialog<T>( + context: context, + builder: builder, + barrierDismissible: barrierDismissible ?? true, + barrierColor: barrierColor, + barrierLabel: barrierLabel, + useSafeArea: useSafeArea, + useRootNavigator: useRootNavigator, + routeSettings: routeSettings, + anchorPoint: anchorPoint, + traversalEdgeBehavior: traversalEdgeBehavior, + ); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return showCupertinoDialog<T>( + context: context, + builder: builder, + barrierDismissible: barrierDismissible ?? false, + barrierLabel: barrierLabel, + useRootNavigator: useRootNavigator, + anchorPoint: anchorPoint, + routeSettings: routeSettings, + ); + } +} + +bool _debugIsActive(BuildContext context) { + if (context is Element && !context.debugIsActive) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('This BuildContext is no longer valid.'), + ErrorDescription( + 'The showDialog function context parameter is a BuildContext that is no longer valid.' + ), + ErrorHint( + 'This can commonly occur when the showDialog function is called after awaiting a Future. ' + 'In this situation the BuildContext might refer to a widget that has already been disposed during the await. ' + 'Consider using a parent context instead.', + ), + ]); + } + return true; +} + +/// A dialog route with Material entrance and exit animations, +/// modal barrier color, and modal barrier behavior (dialog is dismissible +/// with a tap on the barrier). +/// +/// It is used internally by [showDialog] or can be directly pushed +/// onto the [Navigator] stack to enable state restoration. See +/// [showDialog] for a state restoration app example. +/// +/// This function takes a `builder` which typically builds a [Dialog] widget. +/// Content below the dialog is dimmed with a [ModalBarrier]. The widget +/// returned by the `builder` does not share a context with the location that +/// `showDialog` is originally called from. Use a [StatefulBuilder] or a +/// custom [StatefulWidget] if the dialog needs to update dynamically. +/// +/// The `context` argument is used to look up +/// [MaterialLocalizations.modalBarrierDismissLabel], which provides the +/// modal with a localized accessibility label that will be used for the +/// modal's barrier. However, a custom `barrierLabel` can be passed in as well. +/// +/// The `barrierDismissible` argument is used to indicate whether tapping on the +/// barrier will dismiss the dialog. It is `true` by default and cannot be `null`. +/// +/// The `barrierColor` argument is used to specify the color of the modal +/// barrier that darkens everything below the dialog. If `null`, the default +/// color `Colors.black54` is used. +/// +/// The `useSafeArea` argument is used to indicate if the dialog should only +/// display in 'safe' areas of the screen not used by the operating system +/// (see [SafeArea] for more details). It is `true` by default, which means +/// the dialog will not overlap operating system areas. If it is set to `false` +/// the dialog will only be constrained by the screen size. It can not be `null`. +/// +/// The `settings` argument define the settings for this route. See +/// [RouteSettings] for details. +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// See also: +/// +/// * [showDialog], which is a way to display a DialogRoute. +/// * [showGeneralDialog], which allows for customization of the dialog popup. +/// * [showCupertinoDialog], which displays an iOS-style dialog. +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +class DialogRoute<T> extends RawDialogRoute<T> { + /// A dialog route with Material entrance and exit animations, + /// modal barrier color, and modal barrier behavior (dialog is dismissible + /// with a tap on the barrier). + DialogRoute({ + required BuildContext context, + required WidgetBuilder builder, + CapturedThemes? themes, + super.barrierColor = Colors.black54, + super.barrierDismissible, + String? barrierLabel, + bool useSafeArea = true, + super.settings, + super.anchorPoint, + super.traversalEdgeBehavior, + }) : super( + pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) { + final Widget pageChild = Builder(builder: builder); + Widget dialog = themes?.wrap(pageChild) ?? pageChild; + if (useSafeArea) { + dialog = SafeArea(child: dialog); + } + return dialog; + }, + barrierLabel: barrierLabel ?? MaterialLocalizations.of(context).modalBarrierDismissLabel, + transitionDuration: const Duration(milliseconds: 150), + transitionBuilder: _buildMaterialDialogTransitions, + ); +} + +double _paddingScaleFactor(double textScaleFactor) { + final double clampedTextScaleFactor = clampDouble(textScaleFactor, 1.0, 2.0); + // The final padding scale factor is clamped between 1/3 and 1. For example, + // a non-scaled padding of 24 will produce a padding between 24 and 8. + return lerpDouble(1.0, 1.0 / 3.0, clampedTextScaleFactor - 1.0)!; +} + +// Hand coded defaults based on Material Design 2. +class _DialogDefaultsM2 extends DialogTheme { + _DialogDefaultsM2(this.context) + : _textTheme = Theme.of(context).textTheme, + _iconTheme = Theme.of(context).iconTheme, + super( + alignment: Alignment.center, + elevation: 24.0, + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))), + ); + + final BuildContext context; + final TextTheme _textTheme; + final IconThemeData _iconTheme; + + @override + Color? get iconColor => _iconTheme.color; + + @override + Color? get backgroundColor => Theme.of(context).dialogBackgroundColor; + + @override + Color? get shadowColor => Theme.of(context).shadowColor; + + @override + TextStyle? get titleTextStyle => _textTheme.titleLarge; + + @override + TextStyle? get contentTextStyle => _textTheme.titleMedium; + + @override + EdgeInsetsGeometry? get actionsPadding => EdgeInsets.zero; +} + +// BEGIN GENERATED TOKEN PROPERTIES - Dialog + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _DialogDefaultsM3 extends DialogTheme { + _DialogDefaultsM3(this.context) + : super( + alignment: Alignment.center, + elevation: 6.0, + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0))), + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + Color? get iconColor => _colors.secondary; + + @override + Color? get backgroundColor => _colors.surface; + + @override + Color? get shadowColor => Colors.transparent; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + TextStyle? get titleTextStyle => _textTheme.headlineSmall; + + @override + TextStyle? get contentTextStyle => _textTheme.bodyMedium; + + @override + EdgeInsetsGeometry? get actionsPadding => const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0); +} + +// END GENERATED TOKEN PROPERTIES - Dialog + +// BEGIN GENERATED TOKEN PROPERTIES - DialogFullscreen + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _DialogFullscreenDefaultsM3 extends DialogTheme { + const _DialogFullscreenDefaultsM3(this.context); + + final BuildContext context; + + @override + Color? get backgroundColor => Theme.of(context).colorScheme.surface; +} + +// END GENERATED TOKEN PROPERTIES - DialogFullscreen diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dialog_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dialog_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..f27728418b64d0cbbbae092ff66954efa06486ea --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dialog_theme.dart @@ -0,0 +1,167 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +/// Defines a theme for [Dialog] widgets. +/// +/// Descendant widgets obtain the current [DialogTheme] object using +/// `DialogTheme.of(context)`. Instances of [DialogTheme] can be customized with +/// [DialogTheme.copyWith]. +/// +/// [titleTextStyle] and [contentTextStyle] are used in [AlertDialog]s and [SimpleDialog]s. +/// +/// See also: +/// +/// * [Dialog], a dialog that can be customized using this [DialogTheme]. +/// * [AlertDialog], a dialog that can be customized using this [DialogTheme]. +/// * [SimpleDialog], a dialog that can be customized using this [DialogTheme]. +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class DialogTheme with Diagnosticable { + /// Creates a dialog theme that can be used for [ThemeData.dialogTheme]. + const DialogTheme({ + this.backgroundColor, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.shape, + this.alignment, + this.iconColor, + this.titleTextStyle, + this.contentTextStyle, + this.actionsPadding, + }); + + /// Overrides the default value for [Dialog.backgroundColor]. + final Color? backgroundColor; + + /// Overrides the default value for [Dialog.elevation]. + final double? elevation; + + /// Overrides the default value for [Dialog.shadowColor]. + final Color? shadowColor; + + /// Overrides the default value for [Dialog.surfaceTintColor]. + final Color? surfaceTintColor; + + /// Overrides the default value for [Dialog.shape]. + final ShapeBorder? shape; + + /// Overrides the default value for [Dialog.alignment]. + final AlignmentGeometry? alignment; + + /// Overrides the default value for [DefaultTextStyle] for [SimpleDialog.title] and + /// [AlertDialog.title]. + final TextStyle? titleTextStyle; + + /// Overrides the default value for [DefaultTextStyle] for [SimpleDialog.children] and + /// [AlertDialog.content]. + final TextStyle? contentTextStyle; + + /// Overrides the default value for [AlertDialog.actionsPadding]. + final EdgeInsetsGeometry? actionsPadding; + + /// Used to configure the [IconTheme] for the [AlertDialog.icon] widget. + final Color? iconColor; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + DialogTheme copyWith({ + Color? backgroundColor, + double? elevation, + Color? shadowColor, + Color? surfaceTintColor, + ShapeBorder? shape, + AlignmentGeometry? alignment, + Color? iconColor, + TextStyle? titleTextStyle, + TextStyle? contentTextStyle, + EdgeInsetsGeometry? actionsPadding, + }) { + return DialogTheme( + backgroundColor: backgroundColor ?? this.backgroundColor, + elevation: elevation ?? this.elevation, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + shape: shape ?? this.shape, + alignment: alignment ?? this.alignment, + iconColor: iconColor ?? this.iconColor, + titleTextStyle: titleTextStyle ?? this.titleTextStyle, + contentTextStyle: contentTextStyle ?? this.contentTextStyle, + actionsPadding: actionsPadding ?? this.actionsPadding, + ); + } + + /// The data from the closest [DialogTheme] instance given the build context. + static DialogTheme of(BuildContext context) { + return Theme.of(context).dialogTheme; + } + + /// Linearly interpolate between two dialog themes. + /// + /// {@macro dart.ui.shadow.lerp} + static DialogTheme lerp(DialogTheme? a, DialogTheme? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return DialogTheme( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + alignment: AlignmentGeometry.lerp(a?.alignment, b?.alignment, t), + iconColor: Color.lerp(a?.iconColor, b?.iconColor, t), + titleTextStyle: TextStyle.lerp(a?.titleTextStyle, b?.titleTextStyle, t), + contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t), + actionsPadding: EdgeInsetsGeometry.lerp(a?.actionsPadding, b?.actionsPadding, t), + ); + } + + @override + int get hashCode => shape.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is DialogTheme + && other.backgroundColor == backgroundColor + && other.elevation == elevation + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.shape == shape + && other.alignment == alignment + && other.iconColor == iconColor + && other.titleTextStyle == titleTextStyle + && other.contentTextStyle == contentTextStyle + && other.actionsPadding == actionsPadding; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor)); + properties.add(DoubleProperty('elevation', elevation)); + properties.add(ColorProperty('shadowColor', shadowColor)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: null)); + properties.add(ColorProperty('iconColor', iconColor)); + properties.add(DiagnosticsProperty<TextStyle>('titleTextStyle', titleTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('contentTextStyle', contentTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('actionsPadding', actionsPadding, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/divider.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/divider.dart new file mode 100644 index 0000000000000000000000000000000000000000..20f3164f983e0cc43f7f0ee2c666fe07c48e3717 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/divider.dart @@ -0,0 +1,344 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'divider_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// A thin horizontal line, with padding on either side. +/// +/// In the Material Design language, this represents a divider. Dividers can be +/// used in lists, [Drawer]s, and elsewhere to separate content. +/// +/// To create a divider between [ListTile] items, consider using +/// [ListTile.divideTiles], which is optimized for this case. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=_liUC641Nmk} +/// +/// The box's total height is controlled by [height]. The appropriate +/// padding is automatically computed from the height. +/// +/// {@tool dartpad} +/// This sample shows how to display a Divider between an orange and blue box +/// inside a column. The Divider is 20 logical pixels in height and contains a +/// vertically centered black line that is 5 logical pixels thick. The black +/// line is indented by 20 logical pixels. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/divider.png) +/// +/// ** See code in examples/api/lib/material/divider/divider.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of [Divider] widget, as described in: +/// https://m3.material.io/components/divider/overview +/// +/// ** See code in examples/api/lib/material/divider/divider.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [PopupMenuDivider], which is the equivalent but for popup menus. +/// * [ListTile.divideTiles], another approach to dividing widgets in a list. +/// * [VerticalDivider], which is the vertical analog of this widget. +/// * <https://material.io/design/components/dividers.html> +class Divider extends StatelessWidget { + /// Creates a Material Design divider. + /// + /// The [height], [thickness], [indent], and [endIndent] must be null or + /// non-negative. + const Divider({ + super.key, + this.height, + this.thickness, + this.indent, + this.endIndent, + this.color, + }) : assert(height == null || height >= 0.0), + assert(thickness == null || thickness >= 0.0), + assert(indent == null || indent >= 0.0), + assert(endIndent == null || endIndent >= 0.0); + + + /// The divider's height extent. + /// + /// The divider itself is always drawn as a horizontal line that is centered + /// within the height specified by this value. + /// + /// If this is null, then the [DividerThemeData.space] is used. If that is + /// also null, then this defaults to 16.0. + final double? height; + + /// The thickness of the line drawn within the divider. + /// + /// A divider with a [thickness] of 0.0 is always drawn as a line with a + /// height of exactly one device pixel. + /// + /// If this is null, then the [DividerThemeData.thickness] is used. If + /// that is also null, then this defaults to 0.0. + final double? thickness; + + /// The amount of empty space to the leading edge of the divider. + /// + /// If this is null, then the [DividerThemeData.indent] is used. If that is + /// also null, then this defaults to 0.0. + final double? indent; + + /// The amount of empty space to the trailing edge of the divider. + /// + /// If this is null, then the [DividerThemeData.endIndent] is used. If that is + /// also null, then this defaults to 0.0. + final double? endIndent; + + /// The color to use when painting the line. + /// + /// If this is null, then the [DividerThemeData.color] is used. If that is + /// also null, then [ThemeData.dividerColor] is used. + /// + /// {@tool snippet} + /// + /// ```dart + /// const Divider( + /// color: Colors.deepOrange, + /// ) + /// ``` + /// {@end-tool} + final Color? color; + + /// Computes the [BorderSide] that represents a divider. + /// + /// If [color] is null, then [DividerThemeData.color] is used. If that is also + /// null, then if [ThemeData.useMaterial3] is true then it defaults to + /// [ThemeData.colorScheme]'s [ColorScheme.outlineVariant]. Otherwise + /// [ThemeData.dividerColor] is used. + /// + /// If [width] is null, then [DividerThemeData.thickness] is used. If that is + /// also null, then this defaults to 0.0 (a hairline border). + /// + /// If [context] is null, the default color of [BorderSide] is used and the + /// default width of 0.0 is used. + /// + /// {@tool snippet} + /// + /// This example uses this method to create a box that has a divider above and + /// below it. This is sometimes useful with lists, for instance, to separate a + /// scrollable section from the rest of the interface. + /// + /// ```dart + /// DecoratedBox( + /// decoration: BoxDecoration( + /// border: Border( + /// top: Divider.createBorderSide(context), + /// bottom: Divider.createBorderSide(context), + /// ), + /// ), + /// // child: ... + /// ) + /// ``` + /// {@end-tool} + static BorderSide createBorderSide(BuildContext? context, { Color? color, double? width }) { + final DividerThemeData? dividerTheme = context != null ? DividerTheme.of(context) : null; + final DividerThemeData? defaults = context != null + ? Theme.of(context).useMaterial3 ? _DividerDefaultsM3(context) : _DividerDefaultsM2(context) + : null; + final Color? effectiveColor = color ?? dividerTheme?.color ?? defaults?.color; + final double effectiveWidth = width ?? dividerTheme?.thickness ?? defaults?.thickness ?? 0.0; + + // Prevent assertion since it is possible that context is null and no color + // is specified. + if (effectiveColor == null) { + return BorderSide( + width: effectiveWidth, + ); + } + return BorderSide( + color: effectiveColor, + width: effectiveWidth, + ); + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final DividerThemeData dividerTheme = DividerTheme.of(context); + final DividerThemeData defaults = theme.useMaterial3 ? _DividerDefaultsM3(context) : _DividerDefaultsM2(context); + final double height = this.height ?? dividerTheme.space ?? defaults.space!; + final double thickness = this.thickness ?? dividerTheme.thickness ?? defaults.thickness!; + final double indent = this.indent ?? dividerTheme.indent ?? defaults.indent!; + final double endIndent = this.endIndent ?? dividerTheme.endIndent ?? defaults.endIndent!; + + return SizedBox( + height: height, + child: Center( + child: Container( + height: thickness, + margin: EdgeInsetsDirectional.only(start: indent, end: endIndent), + decoration: BoxDecoration( + border: Border( + bottom: createBorderSide(context, color: color, width: thickness), + ), + ), + ), + ), + ); + } +} + +/// A thin vertical line, with padding on either side. +/// +/// In the Material Design language, this represents a divider. Vertical +/// dividers can be used in horizontally scrolling lists, such as a +/// [ListView] with [ListView.scrollDirection] set to [Axis.horizontal]. +/// +/// The box's total width is controlled by [width]. The appropriate +/// padding is automatically computed from the width. +/// +/// {@tool dartpad} +/// This sample shows how to display a [VerticalDivider] between a purple and orange box +/// inside a [Row]. The [VerticalDivider] is 20 logical pixels in width and contains a +/// horizontally centered black line that is 1 logical pixels thick. The grey +/// line is indented by 20 logical pixels. +/// +/// ** See code in examples/api/lib/material/divider/vertical_divider.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of [VerticalDivider] widget, as described in: +/// https://m3.material.io/components/divider/overview +/// +/// ** See code in examples/api/lib/material/divider/vertical_divider.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListView.separated], which can be used to generate vertical dividers. +/// * [Divider], which is the horizontal analog of this widget. +/// * <https://material.io/design/components/dividers.html> +class VerticalDivider extends StatelessWidget { + /// Creates a Material Design vertical divider. + /// + /// The [width], [thickness], [indent], and [endIndent] must be null or + /// non-negative. + const VerticalDivider({ + super.key, + this.width, + this.thickness, + this.indent, + this.endIndent, + this.color, + }) : assert(width == null || width >= 0.0), + assert(thickness == null || thickness >= 0.0), + assert(indent == null || indent >= 0.0), + assert(endIndent == null || endIndent >= 0.0); + + /// The divider's width. + /// + /// The divider itself is always drawn as a vertical line that is centered + /// within the width specified by this value. + /// + /// If this is null, then the [DividerThemeData.space] is used. If that is + /// also null, then this defaults to 16.0. + final double? width; + + /// The thickness of the line drawn within the divider. + /// + /// A divider with a [thickness] of 0.0 is always drawn as a line with a + /// width of exactly one device pixel. + /// + /// If this is null, then the [DividerThemeData.thickness] is used which + /// defaults to 0.0. + final double? thickness; + + /// The amount of empty space on top of the divider. + /// + /// If this is null, then the [DividerThemeData.indent] is used. If that is + /// also null, then this defaults to 0.0. + final double? indent; + + /// The amount of empty space under the divider. + /// + /// If this is null, then the [DividerThemeData.endIndent] is used. If that is + /// also null, then this defaults to 0.0. + final double? endIndent; + + /// The color to use when painting the line. + /// + /// If this is null, then the [DividerThemeData.color] is used. If that is + /// also null, then [ThemeData.dividerColor] is used. + /// + /// {@tool snippet} + /// + /// ```dart + /// const Divider( + /// color: Colors.deepOrange, + /// ) + /// ``` + /// {@end-tool} + final Color? color; + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final DividerThemeData dividerTheme = DividerTheme.of(context); + final DividerThemeData defaults = theme.useMaterial3 ? _DividerDefaultsM3(context) : _DividerDefaultsM2(context); + final double width = this.width ?? dividerTheme.space ?? defaults.space!; + final double thickness = this.thickness ?? dividerTheme.thickness ?? defaults.thickness!; + final double indent = this.indent ?? dividerTheme.indent ?? defaults.indent!; + final double endIndent = this.endIndent ?? dividerTheme.endIndent ?? defaults.endIndent!; + + return SizedBox( + width: width, + child: Center( + child: Container( + width: thickness, + margin: EdgeInsetsDirectional.only(top: indent, bottom: endIndent), + decoration: BoxDecoration( + border: Border( + left: Divider.createBorderSide(context, color: color, width: thickness), + ), + ), + ), + ), + ); + } +} + +class _DividerDefaultsM2 extends DividerThemeData { + const _DividerDefaultsM2(this.context) : super( + space: 16, + thickness: 0, + indent: 0, + endIndent: 0, + ); + + final BuildContext context; + + @override Color? get color => Theme.of(context).dividerColor; +} + +// BEGIN GENERATED TOKEN PROPERTIES - Divider + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _DividerDefaultsM3 extends DividerThemeData { + const _DividerDefaultsM3(this.context) : super( + space: 16, + thickness: 1.0, + indent: 0, + endIndent: 0, + ); + + final BuildContext context; + + @override Color? get color => Theme.of(context).colorScheme.outlineVariant; +} + +// END GENERATED TOKEN PROPERTIES - Divider diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/divider_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/divider_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..b9f0a52fccd6546de8cbeddf7d55bd90bde1bf84 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/divider_theme.dart @@ -0,0 +1,176 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines the visual properties of [Divider], [VerticalDivider], dividers +/// between [ListTile]s, and dividers between rows in [DataTable]s. +/// +/// Descendant widgets obtain the current [DividerThemeData] object using +/// `DividerTheme.of(context)`. Instances of [DividerThemeData] +/// can be customized with [DividerThemeData.copyWith]. +/// +/// Typically a [DividerThemeData] is specified as part of the overall +/// [Theme] with [ThemeData.dividerTheme]. +/// +/// All [DividerThemeData] properties are `null` by default. When null, +/// the widgets will provide their own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class DividerThemeData with Diagnosticable { + + /// Creates a theme that can be used for [DividerTheme] or + /// [ThemeData.dividerTheme]. + const DividerThemeData({ + this.color, + this.space, + this.thickness, + this.indent, + this.endIndent, + }); + + /// The color of [Divider]s and [VerticalDivider]s, also + /// used between [ListTile]s, between rows in [DataTable]s, and so forth. + final Color? color; + + /// The [Divider]'s height or the [VerticalDivider]'s width. + /// + /// This represents the amount of horizontal or vertical space the divider + /// takes up. + final double? space; + + /// The thickness of the line drawn within the divider. + final double? thickness; + + /// The amount of empty space at the leading edge of [Divider] or top edge of + /// [VerticalDivider]. + final double? indent; + + /// The amount of empty space at the trailing edge of [Divider] or bottom edge + /// of [VerticalDivider]. + final double? endIndent; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + DividerThemeData copyWith({ + Color? color, + double? space, + double? thickness, + double? indent, + double? endIndent, + }) { + return DividerThemeData( + color: color ?? this.color, + space: space ?? this.space, + thickness: thickness ?? this.thickness, + indent: indent ?? this.indent, + endIndent: endIndent ?? this.endIndent, + ); + } + + /// Linearly interpolate between two Divider themes. + /// + /// {@macro dart.ui.shadow.lerp} + static DividerThemeData lerp(DividerThemeData? a, DividerThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return DividerThemeData( + color: Color.lerp(a?.color, b?.color, t), + space: lerpDouble(a?.space, b?.space, t), + thickness: lerpDouble(a?.thickness, b?.thickness, t), + indent: lerpDouble(a?.indent, b?.indent, t), + endIndent: lerpDouble(a?.endIndent, b?.endIndent, t), + ); + } + + @override + int get hashCode => Object.hash( + color, + space, + thickness, + indent, + endIndent, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is DividerThemeData + && other.color == color + && other.space == space + && other.thickness == thickness + && other.indent == indent + && other.endIndent == endIndent; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(DoubleProperty('space', space, defaultValue: null)); + properties.add(DoubleProperty('thickness', thickness, defaultValue: null)); + properties.add(DoubleProperty('indent', indent, defaultValue: null)); + properties.add(DoubleProperty('endIndent', endIndent, defaultValue: null)); + } +} + +/// An inherited widget that defines the configuration for +/// [Divider]s, [VerticalDivider]s, dividers between [ListTile]s, and dividers +/// between rows in [DataTable]s in this widget's subtree. +class DividerTheme extends InheritedTheme { + /// Creates a divider theme that controls the configurations for + /// [Divider]s, [VerticalDivider]s, dividers between [ListTile]s, and dividers + /// between rows in [DataTable]s in its widget subtree. + const DividerTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties for descendant [Divider]s, [VerticalDivider]s, dividers + /// between [ListTile]s, and dividers between rows in [DataTable]s. + final DividerThemeData data; + + /// The closest instance of this class's [data] value that encloses the given + /// context. + /// + /// If there is no ancestor, it returns [ThemeData.dividerTheme]. Applications + /// can assume that the returned value will not be null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// DividerThemeData theme = DividerTheme.of(context); + /// ``` + static DividerThemeData of(BuildContext context) { + final DividerTheme? dividerTheme = context.dependOnInheritedWidgetOfExactType<DividerTheme>(); + return dividerTheme?.data ?? Theme.of(context).dividerTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return DividerTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(DividerTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/drawer.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/drawer.dart new file mode 100644 index 0000000000000000000000000000000000000000..abb67e32858a5c9591008a439e833bb790f0e451 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/drawer.dart @@ -0,0 +1,841 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/gestures.dart' show DragStartBehavior; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'debug.dart'; +import 'drawer_theme.dart'; +import 'list_tile.dart'; +import 'list_tile_theme.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// The possible alignments of a [Drawer]. +enum DrawerAlignment { + /// Denotes that the [Drawer] is at the start side of the [Scaffold]. + /// + /// This corresponds to the left side when the text direction is left-to-right + /// and the right side when the text direction is right-to-left. + start, + + /// Denotes that the [Drawer] is at the end side of the [Scaffold]. + /// + /// This corresponds to the right side when the text direction is left-to-right + /// and the left side when the text direction is right-to-left. + end, +} + +// TODO(eseidel): Draw width should vary based on device size: +// https://material.io/design/components/navigation-drawer.html#specs + +// Mobile: +// Width = Screen width − 56 dp +// Maximum width: 320dp +// Maximum width applies only when using a left nav. When using a right nav, +// the panel can cover the full width of the screen. + +// Desktop/Tablet: +// Maximum width for a left nav is 400dp. +// The right nav can vary depending on content. + +const double _kWidth = 304.0; +const double _kEdgeDragWidth = 20.0; +const double _kMinFlingVelocity = 365.0; +const Duration _kBaseSettleDuration = Duration(milliseconds: 246); + +/// A Material Design panel that slides in horizontally from the edge of a +/// [Scaffold] to show navigation links in an application. +/// +/// There is a Material 3 version of this component, [NavigationDrawer], +/// that's preferred for applications that are configured for Material 3 +/// (see [ThemeData.useMaterial3]). +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=WRj86iHihgY} +/// +/// Drawers are typically used with the [Scaffold.drawer] property. The child of +/// the drawer is usually a [ListView] whose first child is a [DrawerHeader] +/// that displays status information about the current user. The remaining +/// drawer children are often constructed with [ListTile]s, often concluding +/// with an [AboutListTile]. +/// +/// The [AppBar] automatically displays an appropriate [IconButton] to show the +/// [Drawer] when a [Drawer] is available in the [Scaffold]. The [Scaffold] +/// automatically handles the edge-swipe gesture to show the drawer. +/// +/// {@animation 350 622 https://flutter.github.io/assets-for-api-docs/assets/material/drawer.mp4} +/// +/// ## Updating to [NavigationDrawer] +/// +/// There is a Material 3 version of this component, [NavigationDrawer], +/// that's preferred for applications that are configured for Material 3 +/// (see [ThemeData.useMaterial3]). The [NavigationDrawer] widget's visual +/// are a little bit different, see the Material 3 spec at +/// <https://m3.material.io/components/navigation-drawer/overview> for +/// more details. While the [Drawer] widget can have only one child, the +/// [NavigationDrawer] widget can have a list of widgets, which typically contains +/// [NavigationDrawerDestination] widgets and/or customized widgets like headlines +/// and dividers. +/// +/// {@tool dartpad} +/// This example shows how to create a [Scaffold] that contains an [AppBar] and +/// a [Drawer]. A user taps the "menu" icon in the [AppBar] to open the +/// [Drawer]. The [Drawer] displays four items: A header and three menu items. +/// The [Drawer] displays the four items using a [ListView], which allows the +/// user to scroll through the items if need be. +/// +/// ** See code in examples/api/lib/material/drawer/drawer.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to migrate the above [Drawer] to a [NavigationDrawer]. +/// +/// ** See code in examples/api/lib/material/navigation_drawer/navigation_drawer.0.dart ** +/// {@end-tool} +/// +/// An open drawer may be closed with a swipe to close gesture, pressing the +/// escape key, by tapping the scrim, or by calling pop route function such as +/// [Navigator.pop]. For example a drawer item might close the drawer when tapped: +/// +/// ```dart +/// ListTile( +/// leading: const Icon(Icons.change_history), +/// title: const Text('Change history'), +/// onTap: () { +/// // change app state... +/// Navigator.pop(context); // close the drawer +/// }, +/// ); +/// ``` +/// +/// See also: +/// +/// * [Scaffold.drawer], where one specifies a [Drawer] so that it can be +/// shown. +/// * [Scaffold.of], to obtain the current [ScaffoldState], which manages the +/// display and animation of the drawer. +/// * [ScaffoldState.openDrawer], which displays its [Drawer], if any. +/// * <https://material.io/design/components/navigation-drawer.html> +class Drawer extends StatelessWidget { + /// Creates a Material Design drawer. + /// + /// Typically used in the [Scaffold.drawer] property. + /// + /// The [elevation] must be non-negative. + const Drawer({ + super.key, + this.backgroundColor, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.shape, + this.width, + this.child, + this.semanticLabel, + this.clipBehavior, + }) : assert(elevation == null || elevation >= 0.0); + + /// Sets the color of the [Material] that holds all of the [Drawer]'s + /// contents. + /// + /// If this is null, then [DrawerThemeData.backgroundColor] is used. If that + /// is also null, then it falls back to [Material]'s default. + final Color? backgroundColor; + + /// The z-coordinate at which to place this drawer relative to its parent. + /// + /// This controls the size of the shadow below the drawer. + /// + /// If this is null, then [DrawerThemeData.elevation] is used. If that + /// is also null, then it defaults to 16.0. + final double? elevation; + + /// The color used to paint a drop shadow under the drawer's [Material], + /// which reflects the drawer's [elevation]. + /// + /// If null and [ThemeData.useMaterial3] is true then no drop shadow will + /// be rendered. + /// + /// If null and [ThemeData.useMaterial3] is false then it will default to + /// [ThemeData.shadowColor]. + /// + /// See also: + /// * [Material.shadowColor], which describes how the drop shadow is painted. + /// * [elevation], which affects how the drop shadow is painted. + /// * [surfaceTintColor], which can be used to indicate elevation through + /// tinting the background color. + final Color? shadowColor; + + /// The color used as a surface tint overlay on the drawer's background color, + /// which reflects the drawer's [elevation]. + /// + /// If [ThemeData.useMaterial3] is false property has no effect. + /// + /// If null and [ThemeData.useMaterial3] is true then [ThemeData]'s + /// [ColorScheme.surfaceTint] will be used. + /// + /// To disable this feature, set [surfaceTintColor] to [Colors.transparent]. + /// + /// See also: + /// * [Material.surfaceTintColor], which describes how the surface tint will + /// be applied to the background color of the drawer. + /// * [elevation], which affects the opacity of the surface tint. + /// * [shadowColor], which can be used to indicate elevation through + /// a drop shadow. + final Color? surfaceTintColor; + + /// The shape of the drawer. + /// + /// Defines the drawer's [Material.shape]. + /// + /// If this is null, then [DrawerThemeData.shape] is used. If that + /// is also null, then it falls back to [Material]'s default. + final ShapeBorder? shape; + + /// The width of the drawer. + /// + /// If this is null, then [DrawerThemeData.width] is used. If that is also + /// null, then it falls back to the Material spec's default (304.0). + final double? width; + + /// The widget below this widget in the tree. + /// + /// Typically a [SliverList]. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The semantic label of the drawer used by accessibility frameworks to + /// announce screen transitions when the drawer is opened and closed. + /// + /// If this label is not provided, it will default to + /// [MaterialLocalizations.drawerLabel]. + /// + /// See also: + /// + /// * [SemanticsConfiguration.namesRoute], for a description of how this + /// value is used. + final String? semanticLabel; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// The [clipBehavior] argument specifies how to clip the drawer's [shape]. + /// + /// If the drawer has a [shape], it defaults to [Clip.hardEdge]. Otherwise, + /// defaults to [Clip.none]. + final Clip? clipBehavior; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + final DrawerThemeData drawerTheme = DrawerTheme.of(context); + String? label = semanticLabel; + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + break; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + label = semanticLabel ?? MaterialLocalizations.of(context).drawerLabel; + } + final bool useMaterial3 = Theme.of(context).useMaterial3; + final bool isDrawerStart = DrawerController.maybeOf(context)?.alignment != DrawerAlignment.end; + final DrawerThemeData defaults= useMaterial3 ? _DrawerDefaultsM3(context): _DrawerDefaultsM2(context); + final ShapeBorder? effectiveShape = shape ?? (isDrawerStart + ? (drawerTheme.shape ?? defaults.shape) + : (drawerTheme.endShape ?? defaults.endShape)); + return Semantics( + scopesRoute: true, + namesRoute: true, + explicitChildNodes: true, + label: label, + child: ConstrainedBox( + constraints: BoxConstraints.expand(width: width ?? drawerTheme.width ?? _kWidth), + child: Material( + color: backgroundColor ?? drawerTheme.backgroundColor ?? defaults.backgroundColor, + elevation: elevation ?? drawerTheme.elevation ?? defaults.elevation!, + shadowColor: shadowColor ?? drawerTheme.shadowColor ?? defaults.shadowColor, + surfaceTintColor: surfaceTintColor ?? drawerTheme.surfaceTintColor ?? defaults.surfaceTintColor, + shape: effectiveShape, + clipBehavior: effectiveShape != null ? (clipBehavior ?? Clip.hardEdge) : Clip.none, + child: child, + ), + ), + ); + } +} + +/// Signature for the callback that's called when a [DrawerController] is +/// opened or closed. +typedef DrawerCallback = void Function(bool isOpened); + +class _DrawerControllerScope extends InheritedWidget { + const _DrawerControllerScope({ + required this.controller, + required super.child, + }); + + final DrawerController controller; + + @override + bool updateShouldNotify(_DrawerControllerScope old) { + return controller != old.controller; + } +} + +/// Provides interactive behavior for [Drawer] widgets. +/// +/// Rarely used directly. Drawer controllers are typically created automatically +/// by [Scaffold] widgets. +/// +/// The drawer controller provides the ability to open and close a drawer, either +/// via an animation or via user interaction. When closed, the drawer collapses +/// to a translucent gesture detector that can be used to listen for edge +/// swipes. +/// +/// See also: +/// +/// * [Drawer], a container with the default width of a drawer. +/// * [Scaffold.drawer], the [Scaffold] slot for showing a drawer. +class DrawerController extends StatefulWidget { + /// Creates a controller for a [Drawer]. + /// + /// Rarely used directly. + /// + /// The [child] argument is typically a [Drawer]. + const DrawerController({ + GlobalKey? key, + required this.child, + required this.alignment, + this.isDrawerOpen = false, + this.drawerCallback, + this.dragStartBehavior = DragStartBehavior.start, + this.scrimColor, + this.edgeDragWidth, + this.enableOpenDragGesture = true, + }) : super(key: key); + + /// The widget below this widget in the tree. + /// + /// Typically a [Drawer]. + final Widget child; + + /// The alignment of the [Drawer]. + /// + /// This controls the direction in which the user should swipe to open and + /// close the drawer. + final DrawerAlignment alignment; + + /// Optional callback that is called when a [Drawer] is opened or closed. + final DrawerCallback? drawerCallback; + + /// {@template flutter.material.DrawerController.dragStartBehavior} + /// Determines the way that drag start behavior is handled. + /// + /// If set to [DragStartBehavior.start], the drag behavior used for opening + /// and closing a drawer will begin at the position where the drag gesture won + /// the arena. If set to [DragStartBehavior.down] it will begin at the position + /// where a down event is first detected. + /// + /// In general, setting this to [DragStartBehavior.start] will make drag + /// animation smoother and setting it to [DragStartBehavior.down] will make + /// drag behavior feel slightly more reactive. + /// + /// By default, the drag start behavior is [DragStartBehavior.start]. + /// + /// See also: + /// + /// * [DragGestureRecognizer.dragStartBehavior], which gives an example for + /// the different behaviors. + /// + /// {@endtemplate} + final DragStartBehavior dragStartBehavior; + + /// The color to use for the scrim that obscures the underlying content while + /// a drawer is open. + /// + /// If this is null, then [DrawerThemeData.scrimColor] is used. If that + /// is also null, then it defaults to [Colors.black54]. + final Color? scrimColor; + + /// Determines if the [Drawer] can be opened with a drag gesture. + /// + /// By default, the drag gesture is enabled. + final bool enableOpenDragGesture; + + /// The width of the area within which a horizontal swipe will open the + /// drawer. + /// + /// By default, the value used is 20.0 added to the padding edge of + /// `MediaQuery.paddingOf(context)` that corresponds to [alignment]. + /// This ensures that the drag area for notched devices is not obscured. For + /// example, if [alignment] is set to [DrawerAlignment.start] and + /// `TextDirection.of(context)` is set to [TextDirection.ltr], + /// 20.0 will be added to `MediaQuery.paddingOf(context).left`. + final double? edgeDragWidth; + + /// Whether or not the drawer is opened or closed. + /// + /// This parameter is primarily used by the state restoration framework + /// to restore the drawer's animation controller to the open or closed state + /// depending on what was last saved to the target platform before the + /// application was killed. + final bool isDrawerOpen; + + /// The closest instance of [DrawerController] that encloses the given + /// context, or null if none is found. + /// + /// {@tool snippet} Typical usage is as follows: + /// + /// ```dart + /// DrawerController? controller = DrawerController.maybeOf(context); + /// ``` + /// {@end-tool} + /// + /// Calling this method will create a dependency on the closest + /// [DrawerController] in the [context], if there is one. + /// + /// See also: + /// + /// * [DrawerController.of], which is similar to this method, but asserts + /// if no [DrawerController] ancestor is found. + static DrawerController? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<_DrawerControllerScope>()?.controller; + } + + /// The closest instance of [DrawerController] that encloses the given + /// context. + /// + /// If no instance is found, this method will assert in debug mode and throw + /// an exception in release mode. + /// + /// Calling this method will create a dependency on the closest + /// [DrawerController] in the [context]. + /// + /// {@tool snippet} Typical usage is as follows: + /// + /// ```dart + /// DrawerController controller = DrawerController.of(context); + /// ``` + /// {@end-tool} + static DrawerController of(BuildContext context) { + final DrawerController? controller = maybeOf(context); + assert(() { + if (controller == null) { + throw FlutterError( + 'DrawerController.of() was called with a context that does not ' + 'contain a DrawerController widget.\n' + 'No DrawerController widget ancestor could be found starting from ' + 'the context that was passed to DrawerController.of(). This can ' + 'happen because you are using a widget that looks for a DrawerController ' + 'ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return controller!; + } + + @override + DrawerControllerState createState() => DrawerControllerState(); +} + +/// State for a [DrawerController]. +/// +/// Typically used by a [Scaffold] to [open] and [close] the drawer. +class DrawerControllerState extends State<DrawerController> with SingleTickerProviderStateMixin { + @override + void initState() { + super.initState(); + _controller = AnimationController( + value: widget.isDrawerOpen ? 1.0 : 0.0, + duration: _kBaseSettleDuration, + vsync: this, + ); + _controller + ..addListener(_animationChanged) + ..addStatusListener(_animationStatusChanged); + } + + @override + void dispose() { + _historyEntry?.remove(); + _controller.dispose(); + _focusScopeNode.dispose(); + super.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _scrimColorTween = _buildScrimColorTween(); + } + + @override + void didUpdateWidget(DrawerController oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.scrimColor != oldWidget.scrimColor) { + _scrimColorTween = _buildScrimColorTween(); + } + if (widget.isDrawerOpen != oldWidget.isDrawerOpen) { + switch (_controller.status) { + case AnimationStatus.completed: + case AnimationStatus.dismissed: + _controller.value = widget.isDrawerOpen ? 1.0 : 0.0; + case AnimationStatus.forward: + case AnimationStatus.reverse: + break; + } + } + } + + void _animationChanged() { + setState(() { + // The animation controller's state is our build state, and it changed already. + }); + } + + LocalHistoryEntry? _historyEntry; + final FocusScopeNode _focusScopeNode = FocusScopeNode(); + + void _ensureHistoryEntry() { + if (_historyEntry == null) { + final ModalRoute<dynamic>? route = ModalRoute.of(context); + if (route != null) { + _historyEntry = LocalHistoryEntry(onRemove: _handleHistoryEntryRemoved, impliesAppBarDismissal: false); + route.addLocalHistoryEntry(_historyEntry!); + FocusScope.of(context).setFirstFocus(_focusScopeNode); + } + } + } + + void _animationStatusChanged(AnimationStatus status) { + switch (status) { + case AnimationStatus.forward: + _ensureHistoryEntry(); + case AnimationStatus.reverse: + _historyEntry?.remove(); + _historyEntry = null; + case AnimationStatus.dismissed: + break; + case AnimationStatus.completed: + break; + } + } + + void _handleHistoryEntryRemoved() { + _historyEntry = null; + close(); + } + + late AnimationController _controller; + + void _handleDragDown(DragDownDetails details) { + _controller.stop(); + _ensureHistoryEntry(); + } + + void _handleDragCancel() { + if (_controller.isDismissed || _controller.isAnimating) { + return; + } + if (_controller.value < 0.5) { + close(); + } else { + open(); + } + } + + final GlobalKey _drawerKey = GlobalKey(); + + double get _width { + final RenderBox? box = _drawerKey.currentContext?.findRenderObject() as RenderBox?; + if (box != null) { + return box.size.width; + } + return _kWidth; // drawer not being shown currently + } + + bool _previouslyOpened = false; + + void _move(DragUpdateDetails details) { + double delta = details.primaryDelta! / _width; + switch (widget.alignment) { + case DrawerAlignment.start: + break; + case DrawerAlignment.end: + delta = -delta; + } + switch (Directionality.of(context)) { + case TextDirection.rtl: + _controller.value -= delta; + case TextDirection.ltr: + _controller.value += delta; + } + + final bool opened = _controller.value > 0.5; + if (opened != _previouslyOpened && widget.drawerCallback != null) { + widget.drawerCallback!(opened); + } + _previouslyOpened = opened; + } + + void _settle(DragEndDetails details) { + if (_controller.isDismissed) { + return; + } + if (details.velocity.pixelsPerSecond.dx.abs() >= _kMinFlingVelocity) { + double visualVelocity = details.velocity.pixelsPerSecond.dx / _width; + switch (widget.alignment) { + case DrawerAlignment.start: + break; + case DrawerAlignment.end: + visualVelocity = -visualVelocity; + } + switch (Directionality.of(context)) { + case TextDirection.rtl: + _controller.fling(velocity: -visualVelocity); + widget.drawerCallback?.call(visualVelocity < 0.0); + case TextDirection.ltr: + _controller.fling(velocity: visualVelocity); + widget.drawerCallback?.call(visualVelocity > 0.0); + } + } else if (_controller.value < 0.5) { + close(); + } else { + open(); + } + } + + /// Starts an animation to open the drawer. + /// + /// Typically called by [ScaffoldState.openDrawer]. + void open() { + _controller.fling(); + widget.drawerCallback?.call(true); + } + + /// Starts an animation to close the drawer. + void close() { + _controller.fling(velocity: -1.0); + widget.drawerCallback?.call(false); + } + + late ColorTween _scrimColorTween; + final GlobalKey _gestureDetectorKey = GlobalKey(); + + ColorTween _buildScrimColorTween() { + return ColorTween( + begin: Colors.transparent, + end: widget.scrimColor + ?? DrawerTheme.of(context).scrimColor + ?? Colors.black54, + ); + } + + AlignmentDirectional get _drawerOuterAlignment { + switch (widget.alignment) { + case DrawerAlignment.start: + return AlignmentDirectional.centerStart; + case DrawerAlignment.end: + return AlignmentDirectional.centerEnd; + } + } + + AlignmentDirectional get _drawerInnerAlignment { + switch (widget.alignment) { + case DrawerAlignment.start: + return AlignmentDirectional.centerEnd; + case DrawerAlignment.end: + return AlignmentDirectional.centerStart; + } + } + + Widget _buildDrawer(BuildContext context) { + final bool drawerIsStart = widget.alignment == DrawerAlignment.start; + final TextDirection textDirection = Directionality.of(context); + final bool isDesktop; + switch (Theme.of(context).platform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + case TargetPlatform.fuchsia: + isDesktop = false; + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + isDesktop = true; + } + + double? dragAreaWidth = widget.edgeDragWidth; + if (widget.edgeDragWidth == null) { + final EdgeInsets padding = MediaQuery.paddingOf(context); + switch (textDirection) { + case TextDirection.ltr: + dragAreaWidth = _kEdgeDragWidth + + (drawerIsStart ? padding.left : padding.right); + case TextDirection.rtl: + dragAreaWidth = _kEdgeDragWidth + + (drawerIsStart ? padding.right : padding.left); + } + } + + if (_controller.status == AnimationStatus.dismissed) { + if (widget.enableOpenDragGesture && !isDesktop) { + return Align( + alignment: _drawerOuterAlignment, + child: GestureDetector( + key: _gestureDetectorKey, + onHorizontalDragUpdate: _move, + onHorizontalDragEnd: _settle, + behavior: HitTestBehavior.translucent, + excludeFromSemantics: true, + dragStartBehavior: widget.dragStartBehavior, + child: Container(width: dragAreaWidth), + ), + ); + } else { + return const SizedBox.shrink(); + } + } else { + final bool platformHasBackButton; + switch (Theme.of(context).platform) { + case TargetPlatform.android: + platformHasBackButton = true; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + platformHasBackButton = false; + } + + final Widget child = _DrawerControllerScope( + controller: widget, + child: RepaintBoundary( + child: Stack( + children: <Widget>[ + BlockSemantics( + child: ExcludeSemantics( + // On Android, the back button is used to dismiss a modal. + excluding: platformHasBackButton, + child: GestureDetector( + onTap: close, + child: Semantics( + label: MaterialLocalizations.of(context).modalBarrierDismissLabel, + child: Container( // The drawer's "scrim" + color: _scrimColorTween.evaluate(_controller), + ), + ), + ), + ), + ), + Align( + alignment: _drawerOuterAlignment, + child: Align( + alignment: _drawerInnerAlignment, + widthFactor: _controller.value, + child: RepaintBoundary( + child: FocusScope( + key: _drawerKey, + node: _focusScopeNode, + child: widget.child, + ), + ), + ), + ), + ], + ), + ), + ); + + if (isDesktop) { + return child; + } + + return GestureDetector( + key: _gestureDetectorKey, + onHorizontalDragDown: _handleDragDown, + onHorizontalDragUpdate: _move, + onHorizontalDragEnd: _settle, + onHorizontalDragCancel: _handleDragCancel, + excludeFromSemantics: true, + dragStartBehavior: widget.dragStartBehavior, + child: child, + ); + } + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + return ListTileTheme.merge( + style: ListTileStyle.drawer, + child: _buildDrawer(context), + ); + } +} + +class _DrawerDefaultsM2 extends DrawerThemeData { + const _DrawerDefaultsM2(this.context) + : super(elevation: 16.0); + + final BuildContext context; + + @override + Color? get shadowColor => Theme.of(context).shadowColor; + +} + +// BEGIN GENERATED TOKEN PROPERTIES - Drawer + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _DrawerDefaultsM3 extends DrawerThemeData { + _DrawerDefaultsM3(this.context) + : super(elevation: 1.0); + + final BuildContext context; + late final TextDirection direction = Directionality.of(context); + + @override + Color? get backgroundColor => Theme.of(context).colorScheme.surface; + + @override + Color? get surfaceTintColor => Theme.of(context).colorScheme.surfaceTint; + + @override + Color? get shadowColor => Colors.transparent; + + // There isn't currently a token for this value, but it is shown in the spec, + // so hard coding here for now. + @override + ShapeBorder? get shape => RoundedRectangleBorder( + borderRadius: const BorderRadiusDirectional.horizontal( + end: Radius.circular(16.0), + ).resolve(direction), + ); + + // There isn't currently a token for this value, but it is shown in the spec, + // so hard coding here for now. + @override + ShapeBorder? get endShape => RoundedRectangleBorder( + borderRadius: const BorderRadiusDirectional.horizontal( + start: Radius.circular(16.0), + ).resolve(direction), + ); +} + +// END GENERATED TOKEN PROPERTIES - Drawer diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/drawer_header.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/drawer_header.dart new file mode 100644 index 0000000000000000000000000000000000000000..3b579d1f5bcd521428bddbd523629d85ebd4c355 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/drawer_header.dart @@ -0,0 +1,104 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'debug.dart'; +import 'divider.dart'; +import 'theme.dart'; + +const double _kDrawerHeaderHeight = 160.0 + 1.0; // bottom edge + +/// The top-most region of a Material Design drawer. The header's [child] +/// widget, if any, is placed inside a [Container] whose [decoration] can be +/// passed as an argument, inset by the given [padding]. +/// +/// Part of the Material Design [Drawer]. +/// +/// Requires one of its ancestors to be a [Material] widget. This condition is +/// satisfied by putting the [DrawerHeader] in a [Drawer]. +/// +/// See also: +/// +/// * [UserAccountsDrawerHeader], a variant of [DrawerHeader] that is +/// specialized for showing user accounts. +/// * <https://material.io/design/components/navigation-drawer.html> +class DrawerHeader extends StatelessWidget { + /// Creates a Material Design drawer header. + /// + /// Requires one of its ancestors to be a [Material] widget. + const DrawerHeader({ + super.key, + this.decoration, + this.margin = const EdgeInsets.only(bottom: 8.0), + this.padding = const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 8.0), + this.duration = const Duration(milliseconds: 250), + this.curve = Curves.fastOutSlowIn, + required this.child, + }); + + /// Decoration for the main drawer header [Container]; useful for applying + /// backgrounds. + /// + /// This decoration will extend under the system status bar. + /// + /// If this is changed, it will be animated according to [duration] and [curve]. + final Decoration? decoration; + + /// The padding by which to inset [child]. + /// + /// The [DrawerHeader] additionally offsets the child by the height of the + /// system status bar. + /// + /// If the child is null, the padding has no effect. + final EdgeInsetsGeometry padding; + + /// The margin around the drawer header. + final EdgeInsetsGeometry? margin; + + /// The duration for animations of the [decoration]. + final Duration duration; + + /// The curve for animations of the [decoration]. + final Curve curve; + + /// A widget to be placed inside the drawer header, inset by the [padding]. + /// + /// This widget will be sized to the size of the header. To position the child + /// precisely, consider using an [Align] or [Center] widget. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMediaQuery(context)); + final ThemeData theme = Theme.of(context); + final double statusBarHeight = MediaQuery.paddingOf(context).top; + return Container( + height: statusBarHeight + _kDrawerHeaderHeight, + margin: margin, + decoration: BoxDecoration( + border: Border( + bottom: Divider.createBorderSide(context), + ), + ), + child: AnimatedContainer( + padding: padding.add(EdgeInsets.only(top: statusBarHeight)), + decoration: decoration, + duration: duration, + curve: curve, + child: child == null ? null : DefaultTextStyle( + style: theme.textTheme.bodyLarge!, + child: MediaQuery.removePadding( + context: context, + removeTop: true, + child: child!, + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/drawer_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/drawer_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..094152c3384a38ac552ae2760a6cac3ffc962bc2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/drawer_theme.dart @@ -0,0 +1,204 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [Drawer] widgets. +/// +/// Descendant widgets obtain the current [DrawerThemeData] object +/// using `DrawerTheme.of(context)`. Instances of [DrawerThemeData] can be +/// customized with [DrawerThemeData.copyWith]. +/// +/// Typically a [DrawerThemeData] is specified as part of the +/// overall [Theme] with [ThemeData.drawerTheme]. +/// +/// All [DrawerThemeData] properties are `null` by default. +/// +/// See also: +/// +/// * [DrawerTheme], an [InheritedWidget] that propagates the theme down its +/// subtree. +/// * [ThemeData], which describes the overall theme information for the +/// application and can customize a drawer using [ThemeData.drawerTheme]. +@immutable +class DrawerThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.drawerTheme] and + /// [DrawerTheme]. + const DrawerThemeData({ + this.backgroundColor, + this.scrimColor, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.shape, + this.endShape, + this.width, + }); + + /// Overrides the default value of [Drawer.backgroundColor]. + final Color? backgroundColor; + + /// Overrides the default value of [DrawerController.scrimColor]. + final Color? scrimColor; + + /// Overrides the default value of [Drawer.elevation]. + final double? elevation; + + /// Overrides the default value for [Drawer.shadowColor]. + final Color? shadowColor; + + /// Overrides the default value for [Drawer.surfaceTintColor]. + final Color? surfaceTintColor; + + /// Overrides the default value of [Drawer.shape]. + final ShapeBorder? shape; + + /// Overrides the default value of [Drawer.shape] for a end drawer. + final ShapeBorder? endShape; + + /// Overrides the default value of [Drawer.width]. + final double? width; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + DrawerThemeData copyWith({ + Color? backgroundColor, + Color? scrimColor, + double? elevation, + Color? shadowColor, + Color? surfaceTintColor, + ShapeBorder? shape, + ShapeBorder? endShape, + double? width, + }) { + return DrawerThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + scrimColor: scrimColor ?? this.scrimColor, + elevation: elevation ?? this.elevation, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + shape: shape ?? this.shape, + endShape: endShape ?? this.endShape, + width: width ?? this.width, + ); + } + + /// Linearly interpolate between two drawer themes. + /// + /// If both arguments are null then null is returned. + /// + /// {@macro dart.ui.shadow.lerp} + static DrawerThemeData? lerp(DrawerThemeData? a, DrawerThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return DrawerThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + scrimColor: Color.lerp(a?.scrimColor, b?.scrimColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + endShape: ShapeBorder.lerp(a?.endShape, b?.endShape, t), + width: lerpDouble(a?.width, b?.width, t), + ); + } + + @override + int get hashCode => Object.hash( + backgroundColor, + scrimColor, + elevation, + shadowColor, + surfaceTintColor, + shape, + endShape, + width, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is DrawerThemeData + && other.backgroundColor == backgroundColor + && other.scrimColor == scrimColor + && other.elevation == elevation + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.shape == shape + && other.endShape == endShape + && other.width == width; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(ColorProperty('scrimColor', scrimColor, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('endShape', endShape, defaultValue: null)); + properties.add(DoubleProperty('width', width, defaultValue: null)); + } +} + +/// An inherited widget that defines visual properties for [Drawer]s in this +/// widget's subtree. +/// +/// Values specified here are used for [Drawer] properties that are not +/// given an explicit non-null value. +/// +/// Using this would allow you to override the [ThemeData.drawerTheme]. +class DrawerTheme extends InheritedTheme { + /// Creates a theme that defines the [DrawerThemeData] properties for a + /// [Drawer]. + const DrawerTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the background color, scrim color, elevation, and shape for + /// descendant [Drawer] widgets. + final DrawerThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [DrawerTheme] widget, then + /// [ThemeData.drawerTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// DrawerThemeData theme = DrawerTheme.of(context); + /// ``` + static DrawerThemeData of(BuildContext context) { + final DrawerTheme? drawerTheme = context.dependOnInheritedWidgetOfExactType<DrawerTheme>(); + return drawerTheme?.data ?? Theme.of(context).drawerTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return DrawerTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(DrawerTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dropdown.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dropdown.dart new file mode 100644 index 0000000000000000000000000000000000000000..9bfa116e73594554693c36ffebf29bb853479765 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dropdown.dart @@ -0,0 +1,1760 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_theme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'input_border.dart'; +import 'input_decorator.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'scrollbar.dart'; +import 'shadows.dart'; +import 'theme.dart'; + +const Duration _kDropdownMenuDuration = Duration(milliseconds: 300); +const double _kMenuItemHeight = kMinInteractiveDimension; +const double _kDenseButtonHeight = 24.0; +const EdgeInsets _kMenuItemPadding = EdgeInsets.symmetric(horizontal: 16.0); +const EdgeInsetsGeometry _kAlignedButtonPadding = EdgeInsetsDirectional.only(start: 16.0, end: 4.0); +const EdgeInsets _kUnalignedButtonPadding = EdgeInsets.zero; +const EdgeInsets _kAlignedMenuMargin = EdgeInsets.zero; +const EdgeInsetsGeometry _kUnalignedMenuMargin = EdgeInsetsDirectional.only(start: 16.0, end: 24.0); + +/// A builder to customize dropdown buttons. +/// +/// Used by [DropdownButton.selectedItemBuilder]. +typedef DropdownButtonBuilder = List<Widget> Function(BuildContext context); + +class _DropdownMenuPainter extends CustomPainter { + _DropdownMenuPainter({ + this.color, + this.elevation, + this.selectedIndex, + this.borderRadius, + required this.resize, + required this.getSelectedItemOffset, + }) : _painter = BoxDecoration( + // If you add an image here, you must provide a real + // configuration in the paint() function and you must provide some sort + // of onChanged callback here. + color: color, + borderRadius: borderRadius ?? const BorderRadius.all(Radius.circular(2.0)), + boxShadow: kElevationToShadow[elevation], + ).createBoxPainter(), + super(repaint: resize); + + final Color? color; + final int? elevation; + final int? selectedIndex; + final BorderRadius? borderRadius; + final Animation<double> resize; + final ValueGetter<double> getSelectedItemOffset; + final BoxPainter _painter; + + @override + void paint(Canvas canvas, Size size) { + final double selectedItemOffset = getSelectedItemOffset(); + final Tween<double> top = Tween<double>( + begin: clampDouble(selectedItemOffset, 0.0, math.max(size.height - _kMenuItemHeight, 0.0)), + end: 0.0, + ); + + final Tween<double> bottom = Tween<double>( + begin: clampDouble(top.begin! + _kMenuItemHeight, math.min(_kMenuItemHeight, size.height), size.height), + end: size.height, + ); + + final Rect rect = Rect.fromLTRB(0.0, top.evaluate(resize), size.width, bottom.evaluate(resize)); + + _painter.paint(canvas, rect.topLeft, ImageConfiguration(size: rect.size)); + } + + @override + bool shouldRepaint(_DropdownMenuPainter oldPainter) { + return oldPainter.color != color + || oldPainter.elevation != elevation + || oldPainter.selectedIndex != selectedIndex + || oldPainter.borderRadius != borderRadius + || oldPainter.resize != resize; + } +} + +// The widget that is the button wrapping the menu items. +class _DropdownMenuItemButton<T> extends StatefulWidget { + const _DropdownMenuItemButton({ + super.key, + this.padding, + required this.route, + required this.buttonRect, + required this.constraints, + required this.itemIndex, + required this.enableFeedback, + required this.scrollController, + }); + + final _DropdownRoute<T> route; + final ScrollController scrollController; + final EdgeInsets? padding; + final Rect buttonRect; + final BoxConstraints constraints; + final int itemIndex; + final bool enableFeedback; + + @override + _DropdownMenuItemButtonState<T> createState() => _DropdownMenuItemButtonState<T>(); +} + +class _DropdownMenuItemButtonState<T> extends State<_DropdownMenuItemButton<T>> { + void _handleFocusChange(bool focused) { + final bool inTraditionalMode; + switch (FocusManager.instance.highlightMode) { + case FocusHighlightMode.touch: + inTraditionalMode = false; + case FocusHighlightMode.traditional: + inTraditionalMode = true; + } + + if (focused && inTraditionalMode) { + final _MenuLimits menuLimits = widget.route.getMenuLimits( + widget.buttonRect, + widget.constraints.maxHeight, + widget.itemIndex, + ); + widget.scrollController.animateTo( + menuLimits.scrollOffset, + curve: Curves.easeInOut, + duration: const Duration(milliseconds: 100), + ); + } + } + + void _handleOnTap() { + final DropdownMenuItem<T> dropdownMenuItem = widget.route.items[widget.itemIndex].item!; + + dropdownMenuItem.onTap?.call(); + + Navigator.pop( + context, + _DropdownRouteResult<T>(dropdownMenuItem.value), + ); + } + + static const Map<ShortcutActivator, Intent> _webShortcuts = <ShortcutActivator, Intent>{ + // On the web, up/down don't change focus, *except* in a <select> + // element, which is what a dropdown emulates. + SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent(TraversalDirection.down), + SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent(TraversalDirection.up), + }; + + @override + Widget build(BuildContext context) { + final DropdownMenuItem<T> dropdownMenuItem = widget.route.items[widget.itemIndex].item!; + final CurvedAnimation opacity; + final double unit = 0.5 / (widget.route.items.length + 1.5); + if (widget.itemIndex == widget.route.selectedIndex) { + opacity = CurvedAnimation(parent: widget.route.animation!, curve: const Threshold(0.0)); + } else { + final double start = clampDouble(0.5 + (widget.itemIndex + 1) * unit, 0.0, 1.0); + final double end = clampDouble(start + 1.5 * unit, 0.0, 1.0); + opacity = CurvedAnimation(parent: widget.route.animation!, curve: Interval(start, end)); + } + Widget child = Container( + padding: widget.padding, + height: widget.route.itemHeight, + child: widget.route.items[widget.itemIndex], + ); + // An [InkWell] is added to the item only if it is enabled + if (dropdownMenuItem.enabled) { + child = InkWell( + autofocus: widget.itemIndex == widget.route.selectedIndex, + enableFeedback: widget.enableFeedback, + onTap: _handleOnTap, + onFocusChange: _handleFocusChange, + child: child, + ); + } + child = FadeTransition(opacity: opacity, child: child); + if (kIsWeb && dropdownMenuItem.enabled) { + child = Shortcuts( + shortcuts: _webShortcuts, + child: child, + ); + } + return child; + } +} + +class _DropdownMenu<T> extends StatefulWidget { + const _DropdownMenu({ + super.key, + this.padding, + required this.route, + required this.buttonRect, + required this.constraints, + this.dropdownColor, + required this.enableFeedback, + this.borderRadius, + required this.scrollController, + }); + + final _DropdownRoute<T> route; + final EdgeInsets? padding; + final Rect buttonRect; + final BoxConstraints constraints; + final Color? dropdownColor; + final bool enableFeedback; + final BorderRadius? borderRadius; + final ScrollController scrollController; + + @override + _DropdownMenuState<T> createState() => _DropdownMenuState<T>(); +} + +class _DropdownMenuState<T> extends State<_DropdownMenu<T>> { + late CurvedAnimation _fadeOpacity; + late CurvedAnimation _resize; + + @override + void initState() { + super.initState(); + // We need to hold these animations as state because of their curve + // direction. When the route's animation reverses, if we were to recreate + // the CurvedAnimation objects in build, we'd lose + // CurvedAnimation._curveDirection. + _fadeOpacity = CurvedAnimation( + parent: widget.route.animation!, + curve: const Interval(0.0, 0.25), + reverseCurve: const Interval(0.75, 1.0), + ); + _resize = CurvedAnimation( + parent: widget.route.animation!, + curve: const Interval(0.25, 0.5), + reverseCurve: const Threshold(0.0), + ); + } + + @override + Widget build(BuildContext context) { + // The menu is shown in three stages (unit timing in brackets): + // [0s - 0.25s] - Fade in a rect-sized menu container with the selected item. + // [0.25s - 0.5s] - Grow the otherwise empty menu container from the center + // until it's big enough for as many items as we're going to show. + // [0.5s - 1.0s] Fade in the remaining visible items from top to bottom. + // + // When the menu is dismissed we just fade the entire thing out + // in the first 0.25s. + assert(debugCheckHasMaterialLocalizations(context)); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final _DropdownRoute<T> route = widget.route; + final List<Widget> children = <Widget>[ + for (int itemIndex = 0; itemIndex < route.items.length; ++itemIndex) + _DropdownMenuItemButton<T>( + route: widget.route, + padding: widget.padding, + buttonRect: widget.buttonRect, + constraints: widget.constraints, + itemIndex: itemIndex, + enableFeedback: widget.enableFeedback, + scrollController: widget.scrollController, + ), + ]; + + return FadeTransition( + opacity: _fadeOpacity, + child: CustomPaint( + painter: _DropdownMenuPainter( + color: widget.dropdownColor ?? Theme.of(context).canvasColor, + elevation: route.elevation, + selectedIndex: route.selectedIndex, + resize: _resize, + borderRadius: widget.borderRadius, + // This offset is passed as a callback, not a value, because it must + // be retrieved at paint time (after layout), not at build time. + getSelectedItemOffset: () => route.getItemOffset(route.selectedIndex), + ), + child: Semantics( + scopesRoute: true, + namesRoute: true, + explicitChildNodes: true, + label: localizations.popupMenuLabel, + child: ClipRRect( + borderRadius: widget.borderRadius ?? BorderRadius.zero, + clipBehavior: widget.borderRadius != null + ? Clip.antiAlias + : Clip.none, + child: Material( + type: MaterialType.transparency, + textStyle: route.style, + child: ScrollConfiguration( + // Dropdown menus should never overscroll or display an overscroll indicator. + // Scrollbars are built-in below. + // Platform must use Theme and ScrollPhysics must be Clamping. + behavior: ScrollConfiguration.of(context).copyWith( + scrollbars: false, + overscroll: false, + physics: const ClampingScrollPhysics(), + platform: Theme.of(context).platform, + ), + child: PrimaryScrollController( + controller: widget.scrollController, + child: Scrollbar( + thumbVisibility: true, + child: ListView( + // Ensure this always inherits the PrimaryScrollController + primary: true, + padding: kMaterialListPadding, + shrinkWrap: true, + children: children, + ), + ), + ), + ), + ), + ), + ), + ), + ); + } +} + +class _DropdownMenuRouteLayout<T> extends SingleChildLayoutDelegate { + _DropdownMenuRouteLayout({ + required this.buttonRect, + required this.route, + required this.textDirection, + }); + + final Rect buttonRect; + final _DropdownRoute<T> route; + final TextDirection? textDirection; + + @override + BoxConstraints getConstraintsForChild(BoxConstraints constraints) { + // The maximum height of a simple menu should be one or more rows less than + // the view height. This ensures a tappable area outside of the simple menu + // with which to dismiss the menu. + // -- https://material.io/design/components/menus.html#usage + double maxHeight = math.max(0.0, constraints.maxHeight - 2 * _kMenuItemHeight); + if (route.menuMaxHeight != null && route.menuMaxHeight! <= maxHeight) { + maxHeight = route.menuMaxHeight!; + } + // The width of a menu should be at most the view width. This ensures that + // the menu does not extend past the left and right edges of the screen. + final double width = math.min(constraints.maxWidth, buttonRect.width); + return BoxConstraints( + minWidth: width, + maxWidth: width, + maxHeight: maxHeight, + ); + } + + @override + Offset getPositionForChild(Size size, Size childSize) { + final _MenuLimits menuLimits = route.getMenuLimits(buttonRect, size.height, route.selectedIndex); + + assert(() { + final Rect container = Offset.zero & size; + if (container.intersect(buttonRect) == buttonRect) { + // If the button was entirely on-screen, then verify + // that the menu is also on-screen. + // If the button was a bit off-screen, then, oh well. + assert(menuLimits.top >= 0.0); + assert(menuLimits.top + menuLimits.height <= size.height); + } + return true; + }()); + assert(textDirection != null); + final double left; + switch (textDirection!) { + case TextDirection.rtl: + left = clampDouble(buttonRect.right, 0.0, size.width) - childSize.width; + case TextDirection.ltr: + left = clampDouble(buttonRect.left, 0.0, size.width - childSize.width); + } + + return Offset(left, menuLimits.top); + } + + @override + bool shouldRelayout(_DropdownMenuRouteLayout<T> oldDelegate) { + return buttonRect != oldDelegate.buttonRect || textDirection != oldDelegate.textDirection; + } +} + +// We box the return value so that the return value can be null. Otherwise, +// canceling the route (which returns null) would get confused with actually +// returning a real null value. +@immutable +class _DropdownRouteResult<T> { + const _DropdownRouteResult(this.result); + + final T? result; + + @override + bool operator ==(Object other) { + return other is _DropdownRouteResult<T> + && other.result == result; + } + + @override + int get hashCode => result.hashCode; +} + +class _MenuLimits { + const _MenuLimits(this.top, this.bottom, this.height, this.scrollOffset); + final double top; + final double bottom; + final double height; + final double scrollOffset; +} + +class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> { + _DropdownRoute({ + required this.items, + required this.padding, + required this.buttonRect, + required this.selectedIndex, + this.elevation = 8, + required this.capturedThemes, + required this.style, + this.barrierLabel, + this.itemHeight, + this.dropdownColor, + this.menuMaxHeight, + required this.enableFeedback, + this.borderRadius, + }) : itemHeights = List<double>.filled(items.length, itemHeight ?? kMinInteractiveDimension); + + final List<_MenuItem<T>> items; + final EdgeInsetsGeometry padding; + final Rect buttonRect; + final int selectedIndex; + final int elevation; + final CapturedThemes capturedThemes; + final TextStyle style; + final double? itemHeight; + final Color? dropdownColor; + final double? menuMaxHeight; + final bool enableFeedback; + final BorderRadius? borderRadius; + + final List<double> itemHeights; + + @override + Duration get transitionDuration => _kDropdownMenuDuration; + + @override + bool get barrierDismissible => true; + + @override + Color? get barrierColor => null; + + @override + final String? barrierLabel; + + @override + Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return _DropdownRoutePage<T>( + route: this, + constraints: constraints, + items: items, + padding: padding, + buttonRect: buttonRect, + selectedIndex: selectedIndex, + elevation: elevation, + capturedThemes: capturedThemes, + style: style, + dropdownColor: dropdownColor, + enableFeedback: enableFeedback, + borderRadius: borderRadius, + ); + }, + ); + } + + void _dismiss() { + if (isActive) { + navigator?.removeRoute(this); + } + } + + double getItemOffset(int index) { + double offset = kMaterialListPadding.top; + if (items.isNotEmpty && index > 0) { + assert(items.length == itemHeights.length); + offset += itemHeights + .sublist(0, index) + .reduce((double total, double height) => total + height); + } + return offset; + } + + // Returns the vertical extent of the menu and the initial scrollOffset + // for the ListView that contains the menu items. The vertical center of the + // selected item is aligned with the button's vertical center, as far as + // that's possible given availableHeight. + _MenuLimits getMenuLimits(Rect buttonRect, double availableHeight, int index) { + double computedMaxHeight = availableHeight - 2.0 * _kMenuItemHeight; + if (menuMaxHeight != null) { + computedMaxHeight = math.min(computedMaxHeight, menuMaxHeight!); + } + final double buttonTop = buttonRect.top; + final double buttonBottom = math.min(buttonRect.bottom, availableHeight); + final double selectedItemOffset = getItemOffset(index); + + // If the button is placed on the bottom or top of the screen, its top or + // bottom may be less than [_kMenuItemHeight] from the edge of the screen. + // In this case, we want to change the menu limits to align with the top + // or bottom edge of the button. + final double topLimit = math.min(_kMenuItemHeight, buttonTop); + final double bottomLimit = math.max(availableHeight - _kMenuItemHeight, buttonBottom); + + double menuTop = (buttonTop - selectedItemOffset) - (itemHeights[selectedIndex] - buttonRect.height) / 2.0; + double preferredMenuHeight = kMaterialListPadding.vertical; + if (items.isNotEmpty) { + preferredMenuHeight += itemHeights.reduce((double total, double height) => total + height); + } + + // If there are too many elements in the menu, we need to shrink it down + // so it is at most the computedMaxHeight. + final double menuHeight = math.min(computedMaxHeight, preferredMenuHeight); + double menuBottom = menuTop + menuHeight; + + // If the computed top or bottom of the menu are outside of the range + // specified, we need to bring them into range. If the item height is larger + // than the button height and the button is at the very bottom or top of the + // screen, the menu will be aligned with the bottom or top of the button + // respectively. + if (menuTop < topLimit) { + menuTop = math.min(buttonTop, topLimit); + menuBottom = menuTop + menuHeight; + } + + if (menuBottom > bottomLimit) { + menuBottom = math.max(buttonBottom, bottomLimit); + menuTop = menuBottom - menuHeight; + } + + if (menuBottom - itemHeights[selectedIndex] / 2.0 < buttonBottom - buttonRect.height / 2.0) { + menuBottom = buttonBottom - buttonRect.height / 2.0 + itemHeights[selectedIndex] / 2.0; + menuTop = menuBottom - menuHeight; + } + + double scrollOffset = 0; + // If all of the menu items will not fit within availableHeight then + // compute the scroll offset that will line the selected menu item up + // with the select item. This is only done when the menu is first + // shown - subsequently we leave the scroll offset where the user left + // it. This scroll offset is only accurate for fixed height menu items + // (the default). + if (preferredMenuHeight > computedMaxHeight) { + // The offset should be zero if the selected item is in view at the beginning + // of the menu. Otherwise, the scroll offset should center the item if possible. + scrollOffset = math.max(0.0, selectedItemOffset - (buttonTop - menuTop)); + // If the selected item's scroll offset is greater than the maximum scroll offset, + // set it instead to the maximum allowed scroll offset. + scrollOffset = math.min(scrollOffset, preferredMenuHeight - menuHeight); + } + + assert((menuBottom - menuTop - menuHeight).abs() < precisionErrorTolerance); + return _MenuLimits(menuTop, menuBottom, menuHeight, scrollOffset); + } +} + +class _DropdownRoutePage<T> extends StatefulWidget { + const _DropdownRoutePage({ + super.key, + required this.route, + required this.constraints, + this.items, + required this.padding, + required this.buttonRect, + required this.selectedIndex, + this.elevation = 8, + required this.capturedThemes, + this.style, + required this.dropdownColor, + required this.enableFeedback, + this.borderRadius, + }); + + final _DropdownRoute<T> route; + final BoxConstraints constraints; + final List<_MenuItem<T>>? items; + final EdgeInsetsGeometry padding; + final Rect buttonRect; + final int selectedIndex; + final int elevation; + final CapturedThemes capturedThemes; + final TextStyle? style; + final Color? dropdownColor; + final bool enableFeedback; + final BorderRadius? borderRadius; + + @override + State<_DropdownRoutePage<T>> createState() => _DropdownRoutePageState<T>(); +} + +class _DropdownRoutePageState<T> extends State<_DropdownRoutePage<T>> { + late ScrollController _scrollController; + + @override + void initState(){ + super.initState(); + + // Computing the initialScrollOffset now, before the items have been laid + // out. This only works if the item heights are effectively fixed, i.e. either + // DropdownButton.itemHeight is specified or DropdownButton.itemHeight is null + // and all of the items' intrinsic heights are less than kMinInteractiveDimension. + // Otherwise the initialScrollOffset is just a rough approximation based on + // treating the items as if their heights were all equal to kMinInteractiveDimension. + final _MenuLimits menuLimits = widget.route.getMenuLimits(widget.buttonRect, widget.constraints.maxHeight, widget.selectedIndex); + _scrollController = ScrollController(initialScrollOffset: menuLimits.scrollOffset); + } + + + @override + Widget build(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + + final TextDirection? textDirection = Directionality.maybeOf(context); + final Widget menu = _DropdownMenu<T>( + route: widget.route, + padding: widget.padding.resolve(textDirection), + buttonRect: widget.buttonRect, + constraints: widget.constraints, + dropdownColor: widget.dropdownColor, + enableFeedback: widget.enableFeedback, + borderRadius: widget.borderRadius, + scrollController: _scrollController, + ); + + return MediaQuery.removePadding( + context: context, + removeTop: true, + removeBottom: true, + removeLeft: true, + removeRight: true, + child: Builder( + builder: (BuildContext context) { + return CustomSingleChildLayout( + delegate: _DropdownMenuRouteLayout<T>( + buttonRect: widget.buttonRect, + route: widget.route, + textDirection: textDirection, + ), + child: widget.capturedThemes.wrap(menu), + ); + }, + ), + ); + } + + @override + void dispose() { + _scrollController.dispose(); + super.dispose(); + } +} + +// This widget enables _DropdownRoute to look up the sizes of +// each menu item. These sizes are used to compute the offset of the selected +// item so that _DropdownRoutePage can align the vertical center of the +// selected item lines up with the vertical center of the dropdown button, +// as closely as possible. +class _MenuItem<T> extends SingleChildRenderObjectWidget { + const _MenuItem({ + super.key, + required this.onLayout, + required this.item, + }) : super(child: item); + + final ValueChanged<Size> onLayout; + final DropdownMenuItem<T>? item; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderMenuItem(onLayout); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderMenuItem renderObject) { + renderObject.onLayout = onLayout; + } +} + +class _RenderMenuItem extends RenderProxyBox { + _RenderMenuItem(this.onLayout, [RenderBox? child]) : super(child); + + ValueChanged<Size> onLayout; + + @override + void performLayout() { + super.performLayout(); + onLayout(size); + } +} + +// The container widget for a menu item created by a [DropdownButton]. It +// provides the default configuration for [DropdownMenuItem]s, as well as a +// [DropdownButton]'s hint and disabledHint widgets. +class _DropdownMenuItemContainer extends StatelessWidget { + /// Creates an item for a dropdown menu. + /// + /// The [child] argument is required. + const _DropdownMenuItemContainer({ + super.key, + this.alignment = AlignmentDirectional.centerStart, + required this.child, + }); + + /// The widget below this widget in the tree. + /// + /// Typically a [Text] widget. + final Widget child; + + /// Defines how the item is positioned within the container. + /// + /// Defaults to [AlignmentDirectional.centerStart]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + @override + Widget build(BuildContext context) { + return Container( + constraints: const BoxConstraints(minHeight: _kMenuItemHeight), + alignment: alignment, + child: child, + ); + } +} + +/// An item in a menu created by a [DropdownButton]. +/// +/// The type `T` is the type of the value the entry represents. All the entries +/// in a given menu must represent values with consistent types. +class DropdownMenuItem<T> extends _DropdownMenuItemContainer { + /// Creates an item for a dropdown menu. + /// + /// The [child] argument is required. + const DropdownMenuItem({ + super.key, + this.onTap, + this.value, + this.enabled = true, + super.alignment, + required super.child, + }); + + /// Called when the dropdown menu item is tapped. + final VoidCallback? onTap; + + /// The value to return if the user selects this menu item. + /// + /// Eventually returned in a call to [DropdownButton.onChanged]. + final T? value; + + /// Whether or not a user can select this menu item. + /// + /// Defaults to `true`. + final bool enabled; +} + +/// An inherited widget that causes any descendant [DropdownButton] +/// widgets to not include their regular underline. +/// +/// This is used by [DataTable] to remove the underline from any +/// [DropdownButton] widgets placed within material data tables, as +/// required by the Material Design specification. +class DropdownButtonHideUnderline extends InheritedWidget { + /// Creates a [DropdownButtonHideUnderline]. A non-null [child] must + /// be given. + const DropdownButtonHideUnderline({ + super.key, + required super.child, + }); + + /// Returns whether the underline of [DropdownButton] widgets should + /// be hidden. + static bool at(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<DropdownButtonHideUnderline>() != null; + } + + @override + bool updateShouldNotify(DropdownButtonHideUnderline oldWidget) => false; +} + +/// A Material Design button for selecting from a list of items. +/// +/// A dropdown button lets the user select from a number of items. The button +/// shows the currently selected item as well as an arrow that opens a menu for +/// selecting another item. +/// +/// ## Updating to [DropdownMenu] +/// +/// There is a Material 3 version of this component, +/// [DropdownMenu] that is preferred for applications that are configured +/// for Material 3 (see [ThemeData.useMaterial3]). +/// The [DropdownMenu] widget's visuals +/// are a little bit different, see the Material 3 spec at +/// <https://m3.material.io/components/menus/guidelines> for +/// more details. +/// +/// The [DropdownMenu] widget's API is also slightly different. +/// To update from [DropdownButton] to [DropdownMenu], you will +/// need to make the following changes: +/// +/// 1. Instead of using [DropdownButton.items], which +/// takes a list of [DropdownMenuItem]s, use +/// [DropdownMenu.dropdownMenuEntries], which +/// takes a list of [DropdownMenuEntry]'s. +/// +/// 2. Instead of using [DropdownButton.onChanged], +/// use [DropdownMenu.onSelected], which is also +/// a callback that is called when the user selects an entry. +/// +/// 3. In [DropdownMenu] it is not required to track +/// the current selection in your app's state. +/// So, instead of tracking the current selection in +/// the [DropdownButton.value] property, you can set the +/// [DropdownMenu.initialSelection] property to the +/// item that should be selected before there is any user action. +/// +/// 4. You may also need to make changes to the styling of the +/// [DropdownMenu], see the properties in the [DropdownMenu] +/// constructor for more details. +/// +/// See the sample below for an example of migrating +/// from [DropdownButton] to [DropdownMenu]. +/// +/// ## Using [DropdownButton] +/// {@youtube 560 315 https://www.youtube.com/watch?v=ZzQ_PWrFihg} +/// +/// One ancestor must be a [Material] widget and typically this is +/// provided by the app's [Scaffold]. +/// +/// The type `T` is the type of the [value] that each dropdown item represents. +/// All the entries in a given menu must represent values with consistent types. +/// Typically, an enum is used. Each [DropdownMenuItem] in [items] must be +/// specialized with that same type argument. +/// +/// The [onChanged] callback should update a state variable that defines the +/// dropdown's value. It should also call [State.setState] to rebuild the +/// dropdown with the new value. +/// +/// +/// {@tool dartpad} +/// This sample shows a [DropdownButton] with a large arrow icon, +/// purple text style, and bold purple underline, whose value is one of "One", +/// "Two", "Free", or "Four". +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/dropdown_button.png) +/// +/// ** See code in examples/api/lib/material/dropdown/dropdown_button.0.dart ** +/// {@end-tool} +/// +/// If the [onChanged] callback is null or the list of [items] is null +/// then the dropdown button will be disabled, i.e. its arrow will be +/// displayed in grey and it will not respond to input. A disabled button +/// will display the [disabledHint] widget if it is non-null. However, if +/// [disabledHint] is null and [hint] is non-null, the [hint] widget will +/// instead be displayed. +/// +/// {@tool dartpad} +/// This sample shows how you would rewrite the above [DropdownButton] +/// to use the [DropdownMenu]. +/// +/// ** See code in examples/api/lib/material/dropdown_menu/dropdown_menu.1.dart ** +/// {@end-tool} +/// +/// +/// See also: +/// +/// * [DropdownButtonFormField], which integrates with the [Form] widget. +/// * [DropdownMenuItem], the class used to represent the [items]. +/// * [DropdownButtonHideUnderline], which prevents its descendant dropdown buttons +/// from displaying their underlines. +/// * [ElevatedButton], [TextButton], ordinary buttons that trigger a single action. +/// * <https://material.io/design/components/menus.html#dropdown-menu> +class DropdownButton<T> extends StatefulWidget { + /// Creates a dropdown button. + /// + /// The [items] must have distinct values. If [value] isn't null then it + /// must be equal to one of the [DropdownMenuItem] values. If [items] or + /// [onChanged] is null, the button will be disabled, the down arrow + /// will be greyed out. + /// + /// If [value] is null and the button is enabled, [hint] will be displayed + /// if it is non-null. + /// + /// If [value] is null and the button is disabled, [disabledHint] will be displayed + /// if it is non-null. If [disabledHint] is null, then [hint] will be displayed + /// if it is non-null. + /// + /// The [dropdownColor] argument specifies the background color of the + /// dropdown when it is open. If it is null, the current theme's + /// [ThemeData.canvasColor] will be used instead. + DropdownButton({ + super.key, + required this.items, + this.selectedItemBuilder, + this.value, + this.hint, + this.disabledHint, + required this.onChanged, + this.onTap, + this.elevation = 8, + this.style, + this.underline, + this.icon, + this.iconDisabledColor, + this.iconEnabledColor, + this.iconSize = 24.0, + this.isDense = false, + this.isExpanded = false, + this.itemHeight = kMinInteractiveDimension, + this.focusColor, + this.focusNode, + this.autofocus = false, + this.dropdownColor, + this.menuMaxHeight, + this.enableFeedback, + this.alignment = AlignmentDirectional.centerStart, + this.borderRadius, + this.padding, + // When adding new arguments, consider adding similar arguments to + // DropdownButtonFormField. + }) : assert(items == null || items.isEmpty || value == null || + items.where((DropdownMenuItem<T> item) { + return item.value == value; + }).length == 1, + "There should be exactly one item with [DropdownButton]'s value: " + '$value. \n' + 'Either zero or 2 or more [DropdownMenuItem]s were detected ' + 'with the same value', + ), + assert(itemHeight == null || itemHeight >= kMinInteractiveDimension), + _inputDecoration = null, + _isEmpty = false, + _isFocused = false; + + DropdownButton._formField({ + super.key, + required this.items, + this.selectedItemBuilder, + this.value, + this.hint, + this.disabledHint, + required this.onChanged, + this.onTap, + this.elevation = 8, + this.style, + this.underline, + this.icon, + this.iconDisabledColor, + this.iconEnabledColor, + this.iconSize = 24.0, + this.isDense = false, + this.isExpanded = false, + this.itemHeight = kMinInteractiveDimension, + this.focusColor, + this.focusNode, + this.autofocus = false, + this.dropdownColor, + this.menuMaxHeight, + this.enableFeedback, + this.alignment = AlignmentDirectional.centerStart, + this.borderRadius, + this.padding, + required InputDecoration inputDecoration, + required bool isEmpty, + required bool isFocused, + }) : assert(items == null || items.isEmpty || value == null || + items.where((DropdownMenuItem<T> item) { + return item.value == value; + }).length == 1, + "There should be exactly one item with [DropdownButtonFormField]'s value: " + '$value. \n' + 'Either zero or 2 or more [DropdownMenuItem]s were detected ' + 'with the same value', + ), + assert(itemHeight == null || itemHeight >= kMinInteractiveDimension), + _inputDecoration = inputDecoration, + _isEmpty = isEmpty, + _isFocused = isFocused; + + /// The list of items the user can select. + /// + /// If the [onChanged] callback is null or the list of items is null + /// then the dropdown button will be disabled, i.e. its arrow will be + /// displayed in grey and it will not respond to input. + final List<DropdownMenuItem<T>>? items; + + /// The value of the currently selected [DropdownMenuItem]. + /// + /// If [value] is null and the button is enabled, [hint] will be displayed + /// if it is non-null. + /// + /// If [value] is null and the button is disabled, [disabledHint] will be displayed + /// if it is non-null. If [disabledHint] is null, then [hint] will be displayed + /// if it is non-null. + final T? value; + + /// A placeholder widget that is displayed by the dropdown button. + /// + /// If [value] is null and the dropdown is enabled ([items] and [onChanged] are non-null), + /// this widget is displayed as a placeholder for the dropdown button's value. + /// + /// If [value] is null and the dropdown is disabled and [disabledHint] is null, + /// this widget is used as the placeholder. + final Widget? hint; + + /// A preferred placeholder widget that is displayed when the dropdown is disabled. + /// + /// If [value] is null, the dropdown is disabled ([items] or [onChanged] is null), + /// this widget is displayed as a placeholder for the dropdown button's value. + final Widget? disabledHint; + + /// {@template flutter.material.dropdownButton.onChanged} + /// Called when the user selects an item. + /// + /// If the [onChanged] callback is null or the list of [DropdownButton.items] + /// is null then the dropdown button will be disabled, i.e. its arrow will be + /// displayed in grey and it will not respond to input. A disabled button + /// will display the [DropdownButton.disabledHint] widget if it is non-null. + /// If [DropdownButton.disabledHint] is also null but [DropdownButton.hint] is + /// non-null, [DropdownButton.hint] will instead be displayed. + /// {@endtemplate} + final ValueChanged<T?>? onChanged; + + /// Called when the dropdown button is tapped. + /// + /// This is distinct from [onChanged], which is called when the user + /// selects an item from the dropdown. + /// + /// The callback will not be invoked if the dropdown button is disabled. + final VoidCallback? onTap; + + /// A builder to customize the dropdown buttons corresponding to the + /// [DropdownMenuItem]s in [items]. + /// + /// When a [DropdownMenuItem] is selected, the widget that will be displayed + /// from the list corresponds to the [DropdownMenuItem] of the same index + /// in [items]. + /// + /// {@tool dartpad} + /// This sample shows a `DropdownButton` with a button with [Text] that + /// corresponds to but is unique from [DropdownMenuItem]. + /// + /// ** See code in examples/api/lib/material/dropdown/dropdown_button.selected_item_builder.0.dart ** + /// {@end-tool} + /// + /// If this callback is null, the [DropdownMenuItem] from [items] + /// that matches [value] will be displayed. + final DropdownButtonBuilder? selectedItemBuilder; + + /// The z-coordinate at which to place the menu when open. + /// + /// The following elevations have defined shadows: 1, 2, 3, 4, 6, 8, 9, 12, + /// 16, and 24. See [kElevationToShadow]. + /// + /// Defaults to 8, the appropriate elevation for dropdown buttons. + final int elevation; + + /// The text style to use for text in the dropdown button and the dropdown + /// menu that appears when you tap the button. + /// + /// To use a separate text style for selected item when it's displayed within + /// the dropdown button, consider using [selectedItemBuilder]. + /// + /// {@tool dartpad} + /// This sample shows a `DropdownButton` with a dropdown button text style + /// that is different than its menu items. + /// + /// ** See code in examples/api/lib/material/dropdown/dropdown_button.style.0.dart ** + /// {@end-tool} + /// + /// Defaults to the [TextTheme.titleMedium] value of the current + /// [ThemeData.textTheme] of the current [Theme]. + final TextStyle? style; + + /// The widget to use for drawing the drop-down button's underline. + /// + /// Defaults to a 0.0 width bottom border with color 0xFFBDBDBD. + final Widget? underline; + + /// The widget to use for the drop-down button's icon. + /// + /// Defaults to an [Icon] with the [Icons.arrow_drop_down] glyph. + final Widget? icon; + + /// The color of any [Icon] descendant of [icon] if this button is disabled, + /// i.e. if [onChanged] is null. + /// + /// Defaults to [MaterialColor.shade400] of [Colors.grey] when the theme's + /// [ThemeData.brightness] is [Brightness.light] and to + /// [Colors.white10] when it is [Brightness.dark] + final Color? iconDisabledColor; + + /// The color of any [Icon] descendant of [icon] if this button is enabled, + /// i.e. if [onChanged] is defined. + /// + /// Defaults to [MaterialColor.shade700] of [Colors.grey] when the theme's + /// [ThemeData.brightness] is [Brightness.light] and to + /// [Colors.white70] when it is [Brightness.dark] + final Color? iconEnabledColor; + + /// The size to use for the drop-down button's down arrow icon button. + /// + /// Defaults to 24.0. + final double iconSize; + + /// Reduce the button's height. + /// + /// By default this button's height is the same as its menu items' heights. + /// If isDense is true, the button's height is reduced by about half. This + /// can be useful when the button is embedded in a container that adds + /// its own decorations, like [InputDecorator]. + final bool isDense; + + /// Set the dropdown's inner contents to horizontally fill its parent. + /// + /// By default this button's inner width is the minimum size of its contents. + /// If [isExpanded] is true, the inner width is expanded to fill its + /// surrounding container. + final bool isExpanded; + + /// If null, then the menu item heights will vary according to each menu item's + /// intrinsic height. + /// + /// The default value is [kMinInteractiveDimension], which is also the minimum + /// height for menu items. + /// + /// If this value is null and there isn't enough vertical room for the menu, + /// then the menu's initial scroll offset may not align the selected item with + /// the dropdown button. That's because, in this case, the initial scroll + /// offset is computed as if all of the menu item heights were + /// [kMinInteractiveDimension]. + final double? itemHeight; + + /// The color for the button's [Material] when it has the input focus. + final Color? focusColor; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// The background color of the dropdown. + /// + /// If it is not provided, the theme's [ThemeData.canvasColor] will be used + /// instead. + final Color? dropdownColor; + + /// Padding around the visible portion of the dropdown widget. + /// + /// As the padding increases, the size of the [DropdownButton] will also + /// increase. The padding is included in the clickable area of the dropdown + /// widget, so this can make the widget easier to click. + /// + /// Padding can be useful when used with a custom border. The clickable + /// area will stay flush with the border, as opposed to an external [Padding] + /// widget which will leave a non-clickable gap. + final EdgeInsetsGeometry? padding; + + /// The maximum height of the menu. + /// + /// The maximum height of the menu must be at least one row shorter than + /// the height of the app's view. This ensures that a tappable area + /// outside of the simple menu is present so the user can dismiss the menu. + /// + /// If this property is set above the maximum allowable height threshold + /// mentioned above, then the menu defaults to being padded at the top + /// and bottom of the menu by at one menu item's height. + final double? menuMaxHeight; + + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// By default, platform-specific feedback is enabled. + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + /// Defines how the hint or the selected item is positioned within the button. + /// + /// Defaults to [AlignmentDirectional.centerStart]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// Defines the corner radii of the menu's rounded rectangle shape. + final BorderRadius? borderRadius; + + final InputDecoration? _inputDecoration; + + final bool _isEmpty; + + final bool _isFocused; + + @override + State<DropdownButton<T>> createState() => _DropdownButtonState<T>(); +} + +class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindingObserver { + int? _selectedIndex; + _DropdownRoute<T>? _dropdownRoute; + Orientation? _lastOrientation; + FocusNode? _internalNode; + FocusNode? get focusNode => widget.focusNode ?? _internalNode; + late Map<Type, Action<Intent>> _actionMap; + + // Only used if needed to create _internalNode. + FocusNode _createFocusNode() { + return FocusNode(debugLabel: '${widget.runtimeType}'); + } + + @override + void initState() { + super.initState(); + _updateSelectedIndex(); + if (widget.focusNode == null) { + _internalNode ??= _createFocusNode(); + } + _actionMap = <Type, Action<Intent>>{ + ActivateIntent: CallbackAction<ActivateIntent>( + onInvoke: (ActivateIntent intent) => _handleTap(), + ), + ButtonActivateIntent: CallbackAction<ButtonActivateIntent>( + onInvoke: (ButtonActivateIntent intent) => _handleTap(), + ), + }; + } + + @override + void dispose() { + WidgetsBinding.instance.removeObserver(this); + _removeDropdownRoute(); + _internalNode?.dispose(); + super.dispose(); + } + + void _removeDropdownRoute() { + _dropdownRoute?._dismiss(); + _dropdownRoute = null; + _lastOrientation = null; + } + + @override + void didUpdateWidget(DropdownButton<T> oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.focusNode == null) { + _internalNode ??= _createFocusNode(); + } + _updateSelectedIndex(); + } + + void _updateSelectedIndex() { + if (widget.items == null + || widget.items!.isEmpty + || (widget.value == null && + widget.items! + .where((DropdownMenuItem<T> item) => item.enabled && item.value == widget.value) + .isEmpty)) { + _selectedIndex = null; + return; + } + + assert(widget.items!.where((DropdownMenuItem<T> item) => item.value == widget.value).length == 1); + for (int itemIndex = 0; itemIndex < widget.items!.length; itemIndex++) { + if (widget.items![itemIndex].value == widget.value) { + _selectedIndex = itemIndex; + return; + } + } + } + + TextStyle? get _textStyle => widget.style ?? Theme.of(context).textTheme.titleMedium; + + void _handleTap() { + final TextDirection? textDirection = Directionality.maybeOf(context); + final EdgeInsetsGeometry menuMargin = ButtonTheme.of(context).alignedDropdown + ? _kAlignedMenuMargin + : _kUnalignedMenuMargin; + + final List<_MenuItem<T>> menuItems = <_MenuItem<T>>[ + for (int index = 0; index < widget.items!.length; index += 1) + _MenuItem<T>( + item: widget.items![index], + onLayout: (Size size) { + // If [_dropdownRoute] is null and onLayout is called, this means + // that performLayout was called on a _DropdownRoute that has not + // left the widget tree but is already on its way out. + // + // Since onLayout is used primarily to collect the desired heights + // of each menu item before laying them out, not having the _DropdownRoute + // collect each item's height to lay out is fine since the route is + // already on its way out. + if (_dropdownRoute == null) { + return; + } + + _dropdownRoute!.itemHeights[index] = size.height; + }, + ), + ]; + + final NavigatorState navigator = Navigator.of(context); + assert(_dropdownRoute == null); + final RenderBox itemBox = context.findRenderObject()! as RenderBox; + final Rect itemRect = itemBox.localToGlobal(Offset.zero, ancestor: navigator.context.findRenderObject()) & itemBox.size; + _dropdownRoute = _DropdownRoute<T>( + items: menuItems, + buttonRect: menuMargin.resolve(textDirection).inflateRect(itemRect), + padding: _kMenuItemPadding.resolve(textDirection), + selectedIndex: _selectedIndex ?? 0, + elevation: widget.elevation, + capturedThemes: InheritedTheme.capture(from: context, to: navigator.context), + style: _textStyle!, + barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, + itemHeight: widget.itemHeight, + dropdownColor: widget.dropdownColor, + menuMaxHeight: widget.menuMaxHeight, + enableFeedback: widget.enableFeedback ?? true, + borderRadius: widget.borderRadius, + ); + + focusNode?.requestFocus(); + navigator.push(_dropdownRoute!).then<void>((_DropdownRouteResult<T>? newValue) { + _removeDropdownRoute(); + if (!mounted || newValue == null) { + return; + } + widget.onChanged?.call(newValue.result); + }); + + widget.onTap?.call(); + } + + // When isDense is true, reduce the height of this button from _kMenuItemHeight to + // _kDenseButtonHeight, but don't make it smaller than the text that it contains. + // Similarly, we don't reduce the height of the button so much that its icon + // would be clipped. + double get _denseButtonHeight { + final double fontSize = _textStyle!.fontSize ?? Theme.of(context).textTheme.titleMedium!.fontSize!; + final double scaledFontSize = MediaQuery.textScalerOf(context).scale(fontSize); + return math.max(scaledFontSize, math.max(widget.iconSize, _kDenseButtonHeight)); + } + + Color get _iconColor { + // These colors are not defined in the Material Design spec. + if (_enabled) { + if (widget.iconEnabledColor != null) { + return widget.iconEnabledColor!; + } + + switch (Theme.of(context).brightness) { + case Brightness.light: + return Colors.grey.shade700; + case Brightness.dark: + return Colors.white70; + } + } else { + if (widget.iconDisabledColor != null) { + return widget.iconDisabledColor!; + } + + switch (Theme.of(context).brightness) { + case Brightness.light: + return Colors.grey.shade400; + case Brightness.dark: + return Colors.white10; + } + } + } + + bool get _enabled => widget.items != null && widget.items!.isNotEmpty && widget.onChanged != null; + + Orientation _getOrientation(BuildContext context) { + Orientation? result = MediaQuery.maybeOrientationOf(context); + if (result == null) { + // If there's no MediaQuery, then use the view aspect to determine + // orientation. + final Size size = View.of(context).physicalSize; + result = size.width > size.height ? Orientation.landscape : Orientation.portrait; + } + return result; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMaterialLocalizations(context)); + final Orientation newOrientation = _getOrientation(context); + _lastOrientation ??= newOrientation; + if (newOrientation != _lastOrientation) { + _removeDropdownRoute(); + _lastOrientation = newOrientation; + } + + // The width of the button and the menu are defined by the widest + // item and the width of the hint. + // We should explicitly type the items list to be a list of <Widget>, + // otherwise, no explicit type adding items maybe trigger a crash/failure + // when hint and selectedItemBuilder are provided. + final List<Widget> items = widget.selectedItemBuilder == null + ? (widget.items != null ? List<Widget>.of(widget.items!) : <Widget>[]) + : List<Widget>.of(widget.selectedItemBuilder!(context)); + + int? hintIndex; + if (widget.hint != null || (!_enabled && widget.disabledHint != null)) { + final Widget displayedHint = _enabled ? widget.hint! : widget.disabledHint ?? widget.hint!; + + hintIndex = items.length; + items.add(DefaultTextStyle( + style: _textStyle!.copyWith(color: Theme.of(context).hintColor), + child: IgnorePointer( + child: _DropdownMenuItemContainer( + alignment: widget.alignment, + child: displayedHint, + ), + ), + )); + } + + final EdgeInsetsGeometry padding = ButtonTheme.of(context).alignedDropdown + ? _kAlignedButtonPadding + : _kUnalignedButtonPadding; + + // If value is null (then _selectedIndex is null) then we + // display the hint or nothing at all. + final Widget innerItemsWidget; + if (items.isEmpty) { + innerItemsWidget = const SizedBox.shrink(); + } else { + innerItemsWidget = IndexedStack( + index: _selectedIndex ?? hintIndex, + alignment: widget.alignment, + children: widget.isDense ? items : items.map((Widget item) { + return widget.itemHeight != null + ? SizedBox(height: widget.itemHeight, child: item) + : Column(mainAxisSize: MainAxisSize.min, children: <Widget>[item]); + }).toList(), + ); + } + + const Icon defaultIcon = Icon(Icons.arrow_drop_down); + + Widget result = DefaultTextStyle( + style: _enabled ? _textStyle! : _textStyle!.copyWith(color: Theme.of(context).disabledColor), + child: Container( + padding: padding.resolve(Directionality.of(context)), + height: widget.isDense ? _denseButtonHeight : null, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + if (widget.isExpanded) + Expanded(child: innerItemsWidget) + else + innerItemsWidget, + IconTheme( + data: IconThemeData( + color: _iconColor, + size: widget.iconSize, + ), + child: widget.icon ?? defaultIcon, + ), + ], + ), + ), + ); + + if (!DropdownButtonHideUnderline.at(context)) { + final double bottom = (widget.isDense || widget.itemHeight == null) ? 0.0 : 8.0; + result = Stack( + children: <Widget>[ + result, + Positioned( + left: 0.0, + right: 0.0, + bottom: bottom, + child: widget.underline ?? Container( + height: 1.0, + decoration: const BoxDecoration( + border: Border( + bottom: BorderSide( + color: Color(0xFFBDBDBD), + width: 0.0, + ), + ), + ), + ), + ), + ], + ); + } + + final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor>( + MaterialStateMouseCursor.clickable, + <MaterialState>{ + if (!_enabled) MaterialState.disabled, + }, + ); + + if (widget._inputDecoration != null) { + result = InputDecorator( + decoration: widget._inputDecoration!, + isEmpty: widget._isEmpty, + isFocused: widget._isFocused, + child: result, + ); + } + + return Semantics( + button: true, + child: Actions( + actions: _actionMap, + child: InkWell( + mouseCursor: effectiveMouseCursor, + onTap: _enabled ? _handleTap : null, + canRequestFocus: _enabled, + borderRadius: widget.borderRadius, + focusNode: focusNode, + autofocus: widget.autofocus, + focusColor: widget.focusColor ?? Theme.of(context).focusColor, + enableFeedback: false, + child: widget.padding == null ? result : Padding(padding: widget.padding!, child: result), + ), + ), + ); + } +} + +/// A [FormField] that contains a [DropdownButton]. +/// +/// This is a convenience widget that wraps a [DropdownButton] widget in a +/// [FormField]. +/// +/// A [Form] ancestor is not required. The [Form] allows one to +/// save, reset, or validate multiple fields at once. To use without a [Form], +/// pass a [GlobalKey] to the constructor and use [GlobalKey.currentState] to +/// save or reset the form field. +/// +/// See also: +/// +/// * [DropdownButton], which is the underlying text field without the [Form] +/// integration. +class DropdownButtonFormField<T> extends FormField<T> { + /// Creates a [DropdownButton] widget that is a [FormField], wrapped in an + /// [InputDecorator]. + /// + /// For a description of the `onSaved`, `validator`, or `autovalidateMode` + /// parameters, see [FormField]. For the rest (other than [decoration]), see + /// [DropdownButton]. + DropdownButtonFormField({ + super.key, + required List<DropdownMenuItem<T>>? items, + DropdownButtonBuilder? selectedItemBuilder, + T? value, + Widget? hint, + Widget? disabledHint, + required this.onChanged, + VoidCallback? onTap, + int elevation = 8, + TextStyle? style, + Widget? icon, + Color? iconDisabledColor, + Color? iconEnabledColor, + double iconSize = 24.0, + bool isDense = true, + bool isExpanded = false, + double? itemHeight, + Color? focusColor, + FocusNode? focusNode, + bool autofocus = false, + Color? dropdownColor, + InputDecoration? decoration, + super.onSaved, + super.validator, + AutovalidateMode? autovalidateMode, + double? menuMaxHeight, + bool? enableFeedback, + AlignmentGeometry alignment = AlignmentDirectional.centerStart, + BorderRadius? borderRadius, + EdgeInsetsGeometry? padding, + // When adding new arguments, consider adding similar arguments to + // DropdownButton. + }) : assert(items == null || items.isEmpty || value == null || + items.where((DropdownMenuItem<T> item) { + return item.value == value; + }).length == 1, + "There should be exactly one item with [DropdownButton]'s value: " + '$value. \n' + 'Either zero or 2 or more [DropdownMenuItem]s were detected ' + 'with the same value', + ), + assert(itemHeight == null || itemHeight >= kMinInteractiveDimension), + decoration = decoration ?? InputDecoration(focusColor: focusColor), + super( + initialValue: value, + autovalidateMode: autovalidateMode ?? AutovalidateMode.disabled, + builder: (FormFieldState<T> field) { + final _DropdownButtonFormFieldState<T> state = field as _DropdownButtonFormFieldState<T>; + final InputDecoration decorationArg = decoration ?? InputDecoration(focusColor: focusColor); + final InputDecoration effectiveDecoration = decorationArg.applyDefaults( + Theme.of(field.context).inputDecorationTheme, + ); + + final bool showSelectedItem = items != null && items.where((DropdownMenuItem<T> item) => item.value == state.value).isNotEmpty; + bool isHintOrDisabledHintAvailable() { + final bool isDropdownDisabled = onChanged == null || (items == null || items.isEmpty); + if (isDropdownDisabled) { + return hint != null || disabledHint != null; + } else { + return hint != null; + } + } + final bool isEmpty = !showSelectedItem && !isHintOrDisabledHintAvailable(); + final bool hasError = effectiveDecoration.errorText != null; + + // An unfocusable Focus widget so that this widget can detect if its + // descendants have focus or not. + return Focus( + canRequestFocus: false, + skipTraversal: true, + child: Builder(builder: (BuildContext context) { + final bool isFocused = Focus.of(context).hasFocus; + InputBorder? resolveInputBorder() { + if (hasError) { + if (isFocused) { + return effectiveDecoration.focusedErrorBorder; + } + return effectiveDecoration.errorBorder; + } + if (isFocused) { + return effectiveDecoration.focusedBorder; + } + if (effectiveDecoration.enabled) { + return effectiveDecoration.enabledBorder; + } + return effectiveDecoration.border; + } + BorderRadius? effectiveBorderRadius() { + final InputBorder? inputBorder = resolveInputBorder(); + if (inputBorder is OutlineInputBorder) { + return inputBorder.borderRadius; + } + if (inputBorder is UnderlineInputBorder) { + return inputBorder.borderRadius; + } + return null; + } + + return DropdownButtonHideUnderline( + child: DropdownButton<T>._formField( + items: items, + selectedItemBuilder: selectedItemBuilder, + value: state.value, + hint: hint, + disabledHint: disabledHint, + onChanged: onChanged == null ? null : state.didChange, + onTap: onTap, + elevation: elevation, + style: style, + icon: icon, + iconDisabledColor: iconDisabledColor, + iconEnabledColor: iconEnabledColor, + iconSize: iconSize, + isDense: isDense, + isExpanded: isExpanded, + itemHeight: itemHeight, + focusColor: focusColor, + focusNode: focusNode, + autofocus: autofocus, + dropdownColor: dropdownColor, + menuMaxHeight: menuMaxHeight, + enableFeedback: enableFeedback, + alignment: alignment, + borderRadius: borderRadius ?? effectiveBorderRadius(), + inputDecoration: effectiveDecoration.copyWith(errorText: field.errorText), + isEmpty: isEmpty, + isFocused: isFocused, + padding: padding, + ), + ); + }), + ); + }, + ); + + /// {@macro flutter.material.dropdownButton.onChanged} + final ValueChanged<T?>? onChanged; + + /// The decoration to show around the dropdown button form field. + /// + /// By default, draws a horizontal line under the dropdown button field but + /// can be configured to show an icon, label, hint text, and error text. + /// + /// If not specified, an [InputDecorator] with the `focusColor` set to the + /// supplied `focusColor` (if any) will be used. + final InputDecoration decoration; + + @override + FormFieldState<T> createState() => _DropdownButtonFormFieldState<T>(); +} + +class _DropdownButtonFormFieldState<T> extends FormFieldState<T> { + DropdownButtonFormField<T> get _dropdownButtonFormField => widget as DropdownButtonFormField<T>; + + @override + void didChange(T? value) { + super.didChange(value); + _dropdownButtonFormField.onChanged!(value); + } + + @override + void didUpdateWidget(DropdownButtonFormField<T> oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.initialValue != widget.initialValue) { + setValue(widget.initialValue); + } + } + + @override + void reset() { + super.reset(); + _dropdownButtonFormField.onChanged!(value); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dropdown_menu.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dropdown_menu.dart new file mode 100644 index 0000000000000000000000000000000000000000..e8f9aceb5f416a6bb625d29b72c90af4de77c3d5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dropdown_menu.dart @@ -0,0 +1,1019 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'dropdown_menu_theme.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'input_border.dart'; +import 'input_decorator.dart'; +import 'material_state.dart'; +import 'menu_anchor.dart'; +import 'menu_style.dart'; +import 'text_field.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +/// A callback function that returns the index of the item that matches the +/// current contents of a text field. +/// +/// If a match doesn't exist then null must be returned. +/// +/// Used by [DropdownMenu.searchCallback]. +typedef SearchCallback<T> = int? Function(List<DropdownMenuEntry<T>> entries, String query); + +// Navigation shortcuts to move the selected menu items up or down. +final Map<ShortcutActivator, Intent> _kMenuTraversalShortcuts = <ShortcutActivator, Intent> { + LogicalKeySet(LogicalKeyboardKey.arrowUp): const _ArrowUpIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowDown): const _ArrowDownIntent(), +}; + +const double _kMinimumWidth = 112.0; + +const double _kDefaultHorizontalPadding = 12.0; + +/// Defines a [DropdownMenu] menu button that represents one item view in the menu. +/// +/// See also: +/// +/// * [DropdownMenu] +class DropdownMenuEntry<T> { + /// Creates an entry that is used with [DropdownMenu.dropdownMenuEntries]. + const DropdownMenuEntry({ + required this.value, + required this.label, + this.labelWidget, + this.leadingIcon, + this.trailingIcon, + this.enabled = true, + this.style, + }); + + /// the value used to identify the entry. + /// + /// This value must be unique across all entries in a [DropdownMenu]. + final T value; + + /// The label displayed in the center of the menu item. + final String label; + + /// Overrides the default label widget which is `Text(label)`. + /// + /// {@tool dartpad} + /// This sample shows how to override the default label [Text] + /// widget with one that forces the menu entry to appear on one line + /// by specifying [Text.maxLines] and [Text.overflow]. + /// + /// ** See code in examples/api/lib/material/dropdown_menu/dropdown_menu_entry_label_widget.0.dart ** + /// {@end-tool} + final Widget? labelWidget; + + /// An optional icon to display before the label. + final Widget? leadingIcon; + + /// An optional icon to display after the label. + final Widget? trailingIcon; + + /// Whether the menu item is enabled or disabled. + /// + /// The default value is true. If true, the [DropdownMenuEntry.label] will be filled + /// out in the text field of the [DropdownMenu] when this entry is clicked; otherwise, + /// this entry is disabled. + final bool enabled; + + /// Customizes this menu item's appearance. + /// + /// Null by default. + final ButtonStyle? style; +} + + +/// A dropdown menu that can be opened from a [TextField]. The selected +/// menu item is displayed in that field. +/// +/// This widget is used to help people make a choice from a menu and put the +/// selected item into the text input field. People can also filter the list based +/// on the text input or search one item in the menu list. +/// +/// The menu is composed of a list of [DropdownMenuEntry]s. People can provide information, +/// such as: label, leading icon or trailing icon for each entry. The [TextField] +/// will be updated based on the selection from the menu entries. The text field +/// will stay empty if the selected entry is disabled. +/// +/// The dropdown menu can be traversed by pressing the up or down key. During the +/// process, the corresponding item will be highlighted and the text field will be updated. +/// Disabled items will be skipped during traversal. +/// +/// The menu can be scrollable if not all items in the list are displayed at once. +/// +/// {@tool dartpad} +/// This sample shows how to display outlined [DropdownMenu] and filled [DropdownMenu]. +/// +/// ** See code in examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [MenuAnchor], which is a widget used to mark the "anchor" for a set of submenus. +/// The [DropdownMenu] uses a [TextField] as the "anchor". +/// * [TextField], which is a text input widget that uses an [InputDecoration]. +/// * [DropdownMenuEntry], which is used to build the [MenuItemButton] in the [DropdownMenu] list. +class DropdownMenu<T> extends StatefulWidget { + /// Creates a const [DropdownMenu]. + /// + /// The leading and trailing icons in the text field can be customized by using + /// [leadingIcon], [trailingIcon] and [selectedTrailingIcon] properties. They are + /// passed down to the [InputDecoration] properties, and will override values + /// in the [InputDecoration.prefixIcon] and [InputDecoration.suffixIcon]. + /// + /// Except leading and trailing icons, the text field can be configured by the + /// [InputDecorationTheme] property. The menu can be configured by the [menuStyle]. + const DropdownMenu({ + super.key, + this.enabled = true, + this.width, + this.menuHeight, + this.leadingIcon, + this.trailingIcon, + this.label, + this.hintText, + this.helperText, + this.errorText, + this.selectedTrailingIcon, + this.enableFilter = false, + this.enableSearch = true, + this.textStyle, + this.inputDecorationTheme, + this.menuStyle, + this.controller, + this.initialSelection, + this.onSelected, + this.requestFocusOnTap, + this.expandedInsets, + this.searchCallback, + required this.dropdownMenuEntries, + }); + + /// Determine if the [DropdownMenu] is enabled. + /// + /// Defaults to true. + final bool enabled; + + /// Determine the width of the [DropdownMenu]. + /// + /// If this is null, the width of the [DropdownMenu] will be the same as the width of the widest + /// menu item plus the width of the leading/trailing icon. + final double? width; + + /// Determine the height of the menu. + /// + /// If this is null, the menu will display as many items as possible on the screen. + final double? menuHeight; + + /// An optional Icon at the front of the text input field. + /// + /// Defaults to null. If this is not null, the menu items will have extra paddings to be aligned + /// with the text in the text field. + final Widget? leadingIcon; + + /// An optional icon at the end of the text field. + /// + /// Defaults to an [Icon] with [Icons.arrow_drop_down]. + final Widget? trailingIcon; + + /// Optional widget that describes the input field. + /// + /// When the input field is empty and unfocused, the label is displayed on + /// top of the input field (i.e., at the same location on the screen where + /// text may be entered in the input field). When the input field receives + /// focus (or if the field is non-empty), the label moves above, either + /// vertically adjacent to, or to the center of the input field. + /// + /// Defaults to null. + final Widget? label; + + /// Text that suggests what sort of input the field accepts. + /// + /// Defaults to null; + final String? hintText; + + /// Text that provides context about the [DropdownMenu]'s value, such + /// as how the value will be used. + /// + /// If non-null, the text is displayed below the input field, in + /// the same location as [errorText]. If a non-null [errorText] value is + /// specified then the helper text is not shown. + /// + /// Defaults to null; + /// + /// See also: + /// + /// * [InputDecoration.helperText], which is the text that provides context about the [InputDecorator.child]'s value. + final String? helperText; + + /// Text that appears below the input field and the border to show the error message. + /// + /// If non-null, the border's color animates to red and the [helperText] is not shown. + /// + /// Defaults to null; + /// + /// See also: + /// + /// * [InputDecoration.errorText], which is the text that appears below the [InputDecorator.child] and the border. + final String? errorText; + + /// An optional icon at the end of the text field to indicate that the text + /// field is pressed. + /// + /// Defaults to an [Icon] with [Icons.arrow_drop_up]. + final Widget? selectedTrailingIcon; + + /// Determine if the menu list can be filtered by the text input. + /// + /// Defaults to false. + final bool enableFilter; + + /// Determine if the first item that matches the text input can be highlighted. + /// + /// Defaults to true as the search function could be commonly used. + final bool enableSearch; + + /// The text style for the [TextField] of the [DropdownMenu]; + /// + /// Defaults to the overall theme's [TextTheme.bodyLarge] + /// if the dropdown menu theme's value is null. + final TextStyle? textStyle; + + /// Defines the default appearance of [InputDecoration] to show around the text field. + /// + /// By default, shows a outlined text field. + final InputDecorationTheme? inputDecorationTheme; + + /// The [MenuStyle] that defines the visual attributes of the menu. + /// + /// The default width of the menu is set to the width of the text field. + final MenuStyle? menuStyle; + + /// Controls the text being edited or selected in the menu. + /// + /// If null, this widget will create its own [TextEditingController]. + final TextEditingController? controller; + + /// The value used to for an initial selection. + /// + /// Defaults to null. + final T? initialSelection; + + /// The callback is called when a selection is made. + /// + /// Defaults to null. If null, only the text field is updated. + final ValueChanged<T?>? onSelected; + + /// Determine if the dropdown button requests focus and the on-screen virtual + /// keyboard is shown in response to a touch event. + /// + /// By default, on mobile platforms, tapping on the text field and opening + /// the menu will not cause a focus request and the virtual keyboard will not + /// appear. The default behavior for desktop platforms is for the dropdown to + /// take the focus. + /// + /// Defaults to null. Setting this field to true or false, rather than allowing + /// the implementation to choose based on the platform, can be useful for + /// applications that want to override the default behavior. + final bool? requestFocusOnTap; + + /// Descriptions of the menu items in the [DropdownMenu]. + /// + /// This is a required parameter. It is recommended that at least one [DropdownMenuEntry] + /// is provided. If this is an empty list, the menu will be empty and only + /// contain space for padding. + final List<DropdownMenuEntry<T>> dropdownMenuEntries; + + /// Defines the menu text field's width to be equal to its parent's width + /// plus the horizontal width of the specified insets. + /// + /// If this property is null, the width of the text field will be determined + /// by the width of menu items or [DropdownMenu.width]. If this property is not null, + /// the text field's width will match the parent's width plus the specified insets. + /// If the value of this property is [EdgeInsets.zero], the width of the text field will be the same + /// as its parent's width. + /// + /// The [expandedInsets]' top and bottom are ignored, only its left and right + /// properties are used. + /// + /// Defaults to null. + final EdgeInsets? expandedInsets; + + /// When [DropdownMenu.enableSearch] is true, this callback is used to compute + /// the index of the search result to be highlighted. + /// + /// {@tool snippet} + /// + /// In this example the `searchCallback` returns the index of the search result + /// that exactly matches the query. + /// + /// ```dart + /// DropdownMenu<Text>( + /// searchCallback: (List<DropdownMenuEntry<Text>> entries, String query) { + /// if (query.isEmpty) { + /// return null; + /// } + /// final int index = entries.indexWhere((DropdownMenuEntry<Text> entry) => entry.label == query); + /// + /// return index != -1 ? index : null; + /// }, + /// dropdownMenuEntries: const <DropdownMenuEntry<Text>>[], + /// ) + /// ``` + /// {@end-tool} + /// + /// Defaults to null. If this is null and [DropdownMenu.enableSearch] is true, + /// the default function will return the index of the first matching result + /// which contains the contents of the text input field. + final SearchCallback<T>? searchCallback; + + @override + State<DropdownMenu<T>> createState() => _DropdownMenuState<T>(); +} + +class _DropdownMenuState<T> extends State<DropdownMenu<T>> { + final GlobalKey _anchorKey = GlobalKey(); + final GlobalKey _leadingKey = GlobalKey(); + late List<GlobalKey> buttonItemKeys; + final MenuController _controller = MenuController(); + late bool _enableFilter; + late List<DropdownMenuEntry<T>> filteredEntries; + List<Widget>? _initialMenu; + int? currentHighlight; + double? leadingPadding; + bool _menuHasEnabledItem = false; + TextEditingController? _localTextEditingController; + TextEditingController get _textEditingController { + return widget.controller ?? (_localTextEditingController ??= TextEditingController()); + } + + @override + void initState() { + super.initState(); + _enableFilter = widget.enableFilter; + filteredEntries = widget.dropdownMenuEntries; + buttonItemKeys = List<GlobalKey>.generate(filteredEntries.length, (int index) => GlobalKey()); + _menuHasEnabledItem = filteredEntries.any((DropdownMenuEntry<T> entry) => entry.enabled); + + final int index = filteredEntries.indexWhere((DropdownMenuEntry<T> entry) => entry.value == widget.initialSelection); + if (index != -1) { + _textEditingController.value = TextEditingValue( + text: filteredEntries[index].label, + selection: TextSelection.collapsed(offset: filteredEntries[index].label.length), + ); + } + refreshLeadingPadding(); + } + + @override + void dispose() { + _localTextEditingController?.dispose(); + _localTextEditingController = null; + super.dispose(); + } + + @override + void didUpdateWidget(DropdownMenu<T> oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.controller != widget.controller) { + if (widget.controller != null) { + _localTextEditingController?.dispose(); + _localTextEditingController = null; + } + } + if (oldWidget.enableSearch != widget.enableSearch) { + if (!widget.enableSearch) { + currentHighlight = null; + } + } + if (oldWidget.dropdownMenuEntries != widget.dropdownMenuEntries) { + currentHighlight = null; + filteredEntries = widget.dropdownMenuEntries; + buttonItemKeys = List<GlobalKey>.generate(filteredEntries.length, (int index) => GlobalKey()); + _menuHasEnabledItem = filteredEntries.any((DropdownMenuEntry<T> entry) => entry.enabled); + } + if (oldWidget.leadingIcon != widget.leadingIcon) { + refreshLeadingPadding(); + } + if (oldWidget.initialSelection != widget.initialSelection) { + final int index = filteredEntries.indexWhere((DropdownMenuEntry<T> entry) => entry.value == widget.initialSelection); + if (index != -1) { + _textEditingController.value = TextEditingValue( + text: filteredEntries[index].label, + selection: TextSelection.collapsed(offset: filteredEntries[index].label.length), + ); + } + } + } + + bool canRequestFocus() { + if (widget.requestFocusOnTap != null) { + return widget.requestFocusOnTap!; + } + + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.android: + case TargetPlatform.fuchsia: + return false; + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + return true; + } + } + + void refreshLeadingPadding() { + WidgetsBinding.instance.addPostFrameCallback((_) { + setState(() { + leadingPadding = getWidth(_leadingKey); + }); + }, debugLabel: 'DropdownMenu.refreshLeadingPadding'); + } + + void scrollToHighlight() { + WidgetsBinding.instance.addPostFrameCallback((_) { + final BuildContext? highlightContext = buttonItemKeys[currentHighlight!].currentContext; + if (highlightContext != null) { + Scrollable.ensureVisible(highlightContext); + } + }, debugLabel: 'DropdownMenu.scrollToHighlight'); + } + + double? getWidth(GlobalKey key) { + final BuildContext? context = key.currentContext; + if (context != null) { + final RenderBox box = context.findRenderObject()! as RenderBox; + return box.hasSize ? box.size.width : null; + } + return null; + } + + List<DropdownMenuEntry<T>> filter(List<DropdownMenuEntry<T>> entries, TextEditingController textEditingController) { + final String filterText = textEditingController.text.toLowerCase(); + return entries + .where((DropdownMenuEntry<T> entry) => entry.label.toLowerCase().contains(filterText)) + .toList(); + } + + int? search(List<DropdownMenuEntry<T>> entries, TextEditingController textEditingController) { + final String searchText = textEditingController.value.text.toLowerCase(); + if (searchText.isEmpty) { + return null; + } + final int index = entries.indexWhere((DropdownMenuEntry<T> entry) => entry.label.toLowerCase().contains(searchText)); + + return index != -1 ? index : null; + } + + List<Widget> _buildButtons( + List<DropdownMenuEntry<T>> filteredEntries, + TextDirection textDirection, + { int? focusedIndex, bool enableScrollToHighlight = true} + ) { + final List<Widget> result = <Widget>[]; + for (int i = 0; i < filteredEntries.length; i++) { + final DropdownMenuEntry<T> entry = filteredEntries[i]; + + // By default, when the text field has a leading icon but a menu entry doesn't + // have one, the label of the entry should have extra padding to be aligned + // with the text in the text input field. When both the text field and the + // menu entry have leading icons, the menu entry should remove the extra + // paddings so its leading icon will be aligned with the leading icon of + // the text field. + final double padding = entry.leadingIcon == null ? (leadingPadding ?? _kDefaultHorizontalPadding) : _kDefaultHorizontalPadding; + final ButtonStyle defaultStyle; + switch (textDirection) { + case TextDirection.rtl: + defaultStyle = MenuItemButton.styleFrom( + padding: EdgeInsets.only(left: _kDefaultHorizontalPadding, right: padding), + ); + case TextDirection.ltr: + defaultStyle = MenuItemButton.styleFrom( + padding: EdgeInsets.only(left: padding, right: _kDefaultHorizontalPadding), + ); + } + + ButtonStyle effectiveStyle = entry.style ?? defaultStyle; + final Color focusedBackgroundColor = effectiveStyle.foregroundColor?.resolve(<MaterialState>{MaterialState.focused}) + ?? Theme.of(context).colorScheme.onSurface; + + Widget label = entry.labelWidget ?? Text(entry.label); + if (widget.width != null) { + final double horizontalPadding = padding + _kDefaultHorizontalPadding; + label = ConstrainedBox( + constraints: BoxConstraints(maxWidth: widget.width! - horizontalPadding), + child: label, + ); + } + + // Simulate the focused state because the text field should always be focused + // during traversal. If the menu item has a custom foreground color, the "focused" + // color will also change to foregroundColor.withOpacity(0.12). + effectiveStyle = entry.enabled && i == focusedIndex + ? effectiveStyle.copyWith( + backgroundColor: MaterialStatePropertyAll<Color>(focusedBackgroundColor.withOpacity(0.12)) + ) + : effectiveStyle; + + final Widget menuItemButton = MenuItemButton( + key: enableScrollToHighlight ? buttonItemKeys[i] : null, + style: effectiveStyle, + leadingIcon: entry.leadingIcon, + trailingIcon: entry.trailingIcon, + onPressed: entry.enabled + ? () { + _textEditingController.value = TextEditingValue( + text: entry.label, + selection: TextSelection.collapsed(offset: entry.label.length), + ); + currentHighlight = widget.enableSearch ? i : null; + widget.onSelected?.call(entry.value); + } + : null, + requestFocusOnHover: false, + child: label, + ); + result.add(menuItemButton); + } + + return result; + } + + void handleUpKeyInvoke(_) { + setState(() { + if (!_menuHasEnabledItem || !_controller.isOpen) { + return; + } + _enableFilter = false; + currentHighlight ??= 0; + currentHighlight = (currentHighlight! - 1) % filteredEntries.length; + while (!filteredEntries[currentHighlight!].enabled) { + currentHighlight = (currentHighlight! - 1) % filteredEntries.length; + } + final String currentLabel = filteredEntries[currentHighlight!].label; + _textEditingController.value = TextEditingValue( + text: currentLabel, + selection: TextSelection.collapsed(offset: currentLabel.length), + ); + }); + } + + void handleDownKeyInvoke(_) { + setState(() { + if (!_menuHasEnabledItem || !_controller.isOpen) { + return; + } + _enableFilter = false; + currentHighlight ??= -1; + currentHighlight = (currentHighlight! + 1) % filteredEntries.length; + while (!filteredEntries[currentHighlight!].enabled) { + currentHighlight = (currentHighlight! + 1) % filteredEntries.length; + } + final String currentLabel = filteredEntries[currentHighlight!].label; + _textEditingController.value = TextEditingValue( + text: currentLabel, + selection: TextSelection.collapsed(offset: currentLabel.length), + ); + }); + } + + void handlePressed(MenuController controller) { + if (controller.isOpen) { + currentHighlight = null; + controller.close(); + } else { // close to open + if (_textEditingController.text.isNotEmpty) { + _enableFilter = false; + } + controller.open(); + } + setState(() {}); + } + + @override + Widget build(BuildContext context) { + final TextDirection textDirection = Directionality.of(context); + _initialMenu ??= _buildButtons(widget.dropdownMenuEntries, textDirection, enableScrollToHighlight: false); + final DropdownMenuThemeData theme = DropdownMenuTheme.of(context); + final DropdownMenuThemeData defaults = _DropdownMenuDefaultsM3(context); + + if (_enableFilter) { + filteredEntries = filter(widget.dropdownMenuEntries, _textEditingController); + } + + if (widget.enableSearch) { + if (widget.searchCallback != null) { + currentHighlight = widget.searchCallback!.call(filteredEntries, _textEditingController.text); + } else { + currentHighlight = search(filteredEntries, _textEditingController); + } + if (currentHighlight != null) { + scrollToHighlight(); + } + } + + final List<Widget> menu = _buildButtons(filteredEntries, textDirection, focusedIndex: currentHighlight); + + final TextStyle? effectiveTextStyle = widget.textStyle ?? theme.textStyle ?? defaults.textStyle; + + MenuStyle? effectiveMenuStyle = widget.menuStyle + ?? theme.menuStyle + ?? defaults.menuStyle!; + + final double? anchorWidth = getWidth(_anchorKey); + if (widget.width != null) { + effectiveMenuStyle = effectiveMenuStyle.copyWith(minimumSize: MaterialStatePropertyAll<Size?>(Size(widget.width!, 0.0))); + } else if (anchorWidth != null){ + effectiveMenuStyle = effectiveMenuStyle.copyWith(minimumSize: MaterialStatePropertyAll<Size?>(Size(anchorWidth, 0.0))); + } + + if (widget.menuHeight != null) { + effectiveMenuStyle = effectiveMenuStyle.copyWith(maximumSize: MaterialStatePropertyAll<Size>(Size(double.infinity, widget.menuHeight!))); + } + final InputDecorationTheme effectiveInputDecorationTheme = widget.inputDecorationTheme + ?? theme.inputDecorationTheme + ?? defaults.inputDecorationTheme!; + + final MouseCursor effectiveMouseCursor = canRequestFocus() ? SystemMouseCursors.text : SystemMouseCursors.click; + + Widget menuAnchor = MenuAnchor( + style: effectiveMenuStyle, + controller: _controller, + menuChildren: menu, + crossAxisUnconstrained: false, + builder: (BuildContext context, MenuController controller, Widget? child) { + assert(_initialMenu != null); + final Widget trailingButton = Padding( + padding: const EdgeInsets.all(4.0), + child: IconButton( + isSelected: controller.isOpen, + icon: widget.trailingIcon ?? const Icon(Icons.arrow_drop_down), + selectedIcon: widget.selectedTrailingIcon ?? const Icon(Icons.arrow_drop_up), + onPressed: () { + handlePressed(controller); + }, + ), + ); + + final Widget leadingButton = Padding( + padding: const EdgeInsets.all(8.0), + child: widget.leadingIcon ?? const SizedBox() + ); + + final Widget textField = TextField( + key: _anchorKey, + mouseCursor: effectiveMouseCursor, + canRequestFocus: canRequestFocus(), + enableInteractiveSelection: canRequestFocus(), + textAlignVertical: TextAlignVertical.center, + style: effectiveTextStyle, + controller: _textEditingController, + onEditingComplete: () { + if (currentHighlight != null) { + final DropdownMenuEntry<T> entry = filteredEntries[currentHighlight!]; + if (entry.enabled) { + _textEditingController.value = TextEditingValue( + text: entry.label, + selection: TextSelection.collapsed(offset: entry.label.length), + ); + widget.onSelected?.call(entry.value); + } + } else { + widget.onSelected?.call(null); + } + if (!widget.enableSearch) { + currentHighlight = null; + } + controller.close(); + }, + onTap: () { + handlePressed(controller); + }, + onChanged: (String text) { + controller.open(); + setState(() { + filteredEntries = widget.dropdownMenuEntries; + _enableFilter = widget.enableFilter; + }); + }, + decoration: InputDecoration( + enabled: widget.enabled, + label: widget.label, + hintText: widget.hintText, + helperText: widget.helperText, + errorText: widget.errorText, + prefixIcon: widget.leadingIcon != null ? Container( + key: _leadingKey, + child: widget.leadingIcon + ) : null, + suffixIcon: trailingButton, + ).applyDefaults(effectiveInputDecorationTheme) + ); + + if (widget.expandedInsets != null) { + // If [expandedInsets] is not null, the width of the text field should depend + // on its parent width. So we don't need to use `_DropdownMenuBody` to + // calculate the children's width. + return textField; + } + + return _DropdownMenuBody( + width: widget.width, + children: <Widget>[ + textField, + for (final Widget item in _initialMenu!) item, + trailingButton, + leadingButton, + ], + ); + }, + ); + + if (widget.expandedInsets != null) { + menuAnchor = Container( + alignment: AlignmentDirectional.topStart, + padding: widget.expandedInsets?.copyWith(top: 0.0, bottom: 0.0), + child: menuAnchor, + ); + } + + return Shortcuts( + shortcuts: _kMenuTraversalShortcuts, + child: Actions( + actions: <Type, Action<Intent>>{ + _ArrowUpIntent: CallbackAction<_ArrowUpIntent>( + onInvoke: handleUpKeyInvoke, + ), + _ArrowDownIntent: CallbackAction<_ArrowDownIntent>( + onInvoke: handleDownKeyInvoke, + ), + }, + child: menuAnchor, + ), + ); + } +} + +class _ArrowUpIntent extends Intent { + const _ArrowUpIntent(); +} + +class _ArrowDownIntent extends Intent { + const _ArrowDownIntent(); +} + +class _DropdownMenuBody extends MultiChildRenderObjectWidget { + const _DropdownMenuBody({ + super.children, + this.width, + }); + + final double? width; + + @override + _RenderDropdownMenuBody createRenderObject(BuildContext context) { + return _RenderDropdownMenuBody( + width: width, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderDropdownMenuBody renderObject) { + renderObject.width = width; + } +} + +class _DropdownMenuBodyParentData extends ContainerBoxParentData<RenderBox> { } + +class _RenderDropdownMenuBody extends RenderBox + with ContainerRenderObjectMixin<RenderBox, _DropdownMenuBodyParentData>, + RenderBoxContainerDefaultsMixin<RenderBox, _DropdownMenuBodyParentData> { + + _RenderDropdownMenuBody({ + double? width, + }) : _width = width; + + double? get width => _width; + double? _width; + set width(double? value) { + if (_width == value) { + return; + } + _width = value; + markNeedsLayout(); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! _DropdownMenuBodyParentData) { + child.parentData = _DropdownMenuBodyParentData(); + } + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + double maxWidth = 0.0; + double? maxHeight; + RenderBox? child = firstChild; + + final BoxConstraints innerConstraints = BoxConstraints( + maxWidth: width ?? computeMaxIntrinsicWidth(constraints.maxWidth), + maxHeight: computeMaxIntrinsicHeight(constraints.maxHeight), + ); + while (child != null) { + if (child == firstChild) { + child.layout(innerConstraints, parentUsesSize: true); + maxHeight ??= child.size.height; + final _DropdownMenuBodyParentData childParentData = child.parentData! as _DropdownMenuBodyParentData; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + continue; + } + child.layout(innerConstraints, parentUsesSize: true); + final _DropdownMenuBodyParentData childParentData = child.parentData! as _DropdownMenuBodyParentData; + childParentData.offset = Offset.zero; + maxWidth = math.max(maxWidth, child.size.width); + maxHeight ??= child.size.height; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + + assert(maxHeight != null); + maxWidth = math.max(_kMinimumWidth, maxWidth); + size = constraints.constrain(Size(width ?? maxWidth, maxHeight!)); + } + + @override + void paint(PaintingContext context, Offset offset) { + final RenderBox? child = firstChild; + if (child != null) { + final _DropdownMenuBodyParentData childParentData = child.parentData! as _DropdownMenuBodyParentData; + context.paintChild(child, offset + childParentData.offset); + } + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + final BoxConstraints constraints = this.constraints; + double maxWidth = 0.0; + double? maxHeight; + RenderBox? child = firstChild; + final BoxConstraints innerConstraints = BoxConstraints( + maxWidth: width ?? computeMaxIntrinsicWidth(constraints.maxWidth), + maxHeight: computeMaxIntrinsicHeight(constraints.maxHeight), + ); + + while (child != null) { + if (child == firstChild) { + final Size childSize = child.getDryLayout(innerConstraints); + maxHeight ??= childSize.height; + final _DropdownMenuBodyParentData childParentData = child.parentData! as _DropdownMenuBodyParentData; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + continue; + } + final Size childSize = child.getDryLayout(innerConstraints); + final _DropdownMenuBodyParentData childParentData = child.parentData! as _DropdownMenuBodyParentData; + childParentData.offset = Offset.zero; + maxWidth = math.max(maxWidth, childSize.width); + maxHeight ??= childSize.height; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + + assert(maxHeight != null); + maxWidth = math.max(_kMinimumWidth, maxWidth); + return constraints.constrain(Size(width ?? maxWidth, maxHeight!)); + } + + @override + double computeMinIntrinsicWidth(double height) { + RenderBox? child = firstChild; + double width = 0; + while (child != null) { + if (child == firstChild) { + final _DropdownMenuBodyParentData childParentData = child.parentData! as _DropdownMenuBodyParentData; + child = childParentData.nextSibling; + continue; + } + final double maxIntrinsicWidth = child.getMinIntrinsicWidth(height); + if (child == lastChild) { + width += maxIntrinsicWidth; + } + if (child == childBefore(lastChild!)) { + width += maxIntrinsicWidth; + } + width = math.max(width, maxIntrinsicWidth); + final _DropdownMenuBodyParentData childParentData = child.parentData! as _DropdownMenuBodyParentData; + child = childParentData.nextSibling; + } + + return math.max(width, _kMinimumWidth); + } + + @override + double computeMaxIntrinsicWidth(double height) { + RenderBox? child = firstChild; + double width = 0; + while (child != null) { + if (child == firstChild) { + final _DropdownMenuBodyParentData childParentData = child.parentData! as _DropdownMenuBodyParentData; + child = childParentData.nextSibling; + continue; + } + final double maxIntrinsicWidth = child.getMaxIntrinsicWidth(height); + // Add the width of leading Icon. + if (child == lastChild) { + width += maxIntrinsicWidth; + } + // Add the width of trailing Icon. + if (child == childBefore(lastChild!)) { + width += maxIntrinsicWidth; + } + width = math.max(width, maxIntrinsicWidth); + final _DropdownMenuBodyParentData childParentData = child.parentData! as _DropdownMenuBodyParentData; + child = childParentData.nextSibling; + } + + return math.max(width, _kMinimumWidth); + } + + @override + double computeMinIntrinsicHeight(double height) { + final RenderBox? child = firstChild; + double width = 0; + if (child != null) { + width = math.max(width, child.getMinIntrinsicHeight(height)); + } + return width; + } + + @override + double computeMaxIntrinsicHeight(double height) { + final RenderBox? child = firstChild; + double width = 0; + if (child != null) { + width = math.max(width, child.getMaxIntrinsicHeight(height)); + } + return width; + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + final RenderBox? child = firstChild; + if (child != null) { + final _DropdownMenuBodyParentData childParentData = child.parentData! as _DropdownMenuBodyParentData; + final bool isHit = result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - childParentData.offset); + return child.hitTest(result, position: transformed); + }, + ); + if (isHit) { + return true; + } + } + return false; + } +} + +// Hand coded defaults. These will be updated once we have tokens/spec. +class _DropdownMenuDefaultsM3 extends DropdownMenuThemeData { + _DropdownMenuDefaultsM3(this.context); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + + @override + TextStyle? get textStyle => _theme.textTheme.bodyLarge; + + @override + MenuStyle get menuStyle { + return const MenuStyle( + minimumSize: MaterialStatePropertyAll<Size>(Size(_kMinimumWidth, 0.0)), + maximumSize: MaterialStatePropertyAll<Size>(Size.infinite), + visualDensity: VisualDensity.standard, + ); + } + + @override + InputDecorationTheme get inputDecorationTheme { + return const InputDecorationTheme(border: OutlineInputBorder()); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dropdown_menu_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dropdown_menu_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..c2471ef6fccb9eb1c09a757dc7edf260c5b23e55 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/dropdown_menu_theme.dart @@ -0,0 +1,178 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; + +import 'input_decorator.dart'; +import 'menu_style.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Overrides the default values of visual properties for descendant [DropdownMenu] widgets. +/// +/// Descendant widgets obtain the current [DropdownMenuThemeData] object with +/// [DropdownMenuTheme.of]. Instances of [DropdownMenuTheme] can +/// be customized with [DropdownMenuThemeData.copyWith]. +/// +/// Typically a [DropdownMenuTheme] is specified as part of the overall [Theme] with +/// [ThemeData.dropdownMenuTheme]. +/// +/// All [DropdownMenuThemeData] properties are null by default. When null, the [DropdownMenu] +/// computes its own default values, typically based on the overall +/// theme's [ThemeData.colorScheme], [ThemeData.textTheme], and [ThemeData.iconTheme]. +@immutable +class DropdownMenuThemeData with Diagnosticable { + /// Creates a [DropdownMenuThemeData] that can be used to override default properties + /// in a [DropdownMenuTheme] widget. + const DropdownMenuThemeData({ + this.textStyle, + this.inputDecorationTheme, + this.menuStyle, + }); + + /// Overrides the default value for [DropdownMenu.textStyle]. + final TextStyle? textStyle; + + /// The input decoration theme for the [TextField]s in a [DropdownMenu]. + /// + /// If this is null, the [DropdownMenu] provides its own defaults. + final InputDecorationTheme? inputDecorationTheme; + + /// Overrides the menu's default style in a [DropdownMenu]. + /// + /// Any values not set in the [MenuStyle] will use the menu default for that + /// property. + final MenuStyle? menuStyle; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + DropdownMenuThemeData copyWith({ + TextStyle? textStyle, + InputDecorationTheme? inputDecorationTheme, + MenuStyle? menuStyle, + }) { + return DropdownMenuThemeData( + textStyle: textStyle ?? this.textStyle, + inputDecorationTheme: inputDecorationTheme ?? this.inputDecorationTheme, + menuStyle: menuStyle ?? this.menuStyle, + ); + } + + /// Linearly interpolates between two dropdown menu themes. + static DropdownMenuThemeData lerp(DropdownMenuThemeData? a, DropdownMenuThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return DropdownMenuThemeData( + textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t), + inputDecorationTheme: t < 0.5 ? a?.inputDecorationTheme : b?.inputDecorationTheme, + menuStyle: MenuStyle.lerp(a?.menuStyle, b?.menuStyle, t), + ); + } + + @override + int get hashCode => Object.hash( + textStyle, + inputDecorationTheme, + menuStyle, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is DropdownMenuThemeData + && other.textStyle == textStyle + && other.inputDecorationTheme == inputDecorationTheme + && other.menuStyle == menuStyle; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<TextStyle>('textStyle', textStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<InputDecorationTheme>('inputDecorationTheme', inputDecorationTheme, defaultValue: null)); + properties.add(DiagnosticsProperty<MenuStyle>('menuStyle', menuStyle, defaultValue: null)); + } +} + +/// An inherited widget that defines the visual properties for [DropdownMenu]s in this widget's subtree. +/// +/// Values specified here are used for [DropdownMenu] properties that are not +/// given an explicit non-null value. +class DropdownMenuTheme extends InheritedTheme { + /// Creates a [DropdownMenuTheme] that controls visual parameters for + /// descendant [DropdownMenu]s. + const DropdownMenuTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the visual properties used by descendant [DropdownMenu] + /// widgets. + final DropdownMenuThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [DropdownMenuTheme] widget, then + /// [ThemeData.dropdownMenuTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// DropdownMenuThemeData theme = DropdownMenuTheme.of(context); + /// ``` + /// + /// See also: + /// + /// * [maybeOf], which returns null if it doesn't find a + /// [DropdownMenuTheme] ancestor. + static DropdownMenuThemeData of(BuildContext context) { + return maybeOf(context) ?? Theme.of(context).dropdownMenuTheme; + } + + /// The data from the closest instance of this class that encloses the given + /// context, if any. + /// + /// Use this function if you want to allow situations where no + /// [DropdownMenuTheme] is in scope. Prefer using [DropdownMenuTheme.of] + /// in situations where a [DropdownMenuThemeData] is expected to be + /// non-null. + /// + /// If there is no [DropdownMenuTheme] in scope, then this function will + /// return null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// DropdownMenuThemeData? theme = DropdownMenuTheme.maybeOf(context); + /// if (theme == null) { + /// // Do something else instead. + /// } + /// ``` + /// + /// See also: + /// + /// * [of], which will return [ThemeData.dropdownMenuTheme] if it doesn't + /// find a [DropdownMenuTheme] ancestor, instead of returning null. + static DropdownMenuThemeData? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<DropdownMenuTheme>()?.data; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return DropdownMenuTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(DropdownMenuTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/elevated_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/elevated_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..f91c9a0928d3c90c0cb726fe4eebaba2edfeff4d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/elevated_button.dart @@ -0,0 +1,651 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'button_style_button.dart'; +import 'color_scheme.dart'; +import 'constants.dart'; +import 'elevated_button_theme.dart'; +import 'ink_ripple.dart'; +import 'ink_well.dart'; +import 'material_state.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +/// A Material Design "elevated button". +/// +/// Use elevated buttons to add dimension to otherwise mostly flat +/// layouts, e.g. in long busy lists of content, or in wide +/// spaces. Avoid using elevated buttons on already-elevated content +/// such as dialogs or cards. +/// +/// An elevated button is a label [child] displayed on a [Material] +/// widget whose [Material.elevation] increases when the button is +/// pressed. The label's [Text] and [Icon] widgets are displayed in +/// [style]'s [ButtonStyle.foregroundColor] and the button's filled +/// background is the [ButtonStyle.backgroundColor]. +/// +/// The elevated button's default style is defined by +/// [defaultStyleOf]. The style of this elevated button can be +/// overridden with its [style] parameter. The style of all elevated +/// buttons in a subtree can be overridden with the +/// [ElevatedButtonTheme], and the style of all of the elevated +/// buttons in an app can be overridden with the [Theme]'s +/// [ThemeData.elevatedButtonTheme] property. +/// +/// The static [styleFrom] method is a convenient way to create a +/// elevated button [ButtonStyle] from simple values. +/// +/// If [onPressed] and [onLongPress] callbacks are null, then the +/// button will be disabled. +/// +/// {@tool dartpad} +/// This sample produces an enabled and a disabled ElevatedButton. +/// +/// ** See code in examples/api/lib/material/elevated_button/elevated_button.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [FilledButton], a filled button that doesn't elevate when pressed. +/// * [FilledButton.tonal], a filled button variant that uses a secondary fill color. +/// * [OutlinedButton], a button with an outlined border and no fill color. +/// * [TextButton], a button with no outline or fill color. +/// * <https://material.io/design/components/buttons.html> +/// * <https://m3.material.io/components/buttons> +class ElevatedButton extends ButtonStyleButton { + /// Create an ElevatedButton. + const ElevatedButton({ + super.key, + required super.onPressed, + super.onLongPress, + super.onHover, + super.onFocusChange, + super.style, + super.focusNode, + super.autofocus = false, + super.clipBehavior = Clip.none, + super.statesController, + required super.child, + }); + + /// Create an elevated button from a pair of widgets that serve as the button's + /// [icon] and [label]. + /// + /// The icon and label are arranged in a row and padded by 12 logical pixels + /// at the start, and 16 at the end, with an 8 pixel gap in between. + factory ElevatedButton.icon({ + Key? key, + required VoidCallback? onPressed, + VoidCallback? onLongPress, + ValueChanged<bool>? onHover, + ValueChanged<bool>? onFocusChange, + ButtonStyle? style, + FocusNode? focusNode, + bool? autofocus, + Clip? clipBehavior, + MaterialStatesController? statesController, + required Widget icon, + required Widget label, + }) = _ElevatedButtonWithIcon; + + /// A static convenience method that constructs an elevated button + /// [ButtonStyle] given simple values. + /// + /// The [foregroundColor] and [disabledForegroundColor] colors are used + /// to create a [MaterialStateProperty] [ButtonStyle.foregroundColor], and + /// a derived [ButtonStyle.overlayColor]. + /// + /// The [backgroundColor] and [disabledBackgroundColor] colors are + /// used to create a [MaterialStateProperty] [ButtonStyle.backgroundColor]. + /// + /// The button's elevations are defined relative to the [elevation] + /// parameter. The disabled elevation is the same as the parameter + /// value, [elevation] + 2 is used when the button is hovered + /// or focused, and elevation + 6 is used when the button is pressed. + /// + /// Similarly, the [enabledMouseCursor] and [disabledMouseCursor] + /// parameters are used to construct [ButtonStyle].mouseCursor. + /// + /// All of the other parameters are either used directly or used to + /// create a [MaterialStateProperty] with a single value for all + /// states. + /// + /// All parameters default to null, by default this method returns + /// a [ButtonStyle] that doesn't override anything. + /// + /// For example, to override the default text and icon colors for a + /// [ElevatedButton], as well as its overlay color, with all of the + /// standard opacity adjustments for the pressed, focused, and + /// hovered states, one could write: + /// + /// ```dart + /// ElevatedButton( + /// style: ElevatedButton.styleFrom(foregroundColor: Colors.green), + /// onPressed: () { + /// // ... + /// }, + /// child: const Text('Jump'), + /// ), + /// ``` + /// + /// And to change the fill color: + /// + /// ```dart + /// ElevatedButton( + /// style: ElevatedButton.styleFrom(backgroundColor: Colors.green), + /// onPressed: () { + /// // ... + /// }, + /// child: const Text('Meow'), + /// ), + /// ``` + /// + static ButtonStyle styleFrom({ + Color? foregroundColor, + Color? backgroundColor, + Color? disabledForegroundColor, + Color? disabledBackgroundColor, + Color? shadowColor, + Color? surfaceTintColor, + double? elevation, + TextStyle? textStyle, + EdgeInsetsGeometry? padding, + Size? minimumSize, + Size? fixedSize, + Size? maximumSize, + BorderSide? side, + OutlinedBorder? shape, + MouseCursor? enabledMouseCursor, + MouseCursor? disabledMouseCursor, + VisualDensity? visualDensity, + MaterialTapTargetSize? tapTargetSize, + Duration? animationDuration, + bool? enableFeedback, + AlignmentGeometry? alignment, + InteractiveInkFeatureFactory? splashFactory, + }) { + final Color? background = backgroundColor; + final Color? disabledBackground = disabledBackgroundColor; + final MaterialStateProperty<Color?>? backgroundColorProp = (background == null && disabledBackground == null) + ? null + : _ElevatedButtonDefaultColor(background, disabledBackground); + final Color? foreground = foregroundColor; + final Color? disabledForeground = disabledForegroundColor; + final MaterialStateProperty<Color?>? foregroundColorProp = (foreground == null && disabledForeground == null) + ? null + : _ElevatedButtonDefaultColor(foreground, disabledForeground); + final MaterialStateProperty<Color?>? overlayColor = (foreground == null) + ? null + : _ElevatedButtonDefaultOverlay(foreground); + final MaterialStateProperty<double>? elevationValue = (elevation == null) + ? null + : _ElevatedButtonDefaultElevation(elevation); + final MaterialStateProperty<MouseCursor?> mouseCursor = _ElevatedButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor); + + return ButtonStyle( + textStyle: MaterialStatePropertyAll<TextStyle?>(textStyle), + backgroundColor: backgroundColorProp, + foregroundColor: foregroundColorProp, + overlayColor: overlayColor, + shadowColor: ButtonStyleButton.allOrNull<Color>(shadowColor), + surfaceTintColor: ButtonStyleButton.allOrNull<Color>(surfaceTintColor), + elevation: elevationValue, + padding: ButtonStyleButton.allOrNull<EdgeInsetsGeometry>(padding), + minimumSize: ButtonStyleButton.allOrNull<Size>(minimumSize), + fixedSize: ButtonStyleButton.allOrNull<Size>(fixedSize), + maximumSize: ButtonStyleButton.allOrNull<Size>(maximumSize), + side: ButtonStyleButton.allOrNull<BorderSide>(side), + shape: ButtonStyleButton.allOrNull<OutlinedBorder>(shape), + mouseCursor: mouseCursor, + visualDensity: visualDensity, + tapTargetSize: tapTargetSize, + animationDuration: animationDuration, + enableFeedback: enableFeedback, + alignment: alignment, + splashFactory: splashFactory, + ); + } + + /// Defines the button's default appearance. + /// + /// The button [child]'s [Text] and [Icon] widgets are rendered with + /// the [ButtonStyle]'s foreground color. The button's [InkWell] adds + /// the style's overlay color when the button is focused, hovered + /// or pressed. The button's background color becomes its [Material] + /// color. + /// + /// All of the ButtonStyle's defaults appear below. In this list + /// "Theme.foo" is shorthand for `Theme.of(context).foo`. Color + /// scheme values like "onSurface(0.38)" are shorthand for + /// `onSurface.withOpacity(0.38)`. [MaterialStateProperty] valued + /// properties that are not followed by a sublist have the same + /// value for all states, otherwise the values are as specified for + /// each state, and "others" means all other states. + /// + /// {@template flutter.material.elevated_button.default_font_size} + /// The "default font size" below refers to the font size specified in the + /// [defaultStyleOf] method (or 14.0 if unspecified), scaled by the + /// `MediaQuery.textScalerOf(context).scale` method. The names of the + /// EdgeInsets constructors and `EdgeInsetsGeometry.lerp` have been abbreviated + /// for readability. + /// {@endtemplate} + /// + /// The color of the [ButtonStyle.textStyle] is not used, the + /// [ButtonStyle.foregroundColor] color is used instead. + /// + /// ## Material 2 defaults + /// + /// * `textStyle` - Theme.textTheme.button + /// * `backgroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.12) + /// * others - Theme.colorScheme.primary + /// * `foregroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.38) + /// * others - Theme.colorScheme.onPrimary + /// * `overlayColor` + /// * hovered - Theme.colorScheme.onPrimary(0.08) + /// * focused or pressed - Theme.colorScheme.onPrimary(0.24) + /// * `shadowColor` - Theme.shadowColor + /// * `elevation` + /// * disabled - 0 + /// * default - 2 + /// * hovered or focused - 4 + /// * pressed - 8 + /// * `padding` + /// * `default font size <= 14` - horizontal(16) + /// * `14 < default font size <= 28` - lerp(horizontal(16), horizontal(8)) + /// * `28 < default font size <= 36` - lerp(horizontal(8), horizontal(4)) + /// * `36 < default font size` - horizontal(4) + /// * `minimumSize` - Size(64, 36) + /// * `fixedSize` - null + /// * `maximumSize` - Size.infinite + /// * `side` - null + /// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)) + /// * `mouseCursor` + /// * disabled - SystemMouseCursors.basic + /// * others - SystemMouseCursors.click + /// * `visualDensity` - theme.visualDensity + /// * `tapTargetSize` - theme.materialTapTargetSize + /// * `animationDuration` - kThemeChangeDuration + /// * `enableFeedback` - true + /// * `alignment` - Alignment.center + /// * `splashFactory` - InkRipple.splashFactory + /// + /// The default padding values for the [ElevatedButton.icon] factory are slightly different: + /// + /// * `padding` + /// * `default font size <= 14` - start(12) end(16) + /// * `14 < default font size <= 28` - lerp(start(12) end(16), horizontal(8)) + /// * `28 < default font size <= 36` - lerp(horizontal(8), horizontal(4)) + /// * `36 < default font size` - horizontal(4) + /// + /// The default value for `side`, which defines the appearance of the button's + /// outline, is null. That means that the outline is defined by the button + /// shape's [OutlinedBorder.side]. Typically the default value of an + /// [OutlinedBorder]'s side is [BorderSide.none], so an outline is not drawn. + /// + /// ## Material 3 defaults + /// + /// If [ThemeData.useMaterial3] is set to true the following defaults will + /// be used: + /// + /// * `textStyle` - Theme.textTheme.labelLarge + /// * `backgroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.12) + /// * others - Theme.colorScheme.surface + /// * `foregroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.38) + /// * others - Theme.colorScheme.primary + /// * `overlayColor` + /// * hovered - Theme.colorScheme.primary(0.08) + /// * focused or pressed - Theme.colorScheme.primary(0.12) + /// * `shadowColor` - Theme.colorScheme.shadow + /// * `surfaceTintColor` - Theme.colorScheme.surfaceTint + /// * `elevation` + /// * disabled - 0 + /// * default - 1 + /// * hovered - 3 + /// * focused or pressed - 1 + /// * `padding` + /// * `default font size <= 14` - horizontal(24) + /// * `14 < default font size <= 28` - lerp(horizontal(24), horizontal(12)) + /// * `28 < default font size <= 36` - lerp(horizontal(12), horizontal(6)) + /// * `36 < default font size` - horizontal(6) + /// * `minimumSize` - Size(64, 40) + /// * `fixedSize` - null + /// * `maximumSize` - Size.infinite + /// * `side` - null + /// * `shape` - StadiumBorder() + /// * `mouseCursor` + /// * disabled - SystemMouseCursors.basic + /// * others - SystemMouseCursors.click + /// * `visualDensity` - Theme.visualDensity + /// * `tapTargetSize` - Theme.materialTapTargetSize + /// * `animationDuration` - kThemeChangeDuration + /// * `enableFeedback` - true + /// * `alignment` - Alignment.center + /// * `splashFactory` - Theme.splashFactory + /// + /// For the [ElevatedButton.icon] factory, the start (generally the left) value of + /// [padding] is reduced from 24 to 16. + + @override + ButtonStyle defaultStyleOf(BuildContext context) { + final ThemeData theme = Theme.of(context); + final ColorScheme colorScheme = theme.colorScheme; + + return Theme.of(context).useMaterial3 + ? _ElevatedButtonDefaultsM3(context) + : styleFrom( + backgroundColor: colorScheme.primary, + foregroundColor: colorScheme.onPrimary, + disabledBackgroundColor: colorScheme.onSurface.withOpacity(0.12), + disabledForegroundColor: colorScheme.onSurface.withOpacity(0.38), + shadowColor: theme.shadowColor, + elevation: 2, + textStyle: theme.textTheme.labelLarge, + padding: _scaledPadding(context), + minimumSize: const Size(64, 36), + maximumSize: Size.infinite, + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))), + enabledMouseCursor: SystemMouseCursors.click, + disabledMouseCursor: SystemMouseCursors.basic, + visualDensity: theme.visualDensity, + tapTargetSize: theme.materialTapTargetSize, + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + splashFactory: InkRipple.splashFactory, + ); + } + + /// Returns the [ElevatedButtonThemeData.style] of the closest + /// [ElevatedButtonTheme] ancestor. + @override + ButtonStyle? themeStyleOf(BuildContext context) { + return ElevatedButtonTheme.of(context).style; + } +} + +EdgeInsetsGeometry _scaledPadding(BuildContext context) { + final ThemeData theme = Theme.of(context); + final double padding1x = theme.useMaterial3 ? 24.0 : 16.0; + final double defaultFontSize = theme.textTheme.labelLarge?.fontSize ?? 14.0; + final double effectiveTextScale = MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0; + + return ButtonStyleButton.scaledPadding( + EdgeInsets.symmetric(horizontal: padding1x), + EdgeInsets.symmetric(horizontal: padding1x / 2), + EdgeInsets.symmetric(horizontal: padding1x / 2 / 2), + effectiveTextScale, + ); +} + +@immutable +class _ElevatedButtonDefaultColor extends MaterialStateProperty<Color?> with Diagnosticable { + _ElevatedButtonDefaultColor(this.color, this.disabled); + + final Color? color; + final Color? disabled; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabled; + } + return color; + } +} + +@immutable +class _ElevatedButtonDefaultOverlay extends MaterialStateProperty<Color?> with Diagnosticable { + _ElevatedButtonDefaultOverlay(this.overlay); + + final Color overlay; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return overlay.withOpacity(0.24); + } + if (states.contains(MaterialState.hovered)) { + return overlay.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return overlay.withOpacity(0.24); + } + return null; + } +} + +@immutable +class _ElevatedButtonDefaultElevation extends MaterialStateProperty<double> with Diagnosticable { + _ElevatedButtonDefaultElevation(this.elevation); + + final double elevation; + + @override + double resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return 0; + } + if (states.contains(MaterialState.pressed)) { + return elevation + 6; + } + if (states.contains(MaterialState.hovered)) { + return elevation + 2; + } + if (states.contains(MaterialState.focused)) { + return elevation + 2; + } + return elevation; + } +} + +@immutable +class _ElevatedButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor?> with Diagnosticable { + _ElevatedButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor); + + final MouseCursor? enabledCursor; + final MouseCursor? disabledCursor; + + @override + MouseCursor? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabledCursor; + } + return enabledCursor; + } +} + +class _ElevatedButtonWithIcon extends ElevatedButton { + _ElevatedButtonWithIcon({ + super.key, + required super.onPressed, + super.onLongPress, + super.onHover, + super.onFocusChange, + super.style, + super.focusNode, + bool? autofocus, + Clip? clipBehavior, + super.statesController, + required Widget icon, + required Widget label, + }) : super( + autofocus: autofocus ?? false, + clipBehavior: clipBehavior ?? Clip.none, + child: _ElevatedButtonWithIconChild(icon: icon, label: label), + ); + + @override + ButtonStyle defaultStyleOf(BuildContext context) { + final bool useMaterial3 = Theme.of(context).useMaterial3; + final ButtonStyle buttonStyle = super.defaultStyleOf(context); + final double defaultFontSize = buttonStyle.textStyle?.resolve(const <MaterialState>{})?.fontSize ?? 14.0; + final double effectiveTextScale = MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0; + + final EdgeInsetsGeometry scaledPadding = useMaterial3 + ? ButtonStyleButton.scaledPadding( + const EdgeInsetsDirectional.fromSTEB(16, 0, 24, 0), + const EdgeInsetsDirectional.fromSTEB(8, 0, 12, 0), + const EdgeInsetsDirectional.fromSTEB(4, 0, 6, 0), + effectiveTextScale, + ) : ButtonStyleButton.scaledPadding( + const EdgeInsetsDirectional.fromSTEB(12, 0, 16, 0), + const EdgeInsets.symmetric(horizontal: 8), + const EdgeInsetsDirectional.fromSTEB(8, 0, 4, 0), + effectiveTextScale, + ); + return buttonStyle.copyWith( + padding: MaterialStatePropertyAll<EdgeInsetsGeometry>(scaledPadding), + ); + } +} + +class _ElevatedButtonWithIconChild extends StatelessWidget { + const _ElevatedButtonWithIconChild({ required this.label, required this.icon }); + + final Widget label; + final Widget icon; + + @override + Widget build(BuildContext context) { + final double scale = MediaQuery.textScalerOf(context).textScaleFactor; + final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!; + return Row( + mainAxisSize: MainAxisSize.min, + children: <Widget>[icon, SizedBox(width: gap), Flexible(child: label)], + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - ElevatedButton + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _ElevatedButtonDefaultsM3 extends ButtonStyle { + _ElevatedButtonDefaultsM3(this.context) + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + MaterialStateProperty<TextStyle?> get textStyle => + MaterialStatePropertyAll<TextStyle?>(Theme.of(context).textTheme.labelLarge); + + @override + MaterialStateProperty<Color?>? get backgroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.12); + } + return _colors.surface; + }); + + @override + MaterialStateProperty<Color?>? get foregroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + return _colors.primary; + }); + + @override + MaterialStateProperty<Color?>? get overlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.primary.withOpacity(0.12); + } + return null; + }); + + @override + MaterialStateProperty<Color>? get shadowColor => + MaterialStatePropertyAll<Color>(_colors.shadow); + + @override + MaterialStateProperty<Color>? get surfaceTintColor => + MaterialStatePropertyAll<Color>(_colors.surfaceTint); + + @override + MaterialStateProperty<double>? get elevation => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return 0.0; + } + if (states.contains(MaterialState.pressed)) { + return 1.0; + } + if (states.contains(MaterialState.hovered)) { + return 3.0; + } + if (states.contains(MaterialState.focused)) { + return 1.0; + } + return 1.0; + }); + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding => + MaterialStatePropertyAll<EdgeInsetsGeometry>(_scaledPadding(context)); + + @override + MaterialStateProperty<Size>? get minimumSize => + const MaterialStatePropertyAll<Size>(Size(64.0, 40.0)); + + // No default fixedSize + + @override + MaterialStateProperty<Size>? get maximumSize => + const MaterialStatePropertyAll<Size>(Size.infinite); + + // No default side + + @override + MaterialStateProperty<OutlinedBorder>? get shape => + const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); + + @override + MaterialStateProperty<MouseCursor?>? get mouseCursor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return SystemMouseCursors.click; + }); + + @override + VisualDensity? get visualDensity => Theme.of(context).visualDensity; + + @override + MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize; + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; +} + +// END GENERATED TOKEN PROPERTIES - ElevatedButton diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/elevated_button_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/elevated_button_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..bc2b93a778abf1dac8d0ab3e3adb375585f88271 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/elevated_button_theme.dart @@ -0,0 +1,125 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// A [ButtonStyle] that overrides the default appearance of +/// [ElevatedButton]s when it's used with [ElevatedButtonTheme] or with the +/// overall [Theme]'s [ThemeData.elevatedButtonTheme]. +/// +/// The [style]'s properties override [ElevatedButton]'s default style, +/// i.e. the [ButtonStyle] returned by [ElevatedButton.defaultStyleOf]. Only +/// the style's non-null property values or resolved non-null +/// [MaterialStateProperty] values are used. +/// +/// See also: +/// +/// * [ElevatedButtonTheme], the theme which is configured with this class. +/// * [ElevatedButton.defaultStyleOf], which returns the default [ButtonStyle] +/// for text buttons. +/// * [ElevatedButton.styleFrom], which converts simple values into a +/// [ButtonStyle] that's consistent with [ElevatedButton]'s defaults. +/// * [MaterialStateProperty.resolve], "resolve" a material state property +/// to a simple value based on a set of [MaterialState]s. +/// * [ThemeData.elevatedButtonTheme], which can be used to override the default +/// [ButtonStyle] for [ElevatedButton]s below the overall [Theme]. +@immutable +class ElevatedButtonThemeData with Diagnosticable { + /// Creates an [ElevatedButtonThemeData]. + /// + /// The [style] may be null. + const ElevatedButtonThemeData({ this.style }); + + /// Overrides for [ElevatedButton]'s default style. + /// + /// Non-null properties or non-null resolved [MaterialStateProperty] + /// values override the [ButtonStyle] returned by + /// [ElevatedButton.defaultStyleOf]. + /// + /// If [style] is null, then this theme doesn't override anything. + final ButtonStyle? style; + + /// Linearly interpolate between two elevated button themes. + static ElevatedButtonThemeData? lerp(ElevatedButtonThemeData? a, ElevatedButtonThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return ElevatedButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + ); + } + + @override + int get hashCode => style.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ElevatedButtonThemeData && other.style == style; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ButtonStyle>('style', style, defaultValue: null)); + } +} + +/// Overrides the default [ButtonStyle] of its [ElevatedButton] descendants. +/// +/// See also: +/// +/// * [ElevatedButtonThemeData], which is used to configure this theme. +/// * [ElevatedButton.defaultStyleOf], which returns the default [ButtonStyle] +/// for elevated buttons. +/// * [ElevatedButton.styleFrom], which converts simple values into a +/// [ButtonStyle] that's consistent with [ElevatedButton]'s defaults. +/// * [ThemeData.elevatedButtonTheme], which can be used to override the default +/// [ButtonStyle] for [ElevatedButton]s below the overall [Theme]. +class ElevatedButtonTheme extends InheritedTheme { + /// Create a [ElevatedButtonTheme]. + const ElevatedButtonTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The configuration of this theme. + final ElevatedButtonThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [ElevatedButtonTheme] widget, then + /// [ThemeData.elevatedButtonTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ElevatedButtonThemeData theme = ElevatedButtonTheme.of(context); + /// ``` + static ElevatedButtonThemeData of(BuildContext context) { + final ElevatedButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<ElevatedButtonTheme>(); + return buttonTheme?.data ?? Theme.of(context).elevatedButtonTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return ElevatedButtonTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(ElevatedButtonTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/elevation_overlay.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/elevation_overlay.dart new file mode 100644 index 0000000000000000000000000000000000000000..24fcbd34b131d70242f3f2881ecd4633d968e1d3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/elevation_overlay.dart @@ -0,0 +1,172 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'theme.dart'; + +/// A utility class for dealing with the overlay color needed +/// to indicate elevation of surfaces. +abstract final class ElevationOverlay { + /// Applies a surface tint color to a given container color to indicate + /// the level of its elevation. + /// + /// With Material Design 3, some components will use a "surface tint" color + /// overlay with an opacity applied to their base color to indicate they are + /// elevated. The amount of opacity will vary with the elevation as described + /// in: https://m3.material.io/styles/color/the-color-system/color-roles. + /// + /// If [surfaceTint] is not null and not completely transparent ([Color.alpha] + /// is 0), then the returned color will be the given [color] with the + /// [surfaceTint] of the appropriate opacity applied to it. Otherwise it will + /// just return [color] unmodified. + static Color applySurfaceTint(Color color, Color? surfaceTint, double elevation) { + if (surfaceTint != null && surfaceTint != Colors.transparent) { + return Color.alphaBlend(surfaceTint.withOpacity(_surfaceTintOpacityForElevation(elevation)), color); + } + return color; + } + + // Calculates the opacity of the surface tint color from the elevation by + // looking it up in the token generated table of opacities, interpolating + // between values as needed. If the elevation is outside the range of values + // in the table it will clamp to the smallest or largest opacity. + static double _surfaceTintOpacityForElevation(double elevation) { + if (elevation < _surfaceTintElevationOpacities[0].elevation) { + // Elevation less than the first entry, so just clamp it to the first one. + return _surfaceTintElevationOpacities[0].opacity; + } + + // Walk the opacity list and find the closest match(es) for the elevation. + int index = 0; + while (elevation >= _surfaceTintElevationOpacities[index].elevation) { + // If we found it exactly or walked off the end of the list just return it. + if (elevation == _surfaceTintElevationOpacities[index].elevation || + index + 1 == _surfaceTintElevationOpacities.length) { + return _surfaceTintElevationOpacities[index].opacity; + } + index += 1; + } + + // Interpolate between the two opacity values + final _ElevationOpacity lower = _surfaceTintElevationOpacities[index - 1]; + final _ElevationOpacity upper = _surfaceTintElevationOpacities[index]; + final double t = (elevation - lower.elevation) / (upper.elevation - lower.elevation); + return lower.opacity + t * (upper.opacity - lower.opacity); + } + + /// Applies an overlay color to a surface color to indicate + /// the level of its elevation in a dark theme. + /// + /// If using Material Design 3, this type of color overlay is no longer used. + /// Instead a "surface tint" overlay is used instead. See [applySurfaceTint], + /// [ThemeData.useMaterial3] for more information. + /// + /// Material drop shadows can be difficult to see in a dark theme, so the + /// elevation of a surface should be portrayed with an "overlay" in addition + /// to the shadow. As the elevation of the component increases, the + /// overlay increases in opacity. This function computes and applies this + /// overlay to a given color as needed. + /// + /// If the ambient theme is dark ([ThemeData.brightness] is [Brightness.dark]), + /// and [ThemeData.applyElevationOverlayColor] is true, and the given + /// [color] is [ColorScheme.surface] then this will return a version of + /// the [color] with a semi-transparent [ColorScheme.onSurface] overlaid + /// on top of it. The opacity of the overlay is computed based on the + /// [elevation]. + /// + /// Otherwise it will just return the [color] unmodified. + /// + /// See also: + /// + /// * [ThemeData.applyElevationOverlayColor] which controls the whether + /// an overlay color will be applied to indicate elevation. + /// * [overlayColor] which computes the needed overlay color. + /// * [Material] which uses this to apply an elevation overlay to its surface. + /// * <https://material.io/design/color/dark-theme.html>, which specifies how + /// the overlay should be applied. + static Color applyOverlay(BuildContext context, Color color, double elevation) { + final ThemeData theme = Theme.of(context); + if (elevation > 0.0 && + theme.applyElevationOverlayColor && + theme.brightness == Brightness.dark && + color.withOpacity(1.0) == theme.colorScheme.surface.withOpacity(1.0)) { + return colorWithOverlay(color, theme.colorScheme.onSurface, elevation); + } + return color; + } + + /// Computes the appropriate overlay color used to indicate elevation in + /// dark themes. + /// + /// If using Material Design 3, this type of color overlay is no longer used. + /// Instead a "surface tint" overlay is used instead. See [applySurfaceTint], + /// [ThemeData.useMaterial3] for more information. + /// + /// See also: + /// + /// * https://material.io/design/color/dark-theme.html#properties which + /// specifies the exact overlay values for a given elevation. + static Color overlayColor(BuildContext context, double elevation) { + final ThemeData theme = Theme.of(context); + return _overlayColor(theme.colorScheme.onSurface, elevation); + } + + /// Returns a color blended by laying a semi-transparent overlay (using the + /// [overlay] color) on top of a surface (using the [surface] color). + /// + /// If using Material Design 3, this type of color overlay is no longer used. + /// Instead a "surface tint" overlay is used instead. See [applySurfaceTint], + /// [ThemeData.useMaterial3] for more information. + /// + /// The opacity of the overlay depends on [elevation]. As [elevation] + /// increases, the opacity will also increase. + /// + /// See https://material.io/design/color/dark-theme.html#properties. + static Color colorWithOverlay(Color surface, Color overlay, double elevation) { + return Color.alphaBlend(_overlayColor(overlay, elevation), surface); + } + + /// Applies an opacity to [color] based on [elevation]. + static Color _overlayColor(Color color, double elevation) { + // Compute the opacity for the given elevation + // This formula matches the values in the spec: + // https://material.io/design/color/dark-theme.html#properties + final double opacity = (4.5 * math.log(elevation + 1) + 2) / 100.0; + return color.withOpacity(opacity); + } +} + +// A data class to hold the opacity at a given elevation. +class _ElevationOpacity { + const _ElevationOpacity(this.elevation, this.opacity); + + final double elevation; + final double opacity; +} + +// BEGIN GENERATED TOKEN PROPERTIES - SurfaceTint + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +// Surface tint opacities based on elevations according to the +// Material Design 3 specification: +// https://m3.material.io/styles/color/the-color-system/color-roles +// Ordered by increasing elevation. +const List<_ElevationOpacity> _surfaceTintElevationOpacities = <_ElevationOpacity>[ + _ElevationOpacity(0.0, 0.0), // Elevation level 0 + _ElevationOpacity(1.0, 0.05), // Elevation level 1 + _ElevationOpacity(3.0, 0.08), // Elevation level 2 + _ElevationOpacity(6.0, 0.11), // Elevation level 3 + _ElevationOpacity(8.0, 0.12), // Elevation level 4 + _ElevationOpacity(12.0, 0.14), // Elevation level 5 +]; + +// END GENERATED TOKEN PROPERTIES - SurfaceTint diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expand_icon.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expand_icon.dart new file mode 100644 index 0000000000000000000000000000000000000000..7672223655d49bc9c03910c28ae9ddb91f28c29f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expand_icon.dart @@ -0,0 +1,185 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'debug.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'material_localizations.dart'; +import 'theme.dart'; + +/// A widget representing a rotating expand/collapse button. The icon rotates +/// 180 degrees when pressed, then reverts the animation on a second press. +/// The underlying icon is [Icons.expand_more]. +/// +/// The expand icon does not include a semantic label for accessibility. In +/// order to be accessible it should be combined with a label using +/// [MergeSemantics]. This is done automatically by the [ExpansionPanel] widget. +/// +/// See [IconButton] for a more general implementation of a pressable button +/// with an icon. +/// +/// See also: +/// +/// * https://material.io/design/iconography/system-icons.html +class ExpandIcon extends StatefulWidget { + /// Creates an [ExpandIcon] with the given padding, and a callback that is + /// triggered when the icon is pressed. + const ExpandIcon({ + super.key, + this.isExpanded = false, + this.size = 24.0, + required this.onPressed, + this.padding = const EdgeInsets.all(8.0), + this.color, + this.disabledColor, + this.expandedColor, + }); + + /// Whether the icon is in an expanded state. + /// + /// Rebuilding the widget with a different [isExpanded] value will trigger + /// the animation, but will not trigger the [onPressed] callback. + final bool isExpanded; + + /// The size of the icon. + /// + /// Defaults to 24. + final double size; + + /// The callback triggered when the icon is pressed and the state changes + /// between expanded and collapsed. The value passed to the current state. + /// + /// If this is set to null, the button will be disabled. + final ValueChanged<bool>? onPressed; + + /// The padding around the icon. The entire padded icon will react to input + /// gestures. + /// + /// Defaults to a padding of 8 on all sides. + final EdgeInsetsGeometry padding; + + /// {@template flutter.material.ExpandIcon.color} + /// The color of the icon. + /// + /// Defaults to [Colors.black54] when the theme's + /// [ThemeData.brightness] is [Brightness.light] and to + /// [Colors.white60] when it is [Brightness.dark]. This adheres to the + /// Material Design specifications for [icons](https://material.io/design/iconography/system-icons.html#color) + /// and for [dark theme](https://material.io/design/color/dark-theme.html#ui-application) + /// {@endtemplate} + final Color? color; + + /// The color of the icon when it is disabled, + /// i.e. if [onPressed] is null. + /// + /// Defaults to [Colors.black38] when the theme's + /// [ThemeData.brightness] is [Brightness.light] and to + /// [Colors.white38] when it is [Brightness.dark]. This adheres to the + /// Material Design specifications for [icons](https://material.io/design/iconography/system-icons.html#color) + /// and for [dark theme](https://material.io/design/color/dark-theme.html#ui-application) + final Color? disabledColor; + + /// The color of the icon when the icon is expanded. + /// + /// Defaults to [Colors.black54] when the theme's + /// [ThemeData.brightness] is [Brightness.light] and to + /// [Colors.white] when it is [Brightness.dark]. This adheres to the + /// Material Design specifications for [icons](https://material.io/design/iconography/system-icons.html#color) + /// and for [dark theme](https://material.io/design/color/dark-theme.html#ui-application) + final Color? expandedColor; + + @override + State<ExpandIcon> createState() => _ExpandIconState(); +} + +class _ExpandIconState extends State<ExpandIcon> with SingleTickerProviderStateMixin { + late AnimationController _controller; + late Animation<double> _iconTurns; + + static final Animatable<double> _iconTurnTween = Tween<double>(begin: 0.0, end: 0.5) + .chain(CurveTween(curve: Curves.fastOutSlowIn)); + + @override + void initState() { + super.initState(); + _controller = AnimationController(duration: kThemeAnimationDuration, vsync: this); + _iconTurns = _controller.drive(_iconTurnTween); + // If the widget is initially expanded, rotate the icon without animating it. + if (widget.isExpanded) { + _controller.value = math.pi; + } + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + void didUpdateWidget(ExpandIcon oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.isExpanded != oldWidget.isExpanded) { + if (widget.isExpanded) { + _controller.forward(); + } else { + _controller.reverse(); + } + } + } + + void _handlePressed() { + widget.onPressed?.call(widget.isExpanded); + } + + /// Default icon colors and opacities for when [Theme.brightness] is set to + /// [Brightness.light] are based on the + /// [Material Design system icon specifications](https://material.io/design/iconography/system-icons.html#color). + /// Icon colors and opacities for [Brightness.dark] are based on the + /// [Material Design dark theme specifications](https://material.io/design/color/dark-theme.html#ui-application) + Color get _iconColor { + if (widget.isExpanded && widget.expandedColor != null) { + return widget.expandedColor!; + } + + if (widget.color != null) { + return widget.color!; + } + + switch (Theme.of(context).brightness) { + case Brightness.light: + return Colors.black54; + case Brightness.dark: + return Colors.white60; + } + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMaterialLocalizations(context)); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final String onTapHint = widget.isExpanded ? localizations.expandedIconTapHint : localizations.collapsedIconTapHint; + + return Semantics( + onTapHint: widget.onPressed == null ? null : onTapHint, + child: IconButton( + padding: widget.padding, + iconSize: widget.size, + color: _iconColor, + disabledColor: widget.disabledColor, + onPressed: widget.onPressed == null ? null : _handlePressed, + icon: RotationTransition( + turns: _iconTurns, + child: const Icon(Icons.expand_more), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expansion_panel.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expansion_panel.dart new file mode 100644 index 0000000000000000000000000000000000000000..95eb2ad7ee801859054ea99e6d41e14d0fab774d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expansion_panel.dart @@ -0,0 +1,438 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'constants.dart'; +import 'expand_icon.dart'; +import 'ink_well.dart'; +import 'material_localizations.dart'; +import 'mergeable_material.dart'; +import 'shadows.dart'; +import 'theme.dart'; + +const double _kPanelHeaderCollapsedHeight = kMinInteractiveDimension; +const EdgeInsets _kPanelHeaderExpandedDefaultPadding = EdgeInsets.symmetric( + vertical: 64.0 - _kPanelHeaderCollapsedHeight, +); +const EdgeInsets _kExpandIconPadding = EdgeInsets.all(12.0); + +class _SaltedKey<S, V> extends LocalKey { + const _SaltedKey(this.salt, this.value); + + final S salt; + final V value; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _SaltedKey<S, V> + && other.salt == salt + && other.value == value; + } + + @override + int get hashCode => Object.hash(runtimeType, salt, value); + + @override + String toString() { + final String saltString = S == String ? "<'$salt'>" : '<$salt>'; + final String valueString = V == String ? "<'$value'>" : '<$value>'; + return '[$saltString $valueString]'; + } +} + +/// Signature for the callback that's called when an [ExpansionPanel] is +/// expanded or collapsed. +/// +/// The position of the panel within an [ExpansionPanelList] is given by +/// [panelIndex]. +typedef ExpansionPanelCallback = void Function(int panelIndex, bool isExpanded); + +/// Signature for the callback that's called when the header of the +/// [ExpansionPanel] needs to rebuild. +typedef ExpansionPanelHeaderBuilder = Widget Function(BuildContext context, bool isExpanded); + +/// A material expansion panel. It has a header and a body and can be either +/// expanded or collapsed. The body of the panel is only visible when it is +/// expanded. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=2aJZzRMziJc} +/// +/// Expansion panels are only intended to be used as children for +/// [ExpansionPanelList]. +/// +/// See [ExpansionPanelList] for a sample implementation. +/// +/// See also: +/// +/// * [ExpansionPanelList] +/// * <https://material.io/design/components/lists.html#types> +class ExpansionPanel { + /// Creates an expansion panel to be used as a child for [ExpansionPanelList]. + /// See [ExpansionPanelList] for an example on how to use this widget. + ExpansionPanel({ + required this.headerBuilder, + required this.body, + this.isExpanded = false, + this.canTapOnHeader = false, + this.backgroundColor, + }); + + /// The widget builder that builds the expansion panels' header. + final ExpansionPanelHeaderBuilder headerBuilder; + + /// The body of the expansion panel that's displayed below the header. + /// + /// This widget is visible only when the panel is expanded. + final Widget body; + + /// Whether the panel is expanded. + /// + /// Defaults to false. + final bool isExpanded; + + /// Whether tapping on the panel's header will expand/collapse it. + /// + /// Defaults to false. + final bool canTapOnHeader; + + /// Defines the background color of the panel. + /// + /// Defaults to [ThemeData.cardColor]. + final Color? backgroundColor; +} + +/// An expansion panel that allows for radio-like functionality. +/// This means that at any given time, at most, one [ExpansionPanelRadio] +/// can remain expanded. +/// +/// A unique identifier [value] must be assigned to each panel. +/// This identifier allows the [ExpansionPanelList] to determine +/// which [ExpansionPanelRadio] instance should be expanded. +/// +/// See [ExpansionPanelList.radio] for a sample implementation. +class ExpansionPanelRadio extends ExpansionPanel { + /// An expansion panel that allows for radio functionality. + /// + /// A unique [value] must be passed into the constructor. + ExpansionPanelRadio({ + required this.value, + required super.headerBuilder, + required super.body, + super.canTapOnHeader, + super.backgroundColor, + }); + + /// The value that uniquely identifies a radio panel so that the currently + /// selected radio panel can be identified. + final Object value; +} + +/// A material expansion panel list that lays out its children and animates +/// expansions. +/// +/// The [expansionCallback] is called when the expansion state changes. For +/// normal [ExpansionPanelList] widgets, it is the responsibility of the parent +/// widget to rebuild the [ExpansionPanelList] with updated values for +/// [ExpansionPanel.isExpanded]. For [ExpansionPanelList.radio] widgets, the +/// open state is tracked internally and the callback is invoked both for the +/// previously open panel, which is closing, and the previously closed panel, +/// which is opening. +/// +/// {@tool dartpad} +/// Here is a simple example of how to use [ExpansionPanelList]. +/// +/// ** See code in examples/api/lib/material/expansion_panel/expansion_panel_list.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ExpansionPanel], which is used in the [children] property. +/// * [ExpansionPanelList.radio], a variant of this widget where only one panel is open at a time. +/// * <https://material.io/design/components/lists.html#types> +class ExpansionPanelList extends StatefulWidget { + /// Creates an expansion panel list widget. The [expansionCallback] is + /// triggered when an expansion panel expand/collapse button is pushed. + const ExpansionPanelList({ + super.key, + this.children = const <ExpansionPanel>[], + this.expansionCallback, + this.animationDuration = kThemeAnimationDuration, + this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding, + this.dividerColor, + this.elevation = 2, + this.expandIconColor, + this.materialGapSize = 16.0, + }) : _allowOnlyOnePanelOpen = false, + initialOpenPanelValue = null; + + /// Creates a radio expansion panel list widget. + /// + /// This widget allows for at most one panel in the list to be open. The + /// expansion panel callback is triggered when an expansion panel + /// expand/collapse button is pushed. The [children] objects must be instances + /// of [ExpansionPanelRadio]. + /// + /// {@tool dartpad} + /// Here is a simple example of how to implement ExpansionPanelList.radio. + /// + /// ** See code in examples/api/lib/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0.dart ** + /// {@end-tool} + const ExpansionPanelList.radio({ + super.key, + this.children = const <ExpansionPanelRadio>[], + this.expansionCallback, + this.animationDuration = kThemeAnimationDuration, + this.initialOpenPanelValue, + this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding, + this.dividerColor, + this.elevation = 2, + this.expandIconColor, + this.materialGapSize = 16.0, + }) : _allowOnlyOnePanelOpen = true; + + /// The children of the expansion panel list. They are laid out in a similar + /// fashion to [ListBody]. + final List<ExpansionPanel> children; + + /// The callback that gets called whenever one of the expand/collapse buttons + /// is pressed. The arguments passed to the callback are the index of the + /// pressed panel and whether the panel is currently expanded or not. + /// + /// If [ExpansionPanelList.radio] is used, the callback may be called a + /// second time if a different panel was previously open. The arguments + /// passed to the second callback are the index of the panel that will close + /// and false, marking that it will be closed. + /// + /// For [ExpansionPanelList], the callback should call [State.setState] when + /// it is notified about the closing/opening panel. On the other hand, the + /// callback for [ExpansionPanelList.radio] is intended to inform the parent + /// widget of changes, as the radio panels' open/close states are managed + /// internally. + /// + /// This callback is useful in order to keep track of the expanded/collapsed + /// panels in a parent widget that may need to react to these changes. + final ExpansionPanelCallback? expansionCallback; + + /// The duration of the expansion animation. + final Duration animationDuration; + + // Whether multiple panels can be open simultaneously + final bool _allowOnlyOnePanelOpen; + + /// The value of the panel that initially begins open. (This value is + /// only used when initializing with the [ExpansionPanelList.radio] + /// constructor.) + final Object? initialOpenPanelValue; + + /// The padding that surrounds the panel header when expanded. + /// + /// By default, 16px of space is added to the header vertically (above and below) + /// during expansion. + final EdgeInsets expandedHeaderPadding; + + /// Defines color for the divider when [ExpansionPanel.isExpanded] is false. + /// + /// If [dividerColor] is null, then [DividerThemeData.color] is used. If that + /// is null, then [ThemeData.dividerColor] is used. + final Color? dividerColor; + + /// Defines elevation for the [ExpansionPanel] while it's expanded. + /// + /// By default, the value of elevation is 2. + final double elevation; + + /// {@macro flutter.material.ExpandIcon.color} + final Color? expandIconColor; + + /// Defines the [MaterialGap.size] of the [MaterialGap] which is placed + /// between the [ExpansionPanelList.children] when they're expanded. + /// + /// Defaults to `16.0`. + final double materialGapSize; + + @override + State<StatefulWidget> createState() => _ExpansionPanelListState(); +} + +class _ExpansionPanelListState extends State<ExpansionPanelList> { + ExpansionPanelRadio? _currentOpenPanel; + + @override + void initState() { + super.initState(); + if (widget._allowOnlyOnePanelOpen) { + assert(_allIdentifiersUnique(), 'All ExpansionPanelRadio identifier values must be unique.'); + if (widget.initialOpenPanelValue != null) { + _currentOpenPanel = + searchPanelByValue(widget.children.cast<ExpansionPanelRadio>(), widget.initialOpenPanelValue); + } + } + } + + @override + void didUpdateWidget(ExpansionPanelList oldWidget) { + super.didUpdateWidget(oldWidget); + + if (widget._allowOnlyOnePanelOpen) { + assert(_allIdentifiersUnique(), 'All ExpansionPanelRadio identifier values must be unique.'); + // If the previous widget was non-radio ExpansionPanelList, initialize the + // open panel to widget.initialOpenPanelValue + if (!oldWidget._allowOnlyOnePanelOpen) { + _currentOpenPanel = + searchPanelByValue(widget.children.cast<ExpansionPanelRadio>(), widget.initialOpenPanelValue); + } + } else { + _currentOpenPanel = null; + } + } + + bool _allIdentifiersUnique() { + final Map<Object, bool> identifierMap = <Object, bool>{}; + for (final ExpansionPanelRadio child in widget.children.cast<ExpansionPanelRadio>()) { + identifierMap[child.value] = true; + } + return identifierMap.length == widget.children.length; + } + + bool _isChildExpanded(int index) { + if (widget._allowOnlyOnePanelOpen) { + final ExpansionPanelRadio radioWidget = widget.children[index] as ExpansionPanelRadio; + return _currentOpenPanel?.value == radioWidget.value; + } + return widget.children[index].isExpanded; + } + + void _handlePressed(bool isExpanded, int index) { + if (widget._allowOnlyOnePanelOpen) { + final ExpansionPanelRadio pressedChild = widget.children[index] as ExpansionPanelRadio; + + // If another ExpansionPanelRadio was already open, apply its + // expansionCallback (if any) to false, because it's closing. + for (int childIndex = 0; childIndex < widget.children.length; childIndex += 1) { + final ExpansionPanelRadio child = widget.children[childIndex] as ExpansionPanelRadio; + if (widget.expansionCallback != null && + childIndex != index && + child.value == _currentOpenPanel?.value) { + widget.expansionCallback!(childIndex, false); + } + } + + setState(() { + _currentOpenPanel = isExpanded ? null : pressedChild; + }); + } + // !isExpanded is passed because, when _handlePressed, the state of the panel to expand is not yet expanded. + widget.expansionCallback?.call(index, !isExpanded); + } + + ExpansionPanelRadio? searchPanelByValue(List<ExpansionPanelRadio> panels, Object? value) { + for (final ExpansionPanelRadio panel in panels) { + if (panel.value == value) { + return panel; + } + } + return null; + } + + @override + Widget build(BuildContext context) { + assert(kElevationToShadow.containsKey(widget.elevation), + 'Invalid value for elevation. See the kElevationToShadow constant for' + ' possible elevation values.', + ); + + final List<MergeableMaterialItem> items = <MergeableMaterialItem>[]; + + for (int index = 0; index < widget.children.length; index += 1) { + if (_isChildExpanded(index) && index != 0 && !_isChildExpanded(index - 1)) { + items.add(MaterialGap(key: _SaltedKey<BuildContext, int>(context, index * 2 - 1), size: widget.materialGapSize)); + } + + final ExpansionPanel child = widget.children[index]; + final Widget headerWidget = child.headerBuilder( + context, + _isChildExpanded(index), + ); + + Widget expandIconContainer = Container( + margin: const EdgeInsetsDirectional.only(end: 8.0), + child: ExpandIcon( + color: widget.expandIconColor, + isExpanded: _isChildExpanded(index), + padding: _kExpandIconPadding, + onPressed: !child.canTapOnHeader + ? (bool isExpanded) => _handlePressed(isExpanded, index) + : null, + ), + ); + if (!child.canTapOnHeader) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + expandIconContainer = Semantics( + label: _isChildExpanded(index)? localizations.expandedIconTapHint : localizations.collapsedIconTapHint, + container: true, + child: expandIconContainer, + ); + } + Widget header = Row( + children: <Widget>[ + Expanded( + child: AnimatedContainer( + duration: widget.animationDuration, + curve: Curves.fastOutSlowIn, + margin: _isChildExpanded(index) ? widget.expandedHeaderPadding : EdgeInsets.zero, + child: ConstrainedBox( + constraints: const BoxConstraints(minHeight: _kPanelHeaderCollapsedHeight), + child: headerWidget, + ), + ), + ), + expandIconContainer, + ], + ); + if (child.canTapOnHeader) { + header = MergeSemantics( + child: InkWell( + onTap: () => _handlePressed(_isChildExpanded(index), index), + child: header, + ), + ); + } + items.add( + MaterialSlice( + key: _SaltedKey<BuildContext, int>(context, index * 2), + color: child.backgroundColor, + child: Column( + children: <Widget>[ + header, + AnimatedCrossFade( + firstChild: Container(height: 0.0), + secondChild: child.body, + firstCurve: const Interval(0.0, 0.6, curve: Curves.fastOutSlowIn), + secondCurve: const Interval(0.4, 1.0, curve: Curves.fastOutSlowIn), + sizeCurve: Curves.fastOutSlowIn, + crossFadeState: _isChildExpanded(index) ? CrossFadeState.showSecond : CrossFadeState.showFirst, + duration: widget.animationDuration, + ), + ], + ), + ), + ); + + if (_isChildExpanded(index) && index != widget.children.length - 1) { + items.add(MaterialGap(key: _SaltedKey<BuildContext, int>(context, index * 2 + 1), size: widget.materialGapSize)); + } + } + + return MergeableMaterial( + hasDividers: true, + dividerColor: widget.dividerColor, + elevation: widget.elevation, + children: items, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expansion_tile.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expansion_tile.dart new file mode 100644 index 0000000000000000000000000000000000000000..e85f2f8a98e2da40366894791f95f79ea5b119cc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expansion_tile.dart @@ -0,0 +1,896 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'expansion_tile_theme.dart'; +import 'icons.dart'; +import 'list_tile.dart'; +import 'list_tile_theme.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +const Duration _kExpand = Duration(milliseconds: 200); + +/// Enables control over a single [ExpansionTile]'s expanded/collapsed state. +/// +/// It can be useful to expand or collapse an [ExpansionTile] +/// programatically, for example to reconfigure an existing expansion +/// tile based on a system event. To do so, create an [ExpansionTile] +/// with an [ExpansionTileController] that's owned by a stateful widget +/// or look up the tile's automatically created [ExpansionTileController] +/// with [ExpansionTileController.of] +/// +/// The controller's [expand] and [collapse] methods cause the +/// the [ExpansionTile] to rebuild, so they may not be called from +/// a build method. +class ExpansionTileController { + /// Create a controller to be used with [ExpansionTile.controller]. + ExpansionTileController(); + + _ExpansionTileState? _state; + + /// Whether the [ExpansionTile] built with this controller is in expanded state. + /// + /// This property doesn't take the animation into account. It reports `true` + /// even if the expansion animation is not completed. + /// + /// See also: + /// + /// * [expand], which expands the [ExpansionTile]. + /// * [collapse], which collapses the [ExpansionTile]. + /// * [ExpansionTile.controller] to create an ExpansionTile with a controller. + bool get isExpanded { + assert(_state != null); + return _state!._isExpanded; + } + + /// Expands the [ExpansionTile] that was built with this controller; + /// + /// Normally the tile is expanded automatically when the user taps on the header. + /// It is sometimes useful to trigger the expansion programmatically due + /// to external changes. + /// + /// If the tile is already in the expanded state (see [isExpanded]), calling + /// this method has no effect. + /// + /// Calling this method may cause the [ExpansionTile] to rebuild, so it may + /// not be called from a build method. + /// + /// Calling this method will trigger an [ExpansionTile.onExpansionChanged] callback. + /// + /// See also: + /// + /// * [collapse], which collapses the tile. + /// * [isExpanded] to check whether the tile is expanded. + /// * [ExpansionTile.controller] to create an ExpansionTile with a controller. + void expand() { + assert(_state != null); + if (!isExpanded) { + _state!._toggleExpansion(); + } + } + + /// Collapses the [ExpansionTile] that was built with this controller. + /// + /// Normally the tile is collapsed automatically when the user taps on the header. + /// It can be useful sometimes to trigger the collapse programmatically due + /// to some external changes. + /// + /// If the tile is already in the collapsed state (see [isExpanded]), calling + /// this method has no effect. + /// + /// Calling this method may cause the [ExpansionTile] to rebuild, so it may + /// not be called from a build method. + /// + /// Calling this method will trigger an [ExpansionTile.onExpansionChanged] callback. + /// + /// See also: + /// + /// * [expand], which expands the tile. + /// * [isExpanded] to check whether the tile is expanded. + /// * [ExpansionTile.controller] to create an ExpansionTile with a controller. + void collapse() { + assert(_state != null); + if (isExpanded) { + _state!._toggleExpansion(); + } + } + + /// Finds the [ExpansionTileController] for the closest [ExpansionTile] instance + /// that encloses the given context. + /// + /// If no [ExpansionTile] encloses the given context, calling this + /// method will cause an assert in debug mode, and throw an + /// exception in release mode. + /// + /// To return null if there is no [ExpansionTile] use [maybeOf] instead. + /// + /// {@tool dartpad} + /// Typical usage of the [ExpansionTileController.of] function is to call it from within the + /// `build` method of a descendant of an [ExpansionTile]. + /// + /// When the [ExpansionTile] is actually created in the same `build` + /// function as the callback that refers to the controller, then the + /// `context` argument to the `build` function can't be used to find + /// the [ExpansionTileController] (since it's "above" the widget + /// being returned in the widget tree). In cases like that you can + /// add a [Builder] widget, which provides a new scope with a + /// [BuildContext] that is "under" the [ExpansionTile]: + /// + /// ** See code in examples/api/lib/material/expansion_tile/expansion_tile.1.dart ** + /// {@end-tool} + /// + /// A more efficient solution is to split your build function into + /// several widgets. This introduces a new context from which you + /// can obtain the [ExpansionTileController]. With this approach you + /// would have an outer widget that creates the [ExpansionTile] + /// populated by instances of your new inner widgets, and then in + /// these inner widgets you would use [ExpansionTileController.of]. + static ExpansionTileController of(BuildContext context) { + final _ExpansionTileState? result = context.findAncestorStateOfType<_ExpansionTileState>(); + if (result != null) { + return result._tileController; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'ExpansionTileController.of() called with a context that does not contain a ExpansionTile.', + ), + ErrorDescription( + 'No ExpansionTile ancestor could be found starting from the context that was passed to ExpansionTileController.of(). ' + 'This usually happens when the context provided is from the same StatefulWidget as that ' + 'whose build function actually creates the ExpansionTile widget being sought.', + ), + ErrorHint( + 'There are several ways to avoid this problem. The simplest is to use a Builder to get a ' + 'context that is "under" the ExpansionTile. For an example of this, please see the ' + 'documentation for ExpansionTileController.of():\n' + ' https://api.flutter.dev/flutter/material/ExpansionTile/of.html', + ), + ErrorHint( + 'A more efficient solution is to split your build function into several widgets. This ' + 'introduces a new context from which you can obtain the ExpansionTile. In this solution, ' + 'you would have an outer widget that creates the ExpansionTile populated by instances of ' + 'your new inner widgets, and then in these inner widgets you would use ExpansionTileController.of().\n' + 'An other solution is assign a GlobalKey to the ExpansionTile, ' + 'then use the key.currentState property to obtain the ExpansionTile rather than ' + 'using the ExpansionTileController.of() function.', + ), + context.describeElement('The context used was'), + ]); + } + + /// Finds the [ExpansionTile] from the closest instance of this class that + /// encloses the given context and returns its [ExpansionTileController]. + /// + /// If no [ExpansionTile] encloses the given context then return null. + /// To throw an exception instead, use [of] instead of this function. + /// + /// See also: + /// + /// * [of], a similar function to this one that throws if no [ExpansionTile] + /// encloses the given context. Also includes some sample code in its + /// documentation. + static ExpansionTileController? maybeOf(BuildContext context) { + return context.findAncestorStateOfType<_ExpansionTileState>()?._tileController; + } +} + +/// A single-line [ListTile] with an expansion arrow icon that expands or collapses +/// the tile to reveal or hide the [children]. +/// +/// This widget is typically used with [ListView] to create an "expand / +/// collapse" list entry. When used with scrolling widgets like [ListView], a +/// unique [PageStorageKey] must be specified as the [key], to enable the +/// [ExpansionTile] to save and restore its expanded state when it is scrolled +/// in and out of view. +/// +/// This class overrides the [ListTileThemeData.iconColor] and [ListTileThemeData.textColor] +/// theme properties for its [ListTile]. These colors animate between values when +/// the tile is expanded and collapsed: between [iconColor], [collapsedIconColor] and +/// between [textColor] and [collapsedTextColor]. +/// +/// The expansion arrow icon is shown on the right by default in left-to-right languages +/// (i.e. the trailing edge). This can be changed using [controlAffinity]. This maps +/// to the [leading] and [trailing] properties of [ExpansionTile]. +/// +/// {@tool dartpad} +/// This example demonstrates how the [ExpansionTile] icon's location and appearance +/// can be customized. +/// +/// ** See code in examples/api/lib/material/expansion_tile/expansion_tile.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example demonstrates how an [ExpansionTileController] can be used to +/// programatically expand or collapse an [ExpansionTile]. +/// +/// ** See code in examples/api/lib/material/expansion_tile/expansion_tile.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListTile], useful for creating expansion tile [children] when the +/// expansion tile represents a sublist. +/// * The "Expand and collapse" section of +/// <https://material.io/components/lists#types> +class ExpansionTile extends StatefulWidget { + /// Creates a single-line [ListTile] with an expansion arrow icon that expands or collapses + /// the tile to reveal or hide the [children]. The [initiallyExpanded] property must + /// be non-null. + const ExpansionTile({ + super.key, + this.leading, + required this.title, + this.subtitle, + this.onExpansionChanged, + this.children = const <Widget>[], + this.trailing, + this.initiallyExpanded = false, + this.maintainState = false, + this.tilePadding, + this.expandedCrossAxisAlignment, + this.expandedAlignment, + this.childrenPadding, + this.backgroundColor, + this.collapsedBackgroundColor, + this.textColor, + this.collapsedTextColor, + this.iconColor, + this.collapsedIconColor, + this.shape, + this.collapsedShape, + this.clipBehavior, + this.controlAffinity, + this.controller, + this.dense, + this.visualDensity, + this.enableFeedback = true, + this.enabled = true, + this.expansionAnimationStyle, + }) : assert( + expandedCrossAxisAlignment != CrossAxisAlignment.baseline, + 'CrossAxisAlignment.baseline is not supported since the expanded children ' + 'are aligned in a column, not a row. Try to use another constant.', + ); + + /// A widget to display before the title. + /// + /// Typically a [CircleAvatar] widget. + /// + /// Depending on the value of [controlAffinity], the [leading] widget + /// may replace the rotating expansion arrow icon. + final Widget? leading; + + /// The primary content of the list item. + /// + /// Typically a [Text] widget. + final Widget title; + + /// Additional content displayed below the title. + /// + /// Typically a [Text] widget. + final Widget? subtitle; + + /// Called when the tile expands or collapses. + /// + /// When the tile starts expanding, this function is called with the value + /// true. When the tile starts collapsing, this function is called with + /// the value false. + final ValueChanged<bool>? onExpansionChanged; + + /// The widgets that are displayed when the tile expands. + /// + /// Typically [ListTile] widgets. + final List<Widget> children; + + /// The color to display behind the sublist when expanded. + /// + /// If this property is null then [ExpansionTileThemeData.backgroundColor] is used. If that + /// is also null then Colors.transparent is used. + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final Color? backgroundColor; + + /// When not null, defines the background color of tile when the sublist is collapsed. + /// + /// If this property is null then [ExpansionTileThemeData.collapsedBackgroundColor] is used. + /// If that is also null then Colors.transparent is used. + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final Color? collapsedBackgroundColor; + + /// A widget to display after the title. + /// + /// Depending on the value of [controlAffinity], the [trailing] widget + /// may replace the rotating expansion arrow icon. + final Widget? trailing; + + /// Specifies if the list tile is initially expanded (true) or collapsed (false, the default). + final bool initiallyExpanded; + + /// Specifies whether the state of the children is maintained when the tile expands and collapses. + /// + /// When true, the children are kept in the tree while the tile is collapsed. + /// When false (default), the children are removed from the tree when the tile is + /// collapsed and recreated upon expansion. + final bool maintainState; + + /// Specifies padding for the [ListTile]. + /// + /// Analogous to [ListTile.contentPadding], this property defines the insets for + /// the [leading], [title], [subtitle] and [trailing] widgets. It does not inset + /// the expanded [children] widgets. + /// + /// If this property is null then [ExpansionTileThemeData.tilePadding] is used. If that + /// is also null then the tile's padding is `EdgeInsets.symmetric(horizontal: 16.0)`. + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final EdgeInsetsGeometry? tilePadding; + + /// Specifies the alignment of [children], which are arranged in a column when + /// the tile is expanded. + /// + /// The internals of the expanded tile make use of a [Column] widget for + /// [children], and [Align] widget to align the column. The [expandedAlignment] + /// parameter is passed directly into the [Align]. + /// + /// Modifying this property controls the alignment of the column within the + /// expanded tile, not the alignment of [children] widgets within the column. + /// To align each child within [children], see [expandedCrossAxisAlignment]. + /// + /// The width of the column is the width of the widest child widget in [children]. + /// + /// If this property is null then [ExpansionTileThemeData.expandedAlignment]is used. If that + /// is also null then the value of [expandedAlignment] is [Alignment.center]. + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final Alignment? expandedAlignment; + + /// Specifies the alignment of each child within [children] when the tile is expanded. + /// + /// The internals of the expanded tile make use of a [Column] widget for + /// [children], and the `crossAxisAlignment` parameter is passed directly into + /// the [Column]. + /// + /// Modifying this property controls the cross axis alignment of each child + /// within its [Column]. The width of the [Column] that houses [children] will + /// be the same as the widest child widget in [children]. The width of the + /// [Column] might not be equal to the width of the expanded tile. + /// + /// To align the [Column] along the expanded tile, use the [expandedAlignment] + /// property instead. + /// + /// When the value is null, the value of [expandedCrossAxisAlignment] is + /// [CrossAxisAlignment.center]. + final CrossAxisAlignment? expandedCrossAxisAlignment; + + /// Specifies padding for [children]. + /// + /// If this property is null then [ExpansionTileThemeData.childrenPadding] is used. If that + /// is also null then the value of [childrenPadding] is [EdgeInsets.zero]. + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final EdgeInsetsGeometry? childrenPadding; + + /// The icon color of tile's expansion arrow icon when the sublist is expanded. + /// + /// Used to override to the [ListTileThemeData.iconColor]. + /// + /// If this property is null then [ExpansionTileThemeData.iconColor] is used. If that + /// is also null then the value of [ColorScheme.primary] is used. + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final Color? iconColor; + + /// The icon color of tile's expansion arrow icon when the sublist is collapsed. + /// + /// Used to override to the [ListTileThemeData.iconColor]. + /// + /// If this property is null then [ExpansionTileThemeData.collapsedIconColor] is used. If that + /// is also null and [ThemeData.useMaterial3] is true, [ColorScheme.onSurface] is used. Otherwise, + /// defaults to [ThemeData.unselectedWidgetColor] color. + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final Color? collapsedIconColor; + + + /// The color of the tile's titles when the sublist is expanded. + /// + /// Used to override to the [ListTileThemeData.textColor]. + /// + /// If this property is null then [ExpansionTileThemeData.textColor] is used. If that + /// is also null then and [ThemeData.useMaterial3] is true, color of the [TextTheme.bodyLarge] + /// will be used for the [title] and [subtitle]. Otherwise, defaults to [ColorScheme.primary] color. + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final Color? textColor; + + /// The color of the tile's titles when the sublist is collapsed. + /// + /// Used to override to the [ListTileThemeData.textColor]. + /// + /// If this property is null then [ExpansionTileThemeData.collapsedTextColor] is used. + /// If that is also null and [ThemeData.useMaterial3] is true, color of the + /// [TextTheme.bodyLarge] will be used for the [title] and [subtitle]. Otherwise, + /// defaults to color of the [TextTheme.titleMedium]. + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final Color? collapsedTextColor; + + /// The tile's border shape when the sublist is expanded. + /// + /// If this property is null, the [ExpansionTileThemeData.shape] is used. If that + /// is also null, a [Border] with vertical sides default to [ThemeData.dividerColor] is used + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final ShapeBorder? shape; + + /// The tile's border shape when the sublist is collapsed. + /// + /// If this property is null, the [ExpansionTileThemeData.collapsedShape] is used. If that + /// is also null, a [Border] with vertical sides default to Color [Colors.transparent] is used + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final ShapeBorder? collapsedShape; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// If this property is null, the [ExpansionTileThemeData.clipBehavior] is used. If that + /// is also null, a [Clip.none] is used + /// + /// See also: + /// + /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s + /// [ExpansionTileThemeData]. + final Clip? clipBehavior; + + /// Typically used to force the expansion arrow icon to the tile's leading or trailing edge. + /// + /// By default, the value of [controlAffinity] is [ListTileControlAffinity.platform], + /// which means that the expansion arrow icon will appear on the tile's trailing edge. + final ListTileControlAffinity? controlAffinity; + + /// If provided, the controller can be used to expand and collapse tiles. + /// + /// In cases were control over the tile's state is needed from a callback triggered + /// by a widget within the tile, [ExpansionTileController.of] may be more convenient + /// than supplying a controller. + final ExpansionTileController? controller; + + /// {@macro flutter.material.ListTile.dense} + final bool? dense; + + /// Defines how compact the expansion tile's layout will be. + /// + /// {@macro flutter.material.themedata.visualDensity} + final VisualDensity? visualDensity; + + /// {@macro flutter.material.ListTile.enableFeedback} + final bool? enableFeedback; + + /// Whether this expansion tile is interactive. + /// + /// If false, the internal [ListTile] will be disabled, changing its + /// appearance according to the theme and disabling user interaction. + /// + /// Even if disabled, the expansion can still be toggled programmatically + /// through an [ExpansionTileController]. + final bool enabled; + + /// Used to override the expansion animation curve and duration. + /// + /// If [AnimationStyle.duration] is provided, it will be used to override + /// the expansion animation duration. If it is null, then [AnimationStyle.duration] + /// from the [ExpansionTileThemeData.expansionAnimationStyle] will be used. + /// Otherwise, defaults to 200ms. + /// + /// If [AnimationStyle.curve] is provided, it will be used to override + /// the expansion animation curve. If it is null, then [AnimationStyle.curve] + /// from the [ExpansionTileThemeData.expansionAnimationStyle] will be used. + /// Otherwise, defaults to [Curves.easeIn]. + /// + /// To disable the theme animation, use [AnimationStyle.noAnimation]. + /// + /// {@tool dartpad} + /// This sample showcases how to override the [ExpansionTile] expansion + /// animation curve and duration using [AnimationStyle]. + /// + /// ** See code in examples/api/lib/material/expansion_tile/expansion_tile.2.dart ** + /// {@end-tool} + final AnimationStyle? expansionAnimationStyle; + + @override + State<ExpansionTile> createState() => _ExpansionTileState(); +} + +class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProviderStateMixin { + static final Animatable<double> _easeOutTween = CurveTween(curve: Curves.easeOut); + static final Animatable<double> _easeInTween = CurveTween(curve: Curves.easeIn); + static final Animatable<double> _halfTween = Tween<double>(begin: 0.0, end: 0.5); + + final ShapeBorderTween _borderTween = ShapeBorderTween(); + final ColorTween _headerColorTween = ColorTween(); + final ColorTween _iconColorTween = ColorTween(); + final ColorTween _backgroundColorTween = ColorTween(); + final CurveTween _heightFactorTween = CurveTween(curve: Curves.easeIn); + + late AnimationController _animationController; + late Animation<double> _iconTurns; + late Animation<double> _heightFactor; + late Animation<ShapeBorder?> _border; + late Animation<Color?> _headerColor; + late Animation<Color?> _iconColor; + late Animation<Color?> _backgroundColor; + + bool _isExpanded = false; + late ExpansionTileController _tileController; + + @override + void initState() { + super.initState(); + _animationController = AnimationController(duration: _kExpand, vsync: this); + _heightFactor = _animationController.drive(_heightFactorTween); + _iconTurns = _animationController.drive(_halfTween.chain(_easeInTween)); + _border = _animationController.drive(_borderTween.chain(_easeOutTween)); + _headerColor = _animationController.drive(_headerColorTween.chain(_easeInTween)); + _iconColor = _animationController.drive(_iconColorTween.chain(_easeInTween)); + _backgroundColor = _animationController.drive(_backgroundColorTween.chain(_easeOutTween)); + + _isExpanded = PageStorage.maybeOf(context)?.readState(context) as bool? ?? widget.initiallyExpanded; + if (_isExpanded) { + _animationController.value = 1.0; + } + + assert(widget.controller?._state == null); + _tileController = widget.controller ?? ExpansionTileController(); + _tileController._state = this; + } + + @override + void dispose() { + _tileController._state = null; + _animationController.dispose(); + super.dispose(); + } + + void _toggleExpansion() { + final TextDirection textDirection = WidgetsLocalizations.of(context).textDirection; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final String stateHint = _isExpanded ? localizations.expandedHint : localizations.collapsedHint; + setState(() { + _isExpanded = !_isExpanded; + if (_isExpanded) { + _animationController.forward(); + } else { + _animationController.reverse().then<void>((void value) { + if (!mounted) { + return; + } + setState(() { + // Rebuild without widget.children. + }); + }); + } + PageStorage.maybeOf(context)?.writeState(context, _isExpanded); + }); + widget.onExpansionChanged?.call(_isExpanded); + SemanticsService.announce(stateHint, textDirection); + } + + void _handleTap() { + _toggleExpansion(); + } + + // Platform or null affinity defaults to trailing. + ListTileControlAffinity _effectiveAffinity(ListTileControlAffinity? affinity) { + switch (affinity ?? ListTileControlAffinity.trailing) { + case ListTileControlAffinity.leading: + return ListTileControlAffinity.leading; + case ListTileControlAffinity.trailing: + case ListTileControlAffinity.platform: + return ListTileControlAffinity.trailing; + } + } + + Widget? _buildIcon(BuildContext context) { + return RotationTransition( + turns: _iconTurns, + child: const Icon(Icons.expand_more), + ); + } + + Widget? _buildLeadingIcon(BuildContext context) { + if (_effectiveAffinity(widget.controlAffinity) != ListTileControlAffinity.leading) { + return null; + } + return _buildIcon(context); + } + + Widget? _buildTrailingIcon(BuildContext context) { + if (_effectiveAffinity(widget.controlAffinity) != ListTileControlAffinity.trailing) { + return null; + } + return _buildIcon(context); + } + + Widget _buildChildren(BuildContext context, Widget? child) { + final ThemeData theme = Theme.of(context); + final ExpansionTileThemeData expansionTileTheme = ExpansionTileTheme.of(context); + final ShapeBorder expansionTileBorder = _border.value ?? const Border( + top: BorderSide(color: Colors.transparent), + bottom: BorderSide(color: Colors.transparent), + ); + final Clip clipBehavior = widget.clipBehavior ?? expansionTileTheme.clipBehavior ?? Clip.none; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final String onTapHint = _isExpanded + ? localizations.expansionTileExpandedTapHint + : localizations.expansionTileCollapsedTapHint; + String? semanticsHint; + switch (theme.platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + semanticsHint = _isExpanded + ? '${localizations.collapsedHint}\n ${localizations.expansionTileExpandedHint}' + : '${localizations.expandedHint}\n ${localizations.expansionTileCollapsedHint}'; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + break; + } + + return Container( + clipBehavior: clipBehavior, + decoration: ShapeDecoration( + color: _backgroundColor.value ?? expansionTileTheme.backgroundColor ?? Colors.transparent, + shape: expansionTileBorder, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + Semantics( + hint: semanticsHint, + onTapHint: onTapHint, + child: ListTileTheme.merge( + iconColor: _iconColor.value ?? expansionTileTheme.iconColor, + textColor: _headerColor.value, + child: ListTile( + enabled: widget.enabled, + onTap: _handleTap, + dense: widget.dense, + visualDensity: widget.visualDensity, + enableFeedback: widget.enableFeedback, + contentPadding: widget.tilePadding ?? expansionTileTheme.tilePadding, + leading: widget.leading ?? _buildLeadingIcon(context), + title: widget.title, + subtitle: widget.subtitle, + trailing: widget.trailing ?? _buildTrailingIcon(context), + ), + ), + ), + ClipRect( + child: Align( + alignment: widget.expandedAlignment + ?? expansionTileTheme.expandedAlignment + ?? Alignment.center, + heightFactor: _heightFactor.value, + child: child, + ), + ), + ], + ), + ); + } + + @override + void didUpdateWidget(covariant ExpansionTile oldWidget) { + super.didUpdateWidget(oldWidget); + final ThemeData theme = Theme.of(context); + final ExpansionTileThemeData expansionTileTheme = ExpansionTileTheme.of(context); + final ExpansionTileThemeData defaults = theme.useMaterial3 + ? _ExpansionTileDefaultsM3(context) + : _ExpansionTileDefaultsM2(context); + if (widget.collapsedShape != oldWidget.collapsedShape + || widget.shape != oldWidget.shape) { + _updateShapeBorder(expansionTileTheme, theme); + } + if (widget.collapsedTextColor != oldWidget.collapsedTextColor + || widget.textColor != oldWidget.textColor) { + _updateHeaderColor(expansionTileTheme, defaults); + } + if (widget.collapsedIconColor != oldWidget.collapsedIconColor + || widget.iconColor != oldWidget.iconColor) { + _updateIconColor(expansionTileTheme, defaults); + } + if (widget.backgroundColor != oldWidget.backgroundColor + || widget.collapsedBackgroundColor != oldWidget.collapsedBackgroundColor) { + _updateBackgroundColor(expansionTileTheme); + } + if (widget.expansionAnimationStyle != oldWidget.expansionAnimationStyle) { + _updateAnimationDuration(expansionTileTheme); + _updateHeightFactorCurve(expansionTileTheme); + } + } + + @override + void didChangeDependencies() { + final ThemeData theme = Theme.of(context); + final ExpansionTileThemeData expansionTileTheme = ExpansionTileTheme.of(context); + final ExpansionTileThemeData defaults = theme.useMaterial3 + ? _ExpansionTileDefaultsM3(context) + : _ExpansionTileDefaultsM2(context); + _updateAnimationDuration(expansionTileTheme); + _updateShapeBorder(expansionTileTheme, theme); + _updateHeaderColor(expansionTileTheme, defaults); + _updateIconColor(expansionTileTheme, defaults); + _updateBackgroundColor(expansionTileTheme); + _updateHeightFactorCurve(expansionTileTheme); + super.didChangeDependencies(); + } + + void _updateAnimationDuration(ExpansionTileThemeData expansionTileTheme) { + _animationController.duration = widget.expansionAnimationStyle?.duration + ?? expansionTileTheme.expansionAnimationStyle?.duration + ?? _kExpand; + } + + void _updateShapeBorder(ExpansionTileThemeData expansionTileTheme, ThemeData theme) { + _borderTween + ..begin = widget.collapsedShape + ?? expansionTileTheme.collapsedShape + ?? const Border( + top: BorderSide(color: Colors.transparent), + bottom: BorderSide(color: Colors.transparent), + ) + ..end = widget.shape + ?? expansionTileTheme.shape + ?? Border( + top: BorderSide(color: theme.dividerColor), + bottom: BorderSide(color: theme.dividerColor), + ); + } + + void _updateHeaderColor(ExpansionTileThemeData expansionTileTheme, ExpansionTileThemeData defaults) { + _headerColorTween + ..begin = widget.collapsedTextColor + ?? expansionTileTheme.collapsedTextColor + ?? defaults.collapsedTextColor + ..end = widget.textColor ?? expansionTileTheme.textColor ?? defaults.textColor; + } + + void _updateIconColor(ExpansionTileThemeData expansionTileTheme, ExpansionTileThemeData defaults) { + _iconColorTween + ..begin = widget.collapsedIconColor + ?? expansionTileTheme.collapsedIconColor + ?? defaults.collapsedIconColor + ..end = widget.iconColor ?? expansionTileTheme.iconColor ?? defaults.iconColor; + } + + void _updateBackgroundColor(ExpansionTileThemeData expansionTileTheme) { + _backgroundColorTween + ..begin = widget.collapsedBackgroundColor ?? expansionTileTheme.collapsedBackgroundColor + ..end = widget.backgroundColor ?? expansionTileTheme.backgroundColor; + } + + void _updateHeightFactorCurve(ExpansionTileThemeData expansionTileTheme) { + _heightFactorTween.curve = widget.expansionAnimationStyle?.curve + ?? expansionTileTheme.expansionAnimationStyle?.curve + ?? Curves.easeIn; + } + + @override + Widget build(BuildContext context) { + final ExpansionTileThemeData expansionTileTheme = ExpansionTileTheme.of(context); + final bool closed = !_isExpanded && _animationController.isDismissed; + final bool shouldRemoveChildren = closed && !widget.maintainState; + + final Widget result = Offstage( + offstage: closed, + child: TickerMode( + enabled: !closed, + child: Padding( + padding: widget.childrenPadding ?? expansionTileTheme.childrenPadding ?? EdgeInsets.zero, + child: Column( + crossAxisAlignment: widget.expandedCrossAxisAlignment ?? CrossAxisAlignment.center, + children: widget.children, + ), + ), + ), + ); + + return AnimatedBuilder( + animation: _animationController.view, + builder: _buildChildren, + child: shouldRemoveChildren ? null : result, + ); + } +} + +class _ExpansionTileDefaultsM2 extends ExpansionTileThemeData { + _ExpansionTileDefaultsM2(this.context); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colorScheme = _theme.colorScheme; + + @override + Color? get textColor => _colorScheme.primary; + + @override + Color? get iconColor => _colorScheme.primary; + + @override + Color? get collapsedTextColor => _theme.textTheme.titleMedium!.color; + + @override + Color? get collapsedIconColor => _theme.unselectedWidgetColor; +} + +// BEGIN GENERATED TOKEN PROPERTIES - ExpansionTile + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _ExpansionTileDefaultsM3 extends ExpansionTileThemeData { + _ExpansionTileDefaultsM3(this.context); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + + @override + Color? get textColor => _colors.onSurface; + + @override + Color? get iconColor => _colors.primary; + + @override + Color? get collapsedTextColor => _colors.onSurface; + + @override + Color? get collapsedIconColor => _colors.onSurfaceVariant; +} + +// END GENERATED TOKEN PROPERTIES - ExpansionTile diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expansion_tile_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expansion_tile_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..b0109b23cc0a07ebd171c73d0ec19f5bb40015dc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/expansion_tile_theme.dart @@ -0,0 +1,256 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Used with [ExpansionTileTheme] to define default property values for +/// descendant [ExpansionTile] widgets. +/// +/// Descendant widgets obtain the current [ExpansionTileThemeData] object +/// using `ExpansionTileTheme.of(context)`. Instances of +/// [ExpansionTileThemeData] can be customized with +/// [ExpansionTileThemeData.copyWith]. +/// +/// A [ExpansionTileThemeData] is often specified as part of the +/// overall [Theme] with [ThemeData.expansionTileTheme]. +/// +/// All [ExpansionTileThemeData] properties are `null` by default. +/// When a theme property is null, the [ExpansionTile] will provide its own +/// default based on the overall [Theme]'s textTheme and +/// colorScheme. See the individual [ExpansionTile] properties for details. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +/// * [ExpansionTileTheme] which overrides the default [ExpansionTileTheme] +/// of its [ExpansionTile] descendants. +/// * [ThemeData.textTheme], text with a color that contrasts with the card +/// and canvas colors. +/// * [ThemeData.colorScheme], the thirteen colors that most Material widget +/// default colors are based on. +@immutable +class ExpansionTileThemeData with Diagnosticable { + /// Creates a [ExpansionTileThemeData]. + const ExpansionTileThemeData ({ + this.backgroundColor, + this.collapsedBackgroundColor, + this.tilePadding, + this.expandedAlignment, + this.childrenPadding, + this.iconColor, + this.collapsedIconColor, + this.textColor, + this.collapsedTextColor, + this.shape, + this.collapsedShape, + this.clipBehavior, + this.expansionAnimationStyle, + }); + + /// Overrides the default value of [ExpansionTile.backgroundColor]. + final Color? backgroundColor; + + /// Overrides the default value of [ExpansionTile.collapsedBackgroundColor]. + final Color? collapsedBackgroundColor; + + /// Overrides the default value of [ExpansionTile.tilePadding]. + final EdgeInsetsGeometry? tilePadding; + + /// Overrides the default value of [ExpansionTile.expandedAlignment]. + final AlignmentGeometry? expandedAlignment; + + /// Overrides the default value of [ExpansionTile.childrenPadding]. + final EdgeInsetsGeometry? childrenPadding; + + /// Overrides the default value of [ExpansionTile.iconColor]. + final Color? iconColor; + + /// Overrides the default value of [ExpansionTile.collapsedIconColor]. + final Color? collapsedIconColor; + + /// Overrides the default value of [ExpansionTile.textColor]. + final Color? textColor; + + /// Overrides the default value of [ExpansionTile.collapsedTextColor]. + final Color? collapsedTextColor; + + /// Overrides the default value of [ExpansionTile.shape]. + final ShapeBorder? shape; + + /// Overrides the default value of [ExpansionTile.collapsedShape]. + final ShapeBorder? collapsedShape; + + /// Overrides the default value of [ExpansionTile.clipBehavior]. + final Clip? clipBehavior; + + /// Overrides the default value of [ExpansionTile.expansionAnimationStyle]. + final AnimationStyle? expansionAnimationStyle; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + ExpansionTileThemeData copyWith({ + Color? backgroundColor, + Color? collapsedBackgroundColor, + EdgeInsetsGeometry? tilePadding, + AlignmentGeometry? expandedAlignment, + EdgeInsetsGeometry? childrenPadding, + Color? iconColor, + Color? collapsedIconColor, + Color? textColor, + Color? collapsedTextColor, + ShapeBorder? shape, + ShapeBorder? collapsedShape, + Clip? clipBehavior, + AnimationStyle? expansionAnimationStyle, + }) { + return ExpansionTileThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + collapsedBackgroundColor: collapsedBackgroundColor ?? this.collapsedBackgroundColor, + tilePadding: tilePadding ?? this.tilePadding, + expandedAlignment: expandedAlignment ?? this.expandedAlignment, + childrenPadding: childrenPadding ?? this.childrenPadding, + iconColor: iconColor ?? this.iconColor, + collapsedIconColor: collapsedIconColor ?? this.collapsedIconColor, + textColor: textColor ?? this.textColor, + collapsedTextColor: collapsedTextColor ?? this.collapsedTextColor, + shape: shape ?? this.shape, + collapsedShape: collapsedShape ?? this.collapsedShape, + clipBehavior: clipBehavior ?? this.clipBehavior, + expansionAnimationStyle: expansionAnimationStyle ?? this.expansionAnimationStyle, + ); + } + + /// Linearly interpolate between ExpansionTileThemeData objects. + static ExpansionTileThemeData? lerp(ExpansionTileThemeData? a, ExpansionTileThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return ExpansionTileThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + collapsedBackgroundColor: Color.lerp(a?.collapsedBackgroundColor, b?.collapsedBackgroundColor, t), + tilePadding: EdgeInsetsGeometry.lerp(a?.tilePadding, b?.tilePadding, t), + expandedAlignment: AlignmentGeometry.lerp(a?.expandedAlignment, b?.expandedAlignment, t), + childrenPadding: EdgeInsetsGeometry.lerp(a?.childrenPadding, b?.childrenPadding, t), + iconColor: Color.lerp(a?.iconColor, b?.iconColor, t), + collapsedIconColor: Color.lerp(a?.collapsedIconColor, b?.collapsedIconColor, t), + textColor: Color.lerp(a?.textColor, b?.textColor, t), + collapsedTextColor: Color.lerp(a?.collapsedTextColor, b?.collapsedTextColor, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + collapsedShape: ShapeBorder.lerp(a?.collapsedShape, b?.collapsedShape, t), + clipBehavior: t < 0.5 ? a?.clipBehavior : b?.clipBehavior, + expansionAnimationStyle: t < 0.5 ? a?.expansionAnimationStyle : b?.expansionAnimationStyle, + ); + } + + @override + int get hashCode { + return Object.hash( + backgroundColor, + collapsedBackgroundColor, + tilePadding, + expandedAlignment, + childrenPadding, + iconColor, + collapsedIconColor, + textColor, + collapsedTextColor, + shape, + collapsedShape, + clipBehavior, + expansionAnimationStyle, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ExpansionTileThemeData + && other.backgroundColor == backgroundColor + && other.collapsedBackgroundColor == collapsedBackgroundColor + && other.tilePadding == tilePadding + && other.expandedAlignment == expandedAlignment + && other.childrenPadding == childrenPadding + && other.iconColor == iconColor + && other.collapsedIconColor == collapsedIconColor + && other.textColor == textColor + && other.collapsedTextColor == collapsedTextColor + && other.shape == shape + && other.collapsedShape == collapsedShape + && other.clipBehavior == clipBehavior + && other.expansionAnimationStyle == expansionAnimationStyle; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(ColorProperty('collapsedBackgroundColor', collapsedBackgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('tilePadding', tilePadding, defaultValue: null)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('expandedAlignment', expandedAlignment, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('childrenPadding', childrenPadding, defaultValue: null)); + properties.add(ColorProperty('iconColor', iconColor, defaultValue: null)); + properties.add(ColorProperty('collapsedIconColor', collapsedIconColor, defaultValue: null)); + properties.add(ColorProperty('textColor', textColor, defaultValue: null)); + properties.add(ColorProperty('collapsedTextColor', collapsedTextColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('collapsedShape', collapsedShape, defaultValue: null)); + properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior, defaultValue: null)); + properties.add(DiagnosticsProperty<AnimationStyle>('expansionAnimationStyle', expansionAnimationStyle, defaultValue: null)); + } +} + +/// Overrides the default [ExpansionTileTheme] of its [ExpansionTile] descendants. +/// +/// See also: +/// +/// * [ExpansionTileThemeData], which is used to configure this theme. +/// * [ThemeData.expansionTileTheme], which can be used to override the default +/// [ExpansionTileTheme] for [ExpansionTile]s below the overall [Theme]. +class ExpansionTileTheme extends InheritedTheme { + /// Applies the given theme [data] to [child]. + const ExpansionTileTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies color, alignment, and text style values for + /// descendant [ExpansionTile] widgets. + final ExpansionTileThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [ExpansionTileTheme] widget, then + /// [ThemeData.expansionTileTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ExpansionTileThemeData theme = ExpansionTileTheme.of(context); + /// ``` + static ExpansionTileThemeData of(BuildContext context) { + final ExpansionTileTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<ExpansionTileTheme>(); + return inheritedTheme?.data ?? Theme.of(context).expansionTileTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return ExpansionTileTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(ExpansionTileTheme oldWidget) => data != oldWidget.data; + } diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/feedback.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/feedback.dart new file mode 100644 index 0000000000000000000000000000000000000000..cfb3a063480bf8029c5a7e1d605f4a9edf2d156f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/feedback.dart @@ -0,0 +1,172 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/semantics.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +/// Provides platform-specific acoustic and/or haptic feedback for certain +/// actions. +/// +/// For example, to play the Android-typically click sound when a button is +/// tapped, call [forTap]. For the Android-specific vibration when long pressing +/// an element, call [forLongPress]. Alternatively, you can also wrap your +/// [GestureDetector.onTap] or [GestureDetector.onLongPress] callback in +/// [wrapForTap] or [wrapForLongPress] to achieve the same (see example code +/// below). +/// +/// Calling any of these methods is a no-op on iOS as actions on that platform +/// typically don't provide haptic or acoustic feedback. +/// +/// All methods in this class are usually called from within a +/// [StatelessWidget.build] method or from a [State]'s methods as you have to +/// provide a [BuildContext]. +/// +/// {@tool snippet} +/// +/// To trigger platform-specific feedback before executing the actual callback: +/// +/// ```dart +/// class WidgetWithWrappedHandler extends StatelessWidget { +/// const WidgetWithWrappedHandler({super.key}); +/// +/// @override +/// Widget build(BuildContext context) { +/// return GestureDetector( +/// onTap: Feedback.wrapForTap(_onTapHandler, context), +/// onLongPress: Feedback.wrapForLongPress(_onLongPressHandler, context), +/// child: const Text('X'), +/// ); +/// } +/// +/// void _onTapHandler() { +/// // Respond to tap. +/// } +/// +/// void _onLongPressHandler() { +/// // Respond to long press. +/// } +/// } +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// Alternatively, you can also call [forTap] or [forLongPress] directly within +/// your tap or long press handler: +/// +/// ```dart +/// class WidgetWithExplicitCall extends StatelessWidget { +/// const WidgetWithExplicitCall({super.key}); +/// +/// @override +/// Widget build(BuildContext context) { +/// return GestureDetector( +/// onTap: () { +/// // Do some work (e.g. check if the tap is valid) +/// Feedback.forTap(context); +/// // Do more work (e.g. respond to the tap) +/// }, +/// onLongPress: () { +/// // Do some work (e.g. check if the long press is valid) +/// Feedback.forLongPress(context); +/// // Do more work (e.g. respond to the long press) +/// }, +/// child: const Text('X'), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +abstract final class Feedback { + /// Provides platform-specific feedback for a tap. + /// + /// On Android the click system sound is played. On iOS this is a no-op. + /// + /// See also: + /// + /// * [wrapForTap] to trigger platform-specific feedback before executing a + /// [GestureTapCallback]. + static Future<void> forTap(BuildContext context) async { + context.findRenderObject()!.sendSemanticsEvent(const TapSemanticEvent()); + switch (_platform(context)) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + return SystemSound.play(SystemSoundType.click); + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return Future<void>.value(); + } + } + + /// Wraps a [GestureTapCallback] to provide platform specific feedback for a + /// tap before the provided callback is executed. + /// + /// On Android the platform-typical click system sound is played. On iOS this + /// is a no-op as that platform usually doesn't provide feedback for a tap. + /// + /// See also: + /// + /// * [forTap] to just trigger the platform-specific feedback without wrapping + /// a [GestureTapCallback]. + static GestureTapCallback? wrapForTap(GestureTapCallback? callback, BuildContext context) { + if (callback == null) { + return null; + } + return () { + Feedback.forTap(context); + callback(); + }; + } + + /// Provides platform-specific feedback for a long press. + /// + /// On Android the platform-typical vibration is triggered. On iOS this is a + /// no-op as that platform usually doesn't provide feedback for long presses. + /// + /// See also: + /// + /// * [wrapForLongPress] to trigger platform-specific feedback before + /// executing a [GestureLongPressCallback]. + static Future<void> forLongPress(BuildContext context) { + context.findRenderObject()!.sendSemanticsEvent(const LongPressSemanticsEvent()); + switch (_platform(context)) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + return HapticFeedback.vibrate(); + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return Future<void>.value(); + } + } + + /// Wraps a [GestureLongPressCallback] to provide platform specific feedback + /// for a long press before the provided callback is executed. + /// + /// On Android the platform-typical vibration is triggered. On iOS this + /// is a no-op as that platform usually doesn't provide feedback for a long + /// press. + /// + /// See also: + /// + /// * [forLongPress] to just trigger the platform-specific feedback without + /// wrapping a [GestureLongPressCallback]. + static GestureLongPressCallback? wrapForLongPress(GestureLongPressCallback? callback, BuildContext context) { + if (callback == null) { + return null; + } + return () { + Feedback.forLongPress(context); + callback(); + }; + } + + static TargetPlatform _platform(BuildContext context) => Theme.of(context).platform; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/filled_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/filled_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..b1772b4d17e5ffbc767e5ae389eb0dcba9a614d1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/filled_button.dart @@ -0,0 +1,787 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'button_style_button.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'filled_button_theme.dart'; +import 'ink_well.dart'; +import 'material_state.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +enum _FilledButtonVariant { filled, tonal } + +/// A Material Design filled button. +/// +/// Filled buttons have the most visual impact after the [FloatingActionButton], +/// and should be used for important, final actions that complete a flow, +/// like **Save**, **Join now**, or **Confirm**. +/// +/// A filled button is a label [child] displayed on a [Material] +/// widget. The label's [Text] and [Icon] widgets are displayed in +/// [style]'s [ButtonStyle.foregroundColor] and the button's filled +/// background is the [ButtonStyle.backgroundColor]. +/// +/// The filled button's default style is defined by +/// [defaultStyleOf]. The style of this filled button can be +/// overridden with its [style] parameter. The style of all filled +/// buttons in a subtree can be overridden with the +/// [FilledButtonTheme], and the style of all of the filled +/// buttons in an app can be overridden with the [Theme]'s +/// [ThemeData.filledButtonTheme] property. +/// +/// The static [styleFrom] method is a convenient way to create a +/// filled button [ButtonStyle] from simple values. +/// +/// If [onPressed] and [onLongPress] callbacks are null, then the +/// button will be disabled. +/// +/// To create a 'filled tonal' button, use [FilledButton.tonal]. +/// +/// {@tool dartpad} +/// This sample produces enabled and disabled filled and filled tonal +/// buttons. +/// +/// ** See code in examples/api/lib/material/filled_button/filled_button.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ElevatedButton], a filled button whose material elevates when pressed. +/// * [OutlinedButton], a button with an outlined border and no fill color. +/// * [TextButton], a button with no outline or fill color. +/// * <https://material.io/design/components/buttons.html> +/// * <https://m3.material.io/components/buttons> +class FilledButton extends ButtonStyleButton { + /// Create a FilledButton. + const FilledButton({ + super.key, + required super.onPressed, + super.onLongPress, + super.onHover, + super.onFocusChange, + super.style, + super.focusNode, + super.autofocus = false, + super.clipBehavior = Clip.none, + super.statesController, + required super.child, + }) : _variant = _FilledButtonVariant.filled; + + /// Create a filled button from [icon] and [label]. + /// + /// The icon and label are arranged in a row with padding at the start and end + /// and a gap between them. + factory FilledButton.icon({ + Key? key, + required VoidCallback? onPressed, + VoidCallback? onLongPress, + ValueChanged<bool>? onHover, + ValueChanged<bool>? onFocusChange, + ButtonStyle? style, + FocusNode? focusNode, + bool? autofocus, + Clip? clipBehavior, + MaterialStatesController? statesController, + required Widget icon, + required Widget label, + }) = _FilledButtonWithIcon; + + /// Create a tonal variant of FilledButton. + /// + /// A filled tonal button is an alternative middle ground between + /// [FilledButton] and [OutlinedButton]. They’re useful in contexts where + /// a lower-priority button requires slightly more emphasis than an + /// outline would give, such as "Next" in an onboarding flow. + const FilledButton.tonal({ + super.key, + required super.onPressed, + super.onLongPress, + super.onHover, + super.onFocusChange, + super.style, + super.focusNode, + super.autofocus = false, + super.clipBehavior = Clip.none, + super.statesController, + required super.child, + }) : _variant = _FilledButtonVariant.tonal; + + /// Create a filled tonal button from [icon] and [label]. + /// + /// The icon and label are arranged in a row with padding at the start and end + /// and a gap between them. + factory FilledButton.tonalIcon({ + Key? key, + required VoidCallback? onPressed, + VoidCallback? onLongPress, + ValueChanged<bool>? onHover, + ValueChanged<bool>? onFocusChange, + ButtonStyle? style, + FocusNode? focusNode, + bool? autofocus, + Clip? clipBehavior, + MaterialStatesController? statesController, + required Widget icon, + required Widget label, + }) { + return _FilledButtonWithIcon.tonal( + key: key, + onPressed: onPressed, + onLongPress: onLongPress, + onHover: onHover, + onFocusChange: onFocusChange, + style: style, + focusNode: focusNode, + autofocus: autofocus, + clipBehavior: clipBehavior, + statesController: statesController, + icon: icon, + label: label, + ); + } + + /// A static convenience method that constructs a filled button + /// [ButtonStyle] given simple values. + /// + /// The [foregroundColor], and [disabledForegroundColor] colors are used to create a + /// [MaterialStateProperty] [ButtonStyle.foregroundColor] value. The + /// [backgroundColor] and [disabledBackgroundColor] are used to create a + /// [MaterialStateProperty] [ButtonStyle.backgroundColor] value. + /// + /// The button's elevations are defined relative to the [elevation] + /// parameter. The disabled elevation is the same as the parameter + /// value, [elevation] + 2 is used when the button is hovered + /// or focused, and elevation + 6 is used when the button is pressed. + /// + /// Similarly, the [enabledMouseCursor] and [disabledMouseCursor] + /// parameters are used to construct [ButtonStyle.mouseCursor]. + /// + /// All of the other parameters are either used directly or used to + /// create a [MaterialStateProperty] with a single value for all + /// states. + /// + /// All parameters default to null, by default this method returns + /// a [ButtonStyle] that doesn't override anything. + /// + /// For example, to override the default text and icon colors for a + /// [FilledButton], as well as its overlay color, with all of the + /// standard opacity adjustments for the pressed, focused, and + /// hovered states, one could write: + /// + /// ```dart + /// FilledButton( + /// style: FilledButton.styleFrom(foregroundColor: Colors.green), + /// onPressed: () {}, + /// child: const Text('Filled button'), + /// ); + /// ``` + /// + /// or for a Filled tonal variant: + /// ```dart + /// FilledButton.tonal( + /// style: FilledButton.styleFrom(foregroundColor: Colors.green), + /// onPressed: () {}, + /// child: const Text('Filled tonal button'), + /// ); + /// ``` + static ButtonStyle styleFrom({ + Color? foregroundColor, + Color? backgroundColor, + Color? disabledForegroundColor, + Color? disabledBackgroundColor, + Color? shadowColor, + Color? surfaceTintColor, + double? elevation, + TextStyle? textStyle, + EdgeInsetsGeometry? padding, + Size? minimumSize, + Size? fixedSize, + Size? maximumSize, + BorderSide? side, + OutlinedBorder? shape, + MouseCursor? enabledMouseCursor, + MouseCursor? disabledMouseCursor, + VisualDensity? visualDensity, + MaterialTapTargetSize? tapTargetSize, + Duration? animationDuration, + bool? enableFeedback, + AlignmentGeometry? alignment, + InteractiveInkFeatureFactory? splashFactory, + }) { + final MaterialStateProperty<Color?>? backgroundColorProp = + (backgroundColor == null && disabledBackgroundColor == null) + ? null + : _FilledButtonDefaultColor(backgroundColor, disabledBackgroundColor); + final Color? foreground = foregroundColor; + final Color? disabledForeground = disabledForegroundColor; + final MaterialStateProperty<Color?>? foregroundColorProp = + (foreground == null && disabledForeground == null) + ? null + : _FilledButtonDefaultColor(foreground, disabledForeground); + final MaterialStateProperty<Color?>? overlayColor = (foreground == null) + ? null + : _FilledButtonDefaultOverlay(foreground); + final MaterialStateProperty<MouseCursor?> mouseCursor = _FilledButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor); + + return ButtonStyle( + textStyle: MaterialStatePropertyAll<TextStyle?>(textStyle), + backgroundColor: backgroundColorProp, + foregroundColor: foregroundColorProp, + overlayColor: overlayColor, + shadowColor: ButtonStyleButton.allOrNull<Color>(shadowColor), + surfaceTintColor: ButtonStyleButton.allOrNull<Color>(surfaceTintColor), + elevation: ButtonStyleButton.allOrNull(elevation), + padding: ButtonStyleButton.allOrNull<EdgeInsetsGeometry>(padding), + minimumSize: ButtonStyleButton.allOrNull<Size>(minimumSize), + fixedSize: ButtonStyleButton.allOrNull<Size>(fixedSize), + maximumSize: ButtonStyleButton.allOrNull<Size>(maximumSize), + side: ButtonStyleButton.allOrNull<BorderSide>(side), + shape: ButtonStyleButton.allOrNull<OutlinedBorder>(shape), + mouseCursor: mouseCursor, + visualDensity: visualDensity, + tapTargetSize: tapTargetSize, + animationDuration: animationDuration, + enableFeedback: enableFeedback, + alignment: alignment, + splashFactory: splashFactory, + ); + } + + final _FilledButtonVariant _variant; + + /// Defines the button's default appearance. + /// + /// The button [child]'s [Text] and [Icon] widgets are rendered with + /// the [ButtonStyle]'s foreground color. The button's [InkWell] adds + /// the style's overlay color when the button is focused, hovered + /// or pressed. The button's background color becomes its [Material] + /// color. + /// + /// All of the ButtonStyle's defaults appear below. In this list + /// "Theme.foo" is shorthand for `Theme.of(context).foo`. Color + /// scheme values like "onSurface(0.38)" are shorthand for + /// `onSurface.withOpacity(0.38)`. [MaterialStateProperty] valued + /// properties that are not followed by a sublist have the same + /// value for all states, otherwise the values are as specified for + /// each state, and "others" means all other states. + /// + /// {@macro flutter.material.elevated_button.default_font_size} + /// + /// The color of the [ButtonStyle.textStyle] is not used, the + /// [ButtonStyle.foregroundColor] color is used instead. + /// + /// * `textStyle` - Theme.textTheme.labelLarge + /// * `backgroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.12) + /// * others - Theme.colorScheme.secondaryContainer + /// * `foregroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.38) + /// * others - Theme.colorScheme.onSecondaryContainer + /// * `overlayColor` + /// * hovered - Theme.colorScheme.onSecondaryContainer(0.08) + /// * focused or pressed - Theme.colorScheme.onSecondaryContainer(0.12) + /// * `shadowColor` - Theme.colorScheme.shadow + /// * `surfaceTintColor` - null + /// * `elevation` + /// * disabled - 0 + /// * default - 0 + /// * hovered - 1 + /// * focused or pressed - 0 + /// * `padding` + /// * `default font size <= 14` - horizontal(16) + /// * `14 < default font size <= 28` - lerp(horizontal(16), horizontal(8)) + /// * `28 < default font size <= 36` - lerp(horizontal(8), horizontal(4)) + /// * `36 < default font size` - horizontal(4) + /// * `minimumSize` - Size(64, 40) + /// * `fixedSize` - null + /// * `maximumSize` - Size.infinite + /// * `side` - null + /// * `shape` - StadiumBorder() + /// * `mouseCursor` + /// * disabled - SystemMouseCursors.basic + /// * others - SystemMouseCursors.click + /// * `visualDensity` - Theme.visualDensity + /// * `tapTargetSize` - Theme.materialTapTargetSize + /// * `animationDuration` - kThemeChangeDuration + /// * `enableFeedback` - true + /// * `alignment` - Alignment.center + /// * `splashFactory` - Theme.splashFactory + /// + /// The default padding values for the [FilledButton.icon] factory are slightly different: + /// + /// * `padding` + /// * `default font size <= 14` - start(12) end(16) + /// * `14 < default font size <= 28` - lerp(start(12) end(16), horizontal(8)) + /// * `28 < default font size <= 36` - lerp(horizontal(8), horizontal(4)) + /// * `36 < default font size` - horizontal(4) + /// + /// The default value for `side`, which defines the appearance of the button's + /// outline, is null. That means that the outline is defined by the button + /// shape's [OutlinedBorder.side]. Typically the default value of an + /// [OutlinedBorder]'s side is [BorderSide.none], so an outline is not drawn. + /// + /// ## Material 3 defaults + /// + /// If [ThemeData.useMaterial3] is set to true the following defaults will + /// be used: + /// + /// * `textStyle` - Theme.textTheme.labelLarge + /// * `backgroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.12) + /// * others - Theme.colorScheme.secondaryContainer + /// * `foregroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.38) + /// * others - Theme.colorScheme.onSecondaryContainer + /// * `overlayColor` + /// * hovered - Theme.colorScheme.onSecondaryContainer(0.08) + /// * focused or pressed - Theme.colorScheme.onSecondaryContainer(0.12) + /// * `shadowColor` - Theme.colorScheme.shadow + /// * `surfaceTintColor` - Colors.transparent + /// * `elevation` + /// * disabled - 0 + /// * default - 1 + /// * hovered - 3 + /// * focused or pressed - 1 + /// * `padding` + /// * `default font size <= 14` - horizontal(24) + /// * `14 < default font size <= 28` - lerp(horizontal(24), horizontal(12)) + /// * `28 < default font size <= 36` - lerp(horizontal(12), horizontal(6)) + /// * `36 < default font size` - horizontal(6) + /// * `minimumSize` - Size(64, 40) + /// * `fixedSize` - null + /// * `maximumSize` - Size.infinite + /// * `side` - null + /// * `shape` - StadiumBorder() + /// * `mouseCursor` + /// * disabled - SystemMouseCursors.basic + /// * others - SystemMouseCursors.click + /// * `visualDensity` - Theme.visualDensity + /// * `tapTargetSize` - Theme.materialTapTargetSize + /// * `animationDuration` - kThemeChangeDuration + /// * `enableFeedback` - true + /// * `alignment` - Alignment.center + /// * `splashFactory` - Theme.splashFactory + /// + /// For the [FilledButton.icon] factory, the start (generally the left) value of + /// [padding] is reduced from 24 to 16. + @override + ButtonStyle defaultStyleOf(BuildContext context) { + switch (_variant) { + case _FilledButtonVariant.filled: + return _FilledButtonDefaultsM3(context); + case _FilledButtonVariant.tonal: + return _FilledTonalButtonDefaultsM3(context); + } + } + + /// Returns the [FilledButtonThemeData.style] of the closest + /// [FilledButtonTheme] ancestor. + @override + ButtonStyle? themeStyleOf(BuildContext context) { + return FilledButtonTheme.of(context).style; + } +} + +EdgeInsetsGeometry _scaledPadding(BuildContext context) { + final ThemeData theme = Theme.of(context); + final double defaultFontSize = theme.textTheme.labelLarge?.fontSize ?? 14.0; + final double effectiveTextScale = MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0; + final double padding1x = theme.useMaterial3 ? 24.0 : 16.0; + return ButtonStyleButton.scaledPadding( + EdgeInsets.symmetric(horizontal: padding1x), + EdgeInsets.symmetric(horizontal: padding1x / 2), + EdgeInsets.symmetric(horizontal: padding1x / 2 / 2), + effectiveTextScale, + ); +} + +@immutable +class _FilledButtonDefaultColor extends MaterialStateProperty<Color?> with Diagnosticable { + _FilledButtonDefaultColor(this.color, this.disabled); + + final Color? color; + final Color? disabled; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabled; + } + return color; + } +} + +@immutable +class _FilledButtonDefaultOverlay extends MaterialStateProperty<Color?> with Diagnosticable { + _FilledButtonDefaultOverlay(this.overlay); + + final Color overlay; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return overlay.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return overlay.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return overlay.withOpacity(0.12); + } + return null; + } +} + +@immutable +class _FilledButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor?> with Diagnosticable { + _FilledButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor); + + final MouseCursor? enabledCursor; + final MouseCursor? disabledCursor; + + @override + MouseCursor? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabledCursor; + } + return enabledCursor; + } +} + +class _FilledButtonWithIcon extends FilledButton { + _FilledButtonWithIcon({ + super.key, + required super.onPressed, + super.onLongPress, + super.onHover, + super.onFocusChange, + super.style, + super.focusNode, + bool? autofocus, + Clip? clipBehavior, + super.statesController, + required Widget icon, + required Widget label, + }) : super( + autofocus: autofocus ?? false, + clipBehavior: clipBehavior ?? Clip.none, + child: _FilledButtonWithIconChild(icon: icon, label: label) + ); + + _FilledButtonWithIcon.tonal({ + super.key, + required super.onPressed, + super.onLongPress, + super.onHover, + super.onFocusChange, + super.style, + super.focusNode, + bool? autofocus, + Clip? clipBehavior, + super.statesController, + required Widget icon, + required Widget label, + }) : super.tonal( + autofocus: autofocus ?? false, + clipBehavior: clipBehavior ?? Clip.none, + child: _FilledButtonWithIconChild(icon: icon, label: label) + ); + + @override + ButtonStyle defaultStyleOf(BuildContext context) { + final bool useMaterial3 = Theme.of(context).useMaterial3; + final ButtonStyle buttonStyle = super.defaultStyleOf(context); + final double defaultFontSize = buttonStyle.textStyle?.resolve(const <MaterialState>{})?.fontSize ?? 14.0; + final double effectiveTextScale = MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0; + + final EdgeInsetsGeometry scaledPadding = useMaterial3 + ? ButtonStyleButton.scaledPadding( + const EdgeInsetsDirectional.fromSTEB(16, 0, 24, 0), + const EdgeInsetsDirectional.fromSTEB(8, 0, 12, 0), + const EdgeInsetsDirectional.fromSTEB(4, 0, 6, 0), + effectiveTextScale, + ) : ButtonStyleButton.scaledPadding( + const EdgeInsetsDirectional.fromSTEB(12, 0, 16, 0), + const EdgeInsets.symmetric(horizontal: 8), + const EdgeInsetsDirectional.fromSTEB(8, 0, 4, 0), + effectiveTextScale, + ); + return buttonStyle.copyWith( + padding: MaterialStatePropertyAll<EdgeInsetsGeometry>(scaledPadding), + ); + } +} + +class _FilledButtonWithIconChild extends StatelessWidget { + const _FilledButtonWithIconChild({ required this.label, required this.icon }); + + final Widget label; + final Widget icon; + + @override + Widget build(BuildContext context) { + final double scale = MediaQuery.textScalerOf(context).textScaleFactor; + // Adjust the gap based on the text scale factor. Start at 8, and lerp + // to 4 based on how large the text is. + final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!; + return Row( + mainAxisSize: MainAxisSize.min, + children: <Widget>[icon, SizedBox(width: gap), Flexible(child: label)], + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - FilledButton + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _FilledButtonDefaultsM3 extends ButtonStyle { + _FilledButtonDefaultsM3(this.context) + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + MaterialStateProperty<TextStyle?> get textStyle => + MaterialStatePropertyAll<TextStyle?>(Theme.of(context).textTheme.labelLarge); + + @override + MaterialStateProperty<Color?>? get backgroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.12); + } + return _colors.primary; + }); + + @override + MaterialStateProperty<Color?>? get foregroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + return _colors.onPrimary; + }); + + @override + MaterialStateProperty<Color?>? get overlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return _colors.onPrimary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onPrimary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onPrimary.withOpacity(0.12); + } + return null; + }); + + @override + MaterialStateProperty<Color>? get shadowColor => + MaterialStatePropertyAll<Color>(_colors.shadow); + + @override + MaterialStateProperty<Color>? get surfaceTintColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<double>? get elevation => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return 0.0; + } + if (states.contains(MaterialState.pressed)) { + return 0.0; + } + if (states.contains(MaterialState.hovered)) { + return 1.0; + } + if (states.contains(MaterialState.focused)) { + return 0.0; + } + return 0.0; + }); + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding => + MaterialStatePropertyAll<EdgeInsetsGeometry>(_scaledPadding(context)); + + @override + MaterialStateProperty<Size>? get minimumSize => + const MaterialStatePropertyAll<Size>(Size(64.0, 40.0)); + + // No default fixedSize + + @override + MaterialStateProperty<Size>? get maximumSize => + const MaterialStatePropertyAll<Size>(Size.infinite); + + // No default side + + @override + MaterialStateProperty<OutlinedBorder>? get shape => + const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); + + @override + MaterialStateProperty<MouseCursor?>? get mouseCursor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return SystemMouseCursors.click; + }); + + @override + VisualDensity? get visualDensity => Theme.of(context).visualDensity; + + @override + MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize; + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; +} + +// END GENERATED TOKEN PROPERTIES - FilledButton + +// BEGIN GENERATED TOKEN PROPERTIES - FilledTonalButton + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _FilledTonalButtonDefaultsM3 extends ButtonStyle { + _FilledTonalButtonDefaultsM3(this.context) + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + MaterialStateProperty<TextStyle?> get textStyle => + MaterialStatePropertyAll<TextStyle?>(Theme.of(context).textTheme.labelLarge); + + @override + MaterialStateProperty<Color?>? get backgroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.12); + } + return _colors.secondaryContainer; + }); + + @override + MaterialStateProperty<Color?>? get foregroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + return _colors.onSecondaryContainer; + }); + + @override + MaterialStateProperty<Color?>? get overlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return _colors.onSecondaryContainer.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSecondaryContainer.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSecondaryContainer.withOpacity(0.12); + } + return null; + }); + + @override + MaterialStateProperty<Color>? get shadowColor => + MaterialStatePropertyAll<Color>(_colors.shadow); + + @override + MaterialStateProperty<Color>? get surfaceTintColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<double>? get elevation => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return 0.0; + } + if (states.contains(MaterialState.pressed)) { + return 0.0; + } + if (states.contains(MaterialState.hovered)) { + return 1.0; + } + if (states.contains(MaterialState.focused)) { + return 0.0; + } + return 0.0; + }); + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding => + MaterialStatePropertyAll<EdgeInsetsGeometry>(_scaledPadding(context)); + + @override + MaterialStateProperty<Size>? get minimumSize => + const MaterialStatePropertyAll<Size>(Size(64.0, 40.0)); + + // No default fixedSize + + @override + MaterialStateProperty<Size>? get maximumSize => + const MaterialStatePropertyAll<Size>(Size.infinite); + + // No default side + + @override + MaterialStateProperty<OutlinedBorder>? get shape => + const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); + + @override + MaterialStateProperty<MouseCursor?>? get mouseCursor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return SystemMouseCursors.click; + }); + + @override + VisualDensity? get visualDensity => Theme.of(context).visualDensity; + + @override + MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize; + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; +} + +// END GENERATED TOKEN PROPERTIES - FilledTonalButton diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/filled_button_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/filled_button_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..eebbf98e282d8b0e11c7229de3e211a86ddb9edf --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/filled_button_theme.dart @@ -0,0 +1,125 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// A [ButtonStyle] that overrides the default appearance of +/// [FilledButton]s when it's used with [FilledButtonTheme] or with the +/// overall [Theme]'s [ThemeData.filledButtonTheme]. +/// +/// The [style]'s properties override [FilledButton]'s default style, +/// i.e. the [ButtonStyle] returned by [FilledButton.defaultStyleOf]. Only +/// the style's non-null property values or resolved non-null +/// [MaterialStateProperty] values are used. +/// +/// See also: +/// +/// * [FilledButtonTheme], the theme which is configured with this class. +/// * [FilledButton.defaultStyleOf], which returns the default [ButtonStyle] +/// for text buttons. +/// * [FilledButton.styleFrom], which converts simple values into a +/// [ButtonStyle] that's consistent with [FilledButton]'s defaults. +/// * [MaterialStateProperty.resolve], "resolve" a material state property +/// to a simple value based on a set of [MaterialState]s. +/// * [ThemeData.filledButtonTheme], which can be used to override the default +/// [ButtonStyle] for [FilledButton]s below the overall [Theme]. +@immutable +class FilledButtonThemeData with Diagnosticable { + /// Creates an [FilledButtonThemeData]. + /// + /// The [style] may be null. + const FilledButtonThemeData({ this.style }); + + /// Overrides for [FilledButton]'s default style. + /// + /// Non-null properties or non-null resolved [MaterialStateProperty] + /// values override the [ButtonStyle] returned by + /// [FilledButton.defaultStyleOf]. + /// + /// If [style] is null, then this theme doesn't override anything. + final ButtonStyle? style; + + /// Linearly interpolate between two filled button themes. + static FilledButtonThemeData? lerp(FilledButtonThemeData? a, FilledButtonThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return FilledButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + ); + } + + @override + int get hashCode => style.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is FilledButtonThemeData && other.style == style; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ButtonStyle>('style', style, defaultValue: null)); + } +} + +/// Overrides the default [ButtonStyle] of its [FilledButton] descendants. +/// +/// See also: +/// +/// * [FilledButtonThemeData], which is used to configure this theme. +/// * [FilledButton.defaultStyleOf], which returns the default [ButtonStyle] +/// for filled buttons. +/// * [FilledButton.styleFrom], which converts simple values into a +/// [ButtonStyle] that's consistent with [FilledButton]'s defaults. +/// * [ThemeData.filledButtonTheme], which can be used to override the default +/// [ButtonStyle] for [FilledButton]s below the overall [Theme]. +class FilledButtonTheme extends InheritedTheme { + /// Create a [FilledButtonTheme]. + const FilledButtonTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The configuration of this theme. + final FilledButtonThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [FilledButtonTheme] widget, then + /// [ThemeData.filledButtonTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// FilledButtonThemeData theme = FilledButtonTheme.of(context); + /// ``` + static FilledButtonThemeData of(BuildContext context) { + final FilledButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<FilledButtonTheme>(); + return buttonTheme?.data ?? Theme.of(context).filledButtonTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return FilledButtonTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(FilledButtonTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/filter_chip.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/filter_chip.dart new file mode 100644 index 0000000000000000000000000000000000000000..7770cf23b84b803f4609c82ff6af7ca5d4ad8936 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/filter_chip.dart @@ -0,0 +1,370 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/widgets.dart'; + +import 'chip.dart'; +import 'chip_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'debug.dart'; +import 'icons.dart'; +import 'material_state.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +enum _ChipVariant { flat, elevated } + +/// A Material Design filter chip. +/// +/// Filter chips use tags or descriptive words as a way to filter content. +/// +/// Filter chips are a good alternative to [Checkbox] or [Switch] widgets. +/// Unlike these alternatives, filter chips allow for clearly delineated and +/// exposed options in a compact area. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// {@tool dartpad} +/// This example shows how to use [FilterChip]s to filter through exercises. +/// +/// ** See code in examples/api/lib/material/filter_chip/filter_chip.0.dart ** +/// {@end-tool} +/// +/// ## Material Design 3 +/// +/// [FilterChip] can be used for multiple select Filter chip from +/// Material Design 3. If [ThemeData.useMaterial3] is true, then [FilterChip] +/// will be styled to match the Material Design 3 specification for Filter +/// chips. Use [ChoiceChip] for single select Filter chips. +/// +/// See also: +/// +/// * [Chip], a chip that displays information and can be deleted. +/// * [InputChip], a chip that represents a complex piece of information, such +/// as an entity (person, place, or thing) or conversational text, in a +/// compact form. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [ActionChip], represents an action related to primary content. +/// * [CircleAvatar], which shows images or initials of people. +/// * [Wrap], A widget that displays its children in multiple horizontal or +/// vertical runs. +/// * <https://material.io/design/components/chips.html> +class FilterChip extends StatelessWidget + implements + ChipAttributes, + DeletableChipAttributes, + SelectableChipAttributes, + CheckmarkableChipAttributes, + DisabledChipAttributes { + /// Create a chip that acts like a checkbox. + /// + /// The [selected], [label], [autofocus], and [clipBehavior] arguments must + /// not be null. The [pressElevation] and [elevation] must be null or + /// non-negative. Typically, [pressElevation] is greater than [elevation]. + const FilterChip({ + super.key, + this.avatar, + required this.label, + this.labelStyle, + this.labelPadding, + this.selected = false, + required this.onSelected, + this.deleteIcon, + this.onDeleted, + this.deleteIconColor, + this.deleteButtonTooltipMessage, + this.pressElevation, + this.disabledColor, + this.selectedColor, + this.tooltip, + this.side, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.color, + this.backgroundColor, + this.padding, + this.visualDensity, + this.materialTapTargetSize, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.iconTheme, + this.selectedShadowColor, + this.showCheckmark, + this.checkmarkColor, + this.avatarBorder = const CircleBorder(), + }) : assert(pressElevation == null || pressElevation >= 0.0), + assert(elevation == null || elevation >= 0.0), + _chipVariant = _ChipVariant.flat; + + /// Create an elevated chip that acts like a checkbox. + /// + /// The [selected], [label], [autofocus], and [clipBehavior] arguments must + /// not be null. The [pressElevation] and [elevation] must be null or + /// non-negative. Typically, [pressElevation] is greater than [elevation]. + const FilterChip.elevated({ + super.key, + this.avatar, + required this.label, + this.labelStyle, + this.labelPadding, + this.selected = false, + required this.onSelected, + this.deleteIcon, + this.onDeleted, + this.deleteIconColor, + this.deleteButtonTooltipMessage, + this.pressElevation, + this.disabledColor, + this.selectedColor, + this.tooltip, + this.side, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.color, + this.backgroundColor, + this.padding, + this.visualDensity, + this.materialTapTargetSize, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.iconTheme, + this.selectedShadowColor, + this.showCheckmark, + this.checkmarkColor, + this.avatarBorder = const CircleBorder(), + }) : assert(pressElevation == null || pressElevation >= 0.0), + assert(elevation == null || elevation >= 0.0), + _chipVariant = _ChipVariant.elevated; + + @override + final Widget? avatar; + @override + final Widget label; + @override + final TextStyle? labelStyle; + @override + final EdgeInsetsGeometry? labelPadding; + @override + final bool selected; + @override + final ValueChanged<bool>? onSelected; + @override + final Widget? deleteIcon; + @override + final VoidCallback? onDeleted; + @override + final Color? deleteIconColor; + @override + final String? deleteButtonTooltipMessage; + @override + final double? pressElevation; + @override + final Color? disabledColor; + @override + final Color? selectedColor; + @override + final String? tooltip; + @override + final BorderSide? side; + @override + final OutlinedBorder? shape; + @override + final Clip clipBehavior; + @override + final FocusNode? focusNode; + @override + final bool autofocus; + @override + final MaterialStateProperty<Color?>? color; + @override + final Color? backgroundColor; + @override + final EdgeInsetsGeometry? padding; + @override + final VisualDensity? visualDensity; + @override + final MaterialTapTargetSize? materialTapTargetSize; + @override + final double? elevation; + @override + final Color? shadowColor; + @override + final Color? surfaceTintColor; + @override + final Color? selectedShadowColor; + @override + final bool? showCheckmark; + @override + final Color? checkmarkColor; + @override + final ShapeBorder avatarBorder; + @override + final IconThemeData? iconTheme; + + @override + bool get isEnabled => onSelected != null; + + final _ChipVariant _chipVariant; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + final ChipThemeData? defaults = Theme.of(context).useMaterial3 + ? _FilterChipDefaultsM3(context, isEnabled, selected, _chipVariant) + : null; + final Widget? resolvedDeleteIcon = deleteIcon + ?? (Theme.of(context).useMaterial3 ? const Icon(Icons.clear, size: 18) : null); + return RawChip( + defaultProperties: defaults, + avatar: avatar, + label: label, + labelStyle: labelStyle, + labelPadding: labelPadding, + onSelected: onSelected, + deleteIcon: resolvedDeleteIcon, + onDeleted: onDeleted, + deleteIconColor: deleteIconColor, + deleteButtonTooltipMessage: deleteButtonTooltipMessage, + pressElevation: pressElevation, + selected: selected, + tooltip: tooltip, + side: side, + shape: shape, + clipBehavior: clipBehavior, + focusNode: focusNode, + autofocus: autofocus, + color: color, + backgroundColor: backgroundColor, + disabledColor: disabledColor, + selectedColor: selectedColor, + padding: padding, + visualDensity: visualDensity, + isEnabled: isEnabled, + materialTapTargetSize: materialTapTargetSize, + elevation: elevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + selectedShadowColor: selectedShadowColor, + showCheckmark: showCheckmark, + checkmarkColor: checkmarkColor, + avatarBorder: avatarBorder, + iconTheme: iconTheme, + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - FilterChip + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _FilterChipDefaultsM3 extends ChipThemeData { + _FilterChipDefaultsM3( + this.context, + this.isEnabled, + this.isSelected, + this._chipVariant, + ) : super( + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))), + showCheckmark: true, + ); + + final BuildContext context; + final bool isEnabled; + final bool isSelected; + final _ChipVariant _chipVariant; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + double? get elevation => _chipVariant == _ChipVariant.flat + ? 0.0 + : isEnabled ? 1.0 : 0.0; + + @override + double? get pressElevation => 1.0; + + @override + TextStyle? get labelStyle => _textTheme.labelLarge; + + @override + MaterialStateProperty<Color?>? get color => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected) && states.contains(MaterialState.disabled)) { + return _chipVariant == _ChipVariant.flat + ? _colors.onSurface.withOpacity(0.12) + : _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.disabled)) { + return _chipVariant == _ChipVariant.flat + ? null + : _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.selected)) { + return _chipVariant == _ChipVariant.flat + ? _colors.secondaryContainer + : _colors.secondaryContainer; + } + return _chipVariant == _ChipVariant.flat + ? null + : null; + }); + + @override + Color? get shadowColor => _chipVariant == _ChipVariant.flat + ? Colors.transparent + : _colors.shadow; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + Color? get checkmarkColor => _colors.onSecondaryContainer; + + @override + Color? get deleteIconColor => _colors.onSecondaryContainer; + + @override + BorderSide? get side => _chipVariant == _ChipVariant.flat && !isSelected + ? isEnabled + ? BorderSide(color: _colors.outline) + : BorderSide(color: _colors.onSurface.withOpacity(0.12)) + : const BorderSide(color: Colors.transparent); + + @override + IconThemeData? get iconTheme => IconThemeData( + color: isEnabled + ? null + : _colors.onSurface, + size: 18.0, + ); + + @override + EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0); + + /// The chip at text scale 1 starts with 8px on each side and as text scaling + /// gets closer to 2 the label padding is linearly interpolated from 8px to 4px. + /// Once the widget has a text scaling of 2 or higher than the label padding + /// remains 4px. + @override + EdgeInsetsGeometry? get labelPadding => EdgeInsets.lerp( + const EdgeInsets.symmetric(horizontal: 8.0), + const EdgeInsets.symmetric(horizontal: 4.0), + clampDouble(MediaQuery.textScalerOf(context).textScaleFactor - 1.0, 0.0, 1.0), + )!; +} + +// END GENERATED TOKEN PROPERTIES - FilterChip diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/flexible_space_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/flexible_space_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..4611e96dbb66daf9ec9144889ae45b932e631039 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/flexible_space_bar.dart @@ -0,0 +1,482 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'constants.dart'; +import 'theme.dart'; + +/// The collapsing effect while the space bar collapses from its full size. +enum CollapseMode { + /// The background widget will scroll in a parallax fashion. + parallax, + + /// The background widget pin in place until it reaches the min extent. + pin, + + /// The background widget will act as normal with no collapsing effect. + none, +} + +/// The stretching effect while the space bar stretches beyond its full size. +enum StretchMode { + /// The background widget will expand to fill the extra space. + zoomBackground, + + /// The background will blur using a [ImageFilter.blur] effect. + blurBackground, + + /// The title will fade away as the user over-scrolls. + fadeTitle, +} + +/// The part of a Material Design [AppBar] that expands, collapses, and +/// stretches. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=mSc7qFzxHDw} +/// +/// Most commonly used in the [SliverAppBar.flexibleSpace] field, a flexible +/// space bar expands and contracts as the app scrolls so that the [AppBar] +/// reaches from the top of the app to the top of the scrolling contents of the +/// app. When using [SliverAppBar.flexibleSpace], the [SliverAppBar.expandedHeight] +/// must be large enough to accommodate the [SliverAppBar.flexibleSpace] widget. +/// +/// Furthermore is included functionality for stretch behavior. When +/// [SliverAppBar.stretch] is true, and your [ScrollPhysics] allow for +/// overscroll, this space will stretch with the overscroll. +/// +/// The widget that sizes the [AppBar] must wrap it in the widget returned by +/// [FlexibleSpaceBar.createSettings], to convey sizing information down to the +/// [FlexibleSpaceBar]. +/// +/// {@tool dartpad} +/// This sample application demonstrates the different features of the +/// [FlexibleSpaceBar] when used in a [SliverAppBar]. This app bar is configured +/// to stretch into the overscroll space, and uses the +/// [FlexibleSpaceBar.stretchModes] to apply `fadeTitle`, `blurBackground` and +/// `zoomBackground`. The app bar also makes use of [CollapseMode.parallax] by +/// default. +/// +/// ** See code in examples/api/lib/material/flexible_space_bar/flexible_space_bar.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverAppBar], which implements the expanding and contracting. +/// * [AppBar], which is used by [SliverAppBar]. +/// * <https://material.io/design/components/app-bars-top.html#behavior> +class FlexibleSpaceBar extends StatefulWidget { + /// Creates a flexible space bar. + /// + /// Most commonly used in the [AppBar.flexibleSpace] field. + const FlexibleSpaceBar({ + super.key, + this.title, + this.background, + this.centerTitle, + this.titlePadding, + this.collapseMode = CollapseMode.parallax, + this.stretchModes = const <StretchMode>[StretchMode.zoomBackground], + this.expandedTitleScale = 1.5, + }) : assert(expandedTitleScale >= 1); + + /// The primary contents of the flexible space bar when expanded. + /// + /// Typically a [Text] widget. + final Widget? title; + + /// Shown behind the [title] when expanded. + /// + /// Typically an [Image] widget with [Image.fit] set to [BoxFit.cover]. + final Widget? background; + + /// Whether the title should be centered. + /// + /// By default this property is true if the current target platform + /// is [TargetPlatform.iOS] or [TargetPlatform.macOS], false otherwise. + final bool? centerTitle; + + /// Collapse effect while scrolling. + /// + /// Defaults to [CollapseMode.parallax]. + final CollapseMode collapseMode; + + /// Stretch effect while over-scrolling. + /// + /// Defaults to include [StretchMode.zoomBackground]. + final List<StretchMode> stretchModes; + + /// Defines how far the [title] is inset from either the widget's + /// bottom-left or its center. + /// + /// Typically this property is used to adjust how far the title is + /// inset from the bottom-left and it is specified along with + /// [centerTitle] false. + /// + /// By default the value of this property is + /// `EdgeInsetsDirectional.only(start: 72, bottom: 16)` if the title is + /// not centered, `EdgeInsetsDirectional.only(start: 0, bottom: 16)` otherwise. + final EdgeInsetsGeometry? titlePadding; + + /// Defines how much the title is scaled when the FlexibleSpaceBar is expanded + /// due to the user scrolling downwards. The title is scaled uniformly on the + /// x and y axes while maintaining its bottom-left position (bottom-center if + /// [centerTitle] is true). + /// + /// Defaults to 1.5 and must be greater than 1. + final double expandedTitleScale; + + /// Wraps a widget that contains an [AppBar] to convey sizing information down + /// to the [FlexibleSpaceBar]. + /// + /// Used by [Scaffold] and [SliverAppBar]. + /// + /// `toolbarOpacity` affects how transparent the text within the toolbar + /// appears. `minExtent` sets the minimum height of the resulting + /// [FlexibleSpaceBar] when fully collapsed. `maxExtent` sets the maximum + /// height of the resulting [FlexibleSpaceBar] when fully expanded. + /// `currentExtent` sets the scale of the [FlexibleSpaceBar.background] and + /// [FlexibleSpaceBar.title] widgets of [FlexibleSpaceBar] upon + /// initialization. `scrolledUnder` is true if the [FlexibleSpaceBar] + /// overlaps the app's primary scrollable, false if it does not, and null + /// if the caller has not determined as much. + /// See also: + /// + /// * [FlexibleSpaceBarSettings] which creates a settings object that can be + /// used to specify these settings to a [FlexibleSpaceBar]. + static Widget createSettings({ + double? toolbarOpacity, + double? minExtent, + double? maxExtent, + bool? isScrolledUnder, + bool? hasLeading, + required double currentExtent, + required Widget child, + }) { + return FlexibleSpaceBarSettings( + toolbarOpacity: toolbarOpacity ?? 1.0, + minExtent: minExtent ?? currentExtent, + maxExtent: maxExtent ?? currentExtent, + isScrolledUnder: isScrolledUnder, + hasLeading: hasLeading, + currentExtent: currentExtent, + child: child, + ); + } + + @override + State<FlexibleSpaceBar> createState() => _FlexibleSpaceBarState(); +} + +class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> { + bool _getEffectiveCenterTitle(ThemeData theme) { + if (widget.centerTitle != null) { + return widget.centerTitle!; + } + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return false; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return true; + } + } + + Alignment _getTitleAlignment(bool effectiveCenterTitle) { + if (effectiveCenterTitle) { + return Alignment.bottomCenter; + } + final TextDirection textDirection = Directionality.of(context); + switch (textDirection) { + case TextDirection.rtl: + return Alignment.bottomRight; + case TextDirection.ltr: + return Alignment.bottomLeft; + } + } + + double _getCollapsePadding(double t, FlexibleSpaceBarSettings settings) { + switch (widget.collapseMode) { + case CollapseMode.pin: + return -(settings.maxExtent - settings.currentExtent); + case CollapseMode.none: + return 0.0; + case CollapseMode.parallax: + final double deltaExtent = settings.maxExtent - settings.minExtent; + return -Tween<double>(begin: 0.0, end: deltaExtent / 4.0).transform(t); + } + } + + @override + Widget build(BuildContext context) { + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + final FlexibleSpaceBarSettings settings = context.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>()!; + + final List<Widget> children = <Widget>[]; + + final double deltaExtent = settings.maxExtent - settings.minExtent; + + // 0.0 -> Expanded + // 1.0 -> Collapsed to toolbar + final double t = clampDouble(1.0 - (settings.currentExtent - settings.minExtent) / deltaExtent, 0.0, 1.0); + + // background + if (widget.background != null) { + final double fadeStart = math.max(0.0, 1.0 - kToolbarHeight / deltaExtent); + const double fadeEnd = 1.0; + assert(fadeStart <= fadeEnd); + // If the min and max extent are the same, the app bar cannot collapse + // and the content should be visible, so opacity = 1. + final double opacity = settings.maxExtent == settings.minExtent + ? 1.0 + : 1.0 - Interval(fadeStart, fadeEnd).transform(t); + double height = settings.maxExtent; + + // StretchMode.zoomBackground + if (widget.stretchModes.contains(StretchMode.zoomBackground) && + constraints.maxHeight > height) { + height = constraints.maxHeight; + } + final double topPadding = _getCollapsePadding(t, settings); + children.add(Positioned( + top: topPadding, + left: 0.0, + right: 0.0, + height: height, + child: _FlexibleSpaceHeaderOpacity( + // IOS is relying on this semantics node to correctly traverse + // through the app bar when it is collapsed. + alwaysIncludeSemantics: true, + opacity: opacity, + child: widget.background + ), + )); + + // StretchMode.blurBackground + if (widget.stretchModes.contains(StretchMode.blurBackground) && + constraints.maxHeight > settings.maxExtent) { + final double blurAmount = (constraints.maxHeight - settings.maxExtent) / 10; + children.add(Positioned.fill( + child: BackdropFilter( + filter: ui.ImageFilter.blur( + sigmaX: blurAmount, + sigmaY: blurAmount, + ), + child: Container( + color: Colors.transparent, + ), + ), + )); + } + } + + // title + if (widget.title != null) { + final ThemeData theme = Theme.of(context); + + Widget? title; + switch (theme.platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + title = widget.title; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + title = Semantics( + namesRoute: true, + child: widget.title, + ); + } + + // StretchMode.fadeTitle + if (widget.stretchModes.contains(StretchMode.fadeTitle) && + constraints.maxHeight > settings.maxExtent) { + final double stretchOpacity = 1 - + clampDouble( + (constraints.maxHeight - settings.maxExtent) / 100, + 0.0, + 1.0); + title = Opacity( + opacity: stretchOpacity, + child: title, + ); + } + + final double opacity = settings.toolbarOpacity; + if (opacity > 0.0) { + TextStyle titleStyle = theme.primaryTextTheme.titleLarge!; + titleStyle = titleStyle.copyWith( + color: titleStyle.color!.withOpacity(opacity), + ); + final bool effectiveCenterTitle = _getEffectiveCenterTitle(theme); + final EdgeInsetsGeometry padding = widget.titlePadding ?? + EdgeInsetsDirectional.only( + start: effectiveCenterTitle && !(settings.hasLeading ?? false) ? 0.0 : 72.0, + bottom: 16.0, + ); + final double scaleValue = Tween<double>(begin: widget.expandedTitleScale, end: 1.0).transform(t); + final Matrix4 scaleTransform = Matrix4.identity() + ..scale(scaleValue, scaleValue, 1.0); + final Alignment titleAlignment = _getTitleAlignment(effectiveCenterTitle); + children.add(Container( + padding: padding, + child: Transform( + alignment: titleAlignment, + transform: scaleTransform, + child: Align( + alignment: titleAlignment, + child: DefaultTextStyle( + style: titleStyle, + child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return Container( + width: constraints.maxWidth / scaleValue, + alignment: titleAlignment, + child: title, + ); + }, + ), + ), + ), + ), + )); + } + } + + return ClipRect(child: Stack(children: children)); + }, + ); + } +} + +/// Provides sizing and opacity information to a [FlexibleSpaceBar]. +/// +/// See also: +/// +/// * [FlexibleSpaceBar] which creates a flexible space bar. +class FlexibleSpaceBarSettings extends InheritedWidget { + /// Creates a Flexible Space Bar Settings widget. + /// + /// Used by [Scaffold] and [SliverAppBar]. [child] must have a + /// [FlexibleSpaceBar] widget in its tree for the settings to take affect. + const FlexibleSpaceBarSettings({ + super.key, + required this.toolbarOpacity, + required this.minExtent, + required this.maxExtent, + required this.currentExtent, + required super.child, + this.isScrolledUnder, + this.hasLeading, + }) : assert(minExtent >= 0), + assert(maxExtent >= 0), + assert(currentExtent >= 0), + assert(toolbarOpacity >= 0.0), + assert(minExtent <= maxExtent), + assert(minExtent <= currentExtent), + assert(currentExtent <= maxExtent); + + /// Affects how transparent the text within the toolbar appears. + final double toolbarOpacity; + + /// Minimum height of the resulting [FlexibleSpaceBar] when fully collapsed. + final double minExtent; + + /// Maximum height of the resulting [FlexibleSpaceBar] when fully expanded. + final double maxExtent; + + /// If the [FlexibleSpaceBar.title] or the [FlexibleSpaceBar.background] is + /// not null, then this value is used to calculate the relative scale of + /// these elements upon initialization. + final double currentExtent; + + /// True if the FlexibleSpaceBar overlaps the primary scrollable's contents. + /// + /// This value is used by the [AppBar] to resolve + /// [AppBar.backgroundColor] against [MaterialState.scrolledUnder], + /// i.e. to enable apps to specify different colors when content + /// has been scrolled up and behind the app bar. + /// + /// Null if the caller hasn't determined if the FlexibleSpaceBar + /// overlaps the primary scrollable's contents. + final bool? isScrolledUnder; + + /// True if the FlexibleSpaceBar has a leading widget. + /// + /// This value is used by the [FlexibleSpaceBar] to determine + /// if there should be a gap between the leading widget and + /// the title. + /// + /// Null if the caller hasn't determined if the FlexibleSpaceBar + /// has a leading widget. + final bool? hasLeading; + + @override + bool updateShouldNotify(FlexibleSpaceBarSettings oldWidget) { + return toolbarOpacity != oldWidget.toolbarOpacity + || minExtent != oldWidget.minExtent + || maxExtent != oldWidget.maxExtent + || currentExtent != oldWidget.currentExtent + || isScrolledUnder != oldWidget.isScrolledUnder + || hasLeading != oldWidget.hasLeading; + } +} + +// We need the child widget to repaint, however both the opacity +// and potentially `widget.background` can be constant which won't +// lead to repainting. +// see: https://github.com/flutter/flutter/issues/127836 +class _FlexibleSpaceHeaderOpacity extends SingleChildRenderObjectWidget { + const _FlexibleSpaceHeaderOpacity({required this.opacity, required super.child, required this.alwaysIncludeSemantics}); + + final double opacity; + final bool alwaysIncludeSemantics; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderFlexibleSpaceHeaderOpacity(opacity: opacity, alwaysIncludeSemantics: alwaysIncludeSemantics); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderFlexibleSpaceHeaderOpacity renderObject) { + renderObject + ..alwaysIncludeSemantics = alwaysIncludeSemantics + ..opacity = opacity; + } +} + +class _RenderFlexibleSpaceHeaderOpacity extends RenderOpacity { + _RenderFlexibleSpaceHeaderOpacity({super.opacity, super.alwaysIncludeSemantics}); + + @override + bool get isRepaintBoundary => false; + + @override + void paint(PaintingContext context, Offset offset) { + if (child == null) { + return; + } + if ((opacity * 255).roundToDouble() <= 0) { + layer = null; + return; + } + assert(needsCompositing); + layer = context.pushOpacity(offset, (opacity * 255).round(), super.paint, oldLayer: layer as OpacityLayer?); + assert(() { + layer!.debugCreator = debugCreator; + return true; + }()); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/floating_action_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/floating_action_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..e692e0ab76cfa7781ec1fdf3a6aabb2d9e02d1ce --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/floating_action_button.dart @@ -0,0 +1,843 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'button.dart'; +import 'color_scheme.dart'; +import 'floating_action_button_theme.dart'; +import 'material_state.dart'; +import 'scaffold.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; +import 'tooltip.dart'; + +class _DefaultHeroTag { + const _DefaultHeroTag(); + @override + String toString() => '<default FloatingActionButton tag>'; +} + +enum _FloatingActionButtonType { + regular, + small, + large, + extended, +} + +/// A Material Design floating action button. +/// +/// A floating action button is a circular icon button that hovers over content +/// to promote a primary action in the application. Floating action buttons are +/// most commonly used in the [Scaffold.floatingActionButton] field. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=2uaoEDOgk_I} +/// +/// Use at most a single floating action button per screen. Floating action +/// buttons should be used for positive actions such as "create", "share", or +/// "navigate". (If more than one floating action button is used within a +/// [Route], then make sure that each button has a unique [heroTag], otherwise +/// an exception will be thrown.) +/// +/// If the [onPressed] callback is null, then the button will be disabled and +/// will not react to touch. It is highly discouraged to disable a floating +/// action button as there is no indication to the user that the button is +/// disabled. Consider changing the [backgroundColor] if disabling the floating +/// action button. +/// +/// {@tool dartpad} +/// This example shows a [FloatingActionButton] in its usual position within a +/// [Scaffold]. Pressing the button cycles it through a few variations in its +/// [foregroundColor], [backgroundColor], and [shape]. The button automatically +/// animates its segue from one set of visual parameters to another. +/// +/// ** See code in examples/api/lib/material/floating_action_button/floating_action_button.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows all the variants of [FloatingActionButton] widget as +/// described in: https://m3.material.io/components/floating-action-button/overview. +/// +/// ** See code in examples/api/lib/material/floating_action_button/floating_action_button.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows [FloatingActionButton] with additional color mappings as +/// described in: https://m3.material.io/components/floating-action-button/overview. +/// +/// ** See code in examples/api/lib/material/floating_action_button/floating_action_button.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Scaffold], in which floating action buttons typically live. +/// * [ElevatedButton], a filled button whose material elevates when pressed. +/// * <https://material.io/design/components/buttons-floating-action-button.html> +/// * <https://m3.material.io/components/floating-action-button> +class FloatingActionButton extends StatelessWidget { + /// Creates a circular floating action button. + /// + /// The [elevation], [highlightElevation], and [disabledElevation] parameters, + /// if specified, must be non-negative. + const FloatingActionButton({ + super.key, + this.child, + this.tooltip, + this.foregroundColor, + this.backgroundColor, + this.focusColor, + this.hoverColor, + this.splashColor, + this.heroTag = const _DefaultHeroTag(), + this.elevation, + this.focusElevation, + this.hoverElevation, + this.highlightElevation, + this.disabledElevation, + required this.onPressed, + this.mouseCursor, + this.mini = false, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.materialTapTargetSize, + this.isExtended = false, + this.enableFeedback, + }) : assert(elevation == null || elevation >= 0.0), + assert(focusElevation == null || focusElevation >= 0.0), + assert(hoverElevation == null || hoverElevation >= 0.0), + assert(highlightElevation == null || highlightElevation >= 0.0), + assert(disabledElevation == null || disabledElevation >= 0.0), + _floatingActionButtonType = mini ? _FloatingActionButtonType.small : _FloatingActionButtonType.regular, + _extendedLabel = null, + extendedIconLabelSpacing = null, + extendedPadding = null, + extendedTextStyle = null; + + /// Creates a small circular floating action button. + /// + /// This constructor overrides the default size constraints of the floating + /// action button. + /// + /// The [elevation], [focusElevation], [hoverElevation], [highlightElevation], + /// and [disabledElevation] parameters, if specified, must be non-negative. + const FloatingActionButton.small({ + super.key, + this.child, + this.tooltip, + this.foregroundColor, + this.backgroundColor, + this.focusColor, + this.hoverColor, + this.splashColor, + this.heroTag = const _DefaultHeroTag(), + this.elevation, + this.focusElevation, + this.hoverElevation, + this.highlightElevation, + this.disabledElevation, + required this.onPressed, + this.mouseCursor, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.materialTapTargetSize, + this.enableFeedback, + }) : assert(elevation == null || elevation >= 0.0), + assert(focusElevation == null || focusElevation >= 0.0), + assert(hoverElevation == null || hoverElevation >= 0.0), + assert(highlightElevation == null || highlightElevation >= 0.0), + assert(disabledElevation == null || disabledElevation >= 0.0), + _floatingActionButtonType = _FloatingActionButtonType.small, + mini = true, + isExtended = false, + _extendedLabel = null, + extendedIconLabelSpacing = null, + extendedPadding = null, + extendedTextStyle = null; + + /// Creates a large circular floating action button. + /// + /// This constructor overrides the default size constraints of the floating + /// action button. + /// + /// The [elevation], [focusElevation], [hoverElevation], [highlightElevation], + /// and [disabledElevation] parameters, if specified, must be non-negative. + const FloatingActionButton.large({ + super.key, + this.child, + this.tooltip, + this.foregroundColor, + this.backgroundColor, + this.focusColor, + this.hoverColor, + this.splashColor, + this.heroTag = const _DefaultHeroTag(), + this.elevation, + this.focusElevation, + this.hoverElevation, + this.highlightElevation, + this.disabledElevation, + required this.onPressed, + this.mouseCursor, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.materialTapTargetSize, + this.enableFeedback, + }) : assert(elevation == null || elevation >= 0.0), + assert(focusElevation == null || focusElevation >= 0.0), + assert(hoverElevation == null || hoverElevation >= 0.0), + assert(highlightElevation == null || highlightElevation >= 0.0), + assert(disabledElevation == null || disabledElevation >= 0.0), + _floatingActionButtonType = _FloatingActionButtonType.large, + mini = false, + isExtended = false, + _extendedLabel = null, + extendedIconLabelSpacing = null, + extendedPadding = null, + extendedTextStyle = null; + + /// Creates a wider [StadiumBorder]-shaped floating action button with + /// an optional [icon] and a [label]. + /// + /// The [elevation], [highlightElevation], and [disabledElevation] parameters, + /// if specified, must be non-negative. + /// + /// See also: + /// * <https://m3.material.io/components/extended-fab> + const FloatingActionButton.extended({ + super.key, + this.tooltip, + this.foregroundColor, + this.backgroundColor, + this.focusColor, + this.hoverColor, + this.heroTag = const _DefaultHeroTag(), + this.elevation, + this.focusElevation, + this.hoverElevation, + this.splashColor, + this.highlightElevation, + this.disabledElevation, + required this.onPressed, + this.mouseCursor = SystemMouseCursors.click, + this.shape, + this.isExtended = true, + this.materialTapTargetSize, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.extendedIconLabelSpacing, + this.extendedPadding, + this.extendedTextStyle, + Widget? icon, + required Widget label, + this.enableFeedback, + }) : assert(elevation == null || elevation >= 0.0), + assert(focusElevation == null || focusElevation >= 0.0), + assert(hoverElevation == null || hoverElevation >= 0.0), + assert(highlightElevation == null || highlightElevation >= 0.0), + assert(disabledElevation == null || disabledElevation >= 0.0), + mini = false, + _floatingActionButtonType = _FloatingActionButtonType.extended, + child = icon, + _extendedLabel = label; + + /// The widget below this widget in the tree. + /// + /// Typically an [Icon]. + final Widget? child; + + /// Text that describes the action that will occur when the button is pressed. + /// + /// This text is displayed when the user long-presses on the button and is + /// used for accessibility. + final String? tooltip; + + /// The default foreground color for icons and text within the button. + /// + /// If this property is null, then the + /// [FloatingActionButtonThemeData.foregroundColor] of + /// [ThemeData.floatingActionButtonTheme] is used. If that property is also + /// null, then the [ColorScheme.onSecondary] color of [ThemeData.colorScheme] + /// is used. + final Color? foregroundColor; + + /// The button's background color. + /// + /// If this property is null, then the + /// [FloatingActionButtonThemeData.backgroundColor] of + /// [ThemeData.floatingActionButtonTheme] is used. If that property is also + /// null, then the [Theme]'s [ColorScheme.secondary] color is used. + final Color? backgroundColor; + + /// The color to use for filling the button when the button has input focus. + /// + /// Defaults to [ThemeData.focusColor] for the current theme. + final Color? focusColor; + + /// The color to use for filling the button when the button has a pointer + /// hovering over it. + /// + /// Defaults to [ThemeData.hoverColor] for the current theme. + final Color? hoverColor; + + /// The splash color for this [FloatingActionButton]'s [InkWell]. + /// + /// If null, [FloatingActionButtonThemeData.splashColor] is used, if that is + /// null, [ThemeData.splashColor] is used. + final Color? splashColor; + + /// The tag to apply to the button's [Hero] widget. + /// + /// Defaults to a tag that matches other floating action buttons. + /// + /// Set this to null explicitly if you don't want the floating action button to + /// have a hero tag. + /// + /// If this is not explicitly set, then there can only be one + /// [FloatingActionButton] per route (that is, per screen), since otherwise + /// there would be a tag conflict (multiple heroes on one route can't have the + /// same tag). The Material Design specification recommends only using one + /// floating action button per screen. + final Object? heroTag; + + /// The callback that is called when the button is tapped or otherwise activated. + /// + /// If this is set to null, the button will be disabled. + final VoidCallback? onPressed; + + /// {@macro flutter.material.RawMaterialButton.mouseCursor} + /// + /// If this property is null, [MaterialStateMouseCursor.clickable] will be used. + final MouseCursor? mouseCursor; + + /// The z-coordinate at which to place this button relative to its parent. + /// + /// This controls the size of the shadow below the floating action button. + /// + /// Defaults to 6, the appropriate elevation for floating action buttons. The + /// value is always non-negative. + /// + /// See also: + /// + /// * [highlightElevation], the elevation when the button is pressed. + /// * [disabledElevation], the elevation when the button is disabled. + final double? elevation; + + /// The z-coordinate at which to place this button relative to its parent when + /// the button has the input focus. + /// + /// This controls the size of the shadow below the floating action button. + /// + /// Defaults to 8, the appropriate elevation for floating action buttons + /// while they have focus. The value is always non-negative. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [highlightElevation], the elevation when the button is pressed. + /// * [disabledElevation], the elevation when the button is disabled. + final double? focusElevation; + + /// The z-coordinate at which to place this button relative to its parent when + /// the button is enabled and has a pointer hovering over it. + /// + /// This controls the size of the shadow below the floating action button. + /// + /// Defaults to 8, the appropriate elevation for floating action buttons while + /// they have a pointer hovering over them. The value is always non-negative. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [highlightElevation], the elevation when the button is pressed. + /// * [disabledElevation], the elevation when the button is disabled. + final double? hoverElevation; + + /// The z-coordinate at which to place this button relative to its parent when + /// the user is touching the button. + /// + /// This controls the size of the shadow below the floating action button. + /// + /// Defaults to 12, the appropriate elevation for floating action buttons + /// while they are being touched. The value is always non-negative. + /// + /// See also: + /// + /// * [elevation], the default elevation. + final double? highlightElevation; + + /// The z-coordinate at which to place this button when the button is disabled + /// ([onPressed] is null). + /// + /// This controls the size of the shadow below the floating action button. + /// + /// Defaults to the same value as [elevation]. Setting this to zero makes the + /// floating action button work similar to an [ElevatedButton] but the titular + /// "floating" effect is lost. The value is always non-negative. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [highlightElevation], the elevation when the button is pressed. + final double? disabledElevation; + + /// Controls the size of this button. + /// + /// By default, floating action buttons are non-mini and have a height and + /// width of 56.0 logical pixels. Mini floating action buttons have a height + /// and width of 40.0 logical pixels with a layout width and height of 48.0 + /// logical pixels. (The extra 4 pixels of padding on each side are added as a + /// result of the floating action button having [MaterialTapTargetSize.padded] + /// set on the underlying [RawMaterialButton.materialTapTargetSize].) + final bool mini; + + /// The shape of the button's [Material]. + /// + /// The button's highlight and splash are clipped to this shape. If the + /// button has an elevation, then its drop shadow is defined by this + /// shape as well. + final ShapeBorder? shape; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// True if this is an "extended" floating action button. + /// + /// Typically [extended] buttons have a [StadiumBorder] [shape] + /// and have been created with the [FloatingActionButton.extended] + /// constructor. + /// + /// The [Scaffold] animates the appearance of ordinary floating + /// action buttons with scale and rotation transitions. Extended + /// floating action buttons are scaled and faded in. + final bool isExtended; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// Configures the minimum size of the tap target. + /// + /// Defaults to [ThemeData.materialTapTargetSize]. + /// + /// See also: + /// + /// * [MaterialTapTargetSize], for a description of how this affects tap targets. + final MaterialTapTargetSize? materialTapTargetSize; + + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// If null, [FloatingActionButtonThemeData.enableFeedback] is used. + /// If both are null, then default value is true. + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + + /// The spacing between the icon and the label for an extended + /// [FloatingActionButton]. + /// + /// If null, [FloatingActionButtonThemeData.extendedIconLabelSpacing] is used. + /// If that is also null, the default is 8.0. + final double? extendedIconLabelSpacing; + + /// The padding for an extended [FloatingActionButton]'s content. + /// + /// If null, [FloatingActionButtonThemeData.extendedPadding] is used. If that + /// is also null, the default is + /// `EdgeInsetsDirectional.only(start: 16.0, end: 20.0)` if an icon is + /// provided, and `EdgeInsetsDirectional.only(start: 20.0, end: 20.0)` if not. + final EdgeInsetsGeometry? extendedPadding; + + /// The text style for an extended [FloatingActionButton]'s label. + /// + /// If null, [FloatingActionButtonThemeData.extendedTextStyle] is used. If + /// that is also null, then [TextTheme.labelLarge] with a letter spacing of 1.2 + /// is used. + final TextStyle? extendedTextStyle; + + final _FloatingActionButtonType _floatingActionButtonType; + + final Widget? _extendedLabel; + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final FloatingActionButtonThemeData floatingActionButtonTheme = theme.floatingActionButtonTheme; + final FloatingActionButtonThemeData defaults = theme.useMaterial3 + ? _FABDefaultsM3(context, _floatingActionButtonType, child != null) + : _FABDefaultsM2(context, _floatingActionButtonType, child != null); + + final Color foregroundColor = this.foregroundColor + ?? floatingActionButtonTheme.foregroundColor + ?? defaults.foregroundColor!; + final Color backgroundColor = this.backgroundColor + ?? floatingActionButtonTheme.backgroundColor + ?? defaults.backgroundColor!; + final Color focusColor = this.focusColor + ?? floatingActionButtonTheme.focusColor + ?? defaults.focusColor!; + final Color hoverColor = this.hoverColor + ?? floatingActionButtonTheme.hoverColor + ?? defaults.hoverColor!; + final Color splashColor = this.splashColor + ?? floatingActionButtonTheme.splashColor + ?? defaults.splashColor!; + final double elevation = this.elevation + ?? floatingActionButtonTheme.elevation + ?? defaults.elevation!; + final double focusElevation = this.focusElevation + ?? floatingActionButtonTheme.focusElevation + ?? defaults.focusElevation!; + final double hoverElevation = this.hoverElevation + ?? floatingActionButtonTheme.hoverElevation + ?? defaults.hoverElevation!; + final double disabledElevation = this.disabledElevation + ?? floatingActionButtonTheme.disabledElevation + ?? defaults.disabledElevation + ?? elevation; + final double highlightElevation = this.highlightElevation + ?? floatingActionButtonTheme.highlightElevation + ?? defaults.highlightElevation!; + final MaterialTapTargetSize materialTapTargetSize = this.materialTapTargetSize + ?? theme.materialTapTargetSize; + final bool enableFeedback = this.enableFeedback + ?? floatingActionButtonTheme.enableFeedback + ?? defaults.enableFeedback!; + final double iconSize = floatingActionButtonTheme.iconSize + ?? defaults.iconSize!; + final TextStyle extendedTextStyle = (this.extendedTextStyle + ?? floatingActionButtonTheme.extendedTextStyle + ?? defaults.extendedTextStyle!).copyWith(color: foregroundColor); + final ShapeBorder shape = this.shape + ?? floatingActionButtonTheme.shape + ?? defaults.shape!; + + BoxConstraints sizeConstraints; + Widget? resolvedChild = child != null ? IconTheme.merge( + data: IconThemeData(size: iconSize), + child: child!, + ) : child; + switch (_floatingActionButtonType) { + case _FloatingActionButtonType.regular: + sizeConstraints = floatingActionButtonTheme.sizeConstraints ?? defaults.sizeConstraints!; + case _FloatingActionButtonType.small: + sizeConstraints = floatingActionButtonTheme.smallSizeConstraints ?? defaults.smallSizeConstraints!; + case _FloatingActionButtonType.large: + sizeConstraints = floatingActionButtonTheme.largeSizeConstraints ?? defaults.largeSizeConstraints!; + case _FloatingActionButtonType.extended: + sizeConstraints = floatingActionButtonTheme.extendedSizeConstraints ?? defaults.extendedSizeConstraints!; + final double iconLabelSpacing = extendedIconLabelSpacing ?? floatingActionButtonTheme.extendedIconLabelSpacing ?? 8.0; + final EdgeInsetsGeometry padding = extendedPadding + ?? floatingActionButtonTheme.extendedPadding + ?? defaults.extendedPadding!; + resolvedChild = _ChildOverflowBox( + child: Padding( + padding: padding, + child: Row( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + if (child != null) + child!, + if (child != null && isExtended) + SizedBox(width: iconLabelSpacing), + if (isExtended) + _extendedLabel!, + ], + ), + ), + ); + } + + Widget result = RawMaterialButton( + onPressed: onPressed, + mouseCursor: _EffectiveMouseCursor(mouseCursor, floatingActionButtonTheme.mouseCursor), + elevation: elevation, + focusElevation: focusElevation, + hoverElevation: hoverElevation, + highlightElevation: highlightElevation, + disabledElevation: disabledElevation, + constraints: sizeConstraints, + materialTapTargetSize: materialTapTargetSize, + fillColor: backgroundColor, + focusColor: focusColor, + hoverColor: hoverColor, + splashColor: splashColor, + textStyle: extendedTextStyle, + shape: shape, + clipBehavior: clipBehavior, + focusNode: focusNode, + autofocus: autofocus, + enableFeedback: enableFeedback, + child: resolvedChild, + ); + + if (tooltip != null) { + result = Tooltip( + message: tooltip, + child: result, + ); + } + + if (heroTag != null) { + result = Hero( + tag: heroTag!, + child: result, + ); + } + + return MergeSemantics(child: result); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ObjectFlagProperty<VoidCallback>('onPressed', onPressed, ifNull: 'disabled')); + properties.add(StringProperty('tooltip', tooltip, defaultValue: null)); + properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null)); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(ColorProperty('focusColor', focusColor, defaultValue: null)); + properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: null)); + properties.add(ColorProperty('splashColor', splashColor, defaultValue: null)); + properties.add(ObjectFlagProperty<Object>('heroTag', heroTag, ifPresent: 'hero')); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(DoubleProperty('focusElevation', focusElevation, defaultValue: null)); + properties.add(DoubleProperty('hoverElevation', hoverElevation, defaultValue: null)); + properties.add(DoubleProperty('highlightElevation', highlightElevation, defaultValue: null)); + properties.add(DoubleProperty('disabledElevation', disabledElevation, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null)); + properties.add(FlagProperty('isExtended', value: isExtended, ifTrue: 'extended')); + properties.add(DiagnosticsProperty<MaterialTapTargetSize>('materialTapTargetSize', materialTapTargetSize, defaultValue: null)); + } +} + +// This MaterialStateProperty is passed along to RawMaterialButton which +// resolves the property against MaterialState.pressed, MaterialState.hovered, +// MaterialState.focused, MaterialState.disabled. +class _EffectiveMouseCursor extends MaterialStateMouseCursor { + const _EffectiveMouseCursor(this.widgetCursor, this.themeCursor); + + final MouseCursor? widgetCursor; + final MaterialStateProperty<MouseCursor?>? themeCursor; + + @override + MouseCursor resolve(Set<MaterialState> states) { + return MaterialStateProperty.resolveAs<MouseCursor?>(widgetCursor, states) + ?? themeCursor?.resolve(states) + ?? MaterialStateMouseCursor.clickable.resolve(states); + } + + @override + String get debugDescription => 'MaterialStateMouseCursor(FloatActionButton)'; +} + +// This widget's size matches its child's size unless its constraints +// force it to be larger or smaller. The child is centered. +// +// Used to encapsulate extended FABs whose size is fixed, using Row +// and MainAxisSize.min, to be as wide as their label and icon. +class _ChildOverflowBox extends SingleChildRenderObjectWidget { + const _ChildOverflowBox({ + super.child, + }); + + @override + _RenderChildOverflowBox createRenderObject(BuildContext context) { + return _RenderChildOverflowBox( + textDirection: Directionality.of(context), + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderChildOverflowBox renderObject) { + renderObject.textDirection = Directionality.of(context); + } +} + +class _RenderChildOverflowBox extends RenderAligningShiftedBox { + _RenderChildOverflowBox({ + super.textDirection, + }) : super(alignment: Alignment.center); + + @override + double computeMinIntrinsicWidth(double height) => 0.0; + + @override + double computeMinIntrinsicHeight(double width) => 0.0; + + @override + Size computeDryLayout(BoxConstraints constraints) { + if (child != null) { + final Size childSize = child!.getDryLayout(const BoxConstraints()); + return Size( + math.max(constraints.minWidth, math.min(constraints.maxWidth, childSize.width)), + math.max(constraints.minHeight, math.min(constraints.maxHeight, childSize.height)), + ); + } else { + return constraints.biggest; + } + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + if (child != null) { + child!.layout(const BoxConstraints(), parentUsesSize: true); + size = Size( + math.max(constraints.minWidth, math.min(constraints.maxWidth, child!.size.width)), + math.max(constraints.minHeight, math.min(constraints.maxHeight, child!.size.height)), + ); + alignChild(); + } else { + size = constraints.biggest; + } + } +} + +// Hand coded defaults based on Material Design 2. +class _FABDefaultsM2 extends FloatingActionButtonThemeData { + _FABDefaultsM2(BuildContext context, this.type, this.hasChild) + : _theme = Theme.of(context), + _colors = Theme.of(context).colorScheme, + super( + elevation: 6, + focusElevation: 6, + hoverElevation: 8, + highlightElevation: 12, + enableFeedback: true, + sizeConstraints: const BoxConstraints.tightFor( + width: 56.0, + height: 56.0, + ), + smallSizeConstraints: const BoxConstraints.tightFor( + width: 40.0, + height: 40.0, + ), + largeSizeConstraints: const BoxConstraints.tightFor( + width: 96.0, + height: 96.0, + ), + extendedSizeConstraints: const BoxConstraints.tightFor( + height: 48.0, + ), + extendedIconLabelSpacing: 8.0, + ); + + final _FloatingActionButtonType type; + final bool hasChild; + final ThemeData _theme; + final ColorScheme _colors; + + bool get _isExtended => type == _FloatingActionButtonType.extended; + bool get _isLarge => type == _FloatingActionButtonType.large; + + @override Color? get foregroundColor => _colors.onSecondary; + @override Color? get backgroundColor => _colors.secondary; + @override Color? get focusColor => _theme.focusColor; + @override Color? get hoverColor => _theme.hoverColor; + @override Color? get splashColor => _theme.splashColor; + @override ShapeBorder? get shape => _isExtended ? const StadiumBorder() : const CircleBorder(); + @override double? get iconSize => _isLarge ? 36.0 : 24.0; + + @override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? 16.0 : 20.0, end: 20.0); + @override TextStyle? get extendedTextStyle => _theme.textTheme.labelLarge!.copyWith(letterSpacing: 1.2); +} + +// BEGIN GENERATED TOKEN PROPERTIES - FAB + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _FABDefaultsM3 extends FloatingActionButtonThemeData { + _FABDefaultsM3(this.context, this.type, this.hasChild) + : super( + elevation: 6.0, + focusElevation: 6.0, + hoverElevation: 8.0, + highlightElevation: 6.0, + enableFeedback: true, + sizeConstraints: const BoxConstraints.tightFor( + width: 56.0, + height: 56.0, + ), + smallSizeConstraints: const BoxConstraints.tightFor( + width: 40.0, + height: 40.0, + ), + largeSizeConstraints: const BoxConstraints.tightFor( + width: 96.0, + height: 96.0, + ), + extendedSizeConstraints: const BoxConstraints.tightFor( + height: 56.0, + ), + extendedIconLabelSpacing: 8.0, + ); + + final BuildContext context; + final _FloatingActionButtonType type; + final bool hasChild; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + bool get _isExtended => type == _FloatingActionButtonType.extended; + + @override Color? get foregroundColor => _colors.onPrimaryContainer; + @override Color? get backgroundColor => _colors.primaryContainer; + @override Color? get splashColor => _colors.onPrimaryContainer.withOpacity(0.12); + @override Color? get focusColor => _colors.onPrimaryContainer.withOpacity(0.12); + @override Color? get hoverColor => _colors.onPrimaryContainer.withOpacity(0.08); + + @override + ShapeBorder? get shape { + switch (type) { + case _FloatingActionButtonType.regular: + return const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))); + case _FloatingActionButtonType.small: + return const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))); + case _FloatingActionButtonType.large: + return const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0))); + case _FloatingActionButtonType.extended: + return const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))); + } + } + + @override + double? get iconSize { + switch (type) { + case _FloatingActionButtonType.regular: return 24.0; + case _FloatingActionButtonType.small: return 24.0; + case _FloatingActionButtonType.large: return 36.0; + case _FloatingActionButtonType.extended: return 24.0; + } + } + + @override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? 16.0 : 20.0, end: 20.0); + @override TextStyle? get extendedTextStyle => _textTheme.labelLarge; +} + +// END GENERATED TOKEN PROPERTIES - FAB diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/floating_action_button_location.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/floating_action_button_location.dart new file mode 100644 index 0000000000000000000000000000000000000000..a23496ce65e097ca7d42a4269d9915c32aed9b42 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/floating_action_button_location.dart @@ -0,0 +1,1016 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'scaffold.dart'; + +/// The margin that a [FloatingActionButton] should leave between it and the +/// edge of the screen. +/// +/// [FloatingActionButtonLocation.endFloat] uses this to set the appropriate margin +/// between the [FloatingActionButton] and the end of the screen. +const double kFloatingActionButtonMargin = 16.0; + +/// The amount of time the [FloatingActionButton] takes to transition in or out. +/// +/// The [Scaffold] uses this to set the duration of [FloatingActionButton] +/// motion, entrance, and exit animations. +const Duration kFloatingActionButtonSegue = Duration(milliseconds: 200); + +/// The fraction of a circle the [FloatingActionButton] should turn when it enters. +/// +/// Its value corresponds to 0.125 of a full circle, equivalent to 45 degrees or pi/4 radians. +const double kFloatingActionButtonTurnInterval = 0.125; + +/// If a [FloatingActionButton] is used on a [Scaffold] in certain positions, +/// it is moved [kMiniButtonOffsetAdjustment] pixels closer to the edge of the screen. +/// +/// This is intended to be used with [FloatingActionButton.mini] set to true, +/// so that the floating action button appears to align with [CircleAvatar]s +/// in the [ListTile.leading] slot of a [ListTile] in a [ListView] in the +/// [Scaffold.body]. +/// +/// More specifically: +/// * In the following positions, the [FloatingActionButton] is moved *horizontally* +/// closer to the edge of the screen: +/// * [FloatingActionButtonLocation.miniStartTop] +/// * [FloatingActionButtonLocation.miniStartFloat] +/// * [FloatingActionButtonLocation.miniStartDocked] +/// * [FloatingActionButtonLocation.miniEndTop] +/// * [FloatingActionButtonLocation.miniEndFloat] +/// * [FloatingActionButtonLocation.miniEndDocked] +/// * In the following positions, the [FloatingActionButton] is moved *vertically* +/// closer to the bottom of the screen: +/// * [FloatingActionButtonLocation.miniStartFloat] +/// * [FloatingActionButtonLocation.miniCenterFloat] +/// * [FloatingActionButtonLocation.miniEndFloat] +const double kMiniButtonOffsetAdjustment = 4.0; + +/// An object that defines a position for the [FloatingActionButton] +/// based on the [Scaffold]'s [ScaffoldPrelayoutGeometry]. +/// +/// Flutter provides [FloatingActionButtonLocation]s for the common +/// [FloatingActionButton] placements in Material Design applications. These +/// locations are available as static members of this class. +/// +/// ## Floating Action Button placements +/// +/// The following diagrams show the available placement locations for the FloatingActionButton. +/// +/// * [FloatingActionButtonLocation.centerDocked]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_center_docked.png) +/// +/// +/// * [FloatingActionButtonLocation.centerFloat]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_center_float.png) +/// +/// +/// * [FloatingActionButtonLocation.centerTop]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_center_top.png) +/// +/// +/// * [FloatingActionButtonLocation.endDocked]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_end_docked.png) +/// +/// +/// * [FloatingActionButtonLocation.endFloat]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_end_float.png) +/// +/// +/// * [FloatingActionButtonLocation.endTop]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_end_top.png) +/// +/// +/// * [FloatingActionButtonLocation.startDocked]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_start_docked.png) +/// +/// +/// * [FloatingActionButtonLocation.startFloat]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_start_float.png) +/// +/// +/// * [FloatingActionButtonLocation.startTop]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_start_top.png) +/// +/// +/// * [FloatingActionButtonLocation.miniCenterDocked]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_center_docked.png) +/// +/// +/// * [FloatingActionButtonLocation.miniCenterFloat]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_center_float.png) +/// +/// +/// * [FloatingActionButtonLocation.miniCenterTop]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_center_top.png) +/// +/// +/// * [FloatingActionButtonLocation.miniEndDocked]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_end_docked.png) +/// +/// +/// * [FloatingActionButtonLocation.miniEndFloat]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_end_float.png) +/// +/// +/// * [FloatingActionButtonLocation.miniEndTop]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_end_top.png) +/// +/// +/// * [FloatingActionButtonLocation.miniStartDocked]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_start_docked.png) +/// +/// +/// * [FloatingActionButtonLocation.miniStartFloat]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_start_float.png) +/// +/// +/// * [FloatingActionButtonLocation.miniStartTop]: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_start_top.png) +/// +/// +/// See also: +/// +/// * [FloatingActionButton], which is a circular button typically shown in the +/// bottom right corner of the app. +/// * [FloatingActionButtonAnimator], which is used to animate the +/// [Scaffold.floatingActionButton] from one [FloatingActionButtonLocation] to +/// another. +/// * [ScaffoldPrelayoutGeometry], the geometry that +/// [FloatingActionButtonLocation]s use to position the [FloatingActionButton]. +abstract class FloatingActionButtonLocation { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const FloatingActionButtonLocation(); + + /// Start-aligned [FloatingActionButton], floating over the transition between + /// the [Scaffold.appBar] and the [Scaffold.body]. + /// + /// To align a floating action button with [CircleAvatar]s in the + /// [ListTile.leading] slots of [ListTile]s in a [ListView] in the [Scaffold.body], + /// use [miniStartTop] and set [FloatingActionButton.mini] to true. + /// + /// This is unlikely to be a useful location for apps that lack a top [AppBar] + /// or that use a [SliverAppBar] in the scaffold body itself. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_start_top.png) + static const FloatingActionButtonLocation startTop = _StartTopFabLocation(); + + /// Start-aligned [FloatingActionButton], floating over the transition between + /// the [Scaffold.appBar] and the [Scaffold.body], optimized for mini floating + /// action buttons. + /// + /// This is intended to be used with [FloatingActionButton.mini] set to true, + /// so that the floating action button appears to align with [CircleAvatar]s + /// in the [ListTile.leading] slot of a [ListTile] in a [ListView] in the + /// [Scaffold.body]. + /// + /// This is unlikely to be a useful location for apps that lack a top [AppBar] + /// or that use a [SliverAppBar] in the scaffold body itself. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_start_top.png) + static const FloatingActionButtonLocation miniStartTop = _MiniStartTopFabLocation(); + + /// Centered [FloatingActionButton], floating over the transition between + /// the [Scaffold.appBar] and the [Scaffold.body]. + /// + /// This is unlikely to be a useful location for apps that lack a top [AppBar] + /// or that use a [SliverAppBar] in the scaffold body itself. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_center_top.png) + static const FloatingActionButtonLocation centerTop = _CenterTopFabLocation(); + + /// Centered [FloatingActionButton], floating over the transition between + /// the [Scaffold.appBar] and the [Scaffold.body], intended to be used with + /// [FloatingActionButton.mini] set to true. + /// + /// This is unlikely to be a useful location for apps that lack a top [AppBar] + /// or that use a [SliverAppBar] in the scaffold body itself. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_center_top.png) + static const FloatingActionButtonLocation miniCenterTop = _MiniCenterTopFabLocation(); + + /// End-aligned [FloatingActionButton], floating over the transition between + /// the [Scaffold.appBar] and the [Scaffold.body]. + /// + /// To align a floating action button with [CircleAvatar]s in the + /// [ListTile.trailing] slots of [ListTile]s in a [ListView] in the [Scaffold.body], + /// use [miniEndTop] and set [FloatingActionButton.mini] to true. + /// + /// This is unlikely to be a useful location for apps that lack a top [AppBar] + /// or that use a [SliverAppBar] in the scaffold body itself. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_end_top.png) + static const FloatingActionButtonLocation endTop = _EndTopFabLocation(); + + /// End-aligned [FloatingActionButton], floating over the transition between + /// the [Scaffold.appBar] and the [Scaffold.body], optimized for mini floating + /// action buttons. + /// + /// This is intended to be used with [FloatingActionButton.mini] set to true, + /// so that the floating action button appears to align with [CircleAvatar]s + /// in the [ListTile.trailing] slot of a [ListTile] in a [ListView] in the + /// [Scaffold.body]. + /// + /// This is unlikely to be a useful location for apps that lack a top [AppBar] + /// or that use a [SliverAppBar] in the scaffold body itself. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_end_top.png) + static const FloatingActionButtonLocation miniEndTop = _MiniEndTopFabLocation(); + + /// Start-aligned [FloatingActionButton], floating at the bottom of the screen. + /// + /// To align a floating action button with [CircleAvatar]s in the + /// [ListTile.leading] slots of [ListTile]s in a [ListView] in the [Scaffold.body], + /// use [miniStartFloat] and set [FloatingActionButton.mini] to true. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_start_float.png) + static const FloatingActionButtonLocation startFloat = _StartFloatFabLocation(); + + /// Start-aligned [FloatingActionButton], floating at the bottom of the screen, + /// optimized for mini floating action buttons. + /// + /// This is intended to be used with [FloatingActionButton.mini] set to true, + /// so that the floating action button appears to align with [CircleAvatar]s + /// in the [ListTile.leading] slot of a [ListTile] in a [ListView] in the + /// [Scaffold.body]. + /// + /// Compared to [FloatingActionButtonLocation.startFloat], floating action + /// buttons using this location will move horizontally _and_ vertically + /// closer to the edges, by [kMiniButtonOffsetAdjustment] each. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_start_float.png) + static const FloatingActionButtonLocation miniStartFloat = _MiniStartFloatFabLocation(); + + /// Centered [FloatingActionButton], floating at the bottom of the screen. + /// + /// To position a mini floating action button, use [miniCenterFloat] and + /// set [FloatingActionButton.mini] to true. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_center_float.png) + static const FloatingActionButtonLocation centerFloat = _CenterFloatFabLocation(); + + /// Centered [FloatingActionButton], floating at the bottom of the screen, + /// optimized for mini floating action buttons. + /// + /// This is intended to be used with [FloatingActionButton.mini] set to true, + /// so that the floating action button appears to align horizontally with + /// the locations [FloatingActionButtonLocation.miniStartFloat] + /// and [FloatingActionButtonLocation.miniEndFloat]. + /// + /// Compared to [FloatingActionButtonLocation.centerFloat], floating action + /// buttons using this location will move vertically down + /// by [kMiniButtonOffsetAdjustment]. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_center_float.png) + static const FloatingActionButtonLocation miniCenterFloat = _MiniCenterFloatFabLocation(); + + /// End-aligned [FloatingActionButton], floating at the bottom of the screen. + /// + /// This is the default alignment of [FloatingActionButton]s in Material applications. + /// + /// To align a floating action button with [CircleAvatar]s in the + /// [ListTile.trailing] slots of [ListTile]s in a [ListView] in the [Scaffold.body], + /// use [miniEndFloat] and set [FloatingActionButton.mini] to true. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_end_float.png) + static const FloatingActionButtonLocation endFloat = _EndFloatFabLocation(); + + /// End-aligned [FloatingActionButton], floating at the bottom of the screen, + /// optimized for mini floating action buttons. + /// + /// This is intended to be used with [FloatingActionButton.mini] set to true, + /// so that the floating action button appears to align with [CircleAvatar]s + /// in the [ListTile.trailing] slot of a [ListTile] in a [ListView] in the + /// [Scaffold.body]. + /// + /// Compared to [FloatingActionButtonLocation.endFloat], floating action + /// buttons using this location will move horizontally _and_ vertically + /// closer to the edges, by [kMiniButtonOffsetAdjustment] each. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_end_float.png) + static const FloatingActionButtonLocation miniEndFloat = _MiniEndFloatFabLocation(); + + /// Start-aligned [FloatingActionButton], floating over the + /// [Scaffold.bottomNavigationBar] so that the center of the floating + /// action button lines up with the top of the bottom navigation bar. + /// + /// To align a floating action button with [CircleAvatar]s in the + /// [ListTile.leading] slots of [ListTile]s in a [ListView] in the [Scaffold.body], + /// use [miniStartDocked] and set [FloatingActionButton.mini] to true. + /// + /// If the value of [Scaffold.bottomNavigationBar] is a [BottomAppBar], + /// the bottom app bar can include a "notch" in its shape that accommodates + /// the overlapping floating action button. + /// + /// This is unlikely to be a useful location for apps that lack a bottom + /// navigation bar. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_start_docked.png) + static const FloatingActionButtonLocation startDocked = _StartDockedFabLocation(); + + /// Start-aligned [FloatingActionButton], floating over the + /// [Scaffold.bottomNavigationBar] so that the center of the floating + /// action button lines up with the top of the bottom navigation bar, + /// optimized for mini floating action buttons. + /// + /// If the value of [Scaffold.bottomNavigationBar] is a [BottomAppBar], + /// the bottom app bar can include a "notch" in its shape that accommodates + /// the overlapping floating action button. + /// + /// This is intended to be used with [FloatingActionButton.mini] set to true, + /// so that the floating action button appears to align with [CircleAvatar]s + /// in the [ListTile.leading] slot of a [ListTile] in a [ListView] in the + /// [Scaffold.body]. + /// + /// This is unlikely to be a useful location for apps that lack a bottom + /// navigation bar. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_start_docked.png) + static const FloatingActionButtonLocation miniStartDocked = _MiniStartDockedFabLocation(); + + /// Centered [FloatingActionButton], floating over the + /// [Scaffold.bottomNavigationBar] so that the center of the floating + /// action button lines up with the top of the bottom navigation bar. + /// + /// If the value of [Scaffold.bottomNavigationBar] is a [BottomAppBar], + /// the bottom app bar can include a "notch" in its shape that accommodates + /// the overlapping floating action button. + /// + /// This is unlikely to be a useful location for apps that lack a bottom + /// navigation bar. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_center_docked.png) + static const FloatingActionButtonLocation centerDocked = _CenterDockedFabLocation(); + + /// Centered [FloatingActionButton], floating over the + /// [Scaffold.bottomNavigationBar] so that the center of the floating + /// action button lines up with the top of the bottom navigation bar; + /// intended to be used with [FloatingActionButton.mini] set to true. + /// + /// If the value of [Scaffold.bottomNavigationBar] is a [BottomAppBar], + /// the bottom app bar can include a "notch" in its shape that accommodates + /// the overlapping floating action button. + /// + /// This is unlikely to be a useful location for apps that lack a bottom + /// navigation bar. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_center_docked.png) + static const FloatingActionButtonLocation miniCenterDocked = _MiniCenterDockedFabLocation(); + + /// End-aligned [FloatingActionButton], floating over the + /// [Scaffold.bottomNavigationBar] so that the center of the floating + /// action button lines up with the top of the bottom navigation bar. + /// + /// If the value of [Scaffold.bottomNavigationBar] is a [BottomAppBar], + /// the bottom app bar can include a "notch" in its shape that accommodates + /// the overlapping floating action button. + /// + /// This is unlikely to be a useful location for apps that lack a bottom + /// navigation bar. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_end_docked.png) + static const FloatingActionButtonLocation endDocked = _EndDockedFabLocation(); + + /// End-aligned [FloatingActionButton], floating over the + /// [Scaffold.bottomNavigationBar] so that the center of the floating + /// action button lines up with the top of the bottom navigation bar, + /// optimized for mini floating action buttons. + /// + /// To align a floating action button with [CircleAvatar]s in the + /// [ListTile.trailing] slots of [ListTile]s in a [ListView] in the [Scaffold.body], + /// use [miniEndDocked] and set [FloatingActionButton.mini] to true. + /// + /// If the value of [Scaffold.bottomNavigationBar] is a [BottomAppBar], + /// the bottom app bar can include a "notch" in its shape that accommodates + /// the overlapping floating action button. + /// + /// This is intended to be used with [FloatingActionButton.mini] set to true, + /// so that the floating action button appears to align with [CircleAvatar]s + /// in the [ListTile.trailing] slot of a [ListTile] in a [ListView] in the + /// [Scaffold.body]. + /// + /// This is unlikely to be a useful location for apps that lack a bottom + /// navigation bar. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_mini_end_docked.png) + static const FloatingActionButtonLocation miniEndDocked = _MiniEndDockedFabLocation(); + + /// End-aligned [FloatingActionButton], floating over the + /// [Scaffold.bottomNavigationBar] so that the floating + /// action button lines up with the center of the bottom navigation bar. + /// + /// This is unlikely to be a useful location for apps which has a [BottomNavigationBar] + /// or a non material 3 [BottomAppBar]. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_location_end_contained.png) + static const FloatingActionButtonLocation endContained = _EndContainedFabLocation(); + + /// Places the [FloatingActionButton] based on the [Scaffold]'s layout. + /// + /// This uses a [ScaffoldPrelayoutGeometry], which the [Scaffold] constructs + /// during its layout phase after it has laid out every widget it can lay out + /// except the [FloatingActionButton]. The [Scaffold] uses the [Offset] + /// returned from this method to position the [FloatingActionButton] and + /// complete its layout. + Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry); + + @override + String toString() => objectRuntimeType(this, 'FloatingActionButtonLocation'); +} + +/// A base class that simplifies building [FloatingActionButtonLocation]s when +/// used with mixins [FabTopOffsetY], [FabFloatOffsetY], [FabDockedOffsetY], +/// [FabStartOffsetX], [FabCenterOffsetX], [FabEndOffsetX], and [FabMiniOffsetAdjustment]. +/// +/// A subclass of [FloatingActionButtonLocation] which implements its [getOffset] method +/// using three other methods: [getOffsetX], [getOffsetY], and [isMini]. +/// +/// Different mixins on this class override different methods, so that combining +/// a set of mixins creates a floating action button location. +/// +/// For example: the location [FloatingActionButtonLocation.miniEndTop] +/// is based on a class that extends [StandardFabLocation] +/// with mixins [FabMiniOffsetAdjustment], [FabEndOffsetX], and [FabTopOffsetY]. +/// +/// You can create your own subclass of [StandardFabLocation] +/// to implement a custom [FloatingActionButtonLocation]. +/// +/// {@tool dartpad} +/// This is an example of a user-defined [FloatingActionButtonLocation]. +/// +/// The example shows a [Scaffold] with an [AppBar], a [BottomAppBar], and a +/// [FloatingActionButton] using a custom [FloatingActionButtonLocation]. +/// +/// The new [FloatingActionButtonLocation] is defined +/// by extending [StandardFabLocation] with two mixins, +/// [FabEndOffsetX] and [FabFloatOffsetY], and overriding the +/// [getOffsetX] method to adjust the FAB's x-coordinate, creating a +/// [FloatingActionButtonLocation] slightly different from +/// [FloatingActionButtonLocation.endFloat]. +/// +/// ** See code in examples/api/lib/material/floating_action_button_location/standard_fab_location.0.dart ** +/// {@end-tool} +/// +abstract class StandardFabLocation extends FloatingActionButtonLocation { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const StandardFabLocation(); + + /// Obtains the x-offset to place the [FloatingActionButton] based on the + /// [Scaffold]'s layout. + /// + /// Used by [getOffset] to compute its x-coordinate. + double getOffsetX(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment); + + /// Obtains the y-offset to place the [FloatingActionButton] based on the + /// [Scaffold]'s layout. + /// + /// Used by [getOffset] to compute its y-coordinate. + double getOffsetY(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment); + + /// A function returning whether this [StandardFabLocation] is optimized for + /// mini [FloatingActionButton]s. + bool isMini () => false; + + @override + Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) { + final double adjustment = isMini() ? kMiniButtonOffsetAdjustment : 0.0; + return Offset( + getOffsetX(scaffoldGeometry, adjustment), + getOffsetY(scaffoldGeometry, adjustment), + ); + } + + /// Calculates x-offset for left-aligned [FloatingActionButtonLocation]s. + static double _leftOffsetX(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { + return kFloatingActionButtonMargin + + scaffoldGeometry.minInsets.left + - adjustment; + } + + /// Calculates x-offset for right-aligned [FloatingActionButtonLocation]s. + static double _rightOffsetX(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { + return scaffoldGeometry.scaffoldSize.width + - kFloatingActionButtonMargin + - scaffoldGeometry.minInsets.right + - scaffoldGeometry.floatingActionButtonSize.width + + adjustment; + } + + +} + +/// Mixin for a "top" floating action button location, such as +/// [FloatingActionButtonLocation.startTop]. +/// +/// The `adjustment`, typically [kMiniButtonOffsetAdjustment], is ignored in the +/// Y axis of "top" positions. For "top" positions, the X offset is adjusted to +/// move closer to the edge of the screen. This is so that a minified floating +/// action button appears to align with [CircleAvatar]s in the +/// [ListTile.leading] slot of a [ListTile] in a [ListView] in the +/// [Scaffold.body]. +mixin FabTopOffsetY on StandardFabLocation { + /// Calculates y-offset for [FloatingActionButtonLocation]s floating over + /// the transition between the [Scaffold.appBar] and the [Scaffold.body]. + @override + double getOffsetY(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { + if (scaffoldGeometry.contentTop > scaffoldGeometry.minViewPadding.top) { + final double fabHalfHeight = scaffoldGeometry.floatingActionButtonSize.height / 2.0; + return scaffoldGeometry.contentTop - fabHalfHeight; + } + // Otherwise, ensure we are placed within the bounds of a safe area. + return scaffoldGeometry.minViewPadding.top; + } +} + +/// Mixin for a "float" floating action button location, such as [FloatingActionButtonLocation.centerFloat]. +mixin FabFloatOffsetY on StandardFabLocation { + /// Calculates y-offset for [FloatingActionButtonLocation]s floating at + /// the bottom of the screen. + @override + double getOffsetY(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { + final double contentBottom = scaffoldGeometry.contentBottom; + final double bottomContentHeight = scaffoldGeometry.scaffoldSize.height - contentBottom; + final double bottomSheetHeight = scaffoldGeometry.bottomSheetSize.height; + final double fabHeight = scaffoldGeometry.floatingActionButtonSize.height; + final double snackBarHeight = scaffoldGeometry.snackBarSize.height; + final double safeMargin = math.max( + kFloatingActionButtonMargin, + scaffoldGeometry.minViewPadding.bottom - bottomContentHeight + kFloatingActionButtonMargin, + ); + + double fabY = contentBottom - fabHeight - safeMargin; + if (snackBarHeight > 0.0) { + fabY = math.min(fabY, contentBottom - snackBarHeight - fabHeight - kFloatingActionButtonMargin); + } + if (bottomSheetHeight > 0.0) { + fabY = math.min(fabY, contentBottom - bottomSheetHeight - fabHeight / 2.0); + } + return fabY + adjustment; + } +} + +/// Mixin for a "docked" floating action button location, such as [FloatingActionButtonLocation.endDocked]. +mixin FabDockedOffsetY on StandardFabLocation { + /// Calculates y-offset for [FloatingActionButtonLocation]s floating over the + /// [Scaffold.bottomNavigationBar] so that the center of the floating + /// action button lines up with the top of the bottom navigation bar. + @override + double getOffsetY(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { + final double contentBottom = scaffoldGeometry.contentBottom; + final double contentMargin = scaffoldGeometry.scaffoldSize.height - contentBottom; + final double bottomViewPadding = scaffoldGeometry.minViewPadding.bottom; + final double bottomSheetHeight = scaffoldGeometry.bottomSheetSize.height; + final double fabHeight = scaffoldGeometry.floatingActionButtonSize.height; + final double snackBarHeight = scaffoldGeometry.snackBarSize.height; + final double bottomMinInset = scaffoldGeometry.minInsets.bottom; + + double safeMargin; + + if (contentMargin > bottomMinInset + fabHeight / 2.0) { + // If contentMargin is higher than bottomMinInset enough to display the + // FAB without clipping, don't provide a margin + safeMargin = 0.0; + } else if (bottomMinInset == 0.0) { + // If bottomMinInset is zero(the software keyboard is not on the screen) + // provide bottomViewPadding as margin + safeMargin = bottomViewPadding; + } else { + // Provide a margin that would shift the FAB enough so that it stays away + // from the keyboard + safeMargin = fabHeight / 2.0 + kFloatingActionButtonMargin; + } + + double fabY = contentBottom - fabHeight / 2.0 - safeMargin; + // The FAB should sit with a margin between it and the snack bar. + if (snackBarHeight > 0.0) { + fabY = math.min(fabY, contentBottom - snackBarHeight - fabHeight - kFloatingActionButtonMargin); + } + // The FAB should sit with its center in front of the top of the bottom sheet. + if (bottomSheetHeight > 0.0) { + fabY = math.min(fabY, contentBottom - bottomSheetHeight - fabHeight / 2.0); + } + final double maxFabY = scaffoldGeometry.scaffoldSize.height - fabHeight - safeMargin; + return math.min(maxFabY, fabY); + } +} + +/// Mixin for a "contained" floating action button location, such as [FloatingActionButtonLocation.endContained]. +mixin FabContainedOffsetY on StandardFabLocation { + /// Calculates y-offset for [FloatingActionButtonLocation]s floating over the + /// [Scaffold.bottomNavigationBar] so that the center of the floating + /// action button lines up with the center of the bottom navigation bar. + @override + double getOffsetY(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { + final double contentBottom = scaffoldGeometry.contentBottom; + final double contentMargin = scaffoldGeometry.scaffoldSize.height - contentBottom; + final double bottomViewPadding = scaffoldGeometry.minViewPadding.bottom; + final double fabHeight = scaffoldGeometry.floatingActionButtonSize.height; + + double safeMargin; + if (contentMargin > bottomViewPadding + fabHeight) { + // If contentMargin is higher than bottomViewPadding enough to display the + // FAB without clipping, don't provide a margin + safeMargin = 0.0; + } else { + safeMargin = bottomViewPadding; + } + + // This is to compute the distance between the content bottom to the top edge + // of the floating action button. This can be negative if content margin is + // too small. + final double contentBottomToFabTop = (contentMargin - bottomViewPadding - fabHeight) / 2.0; + final double fabY = contentBottom + contentBottomToFabTop; + final double maxFabY = scaffoldGeometry.scaffoldSize.height - fabHeight - safeMargin; + + return math.min(maxFabY, fabY); + } +} + +/// Mixin for a "start" floating action button location, such as [FloatingActionButtonLocation.startTop]. +mixin FabStartOffsetX on StandardFabLocation { + /// Calculates x-offset for start-aligned [FloatingActionButtonLocation]s. + @override + double getOffsetX(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { + switch (scaffoldGeometry.textDirection) { + case TextDirection.rtl: + return StandardFabLocation._rightOffsetX(scaffoldGeometry, adjustment); + case TextDirection.ltr: + return StandardFabLocation._leftOffsetX(scaffoldGeometry, adjustment); + } + } +} + +/// Mixin for a "center" floating action button location, such as [FloatingActionButtonLocation.centerFloat]. +mixin FabCenterOffsetX on StandardFabLocation { + /// Calculates x-offset for center-aligned [FloatingActionButtonLocation]s. + @override + double getOffsetX(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { + return (scaffoldGeometry.scaffoldSize.width - scaffoldGeometry.floatingActionButtonSize.width) / 2.0; + } +} + +/// Mixin for an "end" floating action button location, such as [FloatingActionButtonLocation.endDocked]. +mixin FabEndOffsetX on StandardFabLocation { + /// Calculates x-offset for end-aligned [FloatingActionButtonLocation]s. + @override + double getOffsetX(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { + switch (scaffoldGeometry.textDirection) { + case TextDirection.rtl: + return StandardFabLocation._leftOffsetX(scaffoldGeometry, adjustment); + case TextDirection.ltr: + return StandardFabLocation._rightOffsetX(scaffoldGeometry, adjustment); + } + } +} + +/// Mixin for a "mini" floating action button location, such as [FloatingActionButtonLocation.miniStartTop]. +mixin FabMiniOffsetAdjustment on StandardFabLocation { + @override + bool isMini () => true; +} + +class _StartTopFabLocation extends StandardFabLocation + with FabStartOffsetX, FabTopOffsetY { + const _StartTopFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.startTop'; +} + +class _MiniStartTopFabLocation extends StandardFabLocation + with FabMiniOffsetAdjustment, FabStartOffsetX, FabTopOffsetY { + const _MiniStartTopFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.miniStartTop'; +} + +class _CenterTopFabLocation extends StandardFabLocation + with FabCenterOffsetX, FabTopOffsetY { + const _CenterTopFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.centerTop'; +} + +class _MiniCenterTopFabLocation extends StandardFabLocation + with FabMiniOffsetAdjustment, FabCenterOffsetX, FabTopOffsetY { + const _MiniCenterTopFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.miniCenterTop'; +} + +class _EndTopFabLocation extends StandardFabLocation + with FabEndOffsetX, FabTopOffsetY { + const _EndTopFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.endTop'; +} + +class _MiniEndTopFabLocation extends StandardFabLocation + with FabMiniOffsetAdjustment, FabEndOffsetX, FabTopOffsetY { + const _MiniEndTopFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.miniEndTop'; +} + +class _StartFloatFabLocation extends StandardFabLocation + with FabStartOffsetX, FabFloatOffsetY { + const _StartFloatFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.startFloat'; +} + +class _MiniStartFloatFabLocation extends StandardFabLocation + with FabMiniOffsetAdjustment, FabStartOffsetX, FabFloatOffsetY { + const _MiniStartFloatFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.miniStartFloat'; +} + +class _CenterFloatFabLocation extends StandardFabLocation + with FabCenterOffsetX, FabFloatOffsetY { + const _CenterFloatFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.centerFloat'; +} + +class _MiniCenterFloatFabLocation extends StandardFabLocation + with FabMiniOffsetAdjustment, FabCenterOffsetX, FabFloatOffsetY { + const _MiniCenterFloatFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.miniCenterFloat'; +} + +class _EndFloatFabLocation extends StandardFabLocation + with FabEndOffsetX, FabFloatOffsetY { + const _EndFloatFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.endFloat'; +} + +class _MiniEndFloatFabLocation extends StandardFabLocation + with FabMiniOffsetAdjustment, FabEndOffsetX, FabFloatOffsetY { + const _MiniEndFloatFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.miniEndFloat'; +} + +class _StartDockedFabLocation extends StandardFabLocation + with FabStartOffsetX, FabDockedOffsetY { + const _StartDockedFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.startDocked'; +} + +class _MiniStartDockedFabLocation extends StandardFabLocation + with FabMiniOffsetAdjustment, FabStartOffsetX, FabDockedOffsetY { + const _MiniStartDockedFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.miniStartDocked'; +} + +class _CenterDockedFabLocation extends StandardFabLocation + with FabCenterOffsetX, FabDockedOffsetY { + const _CenterDockedFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.centerDocked'; +} + +class _MiniCenterDockedFabLocation extends StandardFabLocation + with FabMiniOffsetAdjustment, FabCenterOffsetX, FabDockedOffsetY { + const _MiniCenterDockedFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.miniCenterDocked'; +} + +class _EndDockedFabLocation extends StandardFabLocation + with FabEndOffsetX, FabDockedOffsetY { + const _EndDockedFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.endDocked'; +} + +class _MiniEndDockedFabLocation extends StandardFabLocation + with FabMiniOffsetAdjustment, FabEndOffsetX, FabDockedOffsetY { + const _MiniEndDockedFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.miniEndDocked'; +} + +class _EndContainedFabLocation extends StandardFabLocation + with FabEndOffsetX, FabContainedOffsetY { + const _EndContainedFabLocation(); + + @override + String toString() => 'FloatingActionButtonLocation.endContained'; +} + +/// Provider of animations to move the [FloatingActionButton] between [FloatingActionButtonLocation]s. +/// +/// The [Scaffold] uses [Scaffold.floatingActionButtonAnimator] to define: +/// +/// * The [Offset] of the [FloatingActionButton] between the old and new +/// [FloatingActionButtonLocation]s as part of the transition animation. +/// * An [Animation] to scale the [FloatingActionButton] during the transition. +/// * An [Animation] to rotate the [FloatingActionButton] during the transition. +/// * Where to start a new animation from if an animation is interrupted. +/// +/// See also: +/// +/// * [FloatingActionButton], which is a circular button typically shown in the +/// bottom right corner of the app. +/// * [FloatingActionButtonLocation], which the [Scaffold] uses to place the +/// [Scaffold.floatingActionButton] within the [Scaffold]'s layout. +abstract class FloatingActionButtonAnimator { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const FloatingActionButtonAnimator(); + + /// Moves the [FloatingActionButton] by scaling out and then in at a new + /// [FloatingActionButtonLocation]. + /// + /// This animator shrinks the [FloatingActionButton] down until it disappears, then + /// grows it back to full size at its new [FloatingActionButtonLocation]. + /// + /// This is the default [FloatingActionButton] motion animation. + static const FloatingActionButtonAnimator scaling = _ScalingFabMotionAnimator(); + + /// Gets the [FloatingActionButton]'s position relative to the origin of the + /// [Scaffold] based on [progress]. + /// + /// [begin] is the [Offset] provided by the previous + /// [FloatingActionButtonLocation]. + /// + /// [end] is the [Offset] provided by the new + /// [FloatingActionButtonLocation]. + /// + /// [progress] is the current progress of the transition animation. + /// When [progress] is 0.0, the returned [Offset] should be equal to [begin]. + /// when [progress] is 1.0, the returned [Offset] should be equal to [end]. + Offset getOffset({ required Offset begin, required Offset end, required double progress }); + + /// Animates the scale of the [FloatingActionButton]. + /// + /// The animation should both start and end with a value of 1.0. + /// + /// For example, to create an animation that linearly scales out and then back in, + /// you could join animations that pass each other: + /// + /// ```dart + /// @override + /// Animation<double> getScaleAnimation({required Animation<double> parent}) { + /// // The animations will cross at value 0, and the train will return to 1.0. + /// return TrainHoppingAnimation( + /// Tween<double>(begin: 1.0, end: -1.0).animate(parent), + /// Tween<double>(begin: -1.0, end: 1.0).animate(parent), + /// ); + /// } + /// ``` + Animation<double> getScaleAnimation({ required Animation<double> parent }); + + /// Animates the rotation of [Scaffold.floatingActionButton]. + /// + /// The animation should both start and end with a value of 0.0 or 1.0. + /// + /// The animation values are a fraction of a full circle, with 0.0 and 1.0 + /// corresponding to 0 and 360 degrees, while 0.5 corresponds to 180 degrees. + /// + /// For example, to create a rotation animation that rotates the + /// [FloatingActionButton] through a full circle: + /// + /// ```dart + /// @override + /// Animation<double> getRotationAnimation({required Animation<double> parent}) { + /// return Tween<double>(begin: 0.0, end: 1.0).animate(parent); + /// } + /// ``` + Animation<double> getRotationAnimation({ required Animation<double> parent }); + + /// Gets the progress value to restart a motion animation from when the animation is interrupted. + /// + /// [previousValue] is the value of the animation before it was interrupted. + /// + /// The restart of the animation will affect all three parts of the motion animation: + /// offset animation, scale animation, and rotation animation. + /// + /// An interruption triggers if the [Scaffold] is given a new [FloatingActionButtonLocation] + /// while it is still animating a transition between two previous [FloatingActionButtonLocation]s. + /// + /// A sensible default is usually 0.0, which is the same as restarting + /// the animation from the beginning, regardless of the original state of the animation. + double getAnimationRestart(double previousValue) => 0.0; + + @override + String toString() => objectRuntimeType(this, 'FloatingActionButtonAnimator'); +} + +class _ScalingFabMotionAnimator extends FloatingActionButtonAnimator { + const _ScalingFabMotionAnimator(); + + @override + Offset getOffset({ required Offset begin, required Offset end, required double progress }) { + if (progress < 0.5) { + return begin; + } else { + return end; + } + } + + @override + Animation<double> getScaleAnimation({ required Animation<double> parent }) { + // Animate the scale down from 1 to 0 in the first half of the animation + // then from 0 back to 1 in the second half. + const Curve curve = Interval(0.5, 1.0, curve: Curves.ease); + return _AnimationSwap<double>( + ReverseAnimation(parent.drive(CurveTween(curve: curve.flipped))), + parent.drive(CurveTween(curve: curve)), + parent, + 0.5, + ); + } + + // Because we only see the last half of the rotation tween, + // it needs to go twice as far. + static final Animatable<double> _rotationTween = Tween<double>( + begin: 1.0 - kFloatingActionButtonTurnInterval * 2.0, + end: 1.0, + ); + + static final Animatable<double> _thresholdCenterTween = CurveTween(curve: const Threshold(0.5)); + + @override + Animation<double> getRotationAnimation({ required Animation<double> parent }) { + // This rotation will turn on the way in, but not on the way out. + return _AnimationSwap<double>( + parent.drive(_rotationTween), + ReverseAnimation(parent.drive(_thresholdCenterTween)), + parent, + 0.5, + ); + } + + // If the animation was just starting, we'll continue from where we left off. + // If the animation was finishing, we'll treat it as if we were starting at that point in reverse. + // This avoids a size jump during the animation. + @override + double getAnimationRestart(double previousValue) => math.min(1.0 - previousValue, previousValue); +} + +/// An animation that swaps from one animation to the next when the [parent] passes [swapThreshold]. +/// +/// The [value] of this animation is the value of [first] when [parent.value] < [swapThreshold] +/// and the value of [next] otherwise. +class _AnimationSwap<T> extends CompoundAnimation<T> { + /// Creates an [_AnimationSwap]. + /// + /// Either argument can be an [_AnimationSwap] itself to combine multiple + /// animations. + _AnimationSwap(Animation<T> first, Animation<T> next, this.parent, this.swapThreshold) : super(first: first, next: next); + + final Animation<double> parent; + final double swapThreshold; + + @override + T get value => parent.value < swapThreshold ? first.value : next.value; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/floating_action_button_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/floating_action_button_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..dc59a8e0e2f1563265f87ee1f86832cf6949e277 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/floating_action_button_theme.dart @@ -0,0 +1,309 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'material_state.dart'; + +/// Defines default property values for descendant [FloatingActionButton] +/// widgets. +/// +/// Descendant widgets obtain the current [FloatingActionButtonThemeData] object +/// using `Theme.of(context).floatingActionButtonTheme`. Instances of +/// [FloatingActionButtonThemeData] can be customized with +/// [FloatingActionButtonThemeData.copyWith]. +/// +/// Typically a [FloatingActionButtonThemeData] is specified as part of the +/// overall [Theme] with [ThemeData.floatingActionButtonTheme]. +/// +/// All [FloatingActionButtonThemeData] properties are `null` by default. +/// When null, the [FloatingActionButton] will use the values from [ThemeData] +/// if they exist, otherwise it will provide its own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class FloatingActionButtonThemeData with Diagnosticable { + /// Creates a theme that can be used for + /// [ThemeData.floatingActionButtonTheme]. + const FloatingActionButtonThemeData({ + this.foregroundColor, + this.backgroundColor, + this.focusColor, + this.hoverColor, + this.splashColor, + this.elevation, + this.focusElevation, + this.hoverElevation, + this.disabledElevation, + this.highlightElevation, + this.shape, + this.enableFeedback, + this.iconSize, + this.sizeConstraints, + this.smallSizeConstraints, + this.largeSizeConstraints, + this.extendedSizeConstraints, + this.extendedIconLabelSpacing, + this.extendedPadding, + this.extendedTextStyle, + this.mouseCursor, + }); + + /// Color to be used for the unselected, enabled [FloatingActionButton]'s + /// foreground. + final Color? foregroundColor; + + /// Color to be used for the unselected, enabled [FloatingActionButton]'s + /// background. + final Color? backgroundColor; + + /// The color to use for filling the button when the button has input focus. + final Color? focusColor; + + /// The color to use for filling the button when the button has a pointer + /// hovering over it. + final Color? hoverColor; + + /// The splash color for this [FloatingActionButton]'s [InkWell]. + final Color? splashColor; + + /// The z-coordinate to be used for the unselected, enabled + /// [FloatingActionButton]'s elevation foreground. + final double? elevation; + + /// The z-coordinate at which to place this button relative to its parent when + /// the button has the input focus. + /// + /// This controls the size of the shadow below the floating action button. + final double? focusElevation; + + /// The z-coordinate at which to place this button relative to its parent when + /// the button is enabled and has a pointer hovering over it. + /// + /// This controls the size of the shadow below the floating action button. + final double? hoverElevation; + + /// The z-coordinate to be used for the disabled [FloatingActionButton]'s + /// elevation foreground. + final double? disabledElevation; + + /// The z-coordinate to be used for the selected, enabled + /// [FloatingActionButton]'s elevation foreground. + final double? highlightElevation; + + /// The shape to be used for the floating action button's [Material]. + final ShapeBorder? shape; + + /// If specified, defines the feedback property for [FloatingActionButton]. + /// + /// If [FloatingActionButton.enableFeedback] is provided, [enableFeedback] is + /// ignored. + final bool? enableFeedback; + + /// Overrides the default icon size for the [FloatingActionButton]; + final double? iconSize; + + /// Overrides the default size constraints for the [FloatingActionButton]. + final BoxConstraints? sizeConstraints; + + /// Overrides the default size constraints for [FloatingActionButton.small]. + final BoxConstraints? smallSizeConstraints; + + /// Overrides the default size constraints for [FloatingActionButton.large]. + final BoxConstraints? largeSizeConstraints; + + /// Overrides the default size constraints for [FloatingActionButton.extended]. + final BoxConstraints? extendedSizeConstraints; + + /// The spacing between the icon and the label for an extended + /// [FloatingActionButton]. + final double? extendedIconLabelSpacing; + + /// The padding for an extended [FloatingActionButton]'s content. + final EdgeInsetsGeometry? extendedPadding; + + /// The text style for an extended [FloatingActionButton]'s label. + final TextStyle? extendedTextStyle; + + /// {@macro flutter.material.RawMaterialButton.mouseCursor} + /// + /// If specified, overrides the default value of [FloatingActionButton.mouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + FloatingActionButtonThemeData copyWith({ + Color? foregroundColor, + Color? backgroundColor, + Color? focusColor, + Color? hoverColor, + Color? splashColor, + double? elevation, + double? focusElevation, + double? hoverElevation, + double? disabledElevation, + double? highlightElevation, + ShapeBorder? shape, + bool? enableFeedback, + double? iconSize, + BoxConstraints? sizeConstraints, + BoxConstraints? smallSizeConstraints, + BoxConstraints? largeSizeConstraints, + BoxConstraints? extendedSizeConstraints, + double? extendedIconLabelSpacing, + EdgeInsetsGeometry? extendedPadding, + TextStyle? extendedTextStyle, + MaterialStateProperty<MouseCursor?>? mouseCursor, + }) { + return FloatingActionButtonThemeData( + foregroundColor: foregroundColor ?? this.foregroundColor, + backgroundColor: backgroundColor ?? this.backgroundColor, + focusColor: focusColor ?? this.focusColor, + hoverColor: hoverColor ?? this.hoverColor, + splashColor: splashColor ?? this.splashColor, + elevation: elevation ?? this.elevation, + focusElevation: focusElevation ?? this.focusElevation, + hoverElevation: hoverElevation ?? this.hoverElevation, + disabledElevation: disabledElevation ?? this.disabledElevation, + highlightElevation: highlightElevation ?? this.highlightElevation, + shape: shape ?? this.shape, + enableFeedback: enableFeedback ?? this.enableFeedback, + iconSize: iconSize ?? this.iconSize, + sizeConstraints: sizeConstraints ?? this.sizeConstraints, + smallSizeConstraints: smallSizeConstraints ?? this.smallSizeConstraints, + largeSizeConstraints: largeSizeConstraints ?? this.largeSizeConstraints, + extendedSizeConstraints: extendedSizeConstraints ?? this.extendedSizeConstraints, + extendedIconLabelSpacing: extendedIconLabelSpacing ?? this.extendedIconLabelSpacing, + extendedPadding: extendedPadding ?? this.extendedPadding, + extendedTextStyle: extendedTextStyle ?? this.extendedTextStyle, + mouseCursor: mouseCursor ?? this.mouseCursor, + ); + } + + /// Linearly interpolate between two floating action button themes. + /// + /// If both arguments are null then null is returned. + /// + /// {@macro dart.ui.shadow.lerp} + static FloatingActionButtonThemeData? lerp(FloatingActionButtonThemeData? a, FloatingActionButtonThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return FloatingActionButtonThemeData( + foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t), + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + focusColor: Color.lerp(a?.focusColor, b?.focusColor, t), + hoverColor: Color.lerp(a?.hoverColor, b?.hoverColor, t), + splashColor: Color.lerp(a?.splashColor, b?.splashColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + focusElevation: lerpDouble(a?.focusElevation, b?.focusElevation, t), + hoverElevation: lerpDouble(a?.hoverElevation, b?.hoverElevation, t), + disabledElevation: lerpDouble(a?.disabledElevation, b?.disabledElevation, t), + highlightElevation: lerpDouble(a?.highlightElevation, b?.highlightElevation, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + enableFeedback: t < 0.5 ? a?.enableFeedback : b?.enableFeedback, + iconSize: lerpDouble(a?.iconSize, b?.iconSize, t), + sizeConstraints: BoxConstraints.lerp(a?.sizeConstraints, b?.sizeConstraints, t), + smallSizeConstraints: BoxConstraints.lerp(a?.smallSizeConstraints, b?.smallSizeConstraints, t), + largeSizeConstraints: BoxConstraints.lerp(a?.largeSizeConstraints, b?.largeSizeConstraints, t), + extendedSizeConstraints: BoxConstraints.lerp(a?.extendedSizeConstraints, b?.extendedSizeConstraints, t), + extendedIconLabelSpacing: lerpDouble(a?.extendedIconLabelSpacing, b?.extendedIconLabelSpacing, t), + extendedPadding: EdgeInsetsGeometry.lerp(a?.extendedPadding, b?.extendedPadding, t), + extendedTextStyle: TextStyle.lerp(a?.extendedTextStyle, b?.extendedTextStyle, t), + mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, + ); + } + + @override + int get hashCode => Object.hash( + foregroundColor, + backgroundColor, + focusColor, + hoverColor, + splashColor, + elevation, + focusElevation, + hoverElevation, + disabledElevation, + highlightElevation, + shape, + enableFeedback, + iconSize, + sizeConstraints, + smallSizeConstraints, + largeSizeConstraints, + extendedSizeConstraints, + extendedIconLabelSpacing, + extendedPadding, + Object.hash( + extendedTextStyle, + mouseCursor, + ), + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is FloatingActionButtonThemeData + && other.foregroundColor == foregroundColor + && other.backgroundColor == backgroundColor + && other.focusColor == focusColor + && other.hoverColor == hoverColor + && other.splashColor == splashColor + && other.elevation == elevation + && other.focusElevation == focusElevation + && other.hoverElevation == hoverElevation + && other.disabledElevation == disabledElevation + && other.highlightElevation == highlightElevation + && other.shape == shape + && other.enableFeedback == enableFeedback + && other.iconSize == iconSize + && other.sizeConstraints == sizeConstraints + && other.smallSizeConstraints == smallSizeConstraints + && other.largeSizeConstraints == largeSizeConstraints + && other.extendedSizeConstraints == extendedSizeConstraints + && other.extendedIconLabelSpacing == extendedIconLabelSpacing + && other.extendedPadding == extendedPadding + && other.extendedTextStyle == extendedTextStyle + && other.mouseCursor == mouseCursor; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + + properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null)); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(ColorProperty('focusColor', focusColor, defaultValue: null)); + properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: null)); + properties.add(ColorProperty('splashColor', splashColor, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(DoubleProperty('focusElevation', focusElevation, defaultValue: null)); + properties.add(DoubleProperty('hoverElevation', hoverElevation, defaultValue: null)); + properties.add(DoubleProperty('disabledElevation', disabledElevation, defaultValue: null)); + properties.add(DoubleProperty('highlightElevation', highlightElevation, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('enableFeedback', enableFeedback, defaultValue: null)); + properties.add(DoubleProperty('iconSize', iconSize, defaultValue: null)); + properties.add(DiagnosticsProperty<BoxConstraints>('sizeConstraints', sizeConstraints, defaultValue: null)); + properties.add(DiagnosticsProperty<BoxConstraints>('smallSizeConstraints', smallSizeConstraints, defaultValue: null)); + properties.add(DiagnosticsProperty<BoxConstraints>('largeSizeConstraints', largeSizeConstraints, defaultValue: null)); + properties.add(DiagnosticsProperty<BoxConstraints>('extendedSizeConstraints', extendedSizeConstraints, defaultValue: null)); + properties.add(DoubleProperty('extendedIconLabelSpacing', extendedIconLabelSpacing, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('extendedPadding', extendedPadding, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('extendedTextStyle', extendedTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/flutter_logo.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/flutter_logo.dart new file mode 100644 index 0000000000000000000000000000000000000000..62f57c2451d0b980b265cf11f90528ee44651ca0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/flutter_logo.dart @@ -0,0 +1,75 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +/// The Flutter logo, in widget form. This widget respects the [IconTheme]. +/// For guidelines on using the Flutter logo, visit https://flutter.dev/brand. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=aAmP-WcI6dg} +/// +/// See also: +/// +/// * [IconTheme], which provides ambient configuration for icons. +/// * [Icon], for showing icons the Material design icon library. +/// * [ImageIcon], for showing icons from [AssetImage]s or other [ImageProvider]s. +class FlutterLogo extends StatelessWidget { + /// Creates a widget that paints the Flutter logo. + /// + /// The [size] defaults to the value given by the current [IconTheme]. + /// + /// The [textColor], [style], [duration], and [curve] arguments must not be + /// null. + const FlutterLogo({ + super.key, + this.size, + this.textColor = const Color(0xFF757575), + this.style = FlutterLogoStyle.markOnly, + this.duration = const Duration(milliseconds: 750), + this.curve = Curves.fastOutSlowIn, + }); + + /// The size of the logo in logical pixels. + /// + /// The logo will be fit into a square this size. + /// + /// Defaults to the current [IconTheme] size, if any. If there is no + /// [IconTheme], or it does not specify an explicit size, then it defaults to + /// 24.0. + final double? size; + + /// The color used to paint the "Flutter" text on the logo, if [style] is + /// [FlutterLogoStyle.horizontal] or [FlutterLogoStyle.stacked]. + /// + /// If possible, the default (a medium grey) should be used against a white + /// background. + final Color textColor; + + /// Whether and where to draw the "Flutter" text. By default, only the logo + /// itself is drawn. + final FlutterLogoStyle style; + + /// The length of time for the animation if the [style] or [textColor] + /// properties are changed. + final Duration duration; + + /// The curve for the logo animation if the [style] or [textColor] change. + final Curve curve; + + @override + Widget build(BuildContext context) { + final IconThemeData iconTheme = IconTheme.of(context); + final double? iconSize = size ?? iconTheme.size; + return AnimatedContainer( + width: iconSize, + height: iconSize, + duration: duration, + curve: curve, + decoration: FlutterLogoDecoration( + style: style, + textColor: textColor, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/grid_tile.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/grid_tile.dart new file mode 100644 index 0000000000000000000000000000000000000000..b69dabcc1834b84913f8f5cbafe1a321d61ffcff --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/grid_tile.dart @@ -0,0 +1,73 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +/// A tile in a Material Design grid list. +/// +/// A grid list is a [GridView] of tiles in a vertical and horizontal +/// array. Each tile typically contains some visually rich content (e.g., an +/// image) together with a [GridTileBar] in either a [header] or a [footer]. +/// +/// See also: +/// +/// * [GridView], which is a scrollable grid of tiles. +/// * [GridTileBar], which is typically used in either the [header] or +/// [footer]. +/// * <https://material.io/design/components/image-lists.html> +class GridTile extends StatelessWidget { + /// Creates a grid tile. + /// + /// Must have a child. Does not typically have both a header and a footer. + const GridTile({ + super.key, + this.header, + this.footer, + required this.child, + }); + + /// The widget to show over the top of this grid tile. + /// + /// Typically a [GridTileBar]. + final Widget? header; + + /// The widget to show over the bottom of this grid tile. + /// + /// Typically a [GridTileBar]. + final Widget? footer; + + /// The widget that fills the tile. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + if (header == null && footer == null) { + return child; + } + + return Stack( + children: <Widget>[ + Positioned.fill( + child: child, + ), + if (header != null) + Positioned( + top: 0.0, + left: 0.0, + right: 0.0, + child: header!, + ), + if (footer != null) + Positioned( + left: 0.0, + bottom: 0.0, + right: 0.0, + child: footer!, + ), + ], + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/grid_tile_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/grid_tile_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..d9b3c3223417d9369207ad523a775c02bdcfa8b6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/grid_tile_bar.dart @@ -0,0 +1,122 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'theme.dart'; + +/// A header used in a Material Design [GridTile]. +/// +/// Typically used to add a one or two line header or footer on a [GridTile]. +/// +/// For a one-line header, include a [title] widget. To add a second line, also +/// include a [subtitle] widget. Use [leading] or [trailing] to add an icon. +/// +/// See also: +/// +/// * [GridTile] +/// * <https://material.io/design/components/image-lists.html#anatomy> +class GridTileBar extends StatelessWidget { + /// Creates a grid tile bar. + /// + /// Typically used to with [GridTile]. + const GridTileBar({ + super.key, + this.backgroundColor, + this.leading, + this.title, + this.subtitle, + this.trailing, + }); + + /// The color to paint behind the child widgets. + /// + /// Defaults to transparent. + final Color? backgroundColor; + + /// A widget to display before the title. + /// + /// Typically an [Icon] or an [IconButton] widget. + final Widget? leading; + + /// The primary content of the list item. + /// + /// Typically a [Text] widget. + final Widget? title; + + /// Additional content displayed below the title. + /// + /// Typically a [Text] widget. + final Widget? subtitle; + + /// A widget to display after the title. + /// + /// Typically an [Icon] or an [IconButton] widget. + final Widget? trailing; + + @override + Widget build(BuildContext context) { + BoxDecoration? decoration; + if (backgroundColor != null) { + decoration = BoxDecoration(color: backgroundColor); + } + + final EdgeInsetsDirectional padding = EdgeInsetsDirectional.only( + start: leading != null ? 8.0 : 16.0, + end: trailing != null ? 8.0 : 16.0, + ); + + final ThemeData darkTheme = ThemeData.dark(); + return Container( + padding: padding, + decoration: decoration, + height: (title != null && subtitle != null) ? 68.0 : 48.0, + child: Theme( + data: darkTheme, + child: IconTheme.merge( + data: const IconThemeData(color: Colors.white), + child: Row( + children: <Widget>[ + if (leading != null) + Padding(padding: const EdgeInsetsDirectional.only(end: 8.0), child: leading), + if (title != null && subtitle != null) + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + DefaultTextStyle( + style: darkTheme.textTheme.titleMedium!, + softWrap: false, + overflow: TextOverflow.ellipsis, + child: title!, + ), + DefaultTextStyle( + style: darkTheme.textTheme.bodySmall!, + softWrap: false, + overflow: TextOverflow.ellipsis, + child: subtitle!, + ), + ], + ), + ) + else if (title != null || subtitle != null) + Expanded( + child: DefaultTextStyle( + style: darkTheme.textTheme.titleMedium!, + softWrap: false, + overflow: TextOverflow.ellipsis, + child: title ?? subtitle!, + ), + ), + if (trailing != null) + Padding(padding: const EdgeInsetsDirectional.only(start: 8.0), child: trailing), + ], + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/icon_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/icon_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..6eac56d2b27849e4b5ff1d3a9302705e79984b11 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/icon_button.dart @@ -0,0 +1,1637 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'button_style_button.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'icon_button_theme.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'theme.dart'; +import 'theme_data.dart'; +import 'tooltip.dart'; + +// Examples can assume: +// late BuildContext context; + +// Minimum logical pixel size of the IconButton. +// See: <https://material.io/design/usability/accessibility.html#layout-typography>. +const double _kMinButtonSize = kMinInteractiveDimension; + +enum _IconButtonVariant { standard, filled, filledTonal, outlined } + +/// A Material Design icon button. +/// +/// An icon button is a picture printed on a [Material] widget that reacts to +/// touches by filling with color (ink). +/// +/// Icon buttons are commonly used in the [AppBar.actions] field, but they can +/// be used in many other places as well. +/// +/// If the [onPressed] callback is null, then the button will be disabled and +/// will not react to touch. +/// +/// Requires one of its ancestors to be a [Material] widget. In Material Design 3, +/// this requirement no longer exists because this widget builds a subclass of +/// [ButtonStyleButton]. +/// +/// The hit region of an icon button will, if possible, be at least +/// kMinInteractiveDimension pixels in size, regardless of the actual +/// [iconSize], to satisfy the [touch target size](https://material.io/design/layout/spacing-methods.html#touch-targets) +/// requirements in the Material Design specification. The [alignment] controls +/// how the icon itself is positioned within the hit region. +/// +/// {@tool dartpad} +/// This sample shows an [IconButton] that uses the Material icon "volume_up" to +/// increase the volume. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/icon_button.png) +/// +/// ** See code in examples/api/lib/material/icon_button/icon_button.0.dart ** +/// {@end-tool} +/// +/// ### Icon sizes +/// +/// When creating an icon button with an [Icon], do not override the +/// icon's size with its [Icon.size] parameter, use the icon button's +/// [iconSize] parameter instead. For example do this: +/// +/// ```dart +/// IconButton( +/// iconSize: 72, +/// icon: const Icon(Icons.favorite), +/// onPressed: () { +/// // ... +/// }, +/// ), +/// ``` +/// +/// Avoid doing this: +/// +/// ```dart +/// IconButton( +/// icon: const Icon(Icons.favorite, size: 72), +/// onPressed: () { +/// // ... +/// }, +/// ), +/// ``` +/// +/// If you do, the button's size will be based on the default icon +/// size, not 72, which may produce unexpected layouts and clipping +/// issues. +/// +/// ### Adding a filled background +/// +/// Icon buttons don't support specifying a background color or other +/// background decoration because typically the icon is just displayed +/// on top of the parent widget's background. Icon buttons that appear +/// in [AppBar.actions] are an example of this. +/// +/// It's easy enough to create an icon button with a filled background +/// using the [Ink] widget. The [Ink] widget renders a decoration on +/// the underlying [Material] along with the splash and highlight +/// [InkResponse] contributed by descendant widgets. +/// +/// {@tool dartpad} +/// In this sample the icon button's background color is defined with an [Ink] +/// widget whose child is an [IconButton]. The icon button's filled background +/// is a light shade of blue, it's a filled circle, and it's as big as the +/// button is. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/icon_button_background.png) +/// +/// ** See code in examples/api/lib/material/icon_button/icon_button.1.dart ** +/// {@end-tool} +/// +/// Material Design 3 introduced new types (standard and contained) of [IconButton]s. +/// The default [IconButton] is the standard type. To create a filled icon button, +/// use [IconButton.filled]; to create a filled tonal icon button, use [IconButton.filledTonal]; +/// to create a outlined icon button, use [IconButton.outlined]. +/// +/// Material Design 3 also treats [IconButton]s as toggle buttons. In order +/// to not break existing apps, the toggle feature can be optionally controlled +/// by the [isSelected] property. +/// +/// If [isSelected] is null it will behave as a normal button. If [isSelected] is not +/// null then it will behave as a toggle button. If [isSelected] is true then it will +/// show [selectedIcon], if it false it will show the normal [icon]. +/// +/// In Material Design 3, both [IconTheme] and [IconButtonTheme] are used to override the default style +/// of [IconButton]. If both themes exist, the [IconButtonTheme] will override [IconTheme] no matter +/// which is closer to the [IconButton]. Each [IconButton]'s property is resolved by the order of +/// precedence: widget property, [IconButtonTheme] property, [IconTheme] property and +/// internal default property value. +/// +/// In Material Design 3, the [IconButton.visualDensity] defaults to [VisualDensity.standard] +/// for all platforms; otherwise the button will have a rounded rectangle shape if +/// the [IconButton.visualDensity] is set to [VisualDensity.compact]. Users can +/// customize it by using [IconButtonTheme], [IconButton.style] or [IconButton.visualDensity]. +/// +/// {@tool dartpad} +/// This sample shows creation of [IconButton] widgets for standard, filled, +/// filled tonal and outlined types, as described in: https://m3.material.io/components/icon-buttons/overview +/// +/// ** See code in examples/api/lib/material/icon_button/icon_button.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows creation of [IconButton] widgets with toggle feature for +/// standard, filled, filled tonal and outlined types, as described +/// in: https://m3.material.io/components/icon-buttons/overview +/// +/// ** See code in examples/api/lib/material/icon_button/icon_button.3.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Icons], the library of Material Icons. +/// * [BackButton], an icon button for a "back" affordance which adapts to the +/// current platform's conventions. +/// * [CloseButton], an icon button for closing pages. +/// * [AppBar], to show a toolbar at the top of an application. +/// * [TextButton], [ElevatedButton], [OutlinedButton], for buttons with text labels and an optional icon. +/// * [InkResponse] and [InkWell], for the ink splash effect itself. +class IconButton extends StatelessWidget { + /// Creates an icon button. + /// + /// Icon buttons are commonly used in the [AppBar.actions] field, but they can + /// be used in many other places as well. + /// + /// Requires one of its ancestors to be a [Material] widget. This requirement + /// no longer exists if [ThemeData.useMaterial3] is set to true. + /// + /// The [icon] argument must be specified, and is typically either an [Icon] + /// or an [ImageIcon]. + const IconButton({ + super.key, + this.iconSize, + this.visualDensity, + this.padding, + this.alignment, + this.splashRadius, + this.color, + this.focusColor, + this.hoverColor, + this.highlightColor, + this.splashColor, + this.disabledColor, + required this.onPressed, + this.mouseCursor, + this.focusNode, + this.autofocus = false, + this.tooltip, + this.enableFeedback, + this.constraints, + this.style, + this.isSelected, + this.selectedIcon, + required this.icon, + }) : assert(splashRadius == null || splashRadius > 0), + _variant = _IconButtonVariant.standard; + + /// Create a filled variant of IconButton. + /// + /// Filled icon buttons have higher visual impact and should be used for + /// high emphasis actions, such as turning off a microphone or camera. + const IconButton.filled({ + super.key, + this.iconSize, + this.visualDensity, + this.padding, + this.alignment, + this.splashRadius, + this.color, + this.focusColor, + this.hoverColor, + this.highlightColor, + this.splashColor, + this.disabledColor, + required this.onPressed, + this.mouseCursor, + this.focusNode, + this.autofocus = false, + this.tooltip, + this.enableFeedback, + this.constraints, + this.style, + this.isSelected, + this.selectedIcon, + required this.icon, + }) : assert(splashRadius == null || splashRadius > 0), + _variant = _IconButtonVariant.filled; + + /// Create a filled tonal variant of IconButton. + /// + /// Filled tonal icon buttons are a middle ground between filled and outlined + /// icon buttons. They’re useful in contexts where the button requires slightly + /// more emphasis than an outline would give, such as a secondary action paired + /// with a high emphasis action. + const IconButton.filledTonal({ + super.key, + this.iconSize, + this.visualDensity, + this.padding, + this.alignment, + this.splashRadius, + this.color, + this.focusColor, + this.hoverColor, + this.highlightColor, + this.splashColor, + this.disabledColor, + required this.onPressed, + this.mouseCursor, + this.focusNode, + this.autofocus = false, + this.tooltip, + this.enableFeedback, + this.constraints, + this.style, + this.isSelected, + this.selectedIcon, + required this.icon, + }) : assert(splashRadius == null || splashRadius > 0), + _variant = _IconButtonVariant.filledTonal; + + /// Create a filled tonal variant of IconButton. + /// + /// Outlined icon buttons are medium-emphasis buttons. They’re useful when an + /// icon button needs more emphasis than a standard icon button but less than + /// a filled or filled tonal icon button. + const IconButton.outlined({ + super.key, + this.iconSize, + this.visualDensity, + this.padding, + this.alignment, + this.splashRadius, + this.color, + this.focusColor, + this.hoverColor, + this.highlightColor, + this.splashColor, + this.disabledColor, + required this.onPressed, + this.mouseCursor, + this.focusNode, + this.autofocus = false, + this.tooltip, + this.enableFeedback, + this.constraints, + this.style, + this.isSelected, + this.selectedIcon, + required this.icon, + }) : assert(splashRadius == null || splashRadius > 0), + _variant = _IconButtonVariant.outlined; + + /// The size of the icon inside the button. + /// + /// If null, uses [IconThemeData.size]. If it is also null, the default size + /// is 24.0. + /// + /// The size given here is passed down to the widget in the [icon] property + /// via an [IconTheme]. Setting the size here instead of in, for example, the + /// [Icon.size] property allows the [IconButton] to size the splash area to + /// fit the [Icon]. If you were to set the size of the [Icon] using + /// [Icon.size] instead, then the [IconButton] would default to 24.0 and then + /// the [Icon] itself would likely get clipped. + /// + /// This property is only used when [icon] is or contains an [Icon] widget. It will be + /// ignored if other widgets are used, such as an [Image]. + /// + /// If [ThemeData.useMaterial3] is set to true and this is null, the size of the + /// [IconButton] would default to 24.0. The size given here is passed down to the + /// [ButtonStyle.iconSize] property. + final double? iconSize; + + /// Defines how compact the icon button's layout will be. + /// + /// {@macro flutter.material.themedata.visualDensity} + /// + /// This property can be null. If null, it defaults to [VisualDensity.standard] + /// in Material Design 3 to make sure the button will be circular on all platforms. + /// + /// See also: + /// + /// * [ThemeData.visualDensity], which specifies the [visualDensity] for all + /// widgets within a [Theme]. + final VisualDensity? visualDensity; + + /// The padding around the button's icon. The entire padded icon will react + /// to input gestures. + /// + /// This property can be null. If null, it defaults to 8.0 padding on all sides. + final EdgeInsetsGeometry? padding; + + /// Defines how the icon is positioned within the IconButton. + /// + /// This property can be null. If null, it defaults to [Alignment.center]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry? alignment; + + /// The splash radius. + /// + /// If [ThemeData.useMaterial3] is set to true, this will not be used. + /// + /// If null, default splash radius of [Material.defaultSplashRadius] is used. + final double? splashRadius; + + /// The icon to display inside the button. + /// + /// The [Icon.size] and [Icon.color] of the icon is configured automatically + /// based on the [iconSize] and [color] properties of _this_ widget using an + /// [IconTheme] and therefore should not be explicitly given in the icon + /// widget. + /// + /// See [Icon], [ImageIcon]. + final Widget icon; + + /// The color for the button when it has the input focus. + /// + /// If [ThemeData.useMaterial3] is set to true, this [focusColor] will be mapped + /// to be the [ButtonStyle.overlayColor] in focused state, which paints on top of + /// the button, as an overlay. Therefore, using a color with some transparency + /// is recommended. For example, one could customize the [focusColor] below: + /// + /// ```dart + /// IconButton( + /// focusColor: Colors.orange.withOpacity(0.3), + /// icon: const Icon(Icons.sunny), + /// onPressed: () { + /// // ... + /// }, + /// ) + /// ``` + /// + /// Defaults to [ThemeData.focusColor] of the ambient theme. + final Color? focusColor; + + /// The color for the button when a pointer is hovering over it. + /// + /// If [ThemeData.useMaterial3] is set to true, this [hoverColor] will be mapped + /// to be the [ButtonStyle.overlayColor] in hovered state, which paints on top of + /// the button, as an overlay. Therefore, using a color with some transparency + /// is recommended. For example, one could customize the [hoverColor] below: + /// + /// ```dart + /// IconButton( + /// hoverColor: Colors.orange.withOpacity(0.3), + /// icon: const Icon(Icons.ac_unit), + /// onPressed: () { + /// // ... + /// }, + /// ) + /// ``` + /// + /// Defaults to [ThemeData.hoverColor] of the ambient theme. + final Color? hoverColor; + + /// The color to use for the icon inside the button, if the icon is enabled. + /// Defaults to leaving this up to the [icon] widget. + /// + /// The icon is enabled if [onPressed] is not null. + /// + /// ```dart + /// IconButton( + /// color: Colors.blue, + /// icon: const Icon(Icons.sunny_snowing), + /// onPressed: () { + /// // ... + /// }, + /// ) + /// ``` + final Color? color; + + /// The primary color of the button when the button is in the down (pressed) state. + /// The splash is represented as a circular overlay that appears above the + /// [highlightColor] overlay. The splash overlay has a center point that matches + /// the hit point of the user touch event. The splash overlay will expand to + /// fill the button area if the touch is held for long enough time. If the splash + /// color has transparency then the highlight and button color will show through. + /// + /// If [ThemeData.useMaterial3] is set to true, this will not be used. Use + /// [highlightColor] instead to show the overlay color of the button when the button + /// is in the pressed state. + /// + /// Defaults to the Theme's splash color, [ThemeData.splashColor]. + final Color? splashColor; + + /// The secondary color of the button when the button is in the down (pressed) + /// state. The highlight color is represented as a solid color that is overlaid over the + /// button color (if any). If the highlight color has transparency, the button color + /// will show through. The highlight fades in quickly as the button is held down. + /// + /// If [ThemeData.useMaterial3] is set to true, this [highlightColor] will be mapped + /// to be the [ButtonStyle.overlayColor] in pressed state, which paints on top + /// of the button, as an overlay. Therefore, using a color with some transparency + /// is recommended. For example, one could customize the [highlightColor] below: + /// + /// ```dart + /// IconButton( + /// highlightColor: Colors.orange.withOpacity(0.3), + /// icon: const Icon(Icons.question_mark), + /// onPressed: () { + /// // ... + /// }, + /// ) + /// ``` + /// + /// Defaults to the Theme's highlight color, [ThemeData.highlightColor]. + final Color? highlightColor; + + /// The color to use for the icon inside the button, if the icon is disabled. + /// Defaults to the [ThemeData.disabledColor] of the current [Theme]. + /// + /// The icon is disabled if [onPressed] is null. + final Color? disabledColor; + + /// The callback that is called when the button is tapped or otherwise activated. + /// + /// If this is set to null, the button will be disabled. + final VoidCallback? onPressed; + + /// {@macro flutter.material.RawMaterialButton.mouseCursor} + /// + /// If set to null, will default to + /// - [SystemMouseCursors.basic], if [onPressed] is null + /// - [SystemMouseCursors.click], otherwise + final MouseCursor? mouseCursor; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// Text that describes the action that will occur when the button is pressed. + /// + /// This text is displayed when the user long-presses on the button and is + /// used for accessibility. + final String? tooltip; + + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + /// Optional size constraints for the button. + /// + /// When unspecified, defaults to: + /// ```dart + /// const BoxConstraints( + /// minWidth: kMinInteractiveDimension, + /// minHeight: kMinInteractiveDimension, + /// ) + /// ``` + /// where [kMinInteractiveDimension] is 48.0, and then with visual density + /// applied. + /// + /// The default constraints ensure that the button is accessible. + /// Specifying this parameter enables creation of buttons smaller than + /// the minimum size, but it is not recommended. + /// + /// The visual density uses the [visualDensity] parameter if specified, + /// and `Theme.of(context).visualDensity` otherwise. + final BoxConstraints? constraints; + + /// Customizes this button's appearance. + /// + /// Non-null properties of this style override the corresponding + /// properties in [_IconButtonM3.themeStyleOf] and [_IconButtonM3.defaultStyleOf]. + /// [MaterialStateProperty]s that resolve to non-null values will similarly + /// override the corresponding [MaterialStateProperty]s in [_IconButtonM3.themeStyleOf] + /// and [_IconButtonM3.defaultStyleOf]. + /// + /// The [style] is only used for Material 3 [IconButton]. If [ThemeData.useMaterial3] + /// is set to true, [style] is preferred for icon button customization, and any + /// parameters defined in [style] will override the same parameters in [IconButton]. + /// + /// For example, if [IconButton]'s [visualDensity] is set to [VisualDensity.standard] + /// and [style]'s [visualDensity] is set to [VisualDensity.compact], + /// the icon button will have [VisualDensity.compact] to define the button's layout. + /// + /// Null by default. + final ButtonStyle? style; + + /// The optional selection state of the icon button. + /// + /// If this property is null, the button will behave as a normal push button, + /// otherwise, the button will toggle between showing [icon] and [selectedIcon] + /// based on the value of [isSelected]. If true, it will show [selectedIcon], + /// if false it will show [icon]. + /// + /// This property is only used if [ThemeData.useMaterial3] is true. + final bool? isSelected; + + /// The icon to display inside the button when [isSelected] is true. This property + /// can be null. The original [icon] will be used for both selected and unselected + /// status if it is null. + /// + /// The [Icon.size] and [Icon.color] of the icon is configured automatically + /// based on the [iconSize] and [color] properties using an [IconTheme] and + /// therefore should not be explicitly configured in the icon widget. + /// + /// This property is only used if [ThemeData.useMaterial3] is true. + /// + /// See also: + /// + /// * [Icon], for icons based on glyphs from fonts instead of images. + /// * [ImageIcon], for showing icons from [AssetImage]s or other [ImageProvider]s. + final Widget? selectedIcon; + + final _IconButtonVariant _variant; + + /// A static convenience method that constructs an icon button + /// [ButtonStyle] given simple values. This method is only used for Material 3. + /// + /// The [foregroundColor] color is used to create a [MaterialStateProperty] + /// [ButtonStyle.foregroundColor] value. Specify a value for [foregroundColor] + /// to specify the color of the button's icons. The [hoverColor], [focusColor] + /// and [highlightColor] colors are used to indicate the hover, focus, + /// and pressed states. Use [backgroundColor] for the button's background + /// fill color. Use [disabledForegroundColor] and [disabledBackgroundColor] + /// to specify the button's disabled icon and fill color. + /// + /// Similarly, the [enabledMouseCursor] and [disabledMouseCursor] + /// parameters are used to construct [ButtonStyle].mouseCursor. + /// + /// All of the other parameters are either used directly or used to + /// create a [MaterialStateProperty] with a single value for all + /// states. + /// + /// All parameters default to null, by default this method returns + /// a [ButtonStyle] that doesn't override anything. + /// + /// For example, to override the default icon color for a + /// [IconButton], as well as its overlay color, with all of the + /// standard opacity adjustments for the pressed, focused, and + /// hovered states, one could write: + /// + /// ```dart + /// IconButton( + /// icon: const Icon(Icons.pets), + /// style: IconButton.styleFrom(foregroundColor: Colors.green), + /// onPressed: () { + /// // ... + /// }, + /// ), + /// ``` + static ButtonStyle styleFrom({ + Color? foregroundColor, + Color? backgroundColor, + Color? disabledForegroundColor, + Color? disabledBackgroundColor, + Color? focusColor, + Color? hoverColor, + Color? highlightColor, + Color? shadowColor, + Color? surfaceTintColor, + double? elevation, + Size? minimumSize, + Size? fixedSize, + Size? maximumSize, + double? iconSize, + BorderSide? side, + OutlinedBorder? shape, + EdgeInsetsGeometry? padding, + MouseCursor? enabledMouseCursor, + MouseCursor? disabledMouseCursor, + VisualDensity? visualDensity, + MaterialTapTargetSize? tapTargetSize, + Duration? animationDuration, + bool? enableFeedback, + AlignmentGeometry? alignment, + InteractiveInkFeatureFactory? splashFactory, + }) { + final MaterialStateProperty<Color?>? buttonBackgroundColor = (backgroundColor == null && disabledBackgroundColor == null) + ? null + : _IconButtonDefaultBackground(backgroundColor, disabledBackgroundColor); + final MaterialStateProperty<Color?>? buttonForegroundColor = (foregroundColor == null && disabledForegroundColor == null) + ? null + : _IconButtonDefaultForeground(foregroundColor, disabledForegroundColor); + final MaterialStateProperty<Color?>? overlayColor = (foregroundColor == null && hoverColor == null && focusColor == null && highlightColor == null) + ? null + : _IconButtonDefaultOverlay(foregroundColor, focusColor, hoverColor, highlightColor); + final MaterialStateProperty<MouseCursor?> mouseCursor = _IconButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor); + + return ButtonStyle( + backgroundColor: buttonBackgroundColor, + foregroundColor: buttonForegroundColor, + overlayColor: overlayColor, + shadowColor: ButtonStyleButton.allOrNull<Color>(shadowColor), + surfaceTintColor: ButtonStyleButton.allOrNull<Color>(surfaceTintColor), + elevation: ButtonStyleButton.allOrNull<double>(elevation), + padding: ButtonStyleButton.allOrNull<EdgeInsetsGeometry>(padding), + minimumSize: ButtonStyleButton.allOrNull<Size>(minimumSize), + fixedSize: ButtonStyleButton.allOrNull<Size>(fixedSize), + maximumSize: ButtonStyleButton.allOrNull<Size>(maximumSize), + iconSize: ButtonStyleButton.allOrNull<double>(iconSize), + side: ButtonStyleButton.allOrNull<BorderSide>(side), + shape: ButtonStyleButton.allOrNull<OutlinedBorder>(shape), + mouseCursor: mouseCursor, + visualDensity: visualDensity, + tapTargetSize: tapTargetSize, + animationDuration: animationDuration, + enableFeedback: enableFeedback, + alignment: alignment, + splashFactory: splashFactory, + ); + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + + if (theme.useMaterial3) { + final Size? minSize = constraints == null + ? null + : Size(constraints!.minWidth, constraints!.minHeight); + final Size? maxSize = constraints == null + ? null + : Size(constraints!.maxWidth, constraints!.maxHeight); + + ButtonStyle adjustedStyle = styleFrom( + visualDensity: visualDensity, + foregroundColor: color, + disabledForegroundColor: disabledColor, + focusColor: focusColor, + hoverColor: hoverColor, + highlightColor: highlightColor, + padding: padding, + minimumSize: minSize, + maximumSize: maxSize, + iconSize: iconSize, + alignment: alignment, + enabledMouseCursor: mouseCursor, + disabledMouseCursor: mouseCursor, + enableFeedback: enableFeedback, + ); + if (style != null) { + adjustedStyle = style!.merge(adjustedStyle); + } + + Widget effectiveIcon = icon; + if ((isSelected ?? false) && selectedIcon != null) { + effectiveIcon = selectedIcon!; + } + + Widget iconButton = effectiveIcon; + if (tooltip != null) { + iconButton = Tooltip( + message: tooltip, + child: effectiveIcon, + ); + } + + return _SelectableIconButton( + style: adjustedStyle, + onPressed: onPressed, + autofocus: autofocus, + focusNode: focusNode, + isSelected: isSelected, + variant: _variant, + child: iconButton, + ); + } + + assert(debugCheckHasMaterial(context)); + + Color? currentColor; + if (onPressed != null) { + currentColor = color; + } else { + currentColor = disabledColor ?? theme.disabledColor; + } + + final VisualDensity effectiveVisualDensity = visualDensity ?? theme.visualDensity; + + final BoxConstraints unadjustedConstraints = constraints ?? const BoxConstraints( + minWidth: _kMinButtonSize, + minHeight: _kMinButtonSize, + ); + final BoxConstraints adjustedConstraints = effectiveVisualDensity.effectiveConstraints(unadjustedConstraints); + final double effectiveIconSize = iconSize ?? IconTheme.of(context).size ?? 24.0; + final EdgeInsetsGeometry effectivePadding = padding ?? const EdgeInsets.all(8.0); + final AlignmentGeometry effectiveAlignment = alignment ?? Alignment.center; + final bool effectiveEnableFeedback = enableFeedback ?? true; + + Widget result = ConstrainedBox( + constraints: adjustedConstraints, + child: Padding( + padding: effectivePadding, + child: SizedBox( + height: effectiveIconSize, + width: effectiveIconSize, + child: Align( + alignment: effectiveAlignment, + child: IconTheme.merge( + data: IconThemeData( + size: effectiveIconSize, + color: currentColor, + ), + child: icon, + ), + ), + ), + ), + ); + + if (tooltip != null) { + result = Tooltip( + message: tooltip, + child: result, + ); + } + + return Semantics( + button: true, + enabled: onPressed != null, + child: InkResponse( + focusNode: focusNode, + autofocus: autofocus, + canRequestFocus: onPressed != null, + onTap: onPressed, + mouseCursor: mouseCursor ?? (onPressed == null ? SystemMouseCursors.basic : SystemMouseCursors.click), + enableFeedback: effectiveEnableFeedback, + focusColor: focusColor ?? theme.focusColor, + hoverColor: hoverColor ?? theme.hoverColor, + highlightColor: highlightColor ?? theme.highlightColor, + splashColor: splashColor ?? theme.splashColor, + radius: splashRadius ?? math.max( + Material.defaultSplashRadius, + (effectiveIconSize + math.min(effectivePadding.horizontal, effectivePadding.vertical)) * 0.7, + // x 0.5 for diameter -> radius and + 40% overflow derived from other Material apps. + ), + child: result, + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Widget>('icon', icon, showName: false)); + properties.add(StringProperty('tooltip', tooltip, defaultValue: null, quoted: false)); + properties.add(ObjectFlagProperty<VoidCallback>('onPressed', onPressed, ifNull: 'disabled')); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: null)); + properties.add(ColorProperty('focusColor', focusColor, defaultValue: null)); + properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: null)); + properties.add(ColorProperty('highlightColor', highlightColor, defaultValue: null)); + properties.add(ColorProperty('splashColor', splashColor, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null)); + } +} + +class _SelectableIconButton extends StatefulWidget { + const _SelectableIconButton({ + this.isSelected, + this.style, + this.focusNode, + required this.variant, + required this.autofocus, + required this.onPressed, + required this.child, + }); + + final bool? isSelected; + final ButtonStyle? style; + final FocusNode? focusNode; + final _IconButtonVariant variant; + final bool autofocus; + final VoidCallback? onPressed; + final Widget child; + + @override + State<_SelectableIconButton> createState() => _SelectableIconButtonState(); +} + +class _SelectableIconButtonState extends State<_SelectableIconButton> { + late final MaterialStatesController statesController; + + @override + void initState() { + super.initState(); + if (widget.isSelected == null) { + statesController = MaterialStatesController(); + } else { + statesController = MaterialStatesController(<MaterialState>{ + if (widget.isSelected!) MaterialState.selected + }); + } + } + + @override + void didUpdateWidget(_SelectableIconButton oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.isSelected == null) { + if (statesController.value.contains(MaterialState.selected)) { + statesController.update(MaterialState.selected, false); + } + return; + } + if (widget.isSelected != oldWidget.isSelected) { + statesController.update(MaterialState.selected, widget.isSelected!); + } + } + + @override + Widget build(BuildContext context) { + final bool toggleable = widget.isSelected != null; + + return _IconButtonM3( + statesController: statesController, + style: widget.style, + autofocus: widget.autofocus, + focusNode: widget.focusNode, + onPressed: widget.onPressed, + variant: widget.variant, + toggleable: toggleable, + child: Semantics( + selected: widget.isSelected, + child: widget.child, + ), + ); + } + + @override + void dispose() { + statesController.dispose(); + super.dispose(); + } +} + +class _IconButtonM3 extends ButtonStyleButton { + const _IconButtonM3({ + required super.onPressed, + super.style, + super.focusNode, + super.autofocus = false, + super.statesController, + required this.variant, + required this.toggleable, + required Widget super.child, + }) : super( + onLongPress: null, + onHover: null, + onFocusChange: null, + clipBehavior: Clip.none); + + final _IconButtonVariant variant; + final bool toggleable; + + /// ## Material 3 defaults + /// + /// If [ThemeData.useMaterial3] is set to true the following defaults will + /// be used: + /// + /// * `textStyle` - null + /// * `backgroundColor` - transparent + /// * `foregroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.38) + /// * selected - Theme.colorScheme.primary + /// * others - Theme.colorScheme.onSurfaceVariant + /// * `overlayColor` + /// * selected + /// * hovered - Theme.colorScheme.primary(0.08) + /// * focused or pressed - Theme.colorScheme.primary(0.12) + /// * hovered or focused - Theme.colorScheme.onSurfaceVariant(0.08) + /// * pressed - Theme.colorScheme.onSurfaceVariant(0.12) + /// * others - null + /// * `shadowColor` - null + /// * `surfaceTintColor` - null + /// * `elevation` - 0 + /// * `padding` - all(8) + /// * `minimumSize` - Size(40, 40) + /// * `fixedSize` - null + /// * `maximumSize` - Size.infinite + /// * `iconSize` - 24 + /// * `side` - null + /// * `shape` - StadiumBorder() + /// * `mouseCursor` + /// * disabled - SystemMouseCursors.basic + /// * others - SystemMouseCursors.click + /// * `visualDensity` - VisualDensity.standard + /// * `tapTargetSize` - theme.materialTapTargetSize + /// * `animationDuration` - kThemeChangeDuration + /// * `enableFeedback` - true + /// * `alignment` - Alignment.center + /// * `splashFactory` - Theme.splashFactory + @override + ButtonStyle defaultStyleOf(BuildContext context) { + switch (variant) { + case _IconButtonVariant.filled: + return _FilledIconButtonDefaultsM3(context, toggleable); + case _IconButtonVariant.filledTonal: + return _FilledTonalIconButtonDefaultsM3(context, toggleable); + case _IconButtonVariant.outlined: + return _OutlinedIconButtonDefaultsM3(context, toggleable); + case _IconButtonVariant.standard: + return _IconButtonDefaultsM3(context, toggleable); + } + } + + /// Returns the [IconButtonThemeData.style] of the closest [IconButtonTheme] ancestor. + /// The color and icon size can also be configured by the [IconTheme] if the same property + /// has a null value in [IconButtonTheme]. However, if any of the properties exist + /// in both [IconButtonTheme] and [IconTheme], [IconTheme] will be overridden. + @override + ButtonStyle? themeStyleOf(BuildContext context) { + final IconThemeData iconTheme = IconTheme.of(context); + final bool isDark = Theme.of(context).brightness == Brightness.dark; + + bool isIconThemeDefault(Color? color) { + if (isDark) { + return identical(color, kDefaultIconLightColor); + } + return identical(color, kDefaultIconDarkColor); + } + final bool isDefaultColor = isIconThemeDefault(iconTheme.color); + final bool isDefaultSize = iconTheme.size == const IconThemeData.fallback().size; + + final ButtonStyle iconThemeStyle = IconButton.styleFrom( + foregroundColor: isDefaultColor ? null : iconTheme.color, + iconSize: isDefaultSize ? null : iconTheme.size + ); + + return IconButtonTheme.of(context).style?.merge(iconThemeStyle) ?? iconThemeStyle; + } +} + +@immutable +class _IconButtonDefaultBackground extends MaterialStateProperty<Color?> { + _IconButtonDefaultBackground(this.background, this.disabledBackground); + + final Color? background; + final Color? disabledBackground; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabledBackground; + } + return background; + } + + @override + String toString() { + return '{disabled: $disabledBackground, otherwise: $background}'; + } +} + +@immutable +class _IconButtonDefaultForeground extends MaterialStateProperty<Color?> { + _IconButtonDefaultForeground(this.foregroundColor, this.disabledForegroundColor); + + final Color? foregroundColor; + final Color? disabledForegroundColor; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabledForegroundColor; + } + return foregroundColor; + } + + @override + String toString() { + return '{disabled: $disabledForegroundColor, otherwise: $foregroundColor}'; + } +} + +@immutable +class _IconButtonDefaultOverlay extends MaterialStateProperty<Color?> { + _IconButtonDefaultOverlay(this.foregroundColor, this.focusColor, this.hoverColor, this.highlightColor); + + final Color? foregroundColor; + final Color? focusColor; + final Color? hoverColor; + final Color? highlightColor; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return highlightColor ?? foregroundColor?.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return hoverColor ?? foregroundColor?.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return focusColor ?? foregroundColor?.withOpacity(0.12); + } + } + if (states.contains(MaterialState.pressed)) { + return highlightColor ?? foregroundColor?.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return hoverColor ?? foregroundColor?.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return focusColor ?? foregroundColor?.withOpacity(0.08); + } + return null; + } + + @override + String toString() { + return '{hovered: $hoverColor, focused: $focusColor, pressed: $highlightColor, otherwise: null}'; + } +} + +@immutable +class _IconButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor?> with Diagnosticable { + _IconButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor); + + final MouseCursor? enabledCursor; + final MouseCursor? disabledCursor; + + @override + MouseCursor? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabledCursor; + } + return enabledCursor; + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - IconButton + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _IconButtonDefaultsM3 extends ButtonStyle { + _IconButtonDefaultsM3(this.context, this.toggleable) + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + ); + + final BuildContext context; + final bool toggleable; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + // No default text style + + @override + MaterialStateProperty<Color?>? get backgroundColor => + const MaterialStatePropertyAll<Color?>(Colors.transparent); + + @override + MaterialStateProperty<Color?>? get foregroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.selected)) { + return _colors.primary; + } + return _colors.onSurfaceVariant; + }); + + @override + MaterialStateProperty<Color?>? get overlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.primary.withOpacity(0.12); + } + } + if (states.contains(MaterialState.pressed)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurfaceVariant.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + return Colors.transparent; + }); + + @override + MaterialStateProperty<double>? get elevation => + const MaterialStatePropertyAll<double>(0.0); + + @override + MaterialStateProperty<Color>? get shadowColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<Color>? get surfaceTintColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding => + const MaterialStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.all(8.0)); + + @override + MaterialStateProperty<Size>? get minimumSize => + const MaterialStatePropertyAll<Size>(Size(40.0, 40.0)); + + // No default fixedSize + + @override + MaterialStateProperty<Size>? get maximumSize => + const MaterialStatePropertyAll<Size>(Size.infinite); + + @override + MaterialStateProperty<double>? get iconSize => + const MaterialStatePropertyAll<double>(24.0); + + @override + MaterialStateProperty<BorderSide?>? get side => null; + + @override + MaterialStateProperty<OutlinedBorder>? get shape => + const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); + + @override + MaterialStateProperty<MouseCursor?>? get mouseCursor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return SystemMouseCursors.click; + }); + + @override + VisualDensity? get visualDensity => VisualDensity.standard; + + @override + MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize; + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; +} + +// END GENERATED TOKEN PROPERTIES - IconButton + +// BEGIN GENERATED TOKEN PROPERTIES - FilledIconButton + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _FilledIconButtonDefaultsM3 extends ButtonStyle { + _FilledIconButtonDefaultsM3(this.context, this.toggleable) + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + ); + + final BuildContext context; + final bool toggleable; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + // No default text style + + @override + MaterialStateProperty<Color?>? get backgroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.selected)) { + return _colors.primary; + } + if (toggleable) { // toggleable but unselected case + return _colors.surfaceVariant; + } + return _colors.primary; + }); + + @override + MaterialStateProperty<Color?>? get foregroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.selected)) { + return _colors.onPrimary; + } + if (toggleable) { // toggleable but unselected case + return _colors.primary; + } + return _colors.onPrimary; + }); + + @override + MaterialStateProperty<Color?>? get overlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onPrimary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onPrimary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onPrimary.withOpacity(0.12); + } + } + if (toggleable) { // toggleable but unselected case + if (states.contains(MaterialState.pressed)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.primary.withOpacity(0.12); + } + } + if (states.contains(MaterialState.pressed)) { + return _colors.onPrimary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onPrimary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onPrimary.withOpacity(0.12); + } + return Colors.transparent; + }); + + @override + MaterialStateProperty<double>? get elevation => + const MaterialStatePropertyAll<double>(0.0); + + @override + MaterialStateProperty<Color>? get shadowColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<Color>? get surfaceTintColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding => + const MaterialStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.all(8.0)); + + @override + MaterialStateProperty<Size>? get minimumSize => + const MaterialStatePropertyAll<Size>(Size(40.0, 40.0)); + + // No default fixedSize + + @override + MaterialStateProperty<Size>? get maximumSize => + const MaterialStatePropertyAll<Size>(Size.infinite); + + @override + MaterialStateProperty<double>? get iconSize => + const MaterialStatePropertyAll<double>(24.0); + + @override + MaterialStateProperty<BorderSide?>? get side => null; + + @override + MaterialStateProperty<OutlinedBorder>? get shape => + const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); + + @override + MaterialStateProperty<MouseCursor?>? get mouseCursor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return SystemMouseCursors.click; + }); + + @override + VisualDensity? get visualDensity => VisualDensity.standard; + + @override + MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize; + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; +} + +// END GENERATED TOKEN PROPERTIES - FilledIconButton + +// BEGIN GENERATED TOKEN PROPERTIES - FilledTonalIconButton + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _FilledTonalIconButtonDefaultsM3 extends ButtonStyle { + _FilledTonalIconButtonDefaultsM3(this.context, this.toggleable) + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + ); + + final BuildContext context; + final bool toggleable; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + // No default text style + + @override + MaterialStateProperty<Color?>? get backgroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.selected)) { + return _colors.secondaryContainer; + } + if (toggleable) { // toggleable but unselected case + return _colors.surfaceVariant; + } + return _colors.secondaryContainer; + }); + + @override + MaterialStateProperty<Color?>? get foregroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.selected)) { + return _colors.onSecondaryContainer; + } + if (toggleable) { // toggleable but unselected case + return _colors.onSurfaceVariant; + } + return _colors.onSecondaryContainer; + }); + + @override + MaterialStateProperty<Color?>? get overlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onSecondaryContainer.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSecondaryContainer.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSecondaryContainer.withOpacity(0.12); + } + } + if (toggleable) { // toggleable but unselected case + if (states.contains(MaterialState.pressed)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurfaceVariant.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurfaceVariant.withOpacity(0.12); + } + } + if (states.contains(MaterialState.pressed)) { + return _colors.onSecondaryContainer.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSecondaryContainer.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSecondaryContainer.withOpacity(0.12); + } + return Colors.transparent; + }); + + @override + MaterialStateProperty<double>? get elevation => + const MaterialStatePropertyAll<double>(0.0); + + @override + MaterialStateProperty<Color>? get shadowColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<Color>? get surfaceTintColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding => + const MaterialStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.all(8.0)); + + @override + MaterialStateProperty<Size>? get minimumSize => + const MaterialStatePropertyAll<Size>(Size(40.0, 40.0)); + + // No default fixedSize + + @override + MaterialStateProperty<Size>? get maximumSize => + const MaterialStatePropertyAll<Size>(Size.infinite); + + @override + MaterialStateProperty<double>? get iconSize => + const MaterialStatePropertyAll<double>(24.0); + + @override + MaterialStateProperty<BorderSide?>? get side => null; + + @override + MaterialStateProperty<OutlinedBorder>? get shape => + const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); + + @override + MaterialStateProperty<MouseCursor?>? get mouseCursor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return SystemMouseCursors.click; + }); + + @override + VisualDensity? get visualDensity => VisualDensity.standard; + + @override + MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize; + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; +} + +// END GENERATED TOKEN PROPERTIES - FilledTonalIconButton + +// BEGIN GENERATED TOKEN PROPERTIES - OutlinedIconButton + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _OutlinedIconButtonDefaultsM3 extends ButtonStyle { + _OutlinedIconButtonDefaultsM3(this.context, this.toggleable) + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + ); + + final BuildContext context; + final bool toggleable; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + // No default text style + + @override + MaterialStateProperty<Color?>? get backgroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + if (states.contains(MaterialState.selected)) { + return _colors.onSurface.withOpacity(0.12); + } + return Colors.transparent; + } + if (states.contains(MaterialState.selected)) { + return _colors.inverseSurface; + } + return Colors.transparent; + }); + + @override + MaterialStateProperty<Color?>? get foregroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.selected)) { + return _colors.onInverseSurface; + } + return _colors.onSurfaceVariant; + }); + + @override + MaterialStateProperty<Color?>? get overlayColor => MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onInverseSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onInverseSurface.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onInverseSurface.withOpacity(0.08); + } + } + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurfaceVariant.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurfaceVariant.withOpacity(0.08); + } + return Colors.transparent; + }); + + @override + MaterialStateProperty<double>? get elevation => + const MaterialStatePropertyAll<double>(0.0); + + @override + MaterialStateProperty<Color>? get shadowColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<Color>? get surfaceTintColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding => + const MaterialStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.all(8.0)); + + @override + MaterialStateProperty<Size>? get minimumSize => + const MaterialStatePropertyAll<Size>(Size(40.0, 40.0)); + + // No default fixedSize + + @override + MaterialStateProperty<Size>? get maximumSize => + const MaterialStatePropertyAll<Size>(Size.infinite); + + @override + MaterialStateProperty<double>? get iconSize => + const MaterialStatePropertyAll<double>(24.0); + + @override + MaterialStateProperty<BorderSide?>? get side => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return null; + } else { + if (states.contains(MaterialState.disabled)) { + return BorderSide(color: _colors.onSurface.withOpacity(0.12)); + } + return BorderSide(color: _colors.outline); + } + }); + + @override + MaterialStateProperty<OutlinedBorder>? get shape => + const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); + + @override + MaterialStateProperty<MouseCursor?>? get mouseCursor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return SystemMouseCursors.click; + }); + + @override + VisualDensity? get visualDensity => VisualDensity.standard; + + @override + MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize; + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; +} + +// END GENERATED TOKEN PROPERTIES - OutlinedIconButton diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/icon_button_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/icon_button_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..b598dc1075caf855fc534dbef84d7720641f954c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/icon_button_theme.dart @@ -0,0 +1,123 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// A [ButtonStyle] that overrides the default appearance of +/// [IconButton]s when it's used with the [IconButton], the [IconButtonTheme] or the +/// overall [Theme]'s [ThemeData.iconButtonTheme]. +/// +/// The [IconButton] will be affected by [IconButtonTheme] and [IconButtonThemeData] +/// only if [ThemeData.useMaterial3] is set to true; otherwise, [IconTheme] will be used. +/// +/// The [style]'s properties override [IconButton]'s default style. Only +/// the style's non-null property values or resolved non-null +/// [MaterialStateProperty] values are used. +/// +/// See also: +/// +/// * [IconButtonTheme], the theme which is configured with this class. +/// * [IconButton.styleFrom], which converts simple values into a +/// [ButtonStyle] that's consistent with [IconButton]'s defaults. +/// * [MaterialStateProperty.resolve], "resolve" a material state property +/// to a simple value based on a set of [MaterialState]s. +/// * [ThemeData.iconButtonTheme], which can be used to override the default +/// [ButtonStyle] for [IconButton]s below the overall [Theme]. +@immutable +class IconButtonThemeData with Diagnosticable { + /// Creates a [IconButtonThemeData]. + /// + /// The [style] may be null. + const IconButtonThemeData({ this.style }); + + /// Overrides for [IconButton]'s default style if [ThemeData.useMaterial3] + /// is set to true. + /// + /// Non-null properties or non-null resolved [MaterialStateProperty] + /// values override the default [ButtonStyle] in [IconButton]. + /// + /// If [style] is null, then this theme doesn't override anything. + final ButtonStyle? style; + + /// Linearly interpolate between two icon button themes. + static IconButtonThemeData? lerp(IconButtonThemeData? a, IconButtonThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return IconButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + ); + } + + @override + int get hashCode => style.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is IconButtonThemeData && other.style == style; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ButtonStyle>('style', style, defaultValue: null)); + } +} + +/// Overrides the default [ButtonStyle] of its [IconButton] descendants. +/// +/// See also: +/// +/// * [IconButtonThemeData], which is used to configure this theme. +/// * [IconButton.styleFrom], which converts simple values into a +/// [ButtonStyle] that's consistent with [IconButton]'s defaults. +/// * [ThemeData.iconButtonTheme], which can be used to override the default +/// [ButtonStyle] for [IconButton]s below the overall [Theme]. +class IconButtonTheme extends InheritedTheme { + /// Create a [IconButtonTheme]. + const IconButtonTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The configuration of this theme. + final IconButtonThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [IconButtonTheme] widget, then + /// [ThemeData.iconButtonTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// IconButtonThemeData theme = IconButtonTheme.of(context); + /// ``` + static IconButtonThemeData of(BuildContext context) { + final IconButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<IconButtonTheme>(); + return buttonTheme?.data ?? Theme.of(context).iconButtonTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return IconButtonTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(IconButtonTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/icons.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/icons.dart new file mode 100644 index 0000000000000000000000000000000000000000..cdf5798213598a485ba870e5bdb648798af191c6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/icons.dart @@ -0,0 +1,26659 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show defaultTargetPlatform; +import 'package:flutter/widgets.dart'; + +// ignore_for_file: non_constant_identifier_names + +/// A set of platform-adaptive Material Design icons. +/// +/// Use [Icons.adaptive] to access a static instance of this class. +final class PlatformAdaptiveIcons implements Icons { + const PlatformAdaptiveIcons._(); + + static bool _isCupertino() { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return false; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return true; + } + } + + // Generated code: do not hand-edit. + // See https://github.com/flutter/flutter/wiki/Updating-Material-Design-Fonts-&-Icons + + // BEGIN GENERATED PLATFORM ADAPTIVE ICONS + + /// Platform-adaptive icon for <i class="material-icons md-36">arrow_back</i> — material icon named "arrow back" and <i class="material-icons md-36">arrow_back_ios</i> — material icon named "arrow back ios".; + IconData get arrow_back => !_isCupertino() ? Icons.arrow_back : Icons.arrow_back_ios; + + /// Platform-adaptive icon for <i class="material-icons-outlined md-36">arrow_back</i> — material icon named "arrow back" (outlined) and <i class="material-icons-outlined md-36">arrow_back_ios</i> — material icon named "arrow back ios" (outlined).; + IconData get arrow_back_outlined => !_isCupertino() ? Icons.arrow_back_outlined : Icons.arrow_back_ios_outlined; + + /// Platform-adaptive icon for <i class="material-icons-round md-36">arrow_back</i> — material icon named "arrow back" (round) and <i class="material-icons-round md-36">arrow_back_ios</i> — material icon named "arrow back ios" (round).; + IconData get arrow_back_rounded => !_isCupertino() ? Icons.arrow_back_rounded : Icons.arrow_back_ios_rounded; + + /// Platform-adaptive icon for <i class="material-icons-sharp md-36">arrow_back</i> — material icon named "arrow back" (sharp) and <i class="material-icons-sharp md-36">arrow_back_ios</i> — material icon named "arrow back ios" (sharp).; + IconData get arrow_back_sharp => !_isCupertino() ? Icons.arrow_back_sharp : Icons.arrow_back_ios_sharp; + + /// Platform-adaptive icon for <i class="material-icons md-36">arrow_forward</i> — material icon named "arrow forward" and <i class="material-icons md-36">arrow_forward_ios</i> — material icon named "arrow forward ios".; + IconData get arrow_forward => !_isCupertino() ? Icons.arrow_forward : Icons.arrow_forward_ios; + + /// Platform-adaptive icon for <i class="material-icons-outlined md-36">arrow_forward</i> — material icon named "arrow forward" (outlined) and <i class="material-icons-outlined md-36">arrow_forward_ios</i> — material icon named "arrow forward ios" (outlined).; + IconData get arrow_forward_outlined => !_isCupertino() ? Icons.arrow_forward_outlined : Icons.arrow_forward_ios_outlined; + + /// Platform-adaptive icon for <i class="material-icons-round md-36">arrow_forward</i> — material icon named "arrow forward" (round) and <i class="material-icons-round md-36">arrow_forward_ios</i> — material icon named "arrow forward ios" (round).; + IconData get arrow_forward_rounded => !_isCupertino() ? Icons.arrow_forward_rounded : Icons.arrow_forward_ios_rounded; + + /// Platform-adaptive icon for <i class="material-icons-sharp md-36">arrow_forward</i> — material icon named "arrow forward" (sharp) and <i class="material-icons-sharp md-36">arrow_forward_ios</i> — material icon named "arrow forward ios" (sharp).; + IconData get arrow_forward_sharp => !_isCupertino() ? Icons.arrow_forward_sharp : Icons.arrow_forward_ios_sharp; + + /// Platform-adaptive icon for <i class="material-icons md-36">flip_camera_android</i> — material icon named "flip camera android" and <i class="material-icons md-36">flip_camera_ios</i> — material icon named "flip camera ios".; + IconData get flip_camera => !_isCupertino() ? Icons.flip_camera_android : Icons.flip_camera_ios; + + /// Platform-adaptive icon for <i class="material-icons-outlined md-36">flip_camera_android</i> — material icon named "flip camera android" (outlined) and <i class="material-icons-outlined md-36">flip_camera_ios</i> — material icon named "flip camera ios" (outlined).; + IconData get flip_camera_outlined => !_isCupertino() ? Icons.flip_camera_android_outlined : Icons.flip_camera_ios_outlined; + + /// Platform-adaptive icon for <i class="material-icons-round md-36">flip_camera_android</i> — material icon named "flip camera android" (round) and <i class="material-icons-round md-36">flip_camera_ios</i> — material icon named "flip camera ios" (round).; + IconData get flip_camera_rounded => !_isCupertino() ? Icons.flip_camera_android_rounded : Icons.flip_camera_ios_rounded; + + /// Platform-adaptive icon for <i class="material-icons-sharp md-36">flip_camera_android</i> — material icon named "flip camera android" (sharp) and <i class="material-icons-sharp md-36">flip_camera_ios</i> — material icon named "flip camera ios" (sharp).; + IconData get flip_camera_sharp => !_isCupertino() ? Icons.flip_camera_android_sharp : Icons.flip_camera_ios_sharp; + + /// Platform-adaptive icon for <i class="material-icons md-36">more_vert</i> — material icon named "more vert" and <i class="material-icons md-36">more_horiz</i> — material icon named "more horiz".; + IconData get more => !_isCupertino() ? Icons.more_vert : Icons.more_horiz; + + /// Platform-adaptive icon for <i class="material-icons-outlined md-36">more_vert</i> — material icon named "more vert" (outlined) and <i class="material-icons-outlined md-36">more_horiz</i> — material icon named "more horiz" (outlined).; + IconData get more_outlined => !_isCupertino() ? Icons.more_vert_outlined : Icons.more_horiz_outlined; + + /// Platform-adaptive icon for <i class="material-icons-round md-36">more_vert</i> — material icon named "more vert" (round) and <i class="material-icons-round md-36">more_horiz</i> — material icon named "more horiz" (round).; + IconData get more_rounded => !_isCupertino() ? Icons.more_vert_rounded : Icons.more_horiz_rounded; + + /// Platform-adaptive icon for <i class="material-icons-sharp md-36">more_vert</i> — material icon named "more vert" (sharp) and <i class="material-icons-sharp md-36">more_horiz</i> — material icon named "more horiz" (sharp).; + IconData get more_sharp => !_isCupertino() ? Icons.more_vert_sharp : Icons.more_horiz_sharp; + + /// Platform-adaptive icon for <i class="material-icons md-36">share</i> — material icon named "share" and <i class="material-icons md-36">ios_share</i> — material icon named "ios share".; + IconData get share => !_isCupertino() ? Icons.share : Icons.ios_share; + + /// Platform-adaptive icon for <i class="material-icons-outlined md-36">share</i> — material icon named "share" (outlined) and <i class="material-icons-outlined md-36">ios_share</i> — material icon named "ios share" (outlined).; + IconData get share_outlined => !_isCupertino() ? Icons.share_outlined : Icons.ios_share_outlined; + + /// Platform-adaptive icon for <i class="material-icons-round md-36">share</i> — material icon named "share" (round) and <i class="material-icons-round md-36">ios_share</i> — material icon named "ios share" (round).; + IconData get share_rounded => !_isCupertino() ? Icons.share_rounded : Icons.ios_share_rounded; + + /// Platform-adaptive icon for <i class="material-icons-sharp md-36">share</i> — material icon named "share" (sharp) and <i class="material-icons-sharp md-36">ios_share</i> — material icon named "ios share" (sharp).; + IconData get share_sharp => !_isCupertino() ? Icons.share_sharp : Icons.ios_share_sharp; + // END GENERATED PLATFORM ADAPTIVE ICONS +} + +/// Identifiers for the supported [Material Icons](https://material.io/resources/icons). +/// +/// Use with the [Icon] class to show specific icons. Icons are identified by +/// their name as listed below, e.g. [Icons.airplanemode_on]. +/// +/// Search and find the perfect icon on the [Google Fonts](https://material.io/resources/icons) website. +/// +/// To use this class, make sure you set `uses-material-design: true` in your +/// project's `pubspec.yaml` file in the `flutter` section. This ensures that +/// the Material Icons font is included in your application. This font is used to +/// display the icons. For example: +/// +/// ```yaml +/// name: my_awesome_application +/// flutter: +/// uses-material-design: true +/// ``` +/// +/// {@tool snippet} +/// This example shows how to create a [Row] of [Icon]s in different colors and +/// sizes. The first [Icon] uses a [Icon.semanticLabel] to announce in accessibility +/// modes like TalkBack and VoiceOver. +/// +/// ![The following code snippet would generate a row of icons consisting of a pink heart, a green musical note, and a blue umbrella, each progressively bigger than the last.](https://flutter.github.io/assets-for-api-docs/assets/widgets/icon.png) +/// +/// ```dart +/// const Row( +/// mainAxisAlignment: MainAxisAlignment.spaceAround, +/// children: <Widget>[ +/// Icon( +/// Icons.favorite, +/// color: Colors.pink, +/// size: 24.0, +/// semanticLabel: 'Text to announce in accessibility modes', +/// ), +/// Icon( +/// Icons.audiotrack, +/// color: Colors.green, +/// size: 30.0, +/// ), +/// Icon( +/// Icons.beach_access, +/// color: Colors.blue, +/// size: 36.0, +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Icon] +/// * [IconButton] +/// * <https://material.io/resources/icons> +/// * [AnimatedIcons], for the list of available animated Material Icons. +@staticIconProvider +abstract final class Icons { + /// A set of platform-adaptive Material Design icons. + /// + /// Provides a convenient way to show a certain set of platform-appropriate + /// icons on Apple platforms. + /// + /// Use with the [Icon] class to show specific icons. + /// + /// {@tool snippet} + /// This example shows how to create a share icon that uses the material icon + /// named "share" on non-Apple platforms, and the icon named "ios share" on + /// Apple platforms. + /// + /// ```dart + /// Icon( + /// Icons.adaptive.share, + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [Icon] + /// * [IconButton] + /// * <https://design.google.com/icons/> + static PlatformAdaptiveIcons get adaptive => const PlatformAdaptiveIcons._(); + + // Generated code: do not hand-edit. + // See https://github.com/flutter/flutter/wiki/Updating-Material-Design-Fonts-&-Icons + // BEGIN GENERATED ICONS + + /// <i class="material-icons md-36">10k</i> — material icon named "10k". + static const IconData ten_k = IconData(0xe000, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">10k</i> — material icon named "10k" (sharp). + static const IconData ten_k_sharp = IconData(0xe700, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">10k</i> — material icon named "10k" (round). + static const IconData ten_k_rounded = IconData(0xf4df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">10k</i> — material icon named "10k" (outlined). + static const IconData ten_k_outlined = IconData(0xedf2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">10mp</i> — material icon named "10mp". + static const IconData ten_mp = IconData(0xe001, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">10mp</i> — material icon named "10mp" (sharp). + static const IconData ten_mp_sharp = IconData(0xe701, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">10mp</i> — material icon named "10mp" (round). + static const IconData ten_mp_rounded = IconData(0xf4e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">10mp</i> — material icon named "10mp" (outlined). + static const IconData ten_mp_outlined = IconData(0xedf3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">11mp</i> — material icon named "11mp". + static const IconData eleven_mp = IconData(0xe002, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">11mp</i> — material icon named "11mp" (sharp). + static const IconData eleven_mp_sharp = IconData(0xe702, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">11mp</i> — material icon named "11mp" (round). + static const IconData eleven_mp_rounded = IconData(0xf4e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">11mp</i> — material icon named "11mp" (outlined). + static const IconData eleven_mp_outlined = IconData(0xedf4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">123</i> — material icon named "123". + static const IconData onetwothree = IconData(0xf04b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">123</i> — material icon named "123" (sharp). + static const IconData onetwothree_sharp = IconData(0xf03c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">123</i> — material icon named "123" (round). + static const IconData onetwothree_rounded = IconData(0xe340, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">123</i> — material icon named "123" (outlined). + static const IconData onetwothree_outlined = IconData(0xf05b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">12mp</i> — material icon named "12mp". + static const IconData twelve_mp = IconData(0xe003, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">12mp</i> — material icon named "12mp" (sharp). + static const IconData twelve_mp_sharp = IconData(0xe703, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">12mp</i> — material icon named "12mp" (round). + static const IconData twelve_mp_rounded = IconData(0xf4e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">12mp</i> — material icon named "12mp" (outlined). + static const IconData twelve_mp_outlined = IconData(0xedf5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">13mp</i> — material icon named "13mp". + static const IconData thirteen_mp = IconData(0xe004, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">13mp</i> — material icon named "13mp" (sharp). + static const IconData thirteen_mp_sharp = IconData(0xe704, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">13mp</i> — material icon named "13mp" (round). + static const IconData thirteen_mp_rounded = IconData(0xf4e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">13mp</i> — material icon named "13mp" (outlined). + static const IconData thirteen_mp_outlined = IconData(0xedf6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">14mp</i> — material icon named "14mp". + static const IconData fourteen_mp = IconData(0xe005, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">14mp</i> — material icon named "14mp" (sharp). + static const IconData fourteen_mp_sharp = IconData(0xe705, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">14mp</i> — material icon named "14mp" (round). + static const IconData fourteen_mp_rounded = IconData(0xf4e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">14mp</i> — material icon named "14mp" (outlined). + static const IconData fourteen_mp_outlined = IconData(0xedf7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">15mp</i> — material icon named "15mp". + static const IconData fifteen_mp = IconData(0xe006, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">15mp</i> — material icon named "15mp" (sharp). + static const IconData fifteen_mp_sharp = IconData(0xe706, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">15mp</i> — material icon named "15mp" (round). + static const IconData fifteen_mp_rounded = IconData(0xf4e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">15mp</i> — material icon named "15mp" (outlined). + static const IconData fifteen_mp_outlined = IconData(0xedf8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">16mp</i> — material icon named "16mp". + static const IconData sixteen_mp = IconData(0xe007, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">16mp</i> — material icon named "16mp" (sharp). + static const IconData sixteen_mp_sharp = IconData(0xe707, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">16mp</i> — material icon named "16mp" (round). + static const IconData sixteen_mp_rounded = IconData(0xf4e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">16mp</i> — material icon named "16mp" (outlined). + static const IconData sixteen_mp_outlined = IconData(0xedf9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">17mp</i> — material icon named "17mp". + static const IconData seventeen_mp = IconData(0xe008, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">17mp</i> — material icon named "17mp" (sharp). + static const IconData seventeen_mp_sharp = IconData(0xe708, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">17mp</i> — material icon named "17mp" (round). + static const IconData seventeen_mp_rounded = IconData(0xf4e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">17mp</i> — material icon named "17mp" (outlined). + static const IconData seventeen_mp_outlined = IconData(0xedfa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">18_up_rating</i> — material icon named "18 up rating". + static const IconData eighteen_up_rating = IconData(0xf0784, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">18_up_rating</i> — material icon named "18 up rating" (sharp). + static const IconData eighteen_up_rating_sharp = IconData(0xf072c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">18_up_rating</i> — material icon named "18 up rating" (round). + static const IconData eighteen_up_rating_rounded = IconData(0xf07dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">18_up_rating</i> — material icon named "18 up rating" (outlined). + static const IconData eighteen_up_rating_outlined = IconData(0xf06d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">18mp</i> — material icon named "18mp". + static const IconData eighteen_mp = IconData(0xe009, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">18mp</i> — material icon named "18mp" (sharp). + static const IconData eighteen_mp_sharp = IconData(0xe709, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">18mp</i> — material icon named "18mp" (round). + static const IconData eighteen_mp_rounded = IconData(0xf4e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">18mp</i> — material icon named "18mp" (outlined). + static const IconData eighteen_mp_outlined = IconData(0xedfb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">19mp</i> — material icon named "19mp". + static const IconData nineteen_mp = IconData(0xe00a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">19mp</i> — material icon named "19mp" (sharp). + static const IconData nineteen_mp_sharp = IconData(0xe70a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">19mp</i> — material icon named "19mp" (round). + static const IconData nineteen_mp_rounded = IconData(0xf4e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">19mp</i> — material icon named "19mp" (outlined). + static const IconData nineteen_mp_outlined = IconData(0xedfc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">1k</i> — material icon named "1k". + static const IconData one_k = IconData(0xe00b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">1k</i> — material icon named "1k" (sharp). + static const IconData one_k_sharp = IconData(0xe70c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">1k</i> — material icon named "1k" (round). + static const IconData one_k_rounded = IconData(0xf4eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">1k</i> — material icon named "1k" (outlined). + static const IconData one_k_outlined = IconData(0xedfd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">1k_plus</i> — material icon named "1k plus". + static const IconData one_k_plus = IconData(0xe00c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">1k_plus</i> — material icon named "1k plus" (sharp). + static const IconData one_k_plus_sharp = IconData(0xe70b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">1k_plus</i> — material icon named "1k plus" (round). + static const IconData one_k_plus_rounded = IconData(0xf4ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">1k_plus</i> — material icon named "1k plus" (outlined). + static const IconData one_k_plus_outlined = IconData(0xedfe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">1x_mobiledata</i> — material icon named "1x mobiledata". + static const IconData one_x_mobiledata = IconData(0xe00d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">1x_mobiledata</i> — material icon named "1x mobiledata" (sharp). + static const IconData one_x_mobiledata_sharp = IconData(0xe70d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">1x_mobiledata</i> — material icon named "1x mobiledata" (round). + static const IconData one_x_mobiledata_rounded = IconData(0xf4ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">1x_mobiledata</i> — material icon named "1x mobiledata" (outlined). + static const IconData one_x_mobiledata_outlined = IconData(0xedff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">20mp</i> — material icon named "20mp". + static const IconData twenty_mp = IconData(0xe00e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">20mp</i> — material icon named "20mp" (sharp). + static const IconData twenty_mp_sharp = IconData(0xe70e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">20mp</i> — material icon named "20mp" (round). + static const IconData twenty_mp_rounded = IconData(0xf4ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">20mp</i> — material icon named "20mp" (outlined). + static const IconData twenty_mp_outlined = IconData(0xee00, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">21mp</i> — material icon named "21mp". + static const IconData twenty_one_mp = IconData(0xe00f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">21mp</i> — material icon named "21mp" (sharp). + static const IconData twenty_one_mp_sharp = IconData(0xe70f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">21mp</i> — material icon named "21mp" (round). + static const IconData twenty_one_mp_rounded = IconData(0xf4ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">21mp</i> — material icon named "21mp" (outlined). + static const IconData twenty_one_mp_outlined = IconData(0xee01, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">22mp</i> — material icon named "22mp". + static const IconData twenty_two_mp = IconData(0xe010, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">22mp</i> — material icon named "22mp" (sharp). + static const IconData twenty_two_mp_sharp = IconData(0xe710, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">22mp</i> — material icon named "22mp" (round). + static const IconData twenty_two_mp_rounded = IconData(0xf4ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">22mp</i> — material icon named "22mp" (outlined). + static const IconData twenty_two_mp_outlined = IconData(0xee02, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">23mp</i> — material icon named "23mp". + static const IconData twenty_three_mp = IconData(0xe011, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">23mp</i> — material icon named "23mp" (sharp). + static const IconData twenty_three_mp_sharp = IconData(0xe711, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">23mp</i> — material icon named "23mp" (round). + static const IconData twenty_three_mp_rounded = IconData(0xf4f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">23mp</i> — material icon named "23mp" (outlined). + static const IconData twenty_three_mp_outlined = IconData(0xee03, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">24mp</i> — material icon named "24mp". + static const IconData twenty_four_mp = IconData(0xe012, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">24mp</i> — material icon named "24mp" (sharp). + static const IconData twenty_four_mp_sharp = IconData(0xe712, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">24mp</i> — material icon named "24mp" (round). + static const IconData twenty_four_mp_rounded = IconData(0xf4f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">24mp</i> — material icon named "24mp" (outlined). + static const IconData twenty_four_mp_outlined = IconData(0xee04, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">2k</i> — material icon named "2k". + static const IconData two_k = IconData(0xe013, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">2k</i> — material icon named "2k" (sharp). + static const IconData two_k_sharp = IconData(0xe714, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">2k</i> — material icon named "2k" (round). + static const IconData two_k_rounded = IconData(0xf4f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">2k</i> — material icon named "2k" (outlined). + static const IconData two_k_outlined = IconData(0xee05, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">2k_plus</i> — material icon named "2k plus". + static const IconData two_k_plus = IconData(0xe014, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">2k_plus</i> — material icon named "2k plus" (sharp). + static const IconData two_k_plus_sharp = IconData(0xe713, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">2k_plus</i> — material icon named "2k plus" (round). + static const IconData two_k_plus_rounded = IconData(0xf4f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">2k_plus</i> — material icon named "2k plus" (outlined). + static const IconData two_k_plus_outlined = IconData(0xee06, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">2mp</i> — material icon named "2mp". + static const IconData two_mp = IconData(0xe015, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">2mp</i> — material icon named "2mp" (sharp). + static const IconData two_mp_sharp = IconData(0xe715, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">2mp</i> — material icon named "2mp" (round). + static const IconData two_mp_rounded = IconData(0xf4f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">2mp</i> — material icon named "2mp" (outlined). + static const IconData two_mp_outlined = IconData(0xee07, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">30fps</i> — material icon named "30fps". + static const IconData thirty_fps = IconData(0xe016, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">30fps</i> — material icon named "30fps" (sharp). + static const IconData thirty_fps_sharp = IconData(0xe717, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">30fps</i> — material icon named "30fps" (round). + static const IconData thirty_fps_rounded = IconData(0xf4f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">30fps</i> — material icon named "30fps" (outlined). + static const IconData thirty_fps_outlined = IconData(0xee08, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">30fps_select</i> — material icon named "30fps select". + static const IconData thirty_fps_select = IconData(0xe017, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">30fps_select</i> — material icon named "30fps select" (sharp). + static const IconData thirty_fps_select_sharp = IconData(0xe716, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">30fps_select</i> — material icon named "30fps select" (round). + static const IconData thirty_fps_select_rounded = IconData(0xf4f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">30fps_select</i> — material icon named "30fps select" (outlined). + static const IconData thirty_fps_select_outlined = IconData(0xee09, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">360</i> — material icon named "360". + static const IconData threesixty = IconData(0xe018, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">360</i> — material icon named "360" (sharp). + static const IconData threesixty_sharp = IconData(0xe718, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">360</i> — material icon named "360" (round). + static const IconData threesixty_rounded = IconData(0xf4f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">360</i> — material icon named "360" (outlined). + static const IconData threesixty_outlined = IconData(0xee0a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">3d_rotation</i> — material icon named "3d rotation". + static const IconData threed_rotation = IconData(0xe019, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">3d_rotation</i> — material icon named "3d rotation" (sharp). + static const IconData threed_rotation_sharp = IconData(0xe719, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">3d_rotation</i> — material icon named "3d rotation" (round). + static const IconData threed_rotation_rounded = IconData(0xf4f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">3d_rotation</i> — material icon named "3d rotation" (outlined). + static const IconData threed_rotation_outlined = IconData(0xee0b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">3g_mobiledata</i> — material icon named "3g mobiledata". + static const IconData three_g_mobiledata = IconData(0xe01a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">3g_mobiledata</i> — material icon named "3g mobiledata" (sharp). + static const IconData three_g_mobiledata_sharp = IconData(0xe71a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">3g_mobiledata</i> — material icon named "3g mobiledata" (round). + static const IconData three_g_mobiledata_rounded = IconData(0xf4f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">3g_mobiledata</i> — material icon named "3g mobiledata" (outlined). + static const IconData three_g_mobiledata_outlined = IconData(0xee0c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">3k</i> — material icon named "3k". + static const IconData three_k = IconData(0xe01b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">3k</i> — material icon named "3k" (sharp). + static const IconData three_k_sharp = IconData(0xe71c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">3k</i> — material icon named "3k" (round). + static const IconData three_k_rounded = IconData(0xf4fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">3k</i> — material icon named "3k" (outlined). + static const IconData three_k_outlined = IconData(0xee0d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">3k_plus</i> — material icon named "3k plus". + static const IconData three_k_plus = IconData(0xe01c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">3k_plus</i> — material icon named "3k plus" (sharp). + static const IconData three_k_plus_sharp = IconData(0xe71b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">3k_plus</i> — material icon named "3k plus" (round). + static const IconData three_k_plus_rounded = IconData(0xf4fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">3k_plus</i> — material icon named "3k plus" (outlined). + static const IconData three_k_plus_outlined = IconData(0xee0e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">3mp</i> — material icon named "3mp". + static const IconData three_mp = IconData(0xe01d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">3mp</i> — material icon named "3mp" (sharp). + static const IconData three_mp_sharp = IconData(0xe71d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">3mp</i> — material icon named "3mp" (round). + static const IconData three_mp_rounded = IconData(0xf4fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">3mp</i> — material icon named "3mp" (outlined). + static const IconData three_mp_outlined = IconData(0xee0f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">3p</i> — material icon named "3p". + static const IconData three_p = IconData(0xe01e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">3p</i> — material icon named "3p" (sharp). + static const IconData three_p_sharp = IconData(0xe71e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">3p</i> — material icon named "3p" (round). + static const IconData three_p_rounded = IconData(0xf4fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">3p</i> — material icon named "3p" (outlined). + static const IconData three_p_outlined = IconData(0xee10, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">4g_mobiledata</i> — material icon named "4g mobiledata". + static const IconData four_g_mobiledata = IconData(0xe01f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">4g_mobiledata</i> — material icon named "4g mobiledata" (sharp). + static const IconData four_g_mobiledata_sharp = IconData(0xe71f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">4g_mobiledata</i> — material icon named "4g mobiledata" (round). + static const IconData four_g_mobiledata_rounded = IconData(0xf4fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">4g_mobiledata</i> — material icon named "4g mobiledata" (outlined). + static const IconData four_g_mobiledata_outlined = IconData(0xee11, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">4g_plus_mobiledata</i> — material icon named "4g plus mobiledata". + static const IconData four_g_plus_mobiledata = IconData(0xe020, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">4g_plus_mobiledata</i> — material icon named "4g plus mobiledata" (sharp). + static const IconData four_g_plus_mobiledata_sharp = IconData(0xe720, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">4g_plus_mobiledata</i> — material icon named "4g plus mobiledata" (round). + static const IconData four_g_plus_mobiledata_rounded = IconData(0xf4ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">4g_plus_mobiledata</i> — material icon named "4g plus mobiledata" (outlined). + static const IconData four_g_plus_mobiledata_outlined = IconData(0xee12, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">4k</i> — material icon named "4k". + static const IconData four_k = IconData(0xe021, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">4k</i> — material icon named "4k" (sharp). + static const IconData four_k_sharp = IconData(0xe722, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">4k</i> — material icon named "4k" (round). + static const IconData four_k_rounded = IconData(0xf501, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">4k</i> — material icon named "4k" (outlined). + static const IconData four_k_outlined = IconData(0xee13, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">4k_plus</i> — material icon named "4k plus". + static const IconData four_k_plus = IconData(0xe022, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">4k_plus</i> — material icon named "4k plus" (sharp). + static const IconData four_k_plus_sharp = IconData(0xe721, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">4k_plus</i> — material icon named "4k plus" (round). + static const IconData four_k_plus_rounded = IconData(0xf500, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">4k_plus</i> — material icon named "4k plus" (outlined). + static const IconData four_k_plus_outlined = IconData(0xee14, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">4mp</i> — material icon named "4mp". + static const IconData four_mp = IconData(0xe023, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">4mp</i> — material icon named "4mp" (sharp). + static const IconData four_mp_sharp = IconData(0xe723, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">4mp</i> — material icon named "4mp" (round). + static const IconData four_mp_rounded = IconData(0xf502, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">4mp</i> — material icon named "4mp" (outlined). + static const IconData four_mp_outlined = IconData(0xee15, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">5g</i> — material icon named "5g". + static const IconData five_g = IconData(0xe024, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">5g</i> — material icon named "5g" (sharp). + static const IconData five_g_sharp = IconData(0xe724, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">5g</i> — material icon named "5g" (round). + static const IconData five_g_rounded = IconData(0xf503, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">5g</i> — material icon named "5g" (outlined). + static const IconData five_g_outlined = IconData(0xee16, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">5k</i> — material icon named "5k". + static const IconData five_k = IconData(0xe025, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">5k</i> — material icon named "5k" (sharp). + static const IconData five_k_sharp = IconData(0xe726, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">5k</i> — material icon named "5k" (round). + static const IconData five_k_rounded = IconData(0xf505, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">5k</i> — material icon named "5k" (outlined). + static const IconData five_k_outlined = IconData(0xee17, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">5k_plus</i> — material icon named "5k plus". + static const IconData five_k_plus = IconData(0xe026, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">5k_plus</i> — material icon named "5k plus" (sharp). + static const IconData five_k_plus_sharp = IconData(0xe725, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">5k_plus</i> — material icon named "5k plus" (round). + static const IconData five_k_plus_rounded = IconData(0xf504, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">5k_plus</i> — material icon named "5k plus" (outlined). + static const IconData five_k_plus_outlined = IconData(0xee18, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">5mp</i> — material icon named "5mp". + static const IconData five_mp = IconData(0xe027, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">5mp</i> — material icon named "5mp" (sharp). + static const IconData five_mp_sharp = IconData(0xe727, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">5mp</i> — material icon named "5mp" (round). + static const IconData five_mp_rounded = IconData(0xf506, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">5mp</i> — material icon named "5mp" (outlined). + static const IconData five_mp_outlined = IconData(0xee19, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">60fps</i> — material icon named "60fps". + static const IconData sixty_fps = IconData(0xe028, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">60fps</i> — material icon named "60fps" (sharp). + static const IconData sixty_fps_sharp = IconData(0xe729, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">60fps</i> — material icon named "60fps" (round). + static const IconData sixty_fps_rounded = IconData(0xf507, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">60fps</i> — material icon named "60fps" (outlined). + static const IconData sixty_fps_outlined = IconData(0xee1a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">60fps_select</i> — material icon named "60fps select". + static const IconData sixty_fps_select = IconData(0xe029, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">60fps_select</i> — material icon named "60fps select" (sharp). + static const IconData sixty_fps_select_sharp = IconData(0xe728, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">60fps_select</i> — material icon named "60fps select" (round). + static const IconData sixty_fps_select_rounded = IconData(0xf508, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">60fps_select</i> — material icon named "60fps select" (outlined). + static const IconData sixty_fps_select_outlined = IconData(0xee1b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">6_ft_apart</i> — material icon named "6 ft apart". + static const IconData six_ft_apart = IconData(0xe02a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">6_ft_apart</i> — material icon named "6 ft apart" (sharp). + static const IconData six_ft_apart_sharp = IconData(0xe72a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">6_ft_apart</i> — material icon named "6 ft apart" (round). + static const IconData six_ft_apart_rounded = IconData(0xf509, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">6_ft_apart</i> — material icon named "6 ft apart" (outlined). + static const IconData six_ft_apart_outlined = IconData(0xee1c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">6k</i> — material icon named "6k". + static const IconData six_k = IconData(0xe02b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">6k</i> — material icon named "6k" (sharp). + static const IconData six_k_sharp = IconData(0xe72c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">6k</i> — material icon named "6k" (round). + static const IconData six_k_rounded = IconData(0xf50b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">6k</i> — material icon named "6k" (outlined). + static const IconData six_k_outlined = IconData(0xee1d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">6k_plus</i> — material icon named "6k plus". + static const IconData six_k_plus = IconData(0xe02c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">6k_plus</i> — material icon named "6k plus" (sharp). + static const IconData six_k_plus_sharp = IconData(0xe72b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">6k_plus</i> — material icon named "6k plus" (round). + static const IconData six_k_plus_rounded = IconData(0xf50a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">6k_plus</i> — material icon named "6k plus" (outlined). + static const IconData six_k_plus_outlined = IconData(0xee1e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">6mp</i> — material icon named "6mp". + static const IconData six_mp = IconData(0xe02d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">6mp</i> — material icon named "6mp" (sharp). + static const IconData six_mp_sharp = IconData(0xe72d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">6mp</i> — material icon named "6mp" (round). + static const IconData six_mp_rounded = IconData(0xf50c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">6mp</i> — material icon named "6mp" (outlined). + static const IconData six_mp_outlined = IconData(0xee1f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">7k</i> — material icon named "7k". + static const IconData seven_k = IconData(0xe02e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">7k</i> — material icon named "7k" (sharp). + static const IconData seven_k_sharp = IconData(0xe72f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">7k</i> — material icon named "7k" (round). + static const IconData seven_k_rounded = IconData(0xf50e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">7k</i> — material icon named "7k" (outlined). + static const IconData seven_k_outlined = IconData(0xee20, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">7k_plus</i> — material icon named "7k plus". + static const IconData seven_k_plus = IconData(0xe02f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">7k_plus</i> — material icon named "7k plus" (sharp). + static const IconData seven_k_plus_sharp = IconData(0xe72e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">7k_plus</i> — material icon named "7k plus" (round). + static const IconData seven_k_plus_rounded = IconData(0xf50d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">7k_plus</i> — material icon named "7k plus" (outlined). + static const IconData seven_k_plus_outlined = IconData(0xee21, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">7mp</i> — material icon named "7mp". + static const IconData seven_mp = IconData(0xe030, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">7mp</i> — material icon named "7mp" (sharp). + static const IconData seven_mp_sharp = IconData(0xe730, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">7mp</i> — material icon named "7mp" (round). + static const IconData seven_mp_rounded = IconData(0xf50f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">7mp</i> — material icon named "7mp" (outlined). + static const IconData seven_mp_outlined = IconData(0xee22, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">8k</i> — material icon named "8k". + static const IconData eight_k = IconData(0xe031, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">8k</i> — material icon named "8k" (sharp). + static const IconData eight_k_sharp = IconData(0xe732, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">8k</i> — material icon named "8k" (round). + static const IconData eight_k_rounded = IconData(0xf511, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">8k</i> — material icon named "8k" (outlined). + static const IconData eight_k_outlined = IconData(0xee23, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">8k_plus</i> — material icon named "8k plus". + static const IconData eight_k_plus = IconData(0xe032, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">8k_plus</i> — material icon named "8k plus" (sharp). + static const IconData eight_k_plus_sharp = IconData(0xe731, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">8k_plus</i> — material icon named "8k plus" (round). + static const IconData eight_k_plus_rounded = IconData(0xf510, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">8k_plus</i> — material icon named "8k plus" (outlined). + static const IconData eight_k_plus_outlined = IconData(0xee24, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">8mp</i> — material icon named "8mp". + static const IconData eight_mp = IconData(0xe033, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">8mp</i> — material icon named "8mp" (sharp). + static const IconData eight_mp_sharp = IconData(0xe733, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">8mp</i> — material icon named "8mp" (round). + static const IconData eight_mp_rounded = IconData(0xf512, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">8mp</i> — material icon named "8mp" (outlined). + static const IconData eight_mp_outlined = IconData(0xee25, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">9k</i> — material icon named "9k". + static const IconData nine_k = IconData(0xe034, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">9k</i> — material icon named "9k" (sharp). + static const IconData nine_k_sharp = IconData(0xe735, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">9k</i> — material icon named "9k" (round). + static const IconData nine_k_rounded = IconData(0xf514, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">9k</i> — material icon named "9k" (outlined). + static const IconData nine_k_outlined = IconData(0xee26, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">9k_plus</i> — material icon named "9k plus". + static const IconData nine_k_plus = IconData(0xe035, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">9k_plus</i> — material icon named "9k plus" (sharp). + static const IconData nine_k_plus_sharp = IconData(0xe734, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">9k_plus</i> — material icon named "9k plus" (round). + static const IconData nine_k_plus_rounded = IconData(0xf513, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">9k_plus</i> — material icon named "9k plus" (outlined). + static const IconData nine_k_plus_outlined = IconData(0xee27, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">9mp</i> — material icon named "9mp". + static const IconData nine_mp = IconData(0xe036, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">9mp</i> — material icon named "9mp" (sharp). + static const IconData nine_mp_sharp = IconData(0xe736, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">9mp</i> — material icon named "9mp" (round). + static const IconData nine_mp_rounded = IconData(0xf515, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">9mp</i> — material icon named "9mp" (outlined). + static const IconData nine_mp_outlined = IconData(0xee28, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">abc</i> — material icon named "abc". + static const IconData abc = IconData(0xf04b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">abc</i> — material icon named "abc" (sharp). + static const IconData abc_sharp = IconData(0xf03c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">abc</i> — material icon named "abc" (round). + static const IconData abc_rounded = IconData(0xe4c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">abc</i> — material icon named "abc" (outlined). + static const IconData abc_outlined = IconData(0xf05b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ac_unit</i> — material icon named "ac unit". + static const IconData ac_unit = IconData(0xe037, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ac_unit</i> — material icon named "ac unit" (sharp). + static const IconData ac_unit_sharp = IconData(0xe737, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ac_unit</i> — material icon named "ac unit" (round). + static const IconData ac_unit_rounded = IconData(0xf516, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ac_unit</i> — material icon named "ac unit" (outlined). + static const IconData ac_unit_outlined = IconData(0xee29, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">access_alarm</i> — material icon named "access alarm". + static const IconData access_alarm = IconData(0xe038, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">access_alarm</i> — material icon named "access alarm" (sharp). + static const IconData access_alarm_sharp = IconData(0xe738, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">access_alarm</i> — material icon named "access alarm" (round). + static const IconData access_alarm_rounded = IconData(0xf517, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">access_alarm</i> — material icon named "access alarm" (outlined). + static const IconData access_alarm_outlined = IconData(0xee2a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">access_alarms</i> — material icon named "access alarms". + static const IconData access_alarms = IconData(0xe039, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">access_alarms</i> — material icon named "access alarms" (sharp). + static const IconData access_alarms_sharp = IconData(0xe739, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">access_alarms</i> — material icon named "access alarms" (round). + static const IconData access_alarms_rounded = IconData(0xf518, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">access_alarms</i> — material icon named "access alarms" (outlined). + static const IconData access_alarms_outlined = IconData(0xee2b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">access_time</i> — material icon named "access time". + static const IconData access_time = IconData(0xe03a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">access_time</i> — material icon named "access time" (sharp). + static const IconData access_time_sharp = IconData(0xe73b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">access_time</i> — material icon named "access time" (round). + static const IconData access_time_rounded = IconData(0xf51a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">access_time</i> — material icon named "access time" (outlined). + static const IconData access_time_outlined = IconData(0xee2d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">access_time_filled</i> — material icon named "access time filled". + static const IconData access_time_filled = IconData(0xe03b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">access_time_filled</i> — material icon named "access time filled" (sharp). + static const IconData access_time_filled_sharp = IconData(0xe73a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">access_time_filled</i> — material icon named "access time filled" (round). + static const IconData access_time_filled_rounded = IconData(0xf519, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">access_time_filled</i> — material icon named "access time filled" (outlined). + static const IconData access_time_filled_outlined = IconData(0xee2c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">accessibility</i> — material icon named "accessibility". + static const IconData accessibility = IconData(0xe03c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">accessibility</i> — material icon named "accessibility" (sharp). + static const IconData accessibility_sharp = IconData(0xe73d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">accessibility</i> — material icon named "accessibility" (round). + static const IconData accessibility_rounded = IconData(0xf51c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">accessibility</i> — material icon named "accessibility" (outlined). + static const IconData accessibility_outlined = IconData(0xee2f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">accessibility_new</i> — material icon named "accessibility new". + static const IconData accessibility_new = IconData(0xe03d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">accessibility_new</i> — material icon named "accessibility new" (sharp). + static const IconData accessibility_new_sharp = IconData(0xe73c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">accessibility_new</i> — material icon named "accessibility new" (round). + static const IconData accessibility_new_rounded = IconData(0xf51b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">accessibility_new</i> — material icon named "accessibility new" (outlined). + static const IconData accessibility_new_outlined = IconData(0xee2e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">accessible</i> — material icon named "accessible". + static const IconData accessible = IconData(0xe03e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">accessible</i> — material icon named "accessible" (sharp). + static const IconData accessible_sharp = IconData(0xe73f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">accessible</i> — material icon named "accessible" (round). + static const IconData accessible_rounded = IconData(0xf51e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">accessible</i> — material icon named "accessible" (outlined). + static const IconData accessible_outlined = IconData(0xee31, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">accessible_forward</i> — material icon named "accessible forward". + static const IconData accessible_forward = IconData(0xe03f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">accessible_forward</i> — material icon named "accessible forward" (sharp). + static const IconData accessible_forward_sharp = IconData(0xe73e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">accessible_forward</i> — material icon named "accessible forward" (round). + static const IconData accessible_forward_rounded = IconData(0xf51d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">accessible_forward</i> — material icon named "accessible forward" (outlined). + static const IconData accessible_forward_outlined = IconData(0xee30, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">account_balance</i> — material icon named "account balance". + static const IconData account_balance = IconData(0xe040, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">account_balance</i> — material icon named "account balance" (sharp). + static const IconData account_balance_sharp = IconData(0xe740, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">account_balance</i> — material icon named "account balance" (round). + static const IconData account_balance_rounded = IconData(0xf51f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">account_balance</i> — material icon named "account balance" (outlined). + static const IconData account_balance_outlined = IconData(0xee32, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">account_balance_wallet</i> — material icon named "account balance wallet". + static const IconData account_balance_wallet = IconData(0xe041, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">account_balance_wallet</i> — material icon named "account balance wallet" (sharp). + static const IconData account_balance_wallet_sharp = IconData(0xe741, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">account_balance_wallet</i> — material icon named "account balance wallet" (round). + static const IconData account_balance_wallet_rounded = IconData(0xf520, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">account_balance_wallet</i> — material icon named "account balance wallet" (outlined). + static const IconData account_balance_wallet_outlined = IconData(0xee33, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">account_box</i> — material icon named "account box". + static const IconData account_box = IconData(0xe042, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">account_box</i> — material icon named "account box" (sharp). + static const IconData account_box_sharp = IconData(0xe742, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">account_box</i> — material icon named "account box" (round). + static const IconData account_box_rounded = IconData(0xf521, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">account_box</i> — material icon named "account box" (outlined). + static const IconData account_box_outlined = IconData(0xee34, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">account_circle</i> — material icon named "account circle". + static const IconData account_circle = IconData(0xe043, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">account_circle</i> — material icon named "account circle" (sharp). + static const IconData account_circle_sharp = IconData(0xe743, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">account_circle</i> — material icon named "account circle" (round). + static const IconData account_circle_rounded = IconData(0xf522, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">account_circle</i> — material icon named "account circle" (outlined). + static const IconData account_circle_outlined = IconData(0xee35, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">account_tree</i> — material icon named "account tree". + static const IconData account_tree = IconData(0xe044, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">account_tree</i> — material icon named "account tree" (sharp). + static const IconData account_tree_sharp = IconData(0xe744, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">account_tree</i> — material icon named "account tree" (round). + static const IconData account_tree_rounded = IconData(0xf523, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">account_tree</i> — material icon named "account tree" (outlined). + static const IconData account_tree_outlined = IconData(0xee36, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ad_units</i> — material icon named "ad units". + static const IconData ad_units = IconData(0xe045, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ad_units</i> — material icon named "ad units" (sharp). + static const IconData ad_units_sharp = IconData(0xe745, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ad_units</i> — material icon named "ad units" (round). + static const IconData ad_units_rounded = IconData(0xf524, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ad_units</i> — material icon named "ad units" (outlined). + static const IconData ad_units_outlined = IconData(0xee37, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">adb</i> — material icon named "adb". + static const IconData adb = IconData(0xe046, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">adb</i> — material icon named "adb" (sharp). + static const IconData adb_sharp = IconData(0xe746, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">adb</i> — material icon named "adb" (round). + static const IconData adb_rounded = IconData(0xf525, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">adb</i> — material icon named "adb" (outlined). + static const IconData adb_outlined = IconData(0xee38, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add</i> — material icon named "add". + static const IconData add = IconData(0xe047, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add</i> — material icon named "add" (sharp). + static const IconData add_sharp = IconData(0xe758, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add</i> — material icon named "add" (round). + static const IconData add_rounded = IconData(0xf537, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add</i> — material icon named "add" (outlined). + static const IconData add_outlined = IconData(0xee47, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_a_photo</i> — material icon named "add a photo". + static const IconData add_a_photo = IconData(0xe048, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_a_photo</i> — material icon named "add a photo" (sharp). + static const IconData add_a_photo_sharp = IconData(0xe747, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_a_photo</i> — material icon named "add a photo" (round). + static const IconData add_a_photo_rounded = IconData(0xf526, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_a_photo</i> — material icon named "add a photo" (outlined). + static const IconData add_a_photo_outlined = IconData(0xee39, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_alarm</i> — material icon named "add alarm". + static const IconData add_alarm = IconData(0xe049, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_alarm</i> — material icon named "add alarm" (sharp). + static const IconData add_alarm_sharp = IconData(0xe748, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_alarm</i> — material icon named "add alarm" (round). + static const IconData add_alarm_rounded = IconData(0xf527, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_alarm</i> — material icon named "add alarm" (outlined). + static const IconData add_alarm_outlined = IconData(0xee3a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_alert</i> — material icon named "add alert". + static const IconData add_alert = IconData(0xe04a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_alert</i> — material icon named "add alert" (sharp). + static const IconData add_alert_sharp = IconData(0xe749, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_alert</i> — material icon named "add alert" (round). + static const IconData add_alert_rounded = IconData(0xf528, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_alert</i> — material icon named "add alert" (outlined). + static const IconData add_alert_outlined = IconData(0xee3b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_box</i> — material icon named "add box". + static const IconData add_box = IconData(0xe04b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_box</i> — material icon named "add box" (sharp). + static const IconData add_box_sharp = IconData(0xe74a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_box</i> — material icon named "add box" (round). + static const IconData add_box_rounded = IconData(0xf529, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_box</i> — material icon named "add box" (outlined). + static const IconData add_box_outlined = IconData(0xee3c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_business</i> — material icon named "add business". + static const IconData add_business = IconData(0xe04c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_business</i> — material icon named "add business" (sharp). + static const IconData add_business_sharp = IconData(0xe74b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_business</i> — material icon named "add business" (round). + static const IconData add_business_rounded = IconData(0xf52a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_business</i> — material icon named "add business" (outlined). + static const IconData add_business_outlined = IconData(0xee3d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_call</i> — material icon named "add call". + static const IconData add_call = IconData(0xe04d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_card</i> — material icon named "add card". + static const IconData add_card = IconData(0xf04b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_card</i> — material icon named "add card" (sharp). + static const IconData add_card_sharp = IconData(0xf03c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_card</i> — material icon named "add card" (round). + static const IconData add_card_rounded = IconData(0xf02d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_card</i> — material icon named "add card" (outlined). + static const IconData add_card_outlined = IconData(0xf05b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_chart</i> — material icon named "add chart". + static const IconData add_chart = IconData(0xe04e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_chart</i> — material icon named "add chart" (sharp). + static const IconData add_chart_sharp = IconData(0xe74c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_chart</i> — material icon named "add chart" (round). + static const IconData add_chart_rounded = IconData(0xf52b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_chart</i> — material icon named "add chart" (outlined). + static const IconData add_chart_outlined = IconData(0xee3e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_circle</i> — material icon named "add circle". + static const IconData add_circle = IconData(0xe04f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_circle</i> — material icon named "add circle" (sharp). + static const IconData add_circle_sharp = IconData(0xe74e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_circle</i> — material icon named "add circle" (round). + static const IconData add_circle_rounded = IconData(0xf52d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_circle</i> — material icon named "add circle" (outlined). + static const IconData add_circle_outlined = IconData(0xee40, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_circle_outline</i> — material icon named "add circle outline". + static const IconData add_circle_outline = IconData(0xe050, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_circle_outline</i> — material icon named "add circle outline" (sharp). + static const IconData add_circle_outline_sharp = IconData(0xe74d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_circle_outline</i> — material icon named "add circle outline" (round). + static const IconData add_circle_outline_rounded = IconData(0xf52c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_circle_outline</i> — material icon named "add circle outline" (outlined). + static const IconData add_circle_outline_outlined = IconData(0xee3f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_comment</i> — material icon named "add comment". + static const IconData add_comment = IconData(0xe051, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_comment</i> — material icon named "add comment" (sharp). + static const IconData add_comment_sharp = IconData(0xe74f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_comment</i> — material icon named "add comment" (round). + static const IconData add_comment_rounded = IconData(0xf52e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_comment</i> — material icon named "add comment" (outlined). + static const IconData add_comment_outlined = IconData(0xee41, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_home</i> — material icon named "add home". + static const IconData add_home = IconData(0xf0785, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_home</i> — material icon named "add home" (sharp). + static const IconData add_home_sharp = IconData(0xf072d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_home</i> — material icon named "add home" (round). + static const IconData add_home_rounded = IconData(0xf07dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_home</i> — material icon named "add home" (outlined). + static const IconData add_home_outlined = IconData(0xf06d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_home_work</i> — material icon named "add home work". + static const IconData add_home_work = IconData(0xf0786, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_home_work</i> — material icon named "add home work" (sharp). + static const IconData add_home_work_sharp = IconData(0xf072e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_home_work</i> — material icon named "add home work" (round). + static const IconData add_home_work_rounded = IconData(0xf07de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_home_work</i> — material icon named "add home work" (outlined). + static const IconData add_home_work_outlined = IconData(0xf06d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_ic_call</i> — material icon named "add ic call". + static const IconData add_ic_call = IconData(0xe052, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_ic_call</i> — material icon named "add ic call" (sharp). + static const IconData add_ic_call_sharp = IconData(0xe750, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_ic_call</i> — material icon named "add ic call" (round). + static const IconData add_ic_call_rounded = IconData(0xf52f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_ic_call</i> — material icon named "add ic call" (outlined). + static const IconData add_ic_call_outlined = IconData(0xee42, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_link</i> — material icon named "add link". + static const IconData add_link = IconData(0xe053, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_link</i> — material icon named "add link" (sharp). + static const IconData add_link_sharp = IconData(0xe751, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_link</i> — material icon named "add link" (round). + static const IconData add_link_rounded = IconData(0xf530, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_link</i> — material icon named "add link" (outlined). + static const IconData add_link_outlined = IconData(0xee43, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_location</i> — material icon named "add location". + static const IconData add_location = IconData(0xe054, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_location</i> — material icon named "add location" (sharp). + static const IconData add_location_sharp = IconData(0xe753, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_location</i> — material icon named "add location" (round). + static const IconData add_location_rounded = IconData(0xf532, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_location</i> — material icon named "add location" (outlined). + static const IconData add_location_outlined = IconData(0xee45, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_location_alt</i> — material icon named "add location alt". + static const IconData add_location_alt = IconData(0xe055, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_location_alt</i> — material icon named "add location alt" (sharp). + static const IconData add_location_alt_sharp = IconData(0xe752, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_location_alt</i> — material icon named "add location alt" (round). + static const IconData add_location_alt_rounded = IconData(0xf531, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_location_alt</i> — material icon named "add location alt" (outlined). + static const IconData add_location_alt_outlined = IconData(0xee44, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_moderator</i> — material icon named "add moderator". + static const IconData add_moderator = IconData(0xe056, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_moderator</i> — material icon named "add moderator" (sharp). + static const IconData add_moderator_sharp = IconData(0xe754, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_moderator</i> — material icon named "add moderator" (round). + static const IconData add_moderator_rounded = IconData(0xf533, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_moderator</i> — material icon named "add moderator" (outlined). + static const IconData add_moderator_outlined = IconData(0xee46, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_photo_alternate</i> — material icon named "add photo alternate". + static const IconData add_photo_alternate = IconData(0xe057, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_photo_alternate</i> — material icon named "add photo alternate" (sharp). + static const IconData add_photo_alternate_sharp = IconData(0xe755, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_photo_alternate</i> — material icon named "add photo alternate" (round). + static const IconData add_photo_alternate_rounded = IconData(0xf534, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_photo_alternate</i> — material icon named "add photo alternate" (outlined). + static const IconData add_photo_alternate_outlined = IconData(0xee48, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_reaction</i> — material icon named "add reaction". + static const IconData add_reaction = IconData(0xe058, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_reaction</i> — material icon named "add reaction" (sharp). + static const IconData add_reaction_sharp = IconData(0xe756, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_reaction</i> — material icon named "add reaction" (round). + static const IconData add_reaction_rounded = IconData(0xf535, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_reaction</i> — material icon named "add reaction" (outlined). + static const IconData add_reaction_outlined = IconData(0xee49, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_road</i> — material icon named "add road". + static const IconData add_road = IconData(0xe059, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_road</i> — material icon named "add road" (sharp). + static const IconData add_road_sharp = IconData(0xe757, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_road</i> — material icon named "add road" (round). + static const IconData add_road_rounded = IconData(0xf536, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_road</i> — material icon named "add road" (outlined). + static const IconData add_road_outlined = IconData(0xee4a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_shopping_cart</i> — material icon named "add shopping cart". + static const IconData add_shopping_cart = IconData(0xe05a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_shopping_cart</i> — material icon named "add shopping cart" (sharp). + static const IconData add_shopping_cart_sharp = IconData(0xe759, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_shopping_cart</i> — material icon named "add shopping cart" (round). + static const IconData add_shopping_cart_rounded = IconData(0xf538, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_shopping_cart</i> — material icon named "add shopping cart" (outlined). + static const IconData add_shopping_cart_outlined = IconData(0xee4b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_task</i> — material icon named "add task". + static const IconData add_task = IconData(0xe05b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_task</i> — material icon named "add task" (sharp). + static const IconData add_task_sharp = IconData(0xe75a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_task</i> — material icon named "add task" (round). + static const IconData add_task_rounded = IconData(0xf539, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_task</i> — material icon named "add task" (outlined). + static const IconData add_task_outlined = IconData(0xee4c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_to_drive</i> — material icon named "add to drive". + static const IconData add_to_drive = IconData(0xe05c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_to_drive</i> — material icon named "add to drive" (sharp). + static const IconData add_to_drive_sharp = IconData(0xe75b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_to_drive</i> — material icon named "add to drive" (round). + static const IconData add_to_drive_rounded = IconData(0xf53a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_to_drive</i> — material icon named "add to drive" (outlined). + static const IconData add_to_drive_outlined = IconData(0xee4d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_to_home_screen</i> — material icon named "add to home screen". + static const IconData add_to_home_screen = IconData(0xe05d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_to_home_screen</i> — material icon named "add to home screen" (sharp). + static const IconData add_to_home_screen_sharp = IconData(0xe75c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_to_home_screen</i> — material icon named "add to home screen" (round). + static const IconData add_to_home_screen_rounded = IconData(0xf53b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_to_home_screen</i> — material icon named "add to home screen" (outlined). + static const IconData add_to_home_screen_outlined = IconData(0xee4e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_to_photos</i> — material icon named "add to photos". + static const IconData add_to_photos = IconData(0xe05e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_to_photos</i> — material icon named "add to photos" (sharp). + static const IconData add_to_photos_sharp = IconData(0xe75d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_to_photos</i> — material icon named "add to photos" (round). + static const IconData add_to_photos_rounded = IconData(0xf53c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_to_photos</i> — material icon named "add to photos" (outlined). + static const IconData add_to_photos_outlined = IconData(0xee4f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">add_to_queue</i> — material icon named "add to queue". + static const IconData add_to_queue = IconData(0xe05f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">add_to_queue</i> — material icon named "add to queue" (sharp). + static const IconData add_to_queue_sharp = IconData(0xe75e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">add_to_queue</i> — material icon named "add to queue" (round). + static const IconData add_to_queue_rounded = IconData(0xf53d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">add_to_queue</i> — material icon named "add to queue" (outlined). + static const IconData add_to_queue_outlined = IconData(0xee50, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">addchart</i> — material icon named "addchart". + static const IconData addchart = IconData(0xe060, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">addchart</i> — material icon named "addchart" (sharp). + static const IconData addchart_sharp = IconData(0xe75f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">addchart</i> — material icon named "addchart" (round). + static const IconData addchart_rounded = IconData(0xf53e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">addchart</i> — material icon named "addchart" (outlined). + static const IconData addchart_outlined = IconData(0xee51, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">adf_scanner</i> — material icon named "adf scanner". + static const IconData adf_scanner = IconData(0xf04b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">adf_scanner</i> — material icon named "adf scanner" (sharp). + static const IconData adf_scanner_sharp = IconData(0xf03c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">adf_scanner</i> — material icon named "adf scanner" (round). + static const IconData adf_scanner_rounded = IconData(0xf02d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">adf_scanner</i> — material icon named "adf scanner" (outlined). + static const IconData adf_scanner_outlined = IconData(0xf05b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">adjust</i> — material icon named "adjust". + static const IconData adjust = IconData(0xe061, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">adjust</i> — material icon named "adjust" (sharp). + static const IconData adjust_sharp = IconData(0xe760, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">adjust</i> — material icon named "adjust" (round). + static const IconData adjust_rounded = IconData(0xf53f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">adjust</i> — material icon named "adjust" (outlined). + static const IconData adjust_outlined = IconData(0xee52, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">admin_panel_settings</i> — material icon named "admin panel settings". + static const IconData admin_panel_settings = IconData(0xe062, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">admin_panel_settings</i> — material icon named "admin panel settings" (sharp). + static const IconData admin_panel_settings_sharp = IconData(0xe761, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">admin_panel_settings</i> — material icon named "admin panel settings" (round). + static const IconData admin_panel_settings_rounded = IconData(0xf540, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">admin_panel_settings</i> — material icon named "admin panel settings" (outlined). + static const IconData admin_panel_settings_outlined = IconData(0xee53, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">adobe</i> — material icon named "adobe". + static const IconData adobe = IconData(0xf04b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">adobe</i> — material icon named "adobe" (sharp). + static const IconData adobe_sharp = IconData(0xf03c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">adobe</i> — material icon named "adobe" (round). + static const IconData adobe_rounded = IconData(0xf02d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">adobe</i> — material icon named "adobe" (outlined). + static const IconData adobe_outlined = IconData(0xf05b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ads_click</i> — material icon named "ads click". + static const IconData ads_click = IconData(0xf04ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ads_click</i> — material icon named "ads click" (sharp). + static const IconData ads_click_sharp = IconData(0xf03c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ads_click</i> — material icon named "ads click" (round). + static const IconData ads_click_rounded = IconData(0xf02d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ads_click</i> — material icon named "ads click" (outlined). + static const IconData ads_click_outlined = IconData(0xf05b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">agriculture</i> — material icon named "agriculture". + static const IconData agriculture = IconData(0xe063, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">agriculture</i> — material icon named "agriculture" (sharp). + static const IconData agriculture_sharp = IconData(0xe762, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">agriculture</i> — material icon named "agriculture" (round). + static const IconData agriculture_rounded = IconData(0xf541, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">agriculture</i> — material icon named "agriculture" (outlined). + static const IconData agriculture_outlined = IconData(0xee54, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">air</i> — material icon named "air". + static const IconData air = IconData(0xe064, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">air</i> — material icon named "air" (sharp). + static const IconData air_sharp = IconData(0xe763, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">air</i> — material icon named "air" (round). + static const IconData air_rounded = IconData(0xf542, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">air</i> — material icon named "air" (outlined). + static const IconData air_outlined = IconData(0xee55, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airline_seat_flat</i> — material icon named "airline seat flat". + static const IconData airline_seat_flat = IconData(0xe065, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airline_seat_flat</i> — material icon named "airline seat flat" (sharp). + static const IconData airline_seat_flat_sharp = IconData(0xe765, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airline_seat_flat</i> — material icon named "airline seat flat" (round). + static const IconData airline_seat_flat_rounded = IconData(0xf544, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airline_seat_flat</i> — material icon named "airline seat flat" (outlined). + static const IconData airline_seat_flat_outlined = IconData(0xee57, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airline_seat_flat_angled</i> — material icon named "airline seat flat angled". + static const IconData airline_seat_flat_angled = IconData(0xe066, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airline_seat_flat_angled</i> — material icon named "airline seat flat angled" (sharp). + static const IconData airline_seat_flat_angled_sharp = IconData(0xe764, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airline_seat_flat_angled</i> — material icon named "airline seat flat angled" (round). + static const IconData airline_seat_flat_angled_rounded = IconData(0xf543, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airline_seat_flat_angled</i> — material icon named "airline seat flat angled" (outlined). + static const IconData airline_seat_flat_angled_outlined = IconData(0xee56, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airline_seat_individual_suite</i> — material icon named "airline seat individual suite". + static const IconData airline_seat_individual_suite = IconData(0xe067, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airline_seat_individual_suite</i> — material icon named "airline seat individual suite" (sharp). + static const IconData airline_seat_individual_suite_sharp = IconData(0xe766, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airline_seat_individual_suite</i> — material icon named "airline seat individual suite" (round). + static const IconData airline_seat_individual_suite_rounded = IconData(0xf545, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airline_seat_individual_suite</i> — material icon named "airline seat individual suite" (outlined). + static const IconData airline_seat_individual_suite_outlined = IconData(0xee58, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airline_seat_legroom_extra</i> — material icon named "airline seat legroom extra". + static const IconData airline_seat_legroom_extra = IconData(0xe068, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airline_seat_legroom_extra</i> — material icon named "airline seat legroom extra" (sharp). + static const IconData airline_seat_legroom_extra_sharp = IconData(0xe767, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airline_seat_legroom_extra</i> — material icon named "airline seat legroom extra" (round). + static const IconData airline_seat_legroom_extra_rounded = IconData(0xf546, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airline_seat_legroom_extra</i> — material icon named "airline seat legroom extra" (outlined). + static const IconData airline_seat_legroom_extra_outlined = IconData(0xee59, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airline_seat_legroom_normal</i> — material icon named "airline seat legroom normal". + static const IconData airline_seat_legroom_normal = IconData(0xe069, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airline_seat_legroom_normal</i> — material icon named "airline seat legroom normal" (sharp). + static const IconData airline_seat_legroom_normal_sharp = IconData(0xe768, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airline_seat_legroom_normal</i> — material icon named "airline seat legroom normal" (round). + static const IconData airline_seat_legroom_normal_rounded = IconData(0xf547, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airline_seat_legroom_normal</i> — material icon named "airline seat legroom normal" (outlined). + static const IconData airline_seat_legroom_normal_outlined = IconData(0xee5a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airline_seat_legroom_reduced</i> — material icon named "airline seat legroom reduced". + static const IconData airline_seat_legroom_reduced = IconData(0xe06a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airline_seat_legroom_reduced</i> — material icon named "airline seat legroom reduced" (sharp). + static const IconData airline_seat_legroom_reduced_sharp = IconData(0xe769, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airline_seat_legroom_reduced</i> — material icon named "airline seat legroom reduced" (round). + static const IconData airline_seat_legroom_reduced_rounded = IconData(0xf548, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airline_seat_legroom_reduced</i> — material icon named "airline seat legroom reduced" (outlined). + static const IconData airline_seat_legroom_reduced_outlined = IconData(0xee5b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airline_seat_recline_extra</i> — material icon named "airline seat recline extra". + static const IconData airline_seat_recline_extra = IconData(0xe06b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airline_seat_recline_extra</i> — material icon named "airline seat recline extra" (sharp). + static const IconData airline_seat_recline_extra_sharp = IconData(0xe76a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airline_seat_recline_extra</i> — material icon named "airline seat recline extra" (round). + static const IconData airline_seat_recline_extra_rounded = IconData(0xf549, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airline_seat_recline_extra</i> — material icon named "airline seat recline extra" (outlined). + static const IconData airline_seat_recline_extra_outlined = IconData(0xee5c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airline_seat_recline_normal</i> — material icon named "airline seat recline normal". + static const IconData airline_seat_recline_normal = IconData(0xe06c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airline_seat_recline_normal</i> — material icon named "airline seat recline normal" (sharp). + static const IconData airline_seat_recline_normal_sharp = IconData(0xe76b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airline_seat_recline_normal</i> — material icon named "airline seat recline normal" (round). + static const IconData airline_seat_recline_normal_rounded = IconData(0xf54a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airline_seat_recline_normal</i> — material icon named "airline seat recline normal" (outlined). + static const IconData airline_seat_recline_normal_outlined = IconData(0xee5d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airline_stops</i> — material icon named "airline stops". + static const IconData airline_stops = IconData(0xf04bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airline_stops</i> — material icon named "airline stops" (sharp). + static const IconData airline_stops_sharp = IconData(0xf03c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airline_stops</i> — material icon named "airline stops" (round). + static const IconData airline_stops_rounded = IconData(0xf02d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airline_stops</i> — material icon named "airline stops" (outlined). + static const IconData airline_stops_outlined = IconData(0xf05b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airlines</i> — material icon named "airlines". + static const IconData airlines = IconData(0xf04bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airlines</i> — material icon named "airlines" (sharp). + static const IconData airlines_sharp = IconData(0xf03c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airlines</i> — material icon named "airlines" (round). + static const IconData airlines_rounded = IconData(0xf02d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airlines</i> — material icon named "airlines" (outlined). + static const IconData airlines_outlined = IconData(0xf05b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airplane_ticket</i> — material icon named "airplane ticket". + static const IconData airplane_ticket = IconData(0xe06d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airplane_ticket</i> — material icon named "airplane ticket" (sharp). + static const IconData airplane_ticket_sharp = IconData(0xe76c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airplane_ticket</i> — material icon named "airplane ticket" (round). + static const IconData airplane_ticket_rounded = IconData(0xf54b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airplane_ticket</i> — material icon named "airplane ticket" (outlined). + static const IconData airplane_ticket_outlined = IconData(0xee5e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airplanemode_active</i> — material icon named "airplanemode active". + static const IconData airplanemode_active = IconData(0xe06e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airplanemode_active</i> — material icon named "airplanemode active" (sharp). + static const IconData airplanemode_active_sharp = IconData(0xe76d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airplanemode_active</i> — material icon named "airplanemode active" (round). + static const IconData airplanemode_active_rounded = IconData(0xf54c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airplanemode_active</i> — material icon named "airplanemode active" (outlined). + static const IconData airplanemode_active_outlined = IconData(0xee5f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airplanemode_inactive</i> — material icon named "airplanemode inactive". + static const IconData airplanemode_inactive = IconData(0xe06f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airplanemode_inactive</i> — material icon named "airplanemode inactive" (sharp). + static const IconData airplanemode_inactive_sharp = IconData(0xe76e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airplanemode_inactive</i> — material icon named "airplanemode inactive" (round). + static const IconData airplanemode_inactive_rounded = IconData(0xf54d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airplanemode_inactive</i> — material icon named "airplanemode inactive" (outlined). + static const IconData airplanemode_inactive_outlined = IconData(0xee60, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airplanemode_off</i> — material icon named "airplanemode off". + static const IconData airplanemode_off = IconData(0xe06f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airplanemode_off</i> — material icon named "airplanemode off" (sharp). + static const IconData airplanemode_off_sharp = IconData(0xe76e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airplanemode_off</i> — material icon named "airplanemode off" (round). + static const IconData airplanemode_off_rounded = IconData(0xf54d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airplanemode_off</i> — material icon named "airplanemode off" (outlined). + static const IconData airplanemode_off_outlined = IconData(0xee60, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airplanemode_on</i> — material icon named "airplanemode on". + static const IconData airplanemode_on = IconData(0xe06e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airplanemode_on</i> — material icon named "airplanemode on" (sharp). + static const IconData airplanemode_on_sharp = IconData(0xe76d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airplanemode_on</i> — material icon named "airplanemode on" (round). + static const IconData airplanemode_on_rounded = IconData(0xf54c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airplanemode_on</i> — material icon named "airplanemode on" (outlined). + static const IconData airplanemode_on_outlined = IconData(0xee5f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airplay</i> — material icon named "airplay". + static const IconData airplay = IconData(0xe070, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airplay</i> — material icon named "airplay" (sharp). + static const IconData airplay_sharp = IconData(0xe76f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airplay</i> — material icon named "airplay" (round). + static const IconData airplay_rounded = IconData(0xf54e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airplay</i> — material icon named "airplay" (outlined). + static const IconData airplay_outlined = IconData(0xee61, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">airport_shuttle</i> — material icon named "airport shuttle". + static const IconData airport_shuttle = IconData(0xe071, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">airport_shuttle</i> — material icon named "airport shuttle" (sharp). + static const IconData airport_shuttle_sharp = IconData(0xe770, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">airport_shuttle</i> — material icon named "airport shuttle" (round). + static const IconData airport_shuttle_rounded = IconData(0xf54f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">airport_shuttle</i> — material icon named "airport shuttle" (outlined). + static const IconData airport_shuttle_outlined = IconData(0xee62, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">alarm</i> — material icon named "alarm". + static const IconData alarm = IconData(0xe072, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">alarm</i> — material icon named "alarm" (sharp). + static const IconData alarm_sharp = IconData(0xe774, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">alarm</i> — material icon named "alarm" (round). + static const IconData alarm_rounded = IconData(0xf553, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">alarm</i> — material icon named "alarm" (outlined). + static const IconData alarm_outlined = IconData(0xee66, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">alarm_add</i> — material icon named "alarm add". + static const IconData alarm_add = IconData(0xe073, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">alarm_add</i> — material icon named "alarm add" (sharp). + static const IconData alarm_add_sharp = IconData(0xe771, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">alarm_add</i> — material icon named "alarm add" (round). + static const IconData alarm_add_rounded = IconData(0xf550, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">alarm_add</i> — material icon named "alarm add" (outlined). + static const IconData alarm_add_outlined = IconData(0xee63, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">alarm_off</i> — material icon named "alarm off". + static const IconData alarm_off = IconData(0xe074, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">alarm_off</i> — material icon named "alarm off" (sharp). + static const IconData alarm_off_sharp = IconData(0xe772, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">alarm_off</i> — material icon named "alarm off" (round). + static const IconData alarm_off_rounded = IconData(0xf551, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">alarm_off</i> — material icon named "alarm off" (outlined). + static const IconData alarm_off_outlined = IconData(0xee64, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">alarm_on</i> — material icon named "alarm on". + static const IconData alarm_on = IconData(0xe075, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">alarm_on</i> — material icon named "alarm on" (sharp). + static const IconData alarm_on_sharp = IconData(0xe773, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">alarm_on</i> — material icon named "alarm on" (round). + static const IconData alarm_on_rounded = IconData(0xf552, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">alarm_on</i> — material icon named "alarm on" (outlined). + static const IconData alarm_on_outlined = IconData(0xee65, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">album</i> — material icon named "album". + static const IconData album = IconData(0xe076, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">album</i> — material icon named "album" (sharp). + static const IconData album_sharp = IconData(0xe775, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">album</i> — material icon named "album" (round). + static const IconData album_rounded = IconData(0xf554, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">album</i> — material icon named "album" (outlined). + static const IconData album_outlined = IconData(0xee67, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">align_horizontal_center</i> — material icon named "align horizontal center". + static const IconData align_horizontal_center = IconData(0xe077, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">align_horizontal_center</i> — material icon named "align horizontal center" (sharp). + static const IconData align_horizontal_center_sharp = IconData(0xe776, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">align_horizontal_center</i> — material icon named "align horizontal center" (round). + static const IconData align_horizontal_center_rounded = IconData(0xf555, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">align_horizontal_center</i> — material icon named "align horizontal center" (outlined). + static const IconData align_horizontal_center_outlined = IconData(0xee68, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">align_horizontal_left</i> — material icon named "align horizontal left". + static const IconData align_horizontal_left = IconData(0xe078, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">align_horizontal_left</i> — material icon named "align horizontal left" (sharp). + static const IconData align_horizontal_left_sharp = IconData(0xe777, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">align_horizontal_left</i> — material icon named "align horizontal left" (round). + static const IconData align_horizontal_left_rounded = IconData(0xf556, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">align_horizontal_left</i> — material icon named "align horizontal left" (outlined). + static const IconData align_horizontal_left_outlined = IconData(0xee69, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">align_horizontal_right</i> — material icon named "align horizontal right". + static const IconData align_horizontal_right = IconData(0xe079, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">align_horizontal_right</i> — material icon named "align horizontal right" (sharp). + static const IconData align_horizontal_right_sharp = IconData(0xe778, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">align_horizontal_right</i> — material icon named "align horizontal right" (round). + static const IconData align_horizontal_right_rounded = IconData(0xf557, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">align_horizontal_right</i> — material icon named "align horizontal right" (outlined). + static const IconData align_horizontal_right_outlined = IconData(0xee6a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">align_vertical_bottom</i> — material icon named "align vertical bottom". + static const IconData align_vertical_bottom = IconData(0xe07a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">align_vertical_bottom</i> — material icon named "align vertical bottom" (sharp). + static const IconData align_vertical_bottom_sharp = IconData(0xe779, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">align_vertical_bottom</i> — material icon named "align vertical bottom" (round). + static const IconData align_vertical_bottom_rounded = IconData(0xf558, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">align_vertical_bottom</i> — material icon named "align vertical bottom" (outlined). + static const IconData align_vertical_bottom_outlined = IconData(0xee6b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">align_vertical_center</i> — material icon named "align vertical center". + static const IconData align_vertical_center = IconData(0xe07b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">align_vertical_center</i> — material icon named "align vertical center" (sharp). + static const IconData align_vertical_center_sharp = IconData(0xe77a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">align_vertical_center</i> — material icon named "align vertical center" (round). + static const IconData align_vertical_center_rounded = IconData(0xf559, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">align_vertical_center</i> — material icon named "align vertical center" (outlined). + static const IconData align_vertical_center_outlined = IconData(0xee6c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">align_vertical_top</i> — material icon named "align vertical top". + static const IconData align_vertical_top = IconData(0xe07c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">align_vertical_top</i> — material icon named "align vertical top" (sharp). + static const IconData align_vertical_top_sharp = IconData(0xe77b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">align_vertical_top</i> — material icon named "align vertical top" (round). + static const IconData align_vertical_top_rounded = IconData(0xf55a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">align_vertical_top</i> — material icon named "align vertical top" (outlined). + static const IconData align_vertical_top_outlined = IconData(0xee6d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">all_inbox</i> — material icon named "all inbox". + static const IconData all_inbox = IconData(0xe07d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">all_inbox</i> — material icon named "all inbox" (sharp). + static const IconData all_inbox_sharp = IconData(0xe77c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">all_inbox</i> — material icon named "all inbox" (round). + static const IconData all_inbox_rounded = IconData(0xf55b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">all_inbox</i> — material icon named "all inbox" (outlined). + static const IconData all_inbox_outlined = IconData(0xee6e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">all_inclusive</i> — material icon named "all inclusive". + static const IconData all_inclusive = IconData(0xe07e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">all_inclusive</i> — material icon named "all inclusive" (sharp). + static const IconData all_inclusive_sharp = IconData(0xe77d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">all_inclusive</i> — material icon named "all inclusive" (round). + static const IconData all_inclusive_rounded = IconData(0xf55c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">all_inclusive</i> — material icon named "all inclusive" (outlined). + static const IconData all_inclusive_outlined = IconData(0xee6f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">all_out</i> — material icon named "all out". + static const IconData all_out = IconData(0xe07f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">all_out</i> — material icon named "all out" (sharp). + static const IconData all_out_sharp = IconData(0xe77e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">all_out</i> — material icon named "all out" (round). + static const IconData all_out_rounded = IconData(0xf55d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">all_out</i> — material icon named "all out" (outlined). + static const IconData all_out_outlined = IconData(0xee70, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">alt_route</i> — material icon named "alt route". + static const IconData alt_route = IconData(0xe080, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">alt_route</i> — material icon named "alt route" (sharp). + static const IconData alt_route_sharp = IconData(0xe77f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">alt_route</i> — material icon named "alt route" (round). + static const IconData alt_route_rounded = IconData(0xf55e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">alt_route</i> — material icon named "alt route" (outlined). + static const IconData alt_route_outlined = IconData(0xee71, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">alternate_email</i> — material icon named "alternate email". + static const IconData alternate_email = IconData(0xe081, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">alternate_email</i> — material icon named "alternate email" (sharp). + static const IconData alternate_email_sharp = IconData(0xe780, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">alternate_email</i> — material icon named "alternate email" (round). + static const IconData alternate_email_rounded = IconData(0xf55f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">alternate_email</i> — material icon named "alternate email" (outlined). + static const IconData alternate_email_outlined = IconData(0xee72, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">amp_stories</i> — material icon named "amp stories". + static const IconData amp_stories = IconData(0xe082, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">amp_stories</i> — material icon named "amp stories" (sharp). + static const IconData amp_stories_sharp = IconData(0xe781, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">amp_stories</i> — material icon named "amp stories" (round). + static const IconData amp_stories_rounded = IconData(0xf560, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">amp_stories</i> — material icon named "amp stories" (outlined). + static const IconData amp_stories_outlined = IconData(0xee73, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">analytics</i> — material icon named "analytics". + static const IconData analytics = IconData(0xe083, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">analytics</i> — material icon named "analytics" (sharp). + static const IconData analytics_sharp = IconData(0xe782, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">analytics</i> — material icon named "analytics" (round). + static const IconData analytics_rounded = IconData(0xf561, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">analytics</i> — material icon named "analytics" (outlined). + static const IconData analytics_outlined = IconData(0xee74, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">anchor</i> — material icon named "anchor". + static const IconData anchor = IconData(0xe084, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">anchor</i> — material icon named "anchor" (sharp). + static const IconData anchor_sharp = IconData(0xe783, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">anchor</i> — material icon named "anchor" (round). + static const IconData anchor_rounded = IconData(0xf562, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">anchor</i> — material icon named "anchor" (outlined). + static const IconData anchor_outlined = IconData(0xee75, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">android</i> — material icon named "android". + static const IconData android = IconData(0xe085, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">android</i> — material icon named "android" (sharp). + static const IconData android_sharp = IconData(0xe784, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">android</i> — material icon named "android" (round). + static const IconData android_rounded = IconData(0xf563, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">android</i> — material icon named "android" (outlined). + static const IconData android_outlined = IconData(0xee76, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">animation</i> — material icon named "animation". + static const IconData animation = IconData(0xe086, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">animation</i> — material icon named "animation" (sharp). + static const IconData animation_sharp = IconData(0xe785, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">animation</i> — material icon named "animation" (round). + static const IconData animation_rounded = IconData(0xf564, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">animation</i> — material icon named "animation" (outlined). + static const IconData animation_outlined = IconData(0xee77, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">announcement</i> — material icon named "announcement". + static const IconData announcement = IconData(0xe087, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">announcement</i> — material icon named "announcement" (sharp). + static const IconData announcement_sharp = IconData(0xe786, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">announcement</i> — material icon named "announcement" (round). + static const IconData announcement_rounded = IconData(0xf565, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">announcement</i> — material icon named "announcement" (outlined). + static const IconData announcement_outlined = IconData(0xee78, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">aod</i> — material icon named "aod". + static const IconData aod = IconData(0xe088, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">aod</i> — material icon named "aod" (sharp). + static const IconData aod_sharp = IconData(0xe787, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">aod</i> — material icon named "aod" (round). + static const IconData aod_rounded = IconData(0xf566, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">aod</i> — material icon named "aod" (outlined). + static const IconData aod_outlined = IconData(0xee79, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">apartment</i> — material icon named "apartment". + static const IconData apartment = IconData(0xe089, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">apartment</i> — material icon named "apartment" (sharp). + static const IconData apartment_sharp = IconData(0xe788, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">apartment</i> — material icon named "apartment" (round). + static const IconData apartment_rounded = IconData(0xf567, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">apartment</i> — material icon named "apartment" (outlined). + static const IconData apartment_outlined = IconData(0xee7a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">api</i> — material icon named "api". + static const IconData api = IconData(0xe08a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">api</i> — material icon named "api" (sharp). + static const IconData api_sharp = IconData(0xe789, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">api</i> — material icon named "api" (round). + static const IconData api_rounded = IconData(0xf568, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">api</i> — material icon named "api" (outlined). + static const IconData api_outlined = IconData(0xee7b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">app_blocking</i> — material icon named "app blocking". + static const IconData app_blocking = IconData(0xe08b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">app_blocking</i> — material icon named "app blocking" (sharp). + static const IconData app_blocking_sharp = IconData(0xe78a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">app_blocking</i> — material icon named "app blocking" (round). + static const IconData app_blocking_rounded = IconData(0xf569, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">app_blocking</i> — material icon named "app blocking" (outlined). + static const IconData app_blocking_outlined = IconData(0xee7c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">app_registration</i> — material icon named "app registration". + static const IconData app_registration = IconData(0xe08c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">app_registration</i> — material icon named "app registration" (sharp). + static const IconData app_registration_sharp = IconData(0xe78b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">app_registration</i> — material icon named "app registration" (round). + static const IconData app_registration_rounded = IconData(0xf56a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">app_registration</i> — material icon named "app registration" (outlined). + static const IconData app_registration_outlined = IconData(0xee7d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">app_settings_alt</i> — material icon named "app settings alt". + static const IconData app_settings_alt = IconData(0xe08d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">app_settings_alt</i> — material icon named "app settings alt" (sharp). + static const IconData app_settings_alt_sharp = IconData(0xe78c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">app_settings_alt</i> — material icon named "app settings alt" (round). + static const IconData app_settings_alt_rounded = IconData(0xf56b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">app_settings_alt</i> — material icon named "app settings alt" (outlined). + static const IconData app_settings_alt_outlined = IconData(0xee7e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">app_shortcut</i> — material icon named "app shortcut". + static const IconData app_shortcut = IconData(0xf04bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">app_shortcut</i> — material icon named "app shortcut" (sharp). + static const IconData app_shortcut_sharp = IconData(0xf03ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">app_shortcut</i> — material icon named "app shortcut" (round). + static const IconData app_shortcut_rounded = IconData(0xf02d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">app_shortcut</i> — material icon named "app shortcut" (outlined). + static const IconData app_shortcut_outlined = IconData(0xf05b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">apple</i> — material icon named "apple". + static const IconData apple = IconData(0xf04be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">apple</i> — material icon named "apple" (sharp). + static const IconData apple_sharp = IconData(0xf03cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">apple</i> — material icon named "apple" (round). + static const IconData apple_rounded = IconData(0xf02d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">apple</i> — material icon named "apple" (outlined). + static const IconData apple_outlined = IconData(0xf05b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">approval</i> — material icon named "approval". + static const IconData approval = IconData(0xe08e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">approval</i> — material icon named "approval" (sharp). + static const IconData approval_sharp = IconData(0xe78d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">approval</i> — material icon named "approval" (round). + static const IconData approval_rounded = IconData(0xf56c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">approval</i> — material icon named "approval" (outlined). + static const IconData approval_outlined = IconData(0xee7f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">apps</i> — material icon named "apps". + static const IconData apps = IconData(0xe08f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">apps</i> — material icon named "apps" (sharp). + static const IconData apps_sharp = IconData(0xe78e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">apps</i> — material icon named "apps" (round). + static const IconData apps_rounded = IconData(0xf56d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">apps</i> — material icon named "apps" (outlined). + static const IconData apps_outlined = IconData(0xee80, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">apps_outage</i> — material icon named "apps outage". + static const IconData apps_outage = IconData(0xf04bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">apps_outage</i> — material icon named "apps outage" (sharp). + static const IconData apps_outage_sharp = IconData(0xf03cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">apps_outage</i> — material icon named "apps outage" (round). + static const IconData apps_outage_rounded = IconData(0xf02d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">apps_outage</i> — material icon named "apps outage" (outlined). + static const IconData apps_outage_outlined = IconData(0xf05ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">architecture</i> — material icon named "architecture". + static const IconData architecture = IconData(0xe090, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">architecture</i> — material icon named "architecture" (sharp). + static const IconData architecture_sharp = IconData(0xe78f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">architecture</i> — material icon named "architecture" (round). + static const IconData architecture_rounded = IconData(0xf56e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">architecture</i> — material icon named "architecture" (outlined). + static const IconData architecture_outlined = IconData(0xee81, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">archive</i> — material icon named "archive". + static const IconData archive = IconData(0xe091, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">archive</i> — material icon named "archive" (sharp). + static const IconData archive_sharp = IconData(0xe790, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">archive</i> — material icon named "archive" (round). + static const IconData archive_rounded = IconData(0xf56f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">archive</i> — material icon named "archive" (outlined). + static const IconData archive_outlined = IconData(0xee82, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">area_chart</i> — material icon named "area chart". + static const IconData area_chart = IconData(0xf04c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">area_chart</i> — material icon named "area chart" (sharp). + static const IconData area_chart_sharp = IconData(0xf03cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">area_chart</i> — material icon named "area chart" (round). + static const IconData area_chart_rounded = IconData(0xf02da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">area_chart</i> — material icon named "area chart" (outlined). + static const IconData area_chart_outlined = IconData(0xf05bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">arrow_back</i> — material icon named "arrow back". + static const IconData arrow_back = IconData(0xe092, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">arrow_back</i> — material icon named "arrow back" (sharp). + static const IconData arrow_back_sharp = IconData(0xe793, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">arrow_back</i> — material icon named "arrow back" (round). + static const IconData arrow_back_rounded = IconData(0xf572, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">arrow_back</i> — material icon named "arrow back" (outlined). + static const IconData arrow_back_outlined = IconData(0xee85, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">arrow_back_ios</i> — material icon named "arrow back ios". + static const IconData arrow_back_ios = IconData(0xe093, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">arrow_back_ios</i> — material icon named "arrow back ios" (sharp). + static const IconData arrow_back_ios_sharp = IconData(0xe792, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">arrow_back_ios</i> — material icon named "arrow back ios" (round). + static const IconData arrow_back_ios_rounded = IconData(0xf571, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">arrow_back_ios</i> — material icon named "arrow back ios" (outlined). + static const IconData arrow_back_ios_outlined = IconData(0xee84, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">arrow_back_ios_new</i> — material icon named "arrow back ios new". + static const IconData arrow_back_ios_new = IconData(0xe094, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">arrow_back_ios_new</i> — material icon named "arrow back ios new" (sharp). + static const IconData arrow_back_ios_new_sharp = IconData(0xe791, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">arrow_back_ios_new</i> — material icon named "arrow back ios new" (round). + static const IconData arrow_back_ios_new_rounded = IconData(0xf570, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">arrow_back_ios_new</i> — material icon named "arrow back ios new" (outlined). + static const IconData arrow_back_ios_new_outlined = IconData(0xee83, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">arrow_circle_down</i> — material icon named "arrow circle down". + static const IconData arrow_circle_down = IconData(0xe095, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">arrow_circle_down</i> — material icon named "arrow circle down" (sharp). + static const IconData arrow_circle_down_sharp = IconData(0xe794, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">arrow_circle_down</i> — material icon named "arrow circle down" (round). + static const IconData arrow_circle_down_rounded = IconData(0xf573, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">arrow_circle_down</i> — material icon named "arrow circle down" (outlined). + static const IconData arrow_circle_down_outlined = IconData(0xee86, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">arrow_circle_left</i> — material icon named "arrow circle left". + static const IconData arrow_circle_left = IconData(0xf04c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">arrow_circle_left</i> — material icon named "arrow circle left" (sharp). + static const IconData arrow_circle_left_sharp = IconData(0xf03ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">arrow_circle_left</i> — material icon named "arrow circle left" (round). + static const IconData arrow_circle_left_rounded = IconData(0xf02db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">arrow_circle_left</i> — material icon named "arrow circle left" (outlined). + static const IconData arrow_circle_left_outlined = IconData(0xf05bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">arrow_circle_right</i> — material icon named "arrow circle right". + static const IconData arrow_circle_right = IconData(0xf04c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">arrow_circle_right</i> — material icon named "arrow circle right" (sharp). + static const IconData arrow_circle_right_sharp = IconData(0xf03cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">arrow_circle_right</i> — material icon named "arrow circle right" (round). + static const IconData arrow_circle_right_rounded = IconData(0xf02dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">arrow_circle_right</i> — material icon named "arrow circle right" (outlined). + static const IconData arrow_circle_right_outlined = IconData(0xf05bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">arrow_circle_up</i> — material icon named "arrow circle up". + static const IconData arrow_circle_up = IconData(0xe096, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">arrow_circle_up</i> — material icon named "arrow circle up" (sharp). + static const IconData arrow_circle_up_sharp = IconData(0xe795, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">arrow_circle_up</i> — material icon named "arrow circle up" (round). + static const IconData arrow_circle_up_rounded = IconData(0xf574, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">arrow_circle_up</i> — material icon named "arrow circle up" (outlined). + static const IconData arrow_circle_up_outlined = IconData(0xee87, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">arrow_downward</i> — material icon named "arrow downward". + static const IconData arrow_downward = IconData(0xe097, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">arrow_downward</i> — material icon named "arrow downward" (sharp). + static const IconData arrow_downward_sharp = IconData(0xe796, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">arrow_downward</i> — material icon named "arrow downward" (round). + static const IconData arrow_downward_rounded = IconData(0xf575, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">arrow_downward</i> — material icon named "arrow downward" (outlined). + static const IconData arrow_downward_outlined = IconData(0xee88, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">arrow_drop_down</i> — material icon named "arrow drop down". + static const IconData arrow_drop_down = IconData(0xe098, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">arrow_drop_down</i> — material icon named "arrow drop down" (sharp). + static const IconData arrow_drop_down_sharp = IconData(0xe798, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">arrow_drop_down</i> — material icon named "arrow drop down" (round). + static const IconData arrow_drop_down_rounded = IconData(0xf577, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">arrow_drop_down</i> — material icon named "arrow drop down" (outlined). + static const IconData arrow_drop_down_outlined = IconData(0xee8a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">arrow_drop_down_circle</i> — material icon named "arrow drop down circle". + static const IconData arrow_drop_down_circle = IconData(0xe099, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">arrow_drop_down_circle</i> — material icon named "arrow drop down circle" (sharp). + static const IconData arrow_drop_down_circle_sharp = IconData(0xe797, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">arrow_drop_down_circle</i> — material icon named "arrow drop down circle" (round). + static const IconData arrow_drop_down_circle_rounded = IconData(0xf576, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">arrow_drop_down_circle</i> — material icon named "arrow drop down circle" (outlined). + static const IconData arrow_drop_down_circle_outlined = IconData(0xee89, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">arrow_drop_up</i> — material icon named "arrow drop up". + static const IconData arrow_drop_up = IconData(0xe09a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">arrow_drop_up</i> — material icon named "arrow drop up" (sharp). + static const IconData arrow_drop_up_sharp = IconData(0xe799, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">arrow_drop_up</i> — material icon named "arrow drop up" (round). + static const IconData arrow_drop_up_rounded = IconData(0xf578, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">arrow_drop_up</i> — material icon named "arrow drop up" (outlined). + static const IconData arrow_drop_up_outlined = IconData(0xee8b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">arrow_forward</i> — material icon named "arrow forward". + static const IconData arrow_forward = IconData(0xe09b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">arrow_forward</i> — material icon named "arrow forward" (sharp). + static const IconData arrow_forward_sharp = IconData(0xe79b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">arrow_forward</i> — material icon named "arrow forward" (round). + static const IconData arrow_forward_rounded = IconData(0xf57a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">arrow_forward</i> — material icon named "arrow forward" (outlined). + static const IconData arrow_forward_outlined = IconData(0xee8d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">arrow_forward_ios</i> — material icon named "arrow forward ios". + static const IconData arrow_forward_ios = IconData(0xe09c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">arrow_forward_ios</i> — material icon named "arrow forward ios" (sharp). + static const IconData arrow_forward_ios_sharp = IconData(0xe79a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">arrow_forward_ios</i> — material icon named "arrow forward ios" (round). + static const IconData arrow_forward_ios_rounded = IconData(0xf579, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">arrow_forward_ios</i> — material icon named "arrow forward ios" (outlined). + static const IconData arrow_forward_ios_outlined = IconData(0xee8c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">arrow_left</i> — material icon named "arrow left". + static const IconData arrow_left = IconData(0xe09d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">arrow_left</i> — material icon named "arrow left" (sharp). + static const IconData arrow_left_sharp = IconData(0xe79c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">arrow_left</i> — material icon named "arrow left" (round). + static const IconData arrow_left_rounded = IconData(0xf57b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">arrow_left</i> — material icon named "arrow left" (outlined). + static const IconData arrow_left_outlined = IconData(0xee8e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">arrow_outward</i> — material icon named "arrow outward". + static const IconData arrow_outward = IconData(0xf0852, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">arrow_outward</i> — material icon named "arrow outward" (sharp). + static const IconData arrow_outward_sharp = IconData(0xf0834, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">arrow_outward</i> — material icon named "arrow outward" (round). + static const IconData arrow_outward_rounded = IconData(0xf087d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">arrow_outward</i> — material icon named "arrow outward" (outlined). + static const IconData arrow_outward_outlined = IconData(0xf089b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">arrow_right</i> — material icon named "arrow right". + static const IconData arrow_right = IconData(0xe09e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">arrow_right</i> — material icon named "arrow right" (sharp). + static const IconData arrow_right_sharp = IconData(0xe79e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">arrow_right</i> — material icon named "arrow right" (round). + static const IconData arrow_right_rounded = IconData(0xf57d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">arrow_right</i> — material icon named "arrow right" (outlined). + static const IconData arrow_right_outlined = IconData(0xee90, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">arrow_right_alt</i> — material icon named "arrow right alt". + static const IconData arrow_right_alt = IconData(0xe09f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">arrow_right_alt</i> — material icon named "arrow right alt" (sharp). + static const IconData arrow_right_alt_sharp = IconData(0xe79d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">arrow_right_alt</i> — material icon named "arrow right alt" (round). + static const IconData arrow_right_alt_rounded = IconData(0xf57c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">arrow_right_alt</i> — material icon named "arrow right alt" (outlined). + static const IconData arrow_right_alt_outlined = IconData(0xee8f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">arrow_upward</i> — material icon named "arrow upward". + static const IconData arrow_upward = IconData(0xe0a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">arrow_upward</i> — material icon named "arrow upward" (sharp). + static const IconData arrow_upward_sharp = IconData(0xe79f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">arrow_upward</i> — material icon named "arrow upward" (round). + static const IconData arrow_upward_rounded = IconData(0xf57e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">arrow_upward</i> — material icon named "arrow upward" (outlined). + static const IconData arrow_upward_outlined = IconData(0xee91, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">art_track</i> — material icon named "art track". + static const IconData art_track = IconData(0xe0a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">art_track</i> — material icon named "art track" (sharp). + static const IconData art_track_sharp = IconData(0xe7a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">art_track</i> — material icon named "art track" (round). + static const IconData art_track_rounded = IconData(0xf57f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">art_track</i> — material icon named "art track" (outlined). + static const IconData art_track_outlined = IconData(0xee92, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">article</i> — material icon named "article". + static const IconData article = IconData(0xe0a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">article</i> — material icon named "article" (sharp). + static const IconData article_sharp = IconData(0xe7a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">article</i> — material icon named "article" (round). + static const IconData article_rounded = IconData(0xf580, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">article</i> — material icon named "article" (outlined). + static const IconData article_outlined = IconData(0xee93, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">aspect_ratio</i> — material icon named "aspect ratio". + static const IconData aspect_ratio = IconData(0xe0a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">aspect_ratio</i> — material icon named "aspect ratio" (sharp). + static const IconData aspect_ratio_sharp = IconData(0xe7a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">aspect_ratio</i> — material icon named "aspect ratio" (round). + static const IconData aspect_ratio_rounded = IconData(0xf581, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">aspect_ratio</i> — material icon named "aspect ratio" (outlined). + static const IconData aspect_ratio_outlined = IconData(0xee94, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assessment</i> — material icon named "assessment". + static const IconData assessment = IconData(0xe0a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">assessment</i> — material icon named "assessment" (sharp). + static const IconData assessment_sharp = IconData(0xe7a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">assessment</i> — material icon named "assessment" (round). + static const IconData assessment_rounded = IconData(0xf582, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">assessment</i> — material icon named "assessment" (outlined). + static const IconData assessment_outlined = IconData(0xee95, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assignment</i> — material icon named "assignment". + static const IconData assignment = IconData(0xe0a5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">assignment</i> — material icon named "assignment" (sharp). + static const IconData assignment_sharp = IconData(0xe7a8, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">assignment</i> — material icon named "assignment" (round). + static const IconData assignment_rounded = IconData(0xf587, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">assignment</i> — material icon named "assignment" (outlined). + static const IconData assignment_outlined = IconData(0xee98, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">assignment_add</i> — material icon named "assignment add". + static const IconData assignment_add = IconData(0xf0853, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assignment_ind</i> — material icon named "assignment ind". + static const IconData assignment_ind = IconData(0xe0a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">assignment_ind</i> — material icon named "assignment ind" (sharp). + static const IconData assignment_ind_sharp = IconData(0xe7a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">assignment_ind</i> — material icon named "assignment ind" (round). + static const IconData assignment_ind_rounded = IconData(0xf583, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">assignment_ind</i> — material icon named "assignment ind" (outlined). + static const IconData assignment_ind_outlined = IconData(0xee96, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assignment_late</i> — material icon named "assignment late". + static const IconData assignment_late = IconData(0xe0a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">assignment_late</i> — material icon named "assignment late" (sharp). + static const IconData assignment_late_sharp = IconData(0xe7a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">assignment_late</i> — material icon named "assignment late" (round). + static const IconData assignment_late_rounded = IconData(0xf584, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">assignment_late</i> — material icon named "assignment late" (outlined). + static const IconData assignment_late_outlined = IconData(0xee97, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assignment_return</i> — material icon named "assignment return". + static const IconData assignment_return = IconData(0xe0a8, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">assignment_return</i> — material icon named "assignment return" (sharp). + static const IconData assignment_return_sharp = IconData(0xe7a6, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">assignment_return</i> — material icon named "assignment return" (round). + static const IconData assignment_return_rounded = IconData(0xf585, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">assignment_return</i> — material icon named "assignment return" (outlined). + static const IconData assignment_return_outlined = IconData(0xee99, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">assignment_returned</i> — material icon named "assignment returned". + static const IconData assignment_returned = IconData(0xe0a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">assignment_returned</i> — material icon named "assignment returned" (sharp). + static const IconData assignment_returned_sharp = IconData(0xe7a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">assignment_returned</i> — material icon named "assignment returned" (round). + static const IconData assignment_returned_rounded = IconData(0xf586, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">assignment_returned</i> — material icon named "assignment returned" (outlined). + static const IconData assignment_returned_outlined = IconData(0xee9a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assignment_turned_in</i> — material icon named "assignment turned in". + static const IconData assignment_turned_in = IconData(0xe0aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">assignment_turned_in</i> — material icon named "assignment turned in" (sharp). + static const IconData assignment_turned_in_sharp = IconData(0xe7a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">assignment_turned_in</i> — material icon named "assignment turned in" (round). + static const IconData assignment_turned_in_rounded = IconData(0xf588, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">assignment_turned_in</i> — material icon named "assignment turned in" (outlined). + static const IconData assignment_turned_in_outlined = IconData(0xee9b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assist_walker</i> — material icon named "assist walker". + static const IconData assist_walker = IconData(0xf0854, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">assist_walker</i> — material icon named "assist walker" (sharp). + static const IconData assist_walker_sharp = IconData(0xf0835, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">assist_walker</i> — material icon named "assist walker" (round). + static const IconData assist_walker_rounded = IconData(0xf087e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">assist_walker</i> — material icon named "assist walker" (outlined). + static const IconData assist_walker_outlined = IconData(0xf089c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assistant</i> — material icon named "assistant". + static const IconData assistant = IconData(0xe0ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">assistant</i> — material icon named "assistant" (sharp). + static const IconData assistant_sharp = IconData(0xe7ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">assistant</i> — material icon named "assistant" (round). + static const IconData assistant_rounded = IconData(0xf58b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">assistant</i> — material icon named "assistant" (outlined). + static const IconData assistant_outlined = IconData(0xee9d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assistant_direction</i> — material icon named "assistant direction". + static const IconData assistant_direction = IconData(0xe0ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">assistant_direction</i> — material icon named "assistant direction" (sharp). + static const IconData assistant_direction_sharp = IconData(0xe7aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">assistant_direction</i> — material icon named "assistant direction" (round). + static const IconData assistant_direction_rounded = IconData(0xf589, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">assistant_direction</i> — material icon named "assistant direction" (outlined). + static const IconData assistant_direction_outlined = IconData(0xee9c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assistant_navigation</i> — material icon named "assistant navigation". + static const IconData assistant_navigation = IconData(0xe0ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assistant_photo</i> — material icon named "assistant photo". + static const IconData assistant_photo = IconData(0xe0ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">assistant_photo</i> — material icon named "assistant photo" (sharp). + static const IconData assistant_photo_sharp = IconData(0xe7ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">assistant_photo</i> — material icon named "assistant photo" (round). + static const IconData assistant_photo_rounded = IconData(0xf58a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">assistant_photo</i> — material icon named "assistant photo" (outlined). + static const IconData assistant_photo_outlined = IconData(0xee9e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">assured_workload</i> — material icon named "assured workload". + static const IconData assured_workload = IconData(0xf04c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">assured_workload</i> — material icon named "assured workload" (sharp). + static const IconData assured_workload_sharp = IconData(0xf03d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">assured_workload</i> — material icon named "assured workload" (round). + static const IconData assured_workload_rounded = IconData(0xf02dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">assured_workload</i> — material icon named "assured workload" (outlined). + static const IconData assured_workload_outlined = IconData(0xf05be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">atm</i> — material icon named "atm". + static const IconData atm = IconData(0xe0af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">atm</i> — material icon named "atm" (sharp). + static const IconData atm_sharp = IconData(0xe7ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">atm</i> — material icon named "atm" (round). + static const IconData atm_rounded = IconData(0xf58c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">atm</i> — material icon named "atm" (outlined). + static const IconData atm_outlined = IconData(0xee9f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">attach_email</i> — material icon named "attach email". + static const IconData attach_email = IconData(0xe0b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">attach_email</i> — material icon named "attach email" (sharp). + static const IconData attach_email_sharp = IconData(0xe7ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">attach_email</i> — material icon named "attach email" (round). + static const IconData attach_email_rounded = IconData(0xf58d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">attach_email</i> — material icon named "attach email" (outlined). + static const IconData attach_email_outlined = IconData(0xeea0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">attach_file</i> — material icon named "attach file". + static const IconData attach_file = IconData(0xe0b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">attach_file</i> — material icon named "attach file" (sharp). + static const IconData attach_file_sharp = IconData(0xe7af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">attach_file</i> — material icon named "attach file" (round). + static const IconData attach_file_rounded = IconData(0xf58e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">attach_file</i> — material icon named "attach file" (outlined). + static const IconData attach_file_outlined = IconData(0xeea1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">attach_money</i> — material icon named "attach money". + static const IconData attach_money = IconData(0xe0b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">attach_money</i> — material icon named "attach money" (sharp). + static const IconData attach_money_sharp = IconData(0xe7b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">attach_money</i> — material icon named "attach money" (round). + static const IconData attach_money_rounded = IconData(0xf58f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">attach_money</i> — material icon named "attach money" (outlined). + static const IconData attach_money_outlined = IconData(0xeea2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">attachment</i> — material icon named "attachment". + static const IconData attachment = IconData(0xe0b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">attachment</i> — material icon named "attachment" (sharp). + static const IconData attachment_sharp = IconData(0xe7b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">attachment</i> — material icon named "attachment" (round). + static const IconData attachment_rounded = IconData(0xf590, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">attachment</i> — material icon named "attachment" (outlined). + static const IconData attachment_outlined = IconData(0xeea3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">attractions</i> — material icon named "attractions". + static const IconData attractions = IconData(0xe0b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">attractions</i> — material icon named "attractions" (sharp). + static const IconData attractions_sharp = IconData(0xe7b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">attractions</i> — material icon named "attractions" (round). + static const IconData attractions_rounded = IconData(0xf591, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">attractions</i> — material icon named "attractions" (outlined). + static const IconData attractions_outlined = IconData(0xeea4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">attribution</i> — material icon named "attribution". + static const IconData attribution = IconData(0xe0b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">attribution</i> — material icon named "attribution" (sharp). + static const IconData attribution_sharp = IconData(0xe7b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">attribution</i> — material icon named "attribution" (round). + static const IconData attribution_rounded = IconData(0xf592, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">attribution</i> — material icon named "attribution" (outlined). + static const IconData attribution_outlined = IconData(0xeea5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">audio_file</i> — material icon named "audio file". + static const IconData audio_file = IconData(0xf04c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">audio_file</i> — material icon named "audio file" (sharp). + static const IconData audio_file_sharp = IconData(0xf03d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">audio_file</i> — material icon named "audio file" (round). + static const IconData audio_file_rounded = IconData(0xf02de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">audio_file</i> — material icon named "audio file" (outlined). + static const IconData audio_file_outlined = IconData(0xf05bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">audiotrack</i> — material icon named "audiotrack". + static const IconData audiotrack = IconData(0xe0b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">audiotrack</i> — material icon named "audiotrack" (sharp). + static const IconData audiotrack_sharp = IconData(0xe7b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">audiotrack</i> — material icon named "audiotrack" (round). + static const IconData audiotrack_rounded = IconData(0xf593, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">audiotrack</i> — material icon named "audiotrack" (outlined). + static const IconData audiotrack_outlined = IconData(0xeea6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">auto_awesome</i> — material icon named "auto awesome". + static const IconData auto_awesome = IconData(0xe0b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">auto_awesome</i> — material icon named "auto awesome" (sharp). + static const IconData auto_awesome_sharp = IconData(0xe7b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">auto_awesome</i> — material icon named "auto awesome" (round). + static const IconData auto_awesome_rounded = IconData(0xf596, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">auto_awesome</i> — material icon named "auto awesome" (outlined). + static const IconData auto_awesome_outlined = IconData(0xeea9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">auto_awesome_mosaic</i> — material icon named "auto awesome mosaic". + static const IconData auto_awesome_mosaic = IconData(0xe0b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">auto_awesome_mosaic</i> — material icon named "auto awesome mosaic" (sharp). + static const IconData auto_awesome_mosaic_sharp = IconData(0xe7b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">auto_awesome_mosaic</i> — material icon named "auto awesome mosaic" (round). + static const IconData auto_awesome_mosaic_rounded = IconData(0xf594, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">auto_awesome_mosaic</i> — material icon named "auto awesome mosaic" (outlined). + static const IconData auto_awesome_mosaic_outlined = IconData(0xeea7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">auto_awesome_motion</i> — material icon named "auto awesome motion". + static const IconData auto_awesome_motion = IconData(0xe0b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">auto_awesome_motion</i> — material icon named "auto awesome motion" (sharp). + static const IconData auto_awesome_motion_sharp = IconData(0xe7b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">auto_awesome_motion</i> — material icon named "auto awesome motion" (round). + static const IconData auto_awesome_motion_rounded = IconData(0xf595, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">auto_awesome_motion</i> — material icon named "auto awesome motion" (outlined). + static const IconData auto_awesome_motion_outlined = IconData(0xeea8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">auto_delete</i> — material icon named "auto delete". + static const IconData auto_delete = IconData(0xe0ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">auto_delete</i> — material icon named "auto delete" (sharp). + static const IconData auto_delete_sharp = IconData(0xe7b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">auto_delete</i> — material icon named "auto delete" (round). + static const IconData auto_delete_rounded = IconData(0xf597, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">auto_delete</i> — material icon named "auto delete" (outlined). + static const IconData auto_delete_outlined = IconData(0xeeaa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">auto_fix_high</i> — material icon named "auto fix high". + static const IconData auto_fix_high = IconData(0xe0bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">auto_fix_high</i> — material icon named "auto fix high" (sharp). + static const IconData auto_fix_high_sharp = IconData(0xe7b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">auto_fix_high</i> — material icon named "auto fix high" (round). + static const IconData auto_fix_high_rounded = IconData(0xf598, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">auto_fix_high</i> — material icon named "auto fix high" (outlined). + static const IconData auto_fix_high_outlined = IconData(0xeeab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">auto_fix_normal</i> — material icon named "auto fix normal". + static const IconData auto_fix_normal = IconData(0xe0bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">auto_fix_normal</i> — material icon named "auto fix normal" (sharp). + static const IconData auto_fix_normal_sharp = IconData(0xe7ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">auto_fix_normal</i> — material icon named "auto fix normal" (round). + static const IconData auto_fix_normal_rounded = IconData(0xf599, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">auto_fix_normal</i> — material icon named "auto fix normal" (outlined). + static const IconData auto_fix_normal_outlined = IconData(0xeeac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">auto_fix_off</i> — material icon named "auto fix off". + static const IconData auto_fix_off = IconData(0xe0bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">auto_fix_off</i> — material icon named "auto fix off" (sharp). + static const IconData auto_fix_off_sharp = IconData(0xe7bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">auto_fix_off</i> — material icon named "auto fix off" (round). + static const IconData auto_fix_off_rounded = IconData(0xf59a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">auto_fix_off</i> — material icon named "auto fix off" (outlined). + static const IconData auto_fix_off_outlined = IconData(0xeead, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">auto_graph</i> — material icon named "auto graph". + static const IconData auto_graph = IconData(0xe0be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">auto_graph</i> — material icon named "auto graph" (sharp). + static const IconData auto_graph_sharp = IconData(0xe7bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">auto_graph</i> — material icon named "auto graph" (round). + static const IconData auto_graph_rounded = IconData(0xf59b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">auto_graph</i> — material icon named "auto graph" (outlined). + static const IconData auto_graph_outlined = IconData(0xeeae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">auto_mode</i> — material icon named "auto mode". + static const IconData auto_mode = IconData(0xf0787, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">auto_mode</i> — material icon named "auto mode" (sharp). + static const IconData auto_mode_sharp = IconData(0xf072f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">auto_mode</i> — material icon named "auto mode" (round). + static const IconData auto_mode_rounded = IconData(0xf07df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">auto_mode</i> — material icon named "auto mode" (outlined). + static const IconData auto_mode_outlined = IconData(0xf06d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">auto_stories</i> — material icon named "auto stories". + static const IconData auto_stories = IconData(0xe0bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">auto_stories</i> — material icon named "auto stories" (sharp). + static const IconData auto_stories_sharp = IconData(0xe7bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">auto_stories</i> — material icon named "auto stories" (round). + static const IconData auto_stories_rounded = IconData(0xf59c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">auto_stories</i> — material icon named "auto stories" (outlined). + static const IconData auto_stories_outlined = IconData(0xeeaf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">autofps_select</i> — material icon named "autofps select". + static const IconData autofps_select = IconData(0xe0c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">autofps_select</i> — material icon named "autofps select" (sharp). + static const IconData autofps_select_sharp = IconData(0xe7be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">autofps_select</i> — material icon named "autofps select" (round). + static const IconData autofps_select_rounded = IconData(0xf59d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">autofps_select</i> — material icon named "autofps select" (outlined). + static const IconData autofps_select_outlined = IconData(0xeeb0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">autorenew</i> — material icon named "autorenew". + static const IconData autorenew = IconData(0xe0c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">autorenew</i> — material icon named "autorenew" (sharp). + static const IconData autorenew_sharp = IconData(0xe7bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">autorenew</i> — material icon named "autorenew" (round). + static const IconData autorenew_rounded = IconData(0xf59e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">autorenew</i> — material icon named "autorenew" (outlined). + static const IconData autorenew_outlined = IconData(0xeeb1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">av_timer</i> — material icon named "av timer". + static const IconData av_timer = IconData(0xe0c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">av_timer</i> — material icon named "av timer" (sharp). + static const IconData av_timer_sharp = IconData(0xe7c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">av_timer</i> — material icon named "av timer" (round). + static const IconData av_timer_rounded = IconData(0xf59f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">av_timer</i> — material icon named "av timer" (outlined). + static const IconData av_timer_outlined = IconData(0xeeb2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">baby_changing_station</i> — material icon named "baby changing station". + static const IconData baby_changing_station = IconData(0xe0c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">baby_changing_station</i> — material icon named "baby changing station" (sharp). + static const IconData baby_changing_station_sharp = IconData(0xe7c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">baby_changing_station</i> — material icon named "baby changing station" (round). + static const IconData baby_changing_station_rounded = IconData(0xf5a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">baby_changing_station</i> — material icon named "baby changing station" (outlined). + static const IconData baby_changing_station_outlined = IconData(0xeeb3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">back_hand</i> — material icon named "back hand". + static const IconData back_hand = IconData(0xf04c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">back_hand</i> — material icon named "back hand" (sharp). + static const IconData back_hand_sharp = IconData(0xf03d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">back_hand</i> — material icon named "back hand" (round). + static const IconData back_hand_rounded = IconData(0xf02df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">back_hand</i> — material icon named "back hand" (outlined). + static const IconData back_hand_outlined = IconData(0xf05c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">backpack</i> — material icon named "backpack". + static const IconData backpack = IconData(0xe0c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">backpack</i> — material icon named "backpack" (sharp). + static const IconData backpack_sharp = IconData(0xe7c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">backpack</i> — material icon named "backpack" (round). + static const IconData backpack_rounded = IconData(0xf5a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">backpack</i> — material icon named "backpack" (outlined). + static const IconData backpack_outlined = IconData(0xeeb4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">backspace</i> — material icon named "backspace". + static const IconData backspace = IconData(0xe0c5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">backspace</i> — material icon named "backspace" (sharp). + static const IconData backspace_sharp = IconData(0xe7c3, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">backspace</i> — material icon named "backspace" (round). + static const IconData backspace_rounded = IconData(0xf5a2, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">backspace</i> — material icon named "backspace" (outlined). + static const IconData backspace_outlined = IconData(0xeeb5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">backup</i> — material icon named "backup". + static const IconData backup = IconData(0xe0c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">backup</i> — material icon named "backup" (sharp). + static const IconData backup_sharp = IconData(0xe7c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">backup</i> — material icon named "backup" (round). + static const IconData backup_rounded = IconData(0xf5a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">backup</i> — material icon named "backup" (outlined). + static const IconData backup_outlined = IconData(0xeeb6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">backup_table</i> — material icon named "backup table". + static const IconData backup_table = IconData(0xe0c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">backup_table</i> — material icon named "backup table" (sharp). + static const IconData backup_table_sharp = IconData(0xe7c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">backup_table</i> — material icon named "backup table" (round). + static const IconData backup_table_rounded = IconData(0xf5a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">backup_table</i> — material icon named "backup table" (outlined). + static const IconData backup_table_outlined = IconData(0xeeb7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">badge</i> — material icon named "badge". + static const IconData badge = IconData(0xe0c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">badge</i> — material icon named "badge" (sharp). + static const IconData badge_sharp = IconData(0xe7c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">badge</i> — material icon named "badge" (round). + static const IconData badge_rounded = IconData(0xf5a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">badge</i> — material icon named "badge" (outlined). + static const IconData badge_outlined = IconData(0xeeb8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bakery_dining</i> — material icon named "bakery dining". + static const IconData bakery_dining = IconData(0xe0c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bakery_dining</i> — material icon named "bakery dining" (sharp). + static const IconData bakery_dining_sharp = IconData(0xe7c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bakery_dining</i> — material icon named "bakery dining" (round). + static const IconData bakery_dining_rounded = IconData(0xf5a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bakery_dining</i> — material icon named "bakery dining" (outlined). + static const IconData bakery_dining_outlined = IconData(0xeeb9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">balance</i> — material icon named "balance". + static const IconData balance = IconData(0xf04c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">balance</i> — material icon named "balance" (sharp). + static const IconData balance_sharp = IconData(0xf03d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">balance</i> — material icon named "balance" (round). + static const IconData balance_rounded = IconData(0xf02e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">balance</i> — material icon named "balance" (outlined). + static const IconData balance_outlined = IconData(0xf05c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">balcony</i> — material icon named "balcony". + static const IconData balcony = IconData(0xe0ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">balcony</i> — material icon named "balcony" (sharp). + static const IconData balcony_sharp = IconData(0xe7c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">balcony</i> — material icon named "balcony" (round). + static const IconData balcony_rounded = IconData(0xf5a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">balcony</i> — material icon named "balcony" (outlined). + static const IconData balcony_outlined = IconData(0xeeba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ballot</i> — material icon named "ballot". + static const IconData ballot = IconData(0xe0cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ballot</i> — material icon named "ballot" (sharp). + static const IconData ballot_sharp = IconData(0xe7c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ballot</i> — material icon named "ballot" (round). + static const IconData ballot_rounded = IconData(0xf5a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ballot</i> — material icon named "ballot" (outlined). + static const IconData ballot_outlined = IconData(0xeebb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bar_chart</i> — material icon named "bar chart". + static const IconData bar_chart = IconData(0xe0cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bar_chart</i> — material icon named "bar chart" (sharp). + static const IconData bar_chart_sharp = IconData(0xe7ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bar_chart</i> — material icon named "bar chart" (round). + static const IconData bar_chart_rounded = IconData(0xf5a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bar_chart</i> — material icon named "bar chart" (outlined). + static const IconData bar_chart_outlined = IconData(0xeebc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">barcode_reader</i> — material icon named "barcode reader". + static const IconData barcode_reader = IconData(0xf0855, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">batch_prediction</i> — material icon named "batch prediction". + static const IconData batch_prediction = IconData(0xe0cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">batch_prediction</i> — material icon named "batch prediction" (sharp). + static const IconData batch_prediction_sharp = IconData(0xe7cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">batch_prediction</i> — material icon named "batch prediction" (round). + static const IconData batch_prediction_rounded = IconData(0xf5aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">batch_prediction</i> — material icon named "batch prediction" (outlined). + static const IconData batch_prediction_outlined = IconData(0xeebd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bathroom</i> — material icon named "bathroom". + static const IconData bathroom = IconData(0xe0ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bathroom</i> — material icon named "bathroom" (sharp). + static const IconData bathroom_sharp = IconData(0xe7cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bathroom</i> — material icon named "bathroom" (round). + static const IconData bathroom_rounded = IconData(0xf5ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bathroom</i> — material icon named "bathroom" (outlined). + static const IconData bathroom_outlined = IconData(0xeebe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bathtub</i> — material icon named "bathtub". + static const IconData bathtub = IconData(0xe0cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bathtub</i> — material icon named "bathtub" (sharp). + static const IconData bathtub_sharp = IconData(0xe7cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bathtub</i> — material icon named "bathtub" (round). + static const IconData bathtub_rounded = IconData(0xf5ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bathtub</i> — material icon named "bathtub" (outlined). + static const IconData bathtub_outlined = IconData(0xeebf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_0_bar</i> — material icon named "battery 0 bar". + static const IconData battery_0_bar = IconData(0xf0788, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_0_bar</i> — material icon named "battery 0 bar" (sharp). + static const IconData battery_0_bar_sharp = IconData(0xf0730, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_0_bar</i> — material icon named "battery 0 bar" (round). + static const IconData battery_0_bar_rounded = IconData(0xf07e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_0_bar</i> — material icon named "battery 0 bar" (outlined). + static const IconData battery_0_bar_outlined = IconData(0xf06d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_1_bar</i> — material icon named "battery 1 bar". + static const IconData battery_1_bar = IconData(0xf0789, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_1_bar</i> — material icon named "battery 1 bar" (sharp). + static const IconData battery_1_bar_sharp = IconData(0xf0731, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_1_bar</i> — material icon named "battery 1 bar" (round). + static const IconData battery_1_bar_rounded = IconData(0xf07e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_1_bar</i> — material icon named "battery 1 bar" (outlined). + static const IconData battery_1_bar_outlined = IconData(0xf06d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_2_bar</i> — material icon named "battery 2 bar". + static const IconData battery_2_bar = IconData(0xf078a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_2_bar</i> — material icon named "battery 2 bar" (sharp). + static const IconData battery_2_bar_sharp = IconData(0xf0732, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_2_bar</i> — material icon named "battery 2 bar" (round). + static const IconData battery_2_bar_rounded = IconData(0xf07e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_2_bar</i> — material icon named "battery 2 bar" (outlined). + static const IconData battery_2_bar_outlined = IconData(0xf06da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_3_bar</i> — material icon named "battery 3 bar". + static const IconData battery_3_bar = IconData(0xf078b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_3_bar</i> — material icon named "battery 3 bar" (sharp). + static const IconData battery_3_bar_sharp = IconData(0xf0733, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_3_bar</i> — material icon named "battery 3 bar" (round). + static const IconData battery_3_bar_rounded = IconData(0xf07e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_3_bar</i> — material icon named "battery 3 bar" (outlined). + static const IconData battery_3_bar_outlined = IconData(0xf06db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_4_bar</i> — material icon named "battery 4 bar". + static const IconData battery_4_bar = IconData(0xf078c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_4_bar</i> — material icon named "battery 4 bar" (sharp). + static const IconData battery_4_bar_sharp = IconData(0xf0734, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_4_bar</i> — material icon named "battery 4 bar" (round). + static const IconData battery_4_bar_rounded = IconData(0xf07e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_4_bar</i> — material icon named "battery 4 bar" (outlined). + static const IconData battery_4_bar_outlined = IconData(0xf06dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_5_bar</i> — material icon named "battery 5 bar". + static const IconData battery_5_bar = IconData(0xf078d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_5_bar</i> — material icon named "battery 5 bar" (sharp). + static const IconData battery_5_bar_sharp = IconData(0xf0735, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_5_bar</i> — material icon named "battery 5 bar" (round). + static const IconData battery_5_bar_rounded = IconData(0xf07e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_5_bar</i> — material icon named "battery 5 bar" (outlined). + static const IconData battery_5_bar_outlined = IconData(0xf06dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_6_bar</i> — material icon named "battery 6 bar". + static const IconData battery_6_bar = IconData(0xf078e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_6_bar</i> — material icon named "battery 6 bar" (sharp). + static const IconData battery_6_bar_sharp = IconData(0xf0736, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_6_bar</i> — material icon named "battery 6 bar" (round). + static const IconData battery_6_bar_rounded = IconData(0xf07e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_6_bar</i> — material icon named "battery 6 bar" (outlined). + static const IconData battery_6_bar_outlined = IconData(0xf06de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_alert</i> — material icon named "battery alert". + static const IconData battery_alert = IconData(0xe0d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_alert</i> — material icon named "battery alert" (sharp). + static const IconData battery_alert_sharp = IconData(0xe7ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_alert</i> — material icon named "battery alert" (round). + static const IconData battery_alert_rounded = IconData(0xf5ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_alert</i> — material icon named "battery alert" (outlined). + static const IconData battery_alert_outlined = IconData(0xeec0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_charging_full</i> — material icon named "battery charging full". + static const IconData battery_charging_full = IconData(0xe0d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_charging_full</i> — material icon named "battery charging full" (sharp). + static const IconData battery_charging_full_sharp = IconData(0xe7cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_charging_full</i> — material icon named "battery charging full" (round). + static const IconData battery_charging_full_rounded = IconData(0xf5ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_charging_full</i> — material icon named "battery charging full" (outlined). + static const IconData battery_charging_full_outlined = IconData(0xeec1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_full</i> — material icon named "battery full". + static const IconData battery_full = IconData(0xe0d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_full</i> — material icon named "battery full" (sharp). + static const IconData battery_full_sharp = IconData(0xe7d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_full</i> — material icon named "battery full" (round). + static const IconData battery_full_rounded = IconData(0xf5af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_full</i> — material icon named "battery full" (outlined). + static const IconData battery_full_outlined = IconData(0xeec2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_saver</i> — material icon named "battery saver". + static const IconData battery_saver = IconData(0xe0d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_saver</i> — material icon named "battery saver" (sharp). + static const IconData battery_saver_sharp = IconData(0xe7d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_saver</i> — material icon named "battery saver" (round). + static const IconData battery_saver_rounded = IconData(0xf5b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_saver</i> — material icon named "battery saver" (outlined). + static const IconData battery_saver_outlined = IconData(0xeec3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_std</i> — material icon named "battery std". + static const IconData battery_std = IconData(0xe0d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">battery_std</i> — material icon named "battery std" (sharp). + static const IconData battery_std_sharp = IconData(0xe7d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">battery_std</i> — material icon named "battery std" (round). + static const IconData battery_std_rounded = IconData(0xf5b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">battery_std</i> — material icon named "battery std" (outlined). + static const IconData battery_std_outlined = IconData(0xeec4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">battery_unknown</i> — material icon named "battery unknown". + static const IconData battery_unknown = IconData(0xe0d5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">battery_unknown</i> — material icon named "battery unknown" (sharp). + static const IconData battery_unknown_sharp = IconData(0xe7d3, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">battery_unknown</i> — material icon named "battery unknown" (round). + static const IconData battery_unknown_rounded = IconData(0xf5b2, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">battery_unknown</i> — material icon named "battery unknown" (outlined). + static const IconData battery_unknown_outlined = IconData(0xeec5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">beach_access</i> — material icon named "beach access". + static const IconData beach_access = IconData(0xe0d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">beach_access</i> — material icon named "beach access" (sharp). + static const IconData beach_access_sharp = IconData(0xe7d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">beach_access</i> — material icon named "beach access" (round). + static const IconData beach_access_rounded = IconData(0xf5b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">beach_access</i> — material icon named "beach access" (outlined). + static const IconData beach_access_outlined = IconData(0xeec6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bed</i> — material icon named "bed". + static const IconData bed = IconData(0xe0d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bed</i> — material icon named "bed" (sharp). + static const IconData bed_sharp = IconData(0xe7d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bed</i> — material icon named "bed" (round). + static const IconData bed_rounded = IconData(0xf5b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bed</i> — material icon named "bed" (outlined). + static const IconData bed_outlined = IconData(0xeec7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bedroom_baby</i> — material icon named "bedroom baby". + static const IconData bedroom_baby = IconData(0xe0d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bedroom_baby</i> — material icon named "bedroom baby" (sharp). + static const IconData bedroom_baby_sharp = IconData(0xe7d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bedroom_baby</i> — material icon named "bedroom baby" (round). + static const IconData bedroom_baby_rounded = IconData(0xf5b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bedroom_baby</i> — material icon named "bedroom baby" (outlined). + static const IconData bedroom_baby_outlined = IconData(0xeec8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bedroom_child</i> — material icon named "bedroom child". + static const IconData bedroom_child = IconData(0xe0d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bedroom_child</i> — material icon named "bedroom child" (sharp). + static const IconData bedroom_child_sharp = IconData(0xe7d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bedroom_child</i> — material icon named "bedroom child" (round). + static const IconData bedroom_child_rounded = IconData(0xf5b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bedroom_child</i> — material icon named "bedroom child" (outlined). + static const IconData bedroom_child_outlined = IconData(0xeec9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bedroom_parent</i> — material icon named "bedroom parent". + static const IconData bedroom_parent = IconData(0xe0da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bedroom_parent</i> — material icon named "bedroom parent" (sharp). + static const IconData bedroom_parent_sharp = IconData(0xe7d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bedroom_parent</i> — material icon named "bedroom parent" (round). + static const IconData bedroom_parent_rounded = IconData(0xf5b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bedroom_parent</i> — material icon named "bedroom parent" (outlined). + static const IconData bedroom_parent_outlined = IconData(0xeeca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bedtime</i> — material icon named "bedtime". + static const IconData bedtime = IconData(0xe0db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bedtime</i> — material icon named "bedtime" (sharp). + static const IconData bedtime_sharp = IconData(0xe7d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bedtime</i> — material icon named "bedtime" (round). + static const IconData bedtime_rounded = IconData(0xf5b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bedtime</i> — material icon named "bedtime" (outlined). + static const IconData bedtime_outlined = IconData(0xeecb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bedtime_off</i> — material icon named "bedtime off". + static const IconData bedtime_off = IconData(0xf04c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bedtime_off</i> — material icon named "bedtime off" (sharp). + static const IconData bedtime_off_sharp = IconData(0xf03d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bedtime_off</i> — material icon named "bedtime off" (round). + static const IconData bedtime_off_rounded = IconData(0xf02e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bedtime_off</i> — material icon named "bedtime off" (outlined). + static const IconData bedtime_off_outlined = IconData(0xf05c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">beenhere</i> — material icon named "beenhere". + static const IconData beenhere = IconData(0xe0dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">beenhere</i> — material icon named "beenhere" (sharp). + static const IconData beenhere_sharp = IconData(0xe7da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">beenhere</i> — material icon named "beenhere" (round). + static const IconData beenhere_rounded = IconData(0xf5b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">beenhere</i> — material icon named "beenhere" (outlined). + static const IconData beenhere_outlined = IconData(0xeecc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bento</i> — material icon named "bento". + static const IconData bento = IconData(0xe0dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bento</i> — material icon named "bento" (sharp). + static const IconData bento_sharp = IconData(0xe7db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bento</i> — material icon named "bento" (round). + static const IconData bento_rounded = IconData(0xf5ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bento</i> — material icon named "bento" (outlined). + static const IconData bento_outlined = IconData(0xeecd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bike_scooter</i> — material icon named "bike scooter". + static const IconData bike_scooter = IconData(0xe0de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bike_scooter</i> — material icon named "bike scooter" (sharp). + static const IconData bike_scooter_sharp = IconData(0xe7dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bike_scooter</i> — material icon named "bike scooter" (round). + static const IconData bike_scooter_rounded = IconData(0xf5bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bike_scooter</i> — material icon named "bike scooter" (outlined). + static const IconData bike_scooter_outlined = IconData(0xeece, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">biotech</i> — material icon named "biotech". + static const IconData biotech = IconData(0xe0df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">biotech</i> — material icon named "biotech" (sharp). + static const IconData biotech_sharp = IconData(0xe7dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">biotech</i> — material icon named "biotech" (round). + static const IconData biotech_rounded = IconData(0xf5bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">biotech</i> — material icon named "biotech" (outlined). + static const IconData biotech_outlined = IconData(0xeecf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">blender</i> — material icon named "blender". + static const IconData blender = IconData(0xe0e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">blender</i> — material icon named "blender" (sharp). + static const IconData blender_sharp = IconData(0xe7de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">blender</i> — material icon named "blender" (round). + static const IconData blender_rounded = IconData(0xf5bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">blender</i> — material icon named "blender" (outlined). + static const IconData blender_outlined = IconData(0xeed0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">blind</i> — material icon named "blind". + static const IconData blind = IconData(0xf0856, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">blind</i> — material icon named "blind" (sharp). + static const IconData blind_sharp = IconData(0xf0836, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">blind</i> — material icon named "blind" (round). + static const IconData blind_rounded = IconData(0xf087f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">blind</i> — material icon named "blind" (outlined). + static const IconData blind_outlined = IconData(0xf089d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">blinds</i> — material icon named "blinds". + static const IconData blinds = IconData(0xf078f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">blinds</i> — material icon named "blinds" (sharp). + static const IconData blinds_sharp = IconData(0xf0738, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">blinds</i> — material icon named "blinds" (round). + static const IconData blinds_rounded = IconData(0xf07e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">blinds</i> — material icon named "blinds" (outlined). + static const IconData blinds_outlined = IconData(0xf06e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">blinds_closed</i> — material icon named "blinds closed". + static const IconData blinds_closed = IconData(0xf0790, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">blinds_closed</i> — material icon named "blinds closed" (sharp). + static const IconData blinds_closed_sharp = IconData(0xf0737, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">blinds_closed</i> — material icon named "blinds closed" (round). + static const IconData blinds_closed_rounded = IconData(0xf07e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">blinds_closed</i> — material icon named "blinds closed" (outlined). + static const IconData blinds_closed_outlined = IconData(0xf06df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">block</i> — material icon named "block". + static const IconData block = IconData(0xe0e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">block</i> — material icon named "block" (sharp). + static const IconData block_sharp = IconData(0xe7df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">block</i> — material icon named "block" (round). + static const IconData block_rounded = IconData(0xf5be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">block</i> — material icon named "block" (outlined). + static const IconData block_outlined = IconData(0xeed1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">block_flipped</i> — material icon named "block flipped". + static const IconData block_flipped = IconData(0xe0e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bloodtype</i> — material icon named "bloodtype". + static const IconData bloodtype = IconData(0xe0e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bloodtype</i> — material icon named "bloodtype" (sharp). + static const IconData bloodtype_sharp = IconData(0xe7e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bloodtype</i> — material icon named "bloodtype" (round). + static const IconData bloodtype_rounded = IconData(0xf5bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bloodtype</i> — material icon named "bloodtype" (outlined). + static const IconData bloodtype_outlined = IconData(0xeed2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bluetooth</i> — material icon named "bluetooth". + static const IconData bluetooth = IconData(0xe0e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bluetooth</i> — material icon named "bluetooth" (sharp). + static const IconData bluetooth_sharp = IconData(0xe7e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bluetooth</i> — material icon named "bluetooth" (round). + static const IconData bluetooth_rounded = IconData(0xf5c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bluetooth</i> — material icon named "bluetooth" (outlined). + static const IconData bluetooth_outlined = IconData(0xeed7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bluetooth_audio</i> — material icon named "bluetooth audio". + static const IconData bluetooth_audio = IconData(0xe0e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bluetooth_audio</i> — material icon named "bluetooth audio" (sharp). + static const IconData bluetooth_audio_sharp = IconData(0xe7e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bluetooth_audio</i> — material icon named "bluetooth audio" (round). + static const IconData bluetooth_audio_rounded = IconData(0xf5c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bluetooth_audio</i> — material icon named "bluetooth audio" (outlined). + static const IconData bluetooth_audio_outlined = IconData(0xeed3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bluetooth_connected</i> — material icon named "bluetooth connected". + static const IconData bluetooth_connected = IconData(0xe0e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bluetooth_connected</i> — material icon named "bluetooth connected" (sharp). + static const IconData bluetooth_connected_sharp = IconData(0xe7e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bluetooth_connected</i> — material icon named "bluetooth connected" (round). + static const IconData bluetooth_connected_rounded = IconData(0xf5c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bluetooth_connected</i> — material icon named "bluetooth connected" (outlined). + static const IconData bluetooth_connected_outlined = IconData(0xeed4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bluetooth_disabled</i> — material icon named "bluetooth disabled". + static const IconData bluetooth_disabled = IconData(0xe0e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bluetooth_disabled</i> — material icon named "bluetooth disabled" (sharp). + static const IconData bluetooth_disabled_sharp = IconData(0xe7e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bluetooth_disabled</i> — material icon named "bluetooth disabled" (round). + static const IconData bluetooth_disabled_rounded = IconData(0xf5c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bluetooth_disabled</i> — material icon named "bluetooth disabled" (outlined). + static const IconData bluetooth_disabled_outlined = IconData(0xeed5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bluetooth_drive</i> — material icon named "bluetooth drive". + static const IconData bluetooth_drive = IconData(0xe0e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bluetooth_drive</i> — material icon named "bluetooth drive" (sharp). + static const IconData bluetooth_drive_sharp = IconData(0xe7e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bluetooth_drive</i> — material icon named "bluetooth drive" (round). + static const IconData bluetooth_drive_rounded = IconData(0xf5c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bluetooth_drive</i> — material icon named "bluetooth drive" (outlined). + static const IconData bluetooth_drive_outlined = IconData(0xeed6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bluetooth_searching</i> — material icon named "bluetooth searching". + static const IconData bluetooth_searching = IconData(0xe0e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bluetooth_searching</i> — material icon named "bluetooth searching" (sharp). + static const IconData bluetooth_searching_sharp = IconData(0xe7e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bluetooth_searching</i> — material icon named "bluetooth searching" (round). + static const IconData bluetooth_searching_rounded = IconData(0xf5c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bluetooth_searching</i> — material icon named "bluetooth searching" (outlined). + static const IconData bluetooth_searching_outlined = IconData(0xeed8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">blur_circular</i> — material icon named "blur circular". + static const IconData blur_circular = IconData(0xe0ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">blur_circular</i> — material icon named "blur circular" (sharp). + static const IconData blur_circular_sharp = IconData(0xe7e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">blur_circular</i> — material icon named "blur circular" (round). + static const IconData blur_circular_rounded = IconData(0xf5c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">blur_circular</i> — material icon named "blur circular" (outlined). + static const IconData blur_circular_outlined = IconData(0xeed9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">blur_linear</i> — material icon named "blur linear". + static const IconData blur_linear = IconData(0xe0eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">blur_linear</i> — material icon named "blur linear" (sharp). + static const IconData blur_linear_sharp = IconData(0xe7e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">blur_linear</i> — material icon named "blur linear" (round). + static const IconData blur_linear_rounded = IconData(0xf5c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">blur_linear</i> — material icon named "blur linear" (outlined). + static const IconData blur_linear_outlined = IconData(0xeeda, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">blur_off</i> — material icon named "blur off". + static const IconData blur_off = IconData(0xe0ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">blur_off</i> — material icon named "blur off" (sharp). + static const IconData blur_off_sharp = IconData(0xe7e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">blur_off</i> — material icon named "blur off" (round). + static const IconData blur_off_rounded = IconData(0xf5c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">blur_off</i> — material icon named "blur off" (outlined). + static const IconData blur_off_outlined = IconData(0xeedb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">blur_on</i> — material icon named "blur on". + static const IconData blur_on = IconData(0xe0ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">blur_on</i> — material icon named "blur on" (sharp). + static const IconData blur_on_sharp = IconData(0xe7ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">blur_on</i> — material icon named "blur on" (round). + static const IconData blur_on_rounded = IconData(0xf5c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">blur_on</i> — material icon named "blur on" (outlined). + static const IconData blur_on_outlined = IconData(0xeedc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bolt</i> — material icon named "bolt". + static const IconData bolt = IconData(0xe0ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bolt</i> — material icon named "bolt" (sharp). + static const IconData bolt_sharp = IconData(0xe7eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bolt</i> — material icon named "bolt" (round). + static const IconData bolt_rounded = IconData(0xf5ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bolt</i> — material icon named "bolt" (outlined). + static const IconData bolt_outlined = IconData(0xeedd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">book</i> — material icon named "book". + static const IconData book = IconData(0xe0ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">book</i> — material icon named "book" (sharp). + static const IconData book_sharp = IconData(0xe7ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">book</i> — material icon named "book" (round). + static const IconData book_rounded = IconData(0xf5cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">book</i> — material icon named "book" (outlined). + static const IconData book_outlined = IconData(0xeedf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">book_online</i> — material icon named "book online". + static const IconData book_online = IconData(0xe0f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">book_online</i> — material icon named "book online" (sharp). + static const IconData book_online_sharp = IconData(0xe7ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">book_online</i> — material icon named "book online" (round). + static const IconData book_online_rounded = IconData(0xf5cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">book_online</i> — material icon named "book online" (outlined). + static const IconData book_online_outlined = IconData(0xeede, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bookmark</i> — material icon named "bookmark". + static const IconData bookmark = IconData(0xe0f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bookmark</i> — material icon named "bookmark" (sharp). + static const IconData bookmark_sharp = IconData(0xe7f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bookmark</i> — material icon named "bookmark" (round). + static const IconData bookmark_rounded = IconData(0xf5d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bookmark</i> — material icon named "bookmark" (outlined). + static const IconData bookmark_outlined = IconData(0xeee3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bookmark_add</i> — material icon named "bookmark add". + static const IconData bookmark_add = IconData(0xe0f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bookmark_add</i> — material icon named "bookmark add" (sharp). + static const IconData bookmark_add_sharp = IconData(0xe7ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bookmark_add</i> — material icon named "bookmark add" (round). + static const IconData bookmark_add_rounded = IconData(0xf5cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bookmark_add</i> — material icon named "bookmark add" (outlined). + static const IconData bookmark_add_outlined = IconData(0xeee0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bookmark_added</i> — material icon named "bookmark added". + static const IconData bookmark_added = IconData(0xe0f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bookmark_added</i> — material icon named "bookmark added" (sharp). + static const IconData bookmark_added_sharp = IconData(0xe7ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bookmark_added</i> — material icon named "bookmark added" (round). + static const IconData bookmark_added_rounded = IconData(0xf5ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bookmark_added</i> — material icon named "bookmark added" (outlined). + static const IconData bookmark_added_outlined = IconData(0xeee1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bookmark_border</i> — material icon named "bookmark border". + static const IconData bookmark_border = IconData(0xe0f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bookmark_border</i> — material icon named "bookmark border" (sharp). + static const IconData bookmark_border_sharp = IconData(0xe7f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bookmark_border</i> — material icon named "bookmark border" (round). + static const IconData bookmark_border_rounded = IconData(0xf5cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bookmark_border</i> — material icon named "bookmark border" (outlined). + static const IconData bookmark_border_outlined = IconData(0xeee2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bookmark_outline</i> — material icon named "bookmark outline". + static const IconData bookmark_outline = IconData(0xe0f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bookmark_outline</i> — material icon named "bookmark outline" (sharp). + static const IconData bookmark_outline_sharp = IconData(0xe7f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bookmark_outline</i> — material icon named "bookmark outline" (round). + static const IconData bookmark_outline_rounded = IconData(0xf5cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bookmark_outline</i> — material icon named "bookmark outline" (outlined). + static const IconData bookmark_outline_outlined = IconData(0xeee2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bookmark_remove</i> — material icon named "bookmark remove". + static const IconData bookmark_remove = IconData(0xe0f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bookmark_remove</i> — material icon named "bookmark remove" (sharp). + static const IconData bookmark_remove_sharp = IconData(0xe7f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bookmark_remove</i> — material icon named "bookmark remove" (round). + static const IconData bookmark_remove_rounded = IconData(0xf5d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bookmark_remove</i> — material icon named "bookmark remove" (outlined). + static const IconData bookmark_remove_outlined = IconData(0xeee4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bookmarks</i> — material icon named "bookmarks". + static const IconData bookmarks = IconData(0xe0f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bookmarks</i> — material icon named "bookmarks" (sharp). + static const IconData bookmarks_sharp = IconData(0xe7f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bookmarks</i> — material icon named "bookmarks" (round). + static const IconData bookmarks_rounded = IconData(0xf5d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bookmarks</i> — material icon named "bookmarks" (outlined). + static const IconData bookmarks_outlined = IconData(0xeee5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_all</i> — material icon named "border all". + static const IconData border_all = IconData(0xe0f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_all</i> — material icon named "border all" (sharp). + static const IconData border_all_sharp = IconData(0xe7f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_all</i> — material icon named "border all" (round). + static const IconData border_all_rounded = IconData(0xf5d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_all</i> — material icon named "border all" (outlined). + static const IconData border_all_outlined = IconData(0xeee6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_bottom</i> — material icon named "border bottom". + static const IconData border_bottom = IconData(0xe0f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_bottom</i> — material icon named "border bottom" (sharp). + static const IconData border_bottom_sharp = IconData(0xe7f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_bottom</i> — material icon named "border bottom" (round). + static const IconData border_bottom_rounded = IconData(0xf5d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_bottom</i> — material icon named "border bottom" (outlined). + static const IconData border_bottom_outlined = IconData(0xeee7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_clear</i> — material icon named "border clear". + static const IconData border_clear = IconData(0xe0f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_clear</i> — material icon named "border clear" (sharp). + static const IconData border_clear_sharp = IconData(0xe7f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_clear</i> — material icon named "border clear" (round). + static const IconData border_clear_rounded = IconData(0xf5d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_clear</i> — material icon named "border clear" (outlined). + static const IconData border_clear_outlined = IconData(0xeee8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_color</i> — material icon named "border color". + static const IconData border_color = IconData(0xe0fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_color</i> — material icon named "border color" (sharp). + static const IconData border_color_sharp = IconData(0xe7f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_color</i> — material icon named "border color" (round). + static const IconData border_color_rounded = IconData(0xf5d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_color</i> — material icon named "border color" (outlined). + static const IconData border_color_outlined = IconData(0xeee9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_horizontal</i> — material icon named "border horizontal". + static const IconData border_horizontal = IconData(0xe0fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_horizontal</i> — material icon named "border horizontal" (sharp). + static const IconData border_horizontal_sharp = IconData(0xe7f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_horizontal</i> — material icon named "border horizontal" (round). + static const IconData border_horizontal_rounded = IconData(0xf5d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_horizontal</i> — material icon named "border horizontal" (outlined). + static const IconData border_horizontal_outlined = IconData(0xeeea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_inner</i> — material icon named "border inner". + static const IconData border_inner = IconData(0xe0fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_inner</i> — material icon named "border inner" (sharp). + static const IconData border_inner_sharp = IconData(0xe7f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_inner</i> — material icon named "border inner" (round). + static const IconData border_inner_rounded = IconData(0xf5d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_inner</i> — material icon named "border inner" (outlined). + static const IconData border_inner_outlined = IconData(0xeeeb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_left</i> — material icon named "border left". + static const IconData border_left = IconData(0xe0fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_left</i> — material icon named "border left" (sharp). + static const IconData border_left_sharp = IconData(0xe7fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_left</i> — material icon named "border left" (round). + static const IconData border_left_rounded = IconData(0xf5d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_left</i> — material icon named "border left" (outlined). + static const IconData border_left_outlined = IconData(0xeeec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_outer</i> — material icon named "border outer". + static const IconData border_outer = IconData(0xe0fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_outer</i> — material icon named "border outer" (sharp). + static const IconData border_outer_sharp = IconData(0xe7fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_outer</i> — material icon named "border outer" (round). + static const IconData border_outer_rounded = IconData(0xf5da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_outer</i> — material icon named "border outer" (outlined). + static const IconData border_outer_outlined = IconData(0xeeed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_right</i> — material icon named "border right". + static const IconData border_right = IconData(0xe0ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_right</i> — material icon named "border right" (sharp). + static const IconData border_right_sharp = IconData(0xe7fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_right</i> — material icon named "border right" (round). + static const IconData border_right_rounded = IconData(0xf5db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_right</i> — material icon named "border right" (outlined). + static const IconData border_right_outlined = IconData(0xeeee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_style</i> — material icon named "border style". + static const IconData border_style = IconData(0xe100, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_style</i> — material icon named "border style" (sharp). + static const IconData border_style_sharp = IconData(0xe7fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_style</i> — material icon named "border style" (round). + static const IconData border_style_rounded = IconData(0xf5dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_style</i> — material icon named "border style" (outlined). + static const IconData border_style_outlined = IconData(0xeeef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_top</i> — material icon named "border top". + static const IconData border_top = IconData(0xe101, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_top</i> — material icon named "border top" (sharp). + static const IconData border_top_sharp = IconData(0xe7fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_top</i> — material icon named "border top" (round). + static const IconData border_top_rounded = IconData(0xf5dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_top</i> — material icon named "border top" (outlined). + static const IconData border_top_outlined = IconData(0xeef0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">border_vertical</i> — material icon named "border vertical". + static const IconData border_vertical = IconData(0xe102, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">border_vertical</i> — material icon named "border vertical" (sharp). + static const IconData border_vertical_sharp = IconData(0xe7ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">border_vertical</i> — material icon named "border vertical" (round). + static const IconData border_vertical_rounded = IconData(0xf5de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">border_vertical</i> — material icon named "border vertical" (outlined). + static const IconData border_vertical_outlined = IconData(0xeef1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">boy</i> — material icon named "boy". + static const IconData boy = IconData(0xf04c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">boy</i> — material icon named "boy" (sharp). + static const IconData boy_sharp = IconData(0xf03d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">boy</i> — material icon named "boy" (round). + static const IconData boy_rounded = IconData(0xf02e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">boy</i> — material icon named "boy" (outlined). + static const IconData boy_outlined = IconData(0xf05c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">branding_watermark</i> — material icon named "branding watermark". + static const IconData branding_watermark = IconData(0xe103, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">branding_watermark</i> — material icon named "branding watermark" (sharp). + static const IconData branding_watermark_sharp = IconData(0xe800, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">branding_watermark</i> — material icon named "branding watermark" (round). + static const IconData branding_watermark_rounded = IconData(0xf5df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">branding_watermark</i> — material icon named "branding watermark" (outlined). + static const IconData branding_watermark_outlined = IconData(0xeef2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">breakfast_dining</i> — material icon named "breakfast dining". + static const IconData breakfast_dining = IconData(0xe104, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">breakfast_dining</i> — material icon named "breakfast dining" (sharp). + static const IconData breakfast_dining_sharp = IconData(0xe801, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">breakfast_dining</i> — material icon named "breakfast dining" (round). + static const IconData breakfast_dining_rounded = IconData(0xf5e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">breakfast_dining</i> — material icon named "breakfast dining" (outlined). + static const IconData breakfast_dining_outlined = IconData(0xeef3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_1</i> — material icon named "brightness 1". + static const IconData brightness_1 = IconData(0xe105, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_1</i> — material icon named "brightness 1" (sharp). + static const IconData brightness_1_sharp = IconData(0xe802, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_1</i> — material icon named "brightness 1" (round). + static const IconData brightness_1_rounded = IconData(0xf5e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_1</i> — material icon named "brightness 1" (outlined). + static const IconData brightness_1_outlined = IconData(0xeef4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_2</i> — material icon named "brightness 2". + static const IconData brightness_2 = IconData(0xe106, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_2</i> — material icon named "brightness 2" (sharp). + static const IconData brightness_2_sharp = IconData(0xe803, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_2</i> — material icon named "brightness 2" (round). + static const IconData brightness_2_rounded = IconData(0xf5e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_2</i> — material icon named "brightness 2" (outlined). + static const IconData brightness_2_outlined = IconData(0xeef5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_3</i> — material icon named "brightness 3". + static const IconData brightness_3 = IconData(0xe107, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_3</i> — material icon named "brightness 3" (sharp). + static const IconData brightness_3_sharp = IconData(0xe804, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_3</i> — material icon named "brightness 3" (round). + static const IconData brightness_3_rounded = IconData(0xf5e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_3</i> — material icon named "brightness 3" (outlined). + static const IconData brightness_3_outlined = IconData(0xeef6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_4</i> — material icon named "brightness 4". + static const IconData brightness_4 = IconData(0xe108, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_4</i> — material icon named "brightness 4" (sharp). + static const IconData brightness_4_sharp = IconData(0xe805, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_4</i> — material icon named "brightness 4" (round). + static const IconData brightness_4_rounded = IconData(0xf5e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_4</i> — material icon named "brightness 4" (outlined). + static const IconData brightness_4_outlined = IconData(0xeef7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_5</i> — material icon named "brightness 5". + static const IconData brightness_5 = IconData(0xe109, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_5</i> — material icon named "brightness 5" (sharp). + static const IconData brightness_5_sharp = IconData(0xe806, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_5</i> — material icon named "brightness 5" (round). + static const IconData brightness_5_rounded = IconData(0xf5e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_5</i> — material icon named "brightness 5" (outlined). + static const IconData brightness_5_outlined = IconData(0xeef8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_6</i> — material icon named "brightness 6". + static const IconData brightness_6 = IconData(0xe10a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_6</i> — material icon named "brightness 6" (sharp). + static const IconData brightness_6_sharp = IconData(0xe807, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_6</i> — material icon named "brightness 6" (round). + static const IconData brightness_6_rounded = IconData(0xf5e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_6</i> — material icon named "brightness 6" (outlined). + static const IconData brightness_6_outlined = IconData(0xeef9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_7</i> — material icon named "brightness 7". + static const IconData brightness_7 = IconData(0xe10b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_7</i> — material icon named "brightness 7" (sharp). + static const IconData brightness_7_sharp = IconData(0xe808, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_7</i> — material icon named "brightness 7" (round). + static const IconData brightness_7_rounded = IconData(0xf5e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_7</i> — material icon named "brightness 7" (outlined). + static const IconData brightness_7_outlined = IconData(0xeefa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_auto</i> — material icon named "brightness auto". + static const IconData brightness_auto = IconData(0xe10c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_auto</i> — material icon named "brightness auto" (sharp). + static const IconData brightness_auto_sharp = IconData(0xe809, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_auto</i> — material icon named "brightness auto" (round). + static const IconData brightness_auto_rounded = IconData(0xf5e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_auto</i> — material icon named "brightness auto" (outlined). + static const IconData brightness_auto_outlined = IconData(0xeefb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_high</i> — material icon named "brightness high". + static const IconData brightness_high = IconData(0xe10d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_high</i> — material icon named "brightness high" (sharp). + static const IconData brightness_high_sharp = IconData(0xe80a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_high</i> — material icon named "brightness high" (round). + static const IconData brightness_high_rounded = IconData(0xf5e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_high</i> — material icon named "brightness high" (outlined). + static const IconData brightness_high_outlined = IconData(0xeefc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_low</i> — material icon named "brightness low". + static const IconData brightness_low = IconData(0xe10e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_low</i> — material icon named "brightness low" (sharp). + static const IconData brightness_low_sharp = IconData(0xe80b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_low</i> — material icon named "brightness low" (round). + static const IconData brightness_low_rounded = IconData(0xf5ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_low</i> — material icon named "brightness low" (outlined). + static const IconData brightness_low_outlined = IconData(0xeefd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brightness_medium</i> — material icon named "brightness medium". + static const IconData brightness_medium = IconData(0xe10f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brightness_medium</i> — material icon named "brightness medium" (sharp). + static const IconData brightness_medium_sharp = IconData(0xe80c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brightness_medium</i> — material icon named "brightness medium" (round). + static const IconData brightness_medium_rounded = IconData(0xf5eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brightness_medium</i> — material icon named "brightness medium" (outlined). + static const IconData brightness_medium_outlined = IconData(0xeefe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">broadcast_on_home</i> — material icon named "broadcast on home". + static const IconData broadcast_on_home = IconData(0xf0791, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">broadcast_on_home</i> — material icon named "broadcast on home" (sharp). + static const IconData broadcast_on_home_sharp = IconData(0xf0739, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">broadcast_on_home</i> — material icon named "broadcast on home" (round). + static const IconData broadcast_on_home_rounded = IconData(0xf07e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">broadcast_on_home</i> — material icon named "broadcast on home" (outlined). + static const IconData broadcast_on_home_outlined = IconData(0xf06e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">broadcast_on_personal</i> — material icon named "broadcast on personal". + static const IconData broadcast_on_personal = IconData(0xf0792, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">broadcast_on_personal</i> — material icon named "broadcast on personal" (sharp). + static const IconData broadcast_on_personal_sharp = IconData(0xf073a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">broadcast_on_personal</i> — material icon named "broadcast on personal" (round). + static const IconData broadcast_on_personal_rounded = IconData(0xf07ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">broadcast_on_personal</i> — material icon named "broadcast on personal" (outlined). + static const IconData broadcast_on_personal_outlined = IconData(0xf06e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">broken_image</i> — material icon named "broken image". + static const IconData broken_image = IconData(0xe110, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">broken_image</i> — material icon named "broken image" (sharp). + static const IconData broken_image_sharp = IconData(0xe80d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">broken_image</i> — material icon named "broken image" (round). + static const IconData broken_image_rounded = IconData(0xf5ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">broken_image</i> — material icon named "broken image" (outlined). + static const IconData broken_image_outlined = IconData(0xeeff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">browse_gallery</i> — material icon named "browse gallery". + static const IconData browse_gallery = IconData(0xf06ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">browse_gallery</i> — material icon named "browse gallery" (sharp). + static const IconData browse_gallery_sharp = IconData(0xf06ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">browse_gallery</i> — material icon named "browse gallery" (round). + static const IconData browse_gallery_rounded = IconData(0xf06c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">browse_gallery</i> — material icon named "browse gallery" (outlined). + static const IconData browse_gallery_outlined = IconData(0xf03bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">browser_not_supported</i> — material icon named "browser not supported". + static const IconData browser_not_supported = IconData(0xe111, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">browser_not_supported</i> — material icon named "browser not supported" (sharp). + static const IconData browser_not_supported_sharp = IconData(0xe80e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">browser_not_supported</i> — material icon named "browser not supported" (round). + static const IconData browser_not_supported_rounded = IconData(0xf5ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">browser_not_supported</i> — material icon named "browser not supported" (outlined). + static const IconData browser_not_supported_outlined = IconData(0xef00, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">browser_updated</i> — material icon named "browser updated". + static const IconData browser_updated = IconData(0xf04c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">browser_updated</i> — material icon named "browser updated" (sharp). + static const IconData browser_updated_sharp = IconData(0xf03d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">browser_updated</i> — material icon named "browser updated" (round). + static const IconData browser_updated_rounded = IconData(0xf02e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">browser_updated</i> — material icon named "browser updated" (outlined). + static const IconData browser_updated_outlined = IconData(0xf05c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brunch_dining</i> — material icon named "brunch dining". + static const IconData brunch_dining = IconData(0xe112, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brunch_dining</i> — material icon named "brunch dining" (sharp). + static const IconData brunch_dining_sharp = IconData(0xe80f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brunch_dining</i> — material icon named "brunch dining" (round). + static const IconData brunch_dining_rounded = IconData(0xf5ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brunch_dining</i> — material icon named "brunch dining" (outlined). + static const IconData brunch_dining_outlined = IconData(0xef01, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">brush</i> — material icon named "brush". + static const IconData brush = IconData(0xe113, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">brush</i> — material icon named "brush" (sharp). + static const IconData brush_sharp = IconData(0xe810, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">brush</i> — material icon named "brush" (round). + static const IconData brush_rounded = IconData(0xf5ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">brush</i> — material icon named "brush" (outlined). + static const IconData brush_outlined = IconData(0xef02, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bubble_chart</i> — material icon named "bubble chart". + static const IconData bubble_chart = IconData(0xe114, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bubble_chart</i> — material icon named "bubble chart" (sharp). + static const IconData bubble_chart_sharp = IconData(0xe811, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bubble_chart</i> — material icon named "bubble chart" (round). + static const IconData bubble_chart_rounded = IconData(0xf5f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bubble_chart</i> — material icon named "bubble chart" (outlined). + static const IconData bubble_chart_outlined = IconData(0xef03, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bug_report</i> — material icon named "bug report". + static const IconData bug_report = IconData(0xe115, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bug_report</i> — material icon named "bug report" (sharp). + static const IconData bug_report_sharp = IconData(0xe812, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bug_report</i> — material icon named "bug report" (round). + static const IconData bug_report_rounded = IconData(0xf5f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bug_report</i> — material icon named "bug report" (outlined). + static const IconData bug_report_outlined = IconData(0xef04, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">build</i> — material icon named "build". + static const IconData build = IconData(0xe116, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">build</i> — material icon named "build" (sharp). + static const IconData build_sharp = IconData(0xe814, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">build</i> — material icon named "build" (round). + static const IconData build_rounded = IconData(0xf5f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">build</i> — material icon named "build" (outlined). + static const IconData build_outlined = IconData(0xef06, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">build_circle</i> — material icon named "build circle". + static const IconData build_circle = IconData(0xe117, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">build_circle</i> — material icon named "build circle" (sharp). + static const IconData build_circle_sharp = IconData(0xe813, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">build_circle</i> — material icon named "build circle" (round). + static const IconData build_circle_rounded = IconData(0xf5f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">build_circle</i> — material icon named "build circle" (outlined). + static const IconData build_circle_outlined = IconData(0xef05, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bungalow</i> — material icon named "bungalow". + static const IconData bungalow = IconData(0xe118, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bungalow</i> — material icon named "bungalow" (sharp). + static const IconData bungalow_sharp = IconData(0xe815, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bungalow</i> — material icon named "bungalow" (round). + static const IconData bungalow_rounded = IconData(0xf5f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bungalow</i> — material icon named "bungalow" (outlined). + static const IconData bungalow_outlined = IconData(0xef07, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">burst_mode</i> — material icon named "burst mode". + static const IconData burst_mode = IconData(0xe119, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">burst_mode</i> — material icon named "burst mode" (sharp). + static const IconData burst_mode_sharp = IconData(0xe816, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">burst_mode</i> — material icon named "burst mode" (round). + static const IconData burst_mode_rounded = IconData(0xf5f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">burst_mode</i> — material icon named "burst mode" (outlined). + static const IconData burst_mode_outlined = IconData(0xef08, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">bus_alert</i> — material icon named "bus alert". + static const IconData bus_alert = IconData(0xe11a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">bus_alert</i> — material icon named "bus alert" (sharp). + static const IconData bus_alert_sharp = IconData(0xe817, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">bus_alert</i> — material icon named "bus alert" (round). + static const IconData bus_alert_rounded = IconData(0xf5f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">bus_alert</i> — material icon named "bus alert" (outlined). + static const IconData bus_alert_outlined = IconData(0xef09, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">business</i> — material icon named "business". + static const IconData business = IconData(0xe11b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">business</i> — material icon named "business" (sharp). + static const IconData business_sharp = IconData(0xe819, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">business</i> — material icon named "business" (round). + static const IconData business_rounded = IconData(0xf5f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">business</i> — material icon named "business" (outlined). + static const IconData business_outlined = IconData(0xef0b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">business_center</i> — material icon named "business center". + static const IconData business_center = IconData(0xe11c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">business_center</i> — material icon named "business center" (sharp). + static const IconData business_center_sharp = IconData(0xe818, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">business_center</i> — material icon named "business center" (round). + static const IconData business_center_rounded = IconData(0xf5f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">business_center</i> — material icon named "business center" (outlined). + static const IconData business_center_outlined = IconData(0xef0a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cabin</i> — material icon named "cabin". + static const IconData cabin = IconData(0xe11d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cabin</i> — material icon named "cabin" (sharp). + static const IconData cabin_sharp = IconData(0xe81a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cabin</i> — material icon named "cabin" (round). + static const IconData cabin_rounded = IconData(0xf5f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cabin</i> — material icon named "cabin" (outlined). + static const IconData cabin_outlined = IconData(0xef0c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cable</i> — material icon named "cable". + static const IconData cable = IconData(0xe11e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cable</i> — material icon named "cable" (sharp). + static const IconData cable_sharp = IconData(0xe81b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cable</i> — material icon named "cable" (round). + static const IconData cable_rounded = IconData(0xf5fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cable</i> — material icon named "cable" (outlined). + static const IconData cable_outlined = IconData(0xef0d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cached</i> — material icon named "cached". + static const IconData cached = IconData(0xe11f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cached</i> — material icon named "cached" (sharp). + static const IconData cached_sharp = IconData(0xe81c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cached</i> — material icon named "cached" (round). + static const IconData cached_rounded = IconData(0xf5fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cached</i> — material icon named "cached" (outlined). + static const IconData cached_outlined = IconData(0xef0e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cake</i> — material icon named "cake". + static const IconData cake = IconData(0xe120, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cake</i> — material icon named "cake" (sharp). + static const IconData cake_sharp = IconData(0xe81d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cake</i> — material icon named "cake" (round). + static const IconData cake_rounded = IconData(0xf5fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cake</i> — material icon named "cake" (outlined). + static const IconData cake_outlined = IconData(0xef0f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">calculate</i> — material icon named "calculate". + static const IconData calculate = IconData(0xe121, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">calculate</i> — material icon named "calculate" (sharp). + static const IconData calculate_sharp = IconData(0xe81e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">calculate</i> — material icon named "calculate" (round). + static const IconData calculate_rounded = IconData(0xf5fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">calculate</i> — material icon named "calculate" (outlined). + static const IconData calculate_outlined = IconData(0xef10, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">calendar_month</i> — material icon named "calendar month". + static const IconData calendar_month = IconData(0xf06bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">calendar_month</i> — material icon named "calendar month" (sharp). + static const IconData calendar_month_sharp = IconData(0xf06ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">calendar_month</i> — material icon named "calendar month" (round). + static const IconData calendar_month_rounded = IconData(0xf06c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">calendar_month</i> — material icon named "calendar month" (outlined). + static const IconData calendar_month_outlined = IconData(0xf051f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">calendar_today</i> — material icon named "calendar today". + static const IconData calendar_today = IconData(0xe122, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">calendar_today</i> — material icon named "calendar today" (sharp). + static const IconData calendar_today_sharp = IconData(0xe81f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">calendar_today</i> — material icon named "calendar today" (round). + static const IconData calendar_today_rounded = IconData(0xf5fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">calendar_today</i> — material icon named "calendar today" (outlined). + static const IconData calendar_today_outlined = IconData(0xef11, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">calendar_view_day</i> — material icon named "calendar view day". + static const IconData calendar_view_day = IconData(0xe123, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">calendar_view_day</i> — material icon named "calendar view day" (sharp). + static const IconData calendar_view_day_sharp = IconData(0xe820, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">calendar_view_day</i> — material icon named "calendar view day" (round). + static const IconData calendar_view_day_rounded = IconData(0xf5ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">calendar_view_day</i> — material icon named "calendar view day" (outlined). + static const IconData calendar_view_day_outlined = IconData(0xef12, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">calendar_view_month</i> — material icon named "calendar view month". + static const IconData calendar_view_month = IconData(0xe124, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">calendar_view_month</i> — material icon named "calendar view month" (sharp). + static const IconData calendar_view_month_sharp = IconData(0xe821, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">calendar_view_month</i> — material icon named "calendar view month" (round). + static const IconData calendar_view_month_rounded = IconData(0xf600, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">calendar_view_month</i> — material icon named "calendar view month" (outlined). + static const IconData calendar_view_month_outlined = IconData(0xef13, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">calendar_view_week</i> — material icon named "calendar view week". + static const IconData calendar_view_week = IconData(0xe125, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">calendar_view_week</i> — material icon named "calendar view week" (sharp). + static const IconData calendar_view_week_sharp = IconData(0xe822, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">calendar_view_week</i> — material icon named "calendar view week" (round). + static const IconData calendar_view_week_rounded = IconData(0xf601, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">calendar_view_week</i> — material icon named "calendar view week" (outlined). + static const IconData calendar_view_week_outlined = IconData(0xef14, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">call</i> — material icon named "call". + static const IconData call = IconData(0xe126, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">call</i> — material icon named "call" (sharp). + static const IconData call_sharp = IconData(0xe829, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">call</i> — material icon named "call" (round). + static const IconData call_rounded = IconData(0xf608, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">call</i> — material icon named "call" (outlined). + static const IconData call_outlined = IconData(0xef1a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">call_end</i> — material icon named "call end". + static const IconData call_end = IconData(0xe127, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">call_end</i> — material icon named "call end" (sharp). + static const IconData call_end_sharp = IconData(0xe823, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">call_end</i> — material icon named "call end" (round). + static const IconData call_end_rounded = IconData(0xf602, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">call_end</i> — material icon named "call end" (outlined). + static const IconData call_end_outlined = IconData(0xef15, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">call_made</i> — material icon named "call made". + static const IconData call_made = IconData(0xe128, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">call_made</i> — material icon named "call made" (sharp). + static const IconData call_made_sharp = IconData(0xe824, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">call_made</i> — material icon named "call made" (round). + static const IconData call_made_rounded = IconData(0xf603, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">call_made</i> — material icon named "call made" (outlined). + static const IconData call_made_outlined = IconData(0xef16, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">call_merge</i> — material icon named "call merge". + static const IconData call_merge = IconData(0xe129, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">call_merge</i> — material icon named "call merge" (sharp). + static const IconData call_merge_sharp = IconData(0xe825, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">call_merge</i> — material icon named "call merge" (round). + static const IconData call_merge_rounded = IconData(0xf604, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">call_merge</i> — material icon named "call merge" (outlined). + static const IconData call_merge_outlined = IconData(0xef17, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">call_missed</i> — material icon named "call missed". + static const IconData call_missed = IconData(0xe12a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">call_missed</i> — material icon named "call missed" (sharp). + static const IconData call_missed_sharp = IconData(0xe827, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">call_missed</i> — material icon named "call missed" (round). + static const IconData call_missed_rounded = IconData(0xf606, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">call_missed</i> — material icon named "call missed" (outlined). + static const IconData call_missed_outlined = IconData(0xef19, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">call_missed_outgoing</i> — material icon named "call missed outgoing". + static const IconData call_missed_outgoing = IconData(0xe12b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">call_missed_outgoing</i> — material icon named "call missed outgoing" (sharp). + static const IconData call_missed_outgoing_sharp = IconData(0xe826, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">call_missed_outgoing</i> — material icon named "call missed outgoing" (round). + static const IconData call_missed_outgoing_rounded = IconData(0xf605, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">call_missed_outgoing</i> — material icon named "call missed outgoing" (outlined). + static const IconData call_missed_outgoing_outlined = IconData(0xef18, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">call_received</i> — material icon named "call received". + static const IconData call_received = IconData(0xe12c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">call_received</i> — material icon named "call received" (sharp). + static const IconData call_received_sharp = IconData(0xe828, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">call_received</i> — material icon named "call received" (round). + static const IconData call_received_rounded = IconData(0xf607, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">call_received</i> — material icon named "call received" (outlined). + static const IconData call_received_outlined = IconData(0xef1b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">call_split</i> — material icon named "call split". + static const IconData call_split = IconData(0xe12d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">call_split</i> — material icon named "call split" (sharp). + static const IconData call_split_sharp = IconData(0xe82a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">call_split</i> — material icon named "call split" (round). + static const IconData call_split_rounded = IconData(0xf609, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">call_split</i> — material icon named "call split" (outlined). + static const IconData call_split_outlined = IconData(0xef1c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">call_to_action</i> — material icon named "call to action". + static const IconData call_to_action = IconData(0xe12e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">call_to_action</i> — material icon named "call to action" (sharp). + static const IconData call_to_action_sharp = IconData(0xe82b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">call_to_action</i> — material icon named "call to action" (round). + static const IconData call_to_action_rounded = IconData(0xf60a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">call_to_action</i> — material icon named "call to action" (outlined). + static const IconData call_to_action_outlined = IconData(0xef1d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">camera</i> — material icon named "camera". + static const IconData camera = IconData(0xe12f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">camera</i> — material icon named "camera" (sharp). + static const IconData camera_sharp = IconData(0xe833, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">camera</i> — material icon named "camera" (round). + static const IconData camera_rounded = IconData(0xf612, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">camera</i> — material icon named "camera" (outlined). + static const IconData camera_outlined = IconData(0xef23, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">camera_alt</i> — material icon named "camera alt". + static const IconData camera_alt = IconData(0xe130, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">camera_alt</i> — material icon named "camera alt" (sharp). + static const IconData camera_alt_sharp = IconData(0xe82c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">camera_alt</i> — material icon named "camera alt" (round). + static const IconData camera_alt_rounded = IconData(0xf60b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">camera_alt</i> — material icon named "camera alt" (outlined). + static const IconData camera_alt_outlined = IconData(0xef1e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">camera_enhance</i> — material icon named "camera enhance". + static const IconData camera_enhance = IconData(0xe131, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">camera_enhance</i> — material icon named "camera enhance" (sharp). + static const IconData camera_enhance_sharp = IconData(0xe82d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">camera_enhance</i> — material icon named "camera enhance" (round). + static const IconData camera_enhance_rounded = IconData(0xf60c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">camera_enhance</i> — material icon named "camera enhance" (outlined). + static const IconData camera_enhance_outlined = IconData(0xef1f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">camera_front</i> — material icon named "camera front". + static const IconData camera_front = IconData(0xe132, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">camera_front</i> — material icon named "camera front" (sharp). + static const IconData camera_front_sharp = IconData(0xe82e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">camera_front</i> — material icon named "camera front" (round). + static const IconData camera_front_rounded = IconData(0xf60d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">camera_front</i> — material icon named "camera front" (outlined). + static const IconData camera_front_outlined = IconData(0xef20, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">camera_indoor</i> — material icon named "camera indoor". + static const IconData camera_indoor = IconData(0xe133, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">camera_indoor</i> — material icon named "camera indoor" (sharp). + static const IconData camera_indoor_sharp = IconData(0xe82f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">camera_indoor</i> — material icon named "camera indoor" (round). + static const IconData camera_indoor_rounded = IconData(0xf60e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">camera_indoor</i> — material icon named "camera indoor" (outlined). + static const IconData camera_indoor_outlined = IconData(0xef21, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">camera_outdoor</i> — material icon named "camera outdoor". + static const IconData camera_outdoor = IconData(0xe134, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">camera_outdoor</i> — material icon named "camera outdoor" (sharp). + static const IconData camera_outdoor_sharp = IconData(0xe830, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">camera_outdoor</i> — material icon named "camera outdoor" (round). + static const IconData camera_outdoor_rounded = IconData(0xf60f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">camera_outdoor</i> — material icon named "camera outdoor" (outlined). + static const IconData camera_outdoor_outlined = IconData(0xef22, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">camera_rear</i> — material icon named "camera rear". + static const IconData camera_rear = IconData(0xe135, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">camera_rear</i> — material icon named "camera rear" (sharp). + static const IconData camera_rear_sharp = IconData(0xe831, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">camera_rear</i> — material icon named "camera rear" (round). + static const IconData camera_rear_rounded = IconData(0xf610, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">camera_rear</i> — material icon named "camera rear" (outlined). + static const IconData camera_rear_outlined = IconData(0xef24, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">camera_roll</i> — material icon named "camera roll". + static const IconData camera_roll = IconData(0xe136, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">camera_roll</i> — material icon named "camera roll" (sharp). + static const IconData camera_roll_sharp = IconData(0xe832, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">camera_roll</i> — material icon named "camera roll" (round). + static const IconData camera_roll_rounded = IconData(0xf611, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">camera_roll</i> — material icon named "camera roll" (outlined). + static const IconData camera_roll_outlined = IconData(0xef25, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cameraswitch</i> — material icon named "cameraswitch". + static const IconData cameraswitch = IconData(0xe137, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cameraswitch</i> — material icon named "cameraswitch" (sharp). + static const IconData cameraswitch_sharp = IconData(0xe834, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cameraswitch</i> — material icon named "cameraswitch" (round). + static const IconData cameraswitch_rounded = IconData(0xf613, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cameraswitch</i> — material icon named "cameraswitch" (outlined). + static const IconData cameraswitch_outlined = IconData(0xef26, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">campaign</i> — material icon named "campaign". + static const IconData campaign = IconData(0xe138, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">campaign</i> — material icon named "campaign" (sharp). + static const IconData campaign_sharp = IconData(0xe835, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">campaign</i> — material icon named "campaign" (round). + static const IconData campaign_rounded = IconData(0xf614, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">campaign</i> — material icon named "campaign" (outlined). + static const IconData campaign_outlined = IconData(0xef27, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cancel</i> — material icon named "cancel". + static const IconData cancel = IconData(0xe139, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cancel</i> — material icon named "cancel" (sharp). + static const IconData cancel_sharp = IconData(0xe838, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cancel</i> — material icon named "cancel" (round). + static const IconData cancel_rounded = IconData(0xf616, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cancel</i> — material icon named "cancel" (outlined). + static const IconData cancel_outlined = IconData(0xef28, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cancel_presentation</i> — material icon named "cancel presentation". + static const IconData cancel_presentation = IconData(0xe13a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cancel_presentation</i> — material icon named "cancel presentation" (sharp). + static const IconData cancel_presentation_sharp = IconData(0xe836, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cancel_presentation</i> — material icon named "cancel presentation" (round). + static const IconData cancel_presentation_rounded = IconData(0xf615, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cancel_presentation</i> — material icon named "cancel presentation" (outlined). + static const IconData cancel_presentation_outlined = IconData(0xef29, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cancel_schedule_send</i> — material icon named "cancel schedule send". + static const IconData cancel_schedule_send = IconData(0xe13b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cancel_schedule_send</i> — material icon named "cancel schedule send" (sharp). + static const IconData cancel_schedule_send_sharp = IconData(0xe837, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cancel_schedule_send</i> — material icon named "cancel schedule send" (round). + static const IconData cancel_schedule_send_rounded = IconData(0xf617, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cancel_schedule_send</i> — material icon named "cancel schedule send" (outlined). + static const IconData cancel_schedule_send_outlined = IconData(0xef2a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">candlestick_chart</i> — material icon named "candlestick chart". + static const IconData candlestick_chart = IconData(0xf04ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">candlestick_chart</i> — material icon named "candlestick chart" (sharp). + static const IconData candlestick_chart_sharp = IconData(0xf03d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">candlestick_chart</i> — material icon named "candlestick chart" (round). + static const IconData candlestick_chart_rounded = IconData(0xf02e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">candlestick_chart</i> — material icon named "candlestick chart" (outlined). + static const IconData candlestick_chart_outlined = IconData(0xf05c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">car_crash</i> — material icon named "car crash". + static const IconData car_crash = IconData(0xf0793, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">car_crash</i> — material icon named "car crash" (sharp). + static const IconData car_crash_sharp = IconData(0xf073b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">car_crash</i> — material icon named "car crash" (round). + static const IconData car_crash_rounded = IconData(0xf07eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">car_crash</i> — material icon named "car crash" (outlined). + static const IconData car_crash_outlined = IconData(0xf06e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">car_rental</i> — material icon named "car rental". + static const IconData car_rental = IconData(0xe13c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">car_rental</i> — material icon named "car rental" (sharp). + static const IconData car_rental_sharp = IconData(0xe839, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">car_rental</i> — material icon named "car rental" (round). + static const IconData car_rental_rounded = IconData(0xf618, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">car_rental</i> — material icon named "car rental" (outlined). + static const IconData car_rental_outlined = IconData(0xef2b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">car_repair</i> — material icon named "car repair". + static const IconData car_repair = IconData(0xe13d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">car_repair</i> — material icon named "car repair" (sharp). + static const IconData car_repair_sharp = IconData(0xe83a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">car_repair</i> — material icon named "car repair" (round). + static const IconData car_repair_rounded = IconData(0xf619, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">car_repair</i> — material icon named "car repair" (outlined). + static const IconData car_repair_outlined = IconData(0xef2c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">card_giftcard</i> — material icon named "card giftcard". + static const IconData card_giftcard = IconData(0xe13e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">card_giftcard</i> — material icon named "card giftcard" (sharp). + static const IconData card_giftcard_sharp = IconData(0xe83b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">card_giftcard</i> — material icon named "card giftcard" (round). + static const IconData card_giftcard_rounded = IconData(0xf61a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">card_giftcard</i> — material icon named "card giftcard" (outlined). + static const IconData card_giftcard_outlined = IconData(0xef2d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">card_membership</i> — material icon named "card membership". + static const IconData card_membership = IconData(0xe13f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">card_membership</i> — material icon named "card membership" (sharp). + static const IconData card_membership_sharp = IconData(0xe83c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">card_membership</i> — material icon named "card membership" (round). + static const IconData card_membership_rounded = IconData(0xf61b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">card_membership</i> — material icon named "card membership" (outlined). + static const IconData card_membership_outlined = IconData(0xef2e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">card_travel</i> — material icon named "card travel". + static const IconData card_travel = IconData(0xe140, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">card_travel</i> — material icon named "card travel" (sharp). + static const IconData card_travel_sharp = IconData(0xe83d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">card_travel</i> — material icon named "card travel" (round). + static const IconData card_travel_rounded = IconData(0xf61c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">card_travel</i> — material icon named "card travel" (outlined). + static const IconData card_travel_outlined = IconData(0xef2f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">carpenter</i> — material icon named "carpenter". + static const IconData carpenter = IconData(0xe141, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">carpenter</i> — material icon named "carpenter" (sharp). + static const IconData carpenter_sharp = IconData(0xe83e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">carpenter</i> — material icon named "carpenter" (round). + static const IconData carpenter_rounded = IconData(0xf61d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">carpenter</i> — material icon named "carpenter" (outlined). + static const IconData carpenter_outlined = IconData(0xef30, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cases</i> — material icon named "cases". + static const IconData cases = IconData(0xe142, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cases</i> — material icon named "cases" (sharp). + static const IconData cases_sharp = IconData(0xe83f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cases</i> — material icon named "cases" (round). + static const IconData cases_rounded = IconData(0xf61e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cases</i> — material icon named "cases" (outlined). + static const IconData cases_outlined = IconData(0xef31, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">casino</i> — material icon named "casino". + static const IconData casino = IconData(0xe143, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">casino</i> — material icon named "casino" (sharp). + static const IconData casino_sharp = IconData(0xe840, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">casino</i> — material icon named "casino" (round). + static const IconData casino_rounded = IconData(0xf61f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">casino</i> — material icon named "casino" (outlined). + static const IconData casino_outlined = IconData(0xef32, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cast</i> — material icon named "cast". + static const IconData cast = IconData(0xe144, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cast</i> — material icon named "cast" (sharp). + static const IconData cast_sharp = IconData(0xe843, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cast</i> — material icon named "cast" (round). + static const IconData cast_rounded = IconData(0xf622, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cast</i> — material icon named "cast" (outlined). + static const IconData cast_outlined = IconData(0xef35, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cast_connected</i> — material icon named "cast connected". + static const IconData cast_connected = IconData(0xe145, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cast_connected</i> — material icon named "cast connected" (sharp). + static const IconData cast_connected_sharp = IconData(0xe841, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cast_connected</i> — material icon named "cast connected" (round). + static const IconData cast_connected_rounded = IconData(0xf620, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cast_connected</i> — material icon named "cast connected" (outlined). + static const IconData cast_connected_outlined = IconData(0xef33, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cast_for_education</i> — material icon named "cast for education". + static const IconData cast_for_education = IconData(0xe146, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cast_for_education</i> — material icon named "cast for education" (sharp). + static const IconData cast_for_education_sharp = IconData(0xe842, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cast_for_education</i> — material icon named "cast for education" (round). + static const IconData cast_for_education_rounded = IconData(0xf621, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cast_for_education</i> — material icon named "cast for education" (outlined). + static const IconData cast_for_education_outlined = IconData(0xef34, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">castle</i> — material icon named "castle". + static const IconData castle = IconData(0xf04cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">castle</i> — material icon named "castle" (sharp). + static const IconData castle_sharp = IconData(0xf03d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">castle</i> — material icon named "castle" (round). + static const IconData castle_rounded = IconData(0xf02e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">castle</i> — material icon named "castle" (outlined). + static const IconData castle_outlined = IconData(0xf05c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">catching_pokemon</i> — material icon named "catching pokemon". + static const IconData catching_pokemon = IconData(0xe147, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">catching_pokemon</i> — material icon named "catching pokemon" (sharp). + static const IconData catching_pokemon_sharp = IconData(0xe844, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">catching_pokemon</i> — material icon named "catching pokemon" (round). + static const IconData catching_pokemon_rounded = IconData(0xf623, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">catching_pokemon</i> — material icon named "catching pokemon" (outlined). + static const IconData catching_pokemon_outlined = IconData(0xef36, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">category</i> — material icon named "category". + static const IconData category = IconData(0xe148, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">category</i> — material icon named "category" (sharp). + static const IconData category_sharp = IconData(0xe845, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">category</i> — material icon named "category" (round). + static const IconData category_rounded = IconData(0xf624, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">category</i> — material icon named "category" (outlined). + static const IconData category_outlined = IconData(0xef37, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">celebration</i> — material icon named "celebration". + static const IconData celebration = IconData(0xe149, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">celebration</i> — material icon named "celebration" (sharp). + static const IconData celebration_sharp = IconData(0xe846, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">celebration</i> — material icon named "celebration" (round). + static const IconData celebration_rounded = IconData(0xf625, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">celebration</i> — material icon named "celebration" (outlined). + static const IconData celebration_outlined = IconData(0xef38, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cell_tower</i> — material icon named "cell tower". + static const IconData cell_tower = IconData(0xf04cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cell_tower</i> — material icon named "cell tower" (sharp). + static const IconData cell_tower_sharp = IconData(0xf03d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cell_tower</i> — material icon named "cell tower" (round). + static const IconData cell_tower_rounded = IconData(0xf02e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cell_tower</i> — material icon named "cell tower" (outlined). + static const IconData cell_tower_outlined = IconData(0xf05c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cell_wifi</i> — material icon named "cell wifi". + static const IconData cell_wifi = IconData(0xe14a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cell_wifi</i> — material icon named "cell wifi" (sharp). + static const IconData cell_wifi_sharp = IconData(0xe847, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cell_wifi</i> — material icon named "cell wifi" (round). + static const IconData cell_wifi_rounded = IconData(0xf626, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cell_wifi</i> — material icon named "cell wifi" (outlined). + static const IconData cell_wifi_outlined = IconData(0xef39, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">center_focus_strong</i> — material icon named "center focus strong". + static const IconData center_focus_strong = IconData(0xe14b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">center_focus_strong</i> — material icon named "center focus strong" (sharp). + static const IconData center_focus_strong_sharp = IconData(0xe848, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">center_focus_strong</i> — material icon named "center focus strong" (round). + static const IconData center_focus_strong_rounded = IconData(0xf627, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">center_focus_strong</i> — material icon named "center focus strong" (outlined). + static const IconData center_focus_strong_outlined = IconData(0xef3a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">center_focus_weak</i> — material icon named "center focus weak". + static const IconData center_focus_weak = IconData(0xe14c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">center_focus_weak</i> — material icon named "center focus weak" (sharp). + static const IconData center_focus_weak_sharp = IconData(0xe849, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">center_focus_weak</i> — material icon named "center focus weak" (round). + static const IconData center_focus_weak_rounded = IconData(0xf628, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">center_focus_weak</i> — material icon named "center focus weak" (outlined). + static const IconData center_focus_weak_outlined = IconData(0xef3b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">chair</i> — material icon named "chair". + static const IconData chair = IconData(0xe14d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">chair</i> — material icon named "chair" (sharp). + static const IconData chair_sharp = IconData(0xe84b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">chair</i> — material icon named "chair" (round). + static const IconData chair_rounded = IconData(0xf62a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">chair</i> — material icon named "chair" (outlined). + static const IconData chair_outlined = IconData(0xef3d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">chair_alt</i> — material icon named "chair alt". + static const IconData chair_alt = IconData(0xe14e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">chair_alt</i> — material icon named "chair alt" (sharp). + static const IconData chair_alt_sharp = IconData(0xe84a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">chair_alt</i> — material icon named "chair alt" (round). + static const IconData chair_alt_rounded = IconData(0xf629, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">chair_alt</i> — material icon named "chair alt" (outlined). + static const IconData chair_alt_outlined = IconData(0xef3c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">chalet</i> — material icon named "chalet". + static const IconData chalet = IconData(0xe14f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">chalet</i> — material icon named "chalet" (sharp). + static const IconData chalet_sharp = IconData(0xe84c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">chalet</i> — material icon named "chalet" (round). + static const IconData chalet_rounded = IconData(0xf62b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">chalet</i> — material icon named "chalet" (outlined). + static const IconData chalet_outlined = IconData(0xef3e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">change_circle</i> — material icon named "change circle". + static const IconData change_circle = IconData(0xe150, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">change_circle</i> — material icon named "change circle" (sharp). + static const IconData change_circle_sharp = IconData(0xe84d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">change_circle</i> — material icon named "change circle" (round). + static const IconData change_circle_rounded = IconData(0xf62c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">change_circle</i> — material icon named "change circle" (outlined). + static const IconData change_circle_outlined = IconData(0xef3f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">change_history</i> — material icon named "change history". + static const IconData change_history = IconData(0xe151, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">change_history</i> — material icon named "change history" (sharp). + static const IconData change_history_sharp = IconData(0xe84e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">change_history</i> — material icon named "change history" (round). + static const IconData change_history_rounded = IconData(0xf62d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">change_history</i> — material icon named "change history" (outlined). + static const IconData change_history_outlined = IconData(0xef40, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">charging_station</i> — material icon named "charging station". + static const IconData charging_station = IconData(0xe152, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">charging_station</i> — material icon named "charging station" (sharp). + static const IconData charging_station_sharp = IconData(0xe84f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">charging_station</i> — material icon named "charging station" (round). + static const IconData charging_station_rounded = IconData(0xf62e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">charging_station</i> — material icon named "charging station" (outlined). + static const IconData charging_station_outlined = IconData(0xef41, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">chat</i> — material icon named "chat". + static const IconData chat = IconData(0xe153, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">chat</i> — material icon named "chat" (sharp). + static const IconData chat_sharp = IconData(0xe852, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">chat</i> — material icon named "chat" (round). + static const IconData chat_rounded = IconData(0xf631, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">chat</i> — material icon named "chat" (outlined). + static const IconData chat_outlined = IconData(0xef44, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">chat_bubble</i> — material icon named "chat bubble". + static const IconData chat_bubble = IconData(0xe154, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">chat_bubble</i> — material icon named "chat bubble" (sharp). + static const IconData chat_bubble_sharp = IconData(0xe851, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">chat_bubble</i> — material icon named "chat bubble" (round). + static const IconData chat_bubble_rounded = IconData(0xf630, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">chat_bubble</i> — material icon named "chat bubble" (outlined). + static const IconData chat_bubble_outlined = IconData(0xef43, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">chat_bubble_outline</i> — material icon named "chat bubble outline". + static const IconData chat_bubble_outline = IconData(0xe155, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">chat_bubble_outline</i> — material icon named "chat bubble outline" (sharp). + static const IconData chat_bubble_outline_sharp = IconData(0xe850, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">chat_bubble_outline</i> — material icon named "chat bubble outline" (round). + static const IconData chat_bubble_outline_rounded = IconData(0xf62f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">chat_bubble_outline</i> — material icon named "chat bubble outline" (outlined). + static const IconData chat_bubble_outline_outlined = IconData(0xef42, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">check</i> — material icon named "check". + static const IconData check = IconData(0xe156, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">check</i> — material icon named "check" (sharp). + static const IconData check_sharp = IconData(0xe857, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">check</i> — material icon named "check" (round). + static const IconData check_rounded = IconData(0xf636, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">check</i> — material icon named "check" (outlined). + static const IconData check_outlined = IconData(0xef49, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">check_box</i> — material icon named "check box". + static const IconData check_box = IconData(0xe157, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">check_box</i> — material icon named "check box" (sharp). + static const IconData check_box_sharp = IconData(0xe854, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">check_box</i> — material icon named "check box" (round). + static const IconData check_box_rounded = IconData(0xf633, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">check_box</i> — material icon named "check box" (outlined). + static const IconData check_box_outlined = IconData(0xef46, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">check_box_outline_blank</i> — material icon named "check box outline blank". + static const IconData check_box_outline_blank = IconData(0xe158, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">check_box_outline_blank</i> — material icon named "check box outline blank" (sharp). + static const IconData check_box_outline_blank_sharp = IconData(0xe853, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">check_box_outline_blank</i> — material icon named "check box outline blank" (round). + static const IconData check_box_outline_blank_rounded = IconData(0xf632, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">check_box_outline_blank</i> — material icon named "check box outline blank" (outlined). + static const IconData check_box_outline_blank_outlined = IconData(0xef45, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">check_circle</i> — material icon named "check circle". + static const IconData check_circle = IconData(0xe159, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">check_circle</i> — material icon named "check circle" (sharp). + static const IconData check_circle_sharp = IconData(0xe856, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">check_circle</i> — material icon named "check circle" (round). + static const IconData check_circle_rounded = IconData(0xf635, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">check_circle</i> — material icon named "check circle" (outlined). + static const IconData check_circle_outlined = IconData(0xef48, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">check_circle_outline</i> — material icon named "check circle outline". + static const IconData check_circle_outline = IconData(0xe15a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">check_circle_outline</i> — material icon named "check circle outline" (sharp). + static const IconData check_circle_outline_sharp = IconData(0xe855, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">check_circle_outline</i> — material icon named "check circle outline" (round). + static const IconData check_circle_outline_rounded = IconData(0xf634, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">check_circle_outline</i> — material icon named "check circle outline" (outlined). + static const IconData check_circle_outline_outlined = IconData(0xef47, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">checklist</i> — material icon named "checklist". + static const IconData checklist = IconData(0xe15b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">checklist</i> — material icon named "checklist" (sharp). + static const IconData checklist_sharp = IconData(0xe859, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">checklist</i> — material icon named "checklist" (round). + static const IconData checklist_rounded = IconData(0xf637, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">checklist</i> — material icon named "checklist" (outlined). + static const IconData checklist_outlined = IconData(0xef4a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">checklist_rtl</i> — material icon named "checklist rtl". + static const IconData checklist_rtl = IconData(0xe15c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">checklist_rtl</i> — material icon named "checklist rtl" (sharp). + static const IconData checklist_rtl_sharp = IconData(0xe858, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">checklist_rtl</i> — material icon named "checklist rtl" (round). + static const IconData checklist_rtl_rounded = IconData(0xf638, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">checklist_rtl</i> — material icon named "checklist rtl" (outlined). + static const IconData checklist_rtl_outlined = IconData(0xef4b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">checkroom</i> — material icon named "checkroom". + static const IconData checkroom = IconData(0xe15d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">checkroom</i> — material icon named "checkroom" (sharp). + static const IconData checkroom_sharp = IconData(0xe85a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">checkroom</i> — material icon named "checkroom" (round). + static const IconData checkroom_rounded = IconData(0xf639, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">checkroom</i> — material icon named "checkroom" (outlined). + static const IconData checkroom_outlined = IconData(0xef4c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">chevron_left</i> — material icon named "chevron left". + static const IconData chevron_left = IconData(0xe15e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">chevron_left</i> — material icon named "chevron left" (sharp). + static const IconData chevron_left_sharp = IconData(0xe85b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">chevron_left</i> — material icon named "chevron left" (round). + static const IconData chevron_left_rounded = IconData(0xf63a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">chevron_left</i> — material icon named "chevron left" (outlined). + static const IconData chevron_left_outlined = IconData(0xef4d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">chevron_right</i> — material icon named "chevron right". + static const IconData chevron_right = IconData(0xe15f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">chevron_right</i> — material icon named "chevron right" (sharp). + static const IconData chevron_right_sharp = IconData(0xe85c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">chevron_right</i> — material icon named "chevron right" (round). + static const IconData chevron_right_rounded = IconData(0xf63b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">chevron_right</i> — material icon named "chevron right" (outlined). + static const IconData chevron_right_outlined = IconData(0xef4e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">child_care</i> — material icon named "child care". + static const IconData child_care = IconData(0xe160, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">child_care</i> — material icon named "child care" (sharp). + static const IconData child_care_sharp = IconData(0xe85d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">child_care</i> — material icon named "child care" (round). + static const IconData child_care_rounded = IconData(0xf63c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">child_care</i> — material icon named "child care" (outlined). + static const IconData child_care_outlined = IconData(0xef4f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">child_friendly</i> — material icon named "child friendly". + static const IconData child_friendly = IconData(0xe161, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">child_friendly</i> — material icon named "child friendly" (sharp). + static const IconData child_friendly_sharp = IconData(0xe85e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">child_friendly</i> — material icon named "child friendly" (round). + static const IconData child_friendly_rounded = IconData(0xf63d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">child_friendly</i> — material icon named "child friendly" (outlined). + static const IconData child_friendly_outlined = IconData(0xef50, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">chrome_reader_mode</i> — material icon named "chrome reader mode". + static const IconData chrome_reader_mode = IconData(0xe162, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">chrome_reader_mode</i> — material icon named "chrome reader mode" (sharp). + static const IconData chrome_reader_mode_sharp = IconData(0xe85f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">chrome_reader_mode</i> — material icon named "chrome reader mode" (round). + static const IconData chrome_reader_mode_rounded = IconData(0xf63e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">chrome_reader_mode</i> — material icon named "chrome reader mode" (outlined). + static const IconData chrome_reader_mode_outlined = IconData(0xef51, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">church</i> — material icon named "church". + static const IconData church = IconData(0xf04cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">church</i> — material icon named "church" (sharp). + static const IconData church_sharp = IconData(0xf03da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">church</i> — material icon named "church" (round). + static const IconData church_rounded = IconData(0xf02e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">church</i> — material icon named "church" (outlined). + static const IconData church_outlined = IconData(0xf05c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">circle</i> — material icon named "circle". + static const IconData circle = IconData(0xe163, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">circle</i> — material icon named "circle" (sharp). + static const IconData circle_sharp = IconData(0xe861, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">circle</i> — material icon named "circle" (round). + static const IconData circle_rounded = IconData(0xf640, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">circle</i> — material icon named "circle" (outlined). + static const IconData circle_outlined = IconData(0xef53, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">circle_notifications</i> — material icon named "circle notifications". + static const IconData circle_notifications = IconData(0xe164, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">circle_notifications</i> — material icon named "circle notifications" (sharp). + static const IconData circle_notifications_sharp = IconData(0xe860, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">circle_notifications</i> — material icon named "circle notifications" (round). + static const IconData circle_notifications_rounded = IconData(0xf63f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">circle_notifications</i> — material icon named "circle notifications" (outlined). + static const IconData circle_notifications_outlined = IconData(0xef52, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">class</i> — material icon named "class". + static const IconData class_ = IconData(0xe165, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">class</i> — material icon named "class" (sharp). + static const IconData class_sharp = IconData(0xe862, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">class</i> — material icon named "class" (round). + static const IconData class_rounded = IconData(0xf641, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">class</i> — material icon named "class" (outlined). + static const IconData class_outlined = IconData(0xef54, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">clean_hands</i> — material icon named "clean hands". + static const IconData clean_hands = IconData(0xe166, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">clean_hands</i> — material icon named "clean hands" (sharp). + static const IconData clean_hands_sharp = IconData(0xe863, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">clean_hands</i> — material icon named "clean hands" (round). + static const IconData clean_hands_rounded = IconData(0xf642, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">clean_hands</i> — material icon named "clean hands" (outlined). + static const IconData clean_hands_outlined = IconData(0xef55, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cleaning_services</i> — material icon named "cleaning services". + static const IconData cleaning_services = IconData(0xe167, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cleaning_services</i> — material icon named "cleaning services" (sharp). + static const IconData cleaning_services_sharp = IconData(0xe864, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cleaning_services</i> — material icon named "cleaning services" (round). + static const IconData cleaning_services_rounded = IconData(0xf643, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cleaning_services</i> — material icon named "cleaning services" (outlined). + static const IconData cleaning_services_outlined = IconData(0xef56, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">clear</i> — material icon named "clear". + static const IconData clear = IconData(0xe168, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">clear</i> — material icon named "clear" (sharp). + static const IconData clear_sharp = IconData(0xe866, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">clear</i> — material icon named "clear" (round). + static const IconData clear_rounded = IconData(0xf645, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">clear</i> — material icon named "clear" (outlined). + static const IconData clear_outlined = IconData(0xef58, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">clear_all</i> — material icon named "clear all". + static const IconData clear_all = IconData(0xe169, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">clear_all</i> — material icon named "clear all" (sharp). + static const IconData clear_all_sharp = IconData(0xe865, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">clear_all</i> — material icon named "clear all" (round). + static const IconData clear_all_rounded = IconData(0xf644, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">clear_all</i> — material icon named "clear all" (outlined). + static const IconData clear_all_outlined = IconData(0xef57, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">close</i> — material icon named "close". + static const IconData close = IconData(0xe16a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">close</i> — material icon named "close" (sharp). + static const IconData close_sharp = IconData(0xe868, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">close</i> — material icon named "close" (round). + static const IconData close_rounded = IconData(0xf647, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">close</i> — material icon named "close" (outlined). + static const IconData close_outlined = IconData(0xef5a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">close_fullscreen</i> — material icon named "close fullscreen". + static const IconData close_fullscreen = IconData(0xe16b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">close_fullscreen</i> — material icon named "close fullscreen" (sharp). + static const IconData close_fullscreen_sharp = IconData(0xe867, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">close_fullscreen</i> — material icon named "close fullscreen" (round). + static const IconData close_fullscreen_rounded = IconData(0xf646, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">close_fullscreen</i> — material icon named "close fullscreen" (outlined). + static const IconData close_fullscreen_outlined = IconData(0xef59, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">closed_caption</i> — material icon named "closed caption". + static const IconData closed_caption = IconData(0xe16c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">closed_caption</i> — material icon named "closed caption" (sharp). + static const IconData closed_caption_sharp = IconData(0xe86b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">closed_caption</i> — material icon named "closed caption" (round). + static const IconData closed_caption_rounded = IconData(0xf64a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">closed_caption</i> — material icon named "closed caption" (outlined). + static const IconData closed_caption_outlined = IconData(0xef5d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">closed_caption_disabled</i> — material icon named "closed caption disabled". + static const IconData closed_caption_disabled = IconData(0xe16d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">closed_caption_disabled</i> — material icon named "closed caption disabled" (sharp). + static const IconData closed_caption_disabled_sharp = IconData(0xe869, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">closed_caption_disabled</i> — material icon named "closed caption disabled" (round). + static const IconData closed_caption_disabled_rounded = IconData(0xf648, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">closed_caption_disabled</i> — material icon named "closed caption disabled" (outlined). + static const IconData closed_caption_disabled_outlined = IconData(0xef5b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">closed_caption_off</i> — material icon named "closed caption off". + static const IconData closed_caption_off = IconData(0xe16e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">closed_caption_off</i> — material icon named "closed caption off" (sharp). + static const IconData closed_caption_off_sharp = IconData(0xe86a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">closed_caption_off</i> — material icon named "closed caption off" (round). + static const IconData closed_caption_off_rounded = IconData(0xf649, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">closed_caption_off</i> — material icon named "closed caption off" (outlined). + static const IconData closed_caption_off_outlined = IconData(0xef5c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cloud</i> — material icon named "cloud". + static const IconData cloud = IconData(0xe16f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cloud</i> — material icon named "cloud" (sharp). + static const IconData cloud_sharp = IconData(0xe871, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cloud</i> — material icon named "cloud" (round). + static const IconData cloud_rounded = IconData(0xf650, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cloud</i> — material icon named "cloud" (outlined). + static const IconData cloud_outlined = IconData(0xef62, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cloud_circle</i> — material icon named "cloud circle". + static const IconData cloud_circle = IconData(0xe170, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cloud_circle</i> — material icon named "cloud circle" (sharp). + static const IconData cloud_circle_sharp = IconData(0xe86c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cloud_circle</i> — material icon named "cloud circle" (round). + static const IconData cloud_circle_rounded = IconData(0xf64b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cloud_circle</i> — material icon named "cloud circle" (outlined). + static const IconData cloud_circle_outlined = IconData(0xef5e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cloud_done</i> — material icon named "cloud done". + static const IconData cloud_done = IconData(0xe171, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cloud_done</i> — material icon named "cloud done" (sharp). + static const IconData cloud_done_sharp = IconData(0xe86d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cloud_done</i> — material icon named "cloud done" (round). + static const IconData cloud_done_rounded = IconData(0xf64c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cloud_done</i> — material icon named "cloud done" (outlined). + static const IconData cloud_done_outlined = IconData(0xef5f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cloud_download</i> — material icon named "cloud download". + static const IconData cloud_download = IconData(0xe172, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cloud_download</i> — material icon named "cloud download" (sharp). + static const IconData cloud_download_sharp = IconData(0xe86e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cloud_download</i> — material icon named "cloud download" (round). + static const IconData cloud_download_rounded = IconData(0xf64d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cloud_download</i> — material icon named "cloud download" (outlined). + static const IconData cloud_download_outlined = IconData(0xef60, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cloud_off</i> — material icon named "cloud off". + static const IconData cloud_off = IconData(0xe173, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cloud_off</i> — material icon named "cloud off" (sharp). + static const IconData cloud_off_sharp = IconData(0xe86f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cloud_off</i> — material icon named "cloud off" (round). + static const IconData cloud_off_rounded = IconData(0xf64e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cloud_off</i> — material icon named "cloud off" (outlined). + static const IconData cloud_off_outlined = IconData(0xef61, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cloud_queue</i> — material icon named "cloud queue". + static const IconData cloud_queue = IconData(0xe174, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cloud_queue</i> — material icon named "cloud queue" (sharp). + static const IconData cloud_queue_sharp = IconData(0xe870, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cloud_queue</i> — material icon named "cloud queue" (round). + static const IconData cloud_queue_rounded = IconData(0xf64f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cloud_queue</i> — material icon named "cloud queue" (outlined). + static const IconData cloud_queue_outlined = IconData(0xef63, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cloud_sync</i> — material icon named "cloud sync". + static const IconData cloud_sync = IconData(0xf04ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cloud_sync</i> — material icon named "cloud sync" (sharp). + static const IconData cloud_sync_sharp = IconData(0xf03db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cloud_sync</i> — material icon named "cloud sync" (round). + static const IconData cloud_sync_rounded = IconData(0xf02e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cloud_sync</i> — material icon named "cloud sync" (outlined). + static const IconData cloud_sync_outlined = IconData(0xf05c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cloud_upload</i> — material icon named "cloud upload". + static const IconData cloud_upload = IconData(0xe175, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cloud_upload</i> — material icon named "cloud upload" (sharp). + static const IconData cloud_upload_sharp = IconData(0xe872, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cloud_upload</i> — material icon named "cloud upload" (round). + static const IconData cloud_upload_rounded = IconData(0xf651, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cloud_upload</i> — material icon named "cloud upload" (outlined). + static const IconData cloud_upload_outlined = IconData(0xef64, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cloudy_snowing</i> — material icon named "cloudy snowing". + static const IconData cloudy_snowing = IconData(0xf04cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">co2</i> — material icon named "co2". + static const IconData co2 = IconData(0xf04d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">co2</i> — material icon named "co2" (sharp). + static const IconData co2_sharp = IconData(0xf03dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">co2</i> — material icon named "co2" (round). + static const IconData co2_rounded = IconData(0xf02e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">co2</i> — material icon named "co2" (outlined). + static const IconData co2_outlined = IconData(0xf05ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">co_present</i> — material icon named "co present". + static const IconData co_present = IconData(0xf04d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">co_present</i> — material icon named "co present" (sharp). + static const IconData co_present_sharp = IconData(0xf03dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">co_present</i> — material icon named "co present" (round). + static const IconData co_present_rounded = IconData(0xf02ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">co_present</i> — material icon named "co present" (outlined). + static const IconData co_present_outlined = IconData(0xf05cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">code</i> — material icon named "code". + static const IconData code = IconData(0xe176, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">code</i> — material icon named "code" (sharp). + static const IconData code_sharp = IconData(0xe874, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">code</i> — material icon named "code" (round). + static const IconData code_rounded = IconData(0xf653, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">code</i> — material icon named "code" (outlined). + static const IconData code_outlined = IconData(0xef66, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">code_off</i> — material icon named "code off". + static const IconData code_off = IconData(0xe177, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">code_off</i> — material icon named "code off" (sharp). + static const IconData code_off_sharp = IconData(0xe873, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">code_off</i> — material icon named "code off" (round). + static const IconData code_off_rounded = IconData(0xf652, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">code_off</i> — material icon named "code off" (outlined). + static const IconData code_off_outlined = IconData(0xef65, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">coffee</i> — material icon named "coffee". + static const IconData coffee = IconData(0xe178, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">coffee</i> — material icon named "coffee" (sharp). + static const IconData coffee_sharp = IconData(0xe876, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">coffee</i> — material icon named "coffee" (round). + static const IconData coffee_rounded = IconData(0xf655, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">coffee</i> — material icon named "coffee" (outlined). + static const IconData coffee_outlined = IconData(0xef68, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">coffee_maker</i> — material icon named "coffee maker". + static const IconData coffee_maker = IconData(0xe179, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">coffee_maker</i> — material icon named "coffee maker" (sharp). + static const IconData coffee_maker_sharp = IconData(0xe875, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">coffee_maker</i> — material icon named "coffee maker" (round). + static const IconData coffee_maker_rounded = IconData(0xf654, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">coffee_maker</i> — material icon named "coffee maker" (outlined). + static const IconData coffee_maker_outlined = IconData(0xef67, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">collections</i> — material icon named "collections". + static const IconData collections = IconData(0xe17a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">collections</i> — material icon named "collections" (sharp). + static const IconData collections_sharp = IconData(0xe878, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">collections</i> — material icon named "collections" (round). + static const IconData collections_rounded = IconData(0xf657, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">collections</i> — material icon named "collections" (outlined). + static const IconData collections_outlined = IconData(0xef6a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">collections_bookmark</i> — material icon named "collections bookmark". + static const IconData collections_bookmark = IconData(0xe17b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">collections_bookmark</i> — material icon named "collections bookmark" (sharp). + static const IconData collections_bookmark_sharp = IconData(0xe877, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">collections_bookmark</i> — material icon named "collections bookmark" (round). + static const IconData collections_bookmark_rounded = IconData(0xf656, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">collections_bookmark</i> — material icon named "collections bookmark" (outlined). + static const IconData collections_bookmark_outlined = IconData(0xef69, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">color_lens</i> — material icon named "color lens". + static const IconData color_lens = IconData(0xe17c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">color_lens</i> — material icon named "color lens" (sharp). + static const IconData color_lens_sharp = IconData(0xe879, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">color_lens</i> — material icon named "color lens" (round). + static const IconData color_lens_rounded = IconData(0xf658, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">color_lens</i> — material icon named "color lens" (outlined). + static const IconData color_lens_outlined = IconData(0xef6b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">colorize</i> — material icon named "colorize". + static const IconData colorize = IconData(0xe17d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">colorize</i> — material icon named "colorize" (sharp). + static const IconData colorize_sharp = IconData(0xe87a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">colorize</i> — material icon named "colorize" (round). + static const IconData colorize_rounded = IconData(0xf659, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">colorize</i> — material icon named "colorize" (outlined). + static const IconData colorize_outlined = IconData(0xef6c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">comment</i> — material icon named "comment". + static const IconData comment = IconData(0xe17e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">comment</i> — material icon named "comment" (sharp). + static const IconData comment_sharp = IconData(0xe87c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">comment</i> — material icon named "comment" (round). + static const IconData comment_rounded = IconData(0xf65b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">comment</i> — material icon named "comment" (outlined). + static const IconData comment_outlined = IconData(0xef6e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">comment_bank</i> — material icon named "comment bank". + static const IconData comment_bank = IconData(0xe17f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">comment_bank</i> — material icon named "comment bank" (sharp). + static const IconData comment_bank_sharp = IconData(0xe87b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">comment_bank</i> — material icon named "comment bank" (round). + static const IconData comment_bank_rounded = IconData(0xf65a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">comment_bank</i> — material icon named "comment bank" (outlined). + static const IconData comment_bank_outlined = IconData(0xef6d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">comments_disabled</i> — material icon named "comments disabled". + static const IconData comments_disabled = IconData(0xf04d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">comments_disabled</i> — material icon named "comments disabled" (sharp). + static const IconData comments_disabled_sharp = IconData(0xf03de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">comments_disabled</i> — material icon named "comments disabled" (round). + static const IconData comments_disabled_rounded = IconData(0xf02eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">comments_disabled</i> — material icon named "comments disabled" (outlined). + static const IconData comments_disabled_outlined = IconData(0xf05cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">commit</i> — material icon named "commit". + static const IconData commit = IconData(0xf04d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">commit</i> — material icon named "commit" (sharp). + static const IconData commit_sharp = IconData(0xf03df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">commit</i> — material icon named "commit" (round). + static const IconData commit_rounded = IconData(0xf02ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">commit</i> — material icon named "commit" (outlined). + static const IconData commit_outlined = IconData(0xf05cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">commute</i> — material icon named "commute". + static const IconData commute = IconData(0xe180, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">commute</i> — material icon named "commute" (sharp). + static const IconData commute_sharp = IconData(0xe87d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">commute</i> — material icon named "commute" (round). + static const IconData commute_rounded = IconData(0xf65c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">commute</i> — material icon named "commute" (outlined). + static const IconData commute_outlined = IconData(0xef6f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">compare</i> — material icon named "compare". + static const IconData compare = IconData(0xe181, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">compare</i> — material icon named "compare" (sharp). + static const IconData compare_sharp = IconData(0xe87f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">compare</i> — material icon named "compare" (round). + static const IconData compare_rounded = IconData(0xf65e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">compare</i> — material icon named "compare" (outlined). + static const IconData compare_outlined = IconData(0xef71, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">compare_arrows</i> — material icon named "compare arrows". + static const IconData compare_arrows = IconData(0xe182, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">compare_arrows</i> — material icon named "compare arrows" (sharp). + static const IconData compare_arrows_sharp = IconData(0xe87e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">compare_arrows</i> — material icon named "compare arrows" (round). + static const IconData compare_arrows_rounded = IconData(0xf65d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">compare_arrows</i> — material icon named "compare arrows" (outlined). + static const IconData compare_arrows_outlined = IconData(0xef70, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">compass_calibration</i> — material icon named "compass calibration". + static const IconData compass_calibration = IconData(0xe183, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">compass_calibration</i> — material icon named "compass calibration" (sharp). + static const IconData compass_calibration_sharp = IconData(0xe880, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">compass_calibration</i> — material icon named "compass calibration" (round). + static const IconData compass_calibration_rounded = IconData(0xf65f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">compass_calibration</i> — material icon named "compass calibration" (outlined). + static const IconData compass_calibration_outlined = IconData(0xef72, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">compost</i> — material icon named "compost". + static const IconData compost = IconData(0xf04d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">compost</i> — material icon named "compost" (sharp). + static const IconData compost_sharp = IconData(0xf03e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">compost</i> — material icon named "compost" (round). + static const IconData compost_rounded = IconData(0xf02ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">compost</i> — material icon named "compost" (outlined). + static const IconData compost_outlined = IconData(0xf05ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">compress</i> — material icon named "compress". + static const IconData compress = IconData(0xe184, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">compress</i> — material icon named "compress" (sharp). + static const IconData compress_sharp = IconData(0xe881, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">compress</i> — material icon named "compress" (round). + static const IconData compress_rounded = IconData(0xf660, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">compress</i> — material icon named "compress" (outlined). + static const IconData compress_outlined = IconData(0xef73, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">computer</i> — material icon named "computer". + static const IconData computer = IconData(0xe185, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">computer</i> — material icon named "computer" (sharp). + static const IconData computer_sharp = IconData(0xe882, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">computer</i> — material icon named "computer" (round). + static const IconData computer_rounded = IconData(0xf661, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">computer</i> — material icon named "computer" (outlined). + static const IconData computer_outlined = IconData(0xef74, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">confirmation_num</i> — material icon named "confirmation num". + static const IconData confirmation_num = IconData(0xe186, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">confirmation_num</i> — material icon named "confirmation num" (sharp). + static const IconData confirmation_num_sharp = IconData(0xe883, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">confirmation_num</i> — material icon named "confirmation num" (round). + static const IconData confirmation_num_rounded = IconData(0xf662, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">confirmation_num</i> — material icon named "confirmation num" (outlined). + static const IconData confirmation_num_outlined = IconData(0xef75, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">confirmation_number</i> — material icon named "confirmation number". + static const IconData confirmation_number = IconData(0xe186, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">confirmation_number</i> — material icon named "confirmation number" (sharp). + static const IconData confirmation_number_sharp = IconData(0xe883, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">confirmation_number</i> — material icon named "confirmation number" (round). + static const IconData confirmation_number_rounded = IconData(0xf662, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">confirmation_number</i> — material icon named "confirmation number" (outlined). + static const IconData confirmation_number_outlined = IconData(0xef75, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">connect_without_contact</i> — material icon named "connect without contact". + static const IconData connect_without_contact = IconData(0xe187, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">connect_without_contact</i> — material icon named "connect without contact" (sharp). + static const IconData connect_without_contact_sharp = IconData(0xe884, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">connect_without_contact</i> — material icon named "connect without contact" (round). + static const IconData connect_without_contact_rounded = IconData(0xf663, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">connect_without_contact</i> — material icon named "connect without contact" (outlined). + static const IconData connect_without_contact_outlined = IconData(0xef76, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">connected_tv</i> — material icon named "connected tv". + static const IconData connected_tv = IconData(0xe188, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">connected_tv</i> — material icon named "connected tv" (sharp). + static const IconData connected_tv_sharp = IconData(0xe885, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">connected_tv</i> — material icon named "connected tv" (round). + static const IconData connected_tv_rounded = IconData(0xf664, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">connected_tv</i> — material icon named "connected tv" (outlined). + static const IconData connected_tv_outlined = IconData(0xef77, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">connecting_airports</i> — material icon named "connecting airports". + static const IconData connecting_airports = IconData(0xf04d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">connecting_airports</i> — material icon named "connecting airports" (sharp). + static const IconData connecting_airports_sharp = IconData(0xf03e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">connecting_airports</i> — material icon named "connecting airports" (round). + static const IconData connecting_airports_rounded = IconData(0xf02ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">connecting_airports</i> — material icon named "connecting airports" (outlined). + static const IconData connecting_airports_outlined = IconData(0xf05cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">construction</i> — material icon named "construction". + static const IconData construction = IconData(0xe189, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">construction</i> — material icon named "construction" (sharp). + static const IconData construction_sharp = IconData(0xe886, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">construction</i> — material icon named "construction" (round). + static const IconData construction_rounded = IconData(0xf665, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">construction</i> — material icon named "construction" (outlined). + static const IconData construction_outlined = IconData(0xef78, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">contact_emergency</i> — material icon named "contact emergency". + static const IconData contact_emergency = IconData(0xf0857, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">contact_emergency</i> — material icon named "contact emergency" (sharp). + static const IconData contact_emergency_sharp = IconData(0xf0837, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">contact_emergency</i> — material icon named "contact emergency" (round). + static const IconData contact_emergency_rounded = IconData(0xf0880, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">contact_emergency</i> — material icon named "contact emergency" (outlined). + static const IconData contact_emergency_outlined = IconData(0xf089e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">contact_mail</i> — material icon named "contact mail". + static const IconData contact_mail = IconData(0xe18a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">contact_mail</i> — material icon named "contact mail" (sharp). + static const IconData contact_mail_sharp = IconData(0xe887, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">contact_mail</i> — material icon named "contact mail" (round). + static const IconData contact_mail_rounded = IconData(0xf666, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">contact_mail</i> — material icon named "contact mail" (outlined). + static const IconData contact_mail_outlined = IconData(0xef79, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">contact_page</i> — material icon named "contact page". + static const IconData contact_page = IconData(0xe18b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">contact_page</i> — material icon named "contact page" (sharp). + static const IconData contact_page_sharp = IconData(0xe888, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">contact_page</i> — material icon named "contact page" (round). + static const IconData contact_page_rounded = IconData(0xf667, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">contact_page</i> — material icon named "contact page" (outlined). + static const IconData contact_page_outlined = IconData(0xef7a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">contact_phone</i> — material icon named "contact phone". + static const IconData contact_phone = IconData(0xe18c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">contact_phone</i> — material icon named "contact phone" (sharp). + static const IconData contact_phone_sharp = IconData(0xe889, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">contact_phone</i> — material icon named "contact phone" (round). + static const IconData contact_phone_rounded = IconData(0xf668, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">contact_phone</i> — material icon named "contact phone" (outlined). + static const IconData contact_phone_outlined = IconData(0xef7b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">contact_support</i> — material icon named "contact support". + static const IconData contact_support = IconData(0xe18d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">contact_support</i> — material icon named "contact support" (sharp). + static const IconData contact_support_sharp = IconData(0xe88a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">contact_support</i> — material icon named "contact support" (round). + static const IconData contact_support_rounded = IconData(0xf669, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">contact_support</i> — material icon named "contact support" (outlined). + static const IconData contact_support_outlined = IconData(0xef7c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">contactless</i> — material icon named "contactless". + static const IconData contactless = IconData(0xe18e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">contactless</i> — material icon named "contactless" (sharp). + static const IconData contactless_sharp = IconData(0xe88b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">contactless</i> — material icon named "contactless" (round). + static const IconData contactless_rounded = IconData(0xf66a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">contactless</i> — material icon named "contactless" (outlined). + static const IconData contactless_outlined = IconData(0xef7d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">contacts</i> — material icon named "contacts". + static const IconData contacts = IconData(0xe18f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">contacts</i> — material icon named "contacts" (sharp). + static const IconData contacts_sharp = IconData(0xe88c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">contacts</i> — material icon named "contacts" (round). + static const IconData contacts_rounded = IconData(0xf66b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">contacts</i> — material icon named "contacts" (outlined). + static const IconData contacts_outlined = IconData(0xef7e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">content_copy</i> — material icon named "content copy". + static const IconData content_copy = IconData(0xe190, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">content_copy</i> — material icon named "content copy" (sharp). + static const IconData content_copy_sharp = IconData(0xe88d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">content_copy</i> — material icon named "content copy" (round). + static const IconData content_copy_rounded = IconData(0xf66c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">content_copy</i> — material icon named "content copy" (outlined). + static const IconData content_copy_outlined = IconData(0xef7f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">content_cut</i> — material icon named "content cut". + static const IconData content_cut = IconData(0xe191, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">content_cut</i> — material icon named "content cut" (sharp). + static const IconData content_cut_sharp = IconData(0xe88e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">content_cut</i> — material icon named "content cut" (round). + static const IconData content_cut_rounded = IconData(0xf66d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">content_cut</i> — material icon named "content cut" (outlined). + static const IconData content_cut_outlined = IconData(0xef80, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">content_paste</i> — material icon named "content paste". + static const IconData content_paste = IconData(0xe192, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">content_paste</i> — material icon named "content paste" (sharp). + static const IconData content_paste_sharp = IconData(0xe890, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">content_paste</i> — material icon named "content paste" (round). + static const IconData content_paste_rounded = IconData(0xf66f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">content_paste</i> — material icon named "content paste" (outlined). + static const IconData content_paste_outlined = IconData(0xef82, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">content_paste_go</i> — material icon named "content paste go". + static const IconData content_paste_go = IconData(0xf04d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">content_paste_go</i> — material icon named "content paste go" (sharp). + static const IconData content_paste_go_sharp = IconData(0xf03e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">content_paste_go</i> — material icon named "content paste go" (round). + static const IconData content_paste_go_rounded = IconData(0xf02ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">content_paste_go</i> — material icon named "content paste go" (outlined). + static const IconData content_paste_go_outlined = IconData(0xf05d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">content_paste_off</i> — material icon named "content paste off". + static const IconData content_paste_off = IconData(0xe193, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">content_paste_off</i> — material icon named "content paste off" (sharp). + static const IconData content_paste_off_sharp = IconData(0xe88f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">content_paste_off</i> — material icon named "content paste off" (round). + static const IconData content_paste_off_rounded = IconData(0xf66e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">content_paste_off</i> — material icon named "content paste off" (outlined). + static const IconData content_paste_off_outlined = IconData(0xef81, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">content_paste_search</i> — material icon named "content paste search". + static const IconData content_paste_search = IconData(0xf04d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">content_paste_search</i> — material icon named "content paste search" (sharp). + static const IconData content_paste_search_sharp = IconData(0xf03e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">content_paste_search</i> — material icon named "content paste search" (round). + static const IconData content_paste_search_rounded = IconData(0xf02f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">content_paste_search</i> — material icon named "content paste search" (outlined). + static const IconData content_paste_search_outlined = IconData(0xf05d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">contrast</i> — material icon named "contrast". + static const IconData contrast = IconData(0xf04d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">contrast</i> — material icon named "contrast" (sharp). + static const IconData contrast_sharp = IconData(0xf03e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">contrast</i> — material icon named "contrast" (round). + static const IconData contrast_rounded = IconData(0xf02f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">contrast</i> — material icon named "contrast" (outlined). + static const IconData contrast_outlined = IconData(0xf05d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">control_camera</i> — material icon named "control camera". + static const IconData control_camera = IconData(0xe194, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">control_camera</i> — material icon named "control camera" (sharp). + static const IconData control_camera_sharp = IconData(0xe891, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">control_camera</i> — material icon named "control camera" (round). + static const IconData control_camera_rounded = IconData(0xf670, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">control_camera</i> — material icon named "control camera" (outlined). + static const IconData control_camera_outlined = IconData(0xef83, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">control_point</i> — material icon named "control point". + static const IconData control_point = IconData(0xe195, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">control_point</i> — material icon named "control point" (sharp). + static const IconData control_point_sharp = IconData(0xe893, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">control_point</i> — material icon named "control point" (round). + static const IconData control_point_rounded = IconData(0xf672, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">control_point</i> — material icon named "control point" (outlined). + static const IconData control_point_outlined = IconData(0xef85, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">control_point_duplicate</i> — material icon named "control point duplicate". + static const IconData control_point_duplicate = IconData(0xe196, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">control_point_duplicate</i> — material icon named "control point duplicate" (sharp). + static const IconData control_point_duplicate_sharp = IconData(0xe892, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">control_point_duplicate</i> — material icon named "control point duplicate" (round). + static const IconData control_point_duplicate_rounded = IconData(0xf671, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">control_point_duplicate</i> — material icon named "control point duplicate" (outlined). + static const IconData control_point_duplicate_outlined = IconData(0xef84, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">conveyor_belt</i> — material icon named "conveyor belt". + static const IconData conveyor_belt = IconData(0xf0858, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cookie</i> — material icon named "cookie". + static const IconData cookie = IconData(0xf04d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cookie</i> — material icon named "cookie" (sharp). + static const IconData cookie_sharp = IconData(0xf03e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cookie</i> — material icon named "cookie" (round). + static const IconData cookie_rounded = IconData(0xf02f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cookie</i> — material icon named "cookie" (outlined). + static const IconData cookie_outlined = IconData(0xf05d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">copy</i> — material icon named "copy". + static const IconData copy = IconData(0xe190, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">copy</i> — material icon named "copy" (sharp). + static const IconData copy_sharp = IconData(0xe88d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">copy</i> — material icon named "copy" (round). + static const IconData copy_rounded = IconData(0xf66c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">copy</i> — material icon named "copy" (outlined). + static const IconData copy_outlined = IconData(0xef7f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">copy_all</i> — material icon named "copy all". + static const IconData copy_all = IconData(0xe197, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">copy_all</i> — material icon named "copy all" (sharp). + static const IconData copy_all_sharp = IconData(0xe894, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">copy_all</i> — material icon named "copy all" (round). + static const IconData copy_all_rounded = IconData(0xf673, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">copy_all</i> — material icon named "copy all" (outlined). + static const IconData copy_all_outlined = IconData(0xef86, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">copyright</i> — material icon named "copyright". + static const IconData copyright = IconData(0xe198, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">copyright</i> — material icon named "copyright" (sharp). + static const IconData copyright_sharp = IconData(0xe895, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">copyright</i> — material icon named "copyright" (round). + static const IconData copyright_rounded = IconData(0xf674, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">copyright</i> — material icon named "copyright" (outlined). + static const IconData copyright_outlined = IconData(0xef87, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">coronavirus</i> — material icon named "coronavirus". + static const IconData coronavirus = IconData(0xe199, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">coronavirus</i> — material icon named "coronavirus" (sharp). + static const IconData coronavirus_sharp = IconData(0xe896, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">coronavirus</i> — material icon named "coronavirus" (round). + static const IconData coronavirus_rounded = IconData(0xf675, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">coronavirus</i> — material icon named "coronavirus" (outlined). + static const IconData coronavirus_outlined = IconData(0xef88, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">corporate_fare</i> — material icon named "corporate fare". + static const IconData corporate_fare = IconData(0xe19a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">corporate_fare</i> — material icon named "corporate fare" (sharp). + static const IconData corporate_fare_sharp = IconData(0xe897, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">corporate_fare</i> — material icon named "corporate fare" (round). + static const IconData corporate_fare_rounded = IconData(0xf676, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">corporate_fare</i> — material icon named "corporate fare" (outlined). + static const IconData corporate_fare_outlined = IconData(0xef89, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cottage</i> — material icon named "cottage". + static const IconData cottage = IconData(0xe19b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cottage</i> — material icon named "cottage" (sharp). + static const IconData cottage_sharp = IconData(0xe898, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cottage</i> — material icon named "cottage" (round). + static const IconData cottage_rounded = IconData(0xf677, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cottage</i> — material icon named "cottage" (outlined). + static const IconData cottage_outlined = IconData(0xef8a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">countertops</i> — material icon named "countertops". + static const IconData countertops = IconData(0xe19c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">countertops</i> — material icon named "countertops" (sharp). + static const IconData countertops_sharp = IconData(0xe899, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">countertops</i> — material icon named "countertops" (round). + static const IconData countertops_rounded = IconData(0xf678, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">countertops</i> — material icon named "countertops" (outlined). + static const IconData countertops_outlined = IconData(0xef8b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">create</i> — material icon named "create". + static const IconData create = IconData(0xe19d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">create</i> — material icon named "create" (sharp). + static const IconData create_sharp = IconData(0xe89b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">create</i> — material icon named "create" (round). + static const IconData create_rounded = IconData(0xf67a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">create</i> — material icon named "create" (outlined). + static const IconData create_outlined = IconData(0xef8d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">create_new_folder</i> — material icon named "create new folder". + static const IconData create_new_folder = IconData(0xe19e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">create_new_folder</i> — material icon named "create new folder" (sharp). + static const IconData create_new_folder_sharp = IconData(0xe89a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">create_new_folder</i> — material icon named "create new folder" (round). + static const IconData create_new_folder_rounded = IconData(0xf679, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">create_new_folder</i> — material icon named "create new folder" (outlined). + static const IconData create_new_folder_outlined = IconData(0xef8c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">credit_card</i> — material icon named "credit card". + static const IconData credit_card = IconData(0xe19f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">credit_card</i> — material icon named "credit card" (sharp). + static const IconData credit_card_sharp = IconData(0xe89d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">credit_card</i> — material icon named "credit card" (round). + static const IconData credit_card_rounded = IconData(0xf67c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">credit_card</i> — material icon named "credit card" (outlined). + static const IconData credit_card_outlined = IconData(0xef8f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">credit_card_off</i> — material icon named "credit card off". + static const IconData credit_card_off = IconData(0xe1a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">credit_card_off</i> — material icon named "credit card off" (sharp). + static const IconData credit_card_off_sharp = IconData(0xe89c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">credit_card_off</i> — material icon named "credit card off" (round). + static const IconData credit_card_off_rounded = IconData(0xf67b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">credit_card_off</i> — material icon named "credit card off" (outlined). + static const IconData credit_card_off_outlined = IconData(0xef8e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">credit_score</i> — material icon named "credit score". + static const IconData credit_score = IconData(0xe1a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">credit_score</i> — material icon named "credit score" (sharp). + static const IconData credit_score_sharp = IconData(0xe89e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">credit_score</i> — material icon named "credit score" (round). + static const IconData credit_score_rounded = IconData(0xf67d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">credit_score</i> — material icon named "credit score" (outlined). + static const IconData credit_score_outlined = IconData(0xef90, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crib</i> — material icon named "crib". + static const IconData crib = IconData(0xe1a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crib</i> — material icon named "crib" (sharp). + static const IconData crib_sharp = IconData(0xe89f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crib</i> — material icon named "crib" (round). + static const IconData crib_rounded = IconData(0xf67e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crib</i> — material icon named "crib" (outlined). + static const IconData crib_outlined = IconData(0xef91, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crisis_alert</i> — material icon named "crisis alert". + static const IconData crisis_alert = IconData(0xf0794, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crisis_alert</i> — material icon named "crisis alert" (sharp). + static const IconData crisis_alert_sharp = IconData(0xf073c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crisis_alert</i> — material icon named "crisis alert" (round). + static const IconData crisis_alert_rounded = IconData(0xf07ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crisis_alert</i> — material icon named "crisis alert" (outlined). + static const IconData crisis_alert_outlined = IconData(0xf06e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop</i> — material icon named "crop". + static const IconData crop = IconData(0xe1a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop</i> — material icon named "crop" (sharp). + static const IconData crop_sharp = IconData(0xe8aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop</i> — material icon named "crop" (round). + static const IconData crop_rounded = IconData(0xf689, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop</i> — material icon named "crop" (outlined). + static const IconData crop_outlined = IconData(0xef9a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_16_9</i> — material icon named "crop 16 9". + static const IconData crop_16_9 = IconData(0xe1a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_16_9</i> — material icon named "crop 16 9" (sharp). + static const IconData crop_16_9_sharp = IconData(0xe8a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_16_9</i> — material icon named "crop 16 9" (round). + static const IconData crop_16_9_rounded = IconData(0xf67f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_16_9</i> — material icon named "crop 16 9" (outlined). + static const IconData crop_16_9_outlined = IconData(0xef92, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_3_2</i> — material icon named "crop 3 2". + static const IconData crop_3_2 = IconData(0xe1a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_3_2</i> — material icon named "crop 3 2" (sharp). + static const IconData crop_3_2_sharp = IconData(0xe8a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_3_2</i> — material icon named "crop 3 2" (round). + static const IconData crop_3_2_rounded = IconData(0xf680, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_3_2</i> — material icon named "crop 3 2" (outlined). + static const IconData crop_3_2_outlined = IconData(0xef93, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_5_4</i> — material icon named "crop 5 4". + static const IconData crop_5_4 = IconData(0xe1a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_5_4</i> — material icon named "crop 5 4" (sharp). + static const IconData crop_5_4_sharp = IconData(0xe8a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_5_4</i> — material icon named "crop 5 4" (round). + static const IconData crop_5_4_rounded = IconData(0xf681, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_5_4</i> — material icon named "crop 5 4" (outlined). + static const IconData crop_5_4_outlined = IconData(0xef94, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_7_5</i> — material icon named "crop 7 5". + static const IconData crop_7_5 = IconData(0xe1a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_7_5</i> — material icon named "crop 7 5" (sharp). + static const IconData crop_7_5_sharp = IconData(0xe8a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_7_5</i> — material icon named "crop 7 5" (round). + static const IconData crop_7_5_rounded = IconData(0xf682, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_7_5</i> — material icon named "crop 7 5" (outlined). + static const IconData crop_7_5_outlined = IconData(0xef95, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_din</i> — material icon named "crop din". + static const IconData crop_din = IconData(0xe1a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_din</i> — material icon named "crop din" (sharp). + static const IconData crop_din_sharp = IconData(0xe8a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_din</i> — material icon named "crop din" (round). + static const IconData crop_din_rounded = IconData(0xf683, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_din</i> — material icon named "crop din" (outlined). + static const IconData crop_din_outlined = IconData(0xef96, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_free</i> — material icon named "crop free". + static const IconData crop_free = IconData(0xe1a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_free</i> — material icon named "crop free" (sharp). + static const IconData crop_free_sharp = IconData(0xe8a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_free</i> — material icon named "crop free" (round). + static const IconData crop_free_rounded = IconData(0xf684, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_free</i> — material icon named "crop free" (outlined). + static const IconData crop_free_outlined = IconData(0xef97, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_landscape</i> — material icon named "crop landscape". + static const IconData crop_landscape = IconData(0xe1aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_landscape</i> — material icon named "crop landscape" (sharp). + static const IconData crop_landscape_sharp = IconData(0xe8a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_landscape</i> — material icon named "crop landscape" (round). + static const IconData crop_landscape_rounded = IconData(0xf685, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_landscape</i> — material icon named "crop landscape" (outlined). + static const IconData crop_landscape_outlined = IconData(0xef98, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_original</i> — material icon named "crop original". + static const IconData crop_original = IconData(0xe1ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_original</i> — material icon named "crop original" (sharp). + static const IconData crop_original_sharp = IconData(0xe8a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_original</i> — material icon named "crop original" (round). + static const IconData crop_original_rounded = IconData(0xf686, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_original</i> — material icon named "crop original" (outlined). + static const IconData crop_original_outlined = IconData(0xef99, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_portrait</i> — material icon named "crop portrait". + static const IconData crop_portrait = IconData(0xe1ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_portrait</i> — material icon named "crop portrait" (sharp). + static const IconData crop_portrait_sharp = IconData(0xe8a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_portrait</i> — material icon named "crop portrait" (round). + static const IconData crop_portrait_rounded = IconData(0xf687, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_portrait</i> — material icon named "crop portrait" (outlined). + static const IconData crop_portrait_outlined = IconData(0xef9b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_rotate</i> — material icon named "crop rotate". + static const IconData crop_rotate = IconData(0xe1ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_rotate</i> — material icon named "crop rotate" (sharp). + static const IconData crop_rotate_sharp = IconData(0xe8a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_rotate</i> — material icon named "crop rotate" (round). + static const IconData crop_rotate_rounded = IconData(0xf688, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_rotate</i> — material icon named "crop rotate" (outlined). + static const IconData crop_rotate_outlined = IconData(0xef9c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">crop_square</i> — material icon named "crop square". + static const IconData crop_square = IconData(0xe1ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">crop_square</i> — material icon named "crop square" (sharp). + static const IconData crop_square_sharp = IconData(0xe8ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">crop_square</i> — material icon named "crop square" (round). + static const IconData crop_square_rounded = IconData(0xf68a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">crop_square</i> — material icon named "crop square" (outlined). + static const IconData crop_square_outlined = IconData(0xef9d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cruelty_free</i> — material icon named "cruelty free". + static const IconData cruelty_free = IconData(0xf04da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cruelty_free</i> — material icon named "cruelty free" (sharp). + static const IconData cruelty_free_sharp = IconData(0xf03e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cruelty_free</i> — material icon named "cruelty free" (round). + static const IconData cruelty_free_rounded = IconData(0xf02f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cruelty_free</i> — material icon named "cruelty free" (outlined). + static const IconData cruelty_free_outlined = IconData(0xf05d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">css</i> — material icon named "css". + static const IconData css = IconData(0xf04db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">css</i> — material icon named "css" (sharp). + static const IconData css_sharp = IconData(0xf03e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">css</i> — material icon named "css" (round). + static const IconData css_rounded = IconData(0xf02f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">css</i> — material icon named "css" (outlined). + static const IconData css_outlined = IconData(0xf05d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">currency_bitcoin</i> — material icon named "currency bitcoin". + static const IconData currency_bitcoin = IconData(0xf06bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">currency_bitcoin</i> — material icon named "currency bitcoin" (sharp). + static const IconData currency_bitcoin_sharp = IconData(0xf06af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">currency_bitcoin</i> — material icon named "currency bitcoin" (round). + static const IconData currency_bitcoin_rounded = IconData(0xf06c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">currency_bitcoin</i> — material icon named "currency bitcoin" (outlined). + static const IconData currency_bitcoin_outlined = IconData(0xf054a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">currency_exchange</i> — material icon named "currency exchange". + static const IconData currency_exchange = IconData(0xf04dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">currency_exchange</i> — material icon named "currency exchange" (sharp). + static const IconData currency_exchange_sharp = IconData(0xf03e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">currency_exchange</i> — material icon named "currency exchange" (round). + static const IconData currency_exchange_rounded = IconData(0xf02f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">currency_exchange</i> — material icon named "currency exchange" (outlined). + static const IconData currency_exchange_outlined = IconData(0xf05d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">currency_franc</i> — material icon named "currency franc". + static const IconData currency_franc = IconData(0xf04dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">currency_franc</i> — material icon named "currency franc" (sharp). + static const IconData currency_franc_sharp = IconData(0xf03e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">currency_franc</i> — material icon named "currency franc" (round). + static const IconData currency_franc_rounded = IconData(0xf02f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">currency_franc</i> — material icon named "currency franc" (outlined). + static const IconData currency_franc_outlined = IconData(0xf05d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">currency_lira</i> — material icon named "currency lira". + static const IconData currency_lira = IconData(0xf04de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">currency_lira</i> — material icon named "currency lira" (sharp). + static const IconData currency_lira_sharp = IconData(0xf03ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">currency_lira</i> — material icon named "currency lira" (round). + static const IconData currency_lira_rounded = IconData(0xf02f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">currency_lira</i> — material icon named "currency lira" (outlined). + static const IconData currency_lira_outlined = IconData(0xf05d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">currency_pound</i> — material icon named "currency pound". + static const IconData currency_pound = IconData(0xf04df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">currency_pound</i> — material icon named "currency pound" (sharp). + static const IconData currency_pound_sharp = IconData(0xf03eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">currency_pound</i> — material icon named "currency pound" (round). + static const IconData currency_pound_rounded = IconData(0xf02f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">currency_pound</i> — material icon named "currency pound" (outlined). + static const IconData currency_pound_outlined = IconData(0xf05d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">currency_ruble</i> — material icon named "currency ruble". + static const IconData currency_ruble = IconData(0xf04e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">currency_ruble</i> — material icon named "currency ruble" (sharp). + static const IconData currency_ruble_sharp = IconData(0xf03ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">currency_ruble</i> — material icon named "currency ruble" (round). + static const IconData currency_ruble_rounded = IconData(0xf02f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">currency_ruble</i> — material icon named "currency ruble" (outlined). + static const IconData currency_ruble_outlined = IconData(0xf05da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">currency_rupee</i> — material icon named "currency rupee". + static const IconData currency_rupee = IconData(0xf04e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">currency_rupee</i> — material icon named "currency rupee" (sharp). + static const IconData currency_rupee_sharp = IconData(0xf03ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">currency_rupee</i> — material icon named "currency rupee" (round). + static const IconData currency_rupee_rounded = IconData(0xf02fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">currency_rupee</i> — material icon named "currency rupee" (outlined). + static const IconData currency_rupee_outlined = IconData(0xf05db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">currency_yen</i> — material icon named "currency yen". + static const IconData currency_yen = IconData(0xf04e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">currency_yen</i> — material icon named "currency yen" (sharp). + static const IconData currency_yen_sharp = IconData(0xf03ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">currency_yen</i> — material icon named "currency yen" (round). + static const IconData currency_yen_rounded = IconData(0xf02fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">currency_yen</i> — material icon named "currency yen" (outlined). + static const IconData currency_yen_outlined = IconData(0xf05dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">currency_yuan</i> — material icon named "currency yuan". + static const IconData currency_yuan = IconData(0xf04e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">currency_yuan</i> — material icon named "currency yuan" (sharp). + static const IconData currency_yuan_sharp = IconData(0xf03ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">currency_yuan</i> — material icon named "currency yuan" (round). + static const IconData currency_yuan_rounded = IconData(0xf02fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">currency_yuan</i> — material icon named "currency yuan" (outlined). + static const IconData currency_yuan_outlined = IconData(0xf05dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">curtains</i> — material icon named "curtains". + static const IconData curtains = IconData(0xf0795, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">curtains</i> — material icon named "curtains" (sharp). + static const IconData curtains_sharp = IconData(0xf073e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">curtains</i> — material icon named "curtains" (round). + static const IconData curtains_rounded = IconData(0xf07ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">curtains</i> — material icon named "curtains" (outlined). + static const IconData curtains_outlined = IconData(0xf06e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">curtains_closed</i> — material icon named "curtains closed". + static const IconData curtains_closed = IconData(0xf0796, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">curtains_closed</i> — material icon named "curtains closed" (sharp). + static const IconData curtains_closed_sharp = IconData(0xf073d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">curtains_closed</i> — material icon named "curtains closed" (round). + static const IconData curtains_closed_rounded = IconData(0xf07ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">curtains_closed</i> — material icon named "curtains closed" (outlined). + static const IconData curtains_closed_outlined = IconData(0xf06e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cut</i> — material icon named "cut". + static const IconData cut = IconData(0xe191, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cut</i> — material icon named "cut" (sharp). + static const IconData cut_sharp = IconData(0xe88e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cut</i> — material icon named "cut" (round). + static const IconData cut_rounded = IconData(0xf66d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cut</i> — material icon named "cut" (outlined). + static const IconData cut_outlined = IconData(0xef80, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">cyclone</i> — material icon named "cyclone". + static const IconData cyclone = IconData(0xf0797, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">cyclone</i> — material icon named "cyclone" (sharp). + static const IconData cyclone_sharp = IconData(0xf073f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">cyclone</i> — material icon named "cyclone" (round). + static const IconData cyclone_rounded = IconData(0xf07ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">cyclone</i> — material icon named "cyclone" (outlined). + static const IconData cyclone_outlined = IconData(0xf06e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dangerous</i> — material icon named "dangerous". + static const IconData dangerous = IconData(0xe1af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dangerous</i> — material icon named "dangerous" (sharp). + static const IconData dangerous_sharp = IconData(0xe8ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dangerous</i> — material icon named "dangerous" (round). + static const IconData dangerous_rounded = IconData(0xf68b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dangerous</i> — material icon named "dangerous" (outlined). + static const IconData dangerous_outlined = IconData(0xef9e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dark_mode</i> — material icon named "dark mode". + static const IconData dark_mode = IconData(0xe1b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dark_mode</i> — material icon named "dark mode" (sharp). + static const IconData dark_mode_sharp = IconData(0xe8ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dark_mode</i> — material icon named "dark mode" (round). + static const IconData dark_mode_rounded = IconData(0xf68c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dark_mode</i> — material icon named "dark mode" (outlined). + static const IconData dark_mode_outlined = IconData(0xef9f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dashboard</i> — material icon named "dashboard". + static const IconData dashboard = IconData(0xe1b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dashboard</i> — material icon named "dashboard" (sharp). + static const IconData dashboard_sharp = IconData(0xe8af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dashboard</i> — material icon named "dashboard" (round). + static const IconData dashboard_rounded = IconData(0xf68e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dashboard</i> — material icon named "dashboard" (outlined). + static const IconData dashboard_outlined = IconData(0xefa1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dashboard_customize</i> — material icon named "dashboard customize". + static const IconData dashboard_customize = IconData(0xe1b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dashboard_customize</i> — material icon named "dashboard customize" (sharp). + static const IconData dashboard_customize_sharp = IconData(0xe8ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dashboard_customize</i> — material icon named "dashboard customize" (round). + static const IconData dashboard_customize_rounded = IconData(0xf68d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dashboard_customize</i> — material icon named "dashboard customize" (outlined). + static const IconData dashboard_customize_outlined = IconData(0xefa0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">data_array</i> — material icon named "data array". + static const IconData data_array = IconData(0xf04e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">data_array</i> — material icon named "data array" (sharp). + static const IconData data_array_sharp = IconData(0xf03f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">data_array</i> — material icon named "data array" (round). + static const IconData data_array_rounded = IconData(0xf02fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">data_array</i> — material icon named "data array" (outlined). + static const IconData data_array_outlined = IconData(0xf05de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">data_exploration</i> — material icon named "data exploration". + static const IconData data_exploration = IconData(0xf04e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">data_exploration</i> — material icon named "data exploration" (sharp). + static const IconData data_exploration_sharp = IconData(0xf03f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">data_exploration</i> — material icon named "data exploration" (round). + static const IconData data_exploration_rounded = IconData(0xf02fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">data_exploration</i> — material icon named "data exploration" (outlined). + static const IconData data_exploration_outlined = IconData(0xf05df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">data_object</i> — material icon named "data object". + static const IconData data_object = IconData(0xf04e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">data_object</i> — material icon named "data object" (sharp). + static const IconData data_object_sharp = IconData(0xf03f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">data_object</i> — material icon named "data object" (round). + static const IconData data_object_rounded = IconData(0xf02ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">data_object</i> — material icon named "data object" (outlined). + static const IconData data_object_outlined = IconData(0xf05e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">data_saver_off</i> — material icon named "data saver off". + static const IconData data_saver_off = IconData(0xe1b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">data_saver_off</i> — material icon named "data saver off" (sharp). + static const IconData data_saver_off_sharp = IconData(0xe8b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">data_saver_off</i> — material icon named "data saver off" (round). + static const IconData data_saver_off_rounded = IconData(0xf68f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">data_saver_off</i> — material icon named "data saver off" (outlined). + static const IconData data_saver_off_outlined = IconData(0xefa2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">data_saver_on</i> — material icon named "data saver on". + static const IconData data_saver_on = IconData(0xe1b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">data_saver_on</i> — material icon named "data saver on" (sharp). + static const IconData data_saver_on_sharp = IconData(0xe8b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">data_saver_on</i> — material icon named "data saver on" (round). + static const IconData data_saver_on_rounded = IconData(0xf690, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">data_saver_on</i> — material icon named "data saver on" (outlined). + static const IconData data_saver_on_outlined = IconData(0xefa3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">data_thresholding</i> — material icon named "data thresholding". + static const IconData data_thresholding = IconData(0xf04e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">data_thresholding</i> — material icon named "data thresholding" (sharp). + static const IconData data_thresholding_sharp = IconData(0xf03f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">data_thresholding</i> — material icon named "data thresholding" (round). + static const IconData data_thresholding_rounded = IconData(0xf0300, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">data_thresholding</i> — material icon named "data thresholding" (outlined). + static const IconData data_thresholding_outlined = IconData(0xf05e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">data_usage</i> — material icon named "data usage". + static const IconData data_usage = IconData(0xe1b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">data_usage</i> — material icon named "data usage" (sharp). + static const IconData data_usage_sharp = IconData(0xe8b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">data_usage</i> — material icon named "data usage" (round). + static const IconData data_usage_rounded = IconData(0xf691, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">data_usage</i> — material icon named "data usage" (outlined). + static const IconData data_usage_outlined = IconData(0xefa4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dataset</i> — material icon named "dataset". + static const IconData dataset = IconData(0xf0798, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dataset</i> — material icon named "dataset" (sharp). + static const IconData dataset_sharp = IconData(0xf0741, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dataset</i> — material icon named "dataset" (round). + static const IconData dataset_rounded = IconData(0xf07f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dataset</i> — material icon named "dataset" (outlined). + static const IconData dataset_outlined = IconData(0xf06e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dataset_linked</i> — material icon named "dataset linked". + static const IconData dataset_linked = IconData(0xf0799, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dataset_linked</i> — material icon named "dataset linked" (sharp). + static const IconData dataset_linked_sharp = IconData(0xf0740, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dataset_linked</i> — material icon named "dataset linked" (round). + static const IconData dataset_linked_rounded = IconData(0xf07f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dataset_linked</i> — material icon named "dataset linked" (outlined). + static const IconData dataset_linked_outlined = IconData(0xf06e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">date_range</i> — material icon named "date range". + static const IconData date_range = IconData(0xe1b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">date_range</i> — material icon named "date range" (sharp). + static const IconData date_range_sharp = IconData(0xe8b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">date_range</i> — material icon named "date range" (round). + static const IconData date_range_rounded = IconData(0xf692, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">date_range</i> — material icon named "date range" (outlined). + static const IconData date_range_outlined = IconData(0xefa5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">deblur</i> — material icon named "deblur". + static const IconData deblur = IconData(0xf04e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">deblur</i> — material icon named "deblur" (sharp). + static const IconData deblur_sharp = IconData(0xf03f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">deblur</i> — material icon named "deblur" (round). + static const IconData deblur_rounded = IconData(0xf0301, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">deblur</i> — material icon named "deblur" (outlined). + static const IconData deblur_outlined = IconData(0xf05e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">deck</i> — material icon named "deck". + static const IconData deck = IconData(0xe1b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">deck</i> — material icon named "deck" (sharp). + static const IconData deck_sharp = IconData(0xe8b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">deck</i> — material icon named "deck" (round). + static const IconData deck_rounded = IconData(0xf693, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">deck</i> — material icon named "deck" (outlined). + static const IconData deck_outlined = IconData(0xefa6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dehaze</i> — material icon named "dehaze". + static const IconData dehaze = IconData(0xe1b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dehaze</i> — material icon named "dehaze" (sharp). + static const IconData dehaze_sharp = IconData(0xe8b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dehaze</i> — material icon named "dehaze" (round). + static const IconData dehaze_rounded = IconData(0xf694, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dehaze</i> — material icon named "dehaze" (outlined). + static const IconData dehaze_outlined = IconData(0xefa7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">delete</i> — material icon named "delete". + static const IconData delete = IconData(0xe1b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">delete</i> — material icon named "delete" (sharp). + static const IconData delete_sharp = IconData(0xe8b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">delete</i> — material icon named "delete" (round). + static const IconData delete_rounded = IconData(0xf697, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">delete</i> — material icon named "delete" (outlined). + static const IconData delete_outlined = IconData(0xefaa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">delete_forever</i> — material icon named "delete forever". + static const IconData delete_forever = IconData(0xe1ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">delete_forever</i> — material icon named "delete forever" (sharp). + static const IconData delete_forever_sharp = IconData(0xe8b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">delete_forever</i> — material icon named "delete forever" (round). + static const IconData delete_forever_rounded = IconData(0xf695, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">delete_forever</i> — material icon named "delete forever" (outlined). + static const IconData delete_forever_outlined = IconData(0xefa8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">delete_outline</i> — material icon named "delete outline". + static const IconData delete_outline = IconData(0xe1bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">delete_outline</i> — material icon named "delete outline" (sharp). + static const IconData delete_outline_sharp = IconData(0xe8b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">delete_outline</i> — material icon named "delete outline" (round). + static const IconData delete_outline_rounded = IconData(0xf696, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">delete_outline</i> — material icon named "delete outline" (outlined). + static const IconData delete_outline_outlined = IconData(0xefa9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">delete_sweep</i> — material icon named "delete sweep". + static const IconData delete_sweep = IconData(0xe1bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">delete_sweep</i> — material icon named "delete sweep" (sharp). + static const IconData delete_sweep_sharp = IconData(0xe8b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">delete_sweep</i> — material icon named "delete sweep" (round). + static const IconData delete_sweep_rounded = IconData(0xf698, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">delete_sweep</i> — material icon named "delete sweep" (outlined). + static const IconData delete_sweep_outlined = IconData(0xefab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">delivery_dining</i> — material icon named "delivery dining". + static const IconData delivery_dining = IconData(0xe1bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">delivery_dining</i> — material icon named "delivery dining" (sharp). + static const IconData delivery_dining_sharp = IconData(0xe8ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">delivery_dining</i> — material icon named "delivery dining" (round). + static const IconData delivery_dining_rounded = IconData(0xf699, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">delivery_dining</i> — material icon named "delivery dining" (outlined). + static const IconData delivery_dining_outlined = IconData(0xefac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">density_large</i> — material icon named "density large". + static const IconData density_large = IconData(0xf04e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">density_large</i> — material icon named "density large" (sharp). + static const IconData density_large_sharp = IconData(0xf03f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">density_large</i> — material icon named "density large" (round). + static const IconData density_large_rounded = IconData(0xf0302, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">density_large</i> — material icon named "density large" (outlined). + static const IconData density_large_outlined = IconData(0xf05e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">density_medium</i> — material icon named "density medium". + static const IconData density_medium = IconData(0xf04ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">density_medium</i> — material icon named "density medium" (sharp). + static const IconData density_medium_sharp = IconData(0xf03f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">density_medium</i> — material icon named "density medium" (round). + static const IconData density_medium_rounded = IconData(0xf0303, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">density_medium</i> — material icon named "density medium" (outlined). + static const IconData density_medium_outlined = IconData(0xf05e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">density_small</i> — material icon named "density small". + static const IconData density_small = IconData(0xf04eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">density_small</i> — material icon named "density small" (sharp). + static const IconData density_small_sharp = IconData(0xf03f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">density_small</i> — material icon named "density small" (round). + static const IconData density_small_rounded = IconData(0xf0304, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">density_small</i> — material icon named "density small" (outlined). + static const IconData density_small_outlined = IconData(0xf05e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">departure_board</i> — material icon named "departure board". + static const IconData departure_board = IconData(0xe1be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">departure_board</i> — material icon named "departure board" (sharp). + static const IconData departure_board_sharp = IconData(0xe8bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">departure_board</i> — material icon named "departure board" (round). + static const IconData departure_board_rounded = IconData(0xf69a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">departure_board</i> — material icon named "departure board" (outlined). + static const IconData departure_board_outlined = IconData(0xefad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">description</i> — material icon named "description". + static const IconData description = IconData(0xe1bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">description</i> — material icon named "description" (sharp). + static const IconData description_sharp = IconData(0xe8bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">description</i> — material icon named "description" (round). + static const IconData description_rounded = IconData(0xf69b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">description</i> — material icon named "description" (outlined). + static const IconData description_outlined = IconData(0xefae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">deselect</i> — material icon named "deselect". + static const IconData deselect = IconData(0xf04ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">deselect</i> — material icon named "deselect" (sharp). + static const IconData deselect_sharp = IconData(0xf03f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">deselect</i> — material icon named "deselect" (round). + static const IconData deselect_rounded = IconData(0xf0305, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">deselect</i> — material icon named "deselect" (outlined). + static const IconData deselect_outlined = IconData(0xf05e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">design_services</i> — material icon named "design services". + static const IconData design_services = IconData(0xe1c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">design_services</i> — material icon named "design services" (sharp). + static const IconData design_services_sharp = IconData(0xe8bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">design_services</i> — material icon named "design services" (round). + static const IconData design_services_rounded = IconData(0xf69c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">design_services</i> — material icon named "design services" (outlined). + static const IconData design_services_outlined = IconData(0xefaf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">desk</i> — material icon named "desk". + static const IconData desk = IconData(0xf079a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">desk</i> — material icon named "desk" (sharp). + static const IconData desk_sharp = IconData(0xf0742, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">desk</i> — material icon named "desk" (round). + static const IconData desk_rounded = IconData(0xf07f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">desk</i> — material icon named "desk" (outlined). + static const IconData desk_outlined = IconData(0xf06ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">desktop_access_disabled</i> — material icon named "desktop access disabled". + static const IconData desktop_access_disabled = IconData(0xe1c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">desktop_access_disabled</i> — material icon named "desktop access disabled" (sharp). + static const IconData desktop_access_disabled_sharp = IconData(0xe8be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">desktop_access_disabled</i> — material icon named "desktop access disabled" (round). + static const IconData desktop_access_disabled_rounded = IconData(0xf69d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">desktop_access_disabled</i> — material icon named "desktop access disabled" (outlined). + static const IconData desktop_access_disabled_outlined = IconData(0xefb0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">desktop_mac</i> — material icon named "desktop mac". + static const IconData desktop_mac = IconData(0xe1c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">desktop_mac</i> — material icon named "desktop mac" (sharp). + static const IconData desktop_mac_sharp = IconData(0xe8bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">desktop_mac</i> — material icon named "desktop mac" (round). + static const IconData desktop_mac_rounded = IconData(0xf69e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">desktop_mac</i> — material icon named "desktop mac" (outlined). + static const IconData desktop_mac_outlined = IconData(0xefb1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">desktop_windows</i> — material icon named "desktop windows". + static const IconData desktop_windows = IconData(0xe1c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">desktop_windows</i> — material icon named "desktop windows" (sharp). + static const IconData desktop_windows_sharp = IconData(0xe8c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">desktop_windows</i> — material icon named "desktop windows" (round). + static const IconData desktop_windows_rounded = IconData(0xf69f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">desktop_windows</i> — material icon named "desktop windows" (outlined). + static const IconData desktop_windows_outlined = IconData(0xefb2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">details</i> — material icon named "details". + static const IconData details = IconData(0xe1c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">details</i> — material icon named "details" (sharp). + static const IconData details_sharp = IconData(0xe8c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">details</i> — material icon named "details" (round). + static const IconData details_rounded = IconData(0xf6a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">details</i> — material icon named "details" (outlined). + static const IconData details_outlined = IconData(0xefb3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">developer_board</i> — material icon named "developer board". + static const IconData developer_board = IconData(0xe1c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">developer_board</i> — material icon named "developer board" (sharp). + static const IconData developer_board_sharp = IconData(0xe8c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">developer_board</i> — material icon named "developer board" (round). + static const IconData developer_board_rounded = IconData(0xf6a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">developer_board</i> — material icon named "developer board" (outlined). + static const IconData developer_board_outlined = IconData(0xefb5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">developer_board_off</i> — material icon named "developer board off". + static const IconData developer_board_off = IconData(0xe1c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">developer_board_off</i> — material icon named "developer board off" (sharp). + static const IconData developer_board_off_sharp = IconData(0xe8c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">developer_board_off</i> — material icon named "developer board off" (round). + static const IconData developer_board_off_rounded = IconData(0xf6a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">developer_board_off</i> — material icon named "developer board off" (outlined). + static const IconData developer_board_off_outlined = IconData(0xefb4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">developer_mode</i> — material icon named "developer mode". + static const IconData developer_mode = IconData(0xe1c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">developer_mode</i> — material icon named "developer mode" (sharp). + static const IconData developer_mode_sharp = IconData(0xe8c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">developer_mode</i> — material icon named "developer mode" (round). + static const IconData developer_mode_rounded = IconData(0xf6a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">developer_mode</i> — material icon named "developer mode" (outlined). + static const IconData developer_mode_outlined = IconData(0xefb6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">device_hub</i> — material icon named "device hub". + static const IconData device_hub = IconData(0xe1c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">device_hub</i> — material icon named "device hub" (sharp). + static const IconData device_hub_sharp = IconData(0xe8c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">device_hub</i> — material icon named "device hub" (round). + static const IconData device_hub_rounded = IconData(0xf6a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">device_hub</i> — material icon named "device hub" (outlined). + static const IconData device_hub_outlined = IconData(0xefb7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">device_thermostat</i> — material icon named "device thermostat". + static const IconData device_thermostat = IconData(0xe1c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">device_thermostat</i> — material icon named "device thermostat" (sharp). + static const IconData device_thermostat_sharp = IconData(0xe8c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">device_thermostat</i> — material icon named "device thermostat" (round). + static const IconData device_thermostat_rounded = IconData(0xf6a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">device_thermostat</i> — material icon named "device thermostat" (outlined). + static const IconData device_thermostat_outlined = IconData(0xefb8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">device_unknown</i> — material icon named "device unknown". + static const IconData device_unknown = IconData(0xe1ca, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">device_unknown</i> — material icon named "device unknown" (sharp). + static const IconData device_unknown_sharp = IconData(0xe8c7, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">device_unknown</i> — material icon named "device unknown" (round). + static const IconData device_unknown_rounded = IconData(0xf6a6, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">device_unknown</i> — material icon named "device unknown" (outlined). + static const IconData device_unknown_outlined = IconData(0xefb9, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">devices</i> — material icon named "devices". + static const IconData devices = IconData(0xe1cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">devices</i> — material icon named "devices" (sharp). + static const IconData devices_sharp = IconData(0xe8c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">devices</i> — material icon named "devices" (round). + static const IconData devices_rounded = IconData(0xf6a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">devices</i> — material icon named "devices" (outlined). + static const IconData devices_outlined = IconData(0xefbb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">devices_fold</i> — material icon named "devices fold". + static const IconData devices_fold = IconData(0xf079b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">devices_fold</i> — material icon named "devices fold" (sharp). + static const IconData devices_fold_sharp = IconData(0xf0743, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">devices_fold</i> — material icon named "devices fold" (round). + static const IconData devices_fold_rounded = IconData(0xf07f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">devices_fold</i> — material icon named "devices fold" (outlined). + static const IconData devices_fold_outlined = IconData(0xf06eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">devices_other</i> — material icon named "devices other". + static const IconData devices_other = IconData(0xe1cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">devices_other</i> — material icon named "devices other" (sharp). + static const IconData devices_other_sharp = IconData(0xe8c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">devices_other</i> — material icon named "devices other" (round). + static const IconData devices_other_rounded = IconData(0xf6a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">devices_other</i> — material icon named "devices other" (outlined). + static const IconData devices_other_outlined = IconData(0xefba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dew_point</i> — material icon named "dew point". + static const IconData dew_point = IconData(0xf0859, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dialer_sip</i> — material icon named "dialer sip". + static const IconData dialer_sip = IconData(0xe1cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dialer_sip</i> — material icon named "dialer sip" (sharp). + static const IconData dialer_sip_sharp = IconData(0xe8ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dialer_sip</i> — material icon named "dialer sip" (round). + static const IconData dialer_sip_rounded = IconData(0xf6a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dialer_sip</i> — material icon named "dialer sip" (outlined). + static const IconData dialer_sip_outlined = IconData(0xefbc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dialpad</i> — material icon named "dialpad". + static const IconData dialpad = IconData(0xe1ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dialpad</i> — material icon named "dialpad" (sharp). + static const IconData dialpad_sharp = IconData(0xe8cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dialpad</i> — material icon named "dialpad" (round). + static const IconData dialpad_rounded = IconData(0xf6aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dialpad</i> — material icon named "dialpad" (outlined). + static const IconData dialpad_outlined = IconData(0xefbd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">diamond</i> — material icon named "diamond". + static const IconData diamond = IconData(0xf04ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">diamond</i> — material icon named "diamond" (sharp). + static const IconData diamond_sharp = IconData(0xf03f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">diamond</i> — material icon named "diamond" (round). + static const IconData diamond_rounded = IconData(0xf0306, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">diamond</i> — material icon named "diamond" (outlined). + static const IconData diamond_outlined = IconData(0xf05e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">difference</i> — material icon named "difference". + static const IconData difference = IconData(0xf04ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">difference</i> — material icon named "difference" (sharp). + static const IconData difference_sharp = IconData(0xf03fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">difference</i> — material icon named "difference" (round). + static const IconData difference_rounded = IconData(0xf0307, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">difference</i> — material icon named "difference" (outlined). + static const IconData difference_outlined = IconData(0xf05e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dining</i> — material icon named "dining". + static const IconData dining = IconData(0xe1cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dining</i> — material icon named "dining" (sharp). + static const IconData dining_sharp = IconData(0xe8cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dining</i> — material icon named "dining" (round). + static const IconData dining_rounded = IconData(0xf6ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dining</i> — material icon named "dining" (outlined). + static const IconData dining_outlined = IconData(0xefbe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dinner_dining</i> — material icon named "dinner dining". + static const IconData dinner_dining = IconData(0xe1d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dinner_dining</i> — material icon named "dinner dining" (sharp). + static const IconData dinner_dining_sharp = IconData(0xe8cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dinner_dining</i> — material icon named "dinner dining" (round). + static const IconData dinner_dining_rounded = IconData(0xf6ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dinner_dining</i> — material icon named "dinner dining" (outlined). + static const IconData dinner_dining_outlined = IconData(0xefbf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions</i> — material icon named "directions". + static const IconData directions = IconData(0xe1d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions</i> — material icon named "directions" (sharp). + static const IconData directions_sharp = IconData(0xe8d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions</i> — material icon named "directions" (round). + static const IconData directions_rounded = IconData(0xf6b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions</i> — material icon named "directions" (outlined). + static const IconData directions_outlined = IconData(0xefc8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_bike</i> — material icon named "directions bike". + static const IconData directions_bike = IconData(0xe1d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_bike</i> — material icon named "directions bike" (sharp). + static const IconData directions_bike_sharp = IconData(0xe8ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_bike</i> — material icon named "directions bike" (round). + static const IconData directions_bike_rounded = IconData(0xf6ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_bike</i> — material icon named "directions bike" (outlined). + static const IconData directions_bike_outlined = IconData(0xefc0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_boat</i> — material icon named "directions boat". + static const IconData directions_boat = IconData(0xe1d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_boat</i> — material icon named "directions boat" (sharp). + static const IconData directions_boat_sharp = IconData(0xe8d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_boat</i> — material icon named "directions boat" (round). + static const IconData directions_boat_rounded = IconData(0xf6af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_boat</i> — material icon named "directions boat" (outlined). + static const IconData directions_boat_outlined = IconData(0xefc2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_boat_filled</i> — material icon named "directions boat filled". + static const IconData directions_boat_filled = IconData(0xe1d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_boat_filled</i> — material icon named "directions boat filled" (sharp). + static const IconData directions_boat_filled_sharp = IconData(0xe8cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_boat_filled</i> — material icon named "directions boat filled" (round). + static const IconData directions_boat_filled_rounded = IconData(0xf6ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_boat_filled</i> — material icon named "directions boat filled" (outlined). + static const IconData directions_boat_filled_outlined = IconData(0xefc1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_bus</i> — material icon named "directions bus". + static const IconData directions_bus = IconData(0xe1d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_bus</i> — material icon named "directions bus" (sharp). + static const IconData directions_bus_sharp = IconData(0xe8d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_bus</i> — material icon named "directions bus" (round). + static const IconData directions_bus_rounded = IconData(0xf6b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_bus</i> — material icon named "directions bus" (outlined). + static const IconData directions_bus_outlined = IconData(0xefc4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_bus_filled</i> — material icon named "directions bus filled". + static const IconData directions_bus_filled = IconData(0xe1d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_bus_filled</i> — material icon named "directions bus filled" (sharp). + static const IconData directions_bus_filled_sharp = IconData(0xe8d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_bus_filled</i> — material icon named "directions bus filled" (round). + static const IconData directions_bus_filled_rounded = IconData(0xf6b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_bus_filled</i> — material icon named "directions bus filled" (outlined). + static const IconData directions_bus_filled_outlined = IconData(0xefc3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_car</i> — material icon named "directions car". + static const IconData directions_car = IconData(0xe1d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_car</i> — material icon named "directions car" (sharp). + static const IconData directions_car_sharp = IconData(0xe8d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_car</i> — material icon named "directions car" (round). + static const IconData directions_car_rounded = IconData(0xf6b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_car</i> — material icon named "directions car" (outlined). + static const IconData directions_car_outlined = IconData(0xefc6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_car_filled</i> — material icon named "directions car filled". + static const IconData directions_car_filled = IconData(0xe1d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_car_filled</i> — material icon named "directions car filled" (sharp). + static const IconData directions_car_filled_sharp = IconData(0xe8d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_car_filled</i> — material icon named "directions car filled" (round). + static const IconData directions_car_filled_rounded = IconData(0xf6b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_car_filled</i> — material icon named "directions car filled" (outlined). + static const IconData directions_car_filled_outlined = IconData(0xefc5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_ferry</i> — material icon named "directions ferry". + static const IconData directions_ferry = IconData(0xe1d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_ferry</i> — material icon named "directions ferry" (sharp). + static const IconData directions_ferry_sharp = IconData(0xe8d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_ferry</i> — material icon named "directions ferry" (round). + static const IconData directions_ferry_rounded = IconData(0xf6af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_ferry</i> — material icon named "directions ferry" (outlined). + static const IconData directions_ferry_outlined = IconData(0xefc2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_off</i> — material icon named "directions off". + static const IconData directions_off = IconData(0xe1d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_off</i> — material icon named "directions off" (sharp). + static const IconData directions_off_sharp = IconData(0xe8d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_off</i> — material icon named "directions off" (round). + static const IconData directions_off_rounded = IconData(0xf6b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_off</i> — material icon named "directions off" (outlined). + static const IconData directions_off_outlined = IconData(0xefc7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_railway</i> — material icon named "directions railway". + static const IconData directions_railway = IconData(0xe1da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_railway</i> — material icon named "directions railway" (sharp). + static const IconData directions_railway_sharp = IconData(0xe8d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_railway</i> — material icon named "directions railway" (round). + static const IconData directions_railway_rounded = IconData(0xf6b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_railway</i> — material icon named "directions railway" (outlined). + static const IconData directions_railway_outlined = IconData(0xefca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_railway_filled</i> — material icon named "directions railway filled". + static const IconData directions_railway_filled = IconData(0xe1db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_railway_filled</i> — material icon named "directions railway filled" (sharp). + static const IconData directions_railway_filled_sharp = IconData(0xe8d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_railway_filled</i> — material icon named "directions railway filled" (round). + static const IconData directions_railway_filled_rounded = IconData(0xf6b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_railway_filled</i> — material icon named "directions railway filled" (outlined). + static const IconData directions_railway_filled_outlined = IconData(0xefc9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_run</i> — material icon named "directions run". + static const IconData directions_run = IconData(0xe1dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_run</i> — material icon named "directions run" (sharp). + static const IconData directions_run_sharp = IconData(0xe8d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_run</i> — material icon named "directions run" (round). + static const IconData directions_run_rounded = IconData(0xf6b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_run</i> — material icon named "directions run" (outlined). + static const IconData directions_run_outlined = IconData(0xefcb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_subway</i> — material icon named "directions subway". + static const IconData directions_subway = IconData(0xe1dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_subway</i> — material icon named "directions subway" (sharp). + static const IconData directions_subway_sharp = IconData(0xe8db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_subway</i> — material icon named "directions subway" (round). + static const IconData directions_subway_rounded = IconData(0xf6ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_subway</i> — material icon named "directions subway" (outlined). + static const IconData directions_subway_outlined = IconData(0xefcd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_subway_filled</i> — material icon named "directions subway filled". + static const IconData directions_subway_filled = IconData(0xe1de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_subway_filled</i> — material icon named "directions subway filled" (sharp). + static const IconData directions_subway_filled_sharp = IconData(0xe8da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_subway_filled</i> — material icon named "directions subway filled" (round). + static const IconData directions_subway_filled_rounded = IconData(0xf6b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_subway_filled</i> — material icon named "directions subway filled" (outlined). + static const IconData directions_subway_filled_outlined = IconData(0xefcc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_train</i> — material icon named "directions train". + static const IconData directions_train = IconData(0xe1da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_train</i> — material icon named "directions train" (sharp). + static const IconData directions_train_sharp = IconData(0xe8d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_train</i> — material icon named "directions train" (round). + static const IconData directions_train_rounded = IconData(0xf6b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_train</i> — material icon named "directions train" (outlined). + static const IconData directions_train_outlined = IconData(0xefca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_transit</i> — material icon named "directions transit". + static const IconData directions_transit = IconData(0xe1df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_transit</i> — material icon named "directions transit" (sharp). + static const IconData directions_transit_sharp = IconData(0xe8dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_transit</i> — material icon named "directions transit" (round). + static const IconData directions_transit_rounded = IconData(0xf6bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_transit</i> — material icon named "directions transit" (outlined). + static const IconData directions_transit_outlined = IconData(0xefcf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_transit_filled</i> — material icon named "directions transit filled". + static const IconData directions_transit_filled = IconData(0xe1e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_transit_filled</i> — material icon named "directions transit filled" (sharp). + static const IconData directions_transit_filled_sharp = IconData(0xe8dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_transit_filled</i> — material icon named "directions transit filled" (round). + static const IconData directions_transit_filled_rounded = IconData(0xf6bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_transit_filled</i> — material icon named "directions transit filled" (outlined). + static const IconData directions_transit_filled_outlined = IconData(0xefce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">directions_walk</i> — material icon named "directions walk". + static const IconData directions_walk = IconData(0xe1e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">directions_walk</i> — material icon named "directions walk" (sharp). + static const IconData directions_walk_sharp = IconData(0xe8de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">directions_walk</i> — material icon named "directions walk" (round). + static const IconData directions_walk_rounded = IconData(0xf6bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">directions_walk</i> — material icon named "directions walk" (outlined). + static const IconData directions_walk_outlined = IconData(0xefd0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dirty_lens</i> — material icon named "dirty lens". + static const IconData dirty_lens = IconData(0xe1e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dirty_lens</i> — material icon named "dirty lens" (sharp). + static const IconData dirty_lens_sharp = IconData(0xe8df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dirty_lens</i> — material icon named "dirty lens" (round). + static const IconData dirty_lens_rounded = IconData(0xf6be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dirty_lens</i> — material icon named "dirty lens" (outlined). + static const IconData dirty_lens_outlined = IconData(0xefd1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">disabled_by_default</i> — material icon named "disabled by default". + static const IconData disabled_by_default = IconData(0xe1e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">disabled_by_default</i> — material icon named "disabled by default" (sharp). + static const IconData disabled_by_default_sharp = IconData(0xe8e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">disabled_by_default</i> — material icon named "disabled by default" (round). + static const IconData disabled_by_default_rounded = IconData(0xf6bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">disabled_by_default</i> — material icon named "disabled by default" (outlined). + static const IconData disabled_by_default_outlined = IconData(0xefd2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">disabled_visible</i> — material icon named "disabled visible". + static const IconData disabled_visible = IconData(0xf04ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">disabled_visible</i> — material icon named "disabled visible" (sharp). + static const IconData disabled_visible_sharp = IconData(0xf03fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">disabled_visible</i> — material icon named "disabled visible" (round). + static const IconData disabled_visible_rounded = IconData(0xf0308, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">disabled_visible</i> — material icon named "disabled visible" (outlined). + static const IconData disabled_visible_outlined = IconData(0xf05e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">disc_full</i> — material icon named "disc full". + static const IconData disc_full = IconData(0xe1e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">disc_full</i> — material icon named "disc full" (sharp). + static const IconData disc_full_sharp = IconData(0xe8e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">disc_full</i> — material icon named "disc full" (round). + static const IconData disc_full_rounded = IconData(0xf6c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">disc_full</i> — material icon named "disc full" (outlined). + static const IconData disc_full_outlined = IconData(0xefd3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">discord</i> — material icon named "discord". + static const IconData discord = IconData(0xf04f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">discord</i> — material icon named "discord" (sharp). + static const IconData discord_sharp = IconData(0xf03fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">discord</i> — material icon named "discord" (round). + static const IconData discord_rounded = IconData(0xf0309, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">discord</i> — material icon named "discord" (outlined). + static const IconData discord_outlined = IconData(0xf05ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">discount</i> — material icon named "discount". + static const IconData discount = IconData(0xf06bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">discount</i> — material icon named "discount" (sharp). + static const IconData discount_sharp = IconData(0xf06b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">discount</i> — material icon named "discount" (round). + static const IconData discount_rounded = IconData(0xf06ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">discount</i> — material icon named "discount" (outlined). + static const IconData discount_outlined = IconData(0xf06a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">display_settings</i> — material icon named "display settings". + static const IconData display_settings = IconData(0xf04f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">display_settings</i> — material icon named "display settings" (sharp). + static const IconData display_settings_sharp = IconData(0xf03fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">display_settings</i> — material icon named "display settings" (round). + static const IconData display_settings_rounded = IconData(0xf030a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">display_settings</i> — material icon named "display settings" (outlined). + static const IconData display_settings_outlined = IconData(0xf05eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">diversity_1</i> — material icon named "diversity 1". + static const IconData diversity_1 = IconData(0xf085a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">diversity_1</i> — material icon named "diversity 1" (sharp). + static const IconData diversity_1_sharp = IconData(0xf0838, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">diversity_1</i> — material icon named "diversity 1" (round). + static const IconData diversity_1_rounded = IconData(0xf0881, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">diversity_1</i> — material icon named "diversity 1" (outlined). + static const IconData diversity_1_outlined = IconData(0xf089f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">diversity_2</i> — material icon named "diversity 2". + static const IconData diversity_2 = IconData(0xf085b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">diversity_2</i> — material icon named "diversity 2" (sharp). + static const IconData diversity_2_sharp = IconData(0xf0839, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">diversity_2</i> — material icon named "diversity 2" (round). + static const IconData diversity_2_rounded = IconData(0xf0882, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">diversity_2</i> — material icon named "diversity 2" (outlined). + static const IconData diversity_2_outlined = IconData(0xf08a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">diversity_3</i> — material icon named "diversity 3". + static const IconData diversity_3 = IconData(0xf085c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">diversity_3</i> — material icon named "diversity 3" (sharp). + static const IconData diversity_3_sharp = IconData(0xf083a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">diversity_3</i> — material icon named "diversity 3" (round). + static const IconData diversity_3_rounded = IconData(0xf0883, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">diversity_3</i> — material icon named "diversity 3" (outlined). + static const IconData diversity_3_outlined = IconData(0xf08a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dnd_forwardslash</i> — material icon named "dnd forwardslash". + static const IconData dnd_forwardslash = IconData(0xe1eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dnd_forwardslash</i> — material icon named "dnd forwardslash" (sharp). + static const IconData dnd_forwardslash_sharp = IconData(0xe8e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dnd_forwardslash</i> — material icon named "dnd forwardslash" (round). + static const IconData dnd_forwardslash_rounded = IconData(0xf6c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dnd_forwardslash</i> — material icon named "dnd forwardslash" (outlined). + static const IconData dnd_forwardslash_outlined = IconData(0xefd9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dns</i> — material icon named "dns". + static const IconData dns = IconData(0xe1e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dns</i> — material icon named "dns" (sharp). + static const IconData dns_sharp = IconData(0xe8e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dns</i> — material icon named "dns" (round). + static const IconData dns_rounded = IconData(0xf6c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dns</i> — material icon named "dns" (outlined). + static const IconData dns_outlined = IconData(0xefd4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_disturb</i> — material icon named "do disturb". + static const IconData do_disturb = IconData(0xe1e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_disturb</i> — material icon named "do disturb" (sharp). + static const IconData do_disturb_sharp = IconData(0xe8e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_disturb</i> — material icon named "do disturb" (round). + static const IconData do_disturb_rounded = IconData(0xf6c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_disturb</i> — material icon named "do disturb" (outlined). + static const IconData do_disturb_outlined = IconData(0xefd8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_disturb_alt</i> — material icon named "do disturb alt". + static const IconData do_disturb_alt = IconData(0xe1e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_disturb_alt</i> — material icon named "do disturb alt" (sharp). + static const IconData do_disturb_alt_sharp = IconData(0xe8e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_disturb_alt</i> — material icon named "do disturb alt" (round). + static const IconData do_disturb_alt_rounded = IconData(0xf6c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_disturb_alt</i> — material icon named "do disturb alt" (outlined). + static const IconData do_disturb_alt_outlined = IconData(0xefd5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_disturb_off</i> — material icon named "do disturb off". + static const IconData do_disturb_off = IconData(0xe1e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_disturb_off</i> — material icon named "do disturb off" (sharp). + static const IconData do_disturb_off_sharp = IconData(0xe8e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_disturb_off</i> — material icon named "do disturb off" (round). + static const IconData do_disturb_off_rounded = IconData(0xf6c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_disturb_off</i> — material icon named "do disturb off" (outlined). + static const IconData do_disturb_off_outlined = IconData(0xefd6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_disturb_on</i> — material icon named "do disturb on". + static const IconData do_disturb_on = IconData(0xe1e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_disturb_on</i> — material icon named "do disturb on" (sharp). + static const IconData do_disturb_on_sharp = IconData(0xe8e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_disturb_on</i> — material icon named "do disturb on" (round). + static const IconData do_disturb_on_rounded = IconData(0xf6c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_disturb_on</i> — material icon named "do disturb on" (outlined). + static const IconData do_disturb_on_outlined = IconData(0xefd7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_not_disturb</i> — material icon named "do not disturb". + static const IconData do_not_disturb = IconData(0xe1ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_not_disturb</i> — material icon named "do not disturb" (sharp). + static const IconData do_not_disturb_sharp = IconData(0xe8eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_not_disturb</i> — material icon named "do not disturb" (round). + static const IconData do_not_disturb_rounded = IconData(0xf6ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_not_disturb</i> — material icon named "do not disturb" (outlined). + static const IconData do_not_disturb_outlined = IconData(0xefdd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_not_disturb_alt</i> — material icon named "do not disturb alt". + static const IconData do_not_disturb_alt = IconData(0xe1eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_not_disturb_alt</i> — material icon named "do not disturb alt" (sharp). + static const IconData do_not_disturb_alt_sharp = IconData(0xe8e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_not_disturb_alt</i> — material icon named "do not disturb alt" (round). + static const IconData do_not_disturb_alt_rounded = IconData(0xf6c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_not_disturb_alt</i> — material icon named "do not disturb alt" (outlined). + static const IconData do_not_disturb_alt_outlined = IconData(0xefd9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_not_disturb_off</i> — material icon named "do not disturb off". + static const IconData do_not_disturb_off = IconData(0xe1ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_not_disturb_off</i> — material icon named "do not disturb off" (sharp). + static const IconData do_not_disturb_off_sharp = IconData(0xe8e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_not_disturb_off</i> — material icon named "do not disturb off" (round). + static const IconData do_not_disturb_off_rounded = IconData(0xf6c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_not_disturb_off</i> — material icon named "do not disturb off" (outlined). + static const IconData do_not_disturb_off_outlined = IconData(0xefda, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_not_disturb_on</i> — material icon named "do not disturb on". + static const IconData do_not_disturb_on = IconData(0xe1ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_not_disturb_on</i> — material icon named "do not disturb on" (sharp). + static const IconData do_not_disturb_on_sharp = IconData(0xe8e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_not_disturb_on</i> — material icon named "do not disturb on" (round). + static const IconData do_not_disturb_on_rounded = IconData(0xf6c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_not_disturb_on</i> — material icon named "do not disturb on" (outlined). + static const IconData do_not_disturb_on_outlined = IconData(0xefdb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_not_disturb_on_total_silence</i> — material icon named "do not disturb on total silence". + static const IconData do_not_disturb_on_total_silence = IconData(0xe1ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_not_disturb_on_total_silence</i> — material icon named "do not disturb on total silence" (sharp). + static const IconData do_not_disturb_on_total_silence_sharp = IconData(0xe8ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_not_disturb_on_total_silence</i> — material icon named "do not disturb on total silence" (round). + static const IconData do_not_disturb_on_total_silence_rounded = IconData(0xf6c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_not_disturb_on_total_silence</i> — material icon named "do not disturb on total silence" (outlined). + static const IconData do_not_disturb_on_total_silence_outlined = IconData(0xefdc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_not_step</i> — material icon named "do not step". + static const IconData do_not_step = IconData(0xe1ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_not_step</i> — material icon named "do not step" (sharp). + static const IconData do_not_step_sharp = IconData(0xe8ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_not_step</i> — material icon named "do not step" (round). + static const IconData do_not_step_rounded = IconData(0xf6cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_not_step</i> — material icon named "do not step" (outlined). + static const IconData do_not_step_outlined = IconData(0xefde, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">do_not_touch</i> — material icon named "do not touch". + static const IconData do_not_touch = IconData(0xe1f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">do_not_touch</i> — material icon named "do not touch" (sharp). + static const IconData do_not_touch_sharp = IconData(0xe8ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">do_not_touch</i> — material icon named "do not touch" (round). + static const IconData do_not_touch_rounded = IconData(0xf6cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">do_not_touch</i> — material icon named "do not touch" (outlined). + static const IconData do_not_touch_outlined = IconData(0xefdf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dock</i> — material icon named "dock". + static const IconData dock = IconData(0xe1f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dock</i> — material icon named "dock" (sharp). + static const IconData dock_sharp = IconData(0xe8ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dock</i> — material icon named "dock" (round). + static const IconData dock_rounded = IconData(0xf6cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dock</i> — material icon named "dock" (outlined). + static const IconData dock_outlined = IconData(0xefe0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">document_scanner</i> — material icon named "document scanner". + static const IconData document_scanner = IconData(0xe1f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">document_scanner</i> — material icon named "document scanner" (sharp). + static const IconData document_scanner_sharp = IconData(0xe8ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">document_scanner</i> — material icon named "document scanner" (round). + static const IconData document_scanner_rounded = IconData(0xf6ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">document_scanner</i> — material icon named "document scanner" (outlined). + static const IconData document_scanner_outlined = IconData(0xefe1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">domain</i> — material icon named "domain". + static const IconData domain = IconData(0xe1f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">domain</i> — material icon named "domain" (sharp). + static const IconData domain_sharp = IconData(0xe8f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">domain</i> — material icon named "domain" (round). + static const IconData domain_rounded = IconData(0xf6d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">domain</i> — material icon named "domain" (outlined). + static const IconData domain_outlined = IconData(0xefe3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">domain_add</i> — material icon named "domain add". + static const IconData domain_add = IconData(0xf04f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">domain_add</i> — material icon named "domain add" (sharp). + static const IconData domain_add_sharp = IconData(0xf03fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">domain_add</i> — material icon named "domain add" (round). + static const IconData domain_add_rounded = IconData(0xf030b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">domain_add</i> — material icon named "domain add" (outlined). + static const IconData domain_add_outlined = IconData(0xf05ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">domain_disabled</i> — material icon named "domain disabled". + static const IconData domain_disabled = IconData(0xe1f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">domain_disabled</i> — material icon named "domain disabled" (sharp). + static const IconData domain_disabled_sharp = IconData(0xe8f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">domain_disabled</i> — material icon named "domain disabled" (round). + static const IconData domain_disabled_rounded = IconData(0xf6cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">domain_disabled</i> — material icon named "domain disabled" (outlined). + static const IconData domain_disabled_outlined = IconData(0xefe2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">domain_verification</i> — material icon named "domain verification". + static const IconData domain_verification = IconData(0xe1f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">domain_verification</i> — material icon named "domain verification" (sharp). + static const IconData domain_verification_sharp = IconData(0xe8f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">domain_verification</i> — material icon named "domain verification" (round). + static const IconData domain_verification_rounded = IconData(0xf6d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">domain_verification</i> — material icon named "domain verification" (outlined). + static const IconData domain_verification_outlined = IconData(0xefe4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">done</i> — material icon named "done". + static const IconData done = IconData(0xe1f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">done</i> — material icon named "done" (sharp). + static const IconData done_sharp = IconData(0xe8f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">done</i> — material icon named "done" (round). + static const IconData done_rounded = IconData(0xf6d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">done</i> — material icon named "done" (outlined). + static const IconData done_outlined = IconData(0xefe7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">done_all</i> — material icon named "done all". + static const IconData done_all = IconData(0xe1f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">done_all</i> — material icon named "done all" (sharp). + static const IconData done_all_sharp = IconData(0xe8f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">done_all</i> — material icon named "done all" (round). + static const IconData done_all_rounded = IconData(0xf6d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">done_all</i> — material icon named "done all" (outlined). + static const IconData done_all_outlined = IconData(0xefe5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">done_outline</i> — material icon named "done outline". + static const IconData done_outline = IconData(0xe1f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">done_outline</i> — material icon named "done outline" (sharp). + static const IconData done_outline_sharp = IconData(0xe8f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">done_outline</i> — material icon named "done outline" (round). + static const IconData done_outline_rounded = IconData(0xf6d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">done_outline</i> — material icon named "done outline" (outlined). + static const IconData done_outline_outlined = IconData(0xefe6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">donut_large</i> — material icon named "donut large". + static const IconData donut_large = IconData(0xe1f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">donut_large</i> — material icon named "donut large" (sharp). + static const IconData donut_large_sharp = IconData(0xe8f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">donut_large</i> — material icon named "donut large" (round). + static const IconData donut_large_rounded = IconData(0xf6d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">donut_large</i> — material icon named "donut large" (outlined). + static const IconData donut_large_outlined = IconData(0xefe8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">donut_small</i> — material icon named "donut small". + static const IconData donut_small = IconData(0xe1fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">donut_small</i> — material icon named "donut small" (sharp). + static const IconData donut_small_sharp = IconData(0xe8f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">donut_small</i> — material icon named "donut small" (round). + static const IconData donut_small_rounded = IconData(0xf6d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">donut_small</i> — material icon named "donut small" (outlined). + static const IconData donut_small_outlined = IconData(0xefe9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">door_back</i> — material icon named "door back". + static const IconData door_back_door = IconData(0xe1fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">door_back</i> — material icon named "door back" (sharp). + static const IconData door_back_door_sharp = IconData(0xe8f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">door_back</i> — material icon named "door back" (round). + static const IconData door_back_door_rounded = IconData(0xf6d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">door_back</i> — material icon named "door back" (outlined). + static const IconData door_back_door_outlined = IconData(0xefea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">door_front</i> — material icon named "door front". + static const IconData door_front_door = IconData(0xe1fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">door_front</i> — material icon named "door front" (sharp). + static const IconData door_front_door_sharp = IconData(0xe8f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">door_front</i> — material icon named "door front" (round). + static const IconData door_front_door_rounded = IconData(0xf6d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">door_front</i> — material icon named "door front" (outlined). + static const IconData door_front_door_outlined = IconData(0xefeb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">door_sliding</i> — material icon named "door sliding". + static const IconData door_sliding = IconData(0xe1fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">door_sliding</i> — material icon named "door sliding" (sharp). + static const IconData door_sliding_sharp = IconData(0xe8fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">door_sliding</i> — material icon named "door sliding" (round). + static const IconData door_sliding_rounded = IconData(0xf6d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">door_sliding</i> — material icon named "door sliding" (outlined). + static const IconData door_sliding_outlined = IconData(0xefec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">doorbell</i> — material icon named "doorbell". + static const IconData doorbell = IconData(0xe1fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">doorbell</i> — material icon named "doorbell" (sharp). + static const IconData doorbell_sharp = IconData(0xe8fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">doorbell</i> — material icon named "doorbell" (round). + static const IconData doorbell_rounded = IconData(0xf6da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">doorbell</i> — material icon named "doorbell" (outlined). + static const IconData doorbell_outlined = IconData(0xefed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">double_arrow</i> — material icon named "double arrow". + static const IconData double_arrow = IconData(0xe1ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">double_arrow</i> — material icon named "double arrow" (sharp). + static const IconData double_arrow_sharp = IconData(0xe8fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">double_arrow</i> — material icon named "double arrow" (round). + static const IconData double_arrow_rounded = IconData(0xf6db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">double_arrow</i> — material icon named "double arrow" (outlined). + static const IconData double_arrow_outlined = IconData(0xefee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">downhill_skiing</i> — material icon named "downhill skiing". + static const IconData downhill_skiing = IconData(0xe200, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">downhill_skiing</i> — material icon named "downhill skiing" (sharp). + static const IconData downhill_skiing_sharp = IconData(0xe8fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">downhill_skiing</i> — material icon named "downhill skiing" (round). + static const IconData downhill_skiing_rounded = IconData(0xf6dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">downhill_skiing</i> — material icon named "downhill skiing" (outlined). + static const IconData downhill_skiing_outlined = IconData(0xefef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">download</i> — material icon named "download". + static const IconData download = IconData(0xe201, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">download</i> — material icon named "download" (sharp). + static const IconData download_sharp = IconData(0xe900, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">download</i> — material icon named "download" (round). + static const IconData download_rounded = IconData(0xf6df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">download</i> — material icon named "download" (outlined). + static const IconData download_outlined = IconData(0xeff2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">download_done</i> — material icon named "download done". + static const IconData download_done = IconData(0xe202, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">download_done</i> — material icon named "download done" (sharp). + static const IconData download_done_sharp = IconData(0xe8fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">download_done</i> — material icon named "download done" (round). + static const IconData download_done_rounded = IconData(0xf6dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">download_done</i> — material icon named "download done" (outlined). + static const IconData download_done_outlined = IconData(0xeff0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">download_for_offline</i> — material icon named "download for offline". + static const IconData download_for_offline = IconData(0xe203, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">download_for_offline</i> — material icon named "download for offline" (sharp). + static const IconData download_for_offline_sharp = IconData(0xe8ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">download_for_offline</i> — material icon named "download for offline" (round). + static const IconData download_for_offline_rounded = IconData(0xf6de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">download_for_offline</i> — material icon named "download for offline" (outlined). + static const IconData download_for_offline_outlined = IconData(0xeff1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">downloading</i> — material icon named "downloading". + static const IconData downloading = IconData(0xe204, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">downloading</i> — material icon named "downloading" (sharp). + static const IconData downloading_sharp = IconData(0xe901, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">downloading</i> — material icon named "downloading" (round). + static const IconData downloading_rounded = IconData(0xf6e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">downloading</i> — material icon named "downloading" (outlined). + static const IconData downloading_outlined = IconData(0xeff3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">drafts</i> — material icon named "drafts". + static const IconData drafts = IconData(0xe205, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">drafts</i> — material icon named "drafts" (sharp). + static const IconData drafts_sharp = IconData(0xe902, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">drafts</i> — material icon named "drafts" (round). + static const IconData drafts_rounded = IconData(0xf6e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">drafts</i> — material icon named "drafts" (outlined). + static const IconData drafts_outlined = IconData(0xeff4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">drag_handle</i> — material icon named "drag handle". + static const IconData drag_handle = IconData(0xe206, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">drag_handle</i> — material icon named "drag handle" (sharp). + static const IconData drag_handle_sharp = IconData(0xe903, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">drag_handle</i> — material icon named "drag handle" (round). + static const IconData drag_handle_rounded = IconData(0xf6e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">drag_handle</i> — material icon named "drag handle" (outlined). + static const IconData drag_handle_outlined = IconData(0xeff5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">drag_indicator</i> — material icon named "drag indicator". + static const IconData drag_indicator = IconData(0xe207, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">drag_indicator</i> — material icon named "drag indicator" (sharp). + static const IconData drag_indicator_sharp = IconData(0xe904, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">drag_indicator</i> — material icon named "drag indicator" (round). + static const IconData drag_indicator_rounded = IconData(0xf6e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">drag_indicator</i> — material icon named "drag indicator" (outlined). + static const IconData drag_indicator_outlined = IconData(0xeff6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">draw</i> — material icon named "draw". + static const IconData draw = IconData(0xf04f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">draw</i> — material icon named "draw" (sharp). + static const IconData draw_sharp = IconData(0xf03ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">draw</i> — material icon named "draw" (round). + static const IconData draw_rounded = IconData(0xf030c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">draw</i> — material icon named "draw" (outlined). + static const IconData draw_outlined = IconData(0xf05ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">drive_eta</i> — material icon named "drive eta". + static const IconData drive_eta = IconData(0xe208, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">drive_eta</i> — material icon named "drive eta" (sharp). + static const IconData drive_eta_sharp = IconData(0xe905, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">drive_eta</i> — material icon named "drive eta" (round). + static const IconData drive_eta_rounded = IconData(0xf6e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">drive_eta</i> — material icon named "drive eta" (outlined). + static const IconData drive_eta_outlined = IconData(0xeff7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">drive_file_move</i> — material icon named "drive file move". + static const IconData drive_file_move = IconData(0xe209, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">drive_file_move</i> — material icon named "drive file move" (sharp). + static const IconData drive_file_move_sharp = IconData(0xe906, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">drive_file_move</i> — material icon named "drive file move" (round). + static const IconData drive_file_move_rounded = IconData(0xf6e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">drive_file_move</i> — material icon named "drive file move" (outlined). + static const IconData drive_file_move_outlined = IconData(0xeff8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">drive_file_move_outline</i> — material icon named "drive file move outline". + static const IconData drive_file_move_outline = IconData(0xe20a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">drive_file_move_rtl</i> — material icon named "drive file move rtl". + static const IconData drive_file_move_rtl = IconData(0xf04f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">drive_file_move_rtl</i> — material icon named "drive file move rtl" (sharp). + static const IconData drive_file_move_rtl_sharp = IconData(0xf0400, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">drive_file_move_rtl</i> — material icon named "drive file move rtl" (round). + static const IconData drive_file_move_rtl_rounded = IconData(0xf030d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">drive_file_move_rtl</i> — material icon named "drive file move rtl" (outlined). + static const IconData drive_file_move_rtl_outlined = IconData(0xf05ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">drive_file_rename_outline</i> — material icon named "drive file rename outline". + static const IconData drive_file_rename_outline = IconData(0xe20b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">drive_file_rename_outline</i> — material icon named "drive file rename outline" (sharp). + static const IconData drive_file_rename_outline_sharp = IconData(0xe907, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">drive_file_rename_outline</i> — material icon named "drive file rename outline" (round). + static const IconData drive_file_rename_outline_rounded = IconData(0xf6e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">drive_file_rename_outline</i> — material icon named "drive file rename outline" (outlined). + static const IconData drive_file_rename_outline_outlined = IconData(0xeff9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">drive_folder_upload</i> — material icon named "drive folder upload". + static const IconData drive_folder_upload = IconData(0xe20c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">drive_folder_upload</i> — material icon named "drive folder upload" (sharp). + static const IconData drive_folder_upload_sharp = IconData(0xe908, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">drive_folder_upload</i> — material icon named "drive folder upload" (round). + static const IconData drive_folder_upload_rounded = IconData(0xf6e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">drive_folder_upload</i> — material icon named "drive folder upload" (outlined). + static const IconData drive_folder_upload_outlined = IconData(0xeffa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dry</i> — material icon named "dry". + static const IconData dry = IconData(0xe20d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dry</i> — material icon named "dry" (sharp). + static const IconData dry_sharp = IconData(0xe90a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dry</i> — material icon named "dry" (round). + static const IconData dry_rounded = IconData(0xf6e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dry</i> — material icon named "dry" (outlined). + static const IconData dry_outlined = IconData(0xeffc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dry_cleaning</i> — material icon named "dry cleaning". + static const IconData dry_cleaning = IconData(0xe20e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dry_cleaning</i> — material icon named "dry cleaning" (sharp). + static const IconData dry_cleaning_sharp = IconData(0xe909, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dry_cleaning</i> — material icon named "dry cleaning" (round). + static const IconData dry_cleaning_rounded = IconData(0xf6e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dry_cleaning</i> — material icon named "dry cleaning" (outlined). + static const IconData dry_cleaning_outlined = IconData(0xeffb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">duo</i> — material icon named "duo". + static const IconData duo = IconData(0xe20f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">duo</i> — material icon named "duo" (sharp). + static const IconData duo_sharp = IconData(0xe90b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">duo</i> — material icon named "duo" (round). + static const IconData duo_rounded = IconData(0xf6ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">duo</i> — material icon named "duo" (outlined). + static const IconData duo_outlined = IconData(0xeffd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dvr</i> — material icon named "dvr". + static const IconData dvr = IconData(0xe210, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">dvr</i> — material icon named "dvr" (sharp). + static const IconData dvr_sharp = IconData(0xe90c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">dvr</i> — material icon named "dvr" (round). + static const IconData dvr_rounded = IconData(0xf6eb, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">dvr</i> — material icon named "dvr" (outlined). + static const IconData dvr_outlined = IconData(0xeffe, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">dynamic_feed</i> — material icon named "dynamic feed". + static const IconData dynamic_feed = IconData(0xe211, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dynamic_feed</i> — material icon named "dynamic feed" (sharp). + static const IconData dynamic_feed_sharp = IconData(0xe90d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dynamic_feed</i> — material icon named "dynamic feed" (round). + static const IconData dynamic_feed_rounded = IconData(0xf6ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dynamic_feed</i> — material icon named "dynamic feed" (outlined). + static const IconData dynamic_feed_outlined = IconData(0xefff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">dynamic_form</i> — material icon named "dynamic form". + static const IconData dynamic_form = IconData(0xe212, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">dynamic_form</i> — material icon named "dynamic form" (sharp). + static const IconData dynamic_form_sharp = IconData(0xe90e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">dynamic_form</i> — material icon named "dynamic form" (round). + static const IconData dynamic_form_rounded = IconData(0xf6ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">dynamic_form</i> — material icon named "dynamic form" (outlined). + static const IconData dynamic_form_outlined = IconData(0xf000, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">e_mobiledata</i> — material icon named "e mobiledata". + static const IconData e_mobiledata = IconData(0xe213, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">e_mobiledata</i> — material icon named "e mobiledata" (sharp). + static const IconData e_mobiledata_sharp = IconData(0xe90f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">e_mobiledata</i> — material icon named "e mobiledata" (round). + static const IconData e_mobiledata_rounded = IconData(0xf6ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">e_mobiledata</i> — material icon named "e mobiledata" (outlined). + static const IconData e_mobiledata_outlined = IconData(0xf001, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">earbuds</i> — material icon named "earbuds". + static const IconData earbuds = IconData(0xe214, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">earbuds</i> — material icon named "earbuds" (sharp). + static const IconData earbuds_sharp = IconData(0xe911, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">earbuds</i> — material icon named "earbuds" (round). + static const IconData earbuds_rounded = IconData(0xf6f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">earbuds</i> — material icon named "earbuds" (outlined). + static const IconData earbuds_outlined = IconData(0xf003, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">earbuds_battery</i> — material icon named "earbuds battery". + static const IconData earbuds_battery = IconData(0xe215, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">earbuds_battery</i> — material icon named "earbuds battery" (sharp). + static const IconData earbuds_battery_sharp = IconData(0xe910, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">earbuds_battery</i> — material icon named "earbuds battery" (round). + static const IconData earbuds_battery_rounded = IconData(0xf6ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">earbuds_battery</i> — material icon named "earbuds battery" (outlined). + static const IconData earbuds_battery_outlined = IconData(0xf002, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">east</i> — material icon named "east". + static const IconData east = IconData(0xe216, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">east</i> — material icon named "east" (sharp). + static const IconData east_sharp = IconData(0xe912, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">east</i> — material icon named "east" (round). + static const IconData east_rounded = IconData(0xf6f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">east</i> — material icon named "east" (outlined). + static const IconData east_outlined = IconData(0xf004, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">eco</i> — material icon named "eco". + static const IconData eco = IconData(0xe217, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">eco</i> — material icon named "eco" (sharp). + static const IconData eco_sharp = IconData(0xe913, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">eco</i> — material icon named "eco" (round). + static const IconData eco_rounded = IconData(0xf6f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">eco</i> — material icon named "eco" (outlined). + static const IconData eco_outlined = IconData(0xf005, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edgesensor_high</i> — material icon named "edgesensor high". + static const IconData edgesensor_high = IconData(0xe218, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edgesensor_high</i> — material icon named "edgesensor high" (sharp). + static const IconData edgesensor_high_sharp = IconData(0xe914, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edgesensor_high</i> — material icon named "edgesensor high" (round). + static const IconData edgesensor_high_rounded = IconData(0xf6f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edgesensor_high</i> — material icon named "edgesensor high" (outlined). + static const IconData edgesensor_high_outlined = IconData(0xf006, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edgesensor_low</i> — material icon named "edgesensor low". + static const IconData edgesensor_low = IconData(0xe219, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edgesensor_low</i> — material icon named "edgesensor low" (sharp). + static const IconData edgesensor_low_sharp = IconData(0xe915, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edgesensor_low</i> — material icon named "edgesensor low" (round). + static const IconData edgesensor_low_rounded = IconData(0xf6f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edgesensor_low</i> — material icon named "edgesensor low" (outlined). + static const IconData edgesensor_low_outlined = IconData(0xf007, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit</i> — material icon named "edit". + static const IconData edit = IconData(0xe21a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edit</i> — material icon named "edit" (sharp). + static const IconData edit_sharp = IconData(0xe91c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edit</i> — material icon named "edit" (round). + static const IconData edit_rounded = IconData(0xf6fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edit</i> — material icon named "edit" (outlined). + static const IconData edit_outlined = IconData(0xf00d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit_attributes</i> — material icon named "edit attributes". + static const IconData edit_attributes = IconData(0xe21b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edit_attributes</i> — material icon named "edit attributes" (sharp). + static const IconData edit_attributes_sharp = IconData(0xe916, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edit_attributes</i> — material icon named "edit attributes" (round). + static const IconData edit_attributes_rounded = IconData(0xf6f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edit_attributes</i> — material icon named "edit attributes" (outlined). + static const IconData edit_attributes_outlined = IconData(0xf008, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit_calendar</i> — material icon named "edit calendar". + static const IconData edit_calendar = IconData(0xf04f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edit_calendar</i> — material icon named "edit calendar" (sharp). + static const IconData edit_calendar_sharp = IconData(0xf0401, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edit_calendar</i> — material icon named "edit calendar" (round). + static const IconData edit_calendar_rounded = IconData(0xf030e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edit_calendar</i> — material icon named "edit calendar" (outlined). + static const IconData edit_calendar_outlined = IconData(0xf05ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit_document</i> — material icon named "edit document". + static const IconData edit_document = IconData(0xf085d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit_location</i> — material icon named "edit location". + static const IconData edit_location = IconData(0xe21c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edit_location</i> — material icon named "edit location" (sharp). + static const IconData edit_location_sharp = IconData(0xe918, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edit_location</i> — material icon named "edit location" (round). + static const IconData edit_location_rounded = IconData(0xf6f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edit_location</i> — material icon named "edit location" (outlined). + static const IconData edit_location_outlined = IconData(0xf00a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit_location_alt</i> — material icon named "edit location alt". + static const IconData edit_location_alt = IconData(0xe21d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edit_location_alt</i> — material icon named "edit location alt" (sharp). + static const IconData edit_location_alt_sharp = IconData(0xe917, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edit_location_alt</i> — material icon named "edit location alt" (round). + static const IconData edit_location_alt_rounded = IconData(0xf6f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edit_location_alt</i> — material icon named "edit location alt" (outlined). + static const IconData edit_location_alt_outlined = IconData(0xf009, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit_note</i> — material icon named "edit note". + static const IconData edit_note = IconData(0xf04f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edit_note</i> — material icon named "edit note" (sharp). + static const IconData edit_note_sharp = IconData(0xf0402, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edit_note</i> — material icon named "edit note" (round). + static const IconData edit_note_rounded = IconData(0xf030f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edit_note</i> — material icon named "edit note" (outlined). + static const IconData edit_note_outlined = IconData(0xf05f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit_notifications</i> — material icon named "edit notifications". + static const IconData edit_notifications = IconData(0xe21e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edit_notifications</i> — material icon named "edit notifications" (sharp). + static const IconData edit_notifications_sharp = IconData(0xe919, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edit_notifications</i> — material icon named "edit notifications" (round). + static const IconData edit_notifications_rounded = IconData(0xf6f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edit_notifications</i> — material icon named "edit notifications" (outlined). + static const IconData edit_notifications_outlined = IconData(0xf00b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit_off</i> — material icon named "edit off". + static const IconData edit_off = IconData(0xe21f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edit_off</i> — material icon named "edit off" (sharp). + static const IconData edit_off_sharp = IconData(0xe91a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edit_off</i> — material icon named "edit off" (round). + static const IconData edit_off_rounded = IconData(0xf6f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edit_off</i> — material icon named "edit off" (outlined). + static const IconData edit_off_outlined = IconData(0xf00c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit_road</i> — material icon named "edit road". + static const IconData edit_road = IconData(0xe220, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">edit_road</i> — material icon named "edit road" (sharp). + static const IconData edit_road_sharp = IconData(0xe91b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">edit_road</i> — material icon named "edit road" (round). + static const IconData edit_road_rounded = IconData(0xf6fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">edit_road</i> — material icon named "edit road" (outlined). + static const IconData edit_road_outlined = IconData(0xf00e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">edit_square</i> — material icon named "edit square". + static const IconData edit_square = IconData(0xf085e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">egg</i> — material icon named "egg". + static const IconData egg = IconData(0xf04f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">egg</i> — material icon named "egg" (sharp). + static const IconData egg_sharp = IconData(0xf0404, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">egg</i> — material icon named "egg" (round). + static const IconData egg_rounded = IconData(0xf0311, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">egg</i> — material icon named "egg" (outlined). + static const IconData egg_outlined = IconData(0xf05f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">egg_alt</i> — material icon named "egg alt". + static const IconData egg_alt = IconData(0xf04f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">egg_alt</i> — material icon named "egg alt" (sharp). + static const IconData egg_alt_sharp = IconData(0xf0403, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">egg_alt</i> — material icon named "egg alt" (round). + static const IconData egg_alt_rounded = IconData(0xf0310, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">egg_alt</i> — material icon named "egg alt" (outlined). + static const IconData egg_alt_outlined = IconData(0xf05f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">eject</i> — material icon named "eject". + static const IconData eject = IconData(0xe221, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">eject</i> — material icon named "eject" (sharp). + static const IconData eject_sharp = IconData(0xe91d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">eject</i> — material icon named "eject" (round). + static const IconData eject_rounded = IconData(0xf6fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">eject</i> — material icon named "eject" (outlined). + static const IconData eject_outlined = IconData(0xf00f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">elderly</i> — material icon named "elderly". + static const IconData elderly = IconData(0xe222, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">elderly</i> — material icon named "elderly" (sharp). + static const IconData elderly_sharp = IconData(0xe91e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">elderly</i> — material icon named "elderly" (round). + static const IconData elderly_rounded = IconData(0xf6fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">elderly</i> — material icon named "elderly" (outlined). + static const IconData elderly_outlined = IconData(0xf010, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">elderly_woman</i> — material icon named "elderly woman". + static const IconData elderly_woman = IconData(0xf04f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">elderly_woman</i> — material icon named "elderly woman" (sharp). + static const IconData elderly_woman_sharp = IconData(0xf0405, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">elderly_woman</i> — material icon named "elderly woman" (round). + static const IconData elderly_woman_rounded = IconData(0xf0312, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">elderly_woman</i> — material icon named "elderly woman" (outlined). + static const IconData elderly_woman_outlined = IconData(0xf05f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">electric_bike</i> — material icon named "electric bike". + static const IconData electric_bike = IconData(0xe223, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">electric_bike</i> — material icon named "electric bike" (sharp). + static const IconData electric_bike_sharp = IconData(0xe91f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">electric_bike</i> — material icon named "electric bike" (round). + static const IconData electric_bike_rounded = IconData(0xf6fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">electric_bike</i> — material icon named "electric bike" (outlined). + static const IconData electric_bike_outlined = IconData(0xf011, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">electric_bolt</i> — material icon named "electric bolt". + static const IconData electric_bolt = IconData(0xf079c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">electric_bolt</i> — material icon named "electric bolt" (sharp). + static const IconData electric_bolt_sharp = IconData(0xf0744, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">electric_bolt</i> — material icon named "electric bolt" (round). + static const IconData electric_bolt_rounded = IconData(0xf07f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">electric_bolt</i> — material icon named "electric bolt" (outlined). + static const IconData electric_bolt_outlined = IconData(0xf06ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">electric_car</i> — material icon named "electric car". + static const IconData electric_car = IconData(0xe224, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">electric_car</i> — material icon named "electric car" (sharp). + static const IconData electric_car_sharp = IconData(0xe920, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">electric_car</i> — material icon named "electric car" (round). + static const IconData electric_car_rounded = IconData(0xf6ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">electric_car</i> — material icon named "electric car" (outlined). + static const IconData electric_car_outlined = IconData(0xf012, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">electric_meter</i> — material icon named "electric meter". + static const IconData electric_meter = IconData(0xf079d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">electric_meter</i> — material icon named "electric meter" (sharp). + static const IconData electric_meter_sharp = IconData(0xf0745, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">electric_meter</i> — material icon named "electric meter" (round). + static const IconData electric_meter_rounded = IconData(0xf07f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">electric_meter</i> — material icon named "electric meter" (outlined). + static const IconData electric_meter_outlined = IconData(0xf06ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">electric_moped</i> — material icon named "electric moped". + static const IconData electric_moped = IconData(0xe225, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">electric_moped</i> — material icon named "electric moped" (sharp). + static const IconData electric_moped_sharp = IconData(0xe921, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">electric_moped</i> — material icon named "electric moped" (round). + static const IconData electric_moped_rounded = IconData(0xf700, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">electric_moped</i> — material icon named "electric moped" (outlined). + static const IconData electric_moped_outlined = IconData(0xf013, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">electric_rickshaw</i> — material icon named "electric rickshaw". + static const IconData electric_rickshaw = IconData(0xe226, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">electric_rickshaw</i> — material icon named "electric rickshaw" (sharp). + static const IconData electric_rickshaw_sharp = IconData(0xe922, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">electric_rickshaw</i> — material icon named "electric rickshaw" (round). + static const IconData electric_rickshaw_rounded = IconData(0xf701, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">electric_rickshaw</i> — material icon named "electric rickshaw" (outlined). + static const IconData electric_rickshaw_outlined = IconData(0xf014, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">electric_scooter</i> — material icon named "electric scooter". + static const IconData electric_scooter = IconData(0xe227, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">electric_scooter</i> — material icon named "electric scooter" (sharp). + static const IconData electric_scooter_sharp = IconData(0xe923, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">electric_scooter</i> — material icon named "electric scooter" (round). + static const IconData electric_scooter_rounded = IconData(0xf702, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">electric_scooter</i> — material icon named "electric scooter" (outlined). + static const IconData electric_scooter_outlined = IconData(0xf015, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">electrical_services</i> — material icon named "electrical services". + static const IconData electrical_services = IconData(0xe228, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">electrical_services</i> — material icon named "electrical services" (sharp). + static const IconData electrical_services_sharp = IconData(0xe924, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">electrical_services</i> — material icon named "electrical services" (round). + static const IconData electrical_services_rounded = IconData(0xf703, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">electrical_services</i> — material icon named "electrical services" (outlined). + static const IconData electrical_services_outlined = IconData(0xf016, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">elevator</i> — material icon named "elevator". + static const IconData elevator = IconData(0xe229, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">elevator</i> — material icon named "elevator" (sharp). + static const IconData elevator_sharp = IconData(0xe925, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">elevator</i> — material icon named "elevator" (round). + static const IconData elevator_rounded = IconData(0xf704, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">elevator</i> — material icon named "elevator" (outlined). + static const IconData elevator_outlined = IconData(0xf017, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">email</i> — material icon named "email". + static const IconData email = IconData(0xe22a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">email</i> — material icon named "email" (sharp). + static const IconData email_sharp = IconData(0xe926, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">email</i> — material icon named "email" (round). + static const IconData email_rounded = IconData(0xf705, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">email</i> — material icon named "email" (outlined). + static const IconData email_outlined = IconData(0xf018, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emergency</i> — material icon named "emergency". + static const IconData emergency = IconData(0xf04fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emergency</i> — material icon named "emergency" (sharp). + static const IconData emergency_sharp = IconData(0xf0406, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emergency</i> — material icon named "emergency" (round). + static const IconData emergency_rounded = IconData(0xf0313, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emergency</i> — material icon named "emergency" (outlined). + static const IconData emergency_outlined = IconData(0xf05f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emergency_recording</i> — material icon named "emergency recording". + static const IconData emergency_recording = IconData(0xf079e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emergency_recording</i> — material icon named "emergency recording" (sharp). + static const IconData emergency_recording_sharp = IconData(0xf0746, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emergency_recording</i> — material icon named "emergency recording" (round). + static const IconData emergency_recording_rounded = IconData(0xf07f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emergency_recording</i> — material icon named "emergency recording" (outlined). + static const IconData emergency_recording_outlined = IconData(0xf06ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emergency_share</i> — material icon named "emergency share". + static const IconData emergency_share = IconData(0xf079f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emergency_share</i> — material icon named "emergency share" (sharp). + static const IconData emergency_share_sharp = IconData(0xf0747, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emergency_share</i> — material icon named "emergency share" (round). + static const IconData emergency_share_rounded = IconData(0xf07f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emergency_share</i> — material icon named "emergency share" (outlined). + static const IconData emergency_share_outlined = IconData(0xf06ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emoji_emotions</i> — material icon named "emoji emotions". + static const IconData emoji_emotions = IconData(0xe22b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emoji_emotions</i> — material icon named "emoji emotions" (sharp). + static const IconData emoji_emotions_sharp = IconData(0xe927, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emoji_emotions</i> — material icon named "emoji emotions" (round). + static const IconData emoji_emotions_rounded = IconData(0xf706, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emoji_emotions</i> — material icon named "emoji emotions" (outlined). + static const IconData emoji_emotions_outlined = IconData(0xf019, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emoji_events</i> — material icon named "emoji events". + static const IconData emoji_events = IconData(0xe22c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emoji_events</i> — material icon named "emoji events" (sharp). + static const IconData emoji_events_sharp = IconData(0xe928, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emoji_events</i> — material icon named "emoji events" (round). + static const IconData emoji_events_rounded = IconData(0xf707, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emoji_events</i> — material icon named "emoji events" (outlined). + static const IconData emoji_events_outlined = IconData(0xf01a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emoji_flags</i> — material icon named "emoji flags". + static const IconData emoji_flags = IconData(0xe22d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emoji_flags</i> — material icon named "emoji flags" (sharp). + static const IconData emoji_flags_sharp = IconData(0xe929, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emoji_flags</i> — material icon named "emoji flags" (round). + static const IconData emoji_flags_rounded = IconData(0xf708, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emoji_flags</i> — material icon named "emoji flags" (outlined). + static const IconData emoji_flags_outlined = IconData(0xf01b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emoji_food_beverage</i> — material icon named "emoji food beverage". + static const IconData emoji_food_beverage = IconData(0xe22e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emoji_food_beverage</i> — material icon named "emoji food beverage" (sharp). + static const IconData emoji_food_beverage_sharp = IconData(0xe92a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emoji_food_beverage</i> — material icon named "emoji food beverage" (round). + static const IconData emoji_food_beverage_rounded = IconData(0xf709, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emoji_food_beverage</i> — material icon named "emoji food beverage" (outlined). + static const IconData emoji_food_beverage_outlined = IconData(0xf01c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emoji_nature</i> — material icon named "emoji nature". + static const IconData emoji_nature = IconData(0xe22f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emoji_nature</i> — material icon named "emoji nature" (sharp). + static const IconData emoji_nature_sharp = IconData(0xe92b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emoji_nature</i> — material icon named "emoji nature" (round). + static const IconData emoji_nature_rounded = IconData(0xf70a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emoji_nature</i> — material icon named "emoji nature" (outlined). + static const IconData emoji_nature_outlined = IconData(0xf01d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emoji_objects</i> — material icon named "emoji objects". + static const IconData emoji_objects = IconData(0xe230, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emoji_objects</i> — material icon named "emoji objects" (sharp). + static const IconData emoji_objects_sharp = IconData(0xe92c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emoji_objects</i> — material icon named "emoji objects" (round). + static const IconData emoji_objects_rounded = IconData(0xf70b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emoji_objects</i> — material icon named "emoji objects" (outlined). + static const IconData emoji_objects_outlined = IconData(0xf01e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emoji_people</i> — material icon named "emoji people". + static const IconData emoji_people = IconData(0xe231, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emoji_people</i> — material icon named "emoji people" (sharp). + static const IconData emoji_people_sharp = IconData(0xe92d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emoji_people</i> — material icon named "emoji people" (round). + static const IconData emoji_people_rounded = IconData(0xf70c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emoji_people</i> — material icon named "emoji people" (outlined). + static const IconData emoji_people_outlined = IconData(0xf01f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emoji_symbols</i> — material icon named "emoji symbols". + static const IconData emoji_symbols = IconData(0xe232, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emoji_symbols</i> — material icon named "emoji symbols" (sharp). + static const IconData emoji_symbols_sharp = IconData(0xe92e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emoji_symbols</i> — material icon named "emoji symbols" (round). + static const IconData emoji_symbols_rounded = IconData(0xf70d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emoji_symbols</i> — material icon named "emoji symbols" (outlined). + static const IconData emoji_symbols_outlined = IconData(0xf020, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">emoji_transportation</i> — material icon named "emoji transportation". + static const IconData emoji_transportation = IconData(0xe233, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">emoji_transportation</i> — material icon named "emoji transportation" (sharp). + static const IconData emoji_transportation_sharp = IconData(0xe92f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">emoji_transportation</i> — material icon named "emoji transportation" (round). + static const IconData emoji_transportation_rounded = IconData(0xf70e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">emoji_transportation</i> — material icon named "emoji transportation" (outlined). + static const IconData emoji_transportation_outlined = IconData(0xf021, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">energy_savings_leaf</i> — material icon named "energy savings leaf". + static const IconData energy_savings_leaf = IconData(0xf07a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">energy_savings_leaf</i> — material icon named "energy savings leaf" (sharp). + static const IconData energy_savings_leaf_sharp = IconData(0xf0748, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">energy_savings_leaf</i> — material icon named "energy savings leaf" (round). + static const IconData energy_savings_leaf_rounded = IconData(0xf07f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">energy_savings_leaf</i> — material icon named "energy savings leaf" (outlined). + static const IconData energy_savings_leaf_outlined = IconData(0xf06f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">engineering</i> — material icon named "engineering". + static const IconData engineering = IconData(0xe234, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">engineering</i> — material icon named "engineering" (sharp). + static const IconData engineering_sharp = IconData(0xe930, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">engineering</i> — material icon named "engineering" (round). + static const IconData engineering_rounded = IconData(0xf70f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">engineering</i> — material icon named "engineering" (outlined). + static const IconData engineering_outlined = IconData(0xf022, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">enhance_photo_translate</i> — material icon named "enhance photo translate". + static const IconData enhance_photo_translate = IconData(0xe131, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">enhance_photo_translate</i> — material icon named "enhance photo translate" (sharp). + static const IconData enhance_photo_translate_sharp = IconData(0xe82d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">enhance_photo_translate</i> — material icon named "enhance photo translate" (round). + static const IconData enhance_photo_translate_rounded = IconData(0xf60c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">enhance_photo_translate</i> — material icon named "enhance photo translate" (outlined). + static const IconData enhance_photo_translate_outlined = IconData(0xef1f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">enhanced_encryption</i> — material icon named "enhanced encryption". + static const IconData enhanced_encryption = IconData(0xe235, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">enhanced_encryption</i> — material icon named "enhanced encryption" (sharp). + static const IconData enhanced_encryption_sharp = IconData(0xe931, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">enhanced_encryption</i> — material icon named "enhanced encryption" (round). + static const IconData enhanced_encryption_rounded = IconData(0xf710, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">enhanced_encryption</i> — material icon named "enhanced encryption" (outlined). + static const IconData enhanced_encryption_outlined = IconData(0xf023, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">equalizer</i> — material icon named "equalizer". + static const IconData equalizer = IconData(0xe236, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">equalizer</i> — material icon named "equalizer" (sharp). + static const IconData equalizer_sharp = IconData(0xe932, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">equalizer</i> — material icon named "equalizer" (round). + static const IconData equalizer_rounded = IconData(0xf711, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">equalizer</i> — material icon named "equalizer" (outlined). + static const IconData equalizer_outlined = IconData(0xf024, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">error</i> — material icon named "error". + static const IconData error = IconData(0xe237, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">error</i> — material icon named "error" (sharp). + static const IconData error_sharp = IconData(0xe934, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">error</i> — material icon named "error" (round). + static const IconData error_rounded = IconData(0xf713, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">error</i> — material icon named "error" (outlined). + static const IconData error_outlined = IconData(0xf026, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">error_outline</i> — material icon named "error outline". + static const IconData error_outline = IconData(0xe238, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">error_outline</i> — material icon named "error outline" (sharp). + static const IconData error_outline_sharp = IconData(0xe933, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">error_outline</i> — material icon named "error outline" (round). + static const IconData error_outline_rounded = IconData(0xf712, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">error_outline</i> — material icon named "error outline" (outlined). + static const IconData error_outline_outlined = IconData(0xf025, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">escalator</i> — material icon named "escalator". + static const IconData escalator = IconData(0xe239, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">escalator</i> — material icon named "escalator" (sharp). + static const IconData escalator_sharp = IconData(0xe935, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">escalator</i> — material icon named "escalator" (round). + static const IconData escalator_rounded = IconData(0xf714, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">escalator</i> — material icon named "escalator" (outlined). + static const IconData escalator_outlined = IconData(0xf027, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">escalator_warning</i> — material icon named "escalator warning". + static const IconData escalator_warning = IconData(0xe23a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">escalator_warning</i> — material icon named "escalator warning" (sharp). + static const IconData escalator_warning_sharp = IconData(0xe936, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">escalator_warning</i> — material icon named "escalator warning" (round). + static const IconData escalator_warning_rounded = IconData(0xf715, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">escalator_warning</i> — material icon named "escalator warning" (outlined). + static const IconData escalator_warning_outlined = IconData(0xf028, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">euro</i> — material icon named "euro". + static const IconData euro = IconData(0xe23b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">euro</i> — material icon named "euro" (sharp). + static const IconData euro_sharp = IconData(0xe937, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">euro</i> — material icon named "euro" (round). + static const IconData euro_rounded = IconData(0xf716, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">euro</i> — material icon named "euro" (outlined). + static const IconData euro_outlined = IconData(0xf029, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">euro_symbol</i> — material icon named "euro symbol". + static const IconData euro_symbol = IconData(0xe23c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">euro_symbol</i> — material icon named "euro symbol" (sharp). + static const IconData euro_symbol_sharp = IconData(0xe938, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">euro_symbol</i> — material icon named "euro symbol" (round). + static const IconData euro_symbol_rounded = IconData(0xf717, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">euro_symbol</i> — material icon named "euro symbol" (outlined). + static const IconData euro_symbol_outlined = IconData(0xf02a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ev_station</i> — material icon named "ev station". + static const IconData ev_station = IconData(0xe23d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ev_station</i> — material icon named "ev station" (sharp). + static const IconData ev_station_sharp = IconData(0xe939, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ev_station</i> — material icon named "ev station" (round). + static const IconData ev_station_rounded = IconData(0xf718, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ev_station</i> — material icon named "ev station" (outlined). + static const IconData ev_station_outlined = IconData(0xf02b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">event</i> — material icon named "event". + static const IconData event = IconData(0xe23e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">event</i> — material icon named "event" (sharp). + static const IconData event_sharp = IconData(0xe93e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">event</i> — material icon named "event" (round). + static const IconData event_rounded = IconData(0xf71c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">event</i> — material icon named "event" (outlined). + static const IconData event_outlined = IconData(0xf02f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">event_available</i> — material icon named "event available". + static const IconData event_available = IconData(0xe23f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">event_available</i> — material icon named "event available" (sharp). + static const IconData event_available_sharp = IconData(0xe93a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">event_available</i> — material icon named "event available" (round). + static const IconData event_available_rounded = IconData(0xf719, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">event_available</i> — material icon named "event available" (outlined). + static const IconData event_available_outlined = IconData(0xf02c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">event_busy</i> — material icon named "event busy". + static const IconData event_busy = IconData(0xe240, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">event_busy</i> — material icon named "event busy" (sharp). + static const IconData event_busy_sharp = IconData(0xe93b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">event_busy</i> — material icon named "event busy" (round). + static const IconData event_busy_rounded = IconData(0xf71a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">event_busy</i> — material icon named "event busy" (outlined). + static const IconData event_busy_outlined = IconData(0xf02d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">event_note</i> — material icon named "event note". + static const IconData event_note = IconData(0xe241, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">event_note</i> — material icon named "event note" (sharp). + static const IconData event_note_sharp = IconData(0xe93c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">event_note</i> — material icon named "event note" (round). + static const IconData event_note_rounded = IconData(0xf71b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">event_note</i> — material icon named "event note" (outlined). + static const IconData event_note_outlined = IconData(0xf02e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">event_repeat</i> — material icon named "event repeat". + static const IconData event_repeat = IconData(0xf04fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">event_repeat</i> — material icon named "event repeat" (sharp). + static const IconData event_repeat_sharp = IconData(0xf0407, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">event_repeat</i> — material icon named "event repeat" (round). + static const IconData event_repeat_rounded = IconData(0xf0314, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">event_repeat</i> — material icon named "event repeat" (outlined). + static const IconData event_repeat_outlined = IconData(0xf05f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">event_seat</i> — material icon named "event seat". + static const IconData event_seat = IconData(0xe242, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">event_seat</i> — material icon named "event seat" (sharp). + static const IconData event_seat_sharp = IconData(0xe93d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">event_seat</i> — material icon named "event seat" (round). + static const IconData event_seat_rounded = IconData(0xf71d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">event_seat</i> — material icon named "event seat" (outlined). + static const IconData event_seat_outlined = IconData(0xf030, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">exit_to_app</i> — material icon named "exit to app". + static const IconData exit_to_app = IconData(0xe243, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">exit_to_app</i> — material icon named "exit to app" (sharp). + static const IconData exit_to_app_sharp = IconData(0xe93f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">exit_to_app</i> — material icon named "exit to app" (round). + static const IconData exit_to_app_rounded = IconData(0xf71e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">exit_to_app</i> — material icon named "exit to app" (outlined). + static const IconData exit_to_app_outlined = IconData(0xf031, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">expand</i> — material icon named "expand". + static const IconData expand = IconData(0xe244, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">expand</i> — material icon named "expand" (sharp). + static const IconData expand_sharp = IconData(0xe942, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">expand</i> — material icon named "expand" (round). + static const IconData expand_rounded = IconData(0xf721, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">expand</i> — material icon named "expand" (outlined). + static const IconData expand_outlined = IconData(0xf034, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">expand_circle_down</i> — material icon named "expand circle down". + static const IconData expand_circle_down = IconData(0xf04fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">expand_circle_down</i> — material icon named "expand circle down" (sharp). + static const IconData expand_circle_down_sharp = IconData(0xf0408, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">expand_circle_down</i> — material icon named "expand circle down" (round). + static const IconData expand_circle_down_rounded = IconData(0xf0315, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">expand_circle_down</i> — material icon named "expand circle down" (outlined). + static const IconData expand_circle_down_outlined = IconData(0xf05f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">expand_less</i> — material icon named "expand less". + static const IconData expand_less = IconData(0xe245, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">expand_less</i> — material icon named "expand less" (sharp). + static const IconData expand_less_sharp = IconData(0xe940, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">expand_less</i> — material icon named "expand less" (round). + static const IconData expand_less_rounded = IconData(0xf71f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">expand_less</i> — material icon named "expand less" (outlined). + static const IconData expand_less_outlined = IconData(0xf032, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">expand_more</i> — material icon named "expand more". + static const IconData expand_more = IconData(0xe246, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">expand_more</i> — material icon named "expand more" (sharp). + static const IconData expand_more_sharp = IconData(0xe941, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">expand_more</i> — material icon named "expand more" (round). + static const IconData expand_more_rounded = IconData(0xf720, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">expand_more</i> — material icon named "expand more" (outlined). + static const IconData expand_more_outlined = IconData(0xf033, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">explicit</i> — material icon named "explicit". + static const IconData explicit = IconData(0xe247, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">explicit</i> — material icon named "explicit" (sharp). + static const IconData explicit_sharp = IconData(0xe943, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">explicit</i> — material icon named "explicit" (round). + static const IconData explicit_rounded = IconData(0xf722, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">explicit</i> — material icon named "explicit" (outlined). + static const IconData explicit_outlined = IconData(0xf035, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">explore</i> — material icon named "explore". + static const IconData explore = IconData(0xe248, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">explore</i> — material icon named "explore" (sharp). + static const IconData explore_sharp = IconData(0xe945, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">explore</i> — material icon named "explore" (round). + static const IconData explore_rounded = IconData(0xf724, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">explore</i> — material icon named "explore" (outlined). + static const IconData explore_outlined = IconData(0xf037, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">explore_off</i> — material icon named "explore off". + static const IconData explore_off = IconData(0xe249, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">explore_off</i> — material icon named "explore off" (sharp). + static const IconData explore_off_sharp = IconData(0xe944, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">explore_off</i> — material icon named "explore off" (round). + static const IconData explore_off_rounded = IconData(0xf723, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">explore_off</i> — material icon named "explore off" (outlined). + static const IconData explore_off_outlined = IconData(0xf036, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">exposure</i> — material icon named "exposure". + static const IconData exposure = IconData(0xe24a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">exposure</i> — material icon named "exposure" (sharp). + static const IconData exposure_sharp = IconData(0xe94a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">exposure</i> — material icon named "exposure" (round). + static const IconData exposure_rounded = IconData(0xf729, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">exposure</i> — material icon named "exposure" (outlined). + static const IconData exposure_outlined = IconData(0xf03a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">exposure_minus_1</i> — material icon named "exposure minus 1". + static const IconData exposure_minus_1 = IconData(0xe24b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">exposure_minus_1</i> — material icon named "exposure minus 1" (sharp). + static const IconData exposure_minus_1_sharp = IconData(0xe946, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">exposure_minus_1</i> — material icon named "exposure minus 1" (round). + static const IconData exposure_minus_1_rounded = IconData(0xf725, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">exposure_minus_1</i> — material icon named "exposure minus 1" (outlined). + static const IconData exposure_minus_1_outlined = IconData(0xf038, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">exposure_minus_2</i> — material icon named "exposure minus 2". + static const IconData exposure_minus_2 = IconData(0xe24c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">exposure_minus_2</i> — material icon named "exposure minus 2" (sharp). + static const IconData exposure_minus_2_sharp = IconData(0xe947, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">exposure_minus_2</i> — material icon named "exposure minus 2" (round). + static const IconData exposure_minus_2_rounded = IconData(0xf726, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">exposure_minus_2</i> — material icon named "exposure minus 2" (outlined). + static const IconData exposure_minus_2_outlined = IconData(0xf039, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">exposure_neg_1</i> — material icon named "exposure neg 1". + static const IconData exposure_neg_1 = IconData(0xe24b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">exposure_neg_1</i> — material icon named "exposure neg 1" (sharp). + static const IconData exposure_neg_1_sharp = IconData(0xe946, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">exposure_neg_1</i> — material icon named "exposure neg 1" (round). + static const IconData exposure_neg_1_rounded = IconData(0xf725, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">exposure_neg_1</i> — material icon named "exposure neg 1" (outlined). + static const IconData exposure_neg_1_outlined = IconData(0xf038, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">exposure_neg_2</i> — material icon named "exposure neg 2". + static const IconData exposure_neg_2 = IconData(0xe24c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">exposure_neg_2</i> — material icon named "exposure neg 2" (sharp). + static const IconData exposure_neg_2_sharp = IconData(0xe947, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">exposure_neg_2</i> — material icon named "exposure neg 2" (round). + static const IconData exposure_neg_2_rounded = IconData(0xf726, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">exposure_neg_2</i> — material icon named "exposure neg 2" (outlined). + static const IconData exposure_neg_2_outlined = IconData(0xf039, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">exposure_plus_1</i> — material icon named "exposure plus 1". + static const IconData exposure_plus_1 = IconData(0xe24d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">exposure_plus_1</i> — material icon named "exposure plus 1" (sharp). + static const IconData exposure_plus_1_sharp = IconData(0xe948, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">exposure_plus_1</i> — material icon named "exposure plus 1" (round). + static const IconData exposure_plus_1_rounded = IconData(0xf727, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">exposure_plus_1</i> — material icon named "exposure plus 1" (outlined). + static const IconData exposure_plus_1_outlined = IconData(0xf03b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">exposure_plus_2</i> — material icon named "exposure plus 2". + static const IconData exposure_plus_2 = IconData(0xe24e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">exposure_plus_2</i> — material icon named "exposure plus 2" (sharp). + static const IconData exposure_plus_2_sharp = IconData(0xe949, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">exposure_plus_2</i> — material icon named "exposure plus 2" (round). + static const IconData exposure_plus_2_rounded = IconData(0xf728, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">exposure_plus_2</i> — material icon named "exposure plus 2" (outlined). + static const IconData exposure_plus_2_outlined = IconData(0xf03c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">exposure_zero</i> — material icon named "exposure zero". + static const IconData exposure_zero = IconData(0xe24f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">exposure_zero</i> — material icon named "exposure zero" (sharp). + static const IconData exposure_zero_sharp = IconData(0xe94b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">exposure_zero</i> — material icon named "exposure zero" (round). + static const IconData exposure_zero_rounded = IconData(0xf72a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">exposure_zero</i> — material icon named "exposure zero" (outlined). + static const IconData exposure_zero_outlined = IconData(0xf03d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">extension</i> — material icon named "extension". + static const IconData extension = IconData(0xe250, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">extension</i> — material icon named "extension" (sharp). + static const IconData extension_sharp = IconData(0xe94d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">extension</i> — material icon named "extension" (round). + static const IconData extension_rounded = IconData(0xf72c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">extension</i> — material icon named "extension" (outlined). + static const IconData extension_outlined = IconData(0xf03f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">extension_off</i> — material icon named "extension off". + static const IconData extension_off = IconData(0xe251, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">extension_off</i> — material icon named "extension off" (sharp). + static const IconData extension_off_sharp = IconData(0xe94c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">extension_off</i> — material icon named "extension off" (round). + static const IconData extension_off_rounded = IconData(0xf72b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">extension_off</i> — material icon named "extension off" (outlined). + static const IconData extension_off_outlined = IconData(0xf03e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">face</i> — material icon named "face". + static const IconData face = IconData(0xe252, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">face</i> — material icon named "face" (sharp). + static const IconData face_sharp = IconData(0xe950, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">face</i> — material icon named "face" (round). + static const IconData face_rounded = IconData(0xf72f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">face</i> — material icon named "face" (outlined). + static const IconData face_outlined = IconData(0xf040, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">face_2</i> — material icon named "face 2". + static const IconData face_2 = IconData(0xf085f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">face_2</i> — material icon named "face 2" (sharp). + static const IconData face_2_sharp = IconData(0xf083b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">face_2</i> — material icon named "face 2" (round). + static const IconData face_2_rounded = IconData(0xf0884, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">face_2</i> — material icon named "face 2" (outlined). + static const IconData face_2_outlined = IconData(0xf08a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">face_3</i> — material icon named "face 3". + static const IconData face_3 = IconData(0xf0860, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">face_3</i> — material icon named "face 3" (sharp). + static const IconData face_3_sharp = IconData(0xf083c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">face_3</i> — material icon named "face 3" (round). + static const IconData face_3_rounded = IconData(0xf0885, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">face_3</i> — material icon named "face 3" (outlined). + static const IconData face_3_outlined = IconData(0xf08a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">face_4</i> — material icon named "face 4". + static const IconData face_4 = IconData(0xf0861, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">face_4</i> — material icon named "face 4" (sharp). + static const IconData face_4_sharp = IconData(0xf083d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">face_4</i> — material icon named "face 4" (round). + static const IconData face_4_rounded = IconData(0xf0886, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">face_4</i> — material icon named "face 4" (outlined). + static const IconData face_4_outlined = IconData(0xf08a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">face_5</i> — material icon named "face 5". + static const IconData face_5 = IconData(0xf0862, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">face_5</i> — material icon named "face 5" (sharp). + static const IconData face_5_sharp = IconData(0xf083e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">face_5</i> — material icon named "face 5" (round). + static const IconData face_5_rounded = IconData(0xf0887, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">face_5</i> — material icon named "face 5" (outlined). + static const IconData face_5_outlined = IconData(0xf08a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">face_6</i> — material icon named "face 6". + static const IconData face_6 = IconData(0xf0863, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">face_6</i> — material icon named "face 6" (sharp). + static const IconData face_6_sharp = IconData(0xf083f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">face_6</i> — material icon named "face 6" (round). + static const IconData face_6_rounded = IconData(0xf0888, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">face_6</i> — material icon named "face 6" (outlined). + static const IconData face_6_outlined = IconData(0xf08a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">face_retouching_natural</i> — material icon named "face retouching natural". + static const IconData face_retouching_natural = IconData(0xe253, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">face_retouching_natural</i> — material icon named "face retouching natural" (sharp). + static const IconData face_retouching_natural_sharp = IconData(0xe94e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">face_retouching_natural</i> — material icon named "face retouching natural" (round). + static const IconData face_retouching_natural_rounded = IconData(0xf72d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">face_retouching_natural</i> — material icon named "face retouching natural" (outlined). + static const IconData face_retouching_natural_outlined = IconData(0xf041, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">face_retouching_off</i> — material icon named "face retouching off". + static const IconData face_retouching_off = IconData(0xe254, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">face_retouching_off</i> — material icon named "face retouching off" (sharp). + static const IconData face_retouching_off_sharp = IconData(0xe94f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">face_retouching_off</i> — material icon named "face retouching off" (round). + static const IconData face_retouching_off_rounded = IconData(0xf72e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">face_retouching_off</i> — material icon named "face retouching off" (outlined). + static const IconData face_retouching_off_outlined = IconData(0xf042, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">face_unlock</i> — material icon named "face unlock" (sharp). + static const IconData face_unlock_sharp = IconData(0xe951, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">face_unlock</i> — material icon named "face unlock" (round). + static const IconData face_unlock_rounded = IconData(0xf730, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">face_unlock</i> — material icon named "face unlock" (outlined). + static const IconData face_unlock_outlined = IconData(0xf043, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">facebook</i> — material icon named "facebook". + static const IconData facebook = IconData(0xe255, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">facebook</i> — material icon named "facebook" (sharp). + static const IconData facebook_sharp = IconData(0xe952, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">facebook</i> — material icon named "facebook" (round). + static const IconData facebook_rounded = IconData(0xf731, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">facebook</i> — material icon named "facebook" (outlined). + static const IconData facebook_outlined = IconData(0xf044, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fact_check</i> — material icon named "fact check". + static const IconData fact_check = IconData(0xe256, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fact_check</i> — material icon named "fact check" (sharp). + static const IconData fact_check_sharp = IconData(0xe953, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fact_check</i> — material icon named "fact check" (round). + static const IconData fact_check_rounded = IconData(0xf732, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fact_check</i> — material icon named "fact check" (outlined). + static const IconData fact_check_outlined = IconData(0xf045, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">factory</i> — material icon named "factory". + static const IconData factory = IconData(0xf04fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">factory</i> — material icon named "factory" (sharp). + static const IconData factory_sharp = IconData(0xf0409, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">factory</i> — material icon named "factory" (round). + static const IconData factory_rounded = IconData(0xf0316, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">factory</i> — material icon named "factory" (outlined). + static const IconData factory_outlined = IconData(0xf05f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">family_restroom</i> — material icon named "family restroom". + static const IconData family_restroom = IconData(0xe257, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">family_restroom</i> — material icon named "family restroom" (sharp). + static const IconData family_restroom_sharp = IconData(0xe954, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">family_restroom</i> — material icon named "family restroom" (round). + static const IconData family_restroom_rounded = IconData(0xf733, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">family_restroom</i> — material icon named "family restroom" (outlined). + static const IconData family_restroom_outlined = IconData(0xf046, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fast_forward</i> — material icon named "fast forward". + static const IconData fast_forward = IconData(0xe258, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fast_forward</i> — material icon named "fast forward" (sharp). + static const IconData fast_forward_sharp = IconData(0xe955, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fast_forward</i> — material icon named "fast forward" (round). + static const IconData fast_forward_rounded = IconData(0xf734, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fast_forward</i> — material icon named "fast forward" (outlined). + static const IconData fast_forward_outlined = IconData(0xf047, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fast_rewind</i> — material icon named "fast rewind". + static const IconData fast_rewind = IconData(0xe259, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fast_rewind</i> — material icon named "fast rewind" (sharp). + static const IconData fast_rewind_sharp = IconData(0xe956, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fast_rewind</i> — material icon named "fast rewind" (round). + static const IconData fast_rewind_rounded = IconData(0xf735, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fast_rewind</i> — material icon named "fast rewind" (outlined). + static const IconData fast_rewind_outlined = IconData(0xf048, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fastfood</i> — material icon named "fastfood". + static const IconData fastfood = IconData(0xe25a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fastfood</i> — material icon named "fastfood" (sharp). + static const IconData fastfood_sharp = IconData(0xe957, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fastfood</i> — material icon named "fastfood" (round). + static const IconData fastfood_rounded = IconData(0xf736, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fastfood</i> — material icon named "fastfood" (outlined). + static const IconData fastfood_outlined = IconData(0xf049, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">favorite</i> — material icon named "favorite". + static const IconData favorite = IconData(0xe25b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">favorite</i> — material icon named "favorite" (sharp). + static const IconData favorite_sharp = IconData(0xe959, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">favorite</i> — material icon named "favorite" (round). + static const IconData favorite_rounded = IconData(0xf738, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">favorite</i> — material icon named "favorite" (outlined). + static const IconData favorite_outlined = IconData(0xf04b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">favorite_border</i> — material icon named "favorite border". + static const IconData favorite_border = IconData(0xe25c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">favorite_border</i> — material icon named "favorite border" (sharp). + static const IconData favorite_border_sharp = IconData(0xe958, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">favorite_border</i> — material icon named "favorite border" (round). + static const IconData favorite_border_rounded = IconData(0xf737, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">favorite_border</i> — material icon named "favorite border" (outlined). + static const IconData favorite_border_outlined = IconData(0xf04a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">favorite_outline</i> — material icon named "favorite outline". + static const IconData favorite_outline = IconData(0xe25c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">favorite_outline</i> — material icon named "favorite outline" (sharp). + static const IconData favorite_outline_sharp = IconData(0xe958, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">favorite_outline</i> — material icon named "favorite outline" (round). + static const IconData favorite_outline_rounded = IconData(0xf737, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">favorite_outline</i> — material icon named "favorite outline" (outlined). + static const IconData favorite_outline_outlined = IconData(0xf04a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fax</i> — material icon named "fax". + static const IconData fax = IconData(0xf04fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fax</i> — material icon named "fax" (sharp). + static const IconData fax_sharp = IconData(0xf040a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fax</i> — material icon named "fax" (round). + static const IconData fax_rounded = IconData(0xf0317, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fax</i> — material icon named "fax" (outlined). + static const IconData fax_outlined = IconData(0xf05f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">featured_play_list</i> — material icon named "featured play list". + static const IconData featured_play_list = IconData(0xe25d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">featured_play_list</i> — material icon named "featured play list" (sharp). + static const IconData featured_play_list_sharp = IconData(0xe95a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">featured_play_list</i> — material icon named "featured play list" (round). + static const IconData featured_play_list_rounded = IconData(0xf739, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">featured_play_list</i> — material icon named "featured play list" (outlined). + static const IconData featured_play_list_outlined = IconData(0xf04c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">featured_video</i> — material icon named "featured video". + static const IconData featured_video = IconData(0xe25e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">featured_video</i> — material icon named "featured video" (sharp). + static const IconData featured_video_sharp = IconData(0xe95b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">featured_video</i> — material icon named "featured video" (round). + static const IconData featured_video_rounded = IconData(0xf73a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">featured_video</i> — material icon named "featured video" (outlined). + static const IconData featured_video_outlined = IconData(0xf04d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">feed</i> — material icon named "feed". + static const IconData feed = IconData(0xe25f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">feed</i> — material icon named "feed" (sharp). + static const IconData feed_sharp = IconData(0xe95c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">feed</i> — material icon named "feed" (round). + static const IconData feed_rounded = IconData(0xf73b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">feed</i> — material icon named "feed" (outlined). + static const IconData feed_outlined = IconData(0xf04e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">feedback</i> — material icon named "feedback". + static const IconData feedback = IconData(0xe260, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">feedback</i> — material icon named "feedback" (sharp). + static const IconData feedback_sharp = IconData(0xe95d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">feedback</i> — material icon named "feedback" (round). + static const IconData feedback_rounded = IconData(0xf73c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">feedback</i> — material icon named "feedback" (outlined). + static const IconData feedback_outlined = IconData(0xf04f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">female</i> — material icon named "female". + static const IconData female = IconData(0xe261, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">female</i> — material icon named "female" (sharp). + static const IconData female_sharp = IconData(0xe95e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">female</i> — material icon named "female" (round). + static const IconData female_rounded = IconData(0xf73d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">female</i> — material icon named "female" (outlined). + static const IconData female_outlined = IconData(0xf050, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fence</i> — material icon named "fence". + static const IconData fence = IconData(0xe262, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fence</i> — material icon named "fence" (sharp). + static const IconData fence_sharp = IconData(0xe95f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fence</i> — material icon named "fence" (round). + static const IconData fence_rounded = IconData(0xf73e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fence</i> — material icon named "fence" (outlined). + static const IconData fence_outlined = IconData(0xf051, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">festival</i> — material icon named "festival". + static const IconData festival = IconData(0xe263, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">festival</i> — material icon named "festival" (sharp). + static const IconData festival_sharp = IconData(0xe960, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">festival</i> — material icon named "festival" (round). + static const IconData festival_rounded = IconData(0xf73f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">festival</i> — material icon named "festival" (outlined). + static const IconData festival_outlined = IconData(0xf052, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fiber_dvr</i> — material icon named "fiber dvr". + static const IconData fiber_dvr = IconData(0xe264, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fiber_dvr</i> — material icon named "fiber dvr" (sharp). + static const IconData fiber_dvr_sharp = IconData(0xe961, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fiber_dvr</i> — material icon named "fiber dvr" (round). + static const IconData fiber_dvr_rounded = IconData(0xf740, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fiber_dvr</i> — material icon named "fiber dvr" (outlined). + static const IconData fiber_dvr_outlined = IconData(0xf053, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fiber_manual_record</i> — material icon named "fiber manual record". + static const IconData fiber_manual_record = IconData(0xe265, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fiber_manual_record</i> — material icon named "fiber manual record" (sharp). + static const IconData fiber_manual_record_sharp = IconData(0xe962, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fiber_manual_record</i> — material icon named "fiber manual record" (round). + static const IconData fiber_manual_record_rounded = IconData(0xf741, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fiber_manual_record</i> — material icon named "fiber manual record" (outlined). + static const IconData fiber_manual_record_outlined = IconData(0xf054, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fiber_new</i> — material icon named "fiber new". + static const IconData fiber_new = IconData(0xe266, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fiber_new</i> — material icon named "fiber new" (sharp). + static const IconData fiber_new_sharp = IconData(0xe963, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fiber_new</i> — material icon named "fiber new" (round). + static const IconData fiber_new_rounded = IconData(0xf742, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fiber_new</i> — material icon named "fiber new" (outlined). + static const IconData fiber_new_outlined = IconData(0xf055, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fiber_pin</i> — material icon named "fiber pin". + static const IconData fiber_pin = IconData(0xe267, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fiber_pin</i> — material icon named "fiber pin" (sharp). + static const IconData fiber_pin_sharp = IconData(0xe964, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fiber_pin</i> — material icon named "fiber pin" (round). + static const IconData fiber_pin_rounded = IconData(0xf743, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fiber_pin</i> — material icon named "fiber pin" (outlined). + static const IconData fiber_pin_outlined = IconData(0xf056, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fiber_smart_record</i> — material icon named "fiber smart record". + static const IconData fiber_smart_record = IconData(0xe268, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fiber_smart_record</i> — material icon named "fiber smart record" (sharp). + static const IconData fiber_smart_record_sharp = IconData(0xe965, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fiber_smart_record</i> — material icon named "fiber smart record" (round). + static const IconData fiber_smart_record_rounded = IconData(0xf744, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fiber_smart_record</i> — material icon named "fiber smart record" (outlined). + static const IconData fiber_smart_record_outlined = IconData(0xf057, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">file_copy</i> — material icon named "file copy". + static const IconData file_copy = IconData(0xe269, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">file_copy</i> — material icon named "file copy" (sharp). + static const IconData file_copy_sharp = IconData(0xe966, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">file_copy</i> — material icon named "file copy" (round). + static const IconData file_copy_rounded = IconData(0xf745, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">file_copy</i> — material icon named "file copy" (outlined). + static const IconData file_copy_outlined = IconData(0xf058, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">file_download</i> — material icon named "file download". + static const IconData file_download = IconData(0xe26a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">file_download</i> — material icon named "file download" (sharp). + static const IconData file_download_sharp = IconData(0xe969, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">file_download</i> — material icon named "file download" (round). + static const IconData file_download_rounded = IconData(0xf748, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">file_download</i> — material icon named "file download" (outlined). + static const IconData file_download_outlined = IconData(0xf05b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">file_download_done</i> — material icon named "file download done". + static const IconData file_download_done = IconData(0xe26b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">file_download_done</i> — material icon named "file download done" (sharp). + static const IconData file_download_done_sharp = IconData(0xe967, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">file_download_done</i> — material icon named "file download done" (round). + static const IconData file_download_done_rounded = IconData(0xf746, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">file_download_done</i> — material icon named "file download done" (outlined). + static const IconData file_download_done_outlined = IconData(0xf059, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">file_download_off</i> — material icon named "file download off". + static const IconData file_download_off = IconData(0xe26c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">file_download_off</i> — material icon named "file download off" (sharp). + static const IconData file_download_off_sharp = IconData(0xe968, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">file_download_off</i> — material icon named "file download off" (round). + static const IconData file_download_off_rounded = IconData(0xf747, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">file_download_off</i> — material icon named "file download off" (outlined). + static const IconData file_download_off_outlined = IconData(0xf05a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">file_open</i> — material icon named "file open". + static const IconData file_open = IconData(0xf04ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">file_open</i> — material icon named "file open" (sharp). + static const IconData file_open_sharp = IconData(0xf040b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">file_open</i> — material icon named "file open" (round). + static const IconData file_open_rounded = IconData(0xf0318, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">file_open</i> — material icon named "file open" (outlined). + static const IconData file_open_outlined = IconData(0xf05f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">file_present</i> — material icon named "file present". + static const IconData file_present = IconData(0xe26d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">file_present</i> — material icon named "file present" (sharp). + static const IconData file_present_sharp = IconData(0xe96a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">file_present</i> — material icon named "file present" (round). + static const IconData file_present_rounded = IconData(0xf749, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">file_present</i> — material icon named "file present" (outlined). + static const IconData file_present_outlined = IconData(0xf05c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">file_upload</i> — material icon named "file upload". + static const IconData file_upload = IconData(0xe26e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">file_upload</i> — material icon named "file upload" (sharp). + static const IconData file_upload_sharp = IconData(0xe96b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">file_upload</i> — material icon named "file upload" (round). + static const IconData file_upload_rounded = IconData(0xf74a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">file_upload</i> — material icon named "file upload" (outlined). + static const IconData file_upload_outlined = IconData(0xf05d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">file_upload_off</i> — material icon named "file upload off". + static const IconData file_upload_off = IconData(0xf0864, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter</i> — material icon named "filter". + static const IconData filter = IconData(0xe26f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter</i> — material icon named "filter" (sharp). + static const IconData filter_sharp = IconData(0xe97e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter</i> — material icon named "filter" (round). + static const IconData filter_rounded = IconData(0xf75d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter</i> — material icon named "filter" (outlined). + static const IconData filter_outlined = IconData(0xf070, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_1</i> — material icon named "filter 1". + static const IconData filter_1 = IconData(0xe270, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_1</i> — material icon named "filter 1" (sharp). + static const IconData filter_1_sharp = IconData(0xe96c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_1</i> — material icon named "filter 1" (round). + static const IconData filter_1_rounded = IconData(0xf74b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_1</i> — material icon named "filter 1" (outlined). + static const IconData filter_1_outlined = IconData(0xf05e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_2</i> — material icon named "filter 2". + static const IconData filter_2 = IconData(0xe271, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_2</i> — material icon named "filter 2" (sharp). + static const IconData filter_2_sharp = IconData(0xe96d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_2</i> — material icon named "filter 2" (round). + static const IconData filter_2_rounded = IconData(0xf74c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_2</i> — material icon named "filter 2" (outlined). + static const IconData filter_2_outlined = IconData(0xf05f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_3</i> — material icon named "filter 3". + static const IconData filter_3 = IconData(0xe272, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_3</i> — material icon named "filter 3" (sharp). + static const IconData filter_3_sharp = IconData(0xe96e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_3</i> — material icon named "filter 3" (round). + static const IconData filter_3_rounded = IconData(0xf74d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_3</i> — material icon named "filter 3" (outlined). + static const IconData filter_3_outlined = IconData(0xf060, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_4</i> — material icon named "filter 4". + static const IconData filter_4 = IconData(0xe273, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_4</i> — material icon named "filter 4" (sharp). + static const IconData filter_4_sharp = IconData(0xe96f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_4</i> — material icon named "filter 4" (round). + static const IconData filter_4_rounded = IconData(0xf74e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_4</i> — material icon named "filter 4" (outlined). + static const IconData filter_4_outlined = IconData(0xf061, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_5</i> — material icon named "filter 5". + static const IconData filter_5 = IconData(0xe274, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_5</i> — material icon named "filter 5" (sharp). + static const IconData filter_5_sharp = IconData(0xe970, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_5</i> — material icon named "filter 5" (round). + static const IconData filter_5_rounded = IconData(0xf74f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_5</i> — material icon named "filter 5" (outlined). + static const IconData filter_5_outlined = IconData(0xf062, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_6</i> — material icon named "filter 6". + static const IconData filter_6 = IconData(0xe275, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_6</i> — material icon named "filter 6" (sharp). + static const IconData filter_6_sharp = IconData(0xe971, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_6</i> — material icon named "filter 6" (round). + static const IconData filter_6_rounded = IconData(0xf750, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_6</i> — material icon named "filter 6" (outlined). + static const IconData filter_6_outlined = IconData(0xf063, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_7</i> — material icon named "filter 7". + static const IconData filter_7 = IconData(0xe276, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_7</i> — material icon named "filter 7" (sharp). + static const IconData filter_7_sharp = IconData(0xe972, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_7</i> — material icon named "filter 7" (round). + static const IconData filter_7_rounded = IconData(0xf751, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_7</i> — material icon named "filter 7" (outlined). + static const IconData filter_7_outlined = IconData(0xf064, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_8</i> — material icon named "filter 8". + static const IconData filter_8 = IconData(0xe277, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_8</i> — material icon named "filter 8" (sharp). + static const IconData filter_8_sharp = IconData(0xe973, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_8</i> — material icon named "filter 8" (round). + static const IconData filter_8_rounded = IconData(0xf752, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_8</i> — material icon named "filter 8" (outlined). + static const IconData filter_8_outlined = IconData(0xf065, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_9</i> — material icon named "filter 9". + static const IconData filter_9 = IconData(0xe278, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_9</i> — material icon named "filter 9" (sharp). + static const IconData filter_9_sharp = IconData(0xe975, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_9</i> — material icon named "filter 9" (round). + static const IconData filter_9_rounded = IconData(0xf754, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_9</i> — material icon named "filter 9" (outlined). + static const IconData filter_9_outlined = IconData(0xf066, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_9_plus</i> — material icon named "filter 9 plus". + static const IconData filter_9_plus = IconData(0xe279, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_9_plus</i> — material icon named "filter 9 plus" (sharp). + static const IconData filter_9_plus_sharp = IconData(0xe974, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_9_plus</i> — material icon named "filter 9 plus" (round). + static const IconData filter_9_plus_rounded = IconData(0xf753, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_9_plus</i> — material icon named "filter 9 plus" (outlined). + static const IconData filter_9_plus_outlined = IconData(0xf067, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_alt</i> — material icon named "filter alt". + static const IconData filter_alt = IconData(0xe27a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_alt</i> — material icon named "filter alt" (sharp). + static const IconData filter_alt_sharp = IconData(0xe976, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_alt</i> — material icon named "filter alt" (round). + static const IconData filter_alt_rounded = IconData(0xf755, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_alt</i> — material icon named "filter alt" (outlined). + static const IconData filter_alt_outlined = IconData(0xf068, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_alt_off</i> — material icon named "filter alt off". + static const IconData filter_alt_off = IconData(0xf0500, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_alt_off</i> — material icon named "filter alt off" (sharp). + static const IconData filter_alt_off_sharp = IconData(0xf040c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_alt_off</i> — material icon named "filter alt off" (round). + static const IconData filter_alt_off_rounded = IconData(0xf0319, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_alt_off</i> — material icon named "filter alt off" (outlined). + static const IconData filter_alt_off_outlined = IconData(0xf05fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_b_and_w</i> — material icon named "filter b and w". + static const IconData filter_b_and_w = IconData(0xe27b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_b_and_w</i> — material icon named "filter b and w" (sharp). + static const IconData filter_b_and_w_sharp = IconData(0xe977, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_b_and_w</i> — material icon named "filter b and w" (round). + static const IconData filter_b_and_w_rounded = IconData(0xf756, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_b_and_w</i> — material icon named "filter b and w" (outlined). + static const IconData filter_b_and_w_outlined = IconData(0xf069, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_center_focus</i> — material icon named "filter center focus". + static const IconData filter_center_focus = IconData(0xe27c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_center_focus</i> — material icon named "filter center focus" (sharp). + static const IconData filter_center_focus_sharp = IconData(0xe978, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_center_focus</i> — material icon named "filter center focus" (round). + static const IconData filter_center_focus_rounded = IconData(0xf757, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_center_focus</i> — material icon named "filter center focus" (outlined). + static const IconData filter_center_focus_outlined = IconData(0xf06a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_drama</i> — material icon named "filter drama". + static const IconData filter_drama = IconData(0xe27d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_drama</i> — material icon named "filter drama" (sharp). + static const IconData filter_drama_sharp = IconData(0xe979, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_drama</i> — material icon named "filter drama" (round). + static const IconData filter_drama_rounded = IconData(0xf758, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_drama</i> — material icon named "filter drama" (outlined). + static const IconData filter_drama_outlined = IconData(0xf06b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_frames</i> — material icon named "filter frames". + static const IconData filter_frames = IconData(0xe27e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_frames</i> — material icon named "filter frames" (sharp). + static const IconData filter_frames_sharp = IconData(0xe97a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_frames</i> — material icon named "filter frames" (round). + static const IconData filter_frames_rounded = IconData(0xf759, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_frames</i> — material icon named "filter frames" (outlined). + static const IconData filter_frames_outlined = IconData(0xf06c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_hdr</i> — material icon named "filter hdr". + static const IconData filter_hdr = IconData(0xe27f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_hdr</i> — material icon named "filter hdr" (sharp). + static const IconData filter_hdr_sharp = IconData(0xe97b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_hdr</i> — material icon named "filter hdr" (round). + static const IconData filter_hdr_rounded = IconData(0xf75a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_hdr</i> — material icon named "filter hdr" (outlined). + static const IconData filter_hdr_outlined = IconData(0xf06d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_list</i> — material icon named "filter list". + static const IconData filter_list = IconData(0xe280, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_list</i> — material icon named "filter list" (sharp). + static const IconData filter_list_sharp = IconData(0xe97c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_list</i> — material icon named "filter list" (round). + static const IconData filter_list_rounded = IconData(0xf75b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_list</i> — material icon named "filter list" (outlined). + static const IconData filter_list_outlined = IconData(0xf06e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_list_alt</i> — material icon named "filter list alt". + static const IconData filter_list_alt = IconData(0xe281, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_list_off</i> — material icon named "filter list off". + static const IconData filter_list_off = IconData(0xf0501, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_list_off</i> — material icon named "filter list off" (sharp). + static const IconData filter_list_off_sharp = IconData(0xf040d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_list_off</i> — material icon named "filter list off" (round). + static const IconData filter_list_off_rounded = IconData(0xf031a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_list_off</i> — material icon named "filter list off" (outlined). + static const IconData filter_list_off_outlined = IconData(0xf05fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_none</i> — material icon named "filter none". + static const IconData filter_none = IconData(0xe282, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_none</i> — material icon named "filter none" (sharp). + static const IconData filter_none_sharp = IconData(0xe97d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_none</i> — material icon named "filter none" (round). + static const IconData filter_none_rounded = IconData(0xf75c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_none</i> — material icon named "filter none" (outlined). + static const IconData filter_none_outlined = IconData(0xf06f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_tilt_shift</i> — material icon named "filter tilt shift". + static const IconData filter_tilt_shift = IconData(0xe283, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_tilt_shift</i> — material icon named "filter tilt shift" (sharp). + static const IconData filter_tilt_shift_sharp = IconData(0xe97f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_tilt_shift</i> — material icon named "filter tilt shift" (round). + static const IconData filter_tilt_shift_rounded = IconData(0xf75e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_tilt_shift</i> — material icon named "filter tilt shift" (outlined). + static const IconData filter_tilt_shift_outlined = IconData(0xf071, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">filter_vintage</i> — material icon named "filter vintage". + static const IconData filter_vintage = IconData(0xe284, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">filter_vintage</i> — material icon named "filter vintage" (sharp). + static const IconData filter_vintage_sharp = IconData(0xe980, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">filter_vintage</i> — material icon named "filter vintage" (round). + static const IconData filter_vintage_rounded = IconData(0xf75f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">filter_vintage</i> — material icon named "filter vintage" (outlined). + static const IconData filter_vintage_outlined = IconData(0xf072, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">find_in_page</i> — material icon named "find in page". + static const IconData find_in_page = IconData(0xe285, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">find_in_page</i> — material icon named "find in page" (sharp). + static const IconData find_in_page_sharp = IconData(0xe981, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">find_in_page</i> — material icon named "find in page" (round). + static const IconData find_in_page_rounded = IconData(0xf760, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">find_in_page</i> — material icon named "find in page" (outlined). + static const IconData find_in_page_outlined = IconData(0xf073, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">find_replace</i> — material icon named "find replace". + static const IconData find_replace = IconData(0xe286, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">find_replace</i> — material icon named "find replace" (sharp). + static const IconData find_replace_sharp = IconData(0xe982, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">find_replace</i> — material icon named "find replace" (round). + static const IconData find_replace_rounded = IconData(0xf761, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">find_replace</i> — material icon named "find replace" (outlined). + static const IconData find_replace_outlined = IconData(0xf074, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fingerprint</i> — material icon named "fingerprint". + static const IconData fingerprint = IconData(0xe287, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fingerprint</i> — material icon named "fingerprint" (sharp). + static const IconData fingerprint_sharp = IconData(0xe983, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fingerprint</i> — material icon named "fingerprint" (round). + static const IconData fingerprint_rounded = IconData(0xf762, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fingerprint</i> — material icon named "fingerprint" (outlined). + static const IconData fingerprint_outlined = IconData(0xf075, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fire_extinguisher</i> — material icon named "fire extinguisher". + static const IconData fire_extinguisher = IconData(0xe288, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fire_extinguisher</i> — material icon named "fire extinguisher" (sharp). + static const IconData fire_extinguisher_sharp = IconData(0xe984, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fire_extinguisher</i> — material icon named "fire extinguisher" (round). + static const IconData fire_extinguisher_rounded = IconData(0xf763, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fire_extinguisher</i> — material icon named "fire extinguisher" (outlined). + static const IconData fire_extinguisher_outlined = IconData(0xf076, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fire_hydrant</i> — material icon named "fire hydrant". + static const IconData fire_hydrant = IconData(0xe289, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fire_hydrant_alt</i> — material icon named "fire hydrant alt". + static const IconData fire_hydrant_alt = IconData(0xf07a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fire_hydrant_alt</i> — material icon named "fire hydrant alt" (sharp). + static const IconData fire_hydrant_alt_sharp = IconData(0xf0749, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fire_hydrant_alt</i> — material icon named "fire hydrant alt" (round). + static const IconData fire_hydrant_alt_rounded = IconData(0xf07f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fire_hydrant_alt</i> — material icon named "fire hydrant alt" (outlined). + static const IconData fire_hydrant_alt_outlined = IconData(0xf06f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fire_truck</i> — material icon named "fire truck". + static const IconData fire_truck = IconData(0xf07a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fire_truck</i> — material icon named "fire truck" (sharp). + static const IconData fire_truck_sharp = IconData(0xf074a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fire_truck</i> — material icon named "fire truck" (round). + static const IconData fire_truck_rounded = IconData(0xf07fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fire_truck</i> — material icon named "fire truck" (outlined). + static const IconData fire_truck_outlined = IconData(0xf06f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fireplace</i> — material icon named "fireplace". + static const IconData fireplace = IconData(0xe28a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fireplace</i> — material icon named "fireplace" (sharp). + static const IconData fireplace_sharp = IconData(0xe985, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fireplace</i> — material icon named "fireplace" (round). + static const IconData fireplace_rounded = IconData(0xf764, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fireplace</i> — material icon named "fireplace" (outlined). + static const IconData fireplace_outlined = IconData(0xf077, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">first_page</i> — material icon named "first page". + static const IconData first_page = IconData(0xe28b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">first_page</i> — material icon named "first page" (sharp). + static const IconData first_page_sharp = IconData(0xe986, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">first_page</i> — material icon named "first page" (round). + static const IconData first_page_rounded = IconData(0xf765, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">first_page</i> — material icon named "first page" (outlined). + static const IconData first_page_outlined = IconData(0xf078, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">fit_screen</i> — material icon named "fit screen". + static const IconData fit_screen = IconData(0xe28c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fit_screen</i> — material icon named "fit screen" (sharp). + static const IconData fit_screen_sharp = IconData(0xe987, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fit_screen</i> — material icon named "fit screen" (round). + static const IconData fit_screen_rounded = IconData(0xf766, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fit_screen</i> — material icon named "fit screen" (outlined). + static const IconData fit_screen_outlined = IconData(0xf079, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fitbit</i> — material icon named "fitbit". + static const IconData fitbit = IconData(0xf0502, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fitbit</i> — material icon named "fitbit" (sharp). + static const IconData fitbit_sharp = IconData(0xf040e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fitbit</i> — material icon named "fitbit" (round). + static const IconData fitbit_rounded = IconData(0xf031b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fitbit</i> — material icon named "fitbit" (outlined). + static const IconData fitbit_outlined = IconData(0xf05fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fitness_center</i> — material icon named "fitness center". + static const IconData fitness_center = IconData(0xe28d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fitness_center</i> — material icon named "fitness center" (sharp). + static const IconData fitness_center_sharp = IconData(0xe988, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fitness_center</i> — material icon named "fitness center" (round). + static const IconData fitness_center_rounded = IconData(0xf767, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fitness_center</i> — material icon named "fitness center" (outlined). + static const IconData fitness_center_outlined = IconData(0xf07a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flag</i> — material icon named "flag". + static const IconData flag = IconData(0xe28e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flag</i> — material icon named "flag" (sharp). + static const IconData flag_sharp = IconData(0xe989, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flag</i> — material icon named "flag" (round). + static const IconData flag_rounded = IconData(0xf768, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flag</i> — material icon named "flag" (outlined). + static const IconData flag_outlined = IconData(0xf07b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flag_circle</i> — material icon named "flag circle". + static const IconData flag_circle = IconData(0xf0503, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flag_circle</i> — material icon named "flag circle" (sharp). + static const IconData flag_circle_sharp = IconData(0xf040f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flag_circle</i> — material icon named "flag circle" (round). + static const IconData flag_circle_rounded = IconData(0xf031c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flag_circle</i> — material icon named "flag circle" (outlined). + static const IconData flag_circle_outlined = IconData(0xf05fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flaky</i> — material icon named "flaky". + static const IconData flaky = IconData(0xe28f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flaky</i> — material icon named "flaky" (sharp). + static const IconData flaky_sharp = IconData(0xe98a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flaky</i> — material icon named "flaky" (round). + static const IconData flaky_rounded = IconData(0xf769, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flaky</i> — material icon named "flaky" (outlined). + static const IconData flaky_outlined = IconData(0xf07c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flare</i> — material icon named "flare". + static const IconData flare = IconData(0xe290, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flare</i> — material icon named "flare" (sharp). + static const IconData flare_sharp = IconData(0xe98b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flare</i> — material icon named "flare" (round). + static const IconData flare_rounded = IconData(0xf76a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flare</i> — material icon named "flare" (outlined). + static const IconData flare_outlined = IconData(0xf07d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flash_auto</i> — material icon named "flash auto". + static const IconData flash_auto = IconData(0xe291, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flash_auto</i> — material icon named "flash auto" (sharp). + static const IconData flash_auto_sharp = IconData(0xe98c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flash_auto</i> — material icon named "flash auto" (round). + static const IconData flash_auto_rounded = IconData(0xf76b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flash_auto</i> — material icon named "flash auto" (outlined). + static const IconData flash_auto_outlined = IconData(0xf07e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flash_off</i> — material icon named "flash off". + static const IconData flash_off = IconData(0xe292, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flash_off</i> — material icon named "flash off" (sharp). + static const IconData flash_off_sharp = IconData(0xe98d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flash_off</i> — material icon named "flash off" (round). + static const IconData flash_off_rounded = IconData(0xf76c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flash_off</i> — material icon named "flash off" (outlined). + static const IconData flash_off_outlined = IconData(0xf07f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flash_on</i> — material icon named "flash on". + static const IconData flash_on = IconData(0xe293, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flash_on</i> — material icon named "flash on" (sharp). + static const IconData flash_on_sharp = IconData(0xe98e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flash_on</i> — material icon named "flash on" (round). + static const IconData flash_on_rounded = IconData(0xf76d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flash_on</i> — material icon named "flash on" (outlined). + static const IconData flash_on_outlined = IconData(0xf080, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flashlight_off</i> — material icon named "flashlight off". + static const IconData flashlight_off = IconData(0xe294, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flashlight_off</i> — material icon named "flashlight off" (sharp). + static const IconData flashlight_off_sharp = IconData(0xe98f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flashlight_off</i> — material icon named "flashlight off" (round). + static const IconData flashlight_off_rounded = IconData(0xf76e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flashlight_off</i> — material icon named "flashlight off" (outlined). + static const IconData flashlight_off_outlined = IconData(0xf081, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flashlight_on</i> — material icon named "flashlight on". + static const IconData flashlight_on = IconData(0xe295, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flashlight_on</i> — material icon named "flashlight on" (sharp). + static const IconData flashlight_on_sharp = IconData(0xe990, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flashlight_on</i> — material icon named "flashlight on" (round). + static const IconData flashlight_on_rounded = IconData(0xf76f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flashlight_on</i> — material icon named "flashlight on" (outlined). + static const IconData flashlight_on_outlined = IconData(0xf082, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flatware</i> — material icon named "flatware". + static const IconData flatware = IconData(0xe296, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flatware</i> — material icon named "flatware" (sharp). + static const IconData flatware_sharp = IconData(0xe991, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flatware</i> — material icon named "flatware" (round). + static const IconData flatware_rounded = IconData(0xf770, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flatware</i> — material icon named "flatware" (outlined). + static const IconData flatware_outlined = IconData(0xf083, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flight</i> — material icon named "flight". + static const IconData flight = IconData(0xe297, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flight</i> — material icon named "flight" (sharp). + static const IconData flight_sharp = IconData(0xe993, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flight</i> — material icon named "flight" (round). + static const IconData flight_rounded = IconData(0xf772, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flight</i> — material icon named "flight" (outlined). + static const IconData flight_outlined = IconData(0xf085, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flight_class</i> — material icon named "flight class". + static const IconData flight_class = IconData(0xf0504, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flight_class</i> — material icon named "flight class" (sharp). + static const IconData flight_class_sharp = IconData(0xf0410, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flight_class</i> — material icon named "flight class" (round). + static const IconData flight_class_rounded = IconData(0xf031d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flight_class</i> — material icon named "flight class" (outlined). + static const IconData flight_class_outlined = IconData(0xf05fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flight_land</i> — material icon named "flight land". + static const IconData flight_land = IconData(0xe298, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">flight_land</i> — material icon named "flight land" (sharp). + static const IconData flight_land_sharp = IconData(0xe992, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">flight_land</i> — material icon named "flight land" (round). + static const IconData flight_land_rounded = IconData(0xf771, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">flight_land</i> — material icon named "flight land" (outlined). + static const IconData flight_land_outlined = IconData(0xf084, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">flight_takeoff</i> — material icon named "flight takeoff". + static const IconData flight_takeoff = IconData(0xe299, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">flight_takeoff</i> — material icon named "flight takeoff" (sharp). + static const IconData flight_takeoff_sharp = IconData(0xe994, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">flight_takeoff</i> — material icon named "flight takeoff" (round). + static const IconData flight_takeoff_rounded = IconData(0xf773, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">flight_takeoff</i> — material icon named "flight takeoff" (outlined). + static const IconData flight_takeoff_outlined = IconData(0xf086, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">flip</i> — material icon named "flip". + static const IconData flip = IconData(0xe29a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flip</i> — material icon named "flip" (sharp). + static const IconData flip_sharp = IconData(0xe997, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flip</i> — material icon named "flip" (round). + static const IconData flip_rounded = IconData(0xf776, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flip</i> — material icon named "flip" (outlined). + static const IconData flip_outlined = IconData(0xf089, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flip_camera_android</i> — material icon named "flip camera android". + static const IconData flip_camera_android = IconData(0xe29b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flip_camera_android</i> — material icon named "flip camera android" (sharp). + static const IconData flip_camera_android_sharp = IconData(0xe995, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flip_camera_android</i> — material icon named "flip camera android" (round). + static const IconData flip_camera_android_rounded = IconData(0xf774, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flip_camera_android</i> — material icon named "flip camera android" (outlined). + static const IconData flip_camera_android_outlined = IconData(0xf087, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flip_camera_ios</i> — material icon named "flip camera ios". + static const IconData flip_camera_ios = IconData(0xe29c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flip_camera_ios</i> — material icon named "flip camera ios" (sharp). + static const IconData flip_camera_ios_sharp = IconData(0xe996, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flip_camera_ios</i> — material icon named "flip camera ios" (round). + static const IconData flip_camera_ios_rounded = IconData(0xf775, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flip_camera_ios</i> — material icon named "flip camera ios" (outlined). + static const IconData flip_camera_ios_outlined = IconData(0xf088, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flip_to_back</i> — material icon named "flip to back". + static const IconData flip_to_back = IconData(0xe29d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flip_to_back</i> — material icon named "flip to back" (sharp). + static const IconData flip_to_back_sharp = IconData(0xe998, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flip_to_back</i> — material icon named "flip to back" (round). + static const IconData flip_to_back_rounded = IconData(0xf777, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flip_to_back</i> — material icon named "flip to back" (outlined). + static const IconData flip_to_back_outlined = IconData(0xf08a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flip_to_front</i> — material icon named "flip to front". + static const IconData flip_to_front = IconData(0xe29e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flip_to_front</i> — material icon named "flip to front" (sharp). + static const IconData flip_to_front_sharp = IconData(0xe999, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flip_to_front</i> — material icon named "flip to front" (round). + static const IconData flip_to_front_rounded = IconData(0xf778, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flip_to_front</i> — material icon named "flip to front" (outlined). + static const IconData flip_to_front_outlined = IconData(0xf08b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flood</i> — material icon named "flood". + static const IconData flood = IconData(0xf07a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flood</i> — material icon named "flood" (sharp). + static const IconData flood_sharp = IconData(0xf074b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flood</i> — material icon named "flood" (round). + static const IconData flood_rounded = IconData(0xf07fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flood</i> — material icon named "flood" (outlined). + static const IconData flood_outlined = IconData(0xf06f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flourescent</i> — material icon named "flourescent". + static const IconData flourescent = IconData(0xf0865, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flourescent</i> — material icon named "flourescent" (sharp). + static const IconData flourescent_sharp = IconData(0xf0840, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flourescent</i> — material icon named "flourescent" (round). + static const IconData flourescent_rounded = IconData(0xf0889, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flourescent</i> — material icon named "flourescent" (outlined). + static const IconData flourescent_outlined = IconData(0xf08a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fluorescent</i> — material icon named "fluorescent". + static const IconData fluorescent = IconData(0xf0865, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fluorescent</i> — material icon named "fluorescent" (sharp). + static const IconData fluorescent_sharp = IconData(0xf0840, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fluorescent</i> — material icon named "fluorescent" (round). + static const IconData fluorescent_rounded = IconData(0xf0889, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fluorescent</i> — material icon named "fluorescent" (outlined). + static const IconData fluorescent_outlined = IconData(0xf08a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">flutter_dash</i> — material icon named "flutter dash". + static const IconData flutter_dash = IconData(0xe2a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">flutter_dash</i> — material icon named "flutter dash" (sharp). + static const IconData flutter_dash_sharp = IconData(0xe99b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">flutter_dash</i> — material icon named "flutter dash" (round). + static const IconData flutter_dash_rounded = IconData(0xf77a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">flutter_dash</i> — material icon named "flutter dash" (outlined). + static const IconData flutter_dash_outlined = IconData(0xf08d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fmd_bad</i> — material icon named "fmd bad". + static const IconData fmd_bad = IconData(0xe2a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fmd_bad</i> — material icon named "fmd bad" (sharp). + static const IconData fmd_bad_sharp = IconData(0xe99c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fmd_bad</i> — material icon named "fmd bad" (round). + static const IconData fmd_bad_rounded = IconData(0xf77b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fmd_bad</i> — material icon named "fmd bad" (outlined). + static const IconData fmd_bad_outlined = IconData(0xf08e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fmd_good</i> — material icon named "fmd good". + static const IconData fmd_good = IconData(0xe2a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fmd_good</i> — material icon named "fmd good" (sharp). + static const IconData fmd_good_sharp = IconData(0xe99d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fmd_good</i> — material icon named "fmd good" (round). + static const IconData fmd_good_rounded = IconData(0xf77c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fmd_good</i> — material icon named "fmd good" (outlined). + static const IconData fmd_good_outlined = IconData(0xf08f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">foggy</i> — material icon named "foggy". + static const IconData foggy = IconData(0xf0505, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">folder</i> — material icon named "folder". + static const IconData folder = IconData(0xe2a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">folder</i> — material icon named "folder" (sharp). + static const IconData folder_sharp = IconData(0xe9a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">folder</i> — material icon named "folder" (round). + static const IconData folder_rounded = IconData(0xf77e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">folder</i> — material icon named "folder" (outlined). + static const IconData folder_outlined = IconData(0xf091, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">folder_copy</i> — material icon named "folder copy". + static const IconData folder_copy = IconData(0xf0506, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">folder_copy</i> — material icon named "folder copy" (sharp). + static const IconData folder_copy_sharp = IconData(0xf0411, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">folder_copy</i> — material icon named "folder copy" (round). + static const IconData folder_copy_rounded = IconData(0xf031e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">folder_copy</i> — material icon named "folder copy" (outlined). + static const IconData folder_copy_outlined = IconData(0xf05ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">folder_delete</i> — material icon named "folder delete". + static const IconData folder_delete = IconData(0xf0507, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">folder_delete</i> — material icon named "folder delete" (sharp). + static const IconData folder_delete_sharp = IconData(0xf0412, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">folder_delete</i> — material icon named "folder delete" (round). + static const IconData folder_delete_rounded = IconData(0xf031f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">folder_delete</i> — material icon named "folder delete" (outlined). + static const IconData folder_delete_outlined = IconData(0xf0600, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">folder_off</i> — material icon named "folder off". + static const IconData folder_off = IconData(0xf0508, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">folder_off</i> — material icon named "folder off" (sharp). + static const IconData folder_off_sharp = IconData(0xf0413, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">folder_off</i> — material icon named "folder off" (round). + static const IconData folder_off_rounded = IconData(0xf0320, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">folder_off</i> — material icon named "folder off" (outlined). + static const IconData folder_off_outlined = IconData(0xf0601, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">folder_open</i> — material icon named "folder open". + static const IconData folder_open = IconData(0xe2a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">folder_open</i> — material icon named "folder open" (sharp). + static const IconData folder_open_sharp = IconData(0xe99e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">folder_open</i> — material icon named "folder open" (round). + static const IconData folder_open_rounded = IconData(0xf77d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">folder_open</i> — material icon named "folder open" (outlined). + static const IconData folder_open_outlined = IconData(0xf090, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">folder_shared</i> — material icon named "folder shared". + static const IconData folder_shared = IconData(0xe2a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">folder_shared</i> — material icon named "folder shared" (sharp). + static const IconData folder_shared_sharp = IconData(0xe99f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">folder_shared</i> — material icon named "folder shared" (round). + static const IconData folder_shared_rounded = IconData(0xf77f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">folder_shared</i> — material icon named "folder shared" (outlined). + static const IconData folder_shared_outlined = IconData(0xf092, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">folder_special</i> — material icon named "folder special". + static const IconData folder_special = IconData(0xe2a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">folder_special</i> — material icon named "folder special" (sharp). + static const IconData folder_special_sharp = IconData(0xe9a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">folder_special</i> — material icon named "folder special" (round). + static const IconData folder_special_rounded = IconData(0xf780, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">folder_special</i> — material icon named "folder special" (outlined). + static const IconData folder_special_outlined = IconData(0xf093, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">folder_zip</i> — material icon named "folder zip". + static const IconData folder_zip = IconData(0xf0509, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">folder_zip</i> — material icon named "folder zip" (sharp). + static const IconData folder_zip_sharp = IconData(0xf0414, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">folder_zip</i> — material icon named "folder zip" (round). + static const IconData folder_zip_rounded = IconData(0xf0321, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">folder_zip</i> — material icon named "folder zip" (outlined). + static const IconData folder_zip_outlined = IconData(0xf0602, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">follow_the_signs</i> — material icon named "follow the signs". + static const IconData follow_the_signs = IconData(0xe2a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">follow_the_signs</i> — material icon named "follow the signs" (sharp). + static const IconData follow_the_signs_sharp = IconData(0xe9a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">follow_the_signs</i> — material icon named "follow the signs" (round). + static const IconData follow_the_signs_rounded = IconData(0xf781, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">follow_the_signs</i> — material icon named "follow the signs" (outlined). + static const IconData follow_the_signs_outlined = IconData(0xf094, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">font_download</i> — material icon named "font download". + static const IconData font_download = IconData(0xe2a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">font_download</i> — material icon named "font download" (sharp). + static const IconData font_download_sharp = IconData(0xe9a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">font_download</i> — material icon named "font download" (round). + static const IconData font_download_rounded = IconData(0xf783, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">font_download</i> — material icon named "font download" (outlined). + static const IconData font_download_outlined = IconData(0xf096, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">font_download_off</i> — material icon named "font download off". + static const IconData font_download_off = IconData(0xe2a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">font_download_off</i> — material icon named "font download off" (sharp). + static const IconData font_download_off_sharp = IconData(0xe9a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">font_download_off</i> — material icon named "font download off" (round). + static const IconData font_download_off_rounded = IconData(0xf782, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">font_download_off</i> — material icon named "font download off" (outlined). + static const IconData font_download_off_outlined = IconData(0xf095, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">food_bank</i> — material icon named "food bank". + static const IconData food_bank = IconData(0xe2aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">food_bank</i> — material icon named "food bank" (sharp). + static const IconData food_bank_sharp = IconData(0xe9a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">food_bank</i> — material icon named "food bank" (round). + static const IconData food_bank_rounded = IconData(0xf784, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">food_bank</i> — material icon named "food bank" (outlined). + static const IconData food_bank_outlined = IconData(0xf097, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">forest</i> — material icon named "forest". + static const IconData forest = IconData(0xf050a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">forest</i> — material icon named "forest" (sharp). + static const IconData forest_sharp = IconData(0xf0415, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">forest</i> — material icon named "forest" (round). + static const IconData forest_rounded = IconData(0xf0322, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">forest</i> — material icon named "forest" (outlined). + static const IconData forest_outlined = IconData(0xf0603, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fork_left</i> — material icon named "fork left". + static const IconData fork_left = IconData(0xf050b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fork_left</i> — material icon named "fork left" (sharp). + static const IconData fork_left_sharp = IconData(0xf0416, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fork_left</i> — material icon named "fork left" (round). + static const IconData fork_left_rounded = IconData(0xf0323, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fork_left</i> — material icon named "fork left" (outlined). + static const IconData fork_left_outlined = IconData(0xf0604, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fork_right</i> — material icon named "fork right". + static const IconData fork_right = IconData(0xf050c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fork_right</i> — material icon named "fork right" (sharp). + static const IconData fork_right_sharp = IconData(0xf0417, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fork_right</i> — material icon named "fork right" (round). + static const IconData fork_right_rounded = IconData(0xf0324, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fork_right</i> — material icon named "fork right" (outlined). + static const IconData fork_right_outlined = IconData(0xf0605, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">forklift</i> — material icon named "forklift". + static const IconData forklift = IconData(0xf0866, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_align_center</i> — material icon named "format align center". + static const IconData format_align_center = IconData(0xe2ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_align_center</i> — material icon named "format align center" (sharp). + static const IconData format_align_center_sharp = IconData(0xe9a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_align_center</i> — material icon named "format align center" (round). + static const IconData format_align_center_rounded = IconData(0xf785, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_align_center</i> — material icon named "format align center" (outlined). + static const IconData format_align_center_outlined = IconData(0xf098, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_align_justify</i> — material icon named "format align justify". + static const IconData format_align_justify = IconData(0xe2ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_align_justify</i> — material icon named "format align justify" (sharp). + static const IconData format_align_justify_sharp = IconData(0xe9a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_align_justify</i> — material icon named "format align justify" (round). + static const IconData format_align_justify_rounded = IconData(0xf786, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_align_justify</i> — material icon named "format align justify" (outlined). + static const IconData format_align_justify_outlined = IconData(0xf099, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_align_left</i> — material icon named "format align left". + static const IconData format_align_left = IconData(0xe2ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_align_left</i> — material icon named "format align left" (sharp). + static const IconData format_align_left_sharp = IconData(0xe9a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_align_left</i> — material icon named "format align left" (round). + static const IconData format_align_left_rounded = IconData(0xf787, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_align_left</i> — material icon named "format align left" (outlined). + static const IconData format_align_left_outlined = IconData(0xf09a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_align_right</i> — material icon named "format align right". + static const IconData format_align_right = IconData(0xe2ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_align_right</i> — material icon named "format align right" (sharp). + static const IconData format_align_right_sharp = IconData(0xe9a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_align_right</i> — material icon named "format align right" (round). + static const IconData format_align_right_rounded = IconData(0xf788, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_align_right</i> — material icon named "format align right" (outlined). + static const IconData format_align_right_outlined = IconData(0xf09b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_bold</i> — material icon named "format bold". + static const IconData format_bold = IconData(0xe2af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_bold</i> — material icon named "format bold" (sharp). + static const IconData format_bold_sharp = IconData(0xe9aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_bold</i> — material icon named "format bold" (round). + static const IconData format_bold_rounded = IconData(0xf789, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_bold</i> — material icon named "format bold" (outlined). + static const IconData format_bold_outlined = IconData(0xf09c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_clear</i> — material icon named "format clear". + static const IconData format_clear = IconData(0xe2b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_clear</i> — material icon named "format clear" (sharp). + static const IconData format_clear_sharp = IconData(0xe9ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_clear</i> — material icon named "format clear" (round). + static const IconData format_clear_rounded = IconData(0xf78a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_clear</i> — material icon named "format clear" (outlined). + static const IconData format_clear_outlined = IconData(0xf09d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_color_fill</i> — material icon named "format color fill". + static const IconData format_color_fill = IconData(0xe2b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_color_fill</i> — material icon named "format color fill" (sharp). + static const IconData format_color_fill_sharp = IconData(0xe9ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_color_fill</i> — material icon named "format color fill" (round). + static const IconData format_color_fill_rounded = IconData(0xf78b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_color_fill</i> — material icon named "format color fill" (outlined). + static const IconData format_color_fill_outlined = IconData(0xf09e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_color_reset</i> — material icon named "format color reset". + static const IconData format_color_reset = IconData(0xe2b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_color_reset</i> — material icon named "format color reset" (sharp). + static const IconData format_color_reset_sharp = IconData(0xe9ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_color_reset</i> — material icon named "format color reset" (round). + static const IconData format_color_reset_rounded = IconData(0xf78c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_color_reset</i> — material icon named "format color reset" (outlined). + static const IconData format_color_reset_outlined = IconData(0xf09f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_color_text</i> — material icon named "format color text". + static const IconData format_color_text = IconData(0xe2b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_color_text</i> — material icon named "format color text" (sharp). + static const IconData format_color_text_sharp = IconData(0xe9ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_color_text</i> — material icon named "format color text" (round). + static const IconData format_color_text_rounded = IconData(0xf78d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_color_text</i> — material icon named "format color text" (outlined). + static const IconData format_color_text_outlined = IconData(0xf0a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_indent_decrease</i> — material icon named "format indent decrease". + static const IconData format_indent_decrease = IconData(0xe2b4, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">format_indent_decrease</i> — material icon named "format indent decrease" (sharp). + static const IconData format_indent_decrease_sharp = IconData(0xe9af, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">format_indent_decrease</i> — material icon named "format indent decrease" (round). + static const IconData format_indent_decrease_rounded = IconData(0xf78e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">format_indent_decrease</i> — material icon named "format indent decrease" (outlined). + static const IconData format_indent_decrease_outlined = IconData(0xf0a1, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">format_indent_increase</i> — material icon named "format indent increase". + static const IconData format_indent_increase = IconData(0xe2b5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">format_indent_increase</i> — material icon named "format indent increase" (sharp). + static const IconData format_indent_increase_sharp = IconData(0xe9b0, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">format_indent_increase</i> — material icon named "format indent increase" (round). + static const IconData format_indent_increase_rounded = IconData(0xf78f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">format_indent_increase</i> — material icon named "format indent increase" (outlined). + static const IconData format_indent_increase_outlined = IconData(0xf0a2, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">format_italic</i> — material icon named "format italic". + static const IconData format_italic = IconData(0xe2b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_italic</i> — material icon named "format italic" (sharp). + static const IconData format_italic_sharp = IconData(0xe9b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_italic</i> — material icon named "format italic" (round). + static const IconData format_italic_rounded = IconData(0xf790, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_italic</i> — material icon named "format italic" (outlined). + static const IconData format_italic_outlined = IconData(0xf0a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_line_spacing</i> — material icon named "format line spacing". + static const IconData format_line_spacing = IconData(0xe2b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_line_spacing</i> — material icon named "format line spacing" (sharp). + static const IconData format_line_spacing_sharp = IconData(0xe9b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_line_spacing</i> — material icon named "format line spacing" (round). + static const IconData format_line_spacing_rounded = IconData(0xf791, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_line_spacing</i> — material icon named "format line spacing" (outlined). + static const IconData format_line_spacing_outlined = IconData(0xf0a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_list_bulleted</i> — material icon named "format list bulleted". + static const IconData format_list_bulleted = IconData(0xe2b8, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">format_list_bulleted</i> — material icon named "format list bulleted" (sharp). + static const IconData format_list_bulleted_sharp = IconData(0xe9b3, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">format_list_bulleted</i> — material icon named "format list bulleted" (round). + static const IconData format_list_bulleted_rounded = IconData(0xf792, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">format_list_bulleted</i> — material icon named "format list bulleted" (outlined). + static const IconData format_list_bulleted_outlined = IconData(0xf0a5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">format_list_bulleted_add</i> — material icon named "format list bulleted add". + static const IconData format_list_bulleted_add = IconData(0xf0867, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_list_numbered</i> — material icon named "format list numbered". + static const IconData format_list_numbered = IconData(0xe2b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_list_numbered</i> — material icon named "format list numbered" (sharp). + static const IconData format_list_numbered_sharp = IconData(0xe9b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_list_numbered</i> — material icon named "format list numbered" (round). + static const IconData format_list_numbered_rounded = IconData(0xf793, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_list_numbered</i> — material icon named "format list numbered" (outlined). + static const IconData format_list_numbered_outlined = IconData(0xf0a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_list_numbered_rtl</i> — material icon named "format list numbered rtl". + static const IconData format_list_numbered_rtl = IconData(0xe2ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_list_numbered_rtl</i> — material icon named "format list numbered rtl" (sharp). + static const IconData format_list_numbered_rtl_sharp = IconData(0xe9b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_list_numbered_rtl</i> — material icon named "format list numbered rtl" (round). + static const IconData format_list_numbered_rtl_rounded = IconData(0xf794, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_list_numbered_rtl</i> — material icon named "format list numbered rtl" (outlined). + static const IconData format_list_numbered_rtl_outlined = IconData(0xf0a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_overline</i> — material icon named "format overline". + static const IconData format_overline = IconData(0xf050d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_overline</i> — material icon named "format overline" (sharp). + static const IconData format_overline_sharp = IconData(0xf0418, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_overline</i> — material icon named "format overline" (round). + static const IconData format_overline_rounded = IconData(0xf0325, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_overline</i> — material icon named "format overline" (outlined). + static const IconData format_overline_outlined = IconData(0xf0606, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_paint</i> — material icon named "format paint". + static const IconData format_paint = IconData(0xe2bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_paint</i> — material icon named "format paint" (sharp). + static const IconData format_paint_sharp = IconData(0xe9b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_paint</i> — material icon named "format paint" (round). + static const IconData format_paint_rounded = IconData(0xf795, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_paint</i> — material icon named "format paint" (outlined). + static const IconData format_paint_outlined = IconData(0xf0a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_quote</i> — material icon named "format quote". + static const IconData format_quote = IconData(0xe2bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_quote</i> — material icon named "format quote" (sharp). + static const IconData format_quote_sharp = IconData(0xe9b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_quote</i> — material icon named "format quote" (round). + static const IconData format_quote_rounded = IconData(0xf796, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_quote</i> — material icon named "format quote" (outlined). + static const IconData format_quote_outlined = IconData(0xf0a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_shapes</i> — material icon named "format shapes". + static const IconData format_shapes = IconData(0xe2bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_shapes</i> — material icon named "format shapes" (sharp). + static const IconData format_shapes_sharp = IconData(0xe9b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_shapes</i> — material icon named "format shapes" (round). + static const IconData format_shapes_rounded = IconData(0xf797, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_shapes</i> — material icon named "format shapes" (outlined). + static const IconData format_shapes_outlined = IconData(0xf0aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_size</i> — material icon named "format size". + static const IconData format_size = IconData(0xe2be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_size</i> — material icon named "format size" (sharp). + static const IconData format_size_sharp = IconData(0xe9b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_size</i> — material icon named "format size" (round). + static const IconData format_size_rounded = IconData(0xf798, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_size</i> — material icon named "format size" (outlined). + static const IconData format_size_outlined = IconData(0xf0ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_strikethrough</i> — material icon named "format strikethrough". + static const IconData format_strikethrough = IconData(0xe2bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_strikethrough</i> — material icon named "format strikethrough" (sharp). + static const IconData format_strikethrough_sharp = IconData(0xe9ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_strikethrough</i> — material icon named "format strikethrough" (round). + static const IconData format_strikethrough_rounded = IconData(0xf799, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_strikethrough</i> — material icon named "format strikethrough" (outlined). + static const IconData format_strikethrough_outlined = IconData(0xf0ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_textdirection_l_to_r</i> — material icon named "format textdirection l to r". + static const IconData format_textdirection_l_to_r = IconData(0xe2c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_textdirection_l_to_r</i> — material icon named "format textdirection l to r" (sharp). + static const IconData format_textdirection_l_to_r_sharp = IconData(0xe9bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_textdirection_l_to_r</i> — material icon named "format textdirection l to r" (round). + static const IconData format_textdirection_l_to_r_rounded = IconData(0xf79a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_textdirection_l_to_r</i> — material icon named "format textdirection l to r" (outlined). + static const IconData format_textdirection_l_to_r_outlined = IconData(0xf0ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_textdirection_r_to_l</i> — material icon named "format textdirection r to l". + static const IconData format_textdirection_r_to_l = IconData(0xe2c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_textdirection_r_to_l</i> — material icon named "format textdirection r to l" (sharp). + static const IconData format_textdirection_r_to_l_sharp = IconData(0xe9bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_textdirection_r_to_l</i> — material icon named "format textdirection r to l" (round). + static const IconData format_textdirection_r_to_l_rounded = IconData(0xf79b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_textdirection_r_to_l</i> — material icon named "format textdirection r to l" (outlined). + static const IconData format_textdirection_r_to_l_outlined = IconData(0xf0ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_underline</i> — material icon named "format underline". + static const IconData format_underline = IconData(0xe2c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_underline</i> — material icon named "format underline" (sharp). + static const IconData format_underline_sharp = IconData(0xe9bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_underline</i> — material icon named "format underline" (round). + static const IconData format_underline_rounded = IconData(0xf79c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_underline</i> — material icon named "format underline" (outlined). + static const IconData format_underline_outlined = IconData(0xf0af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">format_underlined</i> — material icon named "format underlined". + static const IconData format_underlined = IconData(0xe2c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">format_underlined</i> — material icon named "format underlined" (sharp). + static const IconData format_underlined_sharp = IconData(0xe9bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">format_underlined</i> — material icon named "format underlined" (round). + static const IconData format_underlined_rounded = IconData(0xf79c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">format_underlined</i> — material icon named "format underlined" (outlined). + static const IconData format_underlined_outlined = IconData(0xf0af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fort</i> — material icon named "fort". + static const IconData fort = IconData(0xf050e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fort</i> — material icon named "fort" (sharp). + static const IconData fort_sharp = IconData(0xf0419, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fort</i> — material icon named "fort" (round). + static const IconData fort_rounded = IconData(0xf0326, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fort</i> — material icon named "fort" (outlined). + static const IconData fort_outlined = IconData(0xf0607, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">forum</i> — material icon named "forum". + static const IconData forum = IconData(0xe2c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">forum</i> — material icon named "forum" (sharp). + static const IconData forum_sharp = IconData(0xe9be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">forum</i> — material icon named "forum" (round). + static const IconData forum_rounded = IconData(0xf79d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">forum</i> — material icon named "forum" (outlined). + static const IconData forum_outlined = IconData(0xf0b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">forward</i> — material icon named "forward". + static const IconData forward = IconData(0xe2c4, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">forward</i> — material icon named "forward" (sharp). + static const IconData forward_sharp = IconData(0xe9c2, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">forward</i> — material icon named "forward" (round). + static const IconData forward_rounded = IconData(0xf7a1, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">forward</i> — material icon named "forward" (outlined). + static const IconData forward_outlined = IconData(0xf0b4, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">forward_10</i> — material icon named "forward 10". + static const IconData forward_10 = IconData(0xe2c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">forward_10</i> — material icon named "forward 10" (sharp). + static const IconData forward_10_sharp = IconData(0xe9bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">forward_10</i> — material icon named "forward 10" (round). + static const IconData forward_10_rounded = IconData(0xf79e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">forward_10</i> — material icon named "forward 10" (outlined). + static const IconData forward_10_outlined = IconData(0xf0b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">forward_30</i> — material icon named "forward 30". + static const IconData forward_30 = IconData(0xe2c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">forward_30</i> — material icon named "forward 30" (sharp). + static const IconData forward_30_sharp = IconData(0xe9c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">forward_30</i> — material icon named "forward 30" (round). + static const IconData forward_30_rounded = IconData(0xf79f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">forward_30</i> — material icon named "forward 30" (outlined). + static const IconData forward_30_outlined = IconData(0xf0b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">forward_5</i> — material icon named "forward 5". + static const IconData forward_5 = IconData(0xe2c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">forward_5</i> — material icon named "forward 5" (sharp). + static const IconData forward_5_sharp = IconData(0xe9c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">forward_5</i> — material icon named "forward 5" (round). + static const IconData forward_5_rounded = IconData(0xf7a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">forward_5</i> — material icon named "forward 5" (outlined). + static const IconData forward_5_outlined = IconData(0xf0b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">forward_to_inbox</i> — material icon named "forward to inbox". + static const IconData forward_to_inbox = IconData(0xe2c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">forward_to_inbox</i> — material icon named "forward to inbox" (sharp). + static const IconData forward_to_inbox_sharp = IconData(0xe9c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">forward_to_inbox</i> — material icon named "forward to inbox" (round). + static const IconData forward_to_inbox_rounded = IconData(0xf7a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">forward_to_inbox</i> — material icon named "forward to inbox" (outlined). + static const IconData forward_to_inbox_outlined = IconData(0xf0b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">foundation</i> — material icon named "foundation". + static const IconData foundation = IconData(0xe2c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">foundation</i> — material icon named "foundation" (sharp). + static const IconData foundation_sharp = IconData(0xe9c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">foundation</i> — material icon named "foundation" (round). + static const IconData foundation_rounded = IconData(0xf7a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">foundation</i> — material icon named "foundation" (outlined). + static const IconData foundation_outlined = IconData(0xf0b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">free_breakfast</i> — material icon named "free breakfast". + static const IconData free_breakfast = IconData(0xe2ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">free_breakfast</i> — material icon named "free breakfast" (sharp). + static const IconData free_breakfast_sharp = IconData(0xe9c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">free_breakfast</i> — material icon named "free breakfast" (round). + static const IconData free_breakfast_rounded = IconData(0xf7a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">free_breakfast</i> — material icon named "free breakfast" (outlined). + static const IconData free_breakfast_outlined = IconData(0xf0b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">free_cancellation</i> — material icon named "free cancellation". + static const IconData free_cancellation = IconData(0xf050f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">free_cancellation</i> — material icon named "free cancellation" (sharp). + static const IconData free_cancellation_sharp = IconData(0xf041a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">free_cancellation</i> — material icon named "free cancellation" (round). + static const IconData free_cancellation_rounded = IconData(0xf0327, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">free_cancellation</i> — material icon named "free cancellation" (outlined). + static const IconData free_cancellation_outlined = IconData(0xf0608, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">front_hand</i> — material icon named "front hand". + static const IconData front_hand = IconData(0xf0510, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">front_hand</i> — material icon named "front hand" (sharp). + static const IconData front_hand_sharp = IconData(0xf041b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">front_hand</i> — material icon named "front hand" (round). + static const IconData front_hand_rounded = IconData(0xf0328, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">front_hand</i> — material icon named "front hand" (outlined). + static const IconData front_hand_outlined = IconData(0xf0609, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">front_loader</i> — material icon named "front loader". + static const IconData front_loader = IconData(0xf0868, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fullscreen</i> — material icon named "fullscreen". + static const IconData fullscreen = IconData(0xe2cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fullscreen</i> — material icon named "fullscreen" (sharp). + static const IconData fullscreen_sharp = IconData(0xe9c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fullscreen</i> — material icon named "fullscreen" (round). + static const IconData fullscreen_rounded = IconData(0xf7a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fullscreen</i> — material icon named "fullscreen" (outlined). + static const IconData fullscreen_outlined = IconData(0xf0b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">fullscreen_exit</i> — material icon named "fullscreen exit". + static const IconData fullscreen_exit = IconData(0xe2cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">fullscreen_exit</i> — material icon named "fullscreen exit" (sharp). + static const IconData fullscreen_exit_sharp = IconData(0xe9c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">fullscreen_exit</i> — material icon named "fullscreen exit" (round). + static const IconData fullscreen_exit_rounded = IconData(0xf7a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">fullscreen_exit</i> — material icon named "fullscreen exit" (outlined). + static const IconData fullscreen_exit_outlined = IconData(0xf0b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">functions</i> — material icon named "functions". + static const IconData functions = IconData(0xe2cd, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">functions</i> — material icon named "functions" (sharp). + static const IconData functions_sharp = IconData(0xe9c8, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">functions</i> — material icon named "functions" (round). + static const IconData functions_rounded = IconData(0xf7a7, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">functions</i> — material icon named "functions" (outlined). + static const IconData functions_outlined = IconData(0xf0ba, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">g_mobiledata</i> — material icon named "g mobiledata". + static const IconData g_mobiledata = IconData(0xe2ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">g_mobiledata</i> — material icon named "g mobiledata" (sharp). + static const IconData g_mobiledata_sharp = IconData(0xe9c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">g_mobiledata</i> — material icon named "g mobiledata" (round). + static const IconData g_mobiledata_rounded = IconData(0xf7a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">g_mobiledata</i> — material icon named "g mobiledata" (outlined). + static const IconData g_mobiledata_outlined = IconData(0xf0bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">g_translate</i> — material icon named "g translate". + static const IconData g_translate = IconData(0xe2cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">g_translate</i> — material icon named "g translate" (sharp). + static const IconData g_translate_sharp = IconData(0xe9ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">g_translate</i> — material icon named "g translate" (round). + static const IconData g_translate_rounded = IconData(0xf7a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">g_translate</i> — material icon named "g translate" (outlined). + static const IconData g_translate_outlined = IconData(0xf0bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gamepad</i> — material icon named "gamepad". + static const IconData gamepad = IconData(0xe2d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gamepad</i> — material icon named "gamepad" (sharp). + static const IconData gamepad_sharp = IconData(0xe9cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gamepad</i> — material icon named "gamepad" (round). + static const IconData gamepad_rounded = IconData(0xf7aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gamepad</i> — material icon named "gamepad" (outlined). + static const IconData gamepad_outlined = IconData(0xf0bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">games</i> — material icon named "games". + static const IconData games = IconData(0xe2d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">games</i> — material icon named "games" (sharp). + static const IconData games_sharp = IconData(0xe9cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">games</i> — material icon named "games" (round). + static const IconData games_rounded = IconData(0xf7ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">games</i> — material icon named "games" (outlined). + static const IconData games_outlined = IconData(0xf0be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">garage</i> — material icon named "garage". + static const IconData garage = IconData(0xe2d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">garage</i> — material icon named "garage" (sharp). + static const IconData garage_sharp = IconData(0xe9cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">garage</i> — material icon named "garage" (round). + static const IconData garage_rounded = IconData(0xf7ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">garage</i> — material icon named "garage" (outlined). + static const IconData garage_outlined = IconData(0xf0bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gas_meter</i> — material icon named "gas meter". + static const IconData gas_meter = IconData(0xf07a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gas_meter</i> — material icon named "gas meter" (sharp). + static const IconData gas_meter_sharp = IconData(0xf074c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gas_meter</i> — material icon named "gas meter" (round). + static const IconData gas_meter_rounded = IconData(0xf07fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gas_meter</i> — material icon named "gas meter" (outlined). + static const IconData gas_meter_outlined = IconData(0xf06f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gavel</i> — material icon named "gavel". + static const IconData gavel = IconData(0xe2d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gavel</i> — material icon named "gavel" (sharp). + static const IconData gavel_sharp = IconData(0xe9ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gavel</i> — material icon named "gavel" (round). + static const IconData gavel_rounded = IconData(0xf7ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gavel</i> — material icon named "gavel" (outlined). + static const IconData gavel_outlined = IconData(0xf0c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">generating_tokens</i> — material icon named "generating tokens". + static const IconData generating_tokens = IconData(0xf0511, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">generating_tokens</i> — material icon named "generating tokens" (sharp). + static const IconData generating_tokens_sharp = IconData(0xf041c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">generating_tokens</i> — material icon named "generating tokens" (round). + static const IconData generating_tokens_rounded = IconData(0xf0329, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">generating_tokens</i> — material icon named "generating tokens" (outlined). + static const IconData generating_tokens_outlined = IconData(0xf060a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gesture</i> — material icon named "gesture". + static const IconData gesture = IconData(0xe2d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gesture</i> — material icon named "gesture" (sharp). + static const IconData gesture_sharp = IconData(0xe9cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gesture</i> — material icon named "gesture" (round). + static const IconData gesture_rounded = IconData(0xf7ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gesture</i> — material icon named "gesture" (outlined). + static const IconData gesture_outlined = IconData(0xf0c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">get_app</i> — material icon named "get app". + static const IconData get_app = IconData(0xe2d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">get_app</i> — material icon named "get app" (sharp). + static const IconData get_app_sharp = IconData(0xe9d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">get_app</i> — material icon named "get app" (round). + static const IconData get_app_rounded = IconData(0xf7af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">get_app</i> — material icon named "get app" (outlined). + static const IconData get_app_outlined = IconData(0xf0c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gif</i> — material icon named "gif". + static const IconData gif = IconData(0xe2d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gif</i> — material icon named "gif" (sharp). + static const IconData gif_sharp = IconData(0xe9d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gif</i> — material icon named "gif" (round). + static const IconData gif_rounded = IconData(0xf7b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gif</i> — material icon named "gif" (outlined). + static const IconData gif_outlined = IconData(0xf0c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gif_box</i> — material icon named "gif box". + static const IconData gif_box = IconData(0xf0512, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gif_box</i> — material icon named "gif box" (sharp). + static const IconData gif_box_sharp = IconData(0xf041d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gif_box</i> — material icon named "gif box" (round). + static const IconData gif_box_rounded = IconData(0xf032a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gif_box</i> — material icon named "gif box" (outlined). + static const IconData gif_box_outlined = IconData(0xf060b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">girl</i> — material icon named "girl". + static const IconData girl = IconData(0xf0513, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">girl</i> — material icon named "girl" (sharp). + static const IconData girl_sharp = IconData(0xf041e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">girl</i> — material icon named "girl" (round). + static const IconData girl_rounded = IconData(0xf032b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">girl</i> — material icon named "girl" (outlined). + static const IconData girl_outlined = IconData(0xf060c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gite</i> — material icon named "gite". + static const IconData gite = IconData(0xe2d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gite</i> — material icon named "gite" (sharp). + static const IconData gite_sharp = IconData(0xe9d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gite</i> — material icon named "gite" (round). + static const IconData gite_rounded = IconData(0xf7b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gite</i> — material icon named "gite" (outlined). + static const IconData gite_outlined = IconData(0xf0c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">golf_course</i> — material icon named "golf course". + static const IconData golf_course = IconData(0xe2d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">golf_course</i> — material icon named "golf course" (sharp). + static const IconData golf_course_sharp = IconData(0xe9d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">golf_course</i> — material icon named "golf course" (round). + static const IconData golf_course_rounded = IconData(0xf7b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">golf_course</i> — material icon named "golf course" (outlined). + static const IconData golf_course_outlined = IconData(0xf0c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gpp_bad</i> — material icon named "gpp bad". + static const IconData gpp_bad = IconData(0xe2d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gpp_bad</i> — material icon named "gpp bad" (sharp). + static const IconData gpp_bad_sharp = IconData(0xe9d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gpp_bad</i> — material icon named "gpp bad" (round). + static const IconData gpp_bad_rounded = IconData(0xf7b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gpp_bad</i> — material icon named "gpp bad" (outlined). + static const IconData gpp_bad_outlined = IconData(0xf0c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gpp_good</i> — material icon named "gpp good". + static const IconData gpp_good = IconData(0xe2da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gpp_good</i> — material icon named "gpp good" (sharp). + static const IconData gpp_good_sharp = IconData(0xe9d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gpp_good</i> — material icon named "gpp good" (round). + static const IconData gpp_good_rounded = IconData(0xf7b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gpp_good</i> — material icon named "gpp good" (outlined). + static const IconData gpp_good_outlined = IconData(0xf0c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gpp_maybe</i> — material icon named "gpp maybe". + static const IconData gpp_maybe = IconData(0xe2db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gpp_maybe</i> — material icon named "gpp maybe" (sharp). + static const IconData gpp_maybe_sharp = IconData(0xe9d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gpp_maybe</i> — material icon named "gpp maybe" (round). + static const IconData gpp_maybe_rounded = IconData(0xf7b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gpp_maybe</i> — material icon named "gpp maybe" (outlined). + static const IconData gpp_maybe_outlined = IconData(0xf0c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gps_fixed</i> — material icon named "gps fixed". + static const IconData gps_fixed = IconData(0xe2dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gps_fixed</i> — material icon named "gps fixed" (sharp). + static const IconData gps_fixed_sharp = IconData(0xe9d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gps_fixed</i> — material icon named "gps fixed" (round). + static const IconData gps_fixed_rounded = IconData(0xf7b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gps_fixed</i> — material icon named "gps fixed" (outlined). + static const IconData gps_fixed_outlined = IconData(0xf0c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gps_not_fixed</i> — material icon named "gps not fixed". + static const IconData gps_not_fixed = IconData(0xe2dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gps_not_fixed</i> — material icon named "gps not fixed" (sharp). + static const IconData gps_not_fixed_sharp = IconData(0xe9d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gps_not_fixed</i> — material icon named "gps not fixed" (round). + static const IconData gps_not_fixed_rounded = IconData(0xf7b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gps_not_fixed</i> — material icon named "gps not fixed" (outlined). + static const IconData gps_not_fixed_outlined = IconData(0xf0ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gps_off</i> — material icon named "gps off". + static const IconData gps_off = IconData(0xe2de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gps_off</i> — material icon named "gps off" (sharp). + static const IconData gps_off_sharp = IconData(0xe9d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gps_off</i> — material icon named "gps off" (round). + static const IconData gps_off_rounded = IconData(0xf7b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gps_off</i> — material icon named "gps off" (outlined). + static const IconData gps_off_outlined = IconData(0xf0cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">grade</i> — material icon named "grade". + static const IconData grade = IconData(0xe2df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">grade</i> — material icon named "grade" (sharp). + static const IconData grade_sharp = IconData(0xe9da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">grade</i> — material icon named "grade" (round). + static const IconData grade_rounded = IconData(0xf7b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">grade</i> — material icon named "grade" (outlined). + static const IconData grade_outlined = IconData(0xf0cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">gradient</i> — material icon named "gradient". + static const IconData gradient = IconData(0xe2e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">gradient</i> — material icon named "gradient" (sharp). + static const IconData gradient_sharp = IconData(0xe9db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">gradient</i> — material icon named "gradient" (round). + static const IconData gradient_rounded = IconData(0xf7ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">gradient</i> — material icon named "gradient" (outlined). + static const IconData gradient_outlined = IconData(0xf0cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">grading</i> — material icon named "grading". + static const IconData grading = IconData(0xe2e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">grading</i> — material icon named "grading" (sharp). + static const IconData grading_sharp = IconData(0xe9dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">grading</i> — material icon named "grading" (round). + static const IconData grading_rounded = IconData(0xf7bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">grading</i> — material icon named "grading" (outlined). + static const IconData grading_outlined = IconData(0xf0ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">grain</i> — material icon named "grain". + static const IconData grain = IconData(0xe2e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">grain</i> — material icon named "grain" (sharp). + static const IconData grain_sharp = IconData(0xe9dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">grain</i> — material icon named "grain" (round). + static const IconData grain_rounded = IconData(0xf7bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">grain</i> — material icon named "grain" (outlined). + static const IconData grain_outlined = IconData(0xf0cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">graphic_eq</i> — material icon named "graphic eq". + static const IconData graphic_eq = IconData(0xe2e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">graphic_eq</i> — material icon named "graphic eq" (sharp). + static const IconData graphic_eq_sharp = IconData(0xe9de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">graphic_eq</i> — material icon named "graphic eq" (round). + static const IconData graphic_eq_rounded = IconData(0xf7bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">graphic_eq</i> — material icon named "graphic eq" (outlined). + static const IconData graphic_eq_outlined = IconData(0xf0d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">grass</i> — material icon named "grass". + static const IconData grass = IconData(0xe2e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">grass</i> — material icon named "grass" (sharp). + static const IconData grass_sharp = IconData(0xe9df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">grass</i> — material icon named "grass" (round). + static const IconData grass_rounded = IconData(0xf7be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">grass</i> — material icon named "grass" (outlined). + static const IconData grass_outlined = IconData(0xf0d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">grid_3x3</i> — material icon named "grid 3x3". + static const IconData grid_3x3 = IconData(0xe2e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">grid_3x3</i> — material icon named "grid 3x3" (sharp). + static const IconData grid_3x3_sharp = IconData(0xe9e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">grid_3x3</i> — material icon named "grid 3x3" (round). + static const IconData grid_3x3_rounded = IconData(0xf7bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">grid_3x3</i> — material icon named "grid 3x3" (outlined). + static const IconData grid_3x3_outlined = IconData(0xf0d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">grid_4x4</i> — material icon named "grid 4x4". + static const IconData grid_4x4 = IconData(0xe2e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">grid_4x4</i> — material icon named "grid 4x4" (sharp). + static const IconData grid_4x4_sharp = IconData(0xe9e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">grid_4x4</i> — material icon named "grid 4x4" (round). + static const IconData grid_4x4_rounded = IconData(0xf7c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">grid_4x4</i> — material icon named "grid 4x4" (outlined). + static const IconData grid_4x4_outlined = IconData(0xf0d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">grid_goldenratio</i> — material icon named "grid goldenratio". + static const IconData grid_goldenratio = IconData(0xe2e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">grid_goldenratio</i> — material icon named "grid goldenratio" (sharp). + static const IconData grid_goldenratio_sharp = IconData(0xe9e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">grid_goldenratio</i> — material icon named "grid goldenratio" (round). + static const IconData grid_goldenratio_rounded = IconData(0xf7c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">grid_goldenratio</i> — material icon named "grid goldenratio" (outlined). + static const IconData grid_goldenratio_outlined = IconData(0xf0d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">grid_off</i> — material icon named "grid off". + static const IconData grid_off = IconData(0xe2e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">grid_off</i> — material icon named "grid off" (sharp). + static const IconData grid_off_sharp = IconData(0xe9e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">grid_off</i> — material icon named "grid off" (round). + static const IconData grid_off_rounded = IconData(0xf7c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">grid_off</i> — material icon named "grid off" (outlined). + static const IconData grid_off_outlined = IconData(0xf0d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">grid_on</i> — material icon named "grid on". + static const IconData grid_on = IconData(0xe2e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">grid_on</i> — material icon named "grid on" (sharp). + static const IconData grid_on_sharp = IconData(0xe9e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">grid_on</i> — material icon named "grid on" (round). + static const IconData grid_on_rounded = IconData(0xf7c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">grid_on</i> — material icon named "grid on" (outlined). + static const IconData grid_on_outlined = IconData(0xf0d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">grid_view</i> — material icon named "grid view". + static const IconData grid_view = IconData(0xe2ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">grid_view</i> — material icon named "grid view" (sharp). + static const IconData grid_view_sharp = IconData(0xe9e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">grid_view</i> — material icon named "grid view" (round). + static const IconData grid_view_rounded = IconData(0xf7c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">grid_view</i> — material icon named "grid view" (outlined). + static const IconData grid_view_outlined = IconData(0xf0d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">group</i> — material icon named "group". + static const IconData group = IconData(0xe2eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">group</i> — material icon named "group" (sharp). + static const IconData group_sharp = IconData(0xe9e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">group</i> — material icon named "group" (round). + static const IconData group_rounded = IconData(0xf7c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">group</i> — material icon named "group" (outlined). + static const IconData group_outlined = IconData(0xf0d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">group_add</i> — material icon named "group add". + static const IconData group_add = IconData(0xe2ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">group_add</i> — material icon named "group add" (sharp). + static const IconData group_add_sharp = IconData(0xe9e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">group_add</i> — material icon named "group add" (round). + static const IconData group_add_rounded = IconData(0xf7c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">group_add</i> — material icon named "group add" (outlined). + static const IconData group_add_outlined = IconData(0xf0d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">group_off</i> — material icon named "group off". + static const IconData group_off = IconData(0xf0514, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">group_off</i> — material icon named "group off" (sharp). + static const IconData group_off_sharp = IconData(0xf041f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">group_off</i> — material icon named "group off" (round). + static const IconData group_off_rounded = IconData(0xf032c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">group_off</i> — material icon named "group off" (outlined). + static const IconData group_off_outlined = IconData(0xf060d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">group_remove</i> — material icon named "group remove". + static const IconData group_remove = IconData(0xf0515, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">group_remove</i> — material icon named "group remove" (sharp). + static const IconData group_remove_sharp = IconData(0xf0420, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">group_remove</i> — material icon named "group remove" (round). + static const IconData group_remove_rounded = IconData(0xf032d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">group_remove</i> — material icon named "group remove" (outlined). + static const IconData group_remove_outlined = IconData(0xf060e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">group_work</i> — material icon named "group work". + static const IconData group_work = IconData(0xe2ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">group_work</i> — material icon named "group work" (sharp). + static const IconData group_work_sharp = IconData(0xe9e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">group_work</i> — material icon named "group work" (round). + static const IconData group_work_rounded = IconData(0xf7c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">group_work</i> — material icon named "group work" (outlined). + static const IconData group_work_outlined = IconData(0xf0da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">groups</i> — material icon named "groups". + static const IconData groups = IconData(0xe2ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">groups</i> — material icon named "groups" (sharp). + static const IconData groups_sharp = IconData(0xe9e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">groups</i> — material icon named "groups" (round). + static const IconData groups_rounded = IconData(0xf7c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">groups</i> — material icon named "groups" (outlined). + static const IconData groups_outlined = IconData(0xf0db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">groups_2</i> — material icon named "groups 2". + static const IconData groups_2 = IconData(0xf0869, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">groups_2</i> — material icon named "groups 2" (sharp). + static const IconData groups_2_sharp = IconData(0xf0841, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">groups_2</i> — material icon named "groups 2" (round). + static const IconData groups_2_rounded = IconData(0xf088a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">groups_2</i> — material icon named "groups 2" (outlined). + static const IconData groups_2_outlined = IconData(0xf08a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">groups_3</i> — material icon named "groups 3". + static const IconData groups_3 = IconData(0xf086a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">groups_3</i> — material icon named "groups 3" (sharp). + static const IconData groups_3_sharp = IconData(0xf0842, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">groups_3</i> — material icon named "groups 3" (round). + static const IconData groups_3_rounded = IconData(0xf088b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">groups_3</i> — material icon named "groups 3" (outlined). + static const IconData groups_3_outlined = IconData(0xf08a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">h_mobiledata</i> — material icon named "h mobiledata". + static const IconData h_mobiledata = IconData(0xe2ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">h_mobiledata</i> — material icon named "h mobiledata" (sharp). + static const IconData h_mobiledata_sharp = IconData(0xe9ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">h_mobiledata</i> — material icon named "h mobiledata" (round). + static const IconData h_mobiledata_rounded = IconData(0xf7c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">h_mobiledata</i> — material icon named "h mobiledata" (outlined). + static const IconData h_mobiledata_outlined = IconData(0xf0dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">h_plus_mobiledata</i> — material icon named "h plus mobiledata". + static const IconData h_plus_mobiledata = IconData(0xe2f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">h_plus_mobiledata</i> — material icon named "h plus mobiledata" (sharp). + static const IconData h_plus_mobiledata_sharp = IconData(0xe9eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">h_plus_mobiledata</i> — material icon named "h plus mobiledata" (round). + static const IconData h_plus_mobiledata_rounded = IconData(0xf7ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">h_plus_mobiledata</i> — material icon named "h plus mobiledata" (outlined). + static const IconData h_plus_mobiledata_outlined = IconData(0xf0dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hail</i> — material icon named "hail". + static const IconData hail = IconData(0xe2f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hail</i> — material icon named "hail" (sharp). + static const IconData hail_sharp = IconData(0xe9ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hail</i> — material icon named "hail" (round). + static const IconData hail_rounded = IconData(0xf7cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hail</i> — material icon named "hail" (outlined). + static const IconData hail_outlined = IconData(0xf0de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">handshake</i> — material icon named "handshake". + static const IconData handshake = IconData(0xf06be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">handshake</i> — material icon named "handshake" (sharp). + static const IconData handshake_sharp = IconData(0xf06b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">handshake</i> — material icon named "handshake" (round). + static const IconData handshake_rounded = IconData(0xf06cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">handshake</i> — material icon named "handshake" (outlined). + static const IconData handshake_outlined = IconData(0xf06a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">handyman</i> — material icon named "handyman". + static const IconData handyman = IconData(0xe2f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">handyman</i> — material icon named "handyman" (sharp). + static const IconData handyman_sharp = IconData(0xe9ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">handyman</i> — material icon named "handyman" (round). + static const IconData handyman_rounded = IconData(0xf7cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">handyman</i> — material icon named "handyman" (outlined). + static const IconData handyman_outlined = IconData(0xf0df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hardware</i> — material icon named "hardware". + static const IconData hardware = IconData(0xe2f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hardware</i> — material icon named "hardware" (sharp). + static const IconData hardware_sharp = IconData(0xe9ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hardware</i> — material icon named "hardware" (round). + static const IconData hardware_rounded = IconData(0xf7cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hardware</i> — material icon named "hardware" (outlined). + static const IconData hardware_outlined = IconData(0xf0e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hd</i> — material icon named "hd". + static const IconData hd = IconData(0xe2f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hd</i> — material icon named "hd" (sharp). + static const IconData hd_sharp = IconData(0xe9ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hd</i> — material icon named "hd" (round). + static const IconData hd_rounded = IconData(0xf7ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hd</i> — material icon named "hd" (outlined). + static const IconData hd_outlined = IconData(0xf0e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hdr_auto</i> — material icon named "hdr auto". + static const IconData hdr_auto = IconData(0xe2f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hdr_auto</i> — material icon named "hdr auto" (sharp). + static const IconData hdr_auto_sharp = IconData(0xe9f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hdr_auto</i> — material icon named "hdr auto" (round). + static const IconData hdr_auto_rounded = IconData(0xf7cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hdr_auto</i> — material icon named "hdr auto" (outlined). + static const IconData hdr_auto_outlined = IconData(0xf0e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hdr_auto_select</i> — material icon named "hdr auto select". + static const IconData hdr_auto_select = IconData(0xe2f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hdr_auto_select</i> — material icon named "hdr auto select" (sharp). + static const IconData hdr_auto_select_sharp = IconData(0xe9f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hdr_auto_select</i> — material icon named "hdr auto select" (round). + static const IconData hdr_auto_select_rounded = IconData(0xf7d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hdr_auto_select</i> — material icon named "hdr auto select" (outlined). + static const IconData hdr_auto_select_outlined = IconData(0xf0e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hdr_enhanced_select</i> — material icon named "hdr enhanced select". + static const IconData hdr_enhanced_select = IconData(0xe2f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hdr_enhanced_select</i> — material icon named "hdr enhanced select" (sharp). + static const IconData hdr_enhanced_select_sharp = IconData(0xe9f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hdr_enhanced_select</i> — material icon named "hdr enhanced select" (round). + static const IconData hdr_enhanced_select_rounded = IconData(0xf7d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hdr_enhanced_select</i> — material icon named "hdr enhanced select" (outlined). + static const IconData hdr_enhanced_select_outlined = IconData(0xf0e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hdr_off</i> — material icon named "hdr off". + static const IconData hdr_off = IconData(0xe2f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hdr_off</i> — material icon named "hdr off" (sharp). + static const IconData hdr_off_sharp = IconData(0xe9f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hdr_off</i> — material icon named "hdr off" (round). + static const IconData hdr_off_rounded = IconData(0xf7d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hdr_off</i> — material icon named "hdr off" (outlined). + static const IconData hdr_off_outlined = IconData(0xf0e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hdr_off_select</i> — material icon named "hdr off select". + static const IconData hdr_off_select = IconData(0xe2f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hdr_off_select</i> — material icon named "hdr off select" (sharp). + static const IconData hdr_off_select_sharp = IconData(0xe9f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hdr_off_select</i> — material icon named "hdr off select" (round). + static const IconData hdr_off_select_rounded = IconData(0xf7d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hdr_off_select</i> — material icon named "hdr off select" (outlined). + static const IconData hdr_off_select_outlined = IconData(0xf0e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hdr_on</i> — material icon named "hdr on". + static const IconData hdr_on = IconData(0xe2fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hdr_on</i> — material icon named "hdr on" (sharp). + static const IconData hdr_on_sharp = IconData(0xe9f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hdr_on</i> — material icon named "hdr on" (round). + static const IconData hdr_on_rounded = IconData(0xf7d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hdr_on</i> — material icon named "hdr on" (outlined). + static const IconData hdr_on_outlined = IconData(0xf0e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hdr_on_select</i> — material icon named "hdr on select". + static const IconData hdr_on_select = IconData(0xe2fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hdr_on_select</i> — material icon named "hdr on select" (sharp). + static const IconData hdr_on_select_sharp = IconData(0xe9f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hdr_on_select</i> — material icon named "hdr on select" (round). + static const IconData hdr_on_select_rounded = IconData(0xf7d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hdr_on_select</i> — material icon named "hdr on select" (outlined). + static const IconData hdr_on_select_outlined = IconData(0xf0e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hdr_plus</i> — material icon named "hdr plus". + static const IconData hdr_plus = IconData(0xe2fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hdr_plus</i> — material icon named "hdr plus" (sharp). + static const IconData hdr_plus_sharp = IconData(0xe9f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hdr_plus</i> — material icon named "hdr plus" (round). + static const IconData hdr_plus_rounded = IconData(0xf7d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hdr_plus</i> — material icon named "hdr plus" (outlined). + static const IconData hdr_plus_outlined = IconData(0xf0e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hdr_strong</i> — material icon named "hdr strong". + static const IconData hdr_strong = IconData(0xe2fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hdr_strong</i> — material icon named "hdr strong" (sharp). + static const IconData hdr_strong_sharp = IconData(0xe9f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hdr_strong</i> — material icon named "hdr strong" (round). + static const IconData hdr_strong_rounded = IconData(0xf7d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hdr_strong</i> — material icon named "hdr strong" (outlined). + static const IconData hdr_strong_outlined = IconData(0xf0ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hdr_weak</i> — material icon named "hdr weak". + static const IconData hdr_weak = IconData(0xe2fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hdr_weak</i> — material icon named "hdr weak" (sharp). + static const IconData hdr_weak_sharp = IconData(0xe9f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hdr_weak</i> — material icon named "hdr weak" (round). + static const IconData hdr_weak_rounded = IconData(0xf7d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hdr_weak</i> — material icon named "hdr weak" (outlined). + static const IconData hdr_weak_outlined = IconData(0xf0eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">headphones</i> — material icon named "headphones". + static const IconData headphones = IconData(0xe2ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">headphones</i> — material icon named "headphones" (sharp). + static const IconData headphones_sharp = IconData(0xe9fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">headphones</i> — material icon named "headphones" (round). + static const IconData headphones_rounded = IconData(0xf7da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">headphones</i> — material icon named "headphones" (outlined). + static const IconData headphones_outlined = IconData(0xf0ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">headphones_battery</i> — material icon named "headphones battery". + static const IconData headphones_battery = IconData(0xe300, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">headphones_battery</i> — material icon named "headphones battery" (sharp). + static const IconData headphones_battery_sharp = IconData(0xe9fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">headphones_battery</i> — material icon named "headphones battery" (round). + static const IconData headphones_battery_rounded = IconData(0xf7d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">headphones_battery</i> — material icon named "headphones battery" (outlined). + static const IconData headphones_battery_outlined = IconData(0xf0ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">headset</i> — material icon named "headset". + static const IconData headset = IconData(0xe301, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">headset</i> — material icon named "headset" (sharp). + static const IconData headset_sharp = IconData(0xe9fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">headset</i> — material icon named "headset" (round). + static const IconData headset_rounded = IconData(0xf7dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">headset</i> — material icon named "headset" (outlined). + static const IconData headset_outlined = IconData(0xf0f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">headset_mic</i> — material icon named "headset mic". + static const IconData headset_mic = IconData(0xe302, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">headset_mic</i> — material icon named "headset mic" (sharp). + static const IconData headset_mic_sharp = IconData(0xe9fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">headset_mic</i> — material icon named "headset mic" (round). + static const IconData headset_mic_rounded = IconData(0xf7db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">headset_mic</i> — material icon named "headset mic" (outlined). + static const IconData headset_mic_outlined = IconData(0xf0ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">headset_off</i> — material icon named "headset off". + static const IconData headset_off = IconData(0xe303, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">headset_off</i> — material icon named "headset off" (sharp). + static const IconData headset_off_sharp = IconData(0xe9fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">headset_off</i> — material icon named "headset off" (round). + static const IconData headset_off_rounded = IconData(0xf7dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">headset_off</i> — material icon named "headset off" (outlined). + static const IconData headset_off_outlined = IconData(0xf0ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">healing</i> — material icon named "healing". + static const IconData healing = IconData(0xe304, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">healing</i> — material icon named "healing" (sharp). + static const IconData healing_sharp = IconData(0xe9ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">healing</i> — material icon named "healing" (round). + static const IconData healing_rounded = IconData(0xf7de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">healing</i> — material icon named "healing" (outlined). + static const IconData healing_outlined = IconData(0xf0f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">health_and_safety</i> — material icon named "health and safety". + static const IconData health_and_safety = IconData(0xe305, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">health_and_safety</i> — material icon named "health and safety" (sharp). + static const IconData health_and_safety_sharp = IconData(0xea00, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">health_and_safety</i> — material icon named "health and safety" (round). + static const IconData health_and_safety_rounded = IconData(0xf7df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">health_and_safety</i> — material icon named "health and safety" (outlined). + static const IconData health_and_safety_outlined = IconData(0xf0f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hearing</i> — material icon named "hearing". + static const IconData hearing = IconData(0xe306, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hearing</i> — material icon named "hearing" (sharp). + static const IconData hearing_sharp = IconData(0xea02, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hearing</i> — material icon named "hearing" (round). + static const IconData hearing_rounded = IconData(0xf7e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hearing</i> — material icon named "hearing" (outlined). + static const IconData hearing_outlined = IconData(0xf0f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hearing_disabled</i> — material icon named "hearing disabled". + static const IconData hearing_disabled = IconData(0xe307, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hearing_disabled</i> — material icon named "hearing disabled" (sharp). + static const IconData hearing_disabled_sharp = IconData(0xea01, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hearing_disabled</i> — material icon named "hearing disabled" (round). + static const IconData hearing_disabled_rounded = IconData(0xf7e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hearing_disabled</i> — material icon named "hearing disabled" (outlined). + static const IconData hearing_disabled_outlined = IconData(0xf0f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">heart_broken</i> — material icon named "heart broken". + static const IconData heart_broken = IconData(0xf0516, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">heart_broken</i> — material icon named "heart broken" (sharp). + static const IconData heart_broken_sharp = IconData(0xf0421, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">heart_broken</i> — material icon named "heart broken" (round). + static const IconData heart_broken_rounded = IconData(0xf032e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">heart_broken</i> — material icon named "heart broken" (outlined). + static const IconData heart_broken_outlined = IconData(0xf060f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">heat_pump</i> — material icon named "heat pump". + static const IconData heat_pump = IconData(0xf07a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">heat_pump</i> — material icon named "heat pump" (sharp). + static const IconData heat_pump_sharp = IconData(0xf074d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">heat_pump</i> — material icon named "heat pump" (round). + static const IconData heat_pump_rounded = IconData(0xf07fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">heat_pump</i> — material icon named "heat pump" (outlined). + static const IconData heat_pump_outlined = IconData(0xf06f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">height</i> — material icon named "height". + static const IconData height = IconData(0xe308, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">height</i> — material icon named "height" (sharp). + static const IconData height_sharp = IconData(0xea03, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">height</i> — material icon named "height" (round). + static const IconData height_rounded = IconData(0xf7e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">height</i> — material icon named "height" (outlined). + static const IconData height_outlined = IconData(0xf0f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">help</i> — material icon named "help". + static const IconData help = IconData(0xe309, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">help</i> — material icon named "help" (sharp). + static const IconData help_sharp = IconData(0xea06, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">help</i> — material icon named "help" (round). + static const IconData help_rounded = IconData(0xf7e5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">help</i> — material icon named "help" (outlined). + static const IconData help_outlined = IconData(0xf0f8, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">help_center</i> — material icon named "help center". + static const IconData help_center = IconData(0xe30a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">help_center</i> — material icon named "help center" (sharp). + static const IconData help_center_sharp = IconData(0xea04, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">help_center</i> — material icon named "help center" (round). + static const IconData help_center_rounded = IconData(0xf7e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">help_center</i> — material icon named "help center" (outlined). + static const IconData help_center_outlined = IconData(0xf0f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">help_outline</i> — material icon named "help outline". + static const IconData help_outline = IconData(0xe30b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">help_outline</i> — material icon named "help outline" (sharp). + static const IconData help_outline_sharp = IconData(0xea05, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">help_outline</i> — material icon named "help outline" (round). + static const IconData help_outline_rounded = IconData(0xf7e4, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">help_outline</i> — material icon named "help outline" (outlined). + static const IconData help_outline_outlined = IconData(0xf0f7, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">hevc</i> — material icon named "hevc". + static const IconData hevc = IconData(0xe30c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hevc</i> — material icon named "hevc" (sharp). + static const IconData hevc_sharp = IconData(0xea07, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hevc</i> — material icon named "hevc" (round). + static const IconData hevc_rounded = IconData(0xf7e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hevc</i> — material icon named "hevc" (outlined). + static const IconData hevc_outlined = IconData(0xf0f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hexagon</i> — material icon named "hexagon". + static const IconData hexagon = IconData(0xf0517, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hexagon</i> — material icon named "hexagon" (sharp). + static const IconData hexagon_sharp = IconData(0xf0422, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hexagon</i> — material icon named "hexagon" (round). + static const IconData hexagon_rounded = IconData(0xf032f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hexagon</i> — material icon named "hexagon" (outlined). + static const IconData hexagon_outlined = IconData(0xf0610, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hide_image</i> — material icon named "hide image". + static const IconData hide_image = IconData(0xe30d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hide_image</i> — material icon named "hide image" (sharp). + static const IconData hide_image_sharp = IconData(0xea08, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hide_image</i> — material icon named "hide image" (round). + static const IconData hide_image_rounded = IconData(0xf7e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hide_image</i> — material icon named "hide image" (outlined). + static const IconData hide_image_outlined = IconData(0xf0fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hide_source</i> — material icon named "hide source". + static const IconData hide_source = IconData(0xe30e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hide_source</i> — material icon named "hide source" (sharp). + static const IconData hide_source_sharp = IconData(0xea09, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hide_source</i> — material icon named "hide source" (round). + static const IconData hide_source_rounded = IconData(0xf7e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hide_source</i> — material icon named "hide source" (outlined). + static const IconData hide_source_outlined = IconData(0xf0fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">high_quality</i> — material icon named "high quality". + static const IconData high_quality = IconData(0xe30f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">high_quality</i> — material icon named "high quality" (sharp). + static const IconData high_quality_sharp = IconData(0xea0a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">high_quality</i> — material icon named "high quality" (round). + static const IconData high_quality_rounded = IconData(0xf7e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">high_quality</i> — material icon named "high quality" (outlined). + static const IconData high_quality_outlined = IconData(0xf0fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">highlight</i> — material icon named "highlight". + static const IconData highlight = IconData(0xe310, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">highlight</i> — material icon named "highlight" (sharp). + static const IconData highlight_sharp = IconData(0xea0d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">highlight</i> — material icon named "highlight" (round). + static const IconData highlight_rounded = IconData(0xf7ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">highlight</i> — material icon named "highlight" (outlined). + static const IconData highlight_outlined = IconData(0xf0ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">highlight_alt</i> — material icon named "highlight alt". + static const IconData highlight_alt = IconData(0xe311, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">highlight_alt</i> — material icon named "highlight alt" (sharp). + static const IconData highlight_alt_sharp = IconData(0xea0b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">highlight_alt</i> — material icon named "highlight alt" (round). + static const IconData highlight_alt_rounded = IconData(0xf7ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">highlight_alt</i> — material icon named "highlight alt" (outlined). + static const IconData highlight_alt_outlined = IconData(0xf0fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">highlight_off</i> — material icon named "highlight off". + static const IconData highlight_off = IconData(0xe312, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">highlight_off</i> — material icon named "highlight off" (sharp). + static const IconData highlight_off_sharp = IconData(0xea0c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">highlight_off</i> — material icon named "highlight off" (round). + static const IconData highlight_off_rounded = IconData(0xf7eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">highlight_off</i> — material icon named "highlight off" (outlined). + static const IconData highlight_off_outlined = IconData(0xf0fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">highlight_remove</i> — material icon named "highlight remove". + static const IconData highlight_remove = IconData(0xe312, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">highlight_remove</i> — material icon named "highlight remove" (sharp). + static const IconData highlight_remove_sharp = IconData(0xea0c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">highlight_remove</i> — material icon named "highlight remove" (round). + static const IconData highlight_remove_rounded = IconData(0xf7eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">highlight_remove</i> — material icon named "highlight remove" (outlined). + static const IconData highlight_remove_outlined = IconData(0xf0fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hiking</i> — material icon named "hiking". + static const IconData hiking = IconData(0xe313, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hiking</i> — material icon named "hiking" (sharp). + static const IconData hiking_sharp = IconData(0xea0e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hiking</i> — material icon named "hiking" (round). + static const IconData hiking_rounded = IconData(0xf7ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hiking</i> — material icon named "hiking" (outlined). + static const IconData hiking_outlined = IconData(0xf100, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">history</i> — material icon named "history". + static const IconData history = IconData(0xe314, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">history</i> — material icon named "history" (sharp). + static const IconData history_sharp = IconData(0xea10, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">history</i> — material icon named "history" (round). + static const IconData history_rounded = IconData(0xf7ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">history</i> — material icon named "history" (outlined). + static const IconData history_outlined = IconData(0xf102, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">history_edu</i> — material icon named "history edu". + static const IconData history_edu = IconData(0xe315, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">history_edu</i> — material icon named "history edu" (sharp). + static const IconData history_edu_sharp = IconData(0xea0f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">history_edu</i> — material icon named "history edu" (round). + static const IconData history_edu_rounded = IconData(0xf7ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">history_edu</i> — material icon named "history edu" (outlined). + static const IconData history_edu_outlined = IconData(0xf101, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">history_toggle_off</i> — material icon named "history toggle off". + static const IconData history_toggle_off = IconData(0xe316, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">history_toggle_off</i> — material icon named "history toggle off" (sharp). + static const IconData history_toggle_off_sharp = IconData(0xea11, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">history_toggle_off</i> — material icon named "history toggle off" (round). + static const IconData history_toggle_off_rounded = IconData(0xf7f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">history_toggle_off</i> — material icon named "history toggle off" (outlined). + static const IconData history_toggle_off_outlined = IconData(0xf103, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hive</i> — material icon named "hive". + static const IconData hive = IconData(0xf0518, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hive</i> — material icon named "hive" (sharp). + static const IconData hive_sharp = IconData(0xf0423, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hive</i> — material icon named "hive" (round). + static const IconData hive_rounded = IconData(0xf0330, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hive</i> — material icon named "hive" (outlined). + static const IconData hive_outlined = IconData(0xf0611, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hls</i> — material icon named "hls". + static const IconData hls = IconData(0xf0519, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hls</i> — material icon named "hls" (sharp). + static const IconData hls_sharp = IconData(0xf0425, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hls</i> — material icon named "hls" (round). + static const IconData hls_rounded = IconData(0xf0332, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hls</i> — material icon named "hls" (outlined). + static const IconData hls_outlined = IconData(0xf0613, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hls_off</i> — material icon named "hls off". + static const IconData hls_off = IconData(0xf051a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hls_off</i> — material icon named "hls off" (sharp). + static const IconData hls_off_sharp = IconData(0xf0424, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hls_off</i> — material icon named "hls off" (round). + static const IconData hls_off_rounded = IconData(0xf0331, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hls_off</i> — material icon named "hls off" (outlined). + static const IconData hls_off_outlined = IconData(0xf0612, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">holiday_village</i> — material icon named "holiday village". + static const IconData holiday_village = IconData(0xe317, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">holiday_village</i> — material icon named "holiday village" (sharp). + static const IconData holiday_village_sharp = IconData(0xea12, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">holiday_village</i> — material icon named "holiday village" (round). + static const IconData holiday_village_rounded = IconData(0xf7f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">holiday_village</i> — material icon named "holiday village" (outlined). + static const IconData holiday_village_outlined = IconData(0xf104, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">home</i> — material icon named "home". + static const IconData home = IconData(0xe318, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">home</i> — material icon named "home" (sharp). + static const IconData home_sharp = IconData(0xea16, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">home</i> — material icon named "home" (round). + static const IconData home_rounded = IconData(0xf7f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">home</i> — material icon named "home" (outlined). + static const IconData home_outlined = IconData(0xf107, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">home_filled</i> — material icon named "home filled". + static const IconData home_filled = IconData(0xe319, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">home_max</i> — material icon named "home max". + static const IconData home_max = IconData(0xe31a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">home_max</i> — material icon named "home max" (sharp). + static const IconData home_max_sharp = IconData(0xea13, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">home_max</i> — material icon named "home max" (round). + static const IconData home_max_rounded = IconData(0xf7f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">home_max</i> — material icon named "home max" (outlined). + static const IconData home_max_outlined = IconData(0xf105, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">home_mini</i> — material icon named "home mini". + static const IconData home_mini = IconData(0xe31b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">home_mini</i> — material icon named "home mini" (sharp). + static const IconData home_mini_sharp = IconData(0xea14, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">home_mini</i> — material icon named "home mini" (round). + static const IconData home_mini_rounded = IconData(0xf7f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">home_mini</i> — material icon named "home mini" (outlined). + static const IconData home_mini_outlined = IconData(0xf106, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">home_repair_service</i> — material icon named "home repair service". + static const IconData home_repair_service = IconData(0xe31c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">home_repair_service</i> — material icon named "home repair service" (sharp). + static const IconData home_repair_service_sharp = IconData(0xea15, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">home_repair_service</i> — material icon named "home repair service" (round). + static const IconData home_repair_service_rounded = IconData(0xf7f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">home_repair_service</i> — material icon named "home repair service" (outlined). + static const IconData home_repair_service_outlined = IconData(0xf108, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">home_work</i> — material icon named "home work". + static const IconData home_work = IconData(0xe31d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">home_work</i> — material icon named "home work" (sharp). + static const IconData home_work_sharp = IconData(0xea17, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">home_work</i> — material icon named "home work" (round). + static const IconData home_work_rounded = IconData(0xf7f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">home_work</i> — material icon named "home work" (outlined). + static const IconData home_work_outlined = IconData(0xf109, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">horizontal_distribute</i> — material icon named "horizontal distribute". + static const IconData horizontal_distribute = IconData(0xe31e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">horizontal_distribute</i> — material icon named "horizontal distribute" (sharp). + static const IconData horizontal_distribute_sharp = IconData(0xea18, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">horizontal_distribute</i> — material icon named "horizontal distribute" (round). + static const IconData horizontal_distribute_rounded = IconData(0xf7f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">horizontal_distribute</i> — material icon named "horizontal distribute" (outlined). + static const IconData horizontal_distribute_outlined = IconData(0xf10a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">horizontal_rule</i> — material icon named "horizontal rule". + static const IconData horizontal_rule = IconData(0xe31f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">horizontal_rule</i> — material icon named "horizontal rule" (sharp). + static const IconData horizontal_rule_sharp = IconData(0xea19, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">horizontal_rule</i> — material icon named "horizontal rule" (round). + static const IconData horizontal_rule_rounded = IconData(0xf7f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">horizontal_rule</i> — material icon named "horizontal rule" (outlined). + static const IconData horizontal_rule_outlined = IconData(0xf10b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">horizontal_split</i> — material icon named "horizontal split". + static const IconData horizontal_split = IconData(0xe320, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">horizontal_split</i> — material icon named "horizontal split" (sharp). + static const IconData horizontal_split_sharp = IconData(0xea1a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">horizontal_split</i> — material icon named "horizontal split" (round). + static const IconData horizontal_split_rounded = IconData(0xf7f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">horizontal_split</i> — material icon named "horizontal split" (outlined). + static const IconData horizontal_split_outlined = IconData(0xf10c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hot_tub</i> — material icon named "hot tub". + static const IconData hot_tub = IconData(0xe321, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hot_tub</i> — material icon named "hot tub" (sharp). + static const IconData hot_tub_sharp = IconData(0xea1b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hot_tub</i> — material icon named "hot tub" (round). + static const IconData hot_tub_rounded = IconData(0xf7fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hot_tub</i> — material icon named "hot tub" (outlined). + static const IconData hot_tub_outlined = IconData(0xf10d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hotel</i> — material icon named "hotel". + static const IconData hotel = IconData(0xe322, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hotel</i> — material icon named "hotel" (sharp). + static const IconData hotel_sharp = IconData(0xea1c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hotel</i> — material icon named "hotel" (round). + static const IconData hotel_rounded = IconData(0xf7fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hotel</i> — material icon named "hotel" (outlined). + static const IconData hotel_outlined = IconData(0xf10e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hotel_class</i> — material icon named "hotel class". + static const IconData hotel_class = IconData(0xf051b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hotel_class</i> — material icon named "hotel class" (sharp). + static const IconData hotel_class_sharp = IconData(0xf0426, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hotel_class</i> — material icon named "hotel class" (round). + static const IconData hotel_class_rounded = IconData(0xf0333, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hotel_class</i> — material icon named "hotel class" (outlined). + static const IconData hotel_class_outlined = IconData(0xf0614, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hourglass_bottom</i> — material icon named "hourglass bottom". + static const IconData hourglass_bottom = IconData(0xe323, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hourglass_bottom</i> — material icon named "hourglass bottom" (sharp). + static const IconData hourglass_bottom_sharp = IconData(0xea1d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hourglass_bottom</i> — material icon named "hourglass bottom" (round). + static const IconData hourglass_bottom_rounded = IconData(0xf7fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hourglass_bottom</i> — material icon named "hourglass bottom" (outlined). + static const IconData hourglass_bottom_outlined = IconData(0xf10f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hourglass_disabled</i> — material icon named "hourglass disabled". + static const IconData hourglass_disabled = IconData(0xe324, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hourglass_disabled</i> — material icon named "hourglass disabled" (sharp). + static const IconData hourglass_disabled_sharp = IconData(0xea1e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hourglass_disabled</i> — material icon named "hourglass disabled" (round). + static const IconData hourglass_disabled_rounded = IconData(0xf7fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hourglass_disabled</i> — material icon named "hourglass disabled" (outlined). + static const IconData hourglass_disabled_outlined = IconData(0xf110, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hourglass_empty</i> — material icon named "hourglass empty". + static const IconData hourglass_empty = IconData(0xe325, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hourglass_empty</i> — material icon named "hourglass empty" (sharp). + static const IconData hourglass_empty_sharp = IconData(0xea1f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hourglass_empty</i> — material icon named "hourglass empty" (round). + static const IconData hourglass_empty_rounded = IconData(0xf7fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hourglass_empty</i> — material icon named "hourglass empty" (outlined). + static const IconData hourglass_empty_outlined = IconData(0xf111, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hourglass_full</i> — material icon named "hourglass full". + static const IconData hourglass_full = IconData(0xe326, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hourglass_full</i> — material icon named "hourglass full" (sharp). + static const IconData hourglass_full_sharp = IconData(0xea20, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hourglass_full</i> — material icon named "hourglass full" (round). + static const IconData hourglass_full_rounded = IconData(0xf7ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hourglass_full</i> — material icon named "hourglass full" (outlined). + static const IconData hourglass_full_outlined = IconData(0xf112, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hourglass_top</i> — material icon named "hourglass top". + static const IconData hourglass_top = IconData(0xe327, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hourglass_top</i> — material icon named "hourglass top" (sharp). + static const IconData hourglass_top_sharp = IconData(0xea21, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hourglass_top</i> — material icon named "hourglass top" (round). + static const IconData hourglass_top_rounded = IconData(0xf800, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hourglass_top</i> — material icon named "hourglass top" (outlined). + static const IconData hourglass_top_outlined = IconData(0xf113, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">house</i> — material icon named "house". + static const IconData house = IconData(0xe328, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">house</i> — material icon named "house" (sharp). + static const IconData house_sharp = IconData(0xea22, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">house</i> — material icon named "house" (round). + static const IconData house_rounded = IconData(0xf801, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">house</i> — material icon named "house" (outlined). + static const IconData house_outlined = IconData(0xf114, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">house_siding</i> — material icon named "house siding". + static const IconData house_siding = IconData(0xe329, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">house_siding</i> — material icon named "house siding" (sharp). + static const IconData house_siding_sharp = IconData(0xea23, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">house_siding</i> — material icon named "house siding" (round). + static const IconData house_siding_rounded = IconData(0xf802, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">house_siding</i> — material icon named "house siding" (outlined). + static const IconData house_siding_outlined = IconData(0xf115, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">houseboat</i> — material icon named "houseboat". + static const IconData houseboat = IconData(0xe32a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">houseboat</i> — material icon named "houseboat" (sharp). + static const IconData houseboat_sharp = IconData(0xea24, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">houseboat</i> — material icon named "houseboat" (round). + static const IconData houseboat_rounded = IconData(0xf803, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">houseboat</i> — material icon named "houseboat" (outlined). + static const IconData houseboat_outlined = IconData(0xf116, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">how_to_reg</i> — material icon named "how to reg". + static const IconData how_to_reg = IconData(0xe32b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">how_to_reg</i> — material icon named "how to reg" (sharp). + static const IconData how_to_reg_sharp = IconData(0xea25, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">how_to_reg</i> — material icon named "how to reg" (round). + static const IconData how_to_reg_rounded = IconData(0xf804, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">how_to_reg</i> — material icon named "how to reg" (outlined). + static const IconData how_to_reg_outlined = IconData(0xf117, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">how_to_vote</i> — material icon named "how to vote". + static const IconData how_to_vote = IconData(0xe32c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">how_to_vote</i> — material icon named "how to vote" (sharp). + static const IconData how_to_vote_sharp = IconData(0xea26, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">how_to_vote</i> — material icon named "how to vote" (round). + static const IconData how_to_vote_rounded = IconData(0xf805, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">how_to_vote</i> — material icon named "how to vote" (outlined). + static const IconData how_to_vote_outlined = IconData(0xf118, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">html</i> — material icon named "html". + static const IconData html = IconData(0xf051c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">html</i> — material icon named "html" (sharp). + static const IconData html_sharp = IconData(0xf0427, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">html</i> — material icon named "html" (round). + static const IconData html_rounded = IconData(0xf0334, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">html</i> — material icon named "html" (outlined). + static const IconData html_outlined = IconData(0xf0615, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">http</i> — material icon named "http". + static const IconData http = IconData(0xe32d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">http</i> — material icon named "http" (sharp). + static const IconData http_sharp = IconData(0xea27, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">http</i> — material icon named "http" (round). + static const IconData http_rounded = IconData(0xf806, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">http</i> — material icon named "http" (outlined). + static const IconData http_outlined = IconData(0xf119, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">https</i> — material icon named "https". + static const IconData https = IconData(0xe32e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">https</i> — material icon named "https" (sharp). + static const IconData https_sharp = IconData(0xea28, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">https</i> — material icon named "https" (round). + static const IconData https_rounded = IconData(0xf807, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">https</i> — material icon named "https" (outlined). + static const IconData https_outlined = IconData(0xf11a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hub</i> — material icon named "hub". + static const IconData hub = IconData(0xf051d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hub</i> — material icon named "hub" (sharp). + static const IconData hub_sharp = IconData(0xf0428, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hub</i> — material icon named "hub" (round). + static const IconData hub_rounded = IconData(0xf0335, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hub</i> — material icon named "hub" (outlined). + static const IconData hub_outlined = IconData(0xf0616, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">hvac</i> — material icon named "hvac". + static const IconData hvac = IconData(0xe32f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">hvac</i> — material icon named "hvac" (sharp). + static const IconData hvac_sharp = IconData(0xea29, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">hvac</i> — material icon named "hvac" (round). + static const IconData hvac_rounded = IconData(0xf808, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">hvac</i> — material icon named "hvac" (outlined). + static const IconData hvac_outlined = IconData(0xf11b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ice_skating</i> — material icon named "ice skating". + static const IconData ice_skating = IconData(0xe330, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ice_skating</i> — material icon named "ice skating" (sharp). + static const IconData ice_skating_sharp = IconData(0xea2a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ice_skating</i> — material icon named "ice skating" (round). + static const IconData ice_skating_rounded = IconData(0xf809, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ice_skating</i> — material icon named "ice skating" (outlined). + static const IconData ice_skating_outlined = IconData(0xf11c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">icecream</i> — material icon named "icecream". + static const IconData icecream = IconData(0xe331, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">icecream</i> — material icon named "icecream" (sharp). + static const IconData icecream_sharp = IconData(0xea2b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">icecream</i> — material icon named "icecream" (round). + static const IconData icecream_rounded = IconData(0xf80a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">icecream</i> — material icon named "icecream" (outlined). + static const IconData icecream_outlined = IconData(0xf11d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">image</i> — material icon named "image". + static const IconData image = IconData(0xe332, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">image</i> — material icon named "image" (sharp). + static const IconData image_sharp = IconData(0xea2f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">image</i> — material icon named "image" (round). + static const IconData image_rounded = IconData(0xf80d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">image</i> — material icon named "image" (outlined). + static const IconData image_outlined = IconData(0xf120, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">image_aspect_ratio</i> — material icon named "image aspect ratio". + static const IconData image_aspect_ratio = IconData(0xe333, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">image_aspect_ratio</i> — material icon named "image aspect ratio" (sharp). + static const IconData image_aspect_ratio_sharp = IconData(0xea2c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">image_aspect_ratio</i> — material icon named "image aspect ratio" (round). + static const IconData image_aspect_ratio_rounded = IconData(0xf80b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">image_aspect_ratio</i> — material icon named "image aspect ratio" (outlined). + static const IconData image_aspect_ratio_outlined = IconData(0xf11e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">image_not_supported</i> — material icon named "image not supported". + static const IconData image_not_supported = IconData(0xe334, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">image_not_supported</i> — material icon named "image not supported" (sharp). + static const IconData image_not_supported_sharp = IconData(0xea2d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">image_not_supported</i> — material icon named "image not supported" (round). + static const IconData image_not_supported_rounded = IconData(0xf80c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">image_not_supported</i> — material icon named "image not supported" (outlined). + static const IconData image_not_supported_outlined = IconData(0xf11f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">image_search</i> — material icon named "image search". + static const IconData image_search = IconData(0xe335, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">image_search</i> — material icon named "image search" (sharp). + static const IconData image_search_sharp = IconData(0xea2e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">image_search</i> — material icon named "image search" (round). + static const IconData image_search_rounded = IconData(0xf80e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">image_search</i> — material icon named "image search" (outlined). + static const IconData image_search_outlined = IconData(0xf121, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">imagesearch_roller</i> — material icon named "imagesearch roller". + static const IconData imagesearch_roller = IconData(0xe336, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">imagesearch_roller</i> — material icon named "imagesearch roller" (sharp). + static const IconData imagesearch_roller_sharp = IconData(0xea30, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">imagesearch_roller</i> — material icon named "imagesearch roller" (round). + static const IconData imagesearch_roller_rounded = IconData(0xf80f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">imagesearch_roller</i> — material icon named "imagesearch roller" (outlined). + static const IconData imagesearch_roller_outlined = IconData(0xf122, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">import_contacts</i> — material icon named "import contacts". + static const IconData import_contacts = IconData(0xe337, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">import_contacts</i> — material icon named "import contacts" (sharp). + static const IconData import_contacts_sharp = IconData(0xea31, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">import_contacts</i> — material icon named "import contacts" (round). + static const IconData import_contacts_rounded = IconData(0xf810, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">import_contacts</i> — material icon named "import contacts" (outlined). + static const IconData import_contacts_outlined = IconData(0xf123, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">import_export</i> — material icon named "import export". + static const IconData import_export = IconData(0xe338, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">import_export</i> — material icon named "import export" (sharp). + static const IconData import_export_sharp = IconData(0xea32, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">import_export</i> — material icon named "import export" (round). + static const IconData import_export_rounded = IconData(0xf811, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">import_export</i> — material icon named "import export" (outlined). + static const IconData import_export_outlined = IconData(0xf124, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">important_devices</i> — material icon named "important devices". + static const IconData important_devices = IconData(0xe339, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">important_devices</i> — material icon named "important devices" (sharp). + static const IconData important_devices_sharp = IconData(0xea33, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">important_devices</i> — material icon named "important devices" (round). + static const IconData important_devices_rounded = IconData(0xf812, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">important_devices</i> — material icon named "important devices" (outlined). + static const IconData important_devices_outlined = IconData(0xf125, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">inbox</i> — material icon named "inbox". + static const IconData inbox = IconData(0xe33a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">inbox</i> — material icon named "inbox" (sharp). + static const IconData inbox_sharp = IconData(0xea34, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">inbox</i> — material icon named "inbox" (round). + static const IconData inbox_rounded = IconData(0xf813, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">inbox</i> — material icon named "inbox" (outlined). + static const IconData inbox_outlined = IconData(0xf126, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">incomplete_circle</i> — material icon named "incomplete circle". + static const IconData incomplete_circle = IconData(0xf051e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">incomplete_circle</i> — material icon named "incomplete circle" (sharp). + static const IconData incomplete_circle_sharp = IconData(0xf0429, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">incomplete_circle</i> — material icon named "incomplete circle" (round). + static const IconData incomplete_circle_rounded = IconData(0xf0336, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">incomplete_circle</i> — material icon named "incomplete circle" (outlined). + static const IconData incomplete_circle_outlined = IconData(0xf0617, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">indeterminate_check_box</i> — material icon named "indeterminate check box". + static const IconData indeterminate_check_box = IconData(0xe33b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">indeterminate_check_box</i> — material icon named "indeterminate check box" (sharp). + static const IconData indeterminate_check_box_sharp = IconData(0xea35, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">indeterminate_check_box</i> — material icon named "indeterminate check box" (round). + static const IconData indeterminate_check_box_rounded = IconData(0xf814, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">indeterminate_check_box</i> — material icon named "indeterminate check box" (outlined). + static const IconData indeterminate_check_box_outlined = IconData(0xf127, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">info</i> — material icon named "info". + static const IconData info = IconData(0xe33c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">info</i> — material icon named "info" (sharp). + static const IconData info_sharp = IconData(0xea37, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">info</i> — material icon named "info" (round). + static const IconData info_rounded = IconData(0xf816, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">info</i> — material icon named "info" (outlined). + static const IconData info_outlined = IconData(0xf128, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">info_outline</i> — material icon named "info outline". + static const IconData info_outline = IconData(0xe33d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">info_outline</i> — material icon named "info outline" (sharp). + static const IconData info_outline_sharp = IconData(0xea36, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">info_outline</i> — material icon named "info outline" (round). + static const IconData info_outline_rounded = IconData(0xf815, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">input</i> — material icon named "input". + static const IconData input = IconData(0xe33e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">input</i> — material icon named "input" (sharp). + static const IconData input_sharp = IconData(0xea38, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">input</i> — material icon named "input" (round). + static const IconData input_rounded = IconData(0xf817, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">input</i> — material icon named "input" (outlined). + static const IconData input_outlined = IconData(0xf129, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">insert_chart</i> — material icon named "insert chart". + static const IconData insert_chart = IconData(0xe33f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">insert_chart</i> — material icon named "insert chart" (sharp). + static const IconData insert_chart_sharp = IconData(0xea3a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">insert_chart</i> — material icon named "insert chart" (round). + static const IconData insert_chart_rounded = IconData(0xf819, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">insert_chart</i> — material icon named "insert chart". + static const IconData insert_chart_outlined = IconData(0xf12a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">insert_chart_outlined</i> — material icon named "insert chart outlined" (sharp). + static const IconData insert_chart_outlined_sharp = IconData(0xea39, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">insert_chart_outlined</i> — material icon named "insert chart outlined" (round). + static const IconData insert_chart_outlined_rounded = IconData(0xf818, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">insert_chart_outlined</i> — material icon named "insert chart outlined" (outlined). + static const IconData insert_chart_outlined_outlined = IconData(0xf12b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">insert_comment</i> — material icon named "insert comment". + static const IconData insert_comment = IconData(0xe341, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">insert_comment</i> — material icon named "insert comment" (sharp). + static const IconData insert_comment_sharp = IconData(0xea3b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">insert_comment</i> — material icon named "insert comment" (round). + static const IconData insert_comment_rounded = IconData(0xf81a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">insert_comment</i> — material icon named "insert comment" (outlined). + static const IconData insert_comment_outlined = IconData(0xf12c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">insert_drive_file</i> — material icon named "insert drive file". + static const IconData insert_drive_file = IconData(0xe342, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">insert_drive_file</i> — material icon named "insert drive file" (sharp). + static const IconData insert_drive_file_sharp = IconData(0xea3c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">insert_drive_file</i> — material icon named "insert drive file" (round). + static const IconData insert_drive_file_rounded = IconData(0xf81b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">insert_drive_file</i> — material icon named "insert drive file" (outlined). + static const IconData insert_drive_file_outlined = IconData(0xf12d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">insert_emoticon</i> — material icon named "insert emoticon". + static const IconData insert_emoticon = IconData(0xe343, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">insert_emoticon</i> — material icon named "insert emoticon" (sharp). + static const IconData insert_emoticon_sharp = IconData(0xea3d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">insert_emoticon</i> — material icon named "insert emoticon" (round). + static const IconData insert_emoticon_rounded = IconData(0xf81c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">insert_emoticon</i> — material icon named "insert emoticon" (outlined). + static const IconData insert_emoticon_outlined = IconData(0xf12e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">insert_invitation</i> — material icon named "insert invitation". + static const IconData insert_invitation = IconData(0xe344, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">insert_invitation</i> — material icon named "insert invitation" (sharp). + static const IconData insert_invitation_sharp = IconData(0xea3e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">insert_invitation</i> — material icon named "insert invitation" (round). + static const IconData insert_invitation_rounded = IconData(0xf81d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">insert_invitation</i> — material icon named "insert invitation" (outlined). + static const IconData insert_invitation_outlined = IconData(0xf12f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">insert_link</i> — material icon named "insert link". + static const IconData insert_link = IconData(0xe345, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">insert_link</i> — material icon named "insert link" (sharp). + static const IconData insert_link_sharp = IconData(0xea3f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">insert_link</i> — material icon named "insert link" (round). + static const IconData insert_link_rounded = IconData(0xf81e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">insert_link</i> — material icon named "insert link" (outlined). + static const IconData insert_link_outlined = IconData(0xf130, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">insert_page_break</i> — material icon named "insert page break". + static const IconData insert_page_break = IconData(0xf0520, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">insert_page_break</i> — material icon named "insert page break" (sharp). + static const IconData insert_page_break_sharp = IconData(0xf042a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">insert_page_break</i> — material icon named "insert page break" (round). + static const IconData insert_page_break_rounded = IconData(0xf0337, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">insert_page_break</i> — material icon named "insert page break" (outlined). + static const IconData insert_page_break_outlined = IconData(0xf0618, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">insert_photo</i> — material icon named "insert photo". + static const IconData insert_photo = IconData(0xe346, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">insert_photo</i> — material icon named "insert photo" (sharp). + static const IconData insert_photo_sharp = IconData(0xea40, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">insert_photo</i> — material icon named "insert photo" (round). + static const IconData insert_photo_rounded = IconData(0xf81f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">insert_photo</i> — material icon named "insert photo" (outlined). + static const IconData insert_photo_outlined = IconData(0xf131, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">insights</i> — material icon named "insights". + static const IconData insights = IconData(0xe347, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">insights</i> — material icon named "insights" (sharp). + static const IconData insights_sharp = IconData(0xea41, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">insights</i> — material icon named "insights" (round). + static const IconData insights_rounded = IconData(0xf820, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">insights</i> — material icon named "insights" (outlined). + static const IconData insights_outlined = IconData(0xf132, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">install_desktop</i> — material icon named "install desktop". + static const IconData install_desktop = IconData(0xf0521, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">install_desktop</i> — material icon named "install desktop" (sharp). + static const IconData install_desktop_sharp = IconData(0xf042b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">install_desktop</i> — material icon named "install desktop" (round). + static const IconData install_desktop_rounded = IconData(0xf0338, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">install_desktop</i> — material icon named "install desktop" (outlined). + static const IconData install_desktop_outlined = IconData(0xf0619, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">install_mobile</i> — material icon named "install mobile". + static const IconData install_mobile = IconData(0xf0522, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">install_mobile</i> — material icon named "install mobile" (sharp). + static const IconData install_mobile_sharp = IconData(0xf042c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">install_mobile</i> — material icon named "install mobile" (round). + static const IconData install_mobile_rounded = IconData(0xf0339, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">install_mobile</i> — material icon named "install mobile" (outlined). + static const IconData install_mobile_outlined = IconData(0xf061a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">integration_instructions</i> — material icon named "integration instructions". + static const IconData integration_instructions = IconData(0xe348, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">integration_instructions</i> — material icon named "integration instructions" (sharp). + static const IconData integration_instructions_sharp = IconData(0xea42, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">integration_instructions</i> — material icon named "integration instructions" (round). + static const IconData integration_instructions_rounded = IconData(0xf821, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">integration_instructions</i> — material icon named "integration instructions" (outlined). + static const IconData integration_instructions_outlined = IconData(0xf133, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">interests</i> — material icon named "interests". + static const IconData interests = IconData(0xf0523, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">interests</i> — material icon named "interests" (sharp). + static const IconData interests_sharp = IconData(0xf042d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">interests</i> — material icon named "interests" (round). + static const IconData interests_rounded = IconData(0xf033a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">interests</i> — material icon named "interests" (outlined). + static const IconData interests_outlined = IconData(0xf061b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">interpreter_mode</i> — material icon named "interpreter mode". + static const IconData interpreter_mode = IconData(0xf0524, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">interpreter_mode</i> — material icon named "interpreter mode" (sharp). + static const IconData interpreter_mode_sharp = IconData(0xf042e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">interpreter_mode</i> — material icon named "interpreter mode" (round). + static const IconData interpreter_mode_rounded = IconData(0xf033b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">interpreter_mode</i> — material icon named "interpreter mode" (outlined). + static const IconData interpreter_mode_outlined = IconData(0xf061c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">inventory</i> — material icon named "inventory". + static const IconData inventory = IconData(0xe349, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">inventory</i> — material icon named "inventory" (sharp). + static const IconData inventory_sharp = IconData(0xea44, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">inventory</i> — material icon named "inventory" (round). + static const IconData inventory_rounded = IconData(0xf823, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">inventory</i> — material icon named "inventory" (outlined). + static const IconData inventory_outlined = IconData(0xf135, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">inventory_2</i> — material icon named "inventory 2". + static const IconData inventory_2 = IconData(0xe34a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">inventory_2</i> — material icon named "inventory 2" (sharp). + static const IconData inventory_2_sharp = IconData(0xea43, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">inventory_2</i> — material icon named "inventory 2" (round). + static const IconData inventory_2_rounded = IconData(0xf822, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">inventory_2</i> — material icon named "inventory 2" (outlined). + static const IconData inventory_2_outlined = IconData(0xf134, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">invert_colors</i> — material icon named "invert colors". + static const IconData invert_colors = IconData(0xe34b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">invert_colors</i> — material icon named "invert colors" (sharp). + static const IconData invert_colors_sharp = IconData(0xea46, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">invert_colors</i> — material icon named "invert colors" (round). + static const IconData invert_colors_rounded = IconData(0xf825, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">invert_colors</i> — material icon named "invert colors" (outlined). + static const IconData invert_colors_outlined = IconData(0xf137, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">invert_colors_off</i> — material icon named "invert colors off". + static const IconData invert_colors_off = IconData(0xe34c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">invert_colors_off</i> — material icon named "invert colors off" (sharp). + static const IconData invert_colors_off_sharp = IconData(0xea45, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">invert_colors_off</i> — material icon named "invert colors off" (round). + static const IconData invert_colors_off_rounded = IconData(0xf824, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">invert_colors_off</i> — material icon named "invert colors off" (outlined). + static const IconData invert_colors_off_outlined = IconData(0xf136, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">invert_colors_on</i> — material icon named "invert colors on". + static const IconData invert_colors_on = IconData(0xe34b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">invert_colors_on</i> — material icon named "invert colors on" (sharp). + static const IconData invert_colors_on_sharp = IconData(0xea46, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">invert_colors_on</i> — material icon named "invert colors on" (round). + static const IconData invert_colors_on_rounded = IconData(0xf825, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">invert_colors_on</i> — material icon named "invert colors on" (outlined). + static const IconData invert_colors_on_outlined = IconData(0xf137, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ios_share</i> — material icon named "ios share". + static const IconData ios_share = IconData(0xe34d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ios_share</i> — material icon named "ios share" (sharp). + static const IconData ios_share_sharp = IconData(0xea47, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ios_share</i> — material icon named "ios share" (round). + static const IconData ios_share_rounded = IconData(0xf826, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ios_share</i> — material icon named "ios share" (outlined). + static const IconData ios_share_outlined = IconData(0xf138, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">iron</i> — material icon named "iron". + static const IconData iron = IconData(0xe34e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">iron</i> — material icon named "iron" (sharp). + static const IconData iron_sharp = IconData(0xea48, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">iron</i> — material icon named "iron" (round). + static const IconData iron_rounded = IconData(0xf827, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">iron</i> — material icon named "iron" (outlined). + static const IconData iron_outlined = IconData(0xf139, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">iso</i> — material icon named "iso". + static const IconData iso = IconData(0xe34f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">iso</i> — material icon named "iso" (sharp). + static const IconData iso_sharp = IconData(0xea49, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">iso</i> — material icon named "iso" (round). + static const IconData iso_rounded = IconData(0xf828, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">iso</i> — material icon named "iso" (outlined). + static const IconData iso_outlined = IconData(0xf13a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">javascript</i> — material icon named "javascript". + static const IconData javascript = IconData(0xf0525, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">javascript</i> — material icon named "javascript" (sharp). + static const IconData javascript_sharp = IconData(0xf042f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">javascript</i> — material icon named "javascript" (round). + static const IconData javascript_rounded = IconData(0xf033c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">javascript</i> — material icon named "javascript" (outlined). + static const IconData javascript_outlined = IconData(0xf061d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">join_full</i> — material icon named "join full". + static const IconData join_full = IconData(0xf0526, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">join_full</i> — material icon named "join full" (sharp). + static const IconData join_full_sharp = IconData(0xf0430, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">join_full</i> — material icon named "join full" (round). + static const IconData join_full_rounded = IconData(0xf033d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">join_full</i> — material icon named "join full" (outlined). + static const IconData join_full_outlined = IconData(0xf061e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">join_inner</i> — material icon named "join inner". + static const IconData join_inner = IconData(0xf0527, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">join_inner</i> — material icon named "join inner" (sharp). + static const IconData join_inner_sharp = IconData(0xf0431, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">join_inner</i> — material icon named "join inner" (round). + static const IconData join_inner_rounded = IconData(0xf033e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">join_inner</i> — material icon named "join inner" (outlined). + static const IconData join_inner_outlined = IconData(0xf061f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">join_left</i> — material icon named "join left". + static const IconData join_left = IconData(0xf0528, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">join_left</i> — material icon named "join left" (sharp). + static const IconData join_left_sharp = IconData(0xf0432, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">join_left</i> — material icon named "join left" (round). + static const IconData join_left_rounded = IconData(0xf033f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">join_left</i> — material icon named "join left" (outlined). + static const IconData join_left_outlined = IconData(0xf0620, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">join_right</i> — material icon named "join right". + static const IconData join_right = IconData(0xf0529, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">join_right</i> — material icon named "join right" (sharp). + static const IconData join_right_sharp = IconData(0xf0433, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">join_right</i> — material icon named "join right" (round). + static const IconData join_right_rounded = IconData(0xf0340, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">join_right</i> — material icon named "join right" (outlined). + static const IconData join_right_outlined = IconData(0xf0621, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">kayaking</i> — material icon named "kayaking". + static const IconData kayaking = IconData(0xe350, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">kayaking</i> — material icon named "kayaking" (sharp). + static const IconData kayaking_sharp = IconData(0xea4a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">kayaking</i> — material icon named "kayaking" (round). + static const IconData kayaking_rounded = IconData(0xf829, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">kayaking</i> — material icon named "kayaking" (outlined). + static const IconData kayaking_outlined = IconData(0xf13b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">kebab_dining</i> — material icon named "kebab dining". + static const IconData kebab_dining = IconData(0xf052a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">kebab_dining</i> — material icon named "kebab dining" (sharp). + static const IconData kebab_dining_sharp = IconData(0xf0434, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">kebab_dining</i> — material icon named "kebab dining" (round). + static const IconData kebab_dining_rounded = IconData(0xf0341, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">kebab_dining</i> — material icon named "kebab dining" (outlined). + static const IconData kebab_dining_outlined = IconData(0xf0622, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">key</i> — material icon named "key". + static const IconData key = IconData(0xf052b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">key</i> — material icon named "key" (sharp). + static const IconData key_sharp = IconData(0xf0436, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">key</i> — material icon named "key" (round). + static const IconData key_rounded = IconData(0xf0343, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">key</i> — material icon named "key" (outlined). + static const IconData key_outlined = IconData(0xf0624, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">key_off</i> — material icon named "key off". + static const IconData key_off = IconData(0xf052c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">key_off</i> — material icon named "key off" (sharp). + static const IconData key_off_sharp = IconData(0xf0435, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">key_off</i> — material icon named "key off" (round). + static const IconData key_off_rounded = IconData(0xf0342, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">key_off</i> — material icon named "key off" (outlined). + static const IconData key_off_outlined = IconData(0xf0623, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard</i> — material icon named "keyboard". + static const IconData keyboard = IconData(0xe351, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard</i> — material icon named "keyboard" (sharp). + static const IconData keyboard_sharp = IconData(0xea54, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard</i> — material icon named "keyboard" (round). + static const IconData keyboard_rounded = IconData(0xf833, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard</i> — material icon named "keyboard" (outlined). + static const IconData keyboard_outlined = IconData(0xf144, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_alt</i> — material icon named "keyboard alt". + static const IconData keyboard_alt = IconData(0xe352, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_alt</i> — material icon named "keyboard alt" (sharp). + static const IconData keyboard_alt_sharp = IconData(0xea4b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_alt</i> — material icon named "keyboard alt" (round). + static const IconData keyboard_alt_rounded = IconData(0xf82a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_alt</i> — material icon named "keyboard alt" (outlined). + static const IconData keyboard_alt_outlined = IconData(0xf13c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_arrow_down</i> — material icon named "keyboard arrow down". + static const IconData keyboard_arrow_down = IconData(0xe353, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_arrow_down</i> — material icon named "keyboard arrow down" (sharp). + static const IconData keyboard_arrow_down_sharp = IconData(0xea4c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_arrow_down</i> — material icon named "keyboard arrow down" (round). + static const IconData keyboard_arrow_down_rounded = IconData(0xf82b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_arrow_down</i> — material icon named "keyboard arrow down" (outlined). + static const IconData keyboard_arrow_down_outlined = IconData(0xf13d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_arrow_left</i> — material icon named "keyboard arrow left". + static const IconData keyboard_arrow_left = IconData(0xe354, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_arrow_left</i> — material icon named "keyboard arrow left" (sharp). + static const IconData keyboard_arrow_left_sharp = IconData(0xea4d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_arrow_left</i> — material icon named "keyboard arrow left" (round). + static const IconData keyboard_arrow_left_rounded = IconData(0xf82c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_arrow_left</i> — material icon named "keyboard arrow left" (outlined). + static const IconData keyboard_arrow_left_outlined = IconData(0xf13e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_arrow_right</i> — material icon named "keyboard arrow right". + static const IconData keyboard_arrow_right = IconData(0xe355, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_arrow_right</i> — material icon named "keyboard arrow right" (sharp). + static const IconData keyboard_arrow_right_sharp = IconData(0xea4e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_arrow_right</i> — material icon named "keyboard arrow right" (round). + static const IconData keyboard_arrow_right_rounded = IconData(0xf82d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_arrow_right</i> — material icon named "keyboard arrow right" (outlined). + static const IconData keyboard_arrow_right_outlined = IconData(0xf13f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_arrow_up</i> — material icon named "keyboard arrow up". + static const IconData keyboard_arrow_up = IconData(0xe356, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_arrow_up</i> — material icon named "keyboard arrow up" (sharp). + static const IconData keyboard_arrow_up_sharp = IconData(0xea4f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_arrow_up</i> — material icon named "keyboard arrow up" (round). + static const IconData keyboard_arrow_up_rounded = IconData(0xf82e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_arrow_up</i> — material icon named "keyboard arrow up" (outlined). + static const IconData keyboard_arrow_up_outlined = IconData(0xf140, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_backspace</i> — material icon named "keyboard backspace". + static const IconData keyboard_backspace = IconData(0xe357, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">keyboard_backspace</i> — material icon named "keyboard backspace" (sharp). + static const IconData keyboard_backspace_sharp = IconData(0xea50, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">keyboard_backspace</i> — material icon named "keyboard backspace" (round). + static const IconData keyboard_backspace_rounded = IconData(0xf82f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">keyboard_backspace</i> — material icon named "keyboard backspace" (outlined). + static const IconData keyboard_backspace_outlined = IconData(0xf141, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">keyboard_capslock</i> — material icon named "keyboard capslock". + static const IconData keyboard_capslock = IconData(0xe358, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_capslock</i> — material icon named "keyboard capslock" (sharp). + static const IconData keyboard_capslock_sharp = IconData(0xea51, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_capslock</i> — material icon named "keyboard capslock" (round). + static const IconData keyboard_capslock_rounded = IconData(0xf830, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_capslock</i> — material icon named "keyboard capslock" (outlined). + static const IconData keyboard_capslock_outlined = IconData(0xf142, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_command_key</i> — material icon named "keyboard command key". + static const IconData keyboard_command_key = IconData(0xf052d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_command_key</i> — material icon named "keyboard command key" (sharp). + static const IconData keyboard_command_key_sharp = IconData(0xf0437, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_command_key</i> — material icon named "keyboard command key" (round). + static const IconData keyboard_command_key_rounded = IconData(0xf0344, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_command_key</i> — material icon named "keyboard command key" (outlined). + static const IconData keyboard_command_key_outlined = IconData(0xf0625, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_control</i> — material icon named "keyboard control". + static const IconData keyboard_control = IconData(0xe402, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_control</i> — material icon named "keyboard control" (sharp). + static const IconData keyboard_control_sharp = IconData(0xeafa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_control</i> — material icon named "keyboard control" (round). + static const IconData keyboard_control_rounded = IconData(0xf8d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_control</i> — material icon named "keyboard control" (outlined). + static const IconData keyboard_control_outlined = IconData(0xf1e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_control_key</i> — material icon named "keyboard control key". + static const IconData keyboard_control_key = IconData(0xf052e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_control_key</i> — material icon named "keyboard control key" (sharp). + static const IconData keyboard_control_key_sharp = IconData(0xf0438, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_control_key</i> — material icon named "keyboard control key" (round). + static const IconData keyboard_control_key_rounded = IconData(0xf0345, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_control_key</i> — material icon named "keyboard control key" (outlined). + static const IconData keyboard_control_key_outlined = IconData(0xf0626, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_double_arrow_down</i> — material icon named "keyboard double arrow down". + static const IconData keyboard_double_arrow_down = IconData(0xf052f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_double_arrow_down</i> — material icon named "keyboard double arrow down" (sharp). + static const IconData keyboard_double_arrow_down_sharp = IconData(0xf0439, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_double_arrow_down</i> — material icon named "keyboard double arrow down" (round). + static const IconData keyboard_double_arrow_down_rounded = IconData(0xf0346, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_double_arrow_down</i> — material icon named "keyboard double arrow down" (outlined). + static const IconData keyboard_double_arrow_down_outlined = IconData(0xf0627, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_double_arrow_left</i> — material icon named "keyboard double arrow left". + static const IconData keyboard_double_arrow_left = IconData(0xf0530, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_double_arrow_left</i> — material icon named "keyboard double arrow left" (sharp). + static const IconData keyboard_double_arrow_left_sharp = IconData(0xf043a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_double_arrow_left</i> — material icon named "keyboard double arrow left" (round). + static const IconData keyboard_double_arrow_left_rounded = IconData(0xf0347, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_double_arrow_left</i> — material icon named "keyboard double arrow left" (outlined). + static const IconData keyboard_double_arrow_left_outlined = IconData(0xf0628, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_double_arrow_right</i> — material icon named "keyboard double arrow right". + static const IconData keyboard_double_arrow_right = IconData(0xf0531, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_double_arrow_right</i> — material icon named "keyboard double arrow right" (sharp). + static const IconData keyboard_double_arrow_right_sharp = IconData(0xf043b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_double_arrow_right</i> — material icon named "keyboard double arrow right" (round). + static const IconData keyboard_double_arrow_right_rounded = IconData(0xf0348, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_double_arrow_right</i> — material icon named "keyboard double arrow right" (outlined). + static const IconData keyboard_double_arrow_right_outlined = IconData(0xf0629, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_double_arrow_up</i> — material icon named "keyboard double arrow up". + static const IconData keyboard_double_arrow_up = IconData(0xf0532, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_double_arrow_up</i> — material icon named "keyboard double arrow up" (sharp). + static const IconData keyboard_double_arrow_up_sharp = IconData(0xf043c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_double_arrow_up</i> — material icon named "keyboard double arrow up" (round). + static const IconData keyboard_double_arrow_up_rounded = IconData(0xf0349, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_double_arrow_up</i> — material icon named "keyboard double arrow up" (outlined). + static const IconData keyboard_double_arrow_up_outlined = IconData(0xf062a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_hide</i> — material icon named "keyboard hide". + static const IconData keyboard_hide = IconData(0xe359, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_hide</i> — material icon named "keyboard hide" (sharp). + static const IconData keyboard_hide_sharp = IconData(0xea52, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_hide</i> — material icon named "keyboard hide" (round). + static const IconData keyboard_hide_rounded = IconData(0xf831, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_hide</i> — material icon named "keyboard hide" (outlined). + static const IconData keyboard_hide_outlined = IconData(0xf143, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_option_key</i> — material icon named "keyboard option key". + static const IconData keyboard_option_key = IconData(0xf0533, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_option_key</i> — material icon named "keyboard option key" (sharp). + static const IconData keyboard_option_key_sharp = IconData(0xf043d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_option_key</i> — material icon named "keyboard option key" (round). + static const IconData keyboard_option_key_rounded = IconData(0xf034a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_option_key</i> — material icon named "keyboard option key" (outlined). + static const IconData keyboard_option_key_outlined = IconData(0xf062b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_return</i> — material icon named "keyboard return". + static const IconData keyboard_return = IconData(0xe35a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_return</i> — material icon named "keyboard return" (sharp). + static const IconData keyboard_return_sharp = IconData(0xea53, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_return</i> — material icon named "keyboard return" (round). + static const IconData keyboard_return_rounded = IconData(0xf832, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_return</i> — material icon named "keyboard return" (outlined). + static const IconData keyboard_return_outlined = IconData(0xf145, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">keyboard_tab</i> — material icon named "keyboard tab". + static const IconData keyboard_tab = IconData(0xe35b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">keyboard_tab</i> — material icon named "keyboard tab" (sharp). + static const IconData keyboard_tab_sharp = IconData(0xea55, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">keyboard_tab</i> — material icon named "keyboard tab" (round). + static const IconData keyboard_tab_rounded = IconData(0xf834, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">keyboard_tab</i> — material icon named "keyboard tab" (outlined). + static const IconData keyboard_tab_outlined = IconData(0xf146, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">keyboard_voice</i> — material icon named "keyboard voice". + static const IconData keyboard_voice = IconData(0xe35c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">keyboard_voice</i> — material icon named "keyboard voice" (sharp). + static const IconData keyboard_voice_sharp = IconData(0xea56, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">keyboard_voice</i> — material icon named "keyboard voice" (round). + static const IconData keyboard_voice_rounded = IconData(0xf835, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">keyboard_voice</i> — material icon named "keyboard voice" (outlined). + static const IconData keyboard_voice_outlined = IconData(0xf147, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">king_bed</i> — material icon named "king bed". + static const IconData king_bed = IconData(0xe35d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">king_bed</i> — material icon named "king bed" (sharp). + static const IconData king_bed_sharp = IconData(0xea57, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">king_bed</i> — material icon named "king bed" (round). + static const IconData king_bed_rounded = IconData(0xf836, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">king_bed</i> — material icon named "king bed" (outlined). + static const IconData king_bed_outlined = IconData(0xf148, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">kitchen</i> — material icon named "kitchen". + static const IconData kitchen = IconData(0xe35e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">kitchen</i> — material icon named "kitchen" (sharp). + static const IconData kitchen_sharp = IconData(0xea58, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">kitchen</i> — material icon named "kitchen" (round). + static const IconData kitchen_rounded = IconData(0xf837, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">kitchen</i> — material icon named "kitchen" (outlined). + static const IconData kitchen_outlined = IconData(0xf149, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">kitesurfing</i> — material icon named "kitesurfing". + static const IconData kitesurfing = IconData(0xe35f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">kitesurfing</i> — material icon named "kitesurfing" (sharp). + static const IconData kitesurfing_sharp = IconData(0xea59, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">kitesurfing</i> — material icon named "kitesurfing" (round). + static const IconData kitesurfing_rounded = IconData(0xf838, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">kitesurfing</i> — material icon named "kitesurfing" (outlined). + static const IconData kitesurfing_outlined = IconData(0xf14a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">label</i> — material icon named "label". + static const IconData label = IconData(0xe360, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">label</i> — material icon named "label" (sharp). + static const IconData label_sharp = IconData(0xea5e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">label</i> — material icon named "label" (round). + static const IconData label_rounded = IconData(0xf83d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">label</i> — material icon named "label" (outlined). + static const IconData label_outlined = IconData(0xf14d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">label_important</i> — material icon named "label important". + static const IconData label_important = IconData(0xe361, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">label_important</i> — material icon named "label important" (sharp). + static const IconData label_important_sharp = IconData(0xea5b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">label_important</i> — material icon named "label important" (round). + static const IconData label_important_rounded = IconData(0xf83a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">label_important</i> — material icon named "label important" (outlined). + static const IconData label_important_outlined = IconData(0xf14b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">label_important_outline</i> — material icon named "label important outline". + static const IconData label_important_outline = IconData(0xe362, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">label_important_outline</i> — material icon named "label important outline" (sharp). + static const IconData label_important_outline_sharp = IconData(0xea5a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">label_important_outline</i> — material icon named "label important outline" (round). + static const IconData label_important_outline_rounded = IconData(0xf839, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">label_off</i> — material icon named "label off". + static const IconData label_off = IconData(0xe363, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">label_off</i> — material icon named "label off" (sharp). + static const IconData label_off_sharp = IconData(0xea5c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">label_off</i> — material icon named "label off" (round). + static const IconData label_off_rounded = IconData(0xf83b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">label_off</i> — material icon named "label off" (outlined). + static const IconData label_off_outlined = IconData(0xf14c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">label_outline</i> — material icon named "label outline". + static const IconData label_outline = IconData(0xe364, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">label_outline</i> — material icon named "label outline" (sharp). + static const IconData label_outline_sharp = IconData(0xea5d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">label_outline</i> — material icon named "label outline" (round). + static const IconData label_outline_rounded = IconData(0xf83c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">lan</i> — material icon named "lan". + static const IconData lan = IconData(0xf0534, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lan</i> — material icon named "lan" (sharp). + static const IconData lan_sharp = IconData(0xf043e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lan</i> — material icon named "lan" (round). + static const IconData lan_rounded = IconData(0xf034b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lan</i> — material icon named "lan" (outlined). + static const IconData lan_outlined = IconData(0xf062c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">landscape</i> — material icon named "landscape". + static const IconData landscape = IconData(0xe365, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">landscape</i> — material icon named "landscape" (sharp). + static const IconData landscape_sharp = IconData(0xea5f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">landscape</i> — material icon named "landscape" (round). + static const IconData landscape_rounded = IconData(0xf83e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">landscape</i> — material icon named "landscape" (outlined). + static const IconData landscape_outlined = IconData(0xf14e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">landslide</i> — material icon named "landslide". + static const IconData landslide = IconData(0xf07a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">landslide</i> — material icon named "landslide" (sharp). + static const IconData landslide_sharp = IconData(0xf074e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">landslide</i> — material icon named "landslide" (round). + static const IconData landslide_rounded = IconData(0xf07fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">landslide</i> — material icon named "landslide" (outlined). + static const IconData landslide_outlined = IconData(0xf06f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">language</i> — material icon named "language". + static const IconData language = IconData(0xe366, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">language</i> — material icon named "language" (sharp). + static const IconData language_sharp = IconData(0xea60, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">language</i> — material icon named "language" (round). + static const IconData language_rounded = IconData(0xf83f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">language</i> — material icon named "language" (outlined). + static const IconData language_outlined = IconData(0xf14f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">laptop</i> — material icon named "laptop". + static const IconData laptop = IconData(0xe367, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">laptop</i> — material icon named "laptop" (sharp). + static const IconData laptop_sharp = IconData(0xea63, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">laptop</i> — material icon named "laptop" (round). + static const IconData laptop_rounded = IconData(0xf842, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">laptop</i> — material icon named "laptop" (outlined). + static const IconData laptop_outlined = IconData(0xf152, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">laptop_chromebook</i> — material icon named "laptop chromebook". + static const IconData laptop_chromebook = IconData(0xe368, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">laptop_chromebook</i> — material icon named "laptop chromebook" (sharp). + static const IconData laptop_chromebook_sharp = IconData(0xea61, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">laptop_chromebook</i> — material icon named "laptop chromebook" (round). + static const IconData laptop_chromebook_rounded = IconData(0xf840, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">laptop_chromebook</i> — material icon named "laptop chromebook" (outlined). + static const IconData laptop_chromebook_outlined = IconData(0xf150, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">laptop_mac</i> — material icon named "laptop mac". + static const IconData laptop_mac = IconData(0xe369, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">laptop_mac</i> — material icon named "laptop mac" (sharp). + static const IconData laptop_mac_sharp = IconData(0xea62, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">laptop_mac</i> — material icon named "laptop mac" (round). + static const IconData laptop_mac_rounded = IconData(0xf841, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">laptop_mac</i> — material icon named "laptop mac" (outlined). + static const IconData laptop_mac_outlined = IconData(0xf151, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">laptop_windows</i> — material icon named "laptop windows". + static const IconData laptop_windows = IconData(0xe36a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">laptop_windows</i> — material icon named "laptop windows" (sharp). + static const IconData laptop_windows_sharp = IconData(0xea64, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">laptop_windows</i> — material icon named "laptop windows" (round). + static const IconData laptop_windows_rounded = IconData(0xf843, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">laptop_windows</i> — material icon named "laptop windows" (outlined). + static const IconData laptop_windows_outlined = IconData(0xf153, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">last_page</i> — material icon named "last page". + static const IconData last_page = IconData(0xe36b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">last_page</i> — material icon named "last page" (sharp). + static const IconData last_page_sharp = IconData(0xea65, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">last_page</i> — material icon named "last page" (round). + static const IconData last_page_rounded = IconData(0xf844, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">last_page</i> — material icon named "last page" (outlined). + static const IconData last_page_outlined = IconData(0xf154, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">launch</i> — material icon named "launch". + static const IconData launch = IconData(0xe36c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">launch</i> — material icon named "launch" (sharp). + static const IconData launch_sharp = IconData(0xea66, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">launch</i> — material icon named "launch" (round). + static const IconData launch_rounded = IconData(0xf845, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">launch</i> — material icon named "launch" (outlined). + static const IconData launch_outlined = IconData(0xf155, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">layers</i> — material icon named "layers". + static const IconData layers = IconData(0xe36d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">layers</i> — material icon named "layers" (sharp). + static const IconData layers_sharp = IconData(0xea68, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">layers</i> — material icon named "layers" (round). + static const IconData layers_rounded = IconData(0xf847, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">layers</i> — material icon named "layers" (outlined). + static const IconData layers_outlined = IconData(0xf157, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">layers_clear</i> — material icon named "layers clear". + static const IconData layers_clear = IconData(0xe36e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">layers_clear</i> — material icon named "layers clear" (sharp). + static const IconData layers_clear_sharp = IconData(0xea67, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">layers_clear</i> — material icon named "layers clear" (round). + static const IconData layers_clear_rounded = IconData(0xf846, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">layers_clear</i> — material icon named "layers clear" (outlined). + static const IconData layers_clear_outlined = IconData(0xf156, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">leaderboard</i> — material icon named "leaderboard". + static const IconData leaderboard = IconData(0xe36f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">leaderboard</i> — material icon named "leaderboard" (sharp). + static const IconData leaderboard_sharp = IconData(0xea69, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">leaderboard</i> — material icon named "leaderboard" (round). + static const IconData leaderboard_rounded = IconData(0xf848, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">leaderboard</i> — material icon named "leaderboard" (outlined). + static const IconData leaderboard_outlined = IconData(0xf158, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">leak_add</i> — material icon named "leak add". + static const IconData leak_add = IconData(0xe370, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">leak_add</i> — material icon named "leak add" (sharp). + static const IconData leak_add_sharp = IconData(0xea6a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">leak_add</i> — material icon named "leak add" (round). + static const IconData leak_add_rounded = IconData(0xf849, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">leak_add</i> — material icon named "leak add" (outlined). + static const IconData leak_add_outlined = IconData(0xf159, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">leak_remove</i> — material icon named "leak remove". + static const IconData leak_remove = IconData(0xe371, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">leak_remove</i> — material icon named "leak remove" (sharp). + static const IconData leak_remove_sharp = IconData(0xea6b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">leak_remove</i> — material icon named "leak remove" (round). + static const IconData leak_remove_rounded = IconData(0xf84a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">leak_remove</i> — material icon named "leak remove" (outlined). + static const IconData leak_remove_outlined = IconData(0xf15a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">leave_bags_at_home</i> — material icon named "leave bags at home". + static const IconData leave_bags_at_home = IconData(0xe439, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">leave_bags_at_home</i> — material icon named "leave bags at home" (sharp). + static const IconData leave_bags_at_home_sharp = IconData(0xeb32, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">leave_bags_at_home</i> — material icon named "leave bags at home" (round). + static const IconData leave_bags_at_home_rounded = IconData(0xf0011, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">leave_bags_at_home</i> — material icon named "leave bags at home" (outlined). + static const IconData leave_bags_at_home_outlined = IconData(0xf21f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">legend_toggle</i> — material icon named "legend toggle". + static const IconData legend_toggle = IconData(0xe372, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">legend_toggle</i> — material icon named "legend toggle" (sharp). + static const IconData legend_toggle_sharp = IconData(0xea6c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">legend_toggle</i> — material icon named "legend toggle" (round). + static const IconData legend_toggle_rounded = IconData(0xf84b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">legend_toggle</i> — material icon named "legend toggle" (outlined). + static const IconData legend_toggle_outlined = IconData(0xf15b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lens</i> — material icon named "lens". + static const IconData lens = IconData(0xe373, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lens</i> — material icon named "lens" (sharp). + static const IconData lens_sharp = IconData(0xea6e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lens</i> — material icon named "lens" (round). + static const IconData lens_rounded = IconData(0xf84d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lens</i> — material icon named "lens" (outlined). + static const IconData lens_outlined = IconData(0xf15d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lens_blur</i> — material icon named "lens blur". + static const IconData lens_blur = IconData(0xe374, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lens_blur</i> — material icon named "lens blur" (sharp). + static const IconData lens_blur_sharp = IconData(0xea6d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lens_blur</i> — material icon named "lens blur" (round). + static const IconData lens_blur_rounded = IconData(0xf84c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lens_blur</i> — material icon named "lens blur" (outlined). + static const IconData lens_blur_outlined = IconData(0xf15c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">library_add</i> — material icon named "library add". + static const IconData library_add = IconData(0xe375, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">library_add</i> — material icon named "library add" (sharp). + static const IconData library_add_sharp = IconData(0xea70, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">library_add</i> — material icon named "library add" (round). + static const IconData library_add_rounded = IconData(0xf84f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">library_add</i> — material icon named "library add" (outlined). + static const IconData library_add_outlined = IconData(0xf15f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">library_add_check</i> — material icon named "library add check". + static const IconData library_add_check = IconData(0xe376, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">library_add_check</i> — material icon named "library add check" (sharp). + static const IconData library_add_check_sharp = IconData(0xea6f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">library_add_check</i> — material icon named "library add check" (round). + static const IconData library_add_check_rounded = IconData(0xf84e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">library_add_check</i> — material icon named "library add check" (outlined). + static const IconData library_add_check_outlined = IconData(0xf15e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">library_books</i> — material icon named "library books". + static const IconData library_books = IconData(0xe377, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">library_books</i> — material icon named "library books" (sharp). + static const IconData library_books_sharp = IconData(0xea71, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">library_books</i> — material icon named "library books" (round). + static const IconData library_books_rounded = IconData(0xf850, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">library_books</i> — material icon named "library books" (outlined). + static const IconData library_books_outlined = IconData(0xf160, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">library_music</i> — material icon named "library music". + static const IconData library_music = IconData(0xe378, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">library_music</i> — material icon named "library music" (sharp). + static const IconData library_music_sharp = IconData(0xea72, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">library_music</i> — material icon named "library music" (round). + static const IconData library_music_rounded = IconData(0xf851, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">library_music</i> — material icon named "library music" (outlined). + static const IconData library_music_outlined = IconData(0xf161, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">light</i> — material icon named "light". + static const IconData light = IconData(0xe379, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">light</i> — material icon named "light" (sharp). + static const IconData light_sharp = IconData(0xea74, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">light</i> — material icon named "light" (round). + static const IconData light_rounded = IconData(0xf853, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">light</i> — material icon named "light" (outlined). + static const IconData light_outlined = IconData(0xf163, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">light_mode</i> — material icon named "light mode". + static const IconData light_mode = IconData(0xe37a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">light_mode</i> — material icon named "light mode" (sharp). + static const IconData light_mode_sharp = IconData(0xea73, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">light_mode</i> — material icon named "light mode" (round). + static const IconData light_mode_rounded = IconData(0xf852, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">light_mode</i> — material icon named "light mode" (outlined). + static const IconData light_mode_outlined = IconData(0xf162, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lightbulb</i> — material icon named "lightbulb". + static const IconData lightbulb = IconData(0xe37b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lightbulb</i> — material icon named "lightbulb" (sharp). + static const IconData lightbulb_sharp = IconData(0xea76, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lightbulb</i> — material icon named "lightbulb" (round). + static const IconData lightbulb_rounded = IconData(0xf855, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lightbulb</i> — material icon named "lightbulb" (outlined). + static const IconData lightbulb_outlined = IconData(0xf164, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lightbulb_circle</i> — material icon named "lightbulb circle". + static const IconData lightbulb_circle = IconData(0xf07a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lightbulb_circle</i> — material icon named "lightbulb circle" (sharp). + static const IconData lightbulb_circle_sharp = IconData(0xf074f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lightbulb_circle</i> — material icon named "lightbulb circle" (round). + static const IconData lightbulb_circle_rounded = IconData(0xf07ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lightbulb_circle</i> — material icon named "lightbulb circle" (outlined). + static const IconData lightbulb_circle_outlined = IconData(0xf06f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lightbulb_outline</i> — material icon named "lightbulb outline". + static const IconData lightbulb_outline = IconData(0xe37c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lightbulb_outline</i> — material icon named "lightbulb outline" (sharp). + static const IconData lightbulb_outline_sharp = IconData(0xea75, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lightbulb_outline</i> — material icon named "lightbulb outline" (round). + static const IconData lightbulb_outline_rounded = IconData(0xf854, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">line_axis</i> — material icon named "line axis". + static const IconData line_axis = IconData(0xf0535, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">line_axis</i> — material icon named "line axis" (sharp). + static const IconData line_axis_sharp = IconData(0xf043f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">line_axis</i> — material icon named "line axis" (round). + static const IconData line_axis_rounded = IconData(0xf034c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">line_axis</i> — material icon named "line axis" (outlined). + static const IconData line_axis_outlined = IconData(0xf062d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">line_style</i> — material icon named "line style". + static const IconData line_style = IconData(0xe37d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">line_style</i> — material icon named "line style" (sharp). + static const IconData line_style_sharp = IconData(0xea77, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">line_style</i> — material icon named "line style" (round). + static const IconData line_style_rounded = IconData(0xf856, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">line_style</i> — material icon named "line style" (outlined). + static const IconData line_style_outlined = IconData(0xf165, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">line_weight</i> — material icon named "line weight". + static const IconData line_weight = IconData(0xe37e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">line_weight</i> — material icon named "line weight" (sharp). + static const IconData line_weight_sharp = IconData(0xea78, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">line_weight</i> — material icon named "line weight" (round). + static const IconData line_weight_rounded = IconData(0xf857, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">line_weight</i> — material icon named "line weight" (outlined). + static const IconData line_weight_outlined = IconData(0xf166, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">linear_scale</i> — material icon named "linear scale". + static const IconData linear_scale = IconData(0xe37f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">linear_scale</i> — material icon named "linear scale" (sharp). + static const IconData linear_scale_sharp = IconData(0xea79, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">linear_scale</i> — material icon named "linear scale" (round). + static const IconData linear_scale_rounded = IconData(0xf858, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">linear_scale</i> — material icon named "linear scale" (outlined). + static const IconData linear_scale_outlined = IconData(0xf167, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">link</i> — material icon named "link". + static const IconData link = IconData(0xe380, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">link</i> — material icon named "link" (sharp). + static const IconData link_sharp = IconData(0xea7b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">link</i> — material icon named "link" (round). + static const IconData link_rounded = IconData(0xf85a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">link</i> — material icon named "link" (outlined). + static const IconData link_outlined = IconData(0xf169, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">link_off</i> — material icon named "link off". + static const IconData link_off = IconData(0xe381, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">link_off</i> — material icon named "link off" (sharp). + static const IconData link_off_sharp = IconData(0xea7a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">link_off</i> — material icon named "link off" (round). + static const IconData link_off_rounded = IconData(0xf859, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">link_off</i> — material icon named "link off" (outlined). + static const IconData link_off_outlined = IconData(0xf168, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">linked_camera</i> — material icon named "linked camera". + static const IconData linked_camera = IconData(0xe382, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">linked_camera</i> — material icon named "linked camera" (sharp). + static const IconData linked_camera_sharp = IconData(0xea7c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">linked_camera</i> — material icon named "linked camera" (round). + static const IconData linked_camera_rounded = IconData(0xf85b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">linked_camera</i> — material icon named "linked camera" (outlined). + static const IconData linked_camera_outlined = IconData(0xf16a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">liquor</i> — material icon named "liquor". + static const IconData liquor = IconData(0xe383, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">liquor</i> — material icon named "liquor" (sharp). + static const IconData liquor_sharp = IconData(0xea7d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">liquor</i> — material icon named "liquor" (round). + static const IconData liquor_rounded = IconData(0xf85c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">liquor</i> — material icon named "liquor" (outlined). + static const IconData liquor_outlined = IconData(0xf16b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">list</i> — material icon named "list". + static const IconData list = IconData(0xe384, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">list</i> — material icon named "list" (sharp). + static const IconData list_sharp = IconData(0xea7f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">list</i> — material icon named "list" (round). + static const IconData list_rounded = IconData(0xf85e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">list</i> — material icon named "list" (outlined). + static const IconData list_outlined = IconData(0xf16d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">list_alt</i> — material icon named "list alt". + static const IconData list_alt = IconData(0xe385, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">list_alt</i> — material icon named "list alt" (sharp). + static const IconData list_alt_sharp = IconData(0xea7e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">list_alt</i> — material icon named "list alt" (round). + static const IconData list_alt_rounded = IconData(0xf85d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">list_alt</i> — material icon named "list alt" (outlined). + static const IconData list_alt_outlined = IconData(0xf16c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">live_help</i> — material icon named "live help". + static const IconData live_help = IconData(0xe386, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">live_help</i> — material icon named "live help" (sharp). + static const IconData live_help_sharp = IconData(0xea80, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">live_help</i> — material icon named "live help" (round). + static const IconData live_help_rounded = IconData(0xf85f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">live_help</i> — material icon named "live help" (outlined). + static const IconData live_help_outlined = IconData(0xf16e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">live_tv</i> — material icon named "live tv". + static const IconData live_tv = IconData(0xe387, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">live_tv</i> — material icon named "live tv" (sharp). + static const IconData live_tv_sharp = IconData(0xea81, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">live_tv</i> — material icon named "live tv" (round). + static const IconData live_tv_rounded = IconData(0xf860, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">live_tv</i> — material icon named "live tv" (outlined). + static const IconData live_tv_outlined = IconData(0xf16f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">living</i> — material icon named "living". + static const IconData living = IconData(0xe388, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">living</i> — material icon named "living" (sharp). + static const IconData living_sharp = IconData(0xea82, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">living</i> — material icon named "living" (round). + static const IconData living_rounded = IconData(0xf861, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">living</i> — material icon named "living" (outlined). + static const IconData living_outlined = IconData(0xf170, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_activity</i> — material icon named "local activity". + static const IconData local_activity = IconData(0xe389, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_activity</i> — material icon named "local activity" (sharp). + static const IconData local_activity_sharp = IconData(0xea83, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_activity</i> — material icon named "local activity" (round). + static const IconData local_activity_rounded = IconData(0xf862, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_activity</i> — material icon named "local activity" (outlined). + static const IconData local_activity_outlined = IconData(0xf171, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_airport</i> — material icon named "local airport". + static const IconData local_airport = IconData(0xe38a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_airport</i> — material icon named "local airport" (sharp). + static const IconData local_airport_sharp = IconData(0xea84, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_airport</i> — material icon named "local airport" (round). + static const IconData local_airport_rounded = IconData(0xf863, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_airport</i> — material icon named "local airport" (outlined). + static const IconData local_airport_outlined = IconData(0xf172, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_atm</i> — material icon named "local atm". + static const IconData local_atm = IconData(0xe38b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_atm</i> — material icon named "local atm" (sharp). + static const IconData local_atm_sharp = IconData(0xea85, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_atm</i> — material icon named "local atm" (round). + static const IconData local_atm_rounded = IconData(0xf864, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_atm</i> — material icon named "local atm" (outlined). + static const IconData local_atm_outlined = IconData(0xf173, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_attraction</i> — material icon named "local attraction". + static const IconData local_attraction = IconData(0xe389, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_attraction</i> — material icon named "local attraction" (sharp). + static const IconData local_attraction_sharp = IconData(0xea83, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_attraction</i> — material icon named "local attraction" (round). + static const IconData local_attraction_rounded = IconData(0xf862, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_attraction</i> — material icon named "local attraction" (outlined). + static const IconData local_attraction_outlined = IconData(0xf171, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_bar</i> — material icon named "local bar". + static const IconData local_bar = IconData(0xe38c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_bar</i> — material icon named "local bar" (sharp). + static const IconData local_bar_sharp = IconData(0xea86, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_bar</i> — material icon named "local bar" (round). + static const IconData local_bar_rounded = IconData(0xf865, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_bar</i> — material icon named "local bar" (outlined). + static const IconData local_bar_outlined = IconData(0xf174, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_cafe</i> — material icon named "local cafe". + static const IconData local_cafe = IconData(0xe38d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_cafe</i> — material icon named "local cafe" (sharp). + static const IconData local_cafe_sharp = IconData(0xea87, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_cafe</i> — material icon named "local cafe" (round). + static const IconData local_cafe_rounded = IconData(0xf866, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_cafe</i> — material icon named "local cafe" (outlined). + static const IconData local_cafe_outlined = IconData(0xf175, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_car_wash</i> — material icon named "local car wash". + static const IconData local_car_wash = IconData(0xe38e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_car_wash</i> — material icon named "local car wash" (sharp). + static const IconData local_car_wash_sharp = IconData(0xea88, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_car_wash</i> — material icon named "local car wash" (round). + static const IconData local_car_wash_rounded = IconData(0xf867, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_car_wash</i> — material icon named "local car wash" (outlined). + static const IconData local_car_wash_outlined = IconData(0xf176, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_convenience_store</i> — material icon named "local convenience store". + static const IconData local_convenience_store = IconData(0xe38f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_convenience_store</i> — material icon named "local convenience store" (sharp). + static const IconData local_convenience_store_sharp = IconData(0xea89, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_convenience_store</i> — material icon named "local convenience store" (round). + static const IconData local_convenience_store_rounded = IconData(0xf868, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_convenience_store</i> — material icon named "local convenience store" (outlined). + static const IconData local_convenience_store_outlined = IconData(0xf177, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_dining</i> — material icon named "local dining". + static const IconData local_dining = IconData(0xe390, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_dining</i> — material icon named "local dining" (sharp). + static const IconData local_dining_sharp = IconData(0xea8a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_dining</i> — material icon named "local dining" (round). + static const IconData local_dining_rounded = IconData(0xf869, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_dining</i> — material icon named "local dining" (outlined). + static const IconData local_dining_outlined = IconData(0xf178, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_drink</i> — material icon named "local drink". + static const IconData local_drink = IconData(0xe391, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_drink</i> — material icon named "local drink" (sharp). + static const IconData local_drink_sharp = IconData(0xea8b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_drink</i> — material icon named "local drink" (round). + static const IconData local_drink_rounded = IconData(0xf86a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_drink</i> — material icon named "local drink" (outlined). + static const IconData local_drink_outlined = IconData(0xf179, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_fire_department</i> — material icon named "local fire department". + static const IconData local_fire_department = IconData(0xe392, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_fire_department</i> — material icon named "local fire department" (sharp). + static const IconData local_fire_department_sharp = IconData(0xea8c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_fire_department</i> — material icon named "local fire department" (round). + static const IconData local_fire_department_rounded = IconData(0xf86b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_fire_department</i> — material icon named "local fire department" (outlined). + static const IconData local_fire_department_outlined = IconData(0xf17a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_florist</i> — material icon named "local florist". + static const IconData local_florist = IconData(0xe393, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_florist</i> — material icon named "local florist" (sharp). + static const IconData local_florist_sharp = IconData(0xea8d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_florist</i> — material icon named "local florist" (round). + static const IconData local_florist_rounded = IconData(0xf86c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_florist</i> — material icon named "local florist" (outlined). + static const IconData local_florist_outlined = IconData(0xf17b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_gas_station</i> — material icon named "local gas station". + static const IconData local_gas_station = IconData(0xe394, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_gas_station</i> — material icon named "local gas station" (sharp). + static const IconData local_gas_station_sharp = IconData(0xea8e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_gas_station</i> — material icon named "local gas station" (round). + static const IconData local_gas_station_rounded = IconData(0xf86d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_gas_station</i> — material icon named "local gas station" (outlined). + static const IconData local_gas_station_outlined = IconData(0xf17c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_grocery_store</i> — material icon named "local grocery store". + static const IconData local_grocery_store = IconData(0xe395, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_grocery_store</i> — material icon named "local grocery store" (sharp). + static const IconData local_grocery_store_sharp = IconData(0xea8f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_grocery_store</i> — material icon named "local grocery store" (round). + static const IconData local_grocery_store_rounded = IconData(0xf86e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_grocery_store</i> — material icon named "local grocery store" (outlined). + static const IconData local_grocery_store_outlined = IconData(0xf17d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_hospital</i> — material icon named "local hospital". + static const IconData local_hospital = IconData(0xe396, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_hospital</i> — material icon named "local hospital" (sharp). + static const IconData local_hospital_sharp = IconData(0xea90, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_hospital</i> — material icon named "local hospital" (round). + static const IconData local_hospital_rounded = IconData(0xf86f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_hospital</i> — material icon named "local hospital" (outlined). + static const IconData local_hospital_outlined = IconData(0xf17e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_hotel</i> — material icon named "local hotel". + static const IconData local_hotel = IconData(0xe397, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_hotel</i> — material icon named "local hotel" (sharp). + static const IconData local_hotel_sharp = IconData(0xea91, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_hotel</i> — material icon named "local hotel" (round). + static const IconData local_hotel_rounded = IconData(0xf870, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_hotel</i> — material icon named "local hotel" (outlined). + static const IconData local_hotel_outlined = IconData(0xf17f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_laundry_service</i> — material icon named "local laundry service". + static const IconData local_laundry_service = IconData(0xe398, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_laundry_service</i> — material icon named "local laundry service" (sharp). + static const IconData local_laundry_service_sharp = IconData(0xea92, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_laundry_service</i> — material icon named "local laundry service" (round). + static const IconData local_laundry_service_rounded = IconData(0xf871, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_laundry_service</i> — material icon named "local laundry service" (outlined). + static const IconData local_laundry_service_outlined = IconData(0xf180, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_library</i> — material icon named "local library". + static const IconData local_library = IconData(0xe399, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_library</i> — material icon named "local library" (sharp). + static const IconData local_library_sharp = IconData(0xea93, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_library</i> — material icon named "local library" (round). + static const IconData local_library_rounded = IconData(0xf872, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_library</i> — material icon named "local library" (outlined). + static const IconData local_library_outlined = IconData(0xf181, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_mall</i> — material icon named "local mall". + static const IconData local_mall = IconData(0xe39a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_mall</i> — material icon named "local mall" (sharp). + static const IconData local_mall_sharp = IconData(0xea94, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_mall</i> — material icon named "local mall" (round). + static const IconData local_mall_rounded = IconData(0xf873, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_mall</i> — material icon named "local mall" (outlined). + static const IconData local_mall_outlined = IconData(0xf182, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_movies</i> — material icon named "local movies". + static const IconData local_movies = IconData(0xe39b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_movies</i> — material icon named "local movies" (sharp). + static const IconData local_movies_sharp = IconData(0xea95, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_movies</i> — material icon named "local movies" (round). + static const IconData local_movies_rounded = IconData(0xf874, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_movies</i> — material icon named "local movies" (outlined). + static const IconData local_movies_outlined = IconData(0xf183, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_offer</i> — material icon named "local offer". + static const IconData local_offer = IconData(0xe39c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_offer</i> — material icon named "local offer" (sharp). + static const IconData local_offer_sharp = IconData(0xea96, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_offer</i> — material icon named "local offer" (round). + static const IconData local_offer_rounded = IconData(0xf875, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_offer</i> — material icon named "local offer" (outlined). + static const IconData local_offer_outlined = IconData(0xf184, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_parking</i> — material icon named "local parking". + static const IconData local_parking = IconData(0xe39d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_parking</i> — material icon named "local parking" (sharp). + static const IconData local_parking_sharp = IconData(0xea97, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_parking</i> — material icon named "local parking" (round). + static const IconData local_parking_rounded = IconData(0xf876, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_parking</i> — material icon named "local parking" (outlined). + static const IconData local_parking_outlined = IconData(0xf185, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_pharmacy</i> — material icon named "local pharmacy". + static const IconData local_pharmacy = IconData(0xe39e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_pharmacy</i> — material icon named "local pharmacy" (sharp). + static const IconData local_pharmacy_sharp = IconData(0xea98, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_pharmacy</i> — material icon named "local pharmacy" (round). + static const IconData local_pharmacy_rounded = IconData(0xf877, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_pharmacy</i> — material icon named "local pharmacy" (outlined). + static const IconData local_pharmacy_outlined = IconData(0xf186, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_phone</i> — material icon named "local phone". + static const IconData local_phone = IconData(0xe39f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_phone</i> — material icon named "local phone" (sharp). + static const IconData local_phone_sharp = IconData(0xea99, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_phone</i> — material icon named "local phone" (round). + static const IconData local_phone_rounded = IconData(0xf878, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_phone</i> — material icon named "local phone" (outlined). + static const IconData local_phone_outlined = IconData(0xf187, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_pizza</i> — material icon named "local pizza". + static const IconData local_pizza = IconData(0xe3a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_pizza</i> — material icon named "local pizza" (sharp). + static const IconData local_pizza_sharp = IconData(0xea9a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_pizza</i> — material icon named "local pizza" (round). + static const IconData local_pizza_rounded = IconData(0xf879, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_pizza</i> — material icon named "local pizza" (outlined). + static const IconData local_pizza_outlined = IconData(0xf188, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_play</i> — material icon named "local play". + static const IconData local_play = IconData(0xe3a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_play</i> — material icon named "local play" (sharp). + static const IconData local_play_sharp = IconData(0xea9b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_play</i> — material icon named "local play" (round). + static const IconData local_play_rounded = IconData(0xf87a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_play</i> — material icon named "local play" (outlined). + static const IconData local_play_outlined = IconData(0xf189, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_police</i> — material icon named "local police". + static const IconData local_police = IconData(0xe3a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_police</i> — material icon named "local police" (sharp). + static const IconData local_police_sharp = IconData(0xea9c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_police</i> — material icon named "local police" (round). + static const IconData local_police_rounded = IconData(0xf87b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_police</i> — material icon named "local police" (outlined). + static const IconData local_police_outlined = IconData(0xf18a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_post_office</i> — material icon named "local post office". + static const IconData local_post_office = IconData(0xe3a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_post_office</i> — material icon named "local post office" (sharp). + static const IconData local_post_office_sharp = IconData(0xea9d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_post_office</i> — material icon named "local post office" (round). + static const IconData local_post_office_rounded = IconData(0xf87c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_post_office</i> — material icon named "local post office" (outlined). + static const IconData local_post_office_outlined = IconData(0xf18b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_print_shop</i> — material icon named "local print shop". + static const IconData local_print_shop = IconData(0xe3a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_print_shop</i> — material icon named "local print shop" (sharp). + static const IconData local_print_shop_sharp = IconData(0xea9e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_print_shop</i> — material icon named "local print shop" (round). + static const IconData local_print_shop_rounded = IconData(0xf87d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_print_shop</i> — material icon named "local print shop" (outlined). + static const IconData local_print_shop_outlined = IconData(0xf18c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_printshop</i> — material icon named "local printshop". + static const IconData local_printshop = IconData(0xe3a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_printshop</i> — material icon named "local printshop" (sharp). + static const IconData local_printshop_sharp = IconData(0xea9e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_printshop</i> — material icon named "local printshop" (round). + static const IconData local_printshop_rounded = IconData(0xf87d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_printshop</i> — material icon named "local printshop" (outlined). + static const IconData local_printshop_outlined = IconData(0xf18c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_restaurant</i> — material icon named "local restaurant". + static const IconData local_restaurant = IconData(0xe390, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_restaurant</i> — material icon named "local restaurant" (sharp). + static const IconData local_restaurant_sharp = IconData(0xea8a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_restaurant</i> — material icon named "local restaurant" (round). + static const IconData local_restaurant_rounded = IconData(0xf869, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_restaurant</i> — material icon named "local restaurant" (outlined). + static const IconData local_restaurant_outlined = IconData(0xf178, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_see</i> — material icon named "local see". + static const IconData local_see = IconData(0xe3a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_see</i> — material icon named "local see" (sharp). + static const IconData local_see_sharp = IconData(0xea9f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_see</i> — material icon named "local see" (round). + static const IconData local_see_rounded = IconData(0xf87e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_see</i> — material icon named "local see" (outlined). + static const IconData local_see_outlined = IconData(0xf18d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_shipping</i> — material icon named "local shipping". + static const IconData local_shipping = IconData(0xe3a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_shipping</i> — material icon named "local shipping" (sharp). + static const IconData local_shipping_sharp = IconData(0xeaa0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_shipping</i> — material icon named "local shipping" (round). + static const IconData local_shipping_rounded = IconData(0xf87f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_shipping</i> — material icon named "local shipping" (outlined). + static const IconData local_shipping_outlined = IconData(0xf18e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">local_taxi</i> — material icon named "local taxi". + static const IconData local_taxi = IconData(0xe3a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">local_taxi</i> — material icon named "local taxi" (sharp). + static const IconData local_taxi_sharp = IconData(0xeaa1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">local_taxi</i> — material icon named "local taxi" (round). + static const IconData local_taxi_rounded = IconData(0xf880, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">local_taxi</i> — material icon named "local taxi" (outlined). + static const IconData local_taxi_outlined = IconData(0xf18f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">location_city</i> — material icon named "location city". + static const IconData location_city = IconData(0xe3a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">location_city</i> — material icon named "location city" (sharp). + static const IconData location_city_sharp = IconData(0xeaa2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">location_city</i> — material icon named "location city" (round). + static const IconData location_city_rounded = IconData(0xf881, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">location_city</i> — material icon named "location city" (outlined). + static const IconData location_city_outlined = IconData(0xf190, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">location_disabled</i> — material icon named "location disabled". + static const IconData location_disabled = IconData(0xe3a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">location_disabled</i> — material icon named "location disabled" (sharp). + static const IconData location_disabled_sharp = IconData(0xeaa3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">location_disabled</i> — material icon named "location disabled" (round). + static const IconData location_disabled_rounded = IconData(0xf882, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">location_disabled</i> — material icon named "location disabled" (outlined). + static const IconData location_disabled_outlined = IconData(0xf191, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">location_history</i> — material icon named "location history". + static const IconData location_history = IconData(0xe498, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">location_history</i> — material icon named "location history" (sharp). + static const IconData location_history_sharp = IconData(0xeb8f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">location_history</i> — material icon named "location history" (round). + static const IconData location_history_rounded = IconData(0xf006e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">location_history</i> — material icon named "location history" (outlined). + static const IconData location_history_outlined = IconData(0xf27d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">location_off</i> — material icon named "location off". + static const IconData location_off = IconData(0xe3aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">location_off</i> — material icon named "location off" (sharp). + static const IconData location_off_sharp = IconData(0xeaa4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">location_off</i> — material icon named "location off" (round). + static const IconData location_off_rounded = IconData(0xf883, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">location_off</i> — material icon named "location off" (outlined). + static const IconData location_off_outlined = IconData(0xf192, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">location_on</i> — material icon named "location on". + static const IconData location_on = IconData(0xe3ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">location_on</i> — material icon named "location on" (sharp). + static const IconData location_on_sharp = IconData(0xeaa5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">location_on</i> — material icon named "location on" (round). + static const IconData location_on_rounded = IconData(0xf884, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">location_on</i> — material icon named "location on" (outlined). + static const IconData location_on_outlined = IconData(0xf193, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">location_pin</i> — material icon named "location pin". + static const IconData location_pin = IconData(0xe3ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">location_searching</i> — material icon named "location searching". + static const IconData location_searching = IconData(0xe3ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">location_searching</i> — material icon named "location searching" (sharp). + static const IconData location_searching_sharp = IconData(0xeaa6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">location_searching</i> — material icon named "location searching" (round). + static const IconData location_searching_rounded = IconData(0xf885, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">location_searching</i> — material icon named "location searching" (outlined). + static const IconData location_searching_outlined = IconData(0xf194, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lock</i> — material icon named "lock". + static const IconData lock = IconData(0xe3ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lock</i> — material icon named "lock" (sharp). + static const IconData lock_sharp = IconData(0xeaaa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lock</i> — material icon named "lock" (round). + static const IconData lock_rounded = IconData(0xf889, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lock</i> — material icon named "lock" (outlined). + static const IconData lock_outlined = IconData(0xf197, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lock_clock</i> — material icon named "lock clock". + static const IconData lock_clock = IconData(0xe3af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lock_clock</i> — material icon named "lock clock" (sharp). + static const IconData lock_clock_sharp = IconData(0xeaa7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lock_clock</i> — material icon named "lock clock" (round). + static const IconData lock_clock_rounded = IconData(0xf886, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lock_clock</i> — material icon named "lock clock" (outlined). + static const IconData lock_clock_outlined = IconData(0xf195, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lock_open</i> — material icon named "lock open". + static const IconData lock_open = IconData(0xe3b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lock_open</i> — material icon named "lock open" (sharp). + static const IconData lock_open_sharp = IconData(0xeaa8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lock_open</i> — material icon named "lock open" (round). + static const IconData lock_open_rounded = IconData(0xf887, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lock_open</i> — material icon named "lock open" (outlined). + static const IconData lock_open_outlined = IconData(0xf196, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lock_outline</i> — material icon named "lock outline". + static const IconData lock_outline = IconData(0xe3b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lock_outline</i> — material icon named "lock outline" (sharp). + static const IconData lock_outline_sharp = IconData(0xeaa9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lock_outline</i> — material icon named "lock outline" (round). + static const IconData lock_outline_rounded = IconData(0xf888, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lock_person</i> — material icon named "lock person". + static const IconData lock_person = IconData(0xf07a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lock_person</i> — material icon named "lock person" (sharp). + static const IconData lock_person_sharp = IconData(0xf0750, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lock_person</i> — material icon named "lock person" (round). + static const IconData lock_person_rounded = IconData(0xf0800, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lock_person</i> — material icon named "lock person" (outlined). + static const IconData lock_person_outlined = IconData(0xf06f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lock_reset</i> — material icon named "lock reset". + static const IconData lock_reset = IconData(0xf0536, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lock_reset</i> — material icon named "lock reset" (sharp). + static const IconData lock_reset_sharp = IconData(0xf0440, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lock_reset</i> — material icon named "lock reset" (round). + static const IconData lock_reset_rounded = IconData(0xf034d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lock_reset</i> — material icon named "lock reset" (outlined). + static const IconData lock_reset_outlined = IconData(0xf062e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">login</i> — material icon named "login". + static const IconData login = IconData(0xe3b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">login</i> — material icon named "login" (sharp). + static const IconData login_sharp = IconData(0xeaab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">login</i> — material icon named "login" (round). + static const IconData login_rounded = IconData(0xf88a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">login</i> — material icon named "login" (outlined). + static const IconData login_outlined = IconData(0xf198, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">logo_dev</i> — material icon named "logo dev". + static const IconData logo_dev = IconData(0xf0537, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">logo_dev</i> — material icon named "logo dev" (sharp). + static const IconData logo_dev_sharp = IconData(0xf0441, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">logo_dev</i> — material icon named "logo dev" (round). + static const IconData logo_dev_rounded = IconData(0xf034e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">logo_dev</i> — material icon named "logo dev" (outlined). + static const IconData logo_dev_outlined = IconData(0xf062f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">logout</i> — material icon named "logout". + static const IconData logout = IconData(0xe3b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">logout</i> — material icon named "logout" (sharp). + static const IconData logout_sharp = IconData(0xeaac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">logout</i> — material icon named "logout" (round). + static const IconData logout_rounded = IconData(0xf88b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">logout</i> — material icon named "logout" (outlined). + static const IconData logout_outlined = IconData(0xf199, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">looks</i> — material icon named "looks". + static const IconData looks = IconData(0xe3b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">looks</i> — material icon named "looks" (sharp). + static const IconData looks_sharp = IconData(0xeab2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">looks</i> — material icon named "looks" (round). + static const IconData looks_rounded = IconData(0xf891, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">looks</i> — material icon named "looks" (outlined). + static const IconData looks_outlined = IconData(0xf19f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">looks_3</i> — material icon named "looks 3". + static const IconData looks_3 = IconData(0xe3b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">looks_3</i> — material icon named "looks 3" (sharp). + static const IconData looks_3_sharp = IconData(0xeaad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">looks_3</i> — material icon named "looks 3" (round). + static const IconData looks_3_rounded = IconData(0xf88c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">looks_3</i> — material icon named "looks 3" (outlined). + static const IconData looks_3_outlined = IconData(0xf19a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">looks_4</i> — material icon named "looks 4". + static const IconData looks_4 = IconData(0xe3b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">looks_4</i> — material icon named "looks 4" (sharp). + static const IconData looks_4_sharp = IconData(0xeaae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">looks_4</i> — material icon named "looks 4" (round). + static const IconData looks_4_rounded = IconData(0xf88d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">looks_4</i> — material icon named "looks 4" (outlined). + static const IconData looks_4_outlined = IconData(0xf19b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">looks_5</i> — material icon named "looks 5". + static const IconData looks_5 = IconData(0xe3b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">looks_5</i> — material icon named "looks 5" (sharp). + static const IconData looks_5_sharp = IconData(0xeaaf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">looks_5</i> — material icon named "looks 5" (round). + static const IconData looks_5_rounded = IconData(0xf88e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">looks_5</i> — material icon named "looks 5" (outlined). + static const IconData looks_5_outlined = IconData(0xf19c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">looks_6</i> — material icon named "looks 6". + static const IconData looks_6 = IconData(0xe3b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">looks_6</i> — material icon named "looks 6" (sharp). + static const IconData looks_6_sharp = IconData(0xeab0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">looks_6</i> — material icon named "looks 6" (round). + static const IconData looks_6_rounded = IconData(0xf88f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">looks_6</i> — material icon named "looks 6" (outlined). + static const IconData looks_6_outlined = IconData(0xf19d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">looks_one</i> — material icon named "looks one". + static const IconData looks_one = IconData(0xe3b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">looks_one</i> — material icon named "looks one" (sharp). + static const IconData looks_one_sharp = IconData(0xeab1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">looks_one</i> — material icon named "looks one" (round). + static const IconData looks_one_rounded = IconData(0xf890, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">looks_one</i> — material icon named "looks one" (outlined). + static const IconData looks_one_outlined = IconData(0xf19e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">looks_two</i> — material icon named "looks two". + static const IconData looks_two = IconData(0xe3ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">looks_two</i> — material icon named "looks two" (sharp). + static const IconData looks_two_sharp = IconData(0xeab3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">looks_two</i> — material icon named "looks two" (round). + static const IconData looks_two_rounded = IconData(0xf892, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">looks_two</i> — material icon named "looks two" (outlined). + static const IconData looks_two_outlined = IconData(0xf1a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">loop</i> — material icon named "loop". + static const IconData loop = IconData(0xe3bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">loop</i> — material icon named "loop" (sharp). + static const IconData loop_sharp = IconData(0xeab4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">loop</i> — material icon named "loop" (round). + static const IconData loop_rounded = IconData(0xf893, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">loop</i> — material icon named "loop" (outlined). + static const IconData loop_outlined = IconData(0xf1a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">loupe</i> — material icon named "loupe". + static const IconData loupe = IconData(0xe3bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">loupe</i> — material icon named "loupe" (sharp). + static const IconData loupe_sharp = IconData(0xeab5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">loupe</i> — material icon named "loupe" (round). + static const IconData loupe_rounded = IconData(0xf894, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">loupe</i> — material icon named "loupe" (outlined). + static const IconData loupe_outlined = IconData(0xf1a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">low_priority</i> — material icon named "low priority". + static const IconData low_priority = IconData(0xe3bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">low_priority</i> — material icon named "low priority" (sharp). + static const IconData low_priority_sharp = IconData(0xeab6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">low_priority</i> — material icon named "low priority" (round). + static const IconData low_priority_rounded = IconData(0xf895, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">low_priority</i> — material icon named "low priority" (outlined). + static const IconData low_priority_outlined = IconData(0xf1a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">loyalty</i> — material icon named "loyalty". + static const IconData loyalty = IconData(0xe3be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">loyalty</i> — material icon named "loyalty" (sharp). + static const IconData loyalty_sharp = IconData(0xeab7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">loyalty</i> — material icon named "loyalty" (round). + static const IconData loyalty_rounded = IconData(0xf896, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">loyalty</i> — material icon named "loyalty" (outlined). + static const IconData loyalty_outlined = IconData(0xf1a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lte_mobiledata</i> — material icon named "lte mobiledata". + static const IconData lte_mobiledata = IconData(0xe3bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lte_mobiledata</i> — material icon named "lte mobiledata" (sharp). + static const IconData lte_mobiledata_sharp = IconData(0xeab8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lte_mobiledata</i> — material icon named "lte mobiledata" (round). + static const IconData lte_mobiledata_rounded = IconData(0xf897, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lte_mobiledata</i> — material icon named "lte mobiledata" (outlined). + static const IconData lte_mobiledata_outlined = IconData(0xf1a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lte_plus_mobiledata</i> — material icon named "lte plus mobiledata". + static const IconData lte_plus_mobiledata = IconData(0xe3c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lte_plus_mobiledata</i> — material icon named "lte plus mobiledata" (sharp). + static const IconData lte_plus_mobiledata_sharp = IconData(0xeab9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lte_plus_mobiledata</i> — material icon named "lte plus mobiledata" (round). + static const IconData lte_plus_mobiledata_rounded = IconData(0xf898, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lte_plus_mobiledata</i> — material icon named "lte plus mobiledata" (outlined). + static const IconData lte_plus_mobiledata_outlined = IconData(0xf1a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">luggage</i> — material icon named "luggage". + static const IconData luggage = IconData(0xe3c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">luggage</i> — material icon named "luggage" (sharp). + static const IconData luggage_sharp = IconData(0xeaba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">luggage</i> — material icon named "luggage" (round). + static const IconData luggage_rounded = IconData(0xf899, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">luggage</i> — material icon named "luggage" (outlined). + static const IconData luggage_outlined = IconData(0xf1a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lunch_dining</i> — material icon named "lunch dining". + static const IconData lunch_dining = IconData(0xe3c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lunch_dining</i> — material icon named "lunch dining" (sharp). + static const IconData lunch_dining_sharp = IconData(0xeabb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lunch_dining</i> — material icon named "lunch dining" (round). + static const IconData lunch_dining_rounded = IconData(0xf89a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lunch_dining</i> — material icon named "lunch dining" (outlined). + static const IconData lunch_dining_outlined = IconData(0xf1a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">lyrics</i> — material icon named "lyrics". + static const IconData lyrics = IconData(0xf07a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">lyrics</i> — material icon named "lyrics" (sharp). + static const IconData lyrics_sharp = IconData(0xf0751, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">lyrics</i> — material icon named "lyrics" (round). + static const IconData lyrics_rounded = IconData(0xf0801, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">lyrics</i> — material icon named "lyrics" (outlined). + static const IconData lyrics_outlined = IconData(0xf06f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">macro_off</i> — material icon named "macro off". + static const IconData macro_off = IconData(0xf086b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">macro_off</i> — material icon named "macro off" (sharp). + static const IconData macro_off_sharp = IconData(0xf0843, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">macro_off</i> — material icon named "macro off" (round). + static const IconData macro_off_rounded = IconData(0xf088c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">macro_off</i> — material icon named "macro off" (outlined). + static const IconData macro_off_outlined = IconData(0xf08aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mail</i> — material icon named "mail". + static const IconData mail = IconData(0xe3c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mail</i> — material icon named "mail" (sharp). + static const IconData mail_sharp = IconData(0xeabd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mail</i> — material icon named "mail" (round). + static const IconData mail_rounded = IconData(0xf89c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mail</i> — material icon named "mail" (outlined). + static const IconData mail_outlined = IconData(0xf1aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mail_lock</i> — material icon named "mail lock". + static const IconData mail_lock = IconData(0xf07aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mail_lock</i> — material icon named "mail lock" (sharp). + static const IconData mail_lock_sharp = IconData(0xf0752, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mail_lock</i> — material icon named "mail lock" (round). + static const IconData mail_lock_rounded = IconData(0xf0802, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mail_lock</i> — material icon named "mail lock" (outlined). + static const IconData mail_lock_outlined = IconData(0xf06fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mail_outline</i> — material icon named "mail outline". + static const IconData mail_outline = IconData(0xe3c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mail_outline</i> — material icon named "mail outline" (sharp). + static const IconData mail_outline_sharp = IconData(0xeabc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mail_outline</i> — material icon named "mail outline" (round). + static const IconData mail_outline_rounded = IconData(0xf89b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mail_outline</i> — material icon named "mail outline" (outlined). + static const IconData mail_outline_outlined = IconData(0xf1a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">male</i> — material icon named "male". + static const IconData male = IconData(0xe3c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">male</i> — material icon named "male" (sharp). + static const IconData male_sharp = IconData(0xeabe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">male</i> — material icon named "male" (round). + static const IconData male_rounded = IconData(0xf89d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">male</i> — material icon named "male" (outlined). + static const IconData male_outlined = IconData(0xf1ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">man</i> — material icon named "man". + static const IconData man = IconData(0xf0538, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">man</i> — material icon named "man" (sharp). + static const IconData man_sharp = IconData(0xf0442, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">man</i> — material icon named "man" (round). + static const IconData man_rounded = IconData(0xf034f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">man</i> — material icon named "man" (outlined). + static const IconData man_outlined = IconData(0xf0630, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">man_2</i> — material icon named "man 2". + static const IconData man_2 = IconData(0xf086c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">man_2</i> — material icon named "man 2" (sharp). + static const IconData man_2_sharp = IconData(0xf0844, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">man_2</i> — material icon named "man 2" (round). + static const IconData man_2_rounded = IconData(0xf088d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">man_2</i> — material icon named "man 2" (outlined). + static const IconData man_2_outlined = IconData(0xf08ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">man_3</i> — material icon named "man 3". + static const IconData man_3 = IconData(0xf086d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">man_3</i> — material icon named "man 3" (sharp). + static const IconData man_3_sharp = IconData(0xf0845, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">man_3</i> — material icon named "man 3" (round). + static const IconData man_3_rounded = IconData(0xf088e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">man_3</i> — material icon named "man 3" (outlined). + static const IconData man_3_outlined = IconData(0xf08ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">man_4</i> — material icon named "man 4". + static const IconData man_4 = IconData(0xf086e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">man_4</i> — material icon named "man 4" (sharp). + static const IconData man_4_sharp = IconData(0xf0846, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">man_4</i> — material icon named "man 4" (round). + static const IconData man_4_rounded = IconData(0xf088f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">man_4</i> — material icon named "man 4" (outlined). + static const IconData man_4_outlined = IconData(0xf08ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">manage_accounts</i> — material icon named "manage accounts". + static const IconData manage_accounts = IconData(0xe3c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">manage_accounts</i> — material icon named "manage accounts" (sharp). + static const IconData manage_accounts_sharp = IconData(0xeabf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">manage_accounts</i> — material icon named "manage accounts" (round). + static const IconData manage_accounts_rounded = IconData(0xf89e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">manage_accounts</i> — material icon named "manage accounts" (outlined). + static const IconData manage_accounts_outlined = IconData(0xf1ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">manage_history</i> — material icon named "manage history". + static const IconData manage_history = IconData(0xf07ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">manage_history</i> — material icon named "manage history" (sharp). + static const IconData manage_history_sharp = IconData(0xf0753, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">manage_history</i> — material icon named "manage history" (round). + static const IconData manage_history_rounded = IconData(0xf0803, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">manage_history</i> — material icon named "manage history" (outlined). + static const IconData manage_history_outlined = IconData(0xf06fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">manage_search</i> — material icon named "manage search". + static const IconData manage_search = IconData(0xe3c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">manage_search</i> — material icon named "manage search" (sharp). + static const IconData manage_search_sharp = IconData(0xeac0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">manage_search</i> — material icon named "manage search" (round). + static const IconData manage_search_rounded = IconData(0xf89f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">manage_search</i> — material icon named "manage search" (outlined). + static const IconData manage_search_outlined = IconData(0xf1ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">map</i> — material icon named "map". + static const IconData map = IconData(0xe3c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">map</i> — material icon named "map" (sharp). + static const IconData map_sharp = IconData(0xeac1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">map</i> — material icon named "map" (round). + static const IconData map_rounded = IconData(0xf8a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">map</i> — material icon named "map" (outlined). + static const IconData map_outlined = IconData(0xf1ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">maps_home_work</i> — material icon named "maps home work". + static const IconData maps_home_work = IconData(0xe3c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">maps_home_work</i> — material icon named "maps home work" (sharp). + static const IconData maps_home_work_sharp = IconData(0xeac2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">maps_home_work</i> — material icon named "maps home work" (round). + static const IconData maps_home_work_rounded = IconData(0xf8a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">maps_home_work</i> — material icon named "maps home work" (outlined). + static const IconData maps_home_work_outlined = IconData(0xf1af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">maps_ugc</i> — material icon named "maps ugc". + static const IconData maps_ugc = IconData(0xe3ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">maps_ugc</i> — material icon named "maps ugc" (sharp). + static const IconData maps_ugc_sharp = IconData(0xeac3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">maps_ugc</i> — material icon named "maps ugc" (round). + static const IconData maps_ugc_rounded = IconData(0xf8a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">maps_ugc</i> — material icon named "maps ugc" (outlined). + static const IconData maps_ugc_outlined = IconData(0xf1b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">margin</i> — material icon named "margin". + static const IconData margin = IconData(0xe3cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">margin</i> — material icon named "margin" (sharp). + static const IconData margin_sharp = IconData(0xeac4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">margin</i> — material icon named "margin" (round). + static const IconData margin_rounded = IconData(0xf8a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">margin</i> — material icon named "margin" (outlined). + static const IconData margin_outlined = IconData(0xf1b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mark_as_unread</i> — material icon named "mark as unread". + static const IconData mark_as_unread = IconData(0xe3cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mark_as_unread</i> — material icon named "mark as unread" (sharp). + static const IconData mark_as_unread_sharp = IconData(0xeac5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mark_as_unread</i> — material icon named "mark as unread" (round). + static const IconData mark_as_unread_rounded = IconData(0xf8a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mark_as_unread</i> — material icon named "mark as unread" (outlined). + static const IconData mark_as_unread_outlined = IconData(0xf1b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mark_chat_read</i> — material icon named "mark chat read". + static const IconData mark_chat_read = IconData(0xe3cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mark_chat_read</i> — material icon named "mark chat read" (sharp). + static const IconData mark_chat_read_sharp = IconData(0xeac6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mark_chat_read</i> — material icon named "mark chat read" (round). + static const IconData mark_chat_read_rounded = IconData(0xf8a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mark_chat_read</i> — material icon named "mark chat read" (outlined). + static const IconData mark_chat_read_outlined = IconData(0xf1b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mark_chat_unread</i> — material icon named "mark chat unread". + static const IconData mark_chat_unread = IconData(0xe3ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mark_chat_unread</i> — material icon named "mark chat unread" (sharp). + static const IconData mark_chat_unread_sharp = IconData(0xeac7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mark_chat_unread</i> — material icon named "mark chat unread" (round). + static const IconData mark_chat_unread_rounded = IconData(0xf8a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mark_chat_unread</i> — material icon named "mark chat unread" (outlined). + static const IconData mark_chat_unread_outlined = IconData(0xf1b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mark_email_read</i> — material icon named "mark email read". + static const IconData mark_email_read = IconData(0xe3cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mark_email_read</i> — material icon named "mark email read" (sharp). + static const IconData mark_email_read_sharp = IconData(0xeac8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mark_email_read</i> — material icon named "mark email read" (round). + static const IconData mark_email_read_rounded = IconData(0xf8a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mark_email_read</i> — material icon named "mark email read" (outlined). + static const IconData mark_email_read_outlined = IconData(0xf1b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mark_email_unread</i> — material icon named "mark email unread". + static const IconData mark_email_unread = IconData(0xe3d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mark_email_unread</i> — material icon named "mark email unread" (sharp). + static const IconData mark_email_unread_sharp = IconData(0xeac9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mark_email_unread</i> — material icon named "mark email unread" (round). + static const IconData mark_email_unread_rounded = IconData(0xf8a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mark_email_unread</i> — material icon named "mark email unread" (outlined). + static const IconData mark_email_unread_outlined = IconData(0xf1b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mark_unread_chat_alt</i> — material icon named "mark unread chat alt". + static const IconData mark_unread_chat_alt = IconData(0xf0539, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mark_unread_chat_alt</i> — material icon named "mark unread chat alt" (sharp). + static const IconData mark_unread_chat_alt_sharp = IconData(0xf0443, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mark_unread_chat_alt</i> — material icon named "mark unread chat alt" (round). + static const IconData mark_unread_chat_alt_rounded = IconData(0xf0350, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mark_unread_chat_alt</i> — material icon named "mark unread chat alt" (outlined). + static const IconData mark_unread_chat_alt_outlined = IconData(0xf0631, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">markunread</i> — material icon named "markunread". + static const IconData markunread = IconData(0xe3d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">markunread</i> — material icon named "markunread" (sharp). + static const IconData markunread_sharp = IconData(0xeacb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">markunread</i> — material icon named "markunread" (round). + static const IconData markunread_rounded = IconData(0xf8aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">markunread</i> — material icon named "markunread" (outlined). + static const IconData markunread_outlined = IconData(0xf1b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">markunread_mailbox</i> — material icon named "markunread mailbox". + static const IconData markunread_mailbox = IconData(0xe3d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">markunread_mailbox</i> — material icon named "markunread mailbox" (sharp). + static const IconData markunread_mailbox_sharp = IconData(0xeaca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">markunread_mailbox</i> — material icon named "markunread mailbox" (round). + static const IconData markunread_mailbox_rounded = IconData(0xf8a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">markunread_mailbox</i> — material icon named "markunread mailbox" (outlined). + static const IconData markunread_mailbox_outlined = IconData(0xf1b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">masks</i> — material icon named "masks". + static const IconData masks = IconData(0xe3d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">masks</i> — material icon named "masks" (sharp). + static const IconData masks_sharp = IconData(0xeacc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">masks</i> — material icon named "masks" (round). + static const IconData masks_rounded = IconData(0xf8ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">masks</i> — material icon named "masks" (outlined). + static const IconData masks_outlined = IconData(0xf1b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">maximize</i> — material icon named "maximize". + static const IconData maximize = IconData(0xe3d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">maximize</i> — material icon named "maximize" (sharp). + static const IconData maximize_sharp = IconData(0xeacd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">maximize</i> — material icon named "maximize" (round). + static const IconData maximize_rounded = IconData(0xf8ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">maximize</i> — material icon named "maximize" (outlined). + static const IconData maximize_outlined = IconData(0xf1ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">media_bluetooth_off</i> — material icon named "media bluetooth off". + static const IconData media_bluetooth_off = IconData(0xe3d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">media_bluetooth_off</i> — material icon named "media bluetooth off" (sharp). + static const IconData media_bluetooth_off_sharp = IconData(0xeace, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">media_bluetooth_off</i> — material icon named "media bluetooth off" (round). + static const IconData media_bluetooth_off_rounded = IconData(0xf8ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">media_bluetooth_off</i> — material icon named "media bluetooth off" (outlined). + static const IconData media_bluetooth_off_outlined = IconData(0xf1bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">media_bluetooth_on</i> — material icon named "media bluetooth on". + static const IconData media_bluetooth_on = IconData(0xe3d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">media_bluetooth_on</i> — material icon named "media bluetooth on" (sharp). + static const IconData media_bluetooth_on_sharp = IconData(0xeacf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">media_bluetooth_on</i> — material icon named "media bluetooth on" (round). + static const IconData media_bluetooth_on_rounded = IconData(0xf8ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">media_bluetooth_on</i> — material icon named "media bluetooth on" (outlined). + static const IconData media_bluetooth_on_outlined = IconData(0xf1bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mediation</i> — material icon named "mediation". + static const IconData mediation = IconData(0xe3d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mediation</i> — material icon named "mediation" (sharp). + static const IconData mediation_sharp = IconData(0xead0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mediation</i> — material icon named "mediation" (round). + static const IconData mediation_rounded = IconData(0xf8af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mediation</i> — material icon named "mediation" (outlined). + static const IconData mediation_outlined = IconData(0xf1bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">medical_information</i> — material icon named "medical information". + static const IconData medical_information = IconData(0xf07ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">medical_information</i> — material icon named "medical information" (sharp). + static const IconData medical_information_sharp = IconData(0xf0754, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">medical_information</i> — material icon named "medical information" (round). + static const IconData medical_information_rounded = IconData(0xf0804, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">medical_information</i> — material icon named "medical information" (outlined). + static const IconData medical_information_outlined = IconData(0xf06fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">medical_services</i> — material icon named "medical services". + static const IconData medical_services = IconData(0xe3d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">medical_services</i> — material icon named "medical services" (sharp). + static const IconData medical_services_sharp = IconData(0xead1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">medical_services</i> — material icon named "medical services" (round). + static const IconData medical_services_rounded = IconData(0xf8b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">medical_services</i> — material icon named "medical services" (outlined). + static const IconData medical_services_outlined = IconData(0xf1be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">medication</i> — material icon named "medication". + static const IconData medication = IconData(0xe3d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">medication</i> — material icon named "medication" (sharp). + static const IconData medication_sharp = IconData(0xead2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">medication</i> — material icon named "medication" (round). + static const IconData medication_rounded = IconData(0xf8b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">medication</i> — material icon named "medication" (outlined). + static const IconData medication_outlined = IconData(0xf1bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">medication_liquid</i> — material icon named "medication liquid". + static const IconData medication_liquid = IconData(0xf053a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">medication_liquid</i> — material icon named "medication liquid" (sharp). + static const IconData medication_liquid_sharp = IconData(0xf0444, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">medication_liquid</i> — material icon named "medication liquid" (round). + static const IconData medication_liquid_rounded = IconData(0xf0351, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">medication_liquid</i> — material icon named "medication liquid" (outlined). + static const IconData medication_liquid_outlined = IconData(0xf0632, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">meeting_room</i> — material icon named "meeting room". + static const IconData meeting_room = IconData(0xe3da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">meeting_room</i> — material icon named "meeting room" (sharp). + static const IconData meeting_room_sharp = IconData(0xead3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">meeting_room</i> — material icon named "meeting room" (round). + static const IconData meeting_room_rounded = IconData(0xf8b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">meeting_room</i> — material icon named "meeting room" (outlined). + static const IconData meeting_room_outlined = IconData(0xf1c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">memory</i> — material icon named "memory". + static const IconData memory = IconData(0xe3db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">memory</i> — material icon named "memory" (sharp). + static const IconData memory_sharp = IconData(0xead4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">memory</i> — material icon named "memory" (round). + static const IconData memory_rounded = IconData(0xf8b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">memory</i> — material icon named "memory" (outlined). + static const IconData memory_outlined = IconData(0xf1c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">menu</i> — material icon named "menu". + static const IconData menu = IconData(0xe3dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">menu</i> — material icon named "menu" (sharp). + static const IconData menu_sharp = IconData(0xead7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">menu</i> — material icon named "menu" (round). + static const IconData menu_rounded = IconData(0xf8b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">menu</i> — material icon named "menu" (outlined). + static const IconData menu_outlined = IconData(0xf1c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">menu_book</i> — material icon named "menu book". + static const IconData menu_book = IconData(0xe3dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">menu_book</i> — material icon named "menu book" (sharp). + static const IconData menu_book_sharp = IconData(0xead5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">menu_book</i> — material icon named "menu book" (round). + static const IconData menu_book_rounded = IconData(0xf8b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">menu_book</i> — material icon named "menu book" (outlined). + static const IconData menu_book_outlined = IconData(0xf1c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">menu_open</i> — material icon named "menu open". + static const IconData menu_open = IconData(0xe3de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">menu_open</i> — material icon named "menu open" (sharp). + static const IconData menu_open_sharp = IconData(0xead6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">menu_open</i> — material icon named "menu open" (round). + static const IconData menu_open_rounded = IconData(0xf8b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">menu_open</i> — material icon named "menu open" (outlined). + static const IconData menu_open_outlined = IconData(0xf1c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">merge</i> — material icon named "merge". + static const IconData merge = IconData(0xf053b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">merge</i> — material icon named "merge" (sharp). + static const IconData merge_sharp = IconData(0xf0445, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">merge</i> — material icon named "merge" (round). + static const IconData merge_rounded = IconData(0xf0352, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">merge</i> — material icon named "merge" (outlined). + static const IconData merge_outlined = IconData(0xf0633, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">merge_type</i> — material icon named "merge type". + static const IconData merge_type = IconData(0xe3df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">merge_type</i> — material icon named "merge type" (sharp). + static const IconData merge_type_sharp = IconData(0xead8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">merge_type</i> — material icon named "merge type" (round). + static const IconData merge_type_rounded = IconData(0xf8b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">merge_type</i> — material icon named "merge type" (outlined). + static const IconData merge_type_outlined = IconData(0xf1c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">message</i> — material icon named "message". + static const IconData message = IconData(0xe3e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">message</i> — material icon named "message" (sharp). + static const IconData message_sharp = IconData(0xead9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">message</i> — material icon named "message" (round). + static const IconData message_rounded = IconData(0xf8b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">message</i> — material icon named "message" (outlined). + static const IconData message_outlined = IconData(0xf1c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">messenger</i> — material icon named "messenger". + static const IconData messenger = IconData(0xe154, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">messenger</i> — material icon named "messenger" (sharp). + static const IconData messenger_sharp = IconData(0xe851, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">messenger</i> — material icon named "messenger" (round). + static const IconData messenger_rounded = IconData(0xf630, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">messenger</i> — material icon named "messenger" (outlined). + static const IconData messenger_outlined = IconData(0xef43, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">messenger_outline</i> — material icon named "messenger outline". + static const IconData messenger_outline = IconData(0xe155, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">messenger_outline</i> — material icon named "messenger outline" (sharp). + static const IconData messenger_outline_sharp = IconData(0xe850, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">messenger_outline</i> — material icon named "messenger outline" (round). + static const IconData messenger_outline_rounded = IconData(0xf62f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">messenger_outline</i> — material icon named "messenger outline" (outlined). + static const IconData messenger_outline_outlined = IconData(0xef42, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mic</i> — material icon named "mic". + static const IconData mic = IconData(0xe3e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mic</i> — material icon named "mic" (sharp). + static const IconData mic_sharp = IconData(0xeade, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mic</i> — material icon named "mic" (round). + static const IconData mic_rounded = IconData(0xf8bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mic</i> — material icon named "mic" (outlined). + static const IconData mic_outlined = IconData(0xf1cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mic_external_off</i> — material icon named "mic external off". + static const IconData mic_external_off = IconData(0xe3e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mic_external_off</i> — material icon named "mic external off" (sharp). + static const IconData mic_external_off_sharp = IconData(0xeada, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mic_external_off</i> — material icon named "mic external off" (round). + static const IconData mic_external_off_rounded = IconData(0xf8b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mic_external_off</i> — material icon named "mic external off" (outlined). + static const IconData mic_external_off_outlined = IconData(0xf1c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mic_external_on</i> — material icon named "mic external on". + static const IconData mic_external_on = IconData(0xe3e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mic_external_on</i> — material icon named "mic external on" (sharp). + static const IconData mic_external_on_sharp = IconData(0xeadb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mic_external_on</i> — material icon named "mic external on" (round). + static const IconData mic_external_on_rounded = IconData(0xf8ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mic_external_on</i> — material icon named "mic external on" (outlined). + static const IconData mic_external_on_outlined = IconData(0xf1c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mic_none</i> — material icon named "mic none". + static const IconData mic_none = IconData(0xe3e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mic_none</i> — material icon named "mic none" (sharp). + static const IconData mic_none_sharp = IconData(0xeadc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mic_none</i> — material icon named "mic none" (round). + static const IconData mic_none_rounded = IconData(0xf8bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mic_none</i> — material icon named "mic none" (outlined). + static const IconData mic_none_outlined = IconData(0xf1c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mic_off</i> — material icon named "mic off". + static const IconData mic_off = IconData(0xe3e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mic_off</i> — material icon named "mic off" (sharp). + static const IconData mic_off_sharp = IconData(0xeadd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mic_off</i> — material icon named "mic off" (round). + static const IconData mic_off_rounded = IconData(0xf8bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mic_off</i> — material icon named "mic off" (outlined). + static const IconData mic_off_outlined = IconData(0xf1ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">microwave</i> — material icon named "microwave". + static const IconData microwave = IconData(0xe3e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">microwave</i> — material icon named "microwave" (sharp). + static const IconData microwave_sharp = IconData(0xeadf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">microwave</i> — material icon named "microwave" (round). + static const IconData microwave_rounded = IconData(0xf8be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">microwave</i> — material icon named "microwave" (outlined). + static const IconData microwave_outlined = IconData(0xf1cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">military_tech</i> — material icon named "military tech". + static const IconData military_tech = IconData(0xe3e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">military_tech</i> — material icon named "military tech" (sharp). + static const IconData military_tech_sharp = IconData(0xeae0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">military_tech</i> — material icon named "military tech" (round). + static const IconData military_tech_rounded = IconData(0xf8bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">military_tech</i> — material icon named "military tech" (outlined). + static const IconData military_tech_outlined = IconData(0xf1cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">minimize</i> — material icon named "minimize". + static const IconData minimize = IconData(0xe3e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">minimize</i> — material icon named "minimize" (sharp). + static const IconData minimize_sharp = IconData(0xeae1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">minimize</i> — material icon named "minimize" (round). + static const IconData minimize_rounded = IconData(0xf8c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">minimize</i> — material icon named "minimize" (outlined). + static const IconData minimize_outlined = IconData(0xf1ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">minor_crash</i> — material icon named "minor crash". + static const IconData minor_crash = IconData(0xf07ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">minor_crash</i> — material icon named "minor crash" (sharp). + static const IconData minor_crash_sharp = IconData(0xf0755, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">minor_crash</i> — material icon named "minor crash" (round). + static const IconData minor_crash_rounded = IconData(0xf0805, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">minor_crash</i> — material icon named "minor crash" (outlined). + static const IconData minor_crash_outlined = IconData(0xf06fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">miscellaneous_services</i> — material icon named "miscellaneous services". + static const IconData miscellaneous_services = IconData(0xe3e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">miscellaneous_services</i> — material icon named "miscellaneous services" (sharp). + static const IconData miscellaneous_services_sharp = IconData(0xeae2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">miscellaneous_services</i> — material icon named "miscellaneous services" (round). + static const IconData miscellaneous_services_rounded = IconData(0xf8c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">miscellaneous_services</i> — material icon named "miscellaneous services" (outlined). + static const IconData miscellaneous_services_outlined = IconData(0xf1cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">missed_video_call</i> — material icon named "missed video call". + static const IconData missed_video_call = IconData(0xe3ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">missed_video_call</i> — material icon named "missed video call" (sharp). + static const IconData missed_video_call_sharp = IconData(0xeae3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">missed_video_call</i> — material icon named "missed video call" (round). + static const IconData missed_video_call_rounded = IconData(0xf8c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">missed_video_call</i> — material icon named "missed video call" (outlined). + static const IconData missed_video_call_outlined = IconData(0xf1d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mms</i> — material icon named "mms". + static const IconData mms = IconData(0xe3eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mms</i> — material icon named "mms" (sharp). + static const IconData mms_sharp = IconData(0xeae4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mms</i> — material icon named "mms" (round). + static const IconData mms_rounded = IconData(0xf8c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mms</i> — material icon named "mms" (outlined). + static const IconData mms_outlined = IconData(0xf1d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mobile_friendly</i> — material icon named "mobile friendly". + static const IconData mobile_friendly = IconData(0xe3ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mobile_friendly</i> — material icon named "mobile friendly" (sharp). + static const IconData mobile_friendly_sharp = IconData(0xeae5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mobile_friendly</i> — material icon named "mobile friendly" (round). + static const IconData mobile_friendly_rounded = IconData(0xf8c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mobile_friendly</i> — material icon named "mobile friendly" (outlined). + static const IconData mobile_friendly_outlined = IconData(0xf1d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mobile_off</i> — material icon named "mobile off". + static const IconData mobile_off = IconData(0xe3ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mobile_off</i> — material icon named "mobile off" (sharp). + static const IconData mobile_off_sharp = IconData(0xeae6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mobile_off</i> — material icon named "mobile off" (round). + static const IconData mobile_off_rounded = IconData(0xf8c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mobile_off</i> — material icon named "mobile off" (outlined). + static const IconData mobile_off_outlined = IconData(0xf1d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mobile_screen_share</i> — material icon named "mobile screen share". + static const IconData mobile_screen_share = IconData(0xe3ee, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">mobile_screen_share</i> — material icon named "mobile screen share" (sharp). + static const IconData mobile_screen_share_sharp = IconData(0xeae7, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">mobile_screen_share</i> — material icon named "mobile screen share" (round). + static const IconData mobile_screen_share_rounded = IconData(0xf8c6, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">mobile_screen_share</i> — material icon named "mobile screen share" (outlined). + static const IconData mobile_screen_share_outlined = IconData(0xf1d4, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">mobiledata_off</i> — material icon named "mobiledata off". + static const IconData mobiledata_off = IconData(0xe3ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mobiledata_off</i> — material icon named "mobiledata off" (sharp). + static const IconData mobiledata_off_sharp = IconData(0xeae8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mobiledata_off</i> — material icon named "mobiledata off" (round). + static const IconData mobiledata_off_rounded = IconData(0xf8c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mobiledata_off</i> — material icon named "mobiledata off" (outlined). + static const IconData mobiledata_off_outlined = IconData(0xf1d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mode</i> — material icon named "mode". + static const IconData mode = IconData(0xe3f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mode</i> — material icon named "mode" (sharp). + static const IconData mode_sharp = IconData(0xeaed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mode</i> — material icon named "mode" (round). + static const IconData mode_rounded = IconData(0xf8cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mode</i> — material icon named "mode" (outlined). + static const IconData mode_outlined = IconData(0xf1da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mode_comment</i> — material icon named "mode comment". + static const IconData mode_comment = IconData(0xe3f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mode_comment</i> — material icon named "mode comment" (sharp). + static const IconData mode_comment_sharp = IconData(0xeae9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mode_comment</i> — material icon named "mode comment" (round). + static const IconData mode_comment_rounded = IconData(0xf8c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mode_comment</i> — material icon named "mode comment" (outlined). + static const IconData mode_comment_outlined = IconData(0xf1d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mode_edit</i> — material icon named "mode edit". + static const IconData mode_edit = IconData(0xe3f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mode_edit</i> — material icon named "mode edit" (sharp). + static const IconData mode_edit_sharp = IconData(0xeaeb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mode_edit</i> — material icon named "mode edit" (round). + static const IconData mode_edit_rounded = IconData(0xf8ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mode_edit</i> — material icon named "mode edit" (outlined). + static const IconData mode_edit_outlined = IconData(0xf1d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mode_edit_outline</i> — material icon named "mode edit outline". + static const IconData mode_edit_outline = IconData(0xe3f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mode_edit_outline</i> — material icon named "mode edit outline" (sharp). + static const IconData mode_edit_outline_sharp = IconData(0xeaea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mode_edit_outline</i> — material icon named "mode edit outline" (round). + static const IconData mode_edit_outline_rounded = IconData(0xf8c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mode_edit_outline</i> — material icon named "mode edit outline" (outlined). + static const IconData mode_edit_outline_outlined = IconData(0xf1d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mode_fan_off</i> — material icon named "mode fan off". + static const IconData mode_fan_off = IconData(0xf07ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mode_fan_off</i> — material icon named "mode fan off" (sharp). + static const IconData mode_fan_off_sharp = IconData(0xf0756, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mode_fan_off</i> — material icon named "mode fan off" (round). + static const IconData mode_fan_off_rounded = IconData(0xf0806, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mode_fan_off</i> — material icon named "mode fan off" (outlined). + static const IconData mode_fan_off_outlined = IconData(0xf06fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mode_night</i> — material icon named "mode night". + static const IconData mode_night = IconData(0xe3f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mode_night</i> — material icon named "mode night" (sharp). + static const IconData mode_night_sharp = IconData(0xeaec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mode_night</i> — material icon named "mode night" (round). + static const IconData mode_night_rounded = IconData(0xf8cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mode_night</i> — material icon named "mode night" (outlined). + static const IconData mode_night_outlined = IconData(0xf1d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mode_of_travel</i> — material icon named "mode of travel". + static const IconData mode_of_travel = IconData(0xf053c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mode_of_travel</i> — material icon named "mode of travel" (sharp). + static const IconData mode_of_travel_sharp = IconData(0xf0446, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mode_of_travel</i> — material icon named "mode of travel" (round). + static const IconData mode_of_travel_rounded = IconData(0xf0353, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mode_of_travel</i> — material icon named "mode of travel" (outlined). + static const IconData mode_of_travel_outlined = IconData(0xf0634, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mode_standby</i> — material icon named "mode standby". + static const IconData mode_standby = IconData(0xe3f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mode_standby</i> — material icon named "mode standby" (sharp). + static const IconData mode_standby_sharp = IconData(0xeaee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mode_standby</i> — material icon named "mode standby" (round). + static const IconData mode_standby_rounded = IconData(0xf8cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mode_standby</i> — material icon named "mode standby" (outlined). + static const IconData mode_standby_outlined = IconData(0xf1db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">model_training</i> — material icon named "model training". + static const IconData model_training = IconData(0xe3f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">model_training</i> — material icon named "model training" (sharp). + static const IconData model_training_sharp = IconData(0xeaef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">model_training</i> — material icon named "model training" (round). + static const IconData model_training_rounded = IconData(0xf8ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">model_training</i> — material icon named "model training" (outlined). + static const IconData model_training_outlined = IconData(0xf1dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">monetization_on</i> — material icon named "monetization on". + static const IconData monetization_on = IconData(0xe3f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">monetization_on</i> — material icon named "monetization on" (sharp). + static const IconData monetization_on_sharp = IconData(0xeaf0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">monetization_on</i> — material icon named "monetization on" (round). + static const IconData monetization_on_rounded = IconData(0xf8cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">monetization_on</i> — material icon named "monetization on" (outlined). + static const IconData monetization_on_outlined = IconData(0xf1dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">money</i> — material icon named "money". + static const IconData money = IconData(0xe3f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">money</i> — material icon named "money" (sharp). + static const IconData money_sharp = IconData(0xeaf3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">money</i> — material icon named "money" (round). + static const IconData money_rounded = IconData(0xf8d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">money</i> — material icon named "money" (outlined). + static const IconData money_outlined = IconData(0xf1e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">money_off</i> — material icon named "money off". + static const IconData money_off = IconData(0xe3f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">money_off</i> — material icon named "money off" (sharp). + static const IconData money_off_sharp = IconData(0xeaf2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">money_off</i> — material icon named "money off" (round). + static const IconData money_off_rounded = IconData(0xf8d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">money_off</i> — material icon named "money off" (outlined). + static const IconData money_off_outlined = IconData(0xf1df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">money_off_csred</i> — material icon named "money off csred". + static const IconData money_off_csred = IconData(0xe3fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">money_off_csred</i> — material icon named "money off csred" (sharp). + static const IconData money_off_csred_sharp = IconData(0xeaf1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">money_off_csred</i> — material icon named "money off csred" (round). + static const IconData money_off_csred_rounded = IconData(0xf8d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">money_off_csred</i> — material icon named "money off csred" (outlined). + static const IconData money_off_csred_outlined = IconData(0xf1de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">monitor</i> — material icon named "monitor". + static const IconData monitor = IconData(0xe3fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">monitor</i> — material icon named "monitor" (sharp). + static const IconData monitor_sharp = IconData(0xeaf4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">monitor</i> — material icon named "monitor" (round). + static const IconData monitor_rounded = IconData(0xf8d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">monitor</i> — material icon named "monitor" (outlined). + static const IconData monitor_outlined = IconData(0xf1e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">monitor_heart</i> — material icon named "monitor heart". + static const IconData monitor_heart = IconData(0xf053d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">monitor_heart</i> — material icon named "monitor heart" (sharp). + static const IconData monitor_heart_sharp = IconData(0xf0447, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">monitor_heart</i> — material icon named "monitor heart" (round). + static const IconData monitor_heart_rounded = IconData(0xf0354, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">monitor_heart</i> — material icon named "monitor heart" (outlined). + static const IconData monitor_heart_outlined = IconData(0xf0635, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">monitor_weight</i> — material icon named "monitor weight". + static const IconData monitor_weight = IconData(0xe3fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">monitor_weight</i> — material icon named "monitor weight" (sharp). + static const IconData monitor_weight_sharp = IconData(0xeaf5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">monitor_weight</i> — material icon named "monitor weight" (round). + static const IconData monitor_weight_rounded = IconData(0xf8d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">monitor_weight</i> — material icon named "monitor weight" (outlined). + static const IconData monitor_weight_outlined = IconData(0xf1e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">monochrome_photos</i> — material icon named "monochrome photos". + static const IconData monochrome_photos = IconData(0xe3fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">monochrome_photos</i> — material icon named "monochrome photos" (sharp). + static const IconData monochrome_photos_sharp = IconData(0xeaf6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">monochrome_photos</i> — material icon named "monochrome photos" (round). + static const IconData monochrome_photos_rounded = IconData(0xf8d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">monochrome_photos</i> — material icon named "monochrome photos" (outlined). + static const IconData monochrome_photos_outlined = IconData(0xf1e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mood</i> — material icon named "mood". + static const IconData mood = IconData(0xe3fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mood</i> — material icon named "mood" (sharp). + static const IconData mood_sharp = IconData(0xeaf8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mood</i> — material icon named "mood" (round). + static const IconData mood_rounded = IconData(0xf8d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mood</i> — material icon named "mood" (outlined). + static const IconData mood_outlined = IconData(0xf1e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mood_bad</i> — material icon named "mood bad". + static const IconData mood_bad = IconData(0xe3ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mood_bad</i> — material icon named "mood bad" (sharp). + static const IconData mood_bad_sharp = IconData(0xeaf7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mood_bad</i> — material icon named "mood bad" (round). + static const IconData mood_bad_rounded = IconData(0xf8d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mood_bad</i> — material icon named "mood bad" (outlined). + static const IconData mood_bad_outlined = IconData(0xf1e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">moped</i> — material icon named "moped". + static const IconData moped = IconData(0xe400, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">moped</i> — material icon named "moped" (sharp). + static const IconData moped_sharp = IconData(0xeaf9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">moped</i> — material icon named "moped" (round). + static const IconData moped_rounded = IconData(0xf8d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">moped</i> — material icon named "moped" (outlined). + static const IconData moped_outlined = IconData(0xf1e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">more</i> — material icon named "more". + static const IconData more = IconData(0xe401, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">more</i> — material icon named "more" (sharp). + static const IconData more_sharp = IconData(0xeafb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">more</i> — material icon named "more" (round). + static const IconData more_rounded = IconData(0xf8da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">more</i> — material icon named "more" (outlined). + static const IconData more_outlined = IconData(0xf1e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">more_horiz</i> — material icon named "more horiz". + static const IconData more_horiz = IconData(0xe402, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">more_horiz</i> — material icon named "more horiz" (sharp). + static const IconData more_horiz_sharp = IconData(0xeafa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">more_horiz</i> — material icon named "more horiz" (round). + static const IconData more_horiz_rounded = IconData(0xf8d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">more_horiz</i> — material icon named "more horiz" (outlined). + static const IconData more_horiz_outlined = IconData(0xf1e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">more_time</i> — material icon named "more time". + static const IconData more_time = IconData(0xe403, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">more_time</i> — material icon named "more time" (sharp). + static const IconData more_time_sharp = IconData(0xeafc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">more_time</i> — material icon named "more time" (round). + static const IconData more_time_rounded = IconData(0xf8db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">more_time</i> — material icon named "more time" (outlined). + static const IconData more_time_outlined = IconData(0xf1e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">more_vert</i> — material icon named "more vert". + static const IconData more_vert = IconData(0xe404, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">more_vert</i> — material icon named "more vert" (sharp). + static const IconData more_vert_sharp = IconData(0xeafd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">more_vert</i> — material icon named "more vert" (round). + static const IconData more_vert_rounded = IconData(0xf8dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">more_vert</i> — material icon named "more vert" (outlined). + static const IconData more_vert_outlined = IconData(0xf1ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mosque</i> — material icon named "mosque". + static const IconData mosque = IconData(0xf053e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mosque</i> — material icon named "mosque" (sharp). + static const IconData mosque_sharp = IconData(0xf0448, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mosque</i> — material icon named "mosque" (round). + static const IconData mosque_rounded = IconData(0xf0355, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mosque</i> — material icon named "mosque" (outlined). + static const IconData mosque_outlined = IconData(0xf0636, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">motion_photos_auto</i> — material icon named "motion photos auto". + static const IconData motion_photos_auto = IconData(0xe405, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">motion_photos_auto</i> — material icon named "motion photos auto" (sharp). + static const IconData motion_photos_auto_sharp = IconData(0xeafe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">motion_photos_auto</i> — material icon named "motion photos auto" (round). + static const IconData motion_photos_auto_rounded = IconData(0xf8dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">motion_photos_auto</i> — material icon named "motion photos auto" (outlined). + static const IconData motion_photos_auto_outlined = IconData(0xf1eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">motion_photos_off</i> — material icon named "motion photos off". + static const IconData motion_photos_off = IconData(0xe406, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">motion_photos_off</i> — material icon named "motion photos off" (sharp). + static const IconData motion_photos_off_sharp = IconData(0xeaff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">motion_photos_off</i> — material icon named "motion photos off" (round). + static const IconData motion_photos_off_rounded = IconData(0xf8de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">motion_photos_off</i> — material icon named "motion photos off" (outlined). + static const IconData motion_photos_off_outlined = IconData(0xf1ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">motion_photos_on</i> — material icon named "motion photos on". + static const IconData motion_photos_on = IconData(0xe407, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">motion_photos_on</i> — material icon named "motion photos on" (sharp). + static const IconData motion_photos_on_sharp = IconData(0xeb00, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">motion_photos_on</i> — material icon named "motion photos on" (round). + static const IconData motion_photos_on_rounded = IconData(0xf8df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">motion_photos_on</i> — material icon named "motion photos on" (outlined). + static const IconData motion_photos_on_outlined = IconData(0xf1ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">motion_photos_pause</i> — material icon named "motion photos pause". + static const IconData motion_photos_pause = IconData(0xe408, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">motion_photos_pause</i> — material icon named "motion photos pause" (sharp). + static const IconData motion_photos_pause_sharp = IconData(0xeb01, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">motion_photos_pause</i> — material icon named "motion photos pause" (round). + static const IconData motion_photos_pause_rounded = IconData(0xf8e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">motion_photos_pause</i> — material icon named "motion photos pause" (outlined). + static const IconData motion_photos_pause_outlined = IconData(0xf1ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">motion_photos_paused</i> — material icon named "motion photos paused". + static const IconData motion_photos_paused = IconData(0xe409, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">motion_photos_paused</i> — material icon named "motion photos paused" (sharp). + static const IconData motion_photos_paused_sharp = IconData(0xeb02, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">motion_photos_paused</i> — material icon named "motion photos paused" (round). + static const IconData motion_photos_paused_rounded = IconData(0xf8e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">motion_photos_paused</i> — material icon named "motion photos paused" (outlined). + static const IconData motion_photos_paused_outlined = IconData(0xf1ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">motorcycle</i> — material icon named "motorcycle". + static const IconData motorcycle = IconData(0xe40a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">motorcycle</i> — material icon named "motorcycle" (sharp). + static const IconData motorcycle_sharp = IconData(0xeb03, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">motorcycle</i> — material icon named "motorcycle" (round). + static const IconData motorcycle_rounded = IconData(0xf8e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">motorcycle</i> — material icon named "motorcycle" (outlined). + static const IconData motorcycle_outlined = IconData(0xf1f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mouse</i> — material icon named "mouse". + static const IconData mouse = IconData(0xe40b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mouse</i> — material icon named "mouse" (sharp). + static const IconData mouse_sharp = IconData(0xeb04, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mouse</i> — material icon named "mouse" (round). + static const IconData mouse_rounded = IconData(0xf8e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mouse</i> — material icon named "mouse" (outlined). + static const IconData mouse_outlined = IconData(0xf1f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">move_down</i> — material icon named "move down". + static const IconData move_down = IconData(0xf053f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">move_down</i> — material icon named "move down" (sharp). + static const IconData move_down_sharp = IconData(0xf0449, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">move_down</i> — material icon named "move down" (round). + static const IconData move_down_rounded = IconData(0xf0356, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">move_down</i> — material icon named "move down" (outlined). + static const IconData move_down_outlined = IconData(0xf0637, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">move_to_inbox</i> — material icon named "move to inbox". + static const IconData move_to_inbox = IconData(0xe40c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">move_to_inbox</i> — material icon named "move to inbox" (sharp). + static const IconData move_to_inbox_sharp = IconData(0xeb05, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">move_to_inbox</i> — material icon named "move to inbox" (round). + static const IconData move_to_inbox_rounded = IconData(0xf8e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">move_to_inbox</i> — material icon named "move to inbox" (outlined). + static const IconData move_to_inbox_outlined = IconData(0xf1f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">move_up</i> — material icon named "move up". + static const IconData move_up = IconData(0xf0540, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">move_up</i> — material icon named "move up" (sharp). + static const IconData move_up_sharp = IconData(0xf044a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">move_up</i> — material icon named "move up" (round). + static const IconData move_up_rounded = IconData(0xf0357, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">move_up</i> — material icon named "move up" (outlined). + static const IconData move_up_outlined = IconData(0xf0638, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">movie</i> — material icon named "movie". + static const IconData movie = IconData(0xe40d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">movie</i> — material icon named "movie" (sharp). + static const IconData movie_sharp = IconData(0xeb08, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">movie</i> — material icon named "movie" (round). + static const IconData movie_rounded = IconData(0xf8e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">movie</i> — material icon named "movie" (outlined). + static const IconData movie_outlined = IconData(0xf1f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">movie_creation</i> — material icon named "movie creation". + static const IconData movie_creation = IconData(0xe40e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">movie_creation</i> — material icon named "movie creation" (sharp). + static const IconData movie_creation_sharp = IconData(0xeb06, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">movie_creation</i> — material icon named "movie creation" (round). + static const IconData movie_creation_rounded = IconData(0xf8e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">movie_creation</i> — material icon named "movie creation" (outlined). + static const IconData movie_creation_outlined = IconData(0xf1f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">movie_edit</i> — material icon named "movie edit". + static const IconData movie_edit = IconData(0xf08b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">movie_filter</i> — material icon named "movie filter". + static const IconData movie_filter = IconData(0xe40f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">movie_filter</i> — material icon named "movie filter" (sharp). + static const IconData movie_filter_sharp = IconData(0xeb07, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">movie_filter</i> — material icon named "movie filter" (round). + static const IconData movie_filter_rounded = IconData(0xf8e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">movie_filter</i> — material icon named "movie filter" (outlined). + static const IconData movie_filter_outlined = IconData(0xf1f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">moving</i> — material icon named "moving". + static const IconData moving = IconData(0xe410, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">moving</i> — material icon named "moving" (sharp). + static const IconData moving_sharp = IconData(0xeb09, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">moving</i> — material icon named "moving" (round). + static const IconData moving_rounded = IconData(0xf8e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">moving</i> — material icon named "moving" (outlined). + static const IconData moving_outlined = IconData(0xf1f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">mp</i> — material icon named "mp". + static const IconData mp = IconData(0xe411, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">mp</i> — material icon named "mp" (sharp). + static const IconData mp_sharp = IconData(0xeb0a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">mp</i> — material icon named "mp" (round). + static const IconData mp_rounded = IconData(0xf8e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">mp</i> — material icon named "mp" (outlined). + static const IconData mp_outlined = IconData(0xf1f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">multiline_chart</i> — material icon named "multiline chart". + static const IconData multiline_chart = IconData(0xe412, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">multiline_chart</i> — material icon named "multiline chart" (sharp). + static const IconData multiline_chart_sharp = IconData(0xeb0b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">multiline_chart</i> — material icon named "multiline chart" (round). + static const IconData multiline_chart_rounded = IconData(0xf8ea, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">multiline_chart</i> — material icon named "multiline chart" (outlined). + static const IconData multiline_chart_outlined = IconData(0xf1f8, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">multiple_stop</i> — material icon named "multiple stop". + static const IconData multiple_stop = IconData(0xe413, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">multiple_stop</i> — material icon named "multiple stop" (sharp). + static const IconData multiple_stop_sharp = IconData(0xeb0c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">multiple_stop</i> — material icon named "multiple stop" (round). + static const IconData multiple_stop_rounded = IconData(0xf8eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">multiple_stop</i> — material icon named "multiple stop" (outlined). + static const IconData multiple_stop_outlined = IconData(0xf1f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">multitrack_audio</i> — material icon named "multitrack audio". + static const IconData multitrack_audio = IconData(0xe2e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">multitrack_audio</i> — material icon named "multitrack audio" (sharp). + static const IconData multitrack_audio_sharp = IconData(0xe9de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">multitrack_audio</i> — material icon named "multitrack audio" (round). + static const IconData multitrack_audio_rounded = IconData(0xf7bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">multitrack_audio</i> — material icon named "multitrack audio" (outlined). + static const IconData multitrack_audio_outlined = IconData(0xf0d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">museum</i> — material icon named "museum". + static const IconData museum = IconData(0xe414, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">museum</i> — material icon named "museum" (sharp). + static const IconData museum_sharp = IconData(0xeb0d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">museum</i> — material icon named "museum" (round). + static const IconData museum_rounded = IconData(0xf8ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">museum</i> — material icon named "museum" (outlined). + static const IconData museum_outlined = IconData(0xf1fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">music_note</i> — material icon named "music note". + static const IconData music_note = IconData(0xe415, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">music_note</i> — material icon named "music note" (sharp). + static const IconData music_note_sharp = IconData(0xeb0e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">music_note</i> — material icon named "music note" (round). + static const IconData music_note_rounded = IconData(0xf8ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">music_note</i> — material icon named "music note" (outlined). + static const IconData music_note_outlined = IconData(0xf1fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">music_off</i> — material icon named "music off". + static const IconData music_off = IconData(0xe416, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">music_off</i> — material icon named "music off" (sharp). + static const IconData music_off_sharp = IconData(0xeb0f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">music_off</i> — material icon named "music off" (round). + static const IconData music_off_rounded = IconData(0xf8ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">music_off</i> — material icon named "music off" (outlined). + static const IconData music_off_outlined = IconData(0xf1fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">music_video</i> — material icon named "music video". + static const IconData music_video = IconData(0xe417, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">music_video</i> — material icon named "music video" (sharp). + static const IconData music_video_sharp = IconData(0xeb10, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">music_video</i> — material icon named "music video" (round). + static const IconData music_video_rounded = IconData(0xf8ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">music_video</i> — material icon named "music video" (outlined). + static const IconData music_video_outlined = IconData(0xf1fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">my_library_add</i> — material icon named "my library add". + static const IconData my_library_add = IconData(0xe375, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">my_library_add</i> — material icon named "my library add" (sharp). + static const IconData my_library_add_sharp = IconData(0xea70, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">my_library_add</i> — material icon named "my library add" (round). + static const IconData my_library_add_rounded = IconData(0xf84f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">my_library_add</i> — material icon named "my library add" (outlined). + static const IconData my_library_add_outlined = IconData(0xf15f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">my_library_books</i> — material icon named "my library books". + static const IconData my_library_books = IconData(0xe377, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">my_library_books</i> — material icon named "my library books" (sharp). + static const IconData my_library_books_sharp = IconData(0xea71, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">my_library_books</i> — material icon named "my library books" (round). + static const IconData my_library_books_rounded = IconData(0xf850, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">my_library_books</i> — material icon named "my library books" (outlined). + static const IconData my_library_books_outlined = IconData(0xf160, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">my_library_music</i> — material icon named "my library music". + static const IconData my_library_music = IconData(0xe378, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">my_library_music</i> — material icon named "my library music" (sharp). + static const IconData my_library_music_sharp = IconData(0xea72, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">my_library_music</i> — material icon named "my library music" (round). + static const IconData my_library_music_rounded = IconData(0xf851, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">my_library_music</i> — material icon named "my library music" (outlined). + static const IconData my_library_music_outlined = IconData(0xf161, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">my_location</i> — material icon named "my location". + static const IconData my_location = IconData(0xe418, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">my_location</i> — material icon named "my location" (sharp). + static const IconData my_location_sharp = IconData(0xeb11, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">my_location</i> — material icon named "my location" (round). + static const IconData my_location_rounded = IconData(0xf8f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">my_location</i> — material icon named "my location" (outlined). + static const IconData my_location_outlined = IconData(0xf1fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nat</i> — material icon named "nat". + static const IconData nat = IconData(0xe419, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nat</i> — material icon named "nat" (sharp). + static const IconData nat_sharp = IconData(0xeb12, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nat</i> — material icon named "nat" (round). + static const IconData nat_rounded = IconData(0xf8f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nat</i> — material icon named "nat" (outlined). + static const IconData nat_outlined = IconData(0xf1ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nature</i> — material icon named "nature". + static const IconData nature = IconData(0xe41a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nature</i> — material icon named "nature" (sharp). + static const IconData nature_sharp = IconData(0xeb14, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nature</i> — material icon named "nature" (round). + static const IconData nature_rounded = IconData(0xf8f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nature</i> — material icon named "nature" (outlined). + static const IconData nature_outlined = IconData(0xf200, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nature_people</i> — material icon named "nature people". + static const IconData nature_people = IconData(0xe41b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nature_people</i> — material icon named "nature people" (sharp). + static const IconData nature_people_sharp = IconData(0xeb13, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nature_people</i> — material icon named "nature people" (round). + static const IconData nature_people_rounded = IconData(0xf8f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nature_people</i> — material icon named "nature people" (outlined). + static const IconData nature_people_outlined = IconData(0xf201, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">navigate_before</i> — material icon named "navigate before". + static const IconData navigate_before = IconData(0xe41c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">navigate_before</i> — material icon named "navigate before" (sharp). + static const IconData navigate_before_sharp = IconData(0xeb15, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">navigate_before</i> — material icon named "navigate before" (round). + static const IconData navigate_before_rounded = IconData(0xf8f4, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">navigate_before</i> — material icon named "navigate before" (outlined). + static const IconData navigate_before_outlined = IconData(0xf202, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">navigate_next</i> — material icon named "navigate next". + static const IconData navigate_next = IconData(0xe41d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">navigate_next</i> — material icon named "navigate next" (sharp). + static const IconData navigate_next_sharp = IconData(0xeb16, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">navigate_next</i> — material icon named "navigate next" (round). + static const IconData navigate_next_rounded = IconData(0xf8f5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">navigate_next</i> — material icon named "navigate next" (outlined). + static const IconData navigate_next_outlined = IconData(0xf203, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">navigation</i> — material icon named "navigation". + static const IconData navigation = IconData(0xe41e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">navigation</i> — material icon named "navigation" (sharp). + static const IconData navigation_sharp = IconData(0xeb17, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">navigation</i> — material icon named "navigation" (round). + static const IconData navigation_rounded = IconData(0xf8f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">navigation</i> — material icon named "navigation" (outlined). + static const IconData navigation_outlined = IconData(0xf204, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">near_me</i> — material icon named "near me". + static const IconData near_me = IconData(0xe41f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">near_me</i> — material icon named "near me" (sharp). + static const IconData near_me_sharp = IconData(0xeb19, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">near_me</i> — material icon named "near me" (round). + static const IconData near_me_rounded = IconData(0xf8f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">near_me</i> — material icon named "near me" (outlined). + static const IconData near_me_outlined = IconData(0xf206, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">near_me_disabled</i> — material icon named "near me disabled". + static const IconData near_me_disabled = IconData(0xe420, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">near_me_disabled</i> — material icon named "near me disabled" (sharp). + static const IconData near_me_disabled_sharp = IconData(0xeb18, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">near_me_disabled</i> — material icon named "near me disabled" (round). + static const IconData near_me_disabled_rounded = IconData(0xf8f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">near_me_disabled</i> — material icon named "near me disabled" (outlined). + static const IconData near_me_disabled_outlined = IconData(0xf205, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nearby_error</i> — material icon named "nearby error". + static const IconData nearby_error = IconData(0xe421, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nearby_error</i> — material icon named "nearby error" (sharp). + static const IconData nearby_error_sharp = IconData(0xeb1a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nearby_error</i> — material icon named "nearby error" (round). + static const IconData nearby_error_rounded = IconData(0xf8f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nearby_error</i> — material icon named "nearby error" (outlined). + static const IconData nearby_error_outlined = IconData(0xf207, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nearby_off</i> — material icon named "nearby off". + static const IconData nearby_off = IconData(0xe422, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nearby_off</i> — material icon named "nearby off" (sharp). + static const IconData nearby_off_sharp = IconData(0xeb1b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nearby_off</i> — material icon named "nearby off" (round). + static const IconData nearby_off_rounded = IconData(0xf8fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nearby_off</i> — material icon named "nearby off" (outlined). + static const IconData nearby_off_outlined = IconData(0xf208, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nest_cam_wired_stand</i> — material icon named "nest cam wired stand". + static const IconData nest_cam_wired_stand = IconData(0xf07af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nest_cam_wired_stand</i> — material icon named "nest cam wired stand" (sharp). + static const IconData nest_cam_wired_stand_sharp = IconData(0xf0757, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nest_cam_wired_stand</i> — material icon named "nest cam wired stand" (round). + static const IconData nest_cam_wired_stand_rounded = IconData(0xf0807, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nest_cam_wired_stand</i> — material icon named "nest cam wired stand" (outlined). + static const IconData nest_cam_wired_stand_outlined = IconData(0xf06ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">network_cell</i> — material icon named "network cell". + static const IconData network_cell = IconData(0xe423, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">network_cell</i> — material icon named "network cell" (sharp). + static const IconData network_cell_sharp = IconData(0xeb1c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">network_cell</i> — material icon named "network cell" (round). + static const IconData network_cell_rounded = IconData(0xf8fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">network_cell</i> — material icon named "network cell" (outlined). + static const IconData network_cell_outlined = IconData(0xf209, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">network_check</i> — material icon named "network check". + static const IconData network_check = IconData(0xe424, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">network_check</i> — material icon named "network check" (sharp). + static const IconData network_check_sharp = IconData(0xeb1d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">network_check</i> — material icon named "network check" (round). + static const IconData network_check_rounded = IconData(0xf8fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">network_check</i> — material icon named "network check" (outlined). + static const IconData network_check_outlined = IconData(0xf20a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">network_locked</i> — material icon named "network locked". + static const IconData network_locked = IconData(0xe425, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">network_locked</i> — material icon named "network locked" (sharp). + static const IconData network_locked_sharp = IconData(0xeb1e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">network_locked</i> — material icon named "network locked" (round). + static const IconData network_locked_rounded = IconData(0xf8fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">network_locked</i> — material icon named "network locked" (outlined). + static const IconData network_locked_outlined = IconData(0xf20b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">network_ping</i> — material icon named "network ping". + static const IconData network_ping = IconData(0xf06bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">network_ping</i> — material icon named "network ping" (sharp). + static const IconData network_ping_sharp = IconData(0xf06b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">network_ping</i> — material icon named "network ping" (round). + static const IconData network_ping_rounded = IconData(0xf06cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">network_ping</i> — material icon named "network ping" (outlined). + static const IconData network_ping_outlined = IconData(0xf06a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">network_wifi</i> — material icon named "network wifi". + static const IconData network_wifi = IconData(0xe426, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">network_wifi</i> — material icon named "network wifi" (sharp). + static const IconData network_wifi_sharp = IconData(0xeb1f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">network_wifi</i> — material icon named "network wifi" (round). + static const IconData network_wifi_rounded = IconData(0xf8fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">network_wifi</i> — material icon named "network wifi" (outlined). + static const IconData network_wifi_outlined = IconData(0xf20c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">network_wifi_1_bar</i> — material icon named "network wifi 1 bar". + static const IconData network_wifi_1_bar = IconData(0xf07b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">network_wifi_1_bar</i> — material icon named "network wifi 1 bar" (sharp). + static const IconData network_wifi_1_bar_sharp = IconData(0xf0758, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">network_wifi_1_bar</i> — material icon named "network wifi 1 bar" (round). + static const IconData network_wifi_1_bar_rounded = IconData(0xf0808, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">network_wifi_1_bar</i> — material icon named "network wifi 1 bar" (outlined). + static const IconData network_wifi_1_bar_outlined = IconData(0xf0700, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">network_wifi_2_bar</i> — material icon named "network wifi 2 bar". + static const IconData network_wifi_2_bar = IconData(0xf07b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">network_wifi_2_bar</i> — material icon named "network wifi 2 bar" (sharp). + static const IconData network_wifi_2_bar_sharp = IconData(0xf0759, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">network_wifi_2_bar</i> — material icon named "network wifi 2 bar" (round). + static const IconData network_wifi_2_bar_rounded = IconData(0xf0809, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">network_wifi_2_bar</i> — material icon named "network wifi 2 bar" (outlined). + static const IconData network_wifi_2_bar_outlined = IconData(0xf0701, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">network_wifi_3_bar</i> — material icon named "network wifi 3 bar". + static const IconData network_wifi_3_bar = IconData(0xf07b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">network_wifi_3_bar</i> — material icon named "network wifi 3 bar" (sharp). + static const IconData network_wifi_3_bar_sharp = IconData(0xf075a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">network_wifi_3_bar</i> — material icon named "network wifi 3 bar" (round). + static const IconData network_wifi_3_bar_rounded = IconData(0xf080a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">network_wifi_3_bar</i> — material icon named "network wifi 3 bar" (outlined). + static const IconData network_wifi_3_bar_outlined = IconData(0xf0702, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">new_label</i> — material icon named "new label". + static const IconData new_label = IconData(0xe427, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">new_label</i> — material icon named "new label" (sharp). + static const IconData new_label_sharp = IconData(0xeb20, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">new_label</i> — material icon named "new label" (round). + static const IconData new_label_rounded = IconData(0xf8ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">new_label</i> — material icon named "new label" (outlined). + static const IconData new_label_outlined = IconData(0xf20d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">new_releases</i> — material icon named "new releases". + static const IconData new_releases = IconData(0xe428, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">new_releases</i> — material icon named "new releases" (sharp). + static const IconData new_releases_sharp = IconData(0xeb21, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">new_releases</i> — material icon named "new releases" (round). + static const IconData new_releases_rounded = IconData(0xf0000, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">new_releases</i> — material icon named "new releases" (outlined). + static const IconData new_releases_outlined = IconData(0xf20e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">newspaper</i> — material icon named "newspaper". + static const IconData newspaper = IconData(0xf0541, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">newspaper</i> — material icon named "newspaper" (sharp). + static const IconData newspaper_sharp = IconData(0xf044b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">newspaper</i> — material icon named "newspaper" (round). + static const IconData newspaper_rounded = IconData(0xf0358, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">newspaper</i> — material icon named "newspaper" (outlined). + static const IconData newspaper_outlined = IconData(0xf0639, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">next_plan</i> — material icon named "next plan". + static const IconData next_plan = IconData(0xe429, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">next_plan</i> — material icon named "next plan" (sharp). + static const IconData next_plan_sharp = IconData(0xeb22, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">next_plan</i> — material icon named "next plan" (round). + static const IconData next_plan_rounded = IconData(0xf0001, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">next_plan</i> — material icon named "next plan" (outlined). + static const IconData next_plan_outlined = IconData(0xf20f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">next_week</i> — material icon named "next week". + static const IconData next_week = IconData(0xe42a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">next_week</i> — material icon named "next week" (sharp). + static const IconData next_week_sharp = IconData(0xeb23, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">next_week</i> — material icon named "next week" (round). + static const IconData next_week_rounded = IconData(0xf0002, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">next_week</i> — material icon named "next week" (outlined). + static const IconData next_week_outlined = IconData(0xf210, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">nfc</i> — material icon named "nfc". + static const IconData nfc = IconData(0xe42b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nfc</i> — material icon named "nfc" (sharp). + static const IconData nfc_sharp = IconData(0xeb24, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nfc</i> — material icon named "nfc" (round). + static const IconData nfc_rounded = IconData(0xf0003, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nfc</i> — material icon named "nfc" (outlined). + static const IconData nfc_outlined = IconData(0xf211, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">night_shelter</i> — material icon named "night shelter". + static const IconData night_shelter = IconData(0xe42c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">night_shelter</i> — material icon named "night shelter" (sharp). + static const IconData night_shelter_sharp = IconData(0xeb25, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">night_shelter</i> — material icon named "night shelter" (round). + static const IconData night_shelter_rounded = IconData(0xf0004, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">night_shelter</i> — material icon named "night shelter" (outlined). + static const IconData night_shelter_outlined = IconData(0xf212, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nightlife</i> — material icon named "nightlife". + static const IconData nightlife = IconData(0xe42d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nightlife</i> — material icon named "nightlife" (sharp). + static const IconData nightlife_sharp = IconData(0xeb26, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nightlife</i> — material icon named "nightlife" (round). + static const IconData nightlife_rounded = IconData(0xf0005, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nightlife</i> — material icon named "nightlife" (outlined). + static const IconData nightlife_outlined = IconData(0xf213, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nightlight</i> — material icon named "nightlight". + static const IconData nightlight = IconData(0xe42e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nightlight</i> — material icon named "nightlight" (sharp). + static const IconData nightlight_sharp = IconData(0xeb28, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nightlight</i> — material icon named "nightlight" (round). + static const IconData nightlight_rounded = IconData(0xf0007, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nightlight</i> — material icon named "nightlight" (outlined). + static const IconData nightlight_outlined = IconData(0xf214, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nightlight_round</i> — material icon named "nightlight round". + static const IconData nightlight_round = IconData(0xe42f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nightlight_round</i> — material icon named "nightlight round" (sharp). + static const IconData nightlight_round_sharp = IconData(0xeb27, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nightlight_round</i> — material icon named "nightlight round" (round). + static const IconData nightlight_round_rounded = IconData(0xf0006, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nightlight_round</i> — material icon named "nightlight round" (outlined). + static const IconData nightlight_round_outlined = IconData(0xf215, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nights_stay</i> — material icon named "nights stay". + static const IconData nights_stay = IconData(0xe430, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nights_stay</i> — material icon named "nights stay" (sharp). + static const IconData nights_stay_sharp = IconData(0xeb29, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nights_stay</i> — material icon named "nights stay" (round). + static const IconData nights_stay_rounded = IconData(0xf0008, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nights_stay</i> — material icon named "nights stay" (outlined). + static const IconData nights_stay_outlined = IconData(0xf216, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_accounts</i> — material icon named "no accounts". + static const IconData no_accounts = IconData(0xe431, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_accounts</i> — material icon named "no accounts" (sharp). + static const IconData no_accounts_sharp = IconData(0xeb2a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_accounts</i> — material icon named "no accounts" (round). + static const IconData no_accounts_rounded = IconData(0xf0009, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_accounts</i> — material icon named "no accounts" (outlined). + static const IconData no_accounts_outlined = IconData(0xf217, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_adult_content</i> — material icon named "no adult content". + static const IconData no_adult_content = IconData(0xf07b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_adult_content</i> — material icon named "no adult content" (sharp). + static const IconData no_adult_content_sharp = IconData(0xf075b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_adult_content</i> — material icon named "no adult content" (round). + static const IconData no_adult_content_rounded = IconData(0xf080b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_adult_content</i> — material icon named "no adult content" (outlined). + static const IconData no_adult_content_outlined = IconData(0xf0703, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_backpack</i> — material icon named "no backpack". + static const IconData no_backpack = IconData(0xe432, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_backpack</i> — material icon named "no backpack" (sharp). + static const IconData no_backpack_sharp = IconData(0xeb2b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_backpack</i> — material icon named "no backpack" (round). + static const IconData no_backpack_rounded = IconData(0xf000a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_backpack</i> — material icon named "no backpack" (outlined). + static const IconData no_backpack_outlined = IconData(0xf218, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_cell</i> — material icon named "no cell". + static const IconData no_cell = IconData(0xe433, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_cell</i> — material icon named "no cell" (sharp). + static const IconData no_cell_sharp = IconData(0xeb2c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_cell</i> — material icon named "no cell" (round). + static const IconData no_cell_rounded = IconData(0xf000b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_cell</i> — material icon named "no cell" (outlined). + static const IconData no_cell_outlined = IconData(0xf219, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_crash</i> — material icon named "no crash". + static const IconData no_crash = IconData(0xf07b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_crash</i> — material icon named "no crash" (sharp). + static const IconData no_crash_sharp = IconData(0xf075c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_crash</i> — material icon named "no crash" (round). + static const IconData no_crash_rounded = IconData(0xf080c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_crash</i> — material icon named "no crash" (outlined). + static const IconData no_crash_outlined = IconData(0xf0704, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_drinks</i> — material icon named "no drinks". + static const IconData no_drinks = IconData(0xe434, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_drinks</i> — material icon named "no drinks" (sharp). + static const IconData no_drinks_sharp = IconData(0xeb2d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_drinks</i> — material icon named "no drinks" (round). + static const IconData no_drinks_rounded = IconData(0xf000c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_drinks</i> — material icon named "no drinks" (outlined). + static const IconData no_drinks_outlined = IconData(0xf21a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_encryption</i> — material icon named "no encryption". + static const IconData no_encryption = IconData(0xe435, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_encryption</i> — material icon named "no encryption" (sharp). + static const IconData no_encryption_sharp = IconData(0xeb2f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_encryption</i> — material icon named "no encryption" (round). + static const IconData no_encryption_rounded = IconData(0xf000e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_encryption</i> — material icon named "no encryption" (outlined). + static const IconData no_encryption_outlined = IconData(0xf21c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_encryption_gmailerrorred</i> — material icon named "no encryption gmailerrorred". + static const IconData no_encryption_gmailerrorred = IconData(0xe436, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_encryption_gmailerrorred</i> — material icon named "no encryption gmailerrorred" (sharp). + static const IconData no_encryption_gmailerrorred_sharp = IconData(0xeb2e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_encryption_gmailerrorred</i> — material icon named "no encryption gmailerrorred" (round). + static const IconData no_encryption_gmailerrorred_rounded = IconData(0xf000d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_encryption_gmailerrorred</i> — material icon named "no encryption gmailerrorred" (outlined). + static const IconData no_encryption_gmailerrorred_outlined = IconData(0xf21b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_flash</i> — material icon named "no flash". + static const IconData no_flash = IconData(0xe437, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_flash</i> — material icon named "no flash" (sharp). + static const IconData no_flash_sharp = IconData(0xeb30, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_flash</i> — material icon named "no flash" (round). + static const IconData no_flash_rounded = IconData(0xf000f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_flash</i> — material icon named "no flash" (outlined). + static const IconData no_flash_outlined = IconData(0xf21d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_food</i> — material icon named "no food". + static const IconData no_food = IconData(0xe438, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_food</i> — material icon named "no food" (sharp). + static const IconData no_food_sharp = IconData(0xeb31, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_food</i> — material icon named "no food" (round). + static const IconData no_food_rounded = IconData(0xf0010, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_food</i> — material icon named "no food" (outlined). + static const IconData no_food_outlined = IconData(0xf21e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_luggage</i> — material icon named "no luggage". + static const IconData no_luggage = IconData(0xe439, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_luggage</i> — material icon named "no luggage" (sharp). + static const IconData no_luggage_sharp = IconData(0xeb32, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_luggage</i> — material icon named "no luggage" (round). + static const IconData no_luggage_rounded = IconData(0xf0011, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_luggage</i> — material icon named "no luggage" (outlined). + static const IconData no_luggage_outlined = IconData(0xf21f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_meals</i> — material icon named "no meals". + static const IconData no_meals = IconData(0xe43a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_meals</i> — material icon named "no meals" (sharp). + static const IconData no_meals_sharp = IconData(0xeb33, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_meals</i> — material icon named "no meals" (round). + static const IconData no_meals_rounded = IconData(0xf0012, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_meals</i> — material icon named "no meals" (outlined). + static const IconData no_meals_outlined = IconData(0xf220, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_meals_ouline</i> — material icon named "no meals ouline". + static const IconData no_meals_ouline = IconData(0xe43b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_meeting_room</i> — material icon named "no meeting room". + static const IconData no_meeting_room = IconData(0xe43c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_meeting_room</i> — material icon named "no meeting room" (sharp). + static const IconData no_meeting_room_sharp = IconData(0xeb34, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_meeting_room</i> — material icon named "no meeting room" (round). + static const IconData no_meeting_room_rounded = IconData(0xf0013, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_meeting_room</i> — material icon named "no meeting room" (outlined). + static const IconData no_meeting_room_outlined = IconData(0xf221, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_photography</i> — material icon named "no photography". + static const IconData no_photography = IconData(0xe43d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_photography</i> — material icon named "no photography" (sharp). + static const IconData no_photography_sharp = IconData(0xeb35, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_photography</i> — material icon named "no photography" (round). + static const IconData no_photography_rounded = IconData(0xf0014, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_photography</i> — material icon named "no photography" (outlined). + static const IconData no_photography_outlined = IconData(0xf222, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_sim</i> — material icon named "no sim". + static const IconData no_sim = IconData(0xe43e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_sim</i> — material icon named "no sim" (sharp). + static const IconData no_sim_sharp = IconData(0xeb36, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_sim</i> — material icon named "no sim" (round). + static const IconData no_sim_rounded = IconData(0xf0015, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_sim</i> — material icon named "no sim" (outlined). + static const IconData no_sim_outlined = IconData(0xf223, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_stroller</i> — material icon named "no stroller". + static const IconData no_stroller = IconData(0xe43f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_stroller</i> — material icon named "no stroller" (sharp). + static const IconData no_stroller_sharp = IconData(0xeb37, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_stroller</i> — material icon named "no stroller" (round). + static const IconData no_stroller_rounded = IconData(0xf0016, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_stroller</i> — material icon named "no stroller" (outlined). + static const IconData no_stroller_outlined = IconData(0xf224, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">no_transfer</i> — material icon named "no transfer". + static const IconData no_transfer = IconData(0xe440, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">no_transfer</i> — material icon named "no transfer" (sharp). + static const IconData no_transfer_sharp = IconData(0xeb38, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">no_transfer</i> — material icon named "no transfer" (round). + static const IconData no_transfer_rounded = IconData(0xf0017, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">no_transfer</i> — material icon named "no transfer" (outlined). + static const IconData no_transfer_outlined = IconData(0xf225, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">noise_aware</i> — material icon named "noise aware". + static const IconData noise_aware = IconData(0xf07b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">noise_aware</i> — material icon named "noise aware" (sharp). + static const IconData noise_aware_sharp = IconData(0xf075d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">noise_aware</i> — material icon named "noise aware" (round). + static const IconData noise_aware_rounded = IconData(0xf080d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">noise_aware</i> — material icon named "noise aware" (outlined). + static const IconData noise_aware_outlined = IconData(0xf0705, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">noise_control_off</i> — material icon named "noise control off". + static const IconData noise_control_off = IconData(0xf07b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">noise_control_off</i> — material icon named "noise control off" (sharp). + static const IconData noise_control_off_sharp = IconData(0xf075e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">noise_control_off</i> — material icon named "noise control off" (round). + static const IconData noise_control_off_rounded = IconData(0xf080e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">noise_control_off</i> — material icon named "noise control off" (outlined). + static const IconData noise_control_off_outlined = IconData(0xf0706, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">nordic_walking</i> — material icon named "nordic walking". + static const IconData nordic_walking = IconData(0xe441, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">nordic_walking</i> — material icon named "nordic walking" (sharp). + static const IconData nordic_walking_sharp = IconData(0xeb39, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">nordic_walking</i> — material icon named "nordic walking" (round). + static const IconData nordic_walking_rounded = IconData(0xf0018, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">nordic_walking</i> — material icon named "nordic walking" (outlined). + static const IconData nordic_walking_outlined = IconData(0xf226, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">north</i> — material icon named "north". + static const IconData north = IconData(0xe442, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">north</i> — material icon named "north" (sharp). + static const IconData north_sharp = IconData(0xeb3b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">north</i> — material icon named "north" (round). + static const IconData north_rounded = IconData(0xf001a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">north</i> — material icon named "north" (outlined). + static const IconData north_outlined = IconData(0xf228, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">north_east</i> — material icon named "north east". + static const IconData north_east = IconData(0xe443, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">north_east</i> — material icon named "north east" (sharp). + static const IconData north_east_sharp = IconData(0xeb3a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">north_east</i> — material icon named "north east" (round). + static const IconData north_east_rounded = IconData(0xf0019, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">north_east</i> — material icon named "north east" (outlined). + static const IconData north_east_outlined = IconData(0xf227, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">north_west</i> — material icon named "north west". + static const IconData north_west = IconData(0xe444, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">north_west</i> — material icon named "north west" (sharp). + static const IconData north_west_sharp = IconData(0xeb3c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">north_west</i> — material icon named "north west" (round). + static const IconData north_west_rounded = IconData(0xf001b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">north_west</i> — material icon named "north west" (outlined). + static const IconData north_west_outlined = IconData(0xf229, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">not_accessible</i> — material icon named "not accessible". + static const IconData not_accessible = IconData(0xe445, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">not_accessible</i> — material icon named "not accessible" (sharp). + static const IconData not_accessible_sharp = IconData(0xeb3d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">not_accessible</i> — material icon named "not accessible" (round). + static const IconData not_accessible_rounded = IconData(0xf001c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">not_accessible</i> — material icon named "not accessible" (outlined). + static const IconData not_accessible_outlined = IconData(0xf22a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">not_interested</i> — material icon named "not interested". + static const IconData not_interested = IconData(0xe446, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">not_interested</i> — material icon named "not interested" (sharp). + static const IconData not_interested_sharp = IconData(0xeb3e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">not_interested</i> — material icon named "not interested" (round). + static const IconData not_interested_rounded = IconData(0xf001d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">not_interested</i> — material icon named "not interested" (outlined). + static const IconData not_interested_outlined = IconData(0xf22b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">not_listed_location</i> — material icon named "not listed location". + static const IconData not_listed_location = IconData(0xe447, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">not_listed_location</i> — material icon named "not listed location" (sharp). + static const IconData not_listed_location_sharp = IconData(0xeb3f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">not_listed_location</i> — material icon named "not listed location" (round). + static const IconData not_listed_location_rounded = IconData(0xf001e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">not_listed_location</i> — material icon named "not listed location" (outlined). + static const IconData not_listed_location_outlined = IconData(0xf22c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">not_started</i> — material icon named "not started". + static const IconData not_started = IconData(0xe448, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">not_started</i> — material icon named "not started" (sharp). + static const IconData not_started_sharp = IconData(0xeb40, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">not_started</i> — material icon named "not started" (round). + static const IconData not_started_rounded = IconData(0xf001f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">not_started</i> — material icon named "not started" (outlined). + static const IconData not_started_outlined = IconData(0xf22d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">note</i> — material icon named "note". + static const IconData note = IconData(0xe449, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">note</i> — material icon named "note" (sharp). + static const IconData note_sharp = IconData(0xeb43, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">note</i> — material icon named "note" (round). + static const IconData note_rounded = IconData(0xf0022, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">note</i> — material icon named "note" (outlined). + static const IconData note_outlined = IconData(0xf230, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">note_add</i> — material icon named "note add". + static const IconData note_add = IconData(0xe44a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">note_add</i> — material icon named "note add" (sharp). + static const IconData note_add_sharp = IconData(0xeb41, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">note_add</i> — material icon named "note add" (round). + static const IconData note_add_rounded = IconData(0xf0020, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">note_add</i> — material icon named "note add" (outlined). + static const IconData note_add_outlined = IconData(0xf22e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">note_alt</i> — material icon named "note alt". + static const IconData note_alt = IconData(0xe44b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">note_alt</i> — material icon named "note alt" (sharp). + static const IconData note_alt_sharp = IconData(0xeb42, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">note_alt</i> — material icon named "note alt" (round). + static const IconData note_alt_rounded = IconData(0xf0021, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">note_alt</i> — material icon named "note alt" (outlined). + static const IconData note_alt_outlined = IconData(0xf22f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">notes</i> — material icon named "notes". + static const IconData notes = IconData(0xe44c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">notes</i> — material icon named "notes" (sharp). + static const IconData notes_sharp = IconData(0xeb44, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">notes</i> — material icon named "notes" (round). + static const IconData notes_rounded = IconData(0xf0023, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">notes</i> — material icon named "notes" (outlined). + static const IconData notes_outlined = IconData(0xf231, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">notification_add</i> — material icon named "notification add". + static const IconData notification_add = IconData(0xe44d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">notification_add</i> — material icon named "notification add" (sharp). + static const IconData notification_add_sharp = IconData(0xeb45, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">notification_add</i> — material icon named "notification add" (round). + static const IconData notification_add_rounded = IconData(0xf0024, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">notification_add</i> — material icon named "notification add" (outlined). + static const IconData notification_add_outlined = IconData(0xf232, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">notification_important</i> — material icon named "notification important". + static const IconData notification_important = IconData(0xe44e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">notification_important</i> — material icon named "notification important" (sharp). + static const IconData notification_important_sharp = IconData(0xeb46, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">notification_important</i> — material icon named "notification important" (round). + static const IconData notification_important_rounded = IconData(0xf0025, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">notification_important</i> — material icon named "notification important" (outlined). + static const IconData notification_important_outlined = IconData(0xf233, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">notifications</i> — material icon named "notifications". + static const IconData notifications = IconData(0xe44f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">notifications</i> — material icon named "notifications" (sharp). + static const IconData notifications_sharp = IconData(0xeb4b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">notifications</i> — material icon named "notifications" (round). + static const IconData notifications_rounded = IconData(0xf002a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">notifications</i> — material icon named "notifications" (outlined). + static const IconData notifications_outlined = IconData(0xf237, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">notifications_active</i> — material icon named "notifications active". + static const IconData notifications_active = IconData(0xe450, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">notifications_active</i> — material icon named "notifications active" (sharp). + static const IconData notifications_active_sharp = IconData(0xeb47, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">notifications_active</i> — material icon named "notifications active" (round). + static const IconData notifications_active_rounded = IconData(0xf0026, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">notifications_active</i> — material icon named "notifications active" (outlined). + static const IconData notifications_active_outlined = IconData(0xf234, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">notifications_none</i> — material icon named "notifications none". + static const IconData notifications_none = IconData(0xe451, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">notifications_none</i> — material icon named "notifications none" (sharp). + static const IconData notifications_none_sharp = IconData(0xeb48, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">notifications_none</i> — material icon named "notifications none" (round). + static const IconData notifications_none_rounded = IconData(0xf0027, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">notifications_none</i> — material icon named "notifications none" (outlined). + static const IconData notifications_none_outlined = IconData(0xf235, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">notifications_off</i> — material icon named "notifications off". + static const IconData notifications_off = IconData(0xe452, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">notifications_off</i> — material icon named "notifications off" (sharp). + static const IconData notifications_off_sharp = IconData(0xeb49, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">notifications_off</i> — material icon named "notifications off" (round). + static const IconData notifications_off_rounded = IconData(0xf0028, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">notifications_off</i> — material icon named "notifications off" (outlined). + static const IconData notifications_off_outlined = IconData(0xf236, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">notifications_on</i> — material icon named "notifications on". + static const IconData notifications_on = IconData(0xe450, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">notifications_on</i> — material icon named "notifications on" (sharp). + static const IconData notifications_on_sharp = IconData(0xeb47, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">notifications_on</i> — material icon named "notifications on" (round). + static const IconData notifications_on_rounded = IconData(0xf0026, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">notifications_on</i> — material icon named "notifications on" (outlined). + static const IconData notifications_on_outlined = IconData(0xf234, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">notifications_paused</i> — material icon named "notifications paused". + static const IconData notifications_paused = IconData(0xe453, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">notifications_paused</i> — material icon named "notifications paused" (sharp). + static const IconData notifications_paused_sharp = IconData(0xeb4a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">notifications_paused</i> — material icon named "notifications paused" (round). + static const IconData notifications_paused_rounded = IconData(0xf0029, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">notifications_paused</i> — material icon named "notifications paused" (outlined). + static const IconData notifications_paused_outlined = IconData(0xf238, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">now_wallpaper</i> — material icon named "now wallpaper". + static const IconData now_wallpaper = IconData(0xe6ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">now_wallpaper</i> — material icon named "now wallpaper" (sharp). + static const IconData now_wallpaper_sharp = IconData(0xedc0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">now_wallpaper</i> — material icon named "now wallpaper" (round). + static const IconData now_wallpaper_rounded = IconData(0xf029f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">now_wallpaper</i> — material icon named "now wallpaper" (outlined). + static const IconData now_wallpaper_outlined = IconData(0xf4ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">now_widgets</i> — material icon named "now widgets". + static const IconData now_widgets = IconData(0xe6e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">now_widgets</i> — material icon named "now widgets" (sharp). + static const IconData now_widgets_sharp = IconData(0xedda, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">now_widgets</i> — material icon named "now widgets" (round). + static const IconData now_widgets_rounded = IconData(0xf02b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">now_widgets</i> — material icon named "now widgets" (outlined). + static const IconData now_widgets_outlined = IconData(0xf4c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">numbers</i> — material icon named "numbers". + static const IconData numbers = IconData(0xf0542, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">numbers</i> — material icon named "numbers" (sharp). + static const IconData numbers_sharp = IconData(0xf044c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">numbers</i> — material icon named "numbers" (round). + static const IconData numbers_rounded = IconData(0xf0359, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">numbers</i> — material icon named "numbers" (outlined). + static const IconData numbers_outlined = IconData(0xf063a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">offline_bolt</i> — material icon named "offline bolt". + static const IconData offline_bolt = IconData(0xe454, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">offline_bolt</i> — material icon named "offline bolt" (sharp). + static const IconData offline_bolt_sharp = IconData(0xeb4c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">offline_bolt</i> — material icon named "offline bolt" (round). + static const IconData offline_bolt_rounded = IconData(0xf002b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">offline_bolt</i> — material icon named "offline bolt" (outlined). + static const IconData offline_bolt_outlined = IconData(0xf239, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">offline_pin</i> — material icon named "offline pin". + static const IconData offline_pin = IconData(0xe455, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">offline_pin</i> — material icon named "offline pin" (sharp). + static const IconData offline_pin_sharp = IconData(0xeb4d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">offline_pin</i> — material icon named "offline pin" (round). + static const IconData offline_pin_rounded = IconData(0xf002c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">offline_pin</i> — material icon named "offline pin" (outlined). + static const IconData offline_pin_outlined = IconData(0xf23a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">offline_share</i> — material icon named "offline share". + static const IconData offline_share = IconData(0xe456, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">offline_share</i> — material icon named "offline share" (sharp). + static const IconData offline_share_sharp = IconData(0xeb4e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">offline_share</i> — material icon named "offline share" (round). + static const IconData offline_share_rounded = IconData(0xf002d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">offline_share</i> — material icon named "offline share" (outlined). + static const IconData offline_share_outlined = IconData(0xf23b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">oil_barrel</i> — material icon named "oil barrel". + static const IconData oil_barrel = IconData(0xf07b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">oil_barrel</i> — material icon named "oil barrel" (sharp). + static const IconData oil_barrel_sharp = IconData(0xf075f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">oil_barrel</i> — material icon named "oil barrel" (round). + static const IconData oil_barrel_rounded = IconData(0xf080f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">oil_barrel</i> — material icon named "oil barrel" (outlined). + static const IconData oil_barrel_outlined = IconData(0xf0707, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">on_device_training</i> — material icon named "on device training". + static const IconData on_device_training = IconData(0xf07b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">on_device_training</i> — material icon named "on device training" (sharp). + static const IconData on_device_training_sharp = IconData(0xf0760, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">on_device_training</i> — material icon named "on device training" (round). + static const IconData on_device_training_rounded = IconData(0xf0810, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">on_device_training</i> — material icon named "on device training" (outlined). + static const IconData on_device_training_outlined = IconData(0xf0708, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ondemand_video</i> — material icon named "ondemand video". + static const IconData ondemand_video = IconData(0xe457, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ondemand_video</i> — material icon named "ondemand video" (sharp). + static const IconData ondemand_video_sharp = IconData(0xeb4f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ondemand_video</i> — material icon named "ondemand video" (round). + static const IconData ondemand_video_rounded = IconData(0xf002e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ondemand_video</i> — material icon named "ondemand video" (outlined). + static const IconData ondemand_video_outlined = IconData(0xf23c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">online_prediction</i> — material icon named "online prediction". + static const IconData online_prediction = IconData(0xe458, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">online_prediction</i> — material icon named "online prediction" (sharp). + static const IconData online_prediction_sharp = IconData(0xeb50, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">online_prediction</i> — material icon named "online prediction" (round). + static const IconData online_prediction_rounded = IconData(0xf002f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">online_prediction</i> — material icon named "online prediction" (outlined). + static const IconData online_prediction_outlined = IconData(0xf23d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">opacity</i> — material icon named "opacity". + static const IconData opacity = IconData(0xe459, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">opacity</i> — material icon named "opacity" (sharp). + static const IconData opacity_sharp = IconData(0xeb51, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">opacity</i> — material icon named "opacity" (round). + static const IconData opacity_rounded = IconData(0xf0030, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">opacity</i> — material icon named "opacity" (outlined). + static const IconData opacity_outlined = IconData(0xf23e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">open_in_browser</i> — material icon named "open in browser". + static const IconData open_in_browser = IconData(0xe45a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">open_in_browser</i> — material icon named "open in browser" (sharp). + static const IconData open_in_browser_sharp = IconData(0xeb52, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">open_in_browser</i> — material icon named "open in browser" (round). + static const IconData open_in_browser_rounded = IconData(0xf0031, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">open_in_browser</i> — material icon named "open in browser" (outlined). + static const IconData open_in_browser_outlined = IconData(0xf23f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">open_in_full</i> — material icon named "open in full". + static const IconData open_in_full = IconData(0xe45b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">open_in_full</i> — material icon named "open in full" (sharp). + static const IconData open_in_full_sharp = IconData(0xeb53, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">open_in_full</i> — material icon named "open in full" (round). + static const IconData open_in_full_rounded = IconData(0xf0032, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">open_in_full</i> — material icon named "open in full" (outlined). + static const IconData open_in_full_outlined = IconData(0xf240, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">open_in_new</i> — material icon named "open in new". + static const IconData open_in_new = IconData(0xe45c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">open_in_new</i> — material icon named "open in new" (sharp). + static const IconData open_in_new_sharp = IconData(0xeb55, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">open_in_new</i> — material icon named "open in new" (round). + static const IconData open_in_new_rounded = IconData(0xf0034, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">open_in_new</i> — material icon named "open in new" (outlined). + static const IconData open_in_new_outlined = IconData(0xf242, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">open_in_new_off</i> — material icon named "open in new off". + static const IconData open_in_new_off = IconData(0xe45d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">open_in_new_off</i> — material icon named "open in new off" (sharp). + static const IconData open_in_new_off_sharp = IconData(0xeb54, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">open_in_new_off</i> — material icon named "open in new off" (round). + static const IconData open_in_new_off_rounded = IconData(0xf0033, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">open_in_new_off</i> — material icon named "open in new off" (outlined). + static const IconData open_in_new_off_outlined = IconData(0xf241, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">open_with</i> — material icon named "open with". + static const IconData open_with = IconData(0xe45e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">open_with</i> — material icon named "open with" (sharp). + static const IconData open_with_sharp = IconData(0xeb56, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">open_with</i> — material icon named "open with" (round). + static const IconData open_with_rounded = IconData(0xf0035, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">open_with</i> — material icon named "open with" (outlined). + static const IconData open_with_outlined = IconData(0xf243, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">other_houses</i> — material icon named "other houses". + static const IconData other_houses = IconData(0xe45f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">other_houses</i> — material icon named "other houses" (sharp). + static const IconData other_houses_sharp = IconData(0xeb57, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">other_houses</i> — material icon named "other houses" (round). + static const IconData other_houses_rounded = IconData(0xf0036, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">other_houses</i> — material icon named "other houses" (outlined). + static const IconData other_houses_outlined = IconData(0xf244, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">outbond</i> — material icon named "outbond". + static const IconData outbond = IconData(0xe460, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">outbond</i> — material icon named "outbond" (sharp). + static const IconData outbond_sharp = IconData(0xeb58, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">outbond</i> — material icon named "outbond" (round). + static const IconData outbond_rounded = IconData(0xf0037, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">outbond</i> — material icon named "outbond" (outlined). + static const IconData outbond_outlined = IconData(0xf245, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">outbound</i> — material icon named "outbound". + static const IconData outbound = IconData(0xe461, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">outbound</i> — material icon named "outbound" (sharp). + static const IconData outbound_sharp = IconData(0xeb59, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">outbound</i> — material icon named "outbound" (round). + static const IconData outbound_rounded = IconData(0xf0038, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">outbound</i> — material icon named "outbound" (outlined). + static const IconData outbound_outlined = IconData(0xf246, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">outbox</i> — material icon named "outbox". + static const IconData outbox = IconData(0xe462, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">outbox</i> — material icon named "outbox" (sharp). + static const IconData outbox_sharp = IconData(0xeb5a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">outbox</i> — material icon named "outbox" (round). + static const IconData outbox_rounded = IconData(0xf0039, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">outbox</i> — material icon named "outbox" (outlined). + static const IconData outbox_outlined = IconData(0xf247, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">outdoor_grill</i> — material icon named "outdoor grill". + static const IconData outdoor_grill = IconData(0xe463, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">outdoor_grill</i> — material icon named "outdoor grill" (sharp). + static const IconData outdoor_grill_sharp = IconData(0xeb5b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">outdoor_grill</i> — material icon named "outdoor grill" (round). + static const IconData outdoor_grill_rounded = IconData(0xf003a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">outdoor_grill</i> — material icon named "outdoor grill" (outlined). + static const IconData outdoor_grill_outlined = IconData(0xf248, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">outgoing_mail</i> — material icon named "outgoing mail". + static const IconData outgoing_mail = IconData(0xe464, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">outlet</i> — material icon named "outlet". + static const IconData outlet = IconData(0xe465, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">outlet</i> — material icon named "outlet" (sharp). + static const IconData outlet_sharp = IconData(0xeb5c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">outlet</i> — material icon named "outlet" (round). + static const IconData outlet_rounded = IconData(0xf003b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">outlet</i> — material icon named "outlet" (outlined). + static const IconData outlet_outlined = IconData(0xf249, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">outlined_flag</i> — material icon named "outlined flag". + static const IconData outlined_flag = IconData(0xe466, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">outlined_flag</i> — material icon named "outlined flag" (sharp). + static const IconData outlined_flag_sharp = IconData(0xeb5d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">outlined_flag</i> — material icon named "outlined flag" (round). + static const IconData outlined_flag_rounded = IconData(0xf003c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">outlined_flag</i> — material icon named "outlined flag" (outlined). + static const IconData outlined_flag_outlined = IconData(0xf24a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">output</i> — material icon named "output". + static const IconData output = IconData(0xf0543, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">output</i> — material icon named "output" (sharp). + static const IconData output_sharp = IconData(0xf044d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">output</i> — material icon named "output" (round). + static const IconData output_rounded = IconData(0xf035a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">output</i> — material icon named "output" (outlined). + static const IconData output_outlined = IconData(0xf063b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">padding</i> — material icon named "padding". + static const IconData padding = IconData(0xe467, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">padding</i> — material icon named "padding" (sharp). + static const IconData padding_sharp = IconData(0xeb5e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">padding</i> — material icon named "padding" (round). + static const IconData padding_rounded = IconData(0xf003d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">padding</i> — material icon named "padding" (outlined). + static const IconData padding_outlined = IconData(0xf24b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pages</i> — material icon named "pages". + static const IconData pages = IconData(0xe468, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pages</i> — material icon named "pages" (sharp). + static const IconData pages_sharp = IconData(0xeb5f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pages</i> — material icon named "pages" (round). + static const IconData pages_rounded = IconData(0xf003e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pages</i> — material icon named "pages" (outlined). + static const IconData pages_outlined = IconData(0xf24c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pageview</i> — material icon named "pageview". + static const IconData pageview = IconData(0xe469, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pageview</i> — material icon named "pageview" (sharp). + static const IconData pageview_sharp = IconData(0xeb60, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pageview</i> — material icon named "pageview" (round). + static const IconData pageview_rounded = IconData(0xf003f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pageview</i> — material icon named "pageview" (outlined). + static const IconData pageview_outlined = IconData(0xf24d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">paid</i> — material icon named "paid". + static const IconData paid = IconData(0xe46a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">paid</i> — material icon named "paid" (sharp). + static const IconData paid_sharp = IconData(0xeb61, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">paid</i> — material icon named "paid" (round). + static const IconData paid_rounded = IconData(0xf0040, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">paid</i> — material icon named "paid" (outlined). + static const IconData paid_outlined = IconData(0xf24e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">palette</i> — material icon named "palette". + static const IconData palette = IconData(0xe46b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">palette</i> — material icon named "palette" (sharp). + static const IconData palette_sharp = IconData(0xeb62, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">palette</i> — material icon named "palette" (round). + static const IconData palette_rounded = IconData(0xf0041, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">palette</i> — material icon named "palette" (outlined). + static const IconData palette_outlined = IconData(0xf24f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pallet</i> — material icon named "pallet". + static const IconData pallet = IconData(0xf086f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pan_tool</i> — material icon named "pan tool". + static const IconData pan_tool = IconData(0xe46c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pan_tool</i> — material icon named "pan tool" (sharp). + static const IconData pan_tool_sharp = IconData(0xeb63, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pan_tool</i> — material icon named "pan tool" (round). + static const IconData pan_tool_rounded = IconData(0xf0042, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pan_tool</i> — material icon named "pan tool" (outlined). + static const IconData pan_tool_outlined = IconData(0xf250, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pan_tool_alt</i> — material icon named "pan tool alt". + static const IconData pan_tool_alt = IconData(0xf0544, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pan_tool_alt</i> — material icon named "pan tool alt" (sharp). + static const IconData pan_tool_alt_sharp = IconData(0xf044e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pan_tool_alt</i> — material icon named "pan tool alt" (round). + static const IconData pan_tool_alt_rounded = IconData(0xf035b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pan_tool_alt</i> — material icon named "pan tool alt" (outlined). + static const IconData pan_tool_alt_outlined = IconData(0xf063c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama</i> — material icon named "panorama". + static const IconData panorama = IconData(0xe46d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama</i> — material icon named "panorama" (sharp). + static const IconData panorama_sharp = IconData(0xeb69, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama</i> — material icon named "panorama" (round). + static const IconData panorama_rounded = IconData(0xf0048, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama</i> — material icon named "panorama" (outlined). + static const IconData panorama_outlined = IconData(0xf254, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama_fish_eye</i> — material icon named "panorama fish eye". + static const IconData panorama_fish_eye = IconData(0xe46e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama_fish_eye</i> — material icon named "panorama fish eye" (sharp). + static const IconData panorama_fish_eye_sharp = IconData(0xeb64, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama_fish_eye</i> — material icon named "panorama fish eye" (round). + static const IconData panorama_fish_eye_rounded = IconData(0xf0043, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama_fish_eye</i> — material icon named "panorama fish eye" (outlined). + static const IconData panorama_fish_eye_outlined = IconData(0xf251, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama_fisheye</i> — material icon named "panorama fisheye". + static const IconData panorama_fisheye = IconData(0xe46e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama_fisheye</i> — material icon named "panorama fisheye" (sharp). + static const IconData panorama_fisheye_sharp = IconData(0xeb64, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama_fisheye</i> — material icon named "panorama fisheye" (round). + static const IconData panorama_fisheye_rounded = IconData(0xf0043, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama_fisheye</i> — material icon named "panorama fisheye" (outlined). + static const IconData panorama_fisheye_outlined = IconData(0xf251, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama_horizontal</i> — material icon named "panorama horizontal". + static const IconData panorama_horizontal = IconData(0xe46f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama_horizontal</i> — material icon named "panorama horizontal" (sharp). + static const IconData panorama_horizontal_sharp = IconData(0xeb66, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama_horizontal</i> — material icon named "panorama horizontal" (round). + static const IconData panorama_horizontal_rounded = IconData(0xf0044, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama_horizontal</i> — material icon named "panorama horizontal" (outlined). + static const IconData panorama_horizontal_outlined = IconData(0xf252, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama_horizontal_select</i> — material icon named "panorama horizontal select". + static const IconData panorama_horizontal_select = IconData(0xe470, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama_horizontal_select</i> — material icon named "panorama horizontal select" (sharp). + static const IconData panorama_horizontal_select_sharp = IconData(0xeb65, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama_horizontal_select</i> — material icon named "panorama horizontal select" (round). + static const IconData panorama_horizontal_select_rounded = IconData(0xf0045, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama_horizontal_select</i> — material icon named "panorama horizontal select" (outlined). + static const IconData panorama_horizontal_select_outlined = IconData(0xf253, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama_photosphere</i> — material icon named "panorama photosphere". + static const IconData panorama_photosphere = IconData(0xe471, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama_photosphere</i> — material icon named "panorama photosphere" (sharp). + static const IconData panorama_photosphere_sharp = IconData(0xeb68, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama_photosphere</i> — material icon named "panorama photosphere" (round). + static const IconData panorama_photosphere_rounded = IconData(0xf0046, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama_photosphere</i> — material icon named "panorama photosphere" (outlined). + static const IconData panorama_photosphere_outlined = IconData(0xf255, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama_photosphere_select</i> — material icon named "panorama photosphere select". + static const IconData panorama_photosphere_select = IconData(0xe472, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama_photosphere_select</i> — material icon named "panorama photosphere select" (sharp). + static const IconData panorama_photosphere_select_sharp = IconData(0xeb67, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama_photosphere_select</i> — material icon named "panorama photosphere select" (round). + static const IconData panorama_photosphere_select_rounded = IconData(0xf0047, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama_photosphere_select</i> — material icon named "panorama photosphere select" (outlined). + static const IconData panorama_photosphere_select_outlined = IconData(0xf256, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama_vertical</i> — material icon named "panorama vertical". + static const IconData panorama_vertical = IconData(0xe473, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama_vertical</i> — material icon named "panorama vertical" (sharp). + static const IconData panorama_vertical_sharp = IconData(0xeb6b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama_vertical</i> — material icon named "panorama vertical" (round). + static const IconData panorama_vertical_rounded = IconData(0xf0049, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama_vertical</i> — material icon named "panorama vertical" (outlined). + static const IconData panorama_vertical_outlined = IconData(0xf257, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama_vertical_select</i> — material icon named "panorama vertical select". + static const IconData panorama_vertical_select = IconData(0xe474, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama_vertical_select</i> — material icon named "panorama vertical select" (sharp). + static const IconData panorama_vertical_select_sharp = IconData(0xeb6a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama_vertical_select</i> — material icon named "panorama vertical select" (round). + static const IconData panorama_vertical_select_rounded = IconData(0xf004a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama_vertical_select</i> — material icon named "panorama vertical select" (outlined). + static const IconData panorama_vertical_select_outlined = IconData(0xf258, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama_wide_angle</i> — material icon named "panorama wide angle". + static const IconData panorama_wide_angle = IconData(0xe475, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama_wide_angle</i> — material icon named "panorama wide angle" (sharp). + static const IconData panorama_wide_angle_sharp = IconData(0xeb6d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama_wide_angle</i> — material icon named "panorama wide angle" (round). + static const IconData panorama_wide_angle_rounded = IconData(0xf004b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama_wide_angle</i> — material icon named "panorama wide angle" (outlined). + static const IconData panorama_wide_angle_outlined = IconData(0xf259, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">panorama_wide_angle_select</i> — material icon named "panorama wide angle select". + static const IconData panorama_wide_angle_select = IconData(0xe476, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">panorama_wide_angle_select</i> — material icon named "panorama wide angle select" (sharp). + static const IconData panorama_wide_angle_select_sharp = IconData(0xeb6c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">panorama_wide_angle_select</i> — material icon named "panorama wide angle select" (round). + static const IconData panorama_wide_angle_select_rounded = IconData(0xf004c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">panorama_wide_angle_select</i> — material icon named "panorama wide angle select" (outlined). + static const IconData panorama_wide_angle_select_outlined = IconData(0xf25a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">paragliding</i> — material icon named "paragliding". + static const IconData paragliding = IconData(0xe477, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">paragliding</i> — material icon named "paragliding" (sharp). + static const IconData paragliding_sharp = IconData(0xeb6e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">paragliding</i> — material icon named "paragliding" (round). + static const IconData paragliding_rounded = IconData(0xf004d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">paragliding</i> — material icon named "paragliding" (outlined). + static const IconData paragliding_outlined = IconData(0xf25b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">park</i> — material icon named "park". + static const IconData park = IconData(0xe478, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">park</i> — material icon named "park" (sharp). + static const IconData park_sharp = IconData(0xeb6f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">park</i> — material icon named "park" (round). + static const IconData park_rounded = IconData(0xf004e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">park</i> — material icon named "park" (outlined). + static const IconData park_outlined = IconData(0xf25c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">party_mode</i> — material icon named "party mode". + static const IconData party_mode = IconData(0xe479, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">party_mode</i> — material icon named "party mode" (sharp). + static const IconData party_mode_sharp = IconData(0xeb70, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">party_mode</i> — material icon named "party mode" (round). + static const IconData party_mode_rounded = IconData(0xf004f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">party_mode</i> — material icon named "party mode" (outlined). + static const IconData party_mode_outlined = IconData(0xf25d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">password</i> — material icon named "password". + static const IconData password = IconData(0xe47a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">password</i> — material icon named "password" (sharp). + static const IconData password_sharp = IconData(0xeb71, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">password</i> — material icon named "password" (round). + static const IconData password_rounded = IconData(0xf0050, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">password</i> — material icon named "password" (outlined). + static const IconData password_outlined = IconData(0xf25e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">paste</i> — material icon named "paste". + static const IconData paste = IconData(0xe192, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">paste</i> — material icon named "paste" (sharp). + static const IconData paste_sharp = IconData(0xe890, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">paste</i> — material icon named "paste" (round). + static const IconData paste_rounded = IconData(0xf66f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">paste</i> — material icon named "paste" (outlined). + static const IconData paste_outlined = IconData(0xef82, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pattern</i> — material icon named "pattern". + static const IconData pattern = IconData(0xe47b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pattern</i> — material icon named "pattern" (sharp). + static const IconData pattern_sharp = IconData(0xeb72, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pattern</i> — material icon named "pattern" (round). + static const IconData pattern_rounded = IconData(0xf0051, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pattern</i> — material icon named "pattern" (outlined). + static const IconData pattern_outlined = IconData(0xf25f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pause</i> — material icon named "pause". + static const IconData pause = IconData(0xe47c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pause</i> — material icon named "pause" (sharp). + static const IconData pause_sharp = IconData(0xeb77, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pause</i> — material icon named "pause" (round). + static const IconData pause_rounded = IconData(0xf0056, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pause</i> — material icon named "pause" (outlined). + static const IconData pause_outlined = IconData(0xf263, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pause_circle</i> — material icon named "pause circle". + static const IconData pause_circle = IconData(0xe47d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pause_circle</i> — material icon named "pause circle" (sharp). + static const IconData pause_circle_sharp = IconData(0xeb75, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pause_circle</i> — material icon named "pause circle" (round). + static const IconData pause_circle_rounded = IconData(0xf0054, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pause_circle</i> — material icon named "pause circle" (outlined). + static const IconData pause_circle_outlined = IconData(0xf262, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pause_circle_filled</i> — material icon named "pause circle filled". + static const IconData pause_circle_filled = IconData(0xe47e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pause_circle_filled</i> — material icon named "pause circle filled" (sharp). + static const IconData pause_circle_filled_sharp = IconData(0xeb73, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pause_circle_filled</i> — material icon named "pause circle filled" (round). + static const IconData pause_circle_filled_rounded = IconData(0xf0052, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pause_circle_filled</i> — material icon named "pause circle filled" (outlined). + static const IconData pause_circle_filled_outlined = IconData(0xf260, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pause_circle_outline</i> — material icon named "pause circle outline". + static const IconData pause_circle_outline = IconData(0xe47f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pause_circle_outline</i> — material icon named "pause circle outline" (sharp). + static const IconData pause_circle_outline_sharp = IconData(0xeb74, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pause_circle_outline</i> — material icon named "pause circle outline" (round). + static const IconData pause_circle_outline_rounded = IconData(0xf0053, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pause_circle_outline</i> — material icon named "pause circle outline" (outlined). + static const IconData pause_circle_outline_outlined = IconData(0xf261, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pause_presentation</i> — material icon named "pause presentation". + static const IconData pause_presentation = IconData(0xe480, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pause_presentation</i> — material icon named "pause presentation" (sharp). + static const IconData pause_presentation_sharp = IconData(0xeb76, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pause_presentation</i> — material icon named "pause presentation" (round). + static const IconData pause_presentation_rounded = IconData(0xf0055, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pause_presentation</i> — material icon named "pause presentation" (outlined). + static const IconData pause_presentation_outlined = IconData(0xf264, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">payment</i> — material icon named "payment". + static const IconData payment = IconData(0xe481, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">payment</i> — material icon named "payment" (sharp). + static const IconData payment_sharp = IconData(0xeb78, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">payment</i> — material icon named "payment" (round). + static const IconData payment_rounded = IconData(0xf0057, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">payment</i> — material icon named "payment" (outlined). + static const IconData payment_outlined = IconData(0xf265, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">payments</i> — material icon named "payments". + static const IconData payments = IconData(0xe482, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">payments</i> — material icon named "payments" (sharp). + static const IconData payments_sharp = IconData(0xeb79, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">payments</i> — material icon named "payments" (round). + static const IconData payments_rounded = IconData(0xf0058, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">payments</i> — material icon named "payments" (outlined). + static const IconData payments_outlined = IconData(0xf266, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">paypal</i> — material icon named "paypal". + static const IconData paypal = IconData(0xf0545, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">paypal</i> — material icon named "paypal" (sharp). + static const IconData paypal_sharp = IconData(0xf044f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">paypal</i> — material icon named "paypal" (round). + static const IconData paypal_rounded = IconData(0xf035c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">paypal</i> — material icon named "paypal" (outlined). + static const IconData paypal_outlined = IconData(0xf063d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pedal_bike</i> — material icon named "pedal bike". + static const IconData pedal_bike = IconData(0xe483, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pedal_bike</i> — material icon named "pedal bike" (sharp). + static const IconData pedal_bike_sharp = IconData(0xeb7a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pedal_bike</i> — material icon named "pedal bike" (round). + static const IconData pedal_bike_rounded = IconData(0xf0059, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pedal_bike</i> — material icon named "pedal bike" (outlined). + static const IconData pedal_bike_outlined = IconData(0xf267, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pending</i> — material icon named "pending". + static const IconData pending = IconData(0xe484, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pending</i> — material icon named "pending" (sharp). + static const IconData pending_sharp = IconData(0xeb7c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pending</i> — material icon named "pending" (round). + static const IconData pending_rounded = IconData(0xf005b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pending</i> — material icon named "pending" (outlined). + static const IconData pending_outlined = IconData(0xf269, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pending_actions</i> — material icon named "pending actions". + static const IconData pending_actions = IconData(0xe485, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pending_actions</i> — material icon named "pending actions" (sharp). + static const IconData pending_actions_sharp = IconData(0xeb7b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pending_actions</i> — material icon named "pending actions" (round). + static const IconData pending_actions_rounded = IconData(0xf005a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pending_actions</i> — material icon named "pending actions" (outlined). + static const IconData pending_actions_outlined = IconData(0xf268, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pentagon</i> — material icon named "pentagon". + static const IconData pentagon = IconData(0xf0546, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pentagon</i> — material icon named "pentagon" (sharp). + static const IconData pentagon_sharp = IconData(0xf0450, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pentagon</i> — material icon named "pentagon" (round). + static const IconData pentagon_rounded = IconData(0xf035d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pentagon</i> — material icon named "pentagon" (outlined). + static const IconData pentagon_outlined = IconData(0xf063e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">people</i> — material icon named "people". + static const IconData people = IconData(0xe486, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">people</i> — material icon named "people" (sharp). + static const IconData people_sharp = IconData(0xeb7f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">people</i> — material icon named "people" (round). + static const IconData people_rounded = IconData(0xf005e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">people</i> — material icon named "people" (outlined). + static const IconData people_outlined = IconData(0xf26c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">people_alt</i> — material icon named "people alt". + static const IconData people_alt = IconData(0xe487, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">people_alt</i> — material icon named "people alt" (sharp). + static const IconData people_alt_sharp = IconData(0xeb7d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">people_alt</i> — material icon named "people alt" (round). + static const IconData people_alt_rounded = IconData(0xf005c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">people_alt</i> — material icon named "people alt" (outlined). + static const IconData people_alt_outlined = IconData(0xf26a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">people_outline</i> — material icon named "people outline". + static const IconData people_outline = IconData(0xe488, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">people_outline</i> — material icon named "people outline" (sharp). + static const IconData people_outline_sharp = IconData(0xeb7e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">people_outline</i> — material icon named "people outline" (round). + static const IconData people_outline_rounded = IconData(0xf005d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">people_outline</i> — material icon named "people outline" (outlined). + static const IconData people_outline_outlined = IconData(0xf26b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">percent</i> — material icon named "percent". + static const IconData percent = IconData(0xf0547, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">percent</i> — material icon named "percent" (sharp). + static const IconData percent_sharp = IconData(0xf0451, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">percent</i> — material icon named "percent" (round). + static const IconData percent_rounded = IconData(0xf035e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">percent</i> — material icon named "percent" (outlined). + static const IconData percent_outlined = IconData(0xf063f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">perm_camera_mic</i> — material icon named "perm camera mic". + static const IconData perm_camera_mic = IconData(0xe489, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">perm_camera_mic</i> — material icon named "perm camera mic" (sharp). + static const IconData perm_camera_mic_sharp = IconData(0xeb80, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">perm_camera_mic</i> — material icon named "perm camera mic" (round). + static const IconData perm_camera_mic_rounded = IconData(0xf005f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">perm_camera_mic</i> — material icon named "perm camera mic" (outlined). + static const IconData perm_camera_mic_outlined = IconData(0xf26d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">perm_contact_cal</i> — material icon named "perm contact cal". + static const IconData perm_contact_cal = IconData(0xe48a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">perm_contact_cal</i> — material icon named "perm contact cal" (sharp). + static const IconData perm_contact_cal_sharp = IconData(0xeb81, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">perm_contact_cal</i> — material icon named "perm contact cal" (round). + static const IconData perm_contact_cal_rounded = IconData(0xf0060, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">perm_contact_cal</i> — material icon named "perm contact cal" (outlined). + static const IconData perm_contact_cal_outlined = IconData(0xf26e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">perm_contact_calendar</i> — material icon named "perm contact calendar". + static const IconData perm_contact_calendar = IconData(0xe48a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">perm_contact_calendar</i> — material icon named "perm contact calendar" (sharp). + static const IconData perm_contact_calendar_sharp = IconData(0xeb81, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">perm_contact_calendar</i> — material icon named "perm contact calendar" (round). + static const IconData perm_contact_calendar_rounded = IconData(0xf0060, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">perm_contact_calendar</i> — material icon named "perm contact calendar" (outlined). + static const IconData perm_contact_calendar_outlined = IconData(0xf26e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">perm_data_setting</i> — material icon named "perm data setting". + static const IconData perm_data_setting = IconData(0xe48b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">perm_data_setting</i> — material icon named "perm data setting" (sharp). + static const IconData perm_data_setting_sharp = IconData(0xeb82, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">perm_data_setting</i> — material icon named "perm data setting" (round). + static const IconData perm_data_setting_rounded = IconData(0xf0061, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">perm_data_setting</i> — material icon named "perm data setting" (outlined). + static const IconData perm_data_setting_outlined = IconData(0xf26f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">perm_device_info</i> — material icon named "perm device info". + static const IconData perm_device_info = IconData(0xe48c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">perm_device_info</i> — material icon named "perm device info" (sharp). + static const IconData perm_device_info_sharp = IconData(0xeb83, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">perm_device_info</i> — material icon named "perm device info" (round). + static const IconData perm_device_info_rounded = IconData(0xf0062, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">perm_device_info</i> — material icon named "perm device info" (outlined). + static const IconData perm_device_info_outlined = IconData(0xf270, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">perm_device_information</i> — material icon named "perm device information". + static const IconData perm_device_information = IconData(0xe48c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">perm_device_information</i> — material icon named "perm device information" (sharp). + static const IconData perm_device_information_sharp = IconData(0xeb83, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">perm_device_information</i> — material icon named "perm device information" (round). + static const IconData perm_device_information_rounded = IconData(0xf0062, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">perm_device_information</i> — material icon named "perm device information" (outlined). + static const IconData perm_device_information_outlined = IconData(0xf270, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">perm_identity</i> — material icon named "perm identity". + static const IconData perm_identity = IconData(0xe48d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">perm_identity</i> — material icon named "perm identity" (sharp). + static const IconData perm_identity_sharp = IconData(0xeb84, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">perm_identity</i> — material icon named "perm identity" (round). + static const IconData perm_identity_rounded = IconData(0xf0063, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">perm_identity</i> — material icon named "perm identity" (outlined). + static const IconData perm_identity_outlined = IconData(0xf271, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">perm_media</i> — material icon named "perm media". + static const IconData perm_media = IconData(0xe48e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">perm_media</i> — material icon named "perm media" (sharp). + static const IconData perm_media_sharp = IconData(0xeb85, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">perm_media</i> — material icon named "perm media" (round). + static const IconData perm_media_rounded = IconData(0xf0064, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">perm_media</i> — material icon named "perm media" (outlined). + static const IconData perm_media_outlined = IconData(0xf272, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">perm_phone_msg</i> — material icon named "perm phone msg". + static const IconData perm_phone_msg = IconData(0xe48f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">perm_phone_msg</i> — material icon named "perm phone msg" (sharp). + static const IconData perm_phone_msg_sharp = IconData(0xeb86, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">perm_phone_msg</i> — material icon named "perm phone msg" (round). + static const IconData perm_phone_msg_rounded = IconData(0xf0065, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">perm_phone_msg</i> — material icon named "perm phone msg" (outlined). + static const IconData perm_phone_msg_outlined = IconData(0xf273, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">perm_scan_wifi</i> — material icon named "perm scan wifi". + static const IconData perm_scan_wifi = IconData(0xe490, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">perm_scan_wifi</i> — material icon named "perm scan wifi" (sharp). + static const IconData perm_scan_wifi_sharp = IconData(0xeb87, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">perm_scan_wifi</i> — material icon named "perm scan wifi" (round). + static const IconData perm_scan_wifi_rounded = IconData(0xf0066, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">perm_scan_wifi</i> — material icon named "perm scan wifi" (outlined). + static const IconData perm_scan_wifi_outlined = IconData(0xf274, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person</i> — material icon named "person". + static const IconData person = IconData(0xe491, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person</i> — material icon named "person" (sharp). + static const IconData person_sharp = IconData(0xeb93, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person</i> — material icon named "person" (round). + static const IconData person_rounded = IconData(0xf0071, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person</i> — material icon named "person" (outlined). + static const IconData person_outlined = IconData(0xf27b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_2</i> — material icon named "person 2". + static const IconData person_2 = IconData(0xf0870, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_2</i> — material icon named "person 2" (sharp). + static const IconData person_2_sharp = IconData(0xf0847, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_2</i> — material icon named "person 2" (round). + static const IconData person_2_rounded = IconData(0xf0890, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_2</i> — material icon named "person 2" (outlined). + static const IconData person_2_outlined = IconData(0xf08ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_3</i> — material icon named "person 3". + static const IconData person_3 = IconData(0xf0871, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_3</i> — material icon named "person 3" (sharp). + static const IconData person_3_sharp = IconData(0xf0848, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_3</i> — material icon named "person 3" (round). + static const IconData person_3_rounded = IconData(0xf0891, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_3</i> — material icon named "person 3" (outlined). + static const IconData person_3_outlined = IconData(0xf08af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_4</i> — material icon named "person 4". + static const IconData person_4 = IconData(0xf0872, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_4</i> — material icon named "person 4" (sharp). + static const IconData person_4_sharp = IconData(0xf0849, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_4</i> — material icon named "person 4" (round). + static const IconData person_4_rounded = IconData(0xf0892, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_4</i> — material icon named "person 4" (outlined). + static const IconData person_4_outlined = IconData(0xf08b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_add</i> — material icon named "person add". + static const IconData person_add = IconData(0xe492, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_add</i> — material icon named "person add" (sharp). + static const IconData person_add_sharp = IconData(0xeb8b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_add</i> — material icon named "person add" (round). + static const IconData person_add_rounded = IconData(0xf006a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_add</i> — material icon named "person add" (outlined). + static const IconData person_add_outlined = IconData(0xf278, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_add_alt</i> — material icon named "person add alt". + static const IconData person_add_alt = IconData(0xe493, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_add_alt</i> — material icon named "person add alt" (sharp). + static const IconData person_add_alt_sharp = IconData(0xeb89, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_add_alt</i> — material icon named "person add alt" (round). + static const IconData person_add_alt_rounded = IconData(0xf0068, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_add_alt</i> — material icon named "person add alt" (outlined). + static const IconData person_add_alt_outlined = IconData(0xf276, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_add_alt_1</i> — material icon named "person add alt 1". + static const IconData person_add_alt_1 = IconData(0xe494, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_add_alt_1</i> — material icon named "person add alt 1" (sharp). + static const IconData person_add_alt_1_sharp = IconData(0xeb88, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_add_alt_1</i> — material icon named "person add alt 1" (round). + static const IconData person_add_alt_1_rounded = IconData(0xf0067, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_add_alt_1</i> — material icon named "person add alt 1" (outlined). + static const IconData person_add_alt_1_outlined = IconData(0xf275, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_add_disabled</i> — material icon named "person add disabled". + static const IconData person_add_disabled = IconData(0xe495, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_add_disabled</i> — material icon named "person add disabled" (sharp). + static const IconData person_add_disabled_sharp = IconData(0xeb8a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_add_disabled</i> — material icon named "person add disabled" (round). + static const IconData person_add_disabled_rounded = IconData(0xf0069, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_add_disabled</i> — material icon named "person add disabled" (outlined). + static const IconData person_add_disabled_outlined = IconData(0xf277, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_off</i> — material icon named "person off". + static const IconData person_off = IconData(0xe496, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_off</i> — material icon named "person off" (sharp). + static const IconData person_off_sharp = IconData(0xeb8c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_off</i> — material icon named "person off" (round). + static const IconData person_off_rounded = IconData(0xf006b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_off</i> — material icon named "person off" (outlined). + static const IconData person_off_outlined = IconData(0xf279, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_outline</i> — material icon named "person outline". + static const IconData person_outline = IconData(0xe497, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_outline</i> — material icon named "person outline" (sharp). + static const IconData person_outline_sharp = IconData(0xeb8d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_outline</i> — material icon named "person outline" (round). + static const IconData person_outline_rounded = IconData(0xf006c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_outline</i> — material icon named "person outline" (outlined). + static const IconData person_outline_outlined = IconData(0xf27a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_pin</i> — material icon named "person pin". + static const IconData person_pin = IconData(0xe498, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_pin</i> — material icon named "person pin" (sharp). + static const IconData person_pin_sharp = IconData(0xeb8f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_pin</i> — material icon named "person pin" (round). + static const IconData person_pin_rounded = IconData(0xf006e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_pin</i> — material icon named "person pin" (outlined). + static const IconData person_pin_outlined = IconData(0xf27d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_pin_circle</i> — material icon named "person pin circle". + static const IconData person_pin_circle = IconData(0xe499, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_pin_circle</i> — material icon named "person pin circle" (sharp). + static const IconData person_pin_circle_sharp = IconData(0xeb8e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_pin_circle</i> — material icon named "person pin circle" (round). + static const IconData person_pin_circle_rounded = IconData(0xf006d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_pin_circle</i> — material icon named "person pin circle" (outlined). + static const IconData person_pin_circle_outlined = IconData(0xf27c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_remove</i> — material icon named "person remove". + static const IconData person_remove = IconData(0xe49a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_remove</i> — material icon named "person remove" (sharp). + static const IconData person_remove_sharp = IconData(0xeb91, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_remove</i> — material icon named "person remove" (round). + static const IconData person_remove_rounded = IconData(0xf0070, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_remove</i> — material icon named "person remove" (outlined). + static const IconData person_remove_outlined = IconData(0xf27f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_remove_alt_1</i> — material icon named "person remove alt 1". + static const IconData person_remove_alt_1 = IconData(0xe49b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_remove_alt_1</i> — material icon named "person remove alt 1" (sharp). + static const IconData person_remove_alt_1_sharp = IconData(0xeb90, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_remove_alt_1</i> — material icon named "person remove alt 1" (round). + static const IconData person_remove_alt_1_rounded = IconData(0xf006f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_remove_alt_1</i> — material icon named "person remove alt 1" (outlined). + static const IconData person_remove_alt_1_outlined = IconData(0xf27e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">person_search</i> — material icon named "person search". + static const IconData person_search = IconData(0xe49c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">person_search</i> — material icon named "person search" (sharp). + static const IconData person_search_sharp = IconData(0xeb92, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">person_search</i> — material icon named "person search" (round). + static const IconData person_search_rounded = IconData(0xf0072, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">person_search</i> — material icon named "person search" (outlined). + static const IconData person_search_outlined = IconData(0xf280, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">personal_injury</i> — material icon named "personal injury". + static const IconData personal_injury = IconData(0xe49d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">personal_injury</i> — material icon named "personal injury" (sharp). + static const IconData personal_injury_sharp = IconData(0xeb94, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">personal_injury</i> — material icon named "personal injury" (round). + static const IconData personal_injury_rounded = IconData(0xf0073, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">personal_injury</i> — material icon named "personal injury" (outlined). + static const IconData personal_injury_outlined = IconData(0xf281, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">personal_video</i> — material icon named "personal video". + static const IconData personal_video = IconData(0xe49e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">personal_video</i> — material icon named "personal video" (sharp). + static const IconData personal_video_sharp = IconData(0xeb95, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">personal_video</i> — material icon named "personal video" (round). + static const IconData personal_video_rounded = IconData(0xf0074, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">personal_video</i> — material icon named "personal video" (outlined). + static const IconData personal_video_outlined = IconData(0xf282, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pest_control</i> — material icon named "pest control". + static const IconData pest_control = IconData(0xe49f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pest_control</i> — material icon named "pest control" (sharp). + static const IconData pest_control_sharp = IconData(0xeb97, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pest_control</i> — material icon named "pest control" (round). + static const IconData pest_control_rounded = IconData(0xf0076, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pest_control</i> — material icon named "pest control" (outlined). + static const IconData pest_control_outlined = IconData(0xf283, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pest_control_rodent</i> — material icon named "pest control rodent". + static const IconData pest_control_rodent = IconData(0xe4a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pest_control_rodent</i> — material icon named "pest control rodent" (sharp). + static const IconData pest_control_rodent_sharp = IconData(0xeb96, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pest_control_rodent</i> — material icon named "pest control rodent" (round). + static const IconData pest_control_rodent_rounded = IconData(0xf0075, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pest_control_rodent</i> — material icon named "pest control rodent" (outlined). + static const IconData pest_control_rodent_outlined = IconData(0xf284, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pets</i> — material icon named "pets". + static const IconData pets = IconData(0xe4a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pets</i> — material icon named "pets" (sharp). + static const IconData pets_sharp = IconData(0xeb98, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pets</i> — material icon named "pets" (round). + static const IconData pets_rounded = IconData(0xf0077, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pets</i> — material icon named "pets" (outlined). + static const IconData pets_outlined = IconData(0xf285, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phishing</i> — material icon named "phishing". + static const IconData phishing = IconData(0xf0548, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phishing</i> — material icon named "phishing" (sharp). + static const IconData phishing_sharp = IconData(0xf0452, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phishing</i> — material icon named "phishing" (round). + static const IconData phishing_rounded = IconData(0xf035f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phishing</i> — material icon named "phishing" (outlined). + static const IconData phishing_outlined = IconData(0xf0640, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone</i> — material icon named "phone". + static const IconData phone = IconData(0xe4a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone</i> — material icon named "phone" (sharp). + static const IconData phone_sharp = IconData(0xeba4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone</i> — material icon named "phone" (round). + static const IconData phone_rounded = IconData(0xf0083, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone</i> — material icon named "phone" (outlined). + static const IconData phone_outlined = IconData(0xf290, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_android</i> — material icon named "phone android". + static const IconData phone_android = IconData(0xe4a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_android</i> — material icon named "phone android" (sharp). + static const IconData phone_android_sharp = IconData(0xeb99, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_android</i> — material icon named "phone android" (round). + static const IconData phone_android_rounded = IconData(0xf0078, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_android</i> — material icon named "phone android" (outlined). + static const IconData phone_android_outlined = IconData(0xf286, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_bluetooth_speaker</i> — material icon named "phone bluetooth speaker". + static const IconData phone_bluetooth_speaker = IconData(0xe4a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_bluetooth_speaker</i> — material icon named "phone bluetooth speaker" (sharp). + static const IconData phone_bluetooth_speaker_sharp = IconData(0xeb9a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_bluetooth_speaker</i> — material icon named "phone bluetooth speaker" (round). + static const IconData phone_bluetooth_speaker_rounded = IconData(0xf0079, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_bluetooth_speaker</i> — material icon named "phone bluetooth speaker" (outlined). + static const IconData phone_bluetooth_speaker_outlined = IconData(0xf287, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_callback</i> — material icon named "phone callback". + static const IconData phone_callback = IconData(0xe4a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_callback</i> — material icon named "phone callback" (sharp). + static const IconData phone_callback_sharp = IconData(0xeb9b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_callback</i> — material icon named "phone callback" (round). + static const IconData phone_callback_rounded = IconData(0xf007a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_callback</i> — material icon named "phone callback" (outlined). + static const IconData phone_callback_outlined = IconData(0xf288, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_disabled</i> — material icon named "phone disabled". + static const IconData phone_disabled = IconData(0xe4a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_disabled</i> — material icon named "phone disabled" (sharp). + static const IconData phone_disabled_sharp = IconData(0xeb9c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_disabled</i> — material icon named "phone disabled" (round). + static const IconData phone_disabled_rounded = IconData(0xf007b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_disabled</i> — material icon named "phone disabled" (outlined). + static const IconData phone_disabled_outlined = IconData(0xf289, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_enabled</i> — material icon named "phone enabled". + static const IconData phone_enabled = IconData(0xe4a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_enabled</i> — material icon named "phone enabled" (sharp). + static const IconData phone_enabled_sharp = IconData(0xeb9d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_enabled</i> — material icon named "phone enabled" (round). + static const IconData phone_enabled_rounded = IconData(0xf007c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_enabled</i> — material icon named "phone enabled" (outlined). + static const IconData phone_enabled_outlined = IconData(0xf28a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_forwarded</i> — material icon named "phone forwarded". + static const IconData phone_forwarded = IconData(0xe4a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_forwarded</i> — material icon named "phone forwarded" (sharp). + static const IconData phone_forwarded_sharp = IconData(0xeb9e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_forwarded</i> — material icon named "phone forwarded" (round). + static const IconData phone_forwarded_rounded = IconData(0xf007d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_forwarded</i> — material icon named "phone forwarded" (outlined). + static const IconData phone_forwarded_outlined = IconData(0xf28b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_in_talk</i> — material icon named "phone in talk". + static const IconData phone_in_talk = IconData(0xe4a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_in_talk</i> — material icon named "phone in talk" (sharp). + static const IconData phone_in_talk_sharp = IconData(0xeb9f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_in_talk</i> — material icon named "phone in talk" (round). + static const IconData phone_in_talk_rounded = IconData(0xf007e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_in_talk</i> — material icon named "phone in talk" (outlined). + static const IconData phone_in_talk_outlined = IconData(0xf28c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_iphone</i> — material icon named "phone iphone". + static const IconData phone_iphone = IconData(0xe4aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_iphone</i> — material icon named "phone iphone" (sharp). + static const IconData phone_iphone_sharp = IconData(0xeba0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_iphone</i> — material icon named "phone iphone" (round). + static const IconData phone_iphone_rounded = IconData(0xf007f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_iphone</i> — material icon named "phone iphone" (outlined). + static const IconData phone_iphone_outlined = IconData(0xf28d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_locked</i> — material icon named "phone locked". + static const IconData phone_locked = IconData(0xe4ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_locked</i> — material icon named "phone locked" (sharp). + static const IconData phone_locked_sharp = IconData(0xeba1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_locked</i> — material icon named "phone locked" (round). + static const IconData phone_locked_rounded = IconData(0xf0080, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_locked</i> — material icon named "phone locked" (outlined). + static const IconData phone_locked_outlined = IconData(0xf28e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_missed</i> — material icon named "phone missed". + static const IconData phone_missed = IconData(0xe4ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_missed</i> — material icon named "phone missed" (sharp). + static const IconData phone_missed_sharp = IconData(0xeba2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_missed</i> — material icon named "phone missed" (round). + static const IconData phone_missed_rounded = IconData(0xf0081, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_missed</i> — material icon named "phone missed" (outlined). + static const IconData phone_missed_outlined = IconData(0xf28f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phone_paused</i> — material icon named "phone paused". + static const IconData phone_paused = IconData(0xe4ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phone_paused</i> — material icon named "phone paused" (sharp). + static const IconData phone_paused_sharp = IconData(0xeba3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phone_paused</i> — material icon named "phone paused" (round). + static const IconData phone_paused_rounded = IconData(0xf0082, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phone_paused</i> — material icon named "phone paused" (outlined). + static const IconData phone_paused_outlined = IconData(0xf291, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phonelink</i> — material icon named "phonelink". + static const IconData phonelink = IconData(0xe4ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phonelink</i> — material icon named "phonelink" (sharp). + static const IconData phonelink_sharp = IconData(0xebaa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phonelink</i> — material icon named "phonelink" (round). + static const IconData phonelink_rounded = IconData(0xf0088, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phonelink</i> — material icon named "phonelink" (outlined). + static const IconData phonelink_outlined = IconData(0xf295, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phonelink_erase</i> — material icon named "phonelink erase". + static const IconData phonelink_erase = IconData(0xe4af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phonelink_erase</i> — material icon named "phonelink erase" (sharp). + static const IconData phonelink_erase_sharp = IconData(0xeba5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phonelink_erase</i> — material icon named "phonelink erase" (round). + static const IconData phonelink_erase_rounded = IconData(0xf0084, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phonelink_erase</i> — material icon named "phonelink erase" (outlined). + static const IconData phonelink_erase_outlined = IconData(0xf292, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phonelink_lock</i> — material icon named "phonelink lock". + static const IconData phonelink_lock = IconData(0xe4b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phonelink_lock</i> — material icon named "phonelink lock" (sharp). + static const IconData phonelink_lock_sharp = IconData(0xeba6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phonelink_lock</i> — material icon named "phonelink lock" (round). + static const IconData phonelink_lock_rounded = IconData(0xf0085, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phonelink_lock</i> — material icon named "phonelink lock" (outlined). + static const IconData phonelink_lock_outlined = IconData(0xf293, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phonelink_off</i> — material icon named "phonelink off". + static const IconData phonelink_off = IconData(0xe4b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phonelink_off</i> — material icon named "phonelink off" (sharp). + static const IconData phonelink_off_sharp = IconData(0xeba7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phonelink_off</i> — material icon named "phonelink off" (round). + static const IconData phonelink_off_rounded = IconData(0xf0086, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phonelink_off</i> — material icon named "phonelink off" (outlined). + static const IconData phonelink_off_outlined = IconData(0xf294, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phonelink_ring</i> — material icon named "phonelink ring". + static const IconData phonelink_ring = IconData(0xe4b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phonelink_ring</i> — material icon named "phonelink ring" (sharp). + static const IconData phonelink_ring_sharp = IconData(0xeba8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phonelink_ring</i> — material icon named "phonelink ring" (round). + static const IconData phonelink_ring_rounded = IconData(0xf0087, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phonelink_ring</i> — material icon named "phonelink ring" (outlined). + static const IconData phonelink_ring_outlined = IconData(0xf296, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">phonelink_setup</i> — material icon named "phonelink setup". + static const IconData phonelink_setup = IconData(0xe4b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">phonelink_setup</i> — material icon named "phonelink setup" (sharp). + static const IconData phonelink_setup_sharp = IconData(0xeba9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">phonelink_setup</i> — material icon named "phonelink setup" (round). + static const IconData phonelink_setup_rounded = IconData(0xf0089, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">phonelink_setup</i> — material icon named "phonelink setup" (outlined). + static const IconData phonelink_setup_outlined = IconData(0xf297, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">photo</i> — material icon named "photo". + static const IconData photo = IconData(0xe4b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">photo</i> — material icon named "photo" (sharp). + static const IconData photo_sharp = IconData(0xebb1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">photo</i> — material icon named "photo" (round). + static const IconData photo_rounded = IconData(0xf0090, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">photo</i> — material icon named "photo" (outlined). + static const IconData photo_outlined = IconData(0xf29e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">photo_album</i> — material icon named "photo album". + static const IconData photo_album = IconData(0xe4b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">photo_album</i> — material icon named "photo album" (sharp). + static const IconData photo_album_sharp = IconData(0xebab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">photo_album</i> — material icon named "photo album" (round). + static const IconData photo_album_rounded = IconData(0xf008a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">photo_album</i> — material icon named "photo album" (outlined). + static const IconData photo_album_outlined = IconData(0xf298, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">photo_camera</i> — material icon named "photo camera". + static const IconData photo_camera = IconData(0xe4b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">photo_camera</i> — material icon named "photo camera" (sharp). + static const IconData photo_camera_sharp = IconData(0xebae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">photo_camera</i> — material icon named "photo camera" (round). + static const IconData photo_camera_rounded = IconData(0xf008d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">photo_camera</i> — material icon named "photo camera" (outlined). + static const IconData photo_camera_outlined = IconData(0xf29b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">photo_camera_back</i> — material icon named "photo camera back". + static const IconData photo_camera_back = IconData(0xe4b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">photo_camera_back</i> — material icon named "photo camera back" (sharp). + static const IconData photo_camera_back_sharp = IconData(0xebac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">photo_camera_back</i> — material icon named "photo camera back" (round). + static const IconData photo_camera_back_rounded = IconData(0xf008b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">photo_camera_back</i> — material icon named "photo camera back" (outlined). + static const IconData photo_camera_back_outlined = IconData(0xf299, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">photo_camera_front</i> — material icon named "photo camera front". + static const IconData photo_camera_front = IconData(0xe4b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">photo_camera_front</i> — material icon named "photo camera front" (sharp). + static const IconData photo_camera_front_sharp = IconData(0xebad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">photo_camera_front</i> — material icon named "photo camera front" (round). + static const IconData photo_camera_front_rounded = IconData(0xf008c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">photo_camera_front</i> — material icon named "photo camera front" (outlined). + static const IconData photo_camera_front_outlined = IconData(0xf29a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">photo_filter</i> — material icon named "photo filter". + static const IconData photo_filter = IconData(0xe4b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">photo_filter</i> — material icon named "photo filter" (sharp). + static const IconData photo_filter_sharp = IconData(0xebaf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">photo_filter</i> — material icon named "photo filter" (round). + static const IconData photo_filter_rounded = IconData(0xf008e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">photo_filter</i> — material icon named "photo filter" (outlined). + static const IconData photo_filter_outlined = IconData(0xf29c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">photo_library</i> — material icon named "photo library". + static const IconData photo_library = IconData(0xe4ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">photo_library</i> — material icon named "photo library" (sharp). + static const IconData photo_library_sharp = IconData(0xebb0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">photo_library</i> — material icon named "photo library" (round). + static const IconData photo_library_rounded = IconData(0xf008f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">photo_library</i> — material icon named "photo library" (outlined). + static const IconData photo_library_outlined = IconData(0xf29d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">photo_size_select_actual</i> — material icon named "photo size select actual". + static const IconData photo_size_select_actual = IconData(0xe4bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">photo_size_select_actual</i> — material icon named "photo size select actual" (sharp). + static const IconData photo_size_select_actual_sharp = IconData(0xebb2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">photo_size_select_actual</i> — material icon named "photo size select actual" (round). + static const IconData photo_size_select_actual_rounded = IconData(0xf0091, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">photo_size_select_actual</i> — material icon named "photo size select actual" (outlined). + static const IconData photo_size_select_actual_outlined = IconData(0xf29f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">photo_size_select_large</i> — material icon named "photo size select large". + static const IconData photo_size_select_large = IconData(0xe4bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">photo_size_select_large</i> — material icon named "photo size select large" (sharp). + static const IconData photo_size_select_large_sharp = IconData(0xebb3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">photo_size_select_large</i> — material icon named "photo size select large" (round). + static const IconData photo_size_select_large_rounded = IconData(0xf0092, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">photo_size_select_large</i> — material icon named "photo size select large" (outlined). + static const IconData photo_size_select_large_outlined = IconData(0xf2a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">photo_size_select_small</i> — material icon named "photo size select small". + static const IconData photo_size_select_small = IconData(0xe4bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">photo_size_select_small</i> — material icon named "photo size select small" (sharp). + static const IconData photo_size_select_small_sharp = IconData(0xebb4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">photo_size_select_small</i> — material icon named "photo size select small" (round). + static const IconData photo_size_select_small_rounded = IconData(0xf0093, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">photo_size_select_small</i> — material icon named "photo size select small" (outlined). + static const IconData photo_size_select_small_outlined = IconData(0xf2a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">php</i> — material icon named "php". + static const IconData php = IconData(0xf0549, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">php</i> — material icon named "php" (sharp). + static const IconData php_sharp = IconData(0xf0453, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">php</i> — material icon named "php" (round). + static const IconData php_rounded = IconData(0xf0360, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">php</i> — material icon named "php" (outlined). + static const IconData php_outlined = IconData(0xf0641, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">piano</i> — material icon named "piano". + static const IconData piano = IconData(0xe4be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">piano</i> — material icon named "piano" (sharp). + static const IconData piano_sharp = IconData(0xebb6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">piano</i> — material icon named "piano" (round). + static const IconData piano_rounded = IconData(0xf0095, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">piano</i> — material icon named "piano" (outlined). + static const IconData piano_outlined = IconData(0xf2a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">piano_off</i> — material icon named "piano off". + static const IconData piano_off = IconData(0xe4bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">piano_off</i> — material icon named "piano off" (sharp). + static const IconData piano_off_sharp = IconData(0xebb5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">piano_off</i> — material icon named "piano off" (round). + static const IconData piano_off_rounded = IconData(0xf0094, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">piano_off</i> — material icon named "piano off" (outlined). + static const IconData piano_off_outlined = IconData(0xf2a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">picture_as_pdf</i> — material icon named "picture as pdf". + static const IconData picture_as_pdf = IconData(0xe4c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">picture_as_pdf</i> — material icon named "picture as pdf" (sharp). + static const IconData picture_as_pdf_sharp = IconData(0xebb7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">picture_as_pdf</i> — material icon named "picture as pdf" (round). + static const IconData picture_as_pdf_rounded = IconData(0xf0096, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">picture_as_pdf</i> — material icon named "picture as pdf" (outlined). + static const IconData picture_as_pdf_outlined = IconData(0xf2a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">picture_in_picture</i> — material icon named "picture in picture". + static const IconData picture_in_picture = IconData(0xe4c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">picture_in_picture</i> — material icon named "picture in picture" (sharp). + static const IconData picture_in_picture_sharp = IconData(0xebb9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">picture_in_picture</i> — material icon named "picture in picture" (round). + static const IconData picture_in_picture_rounded = IconData(0xf0098, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">picture_in_picture</i> — material icon named "picture in picture" (outlined). + static const IconData picture_in_picture_outlined = IconData(0xf2a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">picture_in_picture_alt</i> — material icon named "picture in picture alt". + static const IconData picture_in_picture_alt = IconData(0xe4c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">picture_in_picture_alt</i> — material icon named "picture in picture alt" (sharp). + static const IconData picture_in_picture_alt_sharp = IconData(0xebb8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">picture_in_picture_alt</i> — material icon named "picture in picture alt" (round). + static const IconData picture_in_picture_alt_rounded = IconData(0xf0097, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">picture_in_picture_alt</i> — material icon named "picture in picture alt" (outlined). + static const IconData picture_in_picture_alt_outlined = IconData(0xf2a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pie_chart</i> — material icon named "pie chart". + static const IconData pie_chart = IconData(0xe4c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pie_chart</i> — material icon named "pie chart" (sharp). + static const IconData pie_chart_sharp = IconData(0xebbb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pie_chart</i> — material icon named "pie chart" (round). + static const IconData pie_chart_rounded = IconData(0xf009a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pie_chart_outline</i> — material icon named "pie chart outline". + static const IconData pie_chart_outline = IconData(0xe4c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pie_chart_outline</i> — material icon named "pie chart outline" (sharp). + static const IconData pie_chart_outline_sharp = IconData(0xebba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pie_chart_outline</i> — material icon named "pie chart outline" (round). + static const IconData pie_chart_outline_rounded = IconData(0xf0099, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pie_chart_outline</i> — material icon named "pie chart outline" (outlined). + static const IconData pie_chart_outline_outlined = IconData(0xf2a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pin</i> — material icon named "pin". + static const IconData pin = IconData(0xe4c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pin</i> — material icon named "pin" (sharp). + static const IconData pin_sharp = IconData(0xebbd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pin</i> — material icon named "pin" (round). + static const IconData pin_rounded = IconData(0xf009c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pin</i> — material icon named "pin" (outlined). + static const IconData pin_outlined = IconData(0xf2aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pin_drop</i> — material icon named "pin drop". + static const IconData pin_drop = IconData(0xe4c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pin_drop</i> — material icon named "pin drop" (sharp). + static const IconData pin_drop_sharp = IconData(0xebbc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pin_drop</i> — material icon named "pin drop" (round). + static const IconData pin_drop_rounded = IconData(0xf009b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pin_drop</i> — material icon named "pin drop" (outlined). + static const IconData pin_drop_outlined = IconData(0xf2a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pin_end</i> — material icon named "pin end". + static const IconData pin_end = IconData(0xf054b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pin_end</i> — material icon named "pin end" (sharp). + static const IconData pin_end_sharp = IconData(0xf0454, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pin_end</i> — material icon named "pin end" (round). + static const IconData pin_end_rounded = IconData(0xf0361, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pin_end</i> — material icon named "pin end" (outlined). + static const IconData pin_end_outlined = IconData(0xf0642, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pin_invoke</i> — material icon named "pin invoke". + static const IconData pin_invoke = IconData(0xf054c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pin_invoke</i> — material icon named "pin invoke" (sharp). + static const IconData pin_invoke_sharp = IconData(0xf0455, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pin_invoke</i> — material icon named "pin invoke" (round). + static const IconData pin_invoke_rounded = IconData(0xf0362, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pin_invoke</i> — material icon named "pin invoke" (outlined). + static const IconData pin_invoke_outlined = IconData(0xf0643, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pinch</i> — material icon named "pinch". + static const IconData pinch = IconData(0xf054d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pinch</i> — material icon named "pinch" (sharp). + static const IconData pinch_sharp = IconData(0xf0456, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pinch</i> — material icon named "pinch" (round). + static const IconData pinch_rounded = IconData(0xf0363, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pinch</i> — material icon named "pinch" (outlined). + static const IconData pinch_outlined = IconData(0xf0644, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pivot_table_chart</i> — material icon named "pivot table chart". + static const IconData pivot_table_chart = IconData(0xe4c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pivot_table_chart</i> — material icon named "pivot table chart" (sharp). + static const IconData pivot_table_chart_sharp = IconData(0xebbe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pivot_table_chart</i> — material icon named "pivot table chart" (round). + static const IconData pivot_table_chart_rounded = IconData(0xf009d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pivot_table_chart</i> — material icon named "pivot table chart" (outlined). + static const IconData pivot_table_chart_outlined = IconData(0xf2ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pix</i> — material icon named "pix". + static const IconData pix = IconData(0xf054e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pix</i> — material icon named "pix" (sharp). + static const IconData pix_sharp = IconData(0xf0457, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pix</i> — material icon named "pix" (round). + static const IconData pix_rounded = IconData(0xf0364, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pix</i> — material icon named "pix" (outlined). + static const IconData pix_outlined = IconData(0xf0645, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">place</i> — material icon named "place". + static const IconData place = IconData(0xe4c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">place</i> — material icon named "place" (sharp). + static const IconData place_sharp = IconData(0xebbf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">place</i> — material icon named "place" (round). + static const IconData place_rounded = IconData(0xf009e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">place</i> — material icon named "place" (outlined). + static const IconData place_outlined = IconData(0xf2ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">plagiarism</i> — material icon named "plagiarism". + static const IconData plagiarism = IconData(0xe4ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">plagiarism</i> — material icon named "plagiarism" (sharp). + static const IconData plagiarism_sharp = IconData(0xebc0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">plagiarism</i> — material icon named "plagiarism" (round). + static const IconData plagiarism_rounded = IconData(0xf009f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">plagiarism</i> — material icon named "plagiarism" (outlined). + static const IconData plagiarism_outlined = IconData(0xf2ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">play_arrow</i> — material icon named "play arrow". + static const IconData play_arrow = IconData(0xe4cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">play_arrow</i> — material icon named "play arrow" (sharp). + static const IconData play_arrow_sharp = IconData(0xebc1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">play_arrow</i> — material icon named "play arrow" (round). + static const IconData play_arrow_rounded = IconData(0xf00a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">play_arrow</i> — material icon named "play arrow" (outlined). + static const IconData play_arrow_outlined = IconData(0xf2ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">play_circle</i> — material icon named "play circle". + static const IconData play_circle = IconData(0xe4cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">play_circle</i> — material icon named "play circle" (sharp). + static const IconData play_circle_sharp = IconData(0xebc4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">play_circle</i> — material icon named "play circle" (round). + static const IconData play_circle_rounded = IconData(0xf00a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">play_circle</i> — material icon named "play circle" (outlined). + static const IconData play_circle_outlined = IconData(0xf2b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">play_circle_fill</i> — material icon named "play circle fill". + static const IconData play_circle_fill = IconData(0xe4cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">play_circle_fill</i> — material icon named "play circle fill" (sharp). + static const IconData play_circle_fill_sharp = IconData(0xebc2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">play_circle_fill</i> — material icon named "play circle fill" (round). + static const IconData play_circle_fill_rounded = IconData(0xf00a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">play_circle_fill</i> — material icon named "play circle fill" (outlined). + static const IconData play_circle_fill_outlined = IconData(0xf2af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">play_circle_filled</i> — material icon named "play circle filled". + static const IconData play_circle_filled = IconData(0xe4cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">play_circle_filled</i> — material icon named "play circle filled" (sharp). + static const IconData play_circle_filled_sharp = IconData(0xebc2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">play_circle_filled</i> — material icon named "play circle filled" (round). + static const IconData play_circle_filled_rounded = IconData(0xf00a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">play_circle_filled</i> — material icon named "play circle filled" (outlined). + static const IconData play_circle_filled_outlined = IconData(0xf2af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">play_circle_outline</i> — material icon named "play circle outline". + static const IconData play_circle_outline = IconData(0xe4ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">play_circle_outline</i> — material icon named "play circle outline" (sharp). + static const IconData play_circle_outline_sharp = IconData(0xebc3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">play_circle_outline</i> — material icon named "play circle outline" (round). + static const IconData play_circle_outline_rounded = IconData(0xf00a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">play_circle_outline</i> — material icon named "play circle outline" (outlined). + static const IconData play_circle_outline_outlined = IconData(0xf2b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">play_disabled</i> — material icon named "play disabled". + static const IconData play_disabled = IconData(0xe4cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">play_disabled</i> — material icon named "play disabled" (sharp). + static const IconData play_disabled_sharp = IconData(0xebc5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">play_disabled</i> — material icon named "play disabled" (round). + static const IconData play_disabled_rounded = IconData(0xf00a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">play_disabled</i> — material icon named "play disabled" (outlined). + static const IconData play_disabled_outlined = IconData(0xf2b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">play_for_work</i> — material icon named "play for work". + static const IconData play_for_work = IconData(0xe4d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">play_for_work</i> — material icon named "play for work" (sharp). + static const IconData play_for_work_sharp = IconData(0xebc6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">play_for_work</i> — material icon named "play for work" (round). + static const IconData play_for_work_rounded = IconData(0xf00a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">play_for_work</i> — material icon named "play for work" (outlined). + static const IconData play_for_work_outlined = IconData(0xf2b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">play_lesson</i> — material icon named "play lesson". + static const IconData play_lesson = IconData(0xe4d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">play_lesson</i> — material icon named "play lesson" (sharp). + static const IconData play_lesson_sharp = IconData(0xebc7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">play_lesson</i> — material icon named "play lesson" (round). + static const IconData play_lesson_rounded = IconData(0xf00a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">play_lesson</i> — material icon named "play lesson" (outlined). + static const IconData play_lesson_outlined = IconData(0xf2b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">playlist_add</i> — material icon named "playlist add". + static const IconData playlist_add = IconData(0xe4d2, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">playlist_add</i> — material icon named "playlist add" (sharp). + static const IconData playlist_add_sharp = IconData(0xebc9, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">playlist_add</i> — material icon named "playlist add" (round). + static const IconData playlist_add_rounded = IconData(0xf00a8, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">playlist_add</i> — material icon named "playlist add" (outlined). + static const IconData playlist_add_outlined = IconData(0xf2b6, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">playlist_add_check</i> — material icon named "playlist add check". + static const IconData playlist_add_check = IconData(0xe4d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">playlist_add_check</i> — material icon named "playlist add check" (sharp). + static const IconData playlist_add_check_sharp = IconData(0xebc8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">playlist_add_check</i> — material icon named "playlist add check" (round). + static const IconData playlist_add_check_rounded = IconData(0xf00a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">playlist_add_check</i> — material icon named "playlist add check" (outlined). + static const IconData playlist_add_check_outlined = IconData(0xf2b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">playlist_add_check_circle</i> — material icon named "playlist add check circle". + static const IconData playlist_add_check_circle = IconData(0xf054f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">playlist_add_check_circle</i> — material icon named "playlist add check circle" (sharp). + static const IconData playlist_add_check_circle_sharp = IconData(0xf0458, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">playlist_add_check_circle</i> — material icon named "playlist add check circle" (round). + static const IconData playlist_add_check_circle_rounded = IconData(0xf0365, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">playlist_add_check_circle</i> — material icon named "playlist add check circle" (outlined). + static const IconData playlist_add_check_circle_outlined = IconData(0xf0646, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">playlist_add_circle</i> — material icon named "playlist add circle". + static const IconData playlist_add_circle = IconData(0xf0550, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">playlist_add_circle</i> — material icon named "playlist add circle" (sharp). + static const IconData playlist_add_circle_sharp = IconData(0xf0459, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">playlist_add_circle</i> — material icon named "playlist add circle" (round). + static const IconData playlist_add_circle_rounded = IconData(0xf0366, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">playlist_add_circle</i> — material icon named "playlist add circle" (outlined). + static const IconData playlist_add_circle_outlined = IconData(0xf0647, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">playlist_play</i> — material icon named "playlist play". + static const IconData playlist_play = IconData(0xe4d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">playlist_play</i> — material icon named "playlist play" (sharp). + static const IconData playlist_play_sharp = IconData(0xebca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">playlist_play</i> — material icon named "playlist play" (round). + static const IconData playlist_play_rounded = IconData(0xf00a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">playlist_play</i> — material icon named "playlist play" (outlined). + static const IconData playlist_play_outlined = IconData(0xf2b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">playlist_remove</i> — material icon named "playlist remove". + static const IconData playlist_remove = IconData(0xf0551, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">playlist_remove</i> — material icon named "playlist remove" (sharp). + static const IconData playlist_remove_sharp = IconData(0xf045a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">playlist_remove</i> — material icon named "playlist remove" (round). + static const IconData playlist_remove_rounded = IconData(0xf0367, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">playlist_remove</i> — material icon named "playlist remove" (outlined). + static const IconData playlist_remove_outlined = IconData(0xf0648, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">plumbing</i> — material icon named "plumbing". + static const IconData plumbing = IconData(0xe4d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">plumbing</i> — material icon named "plumbing" (sharp). + static const IconData plumbing_sharp = IconData(0xebcb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">plumbing</i> — material icon named "plumbing" (round). + static const IconData plumbing_rounded = IconData(0xf00aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">plumbing</i> — material icon named "plumbing" (outlined). + static const IconData plumbing_outlined = IconData(0xf2b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">plus_one</i> — material icon named "plus one". + static const IconData plus_one = IconData(0xe4d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">plus_one</i> — material icon named "plus one" (sharp). + static const IconData plus_one_sharp = IconData(0xebcc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">plus_one</i> — material icon named "plus one" (round). + static const IconData plus_one_rounded = IconData(0xf00ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">plus_one</i> — material icon named "plus one" (outlined). + static const IconData plus_one_outlined = IconData(0xf2b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">podcasts</i> — material icon named "podcasts". + static const IconData podcasts = IconData(0xe4d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">podcasts</i> — material icon named "podcasts" (sharp). + static const IconData podcasts_sharp = IconData(0xebcd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">podcasts</i> — material icon named "podcasts" (round). + static const IconData podcasts_rounded = IconData(0xf00ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">podcasts</i> — material icon named "podcasts" (outlined). + static const IconData podcasts_outlined = IconData(0xf2ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">point_of_sale</i> — material icon named "point of sale". + static const IconData point_of_sale = IconData(0xe4d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">point_of_sale</i> — material icon named "point of sale" (sharp). + static const IconData point_of_sale_sharp = IconData(0xebce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">point_of_sale</i> — material icon named "point of sale" (round). + static const IconData point_of_sale_rounded = IconData(0xf00ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">point_of_sale</i> — material icon named "point of sale" (outlined). + static const IconData point_of_sale_outlined = IconData(0xf2bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">policy</i> — material icon named "policy". + static const IconData policy = IconData(0xe4d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">policy</i> — material icon named "policy" (sharp). + static const IconData policy_sharp = IconData(0xebcf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">policy</i> — material icon named "policy" (round). + static const IconData policy_rounded = IconData(0xf00ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">policy</i> — material icon named "policy" (outlined). + static const IconData policy_outlined = IconData(0xf2bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">poll</i> — material icon named "poll". + static const IconData poll = IconData(0xe4da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">poll</i> — material icon named "poll" (sharp). + static const IconData poll_sharp = IconData(0xebd0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">poll</i> — material icon named "poll" (round). + static const IconData poll_rounded = IconData(0xf00af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">poll</i> — material icon named "poll" (outlined). + static const IconData poll_outlined = IconData(0xf2bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">polyline</i> — material icon named "polyline". + static const IconData polyline = IconData(0xf0552, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">polyline</i> — material icon named "polyline" (sharp). + static const IconData polyline_sharp = IconData(0xf045b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">polyline</i> — material icon named "polyline" (round). + static const IconData polyline_rounded = IconData(0xf0368, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">polyline</i> — material icon named "polyline" (outlined). + static const IconData polyline_outlined = IconData(0xf0649, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">polymer</i> — material icon named "polymer". + static const IconData polymer = IconData(0xe4db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">polymer</i> — material icon named "polymer" (sharp). + static const IconData polymer_sharp = IconData(0xebd1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">polymer</i> — material icon named "polymer" (round). + static const IconData polymer_rounded = IconData(0xf00b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">polymer</i> — material icon named "polymer" (outlined). + static const IconData polymer_outlined = IconData(0xf2be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pool</i> — material icon named "pool". + static const IconData pool = IconData(0xe4dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pool</i> — material icon named "pool" (sharp). + static const IconData pool_sharp = IconData(0xebd2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pool</i> — material icon named "pool" (round). + static const IconData pool_rounded = IconData(0xf00b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pool</i> — material icon named "pool" (outlined). + static const IconData pool_outlined = IconData(0xf2bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">portable_wifi_off</i> — material icon named "portable wifi off". + static const IconData portable_wifi_off = IconData(0xe4dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">portable_wifi_off</i> — material icon named "portable wifi off" (sharp). + static const IconData portable_wifi_off_sharp = IconData(0xebd3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">portable_wifi_off</i> — material icon named "portable wifi off" (round). + static const IconData portable_wifi_off_rounded = IconData(0xf00b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">portable_wifi_off</i> — material icon named "portable wifi off" (outlined). + static const IconData portable_wifi_off_outlined = IconData(0xf2c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">portrait</i> — material icon named "portrait". + static const IconData portrait = IconData(0xe4de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">portrait</i> — material icon named "portrait" (sharp). + static const IconData portrait_sharp = IconData(0xebd4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">portrait</i> — material icon named "portrait" (round). + static const IconData portrait_rounded = IconData(0xf00b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">portrait</i> — material icon named "portrait" (outlined). + static const IconData portrait_outlined = IconData(0xf2c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">post_add</i> — material icon named "post add". + static const IconData post_add = IconData(0xe4df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">post_add</i> — material icon named "post add" (sharp). + static const IconData post_add_sharp = IconData(0xebd5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">post_add</i> — material icon named "post add" (round). + static const IconData post_add_rounded = IconData(0xf00b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">post_add</i> — material icon named "post add" (outlined). + static const IconData post_add_outlined = IconData(0xf2c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">power</i> — material icon named "power". + static const IconData power = IconData(0xe4e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">power</i> — material icon named "power" (sharp). + static const IconData power_sharp = IconData(0xebd9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">power</i> — material icon named "power" (round). + static const IconData power_rounded = IconData(0xf00b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">power</i> — material icon named "power" (outlined). + static const IconData power_outlined = IconData(0xf2c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">power_input</i> — material icon named "power input". + static const IconData power_input = IconData(0xe4e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">power_input</i> — material icon named "power input" (sharp). + static const IconData power_input_sharp = IconData(0xebd6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">power_input</i> — material icon named "power input" (round). + static const IconData power_input_rounded = IconData(0xf00b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">power_input</i> — material icon named "power input" (outlined). + static const IconData power_input_outlined = IconData(0xf2c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">power_off</i> — material icon named "power off". + static const IconData power_off = IconData(0xe4e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">power_off</i> — material icon named "power off" (sharp). + static const IconData power_off_sharp = IconData(0xebd7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">power_off</i> — material icon named "power off" (round). + static const IconData power_off_rounded = IconData(0xf00b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">power_off</i> — material icon named "power off" (outlined). + static const IconData power_off_outlined = IconData(0xf2c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">power_settings_new</i> — material icon named "power settings new". + static const IconData power_settings_new = IconData(0xe4e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">power_settings_new</i> — material icon named "power settings new" (sharp). + static const IconData power_settings_new_sharp = IconData(0xebd8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">power_settings_new</i> — material icon named "power settings new" (round). + static const IconData power_settings_new_rounded = IconData(0xf00b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">power_settings_new</i> — material icon named "power settings new" (outlined). + static const IconData power_settings_new_outlined = IconData(0xf2c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">precision_manufacturing</i> — material icon named "precision manufacturing". + static const IconData precision_manufacturing = IconData(0xe4e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">precision_manufacturing</i> — material icon named "precision manufacturing" (sharp). + static const IconData precision_manufacturing_sharp = IconData(0xebda, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">precision_manufacturing</i> — material icon named "precision manufacturing" (round). + static const IconData precision_manufacturing_rounded = IconData(0xf00b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">precision_manufacturing</i> — material icon named "precision manufacturing" (outlined). + static const IconData precision_manufacturing_outlined = IconData(0xf2c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">pregnant_woman</i> — material icon named "pregnant woman". + static const IconData pregnant_woman = IconData(0xe4e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">pregnant_woman</i> — material icon named "pregnant woman" (sharp). + static const IconData pregnant_woman_sharp = IconData(0xebdb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">pregnant_woman</i> — material icon named "pregnant woman" (round). + static const IconData pregnant_woman_rounded = IconData(0xf00ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">pregnant_woman</i> — material icon named "pregnant woman" (outlined). + static const IconData pregnant_woman_outlined = IconData(0xf2c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">present_to_all</i> — material icon named "present to all". + static const IconData present_to_all = IconData(0xe4e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">present_to_all</i> — material icon named "present to all" (sharp). + static const IconData present_to_all_sharp = IconData(0xebdc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">present_to_all</i> — material icon named "present to all" (round). + static const IconData present_to_all_rounded = IconData(0xf00bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">present_to_all</i> — material icon named "present to all" (outlined). + static const IconData present_to_all_outlined = IconData(0xf2c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">preview</i> — material icon named "preview". + static const IconData preview = IconData(0xe4e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">preview</i> — material icon named "preview" (sharp). + static const IconData preview_sharp = IconData(0xebdd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">preview</i> — material icon named "preview" (round). + static const IconData preview_rounded = IconData(0xf00bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">preview</i> — material icon named "preview" (outlined). + static const IconData preview_outlined = IconData(0xf2ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">price_change</i> — material icon named "price change". + static const IconData price_change = IconData(0xe4e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">price_change</i> — material icon named "price change" (sharp). + static const IconData price_change_sharp = IconData(0xebde, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">price_change</i> — material icon named "price change" (round). + static const IconData price_change_rounded = IconData(0xf00bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">price_change</i> — material icon named "price change" (outlined). + static const IconData price_change_outlined = IconData(0xf2cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">price_check</i> — material icon named "price check". + static const IconData price_check = IconData(0xe4e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">price_check</i> — material icon named "price check" (sharp). + static const IconData price_check_sharp = IconData(0xebdf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">price_check</i> — material icon named "price check" (round). + static const IconData price_check_rounded = IconData(0xf00be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">price_check</i> — material icon named "price check" (outlined). + static const IconData price_check_outlined = IconData(0xf2cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">print</i> — material icon named "print". + static const IconData print = IconData(0xe4ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">print</i> — material icon named "print" (sharp). + static const IconData print_sharp = IconData(0xebe1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">print</i> — material icon named "print" (round). + static const IconData print_rounded = IconData(0xf00c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">print</i> — material icon named "print" (outlined). + static const IconData print_outlined = IconData(0xf2ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">print_disabled</i> — material icon named "print disabled". + static const IconData print_disabled = IconData(0xe4eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">print_disabled</i> — material icon named "print disabled" (sharp). + static const IconData print_disabled_sharp = IconData(0xebe0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">print_disabled</i> — material icon named "print disabled" (round). + static const IconData print_disabled_rounded = IconData(0xf00bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">print_disabled</i> — material icon named "print disabled" (outlined). + static const IconData print_disabled_outlined = IconData(0xf2cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">priority_high</i> — material icon named "priority high". + static const IconData priority_high = IconData(0xe4ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">priority_high</i> — material icon named "priority high" (sharp). + static const IconData priority_high_sharp = IconData(0xebe2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">priority_high</i> — material icon named "priority high" (round). + static const IconData priority_high_rounded = IconData(0xf00c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">priority_high</i> — material icon named "priority high" (outlined). + static const IconData priority_high_outlined = IconData(0xf2cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">privacy_tip</i> — material icon named "privacy tip". + static const IconData privacy_tip = IconData(0xe4ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">privacy_tip</i> — material icon named "privacy tip" (sharp). + static const IconData privacy_tip_sharp = IconData(0xebe3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">privacy_tip</i> — material icon named "privacy tip" (round). + static const IconData privacy_tip_rounded = IconData(0xf00c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">privacy_tip</i> — material icon named "privacy tip" (outlined). + static const IconData privacy_tip_outlined = IconData(0xf2d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">private_connectivity</i> — material icon named "private connectivity". + static const IconData private_connectivity = IconData(0xf0553, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">private_connectivity</i> — material icon named "private connectivity" (sharp). + static const IconData private_connectivity_sharp = IconData(0xf045c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">private_connectivity</i> — material icon named "private connectivity" (round). + static const IconData private_connectivity_rounded = IconData(0xf0369, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">private_connectivity</i> — material icon named "private connectivity" (outlined). + static const IconData private_connectivity_outlined = IconData(0xf064a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">production_quantity_limits</i> — material icon named "production quantity limits". + static const IconData production_quantity_limits = IconData(0xe4ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">production_quantity_limits</i> — material icon named "production quantity limits" (sharp). + static const IconData production_quantity_limits_sharp = IconData(0xebe4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">production_quantity_limits</i> — material icon named "production quantity limits" (round). + static const IconData production_quantity_limits_rounded = IconData(0xf00c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">production_quantity_limits</i> — material icon named "production quantity limits" (outlined). + static const IconData production_quantity_limits_outlined = IconData(0xf2d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">propane</i> — material icon named "propane". + static const IconData propane = IconData(0xf07b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">propane</i> — material icon named "propane" (sharp). + static const IconData propane_sharp = IconData(0xf0761, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">propane</i> — material icon named "propane" (round). + static const IconData propane_rounded = IconData(0xf0811, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">propane</i> — material icon named "propane" (outlined). + static const IconData propane_outlined = IconData(0xf0709, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">propane_tank</i> — material icon named "propane tank". + static const IconData propane_tank = IconData(0xf07ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">propane_tank</i> — material icon named "propane tank" (sharp). + static const IconData propane_tank_sharp = IconData(0xf0762, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">propane_tank</i> — material icon named "propane tank" (round). + static const IconData propane_tank_rounded = IconData(0xf0812, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">propane_tank</i> — material icon named "propane tank" (outlined). + static const IconData propane_tank_outlined = IconData(0xf070a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">psychology</i> — material icon named "psychology". + static const IconData psychology = IconData(0xe4ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">psychology</i> — material icon named "psychology" (sharp). + static const IconData psychology_sharp = IconData(0xebe5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">psychology</i> — material icon named "psychology" (round). + static const IconData psychology_rounded = IconData(0xf00c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">psychology</i> — material icon named "psychology" (outlined). + static const IconData psychology_outlined = IconData(0xf2d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">psychology_alt</i> — material icon named "psychology alt". + static const IconData psychology_alt = IconData(0xf0873, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">psychology_alt</i> — material icon named "psychology alt" (sharp). + static const IconData psychology_alt_sharp = IconData(0xf084a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">psychology_alt</i> — material icon named "psychology alt" (round). + static const IconData psychology_alt_rounded = IconData(0xf0893, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">psychology_alt</i> — material icon named "psychology alt" (outlined). + static const IconData psychology_alt_outlined = IconData(0xf08b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">public</i> — material icon named "public". + static const IconData public = IconData(0xe4f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">public</i> — material icon named "public" (sharp). + static const IconData public_sharp = IconData(0xebe7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">public</i> — material icon named "public" (round). + static const IconData public_rounded = IconData(0xf00c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">public</i> — material icon named "public" (outlined). + static const IconData public_outlined = IconData(0xf2d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">public_off</i> — material icon named "public off". + static const IconData public_off = IconData(0xe4f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">public_off</i> — material icon named "public off" (sharp). + static const IconData public_off_sharp = IconData(0xebe6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">public_off</i> — material icon named "public off" (round). + static const IconData public_off_rounded = IconData(0xf00c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">public_off</i> — material icon named "public off" (outlined). + static const IconData public_off_outlined = IconData(0xf2d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">publish</i> — material icon named "publish". + static const IconData publish = IconData(0xe4f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">publish</i> — material icon named "publish" (sharp). + static const IconData publish_sharp = IconData(0xebe8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">publish</i> — material icon named "publish" (round). + static const IconData publish_rounded = IconData(0xf00c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">publish</i> — material icon named "publish" (outlined). + static const IconData publish_outlined = IconData(0xf2d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">published_with_changes</i> — material icon named "published with changes". + static const IconData published_with_changes = IconData(0xe4f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">published_with_changes</i> — material icon named "published with changes" (sharp). + static const IconData published_with_changes_sharp = IconData(0xebe9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">published_with_changes</i> — material icon named "published with changes" (round). + static const IconData published_with_changes_rounded = IconData(0xf00c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">published_with_changes</i> — material icon named "published with changes" (outlined). + static const IconData published_with_changes_outlined = IconData(0xf2d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">punch_clock</i> — material icon named "punch clock". + static const IconData punch_clock = IconData(0xf0554, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">punch_clock</i> — material icon named "punch clock" (sharp). + static const IconData punch_clock_sharp = IconData(0xf045d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">punch_clock</i> — material icon named "punch clock" (round). + static const IconData punch_clock_rounded = IconData(0xf036a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">punch_clock</i> — material icon named "punch clock" (outlined). + static const IconData punch_clock_outlined = IconData(0xf064b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">push_pin</i> — material icon named "push pin". + static const IconData push_pin = IconData(0xe4f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">push_pin</i> — material icon named "push pin" (sharp). + static const IconData push_pin_sharp = IconData(0xebea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">push_pin</i> — material icon named "push pin" (round). + static const IconData push_pin_rounded = IconData(0xf00c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">push_pin</i> — material icon named "push pin" (outlined). + static const IconData push_pin_outlined = IconData(0xf2d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">qr_code</i> — material icon named "qr code". + static const IconData qr_code = IconData(0xe4f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">qr_code</i> — material icon named "qr code" (sharp). + static const IconData qr_code_sharp = IconData(0xebed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">qr_code</i> — material icon named "qr code" (round). + static const IconData qr_code_rounded = IconData(0xf00cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">qr_code</i> — material icon named "qr code" (outlined). + static const IconData qr_code_outlined = IconData(0xf2d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">qr_code_2</i> — material icon named "qr code 2". + static const IconData qr_code_2 = IconData(0xe4f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">qr_code_2</i> — material icon named "qr code 2" (sharp). + static const IconData qr_code_2_sharp = IconData(0xebeb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">qr_code_2</i> — material icon named "qr code 2" (round). + static const IconData qr_code_2_rounded = IconData(0xf00ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">qr_code_2</i> — material icon named "qr code 2" (outlined). + static const IconData qr_code_2_outlined = IconData(0xf2d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">qr_code_scanner</i> — material icon named "qr code scanner". + static const IconData qr_code_scanner = IconData(0xe4f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">qr_code_scanner</i> — material icon named "qr code scanner" (sharp). + static const IconData qr_code_scanner_sharp = IconData(0xebec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">qr_code_scanner</i> — material icon named "qr code scanner" (round). + static const IconData qr_code_scanner_rounded = IconData(0xf00cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">qr_code_scanner</i> — material icon named "qr code scanner" (outlined). + static const IconData qr_code_scanner_outlined = IconData(0xf2da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">query_builder</i> — material icon named "query builder". + static const IconData query_builder = IconData(0xe4f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">query_builder</i> — material icon named "query builder" (sharp). + static const IconData query_builder_sharp = IconData(0xebee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">query_builder</i> — material icon named "query builder" (round). + static const IconData query_builder_rounded = IconData(0xf00cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">query_builder</i> — material icon named "query builder" (outlined). + static const IconData query_builder_outlined = IconData(0xf2db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">query_stats</i> — material icon named "query stats". + static const IconData query_stats = IconData(0xe4f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">query_stats</i> — material icon named "query stats" (sharp). + static const IconData query_stats_sharp = IconData(0xebef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">query_stats</i> — material icon named "query stats" (round). + static const IconData query_stats_rounded = IconData(0xf00ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">query_stats</i> — material icon named "query stats" (outlined). + static const IconData query_stats_outlined = IconData(0xf2dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">question_answer</i> — material icon named "question answer". + static const IconData question_answer = IconData(0xe4fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">question_answer</i> — material icon named "question answer" (sharp). + static const IconData question_answer_sharp = IconData(0xebf0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">question_answer</i> — material icon named "question answer" (round). + static const IconData question_answer_rounded = IconData(0xf00cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">question_answer</i> — material icon named "question answer" (outlined). + static const IconData question_answer_outlined = IconData(0xf2dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">question_mark</i> — material icon named "question mark". + static const IconData question_mark = IconData(0xf0555, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">question_mark</i> — material icon named "question mark" (sharp). + static const IconData question_mark_sharp = IconData(0xf045e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">question_mark</i> — material icon named "question mark" (round). + static const IconData question_mark_rounded = IconData(0xf036b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">question_mark</i> — material icon named "question mark" (outlined). + static const IconData question_mark_outlined = IconData(0xf064c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">queue</i> — material icon named "queue". + static const IconData queue = IconData(0xe4fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">queue</i> — material icon named "queue" (sharp). + static const IconData queue_sharp = IconData(0xebf3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">queue</i> — material icon named "queue" (round). + static const IconData queue_rounded = IconData(0xf00d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">queue</i> — material icon named "queue" (outlined). + static const IconData queue_outlined = IconData(0xf2df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">queue_music</i> — material icon named "queue music". + static const IconData queue_music = IconData(0xe4fc, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">queue_music</i> — material icon named "queue music" (sharp). + static const IconData queue_music_sharp = IconData(0xebf1, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">queue_music</i> — material icon named "queue music" (round). + static const IconData queue_music_rounded = IconData(0xf00d0, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">queue_music</i> — material icon named "queue music" (outlined). + static const IconData queue_music_outlined = IconData(0xf2de, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">queue_play_next</i> — material icon named "queue play next". + static const IconData queue_play_next = IconData(0xe4fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">queue_play_next</i> — material icon named "queue play next" (sharp). + static const IconData queue_play_next_sharp = IconData(0xebf2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">queue_play_next</i> — material icon named "queue play next" (round). + static const IconData queue_play_next_rounded = IconData(0xf00d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">queue_play_next</i> — material icon named "queue play next" (outlined). + static const IconData queue_play_next_outlined = IconData(0xf2e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">quick_contacts_dialer</i> — material icon named "quick contacts dialer". + static const IconData quick_contacts_dialer = IconData(0xe18c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">quick_contacts_dialer</i> — material icon named "quick contacts dialer" (sharp). + static const IconData quick_contacts_dialer_sharp = IconData(0xe889, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">quick_contacts_dialer</i> — material icon named "quick contacts dialer" (round). + static const IconData quick_contacts_dialer_rounded = IconData(0xf668, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">quick_contacts_dialer</i> — material icon named "quick contacts dialer" (outlined). + static const IconData quick_contacts_dialer_outlined = IconData(0xef7b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">quick_contacts_mail</i> — material icon named "quick contacts mail". + static const IconData quick_contacts_mail = IconData(0xe18a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">quick_contacts_mail</i> — material icon named "quick contacts mail" (sharp). + static const IconData quick_contacts_mail_sharp = IconData(0xe887, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">quick_contacts_mail</i> — material icon named "quick contacts mail" (round). + static const IconData quick_contacts_mail_rounded = IconData(0xf666, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">quick_contacts_mail</i> — material icon named "quick contacts mail" (outlined). + static const IconData quick_contacts_mail_outlined = IconData(0xef79, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">quickreply</i> — material icon named "quickreply". + static const IconData quickreply = IconData(0xe4fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">quickreply</i> — material icon named "quickreply" (sharp). + static const IconData quickreply_sharp = IconData(0xebf4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">quickreply</i> — material icon named "quickreply" (round). + static const IconData quickreply_rounded = IconData(0xf00d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">quickreply</i> — material icon named "quickreply" (outlined). + static const IconData quickreply_outlined = IconData(0xf2e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">quiz</i> — material icon named "quiz". + static const IconData quiz = IconData(0xe4ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">quiz</i> — material icon named "quiz" (sharp). + static const IconData quiz_sharp = IconData(0xebf5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">quiz</i> — material icon named "quiz" (round). + static const IconData quiz_rounded = IconData(0xf00d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">quiz</i> — material icon named "quiz" (outlined). + static const IconData quiz_outlined = IconData(0xf2e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">quora</i> — material icon named "quora". + static const IconData quora = IconData(0xf0556, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">quora</i> — material icon named "quora" (sharp). + static const IconData quora_sharp = IconData(0xf045f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">quora</i> — material icon named "quora" (round). + static const IconData quora_rounded = IconData(0xf036c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">quora</i> — material icon named "quora" (outlined). + static const IconData quora_outlined = IconData(0xf064d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">r_mobiledata</i> — material icon named "r mobiledata". + static const IconData r_mobiledata = IconData(0xe500, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">r_mobiledata</i> — material icon named "r mobiledata" (sharp). + static const IconData r_mobiledata_sharp = IconData(0xebf6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">r_mobiledata</i> — material icon named "r mobiledata" (round). + static const IconData r_mobiledata_rounded = IconData(0xf00d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">r_mobiledata</i> — material icon named "r mobiledata" (outlined). + static const IconData r_mobiledata_outlined = IconData(0xf2e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">radar</i> — material icon named "radar". + static const IconData radar = IconData(0xe501, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">radar</i> — material icon named "radar" (sharp). + static const IconData radar_sharp = IconData(0xebf7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">radar</i> — material icon named "radar" (round). + static const IconData radar_rounded = IconData(0xf00d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">radar</i> — material icon named "radar" (outlined). + static const IconData radar_outlined = IconData(0xf2e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">radio</i> — material icon named "radio". + static const IconData radio = IconData(0xe502, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">radio</i> — material icon named "radio" (sharp). + static const IconData radio_sharp = IconData(0xebfa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">radio</i> — material icon named "radio" (round). + static const IconData radio_rounded = IconData(0xf00d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">radio</i> — material icon named "radio" (outlined). + static const IconData radio_outlined = IconData(0xf2e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">radio_button_checked</i> — material icon named "radio button checked". + static const IconData radio_button_checked = IconData(0xe503, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">radio_button_checked</i> — material icon named "radio button checked" (sharp). + static const IconData radio_button_checked_sharp = IconData(0xebf8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">radio_button_checked</i> — material icon named "radio button checked" (round). + static const IconData radio_button_checked_rounded = IconData(0xf00d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">radio_button_checked</i> — material icon named "radio button checked" (outlined). + static const IconData radio_button_checked_outlined = IconData(0xf2e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">radio_button_off</i> — material icon named "radio button off". + static const IconData radio_button_off = IconData(0xe504, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">radio_button_off</i> — material icon named "radio button off" (sharp). + static const IconData radio_button_off_sharp = IconData(0xebf9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">radio_button_off</i> — material icon named "radio button off" (round). + static const IconData radio_button_off_rounded = IconData(0xf00d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">radio_button_off</i> — material icon named "radio button off" (outlined). + static const IconData radio_button_off_outlined = IconData(0xf2e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">radio_button_on</i> — material icon named "radio button on". + static const IconData radio_button_on = IconData(0xe503, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">radio_button_on</i> — material icon named "radio button on" (sharp). + static const IconData radio_button_on_sharp = IconData(0xebf8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">radio_button_on</i> — material icon named "radio button on" (round). + static const IconData radio_button_on_rounded = IconData(0xf00d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">radio_button_on</i> — material icon named "radio button on" (outlined). + static const IconData radio_button_on_outlined = IconData(0xf2e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">radio_button_unchecked</i> — material icon named "radio button unchecked". + static const IconData radio_button_unchecked = IconData(0xe504, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">radio_button_unchecked</i> — material icon named "radio button unchecked" (sharp). + static const IconData radio_button_unchecked_sharp = IconData(0xebf9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">radio_button_unchecked</i> — material icon named "radio button unchecked" (round). + static const IconData radio_button_unchecked_rounded = IconData(0xf00d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">radio_button_unchecked</i> — material icon named "radio button unchecked" (outlined). + static const IconData radio_button_unchecked_outlined = IconData(0xf2e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">railway_alert</i> — material icon named "railway alert". + static const IconData railway_alert = IconData(0xe505, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">railway_alert</i> — material icon named "railway alert" (sharp). + static const IconData railway_alert_sharp = IconData(0xebfb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">railway_alert</i> — material icon named "railway alert" (round). + static const IconData railway_alert_rounded = IconData(0xf00da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">railway_alert</i> — material icon named "railway alert" (outlined). + static const IconData railway_alert_outlined = IconData(0xf2e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ramen_dining</i> — material icon named "ramen dining". + static const IconData ramen_dining = IconData(0xe506, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ramen_dining</i> — material icon named "ramen dining" (sharp). + static const IconData ramen_dining_sharp = IconData(0xebfc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ramen_dining</i> — material icon named "ramen dining" (round). + static const IconData ramen_dining_rounded = IconData(0xf00db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ramen_dining</i> — material icon named "ramen dining" (outlined). + static const IconData ramen_dining_outlined = IconData(0xf2e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ramp_left</i> — material icon named "ramp left". + static const IconData ramp_left = IconData(0xf0557, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ramp_left</i> — material icon named "ramp left" (sharp). + static const IconData ramp_left_sharp = IconData(0xf0460, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ramp_left</i> — material icon named "ramp left" (round). + static const IconData ramp_left_rounded = IconData(0xf036d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ramp_left</i> — material icon named "ramp left" (outlined). + static const IconData ramp_left_outlined = IconData(0xf064e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ramp_right</i> — material icon named "ramp right". + static const IconData ramp_right = IconData(0xf0558, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ramp_right</i> — material icon named "ramp right" (sharp). + static const IconData ramp_right_sharp = IconData(0xf0461, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ramp_right</i> — material icon named "ramp right" (round). + static const IconData ramp_right_rounded = IconData(0xf036e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ramp_right</i> — material icon named "ramp right" (outlined). + static const IconData ramp_right_outlined = IconData(0xf064f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rate_review</i> — material icon named "rate review". + static const IconData rate_review = IconData(0xe507, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rate_review</i> — material icon named "rate review" (sharp). + static const IconData rate_review_sharp = IconData(0xebfd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rate_review</i> — material icon named "rate review" (round). + static const IconData rate_review_rounded = IconData(0xf00dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rate_review</i> — material icon named "rate review" (outlined). + static const IconData rate_review_outlined = IconData(0xf2ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">raw_off</i> — material icon named "raw off". + static const IconData raw_off = IconData(0xe508, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">raw_off</i> — material icon named "raw off" (sharp). + static const IconData raw_off_sharp = IconData(0xebfe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">raw_off</i> — material icon named "raw off" (round). + static const IconData raw_off_rounded = IconData(0xf00dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">raw_off</i> — material icon named "raw off" (outlined). + static const IconData raw_off_outlined = IconData(0xf2eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">raw_on</i> — material icon named "raw on". + static const IconData raw_on = IconData(0xe509, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">raw_on</i> — material icon named "raw on" (sharp). + static const IconData raw_on_sharp = IconData(0xebff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">raw_on</i> — material icon named "raw on" (round). + static const IconData raw_on_rounded = IconData(0xf00de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">raw_on</i> — material icon named "raw on" (outlined). + static const IconData raw_on_outlined = IconData(0xf2ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">read_more</i> — material icon named "read more". + static const IconData read_more = IconData(0xe50a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">read_more</i> — material icon named "read more" (sharp). + static const IconData read_more_sharp = IconData(0xec00, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">read_more</i> — material icon named "read more" (round). + static const IconData read_more_rounded = IconData(0xf00df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">read_more</i> — material icon named "read more" (outlined). + static const IconData read_more_outlined = IconData(0xf2ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">real_estate_agent</i> — material icon named "real estate agent". + static const IconData real_estate_agent = IconData(0xe50b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">real_estate_agent</i> — material icon named "real estate agent" (sharp). + static const IconData real_estate_agent_sharp = IconData(0xec01, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">real_estate_agent</i> — material icon named "real estate agent" (round). + static const IconData real_estate_agent_rounded = IconData(0xf00e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">real_estate_agent</i> — material icon named "real estate agent" (outlined). + static const IconData real_estate_agent_outlined = IconData(0xf2ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rebase_edit</i> — material icon named "rebase edit". + static const IconData rebase_edit = IconData(0xf0874, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">receipt</i> — material icon named "receipt". + static const IconData receipt = IconData(0xe50c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">receipt</i> — material icon named "receipt" (sharp). + static const IconData receipt_sharp = IconData(0xec03, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">receipt</i> — material icon named "receipt" (round). + static const IconData receipt_rounded = IconData(0xf00e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">receipt</i> — material icon named "receipt" (outlined). + static const IconData receipt_outlined = IconData(0xf2f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">receipt_long</i> — material icon named "receipt long". + static const IconData receipt_long = IconData(0xe50d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">receipt_long</i> — material icon named "receipt long" (sharp). + static const IconData receipt_long_sharp = IconData(0xec02, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">receipt_long</i> — material icon named "receipt long" (round). + static const IconData receipt_long_rounded = IconData(0xf00e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">receipt_long</i> — material icon named "receipt long" (outlined). + static const IconData receipt_long_outlined = IconData(0xf2ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">recent_actors</i> — material icon named "recent actors". + static const IconData recent_actors = IconData(0xe50e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">recent_actors</i> — material icon named "recent actors" (sharp). + static const IconData recent_actors_sharp = IconData(0xec04, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">recent_actors</i> — material icon named "recent actors" (round). + static const IconData recent_actors_rounded = IconData(0xf00e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">recent_actors</i> — material icon named "recent actors" (outlined). + static const IconData recent_actors_outlined = IconData(0xf2f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">recommend</i> — material icon named "recommend". + static const IconData recommend = IconData(0xe50f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">recommend</i> — material icon named "recommend" (sharp). + static const IconData recommend_sharp = IconData(0xec05, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">recommend</i> — material icon named "recommend" (round). + static const IconData recommend_rounded = IconData(0xf00e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">recommend</i> — material icon named "recommend" (outlined). + static const IconData recommend_outlined = IconData(0xf2f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">record_voice_over</i> — material icon named "record voice over". + static const IconData record_voice_over = IconData(0xe510, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">record_voice_over</i> — material icon named "record voice over" (sharp). + static const IconData record_voice_over_sharp = IconData(0xec06, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">record_voice_over</i> — material icon named "record voice over" (round). + static const IconData record_voice_over_rounded = IconData(0xf00e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">record_voice_over</i> — material icon named "record voice over" (outlined). + static const IconData record_voice_over_outlined = IconData(0xf2f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rectangle</i> — material icon named "rectangle". + static const IconData rectangle = IconData(0xf0559, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rectangle</i> — material icon named "rectangle" (sharp). + static const IconData rectangle_sharp = IconData(0xf0462, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rectangle</i> — material icon named "rectangle" (round). + static const IconData rectangle_rounded = IconData(0xf036f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rectangle</i> — material icon named "rectangle" (outlined). + static const IconData rectangle_outlined = IconData(0xf0650, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">recycling</i> — material icon named "recycling". + static const IconData recycling = IconData(0xf055a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">recycling</i> — material icon named "recycling" (sharp). + static const IconData recycling_sharp = IconData(0xf0463, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">recycling</i> — material icon named "recycling" (round). + static const IconData recycling_rounded = IconData(0xf0370, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">recycling</i> — material icon named "recycling" (outlined). + static const IconData recycling_outlined = IconData(0xf0651, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">reddit</i> — material icon named "reddit". + static const IconData reddit = IconData(0xf055b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">reddit</i> — material icon named "reddit" (sharp). + static const IconData reddit_sharp = IconData(0xf0464, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">reddit</i> — material icon named "reddit" (round). + static const IconData reddit_rounded = IconData(0xf0371, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">reddit</i> — material icon named "reddit" (outlined). + static const IconData reddit_outlined = IconData(0xf0652, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">redeem</i> — material icon named "redeem". + static const IconData redeem = IconData(0xe511, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">redeem</i> — material icon named "redeem" (sharp). + static const IconData redeem_sharp = IconData(0xec07, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">redeem</i> — material icon named "redeem" (round). + static const IconData redeem_rounded = IconData(0xf00e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">redeem</i> — material icon named "redeem" (outlined). + static const IconData redeem_outlined = IconData(0xf2f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">redo</i> — material icon named "redo". + static const IconData redo = IconData(0xe512, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">redo</i> — material icon named "redo" (sharp). + static const IconData redo_sharp = IconData(0xec08, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">redo</i> — material icon named "redo" (round). + static const IconData redo_rounded = IconData(0xf00e7, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">redo</i> — material icon named "redo" (outlined). + static const IconData redo_outlined = IconData(0xf2f5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">reduce_capacity</i> — material icon named "reduce capacity". + static const IconData reduce_capacity = IconData(0xe513, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">reduce_capacity</i> — material icon named "reduce capacity" (sharp). + static const IconData reduce_capacity_sharp = IconData(0xec09, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">reduce_capacity</i> — material icon named "reduce capacity" (round). + static const IconData reduce_capacity_rounded = IconData(0xf00e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">reduce_capacity</i> — material icon named "reduce capacity" (outlined). + static const IconData reduce_capacity_outlined = IconData(0xf2f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">refresh</i> — material icon named "refresh". + static const IconData refresh = IconData(0xe514, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">refresh</i> — material icon named "refresh" (sharp). + static const IconData refresh_sharp = IconData(0xec0a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">refresh</i> — material icon named "refresh" (round). + static const IconData refresh_rounded = IconData(0xf00e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">refresh</i> — material icon named "refresh" (outlined). + static const IconData refresh_outlined = IconData(0xf2f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">remember_me</i> — material icon named "remember me". + static const IconData remember_me = IconData(0xe515, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">remember_me</i> — material icon named "remember me" (sharp). + static const IconData remember_me_sharp = IconData(0xec0b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">remember_me</i> — material icon named "remember me" (round). + static const IconData remember_me_rounded = IconData(0xf00ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">remember_me</i> — material icon named "remember me" (outlined). + static const IconData remember_me_outlined = IconData(0xf2f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">remove</i> — material icon named "remove". + static const IconData remove = IconData(0xe516, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">remove</i> — material icon named "remove" (sharp). + static const IconData remove_sharp = IconData(0xec12, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">remove</i> — material icon named "remove" (round). + static const IconData remove_rounded = IconData(0xf00f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">remove</i> — material icon named "remove" (outlined). + static const IconData remove_outlined = IconData(0xf2fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">remove_circle</i> — material icon named "remove circle". + static const IconData remove_circle = IconData(0xe517, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">remove_circle</i> — material icon named "remove circle" (sharp). + static const IconData remove_circle_sharp = IconData(0xec0d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">remove_circle</i> — material icon named "remove circle" (round). + static const IconData remove_circle_rounded = IconData(0xf00ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">remove_circle</i> — material icon named "remove circle" (outlined). + static const IconData remove_circle_outlined = IconData(0xf2fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">remove_circle_outline</i> — material icon named "remove circle outline". + static const IconData remove_circle_outline = IconData(0xe518, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">remove_circle_outline</i> — material icon named "remove circle outline" (sharp). + static const IconData remove_circle_outline_sharp = IconData(0xec0c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">remove_circle_outline</i> — material icon named "remove circle outline" (round). + static const IconData remove_circle_outline_rounded = IconData(0xf00eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">remove_circle_outline</i> — material icon named "remove circle outline" (outlined). + static const IconData remove_circle_outline_outlined = IconData(0xf2f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">remove_done</i> — material icon named "remove done". + static const IconData remove_done = IconData(0xe519, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">remove_done</i> — material icon named "remove done" (sharp). + static const IconData remove_done_sharp = IconData(0xec0e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">remove_done</i> — material icon named "remove done" (round). + static const IconData remove_done_rounded = IconData(0xf00ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">remove_done</i> — material icon named "remove done" (outlined). + static const IconData remove_done_outlined = IconData(0xf2fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">remove_from_queue</i> — material icon named "remove from queue". + static const IconData remove_from_queue = IconData(0xe51a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">remove_from_queue</i> — material icon named "remove from queue" (sharp). + static const IconData remove_from_queue_sharp = IconData(0xec0f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">remove_from_queue</i> — material icon named "remove from queue" (round). + static const IconData remove_from_queue_rounded = IconData(0xf00ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">remove_from_queue</i> — material icon named "remove from queue" (outlined). + static const IconData remove_from_queue_outlined = IconData(0xf2fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">remove_moderator</i> — material icon named "remove moderator". + static const IconData remove_moderator = IconData(0xe51b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">remove_moderator</i> — material icon named "remove moderator" (sharp). + static const IconData remove_moderator_sharp = IconData(0xec10, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">remove_moderator</i> — material icon named "remove moderator" (round). + static const IconData remove_moderator_rounded = IconData(0xf00ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">remove_moderator</i> — material icon named "remove moderator" (outlined). + static const IconData remove_moderator_outlined = IconData(0xf2fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">remove_red_eye</i> — material icon named "remove red eye". + static const IconData remove_red_eye = IconData(0xe51c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">remove_red_eye</i> — material icon named "remove red eye" (sharp). + static const IconData remove_red_eye_sharp = IconData(0xec11, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">remove_red_eye</i> — material icon named "remove red eye" (round). + static const IconData remove_red_eye_rounded = IconData(0xf00f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">remove_red_eye</i> — material icon named "remove red eye" (outlined). + static const IconData remove_red_eye_outlined = IconData(0xf2ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">remove_road</i> — material icon named "remove road". + static const IconData remove_road = IconData(0xf07bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">remove_road</i> — material icon named "remove road" (sharp). + static const IconData remove_road_sharp = IconData(0xf0763, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">remove_road</i> — material icon named "remove road" (round). + static const IconData remove_road_rounded = IconData(0xf0813, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">remove_road</i> — material icon named "remove road" (outlined). + static const IconData remove_road_outlined = IconData(0xf070b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">remove_shopping_cart</i> — material icon named "remove shopping cart". + static const IconData remove_shopping_cart = IconData(0xe51d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">remove_shopping_cart</i> — material icon named "remove shopping cart" (sharp). + static const IconData remove_shopping_cart_sharp = IconData(0xec13, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">remove_shopping_cart</i> — material icon named "remove shopping cart" (round). + static const IconData remove_shopping_cart_rounded = IconData(0xf00f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">remove_shopping_cart</i> — material icon named "remove shopping cart" (outlined). + static const IconData remove_shopping_cart_outlined = IconData(0xf300, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">reorder</i> — material icon named "reorder". + static const IconData reorder = IconData(0xe51e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">reorder</i> — material icon named "reorder" (sharp). + static const IconData reorder_sharp = IconData(0xec14, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">reorder</i> — material icon named "reorder" (round). + static const IconData reorder_rounded = IconData(0xf00f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">reorder</i> — material icon named "reorder" (outlined). + static const IconData reorder_outlined = IconData(0xf301, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">repartition</i> — material icon named "repartition". + static const IconData repartition = IconData(0xf0875, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">repartition</i> — material icon named "repartition" (sharp). + static const IconData repartition_sharp = IconData(0xf084b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">repartition</i> — material icon named "repartition" (round). + static const IconData repartition_rounded = IconData(0xf0894, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">repartition</i> — material icon named "repartition" (outlined). + static const IconData repartition_outlined = IconData(0xf08b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">repeat</i> — material icon named "repeat". + static const IconData repeat = IconData(0xe51f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">repeat</i> — material icon named "repeat" (sharp). + static const IconData repeat_sharp = IconData(0xec18, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">repeat</i> — material icon named "repeat" (round). + static const IconData repeat_rounded = IconData(0xf00f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">repeat</i> — material icon named "repeat" (outlined). + static const IconData repeat_outlined = IconData(0xf305, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">repeat_on</i> — material icon named "repeat on". + static const IconData repeat_on = IconData(0xe520, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">repeat_on</i> — material icon named "repeat on" (sharp). + static const IconData repeat_on_sharp = IconData(0xec15, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">repeat_on</i> — material icon named "repeat on" (round). + static const IconData repeat_on_rounded = IconData(0xf00f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">repeat_on</i> — material icon named "repeat on" (outlined). + static const IconData repeat_on_outlined = IconData(0xf302, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">repeat_one</i> — material icon named "repeat one". + static const IconData repeat_one = IconData(0xe521, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">repeat_one</i> — material icon named "repeat one" (sharp). + static const IconData repeat_one_sharp = IconData(0xec17, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">repeat_one</i> — material icon named "repeat one" (round). + static const IconData repeat_one_rounded = IconData(0xf00f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">repeat_one</i> — material icon named "repeat one" (outlined). + static const IconData repeat_one_outlined = IconData(0xf304, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">repeat_one_on</i> — material icon named "repeat one on". + static const IconData repeat_one_on = IconData(0xe522, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">repeat_one_on</i> — material icon named "repeat one on" (sharp). + static const IconData repeat_one_on_sharp = IconData(0xec16, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">repeat_one_on</i> — material icon named "repeat one on" (round). + static const IconData repeat_one_on_rounded = IconData(0xf00f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">repeat_one_on</i> — material icon named "repeat one on" (outlined). + static const IconData repeat_one_on_outlined = IconData(0xf303, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">replay</i> — material icon named "replay". + static const IconData replay = IconData(0xe523, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">replay</i> — material icon named "replay" (sharp). + static const IconData replay_sharp = IconData(0xec1d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">replay</i> — material icon named "replay" (round). + static const IconData replay_rounded = IconData(0xf00fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">replay</i> — material icon named "replay" (outlined). + static const IconData replay_outlined = IconData(0xf30a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">replay_10</i> — material icon named "replay 10". + static const IconData replay_10 = IconData(0xe524, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">replay_10</i> — material icon named "replay 10" (sharp). + static const IconData replay_10_sharp = IconData(0xec19, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">replay_10</i> — material icon named "replay 10" (round). + static const IconData replay_10_rounded = IconData(0xf00f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">replay_10</i> — material icon named "replay 10" (outlined). + static const IconData replay_10_outlined = IconData(0xf306, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">replay_30</i> — material icon named "replay 30". + static const IconData replay_30 = IconData(0xe525, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">replay_30</i> — material icon named "replay 30" (sharp). + static const IconData replay_30_sharp = IconData(0xec1a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">replay_30</i> — material icon named "replay 30" (round). + static const IconData replay_30_rounded = IconData(0xf00f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">replay_30</i> — material icon named "replay 30" (outlined). + static const IconData replay_30_outlined = IconData(0xf307, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">replay_5</i> — material icon named "replay 5". + static const IconData replay_5 = IconData(0xe526, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">replay_5</i> — material icon named "replay 5" (sharp). + static const IconData replay_5_sharp = IconData(0xec1b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">replay_5</i> — material icon named "replay 5" (round). + static const IconData replay_5_rounded = IconData(0xf00fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">replay_5</i> — material icon named "replay 5" (outlined). + static const IconData replay_5_outlined = IconData(0xf308, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">replay_circle_filled</i> — material icon named "replay circle filled". + static const IconData replay_circle_filled = IconData(0xe527, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">replay_circle_filled</i> — material icon named "replay circle filled" (sharp). + static const IconData replay_circle_filled_sharp = IconData(0xec1c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">replay_circle_filled</i> — material icon named "replay circle filled" (round). + static const IconData replay_circle_filled_rounded = IconData(0xf00fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">replay_circle_filled</i> — material icon named "replay circle filled" (outlined). + static const IconData replay_circle_filled_outlined = IconData(0xf309, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">reply</i> — material icon named "reply". + static const IconData reply = IconData(0xe528, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">reply</i> — material icon named "reply" (sharp). + static const IconData reply_sharp = IconData(0xec1f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">reply</i> — material icon named "reply" (round). + static const IconData reply_rounded = IconData(0xf00fe, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">reply</i> — material icon named "reply" (outlined). + static const IconData reply_outlined = IconData(0xf30c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">reply_all</i> — material icon named "reply all". + static const IconData reply_all = IconData(0xe529, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">reply_all</i> — material icon named "reply all" (sharp). + static const IconData reply_all_sharp = IconData(0xec1e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">reply_all</i> — material icon named "reply all" (round). + static const IconData reply_all_rounded = IconData(0xf00fd, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">reply_all</i> — material icon named "reply all" (outlined). + static const IconData reply_all_outlined = IconData(0xf30b, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">report</i> — material icon named "report". + static const IconData report = IconData(0xe52a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">report</i> — material icon named "report" (sharp). + static const IconData report_sharp = IconData(0xec23, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">report</i> — material icon named "report" (round). + static const IconData report_rounded = IconData(0xf0102, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">report</i> — material icon named "report" (outlined). + static const IconData report_outlined = IconData(0xf30f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">report_gmailerrorred</i> — material icon named "report gmailerrorred". + static const IconData report_gmailerrorred = IconData(0xe52b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">report_gmailerrorred</i> — material icon named "report gmailerrorred" (sharp). + static const IconData report_gmailerrorred_sharp = IconData(0xec20, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">report_gmailerrorred</i> — material icon named "report gmailerrorred" (round). + static const IconData report_gmailerrorred_rounded = IconData(0xf00ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">report_gmailerrorred</i> — material icon named "report gmailerrorred" (outlined). + static const IconData report_gmailerrorred_outlined = IconData(0xf30d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">report_off</i> — material icon named "report off". + static const IconData report_off = IconData(0xe52c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">report_off</i> — material icon named "report off" (sharp). + static const IconData report_off_sharp = IconData(0xec21, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">report_off</i> — material icon named "report off" (round). + static const IconData report_off_rounded = IconData(0xf0100, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">report_off</i> — material icon named "report off" (outlined). + static const IconData report_off_outlined = IconData(0xf30e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">report_problem</i> — material icon named "report problem". + static const IconData report_problem = IconData(0xe52d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">report_problem</i> — material icon named "report problem" (sharp). + static const IconData report_problem_sharp = IconData(0xec22, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">report_problem</i> — material icon named "report problem" (round). + static const IconData report_problem_rounded = IconData(0xf0101, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">report_problem</i> — material icon named "report problem" (outlined). + static const IconData report_problem_outlined = IconData(0xf310, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">request_page</i> — material icon named "request page". + static const IconData request_page = IconData(0xe52e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">request_page</i> — material icon named "request page" (sharp). + static const IconData request_page_sharp = IconData(0xec24, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">request_page</i> — material icon named "request page" (round). + static const IconData request_page_rounded = IconData(0xf0103, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">request_page</i> — material icon named "request page" (outlined). + static const IconData request_page_outlined = IconData(0xf311, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">request_quote</i> — material icon named "request quote". + static const IconData request_quote = IconData(0xe52f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">request_quote</i> — material icon named "request quote" (sharp). + static const IconData request_quote_sharp = IconData(0xec25, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">request_quote</i> — material icon named "request quote" (round). + static const IconData request_quote_rounded = IconData(0xf0104, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">request_quote</i> — material icon named "request quote" (outlined). + static const IconData request_quote_outlined = IconData(0xf312, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">reset_tv</i> — material icon named "reset tv". + static const IconData reset_tv = IconData(0xe530, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">reset_tv</i> — material icon named "reset tv" (sharp). + static const IconData reset_tv_sharp = IconData(0xec26, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">reset_tv</i> — material icon named "reset tv" (round). + static const IconData reset_tv_rounded = IconData(0xf0105, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">reset_tv</i> — material icon named "reset tv" (outlined). + static const IconData reset_tv_outlined = IconData(0xf313, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">restart_alt</i> — material icon named "restart alt". + static const IconData restart_alt = IconData(0xe531, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">restart_alt</i> — material icon named "restart alt" (sharp). + static const IconData restart_alt_sharp = IconData(0xec27, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">restart_alt</i> — material icon named "restart alt" (round). + static const IconData restart_alt_rounded = IconData(0xf0106, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">restart_alt</i> — material icon named "restart alt" (outlined). + static const IconData restart_alt_outlined = IconData(0xf314, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">restaurant</i> — material icon named "restaurant". + static const IconData restaurant = IconData(0xe532, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">restaurant</i> — material icon named "restaurant" (sharp). + static const IconData restaurant_sharp = IconData(0xec29, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">restaurant</i> — material icon named "restaurant" (round). + static const IconData restaurant_rounded = IconData(0xf0108, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">restaurant</i> — material icon named "restaurant" (outlined). + static const IconData restaurant_outlined = IconData(0xf316, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">restaurant_menu</i> — material icon named "restaurant menu". + static const IconData restaurant_menu = IconData(0xe533, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">restaurant_menu</i> — material icon named "restaurant menu" (sharp). + static const IconData restaurant_menu_sharp = IconData(0xec28, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">restaurant_menu</i> — material icon named "restaurant menu" (round). + static const IconData restaurant_menu_rounded = IconData(0xf0107, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">restaurant_menu</i> — material icon named "restaurant menu" (outlined). + static const IconData restaurant_menu_outlined = IconData(0xf315, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">restore</i> — material icon named "restore". + static const IconData restore = IconData(0xe534, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">restore</i> — material icon named "restore" (sharp). + static const IconData restore_sharp = IconData(0xec2c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">restore</i> — material icon named "restore" (round). + static const IconData restore_rounded = IconData(0xf010b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">restore</i> — material icon named "restore" (outlined). + static const IconData restore_outlined = IconData(0xf318, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">restore_from_trash</i> — material icon named "restore from trash". + static const IconData restore_from_trash = IconData(0xe535, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">restore_from_trash</i> — material icon named "restore from trash" (sharp). + static const IconData restore_from_trash_sharp = IconData(0xec2a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">restore_from_trash</i> — material icon named "restore from trash" (round). + static const IconData restore_from_trash_rounded = IconData(0xf0109, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">restore_from_trash</i> — material icon named "restore from trash" (outlined). + static const IconData restore_from_trash_outlined = IconData(0xf317, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">restore_page</i> — material icon named "restore page". + static const IconData restore_page = IconData(0xe536, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">restore_page</i> — material icon named "restore page" (sharp). + static const IconData restore_page_sharp = IconData(0xec2b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">restore_page</i> — material icon named "restore page" (round). + static const IconData restore_page_rounded = IconData(0xf010a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">restore_page</i> — material icon named "restore page" (outlined). + static const IconData restore_page_outlined = IconData(0xf319, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">reviews</i> — material icon named "reviews". + static const IconData reviews = IconData(0xe537, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">reviews</i> — material icon named "reviews" (sharp). + static const IconData reviews_sharp = IconData(0xec2d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">reviews</i> — material icon named "reviews" (round). + static const IconData reviews_rounded = IconData(0xf010c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">reviews</i> — material icon named "reviews" (outlined). + static const IconData reviews_outlined = IconData(0xf31a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rice_bowl</i> — material icon named "rice bowl". + static const IconData rice_bowl = IconData(0xe538, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rice_bowl</i> — material icon named "rice bowl" (sharp). + static const IconData rice_bowl_sharp = IconData(0xec2e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rice_bowl</i> — material icon named "rice bowl" (round). + static const IconData rice_bowl_rounded = IconData(0xf010d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rice_bowl</i> — material icon named "rice bowl" (outlined). + static const IconData rice_bowl_outlined = IconData(0xf31b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ring_volume</i> — material icon named "ring volume". + static const IconData ring_volume = IconData(0xe539, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ring_volume</i> — material icon named "ring volume" (sharp). + static const IconData ring_volume_sharp = IconData(0xec2f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ring_volume</i> — material icon named "ring volume" (round). + static const IconData ring_volume_rounded = IconData(0xf010e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ring_volume</i> — material icon named "ring volume" (outlined). + static const IconData ring_volume_outlined = IconData(0xf31c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rocket</i> — material icon named "rocket". + static const IconData rocket = IconData(0xf055c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rocket</i> — material icon named "rocket" (sharp). + static const IconData rocket_sharp = IconData(0xf0466, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rocket</i> — material icon named "rocket" (round). + static const IconData rocket_rounded = IconData(0xf0373, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rocket</i> — material icon named "rocket" (outlined). + static const IconData rocket_outlined = IconData(0xf0654, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rocket_launch</i> — material icon named "rocket launch". + static const IconData rocket_launch = IconData(0xf055d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rocket_launch</i> — material icon named "rocket launch" (sharp). + static const IconData rocket_launch_sharp = IconData(0xf0465, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rocket_launch</i> — material icon named "rocket launch" (round). + static const IconData rocket_launch_rounded = IconData(0xf0372, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rocket_launch</i> — material icon named "rocket launch" (outlined). + static const IconData rocket_launch_outlined = IconData(0xf0653, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">roller_shades</i> — material icon named "roller shades". + static const IconData roller_shades = IconData(0xf07bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">roller_shades</i> — material icon named "roller shades" (sharp). + static const IconData roller_shades_sharp = IconData(0xf0765, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">roller_shades</i> — material icon named "roller shades" (round). + static const IconData roller_shades_rounded = IconData(0xf0815, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">roller_shades</i> — material icon named "roller shades" (outlined). + static const IconData roller_shades_outlined = IconData(0xf070d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">roller_shades_closed</i> — material icon named "roller shades closed". + static const IconData roller_shades_closed = IconData(0xf07bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">roller_shades_closed</i> — material icon named "roller shades closed" (sharp). + static const IconData roller_shades_closed_sharp = IconData(0xf0764, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">roller_shades_closed</i> — material icon named "roller shades closed" (round). + static const IconData roller_shades_closed_rounded = IconData(0xf0814, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">roller_shades_closed</i> — material icon named "roller shades closed" (outlined). + static const IconData roller_shades_closed_outlined = IconData(0xf070c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">roller_skating</i> — material icon named "roller skating". + static const IconData roller_skating = IconData(0xf06c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">roller_skating</i> — material icon named "roller skating" (sharp). + static const IconData roller_skating_sharp = IconData(0xf06b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">roller_skating</i> — material icon named "roller skating" (round). + static const IconData roller_skating_rounded = IconData(0xf06cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">roller_skating</i> — material icon named "roller skating" (outlined). + static const IconData roller_skating_outlined = IconData(0xf06a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">roofing</i> — material icon named "roofing". + static const IconData roofing = IconData(0xe53a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">roofing</i> — material icon named "roofing" (sharp). + static const IconData roofing_sharp = IconData(0xec30, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">roofing</i> — material icon named "roofing" (round). + static const IconData roofing_rounded = IconData(0xf010f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">roofing</i> — material icon named "roofing" (outlined). + static const IconData roofing_outlined = IconData(0xf31d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">room</i> — material icon named "room". + static const IconData room = IconData(0xe53b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">room</i> — material icon named "room" (sharp). + static const IconData room_sharp = IconData(0xec33, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">room</i> — material icon named "room" (round). + static const IconData room_rounded = IconData(0xf0111, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">room</i> — material icon named "room" (outlined). + static const IconData room_outlined = IconData(0xf31e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">room_preferences</i> — material icon named "room preferences". + static const IconData room_preferences = IconData(0xe53c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">room_preferences</i> — material icon named "room preferences" (sharp). + static const IconData room_preferences_sharp = IconData(0xec31, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">room_preferences</i> — material icon named "room preferences" (round). + static const IconData room_preferences_rounded = IconData(0xf0110, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">room_preferences</i> — material icon named "room preferences" (outlined). + static const IconData room_preferences_outlined = IconData(0xf31f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">room_service</i> — material icon named "room service". + static const IconData room_service = IconData(0xe53d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">room_service</i> — material icon named "room service" (sharp). + static const IconData room_service_sharp = IconData(0xec32, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">room_service</i> — material icon named "room service" (round). + static const IconData room_service_rounded = IconData(0xf0112, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">room_service</i> — material icon named "room service" (outlined). + static const IconData room_service_outlined = IconData(0xf320, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rotate_90_degrees_ccw</i> — material icon named "rotate 90 degrees ccw". + static const IconData rotate_90_degrees_ccw = IconData(0xe53e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rotate_90_degrees_ccw</i> — material icon named "rotate 90 degrees ccw" (sharp). + static const IconData rotate_90_degrees_ccw_sharp = IconData(0xec34, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rotate_90_degrees_ccw</i> — material icon named "rotate 90 degrees ccw" (round). + static const IconData rotate_90_degrees_ccw_rounded = IconData(0xf0113, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rotate_90_degrees_ccw</i> — material icon named "rotate 90 degrees ccw" (outlined). + static const IconData rotate_90_degrees_ccw_outlined = IconData(0xf321, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rotate_90_degrees_cw</i> — material icon named "rotate 90 degrees cw". + static const IconData rotate_90_degrees_cw = IconData(0xf055e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rotate_90_degrees_cw</i> — material icon named "rotate 90 degrees cw" (sharp). + static const IconData rotate_90_degrees_cw_sharp = IconData(0xf0467, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rotate_90_degrees_cw</i> — material icon named "rotate 90 degrees cw" (round). + static const IconData rotate_90_degrees_cw_rounded = IconData(0xf0374, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rotate_90_degrees_cw</i> — material icon named "rotate 90 degrees cw" (outlined). + static const IconData rotate_90_degrees_cw_outlined = IconData(0xf0655, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rotate_left</i> — material icon named "rotate left". + static const IconData rotate_left = IconData(0xe53f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rotate_left</i> — material icon named "rotate left" (sharp). + static const IconData rotate_left_sharp = IconData(0xec35, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rotate_left</i> — material icon named "rotate left" (round). + static const IconData rotate_left_rounded = IconData(0xf0114, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rotate_left</i> — material icon named "rotate left" (outlined). + static const IconData rotate_left_outlined = IconData(0xf322, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rotate_right</i> — material icon named "rotate right". + static const IconData rotate_right = IconData(0xe540, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rotate_right</i> — material icon named "rotate right" (sharp). + static const IconData rotate_right_sharp = IconData(0xec36, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rotate_right</i> — material icon named "rotate right" (round). + static const IconData rotate_right_rounded = IconData(0xf0115, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rotate_right</i> — material icon named "rotate right" (outlined). + static const IconData rotate_right_outlined = IconData(0xf323, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">roundabout_left</i> — material icon named "roundabout left". + static const IconData roundabout_left = IconData(0xf055f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">roundabout_left</i> — material icon named "roundabout left" (sharp). + static const IconData roundabout_left_sharp = IconData(0xf0468, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">roundabout_left</i> — material icon named "roundabout left" (round). + static const IconData roundabout_left_rounded = IconData(0xf0375, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">roundabout_left</i> — material icon named "roundabout left" (outlined). + static const IconData roundabout_left_outlined = IconData(0xf0656, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">roundabout_right</i> — material icon named "roundabout right". + static const IconData roundabout_right = IconData(0xf0560, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">roundabout_right</i> — material icon named "roundabout right" (sharp). + static const IconData roundabout_right_sharp = IconData(0xf0469, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">roundabout_right</i> — material icon named "roundabout right" (round). + static const IconData roundabout_right_rounded = IconData(0xf0376, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">roundabout_right</i> — material icon named "roundabout right" (outlined). + static const IconData roundabout_right_outlined = IconData(0xf0657, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rounded_corner</i> — material icon named "rounded corner". + static const IconData rounded_corner = IconData(0xe541, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rounded_corner</i> — material icon named "rounded corner" (sharp). + static const IconData rounded_corner_sharp = IconData(0xec37, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rounded_corner</i> — material icon named "rounded corner" (round). + static const IconData rounded_corner_rounded = IconData(0xf0116, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rounded_corner</i> — material icon named "rounded corner" (outlined). + static const IconData rounded_corner_outlined = IconData(0xf324, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">route</i> — material icon named "route". + static const IconData route = IconData(0xf0561, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">route</i> — material icon named "route" (sharp). + static const IconData route_sharp = IconData(0xf046a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">route</i> — material icon named "route" (round). + static const IconData route_rounded = IconData(0xf0377, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">route</i> — material icon named "route" (outlined). + static const IconData route_outlined = IconData(0xf0658, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">router</i> — material icon named "router". + static const IconData router = IconData(0xe542, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">router</i> — material icon named "router" (sharp). + static const IconData router_sharp = IconData(0xec38, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">router</i> — material icon named "router" (round). + static const IconData router_rounded = IconData(0xf0117, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">router</i> — material icon named "router" (outlined). + static const IconData router_outlined = IconData(0xf325, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rowing</i> — material icon named "rowing". + static const IconData rowing = IconData(0xe543, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rowing</i> — material icon named "rowing" (sharp). + static const IconData rowing_sharp = IconData(0xec39, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rowing</i> — material icon named "rowing" (round). + static const IconData rowing_rounded = IconData(0xf0118, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rowing</i> — material icon named "rowing" (outlined). + static const IconData rowing_outlined = IconData(0xf326, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rss_feed</i> — material icon named "rss feed". + static const IconData rss_feed = IconData(0xe544, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rss_feed</i> — material icon named "rss feed" (sharp). + static const IconData rss_feed_sharp = IconData(0xec3a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rss_feed</i> — material icon named "rss feed" (round). + static const IconData rss_feed_rounded = IconData(0xf0119, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rss_feed</i> — material icon named "rss feed" (outlined). + static const IconData rss_feed_outlined = IconData(0xf327, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rsvp</i> — material icon named "rsvp". + static const IconData rsvp = IconData(0xe545, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rsvp</i> — material icon named "rsvp" (sharp). + static const IconData rsvp_sharp = IconData(0xec3b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rsvp</i> — material icon named "rsvp" (round). + static const IconData rsvp_rounded = IconData(0xf011a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rsvp</i> — material icon named "rsvp" (outlined). + static const IconData rsvp_outlined = IconData(0xf328, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rtt</i> — material icon named "rtt". + static const IconData rtt = IconData(0xe546, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rtt</i> — material icon named "rtt" (sharp). + static const IconData rtt_sharp = IconData(0xec3c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rtt</i> — material icon named "rtt" (round). + static const IconData rtt_rounded = IconData(0xf011b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rtt</i> — material icon named "rtt" (outlined). + static const IconData rtt_outlined = IconData(0xf329, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rule</i> — material icon named "rule". + static const IconData rule = IconData(0xe547, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rule</i> — material icon named "rule" (sharp). + static const IconData rule_sharp = IconData(0xec3e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rule</i> — material icon named "rule" (round). + static const IconData rule_rounded = IconData(0xf011d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rule</i> — material icon named "rule" (outlined). + static const IconData rule_outlined = IconData(0xf32b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rule_folder</i> — material icon named "rule folder". + static const IconData rule_folder = IconData(0xe548, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rule_folder</i> — material icon named "rule folder" (sharp). + static const IconData rule_folder_sharp = IconData(0xec3d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rule_folder</i> — material icon named "rule folder" (round). + static const IconData rule_folder_rounded = IconData(0xf011c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rule_folder</i> — material icon named "rule folder" (outlined). + static const IconData rule_folder_outlined = IconData(0xf32a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">run_circle</i> — material icon named "run circle". + static const IconData run_circle = IconData(0xe549, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">run_circle</i> — material icon named "run circle" (sharp). + static const IconData run_circle_sharp = IconData(0xec3f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">run_circle</i> — material icon named "run circle" (round). + static const IconData run_circle_rounded = IconData(0xf011e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">run_circle</i> — material icon named "run circle" (outlined). + static const IconData run_circle_outlined = IconData(0xf32c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">running_with_errors</i> — material icon named "running with errors". + static const IconData running_with_errors = IconData(0xe54a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">running_with_errors</i> — material icon named "running with errors" (sharp). + static const IconData running_with_errors_sharp = IconData(0xec40, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">running_with_errors</i> — material icon named "running with errors" (round). + static const IconData running_with_errors_rounded = IconData(0xf011f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">running_with_errors</i> — material icon named "running with errors" (outlined). + static const IconData running_with_errors_outlined = IconData(0xf32d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">rv_hookup</i> — material icon named "rv hookup". + static const IconData rv_hookup = IconData(0xe54b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">rv_hookup</i> — material icon named "rv hookup" (sharp). + static const IconData rv_hookup_sharp = IconData(0xec41, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">rv_hookup</i> — material icon named "rv hookup" (round). + static const IconData rv_hookup_rounded = IconData(0xf0120, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">rv_hookup</i> — material icon named "rv hookup" (outlined). + static const IconData rv_hookup_outlined = IconData(0xf32e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">safety_check</i> — material icon named "safety check". + static const IconData safety_check = IconData(0xf07be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">safety_check</i> — material icon named "safety check" (sharp). + static const IconData safety_check_sharp = IconData(0xf0766, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">safety_check</i> — material icon named "safety check" (round). + static const IconData safety_check_rounded = IconData(0xf0816, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">safety_check</i> — material icon named "safety check" (outlined). + static const IconData safety_check_outlined = IconData(0xf070e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">safety_divider</i> — material icon named "safety divider". + static const IconData safety_divider = IconData(0xe54c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">safety_divider</i> — material icon named "safety divider" (sharp). + static const IconData safety_divider_sharp = IconData(0xec42, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">safety_divider</i> — material icon named "safety divider" (round). + static const IconData safety_divider_rounded = IconData(0xf0121, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">safety_divider</i> — material icon named "safety divider" (outlined). + static const IconData safety_divider_outlined = IconData(0xf32f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sailing</i> — material icon named "sailing". + static const IconData sailing = IconData(0xe54d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sailing</i> — material icon named "sailing" (sharp). + static const IconData sailing_sharp = IconData(0xec43, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sailing</i> — material icon named "sailing" (round). + static const IconData sailing_rounded = IconData(0xf0122, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sailing</i> — material icon named "sailing" (outlined). + static const IconData sailing_outlined = IconData(0xf330, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sanitizer</i> — material icon named "sanitizer". + static const IconData sanitizer = IconData(0xe54e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sanitizer</i> — material icon named "sanitizer" (sharp). + static const IconData sanitizer_sharp = IconData(0xec44, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sanitizer</i> — material icon named "sanitizer" (round). + static const IconData sanitizer_rounded = IconData(0xf0123, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sanitizer</i> — material icon named "sanitizer" (outlined). + static const IconData sanitizer_outlined = IconData(0xf331, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">satellite</i> — material icon named "satellite". + static const IconData satellite = IconData(0xe54f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">satellite</i> — material icon named "satellite" (sharp). + static const IconData satellite_sharp = IconData(0xec45, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">satellite</i> — material icon named "satellite" (round). + static const IconData satellite_rounded = IconData(0xf0124, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">satellite</i> — material icon named "satellite" (outlined). + static const IconData satellite_outlined = IconData(0xf332, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">satellite_alt</i> — material icon named "satellite alt". + static const IconData satellite_alt = IconData(0xf0562, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">satellite_alt</i> — material icon named "satellite alt" (sharp). + static const IconData satellite_alt_sharp = IconData(0xf046b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">satellite_alt</i> — material icon named "satellite alt" (round). + static const IconData satellite_alt_rounded = IconData(0xf0378, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">satellite_alt</i> — material icon named "satellite alt" (outlined). + static const IconData satellite_alt_outlined = IconData(0xf0659, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">save</i> — material icon named "save". + static const IconData save = IconData(0xe550, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">save</i> — material icon named "save" (sharp). + static const IconData save_sharp = IconData(0xec47, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">save</i> — material icon named "save" (round). + static const IconData save_rounded = IconData(0xf0126, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">save</i> — material icon named "save" (outlined). + static const IconData save_outlined = IconData(0xf334, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">save_alt</i> — material icon named "save alt". + static const IconData save_alt = IconData(0xe551, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">save_alt</i> — material icon named "save alt" (sharp). + static const IconData save_alt_sharp = IconData(0xec46, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">save_alt</i> — material icon named "save alt" (round). + static const IconData save_alt_rounded = IconData(0xf0125, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">save_alt</i> — material icon named "save alt" (outlined). + static const IconData save_alt_outlined = IconData(0xf333, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">save_as</i> — material icon named "save as". + static const IconData save_as = IconData(0xf0563, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">save_as</i> — material icon named "save as" (sharp). + static const IconData save_as_sharp = IconData(0xf046c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">save_as</i> — material icon named "save as" (round). + static const IconData save_as_rounded = IconData(0xf0379, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">save_as</i> — material icon named "save as" (outlined). + static const IconData save_as_outlined = IconData(0xf065a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">saved_search</i> — material icon named "saved search". + static const IconData saved_search = IconData(0xe552, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">saved_search</i> — material icon named "saved search" (sharp). + static const IconData saved_search_sharp = IconData(0xec48, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">saved_search</i> — material icon named "saved search" (round). + static const IconData saved_search_rounded = IconData(0xf0127, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">saved_search</i> — material icon named "saved search" (outlined). + static const IconData saved_search_outlined = IconData(0xf335, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">savings</i> — material icon named "savings". + static const IconData savings = IconData(0xe553, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">savings</i> — material icon named "savings" (sharp). + static const IconData savings_sharp = IconData(0xec49, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">savings</i> — material icon named "savings" (round). + static const IconData savings_rounded = IconData(0xf0128, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">savings</i> — material icon named "savings" (outlined). + static const IconData savings_outlined = IconData(0xf336, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">scale</i> — material icon named "scale". + static const IconData scale = IconData(0xf0564, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">scale</i> — material icon named "scale" (sharp). + static const IconData scale_sharp = IconData(0xf046d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">scale</i> — material icon named "scale" (round). + static const IconData scale_rounded = IconData(0xf037a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">scale</i> — material icon named "scale" (outlined). + static const IconData scale_outlined = IconData(0xf065b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">scanner</i> — material icon named "scanner". + static const IconData scanner = IconData(0xe554, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">scanner</i> — material icon named "scanner" (sharp). + static const IconData scanner_sharp = IconData(0xec4a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">scanner</i> — material icon named "scanner" (round). + static const IconData scanner_rounded = IconData(0xf0129, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">scanner</i> — material icon named "scanner" (outlined). + static const IconData scanner_outlined = IconData(0xf337, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">scatter_plot</i> — material icon named "scatter plot". + static const IconData scatter_plot = IconData(0xe555, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">scatter_plot</i> — material icon named "scatter plot" (sharp). + static const IconData scatter_plot_sharp = IconData(0xec4b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">scatter_plot</i> — material icon named "scatter plot" (round). + static const IconData scatter_plot_rounded = IconData(0xf012a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">scatter_plot</i> — material icon named "scatter plot" (outlined). + static const IconData scatter_plot_outlined = IconData(0xf338, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">schedule</i> — material icon named "schedule". + static const IconData schedule = IconData(0xe556, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">schedule</i> — material icon named "schedule" (sharp). + static const IconData schedule_sharp = IconData(0xec4d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">schedule</i> — material icon named "schedule" (round). + static const IconData schedule_rounded = IconData(0xf012b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">schedule</i> — material icon named "schedule" (outlined). + static const IconData schedule_outlined = IconData(0xf339, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">schedule_send</i> — material icon named "schedule send". + static const IconData schedule_send = IconData(0xe557, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">schedule_send</i> — material icon named "schedule send" (sharp). + static const IconData schedule_send_sharp = IconData(0xec4c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">schedule_send</i> — material icon named "schedule send" (round). + static const IconData schedule_send_rounded = IconData(0xf012c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">schedule_send</i> — material icon named "schedule send" (outlined). + static const IconData schedule_send_outlined = IconData(0xf33a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">schema</i> — material icon named "schema". + static const IconData schema = IconData(0xe558, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">schema</i> — material icon named "schema" (sharp). + static const IconData schema_sharp = IconData(0xec4e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">schema</i> — material icon named "schema" (round). + static const IconData schema_rounded = IconData(0xf012d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">schema</i> — material icon named "schema" (outlined). + static const IconData schema_outlined = IconData(0xf33b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">school</i> — material icon named "school". + static const IconData school = IconData(0xe559, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">school</i> — material icon named "school" (sharp). + static const IconData school_sharp = IconData(0xec4f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">school</i> — material icon named "school" (round). + static const IconData school_rounded = IconData(0xf012e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">school</i> — material icon named "school" (outlined). + static const IconData school_outlined = IconData(0xf33c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">science</i> — material icon named "science". + static const IconData science = IconData(0xe55a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">science</i> — material icon named "science" (sharp). + static const IconData science_sharp = IconData(0xec50, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">science</i> — material icon named "science" (round). + static const IconData science_rounded = IconData(0xf012f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">science</i> — material icon named "science" (outlined). + static const IconData science_outlined = IconData(0xf33d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">score</i> — material icon named "score". + static const IconData score = IconData(0xe55b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">score</i> — material icon named "score" (sharp). + static const IconData score_sharp = IconData(0xec51, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">score</i> — material icon named "score" (round). + static const IconData score_rounded = IconData(0xf0130, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">score</i> — material icon named "score" (outlined). + static const IconData score_outlined = IconData(0xf33e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">scoreboard</i> — material icon named "scoreboard". + static const IconData scoreboard = IconData(0xf06c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">scoreboard</i> — material icon named "scoreboard" (sharp). + static const IconData scoreboard_sharp = IconData(0xf06b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">scoreboard</i> — material icon named "scoreboard" (round). + static const IconData scoreboard_rounded = IconData(0xf06ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">scoreboard</i> — material icon named "scoreboard" (outlined). + static const IconData scoreboard_outlined = IconData(0xf06a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">screen_lock_landscape</i> — material icon named "screen lock landscape". + static const IconData screen_lock_landscape = IconData(0xe55c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">screen_lock_landscape</i> — material icon named "screen lock landscape" (sharp). + static const IconData screen_lock_landscape_sharp = IconData(0xec52, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">screen_lock_landscape</i> — material icon named "screen lock landscape" (round). + static const IconData screen_lock_landscape_rounded = IconData(0xf0131, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">screen_lock_landscape</i> — material icon named "screen lock landscape" (outlined). + static const IconData screen_lock_landscape_outlined = IconData(0xf33f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">screen_lock_portrait</i> — material icon named "screen lock portrait". + static const IconData screen_lock_portrait = IconData(0xe55d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">screen_lock_portrait</i> — material icon named "screen lock portrait" (sharp). + static const IconData screen_lock_portrait_sharp = IconData(0xec53, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">screen_lock_portrait</i> — material icon named "screen lock portrait" (round). + static const IconData screen_lock_portrait_rounded = IconData(0xf0132, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">screen_lock_portrait</i> — material icon named "screen lock portrait" (outlined). + static const IconData screen_lock_portrait_outlined = IconData(0xf340, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">screen_lock_rotation</i> — material icon named "screen lock rotation". + static const IconData screen_lock_rotation = IconData(0xe55e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">screen_lock_rotation</i> — material icon named "screen lock rotation" (sharp). + static const IconData screen_lock_rotation_sharp = IconData(0xec54, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">screen_lock_rotation</i> — material icon named "screen lock rotation" (round). + static const IconData screen_lock_rotation_rounded = IconData(0xf0133, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">screen_lock_rotation</i> — material icon named "screen lock rotation" (outlined). + static const IconData screen_lock_rotation_outlined = IconData(0xf341, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">screen_rotation</i> — material icon named "screen rotation". + static const IconData screen_rotation = IconData(0xe55f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">screen_rotation</i> — material icon named "screen rotation" (sharp). + static const IconData screen_rotation_sharp = IconData(0xec55, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">screen_rotation</i> — material icon named "screen rotation" (round). + static const IconData screen_rotation_rounded = IconData(0xf0134, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">screen_rotation</i> — material icon named "screen rotation" (outlined). + static const IconData screen_rotation_outlined = IconData(0xf342, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">screen_rotation_alt</i> — material icon named "screen rotation alt". + static const IconData screen_rotation_alt = IconData(0xf07bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">screen_rotation_alt</i> — material icon named "screen rotation alt" (sharp). + static const IconData screen_rotation_alt_sharp = IconData(0xf0767, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">screen_rotation_alt</i> — material icon named "screen rotation alt" (round). + static const IconData screen_rotation_alt_rounded = IconData(0xf0817, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">screen_rotation_alt</i> — material icon named "screen rotation alt" (outlined). + static const IconData screen_rotation_alt_outlined = IconData(0xf070f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">screen_search_desktop</i> — material icon named "screen search desktop". + static const IconData screen_search_desktop = IconData(0xe560, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">screen_search_desktop</i> — material icon named "screen search desktop" (sharp). + static const IconData screen_search_desktop_sharp = IconData(0xec56, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">screen_search_desktop</i> — material icon named "screen search desktop" (round). + static const IconData screen_search_desktop_rounded = IconData(0xf0135, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">screen_search_desktop</i> — material icon named "screen search desktop" (outlined). + static const IconData screen_search_desktop_outlined = IconData(0xf343, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">screen_share</i> — material icon named "screen share". + static const IconData screen_share = IconData(0xe561, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">screen_share</i> — material icon named "screen share" (sharp). + static const IconData screen_share_sharp = IconData(0xec57, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">screen_share</i> — material icon named "screen share" (round). + static const IconData screen_share_rounded = IconData(0xf0136, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">screen_share</i> — material icon named "screen share" (outlined). + static const IconData screen_share_outlined = IconData(0xf344, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">screenshot</i> — material icon named "screenshot". + static const IconData screenshot = IconData(0xe562, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">screenshot</i> — material icon named "screenshot" (sharp). + static const IconData screenshot_sharp = IconData(0xec58, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">screenshot</i> — material icon named "screenshot" (round). + static const IconData screenshot_rounded = IconData(0xf0137, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">screenshot</i> — material icon named "screenshot" (outlined). + static const IconData screenshot_outlined = IconData(0xf345, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">screenshot_monitor</i> — material icon named "screenshot monitor". + static const IconData screenshot_monitor = IconData(0xf07c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">screenshot_monitor</i> — material icon named "screenshot monitor" (sharp). + static const IconData screenshot_monitor_sharp = IconData(0xf0768, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">screenshot_monitor</i> — material icon named "screenshot monitor" (round). + static const IconData screenshot_monitor_rounded = IconData(0xf0818, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">screenshot_monitor</i> — material icon named "screenshot monitor" (outlined). + static const IconData screenshot_monitor_outlined = IconData(0xf0710, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">scuba_diving</i> — material icon named "scuba diving". + static const IconData scuba_diving = IconData(0xf06c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">scuba_diving</i> — material icon named "scuba diving" (sharp). + static const IconData scuba_diving_sharp = IconData(0xf06b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">scuba_diving</i> — material icon named "scuba diving" (round). + static const IconData scuba_diving_rounded = IconData(0xf06cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">scuba_diving</i> — material icon named "scuba diving" (outlined). + static const IconData scuba_diving_outlined = IconData(0xf06a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sd</i> — material icon named "sd". + static const IconData sd = IconData(0xe563, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sd</i> — material icon named "sd" (sharp). + static const IconData sd_sharp = IconData(0xec5b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sd</i> — material icon named "sd" (round). + static const IconData sd_rounded = IconData(0xf013a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sd</i> — material icon named "sd" (outlined). + static const IconData sd_outlined = IconData(0xf348, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sd_card</i> — material icon named "sd card". + static const IconData sd_card = IconData(0xe564, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sd_card</i> — material icon named "sd card" (sharp). + static const IconData sd_card_sharp = IconData(0xec5a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sd_card</i> — material icon named "sd card" (round). + static const IconData sd_card_rounded = IconData(0xf0139, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sd_card</i> — material icon named "sd card" (outlined). + static const IconData sd_card_outlined = IconData(0xf347, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sd_card_alert</i> — material icon named "sd card alert". + static const IconData sd_card_alert = IconData(0xe565, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sd_card_alert</i> — material icon named "sd card alert" (sharp). + static const IconData sd_card_alert_sharp = IconData(0xec59, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sd_card_alert</i> — material icon named "sd card alert" (round). + static const IconData sd_card_alert_rounded = IconData(0xf0138, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sd_card_alert</i> — material icon named "sd card alert" (outlined). + static const IconData sd_card_alert_outlined = IconData(0xf346, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sd_storage</i> — material icon named "sd storage". + static const IconData sd_storage = IconData(0xe566, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sd_storage</i> — material icon named "sd storage" (sharp). + static const IconData sd_storage_sharp = IconData(0xec5c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sd_storage</i> — material icon named "sd storage" (round). + static const IconData sd_storage_rounded = IconData(0xf013b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sd_storage</i> — material icon named "sd storage" (outlined). + static const IconData sd_storage_outlined = IconData(0xf349, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">search</i> — material icon named "search". + static const IconData search = IconData(0xe567, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">search</i> — material icon named "search" (sharp). + static const IconData search_sharp = IconData(0xec5e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">search</i> — material icon named "search" (round). + static const IconData search_rounded = IconData(0xf013d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">search</i> — material icon named "search" (outlined). + static const IconData search_outlined = IconData(0xf34b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">search_off</i> — material icon named "search off". + static const IconData search_off = IconData(0xe568, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">search_off</i> — material icon named "search off" (sharp). + static const IconData search_off_sharp = IconData(0xec5d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">search_off</i> — material icon named "search off" (round). + static const IconData search_off_rounded = IconData(0xf013c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">search_off</i> — material icon named "search off" (outlined). + static const IconData search_off_outlined = IconData(0xf34a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">security</i> — material icon named "security". + static const IconData security = IconData(0xe569, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">security</i> — material icon named "security" (sharp). + static const IconData security_sharp = IconData(0xec5f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">security</i> — material icon named "security" (round). + static const IconData security_rounded = IconData(0xf013e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">security</i> — material icon named "security" (outlined). + static const IconData security_outlined = IconData(0xf34c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">security_update</i> — material icon named "security update". + static const IconData security_update = IconData(0xe56a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">security_update</i> — material icon named "security update" (sharp). + static const IconData security_update_sharp = IconData(0xec61, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">security_update</i> — material icon named "security update" (round). + static const IconData security_update_rounded = IconData(0xf0140, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">security_update</i> — material icon named "security update" (outlined). + static const IconData security_update_outlined = IconData(0xf34e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">security_update_good</i> — material icon named "security update good". + static const IconData security_update_good = IconData(0xe56b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">security_update_good</i> — material icon named "security update good" (sharp). + static const IconData security_update_good_sharp = IconData(0xec60, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">security_update_good</i> — material icon named "security update good" (round). + static const IconData security_update_good_rounded = IconData(0xf013f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">security_update_good</i> — material icon named "security update good" (outlined). + static const IconData security_update_good_outlined = IconData(0xf34d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">security_update_warning</i> — material icon named "security update warning". + static const IconData security_update_warning = IconData(0xe56c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">security_update_warning</i> — material icon named "security update warning" (sharp). + static const IconData security_update_warning_sharp = IconData(0xec62, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">security_update_warning</i> — material icon named "security update warning" (round). + static const IconData security_update_warning_rounded = IconData(0xf0141, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">security_update_warning</i> — material icon named "security update warning" (outlined). + static const IconData security_update_warning_outlined = IconData(0xf34f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">segment</i> — material icon named "segment". + static const IconData segment = IconData(0xe56d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">segment</i> — material icon named "segment" (sharp). + static const IconData segment_sharp = IconData(0xec63, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">segment</i> — material icon named "segment" (round). + static const IconData segment_rounded = IconData(0xf0142, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">segment</i> — material icon named "segment" (outlined). + static const IconData segment_outlined = IconData(0xf350, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">select_all</i> — material icon named "select all". + static const IconData select_all = IconData(0xe56e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">select_all</i> — material icon named "select all" (sharp). + static const IconData select_all_sharp = IconData(0xec64, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">select_all</i> — material icon named "select all" (round). + static const IconData select_all_rounded = IconData(0xf0143, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">select_all</i> — material icon named "select all" (outlined). + static const IconData select_all_outlined = IconData(0xf351, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">self_improvement</i> — material icon named "self improvement". + static const IconData self_improvement = IconData(0xe56f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">self_improvement</i> — material icon named "self improvement" (sharp). + static const IconData self_improvement_sharp = IconData(0xec65, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">self_improvement</i> — material icon named "self improvement" (round). + static const IconData self_improvement_rounded = IconData(0xf0144, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">self_improvement</i> — material icon named "self improvement" (outlined). + static const IconData self_improvement_outlined = IconData(0xf352, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sell</i> — material icon named "sell". + static const IconData sell = IconData(0xe570, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sell</i> — material icon named "sell" (sharp). + static const IconData sell_sharp = IconData(0xec66, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sell</i> — material icon named "sell" (round). + static const IconData sell_rounded = IconData(0xf0145, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sell</i> — material icon named "sell" (outlined). + static const IconData sell_outlined = IconData(0xf353, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">send</i> — material icon named "send". + static const IconData send = IconData(0xe571, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">send</i> — material icon named "send" (sharp). + static const IconData send_sharp = IconData(0xec68, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">send</i> — material icon named "send" (round). + static const IconData send_rounded = IconData(0xf0147, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">send</i> — material icon named "send" (outlined). + static const IconData send_outlined = IconData(0xf355, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">send_and_archive</i> — material icon named "send and archive". + static const IconData send_and_archive = IconData(0xe572, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">send_and_archive</i> — material icon named "send and archive" (sharp). + static const IconData send_and_archive_sharp = IconData(0xec67, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">send_and_archive</i> — material icon named "send and archive" (round). + static const IconData send_and_archive_rounded = IconData(0xf0146, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">send_and_archive</i> — material icon named "send and archive" (outlined). + static const IconData send_and_archive_outlined = IconData(0xf354, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">send_time_extension</i> — material icon named "send time extension". + static const IconData send_time_extension = IconData(0xf0565, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">send_time_extension</i> — material icon named "send time extension" (sharp). + static const IconData send_time_extension_sharp = IconData(0xf046e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">send_time_extension</i> — material icon named "send time extension" (round). + static const IconData send_time_extension_rounded = IconData(0xf037b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">send_time_extension</i> — material icon named "send time extension" (outlined). + static const IconData send_time_extension_outlined = IconData(0xf065c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">send_to_mobile</i> — material icon named "send to mobile". + static const IconData send_to_mobile = IconData(0xe573, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">send_to_mobile</i> — material icon named "send to mobile" (sharp). + static const IconData send_to_mobile_sharp = IconData(0xec69, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">send_to_mobile</i> — material icon named "send to mobile" (round). + static const IconData send_to_mobile_rounded = IconData(0xf0148, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">send_to_mobile</i> — material icon named "send to mobile" (outlined). + static const IconData send_to_mobile_outlined = IconData(0xf356, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sensor_door</i> — material icon named "sensor door". + static const IconData sensor_door = IconData(0xe574, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sensor_door</i> — material icon named "sensor door" (sharp). + static const IconData sensor_door_sharp = IconData(0xec6a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sensor_door</i> — material icon named "sensor door" (round). + static const IconData sensor_door_rounded = IconData(0xf0149, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sensor_door</i> — material icon named "sensor door" (outlined). + static const IconData sensor_door_outlined = IconData(0xf357, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sensor_occupied</i> — material icon named "sensor occupied". + static const IconData sensor_occupied = IconData(0xf07c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sensor_occupied</i> — material icon named "sensor occupied" (sharp). + static const IconData sensor_occupied_sharp = IconData(0xf0769, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sensor_occupied</i> — material icon named "sensor occupied" (round). + static const IconData sensor_occupied_rounded = IconData(0xf0819, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sensor_occupied</i> — material icon named "sensor occupied" (outlined). + static const IconData sensor_occupied_outlined = IconData(0xf0711, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sensor_window</i> — material icon named "sensor window". + static const IconData sensor_window = IconData(0xe575, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sensor_window</i> — material icon named "sensor window" (sharp). + static const IconData sensor_window_sharp = IconData(0xec6b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sensor_window</i> — material icon named "sensor window" (round). + static const IconData sensor_window_rounded = IconData(0xf014a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sensor_window</i> — material icon named "sensor window" (outlined). + static const IconData sensor_window_outlined = IconData(0xf358, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sensors</i> — material icon named "sensors". + static const IconData sensors = IconData(0xe576, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sensors</i> — material icon named "sensors" (sharp). + static const IconData sensors_sharp = IconData(0xec6d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sensors</i> — material icon named "sensors" (round). + static const IconData sensors_rounded = IconData(0xf014c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sensors</i> — material icon named "sensors" (outlined). + static const IconData sensors_outlined = IconData(0xf35a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sensors_off</i> — material icon named "sensors off". + static const IconData sensors_off = IconData(0xe577, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sensors_off</i> — material icon named "sensors off" (sharp). + static const IconData sensors_off_sharp = IconData(0xec6c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sensors_off</i> — material icon named "sensors off" (round). + static const IconData sensors_off_rounded = IconData(0xf014b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sensors_off</i> — material icon named "sensors off" (outlined). + static const IconData sensors_off_outlined = IconData(0xf359, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sentiment_dissatisfied</i> — material icon named "sentiment dissatisfied". + static const IconData sentiment_dissatisfied = IconData(0xe578, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sentiment_dissatisfied</i> — material icon named "sentiment dissatisfied" (sharp). + static const IconData sentiment_dissatisfied_sharp = IconData(0xec6e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sentiment_dissatisfied</i> — material icon named "sentiment dissatisfied" (round). + static const IconData sentiment_dissatisfied_rounded = IconData(0xf014d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sentiment_dissatisfied</i> — material icon named "sentiment dissatisfied" (outlined). + static const IconData sentiment_dissatisfied_outlined = IconData(0xf35b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sentiment_neutral</i> — material icon named "sentiment neutral". + static const IconData sentiment_neutral = IconData(0xe579, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sentiment_neutral</i> — material icon named "sentiment neutral" (sharp). + static const IconData sentiment_neutral_sharp = IconData(0xec6f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sentiment_neutral</i> — material icon named "sentiment neutral" (round). + static const IconData sentiment_neutral_rounded = IconData(0xf014e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sentiment_neutral</i> — material icon named "sentiment neutral" (outlined). + static const IconData sentiment_neutral_outlined = IconData(0xf35c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sentiment_satisfied</i> — material icon named "sentiment satisfied". + static const IconData sentiment_satisfied = IconData(0xe57a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sentiment_satisfied</i> — material icon named "sentiment satisfied" (sharp). + static const IconData sentiment_satisfied_sharp = IconData(0xec71, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sentiment_satisfied</i> — material icon named "sentiment satisfied" (round). + static const IconData sentiment_satisfied_rounded = IconData(0xf0150, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sentiment_satisfied</i> — material icon named "sentiment satisfied" (outlined). + static const IconData sentiment_satisfied_outlined = IconData(0xf35e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sentiment_satisfied_alt</i> — material icon named "sentiment satisfied alt". + static const IconData sentiment_satisfied_alt = IconData(0xe57b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sentiment_satisfied_alt</i> — material icon named "sentiment satisfied alt" (sharp). + static const IconData sentiment_satisfied_alt_sharp = IconData(0xec70, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sentiment_satisfied_alt</i> — material icon named "sentiment satisfied alt" (round). + static const IconData sentiment_satisfied_alt_rounded = IconData(0xf014f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sentiment_satisfied_alt</i> — material icon named "sentiment satisfied alt" (outlined). + static const IconData sentiment_satisfied_alt_outlined = IconData(0xf35d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sentiment_very_dissatisfied</i> — material icon named "sentiment very dissatisfied". + static const IconData sentiment_very_dissatisfied = IconData(0xe57c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sentiment_very_dissatisfied</i> — material icon named "sentiment very dissatisfied" (sharp). + static const IconData sentiment_very_dissatisfied_sharp = IconData(0xec72, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sentiment_very_dissatisfied</i> — material icon named "sentiment very dissatisfied" (round). + static const IconData sentiment_very_dissatisfied_rounded = IconData(0xf0151, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sentiment_very_dissatisfied</i> — material icon named "sentiment very dissatisfied" (outlined). + static const IconData sentiment_very_dissatisfied_outlined = IconData(0xf35f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sentiment_very_satisfied</i> — material icon named "sentiment very satisfied". + static const IconData sentiment_very_satisfied = IconData(0xe57d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sentiment_very_satisfied</i> — material icon named "sentiment very satisfied" (sharp). + static const IconData sentiment_very_satisfied_sharp = IconData(0xec73, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sentiment_very_satisfied</i> — material icon named "sentiment very satisfied" (round). + static const IconData sentiment_very_satisfied_rounded = IconData(0xf0152, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sentiment_very_satisfied</i> — material icon named "sentiment very satisfied" (outlined). + static const IconData sentiment_very_satisfied_outlined = IconData(0xf360, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">set_meal</i> — material icon named "set meal". + static const IconData set_meal = IconData(0xe57e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">set_meal</i> — material icon named "set meal" (sharp). + static const IconData set_meal_sharp = IconData(0xec74, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">set_meal</i> — material icon named "set meal" (round). + static const IconData set_meal_rounded = IconData(0xf0153, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">set_meal</i> — material icon named "set meal" (outlined). + static const IconData set_meal_outlined = IconData(0xf361, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings</i> — material icon named "settings". + static const IconData settings = IconData(0xe57f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings</i> — material icon named "settings" (sharp). + static const IconData settings_sharp = IconData(0xec85, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings</i> — material icon named "settings" (round). + static const IconData settings_rounded = IconData(0xf0164, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings</i> — material icon named "settings" (outlined). + static const IconData settings_outlined = IconData(0xf36e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_accessibility</i> — material icon named "settings accessibility". + static const IconData settings_accessibility = IconData(0xe580, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_accessibility</i> — material icon named "settings accessibility" (sharp). + static const IconData settings_accessibility_sharp = IconData(0xec75, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_accessibility</i> — material icon named "settings accessibility" (round). + static const IconData settings_accessibility_rounded = IconData(0xf0154, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_accessibility</i> — material icon named "settings accessibility" (outlined). + static const IconData settings_accessibility_outlined = IconData(0xf362, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_applications</i> — material icon named "settings applications". + static const IconData settings_applications = IconData(0xe581, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_applications</i> — material icon named "settings applications" (sharp). + static const IconData settings_applications_sharp = IconData(0xec76, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_applications</i> — material icon named "settings applications" (round). + static const IconData settings_applications_rounded = IconData(0xf0155, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_applications</i> — material icon named "settings applications" (outlined). + static const IconData settings_applications_outlined = IconData(0xf363, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_backup_restore</i> — material icon named "settings backup restore". + static const IconData settings_backup_restore = IconData(0xe582, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_backup_restore</i> — material icon named "settings backup restore" (sharp). + static const IconData settings_backup_restore_sharp = IconData(0xec77, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_backup_restore</i> — material icon named "settings backup restore" (round). + static const IconData settings_backup_restore_rounded = IconData(0xf0156, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_backup_restore</i> — material icon named "settings backup restore" (outlined). + static const IconData settings_backup_restore_outlined = IconData(0xf364, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_bluetooth</i> — material icon named "settings bluetooth". + static const IconData settings_bluetooth = IconData(0xe583, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_bluetooth</i> — material icon named "settings bluetooth" (sharp). + static const IconData settings_bluetooth_sharp = IconData(0xec78, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_bluetooth</i> — material icon named "settings bluetooth" (round). + static const IconData settings_bluetooth_rounded = IconData(0xf0157, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_bluetooth</i> — material icon named "settings bluetooth" (outlined). + static const IconData settings_bluetooth_outlined = IconData(0xf365, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_brightness</i> — material icon named "settings brightness". + static const IconData settings_brightness = IconData(0xe584, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_brightness</i> — material icon named "settings brightness" (sharp). + static const IconData settings_brightness_sharp = IconData(0xec79, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_brightness</i> — material icon named "settings brightness" (round). + static const IconData settings_brightness_rounded = IconData(0xf0158, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_brightness</i> — material icon named "settings brightness" (outlined). + static const IconData settings_brightness_outlined = IconData(0xf366, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_cell</i> — material icon named "settings cell". + static const IconData settings_cell = IconData(0xe585, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_cell</i> — material icon named "settings cell" (sharp). + static const IconData settings_cell_sharp = IconData(0xec7a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_cell</i> — material icon named "settings cell" (round). + static const IconData settings_cell_rounded = IconData(0xf0159, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_cell</i> — material icon named "settings cell" (outlined). + static const IconData settings_cell_outlined = IconData(0xf367, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_display</i> — material icon named "settings display". + static const IconData settings_display = IconData(0xe584, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_display</i> — material icon named "settings display" (sharp). + static const IconData settings_display_sharp = IconData(0xec79, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_display</i> — material icon named "settings display" (round). + static const IconData settings_display_rounded = IconData(0xf0158, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_display</i> — material icon named "settings display" (outlined). + static const IconData settings_display_outlined = IconData(0xf366, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_ethernet</i> — material icon named "settings ethernet". + static const IconData settings_ethernet = IconData(0xe586, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_ethernet</i> — material icon named "settings ethernet" (sharp). + static const IconData settings_ethernet_sharp = IconData(0xec7b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_ethernet</i> — material icon named "settings ethernet" (round). + static const IconData settings_ethernet_rounded = IconData(0xf015a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_ethernet</i> — material icon named "settings ethernet" (outlined). + static const IconData settings_ethernet_outlined = IconData(0xf368, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_input_antenna</i> — material icon named "settings input antenna". + static const IconData settings_input_antenna = IconData(0xe587, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_input_antenna</i> — material icon named "settings input antenna" (sharp). + static const IconData settings_input_antenna_sharp = IconData(0xec7c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_input_antenna</i> — material icon named "settings input antenna" (round). + static const IconData settings_input_antenna_rounded = IconData(0xf015b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_input_antenna</i> — material icon named "settings input antenna" (outlined). + static const IconData settings_input_antenna_outlined = IconData(0xf369, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_input_component</i> — material icon named "settings input component". + static const IconData settings_input_component = IconData(0xe588, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_input_component</i> — material icon named "settings input component" (sharp). + static const IconData settings_input_component_sharp = IconData(0xec7d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_input_component</i> — material icon named "settings input component" (round). + static const IconData settings_input_component_rounded = IconData(0xf015c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_input_component</i> — material icon named "settings input component" (outlined). + static const IconData settings_input_component_outlined = IconData(0xf36a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_input_composite</i> — material icon named "settings input composite". + static const IconData settings_input_composite = IconData(0xe589, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_input_composite</i> — material icon named "settings input composite" (sharp). + static const IconData settings_input_composite_sharp = IconData(0xec7e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_input_composite</i> — material icon named "settings input composite" (round). + static const IconData settings_input_composite_rounded = IconData(0xf015d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_input_composite</i> — material icon named "settings input composite" (outlined). + static const IconData settings_input_composite_outlined = IconData(0xf36b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_input_hdmi</i> — material icon named "settings input hdmi". + static const IconData settings_input_hdmi = IconData(0xe58a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_input_hdmi</i> — material icon named "settings input hdmi" (sharp). + static const IconData settings_input_hdmi_sharp = IconData(0xec7f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_input_hdmi</i> — material icon named "settings input hdmi" (round). + static const IconData settings_input_hdmi_rounded = IconData(0xf015e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_input_hdmi</i> — material icon named "settings input hdmi" (outlined). + static const IconData settings_input_hdmi_outlined = IconData(0xf36c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_input_svideo</i> — material icon named "settings input svideo". + static const IconData settings_input_svideo = IconData(0xe58b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_input_svideo</i> — material icon named "settings input svideo" (sharp). + static const IconData settings_input_svideo_sharp = IconData(0xec80, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_input_svideo</i> — material icon named "settings input svideo" (round). + static const IconData settings_input_svideo_rounded = IconData(0xf015f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_input_svideo</i> — material icon named "settings input svideo" (outlined). + static const IconData settings_input_svideo_outlined = IconData(0xf36d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_overscan</i> — material icon named "settings overscan". + static const IconData settings_overscan = IconData(0xe58c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_overscan</i> — material icon named "settings overscan" (sharp). + static const IconData settings_overscan_sharp = IconData(0xec81, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_overscan</i> — material icon named "settings overscan" (round). + static const IconData settings_overscan_rounded = IconData(0xf0160, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_overscan</i> — material icon named "settings overscan" (outlined). + static const IconData settings_overscan_outlined = IconData(0xf36f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_phone</i> — material icon named "settings phone". + static const IconData settings_phone = IconData(0xe58d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_phone</i> — material icon named "settings phone" (sharp). + static const IconData settings_phone_sharp = IconData(0xec82, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_phone</i> — material icon named "settings phone" (round). + static const IconData settings_phone_rounded = IconData(0xf0161, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_phone</i> — material icon named "settings phone" (outlined). + static const IconData settings_phone_outlined = IconData(0xf370, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_power</i> — material icon named "settings power". + static const IconData settings_power = IconData(0xe58e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_power</i> — material icon named "settings power" (sharp). + static const IconData settings_power_sharp = IconData(0xec83, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_power</i> — material icon named "settings power" (round). + static const IconData settings_power_rounded = IconData(0xf0162, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_power</i> — material icon named "settings power" (outlined). + static const IconData settings_power_outlined = IconData(0xf371, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_remote</i> — material icon named "settings remote". + static const IconData settings_remote = IconData(0xe58f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_remote</i> — material icon named "settings remote" (sharp). + static const IconData settings_remote_sharp = IconData(0xec84, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_remote</i> — material icon named "settings remote" (round). + static const IconData settings_remote_rounded = IconData(0xf0163, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_remote</i> — material icon named "settings remote" (outlined). + static const IconData settings_remote_outlined = IconData(0xf372, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_suggest</i> — material icon named "settings suggest". + static const IconData settings_suggest = IconData(0xe590, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_suggest</i> — material icon named "settings suggest" (sharp). + static const IconData settings_suggest_sharp = IconData(0xec86, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_suggest</i> — material icon named "settings suggest" (round). + static const IconData settings_suggest_rounded = IconData(0xf0165, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_suggest</i> — material icon named "settings suggest" (outlined). + static const IconData settings_suggest_outlined = IconData(0xf373, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_system_daydream</i> — material icon named "settings system daydream". + static const IconData settings_system_daydream = IconData(0xe591, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_system_daydream</i> — material icon named "settings system daydream" (sharp). + static const IconData settings_system_daydream_sharp = IconData(0xec87, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_system_daydream</i> — material icon named "settings system daydream" (round). + static const IconData settings_system_daydream_rounded = IconData(0xf0166, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_system_daydream</i> — material icon named "settings system daydream" (outlined). + static const IconData settings_system_daydream_outlined = IconData(0xf374, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">settings_voice</i> — material icon named "settings voice". + static const IconData settings_voice = IconData(0xe592, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">settings_voice</i> — material icon named "settings voice" (sharp). + static const IconData settings_voice_sharp = IconData(0xec88, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">settings_voice</i> — material icon named "settings voice" (round). + static const IconData settings_voice_rounded = IconData(0xf0167, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">settings_voice</i> — material icon named "settings voice" (outlined). + static const IconData settings_voice_outlined = IconData(0xf375, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">severe_cold</i> — material icon named "severe cold". + static const IconData severe_cold = IconData(0xf07c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">severe_cold</i> — material icon named "severe cold" (sharp). + static const IconData severe_cold_sharp = IconData(0xf076a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">severe_cold</i> — material icon named "severe cold" (round). + static const IconData severe_cold_rounded = IconData(0xf081a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">severe_cold</i> — material icon named "severe cold" (outlined). + static const IconData severe_cold_outlined = IconData(0xf0712, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shape_line</i> — material icon named "shape line". + static const IconData shape_line = IconData(0xf0876, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shape_line</i> — material icon named "shape line" (sharp). + static const IconData shape_line_sharp = IconData(0xf084c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shape_line</i> — material icon named "shape line" (round). + static const IconData shape_line_rounded = IconData(0xf0895, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shape_line</i> — material icon named "shape line" (outlined). + static const IconData shape_line_outlined = IconData(0xf08b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">share</i> — material icon named "share". + static const IconData share = IconData(0xe593, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">share</i> — material icon named "share" (sharp). + static const IconData share_sharp = IconData(0xec8b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">share</i> — material icon named "share" (round). + static const IconData share_rounded = IconData(0xf016a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">share</i> — material icon named "share" (outlined). + static const IconData share_outlined = IconData(0xf378, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">share_arrival_time</i> — material icon named "share arrival time". + static const IconData share_arrival_time = IconData(0xe594, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">share_arrival_time</i> — material icon named "share arrival time" (sharp). + static const IconData share_arrival_time_sharp = IconData(0xec89, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">share_arrival_time</i> — material icon named "share arrival time" (round). + static const IconData share_arrival_time_rounded = IconData(0xf0168, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">share_arrival_time</i> — material icon named "share arrival time" (outlined). + static const IconData share_arrival_time_outlined = IconData(0xf376, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">share_location</i> — material icon named "share location". + static const IconData share_location = IconData(0xe595, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">share_location</i> — material icon named "share location" (sharp). + static const IconData share_location_sharp = IconData(0xec8a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">share_location</i> — material icon named "share location" (round). + static const IconData share_location_rounded = IconData(0xf0169, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">share_location</i> — material icon named "share location" (outlined). + static const IconData share_location_outlined = IconData(0xf377, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shelves</i> — material icon named "shelves". + static const IconData shelves = IconData(0xf0877, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shield</i> — material icon named "shield". + static const IconData shield = IconData(0xe596, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shield</i> — material icon named "shield" (sharp). + static const IconData shield_sharp = IconData(0xec8c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shield</i> — material icon named "shield" (round). + static const IconData shield_rounded = IconData(0xf016b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shield</i> — material icon named "shield" (outlined). + static const IconData shield_outlined = IconData(0xf379, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shield_moon</i> — material icon named "shield moon". + static const IconData shield_moon = IconData(0xf0566, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shield_moon</i> — material icon named "shield moon" (sharp). + static const IconData shield_moon_sharp = IconData(0xf046f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shield_moon</i> — material icon named "shield moon" (round). + static const IconData shield_moon_rounded = IconData(0xf037c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shield_moon</i> — material icon named "shield moon" (outlined). + static const IconData shield_moon_outlined = IconData(0xf065d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shop</i> — material icon named "shop". + static const IconData shop = IconData(0xe597, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shop</i> — material icon named "shop" (sharp). + static const IconData shop_sharp = IconData(0xec8e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shop</i> — material icon named "shop" (round). + static const IconData shop_rounded = IconData(0xf016d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shop</i> — material icon named "shop" (outlined). + static const IconData shop_outlined = IconData(0xf37b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shop_2</i> — material icon named "shop 2". + static const IconData shop_2 = IconData(0xe598, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shop_2</i> — material icon named "shop 2" (sharp). + static const IconData shop_2_sharp = IconData(0xec8d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shop_2</i> — material icon named "shop 2" (round). + static const IconData shop_2_rounded = IconData(0xf016c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shop_2</i> — material icon named "shop 2" (outlined). + static const IconData shop_2_outlined = IconData(0xf37a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shop_two</i> — material icon named "shop two". + static const IconData shop_two = IconData(0xe599, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shop_two</i> — material icon named "shop two" (sharp). + static const IconData shop_two_sharp = IconData(0xec8f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shop_two</i> — material icon named "shop two" (round). + static const IconData shop_two_rounded = IconData(0xf016e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shop_two</i> — material icon named "shop two" (outlined). + static const IconData shop_two_outlined = IconData(0xf37c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shopify</i> — material icon named "shopify". + static const IconData shopify = IconData(0xf0567, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shopify</i> — material icon named "shopify" (sharp). + static const IconData shopify_sharp = IconData(0xf0470, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shopify</i> — material icon named "shopify" (round). + static const IconData shopify_rounded = IconData(0xf037d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shopify</i> — material icon named "shopify" (outlined). + static const IconData shopify_outlined = IconData(0xf065e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shopping_bag</i> — material icon named "shopping bag". + static const IconData shopping_bag = IconData(0xe59a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shopping_bag</i> — material icon named "shopping bag" (sharp). + static const IconData shopping_bag_sharp = IconData(0xec90, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shopping_bag</i> — material icon named "shopping bag" (round). + static const IconData shopping_bag_rounded = IconData(0xf016f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shopping_bag</i> — material icon named "shopping bag" (outlined). + static const IconData shopping_bag_outlined = IconData(0xf37d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shopping_basket</i> — material icon named "shopping basket". + static const IconData shopping_basket = IconData(0xe59b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shopping_basket</i> — material icon named "shopping basket" (sharp). + static const IconData shopping_basket_sharp = IconData(0xec91, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shopping_basket</i> — material icon named "shopping basket" (round). + static const IconData shopping_basket_rounded = IconData(0xf0170, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shopping_basket</i> — material icon named "shopping basket" (outlined). + static const IconData shopping_basket_outlined = IconData(0xf37e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shopping_cart</i> — material icon named "shopping cart". + static const IconData shopping_cart = IconData(0xe59c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shopping_cart</i> — material icon named "shopping cart" (sharp). + static const IconData shopping_cart_sharp = IconData(0xec92, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shopping_cart</i> — material icon named "shopping cart" (round). + static const IconData shopping_cart_rounded = IconData(0xf0171, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shopping_cart</i> — material icon named "shopping cart" (outlined). + static const IconData shopping_cart_outlined = IconData(0xf37f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shopping_cart_checkout</i> — material icon named "shopping cart checkout". + static const IconData shopping_cart_checkout = IconData(0xf0568, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shopping_cart_checkout</i> — material icon named "shopping cart checkout" (sharp). + static const IconData shopping_cart_checkout_sharp = IconData(0xf0471, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shopping_cart_checkout</i> — material icon named "shopping cart checkout" (round). + static const IconData shopping_cart_checkout_rounded = IconData(0xf037e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shopping_cart_checkout</i> — material icon named "shopping cart checkout" (outlined). + static const IconData shopping_cart_checkout_outlined = IconData(0xf065f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">short_text</i> — material icon named "short text". + static const IconData short_text = IconData(0xe59d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">short_text</i> — material icon named "short text" (sharp). + static const IconData short_text_sharp = IconData(0xec93, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">short_text</i> — material icon named "short text" (round). + static const IconData short_text_rounded = IconData(0xf0172, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">short_text</i> — material icon named "short text" (outlined). + static const IconData short_text_outlined = IconData(0xf380, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">shortcut</i> — material icon named "shortcut". + static const IconData shortcut = IconData(0xe59e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shortcut</i> — material icon named "shortcut" (sharp). + static const IconData shortcut_sharp = IconData(0xec94, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shortcut</i> — material icon named "shortcut" (round). + static const IconData shortcut_rounded = IconData(0xf0173, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shortcut</i> — material icon named "shortcut" (outlined). + static const IconData shortcut_outlined = IconData(0xf381, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">show_chart</i> — material icon named "show chart". + static const IconData show_chart = IconData(0xe59f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">show_chart</i> — material icon named "show chart" (sharp). + static const IconData show_chart_sharp = IconData(0xec95, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">show_chart</i> — material icon named "show chart" (round). + static const IconData show_chart_rounded = IconData(0xf0174, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">show_chart</i> — material icon named "show chart" (outlined). + static const IconData show_chart_outlined = IconData(0xf382, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">shower</i> — material icon named "shower". + static const IconData shower = IconData(0xe5a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shower</i> — material icon named "shower" (sharp). + static const IconData shower_sharp = IconData(0xec96, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shower</i> — material icon named "shower" (round). + static const IconData shower_rounded = IconData(0xf0175, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shower</i> — material icon named "shower" (outlined). + static const IconData shower_outlined = IconData(0xf383, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shuffle</i> — material icon named "shuffle". + static const IconData shuffle = IconData(0xe5a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shuffle</i> — material icon named "shuffle" (sharp). + static const IconData shuffle_sharp = IconData(0xec98, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shuffle</i> — material icon named "shuffle" (round). + static const IconData shuffle_rounded = IconData(0xf0177, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shuffle</i> — material icon named "shuffle" (outlined). + static const IconData shuffle_outlined = IconData(0xf385, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shuffle_on</i> — material icon named "shuffle on". + static const IconData shuffle_on = IconData(0xe5a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shuffle_on</i> — material icon named "shuffle on" (sharp). + static const IconData shuffle_on_sharp = IconData(0xec97, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shuffle_on</i> — material icon named "shuffle on" (round). + static const IconData shuffle_on_rounded = IconData(0xf0176, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shuffle_on</i> — material icon named "shuffle on" (outlined). + static const IconData shuffle_on_outlined = IconData(0xf384, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">shutter_speed</i> — material icon named "shutter speed". + static const IconData shutter_speed = IconData(0xe5a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">shutter_speed</i> — material icon named "shutter speed" (sharp). + static const IconData shutter_speed_sharp = IconData(0xec99, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">shutter_speed</i> — material icon named "shutter speed" (round). + static const IconData shutter_speed_rounded = IconData(0xf0178, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">shutter_speed</i> — material icon named "shutter speed" (outlined). + static const IconData shutter_speed_outlined = IconData(0xf386, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sick</i> — material icon named "sick". + static const IconData sick = IconData(0xe5a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sick</i> — material icon named "sick" (sharp). + static const IconData sick_sharp = IconData(0xec9a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sick</i> — material icon named "sick" (round). + static const IconData sick_rounded = IconData(0xf0179, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sick</i> — material icon named "sick" (outlined). + static const IconData sick_outlined = IconData(0xf387, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sign_language</i> — material icon named "sign language". + static const IconData sign_language = IconData(0xf07c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sign_language</i> — material icon named "sign language" (sharp). + static const IconData sign_language_sharp = IconData(0xf076b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sign_language</i> — material icon named "sign language" (round). + static const IconData sign_language_rounded = IconData(0xf081b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sign_language</i> — material icon named "sign language" (outlined). + static const IconData sign_language_outlined = IconData(0xf0713, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_0_bar</i> — material icon named "signal cellular 0 bar". + static const IconData signal_cellular_0_bar = IconData(0xe5a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_0_bar</i> — material icon named "signal cellular 0 bar" (sharp). + static const IconData signal_cellular_0_bar_sharp = IconData(0xec9b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_0_bar</i> — material icon named "signal cellular 0 bar" (round). + static const IconData signal_cellular_0_bar_rounded = IconData(0xf017a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_0_bar</i> — material icon named "signal cellular 0 bar" (outlined). + static const IconData signal_cellular_0_bar_outlined = IconData(0xf388, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_4_bar</i> — material icon named "signal cellular 4 bar". + static const IconData signal_cellular_4_bar = IconData(0xe5a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_4_bar</i> — material icon named "signal cellular 4 bar" (sharp). + static const IconData signal_cellular_4_bar_sharp = IconData(0xec9c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_4_bar</i> — material icon named "signal cellular 4 bar" (round). + static const IconData signal_cellular_4_bar_rounded = IconData(0xf017b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_4_bar</i> — material icon named "signal cellular 4 bar" (outlined). + static const IconData signal_cellular_4_bar_outlined = IconData(0xf389, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_alt</i> — material icon named "signal cellular alt". + static const IconData signal_cellular_alt = IconData(0xe5a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_alt</i> — material icon named "signal cellular alt" (sharp). + static const IconData signal_cellular_alt_sharp = IconData(0xec9d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_alt</i> — material icon named "signal cellular alt" (round). + static const IconData signal_cellular_alt_rounded = IconData(0xf017c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_alt</i> — material icon named "signal cellular alt" (outlined). + static const IconData signal_cellular_alt_outlined = IconData(0xf38a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_alt_1_bar</i> — material icon named "signal cellular alt 1 bar". + static const IconData signal_cellular_alt_1_bar = IconData(0xf07c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_alt_1_bar</i> — material icon named "signal cellular alt 1 bar" (sharp). + static const IconData signal_cellular_alt_1_bar_sharp = IconData(0xf076c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_alt_1_bar</i> — material icon named "signal cellular alt 1 bar" (round). + static const IconData signal_cellular_alt_1_bar_rounded = IconData(0xf081c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_alt_1_bar</i> — material icon named "signal cellular alt 1 bar" (outlined). + static const IconData signal_cellular_alt_1_bar_outlined = IconData(0xf0714, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_alt_2_bar</i> — material icon named "signal cellular alt 2 bar". + static const IconData signal_cellular_alt_2_bar = IconData(0xf07c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_alt_2_bar</i> — material icon named "signal cellular alt 2 bar" (sharp). + static const IconData signal_cellular_alt_2_bar_sharp = IconData(0xf076d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_alt_2_bar</i> — material icon named "signal cellular alt 2 bar" (round). + static const IconData signal_cellular_alt_2_bar_rounded = IconData(0xf081d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_alt_2_bar</i> — material icon named "signal cellular alt 2 bar" (outlined). + static const IconData signal_cellular_alt_2_bar_outlined = IconData(0xf0715, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_connected_no_internet_0_bar</i> — material icon named "signal cellular connected no internet 0 bar". + static const IconData signal_cellular_connected_no_internet_0_bar = IconData(0xe5a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_connected_no_internet_0_bar</i> — material icon named "signal cellular connected no internet 0 bar" (sharp). + static const IconData signal_cellular_connected_no_internet_0_bar_sharp = IconData(0xec9e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_connected_no_internet_0_bar</i> — material icon named "signal cellular connected no internet 0 bar" (round). + static const IconData signal_cellular_connected_no_internet_0_bar_rounded = IconData(0xf017d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_connected_no_internet_0_bar</i> — material icon named "signal cellular connected no internet 0 bar" (outlined). + static const IconData signal_cellular_connected_no_internet_0_bar_outlined = IconData(0xf38b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_connected_no_internet_4_bar</i> — material icon named "signal cellular connected no internet 4 bar". + static const IconData signal_cellular_connected_no_internet_4_bar = IconData(0xe5a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_connected_no_internet_4_bar</i> — material icon named "signal cellular connected no internet 4 bar" (sharp). + static const IconData signal_cellular_connected_no_internet_4_bar_sharp = IconData(0xec9f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_connected_no_internet_4_bar</i> — material icon named "signal cellular connected no internet 4 bar" (round). + static const IconData signal_cellular_connected_no_internet_4_bar_rounded = IconData(0xf017e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_connected_no_internet_4_bar</i> — material icon named "signal cellular connected no internet 4 bar" (outlined). + static const IconData signal_cellular_connected_no_internet_4_bar_outlined = IconData(0xf38c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_no_sim</i> — material icon named "signal cellular no sim". + static const IconData signal_cellular_no_sim = IconData(0xe5aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_no_sim</i> — material icon named "signal cellular no sim" (sharp). + static const IconData signal_cellular_no_sim_sharp = IconData(0xeca0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_no_sim</i> — material icon named "signal cellular no sim" (round). + static const IconData signal_cellular_no_sim_rounded = IconData(0xf017f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_no_sim</i> — material icon named "signal cellular no sim" (outlined). + static const IconData signal_cellular_no_sim_outlined = IconData(0xf38d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_nodata</i> — material icon named "signal cellular nodata". + static const IconData signal_cellular_nodata = IconData(0xe5ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_nodata</i> — material icon named "signal cellular nodata" (sharp). + static const IconData signal_cellular_nodata_sharp = IconData(0xeca1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_nodata</i> — material icon named "signal cellular nodata" (round). + static const IconData signal_cellular_nodata_rounded = IconData(0xf0180, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_nodata</i> — material icon named "signal cellular nodata" (outlined). + static const IconData signal_cellular_nodata_outlined = IconData(0xf38e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_null</i> — material icon named "signal cellular null". + static const IconData signal_cellular_null = IconData(0xe5ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_null</i> — material icon named "signal cellular null" (sharp). + static const IconData signal_cellular_null_sharp = IconData(0xeca2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_null</i> — material icon named "signal cellular null" (round). + static const IconData signal_cellular_null_rounded = IconData(0xf0181, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_null</i> — material icon named "signal cellular null" (outlined). + static const IconData signal_cellular_null_outlined = IconData(0xf38f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_cellular_off</i> — material icon named "signal cellular off". + static const IconData signal_cellular_off = IconData(0xe5ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_cellular_off</i> — material icon named "signal cellular off" (sharp). + static const IconData signal_cellular_off_sharp = IconData(0xeca3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_cellular_off</i> — material icon named "signal cellular off" (round). + static const IconData signal_cellular_off_rounded = IconData(0xf0182, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_cellular_off</i> — material icon named "signal cellular off" (outlined). + static const IconData signal_cellular_off_outlined = IconData(0xf390, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_wifi_0_bar</i> — material icon named "signal wifi 0 bar". + static const IconData signal_wifi_0_bar = IconData(0xe5ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_wifi_0_bar</i> — material icon named "signal wifi 0 bar" (sharp). + static const IconData signal_wifi_0_bar_sharp = IconData(0xeca4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_wifi_0_bar</i> — material icon named "signal wifi 0 bar" (round). + static const IconData signal_wifi_0_bar_rounded = IconData(0xf0183, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_wifi_0_bar</i> — material icon named "signal wifi 0 bar" (outlined). + static const IconData signal_wifi_0_bar_outlined = IconData(0xf391, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_wifi_4_bar</i> — material icon named "signal wifi 4 bar". + static const IconData signal_wifi_4_bar = IconData(0xe5af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_wifi_4_bar</i> — material icon named "signal wifi 4 bar" (sharp). + static const IconData signal_wifi_4_bar_sharp = IconData(0xeca6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_wifi_4_bar</i> — material icon named "signal wifi 4 bar" (round). + static const IconData signal_wifi_4_bar_rounded = IconData(0xf0185, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_wifi_4_bar</i> — material icon named "signal wifi 4 bar" (outlined). + static const IconData signal_wifi_4_bar_outlined = IconData(0xf393, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_wifi_4_bar_lock</i> — material icon named "signal wifi 4 bar lock". + static const IconData signal_wifi_4_bar_lock = IconData(0xe5b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_wifi_4_bar_lock</i> — material icon named "signal wifi 4 bar lock" (sharp). + static const IconData signal_wifi_4_bar_lock_sharp = IconData(0xeca5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_wifi_4_bar_lock</i> — material icon named "signal wifi 4 bar lock" (round). + static const IconData signal_wifi_4_bar_lock_rounded = IconData(0xf0184, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_wifi_4_bar_lock</i> — material icon named "signal wifi 4 bar lock" (outlined). + static const IconData signal_wifi_4_bar_lock_outlined = IconData(0xf392, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_wifi_bad</i> — material icon named "signal wifi bad". + static const IconData signal_wifi_bad = IconData(0xe5b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_wifi_bad</i> — material icon named "signal wifi bad" (sharp). + static const IconData signal_wifi_bad_sharp = IconData(0xeca7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_wifi_bad</i> — material icon named "signal wifi bad" (round). + static const IconData signal_wifi_bad_rounded = IconData(0xf0186, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_wifi_bad</i> — material icon named "signal wifi bad" (outlined). + static const IconData signal_wifi_bad_outlined = IconData(0xf394, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_wifi_connected_no_internet_4</i> — material icon named "signal wifi connected no internet 4". + static const IconData signal_wifi_connected_no_internet_4 = IconData(0xe5b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_wifi_connected_no_internet_4</i> — material icon named "signal wifi connected no internet 4" (sharp). + static const IconData signal_wifi_connected_no_internet_4_sharp = IconData(0xeca8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_wifi_connected_no_internet_4</i> — material icon named "signal wifi connected no internet 4" (round). + static const IconData signal_wifi_connected_no_internet_4_rounded = IconData(0xf0187, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_wifi_connected_no_internet_4</i> — material icon named "signal wifi connected no internet 4" (outlined). + static const IconData signal_wifi_connected_no_internet_4_outlined = IconData(0xf395, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_wifi_off</i> — material icon named "signal wifi off". + static const IconData signal_wifi_off = IconData(0xe5b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_wifi_off</i> — material icon named "signal wifi off" (sharp). + static const IconData signal_wifi_off_sharp = IconData(0xeca9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_wifi_off</i> — material icon named "signal wifi off" (round). + static const IconData signal_wifi_off_rounded = IconData(0xf0188, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_wifi_off</i> — material icon named "signal wifi off" (outlined). + static const IconData signal_wifi_off_outlined = IconData(0xf396, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_wifi_statusbar_4_bar</i> — material icon named "signal wifi statusbar 4 bar". + static const IconData signal_wifi_statusbar_4_bar = IconData(0xe5b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_wifi_statusbar_4_bar</i> — material icon named "signal wifi statusbar 4 bar" (sharp). + static const IconData signal_wifi_statusbar_4_bar_sharp = IconData(0xecaa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_wifi_statusbar_4_bar</i> — material icon named "signal wifi statusbar 4 bar" (round). + static const IconData signal_wifi_statusbar_4_bar_rounded = IconData(0xf0189, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_wifi_statusbar_4_bar</i> — material icon named "signal wifi statusbar 4 bar" (outlined). + static const IconData signal_wifi_statusbar_4_bar_outlined = IconData(0xf397, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_wifi_statusbar_connected_no_internet_4</i> — material icon named "signal wifi statusbar connected no internet 4". + static const IconData signal_wifi_statusbar_connected_no_internet_4 = IconData(0xe5b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_wifi_statusbar_connected_no_internet_4</i> — material icon named "signal wifi statusbar connected no internet 4" (sharp). + static const IconData signal_wifi_statusbar_connected_no_internet_4_sharp = IconData(0xecab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_wifi_statusbar_connected_no_internet_4</i> — material icon named "signal wifi statusbar connected no internet 4" (round). + static const IconData signal_wifi_statusbar_connected_no_internet_4_rounded = IconData(0xf018a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_wifi_statusbar_connected_no_internet_4</i> — material icon named "signal wifi statusbar connected no internet 4" (outlined). + static const IconData signal_wifi_statusbar_connected_no_internet_4_outlined = IconData(0xf398, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signal_wifi_statusbar_null</i> — material icon named "signal wifi statusbar null". + static const IconData signal_wifi_statusbar_null = IconData(0xe5b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signal_wifi_statusbar_null</i> — material icon named "signal wifi statusbar null" (sharp). + static const IconData signal_wifi_statusbar_null_sharp = IconData(0xecac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signal_wifi_statusbar_null</i> — material icon named "signal wifi statusbar null" (round). + static const IconData signal_wifi_statusbar_null_rounded = IconData(0xf018b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signal_wifi_statusbar_null</i> — material icon named "signal wifi statusbar null" (outlined). + static const IconData signal_wifi_statusbar_null_outlined = IconData(0xf399, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">signpost</i> — material icon named "signpost". + static const IconData signpost = IconData(0xf0569, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">signpost</i> — material icon named "signpost" (sharp). + static const IconData signpost_sharp = IconData(0xf0472, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">signpost</i> — material icon named "signpost" (round). + static const IconData signpost_rounded = IconData(0xf037f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">signpost</i> — material icon named "signpost" (outlined). + static const IconData signpost_outlined = IconData(0xf0660, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sim_card</i> — material icon named "sim card". + static const IconData sim_card = IconData(0xe5b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sim_card</i> — material icon named "sim card" (sharp). + static const IconData sim_card_sharp = IconData(0xecaf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sim_card</i> — material icon named "sim card" (round). + static const IconData sim_card_rounded = IconData(0xf018e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sim_card</i> — material icon named "sim card" (outlined). + static const IconData sim_card_outlined = IconData(0xf39c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sim_card_alert</i> — material icon named "sim card alert". + static const IconData sim_card_alert = IconData(0xe5b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sim_card_alert</i> — material icon named "sim card alert" (sharp). + static const IconData sim_card_alert_sharp = IconData(0xecad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sim_card_alert</i> — material icon named "sim card alert" (round). + static const IconData sim_card_alert_rounded = IconData(0xf018c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sim_card_alert</i> — material icon named "sim card alert" (outlined). + static const IconData sim_card_alert_outlined = IconData(0xf39a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sim_card_download</i> — material icon named "sim card download". + static const IconData sim_card_download = IconData(0xe5b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sim_card_download</i> — material icon named "sim card download" (sharp). + static const IconData sim_card_download_sharp = IconData(0xecae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sim_card_download</i> — material icon named "sim card download" (round). + static const IconData sim_card_download_rounded = IconData(0xf018d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sim_card_download</i> — material icon named "sim card download" (outlined). + static const IconData sim_card_download_outlined = IconData(0xf39b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">single_bed</i> — material icon named "single bed". + static const IconData single_bed = IconData(0xe5ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">single_bed</i> — material icon named "single bed" (sharp). + static const IconData single_bed_sharp = IconData(0xecb0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">single_bed</i> — material icon named "single bed" (round). + static const IconData single_bed_rounded = IconData(0xf018f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">single_bed</i> — material icon named "single bed" (outlined). + static const IconData single_bed_outlined = IconData(0xf39d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sip</i> — material icon named "sip". + static const IconData sip = IconData(0xe5bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sip</i> — material icon named "sip" (sharp). + static const IconData sip_sharp = IconData(0xecb1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sip</i> — material icon named "sip" (round). + static const IconData sip_rounded = IconData(0xf0190, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sip</i> — material icon named "sip" (outlined). + static const IconData sip_outlined = IconData(0xf39e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">skateboarding</i> — material icon named "skateboarding". + static const IconData skateboarding = IconData(0xe5bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">skateboarding</i> — material icon named "skateboarding" (sharp). + static const IconData skateboarding_sharp = IconData(0xecb2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">skateboarding</i> — material icon named "skateboarding" (round). + static const IconData skateboarding_rounded = IconData(0xf0191, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">skateboarding</i> — material icon named "skateboarding" (outlined). + static const IconData skateboarding_outlined = IconData(0xf39f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">skip_next</i> — material icon named "skip next". + static const IconData skip_next = IconData(0xe5bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">skip_next</i> — material icon named "skip next" (sharp). + static const IconData skip_next_sharp = IconData(0xecb3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">skip_next</i> — material icon named "skip next" (round). + static const IconData skip_next_rounded = IconData(0xf0192, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">skip_next</i> — material icon named "skip next" (outlined). + static const IconData skip_next_outlined = IconData(0xf3a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">skip_previous</i> — material icon named "skip previous". + static const IconData skip_previous = IconData(0xe5be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">skip_previous</i> — material icon named "skip previous" (sharp). + static const IconData skip_previous_sharp = IconData(0xecb4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">skip_previous</i> — material icon named "skip previous" (round). + static const IconData skip_previous_rounded = IconData(0xf0193, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">skip_previous</i> — material icon named "skip previous" (outlined). + static const IconData skip_previous_outlined = IconData(0xf3a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sledding</i> — material icon named "sledding". + static const IconData sledding = IconData(0xe5bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sledding</i> — material icon named "sledding" (sharp). + static const IconData sledding_sharp = IconData(0xecb5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sledding</i> — material icon named "sledding" (round). + static const IconData sledding_rounded = IconData(0xf0194, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sledding</i> — material icon named "sledding" (outlined). + static const IconData sledding_outlined = IconData(0xf3a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">slideshow</i> — material icon named "slideshow". + static const IconData slideshow = IconData(0xe5c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">slideshow</i> — material icon named "slideshow" (sharp). + static const IconData slideshow_sharp = IconData(0xecb6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">slideshow</i> — material icon named "slideshow" (round). + static const IconData slideshow_rounded = IconData(0xf0195, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">slideshow</i> — material icon named "slideshow" (outlined). + static const IconData slideshow_outlined = IconData(0xf3a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">slow_motion_video</i> — material icon named "slow motion video". + static const IconData slow_motion_video = IconData(0xe5c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">slow_motion_video</i> — material icon named "slow motion video" (sharp). + static const IconData slow_motion_video_sharp = IconData(0xecb7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">slow_motion_video</i> — material icon named "slow motion video" (round). + static const IconData slow_motion_video_rounded = IconData(0xf0196, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">slow_motion_video</i> — material icon named "slow motion video" (outlined). + static const IconData slow_motion_video_outlined = IconData(0xf3a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">smart_button</i> — material icon named "smart button". + static const IconData smart_button = IconData(0xe5c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">smart_button</i> — material icon named "smart button" (sharp). + static const IconData smart_button_sharp = IconData(0xecb8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">smart_button</i> — material icon named "smart button" (round). + static const IconData smart_button_rounded = IconData(0xf0197, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">smart_button</i> — material icon named "smart button" (outlined). + static const IconData smart_button_outlined = IconData(0xf3a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">smart_display</i> — material icon named "smart display". + static const IconData smart_display = IconData(0xe5c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">smart_display</i> — material icon named "smart display" (sharp). + static const IconData smart_display_sharp = IconData(0xecb9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">smart_display</i> — material icon named "smart display" (round). + static const IconData smart_display_rounded = IconData(0xf0198, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">smart_display</i> — material icon named "smart display" (outlined). + static const IconData smart_display_outlined = IconData(0xf3a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">smart_screen</i> — material icon named "smart screen". + static const IconData smart_screen = IconData(0xe5c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">smart_screen</i> — material icon named "smart screen" (sharp). + static const IconData smart_screen_sharp = IconData(0xecba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">smart_screen</i> — material icon named "smart screen" (round). + static const IconData smart_screen_rounded = IconData(0xf0199, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">smart_screen</i> — material icon named "smart screen" (outlined). + static const IconData smart_screen_outlined = IconData(0xf3a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">smart_toy</i> — material icon named "smart toy". + static const IconData smart_toy = IconData(0xe5c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">smart_toy</i> — material icon named "smart toy" (sharp). + static const IconData smart_toy_sharp = IconData(0xecbb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">smart_toy</i> — material icon named "smart toy" (round). + static const IconData smart_toy_rounded = IconData(0xf019a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">smart_toy</i> — material icon named "smart toy" (outlined). + static const IconData smart_toy_outlined = IconData(0xf3a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">smartphone</i> — material icon named "smartphone". + static const IconData smartphone = IconData(0xe5c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">smartphone</i> — material icon named "smartphone" (sharp). + static const IconData smartphone_sharp = IconData(0xecbc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">smartphone</i> — material icon named "smartphone" (round). + static const IconData smartphone_rounded = IconData(0xf019b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">smartphone</i> — material icon named "smartphone" (outlined). + static const IconData smartphone_outlined = IconData(0xf3a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">smoke_free</i> — material icon named "smoke free". + static const IconData smoke_free = IconData(0xe5c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">smoke_free</i> — material icon named "smoke free" (sharp). + static const IconData smoke_free_sharp = IconData(0xecbd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">smoke_free</i> — material icon named "smoke free" (round). + static const IconData smoke_free_rounded = IconData(0xf019c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">smoke_free</i> — material icon named "smoke free" (outlined). + static const IconData smoke_free_outlined = IconData(0xf3aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">smoking_rooms</i> — material icon named "smoking rooms". + static const IconData smoking_rooms = IconData(0xe5c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">smoking_rooms</i> — material icon named "smoking rooms" (sharp). + static const IconData smoking_rooms_sharp = IconData(0xecbe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">smoking_rooms</i> — material icon named "smoking rooms" (round). + static const IconData smoking_rooms_rounded = IconData(0xf019d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">smoking_rooms</i> — material icon named "smoking rooms" (outlined). + static const IconData smoking_rooms_outlined = IconData(0xf3ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sms</i> — material icon named "sms". + static const IconData sms = IconData(0xe5c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sms</i> — material icon named "sms" (sharp). + static const IconData sms_sharp = IconData(0xecc0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sms</i> — material icon named "sms" (round). + static const IconData sms_rounded = IconData(0xf019f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sms</i> — material icon named "sms" (outlined). + static const IconData sms_outlined = IconData(0xf3ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sms_failed</i> — material icon named "sms failed". + static const IconData sms_failed = IconData(0xe5ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sms_failed</i> — material icon named "sms failed" (sharp). + static const IconData sms_failed_sharp = IconData(0xecbf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sms_failed</i> — material icon named "sms failed" (round). + static const IconData sms_failed_rounded = IconData(0xf019e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sms_failed</i> — material icon named "sms failed" (outlined). + static const IconData sms_failed_outlined = IconData(0xf3ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">snapchat</i> — material icon named "snapchat". + static const IconData snapchat = IconData(0xf056a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">snapchat</i> — material icon named "snapchat" (sharp). + static const IconData snapchat_sharp = IconData(0xf0473, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">snapchat</i> — material icon named "snapchat" (round). + static const IconData snapchat_rounded = IconData(0xf0380, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">snapchat</i> — material icon named "snapchat" (outlined). + static const IconData snapchat_outlined = IconData(0xf0661, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">snippet_folder</i> — material icon named "snippet folder". + static const IconData snippet_folder = IconData(0xe5cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">snippet_folder</i> — material icon named "snippet folder" (sharp). + static const IconData snippet_folder_sharp = IconData(0xecc1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">snippet_folder</i> — material icon named "snippet folder" (round). + static const IconData snippet_folder_rounded = IconData(0xf01a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">snippet_folder</i> — material icon named "snippet folder" (outlined). + static const IconData snippet_folder_outlined = IconData(0xf3ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">snooze</i> — material icon named "snooze". + static const IconData snooze = IconData(0xe5cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">snooze</i> — material icon named "snooze" (sharp). + static const IconData snooze_sharp = IconData(0xecc2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">snooze</i> — material icon named "snooze" (round). + static const IconData snooze_rounded = IconData(0xf01a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">snooze</i> — material icon named "snooze" (outlined). + static const IconData snooze_outlined = IconData(0xf3af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">snowboarding</i> — material icon named "snowboarding". + static const IconData snowboarding = IconData(0xe5cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">snowboarding</i> — material icon named "snowboarding" (sharp). + static const IconData snowboarding_sharp = IconData(0xecc3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">snowboarding</i> — material icon named "snowboarding" (round). + static const IconData snowboarding_rounded = IconData(0xf01a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">snowboarding</i> — material icon named "snowboarding" (outlined). + static const IconData snowboarding_outlined = IconData(0xf3b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">snowing</i> — material icon named "snowing". + static const IconData snowing = IconData(0xf056b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">snowmobile</i> — material icon named "snowmobile". + static const IconData snowmobile = IconData(0xe5ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">snowmobile</i> — material icon named "snowmobile" (sharp). + static const IconData snowmobile_sharp = IconData(0xecc4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">snowmobile</i> — material icon named "snowmobile" (round). + static const IconData snowmobile_rounded = IconData(0xf01a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">snowmobile</i> — material icon named "snowmobile" (outlined). + static const IconData snowmobile_outlined = IconData(0xf3b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">snowshoeing</i> — material icon named "snowshoeing". + static const IconData snowshoeing = IconData(0xe5cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">snowshoeing</i> — material icon named "snowshoeing" (sharp). + static const IconData snowshoeing_sharp = IconData(0xecc5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">snowshoeing</i> — material icon named "snowshoeing" (round). + static const IconData snowshoeing_rounded = IconData(0xf01a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">snowshoeing</i> — material icon named "snowshoeing" (outlined). + static const IconData snowshoeing_outlined = IconData(0xf3b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">soap</i> — material icon named "soap". + static const IconData soap = IconData(0xe5d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">soap</i> — material icon named "soap" (sharp). + static const IconData soap_sharp = IconData(0xecc6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">soap</i> — material icon named "soap" (round). + static const IconData soap_rounded = IconData(0xf01a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">soap</i> — material icon named "soap" (outlined). + static const IconData soap_outlined = IconData(0xf3b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">social_distance</i> — material icon named "social distance". + static const IconData social_distance = IconData(0xe5d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">social_distance</i> — material icon named "social distance" (sharp). + static const IconData social_distance_sharp = IconData(0xecc7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">social_distance</i> — material icon named "social distance" (round). + static const IconData social_distance_rounded = IconData(0xf01a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">social_distance</i> — material icon named "social distance" (outlined). + static const IconData social_distance_outlined = IconData(0xf3b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">solar_power</i> — material icon named "solar power". + static const IconData solar_power = IconData(0xf07c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">solar_power</i> — material icon named "solar power" (sharp). + static const IconData solar_power_sharp = IconData(0xf076e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">solar_power</i> — material icon named "solar power" (round). + static const IconData solar_power_rounded = IconData(0xf081e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">solar_power</i> — material icon named "solar power" (outlined). + static const IconData solar_power_outlined = IconData(0xf0716, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sort</i> — material icon named "sort". + static const IconData sort = IconData(0xe5d2, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">sort</i> — material icon named "sort" (sharp). + static const IconData sort_sharp = IconData(0xecc9, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">sort</i> — material icon named "sort" (round). + static const IconData sort_rounded = IconData(0xf01a8, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">sort</i> — material icon named "sort" (outlined). + static const IconData sort_outlined = IconData(0xf3b6, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">sort_by_alpha</i> — material icon named "sort by alpha". + static const IconData sort_by_alpha = IconData(0xe5d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sort_by_alpha</i> — material icon named "sort by alpha" (sharp). + static const IconData sort_by_alpha_sharp = IconData(0xecc8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sort_by_alpha</i> — material icon named "sort by alpha" (round). + static const IconData sort_by_alpha_rounded = IconData(0xf01a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sort_by_alpha</i> — material icon named "sort by alpha" (outlined). + static const IconData sort_by_alpha_outlined = IconData(0xf3b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sos</i> — material icon named "sos". + static const IconData sos = IconData(0xf07c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sos</i> — material icon named "sos" (sharp). + static const IconData sos_sharp = IconData(0xf076f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sos</i> — material icon named "sos" (round). + static const IconData sos_rounded = IconData(0xf081f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sos</i> — material icon named "sos" (outlined). + static const IconData sos_outlined = IconData(0xf0717, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">soup_kitchen</i> — material icon named "soup kitchen". + static const IconData soup_kitchen = IconData(0xf056c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">soup_kitchen</i> — material icon named "soup kitchen" (sharp). + static const IconData soup_kitchen_sharp = IconData(0xf0474, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">soup_kitchen</i> — material icon named "soup kitchen" (round). + static const IconData soup_kitchen_rounded = IconData(0xf0381, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">soup_kitchen</i> — material icon named "soup kitchen" (outlined). + static const IconData soup_kitchen_outlined = IconData(0xf0662, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">source</i> — material icon named "source". + static const IconData source = IconData(0xe5d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">source</i> — material icon named "source" (sharp). + static const IconData source_sharp = IconData(0xecca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">source</i> — material icon named "source" (round). + static const IconData source_rounded = IconData(0xf01a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">source</i> — material icon named "source" (outlined). + static const IconData source_outlined = IconData(0xf3b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">south</i> — material icon named "south". + static const IconData south = IconData(0xe5d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">south</i> — material icon named "south" (sharp). + static const IconData south_sharp = IconData(0xeccc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">south</i> — material icon named "south" (round). + static const IconData south_rounded = IconData(0xf01ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">south</i> — material icon named "south" (outlined). + static const IconData south_outlined = IconData(0xf3b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">south_america</i> — material icon named "south america". + static const IconData south_america = IconData(0xf056d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">south_america</i> — material icon named "south america" (sharp). + static const IconData south_america_sharp = IconData(0xf0475, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">south_america</i> — material icon named "south america" (round). + static const IconData south_america_rounded = IconData(0xf0382, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">south_america</i> — material icon named "south america" (outlined). + static const IconData south_america_outlined = IconData(0xf0663, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">south_east</i> — material icon named "south east". + static const IconData south_east = IconData(0xe5d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">south_east</i> — material icon named "south east" (sharp). + static const IconData south_east_sharp = IconData(0xeccb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">south_east</i> — material icon named "south east" (round). + static const IconData south_east_rounded = IconData(0xf01aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">south_east</i> — material icon named "south east" (outlined). + static const IconData south_east_outlined = IconData(0xf3b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">south_west</i> — material icon named "south west". + static const IconData south_west = IconData(0xe5d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">south_west</i> — material icon named "south west" (sharp). + static const IconData south_west_sharp = IconData(0xeccd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">south_west</i> — material icon named "south west" (round). + static const IconData south_west_rounded = IconData(0xf01ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">south_west</i> — material icon named "south west" (outlined). + static const IconData south_west_outlined = IconData(0xf3ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">spa</i> — material icon named "spa". + static const IconData spa = IconData(0xe5d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">spa</i> — material icon named "spa" (sharp). + static const IconData spa_sharp = IconData(0xecce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">spa</i> — material icon named "spa" (round). + static const IconData spa_rounded = IconData(0xf01ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">spa</i> — material icon named "spa" (outlined). + static const IconData spa_outlined = IconData(0xf3bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">space_bar</i> — material icon named "space bar". + static const IconData space_bar = IconData(0xe5d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">space_bar</i> — material icon named "space bar" (sharp). + static const IconData space_bar_sharp = IconData(0xeccf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">space_bar</i> — material icon named "space bar" (round). + static const IconData space_bar_rounded = IconData(0xf01ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">space_bar</i> — material icon named "space bar" (outlined). + static const IconData space_bar_outlined = IconData(0xf3bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">space_dashboard</i> — material icon named "space dashboard". + static const IconData space_dashboard = IconData(0xe5da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">space_dashboard</i> — material icon named "space dashboard" (sharp). + static const IconData space_dashboard_sharp = IconData(0xecd0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">space_dashboard</i> — material icon named "space dashboard" (round). + static const IconData space_dashboard_rounded = IconData(0xf01af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">space_dashboard</i> — material icon named "space dashboard" (outlined). + static const IconData space_dashboard_outlined = IconData(0xf3bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">spatial_audio</i> — material icon named "spatial audio". + static const IconData spatial_audio = IconData(0xf07c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">spatial_audio</i> — material icon named "spatial audio" (sharp). + static const IconData spatial_audio_sharp = IconData(0xf0771, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">spatial_audio</i> — material icon named "spatial audio" (round). + static const IconData spatial_audio_rounded = IconData(0xf0821, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">spatial_audio</i> — material icon named "spatial audio" (outlined). + static const IconData spatial_audio_outlined = IconData(0xf0719, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">spatial_audio_off</i> — material icon named "spatial audio off". + static const IconData spatial_audio_off = IconData(0xf07c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">spatial_audio_off</i> — material icon named "spatial audio off" (sharp). + static const IconData spatial_audio_off_sharp = IconData(0xf0770, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">spatial_audio_off</i> — material icon named "spatial audio off" (round). + static const IconData spatial_audio_off_rounded = IconData(0xf0820, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">spatial_audio_off</i> — material icon named "spatial audio off" (outlined). + static const IconData spatial_audio_off_outlined = IconData(0xf0718, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">spatial_tracking</i> — material icon named "spatial tracking". + static const IconData spatial_tracking = IconData(0xf07ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">spatial_tracking</i> — material icon named "spatial tracking" (sharp). + static const IconData spatial_tracking_sharp = IconData(0xf0772, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">spatial_tracking</i> — material icon named "spatial tracking" (round). + static const IconData spatial_tracking_rounded = IconData(0xf0822, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">spatial_tracking</i> — material icon named "spatial tracking" (outlined). + static const IconData spatial_tracking_outlined = IconData(0xf071a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">speaker</i> — material icon named "speaker". + static const IconData speaker = IconData(0xe5db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">speaker</i> — material icon named "speaker" (sharp). + static const IconData speaker_sharp = IconData(0xecd5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">speaker</i> — material icon named "speaker" (round). + static const IconData speaker_rounded = IconData(0xf01b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">speaker</i> — material icon named "speaker" (outlined). + static const IconData speaker_outlined = IconData(0xf3c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">speaker_group</i> — material icon named "speaker group". + static const IconData speaker_group = IconData(0xe5dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">speaker_group</i> — material icon named "speaker group" (sharp). + static const IconData speaker_group_sharp = IconData(0xecd1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">speaker_group</i> — material icon named "speaker group" (round). + static const IconData speaker_group_rounded = IconData(0xf01b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">speaker_group</i> — material icon named "speaker group" (outlined). + static const IconData speaker_group_outlined = IconData(0xf3be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">speaker_notes</i> — material icon named "speaker notes". + static const IconData speaker_notes = IconData(0xe5dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">speaker_notes</i> — material icon named "speaker notes" (sharp). + static const IconData speaker_notes_sharp = IconData(0xecd3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">speaker_notes</i> — material icon named "speaker notes" (round). + static const IconData speaker_notes_rounded = IconData(0xf01b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">speaker_notes</i> — material icon named "speaker notes" (outlined). + static const IconData speaker_notes_outlined = IconData(0xf3c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">speaker_notes_off</i> — material icon named "speaker notes off". + static const IconData speaker_notes_off = IconData(0xe5de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">speaker_notes_off</i> — material icon named "speaker notes off" (sharp). + static const IconData speaker_notes_off_sharp = IconData(0xecd2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">speaker_notes_off</i> — material icon named "speaker notes off" (round). + static const IconData speaker_notes_off_rounded = IconData(0xf01b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">speaker_notes_off</i> — material icon named "speaker notes off" (outlined). + static const IconData speaker_notes_off_outlined = IconData(0xf3bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">speaker_phone</i> — material icon named "speaker phone". + static const IconData speaker_phone = IconData(0xe5df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">speaker_phone</i> — material icon named "speaker phone" (sharp). + static const IconData speaker_phone_sharp = IconData(0xecd4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">speaker_phone</i> — material icon named "speaker phone" (round). + static const IconData speaker_phone_rounded = IconData(0xf01b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">speaker_phone</i> — material icon named "speaker phone" (outlined). + static const IconData speaker_phone_outlined = IconData(0xf3c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">speed</i> — material icon named "speed". + static const IconData speed = IconData(0xe5e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">speed</i> — material icon named "speed" (sharp). + static const IconData speed_sharp = IconData(0xecd6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">speed</i> — material icon named "speed" (round). + static const IconData speed_rounded = IconData(0xf01b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">speed</i> — material icon named "speed" (outlined). + static const IconData speed_outlined = IconData(0xf3c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">spellcheck</i> — material icon named "spellcheck". + static const IconData spellcheck = IconData(0xe5e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">spellcheck</i> — material icon named "spellcheck" (sharp). + static const IconData spellcheck_sharp = IconData(0xecd7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">spellcheck</i> — material icon named "spellcheck" (round). + static const IconData spellcheck_rounded = IconData(0xf01b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">spellcheck</i> — material icon named "spellcheck" (outlined). + static const IconData spellcheck_outlined = IconData(0xf3c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">splitscreen</i> — material icon named "splitscreen". + static const IconData splitscreen = IconData(0xe5e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">splitscreen</i> — material icon named "splitscreen" (sharp). + static const IconData splitscreen_sharp = IconData(0xecd8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">splitscreen</i> — material icon named "splitscreen" (round). + static const IconData splitscreen_rounded = IconData(0xf01b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">splitscreen</i> — material icon named "splitscreen" (outlined). + static const IconData splitscreen_outlined = IconData(0xf3c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">spoke</i> — material icon named "spoke". + static const IconData spoke = IconData(0xf056e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">spoke</i> — material icon named "spoke" (sharp). + static const IconData spoke_sharp = IconData(0xf0476, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">spoke</i> — material icon named "spoke" (round). + static const IconData spoke_rounded = IconData(0xf0383, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">spoke</i> — material icon named "spoke" (outlined). + static const IconData spoke_outlined = IconData(0xf0664, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports</i> — material icon named "sports". + static const IconData sports = IconData(0xe5e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports</i> — material icon named "sports" (sharp). + static const IconData sports_sharp = IconData(0xece7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports</i> — material icon named "sports" (round). + static const IconData sports_rounded = IconData(0xf01c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports</i> — material icon named "sports" (outlined). + static const IconData sports_outlined = IconData(0xf3d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_bar</i> — material icon named "sports bar". + static const IconData sports_bar = IconData(0xe5e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_bar</i> — material icon named "sports bar" (sharp). + static const IconData sports_bar_sharp = IconData(0xecd9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_bar</i> — material icon named "sports bar" (round). + static const IconData sports_bar_rounded = IconData(0xf01b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_bar</i> — material icon named "sports bar" (outlined). + static const IconData sports_bar_outlined = IconData(0xf3c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_baseball</i> — material icon named "sports baseball". + static const IconData sports_baseball = IconData(0xe5e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_baseball</i> — material icon named "sports baseball" (sharp). + static const IconData sports_baseball_sharp = IconData(0xecda, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_baseball</i> — material icon named "sports baseball" (round). + static const IconData sports_baseball_rounded = IconData(0xf01b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_baseball</i> — material icon named "sports baseball" (outlined). + static const IconData sports_baseball_outlined = IconData(0xf3c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_basketball</i> — material icon named "sports basketball". + static const IconData sports_basketball = IconData(0xe5e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_basketball</i> — material icon named "sports basketball" (sharp). + static const IconData sports_basketball_sharp = IconData(0xecdb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_basketball</i> — material icon named "sports basketball" (round). + static const IconData sports_basketball_rounded = IconData(0xf01ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_basketball</i> — material icon named "sports basketball" (outlined). + static const IconData sports_basketball_outlined = IconData(0xf3c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_cricket</i> — material icon named "sports cricket". + static const IconData sports_cricket = IconData(0xe5e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_cricket</i> — material icon named "sports cricket" (sharp). + static const IconData sports_cricket_sharp = IconData(0xecdc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_cricket</i> — material icon named "sports cricket" (round). + static const IconData sports_cricket_rounded = IconData(0xf01bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_cricket</i> — material icon named "sports cricket" (outlined). + static const IconData sports_cricket_outlined = IconData(0xf3c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_esports</i> — material icon named "sports esports". + static const IconData sports_esports = IconData(0xe5e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_esports</i> — material icon named "sports esports" (sharp). + static const IconData sports_esports_sharp = IconData(0xecdd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_esports</i> — material icon named "sports esports" (round). + static const IconData sports_esports_rounded = IconData(0xf01bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_esports</i> — material icon named "sports esports" (outlined). + static const IconData sports_esports_outlined = IconData(0xf3ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_football</i> — material icon named "sports football". + static const IconData sports_football = IconData(0xe5e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_football</i> — material icon named "sports football" (sharp). + static const IconData sports_football_sharp = IconData(0xecde, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_football</i> — material icon named "sports football" (round). + static const IconData sports_football_rounded = IconData(0xf01bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_football</i> — material icon named "sports football" (outlined). + static const IconData sports_football_outlined = IconData(0xf3cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_golf</i> — material icon named "sports golf". + static const IconData sports_golf = IconData(0xe5ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_golf</i> — material icon named "sports golf" (sharp). + static const IconData sports_golf_sharp = IconData(0xecdf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_golf</i> — material icon named "sports golf" (round). + static const IconData sports_golf_rounded = IconData(0xf01be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_golf</i> — material icon named "sports golf" (outlined). + static const IconData sports_golf_outlined = IconData(0xf3cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_gymnastics</i> — material icon named "sports gymnastics". + static const IconData sports_gymnastics = IconData(0xf06c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_gymnastics</i> — material icon named "sports gymnastics" (sharp). + static const IconData sports_gymnastics_sharp = IconData(0xf06b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_gymnastics</i> — material icon named "sports gymnastics" (round). + static const IconData sports_gymnastics_rounded = IconData(0xf06d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_gymnastics</i> — material icon named "sports gymnastics" (outlined). + static const IconData sports_gymnastics_outlined = IconData(0xf06a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_handball</i> — material icon named "sports handball". + static const IconData sports_handball = IconData(0xe5eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_handball</i> — material icon named "sports handball" (sharp). + static const IconData sports_handball_sharp = IconData(0xece0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_handball</i> — material icon named "sports handball" (round). + static const IconData sports_handball_rounded = IconData(0xf01bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_handball</i> — material icon named "sports handball" (outlined). + static const IconData sports_handball_outlined = IconData(0xf3cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_hockey</i> — material icon named "sports hockey". + static const IconData sports_hockey = IconData(0xe5ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_hockey</i> — material icon named "sports hockey" (sharp). + static const IconData sports_hockey_sharp = IconData(0xece1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_hockey</i> — material icon named "sports hockey" (round). + static const IconData sports_hockey_rounded = IconData(0xf01c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_hockey</i> — material icon named "sports hockey" (outlined). + static const IconData sports_hockey_outlined = IconData(0xf3ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_kabaddi</i> — material icon named "sports kabaddi". + static const IconData sports_kabaddi = IconData(0xe5ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_kabaddi</i> — material icon named "sports kabaddi" (sharp). + static const IconData sports_kabaddi_sharp = IconData(0xece2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_kabaddi</i> — material icon named "sports kabaddi" (round). + static const IconData sports_kabaddi_rounded = IconData(0xf01c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_kabaddi</i> — material icon named "sports kabaddi" (outlined). + static const IconData sports_kabaddi_outlined = IconData(0xf3cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_martial_arts</i> — material icon named "sports martial arts". + static const IconData sports_martial_arts = IconData(0xf056f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_martial_arts</i> — material icon named "sports martial arts" (sharp). + static const IconData sports_martial_arts_sharp = IconData(0xf0477, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_martial_arts</i> — material icon named "sports martial arts" (round). + static const IconData sports_martial_arts_rounded = IconData(0xf0384, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_martial_arts</i> — material icon named "sports martial arts" (outlined). + static const IconData sports_martial_arts_outlined = IconData(0xf0665, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_mma</i> — material icon named "sports mma". + static const IconData sports_mma = IconData(0xe5ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_mma</i> — material icon named "sports mma" (sharp). + static const IconData sports_mma_sharp = IconData(0xece3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_mma</i> — material icon named "sports mma" (round). + static const IconData sports_mma_rounded = IconData(0xf01c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_mma</i> — material icon named "sports mma" (outlined). + static const IconData sports_mma_outlined = IconData(0xf3d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_motorsports</i> — material icon named "sports motorsports". + static const IconData sports_motorsports = IconData(0xe5ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_motorsports</i> — material icon named "sports motorsports" (sharp). + static const IconData sports_motorsports_sharp = IconData(0xece4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_motorsports</i> — material icon named "sports motorsports" (round). + static const IconData sports_motorsports_rounded = IconData(0xf01c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_motorsports</i> — material icon named "sports motorsports" (outlined). + static const IconData sports_motorsports_outlined = IconData(0xf3d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_rugby</i> — material icon named "sports rugby". + static const IconData sports_rugby = IconData(0xe5f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_rugby</i> — material icon named "sports rugby" (sharp). + static const IconData sports_rugby_sharp = IconData(0xece5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_rugby</i> — material icon named "sports rugby" (round). + static const IconData sports_rugby_rounded = IconData(0xf01c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_rugby</i> — material icon named "sports rugby" (outlined). + static const IconData sports_rugby_outlined = IconData(0xf3d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_score</i> — material icon named "sports score". + static const IconData sports_score = IconData(0xe5f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_score</i> — material icon named "sports score" (sharp). + static const IconData sports_score_sharp = IconData(0xece6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_score</i> — material icon named "sports score" (round). + static const IconData sports_score_rounded = IconData(0xf01c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_score</i> — material icon named "sports score" (outlined). + static const IconData sports_score_outlined = IconData(0xf3d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_soccer</i> — material icon named "sports soccer". + static const IconData sports_soccer = IconData(0xe5f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_soccer</i> — material icon named "sports soccer" (sharp). + static const IconData sports_soccer_sharp = IconData(0xece8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_soccer</i> — material icon named "sports soccer" (round). + static const IconData sports_soccer_rounded = IconData(0xf01c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_soccer</i> — material icon named "sports soccer" (outlined). + static const IconData sports_soccer_outlined = IconData(0xf3d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_tennis</i> — material icon named "sports tennis". + static const IconData sports_tennis = IconData(0xe5f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_tennis</i> — material icon named "sports tennis" (sharp). + static const IconData sports_tennis_sharp = IconData(0xece9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_tennis</i> — material icon named "sports tennis" (round). + static const IconData sports_tennis_rounded = IconData(0xf01c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_tennis</i> — material icon named "sports tennis" (outlined). + static const IconData sports_tennis_outlined = IconData(0xf3d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sports_volleyball</i> — material icon named "sports volleyball". + static const IconData sports_volleyball = IconData(0xe5f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sports_volleyball</i> — material icon named "sports volleyball" (sharp). + static const IconData sports_volleyball_sharp = IconData(0xecea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sports_volleyball</i> — material icon named "sports volleyball" (round). + static const IconData sports_volleyball_rounded = IconData(0xf01c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sports_volleyball</i> — material icon named "sports volleyball" (outlined). + static const IconData sports_volleyball_outlined = IconData(0xf3d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">square</i> — material icon named "square". + static const IconData square = IconData(0xf0570, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">square</i> — material icon named "square" (sharp). + static const IconData square_sharp = IconData(0xf0478, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">square</i> — material icon named "square" (round). + static const IconData square_rounded = IconData(0xf0385, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">square</i> — material icon named "square" (outlined). + static const IconData square_outlined = IconData(0xf0666, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">square_foot</i> — material icon named "square foot". + static const IconData square_foot = IconData(0xe5f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">square_foot</i> — material icon named "square foot" (sharp). + static const IconData square_foot_sharp = IconData(0xeceb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">square_foot</i> — material icon named "square foot" (round). + static const IconData square_foot_rounded = IconData(0xf01ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">square_foot</i> — material icon named "square foot" (outlined). + static const IconData square_foot_outlined = IconData(0xf3d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">ssid_chart</i> — material icon named "ssid chart". + static const IconData ssid_chart = IconData(0xf0571, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">ssid_chart</i> — material icon named "ssid chart" (sharp). + static const IconData ssid_chart_sharp = IconData(0xf0479, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">ssid_chart</i> — material icon named "ssid chart" (round). + static const IconData ssid_chart_rounded = IconData(0xf0386, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">ssid_chart</i> — material icon named "ssid chart" (outlined). + static const IconData ssid_chart_outlined = IconData(0xf0667, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stacked_bar_chart</i> — material icon named "stacked bar chart". + static const IconData stacked_bar_chart = IconData(0xe5f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stacked_bar_chart</i> — material icon named "stacked bar chart" (sharp). + static const IconData stacked_bar_chart_sharp = IconData(0xecec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stacked_bar_chart</i> — material icon named "stacked bar chart" (round). + static const IconData stacked_bar_chart_rounded = IconData(0xf01cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stacked_bar_chart</i> — material icon named "stacked bar chart" (outlined). + static const IconData stacked_bar_chart_outlined = IconData(0xf3d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stacked_line_chart</i> — material icon named "stacked line chart". + static const IconData stacked_line_chart = IconData(0xe5f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stacked_line_chart</i> — material icon named "stacked line chart" (sharp). + static const IconData stacked_line_chart_sharp = IconData(0xeced, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stacked_line_chart</i> — material icon named "stacked line chart" (round). + static const IconData stacked_line_chart_rounded = IconData(0xf01cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stacked_line_chart</i> — material icon named "stacked line chart" (outlined). + static const IconData stacked_line_chart_outlined = IconData(0xf3da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stadium</i> — material icon named "stadium". + static const IconData stadium = IconData(0xf0572, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stadium</i> — material icon named "stadium" (sharp). + static const IconData stadium_sharp = IconData(0xf047a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stadium</i> — material icon named "stadium" (round). + static const IconData stadium_rounded = IconData(0xf0387, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stadium</i> — material icon named "stadium" (outlined). + static const IconData stadium_outlined = IconData(0xf0668, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stairs</i> — material icon named "stairs". + static const IconData stairs = IconData(0xe5f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stairs</i> — material icon named "stairs" (sharp). + static const IconData stairs_sharp = IconData(0xecee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stairs</i> — material icon named "stairs" (round). + static const IconData stairs_rounded = IconData(0xf01cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stairs</i> — material icon named "stairs" (outlined). + static const IconData stairs_outlined = IconData(0xf3db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">star</i> — material icon named "star". + static const IconData star = IconData(0xe5f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">star</i> — material icon named "star" (sharp). + static const IconData star_sharp = IconData(0xecf5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">star</i> — material icon named "star" (round). + static const IconData star_rounded = IconData(0xf01d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">star</i> — material icon named "star" (outlined). + static const IconData star_outlined = IconData(0xf3e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">star_border</i> — material icon named "star border". + static const IconData star_border = IconData(0xe5fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">star_border</i> — material icon named "star border" (sharp). + static const IconData star_border_sharp = IconData(0xecf0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">star_border</i> — material icon named "star border" (round). + static const IconData star_border_rounded = IconData(0xf01cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">star_border</i> — material icon named "star border" (outlined). + static const IconData star_border_outlined = IconData(0xf3dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">star_border_purple500</i> — material icon named "star border purple500". + static const IconData star_border_purple500 = IconData(0xe5fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">star_border_purple500</i> — material icon named "star border purple500" (sharp). + static const IconData star_border_purple500_sharp = IconData(0xecef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">star_border_purple500</i> — material icon named "star border purple500" (round). + static const IconData star_border_purple500_rounded = IconData(0xf01ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">star_border_purple500</i> — material icon named "star border purple500" (outlined). + static const IconData star_border_purple500_outlined = IconData(0xf3dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">star_half</i> — material icon named "star half". + static const IconData star_half = IconData(0xe5fc, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">star_half</i> — material icon named "star half" (sharp). + static const IconData star_half_sharp = IconData(0xecf1, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">star_half</i> — material icon named "star half" (round). + static const IconData star_half_rounded = IconData(0xf01d0, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">star_half</i> — material icon named "star half" (outlined). + static const IconData star_half_outlined = IconData(0xf3de, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">star_outline</i> — material icon named "star outline". + static const IconData star_outline = IconData(0xe5fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">star_outline</i> — material icon named "star outline" (sharp). + static const IconData star_outline_sharp = IconData(0xecf2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">star_outline</i> — material icon named "star outline" (round). + static const IconData star_outline_rounded = IconData(0xf01d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">star_outline</i> — material icon named "star outline" (outlined). + static const IconData star_outline_outlined = IconData(0xf3df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">star_purple500</i> — material icon named "star purple500". + static const IconData star_purple500 = IconData(0xe5fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">star_purple500</i> — material icon named "star purple500" (sharp). + static const IconData star_purple500_sharp = IconData(0xecf3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">star_purple500</i> — material icon named "star purple500" (round). + static const IconData star_purple500_rounded = IconData(0xf01d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">star_purple500</i> — material icon named "star purple500" (outlined). + static const IconData star_purple500_outlined = IconData(0xf3e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">star_rate</i> — material icon named "star rate". + static const IconData star_rate = IconData(0xe5ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">star_rate</i> — material icon named "star rate" (sharp). + static const IconData star_rate_sharp = IconData(0xecf4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">star_rate</i> — material icon named "star rate" (round). + static const IconData star_rate_rounded = IconData(0xf01d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">star_rate</i> — material icon named "star rate" (outlined). + static const IconData star_rate_outlined = IconData(0xf3e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stars</i> — material icon named "stars". + static const IconData stars = IconData(0xe600, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stars</i> — material icon named "stars" (sharp). + static const IconData stars_sharp = IconData(0xecf6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stars</i> — material icon named "stars" (round). + static const IconData stars_rounded = IconData(0xf01d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stars</i> — material icon named "stars" (outlined). + static const IconData stars_outlined = IconData(0xf3e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">start</i> — material icon named "start". + static const IconData start = IconData(0xf0573, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">start</i> — material icon named "start" (sharp). + static const IconData start_sharp = IconData(0xf047b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">start</i> — material icon named "start" (round). + static const IconData start_rounded = IconData(0xf0388, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">start</i> — material icon named "start" (outlined). + static const IconData start_outlined = IconData(0xf0669, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stay_current_landscape</i> — material icon named "stay current landscape". + static const IconData stay_current_landscape = IconData(0xe601, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stay_current_landscape</i> — material icon named "stay current landscape" (sharp). + static const IconData stay_current_landscape_sharp = IconData(0xecf7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stay_current_landscape</i> — material icon named "stay current landscape" (round). + static const IconData stay_current_landscape_rounded = IconData(0xf01d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stay_current_landscape</i> — material icon named "stay current landscape" (outlined). + static const IconData stay_current_landscape_outlined = IconData(0xf3e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stay_current_portrait</i> — material icon named "stay current portrait". + static const IconData stay_current_portrait = IconData(0xe602, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stay_current_portrait</i> — material icon named "stay current portrait" (sharp). + static const IconData stay_current_portrait_sharp = IconData(0xecf8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stay_current_portrait</i> — material icon named "stay current portrait" (round). + static const IconData stay_current_portrait_rounded = IconData(0xf01d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stay_current_portrait</i> — material icon named "stay current portrait" (outlined). + static const IconData stay_current_portrait_outlined = IconData(0xf3e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stay_primary_landscape</i> — material icon named "stay primary landscape". + static const IconData stay_primary_landscape = IconData(0xe603, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stay_primary_landscape</i> — material icon named "stay primary landscape" (sharp). + static const IconData stay_primary_landscape_sharp = IconData(0xecf9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stay_primary_landscape</i> — material icon named "stay primary landscape" (round). + static const IconData stay_primary_landscape_rounded = IconData(0xf01d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stay_primary_landscape</i> — material icon named "stay primary landscape" (outlined). + static const IconData stay_primary_landscape_outlined = IconData(0xf3e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stay_primary_portrait</i> — material icon named "stay primary portrait". + static const IconData stay_primary_portrait = IconData(0xe604, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stay_primary_portrait</i> — material icon named "stay primary portrait" (sharp). + static const IconData stay_primary_portrait_sharp = IconData(0xecfa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stay_primary_portrait</i> — material icon named "stay primary portrait" (round). + static const IconData stay_primary_portrait_rounded = IconData(0xf01d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stay_primary_portrait</i> — material icon named "stay primary portrait" (outlined). + static const IconData stay_primary_portrait_outlined = IconData(0xf3e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sticky_note_2</i> — material icon named "sticky note 2". + static const IconData sticky_note_2 = IconData(0xe605, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sticky_note_2</i> — material icon named "sticky note 2" (sharp). + static const IconData sticky_note_2_sharp = IconData(0xecfb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sticky_note_2</i> — material icon named "sticky note 2" (round). + static const IconData sticky_note_2_rounded = IconData(0xf01da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sticky_note_2</i> — material icon named "sticky note 2" (outlined). + static const IconData sticky_note_2_outlined = IconData(0xf3e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stop</i> — material icon named "stop". + static const IconData stop = IconData(0xe606, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stop</i> — material icon named "stop" (sharp). + static const IconData stop_sharp = IconData(0xecfe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stop</i> — material icon named "stop" (round). + static const IconData stop_rounded = IconData(0xf01dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stop</i> — material icon named "stop" (outlined). + static const IconData stop_outlined = IconData(0xf3ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stop_circle</i> — material icon named "stop circle". + static const IconData stop_circle = IconData(0xe607, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stop_circle</i> — material icon named "stop circle" (sharp). + static const IconData stop_circle_sharp = IconData(0xecfc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stop_circle</i> — material icon named "stop circle" (round). + static const IconData stop_circle_rounded = IconData(0xf01db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stop_circle</i> — material icon named "stop circle" (outlined). + static const IconData stop_circle_outlined = IconData(0xf3e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stop_screen_share</i> — material icon named "stop screen share". + static const IconData stop_screen_share = IconData(0xe608, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stop_screen_share</i> — material icon named "stop screen share" (sharp). + static const IconData stop_screen_share_sharp = IconData(0xecfd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stop_screen_share</i> — material icon named "stop screen share" (round). + static const IconData stop_screen_share_rounded = IconData(0xf01dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stop_screen_share</i> — material icon named "stop screen share" (outlined). + static const IconData stop_screen_share_outlined = IconData(0xf3eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">storage</i> — material icon named "storage". + static const IconData storage = IconData(0xe609, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">storage</i> — material icon named "storage" (sharp). + static const IconData storage_sharp = IconData(0xecff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">storage</i> — material icon named "storage" (round). + static const IconData storage_rounded = IconData(0xf01de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">storage</i> — material icon named "storage" (outlined). + static const IconData storage_outlined = IconData(0xf3ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">store</i> — material icon named "store". + static const IconData store = IconData(0xe60a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">store</i> — material icon named "store" (sharp). + static const IconData store_sharp = IconData(0xed01, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">store</i> — material icon named "store" (round). + static const IconData store_rounded = IconData(0xf01e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">store</i> — material icon named "store" (outlined). + static const IconData store_outlined = IconData(0xf3ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">store_mall_directory</i> — material icon named "store mall directory". + static const IconData store_mall_directory = IconData(0xe60b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">store_mall_directory</i> — material icon named "store mall directory" (sharp). + static const IconData store_mall_directory_sharp = IconData(0xed00, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">store_mall_directory</i> — material icon named "store mall directory" (round). + static const IconData store_mall_directory_rounded = IconData(0xf01df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">store_mall_directory</i> — material icon named "store mall directory" (outlined). + static const IconData store_mall_directory_outlined = IconData(0xf3ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">storefront</i> — material icon named "storefront". + static const IconData storefront = IconData(0xe60c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">storefront</i> — material icon named "storefront" (sharp). + static const IconData storefront_sharp = IconData(0xed02, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">storefront</i> — material icon named "storefront" (round). + static const IconData storefront_rounded = IconData(0xf01e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">storefront</i> — material icon named "storefront" (outlined). + static const IconData storefront_outlined = IconData(0xf3ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">storm</i> — material icon named "storm". + static const IconData storm = IconData(0xe60d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">storm</i> — material icon named "storm" (sharp). + static const IconData storm_sharp = IconData(0xed03, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">storm</i> — material icon named "storm" (round). + static const IconData storm_rounded = IconData(0xf01e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">storm</i> — material icon named "storm" (outlined). + static const IconData storm_outlined = IconData(0xf3f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">straight</i> — material icon named "straight". + static const IconData straight = IconData(0xf0574, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">straight</i> — material icon named "straight" (sharp). + static const IconData straight_sharp = IconData(0xf047c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">straight</i> — material icon named "straight" (round). + static const IconData straight_rounded = IconData(0xf0389, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">straight</i> — material icon named "straight" (outlined). + static const IconData straight_outlined = IconData(0xf066a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">straighten</i> — material icon named "straighten". + static const IconData straighten = IconData(0xe60e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">straighten</i> — material icon named "straighten" (sharp). + static const IconData straighten_sharp = IconData(0xed04, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">straighten</i> — material icon named "straighten" (round). + static const IconData straighten_rounded = IconData(0xf01e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">straighten</i> — material icon named "straighten" (outlined). + static const IconData straighten_outlined = IconData(0xf3f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stream</i> — material icon named "stream". + static const IconData stream = IconData(0xe60f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stream</i> — material icon named "stream" (sharp). + static const IconData stream_sharp = IconData(0xed05, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stream</i> — material icon named "stream" (round). + static const IconData stream_rounded = IconData(0xf01e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stream</i> — material icon named "stream" (outlined). + static const IconData stream_outlined = IconData(0xf3f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">streetview</i> — material icon named "streetview". + static const IconData streetview = IconData(0xe610, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">streetview</i> — material icon named "streetview" (sharp). + static const IconData streetview_sharp = IconData(0xed06, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">streetview</i> — material icon named "streetview" (round). + static const IconData streetview_rounded = IconData(0xf01e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">streetview</i> — material icon named "streetview" (outlined). + static const IconData streetview_outlined = IconData(0xf3f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">strikethrough_s</i> — material icon named "strikethrough s". + static const IconData strikethrough_s = IconData(0xe611, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">strikethrough_s</i> — material icon named "strikethrough s" (sharp). + static const IconData strikethrough_s_sharp = IconData(0xed07, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">strikethrough_s</i> — material icon named "strikethrough s" (round). + static const IconData strikethrough_s_rounded = IconData(0xf01e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">strikethrough_s</i> — material icon named "strikethrough s" (outlined). + static const IconData strikethrough_s_outlined = IconData(0xf3f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">stroller</i> — material icon named "stroller". + static const IconData stroller = IconData(0xe612, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">stroller</i> — material icon named "stroller" (sharp). + static const IconData stroller_sharp = IconData(0xed08, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">stroller</i> — material icon named "stroller" (round). + static const IconData stroller_rounded = IconData(0xf01e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">stroller</i> — material icon named "stroller" (outlined). + static const IconData stroller_outlined = IconData(0xf3f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">style</i> — material icon named "style". + static const IconData style = IconData(0xe613, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">style</i> — material icon named "style" (sharp). + static const IconData style_sharp = IconData(0xed09, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">style</i> — material icon named "style" (round). + static const IconData style_rounded = IconData(0xf01e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">style</i> — material icon named "style" (outlined). + static const IconData style_outlined = IconData(0xf3f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">subdirectory_arrow_left</i> — material icon named "subdirectory arrow left". + static const IconData subdirectory_arrow_left = IconData(0xe614, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">subdirectory_arrow_left</i> — material icon named "subdirectory arrow left" (sharp). + static const IconData subdirectory_arrow_left_sharp = IconData(0xed0a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">subdirectory_arrow_left</i> — material icon named "subdirectory arrow left" (round). + static const IconData subdirectory_arrow_left_rounded = IconData(0xf01e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">subdirectory_arrow_left</i> — material icon named "subdirectory arrow left" (outlined). + static const IconData subdirectory_arrow_left_outlined = IconData(0xf3f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">subdirectory_arrow_right</i> — material icon named "subdirectory arrow right". + static const IconData subdirectory_arrow_right = IconData(0xe615, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">subdirectory_arrow_right</i> — material icon named "subdirectory arrow right" (sharp). + static const IconData subdirectory_arrow_right_sharp = IconData(0xed0b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">subdirectory_arrow_right</i> — material icon named "subdirectory arrow right" (round). + static const IconData subdirectory_arrow_right_rounded = IconData(0xf01ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">subdirectory_arrow_right</i> — material icon named "subdirectory arrow right" (outlined). + static const IconData subdirectory_arrow_right_outlined = IconData(0xf3f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">subject</i> — material icon named "subject". + static const IconData subject = IconData(0xe616, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">subject</i> — material icon named "subject" (sharp). + static const IconData subject_sharp = IconData(0xed0c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">subject</i> — material icon named "subject" (round). + static const IconData subject_rounded = IconData(0xf01eb, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">subject</i> — material icon named "subject" (outlined). + static const IconData subject_outlined = IconData(0xf3f9, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">subscript</i> — material icon named "subscript". + static const IconData subscript = IconData(0xe617, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">subscript</i> — material icon named "subscript" (sharp). + static const IconData subscript_sharp = IconData(0xed0d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">subscript</i> — material icon named "subscript" (round). + static const IconData subscript_rounded = IconData(0xf01ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">subscript</i> — material icon named "subscript" (outlined). + static const IconData subscript_outlined = IconData(0xf3fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">subscriptions</i> — material icon named "subscriptions". + static const IconData subscriptions = IconData(0xe618, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">subscriptions</i> — material icon named "subscriptions" (sharp). + static const IconData subscriptions_sharp = IconData(0xed0e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">subscriptions</i> — material icon named "subscriptions" (round). + static const IconData subscriptions_rounded = IconData(0xf01ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">subscriptions</i> — material icon named "subscriptions" (outlined). + static const IconData subscriptions_outlined = IconData(0xf3fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">subtitles</i> — material icon named "subtitles". + static const IconData subtitles = IconData(0xe619, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">subtitles</i> — material icon named "subtitles" (sharp). + static const IconData subtitles_sharp = IconData(0xed10, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">subtitles</i> — material icon named "subtitles" (round). + static const IconData subtitles_rounded = IconData(0xf01ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">subtitles</i> — material icon named "subtitles" (outlined). + static const IconData subtitles_outlined = IconData(0xf3fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">subtitles_off</i> — material icon named "subtitles off". + static const IconData subtitles_off = IconData(0xe61a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">subtitles_off</i> — material icon named "subtitles off" (sharp). + static const IconData subtitles_off_sharp = IconData(0xed0f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">subtitles_off</i> — material icon named "subtitles off" (round). + static const IconData subtitles_off_rounded = IconData(0xf01ee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">subtitles_off</i> — material icon named "subtitles off" (outlined). + static const IconData subtitles_off_outlined = IconData(0xf3fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">subway</i> — material icon named "subway". + static const IconData subway = IconData(0xe61b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">subway</i> — material icon named "subway" (sharp). + static const IconData subway_sharp = IconData(0xed11, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">subway</i> — material icon named "subway" (round). + static const IconData subway_rounded = IconData(0xf01f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">subway</i> — material icon named "subway" (outlined). + static const IconData subway_outlined = IconData(0xf3fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">summarize</i> — material icon named "summarize". + static const IconData summarize = IconData(0xe61c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">summarize</i> — material icon named "summarize" (sharp). + static const IconData summarize_sharp = IconData(0xed12, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">summarize</i> — material icon named "summarize" (round). + static const IconData summarize_rounded = IconData(0xf01f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">summarize</i> — material icon named "summarize" (outlined). + static const IconData summarize_outlined = IconData(0xf3ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sunny</i> — material icon named "sunny". + static const IconData sunny = IconData(0xf0575, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sunny_snowing</i> — material icon named "sunny snowing". + static const IconData sunny_snowing = IconData(0xf0576, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">superscript</i> — material icon named "superscript". + static const IconData superscript = IconData(0xe61d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">superscript</i> — material icon named "superscript" (sharp). + static const IconData superscript_sharp = IconData(0xed13, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">superscript</i> — material icon named "superscript" (round). + static const IconData superscript_rounded = IconData(0xf01f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">superscript</i> — material icon named "superscript" (outlined). + static const IconData superscript_outlined = IconData(0xf400, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">supervised_user_circle</i> — material icon named "supervised user circle". + static const IconData supervised_user_circle = IconData(0xe61e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">supervised_user_circle</i> — material icon named "supervised user circle" (sharp). + static const IconData supervised_user_circle_sharp = IconData(0xed14, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">supervised_user_circle</i> — material icon named "supervised user circle" (round). + static const IconData supervised_user_circle_rounded = IconData(0xf01f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">supervised_user_circle</i> — material icon named "supervised user circle" (outlined). + static const IconData supervised_user_circle_outlined = IconData(0xf401, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">supervisor_account</i> — material icon named "supervisor account". + static const IconData supervisor_account = IconData(0xe61f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">supervisor_account</i> — material icon named "supervisor account" (sharp). + static const IconData supervisor_account_sharp = IconData(0xed15, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">supervisor_account</i> — material icon named "supervisor account" (round). + static const IconData supervisor_account_rounded = IconData(0xf01f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">supervisor_account</i> — material icon named "supervisor account" (outlined). + static const IconData supervisor_account_outlined = IconData(0xf402, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">support</i> — material icon named "support". + static const IconData support = IconData(0xe620, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">support</i> — material icon named "support" (sharp). + static const IconData support_sharp = IconData(0xed17, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">support</i> — material icon named "support" (round). + static const IconData support_rounded = IconData(0xf01f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">support</i> — material icon named "support" (outlined). + static const IconData support_outlined = IconData(0xf404, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">support_agent</i> — material icon named "support agent". + static const IconData support_agent = IconData(0xe621, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">support_agent</i> — material icon named "support agent" (sharp). + static const IconData support_agent_sharp = IconData(0xed16, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">support_agent</i> — material icon named "support agent" (round). + static const IconData support_agent_rounded = IconData(0xf01f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">support_agent</i> — material icon named "support agent" (outlined). + static const IconData support_agent_outlined = IconData(0xf403, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">surfing</i> — material icon named "surfing". + static const IconData surfing = IconData(0xe622, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">surfing</i> — material icon named "surfing" (sharp). + static const IconData surfing_sharp = IconData(0xed18, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">surfing</i> — material icon named "surfing" (round). + static const IconData surfing_rounded = IconData(0xf01f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">surfing</i> — material icon named "surfing" (outlined). + static const IconData surfing_outlined = IconData(0xf405, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">surround_sound</i> — material icon named "surround sound". + static const IconData surround_sound = IconData(0xe623, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">surround_sound</i> — material icon named "surround sound" (sharp). + static const IconData surround_sound_sharp = IconData(0xed19, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">surround_sound</i> — material icon named "surround sound" (round). + static const IconData surround_sound_rounded = IconData(0xf01f8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">surround_sound</i> — material icon named "surround sound" (outlined). + static const IconData surround_sound_outlined = IconData(0xf406, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swap_calls</i> — material icon named "swap calls". + static const IconData swap_calls = IconData(0xe624, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swap_calls</i> — material icon named "swap calls" (sharp). + static const IconData swap_calls_sharp = IconData(0xed1a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swap_calls</i> — material icon named "swap calls" (round). + static const IconData swap_calls_rounded = IconData(0xf01f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swap_calls</i> — material icon named "swap calls" (outlined). + static const IconData swap_calls_outlined = IconData(0xf407, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swap_horiz</i> — material icon named "swap horiz". + static const IconData swap_horiz = IconData(0xe625, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swap_horiz</i> — material icon named "swap horiz" (sharp). + static const IconData swap_horiz_sharp = IconData(0xed1b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swap_horiz</i> — material icon named "swap horiz" (round). + static const IconData swap_horiz_rounded = IconData(0xf01fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swap_horiz</i> — material icon named "swap horiz" (outlined). + static const IconData swap_horiz_outlined = IconData(0xf408, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swap_horizontal_circle</i> — material icon named "swap horizontal circle". + static const IconData swap_horizontal_circle = IconData(0xe626, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swap_horizontal_circle</i> — material icon named "swap horizontal circle" (sharp). + static const IconData swap_horizontal_circle_sharp = IconData(0xed1c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swap_horizontal_circle</i> — material icon named "swap horizontal circle" (round). + static const IconData swap_horizontal_circle_rounded = IconData(0xf01fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swap_horizontal_circle</i> — material icon named "swap horizontal circle" (outlined). + static const IconData swap_horizontal_circle_outlined = IconData(0xf409, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swap_vert</i> — material icon named "swap vert". + static const IconData swap_vert = IconData(0xe627, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swap_vert</i> — material icon named "swap vert" (sharp). + static const IconData swap_vert_sharp = IconData(0xed1d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swap_vert</i> — material icon named "swap vert" (round). + static const IconData swap_vert_rounded = IconData(0xf01fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swap_vert</i> — material icon named "swap vert" (outlined). + static const IconData swap_vert_outlined = IconData(0xf40a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swap_vert_circle</i> — material icon named "swap vert circle". + static const IconData swap_vert_circle = IconData(0xe628, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swap_vert_circle</i> — material icon named "swap vert circle" (sharp). + static const IconData swap_vert_circle_sharp = IconData(0xed1e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swap_vert_circle</i> — material icon named "swap vert circle" (round). + static const IconData swap_vert_circle_rounded = IconData(0xf01fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swap_vert_circle</i> — material icon named "swap vert circle" (outlined). + static const IconData swap_vert_circle_outlined = IconData(0xf40b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swap_vertical_circle</i> — material icon named "swap vertical circle". + static const IconData swap_vertical_circle = IconData(0xe628, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swap_vertical_circle</i> — material icon named "swap vertical circle" (sharp). + static const IconData swap_vertical_circle_sharp = IconData(0xed1e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swap_vertical_circle</i> — material icon named "swap vertical circle" (round). + static const IconData swap_vertical_circle_rounded = IconData(0xf01fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swap_vertical_circle</i> — material icon named "swap vertical circle" (outlined). + static const IconData swap_vertical_circle_outlined = IconData(0xf40b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swipe</i> — material icon named "swipe". + static const IconData swipe = IconData(0xe629, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swipe</i> — material icon named "swipe" (sharp). + static const IconData swipe_sharp = IconData(0xed1f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swipe</i> — material icon named "swipe" (round). + static const IconData swipe_rounded = IconData(0xf01fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swipe</i> — material icon named "swipe" (outlined). + static const IconData swipe_outlined = IconData(0xf40c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swipe_down</i> — material icon named "swipe down". + static const IconData swipe_down = IconData(0xf0578, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swipe_down</i> — material icon named "swipe down" (sharp). + static const IconData swipe_down_sharp = IconData(0xf047e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swipe_down</i> — material icon named "swipe down" (round). + static const IconData swipe_down_rounded = IconData(0xf038b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swipe_down</i> — material icon named "swipe down" (outlined). + static const IconData swipe_down_outlined = IconData(0xf066c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swipe_down_alt</i> — material icon named "swipe down alt". + static const IconData swipe_down_alt = IconData(0xf0577, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swipe_down_alt</i> — material icon named "swipe down alt" (sharp). + static const IconData swipe_down_alt_sharp = IconData(0xf047d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swipe_down_alt</i> — material icon named "swipe down alt" (round). + static const IconData swipe_down_alt_rounded = IconData(0xf038a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swipe_down_alt</i> — material icon named "swipe down alt" (outlined). + static const IconData swipe_down_alt_outlined = IconData(0xf066b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swipe_left</i> — material icon named "swipe left". + static const IconData swipe_left = IconData(0xf057a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swipe_left</i> — material icon named "swipe left" (sharp). + static const IconData swipe_left_sharp = IconData(0xf0480, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swipe_left</i> — material icon named "swipe left" (round). + static const IconData swipe_left_rounded = IconData(0xf038d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swipe_left</i> — material icon named "swipe left" (outlined). + static const IconData swipe_left_outlined = IconData(0xf066e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swipe_left_alt</i> — material icon named "swipe left alt". + static const IconData swipe_left_alt = IconData(0xf0579, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swipe_left_alt</i> — material icon named "swipe left alt" (sharp). + static const IconData swipe_left_alt_sharp = IconData(0xf047f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swipe_left_alt</i> — material icon named "swipe left alt" (round). + static const IconData swipe_left_alt_rounded = IconData(0xf038c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swipe_left_alt</i> — material icon named "swipe left alt" (outlined). + static const IconData swipe_left_alt_outlined = IconData(0xf066d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swipe_right</i> — material icon named "swipe right". + static const IconData swipe_right = IconData(0xf057c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swipe_right</i> — material icon named "swipe right" (sharp). + static const IconData swipe_right_sharp = IconData(0xf0482, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swipe_right</i> — material icon named "swipe right" (round). + static const IconData swipe_right_rounded = IconData(0xf038f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swipe_right</i> — material icon named "swipe right" (outlined). + static const IconData swipe_right_outlined = IconData(0xf0670, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swipe_right_alt</i> — material icon named "swipe right alt". + static const IconData swipe_right_alt = IconData(0xf057b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swipe_right_alt</i> — material icon named "swipe right alt" (sharp). + static const IconData swipe_right_alt_sharp = IconData(0xf0481, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swipe_right_alt</i> — material icon named "swipe right alt" (round). + static const IconData swipe_right_alt_rounded = IconData(0xf038e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swipe_right_alt</i> — material icon named "swipe right alt" (outlined). + static const IconData swipe_right_alt_outlined = IconData(0xf066f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swipe_up</i> — material icon named "swipe up". + static const IconData swipe_up = IconData(0xf057e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swipe_up</i> — material icon named "swipe up" (sharp). + static const IconData swipe_up_sharp = IconData(0xf0484, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swipe_up</i> — material icon named "swipe up" (round). + static const IconData swipe_up_rounded = IconData(0xf0391, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swipe_up</i> — material icon named "swipe up" (outlined). + static const IconData swipe_up_outlined = IconData(0xf0672, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swipe_up_alt</i> — material icon named "swipe up alt". + static const IconData swipe_up_alt = IconData(0xf057d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swipe_up_alt</i> — material icon named "swipe up alt" (sharp). + static const IconData swipe_up_alt_sharp = IconData(0xf0483, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swipe_up_alt</i> — material icon named "swipe up alt" (round). + static const IconData swipe_up_alt_rounded = IconData(0xf0390, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swipe_up_alt</i> — material icon named "swipe up alt" (outlined). + static const IconData swipe_up_alt_outlined = IconData(0xf0671, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">swipe_vertical</i> — material icon named "swipe vertical". + static const IconData swipe_vertical = IconData(0xf057f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">swipe_vertical</i> — material icon named "swipe vertical" (sharp). + static const IconData swipe_vertical_sharp = IconData(0xf0485, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">swipe_vertical</i> — material icon named "swipe vertical" (round). + static const IconData swipe_vertical_rounded = IconData(0xf0392, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">swipe_vertical</i> — material icon named "swipe vertical" (outlined). + static const IconData swipe_vertical_outlined = IconData(0xf0673, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">switch_access_shortcut</i> — material icon named "switch access shortcut". + static const IconData switch_access_shortcut = IconData(0xf0581, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">switch_access_shortcut</i> — material icon named "switch access shortcut" (sharp). + static const IconData switch_access_shortcut_sharp = IconData(0xf0487, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">switch_access_shortcut</i> — material icon named "switch access shortcut" (round). + static const IconData switch_access_shortcut_rounded = IconData(0xf0394, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">switch_access_shortcut</i> — material icon named "switch access shortcut" (outlined). + static const IconData switch_access_shortcut_outlined = IconData(0xf0675, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">switch_access_shortcut_add</i> — material icon named "switch access shortcut add". + static const IconData switch_access_shortcut_add = IconData(0xf0580, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">switch_access_shortcut_add</i> — material icon named "switch access shortcut add" (sharp). + static const IconData switch_access_shortcut_add_sharp = IconData(0xf0486, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">switch_access_shortcut_add</i> — material icon named "switch access shortcut add" (round). + static const IconData switch_access_shortcut_add_rounded = IconData(0xf0393, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">switch_access_shortcut_add</i> — material icon named "switch access shortcut add" (outlined). + static const IconData switch_access_shortcut_add_outlined = IconData(0xf0674, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">switch_account</i> — material icon named "switch account". + static const IconData switch_account = IconData(0xe62a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">switch_account</i> — material icon named "switch account" (sharp). + static const IconData switch_account_sharp = IconData(0xed20, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">switch_account</i> — material icon named "switch account" (round). + static const IconData switch_account_rounded = IconData(0xf01ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">switch_account</i> — material icon named "switch account" (outlined). + static const IconData switch_account_outlined = IconData(0xf40d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">switch_camera</i> — material icon named "switch camera". + static const IconData switch_camera = IconData(0xe62b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">switch_camera</i> — material icon named "switch camera" (sharp). + static const IconData switch_camera_sharp = IconData(0xed21, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">switch_camera</i> — material icon named "switch camera" (round). + static const IconData switch_camera_rounded = IconData(0xf0200, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">switch_camera</i> — material icon named "switch camera" (outlined). + static const IconData switch_camera_outlined = IconData(0xf40e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">switch_left</i> — material icon named "switch left". + static const IconData switch_left = IconData(0xe62c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">switch_left</i> — material icon named "switch left" (sharp). + static const IconData switch_left_sharp = IconData(0xed22, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">switch_left</i> — material icon named "switch left" (round). + static const IconData switch_left_rounded = IconData(0xf0201, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">switch_left</i> — material icon named "switch left" (outlined). + static const IconData switch_left_outlined = IconData(0xf40f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">switch_right</i> — material icon named "switch right". + static const IconData switch_right = IconData(0xe62d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">switch_right</i> — material icon named "switch right" (sharp). + static const IconData switch_right_sharp = IconData(0xed23, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">switch_right</i> — material icon named "switch right" (round). + static const IconData switch_right_rounded = IconData(0xf0202, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">switch_right</i> — material icon named "switch right" (outlined). + static const IconData switch_right_outlined = IconData(0xf410, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">switch_video</i> — material icon named "switch video". + static const IconData switch_video = IconData(0xe62e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">switch_video</i> — material icon named "switch video" (sharp). + static const IconData switch_video_sharp = IconData(0xed24, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">switch_video</i> — material icon named "switch video" (round). + static const IconData switch_video_rounded = IconData(0xf0203, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">switch_video</i> — material icon named "switch video" (outlined). + static const IconData switch_video_outlined = IconData(0xf411, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">synagogue</i> — material icon named "synagogue". + static const IconData synagogue = IconData(0xf0582, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">synagogue</i> — material icon named "synagogue" (sharp). + static const IconData synagogue_sharp = IconData(0xf0488, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">synagogue</i> — material icon named "synagogue" (round). + static const IconData synagogue_rounded = IconData(0xf0395, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">synagogue</i> — material icon named "synagogue" (outlined). + static const IconData synagogue_outlined = IconData(0xf0676, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sync</i> — material icon named "sync". + static const IconData sync = IconData(0xe62f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sync</i> — material icon named "sync" (sharp). + static const IconData sync_sharp = IconData(0xed28, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sync</i> — material icon named "sync" (round). + static const IconData sync_rounded = IconData(0xf0207, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sync</i> — material icon named "sync" (outlined). + static const IconData sync_outlined = IconData(0xf414, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sync_alt</i> — material icon named "sync alt". + static const IconData sync_alt = IconData(0xe630, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sync_alt</i> — material icon named "sync alt" (sharp). + static const IconData sync_alt_sharp = IconData(0xed25, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sync_alt</i> — material icon named "sync alt" (round). + static const IconData sync_alt_rounded = IconData(0xf0204, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sync_alt</i> — material icon named "sync alt" (outlined). + static const IconData sync_alt_outlined = IconData(0xf412, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sync_disabled</i> — material icon named "sync disabled". + static const IconData sync_disabled = IconData(0xe631, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sync_disabled</i> — material icon named "sync disabled" (sharp). + static const IconData sync_disabled_sharp = IconData(0xed26, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sync_disabled</i> — material icon named "sync disabled" (round). + static const IconData sync_disabled_rounded = IconData(0xf0205, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sync_disabled</i> — material icon named "sync disabled" (outlined). + static const IconData sync_disabled_outlined = IconData(0xf413, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sync_lock</i> — material icon named "sync lock". + static const IconData sync_lock = IconData(0xf0583, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sync_lock</i> — material icon named "sync lock" (sharp). + static const IconData sync_lock_sharp = IconData(0xf0489, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sync_lock</i> — material icon named "sync lock" (round). + static const IconData sync_lock_rounded = IconData(0xf0396, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sync_lock</i> — material icon named "sync lock" (outlined). + static const IconData sync_lock_outlined = IconData(0xf0677, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">sync_problem</i> — material icon named "sync problem". + static const IconData sync_problem = IconData(0xe632, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">sync_problem</i> — material icon named "sync problem" (sharp). + static const IconData sync_problem_sharp = IconData(0xed27, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">sync_problem</i> — material icon named "sync problem" (round). + static const IconData sync_problem_rounded = IconData(0xf0206, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">sync_problem</i> — material icon named "sync problem" (outlined). + static const IconData sync_problem_outlined = IconData(0xf415, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">system_security_update</i> — material icon named "system security update". + static const IconData system_security_update = IconData(0xe633, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">system_security_update</i> — material icon named "system security update" (sharp). + static const IconData system_security_update_sharp = IconData(0xed2a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">system_security_update</i> — material icon named "system security update" (round). + static const IconData system_security_update_rounded = IconData(0xf0209, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">system_security_update</i> — material icon named "system security update" (outlined). + static const IconData system_security_update_outlined = IconData(0xf417, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">system_security_update_good</i> — material icon named "system security update good". + static const IconData system_security_update_good = IconData(0xe634, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">system_security_update_good</i> — material icon named "system security update good" (sharp). + static const IconData system_security_update_good_sharp = IconData(0xed29, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">system_security_update_good</i> — material icon named "system security update good" (round). + static const IconData system_security_update_good_rounded = IconData(0xf0208, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">system_security_update_good</i> — material icon named "system security update good" (outlined). + static const IconData system_security_update_good_outlined = IconData(0xf416, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">system_security_update_warning</i> — material icon named "system security update warning". + static const IconData system_security_update_warning = IconData(0xe635, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">system_security_update_warning</i> — material icon named "system security update warning" (sharp). + static const IconData system_security_update_warning_sharp = IconData(0xed2b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">system_security_update_warning</i> — material icon named "system security update warning" (round). + static const IconData system_security_update_warning_rounded = IconData(0xf020a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">system_security_update_warning</i> — material icon named "system security update warning" (outlined). + static const IconData system_security_update_warning_outlined = IconData(0xf418, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">system_update</i> — material icon named "system update". + static const IconData system_update = IconData(0xe636, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">system_update</i> — material icon named "system update" (sharp). + static const IconData system_update_sharp = IconData(0xed2d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">system_update</i> — material icon named "system update" (round). + static const IconData system_update_rounded = IconData(0xf020c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">system_update</i> — material icon named "system update" (outlined). + static const IconData system_update_outlined = IconData(0xf41a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">system_update_alt</i> — material icon named "system update alt". + static const IconData system_update_alt = IconData(0xe637, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">system_update_alt</i> — material icon named "system update alt" (sharp). + static const IconData system_update_alt_sharp = IconData(0xed2c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">system_update_alt</i> — material icon named "system update alt" (round). + static const IconData system_update_alt_rounded = IconData(0xf020b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">system_update_alt</i> — material icon named "system update alt" (outlined). + static const IconData system_update_alt_outlined = IconData(0xf419, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">system_update_tv</i> — material icon named "system update tv". + static const IconData system_update_tv = IconData(0xe637, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">system_update_tv</i> — material icon named "system update tv" (sharp). + static const IconData system_update_tv_sharp = IconData(0xed2c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">system_update_tv</i> — material icon named "system update tv" (round). + static const IconData system_update_tv_rounded = IconData(0xf020b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">system_update_tv</i> — material icon named "system update tv" (outlined). + static const IconData system_update_tv_outlined = IconData(0xf419, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tab</i> — material icon named "tab". + static const IconData tab = IconData(0xe638, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tab</i> — material icon named "tab" (sharp). + static const IconData tab_sharp = IconData(0xed2e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tab</i> — material icon named "tab" (round). + static const IconData tab_rounded = IconData(0xf020d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tab</i> — material icon named "tab" (outlined). + static const IconData tab_outlined = IconData(0xf41b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tab_unselected</i> — material icon named "tab unselected". + static const IconData tab_unselected = IconData(0xe639, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tab_unselected</i> — material icon named "tab unselected" (sharp). + static const IconData tab_unselected_sharp = IconData(0xed2f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tab_unselected</i> — material icon named "tab unselected" (round). + static const IconData tab_unselected_rounded = IconData(0xf020e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tab_unselected</i> — material icon named "tab unselected" (outlined). + static const IconData tab_unselected_outlined = IconData(0xf41c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">table_bar</i> — material icon named "table bar". + static const IconData table_bar = IconData(0xf0584, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">table_bar</i> — material icon named "table bar" (sharp). + static const IconData table_bar_sharp = IconData(0xf048a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">table_bar</i> — material icon named "table bar" (round). + static const IconData table_bar_rounded = IconData(0xf0397, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">table_bar</i> — material icon named "table bar" (outlined). + static const IconData table_bar_outlined = IconData(0xf0678, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">table_chart</i> — material icon named "table chart". + static const IconData table_chart = IconData(0xe63a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">table_chart</i> — material icon named "table chart" (sharp). + static const IconData table_chart_sharp = IconData(0xed30, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">table_chart</i> — material icon named "table chart" (round). + static const IconData table_chart_rounded = IconData(0xf020f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">table_chart</i> — material icon named "table chart" (outlined). + static const IconData table_chart_outlined = IconData(0xf41d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">table_restaurant</i> — material icon named "table restaurant". + static const IconData table_restaurant = IconData(0xf0585, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">table_restaurant</i> — material icon named "table restaurant" (sharp). + static const IconData table_restaurant_sharp = IconData(0xf048b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">table_restaurant</i> — material icon named "table restaurant" (round). + static const IconData table_restaurant_rounded = IconData(0xf0398, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">table_restaurant</i> — material icon named "table restaurant" (outlined). + static const IconData table_restaurant_outlined = IconData(0xf0679, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">table_rows</i> — material icon named "table rows". + static const IconData table_rows = IconData(0xe63b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">table_rows</i> — material icon named "table rows" (sharp). + static const IconData table_rows_sharp = IconData(0xed31, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">table_rows</i> — material icon named "table rows" (round). + static const IconData table_rows_rounded = IconData(0xf0210, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">table_rows</i> — material icon named "table rows" (outlined). + static const IconData table_rows_outlined = IconData(0xf41e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">table_view</i> — material icon named "table view". + static const IconData table_view = IconData(0xe63c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">table_view</i> — material icon named "table view" (sharp). + static const IconData table_view_sharp = IconData(0xed32, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">table_view</i> — material icon named "table view" (round). + static const IconData table_view_rounded = IconData(0xf0211, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">table_view</i> — material icon named "table view" (outlined). + static const IconData table_view_outlined = IconData(0xf41f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tablet</i> — material icon named "tablet". + static const IconData tablet = IconData(0xe63d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tablet</i> — material icon named "tablet" (sharp). + static const IconData tablet_sharp = IconData(0xed35, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tablet</i> — material icon named "tablet" (round). + static const IconData tablet_rounded = IconData(0xf0214, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tablet</i> — material icon named "tablet" (outlined). + static const IconData tablet_outlined = IconData(0xf422, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tablet_android</i> — material icon named "tablet android". + static const IconData tablet_android = IconData(0xe63e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tablet_android</i> — material icon named "tablet android" (sharp). + static const IconData tablet_android_sharp = IconData(0xed33, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tablet_android</i> — material icon named "tablet android" (round). + static const IconData tablet_android_rounded = IconData(0xf0212, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tablet_android</i> — material icon named "tablet android" (outlined). + static const IconData tablet_android_outlined = IconData(0xf420, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tablet_mac</i> — material icon named "tablet mac". + static const IconData tablet_mac = IconData(0xe63f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tablet_mac</i> — material icon named "tablet mac" (sharp). + static const IconData tablet_mac_sharp = IconData(0xed34, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tablet_mac</i> — material icon named "tablet mac" (round). + static const IconData tablet_mac_rounded = IconData(0xf0213, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tablet_mac</i> — material icon named "tablet mac" (outlined). + static const IconData tablet_mac_outlined = IconData(0xf421, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tag</i> — material icon named "tag". + static const IconData tag = IconData(0xe640, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tag</i> — material icon named "tag" (sharp). + static const IconData tag_sharp = IconData(0xed37, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tag</i> — material icon named "tag" (round). + static const IconData tag_rounded = IconData(0xf0216, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tag</i> — material icon named "tag" (outlined). + static const IconData tag_outlined = IconData(0xf424, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tag_faces</i> — material icon named "tag faces". + static const IconData tag_faces = IconData(0xe641, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tag_faces</i> — material icon named "tag faces" (sharp). + static const IconData tag_faces_sharp = IconData(0xed36, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tag_faces</i> — material icon named "tag faces" (round). + static const IconData tag_faces_rounded = IconData(0xf0215, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tag_faces</i> — material icon named "tag faces" (outlined). + static const IconData tag_faces_outlined = IconData(0xf423, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">takeout_dining</i> — material icon named "takeout dining". + static const IconData takeout_dining = IconData(0xe642, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">takeout_dining</i> — material icon named "takeout dining" (sharp). + static const IconData takeout_dining_sharp = IconData(0xed38, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">takeout_dining</i> — material icon named "takeout dining" (round). + static const IconData takeout_dining_rounded = IconData(0xf0217, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">takeout_dining</i> — material icon named "takeout dining" (outlined). + static const IconData takeout_dining_outlined = IconData(0xf425, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tap_and_play</i> — material icon named "tap and play". + static const IconData tap_and_play = IconData(0xe643, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tap_and_play</i> — material icon named "tap and play" (sharp). + static const IconData tap_and_play_sharp = IconData(0xed39, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tap_and_play</i> — material icon named "tap and play" (round). + static const IconData tap_and_play_rounded = IconData(0xf0218, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tap_and_play</i> — material icon named "tap and play" (outlined). + static const IconData tap_and_play_outlined = IconData(0xf426, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tapas</i> — material icon named "tapas". + static const IconData tapas = IconData(0xe644, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tapas</i> — material icon named "tapas" (sharp). + static const IconData tapas_sharp = IconData(0xed3a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tapas</i> — material icon named "tapas" (round). + static const IconData tapas_rounded = IconData(0xf0219, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tapas</i> — material icon named "tapas" (outlined). + static const IconData tapas_outlined = IconData(0xf427, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">task</i> — material icon named "task". + static const IconData task = IconData(0xe645, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">task</i> — material icon named "task" (sharp). + static const IconData task_sharp = IconData(0xed3c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">task</i> — material icon named "task" (round). + static const IconData task_rounded = IconData(0xf021b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">task</i> — material icon named "task" (outlined). + static const IconData task_outlined = IconData(0xf429, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">task_alt</i> — material icon named "task alt". + static const IconData task_alt = IconData(0xe646, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">task_alt</i> — material icon named "task alt" (sharp). + static const IconData task_alt_sharp = IconData(0xed3b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">task_alt</i> — material icon named "task alt" (round). + static const IconData task_alt_rounded = IconData(0xf021a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">task_alt</i> — material icon named "task alt" (outlined). + static const IconData task_alt_outlined = IconData(0xf428, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">taxi_alert</i> — material icon named "taxi alert". + static const IconData taxi_alert = IconData(0xe647, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">taxi_alert</i> — material icon named "taxi alert" (sharp). + static const IconData taxi_alert_sharp = IconData(0xed3d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">taxi_alert</i> — material icon named "taxi alert" (round). + static const IconData taxi_alert_rounded = IconData(0xf021c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">taxi_alert</i> — material icon named "taxi alert" (outlined). + static const IconData taxi_alert_outlined = IconData(0xf42a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">telegram</i> — material icon named "telegram". + static const IconData telegram = IconData(0xf0586, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">telegram</i> — material icon named "telegram" (sharp). + static const IconData telegram_sharp = IconData(0xf048c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">telegram</i> — material icon named "telegram" (round). + static const IconData telegram_rounded = IconData(0xf0399, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">telegram</i> — material icon named "telegram" (outlined). + static const IconData telegram_outlined = IconData(0xf067a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">temple_buddhist</i> — material icon named "temple buddhist". + static const IconData temple_buddhist = IconData(0xf0587, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">temple_buddhist</i> — material icon named "temple buddhist" (sharp). + static const IconData temple_buddhist_sharp = IconData(0xf048d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">temple_buddhist</i> — material icon named "temple buddhist" (round). + static const IconData temple_buddhist_rounded = IconData(0xf039a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">temple_buddhist</i> — material icon named "temple buddhist" (outlined). + static const IconData temple_buddhist_outlined = IconData(0xf067b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">temple_hindu</i> — material icon named "temple hindu". + static const IconData temple_hindu = IconData(0xf0588, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">temple_hindu</i> — material icon named "temple hindu" (sharp). + static const IconData temple_hindu_sharp = IconData(0xf048e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">temple_hindu</i> — material icon named "temple hindu" (round). + static const IconData temple_hindu_rounded = IconData(0xf039b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">temple_hindu</i> — material icon named "temple hindu" (outlined). + static const IconData temple_hindu_outlined = IconData(0xf067c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">terminal</i> — material icon named "terminal". + static const IconData terminal = IconData(0xf0589, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">terminal</i> — material icon named "terminal" (sharp). + static const IconData terminal_sharp = IconData(0xf048f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">terminal</i> — material icon named "terminal" (round). + static const IconData terminal_rounded = IconData(0xf039c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">terminal</i> — material icon named "terminal" (outlined). + static const IconData terminal_outlined = IconData(0xf067d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">terrain</i> — material icon named "terrain". + static const IconData terrain = IconData(0xe648, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">terrain</i> — material icon named "terrain" (sharp). + static const IconData terrain_sharp = IconData(0xed3e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">terrain</i> — material icon named "terrain" (round). + static const IconData terrain_rounded = IconData(0xf021d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">terrain</i> — material icon named "terrain" (outlined). + static const IconData terrain_outlined = IconData(0xf42b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_decrease</i> — material icon named "text decrease". + static const IconData text_decrease = IconData(0xf058a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_decrease</i> — material icon named "text decrease" (sharp). + static const IconData text_decrease_sharp = IconData(0xf0490, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_decrease</i> — material icon named "text decrease" (round). + static const IconData text_decrease_rounded = IconData(0xf039d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_decrease</i> — material icon named "text decrease" (outlined). + static const IconData text_decrease_outlined = IconData(0xf067e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_fields</i> — material icon named "text fields". + static const IconData text_fields = IconData(0xe649, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_fields</i> — material icon named "text fields" (sharp). + static const IconData text_fields_sharp = IconData(0xed3f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_fields</i> — material icon named "text fields" (round). + static const IconData text_fields_rounded = IconData(0xf021e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_fields</i> — material icon named "text fields" (outlined). + static const IconData text_fields_outlined = IconData(0xf42c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_format</i> — material icon named "text format". + static const IconData text_format = IconData(0xe64a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_format</i> — material icon named "text format" (sharp). + static const IconData text_format_sharp = IconData(0xed40, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_format</i> — material icon named "text format" (round). + static const IconData text_format_rounded = IconData(0xf021f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_format</i> — material icon named "text format" (outlined). + static const IconData text_format_outlined = IconData(0xf42d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_increase</i> — material icon named "text increase". + static const IconData text_increase = IconData(0xf058b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_increase</i> — material icon named "text increase" (sharp). + static const IconData text_increase_sharp = IconData(0xf0491, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_increase</i> — material icon named "text increase" (round). + static const IconData text_increase_rounded = IconData(0xf039e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_increase</i> — material icon named "text increase" (outlined). + static const IconData text_increase_outlined = IconData(0xf067f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_rotate_up</i> — material icon named "text rotate up". + static const IconData text_rotate_up = IconData(0xe64b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_rotate_up</i> — material icon named "text rotate up" (sharp). + static const IconData text_rotate_up_sharp = IconData(0xed41, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_rotate_up</i> — material icon named "text rotate up" (round). + static const IconData text_rotate_up_rounded = IconData(0xf0220, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_rotate_up</i> — material icon named "text rotate up" (outlined). + static const IconData text_rotate_up_outlined = IconData(0xf42e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_rotate_vertical</i> — material icon named "text rotate vertical". + static const IconData text_rotate_vertical = IconData(0xe64c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_rotate_vertical</i> — material icon named "text rotate vertical" (sharp). + static const IconData text_rotate_vertical_sharp = IconData(0xed42, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_rotate_vertical</i> — material icon named "text rotate vertical" (round). + static const IconData text_rotate_vertical_rounded = IconData(0xf0221, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_rotate_vertical</i> — material icon named "text rotate vertical" (outlined). + static const IconData text_rotate_vertical_outlined = IconData(0xf42f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_rotation_angledown</i> — material icon named "text rotation angledown". + static const IconData text_rotation_angledown = IconData(0xe64d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_rotation_angledown</i> — material icon named "text rotation angledown" (sharp). + static const IconData text_rotation_angledown_sharp = IconData(0xed43, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_rotation_angledown</i> — material icon named "text rotation angledown" (round). + static const IconData text_rotation_angledown_rounded = IconData(0xf0222, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_rotation_angledown</i> — material icon named "text rotation angledown" (outlined). + static const IconData text_rotation_angledown_outlined = IconData(0xf430, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_rotation_angleup</i> — material icon named "text rotation angleup". + static const IconData text_rotation_angleup = IconData(0xe64e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_rotation_angleup</i> — material icon named "text rotation angleup" (sharp). + static const IconData text_rotation_angleup_sharp = IconData(0xed44, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_rotation_angleup</i> — material icon named "text rotation angleup" (round). + static const IconData text_rotation_angleup_rounded = IconData(0xf0223, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_rotation_angleup</i> — material icon named "text rotation angleup" (outlined). + static const IconData text_rotation_angleup_outlined = IconData(0xf431, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_rotation_down</i> — material icon named "text rotation down". + static const IconData text_rotation_down = IconData(0xe64f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_rotation_down</i> — material icon named "text rotation down" (sharp). + static const IconData text_rotation_down_sharp = IconData(0xed45, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_rotation_down</i> — material icon named "text rotation down" (round). + static const IconData text_rotation_down_rounded = IconData(0xf0224, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_rotation_down</i> — material icon named "text rotation down" (outlined). + static const IconData text_rotation_down_outlined = IconData(0xf432, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_rotation_none</i> — material icon named "text rotation none". + static const IconData text_rotation_none = IconData(0xe650, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_rotation_none</i> — material icon named "text rotation none" (sharp). + static const IconData text_rotation_none_sharp = IconData(0xed46, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_rotation_none</i> — material icon named "text rotation none" (round). + static const IconData text_rotation_none_rounded = IconData(0xf0225, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_rotation_none</i> — material icon named "text rotation none" (outlined). + static const IconData text_rotation_none_outlined = IconData(0xf433, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">text_snippet</i> — material icon named "text snippet". + static const IconData text_snippet = IconData(0xe651, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">text_snippet</i> — material icon named "text snippet" (sharp). + static const IconData text_snippet_sharp = IconData(0xed47, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">text_snippet</i> — material icon named "text snippet" (round). + static const IconData text_snippet_rounded = IconData(0xf0226, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">text_snippet</i> — material icon named "text snippet" (outlined). + static const IconData text_snippet_outlined = IconData(0xf434, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">textsms</i> — material icon named "textsms". + static const IconData textsms = IconData(0xe652, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">textsms</i> — material icon named "textsms" (sharp). + static const IconData textsms_sharp = IconData(0xed48, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">textsms</i> — material icon named "textsms" (round). + static const IconData textsms_rounded = IconData(0xf0227, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">textsms</i> — material icon named "textsms" (outlined). + static const IconData textsms_outlined = IconData(0xf435, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">texture</i> — material icon named "texture". + static const IconData texture = IconData(0xe653, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">texture</i> — material icon named "texture" (sharp). + static const IconData texture_sharp = IconData(0xed49, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">texture</i> — material icon named "texture" (round). + static const IconData texture_rounded = IconData(0xf0228, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">texture</i> — material icon named "texture" (outlined). + static const IconData texture_outlined = IconData(0xf436, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">theater_comedy</i> — material icon named "theater comedy". + static const IconData theater_comedy = IconData(0xe654, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">theater_comedy</i> — material icon named "theater comedy" (sharp). + static const IconData theater_comedy_sharp = IconData(0xed4a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">theater_comedy</i> — material icon named "theater comedy" (round). + static const IconData theater_comedy_rounded = IconData(0xf0229, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">theater_comedy</i> — material icon named "theater comedy" (outlined). + static const IconData theater_comedy_outlined = IconData(0xf437, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">theaters</i> — material icon named "theaters". + static const IconData theaters = IconData(0xe655, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">theaters</i> — material icon named "theaters" (sharp). + static const IconData theaters_sharp = IconData(0xed4b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">theaters</i> — material icon named "theaters" (round). + static const IconData theaters_rounded = IconData(0xf022a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">theaters</i> — material icon named "theaters" (outlined). + static const IconData theaters_outlined = IconData(0xf438, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">thermostat</i> — material icon named "thermostat". + static const IconData thermostat = IconData(0xe656, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">thermostat</i> — material icon named "thermostat" (sharp). + static const IconData thermostat_sharp = IconData(0xed4d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">thermostat</i> — material icon named "thermostat" (round). + static const IconData thermostat_rounded = IconData(0xf022c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">thermostat</i> — material icon named "thermostat" (outlined). + static const IconData thermostat_outlined = IconData(0xf43a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">thermostat_auto</i> — material icon named "thermostat auto". + static const IconData thermostat_auto = IconData(0xe657, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">thermostat_auto</i> — material icon named "thermostat auto" (sharp). + static const IconData thermostat_auto_sharp = IconData(0xed4c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">thermostat_auto</i> — material icon named "thermostat auto" (round). + static const IconData thermostat_auto_rounded = IconData(0xf022b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">thermostat_auto</i> — material icon named "thermostat auto" (outlined). + static const IconData thermostat_auto_outlined = IconData(0xf439, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">thumb_down</i> — material icon named "thumb down". + static const IconData thumb_down = IconData(0xe658, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">thumb_down</i> — material icon named "thumb down" (sharp). + static const IconData thumb_down_sharp = IconData(0xed50, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">thumb_down</i> — material icon named "thumb down" (round). + static const IconData thumb_down_rounded = IconData(0xf022f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">thumb_down</i> — material icon named "thumb down" (outlined). + static const IconData thumb_down_outlined = IconData(0xf43d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">thumb_down_alt</i> — material icon named "thumb down alt". + static const IconData thumb_down_alt = IconData(0xe659, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">thumb_down_alt</i> — material icon named "thumb down alt" (sharp). + static const IconData thumb_down_alt_sharp = IconData(0xed4e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">thumb_down_alt</i> — material icon named "thumb down alt" (round). + static const IconData thumb_down_alt_rounded = IconData(0xf022d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">thumb_down_alt</i> — material icon named "thumb down alt" (outlined). + static const IconData thumb_down_alt_outlined = IconData(0xf43b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">thumb_down_off_alt</i> — material icon named "thumb down off alt". + static const IconData thumb_down_off_alt = IconData(0xe65a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">thumb_down_off_alt</i> — material icon named "thumb down off alt" (sharp). + static const IconData thumb_down_off_alt_sharp = IconData(0xed4f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">thumb_down_off_alt</i> — material icon named "thumb down off alt" (round). + static const IconData thumb_down_off_alt_rounded = IconData(0xf022e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">thumb_down_off_alt</i> — material icon named "thumb down off alt" (outlined). + static const IconData thumb_down_off_alt_outlined = IconData(0xf43c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">thumb_up</i> — material icon named "thumb up". + static const IconData thumb_up = IconData(0xe65b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">thumb_up</i> — material icon named "thumb up" (sharp). + static const IconData thumb_up_sharp = IconData(0xed53, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">thumb_up</i> — material icon named "thumb up" (round). + static const IconData thumb_up_rounded = IconData(0xf0232, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">thumb_up</i> — material icon named "thumb up" (outlined). + static const IconData thumb_up_outlined = IconData(0xf440, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">thumb_up_alt</i> — material icon named "thumb up alt". + static const IconData thumb_up_alt = IconData(0xe65c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">thumb_up_alt</i> — material icon named "thumb up alt" (sharp). + static const IconData thumb_up_alt_sharp = IconData(0xed51, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">thumb_up_alt</i> — material icon named "thumb up alt" (round). + static const IconData thumb_up_alt_rounded = IconData(0xf0230, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">thumb_up_alt</i> — material icon named "thumb up alt" (outlined). + static const IconData thumb_up_alt_outlined = IconData(0xf43e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">thumb_up_off_alt</i> — material icon named "thumb up off alt". + static const IconData thumb_up_off_alt = IconData(0xe65d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">thumb_up_off_alt</i> — material icon named "thumb up off alt" (sharp). + static const IconData thumb_up_off_alt_sharp = IconData(0xed52, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">thumb_up_off_alt</i> — material icon named "thumb up off alt" (round). + static const IconData thumb_up_off_alt_rounded = IconData(0xf0231, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">thumb_up_off_alt</i> — material icon named "thumb up off alt" (outlined). + static const IconData thumb_up_off_alt_outlined = IconData(0xf43f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">thumbs_up_down</i> — material icon named "thumbs up down". + static const IconData thumbs_up_down = IconData(0xe65e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">thumbs_up_down</i> — material icon named "thumbs up down" (sharp). + static const IconData thumbs_up_down_sharp = IconData(0xed54, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">thumbs_up_down</i> — material icon named "thumbs up down" (round). + static const IconData thumbs_up_down_rounded = IconData(0xf0233, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">thumbs_up_down</i> — material icon named "thumbs up down" (outlined). + static const IconData thumbs_up_down_outlined = IconData(0xf441, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">thunderstorm</i> — material icon named "thunderstorm". + static const IconData thunderstorm = IconData(0xf07cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">thunderstorm</i> — material icon named "thunderstorm" (sharp). + static const IconData thunderstorm_sharp = IconData(0xf0773, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">thunderstorm</i> — material icon named "thunderstorm" (round). + static const IconData thunderstorm_rounded = IconData(0xf0823, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">thunderstorm</i> — material icon named "thunderstorm" (outlined). + static const IconData thunderstorm_outlined = IconData(0xf071b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tiktok</i> — material icon named "tiktok". + static const IconData tiktok = IconData(0xf058c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tiktok</i> — material icon named "tiktok" (sharp). + static const IconData tiktok_sharp = IconData(0xf0492, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tiktok</i> — material icon named "tiktok" (round). + static const IconData tiktok_rounded = IconData(0xf039f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tiktok</i> — material icon named "tiktok" (outlined). + static const IconData tiktok_outlined = IconData(0xf0680, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">time_to_leave</i> — material icon named "time to leave". + static const IconData time_to_leave = IconData(0xe65f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">time_to_leave</i> — material icon named "time to leave" (sharp). + static const IconData time_to_leave_sharp = IconData(0xed55, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">time_to_leave</i> — material icon named "time to leave" (round). + static const IconData time_to_leave_rounded = IconData(0xf0234, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">time_to_leave</i> — material icon named "time to leave" (outlined). + static const IconData time_to_leave_outlined = IconData(0xf442, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">timelapse</i> — material icon named "timelapse". + static const IconData timelapse = IconData(0xe660, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">timelapse</i> — material icon named "timelapse" (sharp). + static const IconData timelapse_sharp = IconData(0xed56, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">timelapse</i> — material icon named "timelapse" (round). + static const IconData timelapse_rounded = IconData(0xf0235, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">timelapse</i> — material icon named "timelapse" (outlined). + static const IconData timelapse_outlined = IconData(0xf443, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">timeline</i> — material icon named "timeline". + static const IconData timeline = IconData(0xe661, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">timeline</i> — material icon named "timeline" (sharp). + static const IconData timeline_sharp = IconData(0xed57, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">timeline</i> — material icon named "timeline" (round). + static const IconData timeline_rounded = IconData(0xf0236, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">timeline</i> — material icon named "timeline" (outlined). + static const IconData timeline_outlined = IconData(0xf444, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">timer</i> — material icon named "timer". + static const IconData timer = IconData(0xe662, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">timer</i> — material icon named "timer" (sharp). + static const IconData timer_sharp = IconData(0xed5d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">timer</i> — material icon named "timer" (round). + static const IconData timer_rounded = IconData(0xf023c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">timer</i> — material icon named "timer" (outlined). + static const IconData timer_outlined = IconData(0xf44a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">timer_10</i> — material icon named "timer 10". + static const IconData timer_10 = IconData(0xe663, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">timer_10</i> — material icon named "timer 10" (sharp). + static const IconData timer_10_sharp = IconData(0xed59, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">timer_10</i> — material icon named "timer 10" (round). + static const IconData timer_10_rounded = IconData(0xf0237, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">timer_10</i> — material icon named "timer 10" (outlined). + static const IconData timer_10_outlined = IconData(0xf445, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">timer_10_select</i> — material icon named "timer 10 select". + static const IconData timer_10_select = IconData(0xe664, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">timer_10_select</i> — material icon named "timer 10 select" (sharp). + static const IconData timer_10_select_sharp = IconData(0xed58, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">timer_10_select</i> — material icon named "timer 10 select" (round). + static const IconData timer_10_select_rounded = IconData(0xf0238, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">timer_10_select</i> — material icon named "timer 10 select" (outlined). + static const IconData timer_10_select_outlined = IconData(0xf446, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">timer_3</i> — material icon named "timer 3". + static const IconData timer_3 = IconData(0xe665, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">timer_3</i> — material icon named "timer 3" (sharp). + static const IconData timer_3_sharp = IconData(0xed5b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">timer_3</i> — material icon named "timer 3" (round). + static const IconData timer_3_rounded = IconData(0xf0239, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">timer_3</i> — material icon named "timer 3" (outlined). + static const IconData timer_3_outlined = IconData(0xf447, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">timer_3_select</i> — material icon named "timer 3 select". + static const IconData timer_3_select = IconData(0xe666, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">timer_3_select</i> — material icon named "timer 3 select" (sharp). + static const IconData timer_3_select_sharp = IconData(0xed5a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">timer_3_select</i> — material icon named "timer 3 select" (round). + static const IconData timer_3_select_rounded = IconData(0xf023a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">timer_3_select</i> — material icon named "timer 3 select" (outlined). + static const IconData timer_3_select_outlined = IconData(0xf448, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">timer_off</i> — material icon named "timer off". + static const IconData timer_off = IconData(0xe667, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">timer_off</i> — material icon named "timer off" (sharp). + static const IconData timer_off_sharp = IconData(0xed5c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">timer_off</i> — material icon named "timer off" (round). + static const IconData timer_off_rounded = IconData(0xf023b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">timer_off</i> — material icon named "timer off" (outlined). + static const IconData timer_off_outlined = IconData(0xf449, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tips_and_updates</i> — material icon named "tips and updates". + static const IconData tips_and_updates = IconData(0xf058d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tips_and_updates</i> — material icon named "tips and updates" (sharp). + static const IconData tips_and_updates_sharp = IconData(0xf0493, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tips_and_updates</i> — material icon named "tips and updates" (round). + static const IconData tips_and_updates_rounded = IconData(0xf03a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tips_and_updates</i> — material icon named "tips and updates" (outlined). + static const IconData tips_and_updates_outlined = IconData(0xf0681, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tire_repair</i> — material icon named "tire repair". + static const IconData tire_repair = IconData(0xf06c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tire_repair</i> — material icon named "tire repair" (sharp). + static const IconData tire_repair_sharp = IconData(0xf06b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tire_repair</i> — material icon named "tire repair" (round). + static const IconData tire_repair_rounded = IconData(0xf06d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tire_repair</i> — material icon named "tire repair" (outlined). + static const IconData tire_repair_outlined = IconData(0xf06aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">title</i> — material icon named "title". + static const IconData title = IconData(0xe668, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">title</i> — material icon named "title" (sharp). + static const IconData title_sharp = IconData(0xed5e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">title</i> — material icon named "title" (round). + static const IconData title_rounded = IconData(0xf023d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">title</i> — material icon named "title" (outlined). + static const IconData title_outlined = IconData(0xf44b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">toc</i> — material icon named "toc". + static const IconData toc = IconData(0xe669, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">toc</i> — material icon named "toc" (sharp). + static const IconData toc_sharp = IconData(0xed5f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">toc</i> — material icon named "toc" (round). + static const IconData toc_rounded = IconData(0xf023e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">toc</i> — material icon named "toc" (outlined). + static const IconData toc_outlined = IconData(0xf44c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">today</i> — material icon named "today". + static const IconData today = IconData(0xe66a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">today</i> — material icon named "today" (sharp). + static const IconData today_sharp = IconData(0xed60, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">today</i> — material icon named "today" (round). + static const IconData today_rounded = IconData(0xf023f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">today</i> — material icon named "today" (outlined). + static const IconData today_outlined = IconData(0xf44d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">toggle_off</i> — material icon named "toggle off". + static const IconData toggle_off = IconData(0xe66b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">toggle_off</i> — material icon named "toggle off" (sharp). + static const IconData toggle_off_sharp = IconData(0xed61, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">toggle_off</i> — material icon named "toggle off" (round). + static const IconData toggle_off_rounded = IconData(0xf0240, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">toggle_off</i> — material icon named "toggle off" (outlined). + static const IconData toggle_off_outlined = IconData(0xf44e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">toggle_on</i> — material icon named "toggle on". + static const IconData toggle_on = IconData(0xe66c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">toggle_on</i> — material icon named "toggle on" (sharp). + static const IconData toggle_on_sharp = IconData(0xed62, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">toggle_on</i> — material icon named "toggle on" (round). + static const IconData toggle_on_rounded = IconData(0xf0241, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">toggle_on</i> — material icon named "toggle on" (outlined). + static const IconData toggle_on_outlined = IconData(0xf44f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">token</i> — material icon named "token". + static const IconData token = IconData(0xf058e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">token</i> — material icon named "token" (sharp). + static const IconData token_sharp = IconData(0xf0494, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">token</i> — material icon named "token" (round). + static const IconData token_rounded = IconData(0xf03a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">token</i> — material icon named "token" (outlined). + static const IconData token_outlined = IconData(0xf0682, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">toll</i> — material icon named "toll". + static const IconData toll = IconData(0xe66d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">toll</i> — material icon named "toll" (sharp). + static const IconData toll_sharp = IconData(0xed63, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">toll</i> — material icon named "toll" (round). + static const IconData toll_rounded = IconData(0xf0242, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">toll</i> — material icon named "toll" (outlined). + static const IconData toll_outlined = IconData(0xf450, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tonality</i> — material icon named "tonality". + static const IconData tonality = IconData(0xe66e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tonality</i> — material icon named "tonality" (sharp). + static const IconData tonality_sharp = IconData(0xed64, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tonality</i> — material icon named "tonality" (round). + static const IconData tonality_rounded = IconData(0xf0243, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tonality</i> — material icon named "tonality" (outlined). + static const IconData tonality_outlined = IconData(0xf451, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">topic</i> — material icon named "topic". + static const IconData topic = IconData(0xe66f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">topic</i> — material icon named "topic" (sharp). + static const IconData topic_sharp = IconData(0xed65, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">topic</i> — material icon named "topic" (round). + static const IconData topic_rounded = IconData(0xf0244, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">topic</i> — material icon named "topic" (outlined). + static const IconData topic_outlined = IconData(0xf452, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tornado</i> — material icon named "tornado". + static const IconData tornado = IconData(0xf07cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tornado</i> — material icon named "tornado" (sharp). + static const IconData tornado_sharp = IconData(0xf0774, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tornado</i> — material icon named "tornado" (round). + static const IconData tornado_rounded = IconData(0xf0824, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tornado</i> — material icon named "tornado" (outlined). + static const IconData tornado_outlined = IconData(0xf071c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">touch_app</i> — material icon named "touch app". + static const IconData touch_app = IconData(0xe670, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">touch_app</i> — material icon named "touch app" (sharp). + static const IconData touch_app_sharp = IconData(0xed66, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">touch_app</i> — material icon named "touch app" (round). + static const IconData touch_app_rounded = IconData(0xf0245, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">touch_app</i> — material icon named "touch app" (outlined). + static const IconData touch_app_outlined = IconData(0xf453, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tour</i> — material icon named "tour". + static const IconData tour = IconData(0xe671, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tour</i> — material icon named "tour" (sharp). + static const IconData tour_sharp = IconData(0xed67, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tour</i> — material icon named "tour" (round). + static const IconData tour_rounded = IconData(0xf0246, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tour</i> — material icon named "tour" (outlined). + static const IconData tour_outlined = IconData(0xf454, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">toys</i> — material icon named "toys". + static const IconData toys = IconData(0xe672, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">toys</i> — material icon named "toys" (sharp). + static const IconData toys_sharp = IconData(0xed68, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">toys</i> — material icon named "toys" (round). + static const IconData toys_rounded = IconData(0xf0247, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">toys</i> — material icon named "toys" (outlined). + static const IconData toys_outlined = IconData(0xf455, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">track_changes</i> — material icon named "track changes". + static const IconData track_changes = IconData(0xe673, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">track_changes</i> — material icon named "track changes" (sharp). + static const IconData track_changes_sharp = IconData(0xed69, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">track_changes</i> — material icon named "track changes" (round). + static const IconData track_changes_rounded = IconData(0xf0248, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">track_changes</i> — material icon named "track changes" (outlined). + static const IconData track_changes_outlined = IconData(0xf456, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">traffic</i> — material icon named "traffic". + static const IconData traffic = IconData(0xe674, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">traffic</i> — material icon named "traffic" (sharp). + static const IconData traffic_sharp = IconData(0xed6a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">traffic</i> — material icon named "traffic" (round). + static const IconData traffic_rounded = IconData(0xf0249, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">traffic</i> — material icon named "traffic" (outlined). + static const IconData traffic_outlined = IconData(0xf457, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">train</i> — material icon named "train". + static const IconData train = IconData(0xe675, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">train</i> — material icon named "train" (sharp). + static const IconData train_sharp = IconData(0xed6b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">train</i> — material icon named "train" (round). + static const IconData train_rounded = IconData(0xf024a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">train</i> — material icon named "train" (outlined). + static const IconData train_outlined = IconData(0xf458, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tram</i> — material icon named "tram". + static const IconData tram = IconData(0xe676, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tram</i> — material icon named "tram" (sharp). + static const IconData tram_sharp = IconData(0xed6c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tram</i> — material icon named "tram" (round). + static const IconData tram_rounded = IconData(0xf024b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tram</i> — material icon named "tram" (outlined). + static const IconData tram_outlined = IconData(0xf459, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">transcribe</i> — material icon named "transcribe". + static const IconData transcribe = IconData(0xf07cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">transcribe</i> — material icon named "transcribe" (sharp). + static const IconData transcribe_sharp = IconData(0xf0775, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">transcribe</i> — material icon named "transcribe" (round). + static const IconData transcribe_rounded = IconData(0xf0825, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">transcribe</i> — material icon named "transcribe" (outlined). + static const IconData transcribe_outlined = IconData(0xf071d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">transfer_within_a_station</i> — material icon named "transfer within a station". + static const IconData transfer_within_a_station = IconData(0xe677, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">transfer_within_a_station</i> — material icon named "transfer within a station" (sharp). + static const IconData transfer_within_a_station_sharp = IconData(0xed6d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">transfer_within_a_station</i> — material icon named "transfer within a station" (round). + static const IconData transfer_within_a_station_rounded = IconData(0xf024c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">transfer_within_a_station</i> — material icon named "transfer within a station" (outlined). + static const IconData transfer_within_a_station_outlined = IconData(0xf45a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">transform</i> — material icon named "transform". + static const IconData transform = IconData(0xe678, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">transform</i> — material icon named "transform" (sharp). + static const IconData transform_sharp = IconData(0xed6e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">transform</i> — material icon named "transform" (round). + static const IconData transform_rounded = IconData(0xf024d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">transform</i> — material icon named "transform" (outlined). + static const IconData transform_outlined = IconData(0xf45b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">transgender</i> — material icon named "transgender". + static const IconData transgender = IconData(0xe679, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">transgender</i> — material icon named "transgender" (sharp). + static const IconData transgender_sharp = IconData(0xed6f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">transgender</i> — material icon named "transgender" (round). + static const IconData transgender_rounded = IconData(0xf024e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">transgender</i> — material icon named "transgender" (outlined). + static const IconData transgender_outlined = IconData(0xf45c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">transit_enterexit</i> — material icon named "transit enterexit". + static const IconData transit_enterexit = IconData(0xe67a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">transit_enterexit</i> — material icon named "transit enterexit" (sharp). + static const IconData transit_enterexit_sharp = IconData(0xed70, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">transit_enterexit</i> — material icon named "transit enterexit" (round). + static const IconData transit_enterexit_rounded = IconData(0xf024f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">transit_enterexit</i> — material icon named "transit enterexit" (outlined). + static const IconData transit_enterexit_outlined = IconData(0xf45d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">translate</i> — material icon named "translate". + static const IconData translate = IconData(0xe67b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">translate</i> — material icon named "translate" (sharp). + static const IconData translate_sharp = IconData(0xed71, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">translate</i> — material icon named "translate" (round). + static const IconData translate_rounded = IconData(0xf0250, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">translate</i> — material icon named "translate" (outlined). + static const IconData translate_outlined = IconData(0xf45e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">travel_explore</i> — material icon named "travel explore". + static const IconData travel_explore = IconData(0xe67c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">travel_explore</i> — material icon named "travel explore" (sharp). + static const IconData travel_explore_sharp = IconData(0xed72, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">travel_explore</i> — material icon named "travel explore" (round). + static const IconData travel_explore_rounded = IconData(0xf0251, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">travel_explore</i> — material icon named "travel explore" (outlined). + static const IconData travel_explore_outlined = IconData(0xf45f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">trending_down</i> — material icon named "trending down". + static const IconData trending_down = IconData(0xe67d, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">trending_down</i> — material icon named "trending down" (sharp). + static const IconData trending_down_sharp = IconData(0xed73, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">trending_down</i> — material icon named "trending down" (round). + static const IconData trending_down_rounded = IconData(0xf0252, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">trending_down</i> — material icon named "trending down" (outlined). + static const IconData trending_down_outlined = IconData(0xf460, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">trending_flat</i> — material icon named "trending flat". + static const IconData trending_flat = IconData(0xe67e, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">trending_flat</i> — material icon named "trending flat" (sharp). + static const IconData trending_flat_sharp = IconData(0xed74, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">trending_flat</i> — material icon named "trending flat" (round). + static const IconData trending_flat_rounded = IconData(0xf0253, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">trending_flat</i> — material icon named "trending flat" (outlined). + static const IconData trending_flat_outlined = IconData(0xf461, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">trending_neutral</i> — material icon named "trending neutral". + static const IconData trending_neutral = IconData(0xe67e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">trending_neutral</i> — material icon named "trending neutral" (sharp). + static const IconData trending_neutral_sharp = IconData(0xed74, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">trending_neutral</i> — material icon named "trending neutral" (round). + static const IconData trending_neutral_rounded = IconData(0xf0253, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">trending_neutral</i> — material icon named "trending neutral" (outlined). + static const IconData trending_neutral_outlined = IconData(0xf461, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">trending_up</i> — material icon named "trending up". + static const IconData trending_up = IconData(0xe67f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">trending_up</i> — material icon named "trending up" (sharp). + static const IconData trending_up_sharp = IconData(0xed75, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">trending_up</i> — material icon named "trending up" (round). + static const IconData trending_up_rounded = IconData(0xf0254, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">trending_up</i> — material icon named "trending up" (outlined). + static const IconData trending_up_outlined = IconData(0xf462, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">trip_origin</i> — material icon named "trip origin". + static const IconData trip_origin = IconData(0xe680, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">trip_origin</i> — material icon named "trip origin" (sharp). + static const IconData trip_origin_sharp = IconData(0xed76, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">trip_origin</i> — material icon named "trip origin" (round). + static const IconData trip_origin_rounded = IconData(0xf0255, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">trip_origin</i> — material icon named "trip origin" (outlined). + static const IconData trip_origin_outlined = IconData(0xf463, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">trolley</i> — material icon named "trolley". + static const IconData trolley = IconData(0xf0878, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">troubleshoot</i> — material icon named "troubleshoot". + static const IconData troubleshoot = IconData(0xf07ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">troubleshoot</i> — material icon named "troubleshoot" (sharp). + static const IconData troubleshoot_sharp = IconData(0xf0776, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">troubleshoot</i> — material icon named "troubleshoot" (round). + static const IconData troubleshoot_rounded = IconData(0xf0826, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">troubleshoot</i> — material icon named "troubleshoot" (outlined). + static const IconData troubleshoot_outlined = IconData(0xf071e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">try</i> — material icon named "try". + static const IconData try_sms_star = IconData(0xe681, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">try</i> — material icon named "try" (sharp). + static const IconData try_sms_star_sharp = IconData(0xed77, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">try</i> — material icon named "try" (round). + static const IconData try_sms_star_rounded = IconData(0xf0256, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">try</i> — material icon named "try" (outlined). + static const IconData try_sms_star_outlined = IconData(0xf464, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tsunami</i> — material icon named "tsunami". + static const IconData tsunami = IconData(0xf07cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tsunami</i> — material icon named "tsunami" (sharp). + static const IconData tsunami_sharp = IconData(0xf0777, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tsunami</i> — material icon named "tsunami" (round). + static const IconData tsunami_rounded = IconData(0xf0827, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tsunami</i> — material icon named "tsunami" (outlined). + static const IconData tsunami_outlined = IconData(0xf071f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tty</i> — material icon named "tty". + static const IconData tty = IconData(0xe682, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tty</i> — material icon named "tty" (sharp). + static const IconData tty_sharp = IconData(0xed78, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tty</i> — material icon named "tty" (round). + static const IconData tty_rounded = IconData(0xf0257, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tty</i> — material icon named "tty" (outlined). + static const IconData tty_outlined = IconData(0xf465, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tune</i> — material icon named "tune". + static const IconData tune = IconData(0xe683, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tune</i> — material icon named "tune" (sharp). + static const IconData tune_sharp = IconData(0xed79, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tune</i> — material icon named "tune" (round). + static const IconData tune_rounded = IconData(0xf0258, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tune</i> — material icon named "tune" (outlined). + static const IconData tune_outlined = IconData(0xf466, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tungsten</i> — material icon named "tungsten". + static const IconData tungsten = IconData(0xe684, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tungsten</i> — material icon named "tungsten" (sharp). + static const IconData tungsten_sharp = IconData(0xed7a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tungsten</i> — material icon named "tungsten" (round). + static const IconData tungsten_rounded = IconData(0xf0259, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tungsten</i> — material icon named "tungsten" (outlined). + static const IconData tungsten_outlined = IconData(0xf467, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">turn_left</i> — material icon named "turn left". + static const IconData turn_left = IconData(0xf058f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">turn_left</i> — material icon named "turn left" (sharp). + static const IconData turn_left_sharp = IconData(0xf0495, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">turn_left</i> — material icon named "turn left" (round). + static const IconData turn_left_rounded = IconData(0xf03a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">turn_left</i> — material icon named "turn left" (outlined). + static const IconData turn_left_outlined = IconData(0xf0683, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">turn_right</i> — material icon named "turn right". + static const IconData turn_right = IconData(0xf0590, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">turn_right</i> — material icon named "turn right" (sharp). + static const IconData turn_right_sharp = IconData(0xf0496, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">turn_right</i> — material icon named "turn right" (round). + static const IconData turn_right_rounded = IconData(0xf03a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">turn_right</i> — material icon named "turn right" (outlined). + static const IconData turn_right_outlined = IconData(0xf0684, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">turn_sharp_left</i> — material icon named "turn sharp left". + static const IconData turn_sharp_left = IconData(0xf0591, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">turn_sharp_left</i> — material icon named "turn sharp left" (sharp). + static const IconData turn_sharp_left_sharp = IconData(0xf0497, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">turn_sharp_left</i> — material icon named "turn sharp left" (round). + static const IconData turn_sharp_left_rounded = IconData(0xf03a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">turn_sharp_left</i> — material icon named "turn sharp left" (outlined). + static const IconData turn_sharp_left_outlined = IconData(0xf0685, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">turn_sharp_right</i> — material icon named "turn sharp right". + static const IconData turn_sharp_right = IconData(0xf0592, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">turn_sharp_right</i> — material icon named "turn sharp right" (sharp). + static const IconData turn_sharp_right_sharp = IconData(0xf0498, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">turn_sharp_right</i> — material icon named "turn sharp right" (round). + static const IconData turn_sharp_right_rounded = IconData(0xf03a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">turn_sharp_right</i> — material icon named "turn sharp right" (outlined). + static const IconData turn_sharp_right_outlined = IconData(0xf0686, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">turn_slight_left</i> — material icon named "turn slight left". + static const IconData turn_slight_left = IconData(0xf0593, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">turn_slight_left</i> — material icon named "turn slight left" (sharp). + static const IconData turn_slight_left_sharp = IconData(0xf0499, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">turn_slight_left</i> — material icon named "turn slight left" (round). + static const IconData turn_slight_left_rounded = IconData(0xf03a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">turn_slight_left</i> — material icon named "turn slight left" (outlined). + static const IconData turn_slight_left_outlined = IconData(0xf0687, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">turn_slight_right</i> — material icon named "turn slight right". + static const IconData turn_slight_right = IconData(0xf0594, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">turn_slight_right</i> — material icon named "turn slight right" (sharp). + static const IconData turn_slight_right_sharp = IconData(0xf049a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">turn_slight_right</i> — material icon named "turn slight right" (round). + static const IconData turn_slight_right_rounded = IconData(0xf03a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">turn_slight_right</i> — material icon named "turn slight right" (outlined). + static const IconData turn_slight_right_outlined = IconData(0xf0688, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">turned_in</i> — material icon named "turned in". + static const IconData turned_in = IconData(0xe685, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">turned_in</i> — material icon named "turned in" (sharp). + static const IconData turned_in_sharp = IconData(0xed7c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">turned_in</i> — material icon named "turned in" (round). + static const IconData turned_in_rounded = IconData(0xf025b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">turned_in</i> — material icon named "turned in" (outlined). + static const IconData turned_in_outlined = IconData(0xf469, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">turned_in_not</i> — material icon named "turned in not". + static const IconData turned_in_not = IconData(0xe686, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">turned_in_not</i> — material icon named "turned in not" (sharp). + static const IconData turned_in_not_sharp = IconData(0xed7b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">turned_in_not</i> — material icon named "turned in not" (round). + static const IconData turned_in_not_rounded = IconData(0xf025a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">turned_in_not</i> — material icon named "turned in not" (outlined). + static const IconData turned_in_not_outlined = IconData(0xf468, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tv</i> — material icon named "tv". + static const IconData tv = IconData(0xe687, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tv</i> — material icon named "tv" (sharp). + static const IconData tv_sharp = IconData(0xed7e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tv</i> — material icon named "tv" (round). + static const IconData tv_rounded = IconData(0xf025d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tv</i> — material icon named "tv" (outlined). + static const IconData tv_outlined = IconData(0xf46b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">tv_off</i> — material icon named "tv off". + static const IconData tv_off = IconData(0xe688, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">tv_off</i> — material icon named "tv off" (sharp). + static const IconData tv_off_sharp = IconData(0xed7d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">tv_off</i> — material icon named "tv off" (round). + static const IconData tv_off_rounded = IconData(0xf025c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">tv_off</i> — material icon named "tv off" (outlined). + static const IconData tv_off_outlined = IconData(0xf46a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">two_wheeler</i> — material icon named "two wheeler". + static const IconData two_wheeler = IconData(0xe689, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">two_wheeler</i> — material icon named "two wheeler" (sharp). + static const IconData two_wheeler_sharp = IconData(0xed7f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">two_wheeler</i> — material icon named "two wheeler" (round). + static const IconData two_wheeler_rounded = IconData(0xf025e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">two_wheeler</i> — material icon named "two wheeler" (outlined). + static const IconData two_wheeler_outlined = IconData(0xf46c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">type_specimen</i> — material icon named "type specimen". + static const IconData type_specimen = IconData(0xf07d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">type_specimen</i> — material icon named "type specimen" (sharp). + static const IconData type_specimen_sharp = IconData(0xf0778, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">type_specimen</i> — material icon named "type specimen" (round). + static const IconData type_specimen_rounded = IconData(0xf0828, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">type_specimen</i> — material icon named "type specimen" (outlined). + static const IconData type_specimen_outlined = IconData(0xf0720, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">u_turn_left</i> — material icon named "u turn left". + static const IconData u_turn_left = IconData(0xf0595, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">u_turn_left</i> — material icon named "u turn left" (sharp). + static const IconData u_turn_left_sharp = IconData(0xf049b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">u_turn_left</i> — material icon named "u turn left" (round). + static const IconData u_turn_left_rounded = IconData(0xf03a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">u_turn_left</i> — material icon named "u turn left" (outlined). + static const IconData u_turn_left_outlined = IconData(0xf0689, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">u_turn_right</i> — material icon named "u turn right". + static const IconData u_turn_right = IconData(0xf0596, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">u_turn_right</i> — material icon named "u turn right" (sharp). + static const IconData u_turn_right_sharp = IconData(0xf049c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">u_turn_right</i> — material icon named "u turn right" (round). + static const IconData u_turn_right_rounded = IconData(0xf03a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">u_turn_right</i> — material icon named "u turn right" (outlined). + static const IconData u_turn_right_outlined = IconData(0xf068a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">umbrella</i> — material icon named "umbrella". + static const IconData umbrella = IconData(0xe68a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">umbrella</i> — material icon named "umbrella" (sharp). + static const IconData umbrella_sharp = IconData(0xed80, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">umbrella</i> — material icon named "umbrella" (round). + static const IconData umbrella_rounded = IconData(0xf025f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">umbrella</i> — material icon named "umbrella" (outlined). + static const IconData umbrella_outlined = IconData(0xf46d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">unarchive</i> — material icon named "unarchive". + static const IconData unarchive = IconData(0xe68b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">unarchive</i> — material icon named "unarchive" (sharp). + static const IconData unarchive_sharp = IconData(0xed81, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">unarchive</i> — material icon named "unarchive" (round). + static const IconData unarchive_rounded = IconData(0xf0260, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">unarchive</i> — material icon named "unarchive" (outlined). + static const IconData unarchive_outlined = IconData(0xf46e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">undo</i> — material icon named "undo". + static const IconData undo = IconData(0xe68c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">undo</i> — material icon named "undo" (sharp). + static const IconData undo_sharp = IconData(0xed82, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">undo</i> — material icon named "undo" (round). + static const IconData undo_rounded = IconData(0xf0261, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">undo</i> — material icon named "undo" (outlined). + static const IconData undo_outlined = IconData(0xf46f, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">unfold_less</i> — material icon named "unfold less". + static const IconData unfold_less = IconData(0xe68d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">unfold_less</i> — material icon named "unfold less" (sharp). + static const IconData unfold_less_sharp = IconData(0xed83, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">unfold_less</i> — material icon named "unfold less" (round). + static const IconData unfold_less_rounded = IconData(0xf0262, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">unfold_less</i> — material icon named "unfold less" (outlined). + static const IconData unfold_less_outlined = IconData(0xf470, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">unfold_less_double</i> — material icon named "unfold less double". + static const IconData unfold_less_double = IconData(0xf0879, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">unfold_less_double</i> — material icon named "unfold less double" (sharp). + static const IconData unfold_less_double_sharp = IconData(0xf084d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">unfold_less_double</i> — material icon named "unfold less double" (round). + static const IconData unfold_less_double_rounded = IconData(0xf0896, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">unfold_less_double</i> — material icon named "unfold less double" (outlined). + static const IconData unfold_less_double_outlined = IconData(0xf08b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">unfold_more</i> — material icon named "unfold more". + static const IconData unfold_more = IconData(0xe68e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">unfold_more</i> — material icon named "unfold more" (sharp). + static const IconData unfold_more_sharp = IconData(0xed84, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">unfold_more</i> — material icon named "unfold more" (round). + static const IconData unfold_more_rounded = IconData(0xf0263, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">unfold_more</i> — material icon named "unfold more" (outlined). + static const IconData unfold_more_outlined = IconData(0xf471, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">unfold_more_double</i> — material icon named "unfold more double". + static const IconData unfold_more_double = IconData(0xf087a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">unfold_more_double</i> — material icon named "unfold more double" (sharp). + static const IconData unfold_more_double_sharp = IconData(0xf084e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">unfold_more_double</i> — material icon named "unfold more double" (round). + static const IconData unfold_more_double_rounded = IconData(0xf0897, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">unfold_more_double</i> — material icon named "unfold more double" (outlined). + static const IconData unfold_more_double_outlined = IconData(0xf08b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">unpublished</i> — material icon named "unpublished". + static const IconData unpublished = IconData(0xe68f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">unpublished</i> — material icon named "unpublished" (sharp). + static const IconData unpublished_sharp = IconData(0xed85, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">unpublished</i> — material icon named "unpublished" (round). + static const IconData unpublished_rounded = IconData(0xf0264, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">unpublished</i> — material icon named "unpublished" (outlined). + static const IconData unpublished_outlined = IconData(0xf472, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">unsubscribe</i> — material icon named "unsubscribe". + static const IconData unsubscribe = IconData(0xe690, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">unsubscribe</i> — material icon named "unsubscribe" (sharp). + static const IconData unsubscribe_sharp = IconData(0xed86, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">unsubscribe</i> — material icon named "unsubscribe" (round). + static const IconData unsubscribe_rounded = IconData(0xf0265, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">unsubscribe</i> — material icon named "unsubscribe" (outlined). + static const IconData unsubscribe_outlined = IconData(0xf473, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">upcoming</i> — material icon named "upcoming". + static const IconData upcoming = IconData(0xe691, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">upcoming</i> — material icon named "upcoming" (sharp). + static const IconData upcoming_sharp = IconData(0xed87, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">upcoming</i> — material icon named "upcoming" (round). + static const IconData upcoming_rounded = IconData(0xf0266, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">upcoming</i> — material icon named "upcoming" (outlined). + static const IconData upcoming_outlined = IconData(0xf474, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">update</i> — material icon named "update". + static const IconData update = IconData(0xe692, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">update</i> — material icon named "update" (sharp). + static const IconData update_sharp = IconData(0xed89, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">update</i> — material icon named "update" (round). + static const IconData update_rounded = IconData(0xf0268, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">update</i> — material icon named "update" (outlined). + static const IconData update_outlined = IconData(0xf476, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">update_disabled</i> — material icon named "update disabled". + static const IconData update_disabled = IconData(0xe693, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">update_disabled</i> — material icon named "update disabled" (sharp). + static const IconData update_disabled_sharp = IconData(0xed88, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">update_disabled</i> — material icon named "update disabled" (round). + static const IconData update_disabled_rounded = IconData(0xf0267, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">update_disabled</i> — material icon named "update disabled" (outlined). + static const IconData update_disabled_outlined = IconData(0xf475, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">upgrade</i> — material icon named "upgrade". + static const IconData upgrade = IconData(0xe694, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">upgrade</i> — material icon named "upgrade" (sharp). + static const IconData upgrade_sharp = IconData(0xed8a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">upgrade</i> — material icon named "upgrade" (round). + static const IconData upgrade_rounded = IconData(0xf0269, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">upgrade</i> — material icon named "upgrade" (outlined). + static const IconData upgrade_outlined = IconData(0xf477, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">upload</i> — material icon named "upload". + static const IconData upload = IconData(0xe695, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">upload</i> — material icon named "upload" (sharp). + static const IconData upload_sharp = IconData(0xed8c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">upload</i> — material icon named "upload" (round). + static const IconData upload_rounded = IconData(0xf026b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">upload</i> — material icon named "upload" (outlined). + static const IconData upload_outlined = IconData(0xf479, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">upload_file</i> — material icon named "upload file". + static const IconData upload_file = IconData(0xe696, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">upload_file</i> — material icon named "upload file" (sharp). + static const IconData upload_file_sharp = IconData(0xed8b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">upload_file</i> — material icon named "upload file" (round). + static const IconData upload_file_rounded = IconData(0xf026a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">upload_file</i> — material icon named "upload file" (outlined). + static const IconData upload_file_outlined = IconData(0xf478, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">usb</i> — material icon named "usb". + static const IconData usb = IconData(0xe697, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">usb</i> — material icon named "usb" (sharp). + static const IconData usb_sharp = IconData(0xed8e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">usb</i> — material icon named "usb" (round). + static const IconData usb_rounded = IconData(0xf026d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">usb</i> — material icon named "usb" (outlined). + static const IconData usb_outlined = IconData(0xf47b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">usb_off</i> — material icon named "usb off". + static const IconData usb_off = IconData(0xe698, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">usb_off</i> — material icon named "usb off" (sharp). + static const IconData usb_off_sharp = IconData(0xed8d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">usb_off</i> — material icon named "usb off" (round). + static const IconData usb_off_rounded = IconData(0xf026c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">usb_off</i> — material icon named "usb off" (outlined). + static const IconData usb_off_outlined = IconData(0xf47a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vaccines</i> — material icon named "vaccines". + static const IconData vaccines = IconData(0xf0597, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vaccines</i> — material icon named "vaccines" (sharp). + static const IconData vaccines_sharp = IconData(0xf049d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vaccines</i> — material icon named "vaccines" (round). + static const IconData vaccines_rounded = IconData(0xf03aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vaccines</i> — material icon named "vaccines" (outlined). + static const IconData vaccines_outlined = IconData(0xf068b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vape_free</i> — material icon named "vape free". + static const IconData vape_free = IconData(0xf06c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vape_free</i> — material icon named "vape free" (sharp). + static const IconData vape_free_sharp = IconData(0xf06b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vape_free</i> — material icon named "vape free" (round). + static const IconData vape_free_rounded = IconData(0xf06d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vape_free</i> — material icon named "vape free" (outlined). + static const IconData vape_free_outlined = IconData(0xf06ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vaping_rooms</i> — material icon named "vaping rooms". + static const IconData vaping_rooms = IconData(0xf06c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vaping_rooms</i> — material icon named "vaping rooms" (sharp). + static const IconData vaping_rooms_sharp = IconData(0xf06b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vaping_rooms</i> — material icon named "vaping rooms" (round). + static const IconData vaping_rooms_rounded = IconData(0xf06d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vaping_rooms</i> — material icon named "vaping rooms" (outlined). + static const IconData vaping_rooms_outlined = IconData(0xf06ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">verified</i> — material icon named "verified". + static const IconData verified = IconData(0xe699, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">verified</i> — material icon named "verified" (sharp). + static const IconData verified_sharp = IconData(0xed8f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">verified</i> — material icon named "verified" (round). + static const IconData verified_rounded = IconData(0xf026e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">verified</i> — material icon named "verified" (outlined). + static const IconData verified_outlined = IconData(0xf47c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">verified_user</i> — material icon named "verified user". + static const IconData verified_user = IconData(0xe69a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">verified_user</i> — material icon named "verified user" (sharp). + static const IconData verified_user_sharp = IconData(0xed90, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">verified_user</i> — material icon named "verified user" (round). + static const IconData verified_user_rounded = IconData(0xf026f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">verified_user</i> — material icon named "verified user" (outlined). + static const IconData verified_user_outlined = IconData(0xf47d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vertical_align_bottom</i> — material icon named "vertical align bottom". + static const IconData vertical_align_bottom = IconData(0xe69b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vertical_align_bottom</i> — material icon named "vertical align bottom" (sharp). + static const IconData vertical_align_bottom_sharp = IconData(0xed91, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vertical_align_bottom</i> — material icon named "vertical align bottom" (round). + static const IconData vertical_align_bottom_rounded = IconData(0xf0270, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vertical_align_bottom</i> — material icon named "vertical align bottom" (outlined). + static const IconData vertical_align_bottom_outlined = IconData(0xf47e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vertical_align_center</i> — material icon named "vertical align center". + static const IconData vertical_align_center = IconData(0xe69c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vertical_align_center</i> — material icon named "vertical align center" (sharp). + static const IconData vertical_align_center_sharp = IconData(0xed92, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vertical_align_center</i> — material icon named "vertical align center" (round). + static const IconData vertical_align_center_rounded = IconData(0xf0271, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vertical_align_center</i> — material icon named "vertical align center" (outlined). + static const IconData vertical_align_center_outlined = IconData(0xf47f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vertical_align_top</i> — material icon named "vertical align top". + static const IconData vertical_align_top = IconData(0xe69d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vertical_align_top</i> — material icon named "vertical align top" (sharp). + static const IconData vertical_align_top_sharp = IconData(0xed93, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vertical_align_top</i> — material icon named "vertical align top" (round). + static const IconData vertical_align_top_rounded = IconData(0xf0272, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vertical_align_top</i> — material icon named "vertical align top" (outlined). + static const IconData vertical_align_top_outlined = IconData(0xf480, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vertical_distribute</i> — material icon named "vertical distribute". + static const IconData vertical_distribute = IconData(0xe69e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vertical_distribute</i> — material icon named "vertical distribute" (sharp). + static const IconData vertical_distribute_sharp = IconData(0xed94, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vertical_distribute</i> — material icon named "vertical distribute" (round). + static const IconData vertical_distribute_rounded = IconData(0xf0273, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vertical_distribute</i> — material icon named "vertical distribute" (outlined). + static const IconData vertical_distribute_outlined = IconData(0xf481, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vertical_shades</i> — material icon named "vertical shades". + static const IconData vertical_shades = IconData(0xf07d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vertical_shades</i> — material icon named "vertical shades" (sharp). + static const IconData vertical_shades_sharp = IconData(0xf077a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vertical_shades</i> — material icon named "vertical shades" (round). + static const IconData vertical_shades_rounded = IconData(0xf082a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vertical_shades</i> — material icon named "vertical shades" (outlined). + static const IconData vertical_shades_outlined = IconData(0xf0722, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vertical_shades_closed</i> — material icon named "vertical shades closed". + static const IconData vertical_shades_closed = IconData(0xf07d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vertical_shades_closed</i> — material icon named "vertical shades closed" (sharp). + static const IconData vertical_shades_closed_sharp = IconData(0xf0779, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vertical_shades_closed</i> — material icon named "vertical shades closed" (round). + static const IconData vertical_shades_closed_rounded = IconData(0xf0829, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vertical_shades_closed</i> — material icon named "vertical shades closed" (outlined). + static const IconData vertical_shades_closed_outlined = IconData(0xf0721, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vertical_split</i> — material icon named "vertical split". + static const IconData vertical_split = IconData(0xe69f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vertical_split</i> — material icon named "vertical split" (sharp). + static const IconData vertical_split_sharp = IconData(0xed95, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vertical_split</i> — material icon named "vertical split" (round). + static const IconData vertical_split_rounded = IconData(0xf0274, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vertical_split</i> — material icon named "vertical split" (outlined). + static const IconData vertical_split_outlined = IconData(0xf482, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vibration</i> — material icon named "vibration". + static const IconData vibration = IconData(0xe6a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vibration</i> — material icon named "vibration" (sharp). + static const IconData vibration_sharp = IconData(0xed96, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vibration</i> — material icon named "vibration" (round). + static const IconData vibration_rounded = IconData(0xf0275, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vibration</i> — material icon named "vibration" (outlined). + static const IconData vibration_outlined = IconData(0xf483, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">video_call</i> — material icon named "video call". + static const IconData video_call = IconData(0xe6a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">video_call</i> — material icon named "video call" (sharp). + static const IconData video_call_sharp = IconData(0xed97, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">video_call</i> — material icon named "video call" (round). + static const IconData video_call_rounded = IconData(0xf0276, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">video_call</i> — material icon named "video call" (outlined). + static const IconData video_call_outlined = IconData(0xf484, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">video_camera_back</i> — material icon named "video camera back". + static const IconData video_camera_back = IconData(0xe6a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">video_camera_back</i> — material icon named "video camera back" (sharp). + static const IconData video_camera_back_sharp = IconData(0xed98, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">video_camera_back</i> — material icon named "video camera back" (round). + static const IconData video_camera_back_rounded = IconData(0xf0277, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">video_camera_back</i> — material icon named "video camera back" (outlined). + static const IconData video_camera_back_outlined = IconData(0xf485, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">video_camera_front</i> — material icon named "video camera front". + static const IconData video_camera_front = IconData(0xe6a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">video_camera_front</i> — material icon named "video camera front" (sharp). + static const IconData video_camera_front_sharp = IconData(0xed99, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">video_camera_front</i> — material icon named "video camera front" (round). + static const IconData video_camera_front_rounded = IconData(0xf0278, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">video_camera_front</i> — material icon named "video camera front" (outlined). + static const IconData video_camera_front_outlined = IconData(0xf486, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">video_chat</i> — material icon named "video chat". + static const IconData video_chat = IconData(0xf087b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">video_chat</i> — material icon named "video chat" (sharp). + static const IconData video_chat_sharp = IconData(0xf084f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">video_chat</i> — material icon named "video chat" (round). + static const IconData video_chat_rounded = IconData(0xf0898, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">video_chat</i> — material icon named "video chat" (outlined). + static const IconData video_chat_outlined = IconData(0xf08b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">video_collection</i> — material icon named "video collection". + static const IconData video_collection = IconData(0xe6a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">video_collection</i> — material icon named "video collection" (sharp). + static const IconData video_collection_sharp = IconData(0xed9b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">video_collection</i> — material icon named "video collection" (round). + static const IconData video_collection_rounded = IconData(0xf027a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">video_collection</i> — material icon named "video collection" (outlined). + static const IconData video_collection_outlined = IconData(0xf488, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">video_file</i> — material icon named "video file". + static const IconData video_file = IconData(0xf0598, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">video_file</i> — material icon named "video file" (sharp). + static const IconData video_file_sharp = IconData(0xf049e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">video_file</i> — material icon named "video file" (round). + static const IconData video_file_rounded = IconData(0xf03ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">video_file</i> — material icon named "video file" (outlined). + static const IconData video_file_outlined = IconData(0xf068c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">video_label</i> — material icon named "video label". + static const IconData video_label = IconData(0xe6a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">video_label</i> — material icon named "video label" (sharp). + static const IconData video_label_sharp = IconData(0xed9a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">video_label</i> — material icon named "video label" (round). + static const IconData video_label_rounded = IconData(0xf0279, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">video_label</i> — material icon named "video label" (outlined). + static const IconData video_label_outlined = IconData(0xf487, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">video_library</i> — material icon named "video library". + static const IconData video_library = IconData(0xe6a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">video_library</i> — material icon named "video library" (sharp). + static const IconData video_library_sharp = IconData(0xed9b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">video_library</i> — material icon named "video library" (round). + static const IconData video_library_rounded = IconData(0xf027a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">video_library</i> — material icon named "video library" (outlined). + static const IconData video_library_outlined = IconData(0xf488, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">video_settings</i> — material icon named "video settings". + static const IconData video_settings = IconData(0xe6a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">video_settings</i> — material icon named "video settings" (sharp). + static const IconData video_settings_sharp = IconData(0xed9c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">video_settings</i> — material icon named "video settings" (round). + static const IconData video_settings_rounded = IconData(0xf027b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">video_settings</i> — material icon named "video settings" (outlined). + static const IconData video_settings_outlined = IconData(0xf489, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">video_stable</i> — material icon named "video stable". + static const IconData video_stable = IconData(0xe6a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">video_stable</i> — material icon named "video stable" (sharp). + static const IconData video_stable_sharp = IconData(0xed9d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">video_stable</i> — material icon named "video stable" (round). + static const IconData video_stable_rounded = IconData(0xf027c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">video_stable</i> — material icon named "video stable" (outlined). + static const IconData video_stable_outlined = IconData(0xf48a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">videocam</i> — material icon named "videocam". + static const IconData videocam = IconData(0xe6a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">videocam</i> — material icon named "videocam" (sharp). + static const IconData videocam_sharp = IconData(0xed9f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">videocam</i> — material icon named "videocam" (round). + static const IconData videocam_rounded = IconData(0xf027e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">videocam</i> — material icon named "videocam" (outlined). + static const IconData videocam_outlined = IconData(0xf48c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">videocam_off</i> — material icon named "videocam off". + static const IconData videocam_off = IconData(0xe6a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">videocam_off</i> — material icon named "videocam off" (sharp). + static const IconData videocam_off_sharp = IconData(0xed9e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">videocam_off</i> — material icon named "videocam off" (round). + static const IconData videocam_off_rounded = IconData(0xf027d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">videocam_off</i> — material icon named "videocam off" (outlined). + static const IconData videocam_off_outlined = IconData(0xf48b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">videogame_asset</i> — material icon named "videogame asset". + static const IconData videogame_asset = IconData(0xe6aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">videogame_asset</i> — material icon named "videogame asset" (sharp). + static const IconData videogame_asset_sharp = IconData(0xeda1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">videogame_asset</i> — material icon named "videogame asset" (round). + static const IconData videogame_asset_rounded = IconData(0xf0280, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">videogame_asset</i> — material icon named "videogame asset" (outlined). + static const IconData videogame_asset_outlined = IconData(0xf48e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">videogame_asset_off</i> — material icon named "videogame asset off". + static const IconData videogame_asset_off = IconData(0xe6ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">videogame_asset_off</i> — material icon named "videogame asset off" (sharp). + static const IconData videogame_asset_off_sharp = IconData(0xeda0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">videogame_asset_off</i> — material icon named "videogame asset off" (round). + static const IconData videogame_asset_off_rounded = IconData(0xf027f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">videogame_asset_off</i> — material icon named "videogame asset off" (outlined). + static const IconData videogame_asset_off_outlined = IconData(0xf48d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_agenda</i> — material icon named "view agenda". + static const IconData view_agenda = IconData(0xe6ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_agenda</i> — material icon named "view agenda" (sharp). + static const IconData view_agenda_sharp = IconData(0xeda2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_agenda</i> — material icon named "view agenda" (round). + static const IconData view_agenda_rounded = IconData(0xf0281, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_agenda</i> — material icon named "view agenda" (outlined). + static const IconData view_agenda_outlined = IconData(0xf48f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_array</i> — material icon named "view array". + static const IconData view_array = IconData(0xe6ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_array</i> — material icon named "view array" (sharp). + static const IconData view_array_sharp = IconData(0xeda3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_array</i> — material icon named "view array" (round). + static const IconData view_array_rounded = IconData(0xf0282, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_array</i> — material icon named "view array" (outlined). + static const IconData view_array_outlined = IconData(0xf490, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_carousel</i> — material icon named "view carousel". + static const IconData view_carousel = IconData(0xe6ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_carousel</i> — material icon named "view carousel" (sharp). + static const IconData view_carousel_sharp = IconData(0xeda4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_carousel</i> — material icon named "view carousel" (round). + static const IconData view_carousel_rounded = IconData(0xf0283, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_carousel</i> — material icon named "view carousel" (outlined). + static const IconData view_carousel_outlined = IconData(0xf491, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_column</i> — material icon named "view column". + static const IconData view_column = IconData(0xe6af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_column</i> — material icon named "view column" (sharp). + static const IconData view_column_sharp = IconData(0xeda5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_column</i> — material icon named "view column" (round). + static const IconData view_column_rounded = IconData(0xf0284, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_column</i> — material icon named "view column" (outlined). + static const IconData view_column_outlined = IconData(0xf492, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_comfortable</i> — material icon named "view comfortable". + static const IconData view_comfortable = IconData(0xe6b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_comfortable</i> — material icon named "view comfortable" (sharp). + static const IconData view_comfortable_sharp = IconData(0xeda6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_comfortable</i> — material icon named "view comfortable" (round). + static const IconData view_comfortable_rounded = IconData(0xf0285, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_comfortable</i> — material icon named "view comfortable" (outlined). + static const IconData view_comfortable_outlined = IconData(0xf493, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_comfy</i> — material icon named "view comfy". + static const IconData view_comfy = IconData(0xe6b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_comfy</i> — material icon named "view comfy" (sharp). + static const IconData view_comfy_sharp = IconData(0xeda6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_comfy</i> — material icon named "view comfy" (round). + static const IconData view_comfy_rounded = IconData(0xf0285, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_comfy</i> — material icon named "view comfy" (outlined). + static const IconData view_comfy_outlined = IconData(0xf493, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_comfy_alt</i> — material icon named "view comfy alt". + static const IconData view_comfy_alt = IconData(0xf0599, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_comfy_alt</i> — material icon named "view comfy alt" (sharp). + static const IconData view_comfy_alt_sharp = IconData(0xf049f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_comfy_alt</i> — material icon named "view comfy alt" (round). + static const IconData view_comfy_alt_rounded = IconData(0xf03ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_comfy_alt</i> — material icon named "view comfy alt" (outlined). + static const IconData view_comfy_alt_outlined = IconData(0xf068d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_compact</i> — material icon named "view compact". + static const IconData view_compact = IconData(0xe6b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_compact</i> — material icon named "view compact" (sharp). + static const IconData view_compact_sharp = IconData(0xeda7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_compact</i> — material icon named "view compact" (round). + static const IconData view_compact_rounded = IconData(0xf0286, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_compact</i> — material icon named "view compact" (outlined). + static const IconData view_compact_outlined = IconData(0xf494, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_compact_alt</i> — material icon named "view compact alt". + static const IconData view_compact_alt = IconData(0xf059a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_compact_alt</i> — material icon named "view compact alt" (sharp). + static const IconData view_compact_alt_sharp = IconData(0xf04a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_compact_alt</i> — material icon named "view compact alt" (round). + static const IconData view_compact_alt_rounded = IconData(0xf03ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_compact_alt</i> — material icon named "view compact alt" (outlined). + static const IconData view_compact_alt_outlined = IconData(0xf068e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_cozy</i> — material icon named "view cozy". + static const IconData view_cozy = IconData(0xf059b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_cozy</i> — material icon named "view cozy" (sharp). + static const IconData view_cozy_sharp = IconData(0xf04a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_cozy</i> — material icon named "view cozy" (round). + static const IconData view_cozy_rounded = IconData(0xf03ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_cozy</i> — material icon named "view cozy" (outlined). + static const IconData view_cozy_outlined = IconData(0xf068f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_day</i> — material icon named "view day". + static const IconData view_day = IconData(0xe6b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_day</i> — material icon named "view day" (sharp). + static const IconData view_day_sharp = IconData(0xeda8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_day</i> — material icon named "view day" (round). + static const IconData view_day_rounded = IconData(0xf0287, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_day</i> — material icon named "view day" (outlined). + static const IconData view_day_outlined = IconData(0xf495, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_headline</i> — material icon named "view headline". + static const IconData view_headline = IconData(0xe6b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_headline</i> — material icon named "view headline" (sharp). + static const IconData view_headline_sharp = IconData(0xeda9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_headline</i> — material icon named "view headline" (round). + static const IconData view_headline_rounded = IconData(0xf0288, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_headline</i> — material icon named "view headline" (outlined). + static const IconData view_headline_outlined = IconData(0xf496, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_in_ar</i> — material icon named "view in ar". + static const IconData view_in_ar = IconData(0xe6b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_in_ar</i> — material icon named "view in ar" (sharp). + static const IconData view_in_ar_sharp = IconData(0xedaa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_in_ar</i> — material icon named "view in ar" (round). + static const IconData view_in_ar_rounded = IconData(0xf0289, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_in_ar</i> — material icon named "view in ar" (outlined). + static const IconData view_in_ar_outlined = IconData(0xf497, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_kanban</i> — material icon named "view kanban". + static const IconData view_kanban = IconData(0xf059c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_kanban</i> — material icon named "view kanban" (sharp). + static const IconData view_kanban_sharp = IconData(0xf04a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_kanban</i> — material icon named "view kanban" (round). + static const IconData view_kanban_rounded = IconData(0xf03af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_kanban</i> — material icon named "view kanban" (outlined). + static const IconData view_kanban_outlined = IconData(0xf0690, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_list</i> — material icon named "view list". + static const IconData view_list = IconData(0xe6b5, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">view_list</i> — material icon named "view list" (sharp). + static const IconData view_list_sharp = IconData(0xedab, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">view_list</i> — material icon named "view list" (round). + static const IconData view_list_rounded = IconData(0xf028a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">view_list</i> — material icon named "view list" (outlined). + static const IconData view_list_outlined = IconData(0xf498, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">view_module</i> — material icon named "view module". + static const IconData view_module = IconData(0xe6b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_module</i> — material icon named "view module" (sharp). + static const IconData view_module_sharp = IconData(0xedac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_module</i> — material icon named "view module" (round). + static const IconData view_module_rounded = IconData(0xf028b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_module</i> — material icon named "view module" (outlined). + static const IconData view_module_outlined = IconData(0xf499, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_quilt</i> — material icon named "view quilt". + static const IconData view_quilt = IconData(0xe6b7, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">view_quilt</i> — material icon named "view quilt" (sharp). + static const IconData view_quilt_sharp = IconData(0xedad, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">view_quilt</i> — material icon named "view quilt" (round). + static const IconData view_quilt_rounded = IconData(0xf028c, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">view_quilt</i> — material icon named "view quilt" (outlined). + static const IconData view_quilt_outlined = IconData(0xf49a, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">view_sidebar</i> — material icon named "view sidebar". + static const IconData view_sidebar = IconData(0xe6b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_sidebar</i> — material icon named "view sidebar" (sharp). + static const IconData view_sidebar_sharp = IconData(0xedae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_sidebar</i> — material icon named "view sidebar" (round). + static const IconData view_sidebar_rounded = IconData(0xf028d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_sidebar</i> — material icon named "view sidebar" (outlined). + static const IconData view_sidebar_outlined = IconData(0xf49b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_stream</i> — material icon named "view stream". + static const IconData view_stream = IconData(0xe6b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_stream</i> — material icon named "view stream" (sharp). + static const IconData view_stream_sharp = IconData(0xedaf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_stream</i> — material icon named "view stream" (round). + static const IconData view_stream_rounded = IconData(0xf028e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_stream</i> — material icon named "view stream" (outlined). + static const IconData view_stream_outlined = IconData(0xf49c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_timeline</i> — material icon named "view timeline". + static const IconData view_timeline = IconData(0xf059d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_timeline</i> — material icon named "view timeline" (sharp). + static const IconData view_timeline_sharp = IconData(0xf04a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_timeline</i> — material icon named "view timeline" (round). + static const IconData view_timeline_rounded = IconData(0xf03b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_timeline</i> — material icon named "view timeline" (outlined). + static const IconData view_timeline_outlined = IconData(0xf0691, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">view_week</i> — material icon named "view week". + static const IconData view_week = IconData(0xe6ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">view_week</i> — material icon named "view week" (sharp). + static const IconData view_week_sharp = IconData(0xedb0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">view_week</i> — material icon named "view week" (round). + static const IconData view_week_rounded = IconData(0xf028f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">view_week</i> — material icon named "view week" (outlined). + static const IconData view_week_outlined = IconData(0xf49d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vignette</i> — material icon named "vignette". + static const IconData vignette = IconData(0xe6bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vignette</i> — material icon named "vignette" (sharp). + static const IconData vignette_sharp = IconData(0xedb1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vignette</i> — material icon named "vignette" (round). + static const IconData vignette_rounded = IconData(0xf0290, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vignette</i> — material icon named "vignette" (outlined). + static const IconData vignette_outlined = IconData(0xf49e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">villa</i> — material icon named "villa". + static const IconData villa = IconData(0xe6bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">villa</i> — material icon named "villa" (sharp). + static const IconData villa_sharp = IconData(0xedb2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">villa</i> — material icon named "villa" (round). + static const IconData villa_rounded = IconData(0xf0291, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">villa</i> — material icon named "villa" (outlined). + static const IconData villa_outlined = IconData(0xf49f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">visibility</i> — material icon named "visibility". + static const IconData visibility = IconData(0xe6bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">visibility</i> — material icon named "visibility" (sharp). + static const IconData visibility_sharp = IconData(0xedb4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">visibility</i> — material icon named "visibility" (round). + static const IconData visibility_rounded = IconData(0xf0293, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">visibility</i> — material icon named "visibility" (outlined). + static const IconData visibility_outlined = IconData(0xf4a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">visibility_off</i> — material icon named "visibility off". + static const IconData visibility_off = IconData(0xe6be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">visibility_off</i> — material icon named "visibility off" (sharp). + static const IconData visibility_off_sharp = IconData(0xedb3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">visibility_off</i> — material icon named "visibility off" (round). + static const IconData visibility_off_rounded = IconData(0xf0292, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">visibility_off</i> — material icon named "visibility off" (outlined). + static const IconData visibility_off_outlined = IconData(0xf4a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">voice_chat</i> — material icon named "voice chat". + static const IconData voice_chat = IconData(0xe6bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">voice_chat</i> — material icon named "voice chat" (sharp). + static const IconData voice_chat_sharp = IconData(0xedb5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">voice_chat</i> — material icon named "voice chat" (round). + static const IconData voice_chat_rounded = IconData(0xf0294, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">voice_chat</i> — material icon named "voice chat" (outlined). + static const IconData voice_chat_outlined = IconData(0xf4a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">voice_over_off</i> — material icon named "voice over off". + static const IconData voice_over_off = IconData(0xe6c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">voice_over_off</i> — material icon named "voice over off" (sharp). + static const IconData voice_over_off_sharp = IconData(0xedb6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">voice_over_off</i> — material icon named "voice over off" (round). + static const IconData voice_over_off_rounded = IconData(0xf0295, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">voice_over_off</i> — material icon named "voice over off" (outlined). + static const IconData voice_over_off_outlined = IconData(0xf4a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">voicemail</i> — material icon named "voicemail". + static const IconData voicemail = IconData(0xe6c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">voicemail</i> — material icon named "voicemail" (sharp). + static const IconData voicemail_sharp = IconData(0xedb7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">voicemail</i> — material icon named "voicemail" (round). + static const IconData voicemail_rounded = IconData(0xf0296, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">voicemail</i> — material icon named "voicemail" (outlined). + static const IconData voicemail_outlined = IconData(0xf4a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">volcano</i> — material icon named "volcano". + static const IconData volcano = IconData(0xf07d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">volcano</i> — material icon named "volcano" (sharp). + static const IconData volcano_sharp = IconData(0xf077b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">volcano</i> — material icon named "volcano" (round). + static const IconData volcano_rounded = IconData(0xf082b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">volcano</i> — material icon named "volcano" (outlined). + static const IconData volcano_outlined = IconData(0xf0723, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">volume_down</i> — material icon named "volume down". + static const IconData volume_down = IconData(0xe6c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">volume_down</i> — material icon named "volume down" (sharp). + static const IconData volume_down_sharp = IconData(0xedb8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">volume_down</i> — material icon named "volume down" (round). + static const IconData volume_down_rounded = IconData(0xf0297, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">volume_down</i> — material icon named "volume down" (outlined). + static const IconData volume_down_outlined = IconData(0xf4a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">volume_down_alt</i> — material icon named "volume down alt". + static const IconData volume_down_alt = IconData(0xf059e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">volume_mute</i> — material icon named "volume mute". + static const IconData volume_mute = IconData(0xe6c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">volume_mute</i> — material icon named "volume mute" (sharp). + static const IconData volume_mute_sharp = IconData(0xedb9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">volume_mute</i> — material icon named "volume mute" (round). + static const IconData volume_mute_rounded = IconData(0xf0298, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">volume_mute</i> — material icon named "volume mute" (outlined). + static const IconData volume_mute_outlined = IconData(0xf4a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">volume_off</i> — material icon named "volume off". + static const IconData volume_off = IconData(0xe6c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">volume_off</i> — material icon named "volume off" (sharp). + static const IconData volume_off_sharp = IconData(0xedba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">volume_off</i> — material icon named "volume off" (round). + static const IconData volume_off_rounded = IconData(0xf0299, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">volume_off</i> — material icon named "volume off" (outlined). + static const IconData volume_off_outlined = IconData(0xf4a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">volume_up</i> — material icon named "volume up". + static const IconData volume_up = IconData(0xe6c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">volume_up</i> — material icon named "volume up" (sharp). + static const IconData volume_up_sharp = IconData(0xedbb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">volume_up</i> — material icon named "volume up" (round). + static const IconData volume_up_rounded = IconData(0xf029a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">volume_up</i> — material icon named "volume up" (outlined). + static const IconData volume_up_outlined = IconData(0xf4a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">volunteer_activism</i> — material icon named "volunteer activism". + static const IconData volunteer_activism = IconData(0xe6c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">volunteer_activism</i> — material icon named "volunteer activism" (sharp). + static const IconData volunteer_activism_sharp = IconData(0xedbc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">volunteer_activism</i> — material icon named "volunteer activism" (round). + static const IconData volunteer_activism_rounded = IconData(0xf029b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">volunteer_activism</i> — material icon named "volunteer activism" (outlined). + static const IconData volunteer_activism_outlined = IconData(0xf4a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vpn_key</i> — material icon named "vpn key". + static const IconData vpn_key = IconData(0xe6c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vpn_key</i> — material icon named "vpn key" (sharp). + static const IconData vpn_key_sharp = IconData(0xedbd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vpn_key</i> — material icon named "vpn key" (round). + static const IconData vpn_key_rounded = IconData(0xf029c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vpn_key</i> — material icon named "vpn key" (outlined). + static const IconData vpn_key_outlined = IconData(0xf4aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vpn_key_off</i> — material icon named "vpn key off". + static const IconData vpn_key_off = IconData(0xf059f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vpn_key_off</i> — material icon named "vpn key off" (sharp). + static const IconData vpn_key_off_sharp = IconData(0xf04a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vpn_key_off</i> — material icon named "vpn key off" (round). + static const IconData vpn_key_off_rounded = IconData(0xf03b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vpn_key_off</i> — material icon named "vpn key off" (outlined). + static const IconData vpn_key_off_outlined = IconData(0xf0692, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vpn_lock</i> — material icon named "vpn lock". + static const IconData vpn_lock = IconData(0xe6c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vpn_lock</i> — material icon named "vpn lock" (sharp). + static const IconData vpn_lock_sharp = IconData(0xedbe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vpn_lock</i> — material icon named "vpn lock" (round). + static const IconData vpn_lock_rounded = IconData(0xf029d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vpn_lock</i> — material icon named "vpn lock" (outlined). + static const IconData vpn_lock_outlined = IconData(0xf4ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">vrpano</i> — material icon named "vrpano". + static const IconData vrpano = IconData(0xe6c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">vrpano</i> — material icon named "vrpano" (sharp). + static const IconData vrpano_sharp = IconData(0xedbf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">vrpano</i> — material icon named "vrpano" (round). + static const IconData vrpano_rounded = IconData(0xf029e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">vrpano</i> — material icon named "vrpano" (outlined). + static const IconData vrpano_outlined = IconData(0xf4ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wallet</i> — material icon named "wallet". + static const IconData wallet = IconData(0xf07d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wallet</i> — material icon named "wallet" (sharp). + static const IconData wallet_sharp = IconData(0xf077c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wallet</i> — material icon named "wallet" (round). + static const IconData wallet_rounded = IconData(0xf082c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wallet</i> — material icon named "wallet" (outlined). + static const IconData wallet_outlined = IconData(0xf0724, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wallet_giftcard</i> — material icon named "wallet giftcard". + static const IconData wallet_giftcard = IconData(0xe13e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wallet_giftcard</i> — material icon named "wallet giftcard" (sharp). + static const IconData wallet_giftcard_sharp = IconData(0xe83b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wallet_giftcard</i> — material icon named "wallet giftcard" (round). + static const IconData wallet_giftcard_rounded = IconData(0xf61a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wallet_giftcard</i> — material icon named "wallet giftcard" (outlined). + static const IconData wallet_giftcard_outlined = IconData(0xef2d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wallet_membership</i> — material icon named "wallet membership". + static const IconData wallet_membership = IconData(0xe13f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wallet_membership</i> — material icon named "wallet membership" (sharp). + static const IconData wallet_membership_sharp = IconData(0xe83c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wallet_membership</i> — material icon named "wallet membership" (round). + static const IconData wallet_membership_rounded = IconData(0xf61b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wallet_membership</i> — material icon named "wallet membership" (outlined). + static const IconData wallet_membership_outlined = IconData(0xef2e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wallet_travel</i> — material icon named "wallet travel". + static const IconData wallet_travel = IconData(0xe140, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wallet_travel</i> — material icon named "wallet travel" (sharp). + static const IconData wallet_travel_sharp = IconData(0xe83d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wallet_travel</i> — material icon named "wallet travel" (round). + static const IconData wallet_travel_rounded = IconData(0xf61c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wallet_travel</i> — material icon named "wallet travel" (outlined). + static const IconData wallet_travel_outlined = IconData(0xef2f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wallpaper</i> — material icon named "wallpaper". + static const IconData wallpaper = IconData(0xe6ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wallpaper</i> — material icon named "wallpaper" (sharp). + static const IconData wallpaper_sharp = IconData(0xedc0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wallpaper</i> — material icon named "wallpaper" (round). + static const IconData wallpaper_rounded = IconData(0xf029f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wallpaper</i> — material icon named "wallpaper" (outlined). + static const IconData wallpaper_outlined = IconData(0xf4ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">warehouse</i> — material icon named "warehouse". + static const IconData warehouse = IconData(0xf05a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">warehouse</i> — material icon named "warehouse" (sharp). + static const IconData warehouse_sharp = IconData(0xf04a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">warehouse</i> — material icon named "warehouse" (round). + static const IconData warehouse_rounded = IconData(0xf03b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">warehouse</i> — material icon named "warehouse" (outlined). + static const IconData warehouse_outlined = IconData(0xf0693, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">warning</i> — material icon named "warning". + static const IconData warning = IconData(0xe6cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">warning</i> — material icon named "warning" (sharp). + static const IconData warning_sharp = IconData(0xedc2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">warning</i> — material icon named "warning" (round). + static const IconData warning_rounded = IconData(0xf02a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">warning</i> — material icon named "warning" (outlined). + static const IconData warning_outlined = IconData(0xf4af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">warning_amber</i> — material icon named "warning amber". + static const IconData warning_amber = IconData(0xe6cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">warning_amber</i> — material icon named "warning amber" (sharp). + static const IconData warning_amber_sharp = IconData(0xedc1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">warning_amber</i> — material icon named "warning amber" (round). + static const IconData warning_amber_rounded = IconData(0xf02a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">warning_amber</i> — material icon named "warning amber" (outlined). + static const IconData warning_amber_outlined = IconData(0xf4ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wash</i> — material icon named "wash". + static const IconData wash = IconData(0xe6cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wash</i> — material icon named "wash" (sharp). + static const IconData wash_sharp = IconData(0xedc3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wash</i> — material icon named "wash" (round). + static const IconData wash_rounded = IconData(0xf02a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wash</i> — material icon named "wash" (outlined). + static const IconData wash_outlined = IconData(0xf4b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">watch</i> — material icon named "watch". + static const IconData watch = IconData(0xe6ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">watch</i> — material icon named "watch" (sharp). + static const IconData watch_sharp = IconData(0xedc5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">watch</i> — material icon named "watch" (round). + static const IconData watch_rounded = IconData(0xf02a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">watch</i> — material icon named "watch" (outlined). + static const IconData watch_outlined = IconData(0xf4b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">watch_later</i> — material icon named "watch later". + static const IconData watch_later = IconData(0xe6cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">watch_later</i> — material icon named "watch later" (sharp). + static const IconData watch_later_sharp = IconData(0xedc4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">watch_later</i> — material icon named "watch later" (round). + static const IconData watch_later_rounded = IconData(0xf02a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">watch_later</i> — material icon named "watch later" (outlined). + static const IconData watch_later_outlined = IconData(0xf4b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">watch_off</i> — material icon named "watch off". + static const IconData watch_off = IconData(0xf05a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">watch_off</i> — material icon named "watch off" (sharp). + static const IconData watch_off_sharp = IconData(0xf04a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">watch_off</i> — material icon named "watch off" (round). + static const IconData watch_off_rounded = IconData(0xf03b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">watch_off</i> — material icon named "watch off" (outlined). + static const IconData watch_off_outlined = IconData(0xf0694, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">water</i> — material icon named "water". + static const IconData water = IconData(0xe6d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">water</i> — material icon named "water" (sharp). + static const IconData water_sharp = IconData(0xedc7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">water</i> — material icon named "water" (round). + static const IconData water_rounded = IconData(0xf02a6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">water</i> — material icon named "water" (outlined). + static const IconData water_outlined = IconData(0xf4b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">water_damage</i> — material icon named "water damage". + static const IconData water_damage = IconData(0xe6d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">water_damage</i> — material icon named "water damage" (sharp). + static const IconData water_damage_sharp = IconData(0xedc6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">water_damage</i> — material icon named "water damage" (round). + static const IconData water_damage_rounded = IconData(0xf02a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">water_damage</i> — material icon named "water damage" (outlined). + static const IconData water_damage_outlined = IconData(0xf4b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">water_drop</i> — material icon named "water drop". + static const IconData water_drop = IconData(0xf05a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">water_drop</i> — material icon named "water drop" (sharp). + static const IconData water_drop_sharp = IconData(0xf04a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">water_drop</i> — material icon named "water drop" (round). + static const IconData water_drop_rounded = IconData(0xf03b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">water_drop</i> — material icon named "water drop" (outlined). + static const IconData water_drop_outlined = IconData(0xf0695, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">waterfall_chart</i> — material icon named "waterfall chart". + static const IconData waterfall_chart = IconData(0xe6d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">waterfall_chart</i> — material icon named "waterfall chart" (sharp). + static const IconData waterfall_chart_sharp = IconData(0xedc8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">waterfall_chart</i> — material icon named "waterfall chart" (round). + static const IconData waterfall_chart_rounded = IconData(0xf02a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">waterfall_chart</i> — material icon named "waterfall chart" (outlined). + static const IconData waterfall_chart_outlined = IconData(0xf4b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">waves</i> — material icon named "waves". + static const IconData waves = IconData(0xe6d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">waves</i> — material icon named "waves" (sharp). + static const IconData waves_sharp = IconData(0xedc9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">waves</i> — material icon named "waves" (round). + static const IconData waves_rounded = IconData(0xf02a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">waves</i> — material icon named "waves" (outlined). + static const IconData waves_outlined = IconData(0xf4b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">waving_hand</i> — material icon named "waving hand". + static const IconData waving_hand = IconData(0xf05a3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">waving_hand</i> — material icon named "waving hand" (sharp). + static const IconData waving_hand_sharp = IconData(0xf04a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">waving_hand</i> — material icon named "waving hand" (round). + static const IconData waving_hand_rounded = IconData(0xf03b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">waving_hand</i> — material icon named "waving hand" (outlined). + static const IconData waving_hand_outlined = IconData(0xf0696, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wb_auto</i> — material icon named "wb auto". + static const IconData wb_auto = IconData(0xe6d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wb_auto</i> — material icon named "wb auto" (sharp). + static const IconData wb_auto_sharp = IconData(0xedca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wb_auto</i> — material icon named "wb auto" (round). + static const IconData wb_auto_rounded = IconData(0xf02a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wb_auto</i> — material icon named "wb auto" (outlined). + static const IconData wb_auto_outlined = IconData(0xf4b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wb_cloudy</i> — material icon named "wb cloudy". + static const IconData wb_cloudy = IconData(0xe6d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wb_cloudy</i> — material icon named "wb cloudy" (sharp). + static const IconData wb_cloudy_sharp = IconData(0xedcb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wb_cloudy</i> — material icon named "wb cloudy" (round). + static const IconData wb_cloudy_rounded = IconData(0xf02aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wb_cloudy</i> — material icon named "wb cloudy" (outlined). + static const IconData wb_cloudy_outlined = IconData(0xf4b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wb_incandescent</i> — material icon named "wb incandescent". + static const IconData wb_incandescent = IconData(0xe6d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wb_incandescent</i> — material icon named "wb incandescent" (sharp). + static const IconData wb_incandescent_sharp = IconData(0xedcc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wb_incandescent</i> — material icon named "wb incandescent" (round). + static const IconData wb_incandescent_rounded = IconData(0xf02ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wb_incandescent</i> — material icon named "wb incandescent" (outlined). + static const IconData wb_incandescent_outlined = IconData(0xf4b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wb_iridescent</i> — material icon named "wb iridescent". + static const IconData wb_iridescent = IconData(0xe6d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wb_iridescent</i> — material icon named "wb iridescent" (sharp). + static const IconData wb_iridescent_sharp = IconData(0xedcd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wb_iridescent</i> — material icon named "wb iridescent" (round). + static const IconData wb_iridescent_rounded = IconData(0xf02ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wb_iridescent</i> — material icon named "wb iridescent" (outlined). + static const IconData wb_iridescent_outlined = IconData(0xf4ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wb_shade</i> — material icon named "wb shade". + static const IconData wb_shade = IconData(0xe6d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wb_shade</i> — material icon named "wb shade" (sharp). + static const IconData wb_shade_sharp = IconData(0xedce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wb_shade</i> — material icon named "wb shade" (round). + static const IconData wb_shade_rounded = IconData(0xf02ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wb_shade</i> — material icon named "wb shade" (outlined). + static const IconData wb_shade_outlined = IconData(0xf4bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wb_sunny</i> — material icon named "wb sunny". + static const IconData wb_sunny = IconData(0xe6d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wb_sunny</i> — material icon named "wb sunny" (sharp). + static const IconData wb_sunny_sharp = IconData(0xedcf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wb_sunny</i> — material icon named "wb sunny" (round). + static const IconData wb_sunny_rounded = IconData(0xf02ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wb_sunny</i> — material icon named "wb sunny" (outlined). + static const IconData wb_sunny_outlined = IconData(0xf4bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wb_twighlight</i> — material icon named "wb twighlight". + static const IconData wb_twighlight = IconData(0xe6da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wb_twilight</i> — material icon named "wb twilight". + static const IconData wb_twilight = IconData(0xe6db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wb_twilight</i> — material icon named "wb twilight" (sharp). + static const IconData wb_twilight_sharp = IconData(0xedd0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wb_twilight</i> — material icon named "wb twilight" (round). + static const IconData wb_twilight_rounded = IconData(0xf02af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wb_twilight</i> — material icon named "wb twilight" (outlined). + static const IconData wb_twilight_outlined = IconData(0xf4bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wc</i> — material icon named "wc". + static const IconData wc = IconData(0xe6dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wc</i> — material icon named "wc" (sharp). + static const IconData wc_sharp = IconData(0xedd1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wc</i> — material icon named "wc" (round). + static const IconData wc_rounded = IconData(0xf02b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wc</i> — material icon named "wc" (outlined). + static const IconData wc_outlined = IconData(0xf4be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">web</i> — material icon named "web". + static const IconData web = IconData(0xe6dd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">web</i> — material icon named "web" (sharp). + static const IconData web_sharp = IconData(0xedd4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">web</i> — material icon named "web" (round). + static const IconData web_rounded = IconData(0xf02b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">web</i> — material icon named "web" (outlined). + static const IconData web_outlined = IconData(0xf4c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">web_asset</i> — material icon named "web asset". + static const IconData web_asset = IconData(0xe6de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">web_asset</i> — material icon named "web asset" (sharp). + static const IconData web_asset_sharp = IconData(0xedd3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">web_asset</i> — material icon named "web asset" (round). + static const IconData web_asset_rounded = IconData(0xf02b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">web_asset</i> — material icon named "web asset" (outlined). + static const IconData web_asset_outlined = IconData(0xf4c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">web_asset_off</i> — material icon named "web asset off". + static const IconData web_asset_off = IconData(0xe6df, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">web_asset_off</i> — material icon named "web asset off" (sharp). + static const IconData web_asset_off_sharp = IconData(0xedd2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">web_asset_off</i> — material icon named "web asset off" (round). + static const IconData web_asset_off_rounded = IconData(0xf02b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">web_asset_off</i> — material icon named "web asset off" (outlined). + static const IconData web_asset_off_outlined = IconData(0xf4bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">web_stories</i> — material icon named "web stories". + static const IconData web_stories = IconData(0xe6e0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">web_stories</i> — material icon named "web stories" (sharp). + static const IconData web_stories_sharp = IconData(0xf0850, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">web_stories</i> — material icon named "web stories" (round). + static const IconData web_stories_rounded = IconData(0xf0899, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">web_stories</i> — material icon named "web stories" (outlined). + static const IconData web_stories_outlined = IconData(0xf08b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">webhook</i> — material icon named "webhook". + static const IconData webhook = IconData(0xf05a4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">webhook</i> — material icon named "webhook" (sharp). + static const IconData webhook_sharp = IconData(0xf04a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">webhook</i> — material icon named "webhook" (round). + static const IconData webhook_rounded = IconData(0xf03b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">webhook</i> — material icon named "webhook" (outlined). + static const IconData webhook_outlined = IconData(0xf0697, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wechat</i> — material icon named "wechat". + static const IconData wechat = IconData(0xf05a5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wechat</i> — material icon named "wechat" (sharp). + static const IconData wechat_sharp = IconData(0xf04aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wechat</i> — material icon named "wechat" (round). + static const IconData wechat_rounded = IconData(0xf03b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wechat</i> — material icon named "wechat" (outlined). + static const IconData wechat_outlined = IconData(0xf0698, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">weekend</i> — material icon named "weekend". + static const IconData weekend = IconData(0xe6e1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">weekend</i> — material icon named "weekend" (sharp). + static const IconData weekend_sharp = IconData(0xedd5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">weekend</i> — material icon named "weekend" (round). + static const IconData weekend_rounded = IconData(0xf02b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">weekend</i> — material icon named "weekend" (outlined). + static const IconData weekend_outlined = IconData(0xf4c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">west</i> — material icon named "west". + static const IconData west = IconData(0xe6e2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">west</i> — material icon named "west" (sharp). + static const IconData west_sharp = IconData(0xedd6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">west</i> — material icon named "west" (round). + static const IconData west_rounded = IconData(0xf02b5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">west</i> — material icon named "west" (outlined). + static const IconData west_outlined = IconData(0xf4c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">whatshot</i> — material icon named "whatshot". + static const IconData whatshot = IconData(0xe6e3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">whatshot</i> — material icon named "whatshot" (sharp). + static const IconData whatshot_sharp = IconData(0xedd7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">whatshot</i> — material icon named "whatshot" (round). + static const IconData whatshot_rounded = IconData(0xf02b6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">whatshot</i> — material icon named "whatshot" (outlined). + static const IconData whatshot_outlined = IconData(0xf4c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wheelchair_pickup</i> — material icon named "wheelchair pickup". + static const IconData wheelchair_pickup = IconData(0xe6e4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wheelchair_pickup</i> — material icon named "wheelchair pickup" (sharp). + static const IconData wheelchair_pickup_sharp = IconData(0xedd8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wheelchair_pickup</i> — material icon named "wheelchair pickup" (round). + static const IconData wheelchair_pickup_rounded = IconData(0xf02b7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wheelchair_pickup</i> — material icon named "wheelchair pickup" (outlined). + static const IconData wheelchair_pickup_outlined = IconData(0xf4c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">where_to_vote</i> — material icon named "where to vote". + static const IconData where_to_vote = IconData(0xe6e5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">where_to_vote</i> — material icon named "where to vote" (sharp). + static const IconData where_to_vote_sharp = IconData(0xedd9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">where_to_vote</i> — material icon named "where to vote" (round). + static const IconData where_to_vote_rounded = IconData(0xf02b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">where_to_vote</i> — material icon named "where to vote" (outlined). + static const IconData where_to_vote_outlined = IconData(0xf4c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">widgets</i> — material icon named "widgets". + static const IconData widgets = IconData(0xe6e6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">widgets</i> — material icon named "widgets" (sharp). + static const IconData widgets_sharp = IconData(0xedda, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">widgets</i> — material icon named "widgets" (round). + static const IconData widgets_rounded = IconData(0xf02b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">widgets</i> — material icon named "widgets" (outlined). + static const IconData widgets_outlined = IconData(0xf4c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">width_full</i> — material icon named "width full". + static const IconData width_full = IconData(0xf07d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">width_full</i> — material icon named "width full" (sharp). + static const IconData width_full_sharp = IconData(0xf077d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">width_full</i> — material icon named "width full" (round). + static const IconData width_full_rounded = IconData(0xf082d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">width_full</i> — material icon named "width full" (outlined). + static const IconData width_full_outlined = IconData(0xf0725, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">width_normal</i> — material icon named "width normal". + static const IconData width_normal = IconData(0xf07d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">width_normal</i> — material icon named "width normal" (sharp). + static const IconData width_normal_sharp = IconData(0xf077e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">width_normal</i> — material icon named "width normal" (round). + static const IconData width_normal_rounded = IconData(0xf082e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">width_normal</i> — material icon named "width normal" (outlined). + static const IconData width_normal_outlined = IconData(0xf0726, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">width_wide</i> — material icon named "width wide". + static const IconData width_wide = IconData(0xf07d7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">width_wide</i> — material icon named "width wide" (sharp). + static const IconData width_wide_sharp = IconData(0xf077f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">width_wide</i> — material icon named "width wide" (round). + static const IconData width_wide_rounded = IconData(0xf082f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">width_wide</i> — material icon named "width wide" (outlined). + static const IconData width_wide_outlined = IconData(0xf0727, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi</i> — material icon named "wifi". + static const IconData wifi = IconData(0xe6e7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi</i> — material icon named "wifi" (sharp). + static const IconData wifi_sharp = IconData(0xede0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi</i> — material icon named "wifi" (round). + static const IconData wifi_rounded = IconData(0xf02bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi</i> — material icon named "wifi" (outlined). + static const IconData wifi_outlined = IconData(0xf4cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_1_bar</i> — material icon named "wifi 1 bar". + static const IconData wifi_1_bar = IconData(0xf07d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_1_bar</i> — material icon named "wifi 1 bar" (sharp). + static const IconData wifi_1_bar_sharp = IconData(0xf0780, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_1_bar</i> — material icon named "wifi 1 bar" (round). + static const IconData wifi_1_bar_rounded = IconData(0xf0830, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_1_bar</i> — material icon named "wifi 1 bar" (outlined). + static const IconData wifi_1_bar_outlined = IconData(0xf0728, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_2_bar</i> — material icon named "wifi 2 bar". + static const IconData wifi_2_bar = IconData(0xf07d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_2_bar</i> — material icon named "wifi 2 bar" (sharp). + static const IconData wifi_2_bar_sharp = IconData(0xf0781, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_2_bar</i> — material icon named "wifi 2 bar" (round). + static const IconData wifi_2_bar_rounded = IconData(0xf0831, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_2_bar</i> — material icon named "wifi 2 bar" (outlined). + static const IconData wifi_2_bar_outlined = IconData(0xf0729, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_calling</i> — material icon named "wifi calling". + static const IconData wifi_calling = IconData(0xe6e8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_calling</i> — material icon named "wifi calling" (sharp). + static const IconData wifi_calling_sharp = IconData(0xeddc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_calling</i> — material icon named "wifi calling" (round). + static const IconData wifi_calling_rounded = IconData(0xf02bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_calling</i> — material icon named "wifi calling" (outlined). + static const IconData wifi_calling_outlined = IconData(0xf4c9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_calling_3</i> — material icon named "wifi calling 3". + static const IconData wifi_calling_3 = IconData(0xe6e9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_calling_3</i> — material icon named "wifi calling 3" (sharp). + static const IconData wifi_calling_3_sharp = IconData(0xeddb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_calling_3</i> — material icon named "wifi calling 3" (round). + static const IconData wifi_calling_3_rounded = IconData(0xf02ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_calling_3</i> — material icon named "wifi calling 3" (outlined). + static const IconData wifi_calling_3_outlined = IconData(0xf4c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_channel</i> — material icon named "wifi channel". + static const IconData wifi_channel = IconData(0xf05a7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_channel</i> — material icon named "wifi channel" (sharp). + static const IconData wifi_channel_sharp = IconData(0xf04ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_channel</i> — material icon named "wifi channel" (round). + static const IconData wifi_channel_rounded = IconData(0xf03b9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_channel</i> — material icon named "wifi channel" (outlined). + static const IconData wifi_channel_outlined = IconData(0xf069a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_find</i> — material icon named "wifi find". + static const IconData wifi_find = IconData(0xf05a8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_find</i> — material icon named "wifi find" (sharp). + static const IconData wifi_find_sharp = IconData(0xf04ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_find</i> — material icon named "wifi find" (round). + static const IconData wifi_find_rounded = IconData(0xf03ba, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_find</i> — material icon named "wifi find" (outlined). + static const IconData wifi_find_outlined = IconData(0xf069b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_lock</i> — material icon named "wifi lock". + static const IconData wifi_lock = IconData(0xe6ea, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_lock</i> — material icon named "wifi lock" (sharp). + static const IconData wifi_lock_sharp = IconData(0xeddd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_lock</i> — material icon named "wifi lock" (round). + static const IconData wifi_lock_rounded = IconData(0xf02bc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_lock</i> — material icon named "wifi lock" (outlined). + static const IconData wifi_lock_outlined = IconData(0xf4ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_off</i> — material icon named "wifi off". + static const IconData wifi_off = IconData(0xe6eb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_off</i> — material icon named "wifi off" (sharp). + static const IconData wifi_off_sharp = IconData(0xedde, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_off</i> — material icon named "wifi off" (round). + static const IconData wifi_off_rounded = IconData(0xf02bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_off</i> — material icon named "wifi off" (outlined). + static const IconData wifi_off_outlined = IconData(0xf4cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_password</i> — material icon named "wifi password". + static const IconData wifi_password = IconData(0xf05a9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_password</i> — material icon named "wifi password" (sharp). + static const IconData wifi_password_sharp = IconData(0xf04ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_password</i> — material icon named "wifi password" (round). + static const IconData wifi_password_rounded = IconData(0xf03bb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_password</i> — material icon named "wifi password" (outlined). + static const IconData wifi_password_outlined = IconData(0xf069c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_protected_setup</i> — material icon named "wifi protected setup". + static const IconData wifi_protected_setup = IconData(0xe6ec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_protected_setup</i> — material icon named "wifi protected setup" (sharp). + static const IconData wifi_protected_setup_sharp = IconData(0xeddf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_protected_setup</i> — material icon named "wifi protected setup" (round). + static const IconData wifi_protected_setup_rounded = IconData(0xf02be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_protected_setup</i> — material icon named "wifi protected setup" (outlined). + static const IconData wifi_protected_setup_outlined = IconData(0xf4cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_tethering</i> — material icon named "wifi tethering". + static const IconData wifi_tethering = IconData(0xe6ed, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_tethering</i> — material icon named "wifi tethering" (sharp). + static const IconData wifi_tethering_sharp = IconData(0xede3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_tethering</i> — material icon named "wifi tethering" (round). + static const IconData wifi_tethering_rounded = IconData(0xf02c2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_tethering</i> — material icon named "wifi tethering" (outlined). + static const IconData wifi_tethering_outlined = IconData(0xf4d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_tethering_error</i> — material icon named "wifi tethering error". + static const IconData wifi_tethering_error = IconData(0xf05aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_tethering_error</i> — material icon named "wifi tethering error" (sharp). + static const IconData wifi_tethering_error_sharp = IconData(0xf04af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_tethering_error</i> — material icon named "wifi tethering error". + static const IconData wifi_tethering_error_rounded = IconData(0xf05aa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_tethering_error</i> — material icon named "wifi tethering error" (outlined). + static const IconData wifi_tethering_error_outlined = IconData(0xf069d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_tethering_error_rounded</i> — material icon named "wifi tethering error rounded" (sharp). + static const IconData wifi_tethering_error_rounded_sharp = IconData(0xf04af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_tethering_error_rounded</i> — material icon named "wifi tethering error rounded" (round). + static const IconData wifi_tethering_error_rounded_rounded = IconData(0xf02c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_tethering_error_rounded</i> — material icon named "wifi tethering error rounded" (outlined). + static const IconData wifi_tethering_error_rounded_outlined = IconData(0xf069d, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wifi_tethering_off</i> — material icon named "wifi tethering off". + static const IconData wifi_tethering_off = IconData(0xe6ef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wifi_tethering_off</i> — material icon named "wifi tethering off" (sharp). + static const IconData wifi_tethering_off_sharp = IconData(0xede2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wifi_tethering_off</i> — material icon named "wifi tethering off" (round). + static const IconData wifi_tethering_off_rounded = IconData(0xf02c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wifi_tethering_off</i> — material icon named "wifi tethering off" (outlined). + static const IconData wifi_tethering_off_outlined = IconData(0xf4cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wind_power</i> — material icon named "wind power". + static const IconData wind_power = IconData(0xf07da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wind_power</i> — material icon named "wind power" (sharp). + static const IconData wind_power_sharp = IconData(0xf0782, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wind_power</i> — material icon named "wind power" (round). + static const IconData wind_power_rounded = IconData(0xf0832, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wind_power</i> — material icon named "wind power" (outlined). + static const IconData wind_power_outlined = IconData(0xf072a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">window</i> — material icon named "window". + static const IconData window = IconData(0xe6f0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">window</i> — material icon named "window" (sharp). + static const IconData window_sharp = IconData(0xede4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">window</i> — material icon named "window" (round). + static const IconData window_rounded = IconData(0xf02c3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">window</i> — material icon named "window" (outlined). + static const IconData window_outlined = IconData(0xf4d1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wine_bar</i> — material icon named "wine bar". + static const IconData wine_bar = IconData(0xe6f1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wine_bar</i> — material icon named "wine bar" (sharp). + static const IconData wine_bar_sharp = IconData(0xede5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wine_bar</i> — material icon named "wine bar" (round). + static const IconData wine_bar_rounded = IconData(0xf02c4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wine_bar</i> — material icon named "wine bar" (outlined). + static const IconData wine_bar_outlined = IconData(0xf4d2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">woman</i> — material icon named "woman". + static const IconData woman = IconData(0xf05ab, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">woman</i> — material icon named "woman" (sharp). + static const IconData woman_sharp = IconData(0xf04b0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">woman</i> — material icon named "woman" (round). + static const IconData woman_rounded = IconData(0xf03bd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">woman</i> — material icon named "woman" (outlined). + static const IconData woman_outlined = IconData(0xf069e, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">woman_2</i> — material icon named "woman 2". + static const IconData woman_2 = IconData(0xf087c, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">woman_2</i> — material icon named "woman 2" (sharp). + static const IconData woman_2_sharp = IconData(0xf0851, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">woman_2</i> — material icon named "woman 2" (round). + static const IconData woman_2_rounded = IconData(0xf089a, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">woman_2</i> — material icon named "woman 2" (outlined). + static const IconData woman_2_outlined = IconData(0xf08b8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">woo_commerce</i> — material icon named "woo commerce". + static const IconData woo_commerce = IconData(0xf05ac, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">woo_commerce</i> — material icon named "woo commerce" (sharp). + static const IconData woo_commerce_sharp = IconData(0xf04b1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">woo_commerce</i> — material icon named "woo commerce" (round). + static const IconData woo_commerce_rounded = IconData(0xf03be, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">woo_commerce</i> — material icon named "woo commerce" (outlined). + static const IconData woo_commerce_outlined = IconData(0xf069f, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wordpress</i> — material icon named "wordpress". + static const IconData wordpress = IconData(0xf05ad, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wordpress</i> — material icon named "wordpress" (sharp). + static const IconData wordpress_sharp = IconData(0xf04b2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wordpress</i> — material icon named "wordpress" (round). + static const IconData wordpress_rounded = IconData(0xf03bf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wordpress</i> — material icon named "wordpress" (outlined). + static const IconData wordpress_outlined = IconData(0xf06a0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">work</i> — material icon named "work". + static const IconData work = IconData(0xe6f2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">work</i> — material icon named "work" (sharp). + static const IconData work_sharp = IconData(0xede8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">work</i> — material icon named "work" (round). + static const IconData work_rounded = IconData(0xf02c7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">work</i> — material icon named "work" (outlined). + static const IconData work_outlined = IconData(0xf4d5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">work_history</i> — material icon named "work history". + static const IconData work_history = IconData(0xf07db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">work_history</i> — material icon named "work history" (sharp). + static const IconData work_history_sharp = IconData(0xf0783, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">work_history</i> — material icon named "work history" (round). + static const IconData work_history_rounded = IconData(0xf0833, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">work_history</i> — material icon named "work history" (outlined). + static const IconData work_history_outlined = IconData(0xf072b, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">work_off</i> — material icon named "work off". + static const IconData work_off = IconData(0xe6f3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">work_off</i> — material icon named "work off" (sharp). + static const IconData work_off_sharp = IconData(0xede6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">work_off</i> — material icon named "work off" (round). + static const IconData work_off_rounded = IconData(0xf02c5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">work_off</i> — material icon named "work off" (outlined). + static const IconData work_off_outlined = IconData(0xf4d3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">work_outline</i> — material icon named "work outline". + static const IconData work_outline = IconData(0xe6f4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">work_outline</i> — material icon named "work outline" (sharp). + static const IconData work_outline_sharp = IconData(0xede7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">work_outline</i> — material icon named "work outline" (round). + static const IconData work_outline_rounded = IconData(0xf02c6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">work_outline</i> — material icon named "work outline" (outlined). + static const IconData work_outline_outlined = IconData(0xf4d4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">workspace_premium</i> — material icon named "workspace premium". + static const IconData workspace_premium = IconData(0xf05ae, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">workspace_premium</i> — material icon named "workspace premium" (sharp). + static const IconData workspace_premium_sharp = IconData(0xf04b3, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">workspace_premium</i> — material icon named "workspace premium" (round). + static const IconData workspace_premium_rounded = IconData(0xf03c0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">workspace_premium</i> — material icon named "workspace premium" (outlined). + static const IconData workspace_premium_outlined = IconData(0xf06a1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">workspaces</i> — material icon named "workspaces". + static const IconData workspaces = IconData(0xe6f5, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">workspaces</i> — material icon named "workspaces" (sharp). + static const IconData workspaces_sharp = IconData(0xede9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">workspaces</i> — material icon named "workspaces" (round). + static const IconData workspaces_rounded = IconData(0xf02c8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">workspaces</i> — material icon named "workspaces" (outlined). + static const IconData workspaces_outlined = IconData(0xf4d6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">workspaces_filled</i> — material icon named "workspaces filled". + static const IconData workspaces_filled = IconData(0xe6f6, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">workspaces_outline</i> — material icon named "workspaces outline". + static const IconData workspaces_outline = IconData(0xe6f7, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wrap_text</i> — material icon named "wrap text". + static const IconData wrap_text = IconData(0xe6f8, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-sharp md-36">wrap_text</i> — material icon named "wrap text" (sharp). + static const IconData wrap_text_sharp = IconData(0xedea, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-round md-36">wrap_text</i> — material icon named "wrap text" (round). + static const IconData wrap_text_rounded = IconData(0xf02c9, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons-outlined md-36">wrap_text</i> — material icon named "wrap text" (outlined). + static const IconData wrap_text_outlined = IconData(0xf4d7, fontFamily: 'MaterialIcons', matchTextDirection: true); + + /// <i class="material-icons md-36">wrong_location</i> — material icon named "wrong location". + static const IconData wrong_location = IconData(0xe6f9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wrong_location</i> — material icon named "wrong location" (sharp). + static const IconData wrong_location_sharp = IconData(0xedeb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wrong_location</i> — material icon named "wrong location" (round). + static const IconData wrong_location_rounded = IconData(0xf02ca, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wrong_location</i> — material icon named "wrong location" (outlined). + static const IconData wrong_location_outlined = IconData(0xf4d8, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">wysiwyg</i> — material icon named "wysiwyg". + static const IconData wysiwyg = IconData(0xe6fa, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">wysiwyg</i> — material icon named "wysiwyg" (sharp). + static const IconData wysiwyg_sharp = IconData(0xedec, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">wysiwyg</i> — material icon named "wysiwyg" (round). + static const IconData wysiwyg_rounded = IconData(0xf02cb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">wysiwyg</i> — material icon named "wysiwyg" (outlined). + static const IconData wysiwyg_outlined = IconData(0xf4d9, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">yard</i> — material icon named "yard". + static const IconData yard = IconData(0xe6fb, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">yard</i> — material icon named "yard" (sharp). + static const IconData yard_sharp = IconData(0xeded, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">yard</i> — material icon named "yard" (round). + static const IconData yard_rounded = IconData(0xf02cc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">yard</i> — material icon named "yard" (outlined). + static const IconData yard_outlined = IconData(0xf4da, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">youtube_searched_for</i> — material icon named "youtube searched for". + static const IconData youtube_searched_for = IconData(0xe6fc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">youtube_searched_for</i> — material icon named "youtube searched for" (sharp). + static const IconData youtube_searched_for_sharp = IconData(0xedee, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">youtube_searched_for</i> — material icon named "youtube searched for" (round). + static const IconData youtube_searched_for_rounded = IconData(0xf02cd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">youtube_searched_for</i> — material icon named "youtube searched for" (outlined). + static const IconData youtube_searched_for_outlined = IconData(0xf4db, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">zoom_in</i> — material icon named "zoom in". + static const IconData zoom_in = IconData(0xe6fd, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">zoom_in</i> — material icon named "zoom in" (sharp). + static const IconData zoom_in_sharp = IconData(0xedef, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">zoom_in</i> — material icon named "zoom in" (round). + static const IconData zoom_in_rounded = IconData(0xf02ce, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">zoom_in</i> — material icon named "zoom in" (outlined). + static const IconData zoom_in_outlined = IconData(0xf4dc, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">zoom_in_map</i> — material icon named "zoom in map". + static const IconData zoom_in_map = IconData(0xf05af, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">zoom_in_map</i> — material icon named "zoom in map" (sharp). + static const IconData zoom_in_map_sharp = IconData(0xf04b4, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">zoom_in_map</i> — material icon named "zoom in map" (round). + static const IconData zoom_in_map_rounded = IconData(0xf03c1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">zoom_in_map</i> — material icon named "zoom in map" (outlined). + static const IconData zoom_in_map_outlined = IconData(0xf06a2, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">zoom_out</i> — material icon named "zoom out". + static const IconData zoom_out = IconData(0xe6fe, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">zoom_out</i> — material icon named "zoom out" (sharp). + static const IconData zoom_out_sharp = IconData(0xedf1, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">zoom_out</i> — material icon named "zoom out" (round). + static const IconData zoom_out_rounded = IconData(0xf02d0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">zoom_out</i> — material icon named "zoom out" (outlined). + static const IconData zoom_out_outlined = IconData(0xf4de, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons md-36">zoom_out_map</i> — material icon named "zoom out map". + static const IconData zoom_out_map = IconData(0xe6ff, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-sharp md-36">zoom_out_map</i> — material icon named "zoom out map" (sharp). + static const IconData zoom_out_map_sharp = IconData(0xedf0, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-round md-36">zoom_out_map</i> — material icon named "zoom out map" (round). + static const IconData zoom_out_map_rounded = IconData(0xf02cf, fontFamily: 'MaterialIcons'); + + /// <i class="material-icons-outlined md-36">zoom_out_map</i> — material icon named "zoom out map" (outlined). + static const IconData zoom_out_map_outlined = IconData(0xf4dd, fontFamily: 'MaterialIcons'); + // END GENERATED ICONS +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_decoration.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_decoration.dart new file mode 100644 index 0000000000000000000000000000000000000000..05434e7f63e406d4ccd5d3913c050a0922667c66 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_decoration.dart @@ -0,0 +1,418 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'debug.dart'; +import 'material.dart'; + +/// A convenience widget for drawing images and other decorations on [Material] +/// widgets, so that [InkWell] and [InkResponse] splashes will render over them. +/// +/// Ink splashes and highlights, as rendered by [InkWell] and [InkResponse], +/// draw on the actual underlying [Material], under whatever widgets are drawn +/// over the material (such as [Text] and [Icon]s). If an opaque image is drawn +/// over the [Material] (maybe using a [Container] or [DecoratedBox]), these ink +/// effects will not be visible, as they will be entirely obscured by the opaque +/// graphics drawn above the [Material]. +/// +/// This widget draws the given [Decoration] directly on the [Material], in the +/// same way that [InkWell] and [InkResponse] draw there. This allows the +/// splashes to be drawn above the otherwise opaque graphics. +/// +/// An alternative solution is to use a [MaterialType.transparency] material +/// above the opaque graphics, so that the ink responses from [InkWell]s and +/// [InkResponse]s will be drawn on the transparent material on top of the +/// opaque graphics, rather than under the opaque graphics on the underlying +/// [Material]. +/// +/// ## Limitations +/// +/// This widget is subject to the same limitations as other ink effects, as +/// described in the documentation for [Material]. Most notably, the position of +/// an [Ink] widget must not change during the lifetime of the [Material] object +/// unless a [LayoutChangedNotification] is dispatched each frame that the +/// position changes. This is done automatically for [ListView] and other +/// scrolling widgets, but is not done for animated transitions such as +/// [SlideTransition]. +/// +/// Additionally, if multiple [Ink] widgets paint on the same [Material] in the +/// same location, their relative order is not guaranteed. The decorations will +/// be painted in the order that they were added to the material, which +/// generally speaking will match the order they are given in the widget tree, +/// but this order may appear to be somewhat random in more dynamic situations. +/// +/// {@tool snippet} +/// +/// This example shows how a [Material] widget can have a yellow rectangle drawn +/// on it using [Ink], while still having ink effects over the yellow rectangle: +/// +/// ```dart +/// Material( +/// color: Colors.teal[900], +/// child: Center( +/// child: Ink( +/// color: Colors.yellow, +/// width: 200.0, +/// height: 100.0, +/// child: InkWell( +/// onTap: () { /* ... */ }, +/// child: const Center( +/// child: Text('YELLOW'), +/// ) +/// ), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// The following example shows how an image can be printed on a [Material] +/// widget with an [InkWell] above it: +/// +/// ```dart +/// Material( +/// color: Colors.grey[800], +/// child: Center( +/// child: Ink.image( +/// image: const AssetImage('cat.jpeg'), +/// fit: BoxFit.cover, +/// width: 300.0, +/// height: 200.0, +/// child: InkWell( +/// onTap: () { /* ... */ }, +/// child: const Align( +/// alignment: Alignment.topLeft, +/// child: Padding( +/// padding: EdgeInsets.all(10.0), +/// child: Text( +/// 'KITTEN', +/// style: TextStyle( +/// fontWeight: FontWeight.w900, +/// color: Colors.white, +/// ), +/// ), +/// ), +/// ) +/// ), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// What to do if you want to clip this [Ink.image]? +/// +/// {@tool dartpad} +/// Wrapping the [Ink] in a clipping widget directly will not work since the +/// [Material] it will be printed on is responsible for clipping. +/// +/// In this example the image is not being clipped as expected. This is because +/// it is being rendered onto the Scaffold body Material, which isn't wrapped in +/// the [ClipRRect]. +/// +/// ** See code in examples/api/lib/material/ink/ink.image_clip.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// One solution would be to deliberately wrap the [Ink.image] in a [Material]. +/// This makes sure the Material that the image is painted on is also responsible +/// for clipping said content. +/// +/// ** See code in examples/api/lib/material/ink/ink.image_clip.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Container], a more generic form of this widget which paints itself, +/// rather that deferring to the nearest [Material] widget. +/// * [InkDecoration], the [InkFeature] subclass used by this widget to paint +/// on [Material] widgets. +/// * [InkWell] and [InkResponse], which also draw on [Material] widgets. +class Ink extends StatefulWidget { + /// Paints a decoration (which can be a simple color) on a [Material]. + /// + /// The [height] and [width] values include the [padding]. + /// + /// The `color` argument is a shorthand for + /// `decoration: BoxDecoration(color: color)`, which means you cannot supply + /// both a `color` and a `decoration` argument. If you want to have both a + /// `color` and a `decoration`, you can pass the color as the `color` + /// argument to the `BoxDecoration`. + /// + /// If there is no intention to render anything on this decoration, consider + /// using a [Container] with a [BoxDecoration] instead. + Ink({ + super.key, + this.padding, + Color? color, + Decoration? decoration, + this.width, + this.height, + this.child, + }) : assert(padding == null || padding.isNonNegative), + assert(decoration == null || decoration.debugAssertIsValid()), + assert(color == null || decoration == null, + 'Cannot provide both a color and a decoration\n' + 'The color argument is just a shorthand for "decoration: BoxDecoration(color: color)".', + ), + decoration = decoration ?? (color != null ? BoxDecoration(color: color) : null); + + /// Creates a widget that shows an image (obtained from an [ImageProvider]) on + /// a [Material]. + /// + /// This argument is a shorthand for passing a [BoxDecoration] that has only + /// its [BoxDecoration.image] property set to the [Ink] constructor. The + /// properties of the [DecorationImage] of that [BoxDecoration] are set + /// according to the arguments passed to this method. + /// + /// If there is no intention to render anything on this image, consider using + /// a [Container] with a [BoxDecoration.image] instead. The `onImageError` + /// argument may be provided to listen for errors when resolving the image. + /// + /// The `alignment`, `repeat`, and `matchTextDirection` arguments must not + /// be null either, but they have default values. + /// + /// See [paintImage] for a description of the meaning of these arguments. + Ink.image({ + super.key, + this.padding, + required ImageProvider image, + ImageErrorListener? onImageError, + ColorFilter? colorFilter, + BoxFit? fit, + AlignmentGeometry alignment = Alignment.center, + Rect? centerSlice, + ImageRepeat repeat = ImageRepeat.noRepeat, + bool matchTextDirection = false, + this.width, + this.height, + this.child, + }) : assert(padding == null || padding.isNonNegative), + decoration = BoxDecoration( + image: DecorationImage( + image: image, + onError: onImageError, + colorFilter: colorFilter, + fit: fit, + alignment: alignment, + centerSlice: centerSlice, + repeat: repeat, + matchTextDirection: matchTextDirection, + ), + ); + + /// The [child] contained by the container. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// Empty space to inscribe inside the [decoration]. The [child], if any, is + /// placed inside this padding. + /// + /// This padding is in addition to any padding inherent in the [decoration]; + /// see [Decoration.padding]. + final EdgeInsetsGeometry? padding; + + /// The decoration to paint on the nearest ancestor [Material] widget. + /// + /// A shorthand for specifying just a solid color is available in the + /// constructor: set the `color` argument instead of the [decoration] + /// argument. + /// + /// A shorthand for specifying just an image is also available using the + /// [Ink.image] constructor. + final Decoration? decoration; + + /// A width to apply to the [decoration] and the [child]. The width includes + /// any [padding]. + final double? width; + + /// A height to apply to the [decoration] and the [child]. The height includes + /// any [padding]. + final double? height; + + EdgeInsetsGeometry get _paddingIncludingDecoration { + if (decoration == null) { + return padding ?? EdgeInsets.zero; + } + final EdgeInsetsGeometry decorationPadding = decoration!.padding; + if (padding == null) { + return decorationPadding; + } + return padding!.add(decorationPadding); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<Decoration>('bg', decoration, defaultValue: null)); + } + + @override + State<Ink> createState() => _InkState(); +} + +class _InkState extends State<Ink> { + final GlobalKey _boxKey = GlobalKey(); + InkDecoration? _ink; + + void _handleRemoved() { + _ink = null; + } + + @override + void deactivate() { + _ink?.dispose(); + assert(_ink == null); + super.deactivate(); + } + + Widget _build(BuildContext context) { + // By creating the InkDecoration from within a Builder widget, we can + // use the RenderBox of the Padding widget. + if (_ink == null) { + _ink = InkDecoration( + decoration: widget.decoration, + isVisible: Visibility.of(context), + configuration: createLocalImageConfiguration(context), + controller: Material.of(context), + referenceBox: _boxKey.currentContext!.findRenderObject()! as RenderBox, + onRemoved: _handleRemoved, + ); + } else { + _ink!.decoration = widget.decoration; + _ink!.isVisible = Visibility.of(context); + _ink!.configuration = createLocalImageConfiguration(context); + } + return widget.child ?? ConstrainedBox(constraints: const BoxConstraints.expand()); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + Widget result = Padding( + key: _boxKey, + padding: widget._paddingIncludingDecoration, + child: Builder(builder: _build), + ); + if (widget.width != null || widget.height != null) { + result = SizedBox( + width: widget.width, + height: widget.height, + child: result, + ); + } + return result; + } +} + +/// A decoration on a part of a [Material]. +/// +/// This object is rarely created directly. Instead of creating an ink +/// decoration directly, consider using an [Ink] widget, which uses this class +/// in combination with [Padding] and [ConstrainedBox] to draw a decoration on a +/// [Material]. +/// +/// See also: +/// +/// * [Ink], the corresponding widget. +/// * [InkResponse], which uses gestures to trigger ink highlights and ink +/// splashes in the parent [Material]. +/// * [InkWell], which is a rectangular [InkResponse] (the most common type of +/// ink response). +/// * [Material], which is the widget on which the ink is painted. +class InkDecoration extends InkFeature { + /// Draws a decoration on a [Material]. + InkDecoration({ + required Decoration? decoration, + bool isVisible = true, + required ImageConfiguration configuration, + required super.controller, + required super.referenceBox, + super.onRemoved, + }) : _configuration = configuration { + this.decoration = decoration; + this.isVisible = isVisible; + controller.addInkFeature(this); + } + + BoxPainter? _painter; + + /// What to paint on the [Material]. + /// + /// The decoration is painted at the position and size of the [referenceBox], + /// on the [Material] that owns the [controller]. + Decoration? get decoration => _decoration; + Decoration? _decoration; + set decoration(Decoration? value) { + if (value == _decoration) { + return; + } + _decoration = value; + _painter?.dispose(); + _painter = _decoration?.createBoxPainter(_handleChanged); + controller.markNeedsPaint(); + } + + /// Whether the decoration should be painted. + /// + /// Defaults to true. + bool get isVisible => _isVisible; + bool _isVisible = true; + set isVisible(bool value) { + if (value == _isVisible) { + return; + } + _isVisible = value; + controller.markNeedsPaint(); + } + + /// The configuration to pass to the [BoxPainter] obtained from the + /// [decoration], when painting. + /// + /// The [ImageConfiguration.size] field is ignored (and replaced by the size + /// of the [referenceBox], at paint time). + ImageConfiguration get configuration => _configuration; + ImageConfiguration _configuration; + set configuration(ImageConfiguration value) { + if (value == _configuration) { + return; + } + _configuration = value; + controller.markNeedsPaint(); + } + + void _handleChanged() { + controller.markNeedsPaint(); + } + + @override + void dispose() { + _painter?.dispose(); + super.dispose(); + } + + @override + void paintFeature(Canvas canvas, Matrix4 transform) { + if (_painter == null || !isVisible) { + return; + } + final Offset? originOffset = MatrixUtils.getAsTranslation(transform); + final ImageConfiguration sizedConfiguration = configuration.copyWith( + size: referenceBox.size, + ); + if (originOffset == null) { + canvas.save(); + canvas.transform(transform.storage); + _painter!.paint(canvas, Offset.zero, sizedConfiguration); + canvas.restore(); + } else { + _painter!.paint(canvas, originOffset, sizedConfiguration); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_highlight.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_highlight.dart new file mode 100644 index 0000000000000000000000000000000000000000..c0d50a7940b648ea5811aa80b9d1f7b106423052 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_highlight.dart @@ -0,0 +1,143 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'ink_well.dart' show InteractiveInkFeature; +import 'material.dart'; + +const Duration _kDefaultHighlightFadeDuration = Duration(milliseconds: 200); + +/// A visual emphasis on a part of a [Material] receiving user interaction. +/// +/// This object is rarely created directly. Instead of creating an ink highlight +/// directly, consider using an [InkResponse] or [InkWell] widget, which uses +/// gestures (such as tap and long-press) to trigger ink highlights. +/// +/// See also: +/// +/// * [InkResponse], which uses gestures to trigger ink highlights and ink +/// splashes in the parent [Material]. +/// * [InkWell], which is a rectangular [InkResponse] (the most common type of +/// ink response). +/// * [Material], which is the widget on which the ink highlight is painted. +/// * [InkSplash], which is an ink feature that shows a reaction to user input +/// on a [Material]. +/// * [Ink], a convenience widget for drawing images and other decorations on +/// Material widgets. +class InkHighlight extends InteractiveInkFeature { + /// Begin a highlight animation. + /// + /// The [controller] argument is typically obtained via + /// `Material.of(context)`. + /// + /// If a `rectCallback` is given, then it provides the highlight rectangle, + /// otherwise, the highlight rectangle is coincident with the [referenceBox]. + /// + /// When the highlight is removed, `onRemoved` will be called. + InkHighlight({ + required super.controller, + required super.referenceBox, + required super.color, + required TextDirection textDirection, + BoxShape shape = BoxShape.rectangle, + double? radius, + BorderRadius? borderRadius, + super.customBorder, + RectCallback? rectCallback, + super.onRemoved, + Duration fadeDuration = _kDefaultHighlightFadeDuration, + }) : _shape = shape, + _radius = radius, + _borderRadius = borderRadius ?? BorderRadius.zero, + + _textDirection = textDirection, + _rectCallback = rectCallback { + _alphaController = AnimationController(duration: fadeDuration, vsync: controller.vsync) + ..addListener(controller.markNeedsPaint) + ..addStatusListener(_handleAlphaStatusChanged) + ..forward(); + _alpha = _alphaController.drive(IntTween( + begin: 0, + end: color.alpha, + )); + + controller.addInkFeature(this); + } + + final BoxShape _shape; + final double? _radius; + final BorderRadius _borderRadius; + final RectCallback? _rectCallback; + final TextDirection _textDirection; + + late Animation<int> _alpha; + late AnimationController _alphaController; + + /// Whether this part of the material is being visually emphasized. + bool get active => _active; + bool _active = true; + + /// Start visually emphasizing this part of the material. + void activate() { + _active = true; + _alphaController.forward(); + } + + /// Stop visually emphasizing this part of the material. + void deactivate() { + _active = false; + _alphaController.reverse(); + } + + void _handleAlphaStatusChanged(AnimationStatus status) { + if (status == AnimationStatus.dismissed && !_active) { + dispose(); + } + } + + @override + void dispose() { + _alphaController.dispose(); + super.dispose(); + } + + void _paintHighlight(Canvas canvas, Rect rect, Paint paint) { + canvas.save(); + if (customBorder != null) { + canvas.clipPath(customBorder!.getOuterPath(rect, textDirection: _textDirection)); + } + switch (_shape) { + case BoxShape.circle: + canvas.drawCircle(rect.center, _radius ?? Material.defaultSplashRadius, paint); + case BoxShape.rectangle: + if (_borderRadius != BorderRadius.zero) { + final RRect clipRRect = RRect.fromRectAndCorners( + rect, + topLeft: _borderRadius.topLeft, topRight: _borderRadius.topRight, + bottomLeft: _borderRadius.bottomLeft, bottomRight: _borderRadius.bottomRight, + ); + canvas.drawRRect(clipRRect, paint); + } else { + canvas.drawRect(rect, paint); + } + } + canvas.restore(); + } + + @override + void paintFeature(Canvas canvas, Matrix4 transform) { + final Paint paint = Paint()..color = color.withAlpha(_alpha.value); + final Offset? originOffset = MatrixUtils.getAsTranslation(transform); + final Rect rect = _rectCallback != null ? _rectCallback() : Offset.zero & referenceBox.size; + if (originOffset == null) { + canvas.save(); + canvas.transform(transform.storage); + _paintHighlight(canvas, rect, paint); + canvas.restore(); + } else { + _paintHighlight(canvas, rect.shift(originOffset), paint); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_ripple.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_ripple.dart new file mode 100644 index 0000000000000000000000000000000000000000..8f9dcde76e90692254639117f38cc2d1bd5186a0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_ripple.dart @@ -0,0 +1,251 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/widgets.dart'; + +import 'ink_well.dart'; +import 'material.dart'; + +const Duration _kUnconfirmedRippleDuration = Duration(seconds: 1); +const Duration _kFadeInDuration = Duration(milliseconds: 75); +const Duration _kRadiusDuration = Duration(milliseconds: 225); +const Duration _kFadeOutDuration = Duration(milliseconds: 375); +const Duration _kCancelDuration = Duration(milliseconds: 75); + +// The fade out begins 225ms after the _fadeOutController starts. See confirm(). +const double _kFadeOutIntervalStart = 225.0 / 375.0; + +RectCallback? _getClipCallback(RenderBox referenceBox, bool containedInkWell, RectCallback? rectCallback) { + if (rectCallback != null) { + assert(containedInkWell); + return rectCallback; + } + if (containedInkWell) { + return () => Offset.zero & referenceBox.size; + } + return null; +} + +double _getTargetRadius(RenderBox referenceBox, bool containedInkWell, RectCallback? rectCallback, Offset position) { + final Size size = rectCallback != null ? rectCallback().size : referenceBox.size; + final double d1 = size.bottomRight(Offset.zero).distance; + final double d2 = (size.topRight(Offset.zero) - size.bottomLeft(Offset.zero)).distance; + return math.max(d1, d2) / 2.0; +} + +class _InkRippleFactory extends InteractiveInkFeatureFactory { + const _InkRippleFactory(); + + @override + InteractiveInkFeature create({ + required MaterialInkController controller, + required RenderBox referenceBox, + required Offset position, + required Color color, + required TextDirection textDirection, + bool containedInkWell = false, + RectCallback? rectCallback, + BorderRadius? borderRadius, + ShapeBorder? customBorder, + double? radius, + VoidCallback? onRemoved, + }) { + return InkRipple( + controller: controller, + referenceBox: referenceBox, + position: position, + color: color, + containedInkWell: containedInkWell, + rectCallback: rectCallback, + borderRadius: borderRadius, + customBorder: customBorder, + radius: radius, + onRemoved: onRemoved, + textDirection: textDirection, + ); + } +} + +/// A visual reaction on a piece of [Material] to user input. +/// +/// A circular ink feature whose origin starts at the input touch point and +/// whose radius expands from 60% of the final radius. The splash origin +/// animates to the center of its [referenceBox]. +/// +/// This object is rarely created directly. Instead of creating an ink ripple, +/// consider using an [InkResponse] or [InkWell] widget, which uses +/// gestures (such as tap and long-press) to trigger ink splashes. This class +/// is used when the [Theme]'s [ThemeData.splashFactory] is [InkRipple.splashFactory]. +/// +/// See also: +/// +/// * [InkSplash], which is an ink splash feature that expands less +/// aggressively than the ripple. +/// * [InkResponse], which uses gestures to trigger ink highlights and ink +/// splashes in the parent [Material]. +/// * [InkWell], which is a rectangular [InkResponse] (the most common type of +/// ink response). +/// * [Material], which is the widget on which the ink splash is painted. +/// * [InkHighlight], which is an ink feature that emphasizes a part of a +/// [Material]. +class InkRipple extends InteractiveInkFeature { + /// Begin a ripple, centered at [position] relative to [referenceBox]. + /// + /// The [controller] argument is typically obtained via + /// `Material.of(context)`. + /// + /// If [containedInkWell] is true, then the ripple will be sized to fit + /// the well rectangle, then clipped to it when drawn. The well + /// rectangle is the box returned by [rectCallback], if provided, or + /// otherwise is the bounds of the [referenceBox]. + /// + /// If [containedInkWell] is false, then [rectCallback] should be null. + /// The ink ripple is clipped only to the edges of the [Material]. + /// This is the default. + /// + /// When the ripple is removed, [onRemoved] will be called. + InkRipple({ + required MaterialInkController controller, + required super.referenceBox, + required Offset position, + required Color color, + required TextDirection textDirection, + bool containedInkWell = false, + RectCallback? rectCallback, + BorderRadius? borderRadius, + super.customBorder, + double? radius, + super.onRemoved, + }) : _position = position, + _borderRadius = borderRadius ?? BorderRadius.zero, + _textDirection = textDirection, + _targetRadius = radius ?? _getTargetRadius(referenceBox, containedInkWell, rectCallback, position), + _clipCallback = _getClipCallback(referenceBox, containedInkWell, rectCallback), + super(controller: controller, color: color) { + + // Immediately begin fading-in the initial splash. + _fadeInController = AnimationController(duration: _kFadeInDuration, vsync: controller.vsync) + ..addListener(controller.markNeedsPaint) + ..forward(); + _fadeIn = _fadeInController.drive(IntTween( + begin: 0, + end: color.alpha, + )); + + // Controls the splash radius and its center. Starts upon confirm. + _radiusController = AnimationController(duration: _kUnconfirmedRippleDuration, vsync: controller.vsync) + ..addListener(controller.markNeedsPaint) + ..forward(); + // Initial splash diameter is 60% of the target diameter, final + // diameter is 10dps larger than the target diameter. + _radius = _radiusController.drive( + Tween<double>( + begin: _targetRadius * 0.30, + end: _targetRadius + 5.0, + ).chain(_easeCurveTween), + ); + + // Controls the splash radius and its center. Starts upon confirm however its + // Interval delays changes until the radius expansion has completed. + _fadeOutController = AnimationController(duration: _kFadeOutDuration, vsync: controller.vsync) + ..addListener(controller.markNeedsPaint) + ..addStatusListener(_handleAlphaStatusChanged); + _fadeOut = _fadeOutController.drive( + IntTween( + begin: color.alpha, + end: 0, + ).chain(_fadeOutIntervalTween), + ); + + controller.addInkFeature(this); + } + + final Offset _position; + final BorderRadius _borderRadius; + final double _targetRadius; + final RectCallback? _clipCallback; + final TextDirection _textDirection; + + late Animation<double> _radius; + late AnimationController _radiusController; + + late Animation<int> _fadeIn; + late AnimationController _fadeInController; + + late Animation<int> _fadeOut; + late AnimationController _fadeOutController; + + /// Used to specify this type of ink splash for an [InkWell], [InkResponse], + /// material [Theme], or [ButtonStyle]. + static const InteractiveInkFeatureFactory splashFactory = _InkRippleFactory(); + + static final Animatable<double> _easeCurveTween = CurveTween(curve: Curves.ease); + static final Animatable<double> _fadeOutIntervalTween = CurveTween(curve: const Interval(_kFadeOutIntervalStart, 1.0)); + + @override + void confirm() { + _radiusController + ..duration = _kRadiusDuration + ..forward(); + // This confirm may have been preceded by a cancel. + _fadeInController.forward(); + _fadeOutController.animateTo(1.0, duration: _kFadeOutDuration); + } + + @override + void cancel() { + _fadeInController.stop(); + // Watch out: setting _fadeOutController's value to 1.0 will + // trigger a call to _handleAlphaStatusChanged() which will + // dispose _fadeOutController. + final double fadeOutValue = 1.0 - _fadeInController.value; + _fadeOutController.value = fadeOutValue; + if (fadeOutValue < 1.0) { + _fadeOutController.animateTo(1.0, duration: _kCancelDuration); + } + } + + void _handleAlphaStatusChanged(AnimationStatus status) { + if (status == AnimationStatus.completed) { + dispose(); + } + } + + @override + void dispose() { + _radiusController.dispose(); + _fadeInController.dispose(); + _fadeOutController.dispose(); + super.dispose(); + } + + @override + void paintFeature(Canvas canvas, Matrix4 transform) { + final int alpha = _fadeInController.isAnimating ? _fadeIn.value : _fadeOut.value; + final Paint paint = Paint()..color = color.withAlpha(alpha); + Rect? rect; + if (_clipCallback != null) { + rect = _clipCallback(); + } + // Splash moves to the center of the reference box. + final Offset center = Offset.lerp( + _position, + rect != null ? rect.center : referenceBox.size.center(Offset.zero), + Curves.ease.transform(_radiusController.value), + )!; + paintInkCircle( + canvas: canvas, + transform: transform, + paint: paint, + center: center, + textDirection: _textDirection, + radius: _radius.value, + customBorder: customBorder, + borderRadius: _borderRadius, + clipCallback: _clipCallback, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_sparkle.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_sparkle.dart new file mode 100644 index 0000000000000000000000000000000000000000..798604985aec83e653666cbb007a01d9c3fb94f5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_sparkle.dart @@ -0,0 +1,515 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui; + +import 'package:flutter/widgets.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'ink_well.dart'; +import 'material.dart'; + +/// Begin a Material 3 ink sparkle ripple, centered at the tap or click position +/// relative to the [referenceBox]. +/// +/// This effect relies on a shader and therefore is unsupported on the Flutter +/// Web HTML backend. +/// +/// To use this effect, pass an instance of [splashFactory] to the +/// `splashFactory` parameter of either the Material [ThemeData] or any +/// component that has a `splashFactory` parameter, such as buttons: +/// - [ElevatedButton] +/// - [TextButton] +/// - [OutlinedButton] +/// +/// The [controller] argument is typically obtained via +/// `Material.of(context)`. +/// +/// If [containedInkWell] is true, then the effect will be sized to fit +/// the well rectangle, and clipped to it when drawn. The well +/// rectangle is the box returned by [rectCallback], if provided, or +/// otherwise is the bounds of the [referenceBox]. +/// +/// If [containedInkWell] is false, then [rectCallback] should be null. +/// The ink ripple is clipped only to the edges of the [Material]. +/// This is the default. +/// +/// When the ripple is removed, [onRemoved] will be called. +/// +/// {@tool snippet} +/// +/// For typical use, pass the [InkSparkle.splashFactory] to the `splashFactory` +/// parameter of a button style or [ThemeData]. +/// +/// ```dart +/// ElevatedButton( +/// style: ElevatedButton.styleFrom(splashFactory: InkSparkle.splashFactory), +/// child: const Text('Sparkle!'), +/// onPressed: () { }, +/// ) +/// ``` +/// {@end-tool} +class InkSparkle extends InteractiveInkFeature { + /// Begin a sparkly ripple effect, centered at [position] relative to + /// [referenceBox]. + /// + /// The [color] defines the color of the splash itself. The sparkles are + /// always white. + /// + /// The [controller] argument is typically obtained via + /// `Material.of(context)`. + /// + /// [textDirection] is used by [customBorder] if it is non-null. This allows + /// the [customBorder]'s path to be properly defined if it was the path was + /// expressed in terms of "start" and "end" instead of + /// "left" and "right". + /// + /// If [containedInkWell] is true, then the ripple will be sized to fit + /// the well rectangle, then clipped to it when drawn. The well + /// rectangle is the box returned by [rectCallback], if provided, or + /// otherwise is the bounds of the [referenceBox]. + /// + /// If [containedInkWell] is false, then [rectCallback] should be null. + /// The ink ripple is clipped only to the edges of the [Material]. + /// This is the default. + /// + /// Clipping can happen in 3 different ways: + /// 1. If [customBorder] is provided, it is used to determine the path for + /// clipping. + /// 2. If [customBorder] is null, and [borderRadius] is provided, then the + /// canvas is clipped by an [RRect] created from [borderRadius]. + /// 3. If [borderRadius] is the default [BorderRadius.zero], then the canvas + /// is clipped with [rectCallback]. + /// When the ripple is removed, [onRemoved] will be called. + /// + /// [turbulenceSeed] can be passed if a non random seed should be used for + /// the turbulence and sparkles. By default, the seed is a random number + /// between 0.0 and 1000.0. + /// + /// Turbulence is an input to the shader and helps to provides a more natural, + /// non-circular, "splash" effect. + /// + /// Sparkle randomization is also driven by the [turbulenceSeed]. Sparkles are + /// identified in the shader as "noise", and the sparkles are derived from + /// pseudorandom triangular noise. + InkSparkle({ + required super.controller, + required super.referenceBox, + required super.color, + required Offset position, + required TextDirection textDirection, + bool containedInkWell = true, + RectCallback? rectCallback, + BorderRadius? borderRadius, + super.customBorder, + double? radius, + super.onRemoved, + double? turbulenceSeed, + }) : assert(containedInkWell || rectCallback == null), + _color = color, + _position = position, + _borderRadius = borderRadius ?? BorderRadius.zero, + _textDirection = textDirection, + _targetRadius = (radius ?? _getTargetRadius( + referenceBox, + containedInkWell, + rectCallback, + position, + ) + ) * _targetRadiusMultiplier, + _clipCallback = _getClipCallback(referenceBox, containedInkWell, rectCallback) { + // InkSparkle will not be painted until the async compilation completes. + _InkSparkleFactory.initializeShader(); + controller.addInkFeature(this); + + // Immediately begin animating the ink. + _animationController = AnimationController( + duration: _animationDuration, + vsync: controller.vsync, + )..addListener(controller.markNeedsPaint) + ..addStatusListener(_handleStatusChanged) + ..forward(); + + _radiusScale = TweenSequence<double>( + <TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: CurveTween(curve: Curves.fastOutSlowIn), + weight: 75, + ), + TweenSequenceItem<double>( + tween: ConstantTween<double>(1.0), + weight: 25, + ), + ], + ).animate(_animationController); + + // Functionally equivalent to Android 12's SkSL: + //`return mix(u_touch, u_resolution, saturate(in_radius_scale * 2.0))` + final Tween<Vector2> centerTween = Tween<Vector2>( + begin: Vector2.array(<double>[_position.dx, _position.dy]), + end: Vector2.array(<double>[referenceBox.size.width / 2, referenceBox.size.height / 2]), + ); + final Animation<double> centerProgress = TweenSequence<double>( + <TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: Tween<double>(begin: 0.0, end: 1.0), + weight: 50, + ), + TweenSequenceItem<double>( + tween: ConstantTween<double>(1.0), + weight: 50, + ), + ], + ).animate(_radiusScale); + _center = centerTween.animate(centerProgress); + + _alpha = TweenSequence<double>( + <TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: Tween<double>(begin: 0.0, end: 1.0), + weight: 13, + ), + TweenSequenceItem<double>( + tween: ConstantTween<double>(1.0), + weight: 27, + ), + TweenSequenceItem<double>( + tween: Tween<double>(begin: 1.0, end: 0.0), + weight: 60, + ), + ], + ).animate(_animationController); + + _sparkleAlpha = TweenSequence<double>( + <TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: Tween<double>(begin: 0.0, end: 1.0), + weight: 13, + ), + TweenSequenceItem<double>( + tween: ConstantTween<double>(1.0), + weight: 27, + ), + TweenSequenceItem<double>( + tween: Tween<double>(begin: 1.0, end: 0.0), + weight: 50, + ), + ], + ).animate(_animationController); + + // Creates an element of randomness so that ink emanating from the same + // pixel have slightly different rings and sparkles. + assert((){ + // In tests, randomness can cause flakes. So if a seed has not + // already been specified (i.e. for the purpose of the test), set it to + // the constant turbulence seed. + turbulenceSeed ??= _InkSparkleFactory.constantSeed; + return true; + }()); + _turbulenceSeed = turbulenceSeed ?? math.Random().nextDouble() * 1000.0; + } + + void _handleStatusChanged(AnimationStatus status) { + if (status == AnimationStatus.completed) { + dispose(); + } + } + + static const Duration _animationDuration = Duration(milliseconds: 617); + static const double _targetRadiusMultiplier = 2.3; + static const double _rotateRight = math.pi * 0.0078125; + static const double _rotateLeft = -_rotateRight; + static const double _noiseDensity = 2.1; + + late AnimationController _animationController; + + // The Android 12 version has these values calculated in the GLSL. They are + // constant for every pixel in the animation, so the Flutter implementation + // computes these animation values in software in order to simplify the shader + // implementation and provide better performance on most devices. + late Animation<Vector2> _center; + late Animation<double> _radiusScale; + late Animation<double> _alpha; + late Animation<double> _sparkleAlpha; + + late double _turbulenceSeed; + + final Color _color; + final Offset _position; + final BorderRadius _borderRadius; + final double _targetRadius; + final RectCallback? _clipCallback; + final TextDirection _textDirection; + + late final ui.FragmentShader _fragmentShader; + bool _fragmentShaderInitialized = false; + + /// Used to specify this type of ink splash for an [InkWell], [InkResponse], + /// material [Theme], or [ButtonStyle]. + /// + /// Since no [turbulenceSeed] is passed, the effect will be random for + /// subsequent presses in the same position. + static const InteractiveInkFeatureFactory splashFactory = _InkSparkleFactory(); + + /// Used to specify this type of ink splash for an [InkWell], [InkResponse], + /// material [Theme], or [ButtonStyle]. + /// + /// Since a [turbulenceSeed] is passed, the effect will not be random for + /// subsequent presses in the same position. This can be used for testing. + static const InteractiveInkFeatureFactory constantTurbulenceSeedSplashFactory = _InkSparkleFactory.constantTurbulenceSeed(); + + @override + void dispose() { + _animationController.stop(); + _animationController.dispose(); + if (_fragmentShaderInitialized) { + _fragmentShader.dispose(); + } + super.dispose(); + } + + @override + void paintFeature(Canvas canvas, Matrix4 transform) { + assert(_animationController.isAnimating); + + // InkSparkle can only paint if its shader has been compiled. + if (_InkSparkleFactory._program == null) { + // Skipping paintFeature because the shader it relies on is not ready to + // be used. InkSparkleFactory.initializeShader must complete + // before InkSparkle can paint. + return; + } + + if (!_fragmentShaderInitialized) { + _fragmentShader = _InkSparkleFactory._program!.fragmentShader(); + _fragmentShaderInitialized = true; + } + + canvas.save(); + _transformCanvas(canvas: canvas, transform: transform); + if (_clipCallback != null) { + _clipCanvas( + canvas: canvas, + clipCallback: _clipCallback, + textDirection: _textDirection, + customBorder: customBorder, + borderRadius: _borderRadius, + ); + } + + _updateFragmentShader(); + + final Paint paint = Paint()..shader = _fragmentShader; + if (_clipCallback != null) { + canvas.drawRect(_clipCallback(), paint); + } else { + canvas.drawPaint(paint); + } + canvas.restore(); + } + + double get _width => referenceBox.size.width; + double get _height => referenceBox.size.height; + + + /// All double values for uniforms come from the Android 12 ripple + /// implementation from the following files: + /// - https://cs.android.com/android/platform/superproject/+/master:frameworks/base/graphics/java/android/graphics/drawable/RippleShader.java + /// - https://cs.android.com/android/platform/superproject/+/master:frameworks/base/graphics/java/android/graphics/drawable/RippleDrawable.java + /// - https://cs.android.com/android/platform/superproject/+/master:frameworks/base/graphics/java/android/graphics/drawable/RippleAnimationSession.java + void _updateFragmentShader() { + const double turbulenceScale = 1.5; + final double turbulencePhase = _turbulenceSeed + _radiusScale.value; + final double noisePhase = turbulencePhase; + final double rotation1 = turbulencePhase * _rotateRight + 1.7 * math.pi; + final double rotation2 = turbulencePhase * _rotateLeft + 2.0 * math.pi; + final double rotation3 = turbulencePhase * _rotateRight + 2.75 * math.pi; + + _fragmentShader + // uColor + ..setFloat(0, _color.red / 255.0) + ..setFloat(1, _color.green / 255.0) + ..setFloat(2, _color.blue / 255.0) + ..setFloat(3, _color.alpha / 255.0) + // Composite 1 (u_alpha, u_sparkle_alpha, u_blur, u_radius_scale) + ..setFloat(4, _alpha.value) + ..setFloat(5, _sparkleAlpha.value) + ..setFloat(6, 1.0) + ..setFloat(7, _radiusScale.value) + // uCenter + ..setFloat(8, _center.value.x) + ..setFloat(9, _center.value.y) + // uMaxRadius + ..setFloat(10, _targetRadius) + // uResolutionScale + ..setFloat(11, 1.0 / _width) + ..setFloat(12, 1.0 / _height) + // uNoiseScale + ..setFloat(13, _noiseDensity / _width) + ..setFloat(14, _noiseDensity / _height) + // uNoisePhase + ..setFloat(15, noisePhase / 1000.0) + // uCircle1 + ..setFloat(16, turbulenceScale * 0.5 + (turbulencePhase * 0.01 * math.cos(turbulenceScale * 0.55))) + ..setFloat(17, turbulenceScale * 0.5 + (turbulencePhase * 0.01 * math.sin(turbulenceScale * 0.55))) + // uCircle2 + ..setFloat(18, turbulenceScale * 0.2 + (turbulencePhase * -0.0066 * math.cos(turbulenceScale * 0.45))) + ..setFloat(19, turbulenceScale * 0.2 + (turbulencePhase * -0.0066 * math.sin(turbulenceScale * 0.45))) + // uCircle3 + ..setFloat(20, turbulenceScale + (turbulencePhase * -0.0066 * math.cos(turbulenceScale * 0.35))) + ..setFloat(21, turbulenceScale + (turbulencePhase * -0.0066 * math.sin(turbulenceScale * 0.35))) + // uRotation1 + ..setFloat(22, math.cos(rotation1)) + ..setFloat(23, math.sin(rotation1)) + // uRotation2 + ..setFloat(24, math.cos(rotation2)) + ..setFloat(25, math.sin(rotation2)) + // uRotation3 + ..setFloat(26, math.cos(rotation3)) + ..setFloat(27, math.sin(rotation3)); + } + + /// Transforms the canvas for an ink feature to be painted on the [canvas]. + /// + /// This should be called before painting ink features that do not use + /// [paintInkCircle]. + /// + /// The [transform] argument is the [Matrix4] transform that typically + /// shifts the coordinate space of the canvas to the space in which + /// the ink feature is to be painted. + /// + /// For examples on how the function is used, see [InkSparkle] and [paintInkCircle]. + void _transformCanvas({ + required Canvas canvas, + required Matrix4 transform, + }) { + final Offset? originOffset = MatrixUtils.getAsTranslation(transform); + if (originOffset == null) { + canvas.transform(transform.storage); + } else { + canvas.translate(originOffset.dx, originOffset.dy); + } + } + + /// Clips the canvas for an ink feature to be painted on the [canvas]. + /// + /// This should be called before painting ink features with [paintFeature] + /// that do not use [paintInkCircle]. + /// + /// The [clipCallback] is the callback used to obtain the [Rect] used for clipping + /// the ink effect. + /// + /// If [clipCallback] is null, no clipping is performed on the ink circle. + /// + /// The [textDirection] is used by [customBorder] if it is non-null. This + /// allows the [customBorder]'s path to be properly defined if the path was + /// expressed in terms of "start" and "end" instead of "left" and "right". + /// + /// For examples on how the function is used, see [InkSparkle]. + void _clipCanvas({ + required Canvas canvas, + required RectCallback clipCallback, + TextDirection? textDirection, + ShapeBorder? customBorder, + BorderRadius borderRadius = BorderRadius.zero, + }) { + final Rect rect = clipCallback(); + if (customBorder != null) { + canvas.clipPath( + customBorder.getOuterPath(rect, textDirection: textDirection)); + } else if (borderRadius != BorderRadius.zero) { + canvas.clipRRect(RRect.fromRectAndCorners( + rect, + topLeft: borderRadius.topLeft, + topRight: borderRadius.topRight, + bottomLeft: borderRadius.bottomLeft, + bottomRight: borderRadius.bottomRight, + )); + } else { + canvas.clipRect(rect); + } + } +} + +class _InkSparkleFactory extends InteractiveInkFeatureFactory { + const _InkSparkleFactory() : turbulenceSeed = null; + + const _InkSparkleFactory.constantTurbulenceSeed() : turbulenceSeed = _InkSparkleFactory.constantSeed; + + static const double constantSeed = 1337.0; + + static void initializeShader() { + if (!_initCalled) { + ui.FragmentProgram.fromAsset('shaders/ink_sparkle.frag').then( + (ui.FragmentProgram program) { + _program = program; + }, + ); + _initCalled = true; + } + } + + static bool _initCalled = false; + static ui.FragmentProgram? _program; + + final double? turbulenceSeed; + + @override + InteractiveInkFeature create({ + required MaterialInkController controller, + required RenderBox referenceBox, + required ui.Offset position, + required ui.Color color, + required ui.TextDirection textDirection, + bool containedInkWell = false, + RectCallback? rectCallback, + BorderRadius? borderRadius, + ShapeBorder? customBorder, + double? radius, + ui.VoidCallback? onRemoved, + }) { + return InkSparkle( + controller: controller, + referenceBox: referenceBox, + position: position, + color: color, + textDirection: textDirection, + containedInkWell: containedInkWell, + rectCallback: rectCallback, + borderRadius: borderRadius, + customBorder: customBorder, + radius: radius, + onRemoved: onRemoved, + turbulenceSeed: turbulenceSeed, + ); + } +} + +RectCallback? _getClipCallback( + RenderBox referenceBox, + bool containedInkWell, + RectCallback? rectCallback, +) { + if (rectCallback != null) { + assert(containedInkWell); + return rectCallback; + } + if (containedInkWell) { + return () => Offset.zero & referenceBox.size; + } + return null; +} + +double _getTargetRadius( + RenderBox referenceBox, + bool containedInkWell, + RectCallback? rectCallback, + Offset position, +) { + final Size size = rectCallback != null ? rectCallback().size : referenceBox.size; + final double d1 = size.bottomRight(Offset.zero).distance; + final double d2 = (size.topRight(Offset.zero) - size.bottomLeft(Offset.zero)).distance; + return math.max(d1, d2) / 2.0; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_splash.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_splash.dart new file mode 100644 index 0000000000000000000000000000000000000000..1a34ae2b7a4d33ede3417ec02595a4708d7b5728 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_splash.dart @@ -0,0 +1,217 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/widgets.dart'; + +import 'ink_well.dart'; +import 'material.dart'; + +const Duration _kUnconfirmedSplashDuration = Duration(seconds: 1); +const Duration _kSplashFadeDuration = Duration(milliseconds: 200); + +const double _kSplashInitialSize = 0.0; // logical pixels +const double _kSplashConfirmedVelocity = 1.0; // logical pixels per millisecond + +RectCallback? _getClipCallback(RenderBox referenceBox, bool containedInkWell, RectCallback? rectCallback) { + if (rectCallback != null) { + assert(containedInkWell); + return rectCallback; + } + if (containedInkWell) { + return () => Offset.zero & referenceBox.size; + } + return null; +} + +double _getTargetRadius(RenderBox referenceBox, bool containedInkWell, RectCallback? rectCallback, Offset position) { + if (containedInkWell) { + final Size size = rectCallback != null ? rectCallback().size : referenceBox.size; + return _getSplashRadiusForPositionInSize(size, position); + } + return Material.defaultSplashRadius; +} + +double _getSplashRadiusForPositionInSize(Size bounds, Offset position) { + final double d1 = (position - bounds.topLeft(Offset.zero)).distance; + final double d2 = (position - bounds.topRight(Offset.zero)).distance; + final double d3 = (position - bounds.bottomLeft(Offset.zero)).distance; + final double d4 = (position - bounds.bottomRight(Offset.zero)).distance; + return math.max(math.max(d1, d2), math.max(d3, d4)).ceilToDouble(); +} + +class _InkSplashFactory extends InteractiveInkFeatureFactory { + const _InkSplashFactory(); + + @override + InteractiveInkFeature create({ + required MaterialInkController controller, + required RenderBox referenceBox, + required Offset position, + required Color color, + required TextDirection textDirection, + bool containedInkWell = false, + RectCallback? rectCallback, + BorderRadius? borderRadius, + ShapeBorder? customBorder, + double? radius, + VoidCallback? onRemoved, + }) { + return InkSplash( + controller: controller, + referenceBox: referenceBox, + position: position, + color: color, + containedInkWell: containedInkWell, + rectCallback: rectCallback, + borderRadius: borderRadius, + customBorder: customBorder, + radius: radius, + onRemoved: onRemoved, + textDirection: textDirection, + ); + } +} + +/// A visual reaction on a piece of [Material] to user input. +/// +/// A circular ink feature whose origin starts at the input touch point +/// and whose radius expands from zero. +/// +/// This object is rarely created directly. Instead of creating an ink splash +/// directly, consider using an [InkResponse] or [InkWell] widget, which uses +/// gestures (such as tap and long-press) to trigger ink splashes. +/// +/// See also: +/// +/// * [InkRipple], which is an ink splash feature that expands more +/// aggressively than this class does. +/// * [InkResponse], which uses gestures to trigger ink highlights and ink +/// splashes in the parent [Material]. +/// * [InkWell], which is a rectangular [InkResponse] (the most common type of +/// ink response). +/// * [Material], which is the widget on which the ink splash is painted. +/// * [InkHighlight], which is an ink feature that emphasizes a part of a +/// [Material]. +/// * [Ink], a convenience widget for drawing images and other decorations on +/// Material widgets. +class InkSplash extends InteractiveInkFeature { + /// Begin a splash, centered at position relative to [referenceBox]. + /// + /// The [controller] argument is typically obtained via + /// `Material.of(context)`. + /// + /// If `containedInkWell` is true, then the splash will be sized to fit + /// the well rectangle, then clipped to it when drawn. The well + /// rectangle is the box returned by `rectCallback`, if provided, or + /// otherwise is the bounds of the [referenceBox]. + /// + /// If `containedInkWell` is false, then `rectCallback` should be null. + /// The ink splash is clipped only to the edges of the [Material]. + /// This is the default. + /// + /// When the splash is removed, `onRemoved` will be called. + InkSplash({ + required MaterialInkController controller, + required super.referenceBox, + required TextDirection textDirection, + Offset? position, + required Color color, + bool containedInkWell = false, + RectCallback? rectCallback, + BorderRadius? borderRadius, + super.customBorder, + double? radius, + super.onRemoved, + }) : _position = position, + _borderRadius = borderRadius ?? BorderRadius.zero, + _targetRadius = radius ?? _getTargetRadius(referenceBox, containedInkWell, rectCallback, position!), + _clipCallback = _getClipCallback(referenceBox, containedInkWell, rectCallback), + _repositionToReferenceBox = !containedInkWell, + _textDirection = textDirection, + super(controller: controller, color: color) { + _radiusController = AnimationController(duration: _kUnconfirmedSplashDuration, vsync: controller.vsync) + ..addListener(controller.markNeedsPaint) + ..forward(); + _radius = _radiusController.drive(Tween<double>( + begin: _kSplashInitialSize, + end: _targetRadius, + )); + _alphaController = AnimationController(duration: _kSplashFadeDuration, vsync: controller.vsync) + ..addListener(controller.markNeedsPaint) + ..addStatusListener(_handleAlphaStatusChanged); + _alpha = _alphaController!.drive(IntTween( + begin: color.alpha, + end: 0, + )); + + controller.addInkFeature(this); + } + + final Offset? _position; + final BorderRadius _borderRadius; + final double _targetRadius; + final RectCallback? _clipCallback; + final bool _repositionToReferenceBox; + final TextDirection _textDirection; + + late Animation<double> _radius; + late AnimationController _radiusController; + + late Animation<int> _alpha; + AnimationController? _alphaController; + + /// Used to specify this type of ink splash for an [InkWell], [InkResponse], + /// material [Theme], or [ButtonStyle]. + static const InteractiveInkFeatureFactory splashFactory = _InkSplashFactory(); + + @override + void confirm() { + final int duration = (_targetRadius / _kSplashConfirmedVelocity).floor(); + _radiusController + ..duration = Duration(milliseconds: duration) + ..forward(); + _alphaController!.forward(); + } + + @override + void cancel() { + _alphaController?.forward(); + } + + void _handleAlphaStatusChanged(AnimationStatus status) { + if (status == AnimationStatus.completed) { + dispose(); + } + } + + @override + void dispose() { + _radiusController.dispose(); + _alphaController!.dispose(); + _alphaController = null; + super.dispose(); + } + + @override + void paintFeature(Canvas canvas, Matrix4 transform) { + final Paint paint = Paint()..color = color.withAlpha(_alpha.value); + Offset? center = _position; + if (_repositionToReferenceBox) { + center = Offset.lerp(center, referenceBox.size.center(Offset.zero), _radiusController.value); + } + paintInkCircle( + canvas: canvas, + transform: transform, + paint: paint, + center: center!, + textDirection: _textDirection, + radius: _radius.value, + customBorder: customBorder, + borderRadius: _borderRadius, + clipCallback: _clipCallback, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_well.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_well.dart new file mode 100644 index 0000000000000000000000000000000000000000..8b92f28a9d9153efa5994e4f7656db1a683785aa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/ink_well.dart @@ -0,0 +1,1491 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:collection'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'debug.dart'; +import 'feedback.dart'; +import 'ink_highlight.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// An ink feature that displays a [color] "splash" in response to a user +/// gesture that can be confirmed or canceled. +/// +/// Subclasses call [confirm] when an input gesture is recognized. For +/// example a press event might trigger an ink feature that's confirmed +/// when the corresponding up event is seen. +/// +/// Subclasses call [cancel] when an input gesture is aborted before it +/// is recognized. For example a press event might trigger an ink feature +/// that's canceled when the pointer is dragged out of the reference +/// box. +/// +/// The [InkWell] and [InkResponse] widgets generate instances of this +/// class. +abstract class InteractiveInkFeature extends InkFeature { + /// Creates an InteractiveInkFeature. + InteractiveInkFeature({ + required super.controller, + required super.referenceBox, + required Color color, + ShapeBorder? customBorder, + super.onRemoved, + }) : _color = color, + _customBorder = customBorder; + + /// Called when the user input that triggered this feature's appearance was confirmed. + /// + /// Typically causes the ink to propagate faster across the material. By default this + /// method does nothing. + void confirm() { } + + /// Called when the user input that triggered this feature's appearance was canceled. + /// + /// Typically causes the ink to gradually disappear. By default this method does + /// nothing. + void cancel() { } + + /// The ink's color. + Color get color => _color; + Color _color; + set color(Color value) { + if (value == _color) { + return; + } + _color = value; + controller.markNeedsPaint(); + } + + /// The ink's optional custom border. + ShapeBorder? get customBorder => _customBorder; + ShapeBorder? _customBorder; + set customBorder(ShapeBorder? value) { + if (value == _customBorder) { + return; + } + _customBorder = value; + controller.markNeedsPaint(); + } + + /// Draws an ink splash or ink ripple on the passed in [Canvas]. + /// + /// The [transform] argument is the [Matrix4] transform that typically + /// shifts the coordinate space of the canvas to the space in which + /// the ink circle is to be painted. + /// + /// [center] is the [Offset] from origin of the canvas where the center + /// of the circle is drawn. + /// + /// [paint] takes a [Paint] object that describes the styles used to draw the ink circle. + /// For example, [paint] can specify properties like color, strokewidth, colorFilter. + /// + /// [radius] is the radius of ink circle to be drawn on canvas. + /// + /// [clipCallback] is the callback used to obtain the [Rect] used for clipping the ink effect. + /// If [clipCallback] is null, no clipping is performed on the ink circle. + /// + /// Clipping can happen in 3 different ways: + /// 1. If [customBorder] is provided, it is used to determine the path + /// for clipping. + /// 2. If [customBorder] is null, and [borderRadius] is provided, the canvas + /// is clipped by an [RRect] created from [clipCallback] and [borderRadius]. + /// 3. If [borderRadius] is the default [BorderRadius.zero], then the [Rect] provided + /// by [clipCallback] is used for clipping. + /// + /// [textDirection] is used by [customBorder] if it is non-null. This allows the [customBorder]'s path + /// to be properly defined if it was the path was expressed in terms of "start" and "end" instead of + /// "left" and "right". + /// + /// For examples on how the function is used, see [InkSplash] and [InkRipple]. + @protected + void paintInkCircle({ + required Canvas canvas, + required Matrix4 transform, + required Paint paint, + required Offset center, + required double radius, + TextDirection? textDirection, + ShapeBorder? customBorder, + BorderRadius borderRadius = BorderRadius.zero, + RectCallback? clipCallback, + }) { + + final Offset? originOffset = MatrixUtils.getAsTranslation(transform); + canvas.save(); + if (originOffset == null) { + canvas.transform(transform.storage); + } else { + canvas.translate(originOffset.dx, originOffset.dy); + } + if (clipCallback != null) { + final Rect rect = clipCallback(); + if (customBorder != null) { + canvas.clipPath(customBorder.getOuterPath(rect, textDirection: textDirection)); + } else if (borderRadius != BorderRadius.zero) { + canvas.clipRRect(RRect.fromRectAndCorners( + rect, + topLeft: borderRadius.topLeft, topRight: borderRadius.topRight, + bottomLeft: borderRadius.bottomLeft, bottomRight: borderRadius.bottomRight, + )); + } else { + canvas.clipRect(rect); + } + } + canvas.drawCircle(center, radius, paint); + canvas.restore(); + } +} + +/// An encapsulation of an [InteractiveInkFeature] constructor used by +/// [InkWell], [InkResponse], and [ThemeData]. +/// +/// Interactive ink feature implementations should provide a static const +/// `splashFactory` value that's an instance of this class. The `splashFactory` +/// can be used to configure an [InkWell], [InkResponse] or [ThemeData]. +/// +/// See also: +/// +/// * [InkSplash.splashFactory] +/// * [InkRipple.splashFactory] +abstract class InteractiveInkFeatureFactory { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + /// + /// Subclasses should provide a const constructor. + const InteractiveInkFeatureFactory(); + + /// The factory method. + /// + /// Subclasses should override this method to return a new instance of an + /// [InteractiveInkFeature]. + @factory + InteractiveInkFeature create({ + required MaterialInkController controller, + required RenderBox referenceBox, + required Offset position, + required Color color, + required TextDirection textDirection, + bool containedInkWell = false, + RectCallback? rectCallback, + BorderRadius? borderRadius, + ShapeBorder? customBorder, + double? radius, + VoidCallback? onRemoved, + }); +} + +abstract class _ParentInkResponseState { + void markChildInkResponsePressed(_ParentInkResponseState childState, bool value); +} + +class _ParentInkResponseProvider extends InheritedWidget { + const _ParentInkResponseProvider({ + required this.state, + required super.child, + }); + + final _ParentInkResponseState state; + + @override + bool updateShouldNotify(_ParentInkResponseProvider oldWidget) => state != oldWidget.state; + + static _ParentInkResponseState? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<_ParentInkResponseProvider>()?.state; + } +} + +typedef _GetRectCallback = RectCallback? Function(RenderBox referenceBox); +typedef _CheckContext = bool Function(BuildContext context); + +/// An area of a [Material] that responds to touch. Has a configurable shape and +/// can be configured to clip splashes that extend outside its bounds or not. +/// +/// For a variant of this widget that is specialized for rectangular areas that +/// always clip splashes, see [InkWell]. +/// +/// An [InkResponse] widget does two things when responding to a tap: +/// +/// * It starts to animate a _highlight_. The shape of the highlight is +/// determined by [highlightShape]. If it is a [BoxShape.circle], the +/// default, then the highlight is a circle of fixed size centered in the +/// [InkResponse]. If it is [BoxShape.rectangle], then the highlight is a box +/// the size of the [InkResponse] itself, unless [getRectCallback] is +/// provided, in which case that callback defines the rectangle. The color of +/// the highlight is set by [highlightColor]. +/// +/// * Simultaneously, it starts to animate a _splash_. This is a growing circle +/// initially centered on the tap location. If this is a [containedInkWell], +/// the splash grows to the [radius] while remaining centered at the tap +/// location. Otherwise, the splash migrates to the center of the box as it +/// grows. +/// +/// The following two diagrams show how [InkResponse] looks when tapped if the +/// [highlightShape] is [BoxShape.circle] (the default) and [containedInkWell] +/// is false (also the default). +/// +/// The first diagram shows how it looks if the [InkResponse] is relatively +/// large: +/// +/// ![The highlight is a disc centered in the box, smaller than the child widget.](https://flutter.github.io/assets-for-api-docs/assets/material/ink_response_large.png) +/// +/// The second diagram shows how it looks if the [InkResponse] is small: +/// +/// ![The highlight is a disc overflowing the box, centered on the child.](https://flutter.github.io/assets-for-api-docs/assets/material/ink_response_small.png) +/// +/// The main thing to notice from these diagrams is that the splashes happily +/// exceed the bounds of the widget (because [containedInkWell] is false). +/// +/// The following diagram shows the effect when the [InkResponse] has a +/// [highlightShape] of [BoxShape.rectangle] with [containedInkWell] set to +/// true. These are the values used by [InkWell]. +/// +/// ![The highlight is a rectangle the size of the box.](https://flutter.github.io/assets-for-api-docs/assets/material/ink_well.png) +/// +/// The [InkResponse] widget must have a [Material] widget as an ancestor. The +/// [Material] widget is where the ink reactions are actually painted. This +/// matches the Material Design premise wherein the [Material] is what is +/// actually reacting to touches by spreading ink. +/// +/// If a Widget uses this class directly, it should include the following line +/// at the top of its build function to call [debugCheckHasMaterial]: +/// +/// ```dart +/// assert(debugCheckHasMaterial(context)); +/// ``` +/// +/// ## Troubleshooting +/// +/// ### The ink splashes aren't visible! +/// +/// If there is an opaque graphic, e.g. painted using a [Container], [Image], or +/// [DecoratedBox], between the [Material] widget and the [InkResponse] widget, +/// then the splash won't be visible because it will be under the opaque graphic. +/// This is because ink splashes draw on the underlying [Material] itself, as +/// if the ink was spreading inside the material. +/// +/// The [Ink] widget can be used as a replacement for [Image], [Container], or +/// [DecoratedBox] to ensure that the image or decoration also paints in the +/// [Material] itself, below the ink. +/// +/// If this is not possible for some reason, e.g. because you are using an +/// opaque [CustomPaint] widget, alternatively consider using a second +/// [Material] above the opaque widget but below the [InkResponse] (as an +/// ancestor to the ink response). The [MaterialType.transparency] material +/// kind can be used for this purpose. +/// +/// See also: +/// +/// * [GestureDetector], for listening for gestures without ink splashes. +/// * [ElevatedButton] and [TextButton], two kinds of buttons in Material Design. +/// * [IconButton], which combines [InkResponse] with an [Icon]. +class InkResponse extends StatelessWidget { + /// Creates an area of a [Material] that responds to touch. + /// + /// Must have an ancestor [Material] widget in which to cause ink reactions. + const InkResponse({ + super.key, + this.child, + this.onTap, + this.onTapDown, + this.onTapUp, + this.onTapCancel, + this.onDoubleTap, + this.onLongPress, + this.onSecondaryTap, + this.onSecondaryTapUp, + this.onSecondaryTapDown, + this.onSecondaryTapCancel, + this.onHighlightChanged, + this.onHover, + this.mouseCursor, + this.containedInkWell = false, + this.highlightShape = BoxShape.circle, + this.radius, + this.borderRadius, + this.customBorder, + this.focusColor, + this.hoverColor, + this.highlightColor, + this.overlayColor, + this.splashColor, + this.splashFactory, + this.enableFeedback = true, + this.excludeFromSemantics = false, + this.focusNode, + this.canRequestFocus = true, + this.onFocusChange, + this.autofocus = false, + this.statesController, + this.hoverDuration, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// Called when the user taps this part of the material. + final GestureTapCallback? onTap; + + /// Called when the user taps down this part of the material. + final GestureTapDownCallback? onTapDown; + + /// Called when the user releases a tap that was started on this part of the + /// material. [onTap] is called immediately after. + final GestureTapUpCallback? onTapUp; + + /// Called when the user cancels a tap that was started on this part of the + /// material. + final GestureTapCallback? onTapCancel; + + /// Called when the user double taps this part of the material. + final GestureTapCallback? onDoubleTap; + + /// Called when the user long-presses on this part of the material. + final GestureLongPressCallback? onLongPress; + + /// Called when the user taps this part of the material with a secondary button. + final GestureTapCallback? onSecondaryTap; + + /// Called when the user taps down on this part of the material with a + /// secondary button. + final GestureTapDownCallback? onSecondaryTapDown; + + /// Called when the user releases a secondary button tap that was started on + /// this part of the material. [onSecondaryTap] is called immediately after. + final GestureTapUpCallback? onSecondaryTapUp; + + /// Called when the user cancels a secondary button tap that was started on + /// this part of the material. + final GestureTapCallback? onSecondaryTapCancel; + + /// Called when this part of the material either becomes highlighted or stops + /// being highlighted. + /// + /// The value passed to the callback is true if this part of the material has + /// become highlighted and false if this part of the material has stopped + /// being highlighted. + /// + /// If all of [onTap], [onDoubleTap], and [onLongPress] become null while a + /// gesture is ongoing, then [onTapCancel] will be fired and + /// [onHighlightChanged] will be fired with the value false _during the + /// build_. This means, for instance, that in that scenario [State.setState] + /// cannot be called. + final ValueChanged<bool>? onHighlightChanged; + + /// Called when a pointer enters or exits the ink response area. + /// + /// The value passed to the callback is true if a pointer has entered this + /// part of the material and false if a pointer has exited this part of the + /// material. + final ValueChanged<bool>? onHover; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// + /// If this property is null, [MaterialStateMouseCursor.clickable] will be used. + final MouseCursor? mouseCursor; + + /// Whether this ink response should be clipped its bounds. + /// + /// This flag also controls whether the splash migrates to the center of the + /// [InkResponse] or not. If [containedInkWell] is true, the splash remains + /// centered around the tap location. If it is false, the splash migrates to + /// the center of the [InkResponse] as it grows. + /// + /// See also: + /// + /// * [highlightShape], the shape of the focus, hover, and pressed + /// highlights. + /// * [borderRadius], which controls the corners when the box is a rectangle. + /// * [getRectCallback], which controls the size and position of the box when + /// it is a rectangle. + final bool containedInkWell; + + /// The shape (e.g., circle, rectangle) to use for the highlight drawn around + /// this part of the material when pressed, hovered over, or focused. + /// + /// The same shape is used for the pressed highlight (see [highlightColor]), + /// the focus highlight (see [focusColor]), and the hover highlight (see + /// [hoverColor]). + /// + /// If the shape is [BoxShape.circle], then the highlight is centered on the + /// [InkResponse]. If the shape is [BoxShape.rectangle], then the highlight + /// fills the [InkResponse], or the rectangle provided by [getRectCallback] if + /// the callback is specified. + /// + /// See also: + /// + /// * [containedInkWell], which controls clipping behavior. + /// * [borderRadius], which controls the corners when the box is a rectangle. + /// * [highlightColor], the color of the highlight. + /// * [getRectCallback], which controls the size and position of the box when + /// it is a rectangle. + final BoxShape highlightShape; + + /// The radius of the ink splash. + /// + /// Splashes grow up to this size. By default, this size is determined from + /// the size of the rectangle provided by [getRectCallback], or the size of + /// the [InkResponse] itself. + /// + /// See also: + /// + /// * [splashColor], the color of the splash. + /// * [splashFactory], which defines the appearance of the splash. + final double? radius; + + /// The border radius of the containing rectangle. This is effective only if + /// [highlightShape] is [BoxShape.rectangle]. + /// + /// If this is null, it is interpreted as [BorderRadius.zero]. + final BorderRadius? borderRadius; + + /// The custom clip border. + /// + /// If this is null, the ink response will not clip its content. + final ShapeBorder? customBorder; + + /// The color of the ink response when the parent widget is focused. If this + /// property is null then the focus color of the theme, + /// [ThemeData.focusColor], will be used. + /// + /// See also: + /// + /// * [highlightShape], the shape of the focus, hover, and pressed + /// highlights. + /// * [hoverColor], the color of the hover highlight. + /// * [splashColor], the color of the splash. + /// * [splashFactory], which defines the appearance of the splash. + final Color? focusColor; + + /// The color of the ink response when a pointer is hovering over it. If this + /// property is null then the hover color of the theme, + /// [ThemeData.hoverColor], will be used. + /// + /// See also: + /// + /// * [highlightShape], the shape of the focus, hover, and pressed + /// highlights. + /// * [highlightColor], the color of the pressed highlight. + /// * [focusColor], the color of the focus highlight. + /// * [splashColor], the color of the splash. + /// * [splashFactory], which defines the appearance of the splash. + final Color? hoverColor; + + /// The highlight color of the ink response when pressed. If this property is + /// null then the highlight color of the theme, [ThemeData.highlightColor], + /// will be used. + /// + /// See also: + /// + /// * [hoverColor], the color of the hover highlight. + /// * [focusColor], the color of the focus highlight. + /// * [highlightShape], the shape of the focus, hover, and pressed + /// highlights. + /// * [splashColor], the color of the splash. + /// * [splashFactory], which defines the appearance of the splash. + final Color? highlightColor; + + /// Defines the ink response focus, hover, and splash colors. + /// + /// This default null property can be used as an alternative to + /// [focusColor], [hoverColor], [highlightColor], and + /// [splashColor]. If non-null, it is resolved against one of + /// [MaterialState.focused], [MaterialState.hovered], and + /// [MaterialState.pressed]. It's convenient to use when the parent + /// widget can pass along its own MaterialStateProperty value for + /// the overlay color. + /// + /// [MaterialState.pressed] triggers a ripple (an ink splash), per + /// the current Material Design spec. The [overlayColor] doesn't map + /// a state to [highlightColor] because a separate highlight is not + /// used by the current design guidelines. See + /// https://material.io/design/interaction/states.html#pressed + /// + /// If the overlay color is null or resolves to null, then [focusColor], + /// [hoverColor], [splashColor] and their defaults are used instead. + /// + /// See also: + /// + /// * The Material Design specification for overlay colors and how they + /// match a component's state: + /// <https://material.io/design/interaction/states.html#anatomy>. + final MaterialStateProperty<Color?>? overlayColor; + + /// The splash color of the ink response. If this property is null then the + /// splash color of the theme, [ThemeData.splashColor], will be used. + /// + /// See also: + /// + /// * [splashFactory], which defines the appearance of the splash. + /// * [radius], the (maximum) size of the ink splash. + /// * [highlightColor], the color of the highlight. + final Color? splashColor; + + /// Defines the appearance of the splash. + /// + /// Defaults to the value of the theme's splash factory: [ThemeData.splashFactory]. + /// + /// See also: + /// + /// * [radius], the (maximum) size of the ink splash. + /// * [splashColor], the color of the splash. + /// * [highlightColor], the color of the highlight. + /// * [InkSplash.splashFactory], which defines the default splash. + /// * [InkRipple.splashFactory], which defines a splash that spreads out + /// more aggressively than the default. + final InteractiveInkFeatureFactory? splashFactory; + + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool enableFeedback; + + /// Whether to exclude the gestures introduced by this widget from the + /// semantics tree. + /// + /// For example, a long-press gesture for showing a tooltip is usually + /// excluded because the tooltip itself is included in the semantics + /// tree directly and so having a gesture to show it would result in + /// duplication of information. + final bool excludeFromSemantics; + + /// {@template flutter.material.inkwell.onFocusChange} + /// Handler called when the focus changes. + /// + /// Called with true if this widget's node gains focus, and false if it loses + /// focus. + /// {@endtemplate} + final ValueChanged<bool>? onFocusChange; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.canRequestFocus} + final bool canRequestFocus; + + /// The rectangle to use for the highlight effect and for clipping + /// the splash effects if [containedInkWell] is true. + /// + /// This method is intended to be overridden by descendants that + /// specialize [InkResponse] for unusual cases. For example, + /// [TableRowInkWell] implements this method to return the rectangle + /// corresponding to the row that the widget is in. + /// + /// The default behavior returns null, which is equivalent to + /// returning the referenceBox argument's bounding box (though + /// slightly more efficient). + RectCallback? getRectCallback(RenderBox referenceBox) => null; + + /// {@template flutter.material.inkwell.statesController} + /// Represents the interactive "state" of this widget in terms of + /// a set of [MaterialState]s, like [MaterialState.pressed] and + /// [MaterialState.focused]. + /// + /// Classes based on this one can provide their own + /// [MaterialStatesController] to which they've added listeners. + /// They can also update the controller's [MaterialStatesController.value] + /// however, this may only be done when it's safe to call + /// [State.setState], like in an event handler. + /// {@endtemplate} + final MaterialStatesController? statesController; + + /// The duration of the animation that animates the hover effect. + /// + /// The default is 50ms. + final Duration? hoverDuration; + + @override + Widget build(BuildContext context) { + final _ParentInkResponseState? parentState = _ParentInkResponseProvider.maybeOf(context); + return _InkResponseStateWidget( + onTap: onTap, + onTapDown: onTapDown, + onTapUp: onTapUp, + onTapCancel: onTapCancel, + onDoubleTap: onDoubleTap, + onLongPress: onLongPress, + onSecondaryTap: onSecondaryTap, + onSecondaryTapUp: onSecondaryTapUp, + onSecondaryTapDown: onSecondaryTapDown, + onSecondaryTapCancel: onSecondaryTapCancel, + onHighlightChanged: onHighlightChanged, + onHover: onHover, + mouseCursor: mouseCursor, + containedInkWell: containedInkWell, + highlightShape: highlightShape, + radius: radius, + borderRadius: borderRadius, + customBorder: customBorder, + focusColor: focusColor, + hoverColor: hoverColor, + highlightColor: highlightColor, + overlayColor: overlayColor, + splashColor: splashColor, + splashFactory: splashFactory, + enableFeedback: enableFeedback, + excludeFromSemantics: excludeFromSemantics, + focusNode: focusNode, + canRequestFocus: canRequestFocus, + onFocusChange: onFocusChange, + autofocus: autofocus, + parentState: parentState, + getRectCallback: getRectCallback, + debugCheckContext: debugCheckContext, + statesController: statesController, + hoverDuration: hoverDuration, + child: child, + ); + } + + /// Asserts that the given context satisfies the prerequisites for + /// this class. + /// + /// This method is intended to be overridden by descendants that + /// specialize [InkResponse] for unusual cases. For example, + /// [TableRowInkWell] implements this method to verify that the widget is + /// in a table. + @mustCallSuper + bool debugCheckContext(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasDirectionality(context)); + return true; + } +} + +class _InkResponseStateWidget extends StatefulWidget { + const _InkResponseStateWidget({ + this.child, + this.onTap, + this.onTapDown, + this.onTapUp, + this.onTapCancel, + this.onDoubleTap, + this.onLongPress, + this.onSecondaryTap, + this.onSecondaryTapUp, + this.onSecondaryTapDown, + this.onSecondaryTapCancel, + this.onHighlightChanged, + this.onHover, + this.mouseCursor, + this.containedInkWell = false, + this.highlightShape = BoxShape.circle, + this.radius, + this.borderRadius, + this.customBorder, + this.focusColor, + this.hoverColor, + this.highlightColor, + this.overlayColor, + this.splashColor, + this.splashFactory, + this.enableFeedback = true, + this.excludeFromSemantics = false, + this.focusNode, + this.canRequestFocus = true, + this.onFocusChange, + this.autofocus = false, + this.parentState, + this.getRectCallback, + required this.debugCheckContext, + this.statesController, + this.hoverDuration, + }); + + final Widget? child; + final GestureTapCallback? onTap; + final GestureTapDownCallback? onTapDown; + final GestureTapUpCallback? onTapUp; + final GestureTapCallback? onTapCancel; + final GestureTapCallback? onDoubleTap; + final GestureLongPressCallback? onLongPress; + final GestureTapCallback? onSecondaryTap; + final GestureTapUpCallback? onSecondaryTapUp; + final GestureTapDownCallback? onSecondaryTapDown; + final GestureTapCallback? onSecondaryTapCancel; + final ValueChanged<bool>? onHighlightChanged; + final ValueChanged<bool>? onHover; + final MouseCursor? mouseCursor; + final bool containedInkWell; + final BoxShape highlightShape; + final double? radius; + final BorderRadius? borderRadius; + final ShapeBorder? customBorder; + final Color? focusColor; + final Color? hoverColor; + final Color? highlightColor; + final MaterialStateProperty<Color?>? overlayColor; + final Color? splashColor; + final InteractiveInkFeatureFactory? splashFactory; + final bool enableFeedback; + final bool excludeFromSemantics; + final ValueChanged<bool>? onFocusChange; + final bool autofocus; + final FocusNode? focusNode; + final bool canRequestFocus; + final _ParentInkResponseState? parentState; + final _GetRectCallback? getRectCallback; + final _CheckContext debugCheckContext; + final MaterialStatesController? statesController; + final Duration? hoverDuration; + + @override + _InkResponseState createState() => _InkResponseState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final List<String> gestures = <String>[ + if (onTap != null) 'tap', + if (onDoubleTap != null) 'double tap', + if (onLongPress != null) 'long press', + if (onTapDown != null) 'tap down', + if (onTapUp != null) 'tap up', + if (onTapCancel != null) 'tap cancel', + if (onSecondaryTap != null) 'secondary tap', + if (onSecondaryTapUp != null) 'secondary tap up', + if (onSecondaryTapDown != null) 'secondary tap down', + if (onSecondaryTapCancel != null) 'secondary tap cancel' + ]; + properties.add(IterableProperty<String>('gestures', gestures, ifEmpty: '<none>')); + properties.add(DiagnosticsProperty<MouseCursor>('mouseCursor', mouseCursor)); + properties.add(DiagnosticsProperty<bool>('containedInkWell', containedInkWell, level: DiagnosticLevel.fine)); + properties.add(DiagnosticsProperty<BoxShape>( + 'highlightShape', + highlightShape, + description: '${containedInkWell ? "clipped to " : ""}$highlightShape', + showName: false, + )); + } +} + +/// Used to index the allocated highlights for the different types of highlights +/// in [_InkResponseState]. +enum _HighlightType { + pressed, + hover, + focus, +} + +class _InkResponseState extends State<_InkResponseStateWidget> + with AutomaticKeepAliveClientMixin<_InkResponseStateWidget> + implements _ParentInkResponseState +{ + Set<InteractiveInkFeature>? _splashes; + InteractiveInkFeature? _currentSplash; + bool _hovering = false; + final Map<_HighlightType, InkHighlight?> _highlights = <_HighlightType, InkHighlight?>{}; + late final Map<Type, Action<Intent>> _actionMap = <Type, Action<Intent>>{ + ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: activateOnIntent), + ButtonActivateIntent: CallbackAction<ButtonActivateIntent>(onInvoke: activateOnIntent), + }; + MaterialStatesController? internalStatesController; + + bool get highlightsExist => _highlights.values.where((InkHighlight? highlight) => highlight != null).isNotEmpty; + + final ObserverList<_ParentInkResponseState> _activeChildren = ObserverList<_ParentInkResponseState>(); + + static const Duration _activationDuration = Duration(milliseconds: 100); + Timer? _activationTimer; + + @override + void markChildInkResponsePressed(_ParentInkResponseState childState, bool value) { + final bool lastAnyPressed = _anyChildInkResponsePressed; + if (value) { + _activeChildren.add(childState); + } else { + _activeChildren.remove(childState); + } + final bool nowAnyPressed = _anyChildInkResponsePressed; + if (nowAnyPressed != lastAnyPressed) { + widget.parentState?.markChildInkResponsePressed(this, nowAnyPressed); + } + } + bool get _anyChildInkResponsePressed => _activeChildren.isNotEmpty; + + void activateOnIntent(Intent? intent) { + _activationTimer?.cancel(); + _activationTimer = null; + _startNewSplash(context: context); + _currentSplash?.confirm(); + _currentSplash = null; + if (widget.onTap != null) { + if (widget.enableFeedback) { + Feedback.forTap(context); + } + widget.onTap?.call(); + } + // Delay the call to `updateHighlight` to simulate a pressed delay + // and give MaterialStatesController listeners a chance to react. + _activationTimer = Timer(_activationDuration, () { + updateHighlight(_HighlightType.pressed, value: false); + }); + } + + void simulateTap([Intent? intent]) { + _startNewSplash(context: context); + handleTap(); + } + + void simulateLongPress() { + _startNewSplash(context: context); + handleLongPress(); + } + + void handleStatesControllerChange() { + // Force a rebuild to resolve widget.overlayColor, widget.mouseCursor + setState(() { }); + } + + MaterialStatesController get statesController => widget.statesController ?? internalStatesController!; + + void initStatesController() { + if (widget.statesController == null) { + internalStatesController = MaterialStatesController(); + } + statesController.update(MaterialState.disabled, !enabled); + statesController.addListener(handleStatesControllerChange); + } + + @override + void initState() { + super.initState(); + initStatesController(); + FocusManager.instance.addHighlightModeListener(handleFocusHighlightModeChange); + } + + @override + void didUpdateWidget(_InkResponseStateWidget oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.statesController != oldWidget.statesController) { + oldWidget.statesController?.removeListener(handleStatesControllerChange); + if (widget.statesController != null) { + internalStatesController?.dispose(); + internalStatesController = null; + } + initStatesController(); + } + if (widget.radius != oldWidget.radius || + widget.highlightShape != oldWidget.highlightShape || + widget.borderRadius != oldWidget.borderRadius) { + final InkHighlight? hoverHighlight = _highlights[_HighlightType.hover]; + if (hoverHighlight != null) { + hoverHighlight.dispose(); + updateHighlight(_HighlightType.hover, value: _hovering, callOnHover: false); + } + final InkHighlight? focusHighlight = _highlights[_HighlightType.focus]; + if (focusHighlight != null) { + focusHighlight.dispose(); + // Do not call updateFocusHighlights() here because it is called below + } + } + if (widget.customBorder != oldWidget.customBorder) { + _updateHighlightsAndSplashes(); + } + if (enabled != isWidgetEnabled(oldWidget)) { + statesController.update(MaterialState.disabled, !enabled); + if (!enabled) { + statesController.update(MaterialState.pressed, false); + // Remove the existing hover highlight immediately when enabled is false. + // Do not rely on updateHighlight or InkHighlight.deactivate to not break + // the expected lifecycle which is updating _hovering when the mouse exit. + // Manually updating _hovering here or calling InkHighlight.deactivate + // will lead to onHover not being called or call when it is not allowed. + final InkHighlight? hoverHighlight = _highlights[_HighlightType.hover]; + hoverHighlight?.dispose(); + } + // Don't call widget.onHover because many widgets, including the button + // widgets, apply setState to an ancestor context from onHover. + updateHighlight(_HighlightType.hover, value: _hovering, callOnHover: false); + } + updateFocusHighlights(); + } + + @override + void dispose() { + FocusManager.instance.removeHighlightModeListener(handleFocusHighlightModeChange); + statesController.removeListener(handleStatesControllerChange); + internalStatesController?.dispose(); + _activationTimer?.cancel(); + _activationTimer = null; + super.dispose(); + } + + @override + bool get wantKeepAlive => highlightsExist || (_splashes != null && _splashes!.isNotEmpty); + + Duration getFadeDurationForType(_HighlightType type) { + switch (type) { + case _HighlightType.pressed: + return const Duration(milliseconds: 200); + case _HighlightType.hover: + case _HighlightType.focus: + return widget.hoverDuration ?? const Duration(milliseconds: 50); + } + } + + void updateHighlight(_HighlightType type, { required bool value, bool callOnHover = true }) { + final InkHighlight? highlight = _highlights[type]; + void handleInkRemoval() { + assert(_highlights[type] != null); + _highlights[type] = null; + updateKeepAlive(); + } + + switch (type) { + case _HighlightType.pressed: + statesController.update(MaterialState.pressed, value); + case _HighlightType.hover: + if (callOnHover) { + statesController.update(MaterialState.hovered, value); + } + case _HighlightType.focus: + // see handleFocusUpdate() + break; + } + + if (type == _HighlightType.pressed) { + widget.parentState?.markChildInkResponsePressed(this, value); + } + if (value == (highlight != null && highlight.active)) { + return; + } + + if (value) { + if (highlight == null) { + Color? resolvedOverlayColor = widget.overlayColor?.resolve(statesController.value); + if (resolvedOverlayColor == null) { + // Use the backwards compatible defaults + final ThemeData theme = Theme.of(context); + switch (type) { + case _HighlightType.pressed: + resolvedOverlayColor = widget.highlightColor ?? theme.highlightColor; + case _HighlightType.focus: + resolvedOverlayColor = widget.focusColor ?? theme.focusColor; + case _HighlightType.hover: + resolvedOverlayColor = widget.hoverColor ?? theme.hoverColor; + } + } + final RenderBox referenceBox = context.findRenderObject()! as RenderBox; + _highlights[type] = InkHighlight( + controller: Material.of(context), + referenceBox: referenceBox, + color: enabled ? resolvedOverlayColor : resolvedOverlayColor.withAlpha(0), + shape: widget.highlightShape, + radius: widget.radius, + borderRadius: widget.borderRadius, + customBorder: widget.customBorder, + rectCallback: widget.getRectCallback!(referenceBox), + onRemoved: handleInkRemoval, + textDirection: Directionality.of(context), + fadeDuration: getFadeDurationForType(type), + ); + updateKeepAlive(); + } else { + highlight.activate(); + } + } else { + highlight!.deactivate(); + } + assert(value == (_highlights[type] != null && _highlights[type]!.active)); + + switch (type) { + case _HighlightType.pressed: + widget.onHighlightChanged?.call(value); + case _HighlightType.hover: + if (callOnHover) { + widget.onHover?.call(value); + } + case _HighlightType.focus: + break; + } + } + + void _updateHighlightsAndSplashes() { + for (final InkHighlight? highlight in _highlights.values) { + if (highlight != null) { + highlight.customBorder = widget.customBorder; + } + } + if (_currentSplash != null) { + _currentSplash!.customBorder = widget.customBorder; + } + if (_splashes != null && _splashes!.isNotEmpty) { + for (final InteractiveInkFeature inkFeature in _splashes!) { + inkFeature.customBorder = widget.customBorder; + } + } + } + + InteractiveInkFeature _createSplash(Offset globalPosition) { + final MaterialInkController inkController = Material.of(context); + final RenderBox referenceBox = context.findRenderObject()! as RenderBox; + final Offset position = referenceBox.globalToLocal(globalPosition); + final Color color = widget.overlayColor?.resolve(statesController.value) ?? widget.splashColor ?? Theme.of(context).splashColor; + final RectCallback? rectCallback = widget.containedInkWell ? widget.getRectCallback!(referenceBox) : null; + final BorderRadius? borderRadius = widget.borderRadius; + final ShapeBorder? customBorder = widget.customBorder; + + InteractiveInkFeature? splash; + void onRemoved() { + if (_splashes != null) { + assert(_splashes!.contains(splash)); + _splashes!.remove(splash); + if (_currentSplash == splash) { + _currentSplash = null; + } + updateKeepAlive(); + } // else we're probably in deactivate() + } + + splash = (widget.splashFactory ?? Theme.of(context).splashFactory).create( + controller: inkController, + referenceBox: referenceBox, + position: position, + color: color, + containedInkWell: widget.containedInkWell, + rectCallback: rectCallback, + radius: widget.radius, + borderRadius: borderRadius, + customBorder: customBorder, + onRemoved: onRemoved, + textDirection: Directionality.of(context), + ); + + return splash; + } + + void handleFocusHighlightModeChange(FocusHighlightMode mode) { + if (!mounted) { + return; + } + setState(() { + updateFocusHighlights(); + }); + } + + bool get _shouldShowFocus { + final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional; + switch (mode) { + case NavigationMode.traditional: + return enabled && _hasFocus; + case NavigationMode.directional: + return _hasFocus; + } + } + + void updateFocusHighlights() { + final bool showFocus; + switch (FocusManager.instance.highlightMode) { + case FocusHighlightMode.touch: + showFocus = false; + case FocusHighlightMode.traditional: + showFocus = _shouldShowFocus; + } + updateHighlight(_HighlightType.focus, value: showFocus); + } + + bool _hasFocus = false; + void handleFocusUpdate(bool hasFocus) { + _hasFocus = hasFocus; + // Set here rather than updateHighlight because this widget's + // (MaterialState) states include MaterialState.focused if + // the InkWell _has_ the focus, rather than if it's showing + // the focus per FocusManager.instance.highlightMode. + statesController.update(MaterialState.focused, hasFocus); + updateFocusHighlights(); + widget.onFocusChange?.call(hasFocus); + } + + void handleAnyTapDown(TapDownDetails details) { + if (_anyChildInkResponsePressed) { + return; + } + _startNewSplash(details: details); + } + + void handleTapDown(TapDownDetails details) { + handleAnyTapDown(details); + widget.onTapDown?.call(details); + } + + void handleTapUp(TapUpDetails details) { + widget.onTapUp?.call(details); + } + + void handleSecondaryTapDown(TapDownDetails details) { + handleAnyTapDown(details); + widget.onSecondaryTapDown?.call(details); + } + + void handleSecondaryTapUp(TapUpDetails details) { + widget.onSecondaryTapUp?.call(details); + } + + void _startNewSplash({TapDownDetails? details, BuildContext? context}) { + assert(details != null || context != null); + + final Offset globalPosition; + if (context != null) { + final RenderBox referenceBox = context.findRenderObject()! as RenderBox; + assert(referenceBox.hasSize, 'InkResponse must be done with layout before starting a splash.'); + globalPosition = referenceBox.localToGlobal(referenceBox.paintBounds.center); + } else { + globalPosition = details!.globalPosition; + } + statesController.update(MaterialState.pressed, true); // ... before creating the splash + final InteractiveInkFeature splash = _createSplash(globalPosition); + _splashes ??= HashSet<InteractiveInkFeature>(); + _splashes!.add(splash); + _currentSplash?.cancel(); + _currentSplash = splash; + updateKeepAlive(); + updateHighlight(_HighlightType.pressed, value: true); + } + + void handleTap() { + _currentSplash?.confirm(); + _currentSplash = null; + updateHighlight(_HighlightType.pressed, value: false); + if (widget.onTap != null) { + if (widget.enableFeedback) { + Feedback.forTap(context); + } + widget.onTap?.call(); + } + } + + void handleTapCancel() { + _currentSplash?.cancel(); + _currentSplash = null; + widget.onTapCancel?.call(); + updateHighlight(_HighlightType.pressed, value: false); + } + + void handleDoubleTap() { + _currentSplash?.confirm(); + _currentSplash = null; + updateHighlight(_HighlightType.pressed, value: false); + widget.onDoubleTap?.call(); + } + + void handleLongPress() { + _currentSplash?.confirm(); + _currentSplash = null; + if (widget.onLongPress != null) { + if (widget.enableFeedback) { + Feedback.forLongPress(context); + } + widget.onLongPress!(); + } + } + + void handleSecondaryTap() { + _currentSplash?.confirm(); + _currentSplash = null; + updateHighlight(_HighlightType.pressed, value: false); + widget.onSecondaryTap?.call(); + } + + void handleSecondaryTapCancel() { + _currentSplash?.cancel(); + _currentSplash = null; + widget.onSecondaryTapCancel?.call(); + updateHighlight(_HighlightType.pressed, value: false); + } + + @override + void deactivate() { + if (_splashes != null) { + final Set<InteractiveInkFeature> splashes = _splashes!; + _splashes = null; + for (final InteractiveInkFeature splash in splashes) { + splash.dispose(); + } + _currentSplash = null; + } + assert(_currentSplash == null); + for (final _HighlightType highlight in _highlights.keys) { + _highlights[highlight]?.dispose(); + _highlights[highlight] = null; + } + widget.parentState?.markChildInkResponsePressed(this, false); + super.deactivate(); + } + + bool isWidgetEnabled(_InkResponseStateWidget widget) { + return _primaryButtonEnabled(widget) || _secondaryButtonEnabled(widget); + } + + bool _primaryButtonEnabled(_InkResponseStateWidget widget) { + return widget.onTap != null + || widget.onDoubleTap != null + || widget.onLongPress != null + || widget.onTapUp != null + || widget.onTapDown != null; + } + + bool _secondaryButtonEnabled(_InkResponseStateWidget widget) { + return widget.onSecondaryTap != null + || widget.onSecondaryTapUp != null + || widget.onSecondaryTapDown != null; + } + + bool get enabled => isWidgetEnabled(widget); + bool get _primaryEnabled => _primaryButtonEnabled(widget); + bool get _secondaryEnabled => _secondaryButtonEnabled(widget); + + void handleMouseEnter(PointerEnterEvent event) { + _hovering = true; + if (enabled) { + handleHoverChange(); + } + } + + void handleMouseExit(PointerExitEvent event) { + _hovering = false; + // If the exit occurs after we've been disabled, we still + // want to take down the highlights and run widget.onHover. + handleHoverChange(); + } + + void handleHoverChange() { + updateHighlight(_HighlightType.hover, value: _hovering); + } + + bool get _canRequestFocus { + final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional; + switch (mode) { + case NavigationMode.traditional: + return enabled && widget.canRequestFocus; + case NavigationMode.directional: + return true; + } + } + + @override + Widget build(BuildContext context) { + assert(widget.debugCheckContext(context)); + super.build(context); // See AutomaticKeepAliveClientMixin. + + Color getHighlightColorForType(_HighlightType type) { + const Set<MaterialState> pressed = <MaterialState>{MaterialState.pressed}; + const Set<MaterialState> focused = <MaterialState>{MaterialState.focused}; + const Set<MaterialState> hovered = <MaterialState>{MaterialState.hovered}; + + final ThemeData theme = Theme.of(context); + switch (type) { + // The pressed state triggers a ripple (ink splash), per the current + // Material Design spec. A separate highlight is no longer used. + // See https://material.io/design/interaction/states.html#pressed + case _HighlightType.pressed: + return widget.overlayColor?.resolve(pressed) ?? widget.highlightColor ?? theme.highlightColor; + case _HighlightType.focus: + return widget.overlayColor?.resolve(focused) ?? widget.focusColor ?? theme.focusColor; + case _HighlightType.hover: + return widget.overlayColor?.resolve(hovered) ?? widget.hoverColor ?? theme.hoverColor; + } + } + for (final _HighlightType type in _highlights.keys) { + _highlights[type]?.color = getHighlightColorForType(type); + } + + _currentSplash?.color = widget.overlayColor?.resolve(statesController.value) ?? widget.splashColor ?? Theme.of(context).splashColor; + + final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor>( + widget.mouseCursor ?? MaterialStateMouseCursor.clickable, + statesController.value, + ); + + return _ParentInkResponseProvider( + state: this, + child: Actions( + actions: _actionMap, + child: Focus( + focusNode: widget.focusNode, + canRequestFocus: _canRequestFocus, + onFocusChange: handleFocusUpdate, + autofocus: widget.autofocus, + child: MouseRegion( + cursor: effectiveMouseCursor, + onEnter: handleMouseEnter, + onExit: handleMouseExit, + child: DefaultSelectionStyle.merge( + mouseCursor: effectiveMouseCursor, + child: Semantics( + onTap: widget.excludeFromSemantics || widget.onTap == null ? null : simulateTap, + onLongPress: widget.excludeFromSemantics || widget.onLongPress == null ? null : simulateLongPress, + child: GestureDetector( + onTapDown: _primaryEnabled ? handleTapDown : null, + onTapUp: _primaryEnabled ? handleTapUp : null, + onTap: _primaryEnabled ? handleTap : null, + onTapCancel: _primaryEnabled ? handleTapCancel : null, + onDoubleTap: widget.onDoubleTap != null ? handleDoubleTap : null, + onLongPress: widget.onLongPress != null ? handleLongPress : null, + onSecondaryTapDown: _secondaryEnabled ? handleSecondaryTapDown : null, + onSecondaryTapUp: _secondaryEnabled ? handleSecondaryTapUp: null, + onSecondaryTap: _secondaryEnabled ? handleSecondaryTap : null, + onSecondaryTapCancel: _secondaryEnabled ? handleSecondaryTapCancel : null, + behavior: HitTestBehavior.opaque, + excludeFromSemantics: true, + child: widget.child, + ), + ), + ), + ), + ), + ), + ); + } +} + +/// A rectangular area of a [Material] that responds to touch. +/// +/// For a variant of this widget that does not clip splashes, see [InkResponse]. +/// +/// The following diagram shows how an [InkWell] looks when tapped, when using +/// default values. +/// +/// ![The highlight is a rectangle the size of the box.](https://flutter.github.io/assets-for-api-docs/assets/material/ink_well.png) +/// +/// The [InkWell] widget must have a [Material] widget as an ancestor. The +/// [Material] widget is where the ink reactions are actually painted. This +/// matches the Material Design premise wherein the [Material] is what is +/// actually reacting to touches by spreading ink. +/// +/// If a Widget uses this class directly, it should include the following line +/// at the top of its build function to call [debugCheckHasMaterial]: +/// +/// ```dart +/// assert(debugCheckHasMaterial(context)); +/// ``` +/// +/// ## Troubleshooting +/// +/// ### The ink splashes aren't visible! +/// +/// If there is an opaque graphic, e.g. painted using a [Container], [Image], or +/// [DecoratedBox], between the [Material] widget and the [InkWell] widget, then +/// the splash won't be visible because it will be under the opaque graphic. +/// This is because ink splashes draw on the underlying [Material] itself, as +/// if the ink was spreading inside the material. +/// +/// The [Ink] widget can be used as a replacement for [Image], [Container], or +/// [DecoratedBox] to ensure that the image or decoration also paints in the +/// [Material] itself, below the ink. +/// +/// If this is not possible for some reason, e.g. because you are using an +/// opaque [CustomPaint] widget, alternatively consider using a second +/// [Material] above the opaque widget but below the [InkWell] (as an +/// ancestor to the ink well). The [MaterialType.transparency] material +/// kind can be used for this purpose. +/// +/// ### InkWell isn't clipping properly +/// +/// If you want to clip an InkWell or any [Ink] widgets you need to keep in mind +/// that the [Material] that the Ink will be printed on is responsible for clipping. +/// This means you can't wrap the [Ink] widget in a clipping widget directly, +/// since this will leave the [Material] not clipped (and by extension the printed +/// [Ink] widgets as well). +/// +/// An easy solution is to deliberately wrap the [Ink] widgets you want to clip +/// in a [Material], and wrap that in a clipping widget instead. See [Ink] for +/// an example. +/// +/// ### The ink splashes don't track the size of an animated container +/// If the size of an InkWell's [Material] ancestor changes while the InkWell's +/// splashes are expanding, you may notice that the splashes aren't clipped +/// correctly. This can't be avoided. +/// +/// An example of this situation is as follows: +/// +/// {@tool dartpad} +/// Tap the container to cause it to grow. Then, tap it again and hold before +/// the widget reaches its maximum size to observe the clipped ink splash. +/// +/// ** See code in examples/api/lib/material/ink_well/ink_well.0.dart ** +/// {@end-tool} +/// +/// An InkWell's splashes will not properly update to conform to changes if the +/// size of its underlying [Material], where the splashes are rendered, changes +/// during animation. You should avoid using InkWells within [Material] widgets +/// that are changing size. +/// +/// See also: +/// +/// * [GestureDetector], for listening for gestures without ink splashes. +/// * [ElevatedButton] and [TextButton], two kinds of buttons in Material Design. +/// * [InkResponse], a variant of [InkWell] that doesn't force a rectangular +/// shape on the ink reaction. +class InkWell extends InkResponse { + /// Creates an ink well. + /// + /// Must have an ancestor [Material] widget in which to cause ink reactions. + const InkWell({ + super.key, + super.child, + super.onTap, + super.onDoubleTap, + super.onLongPress, + super.onTapDown, + super.onTapUp, + super.onTapCancel, + super.onSecondaryTap, + super.onSecondaryTapUp, + super.onSecondaryTapDown, + super.onSecondaryTapCancel, + super.onHighlightChanged, + super.onHover, + super.mouseCursor, + super.focusColor, + super.hoverColor, + super.highlightColor, + super.overlayColor, + super.splashColor, + super.splashFactory, + super.radius, + super.borderRadius, + super.customBorder, + bool? enableFeedback = true, + super.excludeFromSemantics, + super.focusNode, + super.canRequestFocus, + super.onFocusChange, + super.autofocus, + super.statesController, + super.hoverDuration, + }) : super( + containedInkWell: true, + highlightShape: BoxShape.rectangle, + enableFeedback: enableFeedback ?? true, + ); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..ae9314a08df9954597b33691e489ef026627c066 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_border.dart @@ -0,0 +1,566 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/widgets.dart'; + +/// Defines the appearance of an [InputDecorator]'s border. +/// +/// An input decorator's border is specified by [InputDecoration.border]. +/// +/// The border is drawn relative to the input decorator's "container" which +/// is the optionally filled area above the decorator's helper, error, +/// and counter. +/// +/// Input border's are decorated with a line whose weight and color are defined +/// by [borderSide]. The input decorator's renderer animates the input border's +/// appearance in response to state changes, like gaining or losing the focus, +/// by creating new copies of its input border with [copyWith]. +/// +/// See also: +/// +/// * [UnderlineInputBorder], the default [InputDecorator] border which +/// draws a horizontal line at the bottom of the input decorator's container. +/// * [OutlineInputBorder], an [InputDecorator] border which draws a +/// rounded rectangle around the input decorator's container. +/// * [InputDecoration], which is used to configure an [InputDecorator]. +abstract class InputBorder extends ShapeBorder { + /// Creates a border for an [InputDecorator]. + /// + /// Applications typically do not specify a [borderSide] parameter because the + /// [InputDecorator] substitutes its own, using [copyWith], based on the + /// current theme and [InputDecorator.isFocused]. + const InputBorder({ + this.borderSide = BorderSide.none, + }); + + /// No input border. + /// + /// Use this value with [InputDecoration.border] to specify that no border + /// should be drawn. The [InputDecoration.collapsed] constructor sets + /// its border to this value. + static const InputBorder none = _NoInputBorder(); + + /// Defines the border line's color and weight. + /// + /// The [InputDecorator] creates copies of its input border, using [copyWith], + /// based on the current theme and [InputDecorator.isFocused]. + final BorderSide borderSide; + + /// Creates a copy of this input border with the specified `borderSide`. + InputBorder copyWith({ BorderSide? borderSide }); + + /// True if this border will enclose the [InputDecorator]'s container. + /// + /// This property affects the alignment of container's contents. For example + /// when an input decorator is configured with an [OutlineInputBorder] its + /// label is centered with its container. + bool get isOutline; + + /// Paint this input border on [canvas]. + /// + /// The [rect] parameter bounds the [InputDecorator]'s container. + /// + /// The additional `gap` parameters reflect the state of the [InputDecorator]'s + /// floating label. When an input decorator gains the focus, its label + /// animates upwards, to make room for the input child. The [gapStart] and + /// [gapExtent] parameters define a floating label width interval, and + /// [gapPercentage] defines the animation's progress (0.0 to 1.0). + @override + void paint( + Canvas canvas, + Rect rect, { + double? gapStart, + double gapExtent = 0.0, + double gapPercentage = 0.0, + TextDirection? textDirection, + }); +} + +// Used to create the InputBorder.none singleton. +class _NoInputBorder extends InputBorder { + const _NoInputBorder() : super(borderSide: BorderSide.none); + + @override + _NoInputBorder copyWith({ BorderSide? borderSide }) => const _NoInputBorder(); + + @override + bool get isOutline => false; + + @override + EdgeInsetsGeometry get dimensions => EdgeInsets.zero; + + @override + _NoInputBorder scale(double t) => const _NoInputBorder(); + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + return Path()..addRect(rect); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path()..addRect(rect); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + canvas.drawRect(rect, paint); + } + + @override + bool get preferPaintInterior => true; + + @override + void paint( + Canvas canvas, + Rect rect, { + double? gapStart, + double gapExtent = 0.0, + double gapPercentage = 0.0, + TextDirection? textDirection, + }) { + // Do not paint. + } +} + +/// Draws a horizontal line at the bottom of an [InputDecorator]'s container and +/// defines the container's shape. +/// +/// The input decorator's "container" is the optionally filled area above the +/// decorator's helper, error, and counter. +/// +/// See also: +/// +/// * [OutlineInputBorder], an [InputDecorator] border which draws a +/// rounded rectangle around the input decorator's container. +/// * [InputDecoration], which is used to configure an [InputDecorator]. +class UnderlineInputBorder extends InputBorder { + /// Creates an underline border for an [InputDecorator]. + /// + /// The [borderSide] parameter defaults to [BorderSide.none] (it must not be + /// null). Applications typically do not specify a [borderSide] parameter + /// because the input decorator substitutes its own, using [copyWith], based + /// on the current theme and [InputDecorator.isFocused]. + /// + /// The [borderRadius] parameter defaults to a value where the top left + /// and right corners have a circular radius of 4.0. + const UnderlineInputBorder({ + super.borderSide = const BorderSide(), + this.borderRadius = const BorderRadius.only( + topLeft: Radius.circular(4.0), + topRight: Radius.circular(4.0), + ), + }); + + /// The radii of the border's rounded rectangle corners. + /// + /// When this border is used with a filled input decorator, see + /// [InputDecoration.filled], the border radius defines the shape + /// of the background fill as well as the bottom left and right + /// edges of the underline itself. + /// + /// By default the top right and top left corners have a circular radius + /// of 4.0. + final BorderRadius borderRadius; + + @override + bool get isOutline => false; + + @override + UnderlineInputBorder copyWith({ BorderSide? borderSide, BorderRadius? borderRadius }) { + return UnderlineInputBorder( + borderSide: borderSide ?? this.borderSide, + borderRadius: borderRadius ?? this.borderRadius, + ); + } + + @override + EdgeInsetsGeometry get dimensions { + return EdgeInsets.only(bottom: borderSide.width); + } + + @override + UnderlineInputBorder scale(double t) { + return UnderlineInputBorder(borderSide: borderSide.scale(t)); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + return Path() + ..addRect(Rect.fromLTWH(rect.left, rect.top, rect.width, math.max(0.0, rect.height - borderSide.width))); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path()..addRRect(borderRadius.resolve(textDirection).toRRect(rect)); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + canvas.drawRRect(borderRadius.resolve(textDirection).toRRect(rect), paint); + } + + @override + bool get preferPaintInterior => true; + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is UnderlineInputBorder) { + return UnderlineInputBorder( + borderSide: BorderSide.lerp(a.borderSide, borderSide, t), + borderRadius: BorderRadius.lerp(a.borderRadius, borderRadius, t)!, + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is UnderlineInputBorder) { + return UnderlineInputBorder( + borderSide: BorderSide.lerp(borderSide, b.borderSide, t), + borderRadius: BorderRadius.lerp(borderRadius, b.borderRadius, t)!, + ); + } + return super.lerpTo(b, t); + } + + /// Draw a horizontal line at the bottom of [rect]. + /// + /// The [borderSide] defines the line's color and weight. The `textDirection` + /// `gap` and `textDirection` parameters are ignored. + @override + void paint( + Canvas canvas, + Rect rect, { + double? gapStart, + double gapExtent = 0.0, + double gapPercentage = 0.0, + TextDirection? textDirection, + }) { + if (borderRadius.bottomLeft != Radius.zero || borderRadius.bottomRight != Radius.zero) { + // This prevents the border from leaking the color due to anti-aliasing rounding errors. + final BorderRadius updatedBorderRadius = BorderRadius.only( + bottomLeft: borderRadius.bottomLeft.clamp(maximum: Radius.circular(rect.height / 2)), + bottomRight: borderRadius.bottomRight.clamp(maximum: Radius.circular(rect.height / 2)), + ); + + // We set the strokeAlign to center, so the behavior is consistent with + // drawLine and with the historical behavior of this border. + BoxBorder.paintNonUniformBorder(canvas, rect, + textDirection: textDirection, + borderRadius: updatedBorderRadius, + bottom: borderSide.copyWith(strokeAlign: BorderSide.strokeAlignCenter), + color: borderSide.color); + } else { + canvas.drawLine(rect.bottomLeft, rect.bottomRight, borderSide.toPaint()); + } + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is UnderlineInputBorder + && other.borderSide == borderSide + && other.borderRadius == borderRadius; + } + + @override + int get hashCode => Object.hash(borderSide, borderRadius); +} + +/// Draws a rounded rectangle around an [InputDecorator]'s container. +/// +/// When the input decorator's label is floating, for example because its +/// input child has the focus, the label appears in a gap in the border outline. +/// +/// The input decorator's "container" is the optionally filled area above the +/// decorator's helper, error, and counter. +/// +/// See also: +/// +/// * [UnderlineInputBorder], the default [InputDecorator] border which +/// draws a horizontal line at the bottom of the input decorator's container. +/// * [InputDecoration], which is used to configure an [InputDecorator]. +class OutlineInputBorder extends InputBorder { + /// Creates a rounded rectangle outline border for an [InputDecorator]. + /// + /// If the [borderSide] parameter is [BorderSide.none], it will not draw a + /// border. However, it will still define a shape (which you can see if + /// [InputDecoration.filled] is true). + /// + /// If an application does not specify a [borderSide] parameter of + /// value [BorderSide.none], the input decorator substitutes its own, using + /// [copyWith], based on the current theme and [InputDecorator.isFocused]. + /// + /// The [borderRadius] parameter defaults to a value where all four corners + /// have a circular radius of 4.0. The corner radii must be circular, i.e. + /// their [Radius.x] and [Radius.y] values must be the same. + /// + /// See also: + /// + /// * [InputDecoration.floatingLabelBehavior], which should be set to + /// [FloatingLabelBehavior.never] when the [borderSide] is + /// [BorderSide.none]. If let as [FloatingLabelBehavior.auto], the label + /// will extend beyond the container as if the border were still being + /// drawn. + const OutlineInputBorder({ + super.borderSide = const BorderSide(), + this.borderRadius = const BorderRadius.all(Radius.circular(4.0)), + this.gapPadding = 4.0, + }) : assert(gapPadding >= 0.0); + + // The label text's gap can extend into the corners (even both the top left + // and the top right corner). To avoid the more complicated problem of finding + // how far the gap penetrates into an elliptical corner, just require them + // to be circular. + // + // This can't be checked by the constructor because const constructor. + static bool _cornersAreCircular(BorderRadius borderRadius) { + return borderRadius.topLeft.x == borderRadius.topLeft.y + && borderRadius.bottomLeft.x == borderRadius.bottomLeft.y + && borderRadius.topRight.x == borderRadius.topRight.y + && borderRadius.bottomRight.x == borderRadius.bottomRight.y; + } + + /// Horizontal padding on either side of the border's + /// [InputDecoration.labelText] width gap. + /// + /// This value is used by the [paint] method to compute the actual gap width. + final double gapPadding; + + /// The radii of the border's rounded rectangle corners. + /// + /// The corner radii must be circular, i.e. their [Radius.x] and [Radius.y] + /// values must be the same. + final BorderRadius borderRadius; + + @override + bool get isOutline => true; + + @override + OutlineInputBorder copyWith({ + BorderSide? borderSide, + BorderRadius? borderRadius, + double? gapPadding, + }) { + return OutlineInputBorder( + borderSide: borderSide ?? this.borderSide, + borderRadius: borderRadius ?? this.borderRadius, + gapPadding: gapPadding ?? this.gapPadding, + ); + } + + @override + EdgeInsetsGeometry get dimensions { + return EdgeInsets.all(borderSide.width); + } + + @override + OutlineInputBorder scale(double t) { + return OutlineInputBorder( + borderSide: borderSide.scale(t), + borderRadius: borderRadius * t, + gapPadding: gapPadding * t, + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is OutlineInputBorder) { + final OutlineInputBorder outline = a; + return OutlineInputBorder( + borderRadius: BorderRadius.lerp(outline.borderRadius, borderRadius, t)!, + borderSide: BorderSide.lerp(outline.borderSide, borderSide, t), + gapPadding: outline.gapPadding, + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is OutlineInputBorder) { + final OutlineInputBorder outline = b; + return OutlineInputBorder( + borderRadius: BorderRadius.lerp(borderRadius, outline.borderRadius, t)!, + borderSide: BorderSide.lerp(borderSide, outline.borderSide, t), + gapPadding: outline.gapPadding, + ); + } + return super.lerpTo(b, t); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + return Path() + ..addRRect(borderRadius.resolve(textDirection).toRRect(rect).deflate(borderSide.width)); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path() + ..addRRect(borderRadius.resolve(textDirection).toRRect(rect)); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + canvas.drawRRect(borderRadius.resolve(textDirection).toRRect(rect), paint); + } + + @override + bool get preferPaintInterior => true; + + Path _gapBorderPath(Canvas canvas, RRect center, double start, double extent) { + // When the corner radii on any side add up to be greater than the + // given height, each radius has to be scaled to not exceed the + // size of the width/height of the RRect. + final RRect scaledRRect = center.scaleRadii(); + + final Rect tlCorner = Rect.fromLTWH( + scaledRRect.left, + scaledRRect.top, + scaledRRect.tlRadiusX * 2.0, + scaledRRect.tlRadiusY * 2.0, + ); + final Rect trCorner = Rect.fromLTWH( + scaledRRect.right - scaledRRect.trRadiusX * 2.0, + scaledRRect.top, + scaledRRect.trRadiusX * 2.0, + scaledRRect.trRadiusY * 2.0, + ); + final Rect brCorner = Rect.fromLTWH( + scaledRRect.right - scaledRRect.brRadiusX * 2.0, + scaledRRect.bottom - scaledRRect.brRadiusY * 2.0, + scaledRRect.brRadiusX * 2.0, + scaledRRect.brRadiusY * 2.0, + ); + final Rect blCorner = Rect.fromLTWH( + scaledRRect.left, + scaledRRect.bottom - scaledRRect.blRadiusY * 2.0, + scaledRRect.blRadiusX * 2.0, + scaledRRect.blRadiusY * 2.0, + ); + + // This assumes that the radius is circular (x and y radius are equal). + // Currently, BorderRadius only supports circular radii. + const double cornerArcSweep = math.pi / 2.0; + final Path path = Path(); + + // Top left corner + if (scaledRRect.tlRadius != Radius.zero) { + final double tlCornerArcSweep = math.acos(clampDouble(1 - start / scaledRRect.tlRadiusX, 0.0, 1.0)); + path.addArc(tlCorner, math.pi, tlCornerArcSweep); + } else { + // Because the path is painted with Paint.strokeCap = StrokeCap.butt, horizontal coordinate is moved + // to the left using borderSide.width / 2. + path.moveTo(scaledRRect.left - borderSide.width / 2, scaledRRect.top); + } + + // Draw top border from top left corner to gap start. + if (start > scaledRRect.tlRadiusX) { + path.lineTo(scaledRRect.left + start, scaledRRect.top); + } + + // Draw top border from gap end to top right corner and draw top right corner. + const double trCornerArcStart = (3 * math.pi) / 2.0; + const double trCornerArcSweep = cornerArcSweep; + if (start + extent < scaledRRect.width - scaledRRect.trRadiusX) { + path.moveTo(scaledRRect.left + start + extent, scaledRRect.top); + path.lineTo(scaledRRect.right - scaledRRect.trRadiusX, scaledRRect.top); + if (scaledRRect.trRadius != Radius.zero) { + path.addArc(trCorner, trCornerArcStart, trCornerArcSweep); + } + } else if (start + extent < scaledRRect.width) { + final double dx = scaledRRect.width - (start + extent); + final double sweep = math.asin(clampDouble(1 - dx / scaledRRect.trRadiusX, 0.0, 1.0)); + path.addArc(trCorner, trCornerArcStart + sweep, trCornerArcSweep - sweep); + } + + // Draw right border and bottom right corner. + if (scaledRRect.brRadius != Radius.zero) { + path.moveTo(scaledRRect.right, scaledRRect.top + scaledRRect.trRadiusY); + } + path.lineTo(scaledRRect.right, scaledRRect.bottom - scaledRRect.brRadiusY); + if (scaledRRect.brRadius != Radius.zero) { + path.addArc(brCorner, 0.0, cornerArcSweep); + } + + // Draw bottom border and bottom left corner. + path.lineTo(scaledRRect.left + scaledRRect.blRadiusX, scaledRRect.bottom); + if (scaledRRect.blRadius != Radius.zero) { + path.addArc(blCorner, math.pi / 2.0, cornerArcSweep); + } + + // Draw left border + path.lineTo(scaledRRect.left, scaledRRect.top + scaledRRect.tlRadiusY); + + return path; + } + + /// Draw a rounded rectangle around [rect] using [borderRadius]. + /// + /// The [borderSide] defines the line's color and weight. + /// + /// The top side of the rounded rectangle may be interrupted by a single gap + /// if [gapExtent] is non-null. In that case the gap begins at + /// `gapStart - gapPadding` (assuming that the [textDirection] is [TextDirection.ltr]). + /// The gap's width is `(gapPadding + gapExtent + gapPadding) * gapPercentage`. + @override + void paint( + Canvas canvas, + Rect rect, { + double? gapStart, + double gapExtent = 0.0, + double gapPercentage = 0.0, + TextDirection? textDirection, + }) { + assert(gapPercentage >= 0.0 && gapPercentage <= 1.0); + assert(_cornersAreCircular(borderRadius)); + + final Paint paint = borderSide.toPaint(); + final RRect outer = borderRadius.toRRect(rect); + final RRect center = outer.deflate(borderSide.width / 2.0); + if (gapStart == null || gapExtent <= 0.0 || gapPercentage == 0.0) { + canvas.drawRRect(center, paint); + } else { + final double extent = lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage)!; + switch (textDirection!) { + case TextDirection.rtl: + final Path path = _gapBorderPath(canvas, center, math.max(0.0, gapStart + gapPadding - extent), extent); + canvas.drawPath(path, paint); + + case TextDirection.ltr: + final Path path = _gapBorderPath(canvas, center, math.max(0.0, gapStart - gapPadding), extent); + canvas.drawPath(path, paint); + } + } + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is OutlineInputBorder + && other.borderSide == borderSide + && other.borderRadius == borderRadius + && other.gapPadding == gapPadding; + } + + @override + int get hashCode => Object.hash(borderSide, borderRadius, gapPadding); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_chip.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_chip.dart new file mode 100644 index 0000000000000000000000000000000000000000..d3f7ba26dd2a7515f34a60b739e89c0dc5f58667 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_chip.dart @@ -0,0 +1,325 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/widgets.dart'; + +import 'chip.dart'; +import 'chip_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'debug.dart'; +import 'icons.dart'; +import 'material_state.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +/// A Material Design input chip. +/// +/// Input chips represent a complex piece of information, such as an entity +/// (person, place, or thing) or conversational text, in a compact form. +/// +/// Input chips can be made selectable by setting [onSelected], deletable by +/// setting [onDeleted], and pressable like a button with [onPressed]. They have +/// a [label], and they can have a leading icon (see [avatar]) and a trailing +/// icon ([deleteIcon]). Colors and padding can be customized. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// Input chips work together with other UI elements. They can appear: +/// +/// * In a [Wrap] widget. +/// * In a horizontally scrollable list, for example configured such as a +/// [ListView] with [ListView.scrollDirection] set to [Axis.horizontal]. +/// +/// {@tool dartpad} +/// This example shows how to create [InputChip]s with [onSelected] and +/// [onDeleted] callbacks. When the user taps the chip, the chip will be selected. +/// When the user taps the delete icon, the chip will be deleted. +/// +/// ** See code in examples/api/lib/material/input_chip/input_chip.0.dart ** +/// {@end-tool} +/// +/// +/// {@tool dartpad} +/// The following example shows how to generate [InputChip]s from +/// user text input. When the user enters a pizza topping in the text field, +/// the user is presented with a list of suggestions. When selecting one of the +/// suggestions, an [InputChip] is generated in the text field. +/// +/// ** See code in examples/api/lib/material/input_chip/input_chip.1.dart ** +/// {@end-tool} +/// +/// ## Material Design 3 +/// +/// [InputChip] can be used for Input chips from Material Design 3. +/// If [ThemeData.useMaterial3] is true, then [InputChip] +/// will be styled to match the Material Design 3 specification for Input +/// chips. +/// +/// See also: +/// +/// * [Chip], a chip that displays information and can be deleted. +/// * [ChoiceChip], allows a single selection from a set of options. Choice +/// chips contain related descriptive text or categories. +/// * [FilterChip], uses tags or descriptive words as a way to filter content. +/// * [ActionChip], represents an action related to primary content. +/// * [CircleAvatar], which shows images or initials of people. +/// * [Wrap], A widget that displays its children in multiple horizontal or +/// vertical runs. +/// * <https://material.io/design/components/chips.html> +class InputChip extends StatelessWidget + implements + ChipAttributes, + DeletableChipAttributes, + SelectableChipAttributes, + CheckmarkableChipAttributes, + DisabledChipAttributes, + TappableChipAttributes { + /// Creates an [InputChip]. + /// + /// The [onPressed] and [onSelected] callbacks must not both be specified at + /// the same time. + /// + /// The [pressElevation] and [elevation] must be null or non-negative. + /// Typically, [pressElevation] is greater than [elevation]. + const InputChip({ + super.key, + this.avatar, + required this.label, + this.labelStyle, + this.labelPadding, + this.selected = false, + this.isEnabled = true, + this.onSelected, + this.deleteIcon, + this.onDeleted, + this.deleteIconColor, + this.deleteButtonTooltipMessage, + this.onPressed, + this.pressElevation, + this.disabledColor, + this.selectedColor, + this.tooltip, + this.side, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.color, + this.backgroundColor, + this.padding, + this.visualDensity, + this.materialTapTargetSize, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.iconTheme, + this.selectedShadowColor, + this.showCheckmark, + this.checkmarkColor, + this.avatarBorder = const CircleBorder(), + }) : assert(pressElevation == null || pressElevation >= 0.0), + assert(elevation == null || elevation >= 0.0); + + @override + final Widget? avatar; + @override + final Widget label; + @override + final TextStyle? labelStyle; + @override + final EdgeInsetsGeometry? labelPadding; + @override + final bool selected; + @override + final bool isEnabled; + @override + final ValueChanged<bool>? onSelected; + @override + final Widget? deleteIcon; + @override + final VoidCallback? onDeleted; + @override + final Color? deleteIconColor; + @override + final String? deleteButtonTooltipMessage; + @override + final VoidCallback? onPressed; + @override + final double? pressElevation; + @override + final Color? disabledColor; + @override + final Color? selectedColor; + @override + final String? tooltip; + @override + final BorderSide? side; + @override + final OutlinedBorder? shape; + @override + final Clip clipBehavior; + @override + final FocusNode? focusNode; + @override + final bool autofocus; + @override + final MaterialStateProperty<Color?>? color; + @override + final Color? backgroundColor; + @override + final EdgeInsetsGeometry? padding; + @override + final VisualDensity? visualDensity; + @override + final MaterialTapTargetSize? materialTapTargetSize; + @override + final double? elevation; + @override + final Color? shadowColor; + @override + final Color? surfaceTintColor; + @override + final Color? selectedShadowColor; + @override + final bool? showCheckmark; + @override + final Color? checkmarkColor; + @override + final ShapeBorder avatarBorder; + @override + final IconThemeData? iconTheme; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + final ChipThemeData? defaults = Theme.of(context).useMaterial3 + ? _InputChipDefaultsM3(context, isEnabled, selected) + : null; + final Widget? resolvedDeleteIcon = deleteIcon + ?? (Theme.of(context).useMaterial3 ? const Icon(Icons.clear, size: 18) : null); + return RawChip( + defaultProperties: defaults, + avatar: avatar, + label: label, + labelStyle: labelStyle, + labelPadding: labelPadding, + deleteIcon: resolvedDeleteIcon, + onDeleted: onDeleted, + deleteIconColor: deleteIconColor, + deleteButtonTooltipMessage: deleteButtonTooltipMessage, + onSelected: onSelected, + onPressed: onPressed, + pressElevation: pressElevation, + selected: selected, + disabledColor: disabledColor, + selectedColor: selectedColor, + tooltip: tooltip, + side: side, + shape: shape, + clipBehavior: clipBehavior, + focusNode: focusNode, + autofocus: autofocus, + color: color, + backgroundColor: backgroundColor, + padding: padding, + visualDensity: visualDensity, + materialTapTargetSize: materialTapTargetSize, + elevation: elevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + selectedShadowColor: selectedShadowColor, + showCheckmark: showCheckmark, + checkmarkColor: checkmarkColor, + isEnabled: isEnabled && (onSelected != null || onDeleted != null || onPressed != null), + avatarBorder: avatarBorder, + iconTheme: iconTheme, + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - InputChip + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _InputChipDefaultsM3 extends ChipThemeData { + _InputChipDefaultsM3(this.context, this.isEnabled, this.isSelected) + : super( + elevation: 0.0, + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))), + showCheckmark: true, + ); + + final BuildContext context; + final bool isEnabled; + final bool isSelected; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + TextStyle? get labelStyle => _textTheme.labelLarge; + + @override + MaterialStateProperty<Color?>? get color => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected) && states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.disabled)) { + return null; + } + if (states.contains(MaterialState.selected)) { + return _colors.secondaryContainer; + } + return null; + }); + + @override + Color? get shadowColor => Colors.transparent; + + @override + Color? get surfaceTintColor => Colors.transparent; + + @override + Color? get checkmarkColor => null; + + @override + Color? get deleteIconColor => _colors.onSecondaryContainer; + + @override + BorderSide? get side => !isSelected + ? isEnabled + ? BorderSide(color: _colors.outline) + : BorderSide(color: _colors.onSurface.withOpacity(0.12)) + : const BorderSide(color: Colors.transparent); + + @override + IconThemeData? get iconTheme => IconThemeData( + color: isEnabled + ? null + : _colors.onSurface, + size: 18.0, + ); + + @override + EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0); + + /// The chip at text scale 1 starts with 8px on each side and as text scaling + /// gets closer to 2 the label padding is linearly interpolated from 8px to 4px. + /// Once the widget has a text scaling of 2 or higher than the label padding + /// remains 4px. + @override + EdgeInsetsGeometry? get labelPadding => EdgeInsets.lerp( + const EdgeInsets.symmetric(horizontal: 8.0), + const EdgeInsets.symmetric(horizontal: 4.0), + clampDouble(MediaQuery.textScalerOf(context).textScaleFactor - 1.0, 0.0, 1.0), + )!; +} + +// END GENERATED TOKEN PROPERTIES - InputChip diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_date_picker_form_field.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_date_picker_form_field.dart new file mode 100644 index 0000000000000000000000000000000000000000..6341360da6830da7c776bc81ed40b4dd930ee00e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_date_picker_form_field.dart @@ -0,0 +1,276 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'date.dart'; +import 'date_picker_theme.dart'; +import 'input_border.dart'; +import 'input_decorator.dart'; +import 'material_localizations.dart'; +import 'text_form_field.dart'; +import 'theme.dart'; + +/// A [TextFormField] configured to accept and validate a date entered by a user. +/// +/// When the field is saved or submitted, the text will be parsed into a +/// [DateTime] according to the ambient locale's compact date format. If the +/// input text doesn't parse into a date, the [errorFormatText] message will +/// be displayed under the field. +/// +/// [firstDate], [lastDate], and [selectableDayPredicate] provide constraints on +/// what days are valid. If the input date isn't in the date range or doesn't pass +/// the given predicate, then the [errorInvalidText] message will be displayed +/// under the field. +/// +/// See also: +/// +/// * [showDatePicker], which shows a dialog that contains a Material Design +/// date picker which includes support for text entry of dates. +/// * [MaterialLocalizations.parseCompactDate], which is used to parse the text +/// input into a [DateTime]. +/// +class InputDatePickerFormField extends StatefulWidget { + /// Creates a [TextFormField] configured to accept and validate a date. + /// + /// If the optional [initialDate] is provided, then it will be used to populate + /// the text field. If the [fieldHintText] is provided, it will be shown. + /// + /// If [initialDate] is provided, it must not be before [firstDate] or after + /// [lastDate]. If [selectableDayPredicate] is provided, it must return `true` + /// for [initialDate]. + /// + /// [firstDate] must be on or before [lastDate]. + InputDatePickerFormField({ + super.key, + DateTime? initialDate, + required DateTime firstDate, + required DateTime lastDate, + this.onDateSubmitted, + this.onDateSaved, + this.selectableDayPredicate, + this.errorFormatText, + this.errorInvalidText, + this.fieldHintText, + this.fieldLabelText, + this.keyboardType, + this.autofocus = false, + this.acceptEmptyDate = false, + this.focusNode, + }) : initialDate = initialDate != null ? DateUtils.dateOnly(initialDate) : null, + firstDate = DateUtils.dateOnly(firstDate), + lastDate = DateUtils.dateOnly(lastDate) { + assert( + !this.lastDate.isBefore(this.firstDate), + 'lastDate ${this.lastDate} must be on or after firstDate ${this.firstDate}.', + ); + assert( + initialDate == null || !this.initialDate!.isBefore(this.firstDate), + 'initialDate ${this.initialDate} must be on or after firstDate ${this.firstDate}.', + ); + assert( + initialDate == null || !this.initialDate!.isAfter(this.lastDate), + 'initialDate ${this.initialDate} must be on or before lastDate ${this.lastDate}.', + ); + assert( + selectableDayPredicate == null || initialDate == null || selectableDayPredicate!(this.initialDate!), + 'Provided initialDate ${this.initialDate} must satisfy provided selectableDayPredicate.', + ); + } + + /// If provided, it will be used as the default value of the field. + final DateTime? initialDate; + + /// The earliest allowable [DateTime] that the user can input. + final DateTime firstDate; + + /// The latest allowable [DateTime] that the user can input. + final DateTime lastDate; + + /// An optional method to call when the user indicates they are done editing + /// the text in the field. Will only be called if the input represents a valid + /// [DateTime]. + final ValueChanged<DateTime>? onDateSubmitted; + + /// An optional method to call with the final date when the form is + /// saved via [FormState.save]. Will only be called if the input represents + /// a valid [DateTime]. + final ValueChanged<DateTime>? onDateSaved; + + /// Function to provide full control over which [DateTime] can be selected. + final SelectableDayPredicate? selectableDayPredicate; + + /// The error text displayed if the entered date is not in the correct format. + final String? errorFormatText; + + /// The error text displayed if the date is not valid. + /// + /// A date is not valid if it is earlier than [firstDate], later than + /// [lastDate], or doesn't pass the [selectableDayPredicate]. + final String? errorInvalidText; + + /// The hint text displayed in the [TextField]. + /// + /// If this is null, it will default to the date format string. For example, + /// 'mm/dd/yyyy' for en_US. + final String? fieldHintText; + + /// The label text displayed in the [TextField]. + /// + /// If this is null, it will default to the words representing the date format + /// string. For example, 'Month, Day, Year' for en_US. + final String? fieldLabelText; + + /// The keyboard type of the [TextField]. + /// + /// If this is null, it will default to [TextInputType.datetime] + final TextInputType? keyboardType; + + /// {@macro flutter.widgets.editableText.autofocus} + final bool autofocus; + + /// Determines if an empty date would show [errorFormatText] or not. + /// + /// Defaults to false. + /// + /// If true, [errorFormatText] is not shown when the date input field is empty. + final bool acceptEmptyDate; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + @override + State<InputDatePickerFormField> createState() => _InputDatePickerFormFieldState(); +} + +class _InputDatePickerFormFieldState extends State<InputDatePickerFormField> { + final TextEditingController _controller = TextEditingController(); + DateTime? _selectedDate; + String? _inputText; + bool _autoSelected = false; + + @override + void initState() { + super.initState(); + _selectedDate = widget.initialDate; + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _updateValueForSelectedDate(); + } + + @override + void didUpdateWidget(InputDatePickerFormField oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.initialDate != oldWidget.initialDate) { + // Can't update the form field in the middle of a build, so do it next frame + WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) { + setState(() { + _selectedDate = widget.initialDate; + _updateValueForSelectedDate(); + }); + }, debugLabel: 'InputDatePickerFormField.update'); + } + } + + void _updateValueForSelectedDate() { + if (_selectedDate != null) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + _inputText = localizations.formatCompactDate(_selectedDate!); + TextEditingValue textEditingValue = TextEditingValue(text: _inputText!); + // Select the new text if we are auto focused and haven't selected the text before. + if (widget.autofocus && !_autoSelected) { + textEditingValue = textEditingValue.copyWith(selection: TextSelection( + baseOffset: 0, + extentOffset: _inputText!.length, + )); + _autoSelected = true; + } + _controller.value = textEditingValue; + } else { + _inputText = ''; + _controller.value = TextEditingValue(text: _inputText!); + } + } + + DateTime? _parseDate(String? text) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + return localizations.parseCompactDate(text); + } + + bool _isValidAcceptableDate(DateTime? date) { + return + date != null && + !date.isBefore(widget.firstDate) && + !date.isAfter(widget.lastDate) && + (widget.selectableDayPredicate == null || widget.selectableDayPredicate!(date)); + } + + String? _validateDate(String? text) { + if ((text == null || text.isEmpty) && widget.acceptEmptyDate) { + return null; + } + final DateTime? date = _parseDate(text); + if (date == null) { + return widget.errorFormatText ?? MaterialLocalizations.of(context).invalidDateFormatLabel; + } else if (!_isValidAcceptableDate(date)) { + return widget.errorInvalidText ?? MaterialLocalizations.of(context).dateOutOfRangeLabel; + } + return null; + } + + void _updateDate(String? text, ValueChanged<DateTime>? callback) { + final DateTime? date = _parseDate(text); + if (_isValidAcceptableDate(date)) { + _selectedDate = date; + _inputText = text; + callback?.call(_selectedDate!); + } + } + + void _handleSaved(String? text) { + _updateDate(text, widget.onDateSaved); + } + + void _handleSubmitted(String text) { + _updateDate(text, widget.onDateSubmitted); + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final bool useMaterial3 = theme.useMaterial3; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final DatePickerThemeData datePickerTheme = theme.datePickerTheme; + final InputDecorationTheme inputTheme = theme.inputDecorationTheme; + final InputBorder effectiveInputBorder = datePickerTheme.inputDecorationTheme?.border + ?? theme.inputDecorationTheme.border + ?? (useMaterial3 ? const OutlineInputBorder() : const UnderlineInputBorder()); + + return TextFormField( + decoration: InputDecoration( + hintText: widget.fieldHintText ?? localizations.dateHelpText, + labelText: widget.fieldLabelText ?? localizations.dateInputLabel, + ).applyDefaults(inputTheme + .merge(datePickerTheme.inputDecorationTheme) + .copyWith(border: effectiveInputBorder), + ), + validator: _validateDate, + keyboardType: widget.keyboardType ?? TextInputType.datetime, + onSaved: _handleSaved, + onFieldSubmitted: _handleSubmitted, + autofocus: widget.autofocus, + controller: _controller, + focusNode: widget.focusNode, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_decorator.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_decorator.dart new file mode 100644 index 0000000000000000000000000000000000000000..607e8ee63ae44306b4a7ab7dc23432077736032c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/input_decorator.dart @@ -0,0 +1,4789 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'icon_button.dart'; +import 'icon_button_theme.dart'; +import 'input_border.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// late Widget _myIcon; + +// The duration value extracted from: +// https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/textfield/TextInputLayout.java +const Duration _kTransitionDuration = Duration(milliseconds: 167); +const Curve _kTransitionCurve = Curves.fastOutSlowIn; +const double _kFinalLabelScale = 0.75; + +// The default duration for hint fade in/out transitions. +// +// Animating hint is not mentioned in the Material specification. +// The animation is kept for backard compatibility and a short duration +// is used to mitigate the UX impact. +const Duration _kHintFadeTransitionDuration = Duration(milliseconds: 20); + +// Defines the gap in the InputDecorator's outline border where the +// floating label will appear. +class _InputBorderGap extends ChangeNotifier { + double? _start; + double? get start => _start; + set start(double? value) { + if (value != _start) { + _start = value; + notifyListeners(); + } + } + + double _extent = 0.0; + double get extent => _extent; + set extent(double value) { + if (value != _extent) { + _extent = value; + notifyListeners(); + } + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes, this class is not used in collection + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is _InputBorderGap + && other.start == start + && other.extent == extent; + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes, this class is not used in collection + int get hashCode => Object.hash(start, extent); + + @override + String toString() => describeIdentity(this); +} + +// Used to interpolate between two InputBorders. +class _InputBorderTween extends Tween<InputBorder> { + _InputBorderTween({super.begin, super.end}); + + @override + InputBorder lerp(double t) => ShapeBorder.lerp(begin, end, t)! as InputBorder; +} + +// Passes the _InputBorderGap parameters along to an InputBorder's paint method. +class _InputBorderPainter extends CustomPainter { + _InputBorderPainter({ + required Listenable repaint, + required this.borderAnimation, + required this.border, + required this.gapAnimation, + required this.gap, + required this.textDirection, + required this.fillColor, + required this.hoverAnimation, + required this.hoverColorTween, + }) : super(repaint: repaint); + + final Animation<double> borderAnimation; + final _InputBorderTween border; + final Animation<double> gapAnimation; + final _InputBorderGap gap; + final TextDirection textDirection; + final Color fillColor; + final ColorTween hoverColorTween; + final Animation<double> hoverAnimation; + + Color get blendedColor => Color.alphaBlend(hoverColorTween.evaluate(hoverAnimation)!, fillColor); + + @override + void paint(Canvas canvas, Size size) { + final InputBorder borderValue = border.evaluate(borderAnimation); + final Rect canvasRect = Offset.zero & size; + final Color blendedFillColor = blendedColor; + if (blendedFillColor.alpha > 0) { + canvas.drawPath( + borderValue.getOuterPath(canvasRect, textDirection: textDirection), + Paint() + ..color = blendedFillColor + ..style = PaintingStyle.fill, + ); + } + + borderValue.paint( + canvas, + canvasRect, + gapStart: gap.start, + gapExtent: gap.extent, + gapPercentage: gapAnimation.value, + textDirection: textDirection, + ); + } + + @override + bool shouldRepaint(_InputBorderPainter oldPainter) { + return borderAnimation != oldPainter.borderAnimation + || hoverAnimation != oldPainter.hoverAnimation + || gapAnimation != oldPainter.gapAnimation + || border != oldPainter.border + || gap != oldPainter.gap + || textDirection != oldPainter.textDirection; + } + + @override + String toString() => describeIdentity(this); +} + +// An analog of AnimatedContainer, which can animate its shaped border, for +// _InputBorder. This specialized animated container is needed because the +// _InputBorderGap, which is computed at layout time, is required by the +// _InputBorder's paint method. +class _BorderContainer extends StatefulWidget { + const _BorderContainer({ + required this.border, + required this.gap, + required this.gapAnimation, + required this.fillColor, + required this.hoverColor, + required this.isHovering, + }); + + final InputBorder border; + final _InputBorderGap gap; + final Animation<double> gapAnimation; + final Color fillColor; + final Color hoverColor; + final bool isHovering; + + @override + _BorderContainerState createState() => _BorderContainerState(); +} + +class _BorderContainerState extends State<_BorderContainer> with TickerProviderStateMixin { + static const Duration _kHoverDuration = Duration(milliseconds: 15); + + late AnimationController _controller; + late AnimationController _hoverColorController; + late Animation<double> _borderAnimation; + late _InputBorderTween _border; + late Animation<double> _hoverAnimation; + late ColorTween _hoverColorTween; + + @override + void initState() { + super.initState(); + _hoverColorController = AnimationController( + duration: _kHoverDuration, + value: widget.isHovering ? 1.0 : 0.0, + vsync: this, + ); + _controller = AnimationController( + duration: _kTransitionDuration, + vsync: this, + ); + _borderAnimation = CurvedAnimation( + parent: _controller, + curve: _kTransitionCurve, + reverseCurve: _kTransitionCurve.flipped, + ); + _border = _InputBorderTween( + begin: widget.border, + end: widget.border, + ); + _hoverAnimation = CurvedAnimation( + parent: _hoverColorController, + curve: Curves.linear, + ); + _hoverColorTween = ColorTween(begin: Colors.transparent, end: widget.hoverColor); + } + + @override + void dispose() { + _controller.dispose(); + _hoverColorController.dispose(); + super.dispose(); + } + + @override + void didUpdateWidget(_BorderContainer oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.border != oldWidget.border) { + _border = _InputBorderTween( + begin: oldWidget.border, + end: widget.border, + ); + _controller + ..value = 0.0 + ..forward(); + } + if (widget.hoverColor != oldWidget.hoverColor) { + _hoverColorTween = ColorTween(begin: Colors.transparent, end: widget.hoverColor); + } + if (widget.isHovering != oldWidget.isHovering) { + if (widget.isHovering) { + _hoverColorController.forward(); + } else { + _hoverColorController.reverse(); + } + } + } + + @override + Widget build(BuildContext context) { + return CustomPaint( + foregroundPainter: _InputBorderPainter( + repaint: Listenable.merge(<Listenable>[ + _borderAnimation, + widget.gap, + _hoverColorController, + ]), + borderAnimation: _borderAnimation, + border: _border, + gapAnimation: widget.gapAnimation, + gap: widget.gap, + textDirection: Directionality.of(context), + fillColor: widget.fillColor, + hoverColorTween: _hoverColorTween, + hoverAnimation: _hoverAnimation, + ), + ); + } +} + +// Used to "shake" the floating label to the left and right +// when the errorText first appears. +class _Shaker extends AnimatedWidget { + const _Shaker({ + required Animation<double> animation, + this.child, + }) : super(listenable: animation); + + final Widget? child; + + Animation<double> get animation => listenable as Animation<double>; + + double get translateX { + const double shakeDelta = 4.0; + final double t = animation.value; + if (t <= 0.25) { + return -t * shakeDelta; + } else if (t < 0.75) { + return (t - 0.5) * shakeDelta; + } else { + return (1.0 - t) * 4.0 * shakeDelta; + } + } + + @override + Widget build(BuildContext context) { + return Transform( + transform: Matrix4.translationValues(translateX, 0.0, 0.0), + child: child, + ); + } +} + +// Display the helper and error text. When the error text appears +// it fades and the helper text fades out. The error text also +// slides upwards a little when it first appears. +class _HelperError extends StatefulWidget { + const _HelperError({ + this.textAlign, + this.helperText, + this.helperStyle, + this.helperMaxLines, + this.error, + this.errorText, + this.errorStyle, + this.errorMaxLines, + }); + + final TextAlign? textAlign; + final String? helperText; + final TextStyle? helperStyle; + final int? helperMaxLines; + final Widget? error; + final String? errorText; + final TextStyle? errorStyle; + final int? errorMaxLines; + + @override + _HelperErrorState createState() => _HelperErrorState(); +} + +class _HelperErrorState extends State<_HelperError> with SingleTickerProviderStateMixin { + // If the height of this widget and the counter are zero ("empty") at + // layout time, no space is allocated for the subtext. + static const Widget empty = SizedBox.shrink(); + + late AnimationController _controller; + Widget? _helper; + Widget? _error; + + bool get _hasError => widget.errorText != null || widget.error != null; + + @override + void initState() { + super.initState(); + _controller = AnimationController( + duration: _kTransitionDuration, + vsync: this, + ); + if (_hasError) { + _error = _buildError(); + _controller.value = 1.0; + } else if (widget.helperText != null) { + _helper = _buildHelper(); + } + _controller.addListener(_handleChange); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + void _handleChange() { + setState(() { + // The _controller's value has changed. + }); + } + + @override + void didUpdateWidget(_HelperError old) { + super.didUpdateWidget(old); + + final Widget? newError = widget.error; + final String? newErrorText = widget.errorText; + final String? newHelperText = widget.helperText; + final Widget? oldError = old.error; + final String? oldErrorText = old.errorText; + final String? oldHelperText = old.helperText; + + final bool errorStateChanged = (newError != null) != (oldError != null); + final bool errorTextStateChanged = (newErrorText != null) != (oldErrorText != null); + final bool helperTextStateChanged = newErrorText == null && (newHelperText != null) != (oldHelperText != null); + + if (errorStateChanged || errorTextStateChanged || helperTextStateChanged) { + if (newError != null || newErrorText != null) { + _error = _buildError(); + _controller.forward(); + } else if (newHelperText != null) { + _helper = _buildHelper(); + _controller.reverse(); + } else { + _controller.reverse(); + } + } + } + + Widget _buildHelper() { + assert(widget.helperText != null); + return Semantics( + container: true, + child: FadeTransition( + opacity: Tween<double>(begin: 1.0, end: 0.0).animate(_controller), + child: Text( + widget.helperText!, + style: widget.helperStyle, + textAlign: widget.textAlign, + overflow: TextOverflow.ellipsis, + maxLines: widget.helperMaxLines, + ), + ), + ); + } + + Widget _buildError() { + assert(widget.error != null || widget.errorText != null); + return Semantics( + container: true, + child: FadeTransition( + opacity: _controller, + child: FractionalTranslation( + translation: Tween<Offset>( + begin: const Offset(0.0, -0.25), + end: Offset.zero, + ).evaluate(_controller.view), + child: widget.error ?? Text( + widget.errorText!, + style: widget.errorStyle, + textAlign: widget.textAlign, + overflow: TextOverflow.ellipsis, + maxLines: widget.errorMaxLines, + ), + ), + ), + ); + } + + @override + Widget build(BuildContext context) { + if (_controller.isDismissed) { + _error = null; + if (widget.helperText != null) { + return _helper = _buildHelper(); + } else { + _helper = null; + return empty; + } + } + + if (_controller.isCompleted) { + _helper = null; + if (_hasError) { + return _error = _buildError(); + } else { + _error = null; + return empty; + } + } + + if (_helper == null && _hasError) { + return _buildError(); + } + + if (_error == null && widget.helperText != null) { + return _buildHelper(); + } + + if (_hasError) { + return Stack( + children: <Widget>[ + FadeTransition( + opacity: Tween<double>(begin: 1.0, end: 0.0).animate(_controller), + child: _helper, + ), + _buildError(), + ], + ); + } + + if (widget.helperText != null) { + return Stack( + children: <Widget>[ + _buildHelper(), + FadeTransition( + opacity: _controller, + child: _error, + ), + ], + ); + } + + return empty; + } +} + +/// Defines **how** the floating label should behave. +/// +/// See also: +/// +/// * [InputDecoration.floatingLabelBehavior] which defines the behavior for +/// [InputDecoration.label] or [InputDecoration.labelText]. +/// * [FloatingLabelAlignment] which defines **where** the floating label +/// should displayed. +enum FloatingLabelBehavior { + /// The label will always be positioned within the content, or hidden. + never, + /// The label will float when the input is focused, or has content. + auto, + /// The label will always float above the content. + always, +} + +/// Defines **where** the floating label should be displayed within an +/// [InputDecorator]. +/// +/// See also: +/// +/// * [InputDecoration.floatingLabelAlignment] which defines the alignment for +/// [InputDecoration.label] or [InputDecoration.labelText]. +/// * [FloatingLabelBehavior] which defines **how** the floating label should +/// behave. +@immutable +class FloatingLabelAlignment { + const FloatingLabelAlignment._(this._x) : assert(_x >= -1.0 && _x <= 1.0); + + // -1 denotes start, 0 denotes center, and 1 denotes end. + final double _x; + + /// Align the floating label on the leading edge of the [InputDecorator]. + /// + /// For left-to-right text ([TextDirection.ltr]), this is the left edge. + /// + /// For right-to-left text ([TextDirection.rtl]), this is the right edge. + static const FloatingLabelAlignment start = FloatingLabelAlignment._(-1.0); + /// Aligns the floating label to the center of an [InputDecorator]. + static const FloatingLabelAlignment center = FloatingLabelAlignment._(0.0); + + @override + int get hashCode => _x.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is FloatingLabelAlignment + && _x == other._x; + } + + static String _stringify(double x) { + if (x == -1.0) { + return 'FloatingLabelAlignment.start'; + } + if (x == 0.0) { + return 'FloatingLabelAlignment.center'; + } + return 'FloatingLabelAlignment(x: ${x.toStringAsFixed(1)})'; + } + + @override + String toString() => _stringify(_x); +} + +// Identifies the children of a _RenderDecorationElement. +enum _DecorationSlot { + icon, + input, + label, + hint, + prefix, + suffix, + prefixIcon, + suffixIcon, + helperError, + counter, + container, +} + +// An analog of InputDecoration for the _Decorator widget. +@immutable +class _Decoration { + const _Decoration({ + required this.contentPadding, + required this.isCollapsed, + required this.floatingLabelHeight, + required this.floatingLabelProgress, + required this.floatingLabelAlignment, + required this.border, + required this.borderGap, + required this.alignLabelWithHint, + required this.isDense, + required this.visualDensity, + this.icon, + this.input, + this.label, + this.hint, + this.prefix, + this.suffix, + this.prefixIcon, + this.suffixIcon, + this.helperError, + this.counter, + this.container, + }); + + final EdgeInsetsGeometry contentPadding; + final bool isCollapsed; + final double floatingLabelHeight; + final double floatingLabelProgress; + final FloatingLabelAlignment floatingLabelAlignment; + final InputBorder border; + final _InputBorderGap borderGap; + final bool alignLabelWithHint; + final bool? isDense; + final VisualDensity visualDensity; + final Widget? icon; + final Widget? input; + final Widget? label; + final Widget? hint; + final Widget? prefix; + final Widget? suffix; + final Widget? prefixIcon; + final Widget? suffixIcon; + final Widget? helperError; + final Widget? counter; + final Widget? container; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is _Decoration + && other.contentPadding == contentPadding + && other.isCollapsed == isCollapsed + && other.floatingLabelHeight == floatingLabelHeight + && other.floatingLabelProgress == floatingLabelProgress + && other.floatingLabelAlignment == floatingLabelAlignment + && other.border == border + && other.borderGap == borderGap + && other.alignLabelWithHint == alignLabelWithHint + && other.isDense == isDense + && other.visualDensity == visualDensity + && other.icon == icon + && other.input == input + && other.label == label + && other.hint == hint + && other.prefix == prefix + && other.suffix == suffix + && other.prefixIcon == prefixIcon + && other.suffixIcon == suffixIcon + && other.helperError == helperError + && other.counter == counter + && other.container == container; + } + + @override + int get hashCode => Object.hash( + contentPadding, + floatingLabelHeight, + floatingLabelProgress, + floatingLabelAlignment, + border, + borderGap, + alignLabelWithHint, + isDense, + visualDensity, + icon, + input, + label, + hint, + prefix, + suffix, + prefixIcon, + suffixIcon, + helperError, + counter, + container, + ); +} + +// A container for the layout values computed by _RenderDecoration._layout. +// These values are used by _RenderDecoration.performLayout to position +// all of the renderer children of a _RenderDecoration. +class _RenderDecorationLayout { + const _RenderDecorationLayout({ + required this.boxToBaseline, + required this.inputBaseline, // for InputBorderType.underline + required this.outlineBaseline, // for InputBorderType.outline + required this.subtextBaseline, + required this.containerHeight, + required this.subtextHeight, + }); + + final Map<RenderBox?, double> boxToBaseline; + final double inputBaseline; + final double outlineBaseline; + final double subtextBaseline; // helper/error counter + final double containerHeight; + final double subtextHeight; +} + +// The workhorse: layout and paint a _Decorator widget's _Decoration. +class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin<_DecorationSlot, RenderBox> { + _RenderDecoration({ + required _Decoration decoration, + required TextDirection textDirection, + required TextBaseline textBaseline, + required bool isFocused, + required bool expands, + required bool material3, + TextAlignVertical? textAlignVertical, + }) : _decoration = decoration, + _textDirection = textDirection, + _textBaseline = textBaseline, + _textAlignVertical = textAlignVertical, + _isFocused = isFocused, + _expands = expands, + _material3 = material3; + + static const double subtextGap = 8.0; + + RenderBox? get icon => childForSlot(_DecorationSlot.icon); + RenderBox? get input => childForSlot(_DecorationSlot.input); + RenderBox? get label => childForSlot(_DecorationSlot.label); + RenderBox? get hint => childForSlot(_DecorationSlot.hint); + RenderBox? get prefix => childForSlot(_DecorationSlot.prefix); + RenderBox? get suffix => childForSlot(_DecorationSlot.suffix); + RenderBox? get prefixIcon => childForSlot(_DecorationSlot.prefixIcon); + RenderBox? get suffixIcon => childForSlot(_DecorationSlot.suffixIcon); + RenderBox? get helperError => childForSlot(_DecorationSlot.helperError); + RenderBox? get counter => childForSlot(_DecorationSlot.counter); + RenderBox? get container => childForSlot(_DecorationSlot.container); + + // The returned list is ordered for hit testing. + @override + Iterable<RenderBox> get children { + return <RenderBox>[ + if (icon != null) + icon!, + if (input != null) + input!, + if (prefixIcon != null) + prefixIcon!, + if (suffixIcon != null) + suffixIcon!, + if (prefix != null) + prefix!, + if (suffix != null) + suffix!, + if (label != null) + label!, + if (hint != null) + hint!, + if (helperError != null) + helperError!, + if (counter != null) + counter!, + if (container != null) + container!, + ]; + } + + _Decoration get decoration => _decoration; + _Decoration _decoration; + set decoration(_Decoration value) { + if (_decoration == value) { + return; + } + _decoration = value; + markNeedsLayout(); + } + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsLayout(); + } + + TextBaseline get textBaseline => _textBaseline; + TextBaseline _textBaseline; + set textBaseline(TextBaseline value) { + if (_textBaseline == value) { + return; + } + _textBaseline = value; + markNeedsLayout(); + } + + TextAlignVertical get _defaultTextAlignVertical => _isOutlineAligned + ? TextAlignVertical.center + : TextAlignVertical.top; + TextAlignVertical get textAlignVertical => _textAlignVertical ?? _defaultTextAlignVertical; + TextAlignVertical? _textAlignVertical; + set textAlignVertical(TextAlignVertical? value) { + if (_textAlignVertical == value) { + return; + } + // No need to relayout if the effective value is still the same. + if (textAlignVertical.y == (value?.y ?? _defaultTextAlignVertical.y)) { + _textAlignVertical = value; + return; + } + _textAlignVertical = value; + markNeedsLayout(); + } + + bool get isFocused => _isFocused; + bool _isFocused; + set isFocused(bool value) { + if (_isFocused == value) { + return; + } + _isFocused = value; + markNeedsSemanticsUpdate(); + } + + bool get expands => _expands; + bool _expands = false; + set expands(bool value) { + if (_expands == value) { + return; + } + _expands = value; + markNeedsLayout(); + } + + bool get material3 => _material3; + bool _material3 = false; + set material3(bool value) { + if (_material3 == value) { + return; + } + _material3 = value; + markNeedsLayout(); + } + + // Indicates that the decoration should be aligned to accommodate an outline + // border. + bool get _isOutlineAligned { + return !decoration.isCollapsed && decoration.border.isOutline; + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (icon != null) { + visitor(icon!); + } + if (prefix != null) { + visitor(prefix!); + } + if (prefixIcon != null) { + visitor(prefixIcon!); + } + + if (label != null) { + visitor(label!); + } + if (hint != null) { + if (isFocused) { + visitor(hint!); + } else if (label == null) { + visitor(hint!); + } + } + + if (input != null) { + visitor(input!); + } + if (suffixIcon != null) { + visitor(suffixIcon!); + } + if (suffix != null) { + visitor(suffix!); + } + if (container != null) { + visitor(container!); + } + if (helperError != null) { + visitor(helperError!); + } + if (counter != null) { + visitor(counter!); + } + } + + @override + bool get sizedByParent => false; + + static double _minWidth(RenderBox? box, double height) { + return box == null ? 0.0 : box.getMinIntrinsicWidth(height); + } + + static double _maxWidth(RenderBox? box, double height) { + return box == null ? 0.0 : box.getMaxIntrinsicWidth(height); + } + + static double _minHeight(RenderBox? box, double width) { + return box == null ? 0.0 : box.getMinIntrinsicHeight(width); + } + + static Size _boxSize(RenderBox? box) => box == null ? Size.zero : box.size; + + static BoxParentData _boxParentData(RenderBox box) => box.parentData! as BoxParentData; + + EdgeInsets get contentPadding => decoration.contentPadding as EdgeInsets; + + // Lay out the given box if needed, and return its baseline. + double _layoutLineBox(RenderBox? box, BoxConstraints constraints) { + if (box == null) { + return 0.0; + } + box.layout(constraints, parentUsesSize: true); + // Since internally, all layout is performed against the alphabetic baseline, + // (eg, ascents/descents are all relative to alphabetic, even if the font is + // an ideographic or hanging font), we should always obtain the reference + // baseline from the alphabetic baseline. The ideographic baseline is for + // use post-layout and is derived from the alphabetic baseline combined with + // the font metrics. + final double baseline = box.getDistanceToBaseline(TextBaseline.alphabetic)!; + + assert(() { + if (baseline >= 0) { + return true; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary("One of InputDecorator's children reported a negative baseline offset."), + ErrorDescription( + '${box.runtimeType}, of size ${box.size}, reported a negative ' + 'alphabetic baseline of $baseline.', + ), + ]); + }()); + return baseline; + } + + // Returns a value used by performLayout to position all of the renderers. + // This method applies layout to all of the renderers except the container. + // For convenience, the container is laid out in performLayout(). + _RenderDecorationLayout _layout(BoxConstraints layoutConstraints) { + assert( + layoutConstraints.maxWidth < double.infinity, + 'An InputDecorator, which is typically created by a TextField, cannot ' + 'have an unbounded width.\n' + 'This happens when the parent widget does not provide a finite width ' + 'constraint. For example, if the InputDecorator is contained by a Row, ' + 'then its width must be constrained. An Expanded widget or a SizedBox ' + 'can be used to constrain the width of the InputDecorator or the ' + 'TextField that contains it.', + ); + + // Margin on each side of subtext (counter and helperError) + final Map<RenderBox?, double> boxToBaseline = <RenderBox?, double>{}; + final BoxConstraints boxConstraints = layoutConstraints.loosen(); + + // Layout all the widgets used by InputDecorator + boxToBaseline[icon] = _layoutLineBox(icon, boxConstraints); + final BoxConstraints containerConstraints = boxConstraints.copyWith( + maxWidth: boxConstraints.maxWidth - _boxSize(icon).width, + ); + boxToBaseline[prefixIcon] = _layoutLineBox(prefixIcon, containerConstraints); + boxToBaseline[suffixIcon] = _layoutLineBox(suffixIcon, containerConstraints); + final BoxConstraints contentConstraints = containerConstraints.copyWith( + maxWidth: math.max(0.0, containerConstraints.maxWidth - contentPadding.horizontal), + ); + boxToBaseline[prefix] = _layoutLineBox(prefix, contentConstraints); + boxToBaseline[suffix] = _layoutLineBox(suffix, contentConstraints); + + final double inputWidth = math.max( + 0.0, + constraints.maxWidth - ( + _boxSize(icon).width + + (prefixIcon != null ? 0 : (textDirection == TextDirection.ltr ? contentPadding.left : contentPadding.right)) + + _boxSize(prefixIcon).width + + _boxSize(prefix).width + + _boxSize(suffix).width + + _boxSize(suffixIcon).width + + (suffixIcon != null ? 0 : (textDirection == TextDirection.ltr ? contentPadding.right : contentPadding.left))), + ); + // Increase the available width for the label when it is scaled down. + final double invertedLabelScale = lerpDouble(1.00, 1 / _kFinalLabelScale, decoration.floatingLabelProgress)!; + double suffixIconWidth = _boxSize(suffixIcon).width; + if (decoration.border.isOutline) { + suffixIconWidth = lerpDouble(suffixIconWidth, 0.0, decoration.floatingLabelProgress)!; + } + final double labelWidth = math.max( + 0.0, + constraints.maxWidth - ( + _boxSize(icon).width + + contentPadding.left + + _boxSize(prefixIcon).width + + suffixIconWidth + + contentPadding.right), + ); + boxToBaseline[label] = _layoutLineBox( + label, + boxConstraints.copyWith(maxWidth: labelWidth * invertedLabelScale), + ); + boxToBaseline[hint] = _layoutLineBox( + hint, + boxConstraints.copyWith(minWidth: inputWidth, maxWidth: inputWidth), + ); + boxToBaseline[counter] = _layoutLineBox(counter, contentConstraints); + + // The helper or error text can occupy the full width less the space + // occupied by the icon and counter. + boxToBaseline[helperError] = _layoutLineBox( + helperError, + contentConstraints.copyWith( + maxWidth: math.max(0.0, contentConstraints.maxWidth - _boxSize(counter).width), + ), + ); + + // The height of the input needs to accommodate label above and counter and + // helperError below, when they exist. + final double labelHeight = label == null + ? 0 + : decoration.floatingLabelHeight; + final double topHeight = decoration.border.isOutline + ? math.max(labelHeight - boxToBaseline[label]!, 0) + : labelHeight; + final double counterHeight = counter == null + ? 0 + : boxToBaseline[counter]! + subtextGap; + final bool helperErrorExists = helperError?.size != null + && helperError!.size.height > 0; + final double helperErrorHeight = !helperErrorExists + ? 0 + : helperError!.size.height + subtextGap; + final double bottomHeight = math.max( + counterHeight, + helperErrorHeight, + ); + final Offset densityOffset = decoration.visualDensity.baseSizeAdjustment; + boxToBaseline[input] = _layoutLineBox( + input, + boxConstraints.deflate(EdgeInsets.only( + top: contentPadding.top + topHeight + densityOffset.dy / 2, + bottom: contentPadding.bottom + bottomHeight + densityOffset.dy / 2, + )).copyWith( + minWidth: inputWidth, + maxWidth: inputWidth, + ), + ); + + // The field can be occupied by a hint or by the input itself + final double hintHeight = hint?.size.height ?? 0; + final double inputDirectHeight = input?.size.height ?? 0; + final double inputHeight = math.max(hintHeight, inputDirectHeight); + final double inputInternalBaseline = math.max( + boxToBaseline[input]!, + boxToBaseline[hint]!, + ); + + // Calculate the amount that prefix/suffix affects height above and below + // the input. + final double prefixHeight = prefix?.size.height ?? 0; + final double suffixHeight = suffix?.size.height ?? 0; + final double fixHeight = math.max( + boxToBaseline[prefix]!, + boxToBaseline[suffix]!, + ); + final double fixAboveInput = math.max(0, fixHeight - inputInternalBaseline); + final double fixBelowBaseline = math.max( + prefixHeight - boxToBaseline[prefix]!, + suffixHeight - boxToBaseline[suffix]!, + ); + // TODO(justinmc): fixBelowInput should have no effect when there is no + // prefix/suffix below the input. + // https://github.com/flutter/flutter/issues/66050 + final double fixBelowInput = math.max( + 0, + fixBelowBaseline - (inputHeight - inputInternalBaseline), + ); + + // Calculate the height of the input text container. + final double prefixIconHeight = prefixIcon?.size.height ?? 0; + final double suffixIconHeight = suffixIcon?.size.height ?? 0; + final double fixIconHeight = math.max(prefixIconHeight, suffixIconHeight); + final double contentHeight = math.max( + fixIconHeight, + topHeight + + contentPadding.top + + fixAboveInput + + inputHeight + + fixBelowInput + + contentPadding.bottom + + densityOffset.dy, + ); + final double minContainerHeight = decoration.isDense! || decoration.isCollapsed || expands + ? 0.0 + : kMinInteractiveDimension; + final double maxContainerHeight = math.max(0.0, boxConstraints.maxHeight - bottomHeight); + final double containerHeight = expands + ? maxContainerHeight + : math.min(math.max(contentHeight, minContainerHeight), maxContainerHeight); + + // Ensure the text is vertically centered in cases where the content is + // shorter than kMinInteractiveDimension. + final double interactiveAdjustment = minContainerHeight > contentHeight + ? (minContainerHeight - contentHeight) / 2.0 + : 0.0; + + // Try to consider the prefix/suffix as part of the text when aligning it. + // If the prefix/suffix overflows however, allow it to extend outside of the + // input and align the remaining part of the text and prefix/suffix. + final double overflow = math.max(0, contentHeight - maxContainerHeight); + // Map textAlignVertical from -1:1 to 0:1 so that it can be used to scale + // the baseline from its minimum to maximum values. + final double textAlignVerticalFactor = (textAlignVertical.y + 1.0) / 2.0; + // Adjust to try to fit top overflow inside the input on an inverse scale of + // textAlignVertical, so that top aligned text adjusts the most and bottom + // aligned text doesn't adjust at all. + final double baselineAdjustment = fixAboveInput - overflow * (1 - textAlignVerticalFactor); + + // The baselines that will be used to draw the actual input text content. + final double topInputBaseline = contentPadding.top + + topHeight + + inputInternalBaseline + + baselineAdjustment + + interactiveAdjustment + + densityOffset.dy / 2.0; + final double maxContentHeight = containerHeight - contentPadding.vertical - topHeight - densityOffset.dy; + final double alignableHeight = fixAboveInput + inputHeight + fixBelowInput; + final double maxVerticalOffset = maxContentHeight - alignableHeight; + final double textAlignVerticalOffset = maxVerticalOffset * textAlignVerticalFactor; + final double inputBaseline = topInputBaseline + textAlignVerticalOffset; + + // The three main alignments for the baseline when an outline is present are + // + // * top (-1.0): topmost point considering padding. + // * center (0.0): the absolute center of the input ignoring padding but + // accommodating the border and floating label. + // * bottom (1.0): bottommost point considering padding. + // + // That means that if the padding is uneven, center is not the exact + // midpoint of top and bottom. To account for this, the above center and + // below center alignments are interpolated independently. + final double outlineCenterBaseline = inputInternalBaseline + + baselineAdjustment / 2.0 + + (containerHeight - (2.0 + inputHeight)) / 2.0; + final double outlineTopBaseline = topInputBaseline; + final double outlineBottomBaseline = topInputBaseline + maxVerticalOffset; + final double outlineBaseline = _interpolateThree( + outlineTopBaseline, + outlineCenterBaseline, + outlineBottomBaseline, + textAlignVertical, + ); + + // Find the positions of the text below the input when it exists. + double subtextCounterBaseline = 0; + double subtextHelperBaseline = 0; + double subtextCounterHeight = 0; + double subtextHelperHeight = 0; + if (counter != null) { + subtextCounterBaseline = + containerHeight + subtextGap + boxToBaseline[counter]!; + subtextCounterHeight = counter!.size.height + subtextGap; + } + if (helperErrorExists) { + subtextHelperBaseline = + containerHeight + subtextGap + boxToBaseline[helperError]!; + subtextHelperHeight = helperErrorHeight; + } + final double subtextBaseline = math.max( + subtextCounterBaseline, + subtextHelperBaseline, + ); + final double subtextHeight = math.max( + subtextCounterHeight, + subtextHelperHeight, + ); + + return _RenderDecorationLayout( + boxToBaseline: boxToBaseline, + containerHeight: containerHeight, + inputBaseline: inputBaseline, + outlineBaseline: outlineBaseline, + subtextBaseline: subtextBaseline, + subtextHeight: subtextHeight, + ); + } + + // Interpolate between three stops using textAlignVertical. This is used to + // calculate the outline baseline, which ignores padding when the alignment is + // middle. When the alignment is less than zero, it interpolates between the + // centered text box's top and the top of the content padding. When the + // alignment is greater than zero, it interpolates between the centered box's + // top and the position that would align the bottom of the box with the bottom + // padding. + double _interpolateThree(double begin, double middle, double end, TextAlignVertical textAlignVertical) { + if (textAlignVertical.y <= 0) { + // It's possible for begin, middle, and end to not be in order because of + // excessive padding. Those cases are handled by using middle. + if (begin >= middle) { + return middle; + } + // Do a standard linear interpolation on the first half, between begin and + // middle. + final double t = textAlignVertical.y + 1; + return begin + (middle - begin) * t; + } + + if (middle >= end) { + return middle; + } + // Do a standard linear interpolation on the second half, between middle and + // end. + final double t = textAlignVertical.y; + return middle + (end - middle) * t; + } + + @override + double computeMinIntrinsicWidth(double height) { + return _minWidth(icon, height) + + (prefixIcon != null ? 0.0 : (textDirection == TextDirection.ltr ? contentPadding.left : contentPadding.right)) + + _minWidth(prefixIcon, height) + + _minWidth(prefix, height) + + math.max(_minWidth(input, height), _minWidth(hint, height)) + + _minWidth(suffix, height) + + _minWidth(suffixIcon, height) + + (suffixIcon != null ? 0.0 : (textDirection == TextDirection.ltr ? contentPadding.right : contentPadding.left)); + } + + @override + double computeMaxIntrinsicWidth(double height) { + return _maxWidth(icon, height) + + (prefixIcon != null ? 0.0 : (textDirection == TextDirection.ltr ? contentPadding.left : contentPadding.right)) + + _maxWidth(prefixIcon, height) + + _maxWidth(prefix, height) + + math.max(_maxWidth(input, height), _maxWidth(hint, height)) + + _maxWidth(suffix, height) + + _maxWidth(suffixIcon, height) + + (suffixIcon != null ? 0.0 : (textDirection == TextDirection.ltr ? contentPadding.right : contentPadding.left)); + } + + double _lineHeight(double width, List<RenderBox?> boxes) { + double height = 0.0; + for (final RenderBox? box in boxes) { + if (box == null) { + continue; + } + height = math.max(_minHeight(box, width), height); + } + return height; + // TODO(hansmuller): this should compute the overall line height for the + // boxes when they've been baseline-aligned. + // See https://github.com/flutter/flutter/issues/13715 + } + + @override + double computeMinIntrinsicHeight(double width) { + final double iconHeight = _minHeight(icon, width); + final double iconWidth = _minWidth(icon, iconHeight); + + width = math.max(width - iconWidth, 0.0); + + final double prefixIconHeight = _minHeight(prefixIcon, width); + final double prefixIconWidth = _minWidth(prefixIcon, prefixIconHeight); + + final double suffixIconHeight = _minHeight(suffixIcon, width); + final double suffixIconWidth = _minWidth(suffixIcon, suffixIconHeight); + + width = math.max(width - contentPadding.horizontal, 0.0); + + final double counterHeight = _minHeight(counter, width); + final double counterWidth = _minWidth(counter, counterHeight); + + final double helperErrorAvailableWidth = math.max(width - counterWidth, 0.0); + final double helperErrorHeight = _minHeight(helperError, helperErrorAvailableWidth); + double subtextHeight = math.max(counterHeight, helperErrorHeight); + if (subtextHeight > 0.0) { + subtextHeight += subtextGap; + } + + final double prefixHeight = _minHeight(prefix, width); + final double prefixWidth = _minWidth(prefix, prefixHeight); + + final double suffixHeight = _minHeight(suffix, width); + final double suffixWidth = _minWidth(suffix, suffixHeight); + + final double availableInputWidth = math.max(width - prefixWidth - suffixWidth - prefixIconWidth - suffixIconWidth, 0.0); + final double inputHeight = _lineHeight(availableInputWidth, <RenderBox?>[input, hint]); + final double inputMaxHeight = <double>[inputHeight, prefixHeight, suffixHeight].reduce(math.max); + + final Offset densityOffset = decoration.visualDensity.baseSizeAdjustment; + final double contentHeight = contentPadding.top + + (label == null ? 0.0 : decoration.floatingLabelHeight) + + inputMaxHeight + + contentPadding.bottom + + densityOffset.dy; + final double containerHeight = <double>[iconHeight, contentHeight, prefixIconHeight, suffixIconHeight].reduce(math.max); + final double minContainerHeight = decoration.isDense! || expands + ? 0.0 + : kMinInteractiveDimension; + return math.max(containerHeight, minContainerHeight) + subtextHeight; + } + + @override + double computeMaxIntrinsicHeight(double width) { + return computeMinIntrinsicHeight(width); + } + + @override + double computeDistanceToActualBaseline(TextBaseline baseline) { + return _boxParentData(input!).offset.dy + (input?.computeDistanceToActualBaseline(baseline) ?? 0.0); + } + + // Records where the label was painted. + Matrix4? _labelTransform; + + @override + Size computeDryLayout(BoxConstraints constraints) { + assert(debugCannotComputeDryLayout( + reason: 'Layout requires baseline metrics, which are only available after a full layout.', + )); + return Size.zero; + } + + ChildSemanticsConfigurationsResult _childSemanticsConfigurationDelegate(List<SemanticsConfiguration> childConfigs) { + final ChildSemanticsConfigurationsResultBuilder builder = ChildSemanticsConfigurationsResultBuilder(); + List<SemanticsConfiguration>? prefixMergeGroup; + List<SemanticsConfiguration>? suffixMergeGroup; + for (final SemanticsConfiguration childConfig in childConfigs) { + if (childConfig.tagsChildrenWith(_InputDecoratorState._kPrefixSemanticsTag)) { + prefixMergeGroup ??= <SemanticsConfiguration>[]; + prefixMergeGroup.add(childConfig); + } else if (childConfig.tagsChildrenWith(_InputDecoratorState._kSuffixSemanticsTag)) { + suffixMergeGroup ??= <SemanticsConfiguration>[]; + suffixMergeGroup.add(childConfig); + } else { + builder.markAsMergeUp(childConfig); + } + } + if (prefixMergeGroup != null) { + builder.markAsSiblingMergeGroup(prefixMergeGroup); + } + if (suffixMergeGroup != null) { + builder.markAsSiblingMergeGroup(suffixMergeGroup); + } + return builder.build(); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + config.childConfigurationsDelegate = _childSemanticsConfigurationDelegate; + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + _labelTransform = null; + final _RenderDecorationLayout layout = _layout(constraints); + + final double overallWidth = constraints.maxWidth; + final double overallHeight = layout.containerHeight + layout.subtextHeight; + + final RenderBox? container = this.container; + if (container != null) { + final BoxConstraints containerConstraints = BoxConstraints.tightFor( + height: layout.containerHeight, + width: overallWidth - _boxSize(icon).width, + ); + container.layout(containerConstraints, parentUsesSize: true); + final double x; + switch (textDirection) { + case TextDirection.rtl: + x = 0.0; + case TextDirection.ltr: + x = _boxSize(icon).width; + } + _boxParentData(container).offset = Offset(x, 0.0); + } + + late double height; + double centerLayout(RenderBox box, double x) { + _boxParentData(box).offset = Offset(x, (height - box.size.height) / 2.0); + return box.size.width; + } + + late double baseline; + double baselineLayout(RenderBox box, double x) { + _boxParentData(box).offset = Offset(x, baseline - layout.boxToBaseline[box]!); + return box.size.width; + } + + final double left = contentPadding.left; + final double right = overallWidth - contentPadding.right; + + height = layout.containerHeight; + baseline = _isOutlineAligned ? layout.outlineBaseline : layout.inputBaseline; + + if (icon != null) { + final double x; + switch (textDirection) { + case TextDirection.rtl: + x = overallWidth - icon!.size.width; + case TextDirection.ltr: + x = 0.0; + } + centerLayout(icon!, x); + } + + switch (textDirection) { + case TextDirection.rtl: { + double start = right - _boxSize(icon).width; + double end = left; + if (prefixIcon != null) { + start += contentPadding.right; + start -= centerLayout(prefixIcon!, start - prefixIcon!.size.width); + } + if (label != null) { + if (decoration.alignLabelWithHint) { + baselineLayout(label!, start - label!.size.width); + } else { + centerLayout(label!, start - label!.size.width); + } + } + if (prefix != null) { + start -= baselineLayout(prefix!, start - prefix!.size.width); + } + if (input != null) { + baselineLayout(input!, start - input!.size.width); + } + if (hint != null) { + baselineLayout(hint!, start - hint!.size.width); + } + if (suffixIcon != null) { + end -= contentPadding.left; + end += centerLayout(suffixIcon!, end); + } + if (suffix != null) { + end += baselineLayout(suffix!, end); + } + break; + } + case TextDirection.ltr: { + double start = left + _boxSize(icon).width; + double end = right; + if (prefixIcon != null) { + start -= contentPadding.left; + start += centerLayout(prefixIcon!, start); + } + if (label != null) { + if (decoration.alignLabelWithHint) { + baselineLayout(label!, start); + } else { + centerLayout(label!, start); + } + } + if (prefix != null) { + start += baselineLayout(prefix!, start); + } + if (input != null) { + baselineLayout(input!, start); + } + if (hint != null) { + baselineLayout(hint!, start); + } + if (suffixIcon != null) { + end += contentPadding.right; + end -= centerLayout(suffixIcon!, end - suffixIcon!.size.width); + } + if (suffix != null) { + end -= baselineLayout(suffix!, end - suffix!.size.width); + } + break; + } + } + + if (helperError != null || counter != null) { + height = layout.subtextHeight; + baseline = layout.subtextBaseline; + + switch (textDirection) { + case TextDirection.rtl: + if (helperError != null) { + baselineLayout(helperError!, right - helperError!.size.width - _boxSize(icon).width); + } + if (counter != null) { + baselineLayout(counter!, left); + } + case TextDirection.ltr: + if (helperError != null) { + baselineLayout(helperError!, left + _boxSize(icon).width); + } + if (counter != null) { + baselineLayout(counter!, right - counter!.size.width); + } + } + } + + if (label != null) { + final double labelX = _boxParentData(label!).offset.dx; + // +1 shifts the range of x from (-1.0, 1.0) to (0.0, 2.0). + final double floatAlign = decoration.floatingLabelAlignment._x + 1; + final double floatWidth = _boxSize(label).width * _kFinalLabelScale; + // When floating label is centered, its x is relative to + // _BorderContainer's x and is independent of label's x. + switch (textDirection) { + case TextDirection.rtl: + double offsetToPrefixIcon = 0.0; + if (prefixIcon != null && !decoration.alignLabelWithHint) { + offsetToPrefixIcon = material3 ? _boxSize(prefixIcon).width - left : 0; + } + decoration.borderGap.start = lerpDouble(labelX + _boxSize(label).width + offsetToPrefixIcon, + _boxSize(container).width / 2.0 + floatWidth / 2.0, + floatAlign); + + case TextDirection.ltr: + // The value of _InputBorderGap.start is relative to the origin of the + // _BorderContainer which is inset by the icon's width. Although, when + // floating label is centered, it's already relative to _BorderContainer. + double offsetToPrefixIcon = 0.0; + if (prefixIcon != null && !decoration.alignLabelWithHint) { + offsetToPrefixIcon = material3 ? (-_boxSize(prefixIcon).width + left) : 0; + } + decoration.borderGap.start = lerpDouble(labelX - _boxSize(icon).width + offsetToPrefixIcon, + _boxSize(container).width / 2.0 - floatWidth / 2.0, + floatAlign); + } + decoration.borderGap.extent = label!.size.width * _kFinalLabelScale; + } else { + decoration.borderGap.start = null; + decoration.borderGap.extent = 0.0; + } + + size = constraints.constrain(Size(overallWidth, overallHeight)); + assert(size.width == constraints.constrainWidth(overallWidth)); + assert(size.height == constraints.constrainHeight(overallHeight)); + } + + void _paintLabel(PaintingContext context, Offset offset) { + context.paintChild(label!, offset); + } + + @override + void paint(PaintingContext context, Offset offset) { + void doPaint(RenderBox? child) { + if (child != null) { + context.paintChild(child, _boxParentData(child).offset + offset); + } + } + doPaint(container); + + if (label != null) { + final Offset labelOffset = _boxParentData(label!).offset; + final double labelHeight = _boxSize(label).height; + final double labelWidth = _boxSize(label).width; + // +1 shifts the range of x from (-1.0, 1.0) to (0.0, 2.0). + final double floatAlign = decoration.floatingLabelAlignment._x + 1; + final double floatWidth = labelWidth * _kFinalLabelScale; + final double borderWeight = decoration.border.borderSide.width; + final double t = decoration.floatingLabelProgress; + // The center of the outline border label ends up a little below the + // center of the top border line. + final bool isOutlineBorder = decoration.border.isOutline; + // Temporary opt-in fix for https://github.com/flutter/flutter/issues/54028 + // Center the scaled label relative to the border. + final double floatingY = isOutlineBorder ? (-labelHeight * _kFinalLabelScale) / 2.0 + borderWeight / 2.0 : contentPadding.top; + final double scale = lerpDouble(1.0, _kFinalLabelScale, t)!; + final double centeredFloatX = _boxParentData(container!).offset.dx + + _boxSize(container).width / 2.0 - floatWidth / 2.0; + final double startX; + double floatStartX; + switch (textDirection) { + case TextDirection.rtl: // origin is on the right + startX = labelOffset.dx + labelWidth * (1.0 - scale); + floatStartX = startX; + if (prefixIcon != null && !decoration.alignLabelWithHint && isOutlineBorder) { + floatStartX += material3 ? _boxSize(prefixIcon).width - contentPadding.left : 0.0; + } + case TextDirection.ltr: // origin on the left + startX = labelOffset.dx; + floatStartX = startX; + if (prefixIcon != null && !decoration.alignLabelWithHint && isOutlineBorder) { + floatStartX += material3 ? -_boxSize(prefixIcon).width + contentPadding.left : 0.0; + } + } + final double floatEndX = lerpDouble(floatStartX, centeredFloatX, floatAlign)!; + final double dx = lerpDouble(startX, floatEndX, t)!; + final double dy = lerpDouble(0.0, floatingY - labelOffset.dy, t)!; + _labelTransform = Matrix4.identity() + ..translate(dx, labelOffset.dy + dy) + ..scale(scale); + layer = context.pushTransform( + needsCompositing, + offset, + _labelTransform!, + _paintLabel, + oldLayer: layer as TransformLayer?, + ); + } else { + layer = null; + } + + doPaint(icon); + doPaint(prefix); + doPaint(suffix); + doPaint(prefixIcon); + doPaint(suffixIcon); + doPaint(hint); + doPaint(input); + doPaint(helperError); + doPaint(counter); + } + + @override + bool hitTestSelf(Offset position) => true; + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + for (final RenderBox child in children) { + // The label must be handled specially since we've transformed it. + final Offset offset = _boxParentData(child).offset; + final bool isHit = result.addWithPaintOffset( + offset: offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - offset); + return child.hitTest(result, position: transformed); + }, + ); + if (isHit) { + return true; + } + } + return false; + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + if (child == label && _labelTransform != null) { + final Offset labelOffset = _boxParentData(label!).offset; + transform + ..multiply(_labelTransform!) + ..translate(-labelOffset.dx, -labelOffset.dy); + } + super.applyPaintTransform(child, transform); + } +} + +class _Decorator extends SlottedMultiChildRenderObjectWidget<_DecorationSlot, RenderBox> { + const _Decorator({ + required this.textAlignVertical, + required this.decoration, + required this.textDirection, + required this.textBaseline, + required this.isFocused, + required this.expands, + }); + + final _Decoration decoration; + final TextDirection textDirection; + final TextBaseline textBaseline; + final TextAlignVertical? textAlignVertical; + final bool isFocused; + final bool expands; + + @override + Iterable<_DecorationSlot> get slots => _DecorationSlot.values; + + @override + Widget? childForSlot(_DecorationSlot slot) { + switch (slot) { + case _DecorationSlot.icon: + return decoration.icon; + case _DecorationSlot.input: + return decoration.input; + case _DecorationSlot.label: + return decoration.label; + case _DecorationSlot.hint: + return decoration.hint; + case _DecorationSlot.prefix: + return decoration.prefix; + case _DecorationSlot.suffix: + return decoration.suffix; + case _DecorationSlot.prefixIcon: + return decoration.prefixIcon; + case _DecorationSlot.suffixIcon: + return decoration.suffixIcon; + case _DecorationSlot.helperError: + return decoration.helperError; + case _DecorationSlot.counter: + return decoration.counter; + case _DecorationSlot.container: + return decoration.container; + } + } + + @override + _RenderDecoration createRenderObject(BuildContext context) { + return _RenderDecoration( + decoration: decoration, + textDirection: textDirection, + textBaseline: textBaseline, + textAlignVertical: textAlignVertical, + isFocused: isFocused, + expands: expands, + material3: Theme.of(context).useMaterial3, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderDecoration renderObject) { + renderObject + ..decoration = decoration + ..expands = expands + ..isFocused = isFocused + ..textAlignVertical = textAlignVertical + ..textBaseline = textBaseline + ..textDirection = textDirection; + } +} + +class _AffixText extends StatelessWidget { + const _AffixText({ + required this.labelIsFloating, + this.text, + this.style, + this.child, + this.semanticsSortKey, + required this.semanticsTag, + }); + + final bool labelIsFloating; + final String? text; + final TextStyle? style; + final Widget? child; + final SemanticsSortKey? semanticsSortKey; + final SemanticsTag semanticsTag; + + @override + Widget build(BuildContext context) { + return DefaultTextStyle.merge( + style: style, + child: AnimatedOpacity( + duration: _kTransitionDuration, + curve: _kTransitionCurve, + opacity: labelIsFloating ? 1.0 : 0.0, + child: Semantics( + sortKey: semanticsSortKey, + tagForChildren: semanticsTag, + child: child ?? (text == null ? null : Text(text!, style: style)), + ), + ), + ); + } +} + +/// Defines the appearance of a Material Design text field. +/// +/// [InputDecorator] displays the visual elements of a Material Design text +/// field around its input [child]. The visual elements themselves are defined +/// by an [InputDecoration] object and their layout and appearance depend +/// on the `baseStyle`, `textAlign`, `isFocused`, and `isEmpty` parameters. +/// +/// [TextField] uses this widget to decorate its [EditableText] child. +/// +/// [InputDecorator] can be used to create widgets that look and behave like a +/// [TextField] but support other kinds of input. +/// +/// Requires one of its ancestors to be a [Material] widget. The [child] widget, +/// as well as the decorative widgets specified in [decoration], must have +/// non-negative baselines. +/// +/// See also: +/// +/// * [TextField], which uses an [InputDecorator] to display a border, +/// labels, and icons, around its [EditableText] child. +/// * [Decoration] and [DecoratedBox], for drawing arbitrary decorations +/// around other widgets. +class InputDecorator extends StatefulWidget { + /// Creates a widget that displays a border, labels, and icons, + /// for a [TextField]. + /// + /// The [isFocused], [isHovering], [expands], and [isEmpty] arguments must not + /// be null. + const InputDecorator({ + super.key, + required this.decoration, + this.baseStyle, + this.textAlign, + this.textAlignVertical, + this.isFocused = false, + this.isHovering = false, + this.expands = false, + this.isEmpty = false, + this.child, + }); + + /// The text and styles to use when decorating the child. + /// + /// Null [InputDecoration] properties are initialized with the corresponding + /// values from [ThemeData.inputDecorationTheme]. + final InputDecoration decoration; + + /// The style on which to base the label, hint, counter, and error styles + /// if the [decoration] does not provide explicit styles. + /// + /// If null, [baseStyle] defaults to the `titleMedium` style from the + /// current [Theme], see [ThemeData.textTheme]. + /// + /// The [TextStyle.textBaseline] of the [baseStyle] is used to determine + /// the baseline used for text alignment. + final TextStyle? baseStyle; + + /// How the text in the decoration should be aligned horizontally. + final TextAlign? textAlign; + + /// {@template flutter.material.InputDecorator.textAlignVertical} + /// How the text should be aligned vertically. + /// + /// Determines the alignment of the baseline within the available space of + /// the input (typically a TextField). For example, TextAlignVertical.top will + /// place the baseline such that the text, and any attached decoration like + /// prefix and suffix, is as close to the top of the input as possible without + /// overflowing. The heights of the prefix and suffix are similarly included + /// for other alignment values. If the height is greater than the height + /// available, then the prefix and suffix will be allowed to overflow first + /// before the text scrolls. + /// {@endtemplate} + final TextAlignVertical? textAlignVertical; + + /// Whether the input field has focus. + /// + /// Determines the position of the label text and the color and weight of the + /// border. + /// + /// Defaults to false. + /// + /// See also: + /// + /// * [InputDecoration.hoverColor], which is also blended into the focus + /// color and fill color when the [isHovering] is true to produce the final + /// color. + final bool isFocused; + + /// Whether the input field is being hovered over by a mouse pointer. + /// + /// Determines the container fill color, which is a blend of + /// [InputDecoration.hoverColor] with [InputDecoration.fillColor] when + /// true, and [InputDecoration.fillColor] when not. + /// + /// Defaults to false. + final bool isHovering; + + /// If true, the height of the input field will be as large as possible. + /// + /// If wrapped in a widget that constrains its child's height, like Expanded + /// or SizedBox, the input field will only be affected if [expands] is set to + /// true. + /// + /// See [TextField.minLines] and [TextField.maxLines] for related ways to + /// affect the height of an input. When [expands] is true, both must be null + /// in order to avoid ambiguity in determining the height. + /// + /// Defaults to false. + final bool expands; + + /// Whether the input field is empty. + /// + /// Determines the position of the label text and whether to display the hint + /// text. + /// + /// Defaults to false. + final bool isEmpty; + + /// The widget below this widget in the tree. + /// + /// Typically an [EditableText], [DropdownButton], or [InkWell]. + final Widget? child; + + /// Whether the label needs to get out of the way of the input, either by + /// floating or disappearing. + /// + /// Will withdraw when not empty, or when focused while enabled. + bool get _labelShouldWithdraw => !isEmpty || (isFocused && decoration.enabled); + + @override + State<InputDecorator> createState() => _InputDecoratorState(); + + /// The RenderBox that defines this decorator's "container". That's the + /// area which is filled if [InputDecoration.filled] is true. It's the area + /// adjacent to [InputDecoration.icon] and above the widgets that contain + /// [InputDecoration.helperText], [InputDecoration.errorText], and + /// [InputDecoration.counterText]. + /// + /// [TextField] renders ink splashes within the container. + static RenderBox? containerOf(BuildContext context) { + final _RenderDecoration? result = context.findAncestorRenderObjectOfType<_RenderDecoration>(); + return result?.container; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<InputDecoration>('decoration', decoration)); + properties.add(DiagnosticsProperty<TextStyle>('baseStyle', baseStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('isFocused', isFocused)); + properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false)); + properties.add(DiagnosticsProperty<bool>('isEmpty', isEmpty)); + } +} + +class _InputDecoratorState extends State<InputDecorator> with TickerProviderStateMixin { + late final AnimationController _floatingLabelController; + late final Animation<double> _floatingLabelAnimation; + late final AnimationController _shakingLabelController; + final _InputBorderGap _borderGap = _InputBorderGap(); + static const OrdinalSortKey _kPrefixSemanticsSortOrder = OrdinalSortKey(0); + static const OrdinalSortKey _kInputSemanticsSortOrder = OrdinalSortKey(1); + static const OrdinalSortKey _kSuffixSemanticsSortOrder = OrdinalSortKey(2); + static const SemanticsTag _kPrefixSemanticsTag = SemanticsTag('_InputDecoratorState.prefix'); + static const SemanticsTag _kSuffixSemanticsTag = SemanticsTag('_InputDecoratorState.suffix'); + + @override + void initState() { + super.initState(); + + final bool labelIsInitiallyFloating = widget.decoration.floatingLabelBehavior == FloatingLabelBehavior.always + || (widget.decoration.floatingLabelBehavior != FloatingLabelBehavior.never && + widget._labelShouldWithdraw); + + _floatingLabelController = AnimationController( + duration: _kTransitionDuration, + vsync: this, + value: labelIsInitiallyFloating ? 1.0 : 0.0, + ); + _floatingLabelController.addListener(_handleChange); + _floatingLabelAnimation = CurvedAnimation( + parent: _floatingLabelController, + curve: _kTransitionCurve, + reverseCurve: _kTransitionCurve.flipped, + ); + + _shakingLabelController = AnimationController( + duration: _kTransitionDuration, + vsync: this, + ); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _effectiveDecoration = null; + } + + @override + void dispose() { + _floatingLabelController.dispose(); + _shakingLabelController.dispose(); + _borderGap.dispose(); + super.dispose(); + } + + void _handleChange() { + setState(() { + // The _floatingLabelController's value has changed. + }); + } + + InputDecoration? _effectiveDecoration; + InputDecoration get decoration => _effectiveDecoration ??= widget.decoration.applyDefaults(Theme.of(context).inputDecorationTheme); + + TextAlign? get textAlign => widget.textAlign; + bool get isFocused => widget.isFocused; + bool get _hasError => decoration.errorText != null || decoration.error != null; + bool get isHovering => widget.isHovering && decoration.enabled; + bool get isEmpty => widget.isEmpty; + bool get _floatingLabelEnabled { + return decoration.floatingLabelBehavior != FloatingLabelBehavior.never; + } + + @override + void didUpdateWidget(InputDecorator old) { + super.didUpdateWidget(old); + if (widget.decoration != old.decoration) { + _effectiveDecoration = null; + } + + final bool floatBehaviorChanged = widget.decoration.floatingLabelBehavior != old.decoration.floatingLabelBehavior; + + if (widget._labelShouldWithdraw != old._labelShouldWithdraw || floatBehaviorChanged) { + if (_floatingLabelEnabled + && (widget._labelShouldWithdraw || widget.decoration.floatingLabelBehavior == FloatingLabelBehavior.always)) { + _floatingLabelController.forward(); + } else { + _floatingLabelController.reverse(); + } + } + + final String? errorText = decoration.errorText; + final String? oldErrorText = old.decoration.errorText; + + if (_floatingLabelController.isCompleted && errorText != null && errorText != oldErrorText) { + _shakingLabelController + ..value = 0.0 + ..forward(); + } + } + + Color _getDefaultM2BorderColor(ThemeData themeData) { + if (!decoration.enabled && !isFocused) { + return ((decoration.filled ?? false) && !(decoration.border?.isOutline ?? false)) + ? Colors.transparent + : themeData.disabledColor; + } + if (_hasError) { + return themeData.colorScheme.error; + } + if (isFocused) { + return themeData.colorScheme.primary; + } + if (decoration.filled!) { + return themeData.hintColor; + } + final Color enabledColor = themeData.colorScheme.onSurface.withOpacity(0.38); + if (isHovering) { + final Color hoverColor = decoration.hoverColor ?? themeData.inputDecorationTheme.hoverColor ?? themeData.hoverColor; + return Color.alphaBlend(hoverColor.withOpacity(0.12), enabledColor); + } + return enabledColor; + } + + Color _getFillColor(ThemeData themeData, InputDecorationTheme defaults) { + if (decoration.filled != true) { // filled == null same as filled == false + return Colors.transparent; + } + if (decoration.fillColor != null) { + return MaterialStateProperty.resolveAs(decoration.fillColor!, materialState); + } + return MaterialStateProperty.resolveAs(defaults.fillColor!, materialState); + } + + Color _getHoverColor(ThemeData themeData) { + if (decoration.filled == null || !decoration.filled! || isFocused || !decoration.enabled) { + return Colors.transparent; + } + return decoration.hoverColor ?? themeData.inputDecorationTheme.hoverColor ?? themeData.hoverColor; + } + + Color _getIconColor(ThemeData themeData, InputDecorationTheme defaults) { + return MaterialStateProperty.resolveAs(decoration.iconColor, materialState) + ?? MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.iconColor, materialState) + ?? MaterialStateProperty.resolveAs(defaults.iconColor!, materialState); + } + + Color _getPrefixIconColor(ThemeData themeData, InputDecorationTheme defaults) { + return MaterialStateProperty.resolveAs(decoration.prefixIconColor, materialState) + ?? MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.prefixIconColor, materialState) + ?? MaterialStateProperty.resolveAs(defaults.prefixIconColor!, materialState); + } + + Color _getSuffixIconColor(ThemeData themeData, InputDecorationTheme defaults) { + return MaterialStateProperty.resolveAs(decoration.suffixIconColor, materialState) + ?? MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.suffixIconColor, materialState) + ?? MaterialStateProperty.resolveAs(defaults.suffixIconColor!, materialState); + } + + // True if the label will be shown and the hint will not. + // If we're not focused, there's no value, labelText was provided, and + // floatingLabelBehavior isn't set to always, then the label appears where the + // hint would. + bool get _hasInlineLabel { + return !widget._labelShouldWithdraw + && (decoration.labelText != null || decoration.label != null) + && decoration.floatingLabelBehavior != FloatingLabelBehavior.always; + } + + // If the label is a floating placeholder, it's always shown. + bool get _shouldShowLabel => _hasInlineLabel || _floatingLabelEnabled; + + // The base style for the inline label when they're displayed "inline", + // i.e. when they appear in place of the empty text field. + TextStyle _getInlineLabelStyle(ThemeData themeData, InputDecorationTheme defaults) { + final TextStyle defaultStyle = MaterialStateProperty.resolveAs(defaults.labelStyle!, materialState); + + final TextStyle? style = MaterialStateProperty.resolveAs(decoration.labelStyle, materialState) + ?? MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.labelStyle, materialState); + + return themeData.textTheme.titleMedium! + .merge(widget.baseStyle) + .merge(defaultStyle) + .merge(style) + .copyWith(height: 1); + } + + // The base style for the inline hint when they're displayed "inline", + // i.e. when they appear in place of the empty text field. + TextStyle _getInlineHintStyle(ThemeData themeData, InputDecorationTheme defaults) { + final TextStyle defaultStyle = MaterialStateProperty.resolveAs(defaults.hintStyle!, materialState); + + final TextStyle? style = MaterialStateProperty.resolveAs(decoration.hintStyle, materialState) + ?? MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.hintStyle, materialState); + + return themeData.textTheme.titleMedium! + .merge(widget.baseStyle) + .merge(defaultStyle) + .merge(style); + } + + TextStyle _getFloatingLabelStyle(ThemeData themeData, InputDecorationTheme defaults) { + TextStyle defaultTextStyle = MaterialStateProperty.resolveAs(defaults.floatingLabelStyle!, materialState); + if (_hasError && decoration.errorStyle?.color != null) { + defaultTextStyle = defaultTextStyle.copyWith(color: decoration.errorStyle?.color); + } + defaultTextStyle = defaultTextStyle.merge(decoration.floatingLabelStyle ?? decoration.labelStyle); + + final TextStyle? style = MaterialStateProperty.resolveAs(decoration.floatingLabelStyle, materialState) + ?? MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.floatingLabelStyle, materialState); + + return themeData.textTheme.titleMedium! + .merge(widget.baseStyle) + .copyWith(height: 1) + .merge(defaultTextStyle) + .merge(style); + } + + TextStyle _getHelperStyle(ThemeData themeData, InputDecorationTheme defaults) { + return MaterialStateProperty.resolveAs(defaults.helperStyle!, materialState) + .merge(MaterialStateProperty.resolveAs(decoration.helperStyle, materialState)); + } + + TextStyle _getErrorStyle(ThemeData themeData, InputDecorationTheme defaults) { + return MaterialStateProperty.resolveAs(defaults.errorStyle!, materialState) + .merge(decoration.errorStyle); + } + + Set<MaterialState> get materialState { + return <MaterialState>{ + if (!decoration.enabled) MaterialState.disabled, + if (isFocused) MaterialState.focused, + if (isHovering) MaterialState.hovered, + if (_hasError) MaterialState.error, + }; + } + + + InputBorder _getDefaultBorder(ThemeData themeData, InputDecorationTheme defaults) { + final InputBorder border = MaterialStateProperty.resolveAs(decoration.border, materialState) + ?? const UnderlineInputBorder(); + + if (decoration.border is MaterialStateProperty<InputBorder>) { + return border; + } + + if (border.borderSide == BorderSide.none) { + return border; + } + + if (themeData.useMaterial3) { + if (decoration.filled!) { + return border.copyWith( + borderSide: MaterialStateProperty.resolveAs(defaults.activeIndicatorBorder, materialState), + ); + } else { + return border.copyWith( + borderSide: MaterialStateProperty.resolveAs(defaults.outlineBorder, materialState), + ); + } + } + else{ + return border.copyWith( + borderSide: BorderSide( + color: _getDefaultM2BorderColor(themeData), + width: ( + (decoration.isCollapsed ?? themeData.inputDecorationTheme.isCollapsed) + || decoration.border == InputBorder.none + || !decoration.enabled) + ? 0.0 + : isFocused ? 2.0 : 1.0, + ), + ); + } + } + + @override + Widget build(BuildContext context) { + final ThemeData themeData = Theme.of(context); + final InputDecorationTheme defaults = + Theme.of(context).useMaterial3 ? _InputDecoratorDefaultsM3(context) : _InputDecoratorDefaultsM2(context); + + final TextStyle labelStyle = _getInlineLabelStyle(themeData, defaults); + final TextBaseline textBaseline = labelStyle.textBaseline!; + + final TextStyle hintStyle = _getInlineHintStyle(themeData, defaults); + final String? hintText = decoration.hintText; + final Widget? hint = hintText == null ? null : AnimatedOpacity( + opacity: (isEmpty && !_hasInlineLabel) ? 1.0 : 0.0, + duration: decoration.hintFadeDuration ?? _kHintFadeTransitionDuration, + curve: _kTransitionCurve, + child: Text( + hintText, + style: hintStyle, + textDirection: decoration.hintTextDirection, + overflow: hintStyle.overflow ?? TextOverflow.ellipsis, + textAlign: textAlign, + maxLines: decoration.hintMaxLines, + ), + ); + + InputBorder? border; + if (!decoration.enabled) { + border = _hasError ? decoration.errorBorder : decoration.disabledBorder; + } else if (isFocused) { + border = _hasError ? decoration.focusedErrorBorder : decoration.focusedBorder; + } else { + border = _hasError ? decoration.errorBorder : decoration.enabledBorder; + } + border ??= _getDefaultBorder(themeData, defaults); + + final Widget container = _BorderContainer( + border: border, + gap: _borderGap, + gapAnimation: _floatingLabelAnimation, + fillColor: _getFillColor(themeData, defaults), + hoverColor: _getHoverColor(themeData), + isHovering: isHovering, + ); + + final Widget? label = decoration.labelText == null && decoration.label == null ? null : _Shaker( + animation: _shakingLabelController.view, + child: AnimatedOpacity( + duration: _kTransitionDuration, + curve: _kTransitionCurve, + opacity: _shouldShowLabel ? 1.0 : 0.0, + child: AnimatedDefaultTextStyle( + duration:_kTransitionDuration, + curve: _kTransitionCurve, + style: widget._labelShouldWithdraw + ? _getFloatingLabelStyle(themeData, defaults) + : labelStyle, + child: decoration.label ?? Text( + decoration.labelText!, + overflow: TextOverflow.ellipsis, + textAlign: textAlign, + ), + ), + ), + ); + + final bool hasPrefix = decoration.prefix != null || decoration.prefixText != null; + final bool hasSuffix = decoration.suffix != null || decoration.suffixText != null; + + Widget? input = widget.child; + // If at least two out of the three are visible, it needs semantics sort + // order. + final bool needsSemanticsSortOrder = widget._labelShouldWithdraw && (input != null ? (hasPrefix || hasSuffix) : (hasPrefix && hasSuffix)); + + final Widget? prefix = hasPrefix + ? _AffixText( + labelIsFloating: widget._labelShouldWithdraw, + text: decoration.prefixText, + style: MaterialStateProperty.resolveAs(decoration.prefixStyle, materialState) ?? hintStyle, + semanticsSortKey: needsSemanticsSortOrder ? _kPrefixSemanticsSortOrder : null, + semanticsTag: _kPrefixSemanticsTag, + child: decoration.prefix, + ) + : null; + + final Widget? suffix = hasSuffix + ? _AffixText( + labelIsFloating: widget._labelShouldWithdraw, + text: decoration.suffixText, + style: MaterialStateProperty.resolveAs(decoration.suffixStyle, materialState) ?? hintStyle, + semanticsSortKey: needsSemanticsSortOrder ? _kSuffixSemanticsSortOrder : null, + semanticsTag: _kSuffixSemanticsTag, + child: decoration.suffix, + ) + : null; + + if (input != null && needsSemanticsSortOrder) { + input = Semantics( + sortKey: _kInputSemanticsSortOrder, + child: input, + ); + } + + final bool decorationIsDense = decoration.isDense ?? false; + final double iconSize = decorationIsDense ? 18.0 : 24.0; + + final Widget? icon = decoration.icon == null ? null : + MouseRegion( + cursor: SystemMouseCursors.basic, + child: Padding( + padding: const EdgeInsetsDirectional.only(end: 16.0), + child: IconTheme.merge( + data: IconThemeData( + color: _getIconColor(themeData, defaults), + size: iconSize, + ), + child: decoration.icon!, + ), + ), + ); + + final Widget? prefixIcon = decoration.prefixIcon == null ? null : + Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: MouseRegion( + cursor: SystemMouseCursors.basic, + child: ConstrainedBox( + constraints: decoration.prefixIconConstraints ?? + themeData.visualDensity.effectiveConstraints( + const BoxConstraints( + minWidth: kMinInteractiveDimension, + minHeight: kMinInteractiveDimension, + ), + ), + child: IconTheme.merge( + data: IconThemeData( + color: _getPrefixIconColor(themeData, defaults), + size: iconSize, + ), + child: IconButtonTheme( + data: IconButtonThemeData( + style: IconButton.styleFrom( + foregroundColor: _getPrefixIconColor(themeData, defaults), + iconSize: iconSize, + ), + ), + child: Semantics( + child: decoration.prefixIcon, + ), + ), + ), + ), + ), + ); + + final Widget? suffixIcon = decoration.suffixIcon == null ? null : + Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: MouseRegion( + cursor: SystemMouseCursors.basic, + child: ConstrainedBox( + constraints: decoration.suffixIconConstraints ?? + themeData.visualDensity.effectiveConstraints( + const BoxConstraints( + minWidth: kMinInteractiveDimension, + minHeight: kMinInteractiveDimension, + ), + ), + child: IconTheme.merge( + data: IconThemeData( + color: _getSuffixIconColor(themeData, defaults), + size: iconSize, + ), + child: IconButtonTheme( + data: IconButtonThemeData( + style: IconButton.styleFrom( + foregroundColor: _getSuffixIconColor(themeData, defaults), + iconSize: iconSize, + ), + ), + child: Semantics( + child: decoration.suffixIcon, + ), + ), + ), + ), + ), + ); + + final Widget helperError = _HelperError( + textAlign: textAlign, + helperText: decoration.helperText, + helperStyle: _getHelperStyle(themeData, defaults), + helperMaxLines: decoration.helperMaxLines, + error: decoration.error, + errorText: decoration.errorText, + errorStyle: _getErrorStyle(themeData, defaults), + errorMaxLines: decoration.errorMaxLines, + ); + + Widget? counter; + if (decoration.counter != null) { + counter = decoration.counter; + } else if (decoration.counterText != null && decoration.counterText != '') { + counter = Semantics( + container: true, + liveRegion: isFocused, + child: Text( + decoration.counterText!, + style: _getHelperStyle(themeData, defaults).merge(MaterialStateProperty.resolveAs(decoration.counterStyle, materialState)), + overflow: TextOverflow.ellipsis, + semanticsLabel: decoration.semanticCounterText, + ), + ); + } + + // The _Decoration widget and _RenderDecoration assume that contentPadding + // has been resolved to EdgeInsets. + final TextDirection textDirection = Directionality.of(context); + final EdgeInsets? decorationContentPadding = decoration.contentPadding?.resolve(textDirection); + + final EdgeInsets contentPadding; + final double floatingLabelHeight; + if (decoration.isCollapsed + ?? themeData.inputDecorationTheme.isCollapsed) { + floatingLabelHeight = 0.0; + contentPadding = decorationContentPadding ?? EdgeInsets.zero; + } else if (!border.isOutline) { + // 4.0: the vertical gap between the inline elements and the floating label. + floatingLabelHeight = (4.0 + 0.75 * labelStyle.fontSize!) * MediaQuery.textScalerOf(context).textScaleFactor; + if (decoration.filled ?? false) { + contentPadding = decorationContentPadding ?? (decorationIsDense + ? const EdgeInsets.fromLTRB(12.0, 8.0, 12.0, 8.0) + : const EdgeInsets.fromLTRB(12.0, 12.0, 12.0, 12.0)); + } else { + // Not left or right padding for underline borders that aren't filled + // is a small concession to backwards compatibility. This eliminates + // the most noticeable layout change introduced by #13734. + contentPadding = decorationContentPadding ?? (decorationIsDense + ? const EdgeInsets.fromLTRB(0.0, 8.0, 0.0, 8.0) + : const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 12.0)); + } + } else { + floatingLabelHeight = 0.0; + contentPadding = decorationContentPadding ?? (decorationIsDense + ? const EdgeInsets.fromLTRB(12.0, 20.0, 12.0, 12.0) + : const EdgeInsets.fromLTRB(12.0, 24.0, 12.0, 16.0)); + } + + final _Decorator decorator = _Decorator( + decoration: _Decoration( + contentPadding: contentPadding, + isCollapsed: decoration.isCollapsed ?? themeData.inputDecorationTheme.isCollapsed, + floatingLabelHeight: floatingLabelHeight, + floatingLabelAlignment: decoration.floatingLabelAlignment!, + floatingLabelProgress: _floatingLabelAnimation.value, + border: border, + borderGap: _borderGap, + alignLabelWithHint: decoration.alignLabelWithHint ?? false, + isDense: decoration.isDense, + visualDensity: themeData.visualDensity, + icon: icon, + input: input, + label: label, + hint: hint, + prefix: prefix, + suffix: suffix, + prefixIcon: prefixIcon, + suffixIcon: suffixIcon, + helperError: helperError, + counter: counter, + container: container + ), + textDirection: textDirection, + textBaseline: textBaseline, + textAlignVertical: widget.textAlignVertical, + isFocused: isFocused, + expands: widget.expands, + ); + + final BoxConstraints? constraints = decoration.constraints ?? themeData.inputDecorationTheme.constraints; + if (constraints != null) { + return ConstrainedBox( + constraints: constraints, + child: decorator, + ); + } + return decorator; + } +} + +/// The border, labels, icons, and styles used to decorate a Material +/// Design text field. +/// +/// The [TextField] and [InputDecorator] classes use [InputDecoration] objects +/// to describe their decoration. (In fact, this class is merely the +/// configuration of an [InputDecorator], which does all the heavy lifting.) +/// +/// {@tool dartpad} +/// This sample shows how to style a `TextField` using an `InputDecorator`. The +/// TextField displays a "send message" icon to the left of the input area, +/// which is surrounded by a border an all sides. It displays the `hintText` +/// inside the input area to help the user understand what input is required. It +/// displays the `helperText` and `counterText` below the input area. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration.png) +/// +/// ** See code in examples/api/lib/material/input_decorator/input_decoration.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows how to style a "collapsed" `TextField` using an +/// `InputDecorator`. The collapsed `TextField` surrounds the hint text and +/// input area with a border, but does not add padding around them. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration_collapsed.png) +/// +/// ** See code in examples/api/lib/material/input_decorator/input_decoration.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows how to create a `TextField` with hint text, a red border +/// on all sides, and an error message. To display a red border and error +/// message, provide `errorText` to the [InputDecoration] constructor. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration_error.png) +/// +/// ** See code in examples/api/lib/material/input_decorator/input_decoration.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows how to style a `TextField` with a round border and +/// additional text before and after the input area. It displays "Prefix" before +/// the input area, and "Suffix" after the input area. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration_prefix_suffix.png) +/// +/// ** See code in examples/api/lib/material/input_decorator/input_decoration.3.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows how to style a `TextField` with a prefixIcon that changes color +/// based on the `MaterialState`. The color defaults to gray, be blue while focused +/// and red if in an error state. +/// +/// ** See code in examples/api/lib/material/input_decorator/input_decoration.material_state.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows how to style a `TextField` with a prefixIcon that changes color +/// based on the `MaterialState` through the use of `ThemeData`. The color defaults +/// to gray, be blue while focused and red if in an error state. +/// +/// ** See code in examples/api/lib/material/input_decorator/input_decoration.material_state.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [TextField], which is a text input widget that uses an +/// [InputDecoration]. +/// * [InputDecorator], which is a widget that draws an [InputDecoration] +/// around an input child widget. +/// * [Decoration] and [DecoratedBox], for drawing borders and backgrounds +/// around a child widget. +@immutable +class InputDecoration { + /// Creates a bundle of the border, labels, icons, and styles used to + /// decorate a Material Design text field. + /// + /// Unless specified by [ThemeData.inputDecorationTheme], [InputDecorator] + /// defaults [isDense] to false and [filled] to false. The default border is + /// an instance of [UnderlineInputBorder]. If [border] is [InputBorder.none] + /// then no border is drawn. + /// + /// Only one of [prefix] and [prefixText] can be specified. + /// + /// Similarly, only one of [suffix] and [suffixText] can be specified. + const InputDecoration({ + this.icon, + this.iconColor, + this.label, + this.labelText, + this.labelStyle, + this.floatingLabelStyle, + this.helperText, + this.helperStyle, + this.helperMaxLines, + this.hintText, + this.hintStyle, + this.hintTextDirection, + this.hintMaxLines, + this.hintFadeDuration, + this.error, + this.errorText, + this.errorStyle, + this.errorMaxLines, + this.floatingLabelBehavior, + this.floatingLabelAlignment, + this.isCollapsed, + this.isDense, + this.contentPadding, + this.prefixIcon, + this.prefixIconConstraints, + this.prefix, + this.prefixText, + this.prefixStyle, + this.prefixIconColor, + this.suffixIcon, + this.suffix, + this.suffixText, + this.suffixStyle, + this.suffixIconColor, + this.suffixIconConstraints, + this.counter, + this.counterText, + this.counterStyle, + this.filled, + this.fillColor, + this.focusColor, + this.hoverColor, + this.errorBorder, + this.focusedBorder, + this.focusedErrorBorder, + this.disabledBorder, + this.enabledBorder, + this.border, + this.enabled = true, + this.semanticCounterText, + this.alignLabelWithHint, + this.constraints, + }) : assert(!(label != null && labelText != null), 'Declaring both label and labelText is not supported.'), + assert(!(prefix != null && prefixText != null), 'Declaring both prefix and prefixText is not supported.'), + assert(!(suffix != null && suffixText != null), 'Declaring both suffix and suffixText is not supported.'), + assert(!(error != null && errorText != null), 'Declaring both error and errorText is not supported.'); + + /// Defines an [InputDecorator] that is the same size as the input field. + /// + /// This type of input decoration does not include a border by default. + /// + /// Sets the [isCollapsed] property to true. + const InputDecoration.collapsed({ + required this.hintText, + this.floatingLabelBehavior, + this.floatingLabelAlignment, + this.hintStyle, + this.hintTextDirection, + this.filled = false, + this.fillColor, + this.focusColor, + this.hoverColor, + this.border = InputBorder.none, + this.enabled = true, + }) : icon = null, + iconColor = null, + label = null, + labelText = null, + labelStyle = null, + floatingLabelStyle = null, + helperText = null, + helperStyle = null, + helperMaxLines = null, + hintMaxLines = null, + hintFadeDuration = null, + error = null, + errorText = null, + errorStyle = null, + errorMaxLines = null, + isDense = false, + contentPadding = EdgeInsets.zero, + isCollapsed = true, + prefixIcon = null, + prefix = null, + prefixText = null, + prefixStyle = null, + prefixIconColor = null, + prefixIconConstraints = null, + suffix = null, + suffixIcon = null, + suffixText = null, + suffixStyle = null, + suffixIconColor = null, + suffixIconConstraints = null, + counter = null, + counterText = null, + counterStyle = null, + errorBorder = null, + focusedBorder = null, + focusedErrorBorder = null, + disabledBorder = null, + enabledBorder = null, + semanticCounterText = null, + alignLabelWithHint = false, + constraints = null; + + /// An icon to show before the input field and outside of the decoration's + /// container. + /// + /// The size and color of the icon is configured automatically using an + /// [IconTheme] and therefore does not need to be explicitly given in the + /// icon widget. + /// + /// The trailing edge of the icon is padded by 16dps. + /// + /// The decoration's container is the area which is filled if [filled] is + /// true and bordered per the [border]. It's the area adjacent to + /// [icon] and above the widgets that contain [helperText], + /// [errorText], and [counterText]. + /// + /// See [Icon], [ImageIcon]. + final Widget? icon; + + /// The color of the [icon]. + /// + /// If [iconColor] is a [MaterialStateColor], then the effective + /// color can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + final Color? iconColor; + + /// Optional widget that describes the input field. + /// + /// {@template flutter.material.inputDecoration.label} + /// When the input field is empty and unfocused, the label is displayed on + /// top of the input field (i.e., at the same location on the screen where + /// text may be entered in the input field). When the input field receives + /// focus (or if the field is non-empty), depending on [floatingLabelAlignment], + /// the label moves above, either vertically adjacent to, or to the center of + /// the input field. + /// {@endtemplate} + /// + /// This can be used, for example, to add multiple [TextStyle]'s to a label that would + /// otherwise be specified using [labelText], which only takes one [TextStyle]. + /// + /// {@tool dartpad} + /// This example shows a `TextField` with a [Text.rich] widget as the [label]. + /// The widget contains multiple [Text] widgets with different [TextStyle]'s. + /// + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.label.0.dart ** + /// {@end-tool} + /// + /// Only one of [label] and [labelText] can be specified. + final Widget? label; + + /// Optional text that describes the input field. + /// + /// {@macro flutter.material.inputDecoration.label} + /// + /// If a more elaborate label is required, consider using [label] instead. + /// Only one of [label] and [labelText] can be specified. + final String? labelText; + + /// {@template flutter.material.inputDecoration.labelStyle} + /// The style to use for [InputDecoration.labelText] when the label is on top + /// of the input field. + /// + /// If [labelStyle] is a [MaterialStateTextStyle], then the effective + /// text style can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// When the [InputDecoration.labelText] is above (i.e., vertically adjacent to) + /// the input field, the text uses the [floatingLabelStyle] instead. + /// + /// If null, defaults to a value derived from the base [TextStyle] for the + /// input field and the current [Theme]. + /// + /// Specifying this style will override the default behavior + /// of [InputDecoration] that changes the color of the label to the + /// [InputDecoration.errorStyle] color or [ColorScheme.error]. + /// + /// {@tool dartpad} + /// It's possible to override the label style for just the error state, or + /// just the default state, or both. + /// + /// In this example the [labelStyle] is specified with a [MaterialStateProperty] + /// which resolves to a text style whose color depends on the decorator's + /// error state. + /// + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.label_style_error.0.dart ** + /// {@end-tool} + /// {@endtemplate} + final TextStyle? labelStyle; + + /// {@template flutter.material.inputDecoration.floatingLabelStyle} + /// The style to use for [InputDecoration.labelText] when the label is + /// above (i.e., vertically adjacent to) the input field. + /// + /// When the [InputDecoration.labelText] is on top of the input field, the + /// text uses the [labelStyle] instead. + /// + /// If [floatingLabelStyle] is a [MaterialStateTextStyle], then the effective + /// text style can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// If null, defaults to [labelStyle]. + /// + /// Specifying this style will override the default behavior + /// of [InputDecoration] that changes the color of the label to the + /// [InputDecoration.errorStyle] color or [ColorScheme.error]. + /// + /// {@tool dartpad} + /// It's possible to override the label style for just the error state, or + /// just the default state, or both. + /// + /// In this example the [floatingLabelStyle] is specified with a + /// [MaterialStateProperty] which resolves to a text style whose color depends + /// on the decorator's error state. + /// + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.floating_label_style_error.0.dart ** + /// {@end-tool} + /// {@endtemplate} + final TextStyle? floatingLabelStyle; + + /// Text that provides context about the [InputDecorator.child]'s value, such + /// as how the value will be used. + /// + /// If non-null, the text is displayed below the [InputDecorator.child], in + /// the same location as [errorText]. If a non-null [errorText] value is + /// specified then the helper text is not shown. + final String? helperText; + + /// The style to use for the [helperText]. + /// + /// If [helperStyle] is a [MaterialStateTextStyle], then the effective + /// text style can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + final TextStyle? helperStyle; + + /// The maximum number of lines the [helperText] can occupy. + /// + /// Defaults to null, which means that the [helperText] will be limited + /// to a single line with [TextOverflow.ellipsis]. + /// + /// This value is passed along to the [Text.maxLines] attribute + /// of the [Text] widget used to display the helper. + /// + /// See also: + /// + /// * [errorMaxLines], the equivalent but for the [errorText]. + final int? helperMaxLines; + + /// Text that suggests what sort of input the field accepts. + /// + /// Displayed on top of the [InputDecorator.child] (i.e., at the same location + /// on the screen where text may be entered in the [InputDecorator.child]) + /// when the input [isEmpty] and either (a) [labelText] is null or (b) the + /// input has the focus. + final String? hintText; + + /// The style to use for the [hintText]. + /// + /// If [hintStyle] is a [MaterialStateTextStyle], then the effective + /// text style can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// Also used for the [labelText] when the [labelText] is displayed on + /// top of the input field (i.e., at the same location on the screen where + /// text may be entered in the [InputDecorator.child]). + /// + /// If null, defaults to a value derived from the base [TextStyle] for the + /// input field and the current [Theme]. + final TextStyle? hintStyle; + + /// The direction to use for the [hintText]. + /// + /// If null, defaults to a value derived from [Directionality] for the + /// input field and the current context. + final TextDirection? hintTextDirection; + + /// The maximum number of lines the [hintText] can occupy. + /// + /// Defaults to the value of [TextField.maxLines] attribute. + /// + /// This value is passed along to the [Text.maxLines] attribute + /// of the [Text] widget used to display the hint text. [TextOverflow.ellipsis] is + /// used to handle the overflow when it is limited to single line. + final int? hintMaxLines; + + /// The duration of the [hintText] fade in and fade out animations. + /// + /// If null, defaults to [InputDecorationTheme.hintFadeDuration]. + /// If [InputDecorationTheme.hintFadeDuration] is null defaults to 20ms. + final Duration? hintFadeDuration; + + /// Optional widget that appears below the [InputDecorator.child] and the border. + /// + /// If non-null, the border's color animates to red and the [helperText] is not shown. + /// + /// Only one of [error] and [errorText] can be specified. + final Widget? error; + + /// Text that appears below the [InputDecorator.child] and the border. + /// + /// If non-null, the border's color animates to red and the [helperText] is + /// not shown. + /// + /// In a [TextFormField], this is overridden by the value returned from + /// [TextFormField.validator], if that is not null. + /// + /// If a more elaborate error is required, consider using [error] instead. + /// + /// Only one of [error] and [errorText] can be specified. + final String? errorText; + + /// {@template flutter.material.inputDecoration.errorStyle} + /// The style to use for the [InputDecoration.errorText]. + /// + /// If null, defaults of a value derived from the base [TextStyle] for the + /// input field and the current [Theme]. + /// + /// By default the color of style will be used by the label of + /// [InputDecoration] if [InputDecoration.errorText] is not null. See + /// [InputDecoration.labelStyle] or [InputDecoration.floatingLabelStyle] for + /// an example of how to replicate this behavior when specifying those + /// styles. + /// {@endtemplate} + final TextStyle? errorStyle; + + /// The maximum number of lines the [errorText] can occupy. + /// + /// Defaults to null, which means that the [errorText] will be limited + /// to a single line with [TextOverflow.ellipsis]. + /// + /// This value is passed along to the [Text.maxLines] attribute + /// of the [Text] widget used to display the error. + /// + /// See also: + /// + /// * [helperMaxLines], the equivalent but for the [helperText]. + final int? errorMaxLines; + + /// {@template flutter.material.inputDecoration.floatingLabelBehavior} + /// Defines **how** the floating label should behave. + /// + /// When [FloatingLabelBehavior.auto] the label will float to the top only when + /// the field is focused or has some text content, otherwise it will appear + /// in the field in place of the content. + /// + /// When [FloatingLabelBehavior.always] the label will always float at the top + /// of the field above the content. + /// + /// When [FloatingLabelBehavior.never] the label will always appear in an empty + /// field in place of the content. + /// {@endtemplate} + /// + /// If null, [InputDecorationTheme.floatingLabelBehavior] will be used. + /// + /// See also: + /// + /// * [floatingLabelAlignment] which defines **where** the floating label + /// should be displayed. + final FloatingLabelBehavior? floatingLabelBehavior; + + /// {@template flutter.material.inputDecoration.floatingLabelAlignment} + /// Defines **where** the floating label should be displayed. + /// + /// [FloatingLabelAlignment.start] aligns the floating label to the leftmost + /// (when [TextDirection.ltr]) or rightmost (when [TextDirection.rtl]), + /// possible position, which is vertically adjacent to the label, on top of + /// the field. + /// + /// [FloatingLabelAlignment.center] aligns the floating label to the center on + /// top of the field. + /// {@endtemplate} + /// + /// If null, [InputDecorationTheme.floatingLabelAlignment] will be used. + /// + /// See also: + /// + /// * [floatingLabelBehavior] which defines **how** the floating label should + /// behave. + final FloatingLabelAlignment? floatingLabelAlignment; + + /// Whether the [InputDecorator.child] is part of a dense form (i.e., uses less vertical + /// space). + /// + /// Defaults to false. + final bool? isDense; + + /// The padding for the input decoration's container. + /// + /// {@macro flutter.material.input_decorator.container_description} + /// + /// By default the [contentPadding] reflects [isDense] and the type of the + /// [border]. + /// + /// If [isCollapsed] is true then [contentPadding] is [EdgeInsets.zero]. + /// + /// If `isOutline` property of [border] is false and if [filled] is true then + /// [contentPadding] is `EdgeInsets.fromLTRB(12, 8, 12, 8)` when [isDense] + /// is true and `EdgeInsets.fromLTRB(12, 12, 12, 12)` when [isDense] is false. + /// If `isOutline` property of [border] is false and if [filled] is false then + /// [contentPadding] is `EdgeInsets.fromLTRB(0, 8, 0, 8)` when [isDense] is + /// true and `EdgeInsets.fromLTRB(0, 12, 0, 12)` when [isDense] is false. + /// + /// If `isOutline` property of [border] is true then [contentPadding] is + /// `EdgeInsets.fromLTRB(12, 20, 12, 12)` when [isDense] is true + /// and `EdgeInsets.fromLTRB(12, 24, 12, 16)` when [isDense] is false. + final EdgeInsetsGeometry? contentPadding; + + /// Whether the decoration is the same size as the input field. + /// + /// A collapsed decoration cannot have [labelText], [errorText], an [icon]. + /// + /// To create a collapsed input decoration, use [InputDecoration.collapsed]. + final bool? isCollapsed; + + /// An icon that appears before the [prefix] or [prefixText] and before + /// the editable part of the text field, within the decoration's container. + /// + /// The size and color of the prefix icon is configured automatically using an + /// [IconTheme] and therefore does not need to be explicitly given in the + /// icon widget. + /// + /// The prefix icon is constrained with a minimum size of 48px by 48px, but + /// can be expanded beyond that. Anything larger than 24px will require + /// additional padding to ensure it matches the Material Design spec of 12px + /// padding between the left edge of the input and leading edge of the prefix + /// icon. The following snippet shows how to pad the leading edge of the + /// prefix icon: + /// + /// ```dart + /// prefixIcon: Padding( + /// padding: const EdgeInsetsDirectional.only(start: 12.0), + /// child: _myIcon, // _myIcon is a 48px-wide widget. + /// ) + /// ``` + /// + /// {@macro flutter.material.input_decorator.container_description} + /// + /// The prefix icon alignment can be changed using [Align] with a fixed `widthFactor` and + /// `heightFactor`. + /// + /// {@tool dartpad} + /// This example shows how the prefix icon alignment can be changed using [Align] with + /// a fixed `widthFactor` and `heightFactor`. + /// + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.prefix_icon.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [Icon] and [ImageIcon], which are typically used to show icons. + /// * [prefix] and [prefixText], which are other ways to show content + /// before the text field (but after the icon). + /// * [suffixIcon], which is the same but on the trailing edge. + /// * [Align] A widget that aligns its child within itself and optionally + /// sizes itself based on the child's size. + final Widget? prefixIcon; + + /// The constraints for the prefix icon. + /// + /// This can be used to modify the [BoxConstraints] surrounding [prefixIcon]. + /// + /// This property is particularly useful for getting the decoration's height + /// less than 48px. This can be achieved by setting [isDense] to true and + /// setting the constraints' minimum height and width to a value lower than + /// 48px. + /// + /// {@tool dartpad} + /// This example shows the differences between two `TextField` widgets when + /// [prefixIconConstraints] is set to the default value and when one is not. + /// + /// The [isDense] property must be set to true to be able to + /// set the constraints smaller than 48px. + /// + /// If null, [BoxConstraints] with a minimum width and height of 48px is + /// used. + /// + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.prefix_icon_constraints.0.dart ** + /// {@end-tool} + final BoxConstraints? prefixIconConstraints; + + /// Optional widget to place on the line before the input. + /// + /// This can be used, for example, to add some padding to text that would + /// otherwise be specified using [prefixText], or to add a custom widget in + /// front of the input. The widget's baseline is lined up with the input + /// baseline. + /// + /// Only one of [prefix] and [prefixText] can be specified. + /// + /// The [prefix] appears after the [prefixIcon], if both are specified. + /// + /// See also: + /// + /// * [suffix], the equivalent but on the trailing edge. + final Widget? prefix; + + /// Optional text prefix to place on the line before the input. + /// + /// Uses the [prefixStyle]. Uses [hintStyle] if [prefixStyle] isn't specified. + /// The prefix text is not returned as part of the user's input. + /// + /// If a more elaborate prefix is required, consider using [prefix] instead. + /// Only one of [prefix] and [prefixText] can be specified. + /// + /// The [prefixText] appears after the [prefixIcon], if both are specified. + /// + /// See also: + /// + /// * [suffixText], the equivalent but on the trailing edge. + final String? prefixText; + + /// The style to use for the [prefixText]. + /// + /// If [prefixStyle] is a [MaterialStateTextStyle], then the effective + /// text style can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// If null, defaults to the [hintStyle]. + /// + /// See also: + /// + /// * [suffixStyle], the equivalent but on the trailing edge. + final TextStyle? prefixStyle; + + /// Optional color of the prefixIcon + /// + /// Defaults to [iconColor] + /// + /// If [prefixIconColor] is a [MaterialStateColor], then the effective + /// color can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + final Color? prefixIconColor; + + /// An icon that appears after the editable part of the text field and + /// after the [suffix] or [suffixText], within the decoration's container. + /// + /// The size and color of the suffix icon is configured automatically using an + /// [IconTheme] and therefore does not need to be explicitly given in the + /// icon widget. + /// + /// The suffix icon is constrained with a minimum size of 48px by 48px, but + /// can be expanded beyond that. Anything larger than 24px will require + /// additional padding to ensure it matches the Material Design spec of 12px + /// padding between the right edge of the input and trailing edge of the + /// prefix icon. The following snippet shows how to pad the trailing edge of + /// the suffix icon: + /// + /// ```dart + /// suffixIcon: Padding( + /// padding: const EdgeInsetsDirectional.only(end: 12.0), + /// child: _myIcon, // myIcon is a 48px-wide widget. + /// ) + /// ``` + /// + /// The decoration's container is the area which is filled if [filled] is + /// true and bordered per the [border]. It's the area adjacent to + /// [icon] and above the widgets that contain [helperText], + /// [errorText], and [counterText]. + /// + /// The suffix icon alignment can be changed using [Align] with a fixed `widthFactor` and + /// `heightFactor`. + /// + /// {@tool dartpad} + /// This example shows how the suffix icon alignment can be changed using [Align] with + /// a fixed `widthFactor` and `heightFactor`. + /// + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.suffix_icon.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [Icon] and [ImageIcon], which are typically used to show icons. + /// * [suffix] and [suffixText], which are other ways to show content + /// after the text field (but before the icon). + /// * [prefixIcon], which is the same but on the leading edge. + /// * [Align] A widget that aligns its child within itself and optionally + /// sizes itself based on the child's size. + final Widget? suffixIcon; + + /// Optional widget to place on the line after the input. + /// + /// This can be used, for example, to add some padding to the text that would + /// otherwise be specified using [suffixText], or to add a custom widget after + /// the input. The widget's baseline is lined up with the input baseline. + /// + /// Only one of [suffix] and [suffixText] can be specified. + /// + /// The [suffix] appears before the [suffixIcon], if both are specified. + /// + /// See also: + /// + /// * [prefix], the equivalent but on the leading edge. + final Widget? suffix; + + /// Optional text suffix to place on the line after the input. + /// + /// Uses the [suffixStyle]. Uses [hintStyle] if [suffixStyle] isn't specified. + /// The suffix text is not returned as part of the user's input. + /// + /// If a more elaborate suffix is required, consider using [suffix] instead. + /// Only one of [suffix] and [suffixText] can be specified. + /// + /// The [suffixText] appears before the [suffixIcon], if both are specified. + /// + /// See also: + /// + /// * [prefixText], the equivalent but on the leading edge. + final String? suffixText; + + /// The style to use for the [suffixText]. + /// + /// If [suffixStyle] is a [MaterialStateTextStyle], then the effective text + /// style can depend on the [MaterialState.focused] state, i.e. if the + /// [TextField] is focused or not. + /// + /// If null, defaults to the [hintStyle]. + /// + /// See also: + /// + /// * [prefixStyle], the equivalent but on the leading edge. + final TextStyle? suffixStyle; + + /// Optional color of the [suffixIcon]. + /// + /// Defaults to [iconColor] + /// + /// If [suffixIconColor] is a [MaterialStateColor], then the effective + /// color can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + final Color? suffixIconColor; + + /// The constraints for the suffix icon. + /// + /// This can be used to modify the [BoxConstraints] surrounding [suffixIcon]. + /// + /// This property is particularly useful for getting the decoration's height + /// less than 48px. This can be achieved by setting [isDense] to true and + /// setting the constraints' minimum height and width to a value lower than + /// 48px. + /// + /// If null, a [BoxConstraints] with a minimum width and height of 48px is + /// used. + /// + /// {@tool dartpad} + /// This example shows the differences between two `TextField` widgets when + /// [suffixIconConstraints] is set to the default value and when one is not. + /// + /// The [isDense] property must be set to true to be able to + /// set the constraints smaller than 48px. + /// + /// If null, [BoxConstraints] with a minimum width and height of 48px is + /// used. + /// + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.suffix_icon_constraints.0.dart ** + /// {@end-tool} + final BoxConstraints? suffixIconConstraints; + + /// Optional text to place below the line as a character count. + /// + /// Rendered using [counterStyle]. Uses [helperStyle] if [counterStyle] is + /// null. + /// + /// The semantic label can be replaced by providing a [semanticCounterText]. + /// + /// If null or an empty string and [counter] isn't specified, then nothing + /// will appear in the counter's location. + final String? counterText; + + /// Optional custom counter widget to go in the place otherwise occupied by + /// [counterText]. If this property is non null, then [counterText] is + /// ignored. + final Widget? counter; + + /// The style to use for the [counterText]. + /// + /// If [counterStyle] is a [MaterialStateTextStyle], then the effective + /// text style can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// If null, defaults to the [helperStyle]. + final TextStyle? counterStyle; + + /// If true the decoration's container is filled with [fillColor]. + /// + /// When [InputDecorator.isHovering] is true, the [hoverColor] is also blended + /// into the final fill color. + /// + /// Typically this field set to true if [border] is an [UnderlineInputBorder]. + /// + /// {@template flutter.material.input_decorator.container_description} + /// The decoration's container is the area which is filled if [filled] is true + /// and bordered per the [border]. It's the area adjacent to [icon] and above + /// the widgets that contain [helperText], [errorText], and [counterText]. + /// {@endtemplate} + /// + /// This property is false by default. + final bool? filled; + + /// The base fill color of the decoration's container color. + /// + /// When [InputDecorator.isHovering] is true, the [hoverColor] is also blended + /// into the final fill color. + /// + /// By default the [fillColor] is based on the current + /// [InputDecorationTheme.fillColor]. + /// + /// {@macro flutter.material.input_decorator.container_description} + final Color? fillColor; + + /// The fill color of the decoration's container when it has the input focus. + /// + /// By default the [focusColor] is based on the current + /// [InputDecorationTheme.focusColor]. + /// + /// This [focusColor] is ignored by [TextField] and [TextFormField] because + /// they don't respond to focus changes by changing their decorator's + /// container color, they respond by changing their border to the + /// [focusedBorder], which you can change the color of. + /// + /// {@macro flutter.material.input_decorator.container_description} + final Color? focusColor; + + /// The color of the highlight for the decoration shown if the container + /// is being hovered over by a mouse. + /// + /// If [filled] is true, the [hoverColor] is blended with [fillColor] and + /// fills the decoration's container. + /// + /// If [filled] is false, and [InputDecorator.isFocused] is false, the color + /// is blended over the [enabledBorder]'s color. + /// + /// By default the [hoverColor] is based on the current [Theme]. + /// + /// {@macro flutter.material.input_decorator.container_description} + final Color? hoverColor; + + /// The border to display when the [InputDecorator] does not have the focus and + /// is showing an error. + /// + /// See also: + /// + /// * [InputDecorator.isFocused], which is true if the [InputDecorator]'s child + /// has the focus. + /// * [InputDecoration.errorText], the error shown by the [InputDecorator], if non-null. + /// * [border], for a description of where the [InputDecorator] border appears. + /// * [UnderlineInputBorder], an [InputDecorator] border which draws a horizontal + /// line at the bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + /// * [InputBorder.none], which doesn't draw a border. + /// * [focusedBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is null. + /// * [focusedErrorBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is non-null. + /// * [disabledBorder], displayed when [InputDecoration.enabled] is false + /// and [InputDecoration.errorText] is null. + /// * [enabledBorder], displayed when [InputDecoration.enabled] is true + /// and [InputDecoration.errorText] is null. + final InputBorder? errorBorder; + + /// The border to display when the [InputDecorator] has the focus and is not + /// showing an error. + /// + /// See also: + /// + /// * [InputDecorator.isFocused], which is true if the [InputDecorator]'s child + /// has the focus. + /// * [InputDecoration.errorText], the error shown by the [InputDecorator], if non-null. + /// * [border], for a description of where the [InputDecorator] border appears. + /// * [UnderlineInputBorder], an [InputDecorator] border which draws a horizontal + /// line at the bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + /// * [InputBorder.none], which doesn't draw a border. + /// * [errorBorder], displayed when [InputDecorator.isFocused] is false + /// and [InputDecoration.errorText] is non-null. + /// * [focusedErrorBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is non-null. + /// * [disabledBorder], displayed when [InputDecoration.enabled] is false + /// and [InputDecoration.errorText] is null. + /// * [enabledBorder], displayed when [InputDecoration.enabled] is true + /// and [InputDecoration.errorText] is null. + final InputBorder? focusedBorder; + + /// The border to display when the [InputDecorator] has the focus and is + /// showing an error. + /// + /// See also: + /// + /// * [InputDecorator.isFocused], which is true if the [InputDecorator]'s child + /// has the focus. + /// * [InputDecoration.errorText], the error shown by the [InputDecorator], if non-null. + /// * [border], for a description of where the [InputDecorator] border appears. + /// * [UnderlineInputBorder], an [InputDecorator] border which draws a horizontal + /// line at the bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + /// * [InputBorder.none], which doesn't draw a border. + /// * [errorBorder], displayed when [InputDecorator.isFocused] is false + /// and [InputDecoration.errorText] is non-null. + /// * [focusedBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is null. + /// * [disabledBorder], displayed when [InputDecoration.enabled] is false + /// and [InputDecoration.errorText] is null. + /// * [enabledBorder], displayed when [InputDecoration.enabled] is true + /// and [InputDecoration.errorText] is null. + final InputBorder? focusedErrorBorder; + + /// The border to display when the [InputDecorator] is disabled and is not + /// showing an error. + /// + /// See also: + /// + /// * [InputDecoration.enabled], which is false if the [InputDecorator] is disabled. + /// * [InputDecoration.errorText], the error shown by the [InputDecorator], if non-null. + /// * [border], for a description of where the [InputDecorator] border appears. + /// * [UnderlineInputBorder], an [InputDecorator] border which draws a horizontal + /// line at the bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + /// * [InputBorder.none], which doesn't draw a border. + /// * [errorBorder], displayed when [InputDecorator.isFocused] is false + /// and [InputDecoration.errorText] is non-null. + /// * [focusedBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is null. + /// * [focusedErrorBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is non-null. + /// * [enabledBorder], displayed when [InputDecoration.enabled] is true + /// and [InputDecoration.errorText] is null. + final InputBorder? disabledBorder; + + /// The border to display when the [InputDecorator] is enabled and is not + /// showing an error. + /// + /// See also: + /// + /// * [InputDecoration.enabled], which is false if the [InputDecorator] is disabled. + /// * [InputDecoration.errorText], the error shown by the [InputDecorator], if non-null. + /// * [border], for a description of where the [InputDecorator] border appears. + /// * [UnderlineInputBorder], an [InputDecorator] border which draws a horizontal + /// line at the bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + /// * [InputBorder.none], which doesn't draw a border. + /// * [errorBorder], displayed when [InputDecorator.isFocused] is false + /// and [InputDecoration.errorText] is non-null. + /// * [focusedBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is null. + /// * [focusedErrorBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is non-null. + /// * [disabledBorder], displayed when [InputDecoration.enabled] is false + /// and [InputDecoration.errorText] is null. + final InputBorder? enabledBorder; + + /// The shape of the border to draw around the decoration's container. + /// + /// If [border] is a [MaterialStateUnderlineInputBorder] + /// or [MaterialStateOutlineInputBorder], then the effective border can depend on + /// the [MaterialState.focused] state, i.e. if the [TextField] is focused or not. + /// + /// If [border] derives from [InputBorder] the border's [InputBorder.borderSide], + /// i.e. the border's color and width, will be overridden to reflect the input + /// decorator's state. Only the border's shape is used. If custom [BorderSide] + /// values are desired for a given state, all four borders – [errorBorder], + /// [focusedBorder], [enabledBorder], [disabledBorder] – must be set. + /// + /// The decoration's container is the area which is filled if [filled] is + /// true and bordered per the [border]. It's the area adjacent to + /// [InputDecoration.icon] and above the widgets that contain + /// [InputDecoration.helperText], [InputDecoration.errorText], and + /// [InputDecoration.counterText]. + /// + /// The border's bounds, i.e. the value of `border.getOuterPath()`, define + /// the area to be filled. + /// + /// This property is only used when the appropriate one of [errorBorder], + /// [focusedBorder], [focusedErrorBorder], [disabledBorder], or [enabledBorder] + /// is not specified. This border's [InputBorder.borderSide] property is + /// configured by the InputDecorator, depending on the values of + /// [InputDecoration.errorText], [InputDecoration.enabled], + /// [InputDecorator.isFocused] and the current [Theme]. + /// + /// Typically one of [UnderlineInputBorder] or [OutlineInputBorder]. + /// If null, InputDecorator's default is `const UnderlineInputBorder()`. + /// + /// See also: + /// + /// * [InputBorder.none], which doesn't draw a border. + /// * [UnderlineInputBorder], which draws a horizontal line at the + /// bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + final InputBorder? border; + + /// If false [helperText],[errorText], and [counterText] are not displayed, + /// and the opacity of the remaining visual elements is reduced. + /// + /// This property is true by default. + final bool enabled; + + /// A semantic label for the [counterText]. + /// + /// Defaults to null. + /// + /// If provided, this replaces the semantic label of the [counterText]. + final String? semanticCounterText; + + /// Typically set to true when the [InputDecorator] contains a multiline + /// [TextField] ([TextField.maxLines] is null or > 1) to override the default + /// behavior of aligning the label with the center of the [TextField]. + /// + /// Defaults to false. + final bool? alignLabelWithHint; + + /// Defines minimum and maximum sizes for the [InputDecorator]. + /// + /// Typically the decorator will fill the horizontal space it is given. For + /// larger screens, it may be useful to have the maximum width clamped to + /// a given value so it doesn't fill the whole screen. This property + /// allows you to control how big the decorator will be in its available + /// space. + /// + /// If null, then the ambient [ThemeData.inputDecorationTheme]'s + /// [InputDecorationTheme.constraints] will be used. If that + /// is null then the decorator will fill the available width with + /// a default height based on text size. + final BoxConstraints? constraints; + + /// Creates a copy of this input decoration with the given fields replaced + /// by the new values. + InputDecoration copyWith({ + Widget? icon, + Color? iconColor, + Widget? label, + String? labelText, + TextStyle? labelStyle, + TextStyle? floatingLabelStyle, + String? helperText, + TextStyle? helperStyle, + int? helperMaxLines, + String? hintText, + TextStyle? hintStyle, + TextDirection? hintTextDirection, + Duration? hintFadeDuration, + int? hintMaxLines, + Widget? error, + String? errorText, + TextStyle? errorStyle, + int? errorMaxLines, + FloatingLabelBehavior? floatingLabelBehavior, + FloatingLabelAlignment? floatingLabelAlignment, + bool? isCollapsed, + bool? isDense, + EdgeInsetsGeometry? contentPadding, + Widget? prefixIcon, + Widget? prefix, + String? prefixText, + BoxConstraints? prefixIconConstraints, + TextStyle? prefixStyle, + Color? prefixIconColor, + Widget? suffixIcon, + Widget? suffix, + String? suffixText, + TextStyle? suffixStyle, + Color? suffixIconColor, + BoxConstraints? suffixIconConstraints, + Widget? counter, + String? counterText, + TextStyle? counterStyle, + bool? filled, + Color? fillColor, + Color? focusColor, + Color? hoverColor, + InputBorder? errorBorder, + InputBorder? focusedBorder, + InputBorder? focusedErrorBorder, + InputBorder? disabledBorder, + InputBorder? enabledBorder, + InputBorder? border, + bool? enabled, + String? semanticCounterText, + bool? alignLabelWithHint, + BoxConstraints? constraints, + }) { + return InputDecoration( + icon: icon ?? this.icon, + iconColor: iconColor ?? this.iconColor, + label: label ?? this.label, + labelText: labelText ?? this.labelText, + labelStyle: labelStyle ?? this.labelStyle, + floatingLabelStyle: floatingLabelStyle ?? this.floatingLabelStyle, + helperText: helperText ?? this.helperText, + helperStyle: helperStyle ?? this.helperStyle, + helperMaxLines : helperMaxLines ?? this.helperMaxLines, + hintText: hintText ?? this.hintText, + hintStyle: hintStyle ?? this.hintStyle, + hintTextDirection: hintTextDirection ?? this.hintTextDirection, + hintMaxLines: hintMaxLines ?? this.hintMaxLines, + hintFadeDuration: hintFadeDuration ?? this.hintFadeDuration, + error: error ?? this.error, + errorText: errorText ?? this.errorText, + errorStyle: errorStyle ?? this.errorStyle, + errorMaxLines: errorMaxLines ?? this.errorMaxLines, + floatingLabelBehavior: floatingLabelBehavior ?? this.floatingLabelBehavior, + floatingLabelAlignment: floatingLabelAlignment ?? this.floatingLabelAlignment, + isCollapsed: isCollapsed ?? this.isCollapsed, + isDense: isDense ?? this.isDense, + contentPadding: contentPadding ?? this.contentPadding, + prefixIcon: prefixIcon ?? this.prefixIcon, + prefix: prefix ?? this.prefix, + prefixText: prefixText ?? this.prefixText, + prefixStyle: prefixStyle ?? this.prefixStyle, + prefixIconColor: prefixIconColor ?? this.prefixIconColor, + prefixIconConstraints: prefixIconConstraints ?? this.prefixIconConstraints, + suffixIcon: suffixIcon ?? this.suffixIcon, + suffix: suffix ?? this.suffix, + suffixText: suffixText ?? this.suffixText, + suffixStyle: suffixStyle ?? this.suffixStyle, + suffixIconColor: suffixIconColor ?? this.suffixIconColor, + suffixIconConstraints: suffixIconConstraints ?? this.suffixIconConstraints, + counter: counter ?? this.counter, + counterText: counterText ?? this.counterText, + counterStyle: counterStyle ?? this.counterStyle, + filled: filled ?? this.filled, + fillColor: fillColor ?? this.fillColor, + focusColor: focusColor ?? this.focusColor, + hoverColor: hoverColor ?? this.hoverColor, + errorBorder: errorBorder ?? this.errorBorder, + focusedBorder: focusedBorder ?? this.focusedBorder, + focusedErrorBorder: focusedErrorBorder ?? this.focusedErrorBorder, + disabledBorder: disabledBorder ?? this.disabledBorder, + enabledBorder: enabledBorder ?? this.enabledBorder, + border: border ?? this.border, + enabled: enabled ?? this.enabled, + semanticCounterText: semanticCounterText ?? this.semanticCounterText, + alignLabelWithHint: alignLabelWithHint ?? this.alignLabelWithHint, + constraints: constraints ?? this.constraints, + ); + } + + /// Used by widgets like [TextField] and [InputDecorator] to create a new + /// [InputDecoration] with default values taken from the [theme]. + /// + /// Only null valued properties from this [InputDecoration] are replaced + /// by the corresponding values from [theme]. + InputDecoration applyDefaults(InputDecorationTheme theme) { + return copyWith( + labelStyle: labelStyle ?? theme.labelStyle, + floatingLabelStyle: floatingLabelStyle ?? theme.floatingLabelStyle, + helperStyle: helperStyle ?? theme.helperStyle, + helperMaxLines : helperMaxLines ?? theme.helperMaxLines, + hintStyle: hintStyle ?? theme.hintStyle, + hintFadeDuration: hintFadeDuration ?? theme.hintFadeDuration, + errorStyle: errorStyle ?? theme.errorStyle, + errorMaxLines: errorMaxLines ?? theme.errorMaxLines, + floatingLabelBehavior: floatingLabelBehavior ?? theme.floatingLabelBehavior, + floatingLabelAlignment: floatingLabelAlignment ?? theme.floatingLabelAlignment, + isDense: isDense ?? theme.isDense, + contentPadding: contentPadding ?? theme.contentPadding, + isCollapsed: isCollapsed ?? theme.isCollapsed, + iconColor: iconColor ?? theme.iconColor, + prefixStyle: prefixStyle ?? theme.prefixStyle, + prefixIconColor: prefixIconColor ?? theme.prefixIconColor, + suffixStyle: suffixStyle ?? theme.suffixStyle, + suffixIconColor: suffixIconColor ?? theme.suffixIconColor, + counterStyle: counterStyle ?? theme.counterStyle, + filled: filled ?? theme.filled, + fillColor: fillColor ?? theme.fillColor, + focusColor: focusColor ?? theme.focusColor, + hoverColor: hoverColor ?? theme.hoverColor, + errorBorder: errorBorder ?? theme.errorBorder, + focusedBorder: focusedBorder ?? theme.focusedBorder, + focusedErrorBorder: focusedErrorBorder ?? theme.focusedErrorBorder, + disabledBorder: disabledBorder ?? theme.disabledBorder, + enabledBorder: enabledBorder ?? theme.enabledBorder, + border: border ?? theme.border, + alignLabelWithHint: alignLabelWithHint ?? theme.alignLabelWithHint, + constraints: constraints ?? theme.constraints, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is InputDecoration + && other.icon == icon + && other.iconColor == iconColor + && other.label == label + && other.labelText == labelText + && other.labelStyle == labelStyle + && other.floatingLabelStyle == floatingLabelStyle + && other.helperText == helperText + && other.helperStyle == helperStyle + && other.helperMaxLines == helperMaxLines + && other.hintText == hintText + && other.hintStyle == hintStyle + && other.hintTextDirection == hintTextDirection + && other.hintMaxLines == hintMaxLines + && other.hintFadeDuration == hintFadeDuration + && other.error == error + && other.errorText == errorText + && other.errorStyle == errorStyle + && other.errorMaxLines == errorMaxLines + && other.floatingLabelBehavior == floatingLabelBehavior + && other.floatingLabelAlignment == floatingLabelAlignment + && other.isDense == isDense + && other.contentPadding == contentPadding + && other.isCollapsed == isCollapsed + && other.prefixIcon == prefixIcon + && other.prefixIconColor == prefixIconColor + && other.prefix == prefix + && other.prefixText == prefixText + && other.prefixStyle == prefixStyle + && other.prefixIconConstraints == prefixIconConstraints + && other.suffixIcon == suffixIcon + && other.suffixIconColor == suffixIconColor + && other.suffix == suffix + && other.suffixText == suffixText + && other.suffixStyle == suffixStyle + && other.suffixIconConstraints == suffixIconConstraints + && other.counter == counter + && other.counterText == counterText + && other.counterStyle == counterStyle + && other.filled == filled + && other.fillColor == fillColor + && other.focusColor == focusColor + && other.hoverColor == hoverColor + && other.errorBorder == errorBorder + && other.focusedBorder == focusedBorder + && other.focusedErrorBorder == focusedErrorBorder + && other.disabledBorder == disabledBorder + && other.enabledBorder == enabledBorder + && other.border == border + && other.enabled == enabled + && other.semanticCounterText == semanticCounterText + && other.alignLabelWithHint == alignLabelWithHint + && other.constraints == constraints; + } + + @override + int get hashCode { + final List<Object?> values = <Object?>[ + icon, + iconColor, + label, + labelText, + floatingLabelStyle, + labelStyle, + helperText, + helperStyle, + helperMaxLines, + hintText, + hintStyle, + hintTextDirection, + hintMaxLines, + hintFadeDuration, + error, + errorText, + errorStyle, + errorMaxLines, + floatingLabelBehavior, + floatingLabelAlignment, + isDense, + contentPadding, + isCollapsed, + filled, + fillColor, + focusColor, + hoverColor, + prefixIcon, + prefixIconColor, + prefix, + prefixText, + prefixStyle, + prefixIconConstraints, + suffixIcon, + suffixIconColor, + suffix, + suffixText, + suffixStyle, + suffixIconConstraints, + counter, + counterText, + counterStyle, + errorBorder, + focusedBorder, + focusedErrorBorder, + disabledBorder, + enabledBorder, + border, + enabled, + semanticCounterText, + alignLabelWithHint, + constraints, + ]; + return Object.hashAll(values); + } + + @override + String toString() { + final List<String> description = <String>[ + if (icon != null) 'icon: $icon', + if (iconColor != null) 'iconColor: $iconColor', + if (label != null) 'label: $label', + if (labelText != null) 'labelText: "$labelText"', + if (floatingLabelStyle != null) 'floatingLabelStyle: "$floatingLabelStyle"', + if (helperText != null) 'helperText: "$helperText"', + if (helperMaxLines != null) 'helperMaxLines: "$helperMaxLines"', + if (hintText != null) 'hintText: "$hintText"', + if (hintMaxLines != null) 'hintMaxLines: "$hintMaxLines"', + if (hintFadeDuration != null) 'hintFadeDuration: "$hintFadeDuration"', + if (error != null) 'error: "$error"', + if (errorText != null) 'errorText: "$errorText"', + if (errorStyle != null) 'errorStyle: "$errorStyle"', + if (errorMaxLines != null) 'errorMaxLines: "$errorMaxLines"', + if (floatingLabelBehavior != null) 'floatingLabelBehavior: $floatingLabelBehavior', + if (floatingLabelAlignment != null) 'floatingLabelAlignment: $floatingLabelAlignment', + if (isDense ?? false) 'isDense: $isDense', + if (contentPadding != null) 'contentPadding: $contentPadding', + if (isCollapsed ?? false) 'isCollapsed: $isCollapsed', + if (prefixIcon != null) 'prefixIcon: $prefixIcon', + if (prefixIconColor != null) 'prefixIconColor: $prefixIconColor', + if (prefix != null) 'prefix: $prefix', + if (prefixText != null) 'prefixText: $prefixText', + if (prefixStyle != null) 'prefixStyle: $prefixStyle', + if (prefixIconConstraints != null) 'prefixIconConstraints: $prefixIconConstraints', + if (suffixIcon != null) 'suffixIcon: $suffixIcon', + if (suffixIconColor != null) 'suffixIconColor: $suffixIconColor', + if (suffix != null) 'suffix: $suffix', + if (suffixText != null) 'suffixText: $suffixText', + if (suffixStyle != null) 'suffixStyle: $suffixStyle', + if (suffixIconConstraints != null) 'suffixIconConstraints: $suffixIconConstraints', + if (counter != null) 'counter: $counter', + if (counterText != null) 'counterText: $counterText', + if (counterStyle != null) 'counterStyle: $counterStyle', + if (filled ?? false) 'filled: true', + if (fillColor != null) 'fillColor: $fillColor', + if (focusColor != null) 'focusColor: $focusColor', + if (hoverColor != null) 'hoverColor: $hoverColor', + if (errorBorder != null) 'errorBorder: $errorBorder', + if (focusedBorder != null) 'focusedBorder: $focusedBorder', + if (focusedErrorBorder != null) 'focusedErrorBorder: $focusedErrorBorder', + if (disabledBorder != null) 'disabledBorder: $disabledBorder', + if (enabledBorder != null) 'enabledBorder: $enabledBorder', + if (border != null) 'border: $border', + if (!enabled) 'enabled: false', + if (semanticCounterText != null) 'semanticCounterText: $semanticCounterText', + if (alignLabelWithHint != null) 'alignLabelWithHint: $alignLabelWithHint', + if (constraints != null) 'constraints: $constraints', + ]; + return 'InputDecoration(${description.join(', ')})'; + } +} + +/// Defines the default appearance of [InputDecorator]s. +/// +/// This class is used to define the value of [ThemeData.inputDecorationTheme]. +/// The [InputDecorator], [TextField], and [TextFormField] widgets use +/// the current input decoration theme to initialize null [InputDecoration] +/// properties. +/// +/// The [InputDecoration.applyDefaults] method is used to combine a input +/// decoration theme with an [InputDecoration] object. +@immutable +class InputDecorationTheme with Diagnosticable { + /// Creates a value for [ThemeData.inputDecorationTheme] that + /// defines default values for [InputDecorator]. + const InputDecorationTheme({ + this.labelStyle, + this.floatingLabelStyle, + this.helperStyle, + this.helperMaxLines, + this.hintStyle, + this.hintFadeDuration, + this.errorStyle, + this.errorMaxLines, + this.floatingLabelBehavior = FloatingLabelBehavior.auto, + this.floatingLabelAlignment = FloatingLabelAlignment.start, + this.isDense = false, + this.contentPadding, + this.isCollapsed = false, + this.iconColor, + this.prefixStyle, + this.prefixIconColor, + this.suffixStyle, + this.suffixIconColor, + this.counterStyle, + this.filled = false, + this.fillColor, + this.activeIndicatorBorder, + this.outlineBorder, + this.focusColor, + this.hoverColor, + this.errorBorder, + this.focusedBorder, + this.focusedErrorBorder, + this.disabledBorder, + this.enabledBorder, + this.border, + this.alignLabelWithHint = false, + this.constraints, + }); + + /// {@macro flutter.material.inputDecoration.labelStyle} + final TextStyle? labelStyle; + + /// {@macro flutter.material.inputDecoration.floatingLabelStyle} + final TextStyle? floatingLabelStyle; + + /// The style to use for [InputDecoration.helperText]. + /// + /// If [helperStyle] is a [MaterialStateTextStyle], then the effective + /// text style can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + final TextStyle? helperStyle; + + /// The maximum number of lines the [InputDecoration.helperText] can occupy. + /// + /// Defaults to null, which means that the [InputDecoration.helperText] will + /// be limited to a single line with [TextOverflow.ellipsis]. + /// + /// This value is passed along to the [Text.maxLines] attribute + /// of the [Text] widget used to display the helper. + /// + /// See also: + /// + /// * [errorMaxLines], the equivalent but for the [InputDecoration.errorText]. + final int? helperMaxLines; + + /// The style to use for the [InputDecoration.hintText]. + /// + /// If [hintStyle] is a [MaterialStateTextStyle], then the effective + /// text style can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// Also used for the [InputDecoration.labelText] when the + /// [InputDecoration.labelText] is displayed on top of the input field (i.e., + /// at the same location on the screen where text may be entered in the input + /// field). + /// + /// If null, defaults to a value derived from the base [TextStyle] for the + /// input field and the current [Theme]. + final TextStyle? hintStyle; + + /// The duration of the [InputDecoration.hintText] fade in and fade out animations. + final Duration? hintFadeDuration; + + /// {@macro flutter.material.inputDecoration.errorStyle} + final TextStyle? errorStyle; + + /// The maximum number of lines the [InputDecoration.errorText] can occupy. + /// + /// Defaults to null, which means that the [InputDecoration.errorText] will be + /// limited to a single line with [TextOverflow.ellipsis]. + /// + /// This value is passed along to the [Text.maxLines] attribute + /// of the [Text] widget used to display the error. + /// + /// See also: + /// + /// * [helperMaxLines], the equivalent but for the [InputDecoration.helperText]. + final int? errorMaxLines; + + /// {@macro flutter.material.inputDecoration.floatingLabelBehavior} + /// + /// Defaults to [FloatingLabelBehavior.auto]. + final FloatingLabelBehavior floatingLabelBehavior; + + /// {@macro flutter.material.inputDecoration.floatingLabelAlignment} + /// + /// Defaults to [FloatingLabelAlignment.start]. + final FloatingLabelAlignment floatingLabelAlignment; + + /// Whether the input decorator's child is part of a dense form (i.e., uses + /// less vertical space). + /// + /// Defaults to false. + final bool isDense; + + /// The padding for the input decoration's container. + /// + /// The decoration's container is the area which is filled if + /// [InputDecoration.filled] is true and bordered per the [border]. + /// It's the area adjacent to [InputDecoration.icon] and above the + /// [InputDecoration.icon] and above the widgets that contain + /// [InputDecoration.helperText], [InputDecoration.errorText], and + /// [InputDecoration.counterText]. + /// + /// By default the [contentPadding] reflects [isDense] and the type of the + /// [border]. If [isCollapsed] is true then [contentPadding] is + /// [EdgeInsets.zero]. + final EdgeInsetsGeometry? contentPadding; + + /// Whether the decoration is the same size as the input field. + /// + /// A collapsed decoration cannot have [InputDecoration.labelText], + /// [InputDecoration.errorText], or an [InputDecoration.icon]. + final bool isCollapsed; + + /// The Color to use for the [InputDecoration.icon]. + /// + /// If [iconColor] is a [MaterialStateColor], then the effective + /// color can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// If null, defaults to the [ColorScheme.primary]. + final Color? iconColor; + + /// The style to use for the [InputDecoration.prefixText]. + /// + /// If [prefixStyle] is a [MaterialStateTextStyle], then the effective + /// text style can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// If null, defaults to the [hintStyle]. + final TextStyle? prefixStyle; + + /// The Color to use for the [InputDecoration.prefixIcon]. + /// + /// If [prefixIconColor] is a [MaterialStateColor], then the effective + /// color can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// If null, defaults to the [ColorScheme.primary]. + final Color? prefixIconColor; + + /// The style to use for the [InputDecoration.suffixText]. + /// + /// If [suffixStyle] is a [MaterialStateTextStyle], then the effective + /// color can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// If null, defaults to the [hintStyle]. + final TextStyle? suffixStyle; + + /// The Color to use for the [InputDecoration.suffixIcon]. + /// + /// If [suffixIconColor] is a [MaterialStateColor], then the effective + /// color can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// If null, defaults to the [ColorScheme.primary]. + final Color? suffixIconColor; + + /// The style to use for the [InputDecoration.counterText]. + /// + /// If [counterStyle] is a [MaterialStateTextStyle], then the effective + /// text style can depend on the [MaterialState.focused] state, i.e. + /// if the [TextField] is focused or not. + /// + /// If null, defaults to the [helperStyle]. + final TextStyle? counterStyle; + + /// If true the decoration's container is filled with [fillColor]. + /// + /// Typically this field set to true if [border] is an + /// [UnderlineInputBorder]. + /// + /// The decoration's container is the area, defined by the border's + /// [InputBorder.getOuterPath], which is filled if [filled] is + /// true and bordered per the [border]. + /// + /// This property is false by default. + final bool filled; + + /// The color to fill the decoration's container with, if [filled] is true. + /// + /// By default the fillColor is based on the current [Theme]. + /// + /// The decoration's container is the area, defined by the border's + /// [InputBorder.getOuterPath], which is filled if [filled] is + /// true and bordered per the [border]. + final Color? fillColor; + + /// The borderSide of the OutlineInputBorder with `color` and `weight`. + final BorderSide? outlineBorder; + + /// The borderSide of the UnderlineInputBorder with `color` and `weight`. + final BorderSide? activeIndicatorBorder; + + /// The color to blend with the decoration's [fillColor] with, if [filled] is + /// true and the container has the input focus. + /// + /// By default the [focusColor] is based on the current [Theme]. + /// + /// The decoration's container is the area, defined by the border's + /// [InputBorder.getOuterPath], which is filled if [filled] is + /// true and bordered per the [border]. + final Color? focusColor; + + /// The color to blend with the decoration's [fillColor] with, if the + /// decoration is being hovered over by a mouse pointer. + /// + /// By default the [hoverColor] is based on the current [Theme]. + /// + /// The decoration's container is the area, defined by the border's + /// [InputBorder.getOuterPath], which is filled if [filled] is + /// true and bordered per the [border]. + /// + /// The container will be filled when hovered over even if [filled] is false. + final Color? hoverColor; + + /// The border to display when the [InputDecorator] does not have the focus and + /// is showing an error. + /// + /// See also: + /// + /// * [InputDecorator.isFocused], which is true if the [InputDecorator]'s child + /// has the focus. + /// * [InputDecoration.errorText], the error shown by the [InputDecorator], if non-null. + /// * [border], for a description of where the [InputDecorator] border appears. + /// * [UnderlineInputBorder], an [InputDecorator] border which draws a horizontal + /// line at the bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + /// * [InputBorder.none], which doesn't draw a border. + /// * [focusedBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is null. + /// * [focusedErrorBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is non-null. + /// * [disabledBorder], displayed when [InputDecoration.enabled] is false + /// and [InputDecoration.errorText] is null. + /// * [enabledBorder], displayed when [InputDecoration.enabled] is true + /// and [InputDecoration.errorText] is null. + final InputBorder? errorBorder; + + /// The border to display when the [InputDecorator] has the focus and is not + /// showing an error. + /// + /// See also: + /// + /// * [InputDecorator.isFocused], which is true if the [InputDecorator]'s child + /// has the focus. + /// * [InputDecoration.errorText], the error shown by the [InputDecorator], if non-null. + /// * [border], for a description of where the [InputDecorator] border appears. + /// * [UnderlineInputBorder], an [InputDecorator] border which draws a horizontal + /// line at the bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + /// * [InputBorder.none], which doesn't draw a border. + /// * [errorBorder], displayed when [InputDecorator.isFocused] is false + /// and [InputDecoration.errorText] is non-null. + /// * [focusedErrorBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is non-null. + /// * [disabledBorder], displayed when [InputDecoration.enabled] is false + /// and [InputDecoration.errorText] is null. + /// * [enabledBorder], displayed when [InputDecoration.enabled] is true + /// and [InputDecoration.errorText] is null. + final InputBorder? focusedBorder; + + /// The border to display when the [InputDecorator] has the focus and is + /// showing an error. + /// + /// See also: + /// + /// * [InputDecorator.isFocused], which is true if the [InputDecorator]'s child + /// has the focus. + /// * [InputDecoration.errorText], the error shown by the [InputDecorator], if non-null. + /// * [border], for a description of where the [InputDecorator] border appears. + /// * [UnderlineInputBorder], an [InputDecorator] border which draws a horizontal + /// line at the bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + /// * [InputBorder.none], which doesn't draw a border. + /// * [errorBorder], displayed when [InputDecorator.isFocused] is false + /// and [InputDecoration.errorText] is non-null. + /// * [focusedBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is null. + /// * [disabledBorder], displayed when [InputDecoration.enabled] is false + /// and [InputDecoration.errorText] is null. + /// * [enabledBorder], displayed when [InputDecoration.enabled] is true + /// and [InputDecoration.errorText] is null. + final InputBorder? focusedErrorBorder; + + /// The border to display when the [InputDecorator] is disabled and is not + /// showing an error. + /// + /// See also: + /// + /// * [InputDecoration.enabled], which is false if the [InputDecorator] is disabled. + /// * [InputDecoration.errorText], the error shown by the [InputDecorator], if non-null. + /// * [border], for a description of where the [InputDecorator] border appears. + /// * [UnderlineInputBorder], an [InputDecorator] border which draws a horizontal + /// line at the bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + /// * [InputBorder.none], which doesn't draw a border. + /// * [errorBorder], displayed when [InputDecorator.isFocused] is false + /// and [InputDecoration.errorText] is non-null. + /// * [focusedBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is null. + /// * [focusedErrorBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is non-null. + /// * [enabledBorder], displayed when [InputDecoration.enabled] is true + /// and [InputDecoration.errorText] is null. + final InputBorder? disabledBorder; + + /// The border to display when the [InputDecorator] is enabled and is not + /// showing an error. + /// + /// See also: + /// + /// * [InputDecoration.enabled], which is false if the [InputDecorator] is disabled. + /// * [InputDecoration.errorText], the error shown by the [InputDecorator], if non-null. + /// * [border], for a description of where the [InputDecorator] border appears. + /// * [UnderlineInputBorder], an [InputDecorator] border which draws a horizontal + /// line at the bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + /// * [InputBorder.none], which doesn't draw a border. + /// * [errorBorder], displayed when [InputDecorator.isFocused] is false + /// and [InputDecoration.errorText] is non-null. + /// * [focusedBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is null. + /// * [focusedErrorBorder], displayed when [InputDecorator.isFocused] is true + /// and [InputDecoration.errorText] is non-null. + /// * [disabledBorder], displayed when [InputDecoration.enabled] is false + /// and [InputDecoration.errorText] is null. + final InputBorder? enabledBorder; + + /// The shape of the border to draw around the decoration's container. + /// + /// If [border] is a [MaterialStateUnderlineInputBorder] + /// or [MaterialStateOutlineInputBorder], then the effective border can depend on + /// the [MaterialState.focused] state, i.e. if the [TextField] is focused or not. + /// + /// The decoration's container is the area which is filled if [filled] is + /// true and bordered per the [border]. It's the area adjacent to + /// [InputDecoration.icon] and above the widgets that contain + /// [InputDecoration.helperText], [InputDecoration.errorText], and + /// [InputDecoration.counterText]. + /// + /// The border's bounds, i.e. the value of `border.getOuterPath()`, define + /// the area to be filled. + /// + /// This property is only used when the appropriate one of [errorBorder], + /// [focusedBorder], [focusedErrorBorder], [disabledBorder], or [enabledBorder] + /// is not specified. This border's [InputBorder.borderSide] property is + /// configured by the InputDecorator, depending on the values of + /// [InputDecoration.errorText], [InputDecoration.enabled], + /// [InputDecorator.isFocused] and the current [Theme]. + /// + /// Typically one of [UnderlineInputBorder] or [OutlineInputBorder]. + /// If null, InputDecorator's default is `const UnderlineInputBorder()`. + /// + /// See also: + /// + /// * [InputBorder.none], which doesn't draw a border. + /// * [UnderlineInputBorder], which draws a horizontal line at the + /// bottom of the input decorator's container. + /// * [OutlineInputBorder], an [InputDecorator] border which draws a + /// rounded rectangle around the input decorator's container. + final InputBorder? border; + + /// Typically set to true when the [InputDecorator] contains a multiline + /// [TextField] ([TextField.maxLines] is null or > 1) to override the default + /// behavior of aligning the label with the center of the [TextField]. + final bool alignLabelWithHint; + + /// Defines minimum and maximum sizes for the [InputDecorator]. + /// + /// Typically the decorator will fill the horizontal space it is given. For + /// larger screens, it may be useful to have the maximum width clamped to + /// a given value so it doesn't fill the whole screen. This property + /// allows you to control how big the decorator will be in its available + /// space. + /// + /// If null, then the decorator will fill the available width with + /// a default height based on text size. + /// + /// See also: + /// + /// * [InputDecoration.constraints], which can override this setting for a + /// given decorator. + final BoxConstraints? constraints; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + InputDecorationTheme copyWith({ + TextStyle? labelStyle, + TextStyle? floatingLabelStyle, + TextStyle? helperStyle, + int? helperMaxLines, + TextStyle? hintStyle, + Duration? hintFadeDuration, + TextStyle? errorStyle, + int? errorMaxLines, + FloatingLabelBehavior? floatingLabelBehavior, + FloatingLabelAlignment? floatingLabelAlignment, + bool? isDense, + EdgeInsetsGeometry? contentPadding, + bool? isCollapsed, + Color? iconColor, + TextStyle? prefixStyle, + Color? prefixIconColor, + TextStyle? suffixStyle, + Color? suffixIconColor, + TextStyle? counterStyle, + bool? filled, + Color? fillColor, + BorderSide? activeIndicatorBorder, + BorderSide? outlineBorder, + Color? focusColor, + Color? hoverColor, + InputBorder? errorBorder, + InputBorder? focusedBorder, + InputBorder? focusedErrorBorder, + InputBorder? disabledBorder, + InputBorder? enabledBorder, + InputBorder? border, + bool? alignLabelWithHint, + BoxConstraints? constraints, + }) { + return InputDecorationTheme( + labelStyle: labelStyle ?? this.labelStyle, + floatingLabelStyle: floatingLabelStyle ?? this.floatingLabelStyle, + helperStyle: helperStyle ?? this.helperStyle, + helperMaxLines: helperMaxLines ?? this.helperMaxLines, + hintStyle: hintStyle ?? this.hintStyle, + hintFadeDuration: hintFadeDuration ?? this.hintFadeDuration, + errorStyle: errorStyle ?? this.errorStyle, + errorMaxLines: errorMaxLines ?? this.errorMaxLines, + floatingLabelBehavior: floatingLabelBehavior ?? this.floatingLabelBehavior, + floatingLabelAlignment: floatingLabelAlignment ?? this.floatingLabelAlignment, + isDense: isDense ?? this.isDense, + contentPadding: contentPadding ?? this.contentPadding, + iconColor: iconColor, + isCollapsed: isCollapsed ?? this.isCollapsed, + prefixStyle: prefixStyle ?? this.prefixStyle, + prefixIconColor: prefixIconColor ?? this.prefixIconColor, + suffixStyle: suffixStyle ?? this.suffixStyle, + suffixIconColor: suffixIconColor ?? this.suffixIconColor, + counterStyle: counterStyle ?? this.counterStyle, + filled: filled ?? this.filled, + fillColor: fillColor ?? this.fillColor, + activeIndicatorBorder: activeIndicatorBorder ?? this.activeIndicatorBorder, + outlineBorder: outlineBorder ?? this.outlineBorder, + focusColor: focusColor ?? this.focusColor, + hoverColor: hoverColor ?? this.hoverColor, + errorBorder: errorBorder ?? this.errorBorder, + focusedBorder: focusedBorder ?? this.focusedBorder, + focusedErrorBorder: focusedErrorBorder ?? this.focusedErrorBorder, + disabledBorder: disabledBorder ?? this.disabledBorder, + enabledBorder: enabledBorder ?? this.enabledBorder, + border: border ?? this.border, + alignLabelWithHint: alignLabelWithHint ?? this.alignLabelWithHint, + constraints: constraints ?? this.constraints, + ); + } + + /// Returns a copy of this InputDecorationTheme where the non-null fields in + /// the given InputDecorationTheme override the corresponding nullable fields + /// in this InputDecorationTheme. + /// + /// The non-nullable fields of InputDecorationTheme, such as [floatingLabelBehavior], + /// [isDense], [isCollapsed], [filled], and [alignLabelWithHint] cannot be overridden. + /// + /// In other words, the fields of the provided [InputDecorationTheme] are used to + /// fill in the unspecified and nullable fields of this InputDecorationTheme. + InputDecorationTheme merge(InputDecorationTheme? inputDecorationTheme) { + if (inputDecorationTheme == null) { + return this; + } + return copyWith( + labelStyle: labelStyle ?? inputDecorationTheme.labelStyle, + floatingLabelStyle: floatingLabelStyle ?? inputDecorationTheme.floatingLabelStyle, + helperStyle: helperStyle ?? inputDecorationTheme.helperStyle, + helperMaxLines: helperMaxLines ?? inputDecorationTheme.helperMaxLines, + hintStyle: hintStyle ?? inputDecorationTheme.hintStyle, + hintFadeDuration: hintFadeDuration ?? inputDecorationTheme.hintFadeDuration, + errorStyle: errorStyle ?? inputDecorationTheme.errorStyle, + errorMaxLines: errorMaxLines ?? inputDecorationTheme.errorMaxLines, + contentPadding: contentPadding ?? inputDecorationTheme.contentPadding, + iconColor: iconColor ?? inputDecorationTheme.iconColor, + prefixStyle: prefixStyle ?? inputDecorationTheme.prefixStyle, + prefixIconColor: prefixIconColor ?? inputDecorationTheme.prefixIconColor, + suffixStyle: suffixStyle ?? inputDecorationTheme.suffixStyle, + suffixIconColor: suffixIconColor ?? inputDecorationTheme.suffixIconColor, + counterStyle: counterStyle ?? inputDecorationTheme.counterStyle, + fillColor: fillColor ?? inputDecorationTheme.fillColor, + activeIndicatorBorder: activeIndicatorBorder ?? inputDecorationTheme.activeIndicatorBorder, + outlineBorder: outlineBorder ?? inputDecorationTheme.outlineBorder, + focusColor: focusColor ?? inputDecorationTheme.focusColor, + hoverColor: hoverColor ?? inputDecorationTheme.hoverColor, + errorBorder: errorBorder ?? inputDecorationTheme.errorBorder, + focusedBorder: focusedBorder ?? inputDecorationTheme.focusedBorder, + focusedErrorBorder: focusedErrorBorder ?? inputDecorationTheme.focusedErrorBorder, + disabledBorder: disabledBorder ?? inputDecorationTheme.disabledBorder, + enabledBorder: enabledBorder ?? inputDecorationTheme.enabledBorder, + border: border ?? inputDecorationTheme.border, + constraints: constraints ?? inputDecorationTheme.constraints, + ); + } + + @override + int get hashCode => Object.hash( + labelStyle, + floatingLabelStyle, + helperStyle, + helperMaxLines, + hintStyle, + errorStyle, + errorMaxLines, + floatingLabelBehavior, + floatingLabelAlignment, + isDense, + contentPadding, + isCollapsed, + iconColor, + prefixStyle, + prefixIconColor, + suffixStyle, + suffixIconColor, + counterStyle, + filled, + Object.hash( + fillColor, + activeIndicatorBorder, + outlineBorder, + focusColor, + hoverColor, + errorBorder, + focusedBorder, + focusedErrorBorder, + disabledBorder, + enabledBorder, + border, + alignLabelWithHint, + constraints, + hintFadeDuration, + ), + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is InputDecorationTheme + && other.labelStyle == labelStyle + && other.floatingLabelStyle == floatingLabelStyle + && other.helperStyle == helperStyle + && other.helperMaxLines == helperMaxLines + && other.hintStyle == hintStyle + && other.hintFadeDuration == hintFadeDuration + && other.errorStyle == errorStyle + && other.errorMaxLines == errorMaxLines + && other.isDense == isDense + && other.contentPadding == contentPadding + && other.isCollapsed == isCollapsed + && other.iconColor == iconColor + && other.prefixStyle == prefixStyle + && other.prefixIconColor == prefixIconColor + && other.suffixStyle == suffixStyle + && other.suffixIconColor == suffixIconColor + && other.counterStyle == counterStyle + && other.floatingLabelBehavior == floatingLabelBehavior + && other.floatingLabelAlignment == floatingLabelAlignment + && other.filled == filled + && other.fillColor == fillColor + && other.activeIndicatorBorder == activeIndicatorBorder + && other.outlineBorder == outlineBorder + && other.focusColor == focusColor + && other.hoverColor == hoverColor + && other.errorBorder == errorBorder + && other.focusedBorder == focusedBorder + && other.focusedErrorBorder == focusedErrorBorder + && other.disabledBorder == disabledBorder + && other.enabledBorder == enabledBorder + && other.border == border + && other.alignLabelWithHint == alignLabelWithHint + && other.constraints == constraints + && other.disabledBorder == disabledBorder; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + const InputDecorationTheme defaultTheme = InputDecorationTheme(); + properties.add(DiagnosticsProperty<TextStyle>('labelStyle', labelStyle, defaultValue: defaultTheme.labelStyle)); + properties.add(DiagnosticsProperty<TextStyle>('floatingLabelStyle', floatingLabelStyle, defaultValue: defaultTheme.floatingLabelStyle)); + properties.add(DiagnosticsProperty<TextStyle>('helperStyle', helperStyle, defaultValue: defaultTheme.helperStyle)); + properties.add(IntProperty('helperMaxLines', helperMaxLines, defaultValue: defaultTheme.helperMaxLines)); + properties.add(DiagnosticsProperty<TextStyle>('hintStyle', hintStyle, defaultValue: defaultTheme.hintStyle)); + properties.add(DiagnosticsProperty<Duration>('hintFadeDuration', hintFadeDuration, defaultValue: defaultTheme.hintFadeDuration)); + properties.add(DiagnosticsProperty<TextStyle>('errorStyle', errorStyle, defaultValue: defaultTheme.errorStyle)); + properties.add(IntProperty('errorMaxLines', errorMaxLines, defaultValue: defaultTheme.errorMaxLines)); + properties.add(DiagnosticsProperty<FloatingLabelBehavior>('floatingLabelBehavior', floatingLabelBehavior, defaultValue: defaultTheme.floatingLabelBehavior)); + properties.add(DiagnosticsProperty<FloatingLabelAlignment>('floatingLabelAlignment', floatingLabelAlignment, defaultValue: defaultTheme.floatingLabelAlignment)); + properties.add(DiagnosticsProperty<bool>('isDense', isDense, defaultValue: defaultTheme.isDense)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('contentPadding', contentPadding, defaultValue: defaultTheme.contentPadding)); + properties.add(DiagnosticsProperty<bool>('isCollapsed', isCollapsed, defaultValue: defaultTheme.isCollapsed)); + properties.add(DiagnosticsProperty<Color>('iconColor', iconColor, defaultValue: defaultTheme.iconColor)); + properties.add(DiagnosticsProperty<Color>('prefixIconColor', prefixIconColor, defaultValue: defaultTheme.prefixIconColor)); + properties.add(DiagnosticsProperty<TextStyle>('prefixStyle', prefixStyle, defaultValue: defaultTheme.prefixStyle)); + properties.add(DiagnosticsProperty<Color>('suffixIconColor', suffixIconColor, defaultValue: defaultTheme.suffixIconColor)); + properties.add(DiagnosticsProperty<TextStyle>('suffixStyle', suffixStyle, defaultValue: defaultTheme.suffixStyle)); + properties.add(DiagnosticsProperty<TextStyle>('counterStyle', counterStyle, defaultValue: defaultTheme.counterStyle)); + properties.add(DiagnosticsProperty<bool>('filled', filled, defaultValue: defaultTheme.filled)); + properties.add(ColorProperty('fillColor', fillColor, defaultValue: defaultTheme.fillColor)); + properties.add(DiagnosticsProperty<BorderSide>('activeIndicatorBorder', activeIndicatorBorder, defaultValue: defaultTheme.activeIndicatorBorder)); + properties.add(DiagnosticsProperty<BorderSide>('outlineBorder', outlineBorder, defaultValue: defaultTheme.outlineBorder)); + properties.add(ColorProperty('focusColor', focusColor, defaultValue: defaultTheme.focusColor)); + properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: defaultTheme.hoverColor)); + properties.add(DiagnosticsProperty<InputBorder>('errorBorder', errorBorder, defaultValue: defaultTheme.errorBorder)); + properties.add(DiagnosticsProperty<InputBorder>('focusedBorder', focusedBorder, defaultValue: defaultTheme.focusedErrorBorder)); + properties.add(DiagnosticsProperty<InputBorder>('focusedErrorBorder', focusedErrorBorder, defaultValue: defaultTheme.focusedErrorBorder)); + properties.add(DiagnosticsProperty<InputBorder>('disabledBorder', disabledBorder, defaultValue: defaultTheme.disabledBorder)); + properties.add(DiagnosticsProperty<InputBorder>('enabledBorder', enabledBorder, defaultValue: defaultTheme.enabledBorder)); + properties.add(DiagnosticsProperty<InputBorder>('border', border, defaultValue: defaultTheme.border)); + properties.add(DiagnosticsProperty<bool>('alignLabelWithHint', alignLabelWithHint, defaultValue: defaultTheme.alignLabelWithHint)); + properties.add(DiagnosticsProperty<BoxConstraints>('constraints', constraints, defaultValue: defaultTheme.constraints)); + } +} + +class _InputDecoratorDefaultsM2 extends InputDecorationTheme { + const _InputDecoratorDefaultsM2(this.context) + : super(); + + final BuildContext context; + + @override + TextStyle? get hintStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return TextStyle(color: Theme.of(context).disabledColor); + } + return TextStyle(color: Theme.of(context).hintColor); + }); + + @override + TextStyle? get labelStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return TextStyle(color: Theme.of(context).disabledColor); + } + return TextStyle(color: Theme.of(context).hintColor); + }); + + @override + TextStyle? get floatingLabelStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return TextStyle(color: Theme.of(context).disabledColor); + } + if (states.contains(MaterialState.error)) { + return TextStyle(color: Theme.of(context).colorScheme.error); + } + if (states.contains(MaterialState.focused)) { + return TextStyle(color: Theme.of(context).colorScheme.primary); + } + return TextStyle(color: Theme.of(context).hintColor); + }); + + @override + TextStyle? get helperStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + final ThemeData themeData= Theme.of(context); + if (states.contains(MaterialState.disabled)) { + return themeData.textTheme.bodySmall!.copyWith(color: Colors.transparent); + } + + return themeData.textTheme.bodySmall!.copyWith(color: themeData.hintColor); + }); + + @override + TextStyle? get errorStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + final ThemeData themeData= Theme.of(context); + if (states.contains(MaterialState.disabled)) { + return themeData.textTheme.bodySmall!.copyWith(color: Colors.transparent); + } + return themeData.textTheme.bodySmall!.copyWith(color: themeData.colorScheme.error); + }); + + @override + Color? get fillColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + // dark theme: 5% white + // light theme: 2% black + switch (Theme.of(context).brightness) { + case Brightness.dark: + return const Color(0x0DFFFFFF); + case Brightness.light: + return const Color(0x05000000) ; + } + } + // dark theme: 10% white + // light theme: 4% black + switch (Theme.of(context).brightness) { + case Brightness.dark: return const Color(0x1AFFFFFF); + case Brightness.light:return const Color(0x0A000000) ; + } + }); + + @override + Color? get iconColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled) && !states.contains(MaterialState.focused)) { + return Theme.of(context).disabledColor; + } + if (states.contains(MaterialState.focused)) { + return Theme.of(context).colorScheme.primary; + } + switch (Theme.of(context).brightness) { + case Brightness.dark: + return Colors.white70; + case Brightness.light: + return Colors.black45; + } + }); + + @override + Color? get prefixIconColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled) && !states.contains(MaterialState.focused)) { + return Theme.of(context).disabledColor; + } + if (states.contains(MaterialState.focused)) { + return Theme.of(context).colorScheme.primary; + } + switch (Theme.of(context).brightness) { + case Brightness.dark: + return Colors.white70; + case Brightness.light: + return Colors.black45; + } + }); + + @override + Color? get suffixIconColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled) && !states.contains(MaterialState.focused)) { + return Theme.of(context).disabledColor; + } + if (states.contains(MaterialState.focused)) { + return Theme.of(context).colorScheme.primary; + } + switch (Theme.of(context).brightness) { + case Brightness.dark: + return Colors.white70; + case Brightness.light: + return Colors.black45; + } + }); +} + +// BEGIN GENERATED TOKEN PROPERTIES - InputDecorator + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _InputDecoratorDefaultsM3 extends InputDecorationTheme { + _InputDecoratorDefaultsM3(this.context) + : super(); + + final BuildContext context; + + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + TextStyle? get hintStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return TextStyle(color: Theme.of(context).disabledColor); + } + return TextStyle(color: Theme.of(context).hintColor); + }); + + @override + Color? get fillColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.04); + } + return _colors.surfaceVariant; + }); + + @override + BorderSide? get activeIndicatorBorder => MaterialStateBorderSide.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return BorderSide(color: _colors.onSurface.withOpacity(0.38)); + } + if (states.contains(MaterialState.error)) { + if (states.contains(MaterialState.hovered)) { + return BorderSide(color: _colors.onErrorContainer); + } + if (states.contains(MaterialState.focused)) { + return BorderSide(color: _colors.error, width: 2.0); + } + return BorderSide(color: _colors.error); + } + if (states.contains(MaterialState.hovered)) { + return BorderSide(color: _colors.onSurface); + } + if (states.contains(MaterialState.focused)) { + return BorderSide(color: _colors.primary, width: 2.0); + } + return BorderSide(color: _colors.onSurfaceVariant); + }); + + @override + BorderSide? get outlineBorder => MaterialStateBorderSide.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return BorderSide(color: _colors.onSurface.withOpacity(0.12)); + } + if (states.contains(MaterialState.error)) { + if (states.contains(MaterialState.hovered)) { + return BorderSide(color: _colors.onErrorContainer); + } + if (states.contains(MaterialState.focused)) { + return BorderSide(color: _colors.error, width: 2.0); + } + return BorderSide(color: _colors.error); + } + if (states.contains(MaterialState.hovered)) { + return BorderSide(color: _colors.onSurface); + } + if (states.contains(MaterialState.focused)) { + return BorderSide(color: _colors.primary, width: 2.0); + } + return BorderSide(color: _colors.outline); + }); + + @override + Color? get iconColor => _colors.onSurfaceVariant; + + @override + Color? get prefixIconColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { + return _colors.onSurfaceVariant; + }); + + @override + Color? get suffixIconColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.error)) { + return _colors.error; + } + return _colors.onSurfaceVariant; + }); + + @override + TextStyle? get labelStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + final TextStyle textStyle = _textTheme.bodyLarge ?? const TextStyle(); + if (states.contains(MaterialState.disabled)) { + return textStyle.copyWith(color: _colors.onSurface.withOpacity(0.38)); + } + if (states.contains(MaterialState.error)) { + if (states.contains(MaterialState.hovered)) { + return textStyle.copyWith(color: _colors.onErrorContainer); + } + if (states.contains(MaterialState.focused)) { + return textStyle.copyWith(color: _colors.error); + } + return textStyle.copyWith(color: _colors.error); + } + if (states.contains(MaterialState.hovered)) { + return textStyle.copyWith(color: _colors.onSurfaceVariant); + } + if (states.contains(MaterialState.focused)) { + return textStyle.copyWith(color: _colors.primary); + } + return textStyle.copyWith(color: _colors.onSurfaceVariant); + }); + + @override + TextStyle? get floatingLabelStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + final TextStyle textStyle = _textTheme.bodyLarge ?? const TextStyle(); + if (states.contains(MaterialState.disabled)) { + return textStyle.copyWith(color: _colors.onSurface.withOpacity(0.38)); + } + if (states.contains(MaterialState.error)) { + if (states.contains(MaterialState.hovered)) { + return textStyle.copyWith(color: _colors.onErrorContainer); + } + if (states.contains(MaterialState.focused)) { + return textStyle.copyWith(color: _colors.error); + } + return textStyle.copyWith(color: _colors.error); + } + if (states.contains(MaterialState.hovered)) { + return textStyle.copyWith(color: _colors.onSurfaceVariant); + } + if (states.contains(MaterialState.focused)) { + return textStyle.copyWith(color: _colors.primary); + } + return textStyle.copyWith(color: _colors.onSurfaceVariant); + }); + + @override + TextStyle? get helperStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + final TextStyle textStyle = _textTheme.bodySmall ?? const TextStyle(); + if (states.contains(MaterialState.disabled)) { + return textStyle.copyWith(color: _colors.onSurface.withOpacity(0.38)); + } + return textStyle.copyWith(color: _colors.onSurfaceVariant); + }); + + @override + TextStyle? get errorStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + final TextStyle textStyle = _textTheme.bodySmall ?? const TextStyle(); + return textStyle.copyWith(color: _colors.error); + }); +} + +// END GENERATED TOKEN PROPERTIES - InputDecorator diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/list_tile.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/list_tile.dart new file mode 100644 index 0000000000000000000000000000000000000000..98d12151595536c3a460e1523a327c4570d90fbe --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/list_tile.dart @@ -0,0 +1,1599 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'divider.dart'; +import 'icon_button.dart'; +import 'icon_button_theme.dart'; +import 'ink_decoration.dart'; +import 'ink_well.dart'; +import 'list_tile_theme.dart'; +import 'material_state.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// int _act = 1; + +/// Defines the title font used for [ListTile] descendants of a [ListTileTheme]. +/// +/// List tiles that appear in a [Drawer] use the theme's [TextTheme.bodyLarge] +/// text style, which is a little smaller than the theme's [TextTheme.titleMedium] +/// text style, which is used by default. +enum ListTileStyle { + /// Use a title font that's appropriate for a [ListTile] in a list. + list, + + /// Use a title font that's appropriate for a [ListTile] that appears in a [Drawer]. + drawer, +} + +/// Where to place the control in widgets that use [ListTile] to position a +/// control next to a label. +/// +/// See also: +/// +/// * [CheckboxListTile], which combines a [ListTile] with a [Checkbox]. +/// * [RadioListTile], which combines a [ListTile] with a [Radio] button. +/// * [SwitchListTile], which combines a [ListTile] with a [Switch]. +/// * [ExpansionTile], which combines a [ListTile] with a button that expands +/// or collapses the tile to reveal or hide the children. +enum ListTileControlAffinity { + /// Position the control on the leading edge, and the secondary widget, if + /// any, on the trailing edge. + leading, + + /// Position the control on the trailing edge, and the secondary widget, if + /// any, on the leading edge. + trailing, + + /// Position the control relative to the text in the fashion that is typical + /// for the current platform, and place the secondary widget on the opposite + /// side. + platform, +} + +/// Defines how [ListTile.leading] and [ListTile.trailing] are +/// vertically aligned relative to the [ListTile]'s titles +/// ([ListTile.title] and [ListTile.subtitle]). +/// +/// See also: +/// +/// * [ListTile.titleAlignment], to configure the title alignment for an +/// individual [ListTile]. +/// * [ListTileThemeData.titleAlignment], to configure the title alignment +/// for all of the [ListTile]s under a [ListTileTheme]. +/// * [ThemeData.listTileTheme], to configure the [ListTileTheme] +/// for an entire app. +enum ListTileTitleAlignment { + /// The top of the [ListTile.leading] and [ListTile.trailing] widgets are + /// placed [ListTile.minVerticalPadding] below the top of the [ListTile.title] + /// if [ListTile.isThreeLine] is true, otherwise they're centered relative + /// to the [ListTile.title] and [ListTile.subtitle] widgets. + /// + /// This is the default when [ThemeData.useMaterial3] is true. + threeLine, + + /// The tops of the [ListTile.leading] and [ListTile.trailing] widgets are + /// placed 16 units below the top of the [ListTile.title] + /// if the titles' overall height is greater than 72, otherwise they're + /// centered relative to the [ListTile.title] and [ListTile.subtitle] widgets. + /// + /// This is the default when [ThemeData.useMaterial3] is false. + titleHeight, + + /// The tops of the [ListTile.leading] and [ListTile.trailing] widgets are + /// placed [ListTile.minVerticalPadding] below the top of the [ListTile.title]. + top, + + /// The [ListTile.leading] and [ListTile.trailing] widgets are + /// centered relative to the [ListTile]'s titles. + center, + + /// The bottoms of the [ListTile.leading] and [ListTile.trailing] widgets are + /// placed [ListTile.minVerticalPadding] above the bottom of the [ListTile]'s + /// titles. + bottom, +} + +/// A single fixed-height row that typically contains some text as well as +/// a leading or trailing icon. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=l8dj0yPBvgQ} +/// +/// A list tile contains one to three lines of text optionally flanked by icons or +/// other widgets, such as check boxes. The icons (or other widgets) for the +/// tile are defined with the [leading] and [trailing] parameters. The first +/// line of text is not optional and is specified with [title]. The value of +/// [subtitle], which _is_ optional, will occupy the space allocated for an +/// additional line of text, or two lines if [isThreeLine] is true. If [dense] +/// is true then the overall height of this tile and the size of the +/// [DefaultTextStyle]s that wrap the [title] and [subtitle] widget are reduced. +/// +/// It is the responsibility of the caller to ensure that [title] does not wrap, +/// and to ensure that [subtitle] doesn't wrap (if [isThreeLine] is false) or +/// wraps to two lines (if it is true). +/// +/// The heights of the [leading] and [trailing] widgets are constrained +/// according to the +/// [Material spec](https://material.io/design/components/lists.html). +/// An exception is made for one-line ListTiles for accessibility. Please +/// see the example below to see how to adhere to both Material spec and +/// accessibility requirements. +/// +/// The [leading] and [trailing] widgets can expand as far as they wish +/// horizontally, so ensure that they are properly constrained. +/// +/// List tiles are typically used in [ListView]s, or arranged in [Column]s in +/// [Drawer]s and [Card]s. +/// +/// This widget requires a [Material] widget ancestor in the tree to paint +/// itself on, which is typically provided by the app's [Scaffold]. +/// The [tileColor], [selectedTileColor], [focusColor], and [hoverColor] +/// are not painted by the [ListTile] itself but by the [Material] widget +/// ancestor. In this case, one can wrap a [Material] widget around the +/// [ListTile], e.g.: +/// +/// {@tool snippet} +/// ```dart +/// const ColoredBox( +/// color: Colors.green, +/// child: Material( +/// child: ListTile( +/// title: Text('ListTile with red background'), +/// tileColor: Colors.red, +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Performance considerations when wrapping [ListTile] with [Material] +/// +/// Wrapping a large number of [ListTile]s individually with [Material]s +/// is expensive. Consider only wrapping the [ListTile]s that require it +/// or include a common [Material] ancestor where possible. +/// +/// [ListTile] must be wrapped in a [Material] widget to animate [tileColor], +/// [selectedTileColor], [focusColor], and [hoverColor] as these colors +/// are not drawn by the list tile itself but by the material widget ancestor. +/// +/// {@tool dartpad} +/// This example showcases how [ListTile] needs to be wrapped in a [Material] +/// widget to animate colors. +/// +/// ** See code in examples/api/lib/material/list_tile/list_tile.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example uses a [ListView] to demonstrate different configurations of +/// [ListTile]s in [Card]s. +/// +/// ![Different variations of ListTile](https://flutter.github.io/assets-for-api-docs/assets/material/list_tile.png) +/// +/// ** See code in examples/api/lib/material/list_tile/list_tile.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of a [ListTile] using [ThemeData.useMaterial3] flag, +/// as described in: https://m3.material.io/components/lists/overview. +/// +/// ** See code in examples/api/lib/material/list_tile/list_tile.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows [ListTile]'s [textColor] and [iconColor] can use +/// [MaterialStateColor] color to change the color of the text and icon +/// when the [ListTile] is enabled, selected, or disabled. +/// +/// ** See code in examples/api/lib/material/list_tile/list_tile.3.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows [ListTile.titleAlignment] can be used to configure the +/// [leading] and [trailing] widgets alignment relative to the [title] and +/// [subtitle] widgets. +/// +/// ** See code in examples/api/lib/material/list_tile/list_tile.4.dart ** +/// {@end-tool} +/// +/// {@tool snippet} +/// To use a [ListTile] within a [Row], it needs to be wrapped in an +/// [Expanded] widget. [ListTile] requires fixed width constraints, +/// whereas a [Row] does not constrain its children. +/// +/// ```dart +/// const Row( +/// children: <Widget>[ +/// Expanded( +/// child: ListTile( +/// leading: FlutterLogo(), +/// title: Text('These ListTiles are expanded '), +/// ), +/// ), +/// Expanded( +/// child: ListTile( +/// trailing: FlutterLogo(), +/// title: Text('to fill the available space.'), +/// ), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// Tiles can be much more elaborate. Here is a tile which can be tapped, but +/// which is disabled when the `_act` variable is not 2. When the tile is +/// tapped, the whole row has an ink splash effect (see [InkWell]). +/// +/// ```dart +/// ListTile( +/// leading: const Icon(Icons.flight_land), +/// title: const Text("Trix's airplane"), +/// subtitle: _act != 2 ? const Text('The airplane is only in Act II.') : null, +/// enabled: _act == 2, +/// onTap: () { /* react to the tile being tapped */ } +/// ) +/// ``` +/// {@end-tool} +/// +/// To be accessible, tappable [leading] and [trailing] widgets have to +/// be at least 48x48 in size. However, to adhere to the Material spec, +/// [trailing] and [leading] widgets in one-line ListTiles should visually be +/// at most 32 ([dense]: true) or 40 ([dense]: false) in height, which may +/// conflict with the accessibility requirement. +/// +/// For this reason, a one-line ListTile allows the height of [leading] +/// and [trailing] widgets to be constrained by the height of the ListTile. +/// This allows for the creation of tappable [leading] and [trailing] widgets +/// that are large enough, but it is up to the developer to ensure that +/// their widgets follow the Material spec. +/// +/// {@tool snippet} +/// +/// Here is an example of a one-line, non-[dense] ListTile with a +/// tappable leading widget that adheres to accessibility requirements and +/// the Material spec. To adjust the use case below for a one-line, [dense] +/// ListTile, adjust the vertical padding to 8.0. +/// +/// ```dart +/// ListTile( +/// leading: GestureDetector( +/// behavior: HitTestBehavior.translucent, +/// onTap: () {}, +/// child: Container( +/// width: 48, +/// height: 48, +/// padding: const EdgeInsets.symmetric(vertical: 4.0), +/// alignment: Alignment.center, +/// child: const CircleAvatar(), +/// ), +/// ), +/// title: const Text('title'), +/// dense: false, +/// ) +/// ``` +/// {@end-tool} +/// +/// ## The ListTile layout isn't exactly what I want +/// +/// If the way ListTile pads and positions its elements isn't quite what +/// you're looking for, it's easy to create custom list items with a +/// combination of other widgets, such as [Row]s and [Column]s. +/// +/// {@tool dartpad} +/// Here is an example of a custom list item that resembles a YouTube-related +/// video list item created with [Expanded] and [Container] widgets. +/// +/// ** See code in examples/api/lib/material/list_tile/custom_list_item.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// Here is an example of an article list item with multiline titles and +/// subtitles. It utilizes [Row]s and [Column]s, as well as [Expanded] and +/// [AspectRatio] widgets to organize its layout. +/// +/// ** See code in examples/api/lib/material/list_tile/custom_list_item.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListTileTheme], which defines visual properties for [ListTile]s. +/// * [ListView], which can display an arbitrary number of [ListTile]s +/// in a scrolling list. +/// * [CircleAvatar], which shows an icon representing a person and is often +/// used as the [leading] element of a ListTile. +/// * [Card], which can be used with [Column] to show a few [ListTile]s. +/// * [Divider], which can be used to separate [ListTile]s. +/// * [ListTile.divideTiles], a utility for inserting [Divider]s in between [ListTile]s. +/// * [CheckboxListTile], [RadioListTile], and [SwitchListTile], widgets +/// that combine [ListTile] with other controls. +/// * Material 3 [ListTile] specifications are referenced from <https://m3.material.io/components/lists/specs> +/// and Material 2 [ListTile] specifications are referenced from <https://material.io/design/components/lists.html> +/// * Cookbook: [Use lists](https://flutter.dev/docs/cookbook/lists/basic-list) +/// * Cookbook: [Implement swipe to dismiss](https://flutter.dev/docs/cookbook/gestures/dismissible) +class ListTile extends StatelessWidget { + /// Creates a list tile. + /// + /// If [isThreeLine] is true, then [subtitle] must not be null. + /// + /// Requires one of its ancestors to be a [Material] widget. + const ListTile({ + super.key, + this.leading, + this.title, + this.subtitle, + this.trailing, + this.isThreeLine = false, + this.dense, + this.visualDensity, + this.shape, + this.style, + this.selectedColor, + this.iconColor, + this.textColor, + this.titleTextStyle, + this.subtitleTextStyle, + this.leadingAndTrailingTextStyle, + this.contentPadding, + this.enabled = true, + this.onTap, + this.onLongPress, + this.onFocusChange, + this.mouseCursor, + this.selected = false, + this.focusColor, + this.hoverColor, + this.splashColor, + this.focusNode, + this.autofocus = false, + this.tileColor, + this.selectedTileColor, + this.enableFeedback, + this.horizontalTitleGap, + this.minVerticalPadding, + this.minLeadingWidth, + this.titleAlignment, + }) : assert(!isThreeLine || subtitle != null); + + /// A widget to display before the title. + /// + /// Typically an [Icon] or a [CircleAvatar] widget. + final Widget? leading; + + /// The primary content of the list tile. + /// + /// Typically a [Text] widget. + /// + /// This should not wrap. To enforce the single line limit, use + /// [Text.maxLines]. + final Widget? title; + + /// Additional content displayed below the title. + /// + /// Typically a [Text] widget. + /// + /// If [isThreeLine] is false, this should not wrap. + /// + /// If [isThreeLine] is true, this should be configured to take a maximum of + /// two lines. For example, you can use [Text.maxLines] to enforce the number + /// of lines. + /// + /// The subtitle's default [TextStyle] depends on [TextTheme.bodyMedium] except + /// [TextStyle.color]. The [TextStyle.color] depends on the value of [enabled] + /// and [selected]. + /// + /// When [enabled] is false, the text color is set to [ThemeData.disabledColor]. + /// + /// When [selected] is false, the text color is set to [ListTileTheme.textColor] + /// if it's not null and to [TextTheme.bodySmall]'s color if [ListTileTheme.textColor] + /// is null. + final Widget? subtitle; + + /// A widget to display after the title. + /// + /// Typically an [Icon] widget. + /// + /// To show right-aligned metadata (assuming left-to-right reading order; + /// left-aligned for right-to-left reading order), consider using a [Row] with + /// [CrossAxisAlignment.baseline] alignment whose first item is [Expanded] and + /// whose second child is the metadata text, instead of using the [trailing] + /// property. + final Widget? trailing; + + /// Whether this list tile is intended to display three lines of text. + /// + /// If true, then [subtitle] must be non-null (since it is expected to give + /// the second and third lines of text). + /// + /// If false, the list tile is treated as having one line if the subtitle is + /// null and treated as having two lines if the subtitle is non-null. + /// + /// When using a [Text] widget for [title] and [subtitle], you can enforce + /// line limits using [Text.maxLines]. + final bool isThreeLine; + + /// {@template flutter.material.ListTile.dense} + /// Whether this list tile is part of a vertically dense list. + /// + /// If this property is null then its value is based on [ListTileTheme.dense]. + /// + /// Dense list tiles default to a smaller height. + /// + /// It is not recommended to set [dense] to true when [ThemeData.useMaterial3] is true. + /// {@endtemplate} + final bool? dense; + + /// Defines how compact the list tile's layout will be. + /// + /// {@macro flutter.material.themedata.visualDensity} + /// + /// See also: + /// + /// * [ThemeData.visualDensity], which specifies the [visualDensity] for all + /// widgets within a [Theme]. + final VisualDensity? visualDensity; + + /// {@template flutter.material.ListTile.shape} + /// Defines the tile's [InkWell.customBorder] and [Ink.decoration] shape. + /// {@endtemplate} + /// + /// If this property is null then [ListTileThemeData.shape] is used. If that + /// is also null then a rectangular [Border] will be used. + /// + /// See also: + /// + /// * [ListTileTheme.of], which returns the nearest [ListTileTheme]'s + /// [ListTileThemeData]. + final ShapeBorder? shape; + + /// Defines the color used for icons and text when the list tile is selected. + /// + /// If this property is null then [ListTileThemeData.selectedColor] + /// is used. If that is also null then [ColorScheme.primary] is used. + /// + /// See also: + /// + /// * [ListTileTheme.of], which returns the nearest [ListTileTheme]'s + /// [ListTileThemeData]. + final Color? selectedColor; + + /// Defines the default color for [leading] and [trailing] icons. + /// + /// If this property is null and [selected] is false then [ListTileThemeData.iconColor] + /// is used. If that is also null and [ThemeData.useMaterial3] is true, [ColorScheme.onSurfaceVariant] + /// is used, otherwise if [ThemeData.brightness] is [Brightness.light], [Colors.black54] is used, + /// and if [ThemeData.brightness] is [Brightness.dark], the value is null. + /// + /// If this property is null and [selected] is true then [ListTileThemeData.selectedColor] + /// is used. If that is also null then [ColorScheme.primary] is used. + /// + /// If this color is a [MaterialStateColor] it will be resolved against + /// [MaterialState.selected] and [MaterialState.disabled] states. + /// + /// See also: + /// + /// * [ListTileTheme.of], which returns the nearest [ListTileTheme]'s + /// [ListTileThemeData]. + final Color? iconColor; + + /// Defines the text color for the [title], [subtitle], [leading], and [trailing]. + /// + /// If this property is null and [selected] is false then [ListTileThemeData.textColor] + /// is used. If that is also null then default text color is used for the [title], [subtitle] + /// [leading], and [trailing]. Except for [subtitle], if [ThemeData.useMaterial3] is false, + /// [TextTheme.bodySmall] is used. + /// + /// If this property is null and [selected] is true then [ListTileThemeData.selectedColor] + /// is used. If that is also null then [ColorScheme.primary] is used. + /// + /// If this color is a [MaterialStateColor] it will be resolved against + /// [MaterialState.selected] and [MaterialState.disabled] states. + /// + /// See also: + /// + /// * [ListTileTheme.of], which returns the nearest [ListTileTheme]'s + /// [ListTileThemeData]. + final Color? textColor; + + /// The text style for ListTile's [title]. + /// + /// If this property is null, then [ListTileThemeData.titleTextStyle] is used. + /// If that is also null and [ThemeData.useMaterial3] is true, [TextTheme.bodyLarge] + /// with [ColorScheme.onSurface] will be used. Otherwise, If ListTile style is + /// [ListTileStyle.list], [TextTheme.titleMedium] will be used and if ListTile style + /// is [ListTileStyle.drawer], [TextTheme.bodyLarge] will be used. + final TextStyle? titleTextStyle; + + /// The text style for ListTile's [subtitle]. + /// + /// If this property is null, then [ListTileThemeData.subtitleTextStyle] is used. + /// If that is also null and [ThemeData.useMaterial3] is true, [TextTheme.bodyMedium] + /// with [ColorScheme.onSurfaceVariant] will be used, otherwise [TextTheme.bodyMedium] + /// with [TextTheme.bodySmall] color will be used. + final TextStyle? subtitleTextStyle; + + /// The text style for ListTile's [leading] and [trailing]. + /// + /// If this property is null, then [ListTileThemeData.leadingAndTrailingTextStyle] is used. + /// If that is also null and [ThemeData.useMaterial3] is true, [TextTheme.labelSmall] + /// with [ColorScheme.onSurfaceVariant] will be used, otherwise [TextTheme.bodyMedium] + /// will be used. + final TextStyle? leadingAndTrailingTextStyle; + + /// Defines the font used for the [title]. + /// + /// If this property is null then [ListTileThemeData.style] is used. If that + /// is also null then [ListTileStyle.list] is used. + /// + /// See also: + /// + /// * [ListTileTheme.of], which returns the nearest [ListTileTheme]'s + /// [ListTileThemeData]. + final ListTileStyle? style; + + /// The tile's internal padding. + /// + /// Insets a [ListTile]'s contents: its [leading], [title], [subtitle], + /// and [trailing] widgets. + /// + /// If null, `EdgeInsets.symmetric(horizontal: 16.0)` is used. + final EdgeInsetsGeometry? contentPadding; + + /// Whether this list tile is interactive. + /// + /// If false, this list tile is styled with the disabled color from the + /// current [Theme] and the [onTap] and [onLongPress] callbacks are + /// inoperative. + final bool enabled; + + /// Called when the user taps this list tile. + /// + /// Inoperative if [enabled] is false. + final GestureTapCallback? onTap; + + /// Called when the user long-presses on this list tile. + /// + /// Inoperative if [enabled] is false. + final GestureLongPressCallback? onLongPress; + + /// {@macro flutter.material.inkwell.onFocusChange} + final ValueChanged<bool>? onFocusChange; + + /// {@template flutter.material.ListTile.mouseCursor} + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.selected]. + /// * [MaterialState.disabled]. + /// {@endtemplate} + /// + /// If null, then the value of [ListTileThemeData.mouseCursor] is used. If + /// that is also null, then [MaterialStateMouseCursor.clickable] is used. + /// + /// See also: + /// + /// * [MaterialStateMouseCursor], which can be used to create a [MouseCursor] + /// that is also a [MaterialStateProperty<MouseCursor>]. + final MouseCursor? mouseCursor; + + /// If this tile is also [enabled] then icons and text are rendered with the same color. + /// + /// By default the selected color is the theme's primary color. The selected color + /// can be overridden with a [ListTileTheme]. + /// + /// {@tool dartpad} + /// Here is an example of using a [StatefulWidget] to keep track of the + /// selected index, and using that to set the [selected] property on the + /// corresponding [ListTile]. + /// + /// ** See code in examples/api/lib/material/list_tile/list_tile.selected.0.dart ** + /// {@end-tool} + final bool selected; + + /// The color for the tile's [Material] when it has the input focus. + final Color? focusColor; + + /// The color for the tile's [Material] when a pointer is hovering over it. + final Color? hoverColor; + + /// The color of splash for the tile's [Material]. + final Color? splashColor; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@template flutter.material.ListTile.tileColor} + /// Defines the background color of `ListTile` when [selected] is false. + /// + /// If this property is null and [selected] is false then [ListTileThemeData.tileColor] + /// is used. If that is also null and [selected] is true, [selectedTileColor] is used. + /// When that is also null, the [ListTileTheme.selectedTileColor] is used, otherwise + /// [Colors.transparent] is used. + /// + /// {@endtemplate} + final Color? tileColor; + + /// Defines the background color of `ListTile` when [selected] is true. + /// + /// When the value if null, the [selectedTileColor] is set to [ListTileTheme.selectedTileColor] + /// if it's not null and to [Colors.transparent] if it's null. + final Color? selectedTileColor; + + /// {@template flutter.material.ListTile.enableFeedback} + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// When null, the default value is true. + /// {@endtemplate} + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + /// The horizontal gap between the titles and the leading/trailing widgets. + /// + /// If null, then the value of [ListTileTheme.horizontalTitleGap] is used. If + /// that is also null, then a default value of 16 is used. + final double? horizontalTitleGap; + + /// The minimum padding on the top and bottom of the title and subtitle widgets. + /// + /// If null, then the value of [ListTileTheme.minVerticalPadding] is used. If + /// that is also null, then a default value of 4 is used. + final double? minVerticalPadding; + + /// The minimum width allocated for the [ListTile.leading] widget. + /// + /// If null, then the value of [ListTileTheme.minLeadingWidth] is used. If + /// that is also null, then a default value of 40 is used. + final double? minLeadingWidth; + + /// Defines how [ListTile.leading] and [ListTile.trailing] are + /// vertically aligned relative to the [ListTile]'s titles + /// ([ListTile.title] and [ListTile.subtitle]). + /// + /// If this property is null then [ListTileThemeData.titleAlignment] + /// is used. If that is also null then [ListTileTitleAlignment.threeLine] + /// is used. + /// + /// See also: + /// + /// * [ListTileTheme.of], which returns the nearest [ListTileTheme]'s + /// [ListTileThemeData]. + final ListTileTitleAlignment? titleAlignment; + + /// Add a one pixel border in between each tile. If color isn't specified the + /// [ThemeData.dividerColor] of the context's [Theme] is used. + /// + /// See also: + /// + /// * [Divider], which you can use to obtain this effect manually. + static Iterable<Widget> divideTiles({ BuildContext? context, required Iterable<Widget> tiles, Color? color }) { + assert(color != null || context != null); + tiles = tiles.toList(); + + if (tiles.isEmpty || tiles.length == 1) { + return tiles; + } + + Widget wrapTile(Widget tile) { + return DecoratedBox( + position: DecorationPosition.foreground, + decoration: BoxDecoration( + border: Border( + bottom: Divider.createBorderSide(context, color: color), + ), + ), + child: tile, + ); + } + + return <Widget>[ + ...tiles.take(tiles.length - 1).map(wrapTile), + tiles.last, + ]; + } + + bool _isDenseLayout(ThemeData theme, ListTileThemeData tileTheme) { + return dense ?? tileTheme.dense ?? theme.listTileTheme.dense ?? false; + } + + Color _tileBackgroundColor(ThemeData theme, ListTileThemeData tileTheme, ListTileThemeData defaults) { + final Color? color = selected + ? selectedTileColor ?? tileTheme.selectedTileColor ?? theme.listTileTheme.selectedTileColor + : tileColor ?? tileTheme.tileColor ?? theme.listTileTheme.tileColor; + return color ?? defaults.tileColor!; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + final ThemeData theme = Theme.of(context); + final ListTileThemeData tileTheme = ListTileTheme.of(context); + final ListTileStyle listTileStyle = style + ?? tileTheme.style + ?? theme.listTileTheme.style + ?? ListTileStyle.list; + final ListTileThemeData defaults = theme.useMaterial3 + ? _LisTileDefaultsM3(context) + : _LisTileDefaultsM2(context, listTileStyle); + final Set<MaterialState> states = <MaterialState>{ + if (!enabled) MaterialState.disabled, + if (selected) MaterialState.selected, + }; + + Color? resolveColor(Color? explicitColor, Color? selectedColor, Color? enabledColor, [Color? disabledColor]) { + return _IndividualOverrides( + explicitColor: explicitColor, + selectedColor: selectedColor, + enabledColor: enabledColor, + disabledColor: disabledColor, + ).resolve(states); + } + + final Color? effectiveIconColor = resolveColor(iconColor, selectedColor, iconColor) + ?? resolveColor(tileTheme.iconColor, tileTheme.selectedColor, tileTheme.iconColor) + ?? resolveColor(theme.listTileTheme.iconColor, theme.listTileTheme.selectedColor, theme.listTileTheme.iconColor) + ?? resolveColor(defaults.iconColor, defaults.selectedColor, defaults.iconColor, theme.disabledColor); + final Color? effectiveColor = resolveColor(textColor, selectedColor, textColor) + ?? resolveColor(tileTheme.textColor, tileTheme.selectedColor, tileTheme.textColor) + ?? resolveColor(theme.listTileTheme.textColor, theme.listTileTheme.selectedColor, theme.listTileTheme.textColor) + ?? resolveColor(defaults.textColor, defaults.selectedColor, defaults.textColor, theme.disabledColor); + final IconThemeData iconThemeData = IconThemeData(color: effectiveIconColor); + final IconButtonThemeData iconButtonThemeData = IconButtonThemeData( + style: IconButton.styleFrom(foregroundColor: effectiveIconColor), + ); + + TextStyle? leadingAndTrailingStyle; + if (leading != null || trailing != null) { + leadingAndTrailingStyle = leadingAndTrailingTextStyle + ?? tileTheme.leadingAndTrailingTextStyle + ?? defaults.leadingAndTrailingTextStyle!; + final Color? leadingAndTrailingTextColor = effectiveColor; + leadingAndTrailingStyle = leadingAndTrailingStyle.copyWith(color: leadingAndTrailingTextColor); + } + + Widget? leadingIcon; + if (leading != null) { + leadingIcon = AnimatedDefaultTextStyle( + style: leadingAndTrailingStyle!, + duration: kThemeChangeDuration, + child: leading!, + ); + } + + TextStyle titleStyle = titleTextStyle + ?? tileTheme.titleTextStyle + ?? defaults.titleTextStyle!; + final Color? titleColor = effectiveColor; + titleStyle = titleStyle.copyWith( + color: titleColor, + fontSize: _isDenseLayout(theme, tileTheme) ? 13.0 : null, + ); + final Widget titleText = AnimatedDefaultTextStyle( + style: titleStyle, + duration: kThemeChangeDuration, + child: title ?? const SizedBox(), + ); + + Widget? subtitleText; + TextStyle? subtitleStyle; + if (subtitle != null) { + subtitleStyle = subtitleTextStyle + ?? tileTheme.subtitleTextStyle + ?? defaults.subtitleTextStyle!; + final Color? subtitleColor = effectiveColor; + subtitleStyle = subtitleStyle.copyWith( + color: subtitleColor, + fontSize: _isDenseLayout(theme, tileTheme) ? 12.0 : null, + ); + subtitleText = AnimatedDefaultTextStyle( + style: subtitleStyle, + duration: kThemeChangeDuration, + child: subtitle!, + ); + } + + Widget? trailingIcon; + if (trailing != null) { + trailingIcon = AnimatedDefaultTextStyle( + style: leadingAndTrailingStyle!, + duration: kThemeChangeDuration, + child: trailing!, + ); + } + + final TextDirection textDirection = Directionality.of(context); + final EdgeInsets resolvedContentPadding = contentPadding?.resolve(textDirection) + ?? tileTheme.contentPadding?.resolve(textDirection) + ?? defaults.contentPadding!.resolve(textDirection); + + // Show basic cursor when ListTile isn't enabled or gesture callbacks are null. + final Set<MaterialState> mouseStates = <MaterialState>{ + if (!enabled || (onTap == null && onLongPress == null)) MaterialState.disabled, + }; + final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor?>(mouseCursor, mouseStates) + ?? tileTheme.mouseCursor?.resolve(mouseStates) + ?? MaterialStateMouseCursor.clickable.resolve(mouseStates); + + final ListTileTitleAlignment effectiveTitleAlignment = titleAlignment + ?? tileTheme.titleAlignment + ?? (theme.useMaterial3 ? ListTileTitleAlignment.threeLine : ListTileTitleAlignment.titleHeight); + + return InkWell( + customBorder: shape ?? tileTheme.shape, + onTap: enabled ? onTap : null, + onLongPress: enabled ? onLongPress : null, + onFocusChange: onFocusChange, + mouseCursor: effectiveMouseCursor, + canRequestFocus: enabled, + focusNode: focusNode, + focusColor: focusColor, + hoverColor: hoverColor, + splashColor: splashColor, + autofocus: autofocus, + enableFeedback: enableFeedback ?? tileTheme.enableFeedback ?? true, + child: Semantics( + selected: selected, + enabled: enabled, + child: Ink( + decoration: ShapeDecoration( + shape: shape ?? tileTheme.shape ?? const Border(), + color: _tileBackgroundColor(theme, tileTheme, defaults), + ), + child: SafeArea( + top: false, + bottom: false, + minimum: resolvedContentPadding, + child: IconTheme.merge( + data: iconThemeData, + child: IconButtonTheme( + data: iconButtonThemeData, + child: _ListTile( + leading: leadingIcon, + title: titleText, + subtitle: subtitleText, + trailing: trailingIcon, + isDense: _isDenseLayout(theme, tileTheme), + visualDensity: visualDensity ?? tileTheme.visualDensity ?? theme.visualDensity, + isThreeLine: isThreeLine, + textDirection: textDirection, + titleBaselineType: titleStyle.textBaseline ?? defaults.titleTextStyle!.textBaseline!, + subtitleBaselineType: subtitleStyle?.textBaseline ?? defaults.subtitleTextStyle!.textBaseline!, + horizontalTitleGap: horizontalTitleGap ?? tileTheme.horizontalTitleGap ?? 16, + minVerticalPadding: minVerticalPadding ?? tileTheme.minVerticalPadding ?? defaults.minVerticalPadding!, + minLeadingWidth: minLeadingWidth ?? tileTheme.minLeadingWidth ?? defaults.minLeadingWidth!, + titleAlignment: effectiveTitleAlignment, + ), + ), + ), + ), + ), + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Widget>('leading', leading, defaultValue: null)); + properties.add(DiagnosticsProperty<Widget>('title', title, defaultValue: null)); + properties.add(DiagnosticsProperty<Widget>('subtitle', subtitle, defaultValue: null)); + properties.add(DiagnosticsProperty<Widget>('trailing', trailing, defaultValue: null)); + properties.add(FlagProperty('isThreeLine', value: isThreeLine, ifTrue:'THREE_LINE', ifFalse: 'TWO_LINE', showName: true, defaultValue: false)); + properties.add(FlagProperty('dense', value: dense, ifTrue: 'true', ifFalse: 'false', showName: true)); + properties.add(DiagnosticsProperty<VisualDensity>('visualDensity', visualDensity, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<ListTileStyle>('style', style, defaultValue: null)); + properties.add(ColorProperty('selectedColor', selectedColor, defaultValue: null)); + properties.add(ColorProperty('iconColor', iconColor, defaultValue: null)); + properties.add(ColorProperty('textColor', textColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('titleTextStyle', titleTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('subtitleTextStyle', subtitleTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('leadingAndTrailingTextStyle', leadingAndTrailingTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('contentPadding', contentPadding, defaultValue: null)); + properties.add(FlagProperty('enabled', value: enabled, ifTrue: 'true', ifFalse: 'false', showName: true, defaultValue: true)); + properties.add(DiagnosticsProperty<Function>('onTap', onTap, defaultValue: null)); + properties.add(DiagnosticsProperty<Function>('onLongPress', onLongPress, defaultValue: null)); + properties.add(DiagnosticsProperty<MouseCursor>('mouseCursor', mouseCursor, defaultValue: null)); + properties.add(FlagProperty('selected', value: selected, ifTrue: 'true', ifFalse: 'false', showName: true, defaultValue: false)); + properties.add(ColorProperty('focusColor', focusColor, defaultValue: null)); + properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: null)); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null)); + properties.add(FlagProperty('autofocus', value: autofocus, ifTrue: 'true', ifFalse: 'false', showName: true, defaultValue: false)); + properties.add(ColorProperty('tileColor', tileColor, defaultValue: null)); + properties.add(ColorProperty('selectedTileColor', selectedTileColor, defaultValue: null)); + properties.add(FlagProperty('enableFeedback', value: enableFeedback, ifTrue: 'true', ifFalse: 'false', showName: true)); + properties.add(DoubleProperty('horizontalTitleGap', horizontalTitleGap, defaultValue: null)); + properties.add(DoubleProperty('minVerticalPadding', minVerticalPadding, defaultValue: null)); + properties.add(DoubleProperty('minLeadingWidth', minLeadingWidth, defaultValue: null)); + properties.add(DiagnosticsProperty<ListTileTitleAlignment>('titleAlignment', titleAlignment, defaultValue: null)); + } +} + +class _IndividualOverrides extends MaterialStateProperty<Color?> { + _IndividualOverrides({ + this.explicitColor, + this.enabledColor, + this.selectedColor, + this.disabledColor, + }); + + final Color? explicitColor; + final Color? enabledColor; + final Color? selectedColor; + final Color? disabledColor; + + @override + Color? resolve(Set<MaterialState> states) { + if (explicitColor is MaterialStateColor) { + return MaterialStateProperty.resolveAs<Color?>(explicitColor, states); + } + if (states.contains(MaterialState.disabled)) { + return disabledColor; + } + if (states.contains(MaterialState.selected)) { + return selectedColor; + } + return enabledColor; + } +} + +// Identifies the children of a _ListTileElement. +enum _ListTileSlot { + leading, + title, + subtitle, + trailing, +} + +class _ListTile extends SlottedMultiChildRenderObjectWidget<_ListTileSlot, RenderBox> { + const _ListTile({ + this.leading, + required this.title, + this.subtitle, + this.trailing, + required this.isThreeLine, + required this.isDense, + required this.visualDensity, + required this.textDirection, + required this.titleBaselineType, + required this.horizontalTitleGap, + required this.minVerticalPadding, + required this.minLeadingWidth, + this.subtitleBaselineType, + required this.titleAlignment, + }); + + final Widget? leading; + final Widget title; + final Widget? subtitle; + final Widget? trailing; + final bool isThreeLine; + final bool isDense; + final VisualDensity visualDensity; + final TextDirection textDirection; + final TextBaseline titleBaselineType; + final TextBaseline? subtitleBaselineType; + final double horizontalTitleGap; + final double minVerticalPadding; + final double minLeadingWidth; + final ListTileTitleAlignment titleAlignment; + + @override + Iterable<_ListTileSlot> get slots => _ListTileSlot.values; + + @override + Widget? childForSlot(_ListTileSlot slot) { + switch (slot) { + case _ListTileSlot.leading: + return leading; + case _ListTileSlot.title: + return title; + case _ListTileSlot.subtitle: + return subtitle; + case _ListTileSlot.trailing: + return trailing; + } + } + + @override + _RenderListTile createRenderObject(BuildContext context) { + return _RenderListTile( + isThreeLine: isThreeLine, + isDense: isDense, + visualDensity: visualDensity, + textDirection: textDirection, + titleBaselineType: titleBaselineType, + subtitleBaselineType: subtitleBaselineType, + horizontalTitleGap: horizontalTitleGap, + minVerticalPadding: minVerticalPadding, + minLeadingWidth: minLeadingWidth, + titleAlignment: titleAlignment, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderListTile renderObject) { + renderObject + ..isThreeLine = isThreeLine + ..isDense = isDense + ..visualDensity = visualDensity + ..textDirection = textDirection + ..titleBaselineType = titleBaselineType + ..subtitleBaselineType = subtitleBaselineType + ..horizontalTitleGap = horizontalTitleGap + ..minLeadingWidth = minLeadingWidth + ..minVerticalPadding = minVerticalPadding + ..titleAlignment = titleAlignment; + } +} + +class _RenderListTile extends RenderBox with SlottedContainerRenderObjectMixin<_ListTileSlot, RenderBox> { + _RenderListTile({ + required bool isDense, + required VisualDensity visualDensity, + required bool isThreeLine, + required TextDirection textDirection, + required TextBaseline titleBaselineType, + TextBaseline? subtitleBaselineType, + required double horizontalTitleGap, + required double minVerticalPadding, + required double minLeadingWidth, + required ListTileTitleAlignment titleAlignment, + }) : _isDense = isDense, + _visualDensity = visualDensity, + _isThreeLine = isThreeLine, + _textDirection = textDirection, + _titleBaselineType = titleBaselineType, + _subtitleBaselineType = subtitleBaselineType, + _horizontalTitleGap = horizontalTitleGap, + _minVerticalPadding = minVerticalPadding, + _minLeadingWidth = minLeadingWidth, + _titleAlignment = titleAlignment; + + RenderBox? get leading => childForSlot(_ListTileSlot.leading); + RenderBox? get title => childForSlot(_ListTileSlot.title); + RenderBox? get subtitle => childForSlot(_ListTileSlot.subtitle); + RenderBox? get trailing => childForSlot(_ListTileSlot.trailing); + + // The returned list is ordered for hit testing. + @override + Iterable<RenderBox> get children { + return <RenderBox>[ + if (leading != null) + leading!, + if (title != null) + title!, + if (subtitle != null) + subtitle!, + if (trailing != null) + trailing!, + ]; + } + + bool get isDense => _isDense; + bool _isDense; + set isDense(bool value) { + if (_isDense == value) { + return; + } + _isDense = value; + markNeedsLayout(); + } + + VisualDensity get visualDensity => _visualDensity; + VisualDensity _visualDensity; + set visualDensity(VisualDensity value) { + if (_visualDensity == value) { + return; + } + _visualDensity = value; + markNeedsLayout(); + } + + bool get isThreeLine => _isThreeLine; + bool _isThreeLine; + set isThreeLine(bool value) { + if (_isThreeLine == value) { + return; + } + _isThreeLine = value; + markNeedsLayout(); + } + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsLayout(); + } + + TextBaseline get titleBaselineType => _titleBaselineType; + TextBaseline _titleBaselineType; + set titleBaselineType(TextBaseline value) { + if (_titleBaselineType == value) { + return; + } + _titleBaselineType = value; + markNeedsLayout(); + } + + TextBaseline? get subtitleBaselineType => _subtitleBaselineType; + TextBaseline? _subtitleBaselineType; + set subtitleBaselineType(TextBaseline? value) { + if (_subtitleBaselineType == value) { + return; + } + _subtitleBaselineType = value; + markNeedsLayout(); + } + + double get horizontalTitleGap => _horizontalTitleGap; + double _horizontalTitleGap; + double get _effectiveHorizontalTitleGap => _horizontalTitleGap + visualDensity.horizontal * 2.0; + + set horizontalTitleGap(double value) { + if (_horizontalTitleGap == value) { + return; + } + _horizontalTitleGap = value; + markNeedsLayout(); + } + + double get minVerticalPadding => _minVerticalPadding; + double _minVerticalPadding; + + set minVerticalPadding(double value) { + if (_minVerticalPadding == value) { + return; + } + _minVerticalPadding = value; + markNeedsLayout(); + } + + double get minLeadingWidth => _minLeadingWidth; + double _minLeadingWidth; + + set minLeadingWidth(double value) { + if (_minLeadingWidth == value) { + return; + } + _minLeadingWidth = value; + markNeedsLayout(); + } + + ListTileTitleAlignment get titleAlignment => _titleAlignment; + ListTileTitleAlignment _titleAlignment; + set titleAlignment(ListTileTitleAlignment value) { + if (_titleAlignment == value) { + return; + } + _titleAlignment = value; + markNeedsLayout(); + } + + @override + bool get sizedByParent => false; + + static double _minWidth(RenderBox? box, double height) { + return box == null ? 0.0 : box.getMinIntrinsicWidth(height); + } + + static double _maxWidth(RenderBox? box, double height) { + return box == null ? 0.0 : box.getMaxIntrinsicWidth(height); + } + + @override + double computeMinIntrinsicWidth(double height) { + final double leadingWidth = leading != null + ? math.max(leading!.getMinIntrinsicWidth(height), _minLeadingWidth) + _effectiveHorizontalTitleGap + : 0.0; + return leadingWidth + + math.max(_minWidth(title, height), _minWidth(subtitle, height)) + + _maxWidth(trailing, height); + } + + @override + double computeMaxIntrinsicWidth(double height) { + final double leadingWidth = leading != null + ? math.max(leading!.getMaxIntrinsicWidth(height), _minLeadingWidth) + _effectiveHorizontalTitleGap + : 0.0; + return leadingWidth + + math.max(_maxWidth(title, height), _maxWidth(subtitle, height)) + + _maxWidth(trailing, height); + } + + double get _defaultTileHeight { + final bool hasSubtitle = subtitle != null; + final bool isTwoLine = !isThreeLine && hasSubtitle; + final bool isOneLine = !isThreeLine && !hasSubtitle; + + final Offset baseDensity = visualDensity.baseSizeAdjustment; + if (isOneLine) { + return (isDense ? 48.0 : 56.0) + baseDensity.dy; + } + if (isTwoLine) { + return (isDense ? 64.0 : 72.0) + baseDensity.dy; + } + return (isDense ? 76.0 : 88.0) + baseDensity.dy; + } + + @override + double computeMinIntrinsicHeight(double width) { + return math.max( + _defaultTileHeight, + title!.getMinIntrinsicHeight(width) + (subtitle?.getMinIntrinsicHeight(width) ?? 0.0), + ); + } + + @override + double computeMaxIntrinsicHeight(double width) { + return computeMinIntrinsicHeight(width); + } + + @override + double computeDistanceToActualBaseline(TextBaseline baseline) { + assert(title != null); + final BoxParentData parentData = title!.parentData! as BoxParentData; + return parentData.offset.dy + title!.getDistanceToActualBaseline(baseline)!; + } + + static double? _boxBaseline(RenderBox box, TextBaseline baseline) { + return box.getDistanceToBaseline(baseline); + } + + static Size _layoutBox(RenderBox? box, BoxConstraints constraints) { + if (box == null) { + return Size.zero; + } + box.layout(constraints, parentUsesSize: true); + return box.size; + } + + static void _positionBox(RenderBox box, Offset offset) { + final BoxParentData parentData = box.parentData! as BoxParentData; + parentData.offset = offset; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + assert(debugCannotComputeDryLayout( + reason: 'Layout requires baseline metrics, which are only available after a full layout.', + )); + return Size.zero; + } + + // All of the dimensions below were taken from the Material Design spec: + // https://material.io/design/components/lists.html#specs + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + final bool hasLeading = leading != null; + final bool hasSubtitle = subtitle != null; + final bool hasTrailing = trailing != null; + final bool isTwoLine = !isThreeLine && hasSubtitle; + final bool isOneLine = !isThreeLine && !hasSubtitle; + final Offset densityAdjustment = visualDensity.baseSizeAdjustment; + + final BoxConstraints maxIconHeightConstraint = BoxConstraints( + // One-line trailing and leading widget heights do not follow + // Material specifications, but this sizing is required to adhere + // to accessibility requirements for smallest tappable widget. + // Two- and three-line trailing widget heights are constrained + // properly according to the Material spec. + maxHeight: (isDense ? 48.0 : 56.0) + densityAdjustment.dy, + ); + final BoxConstraints looseConstraints = constraints.loosen(); + final BoxConstraints iconConstraints = looseConstraints.enforce(maxIconHeightConstraint); + + final double tileWidth = looseConstraints.maxWidth; + final Size leadingSize = _layoutBox(leading, iconConstraints); + final Size trailingSize = _layoutBox(trailing, iconConstraints); + assert( + tileWidth != leadingSize.width || tileWidth == 0.0, + 'Leading widget consumes entire tile width. Please use a sized widget, ' + 'or consider replacing ListTile with a custom widget ' + '(see https://api.flutter.dev/flutter/material/ListTile-class.html#material.ListTile.4)', + ); + assert( + tileWidth != trailingSize.width || tileWidth == 0.0, + 'Trailing widget consumes entire tile width. Please use a sized widget, ' + 'or consider replacing ListTile with a custom widget ' + '(see https://api.flutter.dev/flutter/material/ListTile-class.html#material.ListTile.4)', + ); + + final double titleStart = hasLeading + ? math.max(_minLeadingWidth, leadingSize.width) + _effectiveHorizontalTitleGap + : 0.0; + final double adjustedTrailingWidth = hasTrailing + ? math.max(trailingSize.width + _effectiveHorizontalTitleGap, 32.0) + : 0.0; + final BoxConstraints textConstraints = looseConstraints.tighten( + width: tileWidth - titleStart - adjustedTrailingWidth, + ); + final Size titleSize = _layoutBox(title, textConstraints); + final Size subtitleSize = _layoutBox(subtitle, textConstraints); + + double? titleBaseline; + double? subtitleBaseline; + if (isTwoLine) { + titleBaseline = isDense ? 28.0 : 32.0; + subtitleBaseline = isDense ? 48.0 : 52.0; + } else if (isThreeLine) { + titleBaseline = isDense ? 22.0 : 28.0; + subtitleBaseline = isDense ? 42.0 : 48.0; + } else { + assert(isOneLine); + } + + final double defaultTileHeight = _defaultTileHeight; + + double tileHeight; + double titleY; + double? subtitleY; + if (!hasSubtitle) { + tileHeight = math.max(defaultTileHeight, titleSize.height + 2.0 * _minVerticalPadding); + titleY = (tileHeight - titleSize.height) / 2.0; + } else { + assert(subtitleBaselineType != null); + titleY = titleBaseline! - _boxBaseline(title!, titleBaselineType)!; + subtitleY = subtitleBaseline! - _boxBaseline(subtitle!, subtitleBaselineType!)! + visualDensity.vertical * 2.0; + tileHeight = defaultTileHeight; + + // If the title and subtitle overlap, move the title upwards by half + // the overlap and the subtitle down by the same amount, and adjust + // tileHeight so that both titles fit. + final double titleOverlap = titleY + titleSize.height - subtitleY; + if (titleOverlap > 0.0) { + titleY -= titleOverlap / 2.0; + subtitleY += titleOverlap / 2.0; + } + + // If the title or subtitle overflow tileHeight then punt: title + // and subtitle are arranged in a column, tileHeight = column height plus + // _minVerticalPadding on top and bottom. + if (titleY < _minVerticalPadding || + (subtitleY + subtitleSize.height + _minVerticalPadding) > tileHeight) { + tileHeight = titleSize.height + subtitleSize.height + 2.0 * _minVerticalPadding; + titleY = _minVerticalPadding; + subtitleY = titleSize.height + _minVerticalPadding; + } + } + + final double leadingY; + final double trailingY; + + switch (titleAlignment) { + case ListTileTitleAlignment.threeLine: { + if (isThreeLine) { + leadingY = _minVerticalPadding; + trailingY = _minVerticalPadding; + } else { + leadingY = (tileHeight - leadingSize.height) / 2.0; + trailingY = (tileHeight - trailingSize.height) / 2.0; + } + break; + } + case ListTileTitleAlignment.titleHeight: { + // This attempts to implement the redlines for the vertical position of the + // leading and trailing icons on the spec page: + // https://m2.material.io/components/lists#specs + // The interpretation for these redlines is as follows: + // - For large tiles (> 72dp), both leading and trailing controls should be + // a fixed distance from top. As per guidelines this is set to 16dp. + // - For smaller tiles, trailing should always be centered. Leading can be + // centered or closer to the top. It should never be further than 16dp + // to the top. + if (tileHeight > 72.0) { + leadingY = 16.0; + trailingY = 16.0; + } else { + leadingY = math.min((tileHeight - leadingSize.height) / 2.0, 16.0); + trailingY = (tileHeight - trailingSize.height) / 2.0; + } + break; + } + case ListTileTitleAlignment.top: { + leadingY = _minVerticalPadding; + trailingY = _minVerticalPadding; + break; + } + case ListTileTitleAlignment.center: { + leadingY = (tileHeight - leadingSize.height) / 2.0; + trailingY = (tileHeight - trailingSize.height) / 2.0; + break; + } + case ListTileTitleAlignment.bottom: { + leadingY = tileHeight - leadingSize.height - _minVerticalPadding; + trailingY = tileHeight - trailingSize.height - _minVerticalPadding; + break; + } + } + + switch (textDirection) { + case TextDirection.rtl: { + if (hasLeading) { + _positionBox(leading!, Offset(tileWidth - leadingSize.width, leadingY)); + } + _positionBox(title!, Offset(adjustedTrailingWidth, titleY)); + if (hasSubtitle) { + _positionBox(subtitle!, Offset(adjustedTrailingWidth, subtitleY!)); + } + if (hasTrailing) { + _positionBox(trailing!, Offset(0.0, trailingY)); + } + break; + } + case TextDirection.ltr: { + if (hasLeading) { + _positionBox(leading!, Offset(0.0, leadingY)); + } + _positionBox(title!, Offset(titleStart, titleY)); + if (hasSubtitle) { + _positionBox(subtitle!, Offset(titleStart, subtitleY!)); + } + if (hasTrailing) { + _positionBox(trailing!, Offset(tileWidth - trailingSize.width, trailingY)); + } + break; + } + } + + size = constraints.constrain(Size(tileWidth, tileHeight)); + assert(size.width == constraints.constrainWidth(tileWidth)); + assert(size.height == constraints.constrainHeight(tileHeight)); + } + + @override + void paint(PaintingContext context, Offset offset) { + void doPaint(RenderBox? child) { + if (child != null) { + final BoxParentData parentData = child.parentData! as BoxParentData; + context.paintChild(child, parentData.offset + offset); + } + } + doPaint(leading); + doPaint(title); + doPaint(subtitle); + doPaint(trailing); + } + + @override + bool hitTestSelf(Offset position) => true; + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + for (final RenderBox child in children) { + final BoxParentData parentData = child.parentData! as BoxParentData; + final bool isHit = result.addWithPaintOffset( + offset: parentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - parentData.offset); + return child.hitTest(result, position: transformed); + }, + ); + if (isHit) { + return true; + } + } + return false; + } +} + +class _LisTileDefaultsM2 extends ListTileThemeData { + _LisTileDefaultsM2(this.context, ListTileStyle style) + : super( + contentPadding: const EdgeInsets.symmetric(horizontal: 16.0), + minLeadingWidth: 40, + minVerticalPadding: 4, + shape: const Border(), + style: style, + ); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final TextTheme _textTheme = _theme.textTheme; + + @override + Color? get tileColor => Colors.transparent; + + @override + TextStyle? get titleTextStyle { + switch (style!) { + case ListTileStyle.drawer: + return _textTheme.bodyLarge; + case ListTileStyle.list: + return _textTheme.titleMedium; + } + } + + @override + TextStyle? get subtitleTextStyle => _textTheme.bodyMedium! + .copyWith(color: _textTheme.bodySmall!.color); + + @override + TextStyle? get leadingAndTrailingTextStyle => _textTheme.bodyMedium; + + @override + Color? get selectedColor => _theme.colorScheme.primary; + + @override + Color? get iconColor { + switch (_theme.brightness) { + case Brightness.light: + // For the sake of backwards compatibility, the default for unselected + // tiles is Colors.black45 rather than colorScheme.onSurface.withAlpha(0x73). + return Colors.black45; + case Brightness.dark: + return null; // null, Use current icon theme color + } + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - LisTile + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _LisTileDefaultsM3 extends ListTileThemeData { + _LisTileDefaultsM3(this.context) + : super( + contentPadding: const EdgeInsetsDirectional.only(start: 16.0, end: 24.0), + minLeadingWidth: 24, + minVerticalPadding: 8, + shape: const RoundedRectangleBorder(), + ); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + late final TextTheme _textTheme = _theme.textTheme; + + @override + Color? get tileColor => Colors.transparent; + + @override + TextStyle? get titleTextStyle => _textTheme.bodyLarge!.copyWith(color: _colors.onSurface); + + @override + TextStyle? get subtitleTextStyle => _textTheme.bodyMedium!.copyWith(color: _colors.onSurfaceVariant); + + @override + TextStyle? get leadingAndTrailingTextStyle => _textTheme.labelSmall!.copyWith(color: _colors.onSurfaceVariant); + + @override + Color? get selectedColor => _colors.primary; + + @override + Color? get iconColor => _colors.onSurfaceVariant; +} + +// END GENERATED TOKEN PROPERTIES - LisTile diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/list_tile_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/list_tile_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..3b77ffd97997e5a49e1b90eb8bcfd764f6945663 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/list_tile_theme.dart @@ -0,0 +1,552 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'list_tile.dart'; +import 'material_state.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Used with [ListTileTheme] to define default property values for +/// descendant [ListTile] widgets, as well as classes that build +/// [ListTile]s, like [CheckboxListTile], [RadioListTile], and +/// [SwitchListTile]. +/// +/// Descendant widgets obtain the current [ListTileThemeData] object +/// using `ListTileTheme.of(context)`. Instances of +/// [ListTileThemeData] can be customized with +/// [ListTileThemeData.copyWith]. +/// +/// A [ListTileThemeData] is often specified as part of the +/// overall [Theme] with [ThemeData.listTileTheme]. +/// +/// All [ListTileThemeData] properties are `null` by default. +/// When a theme property is null, the [ListTile] will provide its own +/// default based on the overall [Theme]'s textTheme and +/// colorScheme. See the individual [ListTile] properties for details. +/// +/// The [Drawer] widget specifies a list tile theme for its children that +/// defines [style] to be [ListTileStyle.drawer]. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class ListTileThemeData with Diagnosticable { + /// Creates a [ListTileThemeData]. + const ListTileThemeData ({ + this.dense, + this.shape, + this.style, + this.selectedColor, + this.iconColor, + this.textColor, + this.titleTextStyle, + this.subtitleTextStyle, + this.leadingAndTrailingTextStyle, + this.contentPadding, + this.tileColor, + this.selectedTileColor, + this.horizontalTitleGap, + this.minVerticalPadding, + this.minLeadingWidth, + this.enableFeedback, + this.mouseCursor, + this.visualDensity, + this.titleAlignment, + }); + + /// Overrides the default value of [ListTile.dense]. + final bool? dense; + + /// Overrides the default value of [ListTile.shape]. + final ShapeBorder? shape; + + /// Overrides the default value of [ListTile.style]. + final ListTileStyle? style; + + /// Overrides the default value of [ListTile.selectedColor]. + final Color? selectedColor; + + /// Overrides the default value of [ListTile.iconColor]. + final Color? iconColor; + + /// Overrides the default value of [ListTile.textColor]. + final Color? textColor; + + /// Overrides the default value of [ListTile.titleTextStyle]. + final TextStyle? titleTextStyle; + + /// Overrides the default value of [ListTile.subtitleTextStyle]. + final TextStyle? subtitleTextStyle; + + /// Overrides the default value of [ListTile.leadingAndTrailingTextStyle]. + final TextStyle? leadingAndTrailingTextStyle; + + /// Overrides the default value of [ListTile.contentPadding]. + final EdgeInsetsGeometry? contentPadding; + + /// Overrides the default value of [ListTile.tileColor]. + final Color? tileColor; + + /// Overrides the default value of [ListTile.selectedTileColor]. + final Color? selectedTileColor; + + /// Overrides the default value of [ListTile.horizontalTitleGap]. + final double? horizontalTitleGap; + + /// Overrides the default value of [ListTile.minVerticalPadding]. + final double? minVerticalPadding; + + /// Overrides the default value of [ListTile.minLeadingWidth]. + final double? minLeadingWidth; + + /// Overrides the default value of [ListTile.enableFeedback]. + final bool? enableFeedback; + + /// If specified, overrides the default value of [ListTile.mouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// If specified, overrides the default value of [ListTile.visualDensity]. + final VisualDensity? visualDensity; + + /// If specified, overrides the default value of [ListTile.titleAlignment]. + final ListTileTitleAlignment? titleAlignment; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + ListTileThemeData copyWith({ + bool? dense, + ShapeBorder? shape, + ListTileStyle? style, + Color? selectedColor, + Color? iconColor, + Color? textColor, + TextStyle? titleTextStyle, + TextStyle? subtitleTextStyle, + TextStyle? leadingAndTrailingTextStyle, + EdgeInsetsGeometry? contentPadding, + Color? tileColor, + Color? selectedTileColor, + double? horizontalTitleGap, + double? minVerticalPadding, + double? minLeadingWidth, + bool? enableFeedback, + MaterialStateProperty<MouseCursor?>? mouseCursor, + bool? isThreeLine, + VisualDensity? visualDensity, + ListTileTitleAlignment? titleAlignment, + }) { + return ListTileThemeData( + dense: dense ?? this.dense, + shape: shape ?? this.shape, + style: style ?? this.style, + selectedColor: selectedColor ?? this.selectedColor, + iconColor: iconColor ?? this.iconColor, + textColor: textColor ?? this.textColor, + titleTextStyle: titleTextStyle ?? this.titleTextStyle, + subtitleTextStyle: subtitleTextStyle ?? this.subtitleTextStyle, + leadingAndTrailingTextStyle: leadingAndTrailingTextStyle ?? this.leadingAndTrailingTextStyle, + contentPadding: contentPadding ?? this.contentPadding, + tileColor: tileColor ?? this.tileColor, + selectedTileColor: selectedTileColor ?? this.selectedTileColor, + horizontalTitleGap: horizontalTitleGap ?? this.horizontalTitleGap, + minVerticalPadding: minVerticalPadding ?? this.minVerticalPadding, + minLeadingWidth: minLeadingWidth ?? this.minLeadingWidth, + enableFeedback: enableFeedback ?? this.enableFeedback, + mouseCursor: mouseCursor ?? this.mouseCursor, + visualDensity: visualDensity ?? this.visualDensity, + titleAlignment: titleAlignment ?? this.titleAlignment, + ); + } + + /// Linearly interpolate between ListTileThemeData objects. + static ListTileThemeData? lerp(ListTileThemeData? a, ListTileThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return ListTileThemeData( + dense: t < 0.5 ? a?.dense : b?.dense, + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + style: t < 0.5 ? a?.style : b?.style, + selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t), + iconColor: Color.lerp(a?.iconColor, b?.iconColor, t), + textColor: Color.lerp(a?.textColor, b?.textColor, t), + titleTextStyle: TextStyle.lerp(a?.titleTextStyle, b?.titleTextStyle, t), + subtitleTextStyle: TextStyle.lerp(a?.subtitleTextStyle, b?.subtitleTextStyle, t), + leadingAndTrailingTextStyle: TextStyle.lerp(a?.leadingAndTrailingTextStyle, b?.leadingAndTrailingTextStyle, t), + contentPadding: EdgeInsetsGeometry.lerp(a?.contentPadding, b?.contentPadding, t), + tileColor: Color.lerp(a?.tileColor, b?.tileColor, t), + selectedTileColor: Color.lerp(a?.selectedTileColor, b?.selectedTileColor, t), + horizontalTitleGap: lerpDouble(a?.horizontalTitleGap, b?.horizontalTitleGap, t), + minVerticalPadding: lerpDouble(a?.minVerticalPadding, b?.minVerticalPadding, t), + minLeadingWidth: lerpDouble(a?.minLeadingWidth, b?.minLeadingWidth, t), + enableFeedback: t < 0.5 ? a?.enableFeedback : b?.enableFeedback, + mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, + visualDensity: t < 0.5 ? a?.visualDensity : b?.visualDensity, + titleAlignment: t < 0.5 ? a?.titleAlignment : b?.titleAlignment, + ); + } + + @override + int get hashCode => Object.hash( + dense, + shape, + style, + selectedColor, + iconColor, + textColor, + titleTextStyle, + subtitleTextStyle, + leadingAndTrailingTextStyle, + contentPadding, + tileColor, + selectedTileColor, + horizontalTitleGap, + minVerticalPadding, + minLeadingWidth, + enableFeedback, + mouseCursor, + visualDensity, + titleAlignment, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ListTileThemeData + && other.dense == dense + && other.shape == shape + && other.style == style + && other.selectedColor == selectedColor + && other.iconColor == iconColor + && other.titleTextStyle == titleTextStyle + && other.subtitleTextStyle == subtitleTextStyle + && other.leadingAndTrailingTextStyle == leadingAndTrailingTextStyle + && other.textColor == textColor + && other.contentPadding == contentPadding + && other.tileColor == tileColor + && other.selectedTileColor == selectedTileColor + && other.horizontalTitleGap == horizontalTitleGap + && other.minVerticalPadding == minVerticalPadding + && other.minLeadingWidth == minLeadingWidth + && other.enableFeedback == enableFeedback + && other.mouseCursor == mouseCursor + && other.visualDensity == visualDensity + && other.titleAlignment == titleAlignment; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('dense', dense, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(EnumProperty<ListTileStyle>('style', style, defaultValue: null)); + properties.add(ColorProperty('selectedColor', selectedColor, defaultValue: null)); + properties.add(ColorProperty('iconColor', iconColor, defaultValue: null)); + properties.add(ColorProperty('textColor', textColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('titleTextStyle', titleTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('subtitleTextStyle', subtitleTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('leadingAndTrailingTextStyle', leadingAndTrailingTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('contentPadding', contentPadding, defaultValue: null)); + properties.add(ColorProperty('tileColor', tileColor, defaultValue: null)); + properties.add(ColorProperty('selectedTileColor', selectedTileColor, defaultValue: null)); + properties.add(DoubleProperty('horizontalTitleGap', horizontalTitleGap, defaultValue: null)); + properties.add(DoubleProperty('minVerticalPadding', minVerticalPadding, defaultValue: null)); + properties.add(DoubleProperty('minLeadingWidth', minLeadingWidth, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('enableFeedback', enableFeedback, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null)); + properties.add(DiagnosticsProperty<VisualDensity>('visualDensity', visualDensity, defaultValue: null)); + properties.add(DiagnosticsProperty<ListTileTitleAlignment>('titleAlignment', titleAlignment, defaultValue: null)); + } +} + +/// An inherited widget that defines color and style parameters for [ListTile]s +/// in this widget's subtree. +/// +/// Values specified here are used for [ListTile] properties that are not given +/// an explicit non-null value. +/// +/// The [Drawer] widget specifies a tile theme for its children which sets +/// [style] to [ListTileStyle.drawer]. +class ListTileTheme extends InheritedTheme { + /// Creates a list tile theme that defines the color and style parameters for + /// descendant [ListTile]s. + /// + /// Only the [data] parameter should be used. The other parameters are + /// redundant (are now obsolete) and will be deprecated in a future update. + const ListTileTheme({ + super.key, + ListTileThemeData? data, + bool? dense, + ShapeBorder? shape, + ListTileStyle? style, + Color? selectedColor, + Color? iconColor, + Color? textColor, + EdgeInsetsGeometry? contentPadding, + Color? tileColor, + Color? selectedTileColor, + bool? enableFeedback, + MaterialStateProperty<MouseCursor?>? mouseCursor, + double? horizontalTitleGap, + double? minVerticalPadding, + double? minLeadingWidth, + required super.child, + }) : assert( + data == null || + (shape ?? + selectedColor ?? + iconColor ?? + textColor ?? + contentPadding ?? + tileColor ?? + selectedTileColor ?? + enableFeedback ?? + mouseCursor ?? + horizontalTitleGap ?? + minVerticalPadding ?? + minLeadingWidth) == null), + _data = data, + _dense = dense, + _shape = shape, + _style = style, + _selectedColor = selectedColor, + _iconColor = iconColor, + _textColor = textColor, + _contentPadding = contentPadding, + _tileColor = tileColor, + _selectedTileColor = selectedTileColor, + _enableFeedback = enableFeedback, + _mouseCursor = mouseCursor, + _horizontalTitleGap = horizontalTitleGap, + _minVerticalPadding = minVerticalPadding, + _minLeadingWidth = minLeadingWidth; + + final ListTileThemeData? _data; + final bool? _dense; + final ShapeBorder? _shape; + final ListTileStyle? _style; + final Color? _selectedColor; + final Color? _iconColor; + final Color? _textColor; + final EdgeInsetsGeometry? _contentPadding; + final Color? _tileColor; + final Color? _selectedTileColor; + final double? _horizontalTitleGap; + final double? _minVerticalPadding; + final double? _minLeadingWidth; + final bool? _enableFeedback; + final MaterialStateProperty<MouseCursor?>? _mouseCursor; + + /// The configuration of this theme. + ListTileThemeData get data { + return _data ?? ListTileThemeData( + dense: _dense, + shape: _shape, + style: _style, + selectedColor: _selectedColor, + iconColor: _iconColor, + textColor: _textColor, + contentPadding: _contentPadding, + tileColor: _tileColor, + selectedTileColor: _selectedTileColor, + enableFeedback: _enableFeedback, + mouseCursor: _mouseCursor, + horizontalTitleGap: _horizontalTitleGap, + minVerticalPadding: _minVerticalPadding, + minLeadingWidth: _minLeadingWidth, + ); + } + + /// Overrides the default value of [ListTile.dense]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.dense] property instead. + bool? get dense => _data != null ? _data.dense : _dense; + + /// Overrides the default value of [ListTile.shape]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.shape] property instead. + ShapeBorder? get shape => _data != null ? _data.shape : _shape; + + /// Overrides the default value of [ListTile.style]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.style] property instead. + ListTileStyle? get style => _data != null ? _data.style : _style; + + /// Overrides the default value of [ListTile.selectedColor]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.selectedColor] property instead. + Color? get selectedColor => _data != null ? _data.selectedColor : _selectedColor; + + /// Overrides the default value of [ListTile.iconColor]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.iconColor] property instead. + Color? get iconColor => _data != null ? _data.iconColor : _iconColor; + + /// Overrides the default value of [ListTile.textColor]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.textColor] property instead. + Color? get textColor => _data != null ? _data.textColor : _textColor; + + /// Overrides the default value of [ListTile.contentPadding]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.contentPadding] property instead. + EdgeInsetsGeometry? get contentPadding => _data != null ? _data.contentPadding : _contentPadding; + + /// Overrides the default value of [ListTile.tileColor]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.tileColor] property instead. + Color? get tileColor => _data != null ? _data.tileColor : _tileColor; + + /// Overrides the default value of [ListTile.selectedTileColor]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.selectedTileColor] property instead. + Color? get selectedTileColor => _data != null ? _data.selectedTileColor : _selectedTileColor; + + /// Overrides the default value of [ListTile.horizontalTitleGap]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.horizontalTitleGap] property instead. + double? get horizontalTitleGap => _data != null ? _data.horizontalTitleGap : _horizontalTitleGap; + + /// Overrides the default value of [ListTile.minVerticalPadding]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.minVerticalPadding] property instead. + double? get minVerticalPadding => _data != null ? _data.minVerticalPadding : _minVerticalPadding; + + /// Overrides the default value of [ListTile.minLeadingWidth]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.minLeadingWidth] property instead. + double? get minLeadingWidth => _data != null ? _data.minLeadingWidth : _minLeadingWidth; + + /// Overrides the default value of [ListTile.enableFeedback]. + /// + /// This property is obsolete: please use the [data] + /// [ListTileThemeData.enableFeedback] property instead. + bool? get enableFeedback => _data != null ? _data.enableFeedback : _enableFeedback; + + /// The [data] property of the closest instance of this class that + /// encloses the given context. + /// + /// If there is no enclosing [ListTileTheme] widget, then + /// [ThemeData.listTileTheme] is used (see [Theme.of]). + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ListTileThemeData theme = ListTileTheme.of(context); + /// ``` + static ListTileThemeData of(BuildContext context) { + final ListTileTheme? result = context.dependOnInheritedWidgetOfExactType<ListTileTheme>(); + return result?.data ?? Theme.of(context).listTileTheme; + } + + /// Creates a list tile theme that controls the color and style parameters for + /// [ListTile]s, and merges in the current list tile theme, if any. + static Widget merge({ + Key? key, + bool? dense, + ShapeBorder? shape, + ListTileStyle? style, + Color? selectedColor, + Color? iconColor, + Color? textColor, + TextStyle? titleTextStyle, + TextStyle? subtitleTextStyle, + TextStyle? leadingAndTrailingTextStyle, + EdgeInsetsGeometry? contentPadding, + Color? tileColor, + Color? selectedTileColor, + bool? enableFeedback, + double? horizontalTitleGap, + double? minVerticalPadding, + double? minLeadingWidth, + ListTileTitleAlignment? titleAlignment, + MaterialStateProperty<MouseCursor?>? mouseCursor, + VisualDensity? visualDensity, + required Widget child, + }) { + return Builder( + builder: (BuildContext context) { + final ListTileThemeData parent = ListTileTheme.of(context); + return ListTileTheme( + key: key, + data: ListTileThemeData( + dense: dense ?? parent.dense, + shape: shape ?? parent.shape, + style: style ?? parent.style, + selectedColor: selectedColor ?? parent.selectedColor, + iconColor: iconColor ?? parent.iconColor, + textColor: textColor ?? parent.textColor, + titleTextStyle: titleTextStyle ?? parent.titleTextStyle, + subtitleTextStyle: subtitleTextStyle ?? parent.subtitleTextStyle, + leadingAndTrailingTextStyle: leadingAndTrailingTextStyle ?? parent.leadingAndTrailingTextStyle, + contentPadding: contentPadding ?? parent.contentPadding, + tileColor: tileColor ?? parent.tileColor, + selectedTileColor: selectedTileColor ?? parent.selectedTileColor, + enableFeedback: enableFeedback ?? parent.enableFeedback, + horizontalTitleGap: horizontalTitleGap ?? parent.horizontalTitleGap, + minVerticalPadding: minVerticalPadding ?? parent.minVerticalPadding, + minLeadingWidth: minLeadingWidth ?? parent.minLeadingWidth, + titleAlignment: titleAlignment ?? parent.titleAlignment, + mouseCursor: mouseCursor ?? parent.mouseCursor, + visualDensity: visualDensity ?? parent.visualDensity, + ), + child: child, + ); + }, + ); + } + + @override + Widget wrap(BuildContext context, Widget child) { + return ListTileTheme( + data: ListTileThemeData( + dense: dense, + shape: shape, + style: style, + selectedColor: selectedColor, + iconColor: iconColor, + textColor: textColor, + contentPadding: contentPadding, + tileColor: tileColor, + selectedTileColor: selectedTileColor, + enableFeedback: enableFeedback, + horizontalTitleGap: horizontalTitleGap, + minVerticalPadding: minVerticalPadding, + minLeadingWidth: minLeadingWidth, + ), + child: child, + ); + } + + @override + bool updateShouldNotify(ListTileTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/magnifier.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/magnifier.dart new file mode 100644 index 0000000000000000000000000000000000000000..6206d0e16b908d7cc86cceeea41b73d39a083d06 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/magnifier.dart @@ -0,0 +1,337 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; + +/// {@template widgets.material.magnifier.magnifier} +/// A [Magnifier] positioned by rules dictated by the native Android magnifier. +/// {@endtemplate} +/// +/// {@template widgets.material.magnifier.positionRules} +/// Positions itself based on [magnifierInfo]. Specifically, follows the +/// following rules: +/// - Tracks the gesture's x coordinate, but clamped to the beginning and end of the +/// currently editing line. +/// - Focal point may never contain anything out of bounds. +/// - Never goes out of bounds vertically; offset until the entire magnifier is in the screen. The +/// focal point, regardless of this transformation, always points to the touch y coordinate. +/// - If just jumped between lines (prevY != currentY) then animate for duration +/// [jumpBetweenLinesAnimationDuration]. +/// {@endtemplate} +class TextMagnifier extends StatefulWidget { + /// {@macro widgets.material.magnifier.magnifier} + /// + /// {@template widgets.material.magnifier.androidDisclaimer} + /// These constants and default parameters were taken from the + /// Android 12 source code where directly transferable, and eyeballed on + /// a Pixel 6 running Android 12 otherwise. + /// {@endtemplate} + /// + /// {@macro widgets.material.magnifier.positionRules} + const TextMagnifier({ + super.key, + required this.magnifierInfo, + }); + + /// A [TextMagnifierConfiguration] that returns a [CupertinoTextMagnifier] on iOS, + /// [TextMagnifier] on Android, and null on all other platforms, and shows the editing handles + /// only on iOS. + static TextMagnifierConfiguration adaptiveMagnifierConfiguration = TextMagnifierConfiguration( + shouldDisplayHandlesInMagnifier: defaultTargetPlatform == TargetPlatform.iOS, + magnifierBuilder: ( + BuildContext context, + MagnifierController controller, + ValueNotifier<MagnifierInfo> magnifierInfo, + ) { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + return CupertinoTextMagnifier( + controller: controller, + magnifierInfo: magnifierInfo, + ); + case TargetPlatform.android: + return TextMagnifier( + magnifierInfo: magnifierInfo, + ); + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return null; + } + } + ); + + /// The duration that the position is animated if [TextMagnifier] just switched + /// between lines. + @visibleForTesting + static const Duration jumpBetweenLinesAnimationDuration = + Duration(milliseconds: 70); + + /// [TextMagnifier] positions itself based on [magnifierInfo]. + /// + /// {@macro widgets.material.magnifier.positionRules} + final ValueNotifier<MagnifierInfo> + magnifierInfo; + + @override + State<TextMagnifier> createState() => _TextMagnifierState(); +} + +class _TextMagnifierState extends State<TextMagnifier> { + // Should _only_ be null on construction. This is because of the animation logic. + // + // Animations are added when `last_build_y != current_build_y`. This condition + // is true on the initial render, which would mean that the initial + // build would be animated - this is undesired. Thus, this is null for the + // first frame and the condition becomes `magnifierPosition != null && last_build_y != this_build_y`. + Offset? _magnifierPosition; + + // A timer that unsets itself after an animation duration. + // If the timer exists, then the magnifier animates its position - + // if this timer does not exist, the magnifier tracks the gesture (with respect + // to the positioning rules) directly. + Timer? _positionShouldBeAnimatedTimer; + bool get _positionShouldBeAnimated => _positionShouldBeAnimatedTimer != null; + + Offset _extraFocalPointOffset = Offset.zero; + + @override + void initState() { + super.initState(); + widget.magnifierInfo + .addListener(_determineMagnifierPositionAndFocalPoint); + } + + @override + void dispose() { + widget.magnifierInfo + .removeListener(_determineMagnifierPositionAndFocalPoint); + _positionShouldBeAnimatedTimer?.cancel(); + super.dispose(); + } + + @override + void didChangeDependencies() { + _determineMagnifierPositionAndFocalPoint(); + super.didChangeDependencies(); + } + + @override + void didUpdateWidget(TextMagnifier oldWidget) { + if (oldWidget.magnifierInfo != widget.magnifierInfo) { + oldWidget.magnifierInfo.removeListener(_determineMagnifierPositionAndFocalPoint); + widget.magnifierInfo.addListener(_determineMagnifierPositionAndFocalPoint); + } + super.didUpdateWidget(oldWidget); + } + + /// {@macro widgets.material.magnifier.positionRules} + void _determineMagnifierPositionAndFocalPoint() { + final MagnifierInfo selectionInfo = + widget.magnifierInfo.value; + final Rect screenRect = Offset.zero & MediaQuery.sizeOf(context); + + // Since by default we draw at the top left corner, this offset + // shifts the magnifier so we draw at the center, and then also includes + // the "above touch point" shift. + final Offset basicMagnifierOffset = Offset( + Magnifier.kDefaultMagnifierSize.width / 2, + Magnifier.kDefaultMagnifierSize.height + + Magnifier.kStandardVerticalFocalPointShift); + + // Since the magnifier should not go past the edges of the line, + // but must track the gesture otherwise, constrain the X of the magnifier + // to always stay between line start and end. + final double magnifierX = clampDouble( + selectionInfo.globalGesturePosition.dx, + selectionInfo.currentLineBoundaries.left, + selectionInfo.currentLineBoundaries.right); + + // Place the magnifier at the previously calculated X, and the Y should be + // exactly at the center of the handle. + final Rect unadjustedMagnifierRect = + Offset(magnifierX, selectionInfo.caretRect.center.dy) - basicMagnifierOffset & + Magnifier.kDefaultMagnifierSize; + + // Shift the magnifier so that, if we are ever out of the screen, we become in bounds. + // This probably won't have much of an effect on the X, since it is already bound + // to the currentLineBoundaries, but will shift vertically if the magnifier is out of bounds. + final Rect screenBoundsAdjustedMagnifierRect = + MagnifierController.shiftWithinBounds( + bounds: screenRect, rect: unadjustedMagnifierRect); + + // Done with the magnifier position! + final Offset finalMagnifierPosition = screenBoundsAdjustedMagnifierRect.topLeft; + + // The insets, from either edge, that the focal point should not point + // past lest the magnifier displays something out of bounds. + final double horizontalMaxFocalPointEdgeInsets = + (Magnifier.kDefaultMagnifierSize.width / 2) / Magnifier._magnification; + + // Adjust the focal point horizontally such that none of the magnifier + // ever points to anything out of bounds. + final double newGlobalFocalPointX; + + // If the text field is so narrow that we must show out of bounds, + // then settle for pointing to the center all the time. + if (selectionInfo.fieldBounds.width < + horizontalMaxFocalPointEdgeInsets * 2) { + newGlobalFocalPointX = selectionInfo.fieldBounds.center.dx; + } else { + // Otherwise, we can clamp the focal point to always point in bounds. + newGlobalFocalPointX = clampDouble( + screenBoundsAdjustedMagnifierRect.center.dx, + selectionInfo.fieldBounds.left + horizontalMaxFocalPointEdgeInsets, + selectionInfo.fieldBounds.right - horizontalMaxFocalPointEdgeInsets); + } + + // Since the previous value is now a global offset (i.e. `newGlobalFocalPoint` + // is now a global offset), we must subtract the magnifier's global offset + // to obtain the relative shift in the focal point. + final double newRelativeFocalPointX = + newGlobalFocalPointX - screenBoundsAdjustedMagnifierRect.center.dx; + + // The Y component means that if we are pressed up against the top of the screen, + // then we should adjust the focal point such that it now points to how far we moved + // the magnifier. screenBoundsAdjustedMagnifierRect.top == unadjustedMagnifierRect.top for most cases, + // but when pressed up against the top of the screen, we adjust the focal point by + // the amount that we shifted from our "natural" position. + final Offset focalPointAdjustmentForScreenBoundsAdjustment = Offset( + newRelativeFocalPointX, + unadjustedMagnifierRect.top - screenBoundsAdjustedMagnifierRect.top, + ); + + Timer? positionShouldBeAnimated = _positionShouldBeAnimatedTimer; + + if (_magnifierPosition != null && finalMagnifierPosition.dy != _magnifierPosition!.dy) { + if (_positionShouldBeAnimatedTimer != null && + _positionShouldBeAnimatedTimer!.isActive) { + _positionShouldBeAnimatedTimer!.cancel(); + } + + // Create a timer that deletes itself when the timer is complete. + // This is `mounted` safe, since the timer is canceled in `dispose`. + positionShouldBeAnimated = Timer( + TextMagnifier.jumpBetweenLinesAnimationDuration, + () => setState(() { + _positionShouldBeAnimatedTimer = null; + })); + } + + setState(() { + _magnifierPosition = finalMagnifierPosition; + _positionShouldBeAnimatedTimer = positionShouldBeAnimated; + _extraFocalPointOffset = focalPointAdjustmentForScreenBoundsAdjustment; + }); + } + + @override + Widget build(BuildContext context) { + assert(_magnifierPosition != null, + 'Magnifier position should only be null before the first build.'); + + return AnimatedPositioned( + top: _magnifierPosition!.dy, + left: _magnifierPosition!.dx, + // Material magnifier typically does not animate, unless we jump between lines, + // in which case we animate between lines. + duration: _positionShouldBeAnimated + ? TextMagnifier.jumpBetweenLinesAnimationDuration + : Duration.zero, + child: Magnifier( + additionalFocalPointOffset: _extraFocalPointOffset, + ), + ); + } +} + +/// A Material styled magnifying glass. +/// +/// {@macro flutter.widgets.magnifier.intro} +/// +/// This widget focuses on mimicking the _style_ of the magnifier on material. For a +/// widget that is focused on mimicking the behavior of a material magnifier, see [TextMagnifier]. +class Magnifier extends StatelessWidget { + /// Creates a [RawMagnifier] in the Material style. + /// + /// {@macro widgets.material.magnifier.androidDisclaimer} + const Magnifier({ + super.key, + this.additionalFocalPointOffset = Offset.zero, + this.borderRadius = const BorderRadius.all(Radius.circular(_borderRadius)), + this.filmColor = const Color.fromARGB(8, 158, 158, 158), + this.shadows = const <BoxShadow>[ + BoxShadow( + blurRadius: 1.5, + offset: Offset(0, 2), + spreadRadius: 0.75, + color: Color.fromARGB(25, 0, 0, 0)) + ], + this.size = Magnifier.kDefaultMagnifierSize, + }); + + /// The default size of this [Magnifier]. + /// + /// The size of the magnifier may be modified through the constructor; + /// [kDefaultMagnifierSize] is extracted from the default parameter of + /// [Magnifier]'s constructor so that positioners may depend on it. + @visibleForTesting + static const Size kDefaultMagnifierSize = Size(77.37, 37.9); + + /// The vertical distance that the magnifier should be above the focal point. + /// + /// [kStandardVerticalFocalPointShift] is an unmodifiable constant so that positioning of this + /// [Magnifier] can be done with a guaranteed size, as opposed to an estimate. + @visibleForTesting + static const double kStandardVerticalFocalPointShift = 22; + + static const double _borderRadius = 40; + static const double _magnification = 1.25; + + /// Any additional offset the focal point requires to "point" + /// to the correct place. + /// + /// This is useful for instances where the magnifier is not pointing to something + /// directly below it. + final Offset additionalFocalPointOffset; + + /// The border radius for this magnifier. + final BorderRadius borderRadius; + + /// The color to tint the image in this [Magnifier]. + /// + /// On native Android, there is a almost transparent gray tint to the + /// magnifier, in order to better distinguish the contents of the lens from + /// the background. + final Color filmColor; + + /// The shadows for this [Magnifier]. + final List<BoxShadow> shadows; + + /// The [Size] of this [Magnifier]. + /// + /// This size does not include the border. + final Size size; + + @override + Widget build(BuildContext context) { + return RawMagnifier( + decoration: MagnifierDecoration( + shape: RoundedRectangleBorder(borderRadius: borderRadius), + shadows: shadows, + ), + magnificationScale: _magnification, + focalPointOffset: additionalFocalPointOffset + + Offset(0, kStandardVerticalFocalPointShift + kDefaultMagnifierSize.height / 2), + size: size, + child: ColoredBox( + color: filmColor, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material.dart new file mode 100644 index 0000000000000000000000000000000000000000..891c2625be71fe742abc40eae505ecf350904d3b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material.dart @@ -0,0 +1,1018 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'constants.dart'; +import 'elevation_overlay.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Signature for the callback used by ink effects to obtain the rectangle for the effect. +/// +/// Used by [InkHighlight] and [InkSplash], for example. +typedef RectCallback = Rect Function(); + +/// The various kinds of material in Material Design. Used to +/// configure the default behavior of [Material] widgets. +/// +/// See also: +/// +/// * [Material], in particular [Material.type]. +/// * [kMaterialEdges] +enum MaterialType { + /// Rectangle using default theme canvas color. + canvas, + + /// Rounded edges, card theme color. + card, + + /// A circle, no color by default (used for floating action buttons). + circle, + + /// Rounded edges, no color by default (used for [MaterialButton] buttons). + button, + + /// A transparent piece of material that draws ink splashes and highlights. + /// + /// While the material metaphor describes child widgets as printed on the + /// material itself and do not hide ink effects, in practice the [Material] + /// widget draws child widgets on top of the ink effects. + /// A [Material] with type transparency can be placed on top of opaque widgets + /// to show ink effects on top of them. + /// + /// Prefer using the [Ink] widget for showing ink effects on top of opaque + /// widgets. + transparency +} + +/// The border radii used by the various kinds of material in Material Design. +/// +/// See also: +/// +/// * [MaterialType] +/// * [Material] +const Map<MaterialType, BorderRadius?> kMaterialEdges = <MaterialType, BorderRadius?>{ + MaterialType.canvas: null, + MaterialType.card: BorderRadius.all(Radius.circular(2.0)), + MaterialType.circle: null, + MaterialType.button: BorderRadius.all(Radius.circular(2.0)), + MaterialType.transparency: null, +}; + +/// An interface for creating [InkSplash]s and [InkHighlight]s on a [Material]. +/// +/// Typically obtained via [Material.of]. +abstract class MaterialInkController { + /// The color of the material. + Color? get color; + + /// The ticker provider used by the controller. + /// + /// Ink features that are added to this controller with [addInkFeature] should + /// use this vsync to drive their animations. + TickerProvider get vsync; + + /// Add an [InkFeature], such as an [InkSplash] or an [InkHighlight]. + /// + /// The ink feature will paint as part of this controller. + void addInkFeature(InkFeature feature); + + /// Notifies the controller that one of its ink features needs to repaint. + void markNeedsPaint(); +} + +/// A piece of material. +/// +/// The Material widget is responsible for: +/// +/// 1. Clipping: If [clipBehavior] is not [Clip.none], Material clips its widget +/// sub-tree to the shape specified by [shape], [type], and [borderRadius]. +/// By default, [clipBehavior] is [Clip.none] for performance considerations. +/// See [Ink] for an example of how this affects clipping [Ink] widgets. +/// 2. Elevation: Material elevates its widget sub-tree on the Z axis by +/// [elevation] pixels, and draws the appropriate shadow. +/// 3. Ink effects: Material shows ink effects implemented by [InkFeature]s +/// like [InkSplash] and [InkHighlight] below its children. +/// +/// ## The Material Metaphor +/// +/// Material is the central metaphor in Material Design. Each piece of material +/// exists at a given elevation, which influences how that piece of material +/// visually relates to other pieces of material and how that material casts +/// shadows. +/// +/// Most user interface elements are either conceptually printed on a piece of +/// material or themselves made of material. Material reacts to user input using +/// [InkSplash] and [InkHighlight] effects. To trigger a reaction on the +/// material, use a [MaterialInkController] obtained via [Material.of]. +/// +/// In general, the features of a [Material] should not change over time (e.g. a +/// [Material] should not change its [color], [shadowColor] or [type]). +/// Changes to [elevation], [shadowColor] and [surfaceTintColor] are animated +/// for [animationDuration]. Changes to [shape] are animated if [type] is +/// not [MaterialType.transparency] and [ShapeBorder.lerp] between the previous +/// and next [shape] values is supported. Shape changes are also animated +/// for [animationDuration]. +/// +/// ## Shape +/// +/// The shape for material is determined by [shape], [type], and [borderRadius]. +/// +/// - If [shape] is non null, it determines the shape. +/// - If [shape] is null and [borderRadius] is non null, the shape is a +/// rounded rectangle, with corners specified by [borderRadius]. +/// - If [shape] and [borderRadius] are null, [type] determines the +/// shape as follows: +/// - [MaterialType.canvas]: the default material shape is a rectangle. +/// - [MaterialType.card]: the default material shape is a rectangle with +/// rounded edges. The edge radii is specified by [kMaterialEdges]. +/// - [MaterialType.circle]: the default material shape is a circle. +/// - [MaterialType.button]: the default material shape is a rectangle with +/// rounded edges. The edge radii is specified by [kMaterialEdges]. +/// - [MaterialType.transparency]: the default material shape is a rectangle. +/// +/// ## Border +/// +/// If [shape] is not null, then its border will also be painted (if any). +/// +/// ## Layout change notifications +/// +/// If the layout changes (e.g. because there's a list on the material, and it's +/// been scrolled), a [LayoutChangedNotification] must be dispatched at the +/// relevant subtree. This in particular means that transitions (e.g. +/// [SlideTransition]) should not be placed inside [Material] widgets so as to +/// move subtrees that contain [InkResponse]s, [InkWell]s, [Ink]s, or other +/// widgets that use the [InkFeature] mechanism. Otherwise, in-progress ink +/// features (e.g., ink splashes and ink highlights) won't move to account for +/// the new layout. +/// +/// ## Painting over the material +/// +/// Material widgets will often trigger reactions on their nearest material +/// ancestor. For example, [ListTile.hoverColor] triggers a reaction on the +/// tile's material when a pointer is hovering over it. These reactions will be +/// obscured if any widget in between them and the material paints in such a +/// way as to obscure the material (such as setting a [BoxDecoration.color] on +/// a [DecoratedBox]). To avoid this behavior, use [InkDecoration] to decorate +/// the material itself. +/// +/// See also: +/// +/// * [MergeableMaterial], a piece of material that can split and re-merge. +/// * [Card], a wrapper for a [Material] of [type] [MaterialType.card]. +/// * <https://material.io/design/> +/// * <https://m3.material.io/styles/color/the-color-system/color-roles> +class Material extends StatefulWidget { + /// Creates a piece of material. + /// + /// The [elevation] must be non-negative. + /// + /// If a [shape] is specified, then the [borderRadius] property must be + /// null and the [type] property must not be [MaterialType.circle]. If the + /// [borderRadius] is specified, then the [type] property must not be + /// [MaterialType.circle]. In both cases, these restrictions are intended to + /// catch likely errors. + const Material({ + super.key, + this.type = MaterialType.canvas, + this.elevation = 0.0, + this.color, + this.shadowColor, + this.surfaceTintColor, + this.textStyle, + this.borderRadius, + this.shape, + this.borderOnForeground = true, + this.clipBehavior = Clip.none, + this.animationDuration = kThemeChangeDuration, + this.child, + }) : assert(elevation >= 0.0), + assert(!(shape != null && borderRadius != null)), + assert(!(identical(type, MaterialType.circle) && (borderRadius != null || shape != null))); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The kind of material to show (e.g., card or canvas). This + /// affects the shape of the widget, the roundness of its corners if + /// the shape is rectangular, and the default color. + final MaterialType type; + + /// {@template flutter.material.material.elevation} + /// The z-coordinate at which to place this material relative to its parent. + /// + /// This controls the size of the shadow below the material and the opacity + /// of the elevation overlay color if it is applied. + /// + /// If this is non-zero, the contents of the material are clipped, because the + /// widget conceptually defines an independent printed piece of material. + /// + /// Defaults to 0. Changing this value will cause the shadow and the elevation + /// overlay or surface tint to animate over [Material.animationDuration]. + /// + /// The value is non-negative. + /// + /// See also: + /// + /// * [ThemeData.useMaterial3] which defines whether a surface tint or + /// elevation overlay is used to indicate elevation. + /// * [ThemeData.applyElevationOverlayColor] which controls the whether + /// an overlay color will be applied to indicate elevation. + /// * [Material.color] which may have an elevation overlay applied. + /// * [Material.shadowColor] which will be used for the color of a drop shadow. + /// * [Material.surfaceTintColor] which will be used as the overlay tint to + /// show elevation. + /// {@endtemplate} + final double elevation; + + /// The color to paint the material. + /// + /// Must be opaque. To create a transparent piece of material, use + /// [MaterialType.transparency]. + /// + /// If [ThemeData.useMaterial3] is true then an optional [surfaceTintColor] + /// overlay may be applied on top of this color to indicate elevation. + /// + /// If [ThemeData.useMaterial3] is false and [ThemeData.applyElevationOverlayColor] + /// is true and [ThemeData.brightness] is [Brightness.dark] then a + /// semi-transparent overlay color will be composited on top of this + /// color to indicate the elevation. This is no longer needed for Material + /// Design 3, which uses [surfaceTintColor]. + /// + /// By default, the color is derived from the [type] of material. + final Color? color; + + /// The color to paint the shadow below the material. + /// + /// {@template flutter.material.material.shadowColor} + /// If null and [ThemeData.useMaterial3] is true then [ThemeData]'s + /// [ColorScheme.shadow] will be used. If [ThemeData.useMaterial3] is false + /// then [ThemeData.shadowColor] will be used. + /// + /// To remove the drop shadow when [elevation] is greater than 0, set + /// [shadowColor] to [Colors.transparent]. + /// + /// See also: + /// * [ThemeData.useMaterial3], which determines the default value for this + /// property if it is null. + /// * [ThemeData.applyElevationOverlayColor], which turns elevation overlay + /// on or off for dark themes. + /// {@endtemplate} + final Color? shadowColor; + + /// The color of the surface tint overlay applied to the material color + /// to indicate elevation. + /// + /// {@template flutter.material.material.surfaceTintColor} + /// Material Design 3 introduced a new way for some components to indicate + /// their elevation by using a surface tint color overlay on top of the + /// base material [color]. This overlay is painted with an opacity that is + /// related to the [elevation] of the material. + /// + /// If [ThemeData.useMaterial3] is false, then this property is not used. + /// + /// If [ThemeData.useMaterial3] is true and [surfaceTintColor] is not null and + /// not [Colors.transparent], then it will be used to overlay the base [color] + /// with an opacity based on the [elevation]. + /// + /// Otherwise, no surface tint will be applied. + /// + /// See also: + /// + /// * [ThemeData.useMaterial3], which turns this feature on. + /// * [ElevationOverlay.applySurfaceTint], which is used to implement the + /// tint. + /// * https://m3.material.io/styles/color/the-color-system/color-roles + /// which specifies how the overlay is applied. + /// {@endtemplate} + final Color? surfaceTintColor; + + /// The typographical style to use for text within this material. + final TextStyle? textStyle; + + /// Defines the material's shape as well its shadow. + /// + /// {@template flutter.material.material.shape} + /// If shape is non null, the [borderRadius] is ignored and the material's + /// clip boundary and shadow are defined by the shape. + /// + /// A shadow is only displayed if the [elevation] is greater than + /// zero. + /// {@endtemplate} + final ShapeBorder? shape; + + /// Whether to paint the [shape] border in front of the [child]. + /// + /// The default value is true. + /// If false, the border will be painted behind the [child]. + final bool borderOnForeground; + + /// {@template flutter.material.Material.clipBehavior} + /// The content will be clipped (or not) according to this option. + /// + /// See the enum [Clip] for details of all possible options and their common + /// use cases. + /// {@endtemplate} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// Defines the duration of animated changes for [shape], [elevation], + /// [shadowColor], [surfaceTintColor] and the elevation overlay if it is applied. + /// + /// The default value is [kThemeChangeDuration]. + final Duration animationDuration; + + /// If non-null, the corners of this box are rounded by this + /// [BorderRadiusGeometry] value. + /// + /// Otherwise, the corners specified for the current [type] of material are + /// used. + /// + /// If [shape] is non null then the border radius is ignored. + /// + /// Must be null if [type] is [MaterialType.circle]. + final BorderRadiusGeometry? borderRadius; + + /// The ink controller from the closest instance of this class that + /// encloses the given context within the closest [LookupBoundary]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// MaterialInkController? inkController = Material.maybeOf(context); + /// ``` + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [Material.of], which is similar to this method, but asserts if + /// no [Material] ancestor is found. + static MaterialInkController? maybeOf(BuildContext context) { + return LookupBoundary.findAncestorRenderObjectOfType<_RenderInkFeatures>(context); + } + + /// The ink controller from the closest instance of [Material] that encloses + /// the given context within the closest [LookupBoundary]. + /// + /// If no [Material] widget ancestor can be found then this method will assert + /// in debug mode, and throw an exception in release mode. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// MaterialInkController inkController = Material.of(context); + /// ``` + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [Material.maybeOf], which is similar to this method, but returns null if + /// no [Material] ancestor is found. + static MaterialInkController of(BuildContext context) { + final MaterialInkController? controller = maybeOf(context); + assert(() { + if (controller == null) { + if (LookupBoundary.debugIsHidingAncestorRenderObjectOfType<_RenderInkFeatures>(context)) { + throw FlutterError( + 'Material.of() was called with a context that does not have access to a Material widget.\n' + 'The context provided to Material.of() does have a Material widget ancestor, but it is ' + 'hidden by a LookupBoundary. This can happen because you are using a widget that looks ' + 'for a Material ancestor, but no such ancestor exists within the closest LookupBoundary.\n' + 'The context used was:\n' + ' $context', + ); + } + throw FlutterError( + 'Material.of() was called with a context that does not contain a Material widget.\n' + 'No Material widget ancestor could be found starting from the context that was passed to ' + 'Material.of(). This can happen because you are using a widget that looks for a Material ' + 'ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return controller!; + } + + @override + State<Material> createState() => _MaterialState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<MaterialType>('type', type)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: 0.0)); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + textStyle?.debugFillProperties(properties, prefix: 'textStyle.'); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('borderOnForeground', borderOnForeground, defaultValue: true)); + properties.add(DiagnosticsProperty<BorderRadiusGeometry>('borderRadius', borderRadius, defaultValue: null)); + } + + /// The default radius of an ink splash in logical pixels. + static const double defaultSplashRadius = 35.0; +} + +class _MaterialState extends State<Material> with TickerProviderStateMixin { + final GlobalKey _inkFeatureRenderer = GlobalKey(debugLabel: 'ink renderer'); + + Color? _getBackgroundColor(BuildContext context) { + final ThemeData theme = Theme.of(context); + Color? color = widget.color; + if (color == null) { + switch (widget.type) { + case MaterialType.canvas: + color = theme.canvasColor; + case MaterialType.card: + color = theme.cardColor; + case MaterialType.button: + case MaterialType.circle: + case MaterialType.transparency: + break; + } + } + return color; + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final Color? backgroundColor = _getBackgroundColor(context); + final Color modelShadowColor = widget.shadowColor ?? (theme.useMaterial3 ? theme.colorScheme.shadow : theme.shadowColor); + // If no shadow color is specified, use 0 for elevation in the model so a drop shadow won't be painted. + final double modelElevation = widget.elevation; + assert( + backgroundColor != null || widget.type == MaterialType.transparency, + 'If Material type is not MaterialType.transparency, a color must ' + 'either be passed in through the `color` property, or be defined ' + 'in the theme (ex. canvasColor != null if type is set to ' + 'MaterialType.canvas)', + ); + Widget? contents = widget.child; + if (contents != null) { + contents = AnimatedDefaultTextStyle( + style: widget.textStyle ?? Theme.of(context).textTheme.bodyMedium!, + duration: widget.animationDuration, + child: contents, + ); + } + contents = NotificationListener<LayoutChangedNotification>( + onNotification: (LayoutChangedNotification notification) { + final _RenderInkFeatures renderer = _inkFeatureRenderer.currentContext!.findRenderObject()! as _RenderInkFeatures; + renderer._didChangeLayout(); + return false; + }, + child: _InkFeatures( + key: _inkFeatureRenderer, + absorbHitTest: widget.type != MaterialType.transparency, + color: backgroundColor, + vsync: this, + child: contents, + ), + ); + + // PhysicalModel has a temporary workaround for a performance issue that + // speeds up rectangular non transparent material (the workaround is to + // skip the call to ui.Canvas.saveLayer if the border radius is 0). + // Until the saveLayer performance issue is resolved, we're keeping this + // special case here for canvas material type that is using the default + // shape (rectangle). We could go down this fast path for explicitly + // specified rectangles (e.g shape RoundedRectangleBorder with radius 0, but + // we choose not to as we want the change from the fast-path to the + // slow-path to be noticeable in the construction site of Material. + if (widget.type == MaterialType.canvas && widget.shape == null && widget.borderRadius == null) { + final Color color = Theme.of(context).useMaterial3 + ? ElevationOverlay.applySurfaceTint(backgroundColor!, widget.surfaceTintColor, widget.elevation) + : ElevationOverlay.applyOverlay(context, backgroundColor!, widget.elevation); + + return AnimatedPhysicalModel( + curve: Curves.fastOutSlowIn, + duration: widget.animationDuration, + shape: BoxShape.rectangle, + clipBehavior: widget.clipBehavior, + elevation: modelElevation, + color: color, + shadowColor: modelShadowColor, + animateColor: false, + child: contents, + ); + } + + final ShapeBorder shape = _getShape(); + + if (widget.type == MaterialType.transparency) { + return _transparentInterior( + context: context, + shape: shape, + clipBehavior: widget.clipBehavior, + contents: contents, + ); + } + + return _MaterialInterior( + curve: Curves.fastOutSlowIn, + duration: widget.animationDuration, + shape: shape, + borderOnForeground: widget.borderOnForeground, + clipBehavior: widget.clipBehavior, + elevation: widget.elevation, + color: backgroundColor!, + shadowColor: modelShadowColor, + surfaceTintColor: widget.surfaceTintColor, + child: contents, + ); + } + + static Widget _transparentInterior({ + required BuildContext context, + required ShapeBorder shape, + required Clip clipBehavior, + required Widget contents, + }) { + final _ShapeBorderPaint child = _ShapeBorderPaint( + shape: shape, + child: contents, + ); + return ClipPath( + clipper: ShapeBorderClipper( + shape: shape, + textDirection: Directionality.maybeOf(context), + ), + clipBehavior: clipBehavior, + child: child, + ); + } + + // Determines the shape for this Material. + // + // If a shape was specified, it will determine the shape. + // If a borderRadius was specified, the shape is a rounded + // rectangle. + // Otherwise, the shape is determined by the widget type as described in the + // Material class documentation. + ShapeBorder _getShape() { + if (widget.shape != null) { + return widget.shape!; + } + if (widget.borderRadius != null) { + return RoundedRectangleBorder(borderRadius: widget.borderRadius!); + } + switch (widget.type) { + case MaterialType.canvas: + case MaterialType.transparency: + return const RoundedRectangleBorder(); + + case MaterialType.card: + case MaterialType.button: + return RoundedRectangleBorder( + borderRadius: widget.borderRadius ?? kMaterialEdges[widget.type]!, + ); + + case MaterialType.circle: + return const CircleBorder(); + } + } +} + +class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController { + _RenderInkFeatures({ + RenderBox? child, + required this.vsync, + required this.absorbHitTest, + this.color, + }) : super(child); + + // This class should exist in a 1:1 relationship with a MaterialState object, + // since there's no current support for dynamically changing the ticker + // provider. + @override + final TickerProvider vsync; + + // This is here to satisfy the MaterialInkController contract. + // The actual painting of this color is done by a Container in the + // MaterialState build method. + @override + Color? color; + + bool absorbHitTest; + + @visibleForTesting + List<InkFeature>? get debugInkFeatures { + if (kDebugMode) { + return _inkFeatures; + } + return null; + } + List<InkFeature>? _inkFeatures; + + @override + void addInkFeature(InkFeature feature) { + assert(!feature._debugDisposed); + assert(feature._controller == this); + _inkFeatures ??= <InkFeature>[]; + assert(!_inkFeatures!.contains(feature)); + _inkFeatures!.add(feature); + markNeedsPaint(); + } + + void _removeFeature(InkFeature feature) { + assert(_inkFeatures != null); + _inkFeatures!.remove(feature); + markNeedsPaint(); + } + + void _didChangeLayout() { + if (_inkFeatures?.isNotEmpty ?? false) { + markNeedsPaint(); + } + } + + @override + bool hitTestSelf(Offset position) => absorbHitTest; + + @override + void paint(PaintingContext context, Offset offset) { + final List<InkFeature>? inkFeatures = _inkFeatures; + if (inkFeatures != null && inkFeatures.isNotEmpty) { + final Canvas canvas = context.canvas; + canvas.save(); + canvas.translate(offset.dx, offset.dy); + canvas.clipRect(Offset.zero & size); + for (final InkFeature inkFeature in inkFeatures) { + inkFeature._paint(canvas); + } + canvas.restore(); + } + assert(inkFeatures == _inkFeatures); + super.paint(context, offset); + } +} + +class _InkFeatures extends SingleChildRenderObjectWidget { + const _InkFeatures({ + super.key, + this.color, + required this.vsync, + required this.absorbHitTest, + super.child, + }); + + // This widget must be owned by a MaterialState, which must be provided as the vsync. + // This relationship must be 1:1 and cannot change for the lifetime of the MaterialState. + + final Color? color; + + final TickerProvider vsync; + + final bool absorbHitTest; + + @override + _RenderInkFeatures createRenderObject(BuildContext context) { + return _RenderInkFeatures( + color: color, + absorbHitTest: absorbHitTest, + vsync: vsync, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderInkFeatures renderObject) { + renderObject..color = color + ..absorbHitTest = absorbHitTest; + assert(vsync == renderObject.vsync); + } +} + +/// A visual reaction on a piece of [Material]. +/// +/// To add an ink feature to a piece of [Material], obtain the +/// [MaterialInkController] via [Material.of] and call +/// [MaterialInkController.addInkFeature]. +abstract class InkFeature { + /// Initializes fields for subclasses. + InkFeature({ + required MaterialInkController controller, + required this.referenceBox, + this.onRemoved, + }) : _controller = controller as _RenderInkFeatures { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/material.dart', + className: '$InkFeature', + object: this, + ); + } + } + + /// The [MaterialInkController] associated with this [InkFeature]. + /// + /// Typically used by subclasses to call + /// [MaterialInkController.markNeedsPaint] when they need to repaint. + MaterialInkController get controller => _controller; + final _RenderInkFeatures _controller; + + /// The render box whose visual position defines the frame of reference for this ink feature. + final RenderBox referenceBox; + + /// Called when the ink feature is no longer visible on the material. + final VoidCallback? onRemoved; + + bool _debugDisposed = false; + + /// Free up the resources associated with this ink feature. + @mustCallSuper + void dispose() { + assert(!_debugDisposed); + assert(() { + _debugDisposed = true; + return true; + }()); + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _controller._removeFeature(this); + onRemoved?.call(); + } + + // Returns the paint transform that allows `fromRenderObject` to perform paint + // in `toRenderObject`'s coordinate space. + // + // Returns null if either `fromRenderObject` or `toRenderObject` is not in the + // same render tree, or either of them is in an offscreen subtree (see + // RenderObject.paintsChild). + static Matrix4? _getPaintTransform( + RenderObject fromRenderObject, + RenderObject toRenderObject, + ) { + // The paths to fromRenderObject and toRenderObject's common ancestor. + final List<RenderObject> fromPath = <RenderObject>[fromRenderObject]; + final List<RenderObject> toPath = <RenderObject>[toRenderObject]; + + RenderObject from = fromRenderObject; + RenderObject to = toRenderObject; + + while (!identical(from, to)) { + final int fromDepth = from.depth; + final int toDepth = to.depth; + + if (fromDepth >= toDepth) { + final RenderObject? fromParent = from.parent; + // Return early if the 2 render objects are not in the same render tree, + // or either of them is offscreen and thus won't get painted. + if (fromParent is! RenderObject || !fromParent.paintsChild(from)) { + return null; + } + fromPath.add(fromParent); + from = fromParent; + } + + if (fromDepth <= toDepth) { + final RenderObject? toParent = to.parent; + if (toParent is! RenderObject || !toParent.paintsChild(to)) { + return null; + } + toPath.add(toParent); + to = toParent; + } + } + assert(identical(from, to)); + + final Matrix4 transform = Matrix4.identity(); + final Matrix4 inverseTransform = Matrix4.identity(); + + for (int index = toPath.length - 1; index > 0; index -= 1) { + toPath[index].applyPaintTransform(toPath[index - 1], transform); + } + for (int index = fromPath.length - 1; index > 0; index -= 1) { + fromPath[index].applyPaintTransform(fromPath[index - 1], inverseTransform); + } + + final double det = inverseTransform.invert(); + return det != 0 ? (inverseTransform..multiply(transform)) : null; + } + + void _paint(Canvas canvas) { + assert(referenceBox.attached); + assert(!_debugDisposed); + // determine the transform that gets our coordinate system to be like theirs + final Matrix4? transform = _getPaintTransform(_controller, referenceBox); + if (transform != null) { + paintFeature(canvas, transform); + } + } + + /// Override this method to paint the ink feature. + /// + /// The transform argument gives the coordinate conversion from the coordinate + /// system of the canvas to the coordinate system of the [referenceBox]. + @protected + void paintFeature(Canvas canvas, Matrix4 transform); + + @override + String toString() => describeIdentity(this); +} + +/// An interpolation between two [ShapeBorder]s. +/// +/// This class specializes the interpolation of [Tween] to use [ShapeBorder.lerp]. +class ShapeBorderTween extends Tween<ShapeBorder?> { + /// Creates a [ShapeBorder] tween. + /// + /// the [begin] and [end] properties may be null; see [ShapeBorder.lerp] for + /// the null handling semantics. + ShapeBorderTween({super.begin, super.end}); + + /// Returns the value this tween has at the given animation clock value. + @override + ShapeBorder? lerp(double t) { + return ShapeBorder.lerp(begin, end, t); + } +} + +/// The interior of non-transparent material. +/// +/// Animates [elevation], [shadowColor], and [shape]. +class _MaterialInterior extends ImplicitlyAnimatedWidget { + /// Creates a const instance of [_MaterialInterior]. + /// + /// The [elevation] must be specified and greater than or equal to zero. + const _MaterialInterior({ + required this.child, + required this.shape, + this.borderOnForeground = true, + this.clipBehavior = Clip.none, + required this.elevation, + required this.color, + required this.shadowColor, + required this.surfaceTintColor, + super.curve, + required super.duration, + }) : assert(elevation >= 0.0); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The border of the widget. + /// + /// This border will be painted, and in addition the outer path of the border + /// determines the physical shape. + final ShapeBorder shape; + + /// Whether to paint the border in front of the child. + /// + /// The default value is true. + /// If false, the border will be painted behind the child. + final bool borderOnForeground; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// The target z-coordinate at which to place this physical object relative + /// to its parent. + /// + /// The value is non-negative. + final double elevation; + + /// The target background color. + final Color color; + + /// The target shadow color. + final Color? shadowColor; + + /// The target surface tint color. + final Color? surfaceTintColor; + + @override + _MaterialInteriorState createState() => _MaterialInteriorState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DiagnosticsProperty<ShapeBorder>('shape', shape)); + description.add(DoubleProperty('elevation', elevation)); + description.add(ColorProperty('color', color)); + description.add(ColorProperty('shadowColor', shadowColor)); + } +} + +class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior> { + Tween<double>? _elevation; + ColorTween? _surfaceTintColor; + ColorTween? _shadowColor; + ShapeBorderTween? _border; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _elevation = visitor( + _elevation, + widget.elevation, + (dynamic value) => Tween<double>(begin: value as double), + ) as Tween<double>?; + _shadowColor = widget.shadowColor != null + ? visitor( + _shadowColor, + widget.shadowColor, + (dynamic value) => ColorTween(begin: value as Color), + ) as ColorTween? + : null; + _surfaceTintColor = widget.surfaceTintColor != null + ? visitor( + _surfaceTintColor, + widget.surfaceTintColor, + (dynamic value) => ColorTween(begin: value as Color), + ) as ColorTween? + : null; + _border = visitor( + _border, + widget.shape, + (dynamic value) => ShapeBorderTween(begin: value as ShapeBorder), + ) as ShapeBorderTween?; + } + + @override + Widget build(BuildContext context) { + final ShapeBorder shape = _border!.evaluate(animation)!; + final double elevation = _elevation!.evaluate(animation); + final Color color = Theme.of(context).useMaterial3 + ? ElevationOverlay.applySurfaceTint(widget.color, _surfaceTintColor?.evaluate(animation), elevation) + : ElevationOverlay.applyOverlay(context, widget.color, elevation); + // If no shadow color is specified, use 0 for elevation in the model so a drop shadow won't be painted. + final double modelElevation = widget.shadowColor != null ? elevation : 0; + final Color shadowColor = _shadowColor?.evaluate(animation) ?? const Color(0x00000000); + return PhysicalShape( + clipper: ShapeBorderClipper( + shape: shape, + textDirection: Directionality.maybeOf(context), + ), + clipBehavior: widget.clipBehavior, + elevation: modelElevation, + color: color, + shadowColor: shadowColor, + child: _ShapeBorderPaint( + shape: shape, + borderOnForeground: widget.borderOnForeground, + child: widget.child, + ), + ); + } +} + +class _ShapeBorderPaint extends StatelessWidget { + const _ShapeBorderPaint({ + required this.child, + required this.shape, + this.borderOnForeground = true, + }); + + final Widget child; + final ShapeBorder shape; + final bool borderOnForeground; + + @override + Widget build(BuildContext context) { + return CustomPaint( + painter: borderOnForeground ? null : _ShapeBorderPainter(shape, Directionality.maybeOf(context)), + foregroundPainter: borderOnForeground ? _ShapeBorderPainter(shape, Directionality.maybeOf(context)) : null, + child: child, + ); + } +} + +class _ShapeBorderPainter extends CustomPainter { + _ShapeBorderPainter(this.border, this.textDirection); + final ShapeBorder border; + final TextDirection? textDirection; + + @override + void paint(Canvas canvas, Size size) { + border.paint(canvas, Offset.zero & size, textDirection: textDirection); + } + + @override + bool shouldRepaint(_ShapeBorderPainter oldDelegate) { + return oldDelegate.border != border; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..4afcc231f9e8ecb8f54cef6cae7e3df4e244b4f8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_button.dart @@ -0,0 +1,440 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'button.dart'; +import 'button_theme.dart'; +import 'constants.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +/// A utility class for building Material buttons that depend on the +/// ambient [ButtonTheme] and [Theme]. +/// +/// This class is planned to be deprecated in a future release. +/// Please use one or more of these buttons and associated themes instead: +/// +/// * [TextButton], [TextButtonTheme], [TextButtonThemeData], +/// * [ElevatedButton], [ElevatedButtonTheme], [ElevatedButtonThemeData], +/// * [OutlinedButton], [OutlinedButtonTheme], [OutlinedButtonThemeData] +/// +/// The button's size will expand to fit the child widget, if necessary. +/// +/// MaterialButtons whose [onPressed] and [onLongPress] callbacks are null will be disabled. To have +/// an enabled button, make sure to pass a non-null value for [onPressed] or [onLongPress]. +/// +/// To create a button directly, without inheriting theme defaults, use +/// [RawMaterialButton]. +/// +/// If you want an ink-splash effect for taps, but don't want to use a button, +/// consider using [InkWell] directly. +/// +/// See also: +/// +/// * [IconButton], to create buttons that contain icons rather than text. +class MaterialButton extends StatelessWidget { + /// Creates a Material Design button. + /// + /// To create a custom Material button consider using [TextButton], + /// [ElevatedButton], or [OutlinedButton]. + /// + /// The [elevation], [hoverElevation], [focusElevation], [highlightElevation], + /// and [disabledElevation] arguments must be non-negative, if specified. + const MaterialButton({ + super.key, + required this.onPressed, + this.onLongPress, + this.onHighlightChanged, + this.mouseCursor, + this.textTheme, + this.textColor, + this.disabledTextColor, + this.color, + this.disabledColor, + this.focusColor, + this.hoverColor, + this.highlightColor, + this.splashColor, + this.colorBrightness, + this.elevation, + this.focusElevation, + this.hoverElevation, + this.highlightElevation, + this.disabledElevation, + this.padding, + this.visualDensity, + this.shape, + this.clipBehavior = Clip.none, + this.focusNode, + this.autofocus = false, + this.materialTapTargetSize, + this.animationDuration, + this.minWidth, + this.height, + this.enableFeedback = true, + this.child, + }) : assert(elevation == null || elevation >= 0.0), + assert(focusElevation == null || focusElevation >= 0.0), + assert(hoverElevation == null || hoverElevation >= 0.0), + assert(highlightElevation == null || highlightElevation >= 0.0), + assert(disabledElevation == null || disabledElevation >= 0.0); + + /// The callback that is called when the button is tapped or otherwise activated. + /// + /// If this callback and [onLongPress] are null, then the button will be disabled. + /// + /// See also: + /// + /// * [enabled], which is true if the button is enabled. + final VoidCallback? onPressed; + + /// The callback that is called when the button is long-pressed. + /// + /// If this callback and [onPressed] are null, then the button will be disabled. + /// + /// See also: + /// + /// * [enabled], which is true if the button is enabled. + final VoidCallback? onLongPress; + + /// Called by the underlying [InkWell] widget's [InkWell.onHighlightChanged] + /// callback. + /// + /// If [onPressed] changes from null to non-null while a gesture is ongoing, + /// this can fire during the build phase (in which case calling + /// [State.setState] is not allowed). + final ValueChanged<bool>? onHighlightChanged; + + /// {@macro flutter.material.RawMaterialButton.mouseCursor} + /// + /// If this property is null, [MaterialStateMouseCursor.clickable] will be used. + final MouseCursor? mouseCursor; + + /// Defines the button's base colors, and the defaults for the button's minimum + /// size, internal padding, and shape. + /// + /// Defaults to `ButtonTheme.of(context).textTheme`. + final ButtonTextTheme? textTheme; + + /// The color to use for this button's text. + /// + /// The button's [Material.textStyle] will be the current theme's button text + /// style, [TextTheme.labelLarge] of [ThemeData.textTheme], configured with this + /// color. + /// + /// The default text color depends on the button theme's text theme, + /// [ButtonThemeData.textTheme]. + /// + /// If [textColor] is a [MaterialStateProperty<Color>], [disabledTextColor] + /// will be ignored. + /// + /// See also: + /// + /// * [disabledTextColor], the text color to use when the button has been + /// disabled. + final Color? textColor; + + /// The color to use for this button's text when the button is disabled. + /// + /// The button's [Material.textStyle] will be the current theme's button text + /// style, [TextTheme.labelLarge] of [ThemeData.textTheme], configured with this + /// color. + /// + /// The default value is the theme's disabled color, + /// [ThemeData.disabledColor]. + /// + /// If [textColor] is a [MaterialStateProperty<Color>], [disabledTextColor] + /// will be ignored. + /// + /// See also: + /// + /// * [textColor] - The color to use for this button's text when the button is [enabled]. + final Color? disabledTextColor; + + /// The button's fill color, displayed by its [Material], while it + /// is in its default (unpressed, [enabled]) state. + /// + /// See also: + /// + /// * [disabledColor] - the fill color of the button when the button is disabled. + final Color? color; + + /// The fill color of the button when the button is disabled. + /// + /// The default value of this color is the theme's disabled color, + /// [ThemeData.disabledColor]. + /// + /// See also: + /// + /// * [color] - the fill color of the button when the button is [enabled]. + final Color? disabledColor; + + /// The splash color of the button's [InkWell]. + /// + /// The ink splash indicates that the button has been touched. It + /// appears on top of the button's child and spreads in an expanding + /// circle beginning where the touch occurred. + /// + /// The default splash color is the current theme's splash color, + /// [ThemeData.splashColor]. + /// + /// The appearance of the splash can be configured with the theme's splash + /// factory, [ThemeData.splashFactory]. + final Color? splashColor; + + /// The fill color of the button's [Material] when it has the input focus. + /// + /// The button changed focus color when the button has the input focus. It + /// appears behind the button's child. + final Color? focusColor; + + /// The fill color of the button's [Material] when a pointer is hovering over + /// it. + /// + /// The button changes fill color when a pointer is hovering over the button. + /// It appears behind the button's child. + final Color? hoverColor; + + /// The highlight color of the button's [InkWell]. + /// + /// The highlight indicates that the button is actively being pressed. It + /// appears on top of the button's child and quickly spreads to fill + /// the button, and then fades out. + /// + /// If [textTheme] is [ButtonTextTheme.primary], the default highlight color is + /// transparent (in other words the highlight doesn't appear). Otherwise it's + /// the current theme's highlight color, [ThemeData.highlightColor]. + final Color? highlightColor; + + /// The z-coordinate at which to place this button relative to its parent. + /// + /// This controls the size of the shadow below the raised button. + /// + /// Defaults to 2, the appropriate elevation for raised buttons. The value + /// is always non-negative. + /// + /// See also: + /// + /// * [TextButton], a button with no elevation or fill color. + /// * [focusElevation], the elevation when the button is focused. + /// * [hoverElevation], the elevation when a pointer is hovering over the + /// button. + /// * [disabledElevation], the elevation when the button is disabled. + /// * [highlightElevation], the elevation when the button is pressed. + final double? elevation; + + /// The elevation for the button's [Material] when the button + /// is [enabled] and a pointer is hovering over it. + /// + /// Defaults to 4.0. The value is always non-negative. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [focusElevation], the elevation when the button is focused. + /// * [disabledElevation], the elevation when the button is disabled. + /// * [highlightElevation], the elevation when the button is pressed. + final double? hoverElevation; + + /// The elevation for the button's [Material] when the button + /// is [enabled] and has the input focus. + /// + /// Defaults to 4.0. The value is always non-negative. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [hoverElevation], the elevation when a pointer is hovering over the + /// button. + /// * [disabledElevation], the elevation when the button is disabled. + /// * [highlightElevation], the elevation when the button is pressed. + final double? focusElevation; + + /// The elevation for the button's [Material] relative to its parent when the + /// button is [enabled] and pressed. + /// + /// This controls the size of the shadow below the button. When a tap + /// down gesture occurs within the button, its [InkWell] displays a + /// [highlightColor] "highlight". + /// + /// Defaults to 8.0. The value is always non-negative. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [focusElevation], the elevation when the button is focused. + /// * [hoverElevation], the elevation when a pointer is hovering over the + /// button. + /// * [disabledElevation], the elevation when the button is disabled. + final double? highlightElevation; + + /// The elevation for the button's [Material] relative to its parent when the + /// button is not [enabled]. + /// + /// Defaults to 0.0. The value is always non-negative. + /// + /// See also: + /// + /// * [elevation], the default elevation. + /// * [highlightElevation], the elevation when the button is pressed. + final double? disabledElevation; + + /// The theme brightness to use for this button. + /// + /// Defaults to the theme's brightness in [ThemeData.brightness]. Setting + /// this value determines the button text's colors based on + /// [ButtonThemeData.getTextColor]. + /// + /// See also: + /// + /// * [ButtonTextTheme], uses [Brightness] to determine text color. + final Brightness? colorBrightness; + + /// The button's label. + /// + /// Often a [Text] widget in all caps. + final Widget? child; + + /// Whether the button is enabled or disabled. + /// + /// Buttons are disabled by default. To enable a button, set its [onPressed] + /// or [onLongPress] properties to a non-null value. + bool get enabled => onPressed != null || onLongPress != null; + + /// The internal padding for the button's [child]. + /// + /// Defaults to the value from the current [ButtonTheme], + /// [ButtonThemeData.padding]. + final EdgeInsetsGeometry? padding; + + /// Defines how compact the button's layout will be. + /// + /// {@macro flutter.material.themedata.visualDensity} + /// + /// See also: + /// + /// * [ThemeData.visualDensity], which specifies the [visualDensity] for all + /// widgets within a [Theme]. + final VisualDensity? visualDensity; + + /// The shape of the button's [Material]. + /// + /// The button's highlight and splash are clipped to this shape. If the + /// button has an elevation, then its drop shadow is defined by this + /// shape as well. + /// + /// Defaults to the value from the current [ButtonTheme], + /// [ButtonThemeData.shape]. + final ShapeBorder? shape; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// Defines the duration of animated changes for [shape] and [elevation]. + /// + /// The default value is [kThemeChangeDuration]. + final Duration? animationDuration; + + /// Configures the minimum size of the tap target. + /// + /// Defaults to [ThemeData.materialTapTargetSize]. + /// + /// See also: + /// + /// * [MaterialTapTargetSize], for a description of how this affects tap targets. + final MaterialTapTargetSize? materialTapTargetSize; + + /// The smallest horizontal extent that the button will occupy. + /// + /// Defaults to the value from the current [ButtonTheme]. + final double? minWidth; + + /// The vertical extent of the button. + /// + /// Defaults to the value from the current [ButtonTheme]. + final double? height; + + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool enableFeedback; + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final ButtonThemeData buttonTheme = ButtonTheme.of(context); + + return RawMaterialButton( + onPressed: onPressed, + onLongPress: onLongPress, + enableFeedback: enableFeedback, + onHighlightChanged: onHighlightChanged, + mouseCursor: mouseCursor, + fillColor: buttonTheme.getFillColor(this), + textStyle: theme.textTheme.labelLarge!.copyWith(color: buttonTheme.getTextColor(this)), + focusColor: focusColor ?? buttonTheme.getFocusColor(this), + hoverColor: hoverColor ?? buttonTheme.getHoverColor(this), + highlightColor: highlightColor ?? theme.highlightColor, + splashColor: splashColor ?? theme.splashColor, + elevation: buttonTheme.getElevation(this), + focusElevation: buttonTheme.getFocusElevation(this), + hoverElevation: buttonTheme.getHoverElevation(this), + highlightElevation: buttonTheme.getHighlightElevation(this), + padding: buttonTheme.getPadding(this), + visualDensity: visualDensity ?? theme.visualDensity, + constraints: buttonTheme.getConstraints(this).copyWith( + minWidth: minWidth, + minHeight: height, + ), + shape: buttonTheme.getShape(this), + clipBehavior: clipBehavior, + focusNode: focusNode, + autofocus: autofocus, + animationDuration: buttonTheme.getAnimationDuration(this), + materialTapTargetSize: materialTapTargetSize ?? theme.materialTapTargetSize, + disabledElevation: disabledElevation ?? 0.0, + child: child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('enabled', value: enabled, ifFalse: 'disabled')); + properties.add(DiagnosticsProperty<ButtonTextTheme>('textTheme', textTheme, defaultValue: null)); + properties.add(ColorProperty('textColor', textColor, defaultValue: null)); + properties.add(ColorProperty('disabledTextColor', disabledTextColor, defaultValue: null)); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: null)); + properties.add(ColorProperty('focusColor', focusColor, defaultValue: null)); + properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: null)); + properties.add(ColorProperty('highlightColor', highlightColor, defaultValue: null)); + properties.add(ColorProperty('splashColor', splashColor, defaultValue: null)); + properties.add(DiagnosticsProperty<Brightness>('colorBrightness', colorBrightness, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<VisualDensity>('visualDensity', visualDensity, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialTapTargetSize>('materialTapTargetSize', materialTapTargetSize, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_localizations.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_localizations.dart new file mode 100644 index 0000000000000000000000000000000000000000..e048ad8b961a02bdf949cbcf3dee31368440b352 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_localizations.dart @@ -0,0 +1,1454 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'debug.dart'; +import 'time.dart'; +import 'typography.dart'; + +// Examples can assume: +// late BuildContext context; + +// ADDING A NEW STRING +// +// Please refer to instructions in this markdown file +// (packages/flutter_localizations/README.md) + +/// Defines the localized resource values used by the Material widgets. +/// +/// See also: +/// +/// * [DefaultMaterialLocalizations], the default, English-only, implementation +/// of this interface. +/// * [GlobalMaterialLocalizations], which provides material localizations for +/// many languages. +abstract class MaterialLocalizations { + /// The tooltip for the leading [AppBar] menu (a.k.a. 'hamburger') button. + String get openAppDrawerTooltip; + + /// The [BackButton]'s tooltip. + String get backButtonTooltip; + + /// The [CloseButton]'s tooltip. + String get closeButtonTooltip; + + /// The tooltip for the delete button on a [Chip]. + String get deleteButtonTooltip; + + /// The tooltip for the more button on an overflowing text selection menu. + String get moreButtonTooltip; + + /// The tooltip for the [CalendarDatePicker]'s "next month" button. + String get nextMonthTooltip; + + /// The tooltip for the [CalendarDatePicker]'s "previous month" button. + String get previousMonthTooltip; + + /// The tooltip for the [PaginatedDataTable]'s "first page" button. + String get firstPageTooltip; + + /// The tooltip for the [PaginatedDataTable]'s "last page" button. + String get lastPageTooltip; + + /// The tooltip for the [PaginatedDataTable]'s "next page" button. + String get nextPageTooltip; + + /// The tooltip for the [PaginatedDataTable]'s "previous page" button. + String get previousPageTooltip; + + /// The default [PopupMenuButton] tooltip. + String get showMenuTooltip; + + /// The default title for [AboutListTile]. + String aboutListTileTitle(String applicationName); + + /// Title for the [LicensePage] widget. + String get licensesPageTitle; + + /// Subtitle for a package in the [LicensePage] widget. + String licensesPackageDetailText(int licenseCount); + + /// Title for the [PaginatedDataTable]'s row info footer. + String pageRowsInfoTitle(int firstRow, int lastRow, int rowCount, bool rowCountIsApproximate); + + /// Title for the [PaginatedDataTable]'s "rows per page" footer. + String get rowsPerPageTitle; + + /// The accessibility label used on a tab in a [TabBar]. + /// + /// This message describes the index of the selected tab and how many tabs + /// there are, e.g. 'Tab 1 of 2' in United States English. + /// + /// `tabIndex` and `tabCount` must be greater than or equal to one. + String tabLabel({ required int tabIndex, required int tabCount }); + + /// Title for the [PaginatedDataTable]'s selected row count header. + String selectedRowCountTitle(int selectedRowCount); + + /// Label for "cancel" buttons and menu items. + String get cancelButtonLabel; + + /// Label for "close" buttons and menu items. + String get closeButtonLabel; + + /// Label for "continue" buttons and menu items. + String get continueButtonLabel; + + /// Label for "copy" edit buttons and menu items. + String get copyButtonLabel; + + /// Label for "cut" edit buttons and menu items. + String get cutButtonLabel; + + /// Label for "scan text" OCR edit buttons and menu items. + String get scanTextButtonLabel; + + /// Label for OK buttons and menu items. + String get okButtonLabel; + + /// Label for "paste" edit buttons and menu items. + String get pasteButtonLabel; + + /// Label for "select all" edit buttons and menu items. + String get selectAllButtonLabel; + + /// Label for "look up" edit buttons and menu items. + String get lookUpButtonLabel; + + /// Label for "search web" edit buttons and menu items. + String get searchWebButtonLabel; + + /// Label for "share" edit buttons and menu items. + String get shareButtonLabel; + + /// Label for the [AboutDialog] button that shows the [LicensePage]. + String get viewLicensesButtonLabel; + + /// The abbreviation for ante meridiem (before noon) shown in the time picker. + String get anteMeridiemAbbreviation; + + /// The abbreviation for post meridiem (after noon) shown in the time picker. + String get postMeridiemAbbreviation; + + /// The text-to-speech announcement made when a time picker invoked using + /// [showTimePicker] is set to the hour picker mode. + String get timePickerHourModeAnnouncement; + + /// The text-to-speech announcement made when a time picker invoked using + /// [showTimePicker] is set to the minute picker mode. + String get timePickerMinuteModeAnnouncement; + + /// Label read out by accessibility tools (TalkBack or VoiceOver) for a modal + /// barrier to indicate that a tap dismisses the barrier. + /// + /// A modal barrier can for example be found behind an alert or popup to block + /// user interaction with elements behind it. + String get modalBarrierDismissLabel; + + /// Label read out by accessibility tools (TalkBack or VoiceOver) for a + /// context menu to indicate that a tap dismisses the context menu. + String get menuDismissLabel; + + /// Label read out by accessibility tools (TalkBack or VoiceOver) when a + /// drawer widget is opened. + String get drawerLabel; + + /// Label read out by accessibility tools (TalkBack or VoiceOver) when a + /// popup menu widget is opened. + String get popupMenuLabel; + + /// Label read out by accessibility tools (TalkBack or VoiceOver) when a + /// MenuBarMenu widget is opened. + String get menuBarMenuLabel; + + /// Label read out by accessibility tools (TalkBack or VoiceOver) when a + /// dialog widget is opened. + String get dialogLabel; + + /// Label read out by accessibility tools (TalkBack or VoiceOver) when an + /// alert dialog widget is opened. + String get alertDialogLabel; + + /// Label indicating that a text field is a search field. This will be used + /// as a hint text in the text field. + String get searchFieldLabel; + + /// Label indicating that a given date is the current date. + String get currentDateLabel; + + /// Label for the scrim rendered underneath a [BottomSheet]. + String get scrimLabel; + + /// Label for a [BottomSheet], used as the `modalRouteContentName` of the + /// [scrimOnTapHint]. + String get bottomSheetLabel; + + /// Hint text announced when tapping on the scrim underneath the content of + /// a modal route. + String scrimOnTapHint(String modalRouteContentName); + + /// The format used to lay out the time picker. + /// + /// The documentation for [TimeOfDayFormat] enum values provides details on + /// each supported layout. + TimeOfDayFormat timeOfDayFormat({ bool alwaysUse24HourFormat = false }); + + /// Defines the localized [TextStyle] geometry for [ThemeData.textTheme]. + /// + /// The [scriptCategory] defines the overall geometry of a [TextTheme] for + /// the [Typography.geometryThemeFor] method in terms of the + /// three language categories defined in https://material.io/go/design-typography. + /// + /// Generally speaking, font sizes for [ScriptCategory.tall] and + /// [ScriptCategory.dense] scripts - for text styles that are smaller than the + /// title style - are one unit larger than they are for + /// [ScriptCategory.englishLike] scripts. + ScriptCategory get scriptCategory; + + /// Formats [number] as a decimal, inserting locale-appropriate thousands + /// separators as necessary. + String formatDecimal(int number); + + /// Formats [TimeOfDay.hour] in the given time of day according to the value + /// of [timeOfDayFormat]. + /// + /// If [alwaysUse24HourFormat] is true, formats hour using [HourFormat.HH] + /// rather than the default for the current locale. + String formatHour(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false }); + + /// Formats [TimeOfDay.minute] in the given time of day according to the value + /// of [timeOfDayFormat]. + String formatMinute(TimeOfDay timeOfDay); + + /// Formats [timeOfDay] according to the value of [timeOfDayFormat]. + /// + /// If [alwaysUse24HourFormat] is true, formats hour using [HourFormat.HH] + /// rather than the default for the current locale. This value is usually + /// passed from [MediaQueryData.alwaysUse24HourFormat], which has platform- + /// specific behavior. + String formatTimeOfDay(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false }); + + /// Full unabbreviated year format, e.g. 2017 rather than 17. + String formatYear(DateTime date); + + /// Formats the date in a compact format. + /// + /// Usually just the numeric values for the for day, month and year are used. + /// + /// Examples: + /// + /// - US English: 02/21/2019 + /// - Russian: 21.02.2019 + /// + /// See also: + /// * [parseCompactDate], which will convert a compact date string to a [DateTime]. + String formatCompactDate(DateTime date); + + /// Formats the date using a short-width format. + /// + /// Includes the abbreviation of the month, the day and year. + /// + /// Examples: + /// + /// - US English: Feb 21, 2019 + /// - Russian: 21 февр. 2019 г. + String formatShortDate(DateTime date); + + /// Formats the date using a medium-width format. + /// + /// Abbreviates month and days of week. This appears in the header of the date + /// picker invoked using [showDatePicker]. + /// + /// Examples: + /// + /// - US English: Wed, Sep 27 + /// - Russian: ср, сент. 27 + String formatMediumDate(DateTime date); + + /// Formats day of week, month, day of month and year in a long-width format. + /// + /// Does not abbreviate names. Appears in spoken announcements of the date + /// picker invoked using [showDatePicker], when accessibility mode is on. + /// + /// Examples: + /// + /// - US English: Wednesday, September 27, 2017 + /// - Russian: Среда, Сентябрь 27, 2017 + String formatFullDate(DateTime date); + + /// Formats the month and the year of the given [date]. + /// + /// The returned string does not contain the day of the month. This appears + /// in the date picker invoked using [showDatePicker]. + String formatMonthYear(DateTime date); + + /// Formats the month and day of the given [date]. + /// + /// Examples: + /// + /// - US English: Feb 21 + /// - Russian: 21 февр. + String formatShortMonthDay(DateTime date); + + /// Converts the given compact date formatted string into a [DateTime]. + /// + /// The format of the string must be a valid compact date format for the + /// given locale. If the text doesn't represent a valid date, `null` will be + /// returned. + /// + /// See also: + /// * [formatCompactDate], which will convert a [DateTime] into a string in the compact format. + DateTime? parseCompactDate(String? inputString); + + /// List of week day names in narrow format, usually 1- or 2-letter + /// abbreviations of full names. + /// + /// The list begins with the value corresponding to Sunday and ends with + /// Saturday. Use [firstDayOfWeekIndex] to find the first day of week in this + /// list. + /// + /// Examples: + /// + /// - US English: S, M, T, W, T, F, S + /// - Russian: вс, пн, вт, ср, чт, пт, сб - notice that the list begins with + /// вс (Sunday) even though the first day of week for Russian is Monday. + List<String> get narrowWeekdays; + + /// Index of the first day of week, where 0 points to Sunday, and 6 points to + /// Saturday. + /// + /// This getter is compatible with [narrowWeekdays]. For example: + /// + /// ```dart + /// MaterialLocalizations localizations = MaterialLocalizations.of(context); + /// // The name of the first day of week for the current locale. + /// String firstDayOfWeek = localizations.narrowWeekdays[localizations.firstDayOfWeekIndex]; + /// ``` + int get firstDayOfWeekIndex; + + /// The character string used to separate the parts of a compact date format + /// (i.e. mm/dd/yyyy has a separator of '/'). + String get dateSeparator; + + /// The help text used on an empty [InputDatePickerFormField] to indicate + /// to the user the date format being asked for. + String get dateHelpText; + + /// The semantic label used to announce when the user has entered the year + /// selection mode of the [CalendarDatePicker] which is used in the data picker + /// dialog created with [showDatePicker]. + String get selectYearSemanticsLabel; + + /// The label used to indicate a date that has not been entered or selected + /// yet in the date picker. + String get unspecifiedDate; + + /// The label used to indicate a date range that has not been entered or + /// selected yet in the date range picker. + String get unspecifiedDateRange; + + /// The label used to describe the text field used in an [InputDatePickerFormField]. + String get dateInputLabel; + + /// The label used for the starting date input field in the date range picker + /// created with [showDateRangePicker]. + String get dateRangeStartLabel; + + /// The label used for the ending date input field in the date range picker + /// created with [showDateRangePicker]. + String get dateRangeEndLabel; + + /// The semantics label used for the selected start date in the date range + /// picker's day grid. + String dateRangeStartDateSemanticLabel(String formattedDate); + + /// The semantics label used for the selected end date in the date range + /// picker's day grid. + String dateRangeEndDateSemanticLabel(String formattedDate); + + /// Error message displayed to the user when they have entered a text string + /// in an [InputDatePickerFormField] that is not in a valid date format. + String get invalidDateFormatLabel; + + /// Error message displayed to the user when they have entered an invalid + /// date range in the input mode of the date range picker created with + /// [showDateRangePicker]. + String get invalidDateRangeLabel; + + /// Error message displayed to the user when they have entered a date that + /// is outside the valid range for the date picker. + /// [showDateRangePicker]. + String get dateOutOfRangeLabel; + + /// Label for a 'SAVE' button. Currently used by the full screen mode of the + /// date range picker. + String get saveButtonLabel; + + /// Label used in the header of the date picker dialog created with + /// [showDatePicker]. + String get datePickerHelpText; + + /// Label used in the header of the date range picker dialog created with + /// [showDateRangePicker]. + String get dateRangePickerHelpText; + + /// Tooltip used for the calendar mode button of the date pickers. + String get calendarModeButtonLabel; + + /// Tooltip used for the text input mode button of the date pickers. + String get inputDateModeButtonLabel; + + /// Label used in the header of the time picker dialog created with + /// [showTimePicker] when in [TimePickerEntryMode.dial]. + String get timePickerDialHelpText; + + /// Label used in the header of the time picker dialog created with + /// [showTimePicker] when in [TimePickerEntryMode.input]. + String get timePickerInputHelpText; + + /// Label used below the hour text field of the time picker dialog created + /// with [showTimePicker] when in [TimePickerEntryMode.input]. + String get timePickerHourLabel; + + /// Label used below the minute text field of the time picker dialog created + /// with [showTimePicker] when in [TimePickerEntryMode.input]. + String get timePickerMinuteLabel; + + /// Error message for the time picker dialog created with [showTimePicker] + /// when in [TimePickerEntryMode.input]. + String get invalidTimeLabel; + + /// Tooltip used to put the time picker into [TimePickerEntryMode.dial]. + String get dialModeButtonLabel; + + /// Tooltip used to put the time picker into [TimePickerEntryMode.input]. + String get inputTimeModeButtonLabel; + + /// The semantics label used to indicate which account is signed in the + /// [UserAccountsDrawerHeader] widget. + String get signedInLabel; + + /// The semantics label used for the button on [UserAccountsDrawerHeader] that + /// hides the list of accounts. + String get hideAccountsLabel; + + /// The semantics label used for the button on [UserAccountsDrawerHeader] that + /// shows the list of accounts. + String get showAccountsLabel; + + /// The semantics label used for [ReorderableListView] to reorder an item in the + /// list to the start of the list. + @Deprecated( + 'Use the reorderItemToStart from WidgetsLocalizations instead. ' + 'This feature was deprecated after v3.10.0-2.0.pre.' + ) + String get reorderItemToStart; + + /// The semantics label used for [ReorderableListView] to reorder an item in the + /// list to the end of the list. + @Deprecated( + 'Use the reorderItemToEnd from WidgetsLocalizations instead. ' + 'This feature was deprecated after v3.10.0-2.0.pre.' + ) + String get reorderItemToEnd; + + /// The semantics label used for [ReorderableListView] to reorder an item in the + /// list one space up the list. + @Deprecated( + 'Use the reorderItemUp from WidgetsLocalizations instead. ' + 'This feature was deprecated after v3.10.0-2.0.pre.' + ) + String get reorderItemUp; + + /// The semantics label used for [ReorderableListView] to reorder an item in the + /// list one space down the list. + @Deprecated( + 'Use the reorderItemDown from WidgetsLocalizations instead. ' + 'This feature was deprecated after v3.10.0-2.0.pre.' + ) + String get reorderItemDown; + + /// The semantics label used for [ReorderableListView] to reorder an item in the + /// list one space left in the list. + @Deprecated( + 'Use the reorderItemLeft from WidgetsLocalizations instead. ' + 'This feature was deprecated after v3.10.0-2.0.pre.' + ) + String get reorderItemLeft; + + /// The semantics label used for [ReorderableListView] to reorder an item in the + /// list one space right in the list. + @Deprecated( + 'Use the reorderItemRight from WidgetsLocalizations instead. ' + 'This feature was deprecated after v3.10.0-2.0.pre.' + ) + String get reorderItemRight; + + /// The semantics hint to describe the tap action on an expanded [ExpandIcon]. + String get expandedIconTapHint => 'Collapse'; + + /// The semantics hint to describe the tap action on a collapsed [ExpandIcon]. + String get collapsedIconTapHint => 'Expand'; + + /// The semantics hint to describe the tap action on an expanded + /// [ExpansionTile] on iOS and macOS. This is appended to the [collapsedHint] + /// hint to provide a more detailed description of the action, e.g. "Expanded + /// double tap to collapse". + String get expansionTileExpandedHint => 'double tap to collapse'; + + /// The semantics hint to describe the tap action on a collapsed + /// [ExpansionTile] on iOS and macOS. This is appended to the [expandedHint] + /// hint to provide a more detailed description of the action, e.g. "Collapsed + /// double tap to expand". + String get expansionTileCollapsedHint => 'double tap to expand'; + + /// The semantics hint to describe the tap action on an expanded [ExpansionTile]. + String get expansionTileExpandedTapHint => 'Collapse'; + + /// The semantics hint to describe the tap action on a collapsed [ExpansionTile]. + String get expansionTileCollapsedTapHint => 'Expand for more details'; + + /// The semantics hint to describe the [ExpansionTile] expanded state. + String get expandedHint => 'Collapsed'; + + /// The semantics hint to describe the [ExpansionTile] collapsed state. + String get collapsedHint => 'Expanded'; + + /// The label for the [TextField]'s character counter. + String remainingTextFieldCharacterCount(int remaining); + + /// The default semantics label for a [RefreshIndicator]. + String get refreshIndicatorSemanticLabel; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.alt]. + String get keyboardKeyAlt; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.altGraph]. + String get keyboardKeyAltGraph; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.backspace]. + String get keyboardKeyBackspace; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.capsLock]. + String get keyboardKeyCapsLock; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.channelDown]. + String get keyboardKeyChannelDown; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.channelUp]. + String get keyboardKeyChannelUp; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.control]. + String get keyboardKeyControl; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.delete]. + String get keyboardKeyDelete; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.eject]. + String get keyboardKeyEject; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.end]. + String get keyboardKeyEnd; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.escape]. + String get keyboardKeyEscape; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.fn]. + String get keyboardKeyFn; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.home]. + String get keyboardKeyHome; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.insert]. + String get keyboardKeyInsert; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.meta]. + String get keyboardKeyMeta; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.meta] on macOS. + String get keyboardKeyMetaMacOs; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.meta] on Windows. + String get keyboardKeyMetaWindows; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numLock]. + String get keyboardKeyNumLock; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpad1]. + String get keyboardKeyNumpad1; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpad2]. + String get keyboardKeyNumpad2; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpad3]. + String get keyboardKeyNumpad3; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpad4]. + String get keyboardKeyNumpad4; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpad5]. + String get keyboardKeyNumpad5; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpad6]. + String get keyboardKeyNumpad6; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpad7]. + String get keyboardKeyNumpad7; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpad8]. + String get keyboardKeyNumpad8; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpad9]. + String get keyboardKeyNumpad9; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpad0]. + String get keyboardKeyNumpad0; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpadAdd]. + String get keyboardKeyNumpadAdd; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpadComma]. + String get keyboardKeyNumpadComma; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpadDecimal]. + String get keyboardKeyNumpadDecimal; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpadDivide]. + String get keyboardKeyNumpadDivide; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpadEnter]. + String get keyboardKeyNumpadEnter; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpadEqual]. + String get keyboardKeyNumpadEqual; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpadMultiply]. + String get keyboardKeyNumpadMultiply; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpadParenLeft]. + String get keyboardKeyNumpadParenLeft; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpadParenRight]. + String get keyboardKeyNumpadParenRight; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.numpadSubtract]. + String get keyboardKeyNumpadSubtract; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.pageDown]. + String get keyboardKeyPageDown; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.pageUp]. + String get keyboardKeyPageUp; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.power]. + String get keyboardKeyPower; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.powerOff]. + String get keyboardKeyPowerOff; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.printScreen]. + String get keyboardKeyPrintScreen; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.scrollLock]. + String get keyboardKeyScrollLock; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.select]. + String get keyboardKeySelect; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.shift]. + String get keyboardKeyShift; + + /// The shortcut label for the keyboard key [LogicalKeyboardKey.space]. + String get keyboardKeySpace; + + /// The `MaterialLocalizations` from the closest [Localizations] instance + /// that encloses the given context. + /// + /// If no [MaterialLocalizations] are available in the given `context`, this + /// method throws an exception. + /// + /// This method is just a convenient shorthand for: + /// `Localizations.of<MaterialLocalizations>(context, MaterialLocalizations)!`. + /// + /// References to the localized resources defined by this class are typically + /// written in terms of this method. For example: + /// + /// ```dart + /// tooltip: MaterialLocalizations.of(context).backButtonTooltip, + /// ``` + static MaterialLocalizations of(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + return Localizations.of<MaterialLocalizations>(context, MaterialLocalizations)!; + } +} + +class _MaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLocalizations> { + const _MaterialLocalizationsDelegate(); + + @override + bool isSupported(Locale locale) => locale.languageCode == 'en'; + + @override + Future<MaterialLocalizations> load(Locale locale) => DefaultMaterialLocalizations.load(locale); + + @override + bool shouldReload(_MaterialLocalizationsDelegate old) => false; + + @override + String toString() => 'DefaultMaterialLocalizations.delegate(en_US)'; +} + +/// US English strings for the material widgets. +/// +/// See also: +/// +/// * [GlobalMaterialLocalizations], which provides material localizations for +/// many languages. +/// * [MaterialApp.localizationsDelegates], which automatically includes +/// [DefaultMaterialLocalizations.delegate] by default. +class DefaultMaterialLocalizations implements MaterialLocalizations { + /// Constructs an object that defines the material widgets' localized strings + /// for US English (only). + /// + /// [LocalizationsDelegate] implementations typically call the static [load] + /// function, rather than constructing this class directly. + const DefaultMaterialLocalizations(); + + // Ordered to match DateTime.monday=1, DateTime.sunday=6 + static const List<String> _shortWeekdays = <String>[ + 'Mon', + 'Tue', + 'Wed', + 'Thu', + 'Fri', + 'Sat', + 'Sun', + ]; + + // Ordered to match DateTime.monday=1, DateTime.sunday=6 + static const List<String> _weekdays = <String>[ + 'Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday', + 'Saturday', + 'Sunday', + ]; + + static const List<String> _narrowWeekdays = <String>[ + 'S', + 'M', + 'T', + 'W', + 'T', + 'F', + 'S', + ]; + + static const List<String> _shortMonths = <String>[ + 'Jan', + 'Feb', + 'Mar', + 'Apr', + 'May', + 'Jun', + 'Jul', + 'Aug', + 'Sep', + 'Oct', + 'Nov', + 'Dec', + ]; + + static const List<String> _months = <String>[ + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December', + ]; + + /// Returns the number of days in a month, according to the proleptic + /// Gregorian calendar. + /// + /// This applies the leap year logic introduced by the Gregorian reforms of + /// 1582. It will not give valid results for dates prior to that time. + int _getDaysInMonth(int year, int month) { + if (month == DateTime.february) { + final bool isLeapYear = (year % 4 == 0) && (year % 100 != 0) || + (year % 400 == 0); + if (isLeapYear) { + return 29; + } + return 28; + } + const List<int> daysInMonth = <int>[31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + return daysInMonth[month - 1]; + } + + @override + String formatHour(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false }) { + final TimeOfDayFormat format = timeOfDayFormat(alwaysUse24HourFormat: alwaysUse24HourFormat); + switch (format) { + case TimeOfDayFormat.h_colon_mm_space_a: + return formatDecimal(timeOfDay.hourOfPeriod == 0 ? 12 : timeOfDay.hourOfPeriod); + case TimeOfDayFormat.HH_colon_mm: + return _formatTwoDigitZeroPad(timeOfDay.hour); + case TimeOfDayFormat.a_space_h_colon_mm: + case TimeOfDayFormat.frenchCanadian: + case TimeOfDayFormat.H_colon_mm: + case TimeOfDayFormat.HH_dot_mm: + throw AssertionError('$runtimeType does not support $format.'); + } + } + + /// Formats [number] using two digits, assuming it's in the 0-99 inclusive + /// range. Not designed to format values outside this range. + String _formatTwoDigitZeroPad(int number) { + assert(0 <= number && number < 100); + + if (number < 10) { + return '0$number'; + } + + return '$number'; + } + + @override + String formatMinute(TimeOfDay timeOfDay) { + final int minute = timeOfDay.minute; + return minute < 10 ? '0$minute' : minute.toString(); + } + + @override + String formatYear(DateTime date) => date.year.toString(); + + @override + String formatCompactDate(DateTime date) { + // Assumes US mm/dd/yyyy format + final String month = _formatTwoDigitZeroPad(date.month); + final String day = _formatTwoDigitZeroPad(date.day); + final String year = date.year.toString().padLeft(4, '0'); + return '$month/$day/$year'; + } + + @override + String formatShortDate(DateTime date) { + final String month = _shortMonths[date.month - DateTime.january]; + return '$month ${date.day}, ${date.year}'; + } + + @override + String formatMediumDate(DateTime date) { + final String day = _shortWeekdays[date.weekday - DateTime.monday]; + final String month = _shortMonths[date.month - DateTime.january]; + return '$day, $month ${date.day}'; + } + + @override + String formatFullDate(DateTime date) { + final String month = _months[date.month - DateTime.january]; + return '${_weekdays[date.weekday - DateTime.monday]}, $month ${date.day}, ${date.year}'; + } + + @override + String formatMonthYear(DateTime date) { + final String year = formatYear(date); + final String month = _months[date.month - DateTime.january]; + return '$month $year'; + } + + @override + String formatShortMonthDay(DateTime date) { + final String month = _shortMonths[date.month - DateTime.january]; + return '$month ${date.day}'; + } + + @override + DateTime? parseCompactDate(String? inputString) { + if (inputString == null) { + return null; + } + + // Assumes US mm/dd/yyyy format + final List<String> inputParts = inputString.split('/'); + if (inputParts.length != 3) { + return null; + } + + final int? year = int.tryParse(inputParts[2], radix: 10); + if (year == null || year < 1) { + return null; + } + + final int? month = int.tryParse(inputParts[0], radix: 10); + if (month == null || month < 1 || month > 12) { + return null; + } + + final int? day = int.tryParse(inputParts[1], radix: 10); + if (day == null || day < 1 || day > _getDaysInMonth(year, month)) { + return null; + } + + try { + return DateTime(year, month, day); + } on ArgumentError { + return null; + } + } + + @override + List<String> get narrowWeekdays => _narrowWeekdays; + + @override + int get firstDayOfWeekIndex => 0; // narrowWeekdays[0] is 'S' for Sunday + + @override + String get dateSeparator => '/'; + + @override + String get dateHelpText => 'mm/dd/yyyy'; + + @override + String get selectYearSemanticsLabel => 'Select year'; + + @override + String get unspecifiedDate => 'Date'; + + @override + String get unspecifiedDateRange => 'Date Range'; + + @override + String get dateInputLabel => 'Enter Date'; + + @override + String get dateRangeStartLabel => 'Start Date'; + + @override + String get dateRangeEndLabel => 'End Date'; + + @override + String dateRangeStartDateSemanticLabel(String formattedDate) => 'Start date $formattedDate'; + + @override + String dateRangeEndDateSemanticLabel(String formattedDate) => 'End date $formattedDate'; + + @override + String get invalidDateFormatLabel => 'Invalid format.'; + + @override + String get invalidDateRangeLabel => 'Invalid range.'; + + @override + String get dateOutOfRangeLabel => 'Out of range.'; + + @override + String get saveButtonLabel => 'Save'; + + @override + String get datePickerHelpText => 'Select date'; + + @override + String get dateRangePickerHelpText => 'Select range'; + + @override + String get calendarModeButtonLabel => 'Switch to calendar'; + + @override + String get inputDateModeButtonLabel => 'Switch to input'; + + @override + String get timePickerDialHelpText => 'Select time'; + + @override + String get timePickerInputHelpText => 'Enter time'; + + @override + String get timePickerHourLabel => 'Hour'; + + @override + String get timePickerMinuteLabel => 'Minute'; + + @override + String get invalidTimeLabel => 'Enter a valid time'; + + @override + String get dialModeButtonLabel => 'Switch to dial picker mode'; + + @override + String get inputTimeModeButtonLabel => 'Switch to text input mode'; + + String _formatDayPeriod(TimeOfDay timeOfDay) { + switch (timeOfDay.period) { + case DayPeriod.am: + return anteMeridiemAbbreviation; + case DayPeriod.pm: + return postMeridiemAbbreviation; + } + } + + @override + String formatDecimal(int number) { + if (number > -1000 && number < 1000) { + return number.toString(); + } + + final String digits = number.abs().toString(); + final StringBuffer result = StringBuffer(number < 0 ? '-' : ''); + final int maxDigitIndex = digits.length - 1; + for (int i = 0; i <= maxDigitIndex; i += 1) { + result.write(digits[i]); + if (i < maxDigitIndex && (maxDigitIndex - i) % 3 == 0) { + result.write(','); + } + } + return result.toString(); + } + + @override + String formatTimeOfDay(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false }) { + // Not using intl.DateFormat for two reasons: + // + // - DateFormat supports more formats than our material time picker does, + // and we want to be consistent across time picker format and the string + // formatting of the time of day. + // - DateFormat operates on DateTime, which is sensitive to time eras and + // time zones, while here we want to format hour and minute within one day + // no matter what date the day falls on. + final StringBuffer buffer = StringBuffer(); + + // Add hour:minute. + buffer + ..write(formatHour(timeOfDay, alwaysUse24HourFormat: alwaysUse24HourFormat)) + ..write(':') + ..write(formatMinute(timeOfDay)); + + if (alwaysUse24HourFormat) { + // There's no AM/PM indicator in 24-hour format. + return '$buffer'; + } + + // Add AM/PM indicator. + buffer + ..write(' ') + ..write(_formatDayPeriod(timeOfDay)); + return '$buffer'; + } + + @override + String get openAppDrawerTooltip => 'Open navigation menu'; + + @override + String get backButtonTooltip => 'Back'; + + @override + String get closeButtonTooltip => 'Close'; + + @override + String get deleteButtonTooltip => 'Delete'; + + @override + String get moreButtonTooltip => 'More'; + + @override + String get nextMonthTooltip => 'Next month'; + + @override + String get previousMonthTooltip => 'Previous month'; + + @override + String get nextPageTooltip => 'Next page'; + + @override + String get previousPageTooltip => 'Previous page'; + + @override + String get firstPageTooltip => 'First page'; + + @override + String get lastPageTooltip => 'Last page'; + + @override + String get showMenuTooltip => 'Show menu'; + + @override + String get drawerLabel => 'Navigation menu'; + + @override + String get menuBarMenuLabel => 'Menu bar menu'; + + @override + String get popupMenuLabel => 'Popup menu'; + + @override + String get dialogLabel => 'Dialog'; + + @override + String get alertDialogLabel => 'Alert'; + + @override + String get searchFieldLabel => 'Search'; + + @override + String get currentDateLabel => 'Today'; + + @override + String get scrimLabel => 'Scrim'; + + @override + String get bottomSheetLabel => 'Bottom Sheet'; + + @override + String scrimOnTapHint(String modalRouteContentName) => 'Close $modalRouteContentName'; + + @override + String aboutListTileTitle(String applicationName) => 'About $applicationName'; + + @override + String get licensesPageTitle => 'Licenses'; + + @override + String licensesPackageDetailText(int licenseCount) { + assert(licenseCount >= 0); + switch (licenseCount) { + case 0: + return 'No licenses.'; + case 1: + return '1 license.'; + default: + return '$licenseCount licenses.'; + } + } + + @override + String pageRowsInfoTitle(int firstRow, int lastRow, int rowCount, bool rowCountIsApproximate) { + return rowCountIsApproximate + ? '$firstRow–$lastRow of about $rowCount' + : '$firstRow–$lastRow of $rowCount'; + } + + @override + String get rowsPerPageTitle => 'Rows per page:'; + + @override + String tabLabel({ required int tabIndex, required int tabCount }) { + assert(tabIndex >= 1); + assert(tabCount >= 1); + return 'Tab $tabIndex of $tabCount'; + } + + @override + String selectedRowCountTitle(int selectedRowCount) { + switch (selectedRowCount) { + case 0: + return 'No items selected'; + case 1: + return '1 item selected'; + default: + return '$selectedRowCount items selected'; + } + } + + @override + String get cancelButtonLabel => 'Cancel'; + + @override + String get closeButtonLabel => 'Close'; + + @override + String get continueButtonLabel => 'Continue'; + + @override + String get copyButtonLabel => 'Copy'; + + @override + String get cutButtonLabel => 'Cut'; + + @override + String get scanTextButtonLabel => 'Scan text'; + + @override + String get okButtonLabel => 'OK'; + + @override + String get pasteButtonLabel => 'Paste'; + + @override + String get selectAllButtonLabel => 'Select all'; + + @override + String get lookUpButtonLabel => 'Look Up'; + + @override + String get searchWebButtonLabel => 'Search Web'; + + @override + String get shareButtonLabel => 'Share'; + + @override + String get viewLicensesButtonLabel => 'View licenses'; + + @override + String get anteMeridiemAbbreviation => 'AM'; + + @override + String get postMeridiemAbbreviation => 'PM'; + + @override + String get timePickerHourModeAnnouncement => 'Select hours'; + + @override + String get timePickerMinuteModeAnnouncement => 'Select minutes'; + + @override + String get modalBarrierDismissLabel => 'Dismiss'; + + @override + String get menuDismissLabel => 'Dismiss menu'; + + @override + ScriptCategory get scriptCategory => ScriptCategory.englishLike; + + @override + TimeOfDayFormat timeOfDayFormat({ bool alwaysUse24HourFormat = false }) { + return alwaysUse24HourFormat + ? TimeOfDayFormat.HH_colon_mm + : TimeOfDayFormat.h_colon_mm_space_a; + } + + @override + String get signedInLabel => 'Signed in'; + + @override + String get hideAccountsLabel => 'Hide accounts'; + + @override + String get showAccountsLabel => 'Show accounts'; + + @override + String get reorderItemUp => 'Move up'; + + @override + String get reorderItemDown => 'Move down'; + + @override + String get reorderItemLeft => 'Move left'; + + @override + String get reorderItemRight => 'Move right'; + + @override + String get reorderItemToEnd => 'Move to the end'; + + @override + String get reorderItemToStart => 'Move to the start'; + + @override + String get expandedIconTapHint => 'Collapse'; + + @override + String get collapsedIconTapHint => 'Expand'; + + @override + String get expansionTileExpandedHint => 'double tap to collapse'; + + @override + String get expansionTileCollapsedHint => 'double tap to expand'; + + @override + String get expansionTileExpandedTapHint => 'Collapse'; + + @override + String get expansionTileCollapsedTapHint => 'Expand for more details'; + + @override + String get expandedHint => 'Collapsed'; + + @override + String get collapsedHint => 'Expanded'; + + @override + String get refreshIndicatorSemanticLabel => 'Refresh'; + + /// Creates an object that provides US English resource values for the material + /// library widgets. + /// + /// The [locale] parameter is ignored. + /// + /// This method is typically used to create a [LocalizationsDelegate]. + /// The [MaterialApp] does so by default. + static Future<MaterialLocalizations> load(Locale locale) { + return SynchronousFuture<MaterialLocalizations>(const DefaultMaterialLocalizations()); + } + + /// A [LocalizationsDelegate] that uses [DefaultMaterialLocalizations.load] + /// to create an instance of this class. + /// + /// [MaterialApp] automatically adds this value to [MaterialApp.localizationsDelegates]. + static const LocalizationsDelegate<MaterialLocalizations> delegate = _MaterialLocalizationsDelegate(); + + @override + String remainingTextFieldCharacterCount(int remaining) { + switch (remaining) { + case 0: + return 'No characters remaining'; + case 1: + return '1 character remaining'; + default: + return '$remaining characters remaining'; + } + } + + @override + String get keyboardKeyAlt => 'Alt'; + + @override + String get keyboardKeyAltGraph => 'AltGr'; + + @override + String get keyboardKeyBackspace => 'Backspace'; + + @override + String get keyboardKeyCapsLock => 'Caps Lock'; + + @override + String get keyboardKeyChannelDown => 'Channel Down'; + + @override + String get keyboardKeyChannelUp => 'Channel Up'; + + @override + String get keyboardKeyControl => 'Ctrl'; + + @override + String get keyboardKeyDelete => 'Del'; + + @override + String get keyboardKeyEject => 'Eject'; + + @override + String get keyboardKeyEnd => 'End'; + + @override + String get keyboardKeyEscape => 'Esc'; + + @override + String get keyboardKeyFn => 'Fn'; + + @override + String get keyboardKeyHome => 'Home'; + + @override + String get keyboardKeyInsert => 'Insert'; + + @override + String get keyboardKeyMeta => 'Meta'; + + @override + String get keyboardKeyMetaMacOs => 'Command'; + + @override + String get keyboardKeyMetaWindows => 'Win'; + + @override + String get keyboardKeyNumLock => 'Num Lock'; + + @override + String get keyboardKeyNumpad1 => 'Num 1'; + + @override + String get keyboardKeyNumpad2 => 'Num 2'; + + @override + String get keyboardKeyNumpad3 => 'Num 3'; + + @override + String get keyboardKeyNumpad4 => 'Num 4'; + + @override + String get keyboardKeyNumpad5 => 'Num 5'; + + @override + String get keyboardKeyNumpad6 => 'Num 6'; + + @override + String get keyboardKeyNumpad7 => 'Num 7'; + + @override + String get keyboardKeyNumpad8 => 'Num 8'; + + @override + String get keyboardKeyNumpad9 => 'Num 9'; + + @override + String get keyboardKeyNumpad0 => 'Num 0'; + + @override + String get keyboardKeyNumpadAdd => 'Num +'; + + @override + String get keyboardKeyNumpadComma => 'Num ,'; + + @override + String get keyboardKeyNumpadDecimal => 'Num .'; + + @override + String get keyboardKeyNumpadDivide => 'Num /'; + + @override + String get keyboardKeyNumpadEnter => 'Num Enter'; + + @override + String get keyboardKeyNumpadEqual => 'Num ='; + + @override + String get keyboardKeyNumpadMultiply => 'Num *'; + + @override + String get keyboardKeyNumpadParenLeft => 'Num ('; + + @override + String get keyboardKeyNumpadParenRight => 'Num )'; + + @override + String get keyboardKeyNumpadSubtract => 'Num -'; + + @override + String get keyboardKeyPageDown => 'PgDown'; + + @override + String get keyboardKeyPageUp => 'PgUp'; + + @override + String get keyboardKeyPower => 'Power'; + + @override + String get keyboardKeyPowerOff => 'Power Off'; + + @override + String get keyboardKeyPrintScreen => 'Print Screen'; + + @override + String get keyboardKeyScrollLock => 'Scroll Lock'; + + @override + String get keyboardKeySelect => 'Select'; + + @override + String get keyboardKeyShift => 'Shift'; + + @override + String get keyboardKeySpace => 'Space'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_state.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_state.dart new file mode 100644 index 0000000000000000000000000000000000000000..59d5dfcb71ee9612c74508237a90b701092a8304 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_state.dart @@ -0,0 +1,765 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; + +import 'input_border.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Interactive states that some of the Material widgets can take on when +/// receiving input from the user. +/// +/// States are defined by https://material.io/design/interaction/states.html#usage. +/// +/// Some Material widgets track their current state in a `Set<MaterialState>`. +/// +/// See also: +/// +/// * [MaterialStateProperty], an interface for objects that "resolve" to +/// different values depending on a widget's material state. +/// {@template flutter.material.MaterialStateProperty.implementations} +/// * [MaterialStateColor], a [Color] that implements `MaterialStateProperty` +/// which is used in APIs that need to accept either a [Color] or a +/// `MaterialStateProperty<Color>`. +/// * [MaterialStateMouseCursor], a [MouseCursor] that implements +/// `MaterialStateProperty` which is used in APIs that need to accept either +/// a [MouseCursor] or a [MaterialStateProperty<MouseCursor>]. +/// * [MaterialStateOutlinedBorder], an [OutlinedBorder] that implements +/// `MaterialStateProperty` which is used in APIs that need to accept either +/// an [OutlinedBorder] or a [MaterialStateProperty<OutlinedBorder>]. +/// * [MaterialStateOutlineInputBorder], an [OutlineInputBorder] that implements +/// `MaterialStateProperty` which is used in APIs that need to accept either +/// an [OutlineInputBorder] or a [MaterialStateProperty<OutlineInputBorder>]. +/// * [MaterialStateUnderlineInputBorder], an [UnderlineInputBorder] that implements +/// `MaterialStateProperty` which is used in APIs that need to accept either +/// an [UnderlineInputBorder] or a [MaterialStateProperty<UnderlineInputBorder>]. +/// * [MaterialStateBorderSide], a [BorderSide] that implements +/// `MaterialStateProperty` which is used in APIs that need to accept either +/// a [BorderSide] or a [MaterialStateProperty<BorderSide>]. +/// * [MaterialStateTextStyle], a [TextStyle] that implements +/// `MaterialStateProperty` which is used in APIs that need to accept either +/// a [TextStyle] or a [MaterialStateProperty<TextStyle>]. +/// {@endtemplate} +enum MaterialState { + /// The state when the user drags their mouse cursor over the given widget. + /// + /// See: https://material.io/design/interaction/states.html#hover. + hovered, + + /// The state when the user navigates with the keyboard to a given widget. + /// + /// This can also sometimes be triggered when a widget is tapped. For example, + /// when a [TextField] is tapped, it becomes [focused]. + /// + /// See: https://material.io/design/interaction/states.html#focus. + focused, + + /// The state when the user is actively pressing down on the given widget. + /// + /// See: https://material.io/design/interaction/states.html#pressed. + pressed, + + /// The state when this widget is being dragged from one place to another by + /// the user. + /// + /// https://material.io/design/interaction/states.html#dragged. + dragged, + + /// The state when this item has been selected. + /// + /// This applies to things that can be toggled (such as chips and checkboxes) + /// and things that are selected from a set of options (such as tabs and radio buttons). + /// + /// See: https://material.io/design/interaction/states.html#selected. + selected, + + /// The state when this widget overlaps the content of a scrollable below. + /// + /// Used by [AppBar] to indicate that the primary scrollable's + /// content has scrolled up and behind the app bar. + scrolledUnder, + + /// The state when this widget is disabled and cannot be interacted with. + /// + /// Disabled widgets should not respond to hover, focus, press, or drag + /// interactions. + /// + /// See: https://material.io/design/interaction/states.html#disabled. + disabled, + + /// The state when the widget has entered some form of invalid state. + /// + /// See https://material.io/design/interaction/states.html#usage. + error, +} + +/// Signature for the function that returns a value of type `T` based on a given +/// set of states. +typedef MaterialPropertyResolver<T> = T Function(Set<MaterialState> states); + +/// Defines a [Color] that is also a [MaterialStateProperty]. +/// +/// This class exists to enable widgets with [Color] valued properties +/// to also accept [MaterialStateProperty<Color>] values. A material +/// state color property represents a color which depends on +/// a widget's "interactive state". This state is represented as a +/// [Set] of [MaterialState]s, like [MaterialState.pressed], +/// [MaterialState.focused] and [MaterialState.hovered]. +/// +/// [MaterialStateColor] should only be used with widgets that document +/// their support, like [TimePickerThemeData.dayPeriodColor]. +/// +/// To use a [MaterialStateColor], you can either: +/// 1. Create a subclass of [MaterialStateColor] and implement the abstract `resolve` method. +/// 2. Use [MaterialStateColor.resolveWith] and pass in a callback that +/// will be used to resolve the color in the given states. +/// +/// If a [MaterialStateColor] is used for a property or a parameter that doesn't +/// support resolving [MaterialStateProperty<Color>]s, then its default color +/// value will be used for all states. +/// +/// To define a `const` [MaterialStateColor], you'll need to extend +/// [MaterialStateColor] and override its [resolve] method. You'll also need +/// to provide a `defaultValue` to the super constructor, so that we can know +/// at compile-time what its default color is. +/// +/// {@tool snippet} +/// +/// This example defines a [MaterialStateColor] with a const constructor. +/// +/// ```dart +/// class MyColor extends MaterialStateColor { +/// const MyColor() : super(_defaultColor); +/// +/// static const int _defaultColor = 0xcafefeed; +/// static const int _pressedColor = 0xdeadbeef; +/// +/// @override +/// Color resolve(Set<MaterialState> states) { +/// if (states.contains(MaterialState.pressed)) { +/// return const Color(_pressedColor); +/// } +/// return const Color(_defaultColor); +/// } +/// } +/// ``` +/// {@end-tool} +abstract class MaterialStateColor extends Color implements MaterialStateProperty<Color> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const MaterialStateColor(super.defaultValue); + + /// Creates a [MaterialStateColor] from a [MaterialPropertyResolver<Color>] + /// callback function. + /// + /// If used as a regular color, the color resolved in the default state (the + /// empty set of states) will be used. + /// + /// The given callback parameter must return a non-null color in the default + /// state. + static MaterialStateColor resolveWith(MaterialPropertyResolver<Color> callback) => _MaterialStateColor(callback); + + /// Returns a [Color] that's to be used when a Material component is in the + /// specified state. + @override + Color resolve(Set<MaterialState> states); +} + +/// A [MaterialStateColor] created from a [MaterialPropertyResolver<Color>] +/// callback alone. +/// +/// If used as a regular color, the color resolved in the default state will +/// be used. +/// +/// Used by [MaterialStateColor.resolveWith]. +class _MaterialStateColor extends MaterialStateColor { + _MaterialStateColor(this._resolve) : super(_resolve(_defaultStates).value); + + final MaterialPropertyResolver<Color> _resolve; + + /// The default state for a Material component, the empty set of interaction states. + static const Set<MaterialState> _defaultStates = <MaterialState>{}; + + @override + Color resolve(Set<MaterialState> states) => _resolve(states); +} + +/// Defines a [MouseCursor] whose value depends on a set of [MaterialState]s which +/// represent the interactive state of a component. +/// +/// This kind of [MouseCursor] is useful when the set of interactive +/// actions a widget supports varies with its state. For example, a +/// mouse pointer hovering over a disabled [ListTile] should not +/// display [SystemMouseCursors.click], since a disabled list tile +/// doesn't respond to mouse clicks. [ListTile]'s default mouse cursor +/// is a [MaterialStateMouseCursor.clickable], which resolves to +/// [SystemMouseCursors.basic] when the button is disabled. +/// +/// To use a [MaterialStateMouseCursor], you should create a subclass of +/// [MaterialStateMouseCursor] and implement the abstract `resolve` method. +/// +/// {@tool dartpad} +/// This example defines a mouse cursor that resolves to +/// [SystemMouseCursors.forbidden] when its widget is disabled. +/// +/// ** See code in examples/api/lib/material/material_state/material_state_mouse_cursor.0.dart ** +/// {@end-tool} +/// +/// This class should only be used for parameters which are documented to take +/// [MaterialStateMouseCursor], otherwise only the default state will be used. +/// +/// See also: +/// +/// * [MouseCursor] for introduction on the mouse cursor system. +/// * [SystemMouseCursors], which defines cursors that are supported by +/// native platforms. +abstract class MaterialStateMouseCursor extends MouseCursor implements MaterialStateProperty<MouseCursor> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const MaterialStateMouseCursor(); + + @protected + @override + MouseCursorSession createSession(int device) { + return resolve(<MaterialState>{}).createSession(device); + } + + /// Returns a [MouseCursor] that's to be used when a Material component is in + /// the specified state. + /// + /// This method should never return null. + @override + MouseCursor resolve(Set<MaterialState> states); + + /// A mouse cursor for clickable material widgets, which resolves differently + /// when the widget is disabled. + /// + /// By default this cursor resolves to [SystemMouseCursors.click]. If the widget is + /// disabled, the cursor resolves to [SystemMouseCursors.basic]. + /// + /// This cursor is the default for many Material widgets. + static const MaterialStateMouseCursor clickable = _EnabledAndDisabledMouseCursor( + enabledCursor: SystemMouseCursors.click, + disabledCursor: SystemMouseCursors.basic, + name: 'clickable', + ); + + /// A mouse cursor for material widgets related to text, which resolves differently + /// when the widget is disabled. + /// + /// By default this cursor resolves to [SystemMouseCursors.text]. If the widget is + /// disabled, the cursor resolves to [SystemMouseCursors.basic]. + /// + /// This cursor is the default for many Material widgets. + static const MaterialStateMouseCursor textable = _EnabledAndDisabledMouseCursor( + enabledCursor: SystemMouseCursors.text, + disabledCursor: SystemMouseCursors.basic, + name: 'textable', + ); +} + +class _EnabledAndDisabledMouseCursor extends MaterialStateMouseCursor { + const _EnabledAndDisabledMouseCursor({ + required this.enabledCursor, + required this.disabledCursor, + required this.name, + }); + + final MouseCursor enabledCursor; + final MouseCursor disabledCursor; + final String name; + + @override + MouseCursor resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabledCursor; + } + return enabledCursor; + } + + @override + String get debugDescription => 'MaterialStateMouseCursor($name)'; +} + +/// Defines a [BorderSide] whose value depends on a set of [MaterialState]s +/// which represent the interactive state of a component. +/// +/// To use a [MaterialStateBorderSide], you should create a subclass of a +/// [MaterialStateBorderSide] and override the abstract `resolve` method. +/// +/// This class enables existing widget implementations with [BorderSide] +/// properties to be extended to also effectively support `MaterialStateProperty<BorderSide>` +/// property values. [MaterialStateBorderSide] should only be used with widgets that document +/// their support, like [ActionChip.side]. +/// +/// {@tool dartpad} +/// This example defines a subclass of [MaterialStateBorderSide], that resolves +/// to a red border side when its widget is selected. +/// +/// ** See code in examples/api/lib/material/material_state/material_state_border_side.0.dart ** +/// {@end-tool} +/// +/// This class should only be used for parameters which are documented to take +/// [MaterialStateBorderSide], otherwise only the default state will be used. +abstract class MaterialStateBorderSide extends BorderSide implements MaterialStateProperty<BorderSide?> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const MaterialStateBorderSide(); + + /// Returns a [BorderSide] that's to be used when a Material component is + /// in the specified state. Return null to defer to the default value of the + /// widget or theme. + @override + BorderSide? resolve(Set<MaterialState> states); + + /// Creates a [MaterialStateBorderSide] from a + /// [MaterialPropertyResolver<BorderSide?>] callback function. + /// + /// If used as a regular [BorderSide], the border resolved in the default state + /// (the empty set of states) will be used. + /// + /// Usage: + /// + /// ```dart + /// ChipTheme( + /// data: Theme.of(context).chipTheme.copyWith( + /// side: MaterialStateBorderSide.resolveWith((Set<MaterialState> states) { + /// if (states.contains(MaterialState.selected)) { + /// return const BorderSide(color: Colors.red); + /// } + /// return null; // Defer to default value on the theme or widget. + /// }), + /// ), + /// child: const Chip( + /// label: Text('Transceiver'), + /// ), + /// ), + /// ``` + /// + /// Alternatively: + /// + /// ```dart + /// Chip( + /// label: const Text('Transceiver'), + /// side: MaterialStateBorderSide.resolveWith((Set<MaterialState> states) { + /// if (states.contains(MaterialState.selected)) { + /// return const BorderSide(color: Colors.red); + /// } + /// return null; // Defer to default value on the theme or widget. + /// }), + /// ), + /// ``` + static MaterialStateBorderSide resolveWith(MaterialPropertyResolver<BorderSide?> callback) => + _MaterialStateBorderSide(callback); +} + +/// A [MaterialStateBorderSide] created from a +/// [MaterialPropertyResolver<BorderSide>] callback alone. +/// +/// If used as a regular side, the side resolved in the default state will +/// be used. +/// +/// Used by [MaterialStateBorderSide.resolveWith]. +class _MaterialStateBorderSide extends MaterialStateBorderSide { + const _MaterialStateBorderSide(this._resolve); + + final MaterialPropertyResolver<BorderSide?> _resolve; + + @override + BorderSide? resolve(Set<MaterialState> states) { + return _resolve(states); + } +} + +/// Defines an [OutlinedBorder] whose value depends on a set of [MaterialState]s +/// which represent the interactive state of a component. +/// +/// To use a [MaterialStateOutlinedBorder], you should create a subclass of an +/// [OutlinedBorder] and implement [MaterialStateOutlinedBorder]'s abstract +/// `resolve` method. +/// +/// {@tool dartpad} +/// This example defines a subclass of [RoundedRectangleBorder] and an +/// implementation of [MaterialStateOutlinedBorder], that resolves to +/// [RoundedRectangleBorder] when its widget is selected. +/// +/// ** See code in examples/api/lib/material/material_state/material_state_outlined_border.0.dart ** +/// {@end-tool} +/// +/// This class should only be used for parameters which are documented to take +/// [MaterialStateOutlinedBorder], otherwise only the default state will be used. +/// +/// See also: +/// +/// * [ShapeBorder] the base class for shape outlines. +abstract class MaterialStateOutlinedBorder extends OutlinedBorder implements MaterialStateProperty<OutlinedBorder?> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const MaterialStateOutlinedBorder(); + + /// Returns an [OutlinedBorder] that's to be used when a Material component is + /// in the specified state. Return null to defer to the default value of the + /// widget or theme. + @override + OutlinedBorder? resolve(Set<MaterialState> states); +} + +/// Defines a [TextStyle] that is also a [MaterialStateProperty]. +/// +/// This class exists to enable widgets with [TextStyle] valued properties +/// to also accept [MaterialStateProperty<TextStyle>] values. A material +/// state text style property represents a text style which depends on +/// a widget's "interactive state". This state is represented as a +/// [Set] of [MaterialState]s, like [MaterialState.pressed], +/// [MaterialState.focused] and [MaterialState.hovered]. +/// +/// [MaterialStateTextStyle] should only be used with widgets that document +/// their support, like [InputDecoration.labelStyle]. +/// +/// To use a [MaterialStateTextStyle], you can either: +/// 1. Create a subclass of [MaterialStateTextStyle] and implement the abstract `resolve` method. +/// 2. Use [MaterialStateTextStyle.resolveWith] and pass in a callback that +/// will be used to resolve the color in the given states. +/// +/// If a [MaterialStateTextStyle] is used for a property or a parameter that doesn't +/// support resolving [MaterialStateProperty<TextStyle>]s, then its default color +/// value will be used for all states. +/// +/// To define a `const` [MaterialStateTextStyle], you'll need to extend +/// [MaterialStateTextStyle] and override its [resolve] method. You'll also need +/// to provide a `defaultValue` to the super constructor, so that we can know +/// at compile-time what its default color is. +abstract class MaterialStateTextStyle extends TextStyle implements MaterialStateProperty<TextStyle> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const MaterialStateTextStyle(); + + /// Creates a [MaterialStateTextStyle] from a [MaterialPropertyResolver<TextStyle>] + /// callback function. + /// + /// If used as a regular text style, the style resolved in the default state (the + /// empty set of states) will be used. + /// + /// The given callback parameter must return a non-null text style in the default + /// state. + static MaterialStateTextStyle resolveWith(MaterialPropertyResolver<TextStyle> callback) => + _MaterialStateTextStyle(callback); + + /// Returns a [TextStyle] that's to be used when a Material component is in the + /// specified state. + @override + TextStyle resolve(Set<MaterialState> states); +} + +/// A [MaterialStateTextStyle] created from a [MaterialPropertyResolver<TextStyle>] +/// callback alone. +/// +/// If used as a regular text style, the style resolved in the default state will +/// be used. +/// +/// Used by [MaterialStateTextStyle.resolveWith]. +class _MaterialStateTextStyle extends MaterialStateTextStyle { + const _MaterialStateTextStyle(this._resolve); + + final MaterialPropertyResolver<TextStyle> _resolve; + + @override + TextStyle resolve(Set<MaterialState> states) => _resolve(states); +} + +/// Defines a [OutlineInputBorder] that is also a [MaterialStateProperty]. +/// +/// This class exists to enable widgets with [OutlineInputBorder] valued properties +/// to also accept [MaterialStateProperty<OutlineInputBorder>] values. A material +/// state input border property represents a text style which depends on +/// a widget's "interactive state". This state is represented as a +/// [Set] of [MaterialState]s, like [MaterialState.pressed], +/// [MaterialState.focused] and [MaterialState.hovered]. +/// +/// [MaterialStateOutlineInputBorder] should only be used with widgets that document +/// their support, like [InputDecoration.border]. +/// +/// To use a [MaterialStateOutlineInputBorder], you can either: +/// 1. Create a subclass of [MaterialStateOutlineInputBorder] and implement the abstract `resolve` method. +/// 2. Use [MaterialStateOutlineInputBorder.resolveWith] and pass in a callback that +/// will be used to resolve the color in the given states. +/// +/// If a [MaterialStateOutlineInputBorder] is used for a property or a parameter that doesn't +/// support resolving [MaterialStateProperty<OutlineInputBorder>]s, then its default color +/// value will be used for all states. +/// +/// To define a `const` [MaterialStateOutlineInputBorder], you'll need to extend +/// [MaterialStateOutlineInputBorder] and override its [resolve] method. You'll also need +/// to provide a `defaultValue` to the super constructor, so that we can know +/// at compile-time what its default color is. +abstract class MaterialStateOutlineInputBorder extends OutlineInputBorder implements MaterialStateProperty<InputBorder> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const MaterialStateOutlineInputBorder(); + + /// Creates a [MaterialStateOutlineInputBorder] from a [MaterialPropertyResolver<InputBorder>] + /// callback function. + /// + /// If used as a regular input border, the border resolved in the default state (the + /// empty set of states) will be used. + /// + /// The given callback parameter must return a non-null text style in the default + /// state. + static MaterialStateOutlineInputBorder resolveWith(MaterialPropertyResolver<InputBorder> callback) => + _MaterialStateOutlineInputBorder(callback); + + /// Returns a [InputBorder] that's to be used when a Material component is in the + /// specified state. + @override + InputBorder resolve(Set<MaterialState> states); +} + +/// A [MaterialStateOutlineInputBorder] created from a [MaterialPropertyResolver<OutlineInputBorder>] +/// callback alone. +/// +/// If used as a regular input border, the border resolved in the default state will +/// be used. +/// +/// Used by [MaterialStateTextStyle.resolveWith]. +class _MaterialStateOutlineInputBorder extends MaterialStateOutlineInputBorder { + const _MaterialStateOutlineInputBorder(this._resolve); + + final MaterialPropertyResolver<InputBorder> _resolve; + + @override + InputBorder resolve(Set<MaterialState> states) => _resolve(states); +} + +/// Defines a [UnderlineInputBorder] that is also a [MaterialStateProperty]. +/// +/// This class exists to enable widgets with [UnderlineInputBorder] valued properties +/// to also accept [MaterialStateProperty<UnderlineInputBorder>] values. A material +/// state input border property represents a text style which depends on +/// a widget's "interactive state". This state is represented as a +/// [Set] of [MaterialState]s, like [MaterialState.pressed], +/// [MaterialState.focused] and [MaterialState.hovered]. +/// +/// [MaterialStateUnderlineInputBorder] should only be used with widgets that document +/// their support, like [InputDecoration.border]. +/// +/// To use a [MaterialStateUnderlineInputBorder], you can either: +/// 1. Create a subclass of [MaterialStateUnderlineInputBorder] and implement the abstract `resolve` method. +/// 2. Use [MaterialStateUnderlineInputBorder.resolveWith] and pass in a callback that +/// will be used to resolve the color in the given states. +/// +/// If a [MaterialStateUnderlineInputBorder] is used for a property or a parameter that doesn't +/// support resolving [MaterialStateProperty<UnderlineInputBorder>]s, then its default color +/// value will be used for all states. +/// +/// To define a `const` [MaterialStateUnderlineInputBorder], you'll need to extend +/// [MaterialStateUnderlineInputBorder] and override its [resolve] method. You'll also need +/// to provide a `defaultValue` to the super constructor, so that we can know +/// at compile-time what its default color is. +abstract class MaterialStateUnderlineInputBorder extends UnderlineInputBorder implements MaterialStateProperty<InputBorder> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const MaterialStateUnderlineInputBorder(); + + /// Creates a [MaterialStateUnderlineInputBorder] from a [MaterialPropertyResolver<InputBorder>] + /// callback function. + /// + /// If used as a regular input border, the border resolved in the default state (the + /// empty set of states) will be used. + /// + /// The given callback parameter must return a non-null text style in the default + /// state. + static MaterialStateUnderlineInputBorder resolveWith(MaterialPropertyResolver<InputBorder> callback) => + _MaterialStateUnderlineInputBorder(callback); + + /// Returns a [InputBorder] that's to be used when a Material component is in the + /// specified state. + @override + InputBorder resolve(Set<MaterialState> states); +} + +/// A [MaterialStateUnderlineInputBorder] created from a [MaterialPropertyResolver<UnderlineInputBorder>] +/// callback alone. +/// +/// If used as a regular input border, the border resolved in the default state will +/// be used. +/// +/// Used by [MaterialStateTextStyle.resolveWith]. +class _MaterialStateUnderlineInputBorder extends MaterialStateUnderlineInputBorder { + const _MaterialStateUnderlineInputBorder(this._resolve); + + final MaterialPropertyResolver<InputBorder> _resolve; + + @override + InputBorder resolve(Set<MaterialState> states) => _resolve(states); +} + +/// Interface for classes that [resolve] to a value of type `T` based +/// on a widget's interactive "state", which is defined as a set +/// of [MaterialState]s. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=CylXr3AF3uU} +/// +/// Material state properties represent values that depend on a widget's material +/// "state". The state is encoded as a set of [MaterialState] values, like +/// [MaterialState.focused], [MaterialState.hovered], [MaterialState.pressed]. For +/// example the [InkWell.overlayColor] defines the color that fills the ink well +/// when it's pressed (the "splash color"), focused, or hovered. The [InkWell] +/// uses the overlay color's [resolve] method to compute the color for the +/// ink well's current state. +/// +/// [ButtonStyle], which is used to configure the appearance of +/// buttons like [TextButton], [ElevatedButton], and [OutlinedButton], +/// has many material state properties. The button widgets keep track +/// of their current material state and [resolve] the button style's +/// material state properties when their value is needed. +/// +/// {@tool dartpad} +/// This example shows how you can override the default text and icon +/// color (the "foreground color") of a [TextButton] with a +/// [MaterialStateProperty]. In this example, the button's text color +/// will be `Colors.blue` when the button is being pressed, hovered, +/// or focused. Otherwise, the text color will be `Colors.red`. +/// +/// ** See code in examples/api/lib/material/material_state/material_state_property.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// {@macro flutter.material.MaterialStateProperty.implementations} +abstract class MaterialStateProperty<T> { + /// Returns a value of type `T` that depends on [states]. + /// + /// Widgets like [TextButton] and [ElevatedButton] apply this method to their + /// current [MaterialState]s to compute colors and other visual parameters + /// at build time. + T resolve(Set<MaterialState> states); + + /// Resolves the value for the given set of states if `value` is a + /// [MaterialStateProperty], otherwise returns the value itself. + /// + /// This is useful for widgets that have parameters which can optionally be a + /// [MaterialStateProperty]. For example, [InkWell.mouseCursor] can be a + /// [MouseCursor] or a [MaterialStateProperty<MouseCursor>]. + static T resolveAs<T>(T value, Set<MaterialState> states) { + if (value is MaterialStateProperty<T>) { + final MaterialStateProperty<T> property = value; + return property.resolve(states); + } + return value; + } + + /// Convenience method for creating a [MaterialStateProperty] from a + /// [MaterialPropertyResolver] function alone. + static MaterialStateProperty<T> resolveWith<T>(MaterialPropertyResolver<T> callback) => _MaterialStatePropertyWith<T>(callback); + + /// Convenience method for creating a [MaterialStateProperty] that resolves + /// to a single value for all states. + /// + /// If you need a const value, use [MaterialStatePropertyAll] directly. + /// + // TODO(darrenaustin): Deprecate this when we have the ability to create + // a dart fix that will replace this with MaterialStatePropertyAll: + // https://github.com/dart-lang/sdk/issues/49056. + static MaterialStateProperty<T> all<T>(T value) => MaterialStatePropertyAll<T>(value); + + /// Linearly interpolate between two [MaterialStateProperty]s. + static MaterialStateProperty<T?>? lerp<T>( + MaterialStateProperty<T>? a, + MaterialStateProperty<T>? b, + double t, + T? Function(T?, T?, double) lerpFunction, + ) { + // Avoid creating a _LerpProperties object for a common case. + if (a == null && b == null) { + return null; + } + return _LerpProperties<T>(a, b, t, lerpFunction); + } +} + +class _LerpProperties<T> implements MaterialStateProperty<T?> { + const _LerpProperties(this.a, this.b, this.t, this.lerpFunction); + + final MaterialStateProperty<T>? a; + final MaterialStateProperty<T>? b; + final double t; + final T? Function(T?, T?, double) lerpFunction; + + @override + T? resolve(Set<MaterialState> states) { + final T? resolvedA = a?.resolve(states); + final T? resolvedB = b?.resolve(states); + return lerpFunction(resolvedA, resolvedB, t); + } +} + +class _MaterialStatePropertyWith<T> implements MaterialStateProperty<T> { + _MaterialStatePropertyWith(this._resolve); + + final MaterialPropertyResolver<T> _resolve; + + @override + T resolve(Set<MaterialState> states) => _resolve(states); +} + +/// Convenience class for creating a [MaterialStateProperty] that +/// resolves to the given value for all states. +class MaterialStatePropertyAll<T> implements MaterialStateProperty<T> { + + /// Constructs a [MaterialStateProperty] that always resolves to the given + /// value. + const MaterialStatePropertyAll(this.value); + + /// The value of the property that will be used for all states. + final T value; + + @override + T resolve(Set<MaterialState> states) => value; + + @override + String toString() { + if (value is double) { + return 'MaterialStatePropertyAll(${debugFormatDouble(value as double)})'; + } else { + return 'MaterialStatePropertyAll($value)'; + } + } +} + +/// Manages a set of [MaterialState]s and notifies listeners of changes. +/// +/// Used by widgets that expose their internal state for the sake of +/// extensions that add support for additional states. See +/// [TextButton] for an example. +/// +/// The controller's [value] is its current set of states. Listeners +/// are notified whenever the [value] changes. The [value] should only be +/// changed with [update]; it should not be modified directly. +/// +/// The controller's [value] represents the set of states that a +/// widget's visual properties, typically [MaterialStateProperty] +/// values, are resolved against. It is _not_ the intrinsic state of +/// the widget. The widget is responsible for ensuring that the +/// controller's [value] tracks its intrinsic state. For example one +/// cannot request the keyboard focus for a widget by adding +/// [MaterialState.focused] to its controller. When the widget gains the +/// or loses the focus it will [update] its controller's [value] and +/// notify listeners of the change. +class MaterialStatesController extends ValueNotifier<Set<MaterialState>> { + /// Creates a MaterialStatesController. + MaterialStatesController([Set<MaterialState>? value]) : super(<MaterialState>{...?value}); + + /// Adds [state] to [value] if [add] is true, and removes it otherwise, + /// and notifies listeners if [value] has changed. + void update(MaterialState state, bool add) { + final bool valueChanged = add ? value.add(state) : value.remove(state); + if (valueChanged) { + notifyListeners(); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_state_mixin.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_state_mixin.dart new file mode 100644 index 0000000000000000000000000000000000000000..5b9b23d2f1e50970cd6715a22f1dd91196dd1e2a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/material_state_mixin.dart @@ -0,0 +1,170 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; + +/// Mixin for [State] classes that require knowledge of changing [MaterialState] +/// values for their child widgets. +/// +/// This mixin does nothing by mere application to a [State] class, but is +/// helpful when writing `build` methods that include child [InkWell], +/// [GestureDetector], [MouseRegion], or [Focus] widgets. Instead of manually +/// creating handlers for each type of user interaction, such [State] classes can +/// instead provide a `ValueChanged<bool>` function and allow [MaterialStateMixin] +/// to manage the set of active [MaterialState]s, and the calling of [setState] +/// as necessary. +/// +/// {@tool snippet} +/// This example shows how to write a [StatefulWidget] that uses the +/// [MaterialStateMixin] class to watch [MaterialState] values. +/// +/// ```dart +/// class MyWidget extends StatefulWidget { +/// const MyWidget({super.key, required this.color, required this.child}); +/// +/// final MaterialStateColor color; +/// final Widget child; +/// +/// @override +/// State<MyWidget> createState() => MyWidgetState(); +/// } +/// +/// class MyWidgetState extends State<MyWidget> with MaterialStateMixin<MyWidget> { +/// @override +/// Widget build(BuildContext context) { +/// return InkWell( +/// onFocusChange: updateMaterialState(MaterialState.focused), +/// child: ColoredBox( +/// color: widget.color.resolve(materialStates), +/// child: widget.child, +/// ), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +@optionalTypeArgs +mixin MaterialStateMixin<T extends StatefulWidget> on State<T> { + /// Managed set of active [MaterialState] values; designed to be passed to + /// [MaterialStateProperty.resolve] methods. + /// + /// To mutate and have [setState] called automatically for you, use + /// [setMaterialState], [addMaterialState], or [removeMaterialState]. Directly + /// mutating the set is possible, and may be necessary if you need to alter its + /// list without calling [setState] (and thus triggering a re-render). + /// + /// To check for a single condition, convenience getters [isPressed], [isHovered], + /// [isFocused], etc, are available for each [MaterialState] value. + @protected + Set<MaterialState> materialStates = <MaterialState>{}; + + /// Callback factory which accepts a [MaterialState] value and returns a + /// closure to mutate [materialStates] and call [setState]. + /// + /// Accepts an optional second named parameter, `onChanged`, which allows + /// arbitrary functionality to be wired through the [MaterialStateMixin]. + /// If supplied, the [onChanged] function is only called when child widgets + /// report events that make changes to the current set of [MaterialState]s. + /// + /// {@tool snippet} + /// This example shows how to use the [updateMaterialState] callback factory + /// in other widgets, including the optional [onChanged] callback. + /// + /// ```dart + /// class MyWidget extends StatefulWidget { + /// const MyWidget({super.key, this.onPressed}); + /// + /// /// Something important this widget must do when pressed. + /// final VoidCallback? onPressed; + /// + /// @override + /// State<MyWidget> createState() => MyWidgetState(); + /// } + /// + /// class MyWidgetState extends State<MyWidget> with MaterialStateMixin<MyWidget> { + /// @override + /// Widget build(BuildContext context) { + /// return ColoredBox( + /// color: isPressed ? Colors.black : Colors.white, + /// child: InkWell( + /// onHighlightChanged: updateMaterialState( + /// MaterialState.pressed, + /// onChanged: (bool val) { + /// if (val) { + /// widget.onPressed?.call(); + /// } + /// }, + /// ), + /// ), + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + @protected + ValueChanged<bool> updateMaterialState(MaterialState key, {ValueChanged<bool>? onChanged}) { + return (bool value) { + if (materialStates.contains(key) == value) { + return; + } + setMaterialState(key, value); + onChanged?.call(value); + }; + } + + /// Mutator to mark a [MaterialState] value as either active or inactive. + @protected + void setMaterialState(MaterialState state, bool isSet) { + return isSet ? addMaterialState(state) : removeMaterialState(state); + } + + /// Mutator to mark a [MaterialState] value as active. + @protected + void addMaterialState(MaterialState state) { + if (materialStates.add(state)) { + setState((){}); + } + } + + /// Mutator to mark a [MaterialState] value as inactive. + @protected + void removeMaterialState(MaterialState state) { + if (materialStates.remove(state)) { + setState((){}); + } + } + + /// Getter for whether this class considers [MaterialState.disabled] to be active. + bool get isDisabled => materialStates.contains(MaterialState.disabled); + + /// Getter for whether this class considers [MaterialState.dragged] to be active. + bool get isDragged => materialStates.contains(MaterialState.dragged); + + /// Getter for whether this class considers [MaterialState.error] to be active. + bool get isErrored => materialStates.contains(MaterialState.error); + + /// Getter for whether this class considers [MaterialState.focused] to be active. + bool get isFocused => materialStates.contains(MaterialState.focused); + + /// Getter for whether this class considers [MaterialState.hovered] to be active. + bool get isHovered => materialStates.contains(MaterialState.hovered); + + /// Getter for whether this class considers [MaterialState.pressed] to be active. + bool get isPressed => materialStates.contains(MaterialState.pressed); + + /// Getter for whether this class considers [MaterialState.scrolledUnder] to be active. + bool get isScrolledUnder => materialStates.contains(MaterialState.scrolledUnder); + + /// Getter for whether this class considers [MaterialState.selected] to be active. + bool get isSelected => materialStates.contains(MaterialState.selected); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Set<MaterialState>>('materialStates', materialStates, defaultValue: <MaterialState>{})); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_anchor.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_anchor.dart new file mode 100644 index 0000000000000000000000000000000000000000..e2e602aee0c2ffb8e2c673adc2cda4e21b543720 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_anchor.dart @@ -0,0 +1,3962 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'button_style_button.dart'; +import 'checkbox.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'menu_bar_theme.dart'; +import 'menu_button_theme.dart'; +import 'menu_style.dart'; +import 'menu_theme.dart'; +import 'radio.dart'; +import 'scrollbar.dart'; +import 'text_button.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// bool _throwShotAway = false; +// late BuildContext context; +// enum SingingCharacter { lafayette } +// late SingingCharacter? _character; +// late StateSetter setState; + +// Enable if you want verbose logging about menu changes. +const bool _kDebugMenus = false; + +// The default size of the arrow in _MenuItemLabel that indicates that a menu +// has a submenu. +const double _kDefaultSubmenuIconSize = 24; + +// The default spacing between the leading icon, label, trailing icon, and +// shortcut label in a _MenuItemLabel. +const double _kLabelItemDefaultSpacing = 12; + +// The minimum spacing between the leading icon, label, trailing icon, and +// shortcut label in a _MenuItemLabel. +const double _kLabelItemMinSpacing = 4; + +// Navigation shortcuts that we need to make sure are active when menus are +// open. +const Map<ShortcutActivator, Intent> _kMenuTraversalShortcuts = <ShortcutActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.gameButtonA): ActivateIntent(), + SingleActivator(LogicalKeyboardKey.escape): DismissIntent(), + SingleActivator(LogicalKeyboardKey.tab): NextFocusIntent(), + SingleActivator(LogicalKeyboardKey.tab, shift: true): PreviousFocusIntent(), + SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent(TraversalDirection.down), + SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent(TraversalDirection.up), + SingleActivator(LogicalKeyboardKey.arrowLeft): DirectionalFocusIntent(TraversalDirection.left), + SingleActivator(LogicalKeyboardKey.arrowRight): DirectionalFocusIntent(TraversalDirection.right), +}; + +// The minimum vertical spacing on the outside of menus. +const double _kMenuVerticalMinPadding = 8; + +// How close to the edge of the safe area the menu will be placed. +const double _kMenuViewPadding = 8; + +// The minimum horizontal spacing on the outside of the top level menu. +const double _kTopLevelMenuHorizontalMinPadding = 4; + +/// The type of builder function used by [MenuAnchor.builder] to build the +/// widget that the [MenuAnchor] surrounds. +/// +/// The `context` is the context that the widget is being built in. +/// +/// The `controller` is the [MenuController] that can be used to open and close +/// the menu with. +/// +/// The `child` is an optional child supplied as the [MenuAnchor.child] +/// attribute. The child is intended to be incorporated in the result of the +/// function. +typedef MenuAnchorChildBuilder = Widget Function( + BuildContext context, + MenuController controller, + Widget? child, +); + +/// A widget used to mark the "anchor" for a set of submenus, defining the +/// rectangle used to position the menu, which can be done either with an +/// explicit location, or with an alignment. +/// +/// When creating a menu with [MenuBar] or a [SubmenuButton], a [MenuAnchor] is +/// not needed, since they provide their own internally. +/// +/// The [MenuAnchor] is meant to be a slightly lower level interface than +/// [MenuBar], used in situations where a [MenuBar] isn't appropriate, or to +/// construct widgets or screen regions that have submenus. +/// +/// {@tool dartpad} +/// This example shows how to use a [MenuAnchor] to wrap a button and open a +/// cascading menu from the button. +/// +/// ** See code in examples/api/lib/material/menu_anchor/menu_anchor.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to use a [MenuAnchor] to create a cascading context +/// menu in a region of the view, positioned where the user clicks the mouse +/// with Ctrl pressed. The [anchorTapClosesMenu] attribute is set to true so +/// that clicks on the [MenuAnchor] area will cause the menus to be closed. +/// +/// ** See code in examples/api/lib/material/menu_anchor/menu_anchor.1.dart ** +/// {@end-tool} +class MenuAnchor extends StatefulWidget { + /// Creates a const [MenuAnchor]. + /// + /// The [menuChildren] argument is required. + const MenuAnchor({ + super.key, + this.controller, + this.childFocusNode, + this.style, + this.alignmentOffset = Offset.zero, + this.clipBehavior = Clip.hardEdge, + @Deprecated( + 'Use consumeOutsideTap instead. ' + 'This feature was deprecated after v3.16.0-8.0.pre.', + ) + this.anchorTapClosesMenu = false, + this.consumeOutsideTap = false, + this.onOpen, + this.onClose, + this.crossAxisUnconstrained = true, + required this.menuChildren, + this.builder, + this.child, + }); + + /// An optional controller that allows opening and closing of the menu from + /// other widgets. + final MenuController? controller; + + /// The [childFocusNode] attribute is the optional [FocusNode] also associated + /// the [child] or [builder] widget that opens the menu. + /// + /// The focus node should be attached to the widget that should receive focus + /// if keyboard focus traversal moves the focus off of the submenu with the + /// arrow keys. + /// + /// If not supplied, then keyboard traversal from the menu back to the + /// controlling button when the menu is open is disabled. + final FocusNode? childFocusNode; + + /// The [MenuStyle] that defines the visual attributes of the menu bar. + /// + /// Colors and sizing of the menus is controllable via the [MenuStyle]. + /// + /// Defaults to the ambient [MenuThemeData.style]. + final MenuStyle? style; + + /// The offset of the menu relative to the alignment origin determined by + /// [MenuStyle.alignment] on the [style] attribute and the ambient + /// [Directionality]. + /// + /// Use this for adjustments of the menu placement. + /// + /// Increasing [Offset.dy] values of [alignmentOffset] move the menu position + /// down. + /// + /// If the [MenuStyle.alignment] from [style] is not an [AlignmentDirectional] + /// (e.g. [Alignment]), then increasing [Offset.dx] values of + /// [alignmentOffset] move the menu position to the right. + /// + /// If the [MenuStyle.alignment] from [style] is an [AlignmentDirectional], + /// then in a [TextDirection.ltr] [Directionality], increasing [Offset.dx] + /// values of [alignmentOffset] move the menu position to the right. In a + /// [TextDirection.rtl] directionality, increasing [Offset.dx] values of + /// [alignmentOffset] move the menu position to the left. + /// + /// Defaults to [Offset.zero]. + final Offset? alignmentOffset; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// Whether the menus will be closed if the anchor area is tapped. + /// + /// For menus opened by buttons that toggle the menu, if the button is tapped + /// when the menu is open, the button should close the menu. But if + /// [anchorTapClosesMenu] is true, then the menu will close, and + /// (surprisingly) immediately re-open. This is because tapping on the button + /// closes the menu before the `onPressed` or `onTap` handler is called + /// because of it being considered to be "outside" the menu system, and then + /// the button (seeing that the menu is closed) immediately reopens the menu. + /// The result is that the user thinks that tapping on the button does + /// nothing. So, for button-initiated menus, this value is typically false so + /// that the menu anchor area is considered "inside" of the menu system and + /// doesn't cause it to close unless [MenuController.close] is called. + /// + /// For menus that are positioned using [MenuController.open]'s `position` + /// parameter, it is often desirable that clicking on the anchor always closes + /// the menu since the anchor area isn't usually considered part of the menu + /// system by the user. In this case [anchorTapClosesMenu] should be true. + /// + /// Defaults to false. + @Deprecated( + 'Use consumeOutsideTap instead. ' + 'This feature was deprecated after v3.16.0-8.0.pre.', + ) + final bool anchorTapClosesMenu; + + /// Whether or not a tap event that closes the menu will be permitted to + /// continue on to the gesture arena. + /// + /// If false, then tapping outside of a menu when the menu is open will both + /// close the menu, and allow the tap to participate in the gesture arena. If + /// true, then it will only close the menu, and the tap event will be + /// consumed. + /// + /// Defaults to false. + final bool consumeOutsideTap; + + /// A callback that is invoked when the menu is opened. + final VoidCallback? onOpen; + + /// A callback that is invoked when the menu is closed. + final VoidCallback? onClose; + + /// Determine if the menu panel can be wrapped by a [UnconstrainedBox] which allows + /// the panel to render at its "natural" size. + /// + /// Defaults to true as it allows developers to render the menu panel at the + /// size it should be. When it is set to false, it can be useful when the menu should + /// be constrained in both main axis and cross axis, such as a [DropdownMenu]. + final bool crossAxisUnconstrained; + + /// A list of children containing the menu items that are the contents of the + /// menu surrounded by this [MenuAnchor]. + /// + /// {@macro flutter.material.MenuBar.shortcuts_note} + final List<Widget> menuChildren; + + /// The widget that this [MenuAnchor] surrounds. + /// + /// Typically this is a button used to open the menu by calling + /// [MenuController.open] on the `controller` passed to the builder. + /// + /// If not supplied, then the [MenuAnchor] will be the size that its parent + /// allocates for it. + final MenuAnchorChildBuilder? builder; + + /// The optional child to be passed to the [builder]. + /// + /// Supply this child if there is a portion of the widget tree built in + /// [builder] that doesn't depend on the `controller` or `context` supplied to + /// the [builder]. It will be more efficient, since Flutter doesn't then need + /// to rebuild this child when those change. + final Widget? child; + + @override + State<MenuAnchor> createState() => _MenuAnchorState(); + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return menuChildren.map<DiagnosticsNode>((Widget child) => child.toDiagnosticsNode()).toList(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('anchorTapClosesMenu', value: anchorTapClosesMenu, ifTrue: 'AUTO-CLOSE')); + properties.add(DiagnosticsProperty<FocusNode?>('focusNode', childFocusNode)); + properties.add(DiagnosticsProperty<MenuStyle?>('style', style)); + properties.add(EnumProperty<Clip>('clipBehavior', clipBehavior)); + properties.add(DiagnosticsProperty<Offset?>('alignmentOffset', alignmentOffset)); + properties.add(StringProperty('child', child.toString())); + } +} + +class _MenuAnchorState extends State<MenuAnchor> { + // This is the global key that is used later to determine the bounding rect + // for the anchor's region that the CustomSingleChildLayout's delegate + // uses to determine where to place the menu on the screen and to avoid the + // view's edges. + final GlobalKey<_MenuAnchorState> _anchorKey = GlobalKey<_MenuAnchorState>(debugLabel: kReleaseMode ? null : 'MenuAnchor'); + _MenuAnchorState? _parent; + late final FocusScopeNode _menuScopeNode; + MenuController? _internalMenuController; + final List<_MenuAnchorState> _anchorChildren = <_MenuAnchorState>[]; + ScrollPosition? _scrollPosition; + Size? _viewSize; + final OverlayPortalController _overlayController = OverlayPortalController(debugLabel: kReleaseMode ? null : 'MenuAnchor controller'); + Offset? _menuPosition; + Axis get _orientation => Axis.vertical; + bool get _isOpen => _overlayController.isShowing; + bool get _isRoot => _parent == null; + bool get _isTopLevel => _parent?._isRoot ?? false; + MenuController get _menuController => widget.controller ?? _internalMenuController!; + + @override + void initState() { + super.initState(); + _menuScopeNode = FocusScopeNode(debugLabel: kReleaseMode ? null : '${describeIdentity(this)} Sub Menu'); + if (widget.controller == null) { + _internalMenuController = MenuController(); + } + _menuController._attach(this); + } + + @override + void dispose() { + assert(_debugMenuInfo('Disposing of $this')); + if (_isOpen) { + _close(inDispose: true); + _parent?._removeChild(this); + } + _anchorChildren.clear(); + _menuController._detach(this); + _internalMenuController = null; + _menuScopeNode.dispose(); + super.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final _MenuAnchorState? newParent = _MenuAnchorState._maybeOf(context); + if (newParent != _parent) { + _parent?._removeChild(this); + _parent = newParent; + _parent?._addChild(this); + } + _scrollPosition?.isScrollingNotifier.removeListener(_handleScroll); + _scrollPosition = Scrollable.maybeOf(context)?.position; + _scrollPosition?.isScrollingNotifier.addListener(_handleScroll); + final Size newSize = MediaQuery.sizeOf(context); + if (_viewSize != null && newSize != _viewSize) { + // Close the menus if the view changes size. + _root._close(); + } + _viewSize = newSize; + } + + @override + void didUpdateWidget(MenuAnchor oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.controller != widget.controller) { + oldWidget.controller?._detach(this); + if (widget.controller != null) { + _internalMenuController?._detach(this); + _internalMenuController = null; + widget.controller?._attach(this); + } else { + assert(_internalMenuController == null); + _internalMenuController = MenuController().._attach(this); + } + } + assert(_menuController._anchor == this); + } + + @override + Widget build(BuildContext context) { + Widget child = OverlayPortal( + controller: _overlayController, + overlayChildBuilder: (BuildContext context) { + return _Submenu( + anchor: this, + menuStyle: widget.style, + alignmentOffset: widget.alignmentOffset ?? Offset.zero, + menuPosition: _menuPosition, + clipBehavior: widget.clipBehavior, + menuChildren: widget.menuChildren, + crossAxisUnconstrained: widget.crossAxisUnconstrained, + ); + }, + child: _buildContents(context), + ); + + if (!widget.anchorTapClosesMenu) { + child = TapRegion( + groupId: _root, + consumeOutsideTaps: _root._isOpen && widget.consumeOutsideTap, + onTapOutside: (PointerDownEvent event) { + assert(_debugMenuInfo('Tapped Outside ${widget.controller}')); + _closeChildren(); + }, + child: child, + ); + } + + return _MenuAnchorScope( + anchorKey: _anchorKey, + anchor: this, + isOpen: _isOpen, + child: child, + ); + } + + Widget _buildContents(BuildContext context) { + return Actions( + actions: <Type, Action<Intent>>{ + DirectionalFocusIntent: _MenuDirectionalFocusAction(), + PreviousFocusIntent: _MenuPreviousFocusAction(), + NextFocusIntent: _MenuNextFocusAction(), + DismissIntent: DismissMenuAction(controller: _menuController), + }, + child: Builder( + key: _anchorKey, + builder: (BuildContext context) { + return widget.builder?.call(context, _menuController, widget.child) + ?? widget.child ?? const SizedBox(); + }, + ), + ); + } + + // Returns the first focusable item in the submenu, where "first" is + // determined by the focus traversal policy. + FocusNode? get _firstItemFocusNode { + if (_menuScopeNode.context == null) { + return null; + } + final FocusTraversalPolicy policy = + FocusTraversalGroup.maybeOf(_menuScopeNode.context!) ?? ReadingOrderTraversalPolicy(); + return policy.findFirstFocus(_menuScopeNode, ignoreCurrentFocus: true); + } + + void _addChild(_MenuAnchorState child) { + assert(_isRoot || _debugMenuInfo('Added root child: $child')); + assert(!_anchorChildren.contains(child)); + _anchorChildren.add(child); + assert(_debugMenuInfo('Added:\n${child.widget.toStringDeep()}')); + assert(_debugMenuInfo('Tree:\n${widget.toStringDeep()}')); + } + + void _removeChild(_MenuAnchorState child) { + assert(_isRoot || _debugMenuInfo('Removed root child: $child')); + assert(_anchorChildren.contains(child)); + assert(_debugMenuInfo('Removing:\n${child.widget.toStringDeep()}')); + _anchorChildren.remove(child); + assert(_debugMenuInfo('Tree:\n${widget.toStringDeep()}')); + } + + List<_MenuAnchorState> _getFocusableChildren() { + if (_parent == null) { + return <_MenuAnchorState>[]; + } + return _parent!._anchorChildren.where((_MenuAnchorState menu) { + return menu.widget.childFocusNode?.canRequestFocus ?? false; + },).toList(); + } + + _MenuAnchorState? get _nextFocusableSibling { + final List<_MenuAnchorState> focusable = _getFocusableChildren(); + if (focusable.isEmpty) { + return null; + } + return focusable[(focusable.indexOf(this) + 1) % focusable.length]; + } + +_MenuAnchorState? get _previousFocusableSibling { + final List<_MenuAnchorState> focusable = _getFocusableChildren(); + if (focusable.isEmpty) { + return null; + } + return focusable[(focusable.indexOf(this) - 1 + focusable.length) % focusable.length]; +} + + _MenuAnchorState get _root { + _MenuAnchorState anchor = this; + while (anchor._parent != null) { + anchor = anchor._parent!; + } + return anchor; + } + + _MenuAnchorState get _topLevel { + _MenuAnchorState handle = this; + while (handle._parent != null && !handle._parent!._isTopLevel) { + handle = handle._parent!; + } + return handle; + } + + void _childChangedOpenState() { + _parent?._childChangedOpenState(); + assert(mounted); + if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks) { + setState(() { + // Mark dirty now, but only if not in a build. + }); + } else { + SchedulerBinding.instance.addPostFrameCallback((Duration _) { + setState(() { + // Mark dirty after this frame, but only if in a build. + }); + }); + } + + } + + void _focusButton() { + if (widget.childFocusNode == null) { + return; + } + assert(_debugMenuInfo('Requesting focus for ${widget.childFocusNode}')); + widget.childFocusNode!.requestFocus(); + } + + void _handleScroll() { + // If an ancestor scrolls, and we're a root anchor, then close the menus. + // Don't just close it on *any* scroll, since we want to be able to scroll + // menus themselves if they're too big for the view. + if (_isRoot) { + _close(); + } + } + + KeyEventResult _checkForEscape(KeyEvent event) { + if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.escape) { + _close(); + return KeyEventResult.handled; + } + return KeyEventResult.ignored; + } + + /// Open the menu, optionally at a position relative to the [MenuAnchor]. + /// + /// Call this when the menu should be shown to the user. + /// + /// The optional `position` argument will specify the location of the menu in + /// the local coordinates of the [MenuAnchor], ignoring any + /// [MenuStyle.alignment] and/or [MenuAnchor.alignmentOffset] that were + /// specified. + void _open({Offset? position}) { + assert(_menuController._anchor == this); + if (_isOpen && position == null) { + assert(_debugMenuInfo("Not opening $this because it's already open")); + return; + } + if (_isOpen && position != null) { + // The menu is already open, but we need to move to another location, so + // close it first. + _close(); + } + assert(_debugMenuInfo( + 'Opening $this at ${position ?? Offset.zero} with alignment offset ${widget.alignmentOffset ?? Offset.zero}')); + _parent?._closeChildren(); // Close all siblings. + assert(!_overlayController.isShowing); + + _parent?._childChangedOpenState(); + _menuPosition = position; + _overlayController.show(); + + widget.onOpen?.call(); + } + + /// Close the menu. + /// + /// Call this when the menu should be closed. Has no effect if the menu is + /// already closed. + void _close({bool inDispose = false}) { + assert(_debugMenuInfo('Closing $this')); + if (!_isOpen) { + return; + } + if (_isRoot) { + FocusManager.instance.removeEarlyKeyEventHandler(_checkForEscape); + } + _closeChildren(inDispose: inDispose); + // Don't hide if we're in the middle of a build. + if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks) { + _overlayController.hide(); + } else if (!inDispose) { + SchedulerBinding.instance.addPostFrameCallback((_) { + _overlayController.hide(); + }, debugLabel: 'MenuAnchor.hide'); + } + if (!inDispose) { + // Notify that _childIsOpen changed state, but only if not + // currently disposing. + _parent?._childChangedOpenState(); + widget.onClose?.call(); + if (mounted && SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks) { + setState(() { + // Mark dirty, but only if mounted and not in a build. + }); + } + } + } + + void _closeChildren({bool inDispose = false}) { + assert(_debugMenuInfo('Closing children of $this${inDispose ? ' (dispose)' : ''}')); + for (final _MenuAnchorState child in List<_MenuAnchorState>.from(_anchorChildren)) { + child._close(inDispose: inDispose); + } + } + + // Returns the active anchor in the given context, if any, and creates a + // dependency relationship that will rebuild the context when the node + // changes. + static _MenuAnchorState? _maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<_MenuAnchorScope>()?.anchor; + } + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.debug}) { + return describeIdentity(this); + } +} + +/// A controller to manage a menu created by a [MenuBar] or [MenuAnchor]. +/// +/// A [MenuController] is used to control and interrogate a menu after it has +/// been created, with methods such as [open] and [close], and state accessors +/// like [isOpen]. +/// +/// See also: +/// +/// * [MenuAnchor], a widget that defines a region that has submenu. +/// * [MenuBar], a widget that creates a menu bar, that can take an optional +/// [MenuController]. +/// * [SubmenuButton], a widget that has a button that manages a submenu. +class MenuController { + /// The anchor that this controller controls. + /// + /// This is set automatically when a [MenuController] is given to the anchor + /// it controls. + _MenuAnchorState? _anchor; + + /// Whether or not the associated menu is currently open. + bool get isOpen { + assert(_anchor != null); + return _anchor!._isOpen; + } + + /// Close the menu that this menu controller is associated with. + /// + /// Associating with a menu is done by passing a [MenuController] to a + /// [MenuAnchor]. A [MenuController] is also be received by the + /// [MenuAnchor.builder] when invoked. + /// + /// If the menu's anchor point (either a [MenuBar] or a [MenuAnchor]) is + /// scrolled by an ancestor, or the view changes size, then any open menu will + /// automatically close. + void close() { + assert(_anchor != null); + _anchor!._close(); + } + + /// Opens the menu that this menu controller is associated with. + /// + /// If `position` is given, then the menu will open at the position given, in + /// the coordinate space of the [MenuAnchor] this controller is attached to. + /// + /// If given, the `position` will override the [MenuAnchor.alignmentOffset] + /// given to the [MenuAnchor]. + /// + /// If the menu's anchor point (either a [MenuBar] or a [MenuAnchor]) is + /// scrolled by an ancestor, or the view changes size, then any open menu will + /// automatically close. + void open({Offset? position}) { + assert(_anchor != null); + _anchor!._open(position: position); + } + + // ignore: use_setters_to_change_properties + void _attach(_MenuAnchorState anchor) { + _anchor = anchor; + } + + void _detach(_MenuAnchorState anchor) { + if (_anchor == anchor) { + _anchor = null; + } + } +} + +/// A menu bar that manages cascading child menus. +/// +/// This is a Material Design menu bar that typically resides above the main +/// body of an application (but can go anywhere) that defines a menu system for +/// invoking callbacks in response to user selection of a menu item. +/// +/// The menus can be opened with a click or tap. Once a menu is opened, it can +/// be navigated by using the arrow and tab keys or via mouse hover. Selecting a +/// menu item can be done by pressing enter, or by clicking or tapping on the +/// menu item. Clicking or tapping on any part of the user interface that isn't +/// part of the menu system controlled by the same controller will cause all of +/// the menus controlled by that controller to close, as will pressing the +/// escape key. +/// +/// When a menu item with a submenu is clicked on, it toggles the visibility of +/// the submenu. When the menu item is hovered over, the submenu will open, and +/// hovering over other items will close the previous menu and open the newly +/// hovered one. When those open/close transitions occur, +/// [SubmenuButton.onOpen], and [SubmenuButton.onClose] are called on the +/// corresponding [SubmenuButton] child of the menu bar. +/// +/// {@template flutter.material.MenuBar.shortcuts_note} +/// Menus using [MenuItemButton] can have a [SingleActivator] or +/// [CharacterActivator] assigned to them as their [MenuItemButton.shortcut], +/// which will display an appropriate shortcut hint. Even though the shortcut +/// labels are displayed in the menu, shortcuts are not automatically handled. +/// They must be available in whatever context they are appropriate, and handled +/// via another mechanism. +/// +/// If shortcuts should be generally enabled, but are not easily defined in a +/// context surrounding the menu bar, consider registering them with a +/// [ShortcutRegistry] (one is already included in the [WidgetsApp], and thus +/// also [MaterialApp] and [CupertinoApp]), as shown in the example below. To be +/// sure that selecting a menu item and triggering the shortcut do the same +/// thing, it is recommended that they call the same callback. +/// +/// {@tool dartpad} This example shows a [MenuBar] that contains a single top +/// level menu, containing three items: "About", a checkbox menu item for +/// showing a message, and "Quit". The items are identified with an enum value, +/// and the shortcuts are registered globally with the [ShortcutRegistry]. +/// +/// ** See code in examples/api/lib/material/menu_anchor/menu_bar.0.dart ** +/// {@end-tool} +/// {@endtemplate} +/// +/// {@macro flutter.material.MenuAcceleratorLabel.accelerator_sample} +/// +/// See also: +/// +/// * [MenuAnchor], a widget that creates a region with a submenu and shows it +/// when requested. +/// * [SubmenuButton], a menu item which manages a submenu. +/// * [MenuItemButton], a leaf menu item which displays the label, an optional +/// shortcut label, and optional leading and trailing icons. +/// * [PlatformMenuBar], which creates a menu bar that is rendered by the host +/// platform instead of by Flutter (on macOS, for example). +/// * [ShortcutRegistry], a registry of shortcuts that apply for the entire +/// application. +/// * [VoidCallbackIntent], to define intents that will call a [VoidCallback] and +/// work with the [Actions] and [Shortcuts] system. +/// * [CallbackShortcuts], to define shortcuts that call a callback without +/// involving [Actions]. +class MenuBar extends StatelessWidget { + /// Creates a const [MenuBar]. + /// + /// The [children] argument is required. + const MenuBar({ + super.key, + this.style, + this.clipBehavior = Clip.none, + this.controller, + required this.children, + }); + + /// The [MenuStyle] that defines the visual attributes of the menu bar. + /// + /// Colors and sizing of the menus is controllable via the [MenuStyle]. + /// + /// Defaults to the ambient [MenuThemeData.style]. + final MenuStyle? style; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// The [MenuController] to use for this menu bar. + final MenuController? controller; + + /// The list of menu items that are the top level children of the [MenuBar]. + /// + /// A Widget in Flutter is immutable, so directly modifying the [children] + /// with [List] APIs such as `someMenuBarWidget.menus.add(...)` will result in + /// incorrect behaviors. Whenever the menus list is modified, a new list + /// object must be provided. + /// + /// {@macro flutter.material.MenuBar.shortcuts_note} + final List<Widget> children; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasOverlay(context)); + return _MenuBarAnchor( + controller: controller, + clipBehavior: clipBehavior, + style: style, + menuChildren: children, + ); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return <DiagnosticsNode>[ + ...children.map<DiagnosticsNode>( + (Widget item) => item.toDiagnosticsNode(), + ), + ]; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MenuStyle?>('style', style, defaultValue: null)); + properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior, defaultValue: null)); + } +} + +/// A button for use in a [MenuBar], in a menu created with [MenuAnchor], or on +/// its own, that can be activated by click or keyboard navigation. +/// +/// This widget represents a leaf entry in a menu hierarchy that is typically +/// part of a [MenuBar], but may be used independently, or as part of a menu +/// created with a [MenuAnchor]. +/// +/// {@macro flutter.material.MenuBar.shortcuts_note} +/// +/// See also: +/// +/// * [MenuBar], a class that creates a top level menu bar in a Material Design +/// style. +/// * [MenuAnchor], a widget that creates a region with a submenu and shows it +/// when requested. +/// * [SubmenuButton], a menu item similar to this one which manages a submenu. +/// * [PlatformMenuBar], which creates a menu bar that is rendered by the host +/// platform instead of by Flutter (on macOS, for example). +/// * [ShortcutRegistry], a registry of shortcuts that apply for the entire +/// application. +/// * [VoidCallbackIntent], to define intents that will call a [VoidCallback] and +/// work with the [Actions] and [Shortcuts] system. +/// * [CallbackShortcuts] to define shortcuts that call a callback without +/// involving [Actions]. +class MenuItemButton extends StatefulWidget { + /// Creates a const [MenuItemButton]. + /// + /// The [child] attribute is required. + const MenuItemButton({ + super.key, + this.onPressed, + this.onHover, + this.requestFocusOnHover = true, + this.onFocusChange, + this.focusNode, + this.shortcut, + this.style, + this.statesController, + this.clipBehavior = Clip.none, + this.leadingIcon, + this.trailingIcon, + this.closeOnActivate = true, + required this.child, + }); + + /// Called when the button is tapped or otherwise activated. + /// + /// If this callback is null, then the button will be disabled. + /// + /// See also: + /// + /// * [enabled], which is true if the button is enabled. + final VoidCallback? onPressed; + + /// Called when a pointer enters or exits the button response area. + /// + /// The value passed to the callback is true if a pointer has entered button + /// area and false if a pointer has exited. + final ValueChanged<bool>? onHover; + + /// Determine if hovering can request focus. + /// + /// Defaults to true. + final bool requestFocusOnHover; + + /// Handler called when the focus changes. + /// + /// Called with true if this widget's node gains focus, and false if it loses + /// focus. + final ValueChanged<bool>? onFocusChange; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// The optional shortcut that selects this [MenuItemButton]. + /// + /// {@macro flutter.material.MenuBar.shortcuts_note} + final MenuSerializableShortcut? shortcut; + + /// Customizes this button's appearance. + /// + /// Non-null properties of this style override the corresponding properties in + /// [themeStyleOf] and [defaultStyleOf]. [MaterialStateProperty]s that resolve + /// to non-null values will similarly override the corresponding + /// [MaterialStateProperty]s in [themeStyleOf] and [defaultStyleOf]. + /// + /// Null by default. + final ButtonStyle? style; + + /// {@macro flutter.material.inkwell.statesController} + final MaterialStatesController? statesController; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// An optional icon to display before the [child] label. + final Widget? leadingIcon; + + /// An optional icon to display after the [child] label. + final Widget? trailingIcon; + + /// {@template flutter.material.menu_anchor.closeOnActivate} + /// Determines if the menu will be closed when a [MenuItemButton] + /// is pressed. + /// + /// Defaults to true. + /// {@endtemplate} + final bool closeOnActivate; + + /// The widget displayed in the center of this button. + /// + /// Typically this is the button's label, using a [Text] widget. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// Whether the button is enabled or disabled. + /// + /// To enable a button, set its [onPressed] property to a non-null value. + bool get enabled => onPressed != null; + + @override + State<MenuItemButton> createState() => _MenuItemButtonState(); + + /// Defines the button's default appearance. + /// + /// {@macro flutter.material.text_button.default_style_of} + /// + /// {@macro flutter.material.text_button.material3_defaults} + ButtonStyle defaultStyleOf(BuildContext context) { + return _MenuButtonDefaultsM3(context); + } + + /// Returns the [MenuButtonThemeData.style] of the closest + /// [MenuButtonTheme] ancestor. + ButtonStyle? themeStyleOf(BuildContext context) { + return MenuButtonTheme.of(context).style; + } + + /// A static convenience method that constructs a [MenuItemButton]'s + /// [ButtonStyle] given simple values. + /// + /// The [foregroundColor] color is used to create a [MaterialStateProperty] + /// [ButtonStyle.foregroundColor] value. Specify a value for [foregroundColor] + /// to specify the color of the button's icons. Use [backgroundColor] for the + /// button's background fill color. Use [disabledForegroundColor] and + /// [disabledBackgroundColor] to specify the button's disabled icon and fill + /// color. + /// + /// All of the other parameters are either used directly or used to create a + /// [MaterialStateProperty] with a single value for all states. + /// + /// All parameters default to null, by default this method returns a + /// [ButtonStyle] that doesn't override anything. + /// + /// For example, to override the default foreground color for a + /// [MenuItemButton], as well as its overlay color, with all of the standard + /// opacity adjustments for the pressed, focused, and hovered states, one + /// could write: + /// + /// ```dart + /// MenuItemButton( + /// leadingIcon: const Icon(Icons.pets), + /// style: MenuItemButton.styleFrom(foregroundColor: Colors.green), + /// onPressed: () { + /// // ... + /// }, + /// child: const Text('Button Label'), + /// ), + /// ``` + static ButtonStyle styleFrom({ + Color? foregroundColor, + Color? backgroundColor, + Color? disabledForegroundColor, + Color? disabledBackgroundColor, + Color? shadowColor, + Color? surfaceTintColor, + Color? iconColor, + TextStyle? textStyle, + double? elevation, + EdgeInsetsGeometry? padding, + Size? minimumSize, + Size? fixedSize, + Size? maximumSize, + MouseCursor? enabledMouseCursor, + MouseCursor? disabledMouseCursor, + BorderSide? side, + OutlinedBorder? shape, + VisualDensity? visualDensity, + MaterialTapTargetSize? tapTargetSize, + Duration? animationDuration, + bool? enableFeedback, + AlignmentGeometry? alignment, + InteractiveInkFeatureFactory? splashFactory, + }) { + return TextButton.styleFrom( + foregroundColor: foregroundColor, + backgroundColor: backgroundColor, + disabledBackgroundColor: disabledBackgroundColor, + disabledForegroundColor: disabledForegroundColor, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + iconColor: iconColor, + textStyle: textStyle, + elevation: elevation, + padding: padding, + minimumSize: minimumSize, + fixedSize: fixedSize, + maximumSize: maximumSize, + enabledMouseCursor: enabledMouseCursor, + disabledMouseCursor: disabledMouseCursor, + side: side, + shape: shape, + visualDensity: visualDensity, + tapTargetSize: tapTargetSize, + animationDuration: animationDuration, + enableFeedback: enableFeedback, + alignment: alignment, + splashFactory: splashFactory, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('enabled', value: onPressed != null, ifFalse: 'DISABLED')); + properties.add(DiagnosticsProperty<String>('child', child.toString())); + properties.add(DiagnosticsProperty<ButtonStyle?>('style', style, defaultValue: null)); + properties.add(DiagnosticsProperty<MenuSerializableShortcut?>('shortcut', shortcut, defaultValue: null)); + properties.add(DiagnosticsProperty<Widget?>('leadingIcon', leadingIcon, defaultValue: null)); + properties.add(DiagnosticsProperty<Widget?>('trailingIcon', trailingIcon, defaultValue: null)); + properties.add(DiagnosticsProperty<FocusNode?>('focusNode', focusNode, defaultValue: null)); + properties.add(EnumProperty<Clip>('clipBehavior', clipBehavior, defaultValue: Clip.none)); + properties.add(DiagnosticsProperty<MaterialStatesController?>('statesController', statesController, defaultValue: null)); + } +} + +class _MenuItemButtonState extends State<MenuItemButton> { + // If a focus node isn't given to the widget, then we have to manage our own. + FocusNode? _internalFocusNode; + FocusNode get _focusNode => widget.focusNode ?? _internalFocusNode!; + + @override + void initState() { + super.initState(); + _createInternalFocusNodeIfNeeded(); + _focusNode.addListener(_handleFocusChange); + } + + @override + void dispose() { + _focusNode.removeListener(_handleFocusChange); + _internalFocusNode?.dispose(); + _internalFocusNode = null; + super.dispose(); + } + + @override + void didUpdateWidget(MenuItemButton oldWidget) { + if (widget.focusNode != oldWidget.focusNode) { + _focusNode.removeListener(_handleFocusChange); + if (widget.focusNode != null) { + _internalFocusNode?.dispose(); + _internalFocusNode = null; + } + _createInternalFocusNodeIfNeeded(); + _focusNode.addListener(_handleFocusChange); + } + super.didUpdateWidget(oldWidget); + } + + @override + Widget build(BuildContext context) { + // Since we don't want to use the theme style or default style from the + // TextButton, we merge the styles, merging them in the right order when + // each type of style exists. Each "*StyleOf" function is only called once. + ButtonStyle mergedStyle = widget.themeStyleOf(context)?.merge(widget.defaultStyleOf(context)) + ?? widget.defaultStyleOf(context); + if (widget.style != null) { + mergedStyle = widget.style!.merge(mergedStyle); + } + + Widget child = TextButton( + onPressed: widget.enabled ? _handleSelect : null, + onHover: widget.enabled ? _handleHover : null, + onFocusChange: widget.enabled ? widget.onFocusChange : null, + focusNode: _focusNode, + style: mergedStyle, + statesController: widget.statesController, + clipBehavior: widget.clipBehavior, + isSemanticButton: null, + child: _MenuItemLabel( + leadingIcon: widget.leadingIcon, + shortcut: widget.shortcut, + trailingIcon: widget.trailingIcon, + hasSubmenu: false, + child: widget.child!, + ), + ); + + if (_platformSupportsAccelerators && widget.enabled) { + child = MenuAcceleratorCallbackBinding( + onInvoke: _handleSelect, + child: child, + ); + } + + return MergeSemantics(child: child); + } + + void _handleFocusChange() { + if (!_focusNode.hasPrimaryFocus) { + // Close any child menus of this button's menu. + _MenuAnchorState._maybeOf(context)?._closeChildren(); + } + } + + void _handleHover(bool hovering) { + widget.onHover?.call(hovering); + if (hovering && widget.requestFocusOnHover) { + assert(_debugMenuInfo('Requesting focus for $_focusNode from hover')); + _focusNode.requestFocus(); + } + } + + void _handleSelect() { + assert(_debugMenuInfo('Selected ${widget.child} menu')); + if (widget.closeOnActivate) { + _MenuAnchorState._maybeOf(context)?._root._close(); + } + // Delay the call to onPressed until post-frame so that the focus is + // restored to what it was before the menu was opened before the action is + // executed. + SchedulerBinding.instance.addPostFrameCallback((Duration _) { + FocusManager.instance.applyFocusChangesIfNeeded(); + widget.onPressed?.call(); + }, debugLabel: 'MenuAnchor.onPressed'); + } + + void _createInternalFocusNodeIfNeeded() { + if (widget.focusNode == null) { + _internalFocusNode = FocusNode(); + assert(() { + if (_internalFocusNode != null) { + _internalFocusNode!.debugLabel = '$MenuItemButton(${widget.child})'; + } + return true; + }()); + } + } +} + +/// A menu item that combines a [Checkbox] widget with a [MenuItemButton]. +/// +/// To style the checkbox separately from the button, add a [CheckboxTheme] +/// ancestor. +/// +/// {@tool dartpad} +/// This example shows a menu with a checkbox that shows a message in the body +/// of the app if checked. +/// +/// ** See code in examples/api/lib/material/menu_anchor/checkbox_menu_button.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// - [MenuBar], a widget that creates a menu bar of cascading menu items. +/// - [MenuAnchor], a widget that defines a region which can host a cascading +/// menu. +class CheckboxMenuButton extends StatelessWidget { + /// Creates a const [CheckboxMenuButton]. + /// + /// The [child], [value], and [onChanged] attributes are required. + const CheckboxMenuButton({ + super.key, + required this.value, + this.tristate = false, + this.isError = false, + required this.onChanged, + this.onHover, + this.onFocusChange, + this.focusNode, + this.shortcut, + this.style, + this.statesController, + this.clipBehavior = Clip.none, + this.trailingIcon, + this.closeOnActivate = true, + required this.child, + }); + + /// Whether this checkbox is checked. + /// + /// When [tristate] is true, a value of null corresponds to the mixed state. + /// When [tristate] is false, this value must not be null. + final bool? value; + + /// If true, then the checkbox's [value] can be true, false, or null. + /// + /// [CheckboxMenuButton] displays a dash when its value is null. + /// + /// When a tri-state checkbox ([tristate] is true) is tapped, its [onChanged] + /// callback will be applied to true if the current value is false, to null if + /// value is true, and to false if value is null (i.e. it cycles through false + /// => true => null => false when tapped). + /// + /// If tristate is false (the default), [value] must not be null. + final bool tristate; + + /// True if this checkbox wants to show an error state. + /// + /// The checkbox will have different default container color and check color when + /// this is true. This is only used when [ThemeData.useMaterial3] is set to true. + /// + /// Defaults to false. + final bool isError; + + /// Called when the value of the checkbox should change. + /// + /// The checkbox passes the new value to the callback but does not actually + /// change state until the parent widget rebuilds the checkbox with the new + /// value. + /// + /// If this callback is null, the menu item will be displayed as disabled + /// and will not respond to input gestures. + /// + /// When the checkbox is tapped, if [tristate] is false (the default) then the + /// [onChanged] callback will be applied to `!value`. If [tristate] is true + /// this callback cycle from false to true to null and then back to false + /// again. + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// CheckboxMenuButton( + /// value: _throwShotAway, + /// child: const Text('THROW'), + /// onChanged: (bool? newValue) { + /// setState(() { + /// _throwShotAway = newValue!; + /// }); + /// }, + /// ) + /// ``` + final ValueChanged<bool?>? onChanged; + + /// Called when a pointer enters or exits the button response area. + /// + /// The value passed to the callback is true if a pointer has entered button + /// area and false if a pointer has exited. + final ValueChanged<bool>? onHover; + + /// Handler called when the focus changes. + /// + /// Called with true if this widget's node gains focus, and false if it loses + /// focus. + final ValueChanged<bool>? onFocusChange; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// The optional shortcut that selects this [MenuItemButton]. + /// + /// {@macro flutter.material.MenuBar.shortcuts_note} + final MenuSerializableShortcut? shortcut; + + /// Customizes this button's appearance. + /// + /// Non-null properties of this style override the corresponding properties in + /// [MenuItemButton.themeStyleOf] and [MenuItemButton.defaultStyleOf]. + /// [MaterialStateProperty]s that resolve to non-null values will similarly + /// override the corresponding [MaterialStateProperty]s in + /// [MenuItemButton.themeStyleOf] and [MenuItemButton.defaultStyleOf]. + /// + /// Null by default. + final ButtonStyle? style; + + /// {@macro flutter.material.inkwell.statesController} + final MaterialStatesController? statesController; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// An optional icon to display after the [child] label. + final Widget? trailingIcon; + + /// {@macro flutter.material.menu_anchor.closeOnActivate} + final bool closeOnActivate; + + /// The widget displayed in the center of this button. + /// + /// Typically this is the button's label, using a [Text] widget. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// Whether the button is enabled or disabled. + /// + /// To enable a button, set its [onChanged] property to a non-null value. + bool get enabled => onChanged != null; + + @override + Widget build(BuildContext context) { + return MenuItemButton( + key: key, + onPressed: onChanged == null ? null : () { + switch (value) { + case false: + onChanged!.call(true); + case true: + onChanged!.call(tristate ? null : false); + case null: + onChanged!.call(false); + } + }, + onHover: onHover, + onFocusChange: onFocusChange, + focusNode: focusNode, + style: style, + shortcut: shortcut, + statesController: statesController, + leadingIcon: ExcludeFocus( + child: IgnorePointer( + child: ConstrainedBox( + constraints: const BoxConstraints( + maxHeight: Checkbox.width, + maxWidth: Checkbox.width, + ), + child: Checkbox( + tristate: tristate, + value: value, + onChanged: onChanged, + isError: isError, + ), + ), + ), + ), + clipBehavior: clipBehavior, + trailingIcon: trailingIcon, + closeOnActivate: closeOnActivate, + child: child, + ); + } +} + +/// A menu item that combines a [Radio] widget with a [MenuItemButton]. +/// +/// To style the radio button separately from the overall button, add a +/// [RadioTheme] ancestor. +/// +/// {@tool dartpad} +/// This example shows a menu with three radio buttons with shortcuts that +/// changes the background color of the body when the buttons are selected. +/// +/// ** See code in examples/api/lib/material/menu_anchor/radio_menu_button.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// - [MenuBar], a widget that creates a menu bar of cascading menu items. +/// - [MenuAnchor], a widget that defines a region which can host a cascading +/// menu. +class RadioMenuButton<T> extends StatelessWidget { + /// Creates a const [RadioMenuButton]. + /// + /// The [child] attribute is required. + const RadioMenuButton({ + super.key, + required this.value, + required this.groupValue, + required this.onChanged, + this.toggleable = false, + this.onHover, + this.onFocusChange, + this.focusNode, + this.shortcut, + this.style, + this.statesController, + this.clipBehavior = Clip.none, + this.trailingIcon, + this.closeOnActivate = true, + required this.child, + }); + + /// The value represented by this radio button. + /// + /// This radio button is considered selected if its [value] matches the + /// [groupValue]. + final T value; + + /// The currently selected value for a group of radio buttons. + /// + /// This radio button is considered selected if its [value] matches the + /// [groupValue]. + final T? groupValue; + + /// Set to true if this radio button is allowed to be returned to an + /// indeterminate state by selecting it again when selected. + /// + /// To indicate returning to an indeterminate state, [onChanged] will be + /// called with null. + /// + /// If true, [onChanged] can be called with [value] when selected while + /// [groupValue] != [value], or with null when selected again while + /// [groupValue] == [value]. + /// + /// If false, [onChanged] will be called with [value] when it is selected + /// while [groupValue] != [value], and only by selecting another radio button + /// in the group (i.e. changing the value of [groupValue]) can this radio + /// button be unselected. + /// + /// The default is false. + final bool toggleable; + + /// Called when the user selects this radio button. + /// + /// The radio button passes [value] as a parameter to this callback. The radio + /// button does not actually change state until the parent widget rebuilds the + /// radio button with the new [groupValue]. + /// + /// If null, the radio button will be displayed as disabled. + /// + /// The provided callback will not be invoked if this radio button is already + /// selected. + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// RadioMenuButton<SingingCharacter>( + /// value: SingingCharacter.lafayette, + /// groupValue: _character, + /// onChanged: (SingingCharacter? newValue) { + /// setState(() { + /// _character = newValue; + /// }); + /// }, + /// child: const Text('Lafayette'), + /// ) + /// ``` + final ValueChanged<T?>? onChanged; + + /// Called when a pointer enters or exits the button response area. + /// + /// The value passed to the callback is true if a pointer has entered button + /// area and false if a pointer has exited. + final ValueChanged<bool>? onHover; + + /// Handler called when the focus changes. + /// + /// Called with true if this widget's node gains focus, and false if it loses + /// focus. + final ValueChanged<bool>? onFocusChange; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// The optional shortcut that selects this [MenuItemButton]. + /// + /// {@macro flutter.material.MenuBar.shortcuts_note} + final MenuSerializableShortcut? shortcut; + + /// Customizes this button's appearance. + /// + /// Non-null properties of this style override the corresponding properties in + /// [MenuItemButton.themeStyleOf] and [MenuItemButton.defaultStyleOf]. + /// [MaterialStateProperty]s that resolve to non-null values will similarly + /// override the corresponding [MaterialStateProperty]s in + /// [MenuItemButton.themeStyleOf] and [MenuItemButton.defaultStyleOf]. + /// + /// Null by default. + final ButtonStyle? style; + + /// {@macro flutter.material.inkwell.statesController} + final MaterialStatesController? statesController; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// An optional icon to display after the [child] label. + final Widget? trailingIcon; + + /// {@macro flutter.material.menu_anchor.closeOnActivate} + final bool closeOnActivate; + + /// The widget displayed in the center of this button. + /// + /// Typically this is the button's label, using a [Text] widget. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// Whether the button is enabled or disabled. + /// + /// To enable a button, set its [onChanged] property to a non-null value. + bool get enabled => onChanged != null; + + @override + Widget build(BuildContext context) { + return MenuItemButton( + key: key, + onPressed: onChanged == null ? null : () { + if (toggleable && groupValue == value) { + onChanged!.call(null); + return; + } + onChanged!.call(value); + }, + onHover: onHover, + onFocusChange: onFocusChange, + focusNode: focusNode, + style: style, + shortcut: shortcut, + statesController: statesController, + leadingIcon: ExcludeFocus( + child: IgnorePointer( + child: ConstrainedBox( + constraints: const BoxConstraints( + maxHeight: Checkbox.width, + maxWidth: Checkbox.width, + ), + child: Radio<T>( + value: value, + groupValue: groupValue, + onChanged: onChanged, + toggleable: toggleable, + ), + ), + ), + ), + clipBehavior: clipBehavior, + trailingIcon: trailingIcon, + closeOnActivate: closeOnActivate, + child: child, + ); + } +} + +/// A menu button that displays a cascading menu. +/// +/// It can be used as part of a [MenuBar], or as a standalone widget. +/// +/// This widget represents a menu item that has a submenu. Like the leaf +/// [MenuItemButton], it shows a label with an optional leading or trailing +/// icon, but additionally shows an arrow icon showing that it has a submenu. +/// +/// By default the submenu will appear to the side of the controlling button. +/// The alignment and offset of the submenu can be controlled by setting +/// [MenuStyle.alignment] on the [style] and the [alignmentOffset] argument, +/// respectively. +/// +/// When activated (by being clicked, through keyboard navigation, or via +/// hovering with a mouse), it will open a submenu containing the +/// [menuChildren]. +/// +/// If [menuChildren] is empty, then this menu item will appear disabled. +/// +/// See also: +/// +/// * [MenuItemButton], a widget that represents a leaf menu item that does not +/// host a submenu. +/// * [MenuBar], a widget that renders menu items in a row in a Material Design +/// style. +/// * [MenuAnchor], a widget that creates a region with a submenu and shows it +/// when requested. +/// * [PlatformMenuBar], a widget that renders similar menu bar items from a +/// [PlatformMenuItem] using platform-native APIs instead of Flutter. +class SubmenuButton extends StatefulWidget { + /// Creates a const [SubmenuButton]. + /// + /// The [child] and [menuChildren] attributes are required. + const SubmenuButton({ + super.key, + this.onHover, + this.onFocusChange, + this.onOpen, + this.onClose, + this.controller, + this.style, + this.menuStyle, + this.alignmentOffset, + this.clipBehavior = Clip.hardEdge, + this.focusNode, + this.statesController, + this.leadingIcon, + this.trailingIcon, + required this.menuChildren, + required this.child, + }); + + /// Called when a pointer enters or exits the button response area. + /// + /// The value passed to the callback is true if a pointer has entered this + /// part of the button and false if a pointer has exited. + final ValueChanged<bool>? onHover; + + /// Handler called when the focus changes. + /// + /// Called with true if this widget's [focusNode] gains focus, and false if it + /// loses focus. + final ValueChanged<bool>? onFocusChange; + + /// A callback that is invoked when the menu is opened. + final VoidCallback? onOpen; + + /// A callback that is invoked when the menu is closed. + final VoidCallback? onClose; + + /// An optional [MenuController] for this submenu. + final MenuController? controller; + + /// Customizes this button's appearance. + /// + /// Non-null properties of this style override the corresponding properties in + /// [themeStyleOf] and [defaultStyleOf]. [MaterialStateProperty]s that resolve + /// to non-null values will similarly override the corresponding + /// [MaterialStateProperty]s in [themeStyleOf] and [defaultStyleOf]. + /// + /// Null by default. + final ButtonStyle? style; + + /// The [MenuStyle] of the menu specified by [menuChildren]. + /// + /// Defaults to the value of [MenuThemeData.style] of the ambient [MenuTheme]. + final MenuStyle? menuStyle; + + /// The offset of the menu relative to the alignment origin determined by + /// [MenuStyle.alignment] on the [style] attribute. + /// + /// Use this for fine adjustments of the menu placement. + /// + /// Defaults to an offset that takes into account the padding of the menu so + /// that the top starting corner of the first menu item is aligned with the + /// top of the [MenuAnchor] region. + final Offset? alignmentOffset; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.material.inkwell.statesController} + final MaterialStatesController? statesController; + + /// An optional icon to display before the [child]. + final Widget? leadingIcon; + + /// An optional icon to display after the [child]. + final Widget? trailingIcon; + + /// The list of widgets that appear in the menu when it is opened. + /// + /// These can be any widget, but are typically either [MenuItemButton] or + /// [SubmenuButton] widgets. + /// + /// If [menuChildren] is empty, then the button for this menu item will be + /// disabled. + final List<Widget> menuChildren; + + /// The widget displayed in the middle portion of this button. + /// + /// Typically this is the button's label, using a [Text] widget. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + @override + State<SubmenuButton> createState() => _SubmenuButtonState(); + + /// Defines the button's default appearance. + /// + /// {@macro flutter.material.text_button.default_style_of} + /// + /// {@macro flutter.material.text_button.material3_defaults} + ButtonStyle defaultStyleOf(BuildContext context) { + return _MenuButtonDefaultsM3(context); + } + + /// Returns the [MenuButtonThemeData.style] of the closest [MenuButtonTheme] + /// ancestor. + ButtonStyle? themeStyleOf(BuildContext context) { + return MenuButtonTheme.of(context).style; + } + + /// A static convenience method that constructs a [SubmenuButton]'s + /// [ButtonStyle] given simple values. + /// + /// The [foregroundColor] color is used to create a [MaterialStateProperty] + /// [ButtonStyle.foregroundColor] value. Specify a value for [foregroundColor] + /// to specify the color of the button's icons. Use [backgroundColor] for the + /// button's background fill color. Use [disabledForegroundColor] and + /// [disabledBackgroundColor] to specify the button's disabled icon and fill + /// color. + /// + /// All of the other parameters are either used directly or used to create a + /// [MaterialStateProperty] with a single value for all states. + /// + /// All parameters default to null, by default this method returns a + /// [ButtonStyle] that doesn't override anything. + /// + /// For example, to override the default foreground color for a + /// [SubmenuButton], as well as its overlay color, with all of the standard + /// opacity adjustments for the pressed, focused, and hovered states, one + /// could write: + /// + /// ```dart + /// SubmenuButton( + /// leadingIcon: const Icon(Icons.pets), + /// style: SubmenuButton.styleFrom(foregroundColor: Colors.green), + /// menuChildren: const <Widget>[ /* ... */ ], + /// child: const Text('Button Label'), + /// ), + /// ``` + static ButtonStyle styleFrom({ + Color? foregroundColor, + Color? backgroundColor, + Color? disabledForegroundColor, + Color? disabledBackgroundColor, + Color? shadowColor, + Color? surfaceTintColor, + Color? iconColor, + TextStyle? textStyle, + double? elevation, + EdgeInsetsGeometry? padding, + Size? minimumSize, + Size? fixedSize, + Size? maximumSize, + MouseCursor? enabledMouseCursor, + MouseCursor? disabledMouseCursor, + BorderSide? side, + OutlinedBorder? shape, + VisualDensity? visualDensity, + MaterialTapTargetSize? tapTargetSize, + Duration? animationDuration, + bool? enableFeedback, + AlignmentGeometry? alignment, + InteractiveInkFeatureFactory? splashFactory, + }) { + return TextButton.styleFrom( + foregroundColor: foregroundColor, + backgroundColor: backgroundColor, + disabledBackgroundColor: disabledBackgroundColor, + disabledForegroundColor: disabledForegroundColor, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + iconColor: iconColor, + textStyle: textStyle, + elevation: elevation, + padding: padding, + minimumSize: minimumSize, + fixedSize: fixedSize, + maximumSize: maximumSize, + enabledMouseCursor: enabledMouseCursor, + disabledMouseCursor: disabledMouseCursor, + side: side, + shape: shape, + visualDensity: visualDensity, + tapTargetSize: tapTargetSize, + animationDuration: animationDuration, + enableFeedback: enableFeedback, + alignment: alignment, + splashFactory: splashFactory, + ); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return <DiagnosticsNode>[ + ...menuChildren.map<DiagnosticsNode>((Widget child) { + return child.toDiagnosticsNode(); + }) + ]; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Widget>('leadingIcon', leadingIcon, defaultValue: null)); + properties.add(DiagnosticsProperty<String>('child', child.toString())); + properties.add(DiagnosticsProperty<Widget>('trailingIcon', trailingIcon, defaultValue: null)); + properties.add(DiagnosticsProperty<FocusNode?>('focusNode', focusNode)); + properties.add(DiagnosticsProperty<MenuStyle>('menuStyle', menuStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<Offset>('alignmentOffset', alignmentOffset)); + properties.add(EnumProperty<Clip>('clipBehavior', clipBehavior)); + } +} + +class _SubmenuButtonState extends State<SubmenuButton> { + FocusNode? _internalFocusNode; + bool _waitingToFocusMenu = false; + MenuController? _internalMenuController; + MenuController get _menuController => widget.controller ?? _internalMenuController!; + _MenuAnchorState? get _anchor => _MenuAnchorState._maybeOf(context); + FocusNode get _buttonFocusNode => widget.focusNode ?? _internalFocusNode!; + bool get _enabled => widget.menuChildren.isNotEmpty; + + @override + void initState() { + super.initState(); + if (widget.focusNode == null) { + _internalFocusNode = FocusNode(); + assert(() { + if (_internalFocusNode != null) { + _internalFocusNode!.debugLabel = '$SubmenuButton(${widget.child})'; + } + return true; + }()); + } + if (widget.controller == null) { + _internalMenuController = MenuController(); + } + _buttonFocusNode.addListener(_handleFocusChange); + } + + @override + void dispose() { + _buttonFocusNode.removeListener(_handleFocusChange); + _internalFocusNode?.dispose(); + _internalFocusNode = null; + super.dispose(); + } + + @override + void didUpdateWidget(SubmenuButton oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.focusNode != oldWidget.focusNode) { + if (oldWidget.focusNode == null) { + _internalFocusNode?.removeListener(_handleFocusChange); + _internalFocusNode?.dispose(); + _internalFocusNode = null; + } else { + oldWidget.focusNode!.removeListener(_handleFocusChange); + } + if (widget.focusNode == null) { + _internalFocusNode ??= FocusNode(); + assert(() { + if (_internalFocusNode != null) { + _internalFocusNode!.debugLabel = '$SubmenuButton(${widget.child})'; + } + return true; + }()); + } + _buttonFocusNode.addListener(_handleFocusChange); + } + if (widget.controller != oldWidget.controller) { + _internalMenuController = (oldWidget.controller == null) ? null : MenuController(); + } + } + + @override + Widget build(BuildContext context) { + Offset menuPaddingOffset = widget.alignmentOffset ?? Offset.zero; + final EdgeInsets menuPadding = _computeMenuPadding(context); + // Move the submenu over by the size of the menu padding, so that + // the first menu item aligns with the submenu button that opens it. + switch (_anchor?._orientation ?? Axis.vertical) { + case Axis.horizontal: + switch (Directionality.of(context)) { + case TextDirection.rtl: + menuPaddingOffset += Offset(menuPadding.right, 0); + case TextDirection.ltr: + menuPaddingOffset += Offset(-menuPadding.left, 0); + } + case Axis.vertical: + menuPaddingOffset += Offset(0, -menuPadding.top); + } + + return MenuAnchor( + controller: _menuController, + childFocusNode: _buttonFocusNode, + alignmentOffset: menuPaddingOffset, + clipBehavior: widget.clipBehavior, + onClose: widget.onClose, + onOpen: () { + if (!_waitingToFocusMenu) { + SchedulerBinding.instance.addPostFrameCallback((_) { + _menuController._anchor?._focusButton(); + _waitingToFocusMenu = false; + }, debugLabel: 'MenuAnchor.focus'); + _waitingToFocusMenu = true; + } + setState(() { /* Rebuild with updated controller.isOpen value */ }); + widget.onOpen?.call(); + }, + style: widget.menuStyle, + builder: (BuildContext context, MenuController controller, Widget? child) { + // Since we don't want to use the theme style or default style from the + // TextButton, we merge the styles, merging them in the right order when + // each type of style exists. Each "*StyleOf" function is only called + // once. + ButtonStyle mergedStyle = widget.themeStyleOf(context)?.merge(widget.defaultStyleOf(context)) + ?? widget.defaultStyleOf(context); + mergedStyle = widget.style?.merge(mergedStyle) ?? mergedStyle; + + void toggleShowMenu(BuildContext context) { + if (controller._anchor == null) { + return; + } + if (controller.isOpen) { + controller.close(); + } else { + controller.open(); + } + } + + // Called when the pointer is hovering over the menu button. + void handleHover(bool hovering, BuildContext context) { + widget.onHover?.call(hovering); + // Don't open the root menu bar menus on hover unless something else + // is already open. This means that the user has to first click to + // open a menu on the menu bar before hovering allows them to traverse + // it. + if (controller._anchor!._root._orientation == Axis.horizontal && !controller._anchor!._root._isOpen) { + return; + } + + if (hovering) { + controller.open(); + controller._anchor!._focusButton(); + } + } + child = MergeSemantics( + child: Semantics( + expanded: _enabled && controller.isOpen, + child: TextButton( + style: mergedStyle, + focusNode: _buttonFocusNode, + onFocusChange: _enabled ? widget.onFocusChange : null, + onHover: _enabled ? (bool hovering) => handleHover(hovering, context) : null, + onPressed: _enabled ? () => toggleShowMenu(context) : null, + isSemanticButton: null, + child: _MenuItemLabel( + leadingIcon: widget.leadingIcon, + trailingIcon: widget.trailingIcon, + hasSubmenu: true, + showDecoration: (controller._anchor!._parent?._orientation ?? Axis.horizontal) == Axis.vertical, + child: child ?? const SizedBox(), + ), + ), + ), + ); + + if (_enabled && _platformSupportsAccelerators) { + return MenuAcceleratorCallbackBinding( + onInvoke: () => toggleShowMenu(context), + hasSubmenu: true, + child: child, + ); + } + return child; + }, + menuChildren: widget.menuChildren, + child: widget.child, + ); + } + + EdgeInsets _computeMenuPadding(BuildContext context) { + final MaterialStateProperty<EdgeInsetsGeometry?> insets = + widget.menuStyle?.padding ?? + MenuTheme.of(context).style?.padding ?? + _MenuDefaultsM3(context).padding!; + return insets + .resolve(widget.statesController?.value ?? const <MaterialState>{})! + .resolve(Directionality.of(context)); + } + + void _handleFocusChange() { + if (_buttonFocusNode.hasPrimaryFocus) { + if (!_menuController.isOpen) { + _menuController.open(); + } + } else { + if (!_menuController._anchor!._menuScopeNode.hasFocus && _menuController.isOpen) { + _menuController.close(); + } + } + } +} + +/// An action that closes all the menus associated with the given +/// [MenuController]. +/// +/// See also: +/// +/// * [MenuAnchor], a widget that hosts a cascading submenu. +/// * [MenuBar], a widget that defines a menu bar with cascading submenus. +class DismissMenuAction extends DismissAction { + /// Creates a [DismissMenuAction]. + DismissMenuAction({required this.controller}); + + /// The [MenuController] associated with the menus that should be closed. + final MenuController controller; + + @override + void invoke(DismissIntent intent) { + assert(_debugMenuInfo('$runtimeType: Dismissing all open menus.')); + controller._anchor!._root._close(); + } + + @override + bool isEnabled(DismissIntent intent) { + return controller.isOpen; + } +} + +/// A helper class used to generate shortcut labels for a +/// [MenuSerializableShortcut] (a subset of the subclasses of +/// [ShortcutActivator]). +/// +/// This helper class is typically used by the [MenuItemButton] and +/// [SubmenuButton] classes to display a label for their assigned shortcuts. +/// +/// Call [getShortcutLabel] with the [MenuSerializableShortcut] to get a label +/// for it. +/// +/// For instance, calling [getShortcutLabel] with `SingleActivator(trigger: +/// LogicalKeyboardKey.keyA, control: true)` would return "⌃ A" on macOS, "Ctrl +/// A" in an US English locale, and "Strg A" in a German locale. +class _LocalizedShortcutLabeler { + _LocalizedShortcutLabeler._(); + + static _LocalizedShortcutLabeler? _instance; + + static final Map<LogicalKeyboardKey, String> _shortcutGraphicEquivalents = <LogicalKeyboardKey, String>{ + LogicalKeyboardKey.arrowLeft: '←', + LogicalKeyboardKey.arrowRight: '→', + LogicalKeyboardKey.arrowUp: '↑', + LogicalKeyboardKey.arrowDown: '↓', + LogicalKeyboardKey.enter: '↵', + }; + + static final Set<LogicalKeyboardKey> _modifiers = <LogicalKeyboardKey>{ + LogicalKeyboardKey.alt, + LogicalKeyboardKey.control, + LogicalKeyboardKey.meta, + LogicalKeyboardKey.shift, + LogicalKeyboardKey.altLeft, + LogicalKeyboardKey.controlLeft, + LogicalKeyboardKey.metaLeft, + LogicalKeyboardKey.shiftLeft, + LogicalKeyboardKey.altRight, + LogicalKeyboardKey.controlRight, + LogicalKeyboardKey.metaRight, + LogicalKeyboardKey.shiftRight, + }; + + /// Return the instance for this singleton. + static _LocalizedShortcutLabeler get instance { + return _instance ??= _LocalizedShortcutLabeler._(); + } + + // Caches the created shortcut key maps so that creating one of these isn't + // expensive after the first time for each unique localizations object. + final Map<MaterialLocalizations, Map<LogicalKeyboardKey, String>> _cachedShortcutKeys = + <MaterialLocalizations, Map<LogicalKeyboardKey, String>>{}; + + /// Returns the label to be shown to the user in the UI when a + /// [MenuSerializableShortcut] is used as a keyboard shortcut. + /// + /// When [defaultTargetPlatform] is [TargetPlatform.macOS] or + /// [TargetPlatform.iOS], this will return graphical key representations when + /// it can. For instance, the default [LogicalKeyboardKey.shift] will return + /// '⇧', and the arrow keys will return arrows. The key + /// [LogicalKeyboardKey.meta] will show as '⌘', [LogicalKeyboardKey.control] + /// will show as '˄', and [LogicalKeyboardKey.alt] will show as '⌥'. + /// + /// The keys are joined by spaces on macOS and iOS, and by "+" on other + /// platforms. + String getShortcutLabel(MenuSerializableShortcut shortcut, MaterialLocalizations localizations) { + final ShortcutSerialization serialized = shortcut.serializeForMenu(); + final String keySeparator; + if (_usesSymbolicModifiers) { + // Use "⌃ ⇧ A" style on macOS and iOS. + keySeparator = ' '; + } else { + // Use "Ctrl+Shift+A" style. + keySeparator = '+'; + } + if (serialized.trigger != null) { + final List<String> modifiers = <String>[]; + final LogicalKeyboardKey trigger = serialized.trigger!; + if (_usesSymbolicModifiers) { + // macOS/iOS platform convention uses this ordering, with ⌘ always last. + if (serialized.control!) { + modifiers.add(_getModifierLabel(LogicalKeyboardKey.control, localizations)); + } + if (serialized.alt!) { + modifiers.add(_getModifierLabel(LogicalKeyboardKey.alt, localizations)); + } + if (serialized.shift!) { + modifiers.add(_getModifierLabel(LogicalKeyboardKey.shift, localizations)); + } + if (serialized.meta!) { + modifiers.add(_getModifierLabel(LogicalKeyboardKey.meta, localizations)); + } + } else { + // These should be in this order, to match the LogicalKeySet version. + if (serialized.alt!) { + modifiers.add(_getModifierLabel(LogicalKeyboardKey.alt, localizations)); + } + if (serialized.control!) { + modifiers.add(_getModifierLabel(LogicalKeyboardKey.control, localizations)); + } + if (serialized.meta!) { + modifiers.add(_getModifierLabel(LogicalKeyboardKey.meta, localizations)); + } + if (serialized.shift!) { + modifiers.add(_getModifierLabel(LogicalKeyboardKey.shift, localizations)); + } + } + String? shortcutTrigger; + final int logicalKeyId = trigger.keyId; + if (_shortcutGraphicEquivalents.containsKey(trigger)) { + shortcutTrigger = _shortcutGraphicEquivalents[trigger]; + } else { + // Otherwise, look it up, and if we don't have a translation for it, + // then fall back to the key label. + shortcutTrigger = _getLocalizedName(trigger, localizations); + if (shortcutTrigger == null && logicalKeyId & LogicalKeyboardKey.planeMask == 0x0) { + // If the trigger is a Unicode-character-producing key, then use the + // character. + shortcutTrigger = String.fromCharCode(logicalKeyId & LogicalKeyboardKey.valueMask).toUpperCase(); + } + // Fall back to the key label if all else fails. + shortcutTrigger ??= trigger.keyLabel; + } + return <String>[ + ...modifiers, + if (shortcutTrigger != null && shortcutTrigger.isNotEmpty) shortcutTrigger, + ].join(keySeparator); + } else if (serialized.character != null) { + return serialized.character!; + } + throw UnimplementedError('Shortcut labels for ShortcutActivators that do not implement ' + 'MenuSerializableShortcut (e.g. ShortcutActivators other than SingleActivator or ' + 'CharacterActivator) are not supported.'); + } + + // Tries to look up the key in an internal table, and if it can't find it, + // then fall back to the key's keyLabel. + String? _getLocalizedName(LogicalKeyboardKey key, MaterialLocalizations localizations) { + // Since this is an expensive table to build, we cache it based on the + // localization object. There's currently no way to clear the cache, but + // it's unlikely that more than one or two will be cached for each run, and + // they're not huge. + _cachedShortcutKeys[localizations] ??= <LogicalKeyboardKey, String>{ + LogicalKeyboardKey.altGraph: localizations.keyboardKeyAltGraph, + LogicalKeyboardKey.backspace: localizations.keyboardKeyBackspace, + LogicalKeyboardKey.capsLock: localizations.keyboardKeyCapsLock, + LogicalKeyboardKey.channelDown: localizations.keyboardKeyChannelDown, + LogicalKeyboardKey.channelUp: localizations.keyboardKeyChannelUp, + LogicalKeyboardKey.delete: localizations.keyboardKeyDelete, + LogicalKeyboardKey.eject: localizations.keyboardKeyEject, + LogicalKeyboardKey.end: localizations.keyboardKeyEnd, + LogicalKeyboardKey.escape: localizations.keyboardKeyEscape, + LogicalKeyboardKey.fn: localizations.keyboardKeyFn, + LogicalKeyboardKey.home: localizations.keyboardKeyHome, + LogicalKeyboardKey.insert: localizations.keyboardKeyInsert, + LogicalKeyboardKey.numLock: localizations.keyboardKeyNumLock, + LogicalKeyboardKey.numpad1: localizations.keyboardKeyNumpad1, + LogicalKeyboardKey.numpad2: localizations.keyboardKeyNumpad2, + LogicalKeyboardKey.numpad3: localizations.keyboardKeyNumpad3, + LogicalKeyboardKey.numpad4: localizations.keyboardKeyNumpad4, + LogicalKeyboardKey.numpad5: localizations.keyboardKeyNumpad5, + LogicalKeyboardKey.numpad6: localizations.keyboardKeyNumpad6, + LogicalKeyboardKey.numpad7: localizations.keyboardKeyNumpad7, + LogicalKeyboardKey.numpad8: localizations.keyboardKeyNumpad8, + LogicalKeyboardKey.numpad9: localizations.keyboardKeyNumpad9, + LogicalKeyboardKey.numpad0: localizations.keyboardKeyNumpad0, + LogicalKeyboardKey.numpadAdd: localizations.keyboardKeyNumpadAdd, + LogicalKeyboardKey.numpadComma: localizations.keyboardKeyNumpadComma, + LogicalKeyboardKey.numpadDecimal: localizations.keyboardKeyNumpadDecimal, + LogicalKeyboardKey.numpadDivide: localizations.keyboardKeyNumpadDivide, + LogicalKeyboardKey.numpadEnter: localizations.keyboardKeyNumpadEnter, + LogicalKeyboardKey.numpadEqual: localizations.keyboardKeyNumpadEqual, + LogicalKeyboardKey.numpadMultiply: localizations.keyboardKeyNumpadMultiply, + LogicalKeyboardKey.numpadParenLeft: localizations.keyboardKeyNumpadParenLeft, + LogicalKeyboardKey.numpadParenRight: localizations.keyboardKeyNumpadParenRight, + LogicalKeyboardKey.numpadSubtract: localizations.keyboardKeyNumpadSubtract, + LogicalKeyboardKey.pageDown: localizations.keyboardKeyPageDown, + LogicalKeyboardKey.pageUp: localizations.keyboardKeyPageUp, + LogicalKeyboardKey.power: localizations.keyboardKeyPower, + LogicalKeyboardKey.powerOff: localizations.keyboardKeyPowerOff, + LogicalKeyboardKey.printScreen: localizations.keyboardKeyPrintScreen, + LogicalKeyboardKey.scrollLock: localizations.keyboardKeyScrollLock, + LogicalKeyboardKey.select: localizations.keyboardKeySelect, + LogicalKeyboardKey.space: localizations.keyboardKeySpace, + }; + return _cachedShortcutKeys[localizations]![key]; + } + + String _getModifierLabel(LogicalKeyboardKey modifier, MaterialLocalizations localizations) { + assert(_modifiers.contains(modifier), '${modifier.keyLabel} is not a modifier key'); + if (modifier == LogicalKeyboardKey.meta || + modifier == LogicalKeyboardKey.metaLeft || + modifier == LogicalKeyboardKey.metaRight) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + return localizations.keyboardKeyMeta; + case TargetPlatform.windows: + return localizations.keyboardKeyMetaWindows; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return '⌘'; + } + } + if (modifier == LogicalKeyboardKey.alt || + modifier == LogicalKeyboardKey.altLeft || + modifier == LogicalKeyboardKey.altRight) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return localizations.keyboardKeyAlt; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return '⌥'; + } + } + if (modifier == LogicalKeyboardKey.control || + modifier == LogicalKeyboardKey.controlLeft || + modifier == LogicalKeyboardKey.controlRight) { + // '⎈' (a boat helm wheel, not an asterisk) is apparently the standard + // icon for "control", but only seems to appear on the French Canadian + // keyboard. A '✲' (an open center asterisk) appears on some Microsoft + // keyboards. For all but macOS (which has standardized on "⌃", it seems), + // we just return the local translation of "Ctrl". + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return localizations.keyboardKeyControl; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return '⌃'; + } + } + if (modifier == LogicalKeyboardKey.shift || + modifier == LogicalKeyboardKey.shiftLeft || + modifier == LogicalKeyboardKey.shiftRight) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return localizations.keyboardKeyShift; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return '⇧'; + } + } + throw ArgumentError('Keyboard key ${modifier.keyLabel} is not a modifier.'); + } +} + +class _MenuAnchorScope extends InheritedWidget { + const _MenuAnchorScope({ + required super.child, + required this.anchorKey, + required this.anchor, + required this.isOpen, + }); + + final GlobalKey anchorKey; + final _MenuAnchorState anchor; + final bool isOpen; + + @override + bool updateShouldNotify(_MenuAnchorScope oldWidget) { + return anchorKey != oldWidget.anchorKey + || anchor != oldWidget.anchor + || isOpen != oldWidget.isOpen; + } +} + +/// MenuBar-specific private specialization of [MenuAnchor] so that it can act +/// differently in regards to orientation, how open works, and what gets built. +class _MenuBarAnchor extends MenuAnchor { + const _MenuBarAnchor({ + required super.menuChildren, + super.controller, + super.clipBehavior, + super.style, + }); + + @override + State<MenuAnchor> createState() => _MenuBarAnchorState(); +} + +class _MenuBarAnchorState extends _MenuAnchorState { + @override + bool get _isOpen { + // If it's a bar, then it's "open" if any of its children are open. + for (final _MenuAnchorState child in _anchorChildren) { + if (child._isOpen) { + return true; + } + } + return false; + } + + @override + Axis get _orientation => Axis.horizontal; + + @override + Widget _buildContents(BuildContext context) { + final bool isOpen = _isOpen; + return FocusScope( + node: _menuScopeNode, + skipTraversal: !isOpen, + canRequestFocus: isOpen, + child: ExcludeFocus( + excluding: !isOpen, + child: Shortcuts( + shortcuts: _kMenuTraversalShortcuts, + child: Actions( + actions: <Type, Action<Intent>>{ + DirectionalFocusIntent: _MenuDirectionalFocusAction(), + PreviousFocusIntent: _MenuPreviousFocusAction(), + NextFocusIntent: _MenuNextFocusAction(), + DismissIntent: DismissMenuAction(controller: _menuController), + }, + child: Builder(builder: (BuildContext context) { + return _MenuPanel( + menuStyle: widget.style, + clipBehavior: widget.clipBehavior, + orientation: Axis.horizontal, + children: widget.menuChildren, + ); + }), + ), + ), + ), + ); + } + + @override + void _open({Offset? position}) { + assert(_menuController._anchor == this); + // Menu bars can't be opened, because they're already always open. + return; + } +} + +class _MenuPreviousFocusAction extends PreviousFocusAction { + @override + bool invoke(PreviousFocusIntent intent) { + assert(_debugMenuInfo('_MenuNextFocusAction invoked with $intent')); + final BuildContext? context = FocusManager.instance.primaryFocus?.context; + if (context == null) { + return super.invoke(intent); + } + final _MenuAnchorState? anchor = _MenuAnchorState._maybeOf(context); + if (anchor == null || !anchor._root._isOpen) { + return super.invoke(intent); + } + + return _moveToPreviousFocusable(anchor); + } + + static bool _moveToPreviousFocusable(_MenuAnchorState currentMenu) { + final _MenuAnchorState? sibling = currentMenu._previousFocusableSibling; + sibling?._focusButton(); + return true; + } +} + +class _MenuNextFocusAction extends NextFocusAction { + @override + bool invoke(NextFocusIntent intent) { + assert(_debugMenuInfo('_MenuNextFocusAction invoked with $intent')); + final BuildContext? context = FocusManager.instance.primaryFocus?.context; + if (context == null) { + return super.invoke(intent); + } + final _MenuAnchorState? anchor = _MenuAnchorState._maybeOf(context); + if (anchor == null || !anchor._root._isOpen) { + return super.invoke(intent); + } + + return _moveToNextFocusable(anchor); + } + + static bool _moveToNextFocusable(_MenuAnchorState currentMenu) { + final _MenuAnchorState? sibling = currentMenu._nextFocusableSibling; + sibling?._focusButton(); + return true; + } + +} + +class _MenuDirectionalFocusAction extends DirectionalFocusAction { + /// Creates a [DirectionalFocusAction]. + _MenuDirectionalFocusAction(); + + @override + void invoke(DirectionalFocusIntent intent) { + assert(_debugMenuInfo('_MenuDirectionalFocusAction invoked with $intent')); + final BuildContext? context = FocusManager.instance.primaryFocus?.context; + if (context == null) { + super.invoke(intent); + return; + } + final _MenuAnchorState? anchor = _MenuAnchorState._maybeOf(context); + if (anchor == null || !anchor._root._isOpen) { + super.invoke(intent); + return; + } + final bool buttonIsFocused = anchor.widget.childFocusNode?.hasPrimaryFocus ?? false; + Axis orientation; + if (buttonIsFocused && anchor._parent != null) { + orientation = anchor._parent!._orientation; + } else { + orientation = anchor._orientation; + } + final bool firstItemIsFocused = anchor._firstItemFocusNode?.hasPrimaryFocus ?? false; + assert(_debugMenuInfo('In _MenuDirectionalFocusAction, current node is ${anchor.widget.childFocusNode?.debugLabel}, ' + 'button is${buttonIsFocused ? '' : ' not'} focused. Assuming ${orientation.name} orientation.')); + + switch (intent.direction) { + case TraversalDirection.up: + switch (orientation) { + case Axis.horizontal: + if (_moveToParent(anchor)) { + return; + } + case Axis.vertical: + if (firstItemIsFocused) { + if (_moveToParent(anchor)) { + return; + } + } + if (_moveToPrevious(anchor)) { + return; + } + } + case TraversalDirection.down: + switch (orientation) { + case Axis.horizontal: + if (_moveToSubmenu(anchor)) { + return; + } + case Axis.vertical: + if (_moveToNext(anchor)) { + return; + } + } + case TraversalDirection.left: + switch (orientation) { + case Axis.horizontal: + switch (Directionality.of(context)) { + case TextDirection.rtl: + if (_moveToNext(anchor)) { + return; + } + case TextDirection.ltr: + if (_moveToPrevious(anchor)) { + return; + } + } + case Axis.vertical: + switch (Directionality.of(context)) { + case TextDirection.rtl: + if (buttonIsFocused) { + if (_moveToSubmenu(anchor)) { + return; + } + } else { + if (_moveToNextFocusableTopLevel(anchor)) { + return; + } + } + case TextDirection.ltr: + switch (anchor._parent?._orientation) { + case Axis.horizontal: + case null: + if (_moveToPreviousFocusableTopLevel(anchor)) { + return; + } + case Axis.vertical: + if (buttonIsFocused) { + if (_moveToPreviousFocusableTopLevel(anchor)) { + return; + } + } else { + if (_moveToParent(anchor)) { + return; + } + } + } + } + } + case TraversalDirection.right: + switch (orientation) { + case Axis.horizontal: + switch (Directionality.of(context)) { + case TextDirection.rtl: + if (_moveToPrevious(anchor)) { + return; + } + case TextDirection.ltr: + if (_moveToNext(anchor)) { + return; + } + } + case Axis.vertical: + switch (Directionality.of(context)) { + case TextDirection.rtl: + switch (anchor._parent?._orientation) { + case Axis.horizontal: + case null: + if (_moveToPreviousFocusableTopLevel(anchor)) { + return; + } + case Axis.vertical: + if (_moveToParent(anchor)) { + return; + } + } + case TextDirection.ltr: + if (buttonIsFocused) { + if (_moveToSubmenu(anchor)) { + return; + } + } else { + if (_moveToNextFocusableTopLevel(anchor)) { + return; + } + } + } + } + } + super.invoke(intent); + } + + bool _moveToNext(_MenuAnchorState currentMenu) { + assert(_debugMenuInfo('Moving focus to next item in menu')); + // Need to invalidate the scope data because we're switching scopes, and + // otherwise the anti-hysteresis code will interfere with moving to the + // correct node. + if (currentMenu.widget.childFocusNode != null) { + if (currentMenu.widget.childFocusNode!.nearestScope != null) { + final FocusTraversalPolicy? policy = FocusTraversalGroup.maybeOf(primaryFocus!.context!); + policy?.invalidateScopeData(currentMenu.widget.childFocusNode!.nearestScope!); + } + } + return false; + } + + bool _moveToNextFocusableTopLevel(_MenuAnchorState currentMenu) { + final _MenuAnchorState? sibling = currentMenu._topLevel._nextFocusableSibling; + sibling?._focusButton(); + return true; + } + + bool _moveToParent(_MenuAnchorState currentMenu) { + assert(_debugMenuInfo('Moving focus to parent menu button')); + if (!(currentMenu.widget.childFocusNode?.hasPrimaryFocus ?? true)) { + currentMenu._focusButton(); + } + return true; + } + + bool _moveToPrevious(_MenuAnchorState currentMenu) { + assert(_debugMenuInfo('Moving focus to previous item in menu')); + // Need to invalidate the scope data because we're switching scopes, and + // otherwise the anti-hysteresis code will interfere with moving to the + // correct node. + if (currentMenu.widget.childFocusNode != null) { + if (currentMenu.widget.childFocusNode!.nearestScope != null) { + final FocusTraversalPolicy? policy = FocusTraversalGroup.maybeOf(primaryFocus!.context!); + policy?.invalidateScopeData(currentMenu.widget.childFocusNode!.nearestScope!); + } + } + return false; + } + + bool _moveToPreviousFocusableTopLevel(_MenuAnchorState currentMenu) { + final _MenuAnchorState? sibling = currentMenu._topLevel._previousFocusableSibling; + sibling?._focusButton(); + return true; + } + + bool _moveToSubmenu(_MenuAnchorState currentMenu) { + assert(_debugMenuInfo('Opening submenu')); + if (!currentMenu._isOpen) { + // If no submenu is open, then an arrow opens the submenu. + currentMenu._open(); + return true; + } else { + final FocusNode? firstNode = currentMenu._firstItemFocusNode; + if (firstNode != null && firstNode.nearestScope != firstNode) { + // Don't request focus if the "first" found node is a focus scope, since + // that means that nothing else in the submenu is focusable. + firstNode.requestFocus(); + } + return true; + } + } +} + +/// An [InheritedWidget] that provides a descendant [MenuAcceleratorLabel] with +/// the function to invoke when the accelerator is pressed. +/// +/// This is used when creating your own custom menu item for use with +/// [MenuAnchor] or [MenuBar]. Provided menu items such as [MenuItemButton] and +/// [SubmenuButton] already supply this wrapper internally. +class MenuAcceleratorCallbackBinding extends InheritedWidget { + /// Create a const [MenuAcceleratorCallbackBinding]. + /// + /// The [child] parameter is required. + const MenuAcceleratorCallbackBinding({ + super.key, + this.onInvoke, + this.hasSubmenu = false, + required super.child, + }); + + /// The function that pressing the accelerator defined in a descendant + /// [MenuAcceleratorLabel] will invoke. + /// + /// If set to null, then the accelerator won't be enabled. + final VoidCallback? onInvoke; + + /// Whether or not the associated label will host its own submenu or not. + /// + /// This setting determines when accelerators are active, since accelerators + /// for menu items that open submenus shouldn't be active when the submenu is + /// open. + final bool hasSubmenu; + + @override + bool updateShouldNotify(MenuAcceleratorCallbackBinding oldWidget) { + return onInvoke != oldWidget.onInvoke || hasSubmenu != oldWidget.hasSubmenu; + } + + /// Returns the active [MenuAcceleratorCallbackBinding] in the given context, if any, + /// and creates a dependency relationship that will rebuild the context when + /// [onInvoke] changes. + /// + /// If no [MenuAcceleratorCallbackBinding] is found, returns null. + /// + /// See also: + /// + /// * [of], which is similar, but asserts if no [MenuAcceleratorCallbackBinding] + /// is found. + static MenuAcceleratorCallbackBinding? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<MenuAcceleratorCallbackBinding>(); + } + + /// Returns the active [MenuAcceleratorCallbackBinding] in the given context, and + /// creates a dependency relationship that will rebuild the context when + /// [onInvoke] changes. + /// + /// If no [MenuAcceleratorCallbackBinding] is found, returns will assert in debug mode + /// and throw an exception in release mode. + /// + /// See also: + /// + /// * [maybeOf], which is similar, but returns null if no + /// [MenuAcceleratorCallbackBinding] is found. + static MenuAcceleratorCallbackBinding of(BuildContext context) { + final MenuAcceleratorCallbackBinding? result = maybeOf(context); + assert(() { + if (result == null) { + throw FlutterError( + 'MenuAcceleratorWrapper.of() was called with a context that does not ' + 'contain a MenuAcceleratorWrapper in the given context.\n' + 'No MenuAcceleratorWrapper ancestor could be found in the context that ' + 'was passed to MenuAcceleratorWrapper.of(). This can happen because ' + 'you are using a widget that looks for a MenuAcceleratorWrapper ' + 'ancestor, and do not have a MenuAcceleratorWrapper widget ancestor.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return result!; + } +} + +/// The type of builder function used for building a [MenuAcceleratorLabel]'s +/// [MenuAcceleratorLabel.builder] function. +/// +/// {@template flutter.material.menu_anchor.menu_accelerator_child_builder.args} +/// The arguments to the function are as follows: +/// +/// * The `context` supplies the [BuildContext] to use. +/// * The `label` is the [MenuAcceleratorLabel.label] attribute for the relevant +/// [MenuAcceleratorLabel] with the accelerator markers stripped out of it. +/// * The `index` is the index of the accelerator character within the +/// `label.characters` that applies to this accelerator. If it is -1, then the +/// accelerator should not be highlighted. Otherwise, the given character +/// should be highlighted somehow in the rendered label (typically with an +/// underscore). Importantly, `index` is not an index into the [String] +/// `label`, it is an index into the [Characters] iterable returned by +/// `label.characters`, so that it is in terms of user-visible characters +/// (a.k.a. grapheme clusters), not Unicode code points. +/// {@endtemplate} +/// +/// See also: +/// +/// * [MenuAcceleratorLabel.defaultLabelBuilder], which is the implementation +/// used as the default value for [MenuAcceleratorLabel.builder]. +typedef MenuAcceleratorChildBuilder = Widget Function( + BuildContext context, + String label, + int index, +); + +/// A widget that draws the label text for a menu item (typically a +/// [MenuItemButton] or [SubmenuButton]) and renders its child with information +/// about the currently active keyboard accelerator. +/// +/// On platforms other than macOS and iOS, this widget listens for the Alt key +/// to be pressed, and when it is down, will update the label by calling the +/// builder again with the position of the accelerator in the label string. +/// While the Alt key is pressed, it registers a shortcut with the +/// [ShortcutRegistry] mapped to a [VoidCallbackIntent] containing the callback +/// defined by the nearest [MenuAcceleratorCallbackBinding]. +/// +/// Because the accelerators are registered with the [ShortcutRegistry], any +/// other shortcuts in the widget tree between the [primaryFocus] and the +/// [ShortcutRegistry] that define Alt-based shortcuts using the same keys will +/// take precedence over the accelerators. +/// +/// Because accelerators aren't used on macOS and iOS, the label ignores the Alt +/// key on those platforms, and the [builder] is always given -1 as an +/// accelerator index. Accelerator labels are still stripped of their +/// accelerator markers. +/// +/// The built-in menu items [MenuItemButton] and [SubmenuButton] already provide +/// the appropriate [MenuAcceleratorCallbackBinding], so unless you are creating +/// your own custom menu item type that takes a [MenuAcceleratorLabel], it is +/// not necessary to provide one. +/// +/// {@template flutter.material.MenuAcceleratorLabel.accelerator_sample} +/// {@tool dartpad} This example shows a [MenuBar] that handles keyboard +/// accelerators using [MenuAcceleratorLabel]. To use the accelerators, press +/// the Alt key to see which letters are underlined in the menu bar, and then +/// press the appropriate letter. Accelerators are not supported on macOS or iOS +/// since those platforms don't support them natively, so this demo will only +/// show a regular Material menu bar on those platforms. +/// +/// ** See code in examples/api/lib/material/menu_anchor/menu_accelerator_label.0.dart ** +/// {@end-tool} +/// {@endtemplate} +class MenuAcceleratorLabel extends StatefulWidget { + /// Creates a const [MenuAcceleratorLabel]. + /// + /// The [label] parameter is required. + const MenuAcceleratorLabel( + this.label, { + super.key, + this.builder = defaultLabelBuilder, + }); + + /// The label string that should be displayed. + /// + /// The label string provides the label text, as well as the possible + /// characters which could be used as accelerators in the menu system. + /// + /// {@template flutter.material.menu_anchor.menu_accelerator_label.label} + /// To indicate which letters in the label are to be used as accelerators, add + /// an "&" character before the character in the string. If more than one + /// character has an "&" in front of it, then the characters appearing earlier + /// in the string are preferred. To represent a literal "&", insert "&&" into + /// the string. All other ampersands will be removed from the string before + /// calling [MenuAcceleratorLabel.builder]. Bare ampersands at the end of the + /// string or before whitespace are stripped and ignored. + /// {@endtemplate} + /// + /// See also: + /// + /// * [displayLabel], which returns the [label] with all of the ampersands + /// stripped out of it, and double ampersands converted to ampersands. + /// * [stripAcceleratorMarkers], which returns the supplied string with all of + /// the ampersands stripped out of it, and double ampersands converted to + /// ampersands, and optionally calls a callback with the index of the + /// accelerator character found. + final String label; + + /// Returns the [label] with any accelerator markers removed. + /// + /// This getter just calls [stripAcceleratorMarkers] with the [label]. + String get displayLabel => stripAcceleratorMarkers(label); + + /// The optional [MenuAcceleratorChildBuilder] which is used to build the + /// widget that displays the label itself. + /// + /// The [defaultLabelBuilder] function serves as the default value for + /// [builder], rendering the label as a [RichText] widget with appropriate + /// [TextSpan]s for rendering the label with an underscore under the selected + /// accelerator for the label when accelerators have been activated. + /// + /// {@macro flutter.material.menu_anchor.menu_accelerator_child_builder.args} + /// + /// When writing the builder function, it's not necessary to take the current + /// platform into account. On platforms which don't support accelerators (e.g. + /// macOS and iOS), the passed accelerator index will always be -1, and the + /// accelerator markers will already be stripped. + final MenuAcceleratorChildBuilder builder; + + /// Whether [label] contains an accelerator definition. + /// + /// {@macro flutter.material.menu_anchor.menu_accelerator_label.label} + bool get hasAccelerator => RegExp(r'&(?!([&\s]|$))').hasMatch(label); + + /// Serves as the default value for [builder], rendering the label as a + /// [RichText] widget with appropriate [TextSpan]s for rendering the label + /// with an underscore under the selected accelerator for the label when the + /// [index] is non-negative, and a [Text] widget when the [index] is negative. + /// + /// {@macro flutter.material.menu_anchor.menu_accelerator_child_builder.args} + static Widget defaultLabelBuilder( + BuildContext context, + String label, + int index, + ) { + if (index < 0) { + return Text(label); + } + final TextStyle defaultStyle = DefaultTextStyle.of(context).style; + final Characters characters = label.characters; + return RichText( + text: TextSpan( + children: <TextSpan>[ + if (index > 0) + TextSpan(text: characters.getRange(0, index).toString(), style: defaultStyle), + TextSpan( + text: characters.getRange(index, index + 1).toString(), + style: defaultStyle.copyWith(decoration: TextDecoration.underline), + ), + if (index < characters.length - 1) + TextSpan(text: characters.getRange(index + 1).toString(), style: defaultStyle), + ], + ), + ); + } + + /// Strips out any accelerator markers from the given [label], and unescapes + /// any escaped ampersands. + /// + /// If [setIndex] is supplied, it will be called before this function returns + /// with the index in the returned string of the accelerator character. + /// + /// {@macro flutter.material.menu_anchor.menu_accelerator_label.label} + static String stripAcceleratorMarkers(String label, {void Function(int index)? setIndex}) { + int quotedAmpersands = 0; + final StringBuffer displayLabel = StringBuffer(); + int acceleratorIndex = -1; + // Use characters so that we don't split up surrogate pairs and interpret + // them incorrectly. + final Characters labelChars = label.characters; + final Characters ampersand = '&'.characters; + bool lastWasAmpersand = false; + for (int i = 0; i < labelChars.length; i += 1) { + // Stop looking one before the end, since a single ampersand at the end is + // just treated as a quoted ampersand. + final Characters character = labelChars.characterAt(i); + if (lastWasAmpersand) { + lastWasAmpersand = false; + displayLabel.write(character); + continue; + } + if (character != ampersand) { + displayLabel.write(character); + continue; + } + if (i == labelChars.length - 1) { + // Strip bare ampersands at the end of a string. + break; + } + lastWasAmpersand = true; + final Characters acceleratorCharacter = labelChars.characterAt(i + 1); + if (acceleratorIndex == -1 && acceleratorCharacter != ampersand && + acceleratorCharacter.toString().trim().isNotEmpty) { + // Don't set the accelerator index if the character is an ampersand, + // or whitespace. + acceleratorIndex = i - quotedAmpersands; + } + // As we encounter '&<character>' pairs, the following indices must be + // adjusted so that they correspond with indices in the stripped string. + quotedAmpersands += 1; + } + setIndex?.call(acceleratorIndex); + return displayLabel.toString(); + } + + @override + State<MenuAcceleratorLabel> createState() => _MenuAcceleratorLabelState(); + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return '$MenuAcceleratorLabel("$label")'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('label', label)); + } +} + +class _MenuAcceleratorLabelState extends State<MenuAcceleratorLabel> { + late String _displayLabel; + int _acceleratorIndex = -1; + MenuAcceleratorCallbackBinding? _binding; + _MenuAnchorState? _anchor; + ShortcutRegistry? _shortcutRegistry; + ShortcutRegistryEntry? _shortcutRegistryEntry; + bool _showAccelerators = false; + + @override + void initState() { + super.initState(); + if (_platformSupportsAccelerators) { + _showAccelerators = _altIsPressed(); + HardwareKeyboard.instance.addHandler(_listenToKeyEvent); + } + _updateDisplayLabel(); + } + + @override + void dispose() { + assert(_platformSupportsAccelerators || _shortcutRegistryEntry == null); + _displayLabel = ''; + if (_platformSupportsAccelerators) { + _shortcutRegistryEntry?.dispose(); + _shortcutRegistryEntry = null; + _shortcutRegistry = null; + _anchor = null; + HardwareKeyboard.instance.removeHandler(_listenToKeyEvent); + } + super.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (!_platformSupportsAccelerators) { + return; + } + _binding = MenuAcceleratorCallbackBinding.maybeOf(context); + _anchor = _MenuAnchorState._maybeOf(context); + _shortcutRegistry = ShortcutRegistry.maybeOf(context); + _updateAcceleratorShortcut(); + } + + @override + void didUpdateWidget(MenuAcceleratorLabel oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.label != oldWidget.label) { + _updateDisplayLabel(); + } + } + + static bool _altIsPressed() { + return HardwareKeyboard.instance.logicalKeysPressed.intersection( + <LogicalKeyboardKey>{ + LogicalKeyboardKey.altLeft, + LogicalKeyboardKey.altRight, + LogicalKeyboardKey.alt, + }, + ).isNotEmpty; + } + + bool _listenToKeyEvent(KeyEvent event) { + assert(_platformSupportsAccelerators); + setState(() { + _showAccelerators = _altIsPressed(); + _updateAcceleratorShortcut(); + }); + // Just listening, so it doesn't ever handle a key. + return false; + } + + void _updateAcceleratorShortcut() { + assert(_platformSupportsAccelerators); + _shortcutRegistryEntry?.dispose(); + _shortcutRegistryEntry = null; + // Before registering an accelerator as a shortcut it should meet these + // conditions: + // + // 1) Is showing accelerators (i.e. Alt key is down). + // 2) Has an accelerator marker in the label. + // 3) Has an associated action callback for the label (from the + // MenuAcceleratorCallbackBinding). + // 4) Is part of an anchor that either doesn't have a submenu, or doesn't + // have any submenus currently open (only the "deepest" open menu should + // have accelerator shortcuts registered). + if (_showAccelerators && _acceleratorIndex != -1 && _binding?.onInvoke != null && (!_binding!.hasSubmenu || !(_anchor?._isOpen ?? false))) { + final String acceleratorCharacter = _displayLabel[_acceleratorIndex].toLowerCase(); + _shortcutRegistryEntry = _shortcutRegistry?.addAll( + <ShortcutActivator, Intent>{ + CharacterActivator(acceleratorCharacter, alt: true): VoidCallbackIntent(_binding!.onInvoke!), + }, + ); + } + } + + void _updateDisplayLabel() { + _displayLabel = MenuAcceleratorLabel.stripAcceleratorMarkers( + widget.label, + setIndex: (int index) { + _acceleratorIndex = index; + }, + ); + } + + @override + Widget build(BuildContext context) { + final int index = _showAccelerators ? _acceleratorIndex : -1; + return widget.builder(context, _displayLabel, index); + } +} + +/// A label widget that is used as the label for a [MenuItemButton] or +/// [SubmenuButton]. +/// +/// It not only shows the [SubmenuButton.child] or [MenuItemButton.child], but if +/// there is a shortcut associated with the [MenuItemButton], it will display a +/// mnemonic for the shortcut. For [SubmenuButton]s, it will display a visual +/// indicator that there is a submenu. +class _MenuItemLabel extends StatelessWidget { + /// Creates a const [_MenuItemLabel]. + /// + /// The [child] and [hasSubmenu] arguments are required. + const _MenuItemLabel({ + required this.hasSubmenu, + this.showDecoration = true, + this.leadingIcon, + this.trailingIcon, + this.shortcut, + required this.child, + }); + + /// Whether or not this menu has a submenu. + /// + /// Determines whether the submenu arrow is shown or not. + final bool hasSubmenu; + + /// Whether or not this item should show decorations like shortcut labels or + /// submenu arrows. Items in a [MenuBar] don't show these decorations when + /// they are laid out horizontally. + final bool showDecoration; + + /// The optional icon that comes before the [child]. + final Widget? leadingIcon; + + /// The optional icon that comes after the [child]. + final Widget? trailingIcon; + + /// The shortcut for this label, so that it can generate a string describing + /// the shortcut. + final MenuSerializableShortcut? shortcut; + + /// The required label child widget. + final Widget child; + + @override + Widget build(BuildContext context) { + final VisualDensity density = Theme.of(context).visualDensity; + final double horizontalPadding = math.max( + _kLabelItemMinSpacing, + _kLabelItemDefaultSpacing + density.horizontal * 2, + ); + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: <Widget>[ + Row( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + if (leadingIcon != null) leadingIcon!, + Padding( + padding: leadingIcon != null ? EdgeInsetsDirectional.only(start: horizontalPadding) : EdgeInsets.zero, + child: child, + ), + ], + ), + if (trailingIcon != null) + Padding( + padding: EdgeInsetsDirectional.only(start: horizontalPadding), + child: trailingIcon, + ), + if (showDecoration && shortcut != null) + Padding( + padding: EdgeInsetsDirectional.only(start: horizontalPadding), + child: Text( + _LocalizedShortcutLabeler.instance.getShortcutLabel( + shortcut!, + MaterialLocalizations.of(context), + ), + ), + ), + if (showDecoration && hasSubmenu) + Padding( + padding: EdgeInsetsDirectional.only(start: horizontalPadding), + child: const Icon( + Icons.arrow_right, // Automatically switches with text direction. + size: _kDefaultSubmenuIconSize, + ), + ), + ], + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('child', child.toString())); + properties.add(DiagnosticsProperty<MenuSerializableShortcut>('shortcut', shortcut, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('hasSubmenu', hasSubmenu)); + properties.add(DiagnosticsProperty<bool>('showDecoration', showDecoration)); + } +} + +// Positions the menu in the view while trying to keep as much as possible +// visible in the view. +class _MenuLayout extends SingleChildLayoutDelegate { + const _MenuLayout({ + required this.anchorRect, + required this.textDirection, + required this.alignment, + required this.alignmentOffset, + required this.menuPosition, + required this.menuPadding, + required this.avoidBounds, + required this.orientation, + required this.parentOrientation, + }); + + // Rectangle of underlying button, relative to the overlay's dimensions. + final Rect anchorRect; + + // Whether to prefer going to the left or to the right. + final TextDirection textDirection; + + // The alignment to use when finding the ideal location for the menu. + final AlignmentGeometry alignment; + + // The offset from the alignment position to find the ideal location for the + // menu. + final Offset alignmentOffset; + + // The position passed to the open method, if any. + final Offset? menuPosition; + + // The padding on the inside of the menu, so it can be accounted for when + // positioning. + final EdgeInsetsGeometry menuPadding; + + // List of rectangles that we should avoid overlapping. Unusable screen area. + final Set<Rect> avoidBounds; + + // The orientation of this menu + final Axis orientation; + + // The orientation of this menu's parent. + final Axis parentOrientation; + + @override + BoxConstraints getConstraintsForChild(BoxConstraints constraints) { + // The menu can be at most the size of the overlay minus _kMenuViewPadding + // pixels in each direction. + return BoxConstraints.loose(constraints.biggest).deflate( + const EdgeInsets.all(_kMenuViewPadding), + ); + } + + @override + Offset getPositionForChild(Size size, Size childSize) { + // size: The size of the overlay. + // childSize: The size of the menu, when fully open, as determined by + // getConstraintsForChild. + final Rect overlayRect = Offset.zero & size; + double x; + double y; + if (menuPosition == null) { + Offset desiredPosition = alignment.resolve(textDirection).withinRect(anchorRect); + final Offset directionalOffset; + if (alignment is AlignmentDirectional) { + switch (textDirection) { + case TextDirection.rtl: + directionalOffset = Offset(-alignmentOffset.dx, alignmentOffset.dy); + case TextDirection.ltr: + directionalOffset = alignmentOffset; + } + } else { + directionalOffset = alignmentOffset; + } + desiredPosition += directionalOffset; + x = desiredPosition.dx; + y = desiredPosition.dy; + switch (textDirection) { + case TextDirection.rtl: + x -= childSize.width; + case TextDirection.ltr: + break; + } + } else { + final Offset adjustedPosition = menuPosition! + anchorRect.topLeft; + x = adjustedPosition.dx; + y = adjustedPosition.dy; + } + + final Iterable<Rect> subScreens = DisplayFeatureSubScreen.subScreensInBounds(overlayRect, avoidBounds); + final Rect allowedRect = _closestScreen(subScreens, anchorRect.center); + bool offLeftSide(double x) => x < allowedRect.left; + bool offRightSide(double x) => x + childSize.width > allowedRect.right; + bool offTop(double y) => y < allowedRect.top; + bool offBottom(double y) => y + childSize.height > allowedRect.bottom; + // Avoid going outside an area defined as the rectangle offset from the + // edge of the screen by the button padding. If the menu is off of the screen, + // move the menu to the other side of the button first, and then if it + // doesn't fit there, then just move it over as much as needed to make it + // fit. + if (childSize.width >= allowedRect.width) { + // It just doesn't fit, so put as much on the screen as possible. + x = allowedRect.left; + } else { + if (offLeftSide(x)) { + // If the parent is a different orientation than the current one, then + // just push it over instead of trying the other side. + if (parentOrientation != orientation) { + x = allowedRect.left; + } else { + final double newX = anchorRect.right + alignmentOffset.dx; + if (!offRightSide(newX)) { + x = newX; + } else { + x = allowedRect.left; + } + } + } else if (offRightSide(x)) { + if (parentOrientation != orientation) { + x = allowedRect.right - childSize.width; + } else { + final double newX = anchorRect.left - childSize.width - alignmentOffset.dx; + if (!offLeftSide(newX)) { + x = newX; + } else { + x = allowedRect.right - childSize.width; + } + } + } + } + if (childSize.height >= allowedRect.height) { + // Too tall to fit, fit as much on as possible. + y = allowedRect.top; + } else { + if (offTop(y)) { + final double newY = anchorRect.bottom; + if (!offBottom(newY)) { + y = newY; + } else { + y = allowedRect.top; + } + } else if (offBottom(y)) { + final double newY = anchorRect.top - childSize.height; + if (!offTop(newY)) { + // Only move the menu up if its parent is horizontal (MenuAnchor/MenuBar). + if (parentOrientation == Axis.horizontal) { + y = newY - alignmentOffset.dy; + } else { + y = newY; + } + } else { + y = allowedRect.bottom - childSize.height; + } + } + } + return Offset(x, y); + } + + @override + bool shouldRelayout(_MenuLayout oldDelegate) { + return anchorRect != oldDelegate.anchorRect + || textDirection != oldDelegate.textDirection + || alignment != oldDelegate.alignment + || alignmentOffset != oldDelegate.alignmentOffset + || menuPosition != oldDelegate.menuPosition + || menuPadding != oldDelegate.menuPadding + || orientation != oldDelegate.orientation + || parentOrientation != oldDelegate.parentOrientation + || !setEquals(avoidBounds, oldDelegate.avoidBounds); + } + + Rect _closestScreen(Iterable<Rect> screens, Offset point) { + Rect closest = screens.first; + for (final Rect screen in screens) { + if ((screen.center - point).distance < (closest.center - point).distance) { + closest = screen; + } + } + return closest; + } +} + +/// A widget that manages a list of menu buttons in a menu. +/// +/// It sizes itself to the widest/tallest item it contains, and then sizes all +/// the other entries to match. +class _MenuPanel extends StatefulWidget { + const _MenuPanel({ + required this.menuStyle, + this.clipBehavior = Clip.none, + required this.orientation, + this.crossAxisUnconstrained = true, + required this.children, + }); + + /// The menu style that has all the attributes for this menu panel. + final MenuStyle? menuStyle; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// Determine if a [UnconstrainedBox] can be applied to the menu panel to allow it to render + /// at its "natural" size. + /// + /// Defaults to true. When it is set to false, it can be useful when the menu should + /// be constrained in both main-axis and cross-axis, such as a [DropdownMenu]. + final bool crossAxisUnconstrained; + + /// The layout orientation of this panel. + final Axis orientation; + + /// The list of widgets to use as children of this menu bar. + /// + /// These are the top level [SubmenuButton]s. + final List<Widget> children; + + @override + State<_MenuPanel> createState() => _MenuPanelState(); +} + +class _MenuPanelState extends State<_MenuPanel> { + ScrollController scrollController = ScrollController(); + + @override + Widget build(BuildContext context) { + final MenuStyle? themeStyle; + final MenuStyle defaultStyle; + switch (widget.orientation) { + case Axis.horizontal: + themeStyle = MenuBarTheme.of(context).style; + defaultStyle = _MenuBarDefaultsM3(context); + case Axis.vertical: + themeStyle = MenuTheme.of(context).style; + defaultStyle = _MenuDefaultsM3(context); + } + final MenuStyle? widgetStyle = widget.menuStyle; + + T? effectiveValue<T>(T? Function(MenuStyle? style) getProperty) { + return getProperty(widgetStyle) ?? getProperty(themeStyle) ?? getProperty(defaultStyle); + } + + T? resolve<T>(MaterialStateProperty<T>? Function(MenuStyle? style) getProperty) { + return effectiveValue( + (MenuStyle? style) { + return getProperty(style)?.resolve(<MaterialState>{}); + }, + ); + } + + final Color? backgroundColor = resolve<Color?>((MenuStyle? style) => style?.backgroundColor); + final Color? shadowColor = resolve<Color?>((MenuStyle? style) => style?.shadowColor); + final Color? surfaceTintColor = resolve<Color?>((MenuStyle? style) => style?.surfaceTintColor); + final double elevation = resolve<double?>((MenuStyle? style) => style?.elevation) ?? 0; + final Size? minimumSize = resolve<Size?>((MenuStyle? style) => style?.minimumSize); + final Size? fixedSize = resolve<Size?>((MenuStyle? style) => style?.fixedSize); + final Size? maximumSize = resolve<Size?>((MenuStyle? style) => style?.maximumSize); + final BorderSide? side = resolve<BorderSide?>((MenuStyle? style) => style?.side); + final OutlinedBorder shape = resolve<OutlinedBorder?>((MenuStyle? style) => style?.shape)!.copyWith(side: side); + final VisualDensity visualDensity = + effectiveValue((MenuStyle? style) => style?.visualDensity) ?? VisualDensity.standard; + final EdgeInsetsGeometry padding = + resolve<EdgeInsetsGeometry?>((MenuStyle? style) => style?.padding) ?? EdgeInsets.zero; + final Offset densityAdjustment = visualDensity.baseSizeAdjustment; + // Per the Material Design team: don't allow the VisualDensity + // adjustment to reduce the width of the left/right padding. If we + // did, VisualDensity.compact, the default for desktop/web, would + // reduce the horizontal padding to zero. + final double dy = densityAdjustment.dy; + final double dx = math.max(0, densityAdjustment.dx); + final EdgeInsetsGeometry resolvedPadding = padding + .add(EdgeInsets.symmetric(horizontal: dx, vertical: dy)) + .clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity); + + BoxConstraints effectiveConstraints = visualDensity.effectiveConstraints( + BoxConstraints( + minWidth: minimumSize?.width ?? 0, + minHeight: minimumSize?.height ?? 0, + maxWidth: maximumSize?.width ?? double.infinity, + maxHeight: maximumSize?.height ?? double.infinity, + ), + ); + if (fixedSize != null) { + final Size size = effectiveConstraints.constrain(fixedSize); + if (size.width.isFinite) { + effectiveConstraints = effectiveConstraints.copyWith( + minWidth: size.width, + maxWidth: size.width, + ); + } + if (size.height.isFinite) { + effectiveConstraints = effectiveConstraints.copyWith( + minHeight: size.height, + maxHeight: size.height, + ); + } + } + + Widget menuPanel = _intrinsicCrossSize( + child: Material( + elevation: elevation, + shape: shape, + color: backgroundColor, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + type: backgroundColor == null ? MaterialType.transparency : MaterialType.canvas, + clipBehavior: widget.clipBehavior, + child: Padding( + padding: resolvedPadding, + child: ScrollConfiguration( + behavior: ScrollConfiguration.of(context).copyWith( + scrollbars: false, + overscroll: false, + physics: const ClampingScrollPhysics(), + ), + child: PrimaryScrollController( + controller: scrollController, + child: Scrollbar( + thumbVisibility: true, + child: SingleChildScrollView( + controller: scrollController, + scrollDirection: widget.orientation, + child: Flex( + crossAxisAlignment: CrossAxisAlignment.start, + textDirection: Directionality.of(context), + direction: widget.orientation, + mainAxisSize: MainAxisSize.min, + children: widget.children, + ), + ), + ), + ), + ), + ), + ), + ); + + if (widget.crossAxisUnconstrained) { + menuPanel = UnconstrainedBox( + constrainedAxis: widget.orientation, + clipBehavior: Clip.hardEdge, + alignment: AlignmentDirectional.centerStart, + child: menuPanel, + ); + } + + return ConstrainedBox( + constraints: effectiveConstraints, + child: menuPanel, + ); + } + + Widget _intrinsicCrossSize({required Widget child}) { + switch (widget.orientation) { + case Axis.horizontal: + return IntrinsicHeight(child: child); + case Axis.vertical: + return IntrinsicWidth(child: child); + } + } +} + +// A widget that defines the menu drawn in the overlay. +class _Submenu extends StatelessWidget { + const _Submenu({ + required this.anchor, + required this.menuStyle, + required this.menuPosition, + required this.alignmentOffset, + required this.clipBehavior, + this.crossAxisUnconstrained = true, + required this.menuChildren, + }); + + final _MenuAnchorState anchor; + final MenuStyle? menuStyle; + final Offset? menuPosition; + final Offset alignmentOffset; + final Clip clipBehavior; + final bool crossAxisUnconstrained; + final List<Widget> menuChildren; + + @override + Widget build(BuildContext context) { + // Use the text direction of the context where the button is. + final TextDirection textDirection = Directionality.of(context); + final MenuStyle? themeStyle; + final MenuStyle defaultStyle; + switch (anchor._parent?._orientation ?? Axis.horizontal) { + case Axis.horizontal: + themeStyle = MenuBarTheme.of(context).style; + defaultStyle = _MenuBarDefaultsM3(context); + case Axis.vertical: + themeStyle = MenuTheme.of(context).style; + defaultStyle = _MenuDefaultsM3(context); + } + T? effectiveValue<T>(T? Function(MenuStyle? style) getProperty) { + return getProperty(menuStyle) ?? getProperty(themeStyle) ?? getProperty(defaultStyle); + } + T? resolve<T>(MaterialStateProperty<T>? Function(MenuStyle? style) getProperty) { + return effectiveValue( + (MenuStyle? style) { + return getProperty(style)?.resolve(<MaterialState>{}); + }, + ); + } + + final MaterialStateMouseCursor mouseCursor = _MouseCursor( + (Set<MaterialState> states) => effectiveValue((MenuStyle? style) => style?.mouseCursor?.resolve(states)), + ); + + final VisualDensity visualDensity = + effectiveValue((MenuStyle? style) => style?.visualDensity) ?? Theme.of(context).visualDensity; + final AlignmentGeometry alignment = effectiveValue((MenuStyle? style) => style?.alignment)!; + final BuildContext anchorContext = anchor._anchorKey.currentContext!; + final RenderBox overlay = Overlay.of(anchorContext).context.findRenderObject()! as RenderBox; + final RenderBox anchorBox = anchorContext.findRenderObject()! as RenderBox; + final Offset upperLeft = anchorBox.localToGlobal(Offset.zero, ancestor: overlay); + final Offset bottomRight = anchorBox.localToGlobal(anchorBox.paintBounds.bottomRight, ancestor: overlay); + final Rect anchorRect = Rect.fromPoints(upperLeft, bottomRight); + final EdgeInsetsGeometry padding = + resolve<EdgeInsetsGeometry?>((MenuStyle? style) => style?.padding) ?? EdgeInsets.zero; + final Offset densityAdjustment = visualDensity.baseSizeAdjustment; + // Per the Material Design team: don't allow the VisualDensity + // adjustment to reduce the width of the left/right padding. If we + // did, VisualDensity.compact, the default for desktop/web, would + // reduce the horizontal padding to zero. + final double dy = densityAdjustment.dy; + final double dx = math.max(0, densityAdjustment.dx); + final EdgeInsetsGeometry resolvedPadding = padding + .add(EdgeInsets.fromLTRB(dx, dy, dx, dy)) + .clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity); + + return Theme( + data: Theme.of(context).copyWith( + visualDensity: visualDensity, + ), + child: ConstrainedBox( + constraints: BoxConstraints.loose(overlay.paintBounds.size), + child: CustomSingleChildLayout( + delegate: _MenuLayout( + anchorRect: anchorRect, + textDirection: textDirection, + avoidBounds: DisplayFeatureSubScreen.avoidBounds(MediaQuery.of(context)).toSet(), + menuPadding: resolvedPadding, + alignment: alignment, + alignmentOffset: alignmentOffset, + menuPosition: menuPosition, + orientation: anchor._orientation, + parentOrientation: anchor._parent?._orientation ?? Axis.horizontal, + ), + child: TapRegion( + groupId: anchor._root, + consumeOutsideTaps: anchor._root._isOpen && anchor.widget.consumeOutsideTap, + onTapOutside: (PointerDownEvent event) { + anchor._close(); + }, + child: MouseRegion( + cursor: mouseCursor, + hitTestBehavior: HitTestBehavior.deferToChild, + child: FocusScope( + node: anchor._menuScopeNode, + skipTraversal: true, + child: Actions( + actions: <Type, Action<Intent>>{ + DirectionalFocusIntent: _MenuDirectionalFocusAction(), + DismissIntent: DismissMenuAction(controller: anchor._menuController), + }, + child: Shortcuts( + shortcuts: _kMenuTraversalShortcuts, + child: _MenuPanel( + menuStyle: menuStyle, + clipBehavior: clipBehavior, + orientation: anchor._orientation, + crossAxisUnconstrained: crossAxisUnconstrained, + children: menuChildren, + ), + ), + ), + ), + ), + ), + ), + ), + ); + } +} + +/// Wraps the [MaterialStateMouseCursor] so that it can default to +/// [MouseCursor.uncontrolled] if none is set. +class _MouseCursor extends MaterialStateMouseCursor { + const _MouseCursor(this.resolveCallback); + + final MaterialPropertyResolver<MouseCursor?> resolveCallback; + + @override + MouseCursor resolve(Set<MaterialState> states) => resolveCallback(states) ?? MouseCursor.uncontrolled; + + @override + String get debugDescription => 'Menu_MouseCursor'; +} + +/// A debug print function, which should only be called within an assert, like +/// so: +/// +/// assert(_debugMenuInfo('Debug Message')); +/// +/// so that the call is entirely removed in release builds. +/// +/// Enable debug printing by setting [_kDebugMenus] to true at the top of the +/// file. +bool _debugMenuInfo(String message, [Iterable<String>? details]) { + assert(() { + if (_kDebugMenus) { + debugPrint('MENU: $message'); + if (details != null && details.isNotEmpty) { + for (final String detail in details) { + debugPrint(' $detail'); + } + } + } + return true; + }()); + // Return true so that it can be easily used inside of an assert. + return true; +} + +/// Whether [defaultTargetPlatform] is an Apple platform (Mac or iOS). +bool get _isApple { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return true; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return false; + } +} + +/// Whether [defaultTargetPlatform] is one that uses symbolic shortcuts. +/// +/// Mac and iOS use special symbols for modifier keys instead of their names, +/// render them in a particular order defined by Apple's human interface +/// guidelines, and format them so that the modifier keys always align. +bool get _usesSymbolicModifiers { + return _isApple; +} + + +bool get _platformSupportsAccelerators { + // On iOS and macOS, pressing the Option key (a.k.a. the Alt key) causes a + // different set of characters to be generated, and the native menus don't + // support accelerators anyhow, so we just disable accelerators on these + // platforms. + return !_isApple; +} + +// BEGIN GENERATED TOKEN PROPERTIES - Menu + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _MenuBarDefaultsM3 extends MenuStyle { + _MenuBarDefaultsM3(this.context) + : super( + elevation: const MaterialStatePropertyAll<double?>(3.0), + shape: const MaterialStatePropertyAll<OutlinedBorder>(_defaultMenuBorder), + alignment: AlignmentDirectional.bottomStart, + ); + + static const RoundedRectangleBorder _defaultMenuBorder = + RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))); + + final BuildContext context; + + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + MaterialStateProperty<Color?> get backgroundColor { + return MaterialStatePropertyAll<Color?>(_colors.surface); + } + + @override + MaterialStateProperty<Color?>? get shadowColor { + return MaterialStatePropertyAll<Color?>(_colors.shadow); + } + + @override + MaterialStateProperty<Color?>? get surfaceTintColor { + return MaterialStatePropertyAll<Color?>(_colors.surfaceTint); + } + + @override + MaterialStateProperty<EdgeInsetsGeometry?>? get padding { + return const MaterialStatePropertyAll<EdgeInsetsGeometry>( + EdgeInsetsDirectional.symmetric( + horizontal: _kTopLevelMenuHorizontalMinPadding + ), + ); + } + + @override + VisualDensity get visualDensity => Theme.of(context).visualDensity; +} + +class _MenuButtonDefaultsM3 extends ButtonStyle { + _MenuButtonDefaultsM3(this.context) + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: AlignmentDirectional.centerStart, + ); + + final BuildContext context; + + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + MaterialStateProperty<Color?>? get backgroundColor { + return ButtonStyleButton.allOrNull<Color>(Colors.transparent); + } + + // No default shadow color + + // No default surface tint color + + @override + MaterialStateProperty<double>? get elevation { + return ButtonStyleButton.allOrNull<double>(0.0); + } + + @override + MaterialStateProperty<Color?>? get foregroundColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface; + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface; + } + return _colors.onSurface; + }); + } + + @override + MaterialStateProperty<Color?>? get iconColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.pressed)) { + return _colors.onSurfaceVariant; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurfaceVariant; + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurfaceVariant; + } + return _colors.onSurfaceVariant; + }); + } + + // No default fixedSize + + @override + MaterialStateProperty<Size>? get maximumSize { + return ButtonStyleButton.allOrNull<Size>(Size.infinite); + } + + @override + MaterialStateProperty<Size>? get minimumSize { + return ButtonStyleButton.allOrNull<Size>(const Size(64.0, 48.0)); + } + + @override + MaterialStateProperty<MouseCursor?>? get mouseCursor { + return MaterialStateProperty.resolveWith( + (Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return SystemMouseCursors.click; + }, + ); + } + + @override + MaterialStateProperty<Color?>? get overlayColor { + return MaterialStateProperty.resolveWith( + (Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface.withOpacity(0.12); + } + return Colors.transparent; + }, + ); + } + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding { + return ButtonStyleButton.allOrNull<EdgeInsetsGeometry>(_scaledPadding(context)); + } + + // No default side + + @override + MaterialStateProperty<OutlinedBorder>? get shape { + return ButtonStyleButton.allOrNull<OutlinedBorder>(const RoundedRectangleBorder()); + } + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; + + @override + MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize; + + @override + MaterialStateProperty<TextStyle?> get textStyle { + // TODO(tahatesser): This is taken from https://m3.material.io/components/menus/specs + // Update this when the token is available. + return MaterialStatePropertyAll<TextStyle?>(_textTheme.labelLarge); + } + + @override + VisualDensity? get visualDensity => Theme.of(context).visualDensity; + + // The horizontal padding number comes from the spec. + EdgeInsetsGeometry _scaledPadding(BuildContext context) { + VisualDensity visualDensity = Theme.of(context).visualDensity; + // When horizontal VisualDensity is greater than zero, set it to zero + // because the [ButtonStyleButton] has already handle the padding based on the density. + // However, the [ButtonStyleButton] doesn't allow the [VisualDensity] adjustment + // to reduce the width of the left/right padding, so we need to handle it here if + // the density is less than zero, such as on desktop platforms. + if (visualDensity.horizontal > 0) { + visualDensity = VisualDensity(vertical: visualDensity.vertical); + } + return ButtonStyleButton.scaledPadding( + EdgeInsets.symmetric(horizontal: math.max( + _kMenuViewPadding, + _kLabelItemDefaultSpacing + visualDensity.baseSizeAdjustment.dx, + )), + EdgeInsets.symmetric(horizontal: math.max( + _kMenuViewPadding, + 8 + visualDensity.baseSizeAdjustment.dx, + )), + const EdgeInsets.symmetric(horizontal: _kMenuViewPadding), + MediaQuery.maybeTextScaleFactorOf(context) ?? 1, + ); + } +} + +class _MenuDefaultsM3 extends MenuStyle { + _MenuDefaultsM3(this.context) + : super( + elevation: const MaterialStatePropertyAll<double?>(3.0), + shape: const MaterialStatePropertyAll<OutlinedBorder>(_defaultMenuBorder), + alignment: AlignmentDirectional.topEnd, + ); + + static const RoundedRectangleBorder _defaultMenuBorder = + RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))); + + final BuildContext context; + + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + MaterialStateProperty<Color?> get backgroundColor { + return MaterialStatePropertyAll<Color?>(_colors.surface); + } + + @override + MaterialStateProperty<Color?>? get surfaceTintColor { + return MaterialStatePropertyAll<Color?>(_colors.surfaceTint); + } + + @override + MaterialStateProperty<Color?>? get shadowColor { + return MaterialStatePropertyAll<Color?>(_colors.shadow); + } + + @override + MaterialStateProperty<EdgeInsetsGeometry?>? get padding { + return const MaterialStatePropertyAll<EdgeInsetsGeometry>( + EdgeInsetsDirectional.symmetric(vertical: _kMenuVerticalMinPadding), + ); + } + + @override + VisualDensity get visualDensity => Theme.of(context).visualDensity; +} + +// END GENERATED TOKEN PROPERTIES - Menu diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_bar_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_bar_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..9eb34e6a8f1a6f44b07ce5d19e4706dfc8d14f72 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_bar_theme.dart @@ -0,0 +1,115 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'menu_anchor.dart'; +import 'menu_style.dart'; +import 'menu_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// late Widget child; + +/// A data class that [MenuBarTheme] uses to define the visual properties of +/// [MenuBar] widgets. +/// +/// This class defines the visual properties of [MenuBar] widgets themselves, +/// but not their submenus. Those properties are defined by [MenuThemeData] or +/// [MenuButtonThemeData] instead. +/// +/// Descendant widgets obtain the current [MenuBarThemeData] object using +/// `MenuBarTheme.of(context)`. +/// +/// Typically, a [MenuBarThemeData] is specified as part of the overall [Theme] +/// with [ThemeData.menuBarTheme]. Otherwise, [MenuTheme] can be used to +/// configure its own widget subtree. +/// +/// All [MenuBarThemeData] properties are `null` by default. If any of these +/// properties are null, the menu bar will provide its own defaults. +/// +/// See also: +/// +/// * [MenuThemeData], which describes the theme for the submenus of a +/// [MenuBar]. +/// * [MenuButtonThemeData], which describes the theme for the [MenuItemButton]s +/// in a menu. +/// * [ThemeData], which describes the overall theme for the application. +@immutable +class MenuBarThemeData extends MenuThemeData { + /// Creates a const set of properties used to configure [MenuTheme]. + const MenuBarThemeData({super.style}); + + /// Linearly interpolate between two [MenuBar] themes. + static MenuBarThemeData? lerp(MenuBarThemeData? a, MenuBarThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return MenuBarThemeData(style: MenuStyle.lerp(a?.style, b?.style, t)); + } +} + +/// An inherited widget that defines the configuration for the [MenuBar] widgets +/// in this widget's descendants. +/// +/// This class defines the visual properties of [MenuBar] widgets themselves, +/// but not their submenus. Those properties are defined by [MenuTheme] or +/// [MenuButtonTheme] instead. +/// +/// Values specified here are used for [MenuBar]'s properties that are not given +/// an explicit non-null value. +/// +/// See also: +/// * [MenuStyle], a configuration object that holds attributes of a menu, and +/// is used by this theme to define those attributes. +/// * [MenuTheme], which does the same thing for the menus created by a +/// [SubmenuButton] or [MenuAnchor]. +/// * [MenuButtonTheme], which does the same thing for the [MenuItemButton]s +/// inside of the menus. +/// * [SubmenuButton], a button that manages a submenu that uses these +/// properties. +/// * [MenuBar], a widget that creates a menu bar that can use [SubmenuButton]s. +class MenuBarTheme extends InheritedTheme { + /// Creates a theme that controls the configurations for [MenuBar] and + /// [MenuItemButton] in its widget subtree. + const MenuBarTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties to set for [MenuBar] in this widget's descendants. + final MenuBarThemeData data; + + /// Returns the closest instance of this class's [data] value that encloses + /// the given context. If there is no ancestor, it returns + /// [ThemeData.menuBarTheme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return MenuTheme( + /// data: const MenuThemeData( + /// style: MenuStyle( + /// backgroundColor: MaterialStatePropertyAll<Color?>(Colors.red), + /// ), + /// ), + /// child: child, + /// ); + /// } + /// ``` + static MenuBarThemeData of(BuildContext context) { + final MenuBarTheme? menuBarTheme = context.dependOnInheritedWidgetOfExactType<MenuBarTheme>(); + return menuBarTheme?.data ?? Theme.of(context).menuBarTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return MenuBarTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(MenuBarTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_button_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_button_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..47bf9b4c58f1a9cfce96222b7149c640a2cf1435 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_button_theme.dart @@ -0,0 +1,137 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'material_state.dart'; +import 'menu_anchor.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// A [ButtonStyle] theme that overrides the default appearance of +/// [SubmenuButton]s and [MenuItemButton]s when it's used with a +/// [MenuButtonTheme] or with the overall [Theme]'s [ThemeData.menuTheme]. +/// +/// The [style]'s properties override [MenuItemButton]'s and [SubmenuButton]'s +/// default style, i.e. the [ButtonStyle] returned by +/// [MenuItemButton.defaultStyleOf] and [SubmenuButton.defaultStyleOf]. Only the +/// style's non-null property values or resolved non-null +/// [MaterialStateProperty] values are used. +/// +/// See also: +/// +/// * [MenuButtonTheme], the theme which is configured with this class. +/// * [MenuTheme], the theme used to configure the look of the menus these +/// buttons reside in. +/// * [MenuItemButton.defaultStyleOf] and [SubmenuButton.defaultStyleOf] which +/// return the default [ButtonStyle]s for menu buttons. +/// * [MenuItemButton.styleFrom] and [SubmenuButton.styleFrom], which converts +/// simple values into a [ButtonStyle] that's consistent with their respective +/// defaults. +/// * [MaterialStateProperty.resolve], "resolve" a material state property to a +/// simple value based on a set of [MaterialState]s. +/// * [ThemeData.menuButtonTheme], which can be used to override the default +/// [ButtonStyle] for [MenuItemButton]s and [SubmenuButton]s below the overall +/// [Theme]. +/// * [MenuAnchor], a widget which hosts cascading menus. +/// * [MenuBar], a widget which defines a menu bar of buttons hosting cascading +/// menus. +@immutable +class MenuButtonThemeData with Diagnosticable { + /// Creates a [MenuButtonThemeData]. + /// + /// The [style] may be null. + const MenuButtonThemeData({this.style}); + + /// Overrides for [SubmenuButton] and [MenuItemButton]'s default style. + /// + /// Non-null properties or non-null resolved [MaterialStateProperty] values + /// override the [ButtonStyle] returned by [SubmenuButton.defaultStyleOf] or + /// [MenuItemButton.defaultStyleOf]. + /// + /// If [style] is null, then this theme doesn't override anything. + final ButtonStyle? style; + + /// Linearly interpolate between two menu button themes. + static MenuButtonThemeData? lerp(MenuButtonThemeData? a, MenuButtonThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return MenuButtonThemeData(style: ButtonStyle.lerp(a?.style, b?.style, t)); + } + + @override + int get hashCode => style.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is MenuButtonThemeData && other.style == style; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ButtonStyle>('style', style, defaultValue: null)); + } +} + +/// Overrides the default [ButtonStyle] of its [MenuItemButton] and +/// [SubmenuButton] descendants. +/// +/// See also: +/// +/// * [MenuButtonThemeData], which is used to configure this theme. +/// * [MenuTheme], the theme used to configure the look of the menus themselves. +/// * [MenuItemButton.defaultStyleOf] and [SubmenuButton.defaultStyleOf] which +/// return the default [ButtonStyle]s for menu buttons. +/// * [MenuItemButton.styleFrom] and [SubmenuButton.styleFrom], which converts +/// simple values into a [ButtonStyle] that's consistent with their respective +/// defaults. +/// * [ThemeData.menuButtonTheme], which can be used to override the default +/// [ButtonStyle] for [MenuItemButton]s and [SubmenuButton]s below the overall +/// [Theme]. +class MenuButtonTheme extends InheritedTheme { + /// Create a [MenuButtonTheme]. + const MenuButtonTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The configuration of this theme. + final MenuButtonThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [MenuButtonTheme] widget, then + /// [ThemeData.menuButtonTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// MenuButtonThemeData theme = MenuButtonTheme.of(context); + /// ``` + static MenuButtonThemeData of(BuildContext context) { + final MenuButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<MenuButtonTheme>(); + return buttonTheme?.data ?? Theme.of(context).menuButtonTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return MenuButtonTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(MenuButtonTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_style.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_style.dart new file mode 100644 index 0000000000000000000000000000000000000000..aa4dcb12ba4aef7dee1c4056332929516c45dd8f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_style.dart @@ -0,0 +1,370 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'material_state.dart'; +import 'menu_anchor.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// late Widget child; +// late BuildContext context; +// late MenuStyle style; +// @immutable +// class MyAppHome extends StatelessWidget { +// const MyAppHome({super.key}); +// @override +// Widget build(BuildContext context) => const SizedBox(); +// } + +/// The visual properties that menus have in common. +/// +/// Menus created by [MenuBar] and [MenuAnchor] and their themes have a +/// [MenuStyle] property which defines the visual properties whose default +/// values are to be overridden. The default values are defined by the +/// individual menu widgets and are typically based on overall theme's +/// [ThemeData.colorScheme] and [ThemeData.textTheme]. +/// +/// All of the [MenuStyle] properties are null by default. +/// +/// Many of the [MenuStyle] properties are [MaterialStateProperty] objects which +/// resolve to different values depending on the menu's state. For example the +/// [Color] properties are defined with `MaterialStateProperty<Color>` and can +/// resolve to different colors depending on if the menu is pressed, hovered, +/// focused, disabled, etc. +/// +/// These properties can override the default value for just one state or all of +/// them. For example to create a [SubmenuButton] whose background color is the +/// color scheme’s primary color with 50% opacity, but only when the menu is +/// pressed, one could write: +/// +/// ```dart +/// SubmenuButton( +/// menuStyle: MenuStyle( +/// backgroundColor: MaterialStateProperty.resolveWith<Color?>( +/// (Set<MaterialState> states) { +/// if (states.contains(MaterialState.focused)) { +/// return Theme.of(context).colorScheme.primary.withOpacity(0.5); +/// } +/// return null; // Use the component's default. +/// }, +/// ), +/// ), +/// menuChildren: const <Widget>[ /* ... */ ], +/// child: const Text('Fly me to the moon'), +/// ), +/// ``` +/// +/// In this case the background color for all other menu states would fall back +/// to the [SubmenuButton]'s default values. To unconditionally set the menu's +/// [backgroundColor] for all states one could write: +/// +/// ```dart +/// const SubmenuButton( +/// menuStyle: MenuStyle( +/// backgroundColor: MaterialStatePropertyAll<Color>(Colors.green), +/// ), +/// menuChildren: <Widget>[ /* ... */ ], +/// child: Text('Let me play among the stars'), +/// ), +/// ``` +/// +/// To configure all of the application's menus in the same way, specify the +/// overall theme's `menuTheme`: +/// +/// ```dart +/// MaterialApp( +/// theme: ThemeData( +/// menuTheme: const MenuThemeData( +/// style: MenuStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.red)), +/// ), +/// ), +/// home: const MyAppHome(), +/// ), +/// ``` +/// +/// See also: +/// +/// * [MenuAnchor], a widget which hosts cascading menus. +/// * [MenuBar], a widget which defines a menu bar of buttons hosting cascading +/// menus. +/// * [MenuButtonTheme], the theme for [SubmenuButton]s and [MenuItemButton]s. +/// * [ButtonStyle], a similar configuration object for button styles. +@immutable +class MenuStyle with Diagnosticable { + /// Create a [MenuStyle]. + const MenuStyle({ + this.backgroundColor, + this.shadowColor, + this.surfaceTintColor, + this.elevation, + this.padding, + this.minimumSize, + this.fixedSize, + this.maximumSize, + this.side, + this.shape, + this.mouseCursor, + this.visualDensity, + this.alignment, + }); + + /// The menu's background fill color. + final MaterialStateProperty<Color?>? backgroundColor; + + /// The shadow color of the menu's [Material]. + /// + /// The material's elevation shadow can be difficult to see for dark themes, + /// so by default the menu classes add a semi-transparent overlay to indicate + /// elevation. See [ThemeData.applyElevationOverlayColor]. + final MaterialStateProperty<Color?>? shadowColor; + + /// The surface tint color of the menu's [Material]. + /// + /// See [Material.surfaceTintColor] for more details. + final MaterialStateProperty<Color?>? surfaceTintColor; + + /// The elevation of the menu's [Material]. + final MaterialStateProperty<double?>? elevation; + + /// The padding between the menu's boundary and its child. + final MaterialStateProperty<EdgeInsetsGeometry?>? padding; + + /// The minimum size of the menu itself. + /// + /// This value must be less than or equal to [maximumSize]. + final MaterialStateProperty<Size?>? minimumSize; + + /// The menu's size. + /// + /// This size is still constrained by the style's [minimumSize] and + /// [maximumSize]. Fixed size dimensions whose value is [double.infinity] are + /// ignored. + /// + /// To specify menus with a fixed width and the default height use `fixedSize: + /// Size.fromWidth(320)`. Similarly, to specify a fixed height and the default + /// width use `fixedSize: Size.fromHeight(100)`. + final MaterialStateProperty<Size?>? fixedSize; + + /// The maximum size of the menu itself. + /// + /// A [Size.infinite] or null value for this property means that the menu's + /// maximum size is not constrained. + /// + /// This value must be greater than or equal to [minimumSize]. + final MaterialStateProperty<Size?>? maximumSize; + + /// The color and weight of the menu's outline. + /// + /// This value is combined with [shape] to create a shape decorated with an + /// outline. + final MaterialStateProperty<BorderSide?>? side; + + /// The shape of the menu's underlying [Material]. + /// + /// This shape is combined with [side] to create a shape decorated with an + /// outline. + final MaterialStateProperty<OutlinedBorder?>? shape; + + /// The cursor for a mouse pointer when it enters or is hovering over this + /// menu's [InkWell]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// Defines how compact the menu's layout will be. + /// + /// {@macro flutter.material.themedata.visualDensity} + /// + /// See also: + /// + /// * [ThemeData.visualDensity], which specifies the [visualDensity] for all + /// widgets within a [Theme]. + final VisualDensity? visualDensity; + + /// Determines the desired alignment of the submenu when opened relative to + /// the button that opens it. + /// + /// If there isn't sufficient space to open the menu with the given alignment, + /// and there's space on the other side of the button, then the alignment is + /// swapped to it's opposite (1 becomes -1, etc.), and the menu will try to + /// appear on the other side of the button. If there isn't enough space there + /// either, then the menu will be pushed as far over as necessary to display + /// as much of itself as possible, possibly overlapping the parent button. + final AlignmentGeometry? alignment; + + @override + int get hashCode { + final List<Object?> values = <Object?>[ + backgroundColor, + shadowColor, + surfaceTintColor, + elevation, + padding, + minimumSize, + fixedSize, + maximumSize, + side, + shape, + mouseCursor, + visualDensity, + alignment, + ]; + return Object.hashAll(values); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is MenuStyle + && other.backgroundColor == backgroundColor + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.elevation == elevation + && other.padding == padding + && other.minimumSize == minimumSize + && other.fixedSize == fixedSize + && other.maximumSize == maximumSize + && other.side == side + && other.shape == shape + && other.mouseCursor == mouseCursor + && other.visualDensity == visualDensity + && other.alignment == alignment; + } + + /// Returns a copy of this MenuStyle with the given fields replaced with + /// the new values. + MenuStyle copyWith({ + MaterialStateProperty<Color?>? backgroundColor, + MaterialStateProperty<Color?>? shadowColor, + MaterialStateProperty<Color?>? surfaceTintColor, + MaterialStateProperty<double?>? elevation, + MaterialStateProperty<EdgeInsetsGeometry?>? padding, + MaterialStateProperty<Size?>? minimumSize, + MaterialStateProperty<Size?>? fixedSize, + MaterialStateProperty<Size?>? maximumSize, + MaterialStateProperty<BorderSide?>? side, + MaterialStateProperty<OutlinedBorder?>? shape, + MaterialStateProperty<MouseCursor?>? mouseCursor, + VisualDensity? visualDensity, + AlignmentGeometry? alignment, + }) { + return MenuStyle( + backgroundColor: backgroundColor ?? this.backgroundColor, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + elevation: elevation ?? this.elevation, + padding: padding ?? this.padding, + minimumSize: minimumSize ?? this.minimumSize, + fixedSize: fixedSize ?? this.fixedSize, + maximumSize: maximumSize ?? this.maximumSize, + side: side ?? this.side, + shape: shape ?? this.shape, + mouseCursor: mouseCursor ?? this.mouseCursor, + visualDensity: visualDensity ?? this.visualDensity, + alignment: alignment ?? this.alignment, + ); + } + + /// Returns a copy of this MenuStyle where the non-null fields in [style] + /// have replaced the corresponding null fields in this MenuStyle. + /// + /// In other words, [style] is used to fill in unspecified (null) fields + /// this MenuStyle. + MenuStyle merge(MenuStyle? style) { + if (style == null) { + return this; + } + return copyWith( + backgroundColor: backgroundColor ?? style.backgroundColor, + shadowColor: shadowColor ?? style.shadowColor, + surfaceTintColor: surfaceTintColor ?? style.surfaceTintColor, + elevation: elevation ?? style.elevation, + padding: padding ?? style.padding, + minimumSize: minimumSize ?? style.minimumSize, + fixedSize: fixedSize ?? style.fixedSize, + maximumSize: maximumSize ?? style.maximumSize, + side: side ?? style.side, + shape: shape ?? style.shape, + mouseCursor: mouseCursor ?? style.mouseCursor, + visualDensity: visualDensity ?? style.visualDensity, + alignment: alignment ?? style.alignment, + ); + } + + /// Linearly interpolate between two [MenuStyle]s. + static MenuStyle? lerp(MenuStyle? a, MenuStyle? b, double t) { + if (identical(a, b)) { + return a; + } + return MenuStyle( + backgroundColor: MaterialStateProperty.lerp<Color?>(a?.backgroundColor, b?.backgroundColor, t, Color.lerp), + shadowColor: MaterialStateProperty.lerp<Color?>(a?.shadowColor, b?.shadowColor, t, Color.lerp), + surfaceTintColor: MaterialStateProperty.lerp<Color?>(a?.surfaceTintColor, b?.surfaceTintColor, t, Color.lerp), + elevation: MaterialStateProperty.lerp<double?>(a?.elevation, b?.elevation, t, lerpDouble), + padding: MaterialStateProperty.lerp<EdgeInsetsGeometry?>(a?.padding, b?.padding, t, EdgeInsetsGeometry.lerp), + minimumSize: MaterialStateProperty.lerp<Size?>(a?.minimumSize, b?.minimumSize, t, Size.lerp), + fixedSize: MaterialStateProperty.lerp<Size?>(a?.fixedSize, b?.fixedSize, t, Size.lerp), + maximumSize: MaterialStateProperty.lerp<Size?>(a?.maximumSize, b?.maximumSize, t, Size.lerp), + side: _LerpSides(a?.side, b?.side, t), + shape: MaterialStateProperty.lerp<OutlinedBorder?>(a?.shape, b?.shape, t, OutlinedBorder.lerp), + mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, + visualDensity: t < 0.5 ? a?.visualDensity : b?.visualDensity, + alignment: AlignmentGeometry.lerp(a?.alignment, b?.alignment, t), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('shadowColor', shadowColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('elevation', elevation, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<EdgeInsetsGeometry?>>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('minimumSize', minimumSize, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('fixedSize', fixedSize, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('maximumSize', maximumSize, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<BorderSide?>>('side', side, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<OutlinedBorder?>>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null)); + properties.add(DiagnosticsProperty<VisualDensity>('visualDensity', visualDensity, defaultValue: null)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: null)); + } +} + +/// A required helper class because [BorderSide.lerp] doesn't support passing or +/// returning null values. +class _LerpSides implements MaterialStateProperty<BorderSide?> { + const _LerpSides(this.a, this.b, this.t); + + final MaterialStateProperty<BorderSide?>? a; + final MaterialStateProperty<BorderSide?>? b; + final double t; + + @override + BorderSide? resolve(Set<MaterialState> states) { + final BorderSide? resolvedA = a?.resolve(states); + final BorderSide? resolvedB = b?.resolve(states); + if (resolvedA == null && resolvedB == null) { + return null; + } + if (resolvedA == null) { + return BorderSide.lerp(BorderSide(width: 0, color: resolvedB!.color.withAlpha(0)), resolvedB, t); + } + if (resolvedB == null) { + return BorderSide.lerp(resolvedA, BorderSide(width: 0, color: resolvedA.color.withAlpha(0)), t); + } + return BorderSide.lerp(resolvedA, resolvedB, t); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..22f3a5bfde51dcc60ebbc5e9b18c2644f310edc7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/menu_theme.dart @@ -0,0 +1,133 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'menu_anchor.dart'; +import 'menu_style.dart'; +import 'theme.dart'; + +// Examples can assume: +// late Widget child; + +/// Defines the configuration of the submenus created by the [SubmenuButton], +/// [MenuBar], or [MenuAnchor] widgets. +/// +/// Descendant widgets obtain the current [MenuThemeData] object using +/// `MenuTheme.of(context)`. +/// +/// Typically, a [MenuThemeData] is specified as part of the overall [Theme] +/// with [ThemeData.menuTheme]. Otherwise, [MenuTheme] can be used to configure +/// its own widget subtree. +/// +/// All [MenuThemeData] properties are `null` by default. If any of these +/// properties are null, the menu bar will provide its own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme for the application. +/// * [MenuBarThemeData], which describes the theme for the menu bar itself in a +/// [MenuBar] widget. +@immutable +class MenuThemeData with Diagnosticable { + /// Creates a const set of properties used to configure [MenuTheme]. + const MenuThemeData({this.style}); + + /// The [MenuStyle] of a [SubmenuButton] menu. + /// + /// Any values not set in the [MenuStyle] will use the menu default for that + /// property. + final MenuStyle? style; + + /// Linearly interpolate between two menu button themes. + static MenuThemeData? lerp(MenuThemeData? a, MenuThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return MenuThemeData(style: MenuStyle.lerp(a?.style, b?.style, t)); + } + + @override + int get hashCode => style.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is MenuThemeData && other.style == style; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MenuStyle>('style', style, defaultValue: null)); + } +} + +/// An inherited widget that defines the configuration in this widget's +/// descendants for menus created by the [SubmenuButton], [MenuBar], or +/// [MenuAnchor] widgets. +/// +/// Values specified here are used for [SubmenuButton]'s menu properties that +/// are not given an explicit non-null value. +/// +/// See also: +/// +/// * [MenuThemeData], a configuration object that holds attributes of a menu +/// used by this theme. +/// * [MenuBarTheme], which does the same thing for the [MenuBar] widget. +/// * [MenuBar], a widget that manages [MenuItemButton]s. +/// * [MenuAnchor], a widget that creates a region that has a submenu. +/// * [MenuItemButton], a widget that is a selectable item in a menu bar menu. +/// * [SubmenuButton], a widget that specifies an item with a cascading submenu +/// in a [MenuBar] menu. +class MenuTheme extends InheritedTheme { + /// Creates a const theme that controls the configurations for the menus + /// created by the [SubmenuButton] or [MenuAnchor] widgets. + const MenuTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties for [MenuBar] and [MenuItemButton] in this widget's + /// descendants. + final MenuThemeData data; + + /// Returns the closest instance of this class's [data] value that encloses + /// the given context. If there is no ancestor, it returns + /// [ThemeData.menuTheme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return MenuTheme( + /// data: const MenuThemeData( + /// style: MenuStyle( + /// backgroundColor: MaterialStatePropertyAll<Color>(Colors.red), + /// ), + /// ), + /// child: child, + /// ); + /// } + /// ``` + static MenuThemeData of(BuildContext context) { + final MenuTheme? menuTheme = context.dependOnInheritedWidgetOfExactType<MenuTheme>(); + return menuTheme?.data ?? Theme.of(context).menuTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return MenuTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(MenuTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/mergeable_material.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/mergeable_material.dart new file mode 100644 index 0000000000000000000000000000000000000000..f209555d0d32b9e660c61f8d59d490fffdccf582 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/mergeable_material.dart @@ -0,0 +1,744 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'divider.dart'; +import 'material.dart'; +import 'theme.dart'; + +/// The base type for [MaterialSlice] and [MaterialGap]. +/// +/// All [MergeableMaterialItem] objects need a [LocalKey]. +@immutable +abstract class MergeableMaterialItem { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const MergeableMaterialItem(this.key); + + /// The key for this item of the list. + /// + /// The key is used to match parts of the mergeable material from frame to + /// frame so that state is maintained appropriately even as slices are added + /// or removed. + final LocalKey key; +} + +/// A class that can be used as a child to [MergeableMaterial]. It is a slice +/// of [Material] that animates merging with other slices. +/// +/// All [MaterialSlice] objects need a [LocalKey]. +class MaterialSlice extends MergeableMaterialItem { + /// Creates a slice of [Material] that's mergeable within a + /// [MergeableMaterial]. + const MaterialSlice({ + required LocalKey key, + required this.child, + this.color, + }) : super(key); + + /// The contents of this slice. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// Defines the color for the slice. + /// + /// By default, the value of [color] is [ThemeData.cardColor]. + final Color? color; + + @override + String toString() { + return 'MergeableSlice(key: $key, child: $child, color: $color)'; + } +} + +/// A class that represents a gap within [MergeableMaterial]. +/// +/// All [MaterialGap] objects need a [LocalKey]. +class MaterialGap extends MergeableMaterialItem { + /// Creates a Material gap with a given size. + const MaterialGap({ + required LocalKey key, + this.size = 16.0, + }) : super(key); + + /// The main axis extent of this gap. For example, if the [MergeableMaterial] + /// is vertical, then this is the height of the gap. + final double size; + + @override + String toString() { + return 'MaterialGap(key: $key, child: $size)'; + } +} + +/// Displays a list of [MergeableMaterialItem] children. The list contains +/// [MaterialSlice] items whose boundaries are either "merged" with adjacent +/// items or separated by a [MaterialGap]. The [children] are distributed along +/// the given [mainAxis] in the same way as the children of a [ListBody]. When +/// the list of children changes, gaps are automatically animated open or closed +/// as needed. +/// +/// To enable this widget to correlate its list of children with the previous +/// one, each child must specify a key. +/// +/// When a new gap is added to the list of children the adjacent items are +/// animated apart. Similarly when a gap is removed the adjacent items are +/// brought back together. +/// +/// When a new slice is added or removed, the app is responsible for animating +/// the transition of the slices, while the gaps will be animated automatically. +/// +/// See also: +/// +/// * [Card], a piece of material that does not support splitting and merging +/// but otherwise looks the same. +class MergeableMaterial extends StatefulWidget { + /// Creates a mergeable Material list of items. + const MergeableMaterial({ + super.key, + this.mainAxis = Axis.vertical, + this.elevation = 2, + this.hasDividers = false, + this.children = const <MergeableMaterialItem>[], + this.dividerColor, + }); + + /// The children of the [MergeableMaterial]. + final List<MergeableMaterialItem> children; + + /// The main layout axis. + final Axis mainAxis; + + /// The z-coordinate at which to place all the [Material] slices. + /// + /// Defaults to 2, the appropriate elevation for cards. + final double elevation; + + /// Whether connected pieces of [MaterialSlice] have dividers between them. + final bool hasDividers; + + /// Defines color used for dividers if [hasDividers] is true. + /// + /// If [dividerColor] is null, then [DividerThemeData.color] is used. If that + /// is null, then [ThemeData.dividerColor] is used. + final Color? dividerColor; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<Axis>('mainAxis', mainAxis)); + properties.add(DoubleProperty('elevation', elevation)); + } + + @override + State<MergeableMaterial> createState() => _MergeableMaterialState(); +} + +class _AnimationTuple { + _AnimationTuple({ + required this.controller, + required this.startAnimation, + required this.endAnimation, + required this.gapAnimation, + }); + + final AnimationController controller; + final CurvedAnimation startAnimation; + final CurvedAnimation endAnimation; + final CurvedAnimation gapAnimation; + double gapStart = 0.0; + + @mustCallSuper + void dispose() { + controller.dispose(); + startAnimation.dispose(); + endAnimation.dispose(); + gapAnimation.dispose(); + } +} + +class _MergeableMaterialState extends State<MergeableMaterial> with TickerProviderStateMixin { + late List<MergeableMaterialItem> _children; + final Map<LocalKey, _AnimationTuple?> _animationTuples = <LocalKey, _AnimationTuple?>{}; + + @override + void initState() { + super.initState(); + _children = List<MergeableMaterialItem>.of(widget.children); + + for (int i = 0; i < _children.length; i += 1) { + final MergeableMaterialItem child = _children[i]; + if (child is MaterialGap) { + _initGap(child); + _animationTuples[child.key]!.controller.value = 1.0; // Gaps are initially full-sized. + } + } + assert(_debugGapsAreValid(_children)); + } + + void _initGap(MaterialGap gap) { + final AnimationController controller = AnimationController( + duration: kThemeAnimationDuration, + vsync: this, + ); + + final CurvedAnimation startAnimation = CurvedAnimation( + parent: controller, + curve: Curves.fastOutSlowIn, + ); + final CurvedAnimation endAnimation = CurvedAnimation( + parent: controller, + curve: Curves.fastOutSlowIn, + ); + final CurvedAnimation gapAnimation = CurvedAnimation( + parent: controller, + curve: Curves.fastOutSlowIn, + ); + + controller.addListener(_handleTick); + + _animationTuples[gap.key] = _AnimationTuple( + controller: controller, + startAnimation: startAnimation, + endAnimation: endAnimation, + gapAnimation: gapAnimation, + ); + } + + @override + void dispose() { + for (final MergeableMaterialItem child in _children) { + if (child is MaterialGap) { + _animationTuples[child.key]!.dispose(); + } + } + super.dispose(); + } + + void _handleTick() { + setState(() { + // The animation's state is our build state, and it changed already. + }); + } + + bool _debugHasConsecutiveGaps(List<MergeableMaterialItem> children) { + for (int i = 0; i < widget.children.length - 1; i += 1) { + if (widget.children[i] is MaterialGap && + widget.children[i + 1] is MaterialGap) { + return true; + } + } + return false; + } + + bool _debugGapsAreValid(List<MergeableMaterialItem> children) { + // Check for consecutive gaps. + if (_debugHasConsecutiveGaps(children)) { + return false; + } + + // First and last children must not be gaps. + if (children.isNotEmpty) { + if (children.first is MaterialGap || children.last is MaterialGap) { + return false; + } + } + + return true; + } + + void _insertChild(int index, MergeableMaterialItem child) { + _children.insert(index, child); + + if (child is MaterialGap) { + _initGap(child); + } + } + + void _removeChild(int index) { + final MergeableMaterialItem child = _children.removeAt(index); + + if (child is MaterialGap) { + _animationTuples[child.key]!.dispose(); + _animationTuples[child.key] = null; + } + } + + bool _isClosingGap(int index) { + if (index < _children.length - 1 && _children[index] is MaterialGap) { + return _animationTuples[_children[index].key]!.controller.status == + AnimationStatus.reverse; + } + + return false; + } + + void _removeEmptyGaps() { + int j = 0; + + while (j < _children.length) { + if ( + _children[j] is MaterialGap && + _animationTuples[_children[j].key]!.controller.status == AnimationStatus.dismissed + ) { + _removeChild(j); + } else { + j += 1; + } + } + } + + @override + void didUpdateWidget(MergeableMaterial oldWidget) { + super.didUpdateWidget(oldWidget); + + final Set<LocalKey> oldKeys = oldWidget.children.map<LocalKey>( + (MergeableMaterialItem child) => child.key, + ).toSet(); + final Set<LocalKey> newKeys = widget.children.map<LocalKey>( + (MergeableMaterialItem child) => child.key, + ).toSet(); + final Set<LocalKey> newOnly = newKeys.difference(oldKeys); + final Set<LocalKey> oldOnly = oldKeys.difference(newKeys); + + final List<MergeableMaterialItem> newChildren = widget.children; + int i = 0; + int j = 0; + + assert(_debugGapsAreValid(newChildren)); + + _removeEmptyGaps(); + + while (i < newChildren.length && j < _children.length) { + if (newOnly.contains(newChildren[i].key) || + oldOnly.contains(_children[j].key)) { + final int startNew = i; + final int startOld = j; + + // Skip new keys. + while (newOnly.contains(newChildren[i].key)) { + i += 1; + } + + // Skip old keys. + while (oldOnly.contains(_children[j].key) || _isClosingGap(j)) { + j += 1; + } + + final int newLength = i - startNew; + final int oldLength = j - startOld; + + if (newLength > 0) { + if (oldLength > 1 || + oldLength == 1 && _children[startOld] is MaterialSlice) { + if (newLength == 1 && newChildren[startNew] is MaterialGap) { + // Shrink all gaps into the size of the new one. + double gapSizeSum = 0.0; + + while (startOld < j) { + final MergeableMaterialItem child = _children[startOld]; + if (child is MaterialGap) { + final MaterialGap gap = child; + gapSizeSum += gap.size; + } + + _removeChild(startOld); + j -= 1; + } + + _insertChild(startOld, newChildren[startNew]); + _animationTuples[newChildren[startNew].key]! + ..gapStart = gapSizeSum + ..controller.forward(); + + j += 1; + } else { + // No animation if replaced items are more than one. + for (int k = 0; k < oldLength; k += 1) { + _removeChild(startOld); + } + for (int k = 0; k < newLength; k += 1) { + _insertChild(startOld + k, newChildren[startNew + k]); + } + + j += newLength - oldLength; + } + } else if (oldLength == 1) { + if (newLength == 1 && newChildren[startNew] is MaterialGap && + _children[startOld].key == newChildren[startNew].key) { + /// Special case: gap added back. + _animationTuples[newChildren[startNew].key]!.controller.forward(); + } else { + final double gapSize = _getGapSize(startOld); + + _removeChild(startOld); + + for (int k = 0; k < newLength; k += 1) { + _insertChild(startOld + k, newChildren[startNew + k]); + } + + j += newLength - 1; + double gapSizeSum = 0.0; + + for (int k = startNew; k < i; k += 1) { + final MergeableMaterialItem newChild = newChildren[k]; + if (newChild is MaterialGap) { + gapSizeSum += newChild.size; + } + } + + // All gaps get proportional sizes of the original gap and they will + // animate to their actual size. + for (int k = startNew; k < i; k += 1) { + final MergeableMaterialItem newChild = newChildren[k]; + if (newChild is MaterialGap) { + _animationTuples[newChild.key]!.gapStart = gapSize * newChild.size / gapSizeSum; + _animationTuples[newChild.key]!.controller + ..value = 0.0 + ..forward(); + } + } + } + } else { + // Grow gaps. + for (int k = 0; k < newLength; k += 1) { + final MergeableMaterialItem newChild = newChildren[startNew + k]; + + _insertChild(startOld + k, newChild); + + if (newChild is MaterialGap) { + _animationTuples[newChild.key]!.controller.forward(); + } + } + + j += newLength; + } + } else { + // If more than a gap disappeared, just remove slices and shrink gaps. + if (oldLength > 1 || + oldLength == 1 && _children[startOld] is MaterialSlice) { + double gapSizeSum = 0.0; + + while (startOld < j) { + final MergeableMaterialItem child = _children[startOld]; + if (child is MaterialGap) { + gapSizeSum += child.size; + } + + _removeChild(startOld); + j -= 1; + } + + if (gapSizeSum != 0.0) { + final MaterialGap gap = MaterialGap( + key: UniqueKey(), + size: gapSizeSum, + ); + _insertChild(startOld, gap); + _animationTuples[gap.key]!.gapStart = 0.0; + _animationTuples[gap.key]!.controller + ..value = 1.0 + ..reverse(); + + j += 1; + } + } else if (oldLength == 1) { + // Shrink gap. + final MaterialGap gap = _children[startOld] as MaterialGap; + _animationTuples[gap.key]!.gapStart = 0.0; + _animationTuples[gap.key]!.controller.reverse(); + } + } + } else { + // Check whether the items are the same type. If they are, it means that + // their places have been swapped. + if ((_children[j] is MaterialGap) == (newChildren[i] is MaterialGap)) { + _children[j] = newChildren[i]; + + i += 1; + j += 1; + } else { + // This is a closing gap which we need to skip. + assert(_children[j] is MaterialGap); + j += 1; + } + } + } + + // Handle remaining items. + while (j < _children.length) { + _removeChild(j); + } + while (i < newChildren.length) { + final MergeableMaterialItem newChild = newChildren[i]; + _insertChild(j, newChild); + + if (newChild is MaterialGap) { + _animationTuples[newChild.key]!.controller.forward(); + } + + i += 1; + j += 1; + } + } + + BorderRadius _borderRadius(int index, bool start, bool end) { + assert(kMaterialEdges[MaterialType.card]!.topLeft == kMaterialEdges[MaterialType.card]!.topRight); + assert(kMaterialEdges[MaterialType.card]!.topLeft == kMaterialEdges[MaterialType.card]!.bottomLeft); + assert(kMaterialEdges[MaterialType.card]!.topLeft == kMaterialEdges[MaterialType.card]!.bottomRight); + final Radius cardRadius = kMaterialEdges[MaterialType.card]!.topLeft; + + Radius startRadius = Radius.zero; + Radius endRadius = Radius.zero; + + if (index > 0 && _children[index - 1] is MaterialGap) { + startRadius = Radius.lerp( + Radius.zero, + cardRadius, + _animationTuples[_children[index - 1].key]!.startAnimation.value, + )!; + } + if (index < _children.length - 2 && _children[index + 1] is MaterialGap) { + endRadius = Radius.lerp( + Radius.zero, + cardRadius, + _animationTuples[_children[index + 1].key]!.endAnimation.value, + )!; + } + + if (widget.mainAxis == Axis.vertical) { + return BorderRadius.vertical( + top: start ? cardRadius : startRadius, + bottom: end ? cardRadius : endRadius, + ); + } else { + return BorderRadius.horizontal( + left: start ? cardRadius : startRadius, + right: end ? cardRadius : endRadius, + ); + } + } + + double _getGapSize(int index) { + final MaterialGap gap = _children[index] as MaterialGap; + + return lerpDouble( + _animationTuples[gap.key]!.gapStart, + gap.size, + _animationTuples[gap.key]!.gapAnimation.value, + )!; + } + + bool _willNeedDivider(int index) { + if (index < 0) { + return false; + } + if (index >= _children.length) { + return false; + } + return _children[index] is MaterialSlice || _isClosingGap(index); + } + + @override + Widget build(BuildContext context) { + _removeEmptyGaps(); + + final List<Widget> widgets = <Widget>[]; + List<Widget> slices = <Widget>[]; + int i; + + for (i = 0; i < _children.length; i += 1) { + if (_children[i] is MaterialGap) { + assert(slices.isNotEmpty); + widgets.add( + ListBody( + mainAxis: widget.mainAxis, + children: slices, + ), + ); + slices = <Widget>[]; + + widgets.add( + SizedBox( + width: widget.mainAxis == Axis.horizontal ? _getGapSize(i) : null, + height: widget.mainAxis == Axis.vertical ? _getGapSize(i) : null, + ), + ); + } else { + final MaterialSlice slice = _children[i] as MaterialSlice; + Widget child = slice.child; + + if (widget.hasDividers) { + final bool hasTopDivider = _willNeedDivider(i - 1); + final bool hasBottomDivider = _willNeedDivider(i + 1); + + final BorderSide divider = Divider.createBorderSide( + context, + width: 0.5, // TODO(ianh): This probably looks terrible when the dpr isn't a power of two. + color: widget.dividerColor, + ); + + final Border border; + if (i == 0) { + border = Border( + bottom: hasBottomDivider ? divider : BorderSide.none, + ); + } else if (i == _children.length - 1) { + border = Border( + top: hasTopDivider ? divider : BorderSide.none, + ); + } else { + border = Border( + top: hasTopDivider ? divider : BorderSide.none, + bottom: hasBottomDivider ? divider : BorderSide.none, + ); + } + + child = AnimatedContainer( + key: _MergeableMaterialSliceKey(_children[i].key), + decoration: BoxDecoration(border: border), + duration: kThemeAnimationDuration, + curve: Curves.fastOutSlowIn, + child: child, + ); + } + + slices.add( + Container( + decoration: BoxDecoration( + color: (_children[i] as MaterialSlice).color ?? Theme.of(context).cardColor, + borderRadius: _borderRadius(i, i == 0, i == _children.length - 1), + ), + child: Material( + type: MaterialType.transparency, + child: child, + ), + ), + ); + } + } + + if (slices.isNotEmpty) { + widgets.add( + ListBody( + mainAxis: widget.mainAxis, + children: slices, + ), + ); + slices = <Widget>[]; + } + + return _MergeableMaterialListBody( + mainAxis: widget.mainAxis, + elevation: widget.elevation, + items: _children, + children: widgets, + ); + } +} + +// The parent hierarchy can change and lead to the slice being +// rebuilt. Using a global key solves the issue. +class _MergeableMaterialSliceKey extends GlobalKey { + const _MergeableMaterialSliceKey(this.value) : super.constructor(); + + final LocalKey value; + + @override + bool operator ==(Object other) { + return other is _MergeableMaterialSliceKey + && other.value == value; + } + + @override + int get hashCode => value.hashCode; + + @override + String toString() { + return '_MergeableMaterialSliceKey($value)'; + } +} + +class _MergeableMaterialListBody extends ListBody { + const _MergeableMaterialListBody({ + required super.children, + super.mainAxis, + required this.items, + required this.elevation, + }); + + final List<MergeableMaterialItem> items; + final double elevation; + + AxisDirection _getDirection(BuildContext context) { + return getAxisDirectionFromAxisReverseAndDirectionality(context, mainAxis, false); + } + + @override + RenderListBody createRenderObject(BuildContext context) { + return _RenderMergeableMaterialListBody( + axisDirection: _getDirection(context), + elevation: elevation, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderListBody renderObject) { + final _RenderMergeableMaterialListBody materialRenderListBody = renderObject as _RenderMergeableMaterialListBody; + materialRenderListBody + ..axisDirection = _getDirection(context) + ..elevation = elevation; + } +} + +class _RenderMergeableMaterialListBody extends RenderListBody { + _RenderMergeableMaterialListBody({ + super.axisDirection, + double elevation = 0.0, + }) : _elevation = elevation; + + double get elevation => _elevation; + double _elevation; + set elevation(double value) { + if (value == _elevation) { + return; + } + _elevation = value; + markNeedsPaint(); + } + + void _paintShadows(Canvas canvas, Rect rect) { + // TODO(ianh): We should interpolate the border radii of the shadows the same way we do those of the visible Material slices. + if (elevation != 0) { + canvas.drawShadow( + Path()..addRRect(kMaterialEdges[MaterialType.card]!.toRRect(rect)), + Colors.black, + elevation, + true, // occluding object is not (necessarily) opaque + ); + } + } + + @override + void paint(PaintingContext context, Offset offset) { + RenderBox? child = firstChild; + int index = 0; + while (child != null) { + final ListBodyParentData childParentData = child.parentData! as ListBodyParentData; + final Rect rect = (childParentData.offset + offset) & child.size; + if (index.isEven) { + _paintShadows(context.canvas, rect); + } + child = childParentData.nextSibling; + index += 1; + } + defaultPaint(context, offset); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/motion.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/motion.dart new file mode 100644 index 0000000000000000000000000000000000000000..e93e8226254d2b43ac8e749ba32fe693ba1dc7fa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/motion.dart @@ -0,0 +1,234 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/animation.dart'; + +// BEGIN GENERATED TOKEN PROPERTIES - Motion + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +/// The set of durations in the Material specification. +/// +/// See also: +/// +/// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) +/// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) +abstract final class Durations { + /// The short1 duration (50ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration short1 = Duration(milliseconds: 50); + + /// The short2 duration (100ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration short2 = Duration(milliseconds: 100); + + /// The short3 duration (150ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration short3 = Duration(milliseconds: 150); + + /// The short4 duration (200ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration short4 = Duration(milliseconds: 200); + + /// The medium1 duration (250ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration medium1 = Duration(milliseconds: 250); + + /// The medium2 duration (300ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration medium2 = Duration(milliseconds: 300); + + /// The medium3 duration (350ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration medium3 = Duration(milliseconds: 350); + + /// The medium4 duration (400ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration medium4 = Duration(milliseconds: 400); + + /// The long1 duration (450ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration long1 = Duration(milliseconds: 450); + + /// The long2 duration (500ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration long2 = Duration(milliseconds: 500); + + /// The long3 duration (550ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration long3 = Duration(milliseconds: 550); + + /// The long4 duration (600ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration long4 = Duration(milliseconds: 600); + + /// The extralong1 duration (700ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration extralong1 = Duration(milliseconds: 700); + + /// The extralong2 duration (800ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration extralong2 = Duration(milliseconds: 800); + + /// The extralong3 duration (900ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration extralong3 = Duration(milliseconds: 900); + + /// The extralong4 duration (1000ms) in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Duration tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#c009dec6-f29b-4503-b9f0-482af14a8bbd) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Duration extralong4 = Duration(milliseconds: 1000); +} + + +// TODO(guidezpl): Improve with description and assets, b/289870605 + +/// The set of easing curves in the Material specification. +/// +/// See also: +/// +/// * [M3 guidelines: Easing tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#433b1153-2ea3-4fe2-9748-803a47bc97ee) +/// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) +/// * [Curves], for a collection of non-Material animation easing curves. +abstract final class Easing { + /// The emphasizedAccelerate easing curve in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Easing tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#433b1153-2ea3-4fe2-9748-803a47bc97ee) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Curve emphasizedAccelerate = Cubic(0.3, 0.0, 0.8, 0.15); + + /// The emphasizedDecelerate easing curve in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Easing tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#433b1153-2ea3-4fe2-9748-803a47bc97ee) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Curve emphasizedDecelerate = Cubic(0.05, 0.7, 0.1, 1.0); + + /// The linear easing curve in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Easing tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#433b1153-2ea3-4fe2-9748-803a47bc97ee) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Curve linear = Cubic(0.0, 0.0, 1.0, 1.0); + + /// The standard easing curve in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Easing tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#433b1153-2ea3-4fe2-9748-803a47bc97ee) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Curve standard = Cubic(0.2, 0.0, 0.0, 1.0); + + /// The standardAccelerate easing curve in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Easing tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#433b1153-2ea3-4fe2-9748-803a47bc97ee) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Curve standardAccelerate = Cubic(0.3, 0.0, 1.0, 1.0); + + /// The standardDecelerate easing curve in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Easing tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#433b1153-2ea3-4fe2-9748-803a47bc97ee) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Curve standardDecelerate = Cubic(0.0, 0.0, 0.0, 1.0); + + /// The legacyDecelerate easing curve in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Easing tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#433b1153-2ea3-4fe2-9748-803a47bc97ee) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Curve legacyDecelerate = Cubic(0.0, 0.0, 0.2, 1.0); + + /// The legacyAccelerate easing curve in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Easing tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#433b1153-2ea3-4fe2-9748-803a47bc97ee) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Curve legacyAccelerate = Cubic(0.4, 0.0, 1.0, 1.0); + + /// The legacy easing curve in the Material specification. + /// + /// See also: + /// + /// * [M3 guidelines: Easing tokens](https://m3.material.io/styles/motion/easing-and-duration/tokens-specs#433b1153-2ea3-4fe2-9748-803a47bc97ee) + /// * [M3 guidelines: Applying easing and duration](https://m3.material.io/styles/motion/easing-and-duration/applying-easing-and-duration) + static const Curve legacy = Cubic(0.4, 0.0, 0.2, 1.0); +} + +// END GENERATED TOKEN PROPERTIES - Motion diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..ca1f9db8acf1dc82be8e76920f53450ec0c82da3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_bar.dart @@ -0,0 +1,1399 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'elevation_overlay.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'navigation_bar_theme.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'tooltip.dart'; + +const double _kIndicatorHeight = 32; +const double _kIndicatorWidth = 64; + +// Examples can assume: +// late BuildContext context; +// late bool _isDrawerOpen; + +/// Material 3 Navigation Bar component. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=DVGYddFaLv0} +/// +/// Navigation bars offer a persistent and convenient way to switch between +/// primary destinations in an app. +/// +/// This widget does not adjust its size with the [ThemeData.visualDensity]. +/// +/// The [MediaQueryData.textScaler] does not adjust the size of this widget but +/// rather the size of the [Tooltip]s displayed on long presses of the +/// destinations. +/// +/// The style for the icons and text are not affected by parent +/// [DefaultTextStyle]s or [IconTheme]s but rather controlled by parameters or +/// the [NavigationBarThemeData]. +/// +/// This widget holds a collection of destinations (usually +/// [NavigationDestination]s). +/// +/// {@tool dartpad} +/// This example shows a [NavigationBar] as it is used within a [Scaffold] +/// widget. The [NavigationBar] has three [NavigationDestination] widgets and +/// the initial [selectedIndex] is set to index 0. The [onDestinationSelected] +/// callback changes the selected item's index and displays a corresponding +/// widget in the body of the [Scaffold]. +/// +/// ** See code in examples/api/lib/material/navigation_bar/navigation_bar.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example showcases [NavigationBar] label behaviors. When tapping on one +/// of the label behavior options, the [labelBehavior] of the [NavigationBar] +/// will be updated. +/// +/// ** See code in examples/api/lib/material/navigation_bar/navigation_bar.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows a [NavigationBar] within a main [Scaffold] +/// widget that's used to control the visibility of destination pages. +/// Each destination has its own scaffold and a nested navigator that +/// provides local navigation. The example's [NavigationBar] has four +/// [NavigationDestination] widgets with different color schemes. Its +/// [onDestinationSelected] callback changes the selected +/// destination's index and displays a corresponding page with its own +/// local navigator and scaffold - all within the body of the main +/// scaffold. The destination pages are organized in a [Stack] and +/// switching destinations fades out the current page and +/// fades in the new one. Destinations that aren't visible or animating +/// are kept [Offstage]. +/// +/// ** See code in examples/api/lib/material/navigation_bar/navigation_bar.2.dart ** +/// {@end-tool} +/// See also: +/// +/// * [NavigationDestination] +/// * [BottomNavigationBar] +/// * <https://api.flutter.dev/flutter/material/NavigationDestination-class.html> +/// * <https://m3.material.io/components/navigation-bar> +class NavigationBar extends StatelessWidget { + /// Creates a Material 3 Navigation Bar component. + /// + /// The value of [destinations] must be a list of two or more + /// [NavigationDestination] values. + // TODO(goderbauer): This class cannot be const constructed, https://github.com/dart-lang/linter/issues/3366. + // ignore: prefer_const_constructors_in_immutables + NavigationBar({ + super.key, + this.animationDuration, + this.selectedIndex = 0, + required this.destinations, + this.onDestinationSelected, + this.backgroundColor, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.indicatorColor, + this.indicatorShape, + this.height, + this.labelBehavior, + this.overlayColor, + }) : assert(destinations.length >= 2), + assert(0 <= selectedIndex && selectedIndex < destinations.length); + + /// Determines the transition time for each destination as it goes between + /// selected and unselected. + final Duration? animationDuration; + + /// Determines which one of the [destinations] is currently selected. + /// + /// When this is updated, the destination (from [destinations]) at + /// [selectedIndex] goes from unselected to selected. + final int selectedIndex; + + /// The list of destinations (usually [NavigationDestination]s) in this + /// [NavigationBar]. + /// + /// When [selectedIndex] is updated, the destination from this list at + /// [selectedIndex] will animate from 0 (unselected) to 1.0 (selected). When + /// the animation is increasing or completed, the destination is considered + /// selected, when the animation is decreasing or dismissed, the destination + /// is considered unselected. + final List<Widget> destinations; + + /// Called when one of the [destinations] is selected. + /// + /// This callback usually updates the int passed to [selectedIndex]. + /// + /// Upon updating [selectedIndex], the [NavigationBar] will be rebuilt. + final ValueChanged<int>? onDestinationSelected; + + /// The color of the [NavigationBar] itself. + /// + /// If null, [NavigationBarThemeData.backgroundColor] is used. If that + /// is also null, then if [ThemeData.useMaterial3] is true, the value is + /// [ColorScheme.surface]. If that is false, the default blends [ColorScheme.surface] + /// and [ColorScheme.onSurface] using an [ElevationOverlay]. + final Color? backgroundColor; + + /// The elevation of the [NavigationBar] itself. + /// + /// If null, [NavigationBarThemeData.elevation] is used. If that + /// is also null, then if [ThemeData.useMaterial3] is true then it will + /// be 3.0 otherwise 0.0. + final double? elevation; + + /// The color used for the drop shadow to indicate elevation. + /// + /// If null, [NavigationBarThemeData.shadowColor] is used. If that + /// is also null, the default value is [Colors.transparent] which + /// indicates that no drop shadow will be displayed. + /// + /// See [Material.shadowColor] for more details on drop shadows. + final Color? shadowColor; + + /// The color used as an overlay on [backgroundColor] to indicate elevation. + /// + /// If null, [NavigationBarThemeData.surfaceTintColor] is used. If that + /// is also null, the default value is [ColorScheme.surfaceTint]. + /// + /// See [Material.surfaceTintColor] for more details on how this + /// overlay is applied. + final Color? surfaceTintColor; + + /// The color of the [indicatorShape] when this destination is selected. + /// + /// If null, [NavigationBarThemeData.indicatorColor] is used. If that + /// is also null and [ThemeData.useMaterial3] is true, [ColorScheme.secondaryContainer] + /// is used. Otherwise, [ColorScheme.secondary] with an opacity of 0.24 is used. + final Color? indicatorColor; + + /// The shape of the selected indicator. + /// + /// If null, [NavigationBarThemeData.indicatorShape] is used. If that + /// is also null and [ThemeData.useMaterial3] is true, [StadiumBorder] is used. + /// Otherwise, [RoundedRectangleBorder] with a circular border radius of 16 is used. + final ShapeBorder? indicatorShape; + + /// The height of the [NavigationBar] itself. + /// + /// If this is used in [Scaffold.bottomNavigationBar] and the scaffold is + /// full-screen, the safe area padding is also added to the height + /// automatically. + /// + /// The height does not adjust with [ThemeData.visualDensity] or + /// [MediaQueryData.textScaler] as this component loses usability at + /// larger and smaller sizes due to the truncating of labels or smaller tap + /// targets. + /// + /// If null, [NavigationBarThemeData.height] is used. If that + /// is also null, the default is 80. + final double? height; + + /// Defines how the [destinations]' labels will be laid out and when they'll + /// be displayed. + /// + /// Can be used to show all labels, show only the selected label, or hide all + /// labels. + /// + /// If null, [NavigationBarThemeData.labelBehavior] is used. If that + /// is also null, the default is + /// [NavigationDestinationLabelBehavior.alwaysShow]. + final NavigationDestinationLabelBehavior? labelBehavior; + + /// The highlight color that's typically used to indicate that + /// the [NavigationDestination] is focused, hovered, or pressed. + final MaterialStateProperty<Color?>? overlayColor; + + VoidCallback _handleTap(int index) { + return onDestinationSelected != null + ? () => onDestinationSelected!(index) + : () {}; + } + + @override + Widget build(BuildContext context) { + final NavigationBarThemeData defaults = _defaultsFor(context); + + final NavigationBarThemeData navigationBarTheme = NavigationBarTheme.of(context); + final double effectiveHeight = height ?? navigationBarTheme.height ?? defaults.height!; + final NavigationDestinationLabelBehavior effectiveLabelBehavior = labelBehavior + ?? navigationBarTheme.labelBehavior + ?? defaults.labelBehavior!; + + return Material( + color: backgroundColor + ?? navigationBarTheme.backgroundColor + ?? defaults.backgroundColor!, + elevation: elevation ?? navigationBarTheme.elevation ?? defaults.elevation!, + shadowColor: shadowColor ?? navigationBarTheme.shadowColor ?? defaults.shadowColor, + surfaceTintColor: surfaceTintColor ?? navigationBarTheme.surfaceTintColor ?? defaults.surfaceTintColor, + child: SafeArea( + child: SizedBox( + height: effectiveHeight, + child: Row( + children: <Widget>[ + for (int i = 0; i < destinations.length; i++) + Expanded( + child: _SelectableAnimatedBuilder( + duration: animationDuration ?? const Duration(milliseconds: 500), + isSelected: i == selectedIndex, + builder: (BuildContext context, Animation<double> animation) { + return _NavigationDestinationInfo( + index: i, + selectedIndex: selectedIndex, + totalNumberOfDestinations: destinations.length, + selectedAnimation: animation, + labelBehavior: effectiveLabelBehavior, + indicatorColor: indicatorColor, + indicatorShape: indicatorShape, + overlayColor: overlayColor, + onTap: _handleTap(i), + child: destinations[i], + ); + }, + ), + ), + ], + ), + ), + ), + ); + } +} + +/// Specifies when each [NavigationDestination]'s label should appear. +/// +/// This is used to determine the behavior of [NavigationBar]'s destinations. +enum NavigationDestinationLabelBehavior { + /// Always shows all of the labels under each navigation bar destination, + /// selected and unselected. + alwaysShow, + + /// Never shows any of the labels under the navigation bar destinations, + /// regardless of selected vs unselected. + alwaysHide, + + /// Only shows the labels of the selected navigation bar destination. + /// + /// When a destination is unselected, the label will be faded out, and the + /// icon will be centered. + /// + /// When a destination is selected, the label will fade in and the label and + /// icon will slide up so that they are both centered. + onlyShowSelected, +} + +/// A Material 3 [NavigationBar] destination. +/// +/// Displays a label below an icon. Use with [NavigationBar.destinations]. +/// +/// See also: +/// +/// * [NavigationBar], for an interactive code sample. +class NavigationDestination extends StatelessWidget { + /// Creates a navigation bar destination with an icon and a label, to be used + /// in the [NavigationBar.destinations]. + const NavigationDestination({ + super.key, + required this.icon, + this.selectedIcon, + required this.label, + this.tooltip, + this.enabled = true, + }); + + /// The [Widget] (usually an [Icon]) that's displayed for this + /// [NavigationDestination]. + /// + /// The icon will use [NavigationBarThemeData.iconTheme]. If this is + /// null, the default [IconThemeData] would use a size of 24.0 and + /// [ColorScheme.onSurface]. + final Widget icon; + + /// The optional [Widget] (usually an [Icon]) that's displayed when this + /// [NavigationDestination] is selected. + /// + /// If [selectedIcon] is non-null, the destination will fade from + /// [icon] to [selectedIcon] when this destination goes from unselected to + /// selected. + /// + /// The icon will use [NavigationBarThemeData.iconTheme] with + /// [MaterialState.selected]. If this is null, the default [IconThemeData] + /// would use a size of 24.0 and [ColorScheme.onSurface]. + final Widget? selectedIcon; + + /// The text label that appears below the icon of this + /// [NavigationDestination]. + /// + /// The accompanying [Text] widget will use + /// [NavigationBarThemeData.labelTextStyle]. If this are null, the default + /// text style would use [TextTheme.labelSmall] with [ColorScheme.onSurface]. + final String label; + + /// The text to display in the tooltip for this [NavigationDestination], when + /// the user long presses the destination. + /// + /// If [tooltip] is an empty string, no tooltip will be used. + /// + /// Defaults to null, in which case the [label] text will be used. + final String? tooltip; + + /// Indicates that this destination is selectable. + /// + /// Defaults to true. + final bool enabled; + + @override + Widget build(BuildContext context) { + final _NavigationDestinationInfo info = _NavigationDestinationInfo.of(context); + const Set<MaterialState> selectedState = <MaterialState>{MaterialState.selected}; + const Set<MaterialState> unselectedState = <MaterialState>{}; + const Set<MaterialState> disabledState = <MaterialState>{MaterialState.disabled}; + + final NavigationBarThemeData navigationBarTheme = NavigationBarTheme.of(context); + final NavigationBarThemeData defaults = _defaultsFor(context); + final Animation<double> animation = info.selectedAnimation; + + return _NavigationDestinationBuilder( + label: label, + tooltip: tooltip, + enabled: enabled, + buildIcon: (BuildContext context) { + final IconThemeData selectedIconTheme = + navigationBarTheme.iconTheme?.resolve(selectedState) + ?? defaults.iconTheme!.resolve(selectedState)!; + final IconThemeData unselectedIconTheme = + navigationBarTheme.iconTheme?.resolve(unselectedState) + ?? defaults.iconTheme!.resolve(unselectedState)!; + final IconThemeData disabledIconTheme = + navigationBarTheme.iconTheme?.resolve(disabledState) + ?? defaults.iconTheme!.resolve(disabledState)!; + + final Widget selectedIconWidget = IconTheme.merge( + data: enabled ? selectedIconTheme : disabledIconTheme, + child: selectedIcon ?? icon, + ); + final Widget unselectedIconWidget = IconTheme.merge( + data: enabled ? unselectedIconTheme : disabledIconTheme, + child: icon, + ); + + return Stack( + alignment: Alignment.center, + children: <Widget>[ + NavigationIndicator( + animation: animation, + color: info.indicatorColor ?? navigationBarTheme.indicatorColor ?? defaults.indicatorColor!, + shape: info.indicatorShape ?? navigationBarTheme.indicatorShape ?? defaults.indicatorShape! + ), + _StatusTransitionWidgetBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + return _isForwardOrCompleted(animation) + ? selectedIconWidget + : unselectedIconWidget; + }, + ), + ], + ); + }, + buildLabel: (BuildContext context) { + final TextStyle? effectiveSelectedLabelTextStyle = navigationBarTheme.labelTextStyle?.resolve(selectedState) + ?? defaults.labelTextStyle!.resolve(selectedState); + final TextStyle? effectiveUnselectedLabelTextStyle = navigationBarTheme.labelTextStyle?.resolve(unselectedState) + ?? defaults.labelTextStyle!.resolve(unselectedState); + final TextStyle? effectiveDisabledLabelTextStyle = navigationBarTheme.labelTextStyle?.resolve(disabledState) + ?? defaults.labelTextStyle!.resolve(disabledState); + + final TextStyle? textStyle = enabled + ? _isForwardOrCompleted(animation) + ? effectiveSelectedLabelTextStyle + : effectiveUnselectedLabelTextStyle + : effectiveDisabledLabelTextStyle; + + return Padding( + padding: const EdgeInsets.only(top: 4), + child: MediaQuery.withClampedTextScaling( + // Don't scale labels of destinations, instead, tooltip text will + // upscale. + maxScaleFactor: 1.0, + child: Text(label, style: textStyle), + ), + ); + }, + ); + } +} + +/// Widget that handles the semantics and layout of a navigation bar +/// destination. +/// +/// Prefer [NavigationDestination] over this widget, as it is a simpler +/// (although less customizable) way to get navigation bar destinations. +/// +/// The icon and label of this destination are built with [buildIcon] and +/// [buildLabel]. They should build the unselected and selected icon and label +/// according to [_NavigationDestinationInfo.selectedAnimation], where an +/// animation value of 0 is unselected and 1 is selected. +/// +/// See [NavigationDestination] for an example. +class _NavigationDestinationBuilder extends StatefulWidget { + /// Builds a destination (icon + label) to use in a Material 3 [NavigationBar]. + const _NavigationDestinationBuilder({ + required this.buildIcon, + required this.buildLabel, + required this.label, + this.tooltip, + this.enabled = true, + }); + + /// Builds the icon for a destination in a [NavigationBar]. + /// + /// To animate between unselected and selected, build the icon based on + /// [_NavigationDestinationInfo.selectedAnimation]. When the animation is 0, + /// the destination is unselected, when the animation is 1, the destination is + /// selected. + /// + /// The destination is considered selected as soon as the animation is + /// increasing or completed, and it is considered unselected as soon as the + /// animation is decreasing or dismissed. + final WidgetBuilder buildIcon; + + /// Builds the label for a destination in a [NavigationBar]. + /// + /// To animate between unselected and selected, build the icon based on + /// [_NavigationDestinationInfo.selectedAnimation]. When the animation is + /// 0, the destination is unselected, when the animation is 1, the destination + /// is selected. + /// + /// The destination is considered selected as soon as the animation is + /// increasing or completed, and it is considered unselected as soon as the + /// animation is decreasing or dismissed. + final WidgetBuilder buildLabel; + + /// The text value of what is in the label widget, this is required for + /// semantics so that screen readers and tooltips can read the proper label. + final String label; + + /// The text to display in the tooltip for this [NavigationDestination], when + /// the user long presses the destination. + /// + /// If [tooltip] is an empty string, no tooltip will be used. + /// + /// Defaults to null, in which case the [label] text will be used. + final String? tooltip; + + /// Indicates that this destination is selectable. + /// + /// Defaults to true. + final bool enabled; + + @override + State<_NavigationDestinationBuilder> createState() => _NavigationDestinationBuilderState(); +} + +class _NavigationDestinationBuilderState extends State<_NavigationDestinationBuilder> { + final GlobalKey iconKey = GlobalKey(); + + @override + Widget build(BuildContext context) { + final _NavigationDestinationInfo info = _NavigationDestinationInfo.of(context); + final NavigationBarThemeData navigationBarTheme = NavigationBarTheme.of(context); + final NavigationBarThemeData defaults = _defaultsFor(context); + + return _NavigationBarDestinationSemantics( + child: _NavigationBarDestinationTooltip( + message: widget.tooltip ?? widget.label, + child: _IndicatorInkWell( + iconKey: iconKey, + labelBehavior: info.labelBehavior, + customBorder: info.indicatorShape ?? navigationBarTheme.indicatorShape ?? defaults.indicatorShape, + overlayColor: info.overlayColor ?? navigationBarTheme.overlayColor, + onTap: widget.enabled ? info.onTap : null, + child: Row( + children: <Widget>[ + Expanded( + child: _NavigationBarDestinationLayout( + icon: widget.buildIcon(context), + iconKey: iconKey, + label: widget.buildLabel(context), + ), + ), + ], + ), + ), + ), + ); + } +} + +class _IndicatorInkWell extends InkResponse { + const _IndicatorInkWell({ + required this.iconKey, + required this.labelBehavior, + super.overlayColor, + super.customBorder, + super.onTap, + super.child, + }) : super( + containedInkWell: true, + highlightColor: Colors.transparent, + ); + + final GlobalKey iconKey; + final NavigationDestinationLabelBehavior labelBehavior; + + @override + RectCallback? getRectCallback(RenderBox referenceBox) { + return () { + final RenderBox iconBox = iconKey.currentContext!.findRenderObject()! as RenderBox; + final Rect iconRect = iconBox.localToGlobal(Offset.zero) & iconBox.size; + return referenceBox.globalToLocal(iconRect.topLeft) & iconBox.size; + }; + } +} + +/// Inherited widget for passing data from the [NavigationBar] to the +/// [NavigationBar.destinations] children widgets. +/// +/// Useful for building navigation destinations using: +/// `_NavigationDestinationInfo.of(context)`. +class _NavigationDestinationInfo extends InheritedWidget { + /// Adds the information needed to build a navigation destination to the + /// [child] and descendants. + const _NavigationDestinationInfo({ + required this.index, + required this.selectedIndex, + required this.totalNumberOfDestinations, + required this.selectedAnimation, + required this.labelBehavior, + required this.indicatorColor, + required this.indicatorShape, + required this.overlayColor, + required this.onTap, + required super.child, + }); + + /// Which destination index is this in the navigation bar. + /// + /// For example: + /// + /// ```dart + /// NavigationBar( + /// destinations: const <Widget>[ + /// NavigationDestination( + /// // This is destination index 0. + /// icon: Icon(Icons.surfing), + /// label: 'Surfing', + /// ), + /// NavigationDestination( + /// // This is destination index 1. + /// icon: Icon(Icons.support), + /// label: 'Support', + /// ), + /// NavigationDestination( + /// // This is destination index 2. + /// icon: Icon(Icons.local_hospital), + /// label: 'Hospital', + /// ), + /// ] + /// ) + /// ``` + /// + /// This is required for semantics, so that each destination can have a label + /// "Tab 1 of 3", for example. + final int index; + + /// This is the index of the currently selected destination. + /// + /// This is required for `_IndicatorInkWell` to apply label padding to ripple animations + /// when label behavior is [NavigationDestinationLabelBehavior.onlyShowSelected]. + final int selectedIndex; + + /// How many total destinations are in this navigation bar. + /// + /// This is required for semantics, so that each destination can have a label + /// "Tab 1 of 4", for example. + final int totalNumberOfDestinations; + + /// Indicates whether or not this destination is selected, from 0 (unselected) + /// to 1 (selected). + final Animation<double> selectedAnimation; + + /// Determines the behavior for how the labels will layout. + /// + /// Can be used to show all labels (the default), show only the selected + /// label, or hide all labels. + final NavigationDestinationLabelBehavior labelBehavior; + + /// The color of the selection indicator. + /// + /// This is used by destinations to override the indicator color. + final Color? indicatorColor; + + /// The shape of the selection indicator. + /// + /// This is used by destinations to override the indicator shape. + final ShapeBorder? indicatorShape; + + /// The highlight color that's typically used to indicate that + /// the [NavigationDestination] is focused, hovered, or pressed. + /// + /// This is used by destinations to override the overlay color. + final MaterialStateProperty<Color?>? overlayColor; + + /// The callback that should be called when this destination is tapped. + /// + /// This is computed by calling [NavigationBar.onDestinationSelected] + /// with [index] passed in. + final VoidCallback onTap; + + /// Returns a non null [_NavigationDestinationInfo]. + /// + /// This will return an error if called with no [_NavigationDestinationInfo] + /// ancestor. + /// + /// Used by widgets that are implementing a navigation destination info to + /// get information like the selected animation and destination number. + static _NavigationDestinationInfo of(BuildContext context) { + final _NavigationDestinationInfo? result = context.dependOnInheritedWidgetOfExactType<_NavigationDestinationInfo>(); + assert( + result != null, + 'Navigation destinations need a _NavigationDestinationInfo parent, ' + 'which is usually provided by NavigationBar.', + ); + return result!; + } + + @override + bool updateShouldNotify(_NavigationDestinationInfo oldWidget) { + return index != oldWidget.index + || totalNumberOfDestinations != oldWidget.totalNumberOfDestinations + || selectedAnimation != oldWidget.selectedAnimation + || labelBehavior != oldWidget.labelBehavior + || onTap != oldWidget.onTap; + } +} + +/// Selection Indicator for the Material 3 [NavigationBar] and [NavigationRail] +/// components. +/// +/// When [animation] is 0, the indicator is not present. As [animation] grows +/// from 0 to 1, the indicator scales in on the x axis. +/// +/// Used in a [Stack] widget behind the icons in the Material 3 Navigation Bar +/// to illuminate the selected destination. +class NavigationIndicator extends StatelessWidget { + /// Builds an indicator, usually used in a stack behind the icon of a + /// navigation bar destination. + const NavigationIndicator({ + super.key, + required this.animation, + this.color, + this.width = _kIndicatorWidth, + this.height = _kIndicatorHeight, + this.borderRadius = const BorderRadius.all(Radius.circular(16)), + this.shape, + }); + + /// Determines the scale of the indicator. + /// + /// When [animation] is 0, the indicator is not present. The indicator scales + /// in as [animation] grows from 0 to 1. + final Animation<double> animation; + + /// The fill color of this indicator. + /// + /// If null, defaults to [ColorScheme.secondary]. + final Color? color; + + /// The width of this indicator. + /// + /// Defaults to `64`. + final double width; + + /// The height of this indicator. + /// + /// Defaults to `32`. + final double height; + + /// The border radius of the shape of the indicator. + /// + /// This is used to create a [RoundedRectangleBorder] shape for the indicator. + /// This is ignored if [shape] is non-null. + /// + /// Defaults to `BorderRadius.circular(16)`. + final BorderRadius borderRadius; + + /// The shape of the indicator. + /// + /// If non-null this is used as the shape used to draw the background + /// of the indicator. If null then a [RoundedRectangleBorder] with the + /// [borderRadius] is used. + final ShapeBorder? shape; + + @override + Widget build(BuildContext context) { + return AnimatedBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + // The scale should be 0 when the animation is unselected, as soon as + // the animation starts, the scale jumps to 40%, and then animates to + // 100% along a curve. + final double scale = animation.isDismissed + ? 0.0 + : Tween<double>(begin: .4, end: 1.0).transform( + CurveTween(curve: Curves.easeInOutCubicEmphasized).transform(animation.value)); + + return Transform( + alignment: Alignment.center, + // Scale in the X direction only. + transform: Matrix4.diagonal3Values( + scale, + 1.0, + 1.0, + ), + child: child, + ); + }, + // Fade should be a 100ms animation whenever the parent animation changes + // direction. + child: _StatusTransitionWidgetBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + return _SelectableAnimatedBuilder( + isSelected: _isForwardOrCompleted(animation), + duration: const Duration(milliseconds: 100), + alwaysDoFullAnimation: true, + builder: (BuildContext context, Animation<double> fadeAnimation) { + return FadeTransition( + opacity: fadeAnimation, + child: Container( + width: width, + height: height, + decoration: ShapeDecoration( + shape: shape ?? RoundedRectangleBorder(borderRadius: borderRadius), + color: color ?? Theme.of(context).colorScheme.secondary, + ), + ), + ); + }, + ); + }, + ), + ); + } +} + +/// Widget that handles the layout of the icon + label in a navigation bar +/// destination, based on [_NavigationDestinationInfo.labelBehavior] and +/// [_NavigationDestinationInfo.selectedAnimation]. +/// +/// Depending on the [_NavigationDestinationInfo.labelBehavior], the labels +/// will shift and fade accordingly. +class _NavigationBarDestinationLayout extends StatelessWidget { + /// Builds a widget to layout an icon + label for a destination in a Material + /// 3 [NavigationBar]. + const _NavigationBarDestinationLayout({ + required this.icon, + required this.iconKey, + required this.label, + }); + + /// The icon widget that sits on top of the label. + /// + /// See [NavigationDestination.icon]. + final Widget icon; + + /// The global key for the icon of this destination. + /// + /// This is used to determine the position of the icon. + final GlobalKey iconKey; + + /// The label widget that sits below the icon. + /// + /// This widget will sometimes be faded out, depending on + /// [_NavigationDestinationInfo.selectedAnimation]. + /// + /// See [NavigationDestination.label]. + final Widget label; + + static final Key _labelKey = UniqueKey(); + + @override + Widget build(BuildContext context) { + return _DestinationLayoutAnimationBuilder( + builder: (BuildContext context, Animation<double> animation) { + return CustomMultiChildLayout( + delegate: _NavigationDestinationLayoutDelegate( + animation: animation, + ), + children: <Widget>[ + LayoutId( + id: _NavigationDestinationLayoutDelegate.iconId, + child: RepaintBoundary( + key: iconKey, + child: icon, + ), + ), + LayoutId( + id: _NavigationDestinationLayoutDelegate.labelId, + child: FadeTransition( + alwaysIncludeSemantics: true, + opacity: animation, + child: RepaintBoundary( + key: _labelKey, + child: label, + ), + ), + ), + ], + ); + }, + ); + } +} + +/// Determines the appropriate [Curve] and [Animation] to use for laying out the +/// [NavigationDestination], based on +/// [_NavigationDestinationInfo.labelBehavior]. +/// +/// The animation controlling the position and fade of the labels differs +/// from the selection animation, depending on the +/// [NavigationDestinationLabelBehavior]. This widget determines what +/// animation should be used for the position and fade of the labels. +class _DestinationLayoutAnimationBuilder extends StatelessWidget { + /// Builds a child with the appropriate animation [Curve] based on the + /// [_NavigationDestinationInfo.labelBehavior]. + const _DestinationLayoutAnimationBuilder({required this.builder}); + + /// Builds the child of this widget. + /// + /// The [Animation] will be the appropriate [Animation] to use for the layout + /// and fade of the [NavigationDestination], either a curve, always + /// showing (1), or always hiding (0). + final Widget Function(BuildContext, Animation<double>) builder; + + @override + Widget build(BuildContext context) { + final _NavigationDestinationInfo info = _NavigationDestinationInfo.of(context); + switch (info.labelBehavior) { + case NavigationDestinationLabelBehavior.alwaysShow: + return builder(context, kAlwaysCompleteAnimation); + case NavigationDestinationLabelBehavior.alwaysHide: + return builder(context, kAlwaysDismissedAnimation); + case NavigationDestinationLabelBehavior.onlyShowSelected: + return _CurvedAnimationBuilder( + animation: info.selectedAnimation, + curve: Curves.easeInOutCubicEmphasized, + reverseCurve: Curves.easeInOutCubicEmphasized.flipped, + builder: (BuildContext context, Animation<double> curvedAnimation) { + return builder(context, curvedAnimation); + }, + ); + } + } +} + +/// Semantics widget for a navigation bar destination. +/// +/// Requires a [_NavigationDestinationInfo] parent (normally provided by the +/// [NavigationBar] by default). +/// +/// Provides localized semantic labels to the destination, for example, it will +/// read "Home, Tab 1 of 3". +/// +/// Used by [_NavigationDestinationBuilder]. +class _NavigationBarDestinationSemantics extends StatelessWidget { + /// Adds the appropriate semantics for navigation bar destinations to the + /// [child]. + const _NavigationBarDestinationSemantics({ + required this.child, + }); + + /// The widget that should receive the destination semantics. + final Widget child; + + @override + Widget build(BuildContext context) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final _NavigationDestinationInfo destinationInfo = _NavigationDestinationInfo.of(context); + // The AnimationStatusBuilder will make sure that the semantics update to + // "selected" when the animation status changes. + return _StatusTransitionWidgetBuilder( + animation: destinationInfo.selectedAnimation, + builder: (BuildContext context, Widget? child) { + return Semantics( + selected: _isForwardOrCompleted(destinationInfo.selectedAnimation), + container: true, + child: child, + ); + }, + child: Stack( + alignment: Alignment.center, + children: <Widget>[ + child, + Semantics( + label: localizations.tabLabel( + tabIndex: destinationInfo.index + 1, + tabCount: destinationInfo.totalNumberOfDestinations, + ), + ), + ], + ), + ); + } +} + +/// Tooltip widget for use in a [NavigationBar]. +/// +/// It appears just above the navigation bar when one of the destinations is +/// long pressed. +class _NavigationBarDestinationTooltip extends StatelessWidget { + /// Adds a tooltip to the [child] widget. + const _NavigationBarDestinationTooltip({ + required this.message, + required this.child, + }); + + /// The text that is rendered in the tooltip when it appears. + final String message; + + /// The widget that, when pressed, will show a tooltip. + final Widget child; + + @override + Widget build(BuildContext context) { + return Tooltip( + message: message, + // TODO(johnsonmh): Make this value configurable/themable. + verticalOffset: 42, + excludeFromSemantics: true, + preferBelow: false, + child: child, + ); + } +} + +/// Custom layout delegate for shifting navigation bar destinations. +/// +/// This will lay out the icon + label according to the [animation]. +/// +/// When the [animation] is 0, the icon will be centered, and the label will be +/// positioned directly below it. +/// +/// When the [animation] is 1, the label will still be positioned directly below +/// the icon, but the icon + label combination will be centered. +/// +/// Used in a [CustomMultiChildLayout] widget in the +/// [_NavigationDestinationBuilder]. +class _NavigationDestinationLayoutDelegate extends MultiChildLayoutDelegate { + _NavigationDestinationLayoutDelegate({required this.animation}) : super(relayout: animation); + + /// The selection animation that indicates whether or not this destination is + /// selected. + /// + /// See [_NavigationDestinationInfo.selectedAnimation]. + final Animation<double> animation; + + /// ID for the icon widget child. + /// + /// This is used by the [LayoutId] when this delegate is used in a + /// [CustomMultiChildLayout]. + /// + /// See [_NavigationDestinationBuilder]. + static const int iconId = 1; + + /// ID for the label widget child. + /// + /// This is used by the [LayoutId] when this delegate is used in a + /// [CustomMultiChildLayout]. + /// + /// See [_NavigationDestinationBuilder]. + static const int labelId = 2; + + @override + void performLayout(Size size) { + double halfWidth(Size size) => size.width / 2; + double halfHeight(Size size) => size.height / 2; + + final Size iconSize = layoutChild(iconId, BoxConstraints.loose(size)); + final Size labelSize = layoutChild(labelId, BoxConstraints.loose(size)); + + final double yPositionOffset = Tween<double>( + // When unselected, the icon is centered vertically. + begin: halfHeight(iconSize), + // When selected, the icon and label are centered vertically. + end: halfHeight(iconSize) + halfHeight(labelSize), + ).transform(animation.value); + final double iconYPosition = halfHeight(size) - yPositionOffset; + + // Position the icon. + positionChild( + iconId, + Offset( + // Center the icon horizontally. + halfWidth(size) - halfWidth(iconSize), + iconYPosition, + ), + ); + + // Position the label. + positionChild( + labelId, + Offset( + // Center the label horizontally. + halfWidth(size) - halfWidth(labelSize), + // Label always appears directly below the icon. + iconYPosition + iconSize.height, + ), + ); + } + + @override + bool shouldRelayout(_NavigationDestinationLayoutDelegate oldDelegate) { + return oldDelegate.animation != animation; + } +} + +/// Widget that listens to an animation, and rebuilds when the animation changes +/// [AnimationStatus]. +/// +/// This can be more efficient than just using an [AnimatedBuilder] when you +/// only need to rebuild when the [Animation.status] changes, since +/// [AnimatedBuilder] rebuilds every time the animation ticks. +class _StatusTransitionWidgetBuilder extends StatusTransitionWidget { + /// Creates a widget that rebuilds when the given animation changes status. + const _StatusTransitionWidgetBuilder({ + required super.animation, + required this.builder, + this.child, + }); + + /// Called every time the [animation] changes [AnimationStatus]. + final TransitionBuilder builder; + + /// The child widget to pass to the [builder]. + /// + /// If a [builder] callback's return value contains a subtree that does not + /// depend on the animation, it's more efficient to build that subtree once + /// instead of rebuilding it on every animation status change. + /// + /// Using this pre-built child is entirely optional, but can improve + /// performance in some cases and is therefore a good practice. + /// + /// See: [AnimatedBuilder.child] + final Widget? child; + + @override + Widget build(BuildContext context) => builder(context, child); +} + +// Builder widget for widgets that need to be animated from 0 (unselected) to +// 1.0 (selected). +// +// This widget creates and manages an [AnimationController] that it passes down +// to the child through the [builder] function. +// +// When [isSelected] is `true`, the animation controller will animate from +// 0 to 1 (for [duration] time). +// +// When [isSelected] is `false`, the animation controller will animate from +// 1 to 0 (for [duration] time). +// +// If [isSelected] is updated while the widget is animating, the animation will +// be reversed until it is either 0 or 1 again. If [alwaysDoFullAnimation] is +// true, the animation will reset to 0 or 1 before beginning the animation, so +// that the full animation is done. +// +// Usage: +// ```dart +// _SelectableAnimatedBuilder( +// isSelected: _isDrawerOpen, +// builder: (context, animation) { +// return AnimatedIcon( +// icon: AnimatedIcons.menu_arrow, +// progress: animation, +// semanticLabel: 'Show menu', +// ); +// } +// ) +// ``` +class _SelectableAnimatedBuilder extends StatefulWidget { + /// Builds and maintains an [AnimationController] that will animate from 0 to + /// 1 and back depending on when [isSelected] is true. + const _SelectableAnimatedBuilder({ + required this.isSelected, + this.duration = const Duration(milliseconds: 200), + this.alwaysDoFullAnimation = false, + required this.builder, + }); + + /// When true, the widget will animate an animation controller from 0 to 1. + /// + /// The animation controller is passed to the child widget through [builder]. + final bool isSelected; + + /// How long the animation controller should animate for when [isSelected] is + /// updated. + /// + /// If the animation is currently running and [isSelected] is updated, only + /// the [duration] left to finish the animation will be run. + final Duration duration; + + /// If true, the animation will always go all the way from 0 to 1 when + /// [isSelected] is true, and from 1 to 0 when [isSelected] is false, even + /// when the status changes mid animation. + /// + /// If this is false and the status changes mid animation, the animation will + /// reverse direction from it's current point. + /// + /// Defaults to false. + final bool alwaysDoFullAnimation; + + /// Builds the child widget based on the current animation status. + /// + /// When [isSelected] is updated to true, this builder will be called and the + /// animation will animate up to 1. When [isSelected] is updated to + /// `false`, this will be called and the animation will animate down to 0. + final Widget Function(BuildContext, Animation<double>) builder; + + @override + _SelectableAnimatedBuilderState createState() => + _SelectableAnimatedBuilderState(); +} + +/// State that manages the [AnimationController] that is passed to +/// [_SelectableAnimatedBuilder.builder]. +class _SelectableAnimatedBuilderState extends State<_SelectableAnimatedBuilder> + with SingleTickerProviderStateMixin { + late AnimationController _controller; + + @override + void initState() { + super.initState(); + _controller = AnimationController(vsync: this); + _controller.duration = widget.duration; + _controller.value = widget.isSelected ? 1.0 : 0.0; + } + + @override + void didUpdateWidget(_SelectableAnimatedBuilder oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.duration != widget.duration) { + _controller.duration = widget.duration; + } + if (oldWidget.isSelected != widget.isSelected) { + if (widget.isSelected) { + _controller.forward(from: widget.alwaysDoFullAnimation ? 0 : null); + } else { + _controller.reverse(from: widget.alwaysDoFullAnimation ? 1 : null); + } + } + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return widget.builder( + context, + _controller, + ); + } +} + +/// Watches [animation] and calls [builder] with the appropriate [Curve] +/// depending on the direction of the [animation] status. +/// +/// If [animation.status] is forward or complete, [curve] is used. If +/// [animation.status] is reverse or dismissed, [reverseCurve] is used. +/// +/// If the [animation] changes direction while it is already running, the curve +/// used will not change, this will keep the animations smooth until it +/// completes. +/// +/// This is similar to [CurvedAnimation] except the animation status listeners +/// are removed when this widget is disposed. +class _CurvedAnimationBuilder extends StatefulWidget { + const _CurvedAnimationBuilder({ + required this.animation, + required this.curve, + required this.reverseCurve, + required this.builder, + }); + + final Animation<double> animation; + final Curve curve; + final Curve reverseCurve; + final Widget Function(BuildContext, Animation<double>) builder; + + @override + _CurvedAnimationBuilderState createState() => _CurvedAnimationBuilderState(); +} + +class _CurvedAnimationBuilderState extends State<_CurvedAnimationBuilder> { + late AnimationStatus _animationDirection; + AnimationStatus? _preservedDirection; + + @override + void initState() { + super.initState(); + _animationDirection = widget.animation.status; + _updateStatus(widget.animation.status); + widget.animation.addStatusListener(_updateStatus); + } + + @override + void dispose() { + widget.animation.removeStatusListener(_updateStatus); + super.dispose(); + } + + // Keeps track of the current animation status, as well as the "preserved + // direction" when the animation changes direction mid animation. + // + // The preserved direction is reset when the animation finishes in either + // direction. + void _updateStatus(AnimationStatus status) { + if (_animationDirection != status) { + setState(() { + _animationDirection = status; + }); + } + + if (status == AnimationStatus.completed || status == AnimationStatus.dismissed) { + setState(() { + _preservedDirection = null; + }); + } + + if (_preservedDirection == null && (status == AnimationStatus.forward || status == AnimationStatus.reverse)) { + setState(() { + _preservedDirection = status; + }); + } + } + + @override + Widget build(BuildContext context) { + final bool shouldUseForwardCurve = (_preservedDirection ?? _animationDirection) != AnimationStatus.reverse; + + final Animation<double> curvedAnimation = CurveTween( + curve: shouldUseForwardCurve ? widget.curve : widget.reverseCurve, + ).animate(widget.animation); + + return widget.builder(context, curvedAnimation); + } +} + +/// Returns `true` if this animation is ticking forward, or has completed, +/// based on [status]. +bool _isForwardOrCompleted(Animation<double> animation) { + return animation.status == AnimationStatus.forward + || animation.status == AnimationStatus.completed; +} + +NavigationBarThemeData _defaultsFor(BuildContext context) { + return Theme.of(context).useMaterial3 ? _NavigationBarDefaultsM3(context) : _NavigationBarDefaultsM2(context); +} + +// Hand coded defaults based on Material Design 2. +class _NavigationBarDefaultsM2 extends NavigationBarThemeData { + _NavigationBarDefaultsM2(BuildContext context) + : _theme = Theme.of(context), + _colors = Theme.of(context).colorScheme, + super( + height: 80.0, + elevation: 0.0, + indicatorShape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))), + labelBehavior: NavigationDestinationLabelBehavior.alwaysShow, + ); + + final ThemeData _theme; + final ColorScheme _colors; + + // With Material 2, the NavigationBar uses an overlay blend for the + // default color regardless of light/dark mode. + @override Color? get backgroundColor => ElevationOverlay.colorWithOverlay(_colors.surface, _colors.onSurface, 3.0); + + @override MaterialStateProperty<IconThemeData?>? get iconTheme { + return MaterialStatePropertyAll<IconThemeData>(IconThemeData( + size: 24, + color: _colors.onSurface, + )); + } + + @override Color? get indicatorColor => _colors.secondary.withOpacity(0.24); + + @override MaterialStateProperty<TextStyle?>? get labelTextStyle => MaterialStatePropertyAll<TextStyle?>(_theme.textTheme.labelSmall!.copyWith(color: _colors.onSurface)); +} + +// BEGIN GENERATED TOKEN PROPERTIES - NavigationBar + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _NavigationBarDefaultsM3 extends NavigationBarThemeData { + _NavigationBarDefaultsM3(this.context) + : super( + height: 80.0, + elevation: 3.0, + labelBehavior: NavigationDestinationLabelBehavior.alwaysShow, + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override Color? get backgroundColor => _colors.surface; + + @override Color? get shadowColor => Colors.transparent; + + @override Color? get surfaceTintColor => _colors.surfaceTint; + + @override MaterialStateProperty<IconThemeData?>? get iconTheme { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + return IconThemeData( + size: 24.0, + color: states.contains(MaterialState.disabled) + ? _colors.onSurfaceVariant.withOpacity(0.38) + : states.contains(MaterialState.selected) + ? _colors.onSecondaryContainer + : _colors.onSurfaceVariant, + ); + }); + } + + @override Color? get indicatorColor => _colors.secondaryContainer; + @override ShapeBorder? get indicatorShape => const StadiumBorder(); + + @override MaterialStateProperty<TextStyle?>? get labelTextStyle { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + final TextStyle style = _textTheme.labelMedium!; + return style.apply( + color: states.contains(MaterialState.disabled) + ? _colors.onSurfaceVariant.withOpacity(0.38) + : states.contains(MaterialState.selected) + ? _colors.onSurface + : _colors.onSurfaceVariant + ); + }); + } +} + +// END GENERATED TOKEN PROPERTIES - NavigationBar diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_bar_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_bar_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..adb9e3985cec1efc49d56d273563876b9f9552e2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_bar_theme.dart @@ -0,0 +1,251 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; +import 'navigation_bar.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [NavigationBar] +/// widgets. +/// +/// Descendant widgets obtain the current [NavigationBarThemeData] object +/// using `NavigationBarTheme.of(context)`. Instances of +/// [NavigationBarThemeData] can be customized with +/// [NavigationBarThemeData.copyWith]. +/// +/// Typically a [NavigationBarThemeData] is specified as part of the +/// overall [Theme] with [ThemeData.navigationBarTheme]. Alternatively, a +/// [NavigationBarTheme] inherited widget can be used to theme [NavigationBar]s +/// in a subtree of widgets. +/// +/// All [NavigationBarThemeData] properties are `null` by default. +/// When null, the [NavigationBar] will provide its own defaults based on the +/// overall [Theme]'s textTheme and colorScheme. See the individual +/// [NavigationBar] properties for details. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class NavigationBarThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.navigationBarTheme] and + /// [NavigationBarTheme]. + const NavigationBarThemeData({ + this.height, + this.backgroundColor, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.indicatorColor, + this.indicatorShape, + this.labelTextStyle, + this.iconTheme, + this.labelBehavior, + this.overlayColor, + }); + + /// Overrides the default value of [NavigationBar.height]. + final double? height; + + /// Overrides the default value of [NavigationBar.backgroundColor]. + final Color? backgroundColor; + + /// Overrides the default value of [NavigationBar.elevation]. + final double? elevation; + + /// Overrides the default value of [NavigationBar.shadowColor]. + final Color? shadowColor; + + /// Overrides the default value of [NavigationBar.surfaceTintColor]. + final Color? surfaceTintColor; + + /// Overrides the default value of [NavigationBar]'s selection indicator. + final Color? indicatorColor; + + /// Overrides the default shape of the [NavigationBar]'s selection indicator. + final ShapeBorder? indicatorShape; + + /// The style to merge with the default text style for + /// [NavigationDestination] labels. + /// + /// You can use this to specify a different style when the label is selected. + final MaterialStateProperty<TextStyle?>? labelTextStyle; + + /// The theme to merge with the default icon theme for + /// [NavigationDestination] icons. + /// + /// You can use this to specify a different icon theme when the icon is + /// selected. + final MaterialStateProperty<IconThemeData?>? iconTheme; + + /// Overrides the default value of [NavigationBar.labelBehavior]. + final NavigationDestinationLabelBehavior? labelBehavior; + + /// Overrides the default value of [NavigationBar.overlayColor]. + final MaterialStateProperty<Color?>? overlayColor; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + NavigationBarThemeData copyWith({ + double? height, + Color? backgroundColor, + double? elevation, + Color? shadowColor, + Color? surfaceTintColor, + Color? indicatorColor, + ShapeBorder? indicatorShape, + MaterialStateProperty<TextStyle?>? labelTextStyle, + MaterialStateProperty<IconThemeData?>? iconTheme, + NavigationDestinationLabelBehavior? labelBehavior, + MaterialStateProperty<Color?>? overlayColor, + }) { + return NavigationBarThemeData( + height: height ?? this.height, + backgroundColor: backgroundColor ?? this.backgroundColor, + elevation: elevation ?? this.elevation, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + indicatorColor: indicatorColor ?? this.indicatorColor, + indicatorShape: indicatorShape ?? this.indicatorShape, + labelTextStyle: labelTextStyle ?? this.labelTextStyle, + iconTheme: iconTheme ?? this.iconTheme, + labelBehavior: labelBehavior ?? this.labelBehavior, + overlayColor: overlayColor ?? this.overlayColor, + ); + } + + /// Linearly interpolate between two navigation rail themes. + /// + /// If both arguments are null then null is returned. + /// + /// {@macro dart.ui.shadow.lerp} + static NavigationBarThemeData? lerp(NavigationBarThemeData? a, NavigationBarThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return NavigationBarThemeData( + height: lerpDouble(a?.height, b?.height, t), + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + indicatorColor: Color.lerp(a?.indicatorColor, b?.indicatorColor, t), + indicatorShape: ShapeBorder.lerp(a?.indicatorShape, b?.indicatorShape, t), + labelTextStyle: MaterialStateProperty.lerp<TextStyle?>(a?.labelTextStyle, b?.labelTextStyle, t, TextStyle.lerp), + iconTheme: MaterialStateProperty.lerp<IconThemeData?>(a?.iconTheme, b?.iconTheme, t, IconThemeData.lerp), + labelBehavior: t < 0.5 ? a?.labelBehavior : b?.labelBehavior, + overlayColor: MaterialStateProperty.lerp<Color?>(a?.overlayColor, b?.overlayColor, t, Color.lerp), + ); + } + + @override + int get hashCode => Object.hash( + height, + backgroundColor, + elevation, + shadowColor, + surfaceTintColor, + indicatorColor, + indicatorShape, + labelTextStyle, + iconTheme, + labelBehavior, + overlayColor, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is NavigationBarThemeData + && other.height == height + && other.backgroundColor == backgroundColor + && other.elevation == elevation + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.indicatorColor == indicatorColor + && other.indicatorShape == indicatorShape + && other.labelTextStyle == labelTextStyle + && other.iconTheme == iconTheme + && other.labelBehavior == labelBehavior + && other.overlayColor == overlayColor; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('height', height, defaultValue: null)); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(ColorProperty('indicatorColor', indicatorColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('indicatorShape', indicatorShape, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<TextStyle?>>('labelTextStyle', labelTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<IconThemeData?>>('iconTheme', iconTheme, defaultValue: null)); + properties.add(DiagnosticsProperty<NavigationDestinationLabelBehavior>('labelBehavior', labelBehavior, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('overlayColor', overlayColor, defaultValue: null)); + } +} + +/// An inherited widget that defines visual properties for [NavigationBar]s and +/// [NavigationDestination]s in this widget's subtree. +/// +/// Values specified here are used for [NavigationBar] properties that are not +/// given an explicit non-null value. +/// +/// See also: +/// +/// * [ThemeData.navigationBarTheme], which describes the +/// [NavigationBarThemeData] in the overall theme for the application. +class NavigationBarTheme extends InheritedTheme { + /// Creates a navigation rail theme that controls the + /// [NavigationBarThemeData] properties for a [NavigationBar]. + const NavigationBarTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the background color, label text style, icon theme, and label + /// type values for descendant [NavigationBar] widgets. + final NavigationBarThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [NavigationBarTheme] widget, then + /// [ThemeData.navigationBarTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// NavigationBarThemeData theme = NavigationBarTheme.of(context); + /// ``` + static NavigationBarThemeData of(BuildContext context) { + final NavigationBarTheme? navigationBarTheme = context.dependOnInheritedWidgetOfExactType<NavigationBarTheme>(); + return navigationBarTheme?.data ?? Theme.of(context).navigationBarTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return NavigationBarTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(NavigationBarTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_drawer.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_drawer.dart new file mode 100644 index 0000000000000000000000000000000000000000..8ce07e90d50bb1faa4165545f9ae643cc7a540e0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_drawer.dart @@ -0,0 +1,754 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'drawer.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'navigation_bar.dart'; +import 'navigation_drawer_theme.dart'; +import 'text_theme.dart'; +import 'theme.dart'; + +/// Material Design Navigation Drawer component. +/// +/// On top of [Drawer]s, Navigation drawers offer a persistent and convenient way to switch +/// between primary destinations in an app. +/// +/// The style for the icons and text are not affected by parent +/// [DefaultTextStyle]s or [IconTheme]s but rather controlled by parameters or +/// the [NavigationDrawerThemeData]. +/// +/// The [children] are a list of widgets to be displayed in the drawer. These can be a +/// mixture of any widgets, but there is special handling for [NavigationDrawerDestination]s. +/// They are treated as a group and when one is selected, the [onDestinationSelected] +/// is called with the index into the group that corresponds to the selected destination. +/// +/// {@tool dartpad} +/// This example shows a [NavigationDrawer] used within a [Scaffold] +/// widget. The [NavigationDrawer] has headline widget, divider widget and three +/// [NavigationDrawerDestination] widgets. The initial [selectedIndex] is 0. +/// The [onDestinationSelected] callback changes the selected item's index and displays +/// a corresponding widget in the body of the [Scaffold]. +/// +/// ** See code in examples/api/lib/material/navigation_drawer/navigation_drawer.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Scaffold.drawer], where one specifies a [Drawer] so that it can be +/// shown. +/// * [Scaffold.of], to obtain the current [ScaffoldState], which manages the +/// display and animation of the drawer. +/// * [ScaffoldState.openDrawer], which displays its [Drawer], if any. +/// * <https://material.io/design/components/navigation-drawer.html> +class NavigationDrawer extends StatelessWidget { + /// Creates a Material Design Navigation Drawer component. + const NavigationDrawer({ + super.key, + required this.children, + this.backgroundColor, + this.shadowColor, + this.surfaceTintColor, + this.elevation, + this.indicatorColor, + this.indicatorShape, + this.onDestinationSelected, + this.selectedIndex = 0, + this.tilePadding = const EdgeInsets.symmetric(horizontal: 12.0), + }); + + /// The background color of the [Material] that holds the [NavigationDrawer]'s + /// contents. + /// + /// If this is null, then [NavigationDrawerThemeData.backgroundColor] is used. + /// If that is also null, then it falls back to [ColorScheme.surface]. + final Color? backgroundColor; + + /// The color used for the drop shadow to indicate elevation. + /// + /// If null, [NavigationDrawerThemeData.shadowColor] is used. If that + /// is also null, the default value is [Colors.transparent] which + /// indicates that no drop shadow will be displayed. + /// + /// See [Material.shadowColor] for more details on drop shadows. + final Color? shadowColor; + + /// The surface tint of the [Material] that holds the [NavigationDrawer]'s + /// contents. + /// + /// If this is null, then [NavigationDrawerThemeData.surfaceTintColor] is used. + /// If that is also null, then it falls back to [Material.surfaceTintColor]'s default. + final Color? surfaceTintColor; + + /// The elevation of the [NavigationDrawer] itself. + /// + /// If null, [NavigationDrawerThemeData.elevation] is used. If that + /// is also null, it will be 1.0. + final double? elevation; + + /// The color of the [indicatorShape] when this destination is selected. + /// + /// If this is null, [NavigationDrawerThemeData.indicatorColor] is used. + /// If that is also null, defaults to [ColorScheme.secondaryContainer]. + final Color? indicatorColor; + + /// The shape of the selected indicator. + /// + /// If this is null, [NavigationDrawerThemeData.indicatorShape] is used. + /// If that is also null, defaults to [StadiumBorder]. + final ShapeBorder? indicatorShape; + + /// Defines the appearance of the items within the navigation drawer. + /// + /// The list contains [NavigationDrawerDestination] widgets and/or customized + /// widgets like headlines and dividers. + final List<Widget> children; + + /// The index into destinations for the current selected + /// [NavigationDrawerDestination] or null if no destination is selected. + /// + /// A valid [selectedIndex] satisfies 0 <= [selectedIndex] < number of [NavigationDrawerDestination]. + /// For an invalid [selectedIndex] like `-1`, all destinations will appear unselected. + final int? selectedIndex; + + /// Called when one of the [NavigationDrawerDestination] children is selected. + /// + /// This callback usually updates the int passed to [selectedIndex]. + /// + /// Upon updating [selectedIndex], the [NavigationDrawer] will be rebuilt. + final ValueChanged<int>? onDestinationSelected; + + /// Defines the padding for [NavigationDrawerDestination] widgets (Drawer items). + /// + /// Defaults to `EdgeInsets.symmetric(horizontal: 12.0)`. + final EdgeInsetsGeometry tilePadding; + + @override + Widget build(BuildContext context) { + final int totalNumberOfDestinations = + children.whereType<NavigationDrawerDestination>().toList().length; + + int destinationIndex = 0; + final List<Widget> wrappedChildren = <Widget>[]; + Widget wrapChild(Widget child, int index) => _SelectableAnimatedBuilder( + duration: const Duration(milliseconds: 500), + isSelected: index == selectedIndex, + builder: (BuildContext context, Animation<double> animation) { + return _NavigationDrawerDestinationInfo( + index: index, + totalNumberOfDestinations: totalNumberOfDestinations, + selectedAnimation: animation, + indicatorColor: indicatorColor, + indicatorShape: indicatorShape, + tilePadding: tilePadding, + onTap: () { + if (onDestinationSelected != null) { + onDestinationSelected!(index); + } + }, + child: child, + ); + }); + + for (int i = 0; i < children.length; i++) { + if (children[i] is! NavigationDrawerDestination) { + wrappedChildren.add(children[i]); + } else { + wrappedChildren.add(wrapChild(children[i], destinationIndex)); + destinationIndex += 1; + } + } + final NavigationDrawerThemeData navigationDrawerTheme = NavigationDrawerTheme.of(context); + + return Drawer( + backgroundColor: backgroundColor ?? navigationDrawerTheme.backgroundColor, + shadowColor: shadowColor ?? navigationDrawerTheme.shadowColor, + surfaceTintColor: surfaceTintColor ?? navigationDrawerTheme.surfaceTintColor, + elevation: elevation ?? navigationDrawerTheme.elevation, + child: SafeArea( + bottom: false, + child: ListView( + children: wrappedChildren, + ), + ), + ); + } +} + +/// A Material Design [NavigationDrawer] destination. +/// +/// Displays an icon with a label, for use in [NavigationDrawer.children]. +class NavigationDrawerDestination extends StatelessWidget { + /// Creates a navigation drawer destination. + const NavigationDrawerDestination({ + super.key, + this.backgroundColor, + required this.icon, + this.selectedIcon, + required this.label, + this.enabled = true, + }); + + /// Sets the color of the destination. + /// + /// If this is null, then [NavigationDrawerThemeData.backgroundColor]. + final Color? backgroundColor; + + /// The [Widget] (usually an [Icon]) that's displayed for this + /// [NavigationDestination]. + /// + /// The icon will use [NavigationDrawerThemeData.iconTheme]. If this is + /// null, the default [IconThemeData] would use a size of 24.0 and + /// [ColorScheme.onSurfaceVariant]. + final Widget icon; + + /// The optional [Widget] (usually an [Icon]) that's displayed when this + /// [NavigationDestination] is selected. + /// + /// If [selectedIcon] is non-null, the destination will fade from + /// [icon] to [selectedIcon] when this destination goes from unselected to + /// selected. + /// + /// The icon will use [NavigationDrawerThemeData.iconTheme] with + /// [MaterialState.selected]. If this is null, the default [IconThemeData] + /// would use a size of 24.0 and [ColorScheme.onSecondaryContainer]. + final Widget? selectedIcon; + + /// The text label that appears on the right of the icon + /// + /// The accompanying [Text] widget will use + /// [NavigationDrawerThemeData.labelTextStyle]. If this are null, the default + /// text style would use [TextTheme.labelLarge] with [ColorScheme.onSurfaceVariant]. + final Widget label; + + /// Indicates that this destination is selectable. + /// + /// Defaults to true. + final bool enabled; + + @override + Widget build(BuildContext context) { + const Set<MaterialState> selectedState = <MaterialState>{ + MaterialState.selected + }; + const Set<MaterialState> unselectedState = <MaterialState>{}; + const Set<MaterialState> disabledState = <MaterialState>{ + MaterialState.disabled + }; + + final NavigationDrawerThemeData navigationDrawerTheme = + NavigationDrawerTheme.of(context); + final NavigationDrawerThemeData defaults = + _NavigationDrawerDefaultsM3(context); + + final Animation<double> animation = + _NavigationDrawerDestinationInfo.of(context).selectedAnimation; + + return _NavigationDestinationBuilder( + buildIcon: (BuildContext context) { + final Widget selectedIconWidget = IconTheme.merge( + data: navigationDrawerTheme.iconTheme?.resolve(enabled ? selectedState : disabledState) ?? + defaults.iconTheme!.resolve(enabled ? selectedState : disabledState)!, + child: selectedIcon ?? icon, + ); + final Widget unselectedIconWidget = IconTheme.merge( + data: navigationDrawerTheme.iconTheme?.resolve(enabled ? unselectedState : disabledState) ?? + defaults.iconTheme!.resolve(enabled ? unselectedState : disabledState)!, + child: icon, + ); + + return _isForwardOrCompleted(animation) + ? selectedIconWidget + : unselectedIconWidget; + }, + buildLabel: (BuildContext context) { + final TextStyle? effectiveSelectedLabelTextStyle = + navigationDrawerTheme.labelTextStyle?.resolve(enabled ? selectedState : disabledState) ?? + defaults.labelTextStyle!.resolve(enabled ? selectedState : disabledState); + final TextStyle? effectiveUnselectedLabelTextStyle = + navigationDrawerTheme.labelTextStyle?.resolve(enabled ? unselectedState : disabledState) ?? + defaults.labelTextStyle!.resolve(enabled ? unselectedState : disabledState); + + return DefaultTextStyle( + style: _isForwardOrCompleted(animation) + ? effectiveSelectedLabelTextStyle! + : effectiveUnselectedLabelTextStyle!, + child: label, + ); + }, + enabled: enabled, + backgroundColor: backgroundColor, + ); + } +} + +/// Widget that handles the semantics and layout of a navigation drawer +/// destination. +/// +/// Prefer [NavigationDestination] over this widget, as it is a simpler +/// (although less customizable) way to get navigation drawer destinations. +/// +/// The icon and label of this destination are built with [buildIcon] and +/// [buildLabel]. They should build the unselected and selected icon and label +/// according to [_NavigationDrawerDestinationInfo.selectedAnimation], where an +/// animation value of 0 is unselected and 1 is selected. +/// +/// See [NavigationDestination] for an example. +class _NavigationDestinationBuilder extends StatelessWidget { + /// Builds a destination (icon + label) to use in a Material 3 [NavigationDrawer]. + const _NavigationDestinationBuilder({ + required this.buildIcon, + required this.buildLabel, + this.enabled = true, + this.backgroundColor, + }); + + /// Builds the icon for a destination in a [NavigationDrawer]. + /// + /// To animate between unselected and selected, build the icon based on + /// [_NavigationDrawerDestinationInfo.selectedAnimation]. When the animation is 0, + /// the destination is unselected, when the animation is 1, the destination is + /// selected. + /// + /// The destination is considered selected as soon as the animation is + /// increasing or completed, and it is considered unselected as soon as the + /// animation is decreasing or dismissed. + final WidgetBuilder buildIcon; + + /// Builds the label for a destination in a [NavigationDrawer]. + /// + /// To animate between unselected and selected, build the icon based on + /// [_NavigationDrawerDestinationInfo.selectedAnimation]. When the animation is + /// 0, the destination is unselected, when the animation is 1, the destination + /// is selected. + /// + /// The destination is considered selected as soon as the animation is + /// increasing or completed, and it is considered unselected as soon as the + /// animation is decreasing or dismissed. + final WidgetBuilder buildLabel; + + /// Indicates that this destination is selectable. + /// + /// Defaults to true. + final bool enabled; + + /// Sets the color of navigation destination. + /// + /// If this is null, then [NavigationDrawerTheme.backgroundColor] is used. + final Color? backgroundColor; + + @override + Widget build(BuildContext context) { + final _NavigationDrawerDestinationInfo info = _NavigationDrawerDestinationInfo.of(context); + final NavigationDrawerThemeData navigationDrawerTheme = NavigationDrawerTheme.of(context); + final NavigationDrawerThemeData defaults = _NavigationDrawerDefaultsM3(context); + + final Row destinationBody = Row( + children: <Widget>[ + const SizedBox(width: 16), + buildIcon(context), + const SizedBox(width: 12), + buildLabel(context), + ], + ); + + return Container( + padding: info.tilePadding, + color: backgroundColor ?? navigationDrawerTheme.backgroundColor, + child: _NavigationDestinationSemantics( + child: SizedBox( + height: navigationDrawerTheme.tileHeight ?? defaults.tileHeight, + child: InkWell( + highlightColor: Colors.transparent, + onTap: enabled ? info.onTap : null, + customBorder: info.indicatorShape ?? navigationDrawerTheme.indicatorShape ?? defaults.indicatorShape!, + child: Stack( + alignment: Alignment.center, + children: <Widget>[ + NavigationIndicator( + animation: info.selectedAnimation, + color: info.indicatorColor ?? navigationDrawerTheme.indicatorColor ?? defaults.indicatorColor!, + shape: info.indicatorShape ?? navigationDrawerTheme.indicatorShape ?? defaults.indicatorShape!, + width: (navigationDrawerTheme.indicatorSize ?? defaults.indicatorSize!).width, + height: (navigationDrawerTheme.indicatorSize ?? defaults.indicatorSize!).height, + ), + destinationBody + ], + ), + ), + ), + ), + ); + } +} + +/// Semantics widget for a navigation drawer destination. +/// +/// Requires a [_NavigationDrawerDestinationInfo] parent (normally provided by the +/// [NavigationDrawer] by default). +/// +/// Provides localized semantic labels to the destination, for example, it will +/// read "Home, Tab 1 of 3". +/// +/// Used by [_NavigationDestinationBuilder]. +class _NavigationDestinationSemantics extends StatelessWidget { + /// Adds the appropriate semantics for navigation drawer destinations to the + /// [child]. + const _NavigationDestinationSemantics({ + required this.child, + }); + + /// The widget that should receive the destination semantics. + final Widget child; + + @override + Widget build(BuildContext context) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final _NavigationDrawerDestinationInfo destinationInfo = _NavigationDrawerDestinationInfo.of(context); + // The AnimationStatusBuilder will make sure that the semantics update to + // "selected" when the animation status changes. + return _StatusTransitionWidgetBuilder( + animation: destinationInfo.selectedAnimation, + builder: (BuildContext context, Widget? child) { + return Semantics( + selected: _isForwardOrCompleted(destinationInfo.selectedAnimation), + container: true, + child: child, + ); + }, + child: Stack( + alignment: Alignment.center, + children: <Widget>[ + child, + Semantics( + label: localizations.tabLabel( + tabIndex: destinationInfo.index + 1, + tabCount: destinationInfo.totalNumberOfDestinations, + ), + ), + ], + ), + ); + } +} + +/// Widget that listens to an animation, and rebuilds when the animation changes +/// [AnimationStatus]. +/// +/// This can be more efficient than just using an [AnimatedBuilder] when you +/// only need to rebuild when the [Animation.status] changes, since +/// [AnimatedBuilder] rebuilds every time the animation ticks. +class _StatusTransitionWidgetBuilder extends StatusTransitionWidget { + /// Creates a widget that rebuilds when the given animation changes status. + const _StatusTransitionWidgetBuilder({ + required super.animation, + required this.builder, + this.child, + }); + + /// Called every time the [animation] changes [AnimationStatus]. + final TransitionBuilder builder; + + /// The child widget to pass to the [builder]. + /// + /// If a [builder] callback's return value contains a subtree that does not + /// depend on the animation, it's more efficient to build that subtree once + /// instead of rebuilding it on every animation status change. + /// + /// Using this pre-built child is entirely optional, but can improve + /// performance in some cases and is therefore a good practice. + /// + /// See: [AnimatedBuilder.child] + final Widget? child; + + @override + Widget build(BuildContext context) => builder(context, child); +} + +/// Inherited widget for passing data from the [NavigationDrawer] to the +/// [NavigationDrawer.destinations] children widgets. +/// +/// Useful for building navigation destinations using: +/// `_NavigationDrawerDestinationInfo.of(context)`. +class _NavigationDrawerDestinationInfo extends InheritedWidget { + /// Adds the information needed to build a navigation destination to the + /// [child] and descendants. + const _NavigationDrawerDestinationInfo({ + required this.index, + required this.totalNumberOfDestinations, + required this.selectedAnimation, + required this.indicatorColor, + required this.indicatorShape, + required this.onTap, + required super.child, + required this.tilePadding, + }); + + /// Which destination index is this in the navigation drawer. + /// + /// For example: + /// + /// ```dart + /// const NavigationDrawer( + /// children: <Widget>[ + /// Text('Headline'), // This doesn't have index. + /// NavigationDrawerDestination( + /// // This is destination index 0. + /// icon: Icon(Icons.surfing), + /// label: Text('Surfing'), + /// ), + /// NavigationDrawerDestination( + /// // This is destination index 1. + /// icon: Icon(Icons.support), + /// label: Text('Support'), + /// ), + /// NavigationDrawerDestination( + /// // This is destination index 2. + /// icon: Icon(Icons.local_hospital), + /// label: Text('Hospital'), + /// ), + /// ] + /// ) + /// ``` + /// + /// This is required for semantics, so that each destination can have a label + /// "Tab 1 of 3", for example. + final int index; + + /// How many total destinations are in this navigation drawer. + /// + /// This is required for semantics, so that each destination can have a label + /// "Tab 1 of 4", for example. + final int totalNumberOfDestinations; + + /// Indicates whether or not this destination is selected, from 0 (unselected) + /// to 1 (selected). + final Animation<double> selectedAnimation; + + /// The color of the indicator. + /// + /// This is used by destinations to override the indicator color. + final Color? indicatorColor; + + /// The shape of the indicator. + /// + /// This is used by destinations to override the indicator shape. + final ShapeBorder? indicatorShape; + + /// The callback that should be called when this destination is tapped. + /// + /// This is computed by calling [NavigationDrawer.onDestinationSelected] + /// with [index] passed in. + final VoidCallback onTap; + + /// Defines the padding for [NavigationDrawerDestination] widgets (Drawer items). + /// + /// Defaults to `EdgeInsets.symmetric(horizontal: 12.0)`. + final EdgeInsetsGeometry tilePadding; + + /// Returns a non null [_NavigationDrawerDestinationInfo]. + /// + /// This will return an error if called with no [_NavigationDrawerDestinationInfo] + /// ancestor. + /// + /// Used by widgets that are implementing a navigation destination info to + /// get information like the selected animation and destination number. + static _NavigationDrawerDestinationInfo of(BuildContext context) { + final _NavigationDrawerDestinationInfo? result = context.dependOnInheritedWidgetOfExactType<_NavigationDrawerDestinationInfo>(); + assert( + result != null, + 'Navigation destinations need a _NavigationDrawerDestinationInfo parent, ' + 'which is usually provided by NavigationDrawer.', + ); + return result!; + } + + @override + bool updateShouldNotify(_NavigationDrawerDestinationInfo oldWidget) { + return index != oldWidget.index + || totalNumberOfDestinations != oldWidget.totalNumberOfDestinations + || selectedAnimation != oldWidget.selectedAnimation + || onTap != oldWidget.onTap; + } +} + +// Builder widget for widgets that need to be animated from 0 (unselected) to +// 1.0 (selected). +// +// This widget creates and manages an [AnimationController] that it passes down +// to the child through the [builder] function. +// +// When [isSelected] is `true`, the animation controller will animate from +// 0 to 1 (for [duration] time). +// +// When [isSelected] is `false`, the animation controller will animate from +// 1 to 0 (for [duration] time). +// +// If [isSelected] is updated while the widget is animating, the animation will +// be reversed until it is either 0 or 1 again. +// +// Usage: +// ```dart +// _SelectableAnimatedBuilder( +// isSelected: _isDrawerOpen, +// builder: (context, animation) { +// return AnimatedIcon( +// icon: AnimatedIcons.menu_arrow, +// progress: animation, +// semanticLabel: 'Show menu', +// ); +// } +// ) +// ``` +class _SelectableAnimatedBuilder extends StatefulWidget { + /// Builds and maintains an [AnimationController] that will animate from 0 to + /// 1 and back depending on when [isSelected] is true. + const _SelectableAnimatedBuilder({ + required this.isSelected, + this.duration = const Duration(milliseconds: 200), + required this.builder, + }); + + /// When true, the widget will animate an animation controller from 0 to 1. + /// + /// The animation controller is passed to the child widget through [builder]. + final bool isSelected; + + /// How long the animation controller should animate for when [isSelected] is + /// updated. + /// + /// If the animation is currently running and [isSelected] is updated, only + /// the [duration] left to finish the animation will be run. + final Duration duration; + + /// Builds the child widget based on the current animation status. + /// + /// When [isSelected] is updated to true, this builder will be called and the + /// animation will animate up to 1. When [isSelected] is updated to + /// `false`, this will be called and the animation will animate down to 0. + final Widget Function(BuildContext, Animation<double>) builder; + + /// + @override + _SelectableAnimatedBuilderState createState() => _SelectableAnimatedBuilderState(); +} + +/// State that manages the [AnimationController] that is passed to +/// [_SelectableAnimatedBuilder.builder]. +class _SelectableAnimatedBuilderState extends State<_SelectableAnimatedBuilder> + with SingleTickerProviderStateMixin { + late AnimationController _controller; + + @override + void initState() { + super.initState(); + _controller = AnimationController(vsync: this); + _controller.duration = widget.duration; + _controller.value = widget.isSelected ? 1.0 : 0.0; + } + + @override + void didUpdateWidget(_SelectableAnimatedBuilder oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.duration != widget.duration) { + _controller.duration = widget.duration; + } + if (oldWidget.isSelected != widget.isSelected) { + if (widget.isSelected) { + _controller.forward(); + } else { + _controller.reverse(); + } + } + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return widget.builder( + context, + _controller, + ); + } +} + +/// Returns `true` if this animation is ticking forward, or has completed, +/// based on [status]. +bool _isForwardOrCompleted(Animation<double> animation) { + return animation.status == AnimationStatus.forward || animation.status == AnimationStatus.completed; +} + +// BEGIN GENERATED TOKEN PROPERTIES - NavigationDrawer + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _NavigationDrawerDefaultsM3 extends NavigationDrawerThemeData { + _NavigationDrawerDefaultsM3(this.context) + : super( + elevation: 1.0, + tileHeight: 56.0, + indicatorShape: const StadiumBorder(), + indicatorSize: const Size(336.0, 56.0), + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + Color? get backgroundColor => _colors.surface; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + Color? get shadowColor => Colors.transparent; + + @override + Color? get indicatorColor => _colors.secondaryContainer; + + @override + MaterialStateProperty<IconThemeData?>? get iconTheme { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + return IconThemeData( + size: 24.0, + color: states.contains(MaterialState.disabled) + ? _colors.onSurfaceVariant.withOpacity(0.38) + : states.contains(MaterialState.selected) + ? _colors.onSecondaryContainer + : _colors.onSurfaceVariant, + ); + }); + } + + @override + MaterialStateProperty<TextStyle?>? get labelTextStyle { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + final TextStyle style = _textTheme.labelLarge!; + return style.apply( + color: states.contains(MaterialState.disabled) + ? _colors.onSurfaceVariant.withOpacity(0.38) + : states.contains(MaterialState.selected) + ? _colors.onSecondaryContainer + : _colors.onSurfaceVariant, + ); + }); + } +} + +// END GENERATED TOKEN PROPERTIES - NavigationDrawer diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_drawer_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_drawer_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..7a06587572cc17d0088130045b7a414fc99a0879 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_drawer_theme.dart @@ -0,0 +1,251 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; +import 'navigation_drawer.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [NavigationDrawer] +/// widgets. +/// +/// Descendant widgets obtain the current [NavigationDrawerThemeData] object +/// using `NavigationDrawerTheme.of(context)`. Instances of +/// [NavigationDrawerThemeData] can be customized with +/// [NavigationDrawerThemeData.copyWith]. +/// +/// Typically a [NavigationDrawerThemeData] is specified as part of the +/// overall [Theme] with [ThemeData.navigationDrawerTheme]. Alternatively, a +/// [NavigationDrawerTheme] inherited widget can be used to theme [NavigationDrawer]s +/// in a subtree of widgets. +/// +/// All [NavigationDrawerThemeData] properties are `null` by default. +/// When null, the [NavigationDrawer] will provide its own defaults based on the +/// overall [Theme]'s textTheme and colorScheme. See the individual +/// [NavigationDrawer] properties for details. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class NavigationDrawerThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.navigationDrawerTheme] and + /// [NavigationDrawerTheme]. + const NavigationDrawerThemeData({ + this.tileHeight, + this.backgroundColor, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.indicatorColor, + this.indicatorShape, + this.indicatorSize, + this.labelTextStyle, + this.iconTheme, + }); + + /// Overrides the default height of [NavigationDrawerDestination]. + final double? tileHeight; + + /// Overrides the default value of [NavigationDrawer.backgroundColor]. + final Color? backgroundColor; + + /// Overrides the default value of [NavigationDrawer.elevation]. + final double? elevation; + + /// Overrides the default value of [NavigationDrawer.shadowColor]. + final Color? shadowColor; + + /// Overrides the default value of [NavigationDrawer.surfaceTintColor]. + final Color? surfaceTintColor; + + /// Overrides the default value of [NavigationDrawer]'s selection indicator. + final Color? indicatorColor; + + /// Overrides the default shape of the [NavigationDrawer]'s selection indicator. + final ShapeBorder? indicatorShape; + + /// Overrides the default size of the [NavigationDrawer]'s selection indicator. + final Size? indicatorSize; + + /// The style to merge with the default text style for + /// [NavigationDestination] labels. + /// + /// You can use this to specify a different style when the label is selected. + final MaterialStateProperty<TextStyle?>? labelTextStyle; + + /// The theme to merge with the default icon theme for + /// [NavigationDestination] icons. + /// + /// You can use this to specify a different icon theme when the icon is + /// selected. + final MaterialStateProperty<IconThemeData?>? iconTheme; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + NavigationDrawerThemeData copyWith({ + double? tileHeight, + Color? backgroundColor, + double? elevation, + Color? shadowColor, + Color? surfaceTintColor, + Color? indicatorColor, + ShapeBorder? indicatorShape, + Size? indicatorSize, + MaterialStateProperty<TextStyle?>? labelTextStyle, + MaterialStateProperty<IconThemeData?>? iconTheme, + }) { + return NavigationDrawerThemeData( + tileHeight: tileHeight ?? this.tileHeight, + backgroundColor: backgroundColor ?? this.backgroundColor, + elevation: elevation ?? this.elevation, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + indicatorColor: indicatorColor ?? this.indicatorColor, + indicatorShape: indicatorShape ?? this.indicatorShape, + indicatorSize: indicatorSize ?? this.indicatorSize, + labelTextStyle: labelTextStyle ?? this.labelTextStyle, + iconTheme: iconTheme ?? this.iconTheme, + ); + } + + /// Linearly interpolate between two navigation rail themes. + /// + /// If both arguments are null then null is returned. + /// + /// {@macro dart.ui.shadow.lerp} + static NavigationDrawerThemeData? lerp(NavigationDrawerThemeData? a, NavigationDrawerThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return NavigationDrawerThemeData( + tileHeight: lerpDouble(a?.tileHeight, b?.tileHeight, t), + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + indicatorColor: Color.lerp(a?.indicatorColor, b?.indicatorColor, t), + indicatorShape: ShapeBorder.lerp(a?.indicatorShape, b?.indicatorShape, t), + indicatorSize: Size.lerp(a?.indicatorSize, a?.indicatorSize, t), + labelTextStyle: MaterialStateProperty.lerp<TextStyle?>( + a?.labelTextStyle, b?.labelTextStyle, t, TextStyle.lerp), + iconTheme: MaterialStateProperty.lerp<IconThemeData?>( + a?.iconTheme, b?.iconTheme, t, IconThemeData.lerp), + ); + } + + @override + int get hashCode => Object.hash( + tileHeight, + backgroundColor, + elevation, + shadowColor, + surfaceTintColor, + indicatorColor, + indicatorShape, + indicatorSize, + labelTextStyle, + iconTheme, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is NavigationDrawerThemeData && + other.tileHeight == tileHeight && + other.backgroundColor == backgroundColor && + other.elevation == elevation && + other.shadowColor == shadowColor && + other.surfaceTintColor == surfaceTintColor && + other.indicatorColor == indicatorColor && + other.indicatorShape == indicatorShape && + other.indicatorSize == indicatorSize && + other.labelTextStyle == labelTextStyle && + other.iconTheme == iconTheme; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + .add(DoubleProperty('tileHeight', tileHeight, defaultValue: null)); + properties.add( + ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, + defaultValue: null)); + properties.add( + ColorProperty('indicatorColor', indicatorColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>( + 'indicatorShape', indicatorShape, + defaultValue: null)); + properties.add(DiagnosticsProperty<Size>('indicatorSize', indicatorSize, + defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<TextStyle?>>( + 'labelTextStyle', labelTextStyle, + defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<IconThemeData?>>( + 'iconTheme', iconTheme, + defaultValue: null)); + } +} + +/// An inherited widget that defines visual properties for [NavigationDrawer]s and +/// [NavigationDestination]s in this widget's subtree. +/// +/// Values specified here are used for [NavigationDrawer] properties that are not +/// given an explicit non-null value. +/// +/// See also: +/// +/// * [ThemeData.navigationDrawerTheme], which describes the +/// [NavigationDrawerThemeData] in the overall theme for the application. +class NavigationDrawerTheme extends InheritedTheme { + /// Creates a navigation rail theme that controls the + /// [NavigationDrawerThemeData] properties for a [NavigationDrawer]. + const NavigationDrawerTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the background color, label text style, icon theme, and label + /// type values for descendant [NavigationDrawer] widgets. + final NavigationDrawerThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [NavigationDrawerTheme] widget, then + /// [ThemeData.navigationDrawerTheme] is used. + static NavigationDrawerThemeData of(BuildContext context) { + final NavigationDrawerTheme? navigationDrawerTheme = + context.dependOnInheritedWidgetOfExactType<NavigationDrawerTheme>(); + return navigationDrawerTheme?.data ?? + Theme.of(context).navigationDrawerTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return NavigationDrawerTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(NavigationDrawerTheme oldWidget) => + data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_rail.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_rail.dart new file mode 100644 index 0000000000000000000000000000000000000000..cb86709e8c89ad9c250ab48c3f50e1d0e958f74d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_rail.dart @@ -0,0 +1,1134 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/widgets.dart'; + +import 'color_scheme.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'navigation_bar.dart'; +import 'navigation_rail_theme.dart'; +import 'text_theme.dart'; +import 'theme.dart'; + +const double _kCircularIndicatorDiameter = 56; +const double _kIndicatorHeight = 32; + +/// A Material Design widget that is meant to be displayed at the left or right of an +/// app to navigate between a small number of views, typically between three and +/// five. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=y9xchtVTtqQ} +/// +/// The navigation rail is meant for layouts with wide viewports, such as a +/// desktop web or tablet landscape layout. For smaller layouts, like mobile +/// portrait, a [BottomNavigationBar] should be used instead. +/// +/// A navigation rail is usually used as the first or last element of a [Row] +/// which defines the app's [Scaffold] body. +/// +/// The appearance of all of the [NavigationRail]s within an app can be +/// specified with [NavigationRailTheme]. The default values for null theme +/// properties are based on the [Theme]'s [ThemeData.textTheme], +/// [ThemeData.iconTheme], and [ThemeData.colorScheme]. +/// +/// Adaptive layouts can build different instances of the [Scaffold] in order to +/// have a navigation rail for more horizontal layouts and a bottom navigation +/// bar for more vertical layouts. See +/// [the adaptive_scaffold.dart sample](https://github.com/flutter/samples/blob/master/experimental/web_dashboard/lib/src/widgets/third_party/adaptive_scaffold.dart) +/// for an example. +/// +/// {@tool dartpad} +/// This example shows a [NavigationRail] used within a Scaffold with 3 +/// [NavigationRailDestination]s. The main content is separated by a divider +/// (although elevation on the navigation rail can be used instead). The +/// `_selectedIndex` is updated by the `onDestinationSelected` callback. +/// +/// ** See code in examples/api/lib/material/navigation_rail/navigation_rail.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of [NavigationRail] widget used within a Scaffold with 3 +/// [NavigationRailDestination]s, as described in: https://m3.material.io/components/navigation-rail/overview +/// +/// ** See code in examples/api/lib/material/navigation_rail/navigation_rail.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Scaffold], which can display the navigation rail within a [Row] of the +/// [Scaffold.body] slot. +/// * [NavigationRailDestination], which is used as a model to create tappable +/// destinations in the navigation rail. +/// * [BottomNavigationBar], which is a similar navigation widget that's laid +/// out horizontally. +/// * <https://material.io/components/navigation-rail/> +/// * <https://m3.material.io/components/navigation-rail> +class NavigationRail extends StatefulWidget { + /// Creates a Material Design navigation rail. + /// + /// The value of [destinations] must be a list of two or more + /// [NavigationRailDestination] values. + /// + /// If [elevation] is specified, it must be non-negative. + /// + /// If [minWidth] is specified, it must be non-negative, and if + /// [minExtendedWidth] is specified, it must be non-negative and greater than + /// [minWidth]. + /// + /// The [extended] argument can only be set to true when the [labelType] is + /// null or [NavigationRailLabelType.none]. + /// + /// If [backgroundColor], [elevation], [groupAlignment], [labelType], + /// [unselectedLabelTextStyle], [selectedLabelTextStyle], + /// [unselectedIconTheme], or [selectedIconTheme] are null, then their + /// [NavigationRailThemeData] values will be used. If the corresponding + /// [NavigationRailThemeData] property is null, then the navigation rail + /// defaults are used. See the individual properties for more information. + /// + /// Typically used within a [Row] that defines the [Scaffold.body] property. + const NavigationRail({ + super.key, + this.backgroundColor, + this.extended = false, + this.leading, + this.trailing, + required this.destinations, + required this.selectedIndex, + this.onDestinationSelected, + this.elevation, + this.groupAlignment, + this.labelType, + this.unselectedLabelTextStyle, + this.selectedLabelTextStyle, + this.unselectedIconTheme, + this.selectedIconTheme, + this.minWidth, + this.minExtendedWidth, + this.useIndicator, + this.indicatorColor, + this.indicatorShape, + }) : assert(destinations.length >= 2), + assert(selectedIndex == null || (0 <= selectedIndex && selectedIndex < destinations.length)), + assert(elevation == null || elevation > 0), + assert(minWidth == null || minWidth > 0), + assert(minExtendedWidth == null || minExtendedWidth > 0), + assert((minWidth == null || minExtendedWidth == null) || minExtendedWidth >= minWidth), + assert(!extended || (labelType == null || labelType == NavigationRailLabelType.none)); + + /// Sets the color of the Container that holds all of the [NavigationRail]'s + /// contents. + /// + /// The default value is [NavigationRailThemeData.backgroundColor]. If + /// [NavigationRailThemeData.backgroundColor] is null, then the default value + /// is based on [ColorScheme.surface] of [ThemeData.colorScheme]. + final Color? backgroundColor; + + /// Indicates that the [NavigationRail] should be in the extended state. + /// + /// The extended state has a wider rail container, and the labels are + /// positioned next to the icons. [minExtendedWidth] can be used to set the + /// minimum width of the rail when it is in this state. + /// + /// The rail will implicitly animate between the extended and normal state. + /// + /// If the rail is going to be in the extended state, then the [labelType] + /// must be set to [NavigationRailLabelType.none]. + /// + /// The default value is false. + final bool extended; + + /// The leading widget in the rail that is placed above the destinations. + /// + /// It is placed at the top of the rail, above the [destinations]. Its + /// location is not affected by [groupAlignment]. + /// + /// This is commonly a [FloatingActionButton], but may also be a non-button, + /// such as a logo. + /// + /// The default value is null. + final Widget? leading; + + /// The trailing widget in the rail that is placed below the destinations. + /// + /// The trailing widget is placed below the last [NavigationRailDestination]. + /// It's location is affected by [groupAlignment]. + /// + /// This is commonly a list of additional options or destinations that is + /// usually only rendered when [extended] is true. + /// + /// The default value is null. + final Widget? trailing; + + /// Defines the appearance of the button items that are arrayed within the + /// navigation rail. + /// + /// The value must be a list of two or more [NavigationRailDestination] + /// values. + final List<NavigationRailDestination> destinations; + + /// The index into [destinations] for the current selected + /// [NavigationRailDestination] or null if no destination is selected. + final int? selectedIndex; + + /// Called when one of the [destinations] is selected. + /// + /// The stateful widget that creates the navigation rail needs to keep + /// track of the index of the selected [NavigationRailDestination] and call + /// `setState` to rebuild the navigation rail with the new [selectedIndex]. + final ValueChanged<int>? onDestinationSelected; + + /// The rail's elevation or z-coordinate. + /// + /// If [Directionality] is [intl.TextDirection.LTR], the inner side is the + /// right side, and if [Directionality] is [intl.TextDirection.RTL], it is + /// the left side. + /// + /// The default value is 0. + final double? elevation; + + /// The vertical alignment for the group of [destinations] within the rail. + /// + /// The [NavigationRailDestination]s are grouped together with the [trailing] + /// widget, between the [leading] widget and the bottom of the rail. + /// + /// The value must be between -1.0 and 1.0. + /// + /// If [groupAlignment] is -1.0, then the items are aligned to the top. If + /// [groupAlignment] is 0.0, then the items are aligned to the center. If + /// [groupAlignment] is 1.0, then the items are aligned to the bottom. + /// + /// The default is -1.0. + /// + /// See also: + /// * [Alignment.y] + /// + final double? groupAlignment; + + /// Defines the layout and behavior of the labels for the default, unextended + /// [NavigationRail]. + /// + /// When a navigation rail is [extended], the labels are always shown. + /// + /// The default value is [NavigationRailThemeData.labelType]. If + /// [NavigationRailThemeData.labelType] is null, then the default value is + /// [NavigationRailLabelType.none]. + /// + /// See also: + /// + /// * [NavigationRailLabelType] for information on the meaning of different + /// types. + final NavigationRailLabelType? labelType; + + /// The [TextStyle] of a destination's label when it is unselected. + /// + /// When one of the [destinations] is selected the [selectedLabelTextStyle] + /// will be used instead. + /// + /// The default value is based on the [Theme]'s [TextTheme.bodyLarge]. The + /// default color is based on the [Theme]'s [ColorScheme.onSurface]. + /// + /// Properties from this text style, or + /// [NavigationRailThemeData.unselectedLabelTextStyle] if this is null, are + /// merged into the defaults. + final TextStyle? unselectedLabelTextStyle; + + /// The [TextStyle] of a destination's label when it is selected. + /// + /// When a [NavigationRailDestination] is not selected, + /// [unselectedLabelTextStyle] will be used. + /// + /// The default value is based on the [TextTheme.bodyLarge] of + /// [ThemeData.textTheme]. The default color is based on the [Theme]'s + /// [ColorScheme.primary]. + /// + /// Properties from this text style, + /// or [NavigationRailThemeData.selectedLabelTextStyle] if this is null, are + /// merged into the defaults. + final TextStyle? selectedLabelTextStyle; + + /// The visual properties of the icon in the unselected destination. + /// + /// If this field is not provided, or provided with any null properties, then + /// a copy of the [IconThemeData.fallback] with a custom [NavigationRail] + /// specific color will be used. + /// + /// The default value is the [Theme]'s [ThemeData.iconTheme] with a color + /// of the [Theme]'s [ColorScheme.onSurface] with an opacity of 0.64. + /// Properties from this icon theme, or + /// [NavigationRailThemeData.unselectedIconTheme] if this is null, are + /// merged into the defaults. + final IconThemeData? unselectedIconTheme; + + /// The visual properties of the icon in the selected destination. + /// + /// When a [NavigationRailDestination] is not selected, + /// [unselectedIconTheme] will be used. + /// + /// The default value is the [Theme]'s [ThemeData.iconTheme] with a color + /// of the [Theme]'s [ColorScheme.primary]. Properties from this icon theme, + /// or [NavigationRailThemeData.selectedIconTheme] if this is null, are + /// merged into the defaults. + final IconThemeData? selectedIconTheme; + + /// The smallest possible width for the rail regardless of the destination's + /// icon or label size. + /// + /// The default is 72. + /// + /// This value also defines the min width and min height of the destinations. + /// + /// To make a compact rail, set this to 56 and use + /// [NavigationRailLabelType.none]. + final double? minWidth; + + /// The final width when the animation is complete for setting [extended] to + /// true. + /// + /// This is only used when [extended] is set to true. + /// + /// The default value is 256. + final double? minExtendedWidth; + + /// If `true`, adds a rounded [NavigationIndicator] behind the selected + /// destination's icon. + /// + /// The indicator's shape will be circular if [labelType] is + /// [NavigationRailLabelType.none], or a [StadiumBorder] if [labelType] is + /// [NavigationRailLabelType.all] or [NavigationRailLabelType.selected]. + /// + /// If `null`, defaults to [NavigationRailThemeData.useIndicator]. If that is + /// `null`, defaults to [ThemeData.useMaterial3]. + final bool? useIndicator; + + /// Overrides the default value of [NavigationRail]'s selection indicator color, + /// when [useIndicator] is true. + /// + /// If this is null, [NavigationRailThemeData.indicatorColor] is used. If + /// that is null, defaults to [ColorScheme.secondaryContainer]. + final Color? indicatorColor; + + /// Overrides the default value of [NavigationRail]'s selection indicator shape, + /// when [useIndicator] is true. + /// + /// If this is null, [NavigationRailThemeData.indicatorShape] is used. If + /// that is null, defaults to [StadiumBorder]. + final ShapeBorder? indicatorShape; + + /// Returns the animation that controls the [NavigationRail.extended] state. + /// + /// This can be used to synchronize animations in the [leading] or [trailing] + /// widget, such as an animated menu or a [FloatingActionButton] animation. + /// + /// {@tool dartpad} + /// This example shows how to use this animation to create a [FloatingActionButton] + /// that animates itself between the normal and extended states of the + /// [NavigationRail]. + /// + /// An instance of `MyNavigationRailFab` is created for [NavigationRail.leading]. + /// Pressing the FAB button toggles the "extended" state of the [NavigationRail]. + /// + /// ** See code in examples/api/lib/material/navigation_rail/navigation_rail.extended_animation.0.dart ** + /// {@end-tool} + static Animation<double> extendedAnimation(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<_ExtendedNavigationRailAnimation>()!.animation; + } + + @override + State<NavigationRail> createState() => _NavigationRailState(); +} + +class _NavigationRailState extends State<NavigationRail> with TickerProviderStateMixin { + late List<AnimationController> _destinationControllers; + late List<Animation<double>> _destinationAnimations; + late AnimationController _extendedController; + late Animation<double> _extendedAnimation; + + @override + void initState() { + super.initState(); + _initControllers(); + } + + @override + void dispose() { + _disposeControllers(); + super.dispose(); + } + + @override + void didUpdateWidget(NavigationRail oldWidget) { + super.didUpdateWidget(oldWidget); + + if (widget.extended != oldWidget.extended) { + if (widget.extended) { + _extendedController.forward(); + } else { + _extendedController.reverse(); + } + } + + // No animated segue if the length of the items list changes. + if (widget.destinations.length != oldWidget.destinations.length) { + _resetState(); + return; + } + + if (widget.selectedIndex != oldWidget.selectedIndex) { + if (oldWidget.selectedIndex != null) { + _destinationControllers[oldWidget.selectedIndex!].reverse(); + } + if (widget.selectedIndex != null) { + _destinationControllers[widget.selectedIndex!].forward(); + } + return; + } + } + + @override + Widget build(BuildContext context) { + final NavigationRailThemeData navigationRailTheme = NavigationRailTheme.of(context); + final NavigationRailThemeData defaults = Theme.of(context).useMaterial3 ? _NavigationRailDefaultsM3(context) : _NavigationRailDefaultsM2(context); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + + final Color backgroundColor = widget.backgroundColor ?? navigationRailTheme.backgroundColor ?? defaults.backgroundColor!; + final double elevation = widget.elevation ?? navigationRailTheme.elevation ?? defaults.elevation!; + final double minWidth = widget.minWidth ?? navigationRailTheme.minWidth ?? defaults.minWidth!; + final double minExtendedWidth = widget.minExtendedWidth ?? navigationRailTheme.minExtendedWidth ?? defaults.minExtendedWidth!; + final TextStyle unselectedLabelTextStyle = widget.unselectedLabelTextStyle ?? navigationRailTheme.unselectedLabelTextStyle ?? defaults.unselectedLabelTextStyle!; + final TextStyle selectedLabelTextStyle = widget.selectedLabelTextStyle ?? navigationRailTheme.selectedLabelTextStyle ?? defaults.selectedLabelTextStyle!; + final IconThemeData unselectedIconTheme = widget.unselectedIconTheme ?? navigationRailTheme.unselectedIconTheme ?? defaults.unselectedIconTheme!; + final IconThemeData selectedIconTheme = widget.selectedIconTheme ?? navigationRailTheme.selectedIconTheme ?? defaults.selectedIconTheme!; + final double groupAlignment = widget.groupAlignment ?? navigationRailTheme.groupAlignment ?? defaults.groupAlignment!; + final NavigationRailLabelType labelType = widget.labelType ?? navigationRailTheme.labelType ?? defaults.labelType!; + final bool useIndicator = widget.useIndicator ?? navigationRailTheme.useIndicator ?? defaults.useIndicator!; + final Color? indicatorColor = widget.indicatorColor ?? navigationRailTheme.indicatorColor ?? defaults.indicatorColor; + final ShapeBorder? indicatorShape = widget.indicatorShape ?? navigationRailTheme.indicatorShape ?? defaults.indicatorShape; + + // For backwards compatibility, in M2 the opacity of the unselected icons needs + // to be set to the default if it isn't in the given theme. This can be removed + // when Material 3 is the default. + final IconThemeData effectiveUnselectedIconTheme = Theme.of(context).useMaterial3 + ? unselectedIconTheme + : unselectedIconTheme.copyWith(opacity: unselectedIconTheme.opacity ?? defaults.unselectedIconTheme!.opacity); + + final bool isRTLDirection = Directionality.of(context) == TextDirection.rtl; + + return _ExtendedNavigationRailAnimation( + animation: _extendedAnimation, + child: Semantics( + explicitChildNodes: true, + child: Material( + elevation: elevation, + color: backgroundColor, + child: SafeArea( + right: isRTLDirection, + left: !isRTLDirection, + child: Column( + children: <Widget>[ + _verticalSpacer, + if (widget.leading != null) + ...<Widget>[ + widget.leading!, + _verticalSpacer, + ], + Expanded( + child: Align( + alignment: Alignment(0, groupAlignment), + child: Column( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + for (int i = 0; i < widget.destinations.length; i += 1) + _RailDestination( + minWidth: minWidth, + minExtendedWidth: minExtendedWidth, + extendedTransitionAnimation: _extendedAnimation, + selected: widget.selectedIndex == i, + icon: widget.selectedIndex == i ? widget.destinations[i].selectedIcon : widget.destinations[i].icon, + label: widget.destinations[i].label, + destinationAnimation: _destinationAnimations[i], + labelType: labelType, + iconTheme: widget.selectedIndex == i ? selectedIconTheme : effectiveUnselectedIconTheme, + labelTextStyle: widget.selectedIndex == i ? selectedLabelTextStyle : unselectedLabelTextStyle, + padding: widget.destinations[i].padding, + useIndicator: useIndicator, + indicatorColor: useIndicator ? indicatorColor : null, + indicatorShape: useIndicator ? indicatorShape : null, + onTap: () { + if (widget.onDestinationSelected != null) { + widget.onDestinationSelected!(i); + } + }, + indexLabel: localizations.tabLabel( + tabIndex: i + 1, + tabCount: widget.destinations.length, + ), + disabled: widget.destinations[i].disabled, + ), + if (widget.trailing != null) + widget.trailing!, + ], + ), + ), + ), + ], + ), + ), + ), + ), + ); + } + + void _disposeControllers() { + for (final AnimationController controller in _destinationControllers) { + controller.dispose(); + } + _extendedController.dispose(); + } + + void _initControllers() { + _destinationControllers = List<AnimationController>.generate(widget.destinations.length, (int index) { + return AnimationController( + duration: kThemeAnimationDuration, + vsync: this, + )..addListener(_rebuild); + }); + _destinationAnimations = _destinationControllers.map((AnimationController controller) => controller.view).toList(); + if (widget.selectedIndex != null) { + _destinationControllers[widget.selectedIndex!].value = 1.0; + } + _extendedController = AnimationController( + duration: kThemeAnimationDuration, + vsync: this, + value: widget.extended ? 1.0 : 0.0, + ); + _extendedAnimation = CurvedAnimation( + parent: _extendedController, + curve: Curves.easeInOut, + ); + _extendedController.addListener(() { + _rebuild(); + }); + } + + void _resetState() { + _disposeControllers(); + _initControllers(); + } + + void _rebuild() { + setState(() { + // Rebuilding when any of the controllers tick, i.e. when the items are + // animating. + }); + } +} + +class _RailDestination extends StatelessWidget { + _RailDestination({ + required this.minWidth, + required this.minExtendedWidth, + required this.icon, + required this.label, + required this.destinationAnimation, + required this.extendedTransitionAnimation, + required this.labelType, + required this.selected, + required this.iconTheme, + required this.labelTextStyle, + required this.onTap, + required this.indexLabel, + this.padding, + required this.useIndicator, + this.indicatorColor, + this.indicatorShape, + this.disabled = false, + }) : _positionAnimation = CurvedAnimation( + parent: ReverseAnimation(destinationAnimation), + curve: Curves.easeInOut, + reverseCurve: Curves.easeInOut.flipped, + ); + + final double minWidth; + final double minExtendedWidth; + final Widget icon; + final Widget label; + final Animation<double> destinationAnimation; + final NavigationRailLabelType labelType; + final bool selected; + final Animation<double> extendedTransitionAnimation; + final IconThemeData iconTheme; + final TextStyle labelTextStyle; + final VoidCallback onTap; + final String indexLabel; + final EdgeInsetsGeometry? padding; + final bool useIndicator; + final Color? indicatorColor; + final ShapeBorder? indicatorShape; + final bool disabled; + + final Animation<double> _positionAnimation; + + @override + Widget build(BuildContext context) { + assert( + useIndicator || indicatorColor == null, + '[NavigationRail.indicatorColor] does not have an effect when [NavigationRail.useIndicator] is false', + ); + + final ThemeData theme = Theme.of(context); + final TextDirection textDirection = Directionality.of(context); + final bool material3 = theme.useMaterial3; + final EdgeInsets destinationPadding = (padding ?? EdgeInsets.zero).resolve(textDirection); + Offset indicatorOffset; + bool applyXOffset = false; + + final Widget themedIcon = IconTheme( + data: disabled + ? iconTheme.copyWith(color: theme.colorScheme.onSurface.withOpacity(0.38)) + : iconTheme, + child: icon, + ); + final Widget styledLabel = DefaultTextStyle( + style: disabled + ? labelTextStyle.copyWith(color: theme.colorScheme.onSurface.withOpacity(0.38)) + : labelTextStyle, + child: label, + ); + + Widget content; + + // The indicator height is fixed and equal to _kIndicatorHeight. + // When the icon height is larger than the indicator height the indicator + // vertical offset is used to vertically center the indicator. + final bool isLargeIconSize = iconTheme.size != null && iconTheme.size! > _kIndicatorHeight; + final double indicatorVerticalOffset = isLargeIconSize ? (iconTheme.size! - _kIndicatorHeight) / 2 : 0; + + switch (labelType) { + case NavigationRailLabelType.none: + // Split the destination spacing across the top and bottom to keep the icon centered. + final Widget? spacing = material3 ? const SizedBox(height: _verticalDestinationSpacingM3 / 2) : null; + indicatorOffset = Offset( + minWidth / 2 + destinationPadding.left, + _verticalDestinationSpacingM3 / 2 + destinationPadding.top + indicatorVerticalOffset, + ); + final Widget iconPart = Column( + children: <Widget>[ + if (spacing != null) spacing, + SizedBox( + width: minWidth, + height: material3 ? null : minWidth, + child: Center( + child: _AddIndicator( + addIndicator: useIndicator, + indicatorColor: indicatorColor, + indicatorShape: indicatorShape, + isCircular: !material3, + indicatorAnimation: destinationAnimation, + child: themedIcon, + ), + ), + ), + if (spacing != null) spacing, + ], + ); + if (extendedTransitionAnimation.value == 0) { + content = Padding( + padding: padding ?? EdgeInsets.zero, + child: Stack( + children: <Widget>[ + iconPart, + // For semantics when label is not showing, + SizedBox.shrink( + child: Visibility.maintain( + visible: false, + child: label, + ), + ), + ], + ), + ); + } else { + final Animation<double> labelFadeAnimation = extendedTransitionAnimation.drive(CurveTween(curve: const Interval(0.0, 0.25))); + applyXOffset = true; + content = Padding( + padding: padding ?? EdgeInsets.zero, + child: ConstrainedBox( + constraints: BoxConstraints( + minWidth: lerpDouble(minWidth, minExtendedWidth, extendedTransitionAnimation.value)!, + ), + child: ClipRect( + child: Row( + children: <Widget>[ + iconPart, + Align( + heightFactor: 1.0, + widthFactor: extendedTransitionAnimation.value, + alignment: AlignmentDirectional.centerStart, + child: FadeTransition( + alwaysIncludeSemantics: true, + opacity: labelFadeAnimation, + child: styledLabel, + ), + ), + SizedBox(width: _horizontalDestinationPadding * extendedTransitionAnimation.value), + ], + ), + ), + ), + ); + } + case NavigationRailLabelType.selected: + final double appearingAnimationValue = 1 - _positionAnimation.value; + final double verticalPadding = lerpDouble(_verticalDestinationPaddingNoLabel, _verticalDestinationPaddingWithLabel, appearingAnimationValue)!; + final Interval interval = selected ? const Interval(0.25, 0.75) : const Interval(0.75, 1.0); + final Animation<double> labelFadeAnimation = destinationAnimation.drive(CurveTween(curve: interval)); + final double minHeight = material3 ? 0 : minWidth; + final Widget topSpacing = SizedBox(height: material3 ? 0 : verticalPadding); + final Widget labelSpacing = SizedBox(height: material3 ? lerpDouble(0, _verticalIconLabelSpacingM3, appearingAnimationValue)! : 0); + final Widget bottomSpacing = SizedBox(height: material3 ? _verticalDestinationSpacingM3 : verticalPadding); + final double indicatorHorizontalPadding = (destinationPadding.left / 2) - (destinationPadding.right / 2); + final double indicatorVerticalPadding = destinationPadding.top; + indicatorOffset = Offset( + minWidth / 2 + indicatorHorizontalPadding, + indicatorVerticalPadding + indicatorVerticalOffset, + ); + if (minWidth < _NavigationRailDefaultsM2(context).minWidth!) { + indicatorOffset = Offset( + minWidth / 2 + _horizontalDestinationSpacingM3, + indicatorVerticalPadding + indicatorVerticalOffset, + ); + } + content = Container( + constraints: BoxConstraints( + minWidth: minWidth, + minHeight: minHeight, + ), + padding: padding ?? const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding), + child: ClipRect( + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: <Widget>[ + topSpacing, + _AddIndicator( + addIndicator: useIndicator, + indicatorColor: indicatorColor, + indicatorShape: indicatorShape, + isCircular: false, + indicatorAnimation: destinationAnimation, + child: themedIcon, + ), + labelSpacing, + Align( + alignment: Alignment.topCenter, + heightFactor: appearingAnimationValue, + widthFactor: 1.0, + child: FadeTransition( + alwaysIncludeSemantics: true, + opacity: labelFadeAnimation, + child: styledLabel, + ), + ), + bottomSpacing, + ], + ), + ), + ); + case NavigationRailLabelType.all: + final double minHeight = material3 ? 0 : minWidth; + final Widget topSpacing = SizedBox(height: material3 ? 0 : _verticalDestinationPaddingWithLabel); + final Widget labelSpacing = SizedBox(height: material3 ? _verticalIconLabelSpacingM3 : 0); + final Widget bottomSpacing = SizedBox(height: material3 ? _verticalDestinationSpacingM3 : _verticalDestinationPaddingWithLabel); + final double indicatorHorizontalPadding = (destinationPadding.left / 2) - (destinationPadding.right / 2); + final double indicatorVerticalPadding = destinationPadding.top; + indicatorOffset = Offset( + minWidth / 2 + indicatorHorizontalPadding, + indicatorVerticalPadding + indicatorVerticalOffset, + ); + if (minWidth < _NavigationRailDefaultsM2(context).minWidth!) { + indicatorOffset = Offset( + minWidth / 2 + _horizontalDestinationSpacingM3, + indicatorVerticalPadding + indicatorVerticalOffset, + ); + } + content = Container( + constraints: BoxConstraints( + minWidth: minWidth, + minHeight: minHeight, + ), + padding: padding ?? const EdgeInsets.symmetric(horizontal: _horizontalDestinationPadding), + child: Column( + children: <Widget>[ + topSpacing, + _AddIndicator( + addIndicator: useIndicator, + indicatorColor: indicatorColor, + indicatorShape: indicatorShape, + isCircular: false, + indicatorAnimation: destinationAnimation, + child: themedIcon, + ), + labelSpacing, + styledLabel, + bottomSpacing, + ], + ), + ); + } + + final ColorScheme colors = Theme.of(context).colorScheme; + final bool primaryColorAlphaModified = colors.primary.alpha < 255.0; + final Color effectiveSplashColor = primaryColorAlphaModified + ? colors.primary + : colors.primary.withOpacity(0.12); + final Color effectiveHoverColor = primaryColorAlphaModified + ? colors.primary + : colors.primary.withOpacity(0.04); + return Semantics( + container: true, + selected: selected, + child: Stack( + children: <Widget>[ + Material( + type: MaterialType.transparency, + child: _IndicatorInkWell( + onTap: disabled ? null : onTap, + borderRadius: BorderRadius.all(Radius.circular(minWidth / 2.0)), + customBorder: indicatorShape, + splashColor: effectiveSplashColor, + hoverColor: effectiveHoverColor, + useMaterial3: material3, + indicatorOffset: indicatorOffset, + applyXOffset: applyXOffset, + textDirection: textDirection, + child: content, + ), + ), + Semantics( + label: indexLabel, + ), + ], + ), + ); + } +} + +class _IndicatorInkWell extends InkResponse { + const _IndicatorInkWell({ + super.child, + super.onTap, + ShapeBorder? customBorder, + BorderRadius? borderRadius, + super.splashColor, + super.hoverColor, + required this.useMaterial3, + required this.indicatorOffset, + required this.applyXOffset, + required this.textDirection, + }) : super( + containedInkWell: true, + highlightShape: BoxShape.rectangle, + borderRadius: useMaterial3 ? null : borderRadius, + customBorder: useMaterial3 ? customBorder : null, + ); + + final bool useMaterial3; + + // The offset used to position Ink highlight. + final Offset indicatorOffset; + + // Whether the horizontal offset from indicatorOffset should be used to position Ink highlight. + // If true, Ink highlight uses the indicator horizontal offset. If false, Ink highlight is centered horizontally. + final bool applyXOffset; + + // The text direction used to adjust the indicator horizontal offset. + final TextDirection textDirection; + + @override + RectCallback? getRectCallback(RenderBox referenceBox) { + if (useMaterial3) { + final double boxWidth = referenceBox.size.width; + double indicatorHorizontalCenter = applyXOffset ? indicatorOffset.dx : boxWidth / 2; + if (textDirection == TextDirection.rtl) { + indicatorHorizontalCenter = boxWidth - indicatorHorizontalCenter; + } + return () { + return Rect.fromLTWH( + indicatorHorizontalCenter - (_kCircularIndicatorDiameter / 2), + indicatorOffset.dy, + _kCircularIndicatorDiameter, + _kIndicatorHeight, + ); + }; + } + return null; + } +} + +/// When [addIndicator] is `true`, puts [child] center aligned in a [Stack] with +/// a [NavigationIndicator] behind it, otherwise returns [child]. +/// +/// When [isCircular] is true, the indicator will be a circle, otherwise the +/// indicator will be a stadium shape. +class _AddIndicator extends StatelessWidget { + const _AddIndicator({ + required this.addIndicator, + required this.isCircular, + required this.indicatorColor, + required this.indicatorShape, + required this.indicatorAnimation, + required this.child, + }); + + final bool addIndicator; + final bool isCircular; + final Color? indicatorColor; + final ShapeBorder? indicatorShape; + final Animation<double> indicatorAnimation; + final Widget child; + + @override + Widget build(BuildContext context) { + if (!addIndicator) { + return child; + } + late final Widget indicator; + if (isCircular) { + indicator = NavigationIndicator( + animation: indicatorAnimation, + height: _kCircularIndicatorDiameter, + width: _kCircularIndicatorDiameter, + borderRadius: BorderRadius.circular(_kCircularIndicatorDiameter / 2), + color: indicatorColor, + ); + } else { + indicator = NavigationIndicator( + animation: indicatorAnimation, + width: _kCircularIndicatorDiameter, + shape: indicatorShape, + color: indicatorColor, + ); + } + + return Stack( + alignment: Alignment.center, + children: <Widget>[ + indicator, + child, + ], + ); + } +} + + +/// Defines the behavior of the labels of a [NavigationRail]. +/// +/// See also: +/// +/// * [NavigationRail] +enum NavigationRailLabelType { + /// Only the [NavigationRailDestination]s are shown. + none, + + /// Only the selected [NavigationRailDestination] will show its label. + /// + /// The label will animate in and out as new [NavigationRailDestination]s are + /// selected. + selected, + + /// All [NavigationRailDestination]s will show their label. + all, +} + +/// Defines a [NavigationRail] button that represents one "destination" view. +/// +/// See also: +/// +/// * [NavigationRail] +class NavigationRailDestination { + /// Creates a destination that is used with [NavigationRail.destinations]. + /// + /// When the [NavigationRail.labelType] is [NavigationRailLabelType.none], the + /// label is still used for semantics, and may still be used if + /// [NavigationRail.extended] is true. + const NavigationRailDestination({ + required this.icon, + Widget? selectedIcon, + this.indicatorColor, + this.indicatorShape, + required this.label, + this.padding, + this.disabled = false, + }) : selectedIcon = selectedIcon ?? icon; + + /// The icon of the destination. + /// + /// Typically the icon is an [Icon] or an [ImageIcon] widget. If another type + /// of widget is provided then it should configure itself to match the current + /// [IconTheme] size and color. + /// + /// If [selectedIcon] is provided, this will only be displayed when the + /// destination is not selected. + /// + /// To make the [NavigationRail] more accessible, consider choosing an + /// icon with a stroked and filled version, such as [Icons.cloud] and + /// [Icons.cloud_queue]. The [icon] should be set to the stroked version and + /// [selectedIcon] to the filled version. + final Widget icon; + + /// An alternative icon displayed when this destination is selected. + /// + /// If this icon is not provided, the [NavigationRail] will display [icon] in + /// either state. The size, color, and opacity of the + /// [NavigationRail.selectedIconTheme] will still apply. + /// + /// See also: + /// + /// * [NavigationRailDestination.icon], for a description of how to pair + /// icons. + final Widget selectedIcon; + + /// The color of the [indicatorShape] when this destination is selected. + final Color? indicatorColor; + + /// The shape of the selection indicator. + final ShapeBorder? indicatorShape; + + /// The label for the destination. + /// + /// The label must be provided when used with the [NavigationRail]. When the + /// [NavigationRail.labelType] is [NavigationRailLabelType.none], the label is + /// still used for semantics, and may still be used if + /// [NavigationRail.extended] is true. + final Widget label; + + /// The amount of space to inset the destination item. + final EdgeInsetsGeometry? padding; + + /// Indicates that this destination is inaccessible. + final bool disabled; +} + +class _ExtendedNavigationRailAnimation extends InheritedWidget { + const _ExtendedNavigationRailAnimation({ + required this.animation, + required super.child, + }); + + final Animation<double> animation; + + @override + bool updateShouldNotify(_ExtendedNavigationRailAnimation old) => animation != old.animation; +} + +// There don't appear to be tokens for these values, but they are +// shown in the spec. +const double _horizontalDestinationPadding = 8.0; +const double _verticalDestinationPaddingNoLabel = 24.0; +const double _verticalDestinationPaddingWithLabel = 16.0; +const Widget _verticalSpacer = SizedBox(height: 8.0); +const double _verticalIconLabelSpacingM3 = 4.0; +const double _verticalDestinationSpacingM3 = 12.0; +const double _horizontalDestinationSpacingM3 = 12.0; + +// Hand coded defaults based on Material Design 2. +class _NavigationRailDefaultsM2 extends NavigationRailThemeData { + _NavigationRailDefaultsM2(BuildContext context) + : _theme = Theme.of(context), + _colors = Theme.of(context).colorScheme, + super( + elevation: 0, + groupAlignment: -1, + labelType: NavigationRailLabelType.none, + useIndicator: false, + minWidth: 72.0, + minExtendedWidth: 256, + ); + + final ThemeData _theme; + final ColorScheme _colors; + + @override Color? get backgroundColor => _colors.surface; + + @override TextStyle? get unselectedLabelTextStyle { + return _theme.textTheme.bodyLarge!.copyWith(color: _colors.onSurface.withOpacity(0.64)); + } + + @override TextStyle? get selectedLabelTextStyle { + return _theme.textTheme.bodyLarge!.copyWith(color: _colors.primary); + } + + @override IconThemeData? get unselectedIconTheme { + return IconThemeData( + size: 24.0, + color: _colors.onSurface, + opacity: 0.64, + ); + } + + @override IconThemeData? get selectedIconTheme { + return IconThemeData( + size: 24.0, + color: _colors.primary, + opacity: 1.0, + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - NavigationRail + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _NavigationRailDefaultsM3 extends NavigationRailThemeData { + _NavigationRailDefaultsM3(this.context) + : super( + elevation: 0.0, + groupAlignment: -1, + labelType: NavigationRailLabelType.none, + useIndicator: true, + minWidth: 80.0, + minExtendedWidth: 256, + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override Color? get backgroundColor => _colors.surface; + + @override TextStyle? get unselectedLabelTextStyle { + return _textTheme.labelMedium!.copyWith(color: _colors.onSurface); + } + + @override TextStyle? get selectedLabelTextStyle { + return _textTheme.labelMedium!.copyWith(color: _colors.onSurface); + } + + @override IconThemeData? get unselectedIconTheme { + return IconThemeData( + size: 24.0, + color: _colors.onSurfaceVariant, + ); + } + + @override IconThemeData? get selectedIconTheme { + return IconThemeData( + size: 24.0, + color: _colors.onSecondaryContainer, + ); + } + + @override Color? get indicatorColor => _colors.secondaryContainer; + + @override ShapeBorder? get indicatorShape => const StadiumBorder(); +} + +// END GENERATED TOKEN PROPERTIES - NavigationRail diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_rail_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_rail_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..664d2cb57fd3fbc4e8d27d71642bec7e122efb91 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/navigation_rail_theme.dart @@ -0,0 +1,272 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'navigation_rail.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [NavigationRail] +/// widgets. +/// +/// Descendant widgets obtain the current [NavigationRailThemeData] object +/// using `NavigationRailTheme.of(context)`. Instances of +/// [NavigationRailThemeData] can be customized with +/// [NavigationRailThemeData.copyWith]. +/// +/// Typically a [NavigationRailThemeData] is specified as part of the +/// overall [Theme] with [ThemeData.navigationRailTheme]. +/// +/// All [NavigationRailThemeData] properties are `null` by default. +/// When null, the [NavigationRail] will use the values from [ThemeData] +/// if they exist, otherwise it will provide its own defaults based on the +/// overall [Theme]'s textTheme and colorScheme. See the individual +/// [NavigationRail] properties for details. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class NavigationRailThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.navigationRailTheme]. + const NavigationRailThemeData({ + this.backgroundColor, + this.elevation, + this.unselectedLabelTextStyle, + this.selectedLabelTextStyle, + this.unselectedIconTheme, + this.selectedIconTheme, + this.groupAlignment, + this.labelType, + this.useIndicator, + this.indicatorColor, + this.indicatorShape, + this.minWidth, + this.minExtendedWidth, + }); + + /// Color to be used for the [NavigationRail]'s background. + final Color? backgroundColor; + + /// The z-coordinate to be used for the [NavigationRail]'s elevation. + final double? elevation; + + /// The style to merge with the default text style for + /// [NavigationRailDestination] labels, when the destination is not selected. + final TextStyle? unselectedLabelTextStyle; + + /// The style to merge with the default text style for + /// [NavigationRailDestination] labels, when the destination is selected. + final TextStyle? selectedLabelTextStyle; + + /// The theme to merge with the default icon theme for + /// [NavigationRailDestination] icons, when the destination is not selected. + final IconThemeData? unselectedIconTheme; + + /// The theme to merge with the default icon theme for + /// [NavigationRailDestination] icons, when the destination is selected. + final IconThemeData? selectedIconTheme; + + /// The alignment for the [NavigationRailDestination]s as they are positioned + /// within the [NavigationRail]. + final double? groupAlignment; + + /// The type that defines the layout and behavior of the labels in the + /// [NavigationRail]. + final NavigationRailLabelType? labelType; + + /// Whether or not the selected [NavigationRailDestination] should include a + /// [NavigationIndicator]. + final bool? useIndicator; + + /// Overrides the default value of [NavigationRail]'s selection indicator color, + /// when [useIndicator] is true. + final Color? indicatorColor; + + /// Overrides the default shape of the [NavigationRail]'s selection indicator. + final ShapeBorder? indicatorShape; + + /// Overrides the default value of [NavigationRail]'s minimum width when it + /// is not extended. + final double? minWidth; + + /// Overrides the default value of [NavigationRail]'s minimum width when it + /// is extended. + final double? minExtendedWidth; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + NavigationRailThemeData copyWith({ + Color? backgroundColor, + double? elevation, + TextStyle? unselectedLabelTextStyle, + TextStyle? selectedLabelTextStyle, + IconThemeData? unselectedIconTheme, + IconThemeData? selectedIconTheme, + double? groupAlignment, + NavigationRailLabelType? labelType, + bool? useIndicator, + Color? indicatorColor, + ShapeBorder? indicatorShape, + double? minWidth, + double? minExtendedWidth, + }) { + return NavigationRailThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + elevation: elevation ?? this.elevation, + unselectedLabelTextStyle: unselectedLabelTextStyle ?? this.unselectedLabelTextStyle, + selectedLabelTextStyle: selectedLabelTextStyle ?? this.selectedLabelTextStyle, + unselectedIconTheme: unselectedIconTheme ?? this.unselectedIconTheme, + selectedIconTheme: selectedIconTheme ?? this.selectedIconTheme, + groupAlignment: groupAlignment ?? this.groupAlignment, + labelType: labelType ?? this.labelType, + useIndicator: useIndicator ?? this.useIndicator, + indicatorColor: indicatorColor ?? this.indicatorColor, + indicatorShape: indicatorShape ?? this.indicatorShape, + minWidth: minWidth ?? this.minWidth, + minExtendedWidth: minExtendedWidth ?? this.minExtendedWidth, + ); + } + + /// Linearly interpolate between two navigation rail themes. + /// + /// If both arguments are null then null is returned. + /// + /// {@macro dart.ui.shadow.lerp} + static NavigationRailThemeData? lerp(NavigationRailThemeData? a, NavigationRailThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return NavigationRailThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + unselectedLabelTextStyle: TextStyle.lerp(a?.unselectedLabelTextStyle, b?.unselectedLabelTextStyle, t), + selectedLabelTextStyle: TextStyle.lerp(a?.selectedLabelTextStyle, b?.selectedLabelTextStyle, t), + unselectedIconTheme: a?.unselectedIconTheme == null && b?.unselectedIconTheme == null + ? null : IconThemeData.lerp(a?.unselectedIconTheme, b?.unselectedIconTheme, t), + selectedIconTheme: a?.selectedIconTheme == null && b?.selectedIconTheme == null + ? null : IconThemeData.lerp(a?.selectedIconTheme, b?.selectedIconTheme, t), + groupAlignment: lerpDouble(a?.groupAlignment, b?.groupAlignment, t), + labelType: t < 0.5 ? a?.labelType : b?.labelType, + useIndicator: t < 0.5 ? a?.useIndicator : b?.useIndicator, + indicatorColor: Color.lerp(a?.indicatorColor, b?.indicatorColor, t), + indicatorShape: ShapeBorder.lerp(a?.indicatorShape, b?.indicatorShape, t), + minWidth: lerpDouble(a?.minWidth, b?.minWidth, t), + minExtendedWidth: lerpDouble(a?.minExtendedWidth, b?.minExtendedWidth, t), + + ); + } + + @override + int get hashCode => Object.hash( + backgroundColor, + elevation, + unselectedLabelTextStyle, + selectedLabelTextStyle, + unselectedIconTheme, + selectedIconTheme, + groupAlignment, + labelType, + useIndicator, + indicatorColor, + indicatorShape, + minWidth, + minExtendedWidth, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is NavigationRailThemeData + && other.backgroundColor == backgroundColor + && other.elevation == elevation + && other.unselectedLabelTextStyle == unselectedLabelTextStyle + && other.selectedLabelTextStyle == selectedLabelTextStyle + && other.unselectedIconTheme == unselectedIconTheme + && other.selectedIconTheme == selectedIconTheme + && other.groupAlignment == groupAlignment + && other.labelType == labelType + && other.useIndicator == useIndicator + && other.indicatorColor == indicatorColor + && other.indicatorShape == indicatorShape + && other.minWidth == minWidth + && other.minExtendedWidth == minExtendedWidth; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + const NavigationRailThemeData defaultData = NavigationRailThemeData(); + + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: defaultData.backgroundColor)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: defaultData.elevation)); + properties.add(DiagnosticsProperty<TextStyle>('unselectedLabelTextStyle', unselectedLabelTextStyle, defaultValue: defaultData.unselectedLabelTextStyle)); + properties.add(DiagnosticsProperty<TextStyle>('selectedLabelTextStyle', selectedLabelTextStyle, defaultValue: defaultData.selectedLabelTextStyle)); + properties.add(DiagnosticsProperty<IconThemeData>('unselectedIconTheme', unselectedIconTheme, defaultValue: defaultData.unselectedIconTheme)); + properties.add(DiagnosticsProperty<IconThemeData>('selectedIconTheme', selectedIconTheme, defaultValue: defaultData.selectedIconTheme)); + properties.add(DoubleProperty('groupAlignment', groupAlignment, defaultValue: defaultData.groupAlignment)); + properties.add(DiagnosticsProperty<NavigationRailLabelType>('labelType', labelType, defaultValue: defaultData.labelType)); + properties.add(DiagnosticsProperty<bool>('useIndicator', useIndicator, defaultValue: defaultData.useIndicator)); + properties.add(ColorProperty('indicatorColor', indicatorColor, defaultValue: defaultData.indicatorColor)); + properties.add(DiagnosticsProperty<ShapeBorder>('indicatorShape', indicatorShape, defaultValue: null)); + properties.add(DoubleProperty('minWidth', minWidth, defaultValue: defaultData.minWidth)); + properties.add(DoubleProperty('minExtendedWidth', minExtendedWidth, defaultValue: defaultData.minExtendedWidth)); + } +} + +/// An inherited widget that defines visual properties for [NavigationRail]s and +/// [NavigationRailDestination]s in this widget's subtree. +/// +/// Values specified here are used for [NavigationRail] properties that are not +/// given an explicit non-null value. +class NavigationRailTheme extends InheritedTheme { + /// Creates a navigation rail theme that controls the + /// [NavigationRailThemeData] properties for a [NavigationRail]. + const NavigationRailTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the background color, elevation, label text style, icon theme, + /// group alignment, and label type and border values for descendant + /// [NavigationRail] widgets. + final NavigationRailThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [NavigationRailTheme] widget, then + /// [ThemeData.navigationRailTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// NavigationRailThemeData theme = NavigationRailTheme.of(context); + /// ``` + static NavigationRailThemeData of(BuildContext context) { + final NavigationRailTheme? navigationRailTheme = context.dependOnInheritedWidgetOfExactType<NavigationRailTheme>(); + return navigationRailTheme?.data ?? Theme.of(context).navigationRailTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return NavigationRailTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(NavigationRailTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/no_splash.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/no_splash.dart new file mode 100644 index 0000000000000000000000000000000000000000..38958a8c70604099a3bc5442204d28e60225e1bb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/no_splash.dart @@ -0,0 +1,80 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'ink_well.dart'; +import 'material.dart'; + +class _NoSplashFactory extends InteractiveInkFeatureFactory { + const _NoSplashFactory(); + + @override + InteractiveInkFeature create({ + required MaterialInkController controller, + required RenderBox referenceBox, + required Offset position, + required Color color, + required TextDirection textDirection, + bool containedInkWell = false, + RectCallback? rectCallback, + BorderRadius? borderRadius, + ShapeBorder? customBorder, + double? radius, + VoidCallback? onRemoved, + }) { + return NoSplash( + controller: controller, + referenceBox: referenceBox, + color: color, + onRemoved: onRemoved, + ); + } +} + +/// An [InteractiveInkFeature] that doesn't paint a splash. +/// +/// Use [NoSplash.splashFactory] to defeat the default ink splash drawn by +/// an [InkWell] or [ButtonStyle]. For example, to create an [ElevatedButton] +/// that does not draw the default "ripple" ink splash when it's tapped: +/// +/// ```dart +/// ElevatedButton( +/// style: ElevatedButton.styleFrom( +/// splashFactory: NoSplash.splashFactory, +/// ), +/// onPressed: () { }, +/// child: const Text('No Splash'), +/// ) +/// ``` +class NoSplash extends InteractiveInkFeature { + /// Create an [InteractiveInkFeature] that doesn't paint a splash. + NoSplash({ + required super.controller, + required super.referenceBox, + required super.color, + super.onRemoved, + }); + + /// Used to specify this type of ink splash for an [InkWell], [InkResponse] + /// material [Theme], or [ButtonStyle]. + static const InteractiveInkFeatureFactory splashFactory = _NoSplashFactory(); + + @override + void paintFeature(Canvas canvas, Matrix4 transform) { + } + + @override + void confirm() { + super.confirm(); + dispose(); + } + + @override + void cancel() { + super.cancel(); + dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/outlined_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/outlined_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..e25cc4bb8b6bf0bb61ce5c97eec6a751d6709cc8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/outlined_button.dart @@ -0,0 +1,572 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'button_style_button.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'ink_ripple.dart'; +import 'ink_well.dart'; +import 'material_state.dart'; +import 'outlined_button_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +/// A Material Design "Outlined Button"; essentially a [TextButton] +/// with an outlined border. +/// +/// Outlined buttons are medium-emphasis buttons. They contain actions +/// that are important, but they aren’t the primary action in an app. +/// +/// An outlined button is a label [child] displayed on a (zero +/// elevation) [Material] widget. The label's [Text] and [Icon] +/// widgets are displayed in the [style]'s +/// [ButtonStyle.foregroundColor] and the outline's weight and color +/// are defined by [ButtonStyle.side]. The button reacts to touches +/// by filling with the [style]'s [ButtonStyle.overlayColor]. +/// +/// The outlined button's default style is defined by [defaultStyleOf]. +/// The style of this outline button can be overridden with its [style] +/// parameter. The style of all text buttons in a subtree can be +/// overridden with the [OutlinedButtonTheme] and the style of all of the +/// outlined buttons in an app can be overridden with the [Theme]'s +/// [ThemeData.outlinedButtonTheme] property. +/// +/// Unlike [TextButton] or [ElevatedButton], outline buttons have a +/// default [ButtonStyle.side] which defines the appearance of the +/// outline. Because the default `side` is non-null, it +/// unconditionally overrides the shape's [OutlinedBorder.side]. In +/// other words, to specify an outlined button's shape _and_ the +/// appearance of its outline, both the [ButtonStyle.shape] and +/// [ButtonStyle.side] properties must be specified. +/// +/// {@tool dartpad} +/// Here is an example of a basic [OutlinedButton]. +/// +/// ** See code in examples/api/lib/material/outlined_button/outlined_button.0.dart ** +/// {@end-tool} +/// +/// The static [styleFrom] method is a convenient way to create a +/// outlined button [ButtonStyle] from simple values. +/// +/// See also: +/// +/// * [ElevatedButton], a filled button whose material elevates when pressed. +/// * [FilledButton], a filled button that doesn't elevate when pressed. +/// * [FilledButton.tonal], a filled button variant that uses a secondary fill color. +/// * [TextButton], a button with no outline or fill color. +/// * <https://material.io/design/components/buttons.html> +/// * <https://m3.material.io/components/buttons> +class OutlinedButton extends ButtonStyleButton { + /// Create an OutlinedButton. + const OutlinedButton({ + super.key, + required super.onPressed, + super.onLongPress, + super.onHover, + super.onFocusChange, + super.style, + super.focusNode, + super.autofocus = false, + super.clipBehavior = Clip.none, + super.statesController, + required super.child, + }); + + /// Create a text button from a pair of widgets that serve as the button's + /// [icon] and [label]. + /// + /// The icon and label are arranged in a row and padded by 12 logical pixels + /// at the start, and 16 at the end, with an 8 pixel gap in between. + factory OutlinedButton.icon({ + Key? key, + required VoidCallback? onPressed, + VoidCallback? onLongPress, + ButtonStyle? style, + FocusNode? focusNode, + bool? autofocus, + Clip? clipBehavior, + MaterialStatesController? statesController, + required Widget icon, + required Widget label, + }) = _OutlinedButtonWithIcon; + + /// A static convenience method that constructs an outlined button + /// [ButtonStyle] given simple values. + /// + /// + /// The [foregroundColor] and [disabledForegroundColor] colors are used + /// to create a [MaterialStateProperty] [ButtonStyle.foregroundColor], and + /// a derived [ButtonStyle.overlayColor]. + /// + /// The [backgroundColor] and [disabledBackgroundColor] colors are + /// used to create a [MaterialStateProperty] [ButtonStyle.backgroundColor]. + /// + /// Similarly, the [enabledMouseCursor] and [disabledMouseCursor] + /// parameters are used to construct [ButtonStyle.mouseCursor]. + /// + /// All of the other parameters are either used directly or used to + /// create a [MaterialStateProperty] with a single value for all + /// states. + /// + /// All parameters default to null, by default this method returns + /// a [ButtonStyle] that doesn't override anything. + /// + /// For example, to override the default shape and outline for an + /// [OutlinedButton], one could write: + /// + /// ```dart + /// OutlinedButton( + /// style: OutlinedButton.styleFrom( + /// shape: const StadiumBorder(), + /// side: const BorderSide(width: 2, color: Colors.green), + /// ), + /// child: const Text('Seasons of Love'), + /// onPressed: () { + /// // ... + /// }, + /// ), + /// ``` + static ButtonStyle styleFrom({ + Color? foregroundColor, + Color? backgroundColor, + Color? disabledForegroundColor, + Color? disabledBackgroundColor, + Color? shadowColor, + Color? surfaceTintColor, + double? elevation, + TextStyle? textStyle, + EdgeInsetsGeometry? padding, + Size? minimumSize, + Size? fixedSize, + Size? maximumSize, + BorderSide? side, + OutlinedBorder? shape, + MouseCursor? enabledMouseCursor, + MouseCursor? disabledMouseCursor, + VisualDensity? visualDensity, + MaterialTapTargetSize? tapTargetSize, + Duration? animationDuration, + bool? enableFeedback, + AlignmentGeometry? alignment, + InteractiveInkFeatureFactory? splashFactory, + }) { + final Color? foreground = foregroundColor; + final Color? disabledForeground = disabledForegroundColor; + final MaterialStateProperty<Color?>? foregroundColorProp = (foreground == null && disabledForeground == null) + ? null + : _OutlinedButtonDefaultColor(foreground, disabledForeground); + final MaterialStateProperty<Color?>? backgroundColorProp = (backgroundColor == null && disabledBackgroundColor == null) + ? null + : disabledBackgroundColor == null + ? ButtonStyleButton.allOrNull<Color?>(backgroundColor) + : _OutlinedButtonDefaultColor(backgroundColor, disabledBackgroundColor); + final MaterialStateProperty<Color?>? overlayColor = (foreground == null) + ? null + : _OutlinedButtonDefaultOverlay(foreground); + final MaterialStateProperty<MouseCursor?> mouseCursor = _OutlinedButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor); + + return ButtonStyle( + textStyle: ButtonStyleButton.allOrNull<TextStyle>(textStyle), + foregroundColor: foregroundColorProp, + backgroundColor: backgroundColorProp, + overlayColor: overlayColor, + shadowColor: ButtonStyleButton.allOrNull<Color>(shadowColor), + surfaceTintColor: ButtonStyleButton.allOrNull<Color>(surfaceTintColor), + elevation: ButtonStyleButton.allOrNull<double>(elevation), + padding: ButtonStyleButton.allOrNull<EdgeInsetsGeometry>(padding), + minimumSize: ButtonStyleButton.allOrNull<Size>(minimumSize), + fixedSize: ButtonStyleButton.allOrNull<Size>(fixedSize), + maximumSize: ButtonStyleButton.allOrNull<Size>(maximumSize), + side: ButtonStyleButton.allOrNull<BorderSide>(side), + shape: ButtonStyleButton.allOrNull<OutlinedBorder>(shape), + mouseCursor: mouseCursor, + visualDensity: visualDensity, + tapTargetSize: tapTargetSize, + animationDuration: animationDuration, + enableFeedback: enableFeedback, + alignment: alignment, + splashFactory: splashFactory, + ); + } + + /// Defines the button's default appearance. + /// + /// With the exception of [ButtonStyle.side], which defines the + /// outline, and [ButtonStyle.padding], the returned style is the + /// same as for [TextButton]. + /// + /// The button [child]'s [Text] and [Icon] widgets are rendered with + /// the [ButtonStyle]'s foreground color. The button's [InkWell] adds + /// the style's overlay color when the button is focused, hovered + /// or pressed. The button's background color becomes its [Material] + /// color and is transparent by default. + /// + /// All of the ButtonStyle's defaults appear below. In this list + /// "Theme.foo" is shorthand for `Theme.of(context).foo`. Color + /// scheme values like "onSurface(0.38)" are shorthand for + /// `onSurface.withOpacity(0.38)`. [MaterialStateProperty] valued + /// properties that are not followed by a sublist have the same + /// value for all states, otherwise the values are as specified for + /// each state and "others" means all other states. + /// + /// The color of the [ButtonStyle.textStyle] is not used, the + /// [ButtonStyle.foregroundColor] is used instead. + /// + /// ## Material 2 defaults + /// + /// * `textStyle` - Theme.textTheme.button + /// * `backgroundColor` - transparent + /// * `foregroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.38) + /// * others - Theme.colorScheme.primary + /// * `overlayColor` + /// * hovered - Theme.colorScheme.primary(0.04) + /// * focused or pressed - Theme.colorScheme.primary(0.12) + /// * `shadowColor` - Theme.shadowColor + /// * `elevation` - 0 + /// * `padding` + /// * `default font size <= 14` - horizontal(16) + /// * `14 < default font size <= 28` - lerp(horizontal(16), horizontal(8)) + /// * `28 < default font size <= 36` - lerp(horizontal(8), horizontal(4)) + /// * `36 < default font size` - horizontal(4) + /// * `minimumSize` - Size(64, 36) + /// * `fixedSize` - null + /// * `maximumSize` - Size.infinite + /// * `side` - BorderSide(width: 1, color: Theme.colorScheme.onSurface(0.12)) + /// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)) + /// * `mouseCursor` + /// * disabled - SystemMouseCursors.basic + /// * others - SystemMouseCursors.click + /// * `visualDensity` - theme.visualDensity + /// * `tapTargetSize` - theme.materialTapTargetSize + /// * `animationDuration` - kThemeChangeDuration + /// * `enableFeedback` - true + /// * `alignment` - Alignment.center + /// * `splashFactory` - InkRipple.splashFactory + /// + /// ## Material 3 defaults + /// + /// If [ThemeData.useMaterial3] is set to true the following defaults will + /// be used: + /// + /// * `textStyle` - Theme.textTheme.labelLarge + /// * `backgroundColor` - transparent + /// * `foregroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.38) + /// * others - Theme.colorScheme.primary + /// * `overlayColor` + /// * hovered - Theme.colorScheme.primary(0.08) + /// * focused or pressed - Theme.colorScheme.primary(0.12) + /// * others - null + /// * `shadowColor` - Colors.transparent, + /// * `surfaceTintColor` - null + /// * `elevation` - 0 + /// * `padding` + /// * `default font size <= 14` - horizontal(24) + /// * `14 < default font size <= 28` - lerp(horizontal(24), horizontal(12)) + /// * `28 < default font size <= 36` - lerp(horizontal(12), horizontal(6)) + /// * `36 < default font size` - horizontal(6) + /// * `minimumSize` - Size(64, 40) + /// * `fixedSize` - null + /// * `maximumSize` - Size.infinite + /// * `side` + /// * disabled - BorderSide(color: Theme.colorScheme.onSurface(0.12)) + /// * others - BorderSide(color: Theme.colorScheme.outline) + /// * `shape` - StadiumBorder() + /// * `mouseCursor` + /// * disabled - SystemMouseCursors.basic + /// * others - SystemMouseCursors.click + /// * `visualDensity` - theme.visualDensity + /// * `tapTargetSize` - theme.materialTapTargetSize + /// * `animationDuration` - kThemeChangeDuration + /// * `enableFeedback` - true + /// * `alignment` - Alignment.center + /// * `splashFactory` - Theme.splashFactory + /// + /// For the [OutlinedButton.icon] factory, the start (generally the left) value of + /// [padding] is reduced from 24 to 16. + @override + ButtonStyle defaultStyleOf(BuildContext context) { + final ThemeData theme = Theme.of(context); + final ColorScheme colorScheme = theme.colorScheme; + + return Theme.of(context).useMaterial3 + ? _OutlinedButtonDefaultsM3(context) + : styleFrom( + foregroundColor: colorScheme.primary, + disabledForegroundColor: colorScheme.onSurface.withOpacity(0.38), + backgroundColor: Colors.transparent, + disabledBackgroundColor: Colors.transparent, + shadowColor: theme.shadowColor, + elevation: 0, + textStyle: theme.textTheme.labelLarge, + padding: _scaledPadding(context), + minimumSize: const Size(64, 36), + maximumSize: Size.infinite, + side: BorderSide( + color: Theme.of(context).colorScheme.onSurface.withOpacity(0.12), + ), + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))), + enabledMouseCursor: SystemMouseCursors.click, + disabledMouseCursor: SystemMouseCursors.basic, + visualDensity: theme.visualDensity, + tapTargetSize: theme.materialTapTargetSize, + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + splashFactory: InkRipple.splashFactory, + ); + } + + @override + ButtonStyle? themeStyleOf(BuildContext context) { + return OutlinedButtonTheme.of(context).style; + } +} + +EdgeInsetsGeometry _scaledPadding(BuildContext context) { + final ThemeData theme = Theme.of(context); + final double padding1x = theme.useMaterial3 ? 24.0 : 16.0; + final double defaultFontSize = theme.textTheme.labelLarge?.fontSize ?? 14.0; + final double effectiveTextScale = MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0; + return ButtonStyleButton.scaledPadding( + EdgeInsets.symmetric(horizontal: padding1x), + EdgeInsets.symmetric(horizontal: padding1x / 2), + EdgeInsets.symmetric(horizontal: padding1x / 2 / 2), + effectiveTextScale, + ); +} + +@immutable +class _OutlinedButtonDefaultColor extends MaterialStateProperty<Color?> with Diagnosticable { + _OutlinedButtonDefaultColor(this.color, this.disabled); + + final Color? color; + final Color? disabled; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabled; + } + return color; + } +} + +@immutable +class _OutlinedButtonDefaultOverlay extends MaterialStateProperty<Color?> with Diagnosticable { + _OutlinedButtonDefaultOverlay(this.foreground); + + final Color foreground; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return foreground.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return foreground.withOpacity(0.04); + } + if (states.contains(MaterialState.focused)) { + return foreground.withOpacity(0.12); + } + return null; + } +} + +@immutable +class _OutlinedButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor?> with Diagnosticable { + _OutlinedButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor); + + final MouseCursor? enabledCursor; + final MouseCursor? disabledCursor; + + @override + MouseCursor? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabledCursor; + } + return enabledCursor; + } +} + +class _OutlinedButtonWithIcon extends OutlinedButton { + _OutlinedButtonWithIcon({ + super.key, + required super.onPressed, + super.onLongPress, + super.style, + super.focusNode, + bool? autofocus, + Clip? clipBehavior, + super.statesController, + required Widget icon, + required Widget label, + }) : super( + autofocus: autofocus ?? false, + clipBehavior: clipBehavior ?? Clip.none, + child: _OutlinedButtonWithIconChild(icon: icon, label: label), + ); + + @override + ButtonStyle defaultStyleOf(BuildContext context) { + final bool useMaterial3 = Theme.of(context).useMaterial3; + if (!useMaterial3) { + return super.defaultStyleOf(context); + } + final ButtonStyle buttonStyle = super.defaultStyleOf(context); + final double defaultFontSize = buttonStyle.textStyle?.resolve(const <MaterialState>{})?.fontSize ?? 14.0; + final double effectiveTextScale = MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0; + final EdgeInsetsGeometry scaledPadding = ButtonStyleButton.scaledPadding( + const EdgeInsetsDirectional.fromSTEB(16, 0, 24, 0), + const EdgeInsetsDirectional.fromSTEB(8, 0, 12, 0), + const EdgeInsetsDirectional.fromSTEB(4, 0, 6, 0), + effectiveTextScale, + ); + return buttonStyle.copyWith( + padding: MaterialStatePropertyAll<EdgeInsetsGeometry>(scaledPadding), + ); + } +} + +class _OutlinedButtonWithIconChild extends StatelessWidget { + const _OutlinedButtonWithIconChild({ + required this.label, + required this.icon, + }); + + final Widget label; + final Widget icon; + + @override + Widget build(BuildContext context) { + final double scale = MediaQuery.textScalerOf(context).textScaleFactor; + final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!; + return Row( + mainAxisSize: MainAxisSize.min, + children: <Widget>[icon, SizedBox(width: gap), Flexible(child: label)], + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - OutlinedButton + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _OutlinedButtonDefaultsM3 extends ButtonStyle { + _OutlinedButtonDefaultsM3(this.context) + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + MaterialStateProperty<TextStyle?> get textStyle => + MaterialStatePropertyAll<TextStyle?>(Theme.of(context).textTheme.labelLarge); + + @override + MaterialStateProperty<Color?>? get backgroundColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<Color?>? get foregroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + return _colors.primary; + }); + + @override + MaterialStateProperty<Color?>? get overlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.primary.withOpacity(0.12); + } + return null; + }); + + @override + MaterialStateProperty<Color>? get shadowColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<Color>? get surfaceTintColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<double>? get elevation => + const MaterialStatePropertyAll<double>(0.0); + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding => + MaterialStatePropertyAll<EdgeInsetsGeometry>(_scaledPadding(context)); + + @override + MaterialStateProperty<Size>? get minimumSize => + const MaterialStatePropertyAll<Size>(Size(64.0, 40.0)); + + // No default fixedSize + + @override + MaterialStateProperty<Size>? get maximumSize => + const MaterialStatePropertyAll<Size>(Size.infinite); + + @override + MaterialStateProperty<BorderSide>? get side => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return BorderSide(color: _colors.onSurface.withOpacity(0.12)); + } + if (states.contains(MaterialState.focused)) { + return BorderSide(color: _colors.primary); + } + return BorderSide(color: _colors.outline); + }); + + @override + MaterialStateProperty<OutlinedBorder>? get shape => + const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); + + @override + MaterialStateProperty<MouseCursor?>? get mouseCursor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return SystemMouseCursors.click; + }); + + @override + VisualDensity? get visualDensity => Theme.of(context).visualDensity; + + @override + MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize; + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; +} + +// END GENERATED TOKEN PROPERTIES - OutlinedButton diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/outlined_button_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/outlined_button_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..724f1e7d4f6016fe4d35dd6f3529e857bd7539eb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/outlined_button_theme.dart @@ -0,0 +1,125 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// A [ButtonStyle] that overrides the default appearance of +/// [OutlinedButton]s when it's used with [OutlinedButtonTheme] or with the +/// overall [Theme]'s [ThemeData.outlinedButtonTheme]. +/// +/// The [style]'s properties override [OutlinedButton]'s default style, +/// i.e. the [ButtonStyle] returned by [OutlinedButton.defaultStyleOf]. Only +/// the style's non-null property values or resolved non-null +/// [MaterialStateProperty] values are used. +/// +/// See also: +/// +/// * [OutlinedButtonTheme], the theme which is configured with this class. +/// * [OutlinedButton.defaultStyleOf], which returns the default [ButtonStyle] +/// for outlined buttons. +/// * [OutlinedButton.styleFrom], which converts simple values into a +/// [ButtonStyle] that's consistent with [OutlinedButton]'s defaults. +/// * [MaterialStateProperty.resolve], "resolve" a material state property +/// to a simple value based on a set of [MaterialState]s. +/// * [ThemeData.outlinedButtonTheme], which can be used to override the default +/// [ButtonStyle] for [OutlinedButton]s below the overall [Theme]. +@immutable +class OutlinedButtonThemeData with Diagnosticable { + /// Creates a [OutlinedButtonThemeData]. + /// + /// The [style] may be null. + const OutlinedButtonThemeData({ this.style }); + + /// Overrides for [OutlinedButton]'s default style. + /// + /// Non-null properties or non-null resolved [MaterialStateProperty] + /// values override the [ButtonStyle] returned by + /// [OutlinedButton.defaultStyleOf]. + /// + /// If [style] is null, then this theme doesn't override anything. + final ButtonStyle? style; + + /// Linearly interpolate between two outlined button themes. + static OutlinedButtonThemeData? lerp(OutlinedButtonThemeData? a, OutlinedButtonThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return OutlinedButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + ); + } + + @override + int get hashCode => style.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is OutlinedButtonThemeData && other.style == style; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ButtonStyle>('style', style, defaultValue: null)); + } +} + +/// Overrides the default [ButtonStyle] of its [OutlinedButton] descendants. +/// +/// See also: +/// +/// * [OutlinedButtonThemeData], which is used to configure this theme. +/// * [OutlinedButton.defaultStyleOf], which returns the default [ButtonStyle] +/// for outlined buttons. +/// * [OutlinedButton.styleFrom], which converts simple values into a +/// [ButtonStyle] that's consistent with [OutlinedButton]'s defaults. +/// * [ThemeData.outlinedButtonTheme], which can be used to override the default +/// [ButtonStyle] for [OutlinedButton]s below the overall [Theme]. +class OutlinedButtonTheme extends InheritedTheme { + /// Create a [OutlinedButtonTheme]. + const OutlinedButtonTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The configuration of this theme. + final OutlinedButtonThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [OutlinedButtonTheme] widget, then + /// [ThemeData.outlinedButtonTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// OutlinedButtonThemeData theme = OutlinedButtonTheme.of(context); + /// ``` + static OutlinedButtonThemeData of(BuildContext context) { + final OutlinedButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<OutlinedButtonTheme>(); + return buttonTheme?.data ?? Theme.of(context).outlinedButtonTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return OutlinedButtonTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(OutlinedButtonTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/page.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/page.dart new file mode 100644 index 0000000000000000000000000000000000000000..db781f53764736cd660929e94ab7c6faa99643eb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/page.dart @@ -0,0 +1,203 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; + +import 'page_transitions_theme.dart'; +import 'theme.dart'; + +/// A modal route that replaces the entire screen with a platform-adaptive +/// transition. +/// +/// {@macro flutter.material.materialRouteTransitionMixin} +/// +/// By default, when a modal route is replaced by another, the previous route +/// remains in memory. To free all the resources when this is not necessary, set +/// [maintainState] to false. +/// +/// The `fullscreenDialog` property specifies whether the incoming route is a +/// fullscreen modal dialog. On iOS, those routes animate from the bottom to the +/// top rather than horizontally. +/// +/// If `barrierDismissible` is true, then pressing the escape key on the keyboard +/// will cause the current route to be popped with null as the value. +/// +/// The type `T` specifies the return type of the route which can be supplied as +/// the route is popped from the stack via [Navigator.pop] by providing the +/// optional `result` argument. +/// +/// See also: +/// +/// * [MaterialRouteTransitionMixin], which provides the material transition +/// for this route. +/// * [MaterialPage], which is a [Page] of this class. +class MaterialPageRoute<T> extends PageRoute<T> with MaterialRouteTransitionMixin<T> { + /// Construct a MaterialPageRoute whose contents are defined by [builder]. + MaterialPageRoute({ + required this.builder, + super.settings, + this.maintainState = true, + super.fullscreenDialog, + super.allowSnapshotting = true, + super.barrierDismissible = false, + }) { + assert(opaque); + } + + /// Builds the primary contents of the route. + final WidgetBuilder builder; + + @override + Widget buildContent(BuildContext context) => builder(context); + + @override + final bool maintainState; + + @override + String get debugLabel => '${super.debugLabel}(${settings.name})'; +} + + +/// A mixin that provides platform-adaptive transitions for a [PageRoute]. +/// +/// {@template flutter.material.materialRouteTransitionMixin} +/// For Android, the entrance transition for the page zooms in and fades in +/// while the exiting page zooms out and fades out. The exit transition is similar, +/// but in reverse. +/// +/// For iOS, the page slides in from the right and exits in reverse. The page +/// also shifts to the left in parallax when another page enters to cover it. +/// (These directions are flipped in environments with a right-to-left reading +/// direction.) +/// {@endtemplate} +/// +/// See also: +/// +/// * [PageTransitionsTheme], which defines the default page transitions used +/// by the [MaterialRouteTransitionMixin.buildTransitions]. +/// * [ZoomPageTransitionsBuilder], which is the default page transition used +/// by the [PageTransitionsTheme]. +/// * [CupertinoPageTransitionsBuilder], which is the default page transition +/// for iOS and macOS. +mixin MaterialRouteTransitionMixin<T> on PageRoute<T> { + /// Builds the primary contents of the route. + @protected + Widget buildContent(BuildContext context); + + @override + Duration get transitionDuration => const Duration(milliseconds: 300); + + @override + Color? get barrierColor => null; + + @override + String? get barrierLabel => null; + + @override + bool canTransitionTo(TransitionRoute<dynamic> nextRoute) { + // Don't perform outgoing animation if the next route is a fullscreen dialog. + return (nextRoute is MaterialRouteTransitionMixin && !nextRoute.fullscreenDialog) + || (nextRoute is CupertinoRouteTransitionMixin && !nextRoute.fullscreenDialog); + } + + @override + Widget buildPage( + BuildContext context, + Animation<double> animation, + Animation<double> secondaryAnimation, + ) { + final Widget result = buildContent(context); + return Semantics( + scopesRoute: true, + explicitChildNodes: true, + child: result, + ); + } + + @override + Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) { + final PageTransitionsTheme theme = Theme.of(context).pageTransitionsTheme; + return theme.buildTransitions<T>(this, context, animation, secondaryAnimation, child); + } +} + +/// A page that creates a material style [PageRoute]. +/// +/// {@macro flutter.material.materialRouteTransitionMixin} +/// +/// By default, when the created route is replaced by another, the previous +/// route remains in memory. To free all the resources when this is not +/// necessary, set [maintainState] to false. +/// +/// The `fullscreenDialog` property specifies whether the created route is a +/// fullscreen modal dialog. On iOS, those routes animate from the bottom to the +/// top rather than horizontally. +/// +/// The type `T` specifies the return type of the route which can be supplied as +/// the route is popped from the stack via [Navigator.transitionDelegate] by +/// providing the optional `result` argument to the +/// [RouteTransitionRecord.markForPop] in the [TransitionDelegate.resolve]. +/// +/// See also: +/// +/// * [MaterialPageRoute], which is the [PageRoute] version of this class +class MaterialPage<T> extends Page<T> { + /// Creates a material page. + const MaterialPage({ + required this.child, + this.maintainState = true, + this.fullscreenDialog = false, + this.allowSnapshotting = true, + super.key, + super.name, + super.arguments, + super.restorationId, + }); + + /// The content to be shown in the [Route] created by this page. + final Widget child; + + /// {@macro flutter.widgets.ModalRoute.maintainState} + final bool maintainState; + + /// {@macro flutter.widgets.PageRoute.fullscreenDialog} + final bool fullscreenDialog; + + /// {@macro flutter.widgets.TransitionRoute.allowSnapshotting} + final bool allowSnapshotting; + + @override + Route<T> createRoute(BuildContext context) { + return _PageBasedMaterialPageRoute<T>(page: this, allowSnapshotting: allowSnapshotting); + } +} + +// A page-based version of MaterialPageRoute. +// +// This route uses the builder from the page to build its content. This ensures +// the content is up to date after page updates. +class _PageBasedMaterialPageRoute<T> extends PageRoute<T> with MaterialRouteTransitionMixin<T> { + _PageBasedMaterialPageRoute({ + required MaterialPage<T> page, + super.allowSnapshotting, + }) : super(settings: page) { + assert(opaque); + } + + MaterialPage<T> get _page => settings as MaterialPage<T>; + + @override + Widget buildContent(BuildContext context) { + return _page.child; + } + + @override + bool get maintainState => _page.maintainState; + + @override + bool get fullscreenDialog => _page.fullscreenDialog; + + @override + String get debugLabel => '${super.debugLabel}(${_page.name})'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/page_transitions_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/page_transitions_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..144f4399fcb34ab89f3b3a235e9e9788b6c09d26 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/page_transitions_theme.dart @@ -0,0 +1,1225 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'colors.dart'; +import 'theme.dart'; + +// Slides the page upwards and fades it in, starting from 1/4 screen +// below the top. The transition is intended to match the default for +// Android O. +class _FadeUpwardsPageTransition extends StatelessWidget { + _FadeUpwardsPageTransition({ + required Animation<double> routeAnimation, // The route's linear 0.0 - 1.0 animation. + required this.child, + }) : _positionAnimation = routeAnimation.drive(_bottomUpTween.chain(_fastOutSlowInTween)), + _opacityAnimation = routeAnimation.drive(_easeInTween); + + // Fractional offset from 1/4 screen below the top to fully on screen. + static final Tween<Offset> _bottomUpTween = Tween<Offset>( + begin: const Offset(0.0, 0.25), + end: Offset.zero, + ); + static final Animatable<double> _fastOutSlowInTween = CurveTween(curve: Curves.fastOutSlowIn); + static final Animatable<double> _easeInTween = CurveTween(curve: Curves.easeIn); + + final Animation<Offset> _positionAnimation; + final Animation<double> _opacityAnimation; + final Widget child; + + @override + Widget build(BuildContext context) { + return SlideTransition( + position: _positionAnimation, + // TODO(ianh): tell the transform to be un-transformed for hit testing + child: FadeTransition( + opacity: _opacityAnimation, + child: child, + ), + ); + } +} + +// This transition is intended to match the default for Android P. +class _OpenUpwardsPageTransition extends StatelessWidget { + const _OpenUpwardsPageTransition({ + required this.animation, + required this.secondaryAnimation, + required this.child, + }); + + // The new page slides upwards just a little as its clip + // rectangle exposes the page from bottom to top. + static final Tween<Offset> _primaryTranslationTween = Tween<Offset>( + begin: const Offset(0.0, 0.05), + end: Offset.zero, + ); + + // The old page slides upwards a little as the new page appears. + static final Tween<Offset> _secondaryTranslationTween = Tween<Offset>( + begin: Offset.zero, + end: const Offset(0.0, -0.025), + ); + + // The scrim obscures the old page by becoming increasingly opaque. + static final Tween<double> _scrimOpacityTween = Tween<double>( + begin: 0.0, + end: 0.25, + ); + + // Used by all of the transition animations. + static const Curve _transitionCurve = Cubic(0.20, 0.00, 0.00, 1.00); + + final Animation<double> animation; + final Animation<double> secondaryAnimation; + final Widget child; + + @override + Widget build(BuildContext context) { + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + final Size size = constraints.biggest; + + final CurvedAnimation primaryAnimation = CurvedAnimation( + parent: animation, + curve: _transitionCurve, + reverseCurve: _transitionCurve.flipped, + ); + + // Gradually expose the new page from bottom to top. + final Animation<double> clipAnimation = Tween<double>( + begin: 0.0, + end: size.height, + ).animate(primaryAnimation); + + final Animation<double> opacityAnimation = _scrimOpacityTween.animate(primaryAnimation); + final Animation<Offset> primaryTranslationAnimation = _primaryTranslationTween.animate(primaryAnimation); + + final Animation<Offset> secondaryTranslationAnimation = _secondaryTranslationTween.animate( + CurvedAnimation( + parent: secondaryAnimation, + curve: _transitionCurve, + reverseCurve: _transitionCurve.flipped, + ), + ); + + return AnimatedBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + return Container( + color: Colors.black.withOpacity(opacityAnimation.value), + alignment: Alignment.bottomLeft, + child: ClipRect( + child: SizedBox( + height: clipAnimation.value, + child: OverflowBox( + alignment: Alignment.bottomLeft, + maxHeight: size.height, + child: child, + ), + ), + ), + ); + }, + child: AnimatedBuilder( + animation: secondaryAnimation, + child: FractionalTranslation( + translation: primaryTranslationAnimation.value, + child: child, + ), + builder: (BuildContext context, Widget? child) { + return FractionalTranslation( + translation: secondaryTranslationAnimation.value, + child: child, + ); + }, + ), + ); + }, + ); + } +} + +// Zooms and fades a new page in, zooming out the previous page. This transition +// is designed to match the Android Q activity transition. +class _ZoomPageTransition extends StatelessWidget { + /// Creates a [_ZoomPageTransition]. + /// + /// The [animation] and [secondaryAnimation] arguments are required and must + /// not be null. + const _ZoomPageTransition({ + required this.animation, + required this.secondaryAnimation, + required this.allowSnapshotting, + required this.allowEnterRouteSnapshotting, + this.child, + }); + + // A curve sequence that is similar to the 'fastOutExtraSlowIn' curve used in + // the native transition. + static final List<TweenSequenceItem<double>> fastOutExtraSlowInTweenSequenceItems = <TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: Tween<double>(begin: 0.0, end: 0.4) + .chain(CurveTween(curve: const Cubic(0.05, 0.0, 0.133333, 0.06))), + weight: 0.166666, + ), + TweenSequenceItem<double>( + tween: Tween<double>(begin: 0.4, end: 1.0) + .chain(CurveTween(curve: const Cubic(0.208333, 0.82, 0.25, 1.0))), + weight: 1.0 - 0.166666, + ), + ]; + static final TweenSequence<double> _scaleCurveSequence = TweenSequence<double>(fastOutExtraSlowInTweenSequenceItems); + + /// The animation that drives the [child]'s entrance and exit. + /// + /// See also: + /// + /// * [TransitionRoute.animation], which is the value given to this property + /// when the [_ZoomPageTransition] is used as a page transition. + final Animation<double> animation; + + /// The animation that transitions [child] when new content is pushed on top + /// of it. + /// + /// See also: + /// + /// * [TransitionRoute.secondaryAnimation], which is the value given to this + /// property when the [_ZoomPageTransition] is used as a page transition. + final Animation<double> secondaryAnimation; + + /// Whether the [SnapshotWidget] will be used. + /// + /// When this value is true, performance is improved by disabling animations + /// on both the outgoing and incoming route. This also implies that ink-splashes + /// or similar animations will not animate during the transition. + /// + /// See also: + /// + /// * [TransitionRoute.allowSnapshotting], which defines whether the route + /// transition will prefer to animate a snapshot of the entering and exiting + /// routes. + final bool allowSnapshotting; + + /// The widget below this widget in the tree. + /// + /// This widget will transition in and out as driven by [animation] and + /// [secondaryAnimation]. + final Widget? child; + + /// Whether to enable snapshotting on the entering route during the + /// transition animation. + /// + /// If not specified, defaults to true. + /// If false, the route snapshotting will not be applied to the route being + /// animating into, e.g. when transitioning from route A to route B, B will + /// not be snapshotted. + final bool allowEnterRouteSnapshotting; + + @override + Widget build(BuildContext context) { + return DualTransitionBuilder( + animation: animation, + forwardBuilder: ( + BuildContext context, + Animation<double> animation, + Widget? child, + ) { + return _ZoomEnterTransition( + animation: animation, + allowSnapshotting: allowSnapshotting && allowEnterRouteSnapshotting, + child: child, + ); + }, + reverseBuilder: ( + BuildContext context, + Animation<double> animation, + Widget? child, + ) { + return _ZoomExitTransition( + animation: animation, + allowSnapshotting: allowSnapshotting, + reverse: true, + child: child, + ); + }, + child: DualTransitionBuilder( + animation: ReverseAnimation(secondaryAnimation), + forwardBuilder: ( + BuildContext context, + Animation<double> animation, + Widget? child, + ) { + return _ZoomEnterTransition( + animation: animation, + allowSnapshotting: allowSnapshotting && allowEnterRouteSnapshotting , + reverse: true, + child: child, + ); + }, + reverseBuilder: ( + BuildContext context, + Animation<double> animation, + Widget? child, + ) { + return _ZoomExitTransition( + animation: animation, + allowSnapshotting: allowSnapshotting, + child: child, + ); + }, + child: child, + ), + ); + } +} + +class _ZoomEnterTransition extends StatefulWidget { + const _ZoomEnterTransition({ + required this.animation, + this.reverse = false, + required this.allowSnapshotting, + this.child, + }); + + final Animation<double> animation; + final Widget? child; + final bool allowSnapshotting; + final bool reverse; + + @override + State<_ZoomEnterTransition> createState() => _ZoomEnterTransitionState(); +} + +class _ZoomEnterTransitionState extends State<_ZoomEnterTransition> with _ZoomTransitionBase<_ZoomEnterTransition> { + // See SnapshotWidget doc comment, this is disabled on web because the HTML backend doesn't + // support this functionality and the canvaskit backend uses a single thread for UI and raster + // work which diminishes the impact of this performance improvement. + @override + bool get useSnapshot => !kIsWeb && widget.allowSnapshotting; + + late _ZoomEnterTransitionPainter delegate; + + static final Animatable<double> _fadeInTransition = Tween<double>( + begin: 0.0, + end: 1.00, + ).chain(CurveTween(curve: const Interval(0.125, 0.250))); + + static final Animatable<double> _scaleDownTransition = Tween<double>( + begin: 1.10, + end: 1.00, + ).chain(_ZoomPageTransition._scaleCurveSequence); + + static final Animatable<double> _scaleUpTransition = Tween<double>( + begin: 0.85, + end: 1.00, + ).chain(_ZoomPageTransition._scaleCurveSequence); + + static final Animatable<double?> _scrimOpacityTween = Tween<double?>( + begin: 0.0, + end: 0.60, + ).chain(CurveTween(curve: const Interval(0.2075, 0.4175))); + + void _updateAnimations() { + fadeTransition = widget.reverse + ? kAlwaysCompleteAnimation + : _fadeInTransition.animate(widget.animation); + + scaleTransition = (widget.reverse + ? _scaleDownTransition + : _scaleUpTransition + ).animate(widget.animation); + + widget.animation.addListener(onAnimationValueChange); + widget.animation.addStatusListener(onAnimationStatusChange); + } + + @override + void initState() { + _updateAnimations(); + delegate = _ZoomEnterTransitionPainter( + reverse: widget.reverse, + fade: fadeTransition, + scale: scaleTransition, + animation: widget.animation, + ); + super.initState(); + } + + @override + void didUpdateWidget(covariant _ZoomEnterTransition oldWidget) { + if (oldWidget.reverse != widget.reverse || oldWidget.animation != widget.animation) { + oldWidget.animation.removeListener(onAnimationValueChange); + oldWidget.animation.removeStatusListener(onAnimationStatusChange); + _updateAnimations(); + delegate.dispose(); + delegate = _ZoomEnterTransitionPainter( + reverse: widget.reverse, + fade: fadeTransition, + scale: scaleTransition, + animation: widget.animation, + ); + } + super.didUpdateWidget(oldWidget); + } + + @override + void dispose() { + widget.animation.removeListener(onAnimationValueChange); + widget.animation.removeStatusListener(onAnimationStatusChange); + delegate.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return SnapshotWidget( + painter: delegate, + controller: controller, + mode: SnapshotMode.permissive, + autoresize: true, + child: widget.child, + ); + } +} + +class _ZoomExitTransition extends StatefulWidget { + const _ZoomExitTransition({ + required this.animation, + this.reverse = false, + required this.allowSnapshotting, + this.child, + }); + + final Animation<double> animation; + final bool allowSnapshotting; + final bool reverse; + final Widget? child; + + @override + State<_ZoomExitTransition> createState() => _ZoomExitTransitionState(); +} + +class _ZoomExitTransitionState extends State<_ZoomExitTransition> with _ZoomTransitionBase<_ZoomExitTransition> { + late _ZoomExitTransitionPainter delegate; + + // See SnapshotWidget doc comment, this is disabled on web because the HTML backend doesn't + // support this functionality and the canvaskit backend uses a single thread for UI and raster + // work which diminishes the impact of this performance improvement. + @override + bool get useSnapshot => !kIsWeb && widget.allowSnapshotting; + + static final Animatable<double> _fadeOutTransition = Tween<double>( + begin: 1.0, + end: 0.0, + ).chain(CurveTween(curve: const Interval(0.0825, 0.2075))); + + static final Animatable<double> _scaleUpTransition = Tween<double>( + begin: 1.00, + end: 1.05, + ).chain(_ZoomPageTransition._scaleCurveSequence); + + static final Animatable<double> _scaleDownTransition = Tween<double>( + begin: 1.00, + end: 0.90, + ).chain(_ZoomPageTransition._scaleCurveSequence); + + void _updateAnimations() { + fadeTransition = widget.reverse + ? _fadeOutTransition.animate(widget.animation) + : kAlwaysCompleteAnimation; + scaleTransition = (widget.reverse + ? _scaleDownTransition + : _scaleUpTransition + ).animate(widget.animation); + + widget.animation.addListener(onAnimationValueChange); + widget.animation.addStatusListener(onAnimationStatusChange); + } + + @override + void initState() { + _updateAnimations(); + delegate = _ZoomExitTransitionPainter( + reverse: widget.reverse, + fade: fadeTransition, + scale: scaleTransition, + animation: widget.animation, + ); + super.initState(); + } + + @override + void didUpdateWidget(covariant _ZoomExitTransition oldWidget) { + if (oldWidget.reverse != widget.reverse || oldWidget.animation != widget.animation) { + oldWidget.animation.removeListener(onAnimationValueChange); + oldWidget.animation.removeStatusListener(onAnimationStatusChange); + _updateAnimations(); + delegate.dispose(); + delegate = _ZoomExitTransitionPainter( + reverse: widget.reverse, + fade: fadeTransition, + scale: scaleTransition, + animation: widget.animation, + ); + } + super.didUpdateWidget(oldWidget); + } + + @override + void dispose() { + widget.animation.removeListener(onAnimationValueChange); + widget.animation.removeStatusListener(onAnimationStatusChange); + delegate.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return SnapshotWidget( + painter: delegate, + controller: controller, + mode: SnapshotMode.permissive, + autoresize: true, + child: widget.child, + ); + } +} + +/// Used by [PageTransitionsTheme] to define a [MaterialPageRoute] page +/// transition animation. +/// +/// Apps can configure the map of builders for [ThemeData.pageTransitionsTheme] +/// to customize the default [MaterialPageRoute] page transition animation +/// for different platforms. +/// +/// See also: +/// +/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android O. +/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android P. +/// * [ZoomPageTransitionsBuilder], which defines the default page transition +/// that's similar to the one provided in Android Q. +/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page +/// transition that matches native iOS page transitions. +abstract class PageTransitionsBuilder { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const PageTransitionsBuilder(); + + /// Wraps the child with one or more transition widgets which define how [route] + /// arrives on and leaves the screen. + /// + /// The [MaterialPageRoute.buildTransitions] method looks up the + /// current [PageTransitionsTheme] with `Theme.of(context).pageTransitionsTheme` + /// and delegates to this method with a [PageTransitionsBuilder] based + /// on the theme's [ThemeData.platform]. + Widget buildTransitions<T>( + PageRoute<T> route, + BuildContext context, + Animation<double> animation, + Animation<double> secondaryAnimation, + Widget child, + ); +} + +/// Used by [PageTransitionsTheme] to define a vertically fading +/// [MaterialPageRoute] page transition animation that looks like +/// the default page transition used on Android O. +/// +/// The animation fades the new page in while translating it upwards, +/// starting from about 25% below the top of the screen. +/// +/// See also: +/// +/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android P. +/// * [ZoomPageTransitionsBuilder], which defines the default page transition +/// that's similar to the one provided in Android Q. +/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page +/// transition that matches native iOS page transitions. +class FadeUpwardsPageTransitionsBuilder extends PageTransitionsBuilder { + /// Constructs a page transition animation that slides the page up. + const FadeUpwardsPageTransitionsBuilder(); + + @override + Widget buildTransitions<T>( + PageRoute<T>? route, + BuildContext? context, + Animation<double> animation, + Animation<double>? secondaryAnimation, + Widget child, + ) { + return _FadeUpwardsPageTransition(routeAnimation: animation, child: child); + } +} + +/// Used by [PageTransitionsTheme] to define a vertical [MaterialPageRoute] page +/// transition animation that looks like the default page transition +/// used on Android P. +/// +/// See also: +/// +/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android O. +/// * [ZoomPageTransitionsBuilder], which defines the default page transition +/// that's similar to the one provided in Android Q. +/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page +/// transition that matches native iOS page transitions. +class OpenUpwardsPageTransitionsBuilder extends PageTransitionsBuilder { + /// Constructs a page transition animation that matches the transition used on + /// Android P. + const OpenUpwardsPageTransitionsBuilder(); + + @override + Widget buildTransitions<T>( + PageRoute<T>? route, + BuildContext? context, + Animation<double> animation, + Animation<double> secondaryAnimation, + Widget child, + ) { + return _OpenUpwardsPageTransition( + animation: animation, + secondaryAnimation: secondaryAnimation, + child: child, + ); + } +} + +/// Used by [PageTransitionsTheme] to define a zooming [MaterialPageRoute] page +/// transition animation that looks like the default page transition used on +/// Android Q. +/// +/// See also: +/// +/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android O. +/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android P. +/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page +/// transition that matches native iOS page transitions. +class ZoomPageTransitionsBuilder extends PageTransitionsBuilder { + /// Constructs a page transition animation that matches the transition used on + /// Android Q. + const ZoomPageTransitionsBuilder({ + this.allowSnapshotting = true, + this.allowEnterRouteSnapshotting = true, + }); + + /// Whether zoom page transitions will prefer to animate a snapshot of the entering + /// and exiting routes. + /// + /// If not specified, defaults to true. + /// + /// When this value is true, zoom page transitions will snapshot the entering and + /// exiting routes. These snapshots are then animated in place of the underlying + /// widgets to improve performance of the transition. + /// + /// Generally this means that animations that occur on the entering/exiting route + /// while the route animation plays may appear frozen - unless they are a hero + /// animation or something that is drawn in a separate overlay. + /// + /// {@tool dartpad} + /// This example shows a [MaterialApp] that disables snapshotting for the zoom + /// transitions on Android. + /// + /// ** See code in examples/api/lib/material/page_transitions_theme/page_transitions_theme.1.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [PageRoute.allowSnapshotting], which enables or disables snapshotting + /// on a per route basis. + final bool allowSnapshotting; + + /// Whether to enable snapshotting on the entering route during the + /// transition animation. + /// + /// If not specified, defaults to true. + /// If false, the route snapshotting will not be applied to the route being + /// animating into, e.g. when transitioning from route A to route B, B will + /// not be snapshotted. + final bool allowEnterRouteSnapshotting; + + // Allows devicelab benchmarks to force disable the snapshotting. This is + // intended to allow us to profile and fix the underlying performance issues + // for the Impeller backend. + static const bool _kProfileForceDisableSnapshotting = bool.fromEnvironment('flutter.benchmarks.force_disable_snapshot'); + + @override + Widget buildTransitions<T>( + PageRoute<T>? route, + BuildContext? context, + Animation<double> animation, + Animation<double> secondaryAnimation, + Widget? child, + ) { + if (_kProfileForceDisableSnapshotting) { + return _ZoomPageTransitionNoCache( + animation: animation, + secondaryAnimation: secondaryAnimation, + child: child, + ); + } + return _ZoomPageTransition( + animation: animation, + secondaryAnimation: secondaryAnimation, + allowSnapshotting: allowSnapshotting && (route?.allowSnapshotting ?? true), + allowEnterRouteSnapshotting: allowEnterRouteSnapshotting, + child: child, + ); + } +} + +/// Used by [PageTransitionsTheme] to define a horizontal [MaterialPageRoute] +/// page transition animation that matches native iOS page transitions. +/// +/// See also: +/// +/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android O. +/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android P. +/// * [ZoomPageTransitionsBuilder], which defines the default page transition +/// that's similar to the one provided in Android Q. +class CupertinoPageTransitionsBuilder extends PageTransitionsBuilder { + /// Constructs a page transition animation that matches the iOS transition. + const CupertinoPageTransitionsBuilder(); + + @override + Widget buildTransitions<T>( + PageRoute<T> route, + BuildContext context, + Animation<double> animation, + Animation<double> secondaryAnimation, + Widget child, + ) { + return CupertinoRouteTransitionMixin.buildPageTransitions<T>(route, context, animation, secondaryAnimation, child); + } +} + +/// Defines the page transition animations used by [MaterialPageRoute] +/// for different [TargetPlatform]s. +/// +/// The [MaterialPageRoute.buildTransitions] method looks up the +/// current [PageTransitionsTheme] with `Theme.of(context).pageTransitionsTheme` +/// and delegates to [buildTransitions]. +/// +/// If a builder with a matching platform is not found, then the +/// [ZoomPageTransitionsBuilder] is used. +/// +/// {@tool dartpad} +/// This example shows a [MaterialApp] that defines a custom [PageTransitionsTheme]. +/// +/// ** See code in examples/api/lib/material/page_transitions_theme/page_transitions_theme.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ThemeData.pageTransitionsTheme], which defines the default page +/// transitions for the overall theme. +/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android O. +/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android P. +/// * [ZoomPageTransitionsBuilder], which defines the default page transition +/// that's similar to the one provided by Android Q. +/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page +/// transition that matches native iOS page transitions. +@immutable +class PageTransitionsTheme with Diagnosticable { + /// Constructs an object that selects a transition based on the platform. + /// + /// By default the list of builders is: [ZoomPageTransitionsBuilder] + /// for [TargetPlatform.android], and [CupertinoPageTransitionsBuilder] for + /// [TargetPlatform.iOS] and [TargetPlatform.macOS]. + const PageTransitionsTheme({ Map<TargetPlatform, PageTransitionsBuilder> builders = _defaultBuilders }) : _builders = builders; + + static const Map<TargetPlatform, PageTransitionsBuilder> _defaultBuilders = <TargetPlatform, PageTransitionsBuilder>{ + TargetPlatform.android: ZoomPageTransitionsBuilder(), + TargetPlatform.iOS: CupertinoPageTransitionsBuilder(), + TargetPlatform.macOS: CupertinoPageTransitionsBuilder(), + }; + + /// The [PageTransitionsBuilder]s supported by this theme. + Map<TargetPlatform, PageTransitionsBuilder> get builders => _builders; + final Map<TargetPlatform, PageTransitionsBuilder> _builders; + + /// Delegates to the builder for the current [ThemeData.platform]. + /// If a builder for the current platform is not found, then the + /// [ZoomPageTransitionsBuilder] is used. + /// + /// [MaterialPageRoute.buildTransitions] delegates to this method. + Widget buildTransitions<T>( + PageRoute<T> route, + BuildContext context, + Animation<double> animation, + Animation<double> secondaryAnimation, + Widget child, + ) { + TargetPlatform platform = Theme.of(context).platform; + + if (CupertinoRouteTransitionMixin.isPopGestureInProgress(route)) { + platform = TargetPlatform.iOS; + } + + final PageTransitionsBuilder matchingBuilder = + builders[platform] ?? const ZoomPageTransitionsBuilder(); + return matchingBuilder.buildTransitions<T>(route, context, animation, secondaryAnimation, child); + } + + // Map the builders to a list with one PageTransitionsBuilder per platform for + // the operator == overload. + List<PageTransitionsBuilder?> _all(Map<TargetPlatform, PageTransitionsBuilder> builders) { + return TargetPlatform.values.map((TargetPlatform platform) => builders[platform]).toList(); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + if (other is PageTransitionsTheme && identical(builders, other.builders)) { + return true; + } + return other is PageTransitionsTheme + && listEquals<PageTransitionsBuilder?>(_all(other.builders), _all(builders)); + } + + @override + int get hashCode => Object.hashAll(_all(builders)); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add( + DiagnosticsProperty<Map<TargetPlatform, PageTransitionsBuilder>>( + 'builders', + builders, + defaultValue: PageTransitionsTheme._defaultBuilders, + ), + ); + } +} + +// Take an image and draw it centered and scaled. The image is already scaled by the [pixelRatio]. +void _drawImageScaledAndCentered(PaintingContext context, ui.Image image, double scale, double opacity, double pixelRatio) { + if (scale <= 0.0 || opacity <= 0.0) { + return; + } + final Paint paint = Paint() + ..filterQuality = ui.FilterQuality.low + ..color = Color.fromRGBO(0, 0, 0, opacity); + final double logicalWidth = image.width / pixelRatio; + final double logicalHeight = image.height / pixelRatio; + final double scaledLogicalWidth = logicalWidth * scale; + final double scaledLogicalHeight = logicalHeight * scale; + final double left = (logicalWidth - scaledLogicalWidth) / 2; + final double top = (logicalHeight - scaledLogicalHeight) / 2; + final Rect dst = Rect.fromLTWH(left, top, scaledLogicalWidth, scaledLogicalHeight); + context.canvas.drawImageRect(image, Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble()), dst, paint); +} + +void _updateScaledTransform(Matrix4 transform, double scale, Size size) { + transform.setIdentity(); + if (scale == 1.0) { + return; + } + transform.scale(scale, scale); + final double dx = ((size.width * scale) - size.width) / 2; + final double dy = ((size.height * scale) - size.height) / 2; + transform.translate(-dx, -dy); +} + +mixin _ZoomTransitionBase<S extends StatefulWidget> on State<S> { + bool get useSnapshot; + + // Don't rasterize if: + // 1. Rasterization is disabled by the platform. + // 2. The animation is paused/stopped. + // 3. The values of the scale/fade transition do not + // benefit from rasterization. + final SnapshotController controller = SnapshotController(); + + late Animation<double> fadeTransition; + late Animation<double> scaleTransition; + + void onAnimationValueChange() { + if ((scaleTransition.value == 1.0) && + (fadeTransition.value == 0.0 || + fadeTransition.value == 1.0)) { + controller.allowSnapshotting = false; + } else { + controller.allowSnapshotting = useSnapshot; + } + } + + void onAnimationStatusChange(AnimationStatus status) { + switch (status) { + case AnimationStatus.dismissed: + case AnimationStatus.completed: + controller.allowSnapshotting = false; + case AnimationStatus.forward: + case AnimationStatus.reverse: + controller.allowSnapshotting = useSnapshot; + } + } + + @override + void dispose() { + controller.dispose(); + super.dispose(); + } +} + +class _ZoomEnterTransitionPainter extends SnapshotPainter { + _ZoomEnterTransitionPainter({ + required this.reverse, + required this.scale, + required this.fade, + required this.animation, + }) { + animation.addListener(notifyListeners); + animation.addStatusListener(_onStatusChange); + scale.addListener(notifyListeners); + fade.addListener(notifyListeners); + } + + void _onStatusChange(_) { + notifyListeners(); + } + + final bool reverse; + final Animation<double> animation; + final Animation<double> scale; + final Animation<double> fade; + + final Matrix4 _transform = Matrix4.zero(); + final LayerHandle<OpacityLayer> _opacityHandle = LayerHandle<OpacityLayer>(); + final LayerHandle<TransformLayer> _transformHandler = LayerHandle<TransformLayer>(); + + void _drawScrim(PaintingContext context, Offset offset, Size size) { + double scrimOpacity = 0.0; + // The transition's scrim opacity only increases on the forward transition. + // In the reverse transition, the opacity should always be 0.0. + // + // Therefore, we need to only apply the scrim opacity animation when + // the transition is running forwards. + // + // The reason that we check that the animation's status is not `completed` + // instead of checking that it is `forward` is that this allows + // the interrupted reversal of the forward transition to smoothly fade + // the scrim away. This prevents a disjointed removal of the scrim. + if (!reverse && animation.status != AnimationStatus.completed) { + scrimOpacity = _ZoomEnterTransitionState._scrimOpacityTween.evaluate(animation)!; + } + assert(!reverse || scrimOpacity == 0.0); + if (scrimOpacity > 0.0) { + context.canvas.drawRect( + offset & size, + Paint()..color = Colors.black.withOpacity(scrimOpacity), + ); + } + } + + @override + void paint(PaintingContext context, ui.Offset offset, Size size, PaintingContextCallback painter) { + switch (animation.status) { + case AnimationStatus.completed: + case AnimationStatus.dismissed: + return painter(context, offset); + case AnimationStatus.forward: + case AnimationStatus.reverse: + } + + _drawScrim(context, offset, size); + _updateScaledTransform(_transform, scale.value, size); + _transformHandler.layer = context.pushTransform(true, offset, _transform, (PaintingContext context, Offset offset) { + _opacityHandle.layer = context.pushOpacity(offset, (fade.value * 255).round(), painter, oldLayer: _opacityHandle.layer); + }, oldLayer: _transformHandler.layer); + } + + @override + void paintSnapshot(PaintingContext context, Offset offset, Size size, ui.Image image, Size sourceSize, double pixelRatio) { + _drawScrim(context, offset, size); + _drawImageScaledAndCentered(context, image, scale.value, fade.value, pixelRatio); + } + + @override + void dispose() { + animation.removeListener(notifyListeners); + animation.removeStatusListener(_onStatusChange); + scale.removeListener(notifyListeners); + fade.removeListener(notifyListeners); + _opacityHandle.layer = null; + _transformHandler.layer = null; + super.dispose(); + } + + @override + bool shouldRepaint(covariant _ZoomEnterTransitionPainter oldDelegate) { + return oldDelegate.reverse != reverse + || oldDelegate.animation.value != animation.value + || oldDelegate.scale.value != scale.value + || oldDelegate.fade.value != fade.value; + } +} + +class _ZoomExitTransitionPainter extends SnapshotPainter { + _ZoomExitTransitionPainter({ + required this.reverse, + required this.scale, + required this.fade, + required this.animation, + }) { + scale.addListener(notifyListeners); + fade.addListener(notifyListeners); + animation.addStatusListener(_onStatusChange); + } + + void _onStatusChange(_) { + notifyListeners(); + } + + final bool reverse; + final Animation<double> scale; + final Animation<double> fade; + final Animation<double> animation; + final Matrix4 _transform = Matrix4.zero(); + final LayerHandle<OpacityLayer> _opacityHandle = LayerHandle<OpacityLayer>(); + final LayerHandle<TransformLayer> _transformHandler = LayerHandle<TransformLayer>(); + + @override + void paintSnapshot(PaintingContext context, Offset offset, Size size, ui.Image image, Size sourceSize, double pixelRatio) { + _drawImageScaledAndCentered(context, image, scale.value, fade.value, pixelRatio); + } + + @override + void paint(PaintingContext context, ui.Offset offset, Size size, PaintingContextCallback painter) { + switch (animation.status) { + case AnimationStatus.completed: + case AnimationStatus.dismissed: + return painter(context, offset); + case AnimationStatus.forward: + case AnimationStatus.reverse: + break; + } + + _updateScaledTransform(_transform, scale.value, size); + _transformHandler.layer = context.pushTransform(true, offset, _transform, (PaintingContext context, Offset offset) { + _opacityHandle.layer = context.pushOpacity(offset, (fade.value * 255).round(), painter, oldLayer: _opacityHandle.layer); + }, oldLayer: _transformHandler.layer); + } + + @override + bool shouldRepaint(covariant _ZoomExitTransitionPainter oldDelegate) { + return oldDelegate.reverse != reverse + || oldDelegate.fade.value != fade.value + || oldDelegate.scale.value != scale.value; + } + + @override + void dispose() { + _opacityHandle.layer = null; + _transformHandler.layer = null; + scale.removeListener(notifyListeners); + fade.removeListener(notifyListeners); + animation.removeStatusListener(_onStatusChange); + super.dispose(); + } +} + +// Zooms and fades a new page in, zooming out the previous page. This transition +// is designed to match the Android Q activity transition. +// +// This was the historical implementation of the cacheless zoom page transition +// that was too slow to run on the Skia backend. This is being benchmarked on +// the Impeller backend so that we can improve performance enough to restore +// the default behavior. +class _ZoomPageTransitionNoCache extends StatelessWidget { + /// Creates a [_ZoomPageTransitionNoCache]. + /// + /// The [animation] and [secondaryAnimation] argument are required and must + /// not be null. + const _ZoomPageTransitionNoCache({ + required this.animation, + required this.secondaryAnimation, + this.child, + }); + + /// The animation that drives the [child]'s entrance and exit. + /// + /// See also: + /// + /// * [TransitionRoute.animation], which is the value given to this property + /// when the [_ZoomPageTransition] is used as a page transition. + final Animation<double> animation; + + /// The animation that transitions [child] when new content is pushed on top + /// of it. + /// + /// See also: + /// + /// * [TransitionRoute.secondaryAnimation], which is the value given to this + /// property when the [_ZoomPageTransition] is used as a page transition. + final Animation<double> secondaryAnimation; + + /// The widget below this widget in the tree. + /// + /// This widget will transition in and out as driven by [animation] and + /// [secondaryAnimation]. + final Widget? child; + + @override + Widget build(BuildContext context) { + return DualTransitionBuilder( + animation: animation, + forwardBuilder: ( + BuildContext context, + Animation<double> animation, + Widget? child, + ) { + return _ZoomEnterTransitionNoCache( + animation: animation, + child: child, + ); + }, + reverseBuilder: ( + BuildContext context, + Animation<double> animation, + Widget? child, + ) { + return _ZoomExitTransitionNoCache( + animation: animation, + reverse: true, + child: child, + ); + }, + child: DualTransitionBuilder( + animation: ReverseAnimation(secondaryAnimation), + forwardBuilder: ( + BuildContext context, + Animation<double> animation, + Widget? child, + ) { + return _ZoomEnterTransitionNoCache( + animation: animation, + reverse: true, + child: child, + ); + }, + reverseBuilder: ( + BuildContext context, + Animation<double> animation, + Widget? child, + ) { + return _ZoomExitTransitionNoCache( + animation: animation, + child: child, + ); + }, + child: child, + ), + ); + } +} + +class _ZoomEnterTransitionNoCache extends StatelessWidget { + const _ZoomEnterTransitionNoCache({ + required this.animation, + this.reverse = false, + this.child, + }); + + final Animation<double> animation; + final Widget? child; + final bool reverse; + + @override + Widget build(BuildContext context) { + double opacity = 0; + // The transition's scrim opacity only increases on the forward transition. + // In the reverse transition, the opacity should always be 0.0. + // + // Therefore, we need to only apply the scrim opacity animation when + // the transition is running forwards. + // + // The reason that we check that the animation's status is not `completed` + // instead of checking that it is `forward` is that this allows + // the interrupted reversal of the forward transition to smoothly fade + // the scrim away. This prevents a disjointed removal of the scrim. + if (!reverse && animation.status != AnimationStatus.completed) { + opacity = _ZoomEnterTransitionState._scrimOpacityTween.evaluate(animation)!; + } + + final Animation<double> fadeTransition = reverse + ? kAlwaysCompleteAnimation + : _ZoomEnterTransitionState._fadeInTransition.animate(animation); + + final Animation<double> scaleTransition = (reverse + ? _ZoomEnterTransitionState._scaleDownTransition + : _ZoomEnterTransitionState._scaleUpTransition + ).animate(animation); + + return AnimatedBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + return ColoredBox( + color: Colors.black.withOpacity(opacity), + child: child, + ); + }, + child: FadeTransition( + opacity: fadeTransition, + child: ScaleTransition( + scale: scaleTransition, + filterQuality: FilterQuality.none, + child: child, + ), + ), + ); + } +} + +class _ZoomExitTransitionNoCache extends StatelessWidget { + const _ZoomExitTransitionNoCache({ + required this.animation, + this.reverse = false, + this.child, + }); + + final Animation<double> animation; + final bool reverse; + final Widget? child; + + @override + Widget build(BuildContext context) { + final Animation<double> fadeTransition = reverse + ? _ZoomExitTransitionState._fadeOutTransition.animate(animation) + : kAlwaysCompleteAnimation; + final Animation<double> scaleTransition = (reverse + ? _ZoomExitTransitionState._scaleDownTransition + : _ZoomExitTransitionState._scaleUpTransition + ).animate(animation); + + return FadeTransition( + opacity: fadeTransition, + child: ScaleTransition( + scale: scaleTransition, + filterQuality: FilterQuality.none, + child: child, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/paginated_data_table.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/paginated_data_table.dart new file mode 100644 index 0000000000000000000000000000000000000000..6bcdbc770c6cac2f899c638a7d74819d9a33cb9e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/paginated_data_table.dart @@ -0,0 +1,648 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/gestures.dart' show DragStartBehavior; +import 'package:flutter/widgets.dart'; + +import 'card.dart'; +import 'constants.dart'; +import 'data_table.dart'; +import 'data_table_source.dart'; +import 'debug.dart'; +import 'dropdown.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'ink_decoration.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'progress_indicator.dart'; +import 'theme.dart'; + +/// A Material Design data table that shows data using multiple pages. +/// +/// A paginated data table shows [rowsPerPage] rows of data per page and +/// provides controls for showing other pages. +/// +/// Data is read lazily from a [DataTableSource]. The widget is presented +/// as a [Card]. +/// +/// If the [key] is a [PageStorageKey], the [initialFirstRowIndex] is persisted +/// to [PageStorage]. +/// +/// {@tool dartpad} +/// +/// This sample shows how to display a [DataTable] with three columns: name, +/// age, and role. The columns are defined by three [DataColumn] objects. The +/// table contains three rows of data for three example users, the data for +/// which is defined by three [DataRow] objects. +/// +/// ** See code in examples/api/lib/material/paginated_data_table/paginated_data_table.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// +/// This example shows how paginated data tables can supported sorted data. +/// +/// ** See code in examples/api/lib/material/paginated_data_table/paginated_data_table.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [DataTable], which is not paginated. +/// * <https://material.io/go/design-data-tables#data-tables-tables-within-cards> +class PaginatedDataTable extends StatefulWidget { + /// Creates a widget describing a paginated [DataTable] on a [Card]. + /// + /// The [header] should give the card's header, typically a [Text] widget. + /// + /// The [columns] argument must be a list of as many [DataColumn] objects as + /// the table is to have columns, ignoring the leading checkbox column if any. + /// The [columns] argument must have a length greater than zero and cannot be + /// null. + /// + /// If the table is sorted, the column that provides the current primary key + /// should be specified by index in [sortColumnIndex], 0 meaning the first + /// column in [columns], 1 being the next one, and so forth. + /// + /// The actual sort order can be specified using [sortAscending]; if the sort + /// order is ascending, this should be true (the default), otherwise it should + /// be false. + /// + /// The [source] should be a long-lived [DataTableSource]. The same source + /// should be provided each time a particular [PaginatedDataTable] widget is + /// created; avoid creating a new [DataTableSource] with each new instance of + /// the [PaginatedDataTable] widget unless the data table really is to now + /// show entirely different data from a new source. + /// + /// Themed by [DataTableTheme]. [DataTableThemeData.decoration] is ignored. + /// To modify the border or background color of the [PaginatedDataTable], use + /// [CardTheme], since a [Card] wraps the inner [DataTable]. + PaginatedDataTable({ + super.key, + this.header, + this.actions, + required this.columns, + this.sortColumnIndex, + this.sortAscending = true, + this.onSelectAll, + @Deprecated( + 'Migrate to use dataRowMinHeight and dataRowMaxHeight instead. ' + 'This feature was deprecated after v3.7.0-5.0.pre.', + ) + double? dataRowHeight, + double? dataRowMinHeight, + double? dataRowMaxHeight, + this.headingRowHeight = 56.0, + this.horizontalMargin = 24.0, + this.columnSpacing = 56.0, + this.showCheckboxColumn = true, + this.showFirstLastButtons = false, + this.initialFirstRowIndex = 0, + this.onPageChanged, + this.rowsPerPage = defaultRowsPerPage, + this.availableRowsPerPage = const <int>[defaultRowsPerPage, defaultRowsPerPage * 2, defaultRowsPerPage * 5, defaultRowsPerPage * 10], + this.onRowsPerPageChanged, + this.dragStartBehavior = DragStartBehavior.start, + this.arrowHeadColor, + required this.source, + this.checkboxHorizontalMargin, + this.controller, + this.primary, + this.headingRowColor, + this.showEmptyRows = true, + }) : assert(actions == null || (header != null)), + assert(columns.isNotEmpty), + assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)), + assert(dataRowMinHeight == null || dataRowMaxHeight == null || dataRowMaxHeight >= dataRowMinHeight), + assert(dataRowHeight == null || (dataRowMinHeight == null && dataRowMaxHeight == null), + 'dataRowHeight ($dataRowHeight) must not be set if dataRowMinHeight ($dataRowMinHeight) or dataRowMaxHeight ($dataRowMaxHeight) are set.'), + dataRowMinHeight = dataRowHeight ?? dataRowMinHeight, + dataRowMaxHeight = dataRowHeight ?? dataRowMaxHeight, + assert(rowsPerPage > 0), + assert(() { + if (onRowsPerPageChanged != null) { + assert(availableRowsPerPage.contains(rowsPerPage)); + } + return true; + }()), + assert(!(controller != null && (primary ?? false)), + 'Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. ' + 'You cannot both set primary to true and pass an explicit controller.', + ); + + /// The table card's optional header. + /// + /// This is typically a [Text] widget, but can also be a [Row] of + /// [TextButton]s. To show icon buttons at the top end side of the table with + /// a header, set the [actions] property. + /// + /// If items in the table are selectable, then, when the selection is not + /// empty, the header is replaced by a count of the selected items. The + /// [actions] are still visible when items are selected. + final Widget? header; + + /// Icon buttons to show at the top end side of the table. The [header] must + /// not be null to show the actions. + /// + /// Typically, the exact actions included in this list will vary based on + /// whether any rows are selected or not. + /// + /// These should be size 24.0 with default padding (8.0). + final List<Widget>? actions; + + /// The configuration and labels for the columns in the table. + final List<DataColumn> columns; + + /// The current primary sort key's column. + /// + /// See [DataTable.sortColumnIndex] for details. + /// + /// The direction of the sort is specified using [sortAscending]. + final int? sortColumnIndex; + + /// Whether the column mentioned in [sortColumnIndex], if any, is sorted + /// in ascending order. + /// + /// See [DataTable.sortAscending] for details. + final bool sortAscending; + + /// Invoked when the user selects or unselects every row, using the + /// checkbox in the heading row. + /// + /// See [DataTable.onSelectAll]. + final ValueSetter<bool?>? onSelectAll; + + /// The height of each row (excluding the row that contains column headings). + /// + /// This value is optional and defaults to kMinInteractiveDimension if not + /// specified. + @Deprecated( + 'Migrate to use dataRowMinHeight and dataRowMaxHeight instead. ' + 'This feature was deprecated after v3.7.0-5.0.pre.', + ) + double? get dataRowHeight => dataRowMinHeight == dataRowMaxHeight ? dataRowMinHeight : null; + + /// The minimum height of each row (excluding the row that contains column headings). + /// + /// This value is optional and defaults to [kMinInteractiveDimension] if not + /// specified. + final double? dataRowMinHeight; + + /// The maximum height of each row (excluding the row that contains column headings). + /// + /// This value is optional and defaults to [kMinInteractiveDimension] if not + /// specified. + final double? dataRowMaxHeight; + + /// The height of the heading row. + /// + /// This value is optional and defaults to 56.0 if not specified. + final double headingRowHeight; + + /// The horizontal margin between the edges of the table and the content + /// in the first and last cells of each row. + /// + /// When a checkbox is displayed, it is also the margin between the checkbox + /// the content in the first data column. + /// + /// This value defaults to 24.0 to adhere to the Material Design specifications. + /// + /// If [checkboxHorizontalMargin] is null, then [horizontalMargin] is also the + /// margin between the edge of the table and the checkbox, as well as the + /// margin between the checkbox and the content in the first data column. + final double horizontalMargin; + + /// The horizontal margin between the contents of each data column. + /// + /// This value defaults to 56.0 to adhere to the Material Design specifications. + final double columnSpacing; + + /// {@macro flutter.material.dataTable.showCheckboxColumn} + final bool showCheckboxColumn; + + /// Flag to display the pagination buttons to go to the first and last pages. + final bool showFirstLastButtons; + + /// The index of the first row to display when the widget is first created. + final int? initialFirstRowIndex; + + /// Invoked when the user switches to another page. + /// + /// The value is the index of the first row on the currently displayed page. + final ValueChanged<int>? onPageChanged; + + /// The number of rows to show on each page. + /// + /// See also: + /// + /// * [onRowsPerPageChanged] + /// * [defaultRowsPerPage] + final int rowsPerPage; + + /// The default value for [rowsPerPage]. + /// + /// Useful when initializing the field that will hold the current + /// [rowsPerPage], when implemented [onRowsPerPageChanged]. + static const int defaultRowsPerPage = 10; + + /// The options to offer for the rowsPerPage. + /// + /// The current [rowsPerPage] must be a value in this list. + /// + /// The values in this list should be sorted in ascending order. + final List<int> availableRowsPerPage; + + /// Invoked when the user selects a different number of rows per page. + /// + /// If this is null, then the value given by [rowsPerPage] will be used + /// and no affordance will be provided to change the value. + final ValueChanged<int?>? onRowsPerPageChanged; + + /// The data source which provides data to show in each row. + /// + /// This object should generally have a lifetime longer than the + /// [PaginatedDataTable] widget itself; it should be reused each time the + /// [PaginatedDataTable] constructor is called. + final DataTableSource source; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// Horizontal margin around the checkbox, if it is displayed. + /// + /// If null, then [horizontalMargin] is used as the margin between the edge + /// of the table and the checkbox, as well as the margin between the checkbox + /// and the content in the first data column. This value defaults to 24.0. + final double? checkboxHorizontalMargin; + + /// Defines the color of the arrow heads in the footer. + final Color? arrowHeadColor; + + /// {@macro flutter.widgets.scroll_view.controller} + final ScrollController? controller; + + /// {@macro flutter.widgets.scroll_view.primary} + final bool? primary; + + /// {@macro flutter.material.dataTable.headingRowColor} + final MaterialStateProperty<Color?>? headingRowColor; + + /// Controls the visibility of empty rows on the last page of a + /// [PaginatedDataTable]. + /// + /// Defaults to `true`, which means empty rows will be populated on the + /// last page of the table if there is not enough content. + /// When set to `false`, empty rows will not be created. + final bool showEmptyRows; + + @override + PaginatedDataTableState createState() => PaginatedDataTableState(); +} + +/// Holds the state of a [PaginatedDataTable]. +/// +/// The table can be programmatically paged using the [pageTo] method. +class PaginatedDataTableState extends State<PaginatedDataTable> { + late int _firstRowIndex; + late int _rowCount; + late bool _rowCountApproximate; + int _selectedRowCount = 0; + final Map<int, DataRow?> _rows = <int, DataRow?>{}; + + @override + void initState() { + super.initState(); + _firstRowIndex = PageStorage.maybeOf(context)?.readState(context) as int? ?? widget.initialFirstRowIndex ?? 0; + widget.source.addListener(_handleDataSourceChanged); + _handleDataSourceChanged(); + } + + @override + void didUpdateWidget(PaginatedDataTable oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.source != widget.source) { + oldWidget.source.removeListener(_handleDataSourceChanged); + widget.source.addListener(_handleDataSourceChanged); + _updateCaches(); + } + } + + @override + void reassemble() { + super.reassemble(); + // This function is called during hot reload. + // + // Normally, if the data source changes, it would notify its listeners and + // thus trigger _handleDataSourceChanged(), which clears the row cache and + // causes the widget to rebuild. + // + // During a hot reload, though, a data source can change in ways that will + // invalidate the row cache (e.g. adding or removing columns) without ever + // triggering a notification, leaving the PaginatedDataTable in an invalid + // state. This method handles this case by clearing the cache any time the + // widget is involved in a hot reload. + _updateCaches(); + } + + @override + void dispose() { + widget.source.removeListener(_handleDataSourceChanged); + super.dispose(); + } + + void _handleDataSourceChanged() { + setState(_updateCaches); + } + + void _updateCaches() { + _rowCount = widget.source.rowCount; + _rowCountApproximate = widget.source.isRowCountApproximate; + _selectedRowCount = widget.source.selectedRowCount; + _rows.clear(); + } + + /// Ensures that the given row is visible. + void pageTo(int rowIndex) { + final int oldFirstRowIndex = _firstRowIndex; + setState(() { + final int rowsPerPage = widget.rowsPerPage; + _firstRowIndex = (rowIndex ~/ rowsPerPage) * rowsPerPage; + }); + if ((widget.onPageChanged != null) && + (oldFirstRowIndex != _firstRowIndex)) { + widget.onPageChanged!(_firstRowIndex); + } + } + + DataRow _getBlankRowFor(int index) { + return DataRow.byIndex( + index: index, + cells: widget.columns.map<DataCell>((DataColumn column) => DataCell.empty).toList(), + ); + } + + DataRow _getProgressIndicatorRowFor(int index) { + bool haveProgressIndicator = false; + final List<DataCell> cells = widget.columns.map<DataCell>((DataColumn column) { + if (!column.numeric) { + haveProgressIndicator = true; + return const DataCell(CircularProgressIndicator()); + } + return DataCell.empty; + }).toList(); + if (!haveProgressIndicator) { + haveProgressIndicator = true; + cells[0] = const DataCell(CircularProgressIndicator()); + } + return DataRow.byIndex( + index: index, + cells: cells, + ); + } + + List<DataRow> _getRows(int firstRowIndex, int rowsPerPage) { + final List<DataRow> result = <DataRow>[]; + final int nextPageFirstRowIndex = firstRowIndex + rowsPerPage; + bool haveProgressIndicator = false; + for (int index = firstRowIndex; index < nextPageFirstRowIndex; index += 1) { + DataRow? row; + if (index < _rowCount || _rowCountApproximate) { + row = _rows.putIfAbsent(index, () => widget.source.getRow(index)); + if (row == null && !haveProgressIndicator) { + row ??= _getProgressIndicatorRowFor(index); + haveProgressIndicator = true; + } + } + + if (widget.showEmptyRows) { + row ??= _getBlankRowFor(index); + } + + if (row != null) { + result.add(row); + } + } + return result; + } + + void _handleFirst() { + pageTo(0); + } + + void _handlePrevious() { + pageTo(math.max(_firstRowIndex - widget.rowsPerPage, 0)); + } + + void _handleNext() { + pageTo(_firstRowIndex + widget.rowsPerPage); + } + + void _handleLast() { + pageTo(((_rowCount - 1) / widget.rowsPerPage).floor() * widget.rowsPerPage); + } + + bool _isNextPageUnavailable() => !_rowCountApproximate && + (_firstRowIndex + widget.rowsPerPage >= _rowCount); + + final GlobalKey _tableKey = GlobalKey(); + + @override + Widget build(BuildContext context) { + // TODO(ianh): This whole build function doesn't handle RTL yet. + assert(debugCheckHasMaterialLocalizations(context)); + final ThemeData themeData = Theme.of(context); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + // HEADER + final List<Widget> headerWidgets = <Widget>[]; + if (_selectedRowCount == 0 && widget.header != null) { + headerWidgets.add(Expanded(child: widget.header!)); + } else if (widget.header != null) { + headerWidgets.add(Expanded( + child: Text(localizations.selectedRowCountTitle(_selectedRowCount)), + )); + } + if (widget.actions != null) { + headerWidgets.addAll( + widget.actions!.map<Widget>((Widget action) { + return Padding( + // 8.0 is the default padding of an icon button + padding: const EdgeInsetsDirectional.only(start: 24.0 - 8.0 * 2.0), + child: action, + ); + }).toList(), + ); + } + + // FOOTER + final TextStyle? footerTextStyle = themeData.textTheme.bodySmall; + final List<Widget> footerWidgets = <Widget>[]; + if (widget.onRowsPerPageChanged != null) { + final List<Widget> availableRowsPerPage = widget.availableRowsPerPage + .where((int value) => value <= _rowCount || value == widget.rowsPerPage) + .map<DropdownMenuItem<int>>((int value) { + return DropdownMenuItem<int>( + value: value, + child: Text('$value'), + ); + }) + .toList(); + footerWidgets.addAll(<Widget>[ + Container(width: 14.0), // to match trailing padding in case we overflow and end up scrolling + Text(localizations.rowsPerPageTitle), + ConstrainedBox( + constraints: const BoxConstraints(minWidth: 64.0), // 40.0 for the text, 24.0 for the icon + child: Align( + alignment: AlignmentDirectional.centerEnd, + child: DropdownButtonHideUnderline( + child: DropdownButton<int>( + items: availableRowsPerPage.cast<DropdownMenuItem<int>>(), + value: widget.rowsPerPage, + onChanged: widget.onRowsPerPageChanged, + style: footerTextStyle, + ), + ), + ), + ), + ]); + } + footerWidgets.addAll(<Widget>[ + Container(width: 32.0), + Text( + localizations.pageRowsInfoTitle( + _firstRowIndex + 1, + math.min(_firstRowIndex + widget.rowsPerPage, _rowCount), + _rowCount, + _rowCountApproximate, + ), + ), + Container(width: 32.0), + if (widget.showFirstLastButtons) + IconButton( + icon: Icon(Icons.skip_previous, color: widget.arrowHeadColor), + padding: EdgeInsets.zero, + tooltip: localizations.firstPageTooltip, + onPressed: _firstRowIndex <= 0 ? null : _handleFirst, + ), + IconButton( + icon: Icon(Icons.chevron_left, color: widget.arrowHeadColor), + padding: EdgeInsets.zero, + tooltip: localizations.previousPageTooltip, + onPressed: _firstRowIndex <= 0 ? null : _handlePrevious, + ), + Container(width: 24.0), + IconButton( + icon: Icon(Icons.chevron_right, color: widget.arrowHeadColor), + padding: EdgeInsets.zero, + tooltip: localizations.nextPageTooltip, + onPressed: _isNextPageUnavailable() ? null : _handleNext, + ), + if (widget.showFirstLastButtons) + IconButton( + icon: Icon(Icons.skip_next, color: widget.arrowHeadColor), + padding: EdgeInsets.zero, + tooltip: localizations.lastPageTooltip, + onPressed: _isNextPageUnavailable() + ? null + : _handleLast, + ), + Container(width: 14.0), + ]); + + // CARD + return Card( + semanticContainer: false, + child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + if (headerWidgets.isNotEmpty) + Semantics( + container: true, + child: DefaultTextStyle( + // These typographic styles aren't quite the regular ones. We pick the closest ones from the regular + // list and then tweak them appropriately. + // See https://material.io/design/components/data-tables.html#tables-within-cards + style: _selectedRowCount > 0 ? themeData.textTheme.titleMedium!.copyWith(color: themeData.colorScheme.secondary) + : themeData.textTheme.titleLarge!.copyWith(fontWeight: FontWeight.w400), + child: IconTheme.merge( + data: const IconThemeData( + opacity: 0.54, + ), + child: Ink( + height: 64.0, + color: _selectedRowCount > 0 ? themeData.secondaryHeaderColor : null, + child: Padding( + padding: const EdgeInsetsDirectional.only(start: 24, end: 14.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: headerWidgets, + ), + ), + ), + ), + ), + ), + SingleChildScrollView( + scrollDirection: Axis.horizontal, + primary: widget.primary, + controller: widget.controller, + dragStartBehavior: widget.dragStartBehavior, + child: ConstrainedBox( + constraints: BoxConstraints(minWidth: constraints.minWidth), + child: DataTable( + key: _tableKey, + columns: widget.columns, + sortColumnIndex: widget.sortColumnIndex, + sortAscending: widget.sortAscending, + onSelectAll: widget.onSelectAll, + // Make sure no decoration is set on the DataTable + // from the theme, as its already wrapped in a Card. + decoration: const BoxDecoration(), + dataRowMinHeight: widget.dataRowMinHeight, + dataRowMaxHeight: widget.dataRowMaxHeight, + headingRowHeight: widget.headingRowHeight, + horizontalMargin: widget.horizontalMargin, + checkboxHorizontalMargin: widget.checkboxHorizontalMargin, + columnSpacing: widget.columnSpacing, + showCheckboxColumn: widget.showCheckboxColumn, + showBottomBorder: true, + rows: _getRows(_firstRowIndex, widget.rowsPerPage), + headingRowColor: widget.headingRowColor, + ), + ), + ), + if (!widget.showEmptyRows) + SizedBox( + height: (widget.dataRowMaxHeight ?? kMinInteractiveDimension) * (widget.rowsPerPage - _rowCount + _firstRowIndex).clamp(0, widget.rowsPerPage)), + DefaultTextStyle( + style: footerTextStyle!, + child: IconTheme.merge( + data: const IconThemeData( + opacity: 0.54, + ), + child: SizedBox( + // TODO(bkonyi): this won't handle text zoom correctly, + // https://github.com/flutter/flutter/issues/48522 + height: 56.0, + child: SingleChildScrollView( + dragStartBehavior: widget.dragStartBehavior, + scrollDirection: Axis.horizontal, + reverse: true, + child: Row( + children: footerWidgets, + ), + ), + ), + ), + ), + ], + ); + }, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/popup_menu.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/popup_menu.dart new file mode 100644 index 0000000000000000000000000000000000000000..3e9a3a176855d9f25e70bf1e94cbd247109fade0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/popup_menu.dart @@ -0,0 +1,1529 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'color_scheme.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'divider.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'list_tile.dart'; +import 'list_tile_theme.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'popup_menu_theme.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'tooltip.dart'; + +// Examples can assume: +// enum Commands { heroAndScholar, hurricaneCame } +// late bool _heroAndScholar; +// late dynamic _selection; +// late BuildContext context; +// void setState(VoidCallback fn) { } +// enum Menu { itemOne, itemTwo, itemThree, itemFour } + +const Duration _kMenuDuration = Duration(milliseconds: 300); +const double _kMenuCloseIntervalEnd = 2.0 / 3.0; +const double _kMenuDividerHeight = 16.0; +const double _kMenuMaxWidth = 5.0 * _kMenuWidthStep; +const double _kMenuMinWidth = 2.0 * _kMenuWidthStep; +const double _kMenuVerticalPadding = 8.0; +const double _kMenuWidthStep = 56.0; +const double _kMenuScreenPadding = 8.0; + +/// A base class for entries in a Material Design popup menu. +/// +/// The popup menu widget uses this interface to interact with the menu items. +/// To show a popup menu, use the [showMenu] function. To create a button that +/// shows a popup menu, consider using [PopupMenuButton]. +/// +/// The type `T` is the type of the value(s) the entry represents. All the +/// entries in a given menu must represent values with consistent types. +/// +/// A [PopupMenuEntry] may represent multiple values, for example a row with +/// several icons, or a single entry, for example a menu item with an icon (see +/// [PopupMenuItem]), or no value at all (for example, [PopupMenuDivider]). +/// +/// See also: +/// +/// * [PopupMenuItem], a popup menu entry for a single value. +/// * [PopupMenuDivider], a popup menu entry that is just a horizontal line. +/// * [CheckedPopupMenuItem], a popup menu item with a checkmark. +/// * [showMenu], a method to dynamically show a popup menu at a given location. +/// * [PopupMenuButton], an [IconButton] that automatically shows a menu when +/// it is tapped. +abstract class PopupMenuEntry<T> extends StatefulWidget { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const PopupMenuEntry({ super.key }); + + /// The amount of vertical space occupied by this entry. + /// + /// This value is used at the time the [showMenu] method is called, if the + /// `initialValue` argument is provided, to determine the position of this + /// entry when aligning the selected entry over the given `position`. It is + /// otherwise ignored. + double get height; + + /// Whether this entry represents a particular value. + /// + /// This method is used by [showMenu], when it is called, to align the entry + /// representing the `initialValue`, if any, to the given `position`, and then + /// later is called on each entry to determine if it should be highlighted (if + /// the method returns true, the entry will have its background color set to + /// the ambient [ThemeData.highlightColor]). If `initialValue` is null, then + /// this method is not called. + /// + /// If the [PopupMenuEntry] represents a single value, this should return true + /// if the argument matches that value. If it represents multiple values, it + /// should return true if the argument matches any of them. + bool represents(T? value); +} + +/// A horizontal divider in a Material Design popup menu. +/// +/// This widget adapts the [Divider] for use in popup menus. +/// +/// See also: +/// +/// * [PopupMenuItem], for the kinds of items that this widget divides. +/// * [showMenu], a method to dynamically show a popup menu at a given location. +/// * [PopupMenuButton], an [IconButton] that automatically shows a menu when +/// it is tapped. +class PopupMenuDivider extends PopupMenuEntry<Never> { + /// Creates a horizontal divider for a popup menu. + /// + /// By default, the divider has a height of 16 logical pixels. + const PopupMenuDivider({ super.key, this.height = _kMenuDividerHeight }); + + /// The height of the divider entry. + /// + /// Defaults to 16 pixels. + @override + final double height; + + @override + bool represents(void value) => false; + + @override + State<PopupMenuDivider> createState() => _PopupMenuDividerState(); +} + +class _PopupMenuDividerState extends State<PopupMenuDivider> { + @override + Widget build(BuildContext context) => Divider(height: widget.height); +} + +// This widget only exists to enable _PopupMenuRoute to save the sizes of +// each menu item. The sizes are used by _PopupMenuRouteLayout to compute the +// y coordinate of the menu's origin so that the center of selected menu +// item lines up with the center of its PopupMenuButton. +class _MenuItem extends SingleChildRenderObjectWidget { + const _MenuItem({ + required this.onLayout, + required super.child, + }); + + final ValueChanged<Size> onLayout; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderMenuItem(onLayout); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderMenuItem renderObject) { + renderObject.onLayout = onLayout; + } +} + +class _RenderMenuItem extends RenderShiftedBox { + _RenderMenuItem(this.onLayout, [RenderBox? child]) : super(child); + + ValueChanged<Size> onLayout; + + @override + Size computeDryLayout(BoxConstraints constraints) { + if (child == null) { + return Size.zero; + } + return child!.getDryLayout(constraints); + } + + @override + void performLayout() { + if (child == null) { + size = Size.zero; + } else { + child!.layout(constraints, parentUsesSize: true); + size = constraints.constrain(child!.size); + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = Offset.zero; + } + onLayout(size); + } +} + +/// An item in a Material Design popup menu. +/// +/// To show a popup menu, use the [showMenu] function. To create a button that +/// shows a popup menu, consider using [PopupMenuButton]. +/// +/// To show a checkmark next to a popup menu item, consider using +/// [CheckedPopupMenuItem]. +/// +/// Typically the [child] of a [PopupMenuItem] is a [Text] widget. More +/// elaborate menus with icons can use a [ListTile]. By default, a +/// [PopupMenuItem] is [kMinInteractiveDimension] pixels high. If you use a widget +/// with a different height, it must be specified in the [height] property. +/// +/// {@tool snippet} +/// +/// Here, a [Text] widget is used with a popup menu item. The `Menu` type +/// is an enum, not shown here. +/// +/// ```dart +/// const PopupMenuItem<Menu>( +/// value: Menu.itemOne, +/// child: Text('Item 1'), +/// ) +/// ``` +/// {@end-tool} +/// +/// See the example at [PopupMenuButton] for how this example could be used in a +/// complete menu, and see the example at [CheckedPopupMenuItem] for one way to +/// keep the text of [PopupMenuItem]s that use [Text] widgets in their [child] +/// slot aligned with the text of [CheckedPopupMenuItem]s or of [PopupMenuItem] +/// that use a [ListTile] in their [child] slot. +/// +/// See also: +/// +/// * [PopupMenuDivider], which can be used to divide items from each other. +/// * [CheckedPopupMenuItem], a variant of [PopupMenuItem] with a checkmark. +/// * [showMenu], a method to dynamically show a popup menu at a given location. +/// * [PopupMenuButton], an [IconButton] that automatically shows a menu when +/// it is tapped. +class PopupMenuItem<T> extends PopupMenuEntry<T> { + /// Creates an item for a popup menu. + /// + /// By default, the item is [enabled]. + const PopupMenuItem({ + super.key, + this.value, + this.onTap, + this.enabled = true, + this.height = kMinInteractiveDimension, + this.padding, + this.textStyle, + this.labelTextStyle, + this.mouseCursor, + required this.child, + }); + + /// The value that will be returned by [showMenu] if this entry is selected. + final T? value; + + /// Called when the menu item is tapped. + final VoidCallback? onTap; + + /// Whether the user is permitted to select this item. + /// + /// Defaults to true. If this is false, then the item will not react to + /// touches. + final bool enabled; + + /// The minimum height of the menu item. + /// + /// Defaults to [kMinInteractiveDimension] pixels. + @override + final double height; + + /// The padding of the menu item. + /// + /// The [height] property may interact with the applied padding. For example, + /// If a [height] greater than the height of the sum of the padding and [child] + /// is provided, then the padding's effect will not be visible. + /// + /// If this is null and [ThemeData.useMaterial3] is true, the horizontal padding + /// defaults to 12.0 on both sides. + /// + /// If this is null and [ThemeData.useMaterial3] is false, the horizontal padding + /// defaults to 16.0 on both sides. + final EdgeInsets? padding; + + /// The text style of the popup menu item. + /// + /// If this property is null, then [PopupMenuThemeData.textStyle] is used. + /// If [PopupMenuThemeData.textStyle] is also null, then [TextTheme.titleMedium] + /// of [ThemeData.textTheme] is used. + final TextStyle? textStyle; + + /// The label style of the popup menu item. + /// + /// When [ThemeData.useMaterial3] is true, this styles the text of the popup menu item. + /// + /// If this property is null, then [PopupMenuThemeData.labelTextStyle] is used. + /// If [PopupMenuThemeData.labelTextStyle] is also null, then [TextTheme.labelLarge] + /// is used with the [ColorScheme.onSurface] color when popup menu item is enabled and + /// the [ColorScheme.onSurface] color with 0.38 opacity when the popup menu item is disabled. + final MaterialStateProperty<TextStyle?>? labelTextStyle; + + /// {@template flutter.material.popupmenu.mouseCursor} + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// {@endtemplate} + /// + /// If null, then the value of [PopupMenuThemeData.mouseCursor] is used. If + /// that is also null, then [MaterialStateMouseCursor.clickable] is used. + final MouseCursor? mouseCursor; + + /// The widget below this widget in the tree. + /// + /// Typically a single-line [ListTile] (for menus with icons) or a [Text]. An + /// appropriate [DefaultTextStyle] is put in scope for the child. In either + /// case, the text should be short enough that it won't wrap. + final Widget? child; + + @override + bool represents(T? value) => value == this.value; + + @override + PopupMenuItemState<T, PopupMenuItem<T>> createState() => PopupMenuItemState<T, PopupMenuItem<T>>(); +} + +/// The [State] for [PopupMenuItem] subclasses. +/// +/// By default this implements the basic styling and layout of Material Design +/// popup menu items. +/// +/// The [buildChild] method can be overridden to adjust exactly what gets placed +/// in the menu. By default it returns [PopupMenuItem.child]. +/// +/// The [handleTap] method can be overridden to adjust exactly what happens when +/// the item is tapped. By default, it uses [Navigator.pop] to return the +/// [PopupMenuItem.value] from the menu route. +/// +/// This class takes two type arguments. The second, `W`, is the exact type of +/// the [Widget] that is using this [State]. It must be a subclass of +/// [PopupMenuItem]. The first, `T`, must match the type argument of that widget +/// class, and is the type of values returned from this menu. +class PopupMenuItemState<T, W extends PopupMenuItem<T>> extends State<W> { + /// The menu item contents. + /// + /// Used by the [build] method. + /// + /// By default, this returns [PopupMenuItem.child]. Override this to put + /// something else in the menu entry. + @protected + Widget? buildChild() => widget.child; + + /// The handler for when the user selects the menu item. + /// + /// Used by the [InkWell] inserted by the [build] method. + /// + /// By default, uses [Navigator.pop] to return the [PopupMenuItem.value] from + /// the menu route. + @protected + void handleTap() { + // Need to pop the navigator first in case onTap may push new route onto navigator. + Navigator.pop<T>(context, widget.value); + + widget.onTap?.call(); + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context); + final PopupMenuThemeData defaults = theme.useMaterial3 ? _PopupMenuDefaultsM3(context) : _PopupMenuDefaultsM2(context); + final Set<MaterialState> states = <MaterialState>{ + if (!widget.enabled) MaterialState.disabled, + }; + + TextStyle style = theme.useMaterial3 + ? (widget.labelTextStyle?.resolve(states) + ?? popupMenuTheme.labelTextStyle?.resolve(states)! + ?? defaults.labelTextStyle!.resolve(states)!) + : (widget.textStyle + ?? popupMenuTheme.textStyle + ?? defaults.textStyle!); + + if (!widget.enabled && !theme.useMaterial3) { + style = style.copyWith(color: theme.disabledColor); + } + + Widget item = AnimatedDefaultTextStyle( + style: style, + duration: kThemeChangeDuration, + child: Container( + alignment: AlignmentDirectional.centerStart, + constraints: BoxConstraints(minHeight: widget.height), + padding: widget.padding ?? (theme.useMaterial3 ? _PopupMenuDefaultsM3.menuHorizontalPadding : _PopupMenuDefaultsM2.menuHorizontalPadding), + child: buildChild(), + ), + ); + + if (!widget.enabled) { + final bool isDark = theme.brightness == Brightness.dark; + item = IconTheme.merge( + data: IconThemeData(opacity: isDark ? 0.5 : 0.38), + child: item, + ); + } + + return MergeSemantics( + child: Semantics( + enabled: widget.enabled, + button: true, + child: InkWell( + onTap: widget.enabled ? handleTap : null, + canRequestFocus: widget.enabled, + mouseCursor: _EffectiveMouseCursor(widget.mouseCursor, popupMenuTheme.mouseCursor), + child: ListTileTheme.merge( + contentPadding: EdgeInsets.zero, + titleTextStyle: style, + child: item, + ), + ), + ), + ); + } +} + +/// An item with a checkmark in a Material Design popup menu. +/// +/// To show a popup menu, use the [showMenu] function. To create a button that +/// shows a popup menu, consider using [PopupMenuButton]. +/// +/// A [CheckedPopupMenuItem] is kMinInteractiveDimension pixels high, which +/// matches the default minimum height of a [PopupMenuItem]. The horizontal +/// layout uses [ListTile]; the checkmark is an [Icons.done] icon, shown in the +/// [ListTile.leading] position. +/// +/// {@tool snippet} +/// +/// Suppose a `Commands` enum exists that lists the possible commands from a +/// particular popup menu, including `Commands.heroAndScholar` and +/// `Commands.hurricaneCame`, and further suppose that there is a +/// `_heroAndScholar` member field which is a boolean. The example below shows a +/// menu with one menu item with a checkmark that can toggle the boolean, and +/// one menu item without a checkmark for selecting the second option. (It also +/// shows a divider placed between the two menu items.) +/// +/// ```dart +/// PopupMenuButton<Commands>( +/// onSelected: (Commands result) { +/// switch (result) { +/// case Commands.heroAndScholar: +/// setState(() { _heroAndScholar = !_heroAndScholar; }); +/// case Commands.hurricaneCame: +/// // ...handle hurricane option +/// break; +/// // ...other items handled here +/// } +/// }, +/// itemBuilder: (BuildContext context) => <PopupMenuEntry<Commands>>[ +/// CheckedPopupMenuItem<Commands>( +/// checked: _heroAndScholar, +/// value: Commands.heroAndScholar, +/// child: const Text('Hero and scholar'), +/// ), +/// const PopupMenuDivider(), +/// const PopupMenuItem<Commands>( +/// value: Commands.hurricaneCame, +/// child: ListTile(leading: Icon(null), title: Text('Bring hurricane')), +/// ), +/// // ...other items listed here +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// In particular, observe how the second menu item uses a [ListTile] with a +/// blank [Icon] in the [ListTile.leading] position to get the same alignment as +/// the item with the checkmark. +/// +/// See also: +/// +/// * [PopupMenuItem], a popup menu entry for picking a command (as opposed to +/// toggling a value). +/// * [PopupMenuDivider], a popup menu entry that is just a horizontal line. +/// * [showMenu], a method to dynamically show a popup menu at a given location. +/// * [PopupMenuButton], an [IconButton] that automatically shows a menu when +/// it is tapped. +class CheckedPopupMenuItem<T> extends PopupMenuItem<T> { + /// Creates a popup menu item with a checkmark. + /// + /// By default, the menu item is [enabled] but unchecked. To mark the item as + /// checked, set [checked] to true. + const CheckedPopupMenuItem({ + super.key, + super.value, + this.checked = false, + super.enabled, + super.padding, + super.height, + super.labelTextStyle, + super.mouseCursor, + super.child, + super.onTap, + }); + + /// Whether to display a checkmark next to the menu item. + /// + /// Defaults to false. + /// + /// When true, an [Icons.done] checkmark is displayed. + /// + /// When this popup menu item is selected, the checkmark will fade in or out + /// as appropriate to represent the implied new state. + final bool checked; + + /// The widget below this widget in the tree. + /// + /// Typically a [Text]. An appropriate [DefaultTextStyle] is put in scope for + /// the child. The text should be short enough that it won't wrap. + /// + /// This widget is placed in the [ListTile.title] slot of a [ListTile] whose + /// [ListTile.leading] slot is an [Icons.done] icon. + @override + Widget? get child => super.child; + + @override + PopupMenuItemState<T, CheckedPopupMenuItem<T>> createState() => _CheckedPopupMenuItemState<T>(); +} + +class _CheckedPopupMenuItemState<T> extends PopupMenuItemState<T, CheckedPopupMenuItem<T>> with SingleTickerProviderStateMixin { + static const Duration _fadeDuration = Duration(milliseconds: 150); + late AnimationController _controller; + Animation<double> get _opacity => _controller.view; + + @override + void initState() { + super.initState(); + _controller = AnimationController(duration: _fadeDuration, vsync: this) + ..value = widget.checked ? 1.0 : 0.0 + ..addListener(() => setState(() { /* animation changed */ })); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + void handleTap() { + // This fades the checkmark in or out when tapped. + if (widget.checked) { + _controller.reverse(); + } else { + _controller.forward(); + } + super.handleTap(); + } + + @override + Widget buildChild() { + final ThemeData theme = Theme.of(context); + final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context); + final PopupMenuThemeData defaults = theme.useMaterial3 ? _PopupMenuDefaultsM3(context) : _PopupMenuDefaultsM2(context); + final Set<MaterialState> states = <MaterialState>{ + if (widget.checked) MaterialState.selected, + }; + final MaterialStateProperty<TextStyle?>? effectiveLabelTextStyle = widget.labelTextStyle + ?? popupMenuTheme.labelTextStyle + ?? defaults.labelTextStyle; + return IgnorePointer( + child: ListTileTheme.merge( + contentPadding: EdgeInsets.zero, + child: ListTile( + enabled: widget.enabled, + titleTextStyle: effectiveLabelTextStyle?.resolve(states), + leading: FadeTransition( + opacity: _opacity, + child: Icon(_controller.isDismissed ? null : Icons.done), + ), + title: widget.child, + ), + ), + ); + } +} + +class _PopupMenu<T> extends StatelessWidget { + const _PopupMenu({ + super.key, + required this.route, + required this.semanticLabel, + this.constraints, + required this.clipBehavior, + }); + + final _PopupMenuRoute<T> route; + final String? semanticLabel; + final BoxConstraints? constraints; + final Clip clipBehavior; + + @override + Widget build(BuildContext context) { + final double unit = 1.0 / (route.items.length + 1.5); // 1.0 for the width and 0.5 for the last item's fade. + final List<Widget> children = <Widget>[]; + final ThemeData theme = Theme.of(context); + final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context); + final PopupMenuThemeData defaults = theme.useMaterial3 ? _PopupMenuDefaultsM3(context) : _PopupMenuDefaultsM2(context); + + for (int i = 0; i < route.items.length; i += 1) { + final double start = (i + 1) * unit; + final double end = clampDouble(start + 1.5 * unit, 0.0, 1.0); + final CurvedAnimation opacity = CurvedAnimation( + parent: route.animation!, + curve: Interval(start, end), + ); + Widget item = route.items[i]; + if (route.initialValue != null && route.items[i].represents(route.initialValue)) { + item = ColoredBox( + color: Theme.of(context).highlightColor, + child: item, + ); + } + children.add( + _MenuItem( + onLayout: (Size size) { + route.itemSizes[i] = size; + }, + child: FadeTransition( + opacity: opacity, + child: item, + ), + ), + ); + } + + final CurveTween opacity = CurveTween(curve: const Interval(0.0, 1.0 / 3.0)); + final CurveTween width = CurveTween(curve: Interval(0.0, unit)); + final CurveTween height = CurveTween(curve: Interval(0.0, unit * route.items.length)); + + final Widget child = ConstrainedBox( + constraints: constraints ?? const BoxConstraints( + minWidth: _kMenuMinWidth, + maxWidth: _kMenuMaxWidth, + ), + child: IntrinsicWidth( + stepWidth: _kMenuWidthStep, + child: Semantics( + scopesRoute: true, + namesRoute: true, + explicitChildNodes: true, + label: semanticLabel, + child: SingleChildScrollView( + padding: const EdgeInsets.symmetric( + vertical: _kMenuVerticalPadding, + ), + child: ListBody(children: children), + ), + ), + ), + ); + + return AnimatedBuilder( + animation: route.animation!, + builder: (BuildContext context, Widget? child) { + return FadeTransition( + opacity: opacity.animate(route.animation!), + child: Material( + shape: route.shape ?? popupMenuTheme.shape ?? defaults.shape, + color: route.color ?? popupMenuTheme.color ?? defaults.color, + clipBehavior: clipBehavior, + type: MaterialType.card, + elevation: route.elevation ?? popupMenuTheme.elevation ?? defaults.elevation!, + shadowColor: route.shadowColor ?? popupMenuTheme.shadowColor ?? defaults.shadowColor, + surfaceTintColor: route.surfaceTintColor ?? popupMenuTheme.surfaceTintColor ?? defaults.surfaceTintColor, + child: Align( + alignment: AlignmentDirectional.topEnd, + widthFactor: width.evaluate(route.animation!), + heightFactor: height.evaluate(route.animation!), + child: child, + ), + ), + ); + }, + child: child, + ); + } +} + +// Positioning of the menu on the screen. +class _PopupMenuRouteLayout extends SingleChildLayoutDelegate { + _PopupMenuRouteLayout( + this.position, + this.itemSizes, + this.selectedItemIndex, + this.textDirection, + this.padding, + this.avoidBounds, + ); + + // Rectangle of underlying button, relative to the overlay's dimensions. + final RelativeRect position; + + // The sizes of each item are computed when the menu is laid out, and before + // the route is laid out. + List<Size?> itemSizes; + + // The index of the selected item, or null if PopupMenuButton.initialValue + // was not specified. + final int? selectedItemIndex; + + // Whether to prefer going to the left or to the right. + final TextDirection textDirection; + + // The padding of unsafe area. + EdgeInsets padding; + + // List of rectangles that we should avoid overlapping. Unusable screen area. + final Set<Rect> avoidBounds; + + // We put the child wherever position specifies, so long as it will fit within + // the specified parent size padded (inset) by 8. If necessary, we adjust the + // child's position so that it fits. + + @override + BoxConstraints getConstraintsForChild(BoxConstraints constraints) { + // The menu can be at most the size of the overlay minus 8.0 pixels in each + // direction. + return BoxConstraints.loose(constraints.biggest).deflate( + const EdgeInsets.all(_kMenuScreenPadding) + padding, + ); + } + + @override + Offset getPositionForChild(Size size, Size childSize) { + // size: The size of the overlay. + // childSize: The size of the menu, when fully open, as determined by + // getConstraintsForChild. + + final double buttonHeight = size.height - position.top - position.bottom; + // Find the ideal vertical position. + double y = position.top; + if (selectedItemIndex != null) { + double selectedItemOffset = _kMenuVerticalPadding; + for (int index = 0; index < selectedItemIndex!; index += 1) { + selectedItemOffset += itemSizes[index]!.height; + } + selectedItemOffset += itemSizes[selectedItemIndex!]!.height / 2; + y = y + buttonHeight / 2.0 - selectedItemOffset; + } + + // Find the ideal horizontal position. + double x; + if (position.left > position.right) { + // Menu button is closer to the right edge, so grow to the left, aligned to the right edge. + x = size.width - position.right - childSize.width; + } else if (position.left < position.right) { + // Menu button is closer to the left edge, so grow to the right, aligned to the left edge. + x = position.left; + } else { + // Menu button is equidistant from both edges, so grow in reading direction. + switch (textDirection) { + case TextDirection.rtl: + x = size.width - position.right - childSize.width; + case TextDirection.ltr: + x = position.left; + } + } + final Offset wantedPosition = Offset(x, y); + final Offset originCenter = position.toRect(Offset.zero & size).center; + final Iterable<Rect> subScreens = DisplayFeatureSubScreen.subScreensInBounds(Offset.zero & size, avoidBounds); + final Rect subScreen = _closestScreen(subScreens, originCenter); + return _fitInsideScreen(subScreen, childSize, wantedPosition); + } + + Rect _closestScreen(Iterable<Rect> screens, Offset point) { + Rect closest = screens.first; + for (final Rect screen in screens) { + if ((screen.center - point).distance < (closest.center - point).distance) { + closest = screen; + } + } + return closest; + } + + Offset _fitInsideScreen(Rect screen, Size childSize, Offset wantedPosition){ + double x = wantedPosition.dx; + double y = wantedPosition.dy; + // Avoid going outside an area defined as the rectangle 8.0 pixels from the + // edge of the screen in every direction. + if (x < screen.left + _kMenuScreenPadding + padding.left) { + x = screen.left + _kMenuScreenPadding + padding.left; + } else if (x + childSize.width > screen.right - _kMenuScreenPadding - padding.right) { + x = screen.right - childSize.width - _kMenuScreenPadding - padding.right; + } + if (y < screen.top + _kMenuScreenPadding + padding.top) { + y = _kMenuScreenPadding + padding.top; + } else if (y + childSize.height > screen.bottom - _kMenuScreenPadding - padding.bottom) { + y = screen.bottom - childSize.height - _kMenuScreenPadding - padding.bottom; + } + + return Offset(x,y); + } + + @override + bool shouldRelayout(_PopupMenuRouteLayout oldDelegate) { + // If called when the old and new itemSizes have been initialized then + // we expect them to have the same length because there's no practical + // way to change length of the items list once the menu has been shown. + assert(itemSizes.length == oldDelegate.itemSizes.length); + + return position != oldDelegate.position + || selectedItemIndex != oldDelegate.selectedItemIndex + || textDirection != oldDelegate.textDirection + || !listEquals(itemSizes, oldDelegate.itemSizes) + || padding != oldDelegate.padding + || !setEquals(avoidBounds, oldDelegate.avoidBounds); + } +} + +class _PopupMenuRoute<T> extends PopupRoute<T> { + _PopupMenuRoute({ + required this.position, + required this.items, + this.initialValue, + this.elevation, + this.surfaceTintColor, + this.shadowColor, + required this.barrierLabel, + this.semanticLabel, + this.shape, + this.color, + required this.capturedThemes, + this.constraints, + required this.clipBehavior, + super.settings, + this.popUpAnimationStyle, + }) : itemSizes = List<Size?>.filled(items.length, null), + // Menus always cycle focus through their items irrespective of the + // focus traversal edge behavior set in the Navigator. + super(traversalEdgeBehavior: TraversalEdgeBehavior.closedLoop); + + final RelativeRect position; + final List<PopupMenuEntry<T>> items; + final List<Size?> itemSizes; + final T? initialValue; + final double? elevation; + final Color? surfaceTintColor; + final Color? shadowColor; + final String? semanticLabel; + final ShapeBorder? shape; + final Color? color; + final CapturedThemes capturedThemes; + final BoxConstraints? constraints; + final Clip clipBehavior; + final AnimationStyle? popUpAnimationStyle; + + @override + Animation<double> createAnimation() { + if (popUpAnimationStyle != AnimationStyle.noAnimation) { + return CurvedAnimation( + parent: super.createAnimation(), + curve: popUpAnimationStyle?.curve ?? Curves.linear, + reverseCurve: popUpAnimationStyle?.reverseCurve ?? const Interval(0.0, _kMenuCloseIntervalEnd), + ); + } + return super.createAnimation(); + } + + @override + Duration get transitionDuration => popUpAnimationStyle?.duration ?? _kMenuDuration; + + @override + bool get barrierDismissible => true; + + @override + Color? get barrierColor => null; + + @override + final String barrierLabel; + + @override + Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { + + int? selectedItemIndex; + if (initialValue != null) { + for (int index = 0; selectedItemIndex == null && index < items.length; index += 1) { + if (items[index].represents(initialValue)) { + selectedItemIndex = index; + } + } + } + + final Widget menu = _PopupMenu<T>( + route: this, + semanticLabel: semanticLabel, + constraints: constraints, + clipBehavior: clipBehavior, + ); + final MediaQueryData mediaQuery = MediaQuery.of(context); + return MediaQuery.removePadding( + context: context, + removeTop: true, + removeBottom: true, + removeLeft: true, + removeRight: true, + child: Builder( + builder: (BuildContext context) { + return CustomSingleChildLayout( + delegate: _PopupMenuRouteLayout( + position, + itemSizes, + selectedItemIndex, + Directionality.of(context), + mediaQuery.padding, + _avoidBounds(mediaQuery), + ), + child: capturedThemes.wrap(menu), + ); + }, + ), + ); + } + + Set<Rect> _avoidBounds(MediaQueryData mediaQuery) { + return DisplayFeatureSubScreen.avoidBounds(mediaQuery).toSet(); + } +} + +/// Show a popup menu that contains the `items` at `position`. +/// +/// The `items` parameter must not be empty. +/// +/// If `initialValue` is specified then the first item with a matching value +/// will be highlighted and the value of `position` gives the rectangle whose +/// vertical center will be aligned with the vertical center of the highlighted +/// item (when possible). +/// +/// If `initialValue` is not specified then the top of the menu will be aligned +/// with the top of the `position` rectangle. +/// +/// In both cases, the menu position will be adjusted if necessary to fit on the +/// screen. +/// +/// Horizontally, the menu is positioned so that it grows in the direction that +/// has the most room. For example, if the `position` describes a rectangle on +/// the left edge of the screen, then the left edge of the menu is aligned with +/// the left edge of the `position`, and the menu grows to the right. If both +/// edges of the `position` are equidistant from the opposite edge of the +/// screen, then the ambient [Directionality] is used as a tie-breaker, +/// preferring to grow in the reading direction. +/// +/// The positioning of the `initialValue` at the `position` is implemented by +/// iterating over the `items` to find the first whose +/// [PopupMenuEntry.represents] method returns true for `initialValue`, and then +/// summing the values of [PopupMenuEntry.height] for all the preceding widgets +/// in the list. +/// +/// The `elevation` argument specifies the z-coordinate at which to place the +/// menu. The elevation defaults to 8, the appropriate elevation for popup +/// menus. +/// +/// The `context` argument is used to look up the [Navigator] and [Theme] for +/// the menu. It is only used when the method is called. Its corresponding +/// widget can be safely removed from the tree before the popup menu is closed. +/// +/// The `useRootNavigator` argument is used to determine whether to push the +/// menu to the [Navigator] furthest from or nearest to the given `context`. It +/// is `false` by default. +/// +/// The `semanticLabel` argument is used by accessibility frameworks to +/// announce screen transitions when the menu is opened and closed. If this +/// label is not provided, it will default to +/// [MaterialLocalizations.popupMenuLabel]. +/// +/// The `clipBehavior` argument is used to clip the shape of the menu. Defaults to +/// [Clip.none]. +/// +/// See also: +/// +/// * [PopupMenuItem], a popup menu entry for a single value. +/// * [PopupMenuDivider], a popup menu entry that is just a horizontal line. +/// * [CheckedPopupMenuItem], a popup menu item with a checkmark. +/// * [PopupMenuButton], which provides an [IconButton] that shows a menu by +/// calling this method automatically. +/// * [SemanticsConfiguration.namesRoute], for a description of edge triggered +/// semantics. +Future<T?> showMenu<T>({ + required BuildContext context, + required RelativeRect position, + required List<PopupMenuEntry<T>> items, + T? initialValue, + double? elevation, + Color? shadowColor, + Color? surfaceTintColor, + String? semanticLabel, + ShapeBorder? shape, + Color? color, + bool useRootNavigator = false, + BoxConstraints? constraints, + Clip clipBehavior = Clip.none, + RouteSettings? routeSettings, + AnimationStyle? popUpAnimationStyle, +}) { + assert(items.isNotEmpty); + assert(debugCheckHasMaterialLocalizations(context)); + + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + break; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + semanticLabel ??= MaterialLocalizations.of(context).popupMenuLabel; + } + + final NavigatorState navigator = Navigator.of(context, rootNavigator: useRootNavigator); + return navigator.push(_PopupMenuRoute<T>( + position: position, + items: items, + initialValue: initialValue, + elevation: elevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + semanticLabel: semanticLabel, + barrierLabel: MaterialLocalizations.of(context).menuDismissLabel, + shape: shape, + color: color, + capturedThemes: InheritedTheme.capture(from: context, to: navigator.context), + constraints: constraints, + clipBehavior: clipBehavior, + settings: routeSettings, + popUpAnimationStyle: popUpAnimationStyle, + )); +} + +/// Signature for the callback invoked when a menu item is selected. The +/// argument is the value of the [PopupMenuItem] that caused its menu to be +/// dismissed. +/// +/// Used by [PopupMenuButton.onSelected]. +typedef PopupMenuItemSelected<T> = void Function(T value); + +/// Signature for the callback invoked when a [PopupMenuButton] is dismissed +/// without selecting an item. +/// +/// Used by [PopupMenuButton.onCanceled]. +typedef PopupMenuCanceled = void Function(); + +/// Signature used by [PopupMenuButton] to lazily construct the items shown when +/// the button is pressed. +/// +/// Used by [PopupMenuButton.itemBuilder]. +typedef PopupMenuItemBuilder<T> = List<PopupMenuEntry<T>> Function(BuildContext context); + +/// Displays a menu when pressed and calls [onSelected] when the menu is dismissed +/// because an item was selected. The value passed to [onSelected] is the value of +/// the selected menu item. +/// +/// One of [child] or [icon] may be provided, but not both. If [icon] is provided, +/// then [PopupMenuButton] behaves like an [IconButton]. +/// +/// If both are null, then a standard overflow icon is created (depending on the +/// platform). +/// +/// ## Updating to [MenuAnchor] +/// +/// There is a Material 3 component, +/// [MenuAnchor] that is preferred for applications that are configured +/// for Material 3 (see [ThemeData.useMaterial3]). +/// The [MenuAnchor] widget's visuals +/// are a little bit different, see the Material 3 spec at +/// <https://m3.material.io/components/menus/guidelines> for +/// more details. +/// +/// The [MenuAnchor] widget's API is also slightly different. +/// [MenuAnchor]'s were built to be lower level interface for +/// creating menus that are displayed from an anchor. +/// +/// There are a few steps you would take to migrate from +/// [PopupMenuButton] to [MenuAnchor]: +/// +/// 1. Instead of using the [PopupMenuButton.itemBuilder] to build +/// a list of [PopupMenuEntry]s, you would use the [MenuAnchor.menuChildren] +/// which takes a list of [Widget]s. Usually, you would use a list of +/// [MenuItemButton]s as shown in the example below. +/// +/// 2. Instead of using the [PopupMenuButton.onSelected] callback, you would +/// set individual callbacks for each of the [MenuItemButton]s using the +/// [MenuItemButton.onPressed] property. +/// +/// 3. To anchor the [MenuAnchor] to a widget, you would use the [MenuAnchor.builder] +/// to return the widget of choice - usually a [TextButton] or an [IconButton]. +/// +/// 4. You may want to style the [MenuItemButton]s, see the [MenuItemButton] +/// documentation for details. +/// +/// Use the sample below for an example of migrating from [PopupMenuButton] to +/// [MenuAnchor]. +/// +/// {@tool dartpad} +/// This example shows a menu with three items, selecting between an enum's +/// values and setting a `selectedMenu` field based on the selection. +/// +/// ** See code in examples/api/lib/material/popup_menu/popup_menu.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to migrate the above to a [MenuAnchor]. +/// +/// ** See code in examples/api/lib/material/menu_anchor/menu_anchor.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of a popup menu, as described in: +/// https://m3.material.io/components/menus/overview +/// +/// ** See code in examples/api/lib/material/popup_menu/popup_menu.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample showcases how to override the [PopupMenuButton] animation +/// curves and duration using [AnimationStyle]. +/// +/// ** See code in examples/api/lib/material/popup_menu/popup_menu.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [PopupMenuItem], a popup menu entry for a single value. +/// * [PopupMenuDivider], a popup menu entry that is just a horizontal line. +/// * [CheckedPopupMenuItem], a popup menu item with a checkmark. +/// * [showMenu], a method to dynamically show a popup menu at a given location. +class PopupMenuButton<T> extends StatefulWidget { + /// Creates a button that shows a popup menu. + const PopupMenuButton({ + super.key, + required this.itemBuilder, + this.initialValue, + this.onOpened, + this.onSelected, + this.onCanceled, + this.tooltip, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.padding = const EdgeInsets.all(8.0), + this.child, + this.splashRadius, + this.icon, + this.iconSize, + this.offset = Offset.zero, + this.enabled = true, + this.shape, + this.color, + this.iconColor, + this.enableFeedback, + this.constraints, + this.position, + this.clipBehavior = Clip.none, + this.useRootNavigator = false, + this.popUpAnimationStyle, + }) : assert( + !(child != null && icon != null), + 'You can only pass [child] or [icon], not both.', + ); + + /// Called when the button is pressed to create the items to show in the menu. + final PopupMenuItemBuilder<T> itemBuilder; + + /// The value of the menu item, if any, that should be highlighted when the menu opens. + final T? initialValue; + + /// Called when the popup menu is shown. + final VoidCallback? onOpened; + + /// Called when the user selects a value from the popup menu created by this button. + /// + /// If the popup menu is dismissed without selecting a value, [onCanceled] is + /// called instead. + final PopupMenuItemSelected<T>? onSelected; + + /// Called when the user dismisses the popup menu without selecting an item. + /// + /// If the user selects a value, [onSelected] is called instead. + final PopupMenuCanceled? onCanceled; + + /// Text that describes the action that will occur when the button is pressed. + /// + /// This text is displayed when the user long-presses on the button and is + /// used for accessibility. + final String? tooltip; + + /// The z-coordinate at which to place the menu when open. This controls the + /// size of the shadow below the menu. + /// + /// Defaults to 8, the appropriate elevation for popup menus. + final double? elevation; + + /// The color used to paint the shadow below the menu. + /// + /// If null then the ambient [PopupMenuThemeData.shadowColor] is used. + /// If that is null too, then the overall theme's [ThemeData.shadowColor] + /// (default black) is used. + final Color? shadowColor; + + /// The color used as an overlay on [color] to indicate elevation. + /// + /// If null, [PopupMenuThemeData.surfaceTintColor] is used. If that + /// is also null, the default value is [ColorScheme.surfaceTint]. + /// + /// See [Material.surfaceTintColor] for more details on how this + /// overlay is applied. + final Color? surfaceTintColor; + + /// Matches IconButton's 8 dps padding by default. In some cases, notably where + /// this button appears as the trailing element of a list item, it's useful to be able + /// to set the padding to zero. + final EdgeInsetsGeometry padding; + + /// The splash radius. + /// + /// If null, default splash radius of [InkWell] or [IconButton] is used. + final double? splashRadius; + + /// If provided, [child] is the widget used for this button + /// and the button will utilize an [InkWell] for taps. + final Widget? child; + + /// If provided, the [icon] is used for this button + /// and the button will behave like an [IconButton]. + final Widget? icon; + + /// The offset is applied relative to the initial position + /// set by the [position]. + /// + /// When not set, the offset defaults to [Offset.zero]. + final Offset offset; + + /// Whether this popup menu button is interactive. + /// + /// Defaults to true. + /// + /// If true, the button will respond to presses by displaying the menu. + /// + /// If false, the button is styled with the disabled color from the + /// current [Theme] and will not respond to presses or show the popup + /// menu and [onSelected], [onCanceled] and [itemBuilder] will not be called. + /// + /// This can be useful in situations where the app needs to show the button, + /// but doesn't currently have anything to show in the menu. + final bool enabled; + + /// If provided, the shape used for the menu. + /// + /// If this property is null, then [PopupMenuThemeData.shape] is used. + /// If [PopupMenuThemeData.shape] is also null, then the default shape for + /// [MaterialType.card] is used. This default shape is a rectangle with + /// rounded edges of BorderRadius.circular(2.0). + final ShapeBorder? shape; + + /// If provided, the background color used for the menu. + /// + /// If this property is null, then [PopupMenuThemeData.color] is used. + /// If [PopupMenuThemeData.color] is also null, then + /// Theme.of(context).cardColor is used. + final Color? color; + + /// If provided, this color is used for the button icon. + /// + /// If this property is null, then [PopupMenuThemeData.iconColor] is used. + /// If [PopupMenuThemeData.iconColor] is also null then defaults to + /// [IconThemeData.color]. + final Color? iconColor; + + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + /// If provided, the size of the [Icon]. + /// + /// If this property is null, then [IconThemeData.size] is used. + /// If [IconThemeData.size] is also null, then + /// default size is 24.0 pixels. + final double? iconSize; + + /// Optional size constraints for the menu. + /// + /// When unspecified, defaults to: + /// ```dart + /// const BoxConstraints( + /// minWidth: 2.0 * 56.0, + /// maxWidth: 5.0 * 56.0, + /// ) + /// ``` + /// + /// The default constraints ensure that the menu width matches maximum width + /// recommended by the Material Design guidelines. + /// Specifying this parameter enables creation of menu wider than + /// the default maximum width. + final BoxConstraints? constraints; + + /// Whether the popup menu is positioned over or under the popup menu button. + /// + /// [offset] is used to change the position of the popup menu relative to the + /// position set by this parameter. + /// + /// If this property is `null`, then [PopupMenuThemeData.position] is used. If + /// [PopupMenuThemeData.position] is also `null`, then the position defaults + /// to [PopupMenuPosition.over] which makes the popup menu appear directly + /// over the button that was used to create it. + final PopupMenuPosition? position; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// The [clipBehavior] argument is used the clip shape of the menu. + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// Used to determine whether to push the menu to the [Navigator] furthest + /// from or nearest to the given `context`. + /// + /// Defaults to false. + final bool useRootNavigator; + + /// Used to override the default animation curves and durations of the popup + /// menu's open and close transitions. + /// + /// If [AnimationStyle.curve] is provided, it will be used to override + /// the default popup animation curve. Otherwise, defaults to [Curves.linear]. + /// + /// If [AnimationStyle.reverseCurve] is provided, it will be used to + /// override the default popup animation reverse curve. Otherwise, defaults to + /// `Interval(0.0, 2.0 / 3.0)`. + /// + /// If [AnimationStyle.duration] is provided, it will be used to override + /// the default popup animation duration. Otherwise, defaults to 300ms. + /// + /// To disable the theme animation, use [AnimationStyle.noAnimation]. + /// + /// If this is null, then the default animation will be used. + final AnimationStyle? popUpAnimationStyle; + + @override + PopupMenuButtonState<T> createState() => PopupMenuButtonState<T>(); +} + +/// The [State] for a [PopupMenuButton]. +/// +/// See [showButtonMenu] for a way to programmatically open the popup menu +/// of your button state. +class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> { + /// A method to show a popup menu with the items supplied to + /// [PopupMenuButton.itemBuilder] at the position of your [PopupMenuButton]. + /// + /// By default, it is called when the user taps the button and [PopupMenuButton.enabled] + /// is set to `true`. Moreover, you can open the button by calling the method manually. + /// + /// You would access your [PopupMenuButtonState] using a [GlobalKey] and + /// show the menu of the button with `globalKey.currentState.showButtonMenu`. + void showButtonMenu() { + final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context); + final RenderBox button = context.findRenderObject()! as RenderBox; + final RenderBox overlay = Navigator.of(context).overlay!.context.findRenderObject()! as RenderBox; + final PopupMenuPosition popupMenuPosition = widget.position ?? popupMenuTheme.position ?? PopupMenuPosition.over; + late Offset offset; + switch (popupMenuPosition) { + case PopupMenuPosition.over: + offset = widget.offset; + case PopupMenuPosition.under: + offset = Offset(0.0, button.size.height) + widget.offset; + if (widget.child == null) { + // Remove the padding of the icon button. + offset -= Offset(0.0, widget.padding.vertical / 2); + } + } + final RelativeRect position = RelativeRect.fromRect( + Rect.fromPoints( + button.localToGlobal(offset, ancestor: overlay), + button.localToGlobal(button.size.bottomRight(Offset.zero) + offset, ancestor: overlay), + ), + Offset.zero & overlay.size, + ); + final List<PopupMenuEntry<T>> items = widget.itemBuilder(context); + // Only show the menu if there is something to show + if (items.isNotEmpty) { + widget.onOpened?.call(); + showMenu<T?>( + context: context, + elevation: widget.elevation ?? popupMenuTheme.elevation, + shadowColor: widget.shadowColor ?? popupMenuTheme.shadowColor, + surfaceTintColor: widget.surfaceTintColor ?? popupMenuTheme.surfaceTintColor, + items: items, + initialValue: widget.initialValue, + position: position, + shape: widget.shape ?? popupMenuTheme.shape, + color: widget.color ?? popupMenuTheme.color, + constraints: widget.constraints, + clipBehavior: widget.clipBehavior, + useRootNavigator: widget.useRootNavigator, + popUpAnimationStyle: widget.popUpAnimationStyle, + ) + .then<void>((T? newValue) { + if (!mounted) { + return null; + } + if (newValue == null) { + widget.onCanceled?.call(); + return null; + } + widget.onSelected?.call(newValue); + }); + } + } + + bool get _canRequestFocus { + final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional; + switch (mode) { + case NavigationMode.traditional: + return widget.enabled; + case NavigationMode.directional: + return true; + } + } + + @override + Widget build(BuildContext context) { + final IconThemeData iconTheme = IconTheme.of(context); + final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context); + final bool enableFeedback = widget.enableFeedback + ?? PopupMenuTheme.of(context).enableFeedback + ?? true; + + assert(debugCheckHasMaterialLocalizations(context)); + + if (widget.child != null) { + return Tooltip( + message: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip, + child: InkWell( + onTap: widget.enabled ? showButtonMenu : null, + canRequestFocus: _canRequestFocus, + radius: widget.splashRadius, + enableFeedback: enableFeedback, + child: widget.child, + ), + ); + } + + return IconButton( + icon: widget.icon ?? Icon(Icons.adaptive.more), + padding: widget.padding, + splashRadius: widget.splashRadius, + iconSize: widget.iconSize ?? popupMenuTheme.iconSize ?? iconTheme.size, + color: widget.iconColor ?? popupMenuTheme.iconColor ?? iconTheme.color, + tooltip: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip, + onPressed: widget.enabled ? showButtonMenu : null, + enableFeedback: enableFeedback, + ); + } +} + +// This MaterialStateProperty is passed along to the menu item's InkWell which +// resolves the property against MaterialState.disabled, MaterialState.hovered, +// MaterialState.focused. +class _EffectiveMouseCursor extends MaterialStateMouseCursor { + const _EffectiveMouseCursor(this.widgetCursor, this.themeCursor); + + final MouseCursor? widgetCursor; + final MaterialStateProperty<MouseCursor?>? themeCursor; + + @override + MouseCursor resolve(Set<MaterialState> states) { + return MaterialStateProperty.resolveAs<MouseCursor?>(widgetCursor, states) + ?? themeCursor?.resolve(states) + ?? MaterialStateMouseCursor.clickable.resolve(states); + } + + @override + String get debugDescription => 'MaterialStateMouseCursor(PopupMenuItemState)'; +} + +class _PopupMenuDefaultsM2 extends PopupMenuThemeData { + _PopupMenuDefaultsM2(this.context) + : super(elevation: 8.0); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final TextTheme _textTheme = _theme.textTheme; + + @override + TextStyle? get textStyle => _textTheme.subtitle1; + + static EdgeInsets menuHorizontalPadding = const EdgeInsets.symmetric(horizontal: 16.0); +} + +// BEGIN GENERATED TOKEN PROPERTIES - PopupMenu + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _PopupMenuDefaultsM3 extends PopupMenuThemeData { + _PopupMenuDefaultsM3(this.context) + : super(elevation: 3.0); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + late final TextTheme _textTheme = _theme.textTheme; + + @override MaterialStateProperty<TextStyle?>? get labelTextStyle { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + final TextStyle style = _textTheme.labelLarge!; + if (states.contains(MaterialState.disabled)) { + return style.apply(color: _colors.onSurface.withOpacity(0.38)); + } + return style.apply(color: _colors.onSurface); + }); + } + + @override + Color? get color => _colors.surface; + + @override + Color? get shadowColor => _colors.shadow; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + @override + ShapeBorder? get shape => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))); + + // TODO(tahatesser): This is taken from https://m3.material.io/components/menus/specs + // Update this when the token is available. + static EdgeInsets menuHorizontalPadding = const EdgeInsets.symmetric(horizontal: 12.0); +} +// END GENERATED TOKEN PROPERTIES - PopupMenu diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/popup_menu_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/popup_menu_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..5d2c675398c5fdd38a5f747fa26fdfaf1c6f053e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/popup_menu_theme.dart @@ -0,0 +1,258 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Used to configure how the [PopupMenuButton] positions its popup menu. +enum PopupMenuPosition { + /// Menu is positioned over the anchor. + over, + /// Menu is positioned under the anchor. + under, +} + +/// Defines the visual properties of the routes used to display popup menus +/// as well as [PopupMenuItem] and [PopupMenuDivider] widgets. +/// +/// Descendant widgets obtain the current [PopupMenuThemeData] object +/// using `PopupMenuTheme.of(context)`. Instances of +/// [PopupMenuThemeData] can be customized with +/// [PopupMenuThemeData.copyWith]. +/// +/// Typically, a [PopupMenuThemeData] is specified as part of the +/// overall [Theme] with [ThemeData.popupMenuTheme]. Otherwise, +/// [PopupMenuTheme] can be used to configure its own widget subtree. +/// +/// All [PopupMenuThemeData] properties are `null` by default. +/// If any of these properties are null, the popup menu will provide its +/// own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class PopupMenuThemeData with Diagnosticable { + /// Creates the set of properties used to configure [PopupMenuTheme]. + const PopupMenuThemeData({ + this.color, + this.shape, + this.elevation, + this.shadowColor, + this.surfaceTintColor, + this.textStyle, + this.labelTextStyle, + this.enableFeedback, + this.mouseCursor, + this.position, + this.iconColor, + this.iconSize, + }); + + /// The background color of the popup menu. + final Color? color; + + /// The shape of the popup menu. + final ShapeBorder? shape; + + /// The elevation of the popup menu. + final double? elevation; + + /// The color used to paint shadow below the popup menu. + final Color? shadowColor; + + /// The color used as an overlay on [color] of the popup menu. + final Color? surfaceTintColor; + + /// The text style of items in the popup menu. + final TextStyle? textStyle; + + /// You can use this to specify a different style of the label + /// when the popup menu item is enabled and disabled. + final MaterialStateProperty<TextStyle?>? labelTextStyle; + + /// If specified, defines the feedback property for [PopupMenuButton]. + /// + /// If [PopupMenuButton.enableFeedback] is provided, [enableFeedback] is ignored. + final bool? enableFeedback; + + /// {@macro flutter.material.popupmenu.mouseCursor} + /// + /// If specified, overrides the default value of [PopupMenuItem.mouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// Whether the popup menu is positioned over or under the popup menu button. + /// + /// When not set, the position defaults to [PopupMenuPosition.over] which makes the + /// popup menu appear directly over the button that was used to create it. + final PopupMenuPosition? position; + + /// The color of the icon in the popup menu button. + final Color? iconColor; + + /// The size of the icon in the popup menu button. + final double? iconSize; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + PopupMenuThemeData copyWith({ + Color? color, + ShapeBorder? shape, + double? elevation, + Color? shadowColor, + Color? surfaceTintColor, + TextStyle? textStyle, + MaterialStateProperty<TextStyle?>? labelTextStyle, + bool? enableFeedback, + MaterialStateProperty<MouseCursor?>? mouseCursor, + PopupMenuPosition? position, + Color? iconColor, + double? iconSize, + }) { + return PopupMenuThemeData( + color: color ?? this.color, + shape: shape ?? this.shape, + elevation: elevation ?? this.elevation, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + textStyle: textStyle ?? this.textStyle, + labelTextStyle: labelTextStyle ?? this.labelTextStyle, + enableFeedback: enableFeedback ?? this.enableFeedback, + mouseCursor: mouseCursor ?? this.mouseCursor, + position: position ?? this.position, + iconColor: iconColor ?? this.iconColor, + iconSize: iconSize ?? this.iconSize, + ); + } + + /// Linearly interpolate between two popup menu themes. + /// + /// If both arguments are null, then null is returned. + /// + /// {@macro dart.ui.shadow.lerp} + static PopupMenuThemeData? lerp(PopupMenuThemeData? a, PopupMenuThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return PopupMenuThemeData( + color: Color.lerp(a?.color, b?.color, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t), + labelTextStyle: MaterialStateProperty.lerp<TextStyle?>(a?.labelTextStyle, b?.labelTextStyle, t, TextStyle.lerp), + enableFeedback: t < 0.5 ? a?.enableFeedback : b?.enableFeedback, + mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, + position: t < 0.5 ? a?.position : b?.position, + iconColor: Color.lerp(a?.iconColor, b?.iconColor, t), + iconSize: lerpDouble(a?.iconSize, b?.iconSize, t), + ); + } + + @override + int get hashCode => Object.hash( + color, + shape, + elevation, + shadowColor, + surfaceTintColor, + textStyle, + labelTextStyle, + enableFeedback, + mouseCursor, + position, + iconColor, + iconSize, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is PopupMenuThemeData + && other.color == color + && other.shape == shape + && other.elevation == elevation + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.textStyle == textStyle + && other.labelTextStyle == labelTextStyle + && other.enableFeedback == enableFeedback + && other.mouseCursor == mouseCursor + && other.position == position + && other.iconColor == iconColor + && other.iconSize == iconSize; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('text style', textStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<TextStyle?>>('labelTextStyle', labelTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('enableFeedback', enableFeedback, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null)); + properties.add(EnumProperty<PopupMenuPosition?>('position', position, defaultValue: null)); + properties.add(ColorProperty('iconColor', iconColor, defaultValue: null)); + properties.add(DoubleProperty('iconSize', iconSize, defaultValue: null)); + } +} + +/// An inherited widget that defines the configuration for +/// popup menus in this widget's subtree. +/// +/// Values specified here are used for popup menu properties that are not +/// given an explicit non-null value. +class PopupMenuTheme extends InheritedTheme { + /// Creates a popup menu theme that controls the configurations for + /// popup menus in its widget subtree. + const PopupMenuTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties for descendant popup menu widgets. + final PopupMenuThemeData data; + + /// The closest instance of this class's [data] value that encloses the given + /// context. If there is no ancestor, it returns [ThemeData.popupMenuTheme]. + /// Applications can assume that the returned value will not be null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// PopupMenuThemeData theme = PopupMenuTheme.of(context); + /// ``` + static PopupMenuThemeData of(BuildContext context) { + final PopupMenuTheme? popupMenuTheme = context.dependOnInheritedWidgetOfExactType<PopupMenuTheme>(); + return popupMenuTheme?.data ?? Theme.of(context).popupMenuTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return PopupMenuTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(PopupMenuTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/predictive_back_page_transitions_builder.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/predictive_back_page_transitions_builder.dart new file mode 100644 index 0000000000000000000000000000000000000000..26d2491f624a8449c68e8045a923e36428f1529a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/predictive_back_page_transitions_builder.dart @@ -0,0 +1,325 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'page_transitions_theme.dart'; + +/// Used by [PageTransitionsTheme] to define a [MaterialPageRoute] page +/// transition animation that looks like the default page transition used on +/// Android U and above when using predictive back. +/// +/// Currently predictive back is only supported on Android U and above, and if +/// this [PageTransitionsBuilder] is used by any other platform, it will fall +/// back to [ZoomPageTransitionsBuilder]. +/// +/// When used on Android U and above, animates along with the back gesture to +/// reveal the destination route. Can be canceled by dragging back towards the +/// edge of the screen. +/// +/// See also: +/// +/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android O. +/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition +/// that's similar to the one provided by Android P. +/// * [ZoomPageTransitionsBuilder], which defines the default page transition +/// that's similar to the one provided in Android Q. +/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page +/// transition that matches native iOS page transitions. +class PredictiveBackPageTransitionsBuilder extends PageTransitionsBuilder { + /// Creates an instance of a [PageTransitionsBuilder] that matches Android U's + /// predictive back transition. + const PredictiveBackPageTransitionsBuilder(); + + @override + Widget buildTransitions<T>( + PageRoute<T> route, + BuildContext context, + Animation<double> animation, + Animation<double> secondaryAnimation, + Widget child, + ) { + return _PredictiveBackGestureDetector( + route: route, + builder: (BuildContext context) { + // Only do a predictive back transition when the user is performing a + // pop gesture. Otherwise, for things like button presses or other + // programmatic navigation, fall back to ZoomPageTransitionsBuilder. + if (route.popGestureInProgress) { + return _PredictiveBackPageTransition( + animation: animation, + secondaryAnimation: secondaryAnimation, + getIsCurrent: () => route.isCurrent, + child: child, + ); + } + + return const ZoomPageTransitionsBuilder().buildTransitions( + route, + context, + animation, + secondaryAnimation, + child, + ); + }, + ); + } +} + +class _PredictiveBackGestureDetector extends StatefulWidget { + const _PredictiveBackGestureDetector({ + required this.route, + required this.builder, + }); + + final WidgetBuilder builder; + final PredictiveBackRoute route; + + @override + State<_PredictiveBackGestureDetector> createState() => + _PredictiveBackGestureDetectorState(); +} + +class _PredictiveBackGestureDetectorState extends State<_PredictiveBackGestureDetector> + with WidgetsBindingObserver { + /// True when the predictive back gesture is enabled. + bool get _isEnabled { + return widget.route.isCurrent + && widget.route.popGestureEnabled; + } + + /// The back event when the gesture first started. + PredictiveBackEvent? get startBackEvent => _startBackEvent; + PredictiveBackEvent? _startBackEvent; + set startBackEvent(PredictiveBackEvent? startBackEvent) { + if (_startBackEvent != startBackEvent && mounted) { + setState(() { + _startBackEvent = startBackEvent; + }); + } + } + + /// The most recent back event during the gesture. + PredictiveBackEvent? get currentBackEvent => _currentBackEvent; + PredictiveBackEvent? _currentBackEvent; + set currentBackEvent(PredictiveBackEvent? currentBackEvent) { + if (_currentBackEvent != currentBackEvent && mounted) { + setState(() { + _currentBackEvent = currentBackEvent; + }); + } + } + + // Begin WidgetsBindingObserver. + + @override + bool handleStartBackGesture(PredictiveBackEvent backEvent) { + final bool gestureInProgress = !backEvent.isButtonEvent && _isEnabled; + if (!gestureInProgress) { + return false; + } + + widget.route.handleStartBackGesture(progress: 1 - backEvent.progress); + startBackEvent = currentBackEvent = backEvent; + return true; + } + + @override + void handleUpdateBackGestureProgress(PredictiveBackEvent backEvent) { + widget.route.handleUpdateBackGestureProgress(progress: 1 - backEvent.progress); + currentBackEvent = backEvent; + } + + @override + void handleCancelBackGesture() { + widget.route.handleCancelBackGesture(); + startBackEvent = currentBackEvent = null; + } + + @override + void handleCommitBackGesture() { + widget.route.handleCommitBackGesture(); + startBackEvent = currentBackEvent = null; + } + + // End WidgetsBindingObserver. + + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addObserver(this); + } + + @override + void dispose() { + WidgetsBinding.instance.removeObserver(this); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return widget.builder(context); + } +} + +/// Android's predictive back page transition. +class _PredictiveBackPageTransition extends StatelessWidget { + const _PredictiveBackPageTransition({ + required this.animation, + required this.secondaryAnimation, + required this.getIsCurrent, + required this.child, + }); + + // These values were eyeballed to match the native predictive back animation + // on a Pixel 2 running Android API 34. + static const double _scaleFullyOpened = 1.0; + static const double _scaleStartTransition = 0.95; + static const double _opacityFullyOpened = 1.0; + static const double _opacityStartTransition = 0.95; + static const double _weightForStartState = 65.0; + static const double _weightForEndState = 35.0; + static const double _screenWidthDivisionFactor = 20.0; + static const double _xShiftAdjustment = 8.0; + + final Animation<double> animation; + final Animation<double> secondaryAnimation; + final ValueGetter<bool> getIsCurrent; + final Widget child; + + Widget _secondaryAnimatedBuilder(BuildContext context, Widget? child) { + final Size size = MediaQuery.sizeOf(context); + final double screenWidth = size.width; + final double xShift = + (screenWidth / _screenWidthDivisionFactor) - _xShiftAdjustment; + + final bool isCurrent = getIsCurrent(); + final Tween<double> xShiftTween = isCurrent + ? ConstantTween<double>(0) + : Tween<double>(begin: xShift, end: 0); + final Animatable<double> scaleTween = isCurrent + ? ConstantTween<double>(_scaleFullyOpened) + : TweenSequence<double>(<TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: Tween<double>( + begin: _scaleStartTransition, + end: _scaleFullyOpened, + ), + weight: _weightForStartState, + ), + TweenSequenceItem<double>( + tween: Tween<double>( + begin: _scaleFullyOpened, + end: _scaleFullyOpened, + ), + weight: _weightForEndState, + ), + ]); + final Animatable<double> fadeTween = isCurrent + ? ConstantTween<double>(_opacityFullyOpened) + : TweenSequence<double>(<TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: Tween<double>( + begin: _opacityFullyOpened, + end: _opacityStartTransition, + ), + weight: _weightForStartState, + ), + TweenSequenceItem<double>( + tween: Tween<double>( + begin: _opacityFullyOpened, + end: _opacityFullyOpened, + ), + weight: _weightForEndState, + ), + ]); + + return Transform.translate( + offset: Offset(xShiftTween.animate(secondaryAnimation).value, 0), + child: Transform.scale( + scale: scaleTween.animate(secondaryAnimation).value, + child: Opacity( + opacity: fadeTween.animate(secondaryAnimation).value, + child: child, + ), + ), + ); + } + + Widget _primaryAnimatedBuilder(BuildContext context, Widget? child) { + final Size size = MediaQuery.sizeOf(context); + final double screenWidth = size.width; + final double xShift = + (screenWidth / _screenWidthDivisionFactor) - _xShiftAdjustment; + + final Animatable<double> xShiftTween = + TweenSequence<double>(<TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: Tween<double>(begin: 0.0, end: 0.0), + weight: _weightForStartState, + ), + TweenSequenceItem<double>( + tween: Tween<double>(begin: xShift, end: 0.0), + weight: _weightForEndState, + ), + ]); + final Animatable<double> scaleTween = + TweenSequence<double>(<TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: Tween<double>( + begin: _scaleFullyOpened, + end: _scaleFullyOpened, + ), + weight: _weightForStartState, + ), + TweenSequenceItem<double>( + tween: Tween<double>( + begin: _scaleStartTransition, + end: _scaleFullyOpened, + ), + weight: _weightForEndState, + ), + ]); + final Animatable<double> fadeTween = + TweenSequence<double>(<TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: Tween<double>(begin: 0.0, end: 0.0), + weight: _weightForStartState, + ), + TweenSequenceItem<double>( + tween: Tween<double>( + begin: _opacityStartTransition, + end: _opacityFullyOpened, + ), + weight: _weightForEndState, + ), + ]); + + return Transform.translate( + offset: Offset(xShiftTween.animate(animation).value, 0), + child: Transform.scale( + scale: scaleTween.animate(animation).value, + child: Opacity( + opacity: fadeTween.animate(animation).value, + child: child, + ), + ), + ); + } + + @override + Widget build(BuildContext context) { + return AnimatedBuilder( + animation: secondaryAnimation, + builder: _secondaryAnimatedBuilder, + child: AnimatedBuilder( + animation: animation, + builder: _primaryAnimatedBuilder, + child: child, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/progress_indicator.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/progress_indicator.dart new file mode 100644 index 0000000000000000000000000000000000000000..2a1cfa80e8f53cb9f0a4518bea3fc0a71c9a0afe --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/progress_indicator.dart @@ -0,0 +1,1087 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; + +import 'color_scheme.dart'; +import 'material.dart'; +import 'progress_indicator_theme.dart'; +import 'theme.dart'; + +const double _kMinCircularProgressIndicatorSize = 36.0; +const int _kIndeterminateLinearDuration = 1800; +const int _kIndeterminateCircularDuration = 1333 * 2222; + +enum _ActivityIndicatorType { material, adaptive } + +/// A base class for Material Design progress indicators. +/// +/// This widget cannot be instantiated directly. For a linear progress +/// indicator, see [LinearProgressIndicator]. For a circular progress indicator, +/// see [CircularProgressIndicator]. +/// +/// See also: +/// +/// * <https://material.io/components/progress-indicators> +abstract class ProgressIndicator extends StatefulWidget { + /// Creates a progress indicator. + /// + /// {@template flutter.material.ProgressIndicator.ProgressIndicator} + /// The [value] argument can either be null for an indeterminate + /// progress indicator, or a non-null value between 0.0 and 1.0 for a + /// determinate progress indicator. + /// + /// ## Accessibility + /// + /// The [semanticsLabel] can be used to identify the purpose of this progress + /// bar for screen reading software. The [semanticsValue] property may be used + /// for determinate progress indicators to indicate how much progress has been made. + /// {@endtemplate} + const ProgressIndicator({ + super.key, + this.value, + this.backgroundColor, + this.color, + this.valueColor, + this.semanticsLabel, + this.semanticsValue, + }); + + /// If non-null, the value of this progress indicator. + /// + /// A value of 0.0 means no progress and 1.0 means that progress is complete. + /// The value will be clamped to be in the range 0.0-1.0. + /// + /// If null, this progress indicator is indeterminate, which means the + /// indicator displays a predetermined animation that does not indicate how + /// much actual progress is being made. + final double? value; + + /// The progress indicator's background color. + /// + /// It is up to the subclass to implement this in whatever way makes sense + /// for the given use case. See the subclass documentation for details. + final Color? backgroundColor; + + /// {@template flutter.progress_indicator.ProgressIndicator.color} + /// The progress indicator's color. + /// + /// This is only used if [ProgressIndicator.valueColor] is null. + /// If [ProgressIndicator.color] is also null, then the ambient + /// [ProgressIndicatorThemeData.color] will be used. If that + /// is null then the current theme's [ColorScheme.primary] will + /// be used by default. + /// {@endtemplate} + final Color? color; + + /// The progress indicator's color as an animated value. + /// + /// If null, the progress indicator is rendered with [color]. If that is null, + /// then it will use the ambient [ProgressIndicatorThemeData.color]. If that + /// is also null then it defaults to the current theme's [ColorScheme.primary]. + final Animation<Color?>? valueColor; + + /// {@template flutter.progress_indicator.ProgressIndicator.semanticsLabel} + /// The [SemanticsProperties.label] for this progress indicator. + /// + /// This value indicates the purpose of the progress bar, and will be + /// read out by screen readers to indicate the purpose of this progress + /// indicator. + /// {@endtemplate} + final String? semanticsLabel; + + /// {@template flutter.progress_indicator.ProgressIndicator.semanticsValue} + /// The [SemanticsProperties.value] for this progress indicator. + /// + /// This will be used in conjunction with the [semanticsLabel] by + /// screen reading software to identify the widget, and is primarily + /// intended for use with determinate progress indicators to announce + /// how far along they are. + /// + /// For determinate progress indicators, this will be defaulted to + /// [ProgressIndicator.value] expressed as a percentage, i.e. `0.1` will + /// become '10%'. + /// {@endtemplate} + final String? semanticsValue; + + Color _getValueColor(BuildContext context, {Color? defaultColor}) { + return valueColor?.value ?? + color ?? + ProgressIndicatorTheme.of(context).color ?? + defaultColor ?? + Theme.of(context).colorScheme.primary; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(PercentProperty('value', value, showName: false, ifNull: '<indeterminate>')); + } + + Widget _buildSemanticsWrapper({ + required BuildContext context, + required Widget child, + }) { + String? expandedSemanticsValue = semanticsValue; + if (value != null) { + expandedSemanticsValue ??= '${(value! * 100).round()}%'; + } + return Semantics( + label: semanticsLabel, + value: expandedSemanticsValue, + child: child, + ); + } +} + +class _LinearProgressIndicatorPainter extends CustomPainter { + const _LinearProgressIndicatorPainter({ + required this.backgroundColor, + required this.valueColor, + this.value, + required this.animationValue, + required this.textDirection, + required this.indicatorBorderRadius, + }); + + final Color backgroundColor; + final Color valueColor; + final double? value; + final double animationValue; + final TextDirection textDirection; + final BorderRadiusGeometry indicatorBorderRadius; + + // The indeterminate progress animation displays two lines whose leading (head) + // and trailing (tail) endpoints are defined by the following four curves. + static const Curve line1Head = Interval( + 0.0, + 750.0 / _kIndeterminateLinearDuration, + curve: Cubic(0.2, 0.0, 0.8, 1.0), + ); + static const Curve line1Tail = Interval( + 333.0 / _kIndeterminateLinearDuration, + (333.0 + 750.0) / _kIndeterminateLinearDuration, + curve: Cubic(0.4, 0.0, 1.0, 1.0), + ); + static const Curve line2Head = Interval( + 1000.0 / _kIndeterminateLinearDuration, + (1000.0 + 567.0) / _kIndeterminateLinearDuration, + curve: Cubic(0.0, 0.0, 0.65, 1.0), + ); + static const Curve line2Tail = Interval( + 1267.0 / _kIndeterminateLinearDuration, + (1267.0 + 533.0) / _kIndeterminateLinearDuration, + curve: Cubic(0.10, 0.0, 0.45, 1.0), + ); + + @override + void paint(Canvas canvas, Size size) { + final Paint paint = Paint() + ..color = backgroundColor + ..style = PaintingStyle.fill; + + paint.color = valueColor; + + void drawBar(double x, double width) { + if (width <= 0.0) { + return; + } + + final double left; + switch (textDirection) { + case TextDirection.rtl: + left = size.width - width - x; + case TextDirection.ltr: + left = x; + } + + final Rect rect = Offset(left, 0.0) & Size(width, size.height); + if (indicatorBorderRadius != BorderRadius.zero) { + final RRect rrect = indicatorBorderRadius.resolve(textDirection).toRRect(rect); + canvas.drawRRect(rrect, paint); + } else { + canvas.drawRect(rect, paint); + } + } + + if (value != null) { + drawBar(0.0, clampDouble(value!, 0.0, 1.0) * size.width); + } else { + final double x1 = size.width * line1Tail.transform(animationValue); + final double width1 = size.width * line1Head.transform(animationValue) - x1; + + final double x2 = size.width * line2Tail.transform(animationValue); + final double width2 = size.width * line2Head.transform(animationValue) - x2; + + drawBar(x1, width1); + drawBar(x2, width2); + } + } + + @override + bool shouldRepaint(_LinearProgressIndicatorPainter oldPainter) { + return oldPainter.backgroundColor != backgroundColor + || oldPainter.valueColor != valueColor + || oldPainter.value != value + || oldPainter.animationValue != animationValue + || oldPainter.textDirection != textDirection + || oldPainter.indicatorBorderRadius != indicatorBorderRadius; + } +} + +/// A Material Design linear progress indicator, also known as a progress bar. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=O-rhXZLtpv0} +/// +/// A widget that shows progress along a line. There are two kinds of linear +/// progress indicators: +/// +/// * _Determinate_. Determinate progress indicators have a specific value at +/// each point in time, and the value should increase monotonically from 0.0 +/// to 1.0, at which time the indicator is complete. To create a determinate +/// progress indicator, use a non-null [value] between 0.0 and 1.0. +/// * _Indeterminate_. Indeterminate progress indicators do not have a specific +/// value at each point in time and instead indicate that progress is being +/// made without indicating how much progress remains. To create an +/// indeterminate progress indicator, use a null [value]. +/// +/// The indicator line is displayed with [valueColor], an animated value. To +/// specify a constant color value use: `AlwaysStoppedAnimation<Color>(color)`. +/// +/// The minimum height of the indicator can be specified using [minHeight]. +/// The indicator can be made taller by wrapping the widget with a [SizedBox]. +/// +/// {@tool dartpad} +/// This example shows a [LinearProgressIndicator] with a changing value. +/// +/// ** See code in examples/api/lib/material/progress_indicator/linear_progress_indicator.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of a [LinearProgressIndicator] with a changing value. +/// When toggling the switch, [LinearProgressIndicator] uses a determinate value. +/// As described in: https://m3.material.io/components/progress-indicators/overview +/// +/// ** See code in examples/api/lib/material/progress_indicator/linear_progress_indicator.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CircularProgressIndicator], which shows progress along a circular arc. +/// * [RefreshIndicator], which automatically displays a [CircularProgressIndicator] +/// when the underlying vertical scrollable is overscrolled. +/// * <https://material.io/design/components/progress-indicators.html#linear-progress-indicators> +class LinearProgressIndicator extends ProgressIndicator { + /// Creates a linear progress indicator. + /// + /// {@macro flutter.material.ProgressIndicator.ProgressIndicator} + const LinearProgressIndicator({ + super.key, + super.value, + super.backgroundColor, + super.color, + super.valueColor, + this.minHeight, + super.semanticsLabel, + super.semanticsValue, + this.borderRadius = BorderRadius.zero, + }) : assert(minHeight == null || minHeight > 0); + + /// {@template flutter.material.LinearProgressIndicator.trackColor} + /// Color of the track being filled by the linear indicator. + /// + /// If [LinearProgressIndicator.backgroundColor] is null then the + /// ambient [ProgressIndicatorThemeData.linearTrackColor] will be used. + /// If that is null, then the ambient theme's [ColorScheme.background] + /// will be used to draw the track. + /// {@endtemplate} + @override + Color? get backgroundColor => super.backgroundColor; + + /// {@template flutter.material.LinearProgressIndicator.minHeight} + /// The minimum height of the line used to draw the linear indicator. + /// + /// If [LinearProgressIndicator.minHeight] is null then it will use the + /// ambient [ProgressIndicatorThemeData.linearMinHeight]. If that is null + /// it will use 4dp. + /// {@endtemplate} + final double? minHeight; + + /// The border radius of both the indicator and the track. + /// + /// By default it is [BorderRadius.zero], which produces a rectangular shape + /// with a rectangular indicator. + final BorderRadiusGeometry borderRadius; + + @override + State<LinearProgressIndicator> createState() => _LinearProgressIndicatorState(); +} + +class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with SingleTickerProviderStateMixin { + late AnimationController _controller; + + @override + void initState() { + super.initState(); + _controller = AnimationController( + duration: const Duration(milliseconds: _kIndeterminateLinearDuration), + vsync: this, + ); + if (widget.value == null) { + _controller.repeat(); + } + } + + @override + void didUpdateWidget(LinearProgressIndicator oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.value == null && !_controller.isAnimating) { + _controller.repeat(); + } else if (widget.value != null && _controller.isAnimating) { + _controller.stop(); + } + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + Widget _buildIndicator(BuildContext context, double animationValue, TextDirection textDirection) { + final ProgressIndicatorThemeData defaults = Theme.of(context).useMaterial3 + ? _LinearProgressIndicatorDefaultsM3(context) + : _LinearProgressIndicatorDefaultsM2(context); + + final ProgressIndicatorThemeData indicatorTheme = ProgressIndicatorTheme.of(context); + final Color trackColor = widget.backgroundColor ?? + indicatorTheme.linearTrackColor ?? + defaults.linearTrackColor!; + final double minHeight = widget.minHeight ?? + indicatorTheme.linearMinHeight ?? + defaults.linearMinHeight!; + + return widget._buildSemanticsWrapper( + context: context, + child: Container( + // Clip is only needed with indeterminate progress indicators + clipBehavior: (widget.borderRadius != BorderRadius.zero && widget.value == null) + ? Clip.antiAlias + : Clip.none, + decoration: ShapeDecoration( + color: trackColor, + shape: RoundedRectangleBorder(borderRadius: widget.borderRadius), + ), + constraints: BoxConstraints( + minWidth: double.infinity, + minHeight: minHeight, + ), + child: CustomPaint( + painter: _LinearProgressIndicatorPainter( + backgroundColor: trackColor, + valueColor: widget._getValueColor(context, defaultColor: defaults.color), + value: widget.value, // may be null + animationValue: animationValue, // ignored if widget.value is not null + textDirection: textDirection, + indicatorBorderRadius: widget.borderRadius, + ), + ), + ), + ); + } + + @override + Widget build(BuildContext context) { + final TextDirection textDirection = Directionality.of(context); + + if (widget.value != null) { + return _buildIndicator(context, _controller.value, textDirection); + } + + return AnimatedBuilder( + animation: _controller.view, + builder: (BuildContext context, Widget? child) { + return _buildIndicator(context, _controller.value, textDirection); + }, + ); + } +} + +class _CircularProgressIndicatorPainter extends CustomPainter { + _CircularProgressIndicatorPainter({ + this.backgroundColor, + required this.valueColor, + required this.value, + required this.headValue, + required this.tailValue, + required this.offsetValue, + required this.rotationValue, + required this.strokeWidth, + required this.strokeAlign, + this.strokeCap, + }) : arcStart = value != null + ? _startAngle + : _startAngle + tailValue * 3 / 2 * math.pi + rotationValue * math.pi * 2.0 + offsetValue * 0.5 * math.pi, + arcSweep = value != null + ? clampDouble(value, 0.0, 1.0) * _sweep + : math.max(headValue * 3 / 2 * math.pi - tailValue * 3 / 2 * math.pi, _epsilon); + + final Color? backgroundColor; + final Color valueColor; + final double? value; + final double headValue; + final double tailValue; + final double offsetValue; + final double rotationValue; + final double strokeWidth; + final double strokeAlign; + final double arcStart; + final double arcSweep; + final StrokeCap? strokeCap; + + static const double _twoPi = math.pi * 2.0; + static const double _epsilon = .001; + // Canvas.drawArc(r, 0, 2*PI) doesn't draw anything, so just get close. + static const double _sweep = _twoPi - _epsilon; + static const double _startAngle = -math.pi / 2.0; + + @override + void paint(Canvas canvas, Size size) { + final Paint paint = Paint() + ..color = valueColor + ..strokeWidth = strokeWidth + ..style = PaintingStyle.stroke; + + // Use the negative operator as intended to keep the exposed constant value + // as users are already familiar with. + final double strokeOffset = strokeWidth / 2 * -strokeAlign; + final Offset arcBaseOffset = Offset(strokeOffset, strokeOffset); + final Size arcActualSize = Size( + size.width - strokeOffset * 2, + size.height - strokeOffset * 2, + ); + + if (backgroundColor != null) { + final Paint backgroundPaint = Paint() + ..color = backgroundColor! + ..strokeWidth = strokeWidth + ..style = PaintingStyle.stroke; + canvas.drawArc( + arcBaseOffset & arcActualSize, + 0, + _sweep, + false, + backgroundPaint, + ); + } + + if (value == null && strokeCap == null) { + // Indeterminate + paint.strokeCap = StrokeCap.square; + } else { + // Butt when determinate (value != null) && strokeCap == null; + paint.strokeCap = strokeCap ?? StrokeCap.butt; + } + + canvas.drawArc( + arcBaseOffset & arcActualSize, + arcStart, + arcSweep, + false, + paint, + ); + } + + @override + bool shouldRepaint(_CircularProgressIndicatorPainter oldPainter) { + return oldPainter.backgroundColor != backgroundColor + || oldPainter.valueColor != valueColor + || oldPainter.value != value + || oldPainter.headValue != headValue + || oldPainter.tailValue != tailValue + || oldPainter.offsetValue != offsetValue + || oldPainter.rotationValue != rotationValue + || oldPainter.strokeWidth != strokeWidth + || oldPainter.strokeAlign != strokeAlign + || oldPainter.strokeCap != strokeCap; + } +} + +/// A Material Design circular progress indicator, which spins to indicate that +/// the application is busy. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=O-rhXZLtpv0} +/// +/// A widget that shows progress along a circle. There are two kinds of circular +/// progress indicators: +/// +/// * _Determinate_. Determinate progress indicators have a specific value at +/// each point in time, and the value should increase monotonically from 0.0 +/// to 1.0, at which time the indicator is complete. To create a determinate +/// progress indicator, use a non-null [value] between 0.0 and 1.0. +/// * _Indeterminate_. Indeterminate progress indicators do not have a specific +/// value at each point in time and instead indicate that progress is being +/// made without indicating how much progress remains. To create an +/// indeterminate progress indicator, use a null [value]. +/// +/// The indicator arc is displayed with [valueColor], an animated value. To +/// specify a constant color use: `AlwaysStoppedAnimation<Color>(color)`. +/// +/// {@tool dartpad} +/// This example shows a [CircularProgressIndicator] with a changing value. +/// +/// ** See code in examples/api/lib/material/progress_indicator/circular_progress_indicator.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of a [CircularProgressIndicator] with a changing value. +/// When toggling the switch, [CircularProgressIndicator] uses a determinate value. +/// As described in: https://m3.material.io/components/progress-indicators/overview +/// +/// ** See code in examples/api/lib/material/progress_indicator/circular_progress_indicator.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [LinearProgressIndicator], which displays progress along a line. +/// * [RefreshIndicator], which automatically displays a [CircularProgressIndicator] +/// when the underlying vertical scrollable is overscrolled. +/// * <https://material.io/design/components/progress-indicators.html#circular-progress-indicators> +class CircularProgressIndicator extends ProgressIndicator { + /// Creates a circular progress indicator. + /// + /// {@macro flutter.material.ProgressIndicator.ProgressIndicator} + const CircularProgressIndicator({ + super.key, + super.value, + super.backgroundColor, + super.color, + super.valueColor, + this.strokeWidth = 4.0, + this.strokeAlign = strokeAlignCenter, + super.semanticsLabel, + super.semanticsValue, + this.strokeCap, + }) : _indicatorType = _ActivityIndicatorType.material; + + /// Creates an adaptive progress indicator that is a + /// [CupertinoActivityIndicator] in iOS and [CircularProgressIndicator] in + /// material theme/non-iOS. + /// + /// The [value], [valueColor], [strokeWidth], [semanticsLabel], and + /// [semanticsValue] will be ignored in iOS. + /// + /// {@macro flutter.material.ProgressIndicator.ProgressIndicator} + const CircularProgressIndicator.adaptive({ + super.key, + super.value, + super.backgroundColor, + super.valueColor, + this.strokeWidth = 4.0, + super.semanticsLabel, + super.semanticsValue, + this.strokeCap, + this.strokeAlign = strokeAlignCenter, + }) : _indicatorType = _ActivityIndicatorType.adaptive; + + final _ActivityIndicatorType _indicatorType; + + /// {@template flutter.material.CircularProgressIndicator.trackColor} + /// Color of the circular track being filled by the circular indicator. + /// + /// If [CircularProgressIndicator.backgroundColor] is null then the + /// ambient [ProgressIndicatorThemeData.circularTrackColor] will be used. + /// If that is null, then the track will not be painted. + /// {@endtemplate} + @override + Color? get backgroundColor => super.backgroundColor; + + /// The width of the line used to draw the circle. + final double strokeWidth; + + /// The relative position of the stroke on a [CircularProgressIndicator]. + /// + /// Values typically range from -1.0 ([strokeAlignInside], inside stroke) + /// to 1.0 ([strokeAlignOutside], outside stroke), + /// without any bound constraints (e.g., a value of -2.0 is not typical, but allowed). + /// A value of 0 ([strokeAlignCenter], default) will center the border + /// on the edge of the widget. + final double strokeAlign; + + /// The progress indicator's line ending. + /// + /// This determines the shape of the stroke ends of the progress indicator. + /// By default, [strokeCap] is null. + /// When [value] is null (indeterminate), the stroke ends are set to + /// [StrokeCap.square]. When [value] is not null, the stroke + /// ends are set to [StrokeCap.butt]. + /// + /// Setting [strokeCap] to [StrokeCap.round] will result in a rounded end. + /// Setting [strokeCap] to [StrokeCap.butt] with [value] == null will result + /// in a slightly different indeterminate animation; the indicator completely + /// disappears and reappears on its minimum value. + /// Setting [strokeCap] to [StrokeCap.square] with [value] != null will + /// result in a different display of [value]. The indicator will start + /// drawing from slightly less than the start, and end slightly after + /// the end. This will produce an alternative result, as the + /// default behavior, for example, that a [value] of 0.5 starts at 90 degrees + /// and ends at 270 degrees. With [StrokeCap.square], it could start 85 + /// degrees and end at 275 degrees. + final StrokeCap? strokeCap; + + /// The indicator stroke is drawn fully inside of the indicator path. + /// + /// This is a constant for use with [strokeAlign]. + static const double strokeAlignInside = -1.0; + + /// The indicator stroke is drawn on the center of the indicator path, + /// with half of the [strokeWidth] on the inside, and the other half + /// on the outside of the path. + /// + /// This is a constant for use with [strokeAlign]. + /// + /// This is the default value for [strokeAlign]. + static const double strokeAlignCenter = 0.0; + + /// The indicator stroke is drawn on the outside of the indicator path. + /// + /// This is a constant for use with [strokeAlign]. + static const double strokeAlignOutside = 1.0; + + @override + State<CircularProgressIndicator> createState() => _CircularProgressIndicatorState(); +} + +class _CircularProgressIndicatorState extends State<CircularProgressIndicator> with SingleTickerProviderStateMixin { + static const int _pathCount = _kIndeterminateCircularDuration ~/ 1333; + static const int _rotationCount = _kIndeterminateCircularDuration ~/ 2222; + + static final Animatable<double> _strokeHeadTween = CurveTween( + curve: const Interval(0.0, 0.5, curve: Curves.fastOutSlowIn), + ).chain(CurveTween( + curve: const SawTooth(_pathCount), + )); + static final Animatable<double> _strokeTailTween = CurveTween( + curve: const Interval(0.5, 1.0, curve: Curves.fastOutSlowIn), + ).chain(CurveTween( + curve: const SawTooth(_pathCount), + )); + static final Animatable<double> _offsetTween = CurveTween(curve: const SawTooth(_pathCount)); + static final Animatable<double> _rotationTween = CurveTween(curve: const SawTooth(_rotationCount)); + + late AnimationController _controller; + + @override + void initState() { + super.initState(); + _controller = AnimationController( + duration: const Duration(milliseconds: _kIndeterminateCircularDuration), + vsync: this, + ); + if (widget.value == null) { + _controller.repeat(); + } + } + + @override + void didUpdateWidget(CircularProgressIndicator oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.value == null && !_controller.isAnimating) { + _controller.repeat(); + } else if (widget.value != null && _controller.isAnimating) { + _controller.stop(); + } + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + Widget _buildCupertinoIndicator(BuildContext context) { + final Color? tickColor = widget.backgroundColor; + return CupertinoActivityIndicator(key: widget.key, color: tickColor); + } + + Widget _buildMaterialIndicator(BuildContext context, double headValue, double tailValue, double offsetValue, double rotationValue) { + final ProgressIndicatorThemeData defaults = Theme.of(context).useMaterial3 + ? _CircularProgressIndicatorDefaultsM3(context) + : _CircularProgressIndicatorDefaultsM2(context); + final Color? trackColor = widget.backgroundColor ?? ProgressIndicatorTheme.of(context).circularTrackColor; + + return widget._buildSemanticsWrapper( + context: context, + child: Container( + constraints: const BoxConstraints( + minWidth: _kMinCircularProgressIndicatorSize, + minHeight: _kMinCircularProgressIndicatorSize, + ), + child: CustomPaint( + painter: _CircularProgressIndicatorPainter( + backgroundColor: trackColor, + valueColor: widget._getValueColor(context, defaultColor: defaults.color), + value: widget.value, // may be null + headValue: headValue, // remaining arguments are ignored if widget.value is not null + tailValue: tailValue, + offsetValue: offsetValue, + rotationValue: rotationValue, + strokeWidth: widget.strokeWidth, + strokeAlign: widget.strokeAlign, + strokeCap: widget.strokeCap, + ), + ), + ), + ); + } + + Widget _buildAnimation() { + return AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget? child) { + return _buildMaterialIndicator( + context, + _strokeHeadTween.evaluate(_controller), + _strokeTailTween.evaluate(_controller), + _offsetTween.evaluate(_controller), + _rotationTween.evaluate(_controller), + ); + }, + ); + } + + @override + Widget build(BuildContext context) { + switch (widget._indicatorType) { + case _ActivityIndicatorType.material: + if (widget.value != null) { + return _buildMaterialIndicator(context, 0.0, 0.0, 0, 0.0); + } + return _buildAnimation(); + case _ActivityIndicatorType.adaptive: + final ThemeData theme = Theme.of(context); + switch (theme.platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return _buildCupertinoIndicator(context); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + if (widget.value != null) { + return _buildMaterialIndicator(context, 0.0, 0.0, 0, 0.0); + } + return _buildAnimation(); + } + } + } +} + +class _RefreshProgressIndicatorPainter extends _CircularProgressIndicatorPainter { + _RefreshProgressIndicatorPainter({ + required super.valueColor, + required super.value, + required super.headValue, + required super.tailValue, + required super.offsetValue, + required super.rotationValue, + required super.strokeWidth, + required super.strokeAlign, + required this.arrowheadScale, + required super.strokeCap, + }); + + final double arrowheadScale; + + void paintArrowhead(Canvas canvas, Size size) { + // ux, uy: a unit vector whose direction parallels the base of the arrowhead. + // (So ux, -uy points in the direction the arrowhead points.) + final double arcEnd = arcStart + arcSweep; + final double ux = math.cos(arcEnd); + final double uy = math.sin(arcEnd); + + assert(size.width == size.height); + final double radius = size.width / 2.0; + final double arrowheadPointX = radius + ux * radius + -uy * strokeWidth * 2.0 * arrowheadScale; + final double arrowheadPointY = radius + uy * radius + ux * strokeWidth * 2.0 * arrowheadScale; + final double arrowheadRadius = strokeWidth * 2.0 * arrowheadScale; + final double innerRadius = radius - arrowheadRadius; + final double outerRadius = radius + arrowheadRadius; + + final Path path = Path() + ..moveTo(radius + ux * innerRadius, radius + uy * innerRadius) + ..lineTo(radius + ux * outerRadius, radius + uy * outerRadius) + ..lineTo(arrowheadPointX, arrowheadPointY) + ..close(); + + final Paint paint = Paint() + ..color = valueColor + ..strokeWidth = strokeWidth + ..style = PaintingStyle.fill; + canvas.drawPath(path, paint); + } + + @override + void paint(Canvas canvas, Size size) { + super.paint(canvas, size); + if (arrowheadScale > 0.0) { + paintArrowhead(canvas, size); + } + } +} + +/// An indicator for the progress of refreshing the contents of a widget. +/// +/// Typically used for swipe-to-refresh interactions. See [RefreshIndicator] for +/// a complete implementation of swipe-to-refresh driven by a [Scrollable] +/// widget. +/// +/// The indicator arc is displayed with [valueColor], an animated value. To +/// specify a constant color use: `AlwaysStoppedAnimation<Color>(color)`. +/// +/// See also: +/// +/// * [RefreshIndicator], which automatically displays a [CircularProgressIndicator] +/// when the underlying vertical scrollable is overscrolled. +class RefreshProgressIndicator extends CircularProgressIndicator { + /// Creates a refresh progress indicator. + /// + /// Rather than creating a refresh progress indicator directly, consider using + /// a [RefreshIndicator] together with a [Scrollable] widget. + /// + /// {@macro flutter.material.ProgressIndicator.ProgressIndicator} + const RefreshProgressIndicator({ + super.key, + super.value, + super.backgroundColor, + super.color, + super.valueColor, + super.strokeWidth = defaultStrokeWidth, // Different default than CircularProgressIndicator. + super.strokeAlign, + super.semanticsLabel, + super.semanticsValue, + super.strokeCap, + this.elevation = 2.0, + this.indicatorMargin = const EdgeInsets.all(4.0), + this.indicatorPadding = const EdgeInsets.all(12.0), + }); + + /// {@macro flutter.material.material.elevation} + final double elevation; + + /// The amount of space by which to inset the whole indicator. + /// It accommodates the [elevation] of the indicator. + final EdgeInsetsGeometry indicatorMargin; + + /// The amount of space by which to inset the inner refresh indicator. + final EdgeInsetsGeometry indicatorPadding; + + /// Default stroke width. + static const double defaultStrokeWidth = 2.5; + + /// {@template flutter.material.RefreshProgressIndicator.backgroundColor} + /// Background color of that fills the circle under the refresh indicator. + /// + /// If [RefreshIndicator.backgroundColor] is null then the + /// ambient [ProgressIndicatorThemeData.refreshBackgroundColor] will be used. + /// If that is null, then the ambient theme's [ThemeData.canvasColor] + /// will be used. + /// {@endtemplate} + @override + Color? get backgroundColor => super.backgroundColor; + + @override + State<CircularProgressIndicator> createState() => _RefreshProgressIndicatorState(); +} + +class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState { + static const double _indicatorSize = 41.0; + + /// Interval for arrow head to fully grow. + static const double _strokeHeadInterval = 0.33; + + late final Animatable<double> _convertTween = CurveTween( + curve: const Interval(0.1, _strokeHeadInterval), + ); + + late final Animatable<double> _additionalRotationTween = TweenSequence<double>( + <TweenSequenceItem<double>>[ + // Makes arrow to expand a little bit earlier, to match the Android look. + TweenSequenceItem<double>( + tween: Tween<double>(begin: -0.1, end: -0.2), + weight: _strokeHeadInterval, + ), + // Additional rotation after the arrow expanded + TweenSequenceItem<double>( + tween: Tween<double>(begin: -0.2, end: 1.35), + weight: 1 - _strokeHeadInterval, + ), + ], + ); + + // Last value received from the widget before null. + double? _lastValue; + + /// Force casting the widget as [RefreshProgressIndicator]. + @override + RefreshProgressIndicator get widget => super.widget as RefreshProgressIndicator; + + // Always show the indeterminate version of the circular progress indicator. + // + // When value is non-null the sweep of the progress indicator arrow's arc + // varies from 0 to about 300 degrees. + // + // When value is null the arrow animation starting from wherever we left it. + @override + Widget build(BuildContext context) { + final double? value = widget.value; + if (value != null) { + _lastValue = value; + _controller.value = _convertTween.transform(value) + * (1333 / 2 / _kIndeterminateCircularDuration); + } + return _buildAnimation(); + } + + @override + Widget _buildAnimation() { + return AnimatedBuilder( + animation: _controller, + builder: (BuildContext context, Widget? child) { + return _buildMaterialIndicator( + context, + // Lengthen the arc a little + 1.05 * _CircularProgressIndicatorState._strokeHeadTween.evaluate(_controller), + _CircularProgressIndicatorState._strokeTailTween.evaluate(_controller), + _CircularProgressIndicatorState._offsetTween.evaluate(_controller), + _CircularProgressIndicatorState._rotationTween.evaluate(_controller), + ); + }, + ); + } + + @override + Widget _buildMaterialIndicator(BuildContext context, double headValue, double tailValue, double offsetValue, double rotationValue) { + final double? value = widget.value; + final double arrowheadScale = value == null ? 0.0 : const Interval(0.1, _strokeHeadInterval).transform(value); + final double rotation; + + if (value == null && _lastValue == null) { + rotation = 0.0; + } else { + rotation = math.pi * _additionalRotationTween.transform(value ?? _lastValue!); + } + + Color valueColor = widget._getValueColor(context); + final double opacity = valueColor.opacity; + valueColor = valueColor.withOpacity(1.0); + + final Color backgroundColor = + widget.backgroundColor ?? + ProgressIndicatorTheme.of(context).refreshBackgroundColor ?? + Theme.of(context).canvasColor; + + return widget._buildSemanticsWrapper( + context: context, + child: Container( + width: _indicatorSize, + height: _indicatorSize, + margin: widget.indicatorMargin, + child: Material( + type: MaterialType.circle, + color: backgroundColor, + elevation: widget.elevation, + child: Padding( + padding: widget.indicatorPadding, + child: Opacity( + opacity: opacity, + child: Transform.rotate( + angle: rotation, + child: CustomPaint( + painter: _RefreshProgressIndicatorPainter( + valueColor: valueColor, + value: null, // Draw the indeterminate progress indicator. + headValue: headValue, + tailValue: tailValue, + offsetValue: offsetValue, + rotationValue: rotationValue, + strokeWidth: widget.strokeWidth, + strokeAlign: widget.strokeAlign, + arrowheadScale: arrowheadScale, + strokeCap: widget.strokeCap, + ), + ), + ), + ), + ), + ), + ), + ); + } +} + +// Hand coded defaults based on Material Design 2. +class _CircularProgressIndicatorDefaultsM2 extends ProgressIndicatorThemeData { + _CircularProgressIndicatorDefaultsM2(this.context); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + Color get color => _colors.primary; +} + +class _LinearProgressIndicatorDefaultsM2 extends ProgressIndicatorThemeData { + _LinearProgressIndicatorDefaultsM2(this.context); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + Color get color => _colors.primary; + + @override + Color get linearTrackColor => _colors.background; + + @override + double get linearMinHeight => 4.0; +} + +// BEGIN GENERATED TOKEN PROPERTIES - ProgressIndicator + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _CircularProgressIndicatorDefaultsM3 extends ProgressIndicatorThemeData { + _CircularProgressIndicatorDefaultsM3(this.context); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + Color get color => _colors.primary; +} + +class _LinearProgressIndicatorDefaultsM3 extends ProgressIndicatorThemeData { + _LinearProgressIndicatorDefaultsM3(this.context); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + Color get color => _colors.primary; + + @override + Color get linearTrackColor => _colors.surfaceVariant; + + @override + double get linearMinHeight => 4.0; +} + +// END GENERATED TOKEN PROPERTIES - ProgressIndicator diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/progress_indicator_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/progress_indicator_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..bf2e5c39331d4ba9ae8ad338a655ca5446cc9b27 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/progress_indicator_theme.dart @@ -0,0 +1,187 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +@immutable +/// Defines the visual properties of [ProgressIndicator] widgets. +/// +/// Used by [ProgressIndicatorTheme] to control the visual properties of +/// progress indicators in a widget subtree. +/// +/// To obtain this configuration, use [ProgressIndicatorTheme.of] to access +/// the closest ancestor [ProgressIndicatorTheme] of the current [BuildContext]. +/// +/// See also: +/// +/// * [ProgressIndicatorTheme], an [InheritedWidget] that propagates the +/// theme down its subtree. +/// * [ThemeData.progressIndicatorTheme], which describes the defaults for +/// any progress indicators as part of the application's [ThemeData]. +class ProgressIndicatorThemeData with Diagnosticable { + /// Creates the set of properties used to configure [ProgressIndicator] widgets. + const ProgressIndicatorThemeData({ + this.color, + this.linearTrackColor, + this.linearMinHeight, + this.circularTrackColor, + this.refreshBackgroundColor, + }); + + /// The color of the [ProgressIndicator]'s indicator. + /// + /// If null, then it will use [ColorScheme.primary] of the ambient + /// [ThemeData.colorScheme]. + /// + /// See also: + /// + /// * [ProgressIndicator.color], which specifies the indicator color for a + /// specific progress indicator. + /// * [ProgressIndicator.valueColor], which specifies the indicator color + /// a an animated color. + final Color? color; + + /// {@macro flutter.material.LinearProgressIndicator.trackColor} + final Color? linearTrackColor; + + /// {@macro flutter.material.LinearProgressIndicator.minHeight} + final double? linearMinHeight; + + /// {@macro flutter.material.CircularProgressIndicator.trackColor} + final Color? circularTrackColor; + + /// {@macro flutter.material.RefreshProgressIndicator.backgroundColor} + final Color? refreshBackgroundColor; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + ProgressIndicatorThemeData copyWith({ + Color? color, + Color? linearTrackColor, + double? linearMinHeight, + Color? circularTrackColor, + Color? refreshBackgroundColor, + }) { + return ProgressIndicatorThemeData( + color: color ?? this.color, + linearTrackColor : linearTrackColor ?? this.linearTrackColor, + linearMinHeight : linearMinHeight ?? this.linearMinHeight, + circularTrackColor : circularTrackColor ?? this.circularTrackColor, + refreshBackgroundColor : refreshBackgroundColor ?? this.refreshBackgroundColor, + ); + } + + /// Linearly interpolate between two progress indicator themes. + /// + /// If both arguments are null, then null is returned. + static ProgressIndicatorThemeData? lerp(ProgressIndicatorThemeData? a, ProgressIndicatorThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return ProgressIndicatorThemeData( + color: Color.lerp(a?.color, b?.color, t), + linearTrackColor : Color.lerp(a?.linearTrackColor, b?.linearTrackColor, t), + linearMinHeight : lerpDouble(a?.linearMinHeight, b?.linearMinHeight, t), + circularTrackColor : Color.lerp(a?.circularTrackColor, b?.circularTrackColor, t), + refreshBackgroundColor : Color.lerp(a?.refreshBackgroundColor, b?.refreshBackgroundColor, t), + ); + } + + @override + int get hashCode => Object.hash( + color, + linearTrackColor, + linearMinHeight, + circularTrackColor, + refreshBackgroundColor, + ); + + @override + bool operator==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ProgressIndicatorThemeData + && other.color == color + && other.linearTrackColor == linearTrackColor + && other.linearMinHeight == linearMinHeight + && other.circularTrackColor == circularTrackColor + && other.refreshBackgroundColor == refreshBackgroundColor; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(ColorProperty('linearTrackColor', linearTrackColor, defaultValue: null)); + properties.add(DoubleProperty('linearMinHeight', linearMinHeight, defaultValue: null)); + properties.add(ColorProperty('circularTrackColor', circularTrackColor, defaultValue: null)); + properties.add(ColorProperty('refreshBackgroundColor', refreshBackgroundColor, defaultValue: null)); + } +} + +/// An inherited widget that defines the configuration for +/// [ProgressIndicator]s in this widget's subtree. +/// +/// Values specified here are used for [ProgressIndicator] properties that are not +/// given an explicit non-null value. +/// +/// {@tool snippet} +/// +/// Here is an example of a progress indicator theme that applies a red indicator +/// color. +/// +/// ```dart +/// const ProgressIndicatorTheme( +/// data: ProgressIndicatorThemeData( +/// color: Colors.red, +/// ), +/// child: LinearProgressIndicator() +/// ) +/// ``` +/// {@end-tool} +class ProgressIndicatorTheme extends InheritedTheme { + /// Creates a theme that controls the configurations for [ProgressIndicator] + /// widgets. + const ProgressIndicatorTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties for descendant [ProgressIndicator] widgets. + final ProgressIndicatorThemeData data; + + /// Returns the [data] from the closest [ProgressIndicatorTheme] ancestor. If + /// there is no ancestor, it returns [ThemeData.progressIndicatorTheme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ProgressIndicatorThemeData theme = ProgressIndicatorTheme.of(context); + /// ``` + static ProgressIndicatorThemeData of(BuildContext context) { + final ProgressIndicatorTheme? progressIndicatorTheme = context.dependOnInheritedWidgetOfExactType<ProgressIndicatorTheme>(); + return progressIndicatorTheme?.data ?? Theme.of(context).progressIndicatorTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return ProgressIndicatorTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(ProgressIndicatorTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/radio.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/radio.dart new file mode 100644 index 0000000000000000000000000000000000000000..b6d967f3f0a2d5e48c3314e053ccbb315124b00c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/radio.dart @@ -0,0 +1,708 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'material_state.dart'; +import 'radio_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; +import 'toggleable.dart'; + +// Examples can assume: +// late BuildContext context; +// enum SingingCharacter { lafayette } +// late SingingCharacter? _character; +// late StateSetter setState; + +enum _RadioType { material, adaptive } + +const double _kOuterRadius = 8.0; +const double _kInnerRadius = 4.5; + +/// A Material Design radio button. +/// +/// Used to select between a number of mutually exclusive values. When one radio +/// button in a group is selected, the other radio buttons in the group cease to +/// be selected. The values are of type `T`, the type parameter of the [Radio] +/// class. Enums are commonly used for this purpose. +/// +/// The radio button itself does not maintain any state. Instead, selecting the +/// radio invokes the [onChanged] callback, passing [value] as a parameter. If +/// [groupValue] and [value] match, this radio will be selected. Most widgets +/// will respond to [onChanged] by calling [State.setState] to update the +/// radio button's [groupValue]. +/// +/// {@tool dartpad} +/// Here is an example of Radio widgets wrapped in ListTiles, which is similar +/// to what you could get with the RadioListTile widget. +/// +/// The currently selected character is passed into `groupValue`, which is +/// maintained by the example's `State`. In this case, the first [Radio] +/// will start off selected because `_character` is initialized to +/// `SingingCharacter.lafayette`. +/// +/// If the second radio button is pressed, the example's state is updated +/// with `setState`, updating `_character` to `SingingCharacter.jefferson`. +/// This causes the buttons to rebuild with the updated `groupValue`, and +/// therefore the selection of the second button. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// ** See code in examples/api/lib/material/radio/radio.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [RadioListTile], which combines this widget with a [ListTile] so that +/// you can give the radio button a label. +/// * [Slider], for selecting a value in a range. +/// * [Checkbox] and [Switch], for toggling a particular value on or off. +/// * <https://material.io/design/components/selection-controls.html#radio-buttons> +class Radio<T> extends StatefulWidget { + /// Creates a Material Design radio button. + /// + /// The radio button itself does not maintain any state. Instead, when the + /// radio button is selected, the widget calls the [onChanged] callback. Most + /// widgets that use a radio button will listen for the [onChanged] callback + /// and rebuild the radio button with a new [groupValue] to update the visual + /// appearance of the radio button. + /// + /// The following arguments are required: + /// + /// * [value] and [groupValue] together determine whether the radio button is + /// selected. + /// * [onChanged] is called when the user selects this radio button. + const Radio({ + super.key, + required this.value, + required this.groupValue, + required this.onChanged, + this.mouseCursor, + this.toggleable = false, + this.activeColor, + this.fillColor, + this.focusColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.materialTapTargetSize, + this.visualDensity, + this.focusNode, + this.autofocus = false, + }) : _radioType = _RadioType.material, + useCupertinoCheckmarkStyle = false; + + /// Creates an adaptive [Radio] based on whether the target platform is iOS + /// or macOS, following Material design's + /// [Cross-platform guidelines](https://material.io/design/platform-guidance/cross-platform-adaptation.html). + /// + /// On iOS and macOS, this constructor creates a [CupertinoRadio], which has + /// matching functionality and presentation as Material checkboxes, and are the + /// graphics expected on iOS. On other platforms, this creates a Material + /// design [Radio]. + /// + /// If a [CupertinoRadio] is created, the following parameters are ignored: + /// [mouseCursor], [fillColor], [hoverColor], [overlayColor], [splashRadius], + /// [materialTapTargetSize], [visualDensity]. + /// + /// [useCupertinoCheckmarkStyle] is used only if a [CupertinoRadio] is created. + /// + /// The target platform is based on the current [Theme]: [ThemeData.platform]. + const Radio.adaptive({ + super.key, + required this.value, + required this.groupValue, + required this.onChanged, + this.mouseCursor, + this.toggleable = false, + this.activeColor, + this.fillColor, + this.focusColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.materialTapTargetSize, + this.visualDensity, + this.focusNode, + this.autofocus = false, + this.useCupertinoCheckmarkStyle = false + }) : _radioType = _RadioType.adaptive; + + /// The value represented by this radio button. + final T value; + + /// The currently selected value for a group of radio buttons. + /// + /// This radio button is considered selected if its [value] matches the + /// [groupValue]. + final T? groupValue; + + /// Called when the user selects this radio button. + /// + /// The radio button passes [value] as a parameter to this callback. The radio + /// button does not actually change state until the parent widget rebuilds the + /// radio button with the new [groupValue]. + /// + /// If null, the radio button will be displayed as disabled. + /// + /// The provided callback will not be invoked if this radio button is already + /// selected. + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// Radio<SingingCharacter>( + /// value: SingingCharacter.lafayette, + /// groupValue: _character, + /// onChanged: (SingingCharacter? newValue) { + /// setState(() { + /// _character = newValue; + /// }); + /// }, + /// ) + /// ``` + final ValueChanged<T?>? onChanged; + + /// {@template flutter.material.radio.mouseCursor} + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// {@endtemplate} + /// + /// If null, then the value of [RadioThemeData.mouseCursor] is used. + /// If that is also null, then [MaterialStateMouseCursor.clickable] is used. + /// + /// See also: + /// + /// * [MaterialStateMouseCursor], a [MouseCursor] that implements + /// `MaterialStateProperty` which is used in APIs that need to accept + /// either a [MouseCursor] or a [MaterialStateProperty<MouseCursor>]. + final MouseCursor? mouseCursor; + + /// Set to true if this radio button is allowed to be returned to an + /// indeterminate state by selecting it again when selected. + /// + /// To indicate returning to an indeterminate state, [onChanged] will be + /// called with null. + /// + /// If true, [onChanged] can be called with [value] when selected while + /// [groupValue] != [value], or with null when selected again while + /// [groupValue] == [value]. + /// + /// If false, [onChanged] will be called with [value] when it is selected + /// while [groupValue] != [value], and only by selecting another radio button + /// in the group (i.e. changing the value of [groupValue]) can this radio + /// button be unselected. + /// + /// The default is false. + /// + /// {@tool dartpad} + /// This example shows how to enable deselecting a radio button by setting the + /// [toggleable] attribute. + /// + /// ** See code in examples/api/lib/material/radio/radio.toggleable.0.dart ** + /// {@end-tool} + final bool toggleable; + + /// The color to use when this radio button is selected. + /// + /// Defaults to [ColorScheme.secondary]. + /// + /// If [fillColor] returns a non-null color in the [MaterialState.selected] + /// state, it will be used instead of this color. + final Color? activeColor; + + /// {@template flutter.material.radio.fillColor} + /// The color that fills the radio button, in all [MaterialState]s. + /// + /// Resolves in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [fillColor] based on the current [MaterialState] + /// of the [Radio], providing a different [Color] when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Radio<int>( + /// value: 1, + /// groupValue: 1, + /// onChanged: (_){}, + /// fillColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) { + /// if (states.contains(MaterialState.disabled)) { + /// return Colors.orange.withOpacity(.32); + /// } + /// return Colors.orange; + /// }) + /// ) + /// ``` + /// {@end-tool} + /// {@endtemplate} + /// + /// If null, then the value of [activeColor] is used in the selected state. If + /// that is also null, then the value of [RadioThemeData.fillColor] is used. + /// If that is also null, then [ThemeData.disabledColor] is used in + /// the disabled state, [ColorScheme.secondary] is used in the + /// selected state, and [ThemeData.unselectedWidgetColor] is used in the + /// default state. + final MaterialStateProperty<Color?>? fillColor; + + /// {@template flutter.material.radio.materialTapTargetSize} + /// Configures the minimum size of the tap target. + /// {@endtemplate} + /// + /// If null, then the value of [RadioThemeData.materialTapTargetSize] is used. + /// If that is also null, then the value of [ThemeData.materialTapTargetSize] + /// is used. + /// + /// See also: + /// + /// * [MaterialTapTargetSize], for a description of how this affects tap targets. + final MaterialTapTargetSize? materialTapTargetSize; + + /// {@template flutter.material.radio.visualDensity} + /// Defines how compact the radio's layout will be. + /// {@endtemplate} + /// + /// {@macro flutter.material.themedata.visualDensity} + /// + /// If null, then the value of [RadioThemeData.visualDensity] is used. If that + /// is also null, then the value of [ThemeData.visualDensity] is used. + /// + /// See also: + /// + /// * [ThemeData.visualDensity], which specifies the [visualDensity] for all + /// widgets within a [Theme]. + final VisualDensity? visualDensity; + + /// The color for the radio's [Material] when it has the input focus. + /// + /// If [overlayColor] returns a non-null color in the [MaterialState.focused] + /// state, it will be used instead. + /// + /// If null, then the value of [RadioThemeData.overlayColor] is used in the + /// focused state. If that is also null, then the value of + /// [ThemeData.focusColor] is used. + final Color? focusColor; + + /// {@template flutter.material.radio.hoverColor} + /// The color for the radio's [Material] when a pointer is hovering over it. + /// + /// If [overlayColor] returns a non-null color in the [MaterialState.hovered] + /// state, it will be used instead. + /// {@endtemplate} + /// + /// If null, then the value of [RadioThemeData.overlayColor] is used in the + /// hovered state. If that is also null, then the value of + /// [ThemeData.hoverColor] is used. + final Color? hoverColor; + + /// {@template flutter.material.radio.overlayColor} + /// The color for the radio's [Material]. + /// + /// Resolves in the following states: + /// * [MaterialState.pressed]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// {@endtemplate} + /// + /// If null, then the value of [activeColor] with alpha + /// [kRadialReactionAlpha], [focusColor] and [hoverColor] is used in the + /// pressed, focused and hovered state. If that is also null, + /// the value of [RadioThemeData.overlayColor] is used. If that is also null, + /// then the value of [ColorScheme.secondary] with alpha + /// [kRadialReactionAlpha], [ThemeData.focusColor] and [ThemeData.hoverColor] + /// is used in the pressed, focused and hovered state. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@template flutter.material.radio.splashRadius} + /// The splash radius of the circular [Material] ink response. + /// {@endtemplate} + /// + /// If null, then the value of [RadioThemeData.splashRadius] is used. If that + /// is also null, then [kRadialReactionRadius] is used. + final double? splashRadius; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// Controls whether the checkmark style is used in an iOS-style radio. + /// + /// Only usable under the [Radio.adaptive] constructor. If set to true, on + /// Apple platforms the radio button will appear as an iOS styled checkmark. + /// Controls the [CupertinoRadio] through [CupertinoRadio.useCheckmarkStyle]. + /// + /// Defaults to false. + final bool useCupertinoCheckmarkStyle; + + final _RadioType _radioType; + + bool get _selected => value == groupValue; + + @override + State<Radio<T>> createState() => _RadioState<T>(); +} + +class _RadioState<T> extends State<Radio<T>> with TickerProviderStateMixin, ToggleableStateMixin { + final _RadioPainter _painter = _RadioPainter(); + + void _handleChanged(bool? selected) { + if (selected == null) { + widget.onChanged!(null); + return; + } + if (selected) { + widget.onChanged!(widget.value); + } + } + + @override + void didUpdateWidget(Radio<T> oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget._selected != oldWidget._selected) { + animateToValue(); + } + } + + @override + void dispose() { + _painter.dispose(); + super.dispose(); + } + + @override + ValueChanged<bool?>? get onChanged => widget.onChanged != null ? _handleChanged : null; + + @override + bool get tristate => widget.toggleable; + + @override + bool? get value => widget._selected; + + MaterialStateProperty<Color?> get _widgetFillColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return null; + } + if (states.contains(MaterialState.selected)) { + return widget.activeColor; + } + return null; + }); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + switch (widget._radioType) { + case _RadioType.material: + break; + + case _RadioType.adaptive: + final ThemeData theme = Theme.of(context); + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + break; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return CupertinoRadio<T>( + value: widget.value, + groupValue: widget.groupValue, + onChanged: widget.onChanged, + toggleable: widget.toggleable, + activeColor: widget.activeColor, + focusColor: widget.focusColor, + focusNode: widget.focusNode, + autofocus: widget.autofocus, + useCheckmarkStyle: widget.useCupertinoCheckmarkStyle, + ); + } + } + + final RadioThemeData radioTheme = RadioTheme.of(context); + final RadioThemeData defaults = Theme.of(context).useMaterial3 ? _RadioDefaultsM3(context) : _RadioDefaultsM2(context); + final MaterialTapTargetSize effectiveMaterialTapTargetSize = widget.materialTapTargetSize + ?? radioTheme.materialTapTargetSize + ?? defaults.materialTapTargetSize!; + final VisualDensity effectiveVisualDensity = widget.visualDensity + ?? radioTheme.visualDensity + ?? defaults.visualDensity!; + Size size; + switch (effectiveMaterialTapTargetSize) { + case MaterialTapTargetSize.padded: + size = const Size(kMinInteractiveDimension, kMinInteractiveDimension); + case MaterialTapTargetSize.shrinkWrap: + size = const Size(kMinInteractiveDimension - 8.0, kMinInteractiveDimension - 8.0); + } + size += effectiveVisualDensity.baseSizeAdjustment; + + final MaterialStateProperty<MouseCursor> effectiveMouseCursor = MaterialStateProperty.resolveWith<MouseCursor>((Set<MaterialState> states) { + return MaterialStateProperty.resolveAs<MouseCursor?>(widget.mouseCursor, states) + ?? radioTheme.mouseCursor?.resolve(states) + ?? MaterialStateProperty.resolveAs<MouseCursor>(MaterialStateMouseCursor.clickable, states); + }); + + // Colors need to be resolved in selected and non selected states separately + // so that they can be lerped between. + final Set<MaterialState> activeStates = states..add(MaterialState.selected); + final Set<MaterialState> inactiveStates = states..remove(MaterialState.selected); + final Color? activeColor = widget.fillColor?.resolve(activeStates) + ?? _widgetFillColor.resolve(activeStates) + ?? radioTheme.fillColor?.resolve(activeStates); + final Color effectiveActiveColor = activeColor ?? defaults.fillColor!.resolve(activeStates)!; + final Color? inactiveColor = widget.fillColor?.resolve(inactiveStates) + ?? _widgetFillColor.resolve(inactiveStates) + ?? radioTheme.fillColor?.resolve(inactiveStates); + final Color effectiveInactiveColor = inactiveColor ?? defaults.fillColor!.resolve(inactiveStates)!; + + final Set<MaterialState> focusedStates = states..add(MaterialState.focused); + Color effectiveFocusOverlayColor = widget.overlayColor?.resolve(focusedStates) + ?? widget.focusColor + ?? radioTheme.overlayColor?.resolve(focusedStates) + ?? defaults.overlayColor!.resolve(focusedStates)!; + + final Set<MaterialState> hoveredStates = states..add(MaterialState.hovered); + Color effectiveHoverOverlayColor = widget.overlayColor?.resolve(hoveredStates) + ?? widget.hoverColor + ?? radioTheme.overlayColor?.resolve(hoveredStates) + ?? defaults.overlayColor!.resolve(hoveredStates)!; + + final Set<MaterialState> activePressedStates = activeStates..add(MaterialState.pressed); + final Color effectiveActivePressedOverlayColor = widget.overlayColor?.resolve(activePressedStates) + ?? radioTheme.overlayColor?.resolve(activePressedStates) + ?? activeColor?.withAlpha(kRadialReactionAlpha) + ?? defaults.overlayColor!.resolve(activePressedStates)!; + + final Set<MaterialState> inactivePressedStates = inactiveStates..add(MaterialState.pressed); + final Color effectiveInactivePressedOverlayColor = widget.overlayColor?.resolve(inactivePressedStates) + ?? radioTheme.overlayColor?.resolve(inactivePressedStates) + ?? inactiveColor?.withAlpha(kRadialReactionAlpha) + ?? defaults.overlayColor!.resolve(inactivePressedStates)!; + + if (downPosition != null) { + effectiveHoverOverlayColor = states.contains(MaterialState.selected) + ? effectiveActivePressedOverlayColor + : effectiveInactivePressedOverlayColor; + effectiveFocusOverlayColor = states.contains(MaterialState.selected) + ? effectiveActivePressedOverlayColor + : effectiveInactivePressedOverlayColor; + } + final bool? accessibilitySelected; + // Apple devices also use `selected` to annotate radio button's semantics + // state. + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + accessibilitySelected = null; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + accessibilitySelected = widget._selected; + } + + return Semantics( + inMutuallyExclusiveGroup: true, + checked: widget._selected, + selected: accessibilitySelected, + child: buildToggleable( + focusNode: widget.focusNode, + autofocus: widget.autofocus, + mouseCursor: effectiveMouseCursor, + size: size, + painter: _painter + ..position = position + ..reaction = reaction + ..reactionFocusFade = reactionFocusFade + ..reactionHoverFade = reactionHoverFade + ..inactiveReactionColor = effectiveInactivePressedOverlayColor + ..reactionColor = effectiveActivePressedOverlayColor + ..hoverColor = effectiveHoverOverlayColor + ..focusColor = effectiveFocusOverlayColor + ..splashRadius = widget.splashRadius ?? radioTheme.splashRadius ?? kRadialReactionRadius + ..downPosition = downPosition + ..isFocused = states.contains(MaterialState.focused) + ..isHovered = states.contains(MaterialState.hovered) + ..activeColor = effectiveActiveColor + ..inactiveColor = effectiveInactiveColor, + ), + ); + } +} + +class _RadioPainter extends ToggleablePainter { + @override + void paint(Canvas canvas, Size size) { + paintRadialReaction(canvas: canvas, origin: size.center(Offset.zero)); + + final Offset center = (Offset.zero & size).center; + + // Outer circle + final Paint paint = Paint() + ..color = Color.lerp(inactiveColor, activeColor, position.value)! + ..style = PaintingStyle.stroke + ..strokeWidth = 2.0; + canvas.drawCircle(center, _kOuterRadius, paint); + + // Inner circle + if (!position.isDismissed) { + paint.style = PaintingStyle.fill; + canvas.drawCircle(center, _kInnerRadius * position.value, paint); + } + } +} + +// Hand coded defaults based on Material Design 2. +class _RadioDefaultsM2 extends RadioThemeData { + _RadioDefaultsM2(this.context); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + + @override + MaterialStateProperty<Color> get fillColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _theme.disabledColor; + } + if (states.contains(MaterialState.selected)) { + return _colors.secondary; + } + return _theme.unselectedWidgetColor; + }); + } + + @override + MaterialStateProperty<Color> get overlayColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return fillColor.resolve(states).withAlpha(kRadialReactionAlpha); + } + if (states.contains(MaterialState.hovered)) { + return _theme.hoverColor; + } + if (states.contains(MaterialState.focused)) { + return _theme.focusColor; + } + return Colors.transparent; + }); + } + + @override + MaterialTapTargetSize get materialTapTargetSize => _theme.materialTapTargetSize; + + @override + VisualDensity get visualDensity => _theme.visualDensity; +} + +// BEGIN GENERATED TOKEN PROPERTIES - Radio<T> + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _RadioDefaultsM3 extends RadioThemeData { + _RadioDefaultsM3(this.context); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + + @override + MaterialStateProperty<Color> get fillColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.pressed)) { + return _colors.primary; + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary; + } + if (states.contains(MaterialState.focused)) { + return _colors.primary; + } + return _colors.primary; + } + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface; + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface; + } + return _colors.onSurfaceVariant; + }); + } + + @override + MaterialStateProperty<Color> get overlayColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.primary.withOpacity(0.12); + } + return Colors.transparent; + } + if (states.contains(MaterialState.pressed)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface.withOpacity(0.12); + } + return Colors.transparent; + }); + } + + @override + MaterialTapTargetSize get materialTapTargetSize => _theme.materialTapTargetSize; + + @override + VisualDensity get visualDensity => _theme.visualDensity; +} + +// END GENERATED TOKEN PROPERTIES - Radio<T> diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/radio_list_tile.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/radio_list_tile.dart new file mode 100644 index 0000000000000000000000000000000000000000..0dfb4c556948d4ce5f95705419f621934cafd928 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/radio_list_tile.dart @@ -0,0 +1,537 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'list_tile.dart'; +import 'list_tile_theme.dart'; +import 'material_state.dart'; +import 'radio.dart'; +import 'radio_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// void setState(VoidCallback fn) { } +// enum Meridiem { am, pm } +// enum SingingCharacter { lafayette } +// late SingingCharacter? _character; + +enum _RadioType { material, adaptive } + +/// A [ListTile] with a [Radio]. In other words, a radio button with a label. +/// +/// The entire list tile is interactive: tapping anywhere in the tile selects +/// the radio button. +/// +/// The [value], [groupValue], [onChanged], and [activeColor] properties of this +/// widget are identical to the similarly-named properties on the [Radio] +/// widget. The type parameter `T` serves the same purpose as that of the +/// [Radio] class' type parameter. +/// +/// The [title], [subtitle], [isThreeLine], and [dense] properties are like +/// those of the same name on [ListTile]. +/// +/// The [selected] property on this widget is similar to the [ListTile.selected] +/// property. This tile's [activeColor] is used for the selected item's text color, or +/// the theme's [ThemeData.toggleableActiveColor] if [activeColor] is null. +/// +/// This widget does not coordinate the [selected] state and the +/// [checked] state; to have the list tile appear selected when the +/// radio button is the selected radio button, set [selected] to true +/// when [value] matches [groupValue]. +/// +/// The radio button is shown on the left by default in left-to-right languages +/// (i.e. the leading edge). This can be changed using [controlAffinity]. The +/// [secondary] widget is placed on the opposite side. This maps to the +/// [ListTile.leading] and [ListTile.trailing] properties of [ListTile]. +/// +/// This widget requires a [Material] widget ancestor in the tree to paint +/// itself on, which is typically provided by the app's [Scaffold]. +/// The [tileColor], and [selectedTileColor] are not painted by the +/// [RadioListTile] itself but by the [Material] widget ancestor. In this +/// case, one can wrap a [Material] widget around the [RadioListTile], e.g.: +/// +/// {@tool snippet} +/// ```dart +/// ColoredBox( +/// color: Colors.green, +/// child: Material( +/// child: RadioListTile<Meridiem>( +/// tileColor: Colors.red, +/// title: const Text('AM'), +/// groupValue: Meridiem.am, +/// value: Meridiem.am, +/// onChanged:(Meridiem? value) { }, +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Performance considerations when wrapping [RadioListTile] with [Material] +/// +/// Wrapping a large number of [RadioListTile]s individually with [Material]s +/// is expensive. Consider only wrapping the [RadioListTile]s that require it +/// or include a common [Material] ancestor where possible. +/// +/// To show the [RadioListTile] as disabled, pass null as the [onChanged] +/// callback. +/// +/// {@tool dartpad} +/// ![RadioListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile.png) +/// +/// This widget shows a pair of radio buttons that control the `_character` +/// field. The field is of the type `SingingCharacter`, an enum. +/// +/// ** See code in examples/api/lib/material/radio_list_tile/radio_list_tile.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample demonstrates how [RadioListTile] positions the radio widget +/// relative to the text in different configurations. +/// +/// ** See code in examples/api/lib/material/radio_list_tile/radio_list_tile.1.dart ** +/// {@end-tool} +/// +/// ## Semantics in RadioListTile +/// +/// Since the entirety of the RadioListTile is interactive, it should represent +/// itself as a single interactive entity. +/// +/// To do so, a RadioListTile widget wraps its children with a [MergeSemantics] +/// widget. [MergeSemantics] will attempt to merge its descendant [Semantics] +/// nodes into one node in the semantics tree. Therefore, RadioListTile will +/// throw an error if any of its children requires its own [Semantics] node. +/// +/// For example, you cannot nest a [RichText] widget as a descendant of +/// RadioListTile. [RichText] has an embedded gesture recognizer that +/// requires its own [Semantics] node, which directly conflicts with +/// RadioListTile's desire to merge all its descendants' semantic nodes +/// into one. Therefore, it may be necessary to create a custom radio tile +/// widget to accommodate similar use cases. +/// +/// {@tool dartpad} +/// ![Radio list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile_semantics.png) +/// +/// Here is an example of a custom labeled radio widget, called +/// LinkedLabelRadio, that includes an interactive [RichText] widget that +/// handles tap gestures. +/// +/// ** See code in examples/api/lib/material/radio_list_tile/custom_labeled_radio.0.dart ** +/// {@end-tool} +/// +/// ## RadioListTile isn't exactly what I want +/// +/// If the way RadioListTile pads and positions its elements isn't quite what +/// you're looking for, you can create custom labeled radio widgets by +/// combining [Radio] with other widgets, such as [Text], [Padding] and +/// [InkWell]. +/// +/// {@tool dartpad} +/// ![Custom radio list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile_custom.png) +/// +/// Here is an example of a custom LabeledRadio widget, but you can easily +/// make your own configurable widget. +/// +/// ** See code in examples/api/lib/material/radio_list_tile/custom_labeled_radio.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListTileTheme], which can be used to affect the style of list tiles, +/// including radio list tiles. +/// * [CheckboxListTile], a similar widget for checkboxes. +/// * [SwitchListTile], a similar widget for switches. +/// * [ListTile] and [Radio], the widgets from which this widget is made. +class RadioListTile<T> extends StatelessWidget { + /// Creates a combination of a list tile and a radio button. + /// + /// The radio tile itself does not maintain any state. Instead, when the radio + /// button is selected, the widget calls the [onChanged] callback. Most + /// widgets that use a radio button will listen for the [onChanged] callback + /// and rebuild the radio tile with a new [groupValue] to update the visual + /// appearance of the radio button. + /// + /// The following arguments are required: + /// + /// * [value] and [groupValue] together determine whether the radio button is + /// selected. + /// * [onChanged] is called when the user selects this radio button. + const RadioListTile({ + super.key, + required this.value, + required this.groupValue, + required this.onChanged, + this.mouseCursor, + this.toggleable = false, + this.activeColor, + this.fillColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.materialTapTargetSize, + this.title, + this.subtitle, + this.isThreeLine = false, + this.dense, + this.secondary, + this.selected = false, + this.controlAffinity = ListTileControlAffinity.platform, + this.autofocus = false, + this.contentPadding, + this.shape, + this.tileColor, + this.selectedTileColor, + this.visualDensity, + this.focusNode, + this.onFocusChange, + this.enableFeedback, + }) : _radioType = _RadioType.material, + useCupertinoCheckmarkStyle = false, + assert(!isThreeLine || subtitle != null); + + /// Creates a combination of a list tile and a platform adaptive radio. + /// + /// The checkbox uses [Radio.adaptive] to show a [CupertinoRadio] for + /// iOS platforms, or [Radio] for all others. + /// + /// All other properties are the same as [RadioListTile]. + const RadioListTile.adaptive({ + super.key, + required this.value, + required this.groupValue, + required this.onChanged, + this.mouseCursor, + this.toggleable = false, + this.activeColor, + this.fillColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.materialTapTargetSize, + this.title, + this.subtitle, + this.isThreeLine = false, + this.dense, + this.secondary, + this.selected = false, + this.controlAffinity = ListTileControlAffinity.platform, + this.autofocus = false, + this.contentPadding, + this.shape, + this.tileColor, + this.selectedTileColor, + this.visualDensity, + this.focusNode, + this.onFocusChange, + this.enableFeedback, + this.useCupertinoCheckmarkStyle = false, + }) : _radioType = _RadioType.adaptive, + assert(!isThreeLine || subtitle != null); + + /// The value represented by this radio button. + final T value; + + /// The currently selected value for this group of radio buttons. + /// + /// This radio button is considered selected if its [value] matches the + /// [groupValue]. + final T? groupValue; + + /// Called when the user selects this radio button. + /// + /// The radio button passes [value] as a parameter to this callback. The radio + /// button does not actually change state until the parent widget rebuilds the + /// radio tile with the new [groupValue]. + /// + /// If null, the radio button will be displayed as disabled. + /// + /// The provided callback will not be invoked if this radio button is already + /// selected. + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// RadioListTile<SingingCharacter>( + /// title: const Text('Lafayette'), + /// value: SingingCharacter.lafayette, + /// groupValue: _character, + /// onChanged: (SingingCharacter? newValue) { + /// setState(() { + /// _character = newValue; + /// }); + /// }, + /// ) + /// ``` + final ValueChanged<T?>? onChanged; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.disabled]. + /// + /// If null, then the value of [RadioThemeData.mouseCursor] is used. + /// If that is also null, then [MaterialStateMouseCursor.clickable] is used. + final MouseCursor? mouseCursor; + + /// Set to true if this radio list tile is allowed to be returned to an + /// indeterminate state by selecting it again when selected. + /// + /// To indicate returning to an indeterminate state, [onChanged] will be + /// called with null. + /// + /// If true, [onChanged] can be called with [value] when selected while + /// [groupValue] != [value], or with null when selected again while + /// [groupValue] == [value]. + /// + /// If false, [onChanged] will be called with [value] when it is selected + /// while [groupValue] != [value], and only by selecting another radio button + /// in the group (i.e. changing the value of [groupValue]) can this radio + /// list tile be unselected. + /// + /// The default is false. + /// + /// {@tool dartpad} + /// This example shows how to enable deselecting a radio button by setting the + /// [toggleable] attribute. + /// + /// ** See code in examples/api/lib/material/radio_list_tile/radio_list_tile.toggleable.0.dart ** + /// {@end-tool} + final bool toggleable; + + /// The color to use when this radio button is selected. + /// + /// Defaults to [ColorScheme.secondary] of the current [Theme]. + final Color? activeColor; + + /// The color that fills the radio button. + /// + /// Resolves in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.disabled]. + /// + /// If null, then the value of [activeColor] is used in the selected state. If + /// that is also null, then the value of [RadioThemeData.fillColor] is used. + /// If that is also null, then the default value is used. + final MaterialStateProperty<Color?>? fillColor; + + /// {@macro flutter.material.radio.materialTapTargetSize} + /// + /// Defaults to [MaterialTapTargetSize.shrinkWrap]. + final MaterialTapTargetSize? materialTapTargetSize; + + /// {@macro flutter.material.radio.hoverColor} + final Color? hoverColor; + + /// The color for the radio's [Material]. + /// + /// Resolves in the following states: + /// * [MaterialState.pressed]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// + /// If null, then the value of [activeColor] with alpha [kRadialReactionAlpha] + /// and [hoverColor] is used in the pressed and hovered state. If that is also + /// null, the value of [SwitchThemeData.overlayColor] is used. If that is + /// also null, then the default value is used in the pressed and hovered state. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@macro flutter.material.radio.splashRadius} + /// + /// If null, then the value of [RadioThemeData.splashRadius] is used. If that + /// is also null, then [kRadialReactionRadius] is used. + final double? splashRadius; + + /// The primary content of the list tile. + /// + /// Typically a [Text] widget. + final Widget? title; + + /// Additional content displayed below the title. + /// + /// Typically a [Text] widget. + final Widget? subtitle; + + /// A widget to display on the opposite side of the tile from the radio button. + /// + /// Typically an [Icon] widget. + final Widget? secondary; + + /// Whether this list tile is intended to display three lines of text. + /// + /// If false, the list tile is treated as having one line if the subtitle is + /// null and treated as having two lines if the subtitle is non-null. + final bool isThreeLine; + + /// Whether this list tile is part of a vertically dense list. + /// + /// If this property is null then its value is based on [ListTileThemeData.dense]. + final bool? dense; + + /// Whether to render icons and text in the [activeColor]. + /// + /// No effort is made to automatically coordinate the [selected] state and the + /// [checked] state. To have the list tile appear selected when the radio + /// button is the selected radio button, set [selected] to true when [value] + /// matches [groupValue]. + /// + /// Normally, this property is left to its default value, false. + final bool selected; + + /// Where to place the control relative to the text. + final ListTileControlAffinity controlAffinity; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// Defines the insets surrounding the contents of the tile. + /// + /// Insets the [Radio], [title], [subtitle], and [secondary] widgets + /// in [RadioListTile]. + /// + /// When null, `EdgeInsets.symmetric(horizontal: 16.0)` is used. + final EdgeInsetsGeometry? contentPadding; + + /// Whether this radio button is checked. + /// + /// To control this value, set [value] and [groupValue] appropriately. + bool get checked => value == groupValue; + + /// If specified, [shape] defines the shape of the [RadioListTile]'s [InkWell] border. + final ShapeBorder? shape; + + /// If specified, defines the background color for `RadioListTile` when + /// [RadioListTile.selected] is false. + final Color? tileColor; + + /// If non-null, defines the background color when [RadioListTile.selected] is true. + final Color? selectedTileColor; + + /// Defines how compact the list tile's layout will be. + /// + /// {@macro flutter.material.themedata.visualDensity} + final VisualDensity? visualDensity; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.material.inkwell.onFocusChange} + final ValueChanged<bool>? onFocusChange; + + /// {@macro flutter.material.ListTile.enableFeedback} + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + final _RadioType _radioType; + + /// Whether to use the checkbox style for the [CupertinoRadio] control. + /// + /// Only usable under the [RadioListTile.adaptive] constructor. If set to + /// true, on Apple platforms the radio button will appear as an iOS styled + /// checkmark. Controls the [CupertinoRadio] through + /// [CupertinoRadio.useCheckmarkStyle]. + /// + /// Defaults to false. + final bool useCupertinoCheckmarkStyle; + + @override + Widget build(BuildContext context) { + final Widget control; + switch (_radioType) { + case _RadioType.material: + control = Radio<T>( + value: value, + groupValue: groupValue, + onChanged: onChanged, + toggleable: toggleable, + activeColor: activeColor, + materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap, + autofocus: autofocus, + fillColor: fillColor, + mouseCursor: mouseCursor, + hoverColor: hoverColor, + overlayColor: overlayColor, + splashRadius: splashRadius, + ); + case _RadioType.adaptive: + control = Radio<T>.adaptive( + value: value, + groupValue: groupValue, + onChanged: onChanged, + toggleable: toggleable, + activeColor: activeColor, + materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap, + autofocus: autofocus, + fillColor: fillColor, + mouseCursor: mouseCursor, + hoverColor: hoverColor, + overlayColor: overlayColor, + splashRadius: splashRadius, + useCupertinoCheckmarkStyle: useCupertinoCheckmarkStyle, + ); + } + + Widget? leading, trailing; + switch (controlAffinity) { + case ListTileControlAffinity.leading: + case ListTileControlAffinity.platform: + leading = control; + trailing = secondary; + case ListTileControlAffinity.trailing: + leading = secondary; + trailing = control; + } + final ThemeData theme = Theme.of(context); + final RadioThemeData radioThemeData = RadioTheme.of(context); + final Set<MaterialState> states = <MaterialState>{ + if (selected) MaterialState.selected, + }; + final Color effectiveActiveColor = activeColor + ?? radioThemeData.fillColor?.resolve(states) + ?? theme.colorScheme.secondary; + return MergeSemantics( + child: ListTile( + selectedColor: effectiveActiveColor, + leading: leading, + title: title, + subtitle: subtitle, + trailing: trailing, + isThreeLine: isThreeLine, + dense: dense, + enabled: onChanged != null, + shape: shape, + tileColor: tileColor, + selectedTileColor: selectedTileColor, + onTap: onChanged != null ? () { + if (toggleable && checked) { + onChanged!(null); + return; + } + if (!checked) { + onChanged!(value); + } + } : null, + selected: selected, + autofocus: autofocus, + contentPadding: contentPadding, + visualDensity: visualDensity, + focusNode: focusNode, + onFocusChange: onFocusChange, + enableFeedback: enableFeedback, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/radio_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/radio_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..f474103ceca8ac571753007aa3ca77da19086a4c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/radio_theme.dart @@ -0,0 +1,206 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [Radio] widgets. +/// +/// Descendant widgets obtain the current [RadioThemeData] object using +/// `RadioTheme.of(context)`. Instances of [RadioThemeData] can be customized +/// with [RadioThemeData.copyWith]. +/// +/// Typically a [RadioThemeData] is specified as part of the overall [Theme] +/// with [ThemeData.radioTheme]. +/// +/// All [RadioThemeData] properties are `null` by default. When null, the +/// [Radio] will use the values from [ThemeData] if they exist, otherwise it +/// will provide its own defaults based on the overall [Theme]'s colorScheme. +/// See the individual [Radio] properties for details. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +/// * [RadioTheme], which is used by descendants to obtain the +/// [RadioThemeData]. +@immutable +class RadioThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.radioTheme]. + const RadioThemeData({ + this.mouseCursor, + this.fillColor, + this.overlayColor, + this.splashRadius, + this.materialTapTargetSize, + this.visualDensity, + }); + + /// {@macro flutter.material.radio.mouseCursor} + /// + /// If specified, overrides the default value of [Radio.mouseCursor]. The + /// default value is [MaterialStateMouseCursor.clickable]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// {@macro flutter.material.radio.fillColor} + /// + /// If specified, overrides the default value of [Radio.fillColor]. The + /// default value is the value of [ThemeData.disabledColor] in the disabled + /// state, [ThemeData.toggleableActiveColor] in the selected state, and + /// [ThemeData.unselectedWidgetColor] in the default state. + final MaterialStateProperty<Color?>? fillColor; + + /// {@macro flutter.material.radio.overlayColor} + /// + /// If specified, overrides the default value of [Radio.overlayColor]. The + /// default value is [ThemeData.toggleableActiveColor] with alpha + /// [kRadialReactionAlpha], [ThemeData.focusColor] and [ThemeData.hoverColor] + /// in the pressed, focused, and hovered state. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@macro flutter.material.radio.splashRadius} + /// + /// If specified, overrides the default value of [Radio.splashRadius]. The + /// default value is [kRadialReactionRadius]. + final double? splashRadius; + + /// {@macro flutter.material.radio.materialTapTargetSize} + /// + /// If specified, overrides the default value of + /// [Radio.materialTapTargetSize]. The default value is the value of + /// [ThemeData.materialTapTargetSize]. + final MaterialTapTargetSize? materialTapTargetSize; + + /// {@macro flutter.material.radio.visualDensity} + /// + /// If specified, overrides the default value of [Radio.visualDensity]. The + /// default value is the value of [ThemeData.visualDensity]. + final VisualDensity? visualDensity; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + RadioThemeData copyWith({ + MaterialStateProperty<MouseCursor?>? mouseCursor, + MaterialStateProperty<Color?>? fillColor, + MaterialStateProperty<Color?>? overlayColor, + double? splashRadius, + MaterialTapTargetSize? materialTapTargetSize, + VisualDensity? visualDensity, + }) { + return RadioThemeData( + mouseCursor: mouseCursor ?? this.mouseCursor, + fillColor: fillColor ?? this.fillColor, + overlayColor: overlayColor ?? this.overlayColor, + splashRadius: splashRadius ?? this.splashRadius, + materialTapTargetSize: materialTapTargetSize ?? this.materialTapTargetSize, + visualDensity: visualDensity ?? this.visualDensity, + ); + } + + /// Linearly interpolate between two [RadioThemeData]s. + /// + /// {@macro dart.ui.shadow.lerp} + static RadioThemeData lerp(RadioThemeData? a, RadioThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return RadioThemeData( + mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, + fillColor: MaterialStateProperty.lerp<Color?>(a?.fillColor, b?.fillColor, t, Color.lerp), + materialTapTargetSize: t < 0.5 ? a?.materialTapTargetSize : b?.materialTapTargetSize, + overlayColor: MaterialStateProperty.lerp<Color?>(a?.overlayColor, b?.overlayColor, t, Color.lerp), + splashRadius: lerpDouble(a?.splashRadius, b?.splashRadius, t), + visualDensity: t < 0.5 ? a?.visualDensity : b?.visualDensity, + ); + } + + @override + int get hashCode => Object.hash( + mouseCursor, + fillColor, + overlayColor, + splashRadius, + materialTapTargetSize, + visualDensity, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is RadioThemeData + && other.mouseCursor == mouseCursor + && other.fillColor == fillColor + && other.overlayColor == overlayColor + && other.splashRadius == splashRadius + && other.materialTapTargetSize == materialTapTargetSize + && other.visualDensity == visualDensity; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('fillColor', fillColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('overlayColor', overlayColor, defaultValue: null)); + properties.add(DoubleProperty('splashRadius', splashRadius, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialTapTargetSize>('materialTapTargetSize', materialTapTargetSize, defaultValue: null)); + properties.add(DiagnosticsProperty<VisualDensity>('visualDensity', visualDensity, defaultValue: null)); + } +} + +/// Applies a radio theme to descendant [Radio] widgets. +/// +/// Descendant widgets obtain the current theme's [RadioTheme] object using +/// [RadioTheme.of]. When a widget uses [RadioTheme.of], it is automatically +/// rebuilt if the theme later changes. +/// +/// A radio theme can be specified as part of the overall Material theme using +/// [ThemeData.radioTheme]. +/// +/// See also: +/// +/// * [RadioThemeData], which describes the actual configuration of a radio +/// theme. +class RadioTheme extends InheritedWidget { + /// Constructs a radio theme that configures all descendant [Radio] widgets. + const RadioTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties used for all descendant [Radio] widgets. + final RadioThemeData data; + + /// Returns the configuration [data] from the closest [RadioTheme] ancestor. + /// If there is no ancestor, it returns [ThemeData.radioTheme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// RadioThemeData theme = RadioTheme.of(context); + /// ``` + static RadioThemeData of(BuildContext context) { + final RadioTheme? radioTheme = context.dependOnInheritedWidgetOfExactType<RadioTheme>(); + return radioTheme?.data ?? Theme.of(context).radioTheme; + } + + @override + bool updateShouldNotify(RadioTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/range_slider.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/range_slider.dart new file mode 100644 index 0000000000000000000000000000000000000000..03978512e2a4d50533a4efa8a3da57232d802200 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/range_slider.dart @@ -0,0 +1,1842 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart' show timeDilation; +import 'package:flutter/widgets.dart'; + +import 'constants.dart'; +import 'debug.dart'; +import 'material_state.dart'; +import 'slider_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// RangeValues _rangeValues = const RangeValues(0.3, 0.7); +// RangeValues _dollarsRange = const RangeValues(50, 100); +// void setState(VoidCallback fn) { } + +/// [RangeSlider] uses this callback to paint the value indicator on the overlay. +/// Since the value indicator is painted on the Overlay; this method paints the +/// value indicator in a [RenderBox] that appears in the [Overlay]. +typedef PaintRangeValueIndicator = void Function(PaintingContext context, Offset offset); + +/// A Material Design range slider. +/// +/// Used to select a range from a range of values. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ufb4gIPDmEs} +/// +/// {@tool dartpad} +/// ![A range slider widget, consisting of 5 divisions and showing the default +/// value indicator.](https://flutter.github.io/assets-for-api-docs/assets/material/range_slider.png) +/// +/// This range values are in intervals of 20 because the Range Slider has 5 +/// divisions, from 0 to 100. This means are values are split between 0, 20, 40, +/// 60, 80, and 100. The range values are initialized with 40 and 80 in this demo. +/// +/// ** See code in examples/api/lib/material/range_slider/range_slider.0.dart ** +/// {@end-tool} +/// +/// A range slider can be used to select from either a continuous or a discrete +/// set of values. The default is to use a continuous range of values from [min] +/// to [max]. To use discrete values, use a non-null value for [divisions], which +/// indicates the number of discrete intervals. For example, if [min] is 0.0 and +/// [max] is 50.0 and [divisions] is 5, then the slider can take on the +/// discrete values 0.0, 10.0, 20.0, 30.0, 40.0, and 50.0. +/// +/// The terms for the parts of a slider are: +/// +/// * The "thumbs", which are the shapes that slide horizontally when the user +/// drags them to change the selected range. +/// * The "track", which is the horizontal line that the thumbs can be dragged +/// along. +/// * The "tick marks", which mark the discrete values of a discrete slider. +/// * The "overlay", which is a highlight that's drawn over a thumb in response +/// to a user tap-down gesture. +/// * The "value indicators", which are the shapes that pop up when the user +/// is dragging a thumb to show the value being selected. +/// * The "active" segment of the slider is the segment between the two thumbs. +/// * The "inactive" slider segments are the two track intervals outside of the +/// slider's thumbs. +/// +/// The range slider will be disabled if [onChanged] is null or if the range +/// given by [min]..[max] is empty (i.e. if [min] is equal to [max]). +/// +/// The range slider widget itself does not maintain any state. Instead, when +/// the state of the slider changes, the widget calls the [onChanged] callback. +/// Most widgets that use a range slider will listen for the [onChanged] callback +/// and rebuild the slider with new [values] to update the visual appearance of +/// the slider. To know when the value starts to change, or when it is done +/// changing, set the optional callbacks [onChangeStart] and/or [onChangeEnd]. +/// +/// By default, a slider will be as wide as possible, centered vertically. When +/// given unbounded constraints, it will attempt to make the track 144 pixels +/// wide (including margins on each side) and will shrink-wrap vertically. +/// +/// Requires one of its ancestors to be a [Material] widget. This is typically +/// provided by a [Scaffold] widget. +/// +/// Requires one of its ancestors to be a [MediaQuery] widget. Typically, a +/// [MediaQuery] widget is introduced by the [MaterialApp] or [WidgetsApp] +/// widget at the top of your application widget tree. +/// +/// To determine how it should be displayed (e.g. colors, thumb shape, etc.), +/// a slider uses the [SliderThemeData] available from either a [SliderTheme] +/// widget, or the [ThemeData.sliderTheme] inside a [Theme] widget above it in +/// the widget tree. You can also override some of the colors with the +/// [activeColor] and [inactiveColor] properties, although more fine-grained +/// control of the colors, and other visual properties is achieved using a +/// [SliderThemeData]. +/// +/// See also: +/// +/// * [SliderTheme] and [SliderThemeData] for information about controlling +/// the visual appearance of the slider. +/// * [Slider], for a single-valued slider. +/// * [Radio], for selecting among a set of explicit values. +/// * [Checkbox] and [Switch], for toggling a particular value on or off. +/// * <https://material.io/design/components/sliders.html> +/// * [MediaQuery], from which the text scale factor is obtained. +class RangeSlider extends StatefulWidget { + /// Creates a Material Design range slider. + /// + /// The range slider widget itself does not maintain any state. Instead, when + /// the state of the slider changes, the widget calls the [onChanged] + /// callback. Most widgets that use a range slider will listen for the + /// [onChanged] callback and rebuild the slider with new [values] to update + /// the visual appearance of the slider. To know when the value starts to + /// change, or when it is done changing, set the optional callbacks + /// [onChangeStart] and/or [onChangeEnd]. + /// + /// * [values], which determines currently selected values for this range + /// slider. + /// * [onChanged], which is called while the user is selecting a new value for + /// the range slider. + /// * [onChangeStart], which is called when the user starts to select a new + /// value for the range slider. + /// * [onChangeEnd], which is called when the user is done selecting a new + /// value for the range slider. + /// + /// You can override some of the colors with the [activeColor] and + /// [inactiveColor] properties, although more fine-grained control of the + /// appearance is achieved using a [SliderThemeData]. + /// + /// The [min] must be less than or equal to the [max]. + /// + /// The [RangeValues.start] attribute of the [values] parameter must be less + /// than or equal to its [RangeValues.end] attribute. The [RangeValues.start] + /// and [RangeValues.end] attributes of the [values] parameter must be greater + /// than or equal to the [min] parameter and less than or equal to the [max] + /// parameter. + /// + /// The [divisions] parameter must be null or greater than zero. + RangeSlider({ + super.key, + required this.values, + required this.onChanged, + this.onChangeStart, + this.onChangeEnd, + this.min = 0.0, + this.max = 1.0, + this.divisions, + this.labels, + this.activeColor, + this.inactiveColor, + this.overlayColor, + this.mouseCursor, + this.semanticFormatterCallback, + }) : assert(min <= max), + assert(values.start <= values.end), + assert(values.start >= min && values.start <= max), + assert(values.end >= min && values.end <= max), + assert(divisions == null || divisions > 0); + + /// The currently selected values for this range slider. + /// + /// The slider's thumbs are drawn at horizontal positions that corresponds to + /// these values. + final RangeValues values; + + /// Called when the user is selecting a new value for the slider by dragging. + /// + /// The slider passes the new values to the callback but does not actually + /// change state until the parent widget rebuilds the slider with the new + /// values. + /// + /// If null, the slider will be displayed as disabled. + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// {@tool snippet} + /// + /// ```dart + /// RangeSlider( + /// values: _rangeValues, + /// min: 1.0, + /// max: 10.0, + /// onChanged: (RangeValues newValues) { + /// setState(() { + /// _rangeValues = newValues; + /// }); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [onChangeStart], which is called when the user starts changing the + /// values. + /// * [onChangeEnd], which is called when the user stops changing the values. + final ValueChanged<RangeValues>? onChanged; + + /// Called when the user starts selecting new values for the slider. + /// + /// This callback shouldn't be used to update the slider [values] (use + /// [onChanged] for that). Rather, it should be used to be notified when the + /// user has started selecting a new value by starting a drag or with a tap. + /// + /// The values passed will be the last [values] that the slider had before the + /// change began. + /// + /// {@tool snippet} + /// + /// ```dart + /// RangeSlider( + /// values: _rangeValues, + /// min: 1.0, + /// max: 10.0, + /// onChanged: (RangeValues newValues) { + /// setState(() { + /// _rangeValues = newValues; + /// }); + /// }, + /// onChangeStart: (RangeValues startValues) { + /// print('Started change at $startValues'); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [onChangeEnd] for a callback that is called when the value change is + /// complete. + final ValueChanged<RangeValues>? onChangeStart; + + /// Called when the user is done selecting new values for the slider. + /// + /// This differs from [onChanged] because it is only called once at the end + /// of the interaction, while [onChanged] is called as the value is getting + /// updated within the interaction. + /// + /// This callback shouldn't be used to update the slider [values] (use + /// [onChanged] for that). Rather, it should be used to know when the user has + /// completed selecting a new [values] by ending a drag or a click. + /// + /// {@tool snippet} + /// + /// ```dart + /// RangeSlider( + /// values: _rangeValues, + /// min: 1.0, + /// max: 10.0, + /// onChanged: (RangeValues newValues) { + /// setState(() { + /// _rangeValues = newValues; + /// }); + /// }, + /// onChangeEnd: (RangeValues endValues) { + /// print('Ended change at $endValues'); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [onChangeStart] for a callback that is called when a value change + /// begins. + final ValueChanged<RangeValues>? onChangeEnd; + + /// The minimum value the user can select. + /// + /// Defaults to 0.0. Must be less than or equal to [max]. + /// + /// If the [max] is equal to the [min], then the slider is disabled. + final double min; + + /// The maximum value the user can select. + /// + /// Defaults to 1.0. Must be greater than or equal to [min]. + /// + /// If the [max] is equal to the [min], then the slider is disabled. + final double max; + + /// The number of discrete divisions. + /// + /// Typically used with [labels] to show the current discrete values. + /// + /// If null, the slider is continuous. + final int? divisions; + + /// Labels to show as text in the [SliderThemeData.rangeValueIndicatorShape] + /// when the slider is active and [SliderThemeData.showValueIndicator] + /// is satisfied. + /// + /// There are two labels: one for the start thumb and one for the end thumb. + /// + /// Each label is rendered using the active [ThemeData]'s + /// [TextTheme.bodyLarge] text style, with the theme data's + /// [ColorScheme.onPrimary] color. The label's text style can be overridden + /// with [SliderThemeData.valueIndicatorTextStyle]. + /// + /// If null, then the value indicator will not be displayed. + /// + /// See also: + /// + /// * [RangeSliderValueIndicatorShape] for how to create a custom value + /// indicator shape. + final RangeLabels? labels; + + /// The color of the track's active segment, i.e. the span of track between + /// the thumbs. + /// + /// Defaults to [ColorScheme.primary]. + /// + /// Using a [SliderTheme] gives more fine-grained control over the + /// appearance of various components of the slider. + final Color? activeColor; + + /// The color of the track's inactive segments, i.e. the span of tracks + /// between the min and the start thumb, and the end thumb and the max. + /// + /// Defaults to [ColorScheme.primary] with 24% opacity. + /// + /// Using a [SliderTheme] gives more fine-grained control over the + /// appearance of various components of the slider. + final Color? inactiveColor; + + /// The highlight color that's typically used to indicate that + /// the range slider thumb is hovered or dragged. + /// + /// If this property is null, [RangeSlider] will use [activeColor] with + /// an opacity of 0.12. If null, [SliderThemeData.overlayColor] + /// will be used, otherwise defaults to [ColorScheme.primary] with + /// an opacity of 0.12. + final MaterialStateProperty<Color?>? overlayColor; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If null, then the value of [SliderThemeData.mouseCursor] is used. If that + /// is also null, then [MaterialStateMouseCursor.clickable] is used. + /// + /// See also: + /// + /// * [MaterialStateMouseCursor], which can be used to create a [MouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// The callback used to create a semantic value from the slider's values. + /// + /// Defaults to formatting values as a percentage. + /// + /// This is used by accessibility frameworks like TalkBack on Android to + /// inform users what the currently selected value is with more context. + /// + /// {@tool snippet} + /// + /// In the example below, a slider for currency values is configured to + /// announce a value with a currency label. + /// + /// ```dart + /// RangeSlider( + /// values: _dollarsRange, + /// min: 20.0, + /// max: 330.0, + /// onChanged: (RangeValues newValues) { + /// setState(() { + /// _dollarsRange = newValues; + /// }); + /// }, + /// semanticFormatterCallback: (double newValue) { + /// return '${newValue.round()} dollars'; + /// } + /// ) + /// ``` + /// {@end-tool} + final SemanticFormatterCallback? semanticFormatterCallback; + + // Touch width for the tap boundary of the slider thumbs. + static const double _minTouchTargetWidth = kMinInteractiveDimension; + + @override + State<RangeSlider> createState() => _RangeSliderState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('valueStart', values.start)); + properties.add(DoubleProperty('valueEnd', values.end)); + properties.add(ObjectFlagProperty<ValueChanged<RangeValues>>('onChanged', onChanged, ifNull: 'disabled')); + properties.add(ObjectFlagProperty<ValueChanged<RangeValues>>.has('onChangeStart', onChangeStart)); + properties.add(ObjectFlagProperty<ValueChanged<RangeValues>>.has('onChangeEnd', onChangeEnd)); + properties.add(DoubleProperty('min', min)); + properties.add(DoubleProperty('max', max)); + properties.add(IntProperty('divisions', divisions)); + properties.add(StringProperty('labelStart', labels?.start)); + properties.add(StringProperty('labelEnd', labels?.end)); + properties.add(ColorProperty('activeColor', activeColor)); + properties.add(ColorProperty('inactiveColor', inactiveColor)); + properties.add(ObjectFlagProperty<ValueChanged<double>>.has('semanticFormatterCallback', semanticFormatterCallback)); + } +} + +class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin { + static const Duration enableAnimationDuration = Duration(milliseconds: 75); + static const Duration valueIndicatorAnimationDuration = Duration(milliseconds: 100); + + // Animation controller that is run when the overlay (a.k.a radial reaction) + // changes visibility in response to user interaction. + late AnimationController overlayController; + + // Animation controller that is run when the value indicators change visibility. + late AnimationController valueIndicatorController; + + // Animation controller that is run when enabling/disabling the slider. + late AnimationController enableController; + + // Animation controllers that are run when transitioning between one value + // and the next on a discrete slider. + late AnimationController startPositionController; + late AnimationController endPositionController; + Timer? interactionTimer; + // Value Indicator paint Animation that appears on the Overlay. + PaintRangeValueIndicator? paintTopValueIndicator; + PaintRangeValueIndicator? paintBottomValueIndicator; + + bool get _enabled => widget.onChanged != null; + + bool _dragging = false; + + bool _hovering = false; + void _handleHoverChanged(bool hovering) { + if (hovering != _hovering) { + setState(() { _hovering = hovering; }); + } + } + + @override + void initState() { + super.initState(); + overlayController = AnimationController( + duration: kRadialReactionDuration, + vsync: this, + ); + valueIndicatorController = AnimationController( + duration: valueIndicatorAnimationDuration, + vsync: this, + ); + enableController = AnimationController( + duration: enableAnimationDuration, + vsync: this, + value: _enabled ? 1.0 : 0.0, + ); + startPositionController = AnimationController( + duration: Duration.zero, + vsync: this, + value: _unlerp(widget.values.start), + ); + endPositionController = AnimationController( + duration: Duration.zero, + vsync: this, + value: _unlerp(widget.values.end), + ); + } + + @override + void didUpdateWidget(RangeSlider oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.onChanged == widget.onChanged) { + return; + } + final bool wasEnabled = oldWidget.onChanged != null; + final bool isEnabled = _enabled; + if (wasEnabled != isEnabled) { + if (isEnabled) { + enableController.forward(); + } else { + enableController.reverse(); + } + } + } + + @override + void dispose() { + interactionTimer?.cancel(); + overlayController.dispose(); + valueIndicatorController.dispose(); + enableController.dispose(); + startPositionController.dispose(); + endPositionController.dispose(); + overlayEntry?.remove(); + overlayEntry?.dispose(); + overlayEntry = null; + super.dispose(); + } + + void _handleChanged(RangeValues values) { + assert(_enabled); + final RangeValues lerpValues = _lerpRangeValues(values); + if (lerpValues != widget.values) { + widget.onChanged!(lerpValues); + } + } + + void _handleDragStart(RangeValues values) { + assert(widget.onChangeStart != null); + _dragging = true; + widget.onChangeStart!(_lerpRangeValues(values)); + } + + void _handleDragEnd(RangeValues values) { + assert(widget.onChangeEnd != null); + _dragging = false; + widget.onChangeEnd!(_lerpRangeValues(values)); + } + + // Returns a number between min and max, proportional to value, which must + // be between 0.0 and 1.0. + double _lerp(double value) => ui.lerpDouble(widget.min, widget.max, value)!; + + // Returns a new range value with the start and end lerped. + RangeValues _lerpRangeValues(RangeValues values) { + return RangeValues(_lerp(values.start), _lerp(values.end)); + } + + // Returns a number between 0.0 and 1.0, given a value between min and max. + double _unlerp(double value) { + assert(value <= widget.max); + assert(value >= widget.min); + return widget.max > widget.min ? (value - widget.min) / (widget.max - widget.min) : 0.0; + } + + // Returns a new range value with the start and end unlerped. + RangeValues _unlerpRangeValues(RangeValues values) { + return RangeValues(_unlerp(values.start), _unlerp(values.end)); + } + + // Finds closest thumb. If the thumbs are close to each other, no thumb is + // immediately selected while the drag displacement is zero. If the first + // non-zero displacement is negative, then the left thumb is selected, and if its + // positive, then the right thumb is selected. + Thumb? _defaultRangeThumbSelector( + TextDirection textDirection, + RangeValues values, + double tapValue, + Size thumbSize, + Size trackSize, + double dx, // The horizontal delta or displacement of the drag update. + ) { + final double touchRadius = math.max(thumbSize.width, RangeSlider._minTouchTargetWidth) / 2; + final bool inStartTouchTarget = (tapValue - values.start).abs() * trackSize.width < touchRadius; + final bool inEndTouchTarget = (tapValue - values.end).abs() * trackSize.width < touchRadius; + + // Use dx if the thumb touch targets overlap. If dx is 0 and the drag + // position is in both touch targets, no thumb is selected because it is + // ambiguous to which thumb should be selected. If the dx is non-zero, the + // thumb selection is determined by the direction of the dx. The left thumb + // is chosen for negative dx, and the right thumb is chosen for positive dx. + if (inStartTouchTarget && inEndTouchTarget) { + final bool towardsStart; + final bool towardsEnd; + switch (textDirection) { + case TextDirection.ltr: + towardsStart = dx < 0; + towardsEnd = dx > 0; + case TextDirection.rtl: + towardsStart = dx > 0; + towardsEnd = dx < 0; + } + if (towardsStart) { + return Thumb.start; + } + if (towardsEnd) { + return Thumb.end; + } + } else { + // Snap position on the track if its in the inactive range. + if (tapValue < values.start || inStartTouchTarget) { + return Thumb.start; + } + if (tapValue > values.end || inEndTouchTarget) { + return Thumb.end; + } + } + return null; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMediaQuery(context)); + + final ThemeData theme = Theme.of(context); + SliderThemeData sliderTheme = SliderTheme.of(context); + + // If the widget has active or inactive colors specified, then we plug them + // in to the slider theme as best we can. If the developer wants more + // control than that, then they need to use a SliderTheme. The default + // colors come from the ThemeData.colorScheme. These colors, along with + // the default shapes and text styles are aligned to the Material + // Guidelines. + + const double defaultTrackHeight = 4; + const RangeSliderTrackShape defaultTrackShape = RoundedRectRangeSliderTrackShape(); + const RangeSliderTickMarkShape defaultTickMarkShape = RoundRangeSliderTickMarkShape(); + const SliderComponentShape defaultOverlayShape = RoundSliderOverlayShape(); + const RangeSliderThumbShape defaultThumbShape = RoundRangeSliderThumbShape(); + const RangeSliderValueIndicatorShape defaultValueIndicatorShape = RectangularRangeSliderValueIndicatorShape(); + const ShowValueIndicator defaultShowValueIndicator = ShowValueIndicator.onlyForDiscrete; + const double defaultMinThumbSeparation = 8; + + final Set<MaterialState> states = <MaterialState>{ + if (!_enabled) MaterialState.disabled, + if (_hovering) MaterialState.hovered, + if (_dragging) MaterialState.dragged, + }; + + // The value indicator's color is not the same as the thumb and active track + // (which can be defined by activeColor) if the + // RectangularSliderValueIndicatorShape is used. In all other cases, the + // value indicator is assumed to be the same as the active color. + final RangeSliderValueIndicatorShape valueIndicatorShape = sliderTheme.rangeValueIndicatorShape ?? defaultValueIndicatorShape; + final Color valueIndicatorColor; + if (valueIndicatorShape is RectangularRangeSliderValueIndicatorShape) { + valueIndicatorColor = sliderTheme.valueIndicatorColor ?? Color.alphaBlend(theme.colorScheme.onSurface.withOpacity(0.60), theme.colorScheme.surface.withOpacity(0.90)); + } else { + valueIndicatorColor = widget.activeColor ?? sliderTheme.valueIndicatorColor ?? theme.colorScheme.primary; + } + + Color? effectiveOverlayColor() { + return widget.overlayColor?.resolve(states) + ?? widget.activeColor?.withOpacity(0.12) + ?? MaterialStateProperty.resolveAs<Color?>(sliderTheme.overlayColor, states) + ?? theme.colorScheme.primary.withOpacity(0.12); + } + + sliderTheme = sliderTheme.copyWith( + trackHeight: sliderTheme.trackHeight ?? defaultTrackHeight, + activeTrackColor: widget.activeColor ?? sliderTheme.activeTrackColor ?? theme.colorScheme.primary, + inactiveTrackColor: widget.inactiveColor ?? sliderTheme.inactiveTrackColor ?? theme.colorScheme.primary.withOpacity(0.24), + disabledActiveTrackColor: sliderTheme.disabledActiveTrackColor ?? theme.colorScheme.onSurface.withOpacity(0.32), + disabledInactiveTrackColor: sliderTheme.disabledInactiveTrackColor ?? theme.colorScheme.onSurface.withOpacity(0.12), + activeTickMarkColor: widget.inactiveColor ?? sliderTheme.activeTickMarkColor ?? theme.colorScheme.onPrimary.withOpacity(0.54), + inactiveTickMarkColor: widget.activeColor ?? sliderTheme.inactiveTickMarkColor ?? theme.colorScheme.primary.withOpacity(0.54), + disabledActiveTickMarkColor: sliderTheme.disabledActiveTickMarkColor ?? theme.colorScheme.onPrimary.withOpacity(0.12), + disabledInactiveTickMarkColor: sliderTheme.disabledInactiveTickMarkColor ?? theme.colorScheme.onSurface.withOpacity(0.12), + thumbColor: widget.activeColor ?? sliderTheme.thumbColor ?? theme.colorScheme.primary, + overlappingShapeStrokeColor: sliderTheme.overlappingShapeStrokeColor ?? theme.colorScheme.surface, + disabledThumbColor: sliderTheme.disabledThumbColor ?? Color.alphaBlend(theme.colorScheme.onSurface.withOpacity(.38), theme.colorScheme.surface), + overlayColor: effectiveOverlayColor(), + valueIndicatorColor: valueIndicatorColor, + rangeTrackShape: sliderTheme.rangeTrackShape ?? defaultTrackShape, + rangeTickMarkShape: sliderTheme.rangeTickMarkShape ?? defaultTickMarkShape, + rangeThumbShape: sliderTheme.rangeThumbShape ?? defaultThumbShape, + overlayShape: sliderTheme.overlayShape ?? defaultOverlayShape, + rangeValueIndicatorShape: valueIndicatorShape, + showValueIndicator: sliderTheme.showValueIndicator ?? defaultShowValueIndicator, + valueIndicatorTextStyle: sliderTheme.valueIndicatorTextStyle ?? theme.textTheme.bodyLarge!.copyWith( + color: theme.colorScheme.onPrimary, + ), + minThumbSeparation: sliderTheme.minThumbSeparation ?? defaultMinThumbSeparation, + thumbSelector: sliderTheme.thumbSelector ?? _defaultRangeThumbSelector, + ); + final MouseCursor effectiveMouseCursor = widget.mouseCursor?.resolve(states) + ?? sliderTheme.mouseCursor?.resolve(states) + ?? MaterialStateMouseCursor.clickable.resolve(states); + + // This size is used as the max bounds for the painting of the value + // indicators. It must be kept in sync with the function with the same name + // in slider.dart. + Size screenSize() => MediaQuery.sizeOf(context); + + return FocusableActionDetector( + enabled: _enabled, + onShowHoverHighlight: _handleHoverChanged, + includeFocusSemantics: false, + mouseCursor: effectiveMouseCursor, + child: CompositedTransformTarget( + link: _layerLink, + child: _RangeSliderRenderObjectWidget( + values: _unlerpRangeValues(widget.values), + divisions: widget.divisions, + labels: widget.labels, + sliderTheme: sliderTheme, + textScaleFactor: MediaQuery.of(context).textScaleFactor, + screenSize: screenSize(), + onChanged: _enabled && (widget.max > widget.min) ? _handleChanged : null, + onChangeStart: widget.onChangeStart != null ? _handleDragStart : null, + onChangeEnd: widget.onChangeEnd != null ? _handleDragEnd : null, + state: this, + semanticFormatterCallback: widget.semanticFormatterCallback, + hovering: _hovering, + ), + ), + ); + } + + final LayerLink _layerLink = LayerLink(); + + OverlayEntry? overlayEntry; + + void showValueIndicator() { + if (overlayEntry == null) { + overlayEntry = OverlayEntry( + builder: (BuildContext context) { + return CompositedTransformFollower( + link: _layerLink, + child: _ValueIndicatorRenderObjectWidget( + state: this, + ), + ); + }, + ); + Overlay.of(context, debugRequiredFor: widget).insert(overlayEntry!); + } + } +} + +class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget { + const _RangeSliderRenderObjectWidget({ + required this.values, + required this.divisions, + required this.labels, + required this.sliderTheme, + required this.textScaleFactor, + required this.screenSize, + required this.onChanged, + required this.onChangeStart, + required this.onChangeEnd, + required this.state, + required this.semanticFormatterCallback, + required this.hovering, + }); + + final RangeValues values; + final int? divisions; + final RangeLabels? labels; + final SliderThemeData sliderTheme; + final double textScaleFactor; + final Size screenSize; + final ValueChanged<RangeValues>? onChanged; + final ValueChanged<RangeValues>? onChangeStart; + final ValueChanged<RangeValues>? onChangeEnd; + final SemanticFormatterCallback? semanticFormatterCallback; + final _RangeSliderState state; + final bool hovering; + + @override + _RenderRangeSlider createRenderObject(BuildContext context) { + return _RenderRangeSlider( + values: values, + divisions: divisions, + labels: labels, + sliderTheme: sliderTheme, + theme: Theme.of(context), + textScaleFactor: textScaleFactor, + screenSize: screenSize, + onChanged: onChanged, + onChangeStart: onChangeStart, + onChangeEnd: onChangeEnd, + state: state, + textDirection: Directionality.of(context), + semanticFormatterCallback: semanticFormatterCallback, + platform: Theme.of(context).platform, + hovering: hovering, + gestureSettings: MediaQuery.gestureSettingsOf(context), + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderRangeSlider renderObject) { + renderObject + // We should update the `divisions` ahead of `values`, because the `values` + // setter dependent on the `divisions`. + ..divisions = divisions + ..values = values + ..labels = labels + ..sliderTheme = sliderTheme + ..theme = Theme.of(context) + ..textScaleFactor = textScaleFactor + ..screenSize = screenSize + ..onChanged = onChanged + ..onChangeStart = onChangeStart + ..onChangeEnd = onChangeEnd + ..textDirection = Directionality.of(context) + ..semanticFormatterCallback = semanticFormatterCallback + ..platform = Theme.of(context).platform + ..hovering = hovering + ..gestureSettings = MediaQuery.gestureSettingsOf(context); + } +} + +class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { + _RenderRangeSlider({ + required RangeValues values, + required int? divisions, + required RangeLabels? labels, + required SliderThemeData sliderTheme, + required ThemeData? theme, + required double textScaleFactor, + required Size screenSize, + required TargetPlatform platform, + required ValueChanged<RangeValues>? onChanged, + required SemanticFormatterCallback? semanticFormatterCallback, + required this.onChangeStart, + required this.onChangeEnd, + required _RangeSliderState state, + required TextDirection textDirection, + required bool hovering, + required DeviceGestureSettings gestureSettings, + }) : assert(values.start >= 0.0 && values.start <= 1.0), + assert(values.end >= 0.0 && values.end <= 1.0), + _platform = platform, + _semanticFormatterCallback = semanticFormatterCallback, + _labels = labels, + _values = values, + _divisions = divisions, + _sliderTheme = sliderTheme, + _theme = theme, + _textScaleFactor = textScaleFactor, + _screenSize = screenSize, + _onChanged = onChanged, + _state = state, + _textDirection = textDirection, + _hovering = hovering { + _updateLabelPainters(); + final GestureArenaTeam team = GestureArenaTeam(); + _drag = HorizontalDragGestureRecognizer() + ..team = team + ..onStart = _handleDragStart + ..onUpdate = _handleDragUpdate + ..onEnd = _handleDragEnd + ..onCancel = _handleDragCancel + ..gestureSettings = gestureSettings; + _tap = TapGestureRecognizer() + ..team = team + ..onTapDown = _handleTapDown + ..onTapUp = _handleTapUp + ..gestureSettings = gestureSettings; + _overlayAnimation = CurvedAnimation( + parent: _state.overlayController, + curve: Curves.fastOutSlowIn, + ); + _valueIndicatorAnimation = CurvedAnimation( + parent: _state.valueIndicatorController, + curve: Curves.fastOutSlowIn, + )..addStatusListener((AnimationStatus status) { + if (status == AnimationStatus.dismissed) { + _state.overlayEntry?.remove(); + _state.overlayEntry?.dispose(); + _state.overlayEntry = null; + } + }); + _enableAnimation = CurvedAnimation( + parent: _state.enableController, + curve: Curves.easeInOut, + ); + } + + // Keep track of the last selected thumb so they can be drawn in the + // right order. + Thumb? _lastThumbSelection; + + static const Duration _positionAnimationDuration = Duration(milliseconds: 75); + + // This value is the touch target, 48, multiplied by 3. + static const double _minPreferredTrackWidth = 144.0; + + // Compute the largest width and height needed to paint the slider shapes, + // other than the track shape. It is assumed that these shapes are vertically + // centered on the track. + double get _maxSliderPartWidth => _sliderPartSizes.map((Size size) => size.width).reduce(math.max); + double get _maxSliderPartHeight => _sliderPartSizes.map((Size size) => size.height).reduce(math.max); + List<Size> get _sliderPartSizes => <Size>[ + _sliderTheme.overlayShape!.getPreferredSize(isEnabled, isDiscrete), + _sliderTheme.rangeThumbShape!.getPreferredSize(isEnabled, isDiscrete), + _sliderTheme.rangeTickMarkShape!.getPreferredSize(isEnabled: isEnabled, sliderTheme: sliderTheme), + ]; + double? get _minPreferredTrackHeight => _sliderTheme.trackHeight; + + // This rect is used in gesture calculations, where the gesture coordinates + // are relative to the sliders origin. Therefore, the offset is passed as + // (0,0). + Rect get _trackRect => _sliderTheme.rangeTrackShape!.getPreferredRect( + parentBox: this, + sliderTheme: _sliderTheme, + isDiscrete: false, + ); + + static const Duration _minimumInteractionTime = Duration(milliseconds: 500); + + final _RangeSliderState _state; + late Animation<double> _overlayAnimation; + late Animation<double> _valueIndicatorAnimation; + late Animation<double> _enableAnimation; + final TextPainter _startLabelPainter = TextPainter(); + final TextPainter _endLabelPainter = TextPainter(); + late HorizontalDragGestureRecognizer _drag; + late TapGestureRecognizer _tap; + bool _active = false; + late RangeValues _newValues; + Offset _startThumbCenter = Offset.zero; + Offset _endThumbCenter = Offset.zero; + Rect? overlayStartRect; + Rect? overlayEndRect; + + bool get isEnabled => onChanged != null; + + bool get isDiscrete => divisions != null && divisions! > 0; + + double get _minThumbSeparationValue => isDiscrete ? 0 : sliderTheme.minThumbSeparation! / _trackRect.width; + + RangeValues get values => _values; + RangeValues _values; + set values(RangeValues newValues) { + assert(newValues.start >= 0.0 && newValues.start <= 1.0); + assert(newValues.end >= 0.0 && newValues.end <= 1.0); + assert(newValues.start <= newValues.end); + final RangeValues convertedValues = isDiscrete ? _discretizeRangeValues(newValues) : newValues; + if (convertedValues == _values) { + return; + } + _values = convertedValues; + if (isDiscrete) { + // Reset the duration to match the distance that we're traveling, so that + // whatever the distance, we still do it in _positionAnimationDuration, + // and if we get re-targeted in the middle, it still takes that long to + // get to the new location. + final double startDistance = (_values.start - _state.startPositionController.value).abs(); + _state.startPositionController.duration = startDistance != 0.0 ? _positionAnimationDuration * (1.0 / startDistance) : Duration.zero; + _state.startPositionController.animateTo(_values.start, curve: Curves.easeInOut); + final double endDistance = (_values.end - _state.endPositionController.value).abs(); + _state.endPositionController.duration = endDistance != 0.0 ? _positionAnimationDuration * (1.0 / endDistance) : Duration.zero; + _state.endPositionController.animateTo(_values.end, curve: Curves.easeInOut); + } else { + _state.startPositionController.value = convertedValues.start; + _state.endPositionController.value = convertedValues.end; + } + markNeedsSemanticsUpdate(); + } + + TargetPlatform _platform; + TargetPlatform get platform => _platform; + set platform(TargetPlatform value) { + if (_platform == value) { + return; + } + _platform = value; + markNeedsSemanticsUpdate(); + } + + DeviceGestureSettings? get gestureSettings => _drag.gestureSettings; + set gestureSettings(DeviceGestureSettings? gestureSettings) { + _drag.gestureSettings = gestureSettings; + _tap.gestureSettings = gestureSettings; + } + + SemanticFormatterCallback? _semanticFormatterCallback; + SemanticFormatterCallback? get semanticFormatterCallback => _semanticFormatterCallback; + set semanticFormatterCallback(SemanticFormatterCallback? value) { + if (_semanticFormatterCallback == value) { + return; + } + _semanticFormatterCallback = value; + markNeedsSemanticsUpdate(); + } + + int? get divisions => _divisions; + int? _divisions; + set divisions(int? value) { + if (value == _divisions) { + return; + } + _divisions = value; + markNeedsPaint(); + } + + RangeLabels? get labels => _labels; + RangeLabels? _labels; + set labels(RangeLabels? labels) { + if (labels == _labels) { + return; + } + _labels = labels; + _updateLabelPainters(); + } + + SliderThemeData get sliderTheme => _sliderTheme; + SliderThemeData _sliderTheme; + set sliderTheme(SliderThemeData value) { + if (value == _sliderTheme) { + return; + } + _sliderTheme = value; + markNeedsPaint(); + } + + ThemeData? get theme => _theme; + ThemeData? _theme; + set theme(ThemeData? value) { + if (value == _theme) { + return; + } + _theme = value; + markNeedsPaint(); + } + + double get textScaleFactor => _textScaleFactor; + double _textScaleFactor; + set textScaleFactor(double value) { + if (value == _textScaleFactor) { + return; + } + _textScaleFactor = value; + _updateLabelPainters(); + } + + Size get screenSize => _screenSize; + Size _screenSize; + set screenSize(Size value) { + if (value == screenSize) { + return; + } + _screenSize = value; + markNeedsPaint(); + } + + ValueChanged<RangeValues>? get onChanged => _onChanged; + ValueChanged<RangeValues>? _onChanged; + set onChanged(ValueChanged<RangeValues>? value) { + if (value == _onChanged) { + return; + } + final bool wasEnabled = isEnabled; + _onChanged = value; + if (wasEnabled != isEnabled) { + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + ValueChanged<RangeValues>? onChangeStart; + ValueChanged<RangeValues>? onChangeEnd; + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (value == _textDirection) { + return; + } + _textDirection = value; + _updateLabelPainters(); + } + + /// True if this slider is being hovered over by a pointer. + bool get hovering => _hovering; + bool _hovering; + set hovering(bool value) { + if (value == _hovering) { + return; + } + _hovering = value; + _updateForHover(_hovering); + } + + /// True if the slider is interactive and the start thumb is being + /// hovered over by a pointer. + bool _hoveringStartThumb = false; + bool get hoveringStartThumb => _hoveringStartThumb; + set hoveringStartThumb(bool value) { + if (value == _hoveringStartThumb) { + return; + } + _hoveringStartThumb = value; + _updateForHover(_hovering); + } + + /// True if the slider is interactive and the end thumb is being + /// hovered over by a pointer. + bool _hoveringEndThumb = false; + bool get hoveringEndThumb => _hoveringEndThumb; + set hoveringEndThumb(bool value) { + if (value == _hoveringEndThumb) { + return; + } + _hoveringEndThumb = value; + _updateForHover(_hovering); + } + + void _updateForHover(bool hovered) { + // Only show overlay when pointer is hovering the thumb. + if (hovered && (hoveringStartThumb || hoveringEndThumb)) { + _state.overlayController.forward(); + } else { + _state.overlayController.reverse(); + } + } + + bool get showValueIndicator { + switch (_sliderTheme.showValueIndicator!) { + case ShowValueIndicator.onlyForDiscrete: + return isDiscrete; + case ShowValueIndicator.onlyForContinuous: + return !isDiscrete; + case ShowValueIndicator.always: + return true; + case ShowValueIndicator.never: + return false; + } + } + + Size get _thumbSize => _sliderTheme.rangeThumbShape!.getPreferredSize(isEnabled, isDiscrete); + + double get _adjustmentUnit { + switch (_platform) { + case TargetPlatform.iOS: + // Matches iOS implementation of material slider. + return 0.1; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + // Matches Android implementation of material slider. + return 0.05; + } + } + + void _updateLabelPainters() { + _updateLabelPainter(Thumb.start); + _updateLabelPainter(Thumb.end); + } + + void _updateLabelPainter(Thumb thumb) { + final RangeLabels? labels = this.labels; + if (labels == null) { + return; + } + + final String text; + final TextPainter labelPainter; + switch (thumb) { + case Thumb.start: + text = labels.start; + labelPainter = _startLabelPainter; + case Thumb.end: + text = labels.end; + labelPainter = _endLabelPainter; + } + + labelPainter + ..text = TextSpan( + style: _sliderTheme.valueIndicatorTextStyle, + text: text, + ) + ..textDirection = textDirection + ..textScaleFactor = textScaleFactor + ..layout(); + // Changing the textDirection can result in the layout changing, because the + // bidi algorithm might line up the glyphs differently which can result in + // different ligatures, different shapes, etc. So we always markNeedsLayout. + markNeedsLayout(); + } + + @override + void systemFontsDidChange() { + super.systemFontsDidChange(); + _startLabelPainter.markNeedsLayout(); + _endLabelPainter.markNeedsLayout(); + _updateLabelPainters(); + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _overlayAnimation.addListener(markNeedsPaint); + _valueIndicatorAnimation.addListener(markNeedsPaint); + _enableAnimation.addListener(markNeedsPaint); + _state.startPositionController.addListener(markNeedsPaint); + _state.endPositionController.addListener(markNeedsPaint); + } + + @override + void detach() { + _overlayAnimation.removeListener(markNeedsPaint); + _valueIndicatorAnimation.removeListener(markNeedsPaint); + _enableAnimation.removeListener(markNeedsPaint); + _state.startPositionController.removeListener(markNeedsPaint); + _state.endPositionController.removeListener(markNeedsPaint); + super.detach(); + } + + @override + void dispose() { + _drag.dispose(); + _tap.dispose(); + _startLabelPainter.dispose(); + _endLabelPainter.dispose(); + super.dispose(); + } + + double _getValueFromVisualPosition(double visualPosition) { + switch (textDirection) { + case TextDirection.rtl: + return 1.0 - visualPosition; + case TextDirection.ltr: + return visualPosition; + } + } + + double _getValueFromGlobalPosition(Offset globalPosition) { + final double visualPosition = (globalToLocal(globalPosition).dx - _trackRect.left) / _trackRect.width; + return _getValueFromVisualPosition(visualPosition); + } + + double _discretize(double value) { + double result = clampDouble(value, 0.0, 1.0); + if (isDiscrete) { + result = (result * divisions!).round() / divisions!; + } + return result; + } + + RangeValues _discretizeRangeValues(RangeValues values) { + return RangeValues(_discretize(values.start), _discretize(values.end)); + } + + void _startInteraction(Offset globalPosition) { + if (_active) { + return; + } + + _state.showValueIndicator(); + final double tapValue = clampDouble(_getValueFromGlobalPosition(globalPosition), 0.0, 1.0); + _lastThumbSelection = sliderTheme.thumbSelector!(textDirection, values, tapValue, _thumbSize, size, 0); + + if (_lastThumbSelection != null) { + _active = true; + // We supply the *current* values as the start locations, so that if we have + // a tap, it consists of a call to onChangeStart with the previous value and + // a call to onChangeEnd with the new value. + final RangeValues currentValues = _discretizeRangeValues(values); + if (_lastThumbSelection == Thumb.start) { + _newValues = RangeValues(tapValue, currentValues.end); + } else if (_lastThumbSelection == Thumb.end) { + _newValues = RangeValues(currentValues.start, tapValue); + } + _updateLabelPainter(_lastThumbSelection!); + + onChangeStart?.call(currentValues); + + onChanged!(_discretizeRangeValues(_newValues)); + + _state.overlayController.forward(); + if (showValueIndicator) { + _state.valueIndicatorController.forward(); + _state.interactionTimer?.cancel(); + _state.interactionTimer = + Timer(_minimumInteractionTime * timeDilation, () { + _state.interactionTimer = null; + if (!_active && _state.valueIndicatorController.status == AnimationStatus.completed) { + _state.valueIndicatorController.reverse(); + } + }); + } + } + } + + void _handleDragUpdate(DragUpdateDetails details) { + if (!_state.mounted) { + return; + } + + final double dragValue = _getValueFromGlobalPosition(details.globalPosition); + + // If no selection has been made yet, test for thumb selection again now + // that the value of dx can be non-zero. If this is the first selection of + // the interaction, then onChangeStart must be called. + bool shouldCallOnChangeStart = false; + if (_lastThumbSelection == null) { + _lastThumbSelection = sliderTheme.thumbSelector!(textDirection, values, dragValue, _thumbSize, size, details.delta.dx); + if (_lastThumbSelection != null) { + shouldCallOnChangeStart = true; + _active = true; + _state.overlayController.forward(); + if (showValueIndicator) { + _state.valueIndicatorController.forward(); + } + } + } + + if (isEnabled && _lastThumbSelection != null) { + final RangeValues currentValues = _discretizeRangeValues(values); + if (onChangeStart != null && shouldCallOnChangeStart) { + onChangeStart!(currentValues); + } + final double currentDragValue = _discretize(dragValue); + + if (_lastThumbSelection == Thumb.start) { + _newValues = RangeValues(math.min(currentDragValue, currentValues.end - _minThumbSeparationValue), currentValues.end); + } else if (_lastThumbSelection == Thumb.end) { + _newValues = RangeValues(currentValues.start, math.max(currentDragValue, currentValues.start + _minThumbSeparationValue)); + } + onChanged!(_newValues); + } + } + + void _endInteraction() { + if (!_state.mounted) { + return; + } + + if (showValueIndicator && _state.interactionTimer == null) { + _state.valueIndicatorController.reverse(); + } + + if (_active && _state.mounted && _lastThumbSelection != null) { + final RangeValues discreteValues = _discretizeRangeValues(_newValues); + onChangeEnd?.call(discreteValues); + _active = false; + } + _state.overlayController.reverse(); + } + + void _handleDragStart(DragStartDetails details) { + _startInteraction(details.globalPosition); + } + + void _handleDragEnd(DragEndDetails details) { + _endInteraction(); + } + + void _handleDragCancel() { + _endInteraction(); + } + + void _handleTapDown(TapDownDetails details) { + _startInteraction(details.globalPosition); + } + + void _handleTapUp(TapUpDetails details) { + _endInteraction(); + } + + @override + bool hitTestSelf(Offset position) => true; + + @override + void handleEvent(PointerEvent event, HitTestEntry entry) { + assert(debugHandleEvent(event, entry)); + if (event is PointerDownEvent && isEnabled) { + // We need to add the drag first so that it has priority. + _drag.addPointer(event); + _tap.addPointer(event); + } + if (isEnabled) { + if (overlayStartRect != null) { + hoveringStartThumb = overlayStartRect!.contains(event.localPosition); + } + if (overlayEndRect != null) { + hoveringEndThumb = overlayEndRect!.contains(event.localPosition); + } + } + } + + @override + double computeMinIntrinsicWidth(double height) => _minPreferredTrackWidth + _maxSliderPartWidth; + + @override + double computeMaxIntrinsicWidth(double height) => _minPreferredTrackWidth + _maxSliderPartWidth; + + @override + double computeMinIntrinsicHeight(double width) => math.max(_minPreferredTrackHeight!, _maxSliderPartHeight); + + @override + double computeMaxIntrinsicHeight(double width) => math.max(_minPreferredTrackHeight!, _maxSliderPartHeight); + + @override + bool get sizedByParent => true; + + @override + Size computeDryLayout(BoxConstraints constraints) { + return Size( + constraints.hasBoundedWidth ? constraints.maxWidth : _minPreferredTrackWidth + _maxSliderPartWidth, + constraints.hasBoundedHeight ? constraints.maxHeight : math.max(_minPreferredTrackHeight!, _maxSliderPartHeight), + ); + } + + @override + void paint(PaintingContext context, Offset offset) { + final double startValue = _state.startPositionController.value; + final double endValue = _state.endPositionController.value; + + // The visual position is the position of the thumb from 0 to 1 from left + // to right. In left to right, this is the same as the value, but it is + // reversed for right to left text. + final double startVisualPosition; + final double endVisualPosition; + switch (textDirection) { + case TextDirection.rtl: + startVisualPosition = 1.0 - startValue; + endVisualPosition = 1.0 - endValue; + case TextDirection.ltr: + startVisualPosition = startValue; + endVisualPosition = endValue; + } + + final Rect trackRect = _sliderTheme.rangeTrackShape!.getPreferredRect( + parentBox: this, + offset: offset, + sliderTheme: _sliderTheme, + isDiscrete: isDiscrete, + ); + _startThumbCenter = Offset(trackRect.left + startVisualPosition * trackRect.width, trackRect.center.dy); + _endThumbCenter = Offset(trackRect.left + endVisualPosition * trackRect.width, trackRect.center.dy); + if (isEnabled) { + final Size overlaySize = sliderTheme.overlayShape!.getPreferredSize(isEnabled, false); + overlayStartRect = Rect.fromCircle(center: _startThumbCenter, radius: overlaySize.width / 2.0); + overlayEndRect = Rect.fromCircle(center: _endThumbCenter, radius: overlaySize.width / 2.0); + } + + _sliderTheme.rangeTrackShape!.paint( + context, + offset, + parentBox: this, + sliderTheme: _sliderTheme, + enableAnimation: _enableAnimation, + textDirection: _textDirection, + startThumbCenter: _startThumbCenter, + endThumbCenter: _endThumbCenter, + isDiscrete: isDiscrete, + isEnabled: isEnabled, + ); + + final bool startThumbSelected = _lastThumbSelection == Thumb.start; + final bool endThumbSelected = _lastThumbSelection == Thumb.end; + final Size resolvedscreenSize = screenSize.isEmpty ? size : screenSize; + + if (!_overlayAnimation.isDismissed) { + if (startThumbSelected || hoveringStartThumb) { + _sliderTheme.overlayShape!.paint( + context, + _startThumbCenter, + activationAnimation: _overlayAnimation, + enableAnimation: _enableAnimation, + isDiscrete: isDiscrete, + labelPainter: _startLabelPainter, + parentBox: this, + sliderTheme: _sliderTheme, + textDirection: _textDirection, + value: startValue, + textScaleFactor: _textScaleFactor, + sizeWithOverflow: resolvedscreenSize, + ); + } + if (endThumbSelected || hoveringEndThumb) { + _sliderTheme.overlayShape!.paint( + context, + _endThumbCenter, + activationAnimation: _overlayAnimation, + enableAnimation: _enableAnimation, + isDiscrete: isDiscrete, + labelPainter: _endLabelPainter, + parentBox: this, + sliderTheme: _sliderTheme, + textDirection: _textDirection, + value: endValue, + textScaleFactor: _textScaleFactor, + sizeWithOverflow: resolvedscreenSize, + ); + } + } + + if (isDiscrete) { + final double tickMarkWidth = _sliderTheme.rangeTickMarkShape!.getPreferredSize( + isEnabled: isEnabled, + sliderTheme: _sliderTheme, + ).width; + final double padding = trackRect.height; + final double adjustedTrackWidth = trackRect.width - padding; + // If the tick marks would be too dense, don't bother painting them. + if (adjustedTrackWidth / divisions! >= 3.0 * tickMarkWidth) { + final double dy = trackRect.center.dy; + for (int i = 0; i <= divisions!; i++) { + final double value = i / divisions!; + // The ticks are mapped to be within the track, so the tick mark width + // must be subtracted from the track width. + final double dx = trackRect.left + value * adjustedTrackWidth + padding / 2; + final Offset tickMarkOffset = Offset(dx, dy); + _sliderTheme.rangeTickMarkShape!.paint( + context, + tickMarkOffset, + parentBox: this, + sliderTheme: _sliderTheme, + enableAnimation: _enableAnimation, + textDirection: _textDirection, + startThumbCenter: _startThumbCenter, + endThumbCenter: _endThumbCenter, + isEnabled: isEnabled, + ); + } + } + } + + final double thumbDelta = (_endThumbCenter.dx - _startThumbCenter.dx).abs(); + + final bool isLastThumbStart = _lastThumbSelection == Thumb.start; + final Thumb bottomThumb = isLastThumbStart ? Thumb.end : Thumb.start; + final Thumb topThumb = isLastThumbStart ? Thumb.start : Thumb.end; + final Offset bottomThumbCenter = isLastThumbStart ? _endThumbCenter : _startThumbCenter; + final Offset topThumbCenter = isLastThumbStart ? _startThumbCenter : _endThumbCenter; + final TextPainter bottomLabelPainter = isLastThumbStart ? _endLabelPainter : _startLabelPainter; + final TextPainter topLabelPainter = isLastThumbStart ? _startLabelPainter : _endLabelPainter; + final double bottomValue = isLastThumbStart ? endValue : startValue; + final double topValue = isLastThumbStart ? startValue : endValue; + final bool shouldPaintValueIndicators = isEnabled && labels != null && !_valueIndicatorAnimation.isDismissed && showValueIndicator; + + if (shouldPaintValueIndicators) { + _state.paintBottomValueIndicator = (PaintingContext context, Offset offset) { + if (attached) { + _sliderTheme.rangeValueIndicatorShape!.paint( + context, + bottomThumbCenter, + activationAnimation: _valueIndicatorAnimation, + enableAnimation: _enableAnimation, + isDiscrete: isDiscrete, + isOnTop: false, + labelPainter: bottomLabelPainter, + parentBox: this, + sliderTheme: _sliderTheme, + textDirection: _textDirection, + thumb: bottomThumb, + value: bottomValue, + textScaleFactor: textScaleFactor, + sizeWithOverflow: resolvedscreenSize, + ); + } + }; + } + + _sliderTheme.rangeThumbShape!.paint( + context, + bottomThumbCenter, + activationAnimation: _valueIndicatorAnimation, + enableAnimation: _enableAnimation, + isDiscrete: isDiscrete, + isOnTop: false, + textDirection: textDirection, + sliderTheme: _sliderTheme, + thumb: bottomThumb, + isPressed: bottomThumb == Thumb.start ? startThumbSelected : endThumbSelected, + ); + + if (shouldPaintValueIndicators) { + final double startOffset = sliderTheme.rangeValueIndicatorShape!.getHorizontalShift( + parentBox: this, + center: _startThumbCenter, + labelPainter: _startLabelPainter, + activationAnimation: _valueIndicatorAnimation, + textScaleFactor: textScaleFactor, + sizeWithOverflow: resolvedscreenSize, + ); + final double endOffset = sliderTheme.rangeValueIndicatorShape!.getHorizontalShift( + parentBox: this, + center: _endThumbCenter, + labelPainter: _endLabelPainter, + activationAnimation: _valueIndicatorAnimation, + textScaleFactor: textScaleFactor, + sizeWithOverflow: resolvedscreenSize, + ); + final double startHalfWidth = sliderTheme.rangeValueIndicatorShape!.getPreferredSize( + isEnabled, + isDiscrete, + labelPainter: _startLabelPainter, + textScaleFactor: textScaleFactor, + ).width / 2; + final double endHalfWidth = sliderTheme.rangeValueIndicatorShape!.getPreferredSize( + isEnabled, + isDiscrete, + labelPainter: _endLabelPainter, + textScaleFactor: textScaleFactor, + ).width / 2; + double innerOverflow = startHalfWidth + endHalfWidth; + switch (textDirection) { + case TextDirection.ltr: + innerOverflow += startOffset; + innerOverflow -= endOffset; + case TextDirection.rtl: + innerOverflow -= startOffset; + innerOverflow += endOffset; + } + + _state.paintTopValueIndicator = (PaintingContext context, Offset offset) { + if (attached) { + _sliderTheme.rangeValueIndicatorShape!.paint( + context, + topThumbCenter, + activationAnimation: _valueIndicatorAnimation, + enableAnimation: _enableAnimation, + isDiscrete: isDiscrete, + isOnTop: thumbDelta < innerOverflow, + labelPainter: topLabelPainter, + parentBox: this, + sliderTheme: _sliderTheme, + textDirection: _textDirection, + thumb: topThumb, + value: topValue, + textScaleFactor: textScaleFactor, + sizeWithOverflow: resolvedscreenSize, + ); + } + }; + } + + _sliderTheme.rangeThumbShape!.paint( + context, + topThumbCenter, + activationAnimation: _overlayAnimation, + enableAnimation: _enableAnimation, + isDiscrete: isDiscrete, + isOnTop: thumbDelta < sliderTheme.rangeThumbShape!.getPreferredSize(isEnabled, isDiscrete).width, + textDirection: textDirection, + sliderTheme: _sliderTheme, + thumb: topThumb, + isPressed: topThumb == Thumb.start ? startThumbSelected : endThumbSelected, + ); + } + + /// Describe the semantics of the start thumb. + SemanticsNode? _startSemanticsNode = SemanticsNode(); + + /// Describe the semantics of the end thumb. + SemanticsNode? _endSemanticsNode = SemanticsNode(); + + // Create the semantics configuration for a single value. + SemanticsConfiguration _createSemanticsConfiguration( + double value, + double increasedValue, + double decreasedValue, + VoidCallback increaseAction, + VoidCallback decreaseAction, + ) { + final SemanticsConfiguration config = SemanticsConfiguration(); + config.isEnabled = isEnabled; + config.textDirection = textDirection; + config.isSlider = true; + if (isEnabled) { + config.onIncrease = increaseAction; + config.onDecrease = decreaseAction; + } + + if (semanticFormatterCallback != null) { + config.value = semanticFormatterCallback!(_state._lerp(value)); + config.increasedValue = semanticFormatterCallback!(_state._lerp(increasedValue)); + config.decreasedValue = semanticFormatterCallback!(_state._lerp(decreasedValue)); + } else { + config.value = '${(value * 100).round()}%'; + config.increasedValue = '${(increasedValue * 100).round()}%'; + config.decreasedValue = '${(decreasedValue * 100).round()}%'; + } + + return config; + } + + @override + void assembleSemanticsNode( + SemanticsNode node, + SemanticsConfiguration config, + Iterable<SemanticsNode> children, + ) { + assert(children.isEmpty); + + final SemanticsConfiguration startSemanticsConfiguration = _createSemanticsConfiguration( + values.start, + _increasedStartValue, + _decreasedStartValue, + _increaseStartAction, + _decreaseStartAction, + ); + final SemanticsConfiguration endSemanticsConfiguration = _createSemanticsConfiguration( + values.end, + _increasedEndValue, + _decreasedEndValue, + _increaseEndAction, + _decreaseEndAction, + ); + + // Split the semantics node area between the start and end nodes. + final Rect leftRect = Rect.fromCenter( + center: _startThumbCenter, + width: kMinInteractiveDimension, + height: kMinInteractiveDimension, + ); + final Rect rightRect = Rect.fromCenter( + center: _endThumbCenter, + width: kMinInteractiveDimension, + height: kMinInteractiveDimension, + ); + switch (textDirection) { + case TextDirection.ltr: + _startSemanticsNode!.rect = leftRect; + _endSemanticsNode!.rect = rightRect; + case TextDirection.rtl: + _startSemanticsNode!.rect = rightRect; + _endSemanticsNode!.rect = leftRect; + } + + _startSemanticsNode!.updateWith(config: startSemanticsConfiguration); + _endSemanticsNode!.updateWith(config: endSemanticsConfiguration); + + final List<SemanticsNode> finalChildren = <SemanticsNode>[ + _startSemanticsNode!, + _endSemanticsNode!, + ]; + + node.updateWith(config: config, childrenInInversePaintOrder: finalChildren); + } + + @override + void clearSemantics() { + super.clearSemantics(); + _startSemanticsNode = null; + _endSemanticsNode = null; + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.isSemanticBoundary = true; + } + + double get _semanticActionUnit => divisions != null ? 1.0 / divisions! : _adjustmentUnit; + + void _increaseStartAction() { + if (isEnabled) { + onChanged!(RangeValues(_increasedStartValue, values.end)); + } + } + + void _decreaseStartAction() { + if (isEnabled) { + onChanged!(RangeValues(_decreasedStartValue, values.end)); + } + } + + void _increaseEndAction() { + if (isEnabled) { + onChanged!(RangeValues(values.start, _increasedEndValue)); + } + } + + void _decreaseEndAction() { + if (isEnabled) { + onChanged!(RangeValues(values.start, _decreasedEndValue)); + } + } + + double get _increasedStartValue { + // Due to floating-point operations, this value can actually be greater than + // expected (e.g. 0.4 + 0.2 = 0.600000000001), so we limit to 2 decimal points. + final double increasedStartValue = double.parse((values.start + _semanticActionUnit).toStringAsFixed(2)); + return increasedStartValue <= values.end - _minThumbSeparationValue ? increasedStartValue : values.start; + } + + double get _decreasedStartValue { + return clampDouble(values.start - _semanticActionUnit, 0.0, 1.0); + } + + double get _increasedEndValue { + return clampDouble(values.end + _semanticActionUnit, 0.0, 1.0); + } + + double get _decreasedEndValue { + final double decreasedEndValue = values.end - _semanticActionUnit; + return decreasedEndValue >= values.start + _minThumbSeparationValue ? decreasedEndValue : values.end; + } +} + + +class _ValueIndicatorRenderObjectWidget extends LeafRenderObjectWidget { + const _ValueIndicatorRenderObjectWidget({ + required this.state, + }); + + final _RangeSliderState state; + + @override + _RenderValueIndicator createRenderObject(BuildContext context) { + return _RenderValueIndicator( + state: state, + ); + } + @override + void updateRenderObject(BuildContext context, _RenderValueIndicator renderObject) { + renderObject._state = state; + } +} + +class _RenderValueIndicator extends RenderBox with RelayoutWhenSystemFontsChangeMixin { + _RenderValueIndicator({ + required _RangeSliderState state, + }) :_state = state { + _valueIndicatorAnimation = CurvedAnimation( + parent: _state.valueIndicatorController, + curve: Curves.fastOutSlowIn, + ); + } + + late Animation<double> _valueIndicatorAnimation; + late _RangeSliderState _state; + + @override + bool get sizedByParent => true; + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _valueIndicatorAnimation.addListener(markNeedsPaint); + _state.startPositionController.addListener(markNeedsPaint); + _state.endPositionController.addListener(markNeedsPaint); + } + + @override + void detach() { + _valueIndicatorAnimation.removeListener(markNeedsPaint); + _state.startPositionController.removeListener(markNeedsPaint); + _state.endPositionController.removeListener(markNeedsPaint); + super.detach(); + } + + @override + void paint(PaintingContext context, Offset offset) { + _state.paintBottomValueIndicator?.call(context, offset); + _state.paintTopValueIndicator?.call(context, offset); + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return constraints.smallest; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/refresh_indicator.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/refresh_indicator.dart new file mode 100644 index 0000000000000000000000000000000000000000..90719320a96a1248ace52a0751c59f44c9059f6f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/refresh_indicator.dart @@ -0,0 +1,632 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart' show clampDouble; + +import 'debug.dart'; +import 'material_localizations.dart'; +import 'progress_indicator.dart'; +import 'theme.dart'; + +// The over-scroll distance that moves the indicator to its maximum +// displacement, as a percentage of the scrollable's container extent. +const double _kDragContainerExtentPercentage = 0.25; + +// How much the scroll's drag gesture can overshoot the RefreshIndicator's +// displacement; max displacement = _kDragSizeFactorLimit * displacement. +const double _kDragSizeFactorLimit = 1.5; + +// When the scroll ends, the duration of the refresh indicator's animation +// to the RefreshIndicator's displacement. +const Duration _kIndicatorSnapDuration = Duration(milliseconds: 150); + +// The duration of the ScaleTransition that starts when the refresh action +// has completed. +const Duration _kIndicatorScaleDuration = Duration(milliseconds: 200); + +/// The signature for a function that's called when the user has dragged a +/// [RefreshIndicator] far enough to demonstrate that they want the app to +/// refresh. The returned [Future] must complete when the refresh operation is +/// finished. +/// +/// Used by [RefreshIndicator.onRefresh]. +typedef RefreshCallback = Future<void> Function(); + +// The state machine moves through these modes only when the scrollable +// identified by scrollableKey has been scrolled to its min or max limit. +enum _RefreshIndicatorMode { + drag, // Pointer is down. + armed, // Dragged far enough that an up event will run the onRefresh callback. + snap, // Animating to the indicator's final "displacement". + refresh, // Running the refresh callback. + done, // Animating the indicator's fade-out after refreshing. + canceled, // Animating the indicator's fade-out after not arming. +} + +/// Used to configure how [RefreshIndicator] can be triggered. +enum RefreshIndicatorTriggerMode { + /// The indicator can be triggered regardless of the scroll position + /// of the [Scrollable] when the drag starts. + anywhere, + + /// The indicator can only be triggered if the [Scrollable] is at the edge + /// when the drag starts. + onEdge, +} + +enum _IndicatorType { material, adaptive } + +/// A widget that supports the Material "swipe to refresh" idiom. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ORApMlzwMdM} +/// +/// When the child's [Scrollable] descendant overscrolls, an animated circular +/// progress indicator is faded into view. When the scroll ends, if the +/// indicator has been dragged far enough for it to become completely opaque, +/// the [onRefresh] callback is called. The callback is expected to update the +/// scrollable's contents and then complete the [Future] it returns. The refresh +/// indicator disappears after the callback's [Future] has completed. +/// +/// The trigger mode is configured by [RefreshIndicator.triggerMode]. +/// +/// {@tool dartpad} +/// This example shows how [RefreshIndicator] can be triggered in different ways. +/// +/// ** See code in examples/api/lib/material/refresh_indicator/refresh_indicator.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to trigger [RefreshIndicator] in a nested scroll view using +/// the [notificationPredicate] property. +/// +/// ** See code in examples/api/lib/material/refresh_indicator/refresh_indicator.1.dart ** +/// {@end-tool} +/// +/// ## Troubleshooting +/// +/// ### Refresh indicator does not show up +/// +/// The [RefreshIndicator] will appear if its scrollable descendant can be +/// overscrolled, i.e. if the scrollable's content is bigger than its viewport. +/// To ensure that the [RefreshIndicator] will always appear, even if the +/// scrollable's content fits within its viewport, set the scrollable's +/// [Scrollable.physics] property to [AlwaysScrollableScrollPhysics]: +/// +/// ```dart +/// ListView( +/// physics: const AlwaysScrollableScrollPhysics(), +/// // ... +/// ) +/// ``` +/// +/// A [RefreshIndicator] can only be used with a vertical scroll view. +/// +/// See also: +/// +/// * <https://material.io/design/platform-guidance/android-swipe-to-refresh.html> +/// * [RefreshIndicatorState], can be used to programmatically show the refresh indicator. +/// * [RefreshProgressIndicator], widget used by [RefreshIndicator] to show +/// the inner circular progress spinner during refreshes. +/// * [CupertinoSliverRefreshControl], an iOS equivalent of the pull-to-refresh pattern. +/// Must be used as a sliver inside a [CustomScrollView] instead of wrapping +/// around a [ScrollView] because it's a part of the scrollable instead of +/// being overlaid on top of it. +class RefreshIndicator extends StatefulWidget { + /// Creates a refresh indicator. + /// + /// The [onRefresh], [child], and [notificationPredicate] arguments must be + /// non-null. The default + /// [displacement] is 40.0 logical pixels. + /// + /// The [semanticsLabel] is used to specify an accessibility label for this widget. + /// If it is null, it will be defaulted to [MaterialLocalizations.refreshIndicatorSemanticLabel]. + /// An empty string may be passed to avoid having anything read by screen reading software. + /// The [semanticsValue] may be used to specify progress on the widget. + const RefreshIndicator({ + super.key, + required this.child, + this.displacement = 40.0, + this.edgeOffset = 0.0, + required this.onRefresh, + this.color, + this.backgroundColor, + this.notificationPredicate = defaultScrollNotificationPredicate, + this.semanticsLabel, + this.semanticsValue, + this.strokeWidth = RefreshProgressIndicator.defaultStrokeWidth, + this.triggerMode = RefreshIndicatorTriggerMode.onEdge, + }) : _indicatorType = _IndicatorType.material; + + /// Creates an adaptive [RefreshIndicator] based on whether the target + /// platform is iOS or macOS, following Material design's + /// [Cross-platform guidelines](https://material.io/design/platform-guidance/cross-platform-adaptation.html). + /// + /// When the descendant overscrolls, a different spinning progress indicator + /// is shown depending on platform. On iOS and macOS, + /// [CupertinoActivityIndicator] is shown, but on all other platforms, + /// [CircularProgressIndicator] appears. + /// + /// If a [CupertinoActivityIndicator] is shown, the following parameters are ignored: + /// [backgroundColor], [semanticsLabel], [semanticsValue], [strokeWidth]. + /// + /// The target platform is based on the current [Theme]: [ThemeData.platform]. + /// + /// Noteably the scrollable widget itself will have slightly different behavior + /// from [CupertinoSliverRefreshControl], due to a difference in structure. + const RefreshIndicator.adaptive({ + super.key, + required this.child, + this.displacement = 40.0, + this.edgeOffset = 0.0, + required this.onRefresh, + this.color, + this.backgroundColor, + this.notificationPredicate = defaultScrollNotificationPredicate, + this.semanticsLabel, + this.semanticsValue, + this.strokeWidth = RefreshProgressIndicator.defaultStrokeWidth, + this.triggerMode = RefreshIndicatorTriggerMode.onEdge, + }) : _indicatorType = _IndicatorType.adaptive; + + /// The widget below this widget in the tree. + /// + /// The refresh indicator will be stacked on top of this child. The indicator + /// will appear when child's Scrollable descendant is over-scrolled. + /// + /// Typically a [ListView] or [CustomScrollView]. + final Widget child; + + /// The distance from the child's top or bottom [edgeOffset] where + /// the refresh indicator will settle. During the drag that exposes the refresh + /// indicator, its actual displacement may significantly exceed this value. + /// + /// In most cases, [displacement] distance starts counting from the parent's + /// edges. However, if [edgeOffset] is larger than zero then the [displacement] + /// value is calculated from that offset instead of the parent's edge. + final double displacement; + + /// The offset where [RefreshProgressIndicator] starts to appear on drag start. + /// + /// Depending whether the indicator is showing on the top or bottom, the value + /// of this variable controls how far from the parent's edge the progress + /// indicator starts to appear. This may come in handy when, for example, the + /// UI contains a top [Widget] which covers the parent's edge where the progress + /// indicator would otherwise appear. + /// + /// By default, the edge offset is set to 0. + /// + /// See also: + /// + /// * [displacement], can be used to change the distance from the edge that + /// the indicator settles. + final double edgeOffset; + + /// A function that's called when the user has dragged the refresh indicator + /// far enough to demonstrate that they want the app to refresh. The returned + /// [Future] must complete when the refresh operation is finished. + final RefreshCallback onRefresh; + + /// The progress indicator's foreground color. The current theme's + /// [ColorScheme.primary] by default. + final Color? color; + + /// The progress indicator's background color. The current theme's + /// [ThemeData.canvasColor] by default. + final Color? backgroundColor; + + /// A check that specifies whether a [ScrollNotification] should be + /// handled by this widget. + /// + /// By default, checks whether `notification.depth == 0`. Set it to something + /// else for more complicated layouts. + final ScrollNotificationPredicate notificationPredicate; + + /// {@macro flutter.progress_indicator.ProgressIndicator.semanticsLabel} + /// + /// This will be defaulted to [MaterialLocalizations.refreshIndicatorSemanticLabel] + /// if it is null. + final String? semanticsLabel; + + /// {@macro flutter.progress_indicator.ProgressIndicator.semanticsValue} + final String? semanticsValue; + + /// Defines [strokeWidth] for `RefreshIndicator`. + /// + /// By default, the value of [strokeWidth] is 2.0 pixels. + final double strokeWidth; + + final _IndicatorType _indicatorType; + + /// Defines how this [RefreshIndicator] can be triggered when users overscroll. + /// + /// The [RefreshIndicator] can be pulled out in two cases, + /// 1, Keep dragging if the scrollable widget at the edge with zero scroll position + /// when the drag starts. + /// 2, Keep dragging after overscroll occurs if the scrollable widget has + /// a non-zero scroll position when the drag starts. + /// + /// If this is [RefreshIndicatorTriggerMode.anywhere], both of the cases above can be triggered. + /// + /// If this is [RefreshIndicatorTriggerMode.onEdge], only case 1 can be triggered. + /// + /// Defaults to [RefreshIndicatorTriggerMode.onEdge]. + final RefreshIndicatorTriggerMode triggerMode; + + @override + RefreshIndicatorState createState() => RefreshIndicatorState(); +} + +/// Contains the state for a [RefreshIndicator]. This class can be used to +/// programmatically show the refresh indicator, see the [show] method. +class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderStateMixin<RefreshIndicator> { + late AnimationController _positionController; + late AnimationController _scaleController; + late Animation<double> _positionFactor; + late Animation<double> _scaleFactor; + late Animation<double> _value; + late Animation<Color?> _valueColor; + + _RefreshIndicatorMode? _mode; + late Future<void> _pendingRefreshFuture; + bool? _isIndicatorAtTop; + double? _dragOffset; + late Color _effectiveValueColor = widget.color ?? Theme.of(context).colorScheme.primary; + + static final Animatable<double> _threeQuarterTween = Tween<double>(begin: 0.0, end: 0.75); + static final Animatable<double> _kDragSizeFactorLimitTween = Tween<double>(begin: 0.0, end: _kDragSizeFactorLimit); + static final Animatable<double> _oneToZeroTween = Tween<double>(begin: 1.0, end: 0.0); + + @override + void initState() { + super.initState(); + _positionController = AnimationController(vsync: this); + _positionFactor = _positionController.drive(_kDragSizeFactorLimitTween); + _value = _positionController.drive(_threeQuarterTween); // The "value" of the circular progress indicator during a drag. + + _scaleController = AnimationController(vsync: this); + _scaleFactor = _scaleController.drive(_oneToZeroTween); + } + + @override + void didChangeDependencies() { + _setupColorTween(); + super.didChangeDependencies(); + } + + @override + void didUpdateWidget(covariant RefreshIndicator oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.color != widget.color) { + _setupColorTween(); + } + } + + @override + void dispose() { + _positionController.dispose(); + _scaleController.dispose(); + super.dispose(); + } + + void _setupColorTween() { + // Reset the current value color. + _effectiveValueColor = widget.color ?? Theme.of(context).colorScheme.primary; + final Color color = _effectiveValueColor; + if (color.alpha == 0x00) { + // Set an always stopped animation instead of a driven tween. + _valueColor = AlwaysStoppedAnimation<Color>(color); + } else { + // Respect the alpha of the given color. + _valueColor = _positionController.drive( + ColorTween( + begin: color.withAlpha(0), + end: color.withAlpha(color.alpha), + ).chain( + CurveTween( + curve: const Interval(0.0, 1.0 / _kDragSizeFactorLimit), + ), + ), + ); + } + } + + bool _shouldStart(ScrollNotification notification) { + // If the notification.dragDetails is null, this scroll is not triggered by + // user dragging. It may be a result of ScrollController.jumpTo or ballistic scroll. + // In this case, we don't want to trigger the refresh indicator. + return ((notification is ScrollStartNotification && notification.dragDetails != null) + || (notification is ScrollUpdateNotification && notification.dragDetails != null && widget.triggerMode == RefreshIndicatorTriggerMode.anywhere)) + && (( notification.metrics.axisDirection == AxisDirection.up && notification.metrics.extentAfter == 0.0) + || (notification.metrics.axisDirection == AxisDirection.down && notification.metrics.extentBefore == 0.0)) + && _mode == null + && _start(notification.metrics.axisDirection); + } + + bool _handleScrollNotification(ScrollNotification notification) { + if (!widget.notificationPredicate(notification)) { + return false; + } + if (_shouldStart(notification)) { + setState(() { + _mode = _RefreshIndicatorMode.drag; + }); + return false; + } + bool? indicatorAtTopNow; + switch (notification.metrics.axisDirection) { + case AxisDirection.down: + case AxisDirection.up: + indicatorAtTopNow = true; + case AxisDirection.left: + case AxisDirection.right: + indicatorAtTopNow = null; + } + if (indicatorAtTopNow != _isIndicatorAtTop) { + if (_mode == _RefreshIndicatorMode.drag || _mode == _RefreshIndicatorMode.armed) { + _dismiss(_RefreshIndicatorMode.canceled); + } + } else if (notification is ScrollUpdateNotification) { + if (_mode == _RefreshIndicatorMode.drag || _mode == _RefreshIndicatorMode.armed) { + if (notification.metrics.axisDirection == AxisDirection.down) { + _dragOffset = _dragOffset! - notification.scrollDelta!; + } else if (notification.metrics.axisDirection == AxisDirection.up) { + _dragOffset = _dragOffset! + notification.scrollDelta!; + } + _checkDragOffset(notification.metrics.viewportDimension); + } + if (_mode == _RefreshIndicatorMode.armed && notification.dragDetails == null) { + // On iOS start the refresh when the Scrollable bounces back from the + // overscroll (ScrollNotification indicating this don't have dragDetails + // because the scroll activity is not directly triggered by a drag). + _show(); + } + } else if (notification is OverscrollNotification) { + if (_mode == _RefreshIndicatorMode.drag || _mode == _RefreshIndicatorMode.armed) { + if (notification.metrics.axisDirection == AxisDirection.down) { + _dragOffset = _dragOffset! - notification.overscroll; + } else if (notification.metrics.axisDirection == AxisDirection.up) { + _dragOffset = _dragOffset! + notification.overscroll; + } + _checkDragOffset(notification.metrics.viewportDimension); + } + } else if (notification is ScrollEndNotification) { + switch (_mode) { + case _RefreshIndicatorMode.armed: + if (_positionController.value < 1.0) { + _dismiss(_RefreshIndicatorMode.canceled); + } else { + _show(); + } + case _RefreshIndicatorMode.drag: + _dismiss(_RefreshIndicatorMode.canceled); + case _RefreshIndicatorMode.canceled: + case _RefreshIndicatorMode.done: + case _RefreshIndicatorMode.refresh: + case _RefreshIndicatorMode.snap: + case null: + // do nothing + break; + } + } + return false; + } + + bool _handleIndicatorNotification(OverscrollIndicatorNotification notification) { + if (notification.depth != 0 || !notification.leading) { + return false; + } + if (_mode == _RefreshIndicatorMode.drag) { + notification.disallowIndicator(); + return true; + } + return false; + } + + bool _start(AxisDirection direction) { + assert(_mode == null); + assert(_isIndicatorAtTop == null); + assert(_dragOffset == null); + switch (direction) { + case AxisDirection.down: + case AxisDirection.up: + _isIndicatorAtTop = true; + case AxisDirection.left: + case AxisDirection.right: + _isIndicatorAtTop = null; + // we do not support horizontal scroll views. + return false; + } + _dragOffset = 0.0; + _scaleController.value = 0.0; + _positionController.value = 0.0; + return true; + } + + void _checkDragOffset(double containerExtent) { + assert(_mode == _RefreshIndicatorMode.drag || _mode == _RefreshIndicatorMode.armed); + double newValue = _dragOffset! / (containerExtent * _kDragContainerExtentPercentage); + if (_mode == _RefreshIndicatorMode.armed) { + newValue = math.max(newValue, 1.0 / _kDragSizeFactorLimit); + } + _positionController.value = clampDouble(newValue, 0.0, 1.0); // this triggers various rebuilds + if (_mode == _RefreshIndicatorMode.drag && _valueColor.value!.alpha == _effectiveValueColor.alpha) { + _mode = _RefreshIndicatorMode.armed; + } + } + + // Stop showing the refresh indicator. + Future<void> _dismiss(_RefreshIndicatorMode newMode) async { + await Future<void>.value(); + // This can only be called from _show() when refreshing and + // _handleScrollNotification in response to a ScrollEndNotification or + // direction change. + assert(newMode == _RefreshIndicatorMode.canceled || newMode == _RefreshIndicatorMode.done); + setState(() { + _mode = newMode; + }); + switch (_mode!) { + case _RefreshIndicatorMode.done: + await _scaleController.animateTo(1.0, duration: _kIndicatorScaleDuration); + case _RefreshIndicatorMode.canceled: + await _positionController.animateTo(0.0, duration: _kIndicatorScaleDuration); + case _RefreshIndicatorMode.armed: + case _RefreshIndicatorMode.drag: + case _RefreshIndicatorMode.refresh: + case _RefreshIndicatorMode.snap: + assert(false); + } + if (mounted && _mode == newMode) { + _dragOffset = null; + _isIndicatorAtTop = null; + setState(() { + _mode = null; + }); + } + } + + void _show() { + assert(_mode != _RefreshIndicatorMode.refresh); + assert(_mode != _RefreshIndicatorMode.snap); + final Completer<void> completer = Completer<void>(); + _pendingRefreshFuture = completer.future; + _mode = _RefreshIndicatorMode.snap; + _positionController + .animateTo(1.0 / _kDragSizeFactorLimit, duration: _kIndicatorSnapDuration) + .then<void>((void value) { + if (mounted && _mode == _RefreshIndicatorMode.snap) { + setState(() { + // Show the indeterminate progress indicator. + _mode = _RefreshIndicatorMode.refresh; + }); + + final Future<void> refreshResult = widget.onRefresh(); + refreshResult.whenComplete(() { + if (mounted && _mode == _RefreshIndicatorMode.refresh) { + completer.complete(); + _dismiss(_RefreshIndicatorMode.done); + } + }); + } + }); + } + + /// Show the refresh indicator and run the refresh callback as if it had + /// been started interactively. If this method is called while the refresh + /// callback is running, it quietly does nothing. + /// + /// Creating the [RefreshIndicator] with a [GlobalKey<RefreshIndicatorState>] + /// makes it possible to refer to the [RefreshIndicatorState]. + /// + /// The future returned from this method completes when the + /// [RefreshIndicator.onRefresh] callback's future completes. + /// + /// If you await the future returned by this function from a [State], you + /// should check that the state is still [mounted] before calling [setState]. + /// + /// When initiated in this manner, the refresh indicator is independent of any + /// actual scroll view. It defaults to showing the indicator at the top. To + /// show it at the bottom, set `atTop` to false. + Future<void> show({ bool atTop = true }) { + if (_mode != _RefreshIndicatorMode.refresh && + _mode != _RefreshIndicatorMode.snap) { + if (_mode == null) { + _start(atTop ? AxisDirection.down : AxisDirection.up); + } + _show(); + } + return _pendingRefreshFuture; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + final Widget child = NotificationListener<ScrollNotification>( + onNotification: _handleScrollNotification, + child: NotificationListener<OverscrollIndicatorNotification>( + onNotification: _handleIndicatorNotification, + child: widget.child, + ), + ); + assert(() { + if (_mode == null) { + assert(_dragOffset == null); + assert(_isIndicatorAtTop == null); + } else { + assert(_dragOffset != null); + assert(_isIndicatorAtTop != null); + } + return true; + }()); + + final bool showIndeterminateIndicator = + _mode == _RefreshIndicatorMode.refresh || _mode == _RefreshIndicatorMode.done; + + return Stack( + children: <Widget>[ + child, + if (_mode != null) Positioned( + top: _isIndicatorAtTop! ? widget.edgeOffset : null, + bottom: !_isIndicatorAtTop! ? widget.edgeOffset : null, + left: 0.0, + right: 0.0, + child: SizeTransition( + axisAlignment: _isIndicatorAtTop! ? 1.0 : -1.0, + sizeFactor: _positionFactor, // this is what brings it down + child: Container( + padding: _isIndicatorAtTop! + ? EdgeInsets.only(top: widget.displacement) + : EdgeInsets.only(bottom: widget.displacement), + alignment: _isIndicatorAtTop! + ? Alignment.topCenter + : Alignment.bottomCenter, + child: ScaleTransition( + scale: _scaleFactor, + child: AnimatedBuilder( + animation: _positionController, + builder: (BuildContext context, Widget? child) { + final Widget materialIndicator = RefreshProgressIndicator( + semanticsLabel: widget.semanticsLabel ?? MaterialLocalizations.of(context).refreshIndicatorSemanticLabel, + semanticsValue: widget.semanticsValue, + value: showIndeterminateIndicator ? null : _value.value, + valueColor: _valueColor, + backgroundColor: widget.backgroundColor, + strokeWidth: widget.strokeWidth, + ); + + final Widget cupertinoIndicator = CupertinoActivityIndicator( + color: widget.color, + ); + + switch (widget._indicatorType) { + case _IndicatorType.material: + return materialIndicator; + + case _IndicatorType.adaptive: { + final ThemeData theme = Theme.of(context); + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return materialIndicator; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return cupertinoIndicator; + } + } + } + }, + ), + ), + ), + ), + ), + ], + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/reorderable_list.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/reorderable_list.dart new file mode 100644 index 0000000000000000000000000000000000000000..6a928e0da809de637750d6729152a741ecf1301d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/reorderable_list.dart @@ -0,0 +1,497 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'debug.dart'; +import 'icons.dart'; +import 'material.dart'; +import 'theme.dart'; + +/// A list whose items the user can interactively reorder by dragging. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=3fB1mxOsqJE} +/// +/// This sample shows by dragging the user can reorder the items of the list. +/// The [onReorder] parameter is required and will be called when a child +/// widget is dragged to a new position. +/// +/// {@tool dartpad} +/// +/// ** See code in examples/api/lib/material/reorderable_list/reorderable_list_view.0.dart ** +/// {@end-tool} +/// +/// By default, on [TargetPlatformVariant.desktop] platforms each item will +/// have a drag handle added on top of it that will allow the user to grab it +/// to move the item. On [TargetPlatformVariant.mobile], no drag handle will be +/// added, but when the user long presses anywhere on the item it will start +/// moving the item. Displaying drag handles can be controlled with +/// [ReorderableListView.buildDefaultDragHandles]. +/// +/// All list items must have a key. +/// +/// This example demonstrates using the [ReorderableListView.proxyDecorator] callback +/// to customize the appearance of a list item while it's being dragged. +/// +/// {@tool dartpad} +/// While a drag is underway, the widget returned by the [ReorderableListView.proxyDecorator] +/// callback serves as a "proxy" (a substitute) for the item in the list. The proxy is +/// created with the original list item as its child. The [ReorderableListView.proxyDecorator] +/// callback in this example is similar to the default one except that it changes the +/// proxy item's background color. +/// +/// ** See code in examples/api/lib/material/reorderable_list/reorderable_list_view.1.dart ** +/// {@end-tool} +/// +/// This example demonstrates using the [ReorderableListView.proxyDecorator] callback to +/// customize the appearance of a [Card] while it's being dragged. +/// +/// {@tool dartpad} +/// The default [proxyDecorator] wraps the dragged item in a [Material] widget and animates +/// its elevation. This example demonstrates how to use the [ReorderableListView.proxyDecorator] +/// callback to update the dragged card elevation without inserted a new [Material] widget. +/// +/// ** See code in examples/api/lib/material/reorderable_list/reorderable_list_view.2.dart ** +/// {@end-tool} +class ReorderableListView extends StatefulWidget { + /// Creates a reorderable list from a pre-built list of widgets. + /// + /// This constructor is appropriate for lists with a small number of + /// children because constructing the [List] requires doing work for every + /// child that could possibly be displayed in the list view instead of just + /// those children that are actually visible. + /// + /// See also: + /// + /// * [ReorderableListView.builder], which allows you to build a reorderable + /// list where the items are built as needed when scrolling the list. + ReorderableListView({ + super.key, + required List<Widget> children, + required this.onReorder, + this.onReorderStart, + this.onReorderEnd, + this.itemExtent, + this.itemExtentBuilder, + this.prototypeItem, + this.proxyDecorator, + this.buildDefaultDragHandles = true, + this.padding, + this.header, + this.footer, + this.scrollDirection = Axis.vertical, + this.reverse = false, + this.scrollController, + this.primary, + this.physics, + this.shrinkWrap = false, + this.anchor = 0.0, + this.cacheExtent, + this.dragStartBehavior = DragStartBehavior.start, + this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, + this.restorationId, + this.clipBehavior = Clip.hardEdge, + this.autoScrollerVelocityScalar, + }) : assert( + (itemExtent == null && prototypeItem == null) || + (itemExtent == null && itemExtentBuilder == null) || + (prototypeItem == null && itemExtentBuilder == null), + 'You can only pass one of itemExtent, prototypeItem and itemExtentBuilder.', + ), + assert( + children.every((Widget w) => w.key != null), + 'All children of this widget must have a key.', + ), + itemBuilder = ((BuildContext context, int index) => children[index]), + itemCount = children.length; + + /// Creates a reorderable list from widget items that are created on demand. + /// + /// This constructor is appropriate for list views with a large number of + /// children because the builder is called only for those children + /// that are actually visible. + /// + /// The `itemBuilder` callback will be called only with indices greater than + /// or equal to zero and less than `itemCount`. + /// + /// The `itemBuilder` should always return a non-null widget, and actually + /// create the widget instances when called. Avoid using a builder that + /// returns a previously-constructed widget; if the list view's children are + /// created in advance, or all at once when the [ReorderableListView] itself + /// is created, it is more efficient to use the [ReorderableListView] + /// constructor. Even more efficient, however, is to create the instances + /// on demand using this constructor's `itemBuilder` callback. + /// + /// This example creates a list using the + /// [ReorderableListView.builder] constructor. Using the [IndexedWidgetBuilder], The + /// list items are built lazily on demand. + /// {@tool dartpad} + /// + /// ** See code in examples/api/lib/material/reorderable_list/reorderable_list_view.reorderable_list_view_builder.0.dart ** + /// {@end-tool} + /// See also: + /// + /// * [ReorderableListView], which allows you to build a reorderable + /// list with all the items passed into the constructor. + const ReorderableListView.builder({ + super.key, + required this.itemBuilder, + required this.itemCount, + required this.onReorder, + this.onReorderStart, + this.onReorderEnd, + this.itemExtent, + this.itemExtentBuilder, + this.prototypeItem, + this.proxyDecorator, + this.buildDefaultDragHandles = true, + this.padding, + this.header, + this.footer, + this.scrollDirection = Axis.vertical, + this.reverse = false, + this.scrollController, + this.primary, + this.physics, + this.shrinkWrap = false, + this.anchor = 0.0, + this.cacheExtent, + this.dragStartBehavior = DragStartBehavior.start, + this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, + this.restorationId, + this.clipBehavior = Clip.hardEdge, + this.autoScrollerVelocityScalar, + }) : assert(itemCount >= 0), + assert( + (itemExtent == null && prototypeItem == null) || + (itemExtent == null && itemExtentBuilder == null) || + (prototypeItem == null && itemExtentBuilder == null), + 'You can only pass one of itemExtent, prototypeItem and itemExtentBuilder.', + ); + + /// {@macro flutter.widgets.reorderable_list.itemBuilder} + final IndexedWidgetBuilder itemBuilder; + + /// {@macro flutter.widgets.reorderable_list.itemCount} + final int itemCount; + + /// {@macro flutter.widgets.reorderable_list.onReorder} + final ReorderCallback onReorder; + + /// {@macro flutter.widgets.reorderable_list.onReorderStart} + final void Function(int index)? onReorderStart; + + /// {@macro flutter.widgets.reorderable_list.onReorderEnd} + final void Function(int index)? onReorderEnd; + + /// {@macro flutter.widgets.reorderable_list.proxyDecorator} + final ReorderItemProxyDecorator? proxyDecorator; + + /// If true: on desktop platforms, a drag handle is stacked over the + /// center of each item's trailing edge; on mobile platforms, a long + /// press anywhere on the item starts a drag. + /// + /// The default desktop drag handle is just an [Icons.drag_handle] + /// wrapped by a [ReorderableDragStartListener]. On mobile + /// platforms, the entire item is wrapped with a + /// [ReorderableDelayedDragStartListener]. + /// + /// To change the appearance or the layout of the drag handles, make + /// this parameter false and wrap each list item, or a widget within + /// each list item, with [ReorderableDragStartListener] or + /// [ReorderableDelayedDragStartListener], or a custom subclass + /// of [ReorderableDragStartListener]. + /// + /// The following sample specifies `buildDefaultDragHandles: false`, and + /// uses a [Card] at the leading edge of each item for the item's drag handle. + /// + /// {@tool dartpad} + /// + /// + /// ** See code in examples/api/lib/material/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart ** + ///{@end-tool} + final bool buildDefaultDragHandles; + + /// {@macro flutter.widgets.reorderable_list.padding} + final EdgeInsets? padding; + + /// A non-reorderable header item to show before the items of the list. + /// + /// If null, no header will appear before the list. + final Widget? header; + + /// A non-reorderable footer item to show after the items of the list. + /// + /// If null, no footer will appear after the list. + final Widget? footer; + + /// {@macro flutter.widgets.scroll_view.scrollDirection} + final Axis scrollDirection; + + /// {@macro flutter.widgets.scroll_view.reverse} + final bool reverse; + + /// {@macro flutter.widgets.scroll_view.controller} + final ScrollController? scrollController; + + /// {@macro flutter.widgets.scroll_view.primary} + + /// Defaults to true when [scrollDirection] is [Axis.vertical] and + /// [scrollController] is null. + final bool? primary; + + /// {@macro flutter.widgets.scroll_view.physics} + final ScrollPhysics? physics; + + /// {@macro flutter.widgets.scroll_view.shrinkWrap} + final bool shrinkWrap; + + /// {@macro flutter.widgets.scroll_view.anchor} + final double anchor; + + /// {@macro flutter.rendering.RenderViewportBase.cacheExtent} + final double? cacheExtent; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@macro flutter.widgets.scroll_view.keyboardDismissBehavior} + /// + /// The default is [ScrollViewKeyboardDismissBehavior.manual] + final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior; + + /// {@macro flutter.widgets.scrollable.restorationId} + final String? restorationId; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// {@macro flutter.widgets.list_view.itemExtent} + final double? itemExtent; + + /// {@macro flutter.widgets.list_view.itemExtentBuilder} + final ItemExtentBuilder? itemExtentBuilder; + + /// {@macro flutter.widgets.list_view.prototypeItem} + final Widget? prototypeItem; + + /// {@macro flutter.widgets.EdgeDraggingAutoScroller.velocityScalar} + /// + /// {@macro flutter.widgets.SliverReorderableList.autoScrollerVelocityScalar.default} + final double? autoScrollerVelocityScalar; + + @override + State<ReorderableListView> createState() => _ReorderableListViewState(); +} + +class _ReorderableListViewState extends State<ReorderableListView> { + Widget _itemBuilder(BuildContext context, int index) { + final Widget item = widget.itemBuilder(context, index); + assert(() { + if (item.key == null) { + throw FlutterError( + 'Every item of ReorderableListView must have a key.', + ); + } + return true; + }()); + + final Key itemGlobalKey = _ReorderableListViewChildGlobalKey(item.key!, this); + + if (widget.buildDefaultDragHandles) { + switch (Theme.of(context).platform) { + case TargetPlatform.linux: + case TargetPlatform.windows: + case TargetPlatform.macOS: + switch (widget.scrollDirection) { + case Axis.horizontal: + return Stack( + key: itemGlobalKey, + children: <Widget>[ + item, + Positioned.directional( + textDirection: Directionality.of(context), + start: 0, + end: 0, + bottom: 8, + child: Align( + alignment: AlignmentDirectional.bottomCenter, + child: ReorderableDragStartListener( + index: index, + child: const Icon(Icons.drag_handle), + ), + ), + ), + ], + ); + case Axis.vertical: + return Stack( + key: itemGlobalKey, + children: <Widget>[ + item, + Positioned.directional( + textDirection: Directionality.of(context), + top: 0, + bottom: 0, + end: 8, + child: Align( + alignment: AlignmentDirectional.centerEnd, + child: ReorderableDragStartListener( + index: index, + child: const Icon(Icons.drag_handle), + ), + ), + ), + ], + ); + } + + case TargetPlatform.iOS: + case TargetPlatform.android: + case TargetPlatform.fuchsia: + return ReorderableDelayedDragStartListener( + key: itemGlobalKey, + index: index, + child: item, + ); + } + } + + return KeyedSubtree( + key: itemGlobalKey, + child: item, + ); + } + + Widget _proxyDecorator(Widget child, int index, Animation<double> animation) { + return AnimatedBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + final double animValue = Curves.easeInOut.transform(animation.value); + final double elevation = lerpDouble(0, 6, animValue)!; + return Material( + elevation: elevation, + child: child, + ); + }, + child: child, + ); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + assert(debugCheckHasOverlay(context)); + + // If there is a header or footer we can't just apply the padding to the list, + // so we break it up into padding for the header, footer and padding for the list. + final EdgeInsets padding = widget.padding ?? EdgeInsets.zero; + late final EdgeInsets headerPadding; + late final EdgeInsets footerPadding; + late final EdgeInsets listPadding; + + if (widget.header == null && widget.footer == null) { + headerPadding = EdgeInsets.zero; + footerPadding = EdgeInsets.zero; + listPadding = padding; + } else if (widget.header != null || widget.footer != null) { + switch (widget.scrollDirection) { + case Axis.horizontal: + if (widget.reverse) { + headerPadding = EdgeInsets.fromLTRB(0, padding.top, padding.right, padding.bottom); + listPadding = EdgeInsets.fromLTRB(widget.footer != null ? 0 : padding.left, padding.top, widget.header != null ? 0 : padding.right, padding.bottom); + footerPadding = EdgeInsets.fromLTRB(padding.left, padding.top, 0, padding.bottom); + } else { + headerPadding = EdgeInsets.fromLTRB(padding.left, padding.top, 0, padding.bottom); + listPadding = EdgeInsets.fromLTRB(widget.header != null ? 0 : padding.left, padding.top, widget.footer != null ? 0 : padding.right, padding.bottom); + footerPadding = EdgeInsets.fromLTRB(0, padding.top, padding.right, padding.bottom); + } + case Axis.vertical: + if (widget.reverse) { + headerPadding = EdgeInsets.fromLTRB(padding.left, 0, padding.right, padding.bottom); + listPadding = EdgeInsets.fromLTRB(padding.left, widget.footer != null ? 0 : padding.top, padding.right, widget.header != null ? 0 : padding.bottom); + footerPadding = EdgeInsets.fromLTRB(padding.left, padding.top, padding.right, 0); + } else { + headerPadding = EdgeInsets.fromLTRB(padding.left, padding.top, padding.right, 0); + listPadding = EdgeInsets.fromLTRB(padding.left, widget.header != null ? 0 : padding.top, padding.right, widget.footer != null ? 0 : padding.bottom); + footerPadding = EdgeInsets.fromLTRB(padding.left, 0, padding.right, padding.bottom); + } + } + } + + return CustomScrollView( + scrollDirection: widget.scrollDirection, + reverse: widget.reverse, + controller: widget.scrollController, + primary: widget.primary, + physics: widget.physics, + shrinkWrap: widget.shrinkWrap, + anchor: widget.anchor, + cacheExtent: widget.cacheExtent, + dragStartBehavior: widget.dragStartBehavior, + keyboardDismissBehavior: widget.keyboardDismissBehavior, + restorationId: widget.restorationId, + clipBehavior: widget.clipBehavior, + slivers: <Widget>[ + if (widget.header != null) + SliverPadding( + padding: headerPadding, + sliver: SliverToBoxAdapter(child: widget.header), + ), + SliverPadding( + padding: listPadding, + sliver: SliverReorderableList( + itemBuilder: _itemBuilder, + itemExtent: widget.itemExtent, + itemExtentBuilder: widget.itemExtentBuilder, + prototypeItem: widget.prototypeItem, + itemCount: widget.itemCount, + onReorder: widget.onReorder, + onReorderStart: widget.onReorderStart, + onReorderEnd: widget.onReorderEnd, + proxyDecorator: widget.proxyDecorator ?? _proxyDecorator, + autoScrollerVelocityScalar: widget.autoScrollerVelocityScalar, + ), + ), + if (widget.footer != null) + SliverPadding( + padding: footerPadding, + sliver: SliverToBoxAdapter(child: widget.footer), + ), + ], + ); + } +} + +// A global key that takes its identity from the object and uses a value of a +// particular type to identify itself. +// +// The difference with GlobalObjectKey is that it uses [==] instead of [identical] +// of the objects used to generate widgets. +@optionalTypeArgs +class _ReorderableListViewChildGlobalKey extends GlobalObjectKey { + const _ReorderableListViewChildGlobalKey(this.subKey, this.state) : super(subKey); + + final Key subKey; + final State state; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _ReorderableListViewChildGlobalKey + && other.subKey == subKey + && other.state == state; + } + + @override + int get hashCode => Object.hash(subKey, state); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/scaffold.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/scaffold.dart new file mode 100644 index 0000000000000000000000000000000000000000..c46860c7cd2bf5f9ea905b59d40a8583a5f9438e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/scaffold.dart @@ -0,0 +1,3305 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:collection'; +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart' show DragStartBehavior; +import 'package:flutter/widgets.dart'; + +import 'app_bar.dart'; +import 'banner.dart'; +import 'banner_theme.dart'; +import 'bottom_sheet.dart'; +import 'colors.dart'; +import 'curves.dart'; +import 'debug.dart'; +import 'divider.dart'; +import 'drawer.dart'; +import 'flexible_space_bar.dart'; +import 'floating_action_button.dart'; +import 'floating_action_button_location.dart'; +import 'material.dart'; +import 'snack_bar.dart'; +import 'snack_bar_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// late TabController tabController; +// void setState(VoidCallback fn) { } +// late String appBarTitle; +// late int tabCount; +// late TickerProvider tickerProvider; + +const FloatingActionButtonLocation _kDefaultFloatingActionButtonLocation = FloatingActionButtonLocation.endFloat; +const FloatingActionButtonAnimator _kDefaultFloatingActionButtonAnimator = FloatingActionButtonAnimator.scaling; + +const Curve _standardBottomSheetCurve = standardEasing; +// When the top of the BottomSheet crosses this threshold, it will start to +// shrink the FAB and show a scrim. +const double _kBottomSheetDominatesPercentage = 0.3; +const double _kMinBottomSheetScrimOpacity = 0.1; +const double _kMaxBottomSheetScrimOpacity = 0.6; + +enum _ScaffoldSlot { + body, + appBar, + bodyScrim, + bottomSheet, + snackBar, + materialBanner, + persistentFooter, + bottomNavigationBar, + floatingActionButton, + drawer, + endDrawer, + statusBar, +} + +/// Manages [SnackBar]s and [MaterialBanner]s for descendant [Scaffold]s. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=lytQi-slT5Y} +/// +/// This class provides APIs for showing snack bars and material banners at the +/// bottom and top of the screen, respectively. +/// +/// To display one of these notifications, obtain the [ScaffoldMessengerState] +/// for the current [BuildContext] via [ScaffoldMessenger.of] and use the +/// [ScaffoldMessengerState.showSnackBar] or the +/// [ScaffoldMessengerState.showMaterialBanner] functions. +/// +/// When the [ScaffoldMessenger] has nested [Scaffold] descendants, the +/// ScaffoldMessenger will only present the notification to the root Scaffold of +/// the subtree of Scaffolds. In order to show notifications for the inner, nested +/// Scaffolds, set a new scope by instantiating a new ScaffoldMessenger in +/// between the levels of nesting. +/// +/// {@tool dartpad} +/// Here is an example of showing a [SnackBar] when the user presses a button. +/// +/// ** See code in examples/api/lib/material/scaffold/scaffold_messenger.0.dart ** +/// {@end-tool} +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=lytQi-slT5Y} +/// +/// See also: +/// +/// * [SnackBar], which is a temporary notification typically shown near the +/// bottom of the app using the [ScaffoldMessengerState.showSnackBar] method. +/// * [MaterialBanner], which is a temporary notification typically shown at the +/// top of the app using the [ScaffoldMessengerState.showMaterialBanner] method. +/// * [debugCheckHasScaffoldMessenger], which asserts that the given context +/// has a [ScaffoldMessenger] ancestor. +/// * Cookbook: [Display a SnackBar](https://flutter.dev/docs/cookbook/design/snackbars) +class ScaffoldMessenger extends StatefulWidget { + /// Creates a widget that manages [SnackBar]s for [Scaffold] descendants. + const ScaffoldMessenger({ + super.key, + required this.child, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// {@tool dartpad} + /// Typical usage of the [ScaffoldMessenger.of] function is to call it in + /// response to a user gesture or an application state change. + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold_messenger.of.0.dart ** + /// {@end-tool} + /// + /// A less elegant but more expedient solution is to assign a [GlobalKey] to the + /// [ScaffoldMessenger], then use the `key.currentState` property to obtain the + /// [ScaffoldMessengerState] rather than using the [ScaffoldMessenger.of] + /// function. The [MaterialApp.scaffoldMessengerKey] refers to the root + /// ScaffoldMessenger that is provided by default. + /// + /// {@tool dartpad} + /// Sometimes [SnackBar]s are produced by code that doesn't have ready access + /// to a valid [BuildContext]. One such example of this is when you show a + /// SnackBar from a method outside of the `build` function. In these + /// cases, you can assign a [GlobalKey] to the [ScaffoldMessenger]. This + /// example shows a key being used to obtain the [ScaffoldMessengerState] + /// provided by the [MaterialApp]. + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold_messenger.of.1.dart ** + /// {@end-tool} + /// + /// If there is no [ScaffoldMessenger] in scope, then this will assert in + /// debug mode, and throw an exception in release mode. + /// + /// See also: + /// + /// * [maybeOf], which is a similar function but will return null instead of + /// throwing if there is no [ScaffoldMessenger] ancestor. + /// * [debugCheckHasScaffoldMessenger], which asserts that the given context + /// has a [ScaffoldMessenger] ancestor. + static ScaffoldMessengerState of(BuildContext context) { + assert(debugCheckHasScaffoldMessenger(context)); + + final _ScaffoldMessengerScope scope = context.dependOnInheritedWidgetOfExactType<_ScaffoldMessengerScope>()!; + return scope._scaffoldMessengerState; + } + + /// The state from the closest instance of this class that encloses the given + /// context, if any. + /// + /// Will return null if a [ScaffoldMessenger] is not found in the given context. + /// + /// See also: + /// + /// * [of], which is a similar function, except that it will throw an + /// exception if a [ScaffoldMessenger] is not found in the given context. + static ScaffoldMessengerState? maybeOf(BuildContext context) { + + final _ScaffoldMessengerScope? scope = context.dependOnInheritedWidgetOfExactType<_ScaffoldMessengerScope>(); + return scope?._scaffoldMessengerState; + } + + @override + ScaffoldMessengerState createState() => ScaffoldMessengerState(); +} + +/// State for a [ScaffoldMessenger]. +/// +/// A [ScaffoldMessengerState] object can be used to [showSnackBar] or +/// [showMaterialBanner] for every registered [Scaffold] that is a descendant of +/// the associated [ScaffoldMessenger]. Scaffolds will register to receive +/// [SnackBar]s and [MaterialBanner]s from their closest ScaffoldMessenger +/// ancestor. +/// +/// Typically obtained via [ScaffoldMessenger.of]. +class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProviderStateMixin { + final LinkedHashSet<ScaffoldState> _scaffolds = LinkedHashSet<ScaffoldState>(); + final Queue<ScaffoldFeatureController<MaterialBanner, MaterialBannerClosedReason>> _materialBanners = Queue<ScaffoldFeatureController<MaterialBanner, MaterialBannerClosedReason>>(); + AnimationController? _materialBannerController; + final Queue<ScaffoldFeatureController<SnackBar, SnackBarClosedReason>> _snackBars = Queue<ScaffoldFeatureController<SnackBar, SnackBarClosedReason>>(); + AnimationController? _snackBarController; + Timer? _snackBarTimer; + bool? _accessibleNavigation; + + @override + void didChangeDependencies() { + final bool accessibleNavigation = MediaQuery.accessibleNavigationOf(context); + // If we transition from accessible navigation to non-accessible navigation + // and there is a SnackBar that would have timed out that has already + // completed its timer, dismiss that SnackBar. If the timer hasn't finished + // yet, let it timeout as normal. + if ((_accessibleNavigation ?? false) + && !accessibleNavigation + && _snackBarTimer != null + && !_snackBarTimer!.isActive) { + hideCurrentSnackBar(reason: SnackBarClosedReason.timeout); + } + _accessibleNavigation = accessibleNavigation; + super.didChangeDependencies(); + } + + void _register(ScaffoldState scaffold) { + _scaffolds.add(scaffold); + + if (_isRoot(scaffold)) { + if (_snackBars.isNotEmpty) { + scaffold._updateSnackBar(); + } + + if (_materialBanners.isNotEmpty) { + scaffold._updateMaterialBanner(); + } + } + } + + void _unregister(ScaffoldState scaffold) { + final bool removed = _scaffolds.remove(scaffold); + // ScaffoldStates should only be removed once. + assert(removed); + } + + void _updateScaffolds() { + for (final ScaffoldState scaffold in _scaffolds) { + if (_isRoot(scaffold)) { + scaffold._updateSnackBar(); + scaffold._updateMaterialBanner(); + } + } + } + + // Nested Scaffolds are handled by the ScaffoldMessenger by only presenting a + // MaterialBanner or SnackBar in the root Scaffold of the nested set. + bool _isRoot(ScaffoldState scaffold) { + final ScaffoldState? parent = scaffold.context.findAncestorStateOfType<ScaffoldState>(); + return parent == null || !_scaffolds.contains(parent); + } + + // SNACKBAR API + + /// Shows a [SnackBar] across all registered [Scaffold]s. Scaffolds register + /// to receive snack bars from their closest [ScaffoldMessenger] ancestor. + /// If there are several registered scaffolds the snack bar is shown + /// simultaneously on all of them. + /// + /// A scaffold can show at most one snack bar at a time. If this function is + /// called while another snack bar is already visible, the given snack bar + /// will be added to a queue and displayed after the earlier snack bars have + /// closed. + /// + /// To control how long a [SnackBar] remains visible, use [SnackBar.duration]. + /// + /// To remove the [SnackBar] with an exit animation, use [hideCurrentSnackBar] + /// or call [ScaffoldFeatureController.close] on the returned + /// [ScaffoldFeatureController]. To remove a [SnackBar] suddenly (without an + /// animation), use [removeCurrentSnackBar]. + /// + /// See [ScaffoldMessenger.of] for information about how to obtain the + /// [ScaffoldMessengerState]. + /// + /// {@tool dartpad} + /// Here is an example of showing a [SnackBar] when the user presses a button. + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold_messenger_state.show_snack_bar.0.dart ** + /// {@end-tool} + /// + /// ## Relative positioning of floating SnackBars + /// + /// A [SnackBar] with [SnackBar.behavior] set to [SnackBarBehavior.floating] is + /// positioned above the widgets provided to [Scaffold.floatingActionButton], + /// [Scaffold.persistentFooterButtons], and [Scaffold.bottomNavigationBar]. + /// If some or all of these widgets take up enough space such that the SnackBar + /// would not be visible when positioned above them, an error will be thrown. + /// In this case, consider constraining the size of these widgets to allow room for + /// the SnackBar to be visible. + /// + /// {@tool dartpad} + /// Here is an example showing how to display a [SnackBar] with [showSnackBar] + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold_messenger_state.show_snack_bar.0.dart ** + /// {@end-tool} + /// + /// {@tool dartpad} + /// Here is an example showing that a floating [SnackBar] appears above [Scaffold.floatingActionButton]. + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold_messenger_state.show_snack_bar.1.dart ** + /// {@end-tool} + /// + ScaffoldFeatureController<SnackBar, SnackBarClosedReason> showSnackBar(SnackBar snackBar) { + assert( + _scaffolds.isNotEmpty, + 'ScaffoldMessenger.showSnackBar was called, but there are currently no ' + 'descendant Scaffolds to present to.', + ); + _snackBarController ??= SnackBar.createAnimationController(vsync: this) + ..addStatusListener(_handleSnackBarStatusChanged); + if (_snackBars.isEmpty) { + assert(_snackBarController!.isDismissed); + _snackBarController!.forward(); + } + late ScaffoldFeatureController<SnackBar, SnackBarClosedReason> controller; + controller = ScaffoldFeatureController<SnackBar, SnackBarClosedReason>._( + // We provide a fallback key so that if back-to-back snackbars happen to + // match in structure, material ink splashes and highlights don't survive + // from one to the next. + snackBar.withAnimation(_snackBarController!, fallbackKey: UniqueKey()), + Completer<SnackBarClosedReason>(), + () { + assert(_snackBars.first == controller); + hideCurrentSnackBar(); + }, + null, // SnackBar doesn't use a builder function so setState() wouldn't rebuild it + ); + try { + setState(() { + _snackBars.addLast(controller); + }); + _updateScaffolds(); + } catch (exception) { + assert (() { + if (exception is FlutterError) { + final String summary = exception.diagnostics.first.toDescription(); + if (summary == 'setState() or markNeedsBuild() called during build.') { + final List<DiagnosticsNode> information = <DiagnosticsNode>[ + ErrorSummary('The showSnackBar() method cannot be called during build.'), + ErrorDescription( + 'The showSnackBar() method was called during build, which is ' + 'prohibited as showing snack bars requires updating state. Updating ' + 'state is not possible during build.', + ), + ErrorHint( + 'Instead of calling showSnackBar() during build, call it directly ' + 'in your on tap (and related) callbacks. If you need to immediately ' + 'show a snack bar, make the call in initState() or ' + 'didChangeDependencies() instead. Otherwise, you can also schedule a ' + 'post-frame callback using SchedulerBinding.addPostFrameCallback to ' + 'show the snack bar after the current frame.', + ), + context.describeOwnershipChain( + 'The ownership chain for the particular ScaffoldMessenger is', + ), + ]; + throw FlutterError.fromParts(information); + } + } + return true; + }()); + rethrow; + } + + return controller; + } + + void _handleSnackBarStatusChanged(AnimationStatus status) { + switch (status) { + case AnimationStatus.dismissed: + assert(_snackBars.isNotEmpty); + setState(() { + _snackBars.removeFirst(); + }); + _updateScaffolds(); + if (_snackBars.isNotEmpty) { + _snackBarController!.forward(); + } + case AnimationStatus.completed: + setState(() { + assert(_snackBarTimer == null); + // build will create a new timer if necessary to dismiss the snackBar. + }); + _updateScaffolds(); + case AnimationStatus.forward: + break; + case AnimationStatus.reverse: + break; + } + } + + /// Removes the current [SnackBar] (if any) immediately from registered + /// [Scaffold]s. + /// + /// The removed snack bar does not run its normal exit animation. If there are + /// any queued snack bars, they begin their entrance animation immediately. + void removeCurrentSnackBar({ SnackBarClosedReason reason = SnackBarClosedReason.remove }) { + if (_snackBars.isEmpty) { + return; + } + final Completer<SnackBarClosedReason> completer = _snackBars.first._completer; + if (!completer.isCompleted) { + completer.complete(reason); + } + _snackBarTimer?.cancel(); + _snackBarTimer = null; + // This will trigger the animation's status callback. + _snackBarController!.value = 0.0; + } + + /// Removes the current [SnackBar] by running its normal exit animation. + /// + /// The closed completer is called after the animation is complete. + void hideCurrentSnackBar({ SnackBarClosedReason reason = SnackBarClosedReason.hide }) { + if (_snackBars.isEmpty || _snackBarController!.status == AnimationStatus.dismissed) { + return; + } + final Completer<SnackBarClosedReason> completer = _snackBars.first._completer; + if (_accessibleNavigation!) { + _snackBarController!.value = 0.0; + completer.complete(reason); + } else { + _snackBarController!.reverse().then<void>((void value) { + assert(mounted); + if (!completer.isCompleted) { + completer.complete(reason); + } + }); + } + _snackBarTimer?.cancel(); + _snackBarTimer = null; + } + + /// Removes all the snackBars currently in queue by clearing the queue + /// and running normal exit animation on the current snackBar. + void clearSnackBars() { + if (_snackBars.isEmpty || _snackBarController!.status == AnimationStatus.dismissed) { + return; + } + final ScaffoldFeatureController<SnackBar, SnackBarClosedReason> currentSnackbar = _snackBars.first; + _snackBars.clear(); + _snackBars.add(currentSnackbar); + hideCurrentSnackBar(); + } + + // MATERIAL BANNER API + + /// Shows a [MaterialBanner] across all registered [Scaffold]s. Scaffolds register + /// to receive material banners from their closest [ScaffoldMessenger] ancestor. + /// If there are several registered scaffolds the material banner is shown + /// simultaneously on all of them. + /// + /// A scaffold can show at most one material banner at a time. If this function is + /// called while another material banner is already visible, the given material banner + /// will be added to a queue and displayed after the earlier material banners have + /// closed. + /// + /// To remove the [MaterialBanner] with an exit animation, use [hideCurrentMaterialBanner] + /// or call [ScaffoldFeatureController.close] on the returned + /// [ScaffoldFeatureController]. To remove a [MaterialBanner] suddenly (without an + /// animation), use [removeCurrentMaterialBanner]. + /// + /// See [ScaffoldMessenger.of] for information about how to obtain the + /// [ScaffoldMessengerState]. + /// + /// {@tool dartpad} + /// Here is an example of showing a [MaterialBanner] when the user presses a button. + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold_messenger_state.show_material_banner.0.dart ** + /// {@end-tool} + ScaffoldFeatureController<MaterialBanner, MaterialBannerClosedReason> showMaterialBanner(MaterialBanner materialBanner) { + assert( + _scaffolds.isNotEmpty, + 'ScaffoldMessenger.showMaterialBanner was called, but there are currently no ' + 'descendant Scaffolds to present to.', + ); + _materialBannerController ??= MaterialBanner.createAnimationController(vsync: this) + ..addStatusListener(_handleMaterialBannerStatusChanged); + if (_materialBanners.isEmpty) { + assert(_materialBannerController!.isDismissed); + _materialBannerController!.forward(); + } + late ScaffoldFeatureController<MaterialBanner, MaterialBannerClosedReason> controller; + controller = ScaffoldFeatureController<MaterialBanner, MaterialBannerClosedReason>._( + // We provide a fallback key so that if back-to-back material banners happen to + // match in structure, material ink splashes and highlights don't survive + // from one to the next. + materialBanner.withAnimation(_materialBannerController!, fallbackKey: UniqueKey()), + Completer<MaterialBannerClosedReason>(), + () { + assert(_materialBanners.first == controller); + hideCurrentMaterialBanner(); + }, + null, // MaterialBanner doesn't use a builder function so setState() wouldn't rebuild it + ); + setState(() { + _materialBanners.addLast(controller); + }); + _updateScaffolds(); + return controller; + } + + void _handleMaterialBannerStatusChanged(AnimationStatus status) { + switch (status) { + case AnimationStatus.dismissed: + assert(_materialBanners.isNotEmpty); + setState(() { + _materialBanners.removeFirst(); + }); + _updateScaffolds(); + if (_materialBanners.isNotEmpty) { + _materialBannerController!.forward(); + } + case AnimationStatus.completed: + _updateScaffolds(); + case AnimationStatus.forward: + break; + case AnimationStatus.reverse: + break; + } + } + + /// Removes the current [MaterialBanner] (if any) immediately from registered + /// [Scaffold]s. + /// + /// The removed material banner does not run its normal exit animation. If there are + /// any queued material banners, they begin their entrance animation immediately. + void removeCurrentMaterialBanner({ MaterialBannerClosedReason reason = MaterialBannerClosedReason.remove }) { + if (_materialBanners.isEmpty) { + return; + } + final Completer<MaterialBannerClosedReason> completer = _materialBanners.first._completer; + if (!completer.isCompleted) { + completer.complete(reason); + } + + // This will trigger the animation's status callback. + _materialBannerController!.value = 0.0; + } + + /// Removes the current [MaterialBanner] by running its normal exit animation. + /// + /// The closed completer is called after the animation is complete. + void hideCurrentMaterialBanner({ MaterialBannerClosedReason reason = MaterialBannerClosedReason.hide }) { + if (_materialBanners.isEmpty || _materialBannerController!.status == AnimationStatus.dismissed) { + return; + } + final Completer<MaterialBannerClosedReason> completer = _materialBanners.first._completer; + if (_accessibleNavigation!) { + _materialBannerController!.value = 0.0; + completer.complete(reason); + } else { + _materialBannerController!.reverse().then<void>((void value) { + assert(mounted); + if (!completer.isCompleted) { + completer.complete(reason); + } + }); + } + } + + /// Removes all the [MaterialBanner]s currently in queue by clearing the queue + /// and running normal exit animation on the current [MaterialBanner]. + void clearMaterialBanners() { + if (_materialBanners.isEmpty || _materialBannerController!.status == AnimationStatus.dismissed) { + return; + } + final ScaffoldFeatureController<MaterialBanner, MaterialBannerClosedReason> currentMaterialBanner = _materialBanners.first; + _materialBanners.clear(); + _materialBanners.add(currentMaterialBanner); + hideCurrentMaterialBanner(); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + _accessibleNavigation = MediaQuery.accessibleNavigationOf(context); + + if (_snackBars.isNotEmpty) { + final ModalRoute<dynamic>? route = ModalRoute.of(context); + if (route == null || route.isCurrent) { + if (_snackBarController!.isCompleted && _snackBarTimer == null) { + final SnackBar snackBar = _snackBars.first._widget; + _snackBarTimer = Timer(snackBar.duration, () { + assert( + _snackBarController!.status == AnimationStatus.forward || + _snackBarController!.status == AnimationStatus.completed, + ); + // Look up MediaQuery again in case the setting changed. + if (snackBar.action != null && MediaQuery.accessibleNavigationOf(context)) { + return; + } + hideCurrentSnackBar(reason: SnackBarClosedReason.timeout); + }); + } + } + } + + return _ScaffoldMessengerScope( + scaffoldMessengerState: this, + child: widget.child, + ); + } + + @override + void dispose() { + _materialBannerController?.dispose(); + _snackBarController?.dispose(); + _snackBarTimer?.cancel(); + _snackBarTimer = null; + super.dispose(); + } +} + +class _ScaffoldMessengerScope extends InheritedWidget { + const _ScaffoldMessengerScope({ + required super.child, + required ScaffoldMessengerState scaffoldMessengerState, + }) : _scaffoldMessengerState = scaffoldMessengerState; + + final ScaffoldMessengerState _scaffoldMessengerState; + + @override + bool updateShouldNotify(_ScaffoldMessengerScope old) => _scaffoldMessengerState != old._scaffoldMessengerState; +} + +/// The geometry of the [Scaffold] after all its contents have been laid out +/// except the [FloatingActionButton]. +/// +/// The [Scaffold] passes this pre-layout geometry to its +/// [FloatingActionButtonLocation], which produces an [Offset] that the +/// [Scaffold] uses to position the [FloatingActionButton]. +/// +/// For a description of the [Scaffold]'s geometry after it has +/// finished laying out, see the [ScaffoldGeometry]. +@immutable +class ScaffoldPrelayoutGeometry { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const ScaffoldPrelayoutGeometry({ + required this.bottomSheetSize, + required this.contentBottom, + required this.contentTop, + required this.floatingActionButtonSize, + required this.minInsets, + required this.minViewPadding, + required this.scaffoldSize, + required this.snackBarSize, + required this.materialBannerSize, + required this.textDirection, + }); + + /// The [Size] of [Scaffold.floatingActionButton]. + /// + /// If [Scaffold.floatingActionButton] is null, this will be [Size.zero]. + final Size floatingActionButtonSize; + + /// The [Size] of the [Scaffold]'s [BottomSheet]. + /// + /// If the [Scaffold] is not currently showing a [BottomSheet], + /// this will be [Size.zero]. + final Size bottomSheetSize; + + /// The vertical distance from the Scaffold's origin to the bottom of + /// [Scaffold.body]. + /// + /// This is useful in a [FloatingActionButtonLocation] designed to + /// place the [FloatingActionButton] at the bottom of the screen, while + /// keeping it above the [BottomSheet], the [Scaffold.bottomNavigationBar], + /// or the keyboard. + /// + /// The [Scaffold.body] is laid out with respect to [minInsets] already. This + /// means that a [FloatingActionButtonLocation] does not need to factor in + /// [EdgeInsets.bottom] of [minInsets] when aligning a [FloatingActionButton] + /// to [contentBottom]. + final double contentBottom; + + /// The vertical distance from the [Scaffold]'s origin to the top of + /// [Scaffold.body]. + /// + /// This is useful in a [FloatingActionButtonLocation] designed to + /// place the [FloatingActionButton] at the top of the screen, while + /// keeping it below the [Scaffold.appBar]. + /// + /// The [Scaffold.body] is laid out with respect to [minInsets] already. This + /// means that a [FloatingActionButtonLocation] does not need to factor in + /// [EdgeInsets.top] of [minInsets] when aligning a [FloatingActionButton] to + /// [contentTop]. + final double contentTop; + + /// The minimum padding to inset the [FloatingActionButton] by for it + /// to remain visible. + /// + /// This value is the result of calling [MediaQueryData.padding] in the + /// [Scaffold]'s [BuildContext], + /// and is useful for insetting the [FloatingActionButton] to avoid features like + /// the system status bar or the keyboard. + /// + /// If [Scaffold.resizeToAvoidBottomInset] is set to false, + /// [EdgeInsets.bottom] of [minInsets] will be 0.0. + final EdgeInsets minInsets; + + /// The minimum padding to inset interactive elements to be within a safe, + /// un-obscured space. + /// + /// This value reflects the [MediaQueryData.viewPadding] of the [Scaffold]'s + /// [BuildContext] when [Scaffold.resizeToAvoidBottomInset] is false or and + /// the [MediaQueryData.viewInsets] > 0.0. This helps distinguish between + /// different types of obstructions on the screen, such as software keyboards + /// and physical device notches. + final EdgeInsets minViewPadding; + + /// The [Size] of the whole [Scaffold]. + /// + /// If the [Size] of the [Scaffold]'s contents is modified by values such as + /// [Scaffold.resizeToAvoidBottomInset] or the keyboard opening, then the + /// [scaffoldSize] will not reflect those changes. + /// + /// This means that [FloatingActionButtonLocation]s designed to reposition + /// the [FloatingActionButton] based on events such as the keyboard popping + /// up should use [minInsets] to make sure that the [FloatingActionButton] is + /// inset by enough to remain visible. + /// + /// See [minInsets] and [MediaQueryData.padding] for more information on the + /// appropriate insets to apply. + final Size scaffoldSize; + + /// The [Size] of the [Scaffold]'s [SnackBar]. + /// + /// If the [Scaffold] is not showing a [SnackBar], this will be [Size.zero]. + final Size snackBarSize; + + /// The [Size] of the [Scaffold]'s [MaterialBanner]. + /// + /// If the [Scaffold] is not showing a [MaterialBanner], this will be [Size.zero]. + final Size materialBannerSize; + + /// The [TextDirection] of the [Scaffold]'s [BuildContext]. + final TextDirection textDirection; +} + +/// A snapshot of a transition between two [FloatingActionButtonLocation]s. +/// +/// [ScaffoldState] uses this to seamlessly change transition animations +/// when a running [FloatingActionButtonLocation] transition is interrupted by a new transition. +@immutable +class _TransitionSnapshotFabLocation extends FloatingActionButtonLocation { + + const _TransitionSnapshotFabLocation(this.begin, this.end, this.animator, this.progress); + + final FloatingActionButtonLocation begin; + final FloatingActionButtonLocation end; + final FloatingActionButtonAnimator animator; + final double progress; + + @override + Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) { + return animator.getOffset( + begin: begin.getOffset(scaffoldGeometry), + end: end.getOffset(scaffoldGeometry), + progress: progress, + ); + } + + @override + String toString() { + return '${objectRuntimeType(this, '_TransitionSnapshotFabLocation')}(begin: $begin, end: $end, progress: $progress)'; + } +} + +/// Geometry information for [Scaffold] components after layout is finished. +/// +/// To get a [ValueNotifier] for the scaffold geometry of a given +/// [BuildContext], use [Scaffold.geometryOf]. +/// +/// The ScaffoldGeometry is only available during the paint phase, because +/// its value is computed during the animation and layout phases prior to painting. +/// +/// For an example of using the [ScaffoldGeometry], see the [BottomAppBar], +/// which uses the [ScaffoldGeometry] to paint a notch around the +/// [FloatingActionButton]. +/// +/// For information about the [Scaffold]'s geometry that is used while laying +/// out the [FloatingActionButton], see [ScaffoldPrelayoutGeometry]. +@immutable +class ScaffoldGeometry { + /// Create an object that describes the geometry of a [Scaffold]. + const ScaffoldGeometry({ + this.bottomNavigationBarTop, + this.floatingActionButtonArea, + }); + + /// The distance from the [Scaffold]'s top edge to the top edge of the + /// rectangle in which the [Scaffold.bottomNavigationBar] bar is laid out. + /// + /// Null if [Scaffold.bottomNavigationBar] is null. + final double? bottomNavigationBarTop; + + /// The [Scaffold.floatingActionButton]'s bounding rectangle. + /// + /// This is null when there is no floating action button showing. + final Rect? floatingActionButtonArea; + + ScaffoldGeometry _scaleFloatingActionButton(double scaleFactor) { + if (scaleFactor == 1.0) { + return this; + } + + if (scaleFactor == 0.0) { + return ScaffoldGeometry( + bottomNavigationBarTop: bottomNavigationBarTop, + ); + } + + final Rect scaledButton = Rect.lerp( + floatingActionButtonArea!.center & Size.zero, + floatingActionButtonArea, + scaleFactor, + )!; + return copyWith(floatingActionButtonArea: scaledButton); + } + + /// Creates a copy of this [ScaffoldGeometry] but with the given fields replaced with + /// the new values. + ScaffoldGeometry copyWith({ + double? bottomNavigationBarTop, + Rect? floatingActionButtonArea, + }) { + return ScaffoldGeometry( + bottomNavigationBarTop: bottomNavigationBarTop ?? this.bottomNavigationBarTop, + floatingActionButtonArea: floatingActionButtonArea ?? this.floatingActionButtonArea, + ); + } +} + +class _ScaffoldGeometryNotifier extends ChangeNotifier implements ValueListenable<ScaffoldGeometry> { + _ScaffoldGeometryNotifier(this.geometry, this.context); + + final BuildContext context; + double? floatingActionButtonScale; + ScaffoldGeometry geometry; + + @override + ScaffoldGeometry get value { + assert(() { + final RenderObject? renderObject = context.findRenderObject(); + if (renderObject == null || !renderObject.owner!.debugDoingPaint) { + throw FlutterError( + 'Scaffold.geometryOf() must only be accessed during the paint phase.\n' + 'The ScaffoldGeometry is only available during the paint phase, because ' + 'its value is computed during the animation and layout phases prior to painting.', + ); + } + return true; + }()); + return geometry._scaleFloatingActionButton(floatingActionButtonScale!); + } + + void _updateWith({ + double? bottomNavigationBarTop, + Rect? floatingActionButtonArea, + double? floatingActionButtonScale, + }) { + this.floatingActionButtonScale = floatingActionButtonScale ?? this.floatingActionButtonScale; + geometry = geometry.copyWith( + bottomNavigationBarTop: bottomNavigationBarTop, + floatingActionButtonArea: floatingActionButtonArea, + ); + notifyListeners(); + } +} + +// Used to communicate the height of the Scaffold's bottomNavigationBar and +// persistentFooterButtons to the LayoutBuilder which builds the Scaffold's body. +// +// Scaffold expects a _BodyBoxConstraints to be passed to the _BodyBuilder +// widget's LayoutBuilder, see _ScaffoldLayout.performLayout(). The BoxConstraints +// methods that construct new BoxConstraints objects, like copyWith() have not +// been overridden here because we expect the _BodyBoxConstraintsObject to be +// passed along unmodified to the LayoutBuilder. If that changes in the future +// then _BodyBuilder will assert. +class _BodyBoxConstraints extends BoxConstraints { + const _BodyBoxConstraints({ + super.maxWidth, + super.maxHeight, + required this.bottomWidgetsHeight, + required this.appBarHeight, + required this.materialBannerHeight, + }) : assert(bottomWidgetsHeight >= 0), + assert(appBarHeight >= 0), + assert(materialBannerHeight >= 0); + + final double bottomWidgetsHeight; + final double appBarHeight; + final double materialBannerHeight; + + // RenderObject.layout() will only short-circuit its call to its performLayout + // method if the new layout constraints are not == to the current constraints. + // If the height of the bottom widgets has changed, even though the constraints' + // min and max values have not, we still want performLayout to happen. + @override + bool operator ==(Object other) { + if (super != other) { + return false; + } + return other is _BodyBoxConstraints + && other.materialBannerHeight == materialBannerHeight + && other.bottomWidgetsHeight == bottomWidgetsHeight + && other.appBarHeight == appBarHeight; + } + + @override + int get hashCode => Object.hash(super.hashCode, materialBannerHeight, bottomWidgetsHeight, appBarHeight); +} + +// Used when Scaffold.extendBody is true to wrap the scaffold's body in a MediaQuery +// whose padding accounts for the height of the bottomNavigationBar and/or the +// persistentFooterButtons. +// +// The bottom widgets' height is passed along via the _BodyBoxConstraints parameter. +// The constraints parameter is constructed in_ScaffoldLayout.performLayout(). +class _BodyBuilder extends StatelessWidget { + const _BodyBuilder({ + required this.extendBody, + required this.extendBodyBehindAppBar, + required this.body, + }); + + final Widget body; + final bool extendBody; + final bool extendBodyBehindAppBar; + + @override + Widget build(BuildContext context) { + if (!extendBody && !extendBodyBehindAppBar) { + return body; + } + + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + final _BodyBoxConstraints bodyConstraints = constraints as _BodyBoxConstraints; + final MediaQueryData metrics = MediaQuery.of(context); + + final double bottom = extendBody + ? math.max(metrics.padding.bottom, bodyConstraints.bottomWidgetsHeight) + : metrics.padding.bottom; + + final double top = extendBodyBehindAppBar + ? math.max(metrics.padding.top, + bodyConstraints.appBarHeight + bodyConstraints.materialBannerHeight) + : metrics.padding.top; + + return MediaQuery( + data: metrics.copyWith( + padding: metrics.padding.copyWith( + top: top, + bottom: bottom, + ), + ), + child: body, + ); + }, + ); + } +} + +class _ScaffoldLayout extends MultiChildLayoutDelegate { + _ScaffoldLayout({ + required this.minInsets, + required this.minViewPadding, + required this.textDirection, + required this.geometryNotifier, + // for floating action button + required this.previousFloatingActionButtonLocation, + required this.currentFloatingActionButtonLocation, + required this.floatingActionButtonMoveAnimationProgress, + required this.floatingActionButtonMotionAnimator, + required this.isSnackBarFloating, + required this.snackBarWidth, + required this.extendBody, + required this.extendBodyBehindAppBar, + required this.extendBodyBehindMaterialBanner, + }); + + final bool extendBody; + final bool extendBodyBehindAppBar; + final EdgeInsets minInsets; + final EdgeInsets minViewPadding; + final TextDirection textDirection; + final _ScaffoldGeometryNotifier geometryNotifier; + + final FloatingActionButtonLocation previousFloatingActionButtonLocation; + final FloatingActionButtonLocation currentFloatingActionButtonLocation; + final double floatingActionButtonMoveAnimationProgress; + final FloatingActionButtonAnimator floatingActionButtonMotionAnimator; + + final bool isSnackBarFloating; + final double? snackBarWidth; + + final bool extendBodyBehindMaterialBanner; + + @override + void performLayout(Size size) { + final BoxConstraints looseConstraints = BoxConstraints.loose(size); + + // This part of the layout has the same effect as putting the app bar and + // body in a column and making the body flexible. What's different is that + // in this case the app bar appears _after_ the body in the stacking order, + // so the app bar's shadow is drawn on top of the body. + + final BoxConstraints fullWidthConstraints = looseConstraints.tighten(width: size.width); + final double bottom = size.height; + double contentTop = 0.0; + double bottomWidgetsHeight = 0.0; + double appBarHeight = 0.0; + + if (hasChild(_ScaffoldSlot.appBar)) { + appBarHeight = layoutChild(_ScaffoldSlot.appBar, fullWidthConstraints).height; + contentTop = extendBodyBehindAppBar ? 0.0 : appBarHeight; + positionChild(_ScaffoldSlot.appBar, Offset.zero); + } + + double? bottomNavigationBarTop; + if (hasChild(_ScaffoldSlot.bottomNavigationBar)) { + final double bottomNavigationBarHeight = layoutChild(_ScaffoldSlot.bottomNavigationBar, fullWidthConstraints).height; + bottomWidgetsHeight += bottomNavigationBarHeight; + bottomNavigationBarTop = math.max(0.0, bottom - bottomWidgetsHeight); + positionChild(_ScaffoldSlot.bottomNavigationBar, Offset(0.0, bottomNavigationBarTop)); + } + + if (hasChild(_ScaffoldSlot.persistentFooter)) { + final BoxConstraints footerConstraints = BoxConstraints( + maxWidth: fullWidthConstraints.maxWidth, + maxHeight: math.max(0.0, bottom - bottomWidgetsHeight - contentTop), + ); + final double persistentFooterHeight = layoutChild(_ScaffoldSlot.persistentFooter, footerConstraints).height; + bottomWidgetsHeight += persistentFooterHeight; + positionChild(_ScaffoldSlot.persistentFooter, Offset(0.0, math.max(0.0, bottom - bottomWidgetsHeight))); + } + + Size materialBannerSize = Size.zero; + if (hasChild(_ScaffoldSlot.materialBanner)) { + materialBannerSize = layoutChild(_ScaffoldSlot.materialBanner, fullWidthConstraints); + positionChild(_ScaffoldSlot.materialBanner, Offset(0.0, appBarHeight)); + + // Push content down only if elevation is 0. + if (!extendBodyBehindMaterialBanner) { + contentTop += materialBannerSize.height; + } + } + + // Set the content bottom to account for the greater of the height of any + // bottom-anchored material widgets or of the keyboard or other + // bottom-anchored system UI. + final double contentBottom = math.max(0.0, bottom - math.max(minInsets.bottom, bottomWidgetsHeight)); + + if (hasChild(_ScaffoldSlot.body)) { + double bodyMaxHeight = math.max(0.0, contentBottom - contentTop); + + if (extendBody) { + bodyMaxHeight += bottomWidgetsHeight; + bodyMaxHeight = clampDouble(bodyMaxHeight, 0.0, looseConstraints.maxHeight - contentTop); + assert(bodyMaxHeight <= math.max(0.0, looseConstraints.maxHeight - contentTop)); + } + + final BoxConstraints bodyConstraints = _BodyBoxConstraints( + maxWidth: fullWidthConstraints.maxWidth, + maxHeight: bodyMaxHeight, + materialBannerHeight: materialBannerSize.height, + bottomWidgetsHeight: extendBody ? bottomWidgetsHeight : 0.0, + appBarHeight: appBarHeight, + ); + layoutChild(_ScaffoldSlot.body, bodyConstraints); + positionChild(_ScaffoldSlot.body, Offset(0.0, contentTop)); + } + + // The BottomSheet and the SnackBar are anchored to the bottom of the parent, + // they're as wide as the parent and are given their intrinsic height. The + // only difference is that SnackBar appears on the top side of the + // BottomNavigationBar while the BottomSheet is stacked on top of it. + // + // If all three elements are present then either the center of the FAB straddles + // the top edge of the BottomSheet or the bottom of the FAB is + // kFloatingActionButtonMargin above the SnackBar, whichever puts the FAB + // the farthest above the bottom of the parent. If only the FAB is has a + // non-zero height then it's inset from the parent's right and bottom edges + // by kFloatingActionButtonMargin. + + Size bottomSheetSize = Size.zero; + Size snackBarSize = Size.zero; + if (hasChild(_ScaffoldSlot.bodyScrim)) { + final BoxConstraints bottomSheetScrimConstraints = BoxConstraints( + maxWidth: fullWidthConstraints.maxWidth, + maxHeight: contentBottom, + ); + layoutChild(_ScaffoldSlot.bodyScrim, bottomSheetScrimConstraints); + positionChild(_ScaffoldSlot.bodyScrim, Offset.zero); + } + + // Set the size of the SnackBar early if the behavior is fixed so + // the FAB can be positioned correctly. + if (hasChild(_ScaffoldSlot.snackBar) && !isSnackBarFloating) { + snackBarSize = layoutChild(_ScaffoldSlot.snackBar, fullWidthConstraints); + } + + if (hasChild(_ScaffoldSlot.bottomSheet)) { + final BoxConstraints bottomSheetConstraints = BoxConstraints( + maxWidth: fullWidthConstraints.maxWidth, + maxHeight: math.max(0.0, contentBottom - contentTop), + ); + bottomSheetSize = layoutChild(_ScaffoldSlot.bottomSheet, bottomSheetConstraints); + positionChild(_ScaffoldSlot.bottomSheet, Offset((size.width - bottomSheetSize.width) / 2.0, contentBottom - bottomSheetSize.height)); + } + + late Rect floatingActionButtonRect; + if (hasChild(_ScaffoldSlot.floatingActionButton)) { + final Size fabSize = layoutChild(_ScaffoldSlot.floatingActionButton, looseConstraints); + + // To account for the FAB position being changed, we'll animate between + // the old and new positions. + final ScaffoldPrelayoutGeometry currentGeometry = ScaffoldPrelayoutGeometry( + bottomSheetSize: bottomSheetSize, + contentBottom: contentBottom, + /// [appBarHeight] should be used instead of [contentTop] because + /// ScaffoldPrelayoutGeometry.contentTop must not be affected by [extendBodyBehindAppBar]. + contentTop: appBarHeight, + floatingActionButtonSize: fabSize, + minInsets: minInsets, + scaffoldSize: size, + snackBarSize: snackBarSize, + materialBannerSize: materialBannerSize, + textDirection: textDirection, + minViewPadding: minViewPadding, + ); + final Offset currentFabOffset = currentFloatingActionButtonLocation.getOffset(currentGeometry); + final Offset previousFabOffset = previousFloatingActionButtonLocation.getOffset(currentGeometry); + final Offset fabOffset = floatingActionButtonMotionAnimator.getOffset( + begin: previousFabOffset, + end: currentFabOffset, + progress: floatingActionButtonMoveAnimationProgress, + ); + positionChild(_ScaffoldSlot.floatingActionButton, fabOffset); + floatingActionButtonRect = fabOffset & fabSize; + } + + if (hasChild(_ScaffoldSlot.snackBar)) { + final bool hasCustomWidth = snackBarWidth != null && snackBarWidth! < size.width; + if (snackBarSize == Size.zero) { + snackBarSize = layoutChild( + _ScaffoldSlot.snackBar, + hasCustomWidth ? looseConstraints : fullWidthConstraints, + ); + } + + final double snackBarYOffsetBase; + final bool showAboveFab = switch (currentFloatingActionButtonLocation) { + FloatingActionButtonLocation.startTop + || FloatingActionButtonLocation.centerTop + || FloatingActionButtonLocation.endTop + || FloatingActionButtonLocation.miniStartTop + || FloatingActionButtonLocation.miniCenterTop + || FloatingActionButtonLocation.miniEndTop => false, + FloatingActionButtonLocation.startDocked + || FloatingActionButtonLocation.startFloat + || FloatingActionButtonLocation.centerDocked + || FloatingActionButtonLocation.centerFloat + || FloatingActionButtonLocation.endContained + || FloatingActionButtonLocation.endDocked + || FloatingActionButtonLocation.endFloat + || FloatingActionButtonLocation.miniStartDocked + || FloatingActionButtonLocation.miniStartFloat + || FloatingActionButtonLocation.miniCenterDocked + || FloatingActionButtonLocation.miniCenterFloat + || FloatingActionButtonLocation.miniEndDocked + || FloatingActionButtonLocation.miniEndFloat => true, + FloatingActionButtonLocation() => true, + }; + if (floatingActionButtonRect.size != Size.zero && isSnackBarFloating && showAboveFab) { + if (bottomNavigationBarTop != null) { + snackBarYOffsetBase = math.min(bottomNavigationBarTop, floatingActionButtonRect.top); + } else { + snackBarYOffsetBase = floatingActionButtonRect.top; + } + } else { + // SnackBarBehavior.fixed applies a SafeArea automatically. + // SnackBarBehavior.floating does not since the positioning is affected + // if there is a FloatingActionButton (see condition above). If there is + // no FAB, make sure we account for safe space when the SnackBar is + // floating. + final double safeYOffsetBase = size.height - minViewPadding.bottom; + snackBarYOffsetBase = isSnackBarFloating + ? math.min(contentBottom, safeYOffsetBase) + : contentBottom; + } + + double xOffset = 0.0; + if (hasCustomWidth) { + xOffset = switch (textDirection) { + TextDirection.rtl => (snackBarWidth! - size.width) / 2, + TextDirection.ltr => (size.width - snackBarWidth!) / 2, + }; + } + positionChild(_ScaffoldSlot.snackBar, Offset(xOffset, snackBarYOffsetBase - snackBarSize.height)); + + assert((){ + // Whether a floating SnackBar has been offset too high. + // + // To improve the developer experience, this assert is done after the call to positionChild. + // if we assert sooner the SnackBar is visible because its defaults position is (0,0) and + // it can cause confusion to the user as the error message states that the SnackBar is off screen. + if (isSnackBarFloating) { + final bool snackBarVisible = (snackBarYOffsetBase - snackBarSize.height) >= 0; + if (!snackBarVisible) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Floating SnackBar presented off screen.'), + ErrorDescription( + 'A SnackBar with behavior property set to SnackBarBehavior.floating is fully ' + 'or partially off screen because some or all the widgets provided to ' + 'Scaffold.floatingActionButton, Scaffold.persistentFooterButtons and ' + 'Scaffold.bottomNavigationBar take up too much vertical space.\n' + ), + ErrorHint( + 'Consider constraining the size of these widgets to allow room for the SnackBar to be visible.', + ), + ]); + } + } + return true; + }()); + } + + if (hasChild(_ScaffoldSlot.statusBar)) { + layoutChild(_ScaffoldSlot.statusBar, fullWidthConstraints.tighten(height: minInsets.top)); + positionChild(_ScaffoldSlot.statusBar, Offset.zero); + } + + if (hasChild(_ScaffoldSlot.drawer)) { + layoutChild(_ScaffoldSlot.drawer, BoxConstraints.tight(size)); + positionChild(_ScaffoldSlot.drawer, Offset.zero); + } + + if (hasChild(_ScaffoldSlot.endDrawer)) { + layoutChild(_ScaffoldSlot.endDrawer, BoxConstraints.tight(size)); + positionChild(_ScaffoldSlot.endDrawer, Offset.zero); + } + + geometryNotifier._updateWith( + bottomNavigationBarTop: bottomNavigationBarTop, + floatingActionButtonArea: floatingActionButtonRect, + ); + } + + @override + bool shouldRelayout(_ScaffoldLayout oldDelegate) { + return oldDelegate.minInsets != minInsets + || oldDelegate.minViewPadding != minViewPadding + || oldDelegate.textDirection != textDirection + || oldDelegate.floatingActionButtonMoveAnimationProgress != floatingActionButtonMoveAnimationProgress + || oldDelegate.previousFloatingActionButtonLocation != previousFloatingActionButtonLocation + || oldDelegate.currentFloatingActionButtonLocation != currentFloatingActionButtonLocation + || oldDelegate.extendBody != extendBody + || oldDelegate.extendBodyBehindAppBar != extendBodyBehindAppBar; + } +} + +/// Handler for scale and rotation animations in the [FloatingActionButton]. +/// +/// Currently, there are two types of [FloatingActionButton] animations: +/// +/// * Entrance/Exit animations, which this widget triggers +/// when the [FloatingActionButton] is added, updated, or removed. +/// * Motion animations, which are triggered by the [Scaffold] +/// when its [FloatingActionButtonLocation] is updated. +class _FloatingActionButtonTransition extends StatefulWidget { + const _FloatingActionButtonTransition({ + required this.child, + required this.fabMoveAnimation, + required this.fabMotionAnimator, + required this.geometryNotifier, + required this.currentController, + }); + + final Widget? child; + final Animation<double> fabMoveAnimation; + final FloatingActionButtonAnimator fabMotionAnimator; + final _ScaffoldGeometryNotifier geometryNotifier; + + /// Controls the current child widget.child as it exits. + final AnimationController currentController; + + @override + _FloatingActionButtonTransitionState createState() => _FloatingActionButtonTransitionState(); +} + +class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTransition> with TickerProviderStateMixin { + // The animations applied to the Floating Action Button when it is entering or exiting. + // Controls the previous widget.child as it exits. + late AnimationController _previousController; + late Animation<double> _previousScaleAnimation; + late Animation<double> _previousRotationAnimation; + // The animations to run, considering the widget's fabMoveAnimation and the current/previous entrance/exit animations. + late Animation<double> _currentScaleAnimation; + late Animation<double> _extendedCurrentScaleAnimation; + late Animation<double> _currentRotationAnimation; + Widget? _previousChild; + + @override + void initState() { + super.initState(); + + _previousController = AnimationController( + duration: kFloatingActionButtonSegue, + vsync: this, + )..addStatusListener(_handlePreviousAnimationStatusChanged); + _updateAnimations(); + + if (widget.child != null) { + // If we start out with a child, have the child appear fully visible instead + // of animating in. + widget.currentController.value = 1.0; + } else { + // If we start without a child we update the geometry object with a + // floating action button scale of 0, as it is not showing on the screen. + _updateGeometryScale(0.0); + } + } + + @override + void dispose() { + _previousController.dispose(); + super.dispose(); + } + + @override + void didUpdateWidget(_FloatingActionButtonTransition oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.fabMotionAnimator != widget.fabMotionAnimator || oldWidget.fabMoveAnimation != widget.fabMoveAnimation) { + // Get the right scale and rotation animations to use for this widget. + _updateAnimations(); + } + final bool oldChildIsNull = oldWidget.child == null; + final bool newChildIsNull = widget.child == null; + if (oldChildIsNull == newChildIsNull && oldWidget.child?.key == widget.child?.key) { + return; + } + if (_previousController.status == AnimationStatus.dismissed) { + final double currentValue = widget.currentController.value; + if (currentValue == 0.0 || oldWidget.child == null) { + // The current child hasn't started its entrance animation yet. We can + // just skip directly to the new child's entrance. + _previousChild = null; + if (widget.child != null) { + widget.currentController.forward(); + } + } else { + // Otherwise, we need to copy the state from the current controller to + // the previous controller and run an exit animation for the previous + // widget before running the entrance animation for the new child. + _previousChild = oldWidget.child; + _previousController + ..value = currentValue + ..reverse(); + widget.currentController.value = 0.0; + } + } + } + + static final Animatable<double> _entranceTurnTween = Tween<double>( + begin: 1.0 - kFloatingActionButtonTurnInterval, + end: 1.0, + ).chain(CurveTween(curve: Curves.easeIn)); + + void _updateAnimations() { + // Get the animations for exit and entrance. + final CurvedAnimation previousExitScaleAnimation = CurvedAnimation( + parent: _previousController, + curve: Curves.easeIn, + ); + final Animation<double> previousExitRotationAnimation = Tween<double>(begin: 1.0, end: 1.0).animate( + CurvedAnimation( + parent: _previousController, + curve: Curves.easeIn, + ), + ); + + final CurvedAnimation currentEntranceScaleAnimation = CurvedAnimation( + parent: widget.currentController, + curve: Curves.easeIn, + ); + final Animation<double> currentEntranceRotationAnimation = widget.currentController.drive(_entranceTurnTween); + + // Get the animations for when the FAB is moving. + final Animation<double> moveScaleAnimation = widget.fabMotionAnimator.getScaleAnimation(parent: widget.fabMoveAnimation); + final Animation<double> moveRotationAnimation = widget.fabMotionAnimator.getRotationAnimation(parent: widget.fabMoveAnimation); + + // Aggregate the animations. + _previousScaleAnimation = AnimationMin<double>(moveScaleAnimation, previousExitScaleAnimation); + _currentScaleAnimation = AnimationMin<double>(moveScaleAnimation, currentEntranceScaleAnimation); + _extendedCurrentScaleAnimation = _currentScaleAnimation.drive(CurveTween(curve: const Interval(0.0, 0.1))); + + _previousRotationAnimation = TrainHoppingAnimation(previousExitRotationAnimation, moveRotationAnimation); + _currentRotationAnimation = TrainHoppingAnimation(currentEntranceRotationAnimation, moveRotationAnimation); + + _currentScaleAnimation.addListener(_onProgressChanged); + _previousScaleAnimation.addListener(_onProgressChanged); + } + + void _handlePreviousAnimationStatusChanged(AnimationStatus status) { + setState(() { + if (widget.child != null && status == AnimationStatus.dismissed) { + assert(widget.currentController.status == AnimationStatus.dismissed); + widget.currentController.forward(); + } + }); + } + + bool _isExtendedFloatingActionButton(Widget? widget) { + return widget is FloatingActionButton + && widget.isExtended; + } + + @override + Widget build(BuildContext context) { + return Stack( + alignment: Alignment.centerRight, + children: <Widget>[ + if (_previousController.status != AnimationStatus.dismissed) + if (_isExtendedFloatingActionButton(_previousChild)) + FadeTransition( + opacity: _previousScaleAnimation, + child: _previousChild, + ) + else + ScaleTransition( + scale: _previousScaleAnimation, + child: RotationTransition( + turns: _previousRotationAnimation, + child: _previousChild, + ), + ), + if (_isExtendedFloatingActionButton(widget.child)) + ScaleTransition( + scale: _extendedCurrentScaleAnimation, + child: FadeTransition( + opacity: _currentScaleAnimation, + child: widget.child, + ), + ) + else + ScaleTransition( + scale: _currentScaleAnimation, + child: RotationTransition( + turns: _currentRotationAnimation, + child: widget.child, + ), + ), + ], + ); + } + + void _onProgressChanged() { + _updateGeometryScale(math.max(_previousScaleAnimation.value, _currentScaleAnimation.value)); + } + + void _updateGeometryScale(double scale) { + widget.geometryNotifier._updateWith( + floatingActionButtonScale: scale, + ); + } +} + +/// Implements the basic Material Design visual layout structure. +/// +/// This class provides APIs for showing drawers and bottom sheets. +/// +/// To display a persistent bottom sheet, obtain the +/// [ScaffoldState] for the current [BuildContext] via [Scaffold.of] and use the +/// [ScaffoldState.showBottomSheet] function. +/// +/// {@tool dartpad} +/// This example shows a [Scaffold] with a [body] and [FloatingActionButton]. +/// The [body] is a [Text] placed in a [Center] in order to center the text +/// within the [Scaffold]. The [FloatingActionButton] is connected to a +/// callback that increments a counter. +/// +/// ** See code in examples/api/lib/material/scaffold/scaffold.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows a [Scaffold] with a blueGrey [backgroundColor], [body] +/// and [FloatingActionButton]. The [body] is a [Text] placed in a [Center] in +/// order to center the text within the [Scaffold]. The [FloatingActionButton] +/// is connected to a callback that increments a counter. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold_background_color.png) +/// +/// ** See code in examples/api/lib/material/scaffold/scaffold.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows a [Scaffold] with an [AppBar], a [BottomAppBar] and a +/// [FloatingActionButton]. The [body] is a [Text] placed in a [Center] in order +/// to center the text within the [Scaffold]. The [FloatingActionButton] is +/// centered and docked within the [BottomAppBar] using +/// [FloatingActionButtonLocation.centerDocked]. The [FloatingActionButton] is +/// connected to a callback that increments a counter. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold_bottom_app_bar.png) +/// +/// ** See code in examples/api/lib/material/scaffold/scaffold.2.dart ** +/// {@end-tool} +/// +/// ## Scaffold layout, the keyboard, and display "notches" +/// +/// The scaffold will expand to fill the available space. That usually +/// means that it will occupy its entire window or device screen. When +/// the device's keyboard appears the Scaffold's ancestor [MediaQuery] +/// widget's [MediaQueryData.viewInsets] changes and the Scaffold will +/// be rebuilt. By default the scaffold's [body] is resized to make +/// room for the keyboard. To prevent the resize set +/// [resizeToAvoidBottomInset] to false. In either case the focused +/// widget will be scrolled into view if it's within a scrollable +/// container. +/// +/// The [MediaQueryData.padding] value defines areas that might +/// not be completely visible, like the display "notch" on the iPhone +/// X. The scaffold's [body] is not inset by this padding value +/// although an [appBar] or [bottomNavigationBar] will typically +/// cause the body to avoid the padding. The [SafeArea] +/// widget can be used within the scaffold's body to avoid areas +/// like display notches. +/// +/// ## Floating action button with a draggable scrollable bottom sheet +/// +/// If [Scaffold.bottomSheet] is a [DraggableScrollableSheet], +/// [Scaffold.floatingActionButton] is set, and the bottom sheet is dragged to +/// cover greater than 70% of the Scaffold's height, two things happen in parallel: +/// +/// * Scaffold starts to show scrim (see [ScaffoldState.showBodyScrim]), and +/// * [Scaffold.floatingActionButton] is scaled down through an animation with a [Curves.easeIn], and +/// disappears when the bottom sheet covers the entire Scaffold. +/// +/// And as soon as the bottom sheet is dragged down to cover less than 70% of the [Scaffold], the scrim +/// disappears and [Scaffold.floatingActionButton] animates back to its normal size. +/// +/// ## Troubleshooting +/// +/// ### Nested Scaffolds +/// +/// The Scaffold is designed to be a top level container for +/// a [MaterialApp]. This means that adding a Scaffold +/// to each route on a Material app will provide the app with +/// Material's basic visual layout structure. +/// +/// It is typically not necessary to nest Scaffolds. For example, in a +/// tabbed UI, where the [bottomNavigationBar] is a [TabBar] +/// and the body is a [TabBarView], you might be tempted to make each tab bar +/// view a scaffold with a differently titled AppBar. Rather, it would be +/// better to add a listener to the [TabController] that updates the +/// AppBar +/// +/// {@tool snippet} +/// Add a listener to the app's tab controller so that the [AppBar] title of the +/// app's one and only scaffold is reset each time a new tab is selected. +/// +/// ```dart +/// TabController(vsync: tickerProvider, length: tabCount)..addListener(() { +/// if (!tabController.indexIsChanging) { +/// setState(() { +/// // Rebuild the enclosing scaffold with a new AppBar title +/// appBarTitle = 'Tab ${tabController.index}'; +/// }); +/// } +/// }) +/// ``` +/// {@end-tool} +/// +/// Although there are some use cases, like a presentation app that +/// shows embedded flutter content, where nested scaffolds are +/// appropriate, it's best to avoid nesting scaffolds. +/// +/// See also: +/// +/// * [AppBar], which is a horizontal bar typically shown at the top of an app +/// using the [appBar] property. +/// * [BottomAppBar], which is a horizontal bar typically shown at the bottom +/// of an app using the [bottomNavigationBar] property. +/// * [FloatingActionButton], which is a circular button typically shown in the +/// bottom right corner of the app using the [floatingActionButton] property. +/// * [Drawer], which is a vertical panel that is typically displayed to the +/// left of the body (and often hidden on phones) using the [drawer] +/// property. +/// * [BottomNavigationBar], which is a horizontal array of buttons typically +/// shown along the bottom of the app using the [bottomNavigationBar] +/// property. +/// * [BottomSheet], which is an overlay typically shown near the bottom of the +/// app. A bottom sheet can either be persistent, in which case it is shown +/// using the [ScaffoldState.showBottomSheet] method, or modal, in which case +/// it is shown using the [showModalBottomSheet] function. +/// * [SnackBar], which is a lightweight message with an optional action which +/// briefly displays at the bottom of the screen. Use the +/// [ScaffoldMessengerState.showSnackBar] method to show snack bars. +/// * [MaterialBanner], which displays an important, succinct message, at the +/// top of the screen, below the app bar. Use the +/// [ScaffoldMessengerState.showMaterialBanner] method to show material banners. +/// * [ScaffoldState], which is the state associated with this widget. +/// * <https://material.io/design/layout/responsive-layout-grid.html> +/// * Cookbook: [Add a Drawer to a screen](https://flutter.dev/docs/cookbook/design/drawer) +class Scaffold extends StatefulWidget { + /// Creates a visual scaffold for Material Design widgets. + const Scaffold({ + super.key, + this.appBar, + this.body, + this.floatingActionButton, + this.floatingActionButtonLocation, + this.floatingActionButtonAnimator, + this.persistentFooterButtons, + this.persistentFooterAlignment = AlignmentDirectional.centerEnd, + this.drawer, + this.onDrawerChanged, + this.endDrawer, + this.onEndDrawerChanged, + this.bottomNavigationBar, + this.bottomSheet, + this.backgroundColor, + this.resizeToAvoidBottomInset, + this.primary = true, + this.drawerDragStartBehavior = DragStartBehavior.start, + this.extendBody = false, + this.extendBodyBehindAppBar = false, + this.drawerScrimColor, + this.drawerEdgeDragWidth, + this.drawerEnableOpenDragGesture = true, + this.endDrawerEnableOpenDragGesture = true, + this.restorationId, + }); + + /// If true, and [bottomNavigationBar] or [persistentFooterButtons] + /// is specified, then the [body] extends to the bottom of the Scaffold, + /// instead of only extending to the top of the [bottomNavigationBar] + /// or the [persistentFooterButtons]. + /// + /// If true, a [MediaQuery] widget whose bottom padding matches the height + /// of the [bottomNavigationBar] will be added above the scaffold's [body]. + /// + /// This property is often useful when the [bottomNavigationBar] has + /// a non-rectangular shape, like [CircularNotchedRectangle], which + /// adds a [FloatingActionButton] sized notch to the top edge of the bar. + /// In this case specifying `extendBody: true` ensures that scaffold's + /// body will be visible through the bottom navigation bar's notch. + /// + /// See also: + /// + /// * [extendBodyBehindAppBar], which extends the height of the body + /// to the top of the scaffold. + final bool extendBody; + + /// If true, and an [appBar] is specified, then the height of the [body] is + /// extended to include the height of the app bar and the top of the body + /// is aligned with the top of the app bar. + /// + /// This is useful if the app bar's [AppBar.backgroundColor] is not + /// completely opaque. + /// + /// This property is false by default. + /// + /// See also: + /// + /// * [extendBody], which extends the height of the body to the bottom + /// of the scaffold. + final bool extendBodyBehindAppBar; + + /// An app bar to display at the top of the scaffold. + final PreferredSizeWidget? appBar; + + /// The primary content of the scaffold. + /// + /// Displayed below the [appBar], above the bottom of the ambient + /// [MediaQuery]'s [MediaQueryData.viewInsets], and behind the + /// [floatingActionButton] and [drawer]. If [resizeToAvoidBottomInset] is + /// false then the body is not resized when the onscreen keyboard appears, + /// i.e. it is not inset by `viewInsets.bottom`. + /// + /// The widget in the body of the scaffold is positioned at the top-left of + /// the available space between the app bar and the bottom of the scaffold. To + /// center this widget instead, consider putting it in a [Center] widget and + /// having that be the body. To expand this widget instead, consider + /// putting it in a [SizedBox.expand]. + /// + /// If you have a column of widgets that should normally fit on the screen, + /// but may overflow and would in such cases need to scroll, consider using a + /// [ListView] as the body of the scaffold. This is also a good choice for + /// the case where your body is a scrollable list. + final Widget? body; + + /// A button displayed floating above [body], in the bottom right corner. + /// + /// Typically a [FloatingActionButton]. + final Widget? floatingActionButton; + + /// Responsible for determining where the [floatingActionButton] should go. + /// + /// If null, the [ScaffoldState] will use the default location, [FloatingActionButtonLocation.endFloat]. + final FloatingActionButtonLocation? floatingActionButtonLocation; + + /// Animator to move the [floatingActionButton] to a new [floatingActionButtonLocation]. + /// + /// If null, the [ScaffoldState] will use the default animator, [FloatingActionButtonAnimator.scaling]. + final FloatingActionButtonAnimator? floatingActionButtonAnimator; + + /// A set of buttons that are displayed at the bottom of the scaffold. + /// + /// Typically this is a list of [TextButton] widgets. These buttons are + /// persistently visible, even if the [body] of the scaffold scrolls. + /// + /// These widgets will be wrapped in an [OverflowBar]. + /// + /// The [persistentFooterButtons] are rendered above the + /// [bottomNavigationBar] but below the [body]. + final List<Widget>? persistentFooterButtons; + + /// The alignment of the [persistentFooterButtons] inside the [OverflowBar]. + /// + /// Defaults to [AlignmentDirectional.centerEnd]. + final AlignmentDirectional persistentFooterAlignment; + + /// A panel displayed to the side of the [body], often hidden on mobile + /// devices. Swipes in from either left-to-right ([TextDirection.ltr]) or + /// right-to-left ([TextDirection.rtl]) + /// + /// Typically a [Drawer]. + /// + /// To open the drawer, use the [ScaffoldState.openDrawer] function. + /// + /// To close the drawer, use either [ScaffoldState.closeDrawer], [Navigator.pop] + /// or press the escape key on the keyboard. + /// + /// {@tool dartpad} + /// To disable the drawer edge swipe on mobile, set the + /// [Scaffold.drawerEnableOpenDragGesture] to false. Then, use + /// [ScaffoldState.openDrawer] to open the drawer and [Navigator.pop] to close + /// it. + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold.drawer.0.dart ** + /// {@end-tool} + final Widget? drawer; + + /// Optional callback that is called when the [Scaffold.drawer] is opened or closed. + final DrawerCallback? onDrawerChanged; + + /// A panel displayed to the side of the [body], often hidden on mobile + /// devices. Swipes in from right-to-left ([TextDirection.ltr]) or + /// left-to-right ([TextDirection.rtl]) + /// + /// Typically a [Drawer]. + /// + /// To open the drawer, use the [ScaffoldState.openEndDrawer] function. + /// + /// To close the drawer, use either [ScaffoldState.closeEndDrawer], [Navigator.pop] + /// or press the escape key on the keyboard. + /// + /// {@tool dartpad} + /// To disable the drawer edge swipe, set the + /// [Scaffold.endDrawerEnableOpenDragGesture] to false. Then, use + /// [ScaffoldState.openEndDrawer] to open the drawer and [Navigator.pop] to + /// close it. + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold.end_drawer.0.dart ** + /// {@end-tool} + final Widget? endDrawer; + + /// Optional callback that is called when the [Scaffold.endDrawer] is opened or closed. + final DrawerCallback? onEndDrawerChanged; + + /// The color to use for the scrim that obscures primary content while a drawer is open. + /// + /// If this is null, then [DrawerThemeData.scrimColor] is used. If that + /// is also null, then it defaults to [Colors.black54]. + final Color? drawerScrimColor; + + /// The color of the [Material] widget that underlies the entire Scaffold. + /// + /// The theme's [ThemeData.scaffoldBackgroundColor] by default. + final Color? backgroundColor; + + /// A bottom navigation bar to display at the bottom of the scaffold. + /// + /// Snack bars slide from underneath the bottom navigation bar while bottom + /// sheets are stacked on top. + /// + /// The [bottomNavigationBar] is rendered below the [persistentFooterButtons] + /// and the [body]. + final Widget? bottomNavigationBar; + + /// The persistent bottom sheet to display. + /// + /// A persistent bottom sheet shows information that supplements the primary + /// content of the app. A persistent bottom sheet remains visible even when + /// the user interacts with other parts of the app. + /// + /// A closely related widget is a modal bottom sheet, which is an alternative + /// to a menu or a dialog and prevents the user from interacting with the rest + /// of the app. Modal bottom sheets can be created and displayed with the + /// [showModalBottomSheet] function. + /// + /// Unlike the persistent bottom sheet displayed by [showBottomSheet] + /// this bottom sheet is not a [LocalHistoryEntry] and cannot be dismissed + /// with the scaffold appbar's back button. + /// + /// If a persistent bottom sheet created with [showBottomSheet] is already + /// visible, it must be closed before building the Scaffold with a new + /// [bottomSheet]. + /// + /// The value of [bottomSheet] can be any widget at all. It's unlikely to + /// actually be a [BottomSheet], which is used by the implementations of + /// [showBottomSheet] and [showModalBottomSheet]. Typically it's a widget + /// that includes [Material]. + /// + /// See also: + /// + /// * [showBottomSheet], which displays a bottom sheet as a route that can + /// be dismissed with the scaffold's back button. + /// * [showModalBottomSheet], which displays a modal bottom sheet. + /// * [BottomSheetThemeData], which can be used to customize the default + /// bottom sheet property values when using a [BottomSheet]. + final Widget? bottomSheet; + + /// If true the [body] and the scaffold's floating widgets should size + /// themselves to avoid the onscreen keyboard whose height is defined by the + /// ambient [MediaQuery]'s [MediaQueryData.viewInsets] `bottom` property. + /// + /// For example, if there is an onscreen keyboard displayed above the + /// scaffold, the body can be resized to avoid overlapping the keyboard, which + /// prevents widgets inside the body from being obscured by the keyboard. + /// + /// Defaults to true. + final bool? resizeToAvoidBottomInset; + + /// Whether this scaffold is being displayed at the top of the screen. + /// + /// If true then the height of the [appBar] will be extended by the height + /// of the screen's status bar, i.e. the top padding for [MediaQuery]. + /// + /// The default value of this property, like the default value of + /// [AppBar.primary], is true. + final bool primary; + + /// {@macro flutter.material.DrawerController.dragStartBehavior} + final DragStartBehavior drawerDragStartBehavior; + + /// The width of the area within which a horizontal swipe will open the + /// drawer. + /// + /// By default, the value used is 20.0 added to the padding edge of + /// `MediaQuery.paddingOf(context)` that corresponds to the surrounding + /// [TextDirection]. This ensures that the drag area for notched devices is + /// not obscured. For example, if `TextDirection.of(context)` is set to + /// [TextDirection.ltr], 20.0 will be added to + /// `MediaQuery.paddingOf(context).left`. + final double? drawerEdgeDragWidth; + + /// Determines if the [Scaffold.drawer] can be opened with a drag + /// gesture on mobile. + /// + /// On desktop platforms, the drawer is not draggable. + /// + /// By default, the drag gesture is enabled on mobile. + final bool drawerEnableOpenDragGesture; + + /// Determines if the [Scaffold.endDrawer] can be opened with a + /// gesture on mobile. + /// + /// On desktop platforms, the drawer is not draggable. + /// + /// By default, the drag gesture is enabled on mobile. + final bool endDrawerEnableOpenDragGesture; + + /// Restoration ID to save and restore the state of the [Scaffold]. + /// + /// If it is non-null, the scaffold will persist and restore whether the + /// [drawer] and [endDrawer] was open or closed. + /// + /// The state of this widget is persisted in a [RestorationBucket] claimed + /// from the surrounding [RestorationScope] using the provided restoration ID. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + final String? restorationId; + + /// Finds the [ScaffoldState] from the closest instance of this class that + /// encloses the given context. + /// + /// If no instance of this class encloses the given context, will cause an + /// assert in debug mode, and throw an exception in release mode. + /// + /// This method can be expensive (it walks the element tree). + /// + /// {@tool dartpad} + /// Typical usage of the [Scaffold.of] function is to call it from within the + /// `build` method of a child of a [Scaffold]. + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold.of.0.dart ** + /// {@end-tool} + /// + /// {@tool dartpad} + /// When the [Scaffold] is actually created in the same `build` function, the + /// `context` argument to the `build` function can't be used to find the + /// [Scaffold] (since it's "above" the widget being returned in the widget + /// tree). In such cases, the following technique with a [Builder] can be used + /// to provide a new scope with a [BuildContext] that is "under" the + /// [Scaffold]: + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold.of.1.dart ** + /// {@end-tool} + /// + /// A more efficient solution is to split your build function into several + /// widgets. This introduces a new context from which you can obtain the + /// [Scaffold]. In this solution, you would have an outer widget that creates + /// the [Scaffold] populated by instances of your new inner widgets, and then + /// in these inner widgets you would use [Scaffold.of]. + /// + /// A less elegant but more expedient solution is assign a [GlobalKey] to the + /// [Scaffold], then use the `key.currentState` property to obtain the + /// [ScaffoldState] rather than using the [Scaffold.of] function. + /// + /// If there is no [Scaffold] in scope, then this will throw an exception. + /// To return null if there is no [Scaffold], use [maybeOf] instead. + static ScaffoldState of(BuildContext context) { + final ScaffoldState? result = context.findAncestorStateOfType<ScaffoldState>(); + if (result != null) { + return result; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'Scaffold.of() called with a context that does not contain a Scaffold.', + ), + ErrorDescription( + 'No Scaffold ancestor could be found starting from the context that was passed to Scaffold.of(). ' + 'This usually happens when the context provided is from the same StatefulWidget as that ' + 'whose build function actually creates the Scaffold widget being sought.', + ), + ErrorHint( + 'There are several ways to avoid this problem. The simplest is to use a Builder to get a ' + 'context that is "under" the Scaffold. For an example of this, please see the ' + 'documentation for Scaffold.of():\n' + ' https://api.flutter.dev/flutter/material/Scaffold/of.html', + ), + ErrorHint( + 'A more efficient solution is to split your build function into several widgets. This ' + 'introduces a new context from which you can obtain the Scaffold. In this solution, ' + 'you would have an outer widget that creates the Scaffold populated by instances of ' + 'your new inner widgets, and then in these inner widgets you would use Scaffold.of().\n' + 'A less elegant but more expedient solution is assign a GlobalKey to the Scaffold, ' + 'then use the key.currentState property to obtain the ScaffoldState rather than ' + 'using the Scaffold.of() function.', + ), + context.describeElement('The context used was'), + ]); + } + + /// Finds the [ScaffoldState] from the closest instance of this class that + /// encloses the given context. + /// + /// If no instance of this class encloses the given context, will return null. + /// To throw an exception instead, use [of] instead of this function. + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [of], a similar function to this one that throws if no instance + /// encloses the given context. Also includes some sample code in its + /// documentation. + static ScaffoldState? maybeOf(BuildContext context) { + return context.findAncestorStateOfType<ScaffoldState>(); + } + + /// Returns a [ValueListenable] for the [ScaffoldGeometry] for the closest + /// [Scaffold] ancestor of the given context. + /// + /// The [ValueListenable.value] is only available at paint time. + /// + /// Notifications are guaranteed to be sent before the first paint pass + /// with the new geometry, but there is no guarantee whether a build or + /// layout passes are going to happen between the notification and the next + /// paint pass. + /// + /// The closest [Scaffold] ancestor for the context might change, e.g when + /// an element is moved from one scaffold to another. For [StatefulWidget]s + /// using this listenable, a change of the [Scaffold] ancestor will + /// trigger a [State.didChangeDependencies]. + /// + /// A typical pattern for listening to the scaffold geometry would be to + /// call [Scaffold.geometryOf] in [State.didChangeDependencies], compare the + /// return value with the previous listenable, if it has changed, unregister + /// the listener, and register a listener to the new [ScaffoldGeometry] + /// listenable. + static ValueListenable<ScaffoldGeometry> geometryOf(BuildContext context) { + final _ScaffoldScope? scaffoldScope = context.dependOnInheritedWidgetOfExactType<_ScaffoldScope>(); + if (scaffoldScope == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'Scaffold.geometryOf() called with a context that does not contain a Scaffold.', + ), + ErrorDescription( + 'This usually happens when the context provided is from the same StatefulWidget as that ' + 'whose build function actually creates the Scaffold widget being sought.', + ), + ErrorHint( + 'There are several ways to avoid this problem. The simplest is to use a Builder to get a ' + 'context that is "under" the Scaffold. For an example of this, please see the ' + 'documentation for Scaffold.of():\n' + ' https://api.flutter.dev/flutter/material/Scaffold/of.html', + ), + ErrorHint( + 'A more efficient solution is to split your build function into several widgets. This ' + 'introduces a new context from which you can obtain the Scaffold. In this solution, ' + 'you would have an outer widget that creates the Scaffold populated by instances of ' + 'your new inner widgets, and then in these inner widgets you would use Scaffold.geometryOf().', + ), + context.describeElement('The context used was'), + ]); + } + return scaffoldScope.geometryNotifier; + } + + /// Whether the Scaffold that most tightly encloses the given context has a + /// drawer. + /// + /// If this is being used during a build (for example to decide whether to + /// show an "open drawer" button), set the `registerForUpdates` argument to + /// true. This will then set up an [InheritedWidget] relationship with the + /// [Scaffold] so that the client widget gets rebuilt whenever the [hasDrawer] + /// value changes. + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [Scaffold.of], which provides access to the [ScaffoldState] object as a + /// whole, from which you can show bottom sheets, and so forth. + static bool hasDrawer(BuildContext context, { bool registerForUpdates = true }) { + if (registerForUpdates) { + final _ScaffoldScope? scaffold = context.dependOnInheritedWidgetOfExactType<_ScaffoldScope>(); + return scaffold?.hasDrawer ?? false; + } else { + final ScaffoldState? scaffold = context.findAncestorStateOfType<ScaffoldState>(); + return scaffold?.hasDrawer ?? false; + } + } + + @override + ScaffoldState createState() => ScaffoldState(); +} + +/// State for a [Scaffold]. +/// +/// Can display [BottomSheet]s. Retrieve a [ScaffoldState] from the current +/// [BuildContext] using [Scaffold.of]. +class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, RestorationMixin { + @override + String? get restorationId => widget.restorationId; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_drawerOpened, 'drawer_open'); + registerForRestoration(_endDrawerOpened, 'end_drawer_open'); + } + + // DRAWER API + + final GlobalKey<DrawerControllerState> _drawerKey = GlobalKey<DrawerControllerState>(); + final GlobalKey<DrawerControllerState> _endDrawerKey = GlobalKey<DrawerControllerState>(); + + final GlobalKey _bodyKey = GlobalKey(); + + /// Whether this scaffold has a non-null [Scaffold.appBar]. + bool get hasAppBar => widget.appBar != null; + /// Whether this scaffold has a non-null [Scaffold.drawer]. + bool get hasDrawer => widget.drawer != null; + /// Whether this scaffold has a non-null [Scaffold.endDrawer]. + bool get hasEndDrawer => widget.endDrawer != null; + /// Whether this scaffold has a non-null [Scaffold.floatingActionButton]. + bool get hasFloatingActionButton => widget.floatingActionButton != null; + + double? _appBarMaxHeight; + /// The max height the [Scaffold.appBar] uses. + /// + /// This is based on the appBar preferred height plus the top padding. + double? get appBarMaxHeight => _appBarMaxHeight; + final RestorableBool _drawerOpened = RestorableBool(false); + final RestorableBool _endDrawerOpened = RestorableBool(false); + + /// Whether the [Scaffold.drawer] is opened. + /// + /// See also: + /// + /// * [ScaffoldState.openDrawer], which opens the [Scaffold.drawer] of a + /// [Scaffold]. + bool get isDrawerOpen => _drawerOpened.value; + + /// Whether the [Scaffold.endDrawer] is opened. + /// + /// See also: + /// + /// * [ScaffoldState.openEndDrawer], which opens the [Scaffold.endDrawer] of + /// a [Scaffold]. + bool get isEndDrawerOpen => _endDrawerOpened.value; + + void _drawerOpenedCallback(bool isOpened) { + if (_drawerOpened.value != isOpened && _drawerKey.currentState != null) { + setState(() { + _drawerOpened.value = isOpened; + }); + widget.onDrawerChanged?.call(isOpened); + } + } + + void _endDrawerOpenedCallback(bool isOpened) { + if (_endDrawerOpened.value != isOpened && _endDrawerKey.currentState != null) { + setState(() { + _endDrawerOpened.value = isOpened; + }); + widget.onEndDrawerChanged?.call(isOpened); + } + } + + /// Opens the [Drawer] (if any). + /// + /// If the scaffold has a non-null [Scaffold.drawer], this function will cause + /// the drawer to begin its entrance animation. + /// + /// Normally this is not needed since the [Scaffold] automatically shows an + /// appropriate [IconButton], and handles the edge-swipe gesture, to show the + /// drawer. + /// + /// To close the drawer, use either [ScaffoldState.closeDrawer] or + /// [Navigator.pop]. + /// + /// See [Scaffold.of] for information about how to obtain the [ScaffoldState]. + void openDrawer() { + if (_endDrawerKey.currentState != null && _endDrawerOpened.value) { + _endDrawerKey.currentState!.close(); + } + _drawerKey.currentState?.open(); + } + + /// Opens the end side [Drawer] (if any). + /// + /// If the scaffold has a non-null [Scaffold.endDrawer], this function will cause + /// the end side drawer to begin its entrance animation. + /// + /// Normally this is not needed since the [Scaffold] automatically shows an + /// appropriate [IconButton], and handles the edge-swipe gesture, to show the + /// drawer. + /// + /// To close the drawer, use either [ScaffoldState.closeEndDrawer] or + /// [Navigator.pop]. + /// + /// See [Scaffold.of] for information about how to obtain the [ScaffoldState]. + void openEndDrawer() { + if (_drawerKey.currentState != null && _drawerOpened.value) { + _drawerKey.currentState!.close(); + } + _endDrawerKey.currentState?.open(); + } + + // Used for both the snackbar and material banner APIs + ScaffoldMessengerState? _scaffoldMessenger; + + // SNACKBAR API + ScaffoldFeatureController<SnackBar, SnackBarClosedReason>? _messengerSnackBar; + + // This is used to update the _messengerSnackBar by the ScaffoldMessenger. + void _updateSnackBar() { + final ScaffoldFeatureController<SnackBar, SnackBarClosedReason>? messengerSnackBar = _scaffoldMessenger!._snackBars.isNotEmpty + ? _scaffoldMessenger!._snackBars.first + : null; + + if (_messengerSnackBar != messengerSnackBar) { + setState(() { + _messengerSnackBar = messengerSnackBar; + }); + } + } + + // MATERIAL BANNER API + + // The _messengerMaterialBanner represents the current MaterialBanner being managed by + // the ScaffoldMessenger, instead of the Scaffold. + ScaffoldFeatureController<MaterialBanner, MaterialBannerClosedReason>? _messengerMaterialBanner; + + // This is used to update the _messengerMaterialBanner by the ScaffoldMessenger. + void _updateMaterialBanner() { + final ScaffoldFeatureController<MaterialBanner, MaterialBannerClosedReason>? messengerMaterialBanner = _scaffoldMessenger!._materialBanners.isNotEmpty + ? _scaffoldMessenger!._materialBanners.first + : null; + + if (_messengerMaterialBanner != messengerMaterialBanner) { + setState(() { + _messengerMaterialBanner = messengerMaterialBanner; + }); + } + } + + // PERSISTENT BOTTOM SHEET API + + // Contains bottom sheets that may still be animating out of view. + // Important if the app/user takes an action that could repeatedly show a + // bottom sheet. + final List<_StandardBottomSheet> _dismissedBottomSheets = <_StandardBottomSheet>[]; + PersistentBottomSheetController? _currentBottomSheet; + final GlobalKey _currentBottomSheetKey = GlobalKey(); + LocalHistoryEntry? _persistentSheetHistoryEntry; + + void _maybeBuildPersistentBottomSheet() { + if (widget.bottomSheet != null && _currentBottomSheet == null) { + // The new _currentBottomSheet is not a local history entry so a "back" button + // will not be added to the Scaffold's appbar and the bottom sheet will not + // support drag or swipe to dismiss. + final AnimationController animationController = BottomSheet.createAnimationController(this)..value = 1.0; + bool persistentBottomSheetExtentChanged(DraggableScrollableNotification notification) { + if (notification.extent - notification.initialExtent > precisionErrorTolerance) { + if (_persistentSheetHistoryEntry == null) { + _persistentSheetHistoryEntry = LocalHistoryEntry(onRemove: () { + DraggableScrollableActuator.reset(notification.context); + showBodyScrim(false, 0.0); + _floatingActionButtonVisibilityValue = 1.0; + _persistentSheetHistoryEntry = null; + }); + ModalRoute.of(context)!.addLocalHistoryEntry(_persistentSheetHistoryEntry!); + } + } else if (_persistentSheetHistoryEntry != null) { + _persistentSheetHistoryEntry!.remove(); + } + return false; + } + + // Stop the animation and unmount the dismissed sheets from the tree immediately, + // otherwise may cause duplicate GlobalKey assertion if the sheet sub-tree contains + // GlobalKey widgets. + if (_dismissedBottomSheets.isNotEmpty) { + final List<_StandardBottomSheet> sheets = List<_StandardBottomSheet>.of(_dismissedBottomSheets, growable: false); + for (final _StandardBottomSheet sheet in sheets) { + sheet.animationController.reset(); + } + assert(_dismissedBottomSheets.isEmpty); + } + + _currentBottomSheet = _buildBottomSheet( + (BuildContext context) { + return NotificationListener<DraggableScrollableNotification>( + onNotification: persistentBottomSheetExtentChanged, + child: DraggableScrollableActuator( + child: StatefulBuilder( + key: _currentBottomSheetKey, + builder: (BuildContext context, StateSetter setState) { + return widget.bottomSheet ?? const SizedBox.shrink(); + }, + ), + ), + ); + }, + isPersistent: true, + animationController: animationController, + ); + } + } + + void _closeCurrentBottomSheet() { + if (_currentBottomSheet != null) { + if (!_currentBottomSheet!._isLocalHistoryEntry) { + _currentBottomSheet!.close(); + } + assert(() { + _currentBottomSheet?._completer.future.whenComplete(() { + assert(_currentBottomSheet == null); + }); + return true; + }()); + } + } + + /// Closes [Scaffold.drawer] if it is currently opened. + /// + /// See [Scaffold.of] for information about how to obtain the [ScaffoldState]. + void closeDrawer() { + if (hasDrawer && isDrawerOpen) { + _drawerKey.currentState!.close(); + } + } + + /// Closes [Scaffold.endDrawer] if it is currently opened. + /// + /// See [Scaffold.of] for information about how to obtain the [ScaffoldState]. + void closeEndDrawer() { + if (hasEndDrawer && isEndDrawerOpen) { + _endDrawerKey.currentState!.close(); + } + } + + void _updatePersistentBottomSheet() { + _currentBottomSheetKey.currentState!.setState(() {}); + } + + PersistentBottomSheetController _buildBottomSheet( + WidgetBuilder builder, { + required bool isPersistent, + required AnimationController animationController, + Color? backgroundColor, + double? elevation, + ShapeBorder? shape, + Clip? clipBehavior, + BoxConstraints? constraints, + bool? enableDrag, + bool shouldDisposeAnimationController = true, + }) { + assert(() { + if (widget.bottomSheet != null && isPersistent && _currentBottomSheet != null) { + throw FlutterError( + 'Scaffold.bottomSheet cannot be specified while a bottom sheet ' + 'displayed with showBottomSheet() is still visible.\n' + 'Rebuild the Scaffold with a null bottomSheet before calling showBottomSheet().', + ); + } + return true; + }()); + + final Completer<void> completer = Completer<void>(); + final GlobalKey<_StandardBottomSheetState> bottomSheetKey = GlobalKey<_StandardBottomSheetState>(); + late _StandardBottomSheet bottomSheet; + + bool removedEntry = false; + bool doingDispose = false; + + void removePersistentSheetHistoryEntryIfNeeded() { + assert(isPersistent); + if (_persistentSheetHistoryEntry != null) { + _persistentSheetHistoryEntry!.remove(); + _persistentSheetHistoryEntry = null; + } + } + + void removeCurrentBottomSheet() { + removedEntry = true; + if (_currentBottomSheet == null) { + return; + } + assert(_currentBottomSheet!._widget == bottomSheet); + assert(bottomSheetKey.currentState != null); + _showFloatingActionButton(); + + if (isPersistent) { + removePersistentSheetHistoryEntryIfNeeded(); + } + + bottomSheetKey.currentState!.close(); + setState(() { + _showBodyScrim = false; + _bodyScrimColor = Colors.black.withOpacity(0.0); + _currentBottomSheet = null; + }); + + if (animationController.status != AnimationStatus.dismissed) { + _dismissedBottomSheets.add(bottomSheet); + } + completer.complete(); + } + + final LocalHistoryEntry? entry = isPersistent + ? null + : LocalHistoryEntry(onRemove: () { + if (!removedEntry && _currentBottomSheet?._widget == bottomSheet && !doingDispose) { + removeCurrentBottomSheet(); + } + }); + + void removeEntryIfNeeded() { + if (!isPersistent && !removedEntry) { + assert(entry != null); + entry!.remove(); + removedEntry = true; + } + } + + bottomSheet = _StandardBottomSheet( + key: bottomSheetKey, + animationController: animationController, + enableDrag: enableDrag ?? !isPersistent, + onClosing: () { + if (_currentBottomSheet == null) { + return; + } + assert(_currentBottomSheet!._widget == bottomSheet); + removeEntryIfNeeded(); + }, + onDismissed: () { + if (_dismissedBottomSheets.contains(bottomSheet)) { + setState(() { + _dismissedBottomSheets.remove(bottomSheet); + }); + } + }, + onDispose: () { + doingDispose = true; + removeEntryIfNeeded(); + if (shouldDisposeAnimationController) { + animationController.dispose(); + } + }, + builder: builder, + isPersistent: isPersistent, + backgroundColor: backgroundColor, + elevation: elevation, + shape: shape, + clipBehavior: clipBehavior, + constraints: constraints, + ); + + if (!isPersistent) { + ModalRoute.of(context)!.addLocalHistoryEntry(entry!); + } + + return PersistentBottomSheetController._( + bottomSheet, + completer, + entry != null + ? entry.remove + : removeCurrentBottomSheet, + (VoidCallback fn) { bottomSheetKey.currentState?.setState(fn); }, + !isPersistent, + ); + } + + /// Shows a Material Design bottom sheet in the nearest [Scaffold]. To show + /// a persistent bottom sheet, use the [Scaffold.bottomSheet]. + /// + /// Returns a controller that can be used to close and otherwise manipulate the + /// bottom sheet. + /// + /// To rebuild the bottom sheet (e.g. if it is stateful), call + /// [PersistentBottomSheetController.setState] on the controller returned by + /// this method. + /// + /// The new bottom sheet becomes a [LocalHistoryEntry] for the enclosing + /// [ModalRoute] and a back button is added to the app bar of the [Scaffold] + /// that closes the bottom sheet. + /// + /// The [transitionAnimationController] controls the bottom sheet's entrance and + /// exit animations. It's up to the owner of the controller to call + /// [AnimationController.dispose] when the controller is no longer needed. + /// + /// To create a persistent bottom sheet that is not a [LocalHistoryEntry] and + /// does not add a back button to the enclosing Scaffold's app bar, use the + /// [Scaffold.bottomSheet] constructor parameter. + /// + /// A persistent bottom sheet shows information that supplements the primary + /// content of the app. A persistent bottom sheet remains visible even when + /// the user interacts with other parts of the app. + /// + /// A closely related widget is a modal bottom sheet, which is an alternative + /// to a menu or a dialog and prevents the user from interacting with the rest + /// of the app. Modal bottom sheets can be created and displayed with the + /// [showModalBottomSheet] function. + /// + /// {@tool dartpad} + /// This example demonstrates how to use [showBottomSheet] to display a + /// bottom sheet when a user taps a button. It also demonstrates how to + /// close a bottom sheet using the Navigator. + /// + /// ** See code in examples/api/lib/material/scaffold/scaffold_state.show_bottom_sheet.0.dart ** + /// {@end-tool} + /// See also: + /// + /// * [BottomSheet], which becomes the parent of the widget returned by the + /// `builder`. + /// * [showBottomSheet], which calls this method given a [BuildContext]. + /// * [showModalBottomSheet], which can be used to display a modal bottom + /// sheet. + /// * [Scaffold.of], for information about how to obtain the [ScaffoldState]. + /// * The Material 2 spec at <https://m2.material.io/components/sheets-bottom>. + /// * The Material 3 spec at <https://m3.material.io/components/bottom-sheets/overview>. + PersistentBottomSheetController showBottomSheet( + WidgetBuilder builder, { + Color? backgroundColor, + double? elevation, + ShapeBorder? shape, + Clip? clipBehavior, + BoxConstraints? constraints, + bool? enableDrag, + AnimationController? transitionAnimationController, + }) { + assert(() { + if (widget.bottomSheet != null) { + throw FlutterError( + 'Scaffold.bottomSheet cannot be specified while a bottom sheet ' + 'displayed with showBottomSheet() is still visible.\n' + 'Rebuild the Scaffold with a null bottomSheet before calling showBottomSheet().', + ); + } + return true; + }()); + assert(debugCheckHasMediaQuery(context)); + + _closeCurrentBottomSheet(); + final AnimationController controller = (transitionAnimationController ?? BottomSheet.createAnimationController(this))..forward(); + setState(() { + _currentBottomSheet = _buildBottomSheet( + builder, + isPersistent: false, + animationController: controller, + backgroundColor: backgroundColor, + elevation: elevation, + shape: shape, + clipBehavior: clipBehavior, + constraints: constraints, + enableDrag: enableDrag, + shouldDisposeAnimationController: transitionAnimationController == null, + ); + }); + return _currentBottomSheet!; + } + + // Floating Action Button API + late AnimationController _floatingActionButtonMoveController; + late FloatingActionButtonAnimator _floatingActionButtonAnimator; + FloatingActionButtonLocation? _previousFloatingActionButtonLocation; + FloatingActionButtonLocation? _floatingActionButtonLocation; + + late AnimationController _floatingActionButtonVisibilityController; + + /// Gets the current value of the visibility animation for the + /// [Scaffold.floatingActionButton]. + double get _floatingActionButtonVisibilityValue => _floatingActionButtonVisibilityController.value; + + /// Sets the current value of the visibility animation for the + /// [Scaffold.floatingActionButton]. + set _floatingActionButtonVisibilityValue(double newValue) { + _floatingActionButtonVisibilityController.value = clampDouble(newValue, + _floatingActionButtonVisibilityController.lowerBound, + _floatingActionButtonVisibilityController.upperBound, + ); + } + + /// Shows the [Scaffold.floatingActionButton]. + TickerFuture _showFloatingActionButton() { + return _floatingActionButtonVisibilityController.forward(); + } + + // Moves the Floating Action Button to the new Floating Action Button Location. + void _moveFloatingActionButton(final FloatingActionButtonLocation newLocation) { + FloatingActionButtonLocation? previousLocation = _floatingActionButtonLocation; + double restartAnimationFrom = 0.0; + // If the Floating Action Button is moving right now, we need to start from a snapshot of the current transition. + if (_floatingActionButtonMoveController.isAnimating) { + previousLocation = _TransitionSnapshotFabLocation(_previousFloatingActionButtonLocation!, _floatingActionButtonLocation!, _floatingActionButtonAnimator, _floatingActionButtonMoveController.value); + restartAnimationFrom = _floatingActionButtonAnimator.getAnimationRestart(_floatingActionButtonMoveController.value); + } + + setState(() { + _previousFloatingActionButtonLocation = previousLocation; + _floatingActionButtonLocation = newLocation; + }); + + // Animate the motion even when the fab is null so that if the exit animation is running, + // the old fab will start the motion transition while it exits instead of jumping to the + // new position. + _floatingActionButtonMoveController.forward(from: restartAnimationFrom); + } + + // iOS FEATURES - status bar tap, back gesture + + // On iOS, tapping the status bar scrolls the app's primary scrollable to the + // top. We implement this by looking up the primary scroll controller and + // scrolling it to the top when tapped. + void _handleStatusBarTap() { + final ScrollController? primaryScrollController = PrimaryScrollController.maybeOf(context); + if (primaryScrollController != null && primaryScrollController.hasClients) { + primaryScrollController.animateTo( + 0.0, + duration: const Duration(milliseconds: 1000), + curve: Curves.easeOutCirc, + ); + } + } + + // INTERNALS + + late _ScaffoldGeometryNotifier _geometryNotifier; + + bool get _resizeToAvoidBottomInset { + return widget.resizeToAvoidBottomInset ?? true; + } + + @override + void initState() { + super.initState(); + _geometryNotifier = _ScaffoldGeometryNotifier(const ScaffoldGeometry(), context); + _floatingActionButtonLocation = widget.floatingActionButtonLocation ?? _kDefaultFloatingActionButtonLocation; + _floatingActionButtonAnimator = widget.floatingActionButtonAnimator ?? _kDefaultFloatingActionButtonAnimator; + _previousFloatingActionButtonLocation = _floatingActionButtonLocation; + _floatingActionButtonMoveController = AnimationController( + vsync: this, + value: 1.0, + duration: kFloatingActionButtonSegue * 2, + ); + + _floatingActionButtonVisibilityController = AnimationController( + duration: kFloatingActionButtonSegue, + vsync: this, + ); + } + + @override + void didUpdateWidget(Scaffold oldWidget) { + super.didUpdateWidget(oldWidget); + // Update the Floating Action Button Animator, and then schedule the Floating Action Button for repositioning. + if (widget.floatingActionButtonAnimator != oldWidget.floatingActionButtonAnimator) { + _floatingActionButtonAnimator = widget.floatingActionButtonAnimator ?? _kDefaultFloatingActionButtonAnimator; + } + if (widget.floatingActionButtonLocation != oldWidget.floatingActionButtonLocation) { + _moveFloatingActionButton(widget.floatingActionButtonLocation ?? _kDefaultFloatingActionButtonLocation); + } + if (widget.bottomSheet != oldWidget.bottomSheet) { + assert(() { + if (widget.bottomSheet != null && (_currentBottomSheet?._isLocalHistoryEntry ?? false)) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'Scaffold.bottomSheet cannot be specified while a bottom sheet displayed ' + 'with showBottomSheet() is still visible.', + ), + ErrorHint( + 'Use the PersistentBottomSheetController ' + 'returned by showBottomSheet() to close the old bottom sheet before creating ' + 'a Scaffold with a (non null) bottomSheet.', + ), + ]); + } + return true; + }()); + if (widget.bottomSheet == null) { + _closeCurrentBottomSheet(); + } else if (widget.bottomSheet != null && oldWidget.bottomSheet == null) { + _maybeBuildPersistentBottomSheet(); + } else { + _updatePersistentBottomSheet(); + } + } + } + + @override + void didChangeDependencies() { + // Using maybeOf is valid here since both the Scaffold and ScaffoldMessenger + // are currently available for managing SnackBars. + final ScaffoldMessengerState? currentScaffoldMessenger = ScaffoldMessenger.maybeOf(context); + // If our ScaffoldMessenger has changed, unregister with the old one first. + if (_scaffoldMessenger != null && + (currentScaffoldMessenger == null || _scaffoldMessenger != currentScaffoldMessenger)) { + _scaffoldMessenger?._unregister(this); + } + // Register with the current ScaffoldMessenger, if there is one. + _scaffoldMessenger = currentScaffoldMessenger; + _scaffoldMessenger?._register(this); + + _maybeBuildPersistentBottomSheet(); + super.didChangeDependencies(); + } + + @override + void dispose() { + _geometryNotifier.dispose(); + _floatingActionButtonMoveController.dispose(); + _floatingActionButtonVisibilityController.dispose(); + _scaffoldMessenger?._unregister(this); + _drawerOpened.dispose(); + _endDrawerOpened.dispose(); + super.dispose(); + } + + void _addIfNonNull( + List<LayoutId> children, + Widget? child, + Object childId, { + required bool removeLeftPadding, + required bool removeTopPadding, + required bool removeRightPadding, + required bool removeBottomPadding, + bool removeBottomInset = false, + bool maintainBottomViewPadding = false, + }) { + MediaQueryData data = MediaQuery.of(context).removePadding( + removeLeft: removeLeftPadding, + removeTop: removeTopPadding, + removeRight: removeRightPadding, + removeBottom: removeBottomPadding, + ); + if (removeBottomInset) { + data = data.removeViewInsets(removeBottom: true); + } + + if (maintainBottomViewPadding && data.viewInsets.bottom != 0.0) { + data = data.copyWith( + padding: data.padding.copyWith(bottom: data.viewPadding.bottom), + ); + } + + if (child != null) { + children.add( + LayoutId( + id: childId, + child: MediaQuery(data: data, child: child), + ), + ); + } + } + + void _buildEndDrawer(List<LayoutId> children, TextDirection textDirection) { + if (widget.endDrawer != null) { + assert(hasEndDrawer); + _addIfNonNull( + children, + DrawerController( + key: _endDrawerKey, + alignment: DrawerAlignment.end, + drawerCallback: _endDrawerOpenedCallback, + dragStartBehavior: widget.drawerDragStartBehavior, + scrimColor: widget.drawerScrimColor, + edgeDragWidth: widget.drawerEdgeDragWidth, + enableOpenDragGesture: widget.endDrawerEnableOpenDragGesture, + isDrawerOpen: _endDrawerOpened.value, + child: widget.endDrawer!, + ), + _ScaffoldSlot.endDrawer, + // remove the side padding from the side we're not touching + removeLeftPadding: textDirection == TextDirection.ltr, + removeTopPadding: false, + removeRightPadding: textDirection == TextDirection.rtl, + removeBottomPadding: false, + ); + } + } + + void _buildDrawer(List<LayoutId> children, TextDirection textDirection) { + if (widget.drawer != null) { + assert(hasDrawer); + _addIfNonNull( + children, + DrawerController( + key: _drawerKey, + alignment: DrawerAlignment.start, + drawerCallback: _drawerOpenedCallback, + dragStartBehavior: widget.drawerDragStartBehavior, + scrimColor: widget.drawerScrimColor, + edgeDragWidth: widget.drawerEdgeDragWidth, + enableOpenDragGesture: widget.drawerEnableOpenDragGesture, + isDrawerOpen: _drawerOpened.value, + child: widget.drawer!, + ), + _ScaffoldSlot.drawer, + // remove the side padding from the side we're not touching + removeLeftPadding: textDirection == TextDirection.rtl, + removeTopPadding: false, + removeRightPadding: textDirection == TextDirection.ltr, + removeBottomPadding: false, + ); + } + } + + bool _showBodyScrim = false; + Color _bodyScrimColor = Colors.black; + + /// Whether to show a [ModalBarrier] over the body of the scaffold. + void showBodyScrim(bool value, double opacity) { + if (_showBodyScrim == value && _bodyScrimColor.opacity == opacity) { + return; + } + setState(() { + _showBodyScrim = value; + _bodyScrimColor = Colors.black.withOpacity(opacity); + }); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + assert(debugCheckHasDirectionality(context)); + final ThemeData themeData = Theme.of(context); + final TextDirection textDirection = Directionality.of(context); + + final List<LayoutId> children = <LayoutId>[]; + _addIfNonNull( + children, + widget.body == null ? null : _BodyBuilder( + extendBody: widget.extendBody, + extendBodyBehindAppBar: widget.extendBodyBehindAppBar, + body: KeyedSubtree(key: _bodyKey, child: widget.body!), + ), + _ScaffoldSlot.body, + removeLeftPadding: false, + removeTopPadding: widget.appBar != null, + removeRightPadding: false, + removeBottomPadding: widget.bottomNavigationBar != null || widget.persistentFooterButtons != null, + removeBottomInset: _resizeToAvoidBottomInset, + ); + if (_showBodyScrim) { + _addIfNonNull( + children, + ModalBarrier( + dismissible: false, + color: _bodyScrimColor, + ), + _ScaffoldSlot.bodyScrim, + removeLeftPadding: true, + removeTopPadding: true, + removeRightPadding: true, + removeBottomPadding: true, + ); + } + + if (widget.appBar != null) { + final double topPadding = widget.primary ? MediaQuery.paddingOf(context).top : 0.0; + _appBarMaxHeight = AppBar.preferredHeightFor(context, widget.appBar!.preferredSize) + topPadding; + assert(_appBarMaxHeight! >= 0.0 && _appBarMaxHeight!.isFinite); + _addIfNonNull( + children, + ConstrainedBox( + constraints: BoxConstraints(maxHeight: _appBarMaxHeight!), + child: FlexibleSpaceBar.createSettings( + currentExtent: _appBarMaxHeight!, + child: widget.appBar!, + ), + ), + _ScaffoldSlot.appBar, + removeLeftPadding: false, + removeTopPadding: false, + removeRightPadding: false, + removeBottomPadding: true, + ); + } + + bool isSnackBarFloating = false; + double? snackBarWidth; + + if (_currentBottomSheet != null || _dismissedBottomSheets.isNotEmpty) { + final Widget stack = Stack( + alignment: Alignment.bottomCenter, + children: <Widget>[ + ..._dismissedBottomSheets, + if (_currentBottomSheet != null) _currentBottomSheet!._widget, + ], + ); + _addIfNonNull( + children, + stack, + _ScaffoldSlot.bottomSheet, + removeLeftPadding: false, + removeTopPadding: true, + removeRightPadding: false, + removeBottomPadding: _resizeToAvoidBottomInset, + ); + } + + // SnackBar set by ScaffoldMessenger + if (_messengerSnackBar != null) { + final SnackBarBehavior snackBarBehavior = _messengerSnackBar?._widget.behavior + ?? themeData.snackBarTheme.behavior + ?? SnackBarBehavior.fixed; + isSnackBarFloating = snackBarBehavior == SnackBarBehavior.floating; + snackBarWidth = _messengerSnackBar?._widget.width ?? themeData.snackBarTheme.width; + + _addIfNonNull( + children, + _messengerSnackBar?._widget, + _ScaffoldSlot.snackBar, + removeLeftPadding: false, + removeTopPadding: true, + removeRightPadding: false, + removeBottomPadding: widget.bottomNavigationBar != null || widget.persistentFooterButtons != null, + maintainBottomViewPadding: !_resizeToAvoidBottomInset, + ); + } + + bool extendBodyBehindMaterialBanner = false; + // MaterialBanner set by ScaffoldMessenger + if (_messengerMaterialBanner != null) { + final MaterialBannerThemeData bannerTheme = MaterialBannerTheme.of(context); + final double elevation = _messengerMaterialBanner?._widget.elevation ?? bannerTheme.elevation ?? 0.0; + extendBodyBehindMaterialBanner = elevation != 0.0; + + _addIfNonNull( + children, + _messengerMaterialBanner?._widget, + _ScaffoldSlot.materialBanner, + removeLeftPadding: false, + removeTopPadding: widget.appBar != null, + removeRightPadding: false, + removeBottomPadding: true, + maintainBottomViewPadding: !_resizeToAvoidBottomInset, + ); + } + + if (widget.persistentFooterButtons != null) { + _addIfNonNull( + children, + Container( + decoration: BoxDecoration( + border: Border( + top: Divider.createBorderSide(context, width: 1.0), + ), + ), + child: SafeArea( + top: false, + child: IntrinsicHeight( + child: Container( + alignment: widget.persistentFooterAlignment, + padding: const EdgeInsets.all(8), + child: OverflowBar( + spacing: 8, + overflowAlignment: OverflowBarAlignment.end, + children: widget.persistentFooterButtons!, + ), + ), + ), + ), + ), + _ScaffoldSlot.persistentFooter, + removeLeftPadding: false, + removeTopPadding: true, + removeRightPadding: false, + removeBottomPadding: widget.bottomNavigationBar != null, + maintainBottomViewPadding: !_resizeToAvoidBottomInset, + ); + } + + if (widget.bottomNavigationBar != null) { + _addIfNonNull( + children, + widget.bottomNavigationBar, + _ScaffoldSlot.bottomNavigationBar, + removeLeftPadding: false, + removeTopPadding: true, + removeRightPadding: false, + removeBottomPadding: false, + maintainBottomViewPadding: !_resizeToAvoidBottomInset, + ); + } + + _addIfNonNull( + children, + _FloatingActionButtonTransition( + fabMoveAnimation: _floatingActionButtonMoveController, + fabMotionAnimator: _floatingActionButtonAnimator, + geometryNotifier: _geometryNotifier, + currentController: _floatingActionButtonVisibilityController, + child: widget.floatingActionButton, + ), + _ScaffoldSlot.floatingActionButton, + removeLeftPadding: true, + removeTopPadding: true, + removeRightPadding: true, + removeBottomPadding: true, + ); + + switch (themeData.platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + _addIfNonNull( + children, + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: _handleStatusBarTap, + // iOS accessibility automatically adds scroll-to-top to the clock in the status bar + excludeFromSemantics: true, + ), + _ScaffoldSlot.statusBar, + removeLeftPadding: false, + removeTopPadding: true, + removeRightPadding: false, + removeBottomPadding: true, + ); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + break; + } + + if (_endDrawerOpened.value) { + _buildDrawer(children, textDirection); + _buildEndDrawer(children, textDirection); + } else { + _buildEndDrawer(children, textDirection); + _buildDrawer(children, textDirection); + } + + // The minimum insets for contents of the Scaffold to keep visible. + final EdgeInsets minInsets = MediaQuery.paddingOf(context).copyWith( + bottom: _resizeToAvoidBottomInset ? MediaQuery.viewInsetsOf(context).bottom : 0.0, + ); + + // The minimum viewPadding for interactive elements positioned by the + // Scaffold to keep within safe interactive areas. + final EdgeInsets minViewPadding = MediaQuery.viewPaddingOf(context).copyWith( + bottom: _resizeToAvoidBottomInset && MediaQuery.viewInsetsOf(context).bottom != 0.0 ? 0.0 : null, + ); + + // extendBody locked when keyboard is open + final bool extendBody = minInsets.bottom <= 0 && widget.extendBody; + + return _ScaffoldScope( + hasDrawer: hasDrawer, + geometryNotifier: _geometryNotifier, + child: ScrollNotificationObserver( + child: Material( + color: widget.backgroundColor ?? themeData.scaffoldBackgroundColor, + child: AnimatedBuilder(animation: _floatingActionButtonMoveController, builder: (BuildContext context, Widget? child) { + return Actions( + actions: <Type, Action<Intent>>{ + DismissIntent: _DismissDrawerAction(context), + }, + child: CustomMultiChildLayout( + delegate: _ScaffoldLayout( + extendBody: extendBody, + extendBodyBehindAppBar: widget.extendBodyBehindAppBar, + minInsets: minInsets, + minViewPadding: minViewPadding, + currentFloatingActionButtonLocation: _floatingActionButtonLocation!, + floatingActionButtonMoveAnimationProgress: _floatingActionButtonMoveController.value, + floatingActionButtonMotionAnimator: _floatingActionButtonAnimator, + geometryNotifier: _geometryNotifier, + previousFloatingActionButtonLocation: _previousFloatingActionButtonLocation!, + textDirection: textDirection, + isSnackBarFloating: isSnackBarFloating, + extendBodyBehindMaterialBanner: extendBodyBehindMaterialBanner, + snackBarWidth: snackBarWidth, + ), + children: children, + ), + ); + }), + ), + ), + ); + } +} + +class _DismissDrawerAction extends DismissAction { + _DismissDrawerAction(this.context); + + final BuildContext context; + + @override + bool isEnabled(DismissIntent intent) { + return Scaffold.of(context).isDrawerOpen || Scaffold.of(context).isEndDrawerOpen; + } + + @override + void invoke(DismissIntent intent) { + Scaffold.of(context).closeDrawer(); + Scaffold.of(context).closeEndDrawer(); + } +} + +/// An interface for controlling a feature of a [Scaffold]. +/// +/// Commonly obtained from [ScaffoldMessengerState.showSnackBar] or +/// [ScaffoldState.showBottomSheet]. +class ScaffoldFeatureController<T extends Widget, U> { + const ScaffoldFeatureController._(this._widget, this._completer, this.close, this.setState); + final T _widget; + final Completer<U> _completer; + + /// Completes when the feature controlled by this object is no longer visible. + Future<U> get closed => _completer.future; + + /// Remove the feature (e.g., bottom sheet, snack bar, or material banner) from the scaffold. + final VoidCallback close; + + /// Mark the feature (e.g., bottom sheet or snack bar) as needing to rebuild. + final StateSetter? setState; +} + +// TODO(guidezpl): Look into making this public. A copy of this class is in +// bottom_sheet.dart, for now, https://github.com/flutter/flutter/issues/51627 +/// A curve that progresses linearly until a specified [startingPoint], at which +/// point [curve] will begin. Unlike [Interval], [curve] will not start at zero, +/// but will use [startingPoint] as the Y position. +/// +/// For example, if [startingPoint] is set to `0.5`, and [curve] is set to +/// [Curves.easeOut], then the bottom-left quarter of the curve will be a +/// straight line, and the top-right quarter will contain the entire contents of +/// [Curves.easeOut]. +/// +/// This is useful in situations where a widget must track the user's finger +/// (which requires a linear animation), and afterwards can be flung using a +/// curve specified with the [curve] argument, after the finger is released. In +/// such a case, the value of [startingPoint] would be the progress of the +/// animation at the time when the finger was released. +class _BottomSheetSuspendedCurve extends ParametricCurve<double> { + /// Creates a suspended curve. + const _BottomSheetSuspendedCurve( + this.startingPoint, { + this.curve = Curves.easeOutCubic, + }); + + /// The progress value at which [curve] should begin. + /// + /// This defaults to [Curves.easeOutCubic]. + final double startingPoint; + + /// The curve to use when [startingPoint] is reached. + final Curve curve; + + @override + double transform(double t) { + assert(t >= 0.0 && t <= 1.0); + assert(startingPoint >= 0.0 && startingPoint <= 1.0); + + if (t < startingPoint) { + return t; + } + + if (t == 1.0) { + return t; + } + + final double curveProgress = (t - startingPoint) / (1 - startingPoint); + final double transformed = curve.transform(curveProgress); + return lerpDouble(startingPoint, 1, transformed)!; + } + + @override + String toString() { + return '${describeIdentity(this)}($startingPoint, $curve)'; + } +} + +class _StandardBottomSheet extends StatefulWidget { + const _StandardBottomSheet({ + super.key, + required this.animationController, + this.enableDrag = true, + required this.onClosing, + required this.onDismissed, + required this.builder, + this.isPersistent = false, + this.backgroundColor, + this.elevation, + this.shape, + this.clipBehavior, + this.constraints, + this.onDispose, + }); + + final AnimationController animationController; // we control it, but it must be disposed by whoever created it. + final bool enableDrag; + final VoidCallback? onClosing; + final VoidCallback? onDismissed; + final VoidCallback? onDispose; + final WidgetBuilder builder; + final bool isPersistent; + final Color? backgroundColor; + final double? elevation; + final ShapeBorder? shape; + final Clip? clipBehavior; + final BoxConstraints? constraints; + + @override + _StandardBottomSheetState createState() => _StandardBottomSheetState(); +} + +class _StandardBottomSheetState extends State<_StandardBottomSheet> { + ParametricCurve<double> animationCurve = _standardBottomSheetCurve; + + @override + void initState() { + super.initState(); + assert( + widget.animationController.status == AnimationStatus.forward + || widget.animationController.status == AnimationStatus.completed, + ); + widget.animationController.addStatusListener(_handleStatusChange); + } + + @override + void dispose() { + widget.onDispose?.call(); + super.dispose(); + } + + @override + void didUpdateWidget(_StandardBottomSheet oldWidget) { + super.didUpdateWidget(oldWidget); + assert(widget.animationController == oldWidget.animationController); + } + + void close() { + widget.animationController.reverse(); + widget.onClosing?.call(); + } + + void _handleDragStart(DragStartDetails details) { + // Allow the bottom sheet to track the user's finger accurately. + animationCurve = Curves.linear; + } + + void _handleDragEnd(DragEndDetails details, { bool? isClosing }) { + // Allow the bottom sheet to animate smoothly from its current position. + animationCurve = _BottomSheetSuspendedCurve( + widget.animationController.value, + curve: _standardBottomSheetCurve, + ); + } + + void _handleStatusChange(AnimationStatus status) { + if (status == AnimationStatus.dismissed) { + widget.onDismissed?.call(); + } + } + + bool extentChanged(DraggableScrollableNotification notification) { + final double extentRemaining = 1.0 - notification.extent; + final ScaffoldState scaffold = Scaffold.of(context); + if (extentRemaining < _kBottomSheetDominatesPercentage) { + scaffold._floatingActionButtonVisibilityValue = extentRemaining * _kBottomSheetDominatesPercentage * 10; + scaffold.showBodyScrim(true, math.max( + _kMinBottomSheetScrimOpacity, + _kMaxBottomSheetScrimOpacity - scaffold._floatingActionButtonVisibilityValue, + )); + } else { + scaffold._floatingActionButtonVisibilityValue = 1.0; + scaffold.showBodyScrim(false, 0.0); + } + // If the Scaffold.bottomSheet != null, we're a persistent bottom sheet. + if (notification.extent == notification.minExtent && + scaffold.widget.bottomSheet == null && + notification.shouldCloseOnMinExtent) { + close(); + } + return false; + } + + @override + Widget build(BuildContext context) { + return AnimatedBuilder( + animation: widget.animationController, + builder: (BuildContext context, Widget? child) { + return Align( + alignment: AlignmentDirectional.topStart, + heightFactor: animationCurve.transform(widget.animationController.value), + child: child, + ); + }, + child: Semantics( + container: true, + onDismiss: !widget.isPersistent ? close : null, + child: NotificationListener<DraggableScrollableNotification>( + onNotification: extentChanged, + child: BottomSheet( + animationController: widget.animationController, + enableDrag: widget.enableDrag, + onDragStart: _handleDragStart, + onDragEnd: _handleDragEnd, + onClosing: widget.onClosing!, + builder: widget.builder, + backgroundColor: widget.backgroundColor, + elevation: widget.elevation, + shape: widget.shape, + clipBehavior: widget.clipBehavior, + constraints: widget.constraints, + ), + ), + ), + ); + } + +} + +/// A [ScaffoldFeatureController] for standard bottom sheets. +/// +/// This is the type of objects returned by [ScaffoldState.showBottomSheet]. +/// +/// This controller is used to display both standard and persistent bottom +/// sheets. A bottom sheet is only persistent if it is set as the +/// [Scaffold.bottomSheet]. +class PersistentBottomSheetController extends ScaffoldFeatureController<_StandardBottomSheet, void> { + const PersistentBottomSheetController._( + super.widget, + super.completer, + super.close, + StateSetter super.setState, + this._isLocalHistoryEntry, + ) : super._(); + + final bool _isLocalHistoryEntry; +} + +class _ScaffoldScope extends InheritedWidget { + const _ScaffoldScope({ + required this.hasDrawer, + required this.geometryNotifier, + required super.child, + }); + + final bool hasDrawer; + final _ScaffoldGeometryNotifier geometryNotifier; + + @override + bool updateShouldNotify(_ScaffoldScope oldWidget) { + return hasDrawer != oldWidget.hasDrawer; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/scrollbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/scrollbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..c274695eed355d5839a9f2f97e954d2e378b8db8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/scrollbar.dart @@ -0,0 +1,425 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/gestures.dart'; + +import 'color_scheme.dart'; +import 'material_state.dart'; +import 'scrollbar_theme.dart'; +import 'theme.dart'; + +const double _kScrollbarThickness = 8.0; +const double _kScrollbarThicknessWithTrack = 12.0; +const double _kScrollbarMargin = 2.0; +const double _kScrollbarMinLength = 48.0; +const Radius _kScrollbarRadius = Radius.circular(8.0); +const Duration _kScrollbarFadeDuration = Duration(milliseconds: 300); +const Duration _kScrollbarTimeToFade = Duration(milliseconds: 600); + +/// A Material Design scrollbar. +/// +/// To add a scrollbar to a [ScrollView], wrap the scroll view +/// widget in a [Scrollbar] widget. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=DbkIQSvwnZc} +/// +/// {@macro flutter.widgets.Scrollbar} +/// +/// Dynamically changes to a [CupertinoScrollbar], an iOS style scrollbar, by +/// default on the iOS platform. +/// +/// The color of the Scrollbar thumb will change when [MaterialState.dragged], +/// or [MaterialState.hovered] on desktop and web platforms. These stateful +/// color choices can be changed using [ScrollbarThemeData.thumbColor]. +/// +/// {@tool dartpad} +/// This sample shows a [Scrollbar] that executes a fade animation as scrolling +/// occurs. The Scrollbar will fade into view as the user scrolls, and fade out +/// when scrolling stops. +/// +/// ** See code in examples/api/lib/material/scrollbar/scrollbar.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// When [thumbVisibility] is true, the scrollbar thumb will remain visible +/// without the fade animation. This requires that a [ScrollController] is +/// provided to controller, or that the [PrimaryScrollController] is available. +/// +/// When a [ScrollView.scrollDirection] is [Axis.horizontal], it is recommended +/// that the [Scrollbar] is always visible, since scrolling in the horizontal +/// axis is less discoverable. +/// +/// ** See code in examples/api/lib/material/scrollbar/scrollbar.1.dart ** +/// {@end-tool} +/// +/// A scrollbar track can be added using [trackVisibility]. This can also be +/// drawn when triggered by a hover event, or based on any [MaterialState] by +/// using [ScrollbarThemeData.trackVisibility]. +/// +/// The [thickness] of the track and scrollbar thumb can be changed dynamically +/// in response to [MaterialState]s using [ScrollbarThemeData.thickness]. +/// +/// See also: +/// +/// * [RawScrollbar], a basic scrollbar that fades in and out, extended +/// by this class to add more animations and behaviors. +/// * [ScrollbarTheme], which configures the Scrollbar's appearance. +/// * [CupertinoScrollbar], an iOS style scrollbar. +/// * [ListView], which displays a linear, scrollable list of children. +/// * [GridView], which displays a 2 dimensional, scrollable array of children. +class Scrollbar extends StatelessWidget { + /// Creates a Material Design scrollbar that by default will connect to the + /// closest Scrollable descendant of [child]. + /// + /// The [child] should be a source of [ScrollNotification] notifications, + /// typically a [Scrollable] widget. + /// + /// If the [controller] is null, the default behavior is to + /// enable scrollbar dragging using the [PrimaryScrollController]. + /// + /// When null, [thickness] defaults to 8.0 pixels on desktop and web, and 4.0 + /// pixels when on mobile platforms. A null [radius] will result in a default + /// of an 8.0 pixel circular radius about the corners of the scrollbar thumb, + /// except for when executing on [TargetPlatform.android], which will render the + /// thumb without a radius. + const Scrollbar({ + super.key, + required this.child, + this.controller, + this.thumbVisibility, + this.trackVisibility, + this.thickness, + this.radius, + this.notificationPredicate, + this.interactive, + this.scrollbarOrientation, + @Deprecated( + 'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. ' + 'This feature was deprecated after v3.4.0-19.0.pre.', + ) + this.showTrackOnHover, + }); + + /// {@macro flutter.widgets.Scrollbar.child} + final Widget child; + + /// {@macro flutter.widgets.Scrollbar.controller} + final ScrollController? controller; + + /// {@macro flutter.widgets.Scrollbar.thumbVisibility} + /// + /// If this property is null, then [ScrollbarThemeData.thumbVisibility] of + /// [ThemeData.scrollbarTheme] is used. If that is also null, the default value + /// is false. + /// + /// If the thumb visibility is related to the scrollbar's material state, + /// use the global [ScrollbarThemeData.thumbVisibility] or override the + /// sub-tree's theme data. + final bool? thumbVisibility; + + /// {@macro flutter.widgets.Scrollbar.trackVisibility} + /// + /// If this property is null, then [ScrollbarThemeData.trackVisibility] of + /// [ThemeData.scrollbarTheme] is used. If that is also null, the default value + /// is false. + /// + /// If the track visibility is related to the scrollbar's material state, + /// use the global [ScrollbarThemeData.trackVisibility] or override the + /// sub-tree's theme data. + /// + /// Replaces deprecated [showTrackOnHover]. + final bool? trackVisibility; + + /// Controls if the track will show on hover and remain, including during drag. + /// + /// If this property is null, then [ScrollbarThemeData.showTrackOnHover] of + /// [ThemeData.scrollbarTheme] is used. If that is also null, the default value + /// is false. + /// + /// This is deprecated, [trackVisibility] or [ScrollbarThemeData.trackVisibility] + /// should be used instead. + @Deprecated( + 'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. ' + 'This feature was deprecated after v3.4.0-19.0.pre.', + ) + final bool? showTrackOnHover; + + /// The thickness of the scrollbar in the cross axis of the scrollable. + /// + /// If null, the default value is platform dependent. On [TargetPlatform.android], + /// the default thickness is 4.0 pixels. On [TargetPlatform.iOS], + /// [CupertinoScrollbar.defaultThickness] is used. The remaining platforms have a + /// default thickness of 8.0 pixels. + final double? thickness; + + /// The [Radius] of the scrollbar thumb's rounded rectangle corners. + /// + /// If null, the default value is platform dependent. On [TargetPlatform.android], + /// no radius is applied to the scrollbar thumb. On [TargetPlatform.iOS], + /// [CupertinoScrollbar.defaultRadius] is used. The remaining platforms have a + /// default [Radius.circular] of 8.0 pixels. + final Radius? radius; + + /// {@macro flutter.widgets.Scrollbar.interactive} + final bool? interactive; + + /// {@macro flutter.widgets.Scrollbar.notificationPredicate} + final ScrollNotificationPredicate? notificationPredicate; + + /// {@macro flutter.widgets.Scrollbar.scrollbarOrientation} + final ScrollbarOrientation? scrollbarOrientation; + + @override + Widget build(BuildContext context) { + if (Theme.of(context).platform == TargetPlatform.iOS) { + return CupertinoScrollbar( + thumbVisibility: thumbVisibility ?? false, + thickness: thickness ?? CupertinoScrollbar.defaultThickness, + thicknessWhileDragging: thickness ?? CupertinoScrollbar.defaultThicknessWhileDragging, + radius: radius ?? CupertinoScrollbar.defaultRadius, + radiusWhileDragging: radius ?? CupertinoScrollbar.defaultRadiusWhileDragging, + controller: controller, + notificationPredicate: notificationPredicate, + scrollbarOrientation: scrollbarOrientation, + child: child, + ); + } + return _MaterialScrollbar( + controller: controller, + thumbVisibility: thumbVisibility, + trackVisibility: trackVisibility, + showTrackOnHover: showTrackOnHover, + thickness: thickness, + radius: radius, + notificationPredicate: notificationPredicate, + interactive: interactive, + scrollbarOrientation: scrollbarOrientation, + child: child, + ); + } +} + +class _MaterialScrollbar extends RawScrollbar { + const _MaterialScrollbar({ + required super.child, + super.controller, + super.thumbVisibility, + super.trackVisibility, + this.showTrackOnHover, + super.thickness, + super.radius, + ScrollNotificationPredicate? notificationPredicate, + super.interactive, + super.scrollbarOrientation, + }) : super( + fadeDuration: _kScrollbarFadeDuration, + timeToFade: _kScrollbarTimeToFade, + pressDuration: Duration.zero, + notificationPredicate: notificationPredicate ?? defaultScrollNotificationPredicate, + ); + + final bool? showTrackOnHover; + + @override + _MaterialScrollbarState createState() => _MaterialScrollbarState(); +} + +class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> { + late AnimationController _hoverAnimationController; + bool _dragIsActive = false; + bool _hoverIsActive = false; + late ColorScheme _colorScheme; + late ScrollbarThemeData _scrollbarTheme; + // On Android, scrollbars should match native appearance. + late bool _useAndroidScrollbar; + + @override + bool get showScrollbar => widget.thumbVisibility ?? _scrollbarTheme.thumbVisibility?.resolve(_states) ?? false; + + @override + bool get enableGestures => widget.interactive ?? _scrollbarTheme.interactive ?? !_useAndroidScrollbar; + + bool get _showTrackOnHover => widget.showTrackOnHover ?? _scrollbarTheme.showTrackOnHover ?? false; + + MaterialStateProperty<bool> get _trackVisibility => MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.hovered) && _showTrackOnHover) { + return true; + } + return widget.trackVisibility ?? _scrollbarTheme.trackVisibility?.resolve(states) ?? false; + }); + + Set<MaterialState> get _states => <MaterialState>{ + if (_dragIsActive) MaterialState.dragged, + if (_hoverIsActive) MaterialState.hovered, + }; + + MaterialStateProperty<Color> get _thumbColor { + final Color onSurface = _colorScheme.onSurface; + final Brightness brightness = _colorScheme.brightness; + late Color dragColor; + late Color hoverColor; + late Color idleColor; + switch (brightness) { + case Brightness.light: + dragColor = onSurface.withOpacity(0.6); + hoverColor = onSurface.withOpacity(0.5); + idleColor = _useAndroidScrollbar + ? Theme.of(context).highlightColor.withOpacity(1.0) + : onSurface.withOpacity(0.1); + case Brightness.dark: + dragColor = onSurface.withOpacity(0.75); + hoverColor = onSurface.withOpacity(0.65); + idleColor = _useAndroidScrollbar + ? Theme.of(context).highlightColor.withOpacity(1.0) + : onSurface.withOpacity(0.3); + } + + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.dragged)) { + return _scrollbarTheme.thumbColor?.resolve(states) ?? dragColor; + } + + // If the track is visible, the thumb color hover animation is ignored and + // changes immediately. + if (_trackVisibility.resolve(states)) { + return _scrollbarTheme.thumbColor?.resolve(states) ?? hoverColor; + } + + return Color.lerp( + _scrollbarTheme.thumbColor?.resolve(states) ?? idleColor, + _scrollbarTheme.thumbColor?.resolve(states) ?? hoverColor, + _hoverAnimationController.value, + )!; + }); + } + + MaterialStateProperty<Color> get _trackColor { + final Color onSurface = _colorScheme.onSurface; + final Brightness brightness = _colorScheme.brightness; + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (showScrollbar && _trackVisibility.resolve(states)) { + return _scrollbarTheme.trackColor?.resolve(states) + ?? (brightness == Brightness.light + ? onSurface.withOpacity(0.03) + : onSurface.withOpacity(0.05)); + } + return const Color(0x00000000); + }); + } + + MaterialStateProperty<Color> get _trackBorderColor { + final Color onSurface = _colorScheme.onSurface; + final Brightness brightness = _colorScheme.brightness; + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (showScrollbar && _trackVisibility.resolve(states)) { + return _scrollbarTheme.trackBorderColor?.resolve(states) + ?? (brightness == Brightness.light + ? onSurface.withOpacity(0.1) + : onSurface.withOpacity(0.25)); + } + return const Color(0x00000000); + }); + } + + MaterialStateProperty<double> get _thickness { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.hovered) && _trackVisibility.resolve(states)) { + return _scrollbarTheme.thickness?.resolve(states) + ?? _kScrollbarThicknessWithTrack; + } + // The default scrollbar thickness is smaller on mobile. + return widget.thickness + ?? _scrollbarTheme.thickness?.resolve(states) + ?? (_kScrollbarThickness / (_useAndroidScrollbar ? 2 : 1)); + }); + } + + @override + void initState() { + super.initState(); + _hoverAnimationController = AnimationController( + vsync: this, + duration: const Duration(milliseconds: 200), + ); + _hoverAnimationController.addListener(() { + updateScrollbarPainter(); + }); + } + + @override + void didChangeDependencies() { + final ThemeData theme = Theme.of(context); + _colorScheme = theme.colorScheme; + _scrollbarTheme = ScrollbarTheme.of(context); + switch (theme.platform) { + case TargetPlatform.android: + _useAndroidScrollbar = true; + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.fuchsia: + case TargetPlatform.macOS: + case TargetPlatform.windows: + _useAndroidScrollbar = false; + } + super.didChangeDependencies(); + } + + @override + void updateScrollbarPainter() { + scrollbarPainter + ..color = _thumbColor.resolve(_states) + ..trackColor = _trackColor.resolve(_states) + ..trackBorderColor = _trackBorderColor.resolve(_states) + ..textDirection = Directionality.of(context) + ..thickness = _thickness.resolve(_states) + ..radius = widget.radius ?? _scrollbarTheme.radius ?? (_useAndroidScrollbar ? null : _kScrollbarRadius) + ..crossAxisMargin = _scrollbarTheme.crossAxisMargin ?? (_useAndroidScrollbar ? 0.0 : _kScrollbarMargin) + ..mainAxisMargin = _scrollbarTheme.mainAxisMargin ?? 0.0 + ..minLength = _scrollbarTheme.minThumbLength ?? _kScrollbarMinLength + ..padding = MediaQuery.paddingOf(context) + ..scrollbarOrientation = widget.scrollbarOrientation + ..ignorePointer = !enableGestures; + } + + @override + void handleThumbPressStart(Offset localPosition) { + super.handleThumbPressStart(localPosition); + setState(() { _dragIsActive = true; }); + } + + @override + void handleThumbPressEnd(Offset localPosition, Velocity velocity) { + super.handleThumbPressEnd(localPosition, velocity); + setState(() { _dragIsActive = false; }); + } + + @override + void handleHover(PointerHoverEvent event) { + super.handleHover(event); + // Check if the position of the pointer falls over the painted scrollbar + if (isPointerOverScrollbar(event.position, event.kind, forHover: true)) { + // Pointer is hovering over the scrollbar + setState(() { _hoverIsActive = true; }); + _hoverAnimationController.forward(); + } else if (_hoverIsActive) { + // Pointer was, but is no longer over painted scrollbar. + setState(() { _hoverIsActive = false; }); + _hoverAnimationController.reverse(); + } + } + + @override + void handleHoverExit(PointerExitEvent event) { + super.handleHoverExit(event); + setState(() { _hoverIsActive = false; }); + _hoverAnimationController.reverse(); + } + + @override + void dispose() { + _hoverAnimationController.dispose(); + super.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/scrollbar_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/scrollbar_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..5cee3bfd4541471f30c4729ab738ad58b6e1dc8d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/scrollbar_theme.dart @@ -0,0 +1,300 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [Scrollbar] widgets. +/// +/// Descendant widgets obtain the current [ScrollbarThemeData] object with +/// `ScrollbarTheme.of(context)`. Instances of [ScrollbarThemeData] can be +/// customized with [ScrollbarThemeData.copyWith]. +/// +/// Typically the [ScrollbarThemeData] of a [ScrollbarTheme] is specified as +/// part of the overall [Theme] with [ThemeData.scrollbarTheme]. +/// +/// All [ScrollbarThemeData] properties are `null` by default. When null, the +/// [Scrollbar] computes its own default values, typically based on the overall +/// theme's [ThemeData.colorScheme]. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class ScrollbarThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.scrollbarTheme]. + const ScrollbarThemeData({ + this.thumbVisibility, + this.thickness, + this.trackVisibility, + this.radius, + this.thumbColor, + this.trackColor, + this.trackBorderColor, + this.crossAxisMargin, + this.mainAxisMargin, + this.minThumbLength, + this.interactive, + @Deprecated( + 'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. ' + 'This feature was deprecated after v3.4.0-19.0.pre.', + ) + this.showTrackOnHover, + }); + + /// Overrides the default value of [Scrollbar.thumbVisibility] in all + /// descendant [Scrollbar] widgets. + final MaterialStateProperty<bool?>? thumbVisibility; + + /// Overrides the default value of [Scrollbar.thickness] in all + /// descendant [Scrollbar] widgets. + /// + /// Resolves in the following states: + /// * [MaterialState.hovered] on web and desktop platforms. + final MaterialStateProperty<double?>? thickness; + + /// Overrides the default value of [Scrollbar.trackVisibility] in all + /// descendant [Scrollbar] widgets. + final MaterialStateProperty<bool?>? trackVisibility; + + /// Overrides the default value of [Scrollbar.showTrackOnHover] in all + /// descendant [Scrollbar] widgets. + @Deprecated( + 'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. ' + 'This feature was deprecated after v3.4.0-19.0.pre.', + ) + final bool? showTrackOnHover; + + /// Overrides the default value of [Scrollbar.interactive] in all + /// descendant [Scrollbar] widgets. + final bool? interactive; + + /// Overrides the default value of [Scrollbar.radius] in all + /// descendant widgets. + final Radius? radius; + + /// Overrides the default [Color] of the [Scrollbar] thumb in all descendant + /// [Scrollbar] widgets. + /// + /// Resolves in the following states: + /// * [MaterialState.dragged]. + /// * [MaterialState.hovered] on web and desktop platforms. + final MaterialStateProperty<Color?>? thumbColor; + + /// Overrides the default [Color] of the [Scrollbar] track when + /// [showTrackOnHover] is true in all descendant [Scrollbar] widgets. + /// + /// Resolves in the following states: + /// * [MaterialState.hovered] on web and desktop platforms. + final MaterialStateProperty<Color?>? trackColor; + + /// Overrides the default [Color] of the [Scrollbar] track border when + /// [showTrackOnHover] is true in all descendant [Scrollbar] widgets. + /// + /// Resolves in the following states: + /// * [MaterialState.hovered] on web and desktop platforms. + final MaterialStateProperty<Color?>? trackBorderColor; + + /// Overrides the default value of the [ScrollbarPainter.crossAxisMargin] + /// property in all descendant [Scrollbar] widgets. + /// + /// See also: + /// + /// * [ScrollbarPainter.crossAxisMargin], which sets the distance from the + /// scrollbar's side to the nearest edge in logical pixels. + final double? crossAxisMargin; + + /// Overrides the default value of the [ScrollbarPainter.mainAxisMargin] + /// property in all descendant [Scrollbar] widgets. + /// + /// See also: + /// + /// * [ScrollbarPainter.mainAxisMargin], which sets the distance from the + /// scrollbar's start and end to the edge of the viewport in logical pixels. + final double? mainAxisMargin; + + /// Overrides the default value of the [ScrollbarPainter.minLength] + /// property in all descendant [Scrollbar] widgets. + /// + /// See also: + /// + /// * [ScrollbarPainter.minLength], which sets the preferred smallest size + /// the scrollbar can shrink to when the total scrollable extent is large, + /// the current visible viewport is small, and the viewport is not + /// overscrolled. + final double? minThumbLength; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + ScrollbarThemeData copyWith({ + MaterialStateProperty<bool?>? thumbVisibility, + MaterialStateProperty<double?>? thickness, + MaterialStateProperty<bool?>? trackVisibility, + bool? interactive, + Radius? radius, + MaterialStateProperty<Color?>? thumbColor, + MaterialStateProperty<Color?>? trackColor, + MaterialStateProperty<Color?>? trackBorderColor, + double? crossAxisMargin, + double? mainAxisMargin, + double? minThumbLength, + @Deprecated( + 'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. ' + 'This feature was deprecated after v3.4.0-19.0.pre.', + ) + bool? showTrackOnHover, + }) { + return ScrollbarThemeData( + thumbVisibility: thumbVisibility ?? this.thumbVisibility, + thickness: thickness ?? this.thickness, + trackVisibility: trackVisibility ?? this.trackVisibility, + showTrackOnHover: showTrackOnHover ?? this.showTrackOnHover, + interactive: interactive ?? this.interactive, + radius: radius ?? this.radius, + thumbColor: thumbColor ?? this.thumbColor, + trackColor: trackColor ?? this.trackColor, + trackBorderColor: trackBorderColor ?? this.trackBorderColor, + crossAxisMargin: crossAxisMargin ?? this.crossAxisMargin, + mainAxisMargin: mainAxisMargin ?? this.mainAxisMargin, + minThumbLength: minThumbLength ?? this.minThumbLength, + ); + } + + /// Linearly interpolate between two Scrollbar themes. + /// + /// {@macro dart.ui.shadow.lerp} + static ScrollbarThemeData lerp(ScrollbarThemeData? a, ScrollbarThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return ScrollbarThemeData( + thumbVisibility: MaterialStateProperty.lerp<bool?>(a?.thumbVisibility, b?.thumbVisibility, t, _lerpBool), + thickness: MaterialStateProperty.lerp<double?>(a?.thickness, b?.thickness, t, lerpDouble), + trackVisibility: MaterialStateProperty.lerp<bool?>(a?.trackVisibility, b?.trackVisibility, t, _lerpBool), + showTrackOnHover: _lerpBool(a?.showTrackOnHover, b?.showTrackOnHover, t), + interactive: _lerpBool(a?.interactive, b?.interactive, t), + radius: Radius.lerp(a?.radius, b?.radius, t), + thumbColor: MaterialStateProperty.lerp<Color?>(a?.thumbColor, b?.thumbColor, t, Color.lerp), + trackColor: MaterialStateProperty.lerp<Color?>(a?.trackColor, b?.trackColor, t, Color.lerp), + trackBorderColor: MaterialStateProperty.lerp<Color?>(a?.trackBorderColor, b?.trackBorderColor, t, Color.lerp), + crossAxisMargin: lerpDouble(a?.crossAxisMargin, b?.crossAxisMargin, t), + mainAxisMargin: lerpDouble(a?.mainAxisMargin, b?.mainAxisMargin, t), + minThumbLength: lerpDouble(a?.minThumbLength, b?.minThumbLength, t), + ); + } + + @override + int get hashCode => Object.hash( + thumbVisibility, + thickness, + trackVisibility, + showTrackOnHover, + interactive, + radius, + thumbColor, + trackColor, + trackBorderColor, + crossAxisMargin, + mainAxisMargin, + minThumbLength, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ScrollbarThemeData + && other.thumbVisibility == thumbVisibility + && other.thickness == thickness + && other.trackVisibility == trackVisibility + && other.showTrackOnHover == showTrackOnHover + && other.interactive == interactive + && other.radius == radius + && other.thumbColor == thumbColor + && other.trackColor == trackColor + && other.trackBorderColor == trackBorderColor + && other.crossAxisMargin == crossAxisMargin + && other.mainAxisMargin == mainAxisMargin + && other.minThumbLength == minThumbLength; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MaterialStateProperty<bool?>>('thumbVisibility', thumbVisibility, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('thickness', thickness, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<bool?>>('trackVisibility', trackVisibility, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('showTrackOnHover', showTrackOnHover, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('interactive', interactive, defaultValue: null)); + properties.add(DiagnosticsProperty<Radius>('radius', radius, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('thumbColor', thumbColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('trackColor', trackColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('trackBorderColor', trackBorderColor, defaultValue: null)); + properties.add(DiagnosticsProperty<double>('crossAxisMargin', crossAxisMargin, defaultValue: null)); + properties.add(DiagnosticsProperty<double>('mainAxisMargin', mainAxisMargin, defaultValue: null)); + properties.add(DiagnosticsProperty<double>('minThumbLength', minThumbLength, defaultValue: null)); + } +} + +bool? _lerpBool(bool? a, bool? b, double t) => t < 0.5 ? a : b; + +/// Applies a scrollbar theme to descendant [Scrollbar] widgets. +/// +/// Descendant widgets obtain the current theme's [ScrollbarThemeData] using +/// [ScrollbarTheme.of]. When a widget uses [ScrollbarTheme.of], it is +/// automatically rebuilt if the theme later changes. +/// +/// A scrollbar theme can be specified as part of the overall Material theme +/// using [ThemeData.scrollbarTheme]. +/// +/// See also: +/// +/// * [ScrollbarThemeData], which describes the configuration of a +/// scrollbar theme. +class ScrollbarTheme extends InheritedTheme { + /// Constructs a scrollbar theme that configures all descendant [Scrollbar] + /// widgets. + const ScrollbarTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties used for all descendant [Scrollbar] widgets. + final ScrollbarThemeData data; + + /// Returns the configuration [data] from the closest [ScrollbarTheme] + /// ancestor. If there is no ancestor, it returns [ThemeData.scrollbarTheme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ScrollbarThemeData theme = ScrollbarTheme.of(context); + /// ``` + static ScrollbarThemeData of(BuildContext context) { + final ScrollbarTheme? scrollbarTheme = context.dependOnInheritedWidgetOfExactType<ScrollbarTheme>(); + return scrollbarTheme?.data ?? Theme.of(context).scrollbarTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return ScrollbarTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(ScrollbarTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search.dart new file mode 100644 index 0000000000000000000000000000000000000000..bca887c6e804fd07cd3be2c9d23ccfecb4c2926b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search.dart @@ -0,0 +1,625 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'app_bar.dart'; +import 'app_bar_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'debug.dart'; +import 'input_border.dart'; +import 'input_decorator.dart'; +import 'material_localizations.dart'; +import 'scaffold.dart'; +import 'text_field.dart'; +import 'theme.dart'; + +/// Shows a full screen search page and returns the search result selected by +/// the user when the page is closed. +/// +/// The search page consists of an app bar with a search field and a body which +/// can either show suggested search queries or the search results. +/// +/// The appearance of the search page is determined by the provided +/// `delegate`. The initial query string is given by `query`, which defaults +/// to the empty string. When `query` is set to null, `delegate.query` will +/// be used as the initial query. +/// +/// This method returns the selected search result, which can be set in the +/// [SearchDelegate.close] call. If the search page is closed with the system +/// back button, it returns null. +/// +/// A given [SearchDelegate] can only be associated with one active [showSearch] +/// call. Call [SearchDelegate.close] before re-using the same delegate instance +/// for another [showSearch] call. +/// +/// The `useRootNavigator` argument is used to determine whether to push the +/// search page to the [Navigator] furthest from or nearest to the given +/// `context`. By default, `useRootNavigator` is `false` and the search page +/// route created by this method is pushed to the nearest navigator to the +/// given `context`. It can not be `null`. +/// +/// The transition to the search page triggered by this method looks best if the +/// screen triggering the transition contains an [AppBar] at the top and the +/// transition is called from an [IconButton] that's part of [AppBar.actions]. +/// The animation provided by [SearchDelegate.transitionAnimation] can be used +/// to trigger additional animations in the underlying page while the search +/// page fades in or out. This is commonly used to animate an [AnimatedIcon] in +/// the [AppBar.leading] position e.g. from the hamburger menu to the back arrow +/// used to exit the search page. +/// +/// ## Handling emojis and other complex characters +/// {@macro flutter.widgets.EditableText.onChanged} +/// +/// See also: +/// +/// * [SearchDelegate] to define the content of the search page. +Future<T?> showSearch<T>({ + required BuildContext context, + required SearchDelegate<T> delegate, + String? query = '', + bool useRootNavigator = false, +}) { + delegate.query = query ?? delegate.query; + delegate._currentBody = _SearchBody.suggestions; + return Navigator.of(context, rootNavigator: useRootNavigator).push(_SearchPageRoute<T>( + delegate: delegate, + )); +} + +/// Delegate for [showSearch] to define the content of the search page. +/// +/// The search page always shows an [AppBar] at the top where users can +/// enter their search queries. The buttons shown before and after the search +/// query text field can be customized via [SearchDelegate.buildLeading] +/// and [SearchDelegate.buildActions]. Additionally, a widget can be placed +/// across the bottom of the [AppBar] via [SearchDelegate.buildBottom]. +/// +/// The body below the [AppBar] can either show suggested queries (returned by +/// [SearchDelegate.buildSuggestions]) or - once the user submits a search - the +/// results of the search as returned by [SearchDelegate.buildResults]. +/// +/// [SearchDelegate.query] always contains the current query entered by the user +/// and should be used to build the suggestions and results. +/// +/// The results can be brought on screen by calling [SearchDelegate.showResults] +/// and you can go back to showing the suggestions by calling +/// [SearchDelegate.showSuggestions]. +/// +/// Once the user has selected a search result, [SearchDelegate.close] should be +/// called to remove the search page from the top of the navigation stack and +/// to notify the caller of [showSearch] about the selected search result. +/// +/// A given [SearchDelegate] can only be associated with one active [showSearch] +/// call. Call [SearchDelegate.close] before re-using the same delegate instance +/// for another [showSearch] call. +/// +/// ## Handling emojis and other complex characters +/// {@macro flutter.widgets.EditableText.onChanged} +abstract class SearchDelegate<T> { + /// Constructor to be called by subclasses which may specify + /// [searchFieldLabel], either [searchFieldStyle] or [searchFieldDecorationTheme], + /// [keyboardType] and/or [textInputAction]. Only one of [searchFieldLabel] + /// and [searchFieldDecorationTheme] may be non-null. + /// + /// {@tool snippet} + /// ```dart + /// class CustomSearchHintDelegate extends SearchDelegate<String> { + /// CustomSearchHintDelegate({ + /// required String hintText, + /// }) : super( + /// searchFieldLabel: hintText, + /// keyboardType: TextInputType.text, + /// textInputAction: TextInputAction.search, + /// ); + /// + /// @override + /// Widget buildLeading(BuildContext context) => const Text('leading'); + /// + /// @override + /// PreferredSizeWidget buildBottom(BuildContext context) { + /// return const PreferredSize( + /// preferredSize: Size.fromHeight(56.0), + /// child: Text('bottom')); + /// } + /// + /// @override + /// Widget buildSuggestions(BuildContext context) => const Text('suggestions'); + /// + /// @override + /// Widget buildResults(BuildContext context) => const Text('results'); + /// + /// @override + /// List<Widget> buildActions(BuildContext context) => <Widget>[]; + /// } + /// ``` + /// {@end-tool} + SearchDelegate({ + this.searchFieldLabel, + this.searchFieldStyle, + this.searchFieldDecorationTheme, + this.keyboardType, + this.textInputAction = TextInputAction.search, + }) : assert(searchFieldStyle == null || searchFieldDecorationTheme == null); + + /// Suggestions shown in the body of the search page while the user types a + /// query into the search field. + /// + /// The delegate method is called whenever the content of [query] changes. + /// The suggestions should be based on the current [query] string. If the query + /// string is empty, it is good practice to show suggested queries based on + /// past queries or the current context. + /// + /// Usually, this method will return a [ListView] with one [ListTile] per + /// suggestion. When [ListTile.onTap] is called, [query] should be updated + /// with the corresponding suggestion and the results page should be shown + /// by calling [showResults]. + Widget buildSuggestions(BuildContext context); + + /// The results shown after the user submits a search from the search page. + /// + /// The current value of [query] can be used to determine what the user + /// searched for. + /// + /// This method might be applied more than once to the same query. + /// If your [buildResults] method is computationally expensive, you may want + /// to cache the search results for one or more queries. + /// + /// Typically, this method returns a [ListView] with the search results. + /// When the user taps on a particular search result, [close] should be called + /// with the selected result as argument. This will close the search page and + /// communicate the result back to the initial caller of [showSearch]. + Widget buildResults(BuildContext context); + + /// A widget to display before the current query in the [AppBar]. + /// + /// Typically an [IconButton] configured with a [BackButtonIcon] that exits + /// the search with [close]. One can also use an [AnimatedIcon] driven by + /// [transitionAnimation], which animates from e.g. a hamburger menu to the + /// back button as the search overlay fades in. + /// + /// Returns null if no widget should be shown. + /// + /// See also: + /// + /// * [AppBar.leading], the intended use for the return value of this method. + Widget? buildLeading(BuildContext context); + + /// {@macro flutter.material.appbar.automaticallyImplyLeading} + bool? automaticallyImplyLeading; + + /// {@macro flutter.material.appbar.leadingWidth} + double? leadingWidth; + + /// Widgets to display after the search query in the [AppBar]. + /// + /// If the [query] is not empty, this should typically contain a button to + /// clear the query and show the suggestions again (via [showSuggestions]) if + /// the results are currently shown. + /// + /// Returns null if no widget should be shown. + /// + /// See also: + /// + /// * [AppBar.actions], the intended use for the return value of this method. + List<Widget>? buildActions(BuildContext context); + + /// Widget to display across the bottom of the [AppBar]. + /// + /// Returns null by default, i.e. a bottom widget is not included. + /// + /// See also: + /// + /// * [AppBar.bottom], the intended use for the return value of this method. + /// + PreferredSizeWidget? buildBottom(BuildContext context) => null; + + /// Widget to display a flexible space in the [AppBar]. + /// + /// Returns null by default, i.e. a flexible space widget is not included. + /// + /// See also: + /// + /// * [AppBar.flexibleSpace], the intended use for the return value of this method. + Widget? buildFlexibleSpace(BuildContext context) => null; + + /// The theme used to configure the search page. + /// + /// The returned [ThemeData] will be used to wrap the entire search page, + /// so it can be used to configure any of its components with the appropriate + /// theme properties. + /// + /// Unless overridden, the default theme will configure the AppBar containing + /// the search input text field with a white background and black text on light + /// themes. For dark themes the default is a dark grey background with light + /// color text. + /// + /// See also: + /// + /// * [AppBarTheme], which configures the AppBar's appearance. + /// * [InputDecorationTheme], which configures the appearance of the search + /// text field. + ThemeData appBarTheme(BuildContext context) { + final ThemeData theme = Theme.of(context); + final ColorScheme colorScheme = theme.colorScheme; + return theme.copyWith( + appBarTheme: AppBarTheme( + systemOverlayStyle: colorScheme.brightness == Brightness.dark + ? SystemUiOverlayStyle.light + : SystemUiOverlayStyle.dark, + backgroundColor: colorScheme.brightness == Brightness.dark ? Colors.grey[900] : Colors.white, + iconTheme: theme.primaryIconTheme.copyWith(color: Colors.grey), + titleTextStyle: theme.textTheme.titleLarge, + toolbarTextStyle: theme.textTheme.bodyMedium, + ), + inputDecorationTheme: searchFieldDecorationTheme ?? + InputDecorationTheme( + hintStyle: searchFieldStyle ?? theme.inputDecorationTheme.hintStyle, + border: InputBorder.none, + ), + ); + } + + /// The current query string shown in the [AppBar]. + /// + /// The user manipulates this string via the keyboard. + /// + /// If the user taps on a suggestion provided by [buildSuggestions] this + /// string should be updated to that suggestion via the setter. + String get query => _queryTextController.text; + + /// Changes the current query string. + /// + /// Setting the query string programmatically moves the cursor to the end of the text field. + set query(String value) { + _queryTextController.text = value; + if (_queryTextController.text.isNotEmpty) { + _queryTextController.selection = TextSelection.fromPosition(TextPosition(offset: _queryTextController.text.length)); + } + } + + /// Transition from the suggestions returned by [buildSuggestions] to the + /// [query] results returned by [buildResults]. + /// + /// If the user taps on a suggestion provided by [buildSuggestions] the + /// screen should typically transition to the page showing the search + /// results for the suggested query. This transition can be triggered + /// by calling this method. + /// + /// See also: + /// + /// * [showSuggestions] to show the search suggestions again. + void showResults(BuildContext context) { + _focusNode?.unfocus(); + _currentBody = _SearchBody.results; + } + + /// Transition from showing the results returned by [buildResults] to showing + /// the suggestions returned by [buildSuggestions]. + /// + /// Calling this method will also put the input focus back into the search + /// field of the [AppBar]. + /// + /// If the results are currently shown this method can be used to go back + /// to showing the search suggestions. + /// + /// See also: + /// + /// * [showResults] to show the search results. + void showSuggestions(BuildContext context) { + assert(_focusNode != null, '_focusNode must be set by route before showSuggestions is called.'); + _focusNode!.requestFocus(); + _currentBody = _SearchBody.suggestions; + } + + /// Closes the search page and returns to the underlying route. + /// + /// The value provided for `result` is used as the return value of the call + /// to [showSearch] that launched the search initially. + void close(BuildContext context, T result) { + _currentBody = null; + _focusNode?.unfocus(); + Navigator.of(context) + ..popUntil((Route<dynamic> route) => route == _route) + ..pop(result); + } + + /// The hint text that is shown in the search field when it is empty. + /// + /// If this value is set to null, the value of + /// `MaterialLocalizations.of(context).searchFieldLabel` will be used instead. + final String? searchFieldLabel; + + /// The style of the [searchFieldLabel]. + /// + /// If this value is set to null, the value of the ambient [Theme]'s + /// [InputDecorationTheme.hintStyle] will be used instead. + /// + /// Only one of [searchFieldStyle] or [searchFieldDecorationTheme] can + /// be non-null. + final TextStyle? searchFieldStyle; + + /// The [InputDecorationTheme] used to configure the search field's visuals. + /// + /// Only one of [searchFieldStyle] or [searchFieldDecorationTheme] can + /// be non-null. + final InputDecorationTheme? searchFieldDecorationTheme; + + /// The type of action button to use for the keyboard. + /// + /// Defaults to the default value specified in [TextField]. + final TextInputType? keyboardType; + + /// The text input action configuring the soft keyboard to a particular action + /// button. + /// + /// Defaults to [TextInputAction.search]. + final TextInputAction textInputAction; + + /// [Animation] triggered when the search pages fades in or out. + /// + /// This animation is commonly used to animate [AnimatedIcon]s of + /// [IconButton]s returned by [buildLeading] or [buildActions]. It can also be + /// used to animate [IconButton]s contained within the route below the search + /// page. + Animation<double> get transitionAnimation => _proxyAnimation; + + // The focus node to use for manipulating focus on the search page. This is + // managed, owned, and set by the _SearchPageRoute using this delegate. + FocusNode? _focusNode; + + final TextEditingController _queryTextController = TextEditingController(); + + final ProxyAnimation _proxyAnimation = ProxyAnimation(kAlwaysDismissedAnimation); + + final ValueNotifier<_SearchBody?> _currentBodyNotifier = ValueNotifier<_SearchBody?>(null); + + _SearchBody? get _currentBody => _currentBodyNotifier.value; + set _currentBody(_SearchBody? value) { + _currentBodyNotifier.value = value; + } + + _SearchPageRoute<T>? _route; + + /// Releases the resources. + @mustCallSuper + void dispose() { + _currentBodyNotifier.dispose(); + _focusNode?.dispose(); + _queryTextController.dispose(); + _proxyAnimation.parent = null; + } +} + +/// Describes the body that is currently shown under the [AppBar] in the +/// search page. +enum _SearchBody { + /// Suggested queries are shown in the body. + /// + /// The suggested queries are generated by [SearchDelegate.buildSuggestions]. + suggestions, + + /// Search results are currently shown in the body. + /// + /// The search results are generated by [SearchDelegate.buildResults]. + results, +} + +class _SearchPageRoute<T> extends PageRoute<T> { + _SearchPageRoute({ + required this.delegate, + }) { + assert( + delegate._route == null, + 'The ${delegate.runtimeType} instance is currently used by another active ' + 'search. Please close that search by calling close() on the SearchDelegate ' + 'before opening another search with the same delegate instance.', + ); + delegate._route = this; + } + + final SearchDelegate<T> delegate; + + @override + Color? get barrierColor => null; + + @override + String? get barrierLabel => null; + + @override + Duration get transitionDuration => const Duration(milliseconds: 300); + + @override + bool get maintainState => false; + + @override + Widget buildTransitions( + BuildContext context, + Animation<double> animation, + Animation<double> secondaryAnimation, + Widget child, + ) { + return FadeTransition( + opacity: animation, + child: child, + ); + } + + @override + Animation<double> createAnimation() { + final Animation<double> animation = super.createAnimation(); + delegate._proxyAnimation.parent = animation; + return animation; + } + + @override + Widget buildPage( + BuildContext context, + Animation<double> animation, + Animation<double> secondaryAnimation, + ) { + return _SearchPage<T>( + delegate: delegate, + animation: animation, + ); + } + + @override + void didComplete(T? result) { + super.didComplete(result); + assert(delegate._route == this); + delegate._route = null; + delegate._currentBody = null; + } +} + +class _SearchPage<T> extends StatefulWidget { + const _SearchPage({ + required this.delegate, + required this.animation, + }); + + final SearchDelegate<T> delegate; + final Animation<double> animation; + + @override + State<StatefulWidget> createState() => _SearchPageState<T>(); +} + +class _SearchPageState<T> extends State<_SearchPage<T>> { + // This node is owned, but not hosted by, the search page. Hosting is done by + // the text field. + FocusNode focusNode = FocusNode(); + + @override + void initState() { + super.initState(); + widget.delegate._queryTextController.addListener(_onQueryChanged); + widget.animation.addStatusListener(_onAnimationStatusChanged); + widget.delegate._currentBodyNotifier.addListener(_onSearchBodyChanged); + focusNode.addListener(_onFocusChanged); + widget.delegate._focusNode = focusNode; + } + + @override + void dispose() { + super.dispose(); + widget.delegate._queryTextController.removeListener(_onQueryChanged); + widget.animation.removeStatusListener(_onAnimationStatusChanged); + widget.delegate._currentBodyNotifier.removeListener(_onSearchBodyChanged); + widget.delegate._focusNode = null; + focusNode.dispose(); + } + + void _onAnimationStatusChanged(AnimationStatus status) { + if (status != AnimationStatus.completed) { + return; + } + widget.animation.removeStatusListener(_onAnimationStatusChanged); + if (widget.delegate._currentBody == _SearchBody.suggestions) { + focusNode.requestFocus(); + } + } + + @override + void didUpdateWidget(_SearchPage<T> oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.delegate != oldWidget.delegate) { + oldWidget.delegate._queryTextController.removeListener(_onQueryChanged); + widget.delegate._queryTextController.addListener(_onQueryChanged); + oldWidget.delegate._currentBodyNotifier.removeListener(_onSearchBodyChanged); + widget.delegate._currentBodyNotifier.addListener(_onSearchBodyChanged); + oldWidget.delegate._focusNode = null; + widget.delegate._focusNode = focusNode; + } + } + + void _onFocusChanged() { + if (focusNode.hasFocus && widget.delegate._currentBody != _SearchBody.suggestions) { + widget.delegate.showSuggestions(context); + } + } + + void _onQueryChanged() { + setState(() { + // rebuild ourselves because query changed. + }); + } + + void _onSearchBodyChanged() { + setState(() { + // rebuild ourselves because search body changed. + }); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + final ThemeData theme = widget.delegate.appBarTheme(context); + final String searchFieldLabel = widget.delegate.searchFieldLabel + ?? MaterialLocalizations.of(context).searchFieldLabel; + Widget? body; + switch (widget.delegate._currentBody) { + case _SearchBody.suggestions: + body = KeyedSubtree( + key: const ValueKey<_SearchBody>(_SearchBody.suggestions), + child: widget.delegate.buildSuggestions(context), + ); + case _SearchBody.results: + body = KeyedSubtree( + key: const ValueKey<_SearchBody>(_SearchBody.results), + child: widget.delegate.buildResults(context), + ); + case null: + break; + } + + late final String routeName; + switch (theme.platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + routeName = ''; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + routeName = searchFieldLabel; + } + + return Semantics( + explicitChildNodes: true, + scopesRoute: true, + namesRoute: true, + label: routeName, + child: Theme( + data: theme, + child: Scaffold( + appBar: AppBar( + leadingWidth: widget.delegate.leadingWidth, + automaticallyImplyLeading: widget.delegate.automaticallyImplyLeading ?? true, + leading: widget.delegate.buildLeading(context), + title: TextField( + controller: widget.delegate._queryTextController, + focusNode: focusNode, + style: widget.delegate.searchFieldStyle ?? theme.textTheme.titleLarge, + textInputAction: widget.delegate.textInputAction, + keyboardType: widget.delegate.keyboardType, + onSubmitted: (String _) => widget.delegate.showResults(context), + decoration: InputDecoration(hintText: searchFieldLabel), + ), + flexibleSpace: widget.delegate.buildFlexibleSpace(context), + actions: widget.delegate.buildActions(context), + bottom: widget.delegate.buildBottom(context), + ), + body: AnimatedSwitcher( + duration: const Duration(milliseconds: 300), + child: body, + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search_anchor.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search_anchor.dart new file mode 100644 index 0000000000000000000000000000000000000000..212774273cd4bfa98c158ca5da7886e1e5e36f49 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search_anchor.dart @@ -0,0 +1,1526 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; +import 'dart:ui'; + +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'divider.dart'; +import 'divider_theme.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'input_border.dart'; +import 'input_decorator.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'search_bar_theme.dart'; +import 'search_view_theme.dart'; +import 'text_field.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +const int _kOpenViewMilliseconds = 600; +const Duration _kOpenViewDuration = Duration(milliseconds: _kOpenViewMilliseconds); +const Duration _kAnchorFadeDuration = Duration(milliseconds: 150); +const Curve _kViewFadeOnInterval = Interval(0.0, 1/2); +const Curve _kViewIconsFadeOnInterval = Interval(1/6, 2/6); +const Curve _kViewDividerFadeOnInterval = Interval(0.0, 1/6); +const Curve _kViewListFadeOnInterval = Interval(133 / _kOpenViewMilliseconds, 233 / _kOpenViewMilliseconds); + +/// Signature for a function that creates a [Widget] which is used to open a search view. +/// +/// The `controller` callback provided to [SearchAnchor.builder] can be used +/// to open the search view and control the editable field on the view. +typedef SearchAnchorChildBuilder = Widget Function(BuildContext context, SearchController controller); + +/// Signature for a function that creates a [Widget] to build the suggestion list +/// based on the input in the search bar. +/// +/// The `controller` callback provided to [SearchAnchor.suggestionsBuilder] can be used +/// to close the search view and control the editable field on the view. +typedef SuggestionsBuilder = FutureOr<Iterable<Widget>> Function(BuildContext context, SearchController controller); + +/// Signature for a function that creates a [Widget] to layout the suggestion list. +/// +/// Parameter `suggestions` is the content list that this function wants to lay out. +typedef ViewBuilder = Widget Function(Iterable<Widget> suggestions); + +/// Manages a "search view" route that allows the user to select one of the +/// suggested completions for a search query. +/// +/// The search view's route can either be shown by creating a [SearchController] +/// and then calling [SearchController.openView] or by tapping on an anchor. +/// When the anchor is tapped or [SearchController.openView] is called, the search view either +/// grows to a specific size, or grows to fill the entire screen. By default, +/// the search view only shows full screen on mobile platforms. Use [SearchAnchor.isFullScreen] +/// to override the default setting. +/// +/// The search view is usually opened by a [SearchBar], an [IconButton] or an [Icon]. +/// If [builder] returns an Icon, or any un-tappable widgets, we don't have +/// to explicitly call [SearchController.openView]. +/// +/// The search view route will be popped if the window size is changed and the +/// search view route is not in full-screen mode. However, if the search view route +/// is in full-screen mode, changing the window size, such as rotating a mobile +/// device from portrait mode to landscape mode, will not close the search view. +/// +/// {@tool dartpad} +/// This example shows how to use an IconButton to open a search view in a [SearchAnchor]. +/// It also shows how to use [SearchController] to open or close the search view route. +/// +/// ** See code in examples/api/lib/material/search_anchor/search_anchor.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to set up a floating (or pinned) AppBar with a +/// [SearchAnchor] for a title. +/// +/// ** See code in examples/api/lib/material/search_anchor/search_anchor.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to fetch the search suggestions from a remote API. +/// +/// ** See code in examples/api/lib/material/search_anchor/search_anchor.3.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example demonstrates fetching the search suggestions asynchronously and +/// debouncing network calls. +/// +/// ** See code in examples/api/lib/material/search_anchor/search_anchor.4.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SearchBar], a widget that defines a search bar. +/// * [SearchBarTheme], a widget that overrides the default configuration of a search bar. +/// * [SearchViewTheme], a widget that overrides the default configuration of a search view. +class SearchAnchor extends StatefulWidget { + /// Creates a const [SearchAnchor]. + /// + /// The [builder] and [suggestionsBuilder] arguments are required. + const SearchAnchor({ + super.key, + this.isFullScreen, + this.searchController, + this.viewBuilder, + this.viewLeading, + this.viewTrailing, + this.viewHintText, + this.viewBackgroundColor, + this.viewElevation, + this.viewSurfaceTintColor, + this.viewSide, + this.viewShape, + this.headerTextStyle, + this.headerHintStyle, + this.dividerColor, + this.viewConstraints, + this.textCapitalization, + this.viewOnChanged, + this.viewOnSubmitted, + required this.builder, + required this.suggestionsBuilder, + this.textInputAction, + this.keyboardType, + }); + + /// Create a [SearchAnchor] that has a [SearchBar] which opens a search view. + /// + /// All the barX parameters are used to customize the anchor. Similarly, all the + /// viewX parameters are used to override the view's defaults. + /// + /// {@tool dartpad} + /// This example shows how to use a [SearchAnchor.bar] which uses a default search + /// bar to open a search view route. + /// + /// ** See code in examples/api/lib/material/search_anchor/search_anchor.0.dart ** + /// {@end-tool} + factory SearchAnchor.bar({ + Widget? barLeading, + Iterable<Widget>? barTrailing, + String? barHintText, + GestureTapCallback? onTap, + ValueChanged<String>? onSubmitted, + ValueChanged<String>? onChanged, + MaterialStateProperty<double?>? barElevation, + MaterialStateProperty<Color?>? barBackgroundColor, + MaterialStateProperty<Color?>? barOverlayColor, + MaterialStateProperty<BorderSide?>? barSide, + MaterialStateProperty<OutlinedBorder?>? barShape, + MaterialStateProperty<EdgeInsetsGeometry?>? barPadding, + MaterialStateProperty<TextStyle?>? barTextStyle, + MaterialStateProperty<TextStyle?>? barHintStyle, + Widget? viewLeading, + Iterable<Widget>? viewTrailing, + String? viewHintText, + Color? viewBackgroundColor, + double? viewElevation, + BorderSide? viewSide, + OutlinedBorder? viewShape, + TextStyle? viewHeaderTextStyle, + TextStyle? viewHeaderHintStyle, + Color? dividerColor, + BoxConstraints? constraints, + BoxConstraints? viewConstraints, + bool? isFullScreen, + SearchController searchController, + TextCapitalization textCapitalization, + required SuggestionsBuilder suggestionsBuilder, + TextInputAction? textInputAction, + TextInputType? keyboardType, + }) = _SearchAnchorWithSearchBar; + + /// Whether the search view grows to fill the entire screen when the + /// [SearchAnchor] is tapped. + /// + /// By default, the search view is full-screen on mobile devices. On other + /// platforms, the search view only grows to a specific size that is determined + /// by the anchor and the default size. + final bool? isFullScreen; + + /// An optional controller that allows opening and closing of the search view from + /// other widgets. + /// + /// If this is null, one internal search controller is created automatically + /// and it is used to open the search view when the user taps on the anchor. + final SearchController? searchController; + + /// Optional callback to obtain a widget to lay out the suggestion list of the + /// search view. + /// + /// Default view uses a [ListView] with a vertical scroll direction. + final ViewBuilder? viewBuilder; + + /// An optional widget to display before the text input field when the search + /// view is open. + /// + /// Typically the [viewLeading] widget is an [Icon] or an [IconButton]. + /// + /// Defaults to a back button which pops the view. + final Widget? viewLeading; + + /// An optional widget list to display after the text input field when the search + /// view is open. + /// + /// Typically the [viewTrailing] widget list only has one or two widgets. + /// + /// Defaults to an icon button which clears the text in the input field. + final Iterable<Widget>? viewTrailing; + + /// Text that is displayed when the search bar's input field is empty. + final String? viewHintText; + + /// The search view's background fill color. + /// + /// If null, the value of [SearchViewThemeData.backgroundColor] will be used. + /// If this is also null, then the default value is [ColorScheme.surface]. + final Color? viewBackgroundColor; + + /// The elevation of the search view's [Material]. + /// + /// If null, the value of [SearchViewThemeData.elevation] will be used. If this + /// is also null, then default value is 6.0. + final double? viewElevation; + + /// The surface tint color of the search view's [Material]. + /// + /// See [Material.surfaceTintColor] for more details. + /// + /// If null, the value of [SearchViewThemeData.surfaceTintColor] will be used. + /// If this is also null, then the default value is [ColorScheme.surfaceTint]. + final Color? viewSurfaceTintColor; + + /// The color and weight of the search view's outline. + /// + /// This value is combined with [viewShape] to create a shape decorated + /// with an outline. This will be ignored if the view is full-screen. + /// + /// If null, the value of [SearchViewThemeData.side] will be used. If this is + /// also null, the search view doesn't have a side by default. + final BorderSide? viewSide; + + /// The shape of the search view's underlying [Material]. + /// + /// This shape is combined with [viewSide] to create a shape decorated + /// with an outline. + /// + /// If null, the value of [SearchViewThemeData.shape] will be used. + /// If this is also null, then the default value is a rectangle shape for full-screen + /// mode and a [RoundedRectangleBorder] shape with a 28.0 radius otherwise. + final OutlinedBorder? viewShape; + + /// The style to use for the text being edited on the search view. + /// + /// If null, defaults to the `bodyLarge` text style from the current [Theme]. + /// The default text color is [ColorScheme.onSurface]. + final TextStyle? headerTextStyle; + + /// The style to use for the [viewHintText] on the search view. + /// + /// If null, the value of [SearchViewThemeData.headerHintStyle] will be used. + /// If this is also null, the value of [headerTextStyle] will be used. If this is also null, + /// defaults to the `bodyLarge` text style from the current [Theme]. The default + /// text color is [ColorScheme.onSurfaceVariant]. + final TextStyle? headerHintStyle; + + /// The color of the divider on the search view. + /// + /// If this property is null, then [SearchViewThemeData.dividerColor] is used. + /// If that is also null, the default value is [ColorScheme.outline]. + final Color? dividerColor; + + /// Optional size constraints for the search view. + /// + /// By default, the search view has the same width as the anchor and is 2/3 + /// the height of the screen. If the width and height of the view are within + /// the [viewConstraints], the view will show its default size. Otherwise, + /// the size of the view will be constrained by this property. + /// + /// If null, the value of [SearchViewThemeData.constraints] will be used. If + /// this is also null, then the constraints defaults to: + /// ```dart + /// const BoxConstraints(minWidth: 360.0, minHeight: 240.0) + /// ``` + final BoxConstraints? viewConstraints; + + /// {@macro flutter.widgets.editableText.textCapitalization} + final TextCapitalization? textCapitalization; + + /// Called each time the user modifies the search view's text field. + /// + /// See also: + /// + /// * [viewOnSubmitted], which is called when the user indicates that they + /// are done editing the search view's text field. + final ValueChanged<String>? viewOnChanged; + + /// Called when the user indicates that they are done editing the text in the + /// text field of a search view. Typically this is called when the user presses + /// the enter key. + /// + /// See also: + /// + /// * [viewOnChanged], which is called when the user modifies the text field + /// of the search view. + final ValueChanged<String>? viewOnSubmitted; + + /// Called to create a widget which can open a search view route when it is tapped. + /// + /// The widget returned by this builder is faded out when it is tapped. + /// At the same time a search view route is faded in. + final SearchAnchorChildBuilder builder; + + /// Called to get the suggestion list for the search view. + /// + /// By default, the list returned by this builder is laid out in a [ListView]. + /// To get a different layout, use [viewBuilder] to override. + final SuggestionsBuilder suggestionsBuilder; + + /// {@macro flutter.widgets.TextField.textInputAction} + final TextInputAction? textInputAction; + + /// The type of action button to use for the keyboard. + /// + /// Defaults to the default value specified in [TextField]. + final TextInputType? keyboardType; + + @override + State<SearchAnchor> createState() => _SearchAnchorState(); +} + +class _SearchAnchorState extends State<SearchAnchor> { + Size? _screenSize; + bool _anchorIsVisible = true; + final GlobalKey _anchorKey = GlobalKey(); + bool get _viewIsOpen => !_anchorIsVisible; + SearchController? _internalSearchController; + SearchController get _searchController => widget.searchController ?? (_internalSearchController ??= SearchController()); + + @override + void initState() { + super.initState(); + _searchController._attach(this); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final Size updatedScreenSize = MediaQuery.of(context).size; + if (_screenSize != null && _screenSize != updatedScreenSize) { + if (_searchController.isOpen && !getShowFullScreenView()) { + _closeView(null); + } + } + _screenSize = updatedScreenSize; + } + + @override + void didUpdateWidget(SearchAnchor oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.searchController != widget.searchController) { + oldWidget.searchController?._detach(this); + _searchController._attach(this); + } + } + + @override + void dispose() { + super.dispose(); + widget.searchController?._detach(this); + _internalSearchController?._detach(this); + _internalSearchController?.dispose(); + } + + void _openView() { + final NavigatorState navigator = Navigator.of(context); + navigator.push(_SearchViewRoute( + viewOnChanged: widget.viewOnChanged, + viewOnSubmitted: widget.viewOnSubmitted, + viewLeading: widget.viewLeading, + viewTrailing: widget.viewTrailing, + viewHintText: widget.viewHintText, + viewBackgroundColor: widget.viewBackgroundColor, + viewElevation: widget.viewElevation, + viewSurfaceTintColor: widget.viewSurfaceTintColor, + viewSide: widget.viewSide, + viewShape: widget.viewShape, + viewHeaderTextStyle: widget.headerTextStyle, + viewHeaderHintStyle: widget.headerHintStyle, + dividerColor: widget.dividerColor, + viewConstraints: widget.viewConstraints, + showFullScreenView: getShowFullScreenView(), + toggleVisibility: toggleVisibility, + textDirection: Directionality.of(context), + viewBuilder: widget.viewBuilder, + anchorKey: _anchorKey, + searchController: _searchController, + suggestionsBuilder: widget.suggestionsBuilder, + textCapitalization: widget.textCapitalization, + capturedThemes: InheritedTheme.capture(from: context, to: navigator.context), + textInputAction: widget.textInputAction, + keyboardType: widget.keyboardType, + )); + } + + void _closeView(String? selectedText) { + if (selectedText != null) { + _searchController.text = selectedText; + } + Navigator.of(context).pop(); + } + + bool toggleVisibility() { + setState(() { + _anchorIsVisible = !_anchorIsVisible; + }); + return _anchorIsVisible; + } + + bool getShowFullScreenView() { + if (widget.isFullScreen != null) { + return widget.isFullScreen!; + } + + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.android: + case TargetPlatform.fuchsia: + return true; + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + return false; + } + } + + @override + Widget build(BuildContext context) { + return AnimatedOpacity( + key: _anchorKey, + opacity: _anchorIsVisible ? 1.0 : 0.0, + duration: _kAnchorFadeDuration, + child: GestureDetector( + onTap: _openView, + child: widget.builder(context, _searchController), + ), + ); + } +} + +class _SearchViewRoute extends PopupRoute<_SearchViewRoute> { + _SearchViewRoute({ + this.viewOnChanged, + this.viewOnSubmitted, + this.toggleVisibility, + this.textDirection, + this.viewBuilder, + this.viewLeading, + this.viewTrailing, + this.viewHintText, + this.viewBackgroundColor, + this.viewElevation, + this.viewSurfaceTintColor, + this.viewSide, + this.viewShape, + this.viewHeaderTextStyle, + this.viewHeaderHintStyle, + this.dividerColor, + this.viewConstraints, + this.textCapitalization, + required this.showFullScreenView, + required this.anchorKey, + required this.searchController, + required this.suggestionsBuilder, + required this.capturedThemes, + this.textInputAction, + this.keyboardType, + }); + + final ValueChanged<String>? viewOnChanged; + final ValueChanged<String>? viewOnSubmitted; + final ValueGetter<bool>? toggleVisibility; + final TextDirection? textDirection; + final ViewBuilder? viewBuilder; + final Widget? viewLeading; + final Iterable<Widget>? viewTrailing; + final String? viewHintText; + final Color? viewBackgroundColor; + final double? viewElevation; + final Color? viewSurfaceTintColor; + final BorderSide? viewSide; + final OutlinedBorder? viewShape; + final TextStyle? viewHeaderTextStyle; + final TextStyle? viewHeaderHintStyle; + final Color? dividerColor; + final BoxConstraints? viewConstraints; + final TextCapitalization? textCapitalization; + final bool showFullScreenView; + final GlobalKey anchorKey; + final SearchController searchController; + final SuggestionsBuilder suggestionsBuilder; + final CapturedThemes capturedThemes; + final TextInputAction? textInputAction; + final TextInputType? keyboardType; + + @override + Color? get barrierColor => Colors.transparent; + + @override + bool get barrierDismissible => true; + + @override + String? get barrierLabel => 'Dismiss'; + + late final SearchViewThemeData viewDefaults; + late final SearchViewThemeData viewTheme; + final RectTween _rectTween = RectTween(); + + Rect? getRect() { + final BuildContext? context = anchorKey.currentContext; + if (context != null) { + final RenderBox searchBarBox = context.findRenderObject()! as RenderBox; + final Size boxSize = searchBarBox.size; + final NavigatorState navigator = Navigator.of(context); + final Offset boxLocation = searchBarBox.localToGlobal(Offset.zero, ancestor: navigator.context.findRenderObject()); + return boxLocation & boxSize; + } + return null; + } + + @override + TickerFuture didPush() { + assert(anchorKey.currentContext != null); + updateViewConfig(anchorKey.currentContext!); + updateTweens(anchorKey.currentContext!); + toggleVisibility?.call(); + return super.didPush(); + } + + @override + bool didPop(_SearchViewRoute? result) { + assert(anchorKey.currentContext != null); + updateTweens(anchorKey.currentContext!); + toggleVisibility?.call(); + return super.didPop(result); + } + + void updateViewConfig(BuildContext context) { + viewDefaults = _SearchViewDefaultsM3(context, isFullScreen: showFullScreenView); + viewTheme = SearchViewTheme.of(context); + } + + void updateTweens(BuildContext context) { + final RenderBox navigator = Navigator.of(context).context.findRenderObject()! as RenderBox; + final Size screenSize = navigator.size; + final Rect anchorRect = getRect() ?? Rect.zero; + + final BoxConstraints effectiveConstraints = viewConstraints ?? viewTheme.constraints ?? viewDefaults.constraints!; + _rectTween.begin = anchorRect; + + final double viewWidth = clampDouble(anchorRect.width, effectiveConstraints.minWidth, effectiveConstraints.maxWidth); + final double viewHeight = clampDouble(screenSize.height * 2 / 3, effectiveConstraints.minHeight, effectiveConstraints.maxHeight); + + switch (textDirection ?? TextDirection.ltr) { + case TextDirection.ltr: + final double viewLeftToScreenRight = screenSize.width - anchorRect.left; + final double viewTopToScreenBottom = screenSize.height - anchorRect.top; + + // Make sure the search view doesn't go off the screen. If the search view + // doesn't fit, move the top-left corner of the view to fit the window. + // If the window is smaller than the view, then we resize the view to fit the window. + Offset topLeft = anchorRect.topLeft; + if (viewLeftToScreenRight < viewWidth) { + topLeft = Offset(screenSize.width - math.min(viewWidth, screenSize.width), topLeft.dy); + } + if (viewTopToScreenBottom < viewHeight) { + topLeft = Offset(topLeft.dx, screenSize.height - math.min(viewHeight, screenSize.height)); + } + final Size endSize = Size(viewWidth, viewHeight); + _rectTween.end = showFullScreenView ? Offset.zero & screenSize : (topLeft & endSize); + return; + case TextDirection.rtl: + final double viewRightToScreenLeft = anchorRect.right; + final double viewTopToScreenBottom = screenSize.height - anchorRect.top; + + // Make sure the search view doesn't go off the screen. + Offset topLeft = Offset(math.max(anchorRect.right - viewWidth, 0.0), anchorRect.top); + if (viewRightToScreenLeft < viewWidth) { + topLeft = Offset(0.0, topLeft.dy); + } + if (viewTopToScreenBottom < viewHeight) { + topLeft = Offset(topLeft.dx, screenSize.height - math.min(viewHeight, screenSize.height)); + } + final Size endSize = Size(viewWidth, viewHeight); + _rectTween.end = showFullScreenView ? Offset.zero & screenSize : (topLeft & endSize); + } + } + + @override + Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { + + return Directionality( + textDirection: textDirection ?? TextDirection.ltr, + child: AnimatedBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + final Animation<double> curvedAnimation = CurvedAnimation( + parent: animation, + curve: Curves.easeInOutCubicEmphasized, + reverseCurve: Curves.easeInOutCubicEmphasized.flipped, + ); + + final Rect viewRect = _rectTween.evaluate(curvedAnimation)!; + final double topPadding = showFullScreenView + ? lerpDouble(0.0, MediaQuery.paddingOf(context).top, curvedAnimation.value)! + : 0.0; + + return FadeTransition( + opacity: CurvedAnimation( + parent: animation, + curve: _kViewFadeOnInterval, + reverseCurve: _kViewFadeOnInterval.flipped, + ), + child: capturedThemes.wrap( + _ViewContent( + viewOnChanged: viewOnChanged, + viewOnSubmitted: viewOnSubmitted, + viewLeading: viewLeading, + viewTrailing: viewTrailing, + viewHintText: viewHintText, + viewBackgroundColor: viewBackgroundColor, + viewElevation: viewElevation, + viewSurfaceTintColor: viewSurfaceTintColor, + viewSide: viewSide, + viewShape: viewShape, + viewHeaderTextStyle: viewHeaderTextStyle, + viewHeaderHintStyle: viewHeaderHintStyle, + dividerColor: dividerColor, + showFullScreenView: showFullScreenView, + animation: curvedAnimation, + topPadding: topPadding, + viewMaxWidth: _rectTween.end!.width, + viewRect: viewRect, + viewBuilder: viewBuilder, + searchController: searchController, + suggestionsBuilder: suggestionsBuilder, + textCapitalization: textCapitalization, + textInputAction: textInputAction, + keyboardType: keyboardType, + ), + ), + ); + } + ), + ); + } + + @override + Duration get transitionDuration => _kOpenViewDuration; +} + +class _ViewContent extends StatefulWidget { + const _ViewContent({ + this.viewOnChanged, + this.viewOnSubmitted, + this.viewBuilder, + this.viewLeading, + this.viewTrailing, + this.viewHintText, + this.viewBackgroundColor, + this.viewElevation, + this.viewSurfaceTintColor, + this.viewSide, + this.viewShape, + this.viewHeaderTextStyle, + this.viewHeaderHintStyle, + this.dividerColor, + this.textCapitalization, + required this.showFullScreenView, + required this.topPadding, + required this.animation, + required this.viewMaxWidth, + required this.viewRect, + required this.searchController, + required this.suggestionsBuilder, + this.textInputAction, + this.keyboardType, + }); + + final ValueChanged<String>? viewOnChanged; + final ValueChanged<String>? viewOnSubmitted; + final ViewBuilder? viewBuilder; + final Widget? viewLeading; + final Iterable<Widget>? viewTrailing; + final String? viewHintText; + final Color? viewBackgroundColor; + final double? viewElevation; + final Color? viewSurfaceTintColor; + final BorderSide? viewSide; + final OutlinedBorder? viewShape; + final TextStyle? viewHeaderTextStyle; + final TextStyle? viewHeaderHintStyle; + final Color? dividerColor; + final TextCapitalization? textCapitalization; + final bool showFullScreenView; + final double topPadding; + final Animation<double> animation; + final double viewMaxWidth; + final Rect viewRect; + final SearchController searchController; + final SuggestionsBuilder suggestionsBuilder; + final TextInputAction? textInputAction; + final TextInputType? keyboardType; + + @override + State<_ViewContent> createState() => _ViewContentState(); +} + +class _ViewContentState extends State<_ViewContent> { + Size? _screenSize; + late Rect _viewRect; + late final SearchController _controller; + Iterable<Widget> result = <Widget>[]; + + @override + void initState() { + super.initState(); + _viewRect = widget.viewRect; + _controller = widget.searchController; + _controller.addListener(updateSuggestions); + } + + @override + void didUpdateWidget(covariant _ViewContent oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.viewRect != oldWidget.viewRect) { + setState(() { + _viewRect = widget.viewRect; + }); + } + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final Size updatedScreenSize = MediaQuery.of(context).size; + + if (_screenSize != updatedScreenSize) { + _screenSize = updatedScreenSize; + if (widget.showFullScreenView) { + _viewRect = Offset.zero & _screenSize!; + } + } + unawaited(updateSuggestions()); + } + + @override + void dispose() { + _controller.removeListener(updateSuggestions); + super.dispose(); + } + + Widget viewBuilder(Iterable<Widget> suggestions) { + if (widget.viewBuilder == null) { + return MediaQuery.removePadding( + context: context, + removeTop: true, + child: ListView( + children: suggestions.toList() + ), + ); + } + return widget.viewBuilder!(suggestions); + } + + Future<void> updateSuggestions() async { + final Iterable<Widget> suggestions = await widget.suggestionsBuilder(context, _controller); + if (mounted) { + setState(() { + result = suggestions; + }); + } + } + + @override + Widget build(BuildContext context) { + final Widget defaultLeading = IconButton( + icon: const Icon(Icons.arrow_back), + onPressed: () { Navigator.of(context).pop(); }, + style: const ButtonStyle(tapTargetSize: MaterialTapTargetSize.shrinkWrap), + ); + + final List<Widget> defaultTrailing = <Widget>[ + IconButton( + icon: const Icon(Icons.close), + onPressed: () { + _controller.clear(); + }, + ), + ]; + + final SearchViewThemeData viewDefaults = _SearchViewDefaultsM3(context, isFullScreen: widget.showFullScreenView); + final SearchViewThemeData viewTheme = SearchViewTheme.of(context); + final DividerThemeData dividerTheme = DividerTheme.of(context); + + final Color effectiveBackgroundColor = widget.viewBackgroundColor + ?? viewTheme.backgroundColor + ?? viewDefaults.backgroundColor!; + final Color effectiveSurfaceTint = widget.viewSurfaceTintColor + ?? viewTheme.surfaceTintColor + ?? viewDefaults.surfaceTintColor!; + final double effectiveElevation = widget.viewElevation + ?? viewTheme.elevation + ?? viewDefaults.elevation!; + final BorderSide? effectiveSide = widget.viewSide + ?? viewTheme.side + ?? viewDefaults.side; + OutlinedBorder effectiveShape = widget.viewShape + ?? viewTheme.shape + ?? viewDefaults.shape!; + if (effectiveSide != null) { + effectiveShape = effectiveShape.copyWith(side: effectiveSide); + } + final Color effectiveDividerColor = widget.dividerColor + ?? viewTheme.dividerColor + ?? dividerTheme.color + ?? viewDefaults.dividerColor!; + final TextStyle? effectiveTextStyle = widget.viewHeaderTextStyle + ?? viewTheme.headerTextStyle + ?? viewDefaults.headerTextStyle; + final TextStyle? effectiveHintStyle = widget.viewHeaderHintStyle + ?? viewTheme.headerHintStyle + ?? widget.viewHeaderTextStyle + ?? viewTheme.headerTextStyle + ?? viewDefaults.headerHintStyle; + + final Widget viewDivider = DividerTheme( + data: dividerTheme.copyWith(color: effectiveDividerColor), + child: const Divider(height: 1), + ); + + return Align( + alignment: Alignment.topLeft, + child: Transform.translate( + offset: _viewRect.topLeft, + child: SizedBox( + width: _viewRect.width, + height: _viewRect.height, + child: Material( + clipBehavior: Clip.antiAlias, + shape: effectiveShape, + color: effectiveBackgroundColor, + surfaceTintColor: effectiveSurfaceTint, + elevation: effectiveElevation, + child: ClipRect( + clipBehavior: Clip.antiAlias, + child: OverflowBox( + alignment: Alignment.topLeft, + maxWidth: math.min(widget.viewMaxWidth, _screenSize!.width), + minWidth: 0, + child: FadeTransition( + opacity: CurvedAnimation( + parent: widget.animation, + curve: _kViewIconsFadeOnInterval, + reverseCurve: _kViewIconsFadeOnInterval.flipped, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + Padding( + padding: EdgeInsets.only(top: widget.topPadding), + child: SafeArea( + top: false, + bottom: false, + child: SearchBar( + autoFocus: true, + constraints: widget.showFullScreenView ? BoxConstraints(minHeight: _SearchViewDefaultsM3.fullScreenBarHeight) : null, + leading: widget.viewLeading ?? defaultLeading, + trailing: widget.viewTrailing ?? defaultTrailing, + hintText: widget.viewHintText, + backgroundColor: const MaterialStatePropertyAll<Color>(Colors.transparent), + overlayColor: const MaterialStatePropertyAll<Color>(Colors.transparent), + elevation: const MaterialStatePropertyAll<double>(0.0), + textStyle: MaterialStatePropertyAll<TextStyle?>(effectiveTextStyle), + hintStyle: MaterialStatePropertyAll<TextStyle?>(effectiveHintStyle), + controller: _controller, + onChanged: (String value) { + widget.viewOnChanged?.call(value); + updateSuggestions(); + }, + onSubmitted: widget.viewOnSubmitted, + textCapitalization: widget.textCapitalization, + textInputAction: widget.textInputAction, + keyboardType: widget.keyboardType, + ), + ), + ), + FadeTransition( + opacity: CurvedAnimation( + parent: widget.animation, + curve: _kViewDividerFadeOnInterval, + reverseCurve: _kViewFadeOnInterval.flipped, + ), + child: viewDivider), + Expanded( + child: FadeTransition( + opacity: CurvedAnimation( + parent: widget.animation, + curve: _kViewListFadeOnInterval, + reverseCurve: _kViewListFadeOnInterval.flipped, + ), + child: viewBuilder(result), + ), + ), + ], + ), + ), + ), + ), + ), + ), + ), + ); + } +} + +class _SearchAnchorWithSearchBar extends SearchAnchor { + _SearchAnchorWithSearchBar({ + Widget? barLeading, + Iterable<Widget>? barTrailing, + String? barHintText, + GestureTapCallback? onTap, + MaterialStateProperty<double?>? barElevation, + MaterialStateProperty<Color?>? barBackgroundColor, + MaterialStateProperty<Color?>? barOverlayColor, + MaterialStateProperty<BorderSide?>? barSide, + MaterialStateProperty<OutlinedBorder?>? barShape, + MaterialStateProperty<EdgeInsetsGeometry?>? barPadding, + MaterialStateProperty<TextStyle?>? barTextStyle, + MaterialStateProperty<TextStyle?>? barHintStyle, + super.viewLeading, + super.viewTrailing, + String? viewHintText, + super.viewBackgroundColor, + super.viewElevation, + super.viewSide, + super.viewShape, + TextStyle? viewHeaderTextStyle, + TextStyle? viewHeaderHintStyle, + super.dividerColor, + BoxConstraints? constraints, + super.viewConstraints, + super.isFullScreen, + super.searchController, + super.textCapitalization, + ValueChanged<String>? onChanged, + ValueChanged<String>? onSubmitted, + required super.suggestionsBuilder, + super.textInputAction, + super.keyboardType, + }) : super( + viewHintText: viewHintText ?? barHintText, + headerTextStyle: viewHeaderTextStyle, + headerHintStyle: viewHeaderHintStyle, + viewOnSubmitted: onSubmitted, + viewOnChanged: onChanged, + builder: (BuildContext context, SearchController controller) { + return SearchBar( + constraints: constraints, + controller: controller, + onTap: () { + controller.openView(); + onTap?.call(); + }, + onChanged: (String value) { + controller.openView(); + }, + onSubmitted: onSubmitted, + hintText: barHintText, + hintStyle: barHintStyle, + textStyle: barTextStyle, + elevation: barElevation, + backgroundColor: barBackgroundColor, + overlayColor: barOverlayColor, + side: barSide, + shape: barShape, + padding: barPadding ?? const MaterialStatePropertyAll<EdgeInsets>(EdgeInsets.symmetric(horizontal: 16.0)), + leading: barLeading ?? const Icon(Icons.search), + trailing: barTrailing, + textCapitalization: textCapitalization, + textInputAction: textInputAction, + keyboardType: keyboardType, + ); + } + ); +} + +/// A controller to manage a search view created by [SearchAnchor]. +/// +/// A [SearchController] is used to control a menu after it has been created, +/// with methods such as [openView] and [closeView]. It can also control the text in the +/// input field. +/// +/// See also: +/// +/// * [SearchAnchor], a widget that defines a region that opens a search view. +/// * [TextEditingController], A controller for an editable text field. +class SearchController extends TextEditingController { + // The anchor that this controller controls. + // + // This is set automatically when a [SearchController] is given to the anchor + // it controls. + _SearchAnchorState? _anchor; + + /// Whether this controller has associated search anchor. + bool get isAttached => _anchor != null; + + /// Whether or not the associated search view is currently open. + bool get isOpen { + assert(isAttached); + return _anchor!._viewIsOpen; + } + + /// Opens the search view that this controller is associated with. + void openView() { + assert(isAttached); + _anchor!._openView(); + } + + /// Close the search view that this search controller is associated with. + /// + /// If `selectedText` is given, then the text value of the controller is set to + /// `selectedText`. + void closeView(String? selectedText) { + assert(isAttached); + _anchor!._closeView(selectedText); + } + + // ignore: use_setters_to_change_properties + void _attach(_SearchAnchorState anchor) { + _anchor = anchor; + } + + void _detach(_SearchAnchorState anchor) { + if (_anchor == anchor) { + _anchor = null; + } + } +} + +/// A Material Design search bar. +/// +/// A [SearchBar] looks like a [TextField]. Tapping a SearchBar typically shows a +/// "search view" route: a route with the search bar at the top and a list of +/// suggested completions for the search bar's text below. [SearchBar]s are +/// usually created by a [SearchAnchor.builder]. The builder provides a +/// [SearchController] that's used by the search bar's [SearchBar.onTap] or +/// [SearchBar.onChanged] callbacks to show the search view and to hide it +/// when the user selects a suggestion. +/// +/// For [TextDirection.ltr], the [leading] widget is on the left side of the bar. +/// It should contain either a navigational action (such as a menu or up-arrow) +/// or a non-functional search icon. +/// +/// The [trailing] is an optional list that appears at the other end of +/// the search bar. Typically only one or two action icons are included. +/// These actions can represent additional modes of searching (like voice search), +/// a separate high-level action (such as current location) or an overflow menu. +/// +/// {@tool dartpad} +/// This example demonstrates how to use a [SearchBar] as the return value of the +/// [SearchAnchor.builder] property. The [SearchBar] also includes a leading search +/// icon and a trailing action to toggle the brightness. +/// +/// ** See code in examples/api/lib/material/search_anchor/search_bar.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SearchAnchor], a widget that typically uses an [IconButton] or a [SearchBar] +/// to manage a "search view" route. +/// * [SearchBarTheme], a widget that overrides the default configuration of a search bar. +/// * [SearchViewTheme], a widget that overrides the default configuration of a search view. +class SearchBar extends StatefulWidget { + /// Creates a Material Design search bar. + const SearchBar({ + super.key, + this.controller, + this.focusNode, + this.hintText, + this.leading, + this.trailing, + this.onTap, + this.onChanged, + this.onSubmitted, + this.constraints, + this.elevation, + this.backgroundColor, + this.shadowColor, + this.surfaceTintColor, + this.overlayColor, + this.side, + this.shape, + this.padding, + this.textStyle, + this.hintStyle, + this.textCapitalization, + this.autoFocus = false, + this.textInputAction, + this.keyboardType, + }); + + /// Controls the text being edited in the search bar's text field. + /// + /// If null, this widget will create its own [TextEditingController]. + final TextEditingController? controller; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// Text that suggests what sort of input the field accepts. + /// + /// Displayed at the same location on the screen where text may be entered + /// when the input is empty. + /// + /// Defaults to null. + final String? hintText; + + /// A widget to display before the text input field. + /// + /// Typically the [leading] widget is an [Icon] or an [IconButton]. + final Widget? leading; + + /// A list of Widgets to display in a row after the text field. + /// + /// Typically these actions can represent additional modes of searching + /// (like voice search), an avatar, a separate high-level action (such as + /// current location) or an overflow menu. There should not be more than + /// two trailing actions. + final Iterable<Widget>? trailing; + + /// Called when the user taps this search bar. + final GestureTapCallback? onTap; + + /// Invoked upon user input. + final ValueChanged<String>? onChanged; + + /// Called when the user indicates that they are done editing the text in the + /// field. + final ValueChanged<String>? onSubmitted; + + /// Optional size constraints for the search bar. + /// + /// If null, the value of [SearchBarThemeData.constraints] will be used. If + /// this is also null, then the constraints defaults to: + /// ```dart + /// const BoxConstraints(minWidth: 360.0, maxWidth: 800.0, minHeight: 56.0) + /// ``` + final BoxConstraints? constraints; + + /// The elevation of the search bar's [Material]. + /// + /// If null, the value of [SearchBarThemeData.elevation] will be used. If this + /// is also null, then default value is 6.0. + final MaterialStateProperty<double?>? elevation; + + /// The search bar's background fill color. + /// + /// If null, the value of [SearchBarThemeData.backgroundColor] will be used. + /// If this is also null, then the default value is [ColorScheme.surface]. + final MaterialStateProperty<Color?>? backgroundColor; + + /// The shadow color of the search bar's [Material]. + /// + /// If null, the value of [SearchBarThemeData.shadowColor] will be used. + /// If this is also null, then the default value is [ColorScheme.shadow]. + final MaterialStateProperty<Color?>? shadowColor; + + /// The surface tint color of the search bar's [Material]. + /// + /// See [Material.surfaceTintColor] for more details. + /// + /// If null, the value of [SearchBarThemeData.surfaceTintColor] will be used. + /// If this is also null, then the default value is [ColorScheme.surfaceTint]. + final MaterialStateProperty<Color?>? surfaceTintColor; + + /// The highlight color that's typically used to indicate that + /// the search bar is focused, hovered, or pressed. + final MaterialStateProperty<Color?>? overlayColor; + + /// The color and weight of the search bar's outline. + /// + /// This value is combined with [shape] to create a shape decorated + /// with an outline. + /// + /// If null, the value of [SearchBarThemeData.side] will be used. If this is + /// also null, the search bar doesn't have a side by default. + final MaterialStateProperty<BorderSide?>? side; + + /// The shape of the search bar's underlying [Material]. + /// + /// This shape is combined with [side] to create a shape decorated + /// with an outline. + /// + /// If null, the value of [SearchBarThemeData.shape] will be used. + /// If this is also null, defaults to [StadiumBorder]. + final MaterialStateProperty<OutlinedBorder?>? shape; + + /// The padding between the search bar's boundary and its contents. + /// + /// If null, the value of [SearchBarThemeData.padding] will be used. + /// If this is also null, then the default value is 16.0 horizontally. + final MaterialStateProperty<EdgeInsetsGeometry?>? padding; + + /// The style to use for the text being edited. + /// + /// If null, defaults to the `bodyLarge` text style from the current [Theme]. + /// The default text color is [ColorScheme.onSurface]. + final MaterialStateProperty<TextStyle?>? textStyle; + + /// The style to use for the [hintText]. + /// + /// If null, the value of [SearchBarThemeData.hintStyle] will be used. If this + /// is also null, the value of [textStyle] will be used. If this is also null, + /// defaults to the `bodyLarge` text style from the current [Theme]. + /// The default text color is [ColorScheme.onSurfaceVariant]. + final MaterialStateProperty<TextStyle?>? hintStyle; + + /// {@macro flutter.widgets.editableText.textCapitalization} + final TextCapitalization? textCapitalization; + + /// {@macro flutter.widgets.editableText.autofocus} + final bool autoFocus; + + /// {@macro flutter.widgets.TextField.textInputAction} + final TextInputAction? textInputAction; + + /// The type of action button to use for the keyboard. + /// + /// Defaults to the default value specified in [TextField]. + final TextInputType? keyboardType; + + @override + State<SearchBar> createState() => _SearchBarState(); +} + +class _SearchBarState extends State<SearchBar> { + late final MaterialStatesController _internalStatesController; + FocusNode? _internalFocusNode; + FocusNode get _focusNode => widget.focusNode ?? (_internalFocusNode ??= FocusNode()); + + @override + void initState() { + super.initState(); + _internalStatesController = MaterialStatesController(); + _internalStatesController.addListener(() { + setState(() {}); + }); + } + + @override + void dispose() { + _internalStatesController.dispose(); + _internalFocusNode?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final TextDirection textDirection = Directionality.of(context); + final ColorScheme colorScheme = Theme.of(context).colorScheme; + final IconThemeData iconTheme = IconTheme.of(context); + final SearchBarThemeData searchBarTheme = SearchBarTheme.of(context); + final SearchBarThemeData defaults = _SearchBarDefaultsM3(context); + + T? resolve<T>( + MaterialStateProperty<T>? widgetValue, + MaterialStateProperty<T>? themeValue, + MaterialStateProperty<T>? defaultValue, + ) { + final Set<MaterialState> states = _internalStatesController.value; + return widgetValue?.resolve(states) ?? themeValue?.resolve(states) ?? defaultValue?.resolve(states); + } + + final TextStyle? effectiveTextStyle = resolve<TextStyle?>(widget.textStyle, searchBarTheme.textStyle, defaults.textStyle); + final double? effectiveElevation = resolve<double?>(widget.elevation, searchBarTheme.elevation, defaults.elevation); + final Color? effectiveShadowColor = resolve<Color?>(widget.shadowColor, searchBarTheme.shadowColor, defaults.shadowColor); + final Color? effectiveBackgroundColor = resolve<Color?>(widget.backgroundColor, searchBarTheme.backgroundColor, defaults.backgroundColor); + final Color? effectiveSurfaceTintColor = resolve<Color?>(widget.surfaceTintColor, searchBarTheme.surfaceTintColor, defaults.surfaceTintColor); + final OutlinedBorder? effectiveShape = resolve<OutlinedBorder?>(widget.shape, searchBarTheme.shape, defaults.shape); + final BorderSide? effectiveSide = resolve<BorderSide?>(widget.side, searchBarTheme.side, defaults.side); + final EdgeInsetsGeometry? effectivePadding = resolve<EdgeInsetsGeometry?>(widget.padding, searchBarTheme.padding, defaults.padding); + final MaterialStateProperty<Color?>? effectiveOverlayColor = widget.overlayColor ?? searchBarTheme.overlayColor ?? defaults.overlayColor; + final TextCapitalization effectiveTextCapitalization = widget.textCapitalization ?? searchBarTheme.textCapitalization ?? defaults.textCapitalization!; + + final Set<MaterialState> states = _internalStatesController.value; + final TextStyle? effectiveHintStyle = widget.hintStyle?.resolve(states) + ?? searchBarTheme.hintStyle?.resolve(states) + ?? widget.textStyle?.resolve(states) + ?? searchBarTheme.textStyle?.resolve(states) + ?? defaults.hintStyle?.resolve(states); + + final bool isDark = Theme.of(context).brightness == Brightness.dark; + bool isIconThemeColorDefault(Color? color) { + if (isDark) { + return color == kDefaultIconLightColor; + } + return color == kDefaultIconDarkColor; + } + + Widget? leading; + if (widget.leading != null) { + leading = IconTheme.merge( + data: isIconThemeColorDefault(iconTheme.color) + ? IconThemeData(color: colorScheme.onSurface) + : iconTheme, + child: widget.leading!, + ); + } + + List<Widget>? trailing; + if (widget.trailing != null) { + trailing = widget.trailing?.map((Widget trailing) => IconTheme.merge( + data: isIconThemeColorDefault(iconTheme.color) + ? IconThemeData(color: colorScheme.onSurfaceVariant) + : iconTheme, + child: trailing, + )).toList(); + } + + return ConstrainedBox( + constraints: widget.constraints ?? searchBarTheme.constraints ?? defaults.constraints!, + child: Material( + elevation: effectiveElevation!, + shadowColor: effectiveShadowColor, + color: effectiveBackgroundColor, + surfaceTintColor: effectiveSurfaceTintColor, + shape: effectiveShape?.copyWith(side: effectiveSide), + child: InkWell( + onTap: () { + widget.onTap?.call(); + if (!_focusNode.hasFocus) { + _focusNode.requestFocus(); + } + }, + overlayColor: effectiveOverlayColor, + customBorder: effectiveShape?.copyWith(side: effectiveSide), + statesController: _internalStatesController, + child: Padding( + padding: effectivePadding!, + child: Row( + textDirection: textDirection, + children: <Widget>[ + if (leading != null) leading, + Expanded( + child: Padding( + padding: effectivePadding, + child: TextField( + autofocus: widget.autoFocus, + onTap: widget.onTap, + onTapAlwaysCalled: true, + focusNode: _focusNode, + onChanged: widget.onChanged, + onSubmitted: widget.onSubmitted, + controller: widget.controller, + style: effectiveTextStyle, + decoration: InputDecoration( + hintText: widget.hintText, + ).applyDefaults(InputDecorationTheme( + hintStyle: effectiveHintStyle, + // The configuration below is to make sure that the text field + // in `SearchBar` will not be overridden by the overall `InputDecorationTheme` + enabledBorder: InputBorder.none, + border: InputBorder.none, + focusedBorder: InputBorder.none, + contentPadding: EdgeInsets.zero, + // Setting `isDense` to true to allow the text field height to be + // smaller than 48.0 + isDense: true, + )), + textCapitalization: effectiveTextCapitalization, + textInputAction: widget.textInputAction, + keyboardType: widget.keyboardType, + ), + ), + ), + if (trailing != null) ...trailing, + ], + ), + ), + ), + ), + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - SearchBar + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _SearchBarDefaultsM3 extends SearchBarThemeData { + _SearchBarDefaultsM3(this.context); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + MaterialStateProperty<Color?>? get backgroundColor => + MaterialStatePropertyAll<Color>(_colors.surface); + + @override + MaterialStateProperty<double>? get elevation => + const MaterialStatePropertyAll<double>(6.0); + + @override + MaterialStateProperty<Color>? get shadowColor => + MaterialStatePropertyAll<Color>(_colors.shadow); + + @override + MaterialStateProperty<Color>? get surfaceTintColor => + MaterialStatePropertyAll<Color>(_colors.surfaceTint); + + @override + MaterialStateProperty<Color?>? get overlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return Colors.transparent; + } + return Colors.transparent; + }); + + // No default side + + @override + MaterialStateProperty<OutlinedBorder>? get shape => + const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding => + const MaterialStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.symmetric(horizontal: 8.0)); + + @override + MaterialStateProperty<TextStyle?> get textStyle => + MaterialStatePropertyAll<TextStyle?>(_textTheme.bodyLarge?.copyWith(color: _colors.onSurface)); + + @override + MaterialStateProperty<TextStyle?> get hintStyle => + MaterialStatePropertyAll<TextStyle?>(_textTheme.bodyLarge?.copyWith(color: _colors.onSurfaceVariant)); + + @override + BoxConstraints get constraints => + const BoxConstraints(minWidth: 360.0, maxWidth: 800.0, minHeight: 56.0); + + @override + TextCapitalization get textCapitalization => TextCapitalization.none; +} + +// END GENERATED TOKEN PROPERTIES - SearchBar + +// BEGIN GENERATED TOKEN PROPERTIES - SearchView + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _SearchViewDefaultsM3 extends SearchViewThemeData { + _SearchViewDefaultsM3(this.context, {required this.isFullScreen}); + + final BuildContext context; + final bool isFullScreen; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + static double fullScreenBarHeight = 72.0; + + @override + Color? get backgroundColor => _colors.surface; + + @override + double? get elevation => 6.0; + + @override + Color? get surfaceTintColor => _colors.surfaceTint; + + // No default side + + @override + OutlinedBorder? get shape => isFullScreen + ? const RoundedRectangleBorder() + : const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0))); + + @override + TextStyle? get headerTextStyle => _textTheme.bodyLarge?.copyWith(color: _colors.onSurface); + + @override + TextStyle? get headerHintStyle => _textTheme.bodyLarge?.copyWith(color: _colors.onSurfaceVariant); + + @override + BoxConstraints get constraints => const BoxConstraints(minWidth: 360.0, minHeight: 240.0); + + @override + Color? get dividerColor => _colors.outline; +} + +// END GENERATED TOKEN PROPERTIES - SearchView diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search_bar_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search_bar_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..3599a4130d53754ac23f439a1894c69f15961614 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search_bar_theme.dart @@ -0,0 +1,273 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [SearchBar] widgets. +/// +/// Descendant widgets obtain the current [SearchBarThemeData] object using +/// `SearchBarTheme.of(context)`. Instances of [SearchBarThemeData] can be customized +/// with [SearchBarThemeData.copyWith]. +/// +/// Typically a [SearchBarThemeData] is specified as part of the overall [Theme] +/// with [ThemeData.searchBarTheme]. +/// +/// All [SearchBarThemeData] properties are `null` by default. When null, the +/// [SearchBar] will use the values from [ThemeData] if they exist, otherwise it +/// will provide its own defaults based on the overall [Theme]'s colorScheme. +/// See the individual [SearchBar] properties for details. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class SearchBarThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.searchBarTheme]. + const SearchBarThemeData({ + this.elevation, + this.backgroundColor, + this.shadowColor, + this.surfaceTintColor, + this.overlayColor, + this.side, + this.shape, + this.padding, + this.textStyle, + this.hintStyle, + this.constraints, + this.textCapitalization, + }); + + /// Overrides the default value of the [SearchBar.elevation]. + final MaterialStateProperty<double?>? elevation; + + /// Overrides the default value of the [SearchBar.backgroundColor]. + final MaterialStateProperty<Color?>? backgroundColor; + + /// Overrides the default value of the [SearchBar.shadowColor]. + final MaterialStateProperty<Color?>? shadowColor; + + /// Overrides the default value of the [SearchBar.surfaceTintColor]. + final MaterialStateProperty<Color?>? surfaceTintColor; + + /// Overrides the default value of the [SearchBar.overlayColor]. + final MaterialStateProperty<Color?>? overlayColor; + + /// Overrides the default value of the [SearchBar.side]. + final MaterialStateProperty<BorderSide?>? side; + + /// Overrides the default value of the [SearchBar.shape]. + final MaterialStateProperty<OutlinedBorder?>? shape; + + /// Overrides the default value for [SearchBar.padding]. + final MaterialStateProperty<EdgeInsetsGeometry?>? padding; + + /// Overrides the default value for [SearchBar.textStyle]. + final MaterialStateProperty<TextStyle?>? textStyle; + + /// Overrides the default value for [SearchBar.hintStyle]. + final MaterialStateProperty<TextStyle?>? hintStyle; + + /// Overrides the value of size constraints for [SearchBar]. + final BoxConstraints? constraints; + + /// Overrides the value of [SearchBar.textCapitalization]. + final TextCapitalization? textCapitalization; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + SearchBarThemeData copyWith({ + MaterialStateProperty<double?>? elevation, + MaterialStateProperty<Color?>? backgroundColor, + MaterialStateProperty<Color?>? shadowColor, + MaterialStateProperty<Color?>? surfaceTintColor, + MaterialStateProperty<Color?>? overlayColor, + MaterialStateProperty<BorderSide?>? side, + MaterialStateProperty<OutlinedBorder?>? shape, + MaterialStateProperty<EdgeInsetsGeometry?>? padding, + MaterialStateProperty<TextStyle?>? textStyle, + MaterialStateProperty<TextStyle?>? hintStyle, + BoxConstraints? constraints, + TextCapitalization? textCapitalization, + }) { + return SearchBarThemeData( + elevation: elevation ?? this.elevation, + backgroundColor: backgroundColor ?? this.backgroundColor, + shadowColor: shadowColor ?? this.shadowColor, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + overlayColor: overlayColor ?? this.overlayColor, + side: side ?? this.side, + shape: shape ?? this.shape, + padding: padding ?? this.padding, + textStyle: textStyle ?? this.textStyle, + hintStyle: hintStyle ?? this.hintStyle, + constraints: constraints ?? this.constraints, + textCapitalization: textCapitalization ?? this.textCapitalization, + ); + } + + /// Linearly interpolate between two [SearchBarThemeData]s. + /// + /// {@macro dart.ui.shadow.lerp} + static SearchBarThemeData? lerp(SearchBarThemeData? a, SearchBarThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return SearchBarThemeData( + elevation: MaterialStateProperty.lerp<double?>(a?.elevation, b?.elevation, t, lerpDouble), + backgroundColor: MaterialStateProperty.lerp<Color?>(a?.backgroundColor, b?.backgroundColor, t, Color.lerp), + shadowColor: MaterialStateProperty.lerp<Color?>(a?.shadowColor, b?.shadowColor, t, Color.lerp), + surfaceTintColor: MaterialStateProperty.lerp<Color?>(a?.surfaceTintColor, b?.surfaceTintColor, t, Color.lerp), + overlayColor: MaterialStateProperty.lerp<Color?>(a?.overlayColor, b?.overlayColor, t, Color.lerp), + side: _lerpSides(a?.side, b?.side, t), + shape: MaterialStateProperty.lerp<OutlinedBorder?>(a?.shape, b?.shape, t, OutlinedBorder.lerp), + padding: MaterialStateProperty.lerp<EdgeInsetsGeometry?>(a?.padding, b?.padding, t, EdgeInsetsGeometry.lerp), + textStyle: MaterialStateProperty.lerp<TextStyle?>(a?.textStyle, b?.textStyle, t, TextStyle.lerp), + hintStyle: MaterialStateProperty.lerp<TextStyle?>(a?.hintStyle, b?.hintStyle, t, TextStyle.lerp), + constraints: BoxConstraints.lerp(a?.constraints, b?.constraints, t), + textCapitalization: t < 0.5 ? a?.textCapitalization : b?.textCapitalization, + ); + } + + @override + int get hashCode => Object.hash( + elevation, + backgroundColor, + shadowColor, + surfaceTintColor, + overlayColor, + side, + shape, + padding, + textStyle, + hintStyle, + constraints, + textCapitalization, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is SearchBarThemeData + && other.elevation == elevation + && other.backgroundColor == backgroundColor + && other.shadowColor == shadowColor + && other.surfaceTintColor == surfaceTintColor + && other.overlayColor == overlayColor + && other.side == side + && other.shape == shape + && other.padding == padding + && other.textStyle == textStyle + && other.hintStyle == hintStyle + && other.constraints == constraints + && other.textCapitalization == textCapitalization; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('elevation', elevation, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('shadowColor', shadowColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('overlayColor', overlayColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<BorderSide?>>('side', side, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<OutlinedBorder?>>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<EdgeInsetsGeometry?>>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<TextStyle?>>('textStyle', textStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<TextStyle?>>('hintStyle', hintStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<BoxConstraints>('constraints', constraints, defaultValue: null)); + properties.add(DiagnosticsProperty<TextCapitalization>('textCapitalization', textCapitalization, defaultValue: null)); + } + + // Special case because BorderSide.lerp() doesn't support null arguments + static MaterialStateProperty<BorderSide?>? _lerpSides(MaterialStateProperty<BorderSide?>? a, MaterialStateProperty<BorderSide?>? b, double t) { + if (identical(a, b)) { + return a; + } + return _LerpSides(a, b, t); + } +} + +class _LerpSides implements MaterialStateProperty<BorderSide?> { + const _LerpSides(this.a, this.b, this.t); + + final MaterialStateProperty<BorderSide?>? a; + final MaterialStateProperty<BorderSide?>? b; + final double t; + + @override + BorderSide? resolve(Set<MaterialState> states) { + final BorderSide? resolvedA = a?.resolve(states); + final BorderSide? resolvedB = b?.resolve(states); + if (identical(resolvedA, resolvedB)) { + return resolvedA; + } + if (resolvedA == null) { + return BorderSide.lerp(BorderSide(width: 0, color: resolvedB!.color.withAlpha(0)), resolvedB, t); + } + if (resolvedB == null) { + return BorderSide.lerp(resolvedA, BorderSide(width: 0, color: resolvedA.color.withAlpha(0)), t); + } + return BorderSide.lerp(resolvedA, resolvedB, t); + } +} + +/// Applies a search bar theme to descendant [SearchBar] widgets. +/// +/// Descendant widgets obtain the current theme's [SearchBarTheme] object using +/// [SearchBarTheme.of]. When a widget uses [SearchBarTheme.of], it is automatically +/// rebuilt if the theme later changes. +/// +/// A search bar theme can be specified as part of the overall Material theme using +/// [ThemeData.searchBarTheme]. +/// +/// See also: +/// +/// * [SearchBarThemeData], which describes the actual configuration of a search bar +/// theme. +class SearchBarTheme extends InheritedWidget { + /// Constructs a search bar theme that configures all descendant [SearchBar] widgets. + const SearchBarTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties used for all descendant [SearchBar] widgets. + final SearchBarThemeData data; + + /// Returns the configuration [data] from the closest [SearchBarTheme] ancestor. + /// If there is no ancestor, it returns [ThemeData.searchBarTheme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// SearchBarThemeData theme = SearchBarTheme.of(context); + /// ``` + static SearchBarThemeData of(BuildContext context) { + final SearchBarTheme? searchBarTheme = context.dependOnInheritedWidgetOfExactType<SearchBarTheme>(); + return searchBarTheme?.data ?? Theme.of(context).searchBarTheme; + } + + @override + bool updateShouldNotify(SearchBarTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search_view_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search_view_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..db583be66c5d3bfbfcd06a6907c8a9085ea274fe --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/search_view_theme.dart @@ -0,0 +1,222 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines the configuration of the search views created by the [SearchAnchor] +/// widget. +/// +/// Descendant widgets obtain the current [SearchViewThemeData] object using +/// `SearchViewTheme.of(context)`. +/// +/// Typically, a [SearchViewThemeData] is specified as part of the overall [Theme] +/// with [ThemeData.searchViewTheme]. Otherwise, [SearchViewTheme] can be used +/// to configure its own widget subtree. +/// +/// All [SearchViewThemeData] properties are `null` by default. If any of these +/// properties are null, the search view will provide its own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme for the application. +/// * [SearchBarThemeData], which describes the theme for the search bar itself in a +/// [SearchBar] widget. +/// * [SearchAnchor], which is used to open a search view route. +@immutable +class SearchViewThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.searchViewTheme]. + const SearchViewThemeData({ + this.backgroundColor, + this.elevation, + this.surfaceTintColor, + this.constraints, + this.side, + this.shape, + this.headerTextStyle, + this.headerHintStyle, + this.dividerColor, + }); + + /// Overrides the default value of the [SearchAnchor.viewBackgroundColor]. + final Color? backgroundColor; + + /// Overrides the default value of the [SearchAnchor.viewElevation]. + final double? elevation; + + /// Overrides the default value of the [SearchAnchor.viewSurfaceTintColor]. + final Color? surfaceTintColor; + + /// Overrides the default value of the [SearchAnchor.viewSide]. + final BorderSide? side; + + /// Overrides the default value of the [SearchAnchor.viewShape]. + final OutlinedBorder? shape; + + /// Overrides the default value for [SearchAnchor.headerTextStyle]. + final TextStyle? headerTextStyle; + + /// Overrides the default value for [SearchAnchor.headerHintStyle]. + final TextStyle? headerHintStyle; + + /// Overrides the value of size constraints for [SearchAnchor.viewConstraints]. + final BoxConstraints? constraints; + + /// Overrides the value of the divider color for [SearchAnchor.dividerColor]. + final Color? dividerColor; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + SearchViewThemeData copyWith({ + Color? backgroundColor, + double? elevation, + Color? surfaceTintColor, + BorderSide? side, + OutlinedBorder? shape, + TextStyle? headerTextStyle, + TextStyle? headerHintStyle, + BoxConstraints? constraints, + Color? dividerColor, + }) { + return SearchViewThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + elevation: elevation ?? this.elevation, + surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor, + side: side ?? this.side, + shape: shape ?? this.shape, + headerTextStyle: headerTextStyle ?? this.headerTextStyle, + headerHintStyle: headerHintStyle ?? this.headerHintStyle, + constraints: constraints ?? this.constraints, + dividerColor: dividerColor ?? this.dividerColor, + ); + } + + /// Linearly interpolate between two [SearchViewThemeData]s. + static SearchViewThemeData? lerp(SearchViewThemeData? a, SearchViewThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return SearchViewThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t), + side: _lerpSides(a?.side, b?.side, t), + shape: OutlinedBorder.lerp(a?.shape, b?.shape, t), + headerTextStyle: TextStyle.lerp(a?.headerTextStyle, b?.headerTextStyle, t), + headerHintStyle: TextStyle.lerp(a?.headerTextStyle, b?.headerTextStyle, t), + constraints: BoxConstraints.lerp(a?.constraints, b?.constraints, t), + dividerColor: Color.lerp(a?.dividerColor, b?.dividerColor, t), + ); + } + + @override + int get hashCode => Object.hash( + backgroundColor, + elevation, + surfaceTintColor, + side, + shape, + headerTextStyle, + headerHintStyle, + constraints, + dividerColor, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is SearchViewThemeData + && other.backgroundColor == backgroundColor + && other.elevation == elevation + && other.surfaceTintColor == surfaceTintColor + && other.side == side + && other.shape == shape + && other.headerTextStyle == headerTextStyle + && other.headerHintStyle == headerHintStyle + && other.constraints == constraints + && other.dividerColor == dividerColor; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Color?>('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<double?>('elevation', elevation, defaultValue: null)); + properties.add(DiagnosticsProperty<Color?>('surfaceTintColor', surfaceTintColor, defaultValue: null)); + properties.add(DiagnosticsProperty<BorderSide?>('side', side, defaultValue: null)); + properties.add(DiagnosticsProperty<OutlinedBorder?>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle?>('headerTextStyle', headerTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle?>('headerHintStyle', headerHintStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<BoxConstraints>('constraints', constraints, defaultValue: null)); + properties.add(DiagnosticsProperty<Color?>('dividerColor', dividerColor, defaultValue: null)); + } + + // Special case because BorderSide.lerp() doesn't support null arguments + static BorderSide? _lerpSides(BorderSide? a, BorderSide? b, double t) { + if (a == null || b == null) { + return null; + } + if (identical(a, b)) { + return a; + } + return BorderSide.lerp(a, b, t); + } +} + +/// An inherited widget that defines the configuration in this widget's +/// descendants for search view created by the [SearchAnchor] widget. +/// +/// A search view theme can be specified as part of the overall Material theme using +/// [ThemeData.searchViewTheme]. +/// +/// See also: +/// +/// * [SearchViewThemeData], which describes the actual configuration of a search view +/// theme. +class SearchViewTheme extends InheritedTheme { + /// Creates a const theme that controls the configurations for the search view + /// created by the [SearchAnchor] widget. + const SearchViewTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties used for all descendant [SearchAnchor] widgets. + final SearchViewThemeData data; + + /// Returns the configuration [data] from the closest [SearchViewTheme] ancestor. + /// If there is no ancestor, it returns [ThemeData.searchViewTheme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// SearchViewThemeData theme = SearchViewTheme.of(context); + /// ``` + static SearchViewThemeData of(BuildContext context) { + final SearchViewTheme? searchViewTheme = context.dependOnInheritedWidgetOfExactType<SearchViewTheme>(); + return searchViewTheme?.data ?? Theme.of(context).searchViewTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return SearchViewTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(SearchViewTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/segmented_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/segmented_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..a4eeb6f132077cd9a8aa2fdde28b9a9827feb675 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/segmented_button.dart @@ -0,0 +1,1019 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; +import 'button_style.dart'; +import 'button_style_button.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'segmented_button_theme.dart'; +import 'text_button.dart'; +import 'text_button_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; +import 'tooltip.dart'; + +/// Data describing a segment of a [SegmentedButton]. +class ButtonSegment<T> { + /// Construct a [ButtonSegment]. + /// + /// One of [icon] or [label] must be non-null. + const ButtonSegment({ + required this.value, + this.icon, + this.label, + this.tooltip, + this.enabled = true, + }) : assert(icon != null || label != null); + + /// Value used to identify the segment. + /// + /// This value must be unique across all segments in a [SegmentedButton]. + final T value; + + /// Optional icon displayed in the segment. + final Widget? icon; + + /// Optional label displayed in the segment. + final Widget? label; + + /// Optional tooltip for the segment + final String? tooltip; + + /// Determines if the segment is available for selection. + final bool enabled; +} + +/// A Material button that allows the user to select from limited set of options. +/// +/// Segmented buttons are used to help people select options, switch views, or +/// sort elements. They are typically used in cases where there are only 2-5 +/// options. +/// +/// The options are represented by segments described with [ButtonSegment] +/// entries in the [segments] field. Each segment has a [ButtonSegment.value] +/// that is used to indicate which segments are selected. +/// +/// The [selected] field is a set of selected [ButtonSegment.value]s. This +/// should be updated by the app in response to [onSelectionChanged] updates. +/// +/// By default, only a single segment can be selected (for mutually exclusive +/// choices). This can be relaxed with the [multiSelectionEnabled] field. +/// +/// Like [ButtonStyleButton]s, the [SegmentedButton]'s visuals can be +/// configured with a [ButtonStyle] [style] field. However, unlike other +/// buttons, some of the style parameters are applied to the entire segmented +/// button, and others are used for each of the segments. +/// +/// By default, a checkmark icon is used to show selected items. To configure +/// this behavior, you can use the [showSelectedIcon] and [selectedIcon] fields. +/// +/// Individual segments can be enabled or disabled with their +/// [ButtonSegment.enabled] flag. If the [onSelectionChanged] field is null, +/// then the entire segmented button will be disabled, regardless of the +/// individual segment settings. +/// +/// {@tool dartpad} +/// This sample shows how to display a [SegmentedButton] with either a single or +/// multiple selection. +/// +/// ** See code in examples/api/lib/material/segmented_button/segmented_button.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample showcases how to customize [SegmentedButton] using [SegmentedButton.styleFrom]. +/// +/// ** See code in examples/api/lib/material/segmented_button/segmented_button.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * Material Design spec: <https://m3.material.io/components/segmented-buttons/overview> +/// * [ButtonStyle], which can be used in the [style] field to configure +/// the appearance of the button and its segments. +/// * [ToggleButtons], a similar widget that was built for Material 2. +/// [SegmentedButton] should be considered as a replacement for +/// [ToggleButtons]. +/// * [Radio], an alternative way to present the user with a mutually exclusive set of options. +/// * [FilterChip], [ChoiceChip], which can be used when you need to show more than five options. +class SegmentedButton<T> extends StatefulWidget { + /// Creates a const [SegmentedButton]. + /// + /// [segments] must contain at least one segment, but it is recommended + /// to have two to five segments. If you need only single segment, + /// consider using a [Checkbox] or [Radio] widget instead. If you need + /// more than five options, consider using [FilterChip] or [ChoiceChip] + /// widgets. + /// + /// If [onSelectionChanged] is null, then the entire segmented button will + /// be disabled. + /// + /// By default [selected] must only contain one entry. However, if + /// [multiSelectionEnabled] is true, then [selected] can contain multiple + /// entries. If [emptySelectionAllowed] is true, then [selected] can be empty. + const SegmentedButton({ + super.key, + required this.segments, + required this.selected, + this.onSelectionChanged, + this.multiSelectionEnabled = false, + this.emptySelectionAllowed = false, + this.style, + this.showSelectedIcon = true, + this.selectedIcon, + }) : assert(segments.length > 0), + assert(selected.length > 0 || emptySelectionAllowed), + assert(selected.length < 2 || multiSelectionEnabled); + + /// Descriptions of the segments in the button. + /// + /// This a required parameter and must contain at least one segment, + /// but it is recommended to contain two to five segments. If you need only + /// a single segment, consider using a [Checkbox] or [Radio] widget instead. + /// If you need more than five options, consider using [FilterChip] or + /// [ChoiceChip] widgets. + final List<ButtonSegment<T>> segments; + + /// The set of [ButtonSegment.value]s that indicate which [segments] are + /// selected. + /// + /// As the [SegmentedButton] does not maintain the state of the selection, + /// you will need to update this in response to [onSelectionChanged] calls. + /// + /// This is a required parameter. + final Set<T> selected; + + /// The function that is called when the selection changes. + /// + /// The callback's parameter indicates which of the segments are selected. + /// + /// When the callback is null, the entire [SegmentedButton] is disabled, + /// and will not respond to input. + /// + /// The default is null. + final void Function(Set<T>)? onSelectionChanged; + + /// Determines if multiple segments can be selected at one time. + /// + /// If true, more than one segment can be selected. When selecting a + /// segment, the other selected segments will stay selected. Selecting an + /// already selected segment will unselect it. + /// + /// If false, only one segment may be selected at a time. When a segment + /// is selected, any previously selected segment will be unselected. + /// + /// The default is false, so only a single segement may be selected at one + /// time. + final bool multiSelectionEnabled; + + /// Determines if having no selected segments is allowed. + /// + /// If true, then it is acceptable for none of the segments to be selected. + /// This means that [selected] can be empty. If the user taps on a + /// selected segment, it will be removed from the selection set passed into + /// [onSelectionChanged]. + /// + /// If false (the default), there must be at least one segment selected. If + /// the user taps on the only selected segment it will not be deselected, and + /// [onSelectionChanged] will not be called. + final bool emptySelectionAllowed; + + /// A static convenience method that constructs a segmented button + /// [ButtonStyle] given simple values. + /// + /// The [foregroundColor], [selectedForegroundColor], and [disabledForegroundColor] + /// colors are used to create a [MaterialStateProperty] [ButtonStyle.foregroundColor], + /// and a derived [ButtonStyle.overlayColor]. + /// + /// The [backgroundColor], [selectedBackgroundColor] and [disabledBackgroundColor] + /// colors are used to create a [MaterialStateProperty] [ButtonStyle.backgroundColor]. + /// + /// Similarly, the [enabledMouseCursor] and [disabledMouseCursor] + /// parameters are used to construct [ButtonStyle.mouseCursor]. + /// + /// All of the other parameters are either used directly or used to + /// create a [MaterialStateProperty] with a single value for all + /// states. + /// + /// All parameters default to null. By default this method returns + /// a [ButtonStyle] that doesn't override anything. + /// + /// {@tool snippet} + /// + /// For example, to override the default text and icon colors for a + /// [SegmentedButton], as well as its overlay color, with all of the + /// standard opacity adjustments for the pressed, focused, and + /// hovered states, one could write: + /// + /// ** See code in examples/api/lib/material/segmented_button/segmented_button.1.dart ** + /// + /// ```dart + /// SegmentedButton<int>( + /// style: SegmentedButton.styleFrom( + /// foregroundColor: Colors.black, + /// selectedForegroundColor: Colors.white, + /// backgroundColor: Colors.amber, + /// selectedBackgroundColor: Colors.red, + /// ), + /// segments: const <ButtonSegment<int>>[ + /// ButtonSegment<int>( + /// value: 0, + /// label: Text('0'), + /// icon: Icon(Icons.calendar_view_day), + /// ), + /// ButtonSegment<int>( + /// value: 1, + /// label: Text('1'), + /// icon: Icon(Icons.calendar_view_week), + /// ), + /// ], + /// selected: const <int>{0}, + /// onSelectionChanged: (Set<int> selection) {}, + /// ), + /// ``` + /// {@end-tool} + static ButtonStyle styleFrom({ + Color? foregroundColor, + Color? backgroundColor, + Color? selectedForegroundColor, + Color? selectedBackgroundColor, + Color? disabledForegroundColor, + Color? disabledBackgroundColor, + Color? shadowColor, + Color? surfaceTintColor, + double? elevation, + TextStyle? textStyle, + EdgeInsetsGeometry? padding, + Size? minimumSize, + Size? fixedSize, + Size? maximumSize, + BorderSide? side, + OutlinedBorder? shape, + MouseCursor? enabledMouseCursor, + MouseCursor? disabledMouseCursor, + VisualDensity? visualDensity, + MaterialTapTargetSize? tapTargetSize, + Duration? animationDuration, + bool? enableFeedback, + AlignmentGeometry? alignment, + InteractiveInkFeatureFactory? splashFactory, + }) { + final MaterialStateProperty<Color?>? foregroundColorProp = + (foregroundColor == null && disabledForegroundColor == null && selectedForegroundColor == null) + ? null + : _SegmentButtonDefaultColor(foregroundColor, disabledForegroundColor, selectedForegroundColor); + final MaterialStateProperty<Color?>? backgroundColorProp = + (backgroundColor == null && disabledBackgroundColor == null && selectedBackgroundColor == null) + ? null + : _SegmentButtonDefaultColor(backgroundColor, disabledBackgroundColor, selectedBackgroundColor); + final MaterialStateProperty<Color?>? overlayColor = (foregroundColor == null && selectedForegroundColor == null) + ? null + : _SegmentedButtonDefaultsM3.resolveStateColor(foregroundColor, selectedForegroundColor); + return TextButton.styleFrom( + textStyle: textStyle, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + elevation: elevation, + padding: padding, + minimumSize: minimumSize, + fixedSize: fixedSize, + maximumSize: maximumSize, + side: side, + shape: shape, + enabledMouseCursor: enabledMouseCursor, + disabledMouseCursor: disabledMouseCursor, + visualDensity: visualDensity, + tapTargetSize: tapTargetSize, + animationDuration: animationDuration, + enableFeedback: enableFeedback, + alignment: alignment, + splashFactory: splashFactory, + ).copyWith( + foregroundColor: foregroundColorProp, + backgroundColor: backgroundColorProp, + overlayColor: overlayColor, + ); + } + + /// Customizes this button's appearance. + /// + /// The following style properties apply to the entire segmented button: + /// + /// * [ButtonStyle.shadowColor] + /// * [ButtonStyle.elevation] + /// * [ButtonStyle.side] - which is used for both the outer shape and + /// dividers between segments. + /// * [ButtonStyle.shape] + /// + /// The following style properties are applied to each of the individual + /// button segments. For properties that are a [MaterialStateProperty], + /// they will be resolved with the current state of the segment: + /// + /// * [ButtonStyle.textStyle] + /// * [ButtonStyle.backgroundColor] + /// * [ButtonStyle.foregroundColor] + /// * [ButtonStyle.overlayColor] + /// * [ButtonStyle.surfaceTintColor] + /// * [ButtonStyle.elevation] + /// * [ButtonStyle.padding] + /// * [ButtonStyle.iconColor] + /// * [ButtonStyle.iconSize] + /// * [ButtonStyle.mouseCursor] + /// * [ButtonStyle.visualDensity] + /// * [ButtonStyle.tapTargetSize] + /// * [ButtonStyle.animationDuration] + /// * [ButtonStyle.enableFeedback] + /// * [ButtonStyle.alignment] + /// * [ButtonStyle.splashFactory] + final ButtonStyle? style; + + /// Determines if the [selectedIcon] (usually an icon using [Icons.check]) + /// is displayed on the selected segments. + /// + /// If true, the [selectedIcon] will be displayed at the start of the segment. + /// If both the [ButtonSegment.label] and [ButtonSegment.icon] are provided, + /// then the icon will be replaced with the [selectedIcon]. If only the icon + /// or the label is present then the [selectedIcon] will be shown at the start + /// of the segment. + /// + /// If false, then the [selectedIcon] is not used and will not be displayed + /// on selected segments. + /// + /// The default is true, meaning the [selectedIcon] will be shown on selected + /// segments. + final bool showSelectedIcon; + + /// An icon that is used to indicate a segment is selected. + /// + /// If [showSelectedIcon] is true then for selected segments this icon + /// will be shown before the [ButtonSegment.label], replacing the + /// [ButtonSegment.icon] if it is specified. + /// + /// Defaults to an [Icon] with [Icons.check]. + final Widget? selectedIcon; + + @override + State<SegmentedButton<T>> createState() => SegmentedButtonState<T>(); +} + +/// State for [SegmentedButton]. +@visibleForTesting +class SegmentedButtonState<T> extends State<SegmentedButton<T>> { + bool get _enabled => widget.onSelectionChanged != null; + + /// Controllers for the [ButtonSegment]s. + @visibleForTesting + final Map<ButtonSegment<T>, MaterialStatesController> statesControllers = <ButtonSegment<T>, MaterialStatesController>{}; + + @override + void didUpdateWidget(covariant SegmentedButton<T> oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget != widget) { + statesControllers.removeWhere((ButtonSegment<T> segment, MaterialStatesController controller) { + if (widget.segments.contains(segment)) { + return false; + } else { + controller.dispose(); + return true; + } + }); + } + } + + void _handleOnPressed(T segmentValue) { + if (!_enabled) { + return; + } + final bool onlySelectedSegment = widget.selected.length == 1 && widget.selected.contains(segmentValue); + final bool validChange = widget.emptySelectionAllowed || !onlySelectedSegment; + if (validChange) { + final bool toggle = widget.multiSelectionEnabled || (widget.emptySelectionAllowed && onlySelectedSegment); + final Set<T> pressedSegment = <T>{segmentValue}; + late final Set<T> updatedSelection; + if (toggle) { + updatedSelection = widget.selected.contains(segmentValue) + ? widget.selected.difference(pressedSegment) + : widget.selected.union(pressedSegment); + } else { + updatedSelection = pressedSegment; + } + if (!setEquals(updatedSelection, widget.selected)) { + widget.onSelectionChanged!(updatedSelection); + } + } + } + + @override + Widget build(BuildContext context) { + final SegmentedButtonThemeData theme = SegmentedButtonTheme.of(context); + final SegmentedButtonThemeData defaults = _SegmentedButtonDefaultsM3(context); + final TextDirection direction = Directionality.of(context); + + const Set<MaterialState> enabledState = <MaterialState>{}; + const Set<MaterialState> disabledState = <MaterialState>{ MaterialState.disabled }; + final Set<MaterialState> currentState = _enabled ? enabledState : disabledState; + + P? effectiveValue<P>(P? Function(ButtonStyle? style) getProperty) { + late final P? widgetValue = getProperty(widget.style); + late final P? themeValue = getProperty(theme.style); + late final P? defaultValue = getProperty(defaults.style); + return widgetValue ?? themeValue ?? defaultValue; + } + + P? resolve<P>(MaterialStateProperty<P>? Function(ButtonStyle? style) getProperty, [Set<MaterialState>? states]) { + return effectiveValue( + (ButtonStyle? style) => getProperty(style)?.resolve(states ?? currentState), + ); + } + + ButtonStyle segmentStyleFor(ButtonStyle? style) { + return ButtonStyle( + textStyle: style?.textStyle, + backgroundColor: style?.backgroundColor, + foregroundColor: style?.foregroundColor, + overlayColor: style?.overlayColor, + surfaceTintColor: style?.surfaceTintColor, + elevation: style?.elevation, + padding: style?.padding, + iconColor: style?.iconColor, + iconSize: style?.iconSize, + shape: const MaterialStatePropertyAll<OutlinedBorder>(RoundedRectangleBorder()), + mouseCursor: style?.mouseCursor, + visualDensity: style?.visualDensity, + tapTargetSize: style?.tapTargetSize, + animationDuration: style?.animationDuration, + enableFeedback: style?.enableFeedback, + alignment: style?.alignment, + splashFactory: style?.splashFactory, + ); + } + + final ButtonStyle segmentStyle = segmentStyleFor(widget.style); + final ButtonStyle segmentThemeStyle = segmentStyleFor(theme.style).merge(segmentStyleFor(defaults.style)); + final Widget? selectedIcon = widget.showSelectedIcon + ? widget.selectedIcon ?? theme.selectedIcon ?? defaults.selectedIcon + : null; + + Widget buttonFor(ButtonSegment<T> segment) { + final Widget label = segment.label ?? segment.icon ?? const SizedBox.shrink(); + final bool segmentSelected = widget.selected.contains(segment.value); + final Widget? icon = (segmentSelected && widget.showSelectedIcon) + ? selectedIcon + : segment.label != null + ? segment.icon + : null; + final MaterialStatesController controller = statesControllers.putIfAbsent(segment, () => MaterialStatesController()); + controller.update(MaterialState.selected, segmentSelected); + + final Widget button = icon != null + ? TextButton.icon( + style: segmentStyle, + statesController: controller, + onPressed: (_enabled && segment.enabled) ? () => _handleOnPressed(segment.value) : null, + icon: icon, + label: label, + ) + : TextButton( + style: segmentStyle, + statesController: controller, + onPressed: (_enabled && segment.enabled) ? () => _handleOnPressed(segment.value) : null, + child: label, + ); + + final Widget buttonWithTooltip = segment.tooltip != null + ? Tooltip( + message: segment.tooltip, + child: button, + ) + : button; + + return MergeSemantics( + child: Semantics( + checked: segmentSelected, + inMutuallyExclusiveGroup: widget.multiSelectionEnabled ? null : true, + child: buttonWithTooltip, + ), + ); + } + + final OutlinedBorder resolvedEnabledBorder = resolve<OutlinedBorder?>((ButtonStyle? style) => style?.shape, disabledState) ?? const RoundedRectangleBorder(); + final OutlinedBorder resolvedDisabledBorder = resolve<OutlinedBorder?>((ButtonStyle? style) => style?.shape, disabledState)?? const RoundedRectangleBorder(); + final BorderSide enabledSide = resolve<BorderSide?>((ButtonStyle? style) => style?.side, enabledState) ?? BorderSide.none; + final BorderSide disabledSide = resolve<BorderSide?>((ButtonStyle? style) => style?.side, disabledState) ?? BorderSide.none; + final OutlinedBorder enabledBorder = resolvedEnabledBorder.copyWith(side: enabledSide); + final OutlinedBorder disabledBorder = resolvedDisabledBorder.copyWith(side: disabledSide); + + final List<Widget> buttons = widget.segments.map(buttonFor).toList(); + + return Material( + type: MaterialType.transparency, + shape: enabledBorder.copyWith(side: BorderSide.none), + elevation: resolve<double?>((ButtonStyle? style) => style?.elevation)!, + shadowColor: resolve<Color?>((ButtonStyle? style) => style?.shadowColor), + surfaceTintColor: resolve<Color?>((ButtonStyle? style) => style?.surfaceTintColor), + child: TextButtonTheme( + data: TextButtonThemeData(style: segmentThemeStyle), + child: _SegmentedButtonRenderWidget<T>( + segments: widget.segments, + enabledBorder: _enabled ? enabledBorder : disabledBorder, + disabledBorder: disabledBorder, + direction: direction, + children: buttons, + ), + ), + ); + } + + @override + void dispose() { + for (final MaterialStatesController controller in statesControllers.values) { + controller.dispose(); + } + super.dispose(); + } +} + +@immutable +class _SegmentButtonDefaultColor extends MaterialStateProperty<Color?> with Diagnosticable { + _SegmentButtonDefaultColor(this.color, this.disabled, this.selected); + + final Color? color; + final Color? disabled; + final Color? selected; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabled; + } + if (states.contains(MaterialState.selected)) { + return selected; + } + return color; + } +} + +class _SegmentedButtonRenderWidget<T> extends MultiChildRenderObjectWidget { + const _SegmentedButtonRenderWidget({ + super.key, + required this.segments, + required this.enabledBorder, + required this.disabledBorder, + required this.direction, + required super.children, + }) : assert(children.length == segments.length); + + final List<ButtonSegment<T>> segments; + final OutlinedBorder enabledBorder; + final OutlinedBorder disabledBorder; + final TextDirection direction; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderSegmentedButton<T>( + segments: segments, + enabledBorder: enabledBorder, + disabledBorder: disabledBorder, + textDirection: direction, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderSegmentedButton<T> renderObject) { + renderObject + ..segments = segments + ..enabledBorder = enabledBorder + ..disabledBorder = disabledBorder + ..textDirection = direction; + } +} + +class _SegmentedButtonContainerBoxParentData extends ContainerBoxParentData<RenderBox> { + RRect? surroundingRect; +} + +typedef _NextChild = RenderBox? Function(RenderBox child); + +class _RenderSegmentedButton<T> extends RenderBox with + ContainerRenderObjectMixin<RenderBox, ContainerBoxParentData<RenderBox>>, + RenderBoxContainerDefaultsMixin<RenderBox, ContainerBoxParentData<RenderBox>> { + _RenderSegmentedButton({ + required List<ButtonSegment<T>> segments, + required OutlinedBorder enabledBorder, + required OutlinedBorder disabledBorder, + required TextDirection textDirection, + }) : _segments = segments, + _enabledBorder = enabledBorder, + _disabledBorder = disabledBorder, + _textDirection = textDirection; + + List<ButtonSegment<T>> get segments => _segments; + List<ButtonSegment<T>> _segments; + set segments(List<ButtonSegment<T>> value) { + if (listEquals(segments, value)) { + return; + } + _segments = value; + markNeedsLayout(); + } + + OutlinedBorder get enabledBorder => _enabledBorder; + OutlinedBorder _enabledBorder; + set enabledBorder(OutlinedBorder value) { + if (_enabledBorder == value) { + return; + } + _enabledBorder = value; + markNeedsLayout(); + } + + OutlinedBorder get disabledBorder => _disabledBorder; + OutlinedBorder _disabledBorder; + set disabledBorder(OutlinedBorder value) { + if (_disabledBorder == value) { + return; + } + _disabledBorder = value; + markNeedsLayout(); + } + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (value == _textDirection) { + return; + } + _textDirection = value; + markNeedsLayout(); + } + + @override + double computeMinIntrinsicWidth(double height) { + RenderBox? child = firstChild; + double minWidth = 0.0; + while (child != null) { + final _SegmentedButtonContainerBoxParentData childParentData = child.parentData! as _SegmentedButtonContainerBoxParentData; + final double childWidth = child.getMinIntrinsicWidth(height); + minWidth = math.max(minWidth, childWidth); + child = childParentData.nextSibling; + } + return minWidth * childCount; + } + + @override + double computeMaxIntrinsicWidth(double height) { + RenderBox? child = firstChild; + double maxWidth = 0.0; + while (child != null) { + final _SegmentedButtonContainerBoxParentData childParentData = child.parentData! as _SegmentedButtonContainerBoxParentData; + final double childWidth = child.getMaxIntrinsicWidth(height); + maxWidth = math.max(maxWidth, childWidth); + child = childParentData.nextSibling; + } + return maxWidth * childCount; + } + + @override + double computeMinIntrinsicHeight(double width) { + RenderBox? child = firstChild; + double minHeight = 0.0; + while (child != null) { + final _SegmentedButtonContainerBoxParentData childParentData = child.parentData! as _SegmentedButtonContainerBoxParentData; + final double childHeight = child.getMinIntrinsicHeight(width); + minHeight = math.max(minHeight, childHeight); + child = childParentData.nextSibling; + } + return minHeight; + } + + @override + double computeMaxIntrinsicHeight(double width) { + RenderBox? child = firstChild; + double maxHeight = 0.0; + while (child != null) { + final _SegmentedButtonContainerBoxParentData childParentData = child.parentData! as _SegmentedButtonContainerBoxParentData; + final double childHeight = child.getMaxIntrinsicHeight(width); + maxHeight = math.max(maxHeight, childHeight); + child = childParentData.nextSibling; + } + return maxHeight; + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + return defaultComputeDistanceToHighestActualBaseline(baseline); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! _SegmentedButtonContainerBoxParentData) { + child.parentData = _SegmentedButtonContainerBoxParentData(); + } + } + + void _layoutRects(_NextChild nextChild, RenderBox? leftChild, RenderBox? rightChild) { + RenderBox? child = leftChild; + double start = 0.0; + while (child != null) { + final _SegmentedButtonContainerBoxParentData childParentData = child.parentData! as _SegmentedButtonContainerBoxParentData; + final Offset childOffset = Offset(start, 0.0); + childParentData.offset = childOffset; + final Rect childRect = Rect.fromLTWH(start, 0.0, child.size.width, child.size.height); + final RRect rChildRect = RRect.fromRectAndCorners(childRect); + childParentData.surroundingRect = rChildRect; + start += child.size.width; + child = nextChild(child); + } + } + + Size _calculateChildSize(BoxConstraints constraints) { + double maxHeight = 0; + double childWidth = constraints.minWidth / childCount; + RenderBox? child = firstChild; + while (child != null) { + childWidth = math.max(childWidth, child.getMaxIntrinsicWidth(double.infinity)); + child = childAfter(child); + } + childWidth = math.min(childWidth, constraints.maxWidth / childCount); + child = firstChild; + while (child != null) { + final double boxHeight = child.getMaxIntrinsicHeight(childWidth); + maxHeight = math.max(maxHeight, boxHeight); + child = childAfter(child); + } + return Size(childWidth, maxHeight); + } + + Size _computeOverallSizeFromChildSize(Size childSize) { + return constraints.constrain(Size(childSize.width * childCount, childSize.height)); + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + final Size childSize = _calculateChildSize(constraints); + return _computeOverallSizeFromChildSize(childSize); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + final Size childSize = _calculateChildSize(constraints); + + final BoxConstraints childConstraints = BoxConstraints.tightFor( + width: childSize.width, + height: childSize.height, + ); + + RenderBox? child = firstChild; + while (child != null) { + child.layout(childConstraints, parentUsesSize: true); + child = childAfter(child); + } + + switch (textDirection) { + case TextDirection.rtl: + _layoutRects( + childBefore, + lastChild, + firstChild, + ); + case TextDirection.ltr: + _layoutRects( + childAfter, + firstChild, + lastChild, + ); + } + + size = _computeOverallSizeFromChildSize(childSize); + } + + @override + void paint(PaintingContext context, Offset offset) { + final Rect borderRect = offset & size; + final Path borderClipPath = enabledBorder.getInnerPath(borderRect, textDirection: textDirection); + RenderBox? child = firstChild; + RenderBox? previousChild; + int index = 0; + Path? enabledClipPath; + Path? disabledClipPath; + + context.canvas..save()..clipPath(borderClipPath); + while (child != null) { + final _SegmentedButtonContainerBoxParentData childParentData = child.parentData! as _SegmentedButtonContainerBoxParentData; + final Rect childRect = childParentData.surroundingRect!.outerRect.shift(offset); + + context.canvas..save()..clipRect(childRect); + context.paintChild(child, childParentData.offset + offset); + context.canvas.restore(); + + // Compute a clip rect for the outer border of the child. + late final double segmentLeft; + late final double segmentRight; + late final double dividerPos; + final double borderOutset = math.max(enabledBorder.side.strokeOutset, disabledBorder.side.strokeOutset); + switch (textDirection) { + case TextDirection.rtl: + segmentLeft = child == lastChild ? borderRect.left - borderOutset : childRect.left; + segmentRight = child == firstChild ? borderRect.right + borderOutset : childRect.right; + dividerPos = segmentRight; + case TextDirection.ltr: + segmentLeft = child == firstChild ? borderRect.left - borderOutset : childRect.left; + segmentRight = child == lastChild ? borderRect.right + borderOutset : childRect.right; + dividerPos = segmentLeft; + } + final Rect segmentClipRect = Rect.fromLTRB( + segmentLeft, borderRect.top - borderOutset, + segmentRight, borderRect.bottom + borderOutset); + + // Add the clip rect to the appropriate border clip path + if (segments[index].enabled) { + enabledClipPath = (enabledClipPath ?? Path())..addRect(segmentClipRect); + } else { + disabledClipPath = (disabledClipPath ?? Path())..addRect(segmentClipRect); + } + + // Paint the divider between this segment and the previous one. + if (previousChild != null) { + final BorderSide divider = segments[index - 1].enabled || segments[index].enabled + ? enabledBorder.side.copyWith(strokeAlign: 0.0) + : disabledBorder.side.copyWith(strokeAlign: 0.0); + final Offset top = Offset(dividerPos, childRect.top); + final Offset bottom = Offset(dividerPos, childRect.bottom); + context.canvas.drawLine(top, bottom, divider.toPaint()); + } + + previousChild = child; + child = childAfter(child); + index += 1; + } + context.canvas.restore(); + + // Paint the outer border for both disabled and enabled clip rect if needed. + if (disabledClipPath == null) { + // Just paint the enabled border with no clip. + enabledBorder.paint(context.canvas, borderRect, textDirection: textDirection); + } else if (enabledClipPath == null) { + // Just paint the disabled border with no. + disabledBorder.paint(context.canvas, borderRect, textDirection: textDirection); + } else { + // Paint both of them clipped appropriately for the children segments. + context.canvas..save()..clipPath(enabledClipPath); + enabledBorder.paint(context.canvas, borderRect, textDirection: textDirection); + context.canvas..restore()..save()..clipPath(disabledClipPath); + disabledBorder.paint(context.canvas, borderRect, textDirection: textDirection); + context.canvas.restore(); + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + RenderBox? child = lastChild; + while (child != null) { + final _SegmentedButtonContainerBoxParentData childParentData = child.parentData! as _SegmentedButtonContainerBoxParentData; + if (childParentData.surroundingRect!.contains(position)) { + return result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset localOffset) { + assert(localOffset == position - childParentData.offset); + return child!.hitTest(result, position: localOffset); + }, + ); + } + child = childParentData.previousSibling; + } + return false; + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - SegmentedButton + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _SegmentedButtonDefaultsM3 extends SegmentedButtonThemeData { + _SegmentedButtonDefaultsM3(this.context); + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + @override ButtonStyle? get style { + return ButtonStyle( + textStyle: MaterialStatePropertyAll<TextStyle?>(Theme.of(context).textTheme.labelLarge), + backgroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return null; + } + if (states.contains(MaterialState.selected)) { + return _colors.secondaryContainer; + } + return null; + }), + foregroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onSecondaryContainer; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSecondaryContainer; + } + if (states.contains(MaterialState.focused)) { + return _colors.onSecondaryContainer; + } + return _colors.onSecondaryContainer; + } else { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface; + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface; + } + return _colors.onSurface; + } + }), + overlayColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onSecondaryContainer.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSecondaryContainer.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSecondaryContainer.withOpacity(0.12); + } + } else { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface.withOpacity(0.12); + } + } + return null; + }), + surfaceTintColor: const MaterialStatePropertyAll<Color>(Colors.transparent), + elevation: const MaterialStatePropertyAll<double>(0), + iconSize: const MaterialStatePropertyAll<double?>(18.0), + side: MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return BorderSide(color: _colors.onSurface.withOpacity(0.12)); + } + return BorderSide(color: _colors.outline); + }), + shape: const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()), + minimumSize: const MaterialStatePropertyAll<Size?>(Size.fromHeight(40.0)), + ); + } + @override + Widget? get selectedIcon => const Icon(Icons.check); + + static MaterialStateProperty<Color?> resolveStateColor(Color? unselectedColor, Color? selectedColor){ + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return selectedColor?.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return selectedColor?.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return selectedColor?.withOpacity(0.12); + } + } else { + if (states.contains(MaterialState.pressed)) { + return unselectedColor?.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return unselectedColor?.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return unselectedColor?.withOpacity(0.12); + } + } + return Colors.transparent; + }); + } +} + +// END GENERATED TOKEN PROPERTIES - SegmentedButton diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/segmented_button_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/segmented_button_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..4f302b15c3dff0cfcfa8ec835048885d93184115 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/segmented_button_theme.dart @@ -0,0 +1,174 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Overrides the default values of visual properties for descendant +/// [SegmentedButton] widgets. +/// +/// Descendant widgets obtain the current [SegmentedButtonThemeData] object with +/// [SegmentedButtonTheme.of]. Instances of [SegmentedButtonTheme] can +/// be customized with [SegmentedButtonThemeData.copyWith]. +/// +/// Typically a [SegmentedButtonTheme] is specified as part of the overall +/// [Theme] with [ThemeData.segmentedButtonTheme]. +/// +/// All [SegmentedButtonThemeData] properties are null by default. When null, +/// the [SegmentedButton] computes its own default values, typically based on +/// the overall theme's [ThemeData.colorScheme], [ThemeData.textTheme], and +/// [ThemeData.iconTheme]. +@immutable +class SegmentedButtonThemeData with Diagnosticable { + /// Creates a [SegmentedButtonThemeData] that can be used to override default properties + /// in a [SegmentedButtonTheme] widget. + const SegmentedButtonThemeData({ + this.style, + this.selectedIcon, + }); + + /// Overrides the [SegmentedButton]'s default style. + /// + /// Non-null properties or non-null resolved [MaterialStateProperty] + /// values override the default values used by [SegmentedButton]. + /// + /// If [style] is null, then this theme doesn't override anything. + final ButtonStyle? style; + + /// Override for [SegmentedButton.selectedIcon] property. + /// + /// If non-null, then [selectedIcon] will be used instead of default + /// value for [SegmentedButton.selectedIcon]. + final Widget? selectedIcon; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + SegmentedButtonThemeData copyWith({ + ButtonStyle? style, + Widget? selectedIcon, + }) { + return SegmentedButtonThemeData( + style: style ?? this.style, + selectedIcon: selectedIcon ?? this.selectedIcon, + ); + } + + /// Linearly interpolates between two segmented button themes. + static SegmentedButtonThemeData lerp(SegmentedButtonThemeData? a, SegmentedButtonThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return SegmentedButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + selectedIcon: t < 0.5 ? a?.selectedIcon : b?.selectedIcon, + ); + } + + @override + int get hashCode => Object.hash( + style, + selectedIcon, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is SegmentedButtonThemeData + && other.style == style + && other.selectedIcon == selectedIcon; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ButtonStyle>('style', style, defaultValue: null)); + properties.add(DiagnosticsProperty<Widget>('selectedIcon', selectedIcon, defaultValue: null)); + } +} + +/// An inherited widget that defines the visual properties for +/// [SegmentedButton]s in this widget's subtree. +/// +/// Values specified here are used for [SegmentedButton] properties that are not +/// given an explicit non-null value. +class SegmentedButtonTheme extends InheritedTheme { + /// Creates a [SegmentedButtonTheme] that controls visual parameters for + /// descendent [SegmentedButton]s. + const SegmentedButtonTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the visual properties used by descendant [SegmentedButton] + /// widgets. + final SegmentedButtonThemeData data; + + /// The [data] from the closest instance of this class that encloses the given + /// context. + /// + /// If there is no [SegmentedButtonTheme] in scope, this will return + /// [ThemeData.segmentedButtonTheme] from the ambient [Theme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// SegmentedButtonThemeData theme = SegmentedButtonTheme.of(context); + /// ``` + /// + /// See also: + /// + /// * [maybeOf], which returns null if it doesn't find a + /// [SegmentedButtonTheme] ancestor. + static SegmentedButtonThemeData of(BuildContext context) { + return maybeOf(context) ?? Theme.of(context).segmentedButtonTheme; + } + + /// The data from the closest instance of this class that encloses the given + /// context, if any. + /// + /// Use this function if you want to allow situations where no + /// [SegmentedButtonTheme] is in scope. Prefer using [SegmentedButtonTheme.of] + /// in situations where a [SegmentedButtonThemeData] is expected to be + /// non-null. + /// + /// If there is no [SegmentedButtonTheme] in scope, then this function will + /// return null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// SegmentedButtonThemeData? theme = SegmentedButtonTheme.maybeOf(context); + /// if (theme == null) { + /// // Do something else instead. + /// } + /// ``` + /// + /// See also: + /// + /// * [of], which will return [ThemeData.segmentedButtonTheme] if it doesn't + /// find a [SegmentedButtonTheme] ancestor, instead of returning null. + static SegmentedButtonThemeData? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<SegmentedButtonTheme>()?.data; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return SegmentedButtonTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(SegmentedButtonTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/selectable_text.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/selectable_text.dart new file mode 100644 index 0000000000000000000000000000000000000000..e97441e7a80a91f502765909510a484e65ed76b3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/selectable_text.dart @@ -0,0 +1,762 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; + +import 'adaptive_text_selection_toolbar.dart'; +import 'desktop_text_selection.dart'; +import 'feedback.dart'; +import 'magnifier.dart'; +import 'text_selection.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; +// late FocusNode myFocusNode; + +/// An eyeballed value that moves the cursor slightly left of where it is +/// rendered for text on Android so its positioning more accurately matches the +/// native iOS text cursor positioning. +/// +/// This value is in device pixels, not logical pixels as is typically used +/// throughout the codebase. +const int iOSHorizontalOffset = -2; + +class _TextSpanEditingController extends TextEditingController { + _TextSpanEditingController({required TextSpan textSpan}): + _textSpan = textSpan, + super(text: textSpan.toPlainText(includeSemanticsLabels: false)); + + final TextSpan _textSpan; + + @override + TextSpan buildTextSpan({required BuildContext context, TextStyle? style, required bool withComposing}) { + // This does not care about composing. + return TextSpan( + style: style, + children: <TextSpan>[_textSpan], + ); + } + + @override + set text(String? newText) { + // This should never be reached. + throw UnimplementedError(); + } +} + +class _SelectableTextSelectionGestureDetectorBuilder extends TextSelectionGestureDetectorBuilder { + _SelectableTextSelectionGestureDetectorBuilder({ + required _SelectableTextState state, + }) : _state = state, + super(delegate: state); + + final _SelectableTextState _state; + + @override + void onForcePressStart(ForcePressDetails details) { + super.onForcePressStart(details); + if (delegate.selectionEnabled && shouldShowSelectionToolbar) { + editableText.showToolbar(); + } + } + + @override + void onForcePressEnd(ForcePressDetails details) { + // Not required. + } + + @override + void onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) { + if (delegate.selectionEnabled) { + renderEditable.selectWordsInRange( + from: details.globalPosition - details.offsetFromOrigin, + to: details.globalPosition, + cause: SelectionChangedCause.longPress, + ); + } + } + + @override + void onSingleTapUp(TapDragUpDetails details) { + editableText.hideToolbar(); + if (delegate.selectionEnabled) { + switch (Theme.of(_state.context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + renderEditable.selectWordEdge(cause: SelectionChangedCause.tap); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + renderEditable.selectPosition(cause: SelectionChangedCause.tap); + } + } + _state.widget.onTap?.call(); + } + + @override + void onSingleLongTapStart(LongPressStartDetails details) { + if (delegate.selectionEnabled) { + renderEditable.selectWord(cause: SelectionChangedCause.longPress); + Feedback.forLongPress(_state.context); + } + } +} + +/// A run of selectable text with a single style. +/// +/// The [SelectableText] widget displays a string of text with a single style. +/// The string might break across multiple lines or might all be displayed on +/// the same line depending on the layout constraints. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ZSU3ZXOs6hc} +/// +/// The [style] argument is optional. When omitted, the text will use the style +/// from the closest enclosing [DefaultTextStyle]. If the given style's +/// [TextStyle.inherit] property is true (the default), the given style will +/// be merged with the closest enclosing [DefaultTextStyle]. This merging +/// behavior is useful, for example, to make the text bold while using the +/// default font family and size. +/// +/// {@macro flutter.material.textfield.wantKeepAlive} +/// +/// {@tool snippet} +/// +/// ```dart +/// const SelectableText( +/// 'Hello! How are you?', +/// textAlign: TextAlign.center, +/// style: TextStyle(fontWeight: FontWeight.bold), +/// ) +/// ``` +/// {@end-tool} +/// +/// Using the [SelectableText.rich] constructor, the [SelectableText] widget can +/// display a paragraph with differently styled [TextSpan]s. The sample +/// that follows displays "Hello beautiful world" with different styles +/// for each word. +/// +/// {@tool snippet} +/// +/// ```dart +/// const SelectableText.rich( +/// TextSpan( +/// text: 'Hello', // default text style +/// children: <TextSpan>[ +/// TextSpan(text: ' beautiful ', style: TextStyle(fontStyle: FontStyle.italic)), +/// TextSpan(text: 'world', style: TextStyle(fontWeight: FontWeight.bold)), +/// ], +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Interactivity +/// +/// To make [SelectableText] react to touch events, use callback [onTap] to achieve +/// the desired behavior. +/// +/// See also: +/// +/// * [Text], which is the non selectable version of this widget. +/// * [TextField], which is the editable version of this widget. +class SelectableText extends StatefulWidget { + /// Creates a selectable text widget. + /// + /// If the [style] argument is null, the text will use the style from the + /// closest enclosing [DefaultTextStyle]. + /// + + /// If the [showCursor], [autofocus], [dragStartBehavior], + /// [selectionHeightStyle], [selectionWidthStyle] and [data] arguments are + /// specified, the [maxLines] argument must be greater than zero. + const SelectableText( + String this.data, { + super.key, + this.focusNode, + this.style, + this.strutStyle, + this.textAlign, + this.textDirection, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + this.textScaleFactor, + this.textScaler, + this.showCursor = false, + this.autofocus = false, + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + this.toolbarOptions, + this.minLines, + this.maxLines, + this.cursorWidth = 2.0, + this.cursorHeight, + this.cursorRadius, + this.cursorColor, + this.selectionHeightStyle = ui.BoxHeightStyle.tight, + this.selectionWidthStyle = ui.BoxWidthStyle.tight, + this.dragStartBehavior = DragStartBehavior.start, + this.enableInteractiveSelection = true, + this.selectionControls, + this.onTap, + this.scrollPhysics, + this.semanticsLabel, + this.textHeightBehavior, + this.textWidthBasis, + this.onSelectionChanged, + this.contextMenuBuilder = _defaultContextMenuBuilder, + this.magnifierConfiguration, + }) : assert(maxLines == null || maxLines > 0), + assert(minLines == null || minLines > 0), + assert( + (maxLines == null) || (minLines == null) || (maxLines >= minLines), + "minLines can't be greater than maxLines", + ), + assert( + textScaler == null || textScaleFactor == null, + 'textScaleFactor is deprecated and cannot be specified when textScaler is specified.', + ), + textSpan = null; + + /// Creates a selectable text widget with a [TextSpan]. + /// + /// The [TextSpan.children] attribute of the [textSpan] parameter must only + /// contain [TextSpan]s. Other types of [InlineSpan] are not allowed. + const SelectableText.rich( + TextSpan this.textSpan, { + super.key, + this.focusNode, + this.style, + this.strutStyle, + this.textAlign, + this.textDirection, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + this.textScaleFactor, + this.textScaler, + this.showCursor = false, + this.autofocus = false, + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + this.toolbarOptions, + this.minLines, + this.maxLines, + this.cursorWidth = 2.0, + this.cursorHeight, + this.cursorRadius, + this.cursorColor, + this.selectionHeightStyle = ui.BoxHeightStyle.tight, + this.selectionWidthStyle = ui.BoxWidthStyle.tight, + this.dragStartBehavior = DragStartBehavior.start, + this.enableInteractiveSelection = true, + this.selectionControls, + this.onTap, + this.scrollPhysics, + this.semanticsLabel, + this.textHeightBehavior, + this.textWidthBasis, + this.onSelectionChanged, + this.contextMenuBuilder = _defaultContextMenuBuilder, + this.magnifierConfiguration, + }) : assert(maxLines == null || maxLines > 0), + assert(minLines == null || minLines > 0), + assert( + (maxLines == null) || (minLines == null) || (maxLines >= minLines), + "minLines can't be greater than maxLines", + ), + assert( + textScaler == null || textScaleFactor == null, + 'textScaleFactor is deprecated and cannot be specified when textScaler is specified.', + ), + data = null; + + /// The text to display. + /// + /// This will be null if a [textSpan] is provided instead. + final String? data; + + /// The text to display as a [TextSpan]. + /// + /// This will be null if [data] is provided instead. + final TextSpan? textSpan; + + /// Defines the focus for this widget. + /// + /// Text is only selectable when widget is focused. + /// + /// The [focusNode] is a long-lived object that's typically managed by a + /// [StatefulWidget] parent. See [FocusNode] for more information. + /// + /// To give the focus to this widget, provide a [focusNode] and then + /// use the current [FocusScope] to request the focus: + /// + /// ```dart + /// FocusScope.of(context).requestFocus(myFocusNode); + /// ``` + /// + /// This happens automatically when the widget is tapped. + /// + /// To be notified when the widget gains or loses the focus, add a listener + /// to the [focusNode]: + /// + /// ```dart + /// myFocusNode.addListener(() { print(myFocusNode.hasFocus); }); + /// ``` + /// + /// If null, this widget will create its own [FocusNode] with + /// [FocusNode.skipTraversal] parameter set to `true`, which causes the widget + /// to be skipped over during focus traversal. + final FocusNode? focusNode; + + /// The style to use for the text. + /// + /// If null, defaults [DefaultTextStyle] of context. + final TextStyle? style; + + /// {@macro flutter.widgets.editableText.strutStyle} + final StrutStyle? strutStyle; + + /// {@macro flutter.widgets.editableText.textAlign} + final TextAlign? textAlign; + + /// {@macro flutter.widgets.editableText.textDirection} + final TextDirection? textDirection; + + /// {@macro flutter.widgets.editableText.textScaleFactor} + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + final double? textScaleFactor; + + /// {@macro flutter.painting.textPainter.textScaler} + final TextScaler? textScaler; + + /// {@macro flutter.widgets.editableText.autofocus} + final bool autofocus; + + /// {@macro flutter.widgets.editableText.minLines} + final int? minLines; + + /// {@macro flutter.widgets.editableText.maxLines} + final int? maxLines; + + /// {@macro flutter.widgets.editableText.showCursor} + final bool showCursor; + + /// {@macro flutter.widgets.editableText.cursorWidth} + final double cursorWidth; + + /// {@macro flutter.widgets.editableText.cursorHeight} + final double? cursorHeight; + + /// {@macro flutter.widgets.editableText.cursorRadius} + final Radius? cursorRadius; + + /// The color of the cursor. + /// + /// The cursor indicates the current text insertion point. + /// + /// If null then [DefaultSelectionStyle.cursorColor] is used. If that is also + /// null and [ThemeData.platform] is [TargetPlatform.iOS] or + /// [TargetPlatform.macOS], then [CupertinoThemeData.primaryColor] is used. + /// Otherwise [ColorScheme.primary] of [ThemeData.colorScheme] is used. + final Color? cursorColor; + + /// Controls how tall the selection highlight boxes are computed to be. + /// + /// See [ui.BoxHeightStyle] for details on available styles. + final ui.BoxHeightStyle selectionHeightStyle; + + /// Controls how wide the selection highlight boxes are computed to be. + /// + /// See [ui.BoxWidthStyle] for details on available styles. + final ui.BoxWidthStyle selectionWidthStyle; + + /// {@macro flutter.widgets.editableText.enableInteractiveSelection} + final bool enableInteractiveSelection; + + /// {@macro flutter.widgets.editableText.selectionControls} + final TextSelectionControls? selectionControls; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// Configuration of toolbar options. + /// + /// Paste and cut will be disabled regardless. + /// + /// If not set, select all and copy will be enabled by default. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + final ToolbarOptions? toolbarOptions; + + /// {@macro flutter.widgets.editableText.selectionEnabled} + bool get selectionEnabled => enableInteractiveSelection; + + /// Called when the user taps on this selectable text. + /// + /// The selectable text builds a [GestureDetector] to handle input events like tap, + /// to trigger focus requests, to move the caret, adjust the selection, etc. + /// Handling some of those events by wrapping the selectable text with a competing + /// GestureDetector is problematic. + /// + /// To unconditionally handle taps, without interfering with the selectable text's + /// internal gesture detector, provide this callback. + /// + /// To be notified when the text field gains or loses the focus, provide a + /// [focusNode] and add a listener to that. + /// + /// To listen to arbitrary pointer events without competing with the + /// selectable text's internal gesture detector, use a [Listener]. + final GestureTapCallback? onTap; + + /// {@macro flutter.widgets.editableText.scrollPhysics} + final ScrollPhysics? scrollPhysics; + + /// {@macro flutter.widgets.Text.semanticsLabel} + final String? semanticsLabel; + + /// {@macro dart.ui.textHeightBehavior} + final TextHeightBehavior? textHeightBehavior; + + /// {@macro flutter.painting.textPainter.textWidthBasis} + final TextWidthBasis? textWidthBasis; + + /// {@macro flutter.widgets.editableText.onSelectionChanged} + final SelectionChangedCallback? onSelectionChanged; + + /// {@macro flutter.widgets.EditableText.contextMenuBuilder} + final EditableTextContextMenuBuilder? contextMenuBuilder; + + static Widget _defaultContextMenuBuilder(BuildContext context, EditableTextState editableTextState) { + return AdaptiveTextSelectionToolbar.editableText( + editableTextState: editableTextState, + ); + } + + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.intro} + /// + /// {@macro flutter.widgets.magnifier.intro} + /// + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.details} + /// + /// By default, builds a [CupertinoTextMagnifier] on iOS and [TextMagnifier] + /// on Android, and builds nothing on all other platforms. If it is desired to + /// suppress the magnifier, consider passing [TextMagnifierConfiguration.disabled]. + final TextMagnifierConfiguration? magnifierConfiguration; + + @override + State<SelectableText> createState() => _SelectableTextState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('data', data, defaultValue: null)); + properties.add(DiagnosticsProperty<String>('semanticsLabel', semanticsLabel, defaultValue: null)); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('style', style, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('autofocus', autofocus, defaultValue: false)); + properties.add(DiagnosticsProperty<bool>('showCursor', showCursor, defaultValue: false)); + properties.add(IntProperty('minLines', minLines, defaultValue: null)); + properties.add(IntProperty('maxLines', maxLines, defaultValue: null)); + properties.add(EnumProperty<TextAlign>('textAlign', textAlign, defaultValue: null)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(DoubleProperty('textScaleFactor', textScaleFactor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextScaler>('textScaler', textScaler, defaultValue: null)); + properties.add(DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0)); + properties.add(DoubleProperty('cursorHeight', cursorHeight, defaultValue: null)); + properties.add(DiagnosticsProperty<Radius>('cursorRadius', cursorRadius, defaultValue: null)); + properties.add(DiagnosticsProperty<Color>('cursorColor', cursorColor, defaultValue: null)); + properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); + properties.add(DiagnosticsProperty<TextSelectionControls>('selectionControls', selectionControls, defaultValue: null)); + properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null)); + properties.add(DiagnosticsProperty<TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null)); + } +} + +class _SelectableTextState extends State<SelectableText> implements TextSelectionGestureDetectorBuilderDelegate { + EditableTextState? get _editableText => editableTextKey.currentState; + + late _TextSpanEditingController _controller; + + FocusNode? _focusNode; + FocusNode get _effectiveFocusNode => + widget.focusNode ?? (_focusNode ??= FocusNode(skipTraversal: true)); + + bool _showSelectionHandles = false; + + late _SelectableTextSelectionGestureDetectorBuilder _selectionGestureDetectorBuilder; + + // API for TextSelectionGestureDetectorBuilderDelegate. + @override + late bool forcePressEnabled; + + @override + final GlobalKey<EditableTextState> editableTextKey = GlobalKey<EditableTextState>(); + + @override + bool get selectionEnabled => widget.selectionEnabled; + // End of API for TextSelectionGestureDetectorBuilderDelegate. + + @override + void initState() { + super.initState(); + _selectionGestureDetectorBuilder = _SelectableTextSelectionGestureDetectorBuilder( + state: this, + ); + _controller = _TextSpanEditingController( + textSpan: widget.textSpan ?? TextSpan(text: widget.data), + ); + _controller.addListener(_onControllerChanged); + } + + @override + void didUpdateWidget(SelectableText oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.data != oldWidget.data || widget.textSpan != oldWidget.textSpan) { + _controller.removeListener(_onControllerChanged); + _controller.dispose(); + _controller = _TextSpanEditingController( + textSpan: widget.textSpan ?? TextSpan(text: widget.data), + ); + _controller.addListener(_onControllerChanged); + } + if (_effectiveFocusNode.hasFocus && _controller.selection.isCollapsed) { + _showSelectionHandles = false; + } else { + _showSelectionHandles = true; + } + } + + @override + void dispose() { + _focusNode?.dispose(); + _controller.dispose(); + super.dispose(); + } + + void _onControllerChanged() { + final bool showSelectionHandles = !_effectiveFocusNode.hasFocus + || !_controller.selection.isCollapsed; + if (showSelectionHandles == _showSelectionHandles) { + return; + } + setState(() { + _showSelectionHandles = showSelectionHandles; + }); + } + + void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) { + final bool willShowSelectionHandles = _shouldShowSelectionHandles(cause); + if (willShowSelectionHandles != _showSelectionHandles) { + setState(() { + _showSelectionHandles = willShowSelectionHandles; + }); + } + + widget.onSelectionChanged?.call(selection, cause); + + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + if (cause == SelectionChangedCause.longPress) { + _editableText?.bringIntoView(selection.base); + } + return; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + // Do nothing. + } + } + + /// Toggle the toolbar when a selection handle is tapped. + void _handleSelectionHandleTapped() { + if (_controller.selection.isCollapsed) { + _editableText!.toggleToolbar(); + } + } + + bool _shouldShowSelectionHandles(SelectionChangedCause? cause) { + // When the text field is activated by something that doesn't trigger the + // selection overlay, we shouldn't show the handles either. + if (!_selectionGestureDetectorBuilder.shouldShowSelectionToolbar) { + return false; + } + + if (_controller.selection.isCollapsed) { + return false; + } + + if (cause == SelectionChangedCause.keyboard) { + return false; + } + + if (cause == SelectionChangedCause.longPress) { + return true; + } + + if (_controller.text.isNotEmpty) { + return true; + } + + return false; + } + + @override + Widget build(BuildContext context) { + // TODO(garyq): Assert to block WidgetSpans from being used here are removed, + // but we still do not yet have nice handling of things like carets, clipboard, + // and other features. We should add proper support. Currently, caret handling + // is blocked on SkParagraph switch and https://github.com/flutter/engine/pull/27010 + // should be landed in SkParagraph after the switch is complete. + assert(debugCheckHasMediaQuery(context)); + assert(debugCheckHasDirectionality(context)); + assert( + !(widget.style != null && !widget.style!.inherit && + (widget.style!.fontSize == null || widget.style!.textBaseline == null)), + 'inherit false style must supply fontSize and textBaseline', + ); + + final ThemeData theme = Theme.of(context); + final DefaultSelectionStyle selectionStyle = DefaultSelectionStyle.of(context); + final FocusNode focusNode = _effectiveFocusNode; + + TextSelectionControls? textSelectionControls = widget.selectionControls; + final bool paintCursorAboveText; + final bool cursorOpacityAnimates; + Offset? cursorOffset; + final Color cursorColor; + final Color selectionColor; + Radius? cursorRadius = widget.cursorRadius; + + switch (theme.platform) { + case TargetPlatform.iOS: + final CupertinoThemeData cupertinoTheme = CupertinoTheme.of(context); + forcePressEnabled = true; + textSelectionControls ??= cupertinoTextSelectionHandleControls; + paintCursorAboveText = true; + cursorOpacityAnimates = true; + cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? cupertinoTheme.primaryColor; + selectionColor = selectionStyle.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40); + cursorRadius ??= const Radius.circular(2.0); + cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.devicePixelRatioOf(context), 0); + + case TargetPlatform.macOS: + final CupertinoThemeData cupertinoTheme = CupertinoTheme.of(context); + forcePressEnabled = false; + textSelectionControls ??= cupertinoDesktopTextSelectionHandleControls; + paintCursorAboveText = true; + cursorOpacityAnimates = true; + cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? cupertinoTheme.primaryColor; + selectionColor = selectionStyle.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40); + cursorRadius ??= const Radius.circular(2.0); + cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.devicePixelRatioOf(context), 0); + + case TargetPlatform.android: + case TargetPlatform.fuchsia: + forcePressEnabled = false; + textSelectionControls ??= materialTextSelectionHandleControls; + paintCursorAboveText = false; + cursorOpacityAnimates = false; + cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? theme.colorScheme.primary; + selectionColor = selectionStyle.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40); + + case TargetPlatform.linux: + case TargetPlatform.windows: + forcePressEnabled = false; + textSelectionControls ??= desktopTextSelectionHandleControls; + paintCursorAboveText = false; + cursorOpacityAnimates = false; + cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? theme.colorScheme.primary; + selectionColor = selectionStyle.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40); + } + + final DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(context); + TextStyle? effectiveTextStyle = widget.style; + if (effectiveTextStyle == null || effectiveTextStyle.inherit) { + effectiveTextStyle = defaultTextStyle.style.merge(widget.style ?? _controller._textSpan.style); + } + final TextScaler? effectiveScaler = widget.textScaler ?? switch (widget.textScaleFactor) { + null => null, + final double textScaleFactor => TextScaler.linear(textScaleFactor), + }; + final Widget child = RepaintBoundary( + child: EditableText( + key: editableTextKey, + style: effectiveTextStyle, + readOnly: true, + toolbarOptions: widget.toolbarOptions, + textWidthBasis: widget.textWidthBasis ?? defaultTextStyle.textWidthBasis, + textHeightBehavior: widget.textHeightBehavior ?? defaultTextStyle.textHeightBehavior, + showSelectionHandles: _showSelectionHandles, + showCursor: widget.showCursor, + controller: _controller, + focusNode: focusNode, + strutStyle: widget.strutStyle ?? const StrutStyle(), + textAlign: widget.textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start, + textDirection: widget.textDirection, + textScaler: effectiveScaler, + autofocus: widget.autofocus, + forceLine: false, + minLines: widget.minLines, + maxLines: widget.maxLines ?? defaultTextStyle.maxLines, + selectionColor: selectionColor, + selectionControls: widget.selectionEnabled ? textSelectionControls : null, + onSelectionChanged: _handleSelectionChanged, + onSelectionHandleTapped: _handleSelectionHandleTapped, + rendererIgnoresPointer: true, + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: cursorRadius, + cursorColor: cursorColor, + selectionHeightStyle: widget.selectionHeightStyle, + selectionWidthStyle: widget.selectionWidthStyle, + cursorOpacityAnimates: cursorOpacityAnimates, + cursorOffset: cursorOffset, + paintCursorAboveText: paintCursorAboveText, + backgroundCursorColor: CupertinoColors.inactiveGray, + enableInteractiveSelection: widget.enableInteractiveSelection, + magnifierConfiguration: widget.magnifierConfiguration ?? TextMagnifier.adaptiveMagnifierConfiguration, + dragStartBehavior: widget.dragStartBehavior, + scrollPhysics: widget.scrollPhysics, + autofillHints: null, + contextMenuBuilder: widget.contextMenuBuilder, + ), + ); + + return Semantics( + label: widget.semanticsLabel, + excludeSemantics: widget.semanticsLabel != null, + onLongPress: () { + _effectiveFocusNode.requestFocus(); + }, + child: _selectionGestureDetectorBuilder.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: child, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/selection_area.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/selection_area.dart new file mode 100644 index 0000000000000000000000000000000000000000..2334f545cc3bf833421e76e5a820f2431a5ada2a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/selection_area.dart @@ -0,0 +1,133 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/rendering.dart'; + +import 'adaptive_text_selection_toolbar.dart'; +import 'debug.dart'; +import 'desktop_text_selection.dart'; +import 'magnifier.dart'; +import 'text_selection.dart'; +import 'theme.dart'; + +/// A widget that introduces an area for user selections with adaptive selection +/// controls. +/// +/// This widget creates a [SelectableRegion] with platform-adaptive selection +/// controls. +/// +/// Flutter widgets are not selectable by default. To enable selection for +/// a specific screen, consider wrapping the body of the [Route] with a +/// [SelectionArea]. +/// +/// The [SelectionArea] widget must have a [Localizations] ancestor that +/// contains a [MaterialLocalizations] delegate; using the [MaterialApp] widget +/// ensures that such an ancestor is present. +/// +/// {@tool dartpad} +/// This example shows how to make a screen selectable. +/// +/// ** See code in examples/api/lib/material/selection_area/selection_area.0.dart ** +/// {@end-tool} +/// +/// See also: +/// * [SelectableRegion], which provides an overview of the selection system. +class SelectionArea extends StatefulWidget { + /// Creates a [SelectionArea]. + /// + /// If [selectionControls] is null, a platform specific one is used. + const SelectionArea({ + super.key, + this.focusNode, + this.selectionControls, + this.contextMenuBuilder = _defaultContextMenuBuilder, + this.magnifierConfiguration, + this.onSelectionChanged, + required this.child, + }); + + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.intro} + /// + /// {@macro flutter.widgets.magnifier.intro} + /// + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.details} + /// + /// By default, builds a [CupertinoTextMagnifier] on iOS and [TextMagnifier] + /// on Android, and builds nothing on all other platforms. If it is desired to + /// suppress the magnifier, consider passing [TextMagnifierConfiguration.disabled]. + final TextMagnifierConfiguration? magnifierConfiguration; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// The delegate to build the selection handles and toolbar. + /// + /// If it is null, the platform specific selection control is used. + final TextSelectionControls? selectionControls; + + /// {@macro flutter.widgets.EditableText.contextMenuBuilder} + /// + /// If not provided, will build a default menu based on the ambient + /// [ThemeData.platform]. + /// + /// {@tool dartpad} + /// This example shows how to build a custom context menu for any selected + /// content in a SelectionArea. + /// + /// ** See code in examples/api/lib/material/context_menu/selectable_region_toolbar_builder.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [AdaptiveTextSelectionToolbar], which is built by default. + final SelectableRegionContextMenuBuilder? contextMenuBuilder; + + /// Called when the selected content changes. + final ValueChanged<SelectedContent?>? onSelectionChanged; + + /// The child widget this selection area applies to. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + static Widget _defaultContextMenuBuilder(BuildContext context, SelectableRegionState selectableRegionState) { + return AdaptiveTextSelectionToolbar.selectableRegion( + selectableRegionState: selectableRegionState, + ); + } + + @override + State<StatefulWidget> createState() => _SelectionAreaState(); +} + +class _SelectionAreaState extends State<SelectionArea> { + FocusNode get _effectiveFocusNode => widget.focusNode ?? (_internalNode ??= FocusNode()); + FocusNode? _internalNode; + + @override + void dispose() { + _internalNode?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + final TextSelectionControls controls = widget.selectionControls ?? switch (Theme.of(context).platform) { + TargetPlatform.android || TargetPlatform.fuchsia => materialTextSelectionHandleControls, + TargetPlatform.linux || TargetPlatform.windows => desktopTextSelectionHandleControls, + TargetPlatform.iOS => cupertinoTextSelectionHandleControls, + TargetPlatform.macOS => cupertinoDesktopTextSelectionHandleControls, + }; + return SelectableRegion( + selectionControls: controls, + focusNode: _effectiveFocusNode, + contextMenuBuilder: widget.contextMenuBuilder, + magnifierConfiguration: widget.magnifierConfiguration ?? TextMagnifier.adaptiveMagnifierConfiguration, + onSelectionChanged: widget.onSelectionChanged, + child: widget.child, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag new file mode 100644 index 0000000000000000000000000000000000000000..f9f3ce6be3dd5b64ae79a7d86c525f4ed2c67aa6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/shaders/ink_sparkle.frag @@ -0,0 +1,105 @@ +#version 320 es + +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +precision highp float; + +#include <flutter/runtime_effect.glsl> + +// TODO(antrob): Put these in a more logical order (e.g. separate consts vs varying, etc) + +layout(location = 0) uniform vec4 u_color; +// u_alpha, u_sparkle_alpha, u_blur, u_radius_scale +layout(location = 1) uniform vec4 u_composite_1; +layout(location = 2) uniform vec2 u_center; +layout(location = 3) uniform float u_max_radius; +layout(location = 4) uniform vec2 u_resolution_scale; +layout(location = 5) uniform vec2 u_noise_scale; +layout(location = 6) uniform float u_noise_phase; +layout(location = 7) uniform vec2 u_circle1; +layout(location = 8) uniform vec2 u_circle2; +layout(location = 9) uniform vec2 u_circle3; +layout(location = 10) uniform vec2 u_rotation1; +layout(location = 11) uniform vec2 u_rotation2; +layout(location = 12) uniform vec2 u_rotation3; + +layout(location = 0) out vec4 fragColor; + +const float PI = 3.1415926535897932384626; +const float PI_ROTATE_RIGHT = PI * 0.0078125; +const float PI_ROTATE_LEFT = PI * -0.0078125; +const float ONE_THIRD = 1./3.; +const vec2 TURBULENCE_SCALE = vec2(0.8); + +float u_alpha = u_composite_1.x; +float u_sparkle_alpha = u_composite_1.y; +float u_blur = u_composite_1.z; +float u_radius_scale = u_composite_1.w; + +float triangle_noise(highp vec2 n) { + n = fract(n * vec2(5.3987, 5.4421)); + n += dot(n.yx, n.xy + vec2(21.5351, 14.3137)); + float xy = n.x * n.y; + return fract(xy * 95.4307) + fract(xy * 75.04961) - 1.0; +} + +float threshold(float v, float l, float h) { + return step(l, v) * (1.0 - step(h, v)); +} + +mat2 rotate2d(vec2 rad){ + return mat2(rad.x, -rad.y, rad.y, rad.x); +} + +float soft_circle(vec2 uv, vec2 xy, float radius, float blur) { + float blur_half = blur * 0.5; + float d = distance(uv, xy); + return 1.0 - smoothstep(1.0 - blur_half, 1.0 + blur_half, d / radius); +} + +float soft_ring(vec2 uv, vec2 xy, float radius, float thickness, float blur) { + float circle_outer = soft_circle(uv, xy, radius + thickness, blur); + float circle_inner = soft_circle(uv, xy, max(radius - thickness, 0.0), blur); + return clamp(circle_outer - circle_inner, 0.0, 1.0); +} + +float circle_grid(vec2 resolution, vec2 p, vec2 xy, vec2 rotation, float cell_diameter) { + p = rotate2d(rotation) * (xy - p) + xy; + p = mod(p, cell_diameter) / resolution; + float cell_uv = cell_diameter / resolution.y * 0.5; + float r = 0.65 * cell_uv; + return soft_circle(p, vec2(cell_uv), r, r * 50.0); +} + +float sparkle(vec2 uv, float t) { + float n = triangle_noise(uv); + float s = threshold(n, 0.0, 0.05); + s += threshold(n + sin(PI * (t + 0.35)), 0.1, 0.15); + s += threshold(n + sin(PI * (t + 0.7)), 0.2, 0.25); + s += threshold(n + sin(PI * (t + 1.05)), 0.3, 0.35); + return clamp(s, 0.0, 1.0) * 0.55; +} + +float turbulence(vec2 uv) { + vec2 uv_scale = uv * TURBULENCE_SCALE; + float g1 = circle_grid(TURBULENCE_SCALE, uv_scale, u_circle1, u_rotation1, 0.17); + float g2 = circle_grid(TURBULENCE_SCALE, uv_scale, u_circle2, u_rotation2, 0.2); + float g3 = circle_grid(TURBULENCE_SCALE, uv_scale, u_circle3, u_rotation3, 0.275); + float v = (g1 * g1 + g2 - g3) * 0.5; + return clamp(0.45 + 0.8 * v, 0.0, 1.0); +} + +void main() { + vec2 p = FlutterFragCoord(); + vec2 uv = p * u_resolution_scale; + vec2 density_uv = uv - mod(p, u_noise_scale); + float radius = u_max_radius * u_radius_scale; + float turbulence = turbulence(uv); + float ring = soft_ring(p, u_center, radius, 0.05 * u_max_radius, u_blur); + float sparkle = sparkle(density_uv, u_noise_phase) * ring * turbulence * u_sparkle_alpha; + float wave_alpha = soft_circle(p, u_center, radius, u_blur) * u_alpha * u_color.a; + vec4 wave_color = vec4(u_color.rgb * wave_alpha, wave_alpha); + fragColor = mix(wave_color, vec4(1.0), sparkle); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/shadows.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/shadows.dart new file mode 100644 index 0000000000000000000000000000000000000000..35947a61b842dcc7486a725830d0e115a8b7a8bb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/shadows.dart @@ -0,0 +1,94 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/painting.dart'; + +// Based on https://material.io/design/environment/elevation.html +// Currently, only the elevation values that are bound to one or more widgets are +// defined here. + +/// Map of elevation offsets used by Material Design to [BoxShadow] definitions. +/// +/// The following elevations have defined shadows: 1, 2, 3, 4, 6, 8, 9, 12, 16, 24. +/// +/// Each entry has three shadows which must be combined to obtain the defined +/// effect for that elevation. +/// +/// This is useful when simulating a shadow with a [BoxDecoration] or other +/// class that uses a list of [BoxShadow] objects. +/// +/// See also: +/// +/// * [Material], which takes an arbitrary double for its elevation and generates +/// a shadow dynamically. +/// * <https://material.io/design/environment/elevation.html> +const Map<int, List<BoxShadow>> kElevationToShadow = _elevationToShadow; // to hide the literal from the docs + +const Color _kKeyUmbraOpacity = Color(0x33000000); // alpha = 0.2 +const Color _kKeyPenumbraOpacity = Color(0x24000000); // alpha = 0.14 +const Color _kAmbientShadowOpacity = Color(0x1F000000); // alpha = 0.12 +const Map<int, List<BoxShadow>> _elevationToShadow = <int, List<BoxShadow>>{ + // The empty list depicts no elevation. + 0: <BoxShadow>[], + + 1: <BoxShadow>[ + BoxShadow(offset: Offset(0.0, 2.0), blurRadius: 1.0, spreadRadius: -1.0, color: _kKeyUmbraOpacity), + BoxShadow(offset: Offset(0.0, 1.0), blurRadius: 1.0, color: _kKeyPenumbraOpacity), + BoxShadow(offset: Offset(0.0, 1.0), blurRadius: 3.0, color: _kAmbientShadowOpacity), + ], + + 2: <BoxShadow>[ + BoxShadow(offset: Offset(0.0, 3.0), blurRadius: 1.0, spreadRadius: -2.0, color: _kKeyUmbraOpacity), + BoxShadow(offset: Offset(0.0, 2.0), blurRadius: 2.0, color: _kKeyPenumbraOpacity), + BoxShadow(offset: Offset(0.0, 1.0), blurRadius: 5.0, color: _kAmbientShadowOpacity), + ], + + 3: <BoxShadow>[ + BoxShadow(offset: Offset(0.0, 3.0), blurRadius: 3.0, spreadRadius: -2.0, color: _kKeyUmbraOpacity), + BoxShadow(offset: Offset(0.0, 3.0), blurRadius: 4.0, color: _kKeyPenumbraOpacity), + BoxShadow(offset: Offset(0.0, 1.0), blurRadius: 8.0, color: _kAmbientShadowOpacity), + ], + + 4: <BoxShadow>[ + BoxShadow(offset: Offset(0.0, 2.0), blurRadius: 4.0, spreadRadius: -1.0, color: _kKeyUmbraOpacity), + BoxShadow(offset: Offset(0.0, 4.0), blurRadius: 5.0, color: _kKeyPenumbraOpacity), + BoxShadow(offset: Offset(0.0, 1.0), blurRadius: 10.0, color: _kAmbientShadowOpacity), + ], + + 6: <BoxShadow>[ + BoxShadow(offset: Offset(0.0, 3.0), blurRadius: 5.0, spreadRadius: -1.0, color: _kKeyUmbraOpacity), + BoxShadow(offset: Offset(0.0, 6.0), blurRadius: 10.0, color: _kKeyPenumbraOpacity), + BoxShadow(offset: Offset(0.0, 1.0), blurRadius: 18.0, color: _kAmbientShadowOpacity), + ], + + 8: <BoxShadow>[ + BoxShadow(offset: Offset(0.0, 5.0), blurRadius: 5.0, spreadRadius: -3.0, color: _kKeyUmbraOpacity), + BoxShadow(offset: Offset(0.0, 8.0), blurRadius: 10.0, spreadRadius: 1.0, color: _kKeyPenumbraOpacity), + BoxShadow(offset: Offset(0.0, 3.0), blurRadius: 14.0, spreadRadius: 2.0, color: _kAmbientShadowOpacity), + ], + + 9: <BoxShadow>[ + BoxShadow(offset: Offset(0.0, 5.0), blurRadius: 6.0, spreadRadius: -3.0, color: _kKeyUmbraOpacity), + BoxShadow(offset: Offset(0.0, 9.0), blurRadius: 12.0, spreadRadius: 1.0, color: _kKeyPenumbraOpacity), + BoxShadow(offset: Offset(0.0, 3.0), blurRadius: 16.0, spreadRadius: 2.0, color: _kAmbientShadowOpacity), + ], + + 12: <BoxShadow>[ + BoxShadow(offset: Offset(0.0, 7.0), blurRadius: 8.0, spreadRadius: -4.0, color: _kKeyUmbraOpacity), + BoxShadow(offset: Offset(0.0, 12.0), blurRadius: 17.0, spreadRadius: 2.0, color: _kKeyPenumbraOpacity), + BoxShadow(offset: Offset(0.0, 5.0), blurRadius: 22.0, spreadRadius: 4.0, color: _kAmbientShadowOpacity), + ], + + 16: <BoxShadow>[ + BoxShadow(offset: Offset(0.0, 8.0), blurRadius: 10.0, spreadRadius: -5.0, color: _kKeyUmbraOpacity), + BoxShadow(offset: Offset(0.0, 16.0), blurRadius: 24.0, spreadRadius: 2.0, color: _kKeyPenumbraOpacity), + BoxShadow(offset: Offset(0.0, 6.0), blurRadius: 30.0, spreadRadius: 5.0, color: _kAmbientShadowOpacity), + ], + + 24: <BoxShadow>[ + BoxShadow(offset: Offset(0.0, 11.0), blurRadius: 15.0, spreadRadius: -7.0, color: _kKeyUmbraOpacity), + BoxShadow(offset: Offset(0.0, 24.0), blurRadius: 38.0, spreadRadius: 3.0, color: _kKeyPenumbraOpacity), + BoxShadow(offset: Offset(0.0, 9.0), blurRadius: 46.0, spreadRadius: 8.0, color: _kAmbientShadowOpacity), + ], +}; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/slider.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/slider.dart new file mode 100644 index 0000000000000000000000000000000000000000..f2075f7c9ca1ec2fe3909c1cca9baa006b63c805 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/slider.dart @@ -0,0 +1,2047 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart' show timeDilation; +import 'package:flutter/services.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'slider_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// int _dollars = 0; +// int _duelCommandment = 1; +// void setState(VoidCallback fn) { } + +/// [Slider] uses this callback to paint the value indicator on the overlay. +/// +/// Since the value indicator is painted on the Overlay; this method paints the +/// value indicator in a [RenderBox] that appears in the [Overlay]. +typedef PaintValueIndicator = void Function(PaintingContext context, Offset offset); + +enum _SliderType { material, adaptive } + +/// Possible ways for a user to interact with a [Slider]. +enum SliderInteraction { + /// Allows the user to interact with a [Slider] by tapping or sliding anywhere + /// on the track. + /// + /// Essentially all possible interactions are allowed. + /// + /// This is different from [SliderInteraction.slideOnly] as when you try + /// to slide anywhere other than the thumb, the thumb will move to the first + /// point of contact. + tapAndSlide, + + /// Allows the user to interact with a [Slider] by only tapping anywhere on + /// the track. + /// + /// Sliding interaction is ignored. + tapOnly, + + /// Allows the user to interact with a [Slider] only by sliding anywhere on + /// the track. + /// + /// Tapping interaction is ignored. + slideOnly, + + /// Allows the user to interact with a [Slider] only by sliding the thumb. + /// + /// Tapping and sliding interactions on the track are ignored. + slideThumb; +} + +/// A Material Design slider. +/// +/// Used to select from a range of values. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ufb4gIPDmEs} +/// +/// {@tool dartpad} +/// ![A legacy slider widget, consisting of 5 divisions and showing the default value +/// indicator.](https://flutter.github.io/assets-for-api-docs/assets/material/slider.png) +/// +/// The Sliders value is part of the Stateful widget subclass to change the value +/// setState was called. +/// +/// ** See code in examples/api/lib/material/slider/slider.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows the creation of a [Slider] using [ThemeData.useMaterial3] flag, +/// as described in: https://m3.material.io/components/sliders/overview. +/// +/// ** See code in examples/api/lib/material/slider/slider.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows a [Slider] widget using the [Slider.secondaryTrackValue] +/// to show a secondary track in the slider. +/// +/// ** See code in examples/api/lib/material/slider/slider.2.dart ** +/// {@end-tool} +/// +/// A slider can be used to select from either a continuous or a discrete set of +/// values. The default is to use a continuous range of values from [min] to +/// [max]. To use discrete values, use a non-null value for [divisions], which +/// indicates the number of discrete intervals. For example, if [min] is 0.0 and +/// [max] is 50.0 and [divisions] is 5, then the slider can take on the +/// discrete values 0.0, 10.0, 20.0, 30.0, 40.0, and 50.0. +/// +/// The terms for the parts of a slider are: +/// +/// * The "thumb", which is a shape that slides horizontally when the user +/// drags it. +/// * The "track", which is the line that the slider thumb slides along. +/// * The "value indicator", which is a shape that pops up when the user +/// is dragging the thumb to indicate the value being selected. +/// * The "active" side of the slider is the side between the thumb and the +/// minimum value. +/// * The "inactive" side of the slider is the side between the thumb and the +/// maximum value. +/// +/// The slider will be disabled if [onChanged] is null or if the range given by +/// [min]..[max] is empty (i.e. if [min] is equal to [max]). +/// +/// The slider widget itself does not maintain any state. Instead, when the state +/// of the slider changes, the widget calls the [onChanged] callback. Most +/// widgets that use a slider will listen for the [onChanged] callback and +/// rebuild the slider with a new [value] to update the visual appearance of the +/// slider. To know when the value starts to change, or when it is done +/// changing, set the optional callbacks [onChangeStart] and/or [onChangeEnd]. +/// +/// By default, a slider will be as wide as possible, centered vertically. When +/// given unbounded constraints, it will attempt to make the track 144 pixels +/// wide (with margins on each side) and will shrink-wrap vertically. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// Requires one of its ancestors to be a [MediaQuery] widget. Typically, these +/// are introduced by the [MaterialApp] or [WidgetsApp] widget at the top of +/// your application widget tree. +/// +/// To determine how it should be displayed (e.g. colors, thumb shape, etc.), +/// a slider uses the [SliderThemeData] available from either a [SliderTheme] +/// widget or the [ThemeData.sliderTheme] a [Theme] widget above it in the +/// widget tree. You can also override some of the colors with the [activeColor] +/// and [inactiveColor] properties, although more fine-grained control of the +/// look is achieved using a [SliderThemeData]. +/// +/// See also: +/// +/// * [SliderTheme] and [SliderThemeData] for information about controlling +/// the visual appearance of the slider. +/// * [Radio], for selecting among a set of explicit values. +/// * [Checkbox] and [Switch], for toggling a particular value on or off. +/// * <https://material.io/design/components/sliders.html> +/// * [MediaQuery], from which the text scale factor is obtained. +class Slider extends StatefulWidget { + /// Creates a Material Design slider. + /// + /// The slider itself does not maintain any state. Instead, when the state of + /// the slider changes, the widget calls the [onChanged] callback. Most + /// widgets that use a slider will listen for the [onChanged] callback and + /// rebuild the slider with a new [value] to update the visual appearance of + /// the slider. + /// + /// * [value] determines currently selected value for this slider. + /// * [onChanged] is called while the user is selecting a new value for the + /// slider. + /// * [onChangeStart] is called when the user starts to select a new value for + /// the slider. + /// * [onChangeEnd] is called when the user is done selecting a new value for + /// the slider. + /// + /// You can override some of the colors with the [activeColor] and + /// [inactiveColor] properties, although more fine-grained control of the + /// appearance is achieved using a [SliderThemeData]. + const Slider({ + super.key, + required this.value, + this.secondaryTrackValue, + required this.onChanged, + this.onChangeStart, + this.onChangeEnd, + this.min = 0.0, + this.max = 1.0, + this.divisions, + this.label, + this.activeColor, + this.inactiveColor, + this.secondaryActiveColor, + this.thumbColor, + this.overlayColor, + this.mouseCursor, + this.semanticFormatterCallback, + this.focusNode, + this.autofocus = false, + this.allowedInteraction, + }) : _sliderType = _SliderType.material, + assert(min <= max), + assert(value >= min && value <= max, + 'Value $value is not between minimum $min and maximum $max'), + assert(secondaryTrackValue == null || (secondaryTrackValue >= min && secondaryTrackValue <= max), + 'SecondaryValue $secondaryTrackValue is not between $min and $max'), + assert(divisions == null || divisions > 0); + + /// Creates an adaptive [Slider] based on the target platform, following + /// Material design's + /// [Cross-platform guidelines](https://material.io/design/platform-guidance/cross-platform-adaptation.html). + /// + /// Creates a [CupertinoSlider] if the target platform is iOS or macOS, creates a + /// Material Design slider otherwise. + /// + /// If a [CupertinoSlider] is created, the following parameters are ignored: + /// [secondaryTrackValue], [label], [inactiveColor], [secondaryActiveColor], + /// [semanticFormatterCallback]. + /// + /// The target platform is based on the current [Theme]: [ThemeData.platform]. + const Slider.adaptive({ + super.key, + required this.value, + this.secondaryTrackValue, + required this.onChanged, + this.onChangeStart, + this.onChangeEnd, + this.min = 0.0, + this.max = 1.0, + this.divisions, + this.label, + this.mouseCursor, + this.activeColor, + this.inactiveColor, + this.secondaryActiveColor, + this.thumbColor, + this.overlayColor, + this.semanticFormatterCallback, + this.focusNode, + this.autofocus = false, + this.allowedInteraction, + }) : _sliderType = _SliderType.adaptive, + assert(min <= max), + assert(value >= min && value <= max, + 'Value $value is not between minimum $min and maximum $max'), + assert(secondaryTrackValue == null || (secondaryTrackValue >= min && secondaryTrackValue <= max), + 'SecondaryValue $secondaryTrackValue is not between $min and $max'), + assert(divisions == null || divisions > 0); + + /// The currently selected value for this slider. + /// + /// The slider's thumb is drawn at a position that corresponds to this value. + final double value; + + /// The secondary track value for this slider. + /// + /// If not null, a secondary track using [Slider.secondaryActiveColor] color + /// is drawn between the thumb and this value, over the inactive track. + /// + /// If less than [Slider.value], then the secondary track is not shown. + /// + /// It can be ideal for media scenarios such as showing the buffering progress + /// while the [Slider.value] shows the play progress. + final double? secondaryTrackValue; + + /// Called during a drag when the user is selecting a new value for the slider + /// by dragging. + /// + /// The slider passes the new value to the callback but does not actually + /// change state until the parent widget rebuilds the slider with the new + /// value. + /// + /// If null, the slider will be displayed as disabled. + /// + /// The callback provided to onChanged should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// {@tool snippet} + /// + /// ```dart + /// Slider( + /// value: _duelCommandment.toDouble(), + /// min: 1.0, + /// max: 10.0, + /// divisions: 10, + /// label: '$_duelCommandment', + /// onChanged: (double newValue) { + /// setState(() { + /// _duelCommandment = newValue.round(); + /// }); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [onChangeStart] for a callback that is called when the user starts + /// changing the value. + /// * [onChangeEnd] for a callback that is called when the user stops + /// changing the value. + final ValueChanged<double>? onChanged; + + /// Called when the user starts selecting a new value for the slider. + /// + /// This callback shouldn't be used to update the slider [value] (use + /// [onChanged] for that), but rather to be notified when the user has started + /// selecting a new value by starting a drag or with a tap. + /// + /// The value passed will be the last [value] that the slider had before the + /// change began. + /// + /// {@tool snippet} + /// + /// ```dart + /// Slider( + /// value: _duelCommandment.toDouble(), + /// min: 1.0, + /// max: 10.0, + /// divisions: 10, + /// label: '$_duelCommandment', + /// onChanged: (double newValue) { + /// setState(() { + /// _duelCommandment = newValue.round(); + /// }); + /// }, + /// onChangeStart: (double startValue) { + /// print('Started change at $startValue'); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [onChangeEnd] for a callback that is called when the value change is + /// complete. + final ValueChanged<double>? onChangeStart; + + /// Called when the user is done selecting a new value for the slider. + /// + /// This callback shouldn't be used to update the slider [value] (use + /// [onChanged] for that), but rather to know when the user has completed + /// selecting a new [value] by ending a drag or a click. + /// + /// {@tool snippet} + /// + /// ```dart + /// Slider( + /// value: _duelCommandment.toDouble(), + /// min: 1.0, + /// max: 10.0, + /// divisions: 10, + /// label: '$_duelCommandment', + /// onChanged: (double newValue) { + /// setState(() { + /// _duelCommandment = newValue.round(); + /// }); + /// }, + /// onChangeEnd: (double newValue) { + /// print('Ended change on $newValue'); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [onChangeStart] for a callback that is called when a value change + /// begins. + final ValueChanged<double>? onChangeEnd; + + /// The minimum value the user can select. + /// + /// Defaults to 0.0. Must be less than or equal to [max]. + /// + /// If the [max] is equal to the [min], then the slider is disabled. + final double min; + + /// The maximum value the user can select. + /// + /// Defaults to 1.0. Must be greater than or equal to [min]. + /// + /// If the [max] is equal to the [min], then the slider is disabled. + final double max; + + /// The number of discrete divisions. + /// + /// Typically used with [label] to show the current discrete value. + /// + /// If null, the slider is continuous. + final int? divisions; + + /// A label to show above the slider when the slider is active and + /// [SliderThemeData.showValueIndicator] is satisfied. + /// + /// It is used to display the value of a discrete slider, and it is displayed + /// as part of the value indicator shape. + /// + /// The label is rendered using the active [ThemeData]'s [TextTheme.bodyLarge] + /// text style, with the theme data's [ColorScheme.onPrimary] color. The + /// label's text style can be overridden with + /// [SliderThemeData.valueIndicatorTextStyle]. + /// + /// If null, then the value indicator will not be displayed. + /// + /// Ignored if this slider is created with [Slider.adaptive]. + /// + /// See also: + /// + /// * [SliderComponentShape] for how to create a custom value indicator + /// shape. + final String? label; + + /// The color to use for the portion of the slider track that is active. + /// + /// The "active" side of the slider is the side between the thumb and the + /// minimum value. + /// + /// If null, [SliderThemeData.activeTrackColor] of the ambient + /// [SliderTheme] is used. If that is null, [ColorScheme.primary] of the + /// surrounding [ThemeData] is used. + /// + /// Using a [SliderTheme] gives much more fine-grained control over the + /// appearance of various components of the slider. + final Color? activeColor; + + /// The color for the inactive portion of the slider track. + /// + /// The "inactive" side of the slider is the side between the thumb and the + /// maximum value. + /// + /// If null, [SliderThemeData.inactiveTrackColor] of the ambient [SliderTheme] + /// is used. If that is null and [ThemeData.useMaterial3] is true, + /// [ColorScheme.surfaceVariant] will be used, otherwise [ColorScheme.primary] + /// with an opacity of 0.24 will be used. + /// + /// Using a [SliderTheme] gives much more fine-grained control over the + /// appearance of various components of the slider. + /// + /// Ignored if this slider is created with [Slider.adaptive]. + final Color? inactiveColor; + + /// The color to use for the portion of the slider track between the thumb and + /// the [Slider.secondaryTrackValue]. + /// + /// Defaults to the [SliderThemeData.secondaryActiveTrackColor] of the current + /// [SliderTheme]. + /// + /// If that is also null, defaults to [ColorScheme.primary] with an + /// opacity of 0.54. + /// + /// Using a [SliderTheme] gives much more fine-grained control over the + /// appearance of various components of the slider. + /// + /// Ignored if this slider is created with [Slider.adaptive]. + final Color? secondaryActiveColor; + + /// The color of the thumb. + /// + /// If this color is null, [Slider] will use [activeColor], If [activeColor] + /// is also null, [Slider] will use [SliderThemeData.thumbColor]. + /// + /// If that is also null, defaults to [ColorScheme.primary]. + /// + /// * [CupertinoSlider] will have a white thumb + /// (like the native default iOS slider). + final Color? thumbColor; + + /// The highlight color that's typically used to indicate that + /// the slider thumb is focused, hovered, or dragged. + /// + /// If this property is null, [Slider] will use [activeColor] with + /// an opacity of 0.12, If null, [SliderThemeData.overlayColor] + /// will be used. + /// + /// If that is also null, If [ThemeData.useMaterial3] is true, + /// Slider will use [ColorScheme.primary] with an opacity of 0.08 when + /// slider thumb is hovered and with an opacity of 0.12 when slider thumb + /// is focused or dragged, If [ThemeData.useMaterial3] is false, defaults + /// to [ColorScheme.primary] with an opacity of 0.12. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@template flutter.material.slider.mouseCursor} + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.dragged]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// {@endtemplate} + /// + /// If null, then the value of [SliderThemeData.mouseCursor] is used. If that + /// is also null, then [MaterialStateMouseCursor.clickable] is used. + /// + /// See also: + /// + /// * [MaterialStateMouseCursor], which can be used to create a [MouseCursor] + /// that is also a [MaterialStateProperty<MouseCursor>]. + final MouseCursor? mouseCursor; + + /// The callback used to create a semantic value from a slider value. + /// + /// Defaults to formatting values as a percentage. + /// + /// This is used by accessibility frameworks like TalkBack on Android to + /// inform users what the currently selected value is with more context. + /// + /// {@tool snippet} + /// + /// In the example below, a slider for currency values is configured to + /// announce a value with a currency label. + /// + /// ```dart + /// Slider( + /// value: _dollars.toDouble(), + /// min: 20.0, + /// max: 330.0, + /// label: '$_dollars dollars', + /// onChanged: (double newValue) { + /// setState(() { + /// _dollars = newValue.round(); + /// }); + /// }, + /// semanticFormatterCallback: (double newValue) { + /// return '${newValue.round()} dollars'; + /// } + /// ) + /// ``` + /// {@end-tool} + /// + /// Ignored if this slider is created with [Slider.adaptive] + final SemanticFormatterCallback? semanticFormatterCallback; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// Allowed way for the user to interact with the [Slider]. + /// + /// For example, if this is set to [SliderInteraction.tapOnly], the user can + /// interact with the slider only by tapping anywhere on the track. Sliding + /// will have no effect. + /// + /// Defaults to [SliderInteraction.tapAndSlide]. + final SliderInteraction? allowedInteraction; + + final _SliderType _sliderType ; + + @override + State<Slider> createState() => _SliderState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('value', value)); + properties.add(DoubleProperty('secondaryTrackValue', secondaryTrackValue)); + properties.add(ObjectFlagProperty<ValueChanged<double>>('onChanged', onChanged, ifNull: 'disabled')); + properties.add(ObjectFlagProperty<ValueChanged<double>>.has('onChangeStart', onChangeStart)); + properties.add(ObjectFlagProperty<ValueChanged<double>>.has('onChangeEnd', onChangeEnd)); + properties.add(DoubleProperty('min', min)); + properties.add(DoubleProperty('max', max)); + properties.add(IntProperty('divisions', divisions)); + properties.add(StringProperty('label', label)); + properties.add(ColorProperty('activeColor', activeColor)); + properties.add(ColorProperty('inactiveColor', inactiveColor)); + properties.add(ColorProperty('secondaryActiveColor', secondaryActiveColor)); + properties.add(ObjectFlagProperty<ValueChanged<double>>.has('semanticFormatterCallback', semanticFormatterCallback)); + properties.add(ObjectFlagProperty<FocusNode>.has('focusNode', focusNode)); + properties.add(FlagProperty('autofocus', value: autofocus, ifTrue: 'autofocus')); + } +} + +class _SliderState extends State<Slider> with TickerProviderStateMixin { + static const Duration enableAnimationDuration = Duration(milliseconds: 75); + static const Duration valueIndicatorAnimationDuration = Duration(milliseconds: 100); + + // Animation controller that is run when the overlay (a.k.a radial reaction) + // is shown in response to user interaction. + late AnimationController overlayController; + // Animation controller that is run when the value indicator is being shown + // or hidden. + late AnimationController valueIndicatorController; + // Animation controller that is run when enabling/disabling the slider. + late AnimationController enableController; + // Animation controller that is run when transitioning between one value + // and the next on a discrete slider. + late AnimationController positionController; + Timer? interactionTimer; + + final GlobalKey _renderObjectKey = GlobalKey(); + + // Keyboard mapping for a focused slider. + static const Map<ShortcutActivator, Intent> _traditionalNavShortcutMap = <ShortcutActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.arrowUp): _AdjustSliderIntent.up(), + SingleActivator(LogicalKeyboardKey.arrowDown): _AdjustSliderIntent.down(), + SingleActivator(LogicalKeyboardKey.arrowLeft): _AdjustSliderIntent.left(), + SingleActivator(LogicalKeyboardKey.arrowRight): _AdjustSliderIntent.right(), + }; + + // Keyboard mapping for a focused slider when using directional navigation. + // The vertical inputs are not handled to allow navigating out of the slider. + static const Map<ShortcutActivator, Intent> _directionalNavShortcutMap = <ShortcutActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.arrowLeft): _AdjustSliderIntent.left(), + SingleActivator(LogicalKeyboardKey.arrowRight): _AdjustSliderIntent.right(), + }; + + // Action mapping for a focused slider. + late Map<Type, Action<Intent>> _actionMap; + + bool get _enabled => widget.onChanged != null; + // Value Indicator Animation that appears on the Overlay. + PaintValueIndicator? paintValueIndicator; + + bool _dragging = false; + + FocusNode? _focusNode; + FocusNode get focusNode => widget.focusNode ?? _focusNode!; + + @override + void initState() { + super.initState(); + overlayController = AnimationController( + duration: kRadialReactionDuration, + vsync: this, + ); + valueIndicatorController = AnimationController( + duration: valueIndicatorAnimationDuration, + vsync: this, + ); + enableController = AnimationController( + duration: enableAnimationDuration, + vsync: this, + ); + positionController = AnimationController( + duration: Duration.zero, + vsync: this, + ); + enableController.value = widget.onChanged != null ? 1.0 : 0.0; + positionController.value = _convert(widget.value); + _actionMap = <Type, Action<Intent>>{ + _AdjustSliderIntent: CallbackAction<_AdjustSliderIntent>( + onInvoke: _actionHandler, + ), + }; + if (widget.focusNode == null) { + // Only create a new node if the widget doesn't have one. + _focusNode ??= FocusNode(); + } + } + + @override + void dispose() { + interactionTimer?.cancel(); + overlayController.dispose(); + valueIndicatorController.dispose(); + enableController.dispose(); + positionController.dispose(); + overlayEntry?.remove(); + overlayEntry?.dispose(); + overlayEntry = null; + _focusNode?.dispose(); + super.dispose(); + } + + void _handleChanged(double value) { + assert(widget.onChanged != null); + final double lerpValue = _lerp(value); + if (lerpValue != widget.value) { + widget.onChanged!(lerpValue); + } + } + + void _handleDragStart(double value) { + _dragging = true; + widget.onChangeStart?.call(_lerp(value)); + } + + void _handleDragEnd(double value) { + _dragging = false; + widget.onChangeEnd?.call(_lerp(value)); + } + + void _actionHandler(_AdjustSliderIntent intent) { + final _RenderSlider renderSlider = _renderObjectKey.currentContext!.findRenderObject()! as _RenderSlider; + final TextDirection textDirection = Directionality.of(_renderObjectKey.currentContext!); + + switch (intent.type) { + case _SliderAdjustmentType.right: + switch (textDirection) { + case TextDirection.rtl: + renderSlider.decreaseAction(); + case TextDirection.ltr: + renderSlider.increaseAction(); + } + case _SliderAdjustmentType.left: + switch (textDirection) { + case TextDirection.rtl: + renderSlider.increaseAction(); + case TextDirection.ltr: + renderSlider.decreaseAction(); + } + case _SliderAdjustmentType.up: + renderSlider.increaseAction(); + case _SliderAdjustmentType.down: + renderSlider.decreaseAction(); + } + } + + bool _focused = false; + void _handleFocusHighlightChanged(bool focused) { + if (focused != _focused) { + setState(() { _focused = focused; }); + } + } + + bool _hovering = false; + void _handleHoverChanged(bool hovering) { + if (hovering != _hovering) { + setState(() { _hovering = hovering; }); + } + } + + // Returns a number between min and max, proportional to value, which must + // be between 0.0 and 1.0. + double _lerp(double value) { + assert(value >= 0.0); + assert(value <= 1.0); + return value * (widget.max - widget.min) + widget.min; + } + + double _discretize(double value) { + assert(widget.divisions != null); + assert(value >= 0.0 && value <= 1.0); + + final int divisions = widget.divisions!; + return (value * divisions).round() / divisions; + } + + double _convert(double value) { + double ret = _unlerp(value); + if (widget.divisions != null) { + ret = _discretize(ret); + } + return ret; + } + + // Returns a number between 0.0 and 1.0, given a value between min and max. + double _unlerp(double value) { + assert(value <= widget.max); + assert(value >= widget.min); + return widget.max > widget.min ? (value - widget.min) / (widget.max - widget.min) : 0.0; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMediaQuery(context)); + + switch (widget._sliderType) { + case _SliderType.material: + return _buildMaterialSlider(context); + + case _SliderType.adaptive: { + final ThemeData theme = Theme.of(context); + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return _buildMaterialSlider(context); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return _buildCupertinoSlider(context); + } + } + } + } + + Widget _buildMaterialSlider(BuildContext context) { + final ThemeData theme = Theme.of(context); + SliderThemeData sliderTheme = SliderTheme.of(context); + final SliderThemeData defaults = theme.useMaterial3 ? _SliderDefaultsM3(context) : _SliderDefaultsM2(context); + + // If the widget has active or inactive colors specified, then we plug them + // in to the slider theme as best we can. If the developer wants more + // control than that, then they need to use a SliderTheme. The default + // colors come from the ThemeData.colorScheme. These colors, along with + // the default shapes and text styles are aligned to the Material + // Guidelines. + + const SliderTrackShape defaultTrackShape = RoundedRectSliderTrackShape(); + const SliderTickMarkShape defaultTickMarkShape = RoundSliderTickMarkShape(); + const SliderComponentShape defaultOverlayShape = RoundSliderOverlayShape(); + const SliderComponentShape defaultThumbShape = RoundSliderThumbShape(); + final SliderComponentShape defaultValueIndicatorShape = defaults.valueIndicatorShape!; + const ShowValueIndicator defaultShowValueIndicator = ShowValueIndicator.onlyForDiscrete; + const SliderInteraction defaultAllowedInteraction = SliderInteraction.tapAndSlide; + + final Set<MaterialState> states = <MaterialState>{ + if (!_enabled) MaterialState.disabled, + if (_hovering) MaterialState.hovered, + if (_focused) MaterialState.focused, + if (_dragging) MaterialState.dragged, + }; + + // The value indicator's color is not the same as the thumb and active track + // (which can be defined by activeColor) if the + // RectangularSliderValueIndicatorShape is used. In all other cases, the + // value indicator is assumed to be the same as the active color. + final SliderComponentShape valueIndicatorShape = sliderTheme.valueIndicatorShape ?? defaultValueIndicatorShape; + final Color valueIndicatorColor; + if (valueIndicatorShape is RectangularSliderValueIndicatorShape) { + valueIndicatorColor = sliderTheme.valueIndicatorColor ?? Color.alphaBlend(theme.colorScheme.onSurface.withOpacity(0.60), theme.colorScheme.surface.withOpacity(0.90)); + } else { + valueIndicatorColor = widget.activeColor ?? sliderTheme.valueIndicatorColor ?? theme.colorScheme.primary; + } + + Color? effectiveOverlayColor() { + return widget.overlayColor?.resolve(states) + ?? widget.activeColor?.withOpacity(0.12) + ?? MaterialStateProperty.resolveAs<Color?>(sliderTheme.overlayColor, states) + ?? MaterialStateProperty.resolveAs<Color?>(defaults.overlayColor, states); + } + + sliderTheme = sliderTheme.copyWith( + trackHeight: sliderTheme.trackHeight ?? defaults.trackHeight, + activeTrackColor: widget.activeColor ?? sliderTheme.activeTrackColor ?? defaults.activeTrackColor, + inactiveTrackColor: widget.inactiveColor ?? sliderTheme.inactiveTrackColor ?? defaults.inactiveTrackColor, + secondaryActiveTrackColor: widget.secondaryActiveColor ?? sliderTheme.secondaryActiveTrackColor ?? defaults.secondaryActiveTrackColor, + disabledActiveTrackColor: sliderTheme.disabledActiveTrackColor ?? defaults.disabledActiveTrackColor, + disabledInactiveTrackColor: sliderTheme.disabledInactiveTrackColor ?? defaults.disabledInactiveTrackColor, + disabledSecondaryActiveTrackColor: sliderTheme.disabledSecondaryActiveTrackColor ?? defaults.disabledSecondaryActiveTrackColor, + activeTickMarkColor: widget.inactiveColor ?? sliderTheme.activeTickMarkColor ?? defaults.activeTickMarkColor, + inactiveTickMarkColor: widget.activeColor ?? sliderTheme.inactiveTickMarkColor ?? defaults.inactiveTickMarkColor, + disabledActiveTickMarkColor: sliderTheme.disabledActiveTickMarkColor ?? defaults.disabledActiveTickMarkColor, + disabledInactiveTickMarkColor: sliderTheme.disabledInactiveTickMarkColor ?? defaults.disabledInactiveTickMarkColor, + thumbColor: widget.thumbColor ?? widget.activeColor ?? sliderTheme.thumbColor ?? defaults.thumbColor, + disabledThumbColor: sliderTheme.disabledThumbColor ?? defaults.disabledThumbColor, + overlayColor: effectiveOverlayColor(), + valueIndicatorColor: valueIndicatorColor, + trackShape: sliderTheme.trackShape ?? defaultTrackShape, + tickMarkShape: sliderTheme.tickMarkShape ?? defaultTickMarkShape, + thumbShape: sliderTheme.thumbShape ?? defaultThumbShape, + overlayShape: sliderTheme.overlayShape ?? defaultOverlayShape, + valueIndicatorShape: valueIndicatorShape, + showValueIndicator: sliderTheme.showValueIndicator ?? defaultShowValueIndicator, + valueIndicatorTextStyle: sliderTheme.valueIndicatorTextStyle ?? defaults.valueIndicatorTextStyle, + ); + final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor?>(widget.mouseCursor, states) + ?? sliderTheme.mouseCursor?.resolve(states) + ?? MaterialStateMouseCursor.clickable.resolve(states); + final SliderInteraction effectiveAllowedInteraction = widget.allowedInteraction + ?? sliderTheme.allowedInteraction + ?? defaultAllowedInteraction; + + // This size is used as the max bounds for the painting of the value + // indicators It must be kept in sync with the function with the same name + // in range_slider.dart. + Size screenSize() => MediaQuery.sizeOf(context); + + VoidCallback? handleDidGainAccessibilityFocus; + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + break; + case TargetPlatform.windows: + handleDidGainAccessibilityFocus = () { + // Automatically activate the slider when it receives a11y focus. + if (!focusNode.hasFocus && focusNode.canRequestFocus) { + focusNode.requestFocus(); + } + }; + } + + final Map<ShortcutActivator, Intent> shortcutMap; + switch (MediaQuery.navigationModeOf(context)) { + case NavigationMode.directional: + shortcutMap = _directionalNavShortcutMap; + case NavigationMode.traditional: + shortcutMap = _traditionalNavShortcutMap; + } + + final double textScaleFactor = theme.useMaterial3 + // TODO(tahatesser): This is an eye-balled value. + // This needs to be updated when accessibility + // guidelines are available on the material specs page + // https://m3.material.io/components/sliders/accessibility. + ? MediaQuery.textScalerOf(context).clamp(maxScaleFactor: 1.3).textScaleFactor + : MediaQuery.textScalerOf(context).textScaleFactor; + + return Semantics( + container: true, + slider: true, + onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus, + child: FocusableActionDetector( + actions: _actionMap, + shortcuts: shortcutMap, + focusNode: focusNode, + autofocus: widget.autofocus, + enabled: _enabled, + onShowFocusHighlight: _handleFocusHighlightChanged, + onShowHoverHighlight: _handleHoverChanged, + mouseCursor: effectiveMouseCursor, + child: CompositedTransformTarget( + link: _layerLink, + child: _SliderRenderObjectWidget( + key: _renderObjectKey, + value: _convert(widget.value), + secondaryTrackValue: (widget.secondaryTrackValue != null) ? _convert(widget.secondaryTrackValue!) : null, + divisions: widget.divisions, + label: widget.label, + sliderTheme: sliderTheme, + textScaleFactor: textScaleFactor, + screenSize: screenSize(), + onChanged: (widget.onChanged != null) && (widget.max > widget.min) ? _handleChanged : null, + onChangeStart: _handleDragStart, + onChangeEnd: _handleDragEnd, + state: this, + semanticFormatterCallback: widget.semanticFormatterCallback, + hasFocus: _focused, + hovering: _hovering, + allowedInteraction: effectiveAllowedInteraction, + ), + ), + ), + ); + } + + Widget _buildCupertinoSlider(BuildContext context) { + // The render box of a slider has a fixed height but takes up the available + // width. Wrapping the [CupertinoSlider] in this manner will help maintain + // the same size. + return SizedBox( + width: double.infinity, + child: CupertinoSlider( + value: widget.value, + onChanged: widget.onChanged, + onChangeStart: widget.onChangeStart, + onChangeEnd: widget.onChangeEnd, + min: widget.min, + max: widget.max, + divisions: widget.divisions, + activeColor: widget.activeColor, + thumbColor: widget.thumbColor ?? CupertinoColors.white, + ), + ); + } + final LayerLink _layerLink = LayerLink(); + + OverlayEntry? overlayEntry; + + void showValueIndicator() { + if (overlayEntry == null) { + overlayEntry = OverlayEntry( + builder: (BuildContext context) { + return CompositedTransformFollower( + link: _layerLink, + child: _ValueIndicatorRenderObjectWidget( + state: this, + ), + ); + }, + ); + Overlay.of(context, debugRequiredFor: widget).insert(overlayEntry!); + } + } +} + +class _SliderRenderObjectWidget extends LeafRenderObjectWidget { + const _SliderRenderObjectWidget({ + super.key, + required this.value, + required this.secondaryTrackValue, + required this.divisions, + required this.label, + required this.sliderTheme, + required this.textScaleFactor, + required this.screenSize, + required this.onChanged, + required this.onChangeStart, + required this.onChangeEnd, + required this.state, + required this.semanticFormatterCallback, + required this.hasFocus, + required this.hovering, + required this.allowedInteraction, + }); + + final double value; + final double? secondaryTrackValue; + final int? divisions; + final String? label; + final SliderThemeData sliderTheme; + final double textScaleFactor; + final Size screenSize; + final ValueChanged<double>? onChanged; + final ValueChanged<double>? onChangeStart; + final ValueChanged<double>? onChangeEnd; + final SemanticFormatterCallback? semanticFormatterCallback; + final _SliderState state; + final bool hasFocus; + final bool hovering; + final SliderInteraction allowedInteraction; + + @override + _RenderSlider createRenderObject(BuildContext context) { + return _RenderSlider( + value: value, + secondaryTrackValue: secondaryTrackValue, + divisions: divisions, + label: label, + sliderTheme: sliderTheme, + textScaleFactor: textScaleFactor, + screenSize: screenSize, + onChanged: onChanged, + onChangeStart: onChangeStart, + onChangeEnd: onChangeEnd, + state: state, + textDirection: Directionality.of(context), + semanticFormatterCallback: semanticFormatterCallback, + platform: Theme.of(context).platform, + hasFocus: hasFocus, + hovering: hovering, + gestureSettings: MediaQuery.gestureSettingsOf(context), + allowedInteraction: allowedInteraction, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderSlider renderObject) { + renderObject + // We should update the `divisions` ahead of `value`, because the `value` + // setter dependent on the `divisions`. + ..divisions = divisions + ..value = value + ..secondaryTrackValue = secondaryTrackValue + ..label = label + ..sliderTheme = sliderTheme + ..textScaleFactor = textScaleFactor + ..screenSize = screenSize + ..onChanged = onChanged + ..onChangeStart = onChangeStart + ..onChangeEnd = onChangeEnd + ..textDirection = Directionality.of(context) + ..semanticFormatterCallback = semanticFormatterCallback + ..platform = Theme.of(context).platform + ..hasFocus = hasFocus + ..hovering = hovering + ..gestureSettings = MediaQuery.gestureSettingsOf(context) + ..allowedInteraction = allowedInteraction; + // Ticker provider cannot change since there's a 1:1 relationship between + // the _SliderRenderObjectWidget object and the _SliderState object. + } +} + +class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { + _RenderSlider({ + required double value, + required double? secondaryTrackValue, + required int? divisions, + required String? label, + required SliderThemeData sliderTheme, + required double textScaleFactor, + required Size screenSize, + required TargetPlatform platform, + required ValueChanged<double>? onChanged, + required SemanticFormatterCallback? semanticFormatterCallback, + required this.onChangeStart, + required this.onChangeEnd, + required _SliderState state, + required TextDirection textDirection, + required bool hasFocus, + required bool hovering, + required DeviceGestureSettings gestureSettings, + required SliderInteraction allowedInteraction, + }) : assert(value >= 0.0 && value <= 1.0), + assert(secondaryTrackValue == null || (secondaryTrackValue >= 0.0 && secondaryTrackValue <= 1.0)), + _platform = platform, + _semanticFormatterCallback = semanticFormatterCallback, + _label = label, + _value = value, + _secondaryTrackValue = secondaryTrackValue, + _divisions = divisions, + _sliderTheme = sliderTheme, + _textScaleFactor = textScaleFactor, + _screenSize = screenSize, + _onChanged = onChanged, + _state = state, + _textDirection = textDirection, + _hasFocus = hasFocus, + _hovering = hovering, + _allowedInteraction = allowedInteraction { + _updateLabelPainter(); + final GestureArenaTeam team = GestureArenaTeam(); + _drag = HorizontalDragGestureRecognizer() + ..team = team + ..onStart = _handleDragStart + ..onUpdate = _handleDragUpdate + ..onEnd = _handleDragEnd + ..onCancel = _endInteraction + ..gestureSettings = gestureSettings; + _tap = TapGestureRecognizer() + ..team = team + ..onTapDown = _handleTapDown + ..onTapUp = _handleTapUp + ..gestureSettings = gestureSettings; + _overlayAnimation = CurvedAnimation( + parent: _state.overlayController, + curve: Curves.fastOutSlowIn, + ); + _valueIndicatorAnimation = CurvedAnimation( + parent: _state.valueIndicatorController, + curve: Curves.fastOutSlowIn, + )..addStatusListener((AnimationStatus status) { + if (status == AnimationStatus.dismissed) { + _state.overlayEntry?.remove(); + _state.overlayEntry?.dispose(); + _state.overlayEntry = null; + } + }); + _enableAnimation = CurvedAnimation( + parent: _state.enableController, + curve: Curves.easeInOut, + ); + } + static const Duration _positionAnimationDuration = Duration(milliseconds: 75); + static const Duration _minimumInteractionTime = Duration(milliseconds: 500); + + // This value is the touch target, 48, multiplied by 3. + static const double _minPreferredTrackWidth = 144.0; + + // Compute the largest width and height needed to paint the slider shapes, + // other than the track shape. It is assumed that these shapes are vertically + // centered on the track. + double get _maxSliderPartWidth => _sliderPartSizes.map((Size size) => size.width).reduce(math.max); + double get _maxSliderPartHeight => _sliderPartSizes.map((Size size) => size.height).reduce(math.max); + List<Size> get _sliderPartSizes => <Size>[ + _sliderTheme.overlayShape!.getPreferredSize(isInteractive, isDiscrete), + _sliderTheme.thumbShape!.getPreferredSize(isInteractive, isDiscrete), + _sliderTheme.tickMarkShape!.getPreferredSize(isEnabled: isInteractive, sliderTheme: sliderTheme), + ]; + double get _minPreferredTrackHeight => _sliderTheme.trackHeight!; + + final _SliderState _state; + late Animation<double> _overlayAnimation; + late Animation<double> _valueIndicatorAnimation; + late Animation<double> _enableAnimation; + final TextPainter _labelPainter = TextPainter(); + late HorizontalDragGestureRecognizer _drag; + late TapGestureRecognizer _tap; + bool _active = false; + double _currentDragValue = 0.0; + Rect? overlayRect; + + // This rect is used in gesture calculations, where the gesture coordinates + // are relative to the sliders origin. Therefore, the offset is passed as + // (0,0). + Rect get _trackRect => _sliderTheme.trackShape!.getPreferredRect( + parentBox: this, + sliderTheme: _sliderTheme, + isDiscrete: false, + ); + + bool get isInteractive => onChanged != null; + + bool get isDiscrete => divisions != null && divisions! > 0; + + double get value => _value; + double _value; + set value(double newValue) { + assert(newValue >= 0.0 && newValue <= 1.0); + final double convertedValue = isDiscrete ? _discretize(newValue) : newValue; + if (convertedValue == _value) { + return; + } + _value = convertedValue; + if (isDiscrete) { + // Reset the duration to match the distance that we're traveling, so that + // whatever the distance, we still do it in _positionAnimationDuration, + // and if we get re-targeted in the middle, it still takes that long to + // get to the new location. + final double distance = (_value - _state.positionController.value).abs(); + _state.positionController.duration = distance != 0.0 + ? _positionAnimationDuration * (1.0 / distance) + : Duration.zero; + _state.positionController.animateTo(convertedValue, curve: Curves.easeInOut); + } else { + _state.positionController.value = convertedValue; + } + markNeedsSemanticsUpdate(); + } + + double? get secondaryTrackValue => _secondaryTrackValue; + double? _secondaryTrackValue; + set secondaryTrackValue(double? newValue) { + assert(newValue == null || (newValue >= 0.0 && newValue <= 1.0)); + if (newValue == _secondaryTrackValue) { + return; + } + _secondaryTrackValue = newValue; + markNeedsSemanticsUpdate(); + } + + DeviceGestureSettings? get gestureSettings => _drag.gestureSettings; + set gestureSettings(DeviceGestureSettings? gestureSettings) { + _drag.gestureSettings = gestureSettings; + _tap.gestureSettings = gestureSettings; + } + + TargetPlatform _platform; + TargetPlatform get platform => _platform; + set platform(TargetPlatform value) { + if (_platform == value) { + return; + } + _platform = value; + markNeedsSemanticsUpdate(); + } + + SemanticFormatterCallback? _semanticFormatterCallback; + SemanticFormatterCallback? get semanticFormatterCallback => _semanticFormatterCallback; + set semanticFormatterCallback(SemanticFormatterCallback? value) { + if (_semanticFormatterCallback == value) { + return; + } + _semanticFormatterCallback = value; + markNeedsSemanticsUpdate(); + } + + int? get divisions => _divisions; + int? _divisions; + set divisions(int? value) { + if (value == _divisions) { + return; + } + _divisions = value; + markNeedsPaint(); + } + + String? get label => _label; + String? _label; + set label(String? value) { + if (value == _label) { + return; + } + _label = value; + _updateLabelPainter(); + } + + SliderThemeData get sliderTheme => _sliderTheme; + SliderThemeData _sliderTheme; + set sliderTheme(SliderThemeData value) { + if (value == _sliderTheme) { + return; + } + _sliderTheme = value; + _updateLabelPainter(); + } + + double get textScaleFactor => _textScaleFactor; + double _textScaleFactor; + set textScaleFactor(double value) { + if (value == _textScaleFactor) { + return; + } + _textScaleFactor = value; + _updateLabelPainter(); + } + + Size get screenSize => _screenSize; + Size _screenSize; + set screenSize(Size value) { + if (value == _screenSize) { + return; + } + _screenSize = value; + markNeedsPaint(); + } + + ValueChanged<double>? get onChanged => _onChanged; + ValueChanged<double>? _onChanged; + set onChanged(ValueChanged<double>? value) { + if (value == _onChanged) { + return; + } + final bool wasInteractive = isInteractive; + _onChanged = value; + if (wasInteractive != isInteractive) { + if (isInteractive) { + _state.enableController.forward(); + } else { + _state.enableController.reverse(); + } + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + ValueChanged<double>? onChangeStart; + ValueChanged<double>? onChangeEnd; + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (value == _textDirection) { + return; + } + _textDirection = value; + _updateLabelPainter(); + } + + /// True if this slider has the input focus. + bool get hasFocus => _hasFocus; + bool _hasFocus; + set hasFocus(bool value) { + if (value == _hasFocus) { + return; + } + _hasFocus = value; + _updateForFocus(_hasFocus); + markNeedsSemanticsUpdate(); + } + + /// True if this slider is being hovered over by a pointer. + bool get hovering => _hovering; + bool _hovering; + set hovering(bool value) { + if (value == _hovering) { + return; + } + _hovering = value; + _updateForHover(_hovering); + } + + /// True if the slider is interactive and the slider thumb is being + /// hovered over by a pointer. + bool _hoveringThumb = false; + bool get hoveringThumb => _hoveringThumb; + set hoveringThumb(bool value) { + if (value == _hoveringThumb) { + return; + } + _hoveringThumb = value; + _updateForHover(_hovering); + } + + SliderInteraction _allowedInteraction; + SliderInteraction get allowedInteraction => _allowedInteraction; + set allowedInteraction(SliderInteraction value) { + if (value == _allowedInteraction) { + return; + } + _allowedInteraction = value; + markNeedsSemanticsUpdate(); + } + + void _updateForFocus(bool focused) { + if (focused) { + _state.overlayController.forward(); + if (showValueIndicator) { + _state.valueIndicatorController.forward(); + } + } else { + _state.overlayController.reverse(); + if (showValueIndicator) { + _state.valueIndicatorController.reverse(); + } + } + } + + void _updateForHover(bool hovered) { + // Only show overlay when pointer is hovering the thumb. + if (hovered && hoveringThumb) { + _state.overlayController.forward(); + } else { + // Only remove overlay when Slider is inactive and unfocused. + if (!_active && !hasFocus) { + _state.overlayController.reverse(); + } + } + } + + bool get showValueIndicator { + switch (_sliderTheme.showValueIndicator!) { + case ShowValueIndicator.onlyForDiscrete: + return isDiscrete; + case ShowValueIndicator.onlyForContinuous: + return !isDiscrete; + case ShowValueIndicator.always: + return true; + case ShowValueIndicator.never: + return false; + } + } + + double get _adjustmentUnit { + switch (_platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + // Matches iOS implementation of material slider. + return 0.1; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + // Matches Android implementation of material slider. + return 0.05; + } + } + + void _updateLabelPainter() { + if (label != null) { + _labelPainter + ..text = TextSpan( + style: _sliderTheme.valueIndicatorTextStyle, + text: label, + ) + ..textDirection = textDirection + ..textScaleFactor = textScaleFactor + ..layout(); + } else { + _labelPainter.text = null; + } + // Changing the textDirection can result in the layout changing, because the + // bidi algorithm might line up the glyphs differently which can result in + // different ligatures, different shapes, etc. So we always markNeedsLayout. + markNeedsLayout(); + } + + @override + void systemFontsDidChange() { + super.systemFontsDidChange(); + _labelPainter.markNeedsLayout(); + _updateLabelPainter(); + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _overlayAnimation.addListener(markNeedsPaint); + _valueIndicatorAnimation.addListener(markNeedsPaint); + _enableAnimation.addListener(markNeedsPaint); + _state.positionController.addListener(markNeedsPaint); + } + + @override + void detach() { + _overlayAnimation.removeListener(markNeedsPaint); + _valueIndicatorAnimation.removeListener(markNeedsPaint); + _enableAnimation.removeListener(markNeedsPaint); + _state.positionController.removeListener(markNeedsPaint); + super.detach(); + } + + @override + void dispose() { + _drag.dispose(); + _tap.dispose(); + _labelPainter.dispose(); + super.dispose(); + } + + double _getValueFromVisualPosition(double visualPosition) { + switch (textDirection) { + case TextDirection.rtl: + return 1.0 - visualPosition; + case TextDirection.ltr: + return visualPosition; + } + } + + double _getValueFromGlobalPosition(Offset globalPosition) { + final double visualPosition = (globalToLocal(globalPosition).dx - _trackRect.left) / _trackRect.width; + return _getValueFromVisualPosition(visualPosition); + } + + double _discretize(double value) { + double result = clampDouble(value, 0.0, 1.0); + if (isDiscrete) { + result = (result * divisions!).round() / divisions!; + } + return result; + } + + void _startInteraction(Offset globalPosition) { + if (!_state.mounted) { + return; + } + _state.showValueIndicator(); + if (!_active && isInteractive) { + switch (allowedInteraction) { + case SliderInteraction.tapAndSlide: + case SliderInteraction.tapOnly: + _active = true; + _currentDragValue = _getValueFromGlobalPosition(globalPosition); + case SliderInteraction.slideThumb: + if (_isPointerOnOverlay(globalPosition)) { + _active = true; + _currentDragValue = value; + } + case SliderInteraction.slideOnly: + onChangeStart?.call(_discretize(value)); + } + + if (_active) { + // We supply the *current* value as the start location, so that if we have + // a tap, it consists of a call to onChangeStart with the previous value and + // a call to onChangeEnd with the new value. + onChangeStart?.call(_discretize(value)); + onChanged!(_discretize(_currentDragValue)); + _state.overlayController.forward(); + if (showValueIndicator) { + _state.valueIndicatorController.forward(); + _state.interactionTimer?.cancel(); + _state.interactionTimer = Timer(_minimumInteractionTime * timeDilation, () { + _state.interactionTimer = null; + if (!_active && _state.valueIndicatorController.status == AnimationStatus.completed) { + _state.valueIndicatorController.reverse(); + } + }); + } + } + } + } + + void _endInteraction() { + if (!_state.mounted) { + return; + } + + if (_active && _state.mounted) { + onChangeEnd?.call(_discretize(_currentDragValue)); + _active = false; + _currentDragValue = 0.0; + _state.overlayController.reverse(); + if (showValueIndicator && _state.interactionTimer == null) { + _state.valueIndicatorController.reverse(); + } + } + } + + void _handleDragStart(DragStartDetails details) { + _startInteraction(details.globalPosition); + } + + void _handleDragUpdate(DragUpdateDetails details) { + if (!_state.mounted) { + return; + } + + // for slide only, there is no start interaction trigger, so _active + // will be false and needs to be made true. + if (!_active && allowedInteraction == SliderInteraction.slideOnly) { + _active = true; + _currentDragValue = value; + } + + switch (allowedInteraction) { + case SliderInteraction.tapAndSlide: + case SliderInteraction.slideOnly: + case SliderInteraction.slideThumb: + if (_active && isInteractive) { + final double valueDelta = details.primaryDelta! / _trackRect.width; + switch (textDirection) { + case TextDirection.rtl: + _currentDragValue -= valueDelta; + case TextDirection.ltr: + _currentDragValue += valueDelta; + } + onChanged!(_discretize(_currentDragValue)); + } + case SliderInteraction.tapOnly: + // cannot slide (drag) as its tapOnly. + break; + } + } + + void _handleDragEnd(DragEndDetails details) { + _endInteraction(); + } + + void _handleTapDown(TapDownDetails details) { + _startInteraction(details.globalPosition); + } + + void _handleTapUp(TapUpDetails details) { + _endInteraction(); + } + + bool _isPointerOnOverlay(Offset globalPosition) { + return overlayRect!.contains(globalToLocal(globalPosition)); + } + + @override + bool hitTestSelf(Offset position) => true; + + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + if (!_state.mounted) { + return; + } + assert(debugHandleEvent(event, entry)); + if (event is PointerDownEvent && isInteractive) { + // We need to add the drag first so that it has priority. + _drag.addPointer(event); + _tap.addPointer(event); + } + if (isInteractive && overlayRect != null) { + hoveringThumb = overlayRect!.contains(event.localPosition); + } + } + + @override + double computeMinIntrinsicWidth(double height) => _minPreferredTrackWidth + _maxSliderPartWidth; + + @override + double computeMaxIntrinsicWidth(double height) => _minPreferredTrackWidth + _maxSliderPartWidth; + + @override + double computeMinIntrinsicHeight(double width) => math.max(_minPreferredTrackHeight, _maxSliderPartHeight); + + @override + double computeMaxIntrinsicHeight(double width) => math.max(_minPreferredTrackHeight, _maxSliderPartHeight); + + @override + bool get sizedByParent => true; + + @override + Size computeDryLayout(BoxConstraints constraints) { + return Size( + constraints.hasBoundedWidth ? constraints.maxWidth : _minPreferredTrackWidth + _maxSliderPartWidth, + constraints.hasBoundedHeight ? constraints.maxHeight : math.max(_minPreferredTrackHeight, _maxSliderPartHeight), + ); + } + + @override + void paint(PaintingContext context, Offset offset) { + final double value = _state.positionController.value; + final double? secondaryValue = _secondaryTrackValue; + + // The visual position is the position of the thumb from 0 to 1 from left + // to right. In left to right, this is the same as the value, but it is + // reversed for right to left text. + final double visualPosition; + final double? secondaryVisualPosition; + switch (textDirection) { + case TextDirection.rtl: + visualPosition = 1.0 - value; + secondaryVisualPosition = (secondaryValue != null) ? (1.0 - secondaryValue) : null; + case TextDirection.ltr: + visualPosition = value; + secondaryVisualPosition = (secondaryValue != null) ? secondaryValue : null; + } + + final Rect trackRect = _sliderTheme.trackShape!.getPreferredRect( + parentBox: this, + offset: offset, + sliderTheme: _sliderTheme, + isDiscrete: isDiscrete, + ); + final Offset thumbCenter = Offset(trackRect.left + visualPosition * trackRect.width, trackRect.center.dy); + if (isInteractive) { + final Size overlaySize = sliderTheme.overlayShape!.getPreferredSize(isInteractive, false); + overlayRect = Rect.fromCircle(center: thumbCenter, radius: overlaySize.width / 2.0); + } + final Offset? secondaryOffset = (secondaryVisualPosition != null) ? Offset(trackRect.left + secondaryVisualPosition * trackRect.width, trackRect.center.dy) : null; + + _sliderTheme.trackShape!.paint( + context, + offset, + parentBox: this, + sliderTheme: _sliderTheme, + enableAnimation: _enableAnimation, + textDirection: _textDirection, + thumbCenter: thumbCenter, + secondaryOffset: secondaryOffset, + isDiscrete: isDiscrete, + isEnabled: isInteractive, + ); + + if (!_overlayAnimation.isDismissed) { + _sliderTheme.overlayShape!.paint( + context, + thumbCenter, + activationAnimation: _overlayAnimation, + enableAnimation: _enableAnimation, + isDiscrete: isDiscrete, + labelPainter: _labelPainter, + parentBox: this, + sliderTheme: _sliderTheme, + textDirection: _textDirection, + value: _value, + textScaleFactor: _textScaleFactor, + sizeWithOverflow: screenSize.isEmpty ? size : screenSize, + ); + } + + if (isDiscrete) { + final double tickMarkWidth = _sliderTheme.tickMarkShape!.getPreferredSize( + isEnabled: isInteractive, + sliderTheme: _sliderTheme, + ).width; + final double padding = trackRect.height; + final double adjustedTrackWidth = trackRect.width - padding; + // If the tick marks would be too dense, don't bother painting them. + if (adjustedTrackWidth / divisions! >= 3.0 * tickMarkWidth) { + final double dy = trackRect.center.dy; + for (int i = 0; i <= divisions!; i++) { + final double value = i / divisions!; + // The ticks are mapped to be within the track, so the tick mark width + // must be subtracted from the track width. + final double dx = trackRect.left + value * adjustedTrackWidth + padding / 2; + final Offset tickMarkOffset = Offset(dx, dy); + _sliderTheme.tickMarkShape!.paint( + context, + tickMarkOffset, + parentBox: this, + sliderTheme: _sliderTheme, + enableAnimation: _enableAnimation, + textDirection: _textDirection, + thumbCenter: thumbCenter, + isEnabled: isInteractive, + ); + } + } + } + + if (isInteractive && label != null && !_valueIndicatorAnimation.isDismissed) { + if (showValueIndicator) { + _state.paintValueIndicator = (PaintingContext context, Offset offset) { + if (attached) { + _sliderTheme.valueIndicatorShape!.paint( + context, + offset + thumbCenter, + activationAnimation: _valueIndicatorAnimation, + enableAnimation: _enableAnimation, + isDiscrete: isDiscrete, + labelPainter: _labelPainter, + parentBox: this, + sliderTheme: _sliderTheme, + textDirection: _textDirection, + value: _value, + textScaleFactor: textScaleFactor, + sizeWithOverflow: screenSize.isEmpty ? size : screenSize, + ); + } + }; + } + } + + _sliderTheme.thumbShape!.paint( + context, + thumbCenter, + activationAnimation: _overlayAnimation, + enableAnimation: _enableAnimation, + isDiscrete: isDiscrete, + labelPainter: _labelPainter, + parentBox: this, + sliderTheme: _sliderTheme, + textDirection: _textDirection, + value: _value, + textScaleFactor: textScaleFactor, + sizeWithOverflow: screenSize.isEmpty ? size : screenSize, + ); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + + // The Slider widget has its own Focus widget with semantics information, + // and we want that semantics node to collect the semantics information here + // so that it's all in the same node: otherwise Talkback sees that the node + // has focusable children, and it won't focus the Slider's Focus widget + // because it thinks the Focus widget's node doesn't have anything to say + // (which it doesn't, but this child does). Aggregating the semantic + // information into one node means that Talkback will recognize that it has + // something to say and focus it when it receives keyboard focus. + // (See https://github.com/flutter/flutter/issues/57038 for context). + config.isSemanticBoundary = false; + + config.isEnabled = isInteractive; + config.textDirection = textDirection; + if (isInteractive) { + config.onIncrease = increaseAction; + config.onDecrease = decreaseAction; + } + + if (semanticFormatterCallback != null) { + config.value = semanticFormatterCallback!(_state._lerp(value)); + config.increasedValue = semanticFormatterCallback!(_state._lerp(clampDouble(value + _semanticActionUnit, 0.0, 1.0))); + config.decreasedValue = semanticFormatterCallback!(_state._lerp(clampDouble(value - _semanticActionUnit, 0.0, 1.0))); + } else { + config.value = '${(value * 100).round()}%'; + config.increasedValue = '${(clampDouble(value + _semanticActionUnit, 0.0, 1.0) * 100).round()}%'; + config.decreasedValue = '${(clampDouble(value - _semanticActionUnit, 0.0, 1.0) * 100).round()}%'; + } + } + + double get _semanticActionUnit => divisions != null ? 1.0 / divisions! : _adjustmentUnit; + + void increaseAction() { + if (isInteractive) { + onChangeStart!(currentValue); + final double increase = increaseValue(); + onChanged!(increase); + onChangeEnd!(increase); + } + } + + void decreaseAction() { + if (isInteractive) { + onChangeStart!(currentValue); + final double decrease = decreaseValue(); + onChanged!(decrease); + onChangeEnd!(decrease); + } + } + + double get currentValue { + return clampDouble(value, 0.0, 1.0); + } + + double increaseValue() { + return clampDouble(value + _semanticActionUnit, 0.0, 1.0); + } + + double decreaseValue() { + return clampDouble(value - _semanticActionUnit, 0.0, 1.0); + } +} + +class _AdjustSliderIntent extends Intent { + const _AdjustSliderIntent({ + required this.type, + }); + + const _AdjustSliderIntent.right() : type = _SliderAdjustmentType.right; + + const _AdjustSliderIntent.left() : type = _SliderAdjustmentType.left; + + const _AdjustSliderIntent.up() : type = _SliderAdjustmentType.up; + + const _AdjustSliderIntent.down() : type = _SliderAdjustmentType.down; + + final _SliderAdjustmentType type; +} + +enum _SliderAdjustmentType { + right, + left, + up, + down, +} + +class _ValueIndicatorRenderObjectWidget extends LeafRenderObjectWidget { + const _ValueIndicatorRenderObjectWidget({ + required this.state, + }); + + final _SliderState state; + + @override + _RenderValueIndicator createRenderObject(BuildContext context) { + return _RenderValueIndicator( + state: state, + ); + } + @override + void updateRenderObject(BuildContext context, _RenderValueIndicator renderObject) { + renderObject._state = state; + } +} + +class _RenderValueIndicator extends RenderBox with RelayoutWhenSystemFontsChangeMixin { + _RenderValueIndicator({ + required _SliderState state, + }) : _state = state { + _valueIndicatorAnimation = CurvedAnimation( + parent: _state.valueIndicatorController, + curve: Curves.fastOutSlowIn, + ); + } + late Animation<double> _valueIndicatorAnimation; + _SliderState _state; + + @override + bool get sizedByParent => true; + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _valueIndicatorAnimation.addListener(markNeedsPaint); + _state.positionController.addListener(markNeedsPaint); + } + + @override + void detach() { + _valueIndicatorAnimation.removeListener(markNeedsPaint); + _state.positionController.removeListener(markNeedsPaint); + super.detach(); + } + + @override + void paint(PaintingContext context, Offset offset) { + _state.paintValueIndicator?.call(context, offset); + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return constraints.smallest; + } +} + +class _SliderDefaultsM2 extends SliderThemeData { + _SliderDefaultsM2(this.context) + : _colors = Theme.of(context).colorScheme, + super(trackHeight: 4.0); + + final BuildContext context; + final ColorScheme _colors; + + @override + Color? get activeTrackColor => _colors.primary; + + @override + Color? get inactiveTrackColor => _colors.primary.withOpacity(0.24); + + @override + Color? get secondaryActiveTrackColor => _colors.primary.withOpacity(0.54); + + @override + Color? get disabledActiveTrackColor => _colors.onSurface.withOpacity(0.32); + + @override + Color? get disabledInactiveTrackColor => _colors.onSurface.withOpacity(0.12); + + @override + Color? get disabledSecondaryActiveTrackColor => _colors.onSurface.withOpacity(0.12); + + @override + Color? get activeTickMarkColor => _colors.onPrimary.withOpacity(0.54); + + @override + Color? get inactiveTickMarkColor => _colors.primary.withOpacity(0.54); + + @override + Color? get disabledActiveTickMarkColor => _colors.onPrimary.withOpacity(0.12); + + @override + Color? get disabledInactiveTickMarkColor => _colors.onSurface.withOpacity(0.12); + + @override + Color? get thumbColor => _colors.primary; + + @override + Color? get disabledThumbColor => Color.alphaBlend(_colors.onSurface.withOpacity(.38), _colors.surface); + + @override + Color? get overlayColor => _colors.primary.withOpacity(0.12); + + @override + TextStyle? get valueIndicatorTextStyle => Theme.of(context).textTheme.bodyLarge!.copyWith( + color: _colors.onPrimary, + ); + + @override + SliderComponentShape? get valueIndicatorShape => const RectangularSliderValueIndicatorShape(); +} + +// BEGIN GENERATED TOKEN PROPERTIES - Slider + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _SliderDefaultsM3 extends SliderThemeData { + _SliderDefaultsM3(this.context) + : super(trackHeight: 4.0); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + Color? get activeTrackColor => _colors.primary; + + @override + Color? get inactiveTrackColor => _colors.surfaceVariant; + + @override + Color? get secondaryActiveTrackColor => _colors.primary.withOpacity(0.54); + + @override + Color? get disabledActiveTrackColor => _colors.onSurface.withOpacity(0.38); + + @override + Color? get disabledInactiveTrackColor => _colors.onSurface.withOpacity(0.12); + + @override + Color? get disabledSecondaryActiveTrackColor => _colors.onSurface.withOpacity(0.12); + + @override + Color? get activeTickMarkColor => _colors.onPrimary.withOpacity(0.38); + + @override + Color? get inactiveTickMarkColor => _colors.onSurfaceVariant.withOpacity(0.38); + + @override + Color? get disabledActiveTickMarkColor => _colors.onSurface.withOpacity(0.38); + + @override + Color? get disabledInactiveTickMarkColor => _colors.onSurface.withOpacity(0.38); + + @override + Color? get thumbColor => _colors.primary; + + @override + Color? get disabledThumbColor => Color.alphaBlend(_colors.onSurface.withOpacity(0.38), _colors.surface); + + @override + Color? get overlayColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.dragged)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.primary.withOpacity(0.12); + } + + return Colors.transparent; + }); + + @override + TextStyle? get valueIndicatorTextStyle => Theme.of(context).textTheme.labelMedium!.copyWith( + color: _colors.onPrimary, + ); + + @override + SliderComponentShape? get valueIndicatorShape => const DropSliderValueIndicatorShape(); +} + +// END GENERATED TOKEN PROPERTIES - Slider diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/slider_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/slider_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..2d4f8444cc994b0c6b85c3272779cb07f09ec301 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/slider_theme.dart @@ -0,0 +1,3573 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show Path, lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'material_state.dart'; +import 'slider.dart'; +import 'theme.dart'; + +/// Applies a slider theme to descendant [Slider] widgets. +/// +/// A slider theme describes the colors and shape choices of the slider +/// components. +/// +/// Descendant widgets obtain the current theme's [SliderThemeData] object using +/// [SliderTheme.of]. When a widget uses [SliderTheme.of], it is automatically +/// rebuilt if the theme later changes. +/// +/// The slider is as big as the largest of +/// the [SliderComponentShape.getPreferredSize] of the thumb shape, +/// the [SliderComponentShape.getPreferredSize] of the overlay shape, +/// and the [SliderTickMarkShape.getPreferredSize] of the tick mark shape. +/// +/// See also: +/// +/// * [SliderThemeData], which describes the actual configuration of a slider +/// theme. +/// * [SliderComponentShape], which can be used to create custom shapes for +/// the [Slider]'s thumb, overlay, and value indicator and the +/// [RangeSlider]'s overlay. +/// * [SliderTrackShape], which can be used to create custom shapes for the +/// [Slider]'s track. +/// * [SliderTickMarkShape], which can be used to create custom shapes for the +/// [Slider]'s tick marks. +/// * [RangeSliderThumbShape], which can be used to create custom shapes for +/// the [RangeSlider]'s thumb. +/// * [RangeSliderValueIndicatorShape], which can be used to create custom +/// shapes for the [RangeSlider]'s value indicator. +/// * [RangeSliderTrackShape], which can be used to create custom shapes for +/// the [RangeSlider]'s track. +/// * [RangeSliderTickMarkShape], which can be used to create custom shapes for +/// the [RangeSlider]'s tick marks. +class SliderTheme extends InheritedTheme { + /// Applies the given theme [data] to [child]. + const SliderTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the color and shape values for descendant slider widgets. + final SliderThemeData data; + + /// Returns the data from the closest [SliderTheme] instance that encloses + /// the given context. + /// + /// Defaults to the ambient [ThemeData.sliderTheme] if there is no + /// [SliderTheme] in the given build context. + /// + /// {@tool snippet} + /// + /// ```dart + /// class Launch extends StatefulWidget { + /// const Launch({super.key}); + /// + /// @override + /// State createState() => LaunchState(); + /// } + /// + /// class LaunchState extends State<Launch> { + /// double _rocketThrust = 0; + /// + /// @override + /// Widget build(BuildContext context) { + /// return SliderTheme( + /// data: SliderTheme.of(context).copyWith(activeTrackColor: const Color(0xff804040)), + /// child: Slider( + /// onChanged: (double value) { setState(() { _rocketThrust = value; }); }, + /// value: _rocketThrust, + /// ), + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [SliderThemeData], which describes the actual configuration of a slider + /// theme. + static SliderThemeData of(BuildContext context) { + final SliderTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<SliderTheme>(); + return inheritedTheme != null ? inheritedTheme.data : Theme.of(context).sliderTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return SliderTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(SliderTheme oldWidget) => data != oldWidget.data; +} + +/// Describes the conditions under which the value indicator on a [Slider] +/// will be shown. Used with [SliderThemeData.showValueIndicator]. +/// +/// See also: +/// +/// * [Slider], a Material Design slider widget. +/// * [SliderThemeData], which describes the actual configuration of a slider +/// theme. +enum ShowValueIndicator { + /// The value indicator will only be shown for discrete sliders (sliders + /// where [Slider.divisions] is non-null). + onlyForDiscrete, + + /// The value indicator will only be shown for continuous sliders (sliders + /// where [Slider.divisions] is null). + onlyForContinuous, + + /// The value indicator will be shown for all types of sliders. + always, + + /// The value indicator will never be shown. + never, +} + +/// Identifier for a thumb. +/// +/// There are 2 thumbs in a [RangeSlider], [start] and [end]. +/// +/// For [TextDirection.ltr], the [start] thumb is the left-most thumb and the +/// [end] thumb is the right-most thumb. For [TextDirection.rtl] the [start] +/// thumb is the right-most thumb, and the [end] thumb is the left-most thumb. +enum Thumb { + /// Left-most thumb for [TextDirection.ltr], otherwise, right-most thumb. + start, + + /// Right-most thumb for [TextDirection.ltr], otherwise, left-most thumb. + end, +} + +/// Holds the color, shape, and typography values for a Material Design slider +/// theme. +/// +/// Use this class to configure a [SliderTheme] widget, or to set the +/// [ThemeData.sliderTheme] for a [Theme] widget. +/// +/// To obtain the current ambient slider theme, use [SliderTheme.of]. +/// +/// This theme is for both the [Slider] and the [RangeSlider]. The properties +/// that are only for the [Slider] are: [tickMarkShape], [thumbShape], +/// [trackShape], and [valueIndicatorShape]. The properties that are only for +/// the [RangeSlider] are [rangeTickMarkShape], [rangeThumbShape], +/// [rangeTrackShape], [rangeValueIndicatorShape], +/// [overlappingShapeStrokeColor], [minThumbSeparation], and [thumbSelector]. +/// All other properties are used by both the [Slider] and the [RangeSlider]. +/// +/// The parts of a slider are: +/// +/// * The "thumb", which is a shape that slides horizontally when the user +/// drags it. +/// * The "track", which is the line that the slider thumb slides along. +/// * The "tick marks", which are regularly spaced marks that are drawn when +/// using discrete divisions. +/// * The "value indicator", which appears when the user is dragging the thumb +/// to indicate the value being selected. +/// * The "overlay", which appears around the thumb, and is shown when the +/// thumb is pressed, focused, or hovered. It is painted underneath the +/// thumb, so it must extend beyond the bounds of the thumb itself to +/// actually be visible. +/// * The "active" side of the slider is the side between the thumb and the +/// minimum value. +/// * The "inactive" side of the slider is the side between the thumb and the +/// maximum value. +/// * The [Slider] is disabled when it is not accepting user input. See +/// [Slider] for details on when this happens. +/// +/// The thumb, track, tick marks, value indicator, and overlay can be customized +/// by creating subclasses of [SliderTrackShape], +/// [SliderComponentShape], and/or [SliderTickMarkShape]. See +/// [RoundSliderThumbShape], [RectangularSliderTrackShape], +/// [RoundSliderTickMarkShape], [RectangularSliderValueIndicatorShape], and +/// [RoundSliderOverlayShape] for examples. +/// +/// The track painting can be skipped by specifying 0 for [trackHeight]. +/// The thumb painting can be skipped by specifying +/// [SliderComponentShape.noThumb] for [SliderThemeData.thumbShape]. +/// The overlay painting can be skipped by specifying +/// [SliderComponentShape.noOverlay] for [SliderThemeData.overlayShape]. +/// The tick mark painting can be skipped by specifying +/// [SliderTickMarkShape.noTickMark] for [SliderThemeData.tickMarkShape]. +/// The value indicator painting can be skipped by specifying the +/// appropriate [ShowValueIndicator] for [SliderThemeData.showValueIndicator]. +/// +/// See also: +/// +/// * [SliderTheme] widget, which can override the slider theme of its +/// children. +/// * [Theme] widget, which performs a similar function to [SliderTheme], +/// but for overall themes. +/// * [ThemeData], which has a default [SliderThemeData]. +/// * [SliderComponentShape], which can be used to create custom shapes for +/// the [Slider]'s thumb, overlay, and value indicator and the +/// [RangeSlider]'s overlay. +/// * [SliderTrackShape], which can be used to create custom shapes for the +/// [Slider]'s track. +/// * [SliderTickMarkShape], which can be used to create custom shapes for the +/// [Slider]'s tick marks. +/// * [RangeSliderThumbShape], which can be used to create custom shapes for +/// the [RangeSlider]'s thumb. +/// * [RangeSliderValueIndicatorShape], which can be used to create custom +/// shapes for the [RangeSlider]'s value indicator. +/// * [RangeSliderTrackShape], which can be used to create custom shapes for +/// the [RangeSlider]'s track. +/// * [RangeSliderTickMarkShape], which can be used to create custom shapes for +/// the [RangeSlider]'s tick marks. +@immutable +class SliderThemeData with Diagnosticable { + /// Create a [SliderThemeData] given a set of exact values. + /// + /// This will rarely be used directly. It is used by [lerp] to + /// create intermediate themes based on two themes. + /// + /// The simplest way to create a SliderThemeData is to use + /// [copyWith] on the one you get from [SliderTheme.of], or create an + /// entirely new one with [SliderThemeData.fromPrimaryColors]. + /// + /// {@tool snippet} + /// + /// ```dart + /// class Blissful extends StatefulWidget { + /// const Blissful({super.key}); + /// + /// @override + /// State createState() => BlissfulState(); + /// } + /// + /// class BlissfulState extends State<Blissful> { + /// double _bliss = 0; + /// + /// @override + /// Widget build(BuildContext context) { + /// return SliderTheme( + /// data: SliderTheme.of(context).copyWith(activeTrackColor: const Color(0xff404080)), + /// child: Slider( + /// onChanged: (double value) { setState(() { _bliss = value; }); }, + /// value: _bliss, + /// ), + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + const SliderThemeData({ + this.trackHeight, + this.activeTrackColor, + this.inactiveTrackColor, + this.secondaryActiveTrackColor, + this.disabledActiveTrackColor, + this.disabledInactiveTrackColor, + this.disabledSecondaryActiveTrackColor, + this.activeTickMarkColor, + this.inactiveTickMarkColor, + this.disabledActiveTickMarkColor, + this.disabledInactiveTickMarkColor, + this.thumbColor, + this.overlappingShapeStrokeColor, + this.disabledThumbColor, + this.overlayColor, + this.valueIndicatorColor, + this.valueIndicatorStrokeColor, + this.overlayShape, + this.tickMarkShape, + this.thumbShape, + this.trackShape, + this.valueIndicatorShape, + this.rangeTickMarkShape, + this.rangeThumbShape, + this.rangeTrackShape, + this.rangeValueIndicatorShape, + this.showValueIndicator, + this.valueIndicatorTextStyle, + this.minThumbSeparation, + this.thumbSelector, + this.mouseCursor, + this.allowedInteraction, + }); + + /// Generates a SliderThemeData from three main colors. + /// + /// Usually these are the primary, dark and light colors from + /// a [ThemeData]. + /// + /// The opacities of these colors will be overridden with the Material Design + /// defaults when assigning them to the slider theme component colors. + /// + /// This is used to generate the default slider theme for a [ThemeData]. + factory SliderThemeData.fromPrimaryColors({ + required Color primaryColor, + required Color primaryColorDark, + required Color primaryColorLight, + required TextStyle valueIndicatorTextStyle, + }) { + + // These are Material Design defaults, and are used to derive + // component Colors (with opacity) from base colors. + const int activeTrackAlpha = 0xff; + const int inactiveTrackAlpha = 0x3d; // 24% opacity + const int secondaryActiveTrackAlpha = 0x8a; // 54% opacity + const int disabledActiveTrackAlpha = 0x52; // 32% opacity + const int disabledInactiveTrackAlpha = 0x1f; // 12% opacity + const int disabledSecondaryActiveTrackAlpha = 0x1f; // 12% opacity + const int activeTickMarkAlpha = 0x8a; // 54% opacity + const int inactiveTickMarkAlpha = 0x8a; // 54% opacity + const int disabledActiveTickMarkAlpha = 0x1f; // 12% opacity + const int disabledInactiveTickMarkAlpha = 0x1f; // 12% opacity + const int thumbAlpha = 0xff; + const int disabledThumbAlpha = 0x52; // 32% opacity + const int overlayAlpha = 0x1f; // 12% opacity + const int valueIndicatorAlpha = 0xff; + + return SliderThemeData( + trackHeight: 2.0, + activeTrackColor: primaryColor.withAlpha(activeTrackAlpha), + inactiveTrackColor: primaryColor.withAlpha(inactiveTrackAlpha), + secondaryActiveTrackColor: primaryColor.withAlpha(secondaryActiveTrackAlpha), + disabledActiveTrackColor: primaryColorDark.withAlpha(disabledActiveTrackAlpha), + disabledInactiveTrackColor: primaryColorDark.withAlpha(disabledInactiveTrackAlpha), + disabledSecondaryActiveTrackColor: primaryColorDark.withAlpha(disabledSecondaryActiveTrackAlpha), + activeTickMarkColor: primaryColorLight.withAlpha(activeTickMarkAlpha), + inactiveTickMarkColor: primaryColor.withAlpha(inactiveTickMarkAlpha), + disabledActiveTickMarkColor: primaryColorLight.withAlpha(disabledActiveTickMarkAlpha), + disabledInactiveTickMarkColor: primaryColorDark.withAlpha(disabledInactiveTickMarkAlpha), + thumbColor: primaryColor.withAlpha(thumbAlpha), + overlappingShapeStrokeColor: Colors.white, + disabledThumbColor: primaryColorDark.withAlpha(disabledThumbAlpha), + overlayColor: primaryColor.withAlpha(overlayAlpha), + valueIndicatorColor: primaryColor.withAlpha(valueIndicatorAlpha), + valueIndicatorStrokeColor: primaryColor.withAlpha(valueIndicatorAlpha), + overlayShape: const RoundSliderOverlayShape(), + tickMarkShape: const RoundSliderTickMarkShape(), + thumbShape: const RoundSliderThumbShape(), + trackShape: const RoundedRectSliderTrackShape(), + valueIndicatorShape: const PaddleSliderValueIndicatorShape(), + rangeTickMarkShape: const RoundRangeSliderTickMarkShape(), + rangeThumbShape: const RoundRangeSliderThumbShape(), + rangeTrackShape: const RoundedRectRangeSliderTrackShape(), + rangeValueIndicatorShape: const PaddleRangeSliderValueIndicatorShape(), + valueIndicatorTextStyle: valueIndicatorTextStyle, + showValueIndicator: ShowValueIndicator.onlyForDiscrete, + ); + } + + /// The height of the [Slider] track. + final double? trackHeight; + + /// The color of the [Slider] track between the [Slider.min] position and the + /// current thumb position. + final Color? activeTrackColor; + + /// The color of the [Slider] track between the current thumb position and the + /// [Slider.max] position. + final Color? inactiveTrackColor; + + /// The color of the [Slider] track between the current thumb position and the + /// [Slider.secondaryTrackValue] position. + final Color? secondaryActiveTrackColor; + + /// The color of the [Slider] track between the [Slider.min] position and the + /// current thumb position when the [Slider] is disabled. + final Color? disabledActiveTrackColor; + + /// The color of the [Slider] track between the current thumb position and the + /// [Slider.secondaryTrackValue] position when the [Slider] is disabled. + final Color? disabledSecondaryActiveTrackColor; + + /// The color of the [Slider] track between the current thumb position and the + /// [Slider.max] position when the [Slider] is disabled. + final Color? disabledInactiveTrackColor; + + /// The color of the track's tick marks that are drawn between the [Slider.min] + /// position and the current thumb position. + final Color? activeTickMarkColor; + + /// The color of the track's tick marks that are drawn between the current + /// thumb position and the [Slider.max] position. + final Color? inactiveTickMarkColor; + + /// The color of the track's tick marks that are drawn between the [Slider.min] + /// position and the current thumb position when the [Slider] is disabled. + final Color? disabledActiveTickMarkColor; + + /// The color of the track's tick marks that are drawn between the current + /// thumb position and the [Slider.max] position when the [Slider] is + /// disabled. + final Color? disabledInactiveTickMarkColor; + + /// The color given to the [thumbShape] to draw itself with. + final Color? thumbColor; + + /// The color given to the perimeter of the top [rangeThumbShape] when the + /// thumbs are overlapping and the top [rangeValueIndicatorShape] when the + /// value indicators are overlapping. + final Color? overlappingShapeStrokeColor; + + /// The color given to the [thumbShape] to draw itself with when the + /// [Slider] is disabled. + final Color? disabledThumbColor; + + /// The color of the overlay drawn around the slider thumb when it is + /// pressed, focused, or hovered. + /// + /// This is typically a semi-transparent color. + final Color? overlayColor; + + /// The color given to the [valueIndicatorShape] to draw itself with. + final Color? valueIndicatorColor; + + /// The color given to the [valueIndicatorShape] stroke. + final Color? valueIndicatorStrokeColor; + + /// The shape that will be used to draw the [Slider]'s overlay. + /// + /// Both the [overlayColor] and a non default [overlayShape] may be specified. + /// The default [overlayShape] refers to the [overlayColor]. + /// + /// The default value is [RoundSliderOverlayShape]. + final SliderComponentShape? overlayShape; + + /// The shape that will be used to draw the [Slider]'s tick marks. + /// + /// The [SliderTickMarkShape.getPreferredSize] is used to help determine the + /// location of each tick mark on the track. The slider's minimum size will + /// be at least this big. + /// + /// The default value is [RoundSliderTickMarkShape]. + /// + /// See also: + /// + /// * [RoundRangeSliderTickMarkShape], which is the default tick mark + /// shape for the range slider. + final SliderTickMarkShape? tickMarkShape; + + /// The shape that will be used to draw the [Slider]'s thumb. + /// + /// The default value is [RoundSliderThumbShape]. + /// + /// See also: + /// + /// * [RoundRangeSliderThumbShape], which is the default thumb shape for + /// the [RangeSlider]. + final SliderComponentShape? thumbShape; + + /// The shape that will be used to draw the [Slider]'s track. + /// + /// The [SliderTrackShape.getPreferredRect] method is used to map + /// slider-relative gesture coordinates to the correct thumb position on the + /// track. It is also used to horizontally position tick marks, when the + /// slider is discrete. + /// + /// The default value is [RoundedRectSliderTrackShape]. + /// + /// See also: + /// + /// * [RoundedRectRangeSliderTrackShape], which is the default track + /// shape for the [RangeSlider]. + final SliderTrackShape? trackShape; + + /// The shape that will be used to draw the [Slider]'s value + /// indicator. + /// + /// The default value is [PaddleSliderValueIndicatorShape]. + /// + /// See also: + /// + /// * [PaddleRangeSliderValueIndicatorShape], which is the default value + /// indicator shape for the [RangeSlider]. + final SliderComponentShape? valueIndicatorShape; + + /// The shape that will be used to draw the [RangeSlider]'s tick marks. + /// + /// The [RangeSliderTickMarkShape.getPreferredSize] is used to help determine + /// the location of each tick mark on the track. The slider's minimum size + /// will be at least this big. + /// + /// The default value is [RoundRangeSliderTickMarkShape]. + /// + /// See also: + /// + /// * [RoundSliderTickMarkShape], which is the default tick mark shape + /// for the [Slider]. + final RangeSliderTickMarkShape? rangeTickMarkShape; + + /// The shape that will be used for the [RangeSlider]'s thumbs. + /// + /// By default the same shape is used for both thumbs, but strokes the top + /// thumb when it overlaps the bottom thumb. The top thumb is always the last + /// selected thumb. + /// + /// The default value is [RoundRangeSliderThumbShape]. + /// + /// See also: + /// + /// * [RoundSliderThumbShape], which is the default thumb shape for the + /// [Slider]. + final RangeSliderThumbShape? rangeThumbShape; + + /// The shape that will be used to draw the [RangeSlider]'s track. + /// + /// The [SliderTrackShape.getPreferredRect] method is used to map + /// slider-relative gesture coordinates to the correct thumb position on the + /// track. It is also used to horizontally position the tick marks, when the + /// slider is discrete. + /// + /// The default value is [RoundedRectRangeSliderTrackShape]. + /// + /// See also: + /// + /// * [RoundedRectSliderTrackShape], which is the default track + /// shape for the [Slider]. + final RangeSliderTrackShape? rangeTrackShape; + + /// The shape that will be used for the [RangeSlider]'s value indicators. + /// + /// The default shape uses the same value indicator for each thumb, but + /// strokes the top value indicator when it overlaps the bottom value + /// indicator. The top indicator corresponds to the top thumb, which is always + /// the most recently selected thumb. + /// + /// The default value is [PaddleRangeSliderValueIndicatorShape]. + /// + /// See also: + /// + /// * [PaddleSliderValueIndicatorShape], which is the default value + /// indicator shape for the [Slider]. + final RangeSliderValueIndicatorShape? rangeValueIndicatorShape; + + /// Whether the value indicator should be shown for different types of + /// sliders. + /// + /// By default, [showValueIndicator] is set to + /// [ShowValueIndicator.onlyForDiscrete]. The value indicator is only shown + /// when the thumb is being touched. + final ShowValueIndicator? showValueIndicator; + + /// The text style for the text on the value indicator. + final TextStyle? valueIndicatorTextStyle; + + /// Limits the thumb's separation distance. + /// + /// Use this only if you want to control the visual appearance of the thumbs + /// in terms of a logical pixel value. This can be done when you want a + /// specific look for thumbs when they are close together. To limit with the + /// real values, rather than logical pixels, the values can be restricted by + /// the parent. + final double? minThumbSeparation; + + /// Determines which thumb should be selected when the slider is interacted + /// with. + /// + /// If null, the default thumb selector finds the closest thumb, excluding + /// taps that are between the thumbs and not within any one touch target. + /// When the selection is within the touch target bounds of both thumbs, no + /// thumb is selected until the selection is moved. + /// + /// Override this for custom thumb selection. + final RangeThumbSelector? thumbSelector; + + /// {@macro flutter.material.slider.mouseCursor} + /// + /// If specified, overrides the default value of [Slider.mouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// Allowed way for the user to interact with the [Slider]. + /// + /// If specified, overrides the default value of [Slider.allowedInteraction]. + final SliderInteraction? allowedInteraction; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + SliderThemeData copyWith({ + double? trackHeight, + Color? activeTrackColor, + Color? inactiveTrackColor, + Color? secondaryActiveTrackColor, + Color? disabledActiveTrackColor, + Color? disabledInactiveTrackColor, + Color? disabledSecondaryActiveTrackColor, + Color? activeTickMarkColor, + Color? inactiveTickMarkColor, + Color? disabledActiveTickMarkColor, + Color? disabledInactiveTickMarkColor, + Color? thumbColor, + Color? overlappingShapeStrokeColor, + Color? disabledThumbColor, + Color? overlayColor, + Color? valueIndicatorColor, + Color? valueIndicatorStrokeColor, + SliderComponentShape? overlayShape, + SliderTickMarkShape? tickMarkShape, + SliderComponentShape? thumbShape, + SliderTrackShape? trackShape, + SliderComponentShape? valueIndicatorShape, + RangeSliderTickMarkShape? rangeTickMarkShape, + RangeSliderThumbShape? rangeThumbShape, + RangeSliderTrackShape? rangeTrackShape, + RangeSliderValueIndicatorShape? rangeValueIndicatorShape, + ShowValueIndicator? showValueIndicator, + TextStyle? valueIndicatorTextStyle, + double? minThumbSeparation, + RangeThumbSelector? thumbSelector, + MaterialStateProperty<MouseCursor?>? mouseCursor, + SliderInteraction? allowedInteraction, + }) { + return SliderThemeData( + trackHeight: trackHeight ?? this.trackHeight, + activeTrackColor: activeTrackColor ?? this.activeTrackColor, + inactiveTrackColor: inactiveTrackColor ?? this.inactiveTrackColor, + secondaryActiveTrackColor: secondaryActiveTrackColor ?? this.secondaryActiveTrackColor, + disabledActiveTrackColor: disabledActiveTrackColor ?? this.disabledActiveTrackColor, + disabledInactiveTrackColor: disabledInactiveTrackColor ?? this.disabledInactiveTrackColor, + disabledSecondaryActiveTrackColor: disabledSecondaryActiveTrackColor ?? this.disabledSecondaryActiveTrackColor, + activeTickMarkColor: activeTickMarkColor ?? this.activeTickMarkColor, + inactiveTickMarkColor: inactiveTickMarkColor ?? this.inactiveTickMarkColor, + disabledActiveTickMarkColor: disabledActiveTickMarkColor ?? this.disabledActiveTickMarkColor, + disabledInactiveTickMarkColor: disabledInactiveTickMarkColor ?? this.disabledInactiveTickMarkColor, + thumbColor: thumbColor ?? this.thumbColor, + overlappingShapeStrokeColor: overlappingShapeStrokeColor ?? this.overlappingShapeStrokeColor, + disabledThumbColor: disabledThumbColor ?? this.disabledThumbColor, + overlayColor: overlayColor ?? this.overlayColor, + valueIndicatorColor: valueIndicatorColor ?? this.valueIndicatorColor, + valueIndicatorStrokeColor: valueIndicatorStrokeColor ?? this.valueIndicatorStrokeColor, + overlayShape: overlayShape ?? this.overlayShape, + tickMarkShape: tickMarkShape ?? this.tickMarkShape, + thumbShape: thumbShape ?? this.thumbShape, + trackShape: trackShape ?? this.trackShape, + valueIndicatorShape: valueIndicatorShape ?? this.valueIndicatorShape, + rangeTickMarkShape: rangeTickMarkShape ?? this.rangeTickMarkShape, + rangeThumbShape: rangeThumbShape ?? this.rangeThumbShape, + rangeTrackShape: rangeTrackShape ?? this.rangeTrackShape, + rangeValueIndicatorShape: rangeValueIndicatorShape ?? this.rangeValueIndicatorShape, + showValueIndicator: showValueIndicator ?? this.showValueIndicator, + valueIndicatorTextStyle: valueIndicatorTextStyle ?? this.valueIndicatorTextStyle, + minThumbSeparation: minThumbSeparation ?? this.minThumbSeparation, + thumbSelector: thumbSelector ?? this.thumbSelector, + mouseCursor: mouseCursor ?? this.mouseCursor, + allowedInteraction: allowedInteraction ?? this.allowedInteraction, + ); + } + + /// Linearly interpolate between two slider themes. + /// + /// {@macro dart.ui.shadow.lerp} + static SliderThemeData lerp(SliderThemeData a, SliderThemeData b, double t) { + if (identical(a, b)) { + return a; + } + return SliderThemeData( + trackHeight: lerpDouble(a.trackHeight, b.trackHeight, t), + activeTrackColor: Color.lerp(a.activeTrackColor, b.activeTrackColor, t), + inactiveTrackColor: Color.lerp(a.inactiveTrackColor, b.inactiveTrackColor, t), + secondaryActiveTrackColor: Color.lerp(a.secondaryActiveTrackColor, b.secondaryActiveTrackColor, t), + disabledActiveTrackColor: Color.lerp(a.disabledActiveTrackColor, b.disabledActiveTrackColor, t), + disabledInactiveTrackColor: Color.lerp(a.disabledInactiveTrackColor, b.disabledInactiveTrackColor, t), + disabledSecondaryActiveTrackColor: Color.lerp(a.disabledSecondaryActiveTrackColor, b.disabledSecondaryActiveTrackColor, t), + activeTickMarkColor: Color.lerp(a.activeTickMarkColor, b.activeTickMarkColor, t), + inactiveTickMarkColor: Color.lerp(a.inactiveTickMarkColor, b.inactiveTickMarkColor, t), + disabledActiveTickMarkColor: Color.lerp(a.disabledActiveTickMarkColor, b.disabledActiveTickMarkColor, t), + disabledInactiveTickMarkColor: Color.lerp(a.disabledInactiveTickMarkColor, b.disabledInactiveTickMarkColor, t), + thumbColor: Color.lerp(a.thumbColor, b.thumbColor, t), + overlappingShapeStrokeColor: Color.lerp(a.overlappingShapeStrokeColor, b.overlappingShapeStrokeColor, t), + disabledThumbColor: Color.lerp(a.disabledThumbColor, b.disabledThumbColor, t), + overlayColor: Color.lerp(a.overlayColor, b.overlayColor, t), + valueIndicatorColor: Color.lerp(a.valueIndicatorColor, b.valueIndicatorColor, t), + valueIndicatorStrokeColor: Color.lerp(a.valueIndicatorStrokeColor, b.valueIndicatorStrokeColor, t), + overlayShape: t < 0.5 ? a.overlayShape : b.overlayShape, + tickMarkShape: t < 0.5 ? a.tickMarkShape : b.tickMarkShape, + thumbShape: t < 0.5 ? a.thumbShape : b.thumbShape, + trackShape: t < 0.5 ? a.trackShape : b.trackShape, + valueIndicatorShape: t < 0.5 ? a.valueIndicatorShape : b.valueIndicatorShape, + rangeTickMarkShape: t < 0.5 ? a.rangeTickMarkShape : b.rangeTickMarkShape, + rangeThumbShape: t < 0.5 ? a.rangeThumbShape : b.rangeThumbShape, + rangeTrackShape: t < 0.5 ? a.rangeTrackShape : b.rangeTrackShape, + rangeValueIndicatorShape: t < 0.5 ? a.rangeValueIndicatorShape : b.rangeValueIndicatorShape, + showValueIndicator: t < 0.5 ? a.showValueIndicator : b.showValueIndicator, + valueIndicatorTextStyle: TextStyle.lerp(a.valueIndicatorTextStyle, b.valueIndicatorTextStyle, t), + minThumbSeparation: lerpDouble(a.minThumbSeparation, b.minThumbSeparation, t), + thumbSelector: t < 0.5 ? a.thumbSelector : b.thumbSelector, + mouseCursor: t < 0.5 ? a.mouseCursor : b.mouseCursor, + allowedInteraction: t < 0.5 ? a.allowedInteraction : b.allowedInteraction, + ); + } + + @override + int get hashCode => Object.hash( + trackHeight, + activeTrackColor, + inactiveTrackColor, + secondaryActiveTrackColor, + disabledActiveTrackColor, + disabledInactiveTrackColor, + disabledSecondaryActiveTrackColor, + activeTickMarkColor, + inactiveTickMarkColor, + disabledActiveTickMarkColor, + disabledInactiveTickMarkColor, + thumbColor, + overlappingShapeStrokeColor, + disabledThumbColor, + overlayColor, + valueIndicatorColor, + overlayShape, + tickMarkShape, + thumbShape, + Object.hash( + trackShape, + valueIndicatorShape, + rangeTickMarkShape, + rangeThumbShape, + rangeTrackShape, + rangeValueIndicatorShape, + showValueIndicator, + valueIndicatorTextStyle, + minThumbSeparation, + thumbSelector, + mouseCursor, + allowedInteraction, + ), + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is SliderThemeData + && other.trackHeight == trackHeight + && other.activeTrackColor == activeTrackColor + && other.inactiveTrackColor == inactiveTrackColor + && other.secondaryActiveTrackColor == secondaryActiveTrackColor + && other.disabledActiveTrackColor == disabledActiveTrackColor + && other.disabledInactiveTrackColor == disabledInactiveTrackColor + && other.disabledSecondaryActiveTrackColor == disabledSecondaryActiveTrackColor + && other.activeTickMarkColor == activeTickMarkColor + && other.inactiveTickMarkColor == inactiveTickMarkColor + && other.disabledActiveTickMarkColor == disabledActiveTickMarkColor + && other.disabledInactiveTickMarkColor == disabledInactiveTickMarkColor + && other.thumbColor == thumbColor + && other.overlappingShapeStrokeColor == overlappingShapeStrokeColor + && other.disabledThumbColor == disabledThumbColor + && other.overlayColor == overlayColor + && other.valueIndicatorColor == valueIndicatorColor + && other.valueIndicatorStrokeColor == valueIndicatorStrokeColor + && other.overlayShape == overlayShape + && other.tickMarkShape == tickMarkShape + && other.thumbShape == thumbShape + && other.trackShape == trackShape + && other.valueIndicatorShape == valueIndicatorShape + && other.rangeTickMarkShape == rangeTickMarkShape + && other.rangeThumbShape == rangeThumbShape + && other.rangeTrackShape == rangeTrackShape + && other.rangeValueIndicatorShape == rangeValueIndicatorShape + && other.showValueIndicator == showValueIndicator + && other.valueIndicatorTextStyle == valueIndicatorTextStyle + && other.minThumbSeparation == minThumbSeparation + && other.thumbSelector == thumbSelector + && other.mouseCursor == mouseCursor + && other.allowedInteraction == allowedInteraction; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + const SliderThemeData defaultData = SliderThemeData(); + properties.add(DoubleProperty('trackHeight', trackHeight, defaultValue: defaultData.trackHeight)); + properties.add(ColorProperty('activeTrackColor', activeTrackColor, defaultValue: defaultData.activeTrackColor)); + properties.add(ColorProperty('inactiveTrackColor', inactiveTrackColor, defaultValue: defaultData.inactiveTrackColor)); + properties.add(ColorProperty('secondaryActiveTrackColor', secondaryActiveTrackColor, defaultValue: defaultData.secondaryActiveTrackColor)); + properties.add(ColorProperty('disabledActiveTrackColor', disabledActiveTrackColor, defaultValue: defaultData.disabledActiveTrackColor)); + properties.add(ColorProperty('disabledInactiveTrackColor', disabledInactiveTrackColor, defaultValue: defaultData.disabledInactiveTrackColor)); + properties.add(ColorProperty('disabledSecondaryActiveTrackColor', disabledSecondaryActiveTrackColor, defaultValue: defaultData.disabledSecondaryActiveTrackColor)); + properties.add(ColorProperty('activeTickMarkColor', activeTickMarkColor, defaultValue: defaultData.activeTickMarkColor)); + properties.add(ColorProperty('inactiveTickMarkColor', inactiveTickMarkColor, defaultValue: defaultData.inactiveTickMarkColor)); + properties.add(ColorProperty('disabledActiveTickMarkColor', disabledActiveTickMarkColor, defaultValue: defaultData.disabledActiveTickMarkColor)); + properties.add(ColorProperty('disabledInactiveTickMarkColor', disabledInactiveTickMarkColor, defaultValue: defaultData.disabledInactiveTickMarkColor)); + properties.add(ColorProperty('thumbColor', thumbColor, defaultValue: defaultData.thumbColor)); + properties.add(ColorProperty('overlappingShapeStrokeColor', overlappingShapeStrokeColor, defaultValue: defaultData.overlappingShapeStrokeColor)); + properties.add(ColorProperty('disabledThumbColor', disabledThumbColor, defaultValue: defaultData.disabledThumbColor)); + properties.add(ColorProperty('overlayColor', overlayColor, defaultValue: defaultData.overlayColor)); + properties.add(ColorProperty('valueIndicatorColor', valueIndicatorColor, defaultValue: defaultData.valueIndicatorColor)); + properties.add(ColorProperty('valueIndicatorStrokeColor', valueIndicatorStrokeColor, defaultValue: defaultData.valueIndicatorStrokeColor)); + properties.add(DiagnosticsProperty<SliderComponentShape>('overlayShape', overlayShape, defaultValue: defaultData.overlayShape)); + properties.add(DiagnosticsProperty<SliderTickMarkShape>('tickMarkShape', tickMarkShape, defaultValue: defaultData.tickMarkShape)); + properties.add(DiagnosticsProperty<SliderComponentShape>('thumbShape', thumbShape, defaultValue: defaultData.thumbShape)); + properties.add(DiagnosticsProperty<SliderTrackShape>('trackShape', trackShape, defaultValue: defaultData.trackShape)); + properties.add(DiagnosticsProperty<SliderComponentShape>('valueIndicatorShape', valueIndicatorShape, defaultValue: defaultData.valueIndicatorShape)); + properties.add(DiagnosticsProperty<RangeSliderTickMarkShape>('rangeTickMarkShape', rangeTickMarkShape, defaultValue: defaultData.rangeTickMarkShape)); + properties.add(DiagnosticsProperty<RangeSliderThumbShape>('rangeThumbShape', rangeThumbShape, defaultValue: defaultData.rangeThumbShape)); + properties.add(DiagnosticsProperty<RangeSliderTrackShape>('rangeTrackShape', rangeTrackShape, defaultValue: defaultData.rangeTrackShape)); + properties.add(DiagnosticsProperty<RangeSliderValueIndicatorShape>('rangeValueIndicatorShape', rangeValueIndicatorShape, defaultValue: defaultData.rangeValueIndicatorShape)); + properties.add(EnumProperty<ShowValueIndicator>('showValueIndicator', showValueIndicator, defaultValue: defaultData.showValueIndicator)); + properties.add(DiagnosticsProperty<TextStyle>('valueIndicatorTextStyle', valueIndicatorTextStyle, defaultValue: defaultData.valueIndicatorTextStyle)); + properties.add(DoubleProperty('minThumbSeparation', minThumbSeparation, defaultValue: defaultData.minThumbSeparation)); + properties.add(DiagnosticsProperty<RangeThumbSelector>('thumbSelector', thumbSelector, defaultValue: defaultData.thumbSelector)); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: defaultData.mouseCursor)); + properties.add(EnumProperty<SliderInteraction>('allowedInteraction', allowedInteraction, defaultValue: defaultData.allowedInteraction)); + } +} + +/// Base class for slider thumb, thumb overlay, and value indicator shapes. +/// +/// Create a subclass of this if you would like a custom shape. +/// +/// All shapes are painted to the same canvas and ordering is important. +/// The overlay is painted first, then the value indicator, then the thumb. +/// +/// The thumb painting can be skipped by specifying [noThumb] for +/// [SliderThemeData.thumbShape]. +/// +/// The overlay painting can be skipped by specifying [noOverlay] for +/// [SliderThemeData.overlayShape]. +/// +/// See also: +/// +/// * [RoundSliderThumbShape], which is the default [Slider]'s thumb shape that +/// paints a solid circle. +/// * [RoundSliderOverlayShape], which is the default [Slider] and +/// [RangeSlider]'s overlay shape that paints a transparent circle. +/// * [PaddleSliderValueIndicatorShape], which is the default [Slider]'s value +/// indicator shape that paints a custom path with text in it. +abstract class SliderComponentShape { + /// This abstract const constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const SliderComponentShape(); + + /// Returns the preferred size of the shape, based on the given conditions. + Size getPreferredSize(bool isEnabled, bool isDiscrete); + + /// Paints the shape, taking into account the state passed to it. + /// + /// {@template flutter.material.SliderComponentShape.paint.context} + /// The `context` argument is the same as the one that includes the [Slider]'s + /// render box. + /// {@endtemplate} + /// + /// {@template flutter.material.SliderComponentShape.paint.center} + /// The `center` argument is the offset for where this shape's center should be + /// painted. This offset is relative to the origin of the [context] canvas. + /// {@endtemplate} + /// + /// The `activationAnimation` argument is an animation triggered when the user + /// begins to interact with the slider. It reverses when the user stops interacting + /// with the slider. + /// + /// {@template flutter.material.SliderComponentShape.paint.enableAnimation} + /// The `enableAnimation` argument is an animation triggered when the [Slider] + /// is enabled, and it reverses when the slider is disabled. The [Slider] is + /// enabled when [Slider.onChanged] is not null.Use this to paint intermediate + /// frames for this shape when the slider changes enabled state. + /// {@endtemplate} + /// + /// {@template flutter.material.SliderComponentShape.paint.isDiscrete} + /// The `isDiscrete` argument is true if [Slider.divisions] is non-null. When + /// true, the slider will render tick marks on top of the track. + /// {@endtemplate} + /// + /// If the `labelPainter` argument is non-null, then [TextPainter.paint] + /// should be called on the `labelPainter` with the location that the label + /// should appear. If the `labelPainter` argument is null, then no label was + /// supplied to the [Slider]. + /// + /// {@template flutter.material.SliderComponentShape.paint.parentBox} + /// The `parentBox` argument is the [RenderBox] of the [Slider]. Its attributes, + /// such as size, can be used to assist in painting this shape. + /// {@endtemplate} + /// + /// {@template flutter.material.SliderComponentShape.paint.sliderTheme} + /// the `sliderTheme` argument is the theme assigned to the [Slider] that this + /// shape belongs to. + /// {@endtemplate} + /// + /// The `textDirection` argument can be used to determine how any extra text + /// or graphics (besides the text painted by the `labelPainter`) should be + /// positioned. The `labelPainter` already has the [textDirection] set. + /// + /// The `value` argument is the current parametric value (from 0.0 to 1.0) of + /// the slider. + /// + /// {@template flutter.material.SliderComponentShape.paint.textScaleFactor} + /// The `textScaleFactor` argument can be used to determine whether the + /// component should paint larger or smaller, depending on whether + /// [textScaleFactor] is greater than 1 for larger, and between 0 and 1 for + /// smaller. It usually comes from [MediaQueryData.textScaleFactor]. + /// {@endtemplate} + /// + /// {@template flutter.material.SliderComponentShape.paint.sizeWithOverflow} + /// The `sizeWithOverflow` argument can be used to determine the bounds the + /// drawing of the components that are outside of the regular slider bounds. + /// It's the size of the box, whose center is aligned with the slider's + /// bounds, that the value indicators must be drawn within. Typically, it is + /// bigger than the slider. + /// {@endtemplate} + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + required bool isDiscrete, + required TextPainter labelPainter, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required TextDirection textDirection, + required double value, + required double textScaleFactor, + required Size sizeWithOverflow, + }); + + /// Special instance of [SliderComponentShape] to skip the thumb drawing. + /// + /// See also: + /// + /// * [SliderThemeData.thumbShape], which is the shape that the [Slider] + /// uses when painting the thumb. + static final SliderComponentShape noThumb = _EmptySliderComponentShape(); + + /// Special instance of [SliderComponentShape] to skip the overlay drawing. + /// + /// See also: + /// + /// * [SliderThemeData.overlayShape], which is the shape that the [Slider] + /// uses when painting the overlay. + static final SliderComponentShape noOverlay = _EmptySliderComponentShape(); +} + +/// Base class for [Slider] tick mark shapes. +/// +/// Create a subclass of this if you would like a custom slider tick mark shape. +/// +/// The tick mark painting can be skipped by specifying [noTickMark] for +/// [SliderThemeData.tickMarkShape]. +/// +/// See also: +/// +/// * [RoundSliderTickMarkShape], which is the default [Slider]'s tick mark +/// shape that paints a solid circle. +/// * [SliderTrackShape], which can be used to create custom shapes for the +/// [Slider]'s track. +/// * [SliderComponentShape], which can be used to create custom shapes for +/// the [Slider]'s thumb, overlay, and value indicator and the +/// [RangeSlider]'s overlay. +abstract class SliderTickMarkShape { + /// This abstract const constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const SliderTickMarkShape(); + + /// Returns the preferred size of the shape. + /// + /// It is used to help position the tick marks within the slider. + /// + /// {@macro flutter.material.SliderComponentShape.paint.sliderTheme} + /// + /// {@template flutter.material.SliderTickMarkShape.getPreferredSize.isEnabled} + /// The `isEnabled` argument is false when [Slider.onChanged] is null and true + /// otherwise. When true, the slider will respond to input. + /// {@endtemplate} + Size getPreferredSize({ + required SliderThemeData sliderTheme, + required bool isEnabled, + }); + + /// Paints the slider track. + /// + /// {@macro flutter.material.SliderComponentShape.paint.context} + /// + /// {@macro flutter.material.SliderComponentShape.paint.center} + /// + /// {@macro flutter.material.SliderComponentShape.paint.parentBox} + /// + /// {@macro flutter.material.SliderComponentShape.paint.sliderTheme} + /// + /// {@macro flutter.material.SliderComponentShape.paint.enableAnimation} + /// + /// {@macro flutter.material.SliderTickMarkShape.getPreferredSize.isEnabled} + /// + /// The `textDirection` argument can be used to determine how the tick marks + /// are painting depending on whether they are on an active track segment or + /// not. The track segment between the start of the slider and the thumb is + /// the active track segment. The track segment between the thumb and the end + /// of the slider is the inactive track segment. In LTR text direction, the + /// start of the slider is on the left, and in RTL text direction, the start + /// of the slider is on the right. + void paint( + PaintingContext context, + Offset center, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double> enableAnimation, + required Offset thumbCenter, + required bool isEnabled, + required TextDirection textDirection, + }); + + /// Special instance of [SliderTickMarkShape] to skip the tick mark painting. + /// + /// See also: + /// + /// * [SliderThemeData.tickMarkShape], which is the shape that the [Slider] + /// uses when painting tick marks. + static final SliderTickMarkShape noTickMark = _EmptySliderTickMarkShape(); +} + +/// Base class for slider track shapes. +/// +/// The slider's thumb moves along the track. A discrete slider's tick marks +/// are drawn after the track, but before the thumb, and are aligned with the +/// track. +/// +/// The [getPreferredRect] helps position the slider thumb and tick marks +/// relative to the track. +/// +/// See also: +/// +/// * [RoundedRectSliderTrackShape] for the default [Slider]'s track shape that +/// paints a stadium-like track. +/// * [SliderTickMarkShape], which can be used to create custom shapes for the +/// [Slider]'s tick marks. +/// * [SliderComponentShape], which can be used to create custom shapes for +/// the [Slider]'s thumb, overlay, and value indicator and the +/// [RangeSlider]'s overlay. +abstract class SliderTrackShape { + /// This abstract const constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const SliderTrackShape(); + + /// Returns the preferred bounds of the shape. + /// + /// It is used to provide horizontal boundaries for the thumb's position, and + /// to help position the slider thumb and tick marks relative to the track. + /// + /// The `parentBox` argument can be used to help determine the preferredRect relative to + /// attributes of the render box of the slider itself, such as size. + /// + /// The `offset` argument is relative to the caller's bounding box. It can be used to + /// convert gesture coordinates from global to slider-relative coordinates. + /// + /// {@macro flutter.material.SliderComponentShape.paint.sliderTheme} + /// + /// {@macro flutter.material.SliderTickMarkShape.getPreferredSize.isEnabled} + /// + /// {@macro flutter.material.SliderComponentShape.paint.isDiscrete} + Rect getPreferredRect({ + required RenderBox parentBox, + Offset offset = Offset.zero, + required SliderThemeData sliderTheme, + bool isEnabled, + bool isDiscrete, + }); + + /// Paints the track shape based on the state passed to it. + /// + /// {@macro flutter.material.SliderComponentShape.paint.context} + /// + /// The `offset` argument the offset of the origin of the `parentBox` to the + /// origin of its `context` canvas. This shape must be painted relative to + /// this offset. See [PaintingContextCallback]. + /// + /// {@macro flutter.material.SliderComponentShape.paint.parentBox} + /// + /// {@macro flutter.material.SliderComponentShape.paint.sliderTheme} + /// + /// {@macro flutter.material.SliderComponentShape.paint.enableAnimation} + /// + /// The `thumbCenter` argument is the offset of the center of the thumb + /// relative to the origin of the [PaintingContext.canvas]. It can be used as + /// the point that divides the track into 2 segments. + /// + /// The `secondaryOffset` argument is the offset of the secondary value + /// relative to the origin of the [PaintingContext.canvas]. + /// + /// If not null, the track is divided into 3 segments. + /// + /// {@macro flutter.material.SliderTickMarkShape.getPreferredSize.isEnabled} + /// + /// {@macro flutter.material.SliderComponentShape.paint.isDiscrete} + /// + /// The `textDirection` argument can be used to determine how the track + /// segments are painted depending on whether they are active or not. + /// + /// {@template flutter.material.SliderTrackShape.paint.trackSegment} + /// The track segment between the start of the slider and the thumb is the + /// active track segment. The track segment between the thumb and the end of the + /// slider is the inactive track segment. In [TextDirection.ltr], the start of + /// the slider is on the left, and in [TextDirection.rtl], the start of the + /// slider is on the right. + /// {@endtemplate} + void paint( + PaintingContext context, + Offset offset, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double> enableAnimation, + required Offset thumbCenter, + Offset? secondaryOffset, + bool isEnabled, + bool isDiscrete, + required TextDirection textDirection, + }); +} + +/// Base class for [RangeSlider] thumb shapes. +/// +/// See also: +/// +/// * [RoundRangeSliderThumbShape] for the default [RangeSlider]'s thumb shape +/// that paints a solid circle. +/// * [RangeSliderTickMarkShape], which can be used to create custom shapes for +/// the [RangeSlider]'s tick marks. +/// * [RangeSliderTrackShape], which can be used to create custom shapes for +/// the [RangeSlider]'s track. +/// * [RangeSliderValueIndicatorShape], which can be used to create custom +/// shapes for the [RangeSlider]'s value indicator. +/// * [SliderComponentShape], which can be used to create custom shapes for +/// the [Slider]'s thumb, overlay, and value indicator and the +/// [RangeSlider]'s overlay. +abstract class RangeSliderThumbShape { + /// This abstract const constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const RangeSliderThumbShape(); + + /// Returns the preferred size of the shape, based on the given conditions. + /// + /// {@template flutter.material.RangeSliderThumbShape.getPreferredSize.isDiscrete} + /// The `isDiscrete` argument is true if [RangeSlider.divisions] is non-null. + /// When true, the slider will render tick marks on top of the track. + /// {@endtemplate} + /// + /// {@template flutter.material.RangeSliderThumbShape.getPreferredSize.isEnabled} + /// The `isEnabled` argument is false when [RangeSlider.onChanged] is null and + /// true otherwise. When true, the slider will respond to input. + /// {@endtemplate} + Size getPreferredSize(bool isEnabled, bool isDiscrete); + + /// Paints the thumb shape based on the state passed to it. + /// + /// {@template flutter.material.RangeSliderThumbShape.paint.context} + /// The `context` argument represents the [RangeSlider]'s render box. + /// {@endtemplate} + /// + /// {@macro flutter.material.SliderComponentShape.paint.center} + /// + /// {@template flutter.material.RangeSliderThumbShape.paint.activationAnimation} + /// The `activationAnimation` argument is an animation triggered when the user + /// begins to interact with the [RangeSlider]. It reverses when the user stops + /// interacting with the slider. + /// {@endtemplate} + /// + /// {@template flutter.material.RangeSliderThumbShape.paint.enableAnimation} + /// The `enableAnimation` argument is an animation triggered when the + /// [RangeSlider] is enabled, and it reverses when the slider is disabled. The + /// [RangeSlider] is enabled when [RangeSlider.onChanged] is not null. Use + /// this to paint intermediate frames for this shape when the slider changes + /// enabled state. + /// {@endtemplate} + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isDiscrete} + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isEnabled} + /// + /// If the `isOnTop` argument is true, this thumb is painted on top of the + /// other slider thumb because this thumb is the one that was most recently + /// selected. + /// + /// {@template flutter.material.RangeSliderThumbShape.paint.sliderTheme} + /// The `sliderTheme` argument is the theme assigned to the [RangeSlider] that + /// this shape belongs to. + /// {@endtemplate} + /// + /// The `textDirection` argument can be used to determine how the orientation + /// of either slider thumb should be changed, such as drawing different + /// shapes for the left and right thumb. + /// + /// {@template flutter.material.RangeSliderThumbShape.paint.thumb} + /// The `thumb` argument is the specifier for which of the two thumbs this + /// method should paint (start or end). + /// {@endtemplate} + /// + /// The `isPressed` argument can be used to give the selected thumb + /// additional selected or pressed state visual feedback, such as a larger + /// shadow. + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + bool isDiscrete, + bool isEnabled, + bool isOnTop, + TextDirection textDirection, + required SliderThemeData sliderTheme, + Thumb thumb, + bool isPressed, + }); +} + +/// Base class for [RangeSlider] value indicator shapes. +/// +/// See also: +/// +/// * [PaddleRangeSliderValueIndicatorShape] for the default [RangeSlider]'s +/// value indicator shape that paints a custom path with text in it. +/// * [RangeSliderTickMarkShape], which can be used to create custom shapes for +/// the [RangeSlider]'s tick marks. +/// * [RangeSliderThumbShape], which can be used to create custom shapes for +/// the [RangeSlider]'s thumb. +/// * [RangeSliderTrackShape], which can be used to create custom shapes for +/// the [RangeSlider]'s track. +/// * [SliderComponentShape], which can be used to create custom shapes for +/// the [Slider]'s thumb, overlay, and value indicator and the +/// [RangeSlider]'s overlay. +abstract class RangeSliderValueIndicatorShape { + /// This abstract const constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const RangeSliderValueIndicatorShape(); + + /// Returns the preferred size of the shape, based on the given conditions. + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isEnabled} + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isDiscrete} + /// + /// The `labelPainter` argument helps determine the width of the shape. It is + /// variable width because it is derived from a formatted string. + /// + /// {@macro flutter.material.SliderComponentShape.paint.textScaleFactor} + Size getPreferredSize( + bool isEnabled, + bool isDiscrete, { + required TextPainter labelPainter, + required double textScaleFactor, + }); + + /// Determines the best offset to keep this shape on the screen. + /// + /// Override this method when the center of the value indicator should be + /// shifted from the vertical center of the thumb. + double getHorizontalShift({ + RenderBox? parentBox, + Offset? center, + TextPainter? labelPainter, + Animation<double>? activationAnimation, + double? textScaleFactor, + Size? sizeWithOverflow, + }) { + return 0; + } + + /// Paints the value indicator shape based on the state passed to it. + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.context} + /// + /// {@macro flutter.material.SliderComponentShape.paint.center} + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.activationAnimation} + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.enableAnimation} + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isDiscrete} + /// + /// The `isOnTop` argument is the top-most value indicator between the two value + /// indicators, which is always the indicator for the most recently selected thumb. In + /// the default case, this is used to paint a stroke around the top indicator + /// for better visibility between the two indicators. + /// + /// {@macro flutter.material.SliderComponentShape.paint.textScaleFactor} + /// + /// {@macro flutter.material.SliderComponentShape.paint.sizeWithOverflow} + /// + /// {@template flutter.material.RangeSliderValueIndicatorShape.paint.parentBox} + /// The `parentBox` argument is the [RenderBox] of the [RangeSlider]. Its + /// attributes, such as size, can be used to assist in painting this shape. + /// {@endtemplate} + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.sliderTheme} + /// + /// The `textDirection` argument can be used to determine how any extra text + /// or graphics, besides the text painted by the [labelPainter] should be + /// positioned. The `labelPainter` argument already has the `textDirection` + /// set. + /// + /// The `value` argument is the current parametric value (from 0.0 to 1.0) of + /// the slider. + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.thumb} + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + bool isDiscrete, + bool isOnTop, + required TextPainter labelPainter, + double textScaleFactor, + Size sizeWithOverflow, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + TextDirection textDirection, + double value, + Thumb thumb, + }); +} + +/// Base class for [RangeSlider] tick mark shapes. +/// +/// This is a simplified version of [SliderComponentShape] with a +/// [SliderThemeData] passed when getting the preferred size. +/// +/// See also: +/// +/// * [RoundRangeSliderTickMarkShape] for the default [RangeSlider]'s tick mark +/// shape that paints a solid circle. +/// * [RangeSliderThumbShape], which can be used to create custom shapes for +/// the [RangeSlider]'s thumb. +/// * [RangeSliderTrackShape], which can be used to create custom shapes for +/// the [RangeSlider]'s track. +/// * [RangeSliderValueIndicatorShape], which can be used to create custom +/// shapes for the [RangeSlider]'s value indicator. +/// * [SliderComponentShape], which can be used to create custom shapes for +/// the [Slider]'s thumb, overlay, and value indicator and the +/// [RangeSlider]'s overlay. +abstract class RangeSliderTickMarkShape { + /// This abstract const constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const RangeSliderTickMarkShape(); + + /// Returns the preferred size of the shape. + /// + /// It is used to help position the tick marks within the slider. + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.sliderTheme} + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isEnabled} + Size getPreferredSize({ + required SliderThemeData sliderTheme, + bool isEnabled, + }); + + /// Paints the slider track. + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.context} + /// + /// {@macro flutter.material.SliderComponentShape.paint.center} + /// + /// {@macro flutter.material.RangeSliderValueIndicatorShape.paint.parentBox} + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.sliderTheme} + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.enableAnimation} + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isEnabled} + /// + /// The `textDirection` argument can be used to determine how the tick marks + /// are painted depending on whether they are on an active track segment or not. + /// + /// {@template flutter.material.RangeSliderTickMarkShape.paint.trackSegment} + /// The track segment between the two thumbs is the active track segment. The + /// track segments between the thumb and each end of the slider are the inactive + /// track segments. In [TextDirection.ltr], the start of the slider is on the + /// left, and in [TextDirection.rtl], the start of the slider is on the right. + /// {@endtemplate} + void paint( + PaintingContext context, + Offset center, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double> enableAnimation, + required Offset startThumbCenter, + required Offset endThumbCenter, + bool isEnabled, + required TextDirection textDirection, + }); +} + +/// Base class for [RangeSlider] track shapes. +/// +/// The slider's thumbs move along the track. A discrete slider's tick marks +/// are drawn after the track, but before the thumb, and are aligned with the +/// track. +/// +/// The [getPreferredRect] helps position the slider thumbs and tick marks +/// relative to the track. +/// +/// See also: +/// +/// * [RoundedRectRangeSliderTrackShape] for the default [RangeSlider]'s track +/// shape that paints a stadium-like track. +/// * [RangeSliderTickMarkShape], which can be used to create custom shapes for +/// the [RangeSlider]'s tick marks. +/// * [RangeSliderThumbShape], which can be used to create custom shapes for +/// the [RangeSlider]'s thumb. +/// * [RangeSliderValueIndicatorShape], which can be used to create custom +/// shapes for the [RangeSlider]'s value indicator. +/// * [SliderComponentShape], which can be used to create custom shapes for +/// the [Slider]'s thumb, overlay, and value indicator and the +/// [RangeSlider]'s overlay. +abstract class RangeSliderTrackShape { + /// This abstract const constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const RangeSliderTrackShape(); + + /// Returns the preferred bounds of the shape. + /// + /// It is used to provide horizontal boundaries for the position of the + /// thumbs, and to help position the slider thumbs and tick marks relative to + /// the track. + /// + /// The `parentBox` argument can be used to help determine the preferredRect + /// relative to attributes of the render box of the slider itself, such as + /// size. + /// + /// The `offset` argument is relative to the caller's bounding box. It can be + /// used to convert gesture coordinates from global to slider-relative + /// coordinates. + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.sliderTheme} + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isEnabled} + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isDiscrete} + Rect getPreferredRect({ + required RenderBox parentBox, + Offset offset = Offset.zero, + required SliderThemeData sliderTheme, + bool isEnabled, + bool isDiscrete, + }); + + /// Paints the track shape based on the state passed to it. + /// + /// {@macro flutter.material.SliderComponentShape.paint.context} + /// + /// The `offset` argument is the offset of the origin of the `parentBox` to + /// the origin of its `context` canvas. This shape must be painted relative + /// to this offset. See [PaintingContextCallback]. + /// + /// {@macro flutter.material.RangeSliderValueIndicatorShape.paint.parentBox} + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.sliderTheme} + /// + /// {@macro flutter.material.RangeSliderThumbShape.paint.enableAnimation} + /// + /// The `startThumbCenter` argument is the offset of the center of the start + /// thumb relative to the origin of the [PaintingContext.canvas]. It can be + /// used as one point that divides the track between inactive and active. + /// + /// The `endThumbCenter` argument is the offset of the center of the end + /// thumb relative to the origin of the [PaintingContext.canvas]. It can be + /// used as one point that divides the track between inactive and active. + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isEnabled} + /// + /// {@macro flutter.material.RangeSliderThumbShape.getPreferredSize.isDiscrete} + /// + /// The `textDirection` argument can be used to determine how the track + /// segments are painted depending on whether they are on an active track + /// segment or not. + /// + /// {@macro flutter.material.RangeSliderTickMarkShape.paint.trackSegment} + void paint( + PaintingContext context, + Offset offset, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double> enableAnimation, + required Offset startThumbCenter, + required Offset endThumbCenter, + bool isEnabled = false, + bool isDiscrete = false, + required TextDirection textDirection, + }); +} + +/// Base track shape that provides an implementation of [getPreferredRect] for +/// default sizing. +/// +/// The height is set from [SliderThemeData.trackHeight] and the width of the +/// parent box less the larger of the widths of [SliderThemeData.thumbShape] and +/// [SliderThemeData.overlayShape]. +/// +/// See also: +/// +/// * [RectangularSliderTrackShape], which is a track shape with sharp +/// rectangular edges +/// * [RoundedRectSliderTrackShape], which is a track shape with round +/// stadium-like edges. +mixin BaseSliderTrackShape { + /// Returns a rect that represents the track bounds that fits within the + /// [Slider]. + /// + /// The width is the width of the [Slider] or [RangeSlider], but padded by + /// the max of the overlay and thumb radius. The height is defined by the + /// [SliderThemeData.trackHeight]. + /// + /// The [Rect] is centered both horizontally and vertically within the slider + /// bounds. + Rect getPreferredRect({ + required RenderBox parentBox, + Offset offset = Offset.zero, + required SliderThemeData sliderTheme, + bool isEnabled = false, + bool isDiscrete = false, + }) { + final double thumbWidth = sliderTheme.thumbShape!.getPreferredSize(isEnabled, isDiscrete).width; + final double overlayWidth = sliderTheme.overlayShape!.getPreferredSize(isEnabled, isDiscrete).width; + final double trackHeight = sliderTheme.trackHeight!; + assert(overlayWidth >= 0); + assert(trackHeight >= 0); + + final double trackLeft = offset.dx + math.max(overlayWidth / 2, thumbWidth / 2); + final double trackTop = offset.dy + (parentBox.size.height - trackHeight) / 2; + final double trackRight = trackLeft + parentBox.size.width - math.max(thumbWidth, overlayWidth); + final double trackBottom = trackTop + trackHeight; + // If the parentBox'size less than slider's size the trackRight will be less than trackLeft, so switch them. + return Rect.fromLTRB(math.min(trackLeft, trackRight), trackTop, math.max(trackLeft, trackRight), trackBottom); + } +} + +/// A [Slider] track that's a simple rectangle. +/// +/// It paints a solid colored rectangle, vertically centered in the +/// `parentBox`. The track rectangle extends to the bounds of the `parentBox`, +/// but is padded by the [RoundSliderOverlayShape] radius. The height is defined +/// by the [SliderThemeData.trackHeight]. The color is determined by the +/// [Slider]'s enabled state and the track segment's active state which are +/// defined by: +/// [SliderThemeData.activeTrackColor], +/// [SliderThemeData.inactiveTrackColor], +/// [SliderThemeData.disabledActiveTrackColor], +/// [SliderThemeData.disabledInactiveTrackColor]. +/// +/// {@macro flutter.material.SliderTrackShape.paint.trackSegment} +/// +/// ![A slider widget, consisting of 5 divisions and showing the rectangular slider track shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/rectangular_slider_track_shape.png) +/// +/// See also: +/// +/// * [Slider], for the component that is meant to display this shape. +/// * [SliderThemeData], where an instance of this class is set to inform the +/// slider of the visual details of the its track. +/// * [SliderTrackShape], which can be used to create custom shapes for the +/// [Slider]'s track. +/// * [RoundedRectSliderTrackShape], for a similar track with rounded edges. +class RectangularSliderTrackShape extends SliderTrackShape with BaseSliderTrackShape { + /// Creates a slider track that draws 2 rectangles. + const RectangularSliderTrackShape(); + + @override + void paint( + PaintingContext context, + Offset offset, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double> enableAnimation, + required TextDirection textDirection, + required Offset thumbCenter, + Offset? secondaryOffset, + bool isDiscrete = false, + bool isEnabled = false, + }) { + assert(sliderTheme.disabledActiveTrackColor != null); + assert(sliderTheme.disabledInactiveTrackColor != null); + assert(sliderTheme.activeTrackColor != null); + assert(sliderTheme.inactiveTrackColor != null); + assert(sliderTheme.thumbShape != null); + // If the slider [SliderThemeData.trackHeight] is less than or equal to 0, + // then it makes no difference whether the track is painted or not, + // therefore the painting can be a no-op. + if (sliderTheme.trackHeight! <= 0) { + return; + } + + // Assign the track segment paints, which are left: active, right: inactive, + // but reversed for right to left text. + final ColorTween activeTrackColorTween = ColorTween(begin: sliderTheme.disabledActiveTrackColor, end: sliderTheme.activeTrackColor); + final ColorTween inactiveTrackColorTween = ColorTween(begin: sliderTheme.disabledInactiveTrackColor, end: sliderTheme.inactiveTrackColor); + final Paint activePaint = Paint()..color = activeTrackColorTween.evaluate(enableAnimation)!; + final Paint inactivePaint = Paint()..color = inactiveTrackColorTween.evaluate(enableAnimation)!; + final Paint leftTrackPaint; + final Paint rightTrackPaint; + switch (textDirection) { + case TextDirection.ltr: + leftTrackPaint = activePaint; + rightTrackPaint = inactivePaint; + case TextDirection.rtl: + leftTrackPaint = inactivePaint; + rightTrackPaint = activePaint; + } + + final Rect trackRect = getPreferredRect( + parentBox: parentBox, + offset: offset, + sliderTheme: sliderTheme, + isEnabled: isEnabled, + isDiscrete: isDiscrete, + ); + + final Rect leftTrackSegment = Rect.fromLTRB(trackRect.left, trackRect.top, thumbCenter.dx, trackRect.bottom); + if (!leftTrackSegment.isEmpty) { + context.canvas.drawRect(leftTrackSegment, leftTrackPaint); + } + final Rect rightTrackSegment = Rect.fromLTRB(thumbCenter.dx, trackRect.top, trackRect.right, trackRect.bottom); + if (!rightTrackSegment.isEmpty) { + context.canvas.drawRect(rightTrackSegment, rightTrackPaint); + } + + final bool showSecondaryTrack = (secondaryOffset != null) && + ((textDirection == TextDirection.ltr) + ? (secondaryOffset.dx > thumbCenter.dx) + : (secondaryOffset.dx < thumbCenter.dx)); + + if (showSecondaryTrack) { + final ColorTween secondaryTrackColorTween = ColorTween(begin: sliderTheme.disabledSecondaryActiveTrackColor, end: sliderTheme.secondaryActiveTrackColor); + final Paint secondaryTrackPaint = Paint()..color = secondaryTrackColorTween.evaluate(enableAnimation)!; + final Rect secondaryTrackSegment = Rect.fromLTRB( + (textDirection == TextDirection.ltr) ? thumbCenter.dx : secondaryOffset.dx, + trackRect.top, + (textDirection == TextDirection.ltr) ? secondaryOffset.dx : thumbCenter.dx, + trackRect.bottom, + ); + if (!secondaryTrackSegment.isEmpty) { + context.canvas.drawRect(secondaryTrackSegment, secondaryTrackPaint); + } + } + } +} + +/// The default shape of a [Slider]'s track. +/// +/// It paints a solid colored rectangle with rounded edges, vertically centered +/// in the `parentBox`. The track rectangle extends to the bounds of the +/// `parentBox`, but is padded by the larger of [RoundSliderOverlayShape]'s +/// radius and [RoundSliderThumbShape]'s radius. The height is defined by the +/// [SliderThemeData.trackHeight]. The color is determined by the [Slider]'s +/// enabled state and the track segment's active state which are defined by: +/// [SliderThemeData.activeTrackColor], +/// [SliderThemeData.inactiveTrackColor], +/// [SliderThemeData.disabledActiveTrackColor], +/// [SliderThemeData.disabledInactiveTrackColor]. +/// +/// {@macro flutter.material.SliderTrackShape.paint.trackSegment} +/// +/// ![A slider widget, consisting of 5 divisions and showing the rounded rect slider track shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/rounded_rect_slider_track_shape.png) +/// +/// See also: +/// +/// * [Slider], for the component that is meant to display this shape. +/// * [SliderThemeData], where an instance of this class is set to inform the +/// slider of the visual details of the its track. +/// * [SliderTrackShape], which can be used to create custom shapes for the +/// [Slider]'s track. +/// * [RectangularSliderTrackShape], for a similar track with sharp edges. +class RoundedRectSliderTrackShape extends SliderTrackShape with BaseSliderTrackShape { + /// Create a slider track that draws two rectangles with rounded outer edges. + const RoundedRectSliderTrackShape(); + + @override + void paint( + PaintingContext context, + Offset offset, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double> enableAnimation, + required TextDirection textDirection, + required Offset thumbCenter, + Offset? secondaryOffset, + bool isDiscrete = false, + bool isEnabled = false, + double additionalActiveTrackHeight = 2, + }) { + assert(sliderTheme.disabledActiveTrackColor != null); + assert(sliderTheme.disabledInactiveTrackColor != null); + assert(sliderTheme.activeTrackColor != null); + assert(sliderTheme.inactiveTrackColor != null); + assert(sliderTheme.thumbShape != null); + // If the slider [SliderThemeData.trackHeight] is less than or equal to 0, + // then it makes no difference whether the track is painted or not, + // therefore the painting can be a no-op. + if (sliderTheme.trackHeight == null || sliderTheme.trackHeight! <= 0) { + return; + } + + // Assign the track segment paints, which are leading: active and + // trailing: inactive. + final ColorTween activeTrackColorTween = ColorTween(begin: sliderTheme.disabledActiveTrackColor, end: sliderTheme.activeTrackColor); + final ColorTween inactiveTrackColorTween = ColorTween(begin: sliderTheme.disabledInactiveTrackColor, end: sliderTheme.inactiveTrackColor); + final Paint activePaint = Paint()..color = activeTrackColorTween.evaluate(enableAnimation)!; + final Paint inactivePaint = Paint()..color = inactiveTrackColorTween.evaluate(enableAnimation)!; + final Paint leftTrackPaint; + final Paint rightTrackPaint; + switch (textDirection) { + case TextDirection.ltr: + leftTrackPaint = activePaint; + rightTrackPaint = inactivePaint; + case TextDirection.rtl: + leftTrackPaint = inactivePaint; + rightTrackPaint = activePaint; + } + + final Rect trackRect = getPreferredRect( + parentBox: parentBox, + offset: offset, + sliderTheme: sliderTheme, + isEnabled: isEnabled, + isDiscrete: isDiscrete, + ); + final Radius trackRadius = Radius.circular(trackRect.height / 2); + final Radius activeTrackRadius = Radius.circular((trackRect.height + additionalActiveTrackHeight) / 2); + + context.canvas.drawRRect( + RRect.fromLTRBAndCorners( + trackRect.left, + (textDirection == TextDirection.ltr) ? trackRect.top - (additionalActiveTrackHeight / 2): trackRect.top, + thumbCenter.dx, + (textDirection == TextDirection.ltr) ? trackRect.bottom + (additionalActiveTrackHeight / 2) : trackRect.bottom, + topLeft: (textDirection == TextDirection.ltr) ? activeTrackRadius : trackRadius, + bottomLeft: (textDirection == TextDirection.ltr) ? activeTrackRadius: trackRadius, + ), + leftTrackPaint, + ); + context.canvas.drawRRect( + RRect.fromLTRBAndCorners( + thumbCenter.dx, + (textDirection == TextDirection.rtl) ? trackRect.top - (additionalActiveTrackHeight / 2) : trackRect.top, + trackRect.right, + (textDirection == TextDirection.rtl) ? trackRect.bottom + (additionalActiveTrackHeight / 2) : trackRect.bottom, + topRight: (textDirection == TextDirection.rtl) ? activeTrackRadius : trackRadius, + bottomRight: (textDirection == TextDirection.rtl) ? activeTrackRadius : trackRadius, + ), + rightTrackPaint, + ); + + final bool showSecondaryTrack = (secondaryOffset != null) && + ((textDirection == TextDirection.ltr) + ? (secondaryOffset.dx > thumbCenter.dx) + : (secondaryOffset.dx < thumbCenter.dx)); + + if (showSecondaryTrack) { + final ColorTween secondaryTrackColorTween = ColorTween(begin: sliderTheme.disabledSecondaryActiveTrackColor, end: sliderTheme.secondaryActiveTrackColor); + final Paint secondaryTrackPaint = Paint()..color = secondaryTrackColorTween.evaluate(enableAnimation)!; + if (textDirection == TextDirection.ltr) { + context.canvas.drawRRect( + RRect.fromLTRBAndCorners( + thumbCenter.dx, + trackRect.top, + secondaryOffset.dx, + trackRect.bottom, + topRight: trackRadius, + bottomRight: trackRadius, + ), + secondaryTrackPaint, + ); + } else { + context.canvas.drawRRect( + RRect.fromLTRBAndCorners( + secondaryOffset.dx, + trackRect.top, + thumbCenter.dx, + trackRect.bottom, + topLeft: trackRadius, + bottomLeft: trackRadius, + ), + secondaryTrackPaint, + ); + } + } + } +} + + +/// Base range slider track shape that provides an implementation of [getPreferredRect] for +/// default sizing. +/// +/// The height is set from [SliderThemeData.trackHeight] and the width of the +/// parent box less the larger of the widths of [SliderThemeData.rangeThumbShape] and +/// [SliderThemeData.overlayShape]. +/// +/// See also: +/// +/// * [RectangularRangeSliderTrackShape], which is a track shape with sharp +/// rectangular edges +mixin BaseRangeSliderTrackShape { + /// Returns a rect that represents the track bounds that fits within the + /// [Slider]. + /// + /// The width is the width of the [RangeSlider], but padded by the max + /// of the overlay and thumb radius. The height is defined by the [SliderThemeData.trackHeight]. + /// + /// The [Rect] is centered both horizontally and vertically within the slider + /// bounds. + Rect getPreferredRect({ + required RenderBox parentBox, + Offset offset = Offset.zero, + required SliderThemeData sliderTheme, + bool isEnabled = false, + bool isDiscrete = false, + }) { + assert(sliderTheme.rangeThumbShape != null); + assert(sliderTheme.overlayShape != null); + assert(sliderTheme.trackHeight != null); + final double thumbWidth = sliderTheme.rangeThumbShape!.getPreferredSize(isEnabled, isDiscrete).width; + final double overlayWidth = sliderTheme.overlayShape!.getPreferredSize(isEnabled, isDiscrete).width; + final double trackHeight = sliderTheme.trackHeight!; + assert(overlayWidth >= 0); + assert(trackHeight >= 0); + + final double trackLeft = offset.dx + math.max(overlayWidth / 2, thumbWidth / 2); + final double trackTop = offset.dy + (parentBox.size.height - trackHeight) / 2; + final double trackRight = trackLeft + parentBox.size.width - math.max(thumbWidth, overlayWidth); + final double trackBottom = trackTop + trackHeight; + // If the parentBox'size less than slider's size the trackRight will be less than trackLeft, so switch them. + return Rect.fromLTRB(math.min(trackLeft, trackRight), trackTop, math.max(trackLeft, trackRight), trackBottom); + } +} + +/// A [RangeSlider] track that's a simple rectangle. +/// +/// It paints a solid colored rectangle, vertically centered in the +/// `parentBox`. The track rectangle extends to the bounds of the `parentBox`, +/// but is padded by the [RoundSliderOverlayShape] radius. The height is +/// defined by the [SliderThemeData.trackHeight]. The color is determined by the +/// [Slider]'s enabled state and the track segment's active state which are +/// defined by: +/// [SliderThemeData.activeTrackColor], +/// [SliderThemeData.inactiveTrackColor], +/// [SliderThemeData.disabledActiveTrackColor], +/// [SliderThemeData.disabledInactiveTrackColor]. +/// +/// {@macro flutter.material.RangeSliderTickMarkShape.paint.trackSegment} +/// +/// ![A range slider widget, consisting of 5 divisions and showing the rectangular range slider track shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/rectangular_range_slider_track_shape.png) +/// +/// See also: +/// +/// * [RangeSlider], for the component that is meant to display this shape. +/// * [SliderThemeData], where an instance of this class is set to inform the +/// slider of the visual details of the its track. +/// * [RangeSliderTrackShape], which can be used to create custom shapes for +/// the [RangeSlider]'s track. +/// * [RoundedRectRangeSliderTrackShape], for a similar track with rounded +/// edges. +class RectangularRangeSliderTrackShape extends RangeSliderTrackShape with BaseRangeSliderTrackShape { + /// Create a slider track with rectangular outer edges. + /// + /// The middle track segment is the selected range and is active, and the two + /// outer track segments are inactive. + const RectangularRangeSliderTrackShape(); + + @override + void paint( + PaintingContext context, + Offset offset, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double>? enableAnimation, + required Offset startThumbCenter, + required Offset endThumbCenter, + bool isEnabled = false, + bool isDiscrete = false, + required TextDirection textDirection, + }) { + assert(sliderTheme.disabledActiveTrackColor != null); + assert(sliderTheme.disabledInactiveTrackColor != null); + assert(sliderTheme.activeTrackColor != null); + assert(sliderTheme.inactiveTrackColor != null); + assert(sliderTheme.rangeThumbShape != null); + assert(enableAnimation != null); + // Assign the track segment paints, which are left: active, right: inactive, + // but reversed for right to left text. + final ColorTween activeTrackColorTween = ColorTween(begin: sliderTheme.disabledActiveTrackColor, end: sliderTheme.activeTrackColor); + final ColorTween inactiveTrackColorTween = ColorTween(begin: sliderTheme.disabledInactiveTrackColor, end: sliderTheme.inactiveTrackColor); + final Paint activePaint = Paint()..color = activeTrackColorTween.evaluate(enableAnimation!)!; + final Paint inactivePaint = Paint()..color = inactiveTrackColorTween.evaluate(enableAnimation)!; + + final Offset leftThumbOffset; + final Offset rightThumbOffset; + switch (textDirection) { + case TextDirection.ltr: + leftThumbOffset = startThumbCenter; + rightThumbOffset = endThumbCenter; + case TextDirection.rtl: + leftThumbOffset = endThumbCenter; + rightThumbOffset = startThumbCenter; + } + + final Rect trackRect = getPreferredRect( + parentBox: parentBox, + offset: offset, + sliderTheme: sliderTheme, + isEnabled: isEnabled, + isDiscrete: isDiscrete, + ); + final Rect leftTrackSegment = Rect.fromLTRB(trackRect.left, trackRect.top, leftThumbOffset.dx, trackRect.bottom); + if (!leftTrackSegment.isEmpty) { + context.canvas.drawRect(leftTrackSegment, inactivePaint); + } + final Rect middleTrackSegment = Rect.fromLTRB(leftThumbOffset.dx, trackRect.top, rightThumbOffset.dx, trackRect.bottom); + if (!middleTrackSegment.isEmpty) { + context.canvas.drawRect(middleTrackSegment, activePaint); + } + final Rect rightTrackSegment = Rect.fromLTRB(rightThumbOffset.dx, trackRect.top, trackRect.right, trackRect.bottom); + if (!rightTrackSegment.isEmpty) { + context.canvas.drawRect(rightTrackSegment, inactivePaint); + } + } +} + +/// The default shape of a [RangeSlider]'s track. +/// +/// It paints a solid colored rectangle with rounded edges, vertically centered +/// in the `parentBox`. The track rectangle extends to the bounds of the +/// `parentBox`, but is padded by the larger of [RoundSliderOverlayShape]'s +/// radius and [RoundRangeSliderThumbShape]'s radius. The height is defined by +/// the [SliderThemeData.trackHeight]. The color is determined by the +/// [RangeSlider]'s enabled state and the track segment's active state which are +/// defined by: +/// [SliderThemeData.activeTrackColor], +/// [SliderThemeData.inactiveTrackColor], +/// [SliderThemeData.disabledActiveTrackColor], +/// [SliderThemeData.disabledInactiveTrackColor]. +/// +/// {@macro flutter.material.RangeSliderTickMarkShape.paint.trackSegment} +/// +/// ![A range slider widget, consisting of 5 divisions and showing the rounded rect range slider track shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/rounded_rect_range_slider_track_shape.png) +/// +/// See also: +/// +/// * [RangeSlider], for the component that is meant to display this shape. +/// * [SliderThemeData], where an instance of this class is set to inform the +/// slider of the visual details of the its track. +/// * [RangeSliderTrackShape], which can be used to create custom shapes for +/// the [RangeSlider]'s track. +/// * [RectangularRangeSliderTrackShape], for a similar track with sharp edges. +class RoundedRectRangeSliderTrackShape extends RangeSliderTrackShape with BaseRangeSliderTrackShape { + /// Create a slider track with rounded outer edges. + /// + /// The middle track segment is the selected range and is active, and the two + /// outer track segments are inactive. + const RoundedRectRangeSliderTrackShape(); + + @override + void paint( + PaintingContext context, + Offset offset, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double> enableAnimation, + required Offset startThumbCenter, + required Offset endThumbCenter, + bool isEnabled = false, + bool isDiscrete = false, + required TextDirection textDirection, + double additionalActiveTrackHeight = 2, + }) { + assert(sliderTheme.disabledActiveTrackColor != null); + assert(sliderTheme.disabledInactiveTrackColor != null); + assert(sliderTheme.activeTrackColor != null); + assert(sliderTheme.inactiveTrackColor != null); + assert(sliderTheme.rangeThumbShape != null); + + if (sliderTheme.trackHeight == null || sliderTheme.trackHeight! <= 0) { + return; + } + + // Assign the track segment paints, which are left: active, right: inactive, + // but reversed for right to left text. + final ColorTween activeTrackColorTween = ColorTween( + begin: sliderTheme.disabledActiveTrackColor, + end: sliderTheme.activeTrackColor, + ); + final ColorTween inactiveTrackColorTween = ColorTween( + begin: sliderTheme.disabledInactiveTrackColor, + end: sliderTheme.inactiveTrackColor, + ); + final Paint activePaint = Paint() + ..color = activeTrackColorTween.evaluate(enableAnimation)!; + final Paint inactivePaint = Paint() + ..color = inactiveTrackColorTween.evaluate(enableAnimation)!; + + final Offset leftThumbOffset; + final Offset rightThumbOffset; + switch (textDirection) { + case TextDirection.ltr: + leftThumbOffset = startThumbCenter; + rightThumbOffset = endThumbCenter; + case TextDirection.rtl: + leftThumbOffset = endThumbCenter; + rightThumbOffset = startThumbCenter; + } + final Size thumbSize = sliderTheme.rangeThumbShape!.getPreferredSize(isEnabled, isDiscrete); + final double thumbRadius = thumbSize.width / 2; + assert(thumbRadius > 0); + + final Rect trackRect = getPreferredRect( + parentBox: parentBox, + offset: offset, + sliderTheme: sliderTheme, + isEnabled: isEnabled, + isDiscrete: isDiscrete, + ); + + final Radius trackRadius = Radius.circular(trackRect.height / 2); + + context.canvas.drawRRect( + RRect.fromLTRBAndCorners( + trackRect.left, + trackRect.top, + leftThumbOffset.dx, + trackRect.bottom, + topLeft: trackRadius, + bottomLeft: trackRadius, + ), + inactivePaint, + ); + context.canvas.drawRect( + Rect.fromLTRB( + leftThumbOffset.dx, + trackRect.top - (additionalActiveTrackHeight / 2), + rightThumbOffset.dx, + trackRect.bottom + (additionalActiveTrackHeight / 2), + ), + activePaint, + ); + context.canvas.drawRRect( + RRect.fromLTRBAndCorners( + rightThumbOffset.dx, + trackRect.top, + trackRect.right, + trackRect.bottom, + topRight: trackRadius, + bottomRight: trackRadius, + ), + inactivePaint, + ); + } +} + +/// The default shape of each [Slider] tick mark. +/// +/// Tick marks are only displayed if the slider is discrete, which can be done +/// by setting the [Slider.divisions] to an integer value. +/// +/// It paints a solid circle, centered in the on the track. +/// The color is determined by the [Slider]'s enabled state and track's active +/// states. These colors are defined in: +/// [SliderThemeData.activeTrackColor], +/// [SliderThemeData.inactiveTrackColor], +/// [SliderThemeData.disabledActiveTrackColor], +/// [SliderThemeData.disabledInactiveTrackColor]. +/// +/// ![A slider widget, consisting of 5 divisions and showing the round slider tick mark shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/rounded_slider_tick_mark_shape.png) +/// +/// See also: +/// +/// * [Slider], which includes tick marks defined by this shape. +/// * [SliderTheme], which can be used to configure the tick mark shape of all +/// sliders in a widget subtree. +class RoundSliderTickMarkShape extends SliderTickMarkShape { + /// Create a slider tick mark that draws a circle. + const RoundSliderTickMarkShape({ + this.tickMarkRadius, + }); + + /// The preferred radius of the round tick mark. + /// + /// If it is not provided, then 1/4 of the [SliderThemeData.trackHeight] is used. + final double? tickMarkRadius; + + @override + Size getPreferredSize({ + required SliderThemeData sliderTheme, + required bool isEnabled, + }) { + assert(sliderTheme.trackHeight != null); + // The tick marks are tiny circles. If no radius is provided, then the + // radius is defaulted to be a fraction of the + // [SliderThemeData.trackHeight]. The fraction is 1/4. + return Size.fromRadius(tickMarkRadius ?? sliderTheme.trackHeight! / 4); + } + + @override + void paint( + PaintingContext context, + Offset center, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double> enableAnimation, + required TextDirection textDirection, + required Offset thumbCenter, + required bool isEnabled, + }) { + assert(sliderTheme.disabledActiveTickMarkColor != null); + assert(sliderTheme.disabledInactiveTickMarkColor != null); + assert(sliderTheme.activeTickMarkColor != null); + assert(sliderTheme.inactiveTickMarkColor != null); + // The paint color of the tick mark depends on its position relative + // to the thumb and the text direction. + Color? begin; + Color? end; + switch (textDirection) { + case TextDirection.ltr: + final bool isTickMarkRightOfThumb = center.dx > thumbCenter.dx; + begin = isTickMarkRightOfThumb ? sliderTheme.disabledInactiveTickMarkColor : sliderTheme.disabledActiveTickMarkColor; + end = isTickMarkRightOfThumb ? sliderTheme.inactiveTickMarkColor : sliderTheme.activeTickMarkColor; + case TextDirection.rtl: + final bool isTickMarkLeftOfThumb = center.dx < thumbCenter.dx; + begin = isTickMarkLeftOfThumb ? sliderTheme.disabledInactiveTickMarkColor : sliderTheme.disabledActiveTickMarkColor; + end = isTickMarkLeftOfThumb ? sliderTheme.inactiveTickMarkColor : sliderTheme.activeTickMarkColor; + } + final Paint paint = Paint()..color = ColorTween(begin: begin, end: end).evaluate(enableAnimation)!; + + // The tick marks are tiny circles that are the same height as the track. + final double tickMarkRadius = getPreferredSize( + isEnabled: isEnabled, + sliderTheme: sliderTheme, + ).width / 2; + if (tickMarkRadius > 0) { + context.canvas.drawCircle(center, tickMarkRadius, paint); + } + } +} + +/// The default shape of each [RangeSlider] tick mark. +/// +/// Tick marks are only displayed if the slider is discrete, which can be done +/// by setting the [RangeSlider.divisions] to an integer value. +/// +/// It paints a solid circle, centered on the track. +/// The color is determined by the [Slider]'s enabled state and track's active +/// states. These colors are defined in: +/// [SliderThemeData.activeTrackColor], +/// [SliderThemeData.inactiveTrackColor], +/// [SliderThemeData.disabledActiveTrackColor], +/// [SliderThemeData.disabledInactiveTrackColor]. +/// +/// ![A slider widget, consisting of 5 divisions and showing the round range slider tick mark shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/round_range_slider_tick_mark_shape.png ) +/// +/// See also: +/// +/// * [RangeSlider], which includes tick marks defined by this shape. +/// * [SliderTheme], which can be used to configure the tick mark shape of all +/// sliders in a widget subtree. +class RoundRangeSliderTickMarkShape extends RangeSliderTickMarkShape { + /// Create a range slider tick mark that draws a circle. + const RoundRangeSliderTickMarkShape({ + this.tickMarkRadius, + }); + + /// The preferred radius of the round tick mark. + /// + /// If it is not provided, then 1/4 of the [SliderThemeData.trackHeight] is used. + final double? tickMarkRadius; + + @override + Size getPreferredSize({ + required SliderThemeData sliderTheme, + bool isEnabled = false, + }) { + assert(sliderTheme.trackHeight != null); + return Size.fromRadius(tickMarkRadius ?? sliderTheme.trackHeight! / 4); + } + + @override + void paint( + PaintingContext context, + Offset center, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double> enableAnimation, + required Offset startThumbCenter, + required Offset endThumbCenter, + bool isEnabled = false, + required TextDirection textDirection, + }) { + assert(sliderTheme.disabledActiveTickMarkColor != null); + assert(sliderTheme.disabledInactiveTickMarkColor != null); + assert(sliderTheme.activeTickMarkColor != null); + assert(sliderTheme.inactiveTickMarkColor != null); + + final bool isBetweenThumbs; + switch (textDirection) { + case TextDirection.ltr: + isBetweenThumbs = startThumbCenter.dx < center.dx && center.dx < endThumbCenter.dx; + case TextDirection.rtl: + isBetweenThumbs = endThumbCenter.dx < center.dx && center.dx < startThumbCenter.dx; + } + final Color? begin = isBetweenThumbs ? sliderTheme.disabledActiveTickMarkColor : sliderTheme.disabledInactiveTickMarkColor; + final Color? end = isBetweenThumbs ? sliderTheme.activeTickMarkColor : sliderTheme.inactiveTickMarkColor; + final Paint paint = Paint()..color = ColorTween(begin: begin, end: end).evaluate(enableAnimation)!; + + // The tick marks are tiny circles that are the same height as the track. + final double tickMarkRadius = getPreferredSize( + isEnabled: isEnabled, + sliderTheme: sliderTheme, + ).width / 2; + if (tickMarkRadius > 0) { + context.canvas.drawCircle(center, tickMarkRadius, paint); + } + } +} + +/// A special version of [SliderTickMarkShape] that has a zero size and paints +/// nothing. +/// +/// This class is used to create a special instance of a [SliderTickMarkShape] +/// that will not paint any tick mark shape. A static reference is stored in +/// [SliderTickMarkShape.noTickMark]. When this value is specified for +/// [SliderThemeData.tickMarkShape], the tick mark painting is skipped. +class _EmptySliderTickMarkShape extends SliderTickMarkShape { + @override + Size getPreferredSize({ + required SliderThemeData sliderTheme, + required bool isEnabled, + }) { + return Size.zero; + } + + @override + void paint( + PaintingContext context, + Offset center, { + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required Animation<double> enableAnimation, + required Offset thumbCenter, + required bool isEnabled, + required TextDirection textDirection, + }) { + // no-op. + } +} + +/// A special version of [SliderComponentShape] that has a zero size and paints +/// nothing. +/// +/// This class is used to create a special instance of a [SliderComponentShape] +/// that will not paint any component shape. A static reference is stored in +/// [SliderTickMarkShape.noThumb] and [SliderTickMarkShape.noOverlay]. When this value +/// is specified for [SliderThemeData.thumbShape], the thumb painting is +/// skipped. When this value is specified for [SliderThemeData.overlayShape], +/// the overlay painting is skipped. +class _EmptySliderComponentShape extends SliderComponentShape { + @override + Size getPreferredSize(bool isEnabled, bool isDiscrete) => Size.zero; + + @override + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + required bool isDiscrete, + required TextPainter labelPainter, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required TextDirection textDirection, + required double value, + required double textScaleFactor, + required Size sizeWithOverflow, + }) { + // no-op. + } +} + +/// The default shape of a [Slider]'s thumb. +/// +/// There is a shadow for the resting, pressed, hovered, and focused state. +/// +/// ![A slider widget, consisting of 5 divisions and showing the round slider thumb shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/round_slider_thumb_shape.png) +/// +/// See also: +/// +/// * [Slider], which includes a thumb defined by this shape. +/// * [SliderTheme], which can be used to configure the thumb shape of all +/// sliders in a widget subtree. +class RoundSliderThumbShape extends SliderComponentShape { + /// Create a slider thumb that draws a circle. + const RoundSliderThumbShape({ + this.enabledThumbRadius = 10.0, + this.disabledThumbRadius, + this.elevation = 1.0, + this.pressedElevation = 6.0, + }); + + /// The preferred radius of the round thumb shape when the slider is enabled. + /// + /// If it is not provided, then the Material Design default of 10 is used. + final double enabledThumbRadius; + + /// The preferred radius of the round thumb shape when the slider is disabled. + /// + /// If no disabledRadius is provided, then it is equal to the + /// [enabledThumbRadius] + final double? disabledThumbRadius; + double get _disabledThumbRadius => disabledThumbRadius ?? enabledThumbRadius; + + /// The resting elevation adds shadow to the unpressed thumb. + /// + /// The default is 1. + /// + /// Use 0 for no shadow. The higher the value, the larger the shadow. For + /// example, a value of 12 will create a very large shadow. + /// + final double elevation; + + /// The pressed elevation adds shadow to the pressed thumb. + /// + /// The default is 6. + /// + /// Use 0 for no shadow. The higher the value, the larger the shadow. For + /// example, a value of 12 will create a very large shadow. + final double pressedElevation; + + @override + Size getPreferredSize(bool isEnabled, bool isDiscrete) { + return Size.fromRadius(isEnabled ? enabledThumbRadius : _disabledThumbRadius); + } + + @override + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + required bool isDiscrete, + required TextPainter labelPainter, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required TextDirection textDirection, + required double value, + required double textScaleFactor, + required Size sizeWithOverflow, + }) { + assert(sliderTheme.disabledThumbColor != null); + assert(sliderTheme.thumbColor != null); + + final Canvas canvas = context.canvas; + final Tween<double> radiusTween = Tween<double>( + begin: _disabledThumbRadius, + end: enabledThumbRadius, + ); + final ColorTween colorTween = ColorTween( + begin: sliderTheme.disabledThumbColor, + end: sliderTheme.thumbColor, + ); + + final Color color = colorTween.evaluate(enableAnimation)!; + final double radius = radiusTween.evaluate(enableAnimation); + + final Tween<double> elevationTween = Tween<double>( + begin: elevation, + end: pressedElevation, + ); + + final double evaluatedElevation = elevationTween.evaluate(activationAnimation); + final Path path = Path() + ..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2); + + bool paintShadows = true; + assert(() { + if (debugDisableShadows) { + _debugDrawShadow(canvas, path, evaluatedElevation); + paintShadows = false; + } + return true; + }()); + + if (paintShadows) { + canvas.drawShadow(path, Colors.black, evaluatedElevation, true); + } + + canvas.drawCircle( + center, + radius, + Paint()..color = color, + ); + } +} + +/// The default shape of a [RangeSlider]'s thumbs. +/// +/// There is a shadow for the resting and pressed state. +/// +/// ![A slider widget, consisting of 5 divisions and showing the round range slider thumb shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/round_range_slider_thumb_shape.png) +/// +/// See also: +/// +/// * [RangeSlider], which includes thumbs defined by this shape. +/// * [SliderTheme], which can be used to configure the thumb shapes of all +/// range sliders in a widget subtree. +class RoundRangeSliderThumbShape extends RangeSliderThumbShape { + /// Create a slider thumb that draws a circle. + const RoundRangeSliderThumbShape({ + this.enabledThumbRadius = 10.0, + this.disabledThumbRadius, + this.elevation = 1.0, + this.pressedElevation = 6.0, + }); + + /// The preferred radius of the round thumb shape when the slider is enabled. + /// + /// If it is not provided, then the Material Design default of 10 is used. + final double enabledThumbRadius; + + /// The preferred radius of the round thumb shape when the slider is disabled. + /// + /// If no disabledRadius is provided, then it is equal to the + /// [enabledThumbRadius]. + final double? disabledThumbRadius; + double get _disabledThumbRadius => disabledThumbRadius ?? enabledThumbRadius; + + /// The resting elevation adds shadow to the unpressed thumb. + /// + /// The default is 1. + final double elevation; + + /// The pressed elevation adds shadow to the pressed thumb. + /// + /// The default is 6. + final double pressedElevation; + + @override + Size getPreferredSize(bool isEnabled, bool isDiscrete) { + return Size.fromRadius(isEnabled ? enabledThumbRadius : _disabledThumbRadius); + } + + @override + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + bool isDiscrete = false, + bool isEnabled = false, + bool? isOnTop, + required SliderThemeData sliderTheme, + TextDirection? textDirection, + Thumb? thumb, + bool? isPressed, + }) { + assert(sliderTheme.showValueIndicator != null); + assert(sliderTheme.overlappingShapeStrokeColor != null); + final Canvas canvas = context.canvas; + final Tween<double> radiusTween = Tween<double>( + begin: _disabledThumbRadius, + end: enabledThumbRadius, + ); + final ColorTween colorTween = ColorTween( + begin: sliderTheme.disabledThumbColor, + end: sliderTheme.thumbColor, + ); + final double radius = radiusTween.evaluate(enableAnimation); + final Tween<double> elevationTween = Tween<double>( + begin: elevation, + end: pressedElevation, + ); + + // Add a stroke of 1dp around the circle if this thumb would overlap + // the other thumb. + if (isOnTop ?? false) { + final Paint strokePaint = Paint() + ..color = sliderTheme.overlappingShapeStrokeColor! + ..strokeWidth = 1.0 + ..style = PaintingStyle.stroke; + canvas.drawCircle(center, radius, strokePaint); + } + + final Color color = colorTween.evaluate(enableAnimation)!; + + final double evaluatedElevation = isPressed! ? elevationTween.evaluate(activationAnimation) : elevation; + final Path shadowPath = Path() + ..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2); + + bool paintShadows = true; + assert(() { + if (debugDisableShadows) { + _debugDrawShadow(canvas, shadowPath, evaluatedElevation); + paintShadows = false; + } + return true; + }()); + + if (paintShadows) { + canvas.drawShadow(shadowPath, Colors.black, evaluatedElevation, true); + } + + canvas.drawCircle( + center, + radius, + Paint()..color = color, + ); + } +} + +/// The default shape of a [Slider]'s thumb overlay. +/// +/// The shape of the overlay is a circle with the same center as the thumb, but +/// with a larger radius. It animates to full size when the thumb is pressed, +/// and animates back down to size 0 when it is released. It is painted behind +/// the thumb, and is expected to extend beyond the bounds of the thumb so that +/// it is visible. +/// +/// The overlay color is defined by [SliderThemeData.overlayColor]. +/// +/// See also: +/// +/// * [Slider], which includes an overlay defined by this shape. +/// * [SliderTheme], which can be used to configure the overlay shape of all +/// sliders in a widget subtree. +class RoundSliderOverlayShape extends SliderComponentShape { + /// Create a slider thumb overlay that draws a circle. + const RoundSliderOverlayShape({ this.overlayRadius = 24.0 }); + + /// The preferred radius of the round thumb shape when enabled. + /// + /// If it is not provided, then half of the [SliderThemeData.trackHeight] is + /// used. + final double overlayRadius; + + @override + Size getPreferredSize(bool isEnabled, bool isDiscrete) { + return Size.fromRadius(overlayRadius); + } + + @override + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + required bool isDiscrete, + required TextPainter labelPainter, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required TextDirection textDirection, + required double value, + required double textScaleFactor, + required Size sizeWithOverflow, + }) { + + final Canvas canvas = context.canvas; + final Tween<double> radiusTween = Tween<double>( + begin: 0.0, + end: overlayRadius, + ); + + canvas.drawCircle( + center, + radiusTween.evaluate(activationAnimation), + Paint()..color = sliderTheme.overlayColor!, + ); + } +} + +/// The default shape of a [Slider]'s value indicator. +/// +/// ![A slider widget, consisting of 5 divisions and showing the rectangular slider value indicator shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/rectangular_slider_value_indicator_shape.png) +/// +/// See also: +/// +/// * [Slider], which includes a value indicator defined by this shape. +/// * [SliderTheme], which can be used to configure the slider value indicator +/// of all sliders in a widget subtree. +class RectangularSliderValueIndicatorShape extends SliderComponentShape { + /// Create a slider value indicator that resembles a rectangular tooltip. + const RectangularSliderValueIndicatorShape(); + + static const _RectangularSliderValueIndicatorPathPainter _pathPainter = _RectangularSliderValueIndicatorPathPainter(); + + @override + Size getPreferredSize( + bool isEnabled, + bool isDiscrete, { + TextPainter? labelPainter, + double? textScaleFactor, + }) { + assert(labelPainter != null); + assert(textScaleFactor != null && textScaleFactor >= 0); + return _pathPainter.getPreferredSize(labelPainter!, textScaleFactor!); + } + + @override + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + required bool isDiscrete, + required TextPainter labelPainter, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required TextDirection textDirection, + required double value, + required double textScaleFactor, + required Size sizeWithOverflow, + }) { + final Canvas canvas = context.canvas; + final double scale = activationAnimation.value; + _pathPainter.paint( + parentBox: parentBox, + canvas: canvas, + center: center, + scale: scale, + labelPainter: labelPainter, + textScaleFactor: textScaleFactor, + sizeWithOverflow: sizeWithOverflow, + backgroundPaintColor: sliderTheme.valueIndicatorColor!, + strokePaintColor: sliderTheme.valueIndicatorStrokeColor, + ); + } +} + +/// The default shape of a [RangeSlider]'s value indicators. +/// +/// ![A slider widget, consisting of 5 divisions and showing the rectangular range slider value indicator shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/rectangular_range_slider_value_indicator_shape.png) +/// +/// See also: +/// +/// * [RangeSlider], which includes value indicators defined by this shape. +/// * [SliderTheme], which can be used to configure the range slider value +/// indicator of all sliders in a widget subtree. +class RectangularRangeSliderValueIndicatorShape + extends RangeSliderValueIndicatorShape { + /// Create a range slider value indicator that resembles a rectangular tooltip. + const RectangularRangeSliderValueIndicatorShape(); + + static const _RectangularSliderValueIndicatorPathPainter _pathPainter = _RectangularSliderValueIndicatorPathPainter(); + + @override + Size getPreferredSize( + bool isEnabled, + bool isDiscrete, { + required TextPainter labelPainter, + required double textScaleFactor, + }) { + assert(textScaleFactor >= 0); + return _pathPainter.getPreferredSize(labelPainter, textScaleFactor); + } + + @override + double getHorizontalShift({ + RenderBox? parentBox, + Offset? center, + TextPainter? labelPainter, + Animation<double>? activationAnimation, + double? textScaleFactor, + Size? sizeWithOverflow, + }) { + return _pathPainter.getHorizontalShift( + parentBox: parentBox!, + center: center!, + labelPainter: labelPainter!, + textScaleFactor: textScaleFactor!, + sizeWithOverflow: sizeWithOverflow!, + scale: activationAnimation!.value, + ); + } + + @override + void paint( + PaintingContext context, + Offset center, { + Animation<double>? activationAnimation, + Animation<double>? enableAnimation, + bool? isDiscrete, + bool? isOnTop, + TextPainter? labelPainter, + double? textScaleFactor, + Size? sizeWithOverflow, + RenderBox? parentBox, + SliderThemeData? sliderTheme, + TextDirection? textDirection, + double? value, + Thumb? thumb, + }) { + final Canvas canvas = context.canvas; + final double scale = activationAnimation!.value; + _pathPainter.paint( + parentBox: parentBox!, + canvas: canvas, + center: center, + scale: scale, + labelPainter: labelPainter!, + textScaleFactor: textScaleFactor!, + sizeWithOverflow: sizeWithOverflow!, + backgroundPaintColor: sliderTheme!.valueIndicatorColor!, + strokePaintColor: isOnTop! ? sliderTheme.overlappingShapeStrokeColor : sliderTheme.valueIndicatorStrokeColor, + ); + } +} + +class _RectangularSliderValueIndicatorPathPainter { + const _RectangularSliderValueIndicatorPathPainter(); + + static const double _triangleHeight = 8.0; + static const double _labelPadding = 16.0; + static const double _preferredHeight = 32.0; + static const double _minLabelWidth = 16.0; + static const double _bottomTipYOffset = 14.0; + static const double _preferredHalfHeight = _preferredHeight / 2; + static const double _upperRectRadius = 4; + + Size getPreferredSize( + TextPainter labelPainter, + double textScaleFactor, + ) { + return Size( + _upperRectangleWidth(labelPainter, 1, textScaleFactor), + labelPainter.height + _labelPadding, + ); + } + + double getHorizontalShift({ + required RenderBox parentBox, + required Offset center, + required TextPainter labelPainter, + required double textScaleFactor, + required Size sizeWithOverflow, + required double scale, + }) { + assert(!sizeWithOverflow.isEmpty); + + const double edgePadding = 8.0; + final double rectangleWidth = _upperRectangleWidth(labelPainter, scale, textScaleFactor); + /// Value indicator draws on the Overlay and by using the global Offset + /// we are making sure we use the bounds of the Overlay instead of the Slider. + final Offset globalCenter = parentBox.localToGlobal(center); + + // The rectangle must be shifted towards the center so that it minimizes the + // chance of it rendering outside the bounds of the render box. If the shift + // is negative, then the lobe is shifted from right to left, and if it is + // positive, then the lobe is shifted from left to right. + final double overflowLeft = math.max(0, rectangleWidth / 2 - globalCenter.dx + edgePadding); + final double overflowRight = math.max(0, rectangleWidth / 2 - (sizeWithOverflow.width - globalCenter.dx - edgePadding)); + + if (rectangleWidth < sizeWithOverflow.width) { + return overflowLeft - overflowRight; + } else if (overflowLeft - overflowRight > 0) { + return overflowLeft - (edgePadding * textScaleFactor); + } else { + return -overflowRight + (edgePadding * textScaleFactor); + } + } + + double _upperRectangleWidth(TextPainter labelPainter, double scale, double textScaleFactor) { + final double unscaledWidth = math.max(_minLabelWidth * textScaleFactor, labelPainter.width) + _labelPadding * 2; + return unscaledWidth * scale; + } + + void paint({ + required RenderBox parentBox, + required Canvas canvas, + required Offset center, + required double scale, + required TextPainter labelPainter, + required double textScaleFactor, + required Size sizeWithOverflow, + required Color backgroundPaintColor, + Color? strokePaintColor, + }) { + if (scale == 0.0) { + // Zero scale essentially means "do not draw anything", so it's safe to just return. + return; + } + assert(!sizeWithOverflow.isEmpty); + + final double rectangleWidth = _upperRectangleWidth(labelPainter, scale, textScaleFactor); + final double horizontalShift = getHorizontalShift( + parentBox: parentBox, + center: center, + labelPainter: labelPainter, + textScaleFactor: textScaleFactor, + sizeWithOverflow: sizeWithOverflow, + scale: scale, + ); + + final double rectHeight = labelPainter.height + _labelPadding; + final Rect upperRect = Rect.fromLTWH( + -rectangleWidth / 2 + horizontalShift, + -_triangleHeight - rectHeight, + rectangleWidth, + rectHeight, + ); + + final Path trianglePath = Path() + ..lineTo(-_triangleHeight, -_triangleHeight) + ..lineTo(_triangleHeight, -_triangleHeight) + ..close(); + final Paint fillPaint = Paint()..color = backgroundPaintColor; + final RRect upperRRect = RRect.fromRectAndRadius(upperRect, const Radius.circular(_upperRectRadius)); + trianglePath.addRRect(upperRRect); + + canvas.save(); + // Prepare the canvas for the base of the tooltip, which is relative to the + // center of the thumb. + canvas.translate(center.dx, center.dy - _bottomTipYOffset); + canvas.scale(scale, scale); + if (strokePaintColor != null) { + final Paint strokePaint = Paint() + ..color = strokePaintColor + ..strokeWidth = 1.0 + ..style = PaintingStyle.stroke; + canvas.drawPath(trianglePath, strokePaint); + } + canvas.drawPath(trianglePath, fillPaint); + + // The label text is centered within the value indicator. + final double bottomTipToUpperRectTranslateY = -_preferredHalfHeight / 2 - upperRect.height; + canvas.translate(0, bottomTipToUpperRectTranslateY); + final Offset boxCenter = Offset(horizontalShift, upperRect.height / 2); + final Offset halfLabelPainterOffset = Offset(labelPainter.width / 2, labelPainter.height / 2); + final Offset labelOffset = boxCenter - halfLabelPainterOffset; + labelPainter.paint(canvas, labelOffset); + canvas.restore(); + } +} + +/// A variant shape of a [Slider]'s value indicator . The value indicator is in +/// the shape of an upside-down pear. +/// +/// ![A slider widget, consisting of 5 divisions and showing the paddle slider value indicator shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/paddle_slider_value_indicator_shape.png) +/// +/// See also: +/// +/// * [Slider], which includes a value indicator defined by this shape. +/// * [SliderTheme], which can be used to configure the slider value indicator +/// of all sliders in a widget subtree. +class PaddleSliderValueIndicatorShape extends SliderComponentShape { + /// Create a slider value indicator in the shape of an upside-down pear. + const PaddleSliderValueIndicatorShape(); + + static const _PaddleSliderValueIndicatorPathPainter _pathPainter = _PaddleSliderValueIndicatorPathPainter(); + + @override + Size getPreferredSize( + bool isEnabled, + bool isDiscrete, { + TextPainter? labelPainter, + double? textScaleFactor, + }) { + assert(labelPainter != null); + assert(textScaleFactor != null && textScaleFactor >= 0); + return _pathPainter.getPreferredSize(labelPainter!, textScaleFactor!); + } + + @override + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + required bool isDiscrete, + required TextPainter labelPainter, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required TextDirection textDirection, + required double value, + required double textScaleFactor, + required Size sizeWithOverflow, + }) { + assert(!sizeWithOverflow.isEmpty); + final ColorTween enableColor = ColorTween( + begin: sliderTheme.disabledThumbColor, + end: sliderTheme.valueIndicatorColor, + ); + _pathPainter.paint( + context.canvas, + center, + Paint()..color = enableColor.evaluate(enableAnimation)!, + activationAnimation.value, + labelPainter, + textScaleFactor, + sizeWithOverflow, + sliderTheme.valueIndicatorStrokeColor, + ); + } +} + +/// A variant shape of a [RangeSlider]'s value indicators. The value indicator +/// is in the shape of an upside-down pear. +/// +/// ![A slider widget, consisting of 5 divisions and showing the paddle range slider value indicator shape.] +/// (https://flutter.github.io/assets-for-api-docs/assets/material/paddle_range_slider_value_indicator_shape.png) +/// +/// See also: +/// +/// * [RangeSlider], which includes value indicators defined by this shape. +/// * [SliderTheme], which can be used to configure the range slider value +/// indicator of all sliders in a widget subtree. +class PaddleRangeSliderValueIndicatorShape extends RangeSliderValueIndicatorShape { + /// Create a slider value indicator in the shape of an upside-down pear. + const PaddleRangeSliderValueIndicatorShape(); + + static const _PaddleSliderValueIndicatorPathPainter _pathPainter = _PaddleSliderValueIndicatorPathPainter(); + + @override + Size getPreferredSize( + bool isEnabled, + bool isDiscrete, { + required TextPainter labelPainter, + required double textScaleFactor, + }) { + assert(textScaleFactor >= 0); + return _pathPainter.getPreferredSize(labelPainter, textScaleFactor); + } + + @override + double getHorizontalShift({ + RenderBox? parentBox, + Offset? center, + TextPainter? labelPainter, + Animation<double>? activationAnimation, + double? textScaleFactor, + Size? sizeWithOverflow, + }) { + return _pathPainter.getHorizontalShift( + center: center!, + labelPainter: labelPainter!, + scale: activationAnimation!.value, + textScaleFactor: textScaleFactor!, + sizeWithOverflow: sizeWithOverflow!, + ); + } + + @override + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + bool? isDiscrete, + bool isOnTop = false, + required TextPainter labelPainter, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + TextDirection? textDirection, + Thumb? thumb, + double? value, + double? textScaleFactor, + Size? sizeWithOverflow, + }) { + assert(!sizeWithOverflow!.isEmpty); + final ColorTween enableColor = ColorTween( + begin: sliderTheme.disabledThumbColor, + end: sliderTheme.valueIndicatorColor, + ); + // Add a stroke of 1dp around the top paddle. + _pathPainter.paint( + context.canvas, + center, + Paint()..color = enableColor.evaluate(enableAnimation)!, + activationAnimation.value, + labelPainter, + textScaleFactor!, + sizeWithOverflow!, + isOnTop ? sliderTheme.overlappingShapeStrokeColor : sliderTheme.valueIndicatorStrokeColor, + ); + } +} + +class _PaddleSliderValueIndicatorPathPainter { + const _PaddleSliderValueIndicatorPathPainter(); + + // These constants define the shape of the default value indicator. + // The value indicator changes shape based on the size of + // the label: The top lobe spreads horizontally, and the + // top arc on the neck moves down to keep it merging smoothly + // with the top lobe as it expands. + + // Radius of the top lobe of the value indicator. + static const double _topLobeRadius = 16.0; + static const double _minLabelWidth = 16.0; + // Radius of the bottom lobe of the value indicator. + static const double _bottomLobeRadius = 10.0; + static const double _labelPadding = 8.0; + static const double _distanceBetweenTopBottomCenters = 40.0; + static const double _middleNeckWidth = 3.0; + static const double _bottomNeckRadius = 4.5; + // The base of the triangle between the top lobe center and the centers of + // the two top neck arcs. + static const double _neckTriangleBase = _topNeckRadius + _middleNeckWidth / 2; + static const double _rightBottomNeckCenterX = _middleNeckWidth / 2 + _bottomNeckRadius; + static const double _rightBottomNeckAngleStart = math.pi; + static const Offset _topLobeCenter = Offset(0.0, -_distanceBetweenTopBottomCenters); + static const double _topNeckRadius = 13.0; + // The length of the hypotenuse of the triangle formed by the center + // of the left top lobe arc and the center of the top left neck arc. + // Used to calculate the position of the center of the arc. + static const double _neckTriangleHypotenuse = _topLobeRadius + _topNeckRadius; + // Some convenience values to help readability. + static const double _twoSeventyDegrees = 3.0 * math.pi / 2.0; + static const double _ninetyDegrees = math.pi / 2.0; + static const double _thirtyDegrees = math.pi / 6.0; + static const double _preferredHeight = _distanceBetweenTopBottomCenters + _topLobeRadius + _bottomLobeRadius; + // Set to true if you want a rectangle to be drawn around the label bubble. + // This helps with building tests that check that the label draws in the right + // place (because it prints the rect in the failed test output). It should not + // be checked in while set to "true". + static const bool _debuggingLabelLocation = false; + + Size getPreferredSize( + TextPainter labelPainter, + double textScaleFactor, + ) { + assert(textScaleFactor >= 0); + final double width = math.max(_minLabelWidth * textScaleFactor, labelPainter.width) + _labelPadding * 2 * textScaleFactor; + return Size(width, _preferredHeight * textScaleFactor); + } + + // Adds an arc to the path that has the attributes passed in. This is + // a convenience to make adding arcs have less boilerplate. + static void _addArc(Path path, Offset center, double radius, double startAngle, double endAngle) { + assert(center.isFinite); + final Rect arcRect = Rect.fromCircle(center: center, radius: radius); + path.arcTo(arcRect, startAngle, endAngle - startAngle, false); + } + + double getHorizontalShift({ + required Offset center, + required TextPainter labelPainter, + required double scale, + required double textScaleFactor, + required Size sizeWithOverflow, + }) { + assert(!sizeWithOverflow.isEmpty); + final double inverseTextScale = textScaleFactor != 0 ? 1.0 / textScaleFactor : 0.0; + final double labelHalfWidth = labelPainter.width / 2.0; + final double halfWidthNeeded = math.max( + 0.0, + inverseTextScale * labelHalfWidth - (_topLobeRadius - _labelPadding), + ); + final double shift = _getIdealOffset(halfWidthNeeded, textScaleFactor * scale, center, sizeWithOverflow.width); + return shift * textScaleFactor; + } + + // Determines the "best" offset to keep the bubble within the slider. The + // calling code will bound that with the available movement in the paddle shape. + double _getIdealOffset( + double halfWidthNeeded, + double scale, + Offset center, + double widthWithOverflow, + ) { + const double edgeMargin = 8.0; + final Rect topLobeRect = Rect.fromLTWH( + -_topLobeRadius - halfWidthNeeded, + -_topLobeRadius - _distanceBetweenTopBottomCenters, + 2.0 * (_topLobeRadius + halfWidthNeeded), + 2.0 * _topLobeRadius, + ); + // We can just multiply by scale instead of a transform, since we're scaling + // around (0, 0). + final Offset topLeft = (topLobeRect.topLeft * scale) + center; + final Offset bottomRight = (topLobeRect.bottomRight * scale) + center; + double shift = 0.0; + + if (topLeft.dx < edgeMargin) { + shift = edgeMargin - topLeft.dx; + } + + final double endGlobal = widthWithOverflow; + if (bottomRight.dx > endGlobal - edgeMargin) { + shift = endGlobal - edgeMargin - bottomRight.dx; + } + + shift = scale == 0.0 ? 0.0 : shift / scale; + if (shift < 0.0) { + // Shifting to the left. + shift = math.max(shift, -halfWidthNeeded); + } else { + // Shifting to the right. + shift = math.min(shift, halfWidthNeeded); + } + return shift; + } + + void paint( + Canvas canvas, + Offset center, + Paint paint, + double scale, + TextPainter labelPainter, + double textScaleFactor, + Size sizeWithOverflow, + Color? strokePaintColor, + ) { + if (scale == 0.0) { + // Zero scale essentially means "do not draw anything", so it's safe to just return. Otherwise, + // our math below will attempt to divide by zero and send needless NaNs to the engine. + return; + } + assert(!sizeWithOverflow.isEmpty); + + // The entire value indicator should scale with the size of the label, + // to keep it large enough to encompass the label text. + final double overallScale = scale * textScaleFactor; + final double inverseTextScale = textScaleFactor != 0 ? 1.0 / textScaleFactor : 0.0; + final double labelHalfWidth = labelPainter.width / 2.0; + + canvas.save(); + canvas.translate(center.dx, center.dy); + canvas.scale(overallScale, overallScale); + + final double bottomNeckTriangleHypotenuse = _bottomNeckRadius + _bottomLobeRadius / overallScale; + final double rightBottomNeckCenterY = -math.sqrt(math.pow(bottomNeckTriangleHypotenuse, 2) - math.pow(_rightBottomNeckCenterX, 2)); + final double rightBottomNeckAngleEnd = math.pi + math.atan(rightBottomNeckCenterY / _rightBottomNeckCenterX); + final Path path = Path()..moveTo(_middleNeckWidth / 2, rightBottomNeckCenterY); + _addArc( + path, + Offset(_rightBottomNeckCenterX, rightBottomNeckCenterY), + _bottomNeckRadius, + _rightBottomNeckAngleStart, + rightBottomNeckAngleEnd, + ); + _addArc( + path, + Offset.zero, + _bottomLobeRadius / overallScale, + rightBottomNeckAngleEnd - math.pi, + 2 * math.pi - rightBottomNeckAngleEnd, + ); + _addArc( + path, + Offset(-_rightBottomNeckCenterX, rightBottomNeckCenterY), + _bottomNeckRadius, + math.pi - rightBottomNeckAngleEnd, + 0, + ); + + // This is the needed extra width for the label. It is only positive when + // the label exceeds the minimum size contained by the round top lobe. + final double halfWidthNeeded = math.max( + 0.0, + inverseTextScale * labelHalfWidth - (_topLobeRadius - _labelPadding), + ); + + final double shift = _getIdealOffset( halfWidthNeeded, overallScale, center, sizeWithOverflow.width); + final double leftWidthNeeded = halfWidthNeeded - shift; + final double rightWidthNeeded = halfWidthNeeded + shift; + + // The parameter that describes how far along the transition from round to + // stretched we are. + final double leftAmount = math.max(0.0, math.min(1.0, leftWidthNeeded / _neckTriangleBase)); + final double rightAmount = math.max(0.0, math.min(1.0, rightWidthNeeded / _neckTriangleBase)); + // The angle between the top neck arc's center and the top lobe's center + // and vertical. The base amount is chosen so that the neck is smooth, + // even when the lobe is shifted due to its size. + final double leftTheta = (1.0 - leftAmount) * _thirtyDegrees; + final double rightTheta = (1.0 - rightAmount) * _thirtyDegrees; + // The center of the top left neck arc. + final Offset leftTopNeckCenter = Offset( + -_neckTriangleBase, + _topLobeCenter.dy + math.cos(leftTheta) * _neckTriangleHypotenuse, + ); + final Offset neckRightCenter = Offset( + _neckTriangleBase, + _topLobeCenter.dy + math.cos(rightTheta) * _neckTriangleHypotenuse, + ); + final double leftNeckArcAngle = _ninetyDegrees - leftTheta; + final double rightNeckArcAngle = math.pi + _ninetyDegrees - rightTheta; + // The distance between the end of the bottom neck arc and the beginning of + // the top neck arc. We use this to shrink/expand it based on the scale + // factor of the value indicator. + final double neckStretchBaseline = math.max(0.0, rightBottomNeckCenterY - math.max(leftTopNeckCenter.dy, neckRightCenter.dy)); + final double t = math.pow(inverseTextScale, 3.0) as double; + final double stretch = clampDouble(neckStretchBaseline * t, 0.0, 10.0 * neckStretchBaseline); + final Offset neckStretch = Offset(0.0, neckStretchBaseline - stretch); + + assert(!_debuggingLabelLocation || () { + final Offset leftCenter = _topLobeCenter - Offset(leftWidthNeeded, 0.0) + neckStretch; + final Offset rightCenter = _topLobeCenter + Offset(rightWidthNeeded, 0.0) + neckStretch; + final Rect valueRect = Rect.fromLTRB( + leftCenter.dx - _topLobeRadius, + leftCenter.dy - _topLobeRadius, + rightCenter.dx + _topLobeRadius, + rightCenter.dy + _topLobeRadius, + ); + final Paint outlinePaint = Paint() + ..color = const Color(0xffff0000) + ..style = PaintingStyle.stroke + ..strokeWidth = 1.0; + canvas.drawRect(valueRect, outlinePaint); + return true; + }()); + + _addArc( + path, + leftTopNeckCenter + neckStretch, + _topNeckRadius, + 0.0, + -leftNeckArcAngle, + ); + _addArc( + path, + _topLobeCenter - Offset(leftWidthNeeded, 0.0) + neckStretch, + _topLobeRadius, + _ninetyDegrees + leftTheta, + _twoSeventyDegrees, + ); + _addArc( + path, + _topLobeCenter + Offset(rightWidthNeeded, 0.0) + neckStretch, + _topLobeRadius, + _twoSeventyDegrees, + _twoSeventyDegrees + math.pi - rightTheta, + ); + _addArc( + path, + neckRightCenter + neckStretch, + _topNeckRadius, + rightNeckArcAngle, + math.pi, + ); + + if (strokePaintColor != null) { + final Paint strokePaint = Paint() + ..color = strokePaintColor + ..strokeWidth = 1.0 + ..style = PaintingStyle.stroke; + canvas.drawPath(path, strokePaint); + } + + canvas.drawPath(path, paint); + + // Draw the label. + canvas.save(); + canvas.translate(shift, -_distanceBetweenTopBottomCenters + neckStretch.dy); + canvas.scale(inverseTextScale, inverseTextScale); + labelPainter.paint(canvas, Offset.zero - Offset(labelHalfWidth, labelPainter.height / 2.0)); + canvas.restore(); + canvas.restore(); + } +} + +/// A callback that formats a numeric value from a [Slider] or [RangeSlider] widget. +/// +/// See also: +/// +/// * [Slider.semanticFormatterCallback], which shows an example use case. +/// * [RangeSlider.semanticFormatterCallback], which shows an example use case. +typedef SemanticFormatterCallback = String Function(double value); + +/// Decides which thumbs (if any) should be selected. +/// +/// The default finds the closest thumb, but if the thumbs are close to each +/// other, it waits for movement defined by [dx] to determine the selected +/// thumb. +/// +/// Override [SliderThemeData.thumbSelector] for custom thumb selection. +typedef RangeThumbSelector = Thumb? Function( + TextDirection textDirection, + RangeValues values, + double tapValue, + Size thumbSize, + Size trackSize, + double dx, +); + +/// Object for representing range slider thumb values. +/// +/// This object is passed into [RangeSlider.values] to set its values, and it +/// is emitted in [RangeSlider.onChanged], [RangeSlider.onChangeStart], and +/// [RangeSlider.onChangeEnd] when the values change. +@immutable +class RangeValues { + /// Creates pair of start and end values. + const RangeValues(this.start, this.end); + + /// The value of the start thumb. + /// + /// For LTR text direction, the start is the left thumb, and for RTL text + /// direction, the start is the right thumb. + final double start; + + /// The value of the end thumb. + /// + /// For LTR text direction, the end is the right thumb, and for RTL text + /// direction, the end is the left thumb. + final double end; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is RangeValues + && other.start == start + && other.end == end; + } + + @override + int get hashCode => Object.hash(start, end); + + @override + String toString() { + return '${objectRuntimeType(this, 'RangeValues')}($start, $end)'; + } +} + +/// Object for setting range slider label values that appear in the value +/// indicator for each thumb. +/// +/// Used in combination with [SliderThemeData.showValueIndicator] to display +/// labels above the thumbs. +@immutable +class RangeLabels { + /// Creates pair of start and end labels. + const RangeLabels(this.start, this.end); + + /// The label of the start thumb. + /// + /// For LTR text direction, the start is the left thumb, and for RTL text + /// direction, the start is the right thumb. + final String start; + + /// The label of the end thumb. + /// + /// For LTR text direction, the end is the right thumb, and for RTL text + /// direction, the end is the left thumb. + final String end; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is RangeLabels + && other.start == start + && other.end == end; + } + + @override + int get hashCode => Object.hash(start, end); + + @override + String toString() { + return '${objectRuntimeType(this, 'RangeLabels')}($start, $end)'; + } +} + +void _debugDrawShadow(Canvas canvas, Path path, double elevation) { + if (elevation > 0.0) { + canvas.drawPath( + path, + Paint() + ..color = Colors.black + ..style = PaintingStyle.stroke + ..strokeWidth = elevation * 2.0, + ); + } +} + +/// The default shape of a Material 3 [Slider]'s value indicator. +/// +/// See also: +/// +/// * [Slider], which includes a value indicator defined by this shape. +/// * [SliderTheme], which can be used to configure the slider value indicator +/// of all sliders in a widget subtree. +class DropSliderValueIndicatorShape extends SliderComponentShape { + /// Create a slider value indicator that resembles a drop shape. + const DropSliderValueIndicatorShape(); + + static const _DropSliderValueIndicatorPathPainter _pathPainter = _DropSliderValueIndicatorPathPainter(); + + @override + Size getPreferredSize( + bool isEnabled, + bool isDiscrete, { + TextPainter? labelPainter, + double? textScaleFactor, + }) { + assert(labelPainter != null); + assert(textScaleFactor != null && textScaleFactor >= 0); + return _pathPainter.getPreferredSize(labelPainter!, textScaleFactor!); + } + + @override + void paint( + PaintingContext context, + Offset center, { + required Animation<double> activationAnimation, + required Animation<double> enableAnimation, + required bool isDiscrete, + required TextPainter labelPainter, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required TextDirection textDirection, + required double value, + required double textScaleFactor, + required Size sizeWithOverflow, + }) { + final Canvas canvas = context.canvas; + final double scale = activationAnimation.value; + _pathPainter.paint( + parentBox: parentBox, + canvas: canvas, + center: center, + scale: scale, + labelPainter: labelPainter, + textScaleFactor: textScaleFactor, + sizeWithOverflow: sizeWithOverflow, + backgroundPaintColor: sliderTheme.valueIndicatorColor!, + strokePaintColor: sliderTheme.valueIndicatorStrokeColor, + ); + } +} + +class _DropSliderValueIndicatorPathPainter { + const _DropSliderValueIndicatorPathPainter(); + + static const double _triangleHeight = 10.0; + static const double _labelPadding = 8.0; + static const double _preferredHeight = 32.0; + static const double _minLabelWidth = 20.0; + static const double _minRectHeight = 28.0; + static const double _rectYOffset = 6.0; + static const double _bottomTipYOffset = 16.0; + static const double _preferredHalfHeight = _preferredHeight / 2; + static const double _upperRectRadius = 4; + + Size getPreferredSize( + TextPainter labelPainter, + double textScaleFactor, + ) { + final double width = math.max(_minLabelWidth, labelPainter.width) + _labelPadding * 2 * textScaleFactor; + return Size(width, _preferredHeight * textScaleFactor); + } + + double getHorizontalShift({ + required RenderBox parentBox, + required Offset center, + required TextPainter labelPainter, + required double textScaleFactor, + required Size sizeWithOverflow, + required double scale, + }) { + assert(!sizeWithOverflow.isEmpty); + + const double edgePadding = 8.0; + final double rectangleWidth = _upperRectangleWidth(labelPainter, scale); + /// Value indicator draws on the Overlay and by using the global Offset + /// we are making sure we use the bounds of the Overlay instead of the Slider. + final Offset globalCenter = parentBox.localToGlobal(center); + + // The rectangle must be shifted towards the center so that it minimizes the + // chance of it rendering outside the bounds of the render box. If the shift + // is negative, then the lobe is shifted from right to left, and if it is + // positive, then the lobe is shifted from left to right. + final double overflowLeft = math.max(0, rectangleWidth / 2 - globalCenter.dx + edgePadding); + final double overflowRight = math.max(0, rectangleWidth / 2 - (sizeWithOverflow.width - globalCenter.dx - edgePadding)); + + if (rectangleWidth < sizeWithOverflow.width) { + return overflowLeft - overflowRight; + } else if (overflowLeft - overflowRight > 0) { + return overflowLeft - (edgePadding * textScaleFactor); + } else { + return -overflowRight + (edgePadding * textScaleFactor); + } + } + + double _upperRectangleWidth(TextPainter labelPainter, double scale) { + final double unscaledWidth = math.max(_minLabelWidth, labelPainter.width) + _labelPadding; + return unscaledWidth * scale; + } + + BorderRadius _adjustBorderRadius(Rect rect) { + const double rectness = 0.0; + return BorderRadius.lerp( + BorderRadius.circular(_upperRectRadius), + BorderRadius.all(Radius.circular(rect.shortestSide / 2.0)), + 1.0 - rectness, + )!; + } + + void paint({ + required RenderBox parentBox, + required Canvas canvas, + required Offset center, + required double scale, + required TextPainter labelPainter, + required double textScaleFactor, + required Size sizeWithOverflow, + required Color backgroundPaintColor, + Color? strokePaintColor, + }) { + if (scale == 0.0) { + // Zero scale essentially means "do not draw anything", so it's safe to just return. + return; + } + assert(!sizeWithOverflow.isEmpty); + + final double rectangleWidth = _upperRectangleWidth(labelPainter, scale); + final double horizontalShift = getHorizontalShift( + parentBox: parentBox, + center: center, + labelPainter: labelPainter, + textScaleFactor: textScaleFactor, + sizeWithOverflow: sizeWithOverflow, + scale: scale, + ); + final Rect upperRect = Rect.fromLTWH( + -rectangleWidth / 2 + horizontalShift, + -_rectYOffset - _minRectHeight, + rectangleWidth, + _minRectHeight, + ); + + final Paint fillPaint = Paint()..color = backgroundPaintColor; + + canvas.save(); + canvas.translate(center.dx, center.dy - _bottomTipYOffset); + canvas.scale(scale, scale); + + final BorderRadius adjustedBorderRadius = _adjustBorderRadius(upperRect); + final RRect borderRect = adjustedBorderRadius.resolve(labelPainter.textDirection).toRRect(upperRect); + final Path trianglePath = Path() + ..lineTo(-_triangleHeight, -_triangleHeight) + ..lineTo(_triangleHeight, -_triangleHeight) + ..close(); + trianglePath.addRRect(borderRect); + + if (strokePaintColor != null) { + final Paint strokePaint = Paint() + ..color = strokePaintColor + ..strokeWidth = 1.0 + ..style = PaintingStyle.stroke; + canvas.drawPath(trianglePath, strokePaint); + } + + canvas.drawPath(trianglePath, fillPaint); + + // The label text is centered within the value indicator. + final double bottomTipToUpperRectTranslateY = -_preferredHalfHeight / 2 - upperRect.height; + canvas.translate(0, bottomTipToUpperRectTranslateY); + final Offset boxCenter = Offset(horizontalShift, upperRect.height / 1.75); + final Offset halfLabelPainterOffset = Offset(labelPainter.width / 2, labelPainter.height / 2); + final Offset labelOffset = boxCenter - halfLabelPainterOffset; + labelPainter.paint(canvas, labelOffset); + canvas.restore(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/snack_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/snack_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..51f8ce1cf9ccda4a0719c73c4b1f701842ead58b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/snack_bar.dart @@ -0,0 +1,969 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'material.dart'; +import 'material_state.dart'; +import 'scaffold.dart'; +import 'snack_bar_theme.dart'; +import 'text_button.dart'; +import 'text_button_theme.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +const double _singleLineVerticalPadding = 14.0; +const Duration _snackBarTransitionDuration = Duration(milliseconds: 250); +const Duration _snackBarDisplayDuration = Duration(milliseconds: 4000); +const Curve _snackBarHeightCurve = Curves.fastOutSlowIn; +const Curve _snackBarM3HeightCurve = Curves.easeInOutQuart; + +const Curve _snackBarFadeInCurve = Interval(0.4, 1.0); +const Curve _snackBarM3FadeInCurve = Interval(0.4, 0.6, curve: Curves.easeInCirc); +const Curve _snackBarFadeOutCurve = Interval(0.72, 1.0, curve: Curves.fastOutSlowIn); + +/// Specify how a [SnackBar] was closed. +/// +/// The [ScaffoldMessengerState.showSnackBar] function returns a +/// [ScaffoldFeatureController]. The value of the controller's closed property +/// is a Future that resolves to a SnackBarClosedReason. Applications that need +/// to know how a snackbar was closed can use this value. +/// +/// Example: +/// +/// ```dart +/// ScaffoldMessenger.of(context).showSnackBar( +/// const SnackBar( +/// content: Text('He likes me. I think he likes me.'), +/// ) +/// ).closed.then((SnackBarClosedReason reason) { +/// // ... +/// }); +/// ``` +enum SnackBarClosedReason { + /// The snack bar was closed after the user tapped a [SnackBarAction]. + action, + + /// The snack bar was closed through a [SemanticsAction.dismiss]. + dismiss, + + /// The snack bar was closed by a user's swipe. + swipe, + + /// The snack bar was closed by the [ScaffoldFeatureController] close callback + /// or by calling [ScaffoldMessengerState.hideCurrentSnackBar] directly. + hide, + + /// The snack bar was closed by an call to [ScaffoldMessengerState.removeCurrentSnackBar]. + remove, + + /// The snack bar was closed because its timer expired. + timeout, +} + +/// A button for a [SnackBar], known as an "action". +/// +/// Snack bar actions are always enabled. Instead of disabling a snack bar +/// action, avoid including it in the snack bar in the first place. +/// +/// Snack bar actions can only be pressed once. Subsequent presses are ignored. +/// +/// See also: +/// +/// * [SnackBar] +/// * <https://material.io/design/components/snackbars.html> +class SnackBarAction extends StatefulWidget { + /// Creates an action for a [SnackBar]. + const SnackBarAction({ + super.key, + this.textColor, + this.disabledTextColor, + this.backgroundColor, + this.disabledBackgroundColor, + required this.label, + required this.onPressed, + }) : assert(backgroundColor is! MaterialStateColor || disabledBackgroundColor == null, + 'disabledBackgroundColor must not be provided when background color is ' + 'a MaterialStateColor'); + + /// The button label color. If not provided, defaults to + /// [SnackBarThemeData.actionTextColor]. + /// + /// If [textColor] is a [MaterialStateColor], then the text color will be + /// resolved against the set of [MaterialState]s that the action text + /// is in, thus allowing for different colors for states such as pressed, + /// hovered and others. + final Color? textColor; + + /// The button background fill color. If not provided, defaults to + /// [SnackBarThemeData.actionBackgroundColor]. + /// + /// If [backgroundColor] is a [MaterialStateColor], then the text color will + /// be resolved against the set of [MaterialState]s that the action text is + /// in, thus allowing for different colors for the states. + final Color? backgroundColor; + + /// The button disabled label color. This color is shown after the + /// [SnackBarAction] is dismissed. + final Color? disabledTextColor; + + /// The button diabled background color. This color is shown after the + /// [SnackBarAction] is dismissed. + /// + /// If not provided, defaults to [SnackBarThemeData.disabledActionBackgroundColor]. + final Color? disabledBackgroundColor; + + /// The button label. + final String label; + + /// The callback to be called when the button is pressed. + /// + /// This callback will be called at most once each time this action is + /// displayed in a [SnackBar]. + final VoidCallback onPressed; + + @override + State<SnackBarAction> createState() => _SnackBarActionState(); +} + +class _SnackBarActionState extends State<SnackBarAction> { + bool _haveTriggeredAction = false; + + void _handlePressed() { + if (_haveTriggeredAction) { + return; + } + setState(() { + _haveTriggeredAction = true; + }); + widget.onPressed(); + ScaffoldMessenger.of(context).hideCurrentSnackBar(reason: SnackBarClosedReason.action); + } + + @override + Widget build(BuildContext context) { + final SnackBarThemeData defaults = Theme.of(context).useMaterial3 + ? _SnackbarDefaultsM3(context) + : _SnackbarDefaultsM2(context); + final SnackBarThemeData snackBarTheme = Theme.of(context).snackBarTheme; + + MaterialStateColor resolveForegroundColor() { + if (widget.textColor != null) { + if (widget.textColor is MaterialStateColor) { + return widget.textColor! as MaterialStateColor; + } + } else if (snackBarTheme.actionTextColor != null) { + if (snackBarTheme.actionTextColor is MaterialStateColor) { + return snackBarTheme.actionTextColor! as MaterialStateColor; + } + } else if (defaults.actionTextColor != null) { + if (defaults.actionTextColor is MaterialStateColor) { + return defaults.actionTextColor! as MaterialStateColor; + } + } + + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return widget.disabledTextColor ?? + snackBarTheme.disabledActionTextColor ?? + defaults.disabledActionTextColor!; + } + return widget.textColor ?? + snackBarTheme.actionTextColor ?? + defaults.actionTextColor!; + }); + } + + MaterialStateColor? resolveBackgroundColor() { + if (widget.backgroundColor is MaterialStateColor) { + return widget.backgroundColor! as MaterialStateColor; + } + if (snackBarTheme.actionBackgroundColor is MaterialStateColor) { + return snackBarTheme.actionBackgroundColor! as MaterialStateColor; + } + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return widget.disabledBackgroundColor ?? + snackBarTheme.disabledActionBackgroundColor ?? + Colors.transparent; + } + return widget.backgroundColor ?? + snackBarTheme.actionBackgroundColor ?? + Colors.transparent; + }); + } + + return TextButton( + style: ButtonStyle( + foregroundColor: resolveForegroundColor(), + backgroundColor: resolveBackgroundColor(), + ), + onPressed: _haveTriggeredAction ? null : _handlePressed, + child: Text(widget.label), + ); + } +} + +/// A lightweight message with an optional action which briefly displays at the +/// bottom of the screen. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=zpO6n_oZWw0} +/// +/// To display a snack bar, call `ScaffoldMessenger.of(context).showSnackBar()`, +/// passing an instance of [SnackBar] that describes the message. +/// +/// To control how long the [SnackBar] remains visible, specify a [duration]. +/// +/// A SnackBar with an action will not time out when TalkBack or VoiceOver are +/// enabled. This is controlled by [AccessibilityFeatures.accessibleNavigation]. +/// +/// During page transitions, the [SnackBar] will smoothly animate to its +/// location on the other page. For example if the [SnackBar.behavior] is set to +/// [SnackBarBehavior.floating] and the next page has a floating action button, +/// while the current one does not, the [SnackBar] will smoothly animate above +/// the floating action button. It also works in the case of a back gesture +/// transition. +/// +/// {@tool dartpad} +/// Here is an example of a [SnackBar] with an [action] button implemented using +/// [SnackBarAction]. +/// +/// ** See code in examples/api/lib/material/snack_bar/snack_bar.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// Here is an example of a customized [SnackBar]. It utilizes +/// [behavior], [shape], [padding], [width], and [duration] to customize the +/// location, appearance, and the duration for which the [SnackBar] is visible. +/// +/// ** See code in examples/api/lib/material/snack_bar/snack_bar.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example demonstrates the various [SnackBar] widget components, +/// including an optional icon, in either floating or fixed format. +/// +/// ** See code in examples/api/lib/material/snack_bar/snack_bar.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ScaffoldMessenger.of], to obtain the current [ScaffoldMessengerState], +/// which manages the display and animation of snack bars. +/// * [ScaffoldMessengerState.showSnackBar], which displays a [SnackBar]. +/// * [ScaffoldMessengerState.removeCurrentSnackBar], which abruptly hides the +/// currently displayed snack bar, if any, and allows the next to be displayed. +/// * [SnackBarAction], which is used to specify an [action] button to show +/// on the snack bar. +/// * [SnackBarThemeData], to configure the default property values for +/// [SnackBar] widgets. +/// * <https://material.io/design/components/snackbars.html> +class SnackBar extends StatefulWidget { + /// Creates a snack bar. + /// + /// The [elevation] must be null or non-negative. + const SnackBar({ + super.key, + required this.content, + this.backgroundColor, + this.elevation, + this.margin, + this.padding, + this.width, + this.shape, + this.hitTestBehavior, + this.behavior, + this.action, + this.actionOverflowThreshold, + this.showCloseIcon, + this.closeIconColor, + this.duration = _snackBarDisplayDuration, + this.animation, + this.onVisible, + this.dismissDirection, + this.clipBehavior = Clip.hardEdge, + }) : assert(elevation == null || elevation >= 0.0), + assert(width == null || margin == null, + 'Width and margin can not be used together', + ), + assert(actionOverflowThreshold == null || (actionOverflowThreshold >= 0 && actionOverflowThreshold <= 1), + 'Action overflow threshold must be between 0 and 1 inclusive'); + + /// The primary content of the snack bar. + /// + /// Typically a [Text] widget. + final Widget content; + + /// The snack bar's background color. + /// + /// If not specified, it will use [SnackBarThemeData.backgroundColor] of + /// [ThemeData.snackBarTheme]. If that is not specified it will default to a + /// dark variation of [ColorScheme.surface] for light themes, or + /// [ColorScheme.onSurface] for dark themes. + final Color? backgroundColor; + + /// The z-coordinate at which to place the snack bar. This controls the size + /// of the shadow below the snack bar. + /// + /// Defines the card's [Material.elevation]. + /// + /// If this property is null, then [SnackBarThemeData.elevation] of + /// [ThemeData.snackBarTheme] is used, if that is also null, the default value + /// is 6.0. + final double? elevation; + + /// Empty space to surround the snack bar. + /// + /// This property is only used when [behavior] is [SnackBarBehavior.floating]. + /// It can not be used if [width] is specified. + /// + /// If this property is null, then [SnackBarThemeData.insetPadding] of + /// [ThemeData.snackBarTheme] is used. If that is also null, then the default is + /// `EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 10.0)`. + /// + /// If this property is not null and [hitTestBehavior] is null, then [hitTestBehavior] default is [HitTestBehavior.deferToChild]. + final EdgeInsetsGeometry? margin; + + /// The amount of padding to apply to the snack bar's content and optional + /// action. + /// + /// If this property is null, the default padding values are as follows: + /// + /// * [content] + /// * Top and bottom paddings are 14. + /// * Left padding is 24 if [behavior] is [SnackBarBehavior.fixed], + /// 16 if [behavior] is [SnackBarBehavior.floating]. + /// * Right padding is same as start padding if there is no [action], + /// otherwise 0. + /// * [action] + /// * Top and bottom paddings are 14. + /// * Left and right paddings are half of [content]'s left padding. + /// + /// If this property is not null, the padding is as follows: + /// + /// * [content] + /// * Left, top and bottom paddings are assigned normally. + /// * Right padding is assigned normally if there is no [action], + /// otherwise 0. + /// * [action] + /// * Left padding is replaced with half the right padding. + /// * Top and bottom paddings are assigned normally. + /// * Right padding is replaced with one and a half times the + /// right padding. + final EdgeInsetsGeometry? padding; + + /// The width of the snack bar. + /// + /// If width is specified, the snack bar will be centered horizontally in the + /// available space. This property is only used when [behavior] is + /// [SnackBarBehavior.floating]. It can not be used if [margin] is specified. + /// + /// If this property is null, then [SnackBarThemeData.width] of + /// [ThemeData.snackBarTheme] is used. If that is null, the snack bar will + /// take up the full device width less the margin. + final double? width; + + /// The shape of the snack bar's [Material]. + /// + /// Defines the snack bar's [Material.shape]. + /// + /// If this property is null then [SnackBarThemeData.shape] of + /// [ThemeData.snackBarTheme] is used. If that's null then the shape will + /// depend on the [SnackBarBehavior]. For [SnackBarBehavior.fixed], no + /// overriding shape is specified, so the [SnackBar] is rectangular. For + /// [SnackBarBehavior.floating], it uses a [RoundedRectangleBorder] with a + /// circular corner radius of 4.0. + final ShapeBorder? shape; + + /// Defines how the snack bar area, including margin, will behave during hit testing. + /// + /// If this property is null and [margin] is not null, then [HitTestBehavior.deferToChild] is used by default. + /// + /// Please refer to [HitTestBehavior] for a detailed explanation of every behavior. + final HitTestBehavior? hitTestBehavior; + + /// This defines the behavior and location of the snack bar. + /// + /// Defines where a [SnackBar] should appear within a [Scaffold] and how its + /// location should be adjusted when the scaffold also includes a + /// [FloatingActionButton] or a [BottomNavigationBar] + /// + /// If this property is null, then [SnackBarThemeData.behavior] of + /// [ThemeData.snackBarTheme] is used. If that is null, then the default is + /// [SnackBarBehavior.fixed]. + /// + /// If this value is [SnackBarBehavior.floating], the length of the bar + /// is defined by either [width] or [margin]. + final SnackBarBehavior? behavior; + + /// (optional) An action that the user can take based on the snack bar. + /// + /// For example, the snack bar might let the user undo the operation that + /// prompted the snackbar. Snack bars can have at most one action. + /// + /// The action should not be "dismiss" or "cancel". + final SnackBarAction? action; + + /// (optional) The percentage threshold for action widget's width before it overflows + /// to a new line. + /// + /// Must be between 0 and 1. If the width of the snackbar's [content] is greater + /// than this percentage of the width of the snackbar less the width of its [action], + /// then the [action] will appear below the [content]. + /// + /// At a value of 0, the action will not overflow to a new line. + /// + /// Defaults to 0.25. + final double? actionOverflowThreshold; + + /// (optional) Whether to include a "close" icon widget. + /// + /// Tapping the icon will close the snack bar. + final bool? showCloseIcon; + + /// (optional) An optional color for the close icon, if [showCloseIcon] is + /// true. + /// + /// If this property is null, then [SnackBarThemeData.closeIconColor] of + /// [ThemeData.snackBarTheme] is used. If that is null, then the default is + /// inverse surface. + /// + /// If [closeIconColor] is a [MaterialStateColor], then the icon color will be + /// resolved against the set of [MaterialState]s that the action text + /// is in, thus allowing for different colors for states such as pressed, + /// hovered and others. + final Color? closeIconColor; + + /// The amount of time the snack bar should be displayed. + /// + /// Defaults to 4.0s. + /// + /// See also: + /// + /// * [ScaffoldMessengerState.removeCurrentSnackBar], which abruptly hides the + /// currently displayed snack bar, if any, and allows the next to be + /// displayed. + /// * <https://material.io/design/components/snackbars.html> + final Duration duration; + + /// The animation driving the entrance and exit of the snack bar. + final Animation<double>? animation; + + /// Called the first time that the snackbar is visible within a [Scaffold]. + final VoidCallback? onVisible; + + /// The direction in which the SnackBar can be dismissed. + /// + /// If this property is null, then [SnackBarThemeData.dismissDirection] of + /// [ThemeData.snackBarTheme] is used. If that is null, then the default is + /// [DismissDirection.down]. + final DismissDirection? dismissDirection; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + // API for ScaffoldMessengerState.showSnackBar(): + + /// Creates an animation controller useful for driving a snack bar's entrance and exit animation. + static AnimationController createAnimationController({ required TickerProvider vsync }) { + return AnimationController( + duration: _snackBarTransitionDuration, + debugLabel: 'SnackBar', + vsync: vsync, + ); + } + + /// Creates a copy of this snack bar but with the animation replaced with the given animation. + /// + /// If the original snack bar lacks a key, the newly created snack bar will + /// use the given fallback key. + SnackBar withAnimation(Animation<double> newAnimation, { Key? fallbackKey }) { + return SnackBar( + key: key ?? fallbackKey, + content: content, + backgroundColor: backgroundColor, + elevation: elevation, + margin: margin, + padding: padding, + width: width, + shape: shape, + hitTestBehavior: hitTestBehavior, + behavior: behavior, + action: action, + actionOverflowThreshold: actionOverflowThreshold, + showCloseIcon: showCloseIcon, + closeIconColor: closeIconColor, + duration: duration, + animation: newAnimation, + onVisible: onVisible, + dismissDirection: dismissDirection, + clipBehavior: clipBehavior, + ); + } + + @override + State<SnackBar> createState() => _SnackBarState(); +} + +class _SnackBarState extends State<SnackBar> { + bool _wasVisible = false; + + @override + void initState() { + super.initState(); + widget.animation!.addStatusListener(_onAnimationStatusChanged); + } + + @override + void didUpdateWidget(SnackBar oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.animation != oldWidget.animation) { + oldWidget.animation!.removeStatusListener(_onAnimationStatusChanged); + widget.animation!.addStatusListener(_onAnimationStatusChanged); + } + } + + @override + void dispose() { + widget.animation!.removeStatusListener(_onAnimationStatusChanged); + super.dispose(); + } + + void _onAnimationStatusChanged(AnimationStatus animationStatus) { + switch (animationStatus) { + case AnimationStatus.dismissed: + case AnimationStatus.forward: + case AnimationStatus.reverse: + break; + case AnimationStatus.completed: + if (widget.onVisible != null && !_wasVisible) { + widget.onVisible!(); + } + _wasVisible = true; + } + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final bool accessibleNavigation = MediaQuery.accessibleNavigationOf(context); + assert(widget.animation != null); + final ThemeData theme = Theme.of(context); + final ColorScheme colorScheme = theme.colorScheme; + final SnackBarThemeData snackBarTheme = theme.snackBarTheme; + final bool isThemeDark = theme.brightness == Brightness.dark; + final Color buttonColor = isThemeDark ? colorScheme.primary : colorScheme.secondary; + final SnackBarThemeData defaults = theme.useMaterial3 + ? _SnackbarDefaultsM3(context) + : _SnackbarDefaultsM2(context); + + // SnackBar uses a theme that is the opposite brightness from + // the surrounding theme. + final Brightness brightness = isThemeDark ? Brightness.light : Brightness.dark; + + // Invert the theme values for Material 2. Material 3 values are tokenized to pre-inverted values. + final ThemeData effectiveTheme = theme.useMaterial3 + ? theme + : theme.copyWith( + colorScheme: ColorScheme( + primary: colorScheme.onPrimary, + secondary: buttonColor, + surface: colorScheme.onSurface, + background: defaults.backgroundColor!, + error: colorScheme.onError, + onPrimary: colorScheme.primary, + onSecondary: colorScheme.secondary, + onSurface: colorScheme.surface, + onBackground: colorScheme.background, + onError: colorScheme.error, + brightness: brightness, + ), + ); + + final TextStyle? contentTextStyle = snackBarTheme.contentTextStyle ?? defaults.contentTextStyle; + final SnackBarBehavior snackBarBehavior = widget.behavior ?? snackBarTheme.behavior ?? defaults.behavior!; + final double? width = widget.width ?? snackBarTheme.width; + assert((){ + // Whether the behavior is set through the constructor or the theme, + // assert that our other properties are configured properly. + if (snackBarBehavior != SnackBarBehavior.floating) { + String message(String parameter) { + final String prefix = '$parameter can only be used with floating behavior.'; + if (widget.behavior != null) { + return '$prefix SnackBarBehavior.fixed was set in the SnackBar constructor.'; + } else if (snackBarTheme.behavior != null) { + return '$prefix SnackBarBehavior.fixed was set by the inherited SnackBarThemeData.'; + } else { + return '$prefix SnackBarBehavior.fixed was set by default.'; + } + } + assert(widget.margin == null, message('Margin')); + assert(width == null, message('Width')); + } + return true; + }()); + + final bool showCloseIcon = widget.showCloseIcon ?? snackBarTheme.showCloseIcon ?? defaults.showCloseIcon!; + + final bool isFloatingSnackBar = snackBarBehavior == SnackBarBehavior.floating; + final double horizontalPadding = isFloatingSnackBar ? 16.0 : 24.0; + final EdgeInsetsGeometry padding = widget.padding ?? + EdgeInsetsDirectional.only( + start: horizontalPadding, + end: widget.action != null || showCloseIcon + ? 0 + : horizontalPadding); + + final double actionHorizontalMargin = (widget.padding?.resolve(TextDirection.ltr).right ?? horizontalPadding) / 2; + final double iconHorizontalMargin = (widget.padding?.resolve(TextDirection.ltr).right ?? horizontalPadding) / 12.0; + + final CurvedAnimation heightAnimation = CurvedAnimation(parent: widget.animation!, curve: _snackBarHeightCurve); + final CurvedAnimation fadeInAnimation = CurvedAnimation(parent: widget.animation!, curve: _snackBarFadeInCurve); + final CurvedAnimation fadeInM3Animation = CurvedAnimation(parent: widget.animation!, curve: _snackBarM3FadeInCurve); + + final CurvedAnimation fadeOutAnimation = CurvedAnimation( + parent: widget.animation!, + curve: _snackBarFadeOutCurve, + reverseCurve: const Threshold(0.0), + ); + // Material 3 Animation has a height animation on entry, but a direct fade out on exit. + final CurvedAnimation heightM3Animation = CurvedAnimation( + parent: widget.animation!, + curve: _snackBarM3HeightCurve, + reverseCurve: const Threshold(0.0), + ); + + + final IconButton? iconButton = showCloseIcon + ? IconButton( + icon: const Icon(Icons.close), + iconSize: 24.0, + color: widget.closeIconColor ?? snackBarTheme.closeIconColor ?? defaults.closeIconColor, + onPressed: () => ScaffoldMessenger.of(context).hideCurrentSnackBar(reason: SnackBarClosedReason.dismiss), + ) + : null; + + // Calculate combined width of Action, Icon, and their padding, if they are present. + final TextPainter actionTextPainter = TextPainter( + text: TextSpan( + text: widget.action?.label ?? '', + style: Theme.of(context).textTheme.labelLarge, + ), + maxLines: 1, + textDirection: TextDirection.ltr) + ..layout(); + final double actionAndIconWidth = actionTextPainter.size.width + + (widget.action != null ? actionHorizontalMargin : 0) + + (showCloseIcon ? (iconButton?.iconSize ?? 0 + iconHorizontalMargin) : 0); + actionTextPainter.dispose(); + + final EdgeInsets margin = widget.margin?.resolve(TextDirection.ltr) ?? snackBarTheme.insetPadding ?? defaults.insetPadding!; + + final double snackBarWidth = widget.width ?? MediaQuery.sizeOf(context).width - (margin.left + margin.right); + final double actionOverflowThreshold = widget.actionOverflowThreshold + ?? snackBarTheme.actionOverflowThreshold + ?? defaults.actionOverflowThreshold!; + + final bool willOverflowAction = actionAndIconWidth / snackBarWidth > actionOverflowThreshold; + + final List<Widget> maybeActionAndIcon = <Widget>[ + if (widget.action != null) + Padding( + padding: EdgeInsets.symmetric(horizontal: actionHorizontalMargin), + child: TextButtonTheme( + data: TextButtonThemeData( + style: TextButton.styleFrom( + foregroundColor: buttonColor, + padding: EdgeInsets.symmetric(horizontal: horizontalPadding), + ), + ), + child: widget.action!, + ), + ), + if (showCloseIcon) + Padding( + padding: EdgeInsets.symmetric(horizontal: iconHorizontalMargin), + child: iconButton, + ), + ]; + + Widget snackBar = Padding( + padding: padding, + child: Wrap( + children: <Widget>[ + Row( + children: <Widget>[ + Expanded( + child: Container( + padding: widget.padding == null + ? const EdgeInsets.symmetric( + vertical: _singleLineVerticalPadding) + : null, + child: DefaultTextStyle( + style: contentTextStyle!, + child: widget.content, + ), + ), + ), + if (!willOverflowAction) ...maybeActionAndIcon, + if (willOverflowAction) SizedBox(width: snackBarWidth * 0.4), + ], + ), + if (willOverflowAction) + Padding( + padding: const EdgeInsets.only(bottom: _singleLineVerticalPadding), + child: Row(mainAxisAlignment: MainAxisAlignment.end, children: maybeActionAndIcon), + ), + ], + ), + ); + + if (!isFloatingSnackBar) { + snackBar = SafeArea( + top: false, + child: snackBar, + ); + } + + final double elevation = widget.elevation ?? snackBarTheme.elevation ?? defaults.elevation!; + final Color backgroundColor = widget.backgroundColor ?? snackBarTheme.backgroundColor ?? defaults.backgroundColor!; + final ShapeBorder? shape = widget.shape ?? snackBarTheme.shape ?? (isFloatingSnackBar ? defaults.shape : null); + final DismissDirection dismissDirection = widget.dismissDirection ?? snackBarTheme.dismissDirection ?? DismissDirection.down; + + snackBar = Material( + shape: shape, + elevation: elevation, + color: backgroundColor, + clipBehavior: widget.clipBehavior, + child: Theme( + data: effectiveTheme, + child: accessibleNavigation || theme.useMaterial3 + ? snackBar + : FadeTransition( + opacity: fadeOutAnimation, + child: snackBar, + ), + ), + ); + + if (isFloatingSnackBar) { + // If width is provided, do not include horizontal margins. + if (width != null) { + snackBar = Container( + margin: EdgeInsets.only(top: margin.top, bottom: margin.bottom), + width: width, + child: snackBar, + ); + } else { + snackBar = Padding( + padding: margin, + child: snackBar, + ); + } + snackBar = SafeArea( + top: false, + bottom: false, + child: snackBar, + ); + } + + snackBar = Semantics( + container: true, + liveRegion: true, + onDismiss: () { + ScaffoldMessenger.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.dismiss); + }, + child: Dismissible( + key: const Key('dismissible'), + direction: dismissDirection, + resizeDuration: null, + behavior: widget.hitTestBehavior ?? (widget.margin != null ? HitTestBehavior.deferToChild : HitTestBehavior.opaque), + onDismissed: (DismissDirection direction) { + ScaffoldMessenger.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe); + }, + child: snackBar, + ), + ); + + final Widget snackBarTransition; + if (accessibleNavigation) { + snackBarTransition = snackBar; + } else if (isFloatingSnackBar && !theme.useMaterial3) { + snackBarTransition = FadeTransition( + opacity: fadeInAnimation, + child: snackBar, + ); + // Is Material 3 Floating Snack Bar. + } else if (isFloatingSnackBar && theme.useMaterial3) { + snackBarTransition = FadeTransition( + opacity: fadeInM3Animation, + child: AnimatedBuilder( + animation: heightM3Animation, + builder: (BuildContext context, Widget? child) { + return Align( + alignment: AlignmentDirectional.bottomStart, + heightFactor: heightM3Animation.value, + child: child, + ); + }, + child: snackBar, + ), + ); + } else { + snackBarTransition = AnimatedBuilder( + animation: heightAnimation, + builder: (BuildContext context, Widget? child) { + return Align( + alignment: AlignmentDirectional.topStart, + heightFactor: heightAnimation.value, + child: child, + ); + }, + child: snackBar, + ); + } + + return Hero( + tag: '<SnackBar Hero tag - ${widget.content}>', + transitionOnUserGestures: true, + child: ClipRect( + clipBehavior: widget.clipBehavior, + child: snackBarTransition, + ), + ); + } +} + +// Hand coded defaults based on Material Design 2. +class _SnackbarDefaultsM2 extends SnackBarThemeData { + _SnackbarDefaultsM2(BuildContext context) + : _theme = Theme.of(context), + _colors = Theme.of(context).colorScheme, + super(elevation: 6.0); + + late final ThemeData _theme; + late final ColorScheme _colors; + + @override + Color get backgroundColor => _theme.brightness == Brightness.light + ? Color.alphaBlend(_colors.onSurface.withOpacity(0.80), _colors.surface) + : _colors.onSurface; + + @override + TextStyle? get contentTextStyle => ThemeData( + useMaterial3: _theme.useMaterial3, + brightness: _theme.brightness == Brightness.light + ? Brightness.dark + : Brightness.light) + .textTheme + .titleMedium; + + @override + SnackBarBehavior get behavior => SnackBarBehavior.fixed; + + @override + Color get actionTextColor => _colors.secondary; + + @override + Color get disabledActionTextColor => _colors.onSurface + .withOpacity(_theme.brightness == Brightness.light ? 0.38 : 0.3); + + @override + ShapeBorder get shape => const RoundedRectangleBorder( + borderRadius: BorderRadius.all( + Radius.circular(4.0), + ), + ); + + @override + EdgeInsets get insetPadding => const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 10.0); + + @override + bool get showCloseIcon => false; + + @override + Color get closeIconColor => _colors.onSurface; + + @override + double get actionOverflowThreshold => 0.25; +} + +// BEGIN GENERATED TOKEN PROPERTIES - Snackbar + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _SnackbarDefaultsM3 extends SnackBarThemeData { + _SnackbarDefaultsM3(this.context); + + final BuildContext context; + late final ThemeData _theme = Theme.of(context); + late final ColorScheme _colors = _theme.colorScheme; + + @override + Color get backgroundColor => _colors.inverseSurface; + + @override + Color get actionTextColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.inversePrimary; + } + if (states.contains(MaterialState.pressed)) { + return _colors.inversePrimary; + } + if (states.contains(MaterialState.hovered)) { + return _colors.inversePrimary; + } + if (states.contains(MaterialState.focused)) { + return _colors.inversePrimary; + } + return _colors.inversePrimary; + }); + + @override + Color get disabledActionTextColor => + _colors.inversePrimary; + + + @override + TextStyle get contentTextStyle => + Theme.of(context).textTheme.bodyMedium!.copyWith + (color: _colors.onInverseSurface, + ); + + @override + double get elevation => 6.0; + + @override + ShapeBorder get shape => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))); + + @override + SnackBarBehavior get behavior => SnackBarBehavior.fixed; + + @override + EdgeInsets get insetPadding => const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 10.0); + + @override + bool get showCloseIcon => false; + + @override + Color? get closeIconColor => _colors.onInverseSurface; + + @override + double get actionOverflowThreshold => 0.25; +} + +// END GENERATED TOKEN PROPERTIES - Snackbar diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/snack_bar_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/snack_bar_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..d0819ac69af3c2a502d89e963fa98f73133369a7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/snack_bar_theme.dart @@ -0,0 +1,294 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; +import 'theme.dart'; + +/// Defines where a [SnackBar] should appear within a [Scaffold] and how its +/// location should be adjusted when the scaffold also includes a +/// [FloatingActionButton] or a [BottomNavigationBar]. +enum SnackBarBehavior { + /// Fixes the [SnackBar] at the bottom of the [Scaffold]. + /// + /// The exception is that the [SnackBar] will be shown above a + /// [BottomNavigationBar] or a [NavigationBar]. Additionally, the [SnackBar] + /// will cause other non-fixed widgets inside [Scaffold] to be pushed above + /// (for example, the [FloatingActionButton]). + fixed, + + /// This behavior will cause [SnackBar] to be shown above other widgets in the + /// [Scaffold]. This includes being displayed above a [BottomNavigationBar] or + /// a [NavigationBar], and a [FloatingActionButton] when its location is on the + /// bottom. When the floating action button location is on the top, this behavior + /// will cause the [SnackBar] to be shown above other widgets in the [Scaffold] + /// except the floating action button. + /// + /// See <https://material.io/design/components/snackbars.html> for more details. + floating, +} + +/// Customizes default property values for [SnackBar] widgets. +/// +/// Descendant widgets obtain the current [SnackBarThemeData] object using +/// `Theme.of(context).snackBarTheme`. Instances of [SnackBarThemeData] can be +/// customized with [SnackBarThemeData.copyWith]. +/// +/// Typically a [SnackBarThemeData] is specified as part of the overall [Theme] +/// with [ThemeData.snackBarTheme]. The default for [ThemeData.snackBarTheme] +/// provides all `null` properties. +/// +/// All [SnackBarThemeData] properties are `null` by default. When null, the +/// [SnackBar] will provide its own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class SnackBarThemeData with Diagnosticable { + + /// Creates a theme that can be used for [ThemeData.snackBarTheme]. + /// + /// The [elevation] must be null or non-negative. + const SnackBarThemeData({ + this.backgroundColor, + this.actionTextColor, + this.disabledActionTextColor, + this.contentTextStyle, + this.elevation, + this.shape, + this.behavior, + this.width, + this.insetPadding, + this.showCloseIcon, + this.closeIconColor, + this.actionOverflowThreshold, + this.actionBackgroundColor, + this.disabledActionBackgroundColor, + this.dismissDirection, + }) : assert(elevation == null || elevation >= 0.0), + assert(width == null || identical(behavior, SnackBarBehavior.floating), + 'Width can only be set if behaviour is SnackBarBehavior.floating'), + assert(actionOverflowThreshold == null || (actionOverflowThreshold >= 0 && actionOverflowThreshold <= 1), + 'Action overflow threshold must be between 0 and 1 inclusive'), + assert(actionBackgroundColor is! MaterialStateColor || disabledActionBackgroundColor == null, + 'disabledBackgroundColor must not be provided when background color is ' + 'a MaterialStateColor'); + + /// Overrides the default value for [SnackBar.backgroundColor]. + /// + /// If null, [SnackBar] defaults to dark grey: `Color(0xFF323232)`. + final Color? backgroundColor; + + /// Overrides the default value for [SnackBarAction.textColor]. + /// + /// If null, [SnackBarAction] defaults to [ColorScheme.secondary] of + /// [ThemeData.colorScheme] . + final Color? actionTextColor; + + /// Overrides the default value for [SnackBarAction.disabledTextColor]. + /// + /// If null, [SnackBarAction] defaults to [ColorScheme.onSurface] with its + /// opacity set to 0.30 if the [Theme]'s brightness is [Brightness.dark], 0.38 + /// otherwise. + final Color? disabledActionTextColor; + + /// Used to configure the [DefaultTextStyle] for the [SnackBar.content] widget. + /// + /// If null, [SnackBar] defines its default. + final TextStyle? contentTextStyle; + + /// Overrides the default value for [SnackBar.elevation]. + /// + /// If null, [SnackBar] uses a default of 6.0. + final double? elevation; + + /// Overrides the default value for [SnackBar.shape]. + /// + /// If null, [SnackBar] provides different defaults depending on the + /// [SnackBarBehavior]. For [SnackBarBehavior.fixed], no overriding shape is + /// specified, so the [SnackBar] is rectangular. For + /// [SnackBarBehavior.floating], it uses a [RoundedRectangleBorder] with a + /// circular corner radius of 4.0. + final ShapeBorder? shape; + + /// Overrides the default value for [SnackBar.behavior]. + /// + /// If null, [SnackBar] will default to [SnackBarBehavior.fixed]. + final SnackBarBehavior? behavior; + + /// Overrides the default value for [SnackBar.width]. + /// + /// If this property is null, then the snack bar will take up the full device + /// width less the margin. This value is only used when [behavior] is + /// [SnackBarBehavior.floating]. + final double? width; + + /// Overrides the default value for [SnackBar.margin]. + /// + /// This value is only used when [behavior] is [SnackBarBehavior.floating]. + final EdgeInsets? insetPadding; + + /// Overrides the default value for [SnackBar.showCloseIcon]. + /// + /// Whether to show an optional "Close" icon. + final bool? showCloseIcon; + + /// Overrides the default value for [SnackBar.closeIconColor]. + /// + /// This value is only used if [showCloseIcon] is true. + final Color? closeIconColor; + + /// Overrides the default value for [SnackBar.actionOverflowThreshold]. + /// + /// Must be a value between 0 and 1, if present. + final double? actionOverflowThreshold; + /// Overrides default value for [SnackBarAction.backgroundColor]. + /// + /// If null, [SnackBarAction] falls back to [Colors.transparent]. + final Color? actionBackgroundColor; + + /// Overrides default value for [SnackBarAction.]. + /// + /// If null, [SnackBarAction] falls back to [Colors.transparent]. + final Color? disabledActionBackgroundColor; + + /// Overrides the default value for [SnackBar.dismissDirection]. + /// + /// If null, [SnackBar] will default to [DismissDirection.down]. + final DismissDirection? dismissDirection; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + SnackBarThemeData copyWith({ + Color? backgroundColor, + Color? actionTextColor, + Color? disabledActionTextColor, + TextStyle? contentTextStyle, + double? elevation, + ShapeBorder? shape, + SnackBarBehavior? behavior, + double? width, + EdgeInsets? insetPadding, + bool? showCloseIcon, + Color? closeIconColor, + double? actionOverflowThreshold, + Color? actionBackgroundColor, + Color? disabledActionBackgroundColor, + DismissDirection? dismissDirection, + }) { + return SnackBarThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + actionTextColor: actionTextColor ?? this.actionTextColor, + disabledActionTextColor: disabledActionTextColor ?? this.disabledActionTextColor, + contentTextStyle: contentTextStyle ?? this.contentTextStyle, + elevation: elevation ?? this.elevation, + shape: shape ?? this.shape, + behavior: behavior ?? this.behavior, + width: width ?? this.width, + insetPadding: insetPadding ?? this.insetPadding, + showCloseIcon: showCloseIcon ?? this.showCloseIcon, + closeIconColor: closeIconColor ?? this.closeIconColor, + actionOverflowThreshold: actionOverflowThreshold ?? this.actionOverflowThreshold, + actionBackgroundColor: actionBackgroundColor ?? this.actionBackgroundColor, + disabledActionBackgroundColor: disabledActionBackgroundColor ?? this.disabledActionBackgroundColor, + dismissDirection: dismissDirection ?? this.dismissDirection, + ); + } + + /// Linearly interpolate between two SnackBar Themes. + /// + /// {@macro dart.ui.shadow.lerp} + static SnackBarThemeData lerp(SnackBarThemeData? a, SnackBarThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return SnackBarThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + actionTextColor: Color.lerp(a?.actionTextColor, b?.actionTextColor, t), + disabledActionTextColor: Color.lerp(a?.disabledActionTextColor, b?.disabledActionTextColor, t), + contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + behavior: t < 0.5 ? a?.behavior : b?.behavior, + width: lerpDouble(a?.width, b?.width, t), + insetPadding: EdgeInsets.lerp(a?.insetPadding, b?.insetPadding, t), + closeIconColor: Color.lerp(a?.closeIconColor, b?.closeIconColor, t), + actionOverflowThreshold: lerpDouble(a?.actionOverflowThreshold, b?.actionOverflowThreshold, t), + actionBackgroundColor: Color.lerp(a?.actionBackgroundColor, b?.actionBackgroundColor, t), + disabledActionBackgroundColor: Color.lerp(a?.disabledActionBackgroundColor, b?.disabledActionBackgroundColor, t), + dismissDirection: t < 0.5 ? a?.dismissDirection : b?.dismissDirection, + ); + } + + @override + int get hashCode => Object.hash( + backgroundColor, + actionTextColor, + disabledActionTextColor, + contentTextStyle, + elevation, + shape, + behavior, + width, + insetPadding, + showCloseIcon, + closeIconColor, + actionOverflowThreshold, + actionBackgroundColor, + disabledActionBackgroundColor, + dismissDirection, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is SnackBarThemeData + && other.backgroundColor == backgroundColor + && other.actionTextColor == actionTextColor + && other.disabledActionTextColor == disabledActionTextColor + && other.contentTextStyle == contentTextStyle + && other.elevation == elevation + && other.shape == shape + && other.behavior == behavior + && other.width == width + && other.insetPadding == insetPadding + && other.showCloseIcon == showCloseIcon + && other.closeIconColor == closeIconColor + && other.actionOverflowThreshold == actionOverflowThreshold + && other.actionBackgroundColor == actionBackgroundColor + && other.disabledActionBackgroundColor == disabledActionBackgroundColor + && other.dismissDirection == dismissDirection; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(ColorProperty('actionTextColor', actionTextColor, defaultValue: null)); + properties.add(ColorProperty('disabledActionTextColor', disabledActionTextColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('contentTextStyle', contentTextStyle, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + properties.add(DiagnosticsProperty<SnackBarBehavior>('behavior', behavior, defaultValue: null)); + properties.add(DoubleProperty('width', width, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsets>('insetPadding', insetPadding, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('showCloseIcon', showCloseIcon, defaultValue: null)); + properties.add(ColorProperty('closeIconColor', closeIconColor, defaultValue: null)); + properties.add(DoubleProperty('actionOverflowThreshold', actionOverflowThreshold, defaultValue: null)); + properties.add(ColorProperty('actionBackgroundColor', actionBackgroundColor, defaultValue: null)); + properties.add(ColorProperty('disabledActionBackgroundColor', disabledActionBackgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<DismissDirection>('dismissDirection', dismissDirection, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/spell_check_suggestions_toolbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/spell_check_suggestions_toolbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..35aa913eb56e3e015b5edf79dc4f02ce4cdd59f6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/spell_check_suggestions_toolbar.dart @@ -0,0 +1,256 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart' show SelectionChangedCause, SuggestionSpan; + +import 'adaptive_text_selection_toolbar.dart'; +import 'colors.dart'; +import 'material.dart'; +import 'spell_check_suggestions_toolbar_layout_delegate.dart'; +import 'text_selection_toolbar_text_button.dart'; + +// The default height of the SpellCheckSuggestionsToolbar, which +// assumes there are the maximum number of spell check suggestions available, 3. +// Size eyeballed on Pixel 4 emulator running Android API 31. +const double _kDefaultToolbarHeight = 193.0; + +/// The maximum number of suggestions in the toolbar is 3, plus a delete button. +const int _kMaxSuggestions = 3; + +/// The default spell check suggestions toolbar for Android. +/// +/// Tries to position itself below the [anchor], but if it doesn't fit, then it +/// readjusts to fit above bottom view insets. +/// +/// See also: +/// +/// * [CupertinoSpellCheckSuggestionsToolbar], which is similar but builds an +/// iOS-style spell check toolbar. +class SpellCheckSuggestionsToolbar extends StatelessWidget { + /// Constructs a [SpellCheckSuggestionsToolbar]. + /// + /// [buttonItems] must not contain more than four items, generally three + /// suggestions and one delete button. + const SpellCheckSuggestionsToolbar({ + super.key, + required this.anchor, + required this.buttonItems, + }) : assert(buttonItems.length <= _kMaxSuggestions + 1); + + /// Constructs a [SpellCheckSuggestionsToolbar] with the default children for + /// an [EditableText]. + /// + /// See also: + /// * [CupertinoSpellCheckSuggestionsToolbar.editableText], which is similar + /// but builds an iOS-style toolbar. + SpellCheckSuggestionsToolbar.editableText({ + super.key, + required EditableTextState editableTextState, + }) : buttonItems = buildButtonItems(editableTextState) ?? <ContextMenuButtonItem>[], + anchor = getToolbarAnchor(editableTextState.contextMenuAnchors); + + /// {@template flutter.material.SpellCheckSuggestionsToolbar.anchor} + /// The focal point below which the toolbar attempts to position itself. + /// {@endtemplate} + final Offset anchor; + + /// The [ContextMenuButtonItem]s that will be turned into the correct button + /// widgets and displayed in the spell check suggestions toolbar. + /// + /// Must not contain more than four items, typically three suggestions and a + /// delete button. + /// + /// See also: + /// + /// * [AdaptiveTextSelectionToolbar.buttonItems], the list of + /// [ContextMenuButtonItem]s that are used to build the buttons of the + /// text selection toolbar. + /// * [CupertinoSpellCheckSuggestionsToolbar.buttonItems], the list of + /// [ContextMenuButtonItem]s used to build the Cupertino style spell check + /// suggestions toolbar. + final List<ContextMenuButtonItem> buttonItems; + + /// Builds the button items for the toolbar based on the available + /// spell check suggestions. + static List<ContextMenuButtonItem>? buildButtonItems( + EditableTextState editableTextState, + ) { + // Determine if composing region is misspelled. + final SuggestionSpan? spanAtCursorIndex = + editableTextState.findSuggestionSpanAtCursorIndex( + editableTextState.currentTextEditingValue.selection.baseOffset, + ); + + if (spanAtCursorIndex == null) { + return null; + } + + final List<ContextMenuButtonItem> buttonItems = <ContextMenuButtonItem>[]; + + // Build suggestion buttons. + for (final String suggestion in spanAtCursorIndex.suggestions.take(_kMaxSuggestions)) { + buttonItems.add(ContextMenuButtonItem( + onPressed: () { + if (!editableTextState.mounted) { + return; + } + _replaceText( + editableTextState, + suggestion, + spanAtCursorIndex.range, + ); + }, + label: suggestion, + )); + } + + // Build delete button. + final ContextMenuButtonItem deleteButton = + ContextMenuButtonItem( + onPressed: () { + if (!editableTextState.mounted) { + return; + } + _replaceText( + editableTextState, + '', + editableTextState.currentTextEditingValue.composing, + ); + }, + type: ContextMenuButtonType.delete, + ); + buttonItems.add(deleteButton); + + return buttonItems; + } + + static void _replaceText(EditableTextState editableTextState, String text, TextRange replacementRange) { + // Replacement cannot be performed if the text is read only or obscured. + assert(!editableTextState.widget.readOnly && !editableTextState.widget.obscureText); + + final TextEditingValue newValue = editableTextState.textEditingValue.replaced( + replacementRange, + text, + ); + editableTextState.userUpdateTextEditingValue(newValue, SelectionChangedCause.toolbar); + + // Schedule a call to bringIntoView() after renderEditable updates. + SchedulerBinding.instance.addPostFrameCallback((Duration duration) { + if (editableTextState.mounted) { + editableTextState.bringIntoView(editableTextState.textEditingValue.selection.extent); + } + }, debugLabel: 'SpellCheckerSuggestionsToolbar.bringIntoView'); + editableTextState.hideToolbar(); + } + + /// Determines the Offset that the toolbar will be anchored to. + static Offset getToolbarAnchor(TextSelectionToolbarAnchors anchors) { + // Since this will be positioned below the anchor point, use the secondary + // anchor by default. + return anchors.secondaryAnchor == null ? anchors.primaryAnchor : anchors.secondaryAnchor!; + } + + /// Builds the toolbar buttons based on the [buttonItems]. + List<Widget> _buildToolbarButtons(BuildContext context) { + return buttonItems.map((ContextMenuButtonItem buttonItem) { + final TextSelectionToolbarTextButton button = + TextSelectionToolbarTextButton( + padding: const EdgeInsets.fromLTRB(20, 0, 0, 0), + onPressed: buttonItem.onPressed, + alignment: Alignment.centerLeft, + child: Text( + AdaptiveTextSelectionToolbar.getButtonLabel(context, buttonItem), + style: buttonItem.type == ContextMenuButtonType.delete ? const TextStyle(color: Colors.blue) : null, + ), + ); + + if (buttonItem.type != ContextMenuButtonType.delete) { + return button; + } + return DecoratedBox( + decoration: const BoxDecoration(border: Border(top: BorderSide(color: Colors.grey))), + child: button, + ); + }).toList(); + } + + @override + Widget build(BuildContext context) { + if (buttonItems.isEmpty){ + return const SizedBox.shrink(); + } + + // Adjust toolbar height if needed. + final double spellCheckSuggestionsToolbarHeight = + _kDefaultToolbarHeight - (48.0 * (4 - buttonItems.length)); + // Incorporate the padding distance between the content and toolbar. + final MediaQueryData mediaQueryData = MediaQuery.of(context); + final double softKeyboardViewInsetsBottom = mediaQueryData.viewInsets.bottom; + final double paddingAbove = mediaQueryData.padding.top + + CupertinoTextSelectionToolbar.kToolbarScreenPadding; + // Makes up for the Padding. + final Offset localAdjustment = Offset( + CupertinoTextSelectionToolbar.kToolbarScreenPadding, + paddingAbove, + ); + + return Padding( + padding: EdgeInsets.fromLTRB( + CupertinoTextSelectionToolbar.kToolbarScreenPadding, + paddingAbove, + CupertinoTextSelectionToolbar.kToolbarScreenPadding, + CupertinoTextSelectionToolbar.kToolbarScreenPadding + softKeyboardViewInsetsBottom, + ), + child: CustomSingleChildLayout( + delegate: SpellCheckSuggestionsToolbarLayoutDelegate( + anchor: anchor - localAdjustment, + ), + child: AnimatedSize( + // This duration was eyeballed on a Pixel 2 emulator running Android + // API 28 for the Material TextSelectionToolbar. + duration: const Duration(milliseconds: 140), + child: _SpellCheckSuggestionsToolbarContainer( + height: spellCheckSuggestionsToolbarHeight, + children: <Widget>[..._buildToolbarButtons(context)], + ), + ), + ), + ); + } +} + +/// The Material-styled toolbar outline for the spell check suggestions +/// toolbar. +class _SpellCheckSuggestionsToolbarContainer extends StatelessWidget { + const _SpellCheckSuggestionsToolbarContainer({ + required this.height, + required this.children, + }); + + final double height; + final List<Widget> children; + + @override + Widget build(BuildContext context) { + return Material( + // This elevation was eyeballed on a Pixel 4 emulator running Android + // API 31 for the SpellCheckSuggestionsToolbar. + elevation: 2.0, + type: MaterialType.card, + child: SizedBox( + // This width was eyeballed on a Pixel 4 emulator running Android + // API 31 for the SpellCheckSuggestionsToolbar. + width: 165.0, + height: height, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: children, + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/spell_check_suggestions_toolbar_layout_delegate.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/spell_check_suggestions_toolbar_layout_delegate.dart new file mode 100644 index 0000000000000000000000000000000000000000..05dd0b45db843019894904d351cd1d66d9623646 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/spell_check_suggestions_toolbar_layout_delegate.dart @@ -0,0 +1,50 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart' show TextSelectionToolbarLayoutDelegate; + +/// Positions the toolbar below [anchor] or adjusts it higher to fit above +/// the bottom view insets, if applicable. +/// +/// See also: +/// +/// * [SpellCheckSuggestionsToolbar], which uses this to position itself. +class SpellCheckSuggestionsToolbarLayoutDelegate extends SingleChildLayoutDelegate { + /// Creates an instance of [SpellCheckSuggestionsToolbarLayoutDelegate]. + SpellCheckSuggestionsToolbarLayoutDelegate({ + required this.anchor, + }); + + /// {@macro flutter.material.SpellCheckSuggestionsToolbar.anchor} + /// + /// Should be provided in local coordinates. + final Offset anchor; + + @override + BoxConstraints getConstraintsForChild(BoxConstraints constraints) { + return constraints.loosen(); + } + + @override + Offset getPositionForChild(Size size, Size childSize) { + return Offset( + TextSelectionToolbarLayoutDelegate.centerOn( + anchor.dx, + childSize.width, + size.width, + ), + // Positions child (of childSize) just enough upwards to fit within size + // if it otherwise does not fit below the anchor. + anchor.dy + childSize.height > size.height + ? size.height - childSize.height + : anchor.dy, + ); + } + + @override + bool shouldRelayout(SpellCheckSuggestionsToolbarLayoutDelegate oldDelegate) { + return anchor != oldDelegate.anchor; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/stepper.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/stepper.dart new file mode 100644 index 0000000000000000000000000000000000000000..470fe0975f91cae157f9cd789f9074260cd8a598 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/stepper.dart @@ -0,0 +1,940 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'debug.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'text_button.dart'; +import 'text_theme.dart'; +import 'theme.dart'; + +// TODO(dragostis): Missing functionality: +// * mobile horizontal mode with adding/removing steps +// * alternative labeling +// * stepper feedback in the case of high-latency interactions + +/// The state of a [Step] which is used to control the style of the circle and +/// text. +/// +/// See also: +/// +/// * [Step] +enum StepState { + /// A step that displays its index in its circle. + indexed, + + /// A step that displays a pencil icon in its circle. + editing, + + /// A step that displays a tick icon in its circle. + complete, + + /// A step that is disabled and does not to react to taps. + disabled, + + /// A step that is currently having an error. e.g. the user has submitted wrong + /// input. + error, +} + +/// Defines the [Stepper]'s main axis. +enum StepperType { + /// A vertical layout of the steps with their content in-between the titles. + vertical, + + /// A horizontal layout of the steps with their content below the titles. + horizontal, +} + +/// Container for all the information necessary to build a Stepper widget's +/// forward and backward controls for any given step. +/// +/// Used by [Stepper.controlsBuilder]. +@immutable +class ControlsDetails { + /// Creates a set of details describing the Stepper. + const ControlsDetails({ + required this.currentStep, + required this.stepIndex, + this.onStepCancel, + this.onStepContinue, + }); + /// Index that is active for the surrounding [Stepper] widget. This may be + /// different from [stepIndex] if the user has just changed steps and we are + /// currently animating toward that step. + final int currentStep; + + /// Index of the step for which these controls are being built. This is + /// not necessarily the active index, if the user has just changed steps and + /// this step is animating away. To determine whether a given builder is building + /// the active step or the step being navigated away from, see [isActive]. + final int stepIndex; + + /// The callback called when the 'continue' button is tapped. + /// + /// If null, the 'continue' button will be disabled. + final VoidCallback? onStepContinue; + + /// The callback called when the 'cancel' button is tapped. + /// + /// If null, the 'cancel' button will be disabled. + final VoidCallback? onStepCancel; + + /// True if the indicated step is also the current active step. If the user has + /// just activated the transition to a new step, some [Stepper.type] values will + /// lead to both steps being rendered for the duration of the animation shifting + /// between steps. + bool get isActive => currentStep == stepIndex; +} + +/// A builder that creates a widget given the two callbacks `onStepContinue` and +/// `onStepCancel`. +/// +/// Used by [Stepper.controlsBuilder]. +/// +/// See also: +/// +/// * [WidgetBuilder], which is similar but only takes a [BuildContext]. +typedef ControlsWidgetBuilder = Widget Function(BuildContext context, ControlsDetails details); + +/// A builder that creates the icon widget for the [Step] at [stepIndex], given +/// [stepState]. +typedef StepIconBuilder = Widget? Function(int stepIndex, StepState stepState); + +const TextStyle _kStepStyle = TextStyle( + fontSize: 12.0, + color: Colors.white, +); +const Color _kErrorLight = Colors.red; +final Color _kErrorDark = Colors.red.shade400; +const Color _kCircleActiveLight = Colors.white; +const Color _kCircleActiveDark = Colors.black87; +const Color _kDisabledLight = Colors.black38; +const Color _kDisabledDark = Colors.white38; +const double _kStepSize = 24.0; +const double _kTriangleHeight = _kStepSize * 0.866025; // Triangle height. sqrt(3.0) / 2.0 + +/// A material step used in [Stepper]. The step can have a title and subtitle, +/// an icon within its circle, some content and a state that governs its +/// styling. +/// +/// See also: +/// +/// * [Stepper] +/// * <https://material.io/archive/guidelines/components/steppers.html> +@immutable +class Step { + /// Creates a step for a [Stepper]. + const Step({ + required this.title, + this.subtitle, + required this.content, + this.state = StepState.indexed, + this.isActive = false, + this.label, + }); + + /// The title of the step that typically describes it. + final Widget title; + + /// The subtitle of the step that appears below the title and has a smaller + /// font size. It typically gives more details that complement the title. + /// + /// If null, the subtitle is not shown. + final Widget? subtitle; + + /// The content of the step that appears below the [title] and [subtitle]. + /// + /// Below the content, every step has a 'continue' and 'cancel' button. + final Widget content; + + /// The state of the step which determines the styling of its components + /// and whether steps are interactive. + final StepState state; + + /// Whether or not the step is active. The flag only influences styling. + final bool isActive; + + /// Only [StepperType.horizontal], Optional widget that appears under the [title]. + /// By default, uses the `bodyLarge` theme. + final Widget? label; +} + +/// A material stepper widget that displays progress through a sequence of +/// steps. Steppers are particularly useful in the case of forms where one step +/// requires the completion of another one, or where multiple steps need to be +/// completed in order to submit the whole form. +/// +/// The widget is a flexible wrapper. A parent class should pass [currentStep] +/// to this widget based on some logic triggered by the three callbacks that it +/// provides. +/// +/// {@tool dartpad} +/// An example the shows how to use the [Stepper], and the [Stepper] UI +/// appearance. +/// +/// ** See code in examples/api/lib/material/stepper/stepper.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Step] +/// * <https://material.io/archive/guidelines/components/steppers.html> +class Stepper extends StatefulWidget { + /// Creates a stepper from a list of steps. + /// + /// This widget is not meant to be rebuilt with a different list of steps + /// unless a key is provided in order to distinguish the old stepper from the + /// new one. + const Stepper({ + super.key, + required this.steps, + this.controller, + this.physics, + this.type = StepperType.vertical, + this.currentStep = 0, + this.onStepTapped, + this.onStepContinue, + this.onStepCancel, + this.controlsBuilder, + this.elevation, + this.margin, + this.connectorColor, + this.connectorThickness, + this.stepIconBuilder, + }) : assert(0 <= currentStep && currentStep < steps.length); + + /// The steps of the stepper whose titles, subtitles, icons always get shown. + /// + /// The length of [steps] must not change. + final List<Step> steps; + + /// How the stepper's scroll view should respond to user input. + /// + /// For example, determines how the scroll view continues to + /// animate after the user stops dragging the scroll view. + /// + /// If the stepper is contained within another scrollable it + /// can be helpful to set this property to [ClampingScrollPhysics]. + final ScrollPhysics? physics; + + /// An object that can be used to control the position to which this scroll + /// view is scrolled. + /// + /// To control the initial scroll offset of the scroll view, provide a + /// [controller] with its [ScrollController.initialScrollOffset] property set. + final ScrollController? controller; + + /// The type of stepper that determines the layout. In the case of + /// [StepperType.horizontal], the content of the current step is displayed + /// underneath as opposed to the [StepperType.vertical] case where it is + /// displayed in-between. + final StepperType type; + + /// The index into [steps] of the current step whose content is displayed. + final int currentStep; + + /// The callback called when a step is tapped, with its index passed as + /// an argument. + final ValueChanged<int>? onStepTapped; + + /// The callback called when the 'continue' button is tapped. + /// + /// If null, the 'continue' button will be disabled. + final VoidCallback? onStepContinue; + + /// The callback called when the 'cancel' button is tapped. + /// + /// If null, the 'cancel' button will be disabled. + final VoidCallback? onStepCancel; + + /// The callback for creating custom controls. + /// + /// If null, the default controls from the current theme will be used. + /// + /// This callback which takes in a context and a [ControlsDetails] object, which + /// contains step information and two functions: [onStepContinue] and [onStepCancel]. + /// These can be used to control the stepper. For example, reading the + /// [ControlsDetails.currentStep] value within the callback can change the text + /// of the continue or cancel button depending on which step users are at. + /// + /// {@tool dartpad} + /// Creates a stepper control with custom buttons. + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return Stepper( + /// controlsBuilder: + /// (BuildContext context, ControlsDetails details) { + /// return Row( + /// children: <Widget>[ + /// TextButton( + /// onPressed: details.onStepContinue, + /// child: Text('Continue to Step ${details.stepIndex + 1}'), + /// ), + /// TextButton( + /// onPressed: details.onStepCancel, + /// child: Text('Back to Step ${details.stepIndex - 1}'), + /// ), + /// ], + /// ); + /// }, + /// steps: const <Step>[ + /// Step( + /// title: Text('A'), + /// content: SizedBox( + /// width: 100.0, + /// height: 100.0, + /// ), + /// ), + /// Step( + /// title: Text('B'), + /// content: SizedBox( + /// width: 100.0, + /// height: 100.0, + /// ), + /// ), + /// ], + /// ); + /// } + /// ``` + /// ** See code in examples/api/lib/material/stepper/stepper.controls_builder.0.dart ** + /// {@end-tool} + final ControlsWidgetBuilder? controlsBuilder; + + /// The elevation of this stepper's [Material] when [type] is [StepperType.horizontal]. + final double? elevation; + + /// Custom margin on vertical stepper. + final EdgeInsetsGeometry? margin; + + /// Customize connected lines colors. + /// + /// Resolves in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.disabled]. + /// + /// If not set then the widget will use default colors, primary for selected state + /// and grey.shade400 for disabled state. + final MaterialStateProperty<Color>? connectorColor; + + /// The thickness of the connecting lines. + final double? connectorThickness; + + /// Callback for creating custom icons for the [steps]. + /// + /// When overriding icon for [StepState.error], please return + /// a widget whose width and height are 14 pixels or less to avoid overflow. + /// + /// If null, the default icons will be used for respective [StepState]. + final StepIconBuilder? stepIconBuilder; + + @override + State<Stepper> createState() => _StepperState(); +} + +class _StepperState extends State<Stepper> with TickerProviderStateMixin { + late List<GlobalKey> _keys; + final Map<int, StepState> _oldStates = <int, StepState>{}; + + @override + void initState() { + super.initState(); + _keys = List<GlobalKey>.generate( + widget.steps.length, + (int i) => GlobalKey(), + ); + + for (int i = 0; i < widget.steps.length; i += 1) { + _oldStates[i] = widget.steps[i].state; + } + } + + @override + void didUpdateWidget(Stepper oldWidget) { + super.didUpdateWidget(oldWidget); + assert(widget.steps.length == oldWidget.steps.length); + + for (int i = 0; i < oldWidget.steps.length; i += 1) { + _oldStates[i] = oldWidget.steps[i].state; + } + } + + bool _isFirst(int index) { + return index == 0; + } + + bool _isLast(int index) { + return widget.steps.length - 1 == index; + } + + bool _isCurrent(int index) { + return widget.currentStep == index; + } + + bool _isDark() { + return Theme.of(context).brightness == Brightness.dark; + } + + bool _isLabel() { + for (final Step step in widget.steps) { + if (step.label != null) { + return true; + } + } + return false; + } + + Color _connectorColor(bool isActive) { + final ColorScheme colorScheme = Theme.of(context).colorScheme; + final Set<MaterialState> states = <MaterialState>{ + if (isActive) MaterialState.selected else MaterialState.disabled, + }; + final Color? resolvedConnectorColor = widget.connectorColor?.resolve(states); + if (resolvedConnectorColor != null) { + return resolvedConnectorColor; + } + return isActive ? colorScheme.primary : Colors.grey.shade400; + } + + Widget _buildLine(bool visible, bool isActive) { + return Container( + width: visible ? widget.connectorThickness ?? 1.0 : 0.0, + height: 16.0, + color: _connectorColor(isActive), + ); + } + + Widget _buildCircleChild(int index, bool oldState) { + final StepState state = oldState ? _oldStates[index]! : widget.steps[index].state; + final bool isDarkActive = _isDark() && widget.steps[index].isActive; + final Widget? icon = widget.stepIconBuilder?.call(index, state); + if (icon != null) { + return icon; + } + switch (state) { + case StepState.indexed: + case StepState.disabled: + return Text( + '${index + 1}', + style: isDarkActive ? _kStepStyle.copyWith(color: Colors.black87) : _kStepStyle, + ); + case StepState.editing: + return Icon( + Icons.edit, + color: isDarkActive ? _kCircleActiveDark : _kCircleActiveLight, + size: 18.0, + ); + case StepState.complete: + return Icon( + Icons.check, + color: isDarkActive ? _kCircleActiveDark : _kCircleActiveLight, + size: 18.0, + ); + case StepState.error: + return const Text('!', style: _kStepStyle); + } + } + + Color _circleColor(int index) { + final bool isActive = widget.steps[index].isActive; + final ColorScheme colorScheme = Theme.of(context).colorScheme; + final Set<MaterialState> states = <MaterialState>{ + if (isActive) MaterialState.selected else MaterialState.disabled, + }; + final Color? resolvedConnectorColor = widget.connectorColor?.resolve(states); + if (resolvedConnectorColor != null) { + return resolvedConnectorColor; + } + if (!_isDark()) { + return isActive ? colorScheme.primary : colorScheme.onSurface.withOpacity(0.38); + } else { + return isActive ? colorScheme.secondary : colorScheme.background; + } + } + + Widget _buildCircle(int index, bool oldState) { + return Container( + margin: const EdgeInsets.symmetric(vertical: 8.0), + width: _kStepSize, + height: _kStepSize, + child: AnimatedContainer( + curve: Curves.fastOutSlowIn, + duration: kThemeAnimationDuration, + decoration: BoxDecoration( + color: _circleColor(index), + shape: BoxShape.circle, + ), + child: Center( + child: _buildCircleChild(index, oldState && widget.steps[index].state == StepState.error), + ), + ), + ); + } + + Widget _buildTriangle(int index, bool oldState) { + return Container( + margin: const EdgeInsets.symmetric(vertical: 8.0), + width: _kStepSize, + height: _kStepSize, + child: Center( + child: SizedBox( + width: _kStepSize, + height: _kTriangleHeight, // Height of 24dp-long-sided equilateral triangle. + child: CustomPaint( + painter: _TrianglePainter( + color: _isDark() ? _kErrorDark : _kErrorLight, + ), + child: Align( + alignment: const Alignment(0.0, 0.8), // 0.8 looks better than the geometrical 0.33. + child: _buildCircleChild(index, oldState && widget.steps[index].state != StepState.error), + ), + ), + ), + ), + ); + } + + Widget _buildIcon(int index) { + if (widget.steps[index].state != _oldStates[index]) { + return AnimatedCrossFade( + firstChild: _buildCircle(index, true), + secondChild: _buildTriangle(index, true), + firstCurve: const Interval(0.0, 0.6, curve: Curves.fastOutSlowIn), + secondCurve: const Interval(0.4, 1.0, curve: Curves.fastOutSlowIn), + sizeCurve: Curves.fastOutSlowIn, + crossFadeState: widget.steps[index].state == StepState.error ? CrossFadeState.showSecond : CrossFadeState.showFirst, + duration: kThemeAnimationDuration, + ); + } else { + if (widget.steps[index].state != StepState.error) { + return _buildCircle(index, false); + } else { + return _buildTriangle(index, false); + } + } + } + + Widget _buildVerticalControls(int stepIndex) { + if (widget.controlsBuilder != null) { + return widget.controlsBuilder!( + context, + ControlsDetails( + currentStep: widget.currentStep, + onStepContinue: widget.onStepContinue, + onStepCancel: widget.onStepCancel, + stepIndex: stepIndex, + ), + ); + } + + final Color cancelColor; + switch (Theme.of(context).brightness) { + case Brightness.light: + cancelColor = Colors.black54; + case Brightness.dark: + cancelColor = Colors.white70; + } + + final ThemeData themeData = Theme.of(context); + final ColorScheme colorScheme = themeData.colorScheme; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + + const OutlinedBorder buttonShape = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(2))); + const EdgeInsets buttonPadding = EdgeInsets.symmetric(horizontal: 16.0); + + return Container( + margin: const EdgeInsets.only(top: 16.0), + child: ConstrainedBox( + constraints: const BoxConstraints.tightFor(height: 48.0), + child: Row( + // The Material spec no longer includes a Stepper widget. The continue + // and cancel button styles have been configured to match the original + // version of this widget. + children: <Widget>[ + TextButton( + onPressed: widget.onStepContinue, + style: ButtonStyle( + foregroundColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) { + return states.contains(MaterialState.disabled) ? null : (_isDark() ? colorScheme.onSurface : colorScheme.onPrimary); + }), + backgroundColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) { + return _isDark() || states.contains(MaterialState.disabled) ? null : colorScheme.primary; + }), + padding: const MaterialStatePropertyAll<EdgeInsetsGeometry>(buttonPadding), + shape: const MaterialStatePropertyAll<OutlinedBorder>(buttonShape), + ), + child: Text( + themeData.useMaterial3 + ? localizations.continueButtonLabel + : localizations.continueButtonLabel.toUpperCase() + ), + ), + Container( + margin: const EdgeInsetsDirectional.only(start: 8.0), + child: TextButton( + onPressed: widget.onStepCancel, + style: TextButton.styleFrom( + foregroundColor: cancelColor, + padding: buttonPadding, + shape: buttonShape, + ), + child: Text( + themeData.useMaterial3 + ? localizations.cancelButtonLabel + : localizations.cancelButtonLabel.toUpperCase() + ), + ), + ), + ], + ), + ), + ); + } + + TextStyle _titleStyle(int index) { + final ThemeData themeData = Theme.of(context); + final TextTheme textTheme = themeData.textTheme; + + switch (widget.steps[index].state) { + case StepState.indexed: + case StepState.editing: + case StepState.complete: + return textTheme.bodyLarge!; + case StepState.disabled: + return textTheme.bodyLarge!.copyWith( + color: _isDark() ? _kDisabledDark : _kDisabledLight, + ); + case StepState.error: + return textTheme.bodyLarge!.copyWith( + color: _isDark() ? _kErrorDark : _kErrorLight, + ); + } + } + + TextStyle _subtitleStyle(int index) { + final ThemeData themeData = Theme.of(context); + final TextTheme textTheme = themeData.textTheme; + + switch (widget.steps[index].state) { + case StepState.indexed: + case StepState.editing: + case StepState.complete: + return textTheme.bodySmall!; + case StepState.disabled: + return textTheme.bodySmall!.copyWith( + color: _isDark() ? _kDisabledDark : _kDisabledLight, + ); + case StepState.error: + return textTheme.bodySmall!.copyWith( + color: _isDark() ? _kErrorDark : _kErrorLight, + ); + } + } + + TextStyle _labelStyle(int index) { + final ThemeData themeData = Theme.of(context); + final TextTheme textTheme = themeData.textTheme; + + switch (widget.steps[index].state) { + case StepState.indexed: + case StepState.editing: + case StepState.complete: + return textTheme.bodyLarge!; + case StepState.disabled: + return textTheme.bodyLarge!.copyWith( + color: _isDark() ? _kDisabledDark : _kDisabledLight, + ); + case StepState.error: + return textTheme.bodyLarge!.copyWith( + color: _isDark() ? _kErrorDark : _kErrorLight, + ); + } + } + + Widget _buildHeaderText(int index) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + AnimatedDefaultTextStyle( + style: _titleStyle(index), + duration: kThemeAnimationDuration, + curve: Curves.fastOutSlowIn, + child: widget.steps[index].title, + ), + if (widget.steps[index].subtitle != null) + Container( + margin: const EdgeInsets.only(top: 2.0), + child: AnimatedDefaultTextStyle( + style: _subtitleStyle(index), + duration: kThemeAnimationDuration, + curve: Curves.fastOutSlowIn, + child: widget.steps[index].subtitle!, + ), + ), + ], + ); + } + + Widget _buildLabelText(int index) { + if (widget.steps[index].label != null) { + return AnimatedDefaultTextStyle( + style: _labelStyle(index), + duration: kThemeAnimationDuration, + child: widget.steps[index].label!, + ); + } + return const SizedBox.shrink(); + } + + Widget _buildVerticalHeader(int index) { + final bool isActive = widget.steps[index].isActive; + return Container( + margin: const EdgeInsets.symmetric(horizontal: 24.0), + child: Row( + children: <Widget>[ + Column( + children: <Widget>[ + // Line parts are always added in order for the ink splash to + // flood the tips of the connector lines. + _buildLine(!_isFirst(index), isActive), + _buildIcon(index), + _buildLine(!_isLast(index), isActive), + ], + ), + Expanded( + child: Container( + margin: const EdgeInsetsDirectional.only(start: 12.0), + child: _buildHeaderText(index), + ), + ), + ], + ), + ); + } + + Widget _buildVerticalBody(int index) { + return Stack( + children: <Widget>[ + PositionedDirectional( + start: 24.0, + top: 0.0, + bottom: 0.0, + child: SizedBox( + width: 24.0, + child: Center( + child: SizedBox( + width: widget.connectorThickness ?? 1.0, + child: Container( + color: _connectorColor(widget.steps[index].isActive), + ), + ), + ), + ), + ), + AnimatedCrossFade( + firstChild: Container(height: 0.0), + secondChild: Container( + margin: widget.margin ?? const EdgeInsetsDirectional.only( + start: 60.0, + end: 24.0, + bottom: 24.0, + ), + child: Column( + children: <Widget>[ + widget.steps[index].content, + _buildVerticalControls(index), + ], + ), + ), + firstCurve: const Interval(0.0, 0.6, curve: Curves.fastOutSlowIn), + secondCurve: const Interval(0.4, 1.0, curve: Curves.fastOutSlowIn), + sizeCurve: Curves.fastOutSlowIn, + crossFadeState: _isCurrent(index) ? CrossFadeState.showSecond : CrossFadeState.showFirst, + duration: kThemeAnimationDuration, + ), + ], + ); + } + + Widget _buildVertical() { + return ListView( + controller: widget.controller, + shrinkWrap: true, + physics: widget.physics, + children: <Widget>[ + for (int i = 0; i < widget.steps.length; i += 1) + Column( + key: _keys[i], + children: <Widget>[ + InkWell( + onTap: widget.steps[i].state != StepState.disabled ? () { + // In the vertical case we need to scroll to the newly tapped + // step. + Scrollable.ensureVisible( + _keys[i].currentContext!, + curve: Curves.fastOutSlowIn, + duration: kThemeAnimationDuration, + ); + + widget.onStepTapped?.call(i); + } : null, + canRequestFocus: widget.steps[i].state != StepState.disabled, + child: _buildVerticalHeader(i), + ), + _buildVerticalBody(i), + ], + ), + ], + ); + } + + Widget _buildHorizontal() { + final List<Widget> children = <Widget>[ + for (int i = 0; i < widget.steps.length; i += 1) ...<Widget>[ + InkResponse( + onTap: widget.steps[i].state != StepState.disabled ? () { + widget.onStepTapped?.call(i); + } : null, + canRequestFocus: widget.steps[i].state != StepState.disabled, + child: Row( + children: <Widget>[ + SizedBox( + height: _isLabel() ? 104.0 : 72.0, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: <Widget>[ + if (widget.steps[i].label != null) const SizedBox(height: 24.0,), + Center(child: _buildIcon(i)), + if (widget.steps[i].label != null) SizedBox(height : 24.0, child: _buildLabelText(i),), + ], + ), + ), + Container( + margin: const EdgeInsetsDirectional.only(start: 12.0), + child: _buildHeaderText(i), + ), + ], + ), + ), + if (!_isLast(i)) + Expanded( + child: Container( + key: Key('line$i'), + margin: const EdgeInsets.symmetric(horizontal: 8.0), + height: widget.connectorThickness ?? 1.0, + color: _connectorColor(widget.steps[i+1].isActive), + ), + ), + ], + ]; + + final List<Widget> stepPanels = <Widget>[]; + for (int i = 0; i < widget.steps.length; i += 1) { + stepPanels.add( + Visibility( + maintainState: true, + visible: i == widget.currentStep, + child: widget.steps[i].content, + ), + ); + } + + return Column( + children: <Widget>[ + Material( + elevation: widget.elevation ?? 2, + child: Container( + margin: const EdgeInsets.symmetric(horizontal: 24.0), + child: Row( + children: children, + ), + ), + ), + Expanded( + child: ListView( + controller: widget.controller, + physics: widget.physics, + padding: const EdgeInsets.all(24.0), + children: <Widget>[ + AnimatedSize( + curve: Curves.fastOutSlowIn, + duration: kThemeAnimationDuration, + child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: stepPanels), + ), + _buildVerticalControls(widget.currentStep), + ], + ), + ), + ], + ); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMaterialLocalizations(context)); + assert(() { + if (context.findAncestorWidgetOfExactType<Stepper>() != null) { + throw FlutterError( + 'Steppers must not be nested.\n' + 'The material specification advises that one should avoid embedding ' + 'steppers within steppers. ' + 'https://material.io/archive/guidelines/components/steppers.html#steppers-usage', + ); + } + return true; + }()); + switch (widget.type) { + case StepperType.vertical: + return _buildVertical(); + case StepperType.horizontal: + return _buildHorizontal(); + } + } +} + +// Paints a triangle whose base is the bottom of the bounding rectangle and its +// top vertex the middle of its top. +class _TrianglePainter extends CustomPainter { + _TrianglePainter({ + required this.color, + }); + + final Color color; + + @override + bool hitTest(Offset point) => true; // Hitting the rectangle is fine enough. + + @override + bool shouldRepaint(_TrianglePainter oldPainter) { + return oldPainter.color != color; + } + + @override + void paint(Canvas canvas, Size size) { + final double base = size.width; + final double halfBase = size.width / 2.0; + final double height = size.height; + final List<Offset> points = <Offset>[ + Offset(0.0, height), + Offset(base, height), + Offset(halfBase, 0.0), + ]; + + canvas.drawPath( + Path()..addPolygon(points, true), + Paint()..color = color, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/switch.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/switch.dart new file mode 100644 index 0000000000000000000000000000000000000000..2ad3179ee55070439ccb6be07800a5e67f5f40d2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/switch.dart @@ -0,0 +1,2246 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'material_state.dart'; +import 'shadows.dart'; +import 'switch_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; +import 'toggleable.dart'; + +// Examples can assume: +// bool _giveVerse = true; +// late StateSetter setState; + +const double _kSwitchMinSize = kMinInteractiveDimension - 8.0; + +enum _SwitchType { material, adaptive } + +/// A Material Design switch. +/// +/// Used to toggle the on/off state of a single setting. +/// +/// The switch itself does not maintain any state. Instead, when the state of +/// the switch changes, the widget calls the [onChanged] callback. Most widgets +/// that use a switch will listen for the [onChanged] callback and rebuild the +/// switch with a new [value] to update the visual appearance of the switch. +/// +/// If the [onChanged] callback is null, then the switch will be disabled (it +/// will not respond to input). A disabled switch's thumb and track are rendered +/// in shades of grey by default. The default appearance of a disabled switch +/// can be overridden with [inactiveThumbColor] and [inactiveTrackColor]. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// Material Design 3 provides the option to add icons on the thumb of the [Switch]. +/// If [ThemeData.useMaterial3] is set to true, users can use [Switch.thumbIcon] +/// to add optional Icons based on the different [MaterialState]s of the [Switch]. +/// +/// {@tool dartpad} +/// This example shows a toggleable [Switch]. When the thumb slides to the other +/// side of the track, the switch is toggled between on/off. +/// +/// ** See code in examples/api/lib/material/switch/switch.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to customize [Switch] using [MaterialStateProperty] +/// switch properties. +/// +/// ** See code in examples/api/lib/material/switch/switch.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to add icons on the thumb of the [Switch] using the +/// [Switch.thumbIcon] property. +/// +/// ** See code in examples/api/lib/material/switch/switch.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to use the ambient [CupertinoThemeData] to style all +/// widgets which would otherwise use iOS defaults. +/// +/// ** See code in examples/api/lib/material/switch/switch.3.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SwitchListTile], which combines this widget with a [ListTile] so that +/// you can give the switch a label. +/// * [Checkbox], another widget with similar semantics. +/// * [Radio], for selecting among a set of explicit values. +/// * [Slider], for selecting a value in a range. +/// * [MaterialStateProperty], an interface for objects that "resolve" to +/// different values depending on a widget's material state. +/// * <https://material.io/design/components/selection-controls.html#switches> +class Switch extends StatelessWidget { + /// Creates a Material Design switch. + /// + /// The switch itself does not maintain any state. Instead, when the state of + /// the switch changes, the widget calls the [onChanged] callback. Most widgets + /// that use a switch will listen for the [onChanged] callback and rebuild the + /// switch with a new [value] to update the visual appearance of the switch. + /// + /// The following arguments are required: + /// + /// * [value] determines whether this switch is on or off. + /// * [onChanged] is called when the user toggles the switch on or off. + const Switch({ + super.key, + required this.value, + required this.onChanged, + this.activeColor, + this.activeTrackColor, + this.inactiveThumbColor, + this.inactiveTrackColor, + this.activeThumbImage, + this.onActiveThumbImageError, + this.inactiveThumbImage, + this.onInactiveThumbImageError, + this.thumbColor, + this.trackColor, + this.trackOutlineColor, + this.trackOutlineWidth, + this.thumbIcon, + this.materialTapTargetSize, + this.dragStartBehavior = DragStartBehavior.start, + this.mouseCursor, + this.focusColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.focusNode, + this.onFocusChange, + this.autofocus = false, + }) : _switchType = _SwitchType.material, + applyCupertinoTheme = false, + assert(activeThumbImage != null || onActiveThumbImageError == null), + assert(inactiveThumbImage != null || onInactiveThumbImageError == null); + + /// Creates an adaptive [Switch] based on whether the target platform is iOS + /// or macOS, following Material design's + /// [Cross-platform guidelines](https://material.io/design/platform-guidance/cross-platform-adaptation.html). + /// + /// Creates a switch that looks and feels native when the [ThemeData.platform] + /// is iOS or macOS, otherwise a Material Design switch is created. + /// + /// To provide a custom switch theme that's only used by this factory + /// constructor, add a custom `Adaptation<SwitchThemeData>` class to + /// [ThemeData.adaptations]. This can be useful in situations where you don't + /// want the overall [ThemeData.switchTheme] to apply when this adaptive + /// constructor is used. + /// + /// {@tool dartpad} + /// This sample shows how to create and use subclasses of [Adaptation] that + /// define adaptive [SwitchThemeData]s. + /// + /// ** See code in examples/api/lib/material/switch/switch.4.dart ** + /// {@end-tool} + /// + /// The target platform is based on the current [Theme]: [ThemeData.platform]. + const Switch.adaptive({ + super.key, + required this.value, + required this.onChanged, + this.activeColor, + this.activeTrackColor, + this.inactiveThumbColor, + this.inactiveTrackColor, + this.activeThumbImage, + this.onActiveThumbImageError, + this.inactiveThumbImage, + this.onInactiveThumbImageError, + this.materialTapTargetSize, + this.thumbColor, + this.trackColor, + this.trackOutlineColor, + this.trackOutlineWidth, + this.thumbIcon, + this.dragStartBehavior = DragStartBehavior.start, + this.mouseCursor, + this.focusColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.focusNode, + this.onFocusChange, + this.autofocus = false, + this.applyCupertinoTheme, + }) : assert(activeThumbImage != null || onActiveThumbImageError == null), + assert(inactiveThumbImage != null || onInactiveThumbImageError == null), + _switchType = _SwitchType.adaptive; + + /// Whether this switch is on or off. + final bool value; + + /// Called when the user toggles the switch on or off. + /// + /// The switch passes the new value to the callback but does not actually + /// change state until the parent widget rebuilds the switch with the new + /// value. + /// + /// If null, the switch will be displayed as disabled. + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// ```dart + /// Switch( + /// value: _giveVerse, + /// onChanged: (bool newValue) { + /// setState(() { + /// _giveVerse = newValue; + /// }); + /// }, + /// ) + /// ``` + final ValueChanged<bool>? onChanged; + + /// {@template flutter.material.switch.activeColor} + /// The color to use when this switch is on. + /// {@endtemplate} + /// + /// Defaults to [ColorScheme.secondary]. + /// + /// If [thumbColor] returns a non-null color in the [MaterialState.selected] + /// state, it will be used instead of this color. + final Color? activeColor; + + /// {@template flutter.material.switch.activeTrackColor} + /// The color to use on the track when this switch is on. + /// {@endtemplate} + /// + /// Defaults to [ColorScheme.secondary] with the opacity set at 50%. + /// + /// If [trackColor] returns a non-null color in the [MaterialState.selected] + /// state, it will be used instead of this color. + final Color? activeTrackColor; + + /// {@template flutter.material.switch.inactiveThumbColor} + /// The color to use on the thumb when this switch is off. + /// {@endtemplate} + /// + /// Defaults to the colors described in the Material design specification. + /// + /// If [thumbColor] returns a non-null color in the default state, it will be + /// used instead of this color. + final Color? inactiveThumbColor; + + /// {@template flutter.material.switch.inactiveTrackColor} + /// The color to use on the track when this switch is off. + /// {@endtemplate} + /// + /// Defaults to the colors described in the Material design specification. + /// + /// If [trackColor] returns a non-null color in the default state, it will be + /// used instead of this color. + final Color? inactiveTrackColor; + + /// {@template flutter.material.switch.activeThumbImage} + /// An image to use on the thumb of this switch when the switch is on. + /// {@endtemplate} + final ImageProvider? activeThumbImage; + + /// {@template flutter.material.switch.onActiveThumbImageError} + /// An optional error callback for errors emitted when loading + /// [activeThumbImage]. + /// {@endtemplate} + final ImageErrorListener? onActiveThumbImageError; + + /// {@template flutter.material.switch.inactiveThumbImage} + /// An image to use on the thumb of this switch when the switch is off. + /// {@endtemplate} + final ImageProvider? inactiveThumbImage; + + /// {@template flutter.material.switch.onInactiveThumbImageError} + /// An optional error callback for errors emitted when loading + /// [inactiveThumbImage]. + /// {@endtemplate} + final ImageErrorListener? onInactiveThumbImageError; + + /// {@template flutter.material.switch.thumbColor} + /// The color of this [Switch]'s thumb. + /// + /// Resolved in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [thumbColor] based on the current + /// [MaterialState] of the [Switch], providing a different [Color] when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Switch( + /// value: true, + /// onChanged: (bool value) { }, + /// thumbColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) { + /// if (states.contains(MaterialState.disabled)) { + /// return Colors.orange.withOpacity(.48); + /// } + /// return Colors.orange; + /// }), + /// ) + /// ``` + /// {@end-tool} + /// {@endtemplate} + /// + /// If null, then the value of [activeColor] is used in the selected + /// state and [inactiveThumbColor] in the default state. If that is also null, + /// then the value of [SwitchThemeData.thumbColor] is used. If that is also + /// null, then the following colors are used: + /// + /// | State | Light theme | Dark theme | + /// |----------|-----------------------------------|-----------------------------------| + /// | Default | `Colors.grey.shade50` | `Colors.grey.shade400` | + /// | Selected | [ColorScheme.secondary] | [ColorScheme.secondary] | + /// | Disabled | `Colors.grey.shade400` | `Colors.grey.shade800` | + final MaterialStateProperty<Color?>? thumbColor; + + /// {@template flutter.material.switch.trackColor} + /// The color of this [Switch]'s track. + /// + /// Resolved in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [trackColor] based on the current + /// [MaterialState] of the [Switch], providing a different [Color] when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Switch( + /// value: true, + /// onChanged: (bool value) { }, + /// thumbColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) { + /// if (states.contains(MaterialState.disabled)) { + /// return Colors.orange.withOpacity(.48); + /// } + /// return Colors.orange; + /// }), + /// ) + /// ``` + /// {@end-tool} + /// {@endtemplate} + /// + /// If null, then the value of [activeTrackColor] is used in the selected + /// state and [inactiveTrackColor] in the default state. If that is also null, + /// then the value of [SwitchThemeData.trackColor] is used. If that is also + /// null, then the following colors are used: + /// + /// | State | Light theme | Dark theme | + /// |----------|---------------------------------|---------------------------------| + /// | Default | `Color(0x52000000)` | `Colors.white30` | + /// | Selected | [activeColor] with alpha `0x80` | [activeColor] with alpha `0x80` | + /// | Disabled | `Colors.black12` | `Colors.white10` | + final MaterialStateProperty<Color?>? trackColor; + + /// {@template flutter.material.switch.trackOutlineColor} + /// The outline color of this [Switch]'s track. + /// + /// Resolved in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [trackOutlineColor] based on the current + /// [MaterialState] of the [Switch], providing a different [Color] when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Switch( + /// value: true, + /// onChanged: (bool value) { }, + /// trackOutlineColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) { + /// if (states.contains(MaterialState.disabled)) { + /// return Colors.orange.withOpacity(.48); + /// } + /// return null; // Use the default color. + /// }), + /// ) + /// ``` + /// {@end-tool} + /// {@endtemplate} + /// + /// In Material 3, the outline color defaults to transparent in the selected + /// state and [ColorScheme.outline] in the unselected state. In Material 2, + /// the [Switch] track has no outline by default. + final MaterialStateProperty<Color?>? trackOutlineColor; + + /// {@template flutter.material.switch.trackOutlineWidth} + /// The outline width of this [Switch]'s track. + /// + /// Resolved in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [trackOutlineWidth] based on the current + /// [MaterialState] of the [Switch], providing a different outline width when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Switch( + /// value: true, + /// onChanged: (bool value) { }, + /// trackOutlineWidth: MaterialStateProperty.resolveWith<double?>((Set<MaterialState> states) { + /// if (states.contains(MaterialState.disabled)) { + /// return 5.0; + /// } + /// return null; // Use the default width. + /// }), + /// ) + /// ``` + /// {@end-tool} + /// {@endtemplate} + /// + /// Defaults to 2.0. + final MaterialStateProperty<double?>? trackOutlineWidth; + + /// {@template flutter.material.switch.thumbIcon} + /// The icon to use on the thumb of this switch + /// + /// Resolved in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [thumbIcon] based on the current + /// [MaterialState] of the [Switch], providing a different [Icon] when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Switch( + /// value: true, + /// onChanged: (bool value) { }, + /// thumbIcon: MaterialStateProperty.resolveWith<Icon?>((Set<MaterialState> states) { + /// if (states.contains(MaterialState.disabled)) { + /// return const Icon(Icons.close); + /// } + /// return null; // All other states will use the default thumbIcon. + /// }), + /// ) + /// ``` + /// {@end-tool} + /// {@endtemplate} + /// + /// If null, then the value of [SwitchThemeData.thumbIcon] is used. If this is also null, + /// then the [Switch] does not have any icons on the thumb. + final MaterialStateProperty<Icon?>? thumbIcon; + + /// {@template flutter.material.switch.materialTapTargetSize} + /// Configures the minimum size of the tap target. + /// {@endtemplate} + /// + /// If null, then the value of [SwitchThemeData.materialTapTargetSize] is + /// used. If that is also null, then the value of + /// [ThemeData.materialTapTargetSize] is used. + /// + /// See also: + /// + /// * [MaterialTapTargetSize], for a description of how this affects tap targets. + final MaterialTapTargetSize? materialTapTargetSize; + + final _SwitchType _switchType; + + /// {@macro flutter.cupertino.CupertinoSwitch.applyTheme} + final bool? applyCupertinoTheme; + + /// {@macro flutter.cupertino.CupertinoSwitch.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@template flutter.material.switch.mouseCursor} + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// {@endtemplate} + /// + /// If null, then the value of [SwitchThemeData.mouseCursor] is used. If that + /// is also null, then [MaterialStateMouseCursor.clickable] is used. + /// + /// See also: + /// + /// * [MaterialStateMouseCursor], a [MouseCursor] that implements + /// `MaterialStateProperty` which is used in APIs that need to accept + /// either a [MouseCursor] or a [MaterialStateProperty<MouseCursor>]. + final MouseCursor? mouseCursor; + + /// The color for the button's [Material] when it has the input focus. + /// + /// If [overlayColor] returns a non-null color in the [MaterialState.focused] + /// state, it will be used instead. + /// + /// If null, then the value of [SwitchThemeData.overlayColor] is used in the + /// focused state. If that is also null, then the value of + /// [ThemeData.focusColor] is used. + final Color? focusColor; + + /// The color for the button's [Material] when a pointer is hovering over it. + /// + /// If [overlayColor] returns a non-null color in the [MaterialState.hovered] + /// state, it will be used instead. + /// + /// If null, then the value of [SwitchThemeData.overlayColor] is used in the + /// hovered state. If that is also null, then the value of + /// [ThemeData.hoverColor] is used. + final Color? hoverColor; + + /// {@template flutter.material.switch.overlayColor} + /// The color for the switch's [Material]. + /// + /// Resolves in the following states: + /// * [MaterialState.pressed]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// {@endtemplate} + /// + /// If null, then the value of [activeColor] with alpha + /// [kRadialReactionAlpha], [focusColor] and [hoverColor] is used in the + /// pressed, focused and hovered state. If that is also null, + /// the value of [SwitchThemeData.overlayColor] is used. If that is + /// also null, then the value of [ColorScheme.secondary] with alpha + /// [kRadialReactionAlpha], [ThemeData.focusColor] and [ThemeData.hoverColor] + /// is used in the pressed, focused and hovered state. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@template flutter.material.switch.splashRadius} + /// The splash radius of the circular [Material] ink response. + /// {@endtemplate} + /// + /// If null, then the value of [SwitchThemeData.splashRadius] is used. If that + /// is also null, then [kRadialReactionRadius] is used. + final double? splashRadius; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.material.inkwell.onFocusChange} + final ValueChanged<bool>? onFocusChange; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + Size _getSwitchSize(BuildContext context) { + final ThemeData theme = Theme.of(context); + SwitchThemeData switchTheme = SwitchTheme.of(context); + if (_switchType == _SwitchType.adaptive) { + final Adaptation<SwitchThemeData> switchAdaptation = theme.getAdaptation<SwitchThemeData>() + ?? const _SwitchThemeAdaptation(); + switchTheme = switchAdaptation.adapt(theme, switchTheme); + } + final _SwitchConfig switchConfig = theme.useMaterial3 ? _SwitchConfigM3(context) : _SwitchConfigM2(); + + final MaterialTapTargetSize effectiveMaterialTapTargetSize = materialTapTargetSize + ?? switchTheme.materialTapTargetSize + ?? theme.materialTapTargetSize; + switch (effectiveMaterialTapTargetSize) { + case MaterialTapTargetSize.padded: + return Size(switchConfig.switchWidth, switchConfig.switchHeight); + case MaterialTapTargetSize.shrinkWrap: + return Size(switchConfig.switchWidth, switchConfig.switchHeightCollapsed); + } + } + + @override + Widget build(BuildContext context) { + Color? effectiveActiveThumbColor; + Color? effectiveActiveTrackColor; + + switch (_switchType) { + case _SwitchType.material: + effectiveActiveThumbColor = activeColor; + case _SwitchType.adaptive: + switch (Theme.of(context).platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + effectiveActiveThumbColor = activeColor; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + effectiveActiveTrackColor = activeColor; + } + } + return _MaterialSwitch( + value: value, + onChanged: onChanged, + size: _getSwitchSize(context), + activeColor: effectiveActiveThumbColor, + activeTrackColor: activeTrackColor ?? effectiveActiveTrackColor, + inactiveThumbColor: inactiveThumbColor, + inactiveTrackColor: inactiveTrackColor, + activeThumbImage: activeThumbImage, + onActiveThumbImageError: onActiveThumbImageError, + inactiveThumbImage: inactiveThumbImage, + onInactiveThumbImageError: onInactiveThumbImageError, + thumbColor: thumbColor, + trackColor: trackColor, + trackOutlineColor: trackOutlineColor, + trackOutlineWidth: trackOutlineWidth, + thumbIcon: thumbIcon, + materialTapTargetSize: materialTapTargetSize, + dragStartBehavior: dragStartBehavior, + mouseCursor: mouseCursor, + focusColor: focusColor, + hoverColor: hoverColor, + overlayColor: overlayColor, + splashRadius: splashRadius, + focusNode: focusNode, + onFocusChange: onFocusChange, + autofocus: autofocus, + applyCupertinoTheme: applyCupertinoTheme, + switchType: _switchType, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('value', value: value, ifTrue: 'on', ifFalse: 'off', showName: true)); + properties.add(ObjectFlagProperty<ValueChanged<bool>>('onChanged', onChanged, ifNull: 'disabled')); + } +} + +class _MaterialSwitch extends StatefulWidget { + const _MaterialSwitch({ + required this.value, + required this.onChanged, + required this.size, + required this.switchType, + this.activeColor, + this.activeTrackColor, + this.inactiveThumbColor, + this.inactiveTrackColor, + this.activeThumbImage, + this.onActiveThumbImageError, + this.inactiveThumbImage, + this.onInactiveThumbImageError, + this.thumbColor, + this.trackColor, + this.trackOutlineColor, + this.trackOutlineWidth, + this.thumbIcon, + this.materialTapTargetSize, + this.dragStartBehavior = DragStartBehavior.start, + this.mouseCursor, + this.focusColor, + this.hoverColor, + this.overlayColor, + this.splashRadius, + this.focusNode, + this.onFocusChange, + this.autofocus = false, + this.applyCupertinoTheme, + }) : assert(activeThumbImage != null || onActiveThumbImageError == null), + assert(inactiveThumbImage != null || onInactiveThumbImageError == null); + + final bool value; + final ValueChanged<bool>? onChanged; + final Color? activeColor; + final Color? activeTrackColor; + final Color? inactiveThumbColor; + final Color? inactiveTrackColor; + final ImageProvider? activeThumbImage; + final ImageErrorListener? onActiveThumbImageError; + final ImageProvider? inactiveThumbImage; + final ImageErrorListener? onInactiveThumbImageError; + final MaterialStateProperty<Color?>? thumbColor; + final MaterialStateProperty<Color?>? trackColor; + final MaterialStateProperty<Color?>? trackOutlineColor; + final MaterialStateProperty<double?>? trackOutlineWidth; + final MaterialStateProperty<Icon?>? thumbIcon; + final MaterialTapTargetSize? materialTapTargetSize; + final DragStartBehavior dragStartBehavior; + final MouseCursor? mouseCursor; + final Color? focusColor; + final Color? hoverColor; + final MaterialStateProperty<Color?>? overlayColor; + final double? splashRadius; + final FocusNode? focusNode; + final ValueChanged<bool>? onFocusChange; + final bool autofocus; + final Size size; + final bool? applyCupertinoTheme; + final _SwitchType switchType; + + @override + State<StatefulWidget> createState() => _MaterialSwitchState(); +} + +class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderStateMixin, ToggleableStateMixin { + final _SwitchPainter _painter = _SwitchPainter(); + + @override + void didUpdateWidget(_MaterialSwitch oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.value != widget.value) { + // During a drag we may have modified the curve, reset it if its possible + // to do without visual discontinuation. + if (position.value == 0.0 || position.value == 1.0) { + switch (widget.switchType) { + case _SwitchType.adaptive: + switch (Theme.of(context).platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + updateCurve(); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + position + ..curve = Curves.linear + ..reverseCurve = Curves.linear; + } + case _SwitchType.material: + updateCurve(); + } + + } + animateToValue(); + } + } + + @override + void dispose() { + _painter.dispose(); + super.dispose(); + } + + @override + ValueChanged<bool?>? get onChanged => widget.onChanged != null ? _handleChanged : null; + + @override + bool get tristate => false; + + @override + bool? get value => widget.value; + + void updateCurve() { + if (Theme.of(context).useMaterial3) { + position + ..curve = Curves.easeOutBack + ..reverseCurve = Curves.easeOutBack.flipped; + } else { + position + ..curve = Curves.easeIn + ..reverseCurve = Curves.easeOut; + } + } + + MaterialStateProperty<Color?> get _widgetThumbColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return widget.inactiveThumbColor; + } + if (states.contains(MaterialState.selected)) { + return widget.activeColor; + } + return widget.inactiveThumbColor; + }); + } + + MaterialStateProperty<Color?> get _widgetTrackColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return widget.activeTrackColor; + } + return widget.inactiveTrackColor; + }); + } + + double get _trackInnerLength { + switch (widget.switchType) { + case _SwitchType.adaptive: + switch (Theme.of(context).platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return widget.size.width - _kSwitchMinSize; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + final _SwitchConfig config = _SwitchConfigCupertino(context); + final double trackInnerStart = config.trackHeight / 2.0; + final double trackInnerEnd = config.trackWidth - trackInnerStart; + final double trackInnerLength = trackInnerEnd - trackInnerStart; + return trackInnerLength; + } + case _SwitchType.material: + return widget.size.width - _kSwitchMinSize; + } + } + + void _handleDragStart(DragStartDetails details) { + if (isInteractive) { + reactionController.forward(); + } + } + + void _handleDragUpdate(DragUpdateDetails details) { + if (isInteractive) { + position + ..curve = Curves.linear + ..reverseCurve = null; + final double delta = details.primaryDelta! / _trackInnerLength; + switch (Directionality.of(context)) { + case TextDirection.rtl: + positionController.value -= delta; + case TextDirection.ltr: + positionController.value += delta; + } + } + } + + bool _needsPositionAnimation = false; + + void _handleDragEnd(DragEndDetails details) { + if (position.value >= 0.5 != widget.value) { + widget.onChanged?.call(!widget.value); + // Wait with finishing the animation until widget.value has changed to + // !widget.value as part of the widget.onChanged call above. + setState(() { + _needsPositionAnimation = true; + }); + } else { + animateToValue(); + } + reactionController.reverse(); + + } + + void _handleChanged(bool? value) { + assert(value != null); + assert(widget.onChanged != null); + widget.onChanged?.call(value!); + } + + bool isCupertino = false; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + + if (_needsPositionAnimation) { + _needsPositionAnimation = false; + animateToValue(); + } + + final ThemeData theme = Theme.of(context); + SwitchThemeData switchTheme = SwitchTheme.of(context); + final Color cupertinoPrimaryColor = theme.cupertinoOverrideTheme?.primaryColor ?? theme.colorScheme.primary; + + _SwitchConfig switchConfig; + SwitchThemeData defaults; + bool applyCupertinoTheme = false; + double disabledOpacity = 1; + switch (widget.switchType) { + case _SwitchType.material: + switchConfig = theme.useMaterial3 ? _SwitchConfigM3(context) : _SwitchConfigM2(); + defaults = theme.useMaterial3 ? _SwitchDefaultsM3(context) : _SwitchDefaultsM2(context); + case _SwitchType.adaptive: + final Adaptation<SwitchThemeData> switchAdaptation = theme.getAdaptation<SwitchThemeData>() + ?? const _SwitchThemeAdaptation(); + switchTheme = switchAdaptation.adapt(theme, switchTheme); + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + switchConfig = theme.useMaterial3 ? _SwitchConfigM3(context) : _SwitchConfigM2(); + defaults = theme.useMaterial3 ? _SwitchDefaultsM3(context) : _SwitchDefaultsM2(context); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + isCupertino = true; + applyCupertinoTheme = widget.applyCupertinoTheme + ?? theme.cupertinoOverrideTheme?.applyThemeToAll + ?? false; + disabledOpacity = 0.5; + switchConfig = _SwitchConfigCupertino(context); + defaults = _SwitchDefaultsCupertino(context); + reactionController.duration = const Duration(milliseconds: 200); + } + } + + positionController.duration = Duration(milliseconds: switchConfig.toggleDuration); + + // Colors need to be resolved in selected and non selected states separately + // so that they can be lerped between. + final Set<MaterialState> activeStates = states..add(MaterialState.selected); + final Set<MaterialState> inactiveStates = states..remove(MaterialState.selected); + + final Color? activeThumbColor = widget.thumbColor?.resolve(activeStates) + ?? _widgetThumbColor.resolve(activeStates) + ?? switchTheme.thumbColor?.resolve(activeStates); + final Color effectiveActiveThumbColor = activeThumbColor + ?? defaults.thumbColor!.resolve(activeStates)!; + final Color? inactiveThumbColor = widget.thumbColor?.resolve(inactiveStates) + ?? _widgetThumbColor.resolve(inactiveStates) + ?? switchTheme.thumbColor?.resolve(inactiveStates); + final Color effectiveInactiveThumbColor = inactiveThumbColor + ?? defaults.thumbColor!.resolve(inactiveStates)!; + final Color effectiveActiveTrackColor = widget.trackColor?.resolve(activeStates) + ?? _widgetTrackColor.resolve(activeStates) + ?? (applyCupertinoTheme ? cupertinoPrimaryColor : switchTheme.trackColor?.resolve(activeStates)) + ?? _widgetThumbColor.resolve(activeStates)?.withAlpha(0x80) + ?? defaults.trackColor!.resolve(activeStates)!; + final Color? effectiveActiveTrackOutlineColor = widget.trackOutlineColor?.resolve(activeStates) + ?? switchTheme.trackOutlineColor?.resolve(activeStates) + ?? defaults.trackOutlineColor!.resolve(activeStates); + final double? effectiveActiveTrackOutlineWidth = widget.trackOutlineWidth?.resolve(activeStates) + ?? switchTheme.trackOutlineWidth?.resolve(activeStates) + ?? defaults.trackOutlineWidth?.resolve(activeStates); + + final Color effectiveInactiveTrackColor = widget.trackColor?.resolve(inactiveStates) + ?? _widgetTrackColor.resolve(inactiveStates) + ?? switchTheme.trackColor?.resolve(inactiveStates) + ?? defaults.trackColor!.resolve(inactiveStates)!; + final Color? effectiveInactiveTrackOutlineColor = widget.trackOutlineColor?.resolve(inactiveStates) + ?? switchTheme.trackOutlineColor?.resolve(inactiveStates) + ?? defaults.trackOutlineColor?.resolve(inactiveStates); + final double? effectiveInactiveTrackOutlineWidth = widget.trackOutlineWidth?.resolve(inactiveStates) + ?? switchTheme.trackOutlineWidth?.resolve(inactiveStates) + ?? defaults.trackOutlineWidth?.resolve(inactiveStates); + + final Icon? effectiveActiveIcon = widget.thumbIcon?.resolve(activeStates) + ?? switchTheme.thumbIcon?.resolve(activeStates); + final Icon? effectiveInactiveIcon = widget.thumbIcon?.resolve(inactiveStates) + ?? switchTheme.thumbIcon?.resolve(inactiveStates); + + final Color effectiveActiveIconColor = effectiveActiveIcon?.color ?? switchConfig.iconColor.resolve(activeStates); + final Color effectiveInactiveIconColor = effectiveInactiveIcon?.color ?? switchConfig.iconColor.resolve(inactiveStates); + + final Set<MaterialState> focusedStates = states..add(MaterialState.focused); + final Color effectiveFocusOverlayColor = widget.overlayColor?.resolve(focusedStates) + ?? widget.focusColor + ?? switchTheme.overlayColor?.resolve(focusedStates) + ?? (applyCupertinoTheme + ? HSLColor + .fromColor(cupertinoPrimaryColor.withOpacity(0.80)) + .withLightness(0.69).withSaturation(0.835) + .toColor() + : null) + ?? defaults.overlayColor!.resolve(focusedStates)!; + + final Set<MaterialState> hoveredStates = states..add(MaterialState.hovered); + final Color effectiveHoverOverlayColor = widget.overlayColor?.resolve(hoveredStates) + ?? widget.hoverColor + ?? switchTheme.overlayColor?.resolve(hoveredStates) + ?? defaults.overlayColor!.resolve(hoveredStates)!; + + final Set<MaterialState> activePressedStates = activeStates..add(MaterialState.pressed); + final Color effectiveActivePressedThumbColor = widget.thumbColor?.resolve(activePressedStates) + ?? _widgetThumbColor.resolve(activePressedStates) + ?? switchTheme.thumbColor?.resolve(activePressedStates) + ?? defaults.thumbColor!.resolve(activePressedStates)!; + final Color effectiveActivePressedOverlayColor = widget.overlayColor?.resolve(activePressedStates) + ?? switchTheme.overlayColor?.resolve(activePressedStates) + ?? activeThumbColor?.withAlpha(kRadialReactionAlpha) + ?? defaults.overlayColor!.resolve(activePressedStates)!; + + final Set<MaterialState> inactivePressedStates = inactiveStates..add(MaterialState.pressed); + final Color effectiveInactivePressedThumbColor = widget.thumbColor?.resolve(inactivePressedStates) + ?? _widgetThumbColor.resolve(inactivePressedStates) + ?? switchTheme.thumbColor?.resolve(inactivePressedStates) + ?? defaults.thumbColor!.resolve(inactivePressedStates)!; + final Color effectiveInactivePressedOverlayColor = widget.overlayColor?.resolve(inactivePressedStates) + ?? switchTheme.overlayColor?.resolve(inactivePressedStates) + ?? inactiveThumbColor?.withAlpha(kRadialReactionAlpha) + ?? defaults.overlayColor!.resolve(inactivePressedStates)!; + + final MaterialStateProperty<MouseCursor> effectiveMouseCursor = MaterialStateProperty.resolveWith<MouseCursor>((Set<MaterialState> states) { + return MaterialStateProperty.resolveAs<MouseCursor?>(widget.mouseCursor, states) + ?? switchTheme.mouseCursor?.resolve(states) + ?? defaults.mouseCursor!.resolve(states)!; + }); + + final double effectiveActiveThumbRadius = effectiveActiveIcon == null ? switchConfig.activeThumbRadius : switchConfig.thumbRadiusWithIcon; + final double effectiveInactiveThumbRadius = effectiveInactiveIcon == null && widget.inactiveThumbImage == null + ? switchConfig.inactiveThumbRadius : switchConfig.thumbRadiusWithIcon; + final double effectiveSplashRadius = widget.splashRadius ?? switchTheme.splashRadius ?? defaults.splashRadius!; + + return Semantics( + toggled: widget.value, + child: GestureDetector( + excludeFromSemantics: true, + onHorizontalDragStart: _handleDragStart, + onHorizontalDragUpdate: _handleDragUpdate, + onHorizontalDragEnd: _handleDragEnd, + dragStartBehavior: widget.dragStartBehavior, + child: Opacity( + opacity: onChanged == null ? disabledOpacity : 1, + child: buildToggleable( + mouseCursor: effectiveMouseCursor, + focusNode: widget.focusNode, + onFocusChange: widget.onFocusChange, + autofocus: widget.autofocus, + size: widget.size, + painter: _painter + ..position = position + ..reaction = reaction + ..reactionFocusFade = reactionFocusFade + ..reactionHoverFade = reactionHoverFade + ..inactiveReactionColor = effectiveInactivePressedOverlayColor + ..reactionColor = effectiveActivePressedOverlayColor + ..hoverColor = effectiveHoverOverlayColor + ..focusColor = effectiveFocusOverlayColor + ..splashRadius = effectiveSplashRadius + ..downPosition = downPosition + ..isFocused = states.contains(MaterialState.focused) + ..isHovered = states.contains(MaterialState.hovered) + ..activeColor = effectiveActiveThumbColor + ..inactiveColor = effectiveInactiveThumbColor + ..activePressedColor = effectiveActivePressedThumbColor + ..inactivePressedColor = effectiveInactivePressedThumbColor + ..activeThumbImage = widget.activeThumbImage + ..onActiveThumbImageError = widget.onActiveThumbImageError + ..inactiveThumbImage = widget.inactiveThumbImage + ..onInactiveThumbImageError = widget.onInactiveThumbImageError + ..activeTrackColor = effectiveActiveTrackColor + ..activeTrackOutlineColor = effectiveActiveTrackOutlineColor + ..activeTrackOutlineWidth = effectiveActiveTrackOutlineWidth + ..inactiveTrackColor = effectiveInactiveTrackColor + ..inactiveTrackOutlineColor = effectiveInactiveTrackOutlineColor + ..inactiveTrackOutlineWidth = effectiveInactiveTrackOutlineWidth + ..configuration = createLocalImageConfiguration(context) + ..isInteractive = isInteractive + ..trackInnerLength = _trackInnerLength + ..textDirection = Directionality.of(context) + ..surfaceColor = theme.colorScheme.surface + ..inactiveThumbRadius = effectiveInactiveThumbRadius + ..activeThumbRadius = effectiveActiveThumbRadius + ..pressedThumbRadius = switchConfig.pressedThumbRadius + ..thumbOffset = switchConfig.thumbOffset + ..trackHeight = switchConfig.trackHeight + ..trackWidth = switchConfig.trackWidth + ..activeIconColor = effectiveActiveIconColor + ..inactiveIconColor = effectiveInactiveIconColor + ..activeIcon = effectiveActiveIcon + ..inactiveIcon = effectiveInactiveIcon + ..iconTheme = IconTheme.of(context) + ..thumbShadow = switchConfig.thumbShadow + ..transitionalThumbSize = switchConfig.transitionalThumbSize + ..positionController = positionController + ..isCupertino = isCupertino, + ), + ), + ), + ); + } +} + +class _SwitchPainter extends ToggleablePainter { + AnimationController get positionController => _positionController!; + AnimationController? _positionController; + set positionController(AnimationController? value) { + assert(value != null); + if (value == _positionController) { + return; + } + _positionController = value; + notifyListeners(); + } + + Icon? get activeIcon => _activeIcon; + Icon? _activeIcon; + set activeIcon(Icon? value) { + if (value == _activeIcon) { + return; + } + _activeIcon = value; + notifyListeners(); + } + + Icon? get inactiveIcon => _inactiveIcon; + Icon? _inactiveIcon; + set inactiveIcon(Icon? value) { + if (value == _inactiveIcon) { + return; + } + _inactiveIcon = value; + notifyListeners(); + } + + IconThemeData? get iconTheme => _iconTheme; + IconThemeData? _iconTheme; + set iconTheme(IconThemeData? value) { + if (value == _iconTheme) { + return; + } + _iconTheme = value; + notifyListeners(); + } + + Color get activeIconColor => _activeIconColor!; + Color? _activeIconColor; + set activeIconColor(Color value) { + if (value == _activeIconColor) { + return; + } + _activeIconColor = value; + notifyListeners(); + } + + Color get inactiveIconColor => _inactiveIconColor!; + Color? _inactiveIconColor; + set inactiveIconColor(Color value) { + if (value == _inactiveIconColor) { + return; + } + _inactiveIconColor = value; + notifyListeners(); + } + + Color get activePressedColor => _activePressedColor!; + Color? _activePressedColor; + set activePressedColor(Color? value) { + assert(value != null); + if (value == _activePressedColor) { + return; + } + _activePressedColor = value; + notifyListeners(); + } + + Color get inactivePressedColor => _inactivePressedColor!; + Color? _inactivePressedColor; + set inactivePressedColor(Color? value) { + assert(value != null); + if (value == _inactivePressedColor) { + return; + } + _inactivePressedColor = value; + notifyListeners(); + } + + double get activeThumbRadius => _activeThumbRadius!; + double? _activeThumbRadius; + set activeThumbRadius(double value) { + if (value == _activeThumbRadius) { + return; + } + _activeThumbRadius = value; + notifyListeners(); + } + + double get inactiveThumbRadius => _inactiveThumbRadius!; + double? _inactiveThumbRadius; + set inactiveThumbRadius(double value) { + if (value == _inactiveThumbRadius) { + return; + } + _inactiveThumbRadius = value; + notifyListeners(); + } + + double get pressedThumbRadius => _pressedThumbRadius!; + double? _pressedThumbRadius; + set pressedThumbRadius(double value) { + if (value == _pressedThumbRadius) { + return; + } + _pressedThumbRadius = value; + notifyListeners(); + } + + double? get thumbOffset => _thumbOffset; + double? _thumbOffset; + set thumbOffset(double? value) { + if (value == _thumbOffset) { + return; + } + _thumbOffset = value; + notifyListeners(); + } + + Size get transitionalThumbSize => _transitionalThumbSize!; + Size? _transitionalThumbSize; + set transitionalThumbSize(Size value) { + if (value == _transitionalThumbSize) { + return; + } + _transitionalThumbSize = value; + notifyListeners(); + } + + double get trackHeight => _trackHeight!; + double? _trackHeight; + set trackHeight(double value) { + if (value == _trackHeight) { + return; + } + _trackHeight = value; + notifyListeners(); + } + + double get trackWidth => _trackWidth!; + double? _trackWidth; + set trackWidth(double value) { + if (value == _trackWidth) { + return; + } + _trackWidth = value; + notifyListeners(); + } + + ImageProvider? get activeThumbImage => _activeThumbImage; + ImageProvider? _activeThumbImage; + set activeThumbImage(ImageProvider? value) { + if (value == _activeThumbImage) { + return; + } + _activeThumbImage = value; + notifyListeners(); + } + + ImageErrorListener? get onActiveThumbImageError => _onActiveThumbImageError; + ImageErrorListener? _onActiveThumbImageError; + set onActiveThumbImageError(ImageErrorListener? value) { + if (value == _onActiveThumbImageError) { + return; + } + _onActiveThumbImageError = value; + notifyListeners(); + } + + ImageProvider? get inactiveThumbImage => _inactiveThumbImage; + ImageProvider? _inactiveThumbImage; + set inactiveThumbImage(ImageProvider? value) { + if (value == _inactiveThumbImage) { + return; + } + _inactiveThumbImage = value; + notifyListeners(); + } + + ImageErrorListener? get onInactiveThumbImageError => _onInactiveThumbImageError; + ImageErrorListener? _onInactiveThumbImageError; + set onInactiveThumbImageError(ImageErrorListener? value) { + if (value == _onInactiveThumbImageError) { + return; + } + _onInactiveThumbImageError = value; + notifyListeners(); + } + + Color get activeTrackColor => _activeTrackColor!; + Color? _activeTrackColor; + set activeTrackColor(Color value) { + if (value == _activeTrackColor) { + return; + } + _activeTrackColor = value; + notifyListeners(); + } + + Color? get activeTrackOutlineColor => _activeTrackOutlineColor; + Color? _activeTrackOutlineColor; + set activeTrackOutlineColor(Color? value) { + if (value == _activeTrackOutlineColor) { + return; + } + _activeTrackOutlineColor = value; + notifyListeners(); + } + + Color? get inactiveTrackOutlineColor => _inactiveTrackOutlineColor; + Color? _inactiveTrackOutlineColor; + set inactiveTrackOutlineColor(Color? value) { + if (value == _inactiveTrackOutlineColor) { + return; + } + _inactiveTrackOutlineColor = value; + notifyListeners(); + } + + double? get activeTrackOutlineWidth => _activeTrackOutlineWidth; + double? _activeTrackOutlineWidth; + set activeTrackOutlineWidth(double? value) { + if (value == _activeTrackOutlineWidth) { + return; + } + _activeTrackOutlineWidth = value; + notifyListeners(); + } + + double? get inactiveTrackOutlineWidth => _inactiveTrackOutlineWidth; + double? _inactiveTrackOutlineWidth; + set inactiveTrackOutlineWidth(double? value) { + if (value == _inactiveTrackOutlineWidth) { + return; + } + _inactiveTrackOutlineWidth = value; + notifyListeners(); + } + + Color get inactiveTrackColor => _inactiveTrackColor!; + Color? _inactiveTrackColor; + set inactiveTrackColor(Color value) { + if (value == _inactiveTrackColor) { + return; + } + _inactiveTrackColor = value; + notifyListeners(); + } + + ImageConfiguration get configuration => _configuration!; + ImageConfiguration? _configuration; + set configuration(ImageConfiguration value) { + if (value == _configuration) { + return; + } + _configuration = value; + notifyListeners(); + } + + TextDirection get textDirection => _textDirection!; + TextDirection? _textDirection; + set textDirection(TextDirection value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + notifyListeners(); + } + + Color get surfaceColor => _surfaceColor!; + Color? _surfaceColor; + set surfaceColor(Color value) { + if (value == _surfaceColor) { + return; + } + _surfaceColor = value; + notifyListeners(); + } + + bool get isInteractive => _isInteractive!; + bool? _isInteractive; + set isInteractive(bool value) { + if (value == _isInteractive) { + return; + } + _isInteractive = value; + notifyListeners(); + } + + double get trackInnerLength => _trackInnerLength!; + double? _trackInnerLength; + set trackInnerLength(double value) { + if (value == _trackInnerLength) { + return; + } + _trackInnerLength = value; + notifyListeners(); + } + + bool get isCupertino => _isCupertino!; + bool? _isCupertino; + set isCupertino(bool? value) { + assert(value != null); + if (value == _isCupertino) { + return; + } + _isCupertino = value; + notifyListeners(); + } + + List<BoxShadow>? get thumbShadow => _thumbShadow; + List<BoxShadow>? _thumbShadow; + set thumbShadow(List<BoxShadow>? value) { + if (value == _thumbShadow) { + return; + } + _thumbShadow = value; + notifyListeners(); + } + + final TextPainter _textPainter = TextPainter(); + Color? _cachedThumbColor; + ImageProvider? _cachedThumbImage; + ImageErrorListener? _cachedThumbErrorListener; + BoxPainter? _cachedThumbPainter; + + ShapeDecoration _createDefaultThumbDecoration(Color color, ImageProvider? image, ImageErrorListener? errorListener) { + return ShapeDecoration( + color: color, + image: image == null ? null : DecorationImage(image: image, onError: errorListener), + shape: const StadiumBorder(), + shadows: isCupertino ? null : thumbShadow, + ); + } + + bool _isPainting = false; + + void _handleDecorationChanged() { + // If the image decoration is available synchronously, we'll get called here + // during paint. There's no reason to mark ourselves as needing paint if we + // are already in the middle of painting. (In fact, doing so would trigger + // an assert). + if (!_isPainting) { + notifyListeners(); + } + } + + bool _stopPressAnimation = false; + double? _pressedInactiveThumbRadius; + double? _pressedActiveThumbRadius; + late double? _pressedThumbExtension; + + @override + void paint(Canvas canvas, Size size) { + final double currentValue = position.value; + + final double visualPosition; + switch (textDirection) { + case TextDirection.rtl: + visualPosition = 1.0 - currentValue; + case TextDirection.ltr: + visualPosition = currentValue; + } + if (reaction.status == AnimationStatus.reverse && !_stopPressAnimation) { + _stopPressAnimation = true; + } else { + _stopPressAnimation = false; + } + + // To get the thumb radius when the press ends, the value can be any number + // between activeThumbRadius/inactiveThumbRadius and pressedThumbRadius. + if (!_stopPressAnimation) { + _pressedThumbExtension = isCupertino ? reaction.value * 7 : 0; + if (reaction.isCompleted) { + // This happens when the thumb is dragged instead of being tapped. + _pressedInactiveThumbRadius = lerpDouble(inactiveThumbRadius, pressedThumbRadius, reaction.value); + _pressedActiveThumbRadius = lerpDouble(activeThumbRadius, pressedThumbRadius, reaction.value); + } + if (currentValue == 0) { + _pressedInactiveThumbRadius = lerpDouble(inactiveThumbRadius, pressedThumbRadius, reaction.value); + _pressedActiveThumbRadius = activeThumbRadius; + } + if (currentValue == 1) { + _pressedActiveThumbRadius = lerpDouble(activeThumbRadius, pressedThumbRadius, reaction.value); + _pressedInactiveThumbRadius = inactiveThumbRadius; + } + } + final Size inactiveThumbSize = isCupertino ? Size(_pressedInactiveThumbRadius! * 2 + _pressedThumbExtension!, _pressedInactiveThumbRadius! * 2) : Size.fromRadius(_pressedInactiveThumbRadius ?? inactiveThumbRadius); + final Size activeThumbSize = isCupertino ? Size(_pressedActiveThumbRadius! * 2 + _pressedThumbExtension!, _pressedActiveThumbRadius! * 2) : Size.fromRadius(_pressedActiveThumbRadius ?? activeThumbRadius); + Animation<Size> thumbSizeAnimation(bool isForward) { + List<TweenSequenceItem<Size>> thumbSizeSequence; + if (isForward) { + thumbSizeSequence = <TweenSequenceItem<Size>>[ + TweenSequenceItem<Size>( + tween: Tween<Size>(begin: inactiveThumbSize, end: transitionalThumbSize) + .chain(CurveTween(curve: const Cubic(0.31, 0.00, 0.56, 1.00))), + weight: 11, + ), + TweenSequenceItem<Size>( + tween: Tween<Size>(begin: transitionalThumbSize, end: activeThumbSize) + .chain(CurveTween(curve: const Cubic(0.20, 0.00, 0.00, 1.00))), + weight: 72, + ), + TweenSequenceItem<Size>( + tween: ConstantTween<Size>(activeThumbSize), + weight: 17, + ) + ]; + } else { + thumbSizeSequence = <TweenSequenceItem<Size>>[ + TweenSequenceItem<Size>( + tween: ConstantTween<Size>(inactiveThumbSize), + weight: 17, + ), + TweenSequenceItem<Size>( + tween: Tween<Size>(begin: inactiveThumbSize, end: transitionalThumbSize) + .chain(CurveTween(curve: const Cubic(0.20, 0.00, 0.00, 1.00).flipped)), + weight: 72, + ), + TweenSequenceItem<Size>( + tween: Tween<Size>(begin: transitionalThumbSize, end: activeThumbSize) + .chain(CurveTween(curve: const Cubic(0.31, 0.00, 0.56, 1.00).flipped)), + weight: 11, + ), + ]; + } + + return TweenSequence<Size>(thumbSizeSequence).animate(positionController); + } + + Size? thumbSize; + if (isCupertino) { + if (reaction.isCompleted) { + thumbSize = Size(_pressedInactiveThumbRadius! * 2 + _pressedThumbExtension!, _pressedInactiveThumbRadius! * 2); + } else { + if (position.isDismissed || position.status == AnimationStatus.forward) { + thumbSize = Size.lerp(inactiveThumbSize, activeThumbSize, position.value); + } else { + thumbSize = Size.lerp(inactiveThumbSize, activeThumbSize, position.value); + } + } + } else { + if (reaction.isCompleted) { + thumbSize = Size.fromRadius(pressedThumbRadius); + } else { + if (position.isDismissed || position.status == AnimationStatus.forward) { + thumbSize = thumbSizeAnimation(true).value; + } else { + thumbSize = thumbSizeAnimation(false).value; + } + } + } + + // The thumb contracts slightly during the animation in Material 2. + final double inset = thumbOffset == null ? 0 : 1.0 - (currentValue - thumbOffset!).abs() * 2.0; + thumbSize = Size(thumbSize!.width - inset, thumbSize.height - inset); + + final double colorValue = CurvedAnimation(parent: positionController, curve: Curves.easeOut, reverseCurve: Curves.easeIn).value; + final Color trackColor = Color.lerp(inactiveTrackColor, activeTrackColor, colorValue)!; + final Color? trackOutlineColor = inactiveTrackOutlineColor == null || activeTrackOutlineColor == null ? null + : Color.lerp(inactiveTrackOutlineColor, activeTrackOutlineColor, colorValue); + final double? trackOutlineWidth = lerpDouble(inactiveTrackOutlineWidth, activeTrackOutlineWidth, colorValue); + Color lerpedThumbColor; + if (!reaction.isDismissed) { + lerpedThumbColor = Color.lerp(inactivePressedColor, activePressedColor, colorValue)!; + } else if (positionController.status == AnimationStatus.forward) { + lerpedThumbColor = Color.lerp(inactivePressedColor, activeColor, colorValue)!; + } else if (positionController.status == AnimationStatus.reverse) { + lerpedThumbColor = Color.lerp(inactiveColor, activePressedColor, colorValue)!; + } else { + lerpedThumbColor = Color.lerp(inactiveColor, activeColor, colorValue)!; + } + + // Blend the thumb color against a `surfaceColor` background in case the + // thumbColor is not opaque. This way we do not see through the thumb to the + // track underneath. + final Color thumbColor = Color.alphaBlend(lerpedThumbColor, surfaceColor); + + final Icon? thumbIcon = currentValue < 0.5 ? inactiveIcon : activeIcon; + + final ImageProvider? thumbImage = currentValue < 0.5 ? inactiveThumbImage : activeThumbImage; + + final ImageErrorListener? thumbErrorListener = currentValue < 0.5 ? onInactiveThumbImageError : onActiveThumbImageError; + + final Paint paint = Paint() + ..color = trackColor; + + final Offset trackPaintOffset = _computeTrackPaintOffset(size, trackWidth, trackHeight); + final Offset thumbPaintOffset = _computeThumbPaintOffset(trackPaintOffset, thumbSize, visualPosition); + final Offset radialReactionOrigin = Offset(thumbPaintOffset.dx + thumbSize.height / 2, size.height / 2); + + _paintTrackWith(canvas, paint, trackPaintOffset, trackOutlineColor, trackOutlineWidth); + paintRadialReaction(canvas: canvas, origin: radialReactionOrigin); + _paintThumbWith( + thumbPaintOffset, + canvas, + colorValue, + thumbColor, + thumbImage, + thumbErrorListener, + thumbIcon, + thumbSize, + inset, + ); + } + + /// Computes canvas offset for track's upper left corner + Offset _computeTrackPaintOffset(Size canvasSize, double trackWidth, double trackHeight) { + final double horizontalOffset = (canvasSize.width - trackWidth) / 2.0; + final double verticalOffset = (canvasSize.height - trackHeight) / 2.0; + + return Offset(horizontalOffset, verticalOffset); + } + + /// Computes canvas offset for thumb's upper left corner as if it were a + /// square + Offset _computeThumbPaintOffset(Offset trackPaintOffset, Size thumbSize, double visualPosition) { + // How much thumb radius extends beyond the track + final double trackRadius = trackHeight / 2; + final double additionalThumbRadius = thumbSize.height / 2 - trackRadius; + + final double horizontalProgress = visualPosition * (trackInnerLength - _pressedThumbExtension!); + final double thumbHorizontalOffset = trackPaintOffset.dx + trackRadius + (_pressedThumbExtension! / 2) - thumbSize.width / 2 + horizontalProgress; + final double thumbVerticalOffset = trackPaintOffset.dy - additionalThumbRadius; + return Offset(thumbHorizontalOffset, thumbVerticalOffset); + } + + void _paintTrackWith(Canvas canvas, Paint paint, Offset trackPaintOffset, Color? trackOutlineColor, double? trackOutlineWidth) { + final Rect trackRect = Rect.fromLTWH( + trackPaintOffset.dx, + trackPaintOffset.dy, + trackWidth, + trackHeight, + ); + final double trackRadius = trackHeight / 2; + final RRect trackRRect = RRect.fromRectAndRadius( + trackRect, + Radius.circular(trackRadius), + ); + + canvas.drawRRect(trackRRect, paint); + + // paint track outline + if (trackOutlineColor != null) { + final Rect outlineTrackRect = Rect.fromLTWH( + trackPaintOffset.dx + 1, + trackPaintOffset.dy + 1, + trackWidth - 2, + trackHeight - 2, + ); + final RRect outlineTrackRRect = RRect.fromRectAndRadius( + outlineTrackRect, + Radius.circular(trackRadius), + ); + + final Paint outlinePaint = Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = trackOutlineWidth ?? 2.0 + ..color = trackOutlineColor; + + canvas.drawRRect(outlineTrackRRect, outlinePaint); + } + + if (isCupertino) { + if (isFocused) { + final RRect focusedOutline = trackRRect.inflate(1.75); + final Paint focusedPaint = Paint() + ..style = PaintingStyle.stroke + ..color = focusColor + ..strokeWidth = _kCupertinoFocusTrackOutline; + canvas.drawRRect(focusedOutline, focusedPaint); + } + canvas.clipRRect(trackRRect); + } + } + + void _paintThumbWith( + Offset thumbPaintOffset, + Canvas canvas, + double currentValue, + Color thumbColor, + ImageProvider? thumbImage, + ImageErrorListener? thumbErrorListener, + Icon? thumbIcon, + Size thumbSize, + double inset, + ) { + try { + _isPainting = true; + if (_cachedThumbPainter == null || thumbColor != _cachedThumbColor || thumbImage != _cachedThumbImage || thumbErrorListener != _cachedThumbErrorListener) { + _cachedThumbColor = thumbColor; + _cachedThumbImage = thumbImage; + _cachedThumbErrorListener = thumbErrorListener; + _cachedThumbPainter?.dispose(); + _cachedThumbPainter = _createDefaultThumbDecoration(thumbColor, thumbImage, thumbErrorListener).createBoxPainter(_handleDecorationChanged); + } + final BoxPainter thumbPainter = _cachedThumbPainter!; + + if (isCupertino) { + _paintCupertinoThumbShadowAndBorder(canvas, thumbPaintOffset, thumbSize); + } + + thumbPainter.paint( + canvas, + thumbPaintOffset, + configuration.copyWith(size: thumbSize), + ); + + if (thumbIcon != null && thumbIcon.icon != null) { + final Color iconColor = Color.lerp(inactiveIconColor, activeIconColor, currentValue)!; + final double iconSize = thumbIcon.size ?? _SwitchConfigM3.iconSize; + final IconData iconData = thumbIcon.icon!; + final double? iconWeight = thumbIcon.weight ?? iconTheme?.weight; + final double? iconFill = thumbIcon.fill ?? iconTheme?.fill; + final double? iconGrade = thumbIcon.grade ?? iconTheme?.grade; + final double? iconOpticalSize = thumbIcon.opticalSize ?? iconTheme?.opticalSize; + final List<Shadow>? iconShadows = thumbIcon.shadows ?? iconTheme?.shadows; + + final TextSpan textSpan = TextSpan( + text: String.fromCharCode(iconData.codePoint), + style: TextStyle( + fontVariations: <FontVariation>[ + if (iconFill != null) FontVariation('FILL', iconFill), + if (iconWeight != null) FontVariation('wght', iconWeight), + if (iconGrade != null) FontVariation('GRAD', iconGrade), + if (iconOpticalSize != null) FontVariation('opsz', iconOpticalSize), + ], + color: iconColor, + fontSize: iconSize, + inherit: false, + fontFamily: iconData.fontFamily, + package: iconData.fontPackage, + shadows: iconShadows, + ), + ); + _textPainter + ..textDirection = textDirection + ..text = textSpan; + _textPainter.layout(); + final double additionalHorizontalOffset = (thumbSize.width - iconSize) / 2; + final double additionalVerticalOffset = (thumbSize.height - iconSize) / 2; + final Offset offset = thumbPaintOffset + Offset(additionalHorizontalOffset, additionalVerticalOffset); + + _textPainter.paint(canvas, offset); + } + } finally { + _isPainting = false; + } + } + + void _paintCupertinoThumbShadowAndBorder(Canvas canvas, Offset thumbPaintOffset, Size thumbSize,) { + final RRect thumbBounds = RRect.fromLTRBR( + thumbPaintOffset.dx, + thumbPaintOffset.dy, + thumbPaintOffset.dx + thumbSize.width, + thumbPaintOffset.dy + thumbSize.height, + Radius.circular(thumbSize.height / 2.0), + ); + if (thumbShadow != null) { + for (final BoxShadow shadow in thumbShadow!) { + canvas.drawRRect(thumbBounds.shift(shadow.offset), shadow.toPaint()); + } + } + + canvas.drawRRect( + thumbBounds.inflate(0.5), + Paint()..color = const Color(0x0A000000), + ); + } + + @override + void dispose() { + _textPainter.dispose(); + _cachedThumbPainter?.dispose(); + _cachedThumbPainter = null; + _cachedThumbColor = null; + _cachedThumbImage = null; + _cachedThumbErrorListener = null; + super.dispose(); + } +} + +class _SwitchThemeAdaptation extends Adaptation<SwitchThemeData> { + const _SwitchThemeAdaptation(); + + @override + SwitchThemeData adapt(ThemeData theme, SwitchThemeData defaultValue) { + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return defaultValue; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return const SwitchThemeData(); + } + } +} + +mixin _SwitchConfig { + double get trackHeight; + double get trackWidth; + double get switchWidth; + double get switchHeight; + double get switchHeightCollapsed; + double get activeThumbRadius; + double get inactiveThumbRadius; + double get pressedThumbRadius; + double get thumbRadiusWithIcon; + List<BoxShadow>? get thumbShadow; + MaterialStateProperty<Color> get iconColor; + double? get thumbOffset; + Size get transitionalThumbSize; + int get toggleDuration; +} + +// Hand coded defaults for iOS/macOS Switch +class _SwitchDefaultsCupertino extends SwitchThemeData { + const _SwitchDefaultsCupertino(this.context); + + final BuildContext context; + + @override + MaterialStateProperty<MouseCursor?> get mouseCursor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return kIsWeb ? SystemMouseCursors.click : SystemMouseCursors.basic; + }); + } + + @override + MaterialStateProperty<Color> get thumbColor => const MaterialStatePropertyAll<Color>(Colors.white); + + @override + MaterialStateProperty<Color> get trackColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return CupertinoDynamicColor.resolve(CupertinoColors.systemGreen, context); + } + return CupertinoDynamicColor.resolve(CupertinoColors.secondarySystemFill, context); + }); + } + + @override + MaterialStateProperty<Color?> get trackOutlineColor => const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<Color?> get overlayColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.focused)) { + return HSLColor + .fromColor(CupertinoDynamicColor.resolve(CupertinoColors.systemGreen, context).withOpacity(0.80)) + .withLightness(0.69).withSaturation(0.835) + .toColor(); + } + return Colors.transparent; + }); + } + + @override + double get splashRadius => 0.0; +} + +const double _kCupertinoFocusTrackOutline = 3.5; + +class _SwitchConfigCupertino with _SwitchConfig { + _SwitchConfigCupertino(this.context) + : _colors = Theme.of(context).colorScheme; + + BuildContext context; + final ColorScheme _colors; + + @override + MaterialStateProperty<Color> get iconColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + return _colors.onPrimaryContainer; + }); + } + + @override + double get activeThumbRadius => 14.0; + + @override + double get inactiveThumbRadius => 14.0; + + @override + double get pressedThumbRadius => 14.0; + + @override + double get switchHeight => _kSwitchMinSize + 8.0; + + @override + double get switchHeightCollapsed => _kSwitchMinSize; + + @override + double get switchWidth => 60.0; + + @override + double get thumbRadiusWithIcon => 14.0; + + @override + List<BoxShadow>? get thumbShadow => const <BoxShadow> [ + BoxShadow( + color: Color(0x26000000), + offset: Offset(0, 3), + blurRadius: 8.0, + ), + BoxShadow( + color: Color(0x0F000000), + offset: Offset(0, 3), + blurRadius: 1.0, + ), + ]; + + @override + double get trackHeight => 31.0; + + @override + double get trackWidth => 51.0; + + // The thumb size at the middle of the track. Hand coded default based on the animation specs. + @override + Size get transitionalThumbSize => const Size(28.0, 28.0); + + // Hand coded default by comparing with [CupertinoSwitch]. + @override + int get toggleDuration => 140; + + // Hand coded default based on the animation specs. + @override + double? get thumbOffset => null; +} + +// Hand coded defaults based on Material Design 2. +class _SwitchConfigM2 with _SwitchConfig { + _SwitchConfigM2(); + + @override + double get activeThumbRadius => 10.0; + + @override + MaterialStateProperty<Color> get iconColor => MaterialStateProperty.all<Color>(Colors.transparent); + + @override + double get inactiveThumbRadius => 10.0; + + @override + double get pressedThumbRadius => 10.0; + + @override + double get switchHeight => _kSwitchMinSize + 8.0; + + @override + double get switchHeightCollapsed => _kSwitchMinSize; + + @override + double get switchWidth => trackWidth - 2 * (trackHeight / 2.0) + _kSwitchMinSize; + + @override + double get thumbRadiusWithIcon => 10.0; + + @override + List<BoxShadow>? get thumbShadow => kElevationToShadow[1]; + + @override + double get trackHeight => 14.0; + + @override + double get trackWidth => 33.0; + + @override + double get thumbOffset => 0.5; + + @override + Size get transitionalThumbSize => const Size(20, 20); + + @override + int get toggleDuration => 200; +} + +class _SwitchDefaultsM2 extends SwitchThemeData { + _SwitchDefaultsM2(BuildContext context) + : _theme = Theme.of(context), + _colors = Theme.of(context).colorScheme; + + final ThemeData _theme; + final ColorScheme _colors; + + @override + MaterialStateProperty<Color> get thumbColor { + final bool isDark = _theme.brightness == Brightness.dark; + + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return isDark ? Colors.grey.shade800 : Colors.grey.shade400; + } + if (states.contains(MaterialState.selected)) { + return _colors.secondary; + } + return isDark ? Colors.grey.shade400 : Colors.grey.shade50; + }); + } + + @override + MaterialStateProperty<Color> get trackColor { + final bool isDark = _theme.brightness == Brightness.dark; + const Color black32 = Color(0x52000000); // Black with 32% opacity + + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return isDark ? Colors.white10 : Colors.black12; + } + if (states.contains(MaterialState.selected)) { + final Color activeColor = _colors.secondary; + return activeColor.withAlpha(0x80); + } + return isDark ? Colors.white30 : black32; + }); + } + + @override + MaterialStateProperty<Color?>? get trackOutlineColor => const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialTapTargetSize get materialTapTargetSize => _theme.materialTapTargetSize; + + @override + MaterialStateProperty<MouseCursor> get mouseCursor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) => MaterialStateMouseCursor.clickable.resolve(states)); + + @override + MaterialStateProperty<Color?> get overlayColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return thumbColor.resolve(states).withAlpha(kRadialReactionAlpha); + } + if (states.contains(MaterialState.hovered)) { + return _theme.hoverColor; + } + if (states.contains(MaterialState.focused)) { + return _theme.focusColor; + } + return null; + }); + } + + @override + double get splashRadius => kRadialReactionRadius; +} + +// BEGIN GENERATED TOKEN PROPERTIES - Switch + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _SwitchDefaultsM3 extends SwitchThemeData { + _SwitchDefaultsM3(this.context); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + MaterialStateProperty<Color> get thumbColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + if (states.contains(MaterialState.selected)) { + return _colors.surface.withOpacity(1.0); + } + return _colors.onSurface.withOpacity(0.38); + } + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.primaryContainer; + } + if (states.contains(MaterialState.hovered)) { + return _colors.primaryContainer; + } + if (states.contains(MaterialState.focused)) { + return _colors.primaryContainer; + } + return _colors.onPrimary; + } + if (states.contains(MaterialState.pressed)) { + return _colors.onSurfaceVariant; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurfaceVariant; + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurfaceVariant; + } + return _colors.outline; + }); + } + + @override + MaterialStateProperty<Color> get trackColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + if (states.contains(MaterialState.selected)) { + return _colors.onSurface.withOpacity(0.12); + } + return _colors.surfaceVariant.withOpacity(0.12); + } + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.primary; + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary; + } + if (states.contains(MaterialState.focused)) { + return _colors.primary; + } + return _colors.primary; + } + if (states.contains(MaterialState.pressed)) { + return _colors.surfaceVariant; + } + if (states.contains(MaterialState.hovered)) { + return _colors.surfaceVariant; + } + if (states.contains(MaterialState.focused)) { + return _colors.surfaceVariant; + } + return _colors.surfaceVariant; + }); + } + + @override + MaterialStateProperty<Color?> get trackOutlineColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return Colors.transparent; + } + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.12); + } + return _colors.outline; + }); + } + + @override + MaterialStateProperty<Color?> get overlayColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.primary.withOpacity(0.12); + } + return null; + } + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface.withOpacity(0.12); + } + return null; + }); + } + + @override + MaterialStateProperty<MouseCursor> get mouseCursor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) + => MaterialStateMouseCursor.clickable.resolve(states)); + } + + @override + MaterialStatePropertyAll<double> get trackOutlineWidth => const MaterialStatePropertyAll<double>(2.0); + + @override + double get splashRadius => 40.0 / 2; +} + +class _SwitchConfigM3 with _SwitchConfig { + _SwitchConfigM3(this.context) + : _colors = Theme.of(context).colorScheme; + + BuildContext context; + final ColorScheme _colors; + + static const double iconSize = 16.0; + + @override + double get activeThumbRadius => 24.0 / 2; + + @override + MaterialStateProperty<Color> get iconColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + if (states.contains(MaterialState.selected)) { + return _colors.onSurface.withOpacity(0.38); + } + return _colors.surfaceVariant.withOpacity(0.38); + } + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onPrimaryContainer; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onPrimaryContainer; + } + if (states.contains(MaterialState.focused)) { + return _colors.onPrimaryContainer; + } + return _colors.onPrimaryContainer; + } + if (states.contains(MaterialState.pressed)) { + return _colors.surfaceVariant; + } + if (states.contains(MaterialState.hovered)) { + return _colors.surfaceVariant; + } + if (states.contains(MaterialState.focused)) { + return _colors.surfaceVariant; + } + return _colors.surfaceVariant; + }); + } + + @override + double get inactiveThumbRadius => 16.0 / 2; + + @override + double get pressedThumbRadius => 28.0 / 2; + + @override + double get switchHeight => _kSwitchMinSize + 8.0; + + @override + double get switchHeightCollapsed => _kSwitchMinSize; + + @override + double get switchWidth => trackWidth - 2 * (trackHeight / 2.0) + _kSwitchMinSize; + + @override + double get thumbRadiusWithIcon => 24.0 / 2; + + @override + List<BoxShadow>? get thumbShadow => kElevationToShadow[0]; + + @override + double get trackHeight => 32.0; + + @override + double get trackWidth => 52.0; + + // The thumb size at the middle of the track. Hand coded default based on the animation specs. + @override + Size get transitionalThumbSize => const Size(34, 22); + + // Hand coded default based on the animation specs. + @override + int get toggleDuration => 300; + + // Hand coded default based on the animation specs. + @override + double? get thumbOffset => null; +} + +// END GENERATED TOKEN PROPERTIES - Switch diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/switch_list_tile.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/switch_list_tile.dart new file mode 100644 index 0000000000000000000000000000000000000000..3ee9a39071c1d5bbd1797f9bd08fc174608d9aa0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/switch_list_tile.dart @@ -0,0 +1,609 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/gestures.dart'; +import 'package:flutter/widgets.dart'; + +import 'list_tile.dart'; +import 'list_tile_theme.dart'; +import 'material_state.dart'; +import 'switch.dart'; +import 'switch_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// void setState(VoidCallback fn) { } +// bool _isSelected = true; + +enum _SwitchListTileType { material, adaptive } + +/// A [ListTile] with a [Switch]. In other words, a switch with a label. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=0igIjvtEWNU} +/// +/// The entire list tile is interactive: tapping anywhere in the tile toggles +/// the switch. Tapping and dragging the [Switch] also triggers the [onChanged] +/// callback. +/// +/// To ensure that [onChanged] correctly triggers, the state passed +/// into [value] must be properly managed. This is typically done by invoking +/// [State.setState] in [onChanged] to toggle the state value. +/// +/// The [value], [onChanged], [activeColor], [activeThumbImage], and +/// [inactiveThumbImage] properties of this widget are identical to the +/// similarly-named properties on the [Switch] widget. +/// +/// The [title], [subtitle], [isThreeLine], and [dense] properties are like +/// those of the same name on [ListTile]. +/// +/// The [selected] property on this widget is similar to the [ListTile.selected] +/// property. This tile's [activeColor] is used for the selected item's text color, or +/// the theme's [SwitchThemeData.overlayColor] if [activeColor] is null. +/// +/// This widget does not coordinate the [selected] state and the +/// [value]; to have the list tile appear selected when the +/// switch button is on, use the same value for both. +/// +/// The switch is shown on the right by default in left-to-right languages (i.e. +/// in the [ListTile.trailing] slot) which can be changed using [controlAffinity]. +/// The [secondary] widget is placed in the [ListTile.leading] slot. +/// +/// This widget requires a [Material] widget ancestor in the tree to paint +/// itself on, which is typically provided by the app's [Scaffold]. +/// The [tileColor], and [selectedTileColor] are not painted by the +/// [SwitchListTile] itself but by the [Material] widget ancestor. In this +/// case, one can wrap a [Material] widget around the [SwitchListTile], e.g.: +/// +/// {@tool snippet} +/// ```dart +/// ColoredBox( +/// color: Colors.green, +/// child: Material( +/// child: SwitchListTile( +/// tileColor: Colors.red, +/// title: const Text('SwitchListTile with red background'), +/// value: true, +/// onChanged:(bool? value) { }, +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Performance considerations when wrapping [SwitchListTile] with [Material] +/// +/// Wrapping a large number of [SwitchListTile]s individually with [Material]s +/// is expensive. Consider only wrapping the [SwitchListTile]s that require it +/// or include a common [Material] ancestor where possible. +/// +/// To show the [SwitchListTile] as disabled, pass null as the [onChanged] +/// callback. +/// +/// {@tool dartpad} +/// ![SwitchListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile.png) +/// +/// This widget shows a switch that, when toggled, changes the state of a [bool] +/// member field called `_lights`. +/// +/// ** See code in examples/api/lib/material/switch_list_tile/switch_list_tile.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample demonstrates how [SwitchListTile] positions the switch widget +/// relative to the text in different configurations. +/// +/// ** See code in examples/api/lib/material/switch_list_tile/switch_list_tile.1.dart ** +/// {@end-tool} +/// +/// ## Semantics in SwitchListTile +/// +/// Since the entirety of the SwitchListTile is interactive, it should represent +/// itself as a single interactive entity. +/// +/// To do so, a SwitchListTile widget wraps its children with a [MergeSemantics] +/// widget. [MergeSemantics] will attempt to merge its descendant [Semantics] +/// nodes into one node in the semantics tree. Therefore, SwitchListTile will +/// throw an error if any of its children requires its own [Semantics] node. +/// +/// For example, you cannot nest a [RichText] widget as a descendant of +/// SwitchListTile. [RichText] has an embedded gesture recognizer that +/// requires its own [Semantics] node, which directly conflicts with +/// SwitchListTile's desire to merge all its descendants' semantic nodes +/// into one. Therefore, it may be necessary to create a custom radio tile +/// widget to accommodate similar use cases. +/// +/// {@tool dartpad} +/// ![Switch list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile_semantics.png) +/// +/// Here is an example of a custom labeled radio widget, called +/// LinkedLabelRadio, that includes an interactive [RichText] widget that +/// handles tap gestures. +/// +/// ** See code in examples/api/lib/material/switch_list_tile/custom_labeled_switch.0.dart ** +/// {@end-tool} +/// +/// ## SwitchListTile isn't exactly what I want +/// +/// If the way SwitchListTile pads and positions its elements isn't quite what +/// you're looking for, you can create custom labeled switch widgets by +/// combining [Switch] with other widgets, such as [Text], [Padding] and +/// [InkWell]. +/// +/// {@tool dartpad} +/// ![Custom switch list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile_custom.png) +/// +/// Here is an example of a custom LabeledSwitch widget, but you can easily +/// make your own configurable widget. +/// +/// ** See code in examples/api/lib/material/switch_list_tile/custom_labeled_switch.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListTileTheme], which can be used to affect the style of list tiles, +/// including switch list tiles. +/// * [CheckboxListTile], a similar widget for checkboxes. +/// * [RadioListTile], a similar widget for radio buttons. +/// * [ListTile] and [Switch], the widgets from which this widget is made. +class SwitchListTile extends StatelessWidget { + /// Creates a combination of a list tile and a switch. + /// + /// The switch tile itself does not maintain any state. Instead, when the + /// state of the switch changes, the widget calls the [onChanged] callback. + /// Most widgets that use a switch will listen for the [onChanged] callback + /// and rebuild the switch tile with a new [value] to update the visual + /// appearance of the switch. + /// + /// The following arguments are required: + /// + /// * [value] determines whether this switch is on or off. + /// * [onChanged] is called when the user toggles the switch on or off. + const SwitchListTile({ + super.key, + required this.value, + required this.onChanged, + this.activeColor, + this.activeTrackColor, + this.inactiveThumbColor, + this.inactiveTrackColor, + this.activeThumbImage, + this.onActiveThumbImageError, + this.inactiveThumbImage, + this.onInactiveThumbImageError, + this.thumbColor, + this.trackColor, + this.trackOutlineColor, + this.thumbIcon, + this.materialTapTargetSize, + this.dragStartBehavior = DragStartBehavior.start, + this.mouseCursor, + this.overlayColor, + this.splashRadius, + this.focusNode, + this.onFocusChange, + this.autofocus = false, + this.tileColor, + this.title, + this.subtitle, + this.isThreeLine = false, + this.dense, + this.contentPadding, + this.secondary, + this.selected = false, + this.controlAffinity = ListTileControlAffinity.platform, + this.shape, + this.selectedTileColor, + this.visualDensity, + this.enableFeedback, + this.hoverColor, + }) : _switchListTileType = _SwitchListTileType.material, + applyCupertinoTheme = false, + assert(activeThumbImage != null || onActiveThumbImageError == null), + assert(inactiveThumbImage != null || onInactiveThumbImageError == null), + assert(!isThreeLine || subtitle != null); + + /// Creates a Material [ListTile] with an adaptive [Switch], following + /// Material design's + /// [Cross-platform guidelines](https://material.io/design/platform-guidance/cross-platform-adaptation.html). + /// + /// This widget uses [Switch.adaptive] to change the graphics of the switch + /// component based on the ambient [ThemeData.platform]. On iOS and macOS, a + /// [CupertinoSwitch] will be used. On other platforms a Material design + /// [Switch] will be used. + /// + /// If a [CupertinoSwitch] is created, the following parameters are + /// ignored: [activeTrackColor], [inactiveThumbColor], [inactiveTrackColor], + /// [activeThumbImage], [inactiveThumbImage]. + const SwitchListTile.adaptive({ + super.key, + required this.value, + required this.onChanged, + this.activeColor, + this.activeTrackColor, + this.inactiveThumbColor, + this.inactiveTrackColor, + this.activeThumbImage, + this.onActiveThumbImageError, + this.inactiveThumbImage, + this.onInactiveThumbImageError, + this.thumbColor, + this.trackColor, + this.trackOutlineColor, + this.thumbIcon, + this.materialTapTargetSize, + this.dragStartBehavior = DragStartBehavior.start, + this.mouseCursor, + this.overlayColor, + this.splashRadius, + this.focusNode, + this.onFocusChange, + this.autofocus = false, + this.applyCupertinoTheme, + this.tileColor, + this.title, + this.subtitle, + this.isThreeLine = false, + this.dense, + this.contentPadding, + this.secondary, + this.selected = false, + this.controlAffinity = ListTileControlAffinity.platform, + this.shape, + this.selectedTileColor, + this.visualDensity, + this.enableFeedback, + this.hoverColor, + }) : _switchListTileType = _SwitchListTileType.adaptive, + assert(!isThreeLine || subtitle != null), + assert(activeThumbImage != null || onActiveThumbImageError == null), + assert(inactiveThumbImage != null || onInactiveThumbImageError == null); + + /// Whether this switch is checked. + final bool value; + + /// Called when the user toggles the switch on or off. + /// + /// The switch passes the new value to the callback but does not actually + /// change state until the parent widget rebuilds the switch tile with the + /// new value. + /// + /// If null, the switch will be displayed as disabled. + /// + /// The callback provided to [onChanged] should update the state of the parent + /// [StatefulWidget] using the [State.setState] method, so that the parent + /// gets rebuilt; for example: + /// + /// {@tool snippet} + /// ```dart + /// SwitchListTile( + /// value: _isSelected, + /// onChanged: (bool newValue) { + /// setState(() { + /// _isSelected = newValue; + /// }); + /// }, + /// title: const Text('Selection'), + /// ) + /// ``` + /// {@end-tool} + final ValueChanged<bool>? onChanged; + + /// {@macro flutter.material.switch.activeColor} + /// + /// Defaults to [ColorScheme.secondary] of the current [Theme]. + final Color? activeColor; + + /// {@macro flutter.material.switch.activeTrackColor} + /// + /// Defaults to [ThemeData.toggleableActiveColor] with the opacity set at 50%. + /// + /// Ignored if created with [SwitchListTile.adaptive]. + final Color? activeTrackColor; + + /// {@macro flutter.material.switch.inactiveThumbColor} + /// + /// Defaults to the colors described in the Material design specification. + /// + /// Ignored if created with [SwitchListTile.adaptive]. + final Color? inactiveThumbColor; + + /// {@macro flutter.material.switch.inactiveTrackColor} + /// + /// Defaults to the colors described in the Material design specification. + /// + /// Ignored if created with [SwitchListTile.adaptive]. + final Color? inactiveTrackColor; + + /// {@macro flutter.material.switch.activeThumbImage} + final ImageProvider? activeThumbImage; + + /// {@macro flutter.material.switch.onActiveThumbImageError} + final ImageErrorListener? onActiveThumbImageError; + + /// {@macro flutter.material.switch.inactiveThumbImage} + /// + /// Ignored if created with [SwitchListTile.adaptive]. + final ImageProvider? inactiveThumbImage; + + /// {@macro flutter.material.switch.onInactiveThumbImageError} + final ImageErrorListener? onInactiveThumbImageError; + + /// The color of this switch's thumb. + /// + /// Resolved in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.disabled]. + /// + /// If null, then the value of [activeColor] is used in the selected state + /// and [inactiveThumbColor] in the default state. If that is also null, then + /// the value of [SwitchThemeData.thumbColor] is used. If that is also null, + /// The default value is used. + final MaterialStateProperty<Color?>? thumbColor; + + /// The color of this switch's track. + /// + /// Resolved in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.disabled]. + /// + /// If null, then the value of [activeTrackColor] is used in the selected + /// state and [inactiveTrackColor] in the default state. If that is also null, + /// then the value of [SwitchThemeData.trackColor] is used. If that is also + /// null, then the default value is used. + final MaterialStateProperty<Color?>? trackColor; + + /// {@macro flutter.material.switch.trackOutlineColor} + /// + /// The [ListTile] will be focused when this [SwitchListTile] requests focus, + /// so the focused outline color of the switch will be ignored. + /// + /// In Material 3, the outline color defaults to transparent in the selected + /// state and [ColorScheme.outline] in the unselected state. In Material 2, + /// the [Switch] track has no outline. + final MaterialStateProperty<Color?>? trackOutlineColor; + + /// The icon to use on the thumb of this switch + /// + /// Resolved in the following states: + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.disabled]. + /// + /// If null, then the value of [SwitchThemeData.thumbIcon] is used. If this is + /// also null, then the [Switch] does not have any icons on the thumb. + final MaterialStateProperty<Icon?>? thumbIcon; + + /// {@macro flutter.material.switch.materialTapTargetSize} + /// + /// defaults to [MaterialTapTargetSize.shrinkWrap]. + final MaterialTapTargetSize? materialTapTargetSize; + + /// {@macro flutter.cupertino.CupertinoSwitch.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// * [MaterialState.disabled]. + /// + /// If null, then the value of [SwitchThemeData.mouseCursor] is used. If that + /// is also null, then [MaterialStateMouseCursor.clickable] is used. + final MouseCursor? mouseCursor; + + /// The color for the switch's [Material]. + /// + /// Resolves in the following states: + /// * [MaterialState.pressed]. + /// * [MaterialState.selected]. + /// * [MaterialState.hovered]. + /// + /// If null, then the value of [activeColor] with alpha [kRadialReactionAlpha] + /// and [hoverColor] is used in the pressed and hovered state. If that is also + /// null, the value of [SwitchThemeData.overlayColor] is used. If that is + /// also null, then the default value is used in the pressed and hovered state. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@macro flutter.material.switch.splashRadius} + /// + /// If null, then the value of [SwitchThemeData.splashRadius] is used. If that + /// is also null, then [kRadialReactionRadius] is used. + final double? splashRadius; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.material.inkwell.onFocusChange} + final ValueChanged<bool>? onFocusChange; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@macro flutter.material.ListTile.tileColor} + final Color? tileColor; + + /// The primary content of the list tile. + /// + /// Typically a [Text] widget. + final Widget? title; + + /// Additional content displayed below the title. + /// + /// Typically a [Text] widget. + final Widget? subtitle; + + /// A widget to display on the opposite side of the tile from the switch. + /// + /// Typically an [Icon] widget. + final Widget? secondary; + + /// Whether this list tile is intended to display three lines of text. + /// + /// If false, the list tile is treated as having one line if the subtitle is + /// null and treated as having two lines if the subtitle is non-null. + final bool isThreeLine; + + /// Whether this list tile is part of a vertically dense list. + /// + /// If this property is null then its value is based on [ListTileThemeData.dense]. + final bool? dense; + + /// The tile's internal padding. + /// + /// Insets a [SwitchListTile]'s contents: its [title], [subtitle], + /// [secondary], and [Switch] widgets. + /// + /// If null, [ListTile]'s default of `EdgeInsets.symmetric(horizontal: 16.0)` + /// is used. + final EdgeInsetsGeometry? contentPadding; + + /// Whether to render icons and text in the [activeColor]. + /// + /// No effort is made to automatically coordinate the [selected] state and the + /// [value] state. To have the list tile appear selected when the switch is + /// on, pass the same value to both. + /// + /// Normally, this property is left to its default value, false. + final bool selected; + + /// If adaptive, creates the switch with [Switch.adaptive]. + final _SwitchListTileType _switchListTileType; + + /// Defines the position of control and [secondary], relative to text. + /// + /// By default, the value of [controlAffinity] is [ListTileControlAffinity.platform]. + final ListTileControlAffinity controlAffinity; + + /// {@macro flutter.material.ListTile.shape} + final ShapeBorder? shape; + + /// If non-null, defines the background color when [SwitchListTile.selected] is true. + final Color? selectedTileColor; + + /// Defines how compact the list tile's layout will be. + /// + /// {@macro flutter.material.themedata.visualDensity} + final VisualDensity? visualDensity; + + /// {@macro flutter.material.ListTile.enableFeedback} + /// + /// See also: + /// + /// * [Feedback] for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + /// The color for the tile's [Material] when a pointer is hovering over it. + final Color? hoverColor; + + /// {@macro flutter.cupertino.CupertinoSwitch.applyTheme} + final bool? applyCupertinoTheme; + + @override + Widget build(BuildContext context) { + final Widget control; + switch (_switchListTileType) { + case _SwitchListTileType.adaptive: + control = Switch.adaptive( + value: value, + onChanged: onChanged, + activeColor: activeColor, + activeThumbImage: activeThumbImage, + inactiveThumbImage: inactiveThumbImage, + materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap, + activeTrackColor: activeTrackColor, + inactiveTrackColor: inactiveTrackColor, + inactiveThumbColor: inactiveThumbColor, + autofocus: autofocus, + onFocusChange: onFocusChange, + onActiveThumbImageError: onActiveThumbImageError, + onInactiveThumbImageError: onInactiveThumbImageError, + thumbColor: thumbColor, + trackColor: trackColor, + trackOutlineColor: trackOutlineColor, + thumbIcon: thumbIcon, + applyCupertinoTheme: applyCupertinoTheme, + dragStartBehavior: dragStartBehavior, + mouseCursor: mouseCursor, + splashRadius: splashRadius, + overlayColor: overlayColor, + ); + + case _SwitchListTileType.material: + control = Switch( + value: value, + onChanged: onChanged, + activeColor: activeColor, + activeThumbImage: activeThumbImage, + inactiveThumbImage: inactiveThumbImage, + materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap, + activeTrackColor: activeTrackColor, + inactiveTrackColor: inactiveTrackColor, + inactiveThumbColor: inactiveThumbColor, + autofocus: autofocus, + onFocusChange: onFocusChange, + onActiveThumbImageError: onActiveThumbImageError, + onInactiveThumbImageError: onInactiveThumbImageError, + thumbColor: thumbColor, + trackColor: trackColor, + trackOutlineColor: trackOutlineColor, + thumbIcon: thumbIcon, + dragStartBehavior: dragStartBehavior, + mouseCursor: mouseCursor, + splashRadius: splashRadius, + overlayColor: overlayColor, + ); + } + + Widget? leading, trailing; + switch (controlAffinity) { + case ListTileControlAffinity.leading: + leading = control; + trailing = secondary; + case ListTileControlAffinity.trailing: + case ListTileControlAffinity.platform: + leading = secondary; + trailing = control; + } + + final ThemeData theme = Theme.of(context); + final SwitchThemeData switchTheme = SwitchTheme.of(context); + final Set<MaterialState> states = <MaterialState>{ + if (selected) MaterialState.selected, + }; + final Color effectiveActiveColor = activeColor + ?? switchTheme.thumbColor?.resolve(states) + ?? theme.colorScheme.secondary; + return MergeSemantics( + child: ListTile( + selectedColor: effectiveActiveColor, + leading: leading, + title: title, + subtitle: subtitle, + trailing: trailing, + isThreeLine: isThreeLine, + dense: dense, + contentPadding: contentPadding, + enabled: onChanged != null, + onTap: onChanged != null ? () { onChanged!(!value); } : null, + selected: selected, + selectedTileColor: selectedTileColor, + autofocus: autofocus, + shape: shape, + tileColor: tileColor, + visualDensity: visualDensity, + focusNode: focusNode, + onFocusChange: onFocusChange, + enableFeedback: enableFeedback, + hoverColor: hoverColor, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/switch_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/switch_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..e0753cf8842d85b2ba9c4b5901f7f6c96aa0b939 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/switch_theme.dart @@ -0,0 +1,230 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'material_state.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines default property values for descendant [Switch] widgets. +/// +/// Descendant widgets obtain the current [SwitchThemeData] object using +/// `SwitchTheme.of(context)`. Instances of [SwitchThemeData] can be customized +/// with [SwitchThemeData.copyWith]. +/// +/// Typically a [SwitchThemeData] is specified as part of the overall [Theme] +/// with [ThemeData.switchTheme]. +/// +/// All [SwitchThemeData] properties are `null` by default. When null, the +/// [Switch] will use the values from [ThemeData] if they exist, otherwise it +/// will provide its own defaults based on the overall [Theme]'s colorScheme. +/// See the individual [Switch] properties for details. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class SwitchThemeData with Diagnosticable { + /// Creates a theme that can be used for [ThemeData.switchTheme]. + const SwitchThemeData({ + this.thumbColor, + this.trackColor, + this.trackOutlineColor, + this.trackOutlineWidth, + this.materialTapTargetSize, + this.mouseCursor, + this.overlayColor, + this.splashRadius, + this.thumbIcon, + }); + + /// {@macro flutter.material.switch.thumbColor} + /// + /// If specified, overrides the default value of [Switch.thumbColor]. + final MaterialStateProperty<Color?>? thumbColor; + + /// {@macro flutter.material.switch.trackColor} + /// + /// If specified, overrides the default value of [Switch.trackColor]. + final MaterialStateProperty<Color?>? trackColor; + + /// {@macro flutter.material.switch.trackOutlineColor} + /// + /// If specified, overrides the default value of [Switch.trackOutlineColor]. + final MaterialStateProperty<Color?>? trackOutlineColor; + + /// {@macro flutter.material.switch.trackOutlineWidth} + /// + /// If specified, overrides the default value of [Switch.trackOutlineWidth]. + final MaterialStateProperty<double?>? trackOutlineWidth; + + /// {@macro flutter.material.switch.materialTapTargetSize} + /// + /// If specified, overrides the default value of + /// [Switch.materialTapTargetSize]. + final MaterialTapTargetSize? materialTapTargetSize; + + /// {@macro flutter.material.switch.mouseCursor} + /// + /// If specified, overrides the default value of [Switch.mouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// {@macro flutter.material.switch.overlayColor} + /// + /// If specified, overrides the default value of [Switch.overlayColor]. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@macro flutter.material.switch.splashRadius} + /// + /// If specified, overrides the default value of [Switch.splashRadius]. + final double? splashRadius; + + /// {@macro flutter.material.switch.thumbIcon} + /// + /// It is overridden by [Switch.thumbIcon]. + final MaterialStateProperty<Icon?>? thumbIcon; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + SwitchThemeData copyWith({ + MaterialStateProperty<Color?>? thumbColor, + MaterialStateProperty<Color?>? trackColor, + MaterialStateProperty<Color?>? trackOutlineColor, + MaterialStateProperty<double?>? trackOutlineWidth, + MaterialTapTargetSize? materialTapTargetSize, + MaterialStateProperty<MouseCursor?>? mouseCursor, + MaterialStateProperty<Color?>? overlayColor, + double? splashRadius, + MaterialStateProperty<Icon?>? thumbIcon, + }) { + return SwitchThemeData( + thumbColor: thumbColor ?? this.thumbColor, + trackColor: trackColor ?? this.trackColor, + trackOutlineColor: trackOutlineColor ?? this.trackOutlineColor, + trackOutlineWidth: trackOutlineWidth ?? this.trackOutlineWidth, + materialTapTargetSize: materialTapTargetSize ?? this.materialTapTargetSize, + mouseCursor: mouseCursor ?? this.mouseCursor, + overlayColor: overlayColor ?? this.overlayColor, + splashRadius: splashRadius ?? this.splashRadius, + thumbIcon: thumbIcon ?? this.thumbIcon, + ); + } + + /// Linearly interpolate between two [SwitchThemeData]s. + /// + /// {@macro dart.ui.shadow.lerp} + static SwitchThemeData lerp(SwitchThemeData? a, SwitchThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return SwitchThemeData( + thumbColor: MaterialStateProperty.lerp<Color?>(a?.thumbColor, b?.thumbColor, t, Color.lerp), + trackColor: MaterialStateProperty.lerp<Color?>(a?.trackColor, b?.trackColor, t, Color.lerp), + trackOutlineColor: MaterialStateProperty.lerp<Color?>(a?.trackOutlineColor, b?.trackOutlineColor, t, Color.lerp), + trackOutlineWidth: MaterialStateProperty.lerp<double?>(a?.trackOutlineWidth, b?.trackOutlineWidth, t, lerpDouble), + materialTapTargetSize: t < 0.5 ? a?.materialTapTargetSize : b?.materialTapTargetSize, + mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, + overlayColor: MaterialStateProperty.lerp<Color?>(a?.overlayColor, b?.overlayColor, t, Color.lerp), + splashRadius: lerpDouble(a?.splashRadius, b?.splashRadius, t), + thumbIcon: t < 0.5 ? a?.thumbIcon : b?.thumbIcon, + ); + } + + @override + int get hashCode => Object.hash( + thumbColor, + trackColor, + trackOutlineColor, + trackOutlineWidth, + materialTapTargetSize, + mouseCursor, + overlayColor, + splashRadius, + thumbIcon, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is SwitchThemeData + && other.thumbColor == thumbColor + && other.trackColor == trackColor + && other.trackOutlineColor == trackOutlineColor + && other.trackOutlineWidth == trackOutlineWidth + && other.materialTapTargetSize == materialTapTargetSize + && other.mouseCursor == mouseCursor + && other.overlayColor == overlayColor + && other.splashRadius == splashRadius + && other.thumbIcon == thumbIcon; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('thumbColor', thumbColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('trackColor', trackColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('trackOutlineColor', trackOutlineColor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('trackOutlineWidth', trackOutlineWidth, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialTapTargetSize>('materialTapTargetSize', materialTapTargetSize, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('overlayColor', overlayColor, defaultValue: null)); + properties.add(DoubleProperty('splashRadius', splashRadius, defaultValue: null)); + properties.add(DiagnosticsProperty<MaterialStateProperty<Icon?>>('thumbIcon', thumbIcon, defaultValue: null)); + } +} + +/// Applies a switch theme to descendant [Switch] widgets. +/// +/// Descendant widgets obtain the current theme's [SwitchTheme] object using +/// [SwitchTheme.of]. When a widget uses [SwitchTheme.of], it is automatically +/// rebuilt if the theme later changes. +/// +/// A switch theme can be specified as part of the overall Material theme using +/// [ThemeData.switchTheme]. +/// +/// See also: +/// +/// * [SwitchThemeData], which describes the actual configuration of a switch +/// theme. +class SwitchTheme extends InheritedWidget { + /// Constructs a switch theme that configures all descendant [Switch] widgets. + const SwitchTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties used for all descendant [Switch] widgets. + final SwitchThemeData data; + + /// Returns the configuration [data] from the closest [SwitchTheme] ancestor. + /// If there is no ancestor, it returns [ThemeData.switchTheme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// SwitchThemeData theme = SwitchTheme.of(context); + /// ``` + static SwitchThemeData of(BuildContext context) { + final SwitchTheme? switchTheme = context.dependOnInheritedWidgetOfExactType<SwitchTheme>(); + return switchTheme?.data ?? Theme.of(context).switchTheme; + } + + @override + bool updateShouldNotify(SwitchTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tab_bar_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tab_bar_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..1f45037ad0ea85abec30b96485d8fa15ec3db9d1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tab_bar_theme.dart @@ -0,0 +1,209 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'ink_well.dart'; +import 'material_state.dart'; +import 'tabs.dart'; +import 'theme.dart'; + +/// Defines a theme for [TabBar] widgets. +/// +/// A tab bar theme describes the color of the tab label and the size/shape of +/// the [TabBar.indicator]. +/// +/// Descendant widgets obtain the current theme's [TabBarTheme] object using +/// `TabBarTheme.of(context)`. Instances of [TabBarTheme] can be customized with +/// [TabBarTheme.copyWith]. +/// +/// See also: +/// +/// * [TabBar], a widget that displays a horizontal row of tabs. +/// * [ThemeData], which describes the overall theme information for the +/// application. +@immutable +class TabBarTheme with Diagnosticable { + /// Creates a tab bar theme that can be used with [ThemeData.tabBarTheme]. + const TabBarTheme({ + this.indicator, + this.indicatorColor, + this.indicatorSize, + this.dividerColor, + this.dividerHeight, + this.labelColor, + this.labelPadding, + this.labelStyle, + this.unselectedLabelColor, + this.unselectedLabelStyle, + this.overlayColor, + this.splashFactory, + this.mouseCursor, + this.tabAlignment, + }); + + /// Overrides the default value for [TabBar.indicator]. + final Decoration? indicator; + + /// Overrides the default value for [TabBar.indicatorColor]. + final Color? indicatorColor; + + /// Overrides the default value for [TabBar.indicatorSize]. + final TabBarIndicatorSize? indicatorSize; + + /// Overrides the default value for [TabBar.dividerColor]. + final Color? dividerColor; + + /// Overrides the default value for [TabBar.dividerHeight]. + final double? dividerHeight; + + /// Overrides the default value for [TabBar.labelColor]. + /// + /// If [labelColor] is a [MaterialStateColor], then the effective color will + /// depend on the [MaterialState.selected] state, i.e. if the [Tab] is + /// selected or not. In case of unselected state, this [MaterialStateColor]'s + /// resolved color will be used even if [TabBar.unselectedLabelColor] or + /// [unselectedLabelColor] is non-null. + final Color? labelColor; + + /// Overrides the default value for [TabBar.labelPadding]. + /// + /// If there are few tabs with both icon and text and few + /// tabs with only icon or text, this padding is vertically + /// adjusted to provide uniform padding to all tabs. + final EdgeInsetsGeometry? labelPadding; + + /// Overrides the default value for [TabBar.labelStyle]. + final TextStyle? labelStyle; + + /// Overrides the default value for [TabBar.unselectedLabelColor]. + final Color? unselectedLabelColor; + + /// Overrides the default value for [TabBar.unselectedLabelStyle]. + final TextStyle? unselectedLabelStyle; + + /// Overrides the default value for [TabBar.overlayColor]. + final MaterialStateProperty<Color?>? overlayColor; + + /// Overrides the default value for [TabBar.splashFactory]. + final InteractiveInkFeatureFactory? splashFactory; + + /// {@macro flutter.material.tabs.mouseCursor} + /// + /// If specified, overrides the default value of [TabBar.mouseCursor]. + final MaterialStateProperty<MouseCursor?>? mouseCursor; + + /// Overrides the default value for [TabBar.tabAlignment]. + final TabAlignment? tabAlignment; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + TabBarTheme copyWith({ + Decoration? indicator, + Color? indicatorColor, + TabBarIndicatorSize? indicatorSize, + Color? dividerColor, + double? dividerHeight, + Color? labelColor, + EdgeInsetsGeometry? labelPadding, + TextStyle? labelStyle, + Color? unselectedLabelColor, + TextStyle? unselectedLabelStyle, + MaterialStateProperty<Color?>? overlayColor, + InteractiveInkFeatureFactory? splashFactory, + MaterialStateProperty<MouseCursor?>? mouseCursor, + TabAlignment? tabAlignment, + }) { + return TabBarTheme( + indicator: indicator ?? this.indicator, + indicatorColor: indicatorColor ?? this.indicatorColor, + indicatorSize: indicatorSize ?? this.indicatorSize, + dividerColor: dividerColor ?? this.dividerColor, + dividerHeight: dividerHeight ?? this.dividerHeight, + labelColor: labelColor ?? this.labelColor, + labelPadding: labelPadding ?? this.labelPadding, + labelStyle: labelStyle ?? this.labelStyle, + unselectedLabelColor: unselectedLabelColor ?? this.unselectedLabelColor, + unselectedLabelStyle: unselectedLabelStyle ?? this.unselectedLabelStyle, + overlayColor: overlayColor ?? this.overlayColor, + splashFactory: splashFactory ?? this.splashFactory, + mouseCursor: mouseCursor ?? this.mouseCursor, + tabAlignment: tabAlignment ?? this.tabAlignment, + ); + } + + /// The data from the closest [TabBarTheme] instance given the build context. + static TabBarTheme of(BuildContext context) { + return Theme.of(context).tabBarTheme; + } + + /// Linearly interpolate between two tab bar themes. + /// + /// {@macro dart.ui.shadow.lerp} + static TabBarTheme lerp(TabBarTheme a, TabBarTheme b, double t) { + if (identical(a, b)) { + return a; + } + return TabBarTheme( + indicator: Decoration.lerp(a.indicator, b.indicator, t), + indicatorColor: Color.lerp(a.indicatorColor, b.indicatorColor, t), + indicatorSize: t < 0.5 ? a.indicatorSize : b.indicatorSize, + dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t), + dividerHeight: t < 0.5 ? a.dividerHeight : b.dividerHeight, + labelColor: Color.lerp(a.labelColor, b.labelColor, t), + labelPadding: EdgeInsetsGeometry.lerp(a.labelPadding, b.labelPadding, t), + labelStyle: TextStyle.lerp(a.labelStyle, b.labelStyle, t), + unselectedLabelColor: Color.lerp(a.unselectedLabelColor, b.unselectedLabelColor, t), + unselectedLabelStyle: TextStyle.lerp(a.unselectedLabelStyle, b.unselectedLabelStyle, t), + overlayColor: MaterialStateProperty.lerp<Color?>(a.overlayColor, b.overlayColor, t, Color.lerp), + splashFactory: t < 0.5 ? a.splashFactory : b.splashFactory, + mouseCursor: t < 0.5 ? a.mouseCursor : b.mouseCursor, + tabAlignment: t < 0.5 ? a.tabAlignment : b.tabAlignment, + ); + } + + @override + int get hashCode => Object.hash( + indicator, + indicatorColor, + indicatorSize, + dividerColor, + dividerHeight, + labelColor, + labelPadding, + labelStyle, + unselectedLabelColor, + unselectedLabelStyle, + overlayColor, + splashFactory, + mouseCursor, + tabAlignment, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is TabBarTheme + && other.indicator == indicator + && other.indicatorColor == indicatorColor + && other.indicatorSize == indicatorSize + && other.dividerColor == dividerColor + && other.dividerHeight == dividerHeight + && other.labelColor == labelColor + && other.labelPadding == labelPadding + && other.labelStyle == labelStyle + && other.unselectedLabelColor == unselectedLabelColor + && other.unselectedLabelStyle == unselectedLabelStyle + && other.overlayColor == overlayColor + && other.splashFactory == splashFactory + && other.mouseCursor == mouseCursor + && other.tabAlignment == tabAlignment; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tab_controller.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tab_controller.dart new file mode 100644 index 0000000000000000000000000000000000000000..b262b883bddbdf91fcdc8d1ee35ef823d125a66f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tab_controller.dart @@ -0,0 +1,518 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'constants.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Coordinates tab selection between a [TabBar] and a [TabBarView]. +/// +/// The [index] property is the index of the selected tab and the [animation] +/// represents the current scroll positions of the tab bar and the tab bar view. +/// The selected tab's index can be changed with [animateTo]. +/// +/// A stateful widget that builds a [TabBar] or a [TabBarView] can create +/// a [TabController] and share it directly. +/// +/// When the [TabBar] and [TabBarView] don't have a convenient stateful +/// ancestor, a [TabController] can be shared by providing a +/// [DefaultTabController] inherited widget. +/// +/// {@animation 700 540 https://flutter.github.io/assets-for-api-docs/assets/material/tabs.mp4} +/// +/// {@tool snippet} +/// +/// This widget introduces a [Scaffold] with an [AppBar] and a [TabBar]. +/// +/// ```dart +/// class MyTabbedPage extends StatefulWidget { +/// const MyTabbedPage({ super.key }); +/// @override +/// State<MyTabbedPage> createState() => _MyTabbedPageState(); +/// } +/// +/// class _MyTabbedPageState extends State<MyTabbedPage> with SingleTickerProviderStateMixin { +/// static const List<Tab> myTabs = <Tab>[ +/// Tab(text: 'LEFT'), +/// Tab(text: 'RIGHT'), +/// ]; +/// +/// late TabController _tabController; +/// +/// @override +/// void initState() { +/// super.initState(); +/// _tabController = TabController(vsync: this, length: myTabs.length); +/// } +/// +/// @override +/// void dispose() { +/// _tabController.dispose(); +/// super.dispose(); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return Scaffold( +/// appBar: AppBar( +/// bottom: TabBar( +/// controller: _tabController, +/// tabs: myTabs, +/// ), +/// ), +/// body: TabBarView( +/// controller: _tabController, +/// children: myTabs.map((Tab tab) { +/// final String label = tab.text!.toLowerCase(); +/// return Center( +/// child: Text( +/// 'This is the $label tab', +/// style: const TextStyle(fontSize: 36), +/// ), +/// ); +/// }).toList(), +/// ), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to listen to page updates in [TabBar] and [TabBarView] +/// when using [DefaultTabController]. +/// +/// ** See code in examples/api/lib/material/tab_controller/tab_controller.1.dart ** +/// {@end-tool} +/// +class TabController extends ChangeNotifier { + /// Creates an object that manages the state required by [TabBar] and a + /// [TabBarView]. + /// + /// The [length] must not be negative. Typically it's a value greater than + /// one, i.e. typically there are two or more tabs. The [length] must match + /// [TabBar.tabs]'s and [TabBarView.children]'s length. + /// + /// The `initialIndex` must be valid given [length]. If [length] is zero, then + /// `initialIndex` must be 0 (the default). + TabController({ + int initialIndex = 0, + Duration? animationDuration, + required this.length, + required TickerProvider vsync, + }) : assert(length >= 0), + assert(initialIndex >= 0 && (length == 0 || initialIndex < length)), + _index = initialIndex, + _previousIndex = initialIndex, + _animationDuration = animationDuration ?? kTabScrollDuration, + _animationController = AnimationController.unbounded( + value: initialIndex.toDouble(), + vsync: vsync, + ) { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + // Private constructor used by `_copyWith`. This allows a new TabController to + // be created without having to create a new animationController. + TabController._({ + required int index, + required int previousIndex, + required AnimationController? animationController, + required Duration animationDuration, + required this.length, + }) : _index = index, + _previousIndex = previousIndex, + _animationController = animationController, + _animationDuration = animationDuration { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + /// Creates a new [TabController] with `index`, `previousIndex`, `length`, and + /// `animationDuration` if they are non-null. + /// + /// This method is used by [DefaultTabController]. + /// + /// When [DefaultTabController.length] is updated, this method is called to + /// create a new [TabController] without creating a new [AnimationController]. + /// + /// This instance of [TabController] will be disposed and must not be used + /// anymore. + TabController _copyWithAndDispose({ + required int? index, + required int? length, + required int? previousIndex, + required Duration? animationDuration, + }) { + if (index != null) { + _animationController!.value = index.toDouble(); + } + final TabController newController = TabController._( + index: index ?? _index, + length: length ?? this.length, + animationController: _animationController, + previousIndex: previousIndex ?? _previousIndex, + animationDuration: animationDuration ?? _animationDuration, + ); + + // Nulling _animationController to not dispose it. It will be disposed by + // the newly created instance of the TabController. + _animationController = null; + dispose(); + + return newController; + } + + /// An animation whose value represents the current position of the [TabBar]'s + /// selected tab indicator as well as the scrollOffsets of the [TabBar] + /// and [TabBarView]. + /// + /// The animation's value ranges from 0.0 to [length] - 1.0. After the + /// selected tab is changed, the animation's value equals [index]. The + /// animation's value can be [offset] by +/- 1.0 to reflect [TabBarView] + /// drag scrolling. + /// + /// If this [TabController] was disposed, then return null. + Animation<double>? get animation => _animationController?.view; + AnimationController? _animationController; + + /// Controls the duration of TabController and TabBarView animations. + /// + /// Defaults to kTabScrollDuration. + Duration get animationDuration => _animationDuration; + final Duration _animationDuration; + + /// The total number of tabs. + /// + /// Typically greater than one. Must match [TabBar.tabs]'s and + /// [TabBarView.children]'s length. + final int length; + + void _changeIndex(int value, { Duration? duration, Curve? curve }) { + assert(value >= 0 && (value < length || length == 0)); + assert(duration != null || curve == null); + assert(_indexIsChangingCount >= 0); + if (value == _index || length < 2) { + return; + } + _previousIndex = index; + _index = value; + if (duration != null && duration > Duration.zero) { + _indexIsChangingCount += 1; + notifyListeners(); // Because the value of indexIsChanging may have changed. + _animationController! + .animateTo(_index.toDouble(), duration: duration, curve: curve!) + .whenCompleteOrCancel(() { + if (_animationController != null) { // don't notify if we've been disposed + _indexIsChangingCount -= 1; + notifyListeners(); + } + }); + } else { + _indexIsChangingCount += 1; + _animationController!.value = _index.toDouble(); + _indexIsChangingCount -= 1; + notifyListeners(); + } + } + + /// The index of the currently selected tab. + /// + /// Changing the index also updates [previousIndex], sets the [animation]'s + /// value to index, resets [indexIsChanging] to false, and notifies listeners. + /// + /// To change the currently selected tab and play the [animation] use [animateTo]. + /// + /// The value of [index] must be valid given [length]. If [length] is zero, + /// then [index] will also be zero. + int get index => _index; + int _index; + set index(int value) { + _changeIndex(value); + } + + /// The index of the previously selected tab. + /// + /// Initially the same as [index]. + int get previousIndex => _previousIndex; + int _previousIndex; + + /// True while we're animating from [previousIndex] to [index] as a + /// consequence of calling [animateTo]. + /// + /// This value is true during the [animateTo] animation that's triggered when + /// the user taps a [TabBar] tab. It is false when [offset] is changing as a + /// consequence of the user dragging (and "flinging") the [TabBarView]. + bool get indexIsChanging => _indexIsChangingCount != 0; + int _indexIsChangingCount = 0; + + /// Immediately sets [index] and [previousIndex] and then plays the + /// [animation] from its current value to [index]. + /// + /// While the animation is running [indexIsChanging] is true. When the + /// animation completes [offset] will be 0.0. + void animateTo(int value, { Duration? duration, Curve curve = Curves.ease }) { + _changeIndex(value, duration: duration ?? _animationDuration, curve: curve); + } + + /// The difference between the [animation]'s value and [index]. + /// + /// The offset value must be between -1.0 and 1.0. + /// + /// This property is typically set by the [TabBarView] when the user + /// drags left or right. A value between -1.0 and 0.0 implies that the + /// TabBarView has been dragged to the left. Similarly a value between + /// 0.0 and 1.0 implies that the TabBarView has been dragged to the right. + double get offset => _animationController!.value - _index.toDouble(); + set offset(double value) { + assert(value >= -1.0 && value <= 1.0); + assert(!indexIsChanging); + if (value == offset) { + return; + } + _animationController!.value = value + _index.toDouble(); + } + + @override + void dispose() { + _animationController?.dispose(); + _animationController = null; + super.dispose(); + } +} + +class _TabControllerScope extends InheritedWidget { + const _TabControllerScope({ + required this.controller, + required this.enabled, + required super.child, + }); + + final TabController controller; + final bool enabled; + + @override + bool updateShouldNotify(_TabControllerScope old) { + return enabled != old.enabled || controller != old.controller; + } +} + +/// The [TabController] for descendant widgets that don't specify one +/// explicitly. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=POtoEH-5l40} +/// +/// [DefaultTabController] is an inherited widget that is used to share a +/// [TabController] with a [TabBar] or a [TabBarView]. It's used when sharing an +/// explicitly created [TabController] isn't convenient because the tab bar +/// widgets are created by a stateless parent widget or by different parent +/// widgets. +/// +/// {@animation 700 540 https://flutter.github.io/assets-for-api-docs/assets/material/tabs.mp4} +/// +/// ```dart +/// class MyDemo extends StatelessWidget { +/// const MyDemo({super.key}); +/// +/// static const List<Tab> myTabs = <Tab>[ +/// Tab(text: 'LEFT'), +/// Tab(text: 'RIGHT'), +/// ]; +/// +/// @override +/// Widget build(BuildContext context) { +/// return DefaultTabController( +/// length: myTabs.length, +/// child: Scaffold( +/// appBar: AppBar( +/// bottom: const TabBar( +/// tabs: myTabs, +/// ), +/// ), +/// body: TabBarView( +/// children: myTabs.map((Tab tab) { +/// final String label = tab.text!.toLowerCase(); +/// return Center( +/// child: Text( +/// 'This is the $label tab', +/// style: const TextStyle(fontSize: 36), +/// ), +/// ); +/// }).toList(), +/// ), +/// ), +/// ); +/// } +/// } +/// ``` +class DefaultTabController extends StatefulWidget { + /// Creates a default tab controller for the given [child] widget. + /// + /// The [length] argument is typically greater than one. The [length] must + /// match [TabBar.tabs]'s and [TabBarView.children]'s length. + const DefaultTabController({ + super.key, + required this.length, + this.initialIndex = 0, + required this.child, + this.animationDuration, + }) : assert(length >= 0), + assert(length == 0 || (initialIndex >= 0 && initialIndex < length)); + + /// The total number of tabs. + /// + /// Typically greater than one. Must match [TabBar.tabs]'s and + /// [TabBarView.children]'s length. + final int length; + + /// The initial index of the selected tab. + /// + /// Defaults to zero. + final int initialIndex; + + /// Controls the duration of DefaultTabController and TabBarView animations. + /// + /// Defaults to kTabScrollDuration. + final Duration? animationDuration; + + /// The widget below this widget in the tree. + /// + /// Typically a [Scaffold] whose [AppBar] includes a [TabBar]. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The closest instance of [DefaultTabController] that encloses the given + /// context, or null if none is found. + /// + /// {@tool snippet} Typical usage is as follows: + /// + /// ```dart + /// TabController? controller = DefaultTabController.maybeOf(context); + /// ``` + /// {@end-tool} + /// + /// Calling this method will create a dependency on the closest + /// [DefaultTabController] in the [context], if there is one. + /// + /// See also: + /// + /// * [DefaultTabController.of], which is similar to this method, but asserts + /// if no [DefaultTabController] ancestor is found. + static TabController? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<_TabControllerScope>()?.controller; + } + + /// The closest instance of [DefaultTabController] that encloses the given + /// context. + /// + /// If no instance is found, this method will assert in debug mode and throw + /// an exception in release mode. + /// + /// Calling this method will create a dependency on the closest + /// [DefaultTabController] in the [context]. + /// + /// {@tool snippet} Typical usage is as follows: + /// + /// ```dart + /// TabController controller = DefaultTabController.of(context); + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [DefaultTabController.maybeOf], which is similar to this method, but + /// returns null if no [DefaultTabController] ancestor is found. + static TabController of(BuildContext context) { + final TabController? controller = maybeOf(context); + assert(() { + if (controller == null) { + throw FlutterError( + 'DefaultTabController.of() was called with a context that does not ' + 'contain a DefaultTabController widget.\n' + 'No DefaultTabController widget ancestor could be found starting from ' + 'the context that was passed to DefaultTabController.of(). This can ' + 'happen because you are using a widget that looks for a DefaultTabController ' + 'ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return controller!; + } + + @override + State<DefaultTabController> createState() => _DefaultTabControllerState(); +} + +class _DefaultTabControllerState extends State<DefaultTabController> with SingleTickerProviderStateMixin { + late TabController _controller; + + @override + void initState() { + super.initState(); + _controller = TabController( + vsync: this, + length: widget.length, + initialIndex: widget.initialIndex, + animationDuration: widget.animationDuration, + ); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return _TabControllerScope( + controller: _controller, + enabled: TickerMode.of(context), + child: widget.child, + ); + } + + @override + void didUpdateWidget(DefaultTabController oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.length != widget.length) { + // If the length is shortened while the last tab is selected, we should + // automatically update the index of the controller to be the new last tab. + int? newIndex; + int previousIndex = _controller.previousIndex; + if (_controller.index >= widget.length) { + newIndex = math.max(0, widget.length - 1); + previousIndex = _controller.index; + } + _controller = _controller._copyWithAndDispose( + length: widget.length, + animationDuration: widget.animationDuration, + index: newIndex, + previousIndex: previousIndex, + ); + } + + if (oldWidget.animationDuration != widget.animationDuration) { + _controller = _controller._copyWithAndDispose( + length: widget.length, + animationDuration: widget.animationDuration, + index: _controller.index, + previousIndex: _controller.previousIndex, + ); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tab_indicator.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tab_indicator.dart new file mode 100644 index 0000000000000000000000000000000000000000..1b46a7f06e2904cf1f6710af96e6567c1bb993e2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tab_indicator.dart @@ -0,0 +1,125 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; + +/// Used with [TabBar.indicator] to draw a horizontal line below the +/// selected tab. +/// +/// The selected tab underline is inset from the tab's boundary by [insets]. +/// The [borderSide] defines the line's color and weight. +/// +/// The [TabBar.indicatorSize] property can be used to define the indicator's +/// bounds in terms of its (centered) widget with [TabBarIndicatorSize.label], +/// or the entire tab with [TabBarIndicatorSize.tab]. +class UnderlineTabIndicator extends Decoration { + /// Create an underline style selected tab indicator. + const UnderlineTabIndicator({ + this.borderRadius, + this.borderSide = const BorderSide(width: 2.0, color: Colors.white), + this.insets = EdgeInsets.zero, + }); + + /// The radius of the indicator's corners. + /// + /// If this value is non-null, rounded rectangular tab indicator is + /// drawn, otherwise rectangular tab indictor is drawn. + final BorderRadius? borderRadius; + + /// The color and weight of the horizontal line drawn below the selected tab. + final BorderSide borderSide; + + /// Locates the selected tab's underline relative to the tab's boundary. + /// + /// The [TabBar.indicatorSize] property can be used to define the tab + /// indicator's bounds in terms of its (centered) tab widget with + /// [TabBarIndicatorSize.label], or the entire tab with + /// [TabBarIndicatorSize.tab]. + final EdgeInsetsGeometry insets; + + @override + Decoration? lerpFrom(Decoration? a, double t) { + if (a is UnderlineTabIndicator) { + return UnderlineTabIndicator( + borderSide: BorderSide.lerp(a.borderSide, borderSide, t), + insets: EdgeInsetsGeometry.lerp(a.insets, insets, t)!, + ); + } + return super.lerpFrom(a, t); + } + + @override + Decoration? lerpTo(Decoration? b, double t) { + if (b is UnderlineTabIndicator) { + return UnderlineTabIndicator( + borderSide: BorderSide.lerp(borderSide, b.borderSide, t), + insets: EdgeInsetsGeometry.lerp(insets, b.insets, t)!, + ); + } + return super.lerpTo(b, t); + } + + @override + BoxPainter createBoxPainter([ VoidCallback? onChanged ]) { + return _UnderlinePainter(this, borderRadius, onChanged); + } + + Rect _indicatorRectFor(Rect rect, TextDirection textDirection) { + final Rect indicator = insets.resolve(textDirection).deflateRect(rect); + return Rect.fromLTWH( + indicator.left, + indicator.bottom - borderSide.width, + indicator.width, + borderSide.width, + ); + } + + @override + Path getClipPath(Rect rect, TextDirection textDirection) { + if (borderRadius != null) { + return Path()..addRRect( + borderRadius!.toRRect(_indicatorRectFor(rect, textDirection)) + ); + } + return Path()..addRect(_indicatorRectFor(rect, textDirection)); + } +} + +class _UnderlinePainter extends BoxPainter { + _UnderlinePainter( + this.decoration, + this.borderRadius, + super.onChanged, + ); + + final UnderlineTabIndicator decoration; + final BorderRadius? borderRadius; + + @override + void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { + assert(configuration.size != null); + final Rect rect = offset & configuration.size!; + final TextDirection textDirection = configuration.textDirection!; + final Paint paint; + if (borderRadius != null) { + paint = Paint()..color = decoration.borderSide.color; + final Rect indicator = decoration._indicatorRectFor(rect, textDirection); + final RRect rrect = RRect.fromRectAndCorners( + indicator, + topLeft: borderRadius!.topLeft, + topRight: borderRadius!.topRight, + bottomRight: borderRadius!.bottomRight, + bottomLeft: borderRadius!.bottomLeft, + ); + canvas.drawRRect(rrect, paint); + } else { + paint = decoration.borderSide.toPaint()..strokeCap = StrokeCap.square; + final Rect indicator = decoration._indicatorRectFor(rect, textDirection) + .deflate(decoration.borderSide.width / 2.0); + canvas.drawLine(indicator.bottomLeft, indicator.bottomRight, paint); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tabs.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tabs.dart new file mode 100644 index 0000000000000000000000000000000000000000..d6af252a1d0f118c0ecb47c3dcf510b6ed458d0a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tabs.dart @@ -0,0 +1,2398 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart' show DragStartBehavior; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'app_bar.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'debug.dart'; +import 'ink_well.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'tab_bar_theme.dart'; +import 'tab_controller.dart'; +import 'tab_indicator.dart'; +import 'text_theme.dart'; +import 'theme.dart'; + +const double _kTabHeight = 46.0; +const double _kTextAndIconTabHeight = 72.0; +const double _kStartOffset = 52.0; + +/// Defines how the bounds of the selected tab indicator are computed. +/// +/// See also: +/// +/// * [TabBar], which displays a row of tabs. +/// * [TabBarView], which displays a widget for the currently selected tab. +/// * [TabBar.indicator], which defines the appearance of the selected tab +/// indicator relative to the tab's bounds. +enum TabBarIndicatorSize { + /// The tab indicator's bounds are as wide as the space occupied by the tab + /// in the tab bar: from the right edge of the previous tab to the left edge + /// of the next tab. + tab, + + /// The tab's bounds are only as wide as the (centered) tab widget itself. + /// + /// This value is used to align the tab's label, typically a [Tab] + /// widget's text or icon, with the selected tab indicator. + label, +} + +/// Defines how tabs are aligned horizontally in a [TabBar]. +/// +/// See also: +/// +/// * [TabBar], which displays a row of tabs. +/// * [TabBarView], which displays a widget for the currently selected tab. +/// * [TabBar.tabAlignment], which defines the horizontal alignment of the +/// tabs within the [TabBar]. +enum TabAlignment { + // TODO(tahatesser): Add a link to the Material Design spec for + // horizontal offset when it is available. + // It's currently sourced from androidx/compose/material3/TabRow.kt. + /// If [TabBar.isScrollable] is true, tabs are aligned to the + /// start of the [TabBar]. Otherwise throws an exception. + /// + /// It is not recommended to set [TabAlignment.start] when + /// [ThemeData.useMaterial3] is false. + start, + + /// If [TabBar.isScrollable] is true, tabs are aligned to the + /// start of the [TabBar] with an offset of 52.0 pixels. + /// Otherwise throws an exception. + /// + /// It is not recommended to set [TabAlignment.startOffset] when + /// [ThemeData.useMaterial3] is false. + startOffset, + + /// If [TabBar.isScrollable] is false, tabs are stretched to fill the + /// [TabBar]. Otherwise throws an exception. + fill, + + /// Tabs are aligned to the center of the [TabBar]. + center, +} + +/// A Material Design [TabBar] tab. +/// +/// If both [icon] and [text] are provided, the text is displayed below +/// the icon. +/// +/// See also: +/// +/// * [TabBar], which displays a row of tabs. +/// * [TabBarView], which displays a widget for the currently selected tab. +/// * [TabController], which coordinates tab selection between a [TabBar] and a [TabBarView]. +/// * <https://material.io/design/components/tabs.html> +class Tab extends StatelessWidget implements PreferredSizeWidget { + /// Creates a Material Design [TabBar] tab. + /// + /// At least one of [text], [icon], and [child] must be non-null. The [text] + /// and [child] arguments must not be used at the same time. The + /// [iconMargin] is only useful when [icon] and either one of [text] or + /// [child] is non-null. + const Tab({ + super.key, + this.text, + this.icon, + this.iconMargin = const EdgeInsets.only(bottom: 10.0), + this.height, + this.child, + }) : assert(text != null || child != null || icon != null), + assert(text == null || child == null); + + /// The text to display as the tab's label. + /// + /// Must not be used in combination with [child]. + final String? text; + + /// The widget to be used as the tab's label. + /// + /// Usually a [Text] widget, possibly wrapped in a [Semantics] widget. + /// + /// Must not be used in combination with [text]. + final Widget? child; + + /// An icon to display as the tab's label. + final Widget? icon; + + /// The margin added around the tab's icon. + /// + /// Only useful when used in combination with [icon], and either one of + /// [text] or [child] is non-null. + final EdgeInsetsGeometry iconMargin; + + /// The height of the [Tab]. + /// + /// If null, the height will be calculated based on the content of the [Tab]. When `icon` is not + /// null along with `child` or `text`, the default height is 72.0 pixels. Without an `icon`, the + /// height is 46.0 pixels. + final double? height; + + Widget _buildLabelText() { + return child ?? Text(text!, softWrap: false, overflow: TextOverflow.fade); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + + final double calculatedHeight; + final Widget label; + if (icon == null) { + calculatedHeight = _kTabHeight; + label = _buildLabelText(); + } else if (text == null && child == null) { + calculatedHeight = _kTabHeight; + label = icon!; + } else { + calculatedHeight = _kTextAndIconTabHeight; + label = Column( + mainAxisAlignment: MainAxisAlignment.center, + children: <Widget>[ + Container( + margin: iconMargin, + child: icon, + ), + _buildLabelText(), + ], + ); + } + + return SizedBox( + height: height ?? calculatedHeight, + child: Center( + widthFactor: 1.0, + child: label, + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('text', text, defaultValue: null)); + properties.add(DiagnosticsProperty<Widget>('icon', icon, defaultValue: null)); + } + + @override + Size get preferredSize { + if (height != null) { + return Size.fromHeight(height!); + } else if ((text != null || child != null) && icon != null) { + return const Size.fromHeight(_kTextAndIconTabHeight); + } else { + return const Size.fromHeight(_kTabHeight); + } + } +} + +class _TabStyle extends AnimatedWidget { + const _TabStyle({ + required Animation<double> animation, + required this.isSelected, + required this.isPrimary, + required this.labelColor, + required this.unselectedLabelColor, + required this.labelStyle, + required this.unselectedLabelStyle, + required this.defaults, + required this.child, + }) : super(listenable: animation); + + final TextStyle? labelStyle; + final TextStyle? unselectedLabelStyle; + final bool isSelected; + final bool isPrimary; + final Color? labelColor; + final Color? unselectedLabelColor; + final TabBarTheme defaults; + final Widget child; + + MaterialStateColor _resolveWithLabelColor(BuildContext context) { + final ThemeData themeData = Theme.of(context); + final TabBarTheme tabBarTheme = TabBarTheme.of(context); + final Animation<double> animation = listenable as Animation<double>; + + // labelStyle.color (and tabBarTheme.labelStyle.color) is not considered + // as it'll be a breaking change without a possible migration plan. for + // details: https://github.com/flutter/flutter/pull/109541#issuecomment-1294241417 + Color selectedColor = labelColor + ?? tabBarTheme.labelColor + ?? labelStyle?.color + ?? tabBarTheme.labelStyle?.color + ?? defaults.labelColor!; + + final Color unselectedColor; + + if (selectedColor is MaterialStateColor) { + unselectedColor = selectedColor.resolve(const <MaterialState>{}); + selectedColor = selectedColor.resolve(const <MaterialState>{MaterialState.selected}); + } else { + // unselectedLabelColor and tabBarTheme.unselectedLabelColor are ignored + // when labelColor is a MaterialStateColor. + unselectedColor = unselectedLabelColor + ?? tabBarTheme.unselectedLabelColor + ?? unselectedLabelStyle?.color + ?? tabBarTheme.unselectedLabelStyle?.color + ?? (themeData.useMaterial3 + ? defaults.unselectedLabelColor! + : selectedColor.withAlpha(0xB2)); // 70% alpha + } + + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return Color.lerp(selectedColor, unselectedColor, animation.value)!; + } + return Color.lerp(unselectedColor, selectedColor, animation.value)!; + }); + } + + @override + Widget build(BuildContext context) { + final TabBarTheme tabBarTheme = TabBarTheme.of(context); + final Animation<double> animation = listenable as Animation<double>; + + final Set<MaterialState> states = isSelected + ? const <MaterialState>{MaterialState.selected} + : const <MaterialState>{}; + + // To enable TextStyle.lerp(style1, style2, value), both styles must have + // the same value of inherit. Force that to be inherit=true here. + final TextStyle selectedStyle = (labelStyle + ?? tabBarTheme.labelStyle + ?? defaults.labelStyle! + ).copyWith(inherit: true); + final TextStyle unselectedStyle = (unselectedLabelStyle + ?? tabBarTheme.unselectedLabelStyle + ?? labelStyle + ?? defaults.unselectedLabelStyle! + ).copyWith(inherit: true); + final TextStyle textStyle = isSelected + ? TextStyle.lerp(selectedStyle, unselectedStyle, animation.value)! + : TextStyle.lerp(unselectedStyle, selectedStyle, animation.value)!; + final Color color = _resolveWithLabelColor(context).resolve(states); + + return DefaultTextStyle( + style: textStyle.copyWith(color: color), + child: IconTheme.merge( + data: IconThemeData( + size: 24.0, + color: color, + ), + child: child, + ), + ); + } +} + +typedef _LayoutCallback = void Function(List<double> xOffsets, TextDirection textDirection, double width); + +class _TabLabelBarRenderer extends RenderFlex { + _TabLabelBarRenderer({ + required super.direction, + required super.mainAxisSize, + required super.mainAxisAlignment, + required super.crossAxisAlignment, + required TextDirection super.textDirection, + required super.verticalDirection, + required this.onPerformLayout, + }); + + _LayoutCallback onPerformLayout; + + @override + void performLayout() { + super.performLayout(); + // xOffsets will contain childCount+1 values, giving the offsets of the + // leading edge of the first tab as the first value, of the leading edge of + // the each subsequent tab as each subsequent value, and of the trailing + // edge of the last tab as the last value. + RenderBox? child = firstChild; + final List<double> xOffsets = <double>[]; + while (child != null) { + final FlexParentData childParentData = child.parentData! as FlexParentData; + xOffsets.add(childParentData.offset.dx); + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + assert(textDirection != null); + switch (textDirection!) { + case TextDirection.rtl: + xOffsets.insert(0, size.width); + case TextDirection.ltr: + xOffsets.add(size.width); + } + onPerformLayout(xOffsets, textDirection!, size.width); + } +} + +// This class and its renderer class only exist to report the widths of the tabs +// upon layout. The tab widths are only used at paint time (see _IndicatorPainter) +// or in response to input. +class _TabLabelBar extends Flex { + const _TabLabelBar({ + super.children, + required this.onPerformLayout, + required super.mainAxisSize, + }) : super( + direction: Axis.horizontal, + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + verticalDirection: VerticalDirection.down, + ); + + final _LayoutCallback onPerformLayout; + + @override + RenderFlex createRenderObject(BuildContext context) { + return _TabLabelBarRenderer( + direction: direction, + mainAxisAlignment: mainAxisAlignment, + mainAxisSize: mainAxisSize, + crossAxisAlignment: crossAxisAlignment, + textDirection: getEffectiveTextDirection(context)!, + verticalDirection: verticalDirection, + onPerformLayout: onPerformLayout, + ); + } + + @override + void updateRenderObject(BuildContext context, _TabLabelBarRenderer renderObject) { + super.updateRenderObject(context, renderObject); + renderObject.onPerformLayout = onPerformLayout; + } +} + +double _indexChangeProgress(TabController controller) { + final double controllerValue = controller.animation!.value; + final double previousIndex = controller.previousIndex.toDouble(); + final double currentIndex = controller.index.toDouble(); + + // The controller's offset is changing because the user is dragging the + // TabBarView's PageView to the left or right. + if (!controller.indexIsChanging) { + return clampDouble((currentIndex - controllerValue).abs(), 0.0, 1.0); + } + + // The TabController animation's value is changing from previousIndex to currentIndex. + return (controllerValue - currentIndex).abs() / (currentIndex - previousIndex).abs(); +} + +class _DividerPainter extends CustomPainter { + _DividerPainter({ + required this.dividerColor, + required this.dividerHeight, + }); + + final Color dividerColor; + final double dividerHeight; + + @override + void paint(Canvas canvas, Size size) { + if (dividerHeight <= 0.0) { + return; + } + + final Paint paint = Paint() + ..color = dividerColor + ..strokeWidth = dividerHeight; + + canvas.drawLine( + Offset(0, size.height - (paint.strokeWidth / 2)), + Offset(size.width, size.height - (paint.strokeWidth / 2)), + paint, + ); + } + + @override + bool shouldRepaint(_DividerPainter oldDelegate) { + return oldDelegate.dividerColor != dividerColor + || oldDelegate.dividerHeight != dividerHeight; + } +} + +class _IndicatorPainter extends CustomPainter { + _IndicatorPainter({ + required this.controller, + required this.indicator, + required this.indicatorSize, + required this.tabKeys, + required _IndicatorPainter? old, + required this.indicatorPadding, + required this.labelPaddings, + this.dividerColor, + this.dividerHeight, + required this.showDivider, + }) : super(repaint: controller.animation) { + if (old != null) { + saveTabOffsets(old._currentTabOffsets, old._currentTextDirection); + } + } + + final TabController controller; + final Decoration indicator; + final TabBarIndicatorSize? indicatorSize; + final EdgeInsetsGeometry indicatorPadding; + final List<GlobalKey> tabKeys; + final List<EdgeInsetsGeometry> labelPaddings; + final Color? dividerColor; + final double? dividerHeight; + final bool showDivider; + + // _currentTabOffsets and _currentTextDirection are set each time TabBar + // layout is completed. These values can be null when TabBar contains no + // tabs, since there are nothing to lay out. + List<double>? _currentTabOffsets; + TextDirection? _currentTextDirection; + + Rect? _currentRect; + BoxPainter? _painter; + bool _needsPaint = false; + void markNeedsPaint() { + _needsPaint = true; + } + + void dispose() { + _painter?.dispose(); + } + + void saveTabOffsets(List<double>? tabOffsets, TextDirection? textDirection) { + _currentTabOffsets = tabOffsets; + _currentTextDirection = textDirection; + } + + // _currentTabOffsets[index] is the offset of the start edge of the tab at index, and + // _currentTabOffsets[_currentTabOffsets.length] is the end edge of the last tab. + int get maxTabIndex => _currentTabOffsets!.length - 2; + + double centerOf(int tabIndex) { + assert(_currentTabOffsets != null); + assert(_currentTabOffsets!.isNotEmpty); + assert(tabIndex >= 0); + assert(tabIndex <= maxTabIndex); + return (_currentTabOffsets![tabIndex] + _currentTabOffsets![tabIndex + 1]) / 2.0; + } + + Rect indicatorRect(Size tabBarSize, int tabIndex) { + assert(_currentTabOffsets != null); + assert(_currentTextDirection != null); + assert(_currentTabOffsets!.isNotEmpty); + assert(tabIndex >= 0); + assert(tabIndex <= maxTabIndex); + double tabLeft, tabRight; + switch (_currentTextDirection!) { + case TextDirection.rtl: + tabLeft = _currentTabOffsets![tabIndex + 1]; + tabRight = _currentTabOffsets![tabIndex]; + case TextDirection.ltr: + tabLeft = _currentTabOffsets![tabIndex]; + tabRight = _currentTabOffsets![tabIndex + 1]; + } + + if (indicatorSize == TabBarIndicatorSize.label) { + final double tabWidth = tabKeys[tabIndex].currentContext!.size!.width; + final EdgeInsetsGeometry labelPadding = labelPaddings[tabIndex]; + final EdgeInsets insets = labelPadding.resolve(_currentTextDirection); + final double delta = ((tabRight - tabLeft) - (tabWidth + insets.horizontal)) / 2.0; + tabLeft += delta + insets.left; + tabRight = tabLeft + tabWidth; + } + + final EdgeInsets insets = indicatorPadding.resolve(_currentTextDirection); + final Rect rect = Rect.fromLTWH(tabLeft, 0.0, tabRight - tabLeft, tabBarSize.height); + + if (!(rect.size >= insets.collapsedSize)) { + throw FlutterError( + 'indicatorPadding insets should be less than Tab Size\n' + 'Rect Size : ${rect.size}, Insets: $insets', + ); + } + return insets.deflateRect(rect); + } + + @override + void paint(Canvas canvas, Size size) { + _needsPaint = false; + _painter ??= indicator.createBoxPainter(markNeedsPaint); + + final double index = controller.index.toDouble(); + final double value = controller.animation!.value; + final bool ltr = index > value; + final int from = (ltr ? value.floor() : value.ceil()).clamp(0, maxTabIndex); + final int to = (ltr ? from + 1 : from - 1).clamp(0, maxTabIndex); + final Rect fromRect = indicatorRect(size, from); + final Rect toRect = indicatorRect(size, to); + _currentRect = Rect.lerp(fromRect, toRect, (value - from).abs()); + assert(_currentRect != null); + + final ImageConfiguration configuration = ImageConfiguration( + size: _currentRect!.size, + textDirection: _currentTextDirection, + ); + if (showDivider && dividerHeight !> 0) { + final Paint dividerPaint = Paint()..color = dividerColor!..strokeWidth = dividerHeight!; + final Offset dividerP1 = Offset(0, size.height - (dividerPaint.strokeWidth / 2)); + final Offset dividerP2 = Offset(size.width, size.height - (dividerPaint.strokeWidth / 2)); + canvas.drawLine(dividerP1, dividerP2, dividerPaint); + } + _painter!.paint(canvas, _currentRect!.topLeft, configuration); + } + + @override + bool shouldRepaint(_IndicatorPainter old) { + return _needsPaint + || controller != old.controller + || indicator != old.indicator + || tabKeys.length != old.tabKeys.length + || (!listEquals(_currentTabOffsets, old._currentTabOffsets)) + || _currentTextDirection != old._currentTextDirection; + } +} + +class _ChangeAnimation extends Animation<double> with AnimationWithParentMixin<double> { + _ChangeAnimation(this.controller); + + final TabController controller; + + @override + Animation<double> get parent => controller.animation!; + + @override + void removeStatusListener(AnimationStatusListener listener) { + if (controller.animation != null) { + super.removeStatusListener(listener); + } + } + + @override + void removeListener(VoidCallback listener) { + if (controller.animation != null) { + super.removeListener(listener); + } + } + + @override + double get value => _indexChangeProgress(controller); +} + +class _DragAnimation extends Animation<double> with AnimationWithParentMixin<double> { + _DragAnimation(this.controller, this.index); + + final TabController controller; + final int index; + + @override + Animation<double> get parent => controller.animation!; + + @override + void removeStatusListener(AnimationStatusListener listener) { + if (controller.animation != null) { + super.removeStatusListener(listener); + } + } + + @override + void removeListener(VoidCallback listener) { + if (controller.animation != null) { + super.removeListener(listener); + } + } + + @override + double get value { + assert(!controller.indexIsChanging); + final double controllerMaxValue = (controller.length - 1).toDouble(); + final double controllerValue = clampDouble(controller.animation!.value, 0.0, controllerMaxValue); + return clampDouble((controllerValue - index.toDouble()).abs(), 0.0, 1.0); + } +} + +// This class, and TabBarScrollController, only exist to handle the case +// where a scrollable TabBar has a non-zero initialIndex. In that case we can +// only compute the scroll position's initial scroll offset (the "correct" +// pixels value) after the TabBar viewport width and scroll limits are known. +class _TabBarScrollPosition extends ScrollPositionWithSingleContext { + _TabBarScrollPosition({ + required super.physics, + required super.context, + required super.oldPosition, + required this.tabBar, + }) : super( + initialPixels: null, + ); + + final _TabBarState tabBar; + + bool _viewportDimensionWasNonZero = false; + + // The scroll position should be adjusted at least once. + bool _needsPixelsCorrection = true; + + @override + bool applyContentDimensions(double minScrollExtent, double maxScrollExtent) { + bool result = true; + if (!_viewportDimensionWasNonZero) { + _viewportDimensionWasNonZero = viewportDimension != 0.0; + } + // If the viewport never had a non-zero dimension, we just want to jump + // to the initial scroll position to avoid strange scrolling effects in + // release mode: the viewport temporarily may have a dimension of zero + // before the actual dimension is calculated. In that scenario, setting + // the actual dimension would cause a strange scroll effect without this + // guard because the super call below would start a ballistic scroll activity. + if (!_viewportDimensionWasNonZero || _needsPixelsCorrection) { + _needsPixelsCorrection = false; + correctPixels(tabBar._initialScrollOffset(viewportDimension, minScrollExtent, maxScrollExtent)); + result = false; + } + return super.applyContentDimensions(minScrollExtent, maxScrollExtent) && result; + } + + void markNeedsPixelsCorrection() { + _needsPixelsCorrection = true; + } +} + +// This class, and TabBarScrollPosition, only exist to handle the case +// where a scrollable TabBar has a non-zero initialIndex. +class _TabBarScrollController extends ScrollController { + _TabBarScrollController(this.tabBar); + + final _TabBarState tabBar; + + @override + ScrollPosition createScrollPosition(ScrollPhysics physics, ScrollContext context, ScrollPosition? oldPosition) { + return _TabBarScrollPosition( + physics: physics, + context: context, + oldPosition: oldPosition, + tabBar: tabBar, + ); + } +} + +/// A Material Design primary tab bar. +/// +/// Primary tabs are placed at the top of the content pane under a top app bar. +/// They display the main content destinations. +/// +/// Typically created as the [AppBar.bottom] part of an [AppBar] and in +/// conjunction with a [TabBarView]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=POtoEH-5l40} +/// +/// If a [TabController] is not provided, then a [DefaultTabController] ancestor +/// must be provided instead. The tab controller's [TabController.length] must +/// equal the length of the [tabs] list and the length of the +/// [TabBarView.children] list. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// Uses values from [TabBarTheme] if it is set in the current context. +/// +/// {@tool dartpad} +/// This sample shows the implementation of [TabBar] and [TabBarView] using a [DefaultTabController]. +/// Each [Tab] corresponds to a child of the [TabBarView] in the order they are written. +/// +/// ** See code in examples/api/lib/material/tabs/tab_bar.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// [TabBar] can also be implemented by using a [TabController] which provides more options +/// to control the behavior of the [TabBar] and [TabBarView]. This can be used instead of +/// a [DefaultTabController], demonstrated below. +/// +/// ** See code in examples/api/lib/material/tabs/tab_bar.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample showcases nested Material 3 [TabBar]s. It consists of a primary +/// [TabBar] with nested a secondary [TabBar]. The primary [TabBar] uses a +/// [DefaultTabController] while the secondary [TabBar] uses a [TabController]. +/// +/// ** See code in examples/api/lib/material/tabs/tab_bar.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [TabBar.secondary], for a secondary tab bar. +/// * [TabBarView], which displays page views that correspond to each tab. +/// * [TabController], which coordinates tab selection between a [TabBar] and a [TabBarView]. +/// * https://m3.material.io/components/tabs/overview, the Material 3 +/// tab bar specification. +class TabBar extends StatefulWidget implements PreferredSizeWidget { + /// Creates a Material Design primary tab bar. + /// + /// The length of the [tabs] argument must match the [controller]'s + /// [TabController.length]. + /// + /// If a [TabController] is not provided, then there must be a + /// [DefaultTabController] ancestor. + /// + /// The [indicatorWeight] parameter defaults to 2. + /// + /// The [indicatorPadding] parameter defaults to [EdgeInsets.zero]. + /// + /// If [indicator] is not null or provided from [TabBarTheme], + /// then [indicatorWeight] and [indicatorColor] are ignored. + const TabBar({ + super.key, + required this.tabs, + this.controller, + this.isScrollable = false, + this.padding, + this.indicatorColor, + this.automaticIndicatorColorAdjustment = true, + this.indicatorWeight = 2.0, + this.indicatorPadding = EdgeInsets.zero, + this.indicator, + this.indicatorSize, + this.dividerColor, + this.dividerHeight, + this.labelColor, + this.labelStyle, + this.labelPadding, + this.unselectedLabelColor, + this.unselectedLabelStyle, + this.dragStartBehavior = DragStartBehavior.start, + this.overlayColor, + this.mouseCursor, + this.enableFeedback, + this.onTap, + this.physics, + this.splashFactory, + this.splashBorderRadius, + this.tabAlignment, + }) : _isPrimary = true, + assert(indicator != null || (indicatorWeight > 0.0)); + + /// Creates a Material Design secondary tab bar. + /// + /// Secondary tabs are used within a content area to further separate related + /// content and establish hierarchy. + /// + /// {@tool dartpad} + /// This sample showcases nested Material 3 [TabBar]s. It consists of a primary + /// [TabBar] with nested a secondary [TabBar]. The primary [TabBar] uses a + /// [DefaultTabController] while the secondary [TabBar] uses a [TabController]. + /// + /// ** See code in examples/api/lib/material/tabs/tab_bar.2.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [TabBar], for a primary tab bar. + /// * [TabBarView], which displays page views that correspond to each tab. + /// * [TabController], which coordinates tab selection between a [TabBar] and a [TabBarView]. + /// * https://m3.material.io/components/tabs/overview, the Material 3 + /// tab bar specification. + const TabBar.secondary({ + super.key, + required this.tabs, + this.controller, + this.isScrollable = false, + this.padding, + this.indicatorColor, + this.automaticIndicatorColorAdjustment = true, + this.indicatorWeight = 2.0, + this.indicatorPadding = EdgeInsets.zero, + this.indicator, + this.indicatorSize, + this.dividerColor, + this.dividerHeight, + this.labelColor, + this.labelStyle, + this.labelPadding, + this.unselectedLabelColor, + this.unselectedLabelStyle, + this.dragStartBehavior = DragStartBehavior.start, + this.overlayColor, + this.mouseCursor, + this.enableFeedback, + this.onTap, + this.physics, + this.splashFactory, + this.splashBorderRadius, + this.tabAlignment, + }) : _isPrimary = false, + assert(indicator != null || (indicatorWeight > 0.0)); + + /// Typically a list of two or more [Tab] widgets. + /// + /// The length of this list must match the [controller]'s [TabController.length] + /// and the length of the [TabBarView.children] list. + final List<Widget> tabs; + + /// This widget's selection and animation state. + /// + /// If [TabController] is not provided, then the value of [DefaultTabController.of] + /// will be used. + final TabController? controller; + + /// Whether this tab bar can be scrolled horizontally. + /// + /// If [isScrollable] is true, then each tab is as wide as needed for its label + /// and the entire [TabBar] is scrollable. Otherwise each tab gets an equal + /// share of the available space. + final bool isScrollable; + + /// The amount of space by which to inset the tab bar. + /// + /// When [isScrollable] is false, this will yield the same result as if [TabBar] was wrapped + /// in a [Padding] widget. When [isScrollable] is true, the scrollable itself is inset, + /// allowing the padding to scroll with the tab bar, rather than enclosing it. + final EdgeInsetsGeometry? padding; + + /// The color of the line that appears below the selected tab. + /// + /// If this parameter is null, then the value of the Theme's indicatorColor + /// property is used. + /// + /// If [indicator] is specified or provided from [TabBarTheme], + /// this property is ignored. + final Color? indicatorColor; + + /// The thickness of the line that appears below the selected tab. + /// + /// The value of this parameter must be greater than zero. + /// + /// If [ThemeData.useMaterial3] is true and [TabBar] is used to create a + /// primary tab bar, the default value is 3.0. If the provided value is less + /// than 3.0, the default value is used. + /// + /// If [ThemeData.useMaterial3] is true and [TabBar.secondary] is used to + /// create a secondary tab bar, the default value is 2.0. + /// + /// If [ThemeData.useMaterial3] is false, the default value is 2.0. + /// + /// If [indicator] is specified or provided from [TabBarTheme], + /// this property is ignored. + final double indicatorWeight; + + /// The padding for the indicator. + /// + /// The default value of this property is [EdgeInsets.zero]. + /// + /// For [isScrollable] tab bars, specifying [kTabLabelPadding] will align + /// the indicator with the tab's text for [Tab] widgets and all but the + /// shortest [Tab.text] values. + final EdgeInsetsGeometry indicatorPadding; + + /// Defines the appearance of the selected tab indicator. + /// + /// If [indicator] is specified or provided from [TabBarTheme], + /// the [indicatorColor] and [indicatorWeight] properties are ignored. + /// + /// The default, underline-style, selected tab indicator can be defined with + /// [UnderlineTabIndicator]. + /// + /// The indicator's size is based on the tab's bounds. If [indicatorSize] + /// is [TabBarIndicatorSize.tab] the tab's bounds are as wide as the space + /// occupied by the tab in the tab bar. If [indicatorSize] is + /// [TabBarIndicatorSize.label], then the tab's bounds are only as wide as + /// the tab widget itself. + /// + /// See also: + /// + /// * [splashBorderRadius], which defines the clipping radius of the splash + /// and is generally used with [BoxDecoration.borderRadius]. + final Decoration? indicator; + + /// Whether this tab bar should automatically adjust the [indicatorColor]. + /// + /// The default value of this property is true. + /// + /// If [automaticIndicatorColorAdjustment] is true, + /// then the [indicatorColor] will be automatically adjusted to [Colors.white] + /// when the [indicatorColor] is same as [Material.color] of the [Material] + /// parent widget. + final bool automaticIndicatorColorAdjustment; + + /// Defines how the selected tab indicator's size is computed. + /// + /// The size of the selected tab indicator is defined relative to the + /// tab's overall bounds if [indicatorSize] is [TabBarIndicatorSize.tab] + /// (the default) or relative to the bounds of the tab's widget if + /// [indicatorSize] is [TabBarIndicatorSize.label]. + /// + /// The selected tab's location appearance can be refined further with + /// the [indicatorColor], [indicatorWeight], [indicatorPadding], and + /// [indicator] properties. + final TabBarIndicatorSize? indicatorSize; + + /// The color of the divider. + /// + /// If null and [ThemeData.useMaterial3] is true, [TabBarTheme.dividerColor] + /// color is used. If that is null and [ThemeData.useMaterial3] is true, + /// [ColorScheme.surfaceVariant] will be used, otherwise divider will not be drawn. + final Color? dividerColor; + + /// The height of the divider. + /// + /// If null and [ThemeData.useMaterial3] is true, [TabBarTheme.dividerHeight] is used. + /// If that is also null and [ThemeData.useMaterial3] is true, 1.0 will be used. + /// Otherwise divider will not be drawn. + final double? dividerHeight; + + /// The color of selected tab labels. + /// + /// If null, then [TabBarTheme.labelColor] is used. If that is also null and + /// [ThemeData.useMaterial3] is true, [ColorScheme.primary] will be used, + /// otherwise the color of the [ThemeData.primaryTextTheme]'s + /// [TextTheme.bodyLarge] text color is used. + /// + /// If [labelColor] (or, if null, [TabBarTheme.labelColor]) is a + /// [MaterialStateColor], then the effective tab color will depend on the + /// [MaterialState.selected] state, i.e. if the [Tab] is selected or not, + /// ignoring [unselectedLabelColor] even if it's non-null. + /// + /// When this color or the [TabBarTheme.labelColor] is specified, it overrides + /// the [TextStyle.color] specified for the [labelStyle] or the + /// [TabBarTheme.labelStyle]. + /// + /// See also: + /// + /// * [unselectedLabelColor], for color of unselected tab labels. + final Color? labelColor; + + /// The color of unselected tab labels. + /// + /// If [labelColor] (or, if null, [TabBarTheme.labelColor]) is a + /// [MaterialStateColor], then the unselected tabs are rendered with + /// that [MaterialStateColor]'s resolved color for unselected state, even if + /// [unselectedLabelColor] is non-null. + /// + /// If null, then [TabBarTheme.unselectedLabelColor] is used. If that is also + /// null and [ThemeData.useMaterial3] is true, [ColorScheme.onSurfaceVariant] + /// will be used, otherwise unselected tab labels are rendered with + /// [labelColor] at 70% opacity. + /// + /// When this color or the [TabBarTheme.unselectedLabelColor] is specified, it + /// overrides the [TextStyle.color] specified for the [unselectedLabelStyle] + /// or the [TabBarTheme.unselectedLabelStyle]. + /// + /// See also: + /// + /// * [labelColor], for color of selected tab labels. + final Color? unselectedLabelColor; + + /// The text style of the selected tab labels. + /// + /// The color specified in [labelStyle] and [TabBarTheme.labelStyle] is used + /// to style the label when [labelColor] or [TabBarTheme.labelColor] are not + /// specified. + /// + /// If [unselectedLabelStyle] is null, then this text style will be used for + /// both selected and unselected label styles. + /// + /// If this property is null, then [TabBarTheme.labelStyle] will be used. + /// + /// If that is also null and [ThemeData.useMaterial3] is true, [TextTheme.titleSmall] + /// will be used, otherwise the text style of the [ThemeData.primaryTextTheme]'s + /// [TextTheme.bodyLarge] definition is used. + final TextStyle? labelStyle; + + /// The text style of the unselected tab labels. + /// + /// The color specified in [unselectedLabelStyle] and [TabBarTheme.unselectedLabelStyle] + /// is used to style the label when [unselectedLabelColor] or [TabBarTheme.unselectedLabelColor] + /// are not specified. + /// + /// If this property is null, then [TabBarTheme.unselectedLabelStyle] will be used. + /// + /// If that is also null and [ThemeData.useMaterial3] is true, [TextTheme.titleSmall] + /// will be used, otherwise then the [labelStyle] value is used. If [labelStyle] is null, + /// the text style of the [ThemeData.primaryTextTheme]'s [TextTheme.bodyLarge] + /// definition is used. + final TextStyle? unselectedLabelStyle; + + /// The padding added to each of the tab labels. + /// + /// If there are few tabs with both icon and text and few + /// tabs with only icon or text, this padding is vertically + /// adjusted to provide uniform padding to all tabs. + /// + /// If this property is null, then [kTabLabelPadding] is used. + final EdgeInsetsGeometry? labelPadding; + + /// Defines the ink response focus, hover, and splash colors. + /// + /// If non-null, it is resolved against one of [MaterialState.focused], + /// [MaterialState.hovered], and [MaterialState.pressed]. + /// + /// [MaterialState.pressed] triggers a ripple (an ink splash), per + /// the current Material Design spec. + /// + /// If the overlay color is null or resolves to null, then the default values + /// for [InkResponse.focusColor], [InkResponse.hoverColor], [InkResponse.splashColor], + /// and [InkResponse.highlightColor] will be used instead. + final MaterialStateProperty<Color?>? overlayColor; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@template flutter.material.tabs.mouseCursor} + /// The cursor for a mouse pointer when it enters or is hovering over the + /// individual tab widgets. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.selected]. + /// {@endtemplate} + /// + /// If null, then the value of [TabBarTheme.mouseCursor] is used. If + /// that is also null, then [MaterialStateMouseCursor.clickable] is used. + /// + /// See also: + /// + /// * [MaterialStateMouseCursor], which can be used to create a [MouseCursor] + /// that is also a [MaterialStateProperty<MouseCursor>]. + final MouseCursor? mouseCursor; + + /// Whether detected gestures should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a long-press + /// will produce a short vibration, when feedback is enabled. + /// + /// Defaults to true. + final bool? enableFeedback; + + /// An optional callback that's called when the [TabBar] is tapped. + /// + /// The callback is applied to the index of the tab where the tap occurred. + /// + /// This callback has no effect on the default handling of taps. It's for + /// applications that want to do a little extra work when a tab is tapped, + /// even if the tap doesn't change the TabController's index. TabBar [onTap] + /// callbacks should not make changes to the TabController since that would + /// interfere with the default tap handler. + final ValueChanged<int>? onTap; + + /// How the [TabBar]'s scroll view should respond to user input. + /// + /// For example, determines how the scroll view continues to animate after the + /// user stops dragging the scroll view. + /// + /// Defaults to matching platform conventions. + final ScrollPhysics? physics; + + /// Creates the tab bar's [InkWell] splash factory, which defines + /// the appearance of "ink" splashes that occur in response to taps. + /// + /// Use [NoSplash.splashFactory] to defeat ink splash rendering. For example + /// to defeat both the splash and the hover/pressed overlay, but not the + /// keyboard focused overlay: + /// + /// ```dart + /// TabBar( + /// splashFactory: NoSplash.splashFactory, + /// overlayColor: MaterialStateProperty.resolveWith<Color?>( + /// (Set<MaterialState> states) { + /// return states.contains(MaterialState.focused) ? null : Colors.transparent; + /// }, + /// ), + /// tabs: const <Widget>[ + /// // ... + /// ], + /// ) + /// ``` + final InteractiveInkFeatureFactory? splashFactory; + + /// Defines the clipping radius of splashes that extend outside the bounds of the tab. + /// + /// This can be useful to match the [BoxDecoration.borderRadius] provided as [indicator]. + /// + /// ```dart + /// TabBar( + /// indicator: BoxDecoration( + /// borderRadius: BorderRadius.circular(40), + /// ), + /// splashBorderRadius: BorderRadius.circular(40), + /// tabs: const <Widget>[ + /// // ... + /// ], + /// ) + /// ``` + /// + /// If this property is null, it is interpreted as [BorderRadius.zero]. + final BorderRadius? splashBorderRadius; + + /// Specifies the horizontal alignment of the tabs within a [TabBar]. + /// + /// If [TabBar.isScrollable] is false, only [TabAlignment.fill] and + /// [TabAlignment.center] are supported. Otherwise an exception is thrown. + /// + /// If [TabBar.isScrollable] is true, only [TabAlignment.start], [TabAlignment.startOffset], + /// and [TabAlignment.center] are supported. Otherwise an exception is thrown. + /// + /// If this is null, then the value of [TabBarTheme.tabAlignment] is used. + /// + /// If [TabBarTheme.tabAlignment] is null and [ThemeData.useMaterial3] is true, + /// then [TabAlignment.startOffset] is used if [isScrollable] is true, + /// otherwise [TabAlignment.fill] is used. + /// + /// If [TabBarTheme.tabAlignment] is null and [ThemeData.useMaterial3] is false, + /// then [TabAlignment.center] is used if [isScrollable] is true, + /// otherwise [TabAlignment.fill] is used. + final TabAlignment? tabAlignment; + + /// A size whose height depends on if the tabs have both icons and text. + /// + /// [AppBar] uses this size to compute its own preferred size. + @override + Size get preferredSize { + double maxHeight = _kTabHeight; + for (final Widget item in tabs) { + if (item is PreferredSizeWidget) { + final double itemHeight = item.preferredSize.height; + maxHeight = math.max(itemHeight, maxHeight); + } + } + return Size.fromHeight(maxHeight + indicatorWeight); + } + + /// Returns whether the [TabBar] contains a tab with both text and icon. + /// + /// [TabBar] uses this to give uniform padding to all tabs in cases where + /// there are some tabs with both text and icon and some which contain only + /// text or icon. + bool get tabHasTextAndIcon { + for (final Widget item in tabs) { + if (item is PreferredSizeWidget) { + if (item.preferredSize.height == _kTextAndIconTabHeight) { + return true; + } + } + } + return false; + } + + /// Whether this tab bar is a primary tab bar. + /// + /// Otherwise, it is a secondary tab bar. + final bool _isPrimary; + + @override + State<TabBar> createState() => _TabBarState(); +} + +class _TabBarState extends State<TabBar> { + ScrollController? _scrollController; + TabController? _controller; + _IndicatorPainter? _indicatorPainter; + int? _currentIndex; + late double _tabStripWidth; + late List<GlobalKey> _tabKeys; + late List<EdgeInsetsGeometry> _labelPaddings; + bool _debugHasScheduledValidTabsCountCheck = false; + + @override + void initState() { + super.initState(); + // If indicatorSize is TabIndicatorSize.label, _tabKeys[i] is used to find + // the width of tab widget i. See _IndicatorPainter.indicatorRect(). + _tabKeys = widget.tabs.map((Widget tab) => GlobalKey()).toList(); + _labelPaddings = List<EdgeInsetsGeometry>.filled(widget.tabs.length, EdgeInsets.zero, growable: true); + } + + TabBarTheme get _defaults { + if (Theme.of(context).useMaterial3) { + return widget._isPrimary + ? _TabsPrimaryDefaultsM3(context, widget.isScrollable) + : _TabsSecondaryDefaultsM3(context, widget.isScrollable); + } else { + return _TabsDefaultsM2(context, widget.isScrollable); + } + } + + Decoration _getIndicator(TabBarIndicatorSize indicatorSize) { + final ThemeData theme = Theme.of(context); + final TabBarTheme tabBarTheme = TabBarTheme.of(context); + + if (widget.indicator != null) { + return widget.indicator!; + } + if (tabBarTheme.indicator != null) { + return tabBarTheme.indicator!; + } + + Color color = widget.indicatorColor ?? tabBarTheme.indicatorColor ?? _defaults.indicatorColor!; + // ThemeData tries to avoid this by having indicatorColor avoid being the + // primaryColor. However, it's possible that the tab bar is on a + // Material that isn't the primaryColor. In that case, if the indicator + // color ends up matching the material's color, then this overrides it. + // When that happens, automatic transitions of the theme will likely look + // ugly as the indicator color suddenly snaps to white at one end, but it's + // not clear how to avoid that any further. + // + // The material's color might be null (if it's a transparency). In that case + // there's no good way for us to find out what the color is so we don't. + // + // TODO(xu-baolin): Remove automatic adjustment to white color indicator + // with a better long-term solution. + // https://github.com/flutter/flutter/pull/68171#pullrequestreview-517753917 + if (widget.automaticIndicatorColorAdjustment && + color.value == Material.maybeOf(context)?.color?.value) { + color = Colors.white; + } + + final bool primaryWithLabelIndicator = widget._isPrimary && indicatorSize == TabBarIndicatorSize.label; + final double effectiveIndicatorWeight = theme.useMaterial3 && primaryWithLabelIndicator + ? math.max(widget.indicatorWeight, _TabsPrimaryDefaultsM3.indicatorWeight) + : widget.indicatorWeight; + // Only Material 3 primary TabBar with label indicatorSize should be rounded. + final BorderRadius? effectiveBorderRadius = theme.useMaterial3 && primaryWithLabelIndicator + ? BorderRadius.only( + topLeft: Radius.circular(effectiveIndicatorWeight), + topRight: Radius.circular(effectiveIndicatorWeight), + ) + : null; + return UnderlineTabIndicator( + borderRadius: effectiveBorderRadius, + borderSide: BorderSide( + // TODO(tahatesser): Make sure this value matches Material 3 Tabs spec + // when `preferredSize`and `indicatorWeight` are updated to support Material 3 + // https://m3.material.io/components/tabs/specs#149a189f-9039-4195-99da-15c205d20e30, + // https://github.com/flutter/flutter/issues/116136 + width: effectiveIndicatorWeight, + color: color, + ), + ); + } + + // If the TabBar is rebuilt with a new tab controller, the caller should + // dispose the old one. In that case the old controller's animation will be + // null and should not be accessed. + bool get _controllerIsValid => _controller?.animation != null; + + void _updateTabController() { + final TabController? newController = widget.controller ?? DefaultTabController.maybeOf(context); + assert(() { + if (newController == null) { + throw FlutterError( + 'No TabController for ${widget.runtimeType}.\n' + 'When creating a ${widget.runtimeType}, you must either provide an explicit ' + 'TabController using the "controller" property, or you must ensure that there ' + 'is a DefaultTabController above the ${widget.runtimeType}.\n' + 'In this case, there was neither an explicit controller nor a default controller.', + ); + } + return true; + }()); + + if (newController == _controller) { + return; + } + + if (_controllerIsValid) { + _controller!.animation!.removeListener(_handleTabControllerAnimationTick); + _controller!.removeListener(_handleTabControllerTick); + } + _controller = newController; + if (_controller != null) { + _controller!.animation!.addListener(_handleTabControllerAnimationTick); + _controller!.addListener(_handleTabControllerTick); + _currentIndex = _controller!.index; + } + } + + void _initIndicatorPainter() { + final ThemeData theme = Theme.of(context); + final TabBarTheme tabBarTheme = TabBarTheme.of(context); + final TabBarIndicatorSize indicatorSize = widget.indicatorSize + ?? tabBarTheme.indicatorSize + ?? _defaults.indicatorSize!; + + _indicatorPainter = !_controllerIsValid ? null : _IndicatorPainter( + controller: _controller!, + indicator: _getIndicator(indicatorSize), + indicatorSize: widget.indicatorSize ?? tabBarTheme.indicatorSize ?? _defaults.indicatorSize!, + indicatorPadding: widget.indicatorPadding, + tabKeys: _tabKeys, + old: _indicatorPainter, + labelPaddings: _labelPaddings, + dividerColor: widget.dividerColor ?? tabBarTheme.dividerColor ?? _defaults.dividerColor, + dividerHeight: widget.dividerHeight ?? tabBarTheme.dividerHeight ?? _defaults.dividerHeight, + showDivider: theme.useMaterial3 && !widget.isScrollable, + ); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + assert(debugCheckHasMaterial(context)); + _updateTabController(); + _initIndicatorPainter(); + } + + @override + void didUpdateWidget(TabBar oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.controller != oldWidget.controller) { + _updateTabController(); + _initIndicatorPainter(); + // Adjust scroll position. + if (_scrollController != null && _scrollController!.hasClients) { + final ScrollPosition position = _scrollController!.position; + if (position is _TabBarScrollPosition) { + position.markNeedsPixelsCorrection(); + } + } + } else if (widget.indicatorColor != oldWidget.indicatorColor || + widget.indicatorWeight != oldWidget.indicatorWeight || + widget.indicatorSize != oldWidget.indicatorSize || + widget.indicatorPadding != oldWidget.indicatorPadding || + widget.indicator != oldWidget.indicator || + widget.dividerColor != oldWidget.dividerColor || + widget.dividerHeight != oldWidget.dividerHeight) { + _initIndicatorPainter(); + } + + if (widget.tabs.length > _tabKeys.length) { + final int delta = widget.tabs.length - _tabKeys.length; + _tabKeys.addAll(List<GlobalKey>.generate(delta, (int n) => GlobalKey())); + _labelPaddings.addAll(List<EdgeInsetsGeometry>.filled(delta, EdgeInsets.zero)); + } else if (widget.tabs.length < _tabKeys.length) { + _tabKeys.removeRange(widget.tabs.length, _tabKeys.length); + _labelPaddings.removeRange(widget.tabs.length, _tabKeys.length); + } + } + + @override + void dispose() { + _indicatorPainter!.dispose(); + if (_controllerIsValid) { + _controller!.animation!.removeListener(_handleTabControllerAnimationTick); + _controller!.removeListener(_handleTabControllerTick); + } + _controller = null; + _scrollController?.dispose(); + // We don't own the _controller Animation, so it's not disposed here. + super.dispose(); + } + + int get maxTabIndex => _indicatorPainter!.maxTabIndex; + + double _tabScrollOffset(int index, double viewportWidth, double minExtent, double maxExtent) { + if (!widget.isScrollable) { + return 0.0; + } + double tabCenter = _indicatorPainter!.centerOf(index); + double paddingStart; + switch (Directionality.of(context)) { + case TextDirection.rtl: + paddingStart = widget.padding?.resolve(TextDirection.rtl).right ?? 0; + tabCenter = _tabStripWidth - tabCenter; + case TextDirection.ltr: + paddingStart = widget.padding?.resolve(TextDirection.ltr).left ?? 0; + } + + return clampDouble(tabCenter + paddingStart - viewportWidth / 2.0, minExtent, maxExtent); + } + + double _tabCenteredScrollOffset(int index) { + final ScrollPosition position = _scrollController!.position; + return _tabScrollOffset(index, position.viewportDimension, position.minScrollExtent, position.maxScrollExtent); + } + + double _initialScrollOffset(double viewportWidth, double minExtent, double maxExtent) { + return _tabScrollOffset(_currentIndex!, viewportWidth, minExtent, maxExtent); + } + + void _scrollToCurrentIndex() { + final double offset = _tabCenteredScrollOffset(_currentIndex!); + _scrollController!.animateTo(offset, duration: kTabScrollDuration, curve: Curves.ease); + } + + void _scrollToControllerValue() { + final double? leadingPosition = _currentIndex! > 0 ? _tabCenteredScrollOffset(_currentIndex! - 1) : null; + final double middlePosition = _tabCenteredScrollOffset(_currentIndex!); + final double? trailingPosition = _currentIndex! < maxTabIndex ? _tabCenteredScrollOffset(_currentIndex! + 1) : null; + + final double index = _controller!.index.toDouble(); + final double value = _controller!.animation!.value; + final double offset; + if (value == index - 1.0) { + offset = leadingPosition ?? middlePosition; + } else if (value == index + 1.0) { + offset = trailingPosition ?? middlePosition; + } else if (value == index) { + offset = middlePosition; + } else if (value < index) { + offset = leadingPosition == null ? middlePosition : lerpDouble(middlePosition, leadingPosition, index - value)!; + } else { + offset = trailingPosition == null ? middlePosition : lerpDouble(middlePosition, trailingPosition, value - index)!; + } + + _scrollController!.jumpTo(offset); + } + + void _handleTabControllerAnimationTick() { + assert(mounted); + if (!_controller!.indexIsChanging && widget.isScrollable) { + // Sync the TabBar's scroll position with the TabBarView's PageView. + _currentIndex = _controller!.index; + _scrollToControllerValue(); + } + } + + void _handleTabControllerTick() { + if (_controller!.index != _currentIndex) { + _currentIndex = _controller!.index; + if (widget.isScrollable) { + _scrollToCurrentIndex(); + } + } + setState(() { + // Rebuild the tabs after a (potentially animated) index change + // has completed. + }); + } + + // Called each time layout completes. + void _saveTabOffsets(List<double> tabOffsets, TextDirection textDirection, double width) { + _tabStripWidth = width; + _indicatorPainter?.saveTabOffsets(tabOffsets, textDirection); + } + + void _handleTap(int index) { + assert(index >= 0 && index < widget.tabs.length); + _controller!.animateTo(index); + widget.onTap?.call(index); + } + + Widget _buildStyledTab(Widget child, bool isSelected, Animation<double> animation, TabBarTheme defaults) { + return _TabStyle( + animation: animation, + isSelected: isSelected, + isPrimary: widget._isPrimary, + labelColor: widget.labelColor, + unselectedLabelColor: widget.unselectedLabelColor, + labelStyle: widget.labelStyle, + unselectedLabelStyle: widget.unselectedLabelStyle, + defaults: defaults, + child: child, + ); + } + + bool _debugScheduleCheckHasValidTabsCount() { + if (_debugHasScheduledValidTabsCountCheck) { + return true; + } + WidgetsBinding.instance.addPostFrameCallback((Duration duration) { + _debugHasScheduledValidTabsCountCheck = false; + if (!mounted) { + return; + } + assert(() { + if (_controller!.length != widget.tabs.length) { + throw FlutterError( + "Controller's length property (${_controller!.length}) does not match the " + "number of tabs (${widget.tabs.length}) present in TabBar's tabs property.", + ); + } + return true; + }()); + }, debugLabel: 'TabBar.tabsCountCheck'); + _debugHasScheduledValidTabsCountCheck = true; + return true; + } + + bool _debugTabAlignmentIsValid(TabAlignment tabAlignment) { + assert(() { + if (widget.isScrollable && tabAlignment == TabAlignment.fill) { + throw FlutterError( + '$tabAlignment is only valid for non-scrollable tab bars.', + ); + } + if (!widget.isScrollable + && (tabAlignment == TabAlignment.start + || tabAlignment == TabAlignment.startOffset)) { + throw FlutterError( + '$tabAlignment is only valid for scrollable tab bars.', + ); + } + return true; + }()); + return true; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + assert(_debugScheduleCheckHasValidTabsCount()); + final ThemeData theme = Theme.of(context); + final TabBarTheme tabBarTheme = TabBarTheme.of(context); + final TabAlignment effectiveTabAlignment = widget.tabAlignment ?? tabBarTheme.tabAlignment ?? _defaults.tabAlignment!; + assert(_debugTabAlignmentIsValid(effectiveTabAlignment)); + + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + if (_controller!.length == 0) { + return Container( + height: _kTabHeight + widget.indicatorWeight, + ); + } + + final List<Widget> wrappedTabs = List<Widget>.generate(widget.tabs.length, (int index) { + const double verticalAdjustment = (_kTextAndIconTabHeight - _kTabHeight)/2.0; + EdgeInsetsGeometry? adjustedPadding; + + if (widget.tabs[index] is PreferredSizeWidget) { + final PreferredSizeWidget tab = widget.tabs[index] as PreferredSizeWidget; + if (widget.tabHasTextAndIcon && tab.preferredSize.height == _kTabHeight) { + if (widget.labelPadding != null || tabBarTheme.labelPadding != null) { + adjustedPadding = (widget.labelPadding ?? tabBarTheme.labelPadding!).add(const EdgeInsets.symmetric(vertical: verticalAdjustment)); + } + else { + adjustedPadding = const EdgeInsets.symmetric(vertical: verticalAdjustment, horizontal: 16.0); + } + } + } + + _labelPaddings[index] = adjustedPadding ?? widget.labelPadding ?? tabBarTheme.labelPadding ?? kTabLabelPadding; + + return Center( + heightFactor: 1.0, + child: Padding( + padding: _labelPaddings[index], + child: KeyedSubtree( + key: _tabKeys[index], + child: widget.tabs[index], + ), + ), + ); + }); + + // If the controller was provided by DefaultTabController and we're part + // of a Hero (typically the AppBar), then we will not be able to find the + // controller during a Hero transition. See https://github.com/flutter/flutter/issues/213. + if (_controller != null) { + final int previousIndex = _controller!.previousIndex; + + if (_controller!.indexIsChanging) { + // The user tapped on a tab, the tab controller's animation is running. + assert(_currentIndex != previousIndex); + final Animation<double> animation = _ChangeAnimation(_controller!); + wrappedTabs[_currentIndex!] = _buildStyledTab(wrappedTabs[_currentIndex!], true, animation, _defaults); + wrappedTabs[previousIndex] = _buildStyledTab(wrappedTabs[previousIndex], false, animation, _defaults); + } else { + // The user is dragging the TabBarView's PageView left or right. + final int tabIndex = _currentIndex!; + final Animation<double> centerAnimation = _DragAnimation(_controller!, tabIndex); + wrappedTabs[tabIndex] = _buildStyledTab(wrappedTabs[tabIndex], true, centerAnimation, _defaults); + if (_currentIndex! > 0) { + final int tabIndex = _currentIndex! - 1; + final Animation<double> previousAnimation = ReverseAnimation(_DragAnimation(_controller!, tabIndex)); + wrappedTabs[tabIndex] = _buildStyledTab(wrappedTabs[tabIndex], false, previousAnimation, _defaults); + } + if (_currentIndex! < widget.tabs.length - 1) { + final int tabIndex = _currentIndex! + 1; + final Animation<double> nextAnimation = ReverseAnimation(_DragAnimation(_controller!, tabIndex)); + wrappedTabs[tabIndex] = _buildStyledTab(wrappedTabs[tabIndex], false, nextAnimation, _defaults); + } + } + } + + // Add the tap handler to each tab. If the tab bar is not scrollable, + // then give all of the tabs equal flexibility so that they each occupy + // the same share of the tab bar's overall width. + final int tabCount = widget.tabs.length; + for (int index = 0; index < tabCount; index += 1) { + final Set<MaterialState> selectedState = <MaterialState>{ + if (index == _currentIndex) MaterialState.selected, + }; + + final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor?>(widget.mouseCursor, selectedState) + ?? tabBarTheme.mouseCursor?.resolve(selectedState) + ?? MaterialStateMouseCursor.clickable.resolve(selectedState); + + final MaterialStateProperty<Color?> defaultOverlay = MaterialStateProperty.resolveWith<Color?>( + (Set<MaterialState> states) { + final Set<MaterialState> effectiveStates = selectedState..addAll(states); + return _defaults.overlayColor?.resolve(effectiveStates); + }, + ); + wrappedTabs[index] = InkWell( + mouseCursor: effectiveMouseCursor, + onTap: () { _handleTap(index); }, + enableFeedback: widget.enableFeedback ?? true, + overlayColor: widget.overlayColor ?? tabBarTheme.overlayColor ?? defaultOverlay, + splashFactory: widget.splashFactory ?? tabBarTheme.splashFactory ?? _defaults.splashFactory, + borderRadius: widget.splashBorderRadius, + child: Padding( + padding: EdgeInsets.only(bottom: widget.indicatorWeight), + child: Stack( + children: <Widget>[ + wrappedTabs[index], + Semantics( + selected: index == _currentIndex, + label: localizations.tabLabel(tabIndex: index + 1, tabCount: tabCount), + ), + ], + ), + ), + ); + if (!widget.isScrollable && effectiveTabAlignment == TabAlignment.fill) { + wrappedTabs[index] = Expanded(child: wrappedTabs[index]); + } + } + + Widget tabBar = CustomPaint( + painter: _indicatorPainter, + child: _TabStyle( + animation: kAlwaysDismissedAnimation, + isSelected: false, + isPrimary: widget._isPrimary, + labelColor: widget.labelColor, + unselectedLabelColor: widget.unselectedLabelColor, + labelStyle: widget.labelStyle, + unselectedLabelStyle: widget.unselectedLabelStyle, + defaults: _defaults, + child: _TabLabelBar( + onPerformLayout: _saveTabOffsets, + mainAxisSize: effectiveTabAlignment == TabAlignment.fill ? MainAxisSize.max : MainAxisSize.min, + children: wrappedTabs, + ), + ), + ); + + if (widget.isScrollable) { + final EdgeInsetsGeometry? effectivePadding = effectiveTabAlignment == TabAlignment.startOffset + ? const EdgeInsetsDirectional.only(start: _kStartOffset).add(widget.padding ?? EdgeInsets.zero) + : widget.padding; + _scrollController ??= _TabBarScrollController(this); + tabBar = ScrollConfiguration( + // The scrolling tabs should not show an overscroll indicator. + behavior: ScrollConfiguration.of(context).copyWith(overscroll: false), + child: SingleChildScrollView( + dragStartBehavior: widget.dragStartBehavior, + scrollDirection: Axis.horizontal, + controller: _scrollController, + padding: effectivePadding, + physics: widget.physics, + child: tabBar, + ), + ); + if (theme.useMaterial3) { + final AlignmentGeometry effectiveAlignment = switch (effectiveTabAlignment) { + TabAlignment.center => Alignment.center, + TabAlignment.start || TabAlignment.startOffset || TabAlignment.fill => AlignmentDirectional.centerStart, + }; + + final Color dividerColor = widget.dividerColor ?? tabBarTheme.dividerColor ?? _defaults.dividerColor!; + final double dividerHeight = widget.dividerHeight ?? tabBarTheme.dividerHeight ?? _defaults.dividerHeight!; + final bool showDivider = dividerColor != Colors.transparent && dividerHeight > 0; + + tabBar = Align( + heightFactor: 1.0, + widthFactor: showDivider ? null : 1.0, + alignment: effectiveAlignment, + child: tabBar, + ); + + if (showDivider) { + tabBar = CustomPaint( + painter: _DividerPainter( + dividerColor: widget.dividerColor ?? tabBarTheme.dividerColor ?? _defaults.dividerColor!, + dividerHeight: widget.dividerHeight ?? tabBarTheme.dividerHeight ?? _defaults.dividerHeight!, + ), + child: tabBar, + ); + } + } + } else if (widget.padding != null) { + tabBar = Padding( + padding: widget.padding!, + child: tabBar, + ); + } + + return tabBar; + } +} + +/// A page view that displays the widget which corresponds to the currently +/// selected tab. +/// +/// This widget is typically used in conjunction with a [TabBar]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=POtoEH-5l40} +/// +/// If a [TabController] is not provided, then there must be a [DefaultTabController] +/// ancestor. +/// +/// The tab controller's [TabController.length] must equal the length of the +/// [children] list and the length of the [TabBar.tabs] list. +/// +/// To see a sample implementation, visit the [TabController] documentation. +class TabBarView extends StatefulWidget { + /// Creates a page view with one child per tab. + /// + /// The length of [children] must be the same as the [controller]'s length. + const TabBarView({ + super.key, + required this.children, + this.controller, + this.physics, + this.dragStartBehavior = DragStartBehavior.start, + this.viewportFraction = 1.0, + this.clipBehavior = Clip.hardEdge, + }); + + /// This widget's selection and animation state. + /// + /// If [TabController] is not provided, then the value of [DefaultTabController.of] + /// will be used. + final TabController? controller; + + /// One widget per tab. + /// + /// Its length must match the length of the [TabBar.tabs] + /// list, as well as the [controller]'s [TabController.length]. + final List<Widget> children; + + /// How the page view should respond to user input. + /// + /// For example, determines how the page view continues to animate after the + /// user stops dragging the page view. + /// + /// The physics are modified to snap to page boundaries using + /// [PageScrollPhysics] prior to being used. + /// + /// Defaults to matching platform conventions. + final ScrollPhysics? physics; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@macro flutter.widgets.pageview.viewportFraction} + final double viewportFraction; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + @override + State<TabBarView> createState() => _TabBarViewState(); +} + +class _TabBarViewState extends State<TabBarView> { + TabController? _controller; + PageController? _pageController; + late List<Widget> _childrenWithKey; + int? _currentIndex; + int _warpUnderwayCount = 0; + int _scrollUnderwayCount = 0; + bool _debugHasScheduledValidChildrenCountCheck = false; + + // If the TabBarView is rebuilt with a new tab controller, the caller should + // dispose the old one. In that case the old controller's animation will be + // null and should not be accessed. + bool get _controllerIsValid => _controller?.animation != null; + + void _updateTabController() { + final TabController? newController = widget.controller ?? DefaultTabController.maybeOf(context); + assert(() { + if (newController == null) { + throw FlutterError( + 'No TabController for ${widget.runtimeType}.\n' + 'When creating a ${widget.runtimeType}, you must either provide an explicit ' + 'TabController using the "controller" property, or you must ensure that there ' + 'is a DefaultTabController above the ${widget.runtimeType}.\n' + 'In this case, there was neither an explicit controller nor a default controller.', + ); + } + return true; + }()); + + if (newController == _controller) { + return; + } + + if (_controllerIsValid) { + _controller!.animation!.removeListener(_handleTabControllerAnimationTick); + } + _controller = newController; + if (_controller != null) { + _controller!.animation!.addListener(_handleTabControllerAnimationTick); + } + } + + void _jumpToPage(int page) { + _warpUnderwayCount += 1; + _pageController!.jumpToPage(page); + _warpUnderwayCount -= 1; + } + + Future<void> _animateToPage( + int page, { + required Duration duration, + required Curve curve, + }) async { + _warpUnderwayCount += 1; + await _pageController!.animateToPage(page, duration: duration, curve: curve); + _warpUnderwayCount -= 1; + } + + @override + void initState() { + super.initState(); + _updateChildren(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _updateTabController(); + _currentIndex = _controller!.index; + if (_pageController == null) { + _pageController = PageController( + initialPage: _currentIndex!, + viewportFraction: widget.viewportFraction, + ); + } else { + _pageController!.jumpToPage(_currentIndex!); + } + } + + @override + void didUpdateWidget(TabBarView oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.controller != oldWidget.controller) { + _updateTabController(); + _currentIndex = _controller!.index; + _jumpToPage(_currentIndex!); + } + if (widget.viewportFraction != oldWidget.viewportFraction) { + _pageController?.dispose(); + _pageController = PageController( + initialPage: _currentIndex!, + viewportFraction: widget.viewportFraction, + ); + } + // While a warp is under way, we stop updating the tab page contents. + // This is tracked in https://github.com/flutter/flutter/issues/31269. + if (widget.children != oldWidget.children && _warpUnderwayCount == 0) { + _updateChildren(); + } + } + + @override + void dispose() { + if (_controllerIsValid) { + _controller!.animation!.removeListener(_handleTabControllerAnimationTick); + } + _controller = null; + _pageController?.dispose(); + // We don't own the _controller Animation, so it's not disposed here. + super.dispose(); + } + + void _updateChildren() { + _childrenWithKey = KeyedSubtree.ensureUniqueKeysForList(widget.children); + } + + void _handleTabControllerAnimationTick() { + if (_scrollUnderwayCount > 0 || !_controller!.indexIsChanging) { + return; + } // This widget is driving the controller's animation. + + if (_controller!.index != _currentIndex) { + _currentIndex = _controller!.index; + _warpToCurrentIndex(); + } + } + + void _warpToCurrentIndex() { + if (!mounted || _pageController!.page == _currentIndex!.toDouble()) { + return; + } + + final bool adjacentDestination = (_currentIndex! - _controller!.previousIndex).abs() == 1; + if (adjacentDestination) { + _warpToAdjacentTab(_controller!.animationDuration); + } else { + _warpToNonAdjacentTab(_controller!.animationDuration); + } + } + + Future<void> _warpToAdjacentTab(Duration duration) async { + if (duration == Duration.zero) { + _jumpToPage(_currentIndex!); + } else { + await _animateToPage(_currentIndex!, duration: duration, curve: Curves.ease); + } + if (mounted) { + setState(() { _updateChildren(); }); + } + return Future<void>.value(); + } + + Future<void> _warpToNonAdjacentTab(Duration duration) async { + final int previousIndex = _controller!.previousIndex; + assert((_currentIndex! - previousIndex).abs() > 1); + + // initialPage defines which page is shown when starting the animation. + // This page is adjacent to the destination page. + final int initialPage = _currentIndex! > previousIndex + ? _currentIndex! - 1 + : _currentIndex! + 1; + + setState(() { + // Needed for `RenderSliverMultiBoxAdaptor.move` and kept alive children. + // For motivation, see https://github.com/flutter/flutter/pull/29188 and + // https://github.com/flutter/flutter/issues/27010#issuecomment-486475152. + _childrenWithKey = List<Widget>.of(_childrenWithKey, growable: false); + final Widget temp = _childrenWithKey[initialPage]; + _childrenWithKey[initialPage] = _childrenWithKey[previousIndex]; + _childrenWithKey[previousIndex] = temp; + }); + + // Make a first jump to the adjacent page. + _jumpToPage(initialPage); + + // Jump or animate to the destination page. + if (duration == Duration.zero) { + _jumpToPage(_currentIndex!); + } else { + await _animateToPage(_currentIndex!, duration: duration, curve: Curves.ease); + } + + if (mounted) { + setState(() { _updateChildren(); }); + } + } + + void _syncControllerOffset() { + _controller!.offset = clampDouble(_pageController!.page! - _controller!.index, -1.0, 1.0); + } + + // Called when the PageView scrolls + bool _handleScrollNotification(ScrollNotification notification) { + if (_warpUnderwayCount > 0 || _scrollUnderwayCount > 0) { + return false; + } + + if (notification.depth != 0) { + return false; + } + + if (!_controllerIsValid) { + return false; + } + + _scrollUnderwayCount += 1; + final double page = _pageController!.page!; + if (notification is ScrollUpdateNotification && !_controller!.indexIsChanging) { + final bool pageChanged = (page - _controller!.index).abs() > 1.0; + if (pageChanged) { + _controller!.index = page.round(); + _currentIndex =_controller!.index; + } + _syncControllerOffset(); + } else if (notification is ScrollEndNotification) { + _controller!.index = page.round(); + _currentIndex = _controller!.index; + if (!_controller!.indexIsChanging) { + _syncControllerOffset(); + } + } + _scrollUnderwayCount -= 1; + + return false; + } + + bool _debugScheduleCheckHasValidChildrenCount() { + if (_debugHasScheduledValidChildrenCountCheck) { + return true; + } + WidgetsBinding.instance.addPostFrameCallback((Duration duration) { + _debugHasScheduledValidChildrenCountCheck = false; + if (!mounted) { + return; + } + assert(() { + if (_controller!.length != widget.children.length) { + throw FlutterError( + "Controller's length property (${_controller!.length}) does not match the " + "number of children (${widget.children.length}) present in TabBarView's children property.", + ); + } + return true; + }()); + }, debugLabel: 'TabBarView.validChildrenCountCheck'); + _debugHasScheduledValidChildrenCountCheck = true; + return true; + } + + @override + Widget build(BuildContext context) { + assert(_debugScheduleCheckHasValidChildrenCount()); + + return NotificationListener<ScrollNotification>( + onNotification: _handleScrollNotification, + child: PageView( + dragStartBehavior: widget.dragStartBehavior, + clipBehavior: widget.clipBehavior, + controller: _pageController, + physics: widget.physics == null + ? const PageScrollPhysics().applyTo(const ClampingScrollPhysics()) + : const PageScrollPhysics().applyTo(widget.physics), + children: _childrenWithKey, + ), + ); + } +} + +/// Displays a single circle with the specified size, border style, border color +/// and background colors. +/// +/// Used by [TabPageSelector] to indicate the selected page. +class TabPageSelectorIndicator extends StatelessWidget { + /// Creates an indicator used by [TabPageSelector]. + const TabPageSelectorIndicator({ + super.key, + required this.backgroundColor, + required this.borderColor, + required this.size, + this.borderStyle = BorderStyle.solid, + }); + + /// The indicator circle's background color. + final Color backgroundColor; + + /// The indicator circle's border color. + final Color borderColor; + + /// The indicator circle's diameter. + final double size; + + /// The indicator circle's border style. + /// + /// Defaults to [BorderStyle.solid] if value is not specified. + final BorderStyle borderStyle; + + @override + Widget build(BuildContext context) { + return Container( + width: size, + height: size, + margin: const EdgeInsets.all(4.0), + decoration: BoxDecoration( + color: backgroundColor, + border: Border.all(color: borderColor, style: borderStyle), + shape: BoxShape.circle, + ), + ); + } +} + +/// Uses [TabPageSelectorIndicator] to display a row of small circular +/// indicators, one per tab. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=Q628ue9Cq7U} +/// +/// The selected tab's indicator is highlighted. Often used in conjunction with +/// a [TabBarView]. +/// +/// If a [TabController] is not provided, then there must be a +/// [DefaultTabController] ancestor. +class TabPageSelector extends StatelessWidget { + /// Creates a compact widget that indicates which tab has been selected. + const TabPageSelector({ + super.key, + this.controller, + this.indicatorSize = 12.0, + this.color, + this.selectedColor, + this.borderStyle, + }) : assert(indicatorSize > 0.0); + + /// This widget's selection and animation state. + /// + /// If [TabController] is not provided, then the value of + /// [DefaultTabController.of] will be used. + final TabController? controller; + + /// The indicator circle's diameter (the default value is 12.0). + final double indicatorSize; + + /// The indicator circle's fill color for unselected pages. + /// + /// If this parameter is null, then the indicator is filled with [Colors.transparent]. + final Color? color; + + /// The indicator circle's fill color for selected pages and border color + /// for all indicator circles. + /// + /// If this parameter is null, then the indicator is filled with the theme's + /// [ColorScheme.secondary]. + final Color? selectedColor; + + /// The indicator circle's border style. + /// + /// Defaults to [BorderStyle.solid] if value is not specified. + final BorderStyle? borderStyle; + + Widget _buildTabIndicator( + int tabIndex, + TabController tabController, + ColorTween selectedColorTween, + ColorTween previousColorTween, + ) { + final Color background; + if (tabController.indexIsChanging) { + // The selection's animation is animating from previousValue to value. + final double t = 1.0 - _indexChangeProgress(tabController); + if (tabController.index == tabIndex) { + background = selectedColorTween.lerp(t)!; + } else if (tabController.previousIndex == tabIndex) { + background = previousColorTween.lerp(t)!; + } else { + background = selectedColorTween.begin!; + } + } else { + // The selection's offset reflects how far the TabBarView has / been dragged + // to the previous page (-1.0 to 0.0) or the next page (0.0 to 1.0). + final double offset = tabController.offset; + if (tabController.index == tabIndex) { + background = selectedColorTween.lerp(1.0 - offset.abs())!; + } else if (tabController.index == tabIndex - 1 && offset > 0.0) { + background = selectedColorTween.lerp(offset)!; + } else if (tabController.index == tabIndex + 1 && offset < 0.0) { + background = selectedColorTween.lerp(-offset)!; + } else { + background = selectedColorTween.begin!; + } + } + return TabPageSelectorIndicator( + backgroundColor: background, + borderColor: selectedColorTween.end!, + size: indicatorSize, + borderStyle: borderStyle ?? BorderStyle.solid, + ); + } + + @override + Widget build(BuildContext context) { + final Color fixColor = color ?? Colors.transparent; + final Color fixSelectedColor = selectedColor ?? Theme.of(context).colorScheme.secondary; + final ColorTween selectedColorTween = ColorTween(begin: fixColor, end: fixSelectedColor); + final ColorTween previousColorTween = ColorTween(begin: fixSelectedColor, end: fixColor); + final TabController? tabController = controller ?? DefaultTabController.maybeOf(context); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + assert(() { + if (tabController == null) { + throw FlutterError( + 'No TabController for $runtimeType.\n' + 'When creating a $runtimeType, you must either provide an explicit TabController ' + 'using the "controller" property, or you must ensure that there is a ' + 'DefaultTabController above the $runtimeType.\n' + 'In this case, there was neither an explicit controller nor a default controller.', + ); + } + return true; + }()); + final Animation<double> animation = CurvedAnimation( + parent: tabController!.animation!, + curve: Curves.fastOutSlowIn, + ); + return AnimatedBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + return Semantics( + label: localizations.tabLabel(tabIndex: tabController.index + 1, tabCount: tabController.length), + child: Row( + mainAxisSize: MainAxisSize.min, + children: List<Widget>.generate(tabController.length, (int tabIndex) { + return _buildTabIndicator(tabIndex, tabController, selectedColorTween, previousColorTween); + }).toList(), + ), + ); + }, + ); + } +} + +// Hand coded defaults based on Material Design 2. +class _TabsDefaultsM2 extends TabBarTheme { + const _TabsDefaultsM2(this.context, this.isScrollable) + : super(indicatorSize: TabBarIndicatorSize.tab); + + final BuildContext context; + final bool isScrollable; + + @override + Color? get indicatorColor => Theme.of(context).indicatorColor; + + @override + Color? get labelColor => Theme.of(context).primaryTextTheme.bodyLarge!.color!; + + @override + TextStyle? get labelStyle => Theme.of(context).primaryTextTheme.bodyLarge; + + @override + TextStyle? get unselectedLabelStyle => Theme.of(context).primaryTextTheme.bodyLarge; + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; + + @override + TabAlignment? get tabAlignment => isScrollable ? TabAlignment.start : TabAlignment.fill; +} + +// BEGIN GENERATED TOKEN PROPERTIES - Tabs + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _TabsPrimaryDefaultsM3 extends TabBarTheme { + _TabsPrimaryDefaultsM3(this.context, this.isScrollable) + : super(indicatorSize: TabBarIndicatorSize.label); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + final bool isScrollable; + + @override + Color? get dividerColor => _colors.surfaceVariant; + + @override + double? get dividerHeight => 1.0; + + @override + Color? get indicatorColor => _colors.primary; + + @override + Color? get labelColor => _colors.primary; + + @override + TextStyle? get labelStyle => _textTheme.titleSmall; + + @override + Color? get unselectedLabelColor => _colors.onSurfaceVariant; + + @override + TextStyle? get unselectedLabelStyle => _textTheme.titleSmall; + + @override + MaterialStateProperty<Color?> get overlayColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.primary.withOpacity(0.12); + } + return null; + } + if (states.contains(MaterialState.pressed)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface.withOpacity(0.12); + } + return null; + }); + } + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; + + @override + TabAlignment? get tabAlignment => isScrollable ? TabAlignment.startOffset : TabAlignment.fill; + + static double indicatorWeight = 3.0; +} + +class _TabsSecondaryDefaultsM3 extends TabBarTheme { + _TabsSecondaryDefaultsM3(this.context, this.isScrollable) + : super(indicatorSize: TabBarIndicatorSize.tab); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + final bool isScrollable; + + @override + Color? get dividerColor => _colors.surfaceVariant; + + @override + double? get dividerHeight => 1.0; + + @override + Color? get indicatorColor => _colors.primary; + + @override + Color? get labelColor => _colors.onSurface; + + @override + TextStyle? get labelStyle => _textTheme.titleSmall; + + @override + Color? get unselectedLabelColor => _colors.onSurfaceVariant; + + @override + TextStyle? get unselectedLabelStyle => _textTheme.titleSmall; + + @override + MaterialStateProperty<Color?> get overlayColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface.withOpacity(0.12); + } + return null; + } + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface.withOpacity(0.12); + } + return null; + }); + } + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; + + @override + TabAlignment? get tabAlignment => isScrollable ? TabAlignment.startOffset : TabAlignment.fill; +} + +// END GENERATED TOKEN PROPERTIES - Tabs diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..687e2a40e70ef4759dd53dd8c8a7959188bec06d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_button.dart @@ -0,0 +1,624 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'button_style_button.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'ink_ripple.dart'; +import 'ink_well.dart'; +import 'material_state.dart'; +import 'text_button_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; + +/// A Material Design "Text Button". +/// +/// Use text buttons on toolbars, in dialogs, or inline with other +/// content but offset from that content with padding so that the +/// button's presence is obvious. Text buttons do not have visible +/// borders and must therefore rely on their position relative to +/// other content for context. In dialogs and cards, they should be +/// grouped together in one of the bottom corners. Avoid using text +/// buttons where they would blend in with other content, for example +/// in the middle of lists. +/// +/// A text button is a label [child] displayed on a (zero elevation) +/// [Material] widget. The label's [Text] and [Icon] widgets are +/// displayed in the [style]'s [ButtonStyle.foregroundColor]. The +/// button reacts to touches by filling with the [style]'s +/// [ButtonStyle.backgroundColor]. +/// +/// The text button's default style is defined by [defaultStyleOf]. +/// The style of this text button can be overridden with its [style] +/// parameter. The style of all text buttons in a subtree can be +/// overridden with the [TextButtonTheme] and the style of all of the +/// text buttons in an app can be overridden with the [Theme]'s +/// [ThemeData.textButtonTheme] property. +/// +/// The static [styleFrom] method is a convenient way to create a +/// text button [ButtonStyle] from simple values. +/// +/// If the [onPressed] and [onLongPress] callbacks are null, then this +/// button will be disabled, it will not react to touch. +/// +/// {@tool dartpad} +/// This sample shows how to render a disabled TextButton, an enabled TextButton +/// and lastly a TextButton with gradient background. +/// +/// ** See code in examples/api/lib/material/text_button/text_button.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample demonstrates using the [statesController] parameter to create a button +/// that adds support for [MaterialState.selected]. +/// +/// ** See code in examples/api/lib/material/text_button/text_button.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ElevatedButton], a filled button whose material elevates when pressed. +/// * [FilledButton], a filled button that doesn't elevate when pressed. +/// * [FilledButton.tonal], a filled button variant that uses a secondary fill color. +/// * [OutlinedButton], a button with an outlined border and no fill color. +/// * <https://material.io/design/components/buttons.html> +/// * <https://m3.material.io/components/buttons> +class TextButton extends ButtonStyleButton { + /// Create a [TextButton]. + const TextButton({ + super.key, + required super.onPressed, + super.onLongPress, + super.onHover, + super.onFocusChange, + super.style, + super.focusNode, + super.autofocus = false, + super.clipBehavior = Clip.none, + super.statesController, + super.isSemanticButton, + required Widget super.child, + }); + + /// Create a text button from a pair of widgets that serve as the button's + /// [icon] and [label]. + /// + /// The icon and label are arranged in a row and padded by 8 logical pixels + /// at the ends, with an 8 pixel gap in between. + factory TextButton.icon({ + Key? key, + required VoidCallback? onPressed, + VoidCallback? onLongPress, + ValueChanged<bool>? onHover, + ValueChanged<bool>? onFocusChange, + ButtonStyle? style, + FocusNode? focusNode, + bool? autofocus, + Clip? clipBehavior, + MaterialStatesController? statesController, + required Widget icon, + required Widget label, + }) = _TextButtonWithIcon; + + /// A static convenience method that constructs a text button + /// [ButtonStyle] given simple values. + /// + /// The [foregroundColor] and [disabledForegroundColor] colors are used + /// to create a [MaterialStateProperty] [ButtonStyle.foregroundColor], and + /// a derived [ButtonStyle.overlayColor]. + /// + /// The [backgroundColor] and [disabledBackgroundColor] colors are + /// used to create a [MaterialStateProperty] [ButtonStyle.backgroundColor]. + /// + /// Similarly, the [enabledMouseCursor] and [disabledMouseCursor] + /// parameters are used to construct [ButtonStyle.mouseCursor]. + /// + /// All of the other parameters are either used directly or used to + /// create a [MaterialStateProperty] with a single value for all + /// states. + /// + /// All parameters default to null. By default this method returns + /// a [ButtonStyle] that doesn't override anything. + /// + /// For example, to override the default text and icon colors for a + /// [TextButton], as well as its overlay color, with all of the + /// standard opacity adjustments for the pressed, focused, and + /// hovered states, one could write: + /// + /// ```dart + /// TextButton( + /// style: TextButton.styleFrom(foregroundColor: Colors.green), + /// child: const Text('Give Kate a mix tape'), + /// onPressed: () { + /// // ... + /// }, + /// ), + /// ``` + static ButtonStyle styleFrom({ + Color? foregroundColor, + Color? backgroundColor, + Color? disabledForegroundColor, + Color? disabledBackgroundColor, + Color? shadowColor, + Color? surfaceTintColor, + Color? iconColor, + Color? disabledIconColor, + double? elevation, + TextStyle? textStyle, + EdgeInsetsGeometry? padding, + Size? minimumSize, + Size? fixedSize, + Size? maximumSize, + BorderSide? side, + OutlinedBorder? shape, + MouseCursor? enabledMouseCursor, + MouseCursor? disabledMouseCursor, + VisualDensity? visualDensity, + MaterialTapTargetSize? tapTargetSize, + Duration? animationDuration, + bool? enableFeedback, + AlignmentGeometry? alignment, + InteractiveInkFeatureFactory? splashFactory, + }) { + final Color? foreground = foregroundColor; + final Color? disabledForeground = disabledForegroundColor; + final MaterialStateProperty<Color?>? foregroundColorProp = (foreground == null && disabledForeground == null) + ? null + : _TextButtonDefaultColor(foreground, disabledForeground); + final MaterialStateProperty<Color?>? backgroundColorProp = (backgroundColor == null && disabledBackgroundColor == null) + ? null + : disabledBackgroundColor == null + ? ButtonStyleButton.allOrNull<Color?>(backgroundColor) + : _TextButtonDefaultColor(backgroundColor, disabledBackgroundColor); + final MaterialStateProperty<Color?>? overlayColor = (foreground == null) + ? null + : _TextButtonDefaultOverlay(foreground); + final MaterialStateProperty<Color?>? iconColorProp = (iconColor == null && disabledIconColor == null) + ? null + : disabledIconColor == null + ? ButtonStyleButton.allOrNull<Color?>(iconColor) + : _TextButtonDefaultIconColor(iconColor, disabledIconColor); + final MaterialStateProperty<MouseCursor?> mouseCursor = _TextButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor); + + return ButtonStyle( + textStyle: ButtonStyleButton.allOrNull<TextStyle>(textStyle), + foregroundColor: foregroundColorProp, + backgroundColor: backgroundColorProp, + overlayColor: overlayColor, + shadowColor: ButtonStyleButton.allOrNull<Color>(shadowColor), + surfaceTintColor: ButtonStyleButton.allOrNull<Color>(surfaceTintColor), + iconColor: iconColorProp, + elevation: ButtonStyleButton.allOrNull<double>(elevation), + padding: ButtonStyleButton.allOrNull<EdgeInsetsGeometry>(padding), + minimumSize: ButtonStyleButton.allOrNull<Size>(minimumSize), + fixedSize: ButtonStyleButton.allOrNull<Size>(fixedSize), + maximumSize: ButtonStyleButton.allOrNull<Size>(maximumSize), + side: ButtonStyleButton.allOrNull<BorderSide>(side), + shape: ButtonStyleButton.allOrNull<OutlinedBorder>(shape), + mouseCursor: mouseCursor, + visualDensity: visualDensity, + tapTargetSize: tapTargetSize, + animationDuration: animationDuration, + enableFeedback: enableFeedback, + alignment: alignment, + splashFactory: splashFactory, + ); + } + + /// Defines the button's default appearance. + /// + /// {@template flutter.material.text_button.default_style_of} + /// The button [child]'s [Text] and [Icon] widgets are rendered with + /// the [ButtonStyle]'s foreground color. The button's [InkWell] adds + /// the style's overlay color when the button is focused, hovered + /// or pressed. The button's background color becomes its [Material] + /// color and is transparent by default. + /// + /// All of the [ButtonStyle]'s defaults appear below. + /// + /// In this list "Theme.foo" is shorthand for + /// `Theme.of(context).foo`. Color scheme values like + /// "onSurface(0.38)" are shorthand for + /// `onSurface.withOpacity(0.38)`. [MaterialStateProperty] valued + /// properties that are not followed by a sublist have the same + /// value for all states, otherwise the values are as specified for + /// each state and "others" means all other states. + /// + /// The "default font size" below refers to the font size specified in the + /// [defaultStyleOf] method (or 14.0 if unspecified), scaled by the + /// `MediaQuery.textScalerOf(context).scale` method. And the names of the + /// EdgeInsets constructors and `EdgeInsetsGeometry.lerp` have been abbreviated + /// for readability. + /// + /// The color of the [ButtonStyle.textStyle] is not used, the + /// [ButtonStyle.foregroundColor] color is used instead. + /// {@endtemplate} + /// + /// ## Material 2 defaults + /// + /// * `textStyle` - Theme.textTheme.button + /// * `backgroundColor` - transparent + /// * `foregroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.38) + /// * others - Theme.colorScheme.primary + /// * `overlayColor` + /// * hovered - Theme.colorScheme.primary(0.04) + /// * focused or pressed - Theme.colorScheme.primary(0.12) + /// * `shadowColor` - Theme.shadowColor + /// * `elevation` - 0 + /// * `padding` + /// * `default font size <= 14` - (horizontal(12), vertical(8)) + /// * `14 < default font size <= 28` - lerp(all(8), horizontal(8)) + /// * `28 < default font size <= 36` - lerp(horizontal(8), horizontal(4)) + /// * `36 < default font size` - horizontal(4) + /// * `minimumSize` - Size(64, 36) + /// * `fixedSize` - null + /// * `maximumSize` - Size.infinite + /// * `side` - null + /// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)) + /// * `mouseCursor` + /// * disabled - SystemMouseCursors.basic + /// * others - SystemMouseCursors.click + /// * `visualDensity` - theme.visualDensity + /// * `tapTargetSize` - theme.materialTapTargetSize + /// * `animationDuration` - kThemeChangeDuration + /// * `enableFeedback` - true + /// * `alignment` - Alignment.center + /// * `splashFactory` - InkRipple.splashFactory + /// + /// The default padding values for the [TextButton.icon] factory are slightly different: + /// + /// * `padding` + /// * `default font size <= 14` - all(8) + /// * `14 < default font size <= 28 `- lerp(all(8), horizontal(4)) + /// * `28 < default font size` - horizontal(4) + /// + /// The default value for `side`, which defines the appearance of the button's + /// outline, is null. That means that the outline is defined by the button + /// shape's [OutlinedBorder.side]. Typically the default value of an + /// [OutlinedBorder]'s side is [BorderSide.none], so an outline is not drawn. + /// + /// ## Material 3 defaults + /// + /// If [ThemeData.useMaterial3] is set to true the following defaults will + /// be used: + /// + /// {@template flutter.material.text_button.material3_defaults} + /// * `textStyle` - Theme.textTheme.labelLarge + /// * `backgroundColor` - transparent + /// * `foregroundColor` + /// * disabled - Theme.colorScheme.onSurface(0.38) + /// * others - Theme.colorScheme.primary + /// * `overlayColor` + /// * hovered - Theme.colorScheme.primary(0.08) + /// * focused or pressed - Theme.colorScheme.primary(0.12) + /// * others - null + /// * `shadowColor` - Colors.transparent, + /// * `surfaceTintColor` - null + /// * `elevation` - 0 + /// * `padding` + /// * `default font size <= 14` - lerp(horizontal(12), horizontal(4)) + /// * `14 < default font size <= 28` - lerp(all(8), horizontal(8)) + /// * `28 < default font size <= 36` - lerp(horizontal(8), horizontal(4)) + /// * `36 < default font size` - horizontal(4) + /// * `minimumSize` - Size(64, 40) + /// * `fixedSize` - null + /// * `maximumSize` - Size.infinite + /// * `side` - null + /// * `shape` - StadiumBorder() + /// * `mouseCursor` + /// * disabled - SystemMouseCursors.basic + /// * others - SystemMouseCursors.click + /// * `visualDensity` - theme.visualDensity + /// * `tapTargetSize` - theme.materialTapTargetSize + /// * `animationDuration` - kThemeChangeDuration + /// * `enableFeedback` - true + /// * `alignment` - Alignment.center + /// * `splashFactory` - Theme.splashFactory + /// + /// For the [TextButton.icon] factory, the end (generally the right) value of + /// [padding] is increased from 12 to 16. + /// {@endtemplate} + @override + ButtonStyle defaultStyleOf(BuildContext context) { + final ThemeData theme = Theme.of(context); + final ColorScheme colorScheme = theme.colorScheme; + + return Theme.of(context).useMaterial3 + ? _TextButtonDefaultsM3(context) + : styleFrom( + foregroundColor: colorScheme.primary, + disabledForegroundColor: colorScheme.onSurface.withOpacity(0.38), + backgroundColor: Colors.transparent, + disabledBackgroundColor: Colors.transparent, + shadowColor: theme.shadowColor, + elevation: 0, + textStyle: theme.textTheme.labelLarge, + padding: _scaledPadding(context), + minimumSize: const Size(64, 36), + maximumSize: Size.infinite, + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))), + enabledMouseCursor: SystemMouseCursors.click, + disabledMouseCursor: SystemMouseCursors.basic, + visualDensity: theme.visualDensity, + tapTargetSize: theme.materialTapTargetSize, + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + splashFactory: InkRipple.splashFactory, + ); + } + + /// Returns the [TextButtonThemeData.style] of the closest + /// [TextButtonTheme] ancestor. + @override + ButtonStyle? themeStyleOf(BuildContext context) { + return TextButtonTheme.of(context).style; + } +} + +EdgeInsetsGeometry _scaledPadding(BuildContext context) { + final ThemeData theme = Theme.of(context); + final double defaultFontSize = theme.textTheme.labelLarge?.fontSize ?? 14.0; + final double effectiveTextScale = MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0; + return ButtonStyleButton.scaledPadding( + theme.useMaterial3 ? const EdgeInsets.symmetric(horizontal: 12, vertical: 8) : const EdgeInsets.all(8), + const EdgeInsets.symmetric(horizontal: 8), + const EdgeInsets.symmetric(horizontal: 4), + effectiveTextScale, + ); +} + +@immutable +class _TextButtonDefaultColor extends MaterialStateProperty<Color?> { + _TextButtonDefaultColor(this.color, this.disabled); + + final Color? color; + final Color? disabled; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabled; + } + return color; + } + + @override + String toString() { + return '{disabled: $disabled, otherwise: $color}'; + } +} + +@immutable +class _TextButtonDefaultOverlay extends MaterialStateProperty<Color?> { + _TextButtonDefaultOverlay(this.primary); + + final Color primary; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return primary.withOpacity(0.04); + } + if (states.contains(MaterialState.focused)) { + return primary.withOpacity(0.12); + } + return null; + } + + @override + String toString() { + return '{hovered: ${primary.withOpacity(0.04)}, focused,pressed: ${primary.withOpacity(0.12)}, otherwise: null}'; + } +} + +@immutable +class _TextButtonDefaultIconColor extends MaterialStateProperty<Color?> { + _TextButtonDefaultIconColor(this.iconColor, this.disabledIconColor); + + final Color? iconColor; + final Color? disabledIconColor; + + @override + Color? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabledIconColor; + } + return iconColor; + } + + @override + String toString() { + return '{disabled: $disabledIconColor, color: $iconColor}'; + } +} + +@immutable +class _TextButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor?> with Diagnosticable { + _TextButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor); + + final MouseCursor? enabledCursor; + final MouseCursor? disabledCursor; + + @override + MouseCursor? resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return disabledCursor; + } + return enabledCursor; + } +} + +class _TextButtonWithIcon extends TextButton { + _TextButtonWithIcon({ + super.key, + required super.onPressed, + super.onLongPress, + super.onHover, + super.onFocusChange, + super.style, + super.focusNode, + bool? autofocus, + Clip? clipBehavior, + super.statesController, + required Widget icon, + required Widget label, + }) : super( + autofocus: autofocus ?? false, + clipBehavior: clipBehavior ?? Clip.none, + child: _TextButtonWithIconChild(icon: icon, label: label), + ); + + @override + ButtonStyle defaultStyleOf(BuildContext context) { + final bool useMaterial3 = Theme.of(context).useMaterial3; + final ButtonStyle buttonStyle = super.defaultStyleOf(context); + final double defaultFontSize = buttonStyle.textStyle?.resolve(const <MaterialState>{})?.fontSize ?? 14.0; + final double effectiveTextScale = MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0; + final EdgeInsetsGeometry scaledPadding = ButtonStyleButton.scaledPadding( + useMaterial3 ? const EdgeInsetsDirectional.fromSTEB(12, 8, 16, 8) : const EdgeInsets.all(8), + const EdgeInsets.symmetric(horizontal: 4), + const EdgeInsets.symmetric(horizontal: 4), + effectiveTextScale, + ); + return buttonStyle.copyWith( + padding: MaterialStatePropertyAll<EdgeInsetsGeometry>(scaledPadding), + ); + } +} + +class _TextButtonWithIconChild extends StatelessWidget { + const _TextButtonWithIconChild({ + required this.label, + required this.icon, + }); + + final Widget label; + final Widget icon; + + @override + Widget build(BuildContext context) { + final double scale = MediaQuery.textScalerOf(context).textScaleFactor; + final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!; + return Row( + mainAxisSize: MainAxisSize.min, + children: <Widget>[icon, SizedBox(width: gap), Flexible(child: label)], + ); + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - TextButton + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _TextButtonDefaultsM3 extends ButtonStyle { + _TextButtonDefaultsM3(this.context) + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + ); + + final BuildContext context; + late final ColorScheme _colors = Theme.of(context).colorScheme; + + @override + MaterialStateProperty<TextStyle?> get textStyle => + MaterialStatePropertyAll<TextStyle?>(Theme.of(context).textTheme.labelLarge); + + @override + MaterialStateProperty<Color?>? get backgroundColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<Color?>? get foregroundColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return _colors.onSurface.withOpacity(0.38); + } + return _colors.primary; + }); + + @override + MaterialStateProperty<Color?>? get overlayColor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.pressed)) { + return _colors.primary.withOpacity(0.12); + } + if (states.contains(MaterialState.hovered)) { + return _colors.primary.withOpacity(0.08); + } + if (states.contains(MaterialState.focused)) { + return _colors.primary.withOpacity(0.12); + } + return null; + }); + + @override + MaterialStateProperty<Color>? get shadowColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<Color>? get surfaceTintColor => + const MaterialStatePropertyAll<Color>(Colors.transparent); + + @override + MaterialStateProperty<double>? get elevation => + const MaterialStatePropertyAll<double>(0.0); + + @override + MaterialStateProperty<EdgeInsetsGeometry>? get padding => + MaterialStatePropertyAll<EdgeInsetsGeometry>(_scaledPadding(context)); + + @override + MaterialStateProperty<Size>? get minimumSize => + const MaterialStatePropertyAll<Size>(Size(64.0, 40.0)); + + // No default fixedSize + + @override + MaterialStateProperty<Size>? get maximumSize => + const MaterialStatePropertyAll<Size>(Size.infinite); + + // No default side + + @override + MaterialStateProperty<OutlinedBorder>? get shape => + const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); + + @override + MaterialStateProperty<MouseCursor?>? get mouseCursor => + MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.basic; + } + return SystemMouseCursors.click; + }); + + @override + VisualDensity? get visualDensity => Theme.of(context).visualDensity; + + @override + MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize; + + @override + InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory; +} + +// END GENERATED TOKEN PROPERTIES - TextButton diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_button_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_button_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..79a2f4016385de5e9d9c48cabb1fc0db00c18a65 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_button_theme.dart @@ -0,0 +1,125 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// A [ButtonStyle] that overrides the default appearance of +/// [TextButton]s when it's used with [TextButtonTheme] or with the +/// overall [Theme]'s [ThemeData.textButtonTheme]. +/// +/// The [style]'s properties override [TextButton]'s default style, +/// i.e. the [ButtonStyle] returned by [TextButton.defaultStyleOf]. Only +/// the style's non-null property values or resolved non-null +/// [MaterialStateProperty] values are used. +/// +/// See also: +/// +/// * [TextButtonTheme], the theme which is configured with this class. +/// * [TextButton.defaultStyleOf], which returns the default [ButtonStyle] +/// for text buttons. +/// * [TextButton.styleFrom], which converts simple values into a +/// [ButtonStyle] that's consistent with [TextButton]'s defaults. +/// * [MaterialStateProperty.resolve], "resolve" a material state property +/// to a simple value based on a set of [MaterialState]s. +/// * [ThemeData.textButtonTheme], which can be used to override the default +/// [ButtonStyle] for [TextButton]s below the overall [Theme]. +@immutable +class TextButtonThemeData with Diagnosticable { + /// Creates a [TextButtonThemeData]. + /// + /// The [style] may be null. + const TextButtonThemeData({ this.style }); + + /// Overrides for [TextButton]'s default style. + /// + /// Non-null properties or non-null resolved [MaterialStateProperty] + /// values override the [ButtonStyle] returned by + /// [TextButton.defaultStyleOf]. + /// + /// If [style] is null, then this theme doesn't override anything. + final ButtonStyle? style; + + /// Linearly interpolate between two text button themes. + static TextButtonThemeData? lerp(TextButtonThemeData? a, TextButtonThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return TextButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + ); + } + + @override + int get hashCode => style.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is TextButtonThemeData && other.style == style; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ButtonStyle>('style', style, defaultValue: null)); + } +} + +/// Overrides the default [ButtonStyle] of its [TextButton] descendants. +/// +/// See also: +/// +/// * [TextButtonThemeData], which is used to configure this theme. +/// * [TextButton.defaultStyleOf], which returns the default [ButtonStyle] +/// for text buttons. +/// * [TextButton.styleFrom], which converts simple values into a +/// [ButtonStyle] that's consistent with [TextButton]'s defaults. +/// * [ThemeData.textButtonTheme], which can be used to override the default +/// [ButtonStyle] for [TextButton]s below the overall [Theme]. +class TextButtonTheme extends InheritedTheme { + /// Create a [TextButtonTheme]. + const TextButtonTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The configuration of this theme. + final TextButtonThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [TextButtonTheme] widget, then + /// [ThemeData.textButtonTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// TextButtonThemeData theme = TextButtonTheme.of(context); + /// ``` + static TextButtonThemeData of(BuildContext context) { + final TextButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<TextButtonTheme>(); + return buttonTheme?.data ?? Theme.of(context).textButtonTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return TextButtonTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(TextButtonTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_field.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_field.dart new file mode 100644 index 0000000000000000000000000000000000000000..e1942cd7f97423b265e6af402f933bdb5be3ccf7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_field.dart @@ -0,0 +1,1627 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; + +import 'adaptive_text_selection_toolbar.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'debug.dart'; +import 'desktop_text_selection.dart'; +import 'feedback.dart'; +import 'input_decorator.dart'; +import 'magnifier.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'selectable_text.dart' show iOSHorizontalOffset; +import 'spell_check_suggestions_toolbar.dart'; +import 'text_selection.dart'; +import 'theme.dart'; + +export 'package:flutter/services.dart' show SmartDashesType, SmartQuotesType, TextCapitalization, TextInputAction, TextInputType; + +// Examples can assume: +// late BuildContext context; +// late FocusNode myFocusNode; + +/// Signature for the [TextField.buildCounter] callback. +typedef InputCounterWidgetBuilder = Widget? Function( + /// The build context for the TextField. + BuildContext context, { + /// The length of the string currently in the input. + required int currentLength, + /// The maximum string length that can be entered into the TextField. + required int? maxLength, + /// Whether or not the TextField is currently focused. Mainly provided for + /// the [liveRegion] parameter in the [Semantics] widget for accessibility. + required bool isFocused, +}); + +class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDetectorBuilder { + _TextFieldSelectionGestureDetectorBuilder({ + required _TextFieldState state, + }) : _state = state, + super(delegate: state); + + final _TextFieldState _state; + + @override + void onForcePressStart(ForcePressDetails details) { + super.onForcePressStart(details); + if (delegate.selectionEnabled && shouldShowSelectionToolbar) { + editableText.showToolbar(); + } + } + + @override + void onForcePressEnd(ForcePressDetails details) { + // Not required. + } + + @override + void onSingleTapUp(TapDragUpDetails details) { + super.onSingleTapUp(details); + _state._requestKeyboard(); + } + + @override + bool get onUserTapAlwaysCalled => _state.widget.onTapAlwaysCalled; + + @override + void onUserTap() { + _state.widget.onTap?.call(); + } + + @override + void onSingleLongTapStart(LongPressStartDetails details) { + super.onSingleLongTapStart(details); + if (delegate.selectionEnabled) { + switch (Theme.of(_state.context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + break; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + Feedback.forLongPress(_state.context); + } + } + } +} + +/// A Material Design text field. +/// +/// A text field lets the user enter text, either with hardware keyboard or with +/// an onscreen keyboard. +/// +/// The text field calls the [onChanged] callback whenever the user changes the +/// text in the field. If the user indicates that they are done typing in the +/// field (e.g., by pressing a button on the soft keyboard), the text field +/// calls the [onSubmitted] callback. +/// +/// To control the text that is displayed in the text field, use the +/// [controller]. For example, to set the initial value of the text field, use +/// a [controller] that already contains some text. The [controller] can also +/// control the selection and composing region (and to observe changes to the +/// text, selection, and composing region). +/// +/// By default, a text field has a [decoration] that draws a divider below the +/// text field. You can use the [decoration] property to control the decoration, +/// for example by adding a label or an icon. If you set the [decoration] +/// property to null, the decoration will be removed entirely, including the +/// extra padding introduced by the decoration to save space for the labels. +/// +/// If [decoration] is non-null (which is the default), the text field requires +/// one of its ancestors to be a [Material] widget. +/// +/// To integrate the [TextField] into a [Form] with other [FormField] widgets, +/// consider using [TextFormField]. +/// +/// {@template flutter.material.textfield.wantKeepAlive} +/// When the widget has focus, it will prevent itself from disposing via its +/// underlying [EditableText]'s [AutomaticKeepAliveClientMixin.wantKeepAlive] in +/// order to avoid losing the selection. Removing the focus will allow it to be +/// disposed. +/// {@endtemplate} +/// +/// Remember to call [TextEditingController.dispose] of the [TextEditingController] +/// when it is no longer needed. This will ensure we discard any resources used +/// by the object. +/// +/// ## Obscured Input +/// +/// {@tool dartpad} +/// This example shows how to create a [TextField] that will obscure input. The +/// [InputDecoration] surrounds the field in a border using [OutlineInputBorder] +/// and adds a label. +/// +/// ** See code in examples/api/lib/material/text_field/text_field.0.dart ** +/// {@end-tool} +/// +/// ## Reading values +/// +/// A common way to read a value from a TextField is to use the [onSubmitted] +/// callback. This callback is applied to the text field's current value when +/// the user finishes editing. +/// +/// {@tool dartpad} +/// This sample shows how to get a value from a TextField via the [onSubmitted] +/// callback. +/// +/// ** See code in examples/api/lib/material/text_field/text_field.1.dart ** +/// {@end-tool} +/// +/// {@macro flutter.widgets.EditableText.lifeCycle} +/// +/// For most applications the [onSubmitted] callback will be sufficient for +/// reacting to user input. +/// +/// The [onEditingComplete] callback also runs when the user finishes editing. +/// It's different from [onSubmitted] because it has a default value which +/// updates the text controller and yields the keyboard focus. Applications that +/// require different behavior can override the default [onEditingComplete] +/// callback. +/// +/// Keep in mind you can also always read the current string from a TextField's +/// [TextEditingController] using [TextEditingController.text]. +/// +/// ## Handling emojis and other complex characters +/// {@macro flutter.widgets.EditableText.onChanged} +/// +/// In the live Dartpad example above, try typing the emoji 👨‍👩‍👦 +/// into the field and submitting. Because the example code measures the length +/// with `value.characters.length`, the emoji is correctly counted as a single +/// character. +/// +/// {@macro flutter.widgets.editableText.showCaretOnScreen} +/// +/// {@macro flutter.widgets.editableText.accessibility} +/// +/// {@tool dartpad} +/// This sample shows how to style a text field to match a filled or outlined +/// Material Design 3 text field. +/// +/// ** See code in examples/api/lib/material/text_field/text_field.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [TextFormField], which integrates with the [Form] widget. +/// * [InputDecorator], which shows the labels and other visual elements that +/// surround the actual text editing widget. +/// * [EditableText], which is the raw text editing control at the heart of a +/// [TextField]. The [EditableText] widget is rarely used directly unless +/// you are implementing an entirely different design language, such as +/// Cupertino. +/// * <https://material.io/design/components/text-fields.html> +/// * Cookbook: [Create and style a text field](https://flutter.dev/docs/cookbook/forms/text-input) +/// * Cookbook: [Handle changes to a text field](https://flutter.dev/docs/cookbook/forms/text-field-changes) +/// * Cookbook: [Retrieve the value of a text field](https://flutter.dev/docs/cookbook/forms/retrieve-input) +/// * Cookbook: [Focus and text fields](https://flutter.dev/docs/cookbook/forms/focus) +class TextField extends StatefulWidget { + /// Creates a Material Design text field. + /// + /// If [decoration] is non-null (which is the default), the text field requires + /// one of its ancestors to be a [Material] widget. + /// + /// To remove the decoration entirely (including the extra padding introduced + /// by the decoration to save space for the labels), set the [decoration] to + /// null. + /// + /// The [maxLines] property can be set to null to remove the restriction on + /// the number of lines. By default, it is one, meaning this is a single-line + /// text field. [maxLines] must not be zero. + /// + /// The [maxLength] property is set to null by default, which means the + /// number of characters allowed in the text field is not restricted. If + /// [maxLength] is set a character counter will be displayed below the + /// field showing how many characters have been entered. If the value is + /// set to a positive integer it will also display the maximum allowed + /// number of characters to be entered. If the value is set to + /// [TextField.noMaxLength] then only the current length is displayed. + /// + /// After [maxLength] characters have been input, additional input + /// is ignored, unless [maxLengthEnforcement] is set to + /// [MaxLengthEnforcement.none]. + /// The text field enforces the length with a [LengthLimitingTextInputFormatter], + /// which is evaluated after the supplied [inputFormatters], if any. + /// The [maxLength] value must be either null or greater than zero. + /// + /// If [maxLengthEnforcement] is set to [MaxLengthEnforcement.none], then more + /// than [maxLength] characters may be entered, and the error counter and + /// divider will switch to the [decoration].errorStyle when the limit is + /// exceeded. + /// + /// The text cursor is not shown if [showCursor] is false or if [showCursor] + /// is null (the default) and [readOnly] is true. + /// + /// The [selectionHeightStyle] and [selectionWidthStyle] properties allow + /// changing the shape of the selection highlighting. These properties default + /// to [ui.BoxHeightStyle.tight] and [ui.BoxWidthStyle.tight], respectively. + /// + /// See also: + /// + /// * [maxLength], which discusses the precise meaning of "number of + /// characters" and how it may differ from the intuitive meaning. + const TextField({ + super.key, + this.controller, + this.focusNode, + this.undoController, + this.decoration = const InputDecoration(), + TextInputType? keyboardType, + this.textInputAction, + this.textCapitalization = TextCapitalization.none, + this.style, + this.strutStyle, + this.textAlign = TextAlign.start, + this.textAlignVertical, + this.textDirection, + this.readOnly = false, + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + this.toolbarOptions, + this.showCursor, + this.autofocus = false, + this.statesController, + this.obscuringCharacter = '•', + this.obscureText = false, + this.autocorrect = true, + SmartDashesType? smartDashesType, + SmartQuotesType? smartQuotesType, + this.enableSuggestions = true, + this.maxLines = 1, + this.minLines, + this.expands = false, + this.maxLength, + this.maxLengthEnforcement, + this.onChanged, + this.onEditingComplete, + this.onSubmitted, + this.onAppPrivateCommand, + this.inputFormatters, + this.enabled, + this.cursorWidth = 2.0, + this.cursorHeight, + this.cursorRadius, + this.cursorOpacityAnimates, + this.cursorColor, + this.cursorErrorColor, + this.selectionHeightStyle = ui.BoxHeightStyle.tight, + this.selectionWidthStyle = ui.BoxWidthStyle.tight, + this.keyboardAppearance, + this.scrollPadding = const EdgeInsets.all(20.0), + this.dragStartBehavior = DragStartBehavior.start, + bool? enableInteractiveSelection, + this.selectionControls, + this.onTap, + this.onTapAlwaysCalled = false, + this.onTapOutside, + this.mouseCursor, + this.buildCounter, + this.scrollController, + this.scrollPhysics, + this.autofillHints = const <String>[], + this.contentInsertionConfiguration, + this.clipBehavior = Clip.hardEdge, + this.restorationId, + this.scribbleEnabled = true, + this.enableIMEPersonalizedLearning = true, + this.contextMenuBuilder = _defaultContextMenuBuilder, + this.canRequestFocus = true, + this.spellCheckConfiguration, + this.magnifierConfiguration, + }) : assert(obscuringCharacter.length == 1), + smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), + smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), + assert(maxLines == null || maxLines > 0), + assert(minLines == null || minLines > 0), + assert( + (maxLines == null) || (minLines == null) || (maxLines >= minLines), + "minLines can't be greater than maxLines", + ), + assert( + !expands || (maxLines == null && minLines == null), + 'minLines and maxLines must be null when expands is true.', + ), + assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'), + assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0), + // Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set. + assert( + !identical(textInputAction, TextInputAction.newline) || + maxLines == 1 || + !identical(keyboardType, TextInputType.text), + 'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.', + ), + keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline), + enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText); + + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.intro} + /// + /// {@macro flutter.widgets.magnifier.intro} + /// + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.details} + /// + /// By default, builds a [CupertinoTextMagnifier] on iOS and [TextMagnifier] + /// on Android, and builds nothing on all other platforms. If it is desired to + /// suppress the magnifier, consider passing [TextMagnifierConfiguration.disabled]. + /// + /// {@tool dartpad} + /// This sample demonstrates how to customize the magnifier that this text field uses. + /// + /// ** See code in examples/api/lib/widgets/text_magnifier/text_magnifier.0.dart ** + /// {@end-tool} + final TextMagnifierConfiguration? magnifierConfiguration; + + /// Controls the text being edited. + /// + /// If null, this widget will create its own [TextEditingController]. + final TextEditingController? controller; + + /// Defines the keyboard focus for this widget. + /// + /// The [focusNode] is a long-lived object that's typically managed by a + /// [StatefulWidget] parent. See [FocusNode] for more information. + /// + /// To give the keyboard focus to this widget, provide a [focusNode] and then + /// use the current [FocusScope] to request the focus: + /// + /// ```dart + /// FocusScope.of(context).requestFocus(myFocusNode); + /// ``` + /// + /// This happens automatically when the widget is tapped. + /// + /// To be notified when the widget gains or loses the focus, add a listener + /// to the [focusNode]: + /// + /// ```dart + /// myFocusNode.addListener(() { print(myFocusNode.hasFocus); }); + /// ``` + /// + /// If null, this widget will create its own [FocusNode]. + /// + /// ## Keyboard + /// + /// Requesting the focus will typically cause the keyboard to be shown + /// if it's not showing already. + /// + /// On Android, the user can hide the keyboard - without changing the focus - + /// with the system back button. They can restore the keyboard's visibility + /// by tapping on a text field. The user might hide the keyboard and + /// switch to a physical keyboard, or they might just need to get it + /// out of the way for a moment, to expose something it's + /// obscuring. In this case requesting the focus again will not + /// cause the focus to change, and will not make the keyboard visible. + /// + /// This widget builds an [EditableText] and will ensure that the keyboard is + /// showing when it is tapped by calling [EditableTextState.requestKeyboard()]. + final FocusNode? focusNode; + + /// The decoration to show around the text field. + /// + /// By default, draws a horizontal line under the text field but can be + /// configured to show an icon, label, hint text, and error text. + /// + /// Specify null to remove the decoration entirely (including the + /// extra padding introduced by the decoration to save space for the labels). + final InputDecoration? decoration; + + /// {@macro flutter.widgets.editableText.keyboardType} + final TextInputType keyboardType; + + /// {@template flutter.widgets.TextField.textInputAction} + /// The type of action button to use for the keyboard. + /// + /// Defaults to [TextInputAction.newline] if [keyboardType] is + /// [TextInputType.multiline] and [TextInputAction.done] otherwise. + /// {@endtemplate} + final TextInputAction? textInputAction; + + /// {@macro flutter.widgets.editableText.textCapitalization} + final TextCapitalization textCapitalization; + + /// The style to use for the text being edited. + /// + /// This text style is also used as the base style for the [decoration]. + /// + /// If null, [TextTheme.bodyLarge] will be used. When the text field is disabled, + /// [TextTheme.bodyLarge] with an opacity of 0.38 will be used instead. + /// + /// If null and [ThemeData.useMaterial3] is false, [TextTheme.titleMedium] will + /// be used. When the text field is disabled, [TextTheme.titleMedium] with + /// [ThemeData.disabledColor] will be used instead. + final TextStyle? style; + + /// {@macro flutter.widgets.editableText.strutStyle} + final StrutStyle? strutStyle; + + /// {@macro flutter.widgets.editableText.textAlign} + final TextAlign textAlign; + + /// {@macro flutter.material.InputDecorator.textAlignVertical} + final TextAlignVertical? textAlignVertical; + + /// {@macro flutter.widgets.editableText.textDirection} + final TextDirection? textDirection; + + /// {@macro flutter.widgets.editableText.autofocus} + final bool autofocus; + + /// Represents the interactive "state" of this widget in terms of a set of + /// [MaterialState]s, including [MaterialState.disabled], [MaterialState.hovered], + /// [MaterialState.error], and [MaterialState.focused]. + /// + /// Classes based on this one can provide their own + /// [MaterialStatesController] to which they've added listeners. + /// They can also update the controller's [MaterialStatesController.value] + /// however, this may only be done when it's safe to call + /// [State.setState], like in an event handler. + /// + /// The controller's [MaterialStatesController.value] represents the set of + /// states that a widget's visual properties, typically [MaterialStateProperty] + /// values, are resolved against. It is _not_ the intrinsic state of the widget. + /// The widget is responsible for ensuring that the controller's + /// [MaterialStatesController.value] tracks its intrinsic state. For example + /// one cannot request the keyboard focus for a widget by adding [MaterialState.focused] + /// to its controller. When the widget gains the or loses the focus it will + /// [MaterialStatesController.update] its controller's [MaterialStatesController.value] + /// and notify listeners of the change. + final MaterialStatesController? statesController; + + /// {@macro flutter.widgets.editableText.obscuringCharacter} + final String obscuringCharacter; + + /// {@macro flutter.widgets.editableText.obscureText} + final bool obscureText; + + /// {@macro flutter.widgets.editableText.autocorrect} + final bool autocorrect; + + /// {@macro flutter.services.TextInputConfiguration.smartDashesType} + final SmartDashesType smartDashesType; + + /// {@macro flutter.services.TextInputConfiguration.smartQuotesType} + final SmartQuotesType smartQuotesType; + + /// {@macro flutter.services.TextInputConfiguration.enableSuggestions} + final bool enableSuggestions; + + /// {@macro flutter.widgets.editableText.maxLines} + /// * [expands], which determines whether the field should fill the height of + /// its parent. + final int? maxLines; + + /// {@macro flutter.widgets.editableText.minLines} + /// * [expands], which determines whether the field should fill the height of + /// its parent. + final int? minLines; + + /// {@macro flutter.widgets.editableText.expands} + final bool expands; + + /// {@macro flutter.widgets.editableText.readOnly} + final bool readOnly; + + /// Configuration of toolbar options. + /// + /// If not set, select all and paste will default to be enabled. Copy and cut + /// will be disabled if [obscureText] is true. If [readOnly] is true, + /// paste and cut will be disabled regardless. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + final ToolbarOptions? toolbarOptions; + + /// {@macro flutter.widgets.editableText.showCursor} + final bool? showCursor; + + /// If [maxLength] is set to this value, only the "current input length" + /// part of the character counter is shown. + static const int noMaxLength = -1; + + /// The maximum number of characters (Unicode grapheme clusters) to allow in + /// the text field. + /// + /// If set, a character counter will be displayed below the + /// field showing how many characters have been entered. If set to a number + /// greater than 0, it will also display the maximum number allowed. If set + /// to [TextField.noMaxLength] then only the current character count is displayed. + /// + /// After [maxLength] characters have been input, additional input + /// is ignored, unless [maxLengthEnforcement] is set to + /// [MaxLengthEnforcement.none]. + /// + /// The text field enforces the length with a [LengthLimitingTextInputFormatter], + /// which is evaluated after the supplied [inputFormatters], if any. + /// + /// This value must be either null, [TextField.noMaxLength], or greater than 0. + /// If null (the default) then there is no limit to the number of characters + /// that can be entered. If set to [TextField.noMaxLength], then no limit will + /// be enforced, but the number of characters entered will still be displayed. + /// + /// Whitespace characters (e.g. newline, space, tab) are included in the + /// character count. + /// + /// If [maxLengthEnforcement] is [MaxLengthEnforcement.none], then more than + /// [maxLength] characters may be entered, but the error counter and divider + /// will switch to the [decoration]'s [InputDecoration.errorStyle] when the + /// limit is exceeded. + /// + /// {@macro flutter.services.lengthLimitingTextInputFormatter.maxLength} + final int? maxLength; + + /// Determines how the [maxLength] limit should be enforced. + /// + /// {@macro flutter.services.textFormatter.effectiveMaxLengthEnforcement} + /// + /// {@macro flutter.services.textFormatter.maxLengthEnforcement} + final MaxLengthEnforcement? maxLengthEnforcement; + + /// {@macro flutter.widgets.editableText.onChanged} + /// + /// See also: + /// + /// * [inputFormatters], which are called before [onChanged] + /// runs and can validate and change ("format") the input value. + /// * [onEditingComplete], [onSubmitted]: + /// which are more specialized input change notifications. + final ValueChanged<String>? onChanged; + + /// {@macro flutter.widgets.editableText.onEditingComplete} + final VoidCallback? onEditingComplete; + + /// {@macro flutter.widgets.editableText.onSubmitted} + /// + /// See also: + /// + /// * [TextInputAction.next] and [TextInputAction.previous], which + /// automatically shift the focus to the next/previous focusable item when + /// the user is done editing. + final ValueChanged<String>? onSubmitted; + + /// {@macro flutter.widgets.editableText.onAppPrivateCommand} + final AppPrivateCommandCallback? onAppPrivateCommand; + + /// {@macro flutter.widgets.editableText.inputFormatters} + final List<TextInputFormatter>? inputFormatters; + + /// If false the text field is "disabled": it ignores taps and its + /// [decoration] is rendered in grey. + /// + /// If non-null this property overrides the [decoration]'s + /// [InputDecoration.enabled] property. + final bool? enabled; + + /// {@macro flutter.widgets.editableText.cursorWidth} + final double cursorWidth; + + /// {@macro flutter.widgets.editableText.cursorHeight} + final double? cursorHeight; + + /// {@macro flutter.widgets.editableText.cursorRadius} + final Radius? cursorRadius; + + /// {@macro flutter.widgets.editableText.cursorOpacityAnimates} + final bool? cursorOpacityAnimates; + + /// The color of the cursor. + /// + /// The cursor indicates the current location of text insertion point in + /// the field. + /// + /// If this is null it will default to the ambient + /// [DefaultSelectionStyle.cursorColor]. If that is null, and the + /// [ThemeData.platform] is [TargetPlatform.iOS] or [TargetPlatform.macOS] + /// it will use [CupertinoThemeData.primaryColor]. Otherwise it will use + /// the value of [ColorScheme.primary] of [ThemeData.colorScheme]. + final Color? cursorColor; + + /// The color of the cursor when the [InputDecorator] is showing an error. + /// + /// If this is null it will default to [TextStyle.color] of + /// [InputDecoration.errorStyle]. If that is null, it will use + /// [ColorScheme.error] of [ThemeData.colorScheme]. + final Color? cursorErrorColor; + + /// Controls how tall the selection highlight boxes are computed to be. + /// + /// See [ui.BoxHeightStyle] for details on available styles. + final ui.BoxHeightStyle selectionHeightStyle; + + /// Controls how wide the selection highlight boxes are computed to be. + /// + /// See [ui.BoxWidthStyle] for details on available styles. + final ui.BoxWidthStyle selectionWidthStyle; + + /// The appearance of the keyboard. + /// + /// This setting is only honored on iOS devices. + /// + /// If unset, defaults to [ThemeData.brightness]. + final Brightness? keyboardAppearance; + + /// {@macro flutter.widgets.editableText.scrollPadding} + final EdgeInsets scrollPadding; + + /// {@macro flutter.widgets.editableText.enableInteractiveSelection} + final bool enableInteractiveSelection; + + /// {@macro flutter.widgets.editableText.selectionControls} + final TextSelectionControls? selectionControls; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@macro flutter.widgets.editableText.selectionEnabled} + bool get selectionEnabled => enableInteractiveSelection; + + /// {@template flutter.material.textfield.onTap} + /// Called for the first tap in a series of taps. + /// + /// The text field builds a [GestureDetector] to handle input events like tap, + /// to trigger focus requests, to move the caret, adjust the selection, etc. + /// Handling some of those events by wrapping the text field with a competing + /// GestureDetector is problematic. + /// + /// To unconditionally handle taps, without interfering with the text field's + /// internal gesture detector, provide this callback. + /// + /// If the text field is created with [enabled] false, taps will not be + /// recognized. + /// + /// To be notified when the text field gains or loses the focus, provide a + /// [focusNode] and add a listener to that. + /// + /// To listen to arbitrary pointer events without competing with the + /// text field's internal gesture detector, use a [Listener]. + /// {@endtemplate} + /// + /// If [onTapAlwaysCalled] is enabled, this will also be called for consecutive + /// taps. + final GestureTapCallback? onTap; + + /// Whether [onTap] should be called for every tap. + /// + /// Defaults to false, so [onTap] is only called for each distinct tap. When + /// enabled, [onTap] is called for every tap including consecutive taps. + final bool onTapAlwaysCalled; + + /// {@macro flutter.widgets.editableText.onTapOutside} + /// + /// {@tool dartpad} + /// This example shows how to use a `TextFieldTapRegion` to wrap a set of + /// "spinner" buttons that increment and decrement a value in the [TextField] + /// without causing the text field to lose keyboard focus. + /// + /// This example includes a generic `SpinnerField<T>` class that you can copy + /// into your own project and customize. + /// + /// ** See code in examples/api/lib/widgets/tap_region/text_field_tap_region.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [TapRegion] for how the region group is determined. + final TapRegionCallback? onTapOutside; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>], + /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s: + /// + /// * [MaterialState.error]. + /// * [MaterialState.hovered]. + /// * [MaterialState.focused]. + /// * [MaterialState.disabled]. + /// + /// If this property is null, [MaterialStateMouseCursor.textable] will be used. + /// + /// The [mouseCursor] is the only property of [TextField] that controls the + /// appearance of the mouse pointer. All other properties related to "cursor" + /// stand for the text cursor, which is usually a blinking vertical line at + /// the editing position. + final MouseCursor? mouseCursor; + + /// Callback that generates a custom [InputDecoration.counter] widget. + /// + /// See [InputCounterWidgetBuilder] for an explanation of the passed in + /// arguments. The returned widget will be placed below the line in place of + /// the default widget built when [InputDecoration.counterText] is specified. + /// + /// The returned widget will be wrapped in a [Semantics] widget for + /// accessibility, but it also needs to be accessible itself. For example, + /// if returning a Text widget, set the [Text.semanticsLabel] property. + /// + /// {@tool snippet} + /// ```dart + /// Widget counter( + /// BuildContext context, + /// { + /// required int currentLength, + /// required int? maxLength, + /// required bool isFocused, + /// } + /// ) { + /// return Text( + /// '$currentLength of $maxLength characters', + /// semanticsLabel: 'character count', + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// If buildCounter returns null, then no counter and no Semantics widget will + /// be created at all. + final InputCounterWidgetBuilder? buildCounter; + + /// {@macro flutter.widgets.editableText.scrollPhysics} + final ScrollPhysics? scrollPhysics; + + /// {@macro flutter.widgets.editableText.scrollController} + final ScrollController? scrollController; + + /// {@macro flutter.widgets.editableText.autofillHints} + /// {@macro flutter.services.AutofillConfiguration.autofillHints} + final Iterable<String>? autofillHints; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// {@template flutter.material.textfield.restorationId} + /// Restoration ID to save and restore the state of the text field. + /// + /// If non-null, the text field will persist and restore its current scroll + /// offset and - if no [controller] has been provided - the content of the + /// text field. If a [controller] has been provided, it is the responsibility + /// of the owner of that controller to persist and restore it, e.g. by using + /// a [RestorableTextEditingController]. + /// + /// The state of this widget is persisted in a [RestorationBucket] claimed + /// from the surrounding [RestorationScope] using the provided restoration ID. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + /// {@endtemplate} + final String? restorationId; + + /// {@macro flutter.widgets.editableText.scribbleEnabled} + final bool scribbleEnabled; + + /// {@macro flutter.services.TextInputConfiguration.enableIMEPersonalizedLearning} + final bool enableIMEPersonalizedLearning; + + /// {@macro flutter.widgets.editableText.contentInsertionConfiguration} + final ContentInsertionConfiguration? contentInsertionConfiguration; + + /// {@macro flutter.widgets.EditableText.contextMenuBuilder} + /// + /// If not provided, will build a default menu based on the platform. + /// + /// See also: + /// + /// * [AdaptiveTextSelectionToolbar], which is built by default. + final EditableTextContextMenuBuilder? contextMenuBuilder; + + /// Determine whether this text field can request the primary focus. + /// + /// Defaults to true. If false, the text field will not request focus + /// when tapped, or when its context menu is displayed. If false it will not + /// be possible to move the focus to the text field with tab key. + final bool canRequestFocus; + + /// {@macro flutter.widgets.undoHistory.controller} + final UndoHistoryController? undoController; + + static Widget _defaultContextMenuBuilder(BuildContext context, EditableTextState editableTextState) { + return AdaptiveTextSelectionToolbar.editableText( + editableTextState: editableTextState, + ); + } + + /// {@macro flutter.widgets.EditableText.spellCheckConfiguration} + /// + /// If [SpellCheckConfiguration.misspelledTextStyle] is not specified in this + /// configuration, then [materialMisspelledTextStyle] is used by default. + final SpellCheckConfiguration? spellCheckConfiguration; + + /// The [TextStyle] used to indicate misspelled words in the Material style. + /// + /// See also: + /// * [SpellCheckConfiguration.misspelledTextStyle], the style configured to + /// mark misspelled words with. + /// * [CupertinoTextField.cupertinoMisspelledTextStyle], the style configured + /// to mark misspelled words with in the Cupertino style. + static const TextStyle materialMisspelledTextStyle = + TextStyle( + decoration: TextDecoration.underline, + decorationColor: Colors.red, + decorationStyle: TextDecorationStyle.wavy, + ); + + /// Default builder for [TextField]'s spell check suggestions toolbar. + /// + /// On Apple platforms, builds an iOS-style toolbar. Everywhere else, builds + /// an Android-style toolbar. + /// + /// See also: + /// * [spellCheckConfiguration], where this is typically specified for + /// [TextField]. + /// * [SpellCheckConfiguration.spellCheckSuggestionsToolbarBuilder], the + /// parameter for which this is the default value for [TextField]. + /// * [CupertinoTextField.defaultSpellCheckSuggestionsToolbarBuilder], which + /// is like this but specifies the default for [CupertinoTextField]. + @visibleForTesting + static Widget defaultSpellCheckSuggestionsToolbarBuilder( + BuildContext context, + EditableTextState editableTextState, + ) { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return CupertinoSpellCheckSuggestionsToolbar.editableText( + editableTextState: editableTextState, + ); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return SpellCheckSuggestionsToolbar.editableText( + editableTextState: editableTextState, + ); + } + } + + /// Returns a new [SpellCheckConfiguration] where the given configuration has + /// had any missing values replaced with their defaults for the Android + /// platform. + static SpellCheckConfiguration inferAndroidSpellCheckConfiguration( + SpellCheckConfiguration? configuration, + ) { + if (configuration == null + || configuration == const SpellCheckConfiguration.disabled()) { + return const SpellCheckConfiguration.disabled(); + } + return configuration.copyWith( + misspelledTextStyle: configuration.misspelledTextStyle + ?? TextField.materialMisspelledTextStyle, + spellCheckSuggestionsToolbarBuilder: + configuration.spellCheckSuggestionsToolbarBuilder + ?? TextField.defaultSpellCheckSuggestionsToolbarBuilder, + ); + } + + @override + State<TextField> createState() => _TextFieldState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<TextEditingController>('controller', controller, defaultValue: null)); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null)); + properties.add(DiagnosticsProperty<UndoHistoryController>('undoController', undoController, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('enabled', enabled, defaultValue: null)); + properties.add(DiagnosticsProperty<InputDecoration>('decoration', decoration, defaultValue: const InputDecoration())); + properties.add(DiagnosticsProperty<TextInputType>('keyboardType', keyboardType, defaultValue: TextInputType.text)); + properties.add(DiagnosticsProperty<TextStyle>('style', style, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('autofocus', autofocus, defaultValue: false)); + properties.add(DiagnosticsProperty<String>('obscuringCharacter', obscuringCharacter, defaultValue: '•')); + properties.add(DiagnosticsProperty<bool>('obscureText', obscureText, defaultValue: false)); + properties.add(DiagnosticsProperty<bool>('autocorrect', autocorrect, defaultValue: true)); + properties.add(EnumProperty<SmartDashesType>('smartDashesType', smartDashesType, defaultValue: obscureText ? SmartDashesType.disabled : SmartDashesType.enabled)); + properties.add(EnumProperty<SmartQuotesType>('smartQuotesType', smartQuotesType, defaultValue: obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled)); + properties.add(DiagnosticsProperty<bool>('enableSuggestions', enableSuggestions, defaultValue: true)); + properties.add(IntProperty('maxLines', maxLines, defaultValue: 1)); + properties.add(IntProperty('minLines', minLines, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false)); + properties.add(IntProperty('maxLength', maxLength, defaultValue: null)); + properties.add(EnumProperty<MaxLengthEnforcement>('maxLengthEnforcement', maxLengthEnforcement, defaultValue: null)); + properties.add(EnumProperty<TextInputAction>('textInputAction', textInputAction, defaultValue: null)); + properties.add(EnumProperty<TextCapitalization>('textCapitalization', textCapitalization, defaultValue: TextCapitalization.none)); + properties.add(EnumProperty<TextAlign>('textAlign', textAlign, defaultValue: TextAlign.start)); + properties.add(DiagnosticsProperty<TextAlignVertical>('textAlignVertical', textAlignVertical, defaultValue: null)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0)); + properties.add(DoubleProperty('cursorHeight', cursorHeight, defaultValue: null)); + properties.add(DiagnosticsProperty<Radius>('cursorRadius', cursorRadius, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('cursorOpacityAnimates', cursorOpacityAnimates, defaultValue: null)); + properties.add(ColorProperty('cursorColor', cursorColor, defaultValue: null)); + properties.add(ColorProperty('cursorErrorColor', cursorErrorColor, defaultValue: null)); + properties.add(DiagnosticsProperty<Brightness>('keyboardAppearance', keyboardAppearance, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('scrollPadding', scrollPadding, defaultValue: const EdgeInsets.all(20.0))); + properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); + properties.add(DiagnosticsProperty<TextSelectionControls>('selectionControls', selectionControls, defaultValue: null)); + properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null)); + properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null)); + properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior, defaultValue: Clip.hardEdge)); + properties.add(DiagnosticsProperty<bool>('scribbleEnabled', scribbleEnabled, defaultValue: true)); + properties.add(DiagnosticsProperty<bool>('enableIMEPersonalizedLearning', enableIMEPersonalizedLearning, defaultValue: true)); + properties.add(DiagnosticsProperty<SpellCheckConfiguration>('spellCheckConfiguration', spellCheckConfiguration, defaultValue: null)); + properties.add(DiagnosticsProperty<List<String>>('contentCommitMimeTypes', contentInsertionConfiguration?.allowedMimeTypes ?? const <String>[], defaultValue: contentInsertionConfiguration == null ? const <String>[] : kDefaultContentInsertionMimeTypes)); + } +} + +class _TextFieldState extends State<TextField> with RestorationMixin implements TextSelectionGestureDetectorBuilderDelegate, AutofillClient { + RestorableTextEditingController? _controller; + TextEditingController get _effectiveController => widget.controller ?? _controller!.value; + + FocusNode? _focusNode; + FocusNode get _effectiveFocusNode => widget.focusNode ?? (_focusNode ??= FocusNode()); + + MaxLengthEnforcement get _effectiveMaxLengthEnforcement => widget.maxLengthEnforcement + ?? LengthLimitingTextInputFormatter.getDefaultMaxLengthEnforcement(Theme.of(context).platform); + + bool _isHovering = false; + + bool get needsCounter => widget.maxLength != null + && widget.decoration != null + && widget.decoration!.counterText == null; + + bool _showSelectionHandles = false; + + late _TextFieldSelectionGestureDetectorBuilder _selectionGestureDetectorBuilder; + + // API for TextSelectionGestureDetectorBuilderDelegate. + @override + late bool forcePressEnabled; + + @override + final GlobalKey<EditableTextState> editableTextKey = GlobalKey<EditableTextState>(); + + @override + bool get selectionEnabled => widget.selectionEnabled; + // End of API for TextSelectionGestureDetectorBuilderDelegate. + + bool get _isEnabled => widget.enabled ?? widget.decoration?.enabled ?? true; + + int get _currentLength => _effectiveController.value.text.characters.length; + + bool get _hasIntrinsicError => widget.maxLength != null && + widget.maxLength! > 0 && + (widget.controller == null ? + !restorePending && _effectiveController.value.text.characters.length > widget.maxLength! : + _effectiveController.value.text.characters.length > widget.maxLength!); + + bool get _hasError => widget.decoration?.errorText != null || widget.decoration?.error != null || _hasIntrinsicError; + + Color get _errorColor => widget.cursorErrorColor ?? widget.decoration?.errorStyle?.color ?? Theme.of(context).colorScheme.error; + + InputDecoration _getEffectiveDecoration() { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final ThemeData themeData = Theme.of(context); + final InputDecoration effectiveDecoration = (widget.decoration ?? const InputDecoration()) + .applyDefaults(themeData.inputDecorationTheme) + .copyWith( + enabled: _isEnabled, + hintMaxLines: widget.decoration?.hintMaxLines ?? widget.maxLines, + ); + + // No need to build anything if counter or counterText were given directly. + if (effectiveDecoration.counter != null || effectiveDecoration.counterText != null) { + return effectiveDecoration; + } + + // If buildCounter was provided, use it to generate a counter widget. + Widget? counter; + final int currentLength = _currentLength; + if (effectiveDecoration.counter == null + && effectiveDecoration.counterText == null + && widget.buildCounter != null) { + final bool isFocused = _effectiveFocusNode.hasFocus; + final Widget? builtCounter = widget.buildCounter!( + context, + currentLength: currentLength, + maxLength: widget.maxLength, + isFocused: isFocused, + ); + // If buildCounter returns null, don't add a counter widget to the field. + if (builtCounter != null) { + counter = Semantics( + container: true, + liveRegion: isFocused, + child: builtCounter, + ); + } + return effectiveDecoration.copyWith(counter: counter); + } + + if (widget.maxLength == null) { + return effectiveDecoration; + } // No counter widget + + String counterText = '$currentLength'; + String semanticCounterText = ''; + + // Handle a real maxLength (positive number) + if (widget.maxLength! > 0) { + // Show the maxLength in the counter + counterText += '/${widget.maxLength}'; + final int remaining = (widget.maxLength! - currentLength).clamp(0, widget.maxLength!); + semanticCounterText = localizations.remainingTextFieldCharacterCount(remaining); + } + + if (_hasIntrinsicError) { + return effectiveDecoration.copyWith( + errorText: effectiveDecoration.errorText ?? '', + counterStyle: effectiveDecoration.errorStyle + ?? (themeData.useMaterial3 ? _m3CounterErrorStyle(context): _m2CounterErrorStyle(context)), + counterText: counterText, + semanticCounterText: semanticCounterText, + ); + } + + return effectiveDecoration.copyWith( + counterText: counterText, + semanticCounterText: semanticCounterText, + ); + } + + @override + void initState() { + super.initState(); + _selectionGestureDetectorBuilder = _TextFieldSelectionGestureDetectorBuilder(state: this); + if (widget.controller == null) { + _createLocalController(); + } + _effectiveFocusNode.canRequestFocus = widget.canRequestFocus && _isEnabled; + _effectiveFocusNode.addListener(_handleFocusChanged); + _initStatesController(); + } + + bool get _canRequestFocus { + final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional; + switch (mode) { + case NavigationMode.traditional: + return widget.canRequestFocus && _isEnabled; + case NavigationMode.directional: + return true; + } + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _effectiveFocusNode.canRequestFocus = _canRequestFocus; + } + + @override + void didUpdateWidget(TextField oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.controller == null && oldWidget.controller != null) { + _createLocalController(oldWidget.controller!.value); + } else if (widget.controller != null && oldWidget.controller == null) { + unregisterFromRestoration(_controller!); + _controller!.dispose(); + _controller = null; + } + + if (widget.focusNode != oldWidget.focusNode) { + (oldWidget.focusNode ?? _focusNode)?.removeListener(_handleFocusChanged); + (widget.focusNode ?? _focusNode)?.addListener(_handleFocusChanged); + } + + _effectiveFocusNode.canRequestFocus = _canRequestFocus; + + if (_effectiveFocusNode.hasFocus && widget.readOnly != oldWidget.readOnly && _isEnabled) { + if (_effectiveController.selection.isCollapsed) { + _showSelectionHandles = !widget.readOnly; + } + } + + if (widget.statesController == oldWidget.statesController) { + _statesController.update(MaterialState.disabled, !_isEnabled); + _statesController.update(MaterialState.hovered, _isHovering); + _statesController.update(MaterialState.focused, _effectiveFocusNode.hasFocus); + _statesController.update(MaterialState.error, _hasError); + } else { + oldWidget.statesController?.removeListener(_handleStatesControllerChange); + if (widget.statesController != null) { + _internalStatesController?.dispose(); + _internalStatesController = null; + } + _initStatesController(); + } + } + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + if (_controller != null) { + _registerController(); + } + } + + void _registerController() { + assert(_controller != null); + registerForRestoration(_controller!, 'controller'); + } + + void _createLocalController([TextEditingValue? value]) { + assert(_controller == null); + _controller = value == null + ? RestorableTextEditingController() + : RestorableTextEditingController.fromValue(value); + if (!restorePending) { + _registerController(); + } + } + + @override + String? get restorationId => widget.restorationId; + + @override + void dispose() { + _effectiveFocusNode.removeListener(_handleFocusChanged); + _focusNode?.dispose(); + _controller?.dispose(); + _statesController.removeListener(_handleStatesControllerChange); + _internalStatesController?.dispose(); + super.dispose(); + } + + EditableTextState? get _editableText => editableTextKey.currentState; + + void _requestKeyboard() { + _editableText?.requestKeyboard(); + } + + bool _shouldShowSelectionHandles(SelectionChangedCause? cause) { + // When the text field is activated by something that doesn't trigger the + // selection overlay, we shouldn't show the handles either. + if (!_selectionGestureDetectorBuilder.shouldShowSelectionToolbar) { + return false; + } + + if (cause == SelectionChangedCause.keyboard) { + return false; + } + + if (widget.readOnly && _effectiveController.selection.isCollapsed) { + return false; + } + + if (!_isEnabled) { + return false; + } + + if (cause == SelectionChangedCause.longPress || cause == SelectionChangedCause.scribble) { + return true; + } + + if (_effectiveController.text.isNotEmpty) { + return true; + } + + return false; + } + + void _handleFocusChanged() { + setState(() { + // Rebuild the widget on focus change to show/hide the text selection + // highlight. + }); + _statesController.update(MaterialState.focused, _effectiveFocusNode.hasFocus); + } + + void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) { + final bool willShowSelectionHandles = _shouldShowSelectionHandles(cause); + if (willShowSelectionHandles != _showSelectionHandles) { + setState(() { + _showSelectionHandles = willShowSelectionHandles; + }); + } + + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + case TargetPlatform.fuchsia: + case TargetPlatform.android: + if (cause == SelectionChangedCause.longPress) { + _editableText?.bringIntoView(selection.extent); + } + } + + switch (Theme.of(context).platform) { + case TargetPlatform.iOS: + case TargetPlatform.fuchsia: + case TargetPlatform.android: + break; + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + if (cause == SelectionChangedCause.drag) { + _editableText?.hideToolbar(); + } + } + } + + /// Toggle the toolbar when a selection handle is tapped. + void _handleSelectionHandleTapped() { + if (_effectiveController.selection.isCollapsed) { + _editableText!.toggleToolbar(); + } + } + + void _handleHover(bool hovering) { + if (hovering != _isHovering) { + setState(() { + _isHovering = hovering; + }); + _statesController.update(MaterialState.hovered, _isHovering); + } + } + + // Material states controller. + MaterialStatesController? _internalStatesController; + + void _handleStatesControllerChange() { + // Force a rebuild to resolve MaterialStateProperty properties. + setState(() { }); + } + + MaterialStatesController get _statesController => widget.statesController ?? _internalStatesController!; + + void _initStatesController() { + if (widget.statesController == null) { + _internalStatesController = MaterialStatesController(); + } + _statesController.update(MaterialState.disabled, !_isEnabled); + _statesController.update(MaterialState.hovered, _isHovering); + _statesController.update(MaterialState.focused, _effectiveFocusNode.hasFocus); + _statesController.update(MaterialState.error, _hasError); + _statesController.addListener(_handleStatesControllerChange); + } + + // AutofillClient implementation start. + @override + String get autofillId => _editableText!.autofillId; + + @override + void autofill(TextEditingValue newEditingValue) => _editableText!.autofill(newEditingValue); + + @override + TextInputConfiguration get textInputConfiguration { + final List<String>? autofillHints = widget.autofillHints?.toList(growable: false); + final AutofillConfiguration autofillConfiguration = autofillHints != null + ? AutofillConfiguration( + uniqueIdentifier: autofillId, + autofillHints: autofillHints, + currentEditingValue: _effectiveController.value, + hintText: (widget.decoration ?? const InputDecoration()).hintText, + ) + : AutofillConfiguration.disabled; + + return _editableText!.textInputConfiguration.copyWith(autofillConfiguration: autofillConfiguration); + } + // AutofillClient implementation end. + + TextStyle _getInputStyleForState(TextStyle style) { + final ThemeData theme = Theme.of(context); + final TextStyle stateStyle = MaterialStateProperty.resolveAs(theme.useMaterial3 ? _m3StateInputStyle(context)! : _m2StateInputStyle(context)!, _statesController.value); + final TextStyle providedStyle = MaterialStateProperty.resolveAs(style, _statesController.value); + return providedStyle.merge(stateStyle); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMaterialLocalizations(context)); + assert(debugCheckHasDirectionality(context)); + assert( + !(widget.style != null && !widget.style!.inherit && + (widget.style!.fontSize == null || widget.style!.textBaseline == null)), + 'inherit false style must supply fontSize and textBaseline', + ); + + final ThemeData theme = Theme.of(context); + final DefaultSelectionStyle selectionStyle = DefaultSelectionStyle.of(context); + final TextStyle? providedStyle = MaterialStateProperty.resolveAs(widget.style, _statesController.value); + final TextStyle style = _getInputStyleForState(theme.useMaterial3 ? _m3InputStyle(context) : theme.textTheme.titleMedium!).merge(providedStyle); + final Brightness keyboardAppearance = widget.keyboardAppearance ?? theme.brightness; + final TextEditingController controller = _effectiveController; + final FocusNode focusNode = _effectiveFocusNode; + final List<TextInputFormatter> formatters = <TextInputFormatter>[ + ...?widget.inputFormatters, + if (widget.maxLength != null) + LengthLimitingTextInputFormatter( + widget.maxLength, + maxLengthEnforcement: _effectiveMaxLengthEnforcement, + ), + ]; + + // Set configuration as disabled if not otherwise specified. If specified, + // ensure that configuration uses the correct style for misspelled words for + // the current platform, unless a custom style is specified. + final SpellCheckConfiguration spellCheckConfiguration; + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + spellCheckConfiguration = + CupertinoTextField.inferIOSSpellCheckConfiguration( + widget.spellCheckConfiguration, + ); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + spellCheckConfiguration = TextField.inferAndroidSpellCheckConfiguration( + widget.spellCheckConfiguration, + ); + } + + TextSelectionControls? textSelectionControls = widget.selectionControls; + final bool paintCursorAboveText; + bool? cursorOpacityAnimates = widget.cursorOpacityAnimates; + Offset? cursorOffset; + final Color cursorColor; + final Color selectionColor; + Color? autocorrectionTextRectColor; + Radius? cursorRadius = widget.cursorRadius; + VoidCallback? handleDidGainAccessibilityFocus; + VoidCallback? handleDidLoseAccessibilityFocus; + + switch (theme.platform) { + case TargetPlatform.iOS: + final CupertinoThemeData cupertinoTheme = CupertinoTheme.of(context); + forcePressEnabled = true; + textSelectionControls ??= cupertinoTextSelectionHandleControls; + paintCursorAboveText = true; + cursorOpacityAnimates ??= true; + cursorColor = _hasError ? _errorColor : widget.cursorColor ?? selectionStyle.cursorColor ?? cupertinoTheme.primaryColor; + selectionColor = selectionStyle.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40); + cursorRadius ??= const Radius.circular(2.0); + cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.devicePixelRatioOf(context), 0); + autocorrectionTextRectColor = selectionColor; + + case TargetPlatform.macOS: + final CupertinoThemeData cupertinoTheme = CupertinoTheme.of(context); + forcePressEnabled = false; + textSelectionControls ??= cupertinoDesktopTextSelectionHandleControls; + paintCursorAboveText = true; + cursorOpacityAnimates ??= false; + cursorColor = _hasError ? _errorColor : widget.cursorColor ?? selectionStyle.cursorColor ?? cupertinoTheme.primaryColor; + selectionColor = selectionStyle.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40); + cursorRadius ??= const Radius.circular(2.0); + cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.devicePixelRatioOf(context), 0); + handleDidGainAccessibilityFocus = () { + // Automatically activate the TextField when it receives accessibility focus. + if (!_effectiveFocusNode.hasFocus && _effectiveFocusNode.canRequestFocus) { + _effectiveFocusNode.requestFocus(); + } + }; + handleDidLoseAccessibilityFocus = () { + _effectiveFocusNode.unfocus(); + }; + + case TargetPlatform.android: + case TargetPlatform.fuchsia: + forcePressEnabled = false; + textSelectionControls ??= materialTextSelectionHandleControls; + paintCursorAboveText = false; + cursorOpacityAnimates ??= false; + cursorColor = _hasError ? _errorColor : widget.cursorColor ?? selectionStyle.cursorColor ?? theme.colorScheme.primary; + selectionColor = selectionStyle.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40); + + case TargetPlatform.linux: + forcePressEnabled = false; + textSelectionControls ??= desktopTextSelectionHandleControls; + paintCursorAboveText = false; + cursorOpacityAnimates ??= false; + cursorColor = _hasError ? _errorColor : widget.cursorColor ?? selectionStyle.cursorColor ?? theme.colorScheme.primary; + selectionColor = selectionStyle.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40); + handleDidGainAccessibilityFocus = () { + // Automatically activate the TextField when it receives accessibility focus. + if (!_effectiveFocusNode.hasFocus && _effectiveFocusNode.canRequestFocus) { + _effectiveFocusNode.requestFocus(); + } + }; + handleDidLoseAccessibilityFocus = () { + _effectiveFocusNode.unfocus(); + }; + + case TargetPlatform.windows: + forcePressEnabled = false; + textSelectionControls ??= desktopTextSelectionHandleControls; + paintCursorAboveText = false; + cursorOpacityAnimates ??= false; + cursorColor = _hasError ? _errorColor : widget.cursorColor ?? selectionStyle.cursorColor ?? theme.colorScheme.primary; + selectionColor = selectionStyle.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40); + handleDidGainAccessibilityFocus = () { + // Automatically activate the TextField when it receives accessibility focus. + if (!_effectiveFocusNode.hasFocus && _effectiveFocusNode.canRequestFocus) { + _effectiveFocusNode.requestFocus(); + } + }; + handleDidLoseAccessibilityFocus = () { + _effectiveFocusNode.unfocus(); + }; + } + + Widget child = RepaintBoundary( + child: UnmanagedRestorationScope( + bucket: bucket, + child: EditableText( + key: editableTextKey, + readOnly: widget.readOnly || !_isEnabled, + toolbarOptions: widget.toolbarOptions, + showCursor: widget.showCursor, + showSelectionHandles: _showSelectionHandles, + controller: controller, + focusNode: focusNode, + undoController: widget.undoController, + keyboardType: widget.keyboardType, + textInputAction: widget.textInputAction, + textCapitalization: widget.textCapitalization, + style: style, + strutStyle: widget.strutStyle, + textAlign: widget.textAlign, + textDirection: widget.textDirection, + autofocus: widget.autofocus, + obscuringCharacter: widget.obscuringCharacter, + obscureText: widget.obscureText, + autocorrect: widget.autocorrect, + smartDashesType: widget.smartDashesType, + smartQuotesType: widget.smartQuotesType, + enableSuggestions: widget.enableSuggestions, + maxLines: widget.maxLines, + minLines: widget.minLines, + expands: widget.expands, + // Only show the selection highlight when the text field is focused. + selectionColor: focusNode.hasFocus ? selectionColor : null, + selectionControls: widget.selectionEnabled ? textSelectionControls : null, + onChanged: widget.onChanged, + onSelectionChanged: _handleSelectionChanged, + onEditingComplete: widget.onEditingComplete, + onSubmitted: widget.onSubmitted, + onAppPrivateCommand: widget.onAppPrivateCommand, + onSelectionHandleTapped: _handleSelectionHandleTapped, + onTapOutside: widget.onTapOutside, + inputFormatters: formatters, + rendererIgnoresPointer: true, + mouseCursor: MouseCursor.defer, // TextField will handle the cursor + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: cursorRadius, + cursorColor: cursorColor, + selectionHeightStyle: widget.selectionHeightStyle, + selectionWidthStyle: widget.selectionWidthStyle, + cursorOpacityAnimates: cursorOpacityAnimates, + cursorOffset: cursorOffset, + paintCursorAboveText: paintCursorAboveText, + backgroundCursorColor: CupertinoColors.inactiveGray, + scrollPadding: widget.scrollPadding, + keyboardAppearance: keyboardAppearance, + enableInteractiveSelection: widget.enableInteractiveSelection, + dragStartBehavior: widget.dragStartBehavior, + scrollController: widget.scrollController, + scrollPhysics: widget.scrollPhysics, + autofillClient: this, + autocorrectionTextRectColor: autocorrectionTextRectColor, + clipBehavior: widget.clipBehavior, + restorationId: 'editable', + scribbleEnabled: widget.scribbleEnabled, + enableIMEPersonalizedLearning: widget.enableIMEPersonalizedLearning, + contentInsertionConfiguration: widget.contentInsertionConfiguration, + contextMenuBuilder: widget.contextMenuBuilder, + spellCheckConfiguration: spellCheckConfiguration, + magnifierConfiguration: widget.magnifierConfiguration ?? TextMagnifier.adaptiveMagnifierConfiguration, + ), + ), + ); + + if (widget.decoration != null) { + child = AnimatedBuilder( + animation: Listenable.merge(<Listenable>[ focusNode, controller ]), + builder: (BuildContext context, Widget? child) { + return InputDecorator( + decoration: _getEffectiveDecoration(), + baseStyle: widget.style, + textAlign: widget.textAlign, + textAlignVertical: widget.textAlignVertical, + isHovering: _isHovering, + isFocused: focusNode.hasFocus, + isEmpty: controller.value.text.isEmpty, + expands: widget.expands, + child: child, + ); + }, + child: child, + ); + } + final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor>( + widget.mouseCursor ?? MaterialStateMouseCursor.textable, + _statesController.value, + ); + + final int? semanticsMaxValueLength; + if (_effectiveMaxLengthEnforcement != MaxLengthEnforcement.none && + widget.maxLength != null && + widget.maxLength! > 0) { + semanticsMaxValueLength = widget.maxLength; + } else { + semanticsMaxValueLength = null; + } + + return MouseRegion( + cursor: effectiveMouseCursor, + onEnter: (PointerEnterEvent event) => _handleHover(true), + onExit: (PointerExitEvent event) => _handleHover(false), + child: TextFieldTapRegion( + child: IgnorePointer( + ignoring: !_isEnabled, + child: AnimatedBuilder( + animation: controller, // changes the _currentLength + builder: (BuildContext context, Widget? child) { + return Semantics( + maxValueLength: semanticsMaxValueLength, + currentValueLength: _currentLength, + onTap: widget.readOnly ? null : () { + if (!_effectiveController.selection.isValid) { + _effectiveController.selection = TextSelection.collapsed(offset: _effectiveController.text.length); + } + _requestKeyboard(); + }, + onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus, + onDidLoseAccessibilityFocus: handleDidLoseAccessibilityFocus, + child: child, + ); + }, + child: _selectionGestureDetectorBuilder.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: child, + ), + ), + ), + ), + ); + } +} + +TextStyle? _m2StateInputStyle(BuildContext context) => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + final ThemeData theme = Theme.of(context); + if (states.contains(MaterialState.disabled)) { + return TextStyle(color: theme.disabledColor); + } + return TextStyle(color: theme.textTheme.titleMedium?.color); +}); + +TextStyle _m2CounterErrorStyle(BuildContext context) => + Theme.of(context).textTheme.bodySmall!.copyWith(color: Theme.of(context).colorScheme.error); + +// BEGIN GENERATED TOKEN PROPERTIES - TextField + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +TextStyle? _m3StateInputStyle(BuildContext context) => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.disabled)) { + return TextStyle(color: Theme.of(context).textTheme.bodyLarge!.color?.withOpacity(0.38)); + } + return TextStyle(color: Theme.of(context).textTheme.bodyLarge!.color); +}); + +TextStyle _m3InputStyle(BuildContext context) => Theme.of(context).textTheme.bodyLarge!; + +TextStyle _m3CounterErrorStyle(BuildContext context) => + Theme.of(context).textTheme.bodySmall!.copyWith(color: Theme.of(context).colorScheme.error); + +// END GENERATED TOKEN PROPERTIES - TextField diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_form_field.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_form_field.dart new file mode 100644 index 0000000000000000000000000000000000000000..87e92d58dc3ce76e3471d741f0685a8b196241ef --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_form_field.dart @@ -0,0 +1,398 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'adaptive_text_selection_toolbar.dart'; +import 'input_decorator.dart'; +import 'material_state.dart'; +import 'text_field.dart'; +import 'theme.dart'; + +export 'package:flutter/services.dart' show SmartDashesType, SmartQuotesType; + +/// A [FormField] that contains a [TextField]. +/// +/// This is a convenience widget that wraps a [TextField] widget in a +/// [FormField]. +/// +/// A [Form] ancestor is not required. The [Form] allows one to +/// save, reset, or validate multiple fields at once. To use without a [Form], +/// pass a `GlobalKey<FormFieldState>` (see [GlobalKey]) to the constructor and use +/// [GlobalKey.currentState] to save or reset the form field. +/// +/// When a [controller] is specified, its [TextEditingController.text] +/// defines the [initialValue]. If this [FormField] is part of a scrolling +/// container that lazily constructs its children, like a [ListView] or a +/// [CustomScrollView], then a [controller] should be specified. +/// The controller's lifetime should be managed by a stateful widget ancestor +/// of the scrolling container. +/// +/// If a [controller] is not specified, [initialValue] can be used to give +/// the automatically generated controller an initial value. +/// +/// {@macro flutter.material.textfield.wantKeepAlive} +/// +/// Remember to call [TextEditingController.dispose] of the [TextEditingController] +/// when it is no longer needed. This will ensure any resources used by the object +/// are discarded. +/// +/// By default, `decoration` will apply the [ThemeData.inputDecorationTheme] for +/// the current context to the [InputDecoration], see +/// [InputDecoration.applyDefaults]. +/// +/// For a documentation about the various parameters, see [TextField]. +/// +/// {@tool snippet} +/// +/// Creates a [TextFormField] with an [InputDecoration] and validator function. +/// +/// ![If the user enters valid text, the TextField appears normally without any warnings to the user](https://flutter.github.io/assets-for-api-docs/assets/material/text_form_field.png) +/// +/// ![If the user enters invalid text, the error message returned from the validator function is displayed in dark red underneath the input](https://flutter.github.io/assets-for-api-docs/assets/material/text_form_field_error.png) +/// +/// ```dart +/// TextFormField( +/// decoration: const InputDecoration( +/// icon: Icon(Icons.person), +/// hintText: 'What do people call you?', +/// labelText: 'Name *', +/// ), +/// onSaved: (String? value) { +/// // This optional block of code can be used to run +/// // code when the user saves the form. +/// }, +/// validator: (String? value) { +/// return (value != null && value.contains('@')) ? 'Do not use the @ char.' : null; +/// }, +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to move the focus to the next field when the user +/// presses the SPACE key. +/// +/// ** See code in examples/api/lib/material/text_form_field/text_form_field.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * <https://material.io/design/components/text-fields.html> +/// * [TextField], which is the underlying text field without the [Form] +/// integration. +/// * [InputDecorator], which shows the labels and other visual elements that +/// surround the actual text editing widget. +/// * Learn how to use a [TextEditingController] in one of our [cookbook recipes](https://flutter.dev/docs/cookbook/forms/text-field-changes#2-use-a-texteditingcontroller). +class TextFormField extends FormField<String> { + /// Creates a [FormField] that contains a [TextField]. + /// + /// When a [controller] is specified, [initialValue] must be null (the + /// default). If [controller] is null, then a [TextEditingController] + /// will be constructed automatically and its `text` will be initialized + /// to [initialValue] or the empty string. + /// + /// For documentation about the various parameters, see the [TextField] class + /// and [TextField.new], the constructor. + TextFormField({ + super.key, + this.controller, + String? initialValue, + FocusNode? focusNode, + InputDecoration? decoration = const InputDecoration(), + TextInputType? keyboardType, + TextCapitalization textCapitalization = TextCapitalization.none, + TextInputAction? textInputAction, + TextStyle? style, + StrutStyle? strutStyle, + TextDirection? textDirection, + TextAlign textAlign = TextAlign.start, + TextAlignVertical? textAlignVertical, + bool autofocus = false, + bool readOnly = false, + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + ToolbarOptions? toolbarOptions, + bool? showCursor, + String obscuringCharacter = '•', + bool obscureText = false, + bool autocorrect = true, + SmartDashesType? smartDashesType, + SmartQuotesType? smartQuotesType, + bool enableSuggestions = true, + MaxLengthEnforcement? maxLengthEnforcement, + int? maxLines = 1, + int? minLines, + bool expands = false, + int? maxLength, + this.onChanged, + GestureTapCallback? onTap, + bool onTapAlwaysCalled = false, + TapRegionCallback? onTapOutside, + VoidCallback? onEditingComplete, + ValueChanged<String>? onFieldSubmitted, + super.onSaved, + super.validator, + List<TextInputFormatter>? inputFormatters, + bool? enabled, + double cursorWidth = 2.0, + double? cursorHeight, + Radius? cursorRadius, + Color? cursorColor, + Color? cursorErrorColor, + Brightness? keyboardAppearance, + EdgeInsets scrollPadding = const EdgeInsets.all(20.0), + bool? enableInteractiveSelection, + TextSelectionControls? selectionControls, + InputCounterWidgetBuilder? buildCounter, + ScrollPhysics? scrollPhysics, + Iterable<String>? autofillHints, + AutovalidateMode? autovalidateMode, + ScrollController? scrollController, + super.restorationId, + bool enableIMEPersonalizedLearning = true, + MouseCursor? mouseCursor, + EditableTextContextMenuBuilder? contextMenuBuilder = _defaultContextMenuBuilder, + SpellCheckConfiguration? spellCheckConfiguration, + TextMagnifierConfiguration? magnifierConfiguration, + UndoHistoryController? undoController, + AppPrivateCommandCallback? onAppPrivateCommand, + bool? cursorOpacityAnimates, + ui.BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight, + ui.BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight, + DragStartBehavior dragStartBehavior = DragStartBehavior.start, + ContentInsertionConfiguration? contentInsertionConfiguration, + MaterialStatesController? statesController, + Clip clipBehavior = Clip.hardEdge, + bool scribbleEnabled = true, + bool canRequestFocus = true, + }) : assert(initialValue == null || controller == null), + assert(obscuringCharacter.length == 1), + assert(maxLines == null || maxLines > 0), + assert(minLines == null || minLines > 0), + assert( + (maxLines == null) || (minLines == null) || (maxLines >= minLines), + "minLines can't be greater than maxLines", + ), + assert( + !expands || (maxLines == null && minLines == null), + 'minLines and maxLines must be null when expands is true.', + ), + assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'), + assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0), + super( + initialValue: controller != null ? controller.text : (initialValue ?? ''), + enabled: enabled ?? decoration?.enabled ?? true, + autovalidateMode: autovalidateMode ?? AutovalidateMode.disabled, + builder: (FormFieldState<String> field) { + final _TextFormFieldState state = field as _TextFormFieldState; + final InputDecoration effectiveDecoration = (decoration ?? const InputDecoration()) + .applyDefaults(Theme.of(field.context).inputDecorationTheme); + void onChangedHandler(String value) { + field.didChange(value); + onChanged?.call(value); + } + return UnmanagedRestorationScope( + bucket: field.bucket, + child: TextField( + restorationId: restorationId, + controller: state._effectiveController, + focusNode: focusNode, + decoration: effectiveDecoration.copyWith(errorText: field.errorText), + keyboardType: keyboardType, + textInputAction: textInputAction, + style: style, + strutStyle: strutStyle, + textAlign: textAlign, + textAlignVertical: textAlignVertical, + textDirection: textDirection, + textCapitalization: textCapitalization, + autofocus: autofocus, + statesController: statesController, + toolbarOptions: toolbarOptions, + readOnly: readOnly, + showCursor: showCursor, + obscuringCharacter: obscuringCharacter, + obscureText: obscureText, + autocorrect: autocorrect, + smartDashesType: smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), + smartQuotesType: smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), + enableSuggestions: enableSuggestions, + maxLengthEnforcement: maxLengthEnforcement, + maxLines: maxLines, + minLines: minLines, + expands: expands, + maxLength: maxLength, + onChanged: onChangedHandler, + onTap: onTap, + onTapAlwaysCalled: onTapAlwaysCalled, + onTapOutside: onTapOutside, + onEditingComplete: onEditingComplete, + onSubmitted: onFieldSubmitted, + inputFormatters: inputFormatters, + enabled: enabled ?? decoration?.enabled ?? true, + cursorWidth: cursorWidth, + cursorHeight: cursorHeight, + cursorRadius: cursorRadius, + cursorColor: cursorColor, + cursorErrorColor: cursorErrorColor, + scrollPadding: scrollPadding, + scrollPhysics: scrollPhysics, + keyboardAppearance: keyboardAppearance, + enableInteractiveSelection: enableInteractiveSelection ?? (!obscureText || !readOnly), + selectionControls: selectionControls, + buildCounter: buildCounter, + autofillHints: autofillHints, + scrollController: scrollController, + enableIMEPersonalizedLearning: enableIMEPersonalizedLearning, + mouseCursor: mouseCursor, + contextMenuBuilder: contextMenuBuilder, + spellCheckConfiguration: spellCheckConfiguration, + magnifierConfiguration: magnifierConfiguration, + undoController: undoController, + onAppPrivateCommand: onAppPrivateCommand, + cursorOpacityAnimates: cursorOpacityAnimates, + selectionHeightStyle: selectionHeightStyle, + selectionWidthStyle: selectionWidthStyle, + dragStartBehavior: dragStartBehavior, + contentInsertionConfiguration: contentInsertionConfiguration, + clipBehavior: clipBehavior, + scribbleEnabled: scribbleEnabled, + canRequestFocus: canRequestFocus, + ), + ); + }, + ); + + /// Controls the text being edited. + /// + /// If null, this widget will create its own [TextEditingController] and + /// initialize its [TextEditingController.text] with [initialValue]. + final TextEditingController? controller; + + /// {@template flutter.material.TextFormField.onChanged} + /// Called when the user initiates a change to the TextField's + /// value: when they have inserted or deleted text or reset the form. + /// {@endtemplate} + final ValueChanged<String>? onChanged; + + static Widget _defaultContextMenuBuilder(BuildContext context, EditableTextState editableTextState) { + return AdaptiveTextSelectionToolbar.editableText( + editableTextState: editableTextState, + ); + } + + @override + FormFieldState<String> createState() => _TextFormFieldState(); +} + +class _TextFormFieldState extends FormFieldState<String> { + RestorableTextEditingController? _controller; + + TextEditingController get _effectiveController => _textFormField.controller ?? _controller!.value; + + TextFormField get _textFormField => super.widget as TextFormField; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + super.restoreState(oldBucket, initialRestore); + if (_controller != null) { + _registerController(); + } + // Make sure to update the internal [FormFieldState] value to sync up with + // text editing controller value. + setValue(_effectiveController.text); + } + + void _registerController() { + assert(_controller != null); + registerForRestoration(_controller!, 'controller'); + } + + void _createLocalController([TextEditingValue? value]) { + assert(_controller == null); + _controller = value == null + ? RestorableTextEditingController() + : RestorableTextEditingController.fromValue(value); + if (!restorePending) { + _registerController(); + } + } + + @override + void initState() { + super.initState(); + if (_textFormField.controller == null) { + _createLocalController(widget.initialValue != null ? TextEditingValue(text: widget.initialValue!) : null); + } else { + _textFormField.controller!.addListener(_handleControllerChanged); + } + } + + @override + void didUpdateWidget(TextFormField oldWidget) { + super.didUpdateWidget(oldWidget); + if (_textFormField.controller != oldWidget.controller) { + oldWidget.controller?.removeListener(_handleControllerChanged); + _textFormField.controller?.addListener(_handleControllerChanged); + + if (oldWidget.controller != null && _textFormField.controller == null) { + _createLocalController(oldWidget.controller!.value); + } + + if (_textFormField.controller != null) { + setValue(_textFormField.controller!.text); + if (oldWidget.controller == null) { + unregisterFromRestoration(_controller!); + _controller!.dispose(); + _controller = null; + } + } + } + } + + @override + void dispose() { + _textFormField.controller?.removeListener(_handleControllerChanged); + _controller?.dispose(); + super.dispose(); + } + + @override + void didChange(String? value) { + super.didChange(value); + + if (_effectiveController.text != value) { + _effectiveController.text = value ?? ''; + } + } + + @override + void reset() { + // Set the controller value before calling super.reset() to let + // _handleControllerChanged suppress the change. + _effectiveController.text = widget.initialValue ?? ''; + super.reset(); + _textFormField.onChanged?.call(_effectiveController.text); + } + + void _handleControllerChanged() { + // Suppress changes that originated from within this class. + // + // In the case where a controller has been passed in to this widget, we + // register this change listener. In these cases, we'll also receive change + // notifications for changes originating from within this class -- for + // example, the reset() method. In such cases, the FormField value will + // already have been set. + if (_effectiveController.text != value) { + didChange(_effectiveController.text); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection.dart new file mode 100644 index 0000000000000000000000000000000000000000..c3026fd3048885a76b22e5bf0074e66028fc41f7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection.dart @@ -0,0 +1,319 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'debug.dart'; +import 'material_localizations.dart'; +import 'text_selection_theme.dart'; +import 'text_selection_toolbar.dart'; +import 'text_selection_toolbar_text_button.dart'; +import 'theme.dart'; + +const double _kHandleSize = 22.0; + +// Padding between the toolbar and the anchor. +const double _kToolbarContentDistanceBelow = _kHandleSize - 2.0; +const double _kToolbarContentDistance = 8.0; + +/// Android Material styled text selection handle controls. +/// +/// Specifically does not manage the toolbar, which is left to +/// [EditableText.contextMenuBuilder]. +@Deprecated( + 'Use `MaterialTextSelectionControls`. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', +) +class MaterialTextSelectionHandleControls extends MaterialTextSelectionControls with TextSelectionHandleControls { +} + +/// Android Material styled text selection controls. +/// +/// The [materialTextSelectionControls] global variable has a +/// suitable instance of this class. +class MaterialTextSelectionControls extends TextSelectionControls { + /// Returns the size of the Material handle. + @override + Size getHandleSize(double textLineHeight) => const Size(_kHandleSize, _kHandleSize); + + /// Builder for material-style copy/paste text selection toolbar. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + Widget buildToolbar( + BuildContext context, + Rect globalEditableRegion, + double textLineHeight, + Offset selectionMidpoint, + List<TextSelectionPoint> endpoints, + TextSelectionDelegate delegate, + ValueListenable<ClipboardStatus>? clipboardStatus, + Offset? lastSecondaryTapDownPosition, + ) { + return _TextSelectionControlsToolbar( + globalEditableRegion: globalEditableRegion, + textLineHeight: textLineHeight, + selectionMidpoint: selectionMidpoint, + endpoints: endpoints, + delegate: delegate, + clipboardStatus: clipboardStatus, + handleCut: canCut(delegate) ? () => handleCut(delegate) : null, + handleCopy: canCopy(delegate) ? () => handleCopy(delegate) : null, + handlePaste: canPaste(delegate) ? () => handlePaste(delegate) : null, + handleSelectAll: canSelectAll(delegate) ? () => handleSelectAll(delegate) : null, + ); + } + + /// Builder for material-style text selection handles. + @override + Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textHeight, [VoidCallback? onTap]) { + final ThemeData theme = Theme.of(context); + final Color handleColor = TextSelectionTheme.of(context).selectionHandleColor ?? theme.colorScheme.primary; + final Widget handle = SizedBox( + width: _kHandleSize, + height: _kHandleSize, + child: CustomPaint( + painter: _TextSelectionHandlePainter( + color: handleColor, + ), + child: GestureDetector( + onTap: onTap, + behavior: HitTestBehavior.translucent, + ), + ), + ); + + // [handle] is a circle, with a rectangle in the top left quadrant of that + // circle (an onion pointing to 10:30). We rotate [handle] to point + // straight up or up-right depending on the handle type. + switch (type) { + case TextSelectionHandleType.left: // points up-right + return Transform.rotate( + angle: math.pi / 2.0, + child: handle, + ); + case TextSelectionHandleType.right: // points up-left + return handle; + case TextSelectionHandleType.collapsed: // points up + return Transform.rotate( + angle: math.pi / 4.0, + child: handle, + ); + } + } + + /// Gets anchor for material-style text selection handles. + /// + /// See [TextSelectionControls.getHandleAnchor]. + @override + Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) { + switch (type) { + case TextSelectionHandleType.left: + return const Offset(_kHandleSize, 0); + case TextSelectionHandleType.right: + return Offset.zero; + case TextSelectionHandleType.collapsed: + return const Offset(_kHandleSize / 2, -4); + } + } + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + bool canSelectAll(TextSelectionDelegate delegate) { + // Android allows SelectAll when selection is not collapsed, unless + // everything has already been selected. + final TextEditingValue value = delegate.textEditingValue; + return delegate.selectAllEnabled && + value.text.isNotEmpty && + !(value.selection.start == 0 && value.selection.end == value.text.length); + } +} + +// The label and callback for the available default text selection menu buttons. +class _TextSelectionToolbarItemData { + const _TextSelectionToolbarItemData({ + required this.label, + required this.onPressed, + }); + + final String label; + final VoidCallback onPressed; +} + +// The highest level toolbar widget, built directly by buildToolbar. +class _TextSelectionControlsToolbar extends StatefulWidget { + const _TextSelectionControlsToolbar({ + required this.clipboardStatus, + required this.delegate, + required this.endpoints, + required this.globalEditableRegion, + required this.handleCut, + required this.handleCopy, + required this.handlePaste, + required this.handleSelectAll, + required this.selectionMidpoint, + required this.textLineHeight, + }); + + final ValueListenable<ClipboardStatus>? clipboardStatus; + final TextSelectionDelegate delegate; + final List<TextSelectionPoint> endpoints; + final Rect globalEditableRegion; + final VoidCallback? handleCut; + final VoidCallback? handleCopy; + final VoidCallback? handlePaste; + final VoidCallback? handleSelectAll; + final Offset selectionMidpoint; + final double textLineHeight; + + @override + _TextSelectionControlsToolbarState createState() => _TextSelectionControlsToolbarState(); +} + +class _TextSelectionControlsToolbarState extends State<_TextSelectionControlsToolbar> with TickerProviderStateMixin { + void _onChangedClipboardStatus() { + setState(() { + // Inform the widget that the value of clipboardStatus has changed. + }); + } + + @override + void initState() { + super.initState(); + widget.clipboardStatus?.addListener(_onChangedClipboardStatus); + } + + @override + void didUpdateWidget(_TextSelectionControlsToolbar oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.clipboardStatus != oldWidget.clipboardStatus) { + widget.clipboardStatus?.addListener(_onChangedClipboardStatus); + oldWidget.clipboardStatus?.removeListener(_onChangedClipboardStatus); + } + } + + @override + void dispose() { + widget.clipboardStatus?.removeListener(_onChangedClipboardStatus); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + // If there are no buttons to be shown, don't render anything. + if (widget.handleCut == null && widget.handleCopy == null + && widget.handlePaste == null && widget.handleSelectAll == null) { + return const SizedBox.shrink(); + } + // If the paste button is desired, don't render anything until the state of + // the clipboard is known, since it's used to determine if paste is shown. + if (widget.handlePaste != null + && widget.clipboardStatus?.value == ClipboardStatus.unknown) { + return const SizedBox.shrink(); + } + + // Calculate the positioning of the menu. It is placed above the selection + // if there is enough room, or otherwise below. + final TextSelectionPoint startTextSelectionPoint = widget.endpoints[0]; + final TextSelectionPoint endTextSelectionPoint = widget.endpoints.length > 1 + ? widget.endpoints[1] + : widget.endpoints[0]; + final double topAmountInEditableRegion = startTextSelectionPoint.point.dy - widget.textLineHeight; + final double anchorTop = math.max(topAmountInEditableRegion, 0) + widget.globalEditableRegion.top - _kToolbarContentDistance; + + final Offset anchorAbove = Offset( + widget.globalEditableRegion.left + widget.selectionMidpoint.dx, + anchorTop, + ); + final Offset anchorBelow = Offset( + widget.globalEditableRegion.left + widget.selectionMidpoint.dx, + widget.globalEditableRegion.top + endTextSelectionPoint.point.dy + _kToolbarContentDistanceBelow, + ); + + // Determine which buttons will appear so that the order and total number is + // known. A button's position in the menu can slightly affect its + // appearance. + assert(debugCheckHasMaterialLocalizations(context)); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final List<_TextSelectionToolbarItemData> itemDatas = <_TextSelectionToolbarItemData>[ + if (widget.handleCut != null) + _TextSelectionToolbarItemData( + label: localizations.cutButtonLabel, + onPressed: widget.handleCut!, + ), + if (widget.handleCopy != null) + _TextSelectionToolbarItemData( + label: localizations.copyButtonLabel, + onPressed: widget.handleCopy!, + ), + if (widget.handlePaste != null + && widget.clipboardStatus?.value == ClipboardStatus.pasteable) + _TextSelectionToolbarItemData( + label: localizations.pasteButtonLabel, + onPressed: widget.handlePaste!, + ), + if (widget.handleSelectAll != null) + _TextSelectionToolbarItemData( + label: localizations.selectAllButtonLabel, + onPressed: widget.handleSelectAll!, + ), + ]; + + // If there is no option available, build an empty widget. + if (itemDatas.isEmpty) { + return const SizedBox.shrink(); + } + + return TextSelectionToolbar( + anchorAbove: anchorAbove, + anchorBelow: anchorBelow, + children: itemDatas.asMap().entries.map((MapEntry<int, _TextSelectionToolbarItemData> entry) { + return TextSelectionToolbarTextButton( + padding: TextSelectionToolbarTextButton.getPadding(entry.key, itemDatas.length), + onPressed: entry.value.onPressed, + child: Text(entry.value.label), + ); + }).toList(), + ); + } +} + +/// Draws a single text selection handle which points up and to the left. +class _TextSelectionHandlePainter extends CustomPainter { + _TextSelectionHandlePainter({ required this.color }); + + final Color color; + + @override + void paint(Canvas canvas, Size size) { + final Paint paint = Paint()..color = color; + final double radius = size.width/2.0; + final Rect circle = Rect.fromCircle(center: Offset(radius, radius), radius: radius); + final Rect point = Rect.fromLTWH(0.0, 0.0, radius, radius); + final Path path = Path()..addOval(circle)..addRect(point); + canvas.drawPath(path, paint); + } + + @override + bool shouldRepaint(_TextSelectionHandlePainter oldPainter) { + return color != oldPainter.color; + } +} + +// TODO(justinmc): Deprecate this after TextSelectionControls.buildToolbar is +// deleted, when users should migrate back to materialTextSelectionControls. +// See https://github.com/flutter/flutter/pull/124262 +/// Text selection handle controls that follow the Material Design specification. +final TextSelectionControls materialTextSelectionHandleControls = MaterialTextSelectionHandleControls(); + +/// Text selection controls that follow the Material Design specification. +final TextSelectionControls materialTextSelectionControls = MaterialTextSelectionControls(); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..b7e659ae4d498bfb84e94715a399b1908bb18516 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection_theme.dart @@ -0,0 +1,196 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines the visual properties needed for text selection in [TextField] and +/// [SelectableText] widgets. +/// +/// Used by [TextSelectionTheme] to control the visual properties of text +/// selection in a widget subtree. +/// +/// Use [TextSelectionTheme.of] to access the closest ancestor +/// [TextSelectionTheme] of the current [BuildContext]. +/// +/// See also: +/// +/// * [TextSelectionTheme], an [InheritedWidget] that propagates the theme down its +/// subtree. +/// * [InputDecorationTheme], which defines most other visual properties of +/// text fields. +@immutable +class TextSelectionThemeData with Diagnosticable { + /// Creates the set of properties used to configure [TextField]s. + const TextSelectionThemeData({ + this.cursorColor, + this.selectionColor, + this.selectionHandleColor, + }); + + /// The color of the cursor in the text field. + /// + /// The cursor indicates the current location of text insertion point in + /// the field. + final Color? cursorColor; + + /// The background color of selected text. + final Color? selectionColor; + + /// The color of the selection handles on the text field. + /// + /// Selection handles are used to indicate the bounds of the selected text, + /// or as a handle to drag the cursor to a new location in the text. + /// + /// On iOS [TextField] and [SelectableText] cannot access [selectionHandleColor]. + /// To set the [selectionHandleColor] on iOS, you can change the + /// [CupertinoThemeData.primaryColor] in [ThemeData.cupertinoOverrideTheme]. + final Color? selectionHandleColor; + + /// Creates a copy of this object with the given fields replaced with the + /// specified values. + TextSelectionThemeData copyWith({ + Color? cursorColor, + Color? selectionColor, + Color? selectionHandleColor, + }) { + return TextSelectionThemeData( + cursorColor: cursorColor ?? this.cursorColor, + selectionColor: selectionColor ?? this.selectionColor, + selectionHandleColor: selectionHandleColor ?? this.selectionHandleColor, + ); + } + + /// Linearly interpolate between two text field themes. + /// + /// If both arguments are null, then null is returned. + /// + /// {@macro dart.ui.shadow.lerp} + static TextSelectionThemeData? lerp(TextSelectionThemeData? a, TextSelectionThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return TextSelectionThemeData( + cursorColor: Color.lerp(a?.cursorColor, b?.cursorColor, t), + selectionColor: Color.lerp(a?.selectionColor, b?.selectionColor, t), + selectionHandleColor: Color.lerp(a?.selectionHandleColor, b?.selectionHandleColor, t), + ); + } + + @override + int get hashCode => Object.hash( + cursorColor, + selectionColor, + selectionHandleColor, + ); + + @override + bool operator==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is TextSelectionThemeData + && other.cursorColor == cursorColor + && other.selectionColor == selectionColor + && other.selectionHandleColor == selectionHandleColor; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('cursorColor', cursorColor, defaultValue: null)); + properties.add(ColorProperty('selectionColor', selectionColor, defaultValue: null)); + properties.add(ColorProperty('selectionHandleColor', selectionHandleColor, defaultValue: null)); + } +} + +/// An inherited widget that defines the appearance of text selection in +/// this widget's subtree. +/// +/// Values specified here are used for [TextField] and [SelectableText] +/// properties that are not given an explicit non-null value. +/// +/// {@tool snippet} +/// +/// Here is an example of a text selection theme that applies a blue cursor +/// color with light blue selection handles to the child text field. +/// +/// ```dart +/// const TextSelectionTheme( +/// data: TextSelectionThemeData( +/// cursorColor: Colors.blue, +/// selectionHandleColor: Colors.lightBlue, +/// ), +/// child: TextField(), +/// ) +/// ``` +/// {@end-tool} +/// +/// This widget also creates a [DefaultSelectionStyle] for its subtree with +/// [data]. +class TextSelectionTheme extends InheritedTheme { + /// Creates a text selection theme widget that specifies the text + /// selection properties for all widgets below it in the widget tree. + const TextSelectionTheme({ + super.key, + required this.data, + required Widget child, + }) : _child = child, + // See `get child` override below. + super(child: const _NullWidget()); + + /// The properties for descendant [TextField] and [SelectableText] widgets. + final TextSelectionThemeData data; + + // Overriding the getter to insert `DefaultSelectionStyle` into the subtree + // without breaking API. In general, this approach should be avoided + // because it relies on an implementation detail of ProxyWidget. This + // workaround is necessary because TextSelectionTheme is const. + @override + Widget get child { + return DefaultSelectionStyle( + selectionColor: data.selectionColor, + cursorColor: data.cursorColor, + child: _child, + ); + } + final Widget _child; + + /// Returns the [data] from the closest [TextSelectionTheme] ancestor. If + /// there is no ancestor, it returns [ThemeData.textSelectionTheme]. + /// Applications can assume that the returned value will not be null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// TextSelectionThemeData theme = TextSelectionTheme.of(context); + /// ``` + static TextSelectionThemeData of(BuildContext context) { + final TextSelectionTheme? selectionTheme = context.dependOnInheritedWidgetOfExactType<TextSelectionTheme>(); + return selectionTheme?.data ?? Theme.of(context).textSelectionTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return TextSelectionTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(TextSelectionTheme oldWidget) => data != oldWidget.data; +} + +class _NullWidget extends Widget { + const _NullWidget(); + + @override + Element createElement() => throw UnimplementedError(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection_toolbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection_toolbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..61b047a3cc9660153400ab2be0f0dc28d82fe955 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection_toolbar.dart @@ -0,0 +1,718 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart' show listEquals; +import 'package:flutter/rendering.dart'; + +import 'color_scheme.dart'; +import 'debug.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'theme.dart'; + +const double _kToolbarHeight = 44.0; +const double _kToolbarContentDistance = 8.0; + +/// A fully-functional Material-style text selection toolbar. +/// +/// Tries to position itself above [anchorAbove], but if it doesn't fit, then +/// it positions itself below [anchorBelow]. +/// +/// If any children don't fit in the menu, an overflow menu will automatically +/// be created. +/// +/// See also: +/// +/// * [AdaptiveTextSelectionToolbar], which builds the toolbar for the current +/// platform. +/// * [CupertinoTextSelectionToolbar], which is similar, but builds an iOS- +/// style toolbar. +class TextSelectionToolbar extends StatelessWidget { + /// Creates an instance of TextSelectionToolbar. + const TextSelectionToolbar({ + super.key, + required this.anchorAbove, + required this.anchorBelow, + this.toolbarBuilder = _defaultToolbarBuilder, + required this.children, + }) : assert(children.length > 0); + + /// {@template flutter.material.TextSelectionToolbar.anchorAbove} + /// The focal point above which the toolbar attempts to position itself. + /// + /// If there is not enough room above before reaching the top of the screen, + /// then the toolbar will position itself below [anchorBelow]. + /// {@endtemplate} + final Offset anchorAbove; + + /// {@template flutter.material.TextSelectionToolbar.anchorBelow} + /// The focal point below which the toolbar attempts to position itself, if it + /// doesn't fit above [anchorAbove]. + /// {@endtemplate} + final Offset anchorBelow; + + /// {@template flutter.material.TextSelectionToolbar.children} + /// The children that will be displayed in the text selection toolbar. + /// + /// Typically these are buttons. + /// + /// Must not be empty. + /// {@endtemplate} + /// + /// See also: + /// * [TextSelectionToolbarTextButton], which builds a default Material- + /// style text selection toolbar text button. + final List<Widget> children; + + /// {@template flutter.material.TextSelectionToolbar.toolbarBuilder} + /// Builds the toolbar container. + /// + /// Useful for customizing the high-level background of the toolbar. The given + /// child Widget will contain all of the [children]. + /// {@endtemplate} + final ToolbarBuilder toolbarBuilder; + + /// The size of the text selection handles. + /// + /// See also: + /// + /// * [SpellCheckSuggestionsToolbar], which references this value to calculate + /// the padding between the toolbar and anchor. + static const double kHandleSize = 22.0; + + /// Padding between the toolbar and the anchor. + static const double kToolbarContentDistanceBelow = kHandleSize - 2.0; + + // Build the default Android Material text selection menu toolbar. + static Widget _defaultToolbarBuilder(BuildContext context, Widget child) { + return _TextSelectionToolbarContainer( + child: child, + ); + } + + @override + Widget build(BuildContext context) { + // Incorporate the padding distance between the content and toolbar. + final Offset anchorAbovePadded = + anchorAbove - const Offset(0.0, _kToolbarContentDistance); + final Offset anchorBelowPadded = + anchorBelow + const Offset(0.0, kToolbarContentDistanceBelow); + + const double screenPadding = CupertinoTextSelectionToolbar.kToolbarScreenPadding; + final double paddingAbove = MediaQuery.paddingOf(context).top + + screenPadding; + final double availableHeight = anchorAbovePadded.dy - _kToolbarContentDistance - paddingAbove; + final bool fitsAbove = _kToolbarHeight <= availableHeight; + // Makes up for the Padding above the Stack. + final Offset localAdjustment = Offset(screenPadding, paddingAbove); + + return Padding( + padding: EdgeInsets.fromLTRB( + screenPadding, + paddingAbove, + screenPadding, + screenPadding, + ), + child: CustomSingleChildLayout( + delegate: TextSelectionToolbarLayoutDelegate( + anchorAbove: anchorAbovePadded - localAdjustment, + anchorBelow: anchorBelowPadded - localAdjustment, + fitsAbove: fitsAbove, + ), + child: _TextSelectionToolbarOverflowable( + isAbove: fitsAbove, + toolbarBuilder: toolbarBuilder, + children: children, + ), + ), + ); + } +} + +// A toolbar containing the given children. If they overflow the width +// available, then the overflowing children will be displayed in an overflow +// menu. +class _TextSelectionToolbarOverflowable extends StatefulWidget { + const _TextSelectionToolbarOverflowable({ + required this.isAbove, + required this.toolbarBuilder, + required this.children, + }) : assert(children.length > 0); + + final List<Widget> children; + + // When true, the toolbar fits above its anchor and will be positioned there. + final bool isAbove; + + // Builds the toolbar that will be populated with the children and fit inside + // of the layout that adjusts to overflow. + final ToolbarBuilder toolbarBuilder; + + @override + _TextSelectionToolbarOverflowableState createState() => _TextSelectionToolbarOverflowableState(); +} + +class _TextSelectionToolbarOverflowableState extends State<_TextSelectionToolbarOverflowable> with TickerProviderStateMixin { + // Whether or not the overflow menu is open. When it is closed, the menu + // items that don't overflow are shown. When it is open, only the overflowing + // menu items are shown. + bool _overflowOpen = false; + + // The key for _TextSelectionToolbarTrailingEdgeAlign. + UniqueKey _containerKey = UniqueKey(); + + // Close the menu and reset layout calculations, as in when the menu has + // changed and saved values are no longer relevant. This should be called in + // setState or another context where a rebuild is happening. + void _reset() { + // Change _TextSelectionToolbarTrailingEdgeAlign's key when the menu changes + // in order to cause it to rebuild. This lets it recalculate its + // saved width for the new set of children, and it prevents AnimatedSize + // from animating the size change. + _containerKey = UniqueKey(); + // If the menu items change, make sure the overflow menu is closed. This + // prevents getting into a broken state where _overflowOpen is true when + // there are not enough children to cause overflow. + _overflowOpen = false; + } + + @override + void didUpdateWidget(_TextSelectionToolbarOverflowable oldWidget) { + super.didUpdateWidget(oldWidget); + // If the children are changing at all, the current page should be reset. + if (!listEquals(widget.children, oldWidget.children)) { + _reset(); + } + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + + return _TextSelectionToolbarTrailingEdgeAlign( + key: _containerKey, + overflowOpen: _overflowOpen, + textDirection: Directionality.of(context), + child: AnimatedSize( + // This duration was eyeballed on a Pixel 2 emulator running Android + // API 28. + duration: const Duration(milliseconds: 140), + child: widget.toolbarBuilder(context, _TextSelectionToolbarItemsLayout( + isAbove: widget.isAbove, + overflowOpen: _overflowOpen, + children: <Widget>[ + // TODO(justinmc): This overflow button should have its own slot in + // _TextSelectionToolbarItemsLayout separate from children, similar + // to how it's done in Cupertino's text selection menu. + // https://github.com/flutter/flutter/issues/69908 + // The navButton that shows and hides the overflow menu is the + // first child. + _TextSelectionToolbarOverflowButton( + icon: Icon(_overflowOpen ? Icons.arrow_back : Icons.more_vert), + onPressed: () { + setState(() { + _overflowOpen = !_overflowOpen; + }); + }, + tooltip: _overflowOpen + ? localizations.backButtonTooltip + : localizations.moreButtonTooltip, + ), + ...widget.children, + ], + )), + ), + ); + } +} + +// When the overflow menu is open, it tries to align its trailing edge to the +// trailing edge of the closed menu. This widget handles this effect by +// measuring and maintaining the width of the closed menu and aligning the child +// to that side. +class _TextSelectionToolbarTrailingEdgeAlign extends SingleChildRenderObjectWidget { + const _TextSelectionToolbarTrailingEdgeAlign({ + super.key, + required Widget super.child, + required this.overflowOpen, + required this.textDirection, + }); + + final bool overflowOpen; + final TextDirection textDirection; + + @override + _TextSelectionToolbarTrailingEdgeAlignRenderBox createRenderObject(BuildContext context) { + return _TextSelectionToolbarTrailingEdgeAlignRenderBox( + overflowOpen: overflowOpen, + textDirection: textDirection, + ); + } + + @override + void updateRenderObject(BuildContext context, _TextSelectionToolbarTrailingEdgeAlignRenderBox renderObject) { + renderObject + ..overflowOpen = overflowOpen + ..textDirection = textDirection; + } +} + +class _TextSelectionToolbarTrailingEdgeAlignRenderBox extends RenderProxyBox { + _TextSelectionToolbarTrailingEdgeAlignRenderBox({ + required bool overflowOpen, + required TextDirection textDirection, + }) : _textDirection = textDirection, + _overflowOpen = overflowOpen, + super(); + + // The width of the menu when it was closed. This is used to achieve the + // behavior where the open menu aligns its trailing edge to the closed menu's + // trailing edge. + double? _closedWidth; + + bool _overflowOpen; + bool get overflowOpen => _overflowOpen; + set overflowOpen(bool value) { + if (value == overflowOpen) { + return; + } + _overflowOpen = value; + markNeedsLayout(); + } + + TextDirection _textDirection; + TextDirection get textDirection => _textDirection; + set textDirection(TextDirection value) { + if (value == textDirection) { + return; + } + _textDirection = value; + markNeedsLayout(); + } + + @override + void performLayout() { + child!.layout(constraints.loosen(), parentUsesSize: true); + + // Save the width when the menu is closed. If the menu changes, this width + // is invalid, so it's important that this RenderBox be recreated in that + // case. Currently, this is achieved by providing a new key to + // _TextSelectionToolbarTrailingEdgeAlign. + if (!overflowOpen && _closedWidth == null) { + _closedWidth = child!.size.width; + } + + size = constraints.constrain(Size( + // If the open menu is wider than the closed menu, just use its own width + // and don't worry about aligning the trailing edges. + // _closedWidth is used even when the menu is closed to allow it to + // animate its size while keeping the same edge alignment. + _closedWidth == null || child!.size.width > _closedWidth! ? child!.size.width : _closedWidth!, + child!.size.height, + )); + + // Set the offset in the parent data such that the child will be aligned to + // the trailing edge, depending on the text direction. + final ToolbarItemsParentData childParentData = child!.parentData! as ToolbarItemsParentData; + childParentData.offset = Offset( + textDirection == TextDirection.rtl ? 0.0 : size.width - child!.size.width, + 0.0, + ); + } + + // Paint at the offset set in the parent data. + @override + void paint(PaintingContext context, Offset offset) { + final ToolbarItemsParentData childParentData = child!.parentData! as ToolbarItemsParentData; + context.paintChild(child!, childParentData.offset + offset); + } + + // Include the parent data offset in the hit test. + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + // The x, y parameters have the top left of the node's box as the origin. + final ToolbarItemsParentData childParentData = child!.parentData! as ToolbarItemsParentData; + return result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - childParentData.offset); + return child!.hitTest(result, position: transformed); + }, + ); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! ToolbarItemsParentData) { + child.parentData = ToolbarItemsParentData(); + } + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData; + transform.translate(childParentData.offset.dx, childParentData.offset.dy); + super.applyPaintTransform(child, transform); + } +} + +// Renders the menu items in the correct positions in the menu and its overflow +// submenu based on calculating which item would first overflow. +class _TextSelectionToolbarItemsLayout extends MultiChildRenderObjectWidget { + const _TextSelectionToolbarItemsLayout({ + required this.isAbove, + required this.overflowOpen, + required super.children, + }); + + final bool isAbove; + final bool overflowOpen; + + @override + _RenderTextSelectionToolbarItemsLayout createRenderObject(BuildContext context) { + return _RenderTextSelectionToolbarItemsLayout( + isAbove: isAbove, + overflowOpen: overflowOpen, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderTextSelectionToolbarItemsLayout renderObject) { + renderObject + ..isAbove = isAbove + ..overflowOpen = overflowOpen; + } + + @override + _TextSelectionToolbarItemsLayoutElement createElement() => _TextSelectionToolbarItemsLayoutElement(this); +} + +class _TextSelectionToolbarItemsLayoutElement extends MultiChildRenderObjectElement { + _TextSelectionToolbarItemsLayoutElement( + super.widget, + ); + + static bool _shouldPaint(Element child) { + return (child.renderObject!.parentData! as ToolbarItemsParentData).shouldPaint; + } + + @override + void debugVisitOnstageChildren(ElementVisitor visitor) { + children.where(_shouldPaint).forEach(visitor); + } +} + +class _RenderTextSelectionToolbarItemsLayout extends RenderBox with ContainerRenderObjectMixin<RenderBox, ToolbarItemsParentData> { + _RenderTextSelectionToolbarItemsLayout({ + required bool isAbove, + required bool overflowOpen, + }) : _isAbove = isAbove, + _overflowOpen = overflowOpen, + super(); + + // The index of the last item that doesn't overflow. + int _lastIndexThatFits = -1; + + bool _isAbove; + bool get isAbove => _isAbove; + set isAbove(bool value) { + if (value == isAbove) { + return; + } + _isAbove = value; + markNeedsLayout(); + } + + bool _overflowOpen; + bool get overflowOpen => _overflowOpen; + set overflowOpen(bool value) { + if (value == overflowOpen) { + return; + } + _overflowOpen = value; + markNeedsLayout(); + } + + // Layout the necessary children, and figure out where the children first + // overflow, if at all. + void _layoutChildren() { + // When overflow is not open, the toolbar is always a specific height. + final BoxConstraints sizedConstraints = _overflowOpen + ? constraints + : BoxConstraints.loose(Size( + constraints.maxWidth, + _kToolbarHeight, + )); + + int i = -1; + double width = 0.0; + visitChildren((RenderObject renderObjectChild) { + i++; + + // No need to layout children inside the overflow menu when it's closed. + // The opposite is not true. It is necessary to layout the children that + // don't overflow when the overflow menu is open in order to calculate + // _lastIndexThatFits. + if (_lastIndexThatFits != -1 && !overflowOpen) { + return; + } + + final RenderBox child = renderObjectChild as RenderBox; + child.layout(sizedConstraints.loosen(), parentUsesSize: true); + width += child.size.width; + + if (width > sizedConstraints.maxWidth && _lastIndexThatFits == -1) { + _lastIndexThatFits = i - 1; + } + }); + + // If the last child overflows, but only because of the width of the + // overflow button, then just show it and hide the overflow button. + final RenderBox navButton = firstChild!; + if (_lastIndexThatFits != -1 + && _lastIndexThatFits == childCount - 2 + && width - navButton.size.width <= sizedConstraints.maxWidth) { + _lastIndexThatFits = -1; + } + } + + // Returns true when the child should be painted, false otherwise. + bool _shouldPaintChild(RenderObject renderObjectChild, int index) { + // Paint the navButton when there is overflow. + if (renderObjectChild == firstChild) { + return _lastIndexThatFits != -1; + } + + // If there is no overflow, all children besides the navButton are painted. + if (_lastIndexThatFits == -1) { + return true; + } + + // When there is overflow, paint if the child is in the part of the menu + // that is currently open. Overflowing children are painted when the + // overflow menu is open, and the children that fit are painted when the + // overflow menu is closed. + return (index > _lastIndexThatFits) == overflowOpen; + } + + // Decide which children will be painted, set their shouldPaint, and set the + // offset that painted children will be placed at. + void _placeChildren() { + int i = -1; + Size nextSize = Size.zero; + double fitWidth = 0.0; + final RenderBox navButton = firstChild!; + double overflowHeight = overflowOpen && !isAbove ? navButton.size.height : 0.0; + visitChildren((RenderObject renderObjectChild) { + i++; + + final RenderBox child = renderObjectChild as RenderBox; + final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData; + + // Handle placing the navigation button after iterating all children. + if (renderObjectChild == navButton) { + return; + } + + // There is no need to place children that won't be painted. + if (!_shouldPaintChild(renderObjectChild, i)) { + childParentData.shouldPaint = false; + return; + } + childParentData.shouldPaint = true; + + if (!overflowOpen) { + childParentData.offset = Offset(fitWidth, 0.0); + fitWidth += child.size.width; + nextSize = Size( + fitWidth, + math.max(child.size.height, nextSize.height), + ); + } else { + childParentData.offset = Offset(0.0, overflowHeight); + overflowHeight += child.size.height; + nextSize = Size( + math.max(child.size.width, nextSize.width), + overflowHeight, + ); + } + }); + + // Place the navigation button if needed. + final ToolbarItemsParentData navButtonParentData = navButton.parentData! as ToolbarItemsParentData; + if (_shouldPaintChild(firstChild!, 0)) { + navButtonParentData.shouldPaint = true; + if (overflowOpen) { + navButtonParentData.offset = isAbove + ? Offset(0.0, overflowHeight) + : Offset.zero; + nextSize = Size( + nextSize.width, + isAbove ? nextSize.height + navButton.size.height : nextSize.height, + ); + } else { + navButtonParentData.offset = Offset(fitWidth, 0.0); + nextSize = Size(nextSize.width + navButton.size.width, nextSize.height); + } + } else { + navButtonParentData.shouldPaint = false; + } + + size = nextSize; + } + + @override + void performLayout() { + _lastIndexThatFits = -1; + if (firstChild == null) { + size = constraints.smallest; + return; + } + + _layoutChildren(); + _placeChildren(); + } + + @override + void paint(PaintingContext context, Offset offset) { + visitChildren((RenderObject renderObjectChild) { + final RenderBox child = renderObjectChild as RenderBox; + final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData; + if (!childParentData.shouldPaint) { + return; + } + + context.paintChild(child, childParentData.offset + offset); + }); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! ToolbarItemsParentData) { + child.parentData = ToolbarItemsParentData(); + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + RenderBox? child = lastChild; + while (child != null) { + // The x, y parameters have the top left of the node's box as the origin. + final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData; + + // Don't hit test children aren't shown. + if (!childParentData.shouldPaint) { + child = childParentData.previousSibling; + continue; + } + + final bool isHit = result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - childParentData.offset); + return child!.hitTest(result, position: transformed); + }, + ); + if (isHit) { + return true; + } + child = childParentData.previousSibling; + } + return false; + } + + // Visit only the children that should be painted. + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + visitChildren((RenderObject renderObjectChild) { + final RenderBox child = renderObjectChild as RenderBox; + final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData; + if (childParentData.shouldPaint) { + visitor(renderObjectChild); + } + }); + } +} + +// The Material-styled toolbar outline. Fill it with any widgets you want. No +// overflow ability. +class _TextSelectionToolbarContainer extends StatelessWidget { + const _TextSelectionToolbarContainer({ + required this.child, + }); + + final Widget child; + + // These colors were taken from a screenshot of a Pixel 6 emulator running + // Android API level 34. + static const Color _defaultColorLight = Color(0xffffffff); + static const Color _defaultColorDark = Color(0xff424242); + + static Color _getColor(ColorScheme colorScheme) { + final bool isDefaultSurface = switch (colorScheme.brightness) { + Brightness.light => identical(ThemeData().colorScheme.surface, colorScheme.surface), + Brightness.dark => identical(ThemeData.dark().colorScheme.surface, colorScheme.surface), + }; + if (!isDefaultSurface) { + return colorScheme.surface; + } + return switch (colorScheme.brightness) { + Brightness.light => _defaultColorLight, + Brightness.dark => _defaultColorDark, + }; + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + return Material( + // This value was eyeballed to match the native text selection menu on + // a Pixel 6 emulator running Android API level 34. + borderRadius: const BorderRadius.all(Radius.circular(_kToolbarHeight / 2)), + clipBehavior: Clip.antiAlias, + color: _getColor(theme.colorScheme), + elevation: 1.0, + type: MaterialType.card, + child: child, + ); + } +} + +// A button styled like a Material native Android text selection overflow menu +// forward and back controls. +class _TextSelectionToolbarOverflowButton extends StatelessWidget { + const _TextSelectionToolbarOverflowButton({ + required this.icon, + this.onPressed, + this.tooltip, + }); + + final Icon icon; + final VoidCallback? onPressed; + final String? tooltip; + + @override + Widget build(BuildContext context) { + return Material( + type: MaterialType.card, + color: const Color(0x00000000), + child: IconButton( + // TODO(justinmc): This should be an AnimatedIcon, but + // AnimatedIcons doesn't yet support arrow_back to more_vert. + // https://github.com/flutter/flutter/issues/51209 + icon: icon, + onPressed: onPressed, + tooltip: tooltip, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection_toolbar_text_button.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection_toolbar_text_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..844da98ce053e81fade5cabab5ec68ff66b8d948 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_selection_toolbar_text_button.dart @@ -0,0 +1,179 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'color_scheme.dart'; +import 'constants.dart'; +import 'text_button.dart'; +import 'theme.dart'; + +enum _TextSelectionToolbarItemPosition { + /// The first item among multiple in the menu. + first, + + /// One of several items, not the first or last. + middle, + + /// The last item among multiple in the menu. + last, + + /// The only item in the menu. + only, +} + +/// A button styled like a Material native Android text selection menu button. +class TextSelectionToolbarTextButton extends StatelessWidget { + /// Creates an instance of TextSelectionToolbarTextButton. + const TextSelectionToolbarTextButton({ + super.key, + required this.child, + required this.padding, + this.onPressed, + this.alignment, + }); + + // These values were eyeballed to match the native text selection menu on a + // Pixel 2 running Android 10. + static const double _kMiddlePadding = 9.5; + static const double _kEndPadding = 14.5; + + /// {@template flutter.material.TextSelectionToolbarTextButton.child} + /// The child of this button. + /// + /// Usually a [Text]. + /// {@endtemplate} + final Widget child; + + /// {@template flutter.material.TextSelectionToolbarTextButton.onPressed} + /// Called when this button is pressed. + /// {@endtemplate} + final VoidCallback? onPressed; + + /// The padding between the button's edge and its child. + /// + /// In a standard Material [TextSelectionToolbar], the padding depends on the + /// button's position within the toolbar. + /// + /// See also: + /// + /// * [getPadding], which calculates the standard padding based on the + /// button's position. + /// * [ButtonStyle.padding], which is where this padding is applied. + final EdgeInsets padding; + + /// The alignment of the button's child. + /// + /// By default, this will be [Alignment.center]. + /// + /// See also: + /// + /// * [ButtonStyle.alignment], which is where this alignment is applied. + final AlignmentGeometry? alignment; + + /// Returns the standard padding for a button at index out of a total number + /// of buttons. + /// + /// Standard Material [TextSelectionToolbar]s have buttons with different + /// padding depending on their position in the toolbar. + static EdgeInsets getPadding(int index, int total) { + assert(total > 0 && index >= 0 && index < total); + final _TextSelectionToolbarItemPosition position = _getPosition(index, total); + return EdgeInsets.only( + left: _getLeftPadding(position), + right: _getRightPadding(position), + ); + } + + static double _getLeftPadding(_TextSelectionToolbarItemPosition position) { + if (position == _TextSelectionToolbarItemPosition.first + || position == _TextSelectionToolbarItemPosition.only) { + return _kEndPadding; + } + return _kMiddlePadding; + } + + static double _getRightPadding(_TextSelectionToolbarItemPosition position) { + if (position == _TextSelectionToolbarItemPosition.last + || position == _TextSelectionToolbarItemPosition.only) { + return _kEndPadding; + } + return _kMiddlePadding; + } + + static _TextSelectionToolbarItemPosition _getPosition(int index, int total) { + if (index == 0) { + return total == 1 + ? _TextSelectionToolbarItemPosition.only + : _TextSelectionToolbarItemPosition.first; + } + if (index == total - 1) { + return _TextSelectionToolbarItemPosition.last; + } + return _TextSelectionToolbarItemPosition.middle; + } + + /// Returns a copy of the current [TextSelectionToolbarTextButton] instance + /// with specific overrides. + TextSelectionToolbarTextButton copyWith({ + Widget? child, + VoidCallback? onPressed, + EdgeInsets? padding, + AlignmentGeometry? alignment, + }) { + return TextSelectionToolbarTextButton( + onPressed: onPressed ?? this.onPressed, + padding: padding ?? this.padding, + alignment: alignment ?? this.alignment, + child: child ?? this.child, + ); + } + + // These colors were taken from a screenshot of a Pixel 6 emulator running + // Android API level 34. + static const Color _defaultForegroundColorLight = Color(0xff000000); + static const Color _defaultForegroundColorDark = Color(0xffffffff); + + // The background color is hardcoded to transparent by default so the buttons + // are the color of the container behind them. For example TextSelectionToolbar + // hardcodes the color value, and TextSelectionToolbarTextButtons that are its + // children become that color. + static const Color _defaultBackgroundColorTransparent = Color(0x00000000); + + static Color _getForegroundColor(ColorScheme colorScheme) { + final bool isDefaultOnSurface = switch (colorScheme.brightness) { + Brightness.light => identical(ThemeData().colorScheme.onSurface, colorScheme.onSurface), + Brightness.dark => identical(ThemeData.dark().colorScheme.onSurface, colorScheme.onSurface), + }; + if (!isDefaultOnSurface) { + return colorScheme.onSurface; + } + return switch (colorScheme.brightness) { + Brightness.light => _defaultForegroundColorLight, + Brightness.dark => _defaultForegroundColorDark, + }; + } + + @override + Widget build(BuildContext context) { + final ColorScheme colorScheme = Theme.of(context).colorScheme; + return TextButton( + style: TextButton.styleFrom( + backgroundColor: _defaultBackgroundColorTransparent, + foregroundColor: _getForegroundColor(colorScheme), + shape: const RoundedRectangleBorder(), + minimumSize: const Size(kMinInteractiveDimension, kMinInteractiveDimension), + padding: padding, + alignment: alignment, + textStyle: const TextStyle( + // This value was eyeballed from a screenshot of a Pixel 6 emulator + // running Android API level 34. + fontWeight: FontWeight.w400, + ), + ), + onPressed: onPressed, + child: child, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..6d1363b3bbdb4ab1cd37fd0829b8bd9a8013b9db --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/text_theme.dart @@ -0,0 +1,889 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; + +import 'typography.dart'; + +/// Material design text theme. +/// +/// Definitions for the various typographical styles found in Material Design +/// (e.g., labelLarge, bodySmall). Rather than creating a [TextTheme] directly, +/// you can obtain an instance as [Typography.black] or [Typography.white]. +/// +/// To obtain the current text theme, call [Theme.of] with the current +/// [BuildContext] and read the [ThemeData.textTheme] property. +/// +/// The names of the TextTheme properties match this table from the +/// [Material Design spec](https://m3.material.io/styles/typography/tokens). +/// +/// ![](https://lh3.googleusercontent.com/Yvngs5mQSjXa_9T4X3JDucO62c5hdZHPDa7qeRH6DsJQvGr_q7EBrTkhkPiQd9OeR1v_Uk38Cjd9nUpP3nevDyHpKWuXSfQ1Gq78bOnBN7sr=s0) +/// +/// The Material Design typography scheme was significantly changed in the +/// current (2021) version of the specification +/// ([https://m3.material.io/styles/typography/tokens](https://m3.material.io/styles/typography/tokens)). +/// +/// The names of the 2018 TextTheme properties match this table from the +/// [Material Design spec](https://material.io/design/typography/the-type-system.html#type-scale) +/// with two exceptions: the styles called H1-H6 in the spec are +/// headline1-headline6 in the API, and body1,body2 are called +/// bodyText1 and bodyText2. +/// +/// The 2018 spec has thirteen text styles: +/// +/// | NAME | SIZE | WEIGHT | SPACING | | +/// |------------|------|---------|----------|-------------| +/// | headline1 | 96.0 | light | -1.5 | | +/// | headline2 | 60.0 | light | -0.5 | | +/// | headline3 | 48.0 | regular | 0.0 | | +/// | headline4 | 34.0 | regular | 0.25 | | +/// | headline5 | 24.0 | regular | 0.0 | | +/// | headline6 | 20.0 | medium | 0.15 | | +/// | subtitle1 | 16.0 | regular | 0.15 | | +/// | subtitle2 | 14.0 | medium | 0.1 | | +/// | body1 | 16.0 | regular | 0.5 | (bodyText1) | +/// | body2 | 14.0 | regular | 0.25 | (bodyText2) | +/// | button | 14.0 | medium | 1.25 | | +/// | caption | 12.0 | regular | 0.4 | | +/// | overline | 10.0 | regular | 1.5 | | +/// +/// ...where "light" is `FontWeight.w300`, "regular" is `FontWeight.w400` and +/// "medium" is `FontWeight.w500`. +/// +/// By default, text styles are initialized to match the 2018 Material Design +/// specification as listed above. To provide backwards compatibility, the 2014 +/// specification is also available. +/// +/// To explicitly configure a [Theme] for the 2018 sizes, weights, and letter +/// spacings, you can initialize its [ThemeData.typography] value using +/// [Typography.material2018]. The [Typography] constructor defaults to this +/// configuration. To configure a [Theme] for the 2014 sizes, weights, and letter +/// spacings, initialize its [ThemeData.typography] value using +/// [Typography.material2014]. +/// +/// See also: +/// +/// * [Typography], the class that generates [TextTheme]s appropriate for a platform. +/// * [Theme], for other aspects of a Material Design application that can be +/// globally adjusted, such as the color scheme. +/// * <https://material.io/design/typography/> +@immutable +class TextTheme with Diagnosticable { + /// Creates a text theme that uses the given values. + /// + /// Rather than creating a new text theme, consider using [Typography.black] + /// or [Typography.white], which implement the typography styles in the + /// Material Design specification: + /// + /// <https://material.io/design/typography/#type-scale> + /// + /// If you do decide to create your own text theme, consider using one of + /// those predefined themes as a starting point for [copyWith] or [apply]. + /// + /// The 2018 styles cannot be mixed with the 2021 styles. Only one or the + /// other is allowed in this constructor. The 2018 styles are deprecated and + /// will eventually be removed. + const TextTheme({ + TextStyle? displayLarge, + TextStyle? displayMedium, + TextStyle? displaySmall, + this.headlineLarge, + TextStyle? headlineMedium, + TextStyle? headlineSmall, + TextStyle? titleLarge, + TextStyle? titleMedium, + TextStyle? titleSmall, + TextStyle? bodyLarge, + TextStyle? bodyMedium, + TextStyle? bodySmall, + TextStyle? labelLarge, + this.labelMedium, + TextStyle? labelSmall, + @Deprecated( + 'Use displayLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline1, + @Deprecated( + 'Use displayMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline2, + @Deprecated( + 'Use displaySmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline3, + @Deprecated( + 'Use headlineMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline4, + @Deprecated( + 'Use headlineSmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline5, + @Deprecated( + 'Use titleLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline6, + @Deprecated( + 'Use titleMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? subtitle1, + @Deprecated( + 'Use titleSmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? subtitle2, + @Deprecated( + 'Use bodyLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? bodyText1, + @Deprecated( + 'Use bodyMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? bodyText2, + @Deprecated( + 'Use bodySmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? caption, + @Deprecated( + 'Use labelLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? button, + @Deprecated( + 'Use labelSmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? overline, + }) : assert( + (displayLarge == null && displayMedium == null && displaySmall == null && headlineMedium == null && + headlineSmall == null && titleLarge == null && titleMedium == null && titleSmall == null && + bodyLarge == null && bodyMedium == null && bodySmall == null && labelLarge == null && labelSmall == null) || + (headline1 == null && headline2 == null && headline3 == null && headline4 == null && + headline5 == null && headline6 == null && subtitle1 == null && subtitle2 == null && + bodyText1 == null && bodyText2 == null && caption == null && button == null && overline == null), + 'Cannot mix 2018 and 2021 terms in call to TextTheme() constructor.' + ), + displayLarge = displayLarge ?? headline1, + displayMedium = displayMedium ?? headline2, + displaySmall = displaySmall ?? headline3, + headlineMedium = headlineMedium ?? headline4, + headlineSmall = headlineSmall ?? headline5, + titleLarge = titleLarge ?? headline6, + titleMedium = titleMedium ?? subtitle1, + titleSmall = titleSmall ?? subtitle2, + bodyLarge = bodyLarge ?? bodyText1, + bodyMedium = bodyMedium ?? bodyText2, + bodySmall = bodySmall ?? caption, + labelLarge = labelLarge ?? button, + labelSmall = labelSmall ?? overline; + + /// Largest of the display styles. + /// + /// As the largest text on the screen, display styles are reserved for short, + /// important text or numerals. They work best on large screens. + final TextStyle? displayLarge; + + /// Middle size of the display styles. + /// + /// As the largest text on the screen, display styles are reserved for short, + /// important text or numerals. They work best on large screens. + final TextStyle? displayMedium; + + /// Smallest of the display styles. + /// + /// As the largest text on the screen, display styles are reserved for short, + /// important text or numerals. They work best on large screens. + final TextStyle? displaySmall; + + /// Largest of the headline styles. + /// + /// Headline styles are smaller than display styles. They're best-suited for + /// short, high-emphasis text on smaller screens. + final TextStyle? headlineLarge; + + /// Middle size of the headline styles. + /// + /// Headline styles are smaller than display styles. They're best-suited for + /// short, high-emphasis text on smaller screens. + final TextStyle? headlineMedium; + + /// Smallest of the headline styles. + /// + /// Headline styles are smaller than display styles. They're best-suited for + /// short, high-emphasis text on smaller screens. + final TextStyle? headlineSmall; + + /// Largest of the title styles. + /// + /// Titles are smaller than headline styles and should be used for shorter, + /// medium-emphasis text. + final TextStyle? titleLarge; + + /// Middle size of the title styles. + /// + /// Titles are smaller than headline styles and should be used for shorter, + /// medium-emphasis text. + final TextStyle? titleMedium; + + /// Smallest of the title styles. + /// + /// Titles are smaller than headline styles and should be used for shorter, + /// medium-emphasis text. + final TextStyle? titleSmall; + + /// Largest of the body styles. + /// + /// Body styles are used for longer passages of text. + final TextStyle? bodyLarge; + + /// Middle size of the body styles. + /// + /// Body styles are used for longer passages of text. + /// + /// The default text style for [Material]. + final TextStyle? bodyMedium; + + /// Smallest of the body styles. + /// + /// Body styles are used for longer passages of text. + final TextStyle? bodySmall; + + /// Largest of the label styles. + /// + /// Label styles are smaller, utilitarian styles, used for areas of the UI + /// such as text inside of components or very small supporting text in the + /// content body, like captions. + /// + /// Used for text on [ElevatedButton], [TextButton] and [OutlinedButton]. + final TextStyle? labelLarge; + + /// Middle size of the label styles. + /// + /// Label styles are smaller, utilitarian styles, used for areas of the UI + /// such as text inside of components or very small supporting text in the + /// content body, like captions. + final TextStyle? labelMedium; + + /// Smallest of the label styles. + /// + /// Label styles are smaller, utilitarian styles, used for areas of the UI + /// such as text inside of components or very small supporting text in the + /// content body, like captions. + final TextStyle? labelSmall; + + /// Extremely large text. + @Deprecated( + 'Use displayLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get headline1 => displayLarge; + + /// Very, very large text. + /// + /// Used for the date in the dialog shown by [showDatePicker]. + @Deprecated( + 'Use displayMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get headline2 => displayMedium; + + /// Very large text. + @Deprecated( + 'Use displaySmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get headline3 => displaySmall; + + /// Large text. + @Deprecated( + 'Use headlineMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get headline4 => headlineMedium; + + /// Used for large text in dialogs (e.g., the month and year in the dialog + /// shown by [showDatePicker]). + @Deprecated( + 'Use headlineSmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get headline5 => headlineSmall; + + /// Used for the primary text in app bars and dialogs (e.g., [AppBar.title] + /// and [AlertDialog.title]). + @Deprecated( + 'Use titleLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get headline6 => titleLarge; + + /// Used for the primary text in lists (e.g., [ListTile.title]). + @Deprecated( + 'Use titleMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get subtitle1 => titleMedium; + + /// For medium emphasis text that's a little smaller than [titleMedium]. + @Deprecated( + 'Use titleSmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get subtitle2 => titleSmall; + + /// Used for emphasizing text that would otherwise be [bodyMedium]. + @Deprecated( + 'Use bodyLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get bodyText1 => bodyLarge; + + /// The default text style for [Material]. + @Deprecated( + 'Use bodyMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get bodyText2 => bodyMedium; + + /// Used for auxiliary text associated with images. + @Deprecated( + 'Use bodySmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get caption => bodySmall; + + /// Used for text on [ElevatedButton], [TextButton] and [OutlinedButton]. + @Deprecated( + 'Use labelLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get button => labelLarge; + + /// The smallest style. + /// + /// Typically used for captions or to introduce a (larger) headline. + @Deprecated( + 'Use labelSmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? get overline => labelSmall; + + /// Creates a copy of this text theme but with the given fields replaced with + /// the new values. + /// + /// Consider using [Typography.black] or [Typography.white], which implement + /// the typography styles in the Material Design specification, as a starting + /// point. + /// + /// {@tool snippet} + /// + /// ```dart + /// /// A Widget that sets the ambient theme's title text color for its + /// /// descendants, while leaving other ambient theme attributes alone. + /// class TitleColorThemeCopy extends StatelessWidget { + /// const TitleColorThemeCopy({super.key, required this.titleColor, required this.child}); + /// + /// final Color titleColor; + /// final Widget child; + /// + /// @override + /// Widget build(BuildContext context) { + /// final ThemeData theme = Theme.of(context); + /// return Theme( + /// data: theme.copyWith( + /// textTheme: theme.textTheme.copyWith( + /// titleLarge: theme.textTheme.titleLarge!.copyWith( + /// color: titleColor, + /// ), + /// ), + /// ), + /// child: child, + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [merge] is used instead of [copyWith] when you want to merge all + /// of the fields of a TextTheme instead of individual fields. + TextTheme copyWith({ + TextStyle? displayLarge, + TextStyle? displayMedium, + TextStyle? displaySmall, + TextStyle? headlineLarge, + TextStyle? headlineMedium, + TextStyle? headlineSmall, + TextStyle? titleLarge, + TextStyle? titleMedium, + TextStyle? titleSmall, + TextStyle? bodyLarge, + TextStyle? bodyMedium, + TextStyle? bodySmall, + TextStyle? labelLarge, + TextStyle? labelMedium, + TextStyle? labelSmall, + @Deprecated( + 'Use displayLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline1, + @Deprecated( + 'Use displayMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline2, + @Deprecated( + 'Use displaySmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline3, + @Deprecated( + 'Use headlineMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline4, + @Deprecated( + 'Use headlineSmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline5, + @Deprecated( + 'Use titleLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? headline6, + @Deprecated( + 'Use titleMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? subtitle1, + @Deprecated( + 'Use titleSmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? subtitle2, + @Deprecated( + 'Use bodyLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? bodyText1, + @Deprecated( + 'Use bodyMedium instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? bodyText2, + @Deprecated( + 'Use bodySmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? caption, + @Deprecated( + 'Use labelLarge instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? button, + @Deprecated( + 'Use labelSmall instead. ' + 'This feature was deprecated after v3.1.0-0.0.pre.', + ) + TextStyle? overline, + }) { + assert( + (displayLarge == null && displayMedium == null && displaySmall == null && headlineMedium == null && + headlineSmall == null && titleLarge == null && titleMedium == null && titleSmall == null && + bodyLarge == null && bodyMedium == null && bodySmall == null && labelLarge == null && labelSmall == null) || + (headline1 == null && headline2 == null && headline3 == null && headline4 == null && + headline5 == null && headline6 == null && subtitle1 == null && subtitle2 == null && + bodyText1 == null && bodyText2 == null && caption == null && button == null && overline == null), + 'Cannot mix 2018 and 2021 terms in call to TextTheme() constructor.' + ); + return TextTheme( + displayLarge: displayLarge ?? headline1 ?? this.displayLarge, + displayMedium: displayMedium ?? headline2 ?? this.displayMedium, + displaySmall: displaySmall ?? headline3 ?? this.displaySmall, + headlineLarge: headlineLarge ?? this.headlineLarge, + headlineMedium: headlineMedium ?? headline4 ?? this.headlineMedium, + headlineSmall: headlineSmall ?? headline5 ?? this.headlineSmall, + titleLarge: titleLarge ?? headline6 ?? this.titleLarge, + titleMedium: titleMedium ?? subtitle1 ?? this.titleMedium, + titleSmall: titleSmall ?? subtitle2 ?? this.titleSmall, + bodyLarge: bodyLarge ?? bodyText1 ?? this.bodyLarge, + bodyMedium: bodyMedium ?? bodyText2 ?? this.bodyMedium, + bodySmall: bodySmall ?? caption ?? this.bodySmall, + labelLarge: labelLarge ?? button ?? this.labelLarge, + labelMedium: labelMedium ?? this.labelMedium, + labelSmall: labelSmall ?? overline ?? this.labelSmall, + ); + } + + /// Creates a new [TextTheme] where each text style from this object has been + /// merged with the matching text style from the `other` object. + /// + /// The merging is done by calling [TextStyle.merge] on each respective pair + /// of text styles from this and the [other] text themes and is subject to + /// the value of [TextStyle.inherit] flag. For more details, see the + /// documentation on [TextStyle.merge] and [TextStyle.inherit]. + /// + /// If this theme, or the `other` theme has members that are null, then the + /// non-null one (if any) is used. If the `other` theme is itself null, then + /// this [TextTheme] is returned unchanged. If values in both are set, then + /// the values are merged using [TextStyle.merge]. + /// + /// This is particularly useful if one [TextTheme] defines one set of + /// properties and another defines a different set, e.g. having colors + /// defined in one text theme and font sizes in another, or when one + /// [TextTheme] has only some fields defined, and you want to define the rest + /// by merging it with a default theme. + /// + /// {@tool snippet} + /// + /// ```dart + /// /// A Widget that sets the ambient theme's title text color for its + /// /// descendants, while leaving other ambient theme attributes alone. + /// class TitleColorTheme extends StatelessWidget { + /// const TitleColorTheme({super.key, required this.child, required this.titleColor}); + /// + /// final Color titleColor; + /// final Widget child; + /// + /// @override + /// Widget build(BuildContext context) { + /// ThemeData theme = Theme.of(context); + /// // This partialTheme is incomplete: it only has the title style + /// // defined. Just replacing theme.textTheme with partialTheme would + /// // set the title, but everything else would be null. This isn't very + /// // useful, so merge it with the existing theme to keep all of the + /// // preexisting definitions for the other styles. + /// final TextTheme partialTheme = TextTheme(titleLarge: TextStyle(color: titleColor)); + /// theme = theme.copyWith(textTheme: theme.textTheme.merge(partialTheme)); + /// return Theme(data: theme, child: child); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [copyWith] is used instead of [merge] when you wish to override + /// individual fields in the [TextTheme] instead of merging all of the + /// fields of two [TextTheme]s. + TextTheme merge(TextTheme? other) { + if (other == null) { + return this; + } + return copyWith( + displayLarge: displayLarge?.merge(other.displayLarge) ?? other.displayLarge, + displayMedium: displayMedium?.merge(other.displayMedium) ?? other.displayMedium, + displaySmall: displaySmall?.merge(other.displaySmall) ?? other.displaySmall, + headlineLarge: headlineLarge?.merge(other.headlineLarge) ?? other.headlineLarge, + headlineMedium: headlineMedium?.merge(other.headlineMedium) ?? other.headlineMedium, + headlineSmall: headlineSmall?.merge(other.headlineSmall) ?? other.headlineSmall, + titleLarge: titleLarge?.merge(other.titleLarge) ?? other.titleLarge, + titleMedium: titleMedium?.merge(other.titleMedium) ?? other.titleMedium, + titleSmall: titleSmall?.merge(other.titleSmall) ?? other.titleSmall, + bodyLarge: bodyLarge?.merge(other.bodyLarge) ?? other.bodyLarge, + bodyMedium: bodyMedium?.merge(other.bodyMedium) ?? other.bodyMedium, + bodySmall: bodySmall?.merge(other.bodySmall) ?? other.bodySmall, + labelLarge: labelLarge?.merge(other.labelLarge) ?? other.labelLarge, + labelMedium: labelMedium?.merge(other.labelMedium) ?? other.labelMedium, + labelSmall: labelSmall?.merge(other.labelSmall) ?? other.labelSmall, + ); + } + + /// Creates a copy of this text theme but with the given field replaced in + /// each of the individual text styles. + /// + /// The `displayColor` is applied to [displayLarge], [displayMedium], + /// [displaySmall], [headlineLarge], [headlineMedium], and [bodySmall]. The + /// `bodyColor` is applied to the remaining text styles. + /// + /// Consider using [Typography.black] or [Typography.white], which implement + /// the typography styles in the Material Design specification, as a starting + /// point. + TextTheme apply({ + String? fontFamily, + List<String>? fontFamilyFallback, + String? package, + double fontSizeFactor = 1.0, + double fontSizeDelta = 0.0, + Color? displayColor, + Color? bodyColor, + TextDecoration? decoration, + Color? decorationColor, + TextDecorationStyle? decorationStyle, + }) { + return TextTheme( + displayLarge: displayLarge?.apply( + color: displayColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + displayMedium: displayMedium?.apply( + color: displayColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + displaySmall: displaySmall?.apply( + color: displayColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + headlineLarge: headlineLarge?.apply( + color: displayColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + headlineMedium: headlineMedium?.apply( + color: displayColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + headlineSmall: headlineSmall?.apply( + color: bodyColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + titleLarge: titleLarge?.apply( + color: bodyColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + titleMedium: titleMedium?.apply( + color: bodyColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + titleSmall: titleSmall?.apply( + color: bodyColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + bodyLarge: bodyLarge?.apply( + color: bodyColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + bodyMedium: bodyMedium?.apply( + color: bodyColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + bodySmall: bodySmall?.apply( + color: displayColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + labelLarge: labelLarge?.apply( + color: bodyColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + labelMedium: labelMedium?.apply( + color: bodyColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + labelSmall: labelSmall?.apply( + color: bodyColor, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSizeFactor: fontSizeFactor, + fontSizeDelta: fontSizeDelta, + package: package, + ), + ); + } + + /// Linearly interpolate between two text themes. + /// + /// {@macro dart.ui.shadow.lerp} + static TextTheme lerp(TextTheme? a, TextTheme? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return TextTheme( + displayLarge: TextStyle.lerp(a?.displayLarge, b?.displayLarge, t), + displayMedium: TextStyle.lerp(a?.displayMedium, b?.displayMedium, t), + displaySmall: TextStyle.lerp(a?.displaySmall, b?.displaySmall, t), + headlineLarge: TextStyle.lerp(a?.headlineLarge, b?.headlineLarge, t), + headlineMedium: TextStyle.lerp(a?.headlineMedium, b?.headlineMedium, t), + headlineSmall: TextStyle.lerp(a?.headlineSmall, b?.headlineSmall, t), + titleLarge: TextStyle.lerp(a?.titleLarge, b?.titleLarge, t), + titleMedium: TextStyle.lerp(a?.titleMedium, b?.titleMedium, t), + titleSmall: TextStyle.lerp(a?.titleSmall, b?.titleSmall, t), + bodyLarge: TextStyle.lerp(a?.bodyLarge, b?.bodyLarge, t), + bodyMedium: TextStyle.lerp(a?.bodyMedium, b?.bodyMedium, t), + bodySmall: TextStyle.lerp(a?.bodySmall, b?.bodySmall, t), + labelLarge: TextStyle.lerp(a?.labelLarge, b?.labelLarge, t), + labelMedium: TextStyle.lerp(a?.labelMedium, b?.labelMedium, t), + labelSmall: TextStyle.lerp(a?.labelSmall, b?.labelSmall, t), + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is TextTheme + && displayLarge == other.displayLarge + && displayMedium == other.displayMedium + && displaySmall == other.displaySmall + && headlineLarge == other.headlineLarge + && headlineMedium == other.headlineMedium + && headlineSmall == other.headlineSmall + && titleLarge == other.titleLarge + && titleMedium == other.titleMedium + && titleSmall == other.titleSmall + && bodyLarge == other.bodyLarge + && bodyMedium == other.bodyMedium + && bodySmall == other.bodySmall + && labelLarge == other.labelLarge + && labelMedium == other.labelMedium + && labelSmall == other.labelSmall; + } + + @override + int get hashCode => Object.hash( + displayLarge, + displayMedium, + displaySmall, + headlineLarge, + headlineMedium, + headlineSmall, + titleLarge, + titleMedium, + titleSmall, + bodyLarge, + bodyMedium, + bodySmall, + labelLarge, + labelMedium, + labelSmall, + ); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final TextTheme defaultTheme = Typography.material2018(platform: defaultTargetPlatform).black; + properties.add(DiagnosticsProperty<TextStyle>('displayLarge', displayLarge, defaultValue: defaultTheme.displayLarge)); + properties.add(DiagnosticsProperty<TextStyle>('displayMedium', displayMedium, defaultValue: defaultTheme.displayMedium)); + properties.add(DiagnosticsProperty<TextStyle>('displaySmall', displaySmall, defaultValue: defaultTheme.displaySmall)); + properties.add(DiagnosticsProperty<TextStyle>('headlineLarge', headlineLarge, defaultValue: defaultTheme.headlineLarge)); + properties.add(DiagnosticsProperty<TextStyle>('headlineMedium', headlineMedium, defaultValue: defaultTheme.headlineMedium)); + properties.add(DiagnosticsProperty<TextStyle>('headlineSmall', headlineSmall, defaultValue: defaultTheme.headlineSmall)); + properties.add(DiagnosticsProperty<TextStyle>('titleLarge', titleLarge, defaultValue: defaultTheme.titleLarge)); + properties.add(DiagnosticsProperty<TextStyle>('titleMedium', titleMedium, defaultValue: defaultTheme.titleMedium)); + properties.add(DiagnosticsProperty<TextStyle>('titleSmall', titleSmall, defaultValue: defaultTheme.titleSmall)); + properties.add(DiagnosticsProperty<TextStyle>('bodyLarge', bodyLarge, defaultValue: defaultTheme.bodyLarge)); + properties.add(DiagnosticsProperty<TextStyle>('bodyMedium', bodyMedium, defaultValue: defaultTheme.bodyMedium)); + properties.add(DiagnosticsProperty<TextStyle>('bodySmall', bodySmall, defaultValue: defaultTheme.bodySmall)); + properties.add(DiagnosticsProperty<TextStyle>('labelLarge', labelLarge, defaultValue: defaultTheme.labelLarge)); + properties.add(DiagnosticsProperty<TextStyle>('labelMedium', labelMedium, defaultValue: defaultTheme.labelMedium)); + properties.add(DiagnosticsProperty<TextStyle>('labelSmall', labelSmall, defaultValue: defaultTheme.labelSmall)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..c55efc2aeb291fc9d3812ef62a0d803977722d17 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/theme.dart @@ -0,0 +1,245 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; + +import 'material_localizations.dart'; +import 'theme_data.dart'; +import 'typography.dart'; + +export 'theme_data.dart' show Brightness, ThemeData; + +/// The duration over which theme changes animate by default. +const Duration kThemeAnimationDuration = Duration(milliseconds: 200); + +/// Applies a theme to descendant widgets. +/// +/// A theme describes the colors and typographic choices of an application. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=oTvQDJOBXmM} +/// +/// Descendant widgets obtain the current theme's [ThemeData] object using +/// [Theme.of]. When a widget uses [Theme.of], it is automatically rebuilt if +/// the theme later changes, so that the changes can be applied. +/// +/// The [Theme] widget implies an [IconTheme] widget, set to the value of the +/// [ThemeData.iconTheme] of the [data] for the [Theme]. +/// +/// See also: +/// +/// * [ThemeData], which describes the actual configuration of a theme. +/// * [AnimatedTheme], which animates the [ThemeData] when it changes rather +/// than changing the theme all at once. +/// * [MaterialApp], which includes an [AnimatedTheme] widget configured via +/// the [MaterialApp.theme] argument. +class Theme extends StatelessWidget { + /// Applies the given theme [data] to [child]. + const Theme({ + super.key, + required this.data, + required this.child, + }); + + /// Specifies the color and typography values for descendant widgets. + final ThemeData data; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + static final ThemeData _kFallbackTheme = ThemeData.fallback(); + + /// The data from the closest [Theme] instance that encloses the given + /// context. + /// + /// If the given context is enclosed in a [Localizations] widget providing + /// [MaterialLocalizations], the returned data is localized according to the + /// nearest available [MaterialLocalizations]. + /// + /// Defaults to [ThemeData.fallback] if there is no [Theme] in the given + /// build context. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// @override + /// Widget build(BuildContext context) { + /// return Text( + /// 'Example', + /// style: Theme.of(context).textTheme.titleLarge, + /// ); + /// } + /// ``` + /// + /// When the [Theme] is actually created in the same `build` function + /// (possibly indirectly, e.g. as part of a [MaterialApp]), the `context` + /// argument to the `build` function can't be used to find the [Theme] (since + /// it's "above" the widget being returned). In such cases, the following + /// technique with a [Builder] can be used to provide a new scope with a + /// [BuildContext] that is "under" the [Theme]: + /// + /// ```dart + /// @override + /// Widget build(BuildContext context) { + /// return MaterialApp( + /// theme: ThemeData.light(), + /// home: Builder( + /// // Create an inner BuildContext so that we can refer to + /// // the Theme with Theme.of(). + /// builder: (BuildContext context) { + /// return Center( + /// child: Text( + /// 'Example', + /// style: Theme.of(context).textTheme.titleLarge, + /// ), + /// ); + /// }, + /// ), + /// ); + /// } + /// ``` + static ThemeData of(BuildContext context) { + final _InheritedTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedTheme>(); + final MaterialLocalizations? localizations = Localizations.of<MaterialLocalizations>(context, MaterialLocalizations); + final ScriptCategory category = localizations?.scriptCategory ?? ScriptCategory.englishLike; + final ThemeData theme = inheritedTheme?.theme.data ?? _kFallbackTheme; + return ThemeData.localize(theme, theme.typography.geometryThemeFor(category)); + } + + // The inherited themes in widgets library can not infer their values from + // Theme in material library. Wraps the child with these inherited themes to + // overrides their values directly. + Widget _wrapsWidgetThemes(BuildContext context, Widget child) { + final DefaultSelectionStyle selectionStyle = DefaultSelectionStyle.of(context); + return IconTheme( + data: data.iconTheme, + child: DefaultSelectionStyle( + selectionColor: data.textSelectionTheme.selectionColor ?? selectionStyle.selectionColor, + cursorColor: data.textSelectionTheme.cursorColor ?? selectionStyle.cursorColor, + child: child, + ), + ); + } + + @override + Widget build(BuildContext context) { + return _InheritedTheme( + theme: this, + child: CupertinoTheme( + // We're using a MaterialBasedCupertinoThemeData here instead of a + // CupertinoThemeData because it defers some properties to the Material + // ThemeData. + data: MaterialBasedCupertinoThemeData( + materialTheme: data, + ), + child: _wrapsWidgetThemes(context, child), + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ThemeData>('data', data, showName: false)); + } +} + +class _InheritedTheme extends InheritedTheme { + const _InheritedTheme({ + required this.theme, + required super.child, + }); + + final Theme theme; + + @override + Widget wrap(BuildContext context, Widget child) { + return Theme(data: theme.data, child: child); + } + + @override + bool updateShouldNotify(_InheritedTheme old) => theme.data != old.theme.data; +} + +/// An interpolation between two [ThemeData]s. +/// +/// This class specializes the interpolation of [Tween<ThemeData>] to call the +/// [ThemeData.lerp] method. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class ThemeDataTween extends Tween<ThemeData> { + /// Creates a [ThemeData] tween. + /// + /// The [begin] and [end] properties must be non-null before the tween is + /// first used, but the arguments can be null if the values are going to be + /// filled in later. + ThemeDataTween({ super.begin, super.end }); + + @override + ThemeData lerp(double t) => ThemeData.lerp(begin!, end!, t); +} + +/// Animated version of [Theme] which automatically transitions the colors, +/// etc, over a given duration whenever the given theme changes. +/// +/// Here's an illustration of what using this widget looks like, using a [curve] +/// of [Curves.elasticInOut]. +/// {@animation 250 266 https://flutter.github.io/assets-for-api-docs/assets/widgets/animated_theme.mp4} +/// +/// See also: +/// +/// * [Theme], which [AnimatedTheme] uses to actually apply the interpolated +/// theme. +/// * [ThemeData], which describes the actual configuration of a theme. +/// * [MaterialApp], which includes an [AnimatedTheme] widget configured via +/// the [MaterialApp.theme] argument. +class AnimatedTheme extends ImplicitlyAnimatedWidget { + /// Creates an animated theme. + /// + /// By default, the theme transition uses a linear curve. + const AnimatedTheme({ + super.key, + required this.data, + super.curve, + super.duration = kThemeAnimationDuration, + super.onEnd, + required this.child, + }); + + /// Specifies the color and typography values for descendant widgets. + final ThemeData data; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + AnimatedWidgetBaseState<AnimatedTheme> createState() => _AnimatedThemeState(); +} + +class _AnimatedThemeState extends AnimatedWidgetBaseState<AnimatedTheme> { + ThemeDataTween? _data; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _data = visitor(_data, widget.data, (dynamic value) => ThemeDataTween(begin: value as ThemeData))! as ThemeDataTween; + } + + @override + Widget build(BuildContext context) { + return Theme( + data: _data!.evaluate(animation), + child: widget.child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DiagnosticsProperty<ThemeDataTween>('data', _data, showName: false, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/theme_data.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/theme_data.dart new file mode 100644 index 0000000000000000000000000000000000000000..8ba11e8162a92d45e635d5b73fe3a6ff0c4425da --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/theme_data.dart @@ -0,0 +1,2728 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show Color, lerpDouble; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; + +import 'action_buttons.dart'; +import 'action_icons_theme.dart'; +import 'app_bar_theme.dart'; +import 'badge_theme.dart'; +import 'banner_theme.dart'; +import 'bottom_app_bar_theme.dart'; +import 'bottom_navigation_bar_theme.dart'; +import 'bottom_sheet_theme.dart'; +import 'button_bar_theme.dart'; +import 'button_theme.dart'; +import 'card_theme.dart'; +import 'checkbox_theme.dart'; +import 'chip_theme.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'constants.dart'; +import 'data_table_theme.dart'; +import 'date_picker_theme.dart'; +import 'dialog_theme.dart'; +import 'divider_theme.dart'; +import 'drawer_theme.dart'; +import 'dropdown_menu_theme.dart'; +import 'elevated_button_theme.dart'; +import 'expansion_tile_theme.dart'; +import 'filled_button_theme.dart'; +import 'floating_action_button_theme.dart'; +import 'icon_button_theme.dart'; +import 'ink_ripple.dart'; +import 'ink_sparkle.dart'; +import 'ink_splash.dart'; +import 'ink_well.dart' show InteractiveInkFeatureFactory; +import 'input_decorator.dart'; +import 'list_tile.dart'; +import 'list_tile_theme.dart'; +import 'menu_bar_theme.dart'; +import 'menu_button_theme.dart'; +import 'menu_theme.dart'; +import 'navigation_bar_theme.dart'; +import 'navigation_drawer_theme.dart'; +import 'navigation_rail_theme.dart'; +import 'outlined_button_theme.dart'; +import 'page_transitions_theme.dart'; +import 'popup_menu_theme.dart'; +import 'progress_indicator_theme.dart'; +import 'radio_theme.dart'; +import 'scrollbar_theme.dart'; +import 'search_bar_theme.dart'; +import 'search_view_theme.dart'; +import 'segmented_button_theme.dart'; +import 'slider_theme.dart'; +import 'snack_bar_theme.dart'; +import 'switch_theme.dart'; +import 'tab_bar_theme.dart'; +import 'text_button_theme.dart'; +import 'text_selection_theme.dart'; +import 'text_theme.dart'; +import 'time_picker_theme.dart'; +import 'toggle_buttons_theme.dart'; +import 'tooltip_theme.dart'; +import 'typography.dart'; + +export 'package:flutter/services.dart' show Brightness; + +// Examples can assume: +// late BuildContext context; + +/// Defines a customized theme for components with an `adaptive` factory constructor. +/// +/// Currently, only [Switch.adaptive] supports this class. +class Adaptation<T> { + /// Creates an [Adaptation]. + const Adaptation(); + + /// The adaptation's type. + Type get type => T; + + /// Typically, this is overridden to return an instance of a custom component + /// ThemeData class, like [SwitchThemeData], instead of the defaultValue. + /// + /// Factory constructors that support adaptations - currently only + /// [Switch.adaptive] - look for a [ThemeData.adaptations] member of the expected + /// type when computing their effective default component theme. If a matching + /// adaptation is not found, the component may choose to use a default adaptation. + /// For example, the [Switch.adaptive] component uses an empty [SwitchThemeData] + /// if a matching adaptation is not found, for the sake of backwards compatibility. + /// + /// {@tool dartpad} + /// This sample shows how to create and use subclasses of [Adaptation] that + /// define adaptive [SwitchThemeData]s. The [adapt] method in this example is + /// overridden to only customize cupertino-style switches, but it can also be + /// used to customize any other platforms. + /// + /// ** See code in examples/api/lib/material/switch/switch.4.dart ** + /// {@end-tool} + T adapt(ThemeData theme, T defaultValue) => defaultValue; +} + +/// An interface that defines custom additions to a [ThemeData] object. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=8-szcYzFVao} +/// +/// Typically used for custom colors. To use, subclass [ThemeExtension], +/// define a number of fields (e.g. [Color]s), and implement the [copyWith] and +/// [lerp] methods. The latter will ensure smooth transitions of properties when +/// switching themes. +/// +/// {@tool dartpad} +/// This sample shows how to create and use a subclass of [ThemeExtension] that +/// defines two colors. +/// +/// ** See code in examples/api/lib/material/theme/theme_extension.1.dart ** +/// {@end-tool} +abstract class ThemeExtension<T extends ThemeExtension<T>> { + /// Enable const constructor for subclasses. + const ThemeExtension(); + + /// The extension's type. + Object get type => T; + + /// Creates a copy of this theme extension with the given fields + /// replaced by the non-null parameter values. + ThemeExtension<T> copyWith(); + + /// Linearly interpolate with another [ThemeExtension] object. + /// + /// {@macro dart.ui.shadow.lerp} + ThemeExtension<T> lerp(covariant ThemeExtension<T>? other, double t); +} + +// Deriving these values is black magic. The spec claims that pressed buttons +// have a highlight of 0x66999999, but that's clearly wrong. The videos in the +// spec show that buttons have a composited highlight of #E1E1E1 on a background +// of #FAFAFA. Assuming that the highlight really has an opacity of 0x66, we can +// solve for the actual color of the highlight: +const Color _kLightThemeHighlightColor = Color(0x66BCBCBC); + +// The same video shows the splash compositing to #D7D7D7 on a background of +// #E1E1E1. Again, assuming the splash has an opacity of 0x66, we can solve for +// the actual color of the splash: +const Color _kLightThemeSplashColor = Color(0x66C8C8C8); + +// Unfortunately, a similar video isn't available for the dark theme, which +// means we assume the values in the spec are actually correct. +const Color _kDarkThemeHighlightColor = Color(0x40CCCCCC); +const Color _kDarkThemeSplashColor = Color(0x40CCCCCC); + +/// Configures the tap target and layout size of certain Material widgets. +/// +/// Changing the value in [ThemeData.materialTapTargetSize] will affect the +/// accessibility experience. +/// +/// Some of the impacted widgets include: +/// +/// * [FloatingActionButton], only the mini tap target size is increased. +/// * [MaterialButton] +/// * [OutlinedButton] +/// * [TextButton] +/// * [ElevatedButton] +/// * [IconButton] +/// * The time picker widget ([showTimePicker]) +/// * [SnackBar] +/// * [Chip] +/// * [RawChip] +/// * [InputChip] +/// * [ChoiceChip] +/// * [FilterChip] +/// * [ActionChip] +/// * [Radio] +/// * [Switch] +/// * [Checkbox] +enum MaterialTapTargetSize { + /// Expands the minimum tap target size to 48px by 48px. + /// + /// This is the default value of [ThemeData.materialTapTargetSize] and the + /// recommended size to conform to Android accessibility scanner + /// recommendations. + padded, + + /// Shrinks the tap target size to the minimum provided by the Material + /// specification. + shrinkWrap, +} + +/// Defines the configuration of the overall visual [Theme] for a [MaterialApp] +/// or a widget subtree within the app. +/// +/// The [MaterialApp] theme property can be used to configure the appearance +/// of the entire app. Widget subtrees within an app can override the app's +/// theme by including a [Theme] widget at the top of the subtree. +/// +/// Widgets whose appearance should align with the overall theme can obtain the +/// current theme's configuration with [Theme.of]. Material components typically +/// depend exclusively on the [colorScheme] and [textTheme]. These properties +/// are guaranteed to have non-null values. +/// +/// The static [Theme.of] method finds the [ThemeData] value specified for the +/// nearest [BuildContext] ancestor. This lookup is inexpensive, essentially +/// just a single HashMap access. It can sometimes be a little confusing +/// because [Theme.of] can not see a [Theme] widget that is defined in the +/// current build method's context. To overcome that, create a new custom widget +/// for the subtree that appears below the new [Theme], or insert a widget +/// that creates a new BuildContext, like [Builder]. +/// +/// {@tool dartpad} +/// This example demonstrates how a typical [MaterialApp] specifies +/// and uses a custom [Theme]. The theme's [ColorScheme] is based on a +/// single "seed" color and configures itself to match the platform's +/// current light or dark color configuration. The theme overrides the +/// default configuration of [FloatingActionButton] to show how to +/// customize the appearance a class of components. +/// +/// ** See code in examples/api/lib/material/theme_data/theme_data.0.dart ** +/// {@end-tool} +/// +/// See <https://material.io/design/color/> for +/// more discussion on how to pick the right colors. + +@immutable +class ThemeData with Diagnosticable { + /// Create a [ThemeData] that's used to configure a [Theme]. + /// + /// The [colorScheme] and [textTheme] are used by the Material components to + /// compute default values for visual properties. The API documentation for + /// each component widget explains exactly how the defaults are computed. + /// + /// When providing a [ColorScheme], apps can either provide one directly + /// with the [colorScheme] parameter, or have one generated for them by + /// using the [colorSchemeSeed] and [brightness] parameters. A generated + /// color scheme will be based on the tones of [colorSchemeSeed] and all of + /// its contrasting color will meet accessibility guidelines for readability. + /// (See [ColorScheme.fromSeed] for more details.) + /// + /// If the app wants to customize a generated color scheme, it can use + /// [ColorScheme.fromSeed] directly and then [ColorScheme.copyWith] on the + /// result to override any colors that need to be replaced. The result of + /// this can be used as the [colorScheme] directly. + /// + /// For historical reasons, instead of using a [colorSchemeSeed] or + /// [colorScheme], you can provide either a [primaryColor] or [primarySwatch] + /// to construct the [colorScheme], but the results will not be as complete + /// as when using generation from a seed color. + /// + /// If [colorSchemeSeed] is non-null then [colorScheme], [primaryColor] and + /// [primarySwatch] must all be null. + /// + /// The [textTheme] [TextStyle] colors are black if the color scheme's + /// brightness is [Brightness.light], and white for [Brightness.dark]. + /// + /// To override the appearance of specific components, provide + /// a component theme parameter like [sliderTheme], [toggleButtonsTheme], + /// or [bottomNavigationBarTheme]. + /// + /// See also: + /// + /// * [ThemeData.from], which creates a ThemeData from a [ColorScheme]. + /// * [ThemeData.light], which creates a light blue theme. + /// * [ThemeData.dark], which creates dark theme with a teal secondary [ColorScheme] color. + /// * [ColorScheme.fromSeed], which is used to create a [ColorScheme] from a seed color. + factory ThemeData({ + // For the sanity of the reader, make sure these properties are in the same + // order in every place that they are separated by section comments (e.g. + // GENERAL CONFIGURATION). Each section except for deprecations should be + // alphabetical by symbol name. + + // GENERAL CONFIGURATION + Iterable<Adaptation<Object>>? adaptations, + bool? applyElevationOverlayColor, + NoDefaultCupertinoThemeData? cupertinoOverrideTheme, + Iterable<ThemeExtension<dynamic>>? extensions, + InputDecorationTheme? inputDecorationTheme, + MaterialTapTargetSize? materialTapTargetSize, + PageTransitionsTheme? pageTransitionsTheme, + TargetPlatform? platform, + ScrollbarThemeData? scrollbarTheme, + InteractiveInkFeatureFactory? splashFactory, + bool? useMaterial3, + VisualDensity? visualDensity, + // COLOR + // [colorScheme] is the preferred way to configure colors. The other color + // properties (as well as primarySwatch) will gradually be phased out, see + // https://github.com/flutter/flutter/issues/91772. + Brightness? brightness, + Color? canvasColor, + Color? cardColor, + ColorScheme? colorScheme, + Color? colorSchemeSeed, + Color? dialogBackgroundColor, + Color? disabledColor, + Color? dividerColor, + Color? focusColor, + Color? highlightColor, + Color? hintColor, + Color? hoverColor, + Color? indicatorColor, + Color? primaryColor, + Color? primaryColorDark, + Color? primaryColorLight, + MaterialColor? primarySwatch, + Color? scaffoldBackgroundColor, + Color? secondaryHeaderColor, + Color? shadowColor, + Color? splashColor, + Color? unselectedWidgetColor, + // TYPOGRAPHY & ICONOGRAPHY + String? fontFamily, + List<String>? fontFamilyFallback, + String? package, + IconThemeData? iconTheme, + IconThemeData? primaryIconTheme, + TextTheme? primaryTextTheme, + TextTheme? textTheme, + Typography? typography, + // COMPONENT THEMES + ActionIconThemeData? actionIconTheme, + AppBarTheme? appBarTheme, + BadgeThemeData? badgeTheme, + MaterialBannerThemeData? bannerTheme, + BottomAppBarTheme? bottomAppBarTheme, + BottomNavigationBarThemeData? bottomNavigationBarTheme, + BottomSheetThemeData? bottomSheetTheme, + ButtonBarThemeData? buttonBarTheme, + ButtonThemeData? buttonTheme, + CardTheme? cardTheme, + CheckboxThemeData? checkboxTheme, + ChipThemeData? chipTheme, + DataTableThemeData? dataTableTheme, + DatePickerThemeData? datePickerTheme, + DialogTheme? dialogTheme, + DividerThemeData? dividerTheme, + DrawerThemeData? drawerTheme, + DropdownMenuThemeData? dropdownMenuTheme, + ElevatedButtonThemeData? elevatedButtonTheme, + ExpansionTileThemeData? expansionTileTheme, + FilledButtonThemeData? filledButtonTheme, + FloatingActionButtonThemeData? floatingActionButtonTheme, + IconButtonThemeData? iconButtonTheme, + ListTileThemeData? listTileTheme, + MenuBarThemeData? menuBarTheme, + MenuButtonThemeData? menuButtonTheme, + MenuThemeData? menuTheme, + NavigationBarThemeData? navigationBarTheme, + NavigationDrawerThemeData? navigationDrawerTheme, + NavigationRailThemeData? navigationRailTheme, + OutlinedButtonThemeData? outlinedButtonTheme, + PopupMenuThemeData? popupMenuTheme, + ProgressIndicatorThemeData? progressIndicatorTheme, + RadioThemeData? radioTheme, + SearchBarThemeData? searchBarTheme, + SearchViewThemeData? searchViewTheme, + SegmentedButtonThemeData? segmentedButtonTheme, + SliderThemeData? sliderTheme, + SnackBarThemeData? snackBarTheme, + SwitchThemeData? switchTheme, + TabBarTheme? tabBarTheme, + TextButtonThemeData? textButtonTheme, + TextSelectionThemeData? textSelectionTheme, + TimePickerThemeData? timePickerTheme, + ToggleButtonsThemeData? toggleButtonsTheme, + TooltipThemeData? tooltipTheme, + // DEPRECATED (newest deprecations at the bottom) + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'For more information, consult the migration guide at ' + 'https://flutter.dev/docs/release/breaking-changes/toggleable-active-color#migration-guide. ' + 'This feature was deprecated after v3.4.0-19.0.pre.', + ) + Color? toggleableActiveColor, + @Deprecated( + 'Use colorScheme.error instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Color? errorColor, + @Deprecated( + 'Use colorScheme.background instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Color? backgroundColor, + @Deprecated( + 'Use BottomAppBarTheme.color instead. ' + 'This feature was deprecated after v3.3.0-0.6.pre.', + ) + Color? bottomAppBarColor, + }) { + // GENERAL CONFIGURATION + cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault(); + extensions ??= <ThemeExtension<dynamic>>[]; + adaptations ??= <Adaptation<Object>>[]; + inputDecorationTheme ??= const InputDecorationTheme(); + platform ??= defaultTargetPlatform; + switch (platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + materialTapTargetSize ??= MaterialTapTargetSize.padded; + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + materialTapTargetSize ??= MaterialTapTargetSize.shrinkWrap; + } + pageTransitionsTheme ??= const PageTransitionsTheme(); + scrollbarTheme ??= const ScrollbarThemeData(); + visualDensity ??= VisualDensity.defaultDensityForPlatform(platform); + useMaterial3 ??= true; + final bool useInkSparkle = platform == TargetPlatform.android && !kIsWeb; + splashFactory ??= useMaterial3 + ? useInkSparkle ? InkSparkle.splashFactory : InkRipple.splashFactory + : InkSplash.splashFactory; + + // COLOR + assert( + colorScheme?.brightness == null || brightness == null || colorScheme!.brightness == brightness, + 'ThemeData.brightness does not match ColorScheme.brightness. ' + 'Either override ColorScheme.brightness or ThemeData.brightness to ' + 'match the other.' + ); + assert(colorSchemeSeed == null || colorScheme == null); + assert(colorSchemeSeed == null || primarySwatch == null); + assert(colorSchemeSeed == null || primaryColor == null); + final Brightness effectiveBrightness = brightness ?? colorScheme?.brightness ?? Brightness.light; + final bool isDark = effectiveBrightness == Brightness.dark; + if (colorSchemeSeed != null || useMaterial3) { + if (colorSchemeSeed != null) { + colorScheme = ColorScheme.fromSeed(seedColor: colorSchemeSeed, brightness: effectiveBrightness); + } + colorScheme ??= isDark ? _colorSchemeDarkM3 : _colorSchemeLightM3; + + // For surfaces that use primary color in light themes and surface color in dark + final Color primarySurfaceColor = isDark ? colorScheme.surface : colorScheme.primary; + final Color onPrimarySurfaceColor = isDark ? colorScheme.onSurface : colorScheme.onPrimary; + + // Default some of the color settings to values from the color scheme + primaryColor ??= primarySurfaceColor; + canvasColor ??= colorScheme.background; + scaffoldBackgroundColor ??= colorScheme.background; + bottomAppBarColor ??= colorScheme.surface; + cardColor ??= colorScheme.surface; + dividerColor ??= colorScheme.outline; + backgroundColor ??= colorScheme.background; + dialogBackgroundColor ??= colorScheme.background; + indicatorColor ??= onPrimarySurfaceColor; + errorColor ??= colorScheme.error; + applyElevationOverlayColor ??= brightness == Brightness.dark; + } + applyElevationOverlayColor ??= false; + primarySwatch ??= Colors.blue; + primaryColor ??= isDark ? Colors.grey[900]! : primarySwatch; + final Brightness estimatedPrimaryColorBrightness = estimateBrightnessForColor(primaryColor); + primaryColorLight ??= isDark ? Colors.grey[500]! : primarySwatch[100]!; + primaryColorDark ??= isDark ? Colors.black : primarySwatch[700]!; + final bool primaryIsDark = estimatedPrimaryColorBrightness == Brightness.dark; + toggleableActiveColor ??= isDark ? Colors.tealAccent[200]! : (colorScheme?.secondary ?? primarySwatch[600]!); + focusColor ??= isDark ? Colors.white.withOpacity(0.12) : Colors.black.withOpacity(0.12); + hoverColor ??= isDark ? Colors.white.withOpacity(0.04) : Colors.black.withOpacity(0.04); + shadowColor ??= Colors.black; + canvasColor ??= isDark ? Colors.grey[850]! : Colors.grey[50]!; + scaffoldBackgroundColor ??= canvasColor; + cardColor ??= isDark ? Colors.grey[800]! : Colors.white; + dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000); + // Create a ColorScheme that is backwards compatible as possible + // with the existing default ThemeData color values. + colorScheme ??= ColorScheme.fromSwatch( + primarySwatch: primarySwatch, + accentColor: isDark ? Colors.tealAccent[200]! : primarySwatch[500]!, + cardColor: cardColor, + backgroundColor: isDark ? Colors.grey[700]! : primarySwatch[200]!, + errorColor: Colors.red[700], + brightness: effectiveBrightness, + ); + unselectedWidgetColor ??= isDark ? Colors.white70 : Colors.black54; + // Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess. + secondaryHeaderColor ??= isDark ? Colors.grey[700]! : primarySwatch[50]!; + dialogBackgroundColor ??= isDark ? Colors.grey[800]! : Colors.white; + indicatorColor ??= colorScheme.secondary == primaryColor ? Colors.white : colorScheme.secondary; + hintColor ??= isDark ? Colors.white60 : Colors.black.withOpacity(0.6); + // The default [buttonTheme] is here because it doesn't use the defaults for + // [disabledColor], [highlightColor], and [splashColor]. + buttonTheme ??= ButtonThemeData( + colorScheme: colorScheme, + buttonColor: isDark ? primarySwatch[600]! : Colors.grey[300]!, + disabledColor: disabledColor, + focusColor: focusColor, + hoverColor: hoverColor, + highlightColor: highlightColor, + splashColor: splashColor, + materialTapTargetSize: materialTapTargetSize, + ); + disabledColor ??= isDark ? Colors.white38 : Colors.black38; + highlightColor ??= isDark ? _kDarkThemeHighlightColor : _kLightThemeHighlightColor; + splashColor ??= isDark ? _kDarkThemeSplashColor : _kLightThemeSplashColor; + + // TYPOGRAPHY & ICONOGRAPHY + typography ??= useMaterial3 + ? Typography.material2021(platform: platform, colorScheme: colorScheme) + : Typography.material2014(platform: platform); + TextTheme defaultTextTheme = isDark ? typography.white : typography.black; + TextTheme defaultPrimaryTextTheme = primaryIsDark ? typography.white : typography.black; + if (fontFamily != null) { + defaultTextTheme = defaultTextTheme.apply(fontFamily: fontFamily); + defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(fontFamily: fontFamily); + } + if (fontFamilyFallback != null) { + defaultTextTheme = defaultTextTheme.apply(fontFamilyFallback: fontFamilyFallback); + defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(fontFamilyFallback: fontFamilyFallback); + } + if (package != null) { + defaultTextTheme = defaultTextTheme.apply(package: package); + defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(package: package); + } + textTheme = defaultTextTheme.merge(textTheme); + primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme); + iconTheme ??= isDark ? IconThemeData(color: kDefaultIconLightColor) : IconThemeData(color: kDefaultIconDarkColor); + primaryIconTheme ??= primaryIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black); + + // COMPONENT THEMES + appBarTheme ??= const AppBarTheme(); + badgeTheme ??= const BadgeThemeData(); + bannerTheme ??= const MaterialBannerThemeData(); + bottomAppBarTheme ??= const BottomAppBarTheme(); + bottomNavigationBarTheme ??= const BottomNavigationBarThemeData(); + bottomSheetTheme ??= const BottomSheetThemeData(); + buttonBarTheme ??= const ButtonBarThemeData(); + cardTheme ??= const CardTheme(); + checkboxTheme ??= const CheckboxThemeData(); + chipTheme ??= const ChipThemeData(); + dataTableTheme ??= const DataTableThemeData(); + datePickerTheme ??= const DatePickerThemeData(); + dialogTheme ??= const DialogTheme(); + dividerTheme ??= const DividerThemeData(); + drawerTheme ??= const DrawerThemeData(); + dropdownMenuTheme ??= const DropdownMenuThemeData(); + elevatedButtonTheme ??= const ElevatedButtonThemeData(); + expansionTileTheme ??= const ExpansionTileThemeData(); + filledButtonTheme ??= const FilledButtonThemeData(); + floatingActionButtonTheme ??= const FloatingActionButtonThemeData(); + iconButtonTheme ??= const IconButtonThemeData(); + listTileTheme ??= const ListTileThemeData(); + menuBarTheme ??= const MenuBarThemeData(); + menuButtonTheme ??= const MenuButtonThemeData(); + menuTheme ??= const MenuThemeData(); + navigationBarTheme ??= const NavigationBarThemeData(); + navigationDrawerTheme ??= const NavigationDrawerThemeData(); + navigationRailTheme ??= const NavigationRailThemeData(); + outlinedButtonTheme ??= const OutlinedButtonThemeData(); + popupMenuTheme ??= const PopupMenuThemeData(); + progressIndicatorTheme ??= const ProgressIndicatorThemeData(); + radioTheme ??= const RadioThemeData(); + searchBarTheme ??= const SearchBarThemeData(); + searchViewTheme ??= const SearchViewThemeData(); + segmentedButtonTheme ??= const SegmentedButtonThemeData(); + sliderTheme ??= const SliderThemeData(); + snackBarTheme ??= const SnackBarThemeData(); + switchTheme ??= const SwitchThemeData(); + tabBarTheme ??= const TabBarTheme(); + textButtonTheme ??= const TextButtonThemeData(); + textSelectionTheme ??= const TextSelectionThemeData(); + timePickerTheme ??= const TimePickerThemeData(); + toggleButtonsTheme ??= const ToggleButtonsThemeData(); + tooltipTheme ??= const TooltipThemeData(); + + // DEPRECATED (newest deprecations at the bottom) + errorColor ??= Colors.red[700]!; + backgroundColor ??= isDark ? Colors.grey[700]! : primarySwatch[200]!; + bottomAppBarColor ??= colorSchemeSeed != null ? colorScheme.surface : isDark ? Colors.grey[800]! : Colors.white; + + return ThemeData.raw( + // For the sanity of the reader, make sure these properties are in the same + // order in every place that they are separated by section comments (e.g. + // GENERAL CONFIGURATION). Each section except for deprecations should be + // alphabetical by symbol name. + + // GENERAL CONFIGURATION + adaptationMap: _createAdaptationMap(adaptations), + applyElevationOverlayColor: applyElevationOverlayColor, + cupertinoOverrideTheme: cupertinoOverrideTheme, + extensions: _themeExtensionIterableToMap(extensions), + inputDecorationTheme: inputDecorationTheme, + materialTapTargetSize: materialTapTargetSize, + pageTransitionsTheme: pageTransitionsTheme, + platform: platform, + scrollbarTheme: scrollbarTheme, + splashFactory: splashFactory, + useMaterial3: useMaterial3, + visualDensity: visualDensity, + // COLOR + canvasColor: canvasColor, + cardColor: cardColor, + colorScheme: colorScheme, + dialogBackgroundColor: dialogBackgroundColor, + disabledColor: disabledColor, + dividerColor: dividerColor, + focusColor: focusColor, + highlightColor: highlightColor, + hintColor: hintColor, + hoverColor: hoverColor, + indicatorColor: indicatorColor, + primaryColor: primaryColor, + primaryColorDark: primaryColorDark, + primaryColorLight: primaryColorLight, + scaffoldBackgroundColor: scaffoldBackgroundColor, + secondaryHeaderColor: secondaryHeaderColor, + shadowColor: shadowColor, + splashColor: splashColor, + unselectedWidgetColor: unselectedWidgetColor, + // TYPOGRAPHY & ICONOGRAPHY + iconTheme: iconTheme, + primaryTextTheme: primaryTextTheme, + textTheme: textTheme, + typography: typography, + primaryIconTheme: primaryIconTheme, + // COMPONENT THEMES + actionIconTheme: actionIconTheme, + appBarTheme: appBarTheme, + badgeTheme: badgeTheme, + bannerTheme: bannerTheme, + bottomAppBarTheme: bottomAppBarTheme, + bottomNavigationBarTheme: bottomNavigationBarTheme, + bottomSheetTheme: bottomSheetTheme, + buttonBarTheme: buttonBarTheme, + buttonTheme: buttonTheme, + cardTheme: cardTheme, + checkboxTheme: checkboxTheme, + chipTheme: chipTheme, + dataTableTheme: dataTableTheme, + datePickerTheme: datePickerTheme, + dialogTheme: dialogTheme, + dividerTheme: dividerTheme, + drawerTheme: drawerTheme, + dropdownMenuTheme: dropdownMenuTheme, + elevatedButtonTheme: elevatedButtonTheme, + expansionTileTheme: expansionTileTheme, + filledButtonTheme: filledButtonTheme, + floatingActionButtonTheme: floatingActionButtonTheme, + iconButtonTheme: iconButtonTheme, + listTileTheme: listTileTheme, + menuBarTheme: menuBarTheme, + menuButtonTheme: menuButtonTheme, + menuTheme: menuTheme, + navigationBarTheme: navigationBarTheme, + navigationDrawerTheme: navigationDrawerTheme, + navigationRailTheme: navigationRailTheme, + outlinedButtonTheme: outlinedButtonTheme, + popupMenuTheme: popupMenuTheme, + progressIndicatorTheme: progressIndicatorTheme, + radioTheme: radioTheme, + searchBarTheme: searchBarTheme, + searchViewTheme: searchViewTheme, + segmentedButtonTheme: segmentedButtonTheme, + sliderTheme: sliderTheme, + snackBarTheme: snackBarTheme, + switchTheme: switchTheme, + tabBarTheme: tabBarTheme, + textButtonTheme: textButtonTheme, + textSelectionTheme: textSelectionTheme, + timePickerTheme: timePickerTheme, + toggleButtonsTheme: toggleButtonsTheme, + tooltipTheme: tooltipTheme, + // DEPRECATED (newest deprecations at the bottom) + toggleableActiveColor: toggleableActiveColor, + errorColor: errorColor, + backgroundColor: backgroundColor, + bottomAppBarColor: bottomAppBarColor, + ); + } + + /// Create a [ThemeData] given a set of exact values. Most values must be + /// specified. They all must also be non-null except for + /// [cupertinoOverrideTheme], and deprecated members. + /// + /// This will rarely be used directly. It is used by [lerp] to + /// create intermediate themes based on two themes created with the + /// [ThemeData] constructor. + const ThemeData.raw({ + // For the sanity of the reader, make sure these properties are in the same + // order in every place that they are separated by section comments (e.g. + // GENERAL CONFIGURATION). Each section except for deprecations should be + // alphabetical by symbol name. + + // GENERAL CONFIGURATION + required this.adaptationMap, + required this.applyElevationOverlayColor, + required this.cupertinoOverrideTheme, + required this.extensions, + required this.inputDecorationTheme, + required this.materialTapTargetSize, + required this.pageTransitionsTheme, + required this.platform, + required this.scrollbarTheme, + required this.splashFactory, + required this.useMaterial3, + required this.visualDensity, + // COLOR + // [colorScheme] is the preferred way to configure colors. The other color + // properties will gradually be phased out, see + // https://github.com/flutter/flutter/issues/91772. + required this.canvasColor, + required this.cardColor, + required this.colorScheme, + required this.dialogBackgroundColor, + required this.disabledColor, + required this.dividerColor, + required this.focusColor, + required this.highlightColor, + required this.hintColor, + required this.hoverColor, + required this.indicatorColor, + required this.primaryColor, + required this.primaryColorDark, + required this.primaryColorLight, + required this.scaffoldBackgroundColor, + required this.secondaryHeaderColor, + required this.shadowColor, + required this.splashColor, + required this.unselectedWidgetColor, + // TYPOGRAPHY & ICONOGRAPHY + required this.iconTheme, + required this.primaryIconTheme, + required this.primaryTextTheme, + required this.textTheme, + required this.typography, + // COMPONENT THEMES + required this.actionIconTheme, + required this.appBarTheme, + required this.badgeTheme, + required this.bannerTheme, + required this.bottomAppBarTheme, + required this.bottomNavigationBarTheme, + required this.bottomSheetTheme, + required this.buttonBarTheme, + required this.buttonTheme, + required this.cardTheme, + required this.checkboxTheme, + required this.chipTheme, + required this.dataTableTheme, + required this.datePickerTheme, + required this.dialogTheme, + required this.dividerTheme, + required this.drawerTheme, + required this.dropdownMenuTheme, + required this.elevatedButtonTheme, + required this.expansionTileTheme, + required this.filledButtonTheme, + required this.floatingActionButtonTheme, + required this.iconButtonTheme, + required this.listTileTheme, + required this.menuBarTheme, + required this.menuButtonTheme, + required this.menuTheme, + required this.navigationBarTheme, + required this.navigationDrawerTheme, + required this.navigationRailTheme, + required this.outlinedButtonTheme, + required this.popupMenuTheme, + required this.progressIndicatorTheme, + required this.radioTheme, + required this.searchBarTheme, + required this.searchViewTheme, + required this.segmentedButtonTheme, + required this.sliderTheme, + required this.snackBarTheme, + required this.switchTheme, + required this.tabBarTheme, + required this.textButtonTheme, + required this.textSelectionTheme, + required this.timePickerTheme, + required this.toggleButtonsTheme, + required this.tooltipTheme, + // DEPRECATED (newest deprecations at the bottom) + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'For more information, consult the migration guide at ' + 'https://flutter.dev/docs/release/breaking-changes/toggleable-active-color#migration-guide. ' + 'This feature was deprecated after v3.4.0-19.0.pre.', + ) + Color? toggleableActiveColor, + @Deprecated( + 'Use colorScheme.error instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Color? errorColor, + @Deprecated( + 'Use colorScheme.background instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Color? backgroundColor, + @Deprecated( + 'Use BottomAppBarTheme.color instead. ' + 'This feature was deprecated after v3.3.0-0.6.pre.', + ) + Color? bottomAppBarColor, + + }) : // DEPRECATED (newest deprecations at the bottom) + // should not be `required`, use getter pattern to avoid breakages. + _toggleableActiveColor = toggleableActiveColor, + _errorColor = errorColor, + _backgroundColor = backgroundColor, + _bottomAppBarColor = bottomAppBarColor, + assert(toggleableActiveColor != null), + // DEPRECATED (newest deprecations at the bottom) + assert(errorColor != null), + assert(backgroundColor != null); + + /// Create a [ThemeData] based on the colors in the given [colorScheme] and + /// text styles of the optional [textTheme]. + /// + /// If [colorScheme].brightness is [Brightness.dark] then + /// [ThemeData.applyElevationOverlayColor] will be set to true to support + /// the Material dark theme method for indicating elevation by applying + /// a semi-transparent onSurface color on top of the surface color. + /// + /// This is the recommended method to theme your application. As we move + /// forward we will be converting all the widget implementations to only use + /// colors or colors derived from those in [ColorScheme]. + /// + /// {@tool snippet} + /// This example will set up an application to use the baseline Material + /// Design light and dark themes. + /// + /// ```dart + /// MaterialApp( + /// theme: ThemeData.from(colorScheme: const ColorScheme.light()), + /// darkTheme: ThemeData.from(colorScheme: const ColorScheme.dark()), + /// ) + /// ``` + /// {@end-tool} + /// + /// See <https://material.io/design/color/> for + /// more discussion on how to pick the right colors. + factory ThemeData.from({ + required ColorScheme colorScheme, + TextTheme? textTheme, + bool? useMaterial3, + }) { + final bool isDark = colorScheme.brightness == Brightness.dark; + + // For surfaces that use primary color in light themes and surface color in dark + final Color primarySurfaceColor = isDark ? colorScheme.surface : colorScheme.primary; + final Color onPrimarySurfaceColor = isDark ? colorScheme.onSurface : colorScheme.onPrimary; + + return ThemeData( + colorScheme: colorScheme, + brightness: colorScheme.brightness, + primaryColor: primarySurfaceColor, + canvasColor: colorScheme.background, + scaffoldBackgroundColor: colorScheme.background, + bottomAppBarColor: colorScheme.surface, + cardColor: colorScheme.surface, + dividerColor: colorScheme.onSurface.withOpacity(0.12), + backgroundColor: colorScheme.background, + dialogBackgroundColor: colorScheme.background, + indicatorColor: onPrimarySurfaceColor, + errorColor: colorScheme.error, + textTheme: textTheme, + applyElevationOverlayColor: isDark, + useMaterial3: useMaterial3, + ); + } + + /// A default light theme. + /// + /// This theme does not contain text geometry. Instead, it is expected that + /// this theme is localized using text geometry using [ThemeData.localize]. + factory ThemeData.light({bool? useMaterial3}) => ThemeData( + brightness: Brightness.light, + useMaterial3: useMaterial3, + ); + + /// A default dark theme. + /// + /// This theme does not contain text geometry. Instead, it is expected that + /// this theme is localized using text geometry using [ThemeData.localize]. + factory ThemeData.dark({bool? useMaterial3}) => ThemeData( + brightness: Brightness.dark, + useMaterial3: useMaterial3, + ); + + /// The default color theme. Same as [ThemeData.light]. + /// + /// This is used by [Theme.of] when no theme has been specified. + /// + /// This theme does not contain text geometry. Instead, it is expected that + /// this theme is localized using text geometry using [ThemeData.localize]. + /// + /// Most applications would use [Theme.of], which provides correct localized + /// text geometry. + factory ThemeData.fallback({bool? useMaterial3}) => ThemeData.light(useMaterial3: useMaterial3); + + /// Used to obtain a particular [Adaptation] from [adaptationMap]. + /// + /// To get an adaptation, use `Theme.of(context).getAdaptation<MyAdaptation>()`. + Adaptation<T>? getAdaptation<T>() => adaptationMap[T] as Adaptation<T>?; + + static Map<Type, Adaptation<Object>> _createAdaptationMap(Iterable<Adaptation<Object>> adaptations) { + final Map<Type, Adaptation<Object>> adaptationMap = <Type, Adaptation<Object>>{ + for (final Adaptation<Object> adaptation in adaptations) + adaptation.type: adaptation + }; + return adaptationMap; + } + + /// The overall theme brightness. + /// + /// The default [TextStyle] color for the [textTheme] is black if the + /// theme is constructed with [Brightness.light] and white if the + /// theme is constructed with [Brightness.dark]. + Brightness get brightness => colorScheme.brightness; + + // For the sanity of the reader, make sure these properties are in the same + // order in every place that they are separated by section comments (e.g. + // GENERAL CONFIGURATION). Each section except for deprecations should be + // alphabetical by symbol name. + + // GENERAL CONFIGURATION + + /// Apply a semi-transparent overlay color on Material surfaces to indicate + /// elevation for dark themes. + /// + /// If [useMaterial3] is true, then this flag is ignored as there is a new + /// [Material.surfaceTintColor] used to create an overlay for Material 3. + /// This flag is meant only for the Material 2 elevation overlay for dark + /// themes. + /// + /// Material drop shadows can be difficult to see in a dark theme, so the + /// elevation of a surface should be portrayed with an "overlay" in addition + /// to the shadow. As the elevation of the component increases, the + /// overlay increases in opacity. [applyElevationOverlayColor] turns the + /// application of this overlay on or off for dark themes. + /// + /// If true and [brightness] is [Brightness.dark], a + /// semi-transparent version of [ColorScheme.onSurface] will be + /// applied on top of [Material] widgets that have a [ColorScheme.surface] + /// color. The level of transparency is based on [Material.elevation] as + /// per the Material Dark theme specification. + /// + /// If false the surface color will be used unmodified. + /// + /// Defaults to false in order to maintain backwards compatibility with + /// apps that were built before the Material Dark theme specification + /// was published. New apps should set this to true for any themes + /// where [brightness] is [Brightness.dark]. + /// + /// See also: + /// + /// * [Material.elevation], which effects the level of transparency of the + /// overlay color. + /// * [ElevationOverlay.applyOverlay], which is used by [Material] to apply + /// the overlay color to its surface color. + /// * <https://material.io/design/color/dark-theme.html>, which specifies how + /// the overlay should be applied. + final bool applyElevationOverlayColor; + + /// Components of the [CupertinoThemeData] to override from the Material + /// [ThemeData] adaptation. + /// + /// By default, [cupertinoOverrideTheme] is null and Cupertino widgets + /// descendant to the Material [Theme] will adhere to a [CupertinoTheme] + /// derived from the Material [ThemeData]. e.g. [ThemeData]'s [ColorScheme] + /// will also inform the [CupertinoThemeData]'s `primaryColor` etc. + /// + /// This cascading effect for individual attributes of the [CupertinoThemeData] + /// can be overridden using attributes of this [cupertinoOverrideTheme]. + final NoDefaultCupertinoThemeData? cupertinoOverrideTheme; + + /// Arbitrary additions to this theme. + /// + /// To define extensions, pass an [Iterable] containing one or more [ThemeExtension] + /// subclasses to [ThemeData.new] or [copyWith]. + /// + /// To obtain an extension, use [extension]. + /// + /// {@tool dartpad} + /// This sample shows how to create and use a subclass of [ThemeExtension] that + /// defines two colors. + /// + /// ** See code in examples/api/lib/material/theme/theme_extension.1.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [extension], a convenience function for obtaining a specific extension. + final Map<Object, ThemeExtension<dynamic>> extensions; + + /// Used to obtain a particular [ThemeExtension] from [extensions]. + /// + /// Obtain with `Theme.of(context).extension<MyThemeExtension>()`. + /// + /// See [extensions] for an interactive example. + T? extension<T>() => extensions[T] as T?; + + /// A map which contains the adaptations for the theme. The entry's key is the + /// type of the adaptation; the value is the adaptation itself. + /// + /// To obtain an adaptation, use [getAdaptation]. + final Map<Type, Adaptation<Object>> adaptationMap; + + /// The default [InputDecoration] values for [InputDecorator], [TextField], + /// and [TextFormField] are based on this theme. + /// + /// See [InputDecoration.applyDefaults]. + final InputDecorationTheme inputDecorationTheme; + + /// Configures the hit test size of certain Material widgets. + /// + /// Defaults to a [platform]-appropriate size: [MaterialTapTargetSize.padded] + /// on mobile platforms, [MaterialTapTargetSize.shrinkWrap] on desktop + /// platforms. + final MaterialTapTargetSize materialTapTargetSize; + + /// Default [MaterialPageRoute] transitions per [TargetPlatform]. + /// + /// [MaterialPageRoute.buildTransitions] delegates to a [platform] specific + /// [PageTransitionsBuilder]. If a matching builder is not found, a builder + /// whose platform is null is used. + final PageTransitionsTheme pageTransitionsTheme; + + /// The platform the material widgets should adapt to target. + /// + /// Defaults to the current platform, as exposed by [defaultTargetPlatform]. + /// This should be used in order to style UI elements according to platform + /// conventions. + /// + /// Widgets from the material library should use this getter (via [Theme.of]) + /// to determine the current platform for the purpose of emulating the + /// platform behavior (e.g. scrolling or haptic effects). Widgets and render + /// objects at lower layers that try to emulate the underlying platform + /// can depend on [defaultTargetPlatform] directly, or may require + /// that the target platform be provided as an argument. The + /// [dart:io.Platform] object should only be used directly when it's critical + /// to actually know the current platform, without any overrides possible (for + /// example, when a system API is about to be called). + /// + /// In a test environment, the platform returned is [TargetPlatform.android] + /// regardless of the host platform. (Android was chosen because the tests + /// were originally written assuming Android-like behavior, and we added + /// platform adaptations for other platforms later). Tests can check behavior + /// for other platforms by setting the [platform] of the [Theme] explicitly to + /// another [TargetPlatform] value, or by setting + /// [debugDefaultTargetPlatformOverride]. + /// + /// Determines the defaults for [typography] and [materialTapTargetSize]. + final TargetPlatform platform; + + /// A theme for customizing the colors, thickness, and shape of [Scrollbar]s. + final ScrollbarThemeData scrollbarTheme; + + /// Defines the appearance of ink splashes produces by [InkWell] + /// and [InkResponse]. + /// + /// See also: + /// + /// * [InkSplash.splashFactory], which defines the default splash. + /// * [InkRipple.splashFactory], which defines a splash that spreads out + /// more aggressively than the default. + /// * [InkSparkle.splashFactory], which defines a more aggressive and organic + /// splash with sparkle effects. + final InteractiveInkFeatureFactory splashFactory; + + /// A temporary flag that can be used to opt-out of Material 3 features. + /// + /// This flag is _true_ by default. If false, then components will + /// continue to use the colors, typography and other features of + /// Material 2. + /// + /// In the long run this flag will be deprecated and eventually + /// only Material 3 will be supported. We recommend that applications + /// migrate to Material 3 as soon as that's practical. Until that migration + /// is complete, this flag can be set to false. + /// + /// ## Defaults + /// + /// If a [ThemeData] is _constructed_ with [useMaterial3] set to true, then + /// some properties will get updated defaults. However, the + /// [ThemeData.copyWith] method with [useMaterial3] set to true will _not_ + /// change any of these properties in the resulting [ThemeData]. + /// + /// <style>table,td,th { border-collapse: collapse; padding: 0.45em; } td { border: 1px solid }</style> + /// + /// | Property | Material 3 default | Material 2 default | + /// | :-------------- | :----------------------------- | :----------------------------- | + /// | [colorScheme] | M3 baseline light color scheme | M2 baseline light color scheme | + /// | [typography] | [Typography.material2021] | [Typography.material2014] | + /// | [splashFactory] | [InkSparkle]* or [InkRipple] | [InkSplash] | + /// + /// \* if the target platform is Android and the app is not + /// running on the web, otherwise it will fallback to [InkRipple]. + /// + /// If [brightness] is [Brightness.dark] then the default color scheme will + /// be either the M3 baseline dark color scheme or the M2 baseline dark color + /// scheme depending on [useMaterial3]. + /// + /// ## Affected widgets + /// + /// This flag affects styles and components. + /// + /// ### Styles + /// * Color: [ColorScheme], [Material] (see table above) + /// * Shape: (see components below) + /// * Typography: [Typography] (see table above) + /// + /// ### Components + /// * Badges: [Badge] + /// * Bottom app bar: [BottomAppBar] + /// * Bottom sheets: [BottomSheet] + /// * Buttons + /// - Common buttons: [ElevatedButton], [FilledButton], [FilledButton.tonal], [OutlinedButton], [TextButton] + /// - FAB: [FloatingActionButton], [FloatingActionButton.extended] + /// - Icon buttons: [IconButton], [IconButton.filled] (*new*), [IconButton.filledTonal], [IconButton.outlined] + /// - Segmented buttons: [SegmentedButton] (replacing [ToggleButtons]) + /// * Cards: [Card] + /// * Checkbox: [Checkbox], [CheckboxListTile] + /// * Chips: + /// - [ActionChip] (used for Assist and Suggestion chips), + /// - [FilterChip], [ChoiceChip] (used for single selection filter chips), + /// - [InputChip] + /// * Date pickers: [showDatePicker], [showDateRangePicker], [DatePickerDialog], [DateRangePickerDialog], [InputDatePickerFormField] + /// * Dialogs: [AlertDialog], [Dialog.fullscreen] + /// * Divider: [Divider], [VerticalDivider] + /// * Lists: [ListTile] + /// * Menus: [MenuAnchor], [DropdownMenu], [MenuBar] + /// * Navigation bar: [NavigationBar] (replacing [BottomNavigationBar]) + /// * Navigation drawer: [NavigationDrawer] (replacing [Drawer]) + /// * Navigation rail: [NavigationRail] + /// * Progress indicators: [CircularProgressIndicator], [LinearProgressIndicator] + /// * Radio button: [Radio], [RadioListTile] + /// * Search: [SearchBar], [SearchAnchor], + /// * Snack bar: [SnackBar] + /// * Slider: [Slider], [RangeSlider] + /// * Switch: [Switch], [SwitchListTile] + /// * Tabs: [TabBar], [TabBar.secondary] + /// * TextFields: [TextField] together with its [InputDecoration] + /// * Time pickers: [showTimePicker], [TimePickerDialog] + /// * Top app bar: [AppBar], [SliverAppBar], [SliverAppBar.medium], [SliverAppBar.large] + /// + /// In addition, this flag enables features introduced in Android 12. + /// * Stretch overscroll: [MaterialScrollBehavior] + /// * Ripple: `splashFactory` (see table above) + /// + /// See also: + /// + /// * [Material 3 specification](https://m3.material.io/). + final bool useMaterial3; + + /// The density value for specifying the compactness of various UI components. + /// + /// {@template flutter.material.themedata.visualDensity} + /// Density, in the context of a UI, is the vertical and horizontal + /// "compactness" of the elements in the UI. It is unitless, since it means + /// different things to different UI elements. For buttons, it affects the + /// spacing around the centered label of the button. For lists, it affects the + /// distance between baselines of entries in the list. + /// + /// Typically, density values are integral, but any value in range may be + /// used. The range includes values from [VisualDensity.minimumDensity] (which + /// is -4), to [VisualDensity.maximumDensity] (which is 4), inclusive, where + /// negative values indicate a denser, more compact, UI, and positive values + /// indicate a less dense, more expanded, UI. If a component doesn't support + /// the value given, it will clamp to the nearest supported value. + /// + /// The default for visual densities is zero for both vertical and horizontal + /// densities, which corresponds to the default visual density of components + /// in the Material Design specification. + /// + /// As a rule of thumb, a change of 1 or -1 in density corresponds to 4 + /// logical pixels. However, this is not a strict relationship since + /// components interpret the density values appropriately for their needs. + /// + /// A larger value translates to a spacing increase (less dense), and a + /// smaller value translates to a spacing decrease (more dense). + /// + /// In Material Design 3, the [visualDensity] does not override the value of + /// [IconButton.visualDensity] which defaults to [VisualDensity.standard] + /// for all platforms. To override the default value of [IconButton.visualDensity], + /// use [ThemeData.iconButtonTheme] instead. + /// {@endtemplate} + final VisualDensity visualDensity; + + // COLOR + + /// The default color of the [BottomAppBar]. + @Deprecated( + 'Use BottomAppBarTheme.color instead. ' + 'This feature was deprecated after v3.3.0-0.6.pre.', + ) + Color get bottomAppBarColor => _bottomAppBarColor!; + final Color? _bottomAppBarColor; + + /// The default color of [MaterialType.canvas] [Material]. + final Color canvasColor; + + /// The color of [Material] when it is used as a [Card]. + final Color cardColor; + + /// {@macro flutter.material.color_scheme.ColorScheme} + /// + /// This property was added much later than the theme's set of highly specific + /// colors, like [cardColor], [canvasColor] etc. New components can be defined + /// exclusively in terms of [colorScheme]. Existing components will gradually + /// migrate to it, to the extent that is possible without significant + /// backwards compatibility breaks. + final ColorScheme colorScheme; + + /// The background color of [Dialog] elements. + final Color dialogBackgroundColor; + + /// The color used for widgets that are inoperative, regardless of + /// their state. For example, a disabled checkbox (which may be + /// checked or unchecked). + final Color disabledColor; + + /// The color of [Divider]s and [PopupMenuDivider]s, also used + /// between [ListTile]s, between rows in [DataTable]s, and so forth. + /// + /// To create an appropriate [BorderSide] that uses this color, consider + /// [Divider.createBorderSide]. + final Color dividerColor; + + /// The focus color used indicate that a component has the input focus. + final Color focusColor; + + /// The highlight color used during ink splash animations or to + /// indicate an item in a menu is selected. + final Color highlightColor; + + /// The color to use for hint text or placeholder text, e.g. in + /// [TextField] fields. + final Color hintColor; + + /// The hover color used to indicate when a pointer is hovering over a + /// component. + final Color hoverColor; + + /// The color of the selected tab indicator in a tab bar. + final Color indicatorColor; + + /// The background color for major parts of the app (toolbars, tab bars, etc) + /// + /// The theme's [colorScheme] property contains [ColorScheme.primary], as + /// well as a color that contrasts well with the primary color called + /// [ColorScheme.onPrimary]. It might be simpler to just configure an app's + /// visuals in terms of the theme's [colorScheme]. + final Color primaryColor; + + /// A darker version of the [primaryColor]. + final Color primaryColorDark; + + /// A lighter version of the [primaryColor]. + final Color primaryColorLight; + + /// The default color of the [Material] that underlies the [Scaffold]. The + /// background color for a typical material app or a page within the app. + final Color scaffoldBackgroundColor; + + /// The color of the header of a [PaginatedDataTable] when there are selected rows. + // According to the spec for data tables: + // https://material.io/archive/guidelines/components/data-tables.html#data-tables-tables-within-cards + // ...this should be the "50-value of secondary app color". + final Color secondaryHeaderColor; + + /// The color that the [Material] widget uses to draw elevation shadows. + /// + /// Defaults to fully opaque black. + /// + /// Shadows can be difficult to see in a dark theme, so the elevation of a + /// surface should be rendered with an "overlay" in addition to the shadow. + /// As the elevation of the component increases, the overlay increases in + /// opacity. The [applyElevationOverlayColor] property turns the elevation + /// overlay on or off for dark themes. + final Color shadowColor; + + /// The color of ink splashes. + /// + /// See also: + /// * [splashFactory], which defines the appearance of the splash. + final Color splashColor; + + /// The color used for widgets in their inactive (but enabled) + /// state. For example, an unchecked checkbox. See also [disabledColor]. + final Color unselectedWidgetColor; + + // TYPOGRAPHY & ICONOGRAPHY + + /// An icon theme that contrasts with the card and canvas colors. + final IconThemeData iconTheme; + + /// An icon theme that contrasts with the primary color. + final IconThemeData primaryIconTheme; + + /// A text theme that contrasts with the primary color. + final TextTheme primaryTextTheme; + + /// Text with a color that contrasts with the card and canvas colors. + final TextTheme textTheme; + + /// The color and geometry [TextTheme] values used to configure [textTheme]. + /// + /// Defaults to a [platform]-appropriate typography. + final Typography typography; + + // COMPONENT THEMES + + /// A theme for customizing icons of [BackButtonIcon], [CloseButtonIcon], + /// [DrawerButtonIcon], or [EndDrawerButtonIcon]. + final ActionIconThemeData? actionIconTheme; + + /// A theme for customizing the color, elevation, brightness, iconTheme and + /// textTheme of [AppBar]s. + final AppBarTheme appBarTheme; + + /// A theme for customizing the color of [Badge]s. + final BadgeThemeData badgeTheme; + + /// A theme for customizing the color and text style of a [MaterialBanner]. + final MaterialBannerThemeData bannerTheme; + + /// A theme for customizing the shape, elevation, and color of a [BottomAppBar]. + final BottomAppBarTheme bottomAppBarTheme; + + /// A theme for customizing the appearance and layout of [BottomNavigationBar] + /// widgets. + final BottomNavigationBarThemeData bottomNavigationBarTheme; + + /// A theme for customizing the color, elevation, and shape of a bottom sheet. + final BottomSheetThemeData bottomSheetTheme; + + /// A theme for customizing the appearance and layout of [ButtonBar] widgets. + final ButtonBarThemeData buttonBarTheme; + + /// Defines the default configuration of button widgets, like [DropdownButton] + /// and [ButtonBar]. + final ButtonThemeData buttonTheme; + + /// The colors and styles used to render [Card]. + /// + /// This is the value returned from [CardTheme.of]. + final CardTheme cardTheme; + + /// A theme for customizing the appearance and layout of [Checkbox] widgets. + final CheckboxThemeData checkboxTheme; + + /// The colors and styles used to render [Chip]s. + /// + /// This is the value returned from [ChipTheme.of]. + final ChipThemeData chipTheme; + + /// A theme for customizing the appearance and layout of [DataTable] + /// widgets. + final DataTableThemeData dataTableTheme; + + /// A theme for customizing the appearance and layout of [DatePickerDialog] + /// widgets. + final DatePickerThemeData datePickerTheme; + + /// A theme for customizing the shape of a dialog. + final DialogTheme dialogTheme; + + /// A theme for customizing the color, thickness, and indents of [Divider]s, + /// [VerticalDivider]s, etc. + final DividerThemeData dividerTheme; + + /// A theme for customizing the appearance and layout of [Drawer] widgets. + final DrawerThemeData drawerTheme; + + /// A theme for customizing the appearance and layout of [DropdownMenu] widgets. + final DropdownMenuThemeData dropdownMenuTheme; + + /// A theme for customizing the appearance and internal layout of + /// [ElevatedButton]s. + final ElevatedButtonThemeData elevatedButtonTheme; + + /// A theme for customizing the visual properties of [ExpansionTile]s. + final ExpansionTileThemeData expansionTileTheme; + + /// A theme for customizing the appearance and internal layout of + /// [FilledButton]s. + final FilledButtonThemeData filledButtonTheme; + + /// A theme for customizing the shape, elevation, and color of a + /// [FloatingActionButton]. + final FloatingActionButtonThemeData floatingActionButtonTheme; + + /// A theme for customizing the appearance and internal layout of + /// [IconButton]s. + final IconButtonThemeData iconButtonTheme; + + /// A theme for customizing the appearance of [ListTile] widgets. + final ListTileThemeData listTileTheme; + + /// A theme for customizing the color, shape, elevation, and other [MenuStyle] + /// aspects of the menu bar created by the [MenuBar] widget. + final MenuBarThemeData menuBarTheme; + + /// A theme for customizing the color, shape, elevation, and text style of + /// cascading menu buttons created by [SubmenuButton] or [MenuItemButton]. + final MenuButtonThemeData menuButtonTheme; + + /// A theme for customizing the color, shape, elevation, and other [MenuStyle] + /// attributes of menus created by the [SubmenuButton] widget. + final MenuThemeData menuTheme; + + /// A theme for customizing the background color, text style, and icon themes + /// of a [NavigationBar]. + final NavigationBarThemeData navigationBarTheme; + + /// A theme for customizing the background color, text style, and icon themes + /// of a [NavigationDrawer]. + final NavigationDrawerThemeData navigationDrawerTheme; + + /// A theme for customizing the background color, elevation, text style, and + /// icon themes of a [NavigationRail]. + final NavigationRailThemeData navigationRailTheme; + + /// A theme for customizing the appearance and internal layout of + /// [OutlinedButton]s. + final OutlinedButtonThemeData outlinedButtonTheme; + + /// A theme for customizing the color, shape, elevation, and text style of + /// popup menus. + final PopupMenuThemeData popupMenuTheme; + + /// A theme for customizing the appearance and layout of [ProgressIndicator] widgets. + final ProgressIndicatorThemeData progressIndicatorTheme; + + /// A theme for customizing the appearance and layout of [Radio] widgets. + final RadioThemeData radioTheme; + + /// A theme for customizing the appearance and layout of [SearchBar] widgets. + final SearchBarThemeData searchBarTheme; + + /// A theme for customizing the appearance and layout of search views created by [SearchAnchor] widgets. + final SearchViewThemeData searchViewTheme; + + /// A theme for customizing the appearance and layout of [SegmentedButton] widgets. + final SegmentedButtonThemeData segmentedButtonTheme; + + /// The colors and shapes used to render [Slider]. + /// + /// This is the value returned from [SliderTheme.of]. + final SliderThemeData sliderTheme; + + /// A theme for customizing colors, shape, elevation, and behavior of a [SnackBar]. + final SnackBarThemeData snackBarTheme; + + /// A theme for customizing the appearance and layout of [Switch] widgets. + final SwitchThemeData switchTheme; + + /// A theme for customizing the size, shape, and color of the tab bar indicator. + final TabBarTheme tabBarTheme; + + /// A theme for customizing the appearance and internal layout of + /// [TextButton]s. + final TextButtonThemeData textButtonTheme; + + /// A theme for customizing the appearance and layout of [TextField] widgets. + final TextSelectionThemeData textSelectionTheme; + + /// A theme for customizing the appearance and layout of time picker widgets. + final TimePickerThemeData timePickerTheme; + + /// Defines the default configuration of [ToggleButtons] widgets. + final ToggleButtonsThemeData toggleButtonsTheme; + + /// A theme for customizing the visual properties of [Tooltip]s. + /// + /// This is the value returned from [TooltipTheme.of]. + final TooltipThemeData tooltipTheme; + + // DEPRECATED (newest deprecations at the bottom) + + /// Obsolete property that was used for input validation errors, e.g. in + /// [TextField] fields. Use [ColorScheme.error] instead. + @Deprecated( + 'Use colorScheme.error instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Color get errorColor => _errorColor!; + final Color? _errorColor; + + /// Obsolete property that was unused by the framework. + /// Use [ColorScheme.background] instead. + @Deprecated( + 'Use colorScheme.background instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Color get backgroundColor => _backgroundColor!; + final Color? _backgroundColor; + + /// The color used to highlight the active states of toggleable widgets like + /// [Switch], [Radio], and [Checkbox]. + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'For more information, consult the migration guide at ' + 'https://flutter.dev/docs/release/breaking-changes/toggleable-active-color#migration-guide. ' + 'This feature was deprecated after v3.4.0-19.0.pre.', + ) + Color get toggleableActiveColor => _toggleableActiveColor!; + final Color? _toggleableActiveColor; + + /// Creates a copy of this theme but with the given fields replaced with the new values. + /// + /// The [brightness] value is applied to the [colorScheme]. + ThemeData copyWith({ + // For the sanity of the reader, make sure these properties are in the same + // order in every place that they are separated by section comments (e.g. + // GENERAL CONFIGURATION). Each section except for deprecations should be + // alphabetical by symbol name. + + // GENERAL CONFIGURATION + Iterable<Adaptation<Object>>? adaptations, + bool? applyElevationOverlayColor, + NoDefaultCupertinoThemeData? cupertinoOverrideTheme, + Iterable<ThemeExtension<dynamic>>? extensions, + InputDecorationTheme? inputDecorationTheme, + MaterialTapTargetSize? materialTapTargetSize, + PageTransitionsTheme? pageTransitionsTheme, + TargetPlatform? platform, + ScrollbarThemeData? scrollbarTheme, + InteractiveInkFeatureFactory? splashFactory, + VisualDensity? visualDensity, + // COLOR + // [colorScheme] is the preferred way to configure colors. The other color + // properties will gradually be phased out, see + // https://github.com/flutter/flutter/issues/91772. + Brightness? brightness, + Color? canvasColor, + Color? cardColor, + ColorScheme? colorScheme, + Color? dialogBackgroundColor, + Color? disabledColor, + Color? dividerColor, + Color? focusColor, + Color? highlightColor, + Color? hintColor, + Color? hoverColor, + Color? indicatorColor, + Color? primaryColor, + Color? primaryColorDark, + Color? primaryColorLight, + Color? scaffoldBackgroundColor, + Color? secondaryHeaderColor, + Color? shadowColor, + Color? splashColor, + Color? unselectedWidgetColor, + // TYPOGRAPHY & ICONOGRAPHY + IconThemeData? iconTheme, + IconThemeData? primaryIconTheme, + TextTheme? primaryTextTheme, + TextTheme? textTheme, + Typography? typography, + // COMPONENT THEMES + ActionIconThemeData? actionIconTheme, + AppBarTheme? appBarTheme, + BadgeThemeData? badgeTheme, + MaterialBannerThemeData? bannerTheme, + BottomAppBarTheme? bottomAppBarTheme, + BottomNavigationBarThemeData? bottomNavigationBarTheme, + BottomSheetThemeData? bottomSheetTheme, + ButtonBarThemeData? buttonBarTheme, + ButtonThemeData? buttonTheme, + CardTheme? cardTheme, + CheckboxThemeData? checkboxTheme, + ChipThemeData? chipTheme, + DataTableThemeData? dataTableTheme, + DatePickerThemeData? datePickerTheme, + DialogTheme? dialogTheme, + DividerThemeData? dividerTheme, + DrawerThemeData? drawerTheme, + DropdownMenuThemeData? dropdownMenuTheme, + ElevatedButtonThemeData? elevatedButtonTheme, + ExpansionTileThemeData? expansionTileTheme, + FilledButtonThemeData? filledButtonTheme, + FloatingActionButtonThemeData? floatingActionButtonTheme, + IconButtonThemeData? iconButtonTheme, + ListTileThemeData? listTileTheme, + MenuBarThemeData? menuBarTheme, + MenuButtonThemeData? menuButtonTheme, + MenuThemeData? menuTheme, + NavigationBarThemeData? navigationBarTheme, + NavigationDrawerThemeData? navigationDrawerTheme, + NavigationRailThemeData? navigationRailTheme, + OutlinedButtonThemeData? outlinedButtonTheme, + PopupMenuThemeData? popupMenuTheme, + ProgressIndicatorThemeData? progressIndicatorTheme, + RadioThemeData? radioTheme, + SearchBarThemeData? searchBarTheme, + SearchViewThemeData? searchViewTheme, + SegmentedButtonThemeData? segmentedButtonTheme, + SliderThemeData? sliderTheme, + SnackBarThemeData? snackBarTheme, + SwitchThemeData? switchTheme, + TabBarTheme? tabBarTheme, + TextButtonThemeData? textButtonTheme, + TextSelectionThemeData? textSelectionTheme, + TimePickerThemeData? timePickerTheme, + ToggleButtonsThemeData? toggleButtonsTheme, + TooltipThemeData? tooltipTheme, + // DEPRECATED (newest deprecations at the bottom) + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'For more information, consult the migration guide at ' + 'https://flutter.dev/docs/release/breaking-changes/toggleable-active-color#migration-guide. ' + 'This feature was deprecated after v3.4.0-19.0.pre.', + ) + Color? toggleableActiveColor, + @Deprecated( + 'Use colorScheme.error instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Color? errorColor, + @Deprecated( + 'Use colorScheme.background instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Color? backgroundColor, + @Deprecated( + 'Use BottomAppBarTheme.color instead. ' + 'This feature was deprecated after v3.3.0-0.6.pre.', + ) + Color? bottomAppBarColor, + @Deprecated( + 'Use a ThemeData constructor (.from, .light, or .dark) instead. ' + 'These constructors all have a useMaterial3 argument, ' + 'and they set appropriate default values based on its value. ' + 'See the useMaterial3 API documentation for full details. ' + 'This feature was deprecated after v3.13.0-0.2.pre.', + ) + bool? useMaterial3, + }) { + cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault(); + return ThemeData.raw( + // For the sanity of the reader, make sure these properties are in the same + // order in every place that they are separated by section comments (e.g. + // GENERAL CONFIGURATION). Each section except for deprecations should be + // alphabetical by symbol name. + + // GENERAL CONFIGURATION + adaptationMap: adaptations != null ? _createAdaptationMap(adaptations) : adaptationMap, + applyElevationOverlayColor: applyElevationOverlayColor ?? this.applyElevationOverlayColor, + cupertinoOverrideTheme: cupertinoOverrideTheme ?? this.cupertinoOverrideTheme, + extensions: (extensions != null) ? _themeExtensionIterableToMap(extensions) : this.extensions, + inputDecorationTheme: inputDecorationTheme ?? this.inputDecorationTheme, + materialTapTargetSize: materialTapTargetSize ?? this.materialTapTargetSize, + pageTransitionsTheme: pageTransitionsTheme ?? this.pageTransitionsTheme, + platform: platform ?? this.platform, + scrollbarTheme: scrollbarTheme ?? this.scrollbarTheme, + splashFactory: splashFactory ?? this.splashFactory, + // When deprecated useMaterial3 removed, maintain `this.useMaterial3` here + // for == evaluation. + useMaterial3: useMaterial3 ?? this.useMaterial3, + visualDensity: visualDensity ?? this.visualDensity, + // COLOR + canvasColor: canvasColor ?? this.canvasColor, + cardColor: cardColor ?? this.cardColor, + colorScheme: (colorScheme ?? this.colorScheme).copyWith(brightness: brightness), + dialogBackgroundColor: dialogBackgroundColor ?? this.dialogBackgroundColor, + disabledColor: disabledColor ?? this.disabledColor, + dividerColor: dividerColor ?? this.dividerColor, + focusColor: focusColor ?? this.focusColor, + highlightColor: highlightColor ?? this.highlightColor, + hintColor: hintColor ?? this.hintColor, + hoverColor: hoverColor ?? this.hoverColor, + indicatorColor: indicatorColor ?? this.indicatorColor, + primaryColor: primaryColor ?? this.primaryColor, + primaryColorDark: primaryColorDark ?? this.primaryColorDark, + primaryColorLight: primaryColorLight ?? this.primaryColorLight, + scaffoldBackgroundColor: scaffoldBackgroundColor ?? this.scaffoldBackgroundColor, + secondaryHeaderColor: secondaryHeaderColor ?? this.secondaryHeaderColor, + shadowColor: shadowColor ?? this.shadowColor, + splashColor: splashColor ?? this.splashColor, + unselectedWidgetColor: unselectedWidgetColor ?? this.unselectedWidgetColor, + // TYPOGRAPHY & ICONOGRAPHY + iconTheme: iconTheme ?? this.iconTheme, + primaryIconTheme: primaryIconTheme ?? this.primaryIconTheme, + primaryTextTheme: primaryTextTheme ?? this.primaryTextTheme, + textTheme: textTheme ?? this.textTheme, + typography: typography ?? this.typography, + // COMPONENT THEMES + actionIconTheme: actionIconTheme ?? this.actionIconTheme, + appBarTheme: appBarTheme ?? this.appBarTheme, + badgeTheme: badgeTheme ?? this.badgeTheme, + bannerTheme: bannerTheme ?? this.bannerTheme, + bottomAppBarTheme: bottomAppBarTheme ?? this.bottomAppBarTheme, + bottomNavigationBarTheme: bottomNavigationBarTheme ?? this.bottomNavigationBarTheme, + bottomSheetTheme: bottomSheetTheme ?? this.bottomSheetTheme, + buttonBarTheme: buttonBarTheme ?? this.buttonBarTheme, + buttonTheme: buttonTheme ?? this.buttonTheme, + cardTheme: cardTheme ?? this.cardTheme, + checkboxTheme: checkboxTheme ?? this.checkboxTheme, + chipTheme: chipTheme ?? this.chipTheme, + dataTableTheme: dataTableTheme ?? this.dataTableTheme, + datePickerTheme: datePickerTheme ?? this.datePickerTheme, + dialogTheme: dialogTheme ?? this.dialogTheme, + dividerTheme: dividerTheme ?? this.dividerTheme, + drawerTheme: drawerTheme ?? this.drawerTheme, + dropdownMenuTheme: dropdownMenuTheme ?? this.dropdownMenuTheme, + elevatedButtonTheme: elevatedButtonTheme ?? this.elevatedButtonTheme, + expansionTileTheme: expansionTileTheme ?? this.expansionTileTheme, + filledButtonTheme: filledButtonTheme ?? this.filledButtonTheme, + floatingActionButtonTheme: floatingActionButtonTheme ?? this.floatingActionButtonTheme, + iconButtonTheme: iconButtonTheme ?? this.iconButtonTheme, + listTileTheme: listTileTheme ?? this.listTileTheme, + menuBarTheme: menuBarTheme ?? this.menuBarTheme, + menuButtonTheme: menuButtonTheme ?? this.menuButtonTheme, + menuTheme: menuTheme ?? this.menuTheme, + navigationBarTheme: navigationBarTheme ?? this.navigationBarTheme, + navigationDrawerTheme: navigationDrawerTheme ?? this.navigationDrawerTheme, + navigationRailTheme: navigationRailTheme ?? this.navigationRailTheme, + outlinedButtonTheme: outlinedButtonTheme ?? this.outlinedButtonTheme, + popupMenuTheme: popupMenuTheme ?? this.popupMenuTheme, + progressIndicatorTheme: progressIndicatorTheme ?? this.progressIndicatorTheme, + radioTheme: radioTheme ?? this.radioTheme, + searchBarTheme: searchBarTheme ?? this.searchBarTheme, + searchViewTheme: searchViewTheme ?? this.searchViewTheme, + segmentedButtonTheme: segmentedButtonTheme ?? this.segmentedButtonTheme, + sliderTheme: sliderTheme ?? this.sliderTheme, + snackBarTheme: snackBarTheme ?? this.snackBarTheme, + switchTheme: switchTheme ?? this.switchTheme, + tabBarTheme: tabBarTheme ?? this.tabBarTheme, + textButtonTheme: textButtonTheme ?? this.textButtonTheme, + textSelectionTheme: textSelectionTheme ?? this.textSelectionTheme, + timePickerTheme: timePickerTheme ?? this.timePickerTheme, + toggleButtonsTheme: toggleButtonsTheme ?? this.toggleButtonsTheme, + tooltipTheme: tooltipTheme ?? this.tooltipTheme, + // DEPRECATED (newest deprecations at the bottom) + toggleableActiveColor: toggleableActiveColor ?? _toggleableActiveColor, + errorColor: errorColor ?? _errorColor, + backgroundColor: backgroundColor ?? _backgroundColor, + bottomAppBarColor: bottomAppBarColor ?? _bottomAppBarColor, + ); + } + + // The number 5 was chosen without any real science or research behind it. It + // just seemed like a number that's not too big (we should be able to fit 5 + // copies of ThemeData in memory comfortably) and not too small (most apps + // shouldn't have more than 5 theme/localization pairs). + static const int _localizedThemeDataCacheSize = 5; + + /// Caches localized themes to speed up the [localize] method. + static final _FifoCache<_IdentityThemeDataCacheKey, ThemeData> _localizedThemeDataCache = + _FifoCache<_IdentityThemeDataCacheKey, ThemeData>(_localizedThemeDataCacheSize); + + /// Returns a new theme built by merging the text geometry provided by the + /// [localTextGeometry] theme with the [baseTheme]. + /// + /// For those text styles in the [baseTheme] whose [TextStyle.inherit] is set + /// to true, the returned theme's text styles inherit the geometric properties + /// of [localTextGeometry]. The resulting text styles' [TextStyle.inherit] is + /// set to those provided by [localTextGeometry]. + static ThemeData localize(ThemeData baseTheme, TextTheme localTextGeometry) { + // WARNING: this method memoizes the result in a cache based on the + // previously seen baseTheme and localTextGeometry. Memoization is safe + // because all inputs and outputs of this function are deeply immutable, and + // the computations are referentially transparent. It only short-circuits + // the computation if the new inputs are identical() to the previous ones. + // It does not use the == operator, which performs a costly deep comparison. + // + // When changing this method, make sure the memoization logic is correct. + // Remember: + // + // There are only two hard things in Computer Science: cache invalidation + // and naming things. -- Phil Karlton + + return _localizedThemeDataCache.putIfAbsent( + _IdentityThemeDataCacheKey(baseTheme, localTextGeometry), + () { + return baseTheme.copyWith( + primaryTextTheme: localTextGeometry.merge(baseTheme.primaryTextTheme), + textTheme: localTextGeometry.merge(baseTheme.textTheme), + ); + }, + ); + } + + /// Determines whether the given [Color] is [Brightness.light] or + /// [Brightness.dark]. + /// + /// This compares the luminosity of the given color to a threshold value that + /// matches the Material Design specification. + static Brightness estimateBrightnessForColor(Color color) { + final double relativeLuminance = color.computeLuminance(); + + // See <https://www.w3.org/TR/WCAG20/#contrast-ratiodef> + // The spec says to use kThreshold=0.0525, but Material Design appears to bias + // more towards using light text than WCAG20 recommends. Material Design spec + // doesn't say what value to use, but 0.15 seemed close to what the Material + // Design spec shows for its color palette on + // <https://material.io/go/design-theming#color-color-palette>. + const double kThreshold = 0.15; + if ((relativeLuminance + 0.05) * (relativeLuminance + 0.05) > kThreshold) { + return Brightness.light; + } + return Brightness.dark; + } + + /// Linearly interpolate between two [extensions]. + /// + /// Includes all theme extensions in [a] and [b]. + /// + /// {@macro dart.ui.shadow.lerp} + static Map<Object, ThemeExtension<dynamic>> _lerpThemeExtensions(ThemeData a, ThemeData b, double t) { + // Lerp [a]. + final Map<Object, ThemeExtension<dynamic>> newExtensions = a.extensions.map((Object id, ThemeExtension<dynamic> extensionA) { + final ThemeExtension<dynamic>? extensionB = b.extensions[id]; + return MapEntry<Object, ThemeExtension<dynamic>>(id, extensionA.lerp(extensionB, t)); + }); + // Add [b]-only extensions. + newExtensions.addEntries(b.extensions.entries.where( + (MapEntry<Object, ThemeExtension<dynamic>> entry) => + !a.extensions.containsKey(entry.key))); + + return newExtensions; + } + + /// Convert the [extensionsIterable] passed to [ThemeData.new] or [copyWith] + /// to the stored [extensions] map, where each entry's key consists of the extension's type. + static Map<Object, ThemeExtension<dynamic>> _themeExtensionIterableToMap(Iterable<ThemeExtension<dynamic>> extensionsIterable) { + return Map<Object, ThemeExtension<dynamic>>.unmodifiable(<Object, ThemeExtension<dynamic>>{ + // Strangely, the cast is necessary for tests to run. + for (final ThemeExtension<dynamic> extension in extensionsIterable) extension.type: extension as ThemeExtension<ThemeExtension<dynamic>>, + }); + } + + /// Linearly interpolate between two themes. + /// + /// {@macro dart.ui.shadow.lerp} + static ThemeData lerp(ThemeData a, ThemeData b, double t) { + if (identical(a, b)) { + return a; + } + return ThemeData.raw( + // For the sanity of the reader, make sure these properties are in the same + // order in every place that they are separated by section comments (e.g. + // GENERAL CONFIGURATION). Each section except for deprecations should be + // alphabetical by symbol name. + + // GENERAL CONFIGURATION + adaptationMap: t < 0.5 ? a.adaptationMap : b.adaptationMap, + applyElevationOverlayColor:t < 0.5 ? a.applyElevationOverlayColor : b.applyElevationOverlayColor, + cupertinoOverrideTheme:t < 0.5 ? a.cupertinoOverrideTheme : b.cupertinoOverrideTheme, + extensions: _lerpThemeExtensions(a, b, t), + inputDecorationTheme:t < 0.5 ? a.inputDecorationTheme : b.inputDecorationTheme, + materialTapTargetSize:t < 0.5 ? a.materialTapTargetSize : b.materialTapTargetSize, + pageTransitionsTheme:t < 0.5 ? a.pageTransitionsTheme : b.pageTransitionsTheme, + platform: t < 0.5 ? a.platform : b.platform, + scrollbarTheme: ScrollbarThemeData.lerp(a.scrollbarTheme, b.scrollbarTheme, t), + splashFactory: t < 0.5 ? a.splashFactory : b.splashFactory, + useMaterial3: t < 0.5 ? a.useMaterial3 : b.useMaterial3, + visualDensity: VisualDensity.lerp(a.visualDensity, b.visualDensity, t), + // COLOR + canvasColor: Color.lerp(a.canvasColor, b.canvasColor, t)!, + cardColor: Color.lerp(a.cardColor, b.cardColor, t)!, + colorScheme: ColorScheme.lerp(a.colorScheme, b.colorScheme, t), + dialogBackgroundColor: Color.lerp(a.dialogBackgroundColor, b.dialogBackgroundColor, t)!, + disabledColor: Color.lerp(a.disabledColor, b.disabledColor, t)!, + dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t)!, + focusColor: Color.lerp(a.focusColor, b.focusColor, t)!, + highlightColor: Color.lerp(a.highlightColor, b.highlightColor, t)!, + hintColor: Color.lerp(a.hintColor, b.hintColor, t)!, + hoverColor: Color.lerp(a.hoverColor, b.hoverColor, t)!, + indicatorColor: Color.lerp(a.indicatorColor, b.indicatorColor, t)!, + primaryColor: Color.lerp(a.primaryColor, b.primaryColor, t)!, + primaryColorDark: Color.lerp(a.primaryColorDark, b.primaryColorDark, t)!, + primaryColorLight: Color.lerp(a.primaryColorLight, b.primaryColorLight, t)!, + scaffoldBackgroundColor: Color.lerp(a.scaffoldBackgroundColor, b.scaffoldBackgroundColor, t)!, + secondaryHeaderColor: Color.lerp(a.secondaryHeaderColor, b.secondaryHeaderColor, t)!, + shadowColor: Color.lerp(a.shadowColor, b.shadowColor, t)!, + splashColor: Color.lerp(a.splashColor, b.splashColor, t)!, + unselectedWidgetColor: Color.lerp(a.unselectedWidgetColor, b.unselectedWidgetColor, t)!, + // TYPOGRAPHY & ICONOGRAPHY + iconTheme: IconThemeData.lerp(a.iconTheme, b.iconTheme, t), + primaryIconTheme: IconThemeData.lerp(a.primaryIconTheme, b.primaryIconTheme, t), + primaryTextTheme: TextTheme.lerp(a.primaryTextTheme, b.primaryTextTheme, t), + textTheme: TextTheme.lerp(a.textTheme, b.textTheme, t), + typography: Typography.lerp(a.typography, b.typography, t), + // COMPONENT THEMES + actionIconTheme: ActionIconThemeData.lerp(a.actionIconTheme, b.actionIconTheme, t), + appBarTheme: AppBarTheme.lerp(a.appBarTheme, b.appBarTheme, t), + badgeTheme: BadgeThemeData.lerp(a.badgeTheme, b.badgeTheme, t), + bannerTheme: MaterialBannerThemeData.lerp(a.bannerTheme, b.bannerTheme, t), + bottomAppBarTheme: BottomAppBarTheme.lerp(a.bottomAppBarTheme, b.bottomAppBarTheme, t), + bottomNavigationBarTheme: BottomNavigationBarThemeData.lerp(a.bottomNavigationBarTheme, b.bottomNavigationBarTheme, t), + bottomSheetTheme: BottomSheetThemeData.lerp(a.bottomSheetTheme, b.bottomSheetTheme, t)!, + buttonBarTheme: ButtonBarThemeData.lerp(a.buttonBarTheme, b.buttonBarTheme, t)!, + buttonTheme: t < 0.5 ? a.buttonTheme : b.buttonTheme, + cardTheme: CardTheme.lerp(a.cardTheme, b.cardTheme, t), + checkboxTheme: CheckboxThemeData.lerp(a.checkboxTheme, b.checkboxTheme, t), + chipTheme: ChipThemeData.lerp(a.chipTheme, b.chipTheme, t)!, + dataTableTheme: DataTableThemeData.lerp(a.dataTableTheme, b.dataTableTheme, t), + datePickerTheme: DatePickerThemeData.lerp(a.datePickerTheme, b.datePickerTheme, t), + dialogTheme: DialogTheme.lerp(a.dialogTheme, b.dialogTheme, t), + dividerTheme: DividerThemeData.lerp(a.dividerTheme, b.dividerTheme, t), + drawerTheme: DrawerThemeData.lerp(a.drawerTheme, b.drawerTheme, t)!, + dropdownMenuTheme: DropdownMenuThemeData.lerp(a.dropdownMenuTheme, b.dropdownMenuTheme, t), + elevatedButtonTheme: ElevatedButtonThemeData.lerp(a.elevatedButtonTheme, b.elevatedButtonTheme, t)!, + expansionTileTheme: ExpansionTileThemeData.lerp(a.expansionTileTheme, b.expansionTileTheme, t)!, + filledButtonTheme: FilledButtonThemeData.lerp(a.filledButtonTheme, b.filledButtonTheme, t)!, + floatingActionButtonTheme: FloatingActionButtonThemeData.lerp(a.floatingActionButtonTheme, b.floatingActionButtonTheme, t)!, + iconButtonTheme: IconButtonThemeData.lerp(a.iconButtonTheme, b.iconButtonTheme, t)!, + listTileTheme: ListTileThemeData.lerp(a.listTileTheme, b.listTileTheme, t)!, + menuBarTheme: MenuBarThemeData.lerp(a.menuBarTheme, b.menuBarTheme, t)!, + menuButtonTheme: MenuButtonThemeData.lerp(a.menuButtonTheme, b.menuButtonTheme, t)!, + menuTheme: MenuThemeData.lerp(a.menuTheme, b.menuTheme, t)!, + navigationBarTheme: NavigationBarThemeData.lerp(a.navigationBarTheme, b.navigationBarTheme, t)!, + navigationDrawerTheme: NavigationDrawerThemeData.lerp(a.navigationDrawerTheme, b.navigationDrawerTheme, t)!, + navigationRailTheme: NavigationRailThemeData.lerp(a.navigationRailTheme, b.navigationRailTheme, t)!, + outlinedButtonTheme: OutlinedButtonThemeData.lerp(a.outlinedButtonTheme, b.outlinedButtonTheme, t)!, + popupMenuTheme: PopupMenuThemeData.lerp(a.popupMenuTheme, b.popupMenuTheme, t)!, + progressIndicatorTheme: ProgressIndicatorThemeData.lerp(a.progressIndicatorTheme, b.progressIndicatorTheme, t)!, + radioTheme: RadioThemeData.lerp(a.radioTheme, b.radioTheme, t), + searchBarTheme: SearchBarThemeData.lerp(a.searchBarTheme, b.searchBarTheme, t)!, + searchViewTheme: SearchViewThemeData.lerp(a.searchViewTheme, b.searchViewTheme, t)!, + segmentedButtonTheme: SegmentedButtonThemeData.lerp(a.segmentedButtonTheme, b.segmentedButtonTheme, t), + sliderTheme: SliderThemeData.lerp(a.sliderTheme, b.sliderTheme, t), + snackBarTheme: SnackBarThemeData.lerp(a.snackBarTheme, b.snackBarTheme, t), + switchTheme: SwitchThemeData.lerp(a.switchTheme, b.switchTheme, t), + tabBarTheme: TabBarTheme.lerp(a.tabBarTheme, b.tabBarTheme, t), + textButtonTheme: TextButtonThemeData.lerp(a.textButtonTheme, b.textButtonTheme, t)!, + textSelectionTheme: TextSelectionThemeData.lerp(a.textSelectionTheme, b.textSelectionTheme, t)!, + timePickerTheme: TimePickerThemeData.lerp(a.timePickerTheme, b.timePickerTheme, t), + toggleButtonsTheme: ToggleButtonsThemeData.lerp(a.toggleButtonsTheme, b.toggleButtonsTheme, t)!, + tooltipTheme: TooltipThemeData.lerp(a.tooltipTheme, b.tooltipTheme, t)!, + // DEPRECATED (newest deprecations at the bottom) + toggleableActiveColor: Color.lerp(a.toggleableActiveColor, b.toggleableActiveColor, t), + errorColor: Color.lerp(a.errorColor, b.errorColor, t), + backgroundColor: Color.lerp(a.backgroundColor, b.backgroundColor, t), + bottomAppBarColor: Color.lerp(a.bottomAppBarColor, b.bottomAppBarColor, t), + ); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ThemeData && + // For the sanity of the reader, make sure these properties are in the same + // order in every place that they are separated by section comments (e.g. + // GENERAL CONFIGURATION). Each section except for deprecations should be + // alphabetical by symbol name. + + // GENERAL CONFIGURATION + mapEquals(other.adaptationMap, adaptationMap) && + other.applyElevationOverlayColor == applyElevationOverlayColor && + other.cupertinoOverrideTheme == cupertinoOverrideTheme && + mapEquals(other.extensions, extensions) && + other.inputDecorationTheme == inputDecorationTheme && + other.materialTapTargetSize == materialTapTargetSize && + other.pageTransitionsTheme == pageTransitionsTheme && + other.platform == platform && + other.scrollbarTheme == scrollbarTheme && + other.splashFactory == splashFactory && + other.useMaterial3 == useMaterial3 && + other.visualDensity == visualDensity && + // COLOR + other.canvasColor == canvasColor && + other.cardColor == cardColor && + other.colorScheme == colorScheme && + other.dialogBackgroundColor == dialogBackgroundColor && + other.disabledColor == disabledColor && + other.dividerColor == dividerColor && + other.focusColor == focusColor && + other.highlightColor == highlightColor && + other.hintColor == hintColor && + other.hoverColor == hoverColor && + other.indicatorColor == indicatorColor && + other.primaryColor == primaryColor && + other.primaryColorDark == primaryColorDark && + other.primaryColorLight == primaryColorLight && + other.scaffoldBackgroundColor == scaffoldBackgroundColor && + other.secondaryHeaderColor == secondaryHeaderColor && + other.shadowColor == shadowColor && + other.splashColor == splashColor && + other.unselectedWidgetColor == unselectedWidgetColor && + // TYPOGRAPHY & ICONOGRAPHY + other.iconTheme == iconTheme && + other.primaryIconTheme == primaryIconTheme && + other.primaryTextTheme == primaryTextTheme && + other.textTheme == textTheme && + other.typography == typography && + // COMPONENT THEMES + other.actionIconTheme == actionIconTheme && + other.appBarTheme == appBarTheme && + other.badgeTheme == badgeTheme && + other.bannerTheme == bannerTheme && + other.bottomAppBarTheme == bottomAppBarTheme && + other.bottomNavigationBarTheme == bottomNavigationBarTheme && + other.bottomSheetTheme == bottomSheetTheme && + other.buttonBarTheme == buttonBarTheme && + other.buttonTheme == buttonTheme && + other.cardTheme == cardTheme && + other.checkboxTheme == checkboxTheme && + other.chipTheme == chipTheme && + other.dataTableTheme == dataTableTheme && + other.datePickerTheme == datePickerTheme && + other.dialogTheme == dialogTheme && + other.dividerTheme == dividerTheme && + other.drawerTheme == drawerTheme && + other.dropdownMenuTheme == dropdownMenuTheme && + other.elevatedButtonTheme == elevatedButtonTheme && + other.expansionTileTheme == expansionTileTheme && + other.filledButtonTheme == filledButtonTheme && + other.floatingActionButtonTheme == floatingActionButtonTheme && + other.iconButtonTheme == iconButtonTheme && + other.listTileTheme == listTileTheme && + other.menuBarTheme == menuBarTheme && + other.menuButtonTheme == menuButtonTheme && + other.menuTheme == menuTheme && + other.navigationBarTheme == navigationBarTheme && + other.navigationDrawerTheme == navigationDrawerTheme && + other.navigationRailTheme == navigationRailTheme && + other.outlinedButtonTheme == outlinedButtonTheme && + other.popupMenuTheme == popupMenuTheme && + other.progressIndicatorTheme == progressIndicatorTheme && + other.radioTheme == radioTheme && + other.searchBarTheme == searchBarTheme && + other.searchViewTheme == searchViewTheme && + other.segmentedButtonTheme == segmentedButtonTheme && + other.sliderTheme == sliderTheme && + other.snackBarTheme == snackBarTheme && + other.switchTheme == switchTheme && + other.tabBarTheme == tabBarTheme && + other.textButtonTheme == textButtonTheme && + other.textSelectionTheme == textSelectionTheme && + other.timePickerTheme == timePickerTheme && + other.toggleButtonsTheme == toggleButtonsTheme && + other.tooltipTheme == tooltipTheme && + // DEPRECATED (newest deprecations at the bottom) + other.toggleableActiveColor == toggleableActiveColor && + other.errorColor == errorColor && + other.backgroundColor == backgroundColor && + other.bottomAppBarColor == bottomAppBarColor; + } + + @override + int get hashCode { + final List<Object?> values = <Object?>[ + // For the sanity of the reader, make sure these properties are in the same + // order in every place that they are separated by section comments (e.g. + // GENERAL CONFIGURATION). Each section except for deprecations should be + // alphabetical by symbol name. + + // GENERAL CONFIGURATION + ...adaptationMap.keys, + ...adaptationMap.values, + applyElevationOverlayColor, + cupertinoOverrideTheme, + ...extensions.keys, + ...extensions.values, + inputDecorationTheme, + materialTapTargetSize, + pageTransitionsTheme, + platform, + scrollbarTheme, + splashFactory, + useMaterial3, + visualDensity, + // COLOR + canvasColor, + cardColor, + colorScheme, + dialogBackgroundColor, + disabledColor, + dividerColor, + focusColor, + highlightColor, + hintColor, + hoverColor, + indicatorColor, + primaryColor, + primaryColorDark, + primaryColorLight, + scaffoldBackgroundColor, + secondaryHeaderColor, + shadowColor, + splashColor, + unselectedWidgetColor, + // TYPOGRAPHY & ICONOGRAPHY + iconTheme, + primaryIconTheme, + primaryTextTheme, + textTheme, + typography, + // COMPONENT THEMES + actionIconTheme, + appBarTheme, + badgeTheme, + bannerTheme, + bottomAppBarTheme, + bottomNavigationBarTheme, + bottomSheetTheme, + buttonBarTheme, + buttonTheme, + cardTheme, + checkboxTheme, + chipTheme, + dataTableTheme, + datePickerTheme, + dialogTheme, + dividerTheme, + drawerTheme, + dropdownMenuTheme, + elevatedButtonTheme, + expansionTileTheme, + filledButtonTheme, + floatingActionButtonTheme, + iconButtonTheme, + listTileTheme, + menuBarTheme, + menuButtonTheme, + menuTheme, + navigationBarTheme, + navigationDrawerTheme, + navigationRailTheme, + outlinedButtonTheme, + popupMenuTheme, + progressIndicatorTheme, + radioTheme, + searchBarTheme, + searchViewTheme, + segmentedButtonTheme, + sliderTheme, + snackBarTheme, + switchTheme, + tabBarTheme, + textButtonTheme, + textSelectionTheme, + timePickerTheme, + toggleButtonsTheme, + tooltipTheme, + // DEPRECATED (newest deprecations at the bottom) + toggleableActiveColor, + errorColor, + backgroundColor, + bottomAppBarColor, + ]; + return Object.hashAll(values); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final ThemeData defaultData = ThemeData.fallback(); + // For the sanity of the reader, make sure these properties are in the same + // order in every place that they are separated by section comments (e.g. + // GENERAL CONFIGURATION). Each section except for deprecations should be + // alphabetical by symbol name. + + // GENERAL CONFIGURATION + properties.add(IterableProperty<Adaptation<dynamic>>('adaptations', adaptationMap.values, defaultValue: defaultData.adaptationMap.values, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<bool>('applyElevationOverlayColor', applyElevationOverlayColor, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<NoDefaultCupertinoThemeData>('cupertinoOverrideTheme', cupertinoOverrideTheme, defaultValue: defaultData.cupertinoOverrideTheme, level: DiagnosticLevel.debug)); + properties.add(IterableProperty<ThemeExtension<dynamic>>('extensions', extensions.values, defaultValue: defaultData.extensions.values, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<InputDecorationTheme>('inputDecorationTheme', inputDecorationTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<MaterialTapTargetSize>('materialTapTargetSize', materialTapTargetSize, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<PageTransitionsTheme>('pageTransitionsTheme', pageTransitionsTheme, level: DiagnosticLevel.debug)); + properties.add(EnumProperty<TargetPlatform>('platform', platform, defaultValue: defaultTargetPlatform, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ScrollbarThemeData>('scrollbarTheme', scrollbarTheme, defaultValue: defaultData.scrollbarTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<InteractiveInkFeatureFactory>('splashFactory', splashFactory, defaultValue: defaultData.splashFactory, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<bool>('useMaterial3', useMaterial3, defaultValue: defaultData.useMaterial3, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<VisualDensity>('visualDensity', visualDensity, defaultValue: defaultData.visualDensity, level: DiagnosticLevel.debug)); + // COLORS + properties.add(ColorProperty('canvasColor', canvasColor, defaultValue: defaultData.canvasColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('cardColor', cardColor, defaultValue: defaultData.cardColor, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ColorScheme>('colorScheme', colorScheme, defaultValue: defaultData.colorScheme, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('dialogBackgroundColor', dialogBackgroundColor, defaultValue: defaultData.dialogBackgroundColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: defaultData.disabledColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('dividerColor', dividerColor, defaultValue: defaultData.dividerColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('focusColor', focusColor, defaultValue: defaultData.focusColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('highlightColor', highlightColor, defaultValue: defaultData.highlightColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('hintColor', hintColor, defaultValue: defaultData.hintColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: defaultData.hoverColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('indicatorColor', indicatorColor, defaultValue: defaultData.indicatorColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('primaryColorDark', primaryColorDark, defaultValue: defaultData.primaryColorDark, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('primaryColorLight', primaryColorLight, defaultValue: defaultData.primaryColorLight, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('primaryColor', primaryColor, defaultValue: defaultData.primaryColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('scaffoldBackgroundColor', scaffoldBackgroundColor, defaultValue: defaultData.scaffoldBackgroundColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('secondaryHeaderColor', secondaryHeaderColor, defaultValue: defaultData.secondaryHeaderColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: defaultData.shadowColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('splashColor', splashColor, defaultValue: defaultData.splashColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('unselectedWidgetColor', unselectedWidgetColor, defaultValue: defaultData.unselectedWidgetColor, level: DiagnosticLevel.debug)); + // TYPOGRAPHY & ICONOGRAPHY + properties.add(DiagnosticsProperty<IconThemeData>('iconTheme', iconTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<IconThemeData>('primaryIconTheme', primaryIconTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<TextTheme>('primaryTextTheme', primaryTextTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<TextTheme>('textTheme', textTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<Typography>('typography', typography, defaultValue: defaultData.typography, level: DiagnosticLevel.debug)); + // COMPONENT THEMES + properties.add(DiagnosticsProperty<ActionIconThemeData>('actionIconTheme', actionIconTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<AppBarTheme>('appBarTheme', appBarTheme, defaultValue: defaultData.appBarTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<BadgeThemeData>('badgeTheme', badgeTheme, defaultValue: defaultData.badgeTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<MaterialBannerThemeData>('bannerTheme', bannerTheme, defaultValue: defaultData.bannerTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<BottomAppBarTheme>('bottomAppBarTheme', bottomAppBarTheme, defaultValue: defaultData.bottomAppBarTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<BottomNavigationBarThemeData>('bottomNavigationBarTheme', bottomNavigationBarTheme, defaultValue: defaultData.bottomNavigationBarTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<BottomSheetThemeData>('bottomSheetTheme', bottomSheetTheme, defaultValue: defaultData.bottomSheetTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ButtonBarThemeData>('buttonBarTheme', buttonBarTheme, defaultValue: defaultData.buttonBarTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ButtonThemeData>('buttonTheme', buttonTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<CardTheme>('cardTheme', cardTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<CheckboxThemeData>('checkboxTheme', checkboxTheme, defaultValue: defaultData.checkboxTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ChipThemeData>('chipTheme', chipTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<DataTableThemeData>('dataTableTheme', dataTableTheme, defaultValue: defaultData.dataTableTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<DatePickerThemeData>('datePickerTheme', datePickerTheme, defaultValue: defaultData.datePickerTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<DialogTheme>('dialogTheme', dialogTheme, defaultValue: defaultData.dialogTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<DividerThemeData>('dividerTheme', dividerTheme, defaultValue: defaultData.dividerTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<DrawerThemeData>('drawerTheme', drawerTheme, defaultValue: defaultData.drawerTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<DropdownMenuThemeData>('dropdownMenuTheme', dropdownMenuTheme, defaultValue: defaultData.dropdownMenuTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ElevatedButtonThemeData>('elevatedButtonTheme', elevatedButtonTheme, defaultValue: defaultData.elevatedButtonTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ExpansionTileThemeData>('expansionTileTheme', expansionTileTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<FilledButtonThemeData>('filledButtonTheme', filledButtonTheme, defaultValue: defaultData.filledButtonTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<FloatingActionButtonThemeData>('floatingActionButtonTheme', floatingActionButtonTheme, defaultValue: defaultData.floatingActionButtonTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<IconButtonThemeData>('iconButtonTheme', iconButtonTheme, defaultValue: defaultData.iconButtonTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ListTileThemeData>('listTileTheme', listTileTheme, defaultValue: defaultData.listTileTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<MenuBarThemeData>('menuBarTheme', menuBarTheme, defaultValue: defaultData.menuBarTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<MenuButtonThemeData>('menuButtonTheme', menuButtonTheme, defaultValue: defaultData.menuButtonTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<MenuThemeData>('menuTheme', menuTheme, defaultValue: defaultData.menuTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<NavigationBarThemeData>('navigationBarTheme', navigationBarTheme, defaultValue: defaultData.navigationBarTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<NavigationDrawerThemeData>('navigationDrawerTheme', navigationDrawerTheme, defaultValue: defaultData.navigationDrawerTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<NavigationRailThemeData>('navigationRailTheme', navigationRailTheme, defaultValue: defaultData.navigationRailTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<OutlinedButtonThemeData>('outlinedButtonTheme', outlinedButtonTheme, defaultValue: defaultData.outlinedButtonTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<PopupMenuThemeData>('popupMenuTheme', popupMenuTheme, defaultValue: defaultData.popupMenuTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ProgressIndicatorThemeData>('progressIndicatorTheme', progressIndicatorTheme, defaultValue: defaultData.progressIndicatorTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<RadioThemeData>('radioTheme', radioTheme, defaultValue: defaultData.radioTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<SearchBarThemeData>('searchBarTheme', searchBarTheme, defaultValue: defaultData.searchBarTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<SearchViewThemeData>('searchViewTheme', searchViewTheme, defaultValue: defaultData.searchViewTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<SegmentedButtonThemeData>('segmentedButtonTheme', segmentedButtonTheme, defaultValue: defaultData.segmentedButtonTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<SliderThemeData>('sliderTheme', sliderTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<SnackBarThemeData>('snackBarTheme', snackBarTheme, defaultValue: defaultData.snackBarTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<SwitchThemeData>('switchTheme', switchTheme, defaultValue: defaultData.switchTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<TabBarTheme>('tabBarTheme', tabBarTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<TextButtonThemeData>('textButtonTheme', textButtonTheme, defaultValue: defaultData.textButtonTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<TextSelectionThemeData>('textSelectionTheme', textSelectionTheme, defaultValue: defaultData.textSelectionTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<TimePickerThemeData>('timePickerTheme', timePickerTheme, defaultValue: defaultData.timePickerTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ToggleButtonsThemeData>('toggleButtonsTheme', toggleButtonsTheme, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<TooltipThemeData>('tooltipTheme', tooltipTheme, level: DiagnosticLevel.debug)); + // DEPRECATED (newest deprecations at the bottom) + properties.add(ColorProperty('toggleableActiveColor', toggleableActiveColor, defaultValue: defaultData.toggleableActiveColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('errorColor', errorColor, defaultValue: defaultData.errorColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: defaultData.backgroundColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('bottomAppBarColor', bottomAppBarColor, defaultValue: defaultData.bottomAppBarColor, level: DiagnosticLevel.debug)); + } +} + +/// A [CupertinoThemeData] that defers unspecified theme attributes to an +/// upstream Material [ThemeData]. +/// +/// This type of [CupertinoThemeData] is used by the Material [Theme] to +/// harmonize the [CupertinoTheme] with the material theme's colors and text +/// styles. +/// +/// In the most basic case, [ThemeData]'s `cupertinoOverrideTheme` is null and +/// descendant Cupertino widgets' styling is derived from the Material theme. +/// +/// To override individual parts of the Material-derived Cupertino styling, +/// `cupertinoOverrideTheme`'s construction parameters can be used. +/// +/// To completely decouple the Cupertino styling from Material theme derivation, +/// another [CupertinoTheme] widget can be inserted as a descendant of the +/// Material [Theme]. On a [MaterialApp], this can be done using the `builder` +/// parameter on the constructor. +/// +/// See also: +/// +/// * [CupertinoThemeData], whose null constructor parameters default to +/// reasonable iOS styling defaults rather than harmonizing with a Material +/// theme. +/// * [Theme], widget which inserts a [CupertinoTheme] with this +/// [MaterialBasedCupertinoThemeData]. +// This class subclasses CupertinoThemeData rather than composes one because it +// _is_ a CupertinoThemeData with partially altered behavior. e.g. its textTheme +// is from the superclass and based on the primaryColor but the primaryColor +// comes from the Material theme unless overridden. +class MaterialBasedCupertinoThemeData extends CupertinoThemeData { + /// Create a [MaterialBasedCupertinoThemeData] based on a Material [ThemeData] + /// and its `cupertinoOverrideTheme`. + MaterialBasedCupertinoThemeData({ + required ThemeData materialTheme, + }) : this._( + materialTheme, + (materialTheme.cupertinoOverrideTheme ?? const CupertinoThemeData()).noDefault(), + ); + + MaterialBasedCupertinoThemeData._( + this._materialTheme, + this._cupertinoOverrideTheme, + ) : // Pass all values to the superclass so Material-agnostic properties + // like barBackgroundColor can still behave like a normal + // CupertinoThemeData. + super.raw( + _cupertinoOverrideTheme.brightness, + _cupertinoOverrideTheme.primaryColor, + _cupertinoOverrideTheme.primaryContrastingColor, + _cupertinoOverrideTheme.textTheme, + _cupertinoOverrideTheme.barBackgroundColor, + _cupertinoOverrideTheme.scaffoldBackgroundColor, + _cupertinoOverrideTheme.applyThemeToAll, + ); + + final ThemeData _materialTheme; + final NoDefaultCupertinoThemeData _cupertinoOverrideTheme; + + @override + Brightness get brightness => _cupertinoOverrideTheme.brightness ?? _materialTheme.brightness; + + @override + Color get primaryColor => _cupertinoOverrideTheme.primaryColor ?? _materialTheme.colorScheme.primary; + + @override + Color get primaryContrastingColor => _cupertinoOverrideTheme.primaryContrastingColor ?? _materialTheme.colorScheme.onPrimary; + + @override + Color get scaffoldBackgroundColor => _cupertinoOverrideTheme.scaffoldBackgroundColor ?? _materialTheme.scaffoldBackgroundColor; + + /// Copies the [ThemeData]'s `cupertinoOverrideTheme`. + /// + /// Only the specified override attributes of the [ThemeData]'s + /// `cupertinoOverrideTheme` and the newly specified parameters are in the + /// returned [CupertinoThemeData]. No derived attributes from iOS defaults or + /// from cascaded Material theme attributes are copied. + /// + /// This [copyWith] cannot change the base Material [ThemeData]. To change the + /// base Material [ThemeData], create a new Material [Theme] and use + /// [ThemeData.copyWith] on the Material [ThemeData] instead. + @override + MaterialBasedCupertinoThemeData copyWith({ + Brightness? brightness, + Color? primaryColor, + Color? primaryContrastingColor, + CupertinoTextThemeData? textTheme, + Color? barBackgroundColor, + Color? scaffoldBackgroundColor, + bool? applyThemeToAll, + }) { + return MaterialBasedCupertinoThemeData._( + _materialTheme, + _cupertinoOverrideTheme.copyWith( + brightness: brightness, + primaryColor: primaryColor, + primaryContrastingColor: primaryContrastingColor, + textTheme: textTheme, + barBackgroundColor: barBackgroundColor, + scaffoldBackgroundColor: scaffoldBackgroundColor, + applyThemeToAll: applyThemeToAll, + ), + ); + } + + @override + CupertinoThemeData resolveFrom(BuildContext context) { + // Only the cupertino override theme part will be resolved. + // If the color comes from the material theme it's not resolved. + return MaterialBasedCupertinoThemeData._( + _materialTheme, + _cupertinoOverrideTheme.resolveFrom(context), + ); + } +} + +@immutable +class _IdentityThemeDataCacheKey { + const _IdentityThemeDataCacheKey(this.baseTheme, this.localTextGeometry); + + final ThemeData baseTheme; + final TextTheme localTextGeometry; + + // Using XOR to make the hash function as fast as possible (e.g. Jenkins is + // noticeably slower). + @override + int get hashCode => identityHashCode(baseTheme) ^ identityHashCode(localTextGeometry); + + @override + bool operator ==(Object other) { + // We are explicitly ignoring the possibility that the types might not + // match in the interests of speed. + return other is _IdentityThemeDataCacheKey + && identical(other.baseTheme, baseTheme) + && identical(other.localTextGeometry, localTextGeometry); + } +} + +/// Cache of objects of limited size that uses the first in first out eviction +/// strategy (a.k.a least recently inserted). +/// +/// The key that was inserted before all other keys is evicted first, i.e. the +/// one inserted least recently. +class _FifoCache<K, V> { + _FifoCache(this._maximumSize) : assert(_maximumSize > 0); + + /// In Dart the map literal uses a linked hash-map implementation, whose keys + /// are stored such that [Map.keys] returns them in the order they were + /// inserted. + final Map<K, V> _cache = <K, V>{}; + + /// Maximum number of entries to store in the cache. + /// + /// Once this many entries have been cached, the entry inserted least recently + /// is evicted when adding a new entry. + final int _maximumSize; + + /// Returns the previously cached value for the given key, if available; + /// if not, calls the given callback to obtain it first. + V putIfAbsent(K key, V Function() loader) { + assert(key != null); + final V? result = _cache[key]; + if (result != null) { + return result; + } + if (_cache.length == _maximumSize) { + _cache.remove(_cache.keys.first); + } + return _cache[key] = loader(); + } +} + +/// Defines the visual density of user interface components. +/// +/// Density, in the context of a UI, is the vertical and horizontal +/// "compactness" of the components in the UI. It is unitless, since it means +/// different things to different UI components. +/// +/// The default for visual densities is zero for both vertical and horizontal +/// densities, which corresponds to the default visual density of components in +/// the Material Design specification. It does not affect text sizes, icon +/// sizes, or padding values. +/// +/// For example, for buttons, it affects the spacing around the child of the +/// button. For lists, it affects the distance between baselines of entries in +/// the list. For chips, it only affects the vertical size, not the horizontal +/// size. +/// +/// Here are some examples of widgets that respond to density changes: +/// +/// * [Checkbox] +/// * [Chip] +/// * [ElevatedButton] +/// * [IconButton] +/// * [InputDecorator] (which gives density support to [TextField], etc.) +/// * [ListTile] +/// * [MaterialButton] +/// * [OutlinedButton] +/// * [Radio] +/// * [RawMaterialButton] +/// * [TextButton] +/// +/// See also: +/// +/// * [ThemeData.visualDensity], where this property is used to specify the base +/// horizontal density of Material components. +/// * [Material design guidance on density](https://material.io/design/layout/applying-density.html). +@immutable +class VisualDensity with Diagnosticable { + /// A const constructor for [VisualDensity]. + /// + /// The [horizontal] and [vertical] arguments must be in the interval between + /// [minimumDensity] and [maximumDensity], inclusive. + const VisualDensity({ + this.horizontal = 0.0, + this.vertical = 0.0, + }) : assert(vertical <= maximumDensity), + assert(vertical <= maximumDensity), + assert(vertical >= minimumDensity), + assert(horizontal <= maximumDensity), + assert(horizontal >= minimumDensity); + + /// The minimum allowed density. + static const double minimumDensity = -4.0; + + /// The maximum allowed density. + static const double maximumDensity = 4.0; + + /// The default profile for [VisualDensity] in [ThemeData]. + /// + /// This default value represents a visual density that is less dense than + /// either [comfortable] or [compact], and corresponds to density values of + /// zero in both axes. + static const VisualDensity standard = VisualDensity(); + + /// The profile for a "comfortable" interpretation of [VisualDensity]. + /// + /// Individual components will interpret the density value independently, + /// making themselves more visually dense than [standard] and less dense than + /// [compact] to different degrees based on the Material Design specification + /// of the "comfortable" setting for their particular use case. + /// + /// It corresponds to a density value of -1 in both axes. + static const VisualDensity comfortable = VisualDensity(horizontal: -1.0, vertical: -1.0); + + /// The profile for a "compact" interpretation of [VisualDensity]. + /// + /// Individual components will interpret the density value independently, + /// making themselves more visually dense than [standard] and [comfortable] to + /// different degrees based on the Material Design specification of the + /// "comfortable" setting for their particular use case. + /// + /// It corresponds to a density value of -2 in both axes. + static const VisualDensity compact = VisualDensity(horizontal: -2.0, vertical: -2.0); + + /// Returns a [VisualDensity] that is adaptive based on the current platform + /// on which the framework is executing, from [defaultTargetPlatform]. + /// + /// When [defaultTargetPlatform] is a desktop platform, this returns + /// [compact], and for other platforms, it returns a default-constructed + /// [VisualDensity]. + /// + /// See also: + /// + /// * [defaultDensityForPlatform] which returns a [VisualDensity] that is + /// adaptive based on the platform given to it. + /// * [defaultTargetPlatform] which returns the platform on which the + /// framework is currently executing. + static VisualDensity get adaptivePlatformDensity => defaultDensityForPlatform(defaultTargetPlatform); + + /// Returns a [VisualDensity] that is adaptive based on the given [platform]. + /// + /// For desktop platforms, this returns [compact], and for other platforms, it + /// returns a default-constructed [VisualDensity]. + /// + /// See also: + /// + /// * [adaptivePlatformDensity] which returns a [VisualDensity] that is + /// adaptive based on [defaultTargetPlatform]. + static VisualDensity defaultDensityForPlatform(TargetPlatform platform) { + switch (platform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + case TargetPlatform.fuchsia: + break; + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return compact; + } + return VisualDensity.standard; + } + + /// Copy the current [VisualDensity] with the given values replacing the + /// current values. + VisualDensity copyWith({ + double? horizontal, + double? vertical, + }) { + return VisualDensity( + horizontal: horizontal ?? this.horizontal, + vertical: vertical ?? this.vertical, + ); + } + + /// The horizontal visual density of UI components. + /// + /// This property affects only the horizontal spacing between and within + /// components, to allow for different UI visual densities. It does not affect + /// text sizes, icon sizes, or padding values. The default value is 0.0, + /// corresponding to the metrics specified in the Material Design + /// specification. The value can range from [minimumDensity] to + /// [maximumDensity], inclusive. + /// + /// See also: + /// + /// * [ThemeData.visualDensity], where this property is used to specify the base + /// horizontal density of Material components. + /// * [Material design guidance on density](https://material.io/design/layout/applying-density.html). + final double horizontal; + + /// The vertical visual density of UI components. + /// + /// This property affects only the vertical spacing between and within + /// components, to allow for different UI visual densities. It does not affect + /// text sizes, icon sizes, or padding values. The default value is 0.0, + /// corresponding to the metrics specified in the Material Design + /// specification. The value can range from [minimumDensity] to + /// [maximumDensity], inclusive. + /// + /// See also: + /// + /// * [ThemeData.visualDensity], where this property is used to specify the base + /// vertical density of Material components. + /// * [Material design guidance on density](https://material.io/design/layout/applying-density.html). + final double vertical; + + /// The base adjustment in logical pixels of the visual density of UI components. + /// + /// The input density values are multiplied by a constant to arrive at a base + /// size adjustment that fits Material Design guidelines. + /// + /// Individual components may adjust this value based upon their own + /// individual interpretation of density. + Offset get baseSizeAdjustment { + // The number of logical pixels represented by an increase or decrease in + // density by one. The Material Design guidelines say to increment/decrement + // sizes in terms of four pixel increments. + const double interval = 4.0; + + return Offset(horizontal, vertical) * interval; + } + + /// Linearly interpolate between two densities. + static VisualDensity lerp(VisualDensity a, VisualDensity b, double t) { + if (identical(a, b)) { + return a; + } + return VisualDensity( + horizontal: lerpDouble(a.horizontal, b.horizontal, t)!, + vertical: lerpDouble(a.vertical, b.vertical, t)!, + ); + } + + /// Return a copy of [constraints] whose minimum width and height have been + /// updated with the [baseSizeAdjustment]. + /// + /// The resulting minWidth and minHeight values are clamped to not exceed the + /// maxWidth and maxHeight values, respectively. + BoxConstraints effectiveConstraints(BoxConstraints constraints) { + assert(constraints.debugAssertIsValid()); + return constraints.copyWith( + minWidth: clampDouble(constraints.minWidth + baseSizeAdjustment.dx, 0.0, constraints.maxWidth), + minHeight: clampDouble(constraints.minHeight + baseSizeAdjustment.dy, 0.0, constraints.maxHeight), + ); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is VisualDensity + && other.horizontal == horizontal + && other.vertical == vertical; + } + + @override + int get hashCode => Object.hash(horizontal, vertical); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('horizontal', horizontal, defaultValue: 0.0)); + properties.add(DoubleProperty('vertical', vertical, defaultValue: 0.0)); + } + + @override + String toStringShort() { + return '${super.toStringShort()}(h: ${debugFormatDouble(horizontal)}, v: ${debugFormatDouble(vertical)})'; + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - ColorScheme + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +const ColorScheme _colorSchemeLightM3 = ColorScheme( + brightness: Brightness.light, + primary: Color(0xFF6750A4), + onPrimary: Color(0xFFFFFFFF), + primaryContainer: Color(0xFFEADDFF), + onPrimaryContainer: Color(0xFF21005D), + secondary: Color(0xFF625B71), + onSecondary: Color(0xFFFFFFFF), + secondaryContainer: Color(0xFFE8DEF8), + onSecondaryContainer: Color(0xFF1D192B), + tertiary: Color(0xFF7D5260), + onTertiary: Color(0xFFFFFFFF), + tertiaryContainer: Color(0xFFFFD8E4), + onTertiaryContainer: Color(0xFF31111D), + error: Color(0xFFB3261E), + onError: Color(0xFFFFFFFF), + errorContainer: Color(0xFFF9DEDC), + onErrorContainer: Color(0xFF410E0B), + background: Color(0xFFFFFBFE), + onBackground: Color(0xFF1C1B1F), + surface: Color(0xFFFFFBFE), + onSurface: Color(0xFF1C1B1F), + surfaceVariant: Color(0xFFE7E0EC), + onSurfaceVariant: Color(0xFF49454F), + outline: Color(0xFF79747E), + outlineVariant: Color(0xFFCAC4D0), + shadow: Color(0xFF000000), + scrim: Color(0xFF000000), + inverseSurface: Color(0xFF313033), + onInverseSurface: Color(0xFFF4EFF4), + inversePrimary: Color(0xFFD0BCFF), + // The surfaceTint color is set to the same color as the primary. + surfaceTint: Color(0xFF6750A4), +); + +const ColorScheme _colorSchemeDarkM3 = ColorScheme( + brightness: Brightness.dark, + primary: Color(0xFFD0BCFF), + onPrimary: Color(0xFF381E72), + primaryContainer: Color(0xFF4F378B), + onPrimaryContainer: Color(0xFFEADDFF), + secondary: Color(0xFFCCC2DC), + onSecondary: Color(0xFF332D41), + secondaryContainer: Color(0xFF4A4458), + onSecondaryContainer: Color(0xFFE8DEF8), + tertiary: Color(0xFFEFB8C8), + onTertiary: Color(0xFF492532), + tertiaryContainer: Color(0xFF633B48), + onTertiaryContainer: Color(0xFFFFD8E4), + error: Color(0xFFF2B8B5), + onError: Color(0xFF601410), + errorContainer: Color(0xFF8C1D18), + onErrorContainer: Color(0xFFF9DEDC), + background: Color(0xFF1C1B1F), + onBackground: Color(0xFFE6E1E5), + surface: Color(0xFF1C1B1F), + onSurface: Color(0xFFE6E1E5), + surfaceVariant: Color(0xFF49454F), + onSurfaceVariant: Color(0xFFCAC4D0), + outline: Color(0xFF938F99), + outlineVariant: Color(0xFF49454F), + shadow: Color(0xFF000000), + scrim: Color(0xFF000000), + inverseSurface: Color(0xFFE6E1E5), + onInverseSurface: Color(0xFF313033), + inversePrimary: Color(0xFF6750A4), + // The surfaceTint color is set to the same color as the primary. + surfaceTint: Color(0xFFD0BCFF), +); + +// END GENERATED TOKEN PROPERTIES - ColorScheme diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/time.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/time.dart new file mode 100644 index 0000000000000000000000000000000000000000..679e80a2616e313e4628f817b83259c1ab5fae52 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/time.dart @@ -0,0 +1,253 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'debug.dart'; +import 'material_localizations.dart'; + + +/// Whether the [TimeOfDay] is before or after noon. +enum DayPeriod { + /// Ante meridiem (before noon). + am, + + /// Post meridiem (after noon). + pm, +} + +/// A value representing a time during the day, independent of the date that +/// day might fall on or the time zone. +/// +/// The time is represented by [hour] and [minute] pair. Once created, both +/// values cannot be changed. +/// +/// You can create TimeOfDay using the constructor which requires both hour and +/// minute or using [DateTime] object. +/// Hours are specified between 0 and 23, as in a 24-hour clock. +/// +/// {@tool snippet} +/// +/// ```dart +/// TimeOfDay now = TimeOfDay.now(); +/// const TimeOfDay releaseTime = TimeOfDay(hour: 15, minute: 0); // 3:00pm +/// TimeOfDay roomBooked = TimeOfDay.fromDateTime(DateTime.parse('2018-10-20 16:30:04Z')); // 4:30pm +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [showTimePicker], which returns this type. +/// * [MaterialLocalizations], which provides methods for formatting values of +/// this type according to the chosen [Locale]. +/// * [DateTime], which represents date and time, and is subject to eras and +/// time zones. +@immutable +class TimeOfDay { + /// Creates a time of day. + /// + /// The [hour] argument must be between 0 and 23, inclusive. The [minute] + /// argument must be between 0 and 59, inclusive. + const TimeOfDay({ required this.hour, required this.minute }); + + /// Creates a time of day based on the given time. + /// + /// The [hour] is set to the time's hour and the [minute] is set to the time's + /// minute in the timezone of the given [DateTime]. + TimeOfDay.fromDateTime(DateTime time) + : hour = time.hour, + minute = time.minute; + + /// Creates a time of day based on the current time. + /// + /// The [hour] is set to the current hour and the [minute] is set to the + /// current minute in the local time zone. + factory TimeOfDay.now() { return TimeOfDay.fromDateTime(DateTime.now()); } + + /// The number of hours in one day, i.e. 24. + static const int hoursPerDay = 24; + + /// The number of hours in one day period (see also [DayPeriod]), i.e. 12. + static const int hoursPerPeriod = 12; + + /// The number of minutes in one hour, i.e. 60. + static const int minutesPerHour = 60; + + /// Returns a new TimeOfDay with the hour and/or minute replaced. + TimeOfDay replacing({ int? hour, int? minute }) { + assert(hour == null || (hour >= 0 && hour < hoursPerDay)); + assert(minute == null || (minute >= 0 && minute < minutesPerHour)); + return TimeOfDay(hour: hour ?? this.hour, minute: minute ?? this.minute); + } + + /// The selected hour, in 24 hour time from 0..23. + final int hour; + + /// The selected minute. + final int minute; + + /// Whether this time of day is before or after noon. + DayPeriod get period => hour < hoursPerPeriod ? DayPeriod.am : DayPeriod.pm; + + /// Which hour of the current period (e.g., am or pm) this time is. + /// + /// For 12AM (midnight) and 12PM (noon) this returns 12. + int get hourOfPeriod => hour == 0 || hour == 12 ? 12 : hour - periodOffset; + + /// The hour at which the current period starts. + int get periodOffset => period == DayPeriod.am ? 0 : hoursPerPeriod; + + /// Returns the localized string representation of this time of day. + /// + /// This is a shortcut for [MaterialLocalizations.formatTimeOfDay]. + String format(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + assert(debugCheckHasMaterialLocalizations(context)); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + return localizations.formatTimeOfDay( + this, + alwaysUse24HourFormat: MediaQuery.alwaysUse24HourFormatOf(context), + ); + } + + @override + bool operator ==(Object other) { + return other is TimeOfDay + && other.hour == hour + && other.minute == minute; + } + + @override + int get hashCode => Object.hash(hour, minute); + + @override + String toString() { + String addLeadingZeroIfNeeded(int value) { + if (value < 10) { + return '0$value'; + } + return value.toString(); + } + + final String hourLabel = addLeadingZeroIfNeeded(hour); + final String minuteLabel = addLeadingZeroIfNeeded(minute); + + return '$TimeOfDay($hourLabel:$minuteLabel)'; + } +} + +/// A [RestorableValue] that knows how to save and restore [TimeOfDay]. +/// +/// {@macro flutter.widgets.RestorableNum}. +class RestorableTimeOfDay extends RestorableValue<TimeOfDay> { + /// Creates a [RestorableTimeOfDay]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableTimeOfDay(TimeOfDay defaultValue) : _defaultValue = defaultValue; + + final TimeOfDay _defaultValue; + + @override + TimeOfDay createDefaultValue() => _defaultValue; + + @override + void didUpdateValue(TimeOfDay? oldValue) { + assert(debugIsSerializableForRestoration(value.hour)); + assert(debugIsSerializableForRestoration(value.minute)); + notifyListeners(); + } + + @override + TimeOfDay fromPrimitives(Object? data) { + final List<Object?> timeData = data! as List<Object?>; + return TimeOfDay( + minute: timeData[0]! as int, + hour: timeData[1]! as int, + ); + } + + @override + Object? toPrimitives() => <int>[value.minute, value.hour]; +} + +/// Determines how the time picker invoked using [showTimePicker] formats and +/// lays out the time controls. +/// +/// The time picker provides layout configurations optimized for each of the +/// enum values. +enum TimeOfDayFormat { + /// Corresponds to the ICU 'HH:mm' pattern. + /// + /// This format uses 24-hour two-digit zero-padded hours. Controls are always + /// laid out horizontally. Hours are separated from minutes by one colon + /// character. + HH_colon_mm, + + /// Corresponds to the ICU 'HH.mm' pattern. + /// + /// This format uses 24-hour two-digit zero-padded hours. Controls are always + /// laid out horizontally. Hours are separated from minutes by one dot + /// character. + HH_dot_mm, + + /// Corresponds to the ICU "HH 'h' mm" pattern used in Canadian French. + /// + /// This format uses 24-hour two-digit zero-padded hours. Controls are always + /// laid out horizontally. Hours are separated from minutes by letter 'h'. + frenchCanadian, + + /// Corresponds to the ICU 'H:mm' pattern. + /// + /// This format uses 24-hour non-padded variable-length hours. Controls are + /// always laid out horizontally. Hours are separated from minutes by one + /// colon character. + H_colon_mm, + + /// Corresponds to the ICU 'h:mm a' pattern. + /// + /// This format uses 12-hour non-padded variable-length hours with a day + /// period. Controls are laid out horizontally in portrait mode. In landscape + /// mode, the day period appears vertically after (consistent with the ambient + /// [TextDirection]) hour-minute indicator. Hours are separated from minutes + /// by one colon character. + h_colon_mm_space_a, + + /// Corresponds to the ICU 'a h:mm' pattern. + /// + /// This format uses 12-hour non-padded variable-length hours with a day + /// period. Controls are laid out horizontally in portrait mode. In landscape + /// mode, the day period appears vertically before (consistent with the + /// ambient [TextDirection]) hour-minute indicator. Hours are separated from + /// minutes by one colon character. + a_space_h_colon_mm, +} + +/// Describes how hours are formatted. +enum HourFormat { + /// Zero-padded two-digit 24-hour format ranging from "00" to "23". + HH, + + /// Non-padded variable-length 24-hour format ranging from "0" to "23". + H, + + /// Non-padded variable-length hour in day period format ranging from "1" to + /// "12". + h, +} + +/// The [HourFormat] used for the given [TimeOfDayFormat]. +HourFormat hourFormat({ required TimeOfDayFormat of }) { + switch (of) { + case TimeOfDayFormat.h_colon_mm_space_a: + case TimeOfDayFormat.a_space_h_colon_mm: + return HourFormat.h; + case TimeOfDayFormat.H_colon_mm: + return HourFormat.H; + case TimeOfDayFormat.HH_dot_mm: + case TimeOfDayFormat.HH_colon_mm: + case TimeOfDayFormat.frenchCanadian: + return HourFormat.HH; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/time_picker.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/time_picker.dart new file mode 100644 index 0000000000000000000000000000000000000000..b6400d5eb5bcd6d7e705da4b0a479b623ffc067e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/time_picker.dart @@ -0,0 +1,3681 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; +import 'dart:ui'; + +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'color_scheme.dart'; +import 'colors.dart'; +import 'curves.dart'; +import 'debug.dart'; +import 'dialog.dart'; +import 'feedback.dart'; +import 'icon_button.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'input_border.dart'; +import 'input_decorator.dart'; +import 'material.dart'; +import 'material_localizations.dart'; +import 'material_state.dart'; +import 'text_button.dart'; +import 'text_form_field.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'theme_data.dart'; +import 'time.dart'; +import 'time_picker_theme.dart'; + +// Examples can assume: +// late BuildContext context; + +const Duration _kDialogSizeAnimationDuration = Duration(milliseconds: 200); +const Duration _kDialAnimateDuration = Duration(milliseconds: 200); +const double _kTwoPi = 2 * math.pi; +const Duration _kVibrateCommitDelay = Duration(milliseconds: 100); + +const double _kTimePickerHeaderLandscapeWidth = 216; +const double _kTimePickerInnerDialOffset = 28; +const double _kTimePickerDialMinRadius = 50; +const double _kTimePickerDialPadding = 28; + +/// Interactive input mode of the time picker dialog. +/// +/// In [TimePickerEntryMode.dial] mode, a clock dial is displayed and the user +/// taps or drags the time they wish to select. In TimePickerEntryMode.input] +/// mode, [TextField]s are displayed and the user types in the time they wish to +/// select. +/// +/// See also: +/// +/// * [showTimePicker], a function that shows a [TimePickerDialog] and returns +/// the selected time as a [Future]. +enum TimePickerEntryMode { + /// User picks time from a clock dial. + /// + /// Can switch to [input] by activating a mode button in the dialog. + dial, + + /// User can input the time by typing it into text fields. + /// + /// Can switch to [dial] by activating a mode button in the dialog. + input, + + /// User can only pick time from a clock dial. + /// + /// There is no user interface to switch to another mode. + dialOnly, + + /// User can only input the time by typing it into text fields. + /// + /// There is no user interface to switch to another mode. + inputOnly +} + +// Whether the dial-mode time picker is currently selecting the hour or the +// minute. +enum _HourMinuteMode { hour, minute } + +// Aspects of _TimePickerModel that can be depended upon. +enum _TimePickerAspect { + use24HourFormat, + useMaterial3, + entryMode, + hourMinuteMode, + onHourMinuteModeChanged, + onHourDoubleTapped, + onMinuteDoubleTapped, + hourDialType, + selectedTime, + onSelectedTimeChanged, + orientation, + theme, + defaultTheme, +} + +class _TimePickerModel extends InheritedModel<_TimePickerAspect> { + const _TimePickerModel({ + required this.entryMode, + required this.hourMinuteMode, + required this.onHourMinuteModeChanged, + required this.onHourDoubleTapped, + required this.onMinuteDoubleTapped, + required this.selectedTime, + required this.onSelectedTimeChanged, + required this.use24HourFormat, + required this.useMaterial3, + required this.hourDialType, + required this.orientation, + required this.theme, + required this.defaultTheme, + required super.child, + }); + + final TimePickerEntryMode entryMode; + final _HourMinuteMode hourMinuteMode; + final ValueChanged<_HourMinuteMode> onHourMinuteModeChanged; + final GestureTapCallback onHourDoubleTapped; + final GestureTapCallback onMinuteDoubleTapped; + final TimeOfDay selectedTime; + final ValueChanged<TimeOfDay> onSelectedTimeChanged; + final bool use24HourFormat; + final bool useMaterial3; + final _HourDialType hourDialType; + final Orientation orientation; + final TimePickerThemeData theme; + final _TimePickerDefaults defaultTheme; + + static _TimePickerModel of(BuildContext context, [_TimePickerAspect? aspect]) => InheritedModel.inheritFrom<_TimePickerModel>(context, aspect: aspect)!; + static TimePickerEntryMode entryModeOf(BuildContext context) => of(context, _TimePickerAspect.entryMode).entryMode; + static _HourMinuteMode hourMinuteModeOf(BuildContext context) => of(context, _TimePickerAspect.hourMinuteMode).hourMinuteMode; + static TimeOfDay selectedTimeOf(BuildContext context) => of(context, _TimePickerAspect.selectedTime).selectedTime; + static bool use24HourFormatOf(BuildContext context) => of(context, _TimePickerAspect.use24HourFormat).use24HourFormat; + static bool useMaterial3Of(BuildContext context) => of(context, _TimePickerAspect.useMaterial3).useMaterial3; + static _HourDialType hourDialTypeOf(BuildContext context) => of(context, _TimePickerAspect.hourDialType).hourDialType; + static Orientation orientationOf(BuildContext context) => of(context, _TimePickerAspect.orientation).orientation; + static TimePickerThemeData themeOf(BuildContext context) => of(context, _TimePickerAspect.theme).theme; + static _TimePickerDefaults defaultThemeOf(BuildContext context) => of(context, _TimePickerAspect.defaultTheme).defaultTheme; + + static void setSelectedTime(BuildContext context, TimeOfDay value) => of(context, _TimePickerAspect.onSelectedTimeChanged).onSelectedTimeChanged(value); + static void setHourMinuteMode(BuildContext context, _HourMinuteMode value) => of(context, _TimePickerAspect.onHourMinuteModeChanged).onHourMinuteModeChanged(value); + + @override + bool updateShouldNotifyDependent(_TimePickerModel oldWidget, Set<_TimePickerAspect> dependencies) { + if (use24HourFormat != oldWidget.use24HourFormat && dependencies.contains(_TimePickerAspect.use24HourFormat)) { + return true; + } + if (useMaterial3 != oldWidget.useMaterial3 && dependencies.contains(_TimePickerAspect.useMaterial3)) { + return true; + } + if (entryMode != oldWidget.entryMode && dependencies.contains(_TimePickerAspect.entryMode)) { + return true; + } + if (hourMinuteMode != oldWidget.hourMinuteMode && dependencies.contains(_TimePickerAspect.hourMinuteMode)) { + return true; + } + if (onHourMinuteModeChanged != oldWidget.onHourMinuteModeChanged && dependencies.contains(_TimePickerAspect.onHourMinuteModeChanged)) { + return true; + } + if (onHourMinuteModeChanged != oldWidget.onHourDoubleTapped && dependencies.contains(_TimePickerAspect.onHourDoubleTapped)) { + return true; + } + if (onHourMinuteModeChanged != oldWidget.onMinuteDoubleTapped && dependencies.contains(_TimePickerAspect.onMinuteDoubleTapped)) { + return true; + } + if (hourDialType != oldWidget.hourDialType && dependencies.contains(_TimePickerAspect.hourDialType)) { + return true; + } + if (selectedTime != oldWidget.selectedTime && dependencies.contains(_TimePickerAspect.selectedTime)) { + return true; + } + if (onSelectedTimeChanged != oldWidget.onSelectedTimeChanged && dependencies.contains(_TimePickerAspect.onSelectedTimeChanged)) { + return true; + } + if (orientation != oldWidget.orientation && dependencies.contains(_TimePickerAspect.orientation)) { + return true; + } + if (theme != oldWidget.theme && dependencies.contains(_TimePickerAspect.theme)) { + return true; + } + if (defaultTheme != oldWidget.defaultTheme && dependencies.contains(_TimePickerAspect.defaultTheme)) { + return true; + } + return false; + } + + @override + bool updateShouldNotify(_TimePickerModel oldWidget) { + return use24HourFormat != oldWidget.use24HourFormat + || useMaterial3 != oldWidget.useMaterial3 + || entryMode != oldWidget.entryMode + || hourMinuteMode != oldWidget.hourMinuteMode + || onHourMinuteModeChanged != oldWidget.onHourMinuteModeChanged + || onHourDoubleTapped != oldWidget.onHourDoubleTapped + || onMinuteDoubleTapped != oldWidget.onMinuteDoubleTapped + || hourDialType != oldWidget.hourDialType + || selectedTime != oldWidget.selectedTime + || onSelectedTimeChanged != oldWidget.onSelectedTimeChanged + || orientation != oldWidget.orientation + || theme != oldWidget.theme + || defaultTheme != oldWidget.defaultTheme; + } +} + +class _TimePickerHeader extends StatelessWidget { + const _TimePickerHeader({ required this.helpText }); + + final String helpText; + + @override + Widget build(BuildContext context) { + final TimeOfDayFormat timeOfDayFormat = MaterialLocalizations.of(context).timeOfDayFormat( + alwaysUse24HourFormat: _TimePickerModel.use24HourFormatOf(context), + ); + + final _HourDialType hourDialType = _TimePickerModel.hourDialTypeOf(context); + switch (_TimePickerModel.orientationOf(context)) { + case Orientation.portrait: + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Padding(padding: EdgeInsetsDirectional.only(bottom: _TimePickerModel.useMaterial3Of(context) ? 20 : 24), + child: Text( + helpText, + style: _TimePickerModel.themeOf(context).helpTextStyle ?? _TimePickerModel.defaultThemeOf(context).helpTextStyle, + ), + ), + Row( + children: <Widget>[ + if (hourDialType == _HourDialType.twelveHour && timeOfDayFormat == TimeOfDayFormat.a_space_h_colon_mm) + const _DayPeriodControl(), + Expanded( + child: Row( + // Hour/minutes should not change positions in RTL locales. + textDirection: TextDirection.ltr, + children: <Widget>[ + const Expanded(child: _HourControl()), + _StringFragment(timeOfDayFormat: timeOfDayFormat), + const Expanded(child: _MinuteControl()), + ], + ), + ), + if (hourDialType == _HourDialType.twelveHour && timeOfDayFormat != TimeOfDayFormat.a_space_h_colon_mm) + ...<Widget>[ + const SizedBox(width: 12), + const _DayPeriodControl(), + ], + ], + ), + ], + ); + case Orientation.landscape: + return SizedBox( + width: _kTimePickerHeaderLandscapeWidth, + child: Stack( + children: <Widget>[ + Text( + helpText, + style: _TimePickerModel.themeOf(context).helpTextStyle ?? _TimePickerModel.defaultThemeOf(context).helpTextStyle, + ), + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + if (hourDialType == _HourDialType.twelveHour && timeOfDayFormat == TimeOfDayFormat.a_space_h_colon_mm) + const _DayPeriodControl(), + Padding( + padding: EdgeInsets.only(bottom: hourDialType == _HourDialType.twelveHour ? 12 : 0), + child: Row( + // Hour/minutes should not change positions in RTL locales. + textDirection: TextDirection.ltr, + children: <Widget>[ + const Expanded(child: _HourControl()), + _StringFragment(timeOfDayFormat: timeOfDayFormat), + const Expanded(child: _MinuteControl()), + ], + ), + ), + if (hourDialType == _HourDialType.twelveHour && timeOfDayFormat != TimeOfDayFormat.a_space_h_colon_mm) + const _DayPeriodControl(), + ], + ), + ], + ), + ); + } + } +} + +class _HourMinuteControl extends StatelessWidget { + const _HourMinuteControl({ + required this.text, + required this.onTap, + required this.onDoubleTap, + required this.isSelected, + }); + + final String text; + final GestureTapCallback onTap; + final GestureTapCallback onDoubleTap; + final bool isSelected; + + @override + Widget build(BuildContext context) { + final TimePickerThemeData timePickerTheme = _TimePickerModel.themeOf(context); + final _TimePickerDefaults defaultTheme = _TimePickerModel.defaultThemeOf(context); + final Color backgroundColor = timePickerTheme.hourMinuteColor ?? defaultTheme.hourMinuteColor; + final ShapeBorder shape = timePickerTheme.hourMinuteShape ?? defaultTheme.hourMinuteShape; + + final Set<MaterialState> states = <MaterialState>{ + if (isSelected) MaterialState.selected, + }; + final Color effectiveTextColor = MaterialStateProperty.resolveAs<Color>( + _TimePickerModel.themeOf(context).hourMinuteTextColor ?? _TimePickerModel.defaultThemeOf(context).hourMinuteTextColor, + states, + ); + final TextStyle effectiveStyle = MaterialStateProperty.resolveAs<TextStyle>( + timePickerTheme.hourMinuteTextStyle ?? defaultTheme.hourMinuteTextStyle, + states, + ).copyWith(color: effectiveTextColor); + + final double height; + switch (_TimePickerModel.entryModeOf(context)) { + case TimePickerEntryMode.dial: + case TimePickerEntryMode.dialOnly: + height = defaultTheme.hourMinuteSize.height; + case TimePickerEntryMode.input: + case TimePickerEntryMode.inputOnly: + height = defaultTheme.hourMinuteInputSize.height; + } + + return SizedBox( + height: height, + child: Material( + color: MaterialStateProperty.resolveAs(backgroundColor, states), + clipBehavior: Clip.antiAlias, + shape: shape, + child: InkWell( + onTap: onTap, + onDoubleTap: isSelected ? onDoubleTap : null, + child: Center( + child: Text( + text, + style: effectiveStyle, + textScaler: TextScaler.noScaling, + ), + ), + ), + ), + ); + } +} + +/// Displays the hour fragment. +/// +/// When tapped changes time picker dial mode to [_HourMinuteMode.hour]. +class _HourControl extends StatelessWidget { + const _HourControl(); + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final bool alwaysUse24HourFormat = MediaQuery.alwaysUse24HourFormatOf(context); + final TimeOfDay selectedTime = _TimePickerModel.selectedTimeOf(context); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final String formattedHour = localizations.formatHour( + selectedTime, + alwaysUse24HourFormat: _TimePickerModel.use24HourFormatOf(context), + ); + + TimeOfDay hoursFromSelected(int hoursToAdd) { + switch (_TimePickerModel.hourDialTypeOf(context)) { + case _HourDialType.twentyFourHour: + case _HourDialType.twentyFourHourDoubleRing: + final int selectedHour = selectedTime.hour; + return selectedTime.replacing( + hour: (selectedHour + hoursToAdd) % TimeOfDay.hoursPerDay, + ); + case _HourDialType.twelveHour: + // Cycle 1 through 12 without changing day period. + final int periodOffset = selectedTime.periodOffset; + final int hours = selectedTime.hourOfPeriod; + return selectedTime.replacing( + hour: periodOffset + (hours + hoursToAdd) % TimeOfDay.hoursPerPeriod, + ); + } + } + + final TimeOfDay nextHour = hoursFromSelected(1); + final String formattedNextHour = localizations.formatHour( + nextHour, + alwaysUse24HourFormat: alwaysUse24HourFormat, + ); + final TimeOfDay previousHour = hoursFromSelected(-1); + final String formattedPreviousHour = localizations.formatHour( + previousHour, + alwaysUse24HourFormat: alwaysUse24HourFormat, + ); + + return Semantics( + value: '${localizations.timePickerHourModeAnnouncement} $formattedHour', + excludeSemantics: true, + increasedValue: formattedNextHour, + onIncrease: () { + _TimePickerModel.setSelectedTime(context, nextHour); + }, + decreasedValue: formattedPreviousHour, + onDecrease: () { + _TimePickerModel.setSelectedTime(context, previousHour); + }, + child: _HourMinuteControl( + isSelected: _TimePickerModel.hourMinuteModeOf(context) == _HourMinuteMode.hour, + text: formattedHour, + onTap: Feedback.wrapForTap(() => _TimePickerModel.setHourMinuteMode(context, _HourMinuteMode.hour), context)!, + onDoubleTap: _TimePickerModel.of(context, _TimePickerAspect.onHourDoubleTapped).onHourDoubleTapped, + ), + ); + } +} + +/// A passive fragment showing a string value. +/// +/// Used to display the appropriate separator between the input fields. +class _StringFragment extends StatelessWidget { + const _StringFragment({ required this.timeOfDayFormat }); + + final TimeOfDayFormat timeOfDayFormat; + + String _stringFragmentValue(TimeOfDayFormat timeOfDayFormat) { + switch (timeOfDayFormat) { + case TimeOfDayFormat.h_colon_mm_space_a: + case TimeOfDayFormat.a_space_h_colon_mm: + case TimeOfDayFormat.H_colon_mm: + case TimeOfDayFormat.HH_colon_mm: + return ':'; + case TimeOfDayFormat.HH_dot_mm: + return '.'; + case TimeOfDayFormat.frenchCanadian: + return 'h'; + } + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final TimePickerThemeData timePickerTheme = TimePickerTheme.of(context); + final _TimePickerDefaults defaultTheme = theme.useMaterial3 ? _TimePickerDefaultsM3(context) : _TimePickerDefaultsM2(context); + final Set<MaterialState> states = <MaterialState>{}; + + final Color effectiveTextColor = MaterialStateProperty.resolveAs<Color>( + timePickerTheme.hourMinuteTextColor ?? defaultTheme.hourMinuteTextColor, + states, + ); + final TextStyle effectiveStyle = MaterialStateProperty.resolveAs<TextStyle>( + timePickerTheme.hourMinuteTextStyle ?? defaultTheme.hourMinuteTextStyle, + states, + ).copyWith(color: effectiveTextColor); + + final double height; + switch (_TimePickerModel.entryModeOf(context)) { + case TimePickerEntryMode.dial: + case TimePickerEntryMode.dialOnly: + height = defaultTheme.hourMinuteSize.height; + case TimePickerEntryMode.input: + case TimePickerEntryMode.inputOnly: + height = defaultTheme.hourMinuteInputSize.height; + } + + return ExcludeSemantics( + child: SizedBox( + width: timeOfDayFormat == TimeOfDayFormat.frenchCanadian ? 36 : 24, + height: height, + child: Text( + _stringFragmentValue(timeOfDayFormat), + style: effectiveStyle, + textScaler: TextScaler.noScaling, + textAlign: TextAlign.center, + ), + ), + ); + } +} + +/// Displays the minute fragment. +/// +/// When tapped changes time picker dial mode to [_HourMinuteMode.minute]. +class _MinuteControl extends StatelessWidget { + const _MinuteControl(); + + @override + Widget build(BuildContext context) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final TimeOfDay selectedTime = _TimePickerModel.selectedTimeOf(context); + final String formattedMinute = localizations.formatMinute(selectedTime); + final TimeOfDay nextMinute = selectedTime.replacing( + minute: (selectedTime.minute + 1) % TimeOfDay.minutesPerHour, + ); + final String formattedNextMinute = localizations.formatMinute(nextMinute); + final TimeOfDay previousMinute = selectedTime.replacing( + minute: (selectedTime.minute - 1) % TimeOfDay.minutesPerHour, + ); + final String formattedPreviousMinute = localizations.formatMinute(previousMinute); + + return Semantics( + excludeSemantics: true, + value: '${localizations.timePickerMinuteModeAnnouncement} $formattedMinute', + increasedValue: formattedNextMinute, + onIncrease: () { + _TimePickerModel.setSelectedTime(context, nextMinute); + }, + decreasedValue: formattedPreviousMinute, + onDecrease: () { + _TimePickerModel.setSelectedTime(context, previousMinute); + }, + child: _HourMinuteControl( + isSelected: _TimePickerModel.hourMinuteModeOf(context) == _HourMinuteMode.minute, + text: formattedMinute, + onTap: Feedback.wrapForTap(() => _TimePickerModel.setHourMinuteMode(context, _HourMinuteMode.minute), context)!, + onDoubleTap: _TimePickerModel.of(context, _TimePickerAspect.onMinuteDoubleTapped).onMinuteDoubleTapped, + ), + ); + } +} + +/// Displays the am/pm fragment and provides controls for switching between am +/// and pm. +class _DayPeriodControl extends StatelessWidget { + const _DayPeriodControl({ this.onPeriodChanged }); + + final ValueChanged<TimeOfDay>? onPeriodChanged; + + void _togglePeriod(BuildContext context) { + final TimeOfDay selectedTime = _TimePickerModel.selectedTimeOf(context); + final int newHour = (selectedTime.hour + TimeOfDay.hoursPerPeriod) % TimeOfDay.hoursPerDay; + final TimeOfDay newTime = selectedTime.replacing(hour: newHour); + if (onPeriodChanged != null) { + onPeriodChanged!.call(newTime); + } else { + _TimePickerModel.setSelectedTime(context, newTime); + } + } + + void _setAm(BuildContext context) { + final TimeOfDay selectedTime = _TimePickerModel.selectedTimeOf(context); + if (selectedTime.period == DayPeriod.am) { + return; + } + switch (Theme.of(context).platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + _announceToAccessibility(context, MaterialLocalizations.of(context).anteMeridiemAbbreviation); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + break; + } + _togglePeriod(context); + } + + void _setPm(BuildContext context) { + final TimeOfDay selectedTime = _TimePickerModel.selectedTimeOf(context); + if (selectedTime.period == DayPeriod.pm) { + return; + } + switch (Theme.of(context).platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + _announceToAccessibility(context, MaterialLocalizations.of(context).postMeridiemAbbreviation); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + break; + } + _togglePeriod(context); + } + + @override + Widget build(BuildContext context) { + final MaterialLocalizations materialLocalizations = MaterialLocalizations.of(context); + final TimePickerThemeData timePickerTheme = _TimePickerModel.themeOf(context); + final _TimePickerDefaults defaultTheme = _TimePickerModel.defaultThemeOf(context); + final TimeOfDay selectedTime = _TimePickerModel.selectedTimeOf(context); + final bool amSelected = selectedTime.period == DayPeriod.am; + final bool pmSelected = !amSelected; + final BorderSide resolvedSide = timePickerTheme.dayPeriodBorderSide ?? defaultTheme.dayPeriodBorderSide; + final OutlinedBorder resolvedShape = (timePickerTheme.dayPeriodShape ?? defaultTheme.dayPeriodShape) + .copyWith(side: resolvedSide); + + final Widget amButton = _AmPmButton( + selected: amSelected, + onPressed: () => _setAm(context), + label: materialLocalizations.anteMeridiemAbbreviation, + ); + + final Widget pmButton = _AmPmButton( + selected: pmSelected, + onPressed: () => _setPm(context), + label: materialLocalizations.postMeridiemAbbreviation, + ); + + Size dayPeriodSize; + final Orientation orientation; + switch (_TimePickerModel.entryModeOf(context)) { + case TimePickerEntryMode.dial: + case TimePickerEntryMode.dialOnly: + orientation = _TimePickerModel.orientationOf(context); + switch (orientation) { + case Orientation.portrait: + dayPeriodSize = defaultTheme.dayPeriodPortraitSize; + case Orientation.landscape: + dayPeriodSize = defaultTheme.dayPeriodLandscapeSize; + } + case TimePickerEntryMode.input: + case TimePickerEntryMode.inputOnly: + orientation = Orientation.portrait; + dayPeriodSize = defaultTheme.dayPeriodInputSize; + } + + final Widget result; + switch (orientation) { + case Orientation.portrait: + result = _DayPeriodInputPadding( + minSize: dayPeriodSize, + orientation: orientation, + child: SizedBox.fromSize( + size: dayPeriodSize, + child: Material( + clipBehavior: Clip.antiAlias, + color: Colors.transparent, + shape: resolvedShape, + child: Column( + children: <Widget>[ + Expanded(child: amButton), + Container( + decoration: BoxDecoration(border: Border(top: resolvedSide)), + height: 1, + ), + Expanded(child: pmButton), + ], + ), + ), + ), + ); + case Orientation.landscape: + result = _DayPeriodInputPadding( + minSize: dayPeriodSize, + orientation: orientation, + child: SizedBox( + height: dayPeriodSize.height, + child: Material( + clipBehavior: Clip.antiAlias, + color: Colors.transparent, + shape: resolvedShape, + child: Row( + children: <Widget>[ + Expanded(child: amButton), + Container( + decoration: BoxDecoration(border: Border(left: resolvedSide)), + width: 1, + ), + Expanded(child: pmButton), + ], + ), + ), + ), + ); + } + return result; + } +} + +class _AmPmButton extends StatelessWidget { + const _AmPmButton({ + required this.onPressed, + required this.selected, + required this.label, + }); + + final bool selected; + final VoidCallback onPressed; + final String label; + + @override + Widget build(BuildContext context) { + final Set<MaterialState> states = <MaterialState>{ if (selected) MaterialState.selected }; + final TimePickerThemeData timePickerTheme = _TimePickerModel.themeOf(context); + final _TimePickerDefaults defaultTheme = _TimePickerModel.defaultThemeOf(context); + final Color resolvedBackgroundColor = MaterialStateProperty.resolveAs<Color>(timePickerTheme.dayPeriodColor ?? defaultTheme.dayPeriodColor, states); + final Color resolvedTextColor = MaterialStateProperty.resolveAs<Color>(timePickerTheme.dayPeriodTextColor ?? defaultTheme.dayPeriodTextColor, states); + final TextStyle? resolvedTextStyle = MaterialStateProperty.resolveAs<TextStyle?>(timePickerTheme.dayPeriodTextStyle ?? defaultTheme.dayPeriodTextStyle, states)?.copyWith(color: resolvedTextColor); + final TextScaler buttonTextScaler = MediaQuery.textScalerOf(context).clamp(maxScaleFactor: 2.0); + + return Material( + color: resolvedBackgroundColor, + child: InkWell( + onTap: Feedback.wrapForTap(onPressed, context), + child: Semantics( + checked: selected, + inMutuallyExclusiveGroup: true, + button: true, + child: Center( + child: Text( + label, + style: resolvedTextStyle, + textScaler: buttonTextScaler, + ), + ), + ), + ), + ); + } +} + +/// A widget to pad the area around the [_DayPeriodControl]'s inner [Material]. +class _DayPeriodInputPadding extends SingleChildRenderObjectWidget { + const _DayPeriodInputPadding({ + required Widget super.child, + required this.minSize, + required this.orientation, + }); + + final Size minSize; + final Orientation orientation; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderInputPadding(minSize, orientation); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderInputPadding renderObject) { + renderObject + ..minSize = minSize + ..orientation = orientation; + } +} + +class _RenderInputPadding extends RenderShiftedBox { + _RenderInputPadding(this._minSize, this._orientation, [RenderBox? child]) : super(child); + + Size get minSize => _minSize; + Size _minSize; + set minSize(Size value) { + if (_minSize == value) { + return; + } + _minSize = value; + markNeedsLayout(); + } + + Orientation get orientation => _orientation; + Orientation _orientation; + set orientation(Orientation value) { + if (_orientation == value) { + return; + } + _orientation = value; + markNeedsLayout(); + } + + @override + double computeMinIntrinsicWidth(double height) { + if (child != null) { + return math.max(child!.getMinIntrinsicWidth(height), minSize.width); + } + return 0; + } + + @override + double computeMinIntrinsicHeight(double width) { + if (child != null) { + return math.max(child!.getMinIntrinsicHeight(width), minSize.height); + } + return 0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (child != null) { + return math.max(child!.getMaxIntrinsicWidth(height), minSize.width); + } + return 0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (child != null) { + return math.max(child!.getMaxIntrinsicHeight(width), minSize.height); + } + return 0; + } + + Size _computeSize({required BoxConstraints constraints, required ChildLayouter layoutChild}) { + if (child != null) { + final Size childSize = layoutChild(child!, constraints); + final double width = math.max(childSize.width, minSize.width); + final double height = math.max(childSize.height, minSize.height); + return constraints.constrain(Size(width, height)); + } + return Size.zero; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.dryLayoutChild, + ); + } + + @override + void performLayout() { + size = _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.layoutChild, + ); + if (child != null) { + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = Alignment.center.alongOffset(size - child!.size as Offset); + } + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (super.hitTest(result, position: position)) { + return true; + } + + if (position.dx < 0 || + position.dx > math.max(child!.size.width, minSize.width) || + position.dy < 0 || + position.dy > math.max(child!.size.height, minSize.height)) { + return false; + } + + Offset newPosition = child!.size.center(Offset.zero); + switch (orientation) { + case Orientation.portrait: + if (position.dy > newPosition.dy) { + newPosition += const Offset(0, 1); + } else { + newPosition += const Offset(0, -1); + } + case Orientation.landscape: + if (position.dx > newPosition.dx) { + newPosition += const Offset(1, 0); + } else { + newPosition += const Offset(-1, 0); + } + } + + return result.addWithRawTransform( + transform: MatrixUtils.forceToPoint(newPosition), + position: newPosition, + hitTest: (BoxHitTestResult result, Offset position) { + assert(position == newPosition); + return child!.hitTest(result, position: newPosition); + }, + ); + } +} + +class _TappableLabel { + _TappableLabel({ + required this.value, + required this.inner, + required this.painter, + required this.onTap, + }); + + /// The value this label is displaying. + final int value; + + /// This value is part of the "inner" ring of values on the dial, used for 24 + /// hour input. + final bool inner; + + /// Paints the text of the label. + final TextPainter painter; + + /// Called when a tap gesture is detected on the label. + final VoidCallback onTap; +} + +class _DialPainter extends CustomPainter { + _DialPainter({ + required this.primaryLabels, + required this.selectedLabels, + required this.backgroundColor, + required this.handColor, + required this.handWidth, + required this.dotColor, + required this.dotRadius, + required this.centerRadius, + required this.theta, + required this.radius, + required this.textDirection, + required this.selectedValue, + }) : super(repaint: PaintingBinding.instance.systemFonts); + + final List<_TappableLabel> primaryLabels; + final List<_TappableLabel> selectedLabels; + final Color backgroundColor; + final Color handColor; + final double handWidth; + final Color dotColor; + final double dotRadius; + final double centerRadius; + final double theta; + final double radius; + final TextDirection textDirection; + final int selectedValue; + + void dispose() { + for (final _TappableLabel label in primaryLabels) { + label.painter.dispose(); + } + for (final _TappableLabel label in selectedLabels) { + label.painter.dispose(); + } + primaryLabels.clear(); + selectedLabels.clear(); + } + + @override + void paint(Canvas canvas, Size size) { + final double dialRadius = clampDouble(size.shortestSide / 2, _kTimePickerDialMinRadius + dotRadius, double.infinity); + final double labelRadius = clampDouble(dialRadius - _kTimePickerDialPadding, _kTimePickerDialMinRadius, double.infinity); + final double innerLabelRadius = clampDouble(labelRadius - _kTimePickerInnerDialOffset, 0, double.infinity); + final double handleRadius = clampDouble(labelRadius - (radius < 0.5 ? 1 : 0) * (labelRadius - innerLabelRadius), _kTimePickerDialMinRadius, double.infinity); + final Offset center = Offset(size.width / 2, size.height / 2); + final Offset centerPoint = center; + canvas.drawCircle(centerPoint, dialRadius, Paint()..color = backgroundColor); + + Offset getOffsetForTheta(double theta, double radius) { + return center + Offset(radius * math.cos(theta), -radius * math.sin(theta)); + } + + void paintLabels(List<_TappableLabel> labels, double radius) { + if (labels.isEmpty) { + return; + } + final double labelThetaIncrement = -_kTwoPi / labels.length; + double labelTheta = math.pi / 2; + + for (final _TappableLabel label in labels) { + final TextPainter labelPainter = label.painter; + final Offset labelOffset = Offset(-labelPainter.width / 2, -labelPainter.height / 2); + labelPainter.paint(canvas, getOffsetForTheta(labelTheta, radius) + labelOffset); + labelTheta += labelThetaIncrement; + } + } + + void paintInnerOuterLabels(List<_TappableLabel>? labels) { + if (labels == null) { + return; + } + + paintLabels(labels.where((_TappableLabel label) => !label.inner).toList(), labelRadius); + paintLabels(labels.where((_TappableLabel label) => label.inner).toList(), innerLabelRadius); + } + + paintInnerOuterLabels(primaryLabels); + + final Paint selectorPaint = Paint()..color = handColor; + final Offset focusedPoint = getOffsetForTheta(theta, handleRadius); + canvas.drawCircle(centerPoint, centerRadius, selectorPaint); + canvas.drawCircle(focusedPoint, dotRadius, selectorPaint); + selectorPaint.strokeWidth = handWidth; + canvas.drawLine(centerPoint, focusedPoint, selectorPaint); + + // Add a dot inside the selector but only when it isn't over the labels. + // This checks that the selector's theta is between two labels. A remainder + // between 0.1 and 0.45 indicates that the selector is roughly not above any + // labels. The values were derived by manually testing the dial. + final double labelThetaIncrement = -_kTwoPi / primaryLabels.length; + if (theta % labelThetaIncrement > 0.1 && theta % labelThetaIncrement < 0.45) { + canvas.drawCircle(focusedPoint, 2, selectorPaint..color = dotColor); + } + + final Rect focusedRect = Rect.fromCircle( + center: focusedPoint, + radius: dotRadius, + ); + canvas + ..save() + ..clipPath(Path()..addOval(focusedRect)); + paintInnerOuterLabels(selectedLabels); + canvas.restore(); + } + + @override + bool shouldRepaint(_DialPainter oldPainter) { + return oldPainter.primaryLabels != primaryLabels + || oldPainter.selectedLabels != selectedLabels + || oldPainter.backgroundColor != backgroundColor + || oldPainter.handColor != handColor + || oldPainter.theta != theta; + } +} + +// Which kind of hour dial being presented. +enum _HourDialType { + twentyFourHour, + twentyFourHourDoubleRing, + twelveHour, +} + +class _Dial extends StatefulWidget { + const _Dial({ + required this.selectedTime, + required this.hourMinuteMode, + required this.hourDialType, + required this.onChanged, + required this.onHourSelected, + }); + + final TimeOfDay selectedTime; + final _HourMinuteMode hourMinuteMode; + final _HourDialType hourDialType; + final ValueChanged<TimeOfDay>? onChanged; + final VoidCallback? onHourSelected; + + @override + _DialState createState() => _DialState(); +} + +class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { + late ThemeData themeData; + late MaterialLocalizations localizations; + _DialPainter? painter; + late AnimationController _animationController; + late Tween<double> _thetaTween; + late Animation<double> _theta; + late Tween<double> _radiusTween; + late Animation<double> _radius; + bool _dragging = false; + + @override + void initState() { + super.initState(); + _animationController = AnimationController( + duration: _kDialAnimateDuration, + vsync: this, + ); + _thetaTween = Tween<double>(begin: _getThetaForTime(widget.selectedTime)); + _radiusTween = Tween<double>(begin: _getRadiusForTime(widget.selectedTime)); + _theta = _animationController + .drive(CurveTween(curve: standardEasing)) + .drive(_thetaTween) + ..addListener(() => setState(() { /* _theta.value has changed */ })); + _radius = _animationController + .drive(CurveTween(curve: standardEasing)) + .drive(_radiusTween) + ..addListener(() => setState(() { /* _radius.value has changed */ })); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + assert(debugCheckHasMediaQuery(context)); + themeData = Theme.of(context); + localizations = MaterialLocalizations.of(context); + } + + @override + void didUpdateWidget(_Dial oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.hourMinuteMode != oldWidget.hourMinuteMode || widget.selectedTime != oldWidget.selectedTime) { + if (!_dragging) { + _animateTo(_getThetaForTime(widget.selectedTime), _getRadiusForTime(widget.selectedTime)); + } + } + } + + @override + void dispose() { + _animationController.dispose(); + painter?.dispose(); + super.dispose(); + } + + static double _nearest(double target, double a, double b) { + return ((target - a).abs() < (target - b).abs()) ? a : b; + } + + void _animateTo(double targetTheta, double targetRadius) { + void animateToValue({ + required double target, + required Animation<double> animation, + required Tween<double> tween, + required AnimationController controller, + required double min, + required double max, + }) { + double beginValue = _nearest(target, animation.value, max); + beginValue = _nearest(target, beginValue, min); + tween + ..begin = beginValue + ..end = target; + controller + ..value = 0 + ..forward(); + } + + animateToValue( + target: targetTheta, + animation: _theta, + tween: _thetaTween, + controller: _animationController, + min: _theta.value - _kTwoPi, + max: _theta.value + _kTwoPi, + ); + animateToValue( + target: targetRadius, + animation: _radius, + tween: _radiusTween, + controller: _animationController, + min: 0, + max: 1, + ); + } + + double _getRadiusForTime(TimeOfDay time) { + switch (widget.hourMinuteMode) { + case _HourMinuteMode.hour: + switch (widget.hourDialType) { + case _HourDialType.twentyFourHourDoubleRing: + return time.hour >= 12 ? 0 : 1; + case _HourDialType.twentyFourHour: + case _HourDialType.twelveHour: + return 1; + } + case _HourMinuteMode.minute: + return 1; + } + } + + double _getThetaForTime(TimeOfDay time) { + final int hoursFactor; + switch (widget.hourDialType) { + case _HourDialType.twentyFourHour: + hoursFactor = TimeOfDay.hoursPerDay; + case _HourDialType.twentyFourHourDoubleRing: + hoursFactor = TimeOfDay.hoursPerPeriod; + case _HourDialType.twelveHour: + hoursFactor = TimeOfDay.hoursPerPeriod; + } + final double fraction; + switch (widget.hourMinuteMode) { + case _HourMinuteMode.hour: + fraction = (time.hour / hoursFactor) % hoursFactor; + case _HourMinuteMode.minute: + fraction = (time.minute / TimeOfDay.minutesPerHour) % TimeOfDay.minutesPerHour; + } + return (math.pi / 2 - fraction * _kTwoPi) % _kTwoPi; + } + + TimeOfDay _getTimeForTheta(double theta, {bool roundMinutes = false, required double radius}) { + final double fraction = (0.25 - (theta % _kTwoPi) / _kTwoPi) % 1; + switch (widget.hourMinuteMode) { + case _HourMinuteMode.hour: + int newHour; + switch (widget.hourDialType) { + case _HourDialType.twentyFourHour: + newHour = (fraction * TimeOfDay.hoursPerDay).round() % TimeOfDay.hoursPerDay; + case _HourDialType.twentyFourHourDoubleRing: + newHour = (fraction * TimeOfDay.hoursPerPeriod).round() % TimeOfDay.hoursPerPeriod; + if (radius < 0.5) { + newHour = newHour + TimeOfDay.hoursPerPeriod; + } + case _HourDialType.twelveHour: + newHour = (fraction * TimeOfDay.hoursPerPeriod).round() % TimeOfDay.hoursPerPeriod; + newHour = newHour + widget.selectedTime.periodOffset; + } + return widget.selectedTime.replacing(hour: newHour); + case _HourMinuteMode.minute: + int minute = (fraction * TimeOfDay.minutesPerHour).round() % TimeOfDay.minutesPerHour; + if (roundMinutes) { + // Round the minutes to nearest 5 minute interval. + minute = ((minute + 2) ~/ 5) * 5 % TimeOfDay.minutesPerHour; + } + return widget.selectedTime.replacing(minute: minute); + } + } + + TimeOfDay _notifyOnChangedIfNeeded({ bool roundMinutes = false }) { + final TimeOfDay current = _getTimeForTheta(_theta.value, roundMinutes: roundMinutes, radius: _radius.value); + if (widget.onChanged == null) { + return current; + } + if (current != widget.selectedTime) { + widget.onChanged!(current); + } + return current; + } + + void _updateThetaForPan({ bool roundMinutes = false }) { + setState(() { + final Offset offset = _position! - _center!; + final double labelRadius = _dialSize!.shortestSide / 2 - _kTimePickerDialPadding; + final double innerRadius = labelRadius - _kTimePickerInnerDialOffset; + double angle = (math.atan2(offset.dx, offset.dy) - math.pi / 2) % _kTwoPi; + final double radius = clampDouble((offset.distance - innerRadius) / _kTimePickerInnerDialOffset, 0, 1); + if (roundMinutes) { + angle = _getThetaForTime(_getTimeForTheta(angle, roundMinutes: roundMinutes, radius: radius)); + } + // The controller doesn't animate during the pan gesture. + _thetaTween + ..begin = angle + ..end = angle; + _radiusTween + ..begin = radius + ..end = radius; + }); + } + + Offset? _position; + Offset? _center; + Size? _dialSize; + + void _handlePanStart(DragStartDetails details) { + assert(!_dragging); + _dragging = true; + final RenderBox box = context.findRenderObject()! as RenderBox; + _position = box.globalToLocal(details.globalPosition); + _dialSize = box.size; + _center = _dialSize!.center(Offset.zero); + _updateThetaForPan(); + _notifyOnChangedIfNeeded(); + } + + void _handlePanUpdate(DragUpdateDetails details) { + _position = _position! + details.delta; + _updateThetaForPan(); + _notifyOnChangedIfNeeded(); + } + + void _handlePanEnd(DragEndDetails details) { + assert(_dragging); + _dragging = false; + _position = null; + _center = null; + _dialSize = null; + _animateTo(_getThetaForTime(widget.selectedTime), _getRadiusForTime(widget.selectedTime)); + if (widget.hourMinuteMode == _HourMinuteMode.hour) { + widget.onHourSelected?.call(); + } + } + + void _handleTapUp(TapUpDetails details) { + final RenderBox box = context.findRenderObject()! as RenderBox; + _position = box.globalToLocal(details.globalPosition); + _center = box.size.center(Offset.zero); + _dialSize = box.size; + _updateThetaForPan(roundMinutes: true); + final TimeOfDay newTime = _notifyOnChangedIfNeeded(roundMinutes: true); + if (widget.hourMinuteMode == _HourMinuteMode.hour) { + switch (widget.hourDialType) { + case _HourDialType.twentyFourHour: + case _HourDialType.twentyFourHourDoubleRing: + _announceToAccessibility(context, localizations.formatDecimal(newTime.hour)); + case _HourDialType.twelveHour: + _announceToAccessibility(context, localizations.formatDecimal(newTime.hourOfPeriod)); + } + widget.onHourSelected?.call(); + } else { + _announceToAccessibility(context, localizations.formatDecimal(newTime.minute)); + } + final TimeOfDay time = _getTimeForTheta(_theta.value, roundMinutes: true, radius: _radius.value); + _animateTo(_getThetaForTime(time), _getRadiusForTime(time)); + _dragging = false; + _position = null; + _center = null; + _dialSize = null; + } + + void _selectHour(int hour) { + _announceToAccessibility(context, localizations.formatDecimal(hour)); + final TimeOfDay time; + + TimeOfDay getAmPmTime() { + switch (widget.selectedTime.period) { + case DayPeriod.am: + return TimeOfDay(hour: hour, minute: widget.selectedTime.minute); + case DayPeriod.pm: + return TimeOfDay(hour: hour + TimeOfDay.hoursPerPeriod, minute: widget.selectedTime.minute); + } + } + + switch (widget.hourMinuteMode) { + case _HourMinuteMode.hour: + switch (widget.hourDialType) { + case _HourDialType.twentyFourHour: + case _HourDialType.twentyFourHourDoubleRing: + time = TimeOfDay(hour: hour, minute: widget.selectedTime.minute); + case _HourDialType.twelveHour: + time = getAmPmTime(); + } + case _HourMinuteMode.minute: + time = getAmPmTime(); + } + final double angle = _getThetaForTime(time); + _thetaTween + ..begin = angle + ..end = angle; + _notifyOnChangedIfNeeded(); + } + + void _selectMinute(int minute) { + _announceToAccessibility(context, localizations.formatDecimal(minute)); + final TimeOfDay time = TimeOfDay( + hour: widget.selectedTime.hour, + minute: minute, + ); + final double angle = _getThetaForTime(time); + _thetaTween + ..begin = angle + ..end = angle; + _notifyOnChangedIfNeeded(); + } + + static const List<TimeOfDay> _amHours = <TimeOfDay>[ + TimeOfDay(hour: 12, minute: 0), + TimeOfDay(hour: 1, minute: 0), + TimeOfDay(hour: 2, minute: 0), + TimeOfDay(hour: 3, minute: 0), + TimeOfDay(hour: 4, minute: 0), + TimeOfDay(hour: 5, minute: 0), + TimeOfDay(hour: 6, minute: 0), + TimeOfDay(hour: 7, minute: 0), + TimeOfDay(hour: 8, minute: 0), + TimeOfDay(hour: 9, minute: 0), + TimeOfDay(hour: 10, minute: 0), + TimeOfDay(hour: 11, minute: 0), + ]; + + // On M2, there's no inner ring of numbers. + static const List<TimeOfDay> _twentyFourHoursM2 = <TimeOfDay>[ + TimeOfDay(hour: 0, minute: 0), + TimeOfDay(hour: 2, minute: 0), + TimeOfDay(hour: 4, minute: 0), + TimeOfDay(hour: 6, minute: 0), + TimeOfDay(hour: 8, minute: 0), + TimeOfDay(hour: 10, minute: 0), + TimeOfDay(hour: 12, minute: 0), + TimeOfDay(hour: 14, minute: 0), + TimeOfDay(hour: 16, minute: 0), + TimeOfDay(hour: 18, minute: 0), + TimeOfDay(hour: 20, minute: 0), + TimeOfDay(hour: 22, minute: 0), + ]; + + static const List<TimeOfDay> _twentyFourHours = <TimeOfDay>[ + TimeOfDay(hour: 0, minute: 0), + TimeOfDay(hour: 1, minute: 0), + TimeOfDay(hour: 2, minute: 0), + TimeOfDay(hour: 3, minute: 0), + TimeOfDay(hour: 4, minute: 0), + TimeOfDay(hour: 5, minute: 0), + TimeOfDay(hour: 6, minute: 0), + TimeOfDay(hour: 7, minute: 0), + TimeOfDay(hour: 8, minute: 0), + TimeOfDay(hour: 9, minute: 0), + TimeOfDay(hour: 10, minute: 0), + TimeOfDay(hour: 11, minute: 0), + TimeOfDay(hour: 12, minute: 0), + TimeOfDay(hour: 13, minute: 0), + TimeOfDay(hour: 14, minute: 0), + TimeOfDay(hour: 15, minute: 0), + TimeOfDay(hour: 16, minute: 0), + TimeOfDay(hour: 17, minute: 0), + TimeOfDay(hour: 18, minute: 0), + TimeOfDay(hour: 19, minute: 0), + TimeOfDay(hour: 20, minute: 0), + TimeOfDay(hour: 21, minute: 0), + TimeOfDay(hour: 22, minute: 0), + TimeOfDay(hour: 23, minute: 0), + ]; + + _TappableLabel _buildTappableLabel({ + required TextStyle? textStyle, + required int selectedValue, + required int value, + required bool inner, + required String label, + required VoidCallback onTap, + }) { + return _TappableLabel( + value: value, + inner: inner, + painter: TextPainter( + text: TextSpan(style: textStyle, text: label), + textDirection: TextDirection.ltr, + textScaler: MediaQuery.textScalerOf(context).clamp(maxScaleFactor: 2.0), + )..layout(), + onTap: onTap, + ); + } + + List<_TappableLabel> _build24HourRing({ + required TextStyle? textStyle, + required int selectedValue, + }) { + return <_TappableLabel>[ + if (themeData.useMaterial3) + for (final TimeOfDay timeOfDay in _twentyFourHours) + _buildTappableLabel( + textStyle: textStyle, + selectedValue: selectedValue, + inner: timeOfDay.hour >= 12, + value: timeOfDay.hour, + label: timeOfDay.hour != 0 + ? '${timeOfDay.hour}' + : localizations.formatHour(timeOfDay, alwaysUse24HourFormat: true), + onTap: () { + _selectHour(timeOfDay.hour); + }, + ), + if (!themeData.useMaterial3) + for (final TimeOfDay timeOfDay in _twentyFourHoursM2) + _buildTappableLabel( + textStyle: textStyle, + selectedValue: selectedValue, + inner: false, + value: timeOfDay.hour, + label: localizations.formatHour(timeOfDay, alwaysUse24HourFormat: true), + onTap: () { + _selectHour(timeOfDay.hour); + }, + ), + ]; + } + + List<_TappableLabel> _build12HourRing({ + required TextStyle? textStyle, + required int selectedValue, + }) { + return <_TappableLabel>[ + for (final TimeOfDay timeOfDay in _amHours) + _buildTappableLabel( + textStyle: textStyle, + selectedValue: selectedValue, + inner: false, + value: timeOfDay.hour, + label: localizations.formatHour(timeOfDay, alwaysUse24HourFormat: MediaQuery.alwaysUse24HourFormatOf(context)), + onTap: () { + _selectHour(timeOfDay.hour); + }, + ), + ]; + } + + List<_TappableLabel> _buildMinutes({ + required TextStyle? textStyle, + required int selectedValue, + }) { + const List<TimeOfDay> minuteMarkerValues = <TimeOfDay>[ + TimeOfDay(hour: 0, minute: 0), + TimeOfDay(hour: 0, minute: 5), + TimeOfDay(hour: 0, minute: 10), + TimeOfDay(hour: 0, minute: 15), + TimeOfDay(hour: 0, minute: 20), + TimeOfDay(hour: 0, minute: 25), + TimeOfDay(hour: 0, minute: 30), + TimeOfDay(hour: 0, minute: 35), + TimeOfDay(hour: 0, minute: 40), + TimeOfDay(hour: 0, minute: 45), + TimeOfDay(hour: 0, minute: 50), + TimeOfDay(hour: 0, minute: 55), + ]; + + return <_TappableLabel>[ + for (final TimeOfDay timeOfDay in minuteMarkerValues) + _buildTappableLabel( + textStyle: textStyle, + selectedValue: selectedValue, + inner: false, + value: timeOfDay.minute, + label: localizations.formatMinute(timeOfDay), + onTap: () { + _selectMinute(timeOfDay.minute); + }, + ), + ]; + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final TimePickerThemeData timePickerTheme = TimePickerTheme.of(context); + final _TimePickerDefaults defaultTheme = theme.useMaterial3 ? _TimePickerDefaultsM3(context) : _TimePickerDefaultsM2(context); + final Color backgroundColor = timePickerTheme.dialBackgroundColor ?? defaultTheme.dialBackgroundColor; + final Color dialHandColor = timePickerTheme.dialHandColor ?? defaultTheme.dialHandColor; + final TextStyle labelStyle = timePickerTheme.dialTextStyle ?? defaultTheme.dialTextStyle; + final Color dialTextUnselectedColor = MaterialStateProperty + .resolveAs<Color>(timePickerTheme.dialTextColor ?? defaultTheme.dialTextColor, <MaterialState>{ }); + final Color dialTextSelectedColor = MaterialStateProperty + .resolveAs<Color>(timePickerTheme.dialTextColor ?? defaultTheme.dialTextColor, <MaterialState>{ MaterialState.selected }); + final TextStyle resolvedUnselectedLabelStyle = labelStyle.copyWith(color: dialTextUnselectedColor); + final TextStyle resolvedSelectedLabelStyle = labelStyle.copyWith(color: dialTextSelectedColor); + final Color dotColor = dialTextSelectedColor; + + List<_TappableLabel> primaryLabels; + List<_TappableLabel> selectedLabels; + final int selectedDialValue; + final double radiusValue; + switch (widget.hourMinuteMode) { + case _HourMinuteMode.hour: + switch (widget.hourDialType) { + case _HourDialType.twentyFourHour: + case _HourDialType.twentyFourHourDoubleRing: + selectedDialValue = widget.selectedTime.hour; + primaryLabels = _build24HourRing( + textStyle: resolvedUnselectedLabelStyle, + selectedValue: selectedDialValue, + ); + selectedLabels = _build24HourRing( + textStyle: resolvedSelectedLabelStyle, + selectedValue: selectedDialValue, + ); + radiusValue = theme.useMaterial3 ? _radius.value : 1; + case _HourDialType.twelveHour: + selectedDialValue = widget.selectedTime.hourOfPeriod; + primaryLabels = _build12HourRing( + textStyle: resolvedUnselectedLabelStyle, + selectedValue: selectedDialValue, + ); + selectedLabels = _build12HourRing( + textStyle: resolvedSelectedLabelStyle, + selectedValue: selectedDialValue, + ); + radiusValue = 1; + } + case _HourMinuteMode.minute: + selectedDialValue = widget.selectedTime.minute; + primaryLabels = _buildMinutes( + textStyle: resolvedUnselectedLabelStyle, + selectedValue: selectedDialValue, + ); + selectedLabels = _buildMinutes( + textStyle: resolvedSelectedLabelStyle, + selectedValue: selectedDialValue, + ); + radiusValue = 1; + } + painter?.dispose(); + painter = _DialPainter( + selectedValue: selectedDialValue, + primaryLabels: primaryLabels, + selectedLabels: selectedLabels, + backgroundColor: backgroundColor, + handColor: dialHandColor, + handWidth: defaultTheme.handWidth, + dotColor: dotColor, + dotRadius: defaultTheme.dotRadius, + centerRadius: defaultTheme.centerRadius, + theta: _theta.value, + radius: radiusValue, + textDirection: Directionality.of(context), + ); + + return GestureDetector( + excludeFromSemantics: true, + onPanStart: _handlePanStart, + onPanUpdate: _handlePanUpdate, + onPanEnd: _handlePanEnd, + onTapUp: _handleTapUp, + child: CustomPaint( + key: const ValueKey<String>('time-picker-dial'), + painter: painter, + ), + ); + } +} + +class _TimePickerInput extends StatefulWidget { + const _TimePickerInput({ + required this.initialSelectedTime, + required this.errorInvalidText, + required this.hourLabelText, + required this.minuteLabelText, + required this.helpText, + required this.autofocusHour, + required this.autofocusMinute, + this.restorationId, + }); + + /// The time initially selected when the dialog is shown. + final TimeOfDay initialSelectedTime; + + /// Optionally provide your own validation error text. + final String? errorInvalidText; + + /// Optionally provide your own hour label text. + final String? hourLabelText; + + /// Optionally provide your own minute label text. + final String? minuteLabelText; + + final String helpText; + + final bool? autofocusHour; + + final bool? autofocusMinute; + + /// Restoration ID to save and restore the state of the time picker input + /// widget. + /// + /// If it is non-null, the widget will persist and restore its state + /// + /// The state of this widget is persisted in a [RestorationBucket] claimed + /// from the surrounding [RestorationScope] using the provided restoration ID. + final String? restorationId; + + @override + _TimePickerInputState createState() => _TimePickerInputState(); +} + +class _TimePickerInputState extends State<_TimePickerInput> with RestorationMixin { + late final RestorableTimeOfDay _selectedTime = RestorableTimeOfDay(widget.initialSelectedTime); + final RestorableBool hourHasError = RestorableBool(false); + final RestorableBool minuteHasError = RestorableBool(false); + + @override + void dispose() { + _selectedTime.dispose(); + hourHasError.dispose(); + minuteHasError.dispose(); + super.dispose(); + } + + @override + String? get restorationId => widget.restorationId; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_selectedTime, 'selected_time'); + registerForRestoration(hourHasError, 'hour_has_error'); + registerForRestoration(minuteHasError, 'minute_has_error'); + } + + int? _parseHour(String? value) { + if (value == null) { + return null; + } + + int? newHour = int.tryParse(value); + if (newHour == null) { + return null; + } + + if (MediaQuery.alwaysUse24HourFormatOf(context)) { + if (newHour >= 0 && newHour < 24) { + return newHour; + } + } else { + if (newHour > 0 && newHour < 13) { + if ((_selectedTime.value.period == DayPeriod.pm && newHour != 12) || + (_selectedTime.value.period == DayPeriod.am && newHour == 12)) { + newHour = (newHour + TimeOfDay.hoursPerPeriod) % TimeOfDay.hoursPerDay; + } + return newHour; + } + } + return null; + } + + int? _parseMinute(String? value) { + if (value == null) { + return null; + } + + final int? newMinute = int.tryParse(value); + if (newMinute == null) { + return null; + } + + if (newMinute >= 0 && newMinute < 60) { + return newMinute; + } + return null; + } + + void _handleHourSavedSubmitted(String? value) { + final int? newHour = _parseHour(value); + if (newHour != null) { + _selectedTime.value = TimeOfDay(hour: newHour, minute: _selectedTime.value.minute); + _TimePickerModel.setSelectedTime(context, _selectedTime.value); + FocusScope.of(context).requestFocus(); + } + } + + void _handleHourChanged(String value) { + final int? newHour = _parseHour(value); + if (newHour != null && value.length == 2) { + // If a valid hour is typed, move focus to the minute TextField. + FocusScope.of(context).nextFocus(); + } + } + + void _handleMinuteSavedSubmitted(String? value) { + final int? newMinute = _parseMinute(value); + if (newMinute != null) { + _selectedTime.value = TimeOfDay(hour: _selectedTime.value.hour, minute: int.parse(value!)); + _TimePickerModel.setSelectedTime(context, _selectedTime.value); + FocusScope.of(context).unfocus(); + } + } + + void _handleDayPeriodChanged(TimeOfDay value) { + _selectedTime.value = value; + _TimePickerModel.setSelectedTime(context, _selectedTime.value); + } + + String? _validateHour(String? value) { + final int? newHour = _parseHour(value); + setState(() { + hourHasError.value = newHour == null; + }); + // This is used as the validator for the [TextFormField]. + // Returning an empty string allows the field to go into an error state. + // Returning null means no error in the validation of the entered text. + return newHour == null ? '' : null; + } + + String? _validateMinute(String? value) { + final int? newMinute = _parseMinute(value); + setState(() { + minuteHasError.value = newMinute == null; + }); + // This is used as the validator for the [TextFormField]. + // Returning an empty string allows the field to go into an error state. + // Returning null means no error in the validation of the entered text. + return newMinute == null ? '' : null; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final TimeOfDayFormat timeOfDayFormat = MaterialLocalizations.of(context).timeOfDayFormat(alwaysUse24HourFormat: _TimePickerModel.use24HourFormatOf(context)); + final bool use24HourDials = hourFormat(of: timeOfDayFormat) != HourFormat.h; + final ThemeData theme = Theme.of(context); + final TimePickerThemeData timePickerTheme = _TimePickerModel.themeOf(context); + final _TimePickerDefaults defaultTheme = _TimePickerModel.defaultThemeOf(context); + final TextStyle hourMinuteStyle = timePickerTheme.hourMinuteTextStyle ?? defaultTheme.hourMinuteTextStyle; + + return Padding( + padding: _TimePickerModel.useMaterial3Of(context) ? EdgeInsets.zero : const EdgeInsets.symmetric(horizontal: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Padding(padding: EdgeInsetsDirectional.only(bottom: _TimePickerModel.useMaterial3Of(context) ? 20 : 24), + child: Text( + widget.helpText, + style: _TimePickerModel.themeOf(context).helpTextStyle ?? _TimePickerModel.defaultThemeOf(context).helpTextStyle, + ), + ), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + if (!use24HourDials && timeOfDayFormat == TimeOfDayFormat.a_space_h_colon_mm) ...<Widget>[ + Padding( + padding: const EdgeInsetsDirectional.only(end: 12), + child: _DayPeriodControl(onPeriodChanged: _handleDayPeriodChanged), + ), + ], + Expanded( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + // Hour/minutes should not change positions in RTL locales. + textDirection: TextDirection.ltr, + children: <Widget>[ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Padding( + padding: const EdgeInsets.only(bottom: 10), + child: _HourTextField( + restorationId: 'hour_text_field', + selectedTime: _selectedTime.value, + style: hourMinuteStyle, + autofocus: widget.autofocusHour, + inputAction: TextInputAction.next, + validator: _validateHour, + onSavedSubmitted: _handleHourSavedSubmitted, + onChanged: _handleHourChanged, + hourLabelText: widget.hourLabelText, + ), + ), + if (!hourHasError.value && !minuteHasError.value) + ExcludeSemantics( + child: Text( + widget.hourLabelText ?? MaterialLocalizations.of(context).timePickerHourLabel, + style: theme.textTheme.bodySmall, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ), + ], + ), + ), + _StringFragment(timeOfDayFormat: timeOfDayFormat), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Padding( + padding: const EdgeInsets.only(bottom: 10), + child: _MinuteTextField( + restorationId: 'minute_text_field', + selectedTime: _selectedTime.value, + style: hourMinuteStyle, + autofocus: widget.autofocusMinute, + inputAction: TextInputAction.done, + validator: _validateMinute, + onSavedSubmitted: _handleMinuteSavedSubmitted, + minuteLabelText: widget.minuteLabelText, + ), + ), + if (!hourHasError.value && !minuteHasError.value) + ExcludeSemantics( + child: Text( + widget.minuteLabelText ?? MaterialLocalizations.of(context).timePickerMinuteLabel, + style: theme.textTheme.bodySmall, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ), + ], + ), + ), + ], + ), + ), + if (!use24HourDials && timeOfDayFormat != TimeOfDayFormat.a_space_h_colon_mm) ...<Widget>[ + Padding( + padding: const EdgeInsetsDirectional.only(start: 12), + child: _DayPeriodControl(onPeriodChanged: _handleDayPeriodChanged), + ), + ], + ], + ), + if (hourHasError.value || minuteHasError.value) + Text( + widget.errorInvalidText ?? MaterialLocalizations.of(context).invalidTimeLabel, + style: theme.textTheme.bodyMedium!.copyWith(color: theme.colorScheme.error), + ) + else + const SizedBox(height: 2), + ], + ), + ); + } +} + +class _HourTextField extends StatelessWidget { + const _HourTextField({ + required this.selectedTime, + required this.style, + required this.autofocus, + required this.inputAction, + required this.validator, + required this.onSavedSubmitted, + required this.onChanged, + required this.hourLabelText, + this.restorationId, + }); + + final TimeOfDay selectedTime; + final TextStyle style; + final bool? autofocus; + final TextInputAction inputAction; + final FormFieldValidator<String> validator; + final ValueChanged<String?> onSavedSubmitted; + final ValueChanged<String> onChanged; + final String? hourLabelText; + final String? restorationId; + + @override + Widget build(BuildContext context) { + return _HourMinuteTextField( + restorationId: restorationId, + selectedTime: selectedTime, + isHour: true, + autofocus: autofocus, + inputAction: inputAction, + style: style, + semanticHintText: hourLabelText ?? MaterialLocalizations.of(context).timePickerHourLabel, + validator: validator, + onSavedSubmitted: onSavedSubmitted, + onChanged: onChanged, + ); + } +} + +class _MinuteTextField extends StatelessWidget { + const _MinuteTextField({ + required this.selectedTime, + required this.style, + required this.autofocus, + required this.inputAction, + required this.validator, + required this.onSavedSubmitted, + required this.minuteLabelText, + this.restorationId, + }); + + final TimeOfDay selectedTime; + final TextStyle style; + final bool? autofocus; + final TextInputAction inputAction; + final FormFieldValidator<String> validator; + final ValueChanged<String?> onSavedSubmitted; + final String? minuteLabelText; + final String? restorationId; + + @override + Widget build(BuildContext context) { + return _HourMinuteTextField( + restorationId: restorationId, + selectedTime: selectedTime, + isHour: false, + autofocus: autofocus, + inputAction: inputAction, + style: style, + semanticHintText: minuteLabelText ?? MaterialLocalizations.of(context).timePickerMinuteLabel, + validator: validator, + onSavedSubmitted: onSavedSubmitted, + ); + } +} + +class _HourMinuteTextField extends StatefulWidget { + const _HourMinuteTextField({ + required this.selectedTime, + required this.isHour, + required this.autofocus, + required this.inputAction, + required this.style, + required this.semanticHintText, + required this.validator, + required this.onSavedSubmitted, + this.restorationId, + this.onChanged, + }); + + final TimeOfDay selectedTime; + final bool isHour; + final bool? autofocus; + final TextInputAction inputAction; + final TextStyle style; + final String semanticHintText; + final FormFieldValidator<String> validator; + final ValueChanged<String?> onSavedSubmitted; + final ValueChanged<String>? onChanged; + final String? restorationId; + + @override + _HourMinuteTextFieldState createState() => _HourMinuteTextFieldState(); +} + +class _HourMinuteTextFieldState extends State<_HourMinuteTextField> with RestorationMixin { + final RestorableTextEditingController controller = RestorableTextEditingController(); + final RestorableBool controllerHasBeenSet = RestorableBool(false); + late FocusNode focusNode; + + @override + void initState() { + super.initState(); + focusNode = FocusNode() + ..addListener(() { + setState(() { + // Rebuild when focus changes. + }); + }); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + // Only set the text value if it has not been populated with a localized + // version yet. + if (!controllerHasBeenSet.value) { + controllerHasBeenSet.value = true; + controller.value.text = _formattedValue; + } + } + + @override + void dispose() { + controller.dispose(); + controllerHasBeenSet.dispose(); + focusNode.dispose(); + super.dispose(); + } + + @override + String? get restorationId => widget.restorationId; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(controller, 'text_editing_controller'); + registerForRestoration(controllerHasBeenSet, 'has_controller_been_set'); + } + + String get _formattedValue { + final bool alwaysUse24HourFormat = MediaQuery.alwaysUse24HourFormatOf(context); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + return !widget.isHour + ? localizations.formatMinute(widget.selectedTime) + : localizations.formatHour( + widget.selectedTime, + alwaysUse24HourFormat: alwaysUse24HourFormat, + ); + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final TimePickerThemeData timePickerTheme = TimePickerTheme.of(context); + final _TimePickerDefaults defaultTheme = theme.useMaterial3 ? _TimePickerDefaultsM3(context) : _TimePickerDefaultsM2(context); + final bool alwaysUse24HourFormat = MediaQuery.alwaysUse24HourFormatOf(context); + + final InputDecorationTheme inputDecorationTheme = timePickerTheme.inputDecorationTheme ?? defaultTheme.inputDecorationTheme; + InputDecoration inputDecoration = const InputDecoration().applyDefaults(inputDecorationTheme); + // Remove the hint text when focused because the centered cursor + // appears odd above the hint text. + final String? hintText = focusNode.hasFocus ? null : _formattedValue; + + // Because the fill color is specified in both the inputDecorationTheme and + // the TimePickerTheme, if there's one in the user's input decoration theme, + // use that. If not, but there's one in the user's + // timePickerTheme.hourMinuteColor, use that, and otherwise use the default. + // We ignore the value in the fillColor of the input decoration in the + // default theme here, but it's the same as the hourMinuteColor. + final Color startingFillColor = + timePickerTheme.inputDecorationTheme?.fillColor ?? + timePickerTheme.hourMinuteColor ?? + defaultTheme.hourMinuteColor; + final Color fillColor; + if (theme.useMaterial3) { + fillColor = MaterialStateProperty.resolveAs<Color>( + startingFillColor, + <MaterialState>{ + if (focusNode.hasFocus) MaterialState.focused, + if (focusNode.hasFocus) MaterialState.selected, + }, + ); + } else { + fillColor = focusNode.hasFocus ? Colors.transparent : startingFillColor; + } + + inputDecoration = inputDecoration.copyWith( + hintText: hintText, + fillColor: fillColor, + ); + + final Set<MaterialState> states = <MaterialState>{ + if (focusNode.hasFocus) MaterialState.focused, + if (focusNode.hasFocus) MaterialState.selected, + }; + final Color effectiveTextColor = MaterialStateProperty.resolveAs<Color>( + timePickerTheme.hourMinuteTextColor ?? defaultTheme.hourMinuteTextColor, + states, + ); + final TextStyle effectiveStyle = MaterialStateProperty.resolveAs<TextStyle>(widget.style, states) + .copyWith(color: effectiveTextColor); + + return SizedBox.fromSize( + size: alwaysUse24HourFormat ? defaultTheme.hourMinuteInputSize24Hour : defaultTheme.hourMinuteInputSize, + child: MediaQuery.withNoTextScaling( + child: UnmanagedRestorationScope( + bucket: bucket, + child: Semantics( + label: widget.semanticHintText, + child: TextFormField( + restorationId: 'hour_minute_text_form_field', + autofocus: widget.autofocus ?? false, + expands: true, + maxLines: null, + inputFormatters: <TextInputFormatter>[ + LengthLimitingTextInputFormatter(2), + ], + focusNode: focusNode, + textAlign: TextAlign.center, + textInputAction: widget.inputAction, + keyboardType: TextInputType.number, + style: effectiveStyle, + controller: controller.value, + decoration: inputDecoration, + validator: widget.validator, + onEditingComplete: () => widget.onSavedSubmitted(controller.value.text), + onSaved: widget.onSavedSubmitted, + onFieldSubmitted: widget.onSavedSubmitted, + onChanged: widget.onChanged, + ), + ), + ), + ), + ); + } +} + +/// Signature for when the time picker entry mode is changed. +typedef EntryModeChangeCallback = void Function(TimePickerEntryMode mode); + +/// A Material Design time picker designed to appear inside a popup dialog. +/// +/// Pass this widget to [showDialog]. The value returned by [showDialog] is the +/// selected [TimeOfDay] if the user taps the "OK" button, or null if the user +/// taps the "CANCEL" button. The selected time is reported by calling +/// [Navigator.pop]. +/// +/// Use [showTimePicker] to show a dialog already containing a [TimePickerDialog]. +class TimePickerDialog extends StatefulWidget { + /// Creates a Material Design time picker. + const TimePickerDialog({ + super.key, + required this.initialTime, + this.cancelText, + this.confirmText, + this.helpText, + this.errorInvalidText, + this.hourLabelText, + this.minuteLabelText, + this.restorationId, + this.initialEntryMode = TimePickerEntryMode.dial, + this.orientation, + this.onEntryModeChanged, + }); + + /// The time initially selected when the dialog is shown. + final TimeOfDay initialTime; + + /// Optionally provide your own text for the cancel button. + /// + /// If null, the button uses [MaterialLocalizations.cancelButtonLabel]. + final String? cancelText; + + /// Optionally provide your own text for the confirm button. + /// + /// If null, the button uses [MaterialLocalizations.okButtonLabel]. + final String? confirmText; + + /// Optionally provide your own help text to the header of the time picker. + final String? helpText; + + /// Optionally provide your own validation error text. + final String? errorInvalidText; + + /// Optionally provide your own hour label text. + final String? hourLabelText; + + /// Optionally provide your own minute label text. + final String? minuteLabelText; + + /// Restoration ID to save and restore the state of the [TimePickerDialog]. + /// + /// If it is non-null, the time picker will persist and restore the + /// dialog's state. + /// + /// The state of this widget is persisted in a [RestorationBucket] claimed + /// from the surrounding [RestorationScope] using the provided restoration ID. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + final String? restorationId; + + /// The entry mode for the picker. Whether it's text input or a dial. + final TimePickerEntryMode initialEntryMode; + + /// The optional [orientation] parameter sets the [Orientation] to use when + /// displaying the dialog. + /// + /// By default, the orientation is derived from the [MediaQueryData.size] of + /// the ambient [MediaQuery]. If the aspect of the size is tall, then + /// [Orientation.portrait] is used, if the size is wide, then + /// [Orientation.landscape] is used. + /// + /// Use this parameter to override the default and force the dialog to appear + /// in either portrait or landscape mode regardless of the aspect of the + /// [MediaQueryData.size]. + final Orientation? orientation; + + /// Callback called when the selected entry mode is changed. + final EntryModeChangeCallback? onEntryModeChanged; + + @override + State<TimePickerDialog> createState() => _TimePickerDialogState(); +} + +class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMixin { + late final RestorableEnum<TimePickerEntryMode> _entryMode = RestorableEnum<TimePickerEntryMode>(widget.initialEntryMode, values: TimePickerEntryMode.values); + late final RestorableTimeOfDay _selectedTime = RestorableTimeOfDay(widget.initialTime); + final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); + final RestorableEnum<AutovalidateMode> _autovalidateMode = RestorableEnum<AutovalidateMode>(AutovalidateMode.disabled, values: AutovalidateMode.values); + late final RestorableEnumN<Orientation> _orientation = RestorableEnumN<Orientation>(widget.orientation, values: Orientation.values); + + // Base sizes + static const Size _kTimePickerPortraitSize = Size(310, 468); + static const Size _kTimePickerLandscapeSize = Size(524, 342); + static const Size _kTimePickerLandscapeSizeM2 = Size(508, 300); + static const Size _kTimePickerInputSize = Size(312, 216); + + // Absolute minimum dialog sizes, which is the point at which it begins + // scrolling to fit everything in. + static const Size _kTimePickerMinPortraitSize = Size(238, 326); + static const Size _kTimePickerMinLandscapeSize = Size(416, 248); + static const Size _kTimePickerMinInputSize = Size(312, 196); + + @override + void dispose() { + _selectedTime.dispose(); + _entryMode.dispose(); + _autovalidateMode.dispose(); + _orientation.dispose(); + super.dispose(); + } + + @override + String? get restorationId => widget.restorationId; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_selectedTime, 'selected_time'); + registerForRestoration(_entryMode, 'entry_mode'); + registerForRestoration(_autovalidateMode, 'autovalidate_mode'); + registerForRestoration(_orientation, 'orientation'); + } + + void _handleTimeChanged(TimeOfDay value) { + if (value != _selectedTime.value) { + setState(() { + _selectedTime.value = value; + }); + } + } + + void _handleEntryModeChanged(TimePickerEntryMode value) { + if (value != _entryMode.value) { + setState(() { + switch (_entryMode.value) { + case TimePickerEntryMode.dial: + _autovalidateMode.value = AutovalidateMode.disabled; + case TimePickerEntryMode.input: + _formKey.currentState!.save(); + case TimePickerEntryMode.dialOnly: + break; + case TimePickerEntryMode.inputOnly: + break; + } + _entryMode.value = value; + widget.onEntryModeChanged?.call(value); + }); + } + } + + void _toggleEntryMode() { + switch (_entryMode.value) { + case TimePickerEntryMode.dial: + _handleEntryModeChanged(TimePickerEntryMode.input); + case TimePickerEntryMode.input: + _handleEntryModeChanged(TimePickerEntryMode.dial); + case TimePickerEntryMode.dialOnly: + case TimePickerEntryMode.inputOnly: + FlutterError('Can not change entry mode from $_entryMode'); + } + } + + void _handleCancel() { + Navigator.pop(context); + } + + void _handleOk() { + if (_entryMode.value == TimePickerEntryMode.input || _entryMode.value == TimePickerEntryMode.inputOnly) { + final FormState form = _formKey.currentState!; + if (!form.validate()) { + setState(() { + _autovalidateMode.value = AutovalidateMode.always; + }); + return; + } + form.save(); + } + Navigator.pop(context, _selectedTime.value); + } + + Size _minDialogSize(BuildContext context, {required bool useMaterial3}) { + final Orientation orientation = _orientation.value ?? MediaQuery.orientationOf(context); + + switch (_entryMode.value) { + case TimePickerEntryMode.dial: + case TimePickerEntryMode.dialOnly: + switch (orientation) { + case Orientation.portrait: + return _kTimePickerMinPortraitSize; + case Orientation.landscape: + return _kTimePickerMinLandscapeSize; + } + case TimePickerEntryMode.input: + case TimePickerEntryMode.inputOnly: + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final TimeOfDayFormat timeOfDayFormat = localizations.timeOfDayFormat(alwaysUse24HourFormat: MediaQuery.alwaysUse24HourFormatOf(context)); + final double timePickerWidth; + switch (timeOfDayFormat) { + case TimeOfDayFormat.HH_colon_mm: + case TimeOfDayFormat.HH_dot_mm: + case TimeOfDayFormat.frenchCanadian: + case TimeOfDayFormat.H_colon_mm: + final _TimePickerDefaults defaultTheme = useMaterial3 ? _TimePickerDefaultsM3(context) : _TimePickerDefaultsM2(context); + timePickerWidth = _kTimePickerMinInputSize.width - defaultTheme.dayPeriodPortraitSize.width - 12; + case TimeOfDayFormat.a_space_h_colon_mm: + case TimeOfDayFormat.h_colon_mm_space_a: + timePickerWidth = _kTimePickerMinInputSize.width - (useMaterial3 ? 32 : 0); + } + return Size(timePickerWidth, _kTimePickerMinInputSize.height); + } + } + + Size _dialogSize(BuildContext context, {required bool useMaterial3}) { + final Orientation orientation = _orientation.value ?? MediaQuery.orientationOf(context); + // Constrain the textScaleFactor to prevent layout issues. Since only some + // parts of the time picker scale up with textScaleFactor, we cap the factor + // to 1.1 as that provides enough space to reasonably fit all the content. + final double textScaleFactor = MediaQuery.textScalerOf(context).clamp(maxScaleFactor: 1.1).textScaleFactor; + + final Size timePickerSize; + switch (_entryMode.value) { + case TimePickerEntryMode.dial: + case TimePickerEntryMode.dialOnly: + switch (orientation) { + case Orientation.portrait: + timePickerSize = _kTimePickerPortraitSize; + case Orientation.landscape: + timePickerSize = Size( + _kTimePickerLandscapeSize.width * textScaleFactor, + useMaterial3 ? _kTimePickerLandscapeSize.height : _kTimePickerLandscapeSizeM2.height + ); + } + case TimePickerEntryMode.input: + case TimePickerEntryMode.inputOnly: + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final TimeOfDayFormat timeOfDayFormat = localizations.timeOfDayFormat(alwaysUse24HourFormat: MediaQuery.alwaysUse24HourFormatOf(context)); + final double timePickerWidth; + switch (timeOfDayFormat) { + case TimeOfDayFormat.HH_colon_mm: + case TimeOfDayFormat.HH_dot_mm: + case TimeOfDayFormat.frenchCanadian: + case TimeOfDayFormat.H_colon_mm: + final _TimePickerDefaults defaultTheme = useMaterial3 ? _TimePickerDefaultsM3(context) : _TimePickerDefaultsM2(context); + timePickerWidth = _kTimePickerInputSize.width - defaultTheme.dayPeriodPortraitSize.width - 12; + case TimeOfDayFormat.a_space_h_colon_mm: + case TimeOfDayFormat.h_colon_mm_space_a: + timePickerWidth = _kTimePickerInputSize.width - (useMaterial3 ? 32 : 0); + } + timePickerSize = Size(timePickerWidth, _kTimePickerInputSize.height); + } + return Size(timePickerSize.width, timePickerSize.height * textScaleFactor); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final ThemeData theme = Theme.of(context); + final TimePickerThemeData pickerTheme = TimePickerTheme.of(context); + final _TimePickerDefaults defaultTheme = theme.useMaterial3 ? _TimePickerDefaultsM3(context) : _TimePickerDefaultsM2(context); + final ShapeBorder shape = pickerTheme.shape ?? defaultTheme.shape; + final Color entryModeIconColor = pickerTheme.entryModeIconColor ?? defaultTheme.entryModeIconColor; + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + + final Widget actions = Padding( + padding: EdgeInsetsDirectional.only(start: theme.useMaterial3 ? 0 : 4), + child: Row( + children: <Widget>[ + if (_entryMode.value == TimePickerEntryMode.dial || _entryMode.value == TimePickerEntryMode.input) + IconButton( + // In material3 mode, we want to use the color as part of the + // button style which applies its own opacity. In material2 mode, + // we want to use the color as the color, which already includes + // the opacity. + color: theme.useMaterial3 ? null : entryModeIconColor, + style: theme.useMaterial3 ? IconButton.styleFrom(foregroundColor: entryModeIconColor) : null, + onPressed: _toggleEntryMode, + icon: Icon(_entryMode.value == TimePickerEntryMode.dial ? Icons.keyboard_outlined : Icons.access_time), + tooltip: _entryMode.value == TimePickerEntryMode.dial + ? MaterialLocalizations.of(context).inputTimeModeButtonLabel + : MaterialLocalizations.of(context).dialModeButtonLabel, + ), + Expanded( + child: Container( + alignment: AlignmentDirectional.centerEnd, + constraints: const BoxConstraints(minHeight: 36), + child: OverflowBar( + spacing: 8, + overflowAlignment: OverflowBarAlignment.end, + children: <Widget>[ + TextButton( + style: pickerTheme.cancelButtonStyle ?? defaultTheme.cancelButtonStyle, + onPressed: _handleCancel, + child: Text(widget.cancelText ?? + (theme.useMaterial3 + ? localizations.cancelButtonLabel + : localizations.cancelButtonLabel.toUpperCase())), + ), + TextButton( + style: pickerTheme.confirmButtonStyle ?? defaultTheme.confirmButtonStyle, + onPressed: _handleOk, + child: Text(widget.confirmText ?? localizations.okButtonLabel), + ), + ], + ), + ), + ), + ], + ), + ); + + final Offset tapTargetSizeOffset; + switch (theme.materialTapTargetSize) { + case MaterialTapTargetSize.padded: + tapTargetSizeOffset = Offset.zero; + case MaterialTapTargetSize.shrinkWrap: + // _dialogSize returns "padded" sizes. + tapTargetSizeOffset = const Offset(0, -12); + } + final Size dialogSize = _dialogSize(context, useMaterial3: theme.useMaterial3) + tapTargetSizeOffset; + final Size minDialogSize = _minDialogSize(context, useMaterial3: theme.useMaterial3) + tapTargetSizeOffset; + return Dialog( + shape: shape, + elevation: pickerTheme.elevation ?? defaultTheme.elevation, + backgroundColor: pickerTheme.backgroundColor ?? defaultTheme.backgroundColor, + insetPadding: EdgeInsets.symmetric( + horizontal: 16, + vertical: (_entryMode.value == TimePickerEntryMode.input || _entryMode.value == TimePickerEntryMode.inputOnly) ? 0 : 24, + ), + child: Padding( + padding: pickerTheme.padding ?? defaultTheme.padding, + child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) { + final Size constrainedSize = constraints.constrain(dialogSize); + final Size allowedSize = Size( + constrainedSize.width < minDialogSize.width ? minDialogSize.width : constrainedSize.width, + constrainedSize.height < minDialogSize.height ? minDialogSize.height : constrainedSize.height, + ); + return SingleChildScrollView( + restorationId: 'time_picker_scroll_view_horizontal', + scrollDirection: Axis.horizontal, + child: SingleChildScrollView( + restorationId: 'time_picker_scroll_view_vertical', + child: AnimatedContainer( + width: allowedSize.width, + height: allowedSize.height, + duration: _kDialogSizeAnimationDuration, + curve: Curves.easeIn, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Expanded( + child: Form( + key: _formKey, + autovalidateMode: _autovalidateMode.value, + child: _TimePicker( + time: widget.initialTime, + onTimeChanged: _handleTimeChanged, + helpText: widget.helpText, + cancelText: widget.cancelText, + confirmText: widget.confirmText, + errorInvalidText: widget.errorInvalidText, + hourLabelText: widget.hourLabelText, + minuteLabelText: widget.minuteLabelText, + restorationId: 'time_picker', + entryMode: _entryMode.value, + orientation: widget.orientation, + onEntryModeChanged: _handleEntryModeChanged, + ), + ), + ), + actions, + ], + ), + ), + ), + ); + }), + ), + ); + } +} + +// The _TimePicker widget is constructed so that in the future we could expose +// this as a public API for embedding time pickers into other non-dialog +// widgets, once we're sure we want to support that. + +/// A Time Picker widget that can be embedded into another widget. +class _TimePicker extends StatefulWidget { + /// Creates a const Material Design time picker. + const _TimePicker({ + required this.time, + required this.onTimeChanged, + this.helpText, + this.cancelText, + this.confirmText, + this.errorInvalidText, + this.hourLabelText, + this.minuteLabelText, + this.restorationId, + this.entryMode = TimePickerEntryMode.dial, + this.orientation, + this.onEntryModeChanged, + }); + + /// Optionally provide your own text for the help text at the top of the + /// control. + /// + /// If null, the widget uses [MaterialLocalizations.timePickerDialHelpText] + /// when the [entryMode] is [TimePickerEntryMode.dial], and + /// [MaterialLocalizations.timePickerInputHelpText] when the [entryMode] is + /// [TimePickerEntryMode.input]. + final String? helpText; + + /// Optionally provide your own text for the cancel button. + /// + /// If null, the button uses [MaterialLocalizations.cancelButtonLabel]. + final String? cancelText; + + /// Optionally provide your own text for the confirm button. + /// + /// If null, the button uses [MaterialLocalizations.okButtonLabel]. + final String? confirmText; + + /// Optionally provide your own validation error text. + final String? errorInvalidText; + + /// Optionally provide your own hour label text. + final String? hourLabelText; + + /// Optionally provide your own minute label text. + final String? minuteLabelText; + + /// Restoration ID to save and restore the state of the [TimePickerDialog]. + /// + /// If it is non-null, the time picker will persist and restore the + /// dialog's state. + /// + /// The state of this widget is persisted in a [RestorationBucket] claimed + /// from the surrounding [RestorationScope] using the provided restoration ID. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + final String? restorationId; + + /// The initial entry mode for the picker. Whether it's text input or a dial. + final TimePickerEntryMode entryMode; + + /// The currently selected time of day. + final TimeOfDay time; + + final ValueChanged<TimeOfDay>? onTimeChanged; + + /// The optional [orientation] parameter sets the [Orientation] to use when + /// displaying the dialog. + /// + /// By default, the orientation is derived from the [MediaQueryData.size] of + /// the ambient [MediaQuery]. If the aspect of the size is tall, then + /// [Orientation.portrait] is used, if the size is wide, then + /// [Orientation.landscape] is used. + /// + /// Use this parameter to override the default and force the dialog to appear + /// in either portrait or landscape mode regardless of the aspect of the + /// [MediaQueryData.size]. + final Orientation? orientation; + + /// Callback called when the selected entry mode is changed. + final EntryModeChangeCallback? onEntryModeChanged; + + @override + State<_TimePicker> createState() => _TimePickerState(); +} + +class _TimePickerState extends State<_TimePicker> with RestorationMixin { + Timer? _vibrateTimer; + late MaterialLocalizations localizations; + final RestorableEnum<_HourMinuteMode> _hourMinuteMode = + RestorableEnum<_HourMinuteMode>(_HourMinuteMode.hour, values: _HourMinuteMode.values); + final RestorableEnumN<_HourMinuteMode> _lastModeAnnounced = + RestorableEnumN<_HourMinuteMode>(null, values: _HourMinuteMode.values); + final RestorableBoolN _autofocusHour = RestorableBoolN(null); + final RestorableBoolN _autofocusMinute = RestorableBoolN(null); + final RestorableBool _announcedInitialTime = RestorableBool(false); + late final RestorableEnumN<Orientation> _orientation = + RestorableEnumN<Orientation>(widget.orientation, values: Orientation.values); + RestorableTimeOfDay get selectedTime => _selectedTime; + late final RestorableTimeOfDay _selectedTime = RestorableTimeOfDay(widget.time); + + @override + void dispose() { + _vibrateTimer?.cancel(); + _vibrateTimer = null; + _orientation.dispose(); + _selectedTime.dispose(); + _hourMinuteMode.dispose(); + _lastModeAnnounced.dispose(); + _autofocusHour.dispose(); + _autofocusMinute.dispose(); + _announcedInitialTime.dispose(); + super.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + localizations = MaterialLocalizations.of(context); + _announceInitialTimeOnce(); + _announceModeOnce(); + } + + @override + void didUpdateWidget (_TimePicker oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.orientation != widget.orientation) { + _orientation.value = widget.orientation; + } + if (oldWidget.time != widget.time) { + _selectedTime.value = widget.time; + } + } + + void _setEntryMode(TimePickerEntryMode mode){ + widget.onEntryModeChanged?.call(mode); + } + + @override + String? get restorationId => widget.restorationId; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_hourMinuteMode, 'hour_minute_mode'); + registerForRestoration(_lastModeAnnounced, 'last_mode_announced'); + registerForRestoration(_autofocusHour, 'autofocus_hour'); + registerForRestoration(_autofocusMinute, 'autofocus_minute'); + registerForRestoration(_announcedInitialTime, 'announced_initial_time'); + registerForRestoration(_selectedTime, 'selected_time'); + registerForRestoration(_orientation, 'orientation'); + } + + void _vibrate() { + switch (Theme.of(context).platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + _vibrateTimer?.cancel(); + _vibrateTimer = Timer(_kVibrateCommitDelay, () { + HapticFeedback.vibrate(); + _vibrateTimer = null; + }); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + break; + } + } + + void _handleHourMinuteModeChanged(_HourMinuteMode mode) { + _vibrate(); + setState(() { + _hourMinuteMode.value = mode; + _announceModeOnce(); + }); + } + + void _handleEntryModeToggle() { + setState(() { + TimePickerEntryMode newMode = widget.entryMode; + switch (widget.entryMode) { + case TimePickerEntryMode.dial: + newMode = TimePickerEntryMode.input; + case TimePickerEntryMode.input: + _autofocusHour.value = false; + _autofocusMinute.value = false; + newMode = TimePickerEntryMode.dial; + case TimePickerEntryMode.dialOnly: + case TimePickerEntryMode.inputOnly: + FlutterError('Can not change entry mode from ${widget.entryMode}'); + } + _setEntryMode(newMode); + }); + } + + void _announceModeOnce() { + if (_lastModeAnnounced.value == _hourMinuteMode.value) { + // Already announced it. + return; + } + + switch (_hourMinuteMode.value) { + case _HourMinuteMode.hour: + _announceToAccessibility(context, localizations.timePickerHourModeAnnouncement); + case _HourMinuteMode.minute: + _announceToAccessibility(context, localizations.timePickerMinuteModeAnnouncement); + } + _lastModeAnnounced.value = _hourMinuteMode.value; + } + + void _announceInitialTimeOnce() { + if (_announcedInitialTime.value) { + return; + } + + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + _announceToAccessibility( + context, + localizations.formatTimeOfDay(_selectedTime.value, alwaysUse24HourFormat: MediaQuery.alwaysUse24HourFormatOf(context)), + ); + _announcedInitialTime.value = true; + } + + void _handleTimeChanged(TimeOfDay value) { + _vibrate(); + setState(() { + _selectedTime.value = value; + widget.onTimeChanged?.call(value); + }); + } + + void _handleHourDoubleTapped() { + _autofocusHour.value = true; + _handleEntryModeToggle(); + } + + void _handleMinuteDoubleTapped() { + _autofocusMinute.value = true; + _handleEntryModeToggle(); + } + + void _handleHourSelected() { + setState(() { + _hourMinuteMode.value = _HourMinuteMode.minute; + }); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final TimeOfDayFormat timeOfDayFormat = localizations.timeOfDayFormat(alwaysUse24HourFormat: MediaQuery.alwaysUse24HourFormatOf(context)); + final ThemeData theme = Theme.of(context); + final _TimePickerDefaults defaultTheme = theme.useMaterial3 ? _TimePickerDefaultsM3(context) : _TimePickerDefaultsM2(context); + final Orientation orientation = _orientation.value ?? MediaQuery.orientationOf(context); + final HourFormat timeOfDayHour = hourFormat(of: timeOfDayFormat); + final _HourDialType hourMode; + switch (timeOfDayHour) { + case HourFormat.HH: + case HourFormat.H: + hourMode = theme.useMaterial3 ? _HourDialType.twentyFourHourDoubleRing : _HourDialType.twentyFourHour; + case HourFormat.h: + hourMode = _HourDialType.twelveHour; + } + + final String helpText; + final Widget picker; + switch (widget.entryMode) { + case TimePickerEntryMode.dial: + case TimePickerEntryMode.dialOnly: + helpText = widget.helpText ?? (theme.useMaterial3 + ? localizations.timePickerDialHelpText + : localizations.timePickerDialHelpText.toUpperCase()); + + final EdgeInsetsGeometry dialPadding; + switch (orientation) { + case Orientation.portrait: + dialPadding = const EdgeInsets.only(left: 12, right: 12, top: 36); + case Orientation.landscape: + switch (theme.materialTapTargetSize) { + case MaterialTapTargetSize.padded: + dialPadding = const EdgeInsetsDirectional.only(start: 64); + case MaterialTapTargetSize.shrinkWrap: + dialPadding = const EdgeInsetsDirectional.only(start: 64); + } + } + final Widget dial = Padding( + padding: dialPadding, + child: ExcludeSemantics( + child: SizedBox.fromSize( + size: defaultTheme.dialSize, + child: AspectRatio( + aspectRatio: 1, + child: _Dial( + hourMinuteMode: _hourMinuteMode.value, + hourDialType: hourMode, + selectedTime: _selectedTime.value, + onChanged: _handleTimeChanged, + onHourSelected: _handleHourSelected, + ), + ), + ), + ), + ); + + switch (orientation) { + case Orientation.portrait: + picker = Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + Padding( + padding: EdgeInsets.symmetric(horizontal: theme.useMaterial3 ? 0 : 16), + child: _TimePickerHeader(helpText: helpText), + ), + Expanded( + child: Column( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + // Dial grows and shrinks with the available space. + Expanded( + child: Padding( + padding: EdgeInsets.symmetric(horizontal: theme.useMaterial3 ? 0 : 16), + child: dial, + ), + ), + ], + ), + ), + ], + ); + case Orientation.landscape: + picker = Column( + children: <Widget>[ + Expanded( + child: Padding( + padding: EdgeInsets.symmetric(horizontal: theme.useMaterial3 ? 0 : 16), + child: Row( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + _TimePickerHeader(helpText: helpText), + Expanded(child: dial), + ], + ), + ), + ), + ], + ); + } + case TimePickerEntryMode.input: + case TimePickerEntryMode.inputOnly: + final String helpText = widget.helpText ?? (theme.useMaterial3 + ? localizations.timePickerInputHelpText + : localizations.timePickerInputHelpText.toUpperCase()); + + picker = Column( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + _TimePickerInput( + initialSelectedTime: _selectedTime.value, + errorInvalidText: widget.errorInvalidText, + hourLabelText: widget.hourLabelText, + minuteLabelText: widget.minuteLabelText, + helpText: helpText, + autofocusHour: _autofocusHour.value, + autofocusMinute: _autofocusMinute.value, + restorationId: 'time_picker_input', + ), + ], + ); + } + return _TimePickerModel( + entryMode: widget.entryMode, + selectedTime: _selectedTime.value, + hourMinuteMode: _hourMinuteMode.value, + orientation: orientation, + onHourMinuteModeChanged: _handleHourMinuteModeChanged, + onHourDoubleTapped: _handleHourDoubleTapped, + onMinuteDoubleTapped: _handleMinuteDoubleTapped, + hourDialType: hourMode, + onSelectedTimeChanged: _handleTimeChanged, + useMaterial3: theme.useMaterial3, + use24HourFormat: MediaQuery.alwaysUse24HourFormatOf(context), + theme: TimePickerTheme.of(context), + defaultTheme: defaultTheme, + child: picker, + ); + } +} + +/// Shows a dialog containing a Material Design time picker. +/// +/// The returned Future resolves to the time selected by the user when the user +/// closes the dialog. If the user cancels the dialog, null is returned. +/// +/// {@tool snippet} Show a dialog with [initialTime] equal to the current time. +/// +/// ```dart +/// Future<TimeOfDay?> selectedTime = showTimePicker( +/// initialTime: TimeOfDay.now(), +/// context: context, +/// ); +/// ``` +/// {@end-tool} +/// +/// The [context], [barrierDismissible], [barrierColor], [barrierLabel], +/// [useRootNavigator] and [routeSettings] arguments are passed to [showDialog], +/// the documentation for which discusses how it is used. +/// +/// The [builder] parameter can be used to wrap the dialog widget to add +/// inherited widgets like [Localizations.override], [Directionality], or +/// [MediaQuery]. +/// +/// The `initialEntryMode` parameter can be used to determine the initial time +/// entry selection of the picker (either a clock dial or text input). +/// +/// Optional strings for the [helpText], [cancelText], [errorInvalidText], +/// [hourLabelText], [minuteLabelText] and [confirmText] can be provided to +/// override the default values. +/// +/// The optional [orientation] parameter sets the [Orientation] to use when +/// displaying the dialog. By default, the orientation is derived from the +/// [MediaQueryData.size] of the ambient [MediaQuery]: wide sizes use the +/// landscape orientation, and tall sizes use the portrait orientation. Use this +/// parameter to override the default and force the dialog to appear in either +/// portrait or landscape mode. +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// By default, the time picker gets its colors from the overall theme's +/// [ColorScheme]. The time picker can be further customized by providing a +/// [TimePickerThemeData] to the overall theme. +/// +/// {@tool snippet} Show a dialog with the text direction overridden to be +/// [TextDirection.rtl]. +/// +/// ```dart +/// Future<TimeOfDay?> selectedTimeRTL = showTimePicker( +/// context: context, +/// initialTime: TimeOfDay.now(), +/// builder: (BuildContext context, Widget? child) { +/// return Directionality( +/// textDirection: TextDirection.rtl, +/// child: child!, +/// ); +/// }, +/// ); +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} Show a dialog with time unconditionally displayed in 24 hour +/// format. +/// +/// ```dart +/// Future<TimeOfDay?> selectedTime24Hour = showTimePicker( +/// context: context, +/// initialTime: const TimeOfDay(hour: 10, minute: 47), +/// builder: (BuildContext context, Widget? child) { +/// return MediaQuery( +/// data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true), +/// child: child!, +/// ); +/// }, +/// ); +/// ``` +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example illustrates how to open a time picker, and allows exploring +/// some of the variations in the types of time pickers that may be shown. +/// +/// ** See code in examples/api/lib/material/time_picker/show_time_picker.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [showDatePicker], which shows a dialog that contains a Material Design +/// date picker. +/// * [TimePickerThemeData], which allows you to customize the colors, +/// typography, and shape of the time picker. +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +Future<TimeOfDay?> showTimePicker({ + required BuildContext context, + required TimeOfDay initialTime, + TransitionBuilder? builder, + bool barrierDismissible = true, + Color? barrierColor, + String? barrierLabel, + bool useRootNavigator = true, + TimePickerEntryMode initialEntryMode = TimePickerEntryMode.dial, + String? cancelText, + String? confirmText, + String? helpText, + String? errorInvalidText, + String? hourLabelText, + String? minuteLabelText, + RouteSettings? routeSettings, + EntryModeChangeCallback? onEntryModeChanged, + Offset? anchorPoint, + Orientation? orientation, +}) async { + assert(debugCheckHasMaterialLocalizations(context)); + + final Widget dialog = TimePickerDialog( + initialTime: initialTime, + initialEntryMode: initialEntryMode, + cancelText: cancelText, + confirmText: confirmText, + helpText: helpText, + errorInvalidText: errorInvalidText, + hourLabelText: hourLabelText, + minuteLabelText: minuteLabelText, + orientation: orientation, + onEntryModeChanged: onEntryModeChanged, + ); + return showDialog<TimeOfDay>( + context: context, + barrierDismissible: barrierDismissible, + barrierColor: barrierColor, + barrierLabel: barrierLabel, + useRootNavigator: useRootNavigator, + builder: (BuildContext context) { + return builder == null ? dialog : builder(context, dialog); + }, + routeSettings: routeSettings, + anchorPoint: anchorPoint, + ); +} + +void _announceToAccessibility(BuildContext context, String message) { + SemanticsService.announce(message, Directionality.of(context)); +} + +// An abstract base class for the M2 and M3 defaults below, so that their return +// types can be non-nullable. +abstract class _TimePickerDefaults extends TimePickerThemeData { + @override + Color get backgroundColor; + + @override + ButtonStyle get cancelButtonStyle; + + @override + ButtonStyle get confirmButtonStyle; + + @override + BorderSide get dayPeriodBorderSide; + + @override + Color get dayPeriodColor; + + @override + OutlinedBorder get dayPeriodShape; + + Size get dayPeriodInputSize; + Size get dayPeriodLandscapeSize; + Size get dayPeriodPortraitSize; + + @override + Color get dayPeriodTextColor; + + @override + TextStyle get dayPeriodTextStyle; + + @override + Color get dialBackgroundColor; + + @override + Color get dialHandColor; + + // Sizes that are generated from the tokens, but these aren't ones we're ready + // to expose in the theme. + Size get dialSize; + double get handWidth; + double get dotRadius; + double get centerRadius; + + @override + Color get dialTextColor; + + @override + TextStyle get dialTextStyle; + + @override + double get elevation; + + @override + Color get entryModeIconColor; + + @override + TextStyle get helpTextStyle; + + @override + Color get hourMinuteColor; + + @override + ShapeBorder get hourMinuteShape; + + Size get hourMinuteSize; + Size get hourMinuteSize24Hour; + Size get hourMinuteInputSize; + Size get hourMinuteInputSize24Hour; + + @override + Color get hourMinuteTextColor; + + @override + TextStyle get hourMinuteTextStyle; + + @override + InputDecorationTheme get inputDecorationTheme; + + @override + EdgeInsetsGeometry get padding; + + @override + ShapeBorder get shape; +} + +// These theme defaults are not auto-generated: they match the values for the +// Material 2 spec, which are not expected to change. +class _TimePickerDefaultsM2 extends _TimePickerDefaults { + _TimePickerDefaultsM2(this.context) : super(); + + final BuildContext context; + + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + static const OutlinedBorder _kDefaultShape = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))); + + @override + Color get backgroundColor { + return _colors.surface; + } + + @override + ButtonStyle get cancelButtonStyle { + return TextButton.styleFrom(); + } + + @override + ButtonStyle get confirmButtonStyle { + return TextButton.styleFrom(); + } + + @override + BorderSide get dayPeriodBorderSide { + return BorderSide( + color: Color.alphaBlend(_colors.onSurface.withOpacity(0.38), _colors.surface), + ); + } + + @override + Color get dayPeriodColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.primary.withOpacity(_colors.brightness == Brightness.dark ? 0.24 : 0.12); + } + // The unselected day period should match the overall picker dialog color. + // Making it transparent enables that without being redundant and allows + // the optional elevation overlay for dark mode to be visible. + return Colors.transparent; + }); + } + + @override + OutlinedBorder get dayPeriodShape { + return _kDefaultShape; + } + + @override + Size get dayPeriodPortraitSize { + return const Size(52, 80); + } + + @override + Size get dayPeriodLandscapeSize { + return const Size(0, 40); + } + + @override + Size get dayPeriodInputSize { + return const Size(52, 70); + } + + @override + Color get dayPeriodTextColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + return states.contains(MaterialState.selected) ? _colors.primary : _colors.onSurface.withOpacity(0.60); + }); + } + + @override + TextStyle get dayPeriodTextStyle { + return _textTheme.titleMedium!.copyWith(color: dayPeriodTextColor); + } + + @override + Color get dialBackgroundColor { + return _colors.onSurface.withOpacity(_colors.brightness == Brightness.dark ? 0.12 : 0.08); + } + + @override + Color get dialHandColor { + return _colors.primary; + } + + @override + Size get dialSize { + return const Size.square(280); + } + + @override + double get handWidth { + return 2; + } + + @override + double get dotRadius { + return 22; + } + + @override + double get centerRadius { + return 4; + } + + @override + Color get dialTextColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.surface; + } + return _colors.onSurface; + }); + } + + @override + TextStyle get dialTextStyle { + return _textTheme.bodyLarge!; + } + + @override + double get elevation { + return 6; + } + + @override + Color get entryModeIconColor { + return _colors.onSurface.withOpacity(_colors.brightness == Brightness.dark ? 1.0 : 0.6); + } + + @override + TextStyle get helpTextStyle { + return _textTheme.labelSmall!; + } + + @override + Color get hourMinuteColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + return states.contains(MaterialState.selected) + ? _colors.primary.withOpacity(_colors.brightness == Brightness.dark ? 0.24 : 0.12) + : _colors.onSurface.withOpacity(0.12); + }); + } + + @override + ShapeBorder get hourMinuteShape { + return _kDefaultShape; + } + + @override + Size get hourMinuteSize { + return const Size(96, 80); + } + + @override + Size get hourMinuteSize24Hour { + return const Size(114, 80); + } + + @override + Size get hourMinuteInputSize { + return const Size(96, 70); + } + + @override + Size get hourMinuteInputSize24Hour { + return const Size(114, 70); + } + + @override + Color get hourMinuteTextColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + return states.contains(MaterialState.selected) ? _colors.primary : _colors.onSurface; + }); + } + + @override + TextStyle get hourMinuteTextStyle { + return _textTheme.displayMedium!; + } + + Color get _hourMinuteInputColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + return states.contains(MaterialState.selected) + ? Colors.transparent + : _colors.onSurface.withOpacity(0.12); + }); + } + + @override + InputDecorationTheme get inputDecorationTheme { + return InputDecorationTheme( + contentPadding: EdgeInsets.zero, + filled: true, + fillColor: _hourMinuteInputColor, + focusColor: Colors.transparent, + enabledBorder: const OutlineInputBorder( + borderSide: BorderSide(color: Colors.transparent), + ), + errorBorder: OutlineInputBorder( + borderSide: BorderSide(color: _colors.error, width: 2), + ), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide(color: _colors.primary, width: 2), + ), + focusedErrorBorder: OutlineInputBorder( + borderSide: BorderSide(color: _colors.error, width: 2), + ), + hintStyle: hourMinuteTextStyle.copyWith(color: _colors.onSurface.withOpacity(0.36)), + // Prevent the error text from appearing. + // TODO(rami-a): Remove this workaround once + // https://github.com/flutter/flutter/issues/54104 + // is fixed. + errorStyle: const TextStyle(fontSize: 0, height: 0), + ); + } + + @override + EdgeInsetsGeometry get padding { + return const EdgeInsets.fromLTRB(8, 18, 8, 8); + } + + @override + ShapeBorder get shape { + return _kDefaultShape; + } +} + +// BEGIN GENERATED TOKEN PROPERTIES - TimePicker + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _TimePickerDefaultsM3 extends _TimePickerDefaults { + _TimePickerDefaultsM3(this.context); + + final BuildContext context; + + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + @override + Color get backgroundColor { + return _colors.surface; + } + + @override + ButtonStyle get cancelButtonStyle { + return TextButton.styleFrom(); + } + + @override + ButtonStyle get confirmButtonStyle { + return TextButton.styleFrom(); + } + + @override + BorderSide get dayPeriodBorderSide { + return BorderSide(color: _colors.outline); + } + + @override + Color get dayPeriodColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.tertiaryContainer; + } + // The unselected day period should match the overall picker dialog color. + // Making it transparent enables that without being redundant and allows + // the optional elevation overlay for dark mode to be visible. + return Colors.transparent; + }); + } + + @override + OutlinedBorder get dayPeriodShape { + return const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))).copyWith(side: dayPeriodBorderSide); + } + + @override + Size get dayPeriodPortraitSize { + return const Size(52, 80); + } + + @override + Size get dayPeriodLandscapeSize { + return const Size(216, 38); + } + + @override + Size get dayPeriodInputSize { + // Input size is eight pixels smaller than the portrait size in the spec, + // but there's not token for it yet. + return Size(dayPeriodPortraitSize.width, dayPeriodPortraitSize.height - 8); + } + + @override + Color get dayPeriodTextColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.focused)) { + return _colors.onTertiaryContainer; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onTertiaryContainer; + } + if (states.contains(MaterialState.pressed)) { + return _colors.onTertiaryContainer; + } + return _colors.onTertiaryContainer; + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurfaceVariant; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurfaceVariant; + } + if (states.contains(MaterialState.pressed)) { + return _colors.onSurfaceVariant; + } + return _colors.onSurfaceVariant; + }); + } + + @override + TextStyle get dayPeriodTextStyle { + return _textTheme.titleMedium!.copyWith(color: dayPeriodTextColor); + } + + @override + Color get dialBackgroundColor { + return _colors.surfaceVariant; + } + + @override + Color get dialHandColor { + return _colors.primary; + } + + @override + Size get dialSize { + return const Size.square(256.0); + } + + @override + double get handWidth { + return const Size(2, double.infinity).width; + } + + @override + double get dotRadius { + return const Size.square(48.0).width / 2; + } + + @override + double get centerRadius { + return const Size.square(8.0).width / 2; + } + + @override + Color get dialTextColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _colors.onPrimary; + } + return _colors.onSurface; + }); + } + + @override + TextStyle get dialTextStyle { + return _textTheme.bodyLarge!; + } + + @override + double get elevation { + return 6.0; + } + + @override + Color get entryModeIconColor { + return _colors.onSurface; + } + + @override + TextStyle get helpTextStyle { + return MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + final TextStyle textStyle = _textTheme.labelMedium!; + return textStyle.copyWith(color: _colors.onSurfaceVariant); + }); + } + + @override + EdgeInsetsGeometry get padding { + return const EdgeInsets.all(24); + } + + @override + Color get hourMinuteColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + Color overlayColor = _colors.primaryContainer; + if (states.contains(MaterialState.pressed)) { + overlayColor = _colors.onPrimaryContainer; + } else if (states.contains(MaterialState.hovered)) { + const double hoverOpacity = 0.08; + overlayColor = _colors.onPrimaryContainer.withOpacity(hoverOpacity); + } else if (states.contains(MaterialState.focused)) { + const double focusOpacity = 0.12; + overlayColor = _colors.onPrimaryContainer.withOpacity(focusOpacity); + } + return Color.alphaBlend(overlayColor, _colors.primaryContainer); + } else { + Color overlayColor = _colors.surfaceVariant; + if (states.contains(MaterialState.pressed)) { + overlayColor = _colors.onSurface; + } else if (states.contains(MaterialState.hovered)) { + const double hoverOpacity = 0.08; + overlayColor = _colors.onSurface.withOpacity(hoverOpacity); + } else if (states.contains(MaterialState.focused)) { + const double focusOpacity = 0.12; + overlayColor = _colors.onSurface.withOpacity(focusOpacity); + } + return Color.alphaBlend(overlayColor, _colors.surfaceVariant); + } + }); + } + + @override + ShapeBorder get hourMinuteShape { + return const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))); + } + + @override + Size get hourMinuteSize { + return const Size(96, 80); + } + + @override + Size get hourMinuteSize24Hour { + return Size(const Size(114, double.infinity).width, hourMinuteSize.height); + } + + @override + Size get hourMinuteInputSize { + // Input size is eight pixels smaller than the regular size in the spec, but + // there's not token for it yet. + return Size(hourMinuteSize.width, hourMinuteSize.height - 8); + } + + @override + Size get hourMinuteInputSize24Hour { + // Input size is eight pixels smaller than the regular size in the spec, but + // there's not token for it yet. + return Size(hourMinuteSize24Hour.width, hourMinuteSize24Hour.height - 8); + } + + @override + Color get hourMinuteTextColor { + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + return _hourMinuteTextColor.resolve(states); + }); + } + + MaterialStateProperty<Color> get _hourMinuteTextColor { + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + if (states.contains(MaterialState.pressed)) { + return _colors.onPrimaryContainer; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onPrimaryContainer; + } + if (states.contains(MaterialState.focused)) { + return _colors.onPrimaryContainer; + } + return _colors.onPrimaryContainer; + } else { + // unselected + if (states.contains(MaterialState.pressed)) { + return _colors.onSurface; + } + if (states.contains(MaterialState.hovered)) { + return _colors.onSurface; + } + if (states.contains(MaterialState.focused)) { + return _colors.onSurface; + } + return _colors.onSurface; + } + }); + } + + @override + TextStyle get hourMinuteTextStyle { + return MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { + // TODO(tahatesser): Update this when https://github.com/flutter/flutter/issues/131247 is fixed. + // This is using the correct text style from Material 3 spec. + // https://m3.material.io/components/time-pickers/specs#fd0b6939-edab-4058-82e1-93d163945215 + return _textTheme.displayMedium!.copyWith(color: _hourMinuteTextColor.resolve(states)); + }); + } + + @override + InputDecorationTheme get inputDecorationTheme { + // This is NOT correct, but there's no token for + // 'time-input.container.shape', so this is using the radius from the shape + // for the hour/minute selector. It's a BorderRadiusGeometry, so we have to + // resolve it before we can use it. + final BorderRadius selectorRadius = const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))) + .borderRadius + .resolve(Directionality.of(context)); + return InputDecorationTheme( + contentPadding: EdgeInsets.zero, + filled: true, + // This should be derived from a token, but there isn't one for 'time-input'. + fillColor: hourMinuteColor, + // This should be derived from a token, but there isn't one for 'time-input'. + focusColor: _colors.primaryContainer, + enabledBorder: OutlineInputBorder( + borderRadius: selectorRadius, + borderSide: const BorderSide(color: Colors.transparent), + ), + errorBorder: OutlineInputBorder( + borderRadius: selectorRadius, + borderSide: BorderSide(color: _colors.error, width: 2), + ), + focusedBorder: OutlineInputBorder( + borderRadius: selectorRadius, + borderSide: BorderSide(color: _colors.primary, width: 2), + ), + focusedErrorBorder: OutlineInputBorder( + borderRadius: selectorRadius, + borderSide: BorderSide(color: _colors.error, width: 2), + ), + hintStyle: hourMinuteTextStyle.copyWith(color: _colors.onSurface.withOpacity(0.36)), + // Prevent the error text from appearing. + // TODO(rami-a): Remove this workaround once + // https://github.com/flutter/flutter/issues/54104 + // is fixed. + errorStyle: const TextStyle(fontSize: 0, height: 0), + ); + } + + @override + ShapeBorder get shape { + return const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0))); + } +} + +// END GENERATED TOKEN PROPERTIES - TimePicker diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/time_picker_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/time_picker_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..aa6a3e20fcc9413936c2d7387452adb3b767409d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/time_picker_theme.dart @@ -0,0 +1,487 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'colors.dart'; +import 'input_decorator.dart'; +import 'material_state.dart'; +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines the visual properties of the widget displayed with [showTimePicker]. +/// +/// Descendant widgets obtain the current [TimePickerThemeData] object using +/// `TimePickerTheme.of(context)`. Instances of [TimePickerThemeData] +/// can be customized with [TimePickerThemeData.copyWith]. +/// +/// Typically a [TimePickerThemeData] is specified as part of the overall +/// [Theme] with [ThemeData.timePickerTheme]. +/// +/// All [TimePickerThemeData] properties are `null` by default. When null, +/// [showTimePicker] will provide its own defaults. +/// +/// See also: +/// +/// * [ThemeData], which describes the overall theme information for the +/// application. +/// * [TimePickerTheme], which describes the actual configuration of a time +/// picker theme. +@immutable +class TimePickerThemeData with Diagnosticable { + + /// Creates a theme that can be used for [TimePickerTheme] or + /// [ThemeData.timePickerTheme]. + const TimePickerThemeData({ + this.backgroundColor, + this.cancelButtonStyle, + this.confirmButtonStyle, + this.dayPeriodBorderSide, + Color? dayPeriodColor, + this.dayPeriodShape, + this.dayPeriodTextColor, + this.dayPeriodTextStyle, + this.dialBackgroundColor, + this.dialHandColor, + this.dialTextColor, + this.dialTextStyle, + this.elevation, + this.entryModeIconColor, + this.helpTextStyle, + this.hourMinuteColor, + this.hourMinuteShape, + this.hourMinuteTextColor, + this.hourMinuteTextStyle, + this.inputDecorationTheme, + this.padding, + this.shape, + }) : _dayPeriodColor = dayPeriodColor; + + /// The background color of a time picker. + /// + /// If this is null, the time picker defaults to the overall theme's + /// [ColorScheme.background]. + final Color? backgroundColor; + + /// The style of the cancel button of a [TimePickerDialog]. + final ButtonStyle? cancelButtonStyle; + + /// The style of the confirm (OK) button of a [TimePickerDialog]. + final ButtonStyle? confirmButtonStyle; + + /// The color and weight of the day period's outline. + /// + /// If this is null, the time picker defaults to: + /// + /// ```dart + /// BorderSide( + /// color: Color.alphaBlend( + /// Theme.of(context).colorScheme.onBackground.withOpacity(0.38), + /// Theme.of(context).colorScheme.surface, + /// ), + /// ), + /// ``` + final BorderSide? dayPeriodBorderSide; + + /// The background color of the AM/PM toggle. + /// + /// If [dayPeriodColor] is a [MaterialStateColor], then the effective + /// background color can depend on the [MaterialState.selected] state, i.e. + /// if the segment is selected or not. + /// + /// By default, if the segment is selected, the overall theme's + /// `ColorScheme.primary.withOpacity(0.12)` is used when the overall theme's + /// brightness is [Brightness.light] and + /// `ColorScheme.primary.withOpacity(0.24)` is used when the overall theme's + /// brightness is [Brightness.dark]. + /// If the segment is not selected, [Colors.transparent] is used to allow the + /// [Dialog]'s color to be used. + Color? get dayPeriodColor { + if (_dayPeriodColor == null || _dayPeriodColor is MaterialStateColor) { + return _dayPeriodColor; + } + return MaterialStateColor.resolveWith((Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return _dayPeriodColor; + } + // The unselected day period should match the overall picker dialog color. + // Making it transparent enables that without being redundant and allows + // the optional elevation overlay for dark mode to be visible. + return Colors.transparent; + }); + } + final Color? _dayPeriodColor; + + /// The shape of the day period that the time picker uses. + /// + /// If this is null, the time picker defaults to: + /// + /// ```dart + /// const RoundedRectangleBorder( + /// borderRadius: BorderRadius.all(Radius.circular(4.0)), + /// side: BorderSide(), + /// ) + /// ``` + final OutlinedBorder? dayPeriodShape; + + /// The color of the day period text that represents AM/PM. + /// + /// If [dayPeriodTextColor] is a [MaterialStateColor], then the effective + /// text color can depend on the [MaterialState.selected] state, i.e. if the + /// text is selected or not. + /// + /// By default the overall theme's [ColorScheme.primary] color is used when + /// the text is selected and `ColorScheme.onSurface.withOpacity(0.60)` when + /// it's not selected. + final Color? dayPeriodTextColor; + + /// Used to configure the [TextStyle]s for the day period control. + /// + /// If this is null, the time picker defaults to the overall theme's + /// [TextTheme.titleMedium]. + final TextStyle? dayPeriodTextStyle; + + /// The background color of the time picker dial when the entry mode is + /// [TimePickerEntryMode.dial] or [TimePickerEntryMode.dialOnly]. + /// + /// If this is null and [ThemeData.useMaterial3] is true, the time picker + /// dial background color defaults [ColorScheme.surfaceVariant] color. + /// + /// If this is null and [ThemeData.useMaterial3] is false, the time picker + /// dial background color defaults to [ColorScheme.onSurface] color with + /// an opacity of 0.08 when the overall theme's brightness is [Brightness.light] + /// and [ColorScheme.onSurface] color with an opacity of 0.12 when the overall + /// theme's brightness is [Brightness.dark]. + final Color? dialBackgroundColor; + + /// The color of the time picker dial's hand when the entry mode is + /// [TimePickerEntryMode.dial] or [TimePickerEntryMode.dialOnly]. + /// + /// If this is null, the time picker defaults to the overall theme's + /// [ColorScheme.primary]. + final Color? dialHandColor; + + /// The color of the dial text that represents specific hours and minutes. + /// + /// If [dialTextColor] is a [MaterialStateColor], then the effective + /// text color can depend on the [MaterialState.selected] state, i.e. if the + /// text is selected or not. + /// + /// If this color is null then the dial's text colors are based on the + /// theme's [ThemeData.colorScheme]. + final Color? dialTextColor; + + /// The [TextStyle] for the numbers on the time selection dial. + /// + /// If [dialTextStyle]'s [TextStyle.color] is a [MaterialStateColor], then the + /// effective text color can depend on the [MaterialState.selected] state, + /// i.e. if the text is selected or not. + /// + /// If this style is null then the dial's text style is based on the theme's + /// [ThemeData.textTheme]. + final TextStyle? dialTextStyle; + + /// The Material elevation for the time picker dialog. + final double? elevation; + + /// The color of the entry mode [IconButton]. + /// + /// If this is null, the time picker defaults to: + /// + /// + /// ```dart + /// Theme.of(context).colorScheme.onSurface.withOpacity( + /// Theme.of(context).colorScheme.brightness == Brightness.dark ? 1.0 : 0.6, + /// ) + /// ``` + final Color? entryModeIconColor; + + /// Used to configure the [TextStyle]s for the helper text in the header. + /// + /// If this is null, the time picker defaults to the overall theme's + /// [TextTheme.labelSmall]. + final TextStyle? helpTextStyle; + + /// The background color of the hour and minute header segments. + /// + /// If [hourMinuteColor] is a [MaterialStateColor], then the effective + /// background color can depend on the [MaterialState.selected] state, i.e. + /// if the segment is selected or not. + /// + /// By default, if the segment is selected, the overall theme's + /// `ColorScheme.primary.withOpacity(0.12)` is used when the overall theme's + /// brightness is [Brightness.light] and + /// `ColorScheme.primary.withOpacity(0.24)` is used when the overall theme's + /// brightness is [Brightness.dark]. + /// If the segment is not selected, the overall theme's + /// `ColorScheme.onSurface.withOpacity(0.12)` is used. + final Color? hourMinuteColor; + + /// The shape of the hour and minute controls that the time picker uses. + /// + /// If this is null, the time picker defaults to + /// `RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)))`. + final ShapeBorder? hourMinuteShape; + + /// The color of the header text that represents hours and minutes. + /// + /// If [hourMinuteTextColor] is a [MaterialStateColor], then the effective + /// text color can depend on the [MaterialState.selected] state, i.e. if the + /// text is selected or not. + /// + /// By default the overall theme's [ColorScheme.primary] color is used when + /// the text is selected and [ColorScheme.onSurface] when it's not selected. + final Color? hourMinuteTextColor; + + /// Used to configure the [TextStyle]s for the hour/minute controls. + /// + /// If this is null, the time picker defaults to the overall theme's + /// [TextTheme.headline3]. + final TextStyle? hourMinuteTextStyle; + + /// The input decoration theme for the [TextField]s in the time picker. + /// + /// If this is null, the time picker provides its own defaults. + final InputDecorationTheme? inputDecorationTheme; + + /// The padding around the time picker dialog when the entry mode is + /// [TimePickerEntryMode.dial] or [TimePickerEntryMode.dialOnly]. + final EdgeInsetsGeometry? padding; + + /// The shape of the [Dialog] that the time picker is presented in. + /// + /// If this is null, the time picker defaults to + /// `RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)))`. + final ShapeBorder? shape; + + /// Creates a copy of this object with the given fields replaced with the + /// new values. + TimePickerThemeData copyWith({ + Color? backgroundColor, + ButtonStyle? cancelButtonStyle, + ButtonStyle? confirmButtonStyle, + ButtonStyle? dayPeriodButtonStyle, + BorderSide? dayPeriodBorderSide, + Color? dayPeriodColor, + OutlinedBorder? dayPeriodShape, + Color? dayPeriodTextColor, + TextStyle? dayPeriodTextStyle, + Color? dialBackgroundColor, + Color? dialHandColor, + Color? dialTextColor, + TextStyle? dialTextStyle, + double? elevation, + Color? entryModeIconColor, + TextStyle? helpTextStyle, + Color? hourMinuteColor, + ShapeBorder? hourMinuteShape, + Color? hourMinuteTextColor, + TextStyle? hourMinuteTextStyle, + InputDecorationTheme? inputDecorationTheme, + EdgeInsetsGeometry? padding, + ShapeBorder? shape, + }) { + return TimePickerThemeData( + backgroundColor: backgroundColor ?? this.backgroundColor, + cancelButtonStyle: cancelButtonStyle ?? this.cancelButtonStyle, + confirmButtonStyle: confirmButtonStyle ?? this.confirmButtonStyle, + dayPeriodBorderSide: dayPeriodBorderSide ?? this.dayPeriodBorderSide, + dayPeriodColor: dayPeriodColor ?? this.dayPeriodColor, + dayPeriodShape: dayPeriodShape ?? this.dayPeriodShape, + dayPeriodTextColor: dayPeriodTextColor ?? this.dayPeriodTextColor, + dayPeriodTextStyle: dayPeriodTextStyle ?? this.dayPeriodTextStyle, + dialBackgroundColor: dialBackgroundColor ?? this.dialBackgroundColor, + dialHandColor: dialHandColor ?? this.dialHandColor, + dialTextColor: dialTextColor ?? this.dialTextColor, + dialTextStyle: dialTextStyle ?? this.dialTextStyle, + elevation: elevation ?? this.elevation, + entryModeIconColor: entryModeIconColor ?? this.entryModeIconColor, + helpTextStyle: helpTextStyle ?? this.helpTextStyle, + hourMinuteColor: hourMinuteColor ?? this.hourMinuteColor, + hourMinuteShape: hourMinuteShape ?? this.hourMinuteShape, + hourMinuteTextColor: hourMinuteTextColor ?? this.hourMinuteTextColor, + hourMinuteTextStyle: hourMinuteTextStyle ?? this.hourMinuteTextStyle, + inputDecorationTheme: inputDecorationTheme ?? this.inputDecorationTheme, + padding: padding ?? this.padding, + shape: shape ?? this.shape, + ); + } + + /// Linearly interpolate between two time picker themes. + /// + /// {@macro dart.ui.shadow.lerp} + static TimePickerThemeData lerp(TimePickerThemeData? a, TimePickerThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + // Workaround since BorderSide's lerp does not allow for null arguments. + BorderSide? lerpedBorderSide; + if (a?.dayPeriodBorderSide == null && b?.dayPeriodBorderSide == null) { + lerpedBorderSide = null; + } else if (a?.dayPeriodBorderSide == null) { + lerpedBorderSide = b?.dayPeriodBorderSide; + } else if (b?.dayPeriodBorderSide == null) { + lerpedBorderSide = a?.dayPeriodBorderSide; + } else { + lerpedBorderSide = BorderSide.lerp(a!.dayPeriodBorderSide!, b!.dayPeriodBorderSide!, t); + } + return TimePickerThemeData( + backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), + cancelButtonStyle: ButtonStyle.lerp(a?.cancelButtonStyle, b?.cancelButtonStyle, t), + confirmButtonStyle: ButtonStyle.lerp(a?.confirmButtonStyle, b?.confirmButtonStyle, t), + dayPeriodBorderSide: lerpedBorderSide, + dayPeriodColor: Color.lerp(a?.dayPeriodColor, b?.dayPeriodColor, t), + dayPeriodShape: ShapeBorder.lerp(a?.dayPeriodShape, b?.dayPeriodShape, t) as OutlinedBorder?, + dayPeriodTextColor: Color.lerp(a?.dayPeriodTextColor, b?.dayPeriodTextColor, t), + dayPeriodTextStyle: TextStyle.lerp(a?.dayPeriodTextStyle, b?.dayPeriodTextStyle, t), + dialBackgroundColor: Color.lerp(a?.dialBackgroundColor, b?.dialBackgroundColor, t), + dialHandColor: Color.lerp(a?.dialHandColor, b?.dialHandColor, t), + dialTextColor: Color.lerp(a?.dialTextColor, b?.dialTextColor, t), + dialTextStyle: TextStyle.lerp(a?.dialTextStyle, b?.dialTextStyle, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), + entryModeIconColor: Color.lerp(a?.entryModeIconColor, b?.entryModeIconColor, t), + helpTextStyle: TextStyle.lerp(a?.helpTextStyle, b?.helpTextStyle, t), + hourMinuteColor: Color.lerp(a?.hourMinuteColor, b?.hourMinuteColor, t), + hourMinuteShape: ShapeBorder.lerp(a?.hourMinuteShape, b?.hourMinuteShape, t), + hourMinuteTextColor: Color.lerp(a?.hourMinuteTextColor, b?.hourMinuteTextColor, t), + hourMinuteTextStyle: TextStyle.lerp(a?.hourMinuteTextStyle, b?.hourMinuteTextStyle, t), + inputDecorationTheme: t < 0.5 ? a?.inputDecorationTheme : b?.inputDecorationTheme, + padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), + ); + } + + @override + int get hashCode => Object.hashAll(<Object?>[ + backgroundColor, + cancelButtonStyle, + confirmButtonStyle, + dayPeriodBorderSide, + dayPeriodColor, + dayPeriodShape, + dayPeriodTextColor, + dayPeriodTextStyle, + dialBackgroundColor, + dialHandColor, + dialTextColor, + dialTextStyle, + elevation, + entryModeIconColor, + helpTextStyle, + hourMinuteColor, + hourMinuteShape, + hourMinuteTextColor, + hourMinuteTextStyle, + inputDecorationTheme, + padding, + shape, + ]); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is TimePickerThemeData + && other.backgroundColor == backgroundColor + && other.cancelButtonStyle == cancelButtonStyle + && other.confirmButtonStyle == confirmButtonStyle + && other.dayPeriodBorderSide == dayPeriodBorderSide + && other.dayPeriodColor == dayPeriodColor + && other.dayPeriodShape == dayPeriodShape + && other.dayPeriodTextColor == dayPeriodTextColor + && other.dayPeriodTextStyle == dayPeriodTextStyle + && other.dialBackgroundColor == dialBackgroundColor + && other.dialHandColor == dialHandColor + && other.dialTextColor == dialTextColor + && other.dialTextStyle == dialTextStyle + && other.elevation == elevation + && other.entryModeIconColor == entryModeIconColor + && other.helpTextStyle == helpTextStyle + && other.hourMinuteColor == hourMinuteColor + && other.hourMinuteShape == hourMinuteShape + && other.hourMinuteTextColor == hourMinuteTextColor + && other.hourMinuteTextStyle == hourMinuteTextStyle + && other.inputDecorationTheme == inputDecorationTheme + && other.padding == padding + && other.shape == shape; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ButtonStyle>('cancelButtonStyle', cancelButtonStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<ButtonStyle>('confirmButtonStyle', confirmButtonStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<BorderSide>('dayPeriodBorderSide', dayPeriodBorderSide, defaultValue: null)); + properties.add(ColorProperty('dayPeriodColor', dayPeriodColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('dayPeriodShape', dayPeriodShape, defaultValue: null)); + properties.add(ColorProperty('dayPeriodTextColor', dayPeriodTextColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('dayPeriodTextStyle', dayPeriodTextStyle, defaultValue: null)); + properties.add(ColorProperty('dialBackgroundColor', dialBackgroundColor, defaultValue: null)); + properties.add(ColorProperty('dialHandColor', dialHandColor, defaultValue: null)); + properties.add(ColorProperty('dialTextColor', dialTextColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle?>('dialTextStyle', dialTextStyle, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); + properties.add(ColorProperty('entryModeIconColor', entryModeIconColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('helpTextStyle', helpTextStyle, defaultValue: null)); + properties.add(ColorProperty('hourMinuteColor', hourMinuteColor, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('hourMinuteShape', hourMinuteShape, defaultValue: null)); + properties.add(ColorProperty('hourMinuteTextColor', hourMinuteTextColor, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('hourMinuteTextStyle', hourMinuteTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<InputDecorationTheme>('inputDecorationTheme', inputDecorationTheme, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); + } +} + +/// An inherited widget that defines the configuration for time pickers +/// displayed using [showTimePicker] in this widget's subtree. +/// +/// Values specified here are used for time picker properties that are not +/// given an explicit non-null value. +class TimePickerTheme extends InheritedTheme { + /// Creates a time picker theme that controls the configurations for + /// time pickers displayed in its widget subtree. + const TimePickerTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties for descendant time picker widgets. + final TimePickerThemeData data; + + /// The [data] value of the closest [TimePickerTheme] ancestor. + /// + /// If there is no ancestor, it returns [ThemeData.timePickerTheme]. + /// Applications can assume that the returned value will not be null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// TimePickerThemeData theme = TimePickerTheme.of(context); + /// ``` + static TimePickerThemeData of(BuildContext context) { + final TimePickerTheme? timePickerTheme = context.dependOnInheritedWidgetOfExactType<TimePickerTheme>(); + return timePickerTheme?.data ?? Theme.of(context).timePickerTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return TimePickerTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(TimePickerTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/toggle_buttons.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/toggle_buttons.dart new file mode 100644 index 0000000000000000000000000000000000000000..731bf9781695e93cf51a8e3e782f6d8f68a2b489 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/toggle_buttons.dart @@ -0,0 +1,1647 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'button_style.dart'; +import 'color_scheme.dart'; +import 'constants.dart'; +import 'ink_ripple.dart'; +import 'material_state.dart'; +import 'text_button.dart'; +import 'theme.dart'; +import 'theme_data.dart'; +import 'toggle_buttons_theme.dart'; + +// Examples can assume: +// List<bool> isSelected = <bool>[]; +// void setState(dynamic arg) { } + +/// A set of toggle buttons. +/// +/// The list of [children] are laid out along [direction]. The state of each button +/// is controlled by [isSelected], which is a list of bools that determine +/// if a button is in an unselected or selected state. They are both +/// correlated by their index in the list. The length of [isSelected] has to +/// match the length of the [children] list. +/// +/// There is a Material 3 version of this component, [SegmentedButton], +/// that's preferred for applications that are configured for Material 3 +/// (see [ThemeData.useMaterial3]). +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=kVEguaQWGAY} +/// +/// ## Updating to [SegmentedButton] +/// +/// There is a Material 3 version of this component, [SegmentedButton], +/// that's preferred for applications that are configured for Material 3 +/// (see [ThemeData.useMaterial3]). The [SegmentedButton] widget's visuals +/// are a little bit different, see the Material 3 spec at +/// <https://m3.material.io/components/segmented-buttons/overview> for +/// more details. The [SegmentedButton] widget's API is also slightly different. +/// While the [ToggleButtons] widget can have list of widgets, the +/// [SegmentedButton] widget has a list of [ButtonSegment]s with +/// a type value. While the [ToggleButtons] uses a list of boolean values +/// to determine the selection state of each button, the [SegmentedButton] +/// uses a set of type values to determine the selection state of each segment. +/// The [SegmentedButton.style] is a [ButtonStyle] style field, which can be +/// used to customize the entire segmented button and the individual segments. +/// +/// {@tool dartpad} +/// This sample shows how to migrate [ToggleButtons] that allows multiple +/// or no selection to [SegmentedButton] that allows multiple or no selection. +/// +/// ** See code in examples/api/lib/material/toggle_buttons/toggle_buttons.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example showcase [ToggleButtons] in various configurations. +/// +/// ** See code in examples/api/lib/material/toggle_buttons/toggle_buttons.0.dart ** +/// {@end-tool} +/// +/// ## Customizing toggle buttons +/// Each toggle's behavior can be configured by the [onPressed] callback, which +/// can update the [isSelected] list however it wants to. +/// +/// {@animation 700 150 https://flutter.github.io/assets-for-api-docs/assets/material/toggle_buttons_simple.mp4} +/// +/// Here is an implementation that allows for multiple buttons to be +/// simultaneously selected, while requiring none of the buttons to be +/// selected. +/// +/// ```dart +/// ToggleButtons( +/// isSelected: isSelected, +/// onPressed: (int index) { +/// setState(() { +/// isSelected[index] = !isSelected[index]; +/// }); +/// }, +/// children: const <Widget>[ +/// Icon(Icons.ac_unit), +/// Icon(Icons.call), +/// Icon(Icons.cake), +/// ], +/// ), +/// ``` +/// +/// {@animation 700 150 https://flutter.github.io/assets-for-api-docs/assets/material/toggle_buttons_required_mutually_exclusive.mp4} +/// +/// Here is an implementation that requires mutually exclusive selection while +/// requiring at least one selection. This assumes that [isSelected] was +/// properly initialized with one selection. +/// +/// ```dart +/// ToggleButtons( +/// isSelected: isSelected, +/// onPressed: (int index) { +/// setState(() { +/// for (int buttonIndex = 0; buttonIndex < isSelected.length; buttonIndex++) { +/// if (buttonIndex == index) { +/// isSelected[buttonIndex] = true; +/// } else { +/// isSelected[buttonIndex] = false; +/// } +/// } +/// }); +/// }, +/// children: const <Widget>[ +/// Icon(Icons.ac_unit), +/// Icon(Icons.call), +/// Icon(Icons.cake), +/// ], +/// ), +/// ``` +/// +/// {@animation 700 150 https://flutter.github.io/assets-for-api-docs/assets/material/toggle_buttons_mutually_exclusive.mp4} +/// +/// Here is an implementation that requires mutually exclusive selection, +/// but allows for none of the buttons to be selected. +/// +/// ```dart +/// ToggleButtons( +/// isSelected: isSelected, +/// onPressed: (int index) { +/// setState(() { +/// for (int buttonIndex = 0; buttonIndex < isSelected.length; buttonIndex++) { +/// if (buttonIndex == index) { +/// isSelected[buttonIndex] = !isSelected[buttonIndex]; +/// } else { +/// isSelected[buttonIndex] = false; +/// } +/// } +/// }); +/// }, +/// children: const <Widget>[ +/// Icon(Icons.ac_unit), +/// Icon(Icons.call), +/// Icon(Icons.cake), +/// ], +/// ), +/// ``` +/// +/// {@animation 700 150 https://flutter.github.io/assets-for-api-docs/assets/material/toggle_buttons_required.mp4} +/// +/// Here is an implementation that allows for multiple buttons to be +/// simultaneously selected, while requiring at least one selection. This +/// assumes that [isSelected] was properly initialized with one selection. +/// +/// ```dart +/// ToggleButtons( +/// isSelected: isSelected, +/// onPressed: (int index) { +/// int count = 0; +/// for (final bool value in isSelected) { +/// if (value) { +/// count += 1; +/// } +/// } +/// if (isSelected[index] && count < 2) { +/// return; +/// } +/// setState(() { +/// isSelected[index] = !isSelected[index]; +/// }); +/// }, +/// children: const <Widget>[ +/// Icon(Icons.ac_unit), +/// Icon(Icons.call), +/// Icon(Icons.cake), +/// ], +/// ), +/// ``` +/// +/// ## ToggleButton Borders +/// The toggle buttons, by default, have a solid, 1 logical pixel border +/// surrounding itself and separating each button. The toggle button borders' +/// color, width, and corner radii are configurable. +/// +/// The [selectedBorderColor] determines the border's color when the button is +/// selected, while [disabledBorderColor] determines the border's color when +/// the button is disabled. [borderColor] is used when the button is enabled. +/// +/// To remove the border, set [renderBorder] to false. Setting [borderWidth] to +/// 0.0 results in a hairline border. For more information on hairline borders, +/// see [BorderSide.width]. +/// +/// See also: +/// +/// * <https://material.io/design/components/buttons.html#toggle-button> +class ToggleButtons extends StatelessWidget { + /// Creates a set of toggle buttons. + /// + /// It displays its widgets provided in a [List] of [children] along [direction]. + /// The state of each button is controlled by [isSelected], which is a list + /// of bools that determine if a button is in an active, disabled, or + /// selected state. They are both correlated by their index in the list. + /// The length of [isSelected] has to match the length of the [children] + /// list. + /// + /// Both [children] and [isSelected] properties arguments are required. + /// + /// The [focusNodes] argument must be null or a list of nodes. If [direction] + /// is [Axis.vertical], [verticalDirection] must not be null. + const ToggleButtons({ + super.key, + required this.children, + required this.isSelected, + this.onPressed, + this.mouseCursor, + this.tapTargetSize, + this.textStyle, + this.constraints, + this.color, + this.selectedColor, + this.disabledColor, + this.fillColor, + this.focusColor, + this.highlightColor, + this.hoverColor, + this.splashColor, + this.focusNodes, + this.renderBorder = true, + this.borderColor, + this.selectedBorderColor, + this.disabledBorderColor, + this.borderRadius, + this.borderWidth, + this.direction = Axis.horizontal, + this.verticalDirection = VerticalDirection.down, + }) : assert(children.length == isSelected.length); + + static const double _defaultBorderWidth = 1.0; + + /// The toggle button widgets. + /// + /// These are typically [Icon] or [Text] widgets. The boolean selection + /// state of each widget is defined by the corresponding [isSelected] + /// list item. + /// + /// The length of children has to match the length of [isSelected]. If + /// [focusNodes] is not null, the length of children has to also match + /// the length of [focusNodes]. + final List<Widget> children; + + /// The corresponding selection state of each toggle button. + /// + /// Each value in this list represents the selection state of the [children] + /// widget at the same index. + /// + /// The length of [isSelected] has to match the length of [children]. + final List<bool> isSelected; + + /// The callback that is called when a button is tapped. + /// + /// The index parameter of the callback is the index of the button that is + /// tapped or otherwise activated. + /// + /// When the callback is null, all toggle buttons will be disabled. + final void Function(int index)? onPressed; + + /// {@macro flutter.material.RawMaterialButton.mouseCursor} + /// + /// If this property is null, [MaterialStateMouseCursor.clickable] will be used. + final MouseCursor? mouseCursor; + + /// Configures the minimum size of the area within which the buttons may + /// be pressed. + /// + /// If the [tapTargetSize] is larger than [constraints], the buttons will + /// include a transparent margin that responds to taps. + /// + /// Defaults to [ThemeData.materialTapTargetSize]. + final MaterialTapTargetSize? tapTargetSize; + + /// The [TextStyle] to apply to any text in these toggle buttons. + /// + /// [TextStyle.color] will be ignored and substituted by [color], + /// [selectedColor] or [disabledColor] depending on whether the buttons + /// are active, selected, or disabled. + final TextStyle? textStyle; + + /// Defines the button's size. + /// + /// Typically used to constrain the button's minimum size. + /// + /// If this property is null, then + /// BoxConstraints(minWidth: 48.0, minHeight: 48.0) is be used. + final BoxConstraints? constraints; + + /// The color for descendant [Text] and [Icon] widgets if the button is + /// enabled and not selected. + /// + /// If [onPressed] is not null, this color will be used for values in + /// [isSelected] that are false. + /// + /// If this property is null, then ToggleButtonTheme.of(context).color + /// is used. If [ToggleButtonsThemeData.color] is also null, then + /// Theme.of(context).colorScheme.onSurface is used. + final Color? color; + + /// The color for descendant [Text] and [Icon] widgets if the button is + /// selected. + /// + /// If [onPressed] is not null, this color will be used for values in + /// [isSelected] that are true. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).selectedColor is used. If + /// [ToggleButtonsThemeData.selectedColor] is also null, then + /// Theme.of(context).colorScheme.primary is used. + final Color? selectedColor; + + /// The color for descendant [Text] and [Icon] widgets if the button is + /// disabled. + /// + /// If [onPressed] is null, this color will be used. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).disabledColor is used. If + /// [ToggleButtonsThemeData.disabledColor] is also null, then + /// Theme.of(context).colorScheme.onSurface.withOpacity(0.38) is used. + final Color? disabledColor; + + /// The fill color for selected toggle buttons. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).fillColor is used. If + /// [ToggleButtonsThemeData.fillColor] is also null, then + /// the fill color is null. + /// + /// If fillColor is a [MaterialStateProperty<Color>], then [MaterialStateProperty.resolve] + /// is used for the following [MaterialState]s: + /// + /// * [MaterialState.disabled] + /// * [MaterialState.selected] + /// + final Color? fillColor; + + /// The color to use for filling the button when the button has input focus. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).focusColor is used. If + /// [ToggleButtonsThemeData.focusColor] is also null, then + /// Theme.of(context).focusColor is used. + final Color? focusColor; + + /// The highlight color for the button's [InkWell]. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).highlightColor is used. If + /// [ToggleButtonsThemeData.highlightColor] is also null, then + /// Theme.of(context).highlightColor is used. + final Color? highlightColor; + + /// The splash color for the button's [InkWell]. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).splashColor is used. If + /// [ToggleButtonsThemeData.splashColor] is also null, then + /// Theme.of(context).splashColor is used. + final Color? splashColor; + + /// The color to use for filling the button when the button has a pointer + /// hovering over it. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).hoverColor is used. If + /// [ToggleButtonsThemeData.hoverColor] is also null, then + /// Theme.of(context).hoverColor is used. + final Color? hoverColor; + + /// The list of [FocusNode]s, corresponding to each toggle button. + /// + /// Focus is used to determine which widget should be affected by keyboard + /// events. The focus tree keeps track of which widget is currently focused + /// on by the user. + /// + /// If not null, the length of focusNodes has to match the length of + /// [children]. + /// + /// See [FocusNode] for more information about how focus nodes are used. + final List<FocusNode>? focusNodes; + + /// Whether or not to render a border around each toggle button. + /// + /// When true, a border with [borderWidth], [borderRadius] and the + /// appropriate border color will render. Otherwise, no border will be + /// rendered. + final bool renderBorder; + + /// The border color to display when the toggle button is enabled and not + /// selected. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).borderColor is used. If + /// [ToggleButtonsThemeData.borderColor] is also null, then + /// Theme.of(context).colorScheme.onSurface is used. + final Color? borderColor; + + /// The border color to display when the toggle button is selected. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).selectedBorderColor is used. If + /// [ToggleButtonsThemeData.selectedBorderColor] is also null, then + /// Theme.of(context).colorScheme.primary is used. + final Color? selectedBorderColor; + + /// The border color to display when the toggle button is disabled. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).disabledBorderColor is used. If + /// [ToggleButtonsThemeData.disabledBorderColor] is also null, then + /// Theme.of(context).disabledBorderColor is used. + final Color? disabledBorderColor; + + /// The width of the border surrounding each toggle button. + /// + /// This applies to both the greater surrounding border, as well as the + /// borders rendered between toggle buttons. + /// + /// To render a hairline border (one physical pixel), set borderWidth to 0.0. + /// See [BorderSide.width] for more details on hairline borders. + /// + /// To omit the border entirely, set [renderBorder] to false. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).borderWidth is used. If + /// [ToggleButtonsThemeData.borderWidth] is also null, then + /// a width of 1.0 is used. + final double? borderWidth; + + /// The radii of the border's corners. + /// + /// If this property is null, then + /// ToggleButtonTheme.of(context).borderRadius is used. If + /// [ToggleButtonsThemeData.borderRadius] is also null, then + /// the buttons default to non-rounded borders. + final BorderRadius? borderRadius; + + /// The direction along which the buttons are rendered. + /// + /// Defaults to [Axis.horizontal]. + final Axis direction; + + /// If [direction] is [Axis.vertical], this parameter determines whether to lay out + /// the buttons starting from the first or last child from top to bottom. + final VerticalDirection verticalDirection; + + // Determines if this is the first child that is being laid out + // by the render object, _not_ the order of the children in its list. + bool _isFirstButton(int index, int length, TextDirection textDirection) { + return index == 0 && ((direction == Axis.horizontal && textDirection == TextDirection.ltr) || + (direction == Axis.vertical && verticalDirection == VerticalDirection.down)) + || index == length - 1 && ((direction == Axis.horizontal && textDirection == TextDirection.rtl) || + (direction == Axis.vertical && verticalDirection == VerticalDirection.up)); + } + + // Determines if this is the last child that is being laid out + // by the render object, _not_ the order of the children in its list. + bool _isLastButton(int index, int length, TextDirection textDirection) { + return index == length - 1 && ((direction == Axis.horizontal && textDirection == TextDirection.ltr) || + (direction == Axis.vertical && verticalDirection == VerticalDirection.down)) + || index == 0 && ((direction == Axis.horizontal && textDirection == TextDirection.rtl) || + (direction == Axis.vertical && verticalDirection == VerticalDirection.up)); + } + + BorderRadius _getEdgeBorderRadius( + int index, + int length, + TextDirection textDirection, + ToggleButtonsThemeData toggleButtonsTheme, + ) { + final BorderRadius resultingBorderRadius = borderRadius + ?? toggleButtonsTheme.borderRadius + ?? BorderRadius.zero; + + if (length == 1) { + return resultingBorderRadius; + } else if (direction == Axis.horizontal) { + if (_isFirstButton(index, length, textDirection)) { + return BorderRadius.only( + topLeft: resultingBorderRadius.topLeft, + bottomLeft: resultingBorderRadius.bottomLeft, + ); + } else if (_isLastButton(index, length, textDirection)) { + return BorderRadius.only( + topRight: resultingBorderRadius.topRight, + bottomRight: resultingBorderRadius.bottomRight, + ); + } + } else { + if (_isFirstButton(index, length, textDirection)) { + return BorderRadius.only( + topLeft: resultingBorderRadius.topLeft, + topRight: resultingBorderRadius.topRight, + ); + } else if (_isLastButton(index, length, textDirection)) { + return BorderRadius.only( + bottomLeft: resultingBorderRadius.bottomLeft, + bottomRight: resultingBorderRadius.bottomRight, + ); + } + } + + return BorderRadius.zero; + } + + BorderRadius _getClipBorderRadius( + int index, + int length, + TextDirection textDirection, + ToggleButtonsThemeData toggleButtonsTheme, + ) { + final BorderRadius resultingBorderRadius = borderRadius + ?? toggleButtonsTheme.borderRadius + ?? BorderRadius.zero; + final double resultingBorderWidth = borderWidth + ?? toggleButtonsTheme.borderWidth + ?? _defaultBorderWidth; + + if (length == 1) { + return BorderRadius.only( + topLeft: resultingBorderRadius.topLeft - Radius.circular(resultingBorderWidth / 2.0), + bottomLeft: resultingBorderRadius.bottomLeft - Radius.circular(resultingBorderWidth / 2.0), + topRight: resultingBorderRadius.topRight - Radius.circular(resultingBorderWidth / 2.0), + bottomRight: resultingBorderRadius.bottomRight - Radius.circular(resultingBorderWidth / 2.0), + ); + } else if (direction == Axis.horizontal) { + if (_isFirstButton(index, length, textDirection)) { + return BorderRadius.only( + topLeft: resultingBorderRadius.topLeft - Radius.circular(resultingBorderWidth / 2.0), + bottomLeft: resultingBorderRadius.bottomLeft - Radius.circular(resultingBorderWidth / 2.0), + ); + } else if (_isLastButton(index, length, textDirection)) { + return BorderRadius.only( + topRight: resultingBorderRadius.topRight - Radius.circular(resultingBorderWidth / 2.0), + bottomRight: resultingBorderRadius.bottomRight - Radius.circular(resultingBorderWidth / 2.0), + ); + } + } else { + if (_isFirstButton(index, length, textDirection)) { + return BorderRadius.only( + topLeft: resultingBorderRadius.topLeft - Radius.circular(resultingBorderWidth / 2.0), + topRight: resultingBorderRadius.topRight - Radius.circular(resultingBorderWidth / 2.0), + ); + } else if (_isLastButton(index, length, textDirection)) { + return BorderRadius.only( + bottomLeft: resultingBorderRadius.bottomLeft - Radius.circular(resultingBorderWidth / 2.0), + bottomRight: resultingBorderRadius.bottomRight - Radius.circular(resultingBorderWidth / 2.0), + ); + } + } + return BorderRadius.zero; + } + + BorderSide _getLeadingBorderSide( + int index, + ThemeData theme, + ToggleButtonsThemeData toggleButtonsTheme, + ) { + if (!renderBorder) { + return BorderSide.none; + } + + final double resultingBorderWidth = borderWidth + ?? toggleButtonsTheme.borderWidth + ?? _defaultBorderWidth; + if (onPressed != null && (isSelected[index] || (index != 0 && isSelected[index - 1]))) { + return BorderSide( + color: selectedBorderColor + ?? toggleButtonsTheme.selectedBorderColor + ?? theme.colorScheme.onSurface.withOpacity(0.12), + width: resultingBorderWidth, + ); + } else if (onPressed != null && !isSelected[index]) { + return BorderSide( + color: borderColor + ?? toggleButtonsTheme.borderColor + ?? theme.colorScheme.onSurface.withOpacity(0.12), + width: resultingBorderWidth, + ); + } else { + return BorderSide( + color: disabledBorderColor + ?? toggleButtonsTheme.disabledBorderColor + ?? theme.colorScheme.onSurface.withOpacity(0.12), + width: resultingBorderWidth, + ); + } + } + + BorderSide _getBorderSide( + int index, + ThemeData theme, + ToggleButtonsThemeData toggleButtonsTheme, + ) { + if (!renderBorder) { + return BorderSide.none; + } + + final double resultingBorderWidth = borderWidth + ?? toggleButtonsTheme.borderWidth + ?? _defaultBorderWidth; + if (onPressed != null && isSelected[index]) { + return BorderSide( + color: selectedBorderColor + ?? toggleButtonsTheme.selectedBorderColor + ?? theme.colorScheme.onSurface.withOpacity(0.12), + width: resultingBorderWidth, + ); + } else if (onPressed != null && !isSelected[index]) { + return BorderSide( + color: borderColor + ?? toggleButtonsTheme.borderColor + ?? theme.colorScheme.onSurface.withOpacity(0.12), + width: resultingBorderWidth, + ); + } else { + return BorderSide( + color: disabledBorderColor + ?? toggleButtonsTheme.disabledBorderColor + ?? theme.colorScheme.onSurface.withOpacity(0.12), + width: resultingBorderWidth, + ); + } + } + + BorderSide _getTrailingBorderSide( + int index, + ThemeData theme, + ToggleButtonsThemeData toggleButtonsTheme, + ) { + if (!renderBorder) { + return BorderSide.none; + } + + if (index != children.length - 1) { + return BorderSide.none; + } + + final double resultingBorderWidth = borderWidth + ?? toggleButtonsTheme.borderWidth + ?? _defaultBorderWidth; + if (onPressed != null && (isSelected[index])) { + return BorderSide( + color: selectedBorderColor + ?? toggleButtonsTheme.selectedBorderColor + ?? theme.colorScheme.onSurface.withOpacity(0.12), + width: resultingBorderWidth, + ); + } else if (onPressed != null && !isSelected[index]) { + return BorderSide( + color: borderColor + ?? toggleButtonsTheme.borderColor + ?? theme.colorScheme.onSurface.withOpacity(0.12), + width: resultingBorderWidth, + ); + } else { + return BorderSide( + color: disabledBorderColor + ?? toggleButtonsTheme.disabledBorderColor + ?? theme.colorScheme.onSurface.withOpacity(0.12), + width: resultingBorderWidth, + ); + } + } + + @override + Widget build(BuildContext context) { + assert( + () { + if (focusNodes != null) { + return focusNodes!.length == children.length; + } + return true; + }(), + 'focusNodes.length must match children.length.\n' + 'There are ${focusNodes!.length} focus nodes, while ' + 'there are ${children.length} children.', + ); + final ThemeData theme = Theme.of(context); + final ToggleButtonsThemeData toggleButtonsTheme = ToggleButtonsTheme.of(context); + final TextDirection textDirection = Directionality.of(context); + + final List<Widget> buttons = List<Widget>.generate(children.length, (int index) { + final BorderRadius edgeBorderRadius = _getEdgeBorderRadius(index, children.length, textDirection, toggleButtonsTheme); + final BorderRadius clipBorderRadius = _getClipBorderRadius(index, children.length, textDirection, toggleButtonsTheme); + + final BorderSide leadingBorderSide = _getLeadingBorderSide(index, theme, toggleButtonsTheme); + final BorderSide borderSide = _getBorderSide(index, theme, toggleButtonsTheme); + final BorderSide trailingBorderSide = _getTrailingBorderSide(index, theme, toggleButtonsTheme); + + final Set<MaterialState> states = <MaterialState>{ + if (isSelected[index] && onPressed != null) MaterialState.selected, + if (onPressed == null) MaterialState.disabled, + }; + final Color effectiveFillColor = _ResolveFillColor(fillColor + ?? toggleButtonsTheme.fillColor).resolve(states) + ?? _DefaultFillColor(theme.colorScheme).resolve(states); + final Color currentColor; + if (onPressed != null && isSelected[index]) { + currentColor = selectedColor + ?? toggleButtonsTheme.selectedColor + ?? theme.colorScheme.primary; + } else if (onPressed != null && !isSelected[index]) { + currentColor = color + ?? toggleButtonsTheme.color + ?? theme.colorScheme.onSurface.withOpacity(0.87); + } else { + currentColor = disabledColor + ?? toggleButtonsTheme.disabledColor + ?? theme.colorScheme.onSurface.withOpacity(0.38); + } + final TextStyle currentTextStyle = textStyle + ?? toggleButtonsTheme.textStyle + ?? theme.textTheme.bodyMedium!; + final BoxConstraints? currentConstraints = constraints + ?? toggleButtonsTheme.constraints; + final Size minimumSize = currentConstraints == null + ? const Size.square(kMinInteractiveDimension) + : Size(currentConstraints.minWidth, currentConstraints.minHeight); + final Size? maximumSize = currentConstraints == null + ? null + : Size(currentConstraints.maxWidth, currentConstraints.maxHeight); + final Size minPaddingSize; + switch (tapTargetSize ?? theme.materialTapTargetSize) { + case MaterialTapTargetSize.padded: + if (direction == Axis.horizontal) { + minPaddingSize = const Size( + 0.0, + kMinInteractiveDimension, + ); + } else { + minPaddingSize = const Size( + kMinInteractiveDimension, + 0.0, + ); + } + assert(minPaddingSize.width >= 0.0); + assert(minPaddingSize.height >= 0.0); + case MaterialTapTargetSize.shrinkWrap: + minPaddingSize = Size.zero; + } + + Widget button = _SelectToggleButton( + leadingBorderSide: leadingBorderSide, + borderSide: borderSide, + trailingBorderSide: trailingBorderSide, + borderRadius: edgeBorderRadius, + isFirstButton: index == 0, + isLastButton: index == children.length - 1, + direction: direction, + verticalDirection: verticalDirection, + child: ClipRRect( + borderRadius: clipBorderRadius, + child: TextButton( + focusNode: focusNodes != null ? focusNodes![index] : null, + style: ButtonStyle( + backgroundColor: MaterialStatePropertyAll<Color?>(effectiveFillColor), + foregroundColor: MaterialStatePropertyAll<Color?>(currentColor), + overlayColor: _ToggleButtonDefaultOverlay( + selected: onPressed != null && isSelected[index], + unselected: onPressed != null && !isSelected[index], + colorScheme: theme.colorScheme, + disabledColor: disabledColor ?? toggleButtonsTheme.disabledColor, + focusColor: focusColor ?? toggleButtonsTheme.focusColor, + highlightColor: highlightColor ?? toggleButtonsTheme.highlightColor, + hoverColor: hoverColor ?? toggleButtonsTheme.hoverColor, + splashColor: splashColor ?? toggleButtonsTheme.splashColor, + ), + elevation: const MaterialStatePropertyAll<double>(0), + textStyle: MaterialStatePropertyAll<TextStyle?>(currentTextStyle.copyWith( + color: currentColor, + )), + padding: const MaterialStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.zero), + minimumSize: MaterialStatePropertyAll<Size?>(minimumSize), + maximumSize: MaterialStatePropertyAll<Size?>(maximumSize), + shape: const MaterialStatePropertyAll<OutlinedBorder>(RoundedRectangleBorder()), + mouseCursor: MaterialStatePropertyAll<MouseCursor?>(mouseCursor), + visualDensity: VisualDensity.standard, + tapTargetSize: MaterialTapTargetSize.shrinkWrap, + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: Alignment.center, + splashFactory: InkRipple.splashFactory, + ), + onPressed: onPressed != null + ? () {onPressed!(index);} + : null, + child: children[index], + ), + ), + ); + + if (currentConstraints != null) { + button = Center(child: button); + } + + return MergeSemantics( + child: Semantics( + container: true, + checked: isSelected[index], + enabled: onPressed != null, + child: _InputPadding( + minSize: minPaddingSize, + direction: direction, + child: button, + ), + ), + ); + }); + + if (direction == Axis.vertical) { + return IntrinsicWidth( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + verticalDirection: verticalDirection, + children: buttons, + ), + ); + } + + return IntrinsicHeight( + child: Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: buttons, + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('disabled', + value: onPressed == null, + ifTrue: 'Buttons are disabled', + ifFalse: 'Buttons are enabled', + )); + textStyle?.debugFillProperties(properties, prefix: 'textStyle.'); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(ColorProperty('selectedColor', selectedColor, defaultValue: null)); + properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: null)); + properties.add(ColorProperty('fillColor', fillColor, defaultValue: null)); + properties.add(ColorProperty('focusColor', focusColor, defaultValue: null)); + properties.add(ColorProperty('highlightColor', highlightColor, defaultValue: null)); + properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: null)); + properties.add(ColorProperty('splashColor', splashColor, defaultValue: null)); + properties.add(ColorProperty('borderColor', borderColor, defaultValue: null)); + properties.add(ColorProperty('selectedBorderColor', selectedBorderColor, defaultValue: null)); + properties.add(ColorProperty('disabledBorderColor', disabledBorderColor, defaultValue: null)); + properties.add(DiagnosticsProperty<BorderRadius>('borderRadius', borderRadius, defaultValue: null)); + properties.add(DoubleProperty('borderWidth', borderWidth, defaultValue: null)); + properties.add(DiagnosticsProperty<Axis>('direction', direction, defaultValue: Axis.horizontal)); + properties.add(DiagnosticsProperty<VerticalDirection>('verticalDirection', verticalDirection, defaultValue: VerticalDirection.down)); + } +} + +@immutable +class _ResolveFillColor extends MaterialStateProperty<Color?> with Diagnosticable { + _ResolveFillColor(this.primary); + + final Color? primary; + + @override + Color? resolve(Set<MaterialState> states) { + if (primary is MaterialStateProperty<Color>) { + return MaterialStateProperty.resolveAs<Color?>(primary, states); + } + return states.contains(MaterialState.selected) ? primary : null; + } +} + +@immutable +class _DefaultFillColor extends MaterialStateProperty<Color> with Diagnosticable { + _DefaultFillColor(this.colorScheme); + + final ColorScheme colorScheme; + + @override + Color resolve(Set<MaterialState> states) { + if (states.contains(MaterialState.selected)) { + return colorScheme.primary.withOpacity(0.12); + } + return colorScheme.surface.withOpacity(0.0); + } +} + +@immutable +class _ToggleButtonDefaultOverlay extends MaterialStateProperty<Color?> { + _ToggleButtonDefaultOverlay({ + required this.selected, + required this.unselected, + this.colorScheme, + this.focusColor, + this.highlightColor, + this.hoverColor, + this.splashColor, + this.disabledColor, + }); + + final bool selected; + final bool unselected; + final ColorScheme? colorScheme; + final Color? focusColor; + final Color? highlightColor; + final Color? hoverColor; + final Color? splashColor; + final Color? disabledColor; + + @override + Color? resolve(Set<MaterialState> states) { + if (selected) { + if (states.contains(MaterialState.pressed)) { + return splashColor ?? colorScheme?.primary.withOpacity(0.16); + } + if (states.contains(MaterialState.hovered)) { + return hoverColor ?? colorScheme?.primary.withOpacity(0.04); + } + if (states.contains(MaterialState.focused)) { + return focusColor ?? colorScheme?.primary.withOpacity(0.12); + } + } else if (unselected) { + if (states.contains(MaterialState.pressed)) { + return splashColor ?? highlightColor ?? colorScheme?.onSurface.withOpacity(0.16); + } + if (states.contains(MaterialState.hovered)) { + return hoverColor ?? colorScheme?.onSurface.withOpacity(0.04); + } + if (states.contains(MaterialState.focused)) { + return focusColor ?? colorScheme?.onSurface.withOpacity(0.12); + } + } + return null; + } + + @override + String toString() { + return ''' + { + selected: + hovered: $hoverColor, otherwise: ${colorScheme?.primary.withOpacity(0.04)}, + focused: $focusColor, otherwise: ${colorScheme?.primary.withOpacity(0.12)}, + pressed: $splashColor, otherwise: ${colorScheme?.primary.withOpacity(0.16)}, + unselected: + hovered: $hoverColor, otherwise: ${colorScheme?.onSurface.withOpacity(0.04)}, + focused: $focusColor, otherwise: ${colorScheme?.onSurface.withOpacity(0.12)}, + pressed: $splashColor, otherwise: ${colorScheme?.onSurface.withOpacity(0.16)}, + otherwise: null, + } + '''; + } +} + +class _SelectToggleButton extends SingleChildRenderObjectWidget { + const _SelectToggleButton({ + required Widget super.child, + required this.leadingBorderSide, + required this.borderSide, + required this.trailingBorderSide, + required this.borderRadius, + required this.isFirstButton, + required this.isLastButton, + required this.direction, + required this.verticalDirection, + }); + + // The width and color of the button's leading side border. + final BorderSide leadingBorderSide; + + // The width and color of the side borders. + // + // If [direction] is [Axis.horizontal], this corresponds to the width and color + // of the button's top and bottom side borders. + // + // If [direction] is [Axis.vertical], this corresponds to the width and color + // of the button's left and right side borders. + final BorderSide borderSide; + + // The width and color of the button's trailing side border. + final BorderSide trailingBorderSide; + + // The border radii of each corner of the button. + final BorderRadius borderRadius; + + // Whether or not this toggle button is the first button in the list. + final bool isFirstButton; + + // Whether or not this toggle button is the last button in the list. + final bool isLastButton; + + // The direction along which the buttons are rendered. + final Axis direction; + + // If [direction] is [Axis.vertical], this property defines whether or not this button in its list + // of buttons is laid out starting from top to bottom or from bottom to top. + final VerticalDirection verticalDirection; + + @override + _SelectToggleButtonRenderObject createRenderObject(BuildContext context) => _SelectToggleButtonRenderObject( + leadingBorderSide, + borderSide, + trailingBorderSide, + borderRadius, + isFirstButton, + isLastButton, + direction, + verticalDirection, + Directionality.of(context), + ); + + @override + void updateRenderObject(BuildContext context, _SelectToggleButtonRenderObject renderObject) { + renderObject + ..leadingBorderSide = leadingBorderSide + ..borderSide = borderSide + ..trailingBorderSide = trailingBorderSide + ..borderRadius = borderRadius + ..isFirstButton = isFirstButton + ..isLastButton = isLastButton + ..direction = direction + ..verticalDirection = verticalDirection + ..textDirection = Directionality.of(context); + } +} + +class _SelectToggleButtonRenderObject extends RenderShiftedBox { + _SelectToggleButtonRenderObject( + this._leadingBorderSide, + this._borderSide, + this._trailingBorderSide, + this._borderRadius, + this._isFirstButton, + this._isLastButton, + this._direction, + this._verticalDirection, + this._textDirection, [ + RenderBox? child, + ]) : super(child); + + Axis get direction => _direction; + Axis _direction; + set direction(Axis value) { + if (_direction == value) { + return; + } + _direction = value; + markNeedsLayout(); + } + + VerticalDirection get verticalDirection => _verticalDirection; + VerticalDirection _verticalDirection; + set verticalDirection(VerticalDirection value) { + if (_verticalDirection == value) { + return; + } + _verticalDirection = value; + markNeedsLayout(); + } + + // The width and color of the button's leading side border. + BorderSide get leadingBorderSide => _leadingBorderSide; + BorderSide _leadingBorderSide; + set leadingBorderSide(BorderSide value) { + if (_leadingBorderSide == value) { + return; + } + _leadingBorderSide = value; + markNeedsLayout(); + } + + // The width and color of the button's top and bottom side borders. + BorderSide get borderSide => _borderSide; + BorderSide _borderSide; + set borderSide(BorderSide value) { + if (_borderSide == value) { + return; + } + _borderSide = value; + markNeedsLayout(); + } + + // The width and color of the button's trailing side border. + BorderSide get trailingBorderSide => _trailingBorderSide; + BorderSide _trailingBorderSide; + set trailingBorderSide(BorderSide value) { + if (_trailingBorderSide == value) { + return; + } + _trailingBorderSide = value; + markNeedsLayout(); + } + + // The border radii of each corner of the button. + BorderRadius get borderRadius => _borderRadius; + BorderRadius _borderRadius; + set borderRadius(BorderRadius value) { + if (_borderRadius == value) { + return; + } + _borderRadius = value; + markNeedsLayout(); + } + + // Whether or not this toggle button is the first button in the list. + bool get isFirstButton => _isFirstButton; + bool _isFirstButton; + set isFirstButton(bool value) { + if (_isFirstButton == value) { + return; + } + _isFirstButton = value; + markNeedsLayout(); + } + + // Whether or not this toggle button is the last button in the list. + bool get isLastButton => _isLastButton; + bool _isLastButton; + set isLastButton(bool value) { + if (_isLastButton == value) { + return; + } + _isLastButton = value; + markNeedsLayout(); + } + + // The direction in which text flows for this application. + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsLayout(); + } + + static double _maxHeight(RenderBox? box, double width) { + return box == null ? 0.0 : box.getMaxIntrinsicHeight(width); + } + + static double _minHeight(RenderBox? box, double width) { + return box == null ? 0.0 : box.getMinIntrinsicHeight(width); + } + + static double _minWidth(RenderBox? box, double height) { + return box == null ? 0.0 : box.getMinIntrinsicWidth(height); + } + + static double _maxWidth(RenderBox? box, double height) { + return box == null ? 0.0 : box.getMaxIntrinsicWidth(height); + } + + @override + double computeDistanceToActualBaseline(TextBaseline baseline) { + // The baseline of this widget is the baseline of its child + return direction == Axis.horizontal + ? child!.computeDistanceToActualBaseline(baseline)! + borderSide.width + : child!.computeDistanceToActualBaseline(baseline)! + leadingBorderSide.width; + } + + @override + double computeMaxIntrinsicHeight(double width) { + return direction == Axis.horizontal + ? borderSide.width * 2.0 + _maxHeight(child, width) + : leadingBorderSide.width + _maxHeight(child, width) + trailingBorderSide.width; + } + + @override + double computeMinIntrinsicHeight(double width) { + return direction == Axis.horizontal + ? borderSide.width * 2.0 + _minHeight(child, width) + : leadingBorderSide.width + _maxHeight(child, width) + trailingBorderSide.width; + } + + @override + double computeMaxIntrinsicWidth(double height) { + return direction == Axis.horizontal + ? leadingBorderSide.width + _maxWidth(child, height) + trailingBorderSide.width + : borderSide.width * 2.0 + _maxWidth(child, height); + } + + @override + double computeMinIntrinsicWidth(double height) { + return direction == Axis.horizontal + ? leadingBorderSide.width + _minWidth(child, height) + trailingBorderSide.width + : borderSide.width * 2.0 + _minWidth(child, height); + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.dryLayoutChild, + ); + } + + @override + void performLayout() { + size = _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.layoutChild, + ); + if (child == null) { + return; + } + final BoxParentData childParentData = child!.parentData! as BoxParentData; + if (direction == Axis.horizontal) { + switch (textDirection) { + case TextDirection.ltr: + childParentData.offset = Offset(leadingBorderSide.width, borderSide.width); + case TextDirection.rtl: + childParentData.offset = Offset(trailingBorderSide.width, borderSide.width); + } + } else { + switch (verticalDirection) { + case VerticalDirection.down: + childParentData.offset = Offset(borderSide.width, leadingBorderSide.width); + case VerticalDirection.up: + childParentData.offset = Offset(borderSide.width, trailingBorderSide.width); + } + } + } + + Size _computeSize({required BoxConstraints constraints, required ChildLayouter layoutChild}) { + if (child == null) { + if (direction == Axis.horizontal) { + return constraints.constrain(Size( + leadingBorderSide.width + trailingBorderSide.width, + borderSide.width * 2.0, + )); + } else { + return constraints.constrain(Size( + borderSide.width * 2.0, + leadingBorderSide.width + trailingBorderSide.width, + )); + } + } + + final double leftConstraint; + final double rightConstraint; + final double topConstraint; + final double bottomConstraint; + + // It does not matter what [textDirection] or [verticalDirection] is, + // since deflating the size constraints horizontally/vertically + // and the returned size accounts for the width of both sides. + if (direction == Axis.horizontal) { + rightConstraint = trailingBorderSide.width; + leftConstraint = leadingBorderSide.width; + topConstraint = borderSide.width; + bottomConstraint = borderSide.width; + } else { + rightConstraint = borderSide.width; + leftConstraint = borderSide.width; + topConstraint = leadingBorderSide.width; + bottomConstraint = trailingBorderSide.width; + } + final BoxConstraints innerConstraints = constraints.deflate( + EdgeInsets.only( + left: leftConstraint, + top: topConstraint, + right: rightConstraint, + bottom: bottomConstraint, + ), + ); + final Size childSize = layoutChild(child!, innerConstraints); + + return constraints.constrain(Size( + leftConstraint + childSize.width + rightConstraint, + topConstraint + childSize.height + bottomConstraint, + )); + } + + @override + void paint(PaintingContext context, Offset offset) { + super.paint(context, offset); + final Offset bottomRight = size.bottomRight(offset); + final Rect outer = Rect.fromLTRB(offset.dx, offset.dy, bottomRight.dx, bottomRight.dy); + final Rect center = outer.deflate(borderSide.width / 2.0); + const double sweepAngle = math.pi / 2.0; + final RRect rrect = RRect.fromRectAndCorners( + center, + topLeft: (borderRadius.topLeft.x * borderRadius.topLeft.y != 0.0) ? borderRadius.topLeft : Radius.zero, + topRight: (borderRadius.topRight.x * borderRadius.topRight.y != 0.0) ? borderRadius.topRight : Radius.zero, + bottomLeft: (borderRadius.bottomLeft.x * borderRadius.bottomLeft.y != 0.0) ? borderRadius.bottomLeft : Radius.zero, + bottomRight: (borderRadius.bottomRight.x * borderRadius.bottomRight.y != 0.0) ? borderRadius.bottomRight : Radius.zero, + ).scaleRadii(); + + final Rect tlCorner = Rect.fromLTWH( + rrect.left, + rrect.top, + rrect.tlRadiusX * 2.0, + rrect.tlRadiusY * 2.0, + ); + final Rect blCorner = Rect.fromLTWH( + rrect.left, + rrect.bottom - (rrect.blRadiusY * 2.0), + rrect.blRadiusX * 2.0, + rrect.blRadiusY * 2.0, + ); + final Rect trCorner = Rect.fromLTWH( + rrect.right - (rrect.trRadiusX * 2), + rrect.top, + rrect.trRadiusX * 2, + rrect.trRadiusY * 2, + ); + final Rect brCorner = Rect.fromLTWH( + rrect.right - (rrect.brRadiusX * 2), + rrect.bottom - (rrect.brRadiusY * 2), + rrect.brRadiusX * 2, + rrect.brRadiusY * 2, + ); + + final Paint leadingPaint = leadingBorderSide.toPaint(); + // Only one button. + if (isFirstButton && isLastButton) { + final Path leadingPath = Path(); + final double startX = (rrect.brRadiusX == 0.0) ? outer.right : rrect.right - rrect.brRadiusX; + leadingPath..moveTo(startX, rrect.bottom) + ..lineTo(rrect.left + rrect.blRadiusX, rrect.bottom) + ..addArc(blCorner, math.pi / 2.0, sweepAngle) + ..lineTo(rrect.left, rrect.top + rrect.tlRadiusY) + ..addArc(tlCorner, math.pi, sweepAngle) + ..lineTo(rrect.right - rrect.trRadiusX, rrect.top) + ..addArc(trCorner, math.pi * 3.0 / 2.0, sweepAngle) + ..lineTo(rrect.right, rrect.bottom - rrect.brRadiusY) + ..addArc(brCorner, 0, sweepAngle); + context.canvas.drawPath(leadingPath, leadingPaint); + return; + } + + if (direction == Axis.horizontal) { + switch (textDirection) { + case TextDirection.ltr: + if (isLastButton) { + final Path leftPath = Path(); + leftPath..moveTo(rrect.left, rrect.bottom + leadingBorderSide.width / 2) + ..lineTo(rrect.left, rrect.top - leadingBorderSide.width / 2); + context.canvas.drawPath(leftPath, leadingPaint); + + final Paint endingPaint = trailingBorderSide.toPaint(); + final Path endingPath = Path(); + endingPath..moveTo(rrect.left + borderSide.width / 2.0, rrect.top) + ..lineTo(rrect.right - rrect.trRadiusX, rrect.top) + ..addArc(trCorner, math.pi * 3.0 / 2.0, sweepAngle) + ..lineTo(rrect.right, rrect.bottom - rrect.brRadiusY) + ..addArc(brCorner, 0, sweepAngle) + ..lineTo(rrect.left + borderSide.width / 2.0, rrect.bottom); + context.canvas.drawPath(endingPath, endingPaint); + } else if (isFirstButton) { + final Path leadingPath = Path(); + leadingPath..moveTo(outer.right, rrect.bottom) + ..lineTo(rrect.left + rrect.blRadiusX, rrect.bottom) + ..addArc(blCorner, math.pi / 2.0, sweepAngle) + ..lineTo(rrect.left, rrect.top + rrect.tlRadiusY) + ..addArc(tlCorner, math.pi, sweepAngle) + ..lineTo(outer.right, rrect.top); + context.canvas.drawPath(leadingPath, leadingPaint); + } else { + final Path leadingPath = Path(); + leadingPath..moveTo(rrect.left, rrect.bottom + leadingBorderSide.width / 2) + ..lineTo(rrect.left, rrect.top - leadingBorderSide.width / 2); + context.canvas.drawPath(leadingPath, leadingPaint); + + final Paint horizontalPaint = borderSide.toPaint(); + final Path horizontalPaths = Path(); + horizontalPaths..moveTo(rrect.left + borderSide.width / 2.0, rrect.top) + ..lineTo(outer.right - rrect.trRadiusX, rrect.top) + ..moveTo(rrect.left + borderSide.width / 2.0 + rrect.tlRadiusX, rrect.bottom) + ..lineTo(outer.right - rrect.trRadiusX, rrect.bottom); + context.canvas.drawPath(horizontalPaths, horizontalPaint); + } + case TextDirection.rtl: + if (isLastButton) { + final Path leadingPath = Path(); + leadingPath..moveTo(rrect.right, rrect.bottom + leadingBorderSide.width / 2) + ..lineTo(rrect.right, rrect.top - leadingBorderSide.width / 2); + context.canvas.drawPath(leadingPath, leadingPaint); + + final Paint endingPaint = trailingBorderSide.toPaint(); + final Path endingPath = Path(); + endingPath..moveTo(rrect.right - borderSide.width / 2.0, rrect.top) + ..lineTo(rrect.left + rrect.tlRadiusX, rrect.top) + ..addArc(tlCorner, math.pi * 3.0 / 2.0, -sweepAngle) + ..lineTo(rrect.left, rrect.bottom - rrect.blRadiusY) + ..addArc(blCorner, math.pi, -sweepAngle) + ..lineTo(rrect.right - borderSide.width / 2.0, rrect.bottom); + context.canvas.drawPath(endingPath, endingPaint); + } else if (isFirstButton) { + final Path leadingPath = Path(); + leadingPath..moveTo(outer.left, rrect.bottom) + ..lineTo(rrect.right - rrect.brRadiusX, rrect.bottom) + ..addArc(brCorner, math.pi / 2.0, -sweepAngle) + ..lineTo(rrect.right, rrect.top + rrect.trRadiusY) + ..addArc(trCorner, 0, -sweepAngle) + ..lineTo(outer.left, rrect.top); + context.canvas.drawPath(leadingPath, leadingPaint); + } else { + final Path leadingPath = Path(); + leadingPath..moveTo(rrect.right, rrect.bottom + leadingBorderSide.width / 2) + ..lineTo(rrect.right, rrect.top - leadingBorderSide.width / 2); + context.canvas.drawPath(leadingPath, leadingPaint); + + final Paint horizontalPaint = borderSide.toPaint(); + final Path horizontalPaths = Path(); + horizontalPaths..moveTo(rrect.right - borderSide.width / 2.0, rrect.top) + ..lineTo(outer.left - rrect.tlRadiusX, rrect.top) + ..moveTo(rrect.right - borderSide.width / 2.0 + rrect.trRadiusX, rrect.bottom) + ..lineTo(outer.left - rrect.tlRadiusX, rrect.bottom); + context.canvas.drawPath(horizontalPaths, horizontalPaint); + } + } + } else { + switch (verticalDirection) { + case VerticalDirection.down: + if (isLastButton) { + final Path topPath = Path(); + topPath..moveTo(outer.left, outer.top + leadingBorderSide.width / 2) + ..lineTo(outer.right, outer.top + leadingBorderSide.width / 2); + context.canvas.drawPath(topPath, leadingPaint); + + final Paint endingPaint = trailingBorderSide.toPaint(); + final Path endingPath = Path(); + endingPath..moveTo(rrect.left, rrect.top + leadingBorderSide.width / 2.0) + ..lineTo(rrect.left, rrect.bottom - rrect.blRadiusY) + ..addArc(blCorner, math.pi * 3.0, -sweepAngle) + ..lineTo(rrect.right - rrect.blRadiusX, rrect.bottom) + ..addArc(brCorner, math.pi / 2.0, -sweepAngle) + ..lineTo(rrect.right, rrect.top + leadingBorderSide.width / 2.0); + context.canvas.drawPath(endingPath, endingPaint); + } else if (isFirstButton) { + final Path leadingPath = Path(); + leadingPath..moveTo(rrect.left, outer.bottom) + ..lineTo(rrect.left, rrect.top + rrect.tlRadiusX) + ..addArc(tlCorner, math.pi, sweepAngle) + ..lineTo(rrect.right - rrect.trRadiusX, rrect.top) + ..addArc(trCorner, math.pi * 3.0 / 2.0, sweepAngle) + ..lineTo(rrect.right, outer.bottom); + context.canvas.drawPath(leadingPath, leadingPaint); + } else { + final Path topPath = Path(); + topPath..moveTo(outer.left, outer.top + leadingBorderSide.width / 2) + ..lineTo(outer.right, outer.top + leadingBorderSide.width / 2); + context.canvas.drawPath(topPath, leadingPaint); + + final Paint paint = borderSide.toPaint(); + final Path paths = Path(); // Left and right borders. + paths..moveTo(rrect.left, outer.top + leadingBorderSide.width) + ..lineTo(rrect.left, outer.bottom) + ..moveTo(rrect.right, outer.top + leadingBorderSide.width) + ..lineTo(rrect.right, outer.bottom); + context.canvas.drawPath(paths, paint); + } + case VerticalDirection.up: + if (isLastButton) { + final Path bottomPath = Path(); + bottomPath..moveTo(outer.left, outer.bottom - leadingBorderSide.width / 2.0) + ..lineTo(outer.right, outer.bottom - leadingBorderSide.width / 2.0); + context.canvas.drawPath(bottomPath, leadingPaint); + + final Paint endingPaint = trailingBorderSide.toPaint(); + final Path endingPath = Path(); + endingPath..moveTo(rrect.left, rrect.bottom - leadingBorderSide.width / 2.0) + ..lineTo(rrect.left, rrect.top + rrect.tlRadiusY) + ..addArc(tlCorner, math.pi, sweepAngle) + ..lineTo(rrect.right - rrect.trRadiusX, rrect.top) + ..addArc(trCorner, math.pi * 3.0 / 2.0, sweepAngle) + ..lineTo(rrect.right, rrect.bottom - leadingBorderSide.width / 2.0); + context.canvas.drawPath(endingPath, endingPaint); + } else if (isFirstButton) { + final Path leadingPath = Path(); + leadingPath..moveTo(rrect.left, outer.top) + ..lineTo(rrect.left, rrect.bottom - rrect.blRadiusY) + ..addArc(blCorner, math.pi, -sweepAngle) + ..lineTo(rrect.right - rrect.brRadiusX, rrect.bottom) + ..addArc(brCorner, math.pi / 2.0, -sweepAngle) + ..lineTo(rrect.right, outer.top); + context.canvas.drawPath(leadingPath, leadingPaint); + } else { + final Path bottomPath = Path(); + bottomPath..moveTo(outer.left, outer.bottom - leadingBorderSide.width / 2.0) + ..lineTo(outer.right, outer.bottom - leadingBorderSide.width / 2.0); + context.canvas.drawPath(bottomPath, leadingPaint); + + final Paint paint = borderSide.toPaint(); + final Path paths = Path(); // Left and right borders. + paths..moveTo(rrect.left, outer.top) + ..lineTo(rrect.left, outer.bottom - leadingBorderSide.width) + ..moveTo(rrect.right, outer.top) + ..lineTo(rrect.right, outer.bottom - leadingBorderSide.width); + context.canvas.drawPath(paths, paint); + } + } + } + } +} + +/// A widget to pad the area around a [ToggleButtons]'s children. +/// +/// This widget is based on a similar one used in [ButtonStyleButton] but it +/// only redirects taps along one axis to ensure the correct button is tapped +/// within the [ToggleButtons]. +/// +/// This ensures that a widget takes up at least as much space as the minSize +/// parameter to ensure adequate tap target size, while keeping the widget +/// visually smaller to the user. +class _InputPadding extends SingleChildRenderObjectWidget { + const _InputPadding({ + super.child, + required this.minSize, + required this.direction, + }); + + final Size minSize; + final Axis direction; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderInputPadding(minSize, direction); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderInputPadding renderObject) { + renderObject.minSize = minSize; + renderObject.direction = direction; + } +} + +class _RenderInputPadding extends RenderShiftedBox { + _RenderInputPadding(this._minSize, this._direction, [RenderBox? child]) : super(child); + + Size get minSize => _minSize; + Size _minSize; + set minSize(Size value) { + if (_minSize == value) { + return; + } + _minSize = value; + markNeedsLayout(); + } + + Axis get direction => _direction; + Axis _direction; + set direction(Axis value) { + if (_direction == value) { + return; + } + _direction = value; + markNeedsLayout(); + } + + @override + double computeMinIntrinsicWidth(double height) { + if (child != null) { + return math.max(child!.getMinIntrinsicWidth(height), minSize.width); + } + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + if (child != null) { + return math.max(child!.getMinIntrinsicHeight(width), minSize.height); + } + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (child != null) { + return math.max(child!.getMaxIntrinsicWidth(height), minSize.width); + } + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (child != null) { + return math.max(child!.getMaxIntrinsicHeight(width), minSize.height); + } + return 0.0; + } + + Size _computeSize({required BoxConstraints constraints, required ChildLayouter layoutChild}) { + if (child != null) { + final Size childSize = layoutChild(child!, constraints); + final double height = math.max(childSize.width, minSize.width); + final double width = math.max(childSize.height, minSize.height); + return constraints.constrain(Size(height, width)); + } + return Size.zero; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + return _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.dryLayoutChild, + ); + } + + @override + void performLayout() { + size = _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.layoutChild, + ); + if (child != null) { + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = Alignment.center.alongOffset(size - child!.size as Offset); + } + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + // The super.hitTest() method also checks hitTestChildren(). We don't + // want that in this case because we've padded around the children per + // tapTargetSize. + if (!size.contains(position)) { + return false; + } + + // Only adjust one axis to ensure the correct button is tapped. + Offset center; + if (direction == Axis.horizontal) { + center = Offset(position.dx, child!.size.height / 2); + } else { + center = Offset(child!.size.width / 2, position.dy); + } + return result.addWithRawTransform( + transform: MatrixUtils.forceToPoint(center), + position: center, + hitTest: (BoxHitTestResult result, Offset position) { + assert(position == center); + return child!.hitTest(result, position: center); + }, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/toggle_buttons_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/toggle_buttons_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..24dbaa7aa1f536c8c75ba8fc0f4b9dbc753e0836 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/toggle_buttons_theme.dart @@ -0,0 +1,280 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines the color and border properties of [ToggleButtons] widgets. +/// +/// Used by [ToggleButtonsTheme] to control the color and border properties +/// of toggle buttons in a widget subtree. +/// +/// To obtain the current [ToggleButtonsTheme], use [ToggleButtonsTheme.of]. +/// +/// Values specified here are used for [ToggleButtons] properties that are not +/// given an explicit non-null value. +/// +/// See also: +/// +/// * [ToggleButtonsTheme], which describes the actual configuration of a +/// toggle buttons theme. +@immutable +class ToggleButtonsThemeData with Diagnosticable { + /// Creates the set of color and border properties used to configure + /// [ToggleButtons]. + const ToggleButtonsThemeData({ + this.textStyle, + this.constraints, + this.color, + this.selectedColor, + this.disabledColor, + this.fillColor, + this.focusColor, + this.highlightColor, + this.hoverColor, + this.splashColor, + this.borderColor, + this.selectedBorderColor, + this.disabledBorderColor, + this.borderRadius, + this.borderWidth, + }); + + /// The default text style for [ToggleButtons.children]. + /// + /// [TextStyle.color] will be ignored and substituted by [color], + /// [selectedColor] or [disabledColor] depending on whether the buttons + /// are active, selected, or disabled. + final TextStyle? textStyle; + + /// Defines the button's size. + /// + /// Typically used to constrain the button's minimum size. + final BoxConstraints? constraints; + + /// The color for descendant [Text] and [Icon] widgets if the toggle button + /// is enabled. + final Color? color; + + /// The color for descendant [Text] and [Icon] widgets if the toggle button + /// is selected. + final Color? selectedColor; + + /// The color for descendant [Text] and [Icon] widgets if the toggle button + /// is disabled. + final Color? disabledColor; + + /// The fill color for selected toggle buttons. + final Color? fillColor; + + /// The color to use for filling the button when the button has input focus. + final Color? focusColor; + + /// The highlight color for the toggle button's [InkWell]. + final Color? highlightColor; + + /// The splash color for the toggle button's [InkWell]. + final Color? splashColor; + + /// The color to use for filling the toggle button when the button has a + /// pointer hovering over it. + final Color? hoverColor; + + /// The border color to display when the toggle button is enabled. + final Color? borderColor; + + /// The border color to display when the toggle button is selected. + final Color? selectedBorderColor; + + /// The border color to display when the toggle button is disabled. + final Color? disabledBorderColor; + + /// The width of the border surrounding each toggle button. + /// + /// This applies to both the greater surrounding border, as well as the + /// borders dividing each toggle button. + /// + /// To render a hairline border (one physical pixel), set borderWidth to 0.0. + /// See [BorderSide.width] for more details on hairline borders. + final double? borderWidth; + + /// The radii of the border's corners. + final BorderRadius? borderRadius; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + ToggleButtonsThemeData copyWith({ + TextStyle? textStyle, + BoxConstraints? constraints, + Color? color, + Color? selectedColor, + Color? disabledColor, + Color? fillColor, + Color? focusColor, + Color? highlightColor, + Color? hoverColor, + Color? splashColor, + Color? borderColor, + Color? selectedBorderColor, + Color? disabledBorderColor, + BorderRadius? borderRadius, + double? borderWidth, + }) { + return ToggleButtonsThemeData( + textStyle: textStyle ?? this.textStyle, + constraints: constraints ?? this.constraints, + color: color ?? this.color, + selectedColor: selectedColor ?? this.selectedColor, + disabledColor: disabledColor ?? this.disabledColor, + fillColor: fillColor ?? this.fillColor, + focusColor: focusColor ?? this.focusColor, + highlightColor: highlightColor ?? this.highlightColor, + hoverColor: hoverColor ?? this.hoverColor, + splashColor: splashColor ?? this.splashColor, + borderColor: borderColor ?? this.borderColor, + selectedBorderColor: selectedBorderColor ?? this.selectedBorderColor, + disabledBorderColor: disabledBorderColor ?? this.disabledBorderColor, + borderRadius: borderRadius ?? this.borderRadius, + borderWidth: borderWidth ?? this.borderWidth, + ); + } + + /// Linearly interpolate between two toggle buttons themes. + static ToggleButtonsThemeData? lerp(ToggleButtonsThemeData? a, ToggleButtonsThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return ToggleButtonsThemeData( + textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t), + constraints: BoxConstraints.lerp(a?.constraints, b?.constraints, t), + color: Color.lerp(a?.color, b?.color, t), + selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t), + disabledColor: Color.lerp(a?.disabledColor, b?.disabledColor, t), + fillColor: Color.lerp(a?.fillColor, b?.fillColor, t), + focusColor: Color.lerp(a?.focusColor, b?.focusColor, t), + highlightColor: Color.lerp(a?.highlightColor, b?.highlightColor, t), + hoverColor: Color.lerp(a?.hoverColor, b?.hoverColor, t), + splashColor: Color.lerp(a?.splashColor, b?.splashColor, t), + borderColor: Color.lerp(a?.borderColor, b?.borderColor, t), + selectedBorderColor: Color.lerp(a?.selectedBorderColor, b?.selectedBorderColor, t), + disabledBorderColor: Color.lerp(a?.disabledBorderColor, b?.disabledBorderColor, t), + borderRadius: BorderRadius.lerp(a?.borderRadius, b?.borderRadius, t), + borderWidth: lerpDouble(a?.borderWidth, b?.borderWidth, t), + ); + } + + @override + int get hashCode => Object.hash( + textStyle, + constraints, + color, + selectedColor, + disabledColor, + fillColor, + focusColor, + highlightColor, + hoverColor, + splashColor, + borderColor, + selectedBorderColor, + disabledBorderColor, + borderRadius, + borderWidth, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ToggleButtonsThemeData + && other.textStyle == textStyle + && other.constraints == constraints + && other.color == color + && other.selectedColor == selectedColor + && other.disabledColor == disabledColor + && other.fillColor == fillColor + && other.focusColor == focusColor + && other.highlightColor == highlightColor + && other.hoverColor == hoverColor + && other.splashColor == splashColor + && other.borderColor == borderColor + && other.selectedBorderColor == selectedBorderColor + && other.disabledBorderColor == disabledBorderColor + && other.borderRadius == borderRadius + && other.borderWidth == borderWidth; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + textStyle?.debugFillProperties(properties, prefix: 'textStyle.'); + properties.add(DiagnosticsProperty<BoxConstraints>('constraints', constraints, defaultValue: null)); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(ColorProperty('selectedColor', selectedColor, defaultValue: null)); + properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: null)); + properties.add(ColorProperty('fillColor', fillColor, defaultValue: null)); + properties.add(ColorProperty('focusColor', focusColor, defaultValue: null)); + properties.add(ColorProperty('highlightColor', highlightColor, defaultValue: null)); + properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: null)); + properties.add(ColorProperty('splashColor', splashColor, defaultValue: null)); + properties.add(ColorProperty('borderColor', borderColor, defaultValue: null)); + properties.add(ColorProperty('selectedBorderColor', selectedBorderColor, defaultValue: null)); + properties.add(ColorProperty('disabledBorderColor', disabledBorderColor, defaultValue: null)); + properties.add(DiagnosticsProperty<BorderRadius>('borderRadius', borderRadius, defaultValue: null)); + properties.add(DoubleProperty('borderWidth', borderWidth, defaultValue: null)); + } +} + +/// An inherited widget that defines color and border parameters for +/// [ToggleButtons] in this widget's subtree. +/// +/// Values specified here are used for [ToggleButtons] properties that are not +/// given an explicit non-null value. +class ToggleButtonsTheme extends InheritedTheme { + /// Creates a toggle buttons theme that controls the color and border + /// parameters for [ToggleButtons]. + const ToggleButtonsTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Specifies the color and border values for descendant [ToggleButtons] widgets. + final ToggleButtonsThemeData data; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [ToggleButtonsTheme] widget, then + /// [ThemeData.toggleButtonsTheme] is used. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ToggleButtonsThemeData theme = ToggleButtonsTheme.of(context); + /// ``` + static ToggleButtonsThemeData of(BuildContext context) { + final ToggleButtonsTheme? toggleButtonsTheme = context.dependOnInheritedWidgetOfExactType<ToggleButtonsTheme>(); + return toggleButtonsTheme?.data ?? Theme.of(context).toggleButtonsTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return ToggleButtonsTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(ToggleButtonsTheme oldWidget) => data != oldWidget.data; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/toggleable.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/toggleable.dart new file mode 100644 index 0000000000000000000000000000000000000000..ecf19d37e4576f7c3303d48274a8e98be3b7b8a9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/toggleable.dart @@ -0,0 +1,598 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +import 'constants.dart'; +import 'material_state.dart'; + +// Duration of the animation that moves the toggle from one state to another. +const Duration _kToggleDuration = Duration(milliseconds: 200); + +// Duration of the fade animation for the reaction when focus and hover occur. +const Duration _kReactionFadeDuration = Duration(milliseconds: 50); + +/// A mixin for [StatefulWidget]s that implement material-themed toggleable +/// controls with toggle animations (e.g. [Switch]es, [Checkbox]es, and +/// [Radio]s). +/// +/// The mixin implements the logic for toggling the control (e.g. when tapped) +/// and provides a series of animation controllers to transition the control +/// from one state to another. It does not have any opinion about the visual +/// representation of the toggleable widget. The visuals are defined by a +/// [CustomPainter] passed to the [buildToggleable]. [State] objects using this +/// mixin should call that method from their [build] method. +/// +/// This mixin is used to implement the material components for [Switch], +/// [Checkbox], and [Radio] controls. +@optionalTypeArgs +mixin ToggleableStateMixin<S extends StatefulWidget> on TickerProviderStateMixin<S> { + /// Used by subclasses to manipulate the visual value of the control. + /// + /// Some controls respond to user input by updating their visual value. For + /// example, the thumb of a switch moves from one position to another when + /// dragged. These controls manipulate this animation controller to update + /// their [position] and eventually trigger an [onChanged] callback when the + /// animation reaches either 0.0 or 1.0. + AnimationController get positionController => _positionController; + late AnimationController _positionController; + + /// The visual value of the control. + /// + /// When the control is inactive, the [value] is false and this animation has + /// the value 0.0. When the control is active, the value is either true or + /// tristate is true and the value is null. When the control is active the + /// animation has a value of 1.0. When the control is changing from inactive + /// to active (or vice versa), [value] is the target value and this animation + /// gradually updates from 0.0 to 1.0 (or vice versa). + CurvedAnimation get position => _position; + late CurvedAnimation _position; + + /// Used by subclasses to control the radial reaction animation. + /// + /// Some controls have a radial ink reaction to user input. This animation + /// controller can be used to start or stop these ink reactions. + /// + /// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction] + /// may be used. + AnimationController get reactionController => _reactionController; + late AnimationController _reactionController; + + /// The visual value of the radial reaction animation. + /// + /// Some controls have a radial ink reaction to user input. This animation + /// controls the progress of these ink reactions. + /// + /// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction] + /// may be used. + Animation<double> get reaction => _reaction; + late Animation<double> _reaction; + + /// Controls the radial reaction's opacity animation for hover changes. + /// + /// Some controls have a radial ink reaction to pointer hover. This animation + /// controls these ink reaction fade-ins and + /// fade-outs. + /// + /// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction] + /// may be used. + Animation<double> get reactionHoverFade => _reactionHoverFade; + late Animation<double> _reactionHoverFade; + late AnimationController _reactionHoverFadeController; + + /// Controls the radial reaction's opacity animation for focus changes. + /// + /// Some controls have a radial ink reaction to focus. This animation + /// controls these ink reaction fade-ins and fade-outs. + /// + /// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction] + /// may be used. + Animation<double> get reactionFocusFade => _reactionFocusFade; + late Animation<double> _reactionFocusFade; + late AnimationController _reactionFocusFadeController; + + /// Whether [value] of this control can be changed by user interaction. + /// + /// The control is considered interactive if the [onChanged] callback is + /// non-null. If the callback is null, then the control is disabled, and + /// non-interactive. A disabled checkbox, for example, is displayed using a + /// grey color and its value cannot be changed. + bool get isInteractive => onChanged != null; + + late final Map<Type, Action<Intent>> _actionMap = <Type, Action<Intent>>{ + ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: _handleTap), + }; + + /// Called when the control changes value. + /// + /// If the control is tapped, [onChanged] is called immediately with the new + /// value. + /// + /// The control is considered interactive (see [isInteractive]) if this + /// callback is non-null. If the callback is null, then the control is + /// disabled, and non-interactive. A disabled checkbox, for example, is + /// displayed using a grey color and its value cannot be changed. + ValueChanged<bool?>? get onChanged; + + /// False if this control is "inactive" (not checked, off, or unselected). + /// + /// If value is true then the control "active" (checked, on, or selected). If + /// tristate is true and value is null, then the control is considered to be + /// in its third or "indeterminate" state. + /// + /// When the value changes, this object starts the [positionController] and + /// [position] animations to animate the visual appearance of the control to + /// the new value. + bool? get value; + + /// If true, [value] can be true, false, or null, otherwise [value] must + /// be true or false. + /// + /// When [tristate] is true and [value] is null, then the control is + /// considered to be in its third or "indeterminate" state. + bool get tristate; + + @override + void initState() { + super.initState(); + _positionController = AnimationController( + duration: _kToggleDuration, + value: value == false ? 0.0 : 1.0, + vsync: this, + ); + _position = CurvedAnimation( + parent: _positionController, + curve: Curves.easeIn, + reverseCurve: Curves.easeOut, + ); + _reactionController = AnimationController( + duration: kRadialReactionDuration, + vsync: this, + ); + _reaction = CurvedAnimation( + parent: _reactionController, + curve: Curves.fastOutSlowIn, + ); + _reactionHoverFadeController = AnimationController( + duration: _kReactionFadeDuration, + value: _hovering || _focused ? 1.0 : 0.0, + vsync: this, + ); + _reactionHoverFade = CurvedAnimation( + parent: _reactionHoverFadeController, + curve: Curves.fastOutSlowIn, + ); + _reactionFocusFadeController = AnimationController( + duration: _kReactionFadeDuration, + value: _hovering || _focused ? 1.0 : 0.0, + vsync: this, + ); + _reactionFocusFade = CurvedAnimation( + parent: _reactionFocusFadeController, + curve: Curves.fastOutSlowIn, + ); + } + + /// Runs the [position] animation to transition the Toggleable's appearance + /// to match [value]. + /// + /// This method must be called whenever [value] changes to ensure that the + /// visual representation of the Toggleable matches the current [value]. + void animateToValue() { + if (tristate) { + if (value == null) { + _positionController.value = 0.0; + } + if (value ?? true) { + _positionController.forward(); + } else { + _positionController.reverse(); + } + } else { + if (value ?? false) { + _positionController.forward(); + } else { + _positionController.reverse(); + } + } + } + + @override + void dispose() { + _positionController.dispose(); + _reactionController.dispose(); + _reactionHoverFadeController.dispose(); + _reactionFocusFadeController.dispose(); + super.dispose(); + } + + /// The most recent [Offset] at which a pointer touched the Toggleable. + /// + /// This is null if currently no pointer is touching the Toggleable or if + /// [isInteractive] is false. + Offset? get downPosition => _downPosition; + Offset? _downPosition; + + void _handleTapDown(TapDownDetails details) { + if (isInteractive) { + setState(() { + _downPosition = details.localPosition; + }); + _reactionController.forward(); + } + } + + void _handleTap([Intent? _]) { + if (!isInteractive) { + return; + } + switch (value) { + case false: + onChanged!(true); + case true: + onChanged!(tristate ? null : false); + case null: + onChanged!(false); + } + context.findRenderObject()!.sendSemanticsEvent(const TapSemanticEvent()); + } + + void _handleTapEnd([TapUpDetails? _]) { + if (_downPosition != null) { + setState(() { _downPosition = null; }); + } + _reactionController.reverse(); + } + + bool _focused = false; + void _handleFocusHighlightChanged(bool focused) { + if (focused != _focused) { + setState(() { _focused = focused; }); + if (focused) { + _reactionFocusFadeController.forward(); + } else { + _reactionFocusFadeController.reverse(); + } + } + } + + bool _hovering = false; + void _handleHoverChanged(bool hovering) { + if (hovering != _hovering) { + setState(() { _hovering = hovering; }); + if (hovering) { + _reactionHoverFadeController.forward(); + } else { + _reactionHoverFadeController.reverse(); + } + } + } + + /// Describes the current [MaterialState] of the Toggleable. + /// + /// The returned set will include: + /// + /// * [MaterialState.disabled], if [isInteractive] is false + /// * [MaterialState.hovered], if a pointer is hovering over the Toggleable + /// * [MaterialState.focused], if the Toggleable has input focus + /// * [MaterialState.selected], if [value] is true or null + Set<MaterialState> get states => <MaterialState>{ + if (!isInteractive) MaterialState.disabled, + if (_hovering) MaterialState.hovered, + if (_focused) MaterialState.focused, + if (value ?? true) MaterialState.selected, + }; + + /// Typically wraps a `painter` that draws the actual visuals of the + /// Toggleable with logic to toggle it. + /// + /// Consider providing a subclass of [ToggleablePainter] as a `painter`, which + /// implements logic to draw a radial ink reaction for this control. The + /// painter is usually configured with the [reaction], [position], + /// [reactionHoverFade], and [reactionFocusFade] animation provided by this + /// mixin. It is expected to draw the visuals of the Toggleable based on the + /// current value of these animations. The animations are triggered by + /// this mixin to transition the Toggleable from one state to another. + /// + /// This method must be called from the [build] method of the [State] class + /// that uses this mixin. The returned [Widget] must be returned from the + /// build method - potentially after wrapping it in other widgets. + Widget buildToggleable({ + FocusNode? focusNode, + ValueChanged<bool>? onFocusChange, + bool autofocus = false, + required MaterialStateProperty<MouseCursor> mouseCursor, + required Size size, + required CustomPainter painter, + }) { + return FocusableActionDetector( + actions: _actionMap, + focusNode: focusNode, + autofocus: autofocus, + onFocusChange: onFocusChange, + enabled: isInteractive, + onShowFocusHighlight: _handleFocusHighlightChanged, + onShowHoverHighlight: _handleHoverChanged, + mouseCursor: mouseCursor.resolve(states), + child: GestureDetector( + excludeFromSemantics: !isInteractive, + onTapDown: isInteractive ? _handleTapDown : null, + onTap: isInteractive ? _handleTap : null, + onTapUp: isInteractive ? _handleTapEnd : null, + onTapCancel: isInteractive ? _handleTapEnd : null, + child: Semantics( + enabled: isInteractive, + child: CustomPaint( + size: size, + painter: painter, + ), + ), + ), + ); + } +} + +/// A base class for a [CustomPainter] that may be passed to +/// [ToggleableStateMixin.buildToggleable] to draw the visual representation of +/// a Toggleable. +/// +/// Subclasses must implement the [paint] method to draw the actual visuals of +/// the Toggleable. In their [paint] method subclasses may call +/// [paintRadialReaction] to draw a radial ink reaction for this control. +abstract class ToggleablePainter extends ChangeNotifier implements CustomPainter { + /// The visual value of the control. + /// + /// Usually set to [ToggleableStateMixin.position]. + Animation<double> get position => _position!; + Animation<double>? _position; + set position(Animation<double> value) { + if (value == _position) { + return; + } + _position?.removeListener(notifyListeners); + value.addListener(notifyListeners); + _position = value; + notifyListeners(); + } + + /// The visual value of the radial reaction animation. + /// + /// Usually set to [ToggleableStateMixin.reaction]. + Animation<double> get reaction => _reaction!; + Animation<double>? _reaction; + set reaction(Animation<double> value) { + if (value == _reaction) { + return; + } + _reaction?.removeListener(notifyListeners); + value.addListener(notifyListeners); + _reaction = value; + notifyListeners(); + } + + /// Controls the radial reaction's opacity animation for focus changes. + /// + /// Usually set to [ToggleableStateMixin.reactionFocusFade]. + Animation<double> get reactionFocusFade => _reactionFocusFade!; + Animation<double>? _reactionFocusFade; + set reactionFocusFade(Animation<double> value) { + if (value == _reactionFocusFade) { + return; + } + _reactionFocusFade?.removeListener(notifyListeners); + value.addListener(notifyListeners); + _reactionFocusFade = value; + notifyListeners(); + } + + /// Controls the radial reaction's opacity animation for hover changes. + /// + /// Usually set to [ToggleableStateMixin.reactionHoverFade]. + Animation<double> get reactionHoverFade => _reactionHoverFade!; + Animation<double>? _reactionHoverFade; + set reactionHoverFade(Animation<double> value) { + if (value == _reactionHoverFade) { + return; + } + _reactionHoverFade?.removeListener(notifyListeners); + value.addListener(notifyListeners); + _reactionHoverFade = value; + notifyListeners(); + } + + /// The color that should be used in the active state (i.e., when + /// [ToggleableStateMixin.value] is true). + /// + /// For example, a checkbox should use this color when checked. + Color get activeColor => _activeColor!; + Color? _activeColor; + set activeColor(Color value) { + if (_activeColor == value) { + return; + } + _activeColor = value; + notifyListeners(); + } + + /// The color that should be used in the inactive state (i.e., when + /// [ToggleableStateMixin.value] is false). + /// + /// For example, a checkbox should use this color when unchecked. + Color get inactiveColor => _inactiveColor!; + Color? _inactiveColor; + set inactiveColor(Color value) { + if (_inactiveColor == value) { + return; + } + _inactiveColor = value; + notifyListeners(); + } + + /// The color that should be used for the reaction when the toggleable is + /// inactive. + /// + /// Used when the toggleable needs to change the reaction color/transparency + /// that is displayed when the toggleable is inactive and tapped. + Color get inactiveReactionColor => _inactiveReactionColor!; + Color? _inactiveReactionColor; + set inactiveReactionColor(Color value) { + if (value == _inactiveReactionColor) { + return; + } + _inactiveReactionColor = value; + notifyListeners(); + } + + /// The color that should be used for the reaction when the toggleable is + /// active. + /// + /// Used when the toggleable needs to change the reaction color/transparency + /// that is displayed when the toggleable is active and tapped. + Color get reactionColor => _reactionColor!; + Color? _reactionColor; + set reactionColor(Color value) { + if (value == _reactionColor) { + return; + } + _reactionColor = value; + notifyListeners(); + } + + /// The color that should be used for the reaction when [isHovered] is true. + /// + /// Used when the toggleable needs to change the reaction color/transparency, + /// when it is being hovered over. + Color get hoverColor => _hoverColor!; + Color? _hoverColor; + set hoverColor(Color value) { + if (value == _hoverColor) { + return; + } + _hoverColor = value; + notifyListeners(); + } + + /// The color that should be used for the reaction when [isFocused] is true. + /// + /// Used when the toggleable needs to change the reaction color/transparency, + /// when it has focus. + Color get focusColor => _focusColor!; + Color? _focusColor; + set focusColor(Color value) { + if (value == _focusColor) { + return; + } + _focusColor = value; + notifyListeners(); + } + + /// The splash radius for the radial reaction. + double get splashRadius => _splashRadius!; + double? _splashRadius; + set splashRadius(double value) { + if (value == _splashRadius) { + return; + } + _splashRadius = value; + notifyListeners(); + } + + /// The [Offset] within the Toggleable at which a pointer touched the Toggleable. + /// + /// This is null if currently no pointer is touching the Toggleable. + /// + /// Usually set to [ToggleableStateMixin.downPosition]. + Offset? get downPosition => _downPosition; + Offset? _downPosition; + set downPosition(Offset? value) { + if (value == _downPosition) { + return; + } + _downPosition = value; + notifyListeners(); + } + + /// True if this toggleable has the input focus. + bool get isFocused => _isFocused!; + bool? _isFocused; + set isFocused(bool? value) { + if (value == _isFocused) { + return; + } + _isFocused = value; + notifyListeners(); + } + + /// True if this toggleable is being hovered over by a pointer. + bool get isHovered => _isHovered!; + bool? _isHovered; + set isHovered(bool? value) { + if (value == _isHovered) { + return; + } + _isHovered = value; + notifyListeners(); + } + + /// Used by subclasses to paint the radial ink reaction for this control. + /// + /// The reaction is painted on the given canvas at the given offset. The + /// origin is the center point of the reaction (usually distinct from the + /// [downPosition] at which the user interacted with the control). + void paintRadialReaction({ + required Canvas canvas, + Offset offset = Offset.zero, + required Offset origin, + }) { + if (!reaction.isDismissed || !reactionFocusFade.isDismissed || !reactionHoverFade.isDismissed) { + final Paint reactionPaint = Paint() + ..color = Color.lerp( + Color.lerp( + Color.lerp(inactiveReactionColor, reactionColor, position.value), + hoverColor, + reactionHoverFade.value, + ), + focusColor, + reactionFocusFade.value, + )!; + final Animatable<double> radialReactionRadiusTween = Tween<double>( + begin: 0.0, + end: splashRadius, + ); + final double reactionRadius = isFocused || isHovered + ? splashRadius + : radialReactionRadiusTween.evaluate(reaction); + if (reactionRadius > 0.0) { + canvas.drawCircle(origin + offset, reactionRadius, reactionPaint); + } + } + } + + + @override + void dispose() { + _position?.removeListener(notifyListeners); + _reaction?.removeListener(notifyListeners); + _reactionFocusFade?.removeListener(notifyListeners); + _reactionHoverFade?.removeListener(notifyListeners); + super.dispose(); + } + + @override + bool shouldRepaint(covariant CustomPainter oldDelegate) => true; + + @override + bool? hitTest(Offset position) => null; + + @override + SemanticsBuilderCallback? get semanticsBuilder => null; + + @override + bool shouldRebuildSemantics(covariant CustomPainter oldDelegate) => false; + + @override + String toString() => describeIdentity(this); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tooltip.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tooltip.dart new file mode 100644 index 0000000000000000000000000000000000000000..cae3acf95282125128769f72b7ec2d40ac6371a5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tooltip.dart @@ -0,0 +1,986 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'feedback.dart'; +import 'text_theme.dart'; +import 'theme.dart'; +import 'tooltip_theme.dart'; +import 'tooltip_visibility.dart'; + +/// Signature for when a tooltip is triggered. +typedef TooltipTriggeredCallback = void Function(); + +/// A special [MouseRegion] that when nested, only the first [_ExclusiveMouseRegion] +/// to be hit in hit-testing order will be added to the BoxHitTestResult (i.e., +/// child over parent, last sibling over first sibling). +/// +/// The [onEnter] method will be called when a mouse pointer enters this +/// [MouseRegion], and there is no other [_ExclusiveMouseRegion]s obstructing +/// this [_ExclusiveMouseRegion] from receiving the events. This includes the +/// case where the mouse cursor stays within the paint bounds of an outer +/// [_ExclusiveMouseRegion], but moves outside of the bounds of the inner +/// [_ExclusiveMouseRegion] that was initially blocking the outer widget. +/// +/// Likewise, [onExit] is called when the a mouse pointer moves out of the paint +/// bounds of this widget, or moves into another [_ExclusiveMouseRegion] that +/// overlaps this widget in hit-testing order. +/// +/// This widget doesn't affect [MouseRegion]s that aren't [_ExclusiveMouseRegion]s, +/// or other [HitTestTarget]s in the tree. +class _ExclusiveMouseRegion extends MouseRegion { + const _ExclusiveMouseRegion({ + super.onEnter, + super.onExit, + super.child, + }); + + @override + _RenderExclusiveMouseRegion createRenderObject(BuildContext context) { + return _RenderExclusiveMouseRegion( + onEnter: onEnter, + onExit: onExit, + ); + } +} + +class _RenderExclusiveMouseRegion extends RenderMouseRegion { + _RenderExclusiveMouseRegion({ + super.onEnter, + super.onExit, + }); + + static bool isOutermostMouseRegion = true; + static bool foundInnermostMouseRegion = false; + + @override + bool hitTest(BoxHitTestResult result, {required Offset position}) { + bool isHit = false; + final bool outermost = isOutermostMouseRegion; + isOutermostMouseRegion = false; + if (size.contains(position)) { + isHit = hitTestChildren(result, position: position) || hitTestSelf(position); + if ((isHit || behavior == HitTestBehavior.translucent) && !foundInnermostMouseRegion) { + foundInnermostMouseRegion = true; + result.add(BoxHitTestEntry(this, position)); + } + } + + if (outermost) { + // The outermost region resets the global states. + isOutermostMouseRegion = true; + foundInnermostMouseRegion = false; + } + return isHit; + } +} + +/// A Material Design tooltip. +/// +/// Tooltips provide text labels which help explain the function of a button or +/// other user interface action. Wrap the button in a [Tooltip] widget and provide +/// a message which will be shown when the widget is long pressed. +/// +/// Many widgets, such as [IconButton], [FloatingActionButton], and +/// [PopupMenuButton] have a `tooltip` property that, when non-null, causes the +/// widget to include a [Tooltip] in its build. +/// +/// Tooltips improve the accessibility of visual widgets by proving a textual +/// representation of the widget, which, for example, can be vocalized by a +/// screen reader. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=EeEfD5fI-5Q} +/// +/// {@tool dartpad} +/// This example show a basic [Tooltip] which has a [Text] as child. +/// [message] contains your label to be shown by the tooltip when +/// the child that Tooltip wraps is hovered over on web or desktop. On mobile, +/// the tooltip is shown when the widget is long pressed. +/// +/// This tooltip will default to showing above the [Text] instead of below +/// because its ambient [TooltipThemeData.preferBelow] is false. +/// (See the use of [MaterialApp.theme].) +/// Setting that piece of theme data is recommended to avoid having a finger or +/// cursor hide the tooltip. For other ways to set that piece of theme data see: +/// +/// * [Theme.data], [ThemeData.tooltipTheme] +/// * [TooltipTheme.data] +/// +/// or it can be set directly on each tooltip with [Tooltip.preferBelow]. +/// +/// ** See code in examples/api/lib/material/tooltip/tooltip.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example covers most of the attributes available in Tooltip. +/// `decoration` has been used to give a gradient and borderRadius to Tooltip. +/// `height` has been used to set a specific height of the Tooltip. +/// `preferBelow` is true; the tooltip will prefer showing below [Tooltip]'s child widget. +/// However, it may show the tooltip above if there's not enough space +/// below the widget. +/// `textStyle` has been used to set the font size of the 'message'. +/// `showDuration` accepts a Duration to continue showing the message after the long +/// press has been released or the mouse pointer exits the child widget. +/// `waitDuration` accepts a Duration for which a mouse pointer has to hover over the child +/// widget before the tooltip is shown. +/// +/// ** See code in examples/api/lib/material/tooltip/tooltip.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows a rich [Tooltip] that specifies the [richMessage] +/// parameter instead of the [message] parameter (only one of these may be +/// non-null. Any [InlineSpan] can be specified for the [richMessage] attribute, +/// including [WidgetSpan]. +/// +/// ** See code in examples/api/lib/material/tooltip/tooltip.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how [Tooltip] can be shown manually with [TooltipTriggerMode.manual] +/// by calling the [TooltipState.ensureTooltipVisible] function. +/// +/// ** See code in examples/api/lib/material/tooltip/tooltip.3.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * <https://material.io/design/components/tooltips.html> +/// * [TooltipTheme] or [ThemeData.tooltipTheme] +/// * [TooltipVisibility] +class Tooltip extends StatefulWidget { + /// Creates a tooltip. + /// + /// By default, tooltips should adhere to the + /// [Material specification](https://material.io/design/components/tooltips.html#spec). + /// If the optional constructor parameters are not defined, the values + /// provided by [TooltipTheme.of] will be used if a [TooltipTheme] is present + /// or specified in [ThemeData]. + /// + /// All parameters that are defined in the constructor will + /// override the default values _and_ the values in [TooltipTheme.of]. + /// + /// Only one of [message] and [richMessage] may be non-null. + const Tooltip({ + super.key, + this.message, + this.richMessage, + this.height, + this.padding, + this.margin, + this.verticalOffset, + this.preferBelow, + this.excludeFromSemantics, + this.decoration, + this.textStyle, + this.textAlign, + this.waitDuration, + this.showDuration, + this.exitDuration, + this.enableTapToDismiss = true, + this.triggerMode, + this.enableFeedback, + this.onTriggered, + this.child, + }) : assert((message == null) != (richMessage == null), 'Either `message` or `richMessage` must be specified'), + assert( + richMessage == null || textStyle == null, + 'If `richMessage` is specified, `textStyle` will have no effect. ' + 'If you wish to provide a `textStyle` for a rich tooltip, add the ' + '`textStyle` directly to the `richMessage` InlineSpan.', + ); + + /// The text to display in the tooltip. + /// + /// Only one of [message] and [richMessage] may be non-null. + final String? message; + + /// The rich text to display in the tooltip. + /// + /// Only one of [message] and [richMessage] may be non-null. + final InlineSpan? richMessage; + + /// The height of the tooltip's [child]. + /// + /// If the [child] is null, then this is the tooltip's intrinsic height. + final double? height; + + /// The amount of space by which to inset the tooltip's [child]. + /// + /// On mobile, defaults to 16.0 logical pixels horizontally and 4.0 vertically. + /// On desktop, defaults to 8.0 logical pixels horizontally and 4.0 vertically. + final EdgeInsetsGeometry? padding; + + /// The empty space that surrounds the tooltip. + /// + /// Defines the tooltip's outer [Container.margin]. By default, a + /// long tooltip will span the width of its window. If long enough, + /// a tooltip might also span the window's height. This property allows + /// one to define how much space the tooltip must be inset from the edges + /// of their display window. + /// + /// If this property is null, then [TooltipThemeData.margin] is used. + /// If [TooltipThemeData.margin] is also null, the default margin is + /// 0.0 logical pixels on all sides. + final EdgeInsetsGeometry? margin; + + /// The vertical gap between the widget and the displayed tooltip. + /// + /// When [preferBelow] is set to true and tooltips have sufficient space to + /// display themselves, this property defines how much vertical space + /// tooltips will position themselves under their corresponding widgets. + /// Otherwise, tooltips will position themselves above their corresponding + /// widgets with the given offset. + final double? verticalOffset; + + /// Whether the tooltip defaults to being displayed below the widget. + /// + /// If there is insufficient space to display the tooltip in + /// the preferred direction, the tooltip will be displayed in the opposite + /// direction. + /// + /// If this property is null, then [TooltipThemeData.preferBelow] is used. + /// If that is also null, the default value is true. + /// + /// Applying [TooltipThemeData.preferBelow]: `false` for the entire app + /// is recommended to avoid having a finger or cursor hide a tooltip. + final bool? preferBelow; + + /// Whether the tooltip's [message] or [richMessage] should be excluded from + /// the semantics tree. + /// + /// Defaults to false. A tooltip will add a [Semantics] label that is set to + /// [Tooltip.message] if non-null, or the plain text value of + /// [Tooltip.richMessage] otherwise. Set this property to true if the app is + /// going to provide its own custom semantics label. + final bool? excludeFromSemantics; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// Specifies the tooltip's shape and background color. + /// + /// The tooltip shape defaults to a rounded rectangle with a border radius of + /// 4.0. Tooltips will also default to an opacity of 90% and with the color + /// [Colors.grey]\[700\] if [ThemeData.brightness] is [Brightness.dark], and + /// [Colors.white] if it is [Brightness.light]. + final Decoration? decoration; + + /// The style to use for the message of the tooltip. + /// + /// If null, the message's [TextStyle] will be determined based on + /// [ThemeData]. If [ThemeData.brightness] is set to [Brightness.dark], + /// [TextTheme.bodyMedium] of [ThemeData.textTheme] will be used with + /// [Colors.white]. Otherwise, if [ThemeData.brightness] is set to + /// [Brightness.light], [TextTheme.bodyMedium] of [ThemeData.textTheme] will be + /// used with [Colors.black]. + final TextStyle? textStyle; + + /// How the message of the tooltip is aligned horizontally. + /// + /// If this property is null, then [TooltipThemeData.textAlign] is used. + /// If [TooltipThemeData.textAlign] is also null, the default value is + /// [TextAlign.start]. + final TextAlign? textAlign; + + /// The length of time that a pointer must hover over a tooltip's widget + /// before the tooltip will be shown. + /// + /// Defaults to 0 milliseconds (tooltips are shown immediately upon hover). + final Duration? waitDuration; + + /// The length of time that the tooltip will be shown after a long press is + /// released (if triggerMode is [TooltipTriggerMode.longPress]) or a tap is + /// released (if triggerMode is [TooltipTriggerMode.tap]). This property + /// does not affect mouse pointer devices. + /// + /// Defaults to 1.5 seconds for long press and tap released + /// + /// See also: + /// + /// * [exitDuration], which allows configuring the time untill a pointer + /// dissapears when hovering. + final Duration? showDuration; + + /// The length of time that a pointer must have stopped hovering over a + /// tooltip's widget before the tooltip will be hidden. + /// + /// Defaults to 100 milliseconds. + /// + /// See also: + /// + /// * [showDuration], which allows configuring the length of time that a + /// tooltip will be visible after touch events are released. + final Duration? exitDuration; + + /// Whether the tooltip can be dismissed by tap. + /// + /// The default value is true. + final bool enableTapToDismiss; + + /// The [TooltipTriggerMode] that will show the tooltip. + /// + /// If this property is null, then [TooltipThemeData.triggerMode] is used. + /// If [TooltipThemeData.triggerMode] is also null, the default mode is + /// [TooltipTriggerMode.longPress]. + /// + /// This property does not affect mouse devices. Setting [triggerMode] to + /// [TooltipTriggerMode.manual] will not prevent the tooltip from showing when + /// the mouse cursor hovers over it. + final TooltipTriggerMode? triggerMode; + + /// Whether the tooltip should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// When null, the default value is true. + /// + /// See also: + /// + /// * [Feedback], for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + /// Called when the Tooltip is triggered. + /// + /// The tooltip is triggered after a tap when [triggerMode] is [TooltipTriggerMode.tap] + /// or after a long press when [triggerMode] is [TooltipTriggerMode.longPress]. + final TooltipTriggeredCallback? onTriggered; + + static final List<TooltipState> _openedTooltips = <TooltipState>[]; + + /// Dismiss all of the tooltips that are currently shown on the screen, + /// including those with mouse cursors currently hovering over them. + /// + /// This method returns true if it successfully dismisses the tooltips. It + /// returns false if there is no tooltip shown on the screen. + static bool dismissAllToolTips() { + if (_openedTooltips.isNotEmpty) { + // Avoid concurrent modification. + final List<TooltipState> openedTooltips = _openedTooltips.toList(); + for (final TooltipState state in openedTooltips) { + assert(state.mounted); + state._scheduleDismissTooltip(withDelay: Duration.zero); + } + return true; + } + return false; + } + + @override + State<Tooltip> createState() => TooltipState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty( + 'message', + message, + showName: message == null, + defaultValue: message == null ? null : kNoDefaultValue, + )); + properties.add(StringProperty( + 'richMessage', + richMessage?.toPlainText(), + showName: richMessage == null, + defaultValue: richMessage == null ? null : kNoDefaultValue, + )); + properties.add(DoubleProperty('height', height, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('margin', margin, defaultValue: null)); + properties.add(DoubleProperty('vertical offset', verticalOffset, defaultValue: null)); + properties.add(FlagProperty('position', value: preferBelow, ifTrue: 'below', ifFalse: 'above', showName: true)); + properties.add(FlagProperty('semantics', value: excludeFromSemantics, ifTrue: 'excluded', showName: true)); + properties.add(DiagnosticsProperty<Duration>('wait duration', waitDuration, defaultValue: null)); + properties.add(DiagnosticsProperty<Duration>('show duration', showDuration, defaultValue: null)); + properties.add(DiagnosticsProperty<Duration>('exit duration', exitDuration, defaultValue: null)); + properties.add(DiagnosticsProperty<TooltipTriggerMode>('triggerMode', triggerMode, defaultValue: null)); + properties.add(FlagProperty('enableFeedback', value: enableFeedback, ifTrue: 'true', showName: true)); + properties.add(DiagnosticsProperty<TextAlign>('textAlign', textAlign, defaultValue: null)); + } +} + +/// Contains the state for a [Tooltip]. +/// +/// This class can be used to programmatically show the Tooltip, see the +/// [ensureTooltipVisible] method. +class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin { + static const double _defaultVerticalOffset = 24.0; + static const bool _defaultPreferBelow = true; + static const EdgeInsetsGeometry _defaultMargin = EdgeInsets.zero; + static const Duration _fadeInDuration = Duration(milliseconds: 150); + static const Duration _fadeOutDuration = Duration(milliseconds: 75); + static const Duration _defaultShowDuration = Duration(milliseconds: 1500); + static const Duration _defaultHoverExitDuration = Duration(milliseconds: 100); + static const Duration _defaultWaitDuration = Duration.zero; + static const bool _defaultExcludeFromSemantics = false; + static const TooltipTriggerMode _defaultTriggerMode = TooltipTriggerMode.longPress; + static const bool _defaultEnableFeedback = true; + static const TextAlign _defaultTextAlign = TextAlign.start; + + final OverlayPortalController _overlayController = OverlayPortalController(); + + // From InheritedWidgets + late bool _visible; + late TooltipThemeData _tooltipTheme; + + Duration get _showDuration => widget.showDuration ?? _tooltipTheme.showDuration ?? _defaultShowDuration; + Duration get _hoverExitDuration => widget.exitDuration ?? _tooltipTheme.exitDuration ?? _defaultHoverExitDuration; + Duration get _waitDuration => widget.waitDuration ?? _tooltipTheme.waitDuration ?? _defaultWaitDuration; + TooltipTriggerMode get _triggerMode => widget.triggerMode ?? _tooltipTheme.triggerMode ?? _defaultTriggerMode; + bool get _enableFeedback => widget.enableFeedback ?? _tooltipTheme.enableFeedback ?? _defaultEnableFeedback; + + /// The plain text message for this tooltip. + /// + /// This value will either come from [widget.message] or [widget.richMessage]. + String get _tooltipMessage => widget.message ?? widget.richMessage!.toPlainText(); + + Timer? _timer; + AnimationController? _backingController; + AnimationController get _controller { + return _backingController ??= AnimationController( + duration: _fadeInDuration, + reverseDuration: _fadeOutDuration, + vsync: this, + )..addStatusListener(_handleStatusChanged); + } + + LongPressGestureRecognizer? _longPressRecognizer; + TapGestureRecognizer? _tapRecognizer; + + // The ids of mouse devices that are keeping the tooltip from being dismissed. + // + // Device ids are added to this set in _handleMouseEnter, and removed in + // _handleMouseExit. The set is cleared in _handleTapToDismiss, typically when + // a PointerDown event interacts with some other UI component. + final Set<int> _activeHoveringPointerDevices = <int>{}; + + static bool _isTooltipVisible(AnimationStatus status) { + return switch (status) { + AnimationStatus.completed || AnimationStatus.forward || AnimationStatus.reverse => true, + AnimationStatus.dismissed => false, + }; + } + + AnimationStatus _animationStatus = AnimationStatus.dismissed; + void _handleStatusChanged(AnimationStatus status) { + assert(mounted); + switch ((_isTooltipVisible(_animationStatus), _isTooltipVisible(status))) { + case (true, false): + Tooltip._openedTooltips.remove(this); + _overlayController.hide(); + case (false, true): + _overlayController.show(); + Tooltip._openedTooltips.add(this); + SemanticsService.tooltip(_tooltipMessage); + case (true, true) || (false, false): + break; + } + _animationStatus = status; + } + + void _scheduleShowTooltip({ required Duration withDelay, Duration? showDuration }) { + assert(mounted); + void show() { + assert(mounted); + if (!_visible) { + return; + } + _controller.forward(); + _timer?.cancel(); + _timer = showDuration == null ? null : Timer(showDuration, _controller.reverse); + } + + assert( + !(_timer?.isActive ?? false) || _controller.status != AnimationStatus.reverse, + 'timer must not be active when the tooltip is fading out', + ); + switch (_controller.status) { + case AnimationStatus.dismissed when withDelay.inMicroseconds > 0: + _timer ??= Timer(withDelay, show); + // If the tooltip is already fading in or fully visible, skip the + // animation and show the tooltip immediately. + case AnimationStatus.dismissed: + case AnimationStatus.forward: + case AnimationStatus.reverse: + case AnimationStatus.completed: + show(); + } + } + + void _scheduleDismissTooltip({ required Duration withDelay }) { + assert(mounted); + assert( + !(_timer?.isActive ?? false) || _backingController?.status != AnimationStatus.reverse, + 'timer must not be active when the tooltip is fading out', + ); + + _timer?.cancel(); + _timer = null; + // Use _backingController instead of _controller to prevent the lazy getter + // from instaniating an AnimationController unnecessarily. + switch (_backingController?.status) { + case null: + case AnimationStatus.reverse: + case AnimationStatus.dismissed: + break; + // Dismiss when the tooltip is fading in: if there's a dismiss delay we'll + // allow the fade in animation to continue until the delay timer fires. + case AnimationStatus.forward: + case AnimationStatus.completed: + if (withDelay.inMicroseconds > 0) { + _timer = Timer(withDelay, _controller.reverse); + } else { + _controller.reverse(); + } + } + } + + void _handlePointerDown(PointerDownEvent event) { + assert(mounted); + // PointerDeviceKinds that don't support hovering. + const Set<PointerDeviceKind> triggerModeDeviceKinds = <PointerDeviceKind> { + PointerDeviceKind.invertedStylus, + PointerDeviceKind.stylus, + PointerDeviceKind.touch, + PointerDeviceKind.unknown, + // MouseRegion only tracks PointerDeviceKind == mouse. + PointerDeviceKind.trackpad, + }; + switch (_triggerMode) { + case TooltipTriggerMode.longPress: + final LongPressGestureRecognizer recognizer = _longPressRecognizer ??= LongPressGestureRecognizer( + debugOwner: this, supportedDevices: triggerModeDeviceKinds, + ); + recognizer + ..onLongPressCancel = _handleTapToDismiss + ..onLongPress = _handleLongPress + ..onLongPressUp = _handlePressUp + ..addPointer(event); + case TooltipTriggerMode.tap: + final TapGestureRecognizer recognizer = _tapRecognizer ??= TapGestureRecognizer( + debugOwner: this, supportedDevices: triggerModeDeviceKinds + ); + recognizer + ..onTapCancel = _handleTapToDismiss + ..onTap = _handleTap + ..addPointer(event); + case TooltipTriggerMode.manual: + break; + } + } + + // For PointerDownEvents, this method will be called after _handlePointerDown. + void _handleGlobalPointerEvent(PointerEvent event) { + assert(mounted); + if (_tapRecognizer?.primaryPointer == event.pointer || _longPressRecognizer?.primaryPointer == event.pointer) { + // This is a pointer of interest specified by the trigger mode, since it's + // picked up by the recognizer. + // + // The recognizer will later determine if this is indeed a "trigger" + // gesture and dismiss the tooltip if that's not the case. However there's + // still a chance that the PointerEvent was cancelled before the gesture + // recognizer gets to emit a tap/longPress down, in which case the onCancel + // callback (_handleTapToDismiss) will not be called. + return; + } + if ((_timer == null && _controller.status == AnimationStatus.dismissed) || event is! PointerDownEvent) { + return; + } + _handleTapToDismiss(); + } + + // The primary pointer is not part of a "trigger" gesture so the tooltip + // should be dismissed. + void _handleTapToDismiss() { + if (!widget.enableTapToDismiss) { + return ; + } + _scheduleDismissTooltip(withDelay: Duration.zero); + _activeHoveringPointerDevices.clear(); + } + + void _handleTap() { + if (!_visible) { + return; + } + final bool tooltipCreated = _controller.status == AnimationStatus.dismissed; + if (tooltipCreated && _enableFeedback) { + assert(_triggerMode == TooltipTriggerMode.tap); + Feedback.forTap(context); + } + widget.onTriggered?.call(); + _scheduleShowTooltip( + withDelay: Duration.zero, + // _activeHoveringPointerDevices keep the tooltip visible. + showDuration: _activeHoveringPointerDevices.isEmpty ? _showDuration : null, + ); + } + + // When a "trigger" gesture is recognized and the pointer down even is a part + // of it. + void _handleLongPress() { + if (!_visible) { + return; + } + final bool tooltipCreated = _visible && _controller.status == AnimationStatus.dismissed; + if (tooltipCreated && _enableFeedback) { + assert(_triggerMode == TooltipTriggerMode.longPress); + Feedback.forLongPress(context); + } + widget.onTriggered?.call(); + _scheduleShowTooltip(withDelay: Duration.zero); + } + + void _handlePressUp() { + if (_activeHoveringPointerDevices.isNotEmpty) { + return; + } + _scheduleDismissTooltip(withDelay: _showDuration); + } + + // # Current Hovering Behavior: + // 1. Hovered tooltips don't show more than one at a time, for each mouse + // device. For example, a chip with a delete icon typically shouldn't show + // both the delete icon tooltip and the chip tooltip at the same time. + // 2. Hovered tooltips are dismissed when: + // i. [dismissAllToolTips] is called, even these tooltips are still hovered + // ii. a unrecognized PointerDownEvent occured withint the application + // (even these tooltips are still hovered), + // iii. The last hovering device leaves the tooltip. + void _handleMouseEnter(PointerEnterEvent event) { + // _handleMouseEnter is only called when the mouse starts to hover over this + // tooltip (including the actual tooltip it shows on the overlay), and this + // tooltip is the first to be hit in the widget tree's hit testing order. + // See also _ExclusiveMouseRegion for the exact behavior. + _activeHoveringPointerDevices.add(event.device); + final List<TooltipState> openedTooltips = Tooltip._openedTooltips.toList(); + bool otherTooltipsDismissed = false; + for (final TooltipState tooltip in openedTooltips) { + assert(tooltip.mounted); + final Set<int> hoveringDevices = tooltip._activeHoveringPointerDevices; + final bool shouldDismiss = tooltip != this + && (hoveringDevices.length == 1 && hoveringDevices.single == event.device); + if (shouldDismiss) { + otherTooltipsDismissed = true; + tooltip._scheduleDismissTooltip(withDelay: Duration.zero); + } + } + _scheduleShowTooltip(withDelay: otherTooltipsDismissed ? Duration.zero : _waitDuration); + } + + void _handleMouseExit(PointerExitEvent event) { + if (_activeHoveringPointerDevices.isEmpty) { + return; + } + _activeHoveringPointerDevices.remove(event.device); + if (_activeHoveringPointerDevices.isEmpty) { + _scheduleDismissTooltip(withDelay: _hoverExitDuration); + } + } + + /// Shows the tooltip if it is not already visible. + /// + /// After made visible by this method, The tooltip does not automatically + /// dismiss after `waitDuration`, until the user dismisses/re-triggers it, or + /// [Tooltip.dismissAllToolTips] is called. + /// + /// Returns `false` when the tooltip shouldn't be shown or when the tooltip + /// was already visible. + bool ensureTooltipVisible() { + if (!_visible) { + return false; + } + + _timer?.cancel(); + _timer = null; + switch (_controller.status) { + case AnimationStatus.dismissed: + case AnimationStatus.reverse: + _scheduleShowTooltip(withDelay: Duration.zero); + return true; + case AnimationStatus.forward: + case AnimationStatus.completed: + return false; + } + } + + @override + void initState() { + super.initState(); + // Listen to global pointer events so that we can hide a tooltip immediately + // if some other control is clicked on. Pointer events are dispatched to + // global routes **after** other routes. + GestureBinding.instance.pointerRouter.addGlobalRoute(_handleGlobalPointerEvent); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _visible = TooltipVisibility.of(context); + _tooltipTheme = TooltipTheme.of(context); + } + + // https://material.io/components/tooltips#specs + double _getDefaultTooltipHeight() { + return switch (Theme.of(context).platform) { + TargetPlatform.macOS || + TargetPlatform.linux || + TargetPlatform.windows => 24.0, + TargetPlatform.android || + TargetPlatform.fuchsia || + TargetPlatform.iOS => 32.0, + }; + } + + EdgeInsets _getDefaultPadding() { + return switch (Theme.of(context).platform) { + TargetPlatform.macOS || + TargetPlatform.linux || + TargetPlatform.windows => const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0), + TargetPlatform.android || + TargetPlatform.fuchsia || + TargetPlatform.iOS => const EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0), + }; + } + + static double _getDefaultFontSize(TargetPlatform platform) { + return switch (platform) { + TargetPlatform.macOS || + TargetPlatform.linux || + TargetPlatform.windows => 12.0, + TargetPlatform.android || + TargetPlatform.fuchsia || + TargetPlatform.iOS => 14.0, + }; + } + + Widget _buildTooltipOverlay(BuildContext context) { + final OverlayState overlayState = Overlay.of(context, debugRequiredFor: widget); + final RenderBox box = this.context.findRenderObject()! as RenderBox; + final Offset target = box.localToGlobal( + box.size.center(Offset.zero), + ancestor: overlayState.context.findRenderObject(), + ); + + final (TextStyle defaultTextStyle, BoxDecoration defaultDecoration) = switch (Theme.of(context)) { + ThemeData(brightness: Brightness.dark, :final TextTheme textTheme, :final TargetPlatform platform) => ( + textTheme.bodyMedium!.copyWith(color: Colors.black, fontSize: _getDefaultFontSize(platform)), + BoxDecoration(color: Colors.white.withOpacity(0.9), borderRadius: const BorderRadius.all(Radius.circular(4))), + ), + ThemeData(brightness: Brightness.light, :final TextTheme textTheme, :final TargetPlatform platform) => ( + textTheme.bodyMedium!.copyWith(color: Colors.white, fontSize: _getDefaultFontSize(platform)), + BoxDecoration(color: Colors.grey[700]!.withOpacity(0.9), borderRadius: const BorderRadius.all(Radius.circular(4))), + ), + }; + + final TooltipThemeData tooltipTheme = _tooltipTheme; + final _TooltipOverlay overlayChild = _TooltipOverlay( + richMessage: widget.richMessage ?? TextSpan(text: widget.message), + height: widget.height ?? tooltipTheme.height ?? _getDefaultTooltipHeight(), + padding: widget.padding ?? tooltipTheme.padding ?? _getDefaultPadding(), + margin: widget.margin ?? tooltipTheme.margin ?? _defaultMargin, + onEnter: _handleMouseEnter, + onExit: _handleMouseExit, + decoration: widget.decoration ?? tooltipTheme.decoration ?? defaultDecoration, + textStyle: widget.textStyle ?? tooltipTheme.textStyle ?? defaultTextStyle, + textAlign: widget.textAlign ?? tooltipTheme.textAlign ?? _defaultTextAlign, + animation: CurvedAnimation(parent: _controller, curve: Curves.fastOutSlowIn), + target: target, + verticalOffset: widget.verticalOffset ?? tooltipTheme.verticalOffset ?? _defaultVerticalOffset, + preferBelow: widget.preferBelow ?? tooltipTheme.preferBelow ?? _defaultPreferBelow, + ); + + return SelectionContainer.maybeOf(context) == null + ? overlayChild + : SelectionContainer.disabled(child: overlayChild); + } + + @override + void dispose() { + GestureBinding.instance.pointerRouter.removeGlobalRoute(_handleGlobalPointerEvent); + Tooltip._openedTooltips.remove(this); + // _longPressRecognizer.dispose() and _tapRecognizer.dispose() may call + // their registered onCancel callbacks if there's a gesture in progress. + // Remove the onCancel callbacks to prevent the registered callbacks from + // triggering unnecessary side effects (such as animations). + _longPressRecognizer?.onLongPressCancel = null; + _longPressRecognizer?.dispose(); + _tapRecognizer?.onTapCancel = null; + _tapRecognizer?.dispose(); + _timer?.cancel(); + _backingController?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + // If message is empty then no need to create a tooltip overlay to show + // the empty black container so just return the wrapped child as is or + // empty container if child is not specified. + if (_tooltipMessage.isEmpty) { + return widget.child ?? const SizedBox.shrink(); + } + assert(debugCheckHasOverlay(context)); + final bool excludeFromSemantics = widget.excludeFromSemantics ?? _tooltipTheme.excludeFromSemantics ?? _defaultExcludeFromSemantics; + Widget result = Semantics( + tooltip: excludeFromSemantics ? null : _tooltipMessage, + child: widget.child, + ); + + // Only check for gestures if tooltip should be visible. + if (_visible) { + result = _ExclusiveMouseRegion( + onEnter: _handleMouseEnter, + onExit: _handleMouseExit, + child: Listener( + onPointerDown: _handlePointerDown, + behavior: HitTestBehavior.opaque, + child: result, + ), + ); + } + return OverlayPortal( + controller: _overlayController, + overlayChildBuilder: _buildTooltipOverlay, + child: result, + ); + } +} + +/// A delegate for computing the layout of a tooltip to be displayed above or +/// below a target specified in the global coordinate system. +class _TooltipPositionDelegate extends SingleChildLayoutDelegate { + /// Creates a delegate for computing the layout of a tooltip. + _TooltipPositionDelegate({ + required this.target, + required this.verticalOffset, + required this.preferBelow, + }); + + /// The offset of the target the tooltip is positioned near in the global + /// coordinate system. + final Offset target; + + /// The amount of vertical distance between the target and the displayed + /// tooltip. + final double verticalOffset; + + /// Whether the tooltip is displayed below its widget by default. + /// + /// If there is insufficient space to display the tooltip in the preferred + /// direction, the tooltip will be displayed in the opposite direction. + final bool preferBelow; + + @override + BoxConstraints getConstraintsForChild(BoxConstraints constraints) => constraints.loosen(); + + @override + Offset getPositionForChild(Size size, Size childSize) { + return positionDependentBox( + size: size, + childSize: childSize, + target: target, + verticalOffset: verticalOffset, + preferBelow: preferBelow, + ); + } + + @override + bool shouldRelayout(_TooltipPositionDelegate oldDelegate) { + return target != oldDelegate.target + || verticalOffset != oldDelegate.verticalOffset + || preferBelow != oldDelegate.preferBelow; + } +} + +class _TooltipOverlay extends StatelessWidget { + const _TooltipOverlay({ + required this.height, + required this.richMessage, + this.padding, + this.margin, + this.decoration, + this.textStyle, + this.textAlign, + required this.animation, + required this.target, + required this.verticalOffset, + required this.preferBelow, + this.onEnter, + this.onExit, + }); + + final InlineSpan richMessage; + final double height; + final EdgeInsetsGeometry? padding; + final EdgeInsetsGeometry? margin; + final Decoration? decoration; + final TextStyle? textStyle; + final TextAlign? textAlign; + final Animation<double> animation; + final Offset target; + final double verticalOffset; + final bool preferBelow; + final PointerEnterEventListener? onEnter; + final PointerExitEventListener? onExit; + + @override + Widget build(BuildContext context) { + Widget result = FadeTransition( + opacity: animation, + child: ConstrainedBox( + constraints: BoxConstraints(minHeight: height), + child: DefaultTextStyle( + style: Theme.of(context).textTheme.bodyMedium!, + child: Semantics( + container: true, + child: Container( + decoration: decoration, + padding: padding, + margin: margin, + child: Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: Text.rich( + richMessage, + style: textStyle, + textAlign: textAlign, + ), + ), + ), + ), + ), + ), + ); + if (onEnter != null || onExit != null) { + result = _ExclusiveMouseRegion( + onEnter: onEnter, + onExit: onExit, + child: result, + ); + } + return Positioned.fill( + bottom: MediaQuery.maybeViewInsetsOf(context)?.bottom ?? 0.0, + child: CustomSingleChildLayout( + delegate: _TooltipPositionDelegate( + target: target, + verticalOffset: verticalOffset, + preferBelow: preferBelow, + ), + child: result, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tooltip_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tooltip_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..adaee3c794c409b67558e1e1a09369a29a029f9b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tooltip_theme.dart @@ -0,0 +1,339 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Defines the visual properties of [Tooltip] widgets. +/// +/// Used by [TooltipTheme] to control the visual properties of tooltips in a +/// widget subtree. +/// +/// To obtain this configuration, use [TooltipTheme.of] to access the closest +/// ancestor [TooltipTheme] of the current [BuildContext]. +/// +/// See also: +/// +/// * [TooltipTheme], an [InheritedWidget] that propagates the theme down its +/// subtree. +/// * [TooltipThemeData], which describes the actual configuration of a +/// tooltip theme. +@immutable +class TooltipThemeData with Diagnosticable { + /// Creates the set of properties used to configure [Tooltip]s. + const TooltipThemeData({ + this.height, + this.padding, + this.margin, + this.verticalOffset, + this.preferBelow, + this.excludeFromSemantics, + this.decoration, + this.textStyle, + this.textAlign, + this.waitDuration, + this.showDuration, + this.exitDuration, + this.triggerMode, + this.enableFeedback, + }); + + /// The height of [Tooltip.child]. + final double? height; + + /// If provided, the amount of space by which to inset [Tooltip.child]. + final EdgeInsetsGeometry? padding; + + /// If provided, the amount of empty space to surround the [Tooltip]. + final EdgeInsetsGeometry? margin; + + /// The vertical gap between the widget and the displayed tooltip. + /// + /// When [preferBelow] is set to true and tooltips have sufficient space to + /// display themselves, this property defines how much vertical space + /// tooltips will position themselves under their corresponding widgets. + /// Otherwise, tooltips will position themselves above their corresponding + /// widgets with the given offset. + final double? verticalOffset; + + /// Whether the tooltip is displayed below its widget by default. + /// + /// If there is insufficient space to display the tooltip in the preferred + /// direction, the tooltip will be displayed in the opposite direction. + /// + /// Applying `false` for the entire app is recommended + /// to avoid having a finger or cursor hide a tooltip. + final bool? preferBelow; + + /// Whether the [Tooltip.message] should be excluded from the semantics + /// tree. + /// + /// By default, [Tooltip]s will add a [Semantics] label that is set to + /// [Tooltip.message]. Set this property to true if the app is going to + /// provide its own custom semantics label. + final bool? excludeFromSemantics; + + /// The [Tooltip]'s shape and background color. + final Decoration? decoration; + + /// The style to use for the message of [Tooltip]s. + final TextStyle? textStyle; + + /// The [TextAlign] to use for the message of [Tooltip]s. + final TextAlign? textAlign; + + /// The length of time that a pointer must hover over a tooltip's widget + /// before the tooltip will be shown. + final Duration? waitDuration; + + /// The length of time that the tooltip will be shown once it has appeared. + final Duration? showDuration; + + /// The length of time that a pointer must have stopped hovering over a + /// tooltip's widget before the tooltip will be hidden. + final Duration? exitDuration; + + /// The [TooltipTriggerMode] that will show the tooltip. + final TooltipTriggerMode? triggerMode; + + /// Whether the tooltip should provide acoustic and/or haptic feedback. + /// + /// For example, on Android a tap will produce a clicking sound and a + /// long-press will produce a short vibration, when feedback is enabled. + /// + /// This value is used if [Tooltip.enableFeedback] is null. + /// If this value is null, the default is true. + /// + /// See also: + /// + /// * [Feedback], for providing platform-specific feedback to certain actions. + final bool? enableFeedback; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + TooltipThemeData copyWith({ + double? height, + EdgeInsetsGeometry? padding, + EdgeInsetsGeometry? margin, + double? verticalOffset, + bool? preferBelow, + bool? excludeFromSemantics, + Decoration? decoration, + TextStyle? textStyle, + TextAlign? textAlign, + Duration? waitDuration, + Duration? showDuration, + Duration? exitDuration, + TooltipTriggerMode? triggerMode, + bool? enableFeedback, + }) { + return TooltipThemeData( + height: height ?? this.height, + padding: padding ?? this.padding, + margin: margin ?? this.margin, + verticalOffset: verticalOffset ?? this.verticalOffset, + preferBelow: preferBelow ?? this.preferBelow, + excludeFromSemantics: excludeFromSemantics ?? this.excludeFromSemantics, + decoration: decoration ?? this.decoration, + textStyle: textStyle ?? this.textStyle, + textAlign: textAlign ?? this.textAlign, + waitDuration: waitDuration ?? this.waitDuration, + showDuration: showDuration ?? this.showDuration, + triggerMode: triggerMode ?? this.triggerMode, + enableFeedback: enableFeedback ?? this.enableFeedback, + ); + } + + /// Linearly interpolate between two tooltip themes. + /// + /// If both arguments are null, then null is returned. + /// + /// {@macro dart.ui.shadow.lerp} + static TooltipThemeData? lerp(TooltipThemeData? a, TooltipThemeData? b, double t) { + if (identical(a, b)) { + return a; + } + return TooltipThemeData( + height: lerpDouble(a?.height, b?.height, t), + padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t), + margin: EdgeInsetsGeometry.lerp(a?.margin, b?.margin, t), + verticalOffset: lerpDouble(a?.verticalOffset, b?.verticalOffset, t), + preferBelow: t < 0.5 ? a?.preferBelow: b?.preferBelow, + excludeFromSemantics: t < 0.5 ? a?.excludeFromSemantics : b?.excludeFromSemantics, + decoration: Decoration.lerp(a?.decoration, b?.decoration, t), + textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t), + textAlign: t < 0.5 ? a?.textAlign: b?.textAlign, + ); + } + + @override + int get hashCode => Object.hash( + height, + padding, + margin, + verticalOffset, + preferBelow, + excludeFromSemantics, + decoration, + textStyle, + textAlign, + waitDuration, + showDuration, + exitDuration, + triggerMode, + enableFeedback, + ); + + @override + bool operator==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is TooltipThemeData + && other.height == height + && other.padding == padding + && other.margin == margin + && other.verticalOffset == verticalOffset + && other.preferBelow == preferBelow + && other.excludeFromSemantics == excludeFromSemantics + && other.decoration == decoration + && other.textStyle == textStyle + && other.textAlign == textAlign + && other.waitDuration == waitDuration + && other.showDuration == showDuration + && other.exitDuration == exitDuration + && other.triggerMode == triggerMode + && other.enableFeedback == enableFeedback; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('height', height, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('margin', margin, defaultValue: null)); + properties.add(DoubleProperty('vertical offset', verticalOffset, defaultValue: null)); + properties.add(FlagProperty('position', value: preferBelow, ifTrue: 'below', ifFalse: 'above', showName: true)); + properties.add(FlagProperty('semantics', value: excludeFromSemantics, ifTrue: 'excluded', showName: true)); + properties.add(DiagnosticsProperty<Decoration>('decoration', decoration, defaultValue: null)); + properties.add(DiagnosticsProperty<TextStyle>('textStyle', textStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextAlign>('textAlign', textAlign, defaultValue: null)); + properties.add(DiagnosticsProperty<Duration>('wait duration', waitDuration, defaultValue: null)); + properties.add(DiagnosticsProperty<Duration>('show duration', showDuration, defaultValue: null)); + properties.add(DiagnosticsProperty<Duration>('exit duration', exitDuration, defaultValue: null)); + properties.add(DiagnosticsProperty<TooltipTriggerMode>('triggerMode', triggerMode, defaultValue: null)); + properties.add(FlagProperty('enableFeedback', value: enableFeedback, ifTrue: 'true', showName: true)); + } +} + +/// An inherited widget that defines the configuration for +/// [Tooltip]s in this widget's subtree. +/// +/// Values specified here are used for [Tooltip] properties that are not +/// given an explicit non-null value. +/// +/// {@tool snippet} +/// +/// Here is an example of a tooltip theme that applies a blue foreground +/// with non-rounded corners. +/// +/// ```dart +/// TooltipTheme( +/// data: TooltipThemeData( +/// decoration: BoxDecoration( +/// color: Colors.blue.withOpacity(0.9), +/// borderRadius: BorderRadius.zero, +/// ), +/// ), +/// child: Tooltip( +/// message: 'Example tooltip', +/// child: IconButton( +/// iconSize: 36.0, +/// icon: const Icon(Icons.touch_app), +/// onPressed: () {}, +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [TooltipVisibility], which can be used to visually disable descendant [Tooltip]s. +class TooltipTheme extends InheritedTheme { + /// Creates a tooltip theme that controls the configurations for + /// [Tooltip]. + const TooltipTheme({ + super.key, + required this.data, + required super.child, + }); + + /// The properties for descendant [Tooltip] widgets. + final TooltipThemeData data; + + /// Returns the [data] from the closest [TooltipTheme] ancestor. If there is + /// no ancestor, it returns [ThemeData.tooltipTheme]. Applications can assume + /// that the returned value will not be null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// TooltipThemeData theme = TooltipTheme.of(context); + /// ``` + static TooltipThemeData of(BuildContext context) { + final TooltipTheme? tooltipTheme = context.dependOnInheritedWidgetOfExactType<TooltipTheme>(); + return tooltipTheme?.data ?? Theme.of(context).tooltipTheme; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return TooltipTheme(data: data, child: child); + } + + @override + bool updateShouldNotify(TooltipTheme oldWidget) => data != oldWidget.data; +} + +/// The method of interaction that will trigger a tooltip. +/// Used in [Tooltip.triggerMode] and [TooltipThemeData.triggerMode]. +/// +/// On desktop, a tooltip will be shown as soon as a pointer hovers over +/// the widget, regardless of the value of [Tooltip.triggerMode]. +/// +/// See also: +/// +/// * [Tooltip.waitDuration], which defines the length of time that +/// a pointer must hover over a tooltip's widget before the tooltip +/// will be shown. +enum TooltipTriggerMode { + /// Tooltip will only be shown by calling `ensureTooltipVisible`. + manual, + + /// Tooltip will be shown after a long press. + /// + /// See also: + /// + /// * [GestureDetector.onLongPress], the event that is used for trigger. + /// * [Feedback.forLongPress], the feedback method called when feedback is enabled. + longPress, + + /// Tooltip will be shown after a single tap. + /// + /// See also: + /// + /// * [GestureDetector.onTap], the event that is used for trigger. + /// * [Feedback.forTap], the feedback method called when feedback is enabled. + tap, +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tooltip_visibility.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tooltip_visibility.dart new file mode 100644 index 0000000000000000000000000000000000000000..52642317a60074eb7d9625403680493cefd6904d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/tooltip_visibility.dart @@ -0,0 +1,60 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +class _TooltipVisibilityScope extends InheritedWidget { + const _TooltipVisibilityScope({ + required super.child, + required this.visible, + }); + + final bool visible; + + @override + bool updateShouldNotify(_TooltipVisibilityScope old) { + return old.visible != visible; + } +} + +/// Overrides the visibility of descendant [Tooltip] widgets. +/// +/// If disabled, the descendant [Tooltip] widgets will not display a tooltip +/// when tapped, long-pressed, hovered by the mouse, or when +/// `ensureTooltipVisible` is called. This only visually disables tooltips but +/// continues to provide any semantic information that is provided. +class TooltipVisibility extends StatelessWidget { + /// Creates a widget that configures the visibility of [Tooltip]. + const TooltipVisibility({ + super.key, + required this.visible, + required this.child, + }); + + /// The widget below this widget in the tree. + /// + /// The entire app can be wrapped in this widget to globally control [Tooltip] + /// visibility. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// Determines the visibility of [Tooltip] widgets that inherit from this widget. + final bool visible; + + /// The [visible] of the closest instance of this class that encloses the + /// given context. Defaults to `true` if none are found. + static bool of(BuildContext context) { + final _TooltipVisibilityScope? visibility = context.dependOnInheritedWidgetOfExactType<_TooltipVisibilityScope>(); + return visibility?.visible ?? true; + } + + @override + Widget build(BuildContext context) { + return _TooltipVisibilityScope( + visible: visible, + child: child, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/typography.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/typography.dart new file mode 100644 index 0000000000000000000000000000000000000000..ca08c41713cbc9432661b90248726e46158c69b6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/typography.dart @@ -0,0 +1,809 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; + +import 'color_scheme.dart'; +import 'colors.dart'; +import 'text_theme.dart'; + +// Examples can assume: +// late TargetPlatform platform; + +/// A characterization of the of a [TextTheme]'s glyphs that is used to define +/// its localized [TextStyle] geometry for [ThemeData.textTheme]. +/// +/// The script category defines the overall geometry of a [TextTheme] for +/// the [Typography.geometryThemeFor] method in terms of the +/// three language categories defined in <https://material.io/go/design-typography>. +/// +/// Generally speaking, font sizes for [ScriptCategory.tall] and +/// [ScriptCategory.dense] scripts - for text styles that are smaller than the +/// title style - are one unit larger than they are for +/// [ScriptCategory.englishLike] scripts. +enum ScriptCategory { + /// The languages of Western, Central, and Eastern Europe and much of + /// Africa are typically written in the Latin alphabet. Vietnamese is a + /// notable exception in that, while it uses a localized form of the Latin + /// writing system, its accented glyphs can be much taller than those + /// found in Western European languages. The Greek and Cyrillic writing + /// systems are very similar to Latin. + englishLike, + + /// Language scripts that require extra line height to accommodate larger + /// glyphs, including Chinese, Japanese, and Korean. + dense, + + /// Language scripts that require extra line height to accommodate + /// larger glyphs, including South and Southeast Asian and + /// Middle-Eastern languages, like Arabic, Hindi, Telugu, Thai, and + /// Vietnamese. + tall, +} + +/// The color and geometry [TextTheme]s for Material apps. +/// +/// The text theme provided by the overall [Theme], +/// [ThemeData.textTheme], is based on the current locale's +/// [MaterialLocalizations.scriptCategory] and is created +/// by merging a color text theme - [black] for +/// [Brightness.light] themes and [white] for [Brightness.dark] +/// themes - and a geometry text theme, one of [englishLike], [dense], +/// or [tall], depending on the locale. +/// +/// To lookup the localized text theme use +/// `Theme.of(context).textTheme`. +/// +/// The color text themes are [blackMountainView], [whiteMountainView], +/// [blackCupertino], and [whiteCupertino]. The Mountain View theme [TextStyle]s +/// are based on the Roboto fonts as used on Android. The Cupertino themes are +/// based on the [San Francisco +/// font](https://developer.apple.com/ios/human-interface-guidelines/visual-design/typography/) +/// fonts as used by Apple on iOS. +/// +/// Two sets of geometry themes are provided: 2014 and 2018. The 2014 themes +/// correspond to the original version of the Material Design spec and are +/// the defaults. The 2018 themes correspond the second iteration of the +/// specification and feature different font sizes, font weights, and +/// letter spacing values. +/// +/// By default, [ThemeData.typography] is `Typography.material2014(platform: +/// platform)` which uses [englishLike2014], [dense2014] and [tall2014]. To use +/// the 2018 text theme geometries, specify a value using the [material2018] +/// constructor: +/// +/// ```dart +/// typography: Typography.material2018(platform: platform) +/// ``` +/// +/// See also: +/// +/// * <https://material.io/design/typography/> +/// * <https://m3.material.io/styles/typography> +@immutable +class Typography with Diagnosticable { + /// Creates a typography instance. + /// + /// This constructor is identical to [Typography.material2018]. + factory Typography({ + TargetPlatform? platform, + TextTheme? black, + TextTheme? white, + TextTheme? englishLike, + TextTheme? dense, + TextTheme? tall, + }) = Typography.material2018; + + /// Creates a typography instance using Material Design's 2014 defaults. + /// + /// If [platform] is [TargetPlatform.iOS] or [TargetPlatform.macOS], the + /// default values for [black] and [white] are [blackCupertino] and + /// [whiteCupertino] respectively. Otherwise they are [blackMountainView] and + /// [whiteMountainView]. If [platform] is null then both [black] and [white] + /// must be specified. + /// + /// The default values for [englishLike], [dense], and [tall] are + /// [englishLike2014], [dense2014], and [tall2014]. + factory Typography.material2014({ + TargetPlatform? platform = TargetPlatform.android, + TextTheme? black, + TextTheme? white, + TextTheme? englishLike, + TextTheme? dense, + TextTheme? tall, + }) { + assert(platform != null || (black != null && white != null)); + return Typography._withPlatform( + platform, + black, white, + englishLike ?? englishLike2014, + dense ?? dense2014, + tall ?? tall2014, + ); + } + + /// Creates a typography instance using Material Design's 2018 defaults. + /// + /// If [platform] is [TargetPlatform.iOS] or [TargetPlatform.macOS], the + /// default values for [black] and [white] are [blackCupertino] and + /// [whiteCupertino] respectively. Otherwise they are [blackMountainView] and + /// [whiteMountainView]. If [platform] is null then both [black] and [white] + /// must be specified. + /// + /// The default values for [englishLike], [dense], and [tall] are + /// [englishLike2018], [dense2018], and [tall2018]. + factory Typography.material2018({ + TargetPlatform? platform = TargetPlatform.android, + TextTheme? black, + TextTheme? white, + TextTheme? englishLike, + TextTheme? dense, + TextTheme? tall, + }) { + assert(platform != null || (black != null && white != null)); + return Typography._withPlatform( + platform, + black, white, + englishLike ?? englishLike2018, + dense ?? dense2018, + tall ?? tall2018, + ); + } + + /// Creates a typography instance using Material Design 3 2021 defaults. + /// + /// If [platform] is [TargetPlatform.iOS] or [TargetPlatform.macOS], the + /// default values for [black] and [white] are [blackCupertino] and + /// [whiteCupertino] respectively. Otherwise they are [blackMountainView] and + /// [whiteMountainView]. If [platform] is null then both [black] and [white] + /// must be specified. + /// + /// The default values for [englishLike], [dense], and [tall] are + /// [englishLike2021], [dense2021], and [tall2021]. + /// + /// See also: + /// * <https://m3.material.io/styles/typography> + factory Typography.material2021({ + TargetPlatform? platform = TargetPlatform.android, + ColorScheme colorScheme = const ColorScheme.light(), + TextTheme? black, + TextTheme? white, + TextTheme? englishLike, + TextTheme? dense, + TextTheme? tall, + }) { + assert(platform != null || (black != null && white != null)); + final Typography base = Typography._withPlatform( + platform, + black, white, + englishLike ?? englishLike2021, + dense ?? dense2021, + tall ?? tall2021, + ); + + // Ensure they are all uniformly dark or light, with + // no color variation based on style as it was in previous + // versions of Material Design. + final Color dark = colorScheme.brightness == Brightness.light ? colorScheme.onSurface : colorScheme.surface; + final Color light = colorScheme.brightness == Brightness.light ? colorScheme.surface : colorScheme.onSurface; + return base.copyWith( + black: base.black.apply( + displayColor: dark, + bodyColor: dark, + decorationColor: dark + ), + white: base.white.apply( + displayColor: light, + bodyColor: light, + decorationColor: light + ), + ); + } + + factory Typography._withPlatform( + TargetPlatform? platform, + TextTheme? black, + TextTheme? white, + TextTheme englishLike, + TextTheme dense, + TextTheme tall, + ) { + assert(platform != null || (black != null && white != null)); + switch (platform) { + case TargetPlatform.iOS: + black ??= blackCupertino; + white ??= whiteCupertino; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + black ??= blackMountainView; + white ??= whiteMountainView; + case TargetPlatform.windows: + black ??= blackRedmond; + white ??= whiteRedmond; + case TargetPlatform.macOS: + black ??= blackRedwoodCity; + white ??= whiteRedwoodCity; + case TargetPlatform.linux: + black ??= blackHelsinki; + white ??= whiteHelsinki; + case null: + break; + } + return Typography._(black!, white!, englishLike, dense, tall); + } + + const Typography._(this.black, this.white, this.englishLike, this.dense, this.tall); + + /// A Material Design text theme with dark glyphs. + /// + /// This [TextTheme] should provide color but not geometry (font size, + /// weight, etc). A text theme's geometry depends on the locale. To look + /// up a localized [TextTheme], use the overall [Theme], for example: + /// `Theme.of(context).textTheme`. + /// + /// The [englishLike], [dense], and [tall] text theme's provide locale-specific + /// geometry. + final TextTheme black; + + /// A Material Design text theme with light glyphs. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + /// A text theme's geometry depends on the locale. To look up a localized + /// [TextTheme], use the overall [Theme], for example: + /// `Theme.of(context).textTheme`. + /// + /// The [englishLike], [dense], and [tall] text theme's provide locale-specific + /// geometry. + final TextTheme white; + + /// Defines text geometry for [ScriptCategory.englishLike] scripts, such as + /// English, French, Russian, etc. + /// + /// This text theme is merged with either [black] or [white], depending + /// on the overall [ThemeData.brightness], when the current locale's + /// [MaterialLocalizations.scriptCategory] is [ScriptCategory.englishLike]. + /// + /// To look up a localized [TextTheme], use the overall [Theme], for + /// example: `Theme.of(context).textTheme`. + final TextTheme englishLike; + + /// Defines text geometry for dense scripts, such as Chinese, Japanese + /// and Korean. + /// + /// This text theme is merged with either [black] or [white], depending + /// on the overall [ThemeData.brightness], when the current locale's + /// [MaterialLocalizations.scriptCategory] is [ScriptCategory.dense]. + /// + /// To look up a localized [TextTheme], use the overall [Theme], for + /// example: `Theme.of(context).textTheme`. + final TextTheme dense; + + /// Defines text geometry for tall scripts, such as Farsi, Hindi, and Thai. + /// + /// This text theme is merged with either [black] or [white], depending + /// on the overall [ThemeData.brightness], when the current locale's + /// [MaterialLocalizations.scriptCategory] is [ScriptCategory.tall]. + /// + /// To look up a localized [TextTheme], use the overall [Theme], for + /// example: `Theme.of(context).textTheme`. + final TextTheme tall; + + /// Returns one of [englishLike], [dense], or [tall]. + TextTheme geometryThemeFor(ScriptCategory category) { + switch (category) { + case ScriptCategory.englishLike: + return englishLike; + case ScriptCategory.dense: + return dense; + case ScriptCategory.tall: + return tall; + } + } + + /// Creates a copy of this [Typography] with the given fields + /// replaced by the non-null parameter values. + Typography copyWith({ + TextTheme? black, + TextTheme? white, + TextTheme? englishLike, + TextTheme? dense, + TextTheme? tall, + }) { + return Typography._( + black ?? this.black, + white ?? this.white, + englishLike ?? this.englishLike, + dense ?? this.dense, + tall ?? this.tall, + ); + } + + /// Linearly interpolate between two [Typography] objects. + /// + /// {@macro dart.ui.shadow.lerp} + static Typography lerp(Typography a, Typography b, double t) { + if (identical(a, b)) { + return a; + } + return Typography._( + TextTheme.lerp(a.black, b.black, t), + TextTheme.lerp(a.white, b.white, t), + TextTheme.lerp(a.englishLike, b.englishLike, t), + TextTheme.lerp(a.dense, b.dense, t), + TextTheme.lerp(a.tall, b.tall, t), + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is Typography + && other.black == black + && other.white == white + && other.englishLike == englishLike + && other.dense == dense + && other.tall == tall; + } + + @override + int get hashCode => Object.hash( + black, + white, + englishLike, + dense, + tall, + ); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final Typography defaultTypography = Typography.material2014(); + properties.add(DiagnosticsProperty<TextTheme>('black', black, defaultValue: defaultTypography.black)); + properties.add(DiagnosticsProperty<TextTheme>('white', white, defaultValue: defaultTypography.white)); + properties.add(DiagnosticsProperty<TextTheme>('englishLike', englishLike, defaultValue: defaultTypography.englishLike)); + properties.add(DiagnosticsProperty<TextTheme>('dense', dense, defaultValue: defaultTypography.dense)); + properties.add(DiagnosticsProperty<TextTheme>('tall', tall, defaultValue: defaultTypography.tall)); + } + + /// A Material Design text theme with dark glyphs based on Roboto. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + static const TextTheme blackMountainView = TextTheme( + displayLarge: TextStyle(debugLabel: 'blackMountainView displayLarge', fontFamily: 'Roboto', color: Colors.black54, decoration: TextDecoration.none), + displayMedium: TextStyle(debugLabel: 'blackMountainView displayMedium', fontFamily: 'Roboto', color: Colors.black54, decoration: TextDecoration.none), + displaySmall: TextStyle(debugLabel: 'blackMountainView displaySmall', fontFamily: 'Roboto', color: Colors.black54, decoration: TextDecoration.none), + headlineLarge: TextStyle(debugLabel: 'blackMountainView headlineLarge', fontFamily: 'Roboto', color: Colors.black54, decoration: TextDecoration.none), + headlineMedium: TextStyle(debugLabel: 'blackMountainView headlineMedium', fontFamily: 'Roboto', color: Colors.black54, decoration: TextDecoration.none), + headlineSmall: TextStyle(debugLabel: 'blackMountainView headlineSmall', fontFamily: 'Roboto', color: Colors.black87, decoration: TextDecoration.none), + titleLarge: TextStyle(debugLabel: 'blackMountainView titleLarge', fontFamily: 'Roboto', color: Colors.black87, decoration: TextDecoration.none), + titleMedium: TextStyle(debugLabel: 'blackMountainView titleMedium', fontFamily: 'Roboto', color: Colors.black87, decoration: TextDecoration.none), + titleSmall: TextStyle(debugLabel: 'blackMountainView titleSmall', fontFamily: 'Roboto', color: Colors.black, decoration: TextDecoration.none), + bodyLarge: TextStyle(debugLabel: 'blackMountainView bodyLarge', fontFamily: 'Roboto', color: Colors.black87, decoration: TextDecoration.none), + bodyMedium: TextStyle(debugLabel: 'blackMountainView bodyMedium', fontFamily: 'Roboto', color: Colors.black87, decoration: TextDecoration.none), + bodySmall: TextStyle(debugLabel: 'blackMountainView bodySmall', fontFamily: 'Roboto', color: Colors.black54, decoration: TextDecoration.none), + labelLarge: TextStyle(debugLabel: 'blackMountainView labelLarge', fontFamily: 'Roboto', color: Colors.black87, decoration: TextDecoration.none), + labelMedium: TextStyle(debugLabel: 'blackMountainView labelMedium', fontFamily: 'Roboto', color: Colors.black, decoration: TextDecoration.none), + labelSmall: TextStyle(debugLabel: 'blackMountainView labelSmall', fontFamily: 'Roboto', color: Colors.black, decoration: TextDecoration.none), + ); + + /// A Material Design text theme with light glyphs based on Roboto. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + static const TextTheme whiteMountainView = TextTheme( + displayLarge: TextStyle(debugLabel: 'whiteMountainView displayLarge', fontFamily: 'Roboto', color: Colors.white70, decoration: TextDecoration.none), + displayMedium: TextStyle(debugLabel: 'whiteMountainView displayMedium', fontFamily: 'Roboto', color: Colors.white70, decoration: TextDecoration.none), + displaySmall: TextStyle(debugLabel: 'whiteMountainView displaySmall', fontFamily: 'Roboto', color: Colors.white70, decoration: TextDecoration.none), + headlineLarge: TextStyle(debugLabel: 'whiteMountainView headlineLarge', fontFamily: 'Roboto', color: Colors.white70, decoration: TextDecoration.none), + headlineMedium: TextStyle(debugLabel: 'whiteMountainView headlineMedium', fontFamily: 'Roboto', color: Colors.white70, decoration: TextDecoration.none), + headlineSmall: TextStyle(debugLabel: 'whiteMountainView headlineSmall', fontFamily: 'Roboto', color: Colors.white, decoration: TextDecoration.none), + titleLarge: TextStyle(debugLabel: 'whiteMountainView titleLarge', fontFamily: 'Roboto', color: Colors.white, decoration: TextDecoration.none), + titleMedium: TextStyle(debugLabel: 'whiteMountainView titleMedium', fontFamily: 'Roboto', color: Colors.white, decoration: TextDecoration.none), + titleSmall: TextStyle(debugLabel: 'whiteMountainView titleSmall', fontFamily: 'Roboto', color: Colors.white, decoration: TextDecoration.none), + bodyLarge: TextStyle(debugLabel: 'whiteMountainView bodyLarge', fontFamily: 'Roboto', color: Colors.white, decoration: TextDecoration.none), + bodyMedium: TextStyle(debugLabel: 'whiteMountainView bodyMedium', fontFamily: 'Roboto', color: Colors.white, decoration: TextDecoration.none), + bodySmall: TextStyle(debugLabel: 'whiteMountainView bodySmall', fontFamily: 'Roboto', color: Colors.white70, decoration: TextDecoration.none), + labelLarge: TextStyle(debugLabel: 'whiteMountainView labelLarge', fontFamily: 'Roboto', color: Colors.white, decoration: TextDecoration.none), + labelMedium: TextStyle(debugLabel: 'whiteMountainView labelMedium', fontFamily: 'Roboto', color: Colors.white, decoration: TextDecoration.none), + labelSmall: TextStyle(debugLabel: 'whiteMountainView labelSmall', fontFamily: 'Roboto', color: Colors.white, decoration: TextDecoration.none), + ); + + /// A Material Design text theme with dark glyphs based on Segoe UI. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + static const TextTheme blackRedmond = TextTheme( + displayLarge: TextStyle(debugLabel: 'blackRedmond displayLarge', fontFamily: 'Segoe UI', color: Colors.black54, decoration: TextDecoration.none), + displayMedium: TextStyle(debugLabel: 'blackRedmond displayMedium', fontFamily: 'Segoe UI', color: Colors.black54, decoration: TextDecoration.none), + displaySmall: TextStyle(debugLabel: 'blackRedmond displaySmall', fontFamily: 'Segoe UI', color: Colors.black54, decoration: TextDecoration.none), + headlineLarge: TextStyle(debugLabel: 'blackRedmond headlineLarge', fontFamily: 'Segoe UI', color: Colors.black54, decoration: TextDecoration.none), + headlineMedium: TextStyle(debugLabel: 'blackRedmond headlineMedium', fontFamily: 'Segoe UI', color: Colors.black54, decoration: TextDecoration.none), + headlineSmall: TextStyle(debugLabel: 'blackRedmond headlineSmall', fontFamily: 'Segoe UI', color: Colors.black87, decoration: TextDecoration.none), + titleLarge: TextStyle(debugLabel: 'blackRedmond titleLarge', fontFamily: 'Segoe UI', color: Colors.black87, decoration: TextDecoration.none), + titleMedium: TextStyle(debugLabel: 'blackRedmond titleMedium', fontFamily: 'Segoe UI', color: Colors.black87, decoration: TextDecoration.none), + titleSmall: TextStyle(debugLabel: 'blackRedmond titleSmall', fontFamily: 'Segoe UI', color: Colors.black, decoration: TextDecoration.none), + bodyLarge: TextStyle(debugLabel: 'blackRedmond bodyLarge', fontFamily: 'Segoe UI', color: Colors.black87, decoration: TextDecoration.none), + bodyMedium: TextStyle(debugLabel: 'blackRedmond bodyMedium', fontFamily: 'Segoe UI', color: Colors.black87, decoration: TextDecoration.none), + bodySmall: TextStyle(debugLabel: 'blackRedmond bodySmall', fontFamily: 'Segoe UI', color: Colors.black54, decoration: TextDecoration.none), + labelLarge: TextStyle(debugLabel: 'blackRedmond labelLarge', fontFamily: 'Segoe UI', color: Colors.black87, decoration: TextDecoration.none), + labelMedium: TextStyle(debugLabel: 'blackRedmond labelMedium', fontFamily: 'Segoe UI', color: Colors.black, decoration: TextDecoration.none), + labelSmall: TextStyle(debugLabel: 'blackRedmond labelSmall', fontFamily: 'Segoe UI', color: Colors.black, decoration: TextDecoration.none), + ); + + /// A Material Design text theme with light glyphs based on Segoe UI. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + static const TextTheme whiteRedmond = TextTheme( + displayLarge: TextStyle(debugLabel: 'whiteRedmond displayLarge', fontFamily: 'Segoe UI', color: Colors.white70, decoration: TextDecoration.none), + displayMedium: TextStyle(debugLabel: 'whiteRedmond displayMedium', fontFamily: 'Segoe UI', color: Colors.white70, decoration: TextDecoration.none), + displaySmall: TextStyle(debugLabel: 'whiteRedmond displaySmall', fontFamily: 'Segoe UI', color: Colors.white70, decoration: TextDecoration.none), + headlineLarge: TextStyle(debugLabel: 'whiteRedmond headlineLarge', fontFamily: 'Segoe UI', color: Colors.white70, decoration: TextDecoration.none), + headlineMedium: TextStyle(debugLabel: 'whiteRedmond headlineMedium', fontFamily: 'Segoe UI', color: Colors.white70, decoration: TextDecoration.none), + headlineSmall: TextStyle(debugLabel: 'whiteRedmond headlineSmall', fontFamily: 'Segoe UI', color: Colors.white, decoration: TextDecoration.none), + titleLarge: TextStyle(debugLabel: 'whiteRedmond titleLarge', fontFamily: 'Segoe UI', color: Colors.white, decoration: TextDecoration.none), + titleMedium: TextStyle(debugLabel: 'whiteRedmond titleMedium', fontFamily: 'Segoe UI', color: Colors.white, decoration: TextDecoration.none), + titleSmall: TextStyle(debugLabel: 'whiteRedmond titleSmall', fontFamily: 'Segoe UI', color: Colors.white, decoration: TextDecoration.none), + bodyLarge: TextStyle(debugLabel: 'whiteRedmond bodyLarge', fontFamily: 'Segoe UI', color: Colors.white, decoration: TextDecoration.none), + bodyMedium: TextStyle(debugLabel: 'whiteRedmond bodyMedium', fontFamily: 'Segoe UI', color: Colors.white, decoration: TextDecoration.none), + bodySmall: TextStyle(debugLabel: 'whiteRedmond bodySmall', fontFamily: 'Segoe UI', color: Colors.white70, decoration: TextDecoration.none), + labelLarge: TextStyle(debugLabel: 'whiteRedmond labelLarge', fontFamily: 'Segoe UI', color: Colors.white, decoration: TextDecoration.none), + labelMedium: TextStyle(debugLabel: 'whiteRedmond labelMedium', fontFamily: 'Segoe UI', color: Colors.white, decoration: TextDecoration.none), + labelSmall: TextStyle(debugLabel: 'whiteRedmond labelSmall', fontFamily: 'Segoe UI', color: Colors.white, decoration: TextDecoration.none), + ); + + static const List<String> _helsinkiFontFallbacks = <String>['Ubuntu', 'Cantarell', 'DejaVu Sans', 'Liberation Sans', 'Arial']; + /// A Material Design text theme with dark glyphs based on Roboto, with + /// fallback fonts that are likely (but not guaranteed) to be installed on + /// Linux. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + static const TextTheme blackHelsinki = TextTheme( + displayLarge: TextStyle(debugLabel: 'blackHelsinki displayLarge', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black54, decoration: TextDecoration.none), + displayMedium: TextStyle(debugLabel: 'blackHelsinki displayMedium', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black54, decoration: TextDecoration.none), + displaySmall: TextStyle(debugLabel: 'blackHelsinki displaySmall', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black54, decoration: TextDecoration.none), + headlineLarge: TextStyle(debugLabel: 'blackHelsinki headlineLarge', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black54, decoration: TextDecoration.none), + headlineMedium: TextStyle(debugLabel: 'blackHelsinki headlineMedium', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black54, decoration: TextDecoration.none), + headlineSmall: TextStyle(debugLabel: 'blackHelsinki headlineSmall', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black87, decoration: TextDecoration.none), + titleLarge: TextStyle(debugLabel: 'blackHelsinki titleLarge', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black87, decoration: TextDecoration.none), + titleMedium: TextStyle(debugLabel: 'blackHelsinki titleMedium', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black87, decoration: TextDecoration.none), + titleSmall: TextStyle(debugLabel: 'blackHelsinki titleSmall', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black, decoration: TextDecoration.none), + bodyLarge: TextStyle(debugLabel: 'blackHelsinki bodyLarge', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black87, decoration: TextDecoration.none), + bodyMedium: TextStyle(debugLabel: 'blackHelsinki bodyMedium', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black87, decoration: TextDecoration.none), + bodySmall: TextStyle(debugLabel: 'blackHelsinki bodySmall', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black54, decoration: TextDecoration.none), + labelLarge: TextStyle(debugLabel: 'blackHelsinki labelLarge', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black87, decoration: TextDecoration.none), + labelMedium: TextStyle(debugLabel: 'blackHelsinki labelMedium', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black, decoration: TextDecoration.none), + labelSmall: TextStyle(debugLabel: 'blackHelsinki labelSmall', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.black, decoration: TextDecoration.none), + ); + + /// A Material Design text theme with light glyphs based on Roboto, with fallbacks of DejaVu Sans, Liberation Sans and Arial. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + static const TextTheme whiteHelsinki = TextTheme( + displayLarge: TextStyle(debugLabel: 'whiteHelsinki displayLarge', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white70, decoration: TextDecoration.none), + displayMedium: TextStyle(debugLabel: 'whiteHelsinki displayMedium', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white70, decoration: TextDecoration.none), + displaySmall: TextStyle(debugLabel: 'whiteHelsinki displaySmall', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white70, decoration: TextDecoration.none), + headlineLarge: TextStyle(debugLabel: 'whiteHelsinki headlineLarge', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white70, decoration: TextDecoration.none), + headlineMedium: TextStyle(debugLabel: 'whiteHelsinki headlineMedium', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white70, decoration: TextDecoration.none), + headlineSmall: TextStyle(debugLabel: 'whiteHelsinki headlineSmall', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white, decoration: TextDecoration.none), + titleLarge: TextStyle(debugLabel: 'whiteHelsinki titleLarge', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white, decoration: TextDecoration.none), + titleMedium: TextStyle(debugLabel: 'whiteHelsinki titleMedium', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white, decoration: TextDecoration.none), + titleSmall: TextStyle(debugLabel: 'whiteHelsinki titleSmall', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white, decoration: TextDecoration.none), + bodyLarge: TextStyle(debugLabel: 'whiteHelsinki bodyLarge', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white, decoration: TextDecoration.none), + bodyMedium: TextStyle(debugLabel: 'whiteHelsinki bodyMedium', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white, decoration: TextDecoration.none), + bodySmall: TextStyle(debugLabel: 'whiteHelsinki bodySmall', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white70, decoration: TextDecoration.none), + labelLarge: TextStyle(debugLabel: 'whiteHelsinki labelLarge', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white, decoration: TextDecoration.none), + labelMedium: TextStyle(debugLabel: 'whiteHelsinki labelMedium', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white, decoration: TextDecoration.none), + labelSmall: TextStyle(debugLabel: 'whiteHelsinki labelSmall', fontFamily: 'Roboto', fontFamilyFallback: _helsinkiFontFallbacks, color: Colors.white, decoration: TextDecoration.none), + ); + + /// A Material Design text theme with dark glyphs based on San Francisco. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + /// + /// This theme uses the iOS version of the font names. + static const TextTheme blackCupertino = TextTheme( + displayLarge: TextStyle(debugLabel: 'blackCupertino displayLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.black54, decoration: TextDecoration.none), + displayMedium: TextStyle(debugLabel: 'blackCupertino displayMedium', fontFamily: 'CupertinoSystemDisplay', color: Colors.black54, decoration: TextDecoration.none), + displaySmall: TextStyle(debugLabel: 'blackCupertino displaySmall', fontFamily: 'CupertinoSystemDisplay', color: Colors.black54, decoration: TextDecoration.none), + headlineLarge: TextStyle(debugLabel: 'blackCupertino headlineLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.black54, decoration: TextDecoration.none), + headlineMedium: TextStyle(debugLabel: 'blackCupertino headlineMedium', fontFamily: 'CupertinoSystemDisplay', color: Colors.black54, decoration: TextDecoration.none), + headlineSmall: TextStyle(debugLabel: 'blackCupertino headlineSmall', fontFamily: 'CupertinoSystemDisplay', color: Colors.black87, decoration: TextDecoration.none), + titleLarge: TextStyle(debugLabel: 'blackCupertino titleLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.black87, decoration: TextDecoration.none), + titleMedium: TextStyle(debugLabel: 'blackCupertino titleMedium', fontFamily: 'CupertinoSystemText', color: Colors.black87, decoration: TextDecoration.none), + titleSmall: TextStyle(debugLabel: 'blackCupertino titleSmall', fontFamily: 'CupertinoSystemText', color: Colors.black, decoration: TextDecoration.none), + bodyLarge: TextStyle(debugLabel: 'blackCupertino bodyLarge', fontFamily: 'CupertinoSystemText', color: Colors.black87, decoration: TextDecoration.none), + bodyMedium: TextStyle(debugLabel: 'blackCupertino bodyMedium', fontFamily: 'CupertinoSystemText', color: Colors.black87, decoration: TextDecoration.none), + bodySmall: TextStyle(debugLabel: 'blackCupertino bodySmall', fontFamily: 'CupertinoSystemText', color: Colors.black54, decoration: TextDecoration.none), + labelLarge: TextStyle(debugLabel: 'blackCupertino labelLarge', fontFamily: 'CupertinoSystemText', color: Colors.black87, decoration: TextDecoration.none), + labelMedium: TextStyle(debugLabel: 'blackCupertino labelMedium', fontFamily: 'CupertinoSystemText', color: Colors.black, decoration: TextDecoration.none), + labelSmall: TextStyle(debugLabel: 'blackCupertino labelSmall', fontFamily: 'CupertinoSystemText', color: Colors.black, decoration: TextDecoration.none), + ); + + /// A Material Design text theme with light glyphs based on San Francisco. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + /// + /// This theme uses the iOS version of the font names. + static const TextTheme whiteCupertino = TextTheme( + displayLarge: TextStyle(debugLabel: 'whiteCupertino displayLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.white70, decoration: TextDecoration.none), + displayMedium: TextStyle(debugLabel: 'whiteCupertino displayMedium', fontFamily: 'CupertinoSystemDisplay', color: Colors.white70, decoration: TextDecoration.none), + displaySmall: TextStyle(debugLabel: 'whiteCupertino displaySmall', fontFamily: 'CupertinoSystemDisplay', color: Colors.white70, decoration: TextDecoration.none), + headlineLarge: TextStyle(debugLabel: 'whiteCupertino headlineLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.white70, decoration: TextDecoration.none), + headlineMedium: TextStyle(debugLabel: 'whiteCupertino headlineMedium', fontFamily: 'CupertinoSystemDisplay', color: Colors.white70, decoration: TextDecoration.none), + headlineSmall: TextStyle(debugLabel: 'whiteCupertino headlineSmall', fontFamily: 'CupertinoSystemDisplay', color: Colors.white, decoration: TextDecoration.none), + titleLarge: TextStyle(debugLabel: 'whiteCupertino titleLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.white, decoration: TextDecoration.none), + titleMedium: TextStyle(debugLabel: 'whiteCupertino titleMedium', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none), + titleSmall: TextStyle(debugLabel: 'whiteCupertino titleSmall', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none), + bodyLarge: TextStyle(debugLabel: 'whiteCupertino bodyLarge', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none), + bodyMedium: TextStyle(debugLabel: 'whiteCupertino bodyMedium', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none), + bodySmall: TextStyle(debugLabel: 'whiteCupertino bodySmall', fontFamily: 'CupertinoSystemText', color: Colors.white70, decoration: TextDecoration.none), + labelLarge: TextStyle(debugLabel: 'whiteCupertino labelLarge', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none), + labelMedium: TextStyle(debugLabel: 'whiteCupertino labelMedium', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none), + labelSmall: TextStyle(debugLabel: 'whiteCupertino labelSmall', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none), + ); + + /// A Material Design text theme with dark glyphs based on San Francisco. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + /// + /// This theme uses the macOS version of the font names. + static const TextTheme blackRedwoodCity = TextTheme( + displayLarge: TextStyle(debugLabel: 'blackRedwoodCity displayLarge', fontFamily: '.AppleSystemUIFont', color: Colors.black54, decoration: TextDecoration.none), + displayMedium: TextStyle(debugLabel: 'blackRedwoodCity displayMedium', fontFamily: '.AppleSystemUIFont', color: Colors.black54, decoration: TextDecoration.none), + displaySmall: TextStyle(debugLabel: 'blackRedwoodCity displaySmall', fontFamily: '.AppleSystemUIFont', color: Colors.black54, decoration: TextDecoration.none), + headlineLarge: TextStyle(debugLabel: 'blackRedwoodCity headlineLarge', fontFamily: '.AppleSystemUIFont', color: Colors.black54, decoration: TextDecoration.none), + headlineMedium: TextStyle(debugLabel: 'blackRedwoodCity headlineMedium', fontFamily: '.AppleSystemUIFont', color: Colors.black54, decoration: TextDecoration.none), + headlineSmall: TextStyle(debugLabel: 'blackRedwoodCity headlineSmall', fontFamily: '.AppleSystemUIFont', color: Colors.black87, decoration: TextDecoration.none), + titleLarge: TextStyle(debugLabel: 'blackRedwoodCity titleLarge', fontFamily: '.AppleSystemUIFont', color: Colors.black87, decoration: TextDecoration.none), + titleMedium: TextStyle(debugLabel: 'blackRedwoodCity titleMedium', fontFamily: '.AppleSystemUIFont', color: Colors.black87, decoration: TextDecoration.none), + titleSmall: TextStyle(debugLabel: 'blackRedwoodCity titleSmall', fontFamily: '.AppleSystemUIFont', color: Colors.black, decoration: TextDecoration.none), + bodyLarge: TextStyle(debugLabel: 'blackRedwoodCity bodyLarge', fontFamily: '.AppleSystemUIFont', color: Colors.black87, decoration: TextDecoration.none), + bodyMedium: TextStyle(debugLabel: 'blackRedwoodCity bodyMedium', fontFamily: '.AppleSystemUIFont', color: Colors.black87, decoration: TextDecoration.none), + bodySmall: TextStyle(debugLabel: 'blackRedwoodCity bodySmall', fontFamily: '.AppleSystemUIFont', color: Colors.black54, decoration: TextDecoration.none), + labelLarge: TextStyle(debugLabel: 'blackRedwoodCity labelLarge', fontFamily: '.AppleSystemUIFont', color: Colors.black87, decoration: TextDecoration.none), + labelMedium: TextStyle(debugLabel: 'blackRedwoodCity labelMedium', fontFamily: '.AppleSystemUIFont', color: Colors.black, decoration: TextDecoration.none), + labelSmall: TextStyle(debugLabel: 'blackRedwoodCity labelSmall', fontFamily: '.AppleSystemUIFont', color: Colors.black, decoration: TextDecoration.none), + ); + + /// A Material Design text theme with light glyphs based on San Francisco. + /// + /// This [TextTheme] provides color but not geometry (font size, weight, etc). + /// + /// This theme uses the macOS version of the font names. + static const TextTheme whiteRedwoodCity = TextTheme( + displayLarge: TextStyle(debugLabel: 'whiteRedwoodCity displayLarge', fontFamily: '.AppleSystemUIFont', color: Colors.white70, decoration: TextDecoration.none), + displayMedium: TextStyle(debugLabel: 'whiteRedwoodCity displayMedium', fontFamily: '.AppleSystemUIFont', color: Colors.white70, decoration: TextDecoration.none), + displaySmall: TextStyle(debugLabel: 'whiteRedwoodCity displaySmall', fontFamily: '.AppleSystemUIFont', color: Colors.white70, decoration: TextDecoration.none), + headlineLarge: TextStyle(debugLabel: 'whiteRedwoodCity headlineLarge', fontFamily: '.AppleSystemUIFont', color: Colors.white70, decoration: TextDecoration.none), + headlineMedium: TextStyle(debugLabel: 'whiteRedwoodCity headlineMedium', fontFamily: '.AppleSystemUIFont', color: Colors.white70, decoration: TextDecoration.none), + headlineSmall: TextStyle(debugLabel: 'whiteRedwoodCity headlineSmall', fontFamily: '.AppleSystemUIFont', color: Colors.white, decoration: TextDecoration.none), + titleLarge: TextStyle(debugLabel: 'whiteRedwoodCity titleLarge', fontFamily: '.AppleSystemUIFont', color: Colors.white, decoration: TextDecoration.none), + titleMedium: TextStyle(debugLabel: 'whiteRedwoodCity titleMedium', fontFamily: '.AppleSystemUIFont', color: Colors.white, decoration: TextDecoration.none), + titleSmall: TextStyle(debugLabel: 'whiteRedwoodCity titleSmall', fontFamily: '.AppleSystemUIFont', color: Colors.white, decoration: TextDecoration.none), + bodyLarge: TextStyle(debugLabel: 'whiteRedwoodCity bodyLarge', fontFamily: '.AppleSystemUIFont', color: Colors.white, decoration: TextDecoration.none), + bodyMedium: TextStyle(debugLabel: 'whiteRedwoodCity bodyMedium', fontFamily: '.AppleSystemUIFont', color: Colors.white, decoration: TextDecoration.none), + bodySmall: TextStyle(debugLabel: 'whiteRedwoodCity bodySmall', fontFamily: '.AppleSystemUIFont', color: Colors.white70, decoration: TextDecoration.none), + labelLarge: TextStyle(debugLabel: 'whiteRedwoodCity labelLarge', fontFamily: '.AppleSystemUIFont', color: Colors.white, decoration: TextDecoration.none), + labelMedium: TextStyle(debugLabel: 'whiteRedwoodCity labelMedium', fontFamily: '.AppleSystemUIFont', color: Colors.white, decoration: TextDecoration.none), + labelSmall: TextStyle(debugLabel: 'whiteRedwoodCity labelSmall', fontFamily: '.AppleSystemUIFont', color: Colors.white, decoration: TextDecoration.none), + ); + + /// Defines text geometry for [ScriptCategory.englishLike] scripts, such as + /// English, French, Russian, etc. + static const TextTheme englishLike2014 = TextTheme( + displayLarge: TextStyle(debugLabel: 'englishLike displayLarge 2014', inherit: false, fontSize: 112.0, fontWeight: FontWeight.w100, textBaseline: TextBaseline.alphabetic), + displayMedium: TextStyle(debugLabel: 'englishLike displayMedium 2014', inherit: false, fontSize: 56.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + displaySmall: TextStyle(debugLabel: 'englishLike displaySmall 2014', inherit: false, fontSize: 45.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + headlineLarge: TextStyle(debugLabel: 'englishLike headlineLarge 2014', inherit: false, fontSize: 40.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + headlineMedium: TextStyle(debugLabel: 'englishLike headlineMedium 2014', inherit: false, fontSize: 34.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + headlineSmall: TextStyle(debugLabel: 'englishLike headlineSmall 2014', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + titleLarge: TextStyle(debugLabel: 'englishLike titleLarge 2014', inherit: false, fontSize: 20.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.alphabetic), + titleMedium: TextStyle(debugLabel: 'englishLike titleMedium 2014', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + titleSmall: TextStyle(debugLabel: 'englishLike titleSmall 2014', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.1), + bodyLarge: TextStyle(debugLabel: 'englishLike bodyLarge 2014', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.alphabetic), + bodyMedium: TextStyle(debugLabel: 'englishLike bodyMedium 2014', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + bodySmall: TextStyle(debugLabel: 'englishLike bodySmall 2014', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + labelLarge: TextStyle(debugLabel: 'englishLike labelLarge 2014', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.alphabetic), + labelMedium: TextStyle(debugLabel: 'englishLike labelMedium 2014', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + labelSmall: TextStyle(debugLabel: 'englishLike labelSmall 2014', inherit: false, fontSize: 10.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 1.5), + ); + + /// Defines text geometry for [ScriptCategory.englishLike] scripts, such as + /// English, French, Russian, etc. + /// + /// The font sizes, weights, and letter spacings in this version match the + /// [2018 Material Design specification](https://material.io/go/design-typography#typography-styles). + static const TextTheme englishLike2018 = TextTheme( + displayLarge: TextStyle(debugLabel: 'englishLike displayLarge 2018', inherit: false, fontSize: 96.0, fontWeight: FontWeight.w300, textBaseline: TextBaseline.alphabetic, letterSpacing: -1.5), + displayMedium: TextStyle(debugLabel: 'englishLike displayMedium 2018', inherit: false, fontSize: 60.0, fontWeight: FontWeight.w300, textBaseline: TextBaseline.alphabetic, letterSpacing: -0.5), + displaySmall: TextStyle(debugLabel: 'englishLike displaySmall 2018', inherit: false, fontSize: 48.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.0), + headlineLarge: TextStyle(debugLabel: 'englishLike headlineLarge 2018', inherit: false, fontSize: 40.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.25), + headlineMedium: TextStyle(debugLabel: 'englishLike headlineMedium 2018', inherit: false, fontSize: 34.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.25), + headlineSmall: TextStyle(debugLabel: 'englishLike headlineSmall 2018', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.0), + titleLarge: TextStyle(debugLabel: 'englishLike titleLarge 2018', inherit: false, fontSize: 20.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.15), + titleMedium: TextStyle(debugLabel: 'englishLike titleMedium 2018', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.15), + titleSmall: TextStyle(debugLabel: 'englishLike titleSmall 2018', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.1), + bodyLarge: TextStyle(debugLabel: 'englishLike bodyLarge 2018', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.5), + bodyMedium: TextStyle(debugLabel: 'englishLike bodyMedium 2018', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.25), + bodySmall: TextStyle(debugLabel: 'englishLike bodySmall 2018', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 0.4), + labelLarge: TextStyle(debugLabel: 'englishLike labelLarge 2018', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.alphabetic, letterSpacing: 1.25), + labelMedium: TextStyle(debugLabel: 'englishLike labelMedium 2018', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 1.5), + labelSmall: TextStyle(debugLabel: 'englishLike labelSmall 2018', inherit: false, fontSize: 10.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic, letterSpacing: 1.5), + ); + + /// Defines text geometry for dense scripts, such as Chinese, Japanese + /// and Korean. + static const TextTheme dense2014 = TextTheme( + displayLarge: TextStyle(debugLabel: 'dense displayLarge 2014', inherit: false, fontSize: 112.0, fontWeight: FontWeight.w100, textBaseline: TextBaseline.ideographic), + displayMedium: TextStyle(debugLabel: 'dense displayMedium 2014', inherit: false, fontSize: 56.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + displaySmall: TextStyle(debugLabel: 'dense displaySmall 2014', inherit: false, fontSize: 45.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + headlineLarge: TextStyle(debugLabel: 'dense headlineLarge 2014', inherit: false, fontSize: 40.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + headlineMedium: TextStyle(debugLabel: 'dense headlineMedium 2014', inherit: false, fontSize: 34.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + headlineSmall: TextStyle(debugLabel: 'dense headlineSmall 2014', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + titleLarge: TextStyle(debugLabel: 'dense titleLarge 2014', inherit: false, fontSize: 21.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.ideographic), + titleMedium: TextStyle(debugLabel: 'dense titleMedium 2014', inherit: false, fontSize: 17.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + titleSmall: TextStyle(debugLabel: 'dense titleSmall 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.ideographic), + bodyLarge: TextStyle(debugLabel: 'dense bodyLarge 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.ideographic), + bodyMedium: TextStyle(debugLabel: 'dense bodyMedium 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + bodySmall: TextStyle(debugLabel: 'dense bodySmall 2014', inherit: false, fontSize: 13.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + labelLarge: TextStyle(debugLabel: 'dense labelLarge 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.ideographic), + labelMedium: TextStyle(debugLabel: 'dense labelMedium 2014', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + labelSmall: TextStyle(debugLabel: 'dense labelSmall 2014', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + ); + + /// Defines text geometry for dense scripts, such as Chinese, Japanese + /// and Korean. + /// + /// The font sizes, weights, and letter spacings in this version match the + /// 2018 [Material Design specification](https://material.io/go/design-typography#typography-styles). + static const TextTheme dense2018 = TextTheme( + displayLarge: TextStyle(debugLabel: 'dense displayLarge 2018', inherit: false, fontSize: 96.0, fontWeight: FontWeight.w100, textBaseline: TextBaseline.ideographic), + displayMedium: TextStyle(debugLabel: 'dense displayMedium 2018', inherit: false, fontSize: 60.0, fontWeight: FontWeight.w100, textBaseline: TextBaseline.ideographic), + displaySmall: TextStyle(debugLabel: 'dense displaySmall 2018', inherit: false, fontSize: 48.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + headlineLarge: TextStyle(debugLabel: 'dense headlineLarge 2018', inherit: false, fontSize: 40.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + headlineMedium: TextStyle(debugLabel: 'dense headlineMedium 2018', inherit: false, fontSize: 34.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + headlineSmall: TextStyle(debugLabel: 'dense headlineSmall 2018', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + titleLarge: TextStyle(debugLabel: 'dense titleLarge 2018', inherit: false, fontSize: 21.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.ideographic), + titleMedium: TextStyle(debugLabel: 'dense titleMedium 2018', inherit: false, fontSize: 17.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + titleSmall: TextStyle(debugLabel: 'dense titleSmall 2018', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.ideographic), + bodyLarge: TextStyle(debugLabel: 'dense bodyLarge 2018', inherit: false, fontSize: 17.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + bodyMedium: TextStyle(debugLabel: 'dense bodyMedium 2018', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + bodySmall: TextStyle(debugLabel: 'dense bodySmall 2018', inherit: false, fontSize: 13.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + labelLarge: TextStyle(debugLabel: 'dense labelLarge 2018', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.ideographic), + labelMedium: TextStyle(debugLabel: 'dense labelMedium 2018', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + labelSmall: TextStyle(debugLabel: 'dense labelSmall 2018', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic), + ); + + /// Defines text geometry for tall scripts, such as Farsi, Hindi, and Thai. + static const TextTheme tall2014 = TextTheme( + displayLarge: TextStyle(debugLabel: 'tall displayLarge 2014', inherit: false, fontSize: 112.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + displayMedium: TextStyle(debugLabel: 'tall displayMedium 2014', inherit: false, fontSize: 56.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + displaySmall: TextStyle(debugLabel: 'tall displaySmall 2014', inherit: false, fontSize: 45.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + headlineLarge: TextStyle(debugLabel: 'tall headlineLarge 2014', inherit: false, fontSize: 40.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + headlineMedium: TextStyle(debugLabel: 'tall headlineMedium 2014', inherit: false, fontSize: 34.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + headlineSmall: TextStyle(debugLabel: 'tall headlineSmall 2014', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + titleLarge: TextStyle(debugLabel: 'tall titleLarge 2014', inherit: false, fontSize: 21.0, fontWeight: FontWeight.w700, textBaseline: TextBaseline.alphabetic), + titleMedium: TextStyle(debugLabel: 'tall titleMedium 2014', inherit: false, fontSize: 17.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + titleSmall: TextStyle(debugLabel: 'tall titleSmall 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.alphabetic), + bodyLarge: TextStyle(debugLabel: 'tall bodyLarge 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w700, textBaseline: TextBaseline.alphabetic), + bodyMedium: TextStyle(debugLabel: 'tall bodyMedium 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + bodySmall: TextStyle(debugLabel: 'tall bodySmall 2014', inherit: false, fontSize: 13.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + labelLarge: TextStyle(debugLabel: 'tall labelLarge 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w700, textBaseline: TextBaseline.alphabetic), + labelMedium: TextStyle(debugLabel: 'tall labelMedium 2014', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + labelSmall: TextStyle(debugLabel: 'tall labelSmall 2014', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + ); + + /// Defines text geometry for tall scripts, such as Farsi, Hindi, and Thai. + /// + /// The font sizes, weights, and letter spacings in this version match the + /// 2018 [Material Design specification](https://material.io/go/design-typography#typography-styles). + static const TextTheme tall2018 = TextTheme( + displayLarge: TextStyle(debugLabel: 'tall displayLarge 2018', inherit: false, fontSize: 96.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + displayMedium: TextStyle(debugLabel: 'tall displayMedium 2018', inherit: false, fontSize: 60.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + displaySmall: TextStyle(debugLabel: 'tall displaySmall 2018', inherit: false, fontSize: 48.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + headlineLarge: TextStyle(debugLabel: 'tall headlineLarge 2018', inherit: false, fontSize: 40.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + headlineMedium: TextStyle(debugLabel: 'tall headlineMedium 2018', inherit: false, fontSize: 34.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + headlineSmall: TextStyle(debugLabel: 'tall headlineSmall 2018', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + titleLarge: TextStyle(debugLabel: 'tall titleLarge 2018', inherit: false, fontSize: 21.0, fontWeight: FontWeight.w700, textBaseline: TextBaseline.alphabetic), + titleMedium : TextStyle(debugLabel: 'tall titleMedium 2018', inherit: false, fontSize: 17.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + titleSmall: TextStyle(debugLabel: 'tall titleSmall 2018', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.alphabetic), + bodyLarge: TextStyle(debugLabel: 'tall bodyLarge 2018', inherit: false, fontSize: 17.0, fontWeight: FontWeight.w700, textBaseline: TextBaseline.alphabetic), + bodyMedium: TextStyle(debugLabel: 'tall bodyMedium 2018', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + bodySmall: TextStyle(debugLabel: 'tall bodySmall 2018', inherit: false, fontSize: 13.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + labelLarge: TextStyle(debugLabel: 'tall labelLarge 2018', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w700, textBaseline: TextBaseline.alphabetic), + labelMedium: TextStyle(debugLabel: 'tall labelMedium 2018', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + labelSmall: TextStyle(debugLabel: 'tall labelSmall 2018', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.alphabetic), + ); + + /// Defines text geometry for [ScriptCategory.englishLike] scripts, such as + /// English, French, Russian, etc. + /// + /// The font sizes, weights, and letter spacings in this version match the + /// [2021 Material Design 3 specification](https://m3.material.io/styles/typography/overview). + static const TextTheme englishLike2021 = _M3Typography.englishLike; + + /// Defines text geometry for dense scripts, such as Chinese, Japanese + /// and Korean. + /// + /// The Material Design 3 specification does not include 'dense' text themes, + /// so this is just here to be consistent with the API. + static const TextTheme dense2021 = _M3Typography.dense; + + /// Defines text geometry for tall scripts, such as Farsi, Hindi, and Thai. + /// + /// The Material Design 3 specification does not include 'tall' text themes, + /// so this is just here to be consistent with the API. + static const TextTheme tall2021 = _M3Typography.tall; +} + +// BEGIN GENERATED TOKEN PROPERTIES - Typography + +// Do not edit by hand. The code between the "BEGIN GENERATED" and +// "END GENERATED" comments are generated from data in the Material +// Design token database by the script: +// dev/tools/gen_defaults/bin/gen_defaults.dart. + +class _M3Typography { + _M3Typography._(); + + static const TextTheme englishLike = TextTheme( + displayLarge: TextStyle(debugLabel: 'englishLike displayLarge 2021', inherit: false, fontSize: 57.0, fontWeight: FontWeight.w400, letterSpacing: -0.25, height: 1.12, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + displayMedium: TextStyle(debugLabel: 'englishLike displayMedium 2021', inherit: false, fontSize: 45.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.16, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + displaySmall: TextStyle(debugLabel: 'englishLike displaySmall 2021', inherit: false, fontSize: 36.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.22, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + headlineLarge: TextStyle(debugLabel: 'englishLike headlineLarge 2021', inherit: false, fontSize: 32.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.25, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + headlineMedium: TextStyle(debugLabel: 'englishLike headlineMedium 2021', inherit: false, fontSize: 28.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.29, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + headlineSmall: TextStyle(debugLabel: 'englishLike headlineSmall 2021', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + titleLarge: TextStyle(debugLabel: 'englishLike titleLarge 2021', inherit: false, fontSize: 22.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.27, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + titleMedium: TextStyle(debugLabel: 'englishLike titleMedium 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w500, letterSpacing: 0.15, height: 1.50, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + titleSmall: TextStyle(debugLabel: 'englishLike titleSmall 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + labelLarge: TextStyle(debugLabel: 'englishLike labelLarge 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + labelMedium: TextStyle(debugLabel: 'englishLike labelMedium 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + labelSmall: TextStyle(debugLabel: 'englishLike labelSmall 2021', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.45, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + bodyLarge: TextStyle(debugLabel: 'englishLike bodyLarge 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, letterSpacing: 0.5, height: 1.50, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + bodyMedium: TextStyle(debugLabel: 'englishLike bodyMedium 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w400, letterSpacing: 0.25, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + bodySmall: TextStyle(debugLabel: 'englishLike bodySmall 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, letterSpacing: 0.4, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + ); + + static const TextTheme dense = TextTheme( + displayLarge: TextStyle(debugLabel: 'dense displayLarge 2021', inherit: false, fontSize: 57.0, fontWeight: FontWeight.w400, letterSpacing: -0.25, height: 1.12, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + displayMedium: TextStyle(debugLabel: 'dense displayMedium 2021', inherit: false, fontSize: 45.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.16, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + displaySmall: TextStyle(debugLabel: 'dense displaySmall 2021', inherit: false, fontSize: 36.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.22, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + headlineLarge: TextStyle(debugLabel: 'dense headlineLarge 2021', inherit: false, fontSize: 32.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.25, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + headlineMedium: TextStyle(debugLabel: 'dense headlineMedium 2021', inherit: false, fontSize: 28.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.29, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + headlineSmall: TextStyle(debugLabel: 'dense headlineSmall 2021', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.33, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + titleLarge: TextStyle(debugLabel: 'dense titleLarge 2021', inherit: false, fontSize: 22.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.27, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + titleMedium: TextStyle(debugLabel: 'dense titleMedium 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w500, letterSpacing: 0.15, height: 1.50, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + titleSmall: TextStyle(debugLabel: 'dense titleSmall 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + labelLarge: TextStyle(debugLabel: 'dense labelLarge 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + labelMedium: TextStyle(debugLabel: 'dense labelMedium 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.33, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + labelSmall: TextStyle(debugLabel: 'dense labelSmall 2021', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.45, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + bodyLarge: TextStyle(debugLabel: 'dense bodyLarge 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, letterSpacing: 0.5, height: 1.50, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + bodyMedium: TextStyle(debugLabel: 'dense bodyMedium 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w400, letterSpacing: 0.25, height: 1.43, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + bodySmall: TextStyle(debugLabel: 'dense bodySmall 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, letterSpacing: 0.4, height: 1.33, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even), + ); + + static const TextTheme tall = TextTheme( + displayLarge: TextStyle(debugLabel: 'tall displayLarge 2021', inherit: false, fontSize: 57.0, fontWeight: FontWeight.w400, letterSpacing: -0.25, height: 1.12, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + displayMedium: TextStyle(debugLabel: 'tall displayMedium 2021', inherit: false, fontSize: 45.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.16, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + displaySmall: TextStyle(debugLabel: 'tall displaySmall 2021', inherit: false, fontSize: 36.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.22, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + headlineLarge: TextStyle(debugLabel: 'tall headlineLarge 2021', inherit: false, fontSize: 32.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.25, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + headlineMedium: TextStyle(debugLabel: 'tall headlineMedium 2021', inherit: false, fontSize: 28.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.29, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + headlineSmall: TextStyle(debugLabel: 'tall headlineSmall 2021', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + titleLarge: TextStyle(debugLabel: 'tall titleLarge 2021', inherit: false, fontSize: 22.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.27, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + titleMedium: TextStyle(debugLabel: 'tall titleMedium 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w500, letterSpacing: 0.15, height: 1.50, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + titleSmall: TextStyle(debugLabel: 'tall titleSmall 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + labelLarge: TextStyle(debugLabel: 'tall labelLarge 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + labelMedium: TextStyle(debugLabel: 'tall labelMedium 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + labelSmall: TextStyle(debugLabel: 'tall labelSmall 2021', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.45, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + bodyLarge: TextStyle(debugLabel: 'tall bodyLarge 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, letterSpacing: 0.5, height: 1.50, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + bodyMedium: TextStyle(debugLabel: 'tall bodyMedium 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w400, letterSpacing: 0.25, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + bodySmall: TextStyle(debugLabel: 'tall bodySmall 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, letterSpacing: 0.4, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), + ); +} + +// END GENERATED TOKEN PROPERTIES - Typography diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/user_accounts_drawer_header.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/user_accounts_drawer_header.dart new file mode 100644 index 0000000000000000000000000000000000000000..97445ef40530886385e6b87981663003b82f12cc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/material/user_accounts_drawer_header.dart @@ -0,0 +1,402 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/widgets.dart'; + +import 'colors.dart'; +import 'debug.dart'; +import 'drawer_header.dart'; +import 'icons.dart'; +import 'ink_well.dart'; +import 'material_localizations.dart'; +import 'theme.dart'; + +class _AccountPictures extends StatelessWidget { + const _AccountPictures({ + this.currentAccountPicture, + this.otherAccountsPictures, + this.currentAccountPictureSize, + this.otherAccountsPicturesSize, + }); + + final Widget? currentAccountPicture; + final List<Widget>? otherAccountsPictures; + final Size? currentAccountPictureSize; + final Size? otherAccountsPicturesSize; + + @override + Widget build(BuildContext context) { + return Stack( + children: <Widget>[ + PositionedDirectional( + top: 0.0, + end: 0.0, + child: Row( + children: (otherAccountsPictures ?? <Widget>[]).take(3).map<Widget>((Widget picture) { + return Padding( + padding: const EdgeInsetsDirectional.only(start: 8.0), + child: Semantics( + container: true, + child: Padding( + padding: const EdgeInsets.only(left: 8.0, bottom: 8.0), + child: SizedBox.fromSize( + size: otherAccountsPicturesSize, + child: picture, + ), + ), + ), + ); + }).toList(), + ), + ), + Positioned( + top: 0.0, + child: Semantics( + explicitChildNodes: true, + child: SizedBox.fromSize( + size: currentAccountPictureSize, + child: currentAccountPicture, + ), + ), + ), + ], + ); + } +} + +class _AccountDetails extends StatefulWidget { + const _AccountDetails({ + required this.accountName, + required this.accountEmail, + this.onTap, + required this.isOpen, + this.arrowColor, + }); + + final Widget? accountName; + final Widget? accountEmail; + final VoidCallback? onTap; + final bool isOpen; + final Color? arrowColor; + + @override + _AccountDetailsState createState() => _AccountDetailsState(); +} + +class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProviderStateMixin { + late Animation<double> _animation; + late AnimationController _controller; + @override + void initState () { + super.initState(); + _controller = AnimationController( + value: widget.isOpen ? 1.0 : 0.0, + duration: const Duration(milliseconds: 200), + vsync: this, + ); + _animation = CurvedAnimation( + parent: _controller, + curve: Curves.fastOutSlowIn, + reverseCurve: Curves.fastOutSlowIn.flipped, + ) + ..addListener(() => setState(() { + // [animation]'s value has changed here. + })); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + void didUpdateWidget (_AccountDetails oldWidget) { + super.didUpdateWidget(oldWidget); + // If the state of the arrow did not change, there is no need to trigger the animation + if (oldWidget.isOpen == widget.isOpen) { + return; + } + + if (widget.isOpen) { + _controller.forward(); + } else { + _controller.reverse(); + } + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + assert(debugCheckHasMaterialLocalizations(context)); + assert(debugCheckHasMaterialLocalizations(context)); + + final ThemeData theme = Theme.of(context); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + + Widget accountDetails = CustomMultiChildLayout( + delegate: _AccountDetailsLayout( + textDirection: Directionality.of(context), + ), + children: <Widget>[ + if (widget.accountName != null) + LayoutId( + id: _AccountDetailsLayout.accountName, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 2.0), + child: DefaultTextStyle( + style: theme.primaryTextTheme.bodyLarge!, + overflow: TextOverflow.ellipsis, + child: widget.accountName!, + ), + ), + ), + if (widget.accountEmail != null) + LayoutId( + id: _AccountDetailsLayout.accountEmail, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 2.0), + child: DefaultTextStyle( + style: theme.primaryTextTheme.bodyMedium!, + overflow: TextOverflow.ellipsis, + child: widget.accountEmail!, + ), + ), + ), + if (widget.onTap != null) + LayoutId( + id: _AccountDetailsLayout.dropdownIcon, + child: Semantics( + container: true, + button: true, + onTap: widget.onTap, + child: SizedBox( + height: _kAccountDetailsHeight, + width: _kAccountDetailsHeight, + child: Center( + child: Transform.rotate( + angle: _animation.value * math.pi, + child: Icon( + Icons.arrow_drop_down, + color: widget.arrowColor, + semanticLabel: widget.isOpen + ? localizations.hideAccountsLabel + : localizations.showAccountsLabel, + ), + ), + ), + ), + ), + ), + ], + ); + + if (widget.onTap != null) { + accountDetails = InkWell( + onTap: widget.onTap, + excludeFromSemantics: true, + child: accountDetails, + ); + } + + return SizedBox( + height: _kAccountDetailsHeight, + child: accountDetails, + ); + } +} + +const double _kAccountDetailsHeight = 56.0; + +class _AccountDetailsLayout extends MultiChildLayoutDelegate { + + _AccountDetailsLayout({ required this.textDirection }); + + static const String accountName = 'accountName'; + static const String accountEmail = 'accountEmail'; + static const String dropdownIcon = 'dropdownIcon'; + + final TextDirection textDirection; + + @override + void performLayout(Size size) { + Size? iconSize; + if (hasChild(dropdownIcon)) { + // place the dropdown icon in bottom right (LTR) or bottom left (RTL) + iconSize = layoutChild(dropdownIcon, BoxConstraints.loose(size)); + positionChild(dropdownIcon, _offsetForIcon(size, iconSize)); + } + + final String? bottomLine = hasChild(accountEmail) ? accountEmail : (hasChild(accountName) ? accountName : null); + + if (bottomLine != null) { + final Size constraintSize = iconSize == null ? size : Size(size.width - iconSize.width, size.height); + iconSize ??= const Size(_kAccountDetailsHeight, _kAccountDetailsHeight); + + // place bottom line center at same height as icon center + final Size bottomLineSize = layoutChild(bottomLine, BoxConstraints.loose(constraintSize)); + final Offset bottomLineOffset = _offsetForBottomLine(size, iconSize, bottomLineSize); + positionChild(bottomLine, bottomLineOffset); + + // place account name above account email + if (bottomLine == accountEmail && hasChild(accountName)) { + final Size nameSize = layoutChild(accountName, BoxConstraints.loose(constraintSize)); + positionChild(accountName, _offsetForName(size, nameSize, bottomLineOffset)); + } + } + } + + @override + bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) => true; + + Offset _offsetForIcon(Size size, Size iconSize) { + switch (textDirection) { + case TextDirection.ltr: + return Offset(size.width - iconSize.width, size.height - iconSize.height); + case TextDirection.rtl: + return Offset(0.0, size.height - iconSize.height); + } + } + + Offset _offsetForBottomLine(Size size, Size iconSize, Size bottomLineSize) { + final double y = size.height - 0.5 * iconSize.height - 0.5 * bottomLineSize.height; + switch (textDirection) { + case TextDirection.ltr: + return Offset(0.0, y); + case TextDirection.rtl: + return Offset(size.width - bottomLineSize.width, y); + } + } + + Offset _offsetForName(Size size, Size nameSize, Offset bottomLineOffset) { + final double y = bottomLineOffset.dy - nameSize.height; + switch (textDirection) { + case TextDirection.ltr: + return Offset(0.0, y); + case TextDirection.rtl: + return Offset(size.width - nameSize.width, y); + } + } +} + +/// A Material Design [Drawer] header that identifies the app's user. +/// +/// Requires one of its ancestors to be a [Material] widget. +/// +/// See also: +/// +/// * [DrawerHeader], for a drawer header that doesn't show user accounts. +/// * <https://material.io/design/components/navigation-drawer.html#anatomy> +class UserAccountsDrawerHeader extends StatefulWidget { + /// Creates a Material Design drawer header. + /// + /// Requires one of its ancestors to be a [Material] widget. + const UserAccountsDrawerHeader({ + super.key, + this.decoration, + this.margin = const EdgeInsets.only(bottom: 8.0), + this.currentAccountPicture, + this.otherAccountsPictures, + this.currentAccountPictureSize = const Size.square(72.0), + this.otherAccountsPicturesSize = const Size.square(40.0), + required this.accountName, + required this.accountEmail, + this.onDetailsPressed, + this.arrowColor = Colors.white, + }); + + /// The header's background. If decoration is null then a [BoxDecoration] + /// with its background color set to the current theme's primaryColor is used. + final Decoration? decoration; + + /// The margin around the drawer header. + final EdgeInsetsGeometry? margin; + + /// A widget placed in the upper-left corner that represents the current + /// user's account. Normally a [CircleAvatar]. + final Widget? currentAccountPicture; + + /// A list of widgets that represent the current user's other accounts. + /// Up to three of these widgets will be arranged in a row in the header's + /// upper-right corner. Normally a list of [CircleAvatar] widgets. + final List<Widget>? otherAccountsPictures; + + /// The size of the [currentAccountPicture]. + final Size currentAccountPictureSize; + + /// The size of each widget in [otherAccountsPicturesSize]. + final Size otherAccountsPicturesSize; + + /// A widget that represents the user's current account name. It is + /// displayed on the left, below the [currentAccountPicture]. + final Widget? accountName; + + /// A widget that represents the email address of the user's current account. + /// It is displayed on the left, below the [accountName]. + final Widget? accountEmail; + + /// A callback that is called when the horizontal area which contains the + /// [accountName] and [accountEmail] is tapped. + final VoidCallback? onDetailsPressed; + + /// The [Color] of the arrow icon. + final Color arrowColor; + + @override + State<UserAccountsDrawerHeader> createState() => _UserAccountsDrawerHeaderState(); +} + +class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> { + bool _isOpen = false; + + void _handleDetailsPressed() { + setState(() { + _isOpen = !_isOpen; + }); + widget.onDetailsPressed!(); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterial(context)); + assert(debugCheckHasMaterialLocalizations(context)); + return Semantics( + container: true, + label: MaterialLocalizations.of(context).signedInLabel, + child: DrawerHeader( + decoration: widget.decoration ?? BoxDecoration(color: Theme.of(context).colorScheme.primary), + margin: widget.margin, + padding: const EdgeInsetsDirectional.only(top: 16.0, start: 16.0), + child: SafeArea( + bottom: false, + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: <Widget>[ + Expanded( + child: Padding( + padding: const EdgeInsetsDirectional.only(end: 16.0), + child: _AccountPictures( + currentAccountPicture: widget.currentAccountPicture, + otherAccountsPictures: widget.otherAccountsPictures, + currentAccountPictureSize: widget.currentAccountPictureSize, + otherAccountsPicturesSize: widget.otherAccountsPicturesSize, + ), + ), + ), + _AccountDetails( + accountName: widget.accountName, + accountEmail: widget.accountEmail, + isOpen: _isOpen, + onTap: widget.onDetailsPressed == null ? null : _handleDetailsPressed, + arrowColor: widget.arrowColor, + ), + ], + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/_network_image_io.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/_network_image_io.dart new file mode 100644 index 0000000000000000000000000000000000000000..a1fbb3f6e7a9994ab66f721ce35bf27c018f2974 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/_network_image_io.dart @@ -0,0 +1,160 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:io'; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; + +import 'binding.dart'; +import 'debug.dart'; +import 'image_provider.dart' as image_provider; +import 'image_stream.dart'; + +// Method signature for _loadAsync decode callbacks. +typedef _SimpleDecoderCallback = Future<ui.Codec> Function(ui.ImmutableBuffer buffer); + +/// The dart:io implementation of [image_provider.NetworkImage]. +@immutable +class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkImage> implements image_provider.NetworkImage { + /// Creates an object that fetches the image at the given URL. + const NetworkImage(this.url, { this.scale = 1.0, this.headers }); + + @override + final String url; + + @override + final double scale; + + @override + final Map<String, String>? headers; + + @override + Future<NetworkImage> obtainKey(image_provider.ImageConfiguration configuration) { + return SynchronousFuture<NetworkImage>(this); + } + + @override + ImageStreamCompleter loadBuffer(image_provider.NetworkImage key, image_provider.DecoderBufferCallback decode) { + // Ownership of this controller is handed off to [_loadAsync]; it is that + // method's responsibility to close the controller's stream when the image + // has been loaded or an error is thrown. + final StreamController<ImageChunkEvent> chunkEvents = StreamController<ImageChunkEvent>(); + + return MultiFrameImageStreamCompleter( + codec: _loadAsync(key as NetworkImage, chunkEvents, decode: decode), + chunkEvents: chunkEvents.stream, + scale: key.scale, + debugLabel: key.url, + informationCollector: () => <DiagnosticsNode>[ + DiagnosticsProperty<image_provider.ImageProvider>('Image provider', this), + DiagnosticsProperty<image_provider.NetworkImage>('Image key', key), + ], + ); + } + + @override + ImageStreamCompleter loadImage(image_provider.NetworkImage key, image_provider.ImageDecoderCallback decode) { + // Ownership of this controller is handed off to [_loadAsync]; it is that + // method's responsibility to close the controller's stream when the image + // has been loaded or an error is thrown. + final StreamController<ImageChunkEvent> chunkEvents = StreamController<ImageChunkEvent>(); + + return MultiFrameImageStreamCompleter( + codec: _loadAsync(key as NetworkImage, chunkEvents, decode: decode), + chunkEvents: chunkEvents.stream, + scale: key.scale, + debugLabel: key.url, + informationCollector: () => <DiagnosticsNode>[ + DiagnosticsProperty<image_provider.ImageProvider>('Image provider', this), + DiagnosticsProperty<image_provider.NetworkImage>('Image key', key), + ], + ); + } + + // Do not access this field directly; use [_httpClient] instead. + // We set `autoUncompress` to false to ensure that we can trust the value of + // the `Content-Length` HTTP header. We automatically uncompress the content + // in our call to [consolidateHttpClientResponseBytes]. + static final HttpClient _sharedHttpClient = HttpClient()..autoUncompress = false; + + static HttpClient get _httpClient { + HttpClient? client; + assert(() { + if (debugNetworkImageHttpClientProvider != null) { + client = debugNetworkImageHttpClientProvider!(); + } + return true; + }()); + return client ?? _sharedHttpClient; + } + + Future<ui.Codec> _loadAsync( + NetworkImage key, + StreamController<ImageChunkEvent> chunkEvents, { + required _SimpleDecoderCallback decode, + }) async { + try { + assert(key == this); + + final Uri resolved = Uri.base.resolve(key.url); + + final HttpClientRequest request = await _httpClient.getUrl(resolved); + + headers?.forEach((String name, String value) { + request.headers.add(name, value); + }); + final HttpClientResponse response = await request.close(); + if (response.statusCode != HttpStatus.ok) { + // The network may be only temporarily unavailable, or the file will be + // added on the server later. Avoid having future calls to resolve + // fail to check the network again. + await response.drain<List<int>>(<int>[]); + throw image_provider.NetworkImageLoadException(statusCode: response.statusCode, uri: resolved); + } + + final Uint8List bytes = await consolidateHttpClientResponseBytes( + response, + onBytesReceived: (int cumulative, int? total) { + chunkEvents.add(ImageChunkEvent( + cumulativeBytesLoaded: cumulative, + expectedTotalBytes: total, + )); + }, + ); + if (bytes.lengthInBytes == 0) { + throw Exception('NetworkImage is an empty file: $resolved'); + } + + return decode(await ui.ImmutableBuffer.fromUint8List(bytes)); + } catch (e) { + // Depending on where the exception was thrown, the image cache may not + // have had a chance to track the key in the cache at all. + // Schedule a microtask to give the cache a chance to add the key. + scheduleMicrotask(() { + PaintingBinding.instance.imageCache.evict(key); + }); + rethrow; + } finally { + chunkEvents.close(); + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is NetworkImage + && other.url == url + && other.scale == scale; + } + + @override + int get hashCode => Object.hash(url, scale); + + @override + String toString() => '${objectRuntimeType(this, 'NetworkImage')}("$url", scale: ${scale.toStringAsFixed(1)})'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/_network_image_web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/_network_image_web.dart new file mode 100644 index 0000000000000000000000000000000000000000..5e2cc90213ee3ec4f41289c30477df4651191c7e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/_network_image_web.dart @@ -0,0 +1,189 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:js_interop'; +import 'dart:ui' as ui; +import 'dart:ui_web' as ui_web; + +import 'package:flutter/foundation.dart'; + +import '../web.dart' as web; +import 'image_provider.dart' as image_provider; +import 'image_stream.dart'; + +/// Creates a type for an overridable factory function for testing purposes. +typedef HttpRequestFactory = web.XMLHttpRequest Function(); + +// Method signature for _loadAsync decode callbacks. +typedef _SimpleDecoderCallback = Future<ui.Codec> Function(ui.ImmutableBuffer buffer); + +/// Default HTTP client. +web.XMLHttpRequest _httpClient() { + return web.XMLHttpRequest(); +} + +/// Creates an overridable factory function. +HttpRequestFactory httpRequestFactory = _httpClient; + +/// Restores to the default HTTP request factory. +void debugRestoreHttpRequestFactory() { + httpRequestFactory = _httpClient; +} + +/// The web implementation of [image_provider.NetworkImage]. +/// +/// NetworkImage on the web does not support decoding to a specified size. +@immutable +class NetworkImage + extends image_provider.ImageProvider<image_provider.NetworkImage> + implements image_provider.NetworkImage { + /// Creates an object that fetches the image at the given URL. + const NetworkImage(this.url, {this.scale = 1.0, this.headers}); + + @override + final String url; + + @override + final double scale; + + @override + final Map<String, String>? headers; + + @override + Future<NetworkImage> obtainKey(image_provider.ImageConfiguration configuration) { + return SynchronousFuture<NetworkImage>(this); + } + + @override + ImageStreamCompleter loadBuffer(image_provider.NetworkImage key, image_provider.DecoderBufferCallback decode) { + // Ownership of this controller is handed off to [_loadAsync]; it is that + // method's responsibility to close the controller's stream when the image + // has been loaded or an error is thrown. + final StreamController<ImageChunkEvent> chunkEvents = + StreamController<ImageChunkEvent>(); + + return MultiFrameImageStreamCompleter( + chunkEvents: chunkEvents.stream, + codec: _loadAsync(key as NetworkImage, decode, chunkEvents), + scale: key.scale, + debugLabel: key.url, + informationCollector: _imageStreamInformationCollector(key), + ); + } + + @override + ImageStreamCompleter loadImage(image_provider.NetworkImage key, image_provider.ImageDecoderCallback decode) { + // Ownership of this controller is handed off to [_loadAsync]; it is that + // method's responsibility to close the controller's stream when the image + // has been loaded or an error is thrown. + final StreamController<ImageChunkEvent> chunkEvents = StreamController<ImageChunkEvent>(); + + return MultiFrameImageStreamCompleter( + chunkEvents: chunkEvents.stream, + codec: _loadAsync(key as NetworkImage, decode, chunkEvents), + scale: key.scale, + debugLabel: key.url, + informationCollector: _imageStreamInformationCollector(key), + ); + } + + InformationCollector? _imageStreamInformationCollector(image_provider.NetworkImage key) { + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<image_provider.ImageProvider>('Image provider', this), + DiagnosticsProperty<NetworkImage>('Image key', key as NetworkImage), + ]; + return true; + }()); + return collector; + } + + // Html renderer does not support decoding network images to a specified size. The decode parameter + // here is ignored and `ui_web.createImageCodecFromUrl` will be used directly + // in place of the typical `instantiateImageCodec` method. + Future<ui.Codec> _loadAsync( + NetworkImage key, + _SimpleDecoderCallback decode, + StreamController<ImageChunkEvent> chunkEvents, + ) async { + assert(key == this); + + final Uri resolved = Uri.base.resolve(key.url); + + final bool containsNetworkImageHeaders = key.headers?.isNotEmpty ?? false; + + // We use a different method when headers are set because the + // `ui_web.createImageCodecFromUrl` method is not capable of handling headers. + if (isCanvasKit || containsNetworkImageHeaders) { + final Completer<web.XMLHttpRequest> completer = + Completer<web.XMLHttpRequest>(); + final web.XMLHttpRequest request = httpRequestFactory(); + + request.open('GET', key.url, true); + request.responseType = 'arraybuffer'; + if (containsNetworkImageHeaders) { + key.headers!.forEach((String header, String value) { + request.setRequestHeader(header, value); + }); + } + + request.addEventListener('load', (web.Event e) { + final int status = request.status; + final bool accepted = status >= 200 && status < 300; + final bool fileUri = status == 0; // file:// URIs have status of 0. + final bool notModified = status == 304; + final bool unknownRedirect = status > 307 && status < 400; + final bool success = + accepted || fileUri || notModified || unknownRedirect; + + if (success) { + completer.complete(request); + } else { + completer.completeError(e); + throw image_provider.NetworkImageLoadException( + statusCode: status, uri: resolved); + } + }.toJS); + + request.addEventListener('error', + ((JSObject e) => completer.completeError(e)).toJS); + + request.send(); + + await completer.future; + + final Uint8List bytes = (request.response! as JSArrayBuffer).toDart.asUint8List(); + + if (bytes.lengthInBytes == 0) { + throw image_provider.NetworkImageLoadException( + statusCode: request.status, uri: resolved); + } + return decode(await ui.ImmutableBuffer.fromUint8List(bytes)); + } else { + return ui_web.createImageCodecFromUrl( + resolved, + chunkCallback: (int bytes, int total) { + chunkEvents.add(ImageChunkEvent( + cumulativeBytesLoaded: bytes, expectedTotalBytes: total)); + }, + ); + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is NetworkImage && other.url == url && other.scale == scale; + } + + @override + int get hashCode => Object.hash(url, scale); + + @override + String toString() => '${objectRuntimeType(this, 'NetworkImage')}("$url", scale: ${scale.toStringAsFixed(1)})'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/alignment.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/alignment.dart new file mode 100644 index 0000000000000000000000000000000000000000..7509321d75b6fef279d561dcd7107b6da0e08c51 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/alignment.dart @@ -0,0 +1,693 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; + +/// Base class for [Alignment] that allows for text-direction aware +/// resolution. +/// +/// A property or argument of this type accepts classes created either with [ +/// Alignment] and its variants, or [AlignmentDirectional.new]. +/// +/// To convert an [AlignmentGeometry] object of indeterminate type into an +/// [Alignment] object, call the [resolve] method. +@immutable +abstract class AlignmentGeometry { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const AlignmentGeometry(); + + double get _x; + + double get _start; + + double get _y; + + /// Returns the sum of two [AlignmentGeometry] objects. + /// + /// If you know you are adding two [Alignment] or two [AlignmentDirectional] + /// objects, consider using the `+` operator instead, which always returns an + /// object of the same type as the operands, and is typed accordingly. + /// + /// If [add] is applied to two objects of the same type ([Alignment] or + /// [AlignmentDirectional]), an object of that type will be returned (though + /// this is not reflected in the type system). Otherwise, an object + /// representing a combination of both is returned. That object can be turned + /// into a concrete [Alignment] using [resolve]. + AlignmentGeometry add(AlignmentGeometry other) { + return _MixedAlignment( + _x + other._x, + _start + other._start, + _y + other._y, + ); + } + + /// Returns the negation of the given [AlignmentGeometry] object. + /// + /// This is the same as multiplying the object by -1.0. + /// + /// This operator returns an object of the same type as the operand. + AlignmentGeometry operator -(); + + /// Scales the [AlignmentGeometry] object in each dimension by the given factor. + /// + /// This operator returns an object of the same type as the operand. + AlignmentGeometry operator *(double other); + + /// Divides the [AlignmentGeometry] object in each dimension by the given factor. + /// + /// This operator returns an object of the same type as the operand. + AlignmentGeometry operator /(double other); + + /// Integer divides the [AlignmentGeometry] object in each dimension by the given factor. + /// + /// This operator returns an object of the same type as the operand. + AlignmentGeometry operator ~/(double other); + + /// Computes the remainder in each dimension by the given factor. + /// + /// This operator returns an object of the same type as the operand. + AlignmentGeometry operator %(double other); + + /// Linearly interpolate between two [AlignmentGeometry] objects. + /// + /// If either is null, this function interpolates from [Alignment.center], and + /// the result is an object of the same type as the non-null argument. + /// + /// If [lerp] is applied to two objects of the same type ([Alignment] or + /// [AlignmentDirectional]), an object of that type will be returned (though + /// this is not reflected in the type system). Otherwise, an object + /// representing a combination of both is returned. That object can be turned + /// into a concrete [Alignment] using [resolve]. + /// + /// {@macro dart.ui.shadow.lerp} + static AlignmentGeometry? lerp(AlignmentGeometry? a, AlignmentGeometry? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b! * t; + } + if (b == null) { + return a * (1.0 - t); + } + if (a is Alignment && b is Alignment) { + return Alignment.lerp(a, b, t); + } + if (a is AlignmentDirectional && b is AlignmentDirectional) { + return AlignmentDirectional.lerp(a, b, t); + } + return _MixedAlignment( + ui.lerpDouble(a._x, b._x, t)!, + ui.lerpDouble(a._start, b._start, t)!, + ui.lerpDouble(a._y, b._y, t)!, + ); + } + + /// Convert this instance into an [Alignment], which uses literal + /// coordinates (the `x` coordinate being explicitly a distance from the + /// left). + /// + /// See also: + /// + /// * [Alignment], for which this is a no-op (returns itself). + /// * [AlignmentDirectional], which flips the horizontal direction + /// based on the `direction` argument. + Alignment resolve(TextDirection? direction); + + @override + String toString() { + if (_start == 0.0) { + return Alignment._stringify(_x, _y); + } + if (_x == 0.0) { + return AlignmentDirectional._stringify(_start, _y); + } + return '${Alignment._stringify(_x, _y)} + ${AlignmentDirectional._stringify(_start, 0.0)}'; + } + + @override + bool operator ==(Object other) { + return other is AlignmentGeometry + && other._x == _x + && other._start == _start + && other._y == _y; + } + + @override + int get hashCode => Object.hash(_x, _start, _y); +} + +/// A point within a rectangle. +/// +/// `Alignment(0.0, 0.0)` represents the center of the rectangle. The distance +/// from -1.0 to +1.0 is the distance from one side of the rectangle to the +/// other side of the rectangle. Therefore, 2.0 units horizontally (or +/// vertically) is equivalent to the width (or height) of the rectangle. +/// +/// `Alignment(-1.0, -1.0)` represents the top left of the rectangle. +/// +/// `Alignment(1.0, 1.0)` represents the bottom right of the rectangle. +/// +/// `Alignment(0.0, 3.0)` represents a point that is horizontally centered with +/// respect to the rectangle and vertically below the bottom of the rectangle by +/// the height of the rectangle. +/// +/// `Alignment(0.0, -0.5)` represents a point that is horizontally centered with +/// respect to the rectangle and vertically half way between the top edge and +/// the center. +/// +/// `Alignment(x, y)` in a rectangle with height h and width w describes +/// the point (x * w/2 + w/2, y * h/2 + h/2) in the coordinate system of the +/// rectangle. +/// +/// [Alignment] uses visual coordinates, which means increasing [x] moves the +/// point from left to right. To support layouts with a right-to-left +/// [TextDirection], consider using [AlignmentDirectional], in which the +/// direction the point moves when increasing the horizontal value depends on +/// the [TextDirection]. +/// +/// A variety of widgets use [Alignment] in their configuration, most +/// notably: +/// +/// * [Align] positions a child according to an [Alignment]. +/// +/// See also: +/// +/// * [AlignmentDirectional], which has a horizontal coordinate orientation +/// that depends on the [TextDirection]. +/// * [AlignmentGeometry], which is an abstract type that is agnostic as to +/// whether the horizontal direction depends on the [TextDirection]. +class Alignment extends AlignmentGeometry { + /// Creates an alignment. + const Alignment(this.x, this.y); + + /// The distance fraction in the horizontal direction. + /// + /// A value of -1.0 corresponds to the leftmost edge. A value of 1.0 + /// corresponds to the rightmost edge. Values are not limited to that range; + /// values less than -1.0 represent positions to the left of the left edge, + /// and values greater than 1.0 represent positions to the right of the right + /// edge. + final double x; + + /// The distance fraction in the vertical direction. + /// + /// A value of -1.0 corresponds to the topmost edge. A value of 1.0 + /// corresponds to the bottommost edge. Values are not limited to that range; + /// values less than -1.0 represent positions above the top, and values + /// greater than 1.0 represent positions below the bottom. + final double y; + + @override + double get _x => x; + + @override + double get _start => 0.0; + + @override + double get _y => y; + + /// The top left corner. + static const Alignment topLeft = Alignment(-1.0, -1.0); + + /// The center point along the top edge. + static const Alignment topCenter = Alignment(0.0, -1.0); + + /// The top right corner. + static const Alignment topRight = Alignment(1.0, -1.0); + + /// The center point along the left edge. + static const Alignment centerLeft = Alignment(-1.0, 0.0); + + /// The center point, both horizontally and vertically. + static const Alignment center = Alignment(0.0, 0.0); + + /// The center point along the right edge. + static const Alignment centerRight = Alignment(1.0, 0.0); + + /// The bottom left corner. + static const Alignment bottomLeft = Alignment(-1.0, 1.0); + + /// The center point along the bottom edge. + static const Alignment bottomCenter = Alignment(0.0, 1.0); + + /// The bottom right corner. + static const Alignment bottomRight = Alignment(1.0, 1.0); + + @override + AlignmentGeometry add(AlignmentGeometry other) { + if (other is Alignment) { + return this + other; + } + return super.add(other); + } + + /// Returns the difference between two [Alignment]s. + Alignment operator -(Alignment other) { + return Alignment(x - other.x, y - other.y); + } + + /// Returns the sum of two [Alignment]s. + Alignment operator +(Alignment other) { + return Alignment(x + other.x, y + other.y); + } + + /// Returns the negation of the given [Alignment]. + @override + Alignment operator -() { + return Alignment(-x, -y); + } + + /// Scales the [Alignment] in each dimension by the given factor. + @override + Alignment operator *(double other) { + return Alignment(x * other, y * other); + } + + /// Divides the [Alignment] in each dimension by the given factor. + @override + Alignment operator /(double other) { + return Alignment(x / other, y / other); + } + + /// Integer divides the [Alignment] in each dimension by the given factor. + @override + Alignment operator ~/(double other) { + return Alignment((x ~/ other).toDouble(), (y ~/ other).toDouble()); + } + + /// Computes the remainder in each dimension by the given factor. + @override + Alignment operator %(double other) { + return Alignment(x % other, y % other); + } + + /// Returns the offset that is this fraction in the direction of the given offset. + Offset alongOffset(Offset other) { + final double centerX = other.dx / 2.0; + final double centerY = other.dy / 2.0; + return Offset(centerX + x * centerX, centerY + y * centerY); + } + + /// Returns the offset that is this fraction within the given size. + Offset alongSize(Size other) { + final double centerX = other.width / 2.0; + final double centerY = other.height / 2.0; + return Offset(centerX + x * centerX, centerY + y * centerY); + } + + /// Returns the point that is this fraction within the given rect. + Offset withinRect(Rect rect) { + final double halfWidth = rect.width / 2.0; + final double halfHeight = rect.height / 2.0; + return Offset( + rect.left + halfWidth + x * halfWidth, + rect.top + halfHeight + y * halfHeight, + ); + } + + /// Returns a rect of the given size, aligned within given rect as specified + /// by this alignment. + /// + /// For example, a 100×100 size inscribed on a 200×200 rect using + /// [Alignment.topLeft] would be the 100×100 rect at the top left of + /// the 200×200 rect. + Rect inscribe(Size size, Rect rect) { + final double halfWidthDelta = (rect.width - size.width) / 2.0; + final double halfHeightDelta = (rect.height - size.height) / 2.0; + return Rect.fromLTWH( + rect.left + halfWidthDelta + x * halfWidthDelta, + rect.top + halfHeightDelta + y * halfHeightDelta, + size.width, + size.height, + ); + } + + /// Linearly interpolate between two [Alignment]s. + /// + /// If either is null, this function interpolates from [Alignment.center]. + /// + /// {@macro dart.ui.shadow.lerp} + static Alignment? lerp(Alignment? a, Alignment? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return Alignment(ui.lerpDouble(0.0, b!.x, t)!, ui.lerpDouble(0.0, b.y, t)!); + } + if (b == null) { + return Alignment(ui.lerpDouble(a.x, 0.0, t)!, ui.lerpDouble(a.y, 0.0, t)!); + } + return Alignment(ui.lerpDouble(a.x, b.x, t)!, ui.lerpDouble(a.y, b.y, t)!); + } + + @override + Alignment resolve(TextDirection? direction) => this; + + static String _stringify(double x, double y) { + if (x == -1.0 && y == -1.0) { + return 'Alignment.topLeft'; + } + if (x == 0.0 && y == -1.0) { + return 'Alignment.topCenter'; + } + if (x == 1.0 && y == -1.0) { + return 'Alignment.topRight'; + } + if (x == -1.0 && y == 0.0) { + return 'Alignment.centerLeft'; + } + if (x == 0.0 && y == 0.0) { + return 'Alignment.center'; + } + if (x == 1.0 && y == 0.0) { + return 'Alignment.centerRight'; + } + if (x == -1.0 && y == 1.0) { + return 'Alignment.bottomLeft'; + } + if (x == 0.0 && y == 1.0) { + return 'Alignment.bottomCenter'; + } + if (x == 1.0 && y == 1.0) { + return 'Alignment.bottomRight'; + } + return 'Alignment(${x.toStringAsFixed(1)}, ' + '${y.toStringAsFixed(1)})'; + } + + @override + String toString() => _stringify(x, y); +} + +/// An offset that's expressed as a fraction of a [Size], but whose horizontal +/// component is dependent on the writing direction. +/// +/// This can be used to indicate an offset from the left in [TextDirection.ltr] +/// text and an offset from the right in [TextDirection.rtl] text without having +/// to be aware of the current text direction. +/// +/// See also: +/// +/// * [Alignment], a variant that is defined in physical terms (i.e. +/// whose horizontal component does not depend on the text direction). +class AlignmentDirectional extends AlignmentGeometry { + /// Creates a directional alignment. + const AlignmentDirectional(this.start, this.y); + + /// The distance fraction in the horizontal direction. + /// + /// A value of -1.0 corresponds to the edge on the "start" side, which is the + /// left side in [TextDirection.ltr] contexts and the right side in + /// [TextDirection.rtl] contexts. A value of 1.0 corresponds to the opposite + /// edge, the "end" side. Values are not limited to that range; values less + /// than -1.0 represent positions beyond the start edge, and values greater than + /// 1.0 represent positions beyond the end edge. + /// + /// This value is normalized into an [Alignment.x] value by the [resolve] + /// method. + final double start; + + /// The distance fraction in the vertical direction. + /// + /// A value of -1.0 corresponds to the topmost edge. A value of 1.0 + /// corresponds to the bottommost edge. Values are not limited to that range; + /// values less than -1.0 represent positions above the top, and values + /// greater than 1.0 represent positions below the bottom. + /// + /// This value is passed through to [Alignment.y] unmodified by the + /// [resolve] method. + final double y; + + @override + double get _x => 0.0; + + @override + double get _start => start; + + @override + double get _y => y; + + /// The top corner on the "start" side. + static const AlignmentDirectional topStart = AlignmentDirectional(-1.0, -1.0); + + /// The center point along the top edge. + /// + /// Consider using [Alignment.topCenter] instead, as it does not need + /// to be [resolve]d to be used. + static const AlignmentDirectional topCenter = AlignmentDirectional(0.0, -1.0); + + /// The top corner on the "end" side. + static const AlignmentDirectional topEnd = AlignmentDirectional(1.0, -1.0); + + /// The center point along the "start" edge. + static const AlignmentDirectional centerStart = AlignmentDirectional(-1.0, 0.0); + + /// The center point, both horizontally and vertically. + /// + /// Consider using [Alignment.center] instead, as it does not need to + /// be [resolve]d to be used. + static const AlignmentDirectional center = AlignmentDirectional(0.0, 0.0); + + /// The center point along the "end" edge. + static const AlignmentDirectional centerEnd = AlignmentDirectional(1.0, 0.0); + + /// The bottom corner on the "start" side. + static const AlignmentDirectional bottomStart = AlignmentDirectional(-1.0, 1.0); + + /// The center point along the bottom edge. + /// + /// Consider using [Alignment.bottomCenter] instead, as it does not + /// need to be [resolve]d to be used. + static const AlignmentDirectional bottomCenter = AlignmentDirectional(0.0, 1.0); + + /// The bottom corner on the "end" side. + static const AlignmentDirectional bottomEnd = AlignmentDirectional(1.0, 1.0); + + @override + AlignmentGeometry add(AlignmentGeometry other) { + if (other is AlignmentDirectional) { + return this + other; + } + return super.add(other); + } + + /// Returns the difference between two [AlignmentDirectional]s. + AlignmentDirectional operator -(AlignmentDirectional other) { + return AlignmentDirectional(start - other.start, y - other.y); + } + + /// Returns the sum of two [AlignmentDirectional]s. + AlignmentDirectional operator +(AlignmentDirectional other) { + return AlignmentDirectional(start + other.start, y + other.y); + } + + /// Returns the negation of the given [AlignmentDirectional]. + @override + AlignmentDirectional operator -() { + return AlignmentDirectional(-start, -y); + } + + /// Scales the [AlignmentDirectional] in each dimension by the given factor. + @override + AlignmentDirectional operator *(double other) { + return AlignmentDirectional(start * other, y * other); + } + + /// Divides the [AlignmentDirectional] in each dimension by the given factor. + @override + AlignmentDirectional operator /(double other) { + return AlignmentDirectional(start / other, y / other); + } + + /// Integer divides the [AlignmentDirectional] in each dimension by the given factor. + @override + AlignmentDirectional operator ~/(double other) { + return AlignmentDirectional((start ~/ other).toDouble(), (y ~/ other).toDouble()); + } + + /// Computes the remainder in each dimension by the given factor. + @override + AlignmentDirectional operator %(double other) { + return AlignmentDirectional(start % other, y % other); + } + + /// Linearly interpolate between two [AlignmentDirectional]s. + /// + /// If either is null, this function interpolates from [AlignmentDirectional.center]. + /// + /// {@macro dart.ui.shadow.lerp} + static AlignmentDirectional? lerp(AlignmentDirectional? a, AlignmentDirectional? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return AlignmentDirectional(ui.lerpDouble(0.0, b!.start, t)!, ui.lerpDouble(0.0, b.y, t)!); + } + if (b == null) { + return AlignmentDirectional(ui.lerpDouble(a.start, 0.0, t)!, ui.lerpDouble(a.y, 0.0, t)!); + } + return AlignmentDirectional(ui.lerpDouble(a.start, b.start, t)!, ui.lerpDouble(a.y, b.y, t)!); + } + + @override + Alignment resolve(TextDirection? direction) { + assert(direction != null, 'Cannot resolve $runtimeType without a TextDirection.'); + switch (direction!) { + case TextDirection.rtl: + return Alignment(-start, y); + case TextDirection.ltr: + return Alignment(start, y); + } + } + + static String _stringify(double start, double y) { + if (start == -1.0 && y == -1.0) { + return 'AlignmentDirectional.topStart'; + } + if (start == 0.0 && y == -1.0) { + return 'AlignmentDirectional.topCenter'; + } + if (start == 1.0 && y == -1.0) { + return 'AlignmentDirectional.topEnd'; + } + if (start == -1.0 && y == 0.0) { + return 'AlignmentDirectional.centerStart'; + } + if (start == 0.0 && y == 0.0) { + return 'AlignmentDirectional.center'; + } + if (start == 1.0 && y == 0.0) { + return 'AlignmentDirectional.centerEnd'; + } + if (start == -1.0 && y == 1.0) { + return 'AlignmentDirectional.bottomStart'; + } + if (start == 0.0 && y == 1.0) { + return 'AlignmentDirectional.bottomCenter'; + } + if (start == 1.0 && y == 1.0) { + return 'AlignmentDirectional.bottomEnd'; + } + return 'AlignmentDirectional(${start.toStringAsFixed(1)}, ' + '${y.toStringAsFixed(1)})'; + } + + @override + String toString() => _stringify(start, y); +} + +class _MixedAlignment extends AlignmentGeometry { + const _MixedAlignment(this._x, this._start, this._y); + + @override + final double _x; + + @override + final double _start; + + @override + final double _y; + + @override + _MixedAlignment operator -() { + return _MixedAlignment( + -_x, + -_start, + -_y, + ); + } + + @override + _MixedAlignment operator *(double other) { + return _MixedAlignment( + _x * other, + _start * other, + _y * other, + ); + } + + @override + _MixedAlignment operator /(double other) { + return _MixedAlignment( + _x / other, + _start / other, + _y / other, + ); + } + + @override + _MixedAlignment operator ~/(double other) { + return _MixedAlignment( + (_x ~/ other).toDouble(), + (_start ~/ other).toDouble(), + (_y ~/ other).toDouble(), + ); + } + + @override + _MixedAlignment operator %(double other) { + return _MixedAlignment( + _x % other, + _start % other, + _y % other, + ); + } + + @override + Alignment resolve(TextDirection? direction) { + assert(direction != null, 'Cannot resolve $runtimeType without a TextDirection.'); + switch (direction!) { + case TextDirection.rtl: + return Alignment(_x - _start, _y); + case TextDirection.ltr: + return Alignment(_x + _start, _y); + } + } +} + +/// The vertical alignment of text within an input box. +/// +/// A single [y] value that can range from -1.0 to 1.0. -1.0 aligns to the top +/// of an input box so that the top of the first line of text fits within the +/// box and its padding. 0.0 aligns to the center of the box. 1.0 aligns so that +/// the bottom of the last line of text aligns with the bottom interior edge of +/// the input box. +/// +/// See also: +/// +/// * [TextField.textAlignVertical], which is passed on to the [InputDecorator]. +/// * [CupertinoTextField.textAlignVertical], which behaves in the same way as +/// the parameter in TextField. +/// * [InputDecorator.textAlignVertical], which defines the alignment of +/// prefix, input, and suffix within an [InputDecorator]. +class TextAlignVertical { + /// Creates a TextAlignVertical from any y value between -1.0 and 1.0. + const TextAlignVertical({ + required this.y, + }) : assert(y >= -1.0 && y <= 1.0); + + /// A value ranging from -1.0 to 1.0 that defines the topmost and bottommost + /// locations of the top and bottom of the input box. + final double y; + + /// Aligns a TextField's input Text with the topmost location within a + /// TextField's input box. + static const TextAlignVertical top = TextAlignVertical(y: -1.0); + /// Aligns a TextField's input Text to the center of the TextField. + static const TextAlignVertical center = TextAlignVertical(y: 0.0); + /// Aligns a TextField's input Text with the bottommost location within a + /// TextField. + static const TextAlignVertical bottom = TextAlignVertical(y: 1.0); + + @override + String toString() { + return '${objectRuntimeType(this, 'TextAlignVertical')}(y: $y)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/basic_types.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/basic_types.dart new file mode 100644 index 0000000000000000000000000000000000000000..fe67c28feb679a349cde966126eaa193cd35d476 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/basic_types.dart @@ -0,0 +1,340 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show TextDirection; + +export 'dart:ui' show + BlendMode, + BlurStyle, + Canvas, + Clip, + Color, + ColorFilter, + FilterQuality, + FontFeature, + FontStyle, + FontVariation, + FontWeight, + GlyphInfo, + ImageShader, + Locale, + MaskFilter, + Offset, + Paint, + PaintingStyle, + Path, + PathFillType, + PathOperation, + RRect, + RSTransform, + Radius, + Rect, + Shader, + Shadow, + Size, + StrokeCap, + StrokeJoin, + TextAffinity, + TextAlign, + TextBaseline, + TextBox, + TextDecoration, + TextDecorationStyle, + TextDirection, + TextHeightBehavior, + TextLeadingDistribution, + TextPosition, + TileMode, + VertexMode, + // TODO(werainkhatri): remove these after their deprecation period in engine + // https://github.com/flutter/flutter/pull/99505 + hashList, // ignore: deprecated_member_use + hashValues; // ignore: deprecated_member_use + +export 'package:flutter/foundation.dart' show VoidCallback; + +// Intentionally not exported: +// - Image, instantiateImageCodec, decodeImageFromList: +// We use ui.* to make it very explicit that these are low-level image APIs. +// Generally, higher layers provide more reasonable APIs around images. +// - lerpDouble: +// Hopefully this will eventually become Double.lerp. +// - Paragraph, ParagraphBuilder, ParagraphStyle, TextBox: +// These are low-level text primitives. Use this package's TextPainter API. +// - Picture, PictureRecorder, Scene, SceneBuilder: +// These are low-level primitives. Generally, the rendering layer makes these moot. +// - Gradient: +// Use this package's higher-level Gradient API instead. +// - window, WindowPadding +// These are generally wrapped by other APIs so we always refer to them directly +// as ui.* to avoid making them seem like high-level APIs. + +/// The description of the difference between two objects, in the context of how +/// it will affect the rendering. +/// +/// Used by [TextSpan.compareTo] and [TextStyle.compareTo]. +/// +/// The values in this enum are ordered such that they are in increasing order +/// of cost. A value with index N implies all the values with index less than N. +/// For example, [layout] (index 3) implies [paint] (2). +enum RenderComparison { + /// The two objects are identical (meaning deeply equal, not necessarily + /// [dart:core.identical]). + identical, + + /// The two objects are identical for the purpose of layout, but may be different + /// in other ways. + /// + /// For example, maybe some event handlers changed. + metadata, + + /// The two objects are different but only in ways that affect paint, not layout. + /// + /// For example, only the color is changed. + /// + /// [RenderObject.markNeedsPaint] would be necessary to handle this kind of + /// change in a render object. + paint, + + /// The two objects are different in ways that affect layout (and therefore paint). + /// + /// For example, the size is changed. + /// + /// This is the most drastic level of change possible. + /// + /// [RenderObject.markNeedsLayout] would be necessary to handle this kind of + /// change in a render object. + layout, +} + +/// The two cardinal directions in two dimensions. +/// +/// The axis is always relative to the current coordinate space. This means, for +/// example, that a [horizontal] axis might actually be diagonally from top +/// right to bottom left, due to some local [Transform] applied to the scene. +/// +/// See also: +/// +/// * [AxisDirection], which is a directional version of this enum (with values +/// like left and right, rather than just horizontal). +/// * [TextDirection], which disambiguates between left-to-right horizontal +/// content and right-to-left horizontal content. +enum Axis { + /// Left and right. + /// + /// See also: + /// + /// * [TextDirection], which disambiguates between left-to-right horizontal + /// content and right-to-left horizontal content. + horizontal, + + /// Up and down. + vertical, +} + +/// Returns the opposite of the given [Axis]. +/// +/// Specifically, returns [Axis.horizontal] for [Axis.vertical], and +/// vice versa. +/// +/// See also: +/// +/// * [flipAxisDirection], which does the same thing for [AxisDirection] values. +Axis flipAxis(Axis direction) { + switch (direction) { + case Axis.horizontal: + return Axis.vertical; + case Axis.vertical: + return Axis.horizontal; + } +} + +/// A direction in which boxes flow vertically. +/// +/// This is used by the flex algorithm (e.g. [Column]) to decide in which +/// direction to draw boxes. +/// +/// This is also used to disambiguate `start` and `end` values (e.g. +/// [MainAxisAlignment.start] or [CrossAxisAlignment.end]). +/// +/// See also: +/// +/// * [TextDirection], which controls the same thing but horizontally. +enum VerticalDirection { + /// Boxes should start at the bottom and be stacked vertically towards the top. + /// + /// The "start" is at the bottom, the "end" is at the top. + up, + + /// Boxes should start at the top and be stacked vertically towards the bottom. + /// + /// The "start" is at the top, the "end" is at the bottom. + down, +} + +/// A direction along either the horizontal or vertical [Axis] in which the +/// origin, or zero position, is determined. +/// +/// This value relates to the direction in which the scroll offset increases +/// from the origin. This value does not represent the direction of user input +/// that may be modifying the scroll offset, such as from a drag. For the +/// active scrolling direction, see [ScrollDirection]. +/// +/// {@tool dartpad} +/// This sample shows a [CustomScrollView], with [Radio] buttons in the +/// [AppBar.bottom] that change the [AxisDirection] to illustrate different +/// configurations. +/// +/// ** See code in examples/api/lib/painting/axis_direction/axis_direction.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ScrollDirection], the direction of active scrolling, relative to the positive +/// scroll offset axis given by an [AxisDirection] and a [GrowthDirection]. +/// * [GrowthDirection], the direction in which slivers and their content are +/// ordered, relative to the scroll offset axis as specified by +/// [AxisDirection]. +/// * [CustomScrollView.anchor], the relative position of the zero scroll +/// offset in a viewport and inflection point for [AxisDirection]s of the +/// same cardinal [Axis]. +/// * [axisDirectionIsReversed], which returns whether traveling along the +/// given axis direction visits coordinates along that axis in numerically +/// decreasing order. +enum AxisDirection { + /// A direction in the [Axis.vertical] where zero is at the bottom and + /// positive values are above it: `⇈` + /// + /// Alphabetical content with a [GrowthDirection.forward] would have the A at + /// the bottom and the Z at the top. + /// + /// For example, the behavior of a [ListView] with [ListView.reverse] set to + /// true would have this axis direction. + /// + /// See also: + /// + /// * [axisDirectionIsReversed], which returns whether traveling along the + /// given axis direction visits coordinates along that axis in numerically + /// decreasing order. + up, + + /// A direction in the [Axis.horizontal] where zero is on the left and + /// positive values are to the right of it: `⇉` + /// + /// Alphabetical content with a [GrowthDirection.forward] would have the A on + /// the left and the Z on the right. This is the ordinary reading order for a + /// horizontal set of tabs in an English application, for example. + /// + /// For example, the behavior of a [ListView] with [ListView.scrollDirection] + /// set to [Axis.horizontal] would have this axis direction. + /// + /// See also: + /// + /// * [axisDirectionIsReversed], which returns whether traveling along the + /// given axis direction visits coordinates along that axis in numerically + /// decreasing order. + right, + + /// A direction in the [Axis.vertical] where zero is at the top and positive + /// values are below it: `⇊` + /// + /// Alphabetical content with a [GrowthDirection.forward] would have the A at + /// the top and the Z at the bottom. This is the ordinary reading order for a + /// vertical list. + /// + /// For example, the default behavior of a [ListView] would have this axis + /// direction. + /// + /// See also: + /// + /// * [axisDirectionIsReversed], which returns whether traveling along the + /// given axis direction visits coordinates along that axis in numerically + /// decreasing order. + down, + + /// A direction in the [Axis.horizontal] where zero is to the right and + /// positive values are to the left of it: `⇇` + /// + /// Alphabetical content with a [GrowthDirection.forward] would have the A at + /// the right and the Z at the left. This is the ordinary reading order for a + /// horizontal set of tabs in a Hebrew application, for example. + /// + /// For example, the behavior of a [ListView] with [ListView.scrollDirection] + /// set to [Axis.horizontal] and [ListView.reverse] set to true would have + /// this axis direction. + /// + /// See also: + /// + /// * [axisDirectionIsReversed], which returns whether traveling along the + /// given axis direction visits coordinates along that axis in numerically + /// decreasing order. + left, +} + +/// Returns the [Axis] that contains the given [AxisDirection]. +/// +/// Specifically, returns [Axis.vertical] for [AxisDirection.up] and +/// [AxisDirection.down] and returns [Axis.horizontal] for [AxisDirection.left] +/// and [AxisDirection.right]. +Axis axisDirectionToAxis(AxisDirection axisDirection) { + switch (axisDirection) { + case AxisDirection.up: + case AxisDirection.down: + return Axis.vertical; + case AxisDirection.left: + case AxisDirection.right: + return Axis.horizontal; + } +} + +/// Returns the [AxisDirection] in which reading occurs in the given [TextDirection]. +/// +/// Specifically, returns [AxisDirection.left] for [TextDirection.rtl] and +/// [AxisDirection.right] for [TextDirection.ltr]. +AxisDirection textDirectionToAxisDirection(TextDirection textDirection) { + switch (textDirection) { + case TextDirection.rtl: + return AxisDirection.left; + case TextDirection.ltr: + return AxisDirection.right; + } +} + +/// Returns the opposite of the given [AxisDirection]. +/// +/// Specifically, returns [AxisDirection.up] for [AxisDirection.down] (and +/// vice versa), as well as [AxisDirection.left] for [AxisDirection.right] (and +/// vice versa). +/// +/// See also: +/// +/// * [flipAxis], which does the same thing for [Axis] values. +AxisDirection flipAxisDirection(AxisDirection axisDirection) { + switch (axisDirection) { + case AxisDirection.up: + return AxisDirection.down; + case AxisDirection.right: + return AxisDirection.left; + case AxisDirection.down: + return AxisDirection.up; + case AxisDirection.left: + return AxisDirection.right; + } +} + +/// Returns whether traveling along the given axis direction visits coordinates +/// along that axis in numerically decreasing order. +/// +/// Specifically, returns true for [AxisDirection.up] and [AxisDirection.left] +/// and false for [AxisDirection.down] and [AxisDirection.right]. +bool axisDirectionIsReversed(AxisDirection axisDirection) { + switch (axisDirection) { + case AxisDirection.up: + case AxisDirection.left: + return true; + case AxisDirection.down: + case AxisDirection.right: + return false; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/beveled_rectangle_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/beveled_rectangle_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..3c900e808dd27ff46eb2e88948a3b08206cd64ff --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/beveled_rectangle_border.dart @@ -0,0 +1,152 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'border_radius.dart'; +import 'borders.dart'; + +/// A rectangular border with flattened or "beveled" corners. +/// +/// The line segments that connect the rectangle's four sides will +/// begin and at locations offset by the corresponding border radius, +/// but not farther than the side's center. If all the border radii +/// exceed the sides' half widths/heights the resulting shape is +/// diamond made by connecting the centers of the sides. +class BeveledRectangleBorder extends OutlinedBorder { + /// Creates a border like a [RoundedRectangleBorder] except that the corners + /// are joined by straight lines instead of arcs. + const BeveledRectangleBorder({ + super.side, + this.borderRadius = BorderRadius.zero, + }); + + /// The radii for each corner. + /// + /// Each corner [Radius] defines the endpoints of a line segment that + /// spans the corner. The endpoints are located in the same place as + /// they would be for [RoundedRectangleBorder], but they're connected + /// by a straight line instead of an arc. + /// + /// Negative radius values are clamped to 0.0 by [getInnerPath] and + /// [getOuterPath]. + final BorderRadiusGeometry borderRadius; + + @override + ShapeBorder scale(double t) { + return BeveledRectangleBorder( + side: side.scale(t), + borderRadius: borderRadius * t, + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is BeveledRectangleBorder) { + return BeveledRectangleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!, + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is BeveledRectangleBorder) { + return BeveledRectangleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t)!, + ); + } + return super.lerpTo(b, t); + } + + /// Returns a copy of this RoundedRectangleBorder with the given fields + /// replaced with the new values. + @override + BeveledRectangleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius }) { + return BeveledRectangleBorder( + side: side ?? this.side, + borderRadius: borderRadius ?? this.borderRadius, + ); + } + + Path _getPath(RRect rrect) { + final Offset centerLeft = Offset(rrect.left, rrect.center.dy); + final Offset centerRight = Offset(rrect.right, rrect.center.dy); + final Offset centerTop = Offset(rrect.center.dx, rrect.top); + final Offset centerBottom = Offset(rrect.center.dx, rrect.bottom); + + final double tlRadiusX = math.max(0.0, rrect.tlRadiusX); + final double tlRadiusY = math.max(0.0, rrect.tlRadiusY); + final double trRadiusX = math.max(0.0, rrect.trRadiusX); + final double trRadiusY = math.max(0.0, rrect.trRadiusY); + final double blRadiusX = math.max(0.0, rrect.blRadiusX); + final double blRadiusY = math.max(0.0, rrect.blRadiusY); + final double brRadiusX = math.max(0.0, rrect.brRadiusX); + final double brRadiusY = math.max(0.0, rrect.brRadiusY); + + final List<Offset> vertices = <Offset>[ + Offset(rrect.left, math.min(centerLeft.dy, rrect.top + tlRadiusY)), + Offset(math.min(centerTop.dx, rrect.left + tlRadiusX), rrect.top), + Offset(math.max(centerTop.dx, rrect.right -trRadiusX), rrect.top), + Offset(rrect.right, math.min(centerRight.dy, rrect.top + trRadiusY)), + Offset(rrect.right, math.max(centerRight.dy, rrect.bottom - brRadiusY)), + Offset(math.max(centerBottom.dx, rrect.right - brRadiusX), rrect.bottom), + Offset(math.min(centerBottom.dx, rrect.left + blRadiusX), rrect.bottom), + Offset(rrect.left, math.max(centerLeft.dy, rrect.bottom - blRadiusY)), + ]; + + return Path()..addPolygon(vertices, true); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + return _getPath(borderRadius.resolve(textDirection).toRRect(rect).deflate(side.strokeInset)); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return _getPath(borderRadius.resolve(textDirection).toRRect(rect)); + } + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + if (rect.isEmpty) { + return; + } + switch (side.style) { + case BorderStyle.none: + break; + case BorderStyle.solid: + final RRect borderRect = borderRadius.resolve(textDirection).toRRect(rect); + final RRect adjustedRect = borderRect.inflate(side.strokeOutset); + final Path path = _getPath(adjustedRect) + ..addPath(getInnerPath(rect, textDirection: textDirection), Offset.zero); + canvas.drawPath(path, side.toPaint()); + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is BeveledRectangleBorder + && other.side == side + && other.borderRadius == borderRadius; + } + + @override + int get hashCode => Object.hash(side, borderRadius); + + @override + String toString() { + return '${objectRuntimeType(this, 'BeveledRectangleBorder')}($side, $borderRadius)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/binding.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/binding.dart new file mode 100644 index 0000000000000000000000000000000000000000..02efc9082ac7c574b5232b4d2714af695d08bf44 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/binding.dart @@ -0,0 +1,208 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui; +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart' show ServicesBinding; + +import 'image_cache.dart'; +import 'shader_warm_up.dart'; + +/// Binding for the painting library. +/// +/// Hooks into the cache eviction logic to clear the image cache. +/// +/// Requires the [ServicesBinding] to be mixed in earlier. +mixin PaintingBinding on BindingBase, ServicesBinding { + @override + void initInstances() { + super.initInstances(); + _instance = this; + _imageCache = createImageCache(); + shaderWarmUp?.execute(); + } + + /// The current [PaintingBinding], if one has been created. + /// + /// Provides access to the features exposed by this mixin. The binding must + /// be initialized before using this getter; this is typically done by calling + /// [runApp] or [WidgetsFlutterBinding.ensureInitialized]. + static PaintingBinding get instance => BindingBase.checkInstance(_instance); + static PaintingBinding? _instance; + + /// [ShaderWarmUp] instance to be executed during [initInstances]. + /// + /// Defaults to `null`, meaning no shader warm-up is done. Some platforms may + /// not support shader warm-up before at least one frame has been displayed. + /// + /// If the application has scenes that require the compilation of complex + /// shaders, it may cause jank in the middle of an animation or interaction. + /// In that case, setting [shaderWarmUp] to a custom [ShaderWarmUp] before + /// creating the binding (usually before [runApp] for normal Flutter apps, and + /// before [enableFlutterDriverExtension] for Flutter driver tests) may help + /// if that object paints the difficult scene in its + /// [ShaderWarmUp.warmUpOnCanvas] method, as this allows Flutter to + /// pre-compile and cache the required shaders during startup. + /// + /// Currently the warm-up happens synchronously on the raster thread which + /// means the rendering of the first frame on the raster thread will be + /// postponed until the warm-up is finished. + /// + /// The warm up is only costly (100ms-200ms, depending on the shaders to + /// compile) during the first run after the installation or a data wipe. The + /// warm up does not block the platform thread so there should be no + /// "Application Not Responding" warning. + /// + /// If this is null, no shader warm-up is executed. + /// + /// See also: + /// + /// * [ShaderWarmUp], the interface for implementing custom warm-up scenes. + /// * <https://flutter.dev/docs/perf/rendering/shader> + static ShaderWarmUp? shaderWarmUp; + + /// The singleton that implements the Flutter framework's image cache. + /// + /// The cache is used internally by [ImageProvider] and should generally not + /// be accessed directly. + /// + /// The image cache is created during startup by the [createImageCache] + /// method. + ImageCache get imageCache => _imageCache; + late ImageCache _imageCache; + + /// Creates the [ImageCache] singleton (accessible via [imageCache]). + /// + /// This method can be overridden to provide a custom image cache. + @protected + ImageCache createImageCache() => ImageCache(); + + /// Calls through to [dart:ui.instantiateImageCodecFromBuffer] from [ImageCache]. + /// + /// The [buffer] parameter should be an [ui.ImmutableBuffer] instance which can + /// be acquired from [ui.ImmutableBuffer.fromUint8List] or [ui.ImmutableBuffer.fromAsset]. + /// + /// The [cacheWidth] and [cacheHeight] parameters, when specified, indicate + /// the size to decode the image to. + /// + /// Both [cacheWidth] and [cacheHeight] must be positive values greater than + /// or equal to 1, or null. It is valid to specify only one of `cacheWidth` + /// and [cacheHeight] with the other remaining null, in which case the omitted + /// dimension will be scaled to maintain the aspect ratio of the original + /// dimensions. When both are null or omitted, the image will be decoded at + /// its native resolution. + /// + /// The [allowUpscaling] parameter determines whether the `cacheWidth` or + /// [cacheHeight] parameters are clamped to the intrinsic width and height of + /// the original image. By default, the dimensions are clamped to avoid + /// unnecessary memory usage for images. Callers that wish to display an image + /// above its native resolution should prefer scaling the canvas the image is + /// drawn into. + @Deprecated( + 'Use instantiateImageCodecWithSize instead. ' + 'This feature was deprecated after v3.7.0-1.4.pre.', + ) + Future<ui.Codec> instantiateImageCodecFromBuffer( + ui.ImmutableBuffer buffer, { + int? cacheWidth, + int? cacheHeight, + bool allowUpscaling = false, + }) { + assert(cacheWidth == null || cacheWidth > 0); + assert(cacheHeight == null || cacheHeight > 0); + return ui.instantiateImageCodecFromBuffer( + buffer, + targetWidth: cacheWidth, + targetHeight: cacheHeight, + allowUpscaling: allowUpscaling, + ); + } + + /// Calls through to [dart:ui.instantiateImageCodecWithSize] from [ImageCache]. + /// + /// The [buffer] parameter should be an [ui.ImmutableBuffer] instance which can + /// be acquired from [ui.ImmutableBuffer.fromUint8List] or + /// [ui.ImmutableBuffer.fromAsset]. + /// + /// The [getTargetSize] parameter, when specified, will be invoked and passed + /// the image's intrinsic size to determine the size to decode the image to. + /// The width and the height of the size it returns must be positive values + /// greater than or equal to 1, or null. It is valid to return a [TargetImageSize] + /// that specifies only one of `width` and `height` with the other remaining + /// null, in which case the omitted dimension will be scaled to maintain the + /// aspect ratio of the original dimensions. When both are null or omitted, + /// the image will be decoded at its native resolution (as will be the case if + /// the [getTargetSize] parameter is omitted). + Future<ui.Codec> instantiateImageCodecWithSize( + ui.ImmutableBuffer buffer, { + ui.TargetImageSizeCallback? getTargetSize, + }) { + return ui.instantiateImageCodecWithSize(buffer, getTargetSize: getTargetSize); + } + + @override + void evict(String asset) { + super.evict(asset); + imageCache.clear(); + imageCache.clearLiveImages(); + } + + @override + void handleMemoryPressure() { + super.handleMemoryPressure(); + imageCache.clear(); + } + + /// Listenable that notifies when the available fonts on the system have + /// changed. + /// + /// System fonts can change when the system installs or removes new font. To + /// correctly reflect the change, it is important to relayout text related + /// widgets when this happens. + /// + /// Objects that show text and/or measure text (e.g. via [TextPainter] or + /// [Paragraph]) should listen to this and redraw/remeasure. + Listenable get systemFonts => _systemFonts; + final _SystemFontsNotifier _systemFonts = _SystemFontsNotifier(); + + @override + Future<void> handleSystemMessage(Object systemMessage) async { + await super.handleSystemMessage(systemMessage); + final Map<String, dynamic> message = systemMessage as Map<String, dynamic>; + final String type = message['type'] as String; + switch (type) { + case 'fontsChange': + _systemFonts.notifyListeners(); + } + return; + } +} + +class _SystemFontsNotifier extends Listenable { + final Set<VoidCallback> _systemFontsCallbacks = <VoidCallback>{}; + + void notifyListeners () { + for (final VoidCallback callback in _systemFontsCallbacks) { + callback(); + } + } + + @override + void addListener(VoidCallback listener) { + _systemFontsCallbacks.add(listener); + } + @override + void removeListener(VoidCallback listener) { + _systemFontsCallbacks.remove(listener); + } +} + +/// The singleton that implements the Flutter framework's image cache. +/// +/// The cache is used internally by [ImageProvider] and should generally not be +/// accessed directly. +/// +/// The image cache is created during startup by the [PaintingBinding]'s +/// [PaintingBinding.createImageCache] method. +ImageCache get imageCache => PaintingBinding.instance.imageCache; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/border_radius.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/border_radius.dart new file mode 100644 index 0000000000000000000000000000000000000000..0c23b0a7d925040909dc7daf41be3a3fbecce499 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/border_radius.dart @@ -0,0 +1,896 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; + +/// Base class for [BorderRadius] that allows for text-direction aware resolution. +/// +/// A property or argument of this type accepts classes created either with [ +/// BorderRadius.only] and its variants, or [BorderRadiusDirectional.only] +/// and its variants. +/// +/// To convert a [BorderRadiusGeometry] object of indeterminate type into a +/// [BorderRadius] object, call the [resolve] method. +@immutable +abstract class BorderRadiusGeometry { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const BorderRadiusGeometry(); + + Radius get _topLeft; + Radius get _topRight; + Radius get _bottomLeft; + Radius get _bottomRight; + Radius get _topStart; + Radius get _topEnd; + Radius get _bottomStart; + Radius get _bottomEnd; + + /// Returns the difference between two [BorderRadiusGeometry] objects. + /// + /// If you know you are applying this to two [BorderRadius] or two + /// [BorderRadiusDirectional] objects, consider using the binary infix `-` + /// operator instead, which always returns an object of the same type as the + /// operands, and is typed accordingly. + /// + /// If [subtract] is applied to two objects of the same type ([BorderRadius] or + /// [BorderRadiusDirectional]), an object of that type will be returned (though + /// this is not reflected in the type system). Otherwise, an object + /// representing a combination of both is returned. That object can be turned + /// into a concrete [BorderRadius] using [resolve]. + /// + /// This method returns the same result as [add] applied to the result of + /// negating the argument (using the prefix unary `-` operator or multiplying + /// the argument by -1.0 using the `*` operator). + BorderRadiusGeometry subtract(BorderRadiusGeometry other) { + return _MixedBorderRadius( + _topLeft - other._topLeft, + _topRight - other._topRight, + _bottomLeft - other._bottomLeft, + _bottomRight - other._bottomRight, + _topStart - other._topStart, + _topEnd - other._topEnd, + _bottomStart - other._bottomStart, + _bottomEnd - other._bottomEnd, + ); + } + + /// Returns the sum of two [BorderRadiusGeometry] objects. + /// + /// If you know you are adding two [BorderRadius] or two [BorderRadiusDirectional] + /// objects, consider using the `+` operator instead, which always returns an + /// object of the same type as the operands, and is typed accordingly. + /// + /// If [add] is applied to two objects of the same type ([BorderRadius] or + /// [BorderRadiusDirectional]), an object of that type will be returned (though + /// this is not reflected in the type system). Otherwise, an object + /// representing a combination of both is returned. That object can be turned + /// into a concrete [BorderRadius] using [resolve]. + BorderRadiusGeometry add(BorderRadiusGeometry other) { + return _MixedBorderRadius( + _topLeft + other._topLeft, + _topRight + other._topRight, + _bottomLeft + other._bottomLeft, + _bottomRight + other._bottomRight, + _topStart + other._topStart, + _topEnd + other._topEnd, + _bottomStart + other._bottomStart, + _bottomEnd + other._bottomEnd, + ); + } + + /// Returns the [BorderRadiusGeometry] object with each corner radius negated. + /// + /// This is the same as multiplying the object by -1.0. + /// + /// This operator returns an object of the same type as the operand. + BorderRadiusGeometry operator -(); + + /// Scales the [BorderRadiusGeometry] object's corners by the given factor. + /// + /// This operator returns an object of the same type as the operand. + BorderRadiusGeometry operator *(double other); + + /// Divides the [BorderRadiusGeometry] object's corners by the given factor. + /// + /// This operator returns an object of the same type as the operand. + BorderRadiusGeometry operator /(double other); + + /// Integer divides the [BorderRadiusGeometry] object's corners by the given factor. + /// + /// This operator returns an object of the same type as the operand. + /// + /// This operator may have unexpected results when applied to a mixture of + /// [BorderRadius] and [BorderRadiusDirectional] objects. + BorderRadiusGeometry operator ~/(double other); + + /// Computes the remainder of each corner by the given factor. + /// + /// This operator returns an object of the same type as the operand. + /// + /// This operator may have unexpected results when applied to a mixture of + /// [BorderRadius] and [BorderRadiusDirectional] objects. + BorderRadiusGeometry operator %(double other); + + /// Linearly interpolate between two [BorderRadiusGeometry] objects. + /// + /// If either is null, this function interpolates from [BorderRadius.zero], + /// and the result is an object of the same type as the non-null argument. (If + /// both are null, this returns null.) + /// + /// If [lerp] is applied to two objects of the same type ([BorderRadius] or + /// [BorderRadiusDirectional]), an object of that type will be returned (though + /// this is not reflected in the type system). Otherwise, an object + /// representing a combination of both is returned. That object can be turned + /// into a concrete [BorderRadius] using [resolve]. + /// + /// {@macro dart.ui.shadow.lerp} + static BorderRadiusGeometry? lerp(BorderRadiusGeometry? a, BorderRadiusGeometry? b, double t) { + if (identical(a, b)) { + return a; + } + a ??= BorderRadius.zero; + b ??= BorderRadius.zero; + return a.add((b.subtract(a)) * t); + } + + /// Convert this instance into a [BorderRadius], so that the radii are + /// expressed for specific physical corners (top-left, top-right, etc) rather + /// than in a direction-dependent manner. + /// + /// See also: + /// + /// * [BorderRadius], for which this is a no-op (returns itself). + /// * [BorderRadiusDirectional], which flips the horizontal direction + /// based on the `direction` argument. + BorderRadius resolve(TextDirection? direction); + + @override + String toString() { + String? visual, logical; + if (_topLeft == _topRight && + _topRight == _bottomLeft && + _bottomLeft == _bottomRight) { + if (_topLeft != Radius.zero) { + if (_topLeft.x == _topLeft.y) { + visual = 'BorderRadius.circular(${_topLeft.x.toStringAsFixed(1)})'; + } else { + visual = 'BorderRadius.all($_topLeft)'; + } + } + } else { + // visuals aren't the same and at least one isn't zero + final StringBuffer result = StringBuffer(); + result.write('BorderRadius.only('); + bool comma = false; + if (_topLeft != Radius.zero) { + result.write('topLeft: $_topLeft'); + comma = true; + } + if (_topRight != Radius.zero) { + if (comma) { + result.write(', '); + } + result.write('topRight: $_topRight'); + comma = true; + } + if (_bottomLeft != Radius.zero) { + if (comma) { + result.write(', '); + } + result.write('bottomLeft: $_bottomLeft'); + comma = true; + } + if (_bottomRight != Radius.zero) { + if (comma) { + result.write(', '); + } + result.write('bottomRight: $_bottomRight'); + } + result.write(')'); + visual = result.toString(); + } + if (_topStart == _topEnd && + _topEnd == _bottomEnd && + _bottomEnd == _bottomStart) { + if (_topStart != Radius.zero) { + if (_topStart.x == _topStart.y) { + logical = 'BorderRadiusDirectional.circular(${_topStart.x.toStringAsFixed(1)})'; + } else { + logical = 'BorderRadiusDirectional.all($_topStart)'; + } + } + } else { + // logicals aren't the same and at least one isn't zero + final StringBuffer result = StringBuffer(); + result.write('BorderRadiusDirectional.only('); + bool comma = false; + if (_topStart != Radius.zero) { + result.write('topStart: $_topStart'); + comma = true; + } + if (_topEnd != Radius.zero) { + if (comma) { + result.write(', '); + } + result.write('topEnd: $_topEnd'); + comma = true; + } + if (_bottomStart != Radius.zero) { + if (comma) { + result.write(', '); + } + result.write('bottomStart: $_bottomStart'); + comma = true; + } + if (_bottomEnd != Radius.zero) { + if (comma) { + result.write(', '); + } + result.write('bottomEnd: $_bottomEnd'); + } + result.write(')'); + logical = result.toString(); + } + if (visual != null && logical != null) { + return '$visual + $logical'; + } + if (visual != null) { + return visual; + } + if (logical != null) { + return logical; + } + return 'BorderRadius.zero'; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is BorderRadiusGeometry + && other._topLeft == _topLeft + && other._topRight == _topRight + && other._bottomLeft == _bottomLeft + && other._bottomRight == _bottomRight + && other._topStart == _topStart + && other._topEnd == _topEnd + && other._bottomStart == _bottomStart + && other._bottomEnd == _bottomEnd; + } + + @override + int get hashCode => Object.hash( + _topLeft, + _topRight, + _bottomLeft, + _bottomRight, + _topStart, + _topEnd, + _bottomStart, + _bottomEnd, + ); +} + +/// An immutable set of radii for each corner of a rectangle. +/// +/// Used by [BoxDecoration] when the shape is a [BoxShape.rectangle]. +/// +/// The [BorderRadius] class specifies offsets in terms of visual corners, e.g. +/// [topLeft]. These values are not affected by the [TextDirection]. To support +/// both left-to-right and right-to-left layouts, consider using +/// [BorderRadiusDirectional], which is expressed in terms that are relative to +/// a [TextDirection] (typically obtained from the ambient [Directionality]). +class BorderRadius extends BorderRadiusGeometry { + /// Creates a border radius where all radii are [radius]. + const BorderRadius.all(Radius radius) : this.only( + topLeft: radius, + topRight: radius, + bottomLeft: radius, + bottomRight: radius, + ); + + /// Creates a border radius where all radii are [Radius.circular(radius)]. + BorderRadius.circular(double radius) : this.all( + Radius.circular(radius), + ); + + /// Creates a vertically symmetric border radius where the top and bottom + /// sides of the rectangle have the same radii. + const BorderRadius.vertical({ + Radius top = Radius.zero, + Radius bottom = Radius.zero, + }) : this.only( + topLeft: top, + topRight: top, + bottomLeft: bottom, + bottomRight: bottom, + ); + + /// Creates a horizontally symmetrical border radius where the left and right + /// sides of the rectangle have the same radii. + const BorderRadius.horizontal({ + Radius left = Radius.zero, + Radius right = Radius.zero, + }) : this.only( + topLeft: left, + topRight: right, + bottomLeft: left, + bottomRight: right, + ); + + /// Creates a border radius with only the given non-zero values. The other + /// corners will be right angles. + const BorderRadius.only({ + this.topLeft = Radius.zero, + this.topRight = Radius.zero, + this.bottomLeft = Radius.zero, + this.bottomRight = Radius.zero, + }); + + /// Returns a copy of this BorderRadius with the given fields replaced with + /// the new values. + BorderRadius copyWith({ + Radius? topLeft, + Radius? topRight, + Radius? bottomLeft, + Radius? bottomRight, + }) { + return BorderRadius.only( + topLeft: topLeft ?? this.topLeft, + topRight: topRight ?? this.topRight, + bottomLeft: bottomLeft ?? this.bottomLeft, + bottomRight: bottomRight ?? this.bottomRight, + ); + } + + /// A border radius with all zero radii. + static const BorderRadius zero = BorderRadius.all(Radius.zero); + + /// The top-left [Radius]. + final Radius topLeft; + + @override + Radius get _topLeft => topLeft; + + /// The top-right [Radius]. + final Radius topRight; + + @override + Radius get _topRight => topRight; + + /// The bottom-left [Radius]. + final Radius bottomLeft; + + @override + Radius get _bottomLeft => bottomLeft; + + /// The bottom-right [Radius]. + final Radius bottomRight; + + @override + Radius get _bottomRight => bottomRight; + + @override + Radius get _topStart => Radius.zero; + + @override + Radius get _topEnd => Radius.zero; + + @override + Radius get _bottomStart => Radius.zero; + + @override + Radius get _bottomEnd => Radius.zero; + + /// Creates an [RRect] from the current border radius and a [Rect]. + /// + /// If any of the radii have negative values in x or y, those values will be + /// clamped to zero in order to produce a valid [RRect]. + RRect toRRect(Rect rect) { + // Because the current radii could be negative, we must clamp them before + // converting them to an RRect to be rendered, since negative radii on + // RRects don't make sense. + return RRect.fromRectAndCorners( + rect, + topLeft: topLeft.clamp(minimum: Radius.zero), + topRight: topRight.clamp(minimum: Radius.zero), + bottomLeft: bottomLeft.clamp(minimum: Radius.zero), + bottomRight: bottomRight.clamp(minimum: Radius.zero), + ); + } + + @override + BorderRadiusGeometry subtract(BorderRadiusGeometry other) { + if (other is BorderRadius) { + return this - other; + } + return super.subtract(other); + } + + @override + BorderRadiusGeometry add(BorderRadiusGeometry other) { + if (other is BorderRadius) { + return this + other; + } + return super.add(other); + } + + /// Returns the difference between two [BorderRadius] objects. + BorderRadius operator -(BorderRadius other) { + return BorderRadius.only( + topLeft: topLeft - other.topLeft, + topRight: topRight - other.topRight, + bottomLeft: bottomLeft - other.bottomLeft, + bottomRight: bottomRight - other.bottomRight, + ); + } + + /// Returns the sum of two [BorderRadius] objects. + BorderRadius operator +(BorderRadius other) { + return BorderRadius.only( + topLeft: topLeft + other.topLeft, + topRight: topRight + other.topRight, + bottomLeft: bottomLeft + other.bottomLeft, + bottomRight: bottomRight + other.bottomRight, + ); + } + + /// Returns the [BorderRadius] object with each corner negated. + /// + /// This is the same as multiplying the object by -1.0. + @override + BorderRadius operator -() { + return BorderRadius.only( + topLeft: -topLeft, + topRight: -topRight, + bottomLeft: -bottomLeft, + bottomRight: -bottomRight, + ); + } + + /// Scales each corner of the [BorderRadius] by the given factor. + @override + BorderRadius operator *(double other) { + return BorderRadius.only( + topLeft: topLeft * other, + topRight: topRight * other, + bottomLeft: bottomLeft * other, + bottomRight: bottomRight * other, + ); + } + + /// Divides each corner of the [BorderRadius] by the given factor. + @override + BorderRadius operator /(double other) { + return BorderRadius.only( + topLeft: topLeft / other, + topRight: topRight / other, + bottomLeft: bottomLeft / other, + bottomRight: bottomRight / other, + ); + } + + /// Integer divides each corner of the [BorderRadius] by the given factor. + @override + BorderRadius operator ~/(double other) { + return BorderRadius.only( + topLeft: topLeft ~/ other, + topRight: topRight ~/ other, + bottomLeft: bottomLeft ~/ other, + bottomRight: bottomRight ~/ other, + ); + } + + /// Computes the remainder of each corner by the given factor. + @override + BorderRadius operator %(double other) { + return BorderRadius.only( + topLeft: topLeft % other, + topRight: topRight % other, + bottomLeft: bottomLeft % other, + bottomRight: bottomRight % other, + ); + } + + /// Linearly interpolate between two [BorderRadius] objects. + /// + /// If either is null, this function interpolates from [BorderRadius.zero]. + /// + /// {@macro dart.ui.shadow.lerp} + static BorderRadius? lerp(BorderRadius? a, BorderRadius? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b! * t; + } + if (b == null) { + return a * (1.0 - t); + } + return BorderRadius.only( + topLeft: Radius.lerp(a.topLeft, b.topLeft, t)!, + topRight: Radius.lerp(a.topRight, b.topRight, t)!, + bottomLeft: Radius.lerp(a.bottomLeft, b.bottomLeft, t)!, + bottomRight: Radius.lerp(a.bottomRight, b.bottomRight, t)!, + ); + } + + @override + BorderRadius resolve(TextDirection? direction) => this; +} + +/// An immutable set of radii for each corner of a rectangle, but with the +/// corners specified in a manner dependent on the writing direction. +/// +/// This can be used to specify a corner radius on the leading or trailing edge +/// of a box, so that it flips to the other side when the text alignment flips +/// (e.g. being on the top right in English text but the top left in Arabic +/// text). +/// +/// See also: +/// +/// * [BorderRadius], a variant that uses physical labels (`topLeft` and +/// `topRight` instead of `topStart` and `topEnd`). +class BorderRadiusDirectional extends BorderRadiusGeometry { + /// Creates a border radius where all radii are [radius]. + const BorderRadiusDirectional.all(Radius radius) : this.only( + topStart: radius, + topEnd: radius, + bottomStart: radius, + bottomEnd: radius, + ); + + /// Creates a border radius where all radii are [Radius.circular(radius)]. + BorderRadiusDirectional.circular(double radius) : this.all( + Radius.circular(radius), + ); + + /// Creates a vertically symmetric border radius where the top and bottom + /// sides of the rectangle have the same radii. + const BorderRadiusDirectional.vertical({ + Radius top = Radius.zero, + Radius bottom = Radius.zero, + }) : this.only( + topStart: top, + topEnd: top, + bottomStart: bottom, + bottomEnd: bottom, + ); + + /// Creates a horizontally symmetrical border radius where the start and end + /// sides of the rectangle have the same radii. + const BorderRadiusDirectional.horizontal({ + Radius start = Radius.zero, + Radius end = Radius.zero, + }) : this.only( + topStart: start, + topEnd: end, + bottomStart: start, + bottomEnd: end, + ); + + /// Creates a border radius with only the given non-zero values. The other + /// corners will be right angles. + const BorderRadiusDirectional.only({ + this.topStart = Radius.zero, + this.topEnd = Radius.zero, + this.bottomStart = Radius.zero, + this.bottomEnd = Radius.zero, + }); + + /// A border radius with all zero radii. + /// + /// Consider using [BorderRadius.zero] instead, since that object has the same + /// effect, but will be cheaper to [resolve]. + static const BorderRadiusDirectional zero = BorderRadiusDirectional.all(Radius.zero); + + /// The top-start [Radius]. + final Radius topStart; + + @override + Radius get _topStart => topStart; + + /// The top-end [Radius]. + final Radius topEnd; + + @override + Radius get _topEnd => topEnd; + + /// The bottom-start [Radius]. + final Radius bottomStart; + + @override + Radius get _bottomStart => bottomStart; + + /// The bottom-end [Radius]. + final Radius bottomEnd; + + @override + Radius get _bottomEnd => bottomEnd; + + @override + Radius get _topLeft => Radius.zero; + + @override + Radius get _topRight => Radius.zero; + + @override + Radius get _bottomLeft => Radius.zero; + + @override + Radius get _bottomRight => Radius.zero; + + @override + BorderRadiusGeometry subtract(BorderRadiusGeometry other) { + if (other is BorderRadiusDirectional) { + return this - other; + } + return super.subtract(other); + } + + @override + BorderRadiusGeometry add(BorderRadiusGeometry other) { + if (other is BorderRadiusDirectional) { + return this + other; + } + return super.add(other); + } + + /// Returns the difference between two [BorderRadiusDirectional] objects. + BorderRadiusDirectional operator -(BorderRadiusDirectional other) { + return BorderRadiusDirectional.only( + topStart: topStart - other.topStart, + topEnd: topEnd - other.topEnd, + bottomStart: bottomStart - other.bottomStart, + bottomEnd: bottomEnd - other.bottomEnd, + ); + } + + /// Returns the sum of two [BorderRadiusDirectional] objects. + BorderRadiusDirectional operator +(BorderRadiusDirectional other) { + return BorderRadiusDirectional.only( + topStart: topStart + other.topStart, + topEnd: topEnd + other.topEnd, + bottomStart: bottomStart + other.bottomStart, + bottomEnd: bottomEnd + other.bottomEnd, + ); + } + + /// Returns the [BorderRadiusDirectional] object with each corner negated. + /// + /// This is the same as multiplying the object by -1.0. + @override + BorderRadiusDirectional operator -() { + return BorderRadiusDirectional.only( + topStart: -topStart, + topEnd: -topEnd, + bottomStart: -bottomStart, + bottomEnd: -bottomEnd, + ); + } + + /// Scales each corner of the [BorderRadiusDirectional] by the given factor. + @override + BorderRadiusDirectional operator *(double other) { + return BorderRadiusDirectional.only( + topStart: topStart * other, + topEnd: topEnd * other, + bottomStart: bottomStart * other, + bottomEnd: bottomEnd * other, + ); + } + + /// Divides each corner of the [BorderRadiusDirectional] by the given factor. + @override + BorderRadiusDirectional operator /(double other) { + return BorderRadiusDirectional.only( + topStart: topStart / other, + topEnd: topEnd / other, + bottomStart: bottomStart / other, + bottomEnd: bottomEnd / other, + ); + } + + /// Integer divides each corner of the [BorderRadiusDirectional] by the given factor. + @override + BorderRadiusDirectional operator ~/(double other) { + return BorderRadiusDirectional.only( + topStart: topStart ~/ other, + topEnd: topEnd ~/ other, + bottomStart: bottomStart ~/ other, + bottomEnd: bottomEnd ~/ other, + ); + } + + /// Computes the remainder of each corner by the given factor. + @override + BorderRadiusDirectional operator %(double other) { + return BorderRadiusDirectional.only( + topStart: topStart % other, + topEnd: topEnd % other, + bottomStart: bottomStart % other, + bottomEnd: bottomEnd % other, + ); + } + + /// Linearly interpolate between two [BorderRadiusDirectional] objects. + /// + /// If either is null, this function interpolates from [BorderRadiusDirectional.zero]. + /// + /// {@macro dart.ui.shadow.lerp} + static BorderRadiusDirectional? lerp(BorderRadiusDirectional? a, BorderRadiusDirectional? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b! * t; + } + if (b == null) { + return a * (1.0 - t); + } + return BorderRadiusDirectional.only( + topStart: Radius.lerp(a.topStart, b.topStart, t)!, + topEnd: Radius.lerp(a.topEnd, b.topEnd, t)!, + bottomStart: Radius.lerp(a.bottomStart, b.bottomStart, t)!, + bottomEnd: Radius.lerp(a.bottomEnd, b.bottomEnd, t)!, + ); + } + + @override + BorderRadius resolve(TextDirection? direction) { + assert(direction != null); + switch (direction!) { + case TextDirection.rtl: + return BorderRadius.only( + topLeft: topEnd, + topRight: topStart, + bottomLeft: bottomEnd, + bottomRight: bottomStart, + ); + case TextDirection.ltr: + return BorderRadius.only( + topLeft: topStart, + topRight: topEnd, + bottomLeft: bottomStart, + bottomRight: bottomEnd, + ); + } + } +} + +class _MixedBorderRadius extends BorderRadiusGeometry { + const _MixedBorderRadius( + this._topLeft, + this._topRight, + this._bottomLeft, + this._bottomRight, + this._topStart, + this._topEnd, + this._bottomStart, + this._bottomEnd, + ); + + @override + final Radius _topLeft; + + @override + final Radius _topRight; + + @override + final Radius _bottomLeft; + + @override + final Radius _bottomRight; + + @override + final Radius _topStart; + + @override + final Radius _topEnd; + + @override + final Radius _bottomStart; + + @override + final Radius _bottomEnd; + + @override + _MixedBorderRadius operator -() { + return _MixedBorderRadius( + -_topLeft, + -_topRight, + -_bottomLeft, + -_bottomRight, + -_topStart, + -_topEnd, + -_bottomStart, + -_bottomEnd, + ); + } + + /// Scales each corner of the [_MixedBorderRadius] by the given factor. + @override + _MixedBorderRadius operator *(double other) { + return _MixedBorderRadius( + _topLeft * other, + _topRight * other, + _bottomLeft * other, + _bottomRight * other, + _topStart * other, + _topEnd * other, + _bottomStart * other, + _bottomEnd * other, + ); + } + + @override + _MixedBorderRadius operator /(double other) { + return _MixedBorderRadius( + _topLeft / other, + _topRight / other, + _bottomLeft / other, + _bottomRight / other, + _topStart / other, + _topEnd / other, + _bottomStart / other, + _bottomEnd / other, + ); + } + + @override + _MixedBorderRadius operator ~/(double other) { + return _MixedBorderRadius( + _topLeft ~/ other, + _topRight ~/ other, + _bottomLeft ~/ other, + _bottomRight ~/ other, + _topStart ~/ other, + _topEnd ~/ other, + _bottomStart ~/ other, + _bottomEnd ~/ other, + ); + } + + @override + _MixedBorderRadius operator %(double other) { + return _MixedBorderRadius( + _topLeft % other, + _topRight % other, + _bottomLeft % other, + _bottomRight % other, + _topStart % other, + _topEnd % other, + _bottomStart % other, + _bottomEnd % other, + ); + } + + @override + BorderRadius resolve(TextDirection? direction) { + assert(direction != null); + switch (direction!) { + case TextDirection.rtl: + return BorderRadius.only( + topLeft: _topLeft + _topEnd, + topRight: _topRight + _topStart, + bottomLeft: _bottomLeft + _bottomEnd, + bottomRight: _bottomRight + _bottomStart, + ); + case TextDirection.ltr: + return BorderRadius.only( + topLeft: _topLeft + _topStart, + topRight: _topRight + _topEnd, + bottomLeft: _bottomLeft + _bottomStart, + bottomRight: _bottomRight + _bottomEnd, + ); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/borders.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/borders.dart new file mode 100644 index 0000000000000000000000000000000000000000..63e7f3bf83748d9c7a48e1dbdf9fe794ef63aa7a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/borders.dart @@ -0,0 +1,973 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'edge_insets.dart'; + +/// The style of line to draw for a [BorderSide] in a [Border]. +enum BorderStyle { + /// Skip the border. + none, + + /// Draw the border as a solid line. + solid, + + // if you add more, think about how they will lerp +} + +/// A side of a border of a box. +/// +/// A [Border] consists of four [BorderSide] objects: [Border.top], +/// [Border.left], [Border.right], and [Border.bottom]. +/// +/// Setting [BorderSide.width] to 0.0 will result in hairline rendering; see +/// [BorderSide.width] for a more involved explanation. +/// +/// {@tool snippet} +/// This sample shows how [BorderSide] objects can be used in a [Container], via +/// a [BoxDecoration] and a [Border], to decorate some [Text]. In this example, +/// the text has a thick bar above it that is light blue, and a thick bar below +/// it that is a darker shade of blue. +/// +/// ```dart +/// Container( +/// padding: const EdgeInsets.all(8.0), +/// decoration: BoxDecoration( +/// border: Border( +/// top: BorderSide(width: 16.0, color: Colors.lightBlue.shade50), +/// bottom: BorderSide(width: 16.0, color: Colors.lightBlue.shade900), +/// ), +/// ), +/// child: const Text('Flutter in the sky', textAlign: TextAlign.center), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Border], which uses [BorderSide] objects to represent its sides. +/// * [BoxDecoration], which optionally takes a [Border] object. +/// * [TableBorder], which is similar to [Border] but has two more sides +/// ([TableBorder.horizontalInside] and [TableBorder.verticalInside]), both +/// of which are also [BorderSide] objects. +@immutable +class BorderSide with Diagnosticable { + /// Creates the side of a border. + /// + /// By default, the border is 1.0 logical pixels wide and solid black. + const BorderSide({ + this.color = const Color(0xFF000000), + this.width = 1.0, + this.style = BorderStyle.solid, + this.strokeAlign = strokeAlignInside, + }) : assert(width >= 0.0); + + /// Creates a [BorderSide] that represents the addition of the two given + /// [BorderSide]s. + /// + /// It is only valid to call this if [canMerge] returns true for the two + /// sides. + /// + /// If one of the sides is zero-width with [BorderStyle.none], then the other + /// side is return as-is. If both of the sides are zero-width with + /// [BorderStyle.none], then [BorderSide.none] is returned. + static BorderSide merge(BorderSide a, BorderSide b) { + assert(canMerge(a, b)); + final bool aIsNone = a.style == BorderStyle.none && a.width == 0.0; + final bool bIsNone = b.style == BorderStyle.none && b.width == 0.0; + if (aIsNone && bIsNone) { + return BorderSide.none; + } + if (aIsNone) { + return b; + } + if (bIsNone) { + return a; + } + assert(a.color == b.color); + assert(a.style == b.style); + return BorderSide( + color: a.color, // == b.color + width: a.width + b.width, + strokeAlign: math.max(a.strokeAlign, b.strokeAlign), + style: a.style, // == b.style + ); + } + + /// The color of this side of the border. + final Color color; + + /// The width of this side of the border, in logical pixels. + /// + /// Setting width to 0.0 will result in a hairline border. This means that + /// the border will have the width of one physical pixel. Hairline + /// rendering takes shortcuts when the path overlaps a pixel more than once. + /// This means that it will render faster than otherwise, but it might + /// double-hit pixels, giving it a slightly darker/lighter result. + /// + /// To omit the border entirely, set the [style] to [BorderStyle.none]. + final double width; + + /// The style of this side of the border. + /// + /// To omit a side, set [style] to [BorderStyle.none]. This skips + /// painting the border, but the border still has a [width]. + final BorderStyle style; + + /// A hairline black border that is not rendered. + static const BorderSide none = BorderSide(width: 0.0, style: BorderStyle.none); + + /// The relative position of the stroke on a [BorderSide] in an + /// [OutlinedBorder] or [Border]. + /// + /// Values typically range from -1.0 ([strokeAlignInside], inside border, + /// default) to 1.0 ([strokeAlignOutside], outside border), without any + /// bound constraints (e.g., a value of -2.0 is not typical, but allowed). + /// A value of 0 ([strokeAlignCenter]) will center the border on the edge + /// of the widget. + /// + /// When set to [strokeAlignInside], the stroke is drawn completely inside + /// the widget. For [strokeAlignCenter] and [strokeAlignOutside], a property + /// such as [Container.clipBehavior] can be used in an outside widget to clip + /// it. If [Container.decoration] has a border, the container may incorporate + /// [width] as additional padding: + /// - [strokeAlignInside] provides padding with full [width]. + /// - [strokeAlignCenter] provides padding with half [width]. + /// - [strokeAlignOutside] provides zero padding, as stroke is drawn entirely outside. + /// + /// This property is not honored by [toPaint] (because the [Paint] object + /// cannot represent it); it is intended that classes that use [BorderSide] + /// objects implement this property when painting borders by suitably + /// inflating or deflating their regions. + /// + /// {@tool dartpad} + /// This example shows an animation of how [strokeAlign] affects the drawing + /// when applied to borders of various shapes. + /// + /// ** See code in examples/api/lib/painting/borders/border_side.stroke_align.0.dart ** + /// {@end-tool} + final double strokeAlign; + + /// The border is drawn fully inside of the border path. + /// + /// This is a constant for use with [strokeAlign]. + /// + /// This is the default value for [strokeAlign]. + static const double strokeAlignInside = -1.0; + + /// The border is drawn on the center of the border path, with half of the + /// [BorderSide.width] on the inside, and the other half on the outside of + /// the path. + /// + /// This is a constant for use with [strokeAlign]. + static const double strokeAlignCenter = 0.0; + + /// The border is drawn on the outside of the border path. + /// + /// This is a constant for use with [strokeAlign]. + static const double strokeAlignOutside = 1.0; + + /// Creates a copy of this border but with the given fields replaced with the new values. + BorderSide copyWith({ + Color? color, + double? width, + BorderStyle? style, + double? strokeAlign, + }) { + return BorderSide( + color: color ?? this.color, + width: width ?? this.width, + style: style ?? this.style, + strokeAlign: strokeAlign ?? this.strokeAlign, + ); + } + + /// Creates a copy of this border side description but with the width scaled + /// by the factor `t`. + /// + /// The `t` argument represents the multiplicand, or the position on the + /// timeline for an interpolation from nothing to `this`, with 0.0 meaning + /// that the object returned should be the nil variant of this object, 1.0 + /// meaning that no change should be applied, returning `this` (or something + /// equivalent to `this`), and other values meaning that the object should be + /// multiplied by `t`. Negative values are treated like zero. + /// + /// Since a zero width is normally painted as a hairline width rather than no + /// border at all, the zero factor is special-cased to instead change the + /// style to [BorderStyle.none]. + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + BorderSide scale(double t) { + return BorderSide( + color: color, + width: math.max(0.0, width * t), + style: t <= 0.0 ? BorderStyle.none : style, + ); + } + + /// Create a [Paint] object that, if used to stroke a line, will draw the line + /// in this border's style. + /// + /// The [strokeAlign] property is not reflected in the [Paint]; consumers must + /// implement that directly by inflating or deflating their region appropriately. + /// + /// Not all borders use this method to paint their border sides. For example, + /// non-uniform rectangular [Border]s have beveled edges and so paint their + /// border sides as filled shapes rather than using a stroke. + Paint toPaint() { + switch (style) { + case BorderStyle.solid: + return Paint() + ..color = color + ..strokeWidth = width + ..style = PaintingStyle.stroke; + case BorderStyle.none: + return Paint() + ..color = const Color(0x00000000) + ..strokeWidth = 0.0 + ..style = PaintingStyle.stroke; + } + } + + /// Whether the two given [BorderSide]s can be merged using + /// [BorderSide.merge]. + /// + /// Two sides can be merged if one or both are zero-width with + /// [BorderStyle.none], or if they both have the same color and style. + static bool canMerge(BorderSide a, BorderSide b) { + if ((a.style == BorderStyle.none && a.width == 0.0) || + (b.style == BorderStyle.none && b.width == 0.0)) { + return true; + } + return a.style == b.style + && a.color == b.color; + } + + /// Linearly interpolate between two border sides. + /// + /// {@macro dart.ui.shadow.lerp} + static BorderSide lerp(BorderSide a, BorderSide b, double t) { + if (identical(a, b)) { + return a; + } + if (t == 0.0) { + return a; + } + if (t == 1.0) { + return b; + } + final double width = ui.lerpDouble(a.width, b.width, t)!; + if (width < 0.0) { + return BorderSide.none; + } + if (a.style == b.style && a.strokeAlign == b.strokeAlign) { + return BorderSide( + color: Color.lerp(a.color, b.color, t)!, + width: width, + style: a.style, // == b.style + strokeAlign: a.strokeAlign, // == b.strokeAlign + ); + } + final Color colorA, colorB; + switch (a.style) { + case BorderStyle.solid: + colorA = a.color; + case BorderStyle.none: + colorA = a.color.withAlpha(0x00); + } + switch (b.style) { + case BorderStyle.solid: + colorB = b.color; + case BorderStyle.none: + colorB = b.color.withAlpha(0x00); + } + if (a.strokeAlign != b.strokeAlign) { + return BorderSide( + color: Color.lerp(colorA, colorB, t)!, + width: width, + strokeAlign: ui.lerpDouble(a.strokeAlign, b.strokeAlign, t)!, + ); + } + return BorderSide( + color: Color.lerp(colorA, colorB, t)!, + width: width, + strokeAlign: a.strokeAlign, // == b.strokeAlign + ); + } + + /// Get the amount of the stroke width that lies inside of the [BorderSide]. + /// + /// For example, this will return the [width] for a [strokeAlign] of -1, half + /// the [width] for a [strokeAlign] of 0, and 0 for a [strokeAlign] of 1. + double get strokeInset => width * (1 - (1 + strokeAlign) / 2); + + /// Get the amount of the stroke width that lies outside of the [BorderSide]. + /// + /// For example, this will return 0 for a [strokeAlign] of -1, half the + /// [width] for a [strokeAlign] of 0, and the [width] for a [strokeAlign] + /// of 1. + double get strokeOutset => width * (1 + strokeAlign) / 2; + + /// The offset of the stroke, taking into account the stroke alignment. + /// + /// For example, this will return the negative [width] of the stroke + /// for a [strokeAlign] of -1, 0 for a [strokeAlign] of 0, and the + /// [width] for a [strokeAlign] of -1. + double get strokeOffset => width * strokeAlign; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is BorderSide + && other.color == color + && other.width == width + && other.style == style + && other.strokeAlign == strokeAlign; + } + + @override + int get hashCode => Object.hash(color, width, style, strokeAlign); + + @override + String toStringShort() => 'BorderSide'; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Color>('color', color, defaultValue: const Color(0xFF000000))); + properties.add(DoubleProperty('width', width, defaultValue: 1.0)); + properties.add(DoubleProperty('strokeAlign', strokeAlign, defaultValue: strokeAlignInside)); + properties.add(EnumProperty<BorderStyle>('style', style, defaultValue: BorderStyle.solid)); + } +} + +/// Base class for shape outlines. +/// +/// This class handles how to add multiple borders together. Subclasses define +/// various shapes, like circles ([CircleBorder]), rounded rectangles +/// ([RoundedRectangleBorder]), continuous rectangles +/// ([ContinuousRectangleBorder]), or beveled rectangles +/// ([BeveledRectangleBorder]). +/// +/// See also: +/// +/// * [ShapeDecoration], which can be used with [DecoratedBox] to show a shape. +/// * [Material] (and many other widgets in the Material library), which takes +/// a [ShapeBorder] to define its shape. +/// * [NotchedShape], which describes a shape with a hole in it. +@immutable +abstract class ShapeBorder { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const ShapeBorder(); + + /// The widths of the sides of this border represented as an [EdgeInsets]. + /// + /// Specifically, this is the amount by which a rectangle should be inset so + /// as to avoid painting over any important part of the border. It is the + /// amount by which additional borders will be inset before they are drawn. + /// + /// This can be used, for example, with a [Padding] widget to inset a box by + /// the size of these borders. + /// + /// Shapes that have a fixed ratio regardless of the area on which they are + /// painted, or that change their rendering based on the size they are given + /// when painting (for instance [CircleBorder]), will not return valid + /// [dimensions] information because they cannot know their eventual size when + /// computing their [dimensions]. + EdgeInsetsGeometry get dimensions; + + /// Attempts to create a new object that represents the amalgamation of `this` + /// border and the `other` border. + /// + /// If the type of the other border isn't known, or the given instance cannot + /// be reasonably added to this instance, then this should return null. + /// + /// This method is used by the [operator +] implementation. + /// + /// The `reversed` argument is true if this object was the right operand of + /// the `+` operator, and false if it was the left operand. + @protected + ShapeBorder? add(ShapeBorder other, { bool reversed = false }) => null; + + /// Creates a new border consisting of the two borders on either side of the + /// operator. + /// + /// If the borders belong to classes that know how to add themselves, then + /// this results in a new border that represents the intelligent addition of + /// those two borders (see [add]). Otherwise, an object is returned that + /// merely paints the two borders sequentially, with the left hand operand on + /// the inside and the right hand operand on the outside. + ShapeBorder operator +(ShapeBorder other) { + return add(other) ?? other.add(this, reversed: true) ?? _CompoundBorder(<ShapeBorder>[other, this]); + } + + /// Creates a copy of this border, scaled by the factor `t`. + /// + /// Typically this means scaling the width of the border's side, but it can + /// also include scaling other artifacts of the border, e.g. the border radius + /// of a [RoundedRectangleBorder]. + /// + /// The `t` argument represents the multiplicand, or the position on the + /// timeline for an interpolation from nothing to `this`, with 0.0 meaning + /// that the object returned should be the nil variant of this object, 1.0 + /// meaning that no change should be applied, returning `this` (or something + /// equivalent to `this`), and other values meaning that the object should be + /// multiplied by `t`. Negative values are allowed but may be meaningless + /// (they correspond to extrapolating the interpolation from this object to + /// nothing, and going beyond nothing) + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + /// + /// See also: + /// + /// * [BorderSide.scale], which most [ShapeBorder] subclasses defer to for + /// the actual computation. + ShapeBorder scale(double t); + + /// Linearly interpolates from another [ShapeBorder] (possibly of another + /// class) to `this`. + /// + /// When implementing this method in subclasses, return null if this class + /// cannot interpolate from `a`. In that case, [lerp] will try `a`'s [lerpTo] + /// method instead. If `a` is null, this must not return null. + /// + /// The base class implementation handles the case of `a` being null by + /// deferring to [scale]. + /// + /// The `t` argument represents position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `a` (or something + /// equivalent to `a`), 1.0 meaning that the interpolation has finished, + /// returning `this` (or something equivalent to `this`), and values in + /// between meaning that the interpolation is at the relevant point on the + /// timeline between `a` and `this`. The interpolation can be extrapolated + /// beyond 0.0 and 1.0, so negative values and values greater than 1.0 are + /// valid (and can easily be generated by curves such as + /// [Curves.elasticInOut]). + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + /// + /// Instead of calling this directly, use [ShapeBorder.lerp]. + @protected + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a == null) { + return scale(t); + } + return null; + } + + /// Linearly interpolates from `this` to another [ShapeBorder] (possibly of + /// another class). + /// + /// This is called if `b`'s [lerpTo] did not know how to handle this class. + /// + /// When implementing this method in subclasses, return null if this class + /// cannot interpolate from `b`. In that case, [lerp] will apply a default + /// behavior instead. If `b` is null, this must not return null. + /// + /// The base class implementation handles the case of `b` being null by + /// deferring to [scale]. + /// + /// The `t` argument represents position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `this` (or something + /// equivalent to `this`), 1.0 meaning that the interpolation has finished, + /// returning `b` (or something equivalent to `b`), and values in between + /// meaning that the interpolation is at the relevant point on the timeline + /// between `this` and `b`. The interpolation can be extrapolated beyond 0.0 + /// and 1.0, so negative values and values greater than 1.0 are valid (and can + /// easily be generated by curves such as [Curves.elasticInOut]). + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + /// + /// Instead of calling this directly, use [ShapeBorder.lerp]. + @protected + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b == null) { + return scale(1.0 - t); + } + return null; + } + + /// Linearly interpolates between two [ShapeBorder]s. + /// + /// This defers to `b`'s [lerpTo] function if `b` is not null. If `b` is + /// null or if its [lerpTo] returns null, it uses `a`'s [lerpFrom] + /// function instead. If both return null, it returns `a` before `t=0.5` + /// and `b` after `t=0.5`. + /// + /// {@macro dart.ui.shadow.lerp} + static ShapeBorder? lerp(ShapeBorder? a, ShapeBorder? b, double t) { + if (identical(a, b)) { + return a; + } + ShapeBorder? result; + if (b != null) { + result = b.lerpFrom(a, t); + } + if (result == null && a != null) { + result = a.lerpTo(b, t); + } + return result ?? (t < 0.5 ? a : b); + } + + /// Create a [Path] that describes the outer edge of the border. + /// + /// This path must not cross the path given by [getInnerPath] for the same + /// [Rect]. + /// + /// To obtain a [Path] that describes the area of the border itself, set the + /// [Path.fillType] of the returned object to [PathFillType.evenOdd], and add + /// to this object the path returned from [getInnerPath] (using + /// [Path.addPath]). + /// + /// The `textDirection` argument must be provided non-null if the border + /// has a text direction dependency (for example if it is expressed in terms + /// of "start" and "end" instead of "left" and "right"). It may be null if + /// the border will not need the text direction to paint itself. + /// + /// See also: + /// + /// * [getInnerPath], which creates the path for the inner edge. + /// * [Path.contains], which can tell if an [Offset] is within a [Path]. + Path getOuterPath(Rect rect, { TextDirection? textDirection }); + + /// Create a [Path] that describes the inner edge of the border. + /// + /// This path must not cross the path given by [getOuterPath] for the same + /// [Rect]. + /// + /// To obtain a [Path] that describes the area of the border itself, set the + /// [Path.fillType] of the returned object to [PathFillType.evenOdd], and add + /// to this object the path returned from [getOuterPath] (using + /// [Path.addPath]). + /// + /// The `textDirection` argument must be provided and non-null if the border + /// has a text direction dependency (for example if it is expressed in terms + /// of "start" and "end" instead of "left" and "right"). It may be null if + /// the border will not need the text direction to paint itself. + /// + /// See also: + /// + /// * [getOuterPath], which creates the path for the outer edge. + /// * [Path.contains], which can tell if an [Offset] is within a [Path]. + Path getInnerPath(Rect rect, { TextDirection? textDirection }); + + /// Paint a canvas with the appropriate shape. + /// + /// On [ShapeBorder] subclasses whose [preferPaintInterior] method returns + /// true, this should be faster than using [Canvas.drawPath] with the path + /// provided by [getOuterPath]. (If [preferPaintInterior] returns false, + /// then this method asserts in debug mode and does nothing in release mode.) + /// + /// Subclasses are expected to implement this method when the [Canvas] API + /// has a dedicated method to draw the relevant shape. For example, + /// [CircleBorder] uses this to call [Canvas.drawCircle], and + /// [RoundedRectangleBorder] uses this to call [Canvas.drawRRect]. + /// + /// Subclasses that implement this must ensure that calling [paintInterior] + /// is semantically equivalent to (i.e. renders the same pixels as) calling + /// [Canvas.drawPath] with the same [Paint] and the [Path] returned from + /// [getOuterPath], and must also override [preferPaintInterior] to + /// return true. + /// + /// For example, a shape that draws a rectangle might implement + /// [getOuterPath], [paintInterior], and [preferPaintInterior] as follows: + /// + /// ```dart + /// class RectangleBorder extends OutlinedBorder { + /// // ... + /// + /// @override + /// Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + /// return Path() + /// ..addRect(rect); + /// } + /// + /// @override + /// void paintInterior(Canvas canvas, Rect rect, Paint paint, {TextDirection? textDirection}) { + /// canvas.drawRect(rect, paint); + /// } + /// + /// @override + /// bool get preferPaintInterior => true; + /// + /// // ... + /// } + /// ``` + /// + /// When a shape can only be drawn using path, [preferPaintInterior] must + /// return false. In that case, classes such as [ShapeDecoration] will cache + /// the path from [getOuterPath] and call [Canvas.drawPath] directly. + void paintInterior(Canvas canvas, Rect rect, Paint paint, {TextDirection? textDirection}) { + assert(!preferPaintInterior, '$runtimeType.preferPaintInterior returns true but $runtimeType.paintInterior is not implemented.'); + assert(false, '$runtimeType.preferPaintInterior returns false, so it is an error to call its paintInterior method.'); + } + + /// Reports whether [paintInterior] is implemented. + /// + /// Classes such as [ShapeDecoration] prefer to use [paintInterior] if this + /// getter returns true. This is intended to enable faster painting; instead + /// of computing a shape using [getOuterPath] and then drawing it using + /// [Canvas.drawPath], the path can be drawn directly to the [Canvas] using + /// dedicated methods such as [Canvas.drawRect] or [Canvas.drawCircle]. + /// + /// By default, this getter returns false. + /// + /// Subclasses that implement [paintInterior] should override this to return + /// true. Subclasses should only override [paintInterior] if doing so enables + /// faster rendering than is possible with [Canvas.drawPath] (so, in + /// particular, subclasses should not call [Canvas.drawPath] in + /// [paintInterior]). + /// + /// See also: + /// + /// * [paintInterior], whose API documentation has an example implementation. + bool get preferPaintInterior => false; + + /// Paints the border within the given [Rect] on the given [Canvas]. + /// + /// The `textDirection` argument must be provided and non-null if the border + /// has a text direction dependency (for example if it is expressed in terms + /// of "start" and "end" instead of "left" and "right"). It may be null if + /// the border will not need the text direction to paint itself. + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }); + + @override + String toString() { + return '${objectRuntimeType(this, 'ShapeBorder')}()'; + } +} + +/// A ShapeBorder that draws an outline with the width and color specified +/// by [side]. +@immutable +abstract class OutlinedBorder extends ShapeBorder { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const OutlinedBorder({ this.side = BorderSide.none }); + + @override + EdgeInsetsGeometry get dimensions => EdgeInsets.all(math.max(side.strokeInset, 0)); + + /// The border outline's color and weight. + /// + /// If [side] is [BorderSide.none], which is the default, an outline is not drawn. + /// Otherwise the outline is centered over the shape's boundary. + final BorderSide side; + + /// Returns a copy of this OutlinedBorder that draws its outline with the + /// specified [side], if [side] is non-null. + OutlinedBorder copyWith({ BorderSide? side }); + + @override + ShapeBorder scale(double t); + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a == null) { + return scale(t); + } + return null; + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b == null) { + return scale(1.0 - t); + } + return null; + } + + /// Linearly interpolates between two [OutlinedBorder]s. + /// + /// This defers to `b`'s [lerpTo] function if `b` is not null. If `b` is + /// null or if its [lerpTo] returns null, it uses `a`'s [lerpFrom] + /// function instead. If both return null, it returns `a` before `t=0.5` + /// and `b` after `t=0.5`. + /// + /// {@macro dart.ui.shadow.lerp} + static OutlinedBorder? lerp(OutlinedBorder? a, OutlinedBorder? b, double t) { + if (identical(a, b)) { + return a; + } + ShapeBorder? result; + if (b != null) { + result = b.lerpFrom(a, t); + } + if (result == null && a != null) { + result = a.lerpTo(b, t); + } + return result as OutlinedBorder? ?? (t < 0.5 ? a : b); + } +} + +/// Represents the addition of two otherwise-incompatible borders. +/// +/// The borders are listed from the outside to the inside. +class _CompoundBorder extends ShapeBorder { + _CompoundBorder(this.borders) + : assert(borders.length >= 2), + assert(!borders.any((ShapeBorder border) => border is _CompoundBorder)); + + final List<ShapeBorder> borders; + + @override + EdgeInsetsGeometry get dimensions { + return borders.fold<EdgeInsetsGeometry>( + EdgeInsets.zero, + (EdgeInsetsGeometry previousValue, ShapeBorder border) { + return previousValue.add(border.dimensions); + }, + ); + } + + @override + ShapeBorder add(ShapeBorder other, { bool reversed = false }) { + // This wraps the list of borders with "other", or, if "reversed" is true, + // wraps "other" with the list of borders. + // If "reversed" is false, "other" should end up being at the start of the + // list, otherwise, if "reversed" is true, it should end up at the end. + // First, see if we can merge the new adjacent borders. + if (other is! _CompoundBorder) { + // Here, "ours" is the border at the side where we're adding the new + // border, and "merged" is the result of attempting to merge it with the + // new border. If it's null, it couldn't be merged. + final ShapeBorder ours = reversed ? borders.last : borders.first; + final ShapeBorder? merged = ours.add(other, reversed: reversed) + ?? other.add(ours, reversed: !reversed); + if (merged != null) { + final List<ShapeBorder> result = <ShapeBorder>[...borders]; + result[reversed ? result.length - 1 : 0] = merged; + return _CompoundBorder(result); + } + } + // We can't, so fall back to just adding the new border to the list. + final List<ShapeBorder> mergedBorders = <ShapeBorder>[ + if (reversed) ...borders, + if (other is _CompoundBorder) ...other.borders + else other, + if (!reversed) ...borders, + ]; + return _CompoundBorder(mergedBorders); + } + + @override + ShapeBorder scale(double t) { + return _CompoundBorder( + borders.map<ShapeBorder>((ShapeBorder border) => border.scale(t)).toList(), + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + return _CompoundBorder.lerp(a, this, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + return _CompoundBorder.lerp(this, b, t); + } + + static _CompoundBorder lerp(ShapeBorder? a, ShapeBorder? b, double t) { + assert(a is _CompoundBorder || b is _CompoundBorder); // Not really necessary, but all call sites currently intend this. + final List<ShapeBorder?> aList = a is _CompoundBorder ? a.borders : <ShapeBorder?>[a]; + final List<ShapeBorder?> bList = b is _CompoundBorder ? b.borders : <ShapeBorder?>[b]; + final List<ShapeBorder> results = <ShapeBorder>[]; + final int length = math.max(aList.length, bList.length); + for (int index = 0; index < length; index += 1) { + final ShapeBorder? localA = index < aList.length ? aList[index] : null; + final ShapeBorder? localB = index < bList.length ? bList[index] : null; + if (localA != null && localB != null) { + final ShapeBorder? localResult = localA.lerpTo(localB, t) ?? localB.lerpFrom(localA, t); + if (localResult != null) { + results.add(localResult); + continue; + } + } + // If we're changing from one shape to another, make sure the shape that is coming in + // is inserted before the shape that is going away, so that the outer path changes to + // the new border earlier rather than later. (This affects, among other things, where + // the ShapeDecoration class puts its background.) + if (localB != null) { + results.add(localB.scale(t)); + } + if (localA != null) { + results.add(localA.scale(1.0 - t)); + } + } + return _CompoundBorder(results); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + for (int index = 0; index < borders.length - 1; index += 1) { + rect = borders[index].dimensions.resolve(textDirection).deflateRect(rect); + } + return borders.last.getInnerPath(rect, textDirection: textDirection); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return borders.first.getOuterPath(rect, textDirection: textDirection); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + borders.first.paintInterior(canvas, rect, paint, textDirection: textDirection); + } + + @override + bool get preferPaintInterior => borders.every((ShapeBorder border) => border.preferPaintInterior); + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + for (final ShapeBorder border in borders) { + border.paint(canvas, rect, textDirection: textDirection); + rect = border.dimensions.resolve(textDirection).deflateRect(rect); + } + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is _CompoundBorder + && listEquals<ShapeBorder>(other.borders, borders); + } + + @override + int get hashCode => Object.hashAll(borders); + + @override + String toString() { + // We list them in reverse order because when adding two borders they end up + // in the list in the opposite order of what the source looks like: a + b => + // [b, a]. We do this to make the painting code more optimal, and most of + // the rest of the code doesn't care, except toString() (for debugging). + return borders.reversed.map<String>((ShapeBorder border) => border.toString()).join(' + '); + } +} + +/// Paints a border around the given rectangle on the canvas. +/// +/// The four sides can be independently specified. They are painted in the order +/// top, right, bottom, left. This is only notable if the widths of the borders +/// and the size of the given rectangle are such that the border sides will +/// overlap each other. No effort is made to optimize the rendering of uniform +/// borders (where all the borders have the same configuration); to render a +/// uniform border, consider using [Canvas.drawRect] directly. +/// +/// See also: +/// +/// * [paintImage], which paints an image in a rectangle on a canvas. +/// * [Border], which uses this function to paint its border when the border is +/// not uniform. +/// * [BoxDecoration], which describes its border using the [Border] class. +void paintBorder( + Canvas canvas, + Rect rect, { + BorderSide top = BorderSide.none, + BorderSide right = BorderSide.none, + BorderSide bottom = BorderSide.none, + BorderSide left = BorderSide.none, +}) { + + // We draw the borders as filled shapes, unless the borders are hairline + // borders, in which case we use PaintingStyle.stroke, with the stroke width + // specified here. + final Paint paint = Paint() + ..strokeWidth = 0.0; + + final Path path = Path(); + + switch (top.style) { + case BorderStyle.solid: + paint.color = top.color; + path.reset(); + path.moveTo(rect.left, rect.top); + path.lineTo(rect.right, rect.top); + if (top.width == 0.0) { + paint.style = PaintingStyle.stroke; + } else { + paint.style = PaintingStyle.fill; + path.lineTo(rect.right - right.width, rect.top + top.width); + path.lineTo(rect.left + left.width, rect.top + top.width); + } + canvas.drawPath(path, paint); + case BorderStyle.none: + break; + } + + switch (right.style) { + case BorderStyle.solid: + paint.color = right.color; + path.reset(); + path.moveTo(rect.right, rect.top); + path.lineTo(rect.right, rect.bottom); + if (right.width == 0.0) { + paint.style = PaintingStyle.stroke; + } else { + paint.style = PaintingStyle.fill; + path.lineTo(rect.right - right.width, rect.bottom - bottom.width); + path.lineTo(rect.right - right.width, rect.top + top.width); + } + canvas.drawPath(path, paint); + case BorderStyle.none: + break; + } + + switch (bottom.style) { + case BorderStyle.solid: + paint.color = bottom.color; + path.reset(); + path.moveTo(rect.right, rect.bottom); + path.lineTo(rect.left, rect.bottom); + if (bottom.width == 0.0) { + paint.style = PaintingStyle.stroke; + } else { + paint.style = PaintingStyle.fill; + path.lineTo(rect.left + left.width, rect.bottom - bottom.width); + path.lineTo(rect.right - right.width, rect.bottom - bottom.width); + } + canvas.drawPath(path, paint); + case BorderStyle.none: + break; + } + + switch (left.style) { + case BorderStyle.solid: + paint.color = left.color; + path.reset(); + path.moveTo(rect.left, rect.bottom); + path.lineTo(rect.left, rect.top); + if (left.width == 0.0) { + paint.style = PaintingStyle.stroke; + } else { + paint.style = PaintingStyle.fill; + path.lineTo(rect.left + left.width, rect.top + top.width); + path.lineTo(rect.left + left.width, rect.bottom - bottom.width); + } + canvas.drawPath(path, paint); + case BorderStyle.none: + break; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..c19441abb60043573efab598d44522730eabdb54 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_border.dart @@ -0,0 +1,1084 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'border_radius.dart'; +import 'borders.dart'; +import 'edge_insets.dart'; + +// Examples can assume: +// late BuildContext context; + +/// The shape to use when rendering a [Border] or [BoxDecoration]. +/// +/// Consider using [ShapeBorder] subclasses directly (with [ShapeDecoration]), +/// instead of using [BoxShape] and [Border], if the shapes will need to be +/// interpolated or animated. The [Border] class cannot interpolate between +/// different shapes. +enum BoxShape { + /// An axis-aligned, 2D rectangle. May have rounded corners (described by a + /// [BorderRadius]). The edges of the rectangle will match the edges of the box + /// into which the [Border] or [BoxDecoration] is painted. + /// + /// See also: + /// + /// * [RoundedRectangleBorder], the equivalent [ShapeBorder]. + rectangle, + + /// A circle centered in the middle of the box into which the [Border] or + /// [BoxDecoration] is painted. The diameter of the circle is the shortest + /// dimension of the box, either the width or the height, such that the circle + /// touches the edges of the box. + /// + /// See also: + /// + /// * [CircleBorder], the equivalent [ShapeBorder]. + circle, + + // Don't add more, instead create a new ShapeBorder. +} + +/// Base class for box borders that can paint as rectangles, circles, or rounded +/// rectangles. +/// +/// This class is extended by [Border] and [BorderDirectional] to provide +/// concrete versions of four-sided borders using different conventions for +/// specifying the sides. +/// +/// The only API difference that this class introduces over [ShapeBorder] is +/// that its [paint] method takes additional arguments. +/// +/// See also: +/// +/// * [BorderSide], which is used to describe each side of the box. +/// * [RoundedRectangleBorder], another way of describing a box's border. +/// * [CircleBorder], another way of describing a circle border. +/// * [BoxDecoration], which uses a [BoxBorder] to describe its borders. +abstract class BoxBorder extends ShapeBorder { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const BoxBorder(); + + /// The top side of this border. + /// + /// This getter is available on both [Border] and [BorderDirectional]. If + /// [isUniform] is true, then this is the same style as all the other sides. + BorderSide get top; + + /// The bottom side of this border. + BorderSide get bottom; + + /// Whether all four sides of the border are identical. Uniform borders are + /// typically more efficient to paint. + /// + /// A uniform border by definition has no text direction dependency and + /// therefore could be expressed as a [Border], even if it is currently a + /// [BorderDirectional]. A uniform border can also be expressed as a + /// [RoundedRectangleBorder]. + bool get isUniform; + + // We override this to tighten the return value, so that callers can assume + // that we'll return a [BoxBorder]. + @override + BoxBorder? add(ShapeBorder other, { bool reversed = false }) => null; + + /// Linearly interpolate between two borders. + /// + /// If a border is null, it is treated as having four [BorderSide.none] + /// borders. + /// + /// This supports interpolating between [Border] and [BorderDirectional] + /// objects. If both objects are different types but both have sides on one or + /// both of their lateral edges (the two sides that aren't the top and bottom) + /// other than [BorderSide.none], then the sides are interpolated by reducing + /// `a`'s lateral edges to [BorderSide.none] over the first half of the + /// animation, and then bringing `b`'s lateral edges _from_ [BorderSide.none] + /// over the second half of the animation. + /// + /// For a more flexible approach, consider [ShapeBorder.lerp], which would + /// instead [add] the two sets of sides and interpolate them simultaneously. + /// + /// {@macro dart.ui.shadow.lerp} + static BoxBorder? lerp(BoxBorder? a, BoxBorder? b, double t) { + if (identical(a, b)) { + return a; + } + if ((a is Border?) && (b is Border?)) { + return Border.lerp(a, b, t); + } + if ((a is BorderDirectional?) && (b is BorderDirectional?)) { + return BorderDirectional.lerp(a, b, t); + } + if (b is Border && a is BorderDirectional) { + final BoxBorder c = b; + b = a; + a = c; + t = 1.0 - t; + // fall through to next case + } + if (a is Border && b is BorderDirectional) { + if (b.start == BorderSide.none && b.end == BorderSide.none) { + // The fact that b is a BorderDirectional really doesn't matter, it turns out. + return Border( + top: BorderSide.lerp(a.top, b.top, t), + right: BorderSide.lerp(a.right, BorderSide.none, t), + bottom: BorderSide.lerp(a.bottom, b.bottom, t), + left: BorderSide.lerp(a.left, BorderSide.none, t), + ); + } + if (a.left == BorderSide.none && a.right == BorderSide.none) { + // The fact that a is a Border really doesn't matter, it turns out. + return BorderDirectional( + top: BorderSide.lerp(a.top, b.top, t), + start: BorderSide.lerp(BorderSide.none, b.start, t), + end: BorderSide.lerp(BorderSide.none, b.end, t), + bottom: BorderSide.lerp(a.bottom, b.bottom, t), + ); + } + // Since we have to swap a visual border for a directional one, + // we speed up the horizontal sides' transitions and switch from + // one mode to the other at t=0.5. + if (t < 0.5) { + return Border( + top: BorderSide.lerp(a.top, b.top, t), + right: BorderSide.lerp(a.right, BorderSide.none, t * 2.0), + bottom: BorderSide.lerp(a.bottom, b.bottom, t), + left: BorderSide.lerp(a.left, BorderSide.none, t * 2.0), + ); + } + return BorderDirectional( + top: BorderSide.lerp(a.top, b.top, t), + start: BorderSide.lerp(BorderSide.none, b.start, (t - 0.5) * 2.0), + end: BorderSide.lerp(BorderSide.none, b.end, (t - 0.5) * 2.0), + bottom: BorderSide.lerp(a.bottom, b.bottom, t), + ); + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('BoxBorder.lerp can only interpolate Border and BorderDirectional classes.'), + ErrorDescription( + 'BoxBorder.lerp() was called with two objects of type ${a.runtimeType} and ${b.runtimeType}:\n' + ' $a\n' + ' $b\n' + 'However, only Border and BorderDirectional classes are supported by this method.', + ), + ErrorHint('For a more general interpolation method, consider using ShapeBorder.lerp instead.'), + ]); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + assert(textDirection != null, 'The textDirection argument to $runtimeType.getInnerPath must not be null.'); + return Path() + ..addRect(dimensions.resolve(textDirection).deflateRect(rect)); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + assert(textDirection != null, 'The textDirection argument to $runtimeType.getOuterPath must not be null.'); + return Path() + ..addRect(rect); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + // For `ShapeDecoration(shape: Border.all())`, a rectangle with sharp edges + // is always painted. There is no borderRadius parameter for + // ShapeDecoration or Border, only for BoxDecoration, which doesn't call + // this method. + canvas.drawRect(rect, paint); + } + + @override + bool get preferPaintInterior => true; + + /// Paints the border within the given [Rect] on the given [Canvas]. + /// + /// This is an extension of the [ShapeBorder.paint] method. It allows + /// [BoxBorder] borders to be applied to different [BoxShape]s and with + /// different [borderRadius] parameters, without changing the [BoxBorder] + /// object itself. + /// + /// The `shape` argument specifies the [BoxShape] to draw the border on. + /// + /// If the `shape` is specifies a rectangular box shape + /// ([BoxShape.rectangle]), then the `borderRadius` argument describes the + /// corners of the rectangle. + /// + /// The [getInnerPath] and [getOuterPath] methods do not know about the + /// `shape` and `borderRadius` arguments. + /// + /// See also: + /// + /// * [paintBorder], which is used if the border has non-uniform colors or styles and no borderRadius. + /// * [Border.paint], similar to this method, includes additional comments + /// and provides more details on each parameter than described here. + @override + void paint( + Canvas canvas, + Rect rect, { + TextDirection? textDirection, + BoxShape shape = BoxShape.rectangle, + BorderRadius? borderRadius, + }); + + static void _paintUniformBorderWithRadius(Canvas canvas, Rect rect, BorderSide side, BorderRadius borderRadius) { + assert(side.style != BorderStyle.none); + final Paint paint = Paint() + ..color = side.color; + final double width = side.width; + if (width == 0.0) { + paint + ..style = PaintingStyle.stroke + ..strokeWidth = 0.0; + canvas.drawRRect(borderRadius.toRRect(rect), paint); + } else { + final RRect borderRect = borderRadius.toRRect(rect); + final RRect inner = borderRect.deflate(side.strokeInset); + final RRect outer = borderRect.inflate(side.strokeOutset); + canvas.drawDRRect(outer, inner, paint); + } + } + + /// Paints a Border with different widths, styles and strokeAligns, on any + /// borderRadius while using a single color. + /// + /// See also: + /// + /// * [paintBorder], which supports multiple colors but not borderRadius. + /// * [paint], which calls this method. + static void paintNonUniformBorder( + Canvas canvas, + Rect rect, { + required BorderRadius? borderRadius, + required TextDirection? textDirection, + BoxShape shape = BoxShape.rectangle, + BorderSide top = BorderSide.none, + BorderSide right = BorderSide.none, + BorderSide bottom = BorderSide.none, + BorderSide left = BorderSide.none, + required Color color, + }) { + final RRect borderRect; + switch (shape) { + case BoxShape.rectangle: + borderRect = (borderRadius ?? BorderRadius.zero) + .resolve(textDirection) + .toRRect(rect); + case BoxShape.circle: + assert(borderRadius == null, 'A borderRadius cannot be given when shape is a BoxShape.circle.'); + borderRect = RRect.fromRectAndRadius( + Rect.fromCircle(center: rect.center, radius: rect.shortestSide / 2.0), + Radius.circular(rect.width), + ); + } + final Paint paint = Paint()..color = color; + final RRect inner = _deflateRRect(borderRect, EdgeInsets.fromLTRB(left.strokeInset, top.strokeInset, right.strokeInset, bottom.strokeInset)); + final RRect outer = _inflateRRect(borderRect, EdgeInsets.fromLTRB(left.strokeOutset, top.strokeOutset, right.strokeOutset, bottom.strokeOutset)); + canvas.drawDRRect(outer, inner, paint); + } + + static RRect _inflateRRect(RRect rect, EdgeInsets insets) { + return RRect.fromLTRBAndCorners( + rect.left - insets.left, + rect.top - insets.top, + rect.right + insets.right, + rect.bottom + insets.bottom, + topLeft: (rect.tlRadius + Radius.elliptical(insets.left, insets.top)).clamp(minimum: Radius.zero), + topRight: (rect.trRadius + Radius.elliptical(insets.right, insets.top)).clamp(minimum: Radius.zero), + bottomRight: (rect.brRadius + Radius.elliptical(insets.right, insets.bottom)).clamp(minimum: Radius.zero), + bottomLeft: (rect.blRadius + Radius.elliptical(insets.left, insets.bottom)).clamp(minimum: Radius.zero), + ); + } + + static RRect _deflateRRect(RRect rect, EdgeInsets insets) { + return RRect.fromLTRBAndCorners( + rect.left + insets.left, + rect.top + insets.top, + rect.right - insets.right, + rect.bottom - insets.bottom, + topLeft: (rect.tlRadius - Radius.elliptical(insets.left, insets.top)).clamp(minimum: Radius.zero), + topRight: (rect.trRadius - Radius.elliptical(insets.right, insets.top)).clamp(minimum: Radius.zero), + bottomRight: (rect.brRadius - Radius.elliptical(insets.right, insets.bottom)).clamp(minimum: Radius.zero), + bottomLeft:(rect.blRadius - Radius.elliptical(insets.left, insets.bottom)).clamp(minimum: Radius.zero), + ); + } + + static void _paintUniformBorderWithCircle(Canvas canvas, Rect rect, BorderSide side) { + assert(side.style != BorderStyle.none); + final double radius = (rect.shortestSide + side.strokeOffset) / 2; + canvas.drawCircle(rect.center, radius, side.toPaint()); + } + + static void _paintUniformBorderWithRectangle(Canvas canvas, Rect rect, BorderSide side) { + assert(side.style != BorderStyle.none); + canvas.drawRect(rect.inflate(side.strokeOffset / 2), side.toPaint()); + } +} + +/// A border of a box, comprised of four sides: top, right, bottom, left. +/// +/// The sides are represented by [BorderSide] objects. +/// +/// {@tool snippet} +/// +/// All four borders the same, two-pixel wide solid white: +/// +/// ```dart +/// Border.all(width: 2.0, color: const Color(0xFFFFFFFF)) +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// The border for a Material Design divider: +/// +/// ```dart +/// Border(bottom: BorderSide(color: Theme.of(context).dividerColor)) +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// A 1990s-era "OK" button: +/// +/// ```dart +/// Container( +/// decoration: const BoxDecoration( +/// border: Border( +/// top: BorderSide(color: Color(0xFFFFFFFF)), +/// left: BorderSide(color: Color(0xFFFFFFFF)), +/// right: BorderSide(), +/// bottom: BorderSide(), +/// ), +/// ), +/// child: Container( +/// padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 2.0), +/// decoration: const BoxDecoration( +/// border: Border( +/// top: BorderSide(color: Color(0xFFDFDFDF)), +/// left: BorderSide(color: Color(0xFFDFDFDF)), +/// right: BorderSide(color: Color(0xFF7F7F7F)), +/// bottom: BorderSide(color: Color(0xFF7F7F7F)), +/// ), +/// color: Color(0xFFBFBFBF), +/// ), +/// child: const Text( +/// 'OK', +/// textAlign: TextAlign.center, +/// style: TextStyle(color: Color(0xFF000000)) +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [BoxDecoration], which uses this class to describe its edge decoration. +/// * [BorderSide], which is used to describe each side of the box. +/// * [Theme], from the material layer, which can be queried to obtain appropriate colors +/// to use for borders in a [MaterialApp], as shown in the "divider" sample above. +/// * [paint], which explains the behavior of [BoxDecoration] parameters. +/// * <https://pub.dev/packages/non_uniform_border>, a package that implements +/// a Non-Uniform Border on ShapeBorder, which is used by Material Design +/// buttons and other widgets, under the "shape" field. +class Border extends BoxBorder { + /// Creates a border. + /// + /// All the sides of the border default to [BorderSide.none]. + const Border({ + this.top = BorderSide.none, + this.right = BorderSide.none, + this.bottom = BorderSide.none, + this.left = BorderSide.none, + }); + + /// Creates a border whose sides are all the same. + const Border.fromBorderSide(BorderSide side) + : top = side, + right = side, + bottom = side, + left = side; + + /// Creates a border with symmetrical vertical and horizontal sides. + /// + /// The `vertical` argument applies to the [left] and [right] sides, and the + /// `horizontal` argument applies to the [top] and [bottom] sides. + /// + /// All arguments default to [BorderSide.none]. + const Border.symmetric({ + BorderSide vertical = BorderSide.none, + BorderSide horizontal = BorderSide.none, + }) : left = vertical, + top = horizontal, + right = vertical, + bottom = horizontal; + + /// A uniform border with all sides the same color and width. + /// + /// The sides default to black solid borders, one logical pixel wide. + factory Border.all({ + Color color = const Color(0xFF000000), + double width = 1.0, + BorderStyle style = BorderStyle.solid, + double strokeAlign = BorderSide.strokeAlignInside, + }) { + final BorderSide side = BorderSide(color: color, width: width, style: style, strokeAlign: strokeAlign); + return Border.fromBorderSide(side); + } + + /// Creates a [Border] that represents the addition of the two given + /// [Border]s. + /// + /// It is only valid to call this if [BorderSide.canMerge] returns true for + /// the pairwise combination of each side on both [Border]s. + static Border merge(Border a, Border b) { + assert(BorderSide.canMerge(a.top, b.top)); + assert(BorderSide.canMerge(a.right, b.right)); + assert(BorderSide.canMerge(a.bottom, b.bottom)); + assert(BorderSide.canMerge(a.left, b.left)); + return Border( + top: BorderSide.merge(a.top, b.top), + right: BorderSide.merge(a.right, b.right), + bottom: BorderSide.merge(a.bottom, b.bottom), + left: BorderSide.merge(a.left, b.left), + ); + } + + @override + final BorderSide top; + + /// The right side of this border. + final BorderSide right; + + @override + final BorderSide bottom; + + /// The left side of this border. + final BorderSide left; + + @override + EdgeInsetsGeometry get dimensions { + if (_widthIsUniform) { + return EdgeInsets.all(top.strokeInset); + } + return EdgeInsets.fromLTRB(left.strokeInset, top.strokeInset, right.strokeInset, bottom.strokeInset); + } + + @override + bool get isUniform => _colorIsUniform && _widthIsUniform && _styleIsUniform && _strokeAlignIsUniform; + + bool get _colorIsUniform { + final Color topColor = top.color; + return left.color == topColor && bottom.color == topColor && right.color == topColor; + } + + bool get _widthIsUniform { + final double topWidth = top.width; + return left.width == topWidth && bottom.width == topWidth && right.width == topWidth; + } + + bool get _styleIsUniform { + final BorderStyle topStyle = top.style; + return left.style == topStyle && bottom.style == topStyle && right.style == topStyle; + } + + bool get _strokeAlignIsUniform { + final double topStrokeAlign = top.strokeAlign; + return left.strokeAlign == topStrokeAlign + && bottom.strokeAlign == topStrokeAlign + && right.strokeAlign == topStrokeAlign; + } + + Set<Color> _distinctVisibleColors() { + final Set<Color> distinctVisibleColors = <Color>{}; + if (top.style != BorderStyle.none) { + distinctVisibleColors.add(top.color); + } + if (right.style != BorderStyle.none) { + distinctVisibleColors.add(right.color); + } + if (bottom.style != BorderStyle.none) { + distinctVisibleColors.add(bottom.color); + } + if (left.style != BorderStyle.none) { + distinctVisibleColors.add(left.color); + } + return distinctVisibleColors; + } + + // [BoxBorder.paintNonUniformBorder] is about 20% faster than [paintBorder], + // but [paintBorder] is able to draw hairline borders when width is zero + // and style is [BorderStyle.solid]. + bool get _hasHairlineBorder => + (top.style == BorderStyle.solid && top.width == 0.0) || + (right.style == BorderStyle.solid && right.width == 0.0) || + (bottom.style == BorderStyle.solid && bottom.width == 0.0) || + (left.style == BorderStyle.solid && left.width == 0.0); + + @override + Border? add(ShapeBorder other, { bool reversed = false }) { + if (other is Border && + BorderSide.canMerge(top, other.top) && + BorderSide.canMerge(right, other.right) && + BorderSide.canMerge(bottom, other.bottom) && + BorderSide.canMerge(left, other.left)) { + return Border.merge(this, other); + } + return null; + } + + @override + Border scale(double t) { + return Border( + top: top.scale(t), + right: right.scale(t), + bottom: bottom.scale(t), + left: left.scale(t), + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is Border) { + return Border.lerp(a, this, t); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is Border) { + return Border.lerp(this, b, t); + } + return super.lerpTo(b, t); + } + + /// Linearly interpolate between two borders. + /// + /// If a border is null, it is treated as having four [BorderSide.none] + /// borders. + /// + /// {@macro dart.ui.shadow.lerp} + static Border? lerp(Border? a, Border? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!.scale(t); + } + if (b == null) { + return a.scale(1.0 - t); + } + return Border( + top: BorderSide.lerp(a.top, b.top, t), + right: BorderSide.lerp(a.right, b.right, t), + bottom: BorderSide.lerp(a.bottom, b.bottom, t), + left: BorderSide.lerp(a.left, b.left, t), + ); + } + + /// Paints the border within the given [Rect] on the given [Canvas]. + /// + /// Uniform borders and non-uniform borders with similar colors and styles + /// are more efficient to paint than more complex borders. + /// + /// You can provide a [BoxShape] to draw the border on. If the `shape` in + /// [BoxShape.circle], there is the requirement that the border has uniform + /// color and style. + /// + /// If you specify a rectangular box shape ([BoxShape.rectangle]), then you + /// may specify a [BorderRadius]. If a `borderRadius` is specified, there is + /// the requirement that the border has uniform color and style. + /// + /// The [getInnerPath] and [getOuterPath] methods do not know about the + /// `shape` and `borderRadius` arguments. + /// + /// The `textDirection` argument is not used by this paint method. + /// + /// See also: + /// + /// * [paintBorder], which is used if the border has non-uniform colors or styles and no borderRadius. + /// * <https://pub.dev/packages/non_uniform_border>, a package that implements + /// a Non-Uniform Border on ShapeBorder, which is used by Material Design + /// buttons and other widgets, under the "shape" field. + @override + void paint( + Canvas canvas, + Rect rect, { + TextDirection? textDirection, + BoxShape shape = BoxShape.rectangle, + BorderRadius? borderRadius, + }) { + if (isUniform) { + switch (top.style) { + case BorderStyle.none: + return; + case BorderStyle.solid: + switch (shape) { + case BoxShape.circle: + assert(borderRadius == null, 'A borderRadius cannot be given when shape is a BoxShape.circle.'); + BoxBorder._paintUniformBorderWithCircle(canvas, rect, top); + case BoxShape.rectangle: + if (borderRadius != null && borderRadius != BorderRadius.zero) { + BoxBorder._paintUniformBorderWithRadius(canvas, rect, top, borderRadius); + return; + } + BoxBorder._paintUniformBorderWithRectangle(canvas, rect, top); + } + return; + } + } + + if (_styleIsUniform && top.style == BorderStyle.none) { + return; + } + + // Allow painting non-uniform borders if the visible colors are uniform. + final Set<Color> visibleColors = _distinctVisibleColors(); + final bool hasHairlineBorder = _hasHairlineBorder; + // Paint a non uniform border if a single color is visible + // and (borderRadius is present) or (border is visible and width != 0.0). + if (visibleColors.length == 1 && + !hasHairlineBorder && + (shape == BoxShape.circle || + (borderRadius != null && borderRadius != BorderRadius.zero))) { + BoxBorder.paintNonUniformBorder(canvas, rect, + shape: shape, + borderRadius: borderRadius, + textDirection: textDirection, + top: top.style == BorderStyle.none ? BorderSide.none : top, + right: right.style == BorderStyle.none ? BorderSide.none : right, + bottom: bottom.style == BorderStyle.none ? BorderSide.none : bottom, + left: left.style == BorderStyle.none ? BorderSide.none : left, + color: visibleColors.first); + return; + } + + assert(() { + if (hasHairlineBorder) { + assert(borderRadius == null || borderRadius == BorderRadius.zero, + 'A hairline border like `BorderSide(width: 0.0, style: BorderStyle.solid)` can only be drawn when BorderRadius is zero or null.'); + } + if (borderRadius != null && borderRadius != BorderRadius.zero) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('A borderRadius can only be given on borders with uniform colors.'), + ErrorDescription('The following is not uniform:'), + if (!_colorIsUniform) ErrorDescription('BorderSide.color'), + ]); + } + return true; + }()); + assert(() { + if (shape != BoxShape.rectangle) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('A Border can only be drawn as a circle on borders with uniform colors.'), + ErrorDescription('The following is not uniform:'), + if (!_colorIsUniform) ErrorDescription('BorderSide.color'), + ]); + } + return true; + }()); + assert(() { + if (!_strokeAlignIsUniform || top.strokeAlign != BorderSide.strokeAlignInside) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('A Border can only draw strokeAlign different than BorderSide.strokeAlignInside on borders with uniform colors.'), + ]); + } + return true; + }()); + + paintBorder(canvas, rect, top: top, right: right, bottom: bottom, left: left); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is Border + && other.top == top + && other.right == right + && other.bottom == bottom + && other.left == left; + } + + @override + int get hashCode => Object.hash(top, right, bottom, left); + + @override + String toString() { + if (isUniform) { + return '${objectRuntimeType(this, 'Border')}.all($top)'; + } + final List<String> arguments = <String>[ + if (top != BorderSide.none) 'top: $top', + if (right != BorderSide.none) 'right: $right', + if (bottom != BorderSide.none) 'bottom: $bottom', + if (left != BorderSide.none) 'left: $left', + ]; + return '${objectRuntimeType(this, 'Border')}(${arguments.join(", ")})'; + } +} + +/// A border of a box, comprised of four sides, the lateral sides of which +/// flip over based on the reading direction. +/// +/// The lateral sides are called [start] and [end]. When painted in +/// left-to-right environments, the [start] side will be painted on the left and +/// the [end] side on the right; in right-to-left environments, it is the +/// reverse. The other two sides are [top] and [bottom]. +/// +/// The sides are represented by [BorderSide] objects. +/// +/// If the [start] and [end] sides are the same, then it is slightly more +/// efficient to use a [Border] object rather than a [BorderDirectional] object. +/// +/// See also: +/// +/// * [BoxDecoration], which uses this class to describe its edge decoration. +/// * [BorderSide], which is used to describe each side of the box. +/// * [Theme], from the material layer, which can be queried to obtain appropriate colors +/// to use for borders in a [MaterialApp], as shown in the "divider" sample above. +/// * <https://pub.dev/packages/non_uniform_border>, a package that implements +/// a Non-Uniform Border on ShapeBorder, which is used by Material Design +/// buttons and other widgets, under the "shape" field. +class BorderDirectional extends BoxBorder { + /// Creates a border. + /// + /// The [start] and [end] sides represent the horizontal sides; the start side + /// is on the leading edge given the reading direction, and the end side is on + /// the trailing edge. They are resolved during [paint]. + /// + /// All the sides of the border default to [BorderSide.none]. + const BorderDirectional({ + this.top = BorderSide.none, + this.start = BorderSide.none, + this.end = BorderSide.none, + this.bottom = BorderSide.none, + }); + + /// Creates a [BorderDirectional] that represents the addition of the two + /// given [BorderDirectional]s. + /// + /// It is only valid to call this if [BorderSide.canMerge] returns true for + /// the pairwise combination of each side on both [BorderDirectional]s. + static BorderDirectional merge(BorderDirectional a, BorderDirectional b) { + assert(BorderSide.canMerge(a.top, b.top)); + assert(BorderSide.canMerge(a.start, b.start)); + assert(BorderSide.canMerge(a.end, b.end)); + assert(BorderSide.canMerge(a.bottom, b.bottom)); + return BorderDirectional( + top: BorderSide.merge(a.top, b.top), + start: BorderSide.merge(a.start, b.start), + end: BorderSide.merge(a.end, b.end), + bottom: BorderSide.merge(a.bottom, b.bottom), + ); + } + + @override + final BorderSide top; + + /// The start side of this border. + /// + /// This is the side on the left in left-to-right text and on the right in + /// right-to-left text. + /// + /// See also: + /// + /// * [TextDirection], which is used to describe the reading direction. + final BorderSide start; + + /// The end side of this border. + /// + /// This is the side on the right in left-to-right text and on the left in + /// right-to-left text. + /// + /// See also: + /// + /// * [TextDirection], which is used to describe the reading direction. + final BorderSide end; + + @override + final BorderSide bottom; + + @override + EdgeInsetsGeometry get dimensions { + if (isUniform) { + return EdgeInsetsDirectional.all(top.strokeInset); + } + return EdgeInsetsDirectional.fromSTEB(start.strokeInset, top.strokeInset, end.strokeInset, bottom.strokeInset); + } + + @override + bool get isUniform => _colorIsUniform && _widthIsUniform && _styleIsUniform && _strokeAlignIsUniform; + + bool get _colorIsUniform { + final Color topColor = top.color; + return start.color == topColor && bottom.color == topColor && end.color == topColor; + } + + bool get _widthIsUniform { + final double topWidth = top.width; + return start.width == topWidth && bottom.width == topWidth && end.width == topWidth; + } + + bool get _styleIsUniform { + final BorderStyle topStyle = top.style; + return start.style == topStyle && bottom.style == topStyle && end.style == topStyle; + } + + bool get _strokeAlignIsUniform { + final double topStrokeAlign = top.strokeAlign; + return start.strokeAlign == topStrokeAlign + && bottom.strokeAlign == topStrokeAlign + && end.strokeAlign == topStrokeAlign; + } + + Set<Color> _distinctVisibleColors() { + final Set<Color> distinctVisibleColors = <Color>{}; + if (top.style != BorderStyle.none) { + distinctVisibleColors.add(top.color); + } + if (end.style != BorderStyle.none) { + distinctVisibleColors.add(end.color); + } + if (bottom.style != BorderStyle.none) { + distinctVisibleColors.add(bottom.color); + } + if (start.style != BorderStyle.none) { + distinctVisibleColors.add(start.color); + } + + return distinctVisibleColors; + } + + + bool get _hasHairlineBorder => + (top.style == BorderStyle.solid && top.width == 0.0) || + (end.style == BorderStyle.solid && end.width == 0.0) || + (bottom.style == BorderStyle.solid && bottom.width == 0.0) || + (start.style == BorderStyle.solid && start.width == 0.0); + + @override + BoxBorder? add(ShapeBorder other, { bool reversed = false }) { + if (other is BorderDirectional) { + final BorderDirectional typedOther = other; + if (BorderSide.canMerge(top, typedOther.top) && + BorderSide.canMerge(start, typedOther.start) && + BorderSide.canMerge(end, typedOther.end) && + BorderSide.canMerge(bottom, typedOther.bottom)) { + return BorderDirectional.merge(this, typedOther); + } + return null; + } + if (other is Border) { + final Border typedOther = other; + if (!BorderSide.canMerge(typedOther.top, top) || + !BorderSide.canMerge(typedOther.bottom, bottom)) { + return null; + } + if (start != BorderSide.none || + end != BorderSide.none) { + if (typedOther.left != BorderSide.none || + typedOther.right != BorderSide.none) { + return null; + } + assert(typedOther.left == BorderSide.none); + assert(typedOther.right == BorderSide.none); + return BorderDirectional( + top: BorderSide.merge(typedOther.top, top), + start: start, + end: end, + bottom: BorderSide.merge(typedOther.bottom, bottom), + ); + } + assert(start == BorderSide.none); + assert(end == BorderSide.none); + return Border( + top: BorderSide.merge(typedOther.top, top), + right: typedOther.right, + bottom: BorderSide.merge(typedOther.bottom, bottom), + left: typedOther.left, + ); + } + return null; + } + + @override + BorderDirectional scale(double t) { + return BorderDirectional( + top: top.scale(t), + start: start.scale(t), + end: end.scale(t), + bottom: bottom.scale(t), + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is BorderDirectional) { + return BorderDirectional.lerp(a, this, t); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is BorderDirectional) { + return BorderDirectional.lerp(this, b, t); + } + return super.lerpTo(b, t); + } + + /// Linearly interpolate between two borders. + /// + /// If a border is null, it is treated as having four [BorderSide.none] + /// borders. + /// + /// {@macro dart.ui.shadow.lerp} + static BorderDirectional? lerp(BorderDirectional? a, BorderDirectional? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!.scale(t); + } + if (b == null) { + return a.scale(1.0 - t); + } + return BorderDirectional( + top: BorderSide.lerp(a.top, b.top, t), + end: BorderSide.lerp(a.end, b.end, t), + bottom: BorderSide.lerp(a.bottom, b.bottom, t), + start: BorderSide.lerp(a.start, b.start, t), + ); + } + + /// Paints the border within the given [Rect] on the given [Canvas]. + /// + /// Uniform borders are more efficient to paint than more complex borders. + /// + /// You can provide a [BoxShape] to draw the border on. If the `shape` in + /// [BoxShape.circle], there is the requirement that the border [isUniform]. + /// + /// If you specify a rectangular box shape ([BoxShape.rectangle]), then you + /// may specify a [BorderRadius]. If a `borderRadius` is specified, there is + /// the requirement that the border [isUniform]. + /// + /// The [getInnerPath] and [getOuterPath] methods do not know about the + /// `shape` and `borderRadius` arguments. + /// + /// The `textDirection` argument is used to determine which of [start] and + /// [end] map to the left and right. For [TextDirection.ltr], the [start] is + /// the left and the [end] is the right; for [TextDirection.rtl], it is the + /// reverse. + /// + /// See also: + /// + /// * [paintBorder], which is used if the border has non-uniform colors or styles and no borderRadius. + @override + void paint( + Canvas canvas, + Rect rect, { + TextDirection? textDirection, + BoxShape shape = BoxShape.rectangle, + BorderRadius? borderRadius, + }) { + if (isUniform) { + switch (top.style) { + case BorderStyle.none: + return; + case BorderStyle.solid: + switch (shape) { + case BoxShape.circle: + assert(borderRadius == null, 'A borderRadius cannot be given when shape is a BoxShape.circle.'); + BoxBorder._paintUniformBorderWithCircle(canvas, rect, top); + case BoxShape.rectangle: + if (borderRadius != null && borderRadius != BorderRadius.zero) { + BoxBorder._paintUniformBorderWithRadius(canvas, rect, top, borderRadius); + return; + } + BoxBorder._paintUniformBorderWithRectangle(canvas, rect, top); + } + return; + } + } + + if (_styleIsUniform && top.style == BorderStyle.none) { + return; + } + + final BorderSide left, right; + assert(textDirection != null, 'Non-uniform BorderDirectional objects require a TextDirection when painting.'); + switch (textDirection!) { + case TextDirection.rtl: + left = end; + right = start; + case TextDirection.ltr: + left = start; + right = end; + } + + // Allow painting non-uniform borders if the visible colors are uniform. + final Set<Color> visibleColors = _distinctVisibleColors(); + final bool hasHairlineBorder = _hasHairlineBorder; + if (visibleColors.length == 1 && + !hasHairlineBorder && + (shape == BoxShape.circle || + (borderRadius != null && borderRadius != BorderRadius.zero))) { + BoxBorder.paintNonUniformBorder(canvas, rect, + shape: shape, + borderRadius: borderRadius, + textDirection: textDirection, + top: top.style == BorderStyle.none ? BorderSide.none : top, + right: right.style == BorderStyle.none ? BorderSide.none : right, + bottom: bottom.style == BorderStyle.none ? BorderSide.none : bottom, + left: left.style == BorderStyle.none ? BorderSide.none : left, + color: visibleColors.first); + return; + } + + if (hasHairlineBorder) { + assert(borderRadius == null || borderRadius == BorderRadius.zero, 'A side like `BorderSide(width: 0.0, style: BorderStyle.solid)` can only be drawn when BorderRadius is zero or null.'); + } + assert(borderRadius == null, 'A borderRadius can only be given for borders with uniform colors.'); + assert(shape == BoxShape.rectangle, 'A Border can only be drawn as a circle on borders with uniform colors.'); + assert(_strokeAlignIsUniform && top.strokeAlign == BorderSide.strokeAlignInside, 'A Border can only draw strokeAlign different than strokeAlignInside on borders with uniform colors.'); + + paintBorder(canvas, rect, top: top, left: left, bottom: bottom, right: right); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is BorderDirectional + && other.top == top + && other.start == start + && other.end == end + && other.bottom == bottom; + } + + @override + int get hashCode => Object.hash(top, start, end, bottom); + + @override + String toString() { + final List<String> arguments = <String>[ + if (top != BorderSide.none) 'top: $top', + if (start != BorderSide.none) 'start: $start', + if (end != BorderSide.none) 'end: $end', + if (bottom != BorderSide.none) 'bottom: $bottom', + ]; + return '${objectRuntimeType(this, 'BorderDirectional')}(${arguments.join(", ")})'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_decoration.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_decoration.dart new file mode 100644 index 0000000000000000000000000000000000000000..26328607ccf3f987e143f60470f4e941ef4d276a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_decoration.dart @@ -0,0 +1,502 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'border_radius.dart'; +import 'box_border.dart'; +import 'box_shadow.dart'; +import 'colors.dart'; +import 'decoration.dart'; +import 'decoration_image.dart'; +import 'edge_insets.dart'; +import 'gradient.dart'; +import 'image_provider.dart'; + +/// An immutable description of how to paint a box. +/// +/// The [BoxDecoration] class provides a variety of ways to draw a box. +/// +/// The box has a [border], a body, and may cast a [boxShadow]. +/// +/// The [shape] of the box can be a circle or a rectangle. If it is a rectangle, +/// then the [borderRadius] property controls the roundness of the corners. +/// +/// The body of the box is painted in layers. The bottom-most layer is the +/// [color], which fills the box. Above that is the [gradient], which also fills +/// the box. Finally there is the [image], the precise alignment of which is +/// controlled by the [DecorationImage] class. +/// +/// The [border] paints over the body; the [boxShadow], naturally, paints below it. +/// +/// {@tool snippet} +/// +/// The following applies a [BoxDecoration] to a [Container] widget to draw an +/// [image] of an owl with a thick black [border] and rounded corners. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/box_decoration.png) +/// +/// ```dart +/// Container( +/// decoration: BoxDecoration( +/// color: const Color(0xff7c94b6), +/// image: const DecorationImage( +/// image: NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'), +/// fit: BoxFit.cover, +/// ), +/// border: Border.all( +/// width: 8, +/// ), +/// borderRadius: BorderRadius.circular(12), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@template flutter.painting.BoxDecoration.clip} +/// The [shape] or the [borderRadius] won't clip the children of the +/// decorated [Container]. If the clip is required, insert a clip widget +/// (e.g., [ClipRect], [ClipRRect], [ClipPath]) as the child of the [Container]. +/// Be aware that clipping may be costly in terms of performance. +/// {@endtemplate} +/// +/// See also: +/// +/// * [DecoratedBox] and [Container], widgets that can be configured with +/// [BoxDecoration] objects. +/// * [DecoratedSliver], a widget that can be configured with a [BoxDecoration] +/// that is converted to render with slivers. +/// * [CustomPaint], a widget that lets you draw arbitrary graphics. +/// * [Decoration], the base class which lets you define other decorations. +class BoxDecoration extends Decoration { + /// Creates a box decoration. + /// + /// * If [color] is null, this decoration does not paint a background color. + /// * If [image] is null, this decoration does not paint a background image. + /// * If [border] is null, this decoration does not paint a border. + /// * If [borderRadius] is null, this decoration uses more efficient background + /// painting commands. The [borderRadius] argument must be null if [shape] is + /// [BoxShape.circle]. + /// * If [boxShadow] is null, this decoration does not paint a shadow. + /// * If [gradient] is null, this decoration does not paint gradients. + /// * If [backgroundBlendMode] is null, this decoration paints with [BlendMode.srcOver] + const BoxDecoration({ + this.color, + this.image, + this.border, + this.borderRadius, + this.boxShadow, + this.gradient, + this.backgroundBlendMode, + this.shape = BoxShape.rectangle, + }) : assert( + backgroundBlendMode == null || color != null || gradient != null, + "backgroundBlendMode applies to BoxDecoration's background color or " + 'gradient, but no color or gradient was provided.', + ); + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + BoxDecoration copyWith({ + Color? color, + DecorationImage? image, + BoxBorder? border, + BorderRadiusGeometry? borderRadius, + List<BoxShadow>? boxShadow, + Gradient? gradient, + BlendMode? backgroundBlendMode, + BoxShape? shape, + }) { + return BoxDecoration( + color: color ?? this.color, + image: image ?? this.image, + border: border ?? this.border, + borderRadius: borderRadius ?? this.borderRadius, + boxShadow: boxShadow ?? this.boxShadow, + gradient: gradient ?? this.gradient, + backgroundBlendMode: backgroundBlendMode ?? this.backgroundBlendMode, + shape: shape ?? this.shape, + ); + } + + @override + bool debugAssertIsValid() { + assert(shape != BoxShape.circle || borderRadius == null); // Can't have a border radius if you're a circle. + return super.debugAssertIsValid(); + } + + /// The color to fill in the background of the box. + /// + /// The color is filled into the [shape] of the box (e.g., either a rectangle, + /// potentially with a [borderRadius], or a circle). + /// + /// This is ignored if [gradient] is non-null. + /// + /// The [color] is drawn under the [image]. + final Color? color; + + /// An image to paint above the background [color] or [gradient]. + /// + /// If [shape] is [BoxShape.circle] then the image is clipped to the circle's + /// boundary; if [borderRadius] is non-null then the image is clipped to the + /// given radii. + final DecorationImage? image; + + /// A border to draw above the background [color], [gradient], or [image]. + /// + /// Follows the [shape] and [borderRadius]. + /// + /// Use [Border] objects to describe borders that do not depend on the reading + /// direction. + /// + /// Use [BoxBorder] objects to describe borders that should flip their left + /// and right edges based on whether the text is being read left-to-right or + /// right-to-left. + final BoxBorder? border; + + /// If non-null, the corners of this box are rounded by this [BorderRadius]. + /// + /// Applies only to boxes with rectangular shapes; ignored if [shape] is not + /// [BoxShape.rectangle]. + /// + /// {@macro flutter.painting.BoxDecoration.clip} + final BorderRadiusGeometry? borderRadius; + + /// A list of shadows cast by this box behind the box. + /// + /// The shadow follows the [shape] of the box. + /// + /// See also: + /// + /// * [kElevationToShadow], for some predefined shadows used in Material + /// Design. + /// * [PhysicalModel], a widget for showing shadows. + final List<BoxShadow>? boxShadow; + + /// A gradient to use when filling the box. + /// + /// If this is specified, [color] has no effect. + /// + /// The [gradient] is drawn under the [image]. + final Gradient? gradient; + + /// The blend mode applied to the [color] or [gradient] background of the box. + /// + /// If no [backgroundBlendMode] is provided then the default painting blend + /// mode is used. + /// + /// If no [color] or [gradient] is provided then the blend mode has no impact. + final BlendMode? backgroundBlendMode; + + /// The shape to fill the background [color], [gradient], and [image] into and + /// to cast as the [boxShadow]. + /// + /// If this is [BoxShape.circle] then [borderRadius] is ignored. + /// + /// The [shape] cannot be interpolated; animating between two [BoxDecoration]s + /// with different [shape]s will result in a discontinuity in the rendering. + /// To interpolate between two shapes, consider using [ShapeDecoration] and + /// different [ShapeBorder]s; in particular, [CircleBorder] instead of + /// [BoxShape.circle] and [RoundedRectangleBorder] instead of + /// [BoxShape.rectangle]. + /// + /// {@macro flutter.painting.BoxDecoration.clip} + final BoxShape shape; + + @override + EdgeInsetsGeometry get padding => border?.dimensions ?? EdgeInsets.zero; + + @override + Path getClipPath(Rect rect, TextDirection textDirection) { + switch (shape) { + case BoxShape.circle: + final Offset center = rect.center; + final double radius = rect.shortestSide / 2.0; + final Rect square = Rect.fromCircle(center: center, radius: radius); + return Path()..addOval(square); + case BoxShape.rectangle: + if (borderRadius != null) { + return Path()..addRRect(borderRadius!.resolve(textDirection).toRRect(rect)); + } + return Path()..addRect(rect); + } + } + + /// Returns a new box decoration that is scaled by the given factor. + BoxDecoration scale(double factor) { + return BoxDecoration( + color: Color.lerp(null, color, factor), + image: DecorationImage.lerp(null, image, factor), + border: BoxBorder.lerp(null, border, factor), + borderRadius: BorderRadiusGeometry.lerp(null, borderRadius, factor), + boxShadow: BoxShadow.lerpList(null, boxShadow, factor), + gradient: gradient?.scale(factor), + shape: shape, + ); + } + + @override + bool get isComplex => boxShadow != null; + + @override + BoxDecoration? lerpFrom(Decoration? a, double t) { + if (a == null) { + return scale(t); + } + if (a is BoxDecoration) { + return BoxDecoration.lerp(a, this, t); + } + return super.lerpFrom(a, t) as BoxDecoration?; + } + + @override + BoxDecoration? lerpTo(Decoration? b, double t) { + if (b == null) { + return scale(1.0 - t); + } + if (b is BoxDecoration) { + return BoxDecoration.lerp(this, b, t); + } + return super.lerpTo(b, t) as BoxDecoration?; + } + + /// Linearly interpolate between two box decorations. + /// + /// Interpolates each parameter of the box decoration separately. + /// + /// The [shape] is not interpolated. To interpolate the shape, consider using + /// a [ShapeDecoration] with different border shapes. + /// + /// If both values are null, this returns null. Otherwise, it returns a + /// non-null value. If one of the values is null, then the result is obtained + /// by applying [scale] to the other value. If neither value is null and `t == + /// 0.0`, then `a` is returned unmodified; if `t == 1.0` then `b` is returned + /// unmodified. Otherwise, the values are computed by interpolating the + /// properties appropriately. + /// + /// {@macro dart.ui.shadow.lerp} + /// + /// See also: + /// + /// * [Decoration.lerp], which can interpolate between any two types of + /// [Decoration]s, not just [BoxDecoration]s. + /// * [lerpFrom] and [lerpTo], which are used to implement [Decoration.lerp] + /// and which use [BoxDecoration.lerp] when interpolating two + /// [BoxDecoration]s or a [BoxDecoration] to or from null. + static BoxDecoration? lerp(BoxDecoration? a, BoxDecoration? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!.scale(t); + } + if (b == null) { + return a.scale(1.0 - t); + } + if (t == 0.0) { + return a; + } + if (t == 1.0) { + return b; + } + return BoxDecoration( + color: Color.lerp(a.color, b.color, t), + image: DecorationImage.lerp(a.image, b.image, t), + border: BoxBorder.lerp(a.border, b.border, t), + borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, b.borderRadius, t), + boxShadow: BoxShadow.lerpList(a.boxShadow, b.boxShadow, t), + gradient: Gradient.lerp(a.gradient, b.gradient, t), + shape: t < 0.5 ? a.shape : b.shape, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is BoxDecoration + && other.color == color + && other.image == image + && other.border == border + && other.borderRadius == borderRadius + && listEquals<BoxShadow>(other.boxShadow, boxShadow) + && other.gradient == gradient + && other.backgroundBlendMode == backgroundBlendMode + && other.shape == shape; + } + + @override + int get hashCode => Object.hash( + color, + image, + border, + borderRadius, + boxShadow == null ? null : Object.hashAll(boxShadow!), + gradient, + backgroundBlendMode, + shape, + ); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..defaultDiagnosticsTreeStyle = DiagnosticsTreeStyle.whitespace + ..emptyBodyDescription = '<no decorations specified>'; + + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(DiagnosticsProperty<DecorationImage>('image', image, defaultValue: null)); + properties.add(DiagnosticsProperty<BoxBorder>('border', border, defaultValue: null)); + properties.add(DiagnosticsProperty<BorderRadiusGeometry>('borderRadius', borderRadius, defaultValue: null)); + properties.add(IterableProperty<BoxShadow>('boxShadow', boxShadow, defaultValue: null, style: DiagnosticsTreeStyle.whitespace)); + properties.add(DiagnosticsProperty<Gradient>('gradient', gradient, defaultValue: null)); + properties.add(EnumProperty<BoxShape>('shape', shape, defaultValue: BoxShape.rectangle)); + } + + @override + bool hitTest(Size size, Offset position, { TextDirection? textDirection }) { + assert((Offset.zero & size).contains(position)); + switch (shape) { + case BoxShape.rectangle: + if (borderRadius != null) { + final RRect bounds = borderRadius!.resolve(textDirection).toRRect(Offset.zero & size); + return bounds.contains(position); + } + return true; + case BoxShape.circle: + // Circles are inscribed into our smallest dimension. + final Offset center = size.center(Offset.zero); + final double distance = (position - center).distance; + return distance <= math.min(size.width, size.height) / 2.0; + } + } + + @override + BoxPainter createBoxPainter([ VoidCallback? onChanged ]) { + assert(onChanged != null || image == null); + return _BoxDecorationPainter(this, onChanged); + } +} + +/// An object that paints a [BoxDecoration] into a canvas. +class _BoxDecorationPainter extends BoxPainter { + _BoxDecorationPainter(this._decoration, super.onChanged); + + final BoxDecoration _decoration; + + Paint? _cachedBackgroundPaint; + Rect? _rectForCachedBackgroundPaint; + Paint _getBackgroundPaint(Rect rect, TextDirection? textDirection) { + assert(_decoration.gradient != null || _rectForCachedBackgroundPaint == null); + + if (_cachedBackgroundPaint == null || + (_decoration.gradient != null && _rectForCachedBackgroundPaint != rect)) { + final Paint paint = Paint(); + if (_decoration.backgroundBlendMode != null) { + paint.blendMode = _decoration.backgroundBlendMode!; + } + if (_decoration.color != null) { + paint.color = _decoration.color!; + } + if (_decoration.gradient != null) { + paint.shader = _decoration.gradient!.createShader(rect, textDirection: textDirection); + _rectForCachedBackgroundPaint = rect; + } + _cachedBackgroundPaint = paint; + } + + return _cachedBackgroundPaint!; + } + + void _paintBox(Canvas canvas, Rect rect, Paint paint, TextDirection? textDirection) { + switch (_decoration.shape) { + case BoxShape.circle: + assert(_decoration.borderRadius == null); + final Offset center = rect.center; + final double radius = rect.shortestSide / 2.0; + canvas.drawCircle(center, radius, paint); + case BoxShape.rectangle: + if (_decoration.borderRadius == null || _decoration.borderRadius == BorderRadius.zero) { + canvas.drawRect(rect, paint); + } else { + canvas.drawRRect(_decoration.borderRadius!.resolve(textDirection).toRRect(rect), paint); + } + } + } + + void _paintShadows(Canvas canvas, Rect rect, TextDirection? textDirection) { + if (_decoration.boxShadow == null) { + return; + } + for (final BoxShadow boxShadow in _decoration.boxShadow!) { + final Paint paint = boxShadow.toPaint(); + final Rect bounds = rect.shift(boxShadow.offset).inflate(boxShadow.spreadRadius); + _paintBox(canvas, bounds, paint, textDirection); + } + } + + void _paintBackgroundColor(Canvas canvas, Rect rect, TextDirection? textDirection) { + if (_decoration.color != null || _decoration.gradient != null) { + _paintBox(canvas, rect, _getBackgroundPaint(rect, textDirection), textDirection); + } + } + + DecorationImagePainter? _imagePainter; + void _paintBackgroundImage(Canvas canvas, Rect rect, ImageConfiguration configuration) { + if (_decoration.image == null) { + return; + } + _imagePainter ??= _decoration.image!.createPainter(onChanged!); + Path? clipPath; + switch (_decoration.shape) { + case BoxShape.circle: + assert(_decoration.borderRadius == null); + final Offset center = rect.center; + final double radius = rect.shortestSide / 2.0; + final Rect square = Rect.fromCircle(center: center, radius: radius); + clipPath = Path()..addOval(square); + case BoxShape.rectangle: + if (_decoration.borderRadius != null) { + clipPath = Path()..addRRect(_decoration.borderRadius!.resolve(configuration.textDirection).toRRect(rect)); + } + } + _imagePainter!.paint(canvas, rect, clipPath, configuration); + } + + @override + void dispose() { + _imagePainter?.dispose(); + super.dispose(); + } + + /// Paint the box decoration into the given location on the given canvas. + @override + void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { + assert(configuration.size != null); + final Rect rect = offset & configuration.size!; + final TextDirection? textDirection = configuration.textDirection; + _paintShadows(canvas, rect, textDirection); + _paintBackgroundColor(canvas, rect, textDirection); + _paintBackgroundImage(canvas, rect, configuration); + _decoration.border?.paint( + canvas, + rect, + shape: _decoration.shape, + borderRadius: _decoration.borderRadius?.resolve(textDirection), + textDirection: configuration.textDirection, + ); + } + + @override + String toString() { + return 'BoxPainter for $_decoration'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_fit.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_fit.dart new file mode 100644 index 0000000000000000000000000000000000000000..a4ad41db61d0708a1f668213b54b06811773120b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_fit.dart @@ -0,0 +1,200 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; + +/// How a box should be inscribed into another box. +/// +/// See also: +/// +/// * [applyBoxFit], which applies the sizing semantics of these values (though +/// not the alignment semantics). +enum BoxFit { + /// Fill the target box by distorting the source's aspect ratio. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/box_fit_fill.png) + fill, + + /// As large as possible while still containing the source entirely within the + /// target box. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/box_fit_contain.png) + contain, + + /// As small as possible while still covering the entire target box. + /// + /// {@template flutter.painting.BoxFit.cover} + /// To actually clip the content, use `clipBehavior: Clip.hardEdge` alongside + /// this in a [FittedBox]. + /// {@endtemplate} + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/box_fit_cover.png) + cover, + + /// Make sure the full width of the source is shown, regardless of + /// whether this means the source overflows the target box vertically. + /// + /// {@macro flutter.painting.BoxFit.cover} + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/box_fit_fitWidth.png) + fitWidth, + + /// Make sure the full height of the source is shown, regardless of + /// whether this means the source overflows the target box horizontally. + /// + /// {@macro flutter.painting.BoxFit.cover} + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/box_fit_fitHeight.png) + fitHeight, + + /// Align the source within the target box (by default, centering) and discard + /// any portions of the source that lie outside the box. + /// + /// The source image is not resized. + /// + /// {@macro flutter.painting.BoxFit.cover} + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/box_fit_none.png) + none, + + /// Align the source within the target box (by default, centering) and, if + /// necessary, scale the source down to ensure that the source fits within the + /// box. + /// + /// This is the same as `contain` if that would shrink the image, otherwise it + /// is the same as `none`. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/box_fit_scaleDown.png) + scaleDown, +} + +/// The pair of sizes returned by [applyBoxFit]. +@immutable +class FittedSizes { + /// Creates an object to store a pair of sizes, + /// as would be returned by [applyBoxFit]. + const FittedSizes(this.source, this.destination); + + /// The size of the part of the input to show on the output. + final Size source; + + /// The size of the part of the output on which to show the input. + final Size destination; +} + +/// Apply a [BoxFit] value. +/// +/// The arguments to this method, in addition to the [BoxFit] value to apply, +/// are two sizes, ostensibly the sizes of an input box and an output box. +/// Specifically, the `inputSize` argument gives the size of the complete source +/// that is being fitted, and the `outputSize` gives the size of the rectangle +/// into which the source is to be drawn. +/// +/// This function then returns two sizes, combined into a single [FittedSizes] +/// object. +/// +/// The [FittedSizes.source] size is the subpart of the `inputSize` that is to +/// be shown. If the entire input source is shown, then this will equal the +/// `inputSize`, but if the input source is to be cropped down, this may be +/// smaller. +/// +/// The [FittedSizes.destination] size is the subpart of the `outputSize` in +/// which to paint the (possibly cropped) source. If the +/// [FittedSizes.destination] size is smaller than the `outputSize` then the +/// source is being letterboxed (or pillarboxed). +/// +/// This method does not express an opinion regarding the alignment of the +/// source and destination sizes within the input and output rectangles. +/// Typically they are centered (this is what [BoxDecoration] does, for +/// instance, and is how [BoxFit] is defined). The [Alignment] class provides a +/// convenience function, [Alignment.inscribe], for resolving the sizes to +/// rects, as shown in the example below. +/// +/// {@tool snippet} +/// +/// This function paints a [dart:ui.Image] `image` onto the [Rect] `outputRect` on a +/// [Canvas] `canvas`, using a [Paint] `paint`, applying the [BoxFit] algorithm +/// `fit`: +/// +/// ```dart +/// void paintImage(ui.Image image, Rect outputRect, Canvas canvas, Paint paint, BoxFit fit) { +/// final Size imageSize = Size(image.width.toDouble(), image.height.toDouble()); +/// final FittedSizes sizes = applyBoxFit(fit, imageSize, outputRect.size); +/// final Rect inputSubrect = Alignment.center.inscribe(sizes.source, Offset.zero & imageSize); +/// final Rect outputSubrect = Alignment.center.inscribe(sizes.destination, outputRect); +/// canvas.drawImageRect(image, inputSubrect, outputSubrect, paint); +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [FittedBox], a widget that applies this algorithm to another widget. +/// * [paintImage], a function that applies this algorithm to images for painting. +/// * [DecoratedBox], [BoxDecoration], and [DecorationImage], which together +/// provide access to [paintImage] at the widgets layer. +FittedSizes applyBoxFit(BoxFit fit, Size inputSize, Size outputSize) { + if (inputSize.height <= 0.0 || inputSize.width <= 0.0 || outputSize.height <= 0.0 || outputSize.width <= 0.0) { + return const FittedSizes(Size.zero, Size.zero); + } + + Size sourceSize, destinationSize; + switch (fit) { + case BoxFit.fill: + sourceSize = inputSize; + destinationSize = outputSize; + case BoxFit.contain: + sourceSize = inputSize; + if (outputSize.width / outputSize.height > sourceSize.width / sourceSize.height) { + destinationSize = Size(sourceSize.width * outputSize.height / sourceSize.height, outputSize.height); + } else { + destinationSize = Size(outputSize.width, sourceSize.height * outputSize.width / sourceSize.width); + } + case BoxFit.cover: + if (outputSize.width / outputSize.height > inputSize.width / inputSize.height) { + sourceSize = Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width); + } else { + sourceSize = Size(inputSize.height * outputSize.width / outputSize.height, inputSize.height); + } + destinationSize = outputSize; + case BoxFit.fitWidth: + if (outputSize.width / outputSize.height > inputSize.width / inputSize.height) { + // Like "cover" + sourceSize = Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width); + destinationSize = outputSize; + } else { + // Like "contain" + sourceSize = inputSize; + destinationSize = Size(outputSize.width, sourceSize.height * outputSize.width / sourceSize.width); + } + case BoxFit.fitHeight: + if (outputSize.width / outputSize.height > inputSize.width / inputSize.height) { + // Like "contain" + sourceSize = inputSize; + destinationSize = Size(sourceSize.width * outputSize.height / sourceSize.height, outputSize.height); + } else { + // Like "cover" + sourceSize = Size(inputSize.height * outputSize.width / outputSize.height, inputSize.height); + destinationSize = outputSize; + } + case BoxFit.none: + sourceSize = Size(math.min(inputSize.width, outputSize.width), math.min(inputSize.height, outputSize.height)); + destinationSize = sourceSize; + case BoxFit.scaleDown: + sourceSize = inputSize; + destinationSize = inputSize; + final double aspectRatio = inputSize.width / inputSize.height; + if (destinationSize.height > outputSize.height) { + destinationSize = Size(outputSize.height * aspectRatio, outputSize.height); + } + if (destinationSize.width > outputSize.width) { + destinationSize = Size(outputSize.width, outputSize.width / aspectRatio); + } + } + return FittedSizes(sourceSize, destinationSize); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_shadow.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_shadow.dart new file mode 100644 index 0000000000000000000000000000000000000000..9c49d1771af03297d42a8668aa6ccd526f05d024 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/box_shadow.dart @@ -0,0 +1,147 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui show Shadow, lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'debug.dart'; + +/// A shadow cast by a box. +/// +/// [BoxShadow] can cast non-rectangular shadows if the box is non-rectangular +/// (e.g., has a border radius or a circular shape). +/// +/// This class is similar to CSS box-shadow. +/// +/// See also: +/// +/// * [Canvas.drawShadow], which is a more efficient way to draw shadows. +/// * [PhysicalModel], a widget for showing shadows. +/// * [kElevationToShadow], for some predefined shadows used in Material +/// Design. +/// * [Shadow], which is the parent class that lacks [spreadRadius]. +@immutable +class BoxShadow extends ui.Shadow { + /// Creates a box shadow. + /// + /// By default, the shadow is solid black with zero [offset], zero [blurRadius], + /// zero [spreadRadius], and [BlurStyle.normal]. + const BoxShadow({ + super.color, + super.offset, + super.blurRadius, + this.spreadRadius = 0.0, + this.blurStyle = BlurStyle.normal, + }); + + /// The amount the box should be inflated prior to applying the blur. + final double spreadRadius; + + /// The [BlurStyle] to use for this shadow. + /// + /// Defaults to [BlurStyle.normal]. + final BlurStyle blurStyle; + + /// Create the [Paint] object that corresponds to this shadow description. + /// + /// The [offset] and [spreadRadius] are not represented in the [Paint] object. + /// To honor those as well, the shape should be inflated by [spreadRadius] pixels + /// in every direction and then translated by [offset] before being filled using + /// this [Paint]. + @override + Paint toPaint() { + final Paint result = Paint() + ..color = color + ..maskFilter = MaskFilter.blur(blurStyle, blurSigma); + assert(() { + if (debugDisableShadows) { + result.maskFilter = null; + } + return true; + }()); + return result; + } + + /// Returns a new box shadow with its offset, blurRadius, and spreadRadius scaled by the given factor. + @override + BoxShadow scale(double factor) { + return BoxShadow( + color: color, + offset: offset * factor, + blurRadius: blurRadius * factor, + spreadRadius: spreadRadius * factor, + blurStyle: blurStyle, + ); + } + + /// Linearly interpolate between two box shadows. + /// + /// If either box shadow is null, this function linearly interpolates from + /// a box shadow that matches the other box shadow in color but has a zero + /// offset and a zero blurRadius. + /// + /// {@macro dart.ui.shadow.lerp} + static BoxShadow? lerp(BoxShadow? a, BoxShadow? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!.scale(t); + } + if (b == null) { + return a.scale(1.0 - t); + } + return BoxShadow( + color: Color.lerp(a.color, b.color, t)!, + offset: Offset.lerp(a.offset, b.offset, t)!, + blurRadius: ui.lerpDouble(a.blurRadius, b.blurRadius, t)!, + spreadRadius: ui.lerpDouble(a.spreadRadius, b.spreadRadius, t)!, + blurStyle: a.blurStyle == BlurStyle.normal ? b.blurStyle : a.blurStyle, + ); + } + + /// Linearly interpolate between two lists of box shadows. + /// + /// If the lists differ in length, excess items are lerped with null. + /// + /// {@macro dart.ui.shadow.lerp} + static List<BoxShadow>? lerpList(List<BoxShadow>? a, List<BoxShadow>? b, double t) { + if (identical(a, b)) { + return a; + } + a ??= <BoxShadow>[]; + b ??= <BoxShadow>[]; + final int commonLength = math.min(a.length, b.length); + return <BoxShadow>[ + for (int i = 0; i < commonLength; i += 1) BoxShadow.lerp(a[i], b[i], t)!, + for (int i = commonLength; i < a.length; i += 1) a[i].scale(1.0 - t), + for (int i = commonLength; i < b.length; i += 1) b[i].scale(t), + ]; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is BoxShadow + && other.color == color + && other.offset == offset + && other.blurRadius == blurRadius + && other.spreadRadius == spreadRadius + && other.blurStyle == blurStyle; + } + + @override + int get hashCode => Object.hash(color, offset, blurRadius, spreadRadius, blurStyle); + + @override + String toString() => 'BoxShadow($color, $offset, ${debugFormatDouble(blurRadius)}, ${debugFormatDouble(spreadRadius)}, $blurStyle)'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/circle_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/circle_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..afec6883efbcca3f38df1250d53f9fce49f67e9a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/circle_border.dart @@ -0,0 +1,153 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'borders.dart'; + +/// A border that fits a circle within the available space. +/// +/// Typically used with [ShapeDecoration] to draw a circle. +/// +/// The [dimensions] assume that the border is being used in a square space. +/// When applied to a rectangular space, the border paints in the center of the +/// rectangle. +/// +/// The [eccentricity] parameter describes how much a circle will deform to +/// fit the rectangle it is a border for. A value of zero implies no +/// deformation (a circle touching at least two sides of the rectangle), a +/// value of one implies full deformation (an oval touching all sides of the +/// rectangle). +/// +/// See also: +/// +/// * [OvalBorder], which draws a Circle touching all the edges of the box. +/// * [BorderSide], which is used to describe each side of the box. +/// * [Border], which, when used with [BoxDecoration], can also describe a circle. +class CircleBorder extends OutlinedBorder { + /// Create a circle border. + const CircleBorder({ super.side, this.eccentricity = 0.0 }) + : assert(eccentricity >= 0.0, 'The eccentricity argument $eccentricity is not greater than or equal to zero.'), + assert(eccentricity <= 1.0, 'The eccentricity argument $eccentricity is not less than or equal to one.'); + + /// Defines the ratio (0.0-1.0) from which the border will deform + /// to fit a rectangle. + /// When 0.0, it draws a circle touching at least two sides of the rectangle. + /// When 1.0, it draws an oval touching all sides of the rectangle. + final double eccentricity; + + @override + ShapeBorder scale(double t) => CircleBorder(side: side.scale(t), eccentricity: eccentricity); + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is CircleBorder) { + return CircleBorder( + side: BorderSide.lerp(a.side, side, t), + eccentricity: clampDouble(ui.lerpDouble(a.eccentricity, eccentricity, t)!, 0.0, 1.0), + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is CircleBorder) { + return CircleBorder( + side: BorderSide.lerp(side, b.side, t), + eccentricity: clampDouble(ui.lerpDouble(eccentricity, b.eccentricity, t)!, 0.0, 1.0), + ); + } + return super.lerpTo(b, t); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + return Path()..addOval(_adjustRect(rect).deflate(side.strokeInset)); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path()..addOval(_adjustRect(rect)); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + if (eccentricity == 0.0) { + canvas.drawCircle(rect.center, rect.shortestSide / 2.0, paint); + } else { + canvas.drawOval(_adjustRect(rect), paint); + } + } + + @override + bool get preferPaintInterior => true; + + @override + CircleBorder copyWith({ BorderSide? side, double? eccentricity }) { + return CircleBorder(side: side ?? this.side, eccentricity: eccentricity ?? this.eccentricity); + } + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + switch (side.style) { + case BorderStyle.none: + break; + case BorderStyle.solid: + if (eccentricity == 0.0) { + canvas.drawCircle(rect.center, (rect.shortestSide + side.strokeOffset) / 2, side.toPaint()); + } else { + final Rect borderRect = _adjustRect(rect); + canvas.drawOval(borderRect.inflate(side.strokeOffset / 2), side.toPaint()); + } + } + } + + Rect _adjustRect(Rect rect) { + if (eccentricity == 0.0 || rect.width == rect.height) { + return Rect.fromCircle(center: rect.center, radius: rect.shortestSide / 2.0); + } + if (rect.width < rect.height) { + final double delta = (1.0 - eccentricity) * (rect.height - rect.width) / 2.0; + return Rect.fromLTRB( + rect.left, + rect.top + delta, + rect.right, + rect.bottom - delta, + ); + } else { + final double delta = (1.0 - eccentricity) * (rect.width - rect.height) / 2.0; + return Rect.fromLTRB( + rect.left + delta, + rect.top, + rect.right - delta, + rect.bottom, + ); + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is CircleBorder + && other.side == side + && other.eccentricity == eccentricity; + } + + @override + int get hashCode => Object.hash(side, eccentricity); + + @override + String toString() { + if (eccentricity != 0.0) { + return '${objectRuntimeType(this, 'CircleBorder')}($side, eccentricity: $eccentricity)'; + } + return '${objectRuntimeType(this, 'CircleBorder')}($side)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/clip.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/clip.dart new file mode 100644 index 0000000000000000000000000000000000000000..e3a95d2595dc161d1e33a153ed2329ab55d55df7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/clip.dart @@ -0,0 +1,55 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show Canvas, Clip, Paint, Path, RRect, Rect, VoidCallback; + +/// Clip utilities used by [PaintingContext]. +abstract class ClipContext { + /// The canvas on which to paint. + Canvas get canvas; + + void _clipAndPaint(void Function(bool doAntiAlias) canvasClipCall, Clip clipBehavior, Rect bounds, VoidCallback painter) { + canvas.save(); + switch (clipBehavior) { + case Clip.none: + break; + case Clip.hardEdge: + canvasClipCall(false); + case Clip.antiAlias: + canvasClipCall(true); + case Clip.antiAliasWithSaveLayer: + canvasClipCall(true); + canvas.saveLayer(bounds, Paint()); + } + painter(); + if (clipBehavior == Clip.antiAliasWithSaveLayer) { + canvas.restore(); + } + canvas.restore(); + } + + /// Clip [canvas] with [Path] according to [Clip] and then paint. [canvas] is + /// restored to the pre-clip status afterwards. + /// + /// `bounds` is the saveLayer bounds used for [Clip.antiAliasWithSaveLayer]. + void clipPathAndPaint(Path path, Clip clipBehavior, Rect bounds, VoidCallback painter) { + _clipAndPaint((bool doAntiAlias) => canvas.clipPath(path, doAntiAlias: doAntiAlias), clipBehavior, bounds, painter); + } + + /// Clip [canvas] with [Path] according to `rrect` and then paint. [canvas] is + /// restored to the pre-clip status afterwards. + /// + /// `bounds` is the saveLayer bounds used for [Clip.antiAliasWithSaveLayer]. + void clipRRectAndPaint(RRect rrect, Clip clipBehavior, Rect bounds, VoidCallback painter) { + _clipAndPaint((bool doAntiAlias) => canvas.clipRRect(rrect, doAntiAlias: doAntiAlias), clipBehavior, bounds, painter); + } + + /// Clip [canvas] with [Path] according to `rect` and then paint. [canvas] is + /// restored to the pre-clip status afterwards. + /// + /// `bounds` is the saveLayer bounds used for [Clip.antiAliasWithSaveLayer]. + void clipRectAndPaint(Rect rect, Clip clipBehavior, Rect bounds, VoidCallback painter) { + _clipAndPaint((bool doAntiAlias) => canvas.clipRect(rect, doAntiAlias: doAntiAlias), clipBehavior, bounds, painter); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/colors.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/colors.dart new file mode 100644 index 0000000000000000000000000000000000000000..f5c9e06bd88566628884b312d91a4b48366f2f7d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/colors.dart @@ -0,0 +1,524 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show Color, lerpDouble; + +import 'package:flutter/foundation.dart'; + +double _getHue(double red, double green, double blue, double max, double delta) { + late double hue; + if (max == 0.0) { + hue = 0.0; + } else if (max == red) { + hue = 60.0 * (((green - blue) / delta) % 6); + } else if (max == green) { + hue = 60.0 * (((blue - red) / delta) + 2); + } else if (max == blue) { + hue = 60.0 * (((red - green) / delta) + 4); + } + + /// Set hue to 0.0 when red == green == blue. + hue = hue.isNaN ? 0.0 : hue; + return hue; +} + +Color _colorFromHue( + double alpha, + double hue, + double chroma, + double secondary, + double match, +) { + double red; + double green; + double blue; + if (hue < 60.0) { + red = chroma; + green = secondary; + blue = 0.0; + } else if (hue < 120.0) { + red = secondary; + green = chroma; + blue = 0.0; + } else if (hue < 180.0) { + red = 0.0; + green = chroma; + blue = secondary; + } else if (hue < 240.0) { + red = 0.0; + green = secondary; + blue = chroma; + } else if (hue < 300.0) { + red = secondary; + green = 0.0; + blue = chroma; + } else { + red = chroma; + green = 0.0; + blue = secondary; + } + return Color.fromARGB((alpha * 0xFF).round(), ((red + match) * 0xFF).round(), ((green + match) * 0xFF).round(), ((blue + match) * 0xFF).round()); +} + +/// A color represented using [alpha], [hue], [saturation], and [value]. +/// +/// An [HSVColor] is represented in a parameter space that's based on human +/// perception of color in pigments (e.g. paint and printer's ink). The +/// representation is useful for some color computations (e.g. rotating the hue +/// through the colors), because interpolation and picking of +/// colors as red, green, and blue channels doesn't always produce intuitive +/// results. +/// +/// The HSV color space models the way that different pigments are perceived +/// when mixed. The hue describes which pigment is used, the saturation +/// describes which shade of the pigment, and the value resembles mixing the +/// pigment with different amounts of black or white pigment. +/// +/// See also: +/// +/// * [HSLColor], a color that uses a color space based on human perception of +/// colored light. +/// * [HSV and HSL](https://en.wikipedia.org/wiki/HSL_and_HSV) Wikipedia +/// article, which this implementation is based upon. +@immutable +class HSVColor { + /// Creates a color. + /// + /// All the arguments must be in their respective ranges. See the fields for + /// each parameter for a description of their ranges. + const HSVColor.fromAHSV(this.alpha, this.hue, this.saturation, this.value) + : assert(alpha >= 0.0), + assert(alpha <= 1.0), + assert(hue >= 0.0), + assert(hue <= 360.0), + assert(saturation >= 0.0), + assert(saturation <= 1.0), + assert(value >= 0.0), + assert(value <= 1.0); + + /// Creates an [HSVColor] from an RGB [Color]. + /// + /// This constructor does not necessarily round-trip with [toColor] because + /// of floating point imprecision. + factory HSVColor.fromColor(Color color) { + final double red = color.red / 0xFF; + final double green = color.green / 0xFF; + final double blue = color.blue / 0xFF; + + final double max = math.max(red, math.max(green, blue)); + final double min = math.min(red, math.min(green, blue)); + final double delta = max - min; + + final double alpha = color.alpha / 0xFF; + final double hue = _getHue(red, green, blue, max, delta); + final double saturation = max == 0.0 ? 0.0 : delta / max; + + return HSVColor.fromAHSV(alpha, hue, saturation, max); + } + + /// Alpha, from 0.0 to 1.0. The describes the transparency of the color. + /// A value of 0.0 is fully transparent, and 1.0 is fully opaque. + final double alpha; + + /// Hue, from 0.0 to 360.0. Describes which color of the spectrum is + /// represented. A value of 0.0 represents red, as does 360.0. Values in + /// between go through all the hues representable in RGB. You can think of + /// this as selecting which pigment will be added to a color. + final double hue; + + /// Saturation, from 0.0 to 1.0. This describes how colorful the color is. + /// 0.0 implies a shade of grey (i.e. no pigment), and 1.0 implies a color as + /// vibrant as that hue gets. You can think of this as the equivalent of + /// how much of a pigment is added. + final double saturation; + + /// Value, from 0.0 to 1.0. The "value" of a color that, in this context, + /// describes how bright a color is. A value of 0.0 indicates black, and 1.0 + /// indicates full intensity color. You can think of this as the equivalent of + /// removing black from the color as value increases. + final double value; + + /// Returns a copy of this color with the [alpha] parameter replaced with the + /// given value. + HSVColor withAlpha(double alpha) { + return HSVColor.fromAHSV(alpha, hue, saturation, value); + } + + /// Returns a copy of this color with the [hue] parameter replaced with the + /// given value. + HSVColor withHue(double hue) { + return HSVColor.fromAHSV(alpha, hue, saturation, value); + } + + /// Returns a copy of this color with the [saturation] parameter replaced with + /// the given value. + HSVColor withSaturation(double saturation) { + return HSVColor.fromAHSV(alpha, hue, saturation, value); + } + + /// Returns a copy of this color with the [value] parameter replaced with the + /// given value. + HSVColor withValue(double value) { + return HSVColor.fromAHSV(alpha, hue, saturation, value); + } + + /// Returns this color in RGB. + Color toColor() { + final double chroma = saturation * value; + final double secondary = chroma * (1.0 - (((hue / 60.0) % 2.0) - 1.0).abs()); + final double match = value - chroma; + + return _colorFromHue(alpha, hue, chroma, secondary, match); + } + + HSVColor _scaleAlpha(double factor) { + return withAlpha(alpha * factor); + } + + /// Linearly interpolate between two HSVColors. + /// + /// The colors are interpolated by interpolating the [alpha], [hue], + /// [saturation], and [value] channels separately, which usually leads to a + /// more pleasing effect than [Color.lerp] (which interpolates the red, green, + /// and blue channels separately). + /// + /// If either color is null, this function linearly interpolates from a + /// transparent instance of the other color. This is usually preferable to + /// interpolating from [Colors.transparent] (`const Color(0x00000000)`) since + /// that will interpolate from a transparent red and cycle through the hues to + /// match the target color, regardless of what that color's hue is. + /// + /// {@macro dart.ui.shadow.lerp} + /// + /// Values outside of the valid range for each channel will be clamped. + static HSVColor? lerp(HSVColor? a, HSVColor? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!._scaleAlpha(t); + } + if (b == null) { + return a._scaleAlpha(1.0 - t); + } + return HSVColor.fromAHSV( + clampDouble(lerpDouble(a.alpha, b.alpha, t)!, 0.0, 1.0), + lerpDouble(a.hue, b.hue, t)! % 360.0, + clampDouble(lerpDouble(a.saturation, b.saturation, t)!, 0.0, 1.0), + clampDouble(lerpDouble(a.value, b.value, t)!, 0.0, 1.0), + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is HSVColor + && other.alpha == alpha + && other.hue == hue + && other.saturation == saturation + && other.value == value; + } + + @override + int get hashCode => Object.hash(alpha, hue, saturation, value); + + @override + String toString() => '${objectRuntimeType(this, 'HSVColor')}($alpha, $hue, $saturation, $value)'; +} + +/// A color represented using [alpha], [hue], [saturation], and [lightness]. +/// +/// An [HSLColor] is represented in a parameter space that's based up human +/// perception of colored light. The representation is useful for some color +/// computations (e.g., combining colors of light), because interpolation and +/// picking of colors as red, green, and blue channels doesn't always produce +/// intuitive results. +/// +/// HSL is a perceptual color model, placing fully saturated colors around a +/// circle (conceptually) at a lightness of ​0.5, with a lightness of 0.0 being +/// completely black, and a lightness of 1.0 being completely white. As the +/// lightness increases or decreases from 0.5, the apparent saturation decreases +/// proportionally (even though the [saturation] parameter hasn't changed). +/// +/// See also: +/// +/// * [HSVColor], a color that uses a color space based on human perception of +/// pigments (e.g. paint and printer's ink). +/// * [HSV and HSL](https://en.wikipedia.org/wiki/HSL_and_HSV) Wikipedia +/// article, which this implementation is based upon. +@immutable +class HSLColor { + /// Creates a color. + /// + /// All the arguments must be in their respective ranges. See the fields for + /// each parameter for a description of their ranges. + const HSLColor.fromAHSL(this.alpha, this.hue, this.saturation, this.lightness) + : assert(alpha >= 0.0), + assert(alpha <= 1.0), + assert(hue >= 0.0), + assert(hue <= 360.0), + assert(saturation >= 0.0), + assert(saturation <= 1.0), + assert(lightness >= 0.0), + assert(lightness <= 1.0); + + /// Creates an [HSLColor] from an RGB [Color]. + /// + /// This constructor does not necessarily round-trip with [toColor] because + /// of floating point imprecision. + factory HSLColor.fromColor(Color color) { + final double red = color.red / 0xFF; + final double green = color.green / 0xFF; + final double blue = color.blue / 0xFF; + + final double max = math.max(red, math.max(green, blue)); + final double min = math.min(red, math.min(green, blue)); + final double delta = max - min; + + final double alpha = color.alpha / 0xFF; + final double hue = _getHue(red, green, blue, max, delta); + final double lightness = (max + min) / 2.0; + // Saturation can exceed 1.0 with rounding errors, so clamp it. + final double saturation = lightness == 1.0 + ? 0.0 + : clampDouble(delta / (1.0 - (2.0 * lightness - 1.0).abs()), 0.0, 1.0); + return HSLColor.fromAHSL(alpha, hue, saturation, lightness); + } + + /// Alpha, from 0.0 to 1.0. The describes the transparency of the color. + /// A value of 0.0 is fully transparent, and 1.0 is fully opaque. + final double alpha; + + /// Hue, from 0.0 to 360.0. Describes which color of the spectrum is + /// represented. A value of 0.0 represents red, as does 360.0. Values in + /// between go through all the hues representable in RGB. You can think of + /// this as selecting which color filter is placed over a light. + final double hue; + + /// Saturation, from 0.0 to 1.0. This describes how colorful the color is. + /// 0.0 implies a shade of grey (i.e. no pigment), and 1.0 implies a color as + /// vibrant as that hue gets. You can think of this as the purity of the + /// color filter over the light. + final double saturation; + + /// Lightness, from 0.0 to 1.0. The lightness of a color describes how bright + /// a color is. A value of 0.0 indicates black, and 1.0 indicates white. You + /// can think of this as the intensity of the light behind the filter. As the + /// lightness approaches 0.5, the colors get brighter and appear more + /// saturated, and over 0.5, the colors start to become less saturated and + /// approach white at 1.0. + final double lightness; + + /// Returns a copy of this color with the alpha parameter replaced with the + /// given value. + HSLColor withAlpha(double alpha) { + return HSLColor.fromAHSL(alpha, hue, saturation, lightness); + } + + /// Returns a copy of this color with the [hue] parameter replaced with the + /// given value. + HSLColor withHue(double hue) { + return HSLColor.fromAHSL(alpha, hue, saturation, lightness); + } + + /// Returns a copy of this color with the [saturation] parameter replaced with + /// the given value. + HSLColor withSaturation(double saturation) { + return HSLColor.fromAHSL(alpha, hue, saturation, lightness); + } + + /// Returns a copy of this color with the [lightness] parameter replaced with + /// the given value. + HSLColor withLightness(double lightness) { + return HSLColor.fromAHSL(alpha, hue, saturation, lightness); + } + + /// Returns this HSL color in RGB. + Color toColor() { + final double chroma = (1.0 - (2.0 * lightness - 1.0).abs()) * saturation; + final double secondary = chroma * (1.0 - (((hue / 60.0) % 2.0) - 1.0).abs()); + final double match = lightness - chroma / 2.0; + + return _colorFromHue(alpha, hue, chroma, secondary, match); + } + + HSLColor _scaleAlpha(double factor) { + return withAlpha(alpha * factor); + } + + /// Linearly interpolate between two HSLColors. + /// + /// The colors are interpolated by interpolating the [alpha], [hue], + /// [saturation], and [lightness] channels separately, which usually leads to + /// a more pleasing effect than [Color.lerp] (which interpolates the red, + /// green, and blue channels separately). + /// + /// If either color is null, this function linearly interpolates from a + /// transparent instance of the other color. This is usually preferable to + /// interpolating from [Colors.transparent] (`const Color(0x00000000)`) since + /// that will interpolate from a transparent red and cycle through the hues to + /// match the target color, regardless of what that color's hue is. + /// + /// The `t` argument represents position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `a` (or something + /// equivalent to `a`), 1.0 meaning that the interpolation has finished, + /// returning `b` (or something equivalent to `b`), and values between them + /// meaning that the interpolation is at the relevant point on the timeline + /// between `a` and `b`. The interpolation can be extrapolated beyond 0.0 and + /// 1.0, so negative values and values greater than 1.0 are valid + /// (and can easily be generated by curves such as [Curves.elasticInOut]). + /// + /// Values outside of the valid range for each channel will be clamped. + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + static HSLColor? lerp(HSLColor? a, HSLColor? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!._scaleAlpha(t); + } + if (b == null) { + return a._scaleAlpha(1.0 - t); + } + return HSLColor.fromAHSL( + clampDouble(lerpDouble(a.alpha, b.alpha, t)!, 0.0, 1.0), + lerpDouble(a.hue, b.hue, t)! % 360.0, + clampDouble(lerpDouble(a.saturation, b.saturation, t)!, 0.0, 1.0), + clampDouble(lerpDouble(a.lightness, b.lightness, t)!, 0.0, 1.0), + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is HSLColor + && other.alpha == alpha + && other.hue == hue + && other.saturation == saturation + && other.lightness == lightness; + } + + @override + int get hashCode => Object.hash(alpha, hue, saturation, lightness); + + @override + String toString() => '${objectRuntimeType(this, 'HSLColor')}($alpha, $hue, $saturation, $lightness)'; +} + +/// A color that has a small table of related colors called a "swatch". +/// +/// The table is indexed by values of type `T`. +/// +/// See also: +/// +/// * [MaterialColor] and [MaterialAccentColor], which define Material Design +/// primary and accent color swatches. +/// * [material.Colors], which defines all of the standard Material Design +/// colors. +@immutable +class ColorSwatch<T> extends Color { + /// Creates a color that has a small table of related colors called a "swatch". + /// + /// The `primary` argument should be the 32 bit ARGB value of one of the + /// values in the swatch, as would be passed to the [Color.new] constructor + /// for that same color, and as is exposed by [value]. (This is distinct from + /// the specific index of the color in the swatch.) + const ColorSwatch(super.primary, this._swatch); + + @protected + final Map<T, Color> _swatch; + + /// Returns an element of the swatch table. + Color? operator [](T index) => _swatch[index]; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return super == other + && other is ColorSwatch<T> + && mapEquals<T, Color>(other._swatch, _swatch); + } + + @override + int get hashCode => Object.hash(runtimeType, value, _swatch); + + @override + String toString() => '${objectRuntimeType(this, 'ColorSwatch')}(primary value: ${super.toString()})'; + + /// Linearly interpolate between two [ColorSwatch]es. + /// + /// It delegates to [Color.lerp] to interpolate the different colors of the + /// swatch. + /// + /// If either color is null, this function linearly interpolates from a + /// transparent instance of the other color. + /// + /// The `t` argument represents position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `a` (or something + /// equivalent to `a`), 1.0 meaning that the interpolation has finished, + /// returning `b` (or something equivalent to `b`), and values in between + /// meaning that the interpolation is at the relevant point on the timeline + /// between `a` and `b`. The interpolation can be extrapolated beyond 0.0 and + /// 1.0, so negative values and values greater than 1.0 are valid (and can + /// easily be generated by curves such as [Curves.elasticInOut]). Each channel + /// will be clamped to the range 0 to 255. + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + static ColorSwatch<T>? lerp<T>(ColorSwatch<T>? a, ColorSwatch<T>? b, double t) { + if (identical(a, b)) { + return a; + } + final Map<T, Color> swatch; + if (b == null) { + swatch = a!._swatch.map((T key, Color color) => MapEntry<T, Color>(key, Color.lerp(color, null, t)!)); + } else { + if (a == null) { + swatch = b._swatch.map((T key, Color color) => MapEntry<T, Color>(key, Color.lerp(null, color, t)!)); + } else { + swatch = a._swatch.map((T key, Color color) => MapEntry<T, Color>(key, Color.lerp(color, b[key], t)!)); + } + } + return ColorSwatch<T>(Color.lerp(a, b, t)!.value, swatch); + } +} + +/// [DiagnosticsProperty] that has an [Color] as value. +class ColorProperty extends DiagnosticsProperty<Color> { + /// Create a diagnostics property for [Color]. + ColorProperty( + String super.name, + super.value, { + super.showName, + super.defaultValue, + super.style, + super.level, + }); + + @override + Map<String, Object?> toJsonMap(DiagnosticsSerializationDelegate delegate) { + final Map<String, Object?> json = super.toJsonMap(delegate); + if (value != null) { + json['valueProperties'] = <String, Object>{ + 'red': value!.red, + 'green': value!.green, + 'blue': value!.blue, + 'alpha': value!.alpha, + }; + } + return json; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/continuous_rectangle_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/continuous_rectangle_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..b7612e43cb4900394a6f08708ed2d2527830171a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/continuous_rectangle_border.dart @@ -0,0 +1,172 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'border_radius.dart'; +import 'borders.dart'; +import 'edge_insets.dart'; + +/// A rectangular border with smooth continuous transitions between the straight +/// sides and the rounded corners. +/// +/// {@tool snippet} +/// ```dart +/// Widget build(BuildContext context) { +/// return Material( +/// shape: ContinuousRectangleBorder( +/// borderRadius: BorderRadius.circular(28.0), +/// ), +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [RoundedRectangleBorder] Which creates rectangles with rounded corners, +/// however its straight sides change into a rounded corner with a circular +/// radius in a step function instead of gradually like the +/// [ContinuousRectangleBorder]. +class ContinuousRectangleBorder extends OutlinedBorder { + /// Creates a [ContinuousRectangleBorder]. + const ContinuousRectangleBorder({ + super.side, + this.borderRadius = BorderRadius.zero, + }); + + /// The radius for each corner. + /// + /// Negative radius values are clamped to 0.0 by [getInnerPath] and + /// [getOuterPath]. + final BorderRadiusGeometry borderRadius; + + @override + EdgeInsetsGeometry get dimensions => EdgeInsets.all(side.width); + + @override + ShapeBorder scale(double t) { + return ContinuousRectangleBorder( + side: side.scale(t), + borderRadius: borderRadius * t, + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is ContinuousRectangleBorder) { + return ContinuousRectangleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!, + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is ContinuousRectangleBorder) { + return ContinuousRectangleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t)!, + ); + } + return super.lerpTo(b, t); + } + + double _clampToShortest(RRect rrect, double value) { + return value > rrect.shortestSide ? rrect.shortestSide : value; + } + + Path _getPath(RRect rrect) { + final double left = rrect.left; + final double right = rrect.right; + final double top = rrect.top; + final double bottom = rrect.bottom; + // Radii will be clamped to the value of the shortest side + // of rrect to avoid strange tie-fighter shapes. + final double tlRadiusX = + math.max(0.0, _clampToShortest(rrect, rrect.tlRadiusX)); + final double tlRadiusY = + math.max(0.0, _clampToShortest(rrect, rrect.tlRadiusY)); + final double trRadiusX = + math.max(0.0, _clampToShortest(rrect, rrect.trRadiusX)); + final double trRadiusY = + math.max(0.0, _clampToShortest(rrect, rrect.trRadiusY)); + final double blRadiusX = + math.max(0.0, _clampToShortest(rrect, rrect.blRadiusX)); + final double blRadiusY = + math.max(0.0, _clampToShortest(rrect, rrect.blRadiusY)); + final double brRadiusX = + math.max(0.0, _clampToShortest(rrect, rrect.brRadiusX)); + final double brRadiusY = + math.max(0.0, _clampToShortest(rrect, rrect.brRadiusY)); + + return Path() + ..moveTo(left, top + tlRadiusX) + ..cubicTo(left, top, left, top, left + tlRadiusY, top) + ..lineTo(right - trRadiusX, top) + ..cubicTo(right, top, right, top, right, top + trRadiusY) + ..lineTo(right, bottom - brRadiusX) + ..cubicTo(right, bottom, right, bottom, right - brRadiusY, bottom) + ..lineTo(left + blRadiusX, bottom) + ..cubicTo(left, bottom, left, bottom, left, bottom - blRadiusY) + ..close(); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + return _getPath(borderRadius.resolve(textDirection).toRRect(rect).deflate(side.width)); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return _getPath(borderRadius.resolve(textDirection).toRRect(rect)); + } + + @override + ContinuousRectangleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius }) { + return ContinuousRectangleBorder( + side: side ?? this.side, + borderRadius: borderRadius ?? this.borderRadius, + ); + } + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + if (rect.isEmpty) { + return; + } + switch (side.style) { + case BorderStyle.none: + break; + case BorderStyle.solid: + canvas.drawPath( + getOuterPath(rect, textDirection: textDirection), + side.toPaint(), + ); + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ContinuousRectangleBorder + && other.side == side + && other.borderRadius == borderRadius; + } + + @override + int get hashCode => Object.hash(side, borderRadius); + + @override + String toString() { + return '${objectRuntimeType(this, 'ContinuousRectangleBorder')}($side, $borderRadius)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/debug.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/debug.dart new file mode 100644 index 0000000000000000000000000000000000000000..cbb6e48561e4e69665c4fe9df1510f8f9db8455a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/debug.dart @@ -0,0 +1,221 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:io'; +import 'dart:ui' show Image, Picture, Size; + +import 'package:flutter/foundation.dart'; + +/// Whether to replace all shadows with solid color blocks. +/// +/// This is useful when writing golden file tests (see [matchesGoldenFile]) since +/// the rendering of shadows is not guaranteed to be pixel-for-pixel identical from +/// version to version (or even from run to run). +/// +/// In those tests, this is usually set to false at the beginning of a test and back +/// to true before the end of the test case. +/// +/// If it remains true when the test ends, an exception is thrown to avoid state +/// leaking from one test case to another. +bool debugDisableShadows = false; + +/// Signature for a method that returns an [HttpClient]. +/// +/// Used by [debugNetworkImageHttpClientProvider]. +typedef HttpClientProvider = HttpClient Function(); + +/// Provider from which [NetworkImage] will get its [HttpClient] in debug builds. +/// +/// If this value is unset, [NetworkImage] will use its own internally-managed +/// [HttpClient]. +/// +/// This setting can be overridden for testing to ensure that each test receives +/// a mock client that hasn't been affected by other tests. +/// +/// This value is ignored in non-debug builds. +HttpClientProvider? debugNetworkImageHttpClientProvider; + +/// Called when the framework is about to paint an [Image] to a [Canvas] with an +/// [ImageSizeInfo] that contains the decoded size of the image as well as its +/// output size. +/// +/// See: [debugOnPaintImage]. +typedef PaintImageCallback = void Function(ImageSizeInfo info); + +/// Tracks the bytes used by a [dart:ui.Image] compared to the bytes needed to +/// paint that image without scaling it. +@immutable +class ImageSizeInfo { + /// Creates an object to track the backing size of a [dart:ui.Image] compared + /// to its display size on a [Canvas]. + /// + /// This class is used by the framework when it paints an image to a canvas + /// to report to `dart:developer`'s [postEvent], as well as to the + /// [debugOnPaintImage] callback if it is set. + const ImageSizeInfo({this.source, required this.displaySize, required this.imageSize}); + + /// A unique identifier for this image, for example its asset path or network + /// URL. + final String? source; + + /// The size of the area the image will be rendered in. + final Size displaySize; + + /// The size the image has been decoded to. + final Size imageSize; + + /// The number of bytes needed to render the image without scaling it. + int get displaySizeInBytes => _sizeToBytes(displaySize); + + /// The number of bytes used by the image in memory. + int get decodedSizeInBytes => _sizeToBytes(imageSize); + + int _sizeToBytes(Size size) { + // Assume 4 bytes per pixel and that mipmapping will be used, which adds + // 4/3. + return (size.width * size.height * 4 * (4/3)).toInt(); + } + + /// Returns a JSON encodable representation of this object. + Map<String, Object?> toJson() { + return <String, Object?>{ + 'source': source, + 'displaySize': <String, Object?>{ + 'width': displaySize.width, + 'height': displaySize.height, + }, + 'imageSize': <String, Object?>{ + 'width': imageSize.width, + 'height': imageSize.height, + }, + 'displaySizeInBytes': displaySizeInBytes, + 'decodedSizeInBytes': decodedSizeInBytes, + }; + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ImageSizeInfo + && other.source == source + && other.imageSize == imageSize + && other.displaySize == displaySize; + } + + @override + int get hashCode => Object.hash(source, displaySize, imageSize); + + @override + String toString() => 'ImageSizeInfo($source, imageSize: $imageSize, displaySize: $displaySize)'; +} + +/// If not null, called when the framework is about to paint an [Image] to a +/// [Canvas] with an [ImageSizeInfo] that contains the decoded size of the +/// image as well as its output size. +/// +/// A test can use this callback to detect if images under test are being +/// rendered with the appropriate cache dimensions. +/// +/// For example, if a 100x100 image is decoded it takes roughly 53kb in memory +/// (including mipmapping overhead). If it is only ever displayed at 50x50, it +/// would take only 13kb if the cacheHeight/cacheWidth parameters had been +/// specified at that size. This problem becomes more serious for larger +/// images, such as a high resolution image from a 12MP camera, which would be +/// 64mb when decoded. +/// +/// When using this callback, developers should consider whether the image will +/// be panned or scaled up in the application, how many images are being +/// displayed, and whether the application will run on multiple devices with +/// different resolutions and memory capacities. For example, it should be fine +/// to have an image that animates from thumbnail size to full screen be at +/// a higher resolution while animating, but it would be problematic to have +/// a grid or list of such thumbnails all be at the full resolution at the same +/// time. +PaintImageCallback? debugOnPaintImage; + +/// If true, the framework will color invert and horizontally flip images that +/// have been decoded to a size taking at least [debugImageOverheadAllowance] +/// bytes more than necessary. +/// +/// It will also call [FlutterError.reportError] with information about the +/// image's decoded size and its display size, which can be used resize the +/// asset before shipping it, apply `cacheHeight` or `cacheWidth` parameters, or +/// directly use a [ResizeImage]. Whenever possible, resizing the image asset +/// itself should be preferred, to avoid unnecessary network traffic, disk space +/// usage, and other memory overhead incurred during decoding. +/// +/// Developers using this flag should test their application on appropriate +/// devices and display sizes for their expected deployment targets when using +/// these parameters. For example, an application that responsively resizes +/// images for a desktop and mobile layout should avoid decoding all images at +/// sizes appropriate for mobile when on desktop. Applications should also avoid +/// animating these parameters, as each change will result in a newly decoded +/// image. For example, an image that always grows into view should decode only +/// at its largest size, whereas an image that normally is a thumbnail and then +/// pops into view should be decoded at its smallest size for the thumbnail and +/// the largest size when needed. +/// +/// This has no effect unless asserts are enabled. +bool debugInvertOversizedImages = false; + +const int _imageOverheadAllowanceDefault = 128 * 1024; + +/// The number of bytes an image must use before it triggers inversion when +/// [debugInvertOversizedImages] is true. +/// +/// Default is 128kb. +int debugImageOverheadAllowance = _imageOverheadAllowanceDefault; + +/// Returns true if none of the painting library debug variables have been changed. +/// +/// This function is used by the test framework to ensure that debug variables +/// haven't been inadvertently changed. +/// +/// See [the painting library](painting/painting-library.html) for a complete +/// list. +/// +/// The `debugDisableShadowsOverride` argument can be provided to override +/// the expected value for [debugDisableShadows]. (This exists because the +/// test framework itself overrides this value in some cases.) +bool debugAssertAllPaintingVarsUnset(String reason, { bool debugDisableShadowsOverride = false }) { + assert(() { + if (debugDisableShadows != debugDisableShadowsOverride || + debugNetworkImageHttpClientProvider != null || + debugOnPaintImage != null || + debugInvertOversizedImages || + debugImageOverheadAllowance != _imageOverheadAllowanceDefault) { + throw FlutterError(reason); + } + return true; + }()); + return true; +} + +/// The signature of [debugCaptureShaderWarmUpPicture]. +/// +/// Used by tests to run assertions on the [Picture] created by +/// [ShaderWarmUp.execute]. The return value indicates whether the assertions +/// pass or not. +typedef ShaderWarmUpPictureCallback = bool Function(Picture picture); + +/// The signature of [debugCaptureShaderWarmUpImage]. +/// +/// Used by tests to run assertions on the [Image] created by +/// [ShaderWarmUp.execute]. The return value indicates whether the assertions +/// pass or not. +typedef ShaderWarmUpImageCallback = bool Function(Image image); + +/// Called by [ShaderWarmUp.execute] immediately after it creates a [Picture]. +/// +/// Tests may use this to capture the picture and run assertions on it. +ShaderWarmUpPictureCallback debugCaptureShaderWarmUpPicture = _defaultPictureCapture; +bool _defaultPictureCapture(Picture picture) => true; + +/// Called by [ShaderWarmUp.execute] immediately after it creates an [Image]. +/// +/// Tests may use this to capture the picture and run assertions on it. +ShaderWarmUpImageCallback debugCaptureShaderWarmUpImage = _defaultImageCapture; +bool _defaultImageCapture(Image image) => true; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/decoration.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/decoration.dart new file mode 100644 index 0000000000000000000000000000000000000000..5e7bd207660c2db5c4e2c6841f1626b940abc51a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/decoration.dart @@ -0,0 +1,247 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'edge_insets.dart'; +import 'image_provider.dart'; + +// Examples can assume: +// late Decoration myDecoration; + +// This group of classes is intended for painting in cartesian coordinates. + +/// A description of a box decoration (a decoration applied to a [Rect]). +/// +/// This class presents the abstract interface for all decorations. +/// See [BoxDecoration] for a concrete example. +/// +/// To actually paint a [Decoration], use the [createBoxPainter] +/// method to obtain a [BoxPainter]. [Decoration] objects can be +/// shared between boxes; [BoxPainter] objects can cache resources to +/// make painting on a particular surface faster. +@immutable +abstract class Decoration with Diagnosticable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const Decoration(); + + @override + String toStringShort() => objectRuntimeType(this, 'Decoration'); + + /// In debug mode, throws an exception if the object is not in a + /// valid configuration. Otherwise, returns true. + /// + /// This is intended to be used as follows: + /// ```dart + /// assert(myDecoration.debugAssertIsValid()); + /// ``` + bool debugAssertIsValid() => true; + + /// Returns the insets to apply when using this decoration on a box + /// that has contents, so that the contents do not overlap the edges + /// of the decoration. For example, if the decoration draws a frame + /// around its edge, the padding would return the distance by which + /// to inset the children so as to not overlap the frame. + /// + /// This only works for decorations that have absolute sizes. If the padding + /// needed would change based on the size at which the decoration is drawn, + /// then this will return incorrect padding values. + /// + /// For example, when a [BoxDecoration] has [BoxShape.circle], the padding + /// does not take into account that the circle is drawn in the center of the + /// box regardless of the ratio of the box; it does not provide the extra + /// padding that is implied by changing the ratio. + /// + /// The value returned by this getter must be resolved (using + /// [EdgeInsetsGeometry.resolve] to obtain an absolute [EdgeInsets]. (For + /// example, [BorderDirectional] will return an [EdgeInsetsDirectional] for + /// its [padding].) + EdgeInsetsGeometry get padding => EdgeInsets.zero; + + /// Whether this decoration is complex enough to benefit from caching its painting. + bool get isComplex => false; + + /// Linearly interpolates from another [Decoration] (which may be of a + /// different class) to `this`. + /// + /// When implementing this method in subclasses, return null if this class + /// cannot interpolate from `a`. In that case, [lerp] will try `a`'s [lerpTo] + /// method instead. Classes should implement both [lerpFrom] and [lerpTo]. + /// + /// Supporting interpolating from null is recommended as the [Decoration.lerp] + /// method uses this as a fallback when two classes can't interpolate between + /// each other. + /// + /// The `t` argument represents position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `a` (or something + /// equivalent to `a`), 1.0 meaning that the interpolation has finished, + /// returning `this` (or something equivalent to `this`), and values in + /// between meaning that the interpolation is at the relevant point on the + /// timeline between `a` and `this`. The interpolation can be extrapolated + /// beyond 0.0 and 1.0, so negative values and values greater than 1.0 are + /// valid (and can easily be generated by curves such as + /// [Curves.elasticInOut]). + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + /// + /// Instead of calling this directly, use [Decoration.lerp]. + @protected + Decoration? lerpFrom(Decoration? a, double t) => null; + + /// Linearly interpolates from `this` to another [Decoration] (which may be of + /// a different class). + /// + /// This is called if `b`'s [lerpFrom] did not know how to handle this class. + /// + /// When implementing this method in subclasses, return null if this class + /// cannot interpolate from `b`. In that case, [lerp] will apply a default + /// behavior instead. Classes should implement both [lerpFrom] and [lerpTo]. + /// + /// Supporting interpolating to null is recommended as the [Decoration.lerp] + /// method uses this as a fallback when two classes can't interpolate between + /// each other. + /// + /// The `t` argument represents position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `this` (or something + /// equivalent to `this`), 1.0 meaning that the interpolation has finished, + /// returning `b` (or something equivalent to `b`), and values in between + /// meaning that the interpolation is at the relevant point on the timeline + /// between `this` and `b`. The interpolation can be extrapolated beyond 0.0 + /// and 1.0, so negative values and values greater than 1.0 are valid (and can + /// easily be generated by curves such as [Curves.elasticInOut]). + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + /// + /// Instead of calling this directly, use [Decoration.lerp]. + @protected + Decoration? lerpTo(Decoration? b, double t) => null; + + /// Linearly interpolates between two [Decoration]s. + /// + /// This attempts to use [lerpFrom] and [lerpTo] on `b` and `a` + /// respectively to find a solution. If the two values can't directly be + /// interpolated, then the interpolation is done via null (at `t == 0.5`). + /// + /// {@macro dart.ui.shadow.lerp} + static Decoration? lerp(Decoration? a, Decoration? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!.lerpFrom(null, t) ?? b; + } + if (b == null) { + return a.lerpTo(null, t) ?? a; + } + if (t == 0.0) { + return a; + } + if (t == 1.0) { + return b; + } + return b.lerpFrom(a, t) + ?? a.lerpTo(b, t) + ?? (t < 0.5 ? (a.lerpTo(null, t * 2.0) ?? a) : (b.lerpFrom(null, (t - 0.5) * 2.0) ?? b)); + } + + /// Tests whether the given point, on a rectangle of a given size, + /// would be considered to hit the decoration or not. For example, + /// if the decoration only draws a circle, this function might + /// return true if the point was inside the circle and false + /// otherwise. + /// + /// The decoration may be sensitive to the [TextDirection]. The + /// `textDirection` argument should therefore be provided. If it is known that + /// the decoration is not affected by the text direction, then the argument + /// may be omitted or set to null. + /// + /// When a [Decoration] is painted in a [Container] or [DecoratedBox] (which + /// is what [Container] uses), the `textDirection` parameter will be populated + /// based on the ambient [Directionality] (by way of the [RenderDecoratedBox] + /// renderer). + bool hitTest(Size size, Offset position, { TextDirection? textDirection }) => true; + + /// Returns a [BoxPainter] that will paint this decoration. + /// + /// The `onChanged` argument configures [BoxPainter.onChanged]. It can be + /// omitted if there is no chance that the painter will change (for example, + /// if it is a [BoxDecoration] with definitely no [DecorationImage]). + @factory + BoxPainter createBoxPainter([ VoidCallback onChanged ]); + + /// Returns a closed [Path] that describes the outer edge of this decoration. + /// + /// The default implementation throws. Subclasses must override this implementation + /// to describe the clip path that should be applied to the decoration when it is + /// used in a [Container] with an explicit [Clip] behavior. + /// + /// See also: + /// + /// * [Container.clipBehavior], which, if set, uses this method to determine + /// the clip path to use. + Path getClipPath(Rect rect, TextDirection textDirection) { + throw UnsupportedError('${objectRuntimeType(this, 'This Decoration subclass')} does not expect to be used for clipping.'); + } +} + +/// A stateful class that can paint a particular [Decoration]. +/// +/// [BoxPainter] objects can cache resources so that they can be used +/// multiple times. +/// +/// Some resources used by [BoxPainter] may load asynchronously. When this +/// happens, the [onChanged] callback will be invoked. To stop this callback +/// from being called after the painter has been discarded, call [dispose]. +abstract class BoxPainter { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const BoxPainter([this.onChanged]); + + /// Paints the [Decoration] for which this object was created on the + /// given canvas using the given configuration. + /// + /// The [ImageConfiguration] object passed as the third argument must, at a + /// minimum, have a non-null [Size]. + /// + /// If this object caches resources for painting (e.g. [Paint] objects), the + /// cache may be flushed when [paint] is called with a new configuration. For + /// this reason, it may be more efficient to call + /// [Decoration.createBoxPainter] for each different rectangle that is being + /// painted in a particular frame. + /// + /// For example, if a decoration's owner wants to paint a particular + /// decoration once for its whole size, and once just in the bottom + /// right, it might get two [BoxPainter] instances, one for each. + /// However, when its size changes, it could continue using those + /// same instances, since the previous resources would no longer be + /// relevant and thus losing them would not be an issue. + /// + /// Implementations should paint their decorations on the canvas in a + /// rectangle whose top left corner is at the given `offset` and whose size is + /// given by `configuration.size`. + /// + /// When a [Decoration] is painted in a [Container] or [DecoratedBox] (which + /// is what [Container] uses), the [ImageConfiguration.textDirection] property + /// will be populated based on the ambient [Directionality]. + void paint(Canvas canvas, Offset offset, ImageConfiguration configuration); + + /// Callback that is invoked if an asynchronously-loading resource used by the + /// decoration finishes loading. For example, an image. When this is invoked, + /// the [paint] method should be called again. + /// + /// Resources might not start to load until after [paint] has been called, + /// because they might depend on the configuration. + final VoidCallback? onChanged; + + /// Discard any resources being held by the object. + /// + /// The [onChanged] callback will not be invoked after this method has been + /// called. + @mustCallSuper + void dispose() { } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/decoration_image.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/decoration_image.dart new file mode 100644 index 0000000000000000000000000000000000000000..eb9f7656794771a3ce428bb9dac345b52e75f0b2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/decoration_image.dart @@ -0,0 +1,828 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:developer' as developer; +import 'dart:math' as math; +import 'dart:ui' as ui show FlutterView, Image; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; + +import 'alignment.dart'; +import 'basic_types.dart'; +import 'binding.dart'; +import 'borders.dart'; +import 'box_fit.dart'; +import 'debug.dart'; +import 'image_provider.dart'; +import 'image_stream.dart'; + +/// How to paint any portions of a box not covered by an image. +enum ImageRepeat { + /// Repeat the image in both the x and y directions until the box is filled. + repeat, + + /// Repeat the image in the x direction until the box is filled horizontally. + repeatX, + + /// Repeat the image in the y direction until the box is filled vertically. + repeatY, + + /// Leave uncovered portions of the box transparent. + noRepeat, +} + +/// An image for a box decoration. +/// +/// The image is painted using [paintImage], which describes the meanings of the +/// various fields on this class in more detail. +@immutable +class DecorationImage { + /// Creates an image to show in a [BoxDecoration]. + const DecorationImage({ + required this.image, + this.onError, + this.colorFilter, + this.fit, + this.alignment = Alignment.center, + this.centerSlice, + this.repeat = ImageRepeat.noRepeat, + this.matchTextDirection = false, + this.scale = 1.0, + this.opacity = 1.0, + this.filterQuality = FilterQuality.low, + this.invertColors = false, + this.isAntiAlias = false, + }); + + /// The image to be painted into the decoration. + /// + /// Typically this will be an [AssetImage] (for an image shipped with the + /// application) or a [NetworkImage] (for an image obtained from the network). + final ImageProvider image; + + /// An optional error callback for errors emitted when loading [image]. + final ImageErrorListener? onError; + + /// A color filter to apply to the image before painting it. + final ColorFilter? colorFilter; + + /// How the image should be inscribed into the box. + /// + /// The default is [BoxFit.scaleDown] if [centerSlice] is null, and + /// [BoxFit.fill] if [centerSlice] is not null. + /// + /// See the discussion at [paintImage] for more details. + final BoxFit? fit; + + /// How to align the image within its bounds. + /// + /// The alignment aligns the given position in the image to the given position + /// in the layout bounds. For example, an [Alignment] alignment of (-1.0, + /// -1.0) aligns the image to the top-left corner of its layout bounds, while a + /// [Alignment] alignment of (1.0, 1.0) aligns the bottom right of the + /// image with the bottom right corner of its layout bounds. Similarly, an + /// alignment of (0.0, 1.0) aligns the bottom middle of the image with the + /// middle of the bottom edge of its layout bounds. + /// + /// To display a subpart of an image, consider using a [CustomPainter] and + /// [Canvas.drawImageRect]. + /// + /// If the [alignment] is [TextDirection]-dependent (i.e. if it is a + /// [AlignmentDirectional]), then a [TextDirection] must be available + /// when the image is painted. + /// + /// Defaults to [Alignment.center]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// The center slice for a nine-patch image. + /// + /// The region of the image inside the center slice will be stretched both + /// horizontally and vertically to fit the image into its destination. The + /// region of the image above and below the center slice will be stretched + /// only horizontally and the region of the image to the left and right of + /// the center slice will be stretched only vertically. + /// + /// The stretching will be applied in order to make the image fit into the box + /// specified by [fit]. When [centerSlice] is not null, [fit] defaults to + /// [BoxFit.fill], which distorts the destination image size relative to the + /// image's original aspect ratio. Values of [BoxFit] which do not distort the + /// destination image size will result in [centerSlice] having no effect + /// (since the nine regions of the image will be rendered with the same + /// scaling, as if it wasn't specified). + final Rect? centerSlice; + + /// How to paint any portions of the box that would not otherwise be covered + /// by the image. + final ImageRepeat repeat; + + /// Whether to paint the image in the direction of the [TextDirection]. + /// + /// If this is true, then in [TextDirection.ltr] contexts, the image will be + /// drawn with its origin in the top left (the "normal" painting direction for + /// images); and in [TextDirection.rtl] contexts, the image will be drawn with + /// a scaling factor of -1 in the horizontal direction so that the origin is + /// in the top right. + final bool matchTextDirection; + + /// Defines image pixels to be shown per logical pixels. + /// + /// By default the value of scale is 1.0. The scale for the image is + /// calculated by multiplying [scale] with [scale] of the given [ImageProvider]. + final double scale; + + /// If non-null, the value is multiplied with the opacity of each image + /// pixel before painting onto the canvas. + /// + /// This is more efficient than using [Opacity] or [FadeTransition] to + /// change the opacity of an image. + final double opacity; + + /// Used to set the filterQuality of the image. + /// + /// Defaults to [FilterQuality.low] to scale the image, which corresponds to + /// bilinear interpolation. + final FilterQuality filterQuality; + + /// Whether the colors of the image are inverted when drawn. + /// + /// Inverting the colors of an image applies a new color filter to the paint. + /// If there is another specified color filter, the invert will be applied + /// after it. This is primarily used for implementing smart invert on iOS. + /// + /// See also: + /// + /// * [Paint.invertColors], for the dart:ui implementation. + final bool invertColors; + + /// Whether to paint the image with anti-aliasing. + /// + /// Anti-aliasing alleviates the sawtooth artifact when the image is rotated. + final bool isAntiAlias; + + /// Creates a [DecorationImagePainter] for this [DecorationImage]. + /// + /// The `onChanged` argument will be called whenever the image needs to be + /// repainted, e.g. because it is loading incrementally or because it is + /// animated. + DecorationImagePainter createPainter(VoidCallback onChanged) { + return _DecorationImagePainter._(this, onChanged); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is DecorationImage + && other.image == image + && other.colorFilter == colorFilter + && other.fit == fit + && other.alignment == alignment + && other.centerSlice == centerSlice + && other.repeat == repeat + && other.matchTextDirection == matchTextDirection + && other.scale == scale + && other.opacity == opacity + && other.filterQuality == filterQuality + && other.invertColors == invertColors + && other.isAntiAlias == isAntiAlias; + } + + @override + int get hashCode => Object.hash( + image, + colorFilter, + fit, + alignment, + centerSlice, + repeat, + matchTextDirection, + scale, + opacity, + filterQuality, + invertColors, + isAntiAlias, + ); + + @override + String toString() { + final List<String> properties = <String>[ + '$image', + if (colorFilter != null) + '$colorFilter', + if (fit != null && + !(fit == BoxFit.fill && centerSlice != null) && + !(fit == BoxFit.scaleDown && centerSlice == null)) + '$fit', + '$alignment', + if (centerSlice != null) + 'centerSlice: $centerSlice', + if (repeat != ImageRepeat.noRepeat) + '$repeat', + if (matchTextDirection) + 'match text direction', + 'scale ${scale.toStringAsFixed(1)}', + 'opacity ${opacity.toStringAsFixed(1)}', + '$filterQuality', + if (invertColors) + 'invert colors', + if (isAntiAlias) + 'use anti-aliasing', + ]; + return '${objectRuntimeType(this, 'DecorationImage')}(${properties.join(", ")})'; + } + + /// Linearly interpolates between two [DecorationImage]s. + /// + /// The `t` argument represents position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `a`, 1.0 meaning that + /// the interpolation has finished, returning `b`, and values in between + /// meaning that the interpolation is at the relevant point on the timeline + /// between `a` and `this`. The interpolation can be extrapolated beyond 0.0 + /// and 1.0, so negative values and values greater than 1.0 are valid (and can + /// easily be generated by curves such as [Curves.elasticInOut]). + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + static DecorationImage? lerp(DecorationImage? a, DecorationImage? b, double t) { + if (identical(a, b) || t == 0.0) { + return a; + } + if (t == 1.0) { + return b; + } + return _BlendedDecorationImage(a, b, t); + } +} + +/// The painter for a [DecorationImage]. +/// +/// To obtain a painter, call [DecorationImage.createPainter]. +/// +/// To paint, call [paint]. The `onChanged` callback passed to +/// [DecorationImage.createPainter] will be called if the image needs to paint +/// again (e.g. because it is animated or because it had not yet loaded the +/// first time the [paint] method was called). +/// +/// This object should be disposed using the [dispose] method when it is no +/// longer needed. +abstract interface class DecorationImagePainter { + /// Draw the image onto the given canvas. + /// + /// The image is drawn at the position and size given by the `rect` argument. + /// + /// The image is clipped to the given `clipPath`, if any. + /// + /// The `configuration` object is used to resolve the image (e.g. to pick + /// resolution-specific assets), and to implement the + /// [DecorationImage.matchTextDirection] feature. + /// + /// If the image needs to be painted again, e.g. because it is animated or + /// because it had not yet been loaded the first time this method was called, + /// then the `onChanged` callback passed to [DecorationImage.createPainter] + /// will be called. + /// + /// The `blend` argument specifies the opacity that should be applied to the + /// image due to this image being blended with another. The `blendMode` + /// argument can be specified to override the [DecorationImagePainter]'s + /// default [BlendMode] behavior. It is usually set to [BlendMode.srcOver] if + /// this is the first or only image being blended, and [BlendMode.plus] if it + /// is being blended with an image below. + void paint(Canvas canvas, Rect rect, Path? clipPath, ImageConfiguration configuration, { double blend = 1.0, BlendMode blendMode = BlendMode.srcOver }); + + /// Releases the resources used by this painter. + /// + /// This should be called whenever the painter is no longer needed. + /// + /// After this method has been called, the object is no longer usable. + void dispose(); +} + +class _DecorationImagePainter implements DecorationImagePainter { + _DecorationImagePainter._(this._details, this._onChanged); + + final DecorationImage _details; + final VoidCallback _onChanged; + + ImageStream? _imageStream; + ImageInfo? _image; + + @override + void paint(Canvas canvas, Rect rect, Path? clipPath, ImageConfiguration configuration, { double blend = 1.0, BlendMode blendMode = BlendMode.srcOver }) { + bool flipHorizontally = false; + if (_details.matchTextDirection) { + assert(() { + // We check this first so that the assert will fire immediately, not just + // when the image is ready. + if (configuration.textDirection == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('DecorationImage.matchTextDirection can only be used when a TextDirection is available.'), + ErrorDescription( + 'When DecorationImagePainter.paint() was called, there was no text direction provided ' + 'in the ImageConfiguration object to match.', + ), + DiagnosticsProperty<DecorationImage>('The DecorationImage was', _details, style: DiagnosticsTreeStyle.errorProperty), + DiagnosticsProperty<ImageConfiguration>('The ImageConfiguration was', configuration, style: DiagnosticsTreeStyle.errorProperty), + ]); + } + return true; + }()); + if (configuration.textDirection == TextDirection.rtl) { + flipHorizontally = true; + } + } + + final ImageStream newImageStream = _details.image.resolve(configuration); + if (newImageStream.key != _imageStream?.key) { + final ImageStreamListener listener = ImageStreamListener( + _handleImage, + onError: _details.onError, + ); + _imageStream?.removeListener(listener); + _imageStream = newImageStream; + _imageStream!.addListener(listener); + } + if (_image == null) { + return; + } + + if (clipPath != null) { + canvas.save(); + canvas.clipPath(clipPath); + } + + paintImage( + canvas: canvas, + rect: rect, + image: _image!.image, + debugImageLabel: _image!.debugLabel, + scale: _details.scale * _image!.scale, + colorFilter: _details.colorFilter, + fit: _details.fit, + alignment: _details.alignment.resolve(configuration.textDirection), + centerSlice: _details.centerSlice, + repeat: _details.repeat, + flipHorizontally: flipHorizontally, + opacity: _details.opacity * blend, + filterQuality: _details.filterQuality, + invertColors: _details.invertColors, + isAntiAlias: _details.isAntiAlias, + blendMode: blendMode, + ); + + if (clipPath != null) { + canvas.restore(); + } + } + + void _handleImage(ImageInfo value, bool synchronousCall) { + if (_image == value) { + return; + } + if (_image != null && _image!.isCloneOf(value)) { + value.dispose(); + return; + } + _image?.dispose(); + _image = value; + if (!synchronousCall) { + _onChanged(); + } + } + + @override + void dispose() { + _imageStream?.removeListener(ImageStreamListener( + _handleImage, + onError: _details.onError, + )); + _image?.dispose(); + _image = null; + } + + @override + String toString() { + return '${objectRuntimeType(this, 'DecorationImagePainter')}(stream: $_imageStream, image: $_image) for $_details'; + } +} + +/// Used by [paintImage] to report image sizes drawn at the end of the frame. +Map<String, ImageSizeInfo> _pendingImageSizeInfo = <String, ImageSizeInfo>{}; + +/// [ImageSizeInfo]s that were reported on the last frame. +/// +/// Used to prevent duplicative reports from frame to frame. +Set<ImageSizeInfo> _lastFrameImageSizeInfo = <ImageSizeInfo>{}; + +/// Flushes inter-frame tracking of image size information from [paintImage]. +/// +/// Has no effect if asserts are disabled. +@visibleForTesting +void debugFlushLastFrameImageSizeInfo() { + assert(() { + _lastFrameImageSizeInfo = <ImageSizeInfo>{}; + return true; + }()); +} + +/// Paints an image into the given rectangle on the canvas. +/// +/// The arguments have the following meanings: +/// +/// * `canvas`: The canvas onto which the image will be painted. +/// +/// * `rect`: The region of the canvas into which the image will be painted. +/// The image might not fill the entire rectangle (e.g., depending on the +/// `fit`). If `rect` is empty, nothing is painted. +/// +/// * `image`: The image to paint onto the canvas. +/// +/// * `scale`: The number of image pixels for each logical pixel. +/// +/// * `opacity`: The opacity to paint the image onto the canvas with. +/// +/// * `colorFilter`: If non-null, the color filter to apply when painting the +/// image. +/// +/// * `fit`: How the image should be inscribed into `rect`. If null, the +/// default behavior depends on `centerSlice`. If `centerSlice` is also null, +/// the default behavior is [BoxFit.scaleDown]. If `centerSlice` is +/// non-null, the default behavior is [BoxFit.fill]. See [BoxFit] for +/// details. +/// +/// * `alignment`: How the destination rectangle defined by applying `fit` is +/// aligned within `rect`. For example, if `fit` is [BoxFit.contain] and +/// `alignment` is [Alignment.bottomRight], the image will be as large +/// as possible within `rect` and placed with its bottom right corner at the +/// bottom right corner of `rect`. Defaults to [Alignment.center]. +/// +/// * `centerSlice`: The image is drawn in nine portions described by splitting +/// the image by drawing two horizontal lines and two vertical lines, where +/// `centerSlice` describes the rectangle formed by the four points where +/// these four lines intersect each other. (This forms a 3-by-3 grid +/// of regions, the center region being described by `centerSlice`.) +/// The four regions in the corners are drawn, without scaling, in the four +/// corners of the destination rectangle defined by applying `fit`. The +/// remaining five regions are drawn by stretching them to fit such that they +/// exactly cover the destination rectangle while maintaining their relative +/// positions. See also [Canvas.drawImageNine]. +/// +/// * `repeat`: If the image does not fill `rect`, whether and how the image +/// should be repeated to fill `rect`. By default, the image is not repeated. +/// See [ImageRepeat] for details. +/// +/// * `flipHorizontally`: Whether to flip the image horizontally. This is +/// occasionally used with images in right-to-left environments, for images +/// that were designed for left-to-right locales (or vice versa). Be careful, +/// when using this, to not flip images with integral shadows, text, or other +/// effects that will look incorrect when flipped. +/// +/// * `invertColors`: Inverting the colors of an image applies a new color +/// filter to the paint. If there is another specified color filter, the +/// invert will be applied after it. This is primarily used for implementing +/// smart invert on iOS. +/// +/// * `filterQuality`: Use this to change the quality when scaling an image. +/// Use the [FilterQuality.low] quality setting to scale the image, which corresponds to +/// bilinear interpolation, rather than the default [FilterQuality.none] which corresponds +/// to nearest-neighbor. +/// +/// See also: +/// +/// * [paintBorder], which paints a border around a rectangle on a canvas. +/// * [DecorationImage], which holds a configuration for calling this function. +/// * [BoxDecoration], which uses this function to paint a [DecorationImage]. +void paintImage({ + required Canvas canvas, + required Rect rect, + required ui.Image image, + String? debugImageLabel, + double scale = 1.0, + double opacity = 1.0, + ColorFilter? colorFilter, + BoxFit? fit, + Alignment alignment = Alignment.center, + Rect? centerSlice, + ImageRepeat repeat = ImageRepeat.noRepeat, + bool flipHorizontally = false, + bool invertColors = false, + FilterQuality filterQuality = FilterQuality.low, + bool isAntiAlias = false, + BlendMode blendMode = BlendMode.srcOver, +}) { + assert( + image.debugGetOpenHandleStackTraces()?.isNotEmpty ?? true, + 'Cannot paint an image that is disposed.\n' + 'The caller of paintImage is expected to wait to dispose the image until ' + 'after painting has completed.', + ); + if (rect.isEmpty) { + return; + } + Size outputSize = rect.size; + Size inputSize = Size(image.width.toDouble(), image.height.toDouble()); + Offset? sliceBorder; + if (centerSlice != null) { + sliceBorder = inputSize / scale - centerSlice.size as Offset; + outputSize = outputSize - sliceBorder as Size; + inputSize = inputSize - sliceBorder * scale as Size; + } + fit ??= centerSlice == null ? BoxFit.scaleDown : BoxFit.fill; + assert(centerSlice == null || (fit != BoxFit.none && fit != BoxFit.cover)); + final FittedSizes fittedSizes = applyBoxFit(fit, inputSize / scale, outputSize); + final Size sourceSize = fittedSizes.source * scale; + Size destinationSize = fittedSizes.destination; + if (centerSlice != null) { + outputSize += sliceBorder!; + destinationSize += sliceBorder; + // We don't have the ability to draw a subset of the image at the same time + // as we apply a nine-patch stretch. + assert(sourceSize == inputSize, 'centerSlice was used with a BoxFit that does not guarantee that the image is fully visible.'); + } + + if (repeat != ImageRepeat.noRepeat && destinationSize == outputSize) { + // There's no need to repeat the image because we're exactly filling the + // output rect with the image. + repeat = ImageRepeat.noRepeat; + } + final Paint paint = Paint()..isAntiAlias = isAntiAlias; + if (colorFilter != null) { + paint.colorFilter = colorFilter; + } + paint.color = Color.fromRGBO(0, 0, 0, clampDouble(opacity, 0.0, 1.0)); + paint.filterQuality = filterQuality; + paint.invertColors = invertColors; + paint.blendMode = blendMode; + final double halfWidthDelta = (outputSize.width - destinationSize.width) / 2.0; + final double halfHeightDelta = (outputSize.height - destinationSize.height) / 2.0; + final double dx = halfWidthDelta + (flipHorizontally ? -alignment.x : alignment.x) * halfWidthDelta; + final double dy = halfHeightDelta + alignment.y * halfHeightDelta; + final Offset destinationPosition = rect.topLeft.translate(dx, dy); + final Rect destinationRect = destinationPosition & destinationSize; + + // Set to true if we added a saveLayer to the canvas to invert/flip the image. + bool invertedCanvas = false; + // Output size and destination rect are fully calculated. + + // Implement debug-mode and profile-mode features: + // - cacheWidth/cacheHeight warning + // - debugInvertOversizedImages + // - debugOnPaintImage + // - Flutter.ImageSizesForFrame events in timeline + if (!kReleaseMode) { + // We can use the devicePixelRatio of the views directly here (instead of + // going through a MediaQuery) because if it changes, whatever is aware of + // the MediaQuery will be repainting the image anyways. + // Furthermore, for the memory check below we just assume that all images + // are decoded for the view with the highest device pixel ratio and use that + // as an upper bound for the display size of the image. + final double maxDevicePixelRatio = PaintingBinding.instance.platformDispatcher.views.fold( + 0.0, + (double previousValue, ui.FlutterView view) => math.max(previousValue, view.devicePixelRatio), + ); + final ImageSizeInfo sizeInfo = ImageSizeInfo( + // Some ImageProvider implementations may not have given this. + source: debugImageLabel ?? '<Unknown Image(${image.width}×${image.height})>', + imageSize: Size(image.width.toDouble(), image.height.toDouble()), + displaySize: outputSize * maxDevicePixelRatio, + ); + assert(() { + if (debugInvertOversizedImages && + sizeInfo.decodedSizeInBytes > sizeInfo.displaySizeInBytes + debugImageOverheadAllowance) { + final int overheadInKilobytes = (sizeInfo.decodedSizeInBytes - sizeInfo.displaySizeInBytes) ~/ 1024; + final int outputWidth = sizeInfo.displaySize.width.toInt(); + final int outputHeight = sizeInfo.displaySize.height.toInt(); + FlutterError.reportError(FlutterErrorDetails( + exception: 'Image $debugImageLabel has a display size of ' + '$outputWidth×$outputHeight but a decode size of ' + '${image.width}×${image.height}, which uses an additional ' + '${overheadInKilobytes}KB (assuming a device pixel ratio of ' + '$maxDevicePixelRatio).\n\n' + 'Consider resizing the asset ahead of time, supplying a cacheWidth ' + 'parameter of $outputWidth, a cacheHeight parameter of ' + '$outputHeight, or using a ResizeImage.', + library: 'painting library', + context: ErrorDescription('while painting an image'), + )); + // Invert the colors of the canvas. + canvas.saveLayer( + destinationRect, + Paint()..colorFilter = const ColorFilter.matrix(<double>[ + -1, 0, 0, 0, 255, + 0, -1, 0, 0, 255, + 0, 0, -1, 0, 255, + 0, 0, 0, 1, 0, + ]), + ); + // Flip the canvas vertically. + final double dy = -(rect.top + rect.height / 2.0); + canvas.translate(0.0, -dy); + canvas.scale(1.0, -1.0); + canvas.translate(0.0, dy); + invertedCanvas = true; + } + return true; + }()); + // Avoid emitting events that are the same as those emitted in the last frame. + if (!_lastFrameImageSizeInfo.contains(sizeInfo)) { + final ImageSizeInfo? existingSizeInfo = _pendingImageSizeInfo[sizeInfo.source]; + if (existingSizeInfo == null || existingSizeInfo.displaySizeInBytes < sizeInfo.displaySizeInBytes) { + _pendingImageSizeInfo[sizeInfo.source!] = sizeInfo; + } + debugOnPaintImage?.call(sizeInfo); + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + _lastFrameImageSizeInfo = _pendingImageSizeInfo.values.toSet(); + if (_pendingImageSizeInfo.isEmpty) { + return; + } + developer.postEvent( + 'Flutter.ImageSizesForFrame', + <String, Object>{ + for (final ImageSizeInfo imageSizeInfo in _pendingImageSizeInfo.values) + imageSizeInfo.source!: imageSizeInfo.toJson(), + }, + ); + _pendingImageSizeInfo = <String, ImageSizeInfo>{}; + }, debugLabel: 'paintImage.recordImageSizes'); + } + } + + final bool needSave = centerSlice != null || repeat != ImageRepeat.noRepeat || flipHorizontally; + if (needSave) { + canvas.save(); + } + if (repeat != ImageRepeat.noRepeat) { + canvas.clipRect(rect); + } + if (flipHorizontally) { + final double dx = -(rect.left + rect.width / 2.0); + canvas.translate(-dx, 0.0); + canvas.scale(-1.0, 1.0); + canvas.translate(dx, 0.0); + } + if (centerSlice == null) { + final Rect sourceRect = alignment.inscribe( + sourceSize, Offset.zero & inputSize, + ); + if (repeat == ImageRepeat.noRepeat) { + canvas.drawImageRect(image, sourceRect, destinationRect, paint); + } else { + for (final Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat)) { + canvas.drawImageRect(image, sourceRect, tileRect, paint); + } + } + } else { + canvas.scale(1 / scale); + if (repeat == ImageRepeat.noRepeat) { + canvas.drawImageNine(image, _scaleRect(centerSlice, scale), _scaleRect(destinationRect, scale), paint); + } else { + for (final Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat)) { + canvas.drawImageNine(image, _scaleRect(centerSlice, scale), _scaleRect(tileRect, scale), paint); + } + } + } + if (needSave) { + canvas.restore(); + } + + if (invertedCanvas) { + canvas.restore(); + } +} + +Iterable<Rect> _generateImageTileRects(Rect outputRect, Rect fundamentalRect, ImageRepeat repeat) { + int startX = 0; + int startY = 0; + int stopX = 0; + int stopY = 0; + final double strideX = fundamentalRect.width; + final double strideY = fundamentalRect.height; + + if (repeat == ImageRepeat.repeat || repeat == ImageRepeat.repeatX) { + startX = ((outputRect.left - fundamentalRect.left) / strideX).floor(); + stopX = ((outputRect.right - fundamentalRect.right) / strideX).ceil(); + } + + if (repeat == ImageRepeat.repeat || repeat == ImageRepeat.repeatY) { + startY = ((outputRect.top - fundamentalRect.top) / strideY).floor(); + stopY = ((outputRect.bottom - fundamentalRect.bottom) / strideY).ceil(); + } + + return <Rect>[ + for (int i = startX; i <= stopX; ++i) + for (int j = startY; j <= stopY; ++j) + fundamentalRect.shift(Offset(i * strideX, j * strideY)), + ]; +} + +Rect _scaleRect(Rect rect, double scale) => Rect.fromLTRB(rect.left * scale, rect.top * scale, rect.right * scale, rect.bottom * scale); + +// Implements DecorationImage.lerp when the image is different. +// +// This class just paints both decorations on top of each other, blended together. +// +// The Decoration properties are faked by just forwarded to the target image. +class _BlendedDecorationImage implements DecorationImage { + const _BlendedDecorationImage(this.a, this.b, this.t) : assert(a != null || b != null); + + final DecorationImage? a; + final DecorationImage? b; + final double t; + + @override + ImageProvider get image => b?.image ?? a!.image; + @override + ImageErrorListener? get onError => b?.onError ?? a!.onError; + @override + ColorFilter? get colorFilter => b?.colorFilter ?? a!.colorFilter; + @override + BoxFit? get fit => b?.fit ?? a!.fit; + @override + AlignmentGeometry get alignment => b?.alignment ?? a!.alignment; + @override + Rect? get centerSlice => b?.centerSlice ?? a!.centerSlice; + @override + ImageRepeat get repeat => b?.repeat ?? a!.repeat; + @override + bool get matchTextDirection => b?.matchTextDirection ?? a!.matchTextDirection; + @override + double get scale => b?.scale ?? a!.scale; + @override + double get opacity => b?.opacity ?? a!.opacity; + @override + FilterQuality get filterQuality => b?.filterQuality ?? a!.filterQuality; + @override + bool get invertColors => b?.invertColors ?? a!.invertColors; + @override + bool get isAntiAlias => b?.isAntiAlias ?? a!.isAntiAlias; + + @override + DecorationImagePainter createPainter(VoidCallback onChanged) { + return _BlendedDecorationImagePainter._( + a?.createPainter(onChanged), + b?.createPainter(onChanged), + t, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is _BlendedDecorationImage + && other.a == a + && other.b == b + && other.t == t; + } + + @override + int get hashCode => Object.hash(a, b, t); + + @override + String toString() { + return '${objectRuntimeType(this, '_BlendedDecorationImage')}($a, $b, $t)'; + } +} + +class _BlendedDecorationImagePainter implements DecorationImagePainter { + _BlendedDecorationImagePainter._(this.a, this.b, this.t); + + final DecorationImagePainter? a; + final DecorationImagePainter? b; + final double t; + + @override + void paint(Canvas canvas, Rect rect, Path? clipPath, ImageConfiguration configuration, { double blend = 1.0, BlendMode blendMode = BlendMode.srcOver }) { + canvas.saveLayer(null, Paint()); + a?.paint(canvas, rect, clipPath, configuration, blend: blend * (1.0 - t), blendMode: blendMode); + b?.paint(canvas, rect, clipPath, configuration, blend: blend * t, blendMode: a != null ? BlendMode.plus : blendMode); + canvas.restore(); + } + + @override + void dispose() { + a?.dispose(); + b?.dispose(); + } + + @override + String toString() { + return '${objectRuntimeType(this, '_BlendedDecorationImagePainter')}($a, $b, $t)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/edge_insets.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/edge_insets.dart new file mode 100644 index 0000000000000000000000000000000000000000..5334913e965bcb55b6a1d51f2417ebf05c9a96a0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/edge_insets.dart @@ -0,0 +1,1026 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show ViewPadding, lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; + +/// Base class for [EdgeInsets] that allows for text-direction aware +/// resolution. +/// +/// A property or argument of this type accepts classes created either with [ +/// EdgeInsets.fromLTRB] and its variants, or [ +/// EdgeInsetsDirectional.fromSTEB] and its variants. +/// +/// To convert an [EdgeInsetsGeometry] object of indeterminate type into a +/// [EdgeInsets] object, call the [resolve] method. +/// +/// See also: +/// +/// * [Padding], a widget that describes margins using [EdgeInsetsGeometry]. +@immutable +abstract class EdgeInsetsGeometry { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const EdgeInsetsGeometry(); + + double get _bottom; + double get _end; + double get _left; + double get _right; + double get _start; + double get _top; + + /// An [EdgeInsetsGeometry] with infinite offsets in each direction. + /// + /// Can be used as an infinite upper bound for [clamp]. + static const EdgeInsetsGeometry infinity = _MixedEdgeInsets.fromLRSETB( + double.infinity, + double.infinity, + double.infinity, + double.infinity, + double.infinity, + double.infinity, + ); + + /// Whether every dimension is non-negative. + bool get isNonNegative { + return _left >= 0.0 + && _right >= 0.0 + && _start >= 0.0 + && _end >= 0.0 + && _top >= 0.0 + && _bottom >= 0.0; + } + + /// The total offset in the horizontal direction. + double get horizontal => _left + _right + _start + _end; + + /// The total offset in the vertical direction. + double get vertical => _top + _bottom; + + /// The total offset in the given direction. + double along(Axis axis) { + switch (axis) { + case Axis.horizontal: + return horizontal; + case Axis.vertical: + return vertical; + } + } + + /// The size that this [EdgeInsets] would occupy with an empty interior. + Size get collapsedSize => Size(horizontal, vertical); + + /// An [EdgeInsetsGeometry] with top and bottom, left and right, and start and end flipped. + EdgeInsetsGeometry get flipped => _MixedEdgeInsets.fromLRSETB(_right, _left, _end, _start, _bottom, _top); + + /// Returns a new size that is bigger than the given size by the amount of + /// inset in the horizontal and vertical directions. + /// + /// See also: + /// + /// * [EdgeInsets.inflateRect], to inflate a [Rect] rather than a [Size] (for + /// [EdgeInsetsDirectional], requires first calling [resolve] to establish + /// how the start and end map to the left or right). + /// * [deflateSize], to deflate a [Size] rather than inflating it. + Size inflateSize(Size size) { + return Size(size.width + horizontal, size.height + vertical); + } + + /// Returns a new size that is smaller than the given size by the amount of + /// inset in the horizontal and vertical directions. + /// + /// If the argument is smaller than [collapsedSize], then the resulting size + /// will have negative dimensions. + /// + /// See also: + /// + /// * [EdgeInsets.deflateRect], to deflate a [Rect] rather than a [Size]. (for + /// [EdgeInsetsDirectional], requires first calling [resolve] to establish + /// how the start and end map to the left or right). + /// * [inflateSize], to inflate a [Size] rather than deflating it. + Size deflateSize(Size size) { + return Size(size.width - horizontal, size.height - vertical); + } + + /// Returns the difference between two [EdgeInsetsGeometry] objects. + /// + /// If you know you are applying this to two [EdgeInsets] or two + /// [EdgeInsetsDirectional] objects, consider using the binary infix `-` + /// operator instead, which always returns an object of the same type as the + /// operands, and is typed accordingly. + /// + /// If [subtract] is applied to two objects of the same type ([EdgeInsets] or + /// [EdgeInsetsDirectional]), an object of that type will be returned (though + /// this is not reflected in the type system). Otherwise, an object + /// representing a combination of both is returned. That object can be turned + /// into a concrete [EdgeInsets] using [resolve]. + /// + /// This method returns the same result as [add] applied to the result of + /// negating the argument (using the prefix unary `-` operator or multiplying + /// the argument by -1.0 using the `*` operator). + EdgeInsetsGeometry subtract(EdgeInsetsGeometry other) { + return _MixedEdgeInsets.fromLRSETB( + _left - other._left, + _right - other._right, + _start - other._start, + _end - other._end, + _top - other._top, + _bottom - other._bottom, + ); + } + + /// Returns the sum of two [EdgeInsetsGeometry] objects. + /// + /// If you know you are adding two [EdgeInsets] or two [EdgeInsetsDirectional] + /// objects, consider using the `+` operator instead, which always returns an + /// object of the same type as the operands, and is typed accordingly. + /// + /// If [add] is applied to two objects of the same type ([EdgeInsets] or + /// [EdgeInsetsDirectional]), an object of that type will be returned (though + /// this is not reflected in the type system). Otherwise, an object + /// representing a combination of both is returned. That object can be turned + /// into a concrete [EdgeInsets] using [resolve]. + EdgeInsetsGeometry add(EdgeInsetsGeometry other) { + return _MixedEdgeInsets.fromLRSETB( + _left + other._left, + _right + other._right, + _start + other._start, + _end + other._end, + _top + other._top, + _bottom + other._bottom, + ); + } + + /// Returns a new [EdgeInsetsGeometry] object with all values greater than + /// or equal to `min`, and less than or equal to `max`. + EdgeInsetsGeometry clamp(EdgeInsetsGeometry min, EdgeInsetsGeometry max) { + return _MixedEdgeInsets.fromLRSETB( + clampDouble(_left, min._left, max._left), + clampDouble(_right, min._right, max._right), + clampDouble(_start, min._start, max._start), + clampDouble(_end, min._end, max._end), + clampDouble(_top, min._top, max._top), + clampDouble(_bottom, min._bottom, max._bottom), + ); + } + + /// Returns the [EdgeInsetsGeometry] object with each dimension negated. + /// + /// This is the same as multiplying the object by -1.0. + /// + /// This operator returns an object of the same type as the operand. + EdgeInsetsGeometry operator -(); + + /// Scales the [EdgeInsetsGeometry] object in each dimension by the given factor. + /// + /// This operator returns an object of the same type as the operand. + EdgeInsetsGeometry operator *(double other); + + /// Divides the [EdgeInsetsGeometry] object in each dimension by the given factor. + /// + /// This operator returns an object of the same type as the operand. + EdgeInsetsGeometry operator /(double other); + + /// Integer divides the [EdgeInsetsGeometry] object in each dimension by the given factor. + /// + /// This operator returns an object of the same type as the operand. + /// + /// This operator may have unexpected results when applied to a mixture of + /// [EdgeInsets] and [EdgeInsetsDirectional] objects. + EdgeInsetsGeometry operator ~/(double other); + + /// Computes the remainder in each dimension by the given factor. + /// + /// This operator returns an object of the same type as the operand. + /// + /// This operator may have unexpected results when applied to a mixture of + /// [EdgeInsets] and [EdgeInsetsDirectional] objects. + EdgeInsetsGeometry operator %(double other); + + /// Linearly interpolate between two [EdgeInsetsGeometry] objects. + /// + /// If either is null, this function interpolates from [EdgeInsets.zero], and + /// the result is an object of the same type as the non-null argument. + /// + /// If [lerp] is applied to two objects of the same type ([EdgeInsets] or + /// [EdgeInsetsDirectional]), an object of that type will be returned (though + /// this is not reflected in the type system). Otherwise, an object + /// representing a combination of both is returned. That object can be turned + /// into a concrete [EdgeInsets] using [resolve]. + /// + /// {@macro dart.ui.shadow.lerp} + static EdgeInsetsGeometry? lerp(EdgeInsetsGeometry? a, EdgeInsetsGeometry? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b! * t; + } + if (b == null) { + return a * (1.0 - t); + } + if (a is EdgeInsets && b is EdgeInsets) { + return EdgeInsets.lerp(a, b, t); + } + if (a is EdgeInsetsDirectional && b is EdgeInsetsDirectional) { + return EdgeInsetsDirectional.lerp(a, b, t); + } + return _MixedEdgeInsets.fromLRSETB( + ui.lerpDouble(a._left, b._left, t)!, + ui.lerpDouble(a._right, b._right, t)!, + ui.lerpDouble(a._start, b._start, t)!, + ui.lerpDouble(a._end, b._end, t)!, + ui.lerpDouble(a._top, b._top, t)!, + ui.lerpDouble(a._bottom, b._bottom, t)!, + ); + } + + /// Convert this instance into an [EdgeInsets], which uses literal coordinates + /// (i.e. the `left` coordinate being explicitly a distance from the left, and + /// the `right` coordinate being explicitly a distance from the right). + /// + /// See also: + /// + /// * [EdgeInsets], for which this is a no-op (returns itself). + /// * [EdgeInsetsDirectional], which flips the horizontal direction + /// based on the `direction` argument. + EdgeInsets resolve(TextDirection? direction); + + @override + String toString() { + if (_start == 0.0 && _end == 0.0) { + if (_left == 0.0 && _right == 0.0 && _top == 0.0 && _bottom == 0.0) { + return 'EdgeInsets.zero'; + } + if (_left == _right && _right == _top && _top == _bottom) { + return 'EdgeInsets.all(${_left.toStringAsFixed(1)})'; + } + return 'EdgeInsets(${_left.toStringAsFixed(1)}, ' + '${_top.toStringAsFixed(1)}, ' + '${_right.toStringAsFixed(1)}, ' + '${_bottom.toStringAsFixed(1)})'; + } + if (_left == 0.0 && _right == 0.0) { + return 'EdgeInsetsDirectional(${_start.toStringAsFixed(1)}, ' + '${_top.toStringAsFixed(1)}, ' + '${_end.toStringAsFixed(1)}, ' + '${_bottom.toStringAsFixed(1)})'; + } + return 'EdgeInsets(${_left.toStringAsFixed(1)}, ' + '${_top.toStringAsFixed(1)}, ' + '${_right.toStringAsFixed(1)}, ' + '${_bottom.toStringAsFixed(1)})' + ' + ' + 'EdgeInsetsDirectional(${_start.toStringAsFixed(1)}, ' + '0.0, ' + '${_end.toStringAsFixed(1)}, ' + '0.0)'; + } + + @override + bool operator ==(Object other) { + return other is EdgeInsetsGeometry + && other._left == _left + && other._right == _right + && other._start == _start + && other._end == _end + && other._top == _top + && other._bottom == _bottom; + } + + @override + int get hashCode => Object.hash(_left, _right, _start, _end, _top, _bottom); +} + +/// An immutable set of offsets in each of the four cardinal directions. +/// +/// Typically used for an offset from each of the four sides of a box. For +/// example, the padding inside a box can be represented using this class. +/// +/// The [EdgeInsets] class specifies offsets in terms of visual edges, left, +/// top, right, and bottom. These values are not affected by the +/// [TextDirection]. To support both left-to-right and right-to-left layouts, +/// consider using [EdgeInsetsDirectional], which is expressed in terms of +/// _start_, top, _end_, and bottom, where start and end are resolved in terms +/// of a [TextDirection] (typically obtained from the ambient [Directionality]). +/// +/// {@tool snippet} +/// +/// Here are some examples of how to create [EdgeInsets] instances: +/// +/// Typical eight-pixel margin on all sides: +/// +/// ```dart +/// const EdgeInsets.all(8.0) +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// Eight pixel margin above and below, no horizontal margins: +/// +/// ```dart +/// const EdgeInsets.symmetric(vertical: 8.0) +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// Left margin indent of 40 pixels: +/// +/// ```dart +/// const EdgeInsets.only(left: 40.0) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Padding], a widget that accepts [EdgeInsets] to describe its margins. +/// * [EdgeInsetsDirectional], which (for properties and arguments that accept +/// the type [EdgeInsetsGeometry]) allows the horizontal insets to be +/// specified in a [TextDirection]-aware manner. +class EdgeInsets extends EdgeInsetsGeometry { + /// Creates insets from offsets from the left, top, right, and bottom. + const EdgeInsets.fromLTRB(this.left, this.top, this.right, this.bottom); + + /// Creates insets where all the offsets are `value`. + /// + /// {@tool snippet} + /// + /// Typical eight-pixel margin on all sides: + /// + /// ```dart + /// const EdgeInsets.all(8.0) + /// ``` + /// {@end-tool} + const EdgeInsets.all(double value) + : left = value, + top = value, + right = value, + bottom = value; + + /// Creates insets with only the given values non-zero. + /// + /// {@tool snippet} + /// + /// Left margin indent of 40 pixels: + /// + /// ```dart + /// const EdgeInsets.only(left: 40.0) + /// ``` + /// {@end-tool} + const EdgeInsets.only({ + this.left = 0.0, + this.top = 0.0, + this.right = 0.0, + this.bottom = 0.0, + }); + + /// Creates insets with symmetrical vertical and horizontal offsets. + /// + /// {@tool snippet} + /// + /// Eight pixel margin above and below, no horizontal margins: + /// + /// ```dart + /// const EdgeInsets.symmetric(vertical: 8.0) + /// ``` + /// {@end-tool} + const EdgeInsets.symmetric({ + double vertical = 0.0, + double horizontal = 0.0, + }) : left = horizontal, + top = vertical, + right = horizontal, + bottom = vertical; + + /// Creates insets that match the given view padding. + /// + /// If you need the current system padding or view insets in the context of a + /// widget, consider using [MediaQuery.paddingOf] to obtain these values rather than + /// using the value from a [FlutterView] directly, so that you get notified of + /// changes. + EdgeInsets.fromViewPadding(ui.ViewPadding padding, double devicePixelRatio) + : left = padding.left / devicePixelRatio, + top = padding.top / devicePixelRatio, + right = padding.right / devicePixelRatio, + bottom = padding.bottom / devicePixelRatio; + + /// Deprecated. Will be removed in a future version of Flutter. + /// + /// Use [EdgeInsets.fromViewPadding] instead. + @Deprecated( + 'Use EdgeInsets.fromViewPadding instead. ' + 'This feature was deprecated after v3.8.0-14.0.pre.', + ) + factory EdgeInsets.fromWindowPadding(ui.ViewPadding padding, double devicePixelRatio) = EdgeInsets.fromViewPadding; + + /// An [EdgeInsets] with zero offsets in each direction. + static const EdgeInsets zero = EdgeInsets.only(); + + /// The offset from the left. + final double left; + + @override + double get _left => left; + + /// The offset from the top. + final double top; + + @override + double get _top => top; + + /// The offset from the right. + final double right; + + @override + double get _right => right; + + /// The offset from the bottom. + final double bottom; + + @override + double get _bottom => bottom; + + @override + double get _start => 0.0; + + @override + double get _end => 0.0; + + /// An Offset describing the vector from the top left of a rectangle to the + /// top left of that rectangle inset by this object. + Offset get topLeft => Offset(left, top); + + /// An Offset describing the vector from the top right of a rectangle to the + /// top right of that rectangle inset by this object. + Offset get topRight => Offset(-right, top); + + /// An Offset describing the vector from the bottom left of a rectangle to the + /// bottom left of that rectangle inset by this object. + Offset get bottomLeft => Offset(left, -bottom); + + /// An Offset describing the vector from the bottom right of a rectangle to the + /// bottom right of that rectangle inset by this object. + Offset get bottomRight => Offset(-right, -bottom); + + /// An [EdgeInsets] with top and bottom as well as left and right flipped. + @override + EdgeInsets get flipped => EdgeInsets.fromLTRB(right, bottom, left, top); + + /// Returns a new rect that is bigger than the given rect in each direction by + /// the amount of inset in each direction. Specifically, the left edge of the + /// rect is moved left by [left], the top edge of the rect is moved up by + /// [top], the right edge of the rect is moved right by [right], and the + /// bottom edge of the rect is moved down by [bottom]. + /// + /// See also: + /// + /// * [inflateSize], to inflate a [Size] rather than a [Rect]. + /// * [deflateRect], to deflate a [Rect] rather than inflating it. + Rect inflateRect(Rect rect) { + return Rect.fromLTRB(rect.left - left, rect.top - top, rect.right + right, rect.bottom + bottom); + } + + /// Returns a new rect that is smaller than the given rect in each direction by + /// the amount of inset in each direction. Specifically, the left edge of the + /// rect is moved right by [left], the top edge of the rect is moved down by + /// [top], the right edge of the rect is moved left by [right], and the + /// bottom edge of the rect is moved up by [bottom]. + /// + /// If the argument's [Rect.size] is smaller than [collapsedSize], then the + /// resulting rectangle will have negative dimensions. + /// + /// See also: + /// + /// * [deflateSize], to deflate a [Size] rather than a [Rect]. + /// * [inflateRect], to inflate a [Rect] rather than deflating it. + Rect deflateRect(Rect rect) { + return Rect.fromLTRB(rect.left + left, rect.top + top, rect.right - right, rect.bottom - bottom); + } + + @override + EdgeInsetsGeometry subtract(EdgeInsetsGeometry other) { + if (other is EdgeInsets) { + return this - other; + } + return super.subtract(other); + } + + @override + EdgeInsetsGeometry add(EdgeInsetsGeometry other) { + if (other is EdgeInsets) { + return this + other; + } + return super.add(other); + } + + @override + EdgeInsetsGeometry clamp(EdgeInsetsGeometry min, EdgeInsetsGeometry max) { + return EdgeInsets.fromLTRB( + clampDouble(_left, min._left, max._left), + clampDouble(_top, min._top, max._top), + clampDouble(_right, min._right, max._right), + clampDouble(_bottom, min._bottom, max._bottom), + ); + } + + /// Returns the difference between two [EdgeInsets]. + EdgeInsets operator -(EdgeInsets other) { + return EdgeInsets.fromLTRB( + left - other.left, + top - other.top, + right - other.right, + bottom - other.bottom, + ); + } + + /// Returns the sum of two [EdgeInsets]. + EdgeInsets operator +(EdgeInsets other) { + return EdgeInsets.fromLTRB( + left + other.left, + top + other.top, + right + other.right, + bottom + other.bottom, + ); + } + + /// Returns the [EdgeInsets] object with each dimension negated. + /// + /// This is the same as multiplying the object by -1.0. + @override + EdgeInsets operator -() { + return EdgeInsets.fromLTRB( + -left, + -top, + -right, + -bottom, + ); + } + + /// Scales the [EdgeInsets] in each dimension by the given factor. + @override + EdgeInsets operator *(double other) { + return EdgeInsets.fromLTRB( + left * other, + top * other, + right * other, + bottom * other, + ); + } + + /// Divides the [EdgeInsets] in each dimension by the given factor. + @override + EdgeInsets operator /(double other) { + return EdgeInsets.fromLTRB( + left / other, + top / other, + right / other, + bottom / other, + ); + } + + /// Integer divides the [EdgeInsets] in each dimension by the given factor. + @override + EdgeInsets operator ~/(double other) { + return EdgeInsets.fromLTRB( + (left ~/ other).toDouble(), + (top ~/ other).toDouble(), + (right ~/ other).toDouble(), + (bottom ~/ other).toDouble(), + ); + } + + /// Computes the remainder in each dimension by the given factor. + @override + EdgeInsets operator %(double other) { + return EdgeInsets.fromLTRB( + left % other, + top % other, + right % other, + bottom % other, + ); + } + + /// Linearly interpolate between two [EdgeInsets]. + /// + /// If either is null, this function interpolates from [EdgeInsets.zero]. + /// + /// {@macro dart.ui.shadow.lerp} + static EdgeInsets? lerp(EdgeInsets? a, EdgeInsets? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b! * t; + } + if (b == null) { + return a * (1.0 - t); + } + return EdgeInsets.fromLTRB( + ui.lerpDouble(a.left, b.left, t)!, + ui.lerpDouble(a.top, b.top, t)!, + ui.lerpDouble(a.right, b.right, t)!, + ui.lerpDouble(a.bottom, b.bottom, t)!, + ); + } + + @override + EdgeInsets resolve(TextDirection? direction) => this; + + /// Creates a copy of this EdgeInsets but with the given fields replaced + /// with the new values. + EdgeInsets copyWith({ + double? left, + double? top, + double? right, + double? bottom, + }) { + return EdgeInsets.only( + left: left ?? this.left, + top: top ?? this.top, + right: right ?? this.right, + bottom: bottom ?? this.bottom, + ); + } +} + +/// An immutable set of offsets in each of the four cardinal directions, but +/// whose horizontal components are dependent on the writing direction. +/// +/// This can be used to indicate padding from the left in [TextDirection.ltr] +/// text and padding from the right in [TextDirection.rtl] text without having +/// to be aware of the current text direction. +/// +/// See also: +/// +/// * [EdgeInsets], a variant that uses physical labels (left and right instead +/// of start and end). +class EdgeInsetsDirectional extends EdgeInsetsGeometry { + /// Creates insets from offsets from the start, top, end, and bottom. + const EdgeInsetsDirectional.fromSTEB(this.start, this.top, this.end, this.bottom); + + /// Creates insets with only the given values non-zero. + /// + /// {@tool snippet} + /// + /// A margin indent of 40 pixels on the leading side: + /// + /// ```dart + /// const EdgeInsetsDirectional.only(start: 40.0) + /// ``` + /// {@end-tool} + const EdgeInsetsDirectional.only({ + this.start = 0.0, + this.top = 0.0, + this.end = 0.0, + this.bottom = 0.0, + }); + + /// Creates insets with symmetric vertical and horizontal offsets. + /// + /// This is equivalent to [EdgeInsets.symmetric], since the inset is the same + /// with either [TextDirection]. This constructor is just a convenience for + /// type compatibility. + /// + /// {@tool snippet} + /// Eight pixel margin above and below, no horizontal margins: + /// + /// ```dart + /// const EdgeInsetsDirectional.symmetric(vertical: 8.0) + /// ``` + /// {@end-tool} + const EdgeInsetsDirectional.symmetric({ + double horizontal = 0.0, + double vertical = 0.0, + }) : start = horizontal, + end = horizontal, + top = vertical, + bottom = vertical; + + /// Creates insets where all the offsets are `value`. + /// + /// {@tool snippet} + /// + /// Typical eight-pixel margin on all sides: + /// + /// ```dart + /// const EdgeInsetsDirectional.all(8.0) + /// ``` + /// {@end-tool} + const EdgeInsetsDirectional.all(double value) + : start = value, + top = value, + end = value, + bottom = value; + + /// An [EdgeInsetsDirectional] with zero offsets in each direction. + /// + /// Consider using [EdgeInsets.zero] instead, since that object has the same + /// effect, but will be cheaper to [resolve]. + static const EdgeInsetsDirectional zero = EdgeInsetsDirectional.only(); + + /// The offset from the start side, the side from which the user will start + /// reading text. + /// + /// This value is normalized into an [EdgeInsets.left] or [EdgeInsets.right] + /// value by the [resolve] method. + final double start; + + @override + double get _start => start; + + /// The offset from the top. + /// + /// This value is passed through to [EdgeInsets.top] unmodified by the + /// [resolve] method. + final double top; + + @override + double get _top => top; + + /// The offset from the end side, the side on which the user ends reading + /// text. + /// + /// This value is normalized into an [EdgeInsets.left] or [EdgeInsets.right] + /// value by the [resolve] method. + final double end; + + @override + double get _end => end; + + /// The offset from the bottom. + /// + /// This value is passed through to [EdgeInsets.bottom] unmodified by the + /// [resolve] method. + final double bottom; + + @override + double get _bottom => bottom; + + @override + double get _left => 0.0; + + @override + double get _right => 0.0; + + @override + bool get isNonNegative => start >= 0.0 && top >= 0.0 && end >= 0.0 && bottom >= 0.0; + + /// An [EdgeInsetsDirectional] with [top] and [bottom] as well as [start] and [end] flipped. + @override + EdgeInsetsDirectional get flipped => EdgeInsetsDirectional.fromSTEB(end, bottom, start, top); + + @override + EdgeInsetsGeometry subtract(EdgeInsetsGeometry other) { + if (other is EdgeInsetsDirectional) { + return this - other; + } + return super.subtract(other); + } + + @override + EdgeInsetsGeometry add(EdgeInsetsGeometry other) { + if (other is EdgeInsetsDirectional) { + return this + other; + } + return super.add(other); + } + + /// Returns the difference between two [EdgeInsetsDirectional] objects. + EdgeInsetsDirectional operator -(EdgeInsetsDirectional other) { + return EdgeInsetsDirectional.fromSTEB( + start - other.start, + top - other.top, + end - other.end, + bottom - other.bottom, + ); + } + + /// Returns the sum of two [EdgeInsetsDirectional] objects. + EdgeInsetsDirectional operator +(EdgeInsetsDirectional other) { + return EdgeInsetsDirectional.fromSTEB( + start + other.start, + top + other.top, + end + other.end, + bottom + other.bottom, + ); + } + + /// Returns the [EdgeInsetsDirectional] object with each dimension negated. + /// + /// This is the same as multiplying the object by -1.0. + @override + EdgeInsetsDirectional operator -() { + return EdgeInsetsDirectional.fromSTEB( + -start, + -top, + -end, + -bottom, + ); + } + + /// Scales the [EdgeInsetsDirectional] object in each dimension by the given factor. + @override + EdgeInsetsDirectional operator *(double other) { + return EdgeInsetsDirectional.fromSTEB( + start * other, + top * other, + end * other, + bottom * other, + ); + } + + /// Divides the [EdgeInsetsDirectional] object in each dimension by the given factor. + @override + EdgeInsetsDirectional operator /(double other) { + return EdgeInsetsDirectional.fromSTEB( + start / other, + top / other, + end / other, + bottom / other, + ); + } + + /// Integer divides the [EdgeInsetsDirectional] object in each dimension by the given factor. + @override + EdgeInsetsDirectional operator ~/(double other) { + return EdgeInsetsDirectional.fromSTEB( + (start ~/ other).toDouble(), + (top ~/ other).toDouble(), + (end ~/ other).toDouble(), + (bottom ~/ other).toDouble(), + ); + } + + /// Computes the remainder in each dimension by the given factor. + @override + EdgeInsetsDirectional operator %(double other) { + return EdgeInsetsDirectional.fromSTEB( + start % other, + top % other, + end % other, + bottom % other, + ); + } + + /// Linearly interpolate between two [EdgeInsetsDirectional]. + /// + /// If either is null, this function interpolates from [EdgeInsetsDirectional.zero]. + /// + /// To interpolate between two [EdgeInsetsGeometry] objects of arbitrary type + /// (either [EdgeInsets] or [EdgeInsetsDirectional]), consider the + /// [EdgeInsetsGeometry.lerp] static method. + /// + /// {@macro dart.ui.shadow.lerp} + static EdgeInsetsDirectional? lerp(EdgeInsetsDirectional? a, EdgeInsetsDirectional? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b! * t; + } + if (b == null) { + return a * (1.0 - t); + } + return EdgeInsetsDirectional.fromSTEB( + ui.lerpDouble(a.start, b.start, t)!, + ui.lerpDouble(a.top, b.top, t)!, + ui.lerpDouble(a.end, b.end, t)!, + ui.lerpDouble(a.bottom, b.bottom, t)!, + ); + } + + @override + EdgeInsets resolve(TextDirection? direction) { + assert(direction != null); + switch (direction!) { + case TextDirection.rtl: + return EdgeInsets.fromLTRB(end, top, start, bottom); + case TextDirection.ltr: + return EdgeInsets.fromLTRB(start, top, end, bottom); + } + } + + /// Creates a copy of this EdgeInsetsDirectional but with the given + /// fields replaced with the new values. + EdgeInsetsDirectional copyWith({ + double? start, + double? top, + double? end, + double? bottom, + }) { + return EdgeInsetsDirectional.only( + start: start ?? this.start, + top: top ?? this.top, + end: end ?? this.end, + bottom: bottom ?? this.bottom, + ); + } +} + +class _MixedEdgeInsets extends EdgeInsetsGeometry { + const _MixedEdgeInsets.fromLRSETB(this._left, this._right, this._start, this._end, this._top, this._bottom); + + @override + final double _left; + + @override + final double _right; + + @override + final double _start; + + @override + final double _end; + + @override + final double _top; + + @override + final double _bottom; + + @override + bool get isNonNegative { + return _left >= 0.0 + && _right >= 0.0 + && _start >= 0.0 + && _end >= 0.0 + && _top >= 0.0 + && _bottom >= 0.0; + } + + @override + _MixedEdgeInsets operator -() { + return _MixedEdgeInsets.fromLRSETB( + -_left, + -_right, + -_start, + -_end, + -_top, + -_bottom, + ); + } + + @override + _MixedEdgeInsets operator *(double other) { + return _MixedEdgeInsets.fromLRSETB( + _left * other, + _right * other, + _start * other, + _end * other, + _top * other, + _bottom * other, + ); + } + + @override + _MixedEdgeInsets operator /(double other) { + return _MixedEdgeInsets.fromLRSETB( + _left / other, + _right / other, + _start / other, + _end / other, + _top / other, + _bottom / other, + ); + } + + @override + _MixedEdgeInsets operator ~/(double other) { + return _MixedEdgeInsets.fromLRSETB( + (_left ~/ other).toDouble(), + (_right ~/ other).toDouble(), + (_start ~/ other).toDouble(), + (_end ~/ other).toDouble(), + (_top ~/ other).toDouble(), + (_bottom ~/ other).toDouble(), + ); + } + + @override + _MixedEdgeInsets operator %(double other) { + return _MixedEdgeInsets.fromLRSETB( + _left % other, + _right % other, + _start % other, + _end % other, + _top % other, + _bottom % other, + ); + } + + @override + EdgeInsets resolve(TextDirection? direction) { + assert(direction != null); + switch (direction!) { + case TextDirection.rtl: + return EdgeInsets.fromLTRB(_end + _left, _top, _start + _right, _bottom); + case TextDirection.ltr: + return EdgeInsets.fromLTRB(_start + _left, _top, _end + _right, _bottom); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/flutter_logo.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/flutter_logo.dart new file mode 100644 index 0000000000000000000000000000000000000000..ecbdffd06164bda18464d32d1cecce102991b04a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/flutter_logo.dart @@ -0,0 +1,447 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui show Gradient, TextBox, lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'alignment.dart'; +import 'basic_types.dart'; +import 'box_fit.dart'; +import 'colors.dart'; +import 'decoration.dart'; +import 'edge_insets.dart'; +import 'image_provider.dart'; +import 'text_painter.dart'; +import 'text_span.dart'; +import 'text_style.dart'; + +/// Possible ways to draw Flutter's logo. +enum FlutterLogoStyle { + /// Show only Flutter's logo, not the "Flutter" label. + /// + /// This is the default behavior for [FlutterLogoDecoration] objects. + markOnly, + + /// Show Flutter's logo on the left, and the "Flutter" label to its right. + horizontal, + + /// Show Flutter's logo above the "Flutter" label. + stacked, +} + +/// An immutable description of how to paint Flutter's logo. +class FlutterLogoDecoration extends Decoration { + /// Creates a decoration that knows how to paint Flutter's logo. + /// + /// The [style] controls whether and where to draw the "Flutter" label. If one + /// is shown, the [textColor] controls the color of the label. + const FlutterLogoDecoration({ + this.textColor = const Color(0xFF757575), + this.style = FlutterLogoStyle.markOnly, + this.margin = EdgeInsets.zero, + }) : _position = identical(style, FlutterLogoStyle.markOnly) ? 0.0 : identical(style, FlutterLogoStyle.horizontal) ? 1.0 : -1.0, + _opacity = 1.0; + + const FlutterLogoDecoration._(this.textColor, this.style, this.margin, this._position, this._opacity); + + /// The color used to paint the "Flutter" text on the logo, if [style] is + /// [FlutterLogoStyle.horizontal] or [FlutterLogoStyle.stacked]. + /// + /// If possible, the default (a medium grey) should be used against a white + /// background. + final Color textColor; + + /// Whether and where to draw the "Flutter" text. By default, only the logo + /// itself is drawn. + // This property isn't actually used when painting. It's only really used to + // set the internal _position property. + final FlutterLogoStyle style; + + /// How far to inset the logo from the edge of the container. + final EdgeInsets margin; + + // The following are set when lerping, to represent states that can't be + // represented by the constructor. + final double _position; // -1.0 for stacked, 1.0 for horizontal, 0.0 for no logo + final double _opacity; // 0.0 .. 1.0 + + bool get _inTransition => _opacity != 1.0 || (_position != -1.0 && _position != 0.0 && _position != 1.0); + + @override + bool debugAssertIsValid() { + assert( + _position.isFinite + && _opacity >= 0.0 + && _opacity <= 1.0, + ); + return true; + } + + @override + bool get isComplex => !_inTransition; + + /// Linearly interpolate between two Flutter logo descriptions. + /// + /// Interpolates both the color and the style in a continuous fashion. + /// + /// If both values are null, this returns null. Otherwise, it returns a + /// non-null value. If one of the values is null, then the result is obtained + /// by scaling the other value's opacity and [margin]. + /// + /// {@macro dart.ui.shadow.lerp} + /// + /// See also: + /// + /// * [Decoration.lerp], which interpolates between arbitrary decorations. + static FlutterLogoDecoration? lerp(FlutterLogoDecoration? a, FlutterLogoDecoration? b, double t) { + assert(a == null || a.debugAssertIsValid()); + assert(b == null || b.debugAssertIsValid()); + if (identical(a, b)) { + return a; + } + if (a == null) { + return FlutterLogoDecoration._( + b!.textColor, + b.style, + b.margin * t, + b._position, + b._opacity * clampDouble(t, 0.0, 1.0), + ); + } + if (b == null) { + return FlutterLogoDecoration._( + a.textColor, + a.style, + a.margin * t, + a._position, + a._opacity * clampDouble(1.0 - t, 0.0, 1.0), + ); + } + if (t == 0.0) { + return a; + } + if (t == 1.0) { + return b; + } + return FlutterLogoDecoration._( + Color.lerp(a.textColor, b.textColor, t)!, + t < 0.5 ? a.style : b.style, + EdgeInsets.lerp(a.margin, b.margin, t)!, + a._position + (b._position - a._position) * t, + clampDouble(a._opacity + (b._opacity - a._opacity) * t, 0.0, 1.0), + ); + } + + @override + FlutterLogoDecoration? lerpFrom(Decoration? a, double t) { + assert(debugAssertIsValid()); + if (a == null || a is FlutterLogoDecoration) { + assert(a == null || a.debugAssertIsValid()); + return FlutterLogoDecoration.lerp(a as FlutterLogoDecoration?, this, t); + } + return super.lerpFrom(a, t) as FlutterLogoDecoration?; + } + + @override + FlutterLogoDecoration? lerpTo(Decoration? b, double t) { + assert(debugAssertIsValid()); + if (b == null || b is FlutterLogoDecoration) { + assert(b == null || b.debugAssertIsValid()); + return FlutterLogoDecoration.lerp(this, b as FlutterLogoDecoration?, t); + } + return super.lerpTo(b, t) as FlutterLogoDecoration?; + } + + @override + // TODO(ianh): better hit testing + bool hitTest(Size size, Offset position, { TextDirection? textDirection }) => true; + + @override + BoxPainter createBoxPainter([ VoidCallback? onChanged ]) { + assert(debugAssertIsValid()); + return _FlutterLogoPainter(this); + } + + @override + Path getClipPath(Rect rect, TextDirection textDirection) { + return Path()..addRect(rect); + } + + @override + bool operator ==(Object other) { + assert(debugAssertIsValid()); + if (identical(this, other)) { + return true; + } + return other is FlutterLogoDecoration + && other.textColor == textColor + && other._position == _position + && other._opacity == _opacity; + } + + @override + int get hashCode { + assert(debugAssertIsValid()); + return Object.hash( + textColor, + _position, + _opacity, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('textColor', textColor)); + properties.add(EnumProperty<FlutterLogoStyle>('style', style)); + if (_inTransition) { + properties.add(DiagnosticsNode.message('transition ${debugFormatDouble(_position)}:${debugFormatDouble(_opacity)}')); + } + } +} + + +/// An object that paints a [BoxDecoration] into a canvas. +class _FlutterLogoPainter extends BoxPainter { + _FlutterLogoPainter(this._config) + : assert(_config.debugAssertIsValid()), + super(null) { + _prepareText(); + } + + final FlutterLogoDecoration _config; + + // these are configured assuming a font size of 100.0. + late TextPainter _textPainter; + late Rect _textBoundingRect; + + @override + void dispose() { + _textPainter.dispose(); + super.dispose(); + } + + void _prepareText() { + const String kLabel = 'Flutter'; + _textPainter = TextPainter( + text: TextSpan( + text: kLabel, + style: TextStyle( + color: _config.textColor, + fontFamily: 'Roboto', + fontSize: 100.0 * 350.0 / 247.0, // 247 is the height of the F when the fontSize is 350, assuming device pixel ratio 1.0 + fontWeight: FontWeight.w300, + textBaseline: TextBaseline.alphabetic, + ), + ), + textDirection: TextDirection.ltr, + ); + _textPainter.layout(); + final ui.TextBox textSize = _textPainter.getBoxesForSelection(const TextSelection(baseOffset: 0, extentOffset: kLabel.length)).single; + _textBoundingRect = Rect.fromLTRB(textSize.left, textSize.top, textSize.right, textSize.bottom); + } + + // This class contains a lot of magic numbers. They were derived from the + // values in the SVG files exported from the original artwork source. + + void _paintLogo(Canvas canvas, Rect rect) { + // Our points are in a coordinate space that's 166 pixels wide and 202 pixels high. + // First, transform the rectangle so that our coordinate space is a square 202 pixels + // to a side, with the top left at the origin. + canvas.save(); + canvas.translate(rect.left, rect.top); + canvas.scale(rect.width / 202.0, rect.height / 202.0); + // Next, offset it some more so that the 166 horizontal pixels are centered + // in that square (as opposed to being on the left side of it). This means + // that if we draw in the rectangle from 0,0 to 166,202, we are drawing in + // the center of the given rect. + canvas.translate((202.0 - 166.0) / 2.0, 0.0); + + // Set up the styles. + final Paint lightPaint = Paint() + ..color = const Color(0xFF54C5F8); + final Paint mediumPaint = Paint() + ..color = const Color(0xFF29B6F6); + final Paint darkPaint = Paint() + ..color = const Color(0xFF01579B); + + final ui.Gradient triangleGradient = ui.Gradient.linear( + const Offset(87.2623 + 37.9092, 28.8384 + 123.4389), + const Offset(42.9205 + 37.9092, 35.0952 + 123.4389), + <Color>[ + const Color(0x001A237E), + const Color(0x661A237E), + ], + ); + final Paint trianglePaint = Paint() + ..shader = triangleGradient; + + // Draw the basic shape. + final Path topBeam = Path() + ..moveTo(37.7, 128.9) + ..lineTo(9.8, 101.0) + ..lineTo(100.4, 10.4) + ..lineTo(156.2, 10.4); + canvas.drawPath(topBeam, lightPaint); + + final Path middleBeam = Path() + ..moveTo(156.2, 94.0) + ..lineTo(100.4, 94.0) + ..lineTo(78.5, 115.9) + ..lineTo(106.4, 143.8); + canvas.drawPath(middleBeam, lightPaint); + + final Path bottomBeam = Path() + ..moveTo(79.5, 170.7) + ..lineTo(100.4, 191.6) + ..lineTo(156.2, 191.6) + ..lineTo(107.4, 142.8); + canvas.drawPath(bottomBeam, darkPaint); + + // The overlap between middle and bottom beam. + canvas.save(); + canvas.transform(Float64List.fromList(const <double>[ + // careful, this is in _column_-major order + 0.7071, -0.7071, 0.0, 0.0, + 0.7071, 0.7071, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + -77.697, 98.057, 0.0, 1.0, + ])); + canvas.drawRect(const Rect.fromLTWH(59.8, 123.1, 39.4, 39.4), mediumPaint); + canvas.restore(); + + // The gradients below the middle beam on top of the bottom beam. + final Path triangle = Path() + ..moveTo(79.5, 170.7) + ..lineTo(120.9, 156.4) + ..lineTo(107.4, 142.8); + canvas.drawPath(triangle, trianglePaint); + + canvas.restore(); + } + + @override + void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { + offset += _config.margin.topLeft; + final Size canvasSize = _config.margin.deflateSize(configuration.size!); + if (canvasSize.isEmpty) { + return; + } + final Size logoSize; + if (_config._position > 0.0) { + // horizontal style + logoSize = const Size(820.0, 232.0); + } else if (_config._position < 0.0) { + // stacked style + logoSize = const Size(252.0, 306.0); + } else { + // only the mark + logoSize = const Size(202.0, 202.0); + } + final FittedSizes fittedSize = applyBoxFit(BoxFit.contain, logoSize, canvasSize); + assert(fittedSize.source == logoSize); + final Rect rect = Alignment.center.inscribe(fittedSize.destination, offset & canvasSize); + final double centerSquareHeight = canvasSize.shortestSide; + final Rect centerSquare = Rect.fromLTWH( + offset.dx + (canvasSize.width - centerSquareHeight) / 2.0, + offset.dy + (canvasSize.height - centerSquareHeight) / 2.0, + centerSquareHeight, + centerSquareHeight, + ); + + final Rect logoTargetSquare; + if (_config._position > 0.0) { + // horizontal style + logoTargetSquare = Rect.fromLTWH(rect.left, rect.top, rect.height, rect.height); + } else if (_config._position < 0.0) { + // stacked style + final double logoHeight = rect.height * 191.0 / 306.0; + logoTargetSquare = Rect.fromLTWH( + rect.left + (rect.width - logoHeight) / 2.0, + rect.top, + logoHeight, + logoHeight, + ); + } else { + // only the mark + logoTargetSquare = centerSquare; + } + final Rect logoSquare = Rect.lerp(centerSquare, logoTargetSquare, _config._position.abs())!; + + if (_config._opacity < 1.0) { + canvas.saveLayer( + offset & canvasSize, + Paint() + ..colorFilter = ColorFilter.mode( + const Color(0xFFFFFFFF).withOpacity(_config._opacity), + BlendMode.modulate, + ), + ); + } + if (_config._position != 0.0) { + if (_config._position > 0.0) { + // horizontal style + final double fontSize = 2.0 / 3.0 * logoSquare.height * (1 - (10.4 * 2.0) / 202.0); + final double scale = fontSize / 100.0; + final double finalLeftTextPosition = // position of text in rest position + (256.4 / 820.0) * rect.width - // 256.4 is the distance from the left edge to the left of the F when the whole logo is 820.0 wide + (32.0 / 350.0) * fontSize; // 32 is the distance from the text bounding box edge to the left edge of the F when the font size is 350 + final double initialLeftTextPosition = // position of text when just starting the animation + rect.width / 2.0 - _textBoundingRect.width * scale; + final Offset textOffset = Offset( + rect.left + ui.lerpDouble(initialLeftTextPosition, finalLeftTextPosition, _config._position)!, + rect.top + (rect.height - _textBoundingRect.height * scale) / 2.0, + ); + canvas.save(); + if (_config._position < 1.0) { + final Offset center = logoSquare.center; + final Path path = Path() + ..moveTo(center.dx, center.dy) + ..lineTo(center.dx + rect.width, center.dy - rect.width) + ..lineTo(center.dx + rect.width, center.dy + rect.width) + ..close(); + canvas.clipPath(path); + } + canvas.translate(textOffset.dx, textOffset.dy); + canvas.scale(scale, scale); + _textPainter.paint(canvas, Offset.zero); + canvas.restore(); + } else if (_config._position < 0.0) { + // stacked style + final double fontSize = 0.35 * logoTargetSquare.height * (1 - (10.4 * 2.0) / 202.0); + final double scale = fontSize / 100.0; + if (_config._position > -1.0) { + // This limits what the drawRect call below is going to blend with. + canvas.saveLayer(_textBoundingRect, Paint()); + } else { + canvas.save(); + } + canvas.translate( + logoTargetSquare.center.dx - (_textBoundingRect.width * scale / 2.0), + logoTargetSquare.bottom, + ); + canvas.scale(scale, scale); + _textPainter.paint(canvas, Offset.zero); + if (_config._position > -1.0) { + canvas.drawRect(_textBoundingRect.inflate(_textBoundingRect.width * 0.5), Paint() + ..blendMode = BlendMode.modulate + ..shader = ui.Gradient.linear( + Offset(_textBoundingRect.width * -0.5, 0.0), + Offset(_textBoundingRect.width * 1.5, 0.0), + <Color>[const Color(0xFFFFFFFF), const Color(0xFFFFFFFF), const Color(0x00FFFFFF), const Color(0x00FFFFFF)], + <double>[ 0.0, math.max(0.0, _config._position.abs() - 0.1), math.min(_config._position.abs() + 0.1, 1.0), 1.0 ], + ), + ); + } + canvas.restore(); + } + } + _paintLogo(canvas, logoSquare); + if (_config._opacity < 1.0) { + canvas.restore(); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/fractional_offset.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/fractional_offset.dart new file mode 100644 index 0000000000000000000000000000000000000000..174e3b522b5f5b3edfdd67355d69b9ac0af984e5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/fractional_offset.dart @@ -0,0 +1,194 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'alignment.dart'; +import 'basic_types.dart'; + +/// An offset that's expressed as a fraction of a [Size]. +/// +/// `FractionalOffset(1.0, 0.0)` represents the top right of the [Size]. +/// +/// `FractionalOffset(0.0, 1.0)` represents the bottom left of the [Size]. +/// +/// `FractionalOffset(0.5, 2.0)` represents a point half way across the [Size], +/// below the bottom of the rectangle by the height of the [Size]. +/// +/// The [FractionalOffset] class specifies offsets in terms of a distance from +/// the top left, regardless of the [TextDirection]. +/// +/// ## Design discussion +/// +/// [FractionalOffset] and [Alignment] are two different representations of the +/// same information: the location within a rectangle relative to the size of +/// the rectangle. The difference between the two classes is in the coordinate +/// system they use to represent the location. +/// +/// [FractionalOffset] uses a coordinate system with an origin in the top-left +/// corner of the rectangle whereas [Alignment] uses a coordinate system with an +/// origin in the center of the rectangle. +/// +/// Historically, [FractionalOffset] predates [Alignment]. When we attempted to +/// make a version of [FractionalOffset] that adapted to the [TextDirection], we +/// ran into difficulty because placing the origin in the top-left corner +/// introduced a left-to-right bias that was hard to remove. +/// +/// By placing the origin in the center, [Alignment] and [AlignmentDirectional] +/// are able to use the same origin, which means we can use a linear function to +/// resolve an [AlignmentDirectional] into an [Alignment] in both +/// [TextDirection.rtl] and [TextDirection.ltr]. +/// +/// [Alignment] is better for most purposes than [FractionalOffset] and should +/// be used instead of [FractionalOffset]. We continue to implement +/// [FractionalOffset] to support code that predates [Alignment]. +/// +/// See also: +/// +/// * [Alignment], which uses a coordinate system based on the center of the +/// rectangle instead of the top left corner of the rectangle. +@immutable +class FractionalOffset extends Alignment { + /// Creates a fractional offset. + const FractionalOffset(double dx, double dy) + : super(dx * 2.0 - 1.0, dy * 2.0 - 1.0); + + /// Creates a fractional offset from a specific offset and size. + /// + /// The returned [FractionalOffset] describes the position of the + /// [Offset] in the [Size], as a fraction of the [Size]. + factory FractionalOffset.fromOffsetAndSize(Offset offset, Size size) { + return FractionalOffset( + offset.dx / size.width, + offset.dy / size.height, + ); + } + + /// Creates a fractional offset from a specific offset and rectangle. + /// + /// The offset is assumed to be relative to the same origin as the rectangle. + /// + /// If the offset is relative to the top left of the rectangle, use [ + /// FractionalOffset.fromOffsetAndSize] instead, passing `rect.size`. + /// + /// The returned [FractionalOffset] describes the position of the + /// [Offset] in the [Rect], as a fraction of the [Rect]. + factory FractionalOffset.fromOffsetAndRect(Offset offset, Rect rect) { + return FractionalOffset.fromOffsetAndSize( + offset - rect.topLeft, + rect.size, + ); + } + + /// The distance fraction in the horizontal direction. + /// + /// A value of 0.0 corresponds to the leftmost edge. A value of 1.0 + /// corresponds to the rightmost edge. Values are not limited to that range; + /// negative values represent positions to the left of the left edge, and + /// values greater than 1.0 represent positions to the right of the right + /// edge. + double get dx => (x + 1.0) / 2.0; + + /// The distance fraction in the vertical direction. + /// + /// A value of 0.0 corresponds to the topmost edge. A value of 1.0 corresponds + /// to the bottommost edge. Values are not limited to that range; negative + /// values represent positions above the top, and values greater than 1.0 + /// represent positions below the bottom. + double get dy => (y + 1.0) / 2.0; + + /// The top left corner. + static const FractionalOffset topLeft = FractionalOffset(0.0, 0.0); + + /// The center point along the top edge. + static const FractionalOffset topCenter = FractionalOffset(0.5, 0.0); + + /// The top right corner. + static const FractionalOffset topRight = FractionalOffset(1.0, 0.0); + + /// The center point along the left edge. + static const FractionalOffset centerLeft = FractionalOffset(0.0, 0.5); + + /// The center point, both horizontally and vertically. + static const FractionalOffset center = FractionalOffset(0.5, 0.5); + + /// The center point along the right edge. + static const FractionalOffset centerRight = FractionalOffset(1.0, 0.5); + + /// The bottom left corner. + static const FractionalOffset bottomLeft = FractionalOffset(0.0, 1.0); + + /// The center point along the bottom edge. + static const FractionalOffset bottomCenter = FractionalOffset(0.5, 1.0); + + /// The bottom right corner. + static const FractionalOffset bottomRight = FractionalOffset(1.0, 1.0); + + @override + Alignment operator -(Alignment other) { + if (other is! FractionalOffset) { + return super - other; + } + return FractionalOffset(dx - other.dx, dy - other.dy); + } + + @override + Alignment operator +(Alignment other) { + if (other is! FractionalOffset) { + return super + other; + } + return FractionalOffset(dx + other.dx, dy + other.dy); + } + + @override + FractionalOffset operator -() { + return FractionalOffset(-dx, -dy); + } + + @override + FractionalOffset operator *(double other) { + return FractionalOffset(dx * other, dy * other); + } + + @override + FractionalOffset operator /(double other) { + return FractionalOffset(dx / other, dy / other); + } + + @override + FractionalOffset operator ~/(double other) { + return FractionalOffset((dx ~/ other).toDouble(), (dy ~/ other).toDouble()); + } + + @override + FractionalOffset operator %(double other) { + return FractionalOffset(dx % other, dy % other); + } + + /// Linearly interpolate between two [FractionalOffset]s. + /// + /// If either is null, this function interpolates from [FractionalOffset.center]. + /// + /// {@macro dart.ui.shadow.lerp} + static FractionalOffset? lerp(FractionalOffset? a, FractionalOffset? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return FractionalOffset(ui.lerpDouble(0.5, b!.dx, t)!, ui.lerpDouble(0.5, b.dy, t)!); + } + if (b == null) { + return FractionalOffset(ui.lerpDouble(a.dx, 0.5, t)!, ui.lerpDouble(a.dy, 0.5, t)!); + } + return FractionalOffset(ui.lerpDouble(a.dx, b.dx, t)!, ui.lerpDouble(a.dy, b.dy, t)!); + } + + @override + String toString() { + return 'FractionalOffset(${dx.toStringAsFixed(1)}, ' + '${dy.toStringAsFixed(1)})'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/geometry.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/geometry.dart new file mode 100644 index 0000000000000000000000000000000000000000..fb12ba1065f7c588c1d13d379530f5055cfbba29 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/geometry.dart @@ -0,0 +1,64 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart' show clampDouble; +import 'basic_types.dart'; + +/// Position a child box within a container box, either above or below a target +/// point. +/// +/// The container's size is described by `size`. +/// +/// The target point is specified by `target`, as an offset from the top left of +/// the container. +/// +/// The child box's size is given by `childSize`. +/// +/// The return value is the suggested distance from the top left of the +/// container box to the top left of the child box. +/// +/// The suggested position will be above the target point if `preferBelow` is +/// false, and below the target point if it is true, unless it wouldn't fit on +/// the preferred side but would fit on the other side. +/// +/// The suggested position will place the nearest side of the child to the +/// target point `verticalOffset` from the target point (even if it cannot fit +/// given that constraint). +/// +/// The suggested position will be at least `margin` away from the edge of the +/// container. If possible, the child will be positioned so that its center is +/// aligned with the target point. If the child cannot fit horizontally within +/// the container given the margin, then the child will be centered in the +/// container. +/// +/// Used by [Tooltip] to position a tooltip relative to its parent. +Offset positionDependentBox({ + required Size size, + required Size childSize, + required Offset target, + required bool preferBelow, + double verticalOffset = 0.0, + double margin = 10.0, +}) { + // VERTICAL DIRECTION + final bool fitsBelow = target.dy + verticalOffset + childSize.height <= size.height - margin; + final bool fitsAbove = target.dy - verticalOffset - childSize.height >= margin; + final bool tooltipBelow = fitsAbove == fitsBelow ? preferBelow : fitsBelow; + final double y; + if (tooltipBelow) { + y = math.min(target.dy + verticalOffset, size.height - margin); + } else { + y = math.max(target.dy - verticalOffset - childSize.height, margin); + } + // HORIZONTAL DIRECTION + final double flexibleSpace = size.width - childSize.width; + final double x = flexibleSpace <= 2 * margin + // If there's not enough horizontal space for margin + child, center the + // child. + ? flexibleSpace / 2.0 + : clampDouble(target.dx - childSize.width / 2, margin, flexibleSpace - margin); + return Offset(x, y); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/gradient.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/gradient.dart new file mode 100644 index 0000000000000000000000000000000000000000..e1545edecdc7280b97f6badb74d5dc6e6efc658e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/gradient.dart @@ -0,0 +1,1101 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:math' as math; +import 'dart:ui' as ui show Gradient, lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'alignment.dart'; +import 'basic_types.dart'; + +class _ColorsAndStops { + _ColorsAndStops(this.colors, this.stops); + final List<Color> colors; + final List<double> stops; +} + +/// Calculate the color at position [t] of the gradient defined by [colors] and [stops]. +Color _sample(List<Color> colors, List<double> stops, double t) { + assert(colors.isNotEmpty); + assert(stops.isNotEmpty); + if (t <= stops.first) { + return colors.first; + } + if (t >= stops.last) { + return colors.last; + } + final int index = stops.lastIndexWhere((double s) => s <= t); + assert(index != -1); + return Color.lerp( + colors[index], colors[index + 1], + (t - stops[index]) / (stops[index + 1] - stops[index]), + )!; +} + +_ColorsAndStops _interpolateColorsAndStops( + List<Color> aColors, + List<double> aStops, + List<Color> bColors, + List<double> bStops, + double t, +) { + assert(aColors.length >= 2); + assert(bColors.length >= 2); + assert(aStops.length == aColors.length); + assert(bStops.length == bColors.length); + final SplayTreeSet<double> stops = SplayTreeSet<double>() + ..addAll(aStops) + ..addAll(bStops); + final List<double> interpolatedStops = stops.toList(growable: false); + final List<Color> interpolatedColors = interpolatedStops.map<Color>( + (double stop) => Color.lerp(_sample(aColors, aStops, stop), _sample(bColors, bStops, stop), t)!, + ).toList(growable: false); + return _ColorsAndStops(interpolatedColors, interpolatedStops); +} + +/// Base class for transforming gradient shaders without applying the same +/// transform to the entire canvas. +/// +/// For example, a [SweepGradient] normally starts its gradation at 3 o'clock +/// and draws clockwise. To have the sweep appear to start at 6 o'clock, supply +/// a [GradientRotation] of `pi/4` radians (i.e. 45 degrees). +@immutable +abstract class GradientTransform { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const GradientTransform(); + + /// When a [Gradient] creates its [Shader], it will call this method to + /// determine what transform to apply to the shader for the given [Rect] and + /// [TextDirection]. + /// + /// Implementers may return null from this method, which achieves the same + /// final effect as returning [Matrix4.identity]. + Matrix4? transform(Rect bounds, {TextDirection? textDirection}); +} + +/// A [GradientTransform] that rotates the gradient around the center-point of +/// its bounding box. +/// +/// {@tool snippet} +/// +/// This sample would rotate a sweep gradient by a quarter turn clockwise: +/// +/// ```dart +/// const SweepGradient gradient = SweepGradient( +/// colors: <Color>[Color(0xFFFFFFFF), Color(0xFF009900)], +/// transform: GradientRotation(math.pi/4), +/// ); +/// ``` +/// {@end-tool} +@immutable +class GradientRotation extends GradientTransform { + /// Constructs a [GradientRotation] for the specified angle. + /// + /// The angle is in radians in the clockwise direction. + const GradientRotation(this.radians); + + /// The angle of rotation in radians in the clockwise direction. + final double radians; + + @override + Matrix4 transform(Rect bounds, {TextDirection? textDirection}) { + final double sinRadians = math.sin(radians); + final double oneMinusCosRadians = 1 - math.cos(radians); + final Offset center = bounds.center; + final double originX = sinRadians * center.dy + oneMinusCosRadians * center.dx; + final double originY = -sinRadians * center.dx + oneMinusCosRadians * center.dy; + + return Matrix4.identity() + ..translate(originX, originY) + ..rotateZ(radians); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is GradientRotation + && other.radians == radians; + } + + @override + int get hashCode => radians.hashCode; + + @override + String toString() { + return '${objectRuntimeType(this, 'GradientRotation')}(radians: ${debugFormatDouble(radians)})'; + } +} + +/// A 2D gradient. +/// +/// This is an interface that allows [LinearGradient], [RadialGradient], and +/// [SweepGradient] classes to be used interchangeably in [BoxDecoration]s. +/// +/// See also: +/// +/// * [Gradient](dart-ui/Gradient-class.html), the class in the [dart:ui] library. +/// +@immutable +abstract class Gradient { + /// Initialize the gradient's colors and stops. + /// + /// The [colors] argument must have at least two colors (the length is not + /// verified until the [createShader] method is called). + /// + /// If specified, the [stops] argument must have the same number of entries as + /// [colors] (this is also not verified until the [createShader] method is + /// called). + /// + /// The [transform] argument can be applied to transform _only_ the gradient, + /// without rotating the canvas itself or other geometry on the canvas. For + /// example, a `GradientRotation(math.pi/4)` will result in a [SweepGradient] + /// that starts from a position of 6 o'clock instead of 3 o'clock, assuming + /// no other rotation or perspective transformations have been applied to the + /// [Canvas]. If null, no transformation is applied. + const Gradient({ + required this.colors, + this.stops, + this.transform, + }); + + /// The colors the gradient should obtain at each of the stops. + /// + /// If [stops] is non-null, this list must have the same length as [stops]. + /// + /// This list must have at least two colors in it (otherwise, it's not a + /// gradient!). + final List<Color> colors; + + /// A list of values from 0.0 to 1.0 that denote fractions along the gradient. + /// + /// If non-null, this list must have the same length as [colors]. + /// + /// If the first value is not 0.0, then a stop with position 0.0 and a color + /// equal to the first color in [colors] is implied. + /// + /// If the last value is not 1.0, then a stop with position 1.0 and a color + /// equal to the last color in [colors] is implied. + /// + /// The values in the [stops] list must be in ascending order. If a value in + /// the [stops] list is less than an earlier value in the list, then its value + /// is assumed to equal the previous value. + /// + /// If stops is null, then a set of uniformly distributed stops is implied, + /// with the first stop at 0.0 and the last stop at 1.0. + final List<double>? stops; + + /// The transform, if any, to apply to the gradient. + /// + /// This transform is in addition to any other transformations applied to the + /// canvas, but does not add any transformations to the canvas. + final GradientTransform? transform; + + List<double> _impliedStops() { + if (stops != null) { + return stops!; + } + assert(colors.length >= 2, 'colors list must have at least two colors'); + final double separation = 1.0 / (colors.length - 1); + return List<double>.generate( + colors.length, + (int index) => index * separation, + growable: false, + ); + } + + /// Creates a [Shader] for this gradient to fill the given rect. + /// + /// If the gradient's configuration is text-direction-dependent, for example + /// it uses [AlignmentDirectional] objects instead of [Alignment] + /// objects, then the `textDirection` argument must not be null. + /// + /// The shader's transform will be resolved from the [transform] of this + /// gradient. + @factory + Shader createShader(Rect rect, { TextDirection? textDirection }); + + /// Returns a new gradient with its properties scaled by the given factor. + /// + /// A factor of 0.0 (or less) should result in a variant of the gradient that + /// is invisible; any two factors epsilon apart should be unnoticeably + /// different from each other at first glance. From this it follows that + /// scaling a gradient with values from 1.0 to 0.0 over time should cause the + /// gradient to smoothly disappear. + /// + /// Typically this is the same as interpolating from null (with [lerp]). + Gradient scale(double factor); + + /// Linearly interpolates from another [Gradient] to `this`. + /// + /// When implementing this method in subclasses, return null if this class + /// cannot interpolate from `a`. In that case, [lerp] will try `a`'s [lerpTo] + /// method instead. + /// + /// If `a` is null, this must not return null. The base class implements this + /// by deferring to [scale]. + /// + /// The `t` argument represents position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `a` (or something + /// equivalent to `a`), 1.0 meaning that the interpolation has finished, + /// returning `this` (or something equivalent to `this`), and values in + /// between meaning that the interpolation is at the relevant point on the + /// timeline between `a` and `this`. The interpolation can be extrapolated + /// beyond 0.0 and 1.0, so negative values and values greater than 1.0 are + /// valid (and can easily be generated by curves such as + /// [Curves.elasticInOut]). + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + /// + /// Instead of calling this directly, use [Gradient.lerp]. + @protected + Gradient? lerpFrom(Gradient? a, double t) { + if (a == null) { + return scale(t); + } + return null; + } + + /// Linearly interpolates from `this` to another [Gradient]. + /// + /// This is called if `b`'s [lerpTo] did not know how to handle this class. + /// + /// When implementing this method in subclasses, return null if this class + /// cannot interpolate from `b`. In that case, [lerp] will apply a default + /// behavior instead. + /// + /// If `b` is null, this must not return null. The base class implements this + /// by deferring to [scale]. + /// + /// The `t` argument represents position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `this` (or something + /// equivalent to `this`), 1.0 meaning that the interpolation has finished, + /// returning `b` (or something equivalent to `b`), and values in between + /// meaning that the interpolation is at the relevant point on the timeline + /// between `this` and `b`. The interpolation can be extrapolated beyond 0.0 + /// and 1.0, so negative values and values greater than 1.0 are valid (and can + /// easily be generated by curves such as [Curves.elasticInOut]). + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + /// + /// Instead of calling this directly, use [Gradient.lerp]. + @protected + Gradient? lerpTo(Gradient? b, double t) { + if (b == null) { + return scale(1.0 - t); + } + return null; + } + + /// Linearly interpolates between two [Gradient]s. + /// + /// This defers to `b`'s [lerpTo] function if `b` is not null. If `b` is + /// null or if its [lerpTo] returns null, it uses `a`'s [lerpFrom] + /// function instead. If both return null, it returns `a` before `t == 0.5` + /// and `b` after `t == 0.5`. + /// + /// {@macro dart.ui.shadow.lerp} + static Gradient? lerp(Gradient? a, Gradient? b, double t) { + if (identical(a, b)) { + return a; + } + Gradient? result; + if (b != null) { + result = b.lerpFrom(a, t); // if a is null, this must return non-null + } + if (result == null && a != null) { + result = a.lerpTo(b, t); // if b is null, this must return non-null + } + if (result != null) { + return result; + } + assert(a != null && b != null); + return t < 0.5 ? a!.scale(1.0 - (t * 2.0)) : b!.scale((t - 0.5) * 2.0); + } + + Float64List? _resolveTransform(Rect bounds, TextDirection? textDirection) { + return transform?.transform(bounds, textDirection: textDirection)?.storage; + } +} + +/// A 2D linear gradient. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=gYNTcgZVcWw} +/// +/// This class is used by [BoxDecoration] to represent linear gradients. This +/// abstracts out the arguments to the [ui.Gradient.linear] constructor from +/// the `dart:ui` library. +/// +/// A gradient has two anchor points, [begin] and [end]. The [begin] point +/// corresponds to 0.0, and the [end] point corresponds to 1.0. These points are +/// expressed in fractions, so that the same gradient can be reused with varying +/// sized boxes without changing the parameters. (This contrasts with [ +/// ui.Gradient.linear], whose arguments are expressed in logical pixels.) +/// +/// The [colors] are described by a list of [Color] objects. There must be at +/// least two colors. The [stops] list, if specified, must have the same length +/// as [colors]. It specifies fractions of the vector from start to end, between +/// 0.0 and 1.0, for each color. If it is null, a uniform distribution is +/// assumed. +/// +/// The region of the canvas before [begin] and after [end] is colored according +/// to [tileMode]. +/// +/// Typically this class is used with [BoxDecoration], which does the painting. +/// To use a [LinearGradient] to paint on a canvas directly, see [createShader]. +/// +/// {@tool dartpad} +/// This sample draws a picture with a gradient sweeping through different +/// colors, by having a [Container] display a [BoxDecoration] with a +/// [LinearGradient]. +/// +/// ** See code in examples/api/lib/painting/gradient/linear_gradient.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [RadialGradient], which displays a gradient in concentric circles, and +/// has an example which shows a different way to use [Gradient] objects. +/// * [SweepGradient], which displays a gradient in a sweeping arc around a +/// center point. +/// * [BoxDecoration], which can take a [LinearGradient] in its +/// [BoxDecoration.gradient] property. +class LinearGradient extends Gradient { + /// Creates a linear gradient. + /// + /// If [stops] is non-null, it must have the same length as [colors]. + const LinearGradient({ + this.begin = Alignment.centerLeft, + this.end = Alignment.centerRight, + required super.colors, + super.stops, + this.tileMode = TileMode.clamp, + super.transform, + }); + + /// The offset at which stop 0.0 of the gradient is placed. + /// + /// If this is an [Alignment], then it is expressed as a vector from + /// coordinate (0.0, 0.0), in a coordinate space that maps the center of the + /// paint box at (0.0, 0.0) and the bottom right at (1.0, 1.0). + /// + /// For example, a begin offset of (-1.0, 0.0) is half way down the + /// left side of the box. + /// + /// It can also be an [AlignmentDirectional], where the start is the + /// left in left-to-right contexts and the right in right-to-left contexts. If + /// a text-direction-dependent value is provided here, then the [createShader] + /// method will need to be given a [TextDirection]. + final AlignmentGeometry begin; + + /// The offset at which stop 1.0 of the gradient is placed. + /// + /// If this is an [Alignment], then it is expressed as a vector from + /// coordinate (0.0, 0.0), in a coordinate space that maps the center of the + /// paint box at (0.0, 0.0) and the bottom right at (1.0, 1.0). + /// + /// For example, a begin offset of (1.0, 0.0) is half way down the + /// right side of the box. + /// + /// It can also be an [AlignmentDirectional], where the start is the left in + /// left-to-right contexts and the right in right-to-left contexts. If a + /// text-direction-dependent value is provided here, then the [createShader] + /// method will need to be given a [TextDirection]. + final AlignmentGeometry end; + + /// How this gradient should tile the plane beyond in the region before + /// [begin] and after [end]. + /// + /// For details, see [TileMode]. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_clamp_linear.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_decal_linear.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_mirror_linear.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_repeated_linear.png) + final TileMode tileMode; + + @override + Shader createShader(Rect rect, { TextDirection? textDirection }) { + return ui.Gradient.linear( + begin.resolve(textDirection).withinRect(rect), + end.resolve(textDirection).withinRect(rect), + colors, _impliedStops(), tileMode, _resolveTransform(rect, textDirection), + ); + } + + /// Returns a new [LinearGradient] with its colors scaled by the given factor. + /// + /// Since the alpha component of the Color is what is scaled, a factor + /// of 0.0 or less results in a gradient that is fully transparent. + @override + LinearGradient scale(double factor) { + return LinearGradient( + begin: begin, + end: end, + colors: colors.map<Color>((Color color) => Color.lerp(null, color, factor)!).toList(), + stops: stops, + tileMode: tileMode, + ); + } + + @override + Gradient? lerpFrom(Gradient? a, double t) { + if (a == null || (a is LinearGradient)) { + return LinearGradient.lerp(a as LinearGradient?, this, t); + } + return super.lerpFrom(a, t); + } + + @override + Gradient? lerpTo(Gradient? b, double t) { + if (b == null || (b is LinearGradient)) { + return LinearGradient.lerp(this, b as LinearGradient?, t); + } + return super.lerpTo(b, t); + } + + /// Linearly interpolate between two [LinearGradient]s. + /// + /// If either gradient is null, this function linearly interpolates from + /// a gradient that matches the other gradient in [begin], [end], [stops] and + /// [tileMode] and with the same [colors] but transparent (using [scale]). + /// + /// If neither gradient is null, they must have the same number of [colors]. + /// + /// The `t` argument represents a position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `a` (or something + /// equivalent to `a`), 1.0 meaning that the interpolation has finished, + /// returning `b` (or something equivalent to `b`), and values in between + /// meaning that the interpolation is at the relevant point on the timeline + /// between `a` and `b`. The interpolation can be extrapolated beyond 0.0 and + /// 1.0, so negative values and values greater than 1.0 are valid (and can + /// easily be generated by curves such as [Curves.elasticInOut]). + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + static LinearGradient? lerp(LinearGradient? a, LinearGradient? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!.scale(t); + } + if (b == null) { + return a.scale(1.0 - t); + } + final _ColorsAndStops interpolated = _interpolateColorsAndStops( + a.colors, + a._impliedStops(), + b.colors, + b._impliedStops(), + t, + ); + return LinearGradient( + begin: AlignmentGeometry.lerp(a.begin, b.begin, t)!, + end: AlignmentGeometry.lerp(a.end, b.end, t)!, + colors: interpolated.colors, + stops: interpolated.stops, + tileMode: t < 0.5 ? a.tileMode : b.tileMode, // TODO(ianh): interpolate tile mode + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is LinearGradient + && other.begin == begin + && other.end == end + && other.tileMode == tileMode + && other.transform == transform + && listEquals<Color>(other.colors, colors) + && listEquals<double>(other.stops, stops); + } + + @override + int get hashCode => Object.hash( + begin, + end, + tileMode, + transform, + Object.hashAll(colors), + stops == null ? null : Object.hashAll(stops!), + ); + + @override + String toString() { + final List<String> description = <String>[ + 'begin: $begin', + 'end: $end', + 'colors: $colors', + if (stops != null) 'stops: $stops', + 'tileMode: $tileMode', + if (transform != null) 'transform: $transform', + ]; + + return '${objectRuntimeType(this, 'LinearGradient')}(${description.join(', ')})'; + } +} + +/// A 2D radial gradient. +/// +/// This class is used by [BoxDecoration] to represent radial gradients. This +/// abstracts out the arguments to the [ui.Gradient.radial] constructor from +/// the `dart:ui` library. +/// +/// A normal radial gradient has a [center] and a [radius]. The [center] point +/// corresponds to 0.0, and the ring at [radius] from the center corresponds +/// to 1.0. These lengths are expressed in fractions, so that the same gradient +/// can be reused with varying sized boxes without changing the parameters. +/// (This contrasts with [ui.Gradient.radial], whose arguments are expressed +/// in logical pixels.) +/// +/// It is also possible to create a two-point (or focal pointed) radial gradient +/// (which is sometimes referred to as a two point conic gradient, but is not the +/// same as a CSS conic gradient which corresponds to a [SweepGradient]). A [focal] +/// point and [focalRadius] can be specified similarly to [center] and [radius], +/// which will make the rendered gradient appear to be pointed or directed in the +/// direction of the [focal] point. This is only important if [focal] and [center] +/// are not equal or [focalRadius] > 0.0 (as this case is visually identical to a +/// normal radial gradient). One important case to avoid is having [focal] and +/// [center] both resolve to [Offset.zero] when [focalRadius] > 0.0. In such a case, +/// a valid shader cannot be created by the framework. +/// +/// The [colors] are described by a list of [Color] objects. There must be at +/// least two colors. The [stops] list, if specified, must have the same length +/// as [colors]. It specifies fractions of the radius between 0.0 and 1.0, +/// giving concentric rings for each color stop. If it is null, a uniform +/// distribution is assumed. +/// +/// The region of the canvas beyond [radius] from the [center] is colored +/// according to [tileMode]. +/// +/// Typically this class is used with [BoxDecoration], which does the painting. +/// To use a [RadialGradient] to paint on a canvas directly, see [createShader]. +/// +/// {@tool snippet} +/// +/// This function draws a gradient that looks like a sun in a blue sky. +/// +/// ```dart +/// void paintSky(Canvas canvas, Rect rect) { +/// const RadialGradient gradient = RadialGradient( +/// center: Alignment(0.7, -0.6), // near the top right +/// radius: 0.2, +/// colors: <Color>[ +/// Color(0xFFFFFF00), // yellow sun +/// Color(0xFF0099FF), // blue sky +/// ], +/// stops: <double>[0.4, 1.0], +/// ); +/// // rect is the area we are painting over +/// final Paint paint = Paint() +/// ..shader = gradient.createShader(rect); +/// canvas.drawRect(rect, paint); +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [LinearGradient], which displays a gradient in parallel lines, and has an +/// example which shows a different way to use [Gradient] objects. +/// * [SweepGradient], which displays a gradient in a sweeping arc around a +/// center point. +/// * [BoxDecoration], which can take a [RadialGradient] in its +/// [BoxDecoration.gradient] property. +/// * [CustomPainter], which shows how to use the above sample code in a custom +/// painter. +class RadialGradient extends Gradient { + /// Creates a radial gradient. + /// + /// If [stops] is non-null, it must have the same length as [colors]. + const RadialGradient({ + this.center = Alignment.center, + this.radius = 0.5, + required super.colors, + super.stops, + this.tileMode = TileMode.clamp, + this.focal, + this.focalRadius = 0.0, + super.transform, + }); + + /// The center of the gradient, as an offset into the (-1.0, -1.0) x (1.0, 1.0) + /// square describing the gradient which will be mapped onto the paint box. + /// + /// For example, an alignment of (0.0, 0.0) will place the radial + /// gradient in the center of the box. + /// + /// If this is an [Alignment], then it is expressed as a vector from + /// coordinate (0.0, 0.0), in a coordinate space that maps the center of the + /// paint box at (0.0, 0.0) and the bottom right at (1.0, 1.0). + /// + /// It can also be an [AlignmentDirectional], where the start is the left in + /// left-to-right contexts and the right in right-to-left contexts. If a + /// text-direction-dependent value is provided here, then the [createShader] + /// method will need to be given a [TextDirection]. + final AlignmentGeometry center; + + /// The radius of the gradient, as a fraction of the shortest side + /// of the paint box. + /// + /// For example, if a radial gradient is painted on a box that is + /// 100.0 pixels wide and 200.0 pixels tall, then a radius of 1.0 + /// will place the 1.0 stop at 100.0 pixels from the [center]. + final double radius; + + /// How this gradient should tile the plane beyond the outer ring at [radius] + /// pixels from the [center]. + /// + /// For details, see [TileMode]. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_clamp_radial.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_decal_radial.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_mirror_radial.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_repeated_radial.png) + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_clamp_radialWithFocal.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_decal_radialWithFocal.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_mirror_radialWithFocal.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_repeated_radialWithFocal.png) + final TileMode tileMode; + + /// The focal point of the gradient. If specified, the gradient will appear + /// to be focused along the vector from [center] to focal. + /// + /// See [center] for a description of how the coordinates are mapped. + /// + /// If this value is specified and [focalRadius] > 0.0, care should be taken + /// to ensure that either this value or [center] will not both resolve to + /// [Offset.zero], which would fail to create a valid gradient. + final AlignmentGeometry? focal; + + /// The radius of the focal point of gradient, as a fraction of the shortest + /// side of the paint box. + /// + /// For example, if a radial gradient is painted on a box that is + /// 100.0 pixels wide and 200.0 pixels tall, then a radius of 1.0 + /// will place the 1.0 stop at 100.0 pixels from the [focal] point. + /// + /// If this value is specified and is greater than 0.0, either [focal] or + /// [center] must not resolve to [Offset.zero], which would fail to create + /// a valid gradient. + final double focalRadius; + + @override + Shader createShader(Rect rect, { TextDirection? textDirection }) { + return ui.Gradient.radial( + center.resolve(textDirection).withinRect(rect), + radius * rect.shortestSide, + colors, _impliedStops(), tileMode, + _resolveTransform(rect, textDirection), + focal?.resolve(textDirection).withinRect(rect), + focalRadius * rect.shortestSide, + ); + } + + /// Returns a new [RadialGradient] with its colors scaled by the given factor. + /// + /// Since the alpha component of the Color is what is scaled, a factor + /// of 0.0 or less results in a gradient that is fully transparent. + @override + RadialGradient scale(double factor) { + return RadialGradient( + center: center, + radius: radius, + colors: colors.map<Color>((Color color) => Color.lerp(null, color, factor)!).toList(), + stops: stops, + tileMode: tileMode, + focal: focal, + focalRadius: focalRadius, + ); + } + + @override + Gradient? lerpFrom(Gradient? a, double t) { + if (a == null || (a is RadialGradient)) { + return RadialGradient.lerp(a as RadialGradient?, this, t); + } + return super.lerpFrom(a, t); + } + + @override + Gradient? lerpTo(Gradient? b, double t) { + if (b == null || (b is RadialGradient)) { + return RadialGradient.lerp(this, b as RadialGradient?, t); + } + return super.lerpTo(b, t); + } + + /// Linearly interpolate between two [RadialGradient]s. + /// + /// If either gradient is null, this function linearly interpolates from + /// a gradient that matches the other gradient in [center], [radius], [stops] and + /// [tileMode] and with the same [colors] but transparent (using [scale]). + /// + /// If neither gradient is null, they must have the same number of [colors]. + /// + /// The `t` argument represents a position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `a` (or something + /// equivalent to `a`), 1.0 meaning that the interpolation has finished, + /// returning `b` (or something equivalent to `b`), and values in between + /// meaning that the interpolation is at the relevant point on the timeline + /// between `a` and `b`. The interpolation can be extrapolated beyond 0.0 and + /// 1.0, so negative values and values greater than 1.0 are valid (and can + /// easily be generated by curves such as [Curves.elasticInOut]). + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + static RadialGradient? lerp(RadialGradient? a, RadialGradient? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!.scale(t); + } + if (b == null) { + return a.scale(1.0 - t); + } + final _ColorsAndStops interpolated = _interpolateColorsAndStops( + a.colors, + a._impliedStops(), + b.colors, + b._impliedStops(), + t, + ); + return RadialGradient( + center: AlignmentGeometry.lerp(a.center, b.center, t)!, + radius: math.max(0.0, ui.lerpDouble(a.radius, b.radius, t)!), + colors: interpolated.colors, + stops: interpolated.stops, + tileMode: t < 0.5 ? a.tileMode : b.tileMode, // TODO(ianh): interpolate tile mode + focal: AlignmentGeometry.lerp(a.focal, b.focal, t), + focalRadius: math.max(0.0, ui.lerpDouble(a.focalRadius, b.focalRadius, t)!), + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is RadialGradient + && other.center == center + && other.radius == radius + && other.tileMode == tileMode + && other.transform == transform + && listEquals<Color>(other.colors, colors) + && listEquals<double>(other.stops, stops) + && other.focal == focal + && other.focalRadius == focalRadius; + } + + @override + int get hashCode => Object.hash( + center, + radius, + tileMode, + transform, + Object.hashAll(colors), + stops == null ? null : Object.hashAll(stops!), + focal, + focalRadius, + ); + + @override + String toString() { + final List<String> description = <String>[ + 'center: $center', + 'radius: ${debugFormatDouble(radius)}', + 'colors: $colors', + if (stops != null) 'stops: $stops', + 'tileMode: $tileMode', + if (focal != null) 'focal: $focal', + 'focalRadius: ${debugFormatDouble(focalRadius)}', + if (transform != null) 'transform: $transform', + ]; + + return '${objectRuntimeType(this, 'RadialGradient')}(${description.join(', ')})'; + } +} + +/// A 2D sweep gradient. +/// +/// This class is used by [BoxDecoration] to represent sweep gradients. This +/// abstracts out the arguments to the [ui.Gradient.sweep] constructor from +/// the `dart:ui` library. +/// +/// A gradient has a [center], a [startAngle], and an [endAngle]. The [startAngle] +/// corresponds to 0.0, and the [endAngle] corresponds to 1.0. These angles are +/// expressed in radians. +/// +/// The [colors] are described by a list of [Color] objects. There must be at +/// least two colors. The [stops] list, if specified, must have the same length +/// as [colors]. It specifies fractions of the vector from start to end, between +/// 0.0 and 1.0, for each color. If it is null, a uniform distribution is +/// assumed. +/// +/// The region of the canvas before [startAngle] and after [endAngle] is colored +/// according to [tileMode]. +/// +/// Typically this class is used with [BoxDecoration], which does the painting. +/// To use a [SweepGradient] to paint on a canvas directly, see [createShader]. +/// +/// {@tool snippet} +/// +/// This sample draws a different color in each quadrant. +/// +/// ```dart +/// Container( +/// decoration: const BoxDecoration( +/// gradient: SweepGradient( +/// center: FractionalOffset.center, +/// colors: <Color>[ +/// Color(0xFF4285F4), // blue +/// Color(0xFF34A853), // green +/// Color(0xFFFBBC05), // yellow +/// Color(0xFFEA4335), // red +/// Color(0xFF4285F4), // blue again to seamlessly transition to the start +/// ], +/// stops: <double>[0.0, 0.25, 0.5, 0.75, 1.0], +/// ), +/// ) +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// +/// This sample takes the above gradient and rotates it by `math.pi/4` radians, +/// i.e. 45 degrees. +/// +/// ```dart +/// Container( +/// decoration: const BoxDecoration( +/// gradient: SweepGradient( +/// center: FractionalOffset.center, +/// colors: <Color>[ +/// Color(0xFF4285F4), // blue +/// Color(0xFF34A853), // green +/// Color(0xFFFBBC05), // yellow +/// Color(0xFFEA4335), // red +/// Color(0xFF4285F4), // blue again to seamlessly transition to the start +/// ], +/// stops: <double>[0.0, 0.25, 0.5, 0.75, 1.0], +/// transform: GradientRotation(math.pi/4), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [LinearGradient], which displays a gradient in parallel lines, and has an +/// example which shows a different way to use [Gradient] objects. +/// * [RadialGradient], which displays a gradient in concentric circles, and +/// has an example which shows a different way to use [Gradient] objects. +/// * [BoxDecoration], which can take a [SweepGradient] in its +/// [BoxDecoration.gradient] property. +class SweepGradient extends Gradient { + /// Creates a sweep gradient. + /// + /// If [stops] is non-null, it must have the same length as [colors]. + const SweepGradient({ + this.center = Alignment.center, + this.startAngle = 0.0, + this.endAngle = math.pi * 2, + required super.colors, + super.stops, + this.tileMode = TileMode.clamp, + super.transform, + }); + + /// The center of the gradient, as an offset into the (-1.0, -1.0) x (1.0, 1.0) + /// square describing the gradient which will be mapped onto the paint box. + /// + /// For example, an alignment of (0.0, 0.0) will place the sweep + /// gradient in the center of the box. + /// + /// If this is an [Alignment], then it is expressed as a vector from + /// coordinate (0.0, 0.0), in a coordinate space that maps the center of the + /// paint box at (0.0, 0.0) and the bottom right at (1.0, 1.0). + /// + /// It can also be an [AlignmentDirectional], where the start is the left in + /// left-to-right contexts and the right in right-to-left contexts. If a + /// text-direction-dependent value is provided here, then the [createShader] + /// method will need to be given a [TextDirection]. + final AlignmentGeometry center; + + /// The angle in radians at which stop 0.0 of the gradient is placed. + /// + /// Defaults to 0.0. + final double startAngle; + + /// The angle in radians at which stop 1.0 of the gradient is placed. + /// + /// Defaults to math.pi * 2. + final double endAngle; + + /// How this gradient should tile the plane beyond in the region before + /// [startAngle] and after [endAngle]. + /// + /// For details, see [TileMode]. + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_clamp_sweep.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_decal_sweep.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_mirror_sweep.png) + /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/tile_mode_repeated_sweep.png) + final TileMode tileMode; + + @override + Shader createShader(Rect rect, { TextDirection? textDirection }) { + return ui.Gradient.sweep( + center.resolve(textDirection).withinRect(rect), + colors, _impliedStops(), tileMode, + startAngle, + endAngle, + _resolveTransform(rect, textDirection), + ); + } + + /// Returns a new [SweepGradient] with its colors scaled by the given factor. + /// + /// Since the alpha component of the Color is what is scaled, a factor + /// of 0.0 or less results in a gradient that is fully transparent. + @override + SweepGradient scale(double factor) { + return SweepGradient( + center: center, + startAngle: startAngle, + endAngle: endAngle, + colors: colors.map<Color>((Color color) => Color.lerp(null, color, factor)!).toList(), + stops: stops, + tileMode: tileMode, + ); + } + + @override + Gradient? lerpFrom(Gradient? a, double t) { + if (a == null || (a is SweepGradient)) { + return SweepGradient.lerp(a as SweepGradient?, this, t); + } + return super.lerpFrom(a, t); + } + + @override + Gradient? lerpTo(Gradient? b, double t) { + if (b == null || (b is SweepGradient)) { + return SweepGradient.lerp(this, b as SweepGradient?, t); + } + return super.lerpTo(b, t); + } + + /// Linearly interpolate between two [SweepGradient]s. + /// + /// If either gradient is null, then the non-null gradient is returned with + /// its color scaled in the same way as the [scale] function. + /// + /// If neither gradient is null, they must have the same number of [colors]. + /// + /// The `t` argument represents a position on the timeline, with 0.0 meaning + /// that the interpolation has not started, returning `a` (or something + /// equivalent to `a`), 1.0 meaning that the interpolation has finished, + /// returning `b` (or something equivalent to `b`), and values in between + /// meaning that the interpolation is at the relevant point on the timeline + /// between `a` and `b`. The interpolation can be extrapolated beyond 0.0 and + /// 1.0, so negative values and values greater than 1.0 are valid (and can + /// easily be generated by curves such as [Curves.elasticInOut]). + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + static SweepGradient? lerp(SweepGradient? a, SweepGradient? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!.scale(t); + } + if (b == null) { + return a.scale(1.0 - t); + } + final _ColorsAndStops interpolated = _interpolateColorsAndStops( + a.colors, + a._impliedStops(), + b.colors, + b._impliedStops(), + t, + ); + return SweepGradient( + center: AlignmentGeometry.lerp(a.center, b.center, t)!, + startAngle: math.max(0.0, ui.lerpDouble(a.startAngle, b.startAngle, t)!), + endAngle: math.max(0.0, ui.lerpDouble(a.endAngle, b.endAngle, t)!), + colors: interpolated.colors, + stops: interpolated.stops, + tileMode: t < 0.5 ? a.tileMode : b.tileMode, // TODO(ianh): interpolate tile mode + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is SweepGradient + && other.center == center + && other.startAngle == startAngle + && other.endAngle == endAngle + && other.tileMode == tileMode + && other.transform == transform + && listEquals<Color>(other.colors, colors) + && listEquals<double>(other.stops, stops); + } + + @override + int get hashCode => Object.hash( + center, + startAngle, + endAngle, + tileMode, + transform, + Object.hashAll(colors), + stops == null ? null : Object.hashAll(stops!), + ); + + @override + String toString() { + final List<String> description = <String>[ + 'center: $center', + 'startAngle: ${debugFormatDouble(startAngle)}', + 'endAngle: ${debugFormatDouble(endAngle)}', + 'colors: $colors', + if (stops != null) 'stops: $stops', + 'tileMode: $tileMode', + if (transform != null) 'transform: $transform', + ]; + + return '${objectRuntimeType(this, 'SweepGradient')}(${description.join(', ')})'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_cache.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_cache.dart new file mode 100644 index 0000000000000000000000000000000000000000..04b69a3f3d18f6849f8c290f417931e5ce42a271 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_cache.dart @@ -0,0 +1,663 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:developer'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; + +import 'image_stream.dart'; + +const int _kDefaultSize = 1000; +const int _kDefaultSizeBytes = 100 << 20; // 100 MiB + +/// Class for caching images. +/// +/// Implements a least-recently-used cache of up to 1000 images, and up to 100 +/// MB. The maximum size can be adjusted using [maximumSize] and +/// [maximumSizeBytes]. +/// +/// The cache also holds a list of 'live' references. An image is considered +/// live if its [ImageStreamCompleter]'s listener count has never dropped to +/// zero after adding at least one listener. The cache uses +/// [ImageStreamCompleter.addOnLastListenerRemovedCallback] to determine when +/// this has happened. +/// +/// The [putIfAbsent] method is the main entry-point to the cache API. It +/// returns the previously cached [ImageStreamCompleter] for the given key, if +/// available; if not, it calls the given callback to obtain it first. In either +/// case, the key is moved to the 'most recently used' position. +/// +/// A caller can determine whether an image is already in the cache by using +/// [containsKey], which will return true if the image is tracked by the cache +/// in a pending or completed state. More fine grained information is available +/// by using the [statusForKey] method. +/// +/// Generally this class is not used directly. The [ImageProvider] class and its +/// subclasses automatically handle the caching of images. +/// +/// A shared instance of this cache is retained by [PaintingBinding] and can be +/// obtained via the [imageCache] top-level property in the [painting] library. +/// +/// {@tool snippet} +/// +/// This sample shows how to supply your own caching logic and replace the +/// global [imageCache] variable. +/// +/// ```dart +/// /// This is the custom implementation of [ImageCache] where we can override +/// /// the logic. +/// class MyImageCache extends ImageCache { +/// @override +/// void clear() { +/// print('Clearing cache!'); +/// super.clear(); +/// } +/// } +/// +/// class MyWidgetsBinding extends WidgetsFlutterBinding { +/// @override +/// ImageCache createImageCache() => MyImageCache(); +/// } +/// +/// void main() { +/// // The constructor sets global variables. +/// MyWidgetsBinding(); +/// runApp(const MyApp()); +/// } +/// +/// class MyApp extends StatelessWidget { +/// const MyApp({super.key}); +/// +/// @override +/// Widget build(BuildContext context) { +/// return Container(); +/// } +/// } +/// ``` +/// {@end-tool} +class ImageCache { + final Map<Object, _PendingImage> _pendingImages = <Object, _PendingImage>{}; + final Map<Object, _CachedImage> _cache = <Object, _CachedImage>{}; + /// ImageStreamCompleters with at least one listener. These images may or may + /// not fit into the _pendingImages or _cache objects. + /// + /// Unlike _cache, the [_CachedImage] for this may have a null byte size. + final Map<Object, _LiveImage> _liveImages = <Object, _LiveImage>{}; + + /// Maximum number of entries to store in the cache. + /// + /// Once this many entries have been cached, the least-recently-used entry is + /// evicted when adding a new entry. + int get maximumSize => _maximumSize; + int _maximumSize = _kDefaultSize; + /// Changes the maximum cache size. + /// + /// If the new size is smaller than the current number of elements, the + /// extraneous elements are evicted immediately. Setting this to zero and then + /// returning it to its original value will therefore immediately clear the + /// cache. + set maximumSize(int value) { + assert(value >= 0); + if (value == maximumSize) { + return; + } + TimelineTask? debugTimelineTask; + if (!kReleaseMode) { + debugTimelineTask = TimelineTask()..start( + 'ImageCache.setMaximumSize', + arguments: <String, dynamic>{'value': value}, + ); + } + _maximumSize = value; + if (maximumSize == 0) { + clear(); + } else { + _checkCacheSize(debugTimelineTask); + } + if (!kReleaseMode) { + debugTimelineTask!.finish(); + } + } + + /// The current number of cached entries. + int get currentSize => _cache.length; + + /// Maximum size of entries to store in the cache in bytes. + /// + /// Once more than this amount of bytes have been cached, the + /// least-recently-used entry is evicted until there are fewer than the + /// maximum bytes. + int get maximumSizeBytes => _maximumSizeBytes; + int _maximumSizeBytes = _kDefaultSizeBytes; + /// Changes the maximum cache bytes. + /// + /// If the new size is smaller than the current size in bytes, the + /// extraneous elements are evicted immediately. Setting this to zero and then + /// returning it to its original value will therefore immediately clear the + /// cache. + set maximumSizeBytes(int value) { + assert(value >= 0); + if (value == _maximumSizeBytes) { + return; + } + TimelineTask? debugTimelineTask; + if (!kReleaseMode) { + debugTimelineTask = TimelineTask()..start( + 'ImageCache.setMaximumSizeBytes', + arguments: <String, dynamic>{'value': value}, + ); + } + _maximumSizeBytes = value; + if (_maximumSizeBytes == 0) { + clear(); + } else { + _checkCacheSize(debugTimelineTask); + } + if (!kReleaseMode) { + debugTimelineTask!.finish(); + } + } + + /// The current size of cached entries in bytes. + int get currentSizeBytes => _currentSizeBytes; + int _currentSizeBytes = 0; + + /// Evicts all pending and keepAlive entries from the cache. + /// + /// This is useful if, for instance, the root asset bundle has been updated + /// and therefore new images must be obtained. + /// + /// Images which have not finished loading yet will not be removed from the + /// cache, and when they complete they will be inserted as normal. + /// + /// This method does not clear live references to images, since clearing those + /// would not reduce memory pressure. Such images still have listeners in the + /// application code, and will still remain resident in memory. + /// + /// To clear live references, use [clearLiveImages]. + void clear() { + if (!kReleaseMode) { + Timeline.instantSync( + 'ImageCache.clear', + arguments: <String, dynamic>{ + 'pendingImages': _pendingImages.length, + 'keepAliveImages': _cache.length, + 'liveImages': _liveImages.length, + 'currentSizeInBytes': _currentSizeBytes, + }, + ); + } + for (final _CachedImage image in _cache.values) { + image.dispose(); + } + _cache.clear(); + for (final _PendingImage pendingImage in _pendingImages.values) { + pendingImage.removeListener(); + } + _pendingImages.clear(); + _currentSizeBytes = 0; + } + + /// Evicts a single entry from the cache, returning true if successful. + /// + /// Pending images waiting for completion are removed as well, returning true + /// if successful. When a pending image is removed the listener on it is + /// removed as well to prevent it from adding itself to the cache if it + /// eventually completes. + /// + /// If this method removes a pending image, it will also remove + /// the corresponding live tracking of the image, since it is no longer clear + /// if the image will ever complete or have any listeners, and failing to + /// remove the live reference could leave the cache in a state where all + /// subsequent calls to [putIfAbsent] will return an [ImageStreamCompleter] + /// that will never complete. + /// + /// If this method removes a completed image, it will _not_ remove the live + /// reference to the image, which will only be cleared when the listener + /// count on the completer drops to zero. To clear live image references, + /// whether completed or not, use [clearLiveImages]. + /// + /// The `key` must be equal to an object used to cache an image in + /// [ImageCache.putIfAbsent]. + /// + /// If the key is not immediately available, as is common, consider using + /// [ImageProvider.evict] to call this method indirectly instead. + /// + /// The `includeLive` argument determines whether images that still have + /// listeners in the tree should be evicted as well. This parameter should be + /// set to true in cases where the image may be corrupted and needs to be + /// completely discarded by the cache. It should be set to false when calls + /// to evict are trying to relieve memory pressure, since an image with a + /// listener will not actually be evicted from memory, and subsequent attempts + /// to load it will end up allocating more memory for the image again. + /// + /// See also: + /// + /// * [ImageProvider], for providing images to the [Image] widget. + bool evict(Object key, { bool includeLive = true }) { + if (includeLive) { + // Remove from live images - the cache will not be able to mark + // it as complete, and it might be getting evicted because it + // will never complete, e.g. it was loaded in a FakeAsync zone. + // In such a case, we need to make sure subsequent calls to + // putIfAbsent don't return this image that may never complete. + final _LiveImage? image = _liveImages.remove(key); + image?.dispose(); + } + final _PendingImage? pendingImage = _pendingImages.remove(key); + if (pendingImage != null) { + if (!kReleaseMode) { + Timeline.instantSync('ImageCache.evict', arguments: <String, dynamic>{ + 'type': 'pending', + }); + } + pendingImage.removeListener(); + return true; + } + final _CachedImage? image = _cache.remove(key); + if (image != null) { + if (!kReleaseMode) { + Timeline.instantSync('ImageCache.evict', arguments: <String, dynamic>{ + 'type': 'keepAlive', + 'sizeInBytes': image.sizeBytes, + }); + } + _currentSizeBytes -= image.sizeBytes!; + image.dispose(); + return true; + } + if (!kReleaseMode) { + Timeline.instantSync('ImageCache.evict', arguments: <String, dynamic>{ + 'type': 'miss', + }); + } + return false; + } + + /// Updates the least recently used image cache with this image, if it is + /// less than the [maximumSizeBytes] of this cache. + /// + /// Resizes the cache as appropriate to maintain the constraints of + /// [maximumSize] and [maximumSizeBytes]. + void _touch(Object key, _CachedImage image, TimelineTask? timelineTask) { + if (image.sizeBytes != null && image.sizeBytes! <= maximumSizeBytes && maximumSize > 0) { + _currentSizeBytes += image.sizeBytes!; + _cache[key] = image; + _checkCacheSize(timelineTask); + } else { + image.dispose(); + } + } + + void _trackLiveImage(Object key, ImageStreamCompleter completer, int? sizeBytes) { + // Avoid adding unnecessary callbacks to the completer. + _liveImages.putIfAbsent(key, () { + // Even if no callers to ImageProvider.resolve have listened to the stream, + // the cache is listening to the stream and will remove itself once the + // image completes to move it from pending to keepAlive. + // Even if the cache size is 0, we still add this tracker, which will add + // a keep alive handle to the stream. + return _LiveImage( + completer, + () { + _liveImages.remove(key); + }, + ); + }).sizeBytes ??= sizeBytes; + } + + /// Returns the previously cached [ImageStream] for the given key, if available; + /// if not, calls the given callback to obtain it first. In either case, the + /// key is moved to the 'most recently used' position. + /// + /// In the event that the loader throws an exception, it will be caught only if + /// `onError` is also provided. When an exception is caught resolving an image, + /// no completers are cached and `null` is returned instead of a new + /// completer. + /// + /// Images that are larger than [maximumSizeBytes] are not cached, and do not + /// cause other images in the cache to be evicted. + ImageStreamCompleter? putIfAbsent(Object key, ImageStreamCompleter Function() loader, { ImageErrorListener? onError }) { + TimelineTask? debugTimelineTask; + if (!kReleaseMode) { + debugTimelineTask = TimelineTask()..start( + 'ImageCache.putIfAbsent', + arguments: <String, dynamic>{ + 'key': key.toString(), + }, + ); + } + ImageStreamCompleter? result = _pendingImages[key]?.completer; + // Nothing needs to be done because the image hasn't loaded yet. + if (result != null) { + if (!kReleaseMode) { + debugTimelineTask!.finish(arguments: <String, dynamic>{'result': 'pending'}); + } + return result; + } + // Remove the provider from the list so that we can move it to the + // recently used position below. + // Don't use _touch here, which would trigger a check on cache size that is + // not needed since this is just moving an existing cache entry to the head. + final _CachedImage? image = _cache.remove(key); + if (image != null) { + if (!kReleaseMode) { + debugTimelineTask!.finish(arguments: <String, dynamic>{'result': 'keepAlive'}); + } + // The image might have been keptAlive but had no listeners (so not live). + // Make sure the cache starts tracking it as live again. + _trackLiveImage( + key, + image.completer, + image.sizeBytes, + ); + _cache[key] = image; + return image.completer; + } + + final _LiveImage? liveImage = _liveImages[key]; + if (liveImage != null) { + _touch( + key, + _CachedImage( + liveImage.completer, + sizeBytes: liveImage.sizeBytes, + ), + debugTimelineTask, + ); + if (!kReleaseMode) { + debugTimelineTask!.finish(arguments: <String, dynamic>{'result': 'keepAlive'}); + } + return liveImage.completer; + } + + try { + result = loader(); + _trackLiveImage(key, result, null); + } catch (error, stackTrace) { + if (!kReleaseMode) { + debugTimelineTask!.finish(arguments: <String, dynamic>{ + 'result': 'error', + 'error': error.toString(), + 'stackTrace': stackTrace.toString(), + }); + } + if (onError != null) { + onError(error, stackTrace); + return null; + } else { + rethrow; + } + } + + if (!kReleaseMode) { + debugTimelineTask!.start('listener'); + } + // A multi-frame provider may call the listener more than once. We need do make + // sure that some cleanup works won't run multiple times, such as finishing the + // tracing task or removing the listeners + bool listenedOnce = false; + + // We shouldn't use the _pendingImages map if the cache is disabled, but we + // will have to listen to the image at least once so we don't leak it in + // the live image tracking. + final bool trackPendingImage = maximumSize > 0 && maximumSizeBytes > 0; + late _PendingImage pendingImage; + void listener(ImageInfo? info, bool syncCall) { + int? sizeBytes; + if (info != null) { + sizeBytes = info.sizeBytes; + info.dispose(); + } + final _CachedImage image = _CachedImage( + result!, + sizeBytes: sizeBytes, + ); + + _trackLiveImage(key, result, sizeBytes); + + // Only touch if the cache was enabled when resolve was initially called. + if (trackPendingImage) { + _touch(key, image, debugTimelineTask); + } else { + image.dispose(); + } + + _pendingImages.remove(key); + if (!listenedOnce) { + pendingImage.removeListener(); + } + if (!kReleaseMode && !listenedOnce) { + debugTimelineTask! + ..finish(arguments: <String, dynamic>{ + 'syncCall': syncCall, + 'sizeInBytes': sizeBytes, + }) + ..finish(arguments: <String, dynamic>{ + 'currentSizeBytes': currentSizeBytes, + 'currentSize': currentSize, + }); + } + listenedOnce = true; + } + + final ImageStreamListener streamListener = ImageStreamListener(listener); + pendingImage = _PendingImage(result, streamListener); + if (trackPendingImage) { + _pendingImages[key] = pendingImage; + } + // Listener is removed in [_PendingImage.removeListener]. + result.addListener(streamListener); + + return result; + } + + /// The [ImageCacheStatus] information for the given `key`. + ImageCacheStatus statusForKey(Object key) { + return ImageCacheStatus._( + pending: _pendingImages.containsKey(key), + keepAlive: _cache.containsKey(key), + live: _liveImages.containsKey(key), + ); + } + + /// Returns whether this `key` has been previously added by [putIfAbsent]. + bool containsKey(Object key) { + return _pendingImages[key] != null || _cache[key] != null; + } + + /// The number of live images being held by the [ImageCache]. + /// + /// Compare with [ImageCache.currentSize] for keepAlive images. + int get liveImageCount => _liveImages.length; + + /// The number of images being tracked as pending in the [ImageCache]. + /// + /// Compare with [ImageCache.currentSize] for keepAlive images. + int get pendingImageCount => _pendingImages.length; + + /// Clears any live references to images in this cache. + /// + /// An image is considered live if its [ImageStreamCompleter] has never hit + /// zero listeners after adding at least one listener. The + /// [ImageStreamCompleter.addOnLastListenerRemovedCallback] is used to + /// determine when this has happened. + /// + /// This is called after a hot reload to evict any stale references to image + /// data for assets that have changed. Calling this method does not relieve + /// memory pressure, since the live image caching only tracks image instances + /// that are also being held by at least one other object. + void clearLiveImages() { + for (final _LiveImage image in _liveImages.values) { + image.dispose(); + } + _liveImages.clear(); + } + + // Remove images from the cache until both the length and bytes are below + // maximum, or the cache is empty. + void _checkCacheSize(TimelineTask? timelineTask) { + final Map<String, dynamic> finishArgs = <String, dynamic>{}; + if (!kReleaseMode) { + timelineTask!.start('checkCacheSize'); + finishArgs['evictedKeys'] = <String>[]; + finishArgs['currentSize'] = currentSize; + finishArgs['currentSizeBytes'] = currentSizeBytes; + } + while (_currentSizeBytes > _maximumSizeBytes || _cache.length > _maximumSize) { + final Object key = _cache.keys.first; + final _CachedImage image = _cache[key]!; + _currentSizeBytes -= image.sizeBytes!; + image.dispose(); + _cache.remove(key); + if (!kReleaseMode) { + (finishArgs['evictedKeys'] as List<String>).add(key.toString()); + } + } + if (!kReleaseMode) { + finishArgs['endSize'] = currentSize; + finishArgs['endSizeBytes'] = currentSizeBytes; + timelineTask!.finish(arguments: finishArgs); + } + assert(_currentSizeBytes >= 0); + assert(_cache.length <= maximumSize); + assert(_currentSizeBytes <= maximumSizeBytes); + } +} + +/// Information about how the [ImageCache] is tracking an image. +/// +/// A [pending] image is one that has not completed yet. It may also be tracked +/// as [live] because something is listening to it. +/// +/// A [keepAlive] image is being held in the cache, which uses Least Recently +/// Used semantics to determine when to evict an image. These images are subject +/// to eviction based on [ImageCache.maximumSizeBytes] and +/// [ImageCache.maximumSize]. It may be [live], but not [pending]. +/// +/// A [live] image is being held until its [ImageStreamCompleter] has no more +/// listeners. It may also be [pending] or [keepAlive]. +/// +/// An [untracked] image is not being cached. +/// +/// To obtain an [ImageCacheStatus], use [ImageCache.statusForKey] or +/// [ImageProvider.obtainCacheStatus]. +@immutable +class ImageCacheStatus { + const ImageCacheStatus._({ + this.pending = false, + this.keepAlive = false, + this.live = false, + }) : assert(!pending || !keepAlive); + + /// An image that has been submitted to [ImageCache.putIfAbsent], but + /// not yet completed. + final bool pending; + + /// An image that has been submitted to [ImageCache.putIfAbsent], has + /// completed, fits based on the sizing rules of the cache, and has not been + /// evicted. + /// + /// Such images will be kept alive even if [live] is false, as long + /// as they have not been evicted from the cache based on its sizing rules. + final bool keepAlive; + + /// An image that has been submitted to [ImageCache.putIfAbsent] and has at + /// least one listener on its [ImageStreamCompleter]. + /// + /// Such images may also be [keepAlive] if they fit in the cache based on its + /// sizing rules. They may also be [pending] if they have not yet resolved. + final bool live; + + /// An image that is tracked in some way by the [ImageCache], whether + /// [pending], [keepAlive], or [live]. + bool get tracked => pending || keepAlive || live; + + /// An image that either has not been submitted to + /// [ImageCache.putIfAbsent] or has otherwise been evicted from the + /// [keepAlive] and [live] caches. + bool get untracked => !pending && !keepAlive && !live; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ImageCacheStatus + && other.pending == pending + && other.keepAlive == keepAlive + && other.live == live; + } + + @override + int get hashCode => Object.hash(pending, keepAlive, live); + + @override + String toString() => '${objectRuntimeType(this, 'ImageCacheStatus')}(pending: $pending, live: $live, keepAlive: $keepAlive)'; +} + +/// Base class for [_CachedImage] and [_LiveImage]. +/// +/// Exists primarily so that a [_LiveImage] cannot be added to the +/// [ImageCache._cache]. +abstract class _CachedImageBase { + _CachedImageBase( + this.completer, { + this.sizeBytes, + }) : handle = completer.keepAlive(); + + final ImageStreamCompleter completer; + int? sizeBytes; + ImageStreamCompleterHandle? handle; + + @mustCallSuper + void dispose() { + assert(handle != null); + // Give any interested parties a chance to listen to the stream before we + // potentially dispose it. + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + assert(handle != null); + handle?.dispose(); + handle = null; + }, debugLabel: 'CachedImage.disposeHandle'); + } +} + +class _CachedImage extends _CachedImageBase { + _CachedImage(super.completer, {super.sizeBytes}); +} + +class _LiveImage extends _CachedImageBase { + _LiveImage(ImageStreamCompleter completer, VoidCallback handleRemove, {int? sizeBytes}) + : super(completer, sizeBytes: sizeBytes) { + _handleRemove = () { + handleRemove(); + dispose(); + }; + completer.addOnLastListenerRemovedCallback(_handleRemove); + } + + late VoidCallback _handleRemove; + + @override + void dispose() { + completer.removeOnLastListenerRemovedCallback(_handleRemove); + super.dispose(); + } + + @override + String toString() => describeIdentity(this); +} + +class _PendingImage { + _PendingImage(this.completer, this.listener); + + final ImageStreamCompleter completer; + final ImageStreamListener listener; + + void removeListener() { + completer.removeListener(listener); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_decoder.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_decoder.dart new file mode 100644 index 0000000000000000000000000000000000000000..328c840f7393f24095584fb2df5444116de6d290 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_decoder.dart @@ -0,0 +1,27 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:typed_data'; +import 'dart:ui' as ui show Codec, FrameInfo, Image, ImmutableBuffer; + +import 'binding.dart'; + +/// Creates an image from a list of bytes. +/// +/// This function attempts to interpret the given bytes an image. If successful, +/// the returned [Future] resolves to the decoded image. Otherwise, the [Future] +/// resolves to null. +/// +/// If the image is animated, this returns the first frame. Consider +/// [instantiateImageCodec] if support for animated images is necessary. +/// +/// This function differs from [ui.decodeImageFromList] in that it defers to +/// [PaintingBinding.instantiateImageCodecWithSize], and therefore can be mocked +/// in tests. +Future<ui.Image> decodeImageFromList(Uint8List bytes) async { + final ui.ImmutableBuffer buffer = await ui.ImmutableBuffer.fromUint8List(bytes); + final ui.Codec codec = await PaintingBinding.instance.instantiateImageCodecWithSize(buffer); + final ui.FrameInfo frameInfo = await codec.getNextFrame(); + return frameInfo.image; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_provider.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_provider.dart new file mode 100644 index 0000000000000000000000000000000000000000..1a03c04d9ba06f1208efd81c0d2f04add5620861 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_provider.dart @@ -0,0 +1,1757 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:io'; +import 'dart:math' as math; +import 'dart:ui' as ui; +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import '_network_image_io.dart' + if (dart.library.js_util) '_network_image_web.dart' as network_image; +import 'binding.dart'; +import 'image_cache.dart'; +import 'image_stream.dart'; + +/// Signature for the callback taken by [_createErrorHandlerAndKey]. +typedef _KeyAndErrorHandlerCallback<T> = void Function(T key, ImageErrorListener handleError); + +/// Signature used for error handling by [_createErrorHandlerAndKey]. +typedef _AsyncKeyErrorHandler<T> = Future<void> Function(T key, Object exception, StackTrace? stack); + +/// Configuration information passed to the [ImageProvider.resolve] method to +/// select a specific image. +/// +/// See also: +/// +/// * [createLocalImageConfiguration], which creates an [ImageConfiguration] +/// based on ambient configuration in a [Widget] environment. +/// * [ImageProvider], which uses [ImageConfiguration] objects to determine +/// which image to obtain. +@immutable +class ImageConfiguration { + /// Creates an object holding the configuration information for an [ImageProvider]. + /// + /// All the arguments are optional. Configuration information is merely + /// advisory and best-effort. + const ImageConfiguration({ + this.bundle, + this.devicePixelRatio, + this.locale, + this.textDirection, + this.size, + this.platform, + }); + + /// Creates an object holding the configuration information for an [ImageProvider]. + /// + /// All the arguments are optional. Configuration information is merely + /// advisory and best-effort. + ImageConfiguration copyWith({ + AssetBundle? bundle, + double? devicePixelRatio, + ui.Locale? locale, + TextDirection? textDirection, + Size? size, + TargetPlatform? platform, + }) { + return ImageConfiguration( + bundle: bundle ?? this.bundle, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + locale: locale ?? this.locale, + textDirection: textDirection ?? this.textDirection, + size: size ?? this.size, + platform: platform ?? this.platform, + ); + } + + /// The preferred [AssetBundle] to use if the [ImageProvider] needs one and + /// does not have one already selected. + final AssetBundle? bundle; + + /// The device pixel ratio where the image will be shown. + final double? devicePixelRatio; + + /// The language and region for which to select the image. + final ui.Locale? locale; + + /// The reading direction of the language for which to select the image. + final TextDirection? textDirection; + + /// The size at which the image will be rendered. + final Size? size; + + /// The [TargetPlatform] for which assets should be used. This allows images + /// to be specified in a platform-neutral fashion yet use different assets on + /// different platforms, to match local conventions e.g. for color matching or + /// shadows. + final TargetPlatform? platform; + + /// An image configuration that provides no additional information. + /// + /// Useful when resolving an [ImageProvider] without any context. + static const ImageConfiguration empty = ImageConfiguration(); + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ImageConfiguration + && other.bundle == bundle + && other.devicePixelRatio == devicePixelRatio + && other.locale == locale + && other.textDirection == textDirection + && other.size == size + && other.platform == platform; + } + + @override + int get hashCode => Object.hash(bundle, devicePixelRatio, locale, size, platform); + + @override + String toString() { + final StringBuffer result = StringBuffer(); + result.write('ImageConfiguration('); + bool hasArguments = false; + if (bundle != null) { + result.write('bundle: $bundle'); + hasArguments = true; + } + if (devicePixelRatio != null) { + if (hasArguments) { + result.write(', '); + } + result.write('devicePixelRatio: ${devicePixelRatio!.toStringAsFixed(1)}'); + hasArguments = true; + } + if (locale != null) { + if (hasArguments) { + result.write(', '); + } + result.write('locale: $locale'); + hasArguments = true; + } + if (textDirection != null) { + if (hasArguments) { + result.write(', '); + } + result.write('textDirection: $textDirection'); + hasArguments = true; + } + if (size != null) { + if (hasArguments) { + result.write(', '); + } + result.write('size: $size'); + hasArguments = true; + } + if (platform != null) { + if (hasArguments) { + result.write(', '); + } + result.write('platform: ${platform!.name}'); + hasArguments = true; + } + result.write(')'); + return result.toString(); + } +} + +/// Performs the decode process for use in [ImageProvider.loadBuffer]. +/// +/// This callback allows decoupling of the `cacheWidth`, `cacheHeight`, and +/// `allowUpscaling` parameters from implementations of [ImageProvider] that do +/// not expose them. +/// +/// See also: +/// +/// * [ResizeImage], which uses this to override the `cacheWidth`, +/// `cacheHeight`, and `allowUpscaling` parameters. +@Deprecated( + 'Use ImageDecoderCallback with ImageProvider.loadImage instead. ' + 'This feature was deprecated after v3.7.0-1.4.pre.', +) +typedef DecoderBufferCallback = Future<ui.Codec> Function(ui.ImmutableBuffer buffer, {int? cacheWidth, int? cacheHeight, bool allowUpscaling}); + +// Method signature for _loadAsync decode callbacks. +typedef _SimpleDecoderCallback = Future<ui.Codec> Function(ui.ImmutableBuffer buffer); + +/// Performs the decode process for use in [ImageProvider.loadImage]. +/// +/// This callback allows decoupling of the `getTargetSize` parameter from +/// implementations of [ImageProvider] that do not expose it. +/// +/// See also: +/// +/// * [ResizeImage], which uses this to load images at specific sizes. +typedef ImageDecoderCallback = Future<ui.Codec> Function( + ui.ImmutableBuffer buffer, { + ui.TargetImageSizeCallback? getTargetSize, +}); + +/// Identifies an image without committing to the precise final asset. This +/// allows a set of images to be identified and for the precise image to later +/// be resolved based on the environment, e.g. the device pixel ratio. +/// +/// To obtain an [ImageStream] from an [ImageProvider], call [resolve], +/// passing it an [ImageConfiguration] object. +/// +/// [ImageProvider] uses the global [imageCache] to cache images. +/// +/// The type argument `T` is the type of the object used to represent a resolved +/// configuration. This is also the type used for the key in the image cache. It +/// should be immutable and implement the [==] operator and the [hashCode] +/// getter. Subclasses should subclass a variant of [ImageProvider] with an +/// explicit `T` type argument. +/// +/// The type argument does not have to be specified when using the type as an +/// argument (where any image provider is acceptable). +/// +/// The following image formats are supported: {@macro dart.ui.imageFormats} +/// +/// ## Lifecycle of resolving an image +/// +/// The [ImageProvider] goes through the following lifecycle to resolve an +/// image, once the [resolve] method is called: +/// +/// 1. Create an [ImageStream] using [createStream] to return to the caller. +/// This stream will be used to communicate back to the caller when the +/// image is decoded and ready to display, or when an error occurs. +/// 2. Obtain the key for the image using [obtainKey]. +/// Calling this method can throw exceptions into the zone asynchronously +/// or into the call stack synchronously. To handle that, an error handler +/// is created that catches both synchronous and asynchronous errors, to +/// make sure errors can be routed to the correct consumers. +/// The error handler is passed on to [resolveStreamForKey] and the +/// [ImageCache]. +/// 3. If the key is successfully obtained, schedule resolution of the image +/// using that key. This is handled by [resolveStreamForKey]. That method +/// may fizzle if it determines the image is no longer necessary, use the +/// provided [ImageErrorListener] to report an error, set the completer +/// from the cache if possible, or call [loadImage] to fetch the encoded image +/// bytes and schedule decoding. +/// 4. The [loadImage] method is responsible for both fetching the encoded bytes +/// and decoding them using the provided [ImageDecoderCallback]. It is called +/// in a context that uses the [ImageErrorListener] to report errors back. +/// +/// Subclasses normally only have to implement the [loadImage] and [obtainKey] +/// methods. A subclass that needs finer grained control over the [ImageStream] +/// type must override [createStream]. A subclass that needs finer grained +/// control over the resolution, such as delaying calling [loadImage], must override +/// [resolveStreamForKey]. +/// +/// The [resolve] method is marked as [nonVirtual] so that [ImageProvider]s can +/// be properly composed, and so that the base class can properly set up error +/// handling for subsequent methods. +/// +/// ## Using an [ImageProvider] +/// +/// {@tool snippet} +/// +/// The following shows the code required to write a widget that fully conforms +/// to the [ImageProvider] and [Widget] protocols. (It is essentially a +/// bare-bones version of the [widgets.Image] widget.) +/// +/// ```dart +/// class MyImage extends StatefulWidget { +/// const MyImage({ +/// super.key, +/// required this.imageProvider, +/// }); +/// +/// final ImageProvider imageProvider; +/// +/// @override +/// State<MyImage> createState() => _MyImageState(); +/// } +/// +/// class _MyImageState extends State<MyImage> { +/// ImageStream? _imageStream; +/// ImageInfo? _imageInfo; +/// +/// @override +/// void didChangeDependencies() { +/// super.didChangeDependencies(); +/// // We call _getImage here because createLocalImageConfiguration() needs to +/// // be called again if the dependencies changed, in case the changes relate +/// // to the DefaultAssetBundle, MediaQuery, etc, which that method uses. +/// _getImage(); +/// } +/// +/// @override +/// void didUpdateWidget(MyImage oldWidget) { +/// super.didUpdateWidget(oldWidget); +/// if (widget.imageProvider != oldWidget.imageProvider) { +/// _getImage(); +/// } +/// } +/// +/// void _getImage() { +/// final ImageStream? oldImageStream = _imageStream; +/// _imageStream = widget.imageProvider.resolve(createLocalImageConfiguration(context)); +/// if (_imageStream!.key != oldImageStream?.key) { +/// // If the keys are the same, then we got the same image back, and so we don't +/// // need to update the listeners. If the key changed, though, we must make sure +/// // to switch our listeners to the new image stream. +/// final ImageStreamListener listener = ImageStreamListener(_updateImage); +/// oldImageStream?.removeListener(listener); +/// _imageStream!.addListener(listener); +/// } +/// } +/// +/// void _updateImage(ImageInfo imageInfo, bool synchronousCall) { +/// setState(() { +/// // Trigger a build whenever the image changes. +/// _imageInfo?.dispose(); +/// _imageInfo = imageInfo; +/// }); +/// } +/// +/// @override +/// void dispose() { +/// _imageStream?.removeListener(ImageStreamListener(_updateImage)); +/// _imageInfo?.dispose(); +/// _imageInfo = null; +/// super.dispose(); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return RawImage( +/// image: _imageInfo?.image, // this is a dart:ui Image object +/// scale: _imageInfo?.scale ?? 1.0, +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// ## Creating an [ImageProvider] +/// +/// {@tool dartpad} +/// In this example, a variant of [NetworkImage] is created that passes all the +/// [ImageConfiguration] information (locale, platform, size, etc) to the server +/// using query arguments in the image URL. +/// +/// ** See code in examples/api/lib/painting/image_provider/image_provider.0.dart ** +/// {@end-tool} +@optionalTypeArgs +abstract class ImageProvider<T extends Object> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const ImageProvider(); + + /// Resolves this image provider using the given `configuration`, returning + /// an [ImageStream]. + /// + /// This is the public entry-point of the [ImageProvider] class hierarchy. + /// + /// Subclasses should implement [obtainKey] and [loadImage], which are used by + /// this method. If they need to change the implementation of [ImageStream] + /// used, they should override [createStream]. If they need to manage the + /// actual resolution of the image, they should override [resolveStreamForKey]. + /// + /// See the Lifecycle documentation on [ImageProvider] for more information. + @nonVirtual + ImageStream resolve(ImageConfiguration configuration) { + final ImageStream stream = createStream(configuration); + // Load the key (potentially asynchronously), set up an error handling zone, + // and call resolveStreamForKey. + _createErrorHandlerAndKey( + configuration, + (T key, ImageErrorListener errorHandler) { + resolveStreamForKey(configuration, stream, key, errorHandler); + }, + (T? key, Object exception, StackTrace? stack) async { + await null; // wait an event turn in case a listener has been added to the image stream. + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<ImageProvider>('Image provider', this), + DiagnosticsProperty<ImageConfiguration>('Image configuration', configuration), + DiagnosticsProperty<T>('Image key', key, defaultValue: null), + ]; + return true; + }()); + if (stream.completer == null) { + stream.setCompleter(_ErrorImageCompleter()); + } + stream.completer!.reportError( + exception: exception, + stack: stack, + context: ErrorDescription('while resolving an image'), + silent: true, // could be a network error or whatnot + informationCollector: collector, + ); + }, + ); + return stream; + } + + /// Called by [resolve] to create the [ImageStream] it returns. + /// + /// Subclasses should override this instead of [resolve] if they need to + /// return some subclass of [ImageStream]. The stream created here will be + /// passed to [resolveStreamForKey]. + @protected + ImageStream createStream(ImageConfiguration configuration) { + return ImageStream(); + } + + /// Returns the cache location for the key that this [ImageProvider] creates. + /// + /// The location may be [ImageCacheStatus.untracked], indicating that this + /// image provider's key is not available in the [ImageCache]. + /// + /// If the `handleError` parameter is null, errors will be reported to + /// [FlutterError.onError], and the method will return null. + /// + /// A completed return value of null indicates that an error has occurred. + Future<ImageCacheStatus?> obtainCacheStatus({ + required ImageConfiguration configuration, + ImageErrorListener? handleError, + }) { + final Completer<ImageCacheStatus?> completer = Completer<ImageCacheStatus?>(); + _createErrorHandlerAndKey( + configuration, + (T key, ImageErrorListener innerHandleError) { + completer.complete(PaintingBinding.instance.imageCache.statusForKey(key)); + }, + (T? key, Object exception, StackTrace? stack) async { + if (handleError != null) { + handleError(exception, stack); + } else { + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<ImageProvider>('Image provider', this), + DiagnosticsProperty<ImageConfiguration>('Image configuration', configuration), + DiagnosticsProperty<T>('Image key', key, defaultValue: null), + ]; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + context: ErrorDescription('while checking the cache location of an image'), + informationCollector: collector, + exception: exception, + stack: stack, + )); + completer.complete(); + } + }, + ); + return completer.future; + } + + /// This method is used by both [resolve] and [obtainCacheStatus] to ensure + /// that errors thrown during key creation are handled whether synchronous or + /// asynchronous. + void _createErrorHandlerAndKey( + ImageConfiguration configuration, + _KeyAndErrorHandlerCallback<T> successCallback, + _AsyncKeyErrorHandler<T?> errorCallback, + ) { + T? obtainedKey; + bool didError = false; + Future<void> handleError(Object exception, StackTrace? stack) async { + if (didError) { + return; + } + if (!didError) { + didError = true; + errorCallback(obtainedKey, exception, stack); + } + } + + Future<T> key; + try { + key = obtainKey(configuration); + } catch (error, stackTrace) { + handleError(error, stackTrace); + return; + } + key.then<void>((T key) { + obtainedKey = key; + try { + successCallback(key, handleError); + } catch (error, stackTrace) { + handleError(error, stackTrace); + } + }).catchError(handleError); + } + + /// Called by [resolve] with the key returned by [obtainKey]. + /// + /// Subclasses should override this method rather than calling [obtainKey] if + /// they need to use a key directly. The [resolve] method installs appropriate + /// error handling guards so that errors will bubble up to the right places in + /// the framework, and passes those guards along to this method via the + /// [handleError] parameter. + /// + /// It is safe for the implementation of this method to call [handleError] + /// multiple times if multiple errors occur, or if an error is thrown both + /// synchronously into the current part of the stack and thrown into the + /// enclosing [Zone]. + /// + /// The default implementation uses the key to interact with the [ImageCache], + /// calling [ImageCache.putIfAbsent] and notifying listeners of the [stream]. + /// Implementers that do not call super are expected to correctly use the + /// [ImageCache]. + @protected + void resolveStreamForKey(ImageConfiguration configuration, ImageStream stream, T key, ImageErrorListener handleError) { + // This is an unusual edge case where someone has told us that they found + // the image we want before getting to this method. We should avoid calling + // load again, but still update the image cache with LRU information. + if (stream.completer != null) { + final ImageStreamCompleter? completer = PaintingBinding.instance.imageCache.putIfAbsent( + key, + () => stream.completer!, + onError: handleError, + ); + assert(identical(completer, stream.completer)); + return; + } + final ImageStreamCompleter? completer = PaintingBinding.instance.imageCache.putIfAbsent( + key, + () { + ImageStreamCompleter result = loadImage(key, PaintingBinding.instance.instantiateImageCodecWithSize); + // This check exists as a fallback for backwards compatibility until the + // deprecated `loadBuffer()` method is removed. Until then, ImageProvider + // subclasses may have only overridden `loadBuffer()`, in which case the + // base implementation of `loadWithSize()` will return a sentinel value + // of type `_AbstractImageStreamCompleter`. + if (result is _AbstractImageStreamCompleter) { + result = loadBuffer(key, PaintingBinding.instance.instantiateImageCodecFromBuffer); + } + return result; + }, + onError: handleError, + ); + if (completer != null) { + stream.setCompleter(completer); + } + } + + /// Evicts an entry from the image cache. + /// + /// Returns a [Future] which indicates whether the value was successfully + /// removed. + /// + /// The [ImageProvider] used does not need to be the same instance that was + /// passed to an [Image] widget, but it does need to create a key which is + /// equal to one. + /// + /// The [cache] is optional and defaults to the global image cache. + /// + /// The [configuration] is optional and defaults to + /// [ImageConfiguration.empty]. + /// + /// {@tool snippet} + /// + /// The following sample code shows how an image loaded using the [Image] + /// widget can be evicted using a [NetworkImage] with a matching URL. + /// + /// ```dart + /// class MyWidget extends StatelessWidget { + /// const MyWidget({ + /// super.key, + /// this.url = ' ... ', + /// }); + /// + /// final String url; + /// + /// @override + /// Widget build(BuildContext context) { + /// return Image.network(url); + /// } + /// + /// void evictImage() { + /// final NetworkImage provider = NetworkImage(url); + /// provider.evict().then<void>((bool success) { + /// if (success) { + /// debugPrint('removed image!'); + /// } + /// }); + /// } + /// } + /// ``` + /// {@end-tool} + Future<bool> evict({ ImageCache? cache, ImageConfiguration configuration = ImageConfiguration.empty }) async { + cache ??= imageCache; + final T key = await obtainKey(configuration); + return cache.evict(key); + } + + /// Converts an [ImageProvider]'s settings plus an [ImageConfiguration] to a key + /// that describes the precise image to load. + /// + /// The type of the key is determined by the subclass. It is a value that + /// unambiguously identifies the image (_including its scale_) that the + /// [loadImage] method will fetch. Different [ImageProvider]s given the same + /// constructor arguments and [ImageConfiguration] objects should return keys + /// that are '==' to each other (possibly by using a class for the key that + /// itself implements [==]). + /// + /// If the result can be determined synchronously, this function should return + /// a [SynchronousFuture]. This allows image resolution to progress + /// synchronously during a frame rather than delaying image loading. + Future<T> obtainKey(ImageConfiguration configuration); + + /// Converts a key into an [ImageStreamCompleter], and begins fetching the + /// image. + /// + /// This method is deprecated. Implement [loadImage] instead. + /// + /// The [decode] callback provides the logic to obtain the codec for the + /// image. + /// + /// See also: + /// + /// * [ResizeImage], for modifying the key to account for cache dimensions. + @protected + @Deprecated( + 'Implement loadImage for image loading. ' + 'This feature was deprecated after v3.7.0-1.4.pre.', + ) + ImageStreamCompleter loadBuffer(T key, DecoderBufferCallback decode) { + return _AbstractImageStreamCompleter(); + } + + /// Converts a key into an [ImageStreamCompleter], and begins fetching the + /// image. + /// + /// For backwards-compatibility the default implementation of this method returns + /// an object that will cause [resolveStreamForKey] to consult [loadBuffer]. + /// However, implementors of this interface should only override this method + /// and not [loadBuffer], which is deprecated. + /// + /// The [decode] callback provides the logic to obtain the codec for the + /// image. + /// + /// See also: + /// + /// * [ResizeImage], for modifying the key to account for cache dimensions. + // TODO(tvolkert): make abstract (https://github.com/flutter/flutter/issues/119209) + @protected + ImageStreamCompleter loadImage(T key, ImageDecoderCallback decode) { + return _AbstractImageStreamCompleter(); + } + + @override + String toString() => '${objectRuntimeType(this, 'ImageConfiguration')}()'; +} + +/// A class that exists to facilitate backwards compatibility in the transition +/// from [ImageProvider.load] to [ImageProvider.loadBuffer] to [ImageProvider.loadImage] +class _AbstractImageStreamCompleter extends ImageStreamCompleter {} + +/// Key for the image obtained by an [AssetImage] or [ExactAssetImage]. +/// +/// This is used to identify the precise resource in the [imageCache]. +@immutable +class AssetBundleImageKey { + /// Creates the key for an [AssetImage] or [AssetBundleImageProvider]. + const AssetBundleImageKey({ + required this.bundle, + required this.name, + required this.scale, + }); + + /// The bundle from which the image will be obtained. + /// + /// The image is obtained by calling [AssetBundle.load] on the given [bundle] + /// using the key given by [name]. + final AssetBundle bundle; + + /// The key to use to obtain the resource from the [bundle]. This is the + /// argument passed to [AssetBundle.load]. + final String name; + + /// The scale to place in the [ImageInfo] object of the image. + final double scale; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is AssetBundleImageKey + && other.bundle == bundle + && other.name == name + && other.scale == scale; + } + + @override + int get hashCode => Object.hash(bundle, name, scale); + + @override + String toString() => '${objectRuntimeType(this, 'AssetBundleImageKey')}(bundle: $bundle, name: "$name", scale: $scale)'; +} + +/// A subclass of [ImageProvider] that knows about [AssetBundle]s. +/// +/// This factors out the common logic of [AssetBundle]-based [ImageProvider] +/// classes, simplifying what subclasses must implement to just [obtainKey]. +abstract class AssetBundleImageProvider extends ImageProvider<AssetBundleImageKey> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const AssetBundleImageProvider(); + + @override + ImageStreamCompleter loadImage(AssetBundleImageKey key, ImageDecoderCallback decode) { + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<ImageProvider>('Image provider', this), + DiagnosticsProperty<AssetBundleImageKey>('Image key', key), + ]; + return true; + }()); + return MultiFrameImageStreamCompleter( + codec: _loadAsync(key, decode: decode), + scale: key.scale, + debugLabel: key.name, + informationCollector: collector, + ); + } + + /// Converts a key into an [ImageStreamCompleter], and begins fetching the + /// image. + @override + ImageStreamCompleter loadBuffer(AssetBundleImageKey key, DecoderBufferCallback decode) { + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<ImageProvider>('Image provider', this), + DiagnosticsProperty<AssetBundleImageKey>('Image key', key), + ]; + return true; + }()); + return MultiFrameImageStreamCompleter( + codec: _loadAsync(key, decode: decode), + scale: key.scale, + debugLabel: key.name, + informationCollector: collector, + ); + } + + /// Fetches the image from the asset bundle, decodes it, and returns a + /// corresponding [ImageInfo] object. + /// + /// This function is used by [loadImage]. + @protected + Future<ui.Codec> _loadAsync( + AssetBundleImageKey key, { + required _SimpleDecoderCallback decode, + }) async { + final ui.ImmutableBuffer buffer; + // Hot reload/restart could change whether an asset bundle or key in a + // bundle are available, or if it is a network backed bundle. + try { + buffer = await key.bundle.loadBuffer(key.name); + } on FlutterError { + PaintingBinding.instance.imageCache.evict(key); + rethrow; + } + return decode(buffer); + } +} + +/// Key used internally by [ResizeImage]. +/// +/// This is used to identify the precise resource in the [imageCache]. +@immutable +class ResizeImageKey { + // Private constructor so nobody from the outside can poison the image cache + // with this key. It's only accessible to [ResizeImage] internally. + const ResizeImageKey._(this._providerCacheKey, this._policy, this._width, this._height, this._allowUpscaling); + + final Object _providerCacheKey; + final ResizeImagePolicy _policy; + final int? _width; + final int? _height; + final bool _allowUpscaling; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ResizeImageKey + && other._providerCacheKey == _providerCacheKey + && other._policy == _policy + && other._width == _width + && other._height == _height + && other._allowUpscaling == _allowUpscaling; + } + + @override + int get hashCode => Object.hash(_providerCacheKey, _policy, _width, _height, _allowUpscaling); +} + +/// Configures the behavior for [ResizeImage]. +/// +/// This is used in [ResizeImage.policy] to affect how the [ResizeImage.width] +/// and [ResizeImage.height] properties are interpreted. +enum ResizeImagePolicy { + /// Sizes the image to the exact width and height specified by + /// [ResizeImage.width] and [ResizeImage.height]. + /// + /// If [ResizeImage.width] and [ResizeImage.height] are both non-null, the + /// output image will have the specified width and height (with the + /// corresponding aspect ratio) regardless of whether it matches the source + /// image's intrinsic aspect ratio. This case is similar to [BoxFit.fill]. + /// + /// If only one of `width` and `height` is non-null, then the output image + /// will be scaled to the associated width or height, and the other dimension + /// will take whatever value is needed to maintain the image's original aspect + /// ratio. These cases are simnilar to [BoxFit.fitWidth] and + /// [BoxFit.fitHeight], respectively. + /// + /// If [ResizeImage.allowUpscaling] is false (the default), the width and the + /// height of the output image will each be clamped to the intrinsic width and + /// height of the image. This may result in a different aspect ratio than the + /// aspect ratio specified by the target width and height (e.g. if the height + /// gets clamped downwards but the width does not). + /// + /// ## Examples + /// + /// The examples below show how [ResizeImagePolicy.exact] works in various + /// scenarios. In each example, the source image has a size of 300x200 + /// (landscape orientation), the red box is a 150x150 square, and the green + /// box is a 400x400 square. + /// + /// <table> + /// <tr> + /// <td>Scenario</td> + /// <td>Output</td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// width: 150, + /// height: 150, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_exact_150x150_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// width: 150, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_exact_150xnull_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// height: 150, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_exact_nullx150_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// width: 400, + /// height: 400, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_exact_400x400_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// width: 400, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_exact_400xnull_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// height: 400, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_exact_nullx400_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// width: 400, + /// height: 400, + /// allowUpscaling: true, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_exact_400x400_true.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// width: 400, + /// allowUpscaling: true, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_exact_400xnull_true.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// height: 400, + /// allowUpscaling: true, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_exact_nullx400_true.png) + /// + /// </td> + /// </tr> + /// </table> + exact, + + /// Scales the image as necessary to ensure that it fits within the bounding + /// box specified by [ResizeImage.width] and [ResizeImage.height] while + /// maintaining its aspect ratio. + /// + /// If [ResizeImage.allowUpscaling] is true, the image will be scaled up or + /// down to best fit the bounding box; otherwise it will only ever be scaled + /// down. + /// + /// This is conceptually similar to [BoxFit.contain]. + /// + /// ## Examples + /// + /// The examples below show how [ResizeImagePolicy.fit] works in various + /// scenarios. In each example, the source image has a size of 300x200 + /// (landscape orientation), the red box is a 150x150 square, and the green + /// box is a 400x400 square. + /// + /// <table> + /// <tr> + /// <td>Scenario</td> + /// <td>Output</td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// policy: ResizeImagePolicy.fit, + /// width: 150, + /// height: 150, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_fit_150x150_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// policy: ResizeImagePolicy.fit, + /// width: 150, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_fit_150xnull_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// policy: ResizeImagePolicy.fit, + /// height: 150, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_fit_nullx150_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// policy: ResizeImagePolicy.fit, + /// width: 400, + /// height: 400, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_fit_400x400_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// policy: ResizeImagePolicy.fit, + /// width: 400, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_fit_400xnull_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// policy: ResizeImagePolicy.fit, + /// height: 400, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_fit_nullx400_false.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// policy: ResizeImagePolicy.fit, + /// width: 400, + /// height: 400, + /// allowUpscaling: true, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_fit_400x400_true.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// policy: ResizeImagePolicy.fit, + /// width: 400, + /// allowUpscaling: true, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_fit_400xnull_true.png) + /// + /// </td> + /// </tr> + /// <tr> + /// <td> + /// + /// ```dart + /// const ResizeImage( + /// AssetImage('dragon_cake.jpg'), + /// policy: ResizeImagePolicy.fit, + /// height: 400, + /// allowUpscaling: true, + /// ) + /// ``` + /// + /// </td> + /// <td> + /// + /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/resize_image_policy_fit_nullx400_true.png) + /// + /// </td> + /// </tr> + /// </table> + fit, +} + +/// Instructs Flutter to decode the image at the specified dimensions +/// instead of at its native size. +/// +/// This allows finer control of the size of the image in [ImageCache] and is +/// generally used to reduce the memory footprint of [ImageCache]. +/// +/// The decoded image may still be displayed at sizes other than the +/// cached size provided here. +class ResizeImage extends ImageProvider<ResizeImageKey> { + /// Creates an ImageProvider that decodes the image to the specified size. + /// + /// The cached image will be directly decoded and stored at the resolution + /// defined by `width` and `height`. The image will lose detail and + /// use less memory if resized to a size smaller than the native size. + /// + /// At least one of `width` and `height` must be non-null. + const ResizeImage( + this.imageProvider, { + this.width, + this.height, + this.policy = ResizeImagePolicy.exact, + this.allowUpscaling = false, + }) : assert(width != null || height != null); + + /// The [ImageProvider] that this class wraps. + final ImageProvider imageProvider; + + /// The width the image should decode to and cache. + /// + /// At least one of this and [height] must be non-null. + final int? width; + + /// The height the image should decode to and cache. + /// + /// At least one of this and [width] must be non-null. + final int? height; + + /// The policy that determines how [width] and [height] are interpreted. + /// + /// Defaults to [ResizeImagePolicy.exact]. + final ResizeImagePolicy policy; + + /// Whether the [width] and [height] parameters should be clamped to the + /// intrinsic width and height of the image. + /// + /// In general, it is better for memory usage to avoid scaling the image + /// beyond its intrinsic dimensions when decoding it. If there is a need to + /// scale an image larger, it is better to apply a scale to the canvas, or + /// to use an appropriate [Image.fit]. + final bool allowUpscaling; + + /// Composes the `provider` in a [ResizeImage] only when `cacheWidth` and + /// `cacheHeight` are not both null. + /// + /// When `cacheWidth` and `cacheHeight` are both null, this will return the + /// `provider` directly. + static ImageProvider<Object> resizeIfNeeded(int? cacheWidth, int? cacheHeight, ImageProvider<Object> provider) { + if (cacheWidth != null || cacheHeight != null) { + return ResizeImage(provider, width: cacheWidth, height: cacheHeight); + } + return provider; + } + + @override + @Deprecated( + 'Implement loadImage for image loading. ' + 'This feature was deprecated after v3.7.0-1.4.pre.', + ) + ImageStreamCompleter loadBuffer(ResizeImageKey key, DecoderBufferCallback decode) { + Future<ui.Codec> decodeResize(ui.ImmutableBuffer buffer, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { + assert( + cacheWidth == null && cacheHeight == null && allowUpscaling == null, + 'ResizeImage cannot be composed with another ImageProvider that applies ' + 'cacheWidth, cacheHeight, or allowUpscaling.', + ); + return decode(buffer, cacheWidth: width, cacheHeight: height, allowUpscaling: this.allowUpscaling); + } + + final ImageStreamCompleter completer = imageProvider.loadBuffer(key._providerCacheKey, decodeResize); + if (!kReleaseMode) { + completer.debugLabel = '${completer.debugLabel} - Resized(${key._width}×${key._height})'; + } + _configureErrorListener(completer, key); + return completer; + } + + @override + ImageStreamCompleter loadImage(ResizeImageKey key, ImageDecoderCallback decode) { + Future<ui.Codec> decodeResize(ui.ImmutableBuffer buffer, {ui.TargetImageSizeCallback? getTargetSize}) { + assert( + getTargetSize == null, + 'ResizeImage cannot be composed with another ImageProvider that applies ' + 'getTargetSize.', + ); + return decode(buffer, getTargetSize: (int intrinsicWidth, int intrinsicHeight) { + switch (policy) { + case ResizeImagePolicy.exact: + int? targetWidth = width; + int? targetHeight = height; + + if (!allowUpscaling) { + if (targetWidth != null && targetWidth > intrinsicWidth) { + targetWidth = intrinsicWidth; + } + if (targetHeight != null && targetHeight > intrinsicHeight) { + targetHeight = intrinsicHeight; + } + } + + return ui.TargetImageSize(width: targetWidth, height: targetHeight); + case ResizeImagePolicy.fit: + final double aspectRatio = intrinsicWidth / intrinsicHeight; + final int maxWidth = width ?? intrinsicWidth; + final int maxHeight = height ?? intrinsicHeight; + int targetWidth = intrinsicWidth; + int targetHeight = intrinsicHeight; + + if (targetWidth > maxWidth) { + targetWidth = maxWidth; + targetHeight = targetWidth ~/ aspectRatio; + } + + if (targetHeight > maxHeight) { + targetHeight = maxHeight; + targetWidth = (targetHeight * aspectRatio).floor(); + } + + if (allowUpscaling) { + if (width == null) { + assert(height != null); + targetHeight = height!; + targetWidth = (targetHeight * aspectRatio).floor(); + } else if (height == null) { + targetWidth = width!; + targetHeight = targetWidth ~/ aspectRatio; + } else { + final int derivedMaxWidth = (maxHeight * aspectRatio).floor(); + final int derivedMaxHeight = maxWidth ~/ aspectRatio; + targetWidth = math.min(maxWidth, derivedMaxWidth); + targetHeight = math.min(maxHeight, derivedMaxHeight); + } + } + + return ui.TargetImageSize(width: targetWidth, height: targetHeight); + } + }); + } + + final ImageStreamCompleter completer = imageProvider.loadImage(key._providerCacheKey, decodeResize); + if (!kReleaseMode) { + completer.debugLabel = '${completer.debugLabel} - Resized(${key._width}×${key._height})'; + } + _configureErrorListener(completer, key); + return completer; + } + + void _configureErrorListener(ImageStreamCompleter completer, ResizeImageKey key) { + completer.addEphemeralErrorListener((Object exception, StackTrace? stackTrace) { + // The microtask is scheduled because of the same reason as NetworkImage: + // Depending on where the exception was thrown, the image cache may not + // have had a chance to track the key in the cache at all. + // Schedule a microtask to give the cache a chance to add the key. + scheduleMicrotask(() { + PaintingBinding.instance.imageCache.evict(key); + }); + }); + } + + @override + Future<ResizeImageKey> obtainKey(ImageConfiguration configuration) { + Completer<ResizeImageKey>? completer; + // If the imageProvider.obtainKey future is synchronous, then we will be able to fill in result with + // a value before completer is initialized below. + SynchronousFuture<ResizeImageKey>? result; + imageProvider.obtainKey(configuration).then((Object key) { + if (completer == null) { + // This future has completed synchronously (completer was never assigned), + // so we can directly create the synchronous result to return. + result = SynchronousFuture<ResizeImageKey>(ResizeImageKey._(key, policy, width, height, allowUpscaling)); + } else { + // This future did not synchronously complete. + completer.complete(ResizeImageKey._(key, policy, width, height, allowUpscaling)); + } + }); + if (result != null) { + return result!; + } + // If the code reaches here, it means the imageProvider.obtainKey was not + // completed sync, so we initialize the completer for completion later. + completer = Completer<ResizeImageKey>(); + return completer.future; + } +} + +/// Fetches the given URL from the network, associating it with the given scale. +/// +/// The image will be cached regardless of cache headers from the server. +/// +/// When a network image is used on the Web platform, the `getTargetSize` +/// parameter of the [ImageDecoderCallback] is only supported when the +/// application is running with the CanvasKit renderer. When the application is +/// using the HTML renderer, the web engine delegates image decoding of network +/// images to the Web, which does not support custom decode sizes. +/// +/// See also: +/// +/// * [Image.network] for a shorthand of an [Image] widget backed by [NetworkImage]. +/// * The example at [ImageProvider], which shows a custom variant of this class +/// that applies different logic for fetching the image. +// TODO(ianh): Find some way to honor cache headers to the extent that when the +// last reference to an image is released, we proactively evict the image from +// our cache if the headers describe the image as having expired at that point. +abstract class NetworkImage extends ImageProvider<NetworkImage> { + /// Creates an object that fetches the image at the given URL. + /// + /// The [scale] argument is the linear scale factor for drawing this image at + /// its intended size. See [ImageInfo.scale] for more information. + const factory NetworkImage(String url, { double scale, Map<String, String>? headers }) = network_image.NetworkImage; + + /// The URL from which the image will be fetched. + String get url; + + /// The scale to place in the [ImageInfo] object of the image. + double get scale; + + /// The HTTP headers that will be used with [HttpClient.get] to fetch image from network. + /// + /// When running Flutter on the web, headers are not used. + Map<String, String>? get headers; + + @override + ImageStreamCompleter loadBuffer(NetworkImage key, DecoderBufferCallback decode); + + @override + ImageStreamCompleter loadImage(NetworkImage key, ImageDecoderCallback decode); +} + +/// Decodes the given [File] object as an image, associating it with the given +/// scale. +/// +/// The provider does not monitor the file for changes. If you expect the +/// underlying data to change, you should call the [evict] method. +/// +/// See also: +/// +/// * [Image.file] for a shorthand of an [Image] widget backed by [FileImage]. +@immutable +class FileImage extends ImageProvider<FileImage> { + /// Creates an object that decodes a [File] as an image. + const FileImage(this.file, { this.scale = 1.0 }); + + /// The file to decode into an image. + final File file; + + /// The scale to place in the [ImageInfo] object of the image. + final double scale; + + @override + Future<FileImage> obtainKey(ImageConfiguration configuration) { + return SynchronousFuture<FileImage>(this); + } + + @override + ImageStreamCompleter loadBuffer(FileImage key, DecoderBufferCallback decode) { + return MultiFrameImageStreamCompleter( + codec: _loadAsync(key, decode: decode), + scale: key.scale, + debugLabel: key.file.path, + informationCollector: () => <DiagnosticsNode>[ + ErrorDescription('Path: ${file.path}'), + ], + ); + } + + @override + @protected + ImageStreamCompleter loadImage(FileImage key, ImageDecoderCallback decode) { + return MultiFrameImageStreamCompleter( + codec: _loadAsync(key, decode: decode), + scale: key.scale, + debugLabel: key.file.path, + informationCollector: () => <DiagnosticsNode>[ + ErrorDescription('Path: ${file.path}'), + ], + ); + } + + Future<ui.Codec> _loadAsync( + FileImage key, { + required _SimpleDecoderCallback decode, + }) async { + assert(key == this); + // TODO(jonahwilliams): making this sync caused test failures that seem to + // indicate that we can fail to call evict unless at least one await has + // occurred in the test. + // https://github.com/flutter/flutter/issues/113044 + final int lengthInBytes = await file.length(); + if (lengthInBytes == 0) { + // The file may become available later. + PaintingBinding.instance.imageCache.evict(key); + throw StateError('$file is empty and cannot be loaded as an image.'); + } + return (file.runtimeType == File) + ? decode(await ui.ImmutableBuffer.fromFilePath(file.path)) + : decode(await ui.ImmutableBuffer.fromUint8List(await file.readAsBytes())); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is FileImage + && other.file.path == file.path + && other.scale == scale; + } + + @override + int get hashCode => Object.hash(file.path, scale); + + @override + String toString() => '${objectRuntimeType(this, 'FileImage')}("${file.path}", scale: ${scale.toStringAsFixed(1)})'; +} + +/// Decodes the given [Uint8List] buffer as an image, associating it with the +/// given scale. +/// +/// The provided [bytes] buffer should not be changed after it is provided +/// to a [MemoryImage]. To provide an [ImageStream] that represents an image +/// that changes over time, consider creating a new subclass of [ImageProvider] +/// whose [loadImage] method returns a subclass of [ImageStreamCompleter] that +/// can handle providing multiple images. +/// +/// See also: +/// +/// * [Image.memory] for a shorthand of an [Image] widget backed by [MemoryImage]. +@immutable +class MemoryImage extends ImageProvider<MemoryImage> { + /// Creates an object that decodes a [Uint8List] buffer as an image. + const MemoryImage(this.bytes, { this.scale = 1.0 }); + + /// The bytes to decode into an image. + /// + /// The bytes represent encoded image bytes and can be encoded in any of the + /// following supported image formats: {@macro dart.ui.imageFormats} + /// + /// See also: + /// + /// * [PaintingBinding.instantiateImageCodecWithSize] + final Uint8List bytes; + + /// The scale to place in the [ImageInfo] object of the image. + /// + /// See also: + /// + /// * [ImageInfo.scale], which gives more information on how this scale is + /// applied. + final double scale; + + @override + Future<MemoryImage> obtainKey(ImageConfiguration configuration) { + return SynchronousFuture<MemoryImage>(this); + } + + @override + ImageStreamCompleter loadBuffer(MemoryImage key, DecoderBufferCallback decode) { + assert(key == this); + return MultiFrameImageStreamCompleter( + codec: _loadAsync(key, decode: decode), + scale: key.scale, + debugLabel: 'MemoryImage(${describeIdentity(key.bytes)})', + ); + } + + @override + ImageStreamCompleter loadImage(MemoryImage key, ImageDecoderCallback decode) { + return MultiFrameImageStreamCompleter( + codec: _loadAsync(key, decode: decode), + scale: key.scale, + debugLabel: 'MemoryImage(${describeIdentity(key.bytes)})', + ); + } + + Future<ui.Codec> _loadAsync( + MemoryImage key, { + required _SimpleDecoderCallback decode, + }) async { + assert(key == this); + return decode(await ui.ImmutableBuffer.fromUint8List(bytes)); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is MemoryImage + && other.bytes == bytes + && other.scale == scale; + } + + @override + int get hashCode => Object.hash(bytes.hashCode, scale); + + @override + String toString() => '${objectRuntimeType(this, 'MemoryImage')}(${describeIdentity(bytes)}, scale: ${scale.toStringAsFixed(1)})'; +} + +/// Fetches an image from an [AssetBundle], associating it with the given scale. +/// +/// This implementation requires an explicit final [assetName] and [scale] on +/// construction, and ignores the device pixel ratio and size in the +/// configuration passed into [resolve]. For a resolution-aware variant that +/// uses the configuration to pick an appropriate image based on the device +/// pixel ratio and size, see [AssetImage]. +/// +/// ## Fetching assets +/// +/// When fetching an image provided by the app itself, use the [assetName] +/// argument to name the asset to choose. For instance, consider a directory +/// `icons` with an image `heart.png`. First, the `pubspec.yaml` of the project +/// should specify its assets in the `flutter` section: +/// +/// ```yaml +/// flutter: +/// assets: +/// - icons/heart.png +/// ``` +/// +/// Then, to fetch the image and associate it with scale `1.5`, use: +/// +/// {@tool snippet} +/// ```dart +/// const ExactAssetImage('icons/heart.png', scale: 1.5) +/// ``` +/// {@end-tool} +/// +/// ## Assets in packages +/// +/// To fetch an asset from a package, the [package] argument must be provided. +/// For instance, suppose the structure above is inside a package called +/// `my_icons`. Then to fetch the image, use: +/// +/// {@tool snippet} +/// ```dart +/// const ExactAssetImage('icons/heart.png', scale: 1.5, package: 'my_icons') +/// ``` +/// {@end-tool} +/// +/// Assets used by the package itself should also be fetched using the [package] +/// argument as above. +/// +/// If the desired asset is specified in the `pubspec.yaml` of the package, it +/// is bundled automatically with the app. In particular, assets used by the +/// package itself must be specified in its `pubspec.yaml`. +/// +/// A package can also choose to have assets in its 'lib/' folder that are not +/// specified in its `pubspec.yaml`. In this case for those images to be +/// bundled, the app has to specify which ones to include. For instance a +/// package named `fancy_backgrounds` could have: +/// +/// lib/backgrounds/background1.png +/// lib/backgrounds/background2.png +/// lib/backgrounds/background3.png +/// +/// To include, say the first image, the `pubspec.yaml` of the app should specify +/// it in the `assets` section: +/// +/// ```yaml +/// assets: +/// - packages/fancy_backgrounds/backgrounds/background1.png +/// ``` +/// +/// The `lib/` is implied, so it should not be included in the asset path. +/// +/// See also: +/// +/// * [Image.asset] for a shorthand of an [Image] widget backed by +/// [ExactAssetImage] when using a scale. +@immutable +class ExactAssetImage extends AssetBundleImageProvider { + /// Creates an object that fetches the given image from an asset bundle. + /// + /// The [scale] argument defaults to 1. The [bundle] argument may be null, in + /// which case the bundle provided in the [ImageConfiguration] passed to the + /// [resolve] call will be used instead. + /// + /// The [package] argument must be non-null when fetching an asset that is + /// included in a package. See the documentation for the [ExactAssetImage] class + /// itself for details. + const ExactAssetImage( + this.assetName, { + this.scale = 1.0, + this.bundle, + this.package, + }); + + /// The name of the asset. + final String assetName; + + /// The key to use to obtain the resource from the [bundle]. This is the + /// argument passed to [AssetBundle.load]. + String get keyName => package == null ? assetName : 'packages/$package/$assetName'; + + /// The scale to place in the [ImageInfo] object of the image. + final double scale; + + /// The bundle from which the image will be obtained. + /// + /// If the provided [bundle] is null, the bundle provided in the + /// [ImageConfiguration] passed to the [resolve] call will be used instead. If + /// that is also null, the [rootBundle] is used. + /// + /// The image is obtained by calling [AssetBundle.load] on the given [bundle] + /// using the key given by [keyName]. + final AssetBundle? bundle; + + /// The name of the package from which the image is included. See the + /// documentation for the [ExactAssetImage] class itself for details. + final String? package; + + @override + Future<AssetBundleImageKey> obtainKey(ImageConfiguration configuration) { + return SynchronousFuture<AssetBundleImageKey>(AssetBundleImageKey( + bundle: bundle ?? configuration.bundle ?? rootBundle, + name: keyName, + scale: scale, + )); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ExactAssetImage + && other.keyName == keyName + && other.scale == scale + && other.bundle == bundle; + } + + @override + int get hashCode => Object.hash(keyName, scale, bundle); + + @override + String toString() => '${objectRuntimeType(this, 'ExactAssetImage')}(name: "$keyName", scale: ${scale.toStringAsFixed(1)}, bundle: $bundle)'; +} + +// A completer used when resolving an image fails sync. +class _ErrorImageCompleter extends ImageStreamCompleter { } + +/// The exception thrown when the HTTP request to load a network image fails. +class NetworkImageLoadException implements Exception { + /// Creates a [NetworkImageLoadException] with the specified http [statusCode] + /// and [uri]. + NetworkImageLoadException({required this.statusCode, required this.uri}) + : _message = 'HTTP request failed, statusCode: $statusCode, $uri'; + + /// The HTTP status code from the server. + final int statusCode; + + /// A human-readable error message. + final String _message; + + /// Resolved URL of the requested image. + final Uri uri; + + @override + String toString() => _message; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_resolution.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_resolution.dart new file mode 100644 index 0000000000000000000000000000000000000000..f3fe4ef975fa8ba6915d80b58db8a97f00d630ba --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_resolution.dart @@ -0,0 +1,396 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:collection'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'image_provider.dart'; + +/// A screen with a device-pixel ratio strictly less than this value is +/// considered a low-resolution screen (typically entry-level to mid-range +/// laptops, desktop screens up to QHD, low-end tablets such as Kindle Fire). +const double _kLowDprLimit = 2.0; + +/// Fetches an image from an [AssetBundle], having determined the exact image to +/// use based on the context. +/// +/// Given a main asset and a set of variants, AssetImage chooses the most +/// appropriate asset for the current context, based on the device pixel ratio +/// and size given in the configuration passed to [resolve]. +/// +/// To show a specific image from a bundle without any asset resolution, use an +/// [AssetBundleImageProvider]. +/// +/// ## Naming assets for matching with different pixel densities +/// +/// Main assets are presumed to match a nominal pixel ratio of 1.0. To specify +/// assets targeting different pixel ratios, place the variant assets in +/// the application bundle under subdirectories named in the form "Nx", where +/// N is the nominal device pixel ratio for that asset. +/// +/// For example, suppose an application wants to use an icon named +/// "heart.png". This icon has representations at 1.0 (the main icon), as well +/// as 2.0 and 4.0 pixel ratios (variants). The asset bundle should then +/// contain the following assets: +/// +/// heart.png +/// 2.0x/heart.png +/// 4.0x/heart.png +/// +/// On a device with a 1.0 device pixel ratio, the image chosen would be +/// heart.png; on a device with a 2.0 device pixel ratio, the image chosen +/// would be 2.0x/heart.png; on a device with a 4.0 device pixel ratio, the +/// image chosen would be 4.0x/heart.png. +/// +/// On a device with a device pixel ratio that does not exactly match an +/// available asset the "best match" is chosen. Which asset is the best depends +/// on the screen. Low-resolution screens (those with device pixel ratio +/// strictly less than 2.0) use a different matching algorithm from the +/// high-resolution screen. Because in low-resolution screens the physical +/// pixels are visible to the user upscaling artifacts (e.g. blurred edges) are +/// more pronounced. Therefore, a higher resolution asset is chosen, if +/// available. For higher-resolution screens, where individual physical pixels +/// are not visible to the user, the asset variant with the pixel ratio that's +/// the closest to the screen's device pixel ratio is chosen. +/// +/// For example, for a screen with device pixel ratio 1.25 the image chosen +/// would be 2.0x/heart.png, even though heart.png (i.e. 1.0) is closer. This +/// is because the screen is considered low-resolution. For a screen with +/// device pixel ratio of 2.25 the image chosen would also be 2.0x/heart.png. +/// This is because the screen is considered to be a high-resolution screen, +/// and therefore upscaling a 2.0x image to 2.25 won't result in visible +/// upscaling artifacts. However, for a screen with device-pixel ratio 3.25 the +/// image chosen would be 4.0x/heart.png because it's closer to 4.0 than it is +/// to 2.0. +/// +/// Choosing a higher-resolution image than necessary may waste significantly +/// more memory if the difference between the screen device pixel ratio and +/// the device pixel ratio of the image is high. To reduce memory usage, +/// consider providing more variants of the image. In the example above adding +/// a 3.0x/heart.png variant would improve memory usage for screens with device +/// pixel ratios between 3.0 and 3.5. +/// +/// [ImageConfiguration] can be used to customize the selection of the image +/// variant by setting [ImageConfiguration.devicePixelRatio] to value different +/// from the default. The default value is derived from +/// [MediaQueryData.devicePixelRatio] by [createLocalImageConfiguration]. +/// +/// The directory level of the asset does not matter as long as the variants are +/// at the equivalent level; that is, the following is also a valid bundle +/// structure: +/// +/// icons/heart.png +/// icons/1.5x/heart.png +/// icons/2.0x/heart.png +/// +/// assets/icons/3.0x/heart.png would be a valid variant of +/// assets/icons/heart.png. +/// +/// ## Fetching assets +/// +/// When fetching an image provided by the app itself, use the [assetName] +/// argument to name the asset to choose. For instance, consider the structure +/// above. First, the `pubspec.yaml` of the project should specify its assets in +/// the `flutter` section: +/// +/// ```yaml +/// flutter: +/// assets: +/// - icons/heart.png +/// ``` +/// +/// Then, to fetch the image, use: +/// ```dart +/// const AssetImage('icons/heart.png') +/// ``` +/// +/// {@tool snippet} +/// +/// The following shows the code required to write a widget that fully conforms +/// to the [AssetImage] and [Widget] protocols. (It is essentially a +/// bare-bones version of the [widgets.Image] widget made to work specifically for +/// an [AssetImage].) +/// +/// ```dart +/// class MyImage extends StatefulWidget { +/// const MyImage({ +/// super.key, +/// required this.assetImage, +/// }); +/// +/// final AssetImage assetImage; +/// +/// @override +/// State<MyImage> createState() => _MyImageState(); +/// } +/// +/// class _MyImageState extends State<MyImage> { +/// ImageStream? _imageStream; +/// ImageInfo? _imageInfo; +/// +/// @override +/// void didChangeDependencies() { +/// super.didChangeDependencies(); +/// // We call _getImage here because createLocalImageConfiguration() needs to +/// // be called again if the dependencies changed, in case the changes relate +/// // to the DefaultAssetBundle, MediaQuery, etc, which that method uses. +/// _getImage(); +/// } +/// +/// @override +/// void didUpdateWidget(MyImage oldWidget) { +/// super.didUpdateWidget(oldWidget); +/// if (widget.assetImage != oldWidget.assetImage) { +/// _getImage(); +/// } +/// } +/// +/// void _getImage() { +/// final ImageStream? oldImageStream = _imageStream; +/// _imageStream = widget.assetImage.resolve(createLocalImageConfiguration(context)); +/// if (_imageStream!.key != oldImageStream?.key) { +/// // If the keys are the same, then we got the same image back, and so we don't +/// // need to update the listeners. If the key changed, though, we must make sure +/// // to switch our listeners to the new image stream. +/// final ImageStreamListener listener = ImageStreamListener(_updateImage); +/// oldImageStream?.removeListener(listener); +/// _imageStream!.addListener(listener); +/// } +/// } +/// +/// void _updateImage(ImageInfo imageInfo, bool synchronousCall) { +/// setState(() { +/// // Trigger a build whenever the image changes. +/// _imageInfo?.dispose(); +/// _imageInfo = imageInfo; +/// }); +/// } +/// +/// @override +/// void dispose() { +/// _imageStream?.removeListener(ImageStreamListener(_updateImage)); +/// _imageInfo?.dispose(); +/// _imageInfo = null; +/// super.dispose(); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return RawImage( +/// image: _imageInfo?.image, // this is a dart:ui Image object +/// scale: _imageInfo?.scale ?? 1.0, +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// ## Assets in packages +/// +/// To fetch an asset from a package, the [package] argument must be provided. +/// For instance, suppose the structure above is inside a package called +/// `my_icons`. Then to fetch the image, use: +/// +/// ```dart +/// const AssetImage('icons/heart.png', package: 'my_icons') +/// ``` +/// +/// Assets used by the package itself should also be fetched using the [package] +/// argument as above. +/// +/// If the desired asset is specified in the `pubspec.yaml` of the package, it +/// is bundled automatically with the app. In particular, assets used by the +/// package itself must be specified in its `pubspec.yaml`. +/// +/// A package can also choose to have assets in its 'lib/' folder that are not +/// specified in its `pubspec.yaml`. In this case for those images to be +/// bundled, the app has to specify which ones to include. For instance a +/// package named `fancy_backgrounds` could have: +/// +/// lib/backgrounds/background1.png +/// lib/backgrounds/background2.png +/// lib/backgrounds/background3.png +/// +/// To include, say the first image, the `pubspec.yaml` of the app should specify +/// it in the `assets` section: +/// +/// ```yaml +/// assets: +/// - packages/fancy_backgrounds/backgrounds/background1.png +/// ``` +/// +/// The `lib/` is implied, so it should not be included in the asset path. +/// +/// See also: +/// +/// * [Image.asset] for a shorthand of an [Image] widget backed by [AssetImage] +/// when used without a scale. +@immutable +class AssetImage extends AssetBundleImageProvider { + /// Creates an object that fetches an image from an asset bundle. + /// + /// The [assetName] argument should name the main asset from the set of images + /// to choose from. The [package] argument must be non-null when fetching an + /// asset that is included in package. See the documentation for the + /// [AssetImage] class itself for details. + const AssetImage( + this.assetName, { + this.bundle, + this.package, + }); + + /// The name of the main asset from the set of images to choose from. See the + /// documentation for the [AssetImage] class itself for details. + final String assetName; + + /// The name used to generate the key to obtain the asset. For local assets + /// this is [assetName], and for assets from packages the [assetName] is + /// prefixed 'packages/<package_name>/'. + String get keyName => package == null ? assetName : 'packages/$package/$assetName'; + + /// The bundle from which the image will be obtained. + /// + /// If the provided [bundle] is null, the bundle provided in the + /// [ImageConfiguration] passed to the [resolve] call will be used instead. If + /// that is also null, the [rootBundle] is used. + /// + /// The image is obtained by calling [AssetBundle.load] on the given [bundle] + /// using the key given by [keyName]. + final AssetBundle? bundle; + + /// The name of the package from which the image is included. See the + /// documentation for the [AssetImage] class itself for details. + final String? package; + + // We assume the main asset is designed for a device pixel ratio of 1.0 + static const double _naturalResolution = 1.0; + + @override + Future<AssetBundleImageKey> obtainKey(ImageConfiguration configuration) { + // This function tries to return a SynchronousFuture if possible. We do this + // because otherwise showing an image would always take at least one frame, + // which would be sad. (This code is called from inside build/layout/paint, + // which all happens in one call frame; using native Futures would guarantee + // that we resolve each future in a new call frame, and thus not in this + // build/layout/paint sequence.) + final AssetBundle chosenBundle = bundle ?? configuration.bundle ?? rootBundle; + Completer<AssetBundleImageKey>? completer; + Future<AssetBundleImageKey>? result; + + AssetManifest.loadFromAssetBundle(chosenBundle) + .then((AssetManifest manifest) { + final Iterable<AssetMetadata>? candidateVariants = manifest.getAssetVariants(keyName); + final AssetMetadata chosenVariant = _chooseVariant( + keyName, + configuration, + candidateVariants, + ); + final AssetBundleImageKey key = AssetBundleImageKey( + bundle: chosenBundle, + name: chosenVariant.key, + scale: chosenVariant.targetDevicePixelRatio ?? _naturalResolution, + ); + if (completer != null) { + // We already returned from this function, which means we are in the + // asynchronous mode. Pass the value to the completer. The completer's + // future is what we returned. + completer.complete(key); + } else { + // We haven't yet returned, so we must have been called synchronously + // just after loadStructuredData returned (which means it provided us + // with a SynchronousFuture). Let's return a SynchronousFuture + // ourselves. + result = SynchronousFuture<AssetBundleImageKey>(key); + } + }) + .onError((Object error, StackTrace stack) { + // We had an error. (This guarantees we weren't called synchronously.) + // Forward the error to the caller. + assert(completer != null); + assert(result == null); + completer!.completeError(error, stack); + }); + + if (result != null) { + // The code above ran synchronously, and came up with an answer. + // Return the SynchronousFuture that we created above. + return result!; + } + // The code above hasn't yet run its "then" handler yet. Let's prepare a + // completer for it to use when it does run. + completer = Completer<AssetBundleImageKey>(); + return completer.future; + } + + AssetMetadata _chooseVariant(String mainAssetKey, ImageConfiguration config, Iterable<AssetMetadata>? candidateVariants) { + if (candidateVariants == null || candidateVariants.isEmpty || config.devicePixelRatio == null) { + return AssetMetadata(key: mainAssetKey, targetDevicePixelRatio: null, main: true); + } + + final SplayTreeMap<double, AssetMetadata> candidatesByDevicePixelRatio = + SplayTreeMap<double, AssetMetadata>(); + for (final AssetMetadata candidate in candidateVariants) { + candidatesByDevicePixelRatio[candidate.targetDevicePixelRatio ?? _naturalResolution] = candidate; + } + // TODO(ianh): implement support for config.locale, config.textDirection, + // config.size, config.platform (then document this over in the Image.asset + // docs) + return _findBestVariant(candidatesByDevicePixelRatio, config.devicePixelRatio!); + } + + // Returns the "best" asset variant amongst the available `candidates`. + // + // The best variant is chosen as follows: + // - Choose a variant whose key matches `value` exactly, if available. + // - If `value` is less than the lowest key, choose the variant with the + // lowest key. + // - If `value` is greater than the highest key, choose the variant with + // the highest key. + // - If the screen has low device pixel ratio, choose the variant with the + // lowest key higher than `value`. + // - If the screen has high device pixel ratio, choose the variant with the + // key nearest to `value`. + AssetMetadata _findBestVariant(SplayTreeMap<double, AssetMetadata> candidatesByDpr, double value) { + if (candidatesByDpr.containsKey(value)) { + return candidatesByDpr[value]!; + } + final double? lower = candidatesByDpr.lastKeyBefore(value); + final double? upper = candidatesByDpr.firstKeyAfter(value); + if (lower == null) { + return candidatesByDpr[upper]!; + } + if (upper == null) { + return candidatesByDpr[lower]!; + } + + // On screens with low device-pixel ratios the artifacts from upscaling + // images are more visible than on screens with a higher device-pixel + // ratios because the physical pixels are larger. Choose the higher + // resolution image in that case instead of the nearest one. + if (value < _kLowDprLimit || value > (lower + upper) / 2) { + return candidatesByDpr[upper]!; + } else { + return candidatesByDpr[lower]!; + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is AssetImage + && other.keyName == keyName + && other.bundle == bundle; + } + + @override + int get hashCode => Object.hash(keyName, bundle); + + @override + String toString() => '${objectRuntimeType(this, 'AssetImage')}(bundle: $bundle, name: "$keyName")'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_stream.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_stream.dart new file mode 100644 index 0000000000000000000000000000000000000000..ffdcf45452bcd7b7306707ee1dae0148da873cbf --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/image_stream.dart @@ -0,0 +1,1107 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:ui' as ui show Codec, FrameInfo, Image; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; + +const String _flutterWidgetsLibrary = 'package:flutter/widgets.dart'; + +/// A [dart:ui.Image] object with its corresponding scale. +/// +/// ImageInfo objects are used by [ImageStream] objects to represent the +/// actual data of the image once it has been obtained. +/// +/// The receiver of an [ImageInfo] object must call [dispose]. To safely share +/// the object with other clients, use the [clone] method before calling +/// dispose. +@immutable +class ImageInfo { + /// Creates an [ImageInfo] object for the given [image] and [scale]. + /// + /// The [debugLabel] may be used to identify the source of this image. + const ImageInfo({ required this.image, this.scale = 1.0, this.debugLabel }); + + /// Creates an [ImageInfo] with a cloned [image]. + /// + /// Once all outstanding references to the [image] are disposed, it is no + /// longer safe to access properties of it or attempt to draw it. Clones serve + /// to create new references to the underlying image data that can safely be + /// disposed without knowledge of whether some other reference holder will + /// still need access to the underlying image. Once a client disposes of its + /// own image reference, it can no longer access the image, but other clients + /// will be able to access their own references. + /// + /// This method must be used in cases where a client holding an [ImageInfo] + /// needs to share the image info object with another client and will still + /// need to access the underlying image data at some later point, e.g. to + /// share it again with another client. + /// + /// See also: + /// + /// * [Image.clone], which describes how and why to clone images. + ImageInfo clone() { + return ImageInfo( + image: image.clone(), + scale: scale, + debugLabel: debugLabel, + ); + } + + /// Whether this [ImageInfo] is a [clone] of the `other`. + /// + /// This method is a convenience wrapper for [Image.isCloneOf], and is useful + /// for clients that are trying to determine whether new layout or painting + /// logic is required when receiving a new image reference. + /// + /// {@tool snippet} + /// + /// The following sample shows how to appropriately check whether the + /// [ImageInfo] reference refers to new image data or not (in this case in a + /// setter). + /// + /// ```dart + /// ImageInfo? get imageInfo => _imageInfo; + /// ImageInfo? _imageInfo; + /// set imageInfo (ImageInfo? value) { + /// // If the image reference is exactly the same, do nothing. + /// if (value == _imageInfo) { + /// return; + /// } + /// // If it is a clone of the current reference, we must dispose of it and + /// // can do so immediately. Since the underlying image has not changed, + /// // We don't have any additional work to do here. + /// if (value != null && _imageInfo != null && value.isCloneOf(_imageInfo!)) { + /// value.dispose(); + /// return; + /// } + /// // It is a new image. Dispose of the old one and take a reference + /// // to the new one. + /// _imageInfo?.dispose(); + /// _imageInfo = value; + /// // Perform work to determine size, paint the image, etc. + /// // ... + /// } + /// ``` + /// {@end-tool} + bool isCloneOf(ImageInfo other) { + return other.image.isCloneOf(image) + && scale == scale + && other.debugLabel == debugLabel; + } + + /// The raw image pixels. + /// + /// This is the object to pass to the [Canvas.drawImage], + /// [Canvas.drawImageRect], or [Canvas.drawImageNine] methods when painting + /// the image. + final ui.Image image; + + /// The size of raw image pixels in bytes. + int get sizeBytes => image.height * image.width * 4; + + /// The linear scale factor for drawing this image at its intended size. + /// + /// The scale factor applies to the width and the height. + /// + /// {@template flutter.painting.imageInfo.scale} + /// For example, if this is 2.0, it means that there are four image pixels for + /// every one logical pixel, and the image's actual width and height (as given + /// by the [dart:ui.Image.width] and [dart:ui.Image.height] properties) are + /// double the height and width that should be used when painting the image + /// (e.g. in the arguments given to [Canvas.drawImage]). + /// {@endtemplate} + final double scale; + + /// A string used for debugging purposes to identify the source of this image. + final String? debugLabel; + + /// Disposes of this object. + /// + /// Once this method has been called, the object should not be used anymore, + /// and no clones of it or the image it contains can be made. + void dispose() { + assert((image.debugGetOpenHandleStackTraces()?.length ?? 1) > 0); + image.dispose(); + } + + @override + String toString() => '${debugLabel != null ? '$debugLabel ' : ''}$image @ ${debugFormatDouble(scale)}x'; + + @override + int get hashCode => Object.hash(image, scale, debugLabel); + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ImageInfo + && other.image == image + && other.scale == scale + && other.debugLabel == debugLabel; + } +} + +/// Interface for receiving notifications about the loading of an image. +/// +/// This class overrides [operator ==] and [hashCode] to compare the individual +/// callbacks in the listener, meaning that if you add an instance of this class +/// as a listener (e.g. via [ImageStream.addListener]), you can instantiate a +/// _different_ instance of this class when you remove the listener, and the +/// listener will be properly removed as long as all associated callbacks are +/// equal. +/// +/// Used by [ImageStream] and [ImageStreamCompleter]. +@immutable +class ImageStreamListener { + /// Creates a new [ImageStreamListener]. + const ImageStreamListener( + this.onImage, { + this.onChunk, + this.onError, + }); + + /// Callback for getting notified that an image is available. + /// + /// This callback may fire multiple times (e.g. if the [ImageStreamCompleter] + /// that drives the notifications fires multiple times). An example of such a + /// case would be an image with multiple frames within it (such as an animated + /// GIF). + /// + /// For more information on how to interpret the parameters to the callback, + /// see the documentation on [ImageListener]. + /// + /// See also: + /// + /// * [onError], which will be called instead of [onImage] if an error occurs + /// during loading. + final ImageListener onImage; + + /// Callback for getting notified when a chunk of bytes has been received + /// during the loading of the image. + /// + /// This callback may fire many times (e.g. when used with a [NetworkImage], + /// where the image bytes are loaded incrementally over the wire) or not at + /// all (e.g. when used with a [MemoryImage], where the image bytes are + /// already available in memory). + /// + /// This callback may also continue to fire after the [onImage] callback has + /// fired (e.g. for multi-frame images that continue to load after the first + /// frame is available). + final ImageChunkListener? onChunk; + + /// Callback for getting notified when an error occurs while loading an image. + /// + /// If an error occurs during loading, [onError] will be called instead of + /// [onImage]. + /// + /// If [onError] is called and does not throw, then the error is considered to + /// be handled. An error handler can explicitly rethrow the exception reported + /// to it to safely indicate that it did not handle the exception. + /// + /// If an image stream has no listeners that handled the error when the error + /// was first encountered, then the error is reported using + /// [FlutterError.reportError], with the [FlutterErrorDetails.silent] flag set + /// to true. + final ImageErrorListener? onError; + + @override + int get hashCode => Object.hash(onImage, onChunk, onError); + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ImageStreamListener + && other.onImage == onImage + && other.onChunk == onChunk + && other.onError == onError; + } +} + +/// Signature for callbacks reporting that an image is available. +/// +/// Used in [ImageStreamListener]. +/// +/// The `image` argument contains information about the image to be rendered. +/// The implementer of [ImageStreamListener.onImage] is expected to call dispose +/// on the [ui.Image] it receives. +/// +/// The `synchronousCall` argument is true if the listener is being invoked +/// during the call to `addListener`. This can be useful if, for example, +/// [ImageStream.addListener] is invoked during a frame, so that a new rendering +/// frame is requested if the call was asynchronous (after the current frame) +/// and no rendering frame is requested if the call was synchronous (within the +/// same stack frame as the call to [ImageStream.addListener]). +typedef ImageListener = void Function(ImageInfo image, bool synchronousCall); + +/// Signature for listening to [ImageChunkEvent] events. +/// +/// Used in [ImageStreamListener]. +typedef ImageChunkListener = void Function(ImageChunkEvent event); + +/// Signature for reporting errors when resolving images. +/// +/// Used in [ImageStreamListener], as well as by [ImageCache.putIfAbsent] and +/// [precacheImage], to report errors. +typedef ImageErrorListener = void Function(Object exception, StackTrace? stackTrace); + +/// An immutable notification of image bytes that have been incrementally loaded. +/// +/// Chunk events represent progress notifications while an image is being +/// loaded (e.g. from disk or over the network). +/// +/// See also: +/// +/// * [ImageChunkListener], the means by which callers get notified of +/// these events. +@immutable +class ImageChunkEvent with Diagnosticable { + /// Creates a new chunk event. + const ImageChunkEvent({ + required this.cumulativeBytesLoaded, + required this.expectedTotalBytes, + }) : assert(cumulativeBytesLoaded >= 0), + assert(expectedTotalBytes == null || expectedTotalBytes >= 0); + + /// The number of bytes that have been received across the wire thus far. + final int cumulativeBytesLoaded; + + /// The expected number of bytes that need to be received to finish loading + /// the image. + /// + /// This value is not necessarily equal to the expected _size_ of the image + /// in bytes, as the bytes required to load the image may be compressed. + /// + /// This value will be null if the number is not known in advance. + /// + /// When this value is null, the chunk event may still be useful as an + /// indication that data is loading (and how much), but it cannot represent a + /// loading completion percentage. + final int? expectedTotalBytes; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('cumulativeBytesLoaded', cumulativeBytesLoaded)); + properties.add(IntProperty('expectedTotalBytes', expectedTotalBytes)); + } +} + +/// A handle to an image resource. +/// +/// ImageStream represents a handle to a [dart:ui.Image] object and its scale +/// (together represented by an [ImageInfo] object). The underlying image object +/// might change over time, either because the image is animating or because the +/// underlying image resource was mutated. +/// +/// ImageStream objects can also represent an image that hasn't finished +/// loading. +/// +/// ImageStream objects are backed by [ImageStreamCompleter] objects. +/// +/// The [ImageCache] will consider an image to be live until the listener count +/// drops to zero after adding at least one listener. The +/// [ImageStreamCompleter.addOnLastListenerRemovedCallback] method is used for +/// tracking this information. +/// +/// See also: +/// +/// * [ImageProvider], which has an example that includes the use of an +/// [ImageStream] in a [Widget]. +class ImageStream with Diagnosticable { + /// Create an initially unbound image stream. + /// + /// Once an [ImageStreamCompleter] is available, call [setCompleter]. + ImageStream(); + + /// The completer that has been assigned to this image stream. + /// + /// Generally there is no need to deal with the completer directly. + ImageStreamCompleter? get completer => _completer; + ImageStreamCompleter? _completer; + + List<ImageStreamListener>? _listeners; + + /// Assigns a particular [ImageStreamCompleter] to this [ImageStream]. + /// + /// This is usually done automatically by the [ImageProvider] that created the + /// [ImageStream]. + /// + /// This method can only be called once per stream. To have an [ImageStream] + /// represent multiple images over time, assign it a completer that + /// completes several images in succession. + void setCompleter(ImageStreamCompleter value) { + assert(_completer == null); + _completer = value; + if (_listeners != null) { + final List<ImageStreamListener> initialListeners = _listeners!; + _listeners = null; + _completer!._addingInitialListeners = true; + initialListeners.forEach(_completer!.addListener); + _completer!._addingInitialListeners = false; + } + } + + /// Adds a listener callback that is called whenever a new concrete [ImageInfo] + /// object is available. If a concrete image is already available, this object + /// will call the listener synchronously. + /// + /// If the assigned [completer] completes multiple images over its lifetime, + /// this listener will fire multiple times. + /// + /// {@template flutter.painting.imageStream.addListener} + /// The listener will be passed a flag indicating whether a synchronous call + /// occurred. If the listener is added within a render object paint function, + /// then use this flag to avoid calling [RenderObject.markNeedsPaint] during + /// a paint. + /// + /// If a duplicate `listener` is registered N times, then it will be called N + /// times when the image stream completes (whether because a new image is + /// available or because an error occurs). Likewise, to remove all instances + /// of the listener, [removeListener] would need to called N times as well. + /// + /// When a `listener` receives an [ImageInfo] object, the `listener` is + /// responsible for disposing of the [ImageInfo.image]. + /// {@endtemplate} + void addListener(ImageStreamListener listener) { + if (_completer != null) { + return _completer!.addListener(listener); + } + _listeners ??= <ImageStreamListener>[]; + _listeners!.add(listener); + } + + /// Stops listening for events from this stream's [ImageStreamCompleter]. + /// + /// If [listener] has been added multiple times, this removes the _first_ + /// instance of the listener. + void removeListener(ImageStreamListener listener) { + if (_completer != null) { + return _completer!.removeListener(listener); + } + assert(_listeners != null); + for (int i = 0; i < _listeners!.length; i += 1) { + if (_listeners![i] == listener) { + _listeners!.removeAt(i); + break; + } + } + } + + /// Returns an object which can be used with `==` to determine if this + /// [ImageStream] shares the same listeners list as another [ImageStream]. + /// + /// This can be used to avoid un-registering and re-registering listeners + /// after calling [ImageProvider.resolve] on a new, but possibly equivalent, + /// [ImageProvider]. + /// + /// The key may change once in the lifetime of the object. When it changes, it + /// will go from being different than other [ImageStream]'s keys to + /// potentially being the same as others'. No notification is sent when this + /// happens. + Object get key => _completer ?? this; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ObjectFlagProperty<ImageStreamCompleter>( + 'completer', + _completer, + ifPresent: _completer?.toStringShort(), + ifNull: 'unresolved', + )); + properties.add(ObjectFlagProperty<List<ImageStreamListener>>( + 'listeners', + _listeners, + ifPresent: '${_listeners?.length} listener${_listeners?.length == 1 ? "" : "s" }', + ifNull: 'no listeners', + level: _completer != null ? DiagnosticLevel.hidden : DiagnosticLevel.info, + )); + _completer?.debugFillProperties(properties); + } +} + +/// An opaque handle that keeps an [ImageStreamCompleter] alive even if it has +/// lost its last listener. +/// +/// To create a handle, use [ImageStreamCompleter.keepAlive]. +/// +/// Such handles are useful when an image cache needs to keep a completer alive +/// but does not actually have a listener subscribed, or when a widget that +/// displays an image needs to temporarily unsubscribe from the completer but +/// may re-subscribe in the future, for example when the [TickerMode] changes. +class ImageStreamCompleterHandle { + ImageStreamCompleterHandle._(ImageStreamCompleter this._completer) { + _completer!._keepAliveHandles += 1; + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: _flutterWidgetsLibrary, + className: '$ImageStreamCompleterHandle', + object: this, + ); + } + } + + ImageStreamCompleter? _completer; + + /// Call this method to signal the [ImageStreamCompleter] that it can now be + /// disposed when its last listener drops. + /// + /// This method must only be called once per object. + void dispose() { + assert(_completer != null); + assert(_completer!._keepAliveHandles > 0); + assert(!_completer!._disposed); + + _completer!._keepAliveHandles -= 1; + _completer!._maybeDispose(); + _completer = null; + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + } +} + +/// Base class for those that manage the loading of [dart:ui.Image] objects for +/// [ImageStream]s. +/// +/// [ImageStreamListener] objects are rarely constructed directly. Generally, an +/// [ImageProvider] subclass will return an [ImageStream] and automatically +/// configure it with the right [ImageStreamCompleter] when possible. +abstract class ImageStreamCompleter with Diagnosticable { + final List<ImageStreamListener> _listeners = <ImageStreamListener>[]; + final List<ImageErrorListener> _ephemeralErrorListeners = <ImageErrorListener>[]; + ImageInfo? _currentImage; + FlutterErrorDetails? _currentError; + + /// A string identifying the source of the underlying image. + String? debugLabel; + + /// Whether any listeners are currently registered. + /// + /// Clients should not depend on this value for their behavior, because having + /// one listener's logic change when another listener happens to start or stop + /// listening will lead to extremely hard-to-track bugs. Subclasses might use + /// this information to determine whether to do any work when there are no + /// listeners, however; for example, [MultiFrameImageStreamCompleter] uses it + /// to determine when to iterate through frames of an animated image. + /// + /// Typically this is used by overriding [addListener], checking if + /// [hasListeners] is false before calling `super.addListener()`, and if so, + /// starting whatever work is needed to determine when to notify listeners; + /// and similarly, by overriding [removeListener], checking if [hasListeners] + /// is false after calling `super.removeListener()`, and if so, stopping that + /// same work. + /// + /// The ephemeral error listeners (added through [addEphemeralErrorListener]) + /// will not be taken into consideration in this property. + @protected + @visibleForTesting + bool get hasListeners => _listeners.isNotEmpty; + + /// We must avoid disposing a completer if it has never had a listener, even + /// if all [keepAlive] handles get disposed. + bool _hadAtLeastOneListener = false; + + /// Whether the future listeners added to this completer are initial listeners. + /// + /// This can be set to true when an [ImageStream] adds its initial listeners to + /// this completer. This ultimately controls the synchronousCall parameter for + /// the listener callbacks. When adding cached listeners to a completer, + /// [_addingInitialListeners] can be set to false to indicate to the listeners + /// that they are being called asynchronously. + bool _addingInitialListeners = false; + + /// Adds a listener callback that is called whenever a new concrete [ImageInfo] + /// object is available or an error is reported. If a concrete image is + /// already available, or if an error has been already reported, this object + /// will notify the listener synchronously. + /// + /// If the [ImageStreamCompleter] completes multiple images over its lifetime, + /// this listener's [ImageStreamListener.onImage] will fire multiple times. + /// + /// {@macro flutter.painting.imageStream.addListener} + /// + /// See also: + /// + /// * [addEphemeralErrorListener], which adds an error listener that is + /// automatically removed after first image load or error. + void addListener(ImageStreamListener listener) { + _checkDisposed(); + _hadAtLeastOneListener = true; + _listeners.add(listener); + if (_currentImage != null) { + try { + listener.onImage(_currentImage!.clone(), !_addingInitialListeners); + } catch (exception, stack) { + reportError( + context: ErrorDescription('by a synchronously-called image listener'), + exception: exception, + stack: stack, + ); + } + } + if (_currentError != null && listener.onError != null) { + try { + listener.onError!(_currentError!.exception, _currentError!.stack); + } catch (newException, newStack) { + if (newException != _currentError!.exception) { + FlutterError.reportError( + FlutterErrorDetails( + exception: newException, + library: 'image resource service', + context: ErrorDescription('by a synchronously-called image error listener'), + stack: newStack, + ), + ); + } + } + } + } + + /// Adds an error listener callback that is called when the first error is reported. + /// + /// The callback will be removed automatically after the first successful + /// image load or the first error - that is why it is called "ephemeral". + /// + /// If a concrete image is already available, the listener will be discarded + /// synchronously. If an error has been already reported, the listener + /// will be notified synchronously. + /// + /// The presence of a listener will affect neither the lifecycle of this object + /// nor what [hasListeners] reports. + /// + /// It is different from [addListener] in a few points: Firstly, this one only + /// listens to errors, while [addListener] listens to all kinds of events. + /// Secondly, this listener will be automatically removed according to the + /// rules mentioned above, while [addListener] will need manual removal. + /// Thirdly, this listener will not affect how this object is disposed, while + /// any non-removed listener added via [addListener] will forbid this object + /// from disposal. + /// + /// When you want to know full information and full control, use [addListener]. + /// When you only want to get notified for an error ephemerally, use this function. + /// + /// See also: + /// + /// * [addListener], which adds a full-featured listener and needs manual + /// removal. + void addEphemeralErrorListener(ImageErrorListener listener) { + _checkDisposed(); + if (_currentError != null) { + // immediately fire the listener, and no need to add to _ephemeralErrorListeners + try { + listener(_currentError!.exception, _currentError!.stack); + } catch (newException, newStack) { + if (newException != _currentError!.exception) { + FlutterError.reportError( + FlutterErrorDetails( + exception: newException, + library: 'image resource service', + context: ErrorDescription('by a synchronously-called image error listener'), + stack: newStack, + ), + ); + } + } + } else if (_currentImage == null) { + // add to _ephemeralErrorListeners to wait for the error, + // only if no image has been loaded + _ephemeralErrorListeners.add(listener); + } + } + + int _keepAliveHandles = 0; + /// Creates an [ImageStreamCompleterHandle] that will prevent this stream from + /// being disposed at least until the handle is disposed. + /// + /// Such handles are useful when an image cache needs to keep a completer + /// alive but does not itself have a listener subscribed, or when a widget + /// that displays an image needs to temporarily unsubscribe from the completer + /// but may re-subscribe in the future, for example when the [TickerMode] + /// changes. + ImageStreamCompleterHandle keepAlive() { + _checkDisposed(); + return ImageStreamCompleterHandle._(this); + } + + /// Stops the specified [listener] from receiving image stream events. + /// + /// If [listener] has been added multiple times, this removes the _first_ + /// instance of the listener. + /// + /// Once all listeners have been removed and all [keepAlive] handles have been + /// disposed, this image stream is no longer usable. + void removeListener(ImageStreamListener listener) { + _checkDisposed(); + for (int i = 0; i < _listeners.length; i += 1) { + if (_listeners[i] == listener) { + _listeners.removeAt(i); + break; + } + } + if (_listeners.isEmpty) { + final List<VoidCallback> callbacks = _onLastListenerRemovedCallbacks.toList(); + for (final VoidCallback callback in callbacks) { + callback(); + } + _onLastListenerRemovedCallbacks.clear(); + _maybeDispose(); + } + } + + bool _disposed = false; + + @mustCallSuper + void _maybeDispose() { + if (!_hadAtLeastOneListener || _disposed || _listeners.isNotEmpty || _keepAliveHandles != 0) { + return; + } + + _ephemeralErrorListeners.clear(); + _currentImage?.dispose(); + _currentImage = null; + _disposed = true; + } + + void _checkDisposed() { + if (_disposed) { + throw StateError( + 'Stream has been disposed.\n' + 'An ImageStream is considered disposed once at least one listener has ' + 'been added and subsequently all listeners have been removed and no ' + 'handles are outstanding from the keepAlive method.\n' + 'To resolve this error, maintain at least one listener on the stream, ' + 'or create an ImageStreamCompleterHandle from the keepAlive ' + 'method, or create a new stream for the image.', + ); + } + } + + final List<VoidCallback> _onLastListenerRemovedCallbacks = <VoidCallback>[]; + + /// Adds a callback to call when [removeListener] results in an empty + /// list of listeners and there are no [keepAlive] handles outstanding. + /// + /// This callback will never fire if [removeListener] is never called. + void addOnLastListenerRemovedCallback(VoidCallback callback) { + _checkDisposed(); + _onLastListenerRemovedCallbacks.add(callback); + } + + /// Removes a callback previously supplied to + /// [addOnLastListenerRemovedCallback]. + void removeOnLastListenerRemovedCallback(VoidCallback callback) { + _checkDisposed(); + _onLastListenerRemovedCallbacks.remove(callback); + } + + /// Calls all the registered listeners to notify them of a new image. + @protected + @pragma('vm:notify-debugger-on-exception') + void setImage(ImageInfo image) { + _checkDisposed(); + _currentImage?.dispose(); + _currentImage = image; + + _ephemeralErrorListeners.clear(); + + if (_listeners.isEmpty) { + return; + } + // Make a copy to allow for concurrent modification. + final List<ImageStreamListener> localListeners = + List<ImageStreamListener>.of(_listeners); + for (final ImageStreamListener listener in localListeners) { + try { + listener.onImage(image.clone(), false); + } catch (exception, stack) { + reportError( + context: ErrorDescription('by an image listener'), + exception: exception, + stack: stack, + ); + } + } + } + + /// Calls all the registered error listeners to notify them of an error that + /// occurred while resolving the image. + /// + /// If no error listeners (listeners with an [ImageStreamListener.onError] + /// specified) are attached, or if the handlers all rethrow the exception + /// verbatim (with `throw exception`), a [FlutterError] will be reported using + /// [FlutterError.reportError]. + /// + /// The `context` should be a string describing where the error was caught, in + /// a form that will make sense in English when following the word "thrown", + /// as in "thrown while obtaining the image from the network" (for the context + /// "while obtaining the image from the network"). + /// + /// The `exception` is the error being reported; the `stack` is the + /// [StackTrace] associated with the exception. + /// + /// The `informationCollector` is a callback (of type [InformationCollector]) + /// that is called when the exception is used by [FlutterError.reportError]. + /// It is used to obtain further details to include in the logs, which may be + /// expensive to collect, and thus should only be collected if the error is to + /// be logged in the first place. + /// + /// The `silent` argument causes the exception to not be reported to the logs + /// in release builds, if passed to [FlutterError.reportError]. (It is still + /// sent to error handlers.) It should be set to true if the error is one that + /// is expected to be encountered in release builds, for example network + /// errors. That way, logs on end-user devices will not have spurious + /// messages, but errors during development will still be reported. + /// + /// See [FlutterErrorDetails] for further details on these values. + @pragma('vm:notify-debugger-on-exception') + void reportError({ + DiagnosticsNode? context, + required Object exception, + StackTrace? stack, + InformationCollector? informationCollector, + bool silent = false, + }) { + _currentError = FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'image resource service', + context: context, + informationCollector: informationCollector, + silent: silent, + ); + + // Make a copy to allow for concurrent modification. + final List<ImageErrorListener> localErrorListeners = <ImageErrorListener>[ + ..._listeners + .map<ImageErrorListener?>((ImageStreamListener listener) => listener.onError) + .whereType<ImageErrorListener>(), + ..._ephemeralErrorListeners, + ]; + + _ephemeralErrorListeners.clear(); + + bool handled = false; + for (final ImageErrorListener errorListener in localErrorListeners) { + try { + errorListener(exception, stack); + handled = true; + } catch (newException, newStack) { + if (newException != exception) { + FlutterError.reportError( + FlutterErrorDetails( + context: ErrorDescription('when reporting an error to an image listener'), + library: 'image resource service', + exception: newException, + stack: newStack, + ), + ); + } + } + } + if (!handled) { + FlutterError.reportError(_currentError!); + } + } + + /// Calls all the registered [ImageChunkListener]s (listeners with an + /// [ImageStreamListener.onChunk] specified) to notify them of a new + /// [ImageChunkEvent]. + @protected + void reportImageChunkEvent(ImageChunkEvent event) { + _checkDisposed(); + if (hasListeners) { + // Make a copy to allow for concurrent modification. + final List<ImageChunkListener> localListeners = _listeners + .map<ImageChunkListener?>((ImageStreamListener listener) => listener.onChunk) + .whereType<ImageChunkListener>() + .toList(); + for (final ImageChunkListener listener in localListeners) { + listener(event); + } + } + } + + /// Accumulates a list of strings describing the object's state. Subclasses + /// should override this to have their information included in [toString]. + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DiagnosticsProperty<ImageInfo>('current', _currentImage, ifNull: 'unresolved', showName: false)); + description.add(ObjectFlagProperty<List<ImageStreamListener>>( + 'listeners', + _listeners, + ifPresent: '${_listeners.length} listener${_listeners.length == 1 ? "" : "s" }', + )); + description.add(ObjectFlagProperty<List<ImageErrorListener>>( + 'ephemeralErrorListeners', + _ephemeralErrorListeners, + ifPresent: '${_ephemeralErrorListeners.length} ephemeralErrorListener${_ephemeralErrorListeners.length == 1 ? "" : "s" }', + )); + description.add(FlagProperty('disposed', value: _disposed, ifTrue: '<disposed>')); + } +} + +/// Manages the loading of [dart:ui.Image] objects for static [ImageStream]s (those +/// with only one frame). +class OneFrameImageStreamCompleter extends ImageStreamCompleter { + /// Creates a manager for one-frame [ImageStream]s. + /// + /// The image resource awaits the given [Future]. When the future resolves, + /// it notifies the [ImageListener]s that have been registered with + /// [addListener]. + /// + /// The [InformationCollector], if provided, is invoked if the given [Future] + /// resolves with an error, and can be used to supplement the reported error + /// message (for example, giving the image's URL). + /// + /// Errors are reported using [FlutterError.reportError] with the `silent` + /// argument on [FlutterErrorDetails] set to true, meaning that by default the + /// message is only dumped to the console in debug mode (see [ + /// FlutterErrorDetails]). + OneFrameImageStreamCompleter(Future<ImageInfo> image, { InformationCollector? informationCollector }) { + image.then<void>(setImage, onError: (Object error, StackTrace stack) { + reportError( + context: ErrorDescription('resolving a single-frame image stream'), + exception: error, + stack: stack, + informationCollector: informationCollector, + silent: true, + ); + }); + } +} + +/// Manages the decoding and scheduling of image frames. +/// +/// New frames will only be emitted while there are registered listeners to the +/// stream (registered with [addListener]). +/// +/// This class deals with 2 types of frames: +/// +/// * image frames - image frames of an animated image. +/// * app frames - frames that the flutter engine is drawing to the screen to +/// show the app GUI. +/// +/// For single frame images the stream will only complete once. +/// +/// For animated images, this class eagerly decodes the next image frame, +/// and notifies the listeners that a new frame is ready on the first app frame +/// that is scheduled after the image frame duration has passed. +/// +/// Scheduling new timers only from scheduled app frames, makes sure we pause +/// the animation when the app is not visible (as new app frames will not be +/// scheduled). +/// +/// See the following timeline example: +/// +/// | Time | Event | Comment | +/// |------|--------------------------------------------|---------------------------| +/// | t1 | App frame scheduled (image frame A posted) | | +/// | t2 | App frame scheduled | | +/// | t3 | App frame scheduled | | +/// | t4 | Image frame B decoded | | +/// | t5 | App frame scheduled | t5 - t1 < frameB_duration | +/// | t6 | App frame scheduled (image frame B posted) | t6 - t1 > frameB_duration | +/// +class MultiFrameImageStreamCompleter extends ImageStreamCompleter { + /// Creates a image stream completer. + /// + /// Immediately starts decoding the first image frame when the codec is ready. + /// + /// The `codec` parameter is a future for an initialized [ui.Codec] that will + /// be used to decode the image. + /// + /// The `scale` parameter is the linear scale factor for drawing this frames + /// of this image at their intended size. + /// + /// The `tag` parameter is passed on to created [ImageInfo] objects to + /// help identify the source of the image. + /// + /// The `chunkEvents` parameter is an optional stream of notifications about + /// the loading progress of the image. If this stream is provided, the events + /// produced by the stream will be delivered to registered [ImageChunkListener]s + /// (see [addListener]). + MultiFrameImageStreamCompleter({ + required Future<ui.Codec> codec, + required double scale, + String? debugLabel, + Stream<ImageChunkEvent>? chunkEvents, + InformationCollector? informationCollector, + }) : _informationCollector = informationCollector, + _scale = scale { + this.debugLabel = debugLabel; + codec.then<void>(_handleCodecReady, onError: (Object error, StackTrace stack) { + reportError( + context: ErrorDescription('resolving an image codec'), + exception: error, + stack: stack, + informationCollector: informationCollector, + silent: true, + ); + }); + if (chunkEvents != null) { + _chunkSubscription = chunkEvents.listen(reportImageChunkEvent, + onError: (Object error, StackTrace stack) { + reportError( + context: ErrorDescription('loading an image'), + exception: error, + stack: stack, + informationCollector: informationCollector, + silent: true, + ); + }, + ); + } + } + + StreamSubscription<ImageChunkEvent>? _chunkSubscription; + ui.Codec? _codec; + final double _scale; + final InformationCollector? _informationCollector; + ui.FrameInfo? _nextFrame; + // When the current was first shown. + late Duration _shownTimestamp; + // The requested duration for the current frame; + Duration? _frameDuration; + // How many frames have been emitted so far. + int _framesEmitted = 0; + Timer? _timer; + + // Used to guard against registering multiple _handleAppFrame callbacks for the same frame. + bool _frameCallbackScheduled = false; + + void _handleCodecReady(ui.Codec codec) { + _codec = codec; + assert(_codec != null); + + if (hasListeners) { + _decodeNextFrameAndSchedule(); + } + } + + void _handleAppFrame(Duration timestamp) { + _frameCallbackScheduled = false; + if (!hasListeners) { + return; + } + assert(_nextFrame != null); + if (_isFirstFrame() || _hasFrameDurationPassed(timestamp)) { + _emitFrame(ImageInfo( + image: _nextFrame!.image.clone(), + scale: _scale, + debugLabel: debugLabel, + )); + _shownTimestamp = timestamp; + _frameDuration = _nextFrame!.duration; + _nextFrame!.image.dispose(); + _nextFrame = null; + final int completedCycles = _framesEmitted ~/ _codec!.frameCount; + if (_codec!.repetitionCount == -1 || completedCycles <= _codec!.repetitionCount) { + _decodeNextFrameAndSchedule(); + } + return; + } + final Duration delay = _frameDuration! - (timestamp - _shownTimestamp); + _timer = Timer(delay * timeDilation, () { + _scheduleAppFrame(); + }); + } + + bool _isFirstFrame() { + return _frameDuration == null; + } + + bool _hasFrameDurationPassed(Duration timestamp) { + return timestamp - _shownTimestamp >= _frameDuration!; + } + + Future<void> _decodeNextFrameAndSchedule() async { + // This will be null if we gave it away. If not, it's still ours and it + // must be disposed of. + _nextFrame?.image.dispose(); + _nextFrame = null; + try { + _nextFrame = await _codec!.getNextFrame(); + } catch (exception, stack) { + reportError( + context: ErrorDescription('resolving an image frame'), + exception: exception, + stack: stack, + informationCollector: _informationCollector, + silent: true, + ); + return; + } + if (_codec!.frameCount == 1) { + // ImageStreamCompleter listeners removed while waiting for next frame to + // be decoded. + // There's no reason to emit the frame without active listeners. + if (!hasListeners) { + return; + } + // This is not an animated image, just return it and don't schedule more + // frames. + _emitFrame(ImageInfo( + image: _nextFrame!.image.clone(), + scale: _scale, + debugLabel: debugLabel, + )); + _nextFrame!.image.dispose(); + _nextFrame = null; + return; + } + _scheduleAppFrame(); + } + + void _scheduleAppFrame() { + if (_frameCallbackScheduled) { + return; + } + _frameCallbackScheduled = true; + SchedulerBinding.instance.scheduleFrameCallback(_handleAppFrame); + } + + void _emitFrame(ImageInfo imageInfo) { + setImage(imageInfo); + _framesEmitted += 1; + } + + @override + void addListener(ImageStreamListener listener) { + if (!hasListeners && _codec != null && (_currentImage == null || _codec!.frameCount > 1)) { + _decodeNextFrameAndSchedule(); + } + super.addListener(listener); + } + + @override + void removeListener(ImageStreamListener listener) { + super.removeListener(listener); + if (!hasListeners) { + _timer?.cancel(); + _timer = null; + } + } + + @override + void _maybeDispose() { + super._maybeDispose(); + if (_disposed) { + _chunkSubscription?.onData(null); + _chunkSubscription?.cancel(); + _chunkSubscription = null; + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/inline_span.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/inline_span.dart new file mode 100644 index 0000000000000000000000000000000000000000..97bb83f2c6b2c79dfd71668dd0f2713a62b14d8f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/inline_span.dart @@ -0,0 +1,402 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show ParagraphBuilder, StringAttribute; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; + +import 'basic_types.dart'; +import 'text_painter.dart'; +import 'text_scaler.dart'; +import 'text_span.dart'; +import 'text_style.dart'; + +// Examples can assume: +// late InlineSpan myInlineSpan; + +/// Mutable wrapper of an integer that can be passed by reference to track a +/// value across a recursive stack. +class Accumulator { + /// [Accumulator] may be initialized with a specified value, otherwise, it will + /// initialize to zero. + Accumulator([this._value = 0]); + + /// The integer stored in this [Accumulator]. + int get value => _value; + int _value; + + /// Increases the [value] by the `addend`. + void increment(int addend) { + assert(addend >= 0); + _value += addend; + } +} +/// Called on each span as [InlineSpan.visitChildren] walks the [InlineSpan] tree. +/// +/// Returns true when the walk should continue, and false to stop visiting further +/// [InlineSpan]s. +typedef InlineSpanVisitor = bool Function(InlineSpan span); + +/// The textual and semantic label information for an [InlineSpan]. +/// +/// For [PlaceholderSpan]s, [InlineSpanSemanticsInformation.placeholder] is used by default. +/// +/// See also: +/// +/// * [InlineSpan.getSemanticsInformation] +@immutable +class InlineSpanSemanticsInformation { + /// Constructs an object that holds the text and semantics label values of an + /// [InlineSpan]. + /// + /// Use [InlineSpanSemanticsInformation.placeholder] instead of directly setting + /// [isPlaceholder]. + const InlineSpanSemanticsInformation( + this.text, { + this.isPlaceholder = false, + this.semanticsLabel, + this.stringAttributes = const <ui.StringAttribute>[], + this.recognizer, + }) : assert(!isPlaceholder || (text == '\uFFFC' && semanticsLabel == null && recognizer == null)), + requiresOwnNode = isPlaceholder || recognizer != null; + + /// The text info for a [PlaceholderSpan]. + static const InlineSpanSemanticsInformation placeholder = InlineSpanSemanticsInformation('\uFFFC', isPlaceholder: true); + + /// The text value, if any. For [PlaceholderSpan]s, this will be the unicode + /// placeholder value. + final String text; + + /// The semanticsLabel, if any. + final String? semanticsLabel; + + /// The gesture recognizer, if any, for this span. + final GestureRecognizer? recognizer; + + /// Whether this is for a placeholder span. + final bool isPlaceholder; + + /// True if this configuration should get its own semantics node. + /// + /// This will be the case of the [recognizer] is not null, of if + /// [isPlaceholder] is true. + final bool requiresOwnNode; + + /// The string attributes attached to this semantics information + final List<ui.StringAttribute> stringAttributes; + + @override + bool operator ==(Object other) { + return other is InlineSpanSemanticsInformation + && other.text == text + && other.semanticsLabel == semanticsLabel + && other.recognizer == recognizer + && other.isPlaceholder == isPlaceholder + && listEquals<ui.StringAttribute>(other.stringAttributes, stringAttributes); + } + + @override + int get hashCode => Object.hash(text, semanticsLabel, recognizer, isPlaceholder); + + @override + String toString() => '${objectRuntimeType(this, 'InlineSpanSemanticsInformation')}{text: $text, semanticsLabel: $semanticsLabel, recognizer: $recognizer}'; +} + +/// Combines _semanticsInfo entries where permissible. +/// +/// Consecutive inline spans can be combined if their +/// [InlineSpanSemanticsInformation.requiresOwnNode] return false. +List<InlineSpanSemanticsInformation> combineSemanticsInfo(List<InlineSpanSemanticsInformation> infoList) { + final List<InlineSpanSemanticsInformation> combined = <InlineSpanSemanticsInformation>[]; + String workingText = ''; + String workingLabel = ''; + List<ui.StringAttribute> workingAttributes = <ui.StringAttribute>[]; + for (final InlineSpanSemanticsInformation info in infoList) { + if (info.requiresOwnNode) { + combined.add(InlineSpanSemanticsInformation( + workingText, + semanticsLabel: workingLabel, + stringAttributes: workingAttributes, + )); + workingText = ''; + workingLabel = ''; + workingAttributes = <ui.StringAttribute>[]; + combined.add(info); + } else { + workingText += info.text; + final String effectiveLabel = info.semanticsLabel ?? info.text; + for (final ui.StringAttribute infoAttribute in info.stringAttributes) { + workingAttributes.add( + infoAttribute.copy( + range: TextRange( + start: infoAttribute.range.start + workingLabel.length, + end: infoAttribute.range.end + workingLabel.length, + ), + ), + ); + } + workingLabel += effectiveLabel; + + } + } + combined.add(InlineSpanSemanticsInformation( + workingText, + semanticsLabel: workingLabel, + stringAttributes: workingAttributes, + )); + return combined; +} + +/// An immutable span of inline content which forms part of a paragraph. +/// +/// * The subclass [TextSpan] specifies text and may contain child [InlineSpan]s. +/// * The subclass [PlaceholderSpan] represents a placeholder that may be +/// filled with non-text content. [PlaceholderSpan] itself defines a +/// [ui.PlaceholderAlignment] and a [TextBaseline]. To be useful, +/// [PlaceholderSpan] must be extended to define content. An instance of +/// this is the [WidgetSpan] class in the widgets library. +/// * The subclass [WidgetSpan] specifies embedded inline widgets. +/// +/// {@tool snippet} +/// +/// This example shows a tree of [InlineSpan]s that make a query asking for a +/// name with a [TextField] embedded inline. +/// +/// ```dart +/// Text.rich( +/// TextSpan( +/// text: 'My name is ', +/// style: const TextStyle(color: Colors.black), +/// children: <InlineSpan>[ +/// WidgetSpan( +/// alignment: PlaceholderAlignment.baseline, +/// baseline: TextBaseline.alphabetic, +/// child: ConstrainedBox( +/// constraints: const BoxConstraints(maxWidth: 100), +/// child: const TextField(), +/// ) +/// ), +/// const TextSpan( +/// text: '.', +/// ), +/// ], +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Text], a widget for showing uniformly-styled text. +/// * [RichText], a widget for finer control of text rendering. +/// * [TextPainter], a class for painting [InlineSpan] objects on a [Canvas]. +@immutable +abstract class InlineSpan extends DiagnosticableTree { + /// Creates an [InlineSpan] with the given values. + const InlineSpan({ + this.style, + }); + + /// The [TextStyle] to apply to this span. + /// + /// The [style] is also applied to any child spans when this is an instance + /// of [TextSpan]. + final TextStyle? style; + + /// Apply the properties of this object to the given [ParagraphBuilder], from + /// which a [Paragraph] can be obtained. + /// + /// The `textScaler` parameter specifies a [TextScaler] that the text and + /// placeholders will be scaled by. The scaling is performed before layout, + /// so the text will be laid out with the scaled glyphs and placeholders. + /// + /// The `dimensions` parameter specifies the sizes of the placeholders. + /// Each [PlaceholderSpan] must be paired with a [PlaceholderDimensions] + /// in the same order as defined in the [InlineSpan] tree. + /// + /// [Paragraph] objects can be drawn on [Canvas] objects. + void build(ui.ParagraphBuilder builder, { + TextScaler textScaler = TextScaler.noScaling, + List<PlaceholderDimensions>? dimensions, + }); + + /// Walks this [InlineSpan] and any descendants in pre-order and calls `visitor` + /// for each span that has content. + /// + /// When `visitor` returns true, the walk will continue. When `visitor` returns + /// false, then the walk will end. + /// + /// See also: + /// + /// * [visitDirectChildren], which preforms `build`-order traversal on the + /// immediate children of this [InlineSpan], regardless of whether they + /// have content. + bool visitChildren(InlineSpanVisitor visitor); + + /// Calls `visitor` for each immediate child of this [InlineSpan]. + /// + /// The immediate children are visited in the same order they are added to + /// a [ui.ParagraphBuilder] in the [build] method, which is also the logical + /// order of the child [InlineSpan]s in the text. + /// + /// The traversal stops when all immediate children are visited, or when the + /// `visitor` callback returns `false` on an immediate child. This method + /// itself returns a `bool` indicating whether the visitor callback returned + /// `true` on all immediate children. + /// + /// See also: + /// + /// * [visitChildren], which performs preorder traversal on this [InlineSpan] + /// if it has content, and all its descendants with content. + bool visitDirectChildren(InlineSpanVisitor visitor); + + /// Returns the [InlineSpan] that contains the given position in the text. + InlineSpan? getSpanForPosition(TextPosition position) { + assert(debugAssertIsValid()); + final Accumulator offset = Accumulator(); + InlineSpan? result; + visitChildren((InlineSpan span) { + result = span.getSpanForPositionVisitor(position, offset); + return result == null; + }); + return result; + } + + /// Performs the check at each [InlineSpan] for if the `position` falls within the range + /// of the span and returns the span if it does. + /// + /// The `offset` parameter tracks the current index offset in the text buffer formed + /// if the contents of the [InlineSpan] tree were concatenated together starting + /// from the root [InlineSpan]. + /// + /// This method should not be directly called. Use [getSpanForPosition] instead. + @protected + InlineSpan? getSpanForPositionVisitor(TextPosition position, Accumulator offset); + + /// Flattens the [InlineSpan] tree into a single string. + /// + /// Styles are not honored in this process. If `includeSemanticsLabels` is + /// true, then the text returned will include the [TextSpan.semanticsLabel]s + /// instead of the text contents for [TextSpan]s. + /// + /// When `includePlaceholders` is true, [PlaceholderSpan]s in the tree will be + /// represented as a 0xFFFC 'object replacement character'. + String toPlainText({bool includeSemanticsLabels = true, bool includePlaceholders = true}) { + final StringBuffer buffer = StringBuffer(); + computeToPlainText(buffer, includeSemanticsLabels: includeSemanticsLabels, includePlaceholders: includePlaceholders); + return buffer.toString(); + } + + /// Flattens the [InlineSpan] tree to a list of + /// [InlineSpanSemanticsInformation] objects. + /// + /// [PlaceholderSpan]s in the tree will be represented with a + /// [InlineSpanSemanticsInformation.placeholder] value. + List<InlineSpanSemanticsInformation> getSemanticsInformation() { + final List<InlineSpanSemanticsInformation> collector = <InlineSpanSemanticsInformation>[]; + computeSemanticsInformation(collector); + return collector; + } + + /// Walks the [InlineSpan] tree and accumulates a list of + /// [InlineSpanSemanticsInformation] objects. + /// + /// This method should not be directly called. Use + /// [getSemanticsInformation] instead. + /// + /// [PlaceholderSpan]s in the tree will be represented with a + /// [InlineSpanSemanticsInformation.placeholder] value. + @protected + void computeSemanticsInformation(List<InlineSpanSemanticsInformation> collector); + + /// Walks the [InlineSpan] tree and writes the plain text representation to `buffer`. + /// + /// This method should not be directly called. Use [toPlainText] instead. + /// + /// Styles are not honored in this process. If `includeSemanticsLabels` is + /// true, then the text returned will include the [TextSpan.semanticsLabel]s + /// instead of the text contents for [TextSpan]s. + /// + /// When `includePlaceholders` is true, [PlaceholderSpan]s in the tree will be + /// represented as a 0xFFFC 'object replacement character'. + /// + /// The plain-text representation of this [InlineSpan] is written into the `buffer`. + /// This method will then recursively call [computeToPlainText] on its children + /// [InlineSpan]s if available. + @protected + void computeToPlainText(StringBuffer buffer, {bool includeSemanticsLabels = true, bool includePlaceholders = true}); + + /// Returns the UTF-16 code unit at the given `index` in the flattened string. + /// + /// This only accounts for the [TextSpan.text] values and ignores [PlaceholderSpan]s. + /// + /// Returns null if the `index` is out of bounds. + int? codeUnitAt(int index) { + if (index < 0) { + return null; + } + final Accumulator offset = Accumulator(); + int? result; + visitChildren((InlineSpan span) { + result = span.codeUnitAtVisitor(index, offset); + return result == null; + }); + return result; + } + + /// Performs the check at each [InlineSpan] for if the `index` falls within the range + /// of the span and returns the corresponding code unit. Returns null otherwise. + /// + /// The `offset` parameter tracks the current index offset in the text buffer formed + /// if the contents of the [InlineSpan] tree were concatenated together starting + /// from the root [InlineSpan]. + /// + /// This method should not be directly called. Use [codeUnitAt] instead. + @protected + int? codeUnitAtVisitor(int index, Accumulator offset); + + /// In debug mode, throws an exception if the object is not in a + /// valid configuration. Otherwise, returns true. + /// + /// This is intended to be used as follows: + /// + /// ```dart + /// assert(myInlineSpan.debugAssertIsValid()); + /// ``` + bool debugAssertIsValid() => true; + + /// Describe the difference between this span and another, in terms of + /// how much damage it will make to the rendering. The comparison is deep. + /// + /// Comparing [InlineSpan] objects of different types, for example, comparing + /// a [TextSpan] to a [WidgetSpan], always results in [RenderComparison.layout]. + /// + /// See also: + /// + /// * [TextStyle.compareTo], which does the same thing for [TextStyle]s. + RenderComparison compareTo(InlineSpan other); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is InlineSpan + && other.style == style; + } + + @override + int get hashCode => style.hashCode; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.defaultDiagnosticsTreeStyle = DiagnosticsTreeStyle.whitespace; + style?.debugFillProperties(properties); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/linear_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/linear_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..eaa51eec1145ee80b2cb71495c141ae826884c04 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/linear_border.dart @@ -0,0 +1,395 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'borders.dart'; +import 'edge_insets.dart'; + +/// Defines the relative size and alignment of one <LinearBorder> edge. +/// +/// A [LinearBorder] defines a box outline as zero to four edges, each +/// of which is rendered as a single line. The width and color of the +/// lines is defined by [LinearBorder.side]. +/// +/// Each line's length is defined by [size], a value between 0.0 and 1.0 +/// (the default) which defines the length as a percentage of the +/// length of a box edge. +/// +/// When [size] is less than 1.0, the line is aligned within the +/// available space according to [alignment], a value between -1.0 and +/// 1.0. The default is 0.0, which means centered, -1.0 means align on the +/// "start" side, and 1.0 means align on the "end" side. The meaning of +/// start and end depend on the current [TextDirection], see +/// [Directionality]. +@immutable +class LinearBorderEdge { + /// Defines one side of a [LinearBorder]. + /// + /// The values of [size] and [alignment] must be between + /// 0.0 and 1.0, and -1.0 and 1.0 respectively. + const LinearBorderEdge({ + this.size = 1.0, + this.alignment = 0.0, + }) : assert(size >= 0.0 && size <= 1.0); + + /// A value between 0.0 and 1.0 that defines the length of the edge as a + /// percentage of the length of the corresponding box + /// edge. Default is 1.0. + final double size; + + /// A value between -1.0 and 1.0 that defines how edges for which [size] + /// is less than 1.0 are aligned relative to the corresponding box edge. + /// + /// * -1.0, aligned in the "start" direction. That's left + /// for [TextDirection.ltr] and right for [TextDirection.rtl]. + /// * 0.0, centered. + /// * 1.0, aligned in the "end" direction. That's right + /// for [TextDirection.ltr] and left for [TextDirection.rtl]. + final double alignment; + + /// Linearly interpolates between two [LinearBorder]s. + /// + /// If both `a` and `b` are null then null is returned. If `a` is null + /// then we interpolate to `b` varying [size] from 0.0 to `b.size`. If `b` + /// is null then we interpolate from `a` varying size from `a.size` to zero. + /// Otherwise both values are interpolated. + static LinearBorderEdge? lerp(LinearBorderEdge? a, LinearBorderEdge? b, double t) { + if (identical(a, b)) { + return a; + } + + a ??= LinearBorderEdge(alignment: b!.alignment, size: 0); + b ??= LinearBorderEdge(alignment: a.alignment, size: 0); + + return LinearBorderEdge( + size: lerpDouble(a.size, b.size, t)!, + alignment: lerpDouble(a.alignment, b.alignment, t)!, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is LinearBorderEdge + && other.size == size + && other.alignment == alignment; + } + + @override + int get hashCode => Object.hash(size, alignment); + + @override + String toString() { + final StringBuffer s = StringBuffer('${objectRuntimeType(this, 'LinearBorderEdge')}('); + if (size != 1.0 ) { + s.write('size: $size'); + } + if (alignment != 0) { + final String comma = size != 1.0 ? ', ' : ''; + s.write('${comma}alignment: $alignment'); + } + s.write(')'); + return s.toString(); + } +} + +/// An [OutlinedBorder] like [BoxBorder] that allows one to define a rectangular (box) border +/// in terms of zero to four [LinearBorderEdge]s, each of which is rendered as a single line. +/// +/// The color and width of each line are defined by [side]. When [LinearBorder] is used +/// with a class whose border sides and shape are defined by a [ButtonStyle], then a non-null +/// [ButtonStyle.side] will override the one specified here. For example the [LinearBorder] +/// in the [TextButton] example below adds a red underline to the button. This is because +/// TextButton's `side` parameter overrides the `side` property of its [ButtonStyle.shape]. +/// +/// ```dart +/// TextButton( +/// style: TextButton.styleFrom( +/// side: const BorderSide(color: Colors.red), +/// shape: const LinearBorder( +/// side: BorderSide(color: Colors.blue), +/// bottom: LinearBorderEdge(), +/// ), +/// ), +/// onPressed: () { }, +/// child: const Text('Red LinearBorder'), +/// ) +///``` +/// +/// This class resolves itself against the current [TextDirection] (see [Directionality]). +/// Start and end values resolve to left and right for [TextDirection.ltr] and to +/// right and left for [TextDirection.rtl]. +/// +/// Convenience constructors are included for the common case where just one edge is specified: +/// [LinearBorder.start], [LinearBorder.end], [LinearBorder.top], [LinearBorder.bottom]. +/// +/// {@tool dartpad} +/// This example shows how to draw different kinds of [LinearBorder]s. +/// +/// ** See code in examples/api/lib/painting/linear_border/linear_border.0.dart ** +/// {@end-tool} +class LinearBorder extends OutlinedBorder { + /// Creates a rectangular box border that's rendered as zero to four lines. + const LinearBorder({ + super.side, + this.start, + this.end, + this.top, + this.bottom, + }); + + /// Creates a rectangular box border with an edge on the left for [TextDirection.ltr] + /// or on the right for [TextDirection.rtl]. + LinearBorder.start({ + super.side, + double alignment = 0.0, + double size = 1.0 + }) : start = LinearBorderEdge(alignment: alignment, size: size), + end = null, + top = null, + bottom = null; + + /// Creates a rectangular box border with an edge on the right for [TextDirection.ltr] + /// or on the left for [TextDirection.rtl]. + LinearBorder.end({ + super.side, + double alignment = 0.0, + double size = 1.0 + }) : start = null, + end = LinearBorderEdge(alignment: alignment, size: size), + top = null, + bottom = null; + + /// Creates a rectangular box border with an edge on the top. + LinearBorder.top({ + super.side, + double alignment = 0.0, + double size = 1.0 + }) : start = null, + end = null, + top = LinearBorderEdge(alignment: alignment, size: size), + bottom = null; + + /// Creates a rectangular box border with an edge on the bottom. + LinearBorder.bottom({ + super.side, + double alignment = 0.0, + double size = 1.0 + }) : start = null, + end = null, + top = null, + bottom = LinearBorderEdge(alignment: alignment, size: size); + + /// No border. + static const LinearBorder none = LinearBorder(); + + /// Defines the left edge for [TextDirection.ltr] or the right + /// for [TextDirection.rtl]. + final LinearBorderEdge? start; + + /// Defines the right edge for [TextDirection.ltr] or the left + /// for [TextDirection.rtl]. + final LinearBorderEdge? end; + + /// Defines the top edge. + final LinearBorderEdge? top; + + /// Defines the bottom edge. + final LinearBorderEdge? bottom; + + @override + LinearBorder scale(double t) { + return LinearBorder( + side: side.scale(t), + ); + } + + @override + EdgeInsetsGeometry get dimensions { + final double width = side.width; + return EdgeInsetsDirectional.fromSTEB( + start == null ? 0.0 : width, + top == null ? 0.0 : width, + end == null ? 0.0 : width, + bottom == null ? 0.0 : width, + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is LinearBorder) { + return LinearBorder( + side: BorderSide.lerp(a.side, side, t), + start: LinearBorderEdge.lerp(a.start, start, t), + end: LinearBorderEdge.lerp(a.end, end, t), + top: LinearBorderEdge.lerp(a.top, top, t), + bottom: LinearBorderEdge.lerp(a.bottom, bottom, t), + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is LinearBorder) { + return LinearBorder( + side: BorderSide.lerp(side, b.side, t), + start: LinearBorderEdge.lerp(start, b.start, t), + end: LinearBorderEdge.lerp(end, b.end, t), + top: LinearBorderEdge.lerp(top, b.top, t), + bottom: LinearBorderEdge.lerp(bottom, b.bottom, t), + ); + } + return super.lerpTo(b, t); + } + + /// Returns a copy of this LinearBorder with the given fields replaced with + /// the new values. + @override + LinearBorder copyWith({ + BorderSide? side, + LinearBorderEdge? start, + LinearBorderEdge? end, + LinearBorderEdge? top, + LinearBorderEdge? bottom, + }) { + return LinearBorder( + side: side ?? this.side, + start: start ?? this.start, + end: end ?? this.end, + top: top ?? this.top, + bottom: bottom ?? this.bottom, + ); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + final Rect adjustedRect = dimensions.resolve(textDirection).deflateRect(rect); + return Path() + ..addRect(adjustedRect); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path() + ..addRect(rect); + } + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + final EdgeInsets insets = dimensions.resolve(textDirection); + final bool rtl = textDirection == TextDirection.rtl; + + final Path path = Path(); + final Paint paint = Paint() + ..strokeWidth = 0.0; + + void drawEdge(Rect rect, Color color) { + paint.color = color; + path.reset(); + path.moveTo(rect.left, rect.top); + if (rect.width == 0.0) { + paint.style = PaintingStyle.stroke; + path.lineTo(rect.left, rect.bottom); + } else if (rect.height == 0.0) { + paint.style = PaintingStyle.stroke; + path.lineTo(rect.right, rect.top); + } else { + paint.style = PaintingStyle.fill; + path.lineTo(rect.right, rect.top); + path.lineTo(rect.right, rect.bottom); + path.lineTo(rect.left, rect.bottom); + } + canvas.drawPath(path, paint); + } + + if (start != null && start!.size != 0.0 && side.style != BorderStyle.none) { + final Rect insetRect = Rect.fromLTWH(rect.left, rect.top + insets.top, rect.width, rect.height - insets.vertical); + final double x = rtl ? rect.right - insets.right : rect.left; + final double width = rtl ? insets.right : insets.left; + final double height = insetRect.height * start!.size; + final double y = (insetRect.height - height) * ((start!.alignment + 1.0) / 2.0); + final Rect r = Rect.fromLTWH(x, y, width, height); + drawEdge(r, side.color); + } + + if (end != null && end!.size != 0.0 && side.style != BorderStyle.none) { + final Rect insetRect = Rect.fromLTWH(rect.left, rect.top + insets.top, rect.width, rect.height - insets.vertical); + final double x = rtl ? rect.left : rect.right - insets.right; + final double width = rtl ? insets.left : insets.right; + final double height = insetRect.height * end!.size; + final double y = (insetRect.height - height) * ((end!.alignment + 1.0) / 2.0); + final Rect r = Rect.fromLTWH(x, y, width, height); + drawEdge(r, side.color); + } + + if (top != null && top!.size != 0.0 && side.style != BorderStyle.none) { + final double width = rect.width * top!.size; + final double startX = (rect.width - width) * ((top!.alignment + 1.0) / 2.0); + final double x = rtl ? rect.width - startX - width : startX; + final Rect r = Rect.fromLTWH(x, rect.top, width, insets.top); + drawEdge(r, side.color); + } + + if (bottom != null && bottom!.size != 0.0 && side.style != BorderStyle.none) { + final double width = rect.width * bottom!.size; + final double startX = (rect.width - width) * ((bottom!.alignment + 1.0) / 2.0); + final double x = rtl ? rect.width - startX - width: startX; + final Rect r = Rect.fromLTWH(x, rect.bottom - insets.bottom, width, side.width); + drawEdge(r, side.color); + } + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is LinearBorder + && other.side == side + && other.start == start + && other.end == end + && other.top == top + && other.bottom == bottom; + } + + @override + int get hashCode => Object.hash(side, start, end, top, bottom); + + @override + String toString() { + if (this == LinearBorder.none) { + return 'LinearBorder.none'; + } + + final StringBuffer s = StringBuffer('${objectRuntimeType(this, 'LinearBorder')}(side: $side'); + + if (start != null ) { + s.write(', start: $start'); + } + if (end != null ) { + s.write(', end: $end'); + } + if (top != null ) { + s.write(', top: $top'); + } + if (bottom != null ) { + s.write(', bottom: $bottom'); + } + s.write(')'); + return s.toString(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/matrix_utils.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/matrix_utils.dart new file mode 100644 index 0000000000000000000000000000000000000000..b2d0018de6207ca8c04ae032cf5c24393cab4937 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/matrix_utils.dart @@ -0,0 +1,567 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'basic_types.dart'; + +/// Utility functions for working with matrices. +abstract final class MatrixUtils { + /// Returns the given [transform] matrix as an [Offset], if the matrix is + /// nothing but a 2D translation. + /// + /// Otherwise, returns null. + static Offset? getAsTranslation(Matrix4 transform) { + final Float64List values = transform.storage; + // Values are stored in column-major order. + if (values[0] == 1.0 && // col 1 + values[1] == 0.0 && + values[2] == 0.0 && + values[3] == 0.0 && + values[4] == 0.0 && // col 2 + values[5] == 1.0 && + values[6] == 0.0 && + values[7] == 0.0 && + values[8] == 0.0 && // col 3 + values[9] == 0.0 && + values[10] == 1.0 && + values[11] == 0.0 && + values[14] == 0.0 && // bottom of col 4 (values 12 and 13 are the x and y offsets) + values[15] == 1.0) { + return Offset(values[12], values[13]); + } + return null; + } + + /// Returns the given [transform] matrix as a [double] describing a uniform + /// scale, if the matrix is nothing but a symmetric 2D scale transform. + /// + /// Otherwise, returns null. + static double? getAsScale(Matrix4 transform) { + final Float64List values = transform.storage; + // Values are stored in column-major order. + if (values[1] == 0.0 && // col 1 (value 0 is the scale) + values[2] == 0.0 && + values[3] == 0.0 && + values[4] == 0.0 && // col 2 (value 5 is the scale) + values[6] == 0.0 && + values[7] == 0.0 && + values[8] == 0.0 && // col 3 + values[9] == 0.0 && + values[10] == 1.0 && + values[11] == 0.0 && + values[12] == 0.0 && // col 4 + values[13] == 0.0 && + values[14] == 0.0 && + values[15] == 1.0 && + values[0] == values[5]) { // uniform scale + return values[0]; + } + return null; + } + + /// Returns true if the given matrices are exactly equal, and false + /// otherwise. Null values are assumed to be the identity matrix. + static bool matrixEquals(Matrix4? a, Matrix4? b) { + if (identical(a, b)) { + return true; + } + assert(a != null || b != null); + if (a == null) { + return isIdentity(b!); + } + if (b == null) { + return isIdentity(a); + } + return a.storage[0] == b.storage[0] + && a.storage[1] == b.storage[1] + && a.storage[2] == b.storage[2] + && a.storage[3] == b.storage[3] + && a.storage[4] == b.storage[4] + && a.storage[5] == b.storage[5] + && a.storage[6] == b.storage[6] + && a.storage[7] == b.storage[7] + && a.storage[8] == b.storage[8] + && a.storage[9] == b.storage[9] + && a.storage[10] == b.storage[10] + && a.storage[11] == b.storage[11] + && a.storage[12] == b.storage[12] + && a.storage[13] == b.storage[13] + && a.storage[14] == b.storage[14] + && a.storage[15] == b.storage[15]; + } + + /// Whether the given matrix is the identity matrix. + static bool isIdentity(Matrix4 a) { + return a.storage[0] == 1.0 // col 1 + && a.storage[1] == 0.0 + && a.storage[2] == 0.0 + && a.storage[3] == 0.0 + && a.storage[4] == 0.0 // col 2 + && a.storage[5] == 1.0 + && a.storage[6] == 0.0 + && a.storage[7] == 0.0 + && a.storage[8] == 0.0 // col 3 + && a.storage[9] == 0.0 + && a.storage[10] == 1.0 + && a.storage[11] == 0.0 + && a.storage[12] == 0.0 // col 4 + && a.storage[13] == 0.0 + && a.storage[14] == 0.0 + && a.storage[15] == 1.0; + } + + /// Applies the given matrix as a perspective transform to the given point. + /// + /// This function assumes the given point has a z-coordinate of 0.0. The + /// z-coordinate of the result is ignored. + /// + /// While not common, this method may return (NaN, NaN), iff the given `point` + /// results in a "point at infinity" in homogeneous coordinates after applying + /// the `transform`. For example, a [RenderObject] may set its transform to + /// the zero matrix to indicate its content is currently not visible. Trying + /// to convert an `Offset` to its coordinate space always results in + /// (NaN, NaN). + static Offset transformPoint(Matrix4 transform, Offset point) { + final Float64List storage = transform.storage; + final double x = point.dx; + final double y = point.dy; + + // Directly simulate the transform of the vector (x, y, 0, 1), + // dropping the resulting Z coordinate, and normalizing only + // if needed. + + final double rx = storage[0] * x + storage[4] * y + storage[12]; + final double ry = storage[1] * x + storage[5] * y + storage[13]; + final double rw = storage[3] * x + storage[7] * y + storage[15]; + if (rw == 1.0) { + return Offset(rx, ry); + } else { + return Offset(rx / rw, ry / rw); + } + } + + /// Returns a rect that bounds the result of applying the given matrix as a + /// perspective transform to the given rect. + /// + /// This version of the operation is slower than the regular transformRect + /// method, but it avoids creating infinite values from large finite values + /// if it can. + static Rect _safeTransformRect(Matrix4 transform, Rect rect) { + final Float64List storage = transform.storage; + final bool isAffine = storage[3] == 0.0 && + storage[7] == 0.0 && + storage[15] == 1.0; + + _accumulate(storage, rect.left, rect.top, true, isAffine); + _accumulate(storage, rect.right, rect.top, false, isAffine); + _accumulate(storage, rect.left, rect.bottom, false, isAffine); + _accumulate(storage, rect.right, rect.bottom, false, isAffine); + + return Rect.fromLTRB(_minMax[0], _minMax[1], _minMax[2], _minMax[3]); + } + + static final Float64List _minMax = Float64List(4); + static void _accumulate(Float64List m, double x, double y, bool first, bool isAffine) { + final double w = isAffine ? 1.0 : 1.0 / (m[3] * x + m[7] * y + m[15]); + final double tx = (m[0] * x + m[4] * y + m[12]) * w; + final double ty = (m[1] * x + m[5] * y + m[13]) * w; + if (first) { + _minMax[0] = _minMax[2] = tx; + _minMax[1] = _minMax[3] = ty; + } else { + if (tx < _minMax[0]) { + _minMax[0] = tx; + } + if (ty < _minMax[1]) { + _minMax[1] = ty; + } + if (tx > _minMax[2]) { + _minMax[2] = tx; + } + if (ty > _minMax[3]) { + _minMax[3] = ty; + } + } + } + + /// Returns a rect that bounds the result of applying the given matrix as a + /// perspective transform to the given rect. + /// + /// This function assumes the given rect is in the plane with z equals 0.0. + /// The transformed rect is then projected back into the plane with z equals + /// 0.0 before computing its bounding rect. + static Rect transformRect(Matrix4 transform, Rect rect) { + final Float64List storage = transform.storage; + final double x = rect.left; + final double y = rect.top; + final double w = rect.right - x; + final double h = rect.bottom - y; + + // We want to avoid turning a finite rect into an infinite one if we can. + if (!w.isFinite || !h.isFinite) { + return _safeTransformRect(transform, rect); + } + + // Transforming the 4 corners of a rectangle the straightforward way + // incurs the cost of transforming 4 points using vector math which + // involves 48 multiplications and 48 adds and then normalizing + // the points using 4 inversions of the homogeneous weight factor + // and then 12 multiplies. Once we have transformed all of the points + // we then need to turn them into a bounding box using 4 min/max + // operations each on 4 values yielding 12 total comparisons. + // + // On top of all of those operations, using the vector_math package to + // do the work for us involves allocating several objects in order to + // communicate the values back and forth - 4 allocating getters to extract + // the [Offset] objects for the corners of the [Rect], 4 conversions to + // a [Vector3] to use [Matrix4.perspectiveTransform()], and then 4 new + // [Offset] objects allocated to hold those results, yielding 8 [Offset] + // and 4 [Vector3] object allocations per rectangle transformed. + // + // But the math we really need to get our answer is actually much less + // than that. + // + // First, consider that a full point transform using the vector math + // package involves expanding it out into a vector3 with a Z coordinate + // of 0.0 and then performing 3 multiplies and 3 adds per coordinate: + // + // xt = x*m00 + y*m10 + z*m20 + m30; + // yt = x*m01 + y*m11 + z*m21 + m31; + // zt = x*m02 + y*m12 + z*m22 + m32; + // wt = x*m03 + y*m13 + z*m23 + m33; + // + // Immediately we see that we can get rid of the 3rd column of multiplies + // since we know that Z=0.0. We can also get rid of the 3rd row because + // we ignore the resulting Z coordinate. Finally we can get rid of the + // last row if we don't have a perspective transform since we can verify + // that the results are 1.0 for all points. This gets us down to 16 + // multiplies and 16 adds in the non-perspective case and 24 of each for + // the perspective case. (Plus the 12 comparisons to turn them back into + // a bounding box.) + // + // But we can do even better than that. + // + // Under optimal conditions of no perspective transformation, + // which is actually a very common condition, we can transform + // a rectangle in as little as 3 operations: + // + // (rx,ry) = transform of upper left corner of rectangle + // (wx,wy) = delta transform of the (w, 0) width relative vector + // (hx,hy) = delta transform of the (0, h) height relative vector + // + // A delta transform is a transform of all elements of the matrix except + // for the translation components. The translation components are added + // in at the end of each transform computation so they represent a + // constant offset for each point transformed. A delta transform of + // a horizontal or vertical vector involves a single multiplication due + // to the fact that it only has one non-zero coordinate and no addition + // of the translation component. + // + // In the absence of a perspective transform, the transformed + // rectangle will be mapped into a parallelogram with corners at: + // corner1 = (rx, ry) + // corner2 = corner1 + dTransformed width vector = (rx+wx, ry+wy) + // corner3 = corner1 + dTransformed height vector = (rx+hx, ry+hy) + // corner4 = corner1 + both dTransformed vectors = (rx+wx+hx, ry+wy+hy) + // In all, this method of transforming the rectangle requires only + // 8 multiplies and 12 additions (which we can reduce to 8 additions if + // we only need a bounding box, see below). + // + // In the presence of a perspective transform, the above conditions + // continue to hold with respect to the non-normalized coordinates so + // we can still save a lot of multiplications by computing the 4 + // non-normalized coordinates using relative additions before we normalize + // them and they lose their "pseudo-parallelogram" relationships. We still + // have to do the normalization divisions and min/max all 4 points to + // get the resulting transformed bounding box, but we save a lot of + // calculations over blindly transforming all 4 coordinates independently. + // In all, we need 12 multiplies and 22 additions to construct the + // non-normalized vectors and then 8 divisions (or 4 inversions and 8 + // multiplies) for normalization (plus the standard set of 12 comparisons + // for the min/max bounds operations). + // + // Back to the non-perspective case, the optimization that lets us get + // away with fewer additions if we only need a bounding box comes from + // analyzing the impact of the relative vectors on expanding the + // bounding box of the parallelogram. First, the bounding box always + // contains the transformed upper-left corner of the rectangle. Next, + // each relative vector either pushes on the left or right side of the + // bounding box and also either the top or bottom side, depending on + // whether it is positive or negative. Finally, you can consider the + // impact of each vector on the bounding box independently. If, say, + // wx and hx have the same sign, then the limiting point in the bounding + // box will be the one that involves adding both of them to the origin + // point. If they have opposite signs, then one will push one wall one + // way and the other will push the opposite wall the other way and when + // you combine both of them, the resulting "opposite corner" will + // actually be between the limits they established by pushing the walls + // away from each other, as below: + // + // +---------(originx,originy)--------------+ + // | -----^---- | + // | ----- ---- | + // | ----- ---- | + // (+hx,+hy)< ---- | + // | ---- ---- | + // | ---- >(+wx,+wy) + // | ---- ----- | + // | ---- ----- | + // | ---- ----- | + // | v | + // +---------------(+wx+hx,+wy+hy)----------+ + // + // In this diagram, consider that: + // + // * wx would be a positive number + // * hx would be a negative number + // * wy and hy would both be positive numbers + // + // As a result, wx pushes out the right wall, hx pushes out the left wall, + // and both wy and hy push down the bottom wall of the bounding box. The + // wx,hx pair (of opposite signs) worked on opposite walls and the final + // opposite corner had an X coordinate between the limits they established. + // The wy,hy pair (of the same sign) both worked together to push the + // bottom wall down by their sum. + // + // This relationship allows us to simply start with the point computed by + // transforming the upper left corner of the rectangle, and then + // conditionally adding wx, wy, hx, and hy to either the left or top + // or right or bottom of the bounding box independently depending on sign. + // In that case we only need 4 comparisons and 4 additions total to + // compute the bounding box, combined with the 8 multiplications and + // 4 additions to compute the transformed point and relative vectors + // for a total of 8 multiplies, 8 adds, and 4 comparisons. + // + // An astute observer will note that we do need to do 2 subtractions at + // the top of the method to compute the width and height. Add those to + // all of the relative solutions listed above. The test for perspective + // also adds 3 compares to the affine case and up to 3 compares to the + // perspective case (depending on which test fails, the rest are omitted). + // + // The final tally: + // basic method = 60 mul + 48 add + 12 compare + // optimized perspective = 12 mul + 22 add + 15 compare + 2 sub + // optimized affine = 8 mul + 8 add + 7 compare + 2 sub + // + // Since compares are essentially subtractions and subtractions are + // the same cost as adds, we end up with: + // basic method = 60 mul + 60 add/sub/compare + // optimized perspective = 12 mul + 39 add/sub/compare + // optimized affine = 8 mul + 17 add/sub/compare + + final double wx = storage[0] * w; + final double hx = storage[4] * h; + final double rx = storage[0] * x + storage[4] * y + storage[12]; + + final double wy = storage[1] * w; + final double hy = storage[5] * h; + final double ry = storage[1] * x + storage[5] * y + storage[13]; + + if (storage[3] == 0.0 && storage[7] == 0.0 && storage[15] == 1.0) { + double left = rx; + double right = rx; + if (wx < 0) { + left += wx; + } else { + right += wx; + } + if (hx < 0) { + left += hx; + } else { + right += hx; + } + + double top = ry; + double bottom = ry; + if (wy < 0) { + top += wy; + } else { + bottom += wy; + } + if (hy < 0) { + top += hy; + } else { + bottom += hy; + } + + return Rect.fromLTRB(left, top, right, bottom); + } else { + final double ww = storage[3] * w; + final double hw = storage[7] * h; + final double rw = storage[3] * x + storage[7] * y + storage[15]; + + final double ulx = rx / rw; + final double uly = ry / rw; + final double urx = (rx + wx) / (rw + ww); + final double ury = (ry + wy) / (rw + ww); + final double llx = (rx + hx) / (rw + hw); + final double lly = (ry + hy) / (rw + hw); + final double lrx = (rx + wx + hx) / (rw + ww + hw); + final double lry = (ry + wy + hy) / (rw + ww + hw); + + return Rect.fromLTRB( + _min4(ulx, urx, llx, lrx), + _min4(uly, ury, lly, lry), + _max4(ulx, urx, llx, lrx), + _max4(uly, ury, lly, lry), + ); + } + } + + static double _min4(double a, double b, double c, double d) { + final double e = (a < b) ? a : b; + final double f = (c < d) ? c : d; + return (e < f) ? e : f; + } + static double _max4(double a, double b, double c, double d) { + final double e = (a > b) ? a : b; + final double f = (c > d) ? c : d; + return (e > f) ? e : f; + } + + /// Returns a rect that bounds the result of applying the inverse of the given + /// matrix as a perspective transform to the given rect. + /// + /// This function assumes the given rect is in the plane with z equals 0.0. + /// The transformed rect is then projected back into the plane with z equals + /// 0.0 before computing its bounding rect. + static Rect inverseTransformRect(Matrix4 transform, Rect rect) { + // As exposed by `unrelated_type_equality_checks`, this assert was a no-op. + // Fixing it introduces a bunch of runtime failures; for more context see: + // https://github.com/flutter/flutter/pull/31568 + // assert(transform.determinant != 0.0); + if (isIdentity(transform)) { + return rect; + } + transform = Matrix4.copy(transform)..invert(); + return transformRect(transform, rect); + } + + /// Create a transformation matrix which mimics the effects of tangentially + /// wrapping the plane on which this transform is applied around a cylinder + /// and then looking at the cylinder from a point outside the cylinder. + /// + /// The `radius` simulates the radius of the cylinder the plane is being + /// wrapped onto. If the transformation is applied to a 0-dimensional dot + /// instead of a plane, the dot would translate by ± `radius` pixels + /// along the `orientation` [Axis] when rotating from 0 to ±90 degrees. + /// + /// A positive radius means the object is closest at 0 `angle` and a negative + /// radius means the object is closest at π `angle` or 180 degrees. + /// + /// The `angle` argument is the difference in angle in radians between the + /// object and the viewing point. A positive `angle` on a positive `radius` + /// moves the object up when `orientation` is vertical and right when + /// horizontal. + /// + /// The transformation is always done such that a 0 `angle` keeps the + /// transformed object at exactly the same size as before regardless of + /// `radius` and `perspective` when `radius` is positive. + /// + /// The `perspective` argument is a number between 0 and 1 where 0 means + /// looking at the object from infinitely far with an infinitely narrow field + /// of view and 1 means looking at the object from infinitely close with an + /// infinitely wide field of view. Defaults to a sane but arbitrary 0.001. + /// + /// The `orientation` is the direction of the rotation axis. + /// + /// Because the viewing position is a point, it's never possible to see the + /// outer side of the cylinder at or past ±π/2 or 90 degrees and it's + /// almost always possible to end up seeing the inner side of the cylinder + /// or the back side of the transformed plane before π / 2 when perspective > 0. + static Matrix4 createCylindricalProjectionTransform({ + required double radius, + required double angle, + double perspective = 0.001, + Axis orientation = Axis.vertical, + }) { + assert(perspective >= 0 && perspective <= 1.0); + + // Pre-multiplied matrix of a projection matrix and a view matrix. + // + // Projection matrix is a simplified perspective matrix + // http://web.iitd.ac.in/~hegde/cad/lecture/L9_persproj.pdf + // in the form of + // [[1.0, 0.0, 0.0, 0.0], + // [0.0, 1.0, 0.0, 0.0], + // [0.0, 0.0, 1.0, 0.0], + // [0.0, 0.0, -perspective, 1.0]] + // + // View matrix is a simplified camera view matrix. + // Basically re-scales to keep object at original size at angle = 0 at + // any radius in the form of + // [[1.0, 0.0, 0.0, 0.0], + // [0.0, 1.0, 0.0, 0.0], + // [0.0, 0.0, 1.0, -radius], + // [0.0, 0.0, 0.0, 1.0]] + Matrix4 result = Matrix4.identity() + ..setEntry(3, 2, -perspective) + ..setEntry(2, 3, -radius) + ..setEntry(3, 3, perspective * radius + 1.0); + + // Model matrix by first translating the object from the origin of the world + // by radius in the z axis and then rotating against the world. + result = result * (( + orientation == Axis.horizontal + ? Matrix4.rotationY(angle) + : Matrix4.rotationX(angle) + ) * Matrix4.translationValues(0.0, 0.0, radius)) as Matrix4; + + // Essentially perspective * view * model. + return result; + } + + /// Returns a matrix that transforms every point to [offset]. + static Matrix4 forceToPoint(Offset offset) { + return Matrix4.identity() + ..setRow(0, Vector4(0, 0, 0, offset.dx)) + ..setRow(1, Vector4(0, 0, 0, offset.dy)); + } +} + +/// Returns a list of strings representing the given transform in a format +/// useful for [TransformProperty]. +/// +/// If the argument is null, returns a list with the single string "null". +List<String> debugDescribeTransform(Matrix4? transform) { + if (transform == null) { + return const <String>['null']; + } + return <String>[ + '[0] ${debugFormatDouble(transform.entry(0, 0))},${debugFormatDouble(transform.entry(0, 1))},${debugFormatDouble(transform.entry(0, 2))},${debugFormatDouble(transform.entry(0, 3))}', + '[1] ${debugFormatDouble(transform.entry(1, 0))},${debugFormatDouble(transform.entry(1, 1))},${debugFormatDouble(transform.entry(1, 2))},${debugFormatDouble(transform.entry(1, 3))}', + '[2] ${debugFormatDouble(transform.entry(2, 0))},${debugFormatDouble(transform.entry(2, 1))},${debugFormatDouble(transform.entry(2, 2))},${debugFormatDouble(transform.entry(2, 3))}', + '[3] ${debugFormatDouble(transform.entry(3, 0))},${debugFormatDouble(transform.entry(3, 1))},${debugFormatDouble(transform.entry(3, 2))},${debugFormatDouble(transform.entry(3, 3))}', + ]; +} + +/// Property which handles [Matrix4] that represent transforms. +class TransformProperty extends DiagnosticsProperty<Matrix4> { + /// Create a diagnostics property for [Matrix4] objects. + TransformProperty( + String super.name, + super.value, { + super.showName, + super.defaultValue, + super.level, + }); + + @override + String valueToString({ TextTreeConfiguration? parentConfiguration }) { + if (parentConfiguration != null && !parentConfiguration.lineBreakProperties) { + // Format the value on a single line to be compatible with the parent's + // style. + final List<String> values = <String>[ + '${debugFormatDouble(value!.entry(0, 0))},${debugFormatDouble(value!.entry(0, 1))},${debugFormatDouble(value!.entry(0, 2))},${debugFormatDouble(value!.entry(0, 3))}', + '${debugFormatDouble(value!.entry(1, 0))},${debugFormatDouble(value!.entry(1, 1))},${debugFormatDouble(value!.entry(1, 2))},${debugFormatDouble(value!.entry(1, 3))}', + '${debugFormatDouble(value!.entry(2, 0))},${debugFormatDouble(value!.entry(2, 1))},${debugFormatDouble(value!.entry(2, 2))},${debugFormatDouble(value!.entry(2, 3))}', + '${debugFormatDouble(value!.entry(3, 0))},${debugFormatDouble(value!.entry(3, 1))},${debugFormatDouble(value!.entry(3, 2))},${debugFormatDouble(value!.entry(3, 3))}', + ]; + return '[${values.join('; ')}]'; + } + return debugDescribeTransform(value).join('\n'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/notched_shapes.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/notched_shapes.dart new file mode 100644 index 0000000000000000000000000000000000000000..2e19b315c66584684f5f17b2fb5144f2d61d1e1e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/notched_shapes.dart @@ -0,0 +1,164 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'basic_types.dart'; +import 'borders.dart'; + +/// A shape with a notch in its outline. +/// +/// Typically used as the outline of a 'host' widget to make a notch that +/// accommodates a 'guest' widget. e.g the [BottomAppBar] may have a notch to +/// accommodate the [FloatingActionButton]. +/// +/// See also: +/// +/// * [ShapeBorder], which defines a shaped border without a dynamic notch. +/// * [AutomaticNotchedShape], an adapter from [ShapeBorder] to [NotchedShape]. +abstract class NotchedShape { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const NotchedShape(); + + /// Creates a [Path] that describes the outline of the shape. + /// + /// The `host` is the bounding rectangle of the shape. + /// + /// The `guest` is the bounding rectangle of the shape for which a notch will + /// be made. It is null when there is no guest. + Path getOuterPath(Rect host, Rect? guest); +} + +/// A rectangle with a smooth circular notch. +/// +/// See also: +/// +/// * [CircleBorder], a [ShapeBorder] that describes a circle. +class CircularNotchedRectangle extends NotchedShape { + /// Creates a [CircularNotchedRectangle]. + /// + /// The same object can be used to create multiple shapes. + const CircularNotchedRectangle(); + + /// Creates a [Path] that describes a rectangle with a smooth circular notch. + /// + /// `host` is the bounding box for the returned shape. Conceptually this is + /// the rectangle to which the notch will be applied. + /// + /// `guest` is the bounding box of a circle that the notch accommodates. All + /// points in the circle bounded by `guest` will be outside of the returned + /// path. + /// + /// The notch is curve that smoothly connects the host's top edge and + /// the guest circle. + // TODO(amirh): add an example diagram here. + @override + Path getOuterPath(Rect host, Rect? guest) { + if (guest == null || !host.overlaps(guest)) { + return Path()..addRect(host); + } + + // The guest's shape is a circle bounded by the guest rectangle. + // So the guest's radius is half the guest width. + final double notchRadius = guest.width / 2.0; + + // We build a path for the notch from 3 segments: + // Segment A - a Bezier curve from the host's top edge to segment B. + // Segment B - an arc with radius notchRadius. + // Segment C - a Bezier curve from segment B back to the host's top edge. + // + // A detailed explanation and the derivation of the formulas below is + // available at: https://goo.gl/Ufzrqn + + const double s1 = 15.0; + const double s2 = 1.0; + + final double r = notchRadius; + final double a = -1.0 * r - s2; + final double b = host.top - guest.center.dy; + + final double n2 = math.sqrt(b * b * r * r * (a * a + b * b - r * r)); + final double p2xA = ((a * r * r) - n2) / (a * a + b * b); + final double p2xB = ((a * r * r) + n2) / (a * a + b * b); + final double p2yA = math.sqrt(r * r - p2xA * p2xA); + final double p2yB = math.sqrt(r * r - p2xB * p2xB); + + final List<Offset?> p = List<Offset?>.filled(6, null); + + // p0, p1, and p2 are the control points for segment A. + p[0] = Offset(a - s1, b); + p[1] = Offset(a, b); + final double cmp = b < 0 ? -1.0 : 1.0; + p[2] = cmp * p2yA > cmp * p2yB ? Offset(p2xA, p2yA) : Offset(p2xB, p2yB); + + // p3, p4, and p5 are the control points for segment B, which is a mirror + // of segment A around the y axis. + p[3] = Offset(-1.0 * p[2]!.dx, p[2]!.dy); + p[4] = Offset(-1.0 * p[1]!.dx, p[1]!.dy); + p[5] = Offset(-1.0 * p[0]!.dx, p[0]!.dy); + + // translate all points back to the absolute coordinate system. + for (int i = 0; i < p.length; i += 1) { + p[i] = p[i]! + guest.center; + } + + return Path() + ..moveTo(host.left, host.top) + ..lineTo(p[0]!.dx, p[0]!.dy) + ..quadraticBezierTo(p[1]!.dx, p[1]!.dy, p[2]!.dx, p[2]!.dy) + ..arcToPoint( + p[3]!, + radius: Radius.circular(notchRadius), + clockwise: false, + ) + ..quadraticBezierTo(p[4]!.dx, p[4]!.dy, p[5]!.dx, p[5]!.dy) + ..lineTo(host.right, host.top) + ..lineTo(host.right, host.bottom) + ..lineTo(host.left, host.bottom) + ..close(); + } +} + +/// A [NotchedShape] created from [ShapeBorder]s. +/// +/// Two shapes can be provided. The [host] is the shape of the widget that +/// uses the [NotchedShape] (typically a [BottomAppBar]). The [guest] is +/// subtracted from the [host] to create the notch (typically to make room +/// for a [FloatingActionButton]). +class AutomaticNotchedShape extends NotchedShape { + /// Creates a [NotchedShape] that is defined by two [ShapeBorder]s. + /// + /// The [guest] may be null, in which case no notch is created even + /// if a guest rectangle is provided to [getOuterPath]. + const AutomaticNotchedShape(this.host, [ this.guest ]); + + /// The shape of the widget that uses the [NotchedShape] (typically a + /// [BottomAppBar]). + /// + /// This shape cannot depend on the [TextDirection], as no text direction + /// is available to [NotchedShape]s. + final ShapeBorder host; + + /// The shape to subtract from the [host] to make the notch. + /// + /// This shape cannot depend on the [TextDirection], as no text direction + /// is available to [NotchedShape]s. + /// + /// If this is null, [getOuterPath] ignores the guest rectangle. + final ShapeBorder? guest; + + @override + Path getOuterPath(Rect hostRect, Rect? guestRect) { // ignore: avoid_renaming_method_parameters + // The parameters of this method are renamed over the baseclass because they + // would clash with properties of this object, and the use of all four of + // them in the code below is really confusing if they have the same names. + final Path hostPath = host.getOuterPath(hostRect); + if (guest != null && guestRect != null) { + final Path guestPath = guest!.getOuterPath(guestRect); + return Path.combine(PathOperation.difference, hostPath, guestPath); + } + return hostPath; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/oval_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/oval_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..d5bbf5b49b47617ab8ec588f41174f7252865c73 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/oval_border.dart @@ -0,0 +1,65 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'borders.dart'; +import 'circle_border.dart'; + +/// A border that fits an elliptical shape. +/// +/// Typically used with [ShapeDecoration] to draw an oval. Instead of centering +/// the [Border] to a square, like [CircleBorder], it fills the available space, +/// such that it touches the edges of the box. There is no difference between +/// `CircleBorder(eccentricity = 1.0)` and `OvalBorder()`. [OvalBorder] works as +/// an alias for users to discover this feature. +/// +/// See also: +/// +/// * [CircleBorder], which draws a circle, centering when the box is rectangular. +/// * [Border], which, when used with [BoxDecoration], can also describe an oval. +class OvalBorder extends CircleBorder { + /// Create an oval border. + const OvalBorder({ super.side, super.eccentricity = 1.0 }); + + @override + ShapeBorder scale(double t) => OvalBorder(side: side.scale(t), eccentricity: eccentricity); + + @override + OvalBorder copyWith({ BorderSide? side, double? eccentricity }) { + return OvalBorder(side: side ?? this.side, eccentricity: eccentricity ?? this.eccentricity); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is OvalBorder) { + return OvalBorder( + side: BorderSide.lerp(a.side, side, t), + eccentricity: clampDouble(ui.lerpDouble(a.eccentricity, eccentricity, t)!, 0.0, 1.0), + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is OvalBorder) { + return OvalBorder( + side: BorderSide.lerp(side, b.side, t), + eccentricity: clampDouble(ui.lerpDouble(eccentricity, b.eccentricity, t)!, 0.0, 1.0), + ); + } + return super.lerpTo(b, t); + } + + @override + String toString() { + if (eccentricity != 1.0) { + return '${objectRuntimeType(this, 'OvalBorder')}($side, eccentricity: $eccentricity)'; + } + return '${objectRuntimeType(this, 'OvalBorder')}($side)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/paint_utilities.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/paint_utilities.dart new file mode 100644 index 0000000000000000000000000000000000000000..54629b95d557927d681d52739187d8d88036c8c9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/paint_utilities.dart @@ -0,0 +1,42 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'basic_types.dart'; + +/// Draw a line between two points, which cuts diagonally back and forth across +/// the line that connects the two points. +/// +/// The line will cross the line `zigs - 1` times. +/// +/// If `zigs` is 1, then this will draw two sides of a triangle from `start` to +/// `end`, with the third point being `width` away from the line, as measured +/// perpendicular to that line. +/// +/// If `width` is positive, the first `zig` will be to the left of the `start` +/// point when facing the `end` point. To reverse the zigging polarity, provide +/// a negative `width`. +/// +/// The line is drawn using the provided `paint` on the provided `canvas`. +void paintZigZag(Canvas canvas, Paint paint, Offset start, Offset end, int zigs, double width) { + assert(zigs.isFinite); + assert(zigs > 0); + canvas.save(); + canvas.translate(start.dx, start.dy); + end = end - start; + canvas.rotate(math.atan2(end.dy, end.dx)); + final double length = end.distance; + final double spacing = length / (zigs * 2.0); + final Path path = Path() + ..moveTo(0.0, 0.0); + for (int index = 0; index < zigs; index += 1) { + final double x = (index * 2.0 + 1.0) * spacing; + final double y = width * ((index % 2.0) * 2.0 - 1.0); + path.lineTo(x, y); + } + path.lineTo(length, 0.0); + canvas.drawPath(path, paint); + canvas.restore(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/placeholder_span.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/placeholder_span.dart new file mode 100644 index 0000000000000000000000000000000000000000..1235fb92a80d2e2225fe4b510beba3511b840dca --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/placeholder_span.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show PlaceholderAlignment; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'inline_span.dart'; +import 'text_painter.dart'; +import 'text_span.dart'; +import 'text_style.dart'; + +/// An immutable placeholder that is embedded inline within text. +/// +/// [PlaceholderSpan] represents a placeholder that acts as a stand-in for other +/// content. A [PlaceholderSpan] by itself does not contain useful information +/// to change a [TextSpan]. [WidgetSpan] from the widgets library extends +/// [PlaceholderSpan] and may be used instead to specify a widget as the contents +/// of the placeholder. +/// +/// Flutter widgets such as [TextField], [Text] and [RichText] do not recognize +/// [PlaceholderSpan] subclasses other than [WidgetSpan]. **Consider +/// implementing the [WidgetSpan] interface instead of the [Placeholder] +/// interface.** +/// +/// +/// See also: +/// +/// * [WidgetSpan], a leaf node that represents an embedded inline widget. +/// * [TextSpan], a node that represents text in a [TextSpan] tree. +/// * [Text], a widget for showing uniformly-styled text. +/// * [RichText], a widget for finer control of text rendering. +/// * [TextPainter], a class for painting [TextSpan] objects on a [Canvas]. +abstract class PlaceholderSpan extends InlineSpan { + /// Creates a [PlaceholderSpan] with the given values. + /// + /// A [TextStyle] may be provided with the [style] property, but only the + /// decoration, foreground, background, and spacing options will be used. + const PlaceholderSpan({ + this.alignment = ui.PlaceholderAlignment.bottom, + this.baseline, + super.style, + }); + + /// The unicode character to represent a placeholder. + static const int placeholderCodeUnit = 0xFFFC; + + /// How the placeholder aligns vertically with the text. + /// + /// See [ui.PlaceholderAlignment] for details on each mode. + final ui.PlaceholderAlignment alignment; + + /// The [TextBaseline] to align against when using [ui.PlaceholderAlignment.baseline], + /// [ui.PlaceholderAlignment.aboveBaseline], and [ui.PlaceholderAlignment.belowBaseline]. + /// + /// This is ignored when using other alignment modes. + final TextBaseline? baseline; + + /// [PlaceholderSpan]s are flattened to a `0xFFFC` object replacement character in the + /// plain text representation when `includePlaceholders` is true. + @override + void computeToPlainText(StringBuffer buffer, {bool includeSemanticsLabels = true, bool includePlaceholders = true}) { + if (includePlaceholders) { + buffer.writeCharCode(placeholderCodeUnit); + } + } + + @override + void computeSemanticsInformation(List<InlineSpanSemanticsInformation> collector) { + collector.add(InlineSpanSemanticsInformation.placeholder); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + + properties.add(EnumProperty<ui.PlaceholderAlignment>('alignment', alignment, defaultValue: null)); + properties.add(EnumProperty<TextBaseline>('baseline', baseline, defaultValue: null)); + } + + @override + bool debugAssertIsValid() { + assert(false, 'Consider implementing the WidgetSpan interface instead.'); + return super.debugAssertIsValid(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/rounded_rectangle_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/rounded_rectangle_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..27109396c2a0c07f30544ac71a09c539dd9b81ec --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/rounded_rectangle_border.dart @@ -0,0 +1,354 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'border_radius.dart'; +import 'borders.dart'; +import 'circle_border.dart'; + +/// A rectangular border with rounded corners. +/// +/// Typically used with [ShapeDecoration] to draw a box with a rounded +/// rectangle. +/// +/// This shape can interpolate to and from [CircleBorder]. +/// +/// See also: +/// +/// * [BorderSide], which is used to describe each side of the box. +/// * [Border], which, when used with [BoxDecoration], can also +/// describe a rounded rectangle. +class RoundedRectangleBorder extends OutlinedBorder { + /// Creates a rounded rectangle border. + const RoundedRectangleBorder({ + super.side, + this.borderRadius = BorderRadius.zero, + }); + + /// The radii for each corner. + final BorderRadiusGeometry borderRadius; + + @override + ShapeBorder scale(double t) { + return RoundedRectangleBorder( + side: side.scale(t), + borderRadius: borderRadius * t, + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is RoundedRectangleBorder) { + return RoundedRectangleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!, + ); + } + if (a is CircleBorder) { + return _RoundedRectangleToCircleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: borderRadius, + circularity: 1.0 - t, + eccentricity: a.eccentricity, + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is RoundedRectangleBorder) { + return RoundedRectangleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t)!, + ); + } + if (b is CircleBorder) { + return _RoundedRectangleToCircleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: borderRadius, + circularity: t, + eccentricity: b.eccentricity, + ); + } + return super.lerpTo(b, t); + } + + /// Returns a copy of this RoundedRectangleBorder with the given fields + /// replaced with the new values. + @override + RoundedRectangleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius }) { + return RoundedRectangleBorder( + side: side ?? this.side, + borderRadius: borderRadius ?? this.borderRadius, + ); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + final RRect borderRect = borderRadius.resolve(textDirection).toRRect(rect); + final RRect adjustedRect = borderRect.deflate(side.strokeInset); + return Path() + ..addRRect(adjustedRect); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path() + ..addRRect(borderRadius.resolve(textDirection).toRRect(rect)); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + if (borderRadius == BorderRadius.zero) { + canvas.drawRect(rect, paint); + } else { + canvas.drawRRect(borderRadius.resolve(textDirection).toRRect(rect), paint); + } + } + + @override + bool get preferPaintInterior => true; + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + switch (side.style) { + case BorderStyle.none: + break; + case BorderStyle.solid: + if (side.width == 0.0) { + canvas.drawRRect(borderRadius.resolve(textDirection).toRRect(rect), side.toPaint()); + } else { + final Paint paint = Paint() + ..color = side.color; + final RRect borderRect = borderRadius.resolve(textDirection).toRRect(rect); + final RRect inner = borderRect.deflate(side.strokeInset); + final RRect outer = borderRect.inflate(side.strokeOutset); + canvas.drawDRRect(outer, inner, paint); + } + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is RoundedRectangleBorder + && other.side == side + && other.borderRadius == borderRadius; + } + + @override + int get hashCode => Object.hash(side, borderRadius); + + @override + String toString() { + return '${objectRuntimeType(this, 'RoundedRectangleBorder')}($side, $borderRadius)'; + } +} + +class _RoundedRectangleToCircleBorder extends OutlinedBorder { + const _RoundedRectangleToCircleBorder({ + super.side, + this.borderRadius = BorderRadius.zero, + required this.circularity, + required this.eccentricity, + }); + + final BorderRadiusGeometry borderRadius; + final double circularity; + final double eccentricity; + + @override + ShapeBorder scale(double t) { + return _RoundedRectangleToCircleBorder( + side: side.scale(t), + borderRadius: borderRadius * t, + circularity: t, + eccentricity: eccentricity, + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is RoundedRectangleBorder) { + return _RoundedRectangleToCircleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!, + circularity: circularity * t, + eccentricity: eccentricity, + ); + } + if (a is CircleBorder) { + return _RoundedRectangleToCircleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: borderRadius, + circularity: circularity + (1.0 - circularity) * (1.0 - t), + eccentricity: a.eccentricity, + ); + } + if (a is _RoundedRectangleToCircleBorder) { + return _RoundedRectangleToCircleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!, + circularity: ui.lerpDouble(a.circularity, circularity, t)!, + eccentricity: eccentricity, + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is RoundedRectangleBorder) { + return _RoundedRectangleToCircleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t)!, + circularity: circularity * (1.0 - t), + eccentricity: eccentricity, + ); + } + if (b is CircleBorder) { + return _RoundedRectangleToCircleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: borderRadius, + circularity: circularity + (1.0 - circularity) * t, + eccentricity: b.eccentricity, + ); + } + if (b is _RoundedRectangleToCircleBorder) { + return _RoundedRectangleToCircleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t)!, + circularity: ui.lerpDouble(circularity, b.circularity, t)!, + eccentricity: eccentricity, + ); + } + return super.lerpTo(b, t); + } + + Rect _adjustRect(Rect rect) { + if (circularity == 0.0 || rect.width == rect.height) { + return rect; + } + if (rect.width < rect.height) { + final double partialDelta = (rect.height - rect.width) / 2; + final double delta = circularity * partialDelta * (1.0 - eccentricity); + return Rect.fromLTRB( + rect.left, + rect.top + delta, + rect.right, + rect.bottom - delta, + ); + } else { + final double partialDelta = (rect.width - rect.height) / 2; + final double delta = circularity * partialDelta * (1.0 - eccentricity); + return Rect.fromLTRB( + rect.left + delta, + rect.top, + rect.right - delta, + rect.bottom, + ); + } + } + + BorderRadius? _adjustBorderRadius(Rect rect, TextDirection? textDirection) { + final BorderRadius resolvedRadius = borderRadius.resolve(textDirection); + if (circularity == 0.0) { + return resolvedRadius; + } + if (eccentricity != 0.0) { + if (rect.width < rect.height) { + return BorderRadius.lerp( + resolvedRadius, + BorderRadius.all(Radius.elliptical(rect.width / 2, (0.5 + eccentricity / 2) * rect.height / 2)), + circularity, + )!; + } else { + return BorderRadius.lerp( + resolvedRadius, + BorderRadius.all(Radius.elliptical((0.5 + eccentricity / 2) * rect.width / 2, rect.height / 2)), + circularity, + )!; + } + } + return BorderRadius.lerp(resolvedRadius, BorderRadius.circular(rect.shortestSide / 2), circularity); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + final RRect borderRect = _adjustBorderRadius(rect, textDirection)!.toRRect(_adjustRect(rect)); + final RRect adjustedRect = borderRect.deflate(ui.lerpDouble(side.width, 0, side.strokeAlign)!); + return Path() + ..addRRect(adjustedRect); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path() + ..addRRect(_adjustBorderRadius(rect, textDirection)!.toRRect(_adjustRect(rect))); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + final BorderRadius adjustedBorderRadius = _adjustBorderRadius(rect, textDirection)!; + if (adjustedBorderRadius == BorderRadius.zero) { + canvas.drawRect(_adjustRect(rect), paint); + } else { + canvas.drawRRect(adjustedBorderRadius.toRRect(_adjustRect(rect)), paint); + } + } + + @override + bool get preferPaintInterior => true; + + @override + _RoundedRectangleToCircleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius, double? circularity, double? eccentricity }) { + return _RoundedRectangleToCircleBorder( + side: side ?? this.side, + borderRadius: borderRadius ?? this.borderRadius, + circularity: circularity ?? this.circularity, + eccentricity: eccentricity ?? this.eccentricity, + ); + } + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + switch (side.style) { + case BorderStyle.none: + break; + case BorderStyle.solid: + final BorderRadius adjustedBorderRadius = _adjustBorderRadius(rect, textDirection)!; + final RRect borderRect = adjustedBorderRadius.toRRect(_adjustRect(rect)); + canvas.drawRRect(borderRect.inflate(side.strokeOffset / 2), side.toPaint()); + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _RoundedRectangleToCircleBorder + && other.side == side + && other.borderRadius == borderRadius + && other.circularity == circularity; + } + + @override + int get hashCode => Object.hash(side, borderRadius, circularity); + + @override + String toString() { + if (eccentricity != 0.0) { + return 'RoundedRectangleBorder($side, $borderRadius, ${(circularity * 100).toStringAsFixed(1)}% of the way to being a CircleBorder that is ${(eccentricity * 100).toStringAsFixed(1)}% oval)'; + } + return 'RoundedRectangleBorder($side, $borderRadius, ${(circularity * 100).toStringAsFixed(1)}% of the way to being a CircleBorder)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/shader_warm_up.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/shader_warm_up.dart new file mode 100644 index 0000000000000000000000000000000000000000..48a5bf0edfdfcbe3bf0975479d3ea0116f967556 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/shader_warm_up.dart @@ -0,0 +1,107 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:developer'; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; + +import 'debug.dart'; + +/// Interface for drawing an image to warm up Skia shader compilations. +/// +/// When Skia first sees a certain type of draw operation on the GPU, it needs +/// to compile the corresponding shader. The compilation can be slow (20ms- +/// 200ms). Having that time as startup latency is often better than having +/// jank in the middle of an animation. +/// +/// Therefore, we use this during the [PaintingBinding.initInstances] call to +/// move common shader compilations from animation time to startup time. If +/// needed, app developers can create a custom [ShaderWarmUp] subclass and +/// hand it to [PaintingBinding.shaderWarmUp] before +/// [PaintingBinding.initInstances] is called. Usually, that can be done before +/// calling [runApp]. +/// +/// To determine whether a draw operation is useful for warming up shaders, +/// check whether it improves the slowest frame rasterization time. Also, +/// tracing with `flutter run --profile --trace-skia` may reveal whether there +/// is shader-compilation-related jank. If there is such jank, some long +/// `GrGLProgramBuilder::finalize` calls would appear in the middle of an +/// animation. Their parent calls, which look like `XyzOp` (e.g., `FillRecOp`, +/// `CircularRRectOp`) would suggest Xyz draw operations are causing the shaders +/// to be compiled. A useful shader warm-up draw operation would eliminate such +/// long compilation calls in the animation. To double-check the warm-up, trace +/// with `flutter run --profile --trace-skia --start-paused`. The +/// `GrGLProgramBuilder` with the associated `XyzOp` should appear during +/// startup rather than in the middle of a later animation. +/// +/// This warm-up needs to be run on each individual device because the shader +/// compilation depends on the specific GPU hardware and driver a device has. It +/// can't be pre-computed during the Flutter engine compilation as the engine is +/// device-agnostic. +/// +/// If no warm-up is desired (e.g., when the startup latency is crucial), set +/// [PaintingBinding.shaderWarmUp] either to a custom ShaderWarmUp with an empty +/// [warmUpOnCanvas] or null. +/// +/// See also: +/// +/// * [PaintingBinding.shaderWarmUp], the actual instance of [ShaderWarmUp] +/// that's used to warm up the shaders. +/// * <https://flutter.dev/docs/perf/rendering/shader> +abstract class ShaderWarmUp { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const ShaderWarmUp(); + + /// The size of the warm up image. + /// + /// The exact size shouldn't matter much as long as all draws are onscreen. + /// 100x100 is an arbitrary small size that's easy to fit significant draw + /// calls onto. + /// + /// A custom shader warm up can override this based on targeted devices. + ui.Size get size => const ui.Size(100.0, 100.0); + + /// Trigger draw operations on a given canvas to warm up GPU shader + /// compilation cache. + /// + /// To decide which draw operations to be added to your custom warm up + /// process, consider capturing an skp using `flutter screenshot + /// --vm-service-uri=<uri> --type=skia` and analyzing it with + /// <https://debugger.skia.org/>. Alternatively, one may run the app with + /// `flutter run --trace-skia` and then examine the raster thread in the + /// Flutter DevTools timeline to see which Skia draw operations are commonly used, + /// and which shader compilations are causing jank. + @protected + Future<void> warmUpOnCanvas(ui.Canvas canvas); + + /// Construct an offscreen image of [size], and execute [warmUpOnCanvas] on a + /// canvas associated with that image. + /// + /// Currently, this has no effect when [kIsWeb] is true. + Future<void> execute() async { + final ui.PictureRecorder recorder = ui.PictureRecorder(); + final ui.Canvas canvas = ui.Canvas(recorder); + await warmUpOnCanvas(canvas); + final ui.Picture picture = recorder.endRecording(); + assert(debugCaptureShaderWarmUpPicture(picture)); + if (!kIsWeb || isCanvasKit) { // Picture.toImage is not yet implemented on the web. + TimelineTask? debugShaderWarmUpTask; + if (!kReleaseMode) { + debugShaderWarmUpTask = TimelineTask()..start('Warm-up shader'); + } + try { + final ui.Image image = await picture.toImage(size.width.ceil(), size.height.ceil()); + assert(debugCaptureShaderWarmUpImage(image)); + image.dispose(); + } finally { + if (!kReleaseMode) { + debugShaderWarmUpTask!.finish(); + } + } + } + picture.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/shape_decoration.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/shape_decoration.dart new file mode 100644 index 0000000000000000000000000000000000000000..fbe3c60ad5c3dd0fa456d87fcccc06af989aa2e2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/shape_decoration.dart @@ -0,0 +1,411 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'borders.dart'; +import 'box_border.dart'; +import 'box_decoration.dart'; +import 'box_shadow.dart'; +import 'circle_border.dart'; +import 'colors.dart'; +import 'decoration.dart'; +import 'decoration_image.dart'; +import 'edge_insets.dart'; +import 'gradient.dart'; +import 'image_provider.dart'; +import 'rounded_rectangle_border.dart'; + +/// An immutable description of how to paint an arbitrary shape. +/// +/// The [ShapeDecoration] class provides a way to draw a [ShapeBorder], +/// optionally filling it with a color or a gradient, optionally painting an +/// image into it, and optionally casting a shadow. +/// +/// {@tool snippet} +/// +/// The following example uses the [Container] widget from the widgets layer to +/// draw a white rectangle with a 24-pixel multicolor outline, with the text +/// "RGB" inside it: +/// +/// ```dart +/// Container( +/// decoration: ShapeDecoration( +/// color: Colors.white, +/// shape: Border.all( +/// color: Colors.red, +/// width: 8.0, +/// ) + Border.all( +/// color: Colors.green, +/// width: 8.0, +/// ) + Border.all( +/// color: Colors.blue, +/// width: 8.0, +/// ), +/// ), +/// child: const Text('RGB', textAlign: TextAlign.center), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [DecoratedBox] and [Container], widgets that can be configured with +/// [ShapeDecoration] objects. +/// * [BoxDecoration], a similar [Decoration] that is optimized for rectangles +/// specifically. +/// * [ShapeBorder], the base class for the objects that are used in the +/// [shape] property. +class ShapeDecoration extends Decoration { + /// Creates a shape decoration. + /// + /// * If [color] is null, this decoration does not paint a background color. + /// * If [gradient] is null, this decoration does not paint gradients. + /// * If [image] is null, this decoration does not paint a background image. + /// * If [shadows] is null, this decoration does not paint a shadow. + /// + /// The [color] and [gradient] properties are mutually exclusive, one (or + /// both) of them must be null. + const ShapeDecoration({ + this.color, + this.image, + this.gradient, + this.shadows, + required this.shape, + }) : assert(!(color != null && gradient != null)); + + /// Creates a shape decoration configured to match a [BoxDecoration]. + /// + /// The [BoxDecoration] class is more efficient for shapes that it can + /// describe than the [ShapeDecoration] class is for those same shapes, + /// because [ShapeDecoration] has to be more general as it can support any + /// shape. However, having a [ShapeDecoration] is sometimes necessary, for + /// example when calling [ShapeDecoration.lerp] to transition between + /// different shapes (e.g. from a [CircleBorder] to a + /// [RoundedRectangleBorder]; the [BoxDecoration] class cannot animate the + /// transition from a [BoxShape.circle] to [BoxShape.rectangle]). + factory ShapeDecoration.fromBoxDecoration(BoxDecoration source) { + final ShapeBorder shape; + switch (source.shape) { + case BoxShape.circle: + if (source.border != null) { + assert(source.border!.isUniform); + shape = CircleBorder(side: source.border!.top); + } else { + shape = const CircleBorder(); + } + case BoxShape.rectangle: + if (source.borderRadius != null) { + assert(source.border == null || source.border!.isUniform); + shape = RoundedRectangleBorder( + side: source.border?.top ?? BorderSide.none, + borderRadius: source.borderRadius!, + ); + } else { + shape = source.border ?? const Border(); + } + } + return ShapeDecoration( + color: source.color, + image: source.image, + gradient: source.gradient, + shadows: source.boxShadow, + shape: shape, + ); + } + + @override + Path getClipPath(Rect rect, TextDirection textDirection) { + return shape.getOuterPath(rect, textDirection: textDirection); + } + + /// The color to fill in the background of the shape. + /// + /// The color is under the [image]. + /// + /// If a [gradient] is specified, [color] must be null. + final Color? color; + + /// A gradient to use when filling the shape. + /// + /// The gradient is under the [image]. + /// + /// If a [color] is specified, [gradient] must be null. + final Gradient? gradient; + + /// An image to paint inside the shape (clipped to its outline). + /// + /// The image is drawn over the [color] or [gradient]. + final DecorationImage? image; + + /// A list of shadows cast by the [shape]. + /// + /// See also: + /// + /// * [kElevationToShadow], for some predefined shadows used in Material + /// Design. + /// * [PhysicalModel], a widget for showing shadows. + final List<BoxShadow>? shadows; + + /// The shape to fill the [color], [gradient], and [image] into and to cast as + /// the [shadows]. + /// + /// Shapes can be stacked (using the `+` operator). The color, gradient, and + /// image are drawn into the inner-most shape specified. + /// + /// The [shape] property specifies the outline (border) of the decoration. + /// + /// ## Directionality-dependent shapes + /// + /// Some [ShapeBorder] subclasses are sensitive to the [TextDirection]. The + /// direction that is provided to the border (e.g. for its [ShapeBorder.paint] + /// method) is the one specified in the [ImageConfiguration] + /// ([ImageConfiguration.textDirection]) provided to the [BoxPainter] (via its + /// [BoxPainter.paint method). The [BoxPainter] is obtained when + /// [createBoxPainter] is called. + /// + /// When a [ShapeDecoration] is used with a [Container] widget or a + /// [DecoratedBox] widget (which is what [Container] uses), the + /// [TextDirection] specified in the [ImageConfiguration] is obtained from the + /// ambient [Directionality], using [createLocalImageConfiguration]. + final ShapeBorder shape; + + /// The inset space occupied by the [shape]'s border. + /// + /// This value may be misleading. See the discussion at [ShapeBorder.dimensions]. + @override + EdgeInsetsGeometry get padding => shape.dimensions; + + @override + bool get isComplex => shadows != null; + + @override + ShapeDecoration? lerpFrom(Decoration? a, double t) { + if (a is BoxDecoration) { + return ShapeDecoration.lerp(ShapeDecoration.fromBoxDecoration(a), this, t); + } else if (a == null || a is ShapeDecoration) { + return ShapeDecoration.lerp(a as ShapeDecoration?, this, t); + } + return super.lerpFrom(a, t) as ShapeDecoration?; + } + + @override + ShapeDecoration? lerpTo(Decoration? b, double t) { + if (b is BoxDecoration) { + return ShapeDecoration.lerp(this, ShapeDecoration.fromBoxDecoration(b), t); + } else if (b == null || b is ShapeDecoration) { + return ShapeDecoration.lerp(this, b as ShapeDecoration?, t); + } + return super.lerpTo(b, t) as ShapeDecoration?; + } + + /// Linearly interpolate between two shapes. + /// + /// Interpolates each parameter of the decoration separately. + /// + /// If both values are null, this returns null. Otherwise, it returns a + /// non-null value, with null arguments treated like a [ShapeDecoration] whose + /// fields are all null (including the [shape], which cannot normally be + /// null). + /// + /// {@macro dart.ui.shadow.lerp} + /// + /// See also: + /// + /// * [Decoration.lerp], which can interpolate between any two types of + /// [Decoration]s, not just [ShapeDecoration]s. + /// * [lerpFrom] and [lerpTo], which are used to implement [Decoration.lerp] + /// and which use [ShapeDecoration.lerp] when interpolating two + /// [ShapeDecoration]s or a [ShapeDecoration] to or from null. + static ShapeDecoration? lerp(ShapeDecoration? a, ShapeDecoration? b, double t) { + if (identical(a, b)) { + return a; + } + if (a != null && b != null) { + if (t == 0.0) { + return a; + } + if (t == 1.0) { + return b; + } + } + return ShapeDecoration( + color: Color.lerp(a?.color, b?.color, t), + gradient: Gradient.lerp(a?.gradient, b?.gradient, t), + image: DecorationImage.lerp(a?.image, b?.image, t), + shadows: BoxShadow.lerpList(a?.shadows, b?.shadows, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t)!, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ShapeDecoration + && other.color == color + && other.gradient == gradient + && other.image == image + && listEquals<BoxShadow>(other.shadows, shadows) + && other.shape == shape; + } + + @override + int get hashCode => Object.hash( + color, + gradient, + image, + shape, + shadows == null ? null : Object.hashAll(shadows!), + ); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.defaultDiagnosticsTreeStyle = DiagnosticsTreeStyle.whitespace; + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(DiagnosticsProperty<Gradient>('gradient', gradient, defaultValue: null)); + properties.add(DiagnosticsProperty<DecorationImage>('image', image, defaultValue: null)); + properties.add(IterableProperty<BoxShadow>('shadows', shadows, defaultValue: null, style: DiagnosticsTreeStyle.whitespace)); + properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape)); + } + + @override + bool hitTest(Size size, Offset position, { TextDirection? textDirection }) { + return shape.getOuterPath(Offset.zero & size, textDirection: textDirection).contains(position); + } + + @override + BoxPainter createBoxPainter([ VoidCallback? onChanged ]) { + assert(onChanged != null || image == null); + return _ShapeDecorationPainter(this, onChanged!); + } +} + +/// An object that paints a [ShapeDecoration] into a canvas. +class _ShapeDecorationPainter extends BoxPainter { + _ShapeDecorationPainter(this._decoration, VoidCallback onChanged) + : super(onChanged); + + final ShapeDecoration _decoration; + + Rect? _lastRect; + TextDirection? _lastTextDirection; + late Path _outerPath; + Path? _innerPath; + Paint? _interiorPaint; + int? _shadowCount; + late List<Rect> _shadowBounds; + late List<Path> _shadowPaths; + late List<Paint> _shadowPaints; + + @override + VoidCallback get onChanged => super.onChanged!; + + void _precache(Rect rect, TextDirection? textDirection) { + if (rect == _lastRect && textDirection == _lastTextDirection) { + return; + } + + // We reach here in two cases: + // - the very first time we paint, in which case everything except _decoration is null + // - subsequent times, if the rect has changed, in which case we only need to update + // the features that depend on the actual rect. + if (_interiorPaint == null && (_decoration.color != null || _decoration.gradient != null)) { + _interiorPaint = Paint(); + if (_decoration.color != null) { + _interiorPaint!.color = _decoration.color!; + } + } + if (_decoration.gradient != null) { + _interiorPaint!.shader = _decoration.gradient!.createShader(rect, textDirection: textDirection); + } + if (_decoration.shadows != null) { + if (_shadowCount == null) { + _shadowCount = _decoration.shadows!.length; + _shadowPaints = <Paint>[ + ..._decoration.shadows!.map((BoxShadow shadow) => shadow.toPaint()), + ]; + } + if (_decoration.shape.preferPaintInterior) { + _shadowBounds = <Rect>[ + ..._decoration.shadows!.map((BoxShadow shadow) { + return rect.shift(shadow.offset).inflate(shadow.spreadRadius); + }), + ]; + } else { + _shadowPaths = <Path>[ + ..._decoration.shadows!.map((BoxShadow shadow) { + return _decoration.shape.getOuterPath(rect.shift(shadow.offset).inflate(shadow.spreadRadius), textDirection: textDirection); + }), + ]; + } + } + if (!_decoration.shape.preferPaintInterior && (_interiorPaint != null || _shadowCount != null)) { + _outerPath = _decoration.shape.getOuterPath(rect, textDirection: textDirection); + } + if (_decoration.image != null) { + _innerPath = _decoration.shape.getInnerPath(rect, textDirection: textDirection); + } + + _lastRect = rect; + _lastTextDirection = textDirection; + } + + void _paintShadows(Canvas canvas, Rect rect, TextDirection? textDirection) { + if (_shadowCount != null) { + if (_decoration.shape.preferPaintInterior) { + for (int index = 0; index < _shadowCount!; index += 1) { + _decoration.shape.paintInterior(canvas, _shadowBounds[index], _shadowPaints[index], textDirection: textDirection); + } + } else { + for (int index = 0; index < _shadowCount!; index += 1) { + canvas.drawPath(_shadowPaths[index], _shadowPaints[index]); + } + } + } + } + + void _paintInterior(Canvas canvas, Rect rect, TextDirection? textDirection) { + if (_interiorPaint != null) { + if (_decoration.shape.preferPaintInterior) { + _decoration.shape.paintInterior(canvas, rect, _interiorPaint!, textDirection: textDirection); + } else { + canvas.drawPath(_outerPath, _interiorPaint!); + } + } + } + + DecorationImagePainter? _imagePainter; + void _paintImage(Canvas canvas, ImageConfiguration configuration) { + if (_decoration.image == null) { + return; + } + _imagePainter ??= _decoration.image!.createPainter(onChanged); + _imagePainter!.paint(canvas, _lastRect!, _innerPath, configuration); + } + + @override + void dispose() { + _imagePainter?.dispose(); + super.dispose(); + } + + @override + void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { + assert(configuration.size != null); + final Rect rect = offset & configuration.size!; + final TextDirection? textDirection = configuration.textDirection; + _precache(rect, textDirection); + _paintShadows(canvas, rect, textDirection); + _paintInterior(canvas, rect, textDirection); + _paintImage(canvas, configuration); + _decoration.shape.paint(canvas, rect, textDirection: textDirection); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/stadium_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/stadium_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..e9e57dfcda24e6b0dcf4afc7919d7e99f24728bb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/stadium_border.dart @@ -0,0 +1,465 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'border_radius.dart'; +import 'borders.dart'; +import 'circle_border.dart'; +import 'rounded_rectangle_border.dart'; + +/// A border that fits a stadium-shaped border (a box with semicircles on the ends) +/// within the rectangle of the widget it is applied to. +/// +/// Typically used with [ShapeDecoration] to draw a stadium border. +/// +/// If the rectangle is taller than it is wide, then the semicircles will be on the +/// top and bottom, and on the left and right otherwise. +/// +/// See also: +/// +/// * [BorderSide], which is used to describe the border of the stadium. +class StadiumBorder extends OutlinedBorder { + /// Create a stadium border. + const StadiumBorder({ super.side }); + + @override + ShapeBorder scale(double t) => StadiumBorder(side: side.scale(t)); + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is StadiumBorder) { + return StadiumBorder(side: BorderSide.lerp(a.side, side, t)); + } + if (a is CircleBorder) { + return _StadiumToCircleBorder( + side: BorderSide.lerp(a.side, side, t), + circularity: 1.0 - t, + eccentricity: a.eccentricity, + ); + } + if (a is RoundedRectangleBorder) { + return _StadiumToRoundedRectangleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: a.borderRadius, + rectilinearity: 1.0 - t, + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is StadiumBorder) { + return StadiumBorder(side: BorderSide.lerp(side, b.side, t)); + } + if (b is CircleBorder) { + return _StadiumToCircleBorder( + side: BorderSide.lerp(side, b.side, t), + circularity: t, + eccentricity: b.eccentricity, + ); + } + if (b is RoundedRectangleBorder) { + return _StadiumToRoundedRectangleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: b.borderRadius, + rectilinearity: t, + ); + } + return super.lerpTo(b, t); + } + + @override + StadiumBorder copyWith({ BorderSide? side }) { + return StadiumBorder(side: side ?? this.side); + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + final Radius radius = Radius.circular(rect.shortestSide / 2.0); + final RRect borderRect = RRect.fromRectAndRadius(rect, radius); + final RRect adjustedRect = borderRect.deflate(side.strokeInset); + return Path() + ..addRRect(adjustedRect); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + final Radius radius = Radius.circular(rect.shortestSide / 2.0); + return Path() + ..addRRect(RRect.fromRectAndRadius(rect, radius)); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + final Radius radius = Radius.circular(rect.shortestSide / 2.0); + canvas.drawRRect(RRect.fromRectAndRadius(rect, radius), paint); + } + + @override + bool get preferPaintInterior => true; + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + switch (side.style) { + case BorderStyle.none: + break; + case BorderStyle.solid: + final Radius radius = Radius.circular(rect.shortestSide / 2); + final RRect borderRect = RRect.fromRectAndRadius(rect, radius); + canvas.drawRRect(borderRect.inflate(side.strokeOffset / 2), side.toPaint()); + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is StadiumBorder + && other.side == side; + } + + @override + int get hashCode => side.hashCode; + + @override + String toString() { + return '${objectRuntimeType(this, 'StadiumBorder')}($side)'; + } +} + +// Class to help with transitioning to/from a CircleBorder. +class _StadiumToCircleBorder extends OutlinedBorder { + const _StadiumToCircleBorder({ + super.side, + this.circularity = 0.0, + required this.eccentricity, + }); + + final double circularity; + final double eccentricity; + + @override + ShapeBorder scale(double t) { + return _StadiumToCircleBorder( + side: side.scale(t), + circularity: t, + eccentricity: eccentricity, + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is StadiumBorder) { + return _StadiumToCircleBorder( + side: BorderSide.lerp(a.side, side, t), + circularity: circularity * t, + eccentricity: eccentricity, + ); + } + if (a is CircleBorder) { + return _StadiumToCircleBorder( + side: BorderSide.lerp(a.side, side, t), + circularity: circularity + (1.0 - circularity) * (1.0 - t), + eccentricity: a.eccentricity, + ); + } + if (a is _StadiumToCircleBorder) { + return _StadiumToCircleBorder( + side: BorderSide.lerp(a.side, side, t), + circularity: ui.lerpDouble(a.circularity, circularity, t)!, + eccentricity: ui.lerpDouble(a.eccentricity, eccentricity, t)!, + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is StadiumBorder) { + return _StadiumToCircleBorder( + side: BorderSide.lerp(side, b.side, t), + circularity: circularity * (1.0 - t), + eccentricity: eccentricity, + ); + } + if (b is CircleBorder) { + return _StadiumToCircleBorder( + side: BorderSide.lerp(side, b.side, t), + circularity: circularity + (1.0 - circularity) * t, + eccentricity: b.eccentricity, + ); + } + if (b is _StadiumToCircleBorder) { + return _StadiumToCircleBorder( + side: BorderSide.lerp(side, b.side, t), + circularity: ui.lerpDouble(circularity, b.circularity, t)!, + eccentricity: ui.lerpDouble(eccentricity, b.eccentricity, t)!, + ); + } + return super.lerpTo(b, t); + } + + Rect _adjustRect(Rect rect) { + if (circularity == 0.0 || rect.width == rect.height) { + return rect; + } + if (rect.width < rect.height) { + final double partialDelta = (rect.height - rect.width) / 2; + final double delta = circularity * partialDelta * (1.0 - eccentricity); + return Rect.fromLTRB( + rect.left, + rect.top + delta, + rect.right, + rect.bottom - delta, + ); + } else { + final double partialDelta = (rect.width - rect.height) / 2; + final double delta = circularity * partialDelta * (1.0 - eccentricity); + return Rect.fromLTRB( + rect.left + delta, + rect.top, + rect.right - delta, + rect.bottom, + ); + } + } + + BorderRadius _adjustBorderRadius(Rect rect) { + final BorderRadius circleRadius = BorderRadius.circular(rect.shortestSide / 2); + if (eccentricity != 0.0) { + if (rect.width < rect.height) { + return BorderRadius.lerp( + circleRadius, + BorderRadius.all(Radius.elliptical(rect.width / 2, (0.5 + eccentricity / 2) * rect.height / 2)), + circularity, + )!; + } else { + return BorderRadius.lerp( + circleRadius, + BorderRadius.all(Radius.elliptical((0.5 + eccentricity / 2) * rect.width / 2, rect.height / 2)), + circularity, + )!; + } + } + return circleRadius; + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + return Path() + ..addRRect(_adjustBorderRadius(rect).toRRect(_adjustRect(rect)).deflate(side.strokeInset)); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path() + ..addRRect(_adjustBorderRadius(rect).toRRect(_adjustRect(rect))); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + canvas.drawRRect(_adjustBorderRadius(rect).toRRect(_adjustRect(rect)), paint); + } + + @override + bool get preferPaintInterior => true; + + @override + _StadiumToCircleBorder copyWith({ BorderSide? side, double? circularity, double? eccentricity }) { + return _StadiumToCircleBorder( + side: side ?? this.side, + circularity: circularity ?? this.circularity, + eccentricity: eccentricity ?? this.eccentricity, + ); + } + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + switch (side.style) { + case BorderStyle.none: + break; + case BorderStyle.solid: + final RRect borderRect = _adjustBorderRadius(rect).toRRect(_adjustRect(rect)); + canvas.drawRRect(borderRect.inflate(side.strokeOffset / 2), side.toPaint()); + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _StadiumToCircleBorder + && other.side == side + && other.circularity == circularity; + } + + @override + int get hashCode => Object.hash(side, circularity); + + @override + String toString() { + if (eccentricity != 0.0) { + return 'StadiumBorder($side, ${(circularity * 100).toStringAsFixed(1)}% of the way to being a CircleBorder that is ${(eccentricity * 100).toStringAsFixed(1)}% oval)'; + } + return 'StadiumBorder($side, ${(circularity * 100).toStringAsFixed(1)}% of the way to being a CircleBorder)'; + } +} + +// Class to help with transitioning to/from a RoundedRectBorder. +class _StadiumToRoundedRectangleBorder extends OutlinedBorder { + const _StadiumToRoundedRectangleBorder({ + super.side, + this.borderRadius = BorderRadius.zero, + this.rectilinearity = 0.0, + }); + + final BorderRadiusGeometry borderRadius; + + final double rectilinearity; + + @override + ShapeBorder scale(double t) { + return _StadiumToRoundedRectangleBorder( + side: side.scale(t), + borderRadius: borderRadius * t, + rectilinearity: t, + ); + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (a is StadiumBorder) { + return _StadiumToRoundedRectangleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: borderRadius, + rectilinearity: rectilinearity * t, + ); + } + if (a is RoundedRectangleBorder) { + return _StadiumToRoundedRectangleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: borderRadius, + rectilinearity: rectilinearity + (1.0 - rectilinearity) * (1.0 - t), + ); + } + if (a is _StadiumToRoundedRectangleBorder) { + return _StadiumToRoundedRectangleBorder( + side: BorderSide.lerp(a.side, side, t), + borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!, + rectilinearity: ui.lerpDouble(a.rectilinearity, rectilinearity, t)!, + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (b is StadiumBorder) { + return _StadiumToRoundedRectangleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: borderRadius, + rectilinearity: rectilinearity * (1.0 - t), + ); + } + if (b is RoundedRectangleBorder) { + return _StadiumToRoundedRectangleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: borderRadius, + rectilinearity: rectilinearity + (1.0 - rectilinearity) * t, + ); + } + if (b is _StadiumToRoundedRectangleBorder) { + return _StadiumToRoundedRectangleBorder( + side: BorderSide.lerp(side, b.side, t), + borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t)!, + rectilinearity: ui.lerpDouble(rectilinearity, b.rectilinearity, t)!, + ); + } + return super.lerpTo(b, t); + } + + BorderRadiusGeometry _adjustBorderRadius(Rect rect) { + return BorderRadiusGeometry.lerp( + borderRadius, + BorderRadius.all(Radius.circular(rect.shortestSide / 2.0)), + 1.0 - rectilinearity, + )!; + } + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + final RRect borderRect = _adjustBorderRadius(rect).resolve(textDirection).toRRect(rect); + final RRect adjustedRect = borderRect.deflate(ui.lerpDouble(side.width, 0, side.strokeAlign)!); + return Path() + ..addRRect(adjustedRect); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path() + ..addRRect(_adjustBorderRadius(rect).resolve(textDirection).toRRect(rect)); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { + final BorderRadiusGeometry adjustedBorderRadius = _adjustBorderRadius(rect); + if (adjustedBorderRadius == BorderRadius.zero) { + canvas.drawRect(rect, paint); + } else { + canvas.drawRRect(adjustedBorderRadius.resolve(textDirection).toRRect(rect), paint); + } + } + + @override + bool get preferPaintInterior => true; + + @override + _StadiumToRoundedRectangleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius, double? rectilinearity }) { + return _StadiumToRoundedRectangleBorder( + side: side ?? this.side, + borderRadius: borderRadius ?? this.borderRadius, + rectilinearity: rectilinearity ?? this.rectilinearity, + ); + } + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + switch (side.style) { + case BorderStyle.none: + break; + case BorderStyle.solid: + final BorderRadiusGeometry adjustedBorderRadius = _adjustBorderRadius(rect); + final RRect borderRect = adjustedBorderRadius.resolve(textDirection).toRRect(rect); + canvas.drawRRect(borderRect.inflate(side.strokeOffset / 2), side.toPaint()); + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _StadiumToRoundedRectangleBorder + && other.side == side + && other.borderRadius == borderRadius + && other.rectilinearity == rectilinearity; + } + + @override + int get hashCode => Object.hash(side, borderRadius, rectilinearity); + + @override + String toString() { + return 'StadiumBorder($side, $borderRadius, ' + '${(rectilinearity * 100).toStringAsFixed(1)}% of the way to being a ' + 'RoundedRectangleBorder)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/star_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/star_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..f2917be8e6a19e73562496f811463f06a9b686bc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/star_border.dart @@ -0,0 +1,675 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'package:vector_math/vector_math_64.dart' show Matrix4; +import 'basic_types.dart'; +import 'borders.dart'; +import 'circle_border.dart'; +import 'rounded_rectangle_border.dart'; +import 'stadium_border.dart'; + +// Conversion from radians to degrees. +const double _kRadToDeg = 180 / math.pi; +// Conversion from degrees to radians. +const double _kDegToRad = math.pi / 180; + +/// A border that fits a star or polygon-shaped border within the rectangle of +/// the widget it is applied to. +/// +/// Typically used with a [ShapeDecoration] to draw a polygonal or star shaped +/// border. +/// +/// {@tool dartpad} +/// This example serves both as a usage example, as well as an explorer for +/// determining the parameters to use with a [StarBorder]. The resulting code +/// can be copied and pasted into your app. A [Container] is just one widget +/// which takes a [ShapeBorder]. [Dialog]s, [OutlinedButton]s, +/// [ElevatedButton]s, etc. all can be shaped with a [ShapeBorder]. +/// +/// ** See code in examples/api/lib/painting/star_border/star_border.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [BorderSide], which is used to describe how the edge of the shape is +/// drawn. +class StarBorder extends OutlinedBorder { + /// Create a const star-shaped border with the given number [points] on the + /// star. + const StarBorder({ + super.side, + this.points = 5, + double innerRadiusRatio = 0.4, + this.pointRounding = 0, + this.valleyRounding = 0, + double rotation = 0, + this.squash = 0, + }) : assert(squash >= 0), + assert(squash <= 1), + assert(pointRounding >= 0), + assert(pointRounding <= 1), + assert(valleyRounding >= 0), + assert(valleyRounding <= 1), + assert( + (valleyRounding + pointRounding) <= 1, + 'The sum of valleyRounding ($valleyRounding) and ' + 'pointRounding ($pointRounding) must not exceed one.'), + assert(innerRadiusRatio >= 0), + assert(innerRadiusRatio <= 1), + assert(points >= 2), + _rotationRadians = rotation * _kDegToRad, + _innerRadiusRatio = innerRadiusRatio; + + /// Create a const polygon border with the given number of [sides]. + const StarBorder.polygon({ + super.side, + double sides = 5, + this.pointRounding = 0, + double rotation = 0, + this.squash = 0, + }) : assert(squash >= 0), + assert(squash <= 1), + assert(pointRounding >= 0), + assert(pointRounding <= 1), + assert(sides >= 2), + points = sides, + valleyRounding = 0, + _rotationRadians = rotation * _kDegToRad, + _innerRadiusRatio = null; + + /// The number of points in this star, or sides on a polygon. + /// + /// This is a floating point number: if this is not a whole number, then an + /// additional star point or corner shorter than the others will be added to + /// finish the shape. Only whole-numbered values will yield a symmetric shape. + /// (This enables the number of points to be animated smoothly.) + /// + /// For stars created with [StarBorder], this is the number of points on + /// the star. For polygons created with [StarBorder.polygon], this is the + /// number of sides on the polygon. + /// + /// Must be greater than or equal to two. + final double points; + + /// The ratio of the inner radius of a star with the outer radius. + /// + /// When making a star using [StarBorder], this is the ratio of the inner + /// radius that to the outer radius. If it is one, then the inner radius + /// will equal the outer radius. + /// + /// For polygons created with [StarBorder.polygon], getting this value will + /// return the incircle radius of the polygon (the radius of a circle + /// inscribed inside the polygon). + /// + /// Defaults to 0.4 for stars, and must be between zero and one, inclusive. + double get innerRadiusRatio { + // Polygons are just a special case of a star where the inner radius is the + // incircle radius of the polygon (the radius of an inscribed circle). + return _innerRadiusRatio ?? math.cos(math.pi / points); + } + + final double? _innerRadiusRatio; + + /// The amount of rounding on the points of stars, or the corners of polygons. + /// + /// This is a value between zero and one which describes how rounded the point + /// or corner should be. A value of zero means no rounding (sharp corners), + /// and a value of one means that the entire point or corner is a portion of a + /// circle. + /// + /// Defaults to zero. The sum of [pointRounding] and [valleyRounding] must be + /// less than or equal to one. + final double pointRounding; + + /// The amount of rounding of the interior corners of stars. + /// + /// This is a value between zero and one which describes how rounded the inner + /// corners in a star (the "valley" between points) should be. A value of zero + /// means no rounding (sharp corners), and a value of one means that the + /// entire corner is a portion of a circle. + /// + /// Defaults to zero. The sum of [pointRounding] and [valleyRounding] must be + /// less than or equal to one. For polygons created with [StarBorder.polygon], + /// this will always be zero. + final double valleyRounding; + + /// The rotation in clockwise degrees around the center of the shape. + /// + /// The rotation occurs before the [squash] effect is applied, so that you can + /// fine tune where the points of a star or corners of a polygon start. + /// + /// Defaults to zero, meaning that the first point or corner is pointing up. + double get rotation => _rotationRadians * _kRadToDeg; + final double _rotationRadians; + + /// How much of the aspect ratio of the attached widget to take on. + /// + /// If [squash] is non-zero, the border will match the aspect ratio of the + /// bounding box of the widget that it is attached to, which can give a + /// squashed appearance. + /// + /// The [squash] parameter lets you control how much of that aspect ratio this + /// border takes on. + /// + /// A value of zero means that the border will be drawn with a square aspect + /// ratio at the size of the shortest side of the bounding rectangle, ignoring + /// the aspect ratio of the widget, and a value of one means it will be drawn + /// with the aspect ratio of the widget. The value of [squash] has no effect + /// if the widget is square to begin with. + /// + /// Defaults to zero, and must be between zero and one, inclusive. + final double squash; + + @override + ShapeBorder scale(double t) { + return StarBorder( + points: points, + side: side.scale(t), + rotation: rotation, + innerRadiusRatio: innerRadiusRatio, + pointRounding: pointRounding, + valleyRounding: valleyRounding, + squash: squash, + ); + } + + ShapeBorder? _twoPhaseLerp( + double t, + double split, + ShapeBorder? Function(double t) first, + ShapeBorder? Function(double t) second, + ) { + // If the rectangle has square corners, then skip the extra lerp to round the corners. + if (t < split) { + return first(t * (1 / split)); + } else { + t = (1 / (1.0 - split)) * (t - split); + return second(t); + } + } + + @override + ShapeBorder? lerpFrom(ShapeBorder? a, double t) { + if (t == 0) { + return a; + } + if (t == 1.0) { + return this; + } + if (a is StarBorder) { + return StarBorder( + side: BorderSide.lerp(a.side, side, t), + points: ui.lerpDouble(a.points, points, t)!, + rotation: ui.lerpDouble(a._rotationRadians, _rotationRadians, t)! * _kRadToDeg, + innerRadiusRatio: ui.lerpDouble(a.innerRadiusRatio, innerRadiusRatio, t)!, + pointRounding: ui.lerpDouble(a.pointRounding, pointRounding, t)!, + valleyRounding: ui.lerpDouble(a.valleyRounding, valleyRounding, t)!, + squash: ui.lerpDouble(a.squash, squash, t)!, + ); + } + + if (a is CircleBorder) { + if (points >= 2.5) { + final double lerpedPoints = ui.lerpDouble(points.round(), points, t)!; + return StarBorder( + side: BorderSide.lerp(a.side, side, t), + points: lerpedPoints, + squash: ui.lerpDouble(a.eccentricity, squash, t)!, + rotation: rotation, + innerRadiusRatio: ui.lerpDouble(math.cos(math.pi / lerpedPoints), innerRadiusRatio, t)!, + pointRounding: ui.lerpDouble(1.0, pointRounding, t)!, + valleyRounding: ui.lerpDouble(0.0, valleyRounding, t)!, + ); + } else { + // Have a slightly different lerp for two-pointed stars, since they get + // kind of squirrelly with near-zero innerRadiusRatios. + final double lerpedPoints = ui.lerpDouble(points, 2, t)!; + return StarBorder( + side: BorderSide.lerp(a.side, side, t), + points: lerpedPoints, + squash: ui.lerpDouble(a.eccentricity, squash, t)!, + rotation: rotation, + innerRadiusRatio: ui.lerpDouble(1, innerRadiusRatio, t)!, + pointRounding: ui.lerpDouble(0.5, pointRounding, t)!, + valleyRounding: ui.lerpDouble(0.5, valleyRounding, t)!, + ); + } + } + + if (a is StadiumBorder) { + // Lerp from a stadium to a circle first, and from there to a star. + final BorderSide lerpedSide = BorderSide.lerp(a.side, side, t); + return _twoPhaseLerp( + t, + 0.5, + (double t) => a.lerpTo(CircleBorder(side: lerpedSide), t), + (double t) => lerpFrom(CircleBorder(side: lerpedSide), t), + ); + } + if (a is RoundedRectangleBorder) { + // Lerp from a rectangle to a stadium, then from a Stadium to a circle, + // then from a circle to a star. + final BorderSide lerpedSide = BorderSide.lerp(a.side, side, t); + return _twoPhaseLerp( + t, + 1 / 3, + (double t) { + return StadiumBorder(side: lerpedSide).lerpFrom(a, t); + }, + (double t) { + return _twoPhaseLerp( + t, + 0.5, + (double t) => StadiumBorder(side: lerpedSide).lerpTo(CircleBorder(side: lerpedSide), t), + (double t) => lerpFrom(CircleBorder(side: lerpedSide), t), + ); + }, + ); + } + return super.lerpFrom(a, t); + } + + @override + ShapeBorder? lerpTo(ShapeBorder? b, double t) { + if (t == 0) { + return this; + } + if (t == 1.0) { + return b; + } + if (b is StarBorder) { + return StarBorder( + side: BorderSide.lerp(side, b.side, t), + points: ui.lerpDouble(points, b.points, t)!, + rotation: ui.lerpDouble(_rotationRadians, b._rotationRadians, t)! * _kRadToDeg, + innerRadiusRatio: ui.lerpDouble(innerRadiusRatio, b.innerRadiusRatio, t)!, + pointRounding: ui.lerpDouble(pointRounding, b.pointRounding, t)!, + valleyRounding: ui.lerpDouble(valleyRounding, b.valleyRounding, t)!, + squash: ui.lerpDouble(squash, b.squash, t)!, + ); + } + if (b is CircleBorder) { + // Have a slightly different lerp for two-pointed stars, since they get + // kind of squirrelly with near-zero innerRadiusRatios. + if (points >= 2.5) { + final double lerpedPoints = ui.lerpDouble(points, points.round(), t)!; + return StarBorder( + side: BorderSide.lerp(side, b.side, t), + points: lerpedPoints, + squash: ui.lerpDouble(squash, b.eccentricity, t)!, + rotation: rotation, + innerRadiusRatio: ui.lerpDouble(innerRadiusRatio, math.cos(math.pi / lerpedPoints), t)!, + pointRounding: ui.lerpDouble(pointRounding, 1.0, t)!, + valleyRounding: ui.lerpDouble(valleyRounding, 0.0, t)!, + ); + } else { + final double lerpedPoints = ui.lerpDouble(points, 2, t)!; + return StarBorder( + side: BorderSide.lerp(side, b.side, t), + points: lerpedPoints, + squash: ui.lerpDouble(squash, b.eccentricity, t)!, + rotation: rotation, + innerRadiusRatio: ui.lerpDouble(innerRadiusRatio, 1, t)!, + pointRounding: ui.lerpDouble(pointRounding, 0.5, t)!, + valleyRounding: ui.lerpDouble(valleyRounding, 0.5, t)!, + ); + } + } + if (b is StadiumBorder) { + // Lerp to a circle first, then to a stadium. + final BorderSide lerpedSide = BorderSide.lerp(side, b.side, t); + return _twoPhaseLerp( + t, + 0.5, + (double t) => lerpTo(CircleBorder(side: lerpedSide), t), + (double t) => b.lerpFrom(CircleBorder(side: lerpedSide), t), + ); + } + if (b is RoundedRectangleBorder) { + // Lerp to a circle, and then to a stadium, then to a rounded rect. + final BorderSide lerpedSide = BorderSide.lerp(side, b.side, t); + return _twoPhaseLerp( + t, + 2 / 3, + (double t) { + return _twoPhaseLerp( + t, + 0.5, + (double t) => lerpTo(CircleBorder(side: lerpedSide), t), + (double t) => StadiumBorder(side: lerpedSide).lerpFrom(CircleBorder(side: lerpedSide), t), + ); + }, + (double t) { + return StadiumBorder(side: lerpedSide).lerpTo(b, t); + }, + ); + } + return super.lerpTo(b, t); + } + + @override + StarBorder copyWith({ + BorderSide? side, + double? points, + double? innerRadiusRatio, + double? pointRounding, + double? valleyRounding, + double? rotation, + double? squash, + }) { + return StarBorder( + side: side ?? this.side, + points: points ?? this.points, + rotation: rotation ?? this.rotation, + innerRadiusRatio: innerRadiusRatio ?? this.innerRadiusRatio, + pointRounding: pointRounding ?? this.pointRounding, + valleyRounding: valleyRounding ?? this.valleyRounding, + squash: squash ?? this.squash, + ); + } + + @override + Path getInnerPath(Rect rect, {TextDirection? textDirection}) { + final Rect adjustedRect = rect.deflate(side.strokeInset); + return _StarGenerator( + points: points, + rotation: _rotationRadians, + innerRadiusRatio: innerRadiusRatio, + pointRounding: pointRounding, + valleyRounding: valleyRounding, + squash: squash, + ).generate(adjustedRect); + } + + @override + Path getOuterPath(Rect rect, {TextDirection? textDirection}) { + return _StarGenerator( + points: points, + rotation: _rotationRadians, + innerRadiusRatio: innerRadiusRatio, + pointRounding: pointRounding, + valleyRounding: valleyRounding, + squash: squash, + ).generate(rect); + } + + @override + void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) { + switch (side.style) { + case BorderStyle.none: + break; + case BorderStyle.solid: + final Rect adjustedRect = rect.inflate(side.strokeOffset / 2); + final Path path = _StarGenerator( + points: points, + rotation: _rotationRadians, + innerRadiusRatio: innerRadiusRatio, + pointRounding: pointRounding, + valleyRounding: valleyRounding, + squash: squash, + ).generate(adjustedRect); + canvas.drawPath(path, side.toPaint()); + } + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is StarBorder + && other.side == side + && other.points == points + && other._innerRadiusRatio == _innerRadiusRatio + && other.pointRounding == pointRounding + && other.valleyRounding == valleyRounding + && other._rotationRadians == _rotationRadians + && other.squash == squash; + } + + @override + int get hashCode => side.hashCode; + + @override + String toString() { + return '${objectRuntimeType(this, 'StarBorder')}($side, points: $points, innerRadiusRatio: $innerRadiusRatio)'; + } +} + +class _PointInfo { + _PointInfo({ + required this.valley, + required this.point, + required this.valleyArc1, + required this.pointArc1, + required this.valleyArc2, + required this.pointArc2, + }); + + Offset valley; + Offset point; + Offset valleyArc1; + Offset pointArc1; + Offset pointArc2; + Offset valleyArc2; +} + +class _StarGenerator { + const _StarGenerator({ + required this.points, + required this.innerRadiusRatio, + required this.pointRounding, + required this.valleyRounding, + required this.rotation, + required this.squash, + }) : assert(points > 1), + assert(innerRadiusRatio <= 1), + assert(innerRadiusRatio >= 0), + assert(squash >= 0), + assert(squash <= 1), + assert(pointRounding >= 0), + assert(pointRounding <= 1), + assert(valleyRounding >= 0), + assert(valleyRounding <= 1), + assert(pointRounding + valleyRounding <= 1); + + final double points; + final double innerRadiusRatio; + final double pointRounding; + final double valleyRounding; + final double rotation; + final double squash; + + Path generate(Rect rect) { + final double radius = rect.shortestSide / 2; + final Offset center = rect.center; + + // The minimum allowed inner radius ratio. Numerical instabilities occur near + // zero, so we just don't allow values in that range. + const double minInnerRadiusRatio = .002; + + // Map the innerRadiusRatio so that we don't get values close to zero, since + // things get a little squirrelly there because the path thinks that the + // length of the conicTo is small enough that it can render it as a straight + // line, even though it will be scaled up later. This maps the range from + // [0, 1] to [minInnerRadiusRatio, 1]. + final double mappedInnerRadiusRatio = (innerRadiusRatio * (1.0 - minInnerRadiusRatio)) + minInnerRadiusRatio; + + // First, generate the "points" of the star. + final List<_PointInfo> points = <_PointInfo>[]; + final double maxDiameter = 2.0 * + _generatePoints( + pointList: points, + center: center, + radius: radius, + innerRadius: radius * mappedInnerRadiusRatio, + ); + + // Calculate the endpoints of each of the arcs, then draw the arcs. + final Path path = Path(); + _drawPoints(path, points); + + Offset scale = Offset(rect.width / maxDiameter, rect.height / maxDiameter); + if (rect.shortestSide == rect.width) { + scale = Offset(scale.dx, squash * scale.dy + (1 - squash) * scale.dx); + } else { + scale = Offset(squash * scale.dx + (1 - squash) * scale.dy, scale.dy); + } + // Scale the border so that it matches the size of the widget rectangle, so + // that "rotation" of the shape doesn't affect how much of the rectangle it + // covers. + final Matrix4 squashMatrix = Matrix4.translationValues(rect.center.dx, rect.center.dy, 0); + squashMatrix.multiply(Matrix4.diagonal3Values(scale.dx, scale.dy, 1)); + squashMatrix.multiply(Matrix4.rotationZ(rotation)); + squashMatrix.multiply(Matrix4.translationValues(-rect.center.dx, -rect.center.dy, 0)); + return path.transform(squashMatrix.storage); + } + + double _generatePoints({ + required List<_PointInfo> pointList, + required Offset center, + required double radius, + required double innerRadius, + }) { + final double step = math.pi / points; + // Start initial rotation one step before zero. + double angle = -math.pi / 2 - step; + Offset valley = Offset( + center.dx + math.cos(angle) * innerRadius, + center.dy + math.sin(angle) * innerRadius, + ); + + // In order to do overall scale properly, calculate the actual radius at the + // point, taking into account the rounding of the points and the weight of + // the corner point. This effectively is evaluating the rational quadratic + // bezier at the midpoint of the curve. + Offset getCurveMidpoint(Offset a, Offset b, Offset c, Offset a1, Offset c1) { + final double angle = _getAngle(a, b, c); + final double w = _getWeight(angle) / 2; + return (a1 / 4 + b * w + c1 / 4) / (0.5 + w); + } + + double addPoint( + double pointAngle, + double pointStep, + double pointRadius, + double pointInnerRadius, + ) { + pointAngle += pointStep; + final Offset point = Offset( + center.dx + math.cos(pointAngle) * pointRadius, + center.dy + math.sin(pointAngle) * pointRadius, + ); + pointAngle += pointStep; + final Offset nextValley = Offset( + center.dx + math.cos(pointAngle) * pointInnerRadius, + center.dy + math.sin(pointAngle) * pointInnerRadius, + ); + final Offset valleyArc1 = valley + (point - valley) * valleyRounding; + final Offset pointArc1 = point + (valley - point) * pointRounding; + final Offset pointArc2 = point + (nextValley - point) * pointRounding; + final Offset valleyArc2 = nextValley + (point - nextValley) * valleyRounding; + + pointList.add(_PointInfo( + valley: valley, + point: point, + valleyArc1: valleyArc1, + pointArc1: pointArc1, + pointArc2: pointArc2, + valleyArc2: valleyArc2, + )); + valley = nextValley; + return pointAngle; + } + + final double remainder = points - points.truncateToDouble(); + final bool hasIntegerSides = remainder < 1e-6; + final double wholeSides = points - (hasIntegerSides ? 0 : 1); + for (int i = 0; i < wholeSides; i += 1) { + angle = addPoint(angle, step, radius, innerRadius); + } + + double valleyRadius = 0; + double pointRadius = 0; + final _PointInfo thisPoint = pointList[0]; + final _PointInfo nextPoint = pointList[1]; + + final Offset pointMidpoint = + getCurveMidpoint(thisPoint.valley, thisPoint.point, nextPoint.valley, thisPoint.pointArc1, thisPoint.pointArc2); + final Offset valleyMidpoint = getCurveMidpoint( + thisPoint.point, nextPoint.valley, nextPoint.point, thisPoint.valleyArc2, nextPoint.valleyArc1); + valleyRadius = (valleyMidpoint - center).distance; + pointRadius = (pointMidpoint - center).distance; + + // Add the final point to close the shape if there are fractional sides to + // account for. + if (!hasIntegerSides) { + final double effectiveInnerRadius = math.max(valleyRadius, innerRadius); + final double endingRadius = effectiveInnerRadius + remainder * (radius - effectiveInnerRadius); + addPoint(angle, step * remainder, endingRadius, innerRadius); + } + + // The rounding added to the valley radius can sometimes push it outside of + // the rounding of the point, since the rounding amount can be different + // between the points and the valleys, so we have to evaluate both the + // valley and the point radii, and pick the largest. Also, since this value + // is used later to determine the scale, we need to keep it finite and + // non-zero. + return clampDouble(math.max(valleyRadius, pointRadius), double.minPositive, double.maxFinite); + } + + void _drawPoints(Path path, List<_PointInfo> points) { + final Offset startingPoint = points.first.pointArc1; + path.moveTo(startingPoint.dx, startingPoint.dy); + final double pointAngle = _getAngle(points[0].valley, points[0].point, points[1].valley); + final double pointWeight = _getWeight(pointAngle); + final double valleyAngle = _getAngle(points[1].point, points[1].valley, points[0].point); + final double valleyWeight = _getWeight(valleyAngle); + + for (int i = 0; i < points.length; i += 1) { + final _PointInfo point = points[i]; + final _PointInfo nextPoint = points[(i + 1) % points.length]; + path.lineTo(point.pointArc1.dx, point.pointArc1.dy); + if (pointAngle != 180 && pointAngle != 0) { + path.conicTo(point.point.dx, point.point.dy, point.pointArc2.dx, point.pointArc2.dy, pointWeight); + } else { + path.lineTo(point.pointArc2.dx, point.pointArc2.dy); + } + path.lineTo(point.valleyArc2.dx, point.valleyArc2.dy); + if (valleyAngle != 180 && valleyAngle != 0) { + path.conicTo( + nextPoint.valley.dx, nextPoint.valley.dy, nextPoint.valleyArc1.dx, nextPoint.valleyArc1.dy, valleyWeight); + } else { + path.lineTo(nextPoint.valleyArc1.dx, nextPoint.valleyArc1.dy); + } + } + path.close(); + } + + double _getWeight(double angle) { + return math.cos((angle / 2) % (math.pi / 2)); + } + + // Returns the included angle between points ABC in radians. + double _getAngle(Offset a, Offset b, Offset c) { + if (a == c || b == c || b == a) { + return 0; + } + final Offset u = a - b; + final Offset v = c - b; + final double dot = u.dx * v.dx + u.dy * v.dy; + final double m1 = b.dx == a.dx ? double.infinity : -u.dy / -u.dx; + final double m2 = b.dx == c.dx ? double.infinity : -v.dy / -v.dx; + double angle = math.atan2(m1 - m2, 1 + m1 * m2).abs(); + if (dot < 0) { + angle += math.pi; + } + return angle; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/strut_style.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/strut_style.dart new file mode 100644 index 0000000000000000000000000000000000000000..4f80fbef761f21b12a4514dff20695beb4c45c11 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/strut_style.dart @@ -0,0 +1,628 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'text_style.dart'; + +/// Defines the strut, which sets the minimum height a line can be +/// relative to the baseline. +/// +/// Strut applies to all lines in the paragraph. Strut is a feature that +/// allows minimum line heights to be set. The effect is as if a zero +/// width space was included at the beginning of each line in the +/// paragraph. This imaginary space is 'shaped' according the properties +/// defined in this class. Flutter's strut is based on +/// [typesetting strut](https://en.wikipedia.org/wiki/Strut_(typesetting)) +/// and CSS's [line-height](https://www.w3.org/TR/CSS2/visudet.html#line-height). +/// +/// No lines may be shorter than the strut. The ascent and descent of the +/// strut are calculated, and any laid out text that has a shorter ascent or +/// descent than the strut's ascent or descent will take the ascent and +/// descent of the strut. Text with ascents or descents larger than the +/// strut's ascent or descent will layout as normal and extend past the strut. +/// +/// Strut is defined independently from any text content or [TextStyle]s. +/// +/// The vertical components of strut are as follows: +/// +/// * Half the font-defined leading +/// * `ascent * height` +/// * `descent * height` +/// * Half the font-defined leading +/// +/// The sum of these four values is the total height of the line. +/// +/// Ascent is the font's spacing above the baseline without leading and +/// descent is the spacing below the baseline without leading. Leading is +/// split evenly between the top and bottom. The values for `ascent` and +/// `descent` are provided by the font named by [fontFamily]. If no +/// [fontFamily] or [fontFamilyFallback] is provided, then the platform's +/// default family will be used. Many fonts will have leading values of +/// zero, so in practice, the leading component is often irrelevant. +/// +/// When [height] is omitted or null, then the font defined ascent and descent +/// will be used. The font's combined ascent and descent may be taller or +/// shorter than the [fontSize]. When [height] is provided, the line's EM-square +/// ascent and descent (which sums to [fontSize]) will be scaled by [height] to +/// achieve a final line height of `fontSize * height + fontSize * leading` +/// logical pixels. The proportion of ascent:descent with [height] specified +/// is the same as the font metrics defined ascent:descent ratio. +/// +/// ![Text height diagram](https://flutter.github.io/assets-for-api-docs/assets/painting/text_height_diagram.png) +/// +/// Each line's spacing above the baseline will be at least as tall as the +/// half leading plus ascent. Each line's spacing below the baseline will +/// be at least as tall as the half leading plus descent. +/// +/// See also: +/// +/// * [StrutStyle](dart-ui/StrutStyle-class.html), the class in the [dart:ui] library. +/// +/// ### Fields and their default values. + +// /////////////////////////////////////////////////////////////////////////// +// The defaults are noted here for convenience. The actual place where they // +// are defined is in the engine paragraph_style.h of LibTxt. The values here// +// should be updated should it change in the engine. The engine specifies // +// the defaults in order to reduce the amount of data we pass to native as // +// strut will usually be unspecified. // +// /////////////////////////////////////////////////////////////////////////// + +/// +/// Omitted or null properties will take the default values specified below: +/// +/// * [fontFamily]: the name of the font to use when calculating the strut +/// (e.g., Roboto). No glyphs from the font will be drawn and the font will +/// be used purely for metrics. +/// +/// * [fontFamilyFallback]: an ordered list of font family names that will +/// be searched for when the font in [fontFamily] cannot be found. When +/// all specified font families have been exhausted an no match was found, +/// the default platform font will be used. +/// +/// * [fontSize]: the size of the ascent plus descent in logical pixels. This +/// is also used as the basis of the custom leading calculation. This value +/// cannot be negative. +/// Default is 14 logical pixels. +/// +/// * [height]: the multiple of [fontSize] the line's height should be. +/// The line's height will take the font's ascent and descent values if +/// [height] is omitted or null. If provided, the EM-square ascent and +/// descent (which sum to [fontSize]) is scaled by [height]. +/// The [height] will impact the spacing above and below the baseline +/// differently depending on the ratios between the font's ascent and +/// descent. This property is separate from the leading multiplier, which +/// is controlled through [leading]. +/// Default is null. +/// +/// * [leading]: the custom leading to apply to the strut as a multiple of +/// [fontSize]. Leading is additional spacing between lines. Half of the +/// leading is added to the top and the other half to the bottom of the +/// line height. This differs from [height] since the spacing is equally +/// distributed above and below the baseline. +/// Default is null, which will use the font-specified leading. +/// +/// * [fontWeight]: the typeface thickness to use when calculating the strut +/// (e.g., bold). +/// Default is [FontWeight.w400]. +/// +/// * [fontStyle]: the typeface variant to use when calculating the strut +/// (e.g., italic). +/// Default is [FontStyle.normal]. +/// +/// * [forceStrutHeight]: when true, all lines will be laid out with the +/// height of the strut. All line and run-specific metrics will be +/// ignored/overridden and only strut metrics will be used instead. +/// This property guarantees uniform line spacing, however text in +/// adjacent lines may overlap. This property should be enabled with +/// caution as it bypasses a large portion of the vertical layout system. +/// The default value is false. +/// +/// ### Examples +/// +/// {@tool snippet} +/// In this simple case, the text will be rendered at font size 10, however, +/// the vertical height of each line will be the strut height (Roboto in +/// font size 30 * 1.5) as the text itself is shorter than the strut. +/// +/// ```dart +/// const Text( +/// 'Hello, world!\nSecond line!', +/// style: TextStyle( +/// fontSize: 10, +/// fontFamily: 'Raleway', +/// ), +/// strutStyle: StrutStyle( +/// fontFamily: 'Roboto', +/// fontSize: 30, +/// height: 1.5, +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// Here, strut is used to absorb the additional line height in the second line. +/// The strut [height] was defined as 1.5 (the default font size is 14), which +/// caused all lines to be laid out taller than without strut. This extra space +/// was able to accommodate the larger font size of `Second line!` without +/// causing the line height to change for the second line only. All lines in +/// this example are thus the same height (`14 * 1.5`). +/// +/// ```dart +/// const Text.rich( +/// TextSpan( +/// text: 'First line!\n', +/// style: TextStyle( +/// fontSize: 14, +/// fontFamily: 'Roboto' +/// ), +/// children: <TextSpan>[ +/// TextSpan( +/// text: 'Second line!\n', +/// style: TextStyle( +/// fontSize: 16, +/// fontFamily: 'Roboto', +/// ), +/// ), +/// TextSpan( +/// text: 'Third line!\n', +/// style: TextStyle( +/// fontSize: 14, +/// fontFamily: 'Roboto', +/// ), +/// ), +/// ], +/// ), +/// strutStyle: StrutStyle( +/// fontFamily: 'Roboto', +/// height: 1.5, +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// Here, strut is used to enable strange and overlapping text to achieve unique +/// effects. The `M`s in lines 2 and 3 are able to extend above their lines and +/// fill empty space in lines above. The [forceStrutHeight] is enabled and functions +/// as a 'grid' for the glyphs to draw on. +/// +/// ![The result of the example below.](https://flutter.github.io/assets-for-api-docs/assets/painting/strut_force_example.png) +/// +/// ```dart +/// const Text.rich( +/// TextSpan( +/// text: '--------- ---------\n', +/// style: TextStyle( +/// fontSize: 14, +/// fontFamily: 'Roboto', +/// ), +/// children: <TextSpan>[ +/// TextSpan( +/// text: '^^^M^^^\n', +/// style: TextStyle( +/// fontSize: 30, +/// fontFamily: 'Roboto', +/// ), +/// ), +/// TextSpan( +/// text: 'M------M\n', +/// style: TextStyle( +/// fontSize: 30, +/// fontFamily: 'Roboto', +/// ), +/// ), +/// ], +/// ), +/// strutStyle: StrutStyle( +/// fontFamily: 'Roboto', +/// fontSize: 14, +/// height: 1, +/// forceStrutHeight: true, +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// This example uses forceStrutHeight to create a 'drop cap' for the 'T' in 'The'. +/// By locking the line heights to the metrics of the 14pt serif font, we are able +/// to lay out a large 37pt 'T' on the second line to take up space on both the first +/// and second lines. +/// +/// ![The result of the example below.](https://flutter.github.io/assets-for-api-docs/assets/painting/strut_force_example_2.png) +/// +/// ```dart +/// const Text.rich( +/// TextSpan( +/// text: '  he candle flickered\n', +/// style: TextStyle( +/// fontSize: 14, +/// fontFamily: 'Serif' +/// ), +/// children: <TextSpan>[ +/// TextSpan( +/// text: 'T', +/// style: TextStyle( +/// fontSize: 37, +/// fontFamily: 'Serif' +/// ), +/// ), +/// TextSpan( +/// text: 'in the moonlight as\n', +/// style: TextStyle( +/// fontSize: 14, +/// fontFamily: 'Serif' +/// ), +/// ), +/// TextSpan( +/// text: 'Dash the bird fluttered\n', +/// style: TextStyle( +/// fontSize: 14, +/// fontFamily: 'Serif' +/// ), +/// ), +/// TextSpan( +/// text: 'off into the distance.', +/// style: TextStyle( +/// fontSize: 14, +/// fontFamily: 'Serif' +/// ), +/// ), +/// ], +/// ), +/// strutStyle: StrutStyle( +/// fontFamily: 'Serif', +/// fontSize: 14, +/// forceStrutHeight: true, +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +@immutable +class StrutStyle with Diagnosticable { + /// Creates a strut style. + /// + /// The `package` argument must be non-null if the font family is defined in a + /// package. It is combined with the `fontFamily` argument to set the + /// [fontFamily] property. + /// + /// If provided, fontSize must be positive and non-zero, leading must be + /// zero or positive. + const StrutStyle({ + String? fontFamily, + List<String>? fontFamilyFallback, + this.fontSize, + this.height, + this.leadingDistribution, + this.leading, + this.fontWeight, + this.fontStyle, + this.forceStrutHeight, + this.debugLabel, + String? package, + }) : fontFamily = package == null ? fontFamily : 'packages/$package/$fontFamily', + _fontFamilyFallback = fontFamilyFallback, + _package = package, + assert(fontSize == null || fontSize > 0), + assert(leading == null || leading >= 0), + assert(package == null || (fontFamily != null || fontFamilyFallback != null)); + + /// Builds a StrutStyle that contains values of the equivalent properties in + /// the provided [textStyle]. + /// + /// The named parameters override the [textStyle]'s argument's properties. + /// Since TextStyle does not contain [leading] or [forceStrutHeight], these + /// values will take on default values (null and false) unless otherwise + /// specified. + /// + /// If provided, fontSize must be positive and non-zero, leading must be + /// zero or positive. + /// + /// When [textStyle] has a package and a new [package] is also specified, + /// the entire font family fallback list should be redefined since the + /// [textStyle]'s package data is inherited by being prepended onto the + /// font family names. If [fontFamilyFallback] is meant to be empty, pass + /// an empty list instead of null. This prevents the previous package name + /// from being prepended twice. + StrutStyle.fromTextStyle( + TextStyle textStyle, { + String? fontFamily, + List<String>? fontFamilyFallback, + double? fontSize, + double? height, + TextLeadingDistribution? leadingDistribution, + this.leading, // TextStyle does not have an equivalent (yet). + FontWeight? fontWeight, + FontStyle? fontStyle, + this.forceStrutHeight, + String? debugLabel, + String? package, + }) : assert(fontSize == null || fontSize > 0), + assert(leading == null || leading >= 0), + assert(package == null || fontFamily != null || fontFamilyFallback != null), + fontFamily = fontFamily != null ? (package == null ? fontFamily : 'packages/$package/$fontFamily') : textStyle.fontFamily, + _fontFamilyFallback = fontFamilyFallback ?? textStyle.fontFamilyFallback, + height = height ?? textStyle.height, + leadingDistribution = leadingDistribution ?? textStyle.leadingDistribution, + fontSize = fontSize ?? textStyle.fontSize, + fontWeight = fontWeight ?? textStyle.fontWeight, + fontStyle = fontStyle ?? textStyle.fontStyle, + debugLabel = debugLabel ?? textStyle.debugLabel, + _package = package; // the textStyle._package data is embedded in the + // fontFamily names, so we no longer need it. + + /// A [StrutStyle] that will have no impact on the text layout. + /// + /// Equivalent to having no strut at all. All lines will be laid out according to + /// the properties defined in [TextStyle]. + static const StrutStyle disabled = StrutStyle( + height: 0.0, + leading: 0.0, + ); + + /// The name of the font to use when calculating the strut (e.g., Roboto). If + /// the font is defined in a package, this will be prefixed with + /// 'packages/package_name/' (e.g. 'packages/cool_fonts/Roboto'). The + /// prefixing is done by the constructor when the `package` argument is + /// provided. + /// + /// The value provided in [fontFamily] will act as the preferred/first font + /// family that will be searched for, followed in order by the font families + /// in [fontFamilyFallback]. If all font families are exhausted and no match + /// was found, the default platform font family will be used instead. Unlike + /// [TextStyle.fontFamilyFallback], the font does not need to contain the + /// desired glyphs to match. + final String? fontFamily; + + /// The ordered list of font families to fall back on when a higher priority + /// font family cannot be found. + /// + /// The value provided in [fontFamily] will act as the preferred/first font + /// family that will be searched for, followed in order by the font families + /// in [fontFamilyFallback]. If all font families are exhausted and no match + /// was found, the default platform font family will be used instead. Unlike + /// [TextStyle.fontFamilyFallback], the font does not need to contain the + /// desired glyphs to match. + /// + /// When [fontFamily] is null or not provided, the first value in [fontFamilyFallback] + /// acts as the preferred/first font family. When neither is provided, then + /// the default platform font will be used. Providing and empty list or null + /// for this property is the same as omitting it. + /// + /// If the font is defined in a package, each font family in the list will be + /// prefixed with 'packages/package_name/' (e.g. 'packages/cool_fonts/Roboto'). + /// The package name should be provided by the `package` argument in the + /// constructor. + List<String>? get fontFamilyFallback { + if (_package != null && _fontFamilyFallback != null) { + return _fontFamilyFallback.map((String family) => 'packages/$_package/$family').toList(); + } + return _fontFamilyFallback; + } + final List<String>? _fontFamilyFallback; + + // This is stored in order to prefix the fontFamilies in _fontFamilyFallback + // in the [fontFamilyFallback] getter. + final String? _package; + + /// The size of text (in logical pixels) to use when obtaining metrics from the font. + /// + /// The [fontSize] is used to get the base set of metrics that are then used to calculated + /// the metrics of strut. The height and leading are expressed as a multiple of + /// [fontSize]. + /// + /// The default fontSize is 14 logical pixels. + final double? fontSize; + + /// The minimum height of the strut, as a multiple of [fontSize]. + /// + /// When [height] is omitted or null, then the strut's height will be the sum + /// of the strut's font-defined ascent, its font-defined descent, and its + /// [leading]. The font's combined ascent and descent may be taller or shorter + /// than the [fontSize]. + /// + /// When [height] is provided, the line's EM-square ascent and descent (which + /// sums to [fontSize]) will be scaled by [height] to achieve a final strut + /// height of `fontSize * height + fontSize * leading` logical pixels. The + /// following diagram illustrates the differences between the font metrics + /// defined height and the EM-square height: + /// + /// ![Text height diagram](https://flutter.github.io/assets-for-api-docs/assets/painting/text_height_diagram.png) + /// + /// The ratio of ascent:descent with [height] specified is the same as the + /// font metrics defined ascent:descent ratio when [height] is null or omitted. + /// + /// See [TextStyle.height], which works in a similar manner. + /// + /// The default height is null. + final double? height; + + /// How the vertical space added by the [height] multiplier should be + /// distributed over and under the strut. + /// + /// When a non-null [height] is specified, after accommodating the imaginary + /// strut glyph, the remaining vertical space from the allotted + /// `fontSize * height` logical pixels will be distributed over and under the + /// strut, according to the [leadingDistribution] property. + /// + /// The additional leading introduced by the [leading] property applies + /// independently of [leadingDistribution]: it will always be distributed + /// evenly over and under the strut, regardless of [leadingDistribution]. + /// + /// Defaults to null, which defers to the paragraph's + /// `ParagraphStyle.textHeightBehavior`'s [leadingDistribution]. + final TextLeadingDistribution? leadingDistribution; + + /// The typeface thickness to use when calculating the strut (e.g., bold). + /// + /// The default fontWeight is [FontWeight.w400]. + final FontWeight? fontWeight; + + /// The typeface variant to use when calculating the strut (e.g., italics). + /// + /// The default fontStyle is [FontStyle.normal]. + final FontStyle? fontStyle; + + /// The additional leading to apply to the strut as a multiple of [fontSize], + /// independent of [height] and [leadingDistribution]. + /// + /// Leading is additional spacing between lines. Half of the leading is added + /// to the top and the other half to the bottom of the line. This differs + /// from [height] since the spacing is always equally distributed above and + /// below the baseline, regardless of [leadingDistribution]. + /// + /// The default leading is null, which will use the font-specified leading. + final double? leading; + + /// Whether the strut height should be forced. + /// + /// When true, all lines will be laid out with the height of the + /// strut. All line and run-specific metrics will be ignored/overridden + /// and only strut metrics will be used instead. This property guarantees + /// uniform line spacing, however text in adjacent lines may overlap. + /// + /// This property should be enabled with caution as + /// it bypasses a large portion of the vertical layout system. + /// + /// This is equivalent to setting [TextStyle.height] to zero for all [TextStyle]s + /// in the paragraph. Since the height of each line is calculated as a max of the + /// metrics of each run of text, zero height [TextStyle]s cause the minimums + /// defined by strut to always manifest, resulting in all lines having the height + /// of the strut. + /// + /// The default is false. + final bool? forceStrutHeight; + + /// A human-readable description of this strut style. + /// + /// This property is maintained only in debug builds. + /// + /// This property is not considered when comparing strut styles using `==` or + /// [compareTo], and it does not affect [hashCode]. + final String? debugLabel; + + /// Describe the difference between this style and another, in terms of how + /// much damage it will make to the rendering. + /// + /// See also: + /// + /// * [TextSpan.compareTo], which does the same thing for entire [TextSpan]s. + RenderComparison compareTo(StrutStyle other) { + if (identical(this, other)) { + return RenderComparison.identical; + } + if (fontFamily != other.fontFamily || + fontSize != other.fontSize || + fontWeight != other.fontWeight || + fontStyle != other.fontStyle || + height != other.height || + leading != other.leading || + forceStrutHeight != other.forceStrutHeight || + !listEquals(fontFamilyFallback, other.fontFamilyFallback)) { + return RenderComparison.layout; + } + return RenderComparison.identical; + } + + /// Returns a new strut style that inherits its null values from + /// corresponding properties in the [other] [TextStyle]. + /// + /// The "missing" properties of the this strut style are _filled_ by + /// the properties of the provided [TextStyle]. This is possible because + /// [StrutStyle] shares many of the same basic properties as [TextStyle]. + /// + /// If the given text style is null, returns this strut style. + StrutStyle inheritFromTextStyle(TextStyle? other) { + if (other == null) { + return this; + } + + return StrutStyle( + fontFamily: fontFamily ?? other.fontFamily, + fontFamilyFallback: fontFamilyFallback ?? other.fontFamilyFallback, + fontSize: fontSize ?? other.fontSize, + height: height ?? other.height, + leading: leading, // No equivalent property in TextStyle yet. + fontWeight: fontWeight ?? other.fontWeight, + fontStyle: fontStyle ?? other.fontStyle, + forceStrutHeight: forceStrutHeight, // StrutStyle-unique property. + debugLabel: debugLabel ?? other.debugLabel, + // Package is embedded within the getters for fontFamilyFallback. + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is StrutStyle + && other.fontFamily == fontFamily + && other.fontSize == fontSize + && other.fontWeight == fontWeight + && other.fontStyle == fontStyle + && other.height == height + && other.leading == leading + && other.forceStrutHeight == forceStrutHeight; + } + + @override + int get hashCode => Object.hash( + fontFamily, + fontSize, + fontWeight, + fontStyle, + height, + leading, + forceStrutHeight, + ); + + @override + String toStringShort() => objectRuntimeType(this, 'StrutStyle'); + + /// Adds all properties prefixing property names with the optional `prefix`. + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties, { String prefix = '' }) { + super.debugFillProperties(properties); + if (debugLabel != null) { + properties.add(MessageProperty('${prefix}debugLabel', debugLabel!)); + } + final List<DiagnosticsNode> styles = <DiagnosticsNode>[ + StringProperty('${prefix}family', fontFamily, defaultValue: null, quoted: false), + IterableProperty<String>('${prefix}familyFallback', fontFamilyFallback, defaultValue: null), + DoubleProperty('${prefix}size', fontSize, defaultValue: null), + ]; + String? weightDescription; + if (fontWeight != null) { + weightDescription = 'w${fontWeight!.index + 1}00'; + } + // TODO(jacobr): switch this to use enumProperty which will either cause the + // weight description to change to w600 from 600 or require existing + // enumProperty to handle this special case. + styles.add(DiagnosticsProperty<FontWeight>( + '${prefix}weight', + fontWeight, + description: weightDescription, + defaultValue: null, + )); + styles.add(EnumProperty<FontStyle>('${prefix}style', fontStyle, defaultValue: null)); + styles.add(DoubleProperty('${prefix}height', height, unit: 'x', defaultValue: null)); + styles.add(FlagProperty('${prefix}forceStrutHeight', value: forceStrutHeight, ifTrue: '$prefix<strut height forced>', ifFalse: '$prefix<strut height normal>')); + + final bool styleSpecified = styles.any((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info)); + styles.forEach(properties.add); + + if (!styleSpecified) { + properties.add(FlagProperty('forceStrutHeight', value: forceStrutHeight, ifTrue: '$prefix<strut height forced>', ifFalse: '$prefix<strut height normal>')); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_painter.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_painter.dart new file mode 100644 index 0000000000000000000000000000000000000000..415db9a1b6b0104482abc8d3f5f4eeccf5879db0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_painter.dart @@ -0,0 +1,1643 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' show max, min; +import 'dart:ui' as ui show + BoxHeightStyle, + BoxWidthStyle, + GlyphInfo, + LineMetrics, + Paragraph, + ParagraphBuilder, + ParagraphConstraints, + ParagraphStyle, + PlaceholderAlignment, + TextStyle; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'basic_types.dart'; +import 'inline_span.dart'; +import 'placeholder_span.dart'; +import 'strut_style.dart'; +import 'text_scaler.dart'; +import 'text_span.dart'; + +export 'dart:ui' show LineMetrics; +export 'package:flutter/services.dart' show TextRange, TextSelection; + +/// The default font size if none is specified. +/// +/// This should be kept in sync with the defaults set in the engine (e.g., +/// LibTxt's text_style.h, paragraph_style.h). +const double kDefaultFontSize = 14.0; + +/// How overflowing text should be handled. +/// +/// A [TextOverflow] can be passed to [Text] and [RichText] via their +/// [Text.overflow] and [RichText.overflow] properties respectively. +enum TextOverflow { + /// Clip the overflowing text to fix its container. + clip, + + /// Fade the overflowing text to transparent. + fade, + + /// Use an ellipsis to indicate that the text has overflowed. + ellipsis, + + /// Render overflowing text outside of its container. + visible, +} + +/// Holds the [Size] and baseline required to represent the dimensions of +/// a placeholder in text. +/// +/// Placeholders specify an empty space in the text layout, which is used +/// to later render arbitrary inline widgets into defined by a [WidgetSpan]. +/// +/// See also: +/// +/// * [WidgetSpan], a subclass of [InlineSpan] and [PlaceholderSpan] that +/// represents an inline widget embedded within text. The space this +/// widget takes is indicated by a placeholder. +/// * [RichText], a text widget that supports text inline widgets. +@immutable +class PlaceholderDimensions { + /// Constructs a [PlaceholderDimensions] with the specified parameters. + /// + /// The `size` and `alignment` are required as a placeholder's dimensions + /// require at least `size` and `alignment` to be fully defined. + const PlaceholderDimensions({ + required this.size, + required this.alignment, + this.baseline, + this.baselineOffset, + }); + + /// A constant representing an empty placeholder. + static const PlaceholderDimensions empty = PlaceholderDimensions(size: Size.zero, alignment: ui.PlaceholderAlignment.bottom); + + /// Width and height dimensions of the placeholder. + final Size size; + + /// How to align the placeholder with the text. + /// + /// See also: + /// + /// * [baseline], the baseline to align to when using + /// [dart:ui.PlaceholderAlignment.baseline], + /// [dart:ui.PlaceholderAlignment.aboveBaseline], + /// or [dart:ui.PlaceholderAlignment.belowBaseline]. + /// * [baselineOffset], the distance of the alphabetic baseline from the upper + /// edge of the placeholder. + final ui.PlaceholderAlignment alignment; + + /// Distance of the [baseline] from the upper edge of the placeholder. + /// + /// Only used when [alignment] is [ui.PlaceholderAlignment.baseline]. + final double? baselineOffset; + + /// The [TextBaseline] to align to. Used with: + /// + /// * [ui.PlaceholderAlignment.baseline] + /// * [ui.PlaceholderAlignment.aboveBaseline] + /// * [ui.PlaceholderAlignment.belowBaseline] + /// * [ui.PlaceholderAlignment.middle] + final TextBaseline? baseline; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is PlaceholderDimensions + && other.size == size + && other.alignment == alignment + && other.baseline == baseline + && other.baselineOffset == baselineOffset; + } + + @override + int get hashCode => Object.hash(size, alignment, baseline, baselineOffset); + + @override + String toString() { + return switch (alignment) { + ui.PlaceholderAlignment.top || + ui.PlaceholderAlignment.bottom || + ui.PlaceholderAlignment.middle || + ui.PlaceholderAlignment.aboveBaseline || + ui.PlaceholderAlignment.belowBaseline => 'PlaceholderDimensions($size, $alignment)', + ui.PlaceholderAlignment.baseline => 'PlaceholderDimensions($size, $alignment($baselineOffset from top))', + }; + } +} + +/// The different ways of measuring the width of one or more lines of text. +/// +/// See [Text.textWidthBasis], for example. +enum TextWidthBasis { + /// multiline text will take up the full width given by the parent. For single + /// line text, only the minimum amount of width needed to contain the text + /// will be used. A common use case for this is a standard series of + /// paragraphs. + parent, + + /// The width will be exactly enough to contain the longest line and no + /// longer. A common use case for this is chat bubbles. + longestLine, +} + +/// A [TextBoundary] subclass for locating word breaks. +/// +/// The underlying implementation uses [UAX #29](https://unicode.org/reports/tr29/) +/// defined default word boundaries. +/// +/// The default word break rules can be tailored to meet the requirements of +/// different use cases. For instance, the default rule set keeps horizontal +/// whitespaces together as a single word, which may not make sense in a +/// word-counting context -- "hello world" counts as 3 words instead of 2. +/// An example is the [moveByWordBoundary] variant, which is a tailored +/// word-break locator that more closely matches the default behavior of most +/// platforms and editors when it comes to handling text editing keyboard +/// shortcuts that move or delete word by word. +class WordBoundary extends TextBoundary { + /// Creates a [WordBoundary] with the text and layout information. + WordBoundary._(this._text, this._paragraph); + + final InlineSpan _text; + final ui.Paragraph _paragraph; + + @override + TextRange getTextBoundaryAt(int position) => _paragraph.getWordBoundary(TextPosition(offset: max(position, 0))); + + // Combines two UTF-16 code units (high surrogate + low surrogate) into a + // single code point that represents a supplementary character. + static int _codePointFromSurrogates(int highSurrogate, int lowSurrogate) { + assert( + TextPainter.isHighSurrogate(highSurrogate), + 'U+${highSurrogate.toRadixString(16).toUpperCase().padLeft(4, "0")}) is not a high surrogate.', + ); + assert( + TextPainter.isLowSurrogate(lowSurrogate), + 'U+${lowSurrogate.toRadixString(16).toUpperCase().padLeft(4, "0")}) is not a low surrogate.', + ); + const int base = 0x010000 - (0xD800 << 10) - 0xDC00; + return (highSurrogate << 10) + lowSurrogate + base; + } + + // The Runes class does not provide random access with a code unit offset. + int? _codePointAt(int index) { + final int? codeUnitAtIndex = _text.codeUnitAt(index); + if (codeUnitAtIndex == null) { + return null; + } + return switch (codeUnitAtIndex & 0xFC00) { + 0xD800 => _codePointFromSurrogates(codeUnitAtIndex, _text.codeUnitAt(index + 1)!), + 0xDC00 => _codePointFromSurrogates(_text.codeUnitAt(index - 1)!, codeUnitAtIndex), + _ => codeUnitAtIndex, + }; + } + + static bool _isNewline(int codePoint) { + return switch (codePoint) { + 0x000A || 0x0085 || 0x000B || 0x000C || 0x2028 || 0x2029 => true, + _ => false, + }; + } + + bool _skipSpacesAndPunctuations(int offset, bool forward) { + // Use code point since some punctuations are supplementary characters. + // "inner" here refers to the code unit that's before the break in the + // search direction (`forward`). + final int? innerCodePoint = _codePointAt(forward ? offset - 1 : offset); + final int? outerCodeUnit = _text.codeUnitAt(forward ? offset : offset - 1); + + // Make sure the hard break rules in UAX#29 take precedence over the ones we + // add below. Luckily there're only 4 hard break rules for word breaks, and + // dictionary based breaking does not introduce new hard breaks: + // https://unicode-org.github.io/icu/userguide/boundaryanalysis/break-rules.html#word-dictionaries + // + // WB1 & WB2: always break at the start or the end of the text. + final bool hardBreakRulesApply = innerCodePoint == null || outerCodeUnit == null + // WB3a & WB3b: always break before and after newlines. + || _isNewline(innerCodePoint) || _isNewline(outerCodeUnit); + return hardBreakRulesApply || !RegExp(r'[\p{Space_Separator}\p{Punctuation}]', unicode: true).hasMatch(String.fromCharCode(innerCodePoint)); + } + + /// Returns a [TextBoundary] suitable for handling keyboard navigation + /// commands that change the current selection word by word. + /// + /// This [TextBoundary] is used by text widgets in the flutter framework to + /// provide default implementation for text editing shortcuts, for example, + /// "delete to the previous word". + /// + /// The implementation applies the same set of rules [WordBoundary] uses, + /// except that word breaks end on a space separator or a punctuation will be + /// skipped, to match the behavior of most platforms. Additional rules may be + /// added in the future to better match platform behaviors. + late final TextBoundary moveByWordBoundary = _UntilTextBoundary(this, _skipSpacesAndPunctuations); +} + +class _UntilTextBoundary extends TextBoundary { + const _UntilTextBoundary(this._textBoundary, this._predicate); + + final UntilPredicate _predicate; + final TextBoundary _textBoundary; + + @override + int? getLeadingTextBoundaryAt(int position) { + if (position < 0) { + return null; + } + final int? offset = _textBoundary.getLeadingTextBoundaryAt(position); + return offset == null || _predicate(offset, false) + ? offset + : getLeadingTextBoundaryAt(offset - 1); + } + + @override + int? getTrailingTextBoundaryAt(int position) { + final int? offset = _textBoundary.getTrailingTextBoundaryAt(max(position, 0)); + return offset == null || _predicate(offset, true) + ? offset + : getTrailingTextBoundaryAt(offset); + } +} + +class _TextLayout { + _TextLayout._(this._paragraph); + + // This field is not final because the owner TextPainter could create a new + // ui.Paragraph with the exact same text layout (for example, when only the + // color of the text is changed). + // + // The creator of this _TextLayout is also responsible for disposing this + // object when it's no logner needed. + ui.Paragraph _paragraph; + + /// Whether this layout has been invalidated and disposed. + /// + /// Only for use when asserts are enabled. + bool get debugDisposed => _paragraph.debugDisposed; + + /// The horizontal space required to paint this text. + /// + /// If a line ends with trailing spaces, the trailing spaces may extend + /// outside of the horizontal paint bounds defined by [width]. + double get width => _paragraph.width; + + /// The vertical space required to paint this text. + double get height => _paragraph.height; + + /// The width at which decreasing the width of the text would prevent it from + /// painting itself completely within its bounds. + double get minIntrinsicLineExtent => _paragraph.minIntrinsicWidth; + + /// The width at which increasing the width of the text no longer decreases the height. + /// + /// Includes trailing spaces if any. + double get maxIntrinsicLineExtent => _paragraph.maxIntrinsicWidth; + + /// The distance from the left edge of the leftmost glyph to the right edge of + /// the rightmost glyph in the paragraph. + double get longestLine => _paragraph.longestLine; + + /// Returns the distance from the top of the text to the first baseline of the + /// given type. + double getDistanceToBaseline(TextBaseline baseline) { + return switch (baseline) { + TextBaseline.alphabetic => _paragraph.alphabeticBaseline, + TextBaseline.ideographic => _paragraph.ideographicBaseline, + }; + } +} + +// This class stores the current text layout and the corresponding +// paintOffset/contentWidth, as well as some cached text metrics values that +// depends on the current text layout, which will be invalidated as soon as the +// text layout is invalidated. +class _TextPainterLayoutCacheWithOffset { + _TextPainterLayoutCacheWithOffset(this.layout, this.textAlignment, double minWidth, double maxWidth, TextWidthBasis widthBasis) + : contentWidth = _contentWidthFor(minWidth, maxWidth, widthBasis, layout), + assert(textAlignment >= 0.0 && textAlignment <= 1.0); + + final _TextLayout layout; + + // The content width the text painter should report in TextPainter.width. + // This is also used to compute `paintOffset` + double contentWidth; + + // The effective text alignment in the TextPainter's canvas. The value is + // within the [0, 1] interval: 0 for left aligned and 1 for right aligned. + final double textAlignment; + + // The paintOffset of the `paragraph` in the TextPainter's canvas. + // + // It's coordinate values are guaranteed to not be NaN. + Offset get paintOffset { + if (textAlignment == 0) { + return Offset.zero; + } + if (!paragraph.width.isFinite) { + return const Offset(double.infinity, 0.0); + } + final double dx = textAlignment * (contentWidth - paragraph.width); + assert(!dx.isNaN); + return Offset(dx, 0); + } + + ui.Paragraph get paragraph => layout._paragraph; + + static double _contentWidthFor(double minWidth, double maxWidth, TextWidthBasis widthBasis, _TextLayout layout) { + return switch (widthBasis) { + TextWidthBasis.longestLine => clampDouble(layout.longestLine, minWidth, maxWidth), + TextWidthBasis.parent => clampDouble(layout.maxIntrinsicLineExtent, minWidth, maxWidth), + }; + } + + // Try to resize the contentWidth to fit the new input constraints, by just + // adjusting the paint offset (so no line-breaking changes needed). + // + // Returns false if the new constraints require re-computing the line breaks, + // in which case no side effects will occur. + bool _resizeToFit(double minWidth, double maxWidth, TextWidthBasis widthBasis) { + assert(layout.maxIntrinsicLineExtent.isFinite); + // The assumption here is that if a Paragraph's width is already >= its + // maxIntrinsicWidth, further increasing the input width does not change its + // layout (but may change the paint offset if it's not left-aligned). This is + // true even for TextAlign.justify: when width >= maxIntrinsicWidth + // TextAlign.justify will behave exactly the same as TextAlign.start. + // + // An exception to this is when the text is not left-aligned, and the input + // width is double.infinity. Since the resulting Paragraph will have a width + // of double.infinity, and to make the text visible the paintOffset.dx is + // bound to be double.negativeInfinity, which invalidates all arithmetic + // operations. + final double newContentWidth = _contentWidthFor(minWidth, maxWidth, widthBasis, layout); + if (newContentWidth == contentWidth) { + return true; + } + assert(minWidth <= maxWidth); + // Always needsLayout when the current paintOffset and the paragraph width are not finite. + if (!paintOffset.dx.isFinite && !paragraph.width.isFinite && minWidth.isFinite) { + assert(paintOffset.dx == double.infinity); + assert(paragraph.width == double.infinity); + return false; + } + final double maxIntrinsicWidth = paragraph.maxIntrinsicWidth; + if ((paragraph.width - maxIntrinsicWidth) > -precisionErrorTolerance && (maxWidth - maxIntrinsicWidth) > -precisionErrorTolerance) { + // Adjust the paintOffset and contentWidth to the new input constraints. + contentWidth = newContentWidth; + return true; + } + return false; + } + + // ---- Cached Values ---- + + List<TextBox> get inlinePlaceholderBoxes => _cachedInlinePlaceholderBoxes ??= paragraph.getBoxesForPlaceholders(); + List<TextBox>? _cachedInlinePlaceholderBoxes; + + List<ui.LineMetrics> get lineMetrics => _cachedLineMetrics ??= paragraph.computeLineMetrics(); + List<ui.LineMetrics>? _cachedLineMetrics; + + // Holds the TextPosition the last caret metrics were computed with. When new + // values are passed in, we recompute the caret metrics only as necessary. + TextPosition? _previousCaretPosition; +} + +/// This is used to cache and pass the computed metrics regarding the +/// caret's size and position. This is preferred due to the expensive +/// nature of the calculation. +/// +// A _CaretMetrics is either a _LineCaretMetrics or an _EmptyLineCaretMetrics. +@immutable +sealed class _CaretMetrics { } + +/// The _CaretMetrics for carets located in a non-empty line. Carets located in a +/// non-empty line are associated with a glyph within the same line. +final class _LineCaretMetrics implements _CaretMetrics { + const _LineCaretMetrics({required this.offset, required this.writingDirection, required this.fullHeight}); + /// The offset of the top left corner of the caret from the top left + /// corner of the paragraph. + final Offset offset; + /// The writing direction of the glyph the _CaretMetrics is associated with. + final TextDirection writingDirection; + /// The full height of the glyph at the caret position. + final double fullHeight; +} + +/// The _CaretMetrics for carets located in an empty line (when the text is +/// empty, or the caret is between two a newline characters). +final class _EmptyLineCaretMetrics implements _CaretMetrics { + const _EmptyLineCaretMetrics({ required this.lineVerticalOffset }); + + /// The y offset of the unoccupied line. + final double lineVerticalOffset; +} + +const String _flutterPaintingLibrary = 'package:flutter/painting.dart'; + +/// An object that paints a [TextSpan] tree into a [Canvas]. +/// +/// To use a [TextPainter], follow these steps: +/// +/// 1. Create a [TextSpan] tree and pass it to the [TextPainter] +/// constructor. +/// +/// 2. Call [layout] to prepare the paragraph. +/// +/// 3. Call [paint] as often as desired to paint the paragraph. +/// +/// 4. Call [dispose] when the object will no longer be accessed to release +/// native resources. For [TextPainter] objects that are used repeatedly and +/// stored on a [State] or [RenderObject], call [dispose] from +/// [State.dispose] or [RenderObject.dispose] or similar. For [TextPainter] +/// objects that are only used ephemerally, it is safe to immediately dispose +/// them after the last call to methods or properties on the object. +/// +/// If the width of the area into which the text is being painted +/// changes, return to step 2. If the text to be painted changes, +/// return to step 1. +/// +/// The default text style is white. To change the color of the text, +/// pass a [TextStyle] object to the [TextSpan] in `text`. +class TextPainter { + /// Creates a text painter that paints the given text. + /// + /// The `text` and `textDirection` arguments are optional but [text] and + /// [textDirection] must be non-null before calling [layout]. + /// + /// The [maxLines] property, if non-null, must be greater than zero. + TextPainter({ + InlineSpan? text, + TextAlign textAlign = TextAlign.start, + TextDirection? textDirection, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double textScaleFactor = 1.0, + TextScaler textScaler = TextScaler.noScaling, + int? maxLines, + String? ellipsis, + Locale? locale, + StrutStyle? strutStyle, + TextWidthBasis textWidthBasis = TextWidthBasis.parent, + TextHeightBehavior? textHeightBehavior, + }) : assert(text == null || text.debugAssertIsValid()), + assert(maxLines == null || maxLines > 0), + assert(textScaleFactor == 1.0 || identical(textScaler, TextScaler.noScaling), 'Use textScaler instead.'), + _text = text, + _textAlign = textAlign, + _textDirection = textDirection, + _textScaler = textScaler == TextScaler.noScaling ? TextScaler.linear(textScaleFactor) : textScaler, + _maxLines = maxLines, + _ellipsis = ellipsis, + _locale = locale, + _strutStyle = strutStyle, + _textWidthBasis = textWidthBasis, + _textHeightBehavior = textHeightBehavior { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: _flutterPaintingLibrary, + className: '$TextPainter', + object: this, + ); + } + } + + /// Computes the width of a configured [TextPainter]. + /// + /// This is a convenience method that creates a text painter with the supplied + /// parameters, lays it out with the supplied [minWidth] and [maxWidth], and + /// returns its [TextPainter.width] making sure to dispose the underlying + /// resources. Doing this operation is expensive and should be avoided + /// whenever it is possible to preserve the [TextPainter] to paint the + /// text or get other information about it. + static double computeWidth({ + required InlineSpan text, + required TextDirection textDirection, + TextAlign textAlign = TextAlign.start, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double textScaleFactor = 1.0, + TextScaler textScaler = TextScaler.noScaling, + int? maxLines, + String? ellipsis, + Locale? locale, + StrutStyle? strutStyle, + TextWidthBasis textWidthBasis = TextWidthBasis.parent, + TextHeightBehavior? textHeightBehavior, + double minWidth = 0.0, + double maxWidth = double.infinity, + }) { + assert( + textScaleFactor == 1.0 || identical(textScaler, TextScaler.noScaling), + 'Use textScaler instead.', + ); + final TextPainter painter = TextPainter( + text: text, + textAlign: textAlign, + textDirection: textDirection, + textScaler: textScaler == TextScaler.noScaling ? TextScaler.linear(textScaleFactor) : textScaler, + maxLines: maxLines, + ellipsis: ellipsis, + locale: locale, + strutStyle: strutStyle, + textWidthBasis: textWidthBasis, + textHeightBehavior: textHeightBehavior, + )..layout(minWidth: minWidth, maxWidth: maxWidth); + + try { + return painter.width; + } finally { + painter.dispose(); + } + } + + /// Computes the max intrinsic width of a configured [TextPainter]. + /// + /// This is a convenience method that creates a text painter with the supplied + /// parameters, lays it out with the supplied [minWidth] and [maxWidth], and + /// returns its [TextPainter.maxIntrinsicWidth] making sure to dispose the + /// underlying resources. Doing this operation is expensive and should be avoided + /// whenever it is possible to preserve the [TextPainter] to paint the + /// text or get other information about it. + static double computeMaxIntrinsicWidth({ + required InlineSpan text, + required TextDirection textDirection, + TextAlign textAlign = TextAlign.start, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double textScaleFactor = 1.0, + TextScaler textScaler = TextScaler.noScaling, + int? maxLines, + String? ellipsis, + Locale? locale, + StrutStyle? strutStyle, + TextWidthBasis textWidthBasis = TextWidthBasis.parent, + TextHeightBehavior? textHeightBehavior, + double minWidth = 0.0, + double maxWidth = double.infinity, + }) { + assert( + textScaleFactor == 1.0 || identical(textScaler, TextScaler.noScaling), + 'Use textScaler instead.', + ); + final TextPainter painter = TextPainter( + text: text, + textAlign: textAlign, + textDirection: textDirection, + textScaler: textScaler == TextScaler.noScaling ? TextScaler.linear(textScaleFactor) : textScaler, + maxLines: maxLines, + ellipsis: ellipsis, + locale: locale, + strutStyle: strutStyle, + textWidthBasis: textWidthBasis, + textHeightBehavior: textHeightBehavior, + )..layout(minWidth: minWidth, maxWidth: maxWidth); + + try { + return painter.maxIntrinsicWidth; + } finally { + painter.dispose(); + } + } + + // Whether textWidthBasis has changed after the most recent `layout` call. + bool _debugNeedsRelayout = true; + // The result of the most recent `layout` call. + _TextPainterLayoutCacheWithOffset? _layoutCache; + + // Whether _layoutCache contains outdated paint information and needs to be + // updated before painting. + // + // ui.Paragraph is entirely immutable, thus text style changes that can affect + // layout and those who can't both require the ui.Paragraph object being + // recreated. The caller may not call `layout` again after text color is + // updated. See: https://github.com/flutter/flutter/issues/85108 + bool _rebuildParagraphForPaint = true; + // `_layoutCache`'s input width. This is only needed because there's no API to + // create paint only updates that don't affect the text layout (e.g., changing + // the color of the text), on ui.Paragraph or ui.ParagraphBuilder. + double _inputWidth = double.nan; + + bool get _debugAssertTextLayoutIsValid { + assert(!debugDisposed); + if (_layoutCache == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Text layout not available'), + if (_debugMarkNeedsLayoutCallStack != null) DiagnosticsStackTrace('The calls that first invalidated the text layout were', _debugMarkNeedsLayoutCallStack) + else ErrorDescription('The TextPainter has never been laid out.') + ]); + } + return true; + } + + StackTrace? _debugMarkNeedsLayoutCallStack; + + /// Marks this text painter's layout information as dirty and removes cached + /// information. + /// + /// Uses this method to notify text painter to relayout in the case of + /// layout changes in engine. In most cases, updating text painter properties + /// in framework will automatically invoke this method. + void markNeedsLayout() { + assert(() { + if (_layoutCache != null) { + _debugMarkNeedsLayoutCallStack ??= StackTrace.current; + } + return true; + }()); + _layoutCache?.paragraph.dispose(); + _layoutCache = null; + } + + /// The (potentially styled) text to paint. + /// + /// After this is set, you must call [layout] before the next call to [paint]. + /// This and [textDirection] must be non-null before you call [layout]. + /// + /// The [InlineSpan] this provides is in the form of a tree that may contain + /// multiple instances of [TextSpan]s and [WidgetSpan]s. To obtain a plain text + /// representation of the contents of this [TextPainter], use [plainText]. + InlineSpan? get text => _text; + InlineSpan? _text; + set text(InlineSpan? value) { + assert(value == null || value.debugAssertIsValid()); + if (_text == value) { + return; + } + if (_text?.style != value?.style) { + _layoutTemplate?.dispose(); + _layoutTemplate = null; + } + + final RenderComparison comparison = value == null + ? RenderComparison.layout + : _text?.compareTo(value) ?? RenderComparison.layout; + + _text = value; + _cachedPlainText = null; + + if (comparison.index >= RenderComparison.layout.index) { + markNeedsLayout(); + } else if (comparison.index >= RenderComparison.paint.index) { + // Don't invalid the _layoutCache just yet. It still contains valid layout + // information. + _rebuildParagraphForPaint = true; + } + // Neither relayout or repaint is needed. + } + + /// Returns a plain text version of the text to paint. + /// + /// This uses [InlineSpan.toPlainText] to get the full contents of all nodes in the tree. + String get plainText { + _cachedPlainText ??= _text?.toPlainText(includeSemanticsLabels: false); + return _cachedPlainText ?? ''; + } + String? _cachedPlainText; + + /// How the text should be aligned horizontally. + /// + /// After this is set, you must call [layout] before the next call to [paint]. + /// + /// The [textAlign] property defaults to [TextAlign.start]. + TextAlign get textAlign => _textAlign; + TextAlign _textAlign; + set textAlign(TextAlign value) { + if (_textAlign == value) { + return; + } + _textAlign = value; + markNeedsLayout(); + } + + /// The default directionality of the text. + /// + /// This controls how the [TextAlign.start], [TextAlign.end], and + /// [TextAlign.justify] values of [textAlign] are resolved. + /// + /// This is also used to disambiguate how to render bidirectional text. For + /// example, if the [text] is an English phrase followed by a Hebrew phrase, + /// in a [TextDirection.ltr] context the English phrase will be on the left + /// and the Hebrew phrase to its right, while in a [TextDirection.rtl] + /// context, the English phrase will be on the right and the Hebrew phrase on + /// its left. + /// + /// After this is set, you must call [layout] before the next call to [paint]. + /// + /// This and [text] must be non-null before you call [layout]. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsLayout(); + _layoutTemplate?.dispose(); + _layoutTemplate = null; // Shouldn't really matter, but for strict correctness... + } + + /// Deprecated. Will be removed in a future version of Flutter. Use + /// [textScaler] instead. + /// + /// The number of font pixels for each logical pixel. + /// + /// For example, if the text scale factor is 1.5, text will be 50% larger than + /// the specified font size. + /// + /// After this is set, you must call [layout] before the next call to [paint]. + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double get textScaleFactor => textScaler.textScaleFactor; + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + set textScaleFactor(double value) { + textScaler = TextScaler.linear(value); + } + + /// {@template flutter.painting.textPainter.textScaler} + /// The font scaling strategy to use when laying out and rendering the text. + /// + /// The value usually comes from [MediaQuery.textScalerOf], which typically + /// reflects the user-specified text scaling value in the platform's + /// accessibility settings. The [TextStyle.fontSize] of the text will be + /// adjusted by the [TextScaler] before the text is laid out and rendered. + /// {@endtemplate} + /// + /// The [layout] method must be called after [textScaler] changes as it + /// affects the text layout. + TextScaler get textScaler => _textScaler; + TextScaler _textScaler; + set textScaler(TextScaler value) { + if (value == _textScaler) { + return; + } + _textScaler = value; + markNeedsLayout(); + _layoutTemplate?.dispose(); + _layoutTemplate = null; + } + + /// The string used to ellipsize overflowing text. Setting this to a non-empty + /// string will cause this string to be substituted for the remaining text + /// if the text can not fit within the specified maximum width. + /// + /// Specifically, the ellipsis is applied to the last line before the line + /// truncated by [maxLines], if [maxLines] is non-null and that line overflows + /// the width constraint, or to the first line that is wider than the width + /// constraint, if [maxLines] is null. The width constraint is the `maxWidth` + /// passed to [layout]. + /// + /// After this is set, you must call [layout] before the next call to [paint]. + /// + /// The higher layers of the system, such as the [Text] widget, represent + /// overflow effects using the [TextOverflow] enum. The + /// [TextOverflow.ellipsis] value corresponds to setting this property to + /// U+2026 HORIZONTAL ELLIPSIS (…). + String? get ellipsis => _ellipsis; + String? _ellipsis; + set ellipsis(String? value) { + assert(value == null || value.isNotEmpty); + if (_ellipsis == value) { + return; + } + _ellipsis = value; + markNeedsLayout(); + } + + /// The locale used to select region-specific glyphs. + Locale? get locale => _locale; + Locale? _locale; + set locale(Locale? value) { + if (_locale == value) { + return; + } + _locale = value; + markNeedsLayout(); + } + + /// An optional maximum number of lines for the text to span, wrapping if + /// necessary. + /// + /// If the text exceeds the given number of lines, it is truncated such that + /// subsequent lines are dropped. + /// + /// After this is set, you must call [layout] before the next call to [paint]. + int? get maxLines => _maxLines; + int? _maxLines; + /// The value may be null. If it is not null, then it must be greater than zero. + set maxLines(int? value) { + assert(value == null || value > 0); + if (_maxLines == value) { + return; + } + _maxLines = value; + markNeedsLayout(); + } + + /// {@template flutter.painting.textPainter.strutStyle} + /// The strut style to use. Strut style defines the strut, which sets minimum + /// vertical layout metrics. + /// + /// Omitting or providing null will disable strut. + /// + /// Omitting or providing null for any properties of [StrutStyle] will result in + /// default values being used. It is highly recommended to at least specify a + /// [StrutStyle.fontSize]. + /// + /// See [StrutStyle] for details. + /// {@endtemplate} + StrutStyle? get strutStyle => _strutStyle; + StrutStyle? _strutStyle; + set strutStyle(StrutStyle? value) { + if (_strutStyle == value) { + return; + } + _strutStyle = value; + markNeedsLayout(); + } + + /// {@template flutter.painting.textPainter.textWidthBasis} + /// Defines how to measure the width of the rendered text. + /// {@endtemplate} + TextWidthBasis get textWidthBasis => _textWidthBasis; + TextWidthBasis _textWidthBasis; + set textWidthBasis(TextWidthBasis value) { + if (_textWidthBasis == value) { + return; + } + assert(() { return _debugNeedsRelayout = true; }()); + _textWidthBasis = value; + } + + /// {@macro dart.ui.textHeightBehavior} + TextHeightBehavior? get textHeightBehavior => _textHeightBehavior; + TextHeightBehavior? _textHeightBehavior; + set textHeightBehavior(TextHeightBehavior? value) { + if (_textHeightBehavior == value) { + return; + } + _textHeightBehavior = value; + markNeedsLayout(); + } + + /// An ordered list of [TextBox]es that bound the positions of the placeholders + /// in the paragraph. + /// + /// Each box corresponds to a [PlaceholderSpan] in the order they were defined + /// in the [InlineSpan] tree. + List<TextBox>? get inlinePlaceholderBoxes { + final _TextPainterLayoutCacheWithOffset? layout = _layoutCache; + if (layout == null) { + return null; + } + final Offset offset = layout.paintOffset; + if (!offset.dx.isFinite || !offset.dy.isFinite) { + return <TextBox>[]; + } + final List<TextBox> rawBoxes = layout.inlinePlaceholderBoxes; + if (offset == Offset.zero) { + return rawBoxes; + } + return rawBoxes.map((TextBox box) => _shiftTextBox(box, offset)).toList(growable: false); + } + + /// Sets the dimensions of each placeholder in [text]. + /// + /// The number of [PlaceholderDimensions] provided should be the same as the + /// number of [PlaceholderSpan]s in text. Passing in an empty or null `value` + /// will do nothing. + /// + /// If [layout] is attempted without setting the placeholder dimensions, the + /// placeholders will be ignored in the text layout and no valid + /// [inlinePlaceholderBoxes] will be returned. + void setPlaceholderDimensions(List<PlaceholderDimensions>? value) { + if (value == null || value.isEmpty || listEquals(value, _placeholderDimensions)) { + return; + } + assert(() { + int placeholderCount = 0; + text!.visitChildren((InlineSpan span) { + if (span is PlaceholderSpan) { + placeholderCount += 1; + } + return value.length >= placeholderCount; + }); + return placeholderCount == value.length; + }()); + _placeholderDimensions = value; + markNeedsLayout(); + } + List<PlaceholderDimensions>? _placeholderDimensions; + + ui.ParagraphStyle _createParagraphStyle([ TextDirection? defaultTextDirection ]) { + // The defaultTextDirection argument is used for preferredLineHeight in case + // textDirection hasn't yet been set. + assert(textDirection != null || defaultTextDirection != null, 'TextPainter.textDirection must be set to a non-null value before using the TextPainter.'); + return _text!.style?.getParagraphStyle( + textAlign: textAlign, + textDirection: textDirection ?? defaultTextDirection, + textScaler: textScaler, + maxLines: _maxLines, + textHeightBehavior: _textHeightBehavior, + ellipsis: _ellipsis, + locale: _locale, + strutStyle: _strutStyle, + ) ?? ui.ParagraphStyle( + textAlign: textAlign, + textDirection: textDirection ?? defaultTextDirection, + // Use the default font size to multiply by as RichText does not + // perform inheriting [TextStyle]s and would otherwise + // fail to apply textScaler. + fontSize: textScaler.scale(kDefaultFontSize), + maxLines: maxLines, + textHeightBehavior: _textHeightBehavior, + ellipsis: ellipsis, + locale: locale, + ); + } + + ui.Paragraph? _layoutTemplate; + ui.Paragraph _createLayoutTemplate() { + final ui.ParagraphBuilder builder = ui.ParagraphBuilder( + _createParagraphStyle(TextDirection.rtl), + ); // direction doesn't matter, text is just a space + final ui.TextStyle? textStyle = text?.style?.getTextStyle(textScaler: textScaler); + if (textStyle != null) { + builder.pushStyle(textStyle); + } + builder.addText(' '); + return builder.build() + ..layout(const ui.ParagraphConstraints(width: double.infinity)); + } + + /// The height of a space in [text] in logical pixels. + /// + /// Not every line of text in [text] will have this height, but this height + /// is "typical" for text in [text] and useful for sizing other objects + /// relative a typical line of text. + /// + /// Obtaining this value does not require calling [layout]. + /// + /// The style of the [text] property is used to determine the font settings + /// that contribute to the [preferredLineHeight]. If [text] is null or if it + /// specifies no styles, the default [TextStyle] values are used (a 10 pixel + /// sans-serif font). + double get preferredLineHeight => (_layoutTemplate ??= _createLayoutTemplate()).height; + + /// The width at which decreasing the width of the text would prevent it from + /// painting itself completely within its bounds. + /// + /// Valid only after [layout] has been called. + double get minIntrinsicWidth { + assert(_debugAssertTextLayoutIsValid); + return _layoutCache!.layout.minIntrinsicLineExtent; + } + + /// The width at which increasing the width of the text no longer decreases the height. + /// + /// Valid only after [layout] has been called. + double get maxIntrinsicWidth { + assert(_debugAssertTextLayoutIsValid); + return _layoutCache!.layout.maxIntrinsicLineExtent; + } + + /// The horizontal space required to paint this text. + /// + /// Valid only after [layout] has been called. + double get width { + assert(_debugAssertTextLayoutIsValid); + assert(!_debugNeedsRelayout); + return _layoutCache!.contentWidth; + } + + /// The vertical space required to paint this text. + /// + /// Valid only after [layout] has been called. + double get height { + assert(_debugAssertTextLayoutIsValid); + return _layoutCache!.layout.height; + } + + /// The amount of space required to paint this text. + /// + /// Valid only after [layout] has been called. + Size get size { + assert(_debugAssertTextLayoutIsValid); + assert(!_debugNeedsRelayout); + return Size(width, height); + } + + /// Returns the distance from the top of the text to the first baseline of the + /// given type. + /// + /// Valid only after [layout] has been called. + double computeDistanceToActualBaseline(TextBaseline baseline) { + assert(_debugAssertTextLayoutIsValid); + return _layoutCache!.layout.getDistanceToBaseline(baseline); + } + + /// Whether any text was truncated or ellipsized. + /// + /// If [maxLines] is not null, this is true if there were more lines to be + /// drawn than the given [maxLines], and thus at least one line was omitted in + /// the output; otherwise it is false. + /// + /// If [maxLines] is null, this is true if [ellipsis] is not the empty string + /// and there was a line that overflowed the `maxWidth` argument passed to + /// [layout]; otherwise it is false. + /// + /// Valid only after [layout] has been called. + bool get didExceedMaxLines { + assert(_debugAssertTextLayoutIsValid); + return _layoutCache!.paragraph.didExceedMaxLines; + } + + // Creates a ui.Paragraph using the current configurations in this class and + // assign it to _paragraph. + ui.Paragraph _createParagraph(InlineSpan text) { + final ui.ParagraphBuilder builder = ui.ParagraphBuilder(_createParagraphStyle()); + text.build(builder, textScaler: textScaler, dimensions: _placeholderDimensions); + assert(() { + _debugMarkNeedsLayoutCallStack = null; + return true; + }()); + _rebuildParagraphForPaint = false; + return builder.build(); + } + + /// Computes the visual position of the glyphs for painting the text. + /// + /// The text will layout with a width that's as close to its max intrinsic + /// width (or its longest line, if [textWidthBasis] is set to + /// [TextWidthBasis.parent]) as possible while still being greater than or + /// equal to `minWidth` and less than or equal to `maxWidth`. + /// + /// The [text] and [textDirection] properties must be non-null before this is + /// called. + void layout({ double minWidth = 0.0, double maxWidth = double.infinity }) { + assert(!maxWidth.isNaN); + assert(!minWidth.isNaN); + assert(() { + _debugNeedsRelayout = false; + return true; + }()); + + final _TextPainterLayoutCacheWithOffset? cachedLayout = _layoutCache; + if (cachedLayout != null && cachedLayout._resizeToFit(minWidth, maxWidth, textWidthBasis)) { + return; + } + + final InlineSpan? text = this.text; + if (text == null) { + throw StateError('TextPainter.text must be set to a non-null value before using the TextPainter.'); + } + final TextDirection? textDirection = this.textDirection; + if (textDirection == null) { + throw StateError('TextPainter.textDirection must be set to a non-null value before using the TextPainter.'); + } + + final double paintOffsetAlignment = _computePaintOffsetFraction(textAlign, textDirection); + // Try to avoid laying out the paragraph with maxWidth=double.infinity + // when the text is not left-aligned, so we don't have to deal with an + // infinite paint offset. + final bool adjustMaxWidth = !maxWidth.isFinite && paintOffsetAlignment != 0; + final double? adjustedMaxWidth = !adjustMaxWidth ? maxWidth : cachedLayout?.layout.maxIntrinsicLineExtent; + _inputWidth = adjustedMaxWidth ?? maxWidth; + + // Only rebuild the paragraph when there're layout changes, even when + // `_rebuildParagraphForPaint` is true. It's best to not eagerly rebuild + // the paragraph to avoid the extra work, because: + // 1. the text color could change again before `paint` is called (so one of + // the paragraph rebuilds is unnecessary) + // 2. the user could be measuring the text layout so `paint` will never be + // called. + final ui.Paragraph paragraph = (cachedLayout?.paragraph ?? _createParagraph(text)) + ..layout(ui.ParagraphConstraints(width: _inputWidth)); + final _TextPainterLayoutCacheWithOffset newLayoutCache = _TextPainterLayoutCacheWithOffset( + _TextLayout._(paragraph), paintOffsetAlignment, minWidth, maxWidth, textWidthBasis, + ); + // Call layout again if newLayoutCache had an infinite paint offset. + // This is not as expensive as it seems, line breaking is relatively cheap + // as compared to shaping. + if (adjustedMaxWidth == null && minWidth.isFinite) { + assert(maxWidth.isInfinite); + final double newInputWidth = newLayoutCache.layout.maxIntrinsicLineExtent; + paragraph.layout(ui.ParagraphConstraints(width: newInputWidth)); + _inputWidth = newInputWidth; + } + _layoutCache = newLayoutCache; + } + + /// Paints the text onto the given canvas at the given offset. + /// + /// Valid only after [layout] has been called. + /// + /// If you cannot see the text being painted, check that your text color does + /// not conflict with the background on which you are drawing. The default + /// text color is white (to contrast with the default black background color), + /// so if you are writing an application with a white background, the text + /// will not be visible by default. + /// + /// To set the text style, specify a [TextStyle] when creating the [TextSpan] + /// that you pass to the [TextPainter] constructor or to the [text] property. + void paint(Canvas canvas, Offset offset) { + final _TextPainterLayoutCacheWithOffset? layoutCache = _layoutCache; + if (layoutCache == null) { + throw StateError( + 'TextPainter.paint called when text geometry was not yet calculated.\n' + 'Please call layout() before paint() to position the text before painting it.', + ); + } + + if (!layoutCache.paintOffset.dx.isFinite || !layoutCache.paintOffset.dy.isFinite) { + return; + } + + if (_rebuildParagraphForPaint) { + Size? debugSize; + assert(() { + debugSize = size; + return true; + }()); + + final ui.Paragraph paragraph = layoutCache.paragraph; + // Unfortunately even if we know that there is only paint changes, there's + // no API to only make those updates so the paragraph has to be recreated + // and re-laid out. + assert(!_inputWidth.isNaN); + layoutCache.layout._paragraph = _createParagraph(text!)..layout(ui.ParagraphConstraints(width: _inputWidth)); + assert(paragraph.width == layoutCache.layout._paragraph.width); + paragraph.dispose(); + assert(debugSize == size); + } + assert(!_rebuildParagraphForPaint); + canvas.drawParagraph(layoutCache.paragraph, offset + layoutCache.paintOffset); + } + + // Returns true if value falls in the valid range of the UTF16 encoding. + static bool _isUTF16(int value) { + return value >= 0x0 && value <= 0xFFFFF; + } + + /// Returns true iff the given value is a valid UTF-16 high (first) surrogate. + /// The value must be a UTF-16 code unit, meaning it must be in the range + /// 0x0000-0xFFFF. + /// + /// See also: + /// * https://en.wikipedia.org/wiki/UTF-16#Code_points_from_U+010000_to_U+10FFFF + /// * [isLowSurrogate], which checks the same thing for low (second) + /// surrogates. + static bool isHighSurrogate(int value) { + assert(_isUTF16(value)); + return value & 0xFC00 == 0xD800; + } + + /// Returns true iff the given value is a valid UTF-16 low (second) surrogate. + /// The value must be a UTF-16 code unit, meaning it must be in the range + /// 0x0000-0xFFFF. + /// + /// See also: + /// * https://en.wikipedia.org/wiki/UTF-16#Code_points_from_U+010000_to_U+10FFFF + /// * [isHighSurrogate], which checks the same thing for high (first) + /// surrogates. + static bool isLowSurrogate(int value) { + assert(_isUTF16(value)); + return value & 0xFC00 == 0xDC00; + } + + // Checks if the glyph is either [Unicode.RLM] or [Unicode.LRM]. These values take + // up zero space and do not have valid bounding boxes around them. + // + // We do not directly use the [Unicode] constants since they are strings. + static bool _isUnicodeDirectionality(int value) { + return value == 0x200F || value == 0x200E; + } + + /// Returns the closest offset after `offset` at which the input cursor can be + /// positioned. + int? getOffsetAfter(int offset) { + final int? nextCodeUnit = _text!.codeUnitAt(offset); + if (nextCodeUnit == null) { + return null; + } + // TODO(goderbauer): doesn't handle extended grapheme clusters with more than one Unicode scalar value (https://github.com/flutter/flutter/issues/13404). + return isHighSurrogate(nextCodeUnit) ? offset + 2 : offset + 1; + } + + /// Returns the closest offset before `offset` at which the input cursor can + /// be positioned. + int? getOffsetBefore(int offset) { + final int? prevCodeUnit = _text!.codeUnitAt(offset - 1); + if (prevCodeUnit == null) { + return null; + } + // TODO(goderbauer): doesn't handle extended grapheme clusters with more than one Unicode scalar value (https://github.com/flutter/flutter/issues/13404). + return isLowSurrogate(prevCodeUnit) ? offset - 2 : offset - 1; + } + + // Unicode value for a zero width joiner character. + static const int _zwjUtf16 = 0x200d; + + // Get the caret metrics (in logical pixels) based off the near edge of the + // character upstream from the given string offset. + _CaretMetrics? _getMetricsFromUpstream(int offset) { + assert(offset >= 0); + final int plainTextLength = plainText.length; + if (plainTextLength == 0 || offset > plainTextLength) { + return null; + } + final int prevCodeUnit = plainText.codeUnitAt(max(0, offset - 1)); + + // If the upstream character is a newline, cursor is at start of next line + const int NEWLINE_CODE_UNIT = 10; + + // Check for multi-code-unit glyphs such as emojis or zero width joiner. + final bool needsSearch = isHighSurrogate(prevCodeUnit) || isLowSurrogate(prevCodeUnit) || _text!.codeUnitAt(offset) == _zwjUtf16 || _isUnicodeDirectionality(prevCodeUnit); + int graphemeClusterLength = needsSearch ? 2 : 1; + List<TextBox> boxes = <TextBox>[]; + while (boxes.isEmpty) { + final int prevRuneOffset = offset - graphemeClusterLength; + // Use BoxHeightStyle.strut to ensure that the caret's height fits within + // the line's height and is consistent throughout the line. + boxes = _layoutCache!.paragraph.getBoxesForRange(max(0, prevRuneOffset), offset, boxHeightStyle: ui.BoxHeightStyle.strut); + // When the range does not include a full cluster, no boxes will be returned. + if (boxes.isEmpty) { + // When we are at the beginning of the line, a non-surrogate position will + // return empty boxes. We break and try from downstream instead. + if (!needsSearch && prevCodeUnit == NEWLINE_CODE_UNIT) { + break; // Only perform one iteration if no search is required. + } + if (prevRuneOffset < -plainTextLength) { + break; // Stop iterating when beyond the max length of the text. + } + // Multiply by two to log(n) time cover the entire text span. This allows + // faster discovery of very long clusters and reduces the possibility + // of certain large clusters taking much longer than others, which can + // cause jank. + graphemeClusterLength *= 2; + continue; + } + + // Try to identify the box nearest the offset. This logic works when + // there's just one box, and when all boxes have the same direction. + // It may not work in bidi text: https://github.com/flutter/flutter/issues/123424 + final TextBox box = boxes.last.direction == TextDirection.ltr + ? boxes.last : boxes.first; + return prevCodeUnit == NEWLINE_CODE_UNIT + ? _EmptyLineCaretMetrics(lineVerticalOffset: box.bottom) + : _LineCaretMetrics(offset: Offset(box.end, box.top), writingDirection: box.direction, fullHeight: box.bottom - box.top); + } + return null; + } + + // Get the caret metrics (in logical pixels) based off the near edge of the + // character downstream from the given string offset. + _CaretMetrics? _getMetricsFromDownstream(int offset) { + assert(offset >= 0); + final int plainTextLength = plainText.length; + if (plainTextLength == 0) { + return null; + } + // We cap the offset at the final index of plain text. + final int nextCodeUnit = plainText.codeUnitAt(min(offset, plainTextLength - 1)); + + // Check for multi-code-unit glyphs such as emojis or zero width joiner + final bool needsSearch = isHighSurrogate(nextCodeUnit) || isLowSurrogate(nextCodeUnit) || nextCodeUnit == _zwjUtf16 || _isUnicodeDirectionality(nextCodeUnit); + int graphemeClusterLength = needsSearch ? 2 : 1; + List<TextBox> boxes = <TextBox>[]; + while (boxes.isEmpty) { + final int nextRuneOffset = offset + graphemeClusterLength; + // Use BoxHeightStyle.strut to ensure that the caret's height fits within + // the line's height and is consistent throughout the line. + boxes = _layoutCache!.paragraph.getBoxesForRange(offset, nextRuneOffset, boxHeightStyle: ui.BoxHeightStyle.strut); + // When the range does not include a full cluster, no boxes will be returned. + if (boxes.isEmpty) { + // When we are at the end of the line, a non-surrogate position will + // return empty boxes. We break and try from upstream instead. + if (!needsSearch) { + break; // Only perform one iteration if no search is required. + } + if (nextRuneOffset >= plainTextLength << 1) { + break; // Stop iterating when beyond the max length of the text. + } + // Multiply by two to log(n) time cover the entire text span. This allows + // faster discovery of very long clusters and reduces the possibility + // of certain large clusters taking much longer than others, which can + // cause jank. + graphemeClusterLength *= 2; + continue; + } + + // Try to identify the box nearest the offset. This logic works when + // there's just one box, and when all boxes have the same direction. + // It may not work in bidi text: https://github.com/flutter/flutter/issues/123424 + final TextBox box = boxes.first.direction == TextDirection.ltr + ? boxes.first : boxes.last; + return _LineCaretMetrics(offset: Offset(box.start, box.top), writingDirection: box.direction, fullHeight: box.bottom - box.top); + } + return null; + } + + static double _computePaintOffsetFraction(TextAlign textAlign, TextDirection textDirection) { + return switch ((textAlign, textDirection)) { + (TextAlign.left, _) => 0.0, + (TextAlign.right, _) => 1.0, + (TextAlign.center, _) => 0.5, + (TextAlign.start, TextDirection.ltr) => 0.0, + (TextAlign.start, TextDirection.rtl) => 1.0, + (TextAlign.justify, TextDirection.ltr) => 0.0, + (TextAlign.justify, TextDirection.rtl) => 1.0, + (TextAlign.end, TextDirection.ltr) => 1.0, + (TextAlign.end, TextDirection.rtl) => 0.0, + }; + } + + /// Returns the offset at which to paint the caret. + /// + /// Valid only after [layout] has been called. + Offset getOffsetForCaret(TextPosition position, Rect caretPrototype) { + final _CaretMetrics caretMetrics; + final _TextPainterLayoutCacheWithOffset layoutCache = _layoutCache!; + if (position.offset < 0) { + // TODO(LongCatIsLooong): make this case impossible; see https://github.com/flutter/flutter/issues/79495 + caretMetrics = const _EmptyLineCaretMetrics(lineVerticalOffset: 0); + } else { + caretMetrics = _computeCaretMetrics(position); + } + + final Offset rawOffset; + switch (caretMetrics) { + case _EmptyLineCaretMetrics(:final double lineVerticalOffset): + final double paintOffsetAlignment = _computePaintOffsetFraction(textAlign, textDirection!); + // The full width is not (width - caretPrototype.width) + // because RenderEditable reserves cursor width on the right. Ideally this + // should be handled by RenderEditable instead. + final double dx = paintOffsetAlignment == 0 ? 0 : paintOffsetAlignment * layoutCache.contentWidth; + return Offset(dx, lineVerticalOffset); + case _LineCaretMetrics(writingDirection: TextDirection.ltr, :final Offset offset): + rawOffset = offset; + case _LineCaretMetrics(writingDirection: TextDirection.rtl, :final Offset offset): + rawOffset = Offset(offset.dx - caretPrototype.width, offset.dy); + } + // If offset.dx is outside of the advertised content area, then the associated + // glyph cluster belongs to a trailing newline character. Ideally the behavior + // should be handled by higher-level implementations (for instance, + // RenderEditable reserves width for showing the caret, it's best to handle + // the clamping there). + final double adjustedDx = clampDouble(rawOffset.dx + layoutCache.paintOffset.dx, 0, layoutCache.contentWidth); + return Offset(adjustedDx, rawOffset.dy + layoutCache.paintOffset.dy); + } + + /// {@template flutter.painting.textPainter.getFullHeightForCaret} + /// Returns the strut bounded height of the glyph at the given `position`. + /// {@endtemplate} + /// + /// Valid only after [layout] has been called. + double? getFullHeightForCaret(TextPosition position, Rect caretPrototype) { + if (position.offset < 0) { + // TODO(LongCatIsLooong): make this case impossible; see https://github.com/flutter/flutter/issues/79495 + return null; + } + return switch (_computeCaretMetrics(position)) { + _LineCaretMetrics(:final double fullHeight) => fullHeight, + _EmptyLineCaretMetrics() => null, + }; + } + + // Cached caret metrics. This allows multiple invokes of [getOffsetForCaret] and + // [getFullHeightForCaret] in a row without performing redundant and expensive + // get rect calls to the paragraph. + late _CaretMetrics _caretMetrics; + + // Checks if the [position] and [caretPrototype] have changed from the cached + // version and recomputes the metrics required to position the caret. + _CaretMetrics _computeCaretMetrics(TextPosition position) { + assert(_debugAssertTextLayoutIsValid); + assert(!_debugNeedsRelayout); + final _TextPainterLayoutCacheWithOffset cachedLayout = _layoutCache!; + if (position == cachedLayout._previousCaretPosition) { + return _caretMetrics; + } + final int offset = position.offset; + final _CaretMetrics? metrics = switch (position.affinity) { + TextAffinity.upstream => _getMetricsFromUpstream(offset) ?? _getMetricsFromDownstream(offset), + TextAffinity.downstream => _getMetricsFromDownstream(offset) ?? _getMetricsFromUpstream(offset), + }; + // Cache the input parameters to prevent repeat work later. + cachedLayout._previousCaretPosition = position; + return _caretMetrics = metrics ?? const _EmptyLineCaretMetrics(lineVerticalOffset: 0); + } + + /// Returns a list of rects that bound the given selection. + /// + /// The [selection] must be a valid range (with [TextSelection.isValid] true). + /// + /// The [boxHeightStyle] and [boxWidthStyle] arguments may be used to select + /// the shape of the [TextBox]s. These properties default to + /// [ui.BoxHeightStyle.tight] and [ui.BoxWidthStyle.tight] respectively. + /// + /// A given selection might have more than one rect if this text painter + /// contains bidirectional text because logically contiguous text might not be + /// visually contiguous. + /// + /// Leading or trailing newline characters will be represented by zero-width + /// `TextBox`es. + /// + /// The method only returns `TextBox`es of glyphs that are entirely enclosed by + /// the given `selection`: a multi-code-unit glyph will be excluded if only + /// part of its code units are in `selection`. + List<TextBox> getBoxesForSelection( + TextSelection selection, { + ui.BoxHeightStyle boxHeightStyle = ui.BoxHeightStyle.tight, + ui.BoxWidthStyle boxWidthStyle = ui.BoxWidthStyle.tight, + }) { + assert(_debugAssertTextLayoutIsValid); + assert(selection.isValid); + assert(!_debugNeedsRelayout); + final _TextPainterLayoutCacheWithOffset cachedLayout = _layoutCache!; + final Offset offset = cachedLayout.paintOffset; + if (!offset.dx.isFinite || !offset.dy.isFinite) { + return <TextBox>[]; + } + final List<TextBox> boxes = cachedLayout.paragraph.getBoxesForRange( + selection.start, + selection.end, + boxHeightStyle: boxHeightStyle, + boxWidthStyle: boxWidthStyle, + ); + return offset == Offset.zero + ? boxes + : boxes.map((TextBox box) => _shiftTextBox(box, offset)).toList(growable: false); + } + + /// Returns the [GlyphInfo] of the glyph closest to the given `offset` in the + /// paragraph coordinate system, or null if the text is empty, or is entirely + /// clipped or ellipsized away. + /// + /// This method first finds the line closest to `offset.dy`, and then returns + /// the [GlyphInfo] of the closest glyph(s) within that line. + ui.GlyphInfo? getClosestGlyphForOffset(Offset offset) { + assert(_debugAssertTextLayoutIsValid); + assert(!_debugNeedsRelayout); + final _TextPainterLayoutCacheWithOffset cachedLayout = _layoutCache!; + final ui.GlyphInfo? rawGlyphInfo = cachedLayout.paragraph.getClosestGlyphInfoForOffset(offset - cachedLayout.paintOffset); + if (rawGlyphInfo == null || cachedLayout.paintOffset == Offset.zero) { + return rawGlyphInfo; + } + return ui.GlyphInfo(rawGlyphInfo.graphemeClusterLayoutBounds.shift(cachedLayout.paintOffset), rawGlyphInfo.graphemeClusterCodeUnitRange, rawGlyphInfo.writingDirection); + } + + /// Returns the closest position within the text for the given pixel offset. + TextPosition getPositionForOffset(Offset offset) { + assert(_debugAssertTextLayoutIsValid); + assert(!_debugNeedsRelayout); + final _TextPainterLayoutCacheWithOffset cachedLayout = _layoutCache!; + return cachedLayout.paragraph.getPositionForOffset(offset - cachedLayout.paintOffset); + } + + /// {@template flutter.painting.TextPainter.getWordBoundary} + /// Returns the text range of the word at the given offset. Characters not + /// part of a word, such as spaces, symbols, and punctuation, have word breaks + /// on both sides. In such cases, this method will return a text range that + /// contains the given text position. + /// + /// Word boundaries are defined more precisely in Unicode Standard Annex #29 + /// <http://www.unicode.org/reports/tr29/#Word_Boundaries>. + /// {@endtemplate} + TextRange getWordBoundary(TextPosition position) { + assert(_debugAssertTextLayoutIsValid); + return _layoutCache!.paragraph.getWordBoundary(position); + } + + /// {@template flutter.painting.TextPainter.wordBoundaries} + /// Returns a [TextBoundary] that can be used to perform word boundary analysis + /// on the current [text]. + /// + /// This [TextBoundary] uses word boundary rules defined in [Unicode Standard + /// Annex #29](http://www.unicode.org/reports/tr29/#Word_Boundaries). + /// {@endtemplate} + /// + /// Currently word boundary analysis can only be performed after [layout] + /// has been called. + WordBoundary get wordBoundaries => WordBoundary._(text!, _layoutCache!.paragraph); + + /// Returns the text range of the line at the given offset. + /// + /// The newline (if any) is not returned as part of the range. + TextRange getLineBoundary(TextPosition position) { + assert(_debugAssertTextLayoutIsValid); + return _layoutCache!.paragraph.getLineBoundary(position); + } + + static ui.LineMetrics _shiftLineMetrics(ui.LineMetrics metrics, Offset offset) { + assert(offset.dx.isFinite); + assert(offset.dy.isFinite); + return ui.LineMetrics( + hardBreak: metrics.hardBreak, + ascent: metrics.ascent, + descent: metrics.descent, + unscaledAscent: metrics.unscaledAscent, + height: metrics.height, + width: metrics.width, + left: metrics.left + offset.dx, + baseline: metrics.baseline + offset.dy, + lineNumber: metrics.lineNumber, + ); + } + + static TextBox _shiftTextBox(TextBox box, Offset offset) { + assert(offset.dx.isFinite); + assert(offset.dy.isFinite); + return TextBox.fromLTRBD( + box.left + offset.dx, + box.top + offset.dy, + box.right + offset.dx, + box.bottom + offset.dy, + box.direction, + ); + } + + /// Returns the full list of [LineMetrics] that describe in detail the various + /// metrics of each laid out line. + /// + /// The [LineMetrics] list is presented in the order of the lines they represent. + /// For example, the first line is in the zeroth index. + /// + /// [LineMetrics] contains measurements such as ascent, descent, baseline, and + /// width for the line as a whole, and may be useful for aligning additional + /// widgets to a particular line. + /// + /// Valid only after [layout] has been called. + List<ui.LineMetrics> computeLineMetrics() { + assert(_debugAssertTextLayoutIsValid); + assert(!_debugNeedsRelayout); + final _TextPainterLayoutCacheWithOffset layout = _layoutCache!; + final Offset offset = layout.paintOffset; + if (!offset.dx.isFinite || !offset.dy.isFinite) { + return const <ui.LineMetrics>[]; + } + final List<ui.LineMetrics> rawMetrics = layout.lineMetrics; + return offset == Offset.zero + ? rawMetrics + : rawMetrics.map((ui.LineMetrics metrics) => _shiftLineMetrics(metrics, offset)).toList(growable: false); + } + + bool _disposed = false; + + /// Whether this object has been disposed or not. + /// + /// Only for use when asserts are enabled. + bool get debugDisposed { + bool? disposed; + assert(() { + disposed = _disposed; + return true; + }()); + return disposed ?? (throw StateError('debugDisposed only available when asserts are on.')); + } + + /// Releases the resources associated with this painter. + /// + /// After disposal this painter is unusable. + void dispose() { + assert(() { + _disposed = true; + return true; + }()); + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _layoutTemplate?.dispose(); + _layoutTemplate = null; + _layoutCache?.paragraph.dispose(); + _layoutCache = null; + _text = null; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_scaler.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_scaler.dart new file mode 100644 index 0000000000000000000000000000000000000000..554cfb892fa5a58d827ab6842d1de39c35ae11ab --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_scaler.dart @@ -0,0 +1,151 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' show max, min; + +import 'package:flutter/foundation.dart'; + +/// A class that describes how textual contents should be scaled for better +/// readability. +/// +/// The [scale] function computes the scaled font size given the original +/// unscaled font size specified by app developers. +/// +/// The [==] operator defines the equality of 2 [TextScaler]s, which the +/// framework uses to determine whether text widgets should rebuild when their +/// [TextScaler] changes. Consider overridding the [==] operator if applicable +/// to avoid unnecessary rebuilds. +@immutable +abstract class TextScaler { + /// Creates a TextScaler. + const TextScaler(); + + /// Creates a proportional [TextScaler] that scales the incoming font size by + /// multiplying it with the given `textScaleFactor`. + const factory TextScaler.linear(double textScaleFactor) = _LinearTextScaler; + + /// A [TextScaler] that doesn't scale the input font size. + /// + /// This is equivalent to `TextScaler.linear(1.0)`, the [TextScaler.scale] + /// implementation always returns the input font size as-is. + static const TextScaler noScaling = _LinearTextScaler(1.0); + + /// Computes the scaled font size (in logical pixels) with the given unscaled + /// `fontSize` (in logical pixels). + /// + /// The input `fontSize` must be finite and non-negative. + /// + /// When given the same `fontSize` input, this method returns the same value. + /// The output of a larger input `fontSize` is typically larger than that of a + /// smaller input, but on unusual occasions they may produce the same output. + /// For example, some platforms use single-precision floats to represent font + /// sizes, as a result of truncation two different unscaled font sizes can be + /// scaled to the same value. + double scale(double fontSize); + + /// The estimated number of font pixels for each logical pixel. This property + /// exists only for backward compatibility purposes, and will be removed in + /// a future version of Flutter. + /// + /// The value of this property is only an estimate, so it may not reflect the + /// exact text scaling strategy this [TextScaler] represents, especially when + /// this [TextScaler] is not linear. Consider using [TextScaler.scale] instead. + @Deprecated( + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double get textScaleFactor; + + /// Returns a new [TextScaler] that restricts the scaled font size to within + /// the range `[minScaleFactor * fontSize, maxScaleFactor * fontSize]`. + TextScaler clamp({ double minScaleFactor = 0, double maxScaleFactor = double.infinity }) { + assert(maxScaleFactor >= minScaleFactor); + assert(!maxScaleFactor.isNaN); + assert(minScaleFactor.isFinite); + assert(minScaleFactor >= 0); + + return minScaleFactor == maxScaleFactor + ? TextScaler.linear(minScaleFactor) + : _ClampedTextScaler(this, minScaleFactor, maxScaleFactor); + } +} + +final class _LinearTextScaler implements TextScaler { + const _LinearTextScaler(this.textScaleFactor) : assert(textScaleFactor >= 0); + + @override + final double textScaleFactor; + + @override + double scale(double fontSize) { + assert(fontSize >= 0); + assert(fontSize.isFinite); + return fontSize * textScaleFactor; + } + + @override + TextScaler clamp({ double minScaleFactor = 0, double maxScaleFactor = double.infinity }) { + assert(maxScaleFactor >= minScaleFactor); + assert(!maxScaleFactor.isNaN); + assert(minScaleFactor.isFinite); + assert(minScaleFactor >= 0); + + final double newScaleFactor = clampDouble(textScaleFactor, minScaleFactor, maxScaleFactor); + return newScaleFactor == textScaleFactor ? this : _LinearTextScaler(newScaleFactor); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is _LinearTextScaler && other.textScaleFactor == textScaleFactor; + } + + @override + int get hashCode => textScaleFactor.hashCode; + + @override + String toString() => textScaleFactor == 1.0 ? 'no scaling' : 'linear (${textScaleFactor}x)'; +} + +final class _ClampedTextScaler implements TextScaler { + const _ClampedTextScaler(this.scaler, this.minScale, this.maxScale) : assert(maxScale > minScale); + final TextScaler scaler; + final double minScale; + final double maxScale; + + @override + double get textScaleFactor => clampDouble(scaler.textScaleFactor, minScale, maxScale); + + @override + double scale(double fontSize) { + assert(fontSize >= 0); + assert(fontSize.isFinite); + return minScale == maxScale + ? minScale * fontSize + : clampDouble(scaler.scale(fontSize), minScale * fontSize, maxScale * fontSize); + } + + @override + TextScaler clamp({ double minScaleFactor = 0, double maxScaleFactor = double.infinity }) { + return minScaleFactor == maxScaleFactor + ? _LinearTextScaler(minScaleFactor) + : _ClampedTextScaler(scaler, max(minScaleFactor, minScale), min(maxScaleFactor, maxScale)); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is _ClampedTextScaler + && minScale == other.minScale + && maxScale == other.maxScale + && (minScale == maxScale || scaler == other.scaler); + } + + @override + int get hashCode => minScale == maxScale ? minScale.hashCode : Object.hash(scaler, minScale, maxScale); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_span.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_span.dart new file mode 100644 index 0000000000000000000000000000000000000000..2b6f2bbc6f6946f600832236a4cccae2e14141ce --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_span.dart @@ -0,0 +1,576 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show Locale, LocaleStringAttribute, ParagraphBuilder, SpellOutStringAttribute, StringAttribute; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/services.dart'; + +import 'basic_types.dart'; +import 'inline_span.dart'; +import 'text_painter.dart'; +import 'text_scaler.dart'; + +// Examples can assume: +// late TextSpan myTextSpan; + +/// An immutable span of text. +/// +/// A [TextSpan] object can be styled using its [style] property. The style will +/// be applied to the [text] and the [children]. +/// +/// A [TextSpan] object can just have plain text, or it can have children +/// [TextSpan] objects with their own styles that (possibly only partially) +/// override the [style] of this object. If a [TextSpan] has both [text] and +/// [children], then the [text] is treated as if it was an un-styled [TextSpan] +/// at the start of the [children] list. Leaving the [TextSpan.text] field null +/// results in the [TextSpan] acting as an empty node in the [InlineSpan] tree +/// with a list of children. +/// +/// To paint a [TextSpan] on a [Canvas], use a [TextPainter]. To display a text +/// span in a widget, use a [RichText]. For text with a single style, consider +/// using the [Text] widget. +/// +/// {@tool snippet} +/// +/// The text "Hello world!", in black: +/// +/// ```dart +/// const TextSpan( +/// text: 'Hello world!', +/// style: TextStyle(color: Colors.black), +/// ) +/// ``` +/// {@end-tool} +/// +/// _There is some more detailed sample code in the documentation for the +/// [recognizer] property._ +/// +/// The [TextSpan.text] will be used as the semantics label unless overridden +/// by the [TextSpan.semanticsLabel] property. Any [PlaceholderSpan]s in the +/// [TextSpan.children] list will separate the text before and after it into two +/// semantics nodes. +/// +/// See also: +/// +/// * [WidgetSpan], a leaf node that represents an embedded inline widget in an +/// [InlineSpan] tree. Specify a widget within the [children] list by +/// wrapping the widget with a [WidgetSpan]. The widget will be laid out +/// inline within the paragraph. +/// * [Text], a widget for showing uniformly-styled text. +/// * [RichText], a widget for finer control of text rendering. +/// * [TextPainter], a class for painting [TextSpan] objects on a [Canvas]. +@immutable +class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotation { + /// Creates a [TextSpan] with the given values. + /// + /// For the object to be useful, at least one of [text] or + /// [children] should be set. + const TextSpan({ + this.text, + this.children, + super.style, + this.recognizer, + MouseCursor? mouseCursor, + this.onEnter, + this.onExit, + this.semanticsLabel, + this.locale, + this.spellOut, + }) : mouseCursor = mouseCursor ?? + (recognizer == null ? MouseCursor.defer : SystemMouseCursors.click), + assert(!(text == null && semanticsLabel != null)); + + /// The text contained in this span. + /// + /// If both [text] and [children] are non-null, the text will precede the + /// children. + /// + /// This getter does not include the contents of its children. + final String? text; + + /// Additional spans to include as children. + /// + /// If both [text] and [children] are non-null, the text will precede the + /// children. + /// + /// Modifying the list after the [TextSpan] has been created is not supported + /// and may have unexpected results. + /// + /// The list must not contain any nulls. + final List<InlineSpan>? children; + + /// A gesture recognizer that will receive events that hit this span. + /// + /// [InlineSpan] itself does not implement hit testing or event dispatch. The + /// object that manages the [InlineSpan] painting is also responsible for + /// dispatching events. In the rendering library, that is the + /// [RenderParagraph] object, which corresponds to the [RichText] widget in + /// the widgets layer; these objects do not bubble events in [InlineSpan]s, + /// so a [recognizer] is only effective for events that directly hit the + /// [text] of that [InlineSpan], not any of its [children]. + /// + /// [InlineSpan] also does not manage the lifetime of the gesture recognizer. + /// The code that owns the [GestureRecognizer] object must call + /// [GestureRecognizer.dispose] when the [InlineSpan] object is no longer + /// used. + /// + /// {@tool snippet} + /// + /// This example shows how to manage the lifetime of a gesture recognizer + /// provided to an [InlineSpan] object. It defines a `BuzzingText` widget + /// which uses the [HapticFeedback] class to vibrate the device when the user + /// long-presses the "find the" span, which is underlined in wavy green. The + /// hit-testing is handled by the [RichText] widget. It also changes the + /// hovering mouse cursor to `precise`. + /// + /// ```dart + /// class BuzzingText extends StatefulWidget { + /// const BuzzingText({super.key}); + /// + /// @override + /// State<BuzzingText> createState() => _BuzzingTextState(); + /// } + /// + /// class _BuzzingTextState extends State<BuzzingText> { + /// late LongPressGestureRecognizer _longPressRecognizer; + /// + /// @override + /// void initState() { + /// super.initState(); + /// _longPressRecognizer = LongPressGestureRecognizer() + /// ..onLongPress = _handlePress; + /// } + /// + /// @override + /// void dispose() { + /// _longPressRecognizer.dispose(); + /// super.dispose(); + /// } + /// + /// void _handlePress() { + /// HapticFeedback.vibrate(); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// return Text.rich( + /// TextSpan( + /// text: 'Can you ', + /// style: const TextStyle(color: Colors.black), + /// children: <InlineSpan>[ + /// TextSpan( + /// text: 'find the', + /// style: const TextStyle( + /// color: Colors.green, + /// decoration: TextDecoration.underline, + /// decorationStyle: TextDecorationStyle.wavy, + /// ), + /// recognizer: _longPressRecognizer, + /// mouseCursor: SystemMouseCursors.precise, + /// ), + /// const TextSpan( + /// text: ' secret?', + /// ), + /// ], + /// ), + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + final GestureRecognizer? recognizer; + + /// Mouse cursor when the mouse hovers over this span. + /// + /// The default value is [SystemMouseCursors.click] if [recognizer] is not + /// null, or [MouseCursor.defer] otherwise. + /// + /// [TextSpan] itself does not implement hit testing or cursor changing. + /// The object that manages the [TextSpan] painting is responsible + /// to return the [TextSpan] in its hit test, as well as providing the + /// correct mouse cursor when the [TextSpan]'s mouse cursor is + /// [MouseCursor.defer]. + final MouseCursor mouseCursor; + + @override + final PointerEnterEventListener? onEnter; + + @override + final PointerExitEventListener? onExit; + + /// Returns the value of [mouseCursor]. + /// + /// This field, required by [MouseTrackerAnnotation], is hidden publicly to + /// avoid the confusion as a text cursor. + @protected + @override + MouseCursor get cursor => mouseCursor; + + /// An alternative semantics label for this [TextSpan]. + /// + /// If present, the semantics of this span will contain this value instead + /// of the actual text. + /// + /// This is useful for replacing abbreviations or shorthands with the full + /// text value: + /// + /// ```dart + /// const TextSpan(text: r'$$', semanticsLabel: 'Double dollars') + /// ``` + final String? semanticsLabel; + + /// The language of the text in this span and its span children. + /// + /// Setting the locale of this text span affects the way that assistive + /// technologies, such as VoiceOver or TalkBack, pronounce the text. + /// + /// If this span contains other text span children, they also inherit the + /// locale from this span unless explicitly set to different locales. + final ui.Locale? locale; + + /// Whether the assistive technologies should spell out this text character + /// by character. + /// + /// If the text is 'hello world', setting this to true causes the assistive + /// technologies, such as VoiceOver or TalkBack, to pronounce + /// 'h-e-l-l-o-space-w-o-r-l-d' instead of complete words. This is useful for + /// texts, such as passwords or verification codes. + /// + /// If this span contains other text span children, they also inherit the + /// property from this span unless explicitly set. + /// + /// If the property is not set, this text span inherits the spell out setting + /// from its parent. If this text span does not have a parent or the parent + /// does not have a spell out setting, this text span does not spell out the + /// text by default. + final bool? spellOut; + + @override + bool get validForMouseTracker => true; + + @override + void handleEvent(PointerEvent event, HitTestEntry entry) { + if (event is PointerDownEvent) { + recognizer?.addPointer(event); + } + } + + /// Apply the [style], [text], and [children] of this object to the + /// given [ParagraphBuilder], from which a [Paragraph] can be obtained. + /// [Paragraph] objects can be drawn on [Canvas] objects. + /// + /// Rather than using this directly, it's simpler to use the + /// [TextPainter] class to paint [TextSpan] objects onto [Canvas] + /// objects. + @override + void build( + ui.ParagraphBuilder builder, { + TextScaler textScaler = TextScaler.noScaling, + List<PlaceholderDimensions>? dimensions, + }) { + assert(debugAssertIsValid()); + final bool hasStyle = style != null; + if (hasStyle) { + builder.pushStyle(style!.getTextStyle(textScaler: textScaler)); + } + if (text != null) { + try { + builder.addText(text!); + } on ArgumentError catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'painting library', + context: ErrorDescription('while building a TextSpan'), + silent: true, + )); + // Use a Unicode replacement character as a substitute for invalid text. + builder.addText('\uFFFD'); + } + } + final List<InlineSpan>? children = this.children; + if (children != null) { + for (final InlineSpan child in children) { + child.build( + builder, + textScaler: textScaler, + dimensions: dimensions, + ); + } + } + if (hasStyle) { + builder.pop(); + } + } + + /// Walks this [TextSpan] and its descendants in pre-order and calls [visitor] + /// for each span that has text. + /// + /// When `visitor` returns true, the walk will continue. When `visitor` + /// returns false, then the walk will end. + @override + bool visitChildren(InlineSpanVisitor visitor) { + if (text != null && !visitor(this)) { + return false; + } + final List<InlineSpan>? children = this.children; + if (children != null) { + for (final InlineSpan child in children) { + if (!child.visitChildren(visitor)) { + return false; + } + } + } + return true; + } + + @override + bool visitDirectChildren(InlineSpanVisitor visitor) { + final List<InlineSpan>? children = this.children; + if (children != null) { + for (final InlineSpan child in children) { + if (!visitor(child)) { + return false; + } + } + } + return true; + } + + /// Returns the text span that contains the given position in the text. + @override + InlineSpan? getSpanForPositionVisitor(TextPosition position, Accumulator offset) { + final String? text = this.text; + if (text == null || text.isEmpty) { + return null; + } + final TextAffinity affinity = position.affinity; + final int targetOffset = position.offset; + final int endOffset = offset.value + text.length; + + if (offset.value == targetOffset && affinity == TextAffinity.downstream || + offset.value < targetOffset && targetOffset < endOffset || + endOffset == targetOffset && affinity == TextAffinity.upstream) { + return this; + } + offset.increment(text.length); + return null; + } + + @override + void computeToPlainText( + StringBuffer buffer, { + bool includeSemanticsLabels = true, + bool includePlaceholders = true, + }) { + assert(debugAssertIsValid()); + if (semanticsLabel != null && includeSemanticsLabels) { + buffer.write(semanticsLabel); + } else if (text != null) { + buffer.write(text); + } + if (children != null) { + for (final InlineSpan child in children!) { + child.computeToPlainText(buffer, + includeSemanticsLabels: includeSemanticsLabels, + includePlaceholders: includePlaceholders, + ); + } + } + } + + @override + void computeSemanticsInformation( + List<InlineSpanSemanticsInformation> collector, { + ui.Locale? inheritedLocale, + bool inheritedSpellOut = false, + }) { + assert(debugAssertIsValid()); + final ui.Locale? effectiveLocale = locale ?? inheritedLocale; + final bool effectiveSpellOut = spellOut ?? inheritedSpellOut; + + if (text != null) { + final int textLength = semanticsLabel?.length ?? text!.length; + collector.add(InlineSpanSemanticsInformation( + text!, + stringAttributes: <ui.StringAttribute>[ + if (effectiveSpellOut && textLength > 0) + ui.SpellOutStringAttribute(range: TextRange(start: 0, end: textLength)), + if (effectiveLocale != null && textLength > 0) + ui.LocaleStringAttribute(locale: effectiveLocale, range: TextRange(start: 0, end: textLength)), + ], + semanticsLabel: semanticsLabel, + recognizer: recognizer, + )); + } + final List<InlineSpan>? children = this.children; + if (children != null) { + for (final InlineSpan child in children) { + if (child is TextSpan) { + child.computeSemanticsInformation( + collector, + inheritedLocale: effectiveLocale, + inheritedSpellOut: effectiveSpellOut, + ); + } else { + child.computeSemanticsInformation(collector); + } + } + } + } + + @override + int? codeUnitAtVisitor(int index, Accumulator offset) { + final String? text = this.text; + if (text == null) { + return null; + } + final int localOffset = index - offset.value; + assert(localOffset >= 0); + offset.increment(text.length); + return localOffset < text.length ? text.codeUnitAt(localOffset) : null; + } + + /// In debug mode, throws an exception if the object is not in a valid + /// configuration. Otherwise, returns true. + /// + /// This is intended to be used as follows: + /// + /// ```dart + /// assert(myTextSpan.debugAssertIsValid()); + /// ``` + @override + bool debugAssertIsValid() { + assert(() { + if (children != null) { + for (final InlineSpan child in children!) { + assert(child.debugAssertIsValid()); + } + } + return true; + }()); + return super.debugAssertIsValid(); + } + + @override + RenderComparison compareTo(InlineSpan other) { + if (identical(this, other)) { + return RenderComparison.identical; + } + if (other.runtimeType != runtimeType) { + return RenderComparison.layout; + } + final TextSpan textSpan = other as TextSpan; + if (textSpan.text != text || + children?.length != textSpan.children?.length || + (style == null) != (textSpan.style == null)) { + return RenderComparison.layout; + } + RenderComparison result = recognizer == textSpan.recognizer ? + RenderComparison.identical : + RenderComparison.metadata; + if (style != null) { + final RenderComparison candidate = style!.compareTo(textSpan.style!); + if (candidate.index > result.index) { + result = candidate; + } + if (result == RenderComparison.layout) { + return result; + } + } + if (children != null) { + for (int index = 0; index < children!.length; index += 1) { + final RenderComparison candidate = children![index].compareTo(textSpan.children![index]); + if (candidate.index > result.index) { + result = candidate; + } + if (result == RenderComparison.layout) { + return result; + } + } + } + return result; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + if (super != other) { + return false; + } + return other is TextSpan + && other.text == text + && other.recognizer == recognizer + && other.semanticsLabel == semanticsLabel + && onEnter == other.onEnter + && onExit == other.onExit + && mouseCursor == other.mouseCursor + && listEquals<InlineSpan>(other.children, children); + } + + @override + int get hashCode => Object.hash( + super.hashCode, + text, + recognizer, + semanticsLabel, + onEnter, + onExit, + mouseCursor, + children == null ? null : Object.hashAll(children!), + ); + + @override + String toStringShort() => objectRuntimeType(this, 'TextSpan'); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + + properties.add( + StringProperty( + 'text', + text, + showName: false, + defaultValue: null, + ), + ); + if (style == null && text == null && children == null) { + properties.add(DiagnosticsNode.message('(empty)')); + } + + properties.add(DiagnosticsProperty<GestureRecognizer>( + 'recognizer', recognizer, + description: recognizer?.runtimeType.toString(), + defaultValue: null, + )); + + properties.add(FlagsSummary<Function?>( + 'callbacks', + <String, Function?> { + 'enter': onEnter, + 'exit': onExit, + }, + )); + properties.add(DiagnosticsProperty<MouseCursor>('mouseCursor', cursor, defaultValue: MouseCursor.defer)); + + if (semanticsLabel != null) { + properties.add(StringProperty('semanticsLabel', semanticsLabel)); + } + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return children?.map<DiagnosticsNode>((InlineSpan child) { + return child.toDiagnosticsNode(); + }).toList() ?? const <DiagnosticsNode>[]; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_style.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_style.dart new file mode 100644 index 0000000000000000000000000000000000000000..f85e10436d74ce97364d33a4bc9296e929fe0fee --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/painting/text_style.dart @@ -0,0 +1,1682 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:ui' as ui show + ParagraphStyle, + StrutStyle, + TextStyle, + lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'basic_types.dart'; +import 'colors.dart'; +import 'strut_style.dart'; +import 'text_painter.dart'; +import 'text_scaler.dart'; + +const String _kDefaultDebugLabel = 'unknown'; + +const String _kColorForegroundWarning = 'Cannot provide both a color and a foreground\n' + 'The color argument is just a shorthand for "foreground: Paint()..color = color".'; + +const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor and a background\n' + 'The backgroundColor argument is just a shorthand for "background: Paint()..color = color".'; + +// Examples can assume: +// late BuildContext context; + +/// An immutable style describing how to format and paint text. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=1z6YP7YmvwA} +/// +/// ### Bold +/// +/// {@tool snippet} +/// Here, a single line of text in a [Text] widget is given a specific style +/// override. The style is mixed with the ambient [DefaultTextStyle] by the +/// [Text] widget. +/// +/// ![Applying the style in this way creates bold text.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_bold.png) +/// +/// ```dart +/// const Text( +/// 'No, we need bold strokes. We need this plan.', +/// style: TextStyle(fontWeight: FontWeight.bold), +/// ) +/// ``` +/// {@end-tool} +/// +/// ### Italics +/// +/// {@tool snippet} +/// As in the previous example, the [Text] widget is given a specific style +/// override which is implicitly mixed with the ambient [DefaultTextStyle]. +/// +/// ![This results in italicized text.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_italics.png) +/// +/// ```dart +/// const Text( +/// "Welcome to the present, we're running a real nation.", +/// style: TextStyle(fontStyle: FontStyle.italic), +/// ) +/// ``` +/// {@end-tool} +/// +/// ### Opacity and Color +/// +/// Each line here is progressively more opaque. The base color is +/// [material.Colors.black], and [Color.withOpacity] is used to create a +/// derivative color with the desired opacity. The root [TextSpan] for this +/// [RichText] widget is explicitly given the ambient [DefaultTextStyle], since +/// [RichText] does not do that automatically. The inner [TextStyle] objects are +/// implicitly mixed with the parent [TextSpan]'s [TextSpan.style]. +/// +/// If [color] is specified, [foreground] must be null and vice versa. [color] is +/// treated as a shorthand for `Paint()..color = color`. +/// +/// If [backgroundColor] is specified, [background] must be null and vice versa. +/// The [backgroundColor] is treated as a shorthand for +/// `background: Paint()..color = backgroundColor`. +/// +/// ![This results in three lines of text that go from lighter to darker in color.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_opacity_and_color.png) +/// +/// ```dart +/// RichText( +/// text: TextSpan( +/// style: DefaultTextStyle.of(context).style, +/// children: <TextSpan>[ +/// TextSpan( +/// text: "You don't have the votes.\n", +/// style: TextStyle(color: Colors.black.withOpacity(0.6)), +/// ), +/// TextSpan( +/// text: "You don't have the votes!\n", +/// style: TextStyle(color: Colors.black.withOpacity(0.8)), +/// ), +/// TextSpan( +/// text: "You're gonna need congressional approval and you don't have the votes!\n", +/// style: TextStyle(color: Colors.black.withOpacity(1.0)), +/// ), +/// ], +/// ), +/// ) +/// ``` +/// +/// ### Size +/// +/// {@tool snippet} +/// In this example, the ambient [DefaultTextStyle] is explicitly manipulated to +/// obtain a [TextStyle] that doubles the default font size. +/// +/// ![This results in text that is twice as large as normal.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_size.png) +/// +/// ```dart +/// Text( +/// "These are wise words, enterprising men quote 'em.", +/// style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 2.0), +/// ) +/// ``` +/// {@end-tool} +/// +/// ### Line height +/// +/// By default, text will layout with line height as defined by the font. +/// Font-metrics defined line height may be taller or shorter than the font size. +/// The [height] property allows manual adjustment of the height of the line as +/// a multiple of [fontSize]. For most fonts, setting [height] to 1.0 is not +/// the same as omitting or setting height to null. The following diagram +/// illustrates the difference between the font-metrics-defined line height and +/// the line height produced with `height: 1.0` (also known as the EM-square): +/// +/// ![With the font-metrics-defined line height, there is space between lines appropriate for the font, whereas the EM-square is only the height required to hold most of the characters.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_height_diagram.png) +/// +/// {@tool snippet} +/// The [height] property can be used to change the line height. Here, the line +/// height is set to 5 times the font size, so that the text is very spaced out. +/// Since the `fontSize` is set to 10, the final height of the line is +/// 50 pixels. +/// +/// ```dart +/// const Text( +/// 'Ladies and gentlemen, you coulda been anywhere in the world tonight, but you’re here with us in New York City.', +/// style: TextStyle(height: 5, fontSize: 10), +/// ) +/// ``` +/// {@end-tool} +/// +/// Examples of the resulting heights from different values of `TextStyle.height`: +/// +/// ![Since the explicit line height is applied as a scale factor on the font-metrics-defined line height, the gap above the text grows faster, as the height grows, than the gap below the text.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_height_comparison_diagram.png) +/// +/// See [StrutStyle] for further control of line height at the paragraph level. +/// +/// ### Leading Distribution and Trimming +/// +/// [Leading](https://en.wikipedia.org/wiki/Leading) is the vertical space +/// between glyphs from adjacent lines. Quantitatively, it is the line height +/// (see the previous section) subtracted by the font's ascent and descent. +/// It's possible to have a negative `Leading` if [height] is sufficiently +/// small. +/// +/// When the [height] multiplier is null, `leading` and how it is distributed +/// is up to the font's +/// [metrics](https://en.wikipedia.org/wiki/Typeface#Font_metrics). +/// When the [height] multiplier is specified, the exact behavior can be +/// configured via [leadingDistribution] and [TextPainter.textHeightBehavior]. +/// +/// ![In configuration 1 the line height is divided by the alphabetic baseline proportionally to the font's ascent and descent, in configuration 3 the glyphs are roughly centered within the line height, configuration 2 is similar to configuration 1 except the Text Top guide on the same line as the font's ascent](https://flutter.github.io/assets-for-api-docs/assets/painting/text_height_breakdown.png) +/// +/// Above is a side-by-side comparison of different [leadingDistribution] and +/// [TextPainter.textHeightBehavior] combinations. +/// +/// * Configuration 1: The default. [leadingDistribution] is set to [TextLeadingDistribution.proportional]. +/// * Configuration 2: same as Configuration 1, except [TextHeightBehavior.applyHeightToFirstAscent] is set to false. +/// * Configuration 3: [leadingDistribution] is set to [TextLeadingDistribution.even]. +/// * Configuration 4: same as Configuration 3, except [TextHeightBehavior.applyHeightToLastDescent] is set to false. +/// +/// The [leadingDistribution] property controls how leading is distributed over +/// and under the text. With [TextLeadingDistribution.proportional] +/// (Configuration 1), `Top Leading : Bottom Leading = Font Ascent : Font +/// Descent`, which also means the alphabetic baseline divides the line height +/// into 2 parts proportional to the font's ascent and descent. With +/// [TextLeadingDistribution.even] (Configuration 3), `Top Leading` equals +/// `Bottom Leading`, and the glyphs are roughly centered within the allotted +/// line height. +/// +/// The [TextPainter.textHeightBehavior] is a property that controls leading at +/// the paragraph level. The `applyHeightToFirstAscent` property is applied +/// **after** [height] and [leadingDistribution]. Setting it to false trims the +/// "Top Leading" of the text box to match the font's ascent if it's on the +/// first line (see Configuration 2). Similarly setting +/// `applyHeightToLastDescent` to false reduces "Bottom Leading" to 0 for the +/// last line of text (Configuration 4). +/// +/// ### Wavy red underline with black text +/// +/// {@tool snippet} +/// Styles can be combined. In this example, the misspelled word is drawn in +/// black text and underlined with a wavy red line to indicate a spelling error. +/// (The remainder is styled according to the Flutter default text styles, not +/// the ambient [DefaultTextStyle], since no explicit style is given and +/// [RichText] does not automatically use the ambient [DefaultTextStyle].) +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_wavy_red_underline.png) +/// +/// ```dart +/// RichText( +/// text: const TextSpan( +/// text: "Don't tax the South ", +/// children: <TextSpan>[ +/// TextSpan( +/// text: 'cuz', +/// style: TextStyle( +/// color: Colors.black, +/// decoration: TextDecoration.underline, +/// decorationColor: Colors.red, +/// decorationStyle: TextDecorationStyle.wavy, +/// ), +/// ), +/// TextSpan( +/// text: ' we got it made in the shade', +/// ), +/// ], +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ### Borders and stroke (Foreground) +/// +/// {@tool snippet} +/// To create bordered text, a [Paint] with [Paint.style] set to [PaintingStyle.stroke] +/// should be provided as a [foreground] paint. The following example uses a [Stack] +/// to produce a stroke and fill effect. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_border.png) +/// +/// ```dart +/// Stack( +/// children: <Widget>[ +/// // Stroked text as border. +/// Text( +/// 'Greetings, planet!', +/// style: TextStyle( +/// fontSize: 40, +/// foreground: Paint() +/// ..style = PaintingStyle.stroke +/// ..strokeWidth = 6 +/// ..color = Colors.blue[700]!, +/// ), +/// ), +/// // Solid text as fill. +/// Text( +/// 'Greetings, planet!', +/// style: TextStyle( +/// fontSize: 40, +/// color: Colors.grey[300], +/// ), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// ### Gradients (Foreground) +/// +/// {@tool snippet} +/// The [foreground] property also allows effects such as gradients to be +/// applied to the text. Here we provide a [Paint] with a [ui.Gradient] +/// shader. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_gradient.png) +/// +/// ```dart +/// Text( +/// 'Greetings, planet!', +/// style: TextStyle( +/// fontSize: 40, +/// foreground: Paint() +/// ..shader = ui.Gradient.linear( +/// const Offset(0, 20), +/// const Offset(150, 20), +/// <Color>[ +/// Colors.red, +/// Colors.yellow, +/// ], +/// ) +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ### Custom Fonts +/// +/// Custom fonts can be declared in the `pubspec.yaml` file as shown below: +/// +/// ```yaml +/// flutter: +/// fonts: +/// - family: Raleway +/// fonts: +/// - asset: fonts/Raleway-Regular.ttf +/// - asset: fonts/Raleway-Medium.ttf +/// weight: 500 +/// - asset: assets/fonts/Raleway-SemiBold.ttf +/// weight: 600 +/// - family: Schyler +/// fonts: +/// - asset: fonts/Schyler-Regular.ttf +/// - asset: fonts/Schyler-Italic.ttf +/// style: italic +/// ``` +/// +/// The `family` property determines the name of the font, which you can use in +/// the [fontFamily] argument. The `asset` property is a path to the font file, +/// relative to the `pubspec.yaml` file. The `weight` property specifies the +/// weight of the glyph outlines in the file as an integer multiple of 100 +/// between 100 and 900. This corresponds to the [FontWeight] class and can be +/// used in the [fontWeight] argument. The `style` property specifies whether the +/// outlines in the file are `italic` or `normal`. These values correspond to +/// the [FontStyle] class and can be used in the [fontStyle] argument. +/// +/// To select a custom font, create [TextStyle] using the [fontFamily] +/// argument as shown in the example below: +/// +/// {@tool snippet} +/// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_custom_fonts.png) +/// +/// ```dart +/// const TextStyle(fontFamily: 'Raleway') +/// ``` +/// {@end-tool} +/// +/// To use a font family defined in a package, the `package` argument must be +/// provided. For instance, suppose the font declaration above is in the +/// `pubspec.yaml` of a package named `my_package` which the app depends on. +/// Then creating the TextStyle is done as follows: +/// +/// ```dart +/// const TextStyle(fontFamily: 'Raleway', package: 'my_package') +/// ``` +/// +/// If the package internally uses the font it defines, it should still specify +/// the `package` argument when creating the text style as in the example above. +/// +/// A package can also provide font files without declaring a font in its +/// `pubspec.yaml`. These files should then be in the `lib/` folder of the +/// package. The font files will not automatically be bundled in the app, instead +/// the app can use these selectively when declaring a font. Suppose a package +/// named `my_package` has: +/// +/// lib/fonts/Raleway-Medium.ttf +/// +/// Then the app can declare a font like in the example below: +/// +/// ```yaml +/// flutter: +/// fonts: +/// - family: Raleway +/// fonts: +/// - asset: assets/fonts/Raleway-Regular.ttf +/// - asset: packages/my_package/fonts/Raleway-Medium.ttf +/// weight: 500 +/// ``` +/// +/// The `lib/` is implied, so it should not be included in the asset path. +/// +/// In this case, since the app locally defines the font, the TextStyle is +/// created without the `package` argument: +/// +/// {@tool snippet} +/// ```dart +/// const TextStyle(fontFamily: 'Raleway') +/// ``` +/// {@end-tool} +/// +/// #### Supported font formats +/// +/// Font formats currently supported by Flutter: +/// +/// * `.ttc` +/// * `.ttf` +/// * `.otf` +/// +/// Flutter does not support `.woff` and `.woff2` fonts for all platforms. +/// +/// ### Custom Font Fallback +/// +/// A custom [fontFamilyFallback] list can be provided. The list should be an +/// ordered list of strings of font family names in the order they will be attempted. +/// +/// The fonts in [fontFamilyFallback] will be used only if the requested glyph is +/// not present in the [fontFamily]. +/// +/// The fallback order is: +/// +/// * [fontFamily] +/// * [fontFamilyFallback] in order of first to last. +/// * System fallback fonts which will vary depending on platform. +/// +/// The glyph used will always be the first matching version in fallback order. +/// +/// The [fontFamilyFallback] property is commonly used to specify different font +/// families for multilingual text spans as well as separate fonts for glyphs such +/// as emojis. +/// +/// {@tool snippet} +/// In the following example, any glyphs not present in the font `Raleway` will be attempted +/// to be resolved with `Noto Sans CJK SC`, and then with `Noto Color Emoji`: +/// +/// ```dart +/// const TextStyle( +/// fontFamily: 'Raleway', +/// fontFamilyFallback: <String>[ +/// 'Noto Sans CJK SC', +/// 'Noto Color Emoji', +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// If all custom fallback font families are exhausted and no match was found +/// or no custom fallback was provided, the platform font fallback will be used. +/// +/// ### Inconsistent platform fonts +/// +/// By default, fonts differ depending on the platform. +/// +/// * The default font-family for `Android`,`Fuchsia` and `Linux` is `Roboto`. +/// * The default font-family for `iOS` is `SF Pro Display`/`SF Pro Text`. +/// * The default font-family for `MacOS` is `.AppleSystemUIFont`. +/// * The default font-family for `Windows` is `Segoe UI`. +// +// The implementation of these defaults can be found in: +// /packages/flutter/lib/src/material/typography.dart +/// +/// Since Flutter's font discovery for default fonts depends on the fonts present +/// on the device, it is not safe to assume all default fonts will be available or +/// consistent across devices. +/// +/// A known example of this is that Samsung devices ship with a CJK font that has +/// smaller line spacing than the Android default. This results in Samsung devices +/// displaying more tightly spaced text than on other Android devices when no +/// custom font is specified. +/// +/// To avoid this, a custom font should be specified if absolute font consistency +/// is required for your application. +/// +/// See also: +/// +/// * [Text], the widget for showing text in a single style. +/// * [DefaultTextStyle], the widget that specifies the default text styles for +/// [Text] widgets, configured using a [TextStyle]. +/// * [RichText], the widget for showing a paragraph of mix-style text. +/// * [TextSpan], the class that wraps a [TextStyle] for the purposes of +/// passing it to a [RichText]. +/// * [TextStyle](https://api.flutter.dev/flutter/dart-ui/TextStyle-class.html), the class in the [dart:ui] library. +/// * Cookbook: [Use a custom font](https://flutter.dev/docs/cookbook/design/fonts) +/// * Cookbook: [Use themes to share colors and font styles](https://flutter.dev/docs/cookbook/design/themes) +@immutable +class TextStyle with Diagnosticable { + /// Creates a text style. + /// + /// The `package` argument must be non-null if the font family is defined in a + /// package. It is combined with the `fontFamily` argument to set the + /// [fontFamily] property. + /// + /// On Apple devices the strings 'CupertinoSystemText' and + /// 'CupertinoSystemDisplay' are used in [fontFamily] as proxies for the + /// Apple system fonts. They currently redirect to the equivilant of SF Pro + /// Text and SF Pro Display respectively. 'CupertinoSystemText' is designed + /// for fonts below 20 point size, and 'CupertinoSystemDisplay' is recommended + /// for sizes 20 and above. When used on non-Apple platforms, these strings + /// will return the regular fallback font family instead. + const TextStyle({ + this.inherit = true, + this.color, + this.backgroundColor, + this.fontSize, + this.fontWeight, + this.fontStyle, + this.letterSpacing, + this.wordSpacing, + this.textBaseline, + this.height, + this.leadingDistribution, + this.locale, + this.foreground, + this.background, + this.shadows, + this.fontFeatures, + this.fontVariations, + this.decoration, + this.decorationColor, + this.decorationStyle, + this.decorationThickness, + this.debugLabel, + String? fontFamily, + List<String>? fontFamilyFallback, + String? package, + this.overflow, + }) : fontFamily = package == null ? fontFamily : 'packages/$package/$fontFamily', + _fontFamilyFallback = fontFamilyFallback, + _package = package, + assert(color == null || foreground == null, _kColorForegroundWarning), + assert(backgroundColor == null || background == null, _kColorBackgroundWarning); + + + /// Whether null values in this [TextStyle] can be replaced with their value + /// in another [TextStyle] using [merge]. + /// + /// The [merge] operation is not commutative: the [inherit] value of the + /// method argument decides whether the two [TextStyle]s can be combined + /// together. If it is false, the method argument [TextStyle] will be returned. + /// Otherwise, the combining is allowed, and the returned [TextStyle] inherits + /// the [inherit] value from the method receiver. + /// + /// This property does not affect the text style inheritance in an [InlineSpan] + /// tree: an [InlineSpan]'s text style is merged with that of an ancestor + /// [InlineSpan] if it has unspecified fields, regardless of its [inherit] + /// value. + /// + /// Properties that don't have explicit values or other default values to fall + /// back to will revert to the defaults: white in color, a font size of 14 + /// pixels, in a sans-serif font face. + /// + /// See also: + /// * [TextStyle.merge], which can be used to combine properties from two + /// [TextStyle]s. + final bool inherit; + + /// The color to use when painting the text. + /// + /// If [foreground] is specified, this value must be null. The [color] property + /// is shorthand for `Paint()..color = color`. + /// + /// In [merge], [apply], and [lerp], conflicts between [color] and [foreground] + /// specification are resolved in [foreground]'s favor - i.e. if [foreground] is + /// specified in one place, it will dominate [color] in another. + final Color? color; + + /// The color to use as the background for the text. + /// + /// If [background] is specified, this value must be null. The + /// [backgroundColor] property is shorthand for + /// `background: Paint()..color = backgroundColor`. + /// + /// In [merge], [apply], and [lerp], conflicts between [backgroundColor] and [background] + /// specification are resolved in [background]'s favor - i.e. if [background] is + /// specified in one place, it will dominate [color] in another. + final Color? backgroundColor; + + /// The name of the font to use when painting the text (e.g., Roboto). + /// + /// If the font is defined in a package, this will be prefixed with + /// 'packages/package_name/' (e.g. 'packages/cool_fonts/Roboto'). The + /// prefixing is done by the constructor when the `package` argument is + /// provided. + /// + /// The value provided in [fontFamily] will act as the preferred/first font + /// family that glyphs are looked for in, followed in order by the font families + /// in [fontFamilyFallback]. When [fontFamily] is null or not provided, the + /// first value in [fontFamilyFallback] acts as the preferred/first font + /// family. When neither is provided, then the default platform font will + /// be used. + /// + /// When running on Apple devices, the strings 'CupertinoSystemText' and + /// 'CupertinoSystemDisplay' are used as proxies for the Apple system fonts. + /// They currently redirect to the equivilant of SF Pro Text and SF Pro Display + /// respectively. 'CupertinoSystemText' is designed for fonts below 20 point + /// size, and 'CupertinoSystemDisplay' is recommended for sizes 20 and above. + /// When used on non-Apple platforms, these strings will return the regular + /// fallback font family instead. + final String? fontFamily; + + /// The ordered list of font families to fall back on when a glyph cannot be + /// found in a higher priority font family. + /// + /// The value provided in [fontFamily] will act as the preferred/first font + /// family that glyphs are looked for in, followed in order by the font families + /// in [fontFamilyFallback]. If all font families are exhausted and no match + /// was found, the default platform font family will be used instead. + /// + /// When [fontFamily] is null or not provided, the first value in [fontFamilyFallback] + /// acts as the preferred/first font family. When neither is provided, then + /// the default platform font will be used. Providing an empty list or null + /// for this property is the same as omitting it. + /// + /// For example, if a glyph is not found in [fontFamily], then each font family + /// in [fontFamilyFallback] will be searched in order until it is found. If it + /// is not found, then a box will be drawn in its place. + /// + /// If the font is defined in a package, each font family in the list will be + /// prefixed with 'packages/package_name/' (e.g. 'packages/cool_fonts/Roboto'). + /// The package name should be provided by the `package` argument in the + /// constructor. + List<String>? get fontFamilyFallback => _package == null ? _fontFamilyFallback : _fontFamilyFallback?.map((String str) => 'packages/$_package/$str').toList(); + final List<String>? _fontFamilyFallback; + + // This is stored in order to prefix the fontFamilies in _fontFamilyFallback + // in the [fontFamilyFallback] getter. + final String? _package; + + /// The size of fonts (in logical pixels) to use when painting the text. + /// + /// The value specified matches the dimension of the + /// [em square](https://fonts.google.com/knowledge/glossary/em) of the + /// underlying font, and more often then not isn't exactly the height or the + /// width of glyphs in the font. + /// + /// During painting, the [fontSize] is multiplied by the current + /// `textScaleFactor` to let users make it easier to read text by increasing + /// its size. + /// + /// The [getParagraphStyle] method defaults to 14 logical pixels if [fontSize] + /// is set to null. + final double? fontSize; + + /// The typeface thickness to use when painting the text (e.g., bold). + final FontWeight? fontWeight; + + /// The typeface variant to use when drawing the letters (e.g., italics). + final FontStyle? fontStyle; + + /// The amount of space (in logical pixels) to add between each letter. + /// A negative value can be used to bring the letters closer. + final double? letterSpacing; + + /// The amount of space (in logical pixels) to add at each sequence of + /// white-space (i.e. between each word). A negative value can be used to + /// bring the words closer. + final double? wordSpacing; + + /// The common baseline that should be aligned between this text span and its + /// parent text span, or, for the root text spans, with the line box. + final TextBaseline? textBaseline; + + /// The height of this text span, as a multiple of the font size. + /// + /// When [height] is null or omitted, the line height will be determined + /// by the font's metrics directly, which may differ from the fontSize. + /// When [height] is non-null, the line height of the span of text will be a + /// multiple of [fontSize] and be exactly `fontSize * height` logical pixels + /// tall. + /// + /// For most fonts, setting [height] to 1.0 is not the same as omitting or + /// setting height to null because the [fontSize] sets the height of the EM-square, + /// which is different than the font provided metrics for line height. The + /// following diagram illustrates the difference between the font-metrics + /// defined line height and the line height produced with `height: 1.0` + /// (which forms the upper and lower edges of the EM-square): + /// + /// ![With the font-metrics-defined line height, there is space between lines appropriate for the font, whereas the EM-square is only the height required to hold most of the characters.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_height_diagram.png) + /// + /// Examples of the resulting line heights from different values of `TextStyle.height`: + /// + /// ![Since the explicit line height is applied as a scale factor on the font-metrics-defined line height, the gap above the text grows faster, as the height grows, than the gap below the text.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_height_comparison_diagram.png) + /// + /// See [StrutStyle] and [TextHeightBehavior] for further control of line + /// height at the paragraph level. + final double? height; + + /// How the vertical space added by the [height] multiplier should be + /// distributed over and under the text. + /// + /// When a non-null [height] is specified, after accommodating the glyphs of + /// the text, the remaining vertical space from the allotted line height will + /// be distributed over and under the text, according to the + /// [leadingDistribution] property. See the [TextStyle] class's documentation + /// for an example. + /// + /// When [height] is null, [leadingDistribution] does not affect the text + /// layout. + /// + /// Defaults to null, which defers to the paragraph's + /// `ParagraphStyle.textHeightBehavior`'s [leadingDistribution]. + final TextLeadingDistribution? leadingDistribution; + + /// The locale used to select region-specific glyphs. + /// + /// This property is rarely set. Typically the locale used to select + /// region-specific glyphs is defined by the text widget's [BuildContext] + /// using `Localizations.localeOf(context)`. For example [RichText] defines + /// its locale this way. However, a rich text widget's [TextSpan]s could + /// specify text styles with different explicit locales in order to select + /// different region-specific glyphs for each text span. + final Locale? locale; + + /// The paint drawn as a foreground for the text. + /// + /// The value should ideally be cached and reused each time if multiple text + /// styles are created with the same paint settings. Otherwise, each time it + /// will appear like the style changed, which will result in unnecessary + /// updates all the way through the framework. + /// + /// If [color] is specified, this value must be null. The [color] property + /// is shorthand for `Paint()..color = color`. + /// + /// In [merge], [apply], and [lerp], conflicts between [color] and [foreground] + /// specification are resolved in [foreground]'s favor - i.e. if [foreground] is + /// specified in one place, it will dominate [color] in another. + final Paint? foreground; + + /// The paint drawn as a background for the text. + /// + /// The value should ideally be cached and reused each time if multiple text + /// styles are created with the same paint settings. Otherwise, each time it + /// will appear like the style changed, which will result in unnecessary + /// updates all the way through the framework. + /// + /// If [backgroundColor] is specified, this value must be null. The + /// [backgroundColor] property is shorthand for + /// `background: Paint()..color = backgroundColor`. + /// + /// In [merge], [apply], and [lerp], conflicts between [backgroundColor] and + /// [background] specification are resolved in [background]'s favor - i.e. if + /// [background] is specified in one place, it will dominate [backgroundColor] + /// in another. + final Paint? background; + + /// The decorations to paint near the text (e.g., an underline). + /// + /// Multiple decorations can be applied using [TextDecoration.combine]. + final TextDecoration? decoration; + + /// The color in which to paint the text decorations. + final Color? decorationColor; + + /// The style in which to paint the text decorations (e.g., dashed). + final TextDecorationStyle? decorationStyle; + + /// The thickness of the decoration stroke as a multiplier of the thickness + /// defined by the font. + /// + /// The font provides a base stroke width for [decoration]s which scales off + /// of the [fontSize]. This property may be used to achieve a thinner or + /// thicker decoration stroke, without changing the [fontSize]. For example, + /// a [decorationThickness] of 2.0 will draw a decoration twice as thick as + /// the font defined decoration thickness. + /// + /// {@tool snippet} + /// To achieve a bolded strike-through, we can apply a thicker stroke for the + /// decoration. + /// + /// ```dart + /// const Text( + /// 'This has a very BOLD strike through!', + /// style: TextStyle( + /// decoration: TextDecoration.lineThrough, + /// decorationThickness: 2.85, + /// ), + /// ) + /// ``` + /// {@end-tool} + /// + /// {@tool snippet} + /// We can apply a very thin and subtle wavy underline (perhaps, when words + /// are misspelled) by using a [decorationThickness] < 1.0. + /// + /// ```dart + /// const Text( + /// 'oopsIforgottousespaces!', + /// style: TextStyle( + /// decoration: TextDecoration.underline, + /// decorationStyle: TextDecorationStyle.wavy, + /// decorationColor: Colors.red, + /// decorationThickness: 0.5, + /// ), + /// ) + /// ``` + /// {@end-tool} + /// + /// The default [decorationThickness] is 1.0, which will use the font's base + /// stroke thickness/width. + final double? decorationThickness; + + /// A human-readable description of this text style. + /// + /// This property is maintained only in debug builds. + /// + /// When merging ([merge]), copying ([copyWith]), modifying using [apply], or + /// interpolating ([lerp]), the label of the resulting style is marked with + /// the debug labels of the original styles. This helps figuring out where a + /// particular text style came from. + /// + /// This property is not considered when comparing text styles using `==` or + /// [compareTo], and it does not affect [hashCode]. + final String? debugLabel; + + /// A list of [Shadow]s that will be painted underneath the text. + /// + /// Multiple shadows are supported to replicate lighting from multiple light + /// sources. + /// + /// Shadows must be in the same order for [TextStyle] to be considered as + /// equivalent as order produces differing transparency. + final List<Shadow>? shadows; + + /// A list of [FontFeature]s that affect how the font selects glyphs. + /// + /// Some fonts support multiple variants of how a given character can be + /// rendered. For example, a font might provide both proportional and + /// tabular numbers, or it might offer versions of the zero digit with + /// and without slashes. [FontFeature]s can be used to select which of + /// these variants will be used for rendering. + /// + /// Font features are not interpolated by [lerp]. + /// + /// See also: + /// + /// * [fontVariations], for font features that have continuous parameters. + final List<FontFeature>? fontFeatures; + + /// A list of [FontVariation]s that affect how a variable font is rendered. + /// + /// Some fonts are variable fonts that can generate multiple font faces based + /// on the values of customizable attributes. For example, a variable font + /// may have a weight axis that can be set to a value between 1 and 1000. + /// [FontVariation]s can be used to select the values of these design axes. + /// + /// For example, to control the weight axis of the Roboto Slab variable font + /// (https://fonts.google.com/specimen/Roboto+Slab): + /// ```dart + /// const TextStyle( + /// fontFamily: 'RobotoSlab', + /// fontVariations: <FontVariation>[FontVariation('wght', 900.0)] + /// ) + /// ``` + /// + /// Font variations can be interpolated via [lerp]. This is fastest when the + /// same font variation axes are specified, in the same order, in both + /// [TextStyle] objects. See [lerpFontVariations]. + /// + /// See also: + /// + /// * [fontFeatures], for font variations that have discrete values. + final List<FontVariation>? fontVariations; + + /// How visual text overflow should be handled. + final TextOverflow? overflow; + + // Return the original value of fontFamily, without the additional + // "packages/$_package/" prefix. + String? get _fontFamily { + if (_package != null) { + final String fontFamilyPrefix = 'packages/$_package/'; + assert(fontFamily?.startsWith(fontFamilyPrefix) ?? true); + return fontFamily?.substring(fontFamilyPrefix.length); + } + return fontFamily; + } + + /// Creates a copy of this text style but with the given fields replaced with + /// the new values. + /// + /// One of [color] or [foreground] must be null, and if this has [foreground] + /// specified it will be given preference over any color parameter. + /// + /// One of [backgroundColor] or [background] must be null, and if this has + /// [background] specified it will be given preference over any + /// backgroundColor parameter. + TextStyle copyWith({ + bool? inherit, + Color? color, + Color? backgroundColor, + double? fontSize, + FontWeight? fontWeight, + FontStyle? fontStyle, + double? letterSpacing, + double? wordSpacing, + TextBaseline? textBaseline, + double? height, + TextLeadingDistribution? leadingDistribution, + Locale? locale, + Paint? foreground, + Paint? background, + List<Shadow>? shadows, + List<FontFeature>? fontFeatures, + List<FontVariation>? fontVariations, + TextDecoration? decoration, + Color? decorationColor, + TextDecorationStyle? decorationStyle, + double? decorationThickness, + String? debugLabel, + String? fontFamily, + List<String>? fontFamilyFallback, + String? package, + TextOverflow? overflow, + }) { + assert(color == null || foreground == null, _kColorForegroundWarning); + assert(backgroundColor == null || background == null, _kColorBackgroundWarning); + String? newDebugLabel; + assert(() { + if (this.debugLabel != null) { + newDebugLabel = debugLabel ?? '(${this.debugLabel}).copyWith'; + } + return true; + }()); + + return TextStyle( + inherit: inherit ?? this.inherit, + color: this.foreground == null && foreground == null ? color ?? this.color : null, + backgroundColor: this.background == null && background == null ? backgroundColor ?? this.backgroundColor : null, + fontSize: fontSize ?? this.fontSize, + fontWeight: fontWeight ?? this.fontWeight, + fontStyle: fontStyle ?? this.fontStyle, + letterSpacing: letterSpacing ?? this.letterSpacing, + wordSpacing: wordSpacing ?? this.wordSpacing, + textBaseline: textBaseline ?? this.textBaseline, + height: height ?? this.height, + leadingDistribution: leadingDistribution ?? this.leadingDistribution, + locale: locale ?? this.locale, + foreground: foreground ?? this.foreground, + background: background ?? this.background, + shadows: shadows ?? this.shadows, + fontFeatures: fontFeatures ?? this.fontFeatures, + fontVariations: fontVariations ?? this.fontVariations, + decoration: decoration ?? this.decoration, + decorationColor: decorationColor ?? this.decorationColor, + decorationStyle: decorationStyle ?? this.decorationStyle, + decorationThickness: decorationThickness ?? this.decorationThickness, + debugLabel: newDebugLabel, + fontFamily: fontFamily ?? _fontFamily, + fontFamilyFallback: fontFamilyFallback ?? _fontFamilyFallback, + package: package ?? _package, + overflow: overflow ?? this.overflow, + ); + } + + /// Creates a copy of this text style replacing or altering the specified + /// properties. + /// + /// The non-numeric properties [color], [fontFamily], [decoration], + /// [decorationColor] and [decorationStyle] are replaced with the new values. + /// + /// [foreground] will be given preference over [color] if it is not null and + /// [background] will be given preference over [backgroundColor] if it is not + /// null. + /// + /// The numeric properties are multiplied by the given factors and then + /// incremented by the given deltas. + /// + /// For example, `style.apply(fontSizeFactor: 2.0, fontSizeDelta: 1.0)` would + /// return a [TextStyle] whose [fontSize] is `style.fontSize * 2.0 + 1.0`. + /// + /// For the [fontWeight], the delta is applied to the [FontWeight] enum index + /// values, so that for instance `style.apply(fontWeightDelta: -2)` when + /// applied to a `style` whose [fontWeight] is [FontWeight.w500] will return a + /// [TextStyle] with a [FontWeight.w300]. + /// + /// If the underlying values are null, then the corresponding factors and/or + /// deltas must not be specified. + /// + /// If [foreground] is specified on this object, then applying [color] here + /// will have no effect and if [background] is specified on this object, then + /// applying [backgroundColor] here will have no effect either. + TextStyle apply({ + Color? color, + Color? backgroundColor, + TextDecoration? decoration, + Color? decorationColor, + TextDecorationStyle? decorationStyle, + double decorationThicknessFactor = 1.0, + double decorationThicknessDelta = 0.0, + String? fontFamily, + List<String>? fontFamilyFallback, + double fontSizeFactor = 1.0, + double fontSizeDelta = 0.0, + int fontWeightDelta = 0, + FontStyle? fontStyle, + double letterSpacingFactor = 1.0, + double letterSpacingDelta = 0.0, + double wordSpacingFactor = 1.0, + double wordSpacingDelta = 0.0, + double heightFactor = 1.0, + double heightDelta = 0.0, + TextBaseline? textBaseline, + TextLeadingDistribution? leadingDistribution, + Locale? locale, + List<Shadow>? shadows, + List<FontFeature>? fontFeatures, + List<FontVariation>? fontVariations, + String? package, + TextOverflow? overflow, + }) { + assert(fontSize != null || (fontSizeFactor == 1.0 && fontSizeDelta == 0.0)); + assert(fontWeight != null || fontWeightDelta == 0.0); + assert(letterSpacing != null || (letterSpacingFactor == 1.0 && letterSpacingDelta == 0.0)); + assert(wordSpacing != null || (wordSpacingFactor == 1.0 && wordSpacingDelta == 0.0)); + assert(decorationThickness != null || (decorationThicknessFactor == 1.0 && decorationThicknessDelta == 0.0)); + + String? modifiedDebugLabel; + assert(() { + if (debugLabel != null) { + modifiedDebugLabel = '($debugLabel).apply'; + } + return true; + }()); + + return TextStyle( + inherit: inherit, + color: foreground == null ? color ?? this.color : null, + backgroundColor: background == null ? backgroundColor ?? this.backgroundColor : null, + fontFamily: fontFamily ?? _fontFamily, + fontFamilyFallback: fontFamilyFallback ?? _fontFamilyFallback, + fontSize: fontSize == null ? null : fontSize! * fontSizeFactor + fontSizeDelta, + fontWeight: fontWeight == null ? null : FontWeight.values[(fontWeight!.index + fontWeightDelta).clamp(0, FontWeight.values.length - 1)], + fontStyle: fontStyle ?? this.fontStyle, + letterSpacing: letterSpacing == null ? null : letterSpacing! * letterSpacingFactor + letterSpacingDelta, + wordSpacing: wordSpacing == null ? null : wordSpacing! * wordSpacingFactor + wordSpacingDelta, + textBaseline: textBaseline ?? this.textBaseline, + height: height == null ? null : height! * heightFactor + heightDelta, + leadingDistribution: leadingDistribution ?? this.leadingDistribution, + locale: locale ?? this.locale, + foreground: foreground, + background: background, + shadows: shadows ?? this.shadows, + fontFeatures: fontFeatures ?? this.fontFeatures, + fontVariations: fontVariations ?? this.fontVariations, + decoration: decoration ?? this.decoration, + decorationColor: decorationColor ?? this.decorationColor, + decorationStyle: decorationStyle ?? this.decorationStyle, + decorationThickness: decorationThickness == null ? null : decorationThickness! * decorationThicknessFactor + decorationThicknessDelta, + overflow: overflow ?? this.overflow, + package: package ?? _package, + debugLabel: modifiedDebugLabel, + ); + } + + /// Returns a new text style that is a combination of this style and the given + /// [other] style. + /// + /// If the given [other] text style has its [TextStyle.inherit] set to true, + /// its null properties are replaced with the non-null properties of this text + /// style. The [other] style _inherits_ the properties of this style. Another + /// way to think of it is that the "missing" properties of the [other] style + /// are _filled_ by the properties of this style. + /// + /// If the given [other] text style has its [TextStyle.inherit] set to false, + /// returns the given [other] style unchanged. The [other] style does not + /// inherit properties of this style. + /// + /// If the given text style is null, returns this text style. + /// + /// One of [color] or [foreground] must be null, and if this or `other` has + /// [foreground] specified it will be given preference over any color parameter. + /// + /// Similarly, one of [backgroundColor] or [background] must be null, and if + /// this or `other` has [background] specified it will be given preference + /// over any backgroundColor parameter. + TextStyle merge(TextStyle? other) { + if (other == null) { + return this; + } + if (!other.inherit) { + return other; + } + + String? mergedDebugLabel; + assert(() { + if (other.debugLabel != null || debugLabel != null) { + mergedDebugLabel = '(${debugLabel ?? _kDefaultDebugLabel}).merge(${other.debugLabel ?? _kDefaultDebugLabel})'; + } + return true; + }()); + + return copyWith( + color: other.color, + backgroundColor: other.backgroundColor, + fontSize: other.fontSize, + fontWeight: other.fontWeight, + fontStyle: other.fontStyle, + letterSpacing: other.letterSpacing, + wordSpacing: other.wordSpacing, + textBaseline: other.textBaseline, + height: other.height, + leadingDistribution: other.leadingDistribution, + locale: other.locale, + foreground: other.foreground, + background: other.background, + shadows: other.shadows, + fontFeatures: other.fontFeatures, + fontVariations: other.fontVariations, + decoration: other.decoration, + decorationColor: other.decorationColor, + decorationStyle: other.decorationStyle, + decorationThickness: other.decorationThickness, + debugLabel: mergedDebugLabel, + fontFamily: other._fontFamily, + fontFamilyFallback: other._fontFamilyFallback, + package: other._package, + overflow: other.overflow, + ); + } + + /// Interpolate between two text styles for animated transitions. + /// + /// Interpolation will not work well if the styles don't specify the same fields. + /// When this happens, to keep the interpolated transition smooth, the + /// implementation uses the non-null value throughout the transition for + /// lerpable fields such as colors (for example, if one [TextStyle] specified + /// `fontSize` but the other didn't, the returned [TextStyle] will use the + /// `fontSize` from the [TextStyle] that specified it, regardless of the `t` + /// value). + /// + /// This method throws when the given [TextStyle]s don't have the same + /// [inherit] value and a lerpable field is missing from both [TextStyle]s, + /// as that could result in jumpy transitions. + /// + /// {@macro dart.ui.shadow.lerp} + /// + /// If [foreground] is specified on either of `a` or `b`, both will be treated + /// as if they have a [foreground] paint (creating a new [Paint] if necessary + /// based on the [color] property). + /// + /// If [background] is specified on either of `a` or `b`, both will be treated + /// as if they have a [background] paint (creating a new [Paint] if necessary + /// based on the [backgroundColor] property). + static TextStyle? lerp(TextStyle? a, TextStyle? b, double t) { + if (identical(a, b)) { + return a; + } + String? lerpDebugLabel; + assert(() { + lerpDebugLabel = 'lerp(${a?.debugLabel ?? _kDefaultDebugLabel} ⎯${t.toStringAsFixed(1)}→ ${b?.debugLabel ?? _kDefaultDebugLabel})'; + return true; + }()); + + if (a == null) { + return TextStyle( + inherit: b!.inherit, + color: Color.lerp(null, b.color, t), + backgroundColor: Color.lerp(null, b.backgroundColor, t), + fontSize: t < 0.5 ? null : b.fontSize, + fontWeight: FontWeight.lerp(null, b.fontWeight, t), + fontStyle: t < 0.5 ? null : b.fontStyle, + letterSpacing: t < 0.5 ? null : b.letterSpacing, + wordSpacing: t < 0.5 ? null : b.wordSpacing, + textBaseline: t < 0.5 ? null : b.textBaseline, + height: t < 0.5 ? null : b.height, + leadingDistribution: t < 0.5 ? null : b.leadingDistribution, + locale: t < 0.5 ? null : b.locale, + foreground: t < 0.5 ? null : b.foreground, + background: t < 0.5 ? null : b.background, + shadows: t < 0.5 ? null : b.shadows, + fontFeatures: t < 0.5 ? null : b.fontFeatures, + fontVariations: lerpFontVariations(null, b.fontVariations, t), + decoration: t < 0.5 ? null : b.decoration, + decorationColor: Color.lerp(null, b.decorationColor, t), + decorationStyle: t < 0.5 ? null : b.decorationStyle, + decorationThickness: t < 0.5 ? null : b.decorationThickness, + debugLabel: lerpDebugLabel, + fontFamily: t < 0.5 ? null : b._fontFamily, + fontFamilyFallback: t < 0.5 ? null : b._fontFamilyFallback, + package: t < 0.5 ? null : b._package, + overflow: t < 0.5 ? null : b.overflow, + ); + } + + if (b == null) { + return TextStyle( + inherit: a.inherit, + color: Color.lerp(a.color, null, t), + backgroundColor: Color.lerp(null, a.backgroundColor, t), + fontSize: t < 0.5 ? a.fontSize : null, + fontWeight: FontWeight.lerp(a.fontWeight, null, t), + fontStyle: t < 0.5 ? a.fontStyle : null, + letterSpacing: t < 0.5 ? a.letterSpacing : null, + wordSpacing: t < 0.5 ? a.wordSpacing : null, + textBaseline: t < 0.5 ? a.textBaseline : null, + height: t < 0.5 ? a.height : null, + leadingDistribution: t < 0.5 ? a.leadingDistribution : null, + locale: t < 0.5 ? a.locale : null, + foreground: t < 0.5 ? a.foreground : null, + background: t < 0.5 ? a.background : null, + shadows: t < 0.5 ? a.shadows : null, + fontFeatures: t < 0.5 ? a.fontFeatures : null, + fontVariations: lerpFontVariations(a.fontVariations, null, t), + decoration: t < 0.5 ? a.decoration : null, + decorationColor: Color.lerp(a.decorationColor, null, t), + decorationStyle: t < 0.5 ? a.decorationStyle : null, + decorationThickness: t < 0.5 ? a.decorationThickness : null, + debugLabel: lerpDebugLabel, + fontFamily: t < 0.5 ? a._fontFamily : null, + fontFamilyFallback: t < 0.5 ? a._fontFamilyFallback : null, + package: t < 0.5 ? a._package : null, + overflow: t < 0.5 ? a.overflow : null, + ); + } + + assert(() { + if (a.inherit == b.inherit) { + return true; + } + + final List<String> nullFields = <String>[ + if (a.foreground == null && b.foreground == null && a.color == null && b.color == null) 'color', + if (a.background == null && b.background == null && a.backgroundColor == null && b.backgroundColor == null) 'backgroundColor', + if (a.fontSize == null && b.fontSize == null) 'fontSize', + if (a.letterSpacing == null && b.letterSpacing == null) 'letterSpacing', + if (a.wordSpacing == null && b.wordSpacing == null) 'wordSpacing', + if (a.height == null && b.height == null) 'height', + if (a.decorationColor == null && b.decorationColor == null) 'decorationColor', + if (a.decorationThickness == null && b.decorationThickness == null) 'decorationThickness', + ]; + if (nullFields.isEmpty) { + return true; + } + + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Failed to interpolate TextStyles with different inherit values.'), + ErrorSpacer(), + ErrorDescription('The TextStyles being interpolated were:'), + a.toDiagnosticsNode(name: 'from', style: DiagnosticsTreeStyle.singleLine), + b.toDiagnosticsNode(name: 'to', style: DiagnosticsTreeStyle.singleLine), + ErrorDescription( + 'The following fields are unspecified in both TextStyles:\n' + '${nullFields.map((String name) => '"$name"').join(', ')}.\n' + 'When "inherit" changes during the transition, these fields may ' + 'observe abrupt value changes as a result, causing "jump"s in the ' + 'transition.' + ), + ErrorSpacer(), + ErrorHint( + 'In general, TextStyle.lerp only works well when both TextStyles have ' + 'the same "inherit" value, and specify the same fields.', + ), + ErrorHint( + 'If the TextStyles were directly created by you, consider bringing ' + 'them to parity to ensure a smooth transition.' + ), + ErrorSpacer(), + ErrorHint( + 'If one of the TextStyles being lerped is significantly more elaborate ' + 'than the other, and has "inherited" set to false, it is often because ' + 'it is merged with another TextStyle before being lerped. Comparing ' + 'the "debugLabel"s of the two TextStyles may help identify if that was ' + 'the case.' + ), + ErrorHint( + 'For example, you may see this error message when trying to lerp ' + 'between "ThemeData()" and "Theme.of(context)". This is because ' + 'TextStyles from "Theme.of(context)" are merged with TextStyles from ' + 'another theme and thus are more elaborate than the TextStyles from ' + '"ThemeData()" (which is reflected in their "debugLabel"s -- ' + 'TextStyles from "Theme.of(context)" should have labels in the form of ' + '"(<A TextStyle>).merge(<Another TextStyle>)"). It is recommended to ' + 'only lerp ThemeData with matching TextStyles.' + ), + ]); + }()); + + return TextStyle( + inherit: t < 0.5 ? a.inherit : b.inherit, + color: a.foreground == null && b.foreground == null ? Color.lerp(a.color, b.color, t) : null, + backgroundColor: a.background == null && b.background == null ? Color.lerp(a.backgroundColor, b.backgroundColor, t) : null, + fontSize: ui.lerpDouble(a.fontSize ?? b.fontSize, b.fontSize ?? a.fontSize, t), + fontWeight: FontWeight.lerp(a.fontWeight, b.fontWeight, t), + fontStyle: t < 0.5 ? a.fontStyle : b.fontStyle, + letterSpacing: ui.lerpDouble(a.letterSpacing ?? b.letterSpacing, b.letterSpacing ?? a.letterSpacing, t), + wordSpacing: ui.lerpDouble(a.wordSpacing ?? b.wordSpacing, b.wordSpacing ?? a.wordSpacing, t), + textBaseline: t < 0.5 ? a.textBaseline : b.textBaseline, + height: ui.lerpDouble(a.height ?? b.height, b.height ?? a.height, t), + leadingDistribution: t < 0.5 ? a.leadingDistribution : b.leadingDistribution, + locale: t < 0.5 ? a.locale : b.locale, + foreground: (a.foreground != null || b.foreground != null) + ? t < 0.5 + ? a.foreground ?? (Paint()..color = a.color!) + : b.foreground ?? (Paint()..color = b.color!) + : null, + background: (a.background != null || b.background != null) + ? t < 0.5 + ? a.background ?? (Paint()..color = a.backgroundColor!) + : b.background ?? (Paint()..color = b.backgroundColor!) + : null, + shadows: t < 0.5 ? a.shadows : b.shadows, + fontFeatures: t < 0.5 ? a.fontFeatures : b.fontFeatures, + fontVariations: lerpFontVariations(a.fontVariations, b.fontVariations, t), + decoration: t < 0.5 ? a.decoration : b.decoration, + decorationColor: Color.lerp(a.decorationColor, b.decorationColor, t), + decorationStyle: t < 0.5 ? a.decorationStyle : b.decorationStyle, + decorationThickness: ui.lerpDouble(a.decorationThickness ?? b.decorationThickness, b.decorationThickness ?? a.decorationThickness, t), + debugLabel: lerpDebugLabel, + fontFamily: t < 0.5 ? a._fontFamily : b._fontFamily, + fontFamilyFallback: t < 0.5 ? a._fontFamilyFallback : b._fontFamilyFallback, + package: t < 0.5 ? a._package : b._package, + overflow: t < 0.5 ? a.overflow : b.overflow, + ); + } + + /// The style information for text runs, encoded for use by `dart:ui`. + ui.TextStyle getTextStyle({ + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double textScaleFactor = 1.0, + TextScaler textScaler = TextScaler.noScaling, + }) { + assert( + identical(textScaler, TextScaler.noScaling) || textScaleFactor == 1.0, + 'textScaleFactor is deprecated and cannot be specified when textScaler is specified.', + ); + final double? fontSize = switch (this.fontSize) { + null => null, + final double size when textScaler == TextScaler.noScaling => size * textScaleFactor, + final double size => textScaler.scale(size), + }; + return ui.TextStyle( + color: color, + decoration: decoration, + decorationColor: decorationColor, + decorationStyle: decorationStyle, + decorationThickness: decorationThickness, + fontWeight: fontWeight, + fontStyle: fontStyle, + textBaseline: textBaseline, + leadingDistribution: leadingDistribution, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + fontSize: fontSize, + letterSpacing: letterSpacing, + wordSpacing: wordSpacing, + height: height, + locale: locale, + foreground: foreground, + background: switch ((background, backgroundColor)) { + (final Paint paint, _) => paint, + (_, final Color color) => Paint()..color = color, + _ => null, + }, + shadows: shadows, + fontFeatures: fontFeatures, + fontVariations: fontVariations, + ); + } + + /// The style information for paragraphs, encoded for use by `dart:ui`. + /// + /// If the `textScaleFactor` argument is omitted, it defaults to one. The + /// other arguments may be null. The `maxLines` argument, if specified and + /// non-null, must be greater than zero. + /// + /// If the font size on this style isn't set, it will default to 14 logical + /// pixels. + ui.ParagraphStyle getParagraphStyle({ + TextAlign? textAlign, + TextDirection? textDirection, + TextScaler textScaler = TextScaler.noScaling, + String? ellipsis, + int? maxLines, + TextHeightBehavior? textHeightBehavior, + Locale? locale, + String? fontFamily, + double? fontSize, + FontWeight? fontWeight, + FontStyle? fontStyle, + double? height, + StrutStyle? strutStyle, + }) { + assert(maxLines == null || maxLines > 0); + final TextLeadingDistribution? leadingDistribution = this.leadingDistribution; + final TextHeightBehavior? effectiveTextHeightBehavior = textHeightBehavior + ?? (leadingDistribution == null ? null : TextHeightBehavior(leadingDistribution: leadingDistribution)); + + return ui.ParagraphStyle( + textAlign: textAlign, + textDirection: textDirection, + // Here, we establish the contents of this TextStyle as the paragraph's default font + // unless an override is passed in. + fontWeight: fontWeight ?? this.fontWeight, + fontStyle: fontStyle ?? this.fontStyle, + fontFamily: fontFamily ?? this.fontFamily, + fontSize: textScaler.scale(fontSize ?? this.fontSize ?? kDefaultFontSize), + height: height ?? this.height, + textHeightBehavior: effectiveTextHeightBehavior, + strutStyle: strutStyle == null ? null : ui.StrutStyle( + fontFamily: strutStyle.fontFamily, + fontFamilyFallback: strutStyle.fontFamilyFallback, + fontSize: switch (strutStyle.fontSize) { + null => null, + final double unscaled => textScaler.scale(unscaled), + }, + height: strutStyle.height, + leading: strutStyle.leading, + fontWeight: strutStyle.fontWeight, + fontStyle: strutStyle.fontStyle, + forceStrutHeight: strutStyle.forceStrutHeight, + ), + maxLines: maxLines, + ellipsis: ellipsis, + locale: locale, + ); + } + + /// Describe the difference between this style and another, in terms of how + /// much damage it will make to the rendering. + /// + /// See also: + /// + /// * [TextSpan.compareTo], which does the same thing for entire [TextSpan]s. + RenderComparison compareTo(TextStyle other) { + if (identical(this, other)) { + return RenderComparison.identical; + } + if (inherit != other.inherit || + fontFamily != other.fontFamily || + fontSize != other.fontSize || + fontWeight != other.fontWeight || + fontStyle != other.fontStyle || + letterSpacing != other.letterSpacing || + wordSpacing != other.wordSpacing || + textBaseline != other.textBaseline || + height != other.height || + leadingDistribution != other.leadingDistribution || + locale != other.locale || + foreground != other.foreground || + background != other.background || + !listEquals(shadows, other.shadows) || + !listEquals(fontFeatures, other.fontFeatures) || + !listEquals(fontVariations, other.fontVariations) || + !listEquals(fontFamilyFallback, other.fontFamilyFallback) || + overflow != other.overflow) { + return RenderComparison.layout; + } + if (color != other.color || + backgroundColor != other.backgroundColor || + decoration != other.decoration || + decorationColor != other.decorationColor || + decorationStyle != other.decorationStyle || + decorationThickness != other.decorationThickness) { + return RenderComparison.paint; + } + return RenderComparison.identical; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is TextStyle + && other.inherit == inherit + && other.color == color + && other.backgroundColor == backgroundColor + && other.fontSize == fontSize + && other.fontWeight == fontWeight + && other.fontStyle == fontStyle + && other.letterSpacing == letterSpacing + && other.wordSpacing == wordSpacing + && other.textBaseline == textBaseline + && other.height == height + && other.leadingDistribution == leadingDistribution + && other.locale == locale + && other.foreground == foreground + && other.background == background + && listEquals(other.shadows, shadows) + && listEquals(other.fontFeatures, fontFeatures) + && listEquals(other.fontVariations, fontVariations) + && other.decoration == decoration + && other.decorationColor == decorationColor + && other.decorationStyle == decorationStyle + && other.decorationThickness == decorationThickness + && other.fontFamily == fontFamily + && listEquals(other.fontFamilyFallback, fontFamilyFallback) + && other._package == _package + && other.overflow == overflow; + } + + @override + int get hashCode { + final List<String>? fontFamilyFallback = this.fontFamilyFallback; + final int fontHash = Object.hash( + decorationStyle, + decorationThickness, + fontFamily, + fontFamilyFallback == null ? null : Object.hashAll(fontFamilyFallback), + _package, + overflow, + ); + + final List<Shadow>? shadows = this.shadows; + final List<FontFeature>? fontFeatures = this.fontFeatures; + final List<FontVariation>? fontVariations = this.fontVariations; + return Object.hash( + inherit, + color, + backgroundColor, + fontSize, + fontWeight, + fontStyle, + letterSpacing, + wordSpacing, + textBaseline, + height, + leadingDistribution, + locale, + foreground, + background, + shadows == null ? null : Object.hashAll(shadows), + fontFeatures == null ? null : Object.hashAll(fontFeatures), + fontVariations == null ? null : Object.hashAll(fontVariations), + decoration, + decorationColor, + fontHash, + ); + } + + @override + String toStringShort() => objectRuntimeType(this, 'TextStyle'); + + /// Adds all properties prefixing property names with the optional `prefix`. + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties, { String prefix = '' }) { + super.debugFillProperties(properties); + if (debugLabel != null) { + properties.add(MessageProperty('${prefix}debugLabel', debugLabel!)); + } + final List<DiagnosticsNode> styles = <DiagnosticsNode>[ + ColorProperty('${prefix}color', color, defaultValue: null), + ColorProperty('${prefix}backgroundColor', backgroundColor, defaultValue: null), + StringProperty('${prefix}family', fontFamily, defaultValue: null, quoted: false), + IterableProperty<String>('${prefix}familyFallback', fontFamilyFallback, defaultValue: null), + DoubleProperty('${prefix}size', fontSize, defaultValue: null), + ]; + String? weightDescription; + if (fontWeight != null) { + weightDescription = '${fontWeight!.index + 1}00'; + } + // TODO(jacobr): switch this to use enumProperty which will either cause the + // weight description to change to w600 from 600 or require existing + // enumProperty to handle this special case. + styles.add(DiagnosticsProperty<FontWeight>( + '${prefix}weight', + fontWeight, + description: weightDescription, + defaultValue: null, + )); + styles.add(EnumProperty<FontStyle>('${prefix}style', fontStyle, defaultValue: null)); + styles.add(DoubleProperty('${prefix}letterSpacing', letterSpacing, defaultValue: null)); + styles.add(DoubleProperty('${prefix}wordSpacing', wordSpacing, defaultValue: null)); + styles.add(EnumProperty<TextBaseline>('${prefix}baseline', textBaseline, defaultValue: null)); + styles.add(DoubleProperty('${prefix}height', height, unit: 'x', defaultValue: null)); + styles.add(EnumProperty<TextLeadingDistribution>('${prefix}leadingDistribution', leadingDistribution, defaultValue: null)); + styles.add(DiagnosticsProperty<Locale>('${prefix}locale', locale, defaultValue: null)); + styles.add(DiagnosticsProperty<Paint>('${prefix}foreground', foreground, defaultValue: null)); + styles.add(DiagnosticsProperty<Paint>('${prefix}background', background, defaultValue: null)); + if (decoration != null || decorationColor != null || decorationStyle != null || decorationThickness != null) { + final List<String> decorationDescription = <String>[]; + if (decorationStyle != null) { + decorationDescription.add(decorationStyle!.name); + } + + // Hide decorationColor from the default text view as it is shown in the + // terse decoration summary as well. + styles.add(ColorProperty('${prefix}decorationColor', decorationColor, defaultValue: null, level: DiagnosticLevel.fine)); + + if (decorationColor != null) { + decorationDescription.add('$decorationColor'); + } + + // Intentionally collide with the property 'decoration' added below. + // Tools that show hidden properties could choose the first property + // matching the name to disambiguate. + styles.add(DiagnosticsProperty<TextDecoration>('${prefix}decoration', decoration, defaultValue: null, level: DiagnosticLevel.hidden)); + if (decoration != null) { + decorationDescription.add('$decoration'); + } + assert(decorationDescription.isNotEmpty); + styles.add(MessageProperty('${prefix}decoration', decorationDescription.join(' '))); + styles.add(DoubleProperty('${prefix}decorationThickness', decorationThickness, unit: 'x', defaultValue: null)); + } + + final bool styleSpecified = styles.any((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info)); + properties.add(DiagnosticsProperty<bool>('${prefix}inherit', inherit, level: (!styleSpecified && inherit) ? DiagnosticLevel.fine : DiagnosticLevel.info)); + styles.forEach(properties.add); + + if (!styleSpecified) { + properties.add(FlagProperty('inherit', value: inherit, ifTrue: '$prefix<all styles inherited>', ifFalse: '$prefix<no style specified>')); + } + + styles.add(EnumProperty<TextOverflow>('${prefix}overflow', overflow, defaultValue: null)); + } +} + +/// Interpolate between two lists of [FontVariation] objects. +/// +/// Variations are paired by axis, and interpolated using [FontVariation.lerp]. +/// +/// Entries that are only present in one list are animated using a step-function +/// at t=0.5 that enables or disables the variation. This can be jarring and +/// largely defeats the point of animating font variations. For best results, +/// specify the same axes in both lists, and for best performance, specify them +/// in the same order. +/// +/// ## Performance details +/// +/// This algorithm is O(N), but the constant factor varies based on the input, +/// and that is probably more important (because typically N is going to be +/// tiny, like 1 or 2; at the time of writing, there are only about five defined +/// axes that fonts typically use!). +/// +/// It is fastest when the lists contain the same axes ([FontVariation.axis]) in +/// the same order. The result is again in the same order, and no attempt is +/// made to detect or remove duplicates in this process. This is, by far, the +/// recommended way to use this algorithm. +/// +/// When the order of items in the two input lists vary, the constant factor +/// increases substantially, as it involves creating two maps and a set, +/// inserting every variation in both lists into the maps and the set, and then +/// iterating over them to recreate the list. +/// +/// In this case, the resulting order is arbitrary. Duplicates are dropped; in +/// each list, the last [FontVariation] for any particular axis is the one used +/// to compute the value for that axis. Values that only appear on one side are +/// interpolated using [FontVariation.lerp] against a null value, and resulting +/// null values are omitted from the resulting list. +/// +/// When the lists begin with matching pairs of axes, the fast algorithm is used +/// up to the point where the lists diverge, and the more expensive algorithm +/// is used on the remaining entries. +/// +/// See also: +/// +/// * [TextStyle.lerp], which uses this function to handle +/// [TextStyle.fontVariations]. +List<FontVariation>? lerpFontVariations(List<FontVariation>? a, List<FontVariation>? b, double t) { + if (t == 0.0) { + return a; + } + if (t == 1.0) { + return b; + } + if (a == null || a.isEmpty || b == null || b.isEmpty) { + // If one side is empty, that means anything on the other + // side will use the null-to-something lerp, which is to + // say, a step function at t=0.5. + return t < 0.5 ? a : b; + } + assert(a.isNotEmpty && b.isNotEmpty); + final List<FontVariation> result = <FontVariation>[]; + // First, try the efficient O(N) solution in the event that + // the lists are compatible. + int index = 0; + final int minLength = a.length < b.length ? a.length : b.length; + for (; index < minLength; index += 1) { + if (a[index].axis != b[index].axis) { + // The lists aren't compatible. + break; + } + result.add(FontVariation.lerp(a[index], b[index], t)!); + } + final int maxLength = a.length > b.length ? a.length : b.length; + if (index < maxLength) { + // If we get here, we have found some case where we cannot + // use the efficient approach. + final Set<String> axes = HashSet<String>(); + final Map<String, FontVariation> aVariations = HashMap<String, FontVariation>(); + for (int indexA = index; indexA < a.length; indexA += 1) { + aVariations[a[indexA].axis] = a[indexA]; + axes.add(a[indexA].axis); + } + final Map<String, FontVariation> bVariations = HashMap<String, FontVariation>(); + for (int indexB = index; indexB < b.length; indexB += 1) { + bVariations[b[indexB].axis] = b[indexB]; + axes.add(b[indexB].axis); + } + for (final String axis in axes) { + final FontVariation? variation = FontVariation.lerp(aVariations[axis], bVariations[axis], t); + if (variation != null) { + result.add(variation); + } + } + } + return result; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/clamped_simulation.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/clamped_simulation.dart new file mode 100644 index 0000000000000000000000000000000000000000..dfd889d284a19293d1cd06c5cc9abe62dfab0243 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/clamped_simulation.dart @@ -0,0 +1,69 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'simulation.dart'; + +export 'simulation.dart' show Simulation; + +/// A simulation that applies limits to another simulation. +/// +/// The limits are only applied to the other simulation's outputs. For example, +/// if a maximum position was applied to a gravity simulation with the +/// particle's initial velocity being up, and the acceleration being down, and +/// the maximum position being between the initial position and the curve's +/// apogee, then the particle would return to its initial position in the same +/// amount of time as it would have if the maximum had not been applied; the +/// difference would just be that the position would be reported as pinned to +/// the maximum value for the times that it would otherwise have been reported +/// as higher. +/// +/// Similarly, this means that the [x] value will change at a rate that does not +/// match the reported [dx] value while one or the other is being clamped. +/// +/// The [isDone] logic is unaffected by the clamping; it reflects the logic of +/// the underlying simulation. +class ClampedSimulation extends Simulation { + /// Creates a [ClampedSimulation] that clamps the given simulation. + /// + /// The named arguments specify the ranges for the clamping behavior, as + /// applied to [x] and [dx]. + ClampedSimulation( + this.simulation, { + this.xMin = double.negativeInfinity, + this.xMax = double.infinity, + this.dxMin = double.negativeInfinity, + this.dxMax = double.infinity, + }) : assert(xMax >= xMin), + assert(dxMax >= dxMin); + + /// The simulation being clamped. Calls to [x], [dx], and [isDone] are + /// forwarded to the simulation. + final Simulation simulation; + + /// The minimum to apply to [x]. + final double xMin; + + /// The maximum to apply to [x]. + final double xMax; + + /// The minimum to apply to [dx]. + final double dxMin; + + /// The maximum to apply to [dx]. + final double dxMax; + + @override + double x(double time) => clampDouble(simulation.x(time), xMin, xMax); + + @override + double dx(double time) => clampDouble(simulation.dx(time), dxMin, dxMax); + + @override + bool isDone(double time) => simulation.isDone(time); + + @override + String toString() => '${objectRuntimeType(this, 'ClampedSimulation')}(simulation: $simulation, x: ${xMin.toStringAsFixed(1)}..${xMax.toStringAsFixed(1)}, dx: ${dxMin.toStringAsFixed(1)}..${dxMax.toStringAsFixed(1)})'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/friction_simulation.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/friction_simulation.dart new file mode 100644 index 0000000000000000000000000000000000000000..e51ca9e9700ed767f8e25a39f499c06a187a033e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/friction_simulation.dart @@ -0,0 +1,195 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'simulation.dart'; + +export 'tolerance.dart' show Tolerance; + +/// Numerically determine the input value which produces output value [target] +/// for a function [f], given its first-derivative [df]. +double _newtonsMethod({ + required double initialGuess, + required double target, + required double Function(double) f, + required double Function(double) df, + required int iterations +}) { + double guess = initialGuess; + for (int i = 0; i < iterations; i++) { + guess = guess - (f(guess) - target) / df(guess); + } + return guess; +} + +/// A simulation that applies a drag to slow a particle down. +/// +/// Models a particle affected by fluid drag, e.g. air resistance. +/// +/// The simulation ends when the velocity of the particle drops to zero (within +/// the current velocity [tolerance]). +class FrictionSimulation extends Simulation { + /// Creates a [FrictionSimulation] with the given arguments, namely: the fluid + /// drag coefficient _cₓ_, a unitless value; the initial position _x₀_, in the same + /// length units as used for [x]; and the initial velocity _dx₀_, in the same + /// velocity units as used for [dx]. + FrictionSimulation( + double drag, + double position, + double velocity, { + super.tolerance, + double constantDeceleration = 0 + }) : _drag = drag, + _dragLog = math.log(drag), + _x = position, + _v = velocity, + _constantDeceleration = constantDeceleration * velocity.sign { + _finalTime = _newtonsMethod( + initialGuess: 0, + target: 0, + f: dx, + df: (double time) => (_v * math.pow(_drag, time) * _dragLog) - _constantDeceleration, + iterations: 10 + ); + } + + /// Creates a new friction simulation with its fluid drag coefficient (_cₓ_) set so + /// as to ensure that the simulation starts and ends at the specified + /// positions and velocities. + /// + /// The positions must use the same units as expected from [x], and the + /// velocities must use the same units as expected from [dx]. + /// + /// The sign of the start and end velocities must be the same, the magnitude + /// of the start velocity must be greater than the magnitude of the end + /// velocity, and the velocities must be in the direction appropriate for the + /// particle to start from the start position and reach the end position. + factory FrictionSimulation.through(double startPosition, double endPosition, double startVelocity, double endVelocity) { + assert(startVelocity == 0.0 || endVelocity == 0.0 || startVelocity.sign == endVelocity.sign); + assert(startVelocity.abs() >= endVelocity.abs()); + assert((endPosition - startPosition).sign == startVelocity.sign); + return FrictionSimulation( + _dragFor(startPosition, endPosition, startVelocity, endVelocity), + startPosition, + startVelocity, + tolerance: Tolerance(velocity: endVelocity.abs()), + ); + } + + final double _drag; + final double _dragLog; + final double _x; + final double _v; + final double _constantDeceleration; + // The time at which the simulation should be stopped. + // This is needed when constantDeceleration is not zero (on Desktop), when + // using the pure friction simulation, acceleration naturally reduces to zero + // and creates a stopping point. + double _finalTime = double.infinity; // needs to be infinity for newtonsMethod call in constructor. + + // Return the drag value for a FrictionSimulation whose x() and dx() values pass + // through the specified start and end position/velocity values. + // + // Total time to reach endVelocity is just: (log(endVelocity) / log(startVelocity)) / log(_drag) + // or (log(v1) - log(v0)) / log(D), given v = v0 * D^t per the dx() function below. + // Solving for D given x(time) is trickier. Algebra courtesy of Wolfram Alpha: + // x1 = x0 + (v0 * D^((log(v1) - log(v0)) / log(D))) / log(D) - v0 / log(D), find D + static double _dragFor(double startPosition, double endPosition, double startVelocity, double endVelocity) { + return math.pow(math.e, (startVelocity - endVelocity) / (startPosition - endPosition)) as double; + } + + @override + double x(double time) { + if (time > _finalTime) { + return finalX; + } + return _x + _v * math.pow(_drag, time) / _dragLog - _v / _dragLog - ((_constantDeceleration / 2) * time * time); + } + + @override + double dx(double time) { + if (time > _finalTime) { + return 0; + } + return _v * math.pow(_drag, time) - _constantDeceleration * time; + } + + /// The value of [x] at `double.infinity`. + double get finalX { + if (_constantDeceleration == 0) { + return _x - _v / _dragLog; + } + return x(_finalTime); + } + + /// The time at which the value of `x(time)` will equal [x]. + /// + /// Returns `double.infinity` if the simulation will never reach [x]. + double timeAtX(double x) { + if (x == _x) { + return 0.0; + } + if (_v == 0.0 || (_v > 0 ? (x < _x || x > finalX) : (x > _x || x < finalX))) { + return double.infinity; + } + return _newtonsMethod( + target: x, + initialGuess: 0, + f: this.x, + df: dx, + iterations: 10 + ); + } + + @override + bool isDone(double time) { + return dx(time).abs() < tolerance.velocity; + } + + @override + String toString() => '${objectRuntimeType(this, 'FrictionSimulation')}(cₓ: ${_drag.toStringAsFixed(1)}, x₀: ${_x.toStringAsFixed(1)}, dx₀: ${_v.toStringAsFixed(1)})'; +} + +/// A [FrictionSimulation] that clamps the modeled particle to a specific range +/// of values. +/// +/// Only the position is clamped. The velocity [dx] will continue to report +/// unbounded simulated velocities once the particle has reached the bounds. +class BoundedFrictionSimulation extends FrictionSimulation { + /// Creates a [BoundedFrictionSimulation] with the given arguments, namely: + /// the fluid drag coefficient _cₓ_, a unitless value; the initial position _x₀_, in the + /// same length units as used for [x]; the initial velocity _dx₀_, in the same + /// velocity units as used for [dx], the minimum value for the position, and + /// the maximum value for the position. The minimum and maximum values must be + /// in the same units as the initial position, and the initial position must + /// be within the given range. + BoundedFrictionSimulation( + super.drag, + super.position, + super.velocity, + this._minX, + this._maxX, + ) : assert(clampDouble(position, _minX, _maxX) == position); + + final double _minX; + final double _maxX; + + @override + double x(double time) { + return clampDouble(super.x(time), _minX, _maxX); + } + + @override + bool isDone(double time) { + return super.isDone(time) || + (x(time) - _minX).abs() < tolerance.distance || + (x(time) - _maxX).abs() < tolerance.distance; + } + + @override + String toString() => '${objectRuntimeType(this, 'BoundedFrictionSimulation')}(cₓ: ${_drag.toStringAsFixed(1)}, x₀: ${_x.toStringAsFixed(1)}, dx₀: ${_v.toStringAsFixed(1)}, x: ${_minX.toStringAsFixed(1)}..${_maxX.toStringAsFixed(1)})'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/gravity_simulation.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/gravity_simulation.dart new file mode 100644 index 0000000000000000000000000000000000000000..56f02ed933a315db405321f3b1772f141818441f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/gravity_simulation.dart @@ -0,0 +1,95 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'simulation.dart'; + +// Examples can assume: +// late AnimationController _controller; + +/// A simulation that applies a constant accelerating force. +/// +/// Models a particle that follows Newton's second law of motion. The simulation +/// ends when the position exceeds a defined threshold. +/// +/// {@tool snippet} +/// +/// This method triggers an [AnimationController] (a previously constructed +/// `_controller` field) to simulate a fall of 300 pixels. +/// +/// ```dart +/// void _startFall() { +/// _controller.animateWith(GravitySimulation( +/// 10.0, // acceleration, pixels per second per second +/// 0.0, // starting position, pixels +/// 300.0, // ending position, pixels +/// 0.0, // starting velocity, pixels per second +/// )); +/// } +/// ``` +/// {@end-tool} +/// +/// This [AnimationController] could be used with an [AnimatedBuilder] to +/// animate the position of a child as if it was falling. +/// +/// The end distance threshold (the constructor's third argument) must be +/// specified as a positive number but can be reached in either the positive or +/// negative direction. For example (assuming negative numbers represent higher +/// physical positions than positive numbers, as is the case with the normal +/// [Canvas] coordinate system), if the acceleration is positive ("down") the +/// starting velocity is negative ("up"), and the starting distance is zero, the +/// particle will climb from the origin, reach a plateau, then fall back towards +/// and past the origin. If the end distance threshold is less than the height +/// of the plateau, then the simulation will end during the climb; otherwise, it +/// will end during the fall, after the particle travels below the origin by +/// that distance. +/// +/// See also: +/// +/// * [Curves.bounceOut], a [Curve] that has a similar aesthetics but includes +/// a bouncing effect. +class GravitySimulation extends Simulation { + /// Creates a [GravitySimulation] using the given arguments, which are, + /// respectively: an acceleration that is to be applied continually over time; + /// an initial position relative to an origin; the magnitude of the distance + /// from that origin beyond which (in either direction) to consider the + /// simulation to be "done", which must be positive; and an initial velocity. + /// + /// The initial position and maximum distance are measured in arbitrary length + /// units L from an arbitrary origin. The units will match those used for [x]. + /// + /// The time unit T used for the arguments to [x], [dx], and [isDone], + /// combined with the aforementioned length unit, together determine the units + /// that must be used for the velocity and acceleration arguments: L/T and + /// L/T² respectively. The same units of velocity are used for the velocity + /// obtained from [dx]. + GravitySimulation( + double acceleration, + double distance, + double endDistance, + double velocity, + ) : assert(endDistance >= 0), + _a = acceleration, + _x = distance, + _v = velocity, + _end = endDistance; + + final double _x; + final double _v; + final double _a; + final double _end; + + @override + double x(double time) => _x + _v * time + 0.5 * _a * time * time; + + @override + double dx(double time) => _v + time * _a; + + @override + bool isDone(double time) => x(time).abs() >= _end; + + @override + String toString() => '${objectRuntimeType(this, 'GravitySimulation')}(g: ${_a.toStringAsFixed(1)}, x₀: ${_x.toStringAsFixed(1)}, dx₀: ${_v.toStringAsFixed(1)}, xₘₐₓ: ±${_end.toStringAsFixed(1)})'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/simulation.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/simulation.dart new file mode 100644 index 0000000000000000000000000000000000000000..adc61f50d07229858d3a8765687d385b61ec6c4c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/simulation.dart @@ -0,0 +1,60 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'tolerance.dart'; + +export 'tolerance.dart' show Tolerance; + +/// The base class for all simulations. +/// +/// A simulation models an object, in a one-dimensional space, on which particular +/// forces are being applied, and exposes: +/// +/// * The object's position, [x] +/// * The object's velocity, [dx] +/// * Whether the simulation is "done", [isDone] +/// +/// A simulation is generally "done" if the object has, to a given [tolerance], +/// come to a complete rest. +/// +/// The [x], [dx], and [isDone] functions take a time argument which specifies +/// the time for which they are to be evaluated. In principle, simulations can +/// be stateless, and thus can be queried with arbitrary times. In practice, +/// however, some simulations are not, and calling any of these functions will +/// advance the simulation to the given time. +/// +/// As a general rule, therefore, a simulation should only be queried using +/// times that are equal to or greater than all times previously used for that +/// simulation. +/// +/// Simulations do not specify units for distance, velocity, and time. Client +/// should establish a convention and use that convention consistently with all +/// related objects. +abstract class Simulation { + /// Initializes the [tolerance] field for subclasses. + Simulation({ this.tolerance = Tolerance.defaultTolerance }); + + /// The position of the object in the simulation at the given time. + double x(double time); + + /// The velocity of the object in the simulation at the given time. + double dx(double time); + + /// Whether the simulation is "done" at the given time. + bool isDone(double time); + + /// How close to the actual end of the simulation a value at a particular time + /// must be before [isDone] considers the simulation to be "done". + /// + /// A simulation with an asymptotic curve would never technically be "done", + /// but once the difference from the value at a particular time and the + /// asymptote itself could not be seen, it would be pointless to continue. The + /// tolerance defines how to determine if the difference could not be seen. + Tolerance tolerance; + + @override + String toString() => objectRuntimeType(this, 'Simulation'); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/spring_simulation.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/spring_simulation.dart new file mode 100644 index 0000000000000000000000000000000000000000..a1675239223e1742e7b8b9549469c7725668f26f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/spring_simulation.dart @@ -0,0 +1,282 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'simulation.dart'; +import 'utils.dart'; + +export 'tolerance.dart' show Tolerance; + +/// Structure that describes a spring's constants. +/// +/// Used to configure a [SpringSimulation]. +class SpringDescription { + /// Creates a spring given the mass, stiffness, and the damping coefficient. + /// + /// See [mass], [stiffness], and [damping] for the units of the arguments. + const SpringDescription({ + required this.mass, + required this.stiffness, + required this.damping, + }); + + /// Creates a spring given the mass (m), stiffness (k), and damping ratio (ζ). + /// The damping ratio is especially useful trying to determining the type of + /// spring to create. A ratio of 1.0 creates a critically damped spring, > 1.0 + /// creates an overdamped spring and < 1.0 an underdamped one. + /// + /// See [mass] and [stiffness] for the units for those arguments. The damping + /// ratio is unitless. + SpringDescription.withDampingRatio({ + required this.mass, + required this.stiffness, + double ratio = 1.0, + }) : damping = ratio * 2.0 * math.sqrt(mass * stiffness); + + /// The mass of the spring (m). The units are arbitrary, but all springs + /// within a system should use the same mass units. + final double mass; + + /// The spring constant (k). The units of stiffness are M/T², where M is the + /// mass unit used for the value of the [mass] property, and T is the time + /// unit used for driving the [SpringSimulation]. + final double stiffness; + + /// The damping coefficient (c). + /// + /// Do not confuse the damping _coefficient_ (c) with the damping _ratio_ (ζ). + /// To create a [SpringDescription] with a damping ratio, use the [ + /// SpringDescription.withDampingRatio] constructor. + /// + /// The units of the damping coefficient are M/T, where M is the mass unit + /// used for the value of the [mass] property, and T is the time unit used for + /// driving the [SpringSimulation]. + final double damping; + + @override + String toString() => '${objectRuntimeType(this, 'SpringDescription')}(mass: ${mass.toStringAsFixed(1)}, stiffness: ${stiffness.toStringAsFixed(1)}, damping: ${damping.toStringAsFixed(1)})'; +} + +/// The kind of spring solution that the [SpringSimulation] is using to simulate the spring. +/// +/// See [SpringSimulation.type]. +enum SpringType { + /// A spring that does not bounce and returns to its rest position in the + /// shortest possible time. + criticallyDamped, + + /// A spring that bounces. + underDamped, + + /// A spring that does not bounce but takes longer to return to its rest + /// position than a [criticallyDamped] one. + overDamped, +} + +/// A spring simulation. +/// +/// Models a particle attached to a spring that follows Hooke's law. +class SpringSimulation extends Simulation { + /// Creates a spring simulation from the provided spring description, start + /// distance, end distance, and initial velocity. + /// + /// The units for the start and end distance arguments are arbitrary, but must + /// be consistent with the units used for other lengths in the system. + /// + /// The units for the velocity are L/T, where L is the aforementioned + /// arbitrary unit of length, and T is the time unit used for driving the + /// [SpringSimulation]. + SpringSimulation( + SpringDescription spring, + double start, + double end, + double velocity, { + super.tolerance, + }) : _endPosition = end, + _solution = _SpringSolution(spring, start - end, velocity); + + final double _endPosition; + final _SpringSolution _solution; + + /// The kind of spring being simulated, for debugging purposes. + /// + /// This is derived from the [SpringDescription] provided to the [ + /// SpringSimulation] constructor. + SpringType get type => _solution.type; + + @override + double x(double time) => _endPosition + _solution.x(time); + + @override + double dx(double time) => _solution.dx(time); + + @override + bool isDone(double time) { + return nearZero(_solution.x(time), tolerance.distance) && + nearZero(_solution.dx(time), tolerance.velocity); + } + + @override + String toString() => '${objectRuntimeType(this, 'SpringSimulation')}(end: ${_endPosition.toStringAsFixed(1)}, $type)'; +} + +/// A [SpringSimulation] where the value of [x] is guaranteed to have exactly the +/// end value when the simulation [isDone]. +class ScrollSpringSimulation extends SpringSimulation { + /// Creates a spring simulation from the provided spring description, start + /// distance, end distance, and initial velocity. + /// + /// See the [SpringSimulation.new] constructor on the superclass for a + /// discussion of the arguments' units. + ScrollSpringSimulation( + super.spring, + super.start, + super.end, + super.velocity, { + super.tolerance, + }); + + @override + double x(double time) => isDone(time) ? _endPosition : super.x(time); +} + + +// SPRING IMPLEMENTATIONS + +abstract class _SpringSolution { + factory _SpringSolution( + SpringDescription spring, + double initialPosition, + double initialVelocity, + ) { + final double cmk = spring.damping * spring.damping - 4 * spring.mass * spring.stiffness; + if (cmk == 0.0) { + return _CriticalSolution(spring, initialPosition, initialVelocity); + } + if (cmk > 0.0) { + return _OverdampedSolution(spring, initialPosition, initialVelocity); + } + return _UnderdampedSolution(spring, initialPosition, initialVelocity); + } + + double x(double time); + double dx(double time); + SpringType get type; +} + +class _CriticalSolution implements _SpringSolution { + factory _CriticalSolution( + SpringDescription spring, + double distance, + double velocity, + ) { + final double r = -spring.damping / (2.0 * spring.mass); + final double c1 = distance; + final double c2 = velocity - (r * distance); + return _CriticalSolution.withArgs(r, c1, c2); + } + + _CriticalSolution.withArgs(double r, double c1, double c2) + : _r = r, + _c1 = c1, + _c2 = c2; + + final double _r, _c1, _c2; + + @override + double x(double time) { + return (_c1 + _c2 * time) * math.pow(math.e, _r * time); + } + + @override + double dx(double time) { + final double power = math.pow(math.e, _r * time) as double; + return _r * (_c1 + _c2 * time) * power + _c2 * power; + } + + @override + SpringType get type => SpringType.criticallyDamped; +} + +class _OverdampedSolution implements _SpringSolution { + factory _OverdampedSolution( + SpringDescription spring, + double distance, + double velocity, + ) { + final double cmk = spring.damping * spring.damping - 4 * spring.mass * spring.stiffness; + final double r1 = (-spring.damping - math.sqrt(cmk)) / (2.0 * spring.mass); + final double r2 = (-spring.damping + math.sqrt(cmk)) / (2.0 * spring.mass); + final double c2 = (velocity - r1 * distance) / (r2 - r1); + final double c1 = distance - c2; + return _OverdampedSolution.withArgs(r1, r2, c1, c2); + } + + _OverdampedSolution.withArgs(double r1, double r2, double c1, double c2) + : _r1 = r1, + _r2 = r2, + _c1 = c1, + _c2 = c2; + + final double _r1, _r2, _c1, _c2; + + @override + double x(double time) { + return _c1 * math.pow(math.e, _r1 * time) + + _c2 * math.pow(math.e, _r2 * time); + } + + @override + double dx(double time) { + return _c1 * _r1 * math.pow(math.e, _r1 * time) + + _c2 * _r2 * math.pow(math.e, _r2 * time); + } + + @override + SpringType get type => SpringType.overDamped; +} + +class _UnderdampedSolution implements _SpringSolution { + factory _UnderdampedSolution( + SpringDescription spring, + double distance, + double velocity, + ) { + final double w = math.sqrt(4.0 * spring.mass * spring.stiffness - spring.damping * spring.damping) / + (2.0 * spring.mass); + final double r = -(spring.damping / 2.0 * spring.mass); + final double c1 = distance; + final double c2 = (velocity - r * distance) / w; + return _UnderdampedSolution.withArgs(w, r, c1, c2); + } + + _UnderdampedSolution.withArgs(double w, double r, double c1, double c2) + : _w = w, + _r = r, + _c1 = c1, + _c2 = c2; + + final double _w, _r, _c1, _c2; + + @override + double x(double time) { + return (math.pow(math.e, _r * time) as double) * + (_c1 * math.cos(_w * time) + _c2 * math.sin(_w * time)); + } + + @override + double dx(double time) { + final double power = math.pow(math.e, _r * time) as double; + final double cosine = math.cos(_w * time); + final double sine = math.sin(_w * time); + return power * (_c2 * _w * cosine - _c1 * _w * sine) + + _r * power * (_c2 * sine + _c1 * cosine); + } + + @override + SpringType get type => SpringType.underDamped; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/tolerance.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/tolerance.dart new file mode 100644 index 0000000000000000000000000000000000000000..10842dca577a02cd3cb36a32fe64e2c5808f995b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/tolerance.dart @@ -0,0 +1,48 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +/// Structure that specifies maximum allowable magnitudes for distances, +/// durations, and velocity differences to be considered equal. +class Tolerance { + /// Creates a [Tolerance] object. By default, the distance, time, and velocity + /// tolerances are all ±0.001; the constructor arguments override this. + /// + /// The arguments should all be positive values. + const Tolerance({ + this.distance = _epsilonDefault, + this.time = _epsilonDefault, + this.velocity = _epsilonDefault, + }); + + static const double _epsilonDefault = 1e-3; + + /// A default tolerance of 0.001 for all three values. + static const Tolerance defaultTolerance = Tolerance(); + + /// The magnitude of the maximum distance between two points for them to be + /// considered within tolerance. + /// + /// The units for the distance tolerance must be the same as the units used + /// for the distances that are to be compared to this tolerance. + final double distance; + + /// The magnitude of the maximum duration between two times for them to be + /// considered within tolerance. + /// + /// The units for the time tolerance must be the same as the units used + /// for the times that are to be compared to this tolerance. + final double time; + + /// The magnitude of the maximum difference between two velocities for them to + /// be considered within tolerance. + /// + /// The units for the velocity tolerance must be the same as the units used + /// for the velocities that are to be compared to this tolerance. + final double velocity; + + @override + String toString() => '${objectRuntimeType(this, 'Tolerance')}(distance: ±$distance, time: ±$time, velocity: ±$velocity)'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/utils.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/utils.dart new file mode 100644 index 0000000000000000000000000000000000000000..7a8f82ecdff3a7a31e343ee4d05442bf0f2f4c8a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/physics/utils.dart @@ -0,0 +1,21 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Whether two doubles are within a given distance of each other. +/// +/// The `epsilon` argument must be positive and not null. +/// The `a` and `b` arguments may be null. A null value is only considered +/// near-equal to another null value. +bool nearEqual(double? a, double? b, double epsilon) { + assert(epsilon >= 0.0); + if (a == null || b == null) { + return a == b; + } + return (a > (b - epsilon)) && (a < (b + epsilon)) || a == b; +} + +/// Whether a double is within a given distance of zero. +/// +/// The epsilon argument must be positive. +bool nearZero(double a, double epsilon) => nearEqual(a, 0.0, epsilon); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/animated_size.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/animated_size.dart new file mode 100644 index 0000000000000000000000000000000000000000..a2ba25aafb7a1aa32807a18c2efed9ff5cef530a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/animated_size.dart @@ -0,0 +1,420 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'layer.dart'; +import 'object.dart'; +import 'shifted_box.dart'; + +/// A [RenderAnimatedSize] can be in exactly one of these states. +@visibleForTesting +enum RenderAnimatedSizeState { + /// The initial state, when we do not yet know what the starting and target + /// sizes are to animate. + /// + /// The next state is [stable]. + start, + + /// At this state the child's size is assumed to be stable and we are either + /// animating, or waiting for the child's size to change. + /// + /// If the child's size changes, the state will become [changed]. Otherwise, + /// it remains [stable]. + stable, + + /// At this state we know that the child has changed once after being assumed + /// [stable]. + /// + /// The next state will be one of: + /// + /// * [stable] if the child's size stabilized immediately. This is a signal + /// for the render object to begin animating the size towards the child's new + /// size. + /// + /// * [unstable] if the child's size continues to change. + changed, + + /// At this state the child's size is assumed to be unstable (changing each + /// frame). + /// + /// Instead of chasing the child's size in this state, the render object + /// tightly tracks the child's size until it stabilizes. + /// + /// The render object remains in this state until a frame where the child's + /// size remains the same as the previous frame. At that time, the next state + /// is [stable]. + unstable, +} + +/// A render object that animates its size to its child's size over a given +/// [duration] and with a given [curve]. If the child's size itself animates +/// (i.e. if it changes size two frames in a row, as opposed to abruptly +/// changing size in one frame then remaining that size in subsequent frames), +/// this render object sizes itself to fit the child instead of animating +/// itself. +/// +/// When the child overflows the current animated size of this render object, it +/// is clipped. +class RenderAnimatedSize extends RenderAligningShiftedBox { + /// Creates a render object that animates its size to match its child. + /// The [duration] and [curve] arguments define the animation. + /// + /// The [alignment] argument is used to align the child when the parent is not + /// (yet) the same size as the child. + /// + /// The [duration] is required. + /// + /// The [vsync] should specify a [TickerProvider] for the animation + /// controller. + /// + /// The arguments [duration], [curve], [alignment], and [vsync] must + /// not be null. + RenderAnimatedSize({ + required TickerProvider vsync, + required Duration duration, + Duration? reverseDuration, + Curve curve = Curves.linear, + super.alignment, + super.textDirection, + super.child, + Clip clipBehavior = Clip.hardEdge, + VoidCallback? onEnd, + }) : _vsync = vsync, + _clipBehavior = clipBehavior { + _controller = AnimationController( + vsync: vsync, + duration: duration, + reverseDuration: reverseDuration, + )..addListener(() { + if (_controller.value != _lastValue) { + markNeedsLayout(); + } + }); + _animation = CurvedAnimation( + parent: _controller, + curve: curve, + ); + _onEnd = onEnd; + } + + /// When asserts are enabled, returns the animation controller that is used + /// to drive the resizing. + /// + /// Otherwise, returns null. + /// + /// This getter is intended for use in framework unit tests. Applications must + /// not depend on its value. + @visibleForTesting + AnimationController? get debugController { + AnimationController? controller; + assert(() { + controller = _controller; + return true; + }()); + return controller; + } + + /// When asserts are enabled, returns the animation that drives the resizing. + /// + /// Otherwise, returns null. + /// + /// This getter is intended for use in framework unit tests. Applications must + /// not depend on its value. + @visibleForTesting + CurvedAnimation? get debugAnimation { + CurvedAnimation? animation; + assert(() { + animation = _animation; + return true; + }()); + return animation; + } + + late final AnimationController _controller; + late final CurvedAnimation _animation; + + final SizeTween _sizeTween = SizeTween(); + late bool _hasVisualOverflow; + double? _lastValue; + + /// The state this size animation is in. + /// + /// See [RenderAnimatedSizeState] for possible states. + @visibleForTesting + RenderAnimatedSizeState get state => _state; + RenderAnimatedSizeState _state = RenderAnimatedSizeState.start; + + /// The duration of the animation. + Duration get duration => _controller.duration!; + set duration(Duration value) { + if (value == _controller.duration) { + return; + } + _controller.duration = value; + } + + /// The duration of the animation when running in reverse. + Duration? get reverseDuration => _controller.reverseDuration; + set reverseDuration(Duration? value) { + if (value == _controller.reverseDuration) { + return; + } + _controller.reverseDuration = value; + } + + /// The curve of the animation. + Curve get curve => _animation.curve; + set curve(Curve value) { + if (value == _animation.curve) { + return; + } + _animation.curve = value; + } + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.hardEdge; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + /// Whether the size is being currently animated towards the child's size. + /// + /// See [RenderAnimatedSizeState] for situations when we may not be animating + /// the size. + bool get isAnimating => _controller.isAnimating; + + /// The [TickerProvider] for the [AnimationController] that runs the animation. + TickerProvider get vsync => _vsync; + TickerProvider _vsync; + set vsync(TickerProvider value) { + if (value == _vsync) { + return; + } + _vsync = value; + _controller.resync(vsync); + } + + /// Called every time an animation completes. + /// + /// This can be useful to trigger additional actions (e.g. another animation) + /// at the end of the current animation. + VoidCallback? get onEnd => _onEnd; + VoidCallback? _onEnd; + set onEnd(VoidCallback? value) { + if (value == _onEnd) { + return; + } + _onEnd = value; + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + switch (state) { + case RenderAnimatedSizeState.start: + case RenderAnimatedSizeState.stable: + break; + case RenderAnimatedSizeState.changed: + case RenderAnimatedSizeState.unstable: + // Call markNeedsLayout in case the RenderObject isn't marked dirty + // already, to resume interrupted resizing animation. + markNeedsLayout(); + } + _controller.addStatusListener(_animationStatusListener); + } + + @override + void detach() { + _controller.stop(); + _controller.removeStatusListener(_animationStatusListener); + super.detach(); + } + + Size? get _animatedSize { + return _sizeTween.evaluate(_animation); + } + + @override + void performLayout() { + _lastValue = _controller.value; + _hasVisualOverflow = false; + final BoxConstraints constraints = this.constraints; + if (child == null || constraints.isTight) { + _controller.stop(); + size = _sizeTween.begin = _sizeTween.end = constraints.smallest; + _state = RenderAnimatedSizeState.start; + child?.layout(constraints); + return; + } + + child!.layout(constraints, parentUsesSize: true); + + switch (_state) { + case RenderAnimatedSizeState.start: + _layoutStart(); + case RenderAnimatedSizeState.stable: + _layoutStable(); + case RenderAnimatedSizeState.changed: + _layoutChanged(); + case RenderAnimatedSizeState.unstable: + _layoutUnstable(); + } + + size = constraints.constrain(_animatedSize!); + alignChild(); + + if (size.width < _sizeTween.end!.width || + size.height < _sizeTween.end!.height) { + _hasVisualOverflow = true; + } + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (child == null || constraints.isTight) { + return constraints.smallest; + } + + // This simplified version of performLayout only calculates the current + // size without modifying global state. See performLayout for comments + // explaining the rational behind the implementation. + final Size childSize = child!.getDryLayout(constraints); + switch (_state) { + case RenderAnimatedSizeState.start: + return constraints.constrain(childSize); + case RenderAnimatedSizeState.stable: + if (_sizeTween.end != childSize) { + return constraints.constrain(size); + } else if (_controller.value == _controller.upperBound) { + return constraints.constrain(childSize); + } + case RenderAnimatedSizeState.unstable: + case RenderAnimatedSizeState.changed: + if (_sizeTween.end != childSize) { + return constraints.constrain(childSize); + } + } + + return constraints.constrain(_animatedSize!); + } + + void _restartAnimation() { + _lastValue = 0.0; + _controller.forward(from: 0.0); + } + + /// Laying out the child for the first time. + /// + /// We have the initial size to animate from, but we do not have the target + /// size to animate to, so we set both ends to child's size. + void _layoutStart() { + _sizeTween.begin = _sizeTween.end = debugAdoptSize(child!.size); + _state = RenderAnimatedSizeState.stable; + } + + /// At this state we're assuming the child size is stable and letting the + /// animation run its course. + /// + /// If during animation the size of the child changes we restart the + /// animation. + void _layoutStable() { + if (_sizeTween.end != child!.size) { + _sizeTween.begin = size; + _sizeTween.end = debugAdoptSize(child!.size); + _restartAnimation(); + _state = RenderAnimatedSizeState.changed; + } else if (_controller.value == _controller.upperBound) { + // Animation finished. Reset target sizes. + _sizeTween.begin = _sizeTween.end = debugAdoptSize(child!.size); + } else if (!_controller.isAnimating) { + _controller.forward(); // resume the animation after being detached + } + } + + /// This state indicates that the size of the child changed once after being + /// considered stable. + /// + /// If the child stabilizes immediately, we go back to stable state. If it + /// changes again, we match the child's size, restart animation and go to + /// unstable state. + void _layoutChanged() { + if (_sizeTween.end != child!.size) { + // Child size changed again. Match the child's size and restart animation. + _sizeTween.begin = _sizeTween.end = debugAdoptSize(child!.size); + _restartAnimation(); + _state = RenderAnimatedSizeState.unstable; + } else { + // Child size stabilized. + _state = RenderAnimatedSizeState.stable; + if (!_controller.isAnimating) { + // Resume the animation after being detached. + _controller.forward(); + } + } + } + + /// The child's size is not stable. + /// + /// Continue tracking the child's size until is stabilizes. + void _layoutUnstable() { + if (_sizeTween.end != child!.size) { + // Still unstable. Continue tracking the child. + _sizeTween.begin = _sizeTween.end = debugAdoptSize(child!.size); + _restartAnimation(); + } else { + // Child size stabilized. + _controller.stop(); + _state = RenderAnimatedSizeState.stable; + } + } + + void _animationStatusListener(AnimationStatus status) { + switch (status) { + case AnimationStatus.completed: + _onEnd?.call(); + case AnimationStatus.dismissed: + case AnimationStatus.forward: + case AnimationStatus.reverse: + } + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null && _hasVisualOverflow && clipBehavior != Clip.none) { + final Rect rect = Offset.zero & size; + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + rect, + super.paint, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + } else { + _clipRectLayer.layer = null; + super.paint(context, offset); + } + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void dispose() { + _clipRectLayer.layer = null; + _controller.dispose(); + _animation.dispose(); + super.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/binding.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/binding.dart new file mode 100644 index 0000000000000000000000000000000000000000..82bb2bd933b2d20691ee86661d2dc27868910bb0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/binding.dart @@ -0,0 +1,859 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show SemanticsUpdate; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/semantics.dart'; +import 'package:flutter/services.dart'; + +import 'debug.dart'; +import 'mouse_tracker.dart'; +import 'object.dart'; +import 'service_extensions.dart'; +import 'view.dart'; + +export 'package:flutter/gestures.dart' show HitTestResult; + +// Examples can assume: +// late BuildContext context; + +/// The glue between the render trees and the Flutter engine. +/// +/// The [RendererBinding] manages multiple independent render trees. Each render +/// tree is rooted in a [RenderView] that must be added to the binding via +/// [addRenderView] to be considered during frame production, hit testing, etc. +/// Furthermore, the render tree must be managed by a [PipelineOwner] that is +/// part of the pipeline owner tree rooted at [rootPipelineOwner]. +/// +/// Adding [PipelineOwner]s and [RenderView]s to this binding in the way +/// described above is left as a responsibility for a higher level abstraction. +/// The widgets library, for example, introduces the [View] widget, which +/// registers its [RenderView] and [PipelineOwner] with this binding. +mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureBinding, SemanticsBinding, HitTestable { + @override + void initInstances() { + super.initInstances(); + _instance = this; + _rootPipelineOwner = createRootPipelineOwner(); + platformDispatcher + ..onMetricsChanged = handleMetricsChanged + ..onTextScaleFactorChanged = handleTextScaleFactorChanged + ..onPlatformBrightnessChanged = handlePlatformBrightnessChanged; + addPersistentFrameCallback(_handlePersistentFrameCallback); + initMouseTracker(); + if (kIsWeb) { + addPostFrameCallback(_handleWebFirstFrame, debugLabel: 'RendererBinding.webFirstFrame'); + } + rootPipelineOwner.attach(_manifold); + } + + /// The current [RendererBinding], if one has been created. + /// + /// Provides access to the features exposed by this mixin. The binding must + /// be initialized before using this getter; this is typically done by calling + /// [runApp] or [WidgetsFlutterBinding.ensureInitialized]. + static RendererBinding get instance => BindingBase.checkInstance(_instance); + static RendererBinding? _instance; + + @override + void initServiceExtensions() { + super.initServiceExtensions(); + + assert(() { + // these service extensions only work in debug mode + registerBoolServiceExtension( + name: RenderingServiceExtensions.invertOversizedImages.name, + getter: () async => debugInvertOversizedImages, + setter: (bool value) async { + if (debugInvertOversizedImages != value) { + debugInvertOversizedImages = value; + return _forceRepaint(); + } + return Future<void>.value(); + }, + ); + registerBoolServiceExtension( + name: RenderingServiceExtensions.debugPaint.name, + getter: () async => debugPaintSizeEnabled, + setter: (bool value) { + if (debugPaintSizeEnabled == value) { + return Future<void>.value(); + } + debugPaintSizeEnabled = value; + return _forceRepaint(); + }, + ); + registerBoolServiceExtension( + name: RenderingServiceExtensions.debugPaintBaselinesEnabled.name, + getter: () async => debugPaintBaselinesEnabled, + setter: (bool value) { + if (debugPaintBaselinesEnabled == value) { + return Future<void>.value(); + } + debugPaintBaselinesEnabled = value; + return _forceRepaint(); + }, + ); + registerBoolServiceExtension( + name: RenderingServiceExtensions.repaintRainbow.name, + getter: () async => debugRepaintRainbowEnabled, + setter: (bool value) { + final bool repaint = debugRepaintRainbowEnabled && !value; + debugRepaintRainbowEnabled = value; + if (repaint) { + return _forceRepaint(); + } + return Future<void>.value(); + }, + ); + registerServiceExtension( + name: RenderingServiceExtensions.debugDumpLayerTree.name, + callback: (Map<String, String> parameters) async { + return <String, Object>{ + 'data': _debugCollectLayerTrees(), + }; + }, + ); + registerBoolServiceExtension( + name: RenderingServiceExtensions.debugDisableClipLayers.name, + getter: () async => debugDisableClipLayers, + setter: (bool value) { + if (debugDisableClipLayers == value) { + return Future<void>.value(); + } + debugDisableClipLayers = value; + return _forceRepaint(); + }, + ); + registerBoolServiceExtension( + name: RenderingServiceExtensions.debugDisablePhysicalShapeLayers.name, + getter: () async => debugDisablePhysicalShapeLayers, + setter: (bool value) { + if (debugDisablePhysicalShapeLayers == value) { + return Future<void>.value(); + } + debugDisablePhysicalShapeLayers = value; + return _forceRepaint(); + }, + ); + registerBoolServiceExtension( + name: RenderingServiceExtensions.debugDisableOpacityLayers.name, + getter: () async => debugDisableOpacityLayers, + setter: (bool value) { + if (debugDisableOpacityLayers == value) { + return Future<void>.value(); + } + debugDisableOpacityLayers = value; + return _forceRepaint(); + }, + ); + return true; + }()); + + if (!kReleaseMode) { + // these service extensions work in debug or profile mode + registerServiceExtension( + name: RenderingServiceExtensions.debugDumpRenderTree.name, + callback: (Map<String, String> parameters) async { + return <String, Object>{ + 'data': _debugCollectRenderTrees(), + }; + }, + ); + registerServiceExtension( + name: RenderingServiceExtensions.debugDumpSemanticsTreeInTraversalOrder.name, + callback: (Map<String, String> parameters) async { + return <String, Object>{ + 'data': _debugCollectSemanticsTrees(DebugSemanticsDumpOrder.traversalOrder), + }; + }, + ); + registerServiceExtension( + name: RenderingServiceExtensions.debugDumpSemanticsTreeInInverseHitTestOrder.name, + callback: (Map<String, String> parameters) async { + return <String, Object>{ + 'data': _debugCollectSemanticsTrees(DebugSemanticsDumpOrder.inverseHitTest), + }; + }, + ); + registerBoolServiceExtension( + name: RenderingServiceExtensions.profileRenderObjectPaints.name, + getter: () async => debugProfilePaintsEnabled, + setter: (bool value) async { + if (debugProfilePaintsEnabled != value) { + debugProfilePaintsEnabled = value; + } + }, + ); + registerBoolServiceExtension( + name: RenderingServiceExtensions.profileRenderObjectLayouts.name, + getter: () async => debugProfileLayoutsEnabled, + setter: (bool value) async { + if (debugProfileLayoutsEnabled != value) { + debugProfileLayoutsEnabled = value; + } + }, + ); + } + } + + late final PipelineManifold _manifold = _BindingPipelineManifold(this); + + /// The object that manages state about currently connected mice, for hover + /// notification. + MouseTracker get mouseTracker => _mouseTracker!; + MouseTracker? _mouseTracker; + + /// Deprecated. Will be removed in a future version of Flutter. + /// + /// This is typically the owner of the render tree bootstrapped by [runApp] + /// and rooted in [renderView]. It maintains dirty state for layout, + /// composite, paint, and accessibility semantics for that tree. + /// + /// However, by default, the [pipelineOwner] does not participate in frame + /// production because it is not automatically attached to the + /// [rootPipelineOwner] or any of its descendants. It is also not + /// automatically associated with the [renderView]. This is left as a + /// responsibility for a higher level abstraction. The [WidgetsBinding], for + /// example, wires this up in [WidgetsBinding.wrapWithDefaultView], which is + /// called indirectly from [runApp]. + /// + /// Apps, that don't use the [WidgetsBinding] or don't call [runApp] (or + /// [WidgetsBinding.wrapWithDefaultView]) must manually add this pipeline owner + /// to the pipeline owner tree rooted at [rootPipelineOwner] and assign a + /// [RenderView] to it if the they want to use this deprecated property. + /// + /// Instead of accessing this deprecated property, consider interacting with + /// the root of the [PipelineOwner] tree (exposed in [rootPipelineOwner]) or + /// instead of accessing the [SemanticsOwner] of any [PipelineOwner] consider + /// interacting with the [SemanticsBinding] (exposed via + /// [SemanticsBinding.instance]) directly. + @Deprecated( + 'Interact with the pipelineOwner tree rooted at RendererBinding.rootPipelineOwner instead. ' + 'Or instead of accessing the SemanticsOwner of any PipelineOwner interact with the SemanticsBinding directly. ' + 'This feature was deprecated after v3.10.0-12.0.pre.' + ) + late final PipelineOwner pipelineOwner = PipelineOwner( + onSemanticsOwnerCreated: () { + (pipelineOwner.rootNode as RenderView?)?.scheduleInitialSemantics(); + }, + onSemanticsUpdate: (ui.SemanticsUpdate update) { + (pipelineOwner.rootNode as RenderView?)?.updateSemantics(update); + }, + onSemanticsOwnerDisposed: () { + (pipelineOwner.rootNode as RenderView?)?.clearSemantics(); + } + ); + + /// Deprecated. Will be removed in a future version of Flutter. + /// + /// This is typically the root of the render tree bootstrapped by [runApp]. + /// + /// However, by default this render view is not associated with any + /// [PipelineOwner] and therefore isn't considered during frame production. + /// It is also not registered with this binding via [addRenderView]. + /// Wiring this up is left as a responsibility for a higher level. The + /// [WidgetsBinding], for example, sets this up in + /// [WidgetsBinding.wrapWithDefaultView], which is called indirectly from + /// [runApp]. + /// + /// Apps that don't use the [WidgetsBinding] or don't call [runApp] (or + /// [WidgetsBinding.wrapWithDefaultView]) must manually assign a + /// [PipelineOwner] to this [RenderView], make sure the pipeline owner is part + /// of the pipeline owner tree rooted at [rootPipelineOwner], and call + /// [addRenderView] if they want to use this deprecated property. + /// + /// Instead of interacting with this deprecated property, consider using + /// [renderViews] instead, which contains all [RenderView]s managed by the + /// binding. + @Deprecated( + 'Consider using RendererBinding.renderViews instead as the binding may manage multiple RenderViews. ' + 'This feature was deprecated after v3.10.0-12.0.pre.' + ) + // TODO(goderbauer): When this deprecated property is removed also delete the _ReusableRenderView class. + late final RenderView renderView = _ReusableRenderView( + view: platformDispatcher.implicitView!, + ); + + /// Creates the [PipelineOwner] that serves as the root of the pipeline owner + /// tree ([rootPipelineOwner]). + /// + /// {@template flutter.rendering.createRootPipelineOwner} + /// By default, the root pipeline owner is not setup to manage a render tree + /// and its [PipelineOwner.rootNode] must not be assigned. If necessary, + /// [createRootPipelineOwner] may be overridden to create a root pipeline + /// owner configured to manage its own render tree. + /// + /// In typical use, child pipeline owners are added to the root pipeline owner + /// (via [PipelineOwner.adoptChild]). Those children typically do each manage + /// their own [RenderView] and produce distinct render trees which render + /// their content into the [FlutterView] associated with that [RenderView]. + /// {@endtemplate} + PipelineOwner createRootPipelineOwner() { + return _DefaultRootPipelineOwner(); + } + + /// The [PipelineOwner] that is the root of the PipelineOwner tree. + /// + /// {@macro flutter.rendering.createRootPipelineOwner} + PipelineOwner get rootPipelineOwner => _rootPipelineOwner; + late PipelineOwner _rootPipelineOwner; + + /// The [RenderView]s managed by this binding. + /// + /// A [RenderView] is added by [addRenderView] and removed by [removeRenderView]. + Iterable<RenderView> get renderViews => _viewIdToRenderView.values; + final Map<Object, RenderView> _viewIdToRenderView = <Object, RenderView>{}; + + /// Adds a [RenderView] to this binding. + /// + /// The binding will interact with the [RenderView] in the following ways: + /// + /// * setting and updating [RenderView.configuration], + /// * calling [RenderView.compositeFrame] when it is time to produce a new + /// frame, and + /// * forwarding relevant pointer events to the [RenderView] for hit testing. + /// + /// To remove a [RenderView] from the binding, call [removeRenderView]. + void addRenderView(RenderView view) { + final Object viewId = view.flutterView.viewId; + assert(!_viewIdToRenderView.containsValue(view)); + assert(!_viewIdToRenderView.containsKey(viewId)); + _viewIdToRenderView[viewId] = view; + view.configuration = createViewConfigurationFor(view); + } + + /// Removes a [RenderView] previously added with [addRenderView] from the + /// binding. + void removeRenderView(RenderView view) { + final Object viewId = view.flutterView.viewId; + assert(_viewIdToRenderView[viewId] == view); + _viewIdToRenderView.remove(viewId); + } + + /// Returns a [ViewConfiguration] configured for the provided [RenderView] + /// based on the current environment. + /// + /// This is called during [addRenderView] and also in response to changes to + /// the system metrics to update all [renderViews] added to the binding. + /// + /// Bindings can override this method to change what size or device pixel + /// ratio the [RenderView] will use. For example, the testing framework uses + /// this to force the display into 800x600 when a test is run on the device + /// using `flutter run`. + @protected + ViewConfiguration createViewConfigurationFor(RenderView renderView) { + final FlutterView view = renderView.flutterView; + final double devicePixelRatio = view.devicePixelRatio; + return ViewConfiguration( + size: view.physicalSize / devicePixelRatio, + devicePixelRatio: devicePixelRatio, + ); + } + + /// Called when the system metrics change. + /// + /// See [dart:ui.PlatformDispatcher.onMetricsChanged]. + @protected + @visibleForTesting + void handleMetricsChanged() { + bool forceFrame = false; + for (final RenderView view in renderViews) { + forceFrame = forceFrame || view.child != null; + view.configuration = createViewConfigurationFor(view); + } + if (forceFrame) { + scheduleForcedFrame(); + } + } + + /// Called when the platform text scale factor changes. + /// + /// See [dart:ui.PlatformDispatcher.onTextScaleFactorChanged]. + @protected + void handleTextScaleFactorChanged() { } + + /// Called when the platform brightness changes. + /// + /// The current platform brightness can be queried from a Flutter binding or + /// from a [MediaQuery] widget. The latter is preferred from widgets because + /// it causes the widget to be automatically rebuilt when the brightness + /// changes. + /// + /// {@tool snippet} + /// Querying [MediaQuery.platformBrightnessOf] directly. Preferred. + /// + /// ```dart + /// final Brightness brightness = MediaQuery.platformBrightnessOf(context); + /// ``` + /// {@end-tool} + /// + /// {@tool snippet} + /// Querying [PlatformDispatcher.platformBrightness]. + /// + /// ```dart + /// final Brightness brightness = WidgetsBinding.instance.platformDispatcher.platformBrightness; + /// ``` + /// {@end-tool} + /// + /// See [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged]. + @protected + void handlePlatformBrightnessChanged() { } + + /// Creates a [MouseTracker] which manages state about currently connected + /// mice, for hover notification. + /// + /// Used by testing framework to reinitialize the mouse tracker between tests. + @visibleForTesting + void initMouseTracker([MouseTracker? tracker]) { + _mouseTracker?.dispose(); + _mouseTracker = tracker ?? MouseTracker((Offset position, int viewId) { + final HitTestResult result = HitTestResult(); + hitTestInView(result, position, viewId); + return result; + }); + } + + @override // from GestureBinding + void dispatchEvent(PointerEvent event, HitTestResult? hitTestResult) { + _mouseTracker!.updateWithEvent( + event, + // When the button is pressed, normal hit test uses a cached + // result, but MouseTracker requires that the hit test is re-executed to + // update the hovering events. + event is PointerMoveEvent ? null : hitTestResult, + ); + super.dispatchEvent(event, hitTestResult); + } + + @override + void performSemanticsAction(SemanticsActionEvent action) { + // Due to the asynchronicity in some screen readers (they may not have + // processed the latest semantics update yet) this code is more forgiving + // and actions for views/nodes that no longer exist are gracefully ignored. + _viewIdToRenderView[action.viewId]?.owner?.semanticsOwner?.performAction(action.nodeId, action.type, action.arguments); + } + + void _handleWebFirstFrame(Duration _) { + assert(kIsWeb); + const MethodChannel methodChannel = MethodChannel('flutter/service_worker'); + methodChannel.invokeMethod<void>('first-frame'); + } + + void _handlePersistentFrameCallback(Duration timeStamp) { + drawFrame(); + _scheduleMouseTrackerUpdate(); + } + + bool _debugMouseTrackerUpdateScheduled = false; + void _scheduleMouseTrackerUpdate() { + assert(!_debugMouseTrackerUpdateScheduled); + assert(() { + _debugMouseTrackerUpdateScheduled = true; + return true; + }()); + SchedulerBinding.instance.addPostFrameCallback((Duration duration) { + assert(_debugMouseTrackerUpdateScheduled); + assert(() { + _debugMouseTrackerUpdateScheduled = false; + return true; + }()); + _mouseTracker!.updateAllDevices(); + }, debugLabel: 'RendererBinding.mouseTrackerUpdate'); + } + + int _firstFrameDeferredCount = 0; + bool _firstFrameSent = false; + + /// Whether frames produced by [drawFrame] are sent to the engine. + /// + /// If false the framework will do all the work to produce a frame, + /// but the frame is never sent to the engine to actually appear on screen. + /// + /// See also: + /// + /// * [deferFirstFrame], which defers when the first frame is sent to the + /// engine. + bool get sendFramesToEngine => _firstFrameSent || _firstFrameDeferredCount == 0; + + /// Tell the framework to not send the first frames to the engine until there + /// is a corresponding call to [allowFirstFrame]. + /// + /// Call this to perform asynchronous initialization work before the first + /// frame is rendered (which takes down the splash screen). The framework + /// will still do all the work to produce frames, but those frames are never + /// sent to the engine and will not appear on screen. + /// + /// Calling this has no effect after the first frame has been sent to the + /// engine. + void deferFirstFrame() { + assert(_firstFrameDeferredCount >= 0); + _firstFrameDeferredCount += 1; + } + + /// Called after [deferFirstFrame] to tell the framework that it is ok to + /// send the first frame to the engine now. + /// + /// For best performance, this method should only be called while the + /// [schedulerPhase] is [SchedulerPhase.idle]. + /// + /// This method may only be called once for each corresponding call + /// to [deferFirstFrame]. + void allowFirstFrame() { + assert(_firstFrameDeferredCount > 0); + _firstFrameDeferredCount -= 1; + // Always schedule a warm up frame even if the deferral count is not down to + // zero yet since the removal of a deferral may uncover new deferrals that + // are lower in the widget tree. + if (!_firstFrameSent) { + scheduleWarmUpFrame(); + } + } + + /// Call this to pretend that no frames have been sent to the engine yet. + /// + /// This is useful for tests that want to call [deferFirstFrame] and + /// [allowFirstFrame] since those methods only have an effect if no frames + /// have been sent to the engine yet. + void resetFirstFrameSent() { + _firstFrameSent = false; + } + + /// Pump the rendering pipeline to generate a frame. + /// + /// This method is called by [handleDrawFrame], which itself is called + /// automatically by the engine when it is time to lay out and paint a frame. + /// + /// Each frame consists of the following phases: + /// + /// 1. The animation phase: The [handleBeginFrame] method, which is registered + /// with [PlatformDispatcher.onBeginFrame], invokes all the transient frame + /// callbacks registered with [scheduleFrameCallback], in registration order. + /// This includes all the [Ticker] instances that are driving + /// [AnimationController] objects, which means all of the active [Animation] + /// objects tick at this point. + /// + /// 2. Microtasks: After [handleBeginFrame] returns, any microtasks that got + /// scheduled by transient frame callbacks get to run. This typically includes + /// callbacks for futures from [Ticker]s and [AnimationController]s that + /// completed this frame. + /// + /// After [handleBeginFrame], [handleDrawFrame], which is registered with + /// [dart:ui.PlatformDispatcher.onDrawFrame], is called, which invokes all the + /// persistent frame callbacks, of which the most notable is this method, + /// [drawFrame], which proceeds as follows: + /// + /// 3. The layout phase: All the dirty [RenderObject]s in the system are laid + /// out (see [RenderObject.performLayout]). See [RenderObject.markNeedsLayout] + /// for further details on marking an object dirty for layout. + /// + /// 4. The compositing bits phase: The compositing bits on any dirty + /// [RenderObject] objects are updated. See + /// [RenderObject.markNeedsCompositingBitsUpdate]. + /// + /// 5. The paint phase: All the dirty [RenderObject]s in the system are + /// repainted (see [RenderObject.paint]). This generates the [Layer] tree. See + /// [RenderObject.markNeedsPaint] for further details on marking an object + /// dirty for paint. + /// + /// 6. The compositing phase: The layer tree is turned into a [Scene] and + /// sent to the GPU. + /// + /// 7. The semantics phase: All the dirty [RenderObject]s in the system have + /// their semantics updated. This generates the [SemanticsNode] tree. See + /// [RenderObject.markNeedsSemanticsUpdate] for further details on marking an + /// object dirty for semantics. + /// + /// For more details on steps 3-7, see [PipelineOwner]. + /// + /// 8. The finalization phase: After [drawFrame] returns, [handleDrawFrame] + /// then invokes post-frame callbacks (registered with [addPostFrameCallback]). + /// + /// Some bindings (for example, the [WidgetsBinding]) add extra steps to this + /// list (for example, see [WidgetsBinding.drawFrame]). + // + // When editing the above, also update widgets/binding.dart's copy. + @protected + void drawFrame() { + rootPipelineOwner.flushLayout(); + rootPipelineOwner.flushCompositingBits(); + rootPipelineOwner.flushPaint(); + if (sendFramesToEngine) { + for (final RenderView renderView in renderViews) { + renderView.compositeFrame(); // this sends the bits to the GPU + } + rootPipelineOwner.flushSemantics(); // this sends the semantics to the OS. + _firstFrameSent = true; + } + } + + @override + Future<void> performReassemble() async { + await super.performReassemble(); + if (!kReleaseMode) { + FlutterTimeline.startSync('Preparing Hot Reload (layout)'); + } + try { + for (final RenderView renderView in renderViews) { + renderView.reassemble(); + } + } finally { + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + } + scheduleWarmUpFrame(); + await endOfFrame; + } + + @override + void hitTestInView(HitTestResult result, Offset position, int viewId) { + _viewIdToRenderView[viewId]?.hitTest(result, position: position); + super.hitTestInView(result, position, viewId); + } + + Future<void> _forceRepaint() { + late RenderObjectVisitor visitor; + visitor = (RenderObject child) { + child.markNeedsPaint(); + child.visitChildren(visitor); + }; + for (final RenderView renderView in renderViews) { + renderView.visitChildren(visitor); + } + return endOfFrame; + } +} + +String _debugCollectRenderTrees() { + if (RendererBinding.instance.renderViews.isEmpty) { + return 'No render tree root was added to the binding.'; + } + return <String>[ + for (final RenderView renderView in RendererBinding.instance.renderViews) + renderView.toStringDeep(), + ].join('\n\n'); +} + +/// Prints a textual representation of the render trees. +/// +/// {@template flutter.rendering.debugDumpRenderTree} +/// It prints the trees associated with every [RenderView] in +/// [RendererBinding.renderView], separated by two blank lines. +/// {@endtemplate} +void debugDumpRenderTree() { + debugPrint(_debugCollectRenderTrees()); +} + +String _debugCollectLayerTrees() { + if (RendererBinding.instance.renderViews.isEmpty) { + return 'No render tree root was added to the binding.'; + } + return <String>[ + for (final RenderView renderView in RendererBinding.instance.renderViews) + renderView.debugLayer?.toStringDeep() ?? 'Layer tree unavailable for $renderView.', + ].join('\n\n'); +} + +/// Prints a textual representation of the layer trees. +/// +/// {@macro flutter.rendering.debugDumpRenderTree} +void debugDumpLayerTree() { + debugPrint(_debugCollectLayerTrees()); +} + +String _debugCollectSemanticsTrees(DebugSemanticsDumpOrder childOrder) { + if (RendererBinding.instance.renderViews.isEmpty) { + return 'No render tree root was added to the binding.'; + } + const String explanation = 'For performance reasons, the framework only generates semantics when asked to do so by the platform.\n' + 'Usually, platforms only ask for semantics when assistive technologies (like screen readers) are running.\n' + 'To generate semantics, try turning on an assistive technology (like VoiceOver or TalkBack) on your device.'; + final List<String> trees = <String>[]; + bool printedExplanation = false; + for (final RenderView renderView in RendererBinding.instance.renderViews) { + final String? tree = renderView.debugSemantics?.toStringDeep(childOrder: childOrder); + if (tree != null) { + trees.add(tree); + } else { + String message = 'Semantics not generated for $renderView.'; + if (!printedExplanation) { + printedExplanation = true; + message = '$message\n$explanation'; + } + trees.add(message); + } + } + return trees.join('\n\n'); +} + +/// Prints a textual representation of the semantics trees. +/// +/// {@macro flutter.rendering.debugDumpRenderTree} +/// +/// Semantics trees are only constructed when semantics are enabled (see +/// [SemanticsBinding.semanticsEnabled]). If a semantics tree is not available, +/// a notice about the missing semantics tree is printed instead. +/// +/// The order in which the children of a [SemanticsNode] will be printed is +/// controlled by the [childOrder] parameter. +void debugDumpSemanticsTree([DebugSemanticsDumpOrder childOrder = DebugSemanticsDumpOrder.traversalOrder]) { + debugPrint(_debugCollectSemanticsTrees(childOrder)); +} + +/// Prints a textual representation of the [PipelineOwner] tree rooted at +/// [RendererBinding.rootPipelineOwner]. +void debugDumpPipelineOwnerTree() { + debugPrint(RendererBinding.instance.rootPipelineOwner.toStringDeep()); +} + +/// A concrete binding for applications that use the Rendering framework +/// directly. This is the glue that binds the framework to the Flutter engine. +/// +/// When using the rendering framework directly, this binding, or one that +/// implements the same interfaces, must be used. The following +/// mixins are used to implement this binding: +/// +/// * [GestureBinding], which implements the basics of hit testing. +/// * [SchedulerBinding], which introduces the concepts of frames. +/// * [ServicesBinding], which provides access to the plugin subsystem. +/// * [SemanticsBinding], which supports accessibility. +/// * [PaintingBinding], which enables decoding images. +/// * [RendererBinding], which handles the render tree. +/// +/// You would only use this binding if you are writing to the +/// rendering layer directly. If you are writing to a higher-level +/// library, such as the Flutter Widgets library, then you would use +/// that layer's binding (see [WidgetsFlutterBinding]). +/// +/// The [RenderingFlutterBinding] can manage multiple render trees. Each render +/// tree is rooted in a [RenderView] that must be added to the binding via +/// [addRenderView] to be consider during frame production, hit testing, etc. +/// Furthermore, the render tree must be managed by a [PipelineOwner] that is +/// part of the pipeline owner tree rooted at [rootPipelineOwner]. +/// +/// Adding [PipelineOwner]s and [RenderView]s to this binding in the way +/// described above is left as a responsibility for a higher level abstraction. +/// The binding does not own any [RenderView]s directly. +class RenderingFlutterBinding extends BindingBase with GestureBinding, SchedulerBinding, ServicesBinding, SemanticsBinding, PaintingBinding, RendererBinding { + /// Returns an instance of the binding that implements + /// [RendererBinding]. If no binding has yet been initialized, the + /// [RenderingFlutterBinding] class is used to create and initialize + /// one. + /// + /// You need to call this method before using the rendering framework + /// if you are using it directly. If you are using the widgets framework, + /// see [WidgetsFlutterBinding.ensureInitialized]. + static RendererBinding ensureInitialized() { + if (RendererBinding._instance == null) { + RenderingFlutterBinding(); + } + return RendererBinding.instance; + } +} + +/// A [PipelineManifold] implementation that is backed by the [RendererBinding]. +class _BindingPipelineManifold extends ChangeNotifier implements PipelineManifold { + _BindingPipelineManifold(this._binding) { + _binding.addSemanticsEnabledListener(notifyListeners); + } + + final RendererBinding _binding; + + @override + void requestVisualUpdate() { + _binding.ensureVisualUpdate(); + } + + @override + bool get semanticsEnabled => _binding.semanticsEnabled; + + @override + void dispose() { + _binding.removeSemanticsEnabledListener(notifyListeners); + super.dispose(); + } +} + +// A [PipelineOwner] that cannot have a root node. +class _DefaultRootPipelineOwner extends PipelineOwner { + _DefaultRootPipelineOwner() : super(onSemanticsUpdate: _onSemanticsUpdate); + + @override + set rootNode(RenderObject? _) { + assert(() { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'Cannot set a rootNode on the default root pipeline owner.', + ), + ErrorDescription( + 'By default, the RendererBinding.rootPipelineOwner is not configured ' + 'to manage a root node because this pipeline owner does not define a ' + 'proper onSemanticsUpdate callback to handle semantics for that node.', + ), + ErrorHint( + 'Typically, the root pipeline owner does not manage a root node. ' + 'Instead, properly configured child pipeline owners (which do manage ' + 'root nodes) are added to it. Alternatively, if you do want to set a ' + 'root node for the root pipeline owner, override ' + 'RendererBinding.createRootPipelineOwner to create a ' + 'pipeline owner that is configured to properly handle semantics for ' + 'the provided root node.' + ), + ]); + }()); + } + + static void _onSemanticsUpdate(ui.SemanticsUpdate _) { + // Neve called because we don't have a root node. + assert(false); + } +} + +// Prior to multi view support, the [RendererBinding] would own a long-lived +// [RenderView], that was never disposed (see [RendererBinding.renderView]). +// With multi view support, the [RendererBinding] no longer owns a [RenderView] +// and instead higher level abstractions (like the [View] widget) can add/remove +// multiple [RenderView]s to the binding as needed. When the [View] widget is no +// longer needed, it expects to dispose its [RenderView]. +// +// This special version of a [RenderView] now exists as a bridge between those +// worlds to continue supporting the [RendererBinding.renderView] property +// through its deprecation period. Per the property's contract, it is supposed +// to be long-lived, but it is also managed by a [View] widget (introduced by +// [WidgetsBinding.wrapWithDefaultView]), that expects to dispose its render +// object at the end of the widget's life time. This special version now +// implements logic to reset the [RenderView] when it is "disposed" so it can be +// reused by another [View] widget. +// +// Once the deprecated [RendererBinding.renderView] property is removed, this +// class is no longer necessary. +class _ReusableRenderView extends RenderView { + _ReusableRenderView({required super.view}); + + bool _initialFramePrepared = false; + + @override + void prepareInitialFrame() { + if (_initialFramePrepared) { + return; + } + super.prepareInitialFrame(); + _initialFramePrepared = true; + } + + @override + void scheduleInitialSemantics() { + clearSemantics(); + super.scheduleInitialSemantics(); + } + + @override + void dispose() { // ignore: must_call_super + child = null; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/box.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/box.dart new file mode 100644 index 0000000000000000000000000000000000000000..1449d8b8fbbc3bf87d4b3d5c3482e4d6edd93538 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/box.dart @@ -0,0 +1,2902 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; + +import 'package:vector_math/vector_math_64.dart'; + +import 'debug.dart'; +import 'object.dart'; + +// Examples can assume: +// abstract class RenderBar extends RenderBox { } +// late RenderBox firstChild; +// void markNeedsLayout() { } + +// This class should only be used in debug builds. +class _DebugSize extends Size { + _DebugSize(super.source, this._owner, this._canBeUsedByParent) : super.copy(); + final RenderBox _owner; + final bool _canBeUsedByParent; +} + +/// Immutable layout constraints for [RenderBox] layout. +/// +/// A [Size] respects a [BoxConstraints] if, and only if, all of the following +/// relations hold: +/// +/// * [minWidth] <= [Size.width] <= [maxWidth] +/// * [minHeight] <= [Size.height] <= [maxHeight] +/// +/// The constraints themselves must satisfy these relations: +/// +/// * 0.0 <= [minWidth] <= [maxWidth] <= [double.infinity] +/// * 0.0 <= [minHeight] <= [maxHeight] <= [double.infinity] +/// +/// [double.infinity] is a legal value for each constraint. +/// +/// ## The box layout model +/// +/// Render objects in the Flutter framework are laid out by a one-pass layout +/// model which walks down the render tree passing constraints, then walks back +/// up the render tree passing concrete geometry. +/// +/// For boxes, the constraints are [BoxConstraints], which, as described herein, +/// consist of four numbers: a minimum width [minWidth], a maximum width +/// [maxWidth], a minimum height [minHeight], and a maximum height [maxHeight]. +/// +/// The geometry for boxes consists of a [Size], which must satisfy the +/// constraints described above. +/// +/// Each [RenderBox] (the objects that provide the layout models for box +/// widgets) receives [BoxConstraints] from its parent, then lays out each of +/// its children, then picks a [Size] that satisfies the [BoxConstraints]. +/// +/// Render objects position their children independently of laying them out. +/// Frequently, the parent will use the children's sizes to determine their +/// position. A child does not know its position and will not necessarily be +/// laid out again, or repainted, if its position changes. +/// +/// ## Terminology +/// +/// When the minimum constraints and the maximum constraint in an axis are the +/// same, that axis is _tightly_ constrained. See: [ +/// BoxConstraints.tightFor], [BoxConstraints.tightForFinite], [tighten], +/// [hasTightWidth], [hasTightHeight], [isTight]. +/// +/// An axis with a minimum constraint of 0.0 is _loose_ (regardless of the +/// maximum constraint; if it is also 0.0, then the axis is simultaneously tight +/// and loose!). See: [BoxConstraints.loose], [loosen]. +/// +/// An axis whose maximum constraint is not infinite is _bounded_. See: +/// [hasBoundedWidth], [hasBoundedHeight]. +/// +/// An axis whose maximum constraint is infinite is _unbounded_. An axis is +/// _expanding_ if it is tightly infinite (its minimum and maximum constraints +/// are both infinite). See: [BoxConstraints.expand]. +/// +/// An axis whose _minimum_ constraint is infinite is just said to be _infinite_ +/// (since by definition the maximum constraint must also be infinite in that +/// case). See: [hasInfiniteWidth], [hasInfiniteHeight]. +/// +/// A size is _constrained_ when it satisfies a [BoxConstraints] description. +/// See: [constrain], [constrainWidth], [constrainHeight], +/// [constrainDimensions], [constrainSizeAndAttemptToPreserveAspectRatio], +/// [isSatisfiedBy]. +class BoxConstraints extends Constraints { + /// Creates box constraints with the given constraints. + const BoxConstraints({ + this.minWidth = 0.0, + this.maxWidth = double.infinity, + this.minHeight = 0.0, + this.maxHeight = double.infinity, + }); + + /// Creates box constraints that is respected only by the given size. + BoxConstraints.tight(Size size) + : minWidth = size.width, + maxWidth = size.width, + minHeight = size.height, + maxHeight = size.height; + + /// Creates box constraints that require the given width or height. + /// + /// See also: + /// + /// * [BoxConstraints.tightForFinite], which is similar but instead of + /// being tight if the value is non-null, is tight if the value is not + /// infinite. + const BoxConstraints.tightFor({ + double? width, + double? height, + }) : minWidth = width ?? 0.0, + maxWidth = width ?? double.infinity, + minHeight = height ?? 0.0, + maxHeight = height ?? double.infinity; + + /// Creates box constraints that require the given width or height, except if + /// they are infinite. + /// + /// See also: + /// + /// * [BoxConstraints.tightFor], which is similar but instead of being + /// tight if the value is not infinite, is tight if the value is non-null. + const BoxConstraints.tightForFinite({ + double width = double.infinity, + double height = double.infinity, + }) : minWidth = width != double.infinity ? width : 0.0, + maxWidth = width != double.infinity ? width : double.infinity, + minHeight = height != double.infinity ? height : 0.0, + maxHeight = height != double.infinity ? height : double.infinity; + + /// Creates box constraints that forbid sizes larger than the given size. + BoxConstraints.loose(Size size) + : minWidth = 0.0, + maxWidth = size.width, + minHeight = 0.0, + maxHeight = size.height; + + /// Creates box constraints that expand to fill another box constraints. + /// + /// If width or height is given, the constraints will require exactly the + /// given value in the given dimension. + const BoxConstraints.expand({ + double? width, + double? height, + }) : minWidth = width ?? double.infinity, + maxWidth = width ?? double.infinity, + minHeight = height ?? double.infinity, + maxHeight = height ?? double.infinity; + + /// The minimum width that satisfies the constraints. + final double minWidth; + + /// The maximum width that satisfies the constraints. + /// + /// Might be [double.infinity]. + final double maxWidth; + + /// The minimum height that satisfies the constraints. + final double minHeight; + + /// The maximum height that satisfies the constraints. + /// + /// Might be [double.infinity]. + final double maxHeight; + + /// Creates a copy of this box constraints but with the given fields replaced with the new values. + BoxConstraints copyWith({ + double? minWidth, + double? maxWidth, + double? minHeight, + double? maxHeight, + }) { + return BoxConstraints( + minWidth: minWidth ?? this.minWidth, + maxWidth: maxWidth ?? this.maxWidth, + minHeight: minHeight ?? this.minHeight, + maxHeight: maxHeight ?? this.maxHeight, + ); + } + + /// Returns new box constraints that are smaller by the given edge dimensions. + BoxConstraints deflate(EdgeInsets edges) { + assert(debugAssertIsValid()); + final double horizontal = edges.horizontal; + final double vertical = edges.vertical; + final double deflatedMinWidth = math.max(0.0, minWidth - horizontal); + final double deflatedMinHeight = math.max(0.0, minHeight - vertical); + return BoxConstraints( + minWidth: deflatedMinWidth, + maxWidth: math.max(deflatedMinWidth, maxWidth - horizontal), + minHeight: deflatedMinHeight, + maxHeight: math.max(deflatedMinHeight, maxHeight - vertical), + ); + } + + /// Returns new box constraints that remove the minimum width and height requirements. + BoxConstraints loosen() { + assert(debugAssertIsValid()); + return BoxConstraints( + maxWidth: maxWidth, + maxHeight: maxHeight, + ); + } + + /// Returns new box constraints that respect the given constraints while being + /// as close as possible to the original constraints. + BoxConstraints enforce(BoxConstraints constraints) { + return BoxConstraints( + minWidth: clampDouble(minWidth, constraints.minWidth, constraints.maxWidth), + maxWidth: clampDouble(maxWidth, constraints.minWidth, constraints.maxWidth), + minHeight: clampDouble(minHeight, constraints.minHeight, constraints.maxHeight), + maxHeight: clampDouble(maxHeight, constraints.minHeight, constraints.maxHeight), + ); + } + + /// Returns new box constraints with a tight width and/or height as close to + /// the given width and height as possible while still respecting the original + /// box constraints. + BoxConstraints tighten({ double? width, double? height }) { + return BoxConstraints( + minWidth: width == null ? minWidth : clampDouble(width, minWidth, maxWidth), + maxWidth: width == null ? maxWidth : clampDouble(width, minWidth, maxWidth), + minHeight: height == null ? minHeight : clampDouble(height, minHeight, maxHeight), + maxHeight: height == null ? maxHeight : clampDouble(height, minHeight, maxHeight), + ); + } + + /// A box constraints with the width and height constraints flipped. + BoxConstraints get flipped { + return BoxConstraints( + minWidth: minHeight, + maxWidth: maxHeight, + minHeight: minWidth, + maxHeight: maxWidth, + ); + } + + /// Returns box constraints with the same width constraints but with + /// unconstrained height. + BoxConstraints widthConstraints() => BoxConstraints(minWidth: minWidth, maxWidth: maxWidth); + + /// Returns box constraints with the same height constraints but with + /// unconstrained width. + BoxConstraints heightConstraints() => BoxConstraints(minHeight: minHeight, maxHeight: maxHeight); + + /// Returns the width that both satisfies the constraints and is as close as + /// possible to the given width. + double constrainWidth([ double width = double.infinity ]) { + assert(debugAssertIsValid()); + return clampDouble(width, minWidth, maxWidth); + } + + /// Returns the height that both satisfies the constraints and is as close as + /// possible to the given height. + double constrainHeight([ double height = double.infinity ]) { + assert(debugAssertIsValid()); + return clampDouble(height, minHeight, maxHeight); + } + + Size _debugPropagateDebugSize(Size size, Size result) { + assert(() { + if (size is _DebugSize) { + result = _DebugSize(result, size._owner, size._canBeUsedByParent); + } + return true; + }()); + return result; + } + + /// Returns the size that both satisfies the constraints and is as close as + /// possible to the given size. + /// + /// See also: + /// + /// * [constrainDimensions], which applies the same algorithm to + /// separately provided widths and heights. + Size constrain(Size size) { + Size result = Size(constrainWidth(size.width), constrainHeight(size.height)); + assert(() { + result = _debugPropagateDebugSize(size, result); + return true; + }()); + return result; + } + + /// Returns the size that both satisfies the constraints and is as close as + /// possible to the given width and height. + /// + /// When you already have a [Size], prefer [constrain], which applies the same + /// algorithm to a [Size] directly. + Size constrainDimensions(double width, double height) { + return Size(constrainWidth(width), constrainHeight(height)); + } + + /// Returns a size that attempts to meet the following conditions, in order: + /// + /// * The size must satisfy these constraints. + /// * The aspect ratio of the returned size matches the aspect ratio of the + /// given size. + /// * The returned size is as big as possible while still being equal to or + /// smaller than the given size. + Size constrainSizeAndAttemptToPreserveAspectRatio(Size size) { + if (isTight) { + Size result = smallest; + assert(() { + result = _debugPropagateDebugSize(size, result); + return true; + }()); + return result; + } + + double width = size.width; + double height = size.height; + assert(width > 0.0); + assert(height > 0.0); + final double aspectRatio = width / height; + + if (width > maxWidth) { + width = maxWidth; + height = width / aspectRatio; + } + + if (height > maxHeight) { + height = maxHeight; + width = height * aspectRatio; + } + + if (width < minWidth) { + width = minWidth; + height = width / aspectRatio; + } + + if (height < minHeight) { + height = minHeight; + width = height * aspectRatio; + } + + Size result = Size(constrainWidth(width), constrainHeight(height)); + assert(() { + result = _debugPropagateDebugSize(size, result); + return true; + }()); + return result; + } + + /// The biggest size that satisfies the constraints. + Size get biggest => Size(constrainWidth(), constrainHeight()); + + /// The smallest size that satisfies the constraints. + Size get smallest => Size(constrainWidth(0.0), constrainHeight(0.0)); + + /// Whether there is exactly one width value that satisfies the constraints. + bool get hasTightWidth => minWidth >= maxWidth; + + /// Whether there is exactly one height value that satisfies the constraints. + bool get hasTightHeight => minHeight >= maxHeight; + + /// Whether there is exactly one size that satisfies the constraints. + @override + bool get isTight => hasTightWidth && hasTightHeight; + + /// Whether there is an upper bound on the maximum width. + /// + /// See also: + /// + /// * [hasBoundedHeight], the equivalent for the vertical axis. + /// * [hasInfiniteWidth], which describes whether the minimum width + /// constraint is infinite. + bool get hasBoundedWidth => maxWidth < double.infinity; + + /// Whether there is an upper bound on the maximum height. + /// + /// See also: + /// + /// * [hasBoundedWidth], the equivalent for the horizontal axis. + /// * [hasInfiniteHeight], which describes whether the minimum height + /// constraint is infinite. + bool get hasBoundedHeight => maxHeight < double.infinity; + + /// Whether the width constraint is infinite. + /// + /// Such a constraint is used to indicate that a box should grow as large as + /// some other constraint (in this case, horizontally). If constraints are + /// infinite, then they must have other (non-infinite) constraints [enforce]d + /// upon them, or must be [tighten]ed, before they can be used to derive a + /// [Size] for a [RenderBox.size]. + /// + /// See also: + /// + /// * [hasInfiniteHeight], the equivalent for the vertical axis. + /// * [hasBoundedWidth], which describes whether the maximum width + /// constraint is finite. + bool get hasInfiniteWidth => minWidth >= double.infinity; + + /// Whether the height constraint is infinite. + /// + /// Such a constraint is used to indicate that a box should grow as large as + /// some other constraint (in this case, vertically). If constraints are + /// infinite, then they must have other (non-infinite) constraints [enforce]d + /// upon them, or must be [tighten]ed, before they can be used to derive a + /// [Size] for a [RenderBox.size]. + /// + /// See also: + /// + /// * [hasInfiniteWidth], the equivalent for the horizontal axis. + /// * [hasBoundedHeight], which describes whether the maximum height + /// constraint is finite. + bool get hasInfiniteHeight => minHeight >= double.infinity; + + /// Whether the given size satisfies the constraints. + bool isSatisfiedBy(Size size) { + assert(debugAssertIsValid()); + return (minWidth <= size.width) && (size.width <= maxWidth) && + (minHeight <= size.height) && (size.height <= maxHeight); + } + + /// Scales each constraint parameter by the given factor. + BoxConstraints operator*(double factor) { + return BoxConstraints( + minWidth: minWidth * factor, + maxWidth: maxWidth * factor, + minHeight: minHeight * factor, + maxHeight: maxHeight * factor, + ); + } + + /// Scales each constraint parameter by the inverse of the given factor. + BoxConstraints operator/(double factor) { + return BoxConstraints( + minWidth: minWidth / factor, + maxWidth: maxWidth / factor, + minHeight: minHeight / factor, + maxHeight: maxHeight / factor, + ); + } + + /// Scales each constraint parameter by the inverse of the given factor, rounded to the nearest integer. + BoxConstraints operator~/(double factor) { + return BoxConstraints( + minWidth: (minWidth ~/ factor).toDouble(), + maxWidth: (maxWidth ~/ factor).toDouble(), + minHeight: (minHeight ~/ factor).toDouble(), + maxHeight: (maxHeight ~/ factor).toDouble(), + ); + } + + /// Computes the remainder of each constraint parameter by the given value. + BoxConstraints operator%(double value) { + return BoxConstraints( + minWidth: minWidth % value, + maxWidth: maxWidth % value, + minHeight: minHeight % value, + maxHeight: maxHeight % value, + ); + } + + /// Linearly interpolate between two BoxConstraints. + /// + /// If either is null, this function interpolates from a [BoxConstraints] + /// object whose fields are all set to 0.0. + /// + /// {@macro dart.ui.shadow.lerp} + static BoxConstraints? lerp(BoxConstraints? a, BoxConstraints? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b! * t; + } + if (b == null) { + return a * (1.0 - t); + } + assert(a.debugAssertIsValid()); + assert(b.debugAssertIsValid()); + assert((a.minWidth.isFinite && b.minWidth.isFinite) || (a.minWidth == double.infinity && b.minWidth == double.infinity), 'Cannot interpolate between finite constraints and unbounded constraints.'); + assert((a.maxWidth.isFinite && b.maxWidth.isFinite) || (a.maxWidth == double.infinity && b.maxWidth == double.infinity), 'Cannot interpolate between finite constraints and unbounded constraints.'); + assert((a.minHeight.isFinite && b.minHeight.isFinite) || (a.minHeight == double.infinity && b.minHeight == double.infinity), 'Cannot interpolate between finite constraints and unbounded constraints.'); + assert((a.maxHeight.isFinite && b.maxHeight.isFinite) || (a.maxHeight == double.infinity && b.maxHeight == double.infinity), 'Cannot interpolate between finite constraints and unbounded constraints.'); + return BoxConstraints( + minWidth: a.minWidth.isFinite ? ui.lerpDouble(a.minWidth, b.minWidth, t)! : double.infinity, + maxWidth: a.maxWidth.isFinite ? ui.lerpDouble(a.maxWidth, b.maxWidth, t)! : double.infinity, + minHeight: a.minHeight.isFinite ? ui.lerpDouble(a.minHeight, b.minHeight, t)! : double.infinity, + maxHeight: a.maxHeight.isFinite ? ui.lerpDouble(a.maxHeight, b.maxHeight, t)! : double.infinity, + ); + } + + /// Returns whether the object's constraints are normalized. + /// Constraints are normalized if the minimums are less than or + /// equal to the corresponding maximums. + /// + /// For example, a BoxConstraints object with a minWidth of 100.0 + /// and a maxWidth of 90.0 is not normalized. + /// + /// Most of the APIs on BoxConstraints expect the constraints to be + /// normalized and have undefined behavior when they are not. In + /// debug mode, many of these APIs will assert if the constraints + /// are not normalized. + @override + bool get isNormalized { + return minWidth >= 0.0 && + minWidth <= maxWidth && + minHeight >= 0.0 && + minHeight <= maxHeight; + } + + @override + bool debugAssertIsValid({ + bool isAppliedConstraint = false, + InformationCollector? informationCollector, + }) { + assert(() { + void throwError(DiagnosticsNode message) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + message, + if (informationCollector != null) ...informationCollector(), + DiagnosticsProperty<BoxConstraints>('The offending constraints were', this, style: DiagnosticsTreeStyle.errorProperty), + ]); + } + if (minWidth.isNaN || maxWidth.isNaN || minHeight.isNaN || maxHeight.isNaN) { + final List<String> affectedFieldsList = <String>[ + if (minWidth.isNaN) 'minWidth', + if (maxWidth.isNaN) 'maxWidth', + if (minHeight.isNaN) 'minHeight', + if (maxHeight.isNaN) 'maxHeight', + ]; + assert(affectedFieldsList.isNotEmpty); + if (affectedFieldsList.length > 1) { + affectedFieldsList.add('and ${affectedFieldsList.removeLast()}'); + } + String whichFields = ''; + if (affectedFieldsList.length > 2) { + whichFields = affectedFieldsList.join(', '); + } else if (affectedFieldsList.length == 2) { + whichFields = affectedFieldsList.join(' '); + } else { + whichFields = affectedFieldsList.single; + } + throwError(ErrorSummary('BoxConstraints has ${affectedFieldsList.length == 1 ? 'a NaN value' : 'NaN values' } in $whichFields.')); + } + if (minWidth < 0.0 && minHeight < 0.0) { + throwError(ErrorSummary('BoxConstraints has both a negative minimum width and a negative minimum height.')); + } + if (minWidth < 0.0) { + throwError(ErrorSummary('BoxConstraints has a negative minimum width.')); + } + if (minHeight < 0.0) { + throwError(ErrorSummary('BoxConstraints has a negative minimum height.')); + } + if (maxWidth < minWidth && maxHeight < minHeight) { + throwError(ErrorSummary('BoxConstraints has both width and height constraints non-normalized.')); + } + if (maxWidth < minWidth) { + throwError(ErrorSummary('BoxConstraints has non-normalized width constraints.')); + } + if (maxHeight < minHeight) { + throwError(ErrorSummary('BoxConstraints has non-normalized height constraints.')); + } + if (isAppliedConstraint) { + if (minWidth.isInfinite && minHeight.isInfinite) { + throwError(ErrorSummary('BoxConstraints forces an infinite width and infinite height.')); + } + if (minWidth.isInfinite) { + throwError(ErrorSummary('BoxConstraints forces an infinite width.')); + } + if (minHeight.isInfinite) { + throwError(ErrorSummary('BoxConstraints forces an infinite height.')); + } + } + assert(isNormalized); + return true; + }()); + return isNormalized; + } + + /// Returns a box constraints that [isNormalized]. + /// + /// The returned [maxWidth] is at least as large as the [minWidth]. Similarly, + /// the returned [maxHeight] is at least as large as the [minHeight]. + BoxConstraints normalize() { + if (isNormalized) { + return this; + } + final double minWidth = this.minWidth >= 0.0 ? this.minWidth : 0.0; + final double minHeight = this.minHeight >= 0.0 ? this.minHeight : 0.0; + return BoxConstraints( + minWidth: minWidth, + maxWidth: minWidth > maxWidth ? minWidth : maxWidth, + minHeight: minHeight, + maxHeight: minHeight > maxHeight ? minHeight : maxHeight, + ); + } + + @override + bool operator ==(Object other) { + assert(debugAssertIsValid()); + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + assert(other is BoxConstraints && other.debugAssertIsValid()); + return other is BoxConstraints + && other.minWidth == minWidth + && other.maxWidth == maxWidth + && other.minHeight == minHeight + && other.maxHeight == maxHeight; + } + + @override + int get hashCode { + assert(debugAssertIsValid()); + return Object.hash(minWidth, maxWidth, minHeight, maxHeight); + } + + @override + String toString() { + final String annotation = isNormalized ? '' : '; NOT NORMALIZED'; + if (minWidth == double.infinity && minHeight == double.infinity) { + return 'BoxConstraints(biggest$annotation)'; + } + if (minWidth == 0 && maxWidth == double.infinity && + minHeight == 0 && maxHeight == double.infinity) { + return 'BoxConstraints(unconstrained$annotation)'; + } + String describe(double min, double max, String dim) { + if (min == max) { + return '$dim=${min.toStringAsFixed(1)}'; + } + return '${min.toStringAsFixed(1)}<=$dim<=${max.toStringAsFixed(1)}'; + } + final String width = describe(minWidth, maxWidth, 'w'); + final String height = describe(minHeight, maxHeight, 'h'); + return 'BoxConstraints($width, $height$annotation)'; + } +} + +/// Method signature for hit testing a [RenderBox]. +/// +/// Used by [BoxHitTestResult.addWithPaintTransform] to hit test children +/// of a [RenderBox]. +/// +/// See also: +/// +/// * [RenderBox.hitTest], which documents more details around hit testing +/// [RenderBox]es. +typedef BoxHitTest = bool Function(BoxHitTestResult result, Offset position); + +/// Method signature for hit testing a [RenderBox] with a manually +/// managed position (one that is passed out-of-band). +/// +/// Used by [RenderSliverSingleBoxAdapter.hitTestBoxChild] to hit test +/// [RenderBox] children of a [RenderSliver]. +/// +/// See also: +/// +/// * [RenderBox.hitTest], which documents more details around hit testing +/// [RenderBox]es. +typedef BoxHitTestWithOutOfBandPosition = bool Function(BoxHitTestResult result); + +/// The result of performing a hit test on [RenderBox]es. +/// +/// An instance of this class is provided to [RenderBox.hitTest] to record the +/// result of the hit test. +class BoxHitTestResult extends HitTestResult { + /// Creates an empty hit test result for hit testing on [RenderBox]. + BoxHitTestResult() : super(); + + /// Wraps `result` to create a [HitTestResult] that implements the + /// [BoxHitTestResult] protocol for hit testing on [RenderBox]es. + /// + /// This method is used by [RenderObject]s that adapt between the + /// [RenderBox]-world and the non-[RenderBox]-world to convert a (subtype of) + /// [HitTestResult] to a [BoxHitTestResult] for hit testing on [RenderBox]es. + /// + /// The [HitTestEntry] instances added to the returned [BoxHitTestResult] are + /// also added to the wrapped `result` (both share the same underlying data + /// structure to store [HitTestEntry] instances). + /// + /// See also: + /// + /// * [HitTestResult.wrap], which turns a [BoxHitTestResult] back into a + /// generic [HitTestResult]. + /// * [SliverHitTestResult.wrap], which turns a [BoxHitTestResult] into a + /// [SliverHitTestResult] for hit testing on [RenderSliver] children. + BoxHitTestResult.wrap(super.result) : super.wrap(); + + /// Transforms `position` to the local coordinate system of a child for + /// hit-testing the child. + /// + /// The actual hit testing of the child needs to be implemented in the + /// provided `hitTest` callback, which is invoked with the transformed + /// `position` as argument. + /// + /// The provided paint `transform` (which describes the transform from the + /// child to the parent in 3D) is processed by + /// [PointerEvent.removePerspectiveTransform] to remove the + /// perspective component and inverted before it is used to transform + /// `position` from the coordinate system of the parent to the system of the + /// child. + /// + /// If `transform` is null it will be treated as the identity transform and + /// `position` is provided to the `hitTest` callback as-is. If `transform` + /// cannot be inverted, the `hitTest` callback is not invoked and false is + /// returned. Otherwise, the return value of the `hitTest` callback is + /// returned. + /// + /// The `position` argument may be null, which will be forwarded to the + /// `hitTest` callback as-is. Using null as the position can be useful if + /// the child speaks a different hit test protocol than the parent and the + /// position is not required to do the actual hit testing in that protocol. + /// + /// The function returns the return value of the `hitTest` callback. + /// + /// {@tool snippet} + /// This method is used in [RenderBox.hitTestChildren] when the child and + /// parent don't share the same origin. + /// + /// ```dart + /// abstract class RenderFoo extends RenderBox { + /// final Matrix4 _effectiveTransform = Matrix4.rotationZ(50); + /// + /// @override + /// void applyPaintTransform(RenderBox child, Matrix4 transform) { + /// transform.multiply(_effectiveTransform); + /// } + /// + /// @override + /// bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + /// return result.addWithPaintTransform( + /// transform: _effectiveTransform, + /// position: position, + /// hitTest: (BoxHitTestResult result, Offset position) { + /// return super.hitTestChildren(result, position: position); + /// }, + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [addWithPaintOffset], which can be used for `transform`s that are just + /// simple matrix translations by an [Offset]. + /// * [addWithRawTransform], which takes a transform matrix that is directly + /// used to transform the position without any pre-processing. + bool addWithPaintTransform({ + required Matrix4? transform, + required Offset position, + required BoxHitTest hitTest, + }) { + if (transform != null) { + transform = Matrix4.tryInvert(PointerEvent.removePerspectiveTransform(transform)); + if (transform == null) { + // Objects are not visible on screen and cannot be hit-tested. + return false; + } + } + return addWithRawTransform( + transform: transform, + position: position, + hitTest: hitTest, + ); + } + + /// Convenience method for hit testing children, that are translated by + /// an [Offset]. + /// + /// The actual hit testing of the child needs to be implemented in the + /// provided `hitTest` callback, which is invoked with the transformed + /// `position` as argument. + /// + /// This method can be used as a convenience over [addWithPaintTransform] if + /// a parent paints a child at an `offset`. + /// + /// A null value for `offset` is treated as if [Offset.zero] was provided. + /// + /// The function returns the return value of the `hitTest` callback. + /// + /// See also: + /// + /// * [addWithPaintTransform], which takes a generic paint transform matrix and + /// documents the intended usage of this API in more detail. + bool addWithPaintOffset({ + required Offset? offset, + required Offset position, + required BoxHitTest hitTest, + }) { + final Offset transformedPosition = offset == null ? position : position - offset; + if (offset != null) { + pushOffset(-offset); + } + final bool isHit = hitTest(this, transformedPosition); + if (offset != null) { + popTransform(); + } + return isHit; + } + + /// Transforms `position` to the local coordinate system of a child for + /// hit-testing the child. + /// + /// The actual hit testing of the child needs to be implemented in the + /// provided `hitTest` callback, which is invoked with the transformed + /// `position` as argument. + /// + /// Unlike [addWithPaintTransform], the provided `transform` matrix is used + /// directly to transform `position` without any pre-processing. + /// + /// If `transform` is null it will be treated as the identity transform ad + /// `position` is provided to the `hitTest` callback as-is. + /// + /// The function returns the return value of the `hitTest` callback. + /// + /// See also: + /// + /// * [addWithPaintTransform], which accomplishes the same thing, but takes a + /// _paint_ transform matrix. + bool addWithRawTransform({ + required Matrix4? transform, + required Offset position, + required BoxHitTest hitTest, + }) { + final Offset transformedPosition = transform == null ? + position : MatrixUtils.transformPoint(transform, position); + if (transform != null) { + pushTransform(transform); + } + final bool isHit = hitTest(this, transformedPosition); + if (transform != null) { + popTransform(); + } + return isHit; + } + + /// Pass-through method for adding a hit test while manually managing + /// the position transformation logic. + /// + /// The actual hit testing of the child needs to be implemented in the + /// provided `hitTest` callback. The position needs to be handled by + /// the caller. + /// + /// The function returns the return value of the `hitTest` callback. + /// + /// A `paintOffset`, `paintTransform`, or `rawTransform` should be + /// passed to the method to update the hit test stack. + /// + /// * `paintOffset` has the semantics of the `offset` passed to + /// [addWithPaintOffset]. + /// + /// * `paintTransform` has the semantics of the `transform` passed to + /// [addWithPaintTransform], except that it must be invertible; it + /// is the responsibility of the caller to ensure this. + /// + /// * `rawTransform` has the semantics of the `transform` passed to + /// [addWithRawTransform]. + /// + /// Exactly one of these must be non-null. + /// + /// See also: + /// + /// * [addWithPaintTransform], which takes a generic paint transform matrix and + /// documents the intended usage of this API in more detail. + bool addWithOutOfBandPosition({ + Offset? paintOffset, + Matrix4? paintTransform, + Matrix4? rawTransform, + required BoxHitTestWithOutOfBandPosition hitTest, + }) { + assert( + (paintOffset == null && paintTransform == null && rawTransform != null) || + (paintOffset == null && paintTransform != null && rawTransform == null) || + (paintOffset != null && paintTransform == null && rawTransform == null), + 'Exactly one transform or offset argument must be provided.', + ); + if (paintOffset != null) { + pushOffset(-paintOffset); + } else if (rawTransform != null) { + pushTransform(rawTransform); + } else { + assert(paintTransform != null); + paintTransform = Matrix4.tryInvert(PointerEvent.removePerspectiveTransform(paintTransform!)); + assert(paintTransform != null, 'paintTransform must be invertible.'); + pushTransform(paintTransform!); + } + final bool isHit = hitTest(this); + popTransform(); + return isHit; + } +} + +/// A hit test entry used by [RenderBox]. +class BoxHitTestEntry extends HitTestEntry<RenderBox> { + /// Creates a box hit test entry. + BoxHitTestEntry(super.target, this.localPosition); + + /// The position of the hit test in the local coordinates of [target]. + final Offset localPosition; + + @override + String toString() => '${describeIdentity(target)}@$localPosition'; +} + +/// Parent data used by [RenderBox] and its subclasses. +/// +/// {@tool dartpad} +/// Parent data is used to communicate to a render object about its +/// children. In this example, there are two render objects that perform +/// text layout. They use parent data to identify the kind of child they +/// are laying out, and space the children accordingly. +/// +/// ** See code in examples/api/lib/rendering/box/parent_data.0.dart ** +/// {@end-tool} +class BoxParentData extends ParentData { + /// The offset at which to paint the child in the parent's coordinate system. + Offset offset = Offset.zero; + + @override + String toString() => 'offset=$offset'; +} + +/// Abstract [ParentData] subclass for [RenderBox] subclasses that want the +/// [ContainerRenderObjectMixin]. +/// +/// This is a convenience class that mixes in the relevant classes with +/// the relevant type arguments. +abstract class ContainerBoxParentData<ChildType extends RenderObject> extends BoxParentData with ContainerParentDataMixin<ChildType> { } + +enum _IntrinsicDimension { minWidth, maxWidth, minHeight, maxHeight } + +@immutable +class _IntrinsicDimensionsCacheEntry { + const _IntrinsicDimensionsCacheEntry(this.dimension, this.argument); + + final _IntrinsicDimension dimension; + final double argument; + + @override + bool operator ==(Object other) { + return other is _IntrinsicDimensionsCacheEntry + && other.dimension == dimension + && other.argument == argument; + } + + @override + int get hashCode => Object.hash(dimension, argument); +} + +/// A render object in a 2D Cartesian coordinate system. +/// +/// The [size] of each box is expressed as a width and a height. Each box has +/// its own coordinate system in which its upper left corner is placed at (0, +/// 0). The lower right corner of the box is therefore at (width, height). The +/// box contains all the points including the upper left corner and extending +/// to, but not including, the lower right corner. +/// +/// Box layout is performed by passing a [BoxConstraints] object down the tree. +/// The box constraints establish a min and max value for the child's width and +/// height. In determining its size, the child must respect the constraints +/// given to it by its parent. +/// +/// This protocol is sufficient for expressing a number of common box layout +/// data flows. For example, to implement a width-in-height-out data flow, call +/// your child's [layout] function with a set of box constraints with a tight +/// width value (and pass true for parentUsesSize). After the child determines +/// its height, use the child's height to determine your size. +/// +/// ## Writing a RenderBox subclass +/// +/// One would implement a new [RenderBox] subclass to describe a new layout +/// model, new paint model, new hit-testing model, or new semantics model, while +/// remaining in the Cartesian space defined by the [RenderBox] protocol. +/// +/// To create a new protocol, consider subclassing [RenderObject] instead. +/// +/// ### Constructors and properties of a new RenderBox subclass +/// +/// The constructor will typically take a named argument for each property of +/// the class. The value is then passed to a private field of the class and the +/// constructor asserts its correctness (e.g. if it should not be null, it +/// asserts it's not null). +/// +/// Properties have the form of a getter/setter/field group like the following: +/// +/// ```dart +/// AxisDirection get axis => _axis; +/// AxisDirection _axis = AxisDirection.down; // or initialized in constructor +/// set axis(AxisDirection value) { +/// if (value == _axis) { +/// return; +/// } +/// _axis = value; +/// markNeedsLayout(); +/// } +/// ``` +/// +/// The setter will typically finish with either a call to [markNeedsLayout], if +/// the layout uses this property, or [markNeedsPaint], if only the painter +/// function does. (No need to call both, [markNeedsLayout] implies +/// [markNeedsPaint].) +/// +/// Consider layout and paint to be expensive; be conservative about calling +/// [markNeedsLayout] or [markNeedsPaint]. They should only be called if the +/// layout (or paint, respectively) has actually changed. +/// +/// ### Children +/// +/// If a render object is a leaf, that is, it cannot have any children, then +/// ignore this section. (Examples of leaf render objects are [RenderImage] and +/// [RenderParagraph].) +/// +/// For render objects with children, there are four possible scenarios: +/// +/// * A single [RenderBox] child. In this scenario, consider inheriting from +/// [RenderProxyBox] (if the render object sizes itself to match the child) or +/// [RenderShiftedBox] (if the child will be smaller than the box and the box +/// will align the child inside itself). +/// +/// * A single child, but it isn't a [RenderBox]. Use the +/// [RenderObjectWithChildMixin] mixin. +/// +/// * A single list of children. Use the [ContainerRenderObjectMixin] mixin. +/// +/// * A more complicated child model. +/// +/// #### Using RenderProxyBox +/// +/// By default, a [RenderProxyBox] render object sizes itself to fit its child, or +/// to be as small as possible if there is no child; it passes all hit testing +/// and painting on to the child, and intrinsic dimensions and baseline +/// measurements similarly are proxied to the child. +/// +/// A subclass of [RenderProxyBox] just needs to override the parts of the +/// [RenderBox] protocol that matter. For example, [RenderOpacity] just +/// overrides the paint method (and [alwaysNeedsCompositing] to reflect what the +/// paint method does, and the [visitChildrenForSemantics] method so that the +/// child is hidden from accessibility tools when it's invisible), and adds an +/// [RenderOpacity.opacity] field. +/// +/// [RenderProxyBox] assumes that the child is the size of the parent and +/// positioned at 0,0. If this is not true, then use [RenderShiftedBox] instead. +/// +/// See +/// [proxy_box.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/rendering/proxy_box.dart) +/// for examples of inheriting from [RenderProxyBox]. +/// +/// #### Using RenderShiftedBox +/// +/// By default, a [RenderShiftedBox] acts much like a [RenderProxyBox] but +/// without assuming that the child is positioned at 0,0 (the actual position +/// recorded in the child's [parentData] field is used), and without providing a +/// default layout algorithm. +/// +/// See +/// [shifted_box.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/rendering/shifted_box.dart) +/// for examples of inheriting from [RenderShiftedBox]. +/// +/// #### Kinds of children and child-specific data +/// +/// A [RenderBox] doesn't have to have [RenderBox] children. One can use another +/// subclass of [RenderObject] for a [RenderBox]'s children. See the discussion +/// at [RenderObject]. +/// +/// Children can have additional data owned by the parent but stored on the +/// child using the [parentData] field. The class used for that data must +/// inherit from [ParentData]. The [setupParentData] method is used to +/// initialize the [parentData] field of a child when the child is attached. +/// +/// By convention, [RenderBox] objects that have [RenderBox] children use the +/// [BoxParentData] class, which has a [BoxParentData.offset] field to store the +/// position of the child relative to the parent. ([RenderProxyBox] does not +/// need this offset and therefore is an exception to this rule.) +/// +/// #### Using RenderObjectWithChildMixin +/// +/// If a render object has a single child but it isn't a [RenderBox], then the +/// [RenderObjectWithChildMixin] class, which is a mixin that will handle the +/// boilerplate of managing a child, will be useful. +/// +/// It's a generic class with one type argument, the type of the child. For +/// example, if you are building a `RenderFoo` class which takes a single +/// `RenderBar` child, you would use the mixin as follows: +/// +/// ```dart +/// class RenderFoo extends RenderBox +/// with RenderObjectWithChildMixin<RenderBar> { +/// // ... +/// } +/// ``` +/// +/// Since the `RenderFoo` class itself is still a [RenderBox] in this case, you +/// still have to implement the [RenderBox] layout algorithm, as well as +/// features like intrinsics and baselines, painting, and hit testing. +/// +/// #### Using ContainerRenderObjectMixin +/// +/// If a render box can have multiple children, then the +/// [ContainerRenderObjectMixin] mixin can be used to handle the boilerplate. It +/// uses a linked list to model the children in a manner that is easy to mutate +/// dynamically and that can be walked efficiently. Random access is not +/// efficient in this model; if you need random access to the children consider +/// the next section on more complicated child models. +/// +/// The [ContainerRenderObjectMixin] class has two type arguments. The first is +/// the type of the child objects. The second is the type for their +/// [parentData]. The class used for [parentData] must itself have the +/// [ContainerParentDataMixin] class mixed into it; this is where +/// [ContainerRenderObjectMixin] stores the linked list. A [ParentData] class +/// can extend [ContainerBoxParentData]; this is essentially +/// [BoxParentData] mixed with [ContainerParentDataMixin]. For example, if a +/// `RenderFoo` class wanted to have a linked list of [RenderBox] children, one +/// might create a `FooParentData` class as follows: +/// +/// ```dart +/// class FooParentData extends ContainerBoxParentData<RenderBox> { +/// // (any fields you might need for these children) +/// } +/// ``` +/// +/// When using [ContainerRenderObjectMixin] in a [RenderBox], consider mixing in +/// [RenderBoxContainerDefaultsMixin], which provides a collection of utility +/// methods that implement common parts of the [RenderBox] protocol (such as +/// painting the children). +/// +/// The declaration of the `RenderFoo` class itself would thus look like this: +/// +/// ```dart +/// // continuing from previous example... +/// class RenderFoo extends RenderBox with +/// ContainerRenderObjectMixin<RenderBox, FooParentData>, +/// RenderBoxContainerDefaultsMixin<RenderBox, FooParentData> { +/// // ... +/// } +/// ``` +/// +/// When walking the children (e.g. during layout), the following pattern is +/// commonly used (in this case assuming that the children are all [RenderBox] +/// objects and that this render object uses `FooParentData` objects for its +/// children's [parentData] fields): +/// +/// ```dart +/// // continuing from previous example... +/// RenderBox? child = firstChild; +/// while (child != null) { +/// final FooParentData childParentData = child.parentData! as FooParentData; +/// // ...operate on child and childParentData... +/// assert(child.parentData == childParentData); +/// child = childParentData.nextSibling; +/// } +/// ``` +/// +/// #### More complicated child models +/// +/// Render objects can have more complicated models, for example a map of +/// children keyed on an enum, or a 2D grid of efficiently randomly-accessible +/// children, or multiple lists of children, etc. If a render object has a model +/// that can't be handled by the mixins above, it must implement the +/// [RenderObject] child protocol, as follows: +/// +/// * Any time a child is removed, call [dropChild] with the child. +/// +/// * Any time a child is added, call [adoptChild] with the child. +/// +/// * Implement the [attach] method such that it calls [attach] on each child. +/// +/// * Implement the [detach] method such that it calls [detach] on each child. +/// +/// * Implement the [redepthChildren] method such that it calls [redepthChild] +/// on each child. +/// +/// * Implement the [visitChildren] method such that it calls its argument for +/// each child, typically in paint order (back-most to front-most). +/// +/// * Implement [debugDescribeChildren] such that it outputs a [DiagnosticsNode] +/// for each child. +/// +/// Implementing these seven bullet points is essentially all that the two +/// aforementioned mixins do. +/// +/// ### Layout +/// +/// [RenderBox] classes implement a layout algorithm. They have a set of +/// constraints provided to them, and they size themselves based on those +/// constraints and whatever other inputs they may have (for example, their +/// children or properties). +/// +/// When implementing a [RenderBox] subclass, one must make a choice. Does it +/// size itself exclusively based on the constraints, or does it use any other +/// information in sizing itself? An example of sizing purely based on the +/// constraints would be growing to fit the parent. +/// +/// Sizing purely based on the constraints allows the system to make some +/// significant optimizations. Classes that use this approach should override +/// [sizedByParent] to return true, and then override [computeDryLayout] to +/// compute the [Size] using nothing but the constraints, e.g.: +/// +/// ```dart +/// @override +/// bool get sizedByParent => true; +/// +/// @override +/// Size computeDryLayout(BoxConstraints constraints) { +/// return constraints.smallest; +/// } +/// ``` +/// +/// Otherwise, the size is set in the [performLayout] function. +/// +/// The [performLayout] function is where render boxes decide, if they are not +/// [sizedByParent], what [size] they should be, and also where they decide +/// where their children should be. +/// +/// #### Layout of RenderBox children +/// +/// The [performLayout] function should call the [layout] function of each (box) +/// child, passing it a [BoxConstraints] object describing the constraints +/// within which the child can render. Passing tight constraints (see +/// [BoxConstraints.isTight]) to the child will allow the rendering library to +/// apply some optimizations, as it knows that if the constraints are tight, the +/// child's dimensions cannot change even if the layout of the child itself +/// changes. +/// +/// If the [performLayout] function will use the child's size to affect other +/// aspects of the layout, for example if the render box sizes itself around the +/// child, or positions several children based on the size of those children, +/// then it must specify the `parentUsesSize` argument to the child's [layout] +/// function, setting it to true. +/// +/// This flag turns off some optimizations; algorithms that do not rely on the +/// children's sizes will be more efficient. (In particular, relying on the +/// child's [size] means that if the child is marked dirty for layout, the +/// parent will probably also be marked dirty for layout, unless the +/// [constraints] given by the parent to the child were tight constraints.) +/// +/// For [RenderBox] classes that do not inherit from [RenderProxyBox], once they +/// have laid out their children, they should also position them, by setting the +/// [BoxParentData.offset] field of each child's [parentData] object. +/// +/// #### Layout of non-RenderBox children +/// +/// The children of a [RenderBox] do not have to be [RenderBox]es themselves. If +/// they use another protocol (as discussed at [RenderObject]), then instead of +/// [BoxConstraints], the parent would pass in the appropriate [Constraints] +/// subclass, and instead of reading the child's size, the parent would read +/// whatever the output of [layout] is for that layout protocol. The +/// `parentUsesSize` flag is still used to indicate whether the parent is going +/// to read that output, and optimizations still kick in if the child has tight +/// constraints (as defined by [Constraints.isTight]). +/// +/// ### Painting +/// +/// To describe how a render box paints, implement the [paint] method. It is +/// given a [PaintingContext] object and an [Offset]. The painting context +/// provides methods to affect the layer tree as well as a +/// [PaintingContext.canvas] which can be used to add drawing commands. The +/// canvas object should not be cached across calls to the [PaintingContext]'s +/// methods; every time a method on [PaintingContext] is called, there is a +/// chance that the canvas will change identity. The offset specifies the +/// position of the top left corner of the box in the coordinate system of the +/// [PaintingContext.canvas]. +/// +/// To draw text on a canvas, use a [TextPainter]. +/// +/// To draw an image to a canvas, use the [paintImage] method. +/// +/// A [RenderBox] that uses methods on [PaintingContext] that introduce new +/// layers should override the [alwaysNeedsCompositing] getter and set it to +/// true. If the object sometimes does and sometimes does not, it can have that +/// getter return true in some cases and false in others. In that case, whenever +/// the return value would change, call [markNeedsCompositingBitsUpdate]. (This +/// is done automatically when a child is added or removed, so you don't have to +/// call it explicitly if the [alwaysNeedsCompositing] getter only changes value +/// based on the presence or absence of children.) +/// +/// Anytime anything changes on the object that would cause the [paint] method +/// to paint something different (but would not cause the layout to change), +/// the object should call [markNeedsPaint]. +/// +/// #### Painting children +/// +/// The [paint] method's `context` argument has a [PaintingContext.paintChild] +/// method, which should be called for each child that is to be painted. It +/// should be given a reference to the child, and an [Offset] giving the +/// position of the child relative to the parent. +/// +/// If the [paint] method applies a transform to the painting context before +/// painting children (or generally applies an additional offset beyond the +/// offset it was itself given as an argument), then the [applyPaintTransform] +/// method should also be overridden. That method must adjust the matrix that it +/// is given in the same manner as it transformed the painting context and +/// offset before painting the given child. This is used by the [globalToLocal] +/// and [localToGlobal] methods. +/// +/// #### Hit Tests +/// +/// Hit testing for render boxes is implemented by the [hitTest] method. The +/// default implementation of this method defers to [hitTestSelf] and +/// [hitTestChildren]. When implementing hit testing, you can either override +/// these latter two methods, or ignore them and just override [hitTest]. +/// +/// The [hitTest] method itself is given an [Offset], and must return true if the +/// object or one of its children has absorbed the hit (preventing objects below +/// this one from being hit), or false if the hit can continue to other objects +/// below this one. +/// +/// For each child [RenderBox], the [hitTest] method on the child should be +/// called with the same [HitTestResult] argument and with the point transformed +/// into the child's coordinate space (in the same manner that the +/// [applyPaintTransform] method would). The default implementation defers to +/// [hitTestChildren] to call the children. [RenderBoxContainerDefaultsMixin] +/// provides a [RenderBoxContainerDefaultsMixin.defaultHitTestChildren] method +/// that does this assuming that the children are axis-aligned, not transformed, +/// and positioned according to the [BoxParentData.offset] field of the +/// [parentData]; more elaborate boxes can override [hitTestChildren] +/// accordingly. +/// +/// If the object is hit, then it should also add itself to the [HitTestResult] +/// object that is given as an argument to the [hitTest] method, using +/// [HitTestResult.add]. The default implementation defers to [hitTestSelf] to +/// determine if the box is hit. If the object adds itself before the children +/// can add themselves, then it will be as if the object was above the children. +/// If it adds itself after the children, then it will be as if it was below the +/// children. Entries added to the [HitTestResult] object should use the +/// [BoxHitTestEntry] class. The entries are subsequently walked by the system +/// in the order they were added, and for each entry, the target's [handleEvent] +/// method is called, passing in the [HitTestEntry] object. +/// +/// Hit testing cannot rely on painting having happened. +/// +/// ### Semantics +/// +/// For a render box to be accessible, implement the +/// [describeApproximatePaintClip], [visitChildrenForSemantics], and +/// [describeSemanticsConfiguration] methods. The default implementations are +/// sufficient for objects that only affect layout, but nodes that represent +/// interactive components or information (diagrams, text, images, etc) should +/// provide more complete implementations. For more information, see the +/// documentation for these members. +/// +/// ### Intrinsics and Baselines +/// +/// The layout, painting, hit testing, and semantics protocols are common to all +/// render objects. [RenderBox] objects must implement two additional protocols: +/// intrinsic sizing and baseline measurements. +/// +/// There are four methods to implement for intrinsic sizing, to compute the +/// minimum and maximum intrinsic width and height of the box. The documentation +/// for these methods discusses the protocol in detail: +/// [computeMinIntrinsicWidth], [computeMaxIntrinsicWidth], +/// [computeMinIntrinsicHeight], [computeMaxIntrinsicHeight]. +/// +/// Be sure to set [debugCheckIntrinsicSizes] to true in your unit tests if you +/// do override any of these methods, which will add additional checks to +/// help validate your implementation. +/// +/// In addition, if the box has any children, it must implement +/// [computeDistanceToActualBaseline]. [RenderProxyBox] provides a simple +/// implementation that forwards to the child; [RenderShiftedBox] provides an +/// implementation that offsets the child's baseline information by the position +/// of the child relative to the parent. If you do not inherited from either of +/// these classes, however, you must implement the algorithm yourself. +abstract class RenderBox extends RenderObject { + @override + void setupParentData(covariant RenderObject child) { + if (child.parentData is! BoxParentData) { + child.parentData = BoxParentData(); + } + } + + Map<_IntrinsicDimensionsCacheEntry, double>? _cachedIntrinsicDimensions; + static int _debugIntrinsicsDepth = 0; + + double _computeIntrinsicDimension(_IntrinsicDimension dimension, double argument, double Function(double argument) computer) { + assert(RenderObject.debugCheckingIntrinsics || !debugDoingThisResize); // performResize should not depend on anything except the incoming constraints + bool shouldCache = true; + assert(() { + // we don't want the checked-mode intrinsic tests to affect + // who gets marked dirty, etc. + if (RenderObject.debugCheckingIntrinsics) { + shouldCache = false; + } + return true; + }()); + if (shouldCache) { + Map<String, String>? debugTimelineArguments; + assert(() { + if (debugEnhanceLayoutTimelineArguments) { + debugTimelineArguments = toDiagnosticsNode().toTimelineArguments(); + } else { + debugTimelineArguments = <String, String>{}; + } + debugTimelineArguments!['intrinsics dimension'] = dimension.name; + debugTimelineArguments!['intrinsics argument'] = '$argument'; + return true; + }()); + if (!kReleaseMode) { + if (debugProfileLayoutsEnabled || _debugIntrinsicsDepth == 0) { + FlutterTimeline.startSync( + '$runtimeType intrinsics', + arguments: debugTimelineArguments, + ); + } + _debugIntrinsicsDepth += 1; + } + _cachedIntrinsicDimensions ??= <_IntrinsicDimensionsCacheEntry, double>{}; + final double result = _cachedIntrinsicDimensions!.putIfAbsent( + _IntrinsicDimensionsCacheEntry(dimension, argument), + () => computer(argument), + ); + if (!kReleaseMode) { + _debugIntrinsicsDepth -= 1; + if (debugProfileLayoutsEnabled || _debugIntrinsicsDepth == 0) { + FlutterTimeline.finishSync(); + } + } + return result; + } + return computer(argument); + } + + /// Returns the minimum width that this box could be without failing to + /// correctly paint its contents within itself, without clipping. + /// + /// The height argument may give a specific height to assume. The given height + /// can be infinite, meaning that the intrinsic width in an unconstrained + /// environment is being requested. The given height should never be negative + /// or null. + /// + /// This function should only be called on one's children. Calling this + /// function couples the child with the parent so that when the child's layout + /// changes, the parent is notified (via [markNeedsLayout]). + /// + /// Calling this function is expensive as it can result in O(N^2) behavior. + /// + /// Do not override this method. Instead, implement [computeMinIntrinsicWidth]. + @mustCallSuper + double getMinIntrinsicWidth(double height) { + assert(() { + if (height < 0.0) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The height argument to getMinIntrinsicWidth was negative.'), + ErrorDescription('The argument to getMinIntrinsicWidth must not be negative or null.'), + ErrorHint( + 'If you perform computations on another height before passing it to ' + 'getMinIntrinsicWidth, consider using math.max() or double.clamp() ' + 'to force the value into the valid range.', + ), + ]); + } + return true; + }()); + return _computeIntrinsicDimension(_IntrinsicDimension.minWidth, height, computeMinIntrinsicWidth); + } + + /// Computes the value returned by [getMinIntrinsicWidth]. Do not call this + /// function directly, instead, call [getMinIntrinsicWidth]. + /// + /// Override in subclasses that implement [performLayout]. This method should + /// return the minimum width that this box could be without failing to + /// correctly paint its contents within itself, without clipping. + /// + /// If the layout algorithm is independent of the context (e.g. it always + /// tries to be a particular size), or if the layout algorithm is + /// width-in-height-out, or if the layout algorithm uses both the incoming + /// width and height constraints (e.g. it always sizes itself to + /// [BoxConstraints.biggest]), then the `height` argument should be ignored. + /// + /// If the layout algorithm is strictly height-in-width-out, or is + /// height-in-width-out when the width is unconstrained, then the height + /// argument is the height to use. + /// + /// The `height` argument will never be negative or null. It may be infinite. + /// + /// If this algorithm depends on the intrinsic dimensions of a child, the + /// intrinsic dimensions of that child should be obtained using the functions + /// whose names start with `get`, not `compute`. + /// + /// This function should never return a negative or infinite value. + /// + /// Be sure to set [debugCheckIntrinsicSizes] to true in your unit tests if + /// you do override this method, which will add additional checks to help + /// validate your implementation. + /// + /// ## Examples + /// + /// ### Text + /// + /// English text is the canonical example of a width-in-height-out algorithm. + /// The `height` argument is therefore ignored. + /// + /// Consider the string "Hello World". The _maximum_ intrinsic width (as + /// returned from [computeMaxIntrinsicWidth]) would be the width of the string + /// with no line breaks. + /// + /// The minimum intrinsic width would be the width of the widest word, "Hello" + /// or "World". If the text is rendered in an even narrower width, however, it + /// might still not overflow. For example, maybe the rendering would put a + /// line-break half-way through the words, as in "Hel⁞lo⁞Wor⁞ld". However, + /// this wouldn't be a _correct_ rendering, and [computeMinIntrinsicWidth] is + /// defined as returning the minimum width that the box could be without + /// failing to _correctly_ paint the contents within itself. + /// + /// The minimum intrinsic _height_ for a given width _smaller_ than the + /// minimum intrinsic width could therefore be greater than the minimum + /// intrinsic height for the minimum intrinsic width. + /// + /// ### Viewports (e.g. scrolling lists) + /// + /// Some render boxes are intended to clip their children. For example, the + /// render box for a scrolling list might always size itself to its parents' + /// size (or rather, to the maximum incoming constraints), regardless of the + /// children's sizes, and then clip the children and position them based on + /// the current scroll offset. + /// + /// The intrinsic dimensions in these cases still depend on the children, even + /// though the layout algorithm sizes the box in a way independent of the + /// children. It is the size that is needed to paint the box's contents (in + /// this case, the children) _without clipping_ that matters. + /// + /// ### When the intrinsic dimensions cannot be known + /// + /// There are cases where render objects do not have an efficient way to + /// compute their intrinsic dimensions. For example, it may be prohibitively + /// expensive to reify and measure every child of a lazy viewport (viewports + /// generally only instantiate the actually visible children), or the + /// dimensions may be computed by a callback about which the render object + /// cannot reason. + /// + /// In such cases, it may be impossible (or at least impractical) to actually + /// return a valid answer. In such cases, the intrinsic functions should throw + /// when [RenderObject.debugCheckingIntrinsics] is false and asserts are + /// enabled, and return 0.0 otherwise. + /// + /// See the implementations of [LayoutBuilder] or [RenderViewportBase] for + /// examples (in particular, + /// [RenderViewportBase.debugThrowIfNotCheckingIntrinsics]). + /// + /// ### Aspect-ratio-driven boxes + /// + /// Some boxes always return a fixed size based on the constraints. For these + /// boxes, the intrinsic functions should return the appropriate size when the + /// incoming `height` or `width` argument is finite, treating that as a tight + /// constraint in the respective direction and treating the other direction's + /// constraints as unbounded. This is because the definitions of + /// [computeMinIntrinsicWidth] and [computeMinIntrinsicHeight] are in terms of + /// what the dimensions _could be_, and such boxes can only be one size in + /// such cases. + /// + /// When the incoming argument is not finite, then they should return the + /// actual intrinsic dimensions based on the contents, as any other box would. + /// + /// See also: + /// + /// * [computeMaxIntrinsicWidth], which computes the smallest width beyond + /// which increasing the width never decreases the preferred height. + @protected + double computeMinIntrinsicWidth(double height) { + return 0.0; + } + + /// Returns the smallest width beyond which increasing the width never + /// decreases the preferred height. The preferred height is the value that + /// would be returned by [getMinIntrinsicHeight] for that width. + /// + /// The height argument may give a specific height to assume. The given height + /// can be infinite, meaning that the intrinsic width in an unconstrained + /// environment is being requested. The given height should never be negative + /// or null. + /// + /// This function should only be called on one's children. Calling this + /// function couples the child with the parent so that when the child's layout + /// changes, the parent is notified (via [markNeedsLayout]). + /// + /// Calling this function is expensive as it can result in O(N^2) behavior. + /// + /// Do not override this method. Instead, implement + /// [computeMaxIntrinsicWidth]. + @mustCallSuper + double getMaxIntrinsicWidth(double height) { + assert(() { + if (height < 0.0) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The height argument to getMaxIntrinsicWidth was negative.'), + ErrorDescription('The argument to getMaxIntrinsicWidth must not be negative or null.'), + ErrorHint( + 'If you perform computations on another height before passing it to ' + 'getMaxIntrinsicWidth, consider using math.max() or double.clamp() ' + 'to force the value into the valid range.', + ), + ]); + } + return true; + }()); + return _computeIntrinsicDimension(_IntrinsicDimension.maxWidth, height, computeMaxIntrinsicWidth); + } + + /// Computes the value returned by [getMaxIntrinsicWidth]. Do not call this + /// function directly, instead, call [getMaxIntrinsicWidth]. + /// + /// Override in subclasses that implement [performLayout]. This should return + /// the smallest width beyond which increasing the width never decreases the + /// preferred height. The preferred height is the value that would be returned + /// by [computeMinIntrinsicHeight] for that width. + /// + /// If the layout algorithm is strictly height-in-width-out, or is + /// height-in-width-out when the width is unconstrained, then this should + /// return the same value as [computeMinIntrinsicWidth] for the same height. + /// + /// Otherwise, the height argument should be ignored, and the returned value + /// should be equal to or bigger than the value returned by + /// [computeMinIntrinsicWidth]. + /// + /// The `height` argument will never be negative or null. It may be infinite. + /// + /// The value returned by this method might not match the size that the object + /// would actually take. For example, a [RenderBox] subclass that always + /// exactly sizes itself using [BoxConstraints.biggest] might well size itself + /// bigger than its max intrinsic size. + /// + /// If this algorithm depends on the intrinsic dimensions of a child, the + /// intrinsic dimensions of that child should be obtained using the functions + /// whose names start with `get`, not `compute`. + /// + /// This function should never return a negative or infinite value. + /// + /// Be sure to set [debugCheckIntrinsicSizes] to true in your unit tests if + /// you do override this method, which will add additional checks to help + /// validate your implementation. + /// + /// See also: + /// + /// * [computeMinIntrinsicWidth], which has usage examples. + @protected + double computeMaxIntrinsicWidth(double height) { + return 0.0; + } + + /// Returns the minimum height that this box could be without failing to + /// correctly paint its contents within itself, without clipping. + /// + /// The width argument may give a specific width to assume. The given width + /// can be infinite, meaning that the intrinsic height in an unconstrained + /// environment is being requested. The given width should never be negative + /// or null. + /// + /// This function should only be called on one's children. Calling this + /// function couples the child with the parent so that when the child's layout + /// changes, the parent is notified (via [markNeedsLayout]). + /// + /// Calling this function is expensive as it can result in O(N^2) behavior. + /// + /// Do not override this method. Instead, implement + /// [computeMinIntrinsicHeight]. + @mustCallSuper + double getMinIntrinsicHeight(double width) { + assert(() { + if (width < 0.0) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The width argument to getMinIntrinsicHeight was negative.'), + ErrorDescription('The argument to getMinIntrinsicHeight must not be negative or null.'), + ErrorHint( + 'If you perform computations on another width before passing it to ' + 'getMinIntrinsicHeight, consider using math.max() or double.clamp() ' + 'to force the value into the valid range.', + ), + ]); + } + return true; + }()); + return _computeIntrinsicDimension(_IntrinsicDimension.minHeight, width, computeMinIntrinsicHeight); + } + + /// Computes the value returned by [getMinIntrinsicHeight]. Do not call this + /// function directly, instead, call [getMinIntrinsicHeight]. + /// + /// Override in subclasses that implement [performLayout]. Should return the + /// minimum height that this box could be without failing to correctly paint + /// its contents within itself, without clipping. + /// + /// If the layout algorithm is independent of the context (e.g. it always + /// tries to be a particular size), or if the layout algorithm is + /// height-in-width-out, or if the layout algorithm uses both the incoming + /// height and width constraints (e.g. it always sizes itself to + /// [BoxConstraints.biggest]), then the `width` argument should be ignored. + /// + /// If the layout algorithm is strictly width-in-height-out, or is + /// width-in-height-out when the height is unconstrained, then the width + /// argument is the width to use. + /// + /// The `width` argument will never be negative or null. It may be infinite. + /// + /// If this algorithm depends on the intrinsic dimensions of a child, the + /// intrinsic dimensions of that child should be obtained using the functions + /// whose names start with `get`, not `compute`. + /// + /// This function should never return a negative or infinite value. + /// + /// Be sure to set [debugCheckIntrinsicSizes] to true in your unit tests if + /// you do override this method, which will add additional checks to help + /// validate your implementation. + /// + /// See also: + /// + /// * [computeMinIntrinsicWidth], which has usage examples. + /// * [computeMaxIntrinsicHeight], which computes the smallest height beyond + /// which increasing the height never decreases the preferred width. + @protected + double computeMinIntrinsicHeight(double width) { + return 0.0; + } + + /// Returns the smallest height beyond which increasing the height never + /// decreases the preferred width. The preferred width is the value that + /// would be returned by [getMinIntrinsicWidth] for that height. + /// + /// The width argument may give a specific width to assume. The given width + /// can be infinite, meaning that the intrinsic height in an unconstrained + /// environment is being requested. The given width should never be negative + /// or null. + /// + /// This function should only be called on one's children. Calling this + /// function couples the child with the parent so that when the child's layout + /// changes, the parent is notified (via [markNeedsLayout]). + /// + /// Calling this function is expensive as it can result in O(N^2) behavior. + /// + /// Do not override this method. Instead, implement + /// [computeMaxIntrinsicHeight]. + @mustCallSuper + double getMaxIntrinsicHeight(double width) { + assert(() { + if (width < 0.0) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The width argument to getMaxIntrinsicHeight was negative.'), + ErrorDescription('The argument to getMaxIntrinsicHeight must not be negative or null.'), + ErrorHint( + 'If you perform computations on another width before passing it to ' + 'getMaxIntrinsicHeight, consider using math.max() or double.clamp() ' + 'to force the value into the valid range.', + ), + ]); + } + return true; + }()); + return _computeIntrinsicDimension(_IntrinsicDimension.maxHeight, width, computeMaxIntrinsicHeight); + } + + /// Computes the value returned by [getMaxIntrinsicHeight]. Do not call this + /// function directly, instead, call [getMaxIntrinsicHeight]. + /// + /// Override in subclasses that implement [performLayout]. Should return the + /// smallest height beyond which increasing the height never decreases the + /// preferred width. The preferred width is the value that would be returned + /// by [computeMinIntrinsicWidth] for that height. + /// + /// If the layout algorithm is strictly width-in-height-out, or is + /// width-in-height-out when the height is unconstrained, then this should + /// return the same value as [computeMinIntrinsicHeight] for the same width. + /// + /// Otherwise, the width argument should be ignored, and the returned value + /// should be equal to or bigger than the value returned by + /// [computeMinIntrinsicHeight]. + /// + /// The `width` argument will never be negative or null. It may be infinite. + /// + /// The value returned by this method might not match the size that the object + /// would actually take. For example, a [RenderBox] subclass that always + /// exactly sizes itself using [BoxConstraints.biggest] might well size itself + /// bigger than its max intrinsic size. + /// + /// If this algorithm depends on the intrinsic dimensions of a child, the + /// intrinsic dimensions of that child should be obtained using the functions + /// whose names start with `get`, not `compute`. + /// + /// This function should never return a negative or infinite value. + /// + /// Be sure to set [debugCheckIntrinsicSizes] to true in your unit tests if + /// you do override this method, which will add additional checks to help + /// validate your implementation. + /// + /// See also: + /// + /// * [computeMinIntrinsicWidth], which has usage examples. + @protected + double computeMaxIntrinsicHeight(double width) { + return 0.0; + } + + Map<BoxConstraints, Size>? _cachedDryLayoutSizes; + bool _computingThisDryLayout = false; + + /// Returns the [Size] that this [RenderBox] would like to be given the + /// provided [BoxConstraints]. + /// + /// The size returned by this method is guaranteed to be the same size that + /// this [RenderBox] computes for itself during layout given the same + /// constraints. + /// + /// This function should only be called on one's children. Calling this + /// function couples the child with the parent so that when the child's layout + /// changes, the parent is notified (via [markNeedsLayout]). + /// + /// This layout is called "dry" layout as opposed to the regular "wet" layout + /// run performed by [performLayout] because it computes the desired size for + /// the given constraints without changing any internal state. + /// + /// Calling this function is expensive as it can result in O(N^2) behavior. + /// + /// Do not override this method. Instead, implement [computeDryLayout]. + @mustCallSuper + Size getDryLayout(BoxConstraints constraints) { + bool shouldCache = true; + assert(() { + // we don't want the checked-mode intrinsic tests to affect + // who gets marked dirty, etc. + if (RenderObject.debugCheckingIntrinsics) { + shouldCache = false; + } + return true; + }()); + if (shouldCache) { + Map<String, String>? debugTimelineArguments; + assert(() { + if (debugEnhanceLayoutTimelineArguments) { + debugTimelineArguments = toDiagnosticsNode().toTimelineArguments(); + } else { + debugTimelineArguments = <String, String>{}; + } + debugTimelineArguments!['getDryLayout constraints'] = '$constraints'; + return true; + }()); + if (!kReleaseMode) { + if (debugProfileLayoutsEnabled || _debugIntrinsicsDepth == 0) { + FlutterTimeline.startSync( + '$runtimeType.getDryLayout', + arguments: debugTimelineArguments, + ); + } + _debugIntrinsicsDepth += 1; + } + _cachedDryLayoutSizes ??= <BoxConstraints, Size>{}; + final Size result = _cachedDryLayoutSizes!.putIfAbsent(constraints, () => _computeDryLayout(constraints)); + if (!kReleaseMode) { + _debugIntrinsicsDepth -= 1; + if (debugProfileLayoutsEnabled || _debugIntrinsicsDepth == 0) { + FlutterTimeline.finishSync(); + } + } + return result; + } + return _computeDryLayout(constraints); + } + + Size _computeDryLayout(BoxConstraints constraints) { + assert(() { + assert(!_computingThisDryLayout); + _computingThisDryLayout = true; + return true; + }()); + final Size result = computeDryLayout(constraints); + assert(() { + assert(_computingThisDryLayout); + _computingThisDryLayout = false; + return true; + }()); + return result; + } + + /// Computes the value returned by [getDryLayout]. Do not call this + /// function directly, instead, call [getDryLayout]. + /// + /// Override in subclasses that implement [performLayout] or [performResize] + /// or when setting [sizedByParent] to true without overriding + /// [performResize]. This method should return the [Size] that this + /// [RenderBox] would like to be given the provided [BoxConstraints]. + /// + /// The size returned by this method must match the [size] that the + /// [RenderBox] will compute for itself in [performLayout] (or + /// [performResize], if [sizedByParent] is true). + /// + /// If this algorithm depends on the size of a child, the size of that child + /// should be obtained using its [getDryLayout] method. + /// + /// This layout is called "dry" layout as opposed to the regular "wet" layout + /// run performed by [performLayout] because it computes the desired size for + /// the given constraints without changing any internal state. + /// + /// ### When the size cannot be known + /// + /// There are cases where render objects do not have an efficient way to + /// compute their size without doing a full layout. For example, the size + /// may depend on the baseline of a child (which is not available without + /// doing a full layout), it may be computed by a callback about which the + /// render object cannot reason, or the layout is so complex that it + /// is impractical to calculate the size in an efficient way. + /// + /// In such cases, it may be impossible (or at least impractical) to actually + /// return a valid answer. In such cases, the function should call + /// [debugCannotComputeDryLayout] from within an assert and return a dummy + /// value of `const Size(0, 0)`. + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + assert(debugCannotComputeDryLayout( + error: FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The ${objectRuntimeType(this, 'RenderBox')} class does not implement "computeDryLayout".'), + ErrorHint( + 'If you are not writing your own RenderBox subclass, then this is not\n' + 'your fault. Contact support: https://github.com/flutter/flutter/issues/new?template=2_bug.yml', + ), + ]), + )); + return Size.zero; + } + + static bool _dryLayoutCalculationValid = true; + + /// Called from [computeDryLayout] within an assert if the given [RenderBox] + /// subclass does not support calculating a dry layout. + /// + /// When asserts are enabled and [debugCheckingIntrinsics] is not true, this + /// method will either throw the provided [FlutterError] or it will create and + /// throw a [FlutterError] with the provided `reason`. Otherwise, it will + /// return true. + /// + /// One of the arguments has to be provided. + /// + /// See also: + /// + /// * [computeDryLayout], which lists some reasons why it may not be feasible + /// to compute the dry layout. + bool debugCannotComputeDryLayout({String? reason, FlutterError? error}) { + assert((reason == null) != (error == null)); + assert(() { + if (!RenderObject.debugCheckingIntrinsics) { + if (reason != null) { + assert(error ==null); + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The ${objectRuntimeType(this, 'RenderBox')} class does not support dry layout.'), + if (reason.isNotEmpty) ErrorDescription(reason), + ]); + } + assert(error != null); + throw error!; + } + _dryLayoutCalculationValid = false; + return true; + }()); + return true; + } + + /// Whether this render object has undergone layout and has a [size]. + bool get hasSize => _size != null; + + /// The size of this render box computed during layout. + /// + /// This value is stale whenever this object is marked as needing layout. + /// During [performLayout], do not read the size of a child unless you pass + /// true for parentUsesSize when calling the child's [layout] function. + /// + /// The size of a box should be set only during the box's [performLayout] or + /// [performResize] functions. If you wish to change the size of a box outside + /// of those functions, call [markNeedsLayout] instead to schedule a layout of + /// the box. + Size get size { + assert(hasSize, 'RenderBox was not laid out: $this'); + assert(() { + final Size? size = _size; + if (size is _DebugSize) { + assert(size._owner == this); + if (RenderObject.debugActiveLayout != null && + !RenderObject.debugActiveLayout!.debugDoingThisLayoutWithCallback) { + assert( + debugDoingThisResize || debugDoingThisLayout || _computingThisDryLayout || + (RenderObject.debugActiveLayout == parent && size._canBeUsedByParent), + 'RenderBox.size accessed beyond the scope of resize, layout, or ' + 'permitted parent access. RenderBox can always access its own size, ' + 'otherwise, the only object that is allowed to read RenderBox.size ' + 'is its parent, if they have said they will. It you hit this assert ' + 'trying to access a child\'s size, pass "parentUsesSize: true" to ' + "that child's layout().", + ); + } + assert(size == _size); + } + return true; + }()); + return _size ?? (throw StateError('RenderBox was not laid out: $runtimeType#${shortHash(this)}')); + } + Size? _size; + /// Setting the size, in debug mode, triggers some analysis of the render box, + /// as implemented by [debugAssertDoesMeetConstraints], including calling the intrinsic + /// sizing methods and checking that they meet certain invariants. + @protected + set size(Size value) { + assert(!(debugDoingThisResize && debugDoingThisLayout)); + assert(sizedByParent || !debugDoingThisResize); + assert(() { + if ((sizedByParent && debugDoingThisResize) || + (!sizedByParent && debugDoingThisLayout)) { + return true; + } + assert(!debugDoingThisResize); + final List<DiagnosticsNode> information = <DiagnosticsNode>[ + ErrorSummary('RenderBox size setter called incorrectly.'), + ]; + if (debugDoingThisLayout) { + assert(sizedByParent); + information.add(ErrorDescription('It appears that the size setter was called from performLayout().')); + } else { + information.add(ErrorDescription( + 'The size setter was called from outside layout (neither performResize() nor performLayout() were being run for this object).', + )); + if (owner != null && owner!.debugDoingLayout) { + information.add(ErrorDescription('Only the object itself can set its size. It is a contract violation for other objects to set it.')); + } + } + if (sizedByParent) { + information.add(ErrorDescription('Because this RenderBox has sizedByParent set to true, it must set its size in performResize().')); + } else { + information.add(ErrorDescription('Because this RenderBox has sizedByParent set to false, it must set its size in performLayout().')); + } + throw FlutterError.fromParts(information); + }()); + assert(() { + value = debugAdoptSize(value); + return true; + }()); + _size = value; + assert(() { + debugAssertDoesMeetConstraints(); + return true; + }()); + } + + /// Claims ownership of the given [Size]. + /// + /// In debug mode, the [RenderBox] class verifies that [Size] objects obtained + /// from other [RenderBox] objects are only used according to the semantics of + /// the [RenderBox] protocol, namely that a [Size] from a [RenderBox] can only + /// be used by its parent, and then only if `parentUsesSize` was set. + /// + /// Sometimes, a [Size] that can validly be used ends up no longer being valid + /// over time. The common example is a [Size] taken from a child that is later + /// removed from the parent. In such cases, this method can be called to first + /// check whether the size can legitimately be used, and if so, to then create + /// a new [Size] that can be used going forward, regardless of what happens to + /// the original owner. + Size debugAdoptSize(Size value) { + Size result = value; + assert(() { + if (value is _DebugSize) { + if (value._owner != this) { + if (value._owner.parent != this) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The size property was assigned a size inappropriately.'), + describeForError('The following render object'), + value._owner.describeForError('...was assigned a size obtained from'), + ErrorDescription( + 'However, this second render object is not, or is no longer, a ' + 'child of the first, and it is therefore a violation of the ' + 'RenderBox layout protocol to use that size in the layout of the ' + 'first render object.', + ), + ErrorHint( + 'If the size was obtained at a time where it was valid to read ' + 'the size (because the second render object above was a child ' + 'of the first at the time), then it should be adopted using ' + 'debugAdoptSize at that time.', + ), + ErrorHint( + 'If the size comes from a grandchild or a render object from an ' + 'entirely different part of the render tree, then there is no ' + 'way to be notified when the size changes and therefore attempts ' + 'to read that size are almost certainly a source of bugs. A different ' + 'approach should be used.', + ), + ]); + } + if (!value._canBeUsedByParent) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary("A child's size was used without setting parentUsesSize."), + describeForError('The following render object'), + value._owner.describeForError('...was assigned a size obtained from its child'), + ErrorDescription( + 'However, when the child was laid out, the parentUsesSize argument ' + 'was not set or set to false. Subsequently this transpired to be ' + 'inaccurate: the size was nonetheless used by the parent.\n' + 'It is important to tell the framework if the size will be used or not ' + 'as several important performance optimizations can be made if the ' + 'size will not be used by the parent.', + ), + ]); + } + } + } + result = _DebugSize(value, this, debugCanParentUseSize); + return true; + }()); + return result; + } + + @override + Rect get semanticBounds => Offset.zero & size; + + @override + void debugResetSize() { + // updates the value of size._canBeUsedByParent if necessary + size = size; // ignore: no_self_assignments + } + + Map<TextBaseline, double?>? _cachedBaselines; + static bool _debugDoingBaseline = false; + static bool _debugSetDoingBaseline(bool value) { + _debugDoingBaseline = value; + return true; + } + + /// Returns the distance from the y-coordinate of the position of the box to + /// the y-coordinate of the first given baseline in the box's contents. + /// + /// Used by certain layout models to align adjacent boxes on a common + /// baseline, regardless of padding, font size differences, etc. If there is + /// no baseline, this function returns the distance from the y-coordinate of + /// the position of the box to the y-coordinate of the bottom of the box + /// (i.e., the height of the box) unless the caller passes true + /// for `onlyReal`, in which case the function returns null. + /// + /// Only call this function after calling [layout] on this box. You + /// are only allowed to call this from the parent of this box during + /// that parent's [performLayout] or [paint] functions. + /// + /// When implementing a [RenderBox] subclass, to override the baseline + /// computation, override [computeDistanceToActualBaseline]. + double? getDistanceToBaseline(TextBaseline baseline, { bool onlyReal = false }) { + assert(!_debugDoingBaseline, 'Please see the documentation for computeDistanceToActualBaseline for the required calling conventions of this method.'); + assert(!debugNeedsLayout); + assert(() { + if (owner!.debugDoingLayout) { + return (RenderObject.debugActiveLayout == parent) && parent!.debugDoingThisLayout; + } + if (owner!.debugDoingPaint) { + return ((RenderObject.debugActivePaint == parent) && parent!.debugDoingThisPaint) || + ((RenderObject.debugActivePaint == this) && debugDoingThisPaint); + } + return false; + }()); + assert(_debugSetDoingBaseline(true)); + final double? result; + try { + result = getDistanceToActualBaseline(baseline); + } finally { + assert(_debugSetDoingBaseline(false)); + } + if (result == null && !onlyReal) { + return size.height; + } + return result; + } + + /// Calls [computeDistanceToActualBaseline] and caches the result. + /// + /// This function must only be called from [getDistanceToBaseline] and + /// [computeDistanceToActualBaseline]. Do not call this function directly from + /// outside those two methods. + @protected + @mustCallSuper + double? getDistanceToActualBaseline(TextBaseline baseline) { + assert(_debugDoingBaseline, 'Please see the documentation for computeDistanceToActualBaseline for the required calling conventions of this method.'); + _cachedBaselines ??= <TextBaseline, double?>{}; + return _cachedBaselines!.putIfAbsent(baseline, () => computeDistanceToActualBaseline(baseline)); + } + + /// Returns the distance from the y-coordinate of the position of the box to + /// the y-coordinate of the first given baseline in the box's contents, if + /// any, or null otherwise. + /// + /// Do not call this function directly. If you need to know the baseline of a + /// child from an invocation of [performLayout] or [paint], call + /// [getDistanceToBaseline]. + /// + /// Subclasses should override this method to supply the distances to their + /// baselines. When implementing this method, there are generally three + /// strategies: + /// + /// * For classes that use the [ContainerRenderObjectMixin] child model, + /// consider mixing in the [RenderBoxContainerDefaultsMixin] class and + /// using + /// [RenderBoxContainerDefaultsMixin.defaultComputeDistanceToFirstActualBaseline]. + /// + /// * For classes that define a particular baseline themselves, return that + /// value directly. + /// + /// * For classes that have a child to which they wish to defer the + /// computation, call [getDistanceToActualBaseline] on the child (not + /// [computeDistanceToActualBaseline], the internal implementation, and not + /// [getDistanceToBaseline], the public entry point for this API). + @protected + double? computeDistanceToActualBaseline(TextBaseline baseline) { + assert(_debugDoingBaseline, 'Please see the documentation for computeDistanceToActualBaseline for the required calling conventions of this method.'); + return null; + } + + /// The box constraints most recently received from the parent. + @override + BoxConstraints get constraints => super.constraints as BoxConstraints; + + @override + void debugAssertDoesMeetConstraints() { + assert(() { + if (!hasSize) { + final DiagnosticsNode contract; + if (sizedByParent) { + contract = ErrorDescription('Because this RenderBox has sizedByParent set to true, it must set its size in performResize().'); + } else { + contract = ErrorDescription('Because this RenderBox has sizedByParent set to false, it must set its size in performLayout().'); + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('RenderBox did not set its size during layout.'), + contract, + ErrorDescription('It appears that this did not happen; layout completed, but the size property is still null.'), + DiagnosticsProperty<RenderBox>('The RenderBox in question is', this, style: DiagnosticsTreeStyle.errorProperty), + ]); + } + // verify that the size is not infinite + if (!_size!.isFinite) { + final List<DiagnosticsNode> information = <DiagnosticsNode>[ + ErrorSummary('$runtimeType object was given an infinite size during layout.'), + ErrorDescription( + 'This probably means that it is a render object that tries to be ' + 'as big as possible, but it was put inside another render object ' + 'that allows its children to pick their own size.', + ), + ]; + if (!constraints.hasBoundedWidth) { + RenderBox node = this; + while (!node.constraints.hasBoundedWidth && node.parent is RenderBox) { + node = node.parent! as RenderBox; + } + + information.add(node.describeForError('The nearest ancestor providing an unbounded width constraint is')); + } + if (!constraints.hasBoundedHeight) { + RenderBox node = this; + while (!node.constraints.hasBoundedHeight && node.parent is RenderBox) { + node = node.parent! as RenderBox; + } + + information.add(node.describeForError('The nearest ancestor providing an unbounded height constraint is')); + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ...information, + DiagnosticsProperty<BoxConstraints>('The constraints that applied to the $runtimeType were', constraints, style: DiagnosticsTreeStyle.errorProperty), + DiagnosticsProperty<Size>('The exact size it was given was', _size, style: DiagnosticsTreeStyle.errorProperty), + ErrorHint('See https://flutter.dev/docs/development/ui/layout/box-constraints for more information.'), + ]); + } + // verify that the size is within the constraints + if (!constraints.isSatisfiedBy(_size!)) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$runtimeType does not meet its constraints.'), + DiagnosticsProperty<BoxConstraints>('Constraints', constraints, style: DiagnosticsTreeStyle.errorProperty), + DiagnosticsProperty<Size>('Size', _size, style: DiagnosticsTreeStyle.errorProperty), + ErrorHint( + 'If you are not writing your own RenderBox subclass, then this is not ' + 'your fault. Contact support: https://github.com/flutter/flutter/issues/new?template=2_bug.yml', + ), + ]); + } + if (debugCheckIntrinsicSizes) { + // verify that the intrinsics are sane + assert(!RenderObject.debugCheckingIntrinsics); + RenderObject.debugCheckingIntrinsics = true; + final List<DiagnosticsNode> failures = <DiagnosticsNode>[]; + + double testIntrinsic(double Function(double extent) function, String name, double constraint) { + final double result = function(constraint); + if (result < 0) { + failures.add(ErrorDescription(' * $name($constraint) returned a negative value: $result')); + } + if (!result.isFinite) { + failures.add(ErrorDescription(' * $name($constraint) returned a non-finite value: $result')); + } + return result; + } + + void testIntrinsicsForValues(double Function(double extent) getMin, double Function(double extent) getMax, String name, double constraint) { + final double min = testIntrinsic(getMin, 'getMinIntrinsic$name', constraint); + final double max = testIntrinsic(getMax, 'getMaxIntrinsic$name', constraint); + if (min > max) { + failures.add(ErrorDescription(' * getMinIntrinsic$name($constraint) returned a larger value ($min) than getMaxIntrinsic$name($constraint) ($max)')); + } + } + + testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', double.infinity); + testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', double.infinity); + if (constraints.hasBoundedWidth) { + testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', constraints.maxHeight); + } + if (constraints.hasBoundedHeight) { + testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', constraints.maxWidth); + } + + // TODO(ianh): Test that values are internally consistent in more ways than the above. + + RenderObject.debugCheckingIntrinsics = false; + if (failures.isNotEmpty) { + // TODO(jacobr): consider nesting the failures object so it is collapsible. + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The intrinsic dimension methods of the $runtimeType class returned values that violate the intrinsic protocol contract.'), + ErrorDescription('The following ${failures.length > 1 ? "failures" : "failure"} was detected:'), // should this be tagged as an error or not? + ...failures, + ErrorHint( + 'If you are not writing your own RenderBox subclass, then this is not\n' + 'your fault. Contact support: https://github.com/flutter/flutter/issues/new?template=2_bug.yml', + ), + ]); + } + + // Checking that getDryLayout computes the same size. + _dryLayoutCalculationValid = true; + RenderObject.debugCheckingIntrinsics = true; + final Size dryLayoutSize; + try { + dryLayoutSize = getDryLayout(constraints); + } finally { + RenderObject.debugCheckingIntrinsics = false; + } + if (_dryLayoutCalculationValid && dryLayoutSize != size) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The size given to the ${objectRuntimeType(this, 'RenderBox')} class differs from the size computed by computeDryLayout.'), + ErrorDescription( + 'The size computed in ${sizedByParent ? 'performResize' : 'performLayout'} ' + 'is $size, which is different from $dryLayoutSize, which was computed by computeDryLayout.', + ), + ErrorDescription( + 'The constraints used were $constraints.', + ), + ErrorHint( + 'If you are not writing your own RenderBox subclass, then this is not\n' + 'your fault. Contact support: https://github.com/flutter/flutter/issues/new?template=2_bug.yml', + ), + ]); + } + } + return true; + }()); + } + + bool _clearCachedData() { + if ((_cachedBaselines != null && _cachedBaselines!.isNotEmpty) || + (_cachedIntrinsicDimensions != null && _cachedIntrinsicDimensions!.isNotEmpty) || + (_cachedDryLayoutSizes != null && _cachedDryLayoutSizes!.isNotEmpty)) { + // If we have cached data, then someone must have used our data. + // Since the parent will shortly be marked dirty, we can forget that they + // used the baseline and/or intrinsic dimensions. If they use them again, + // then we'll fill the cache again, and if we get dirty again, we'll + // notify them again. + _cachedBaselines?.clear(); + _cachedIntrinsicDimensions?.clear(); + _cachedDryLayoutSizes?.clear(); + return true; + } + return false; + } + + @override + void markNeedsLayout() { + if (_clearCachedData() && parent is RenderObject) { + markParentNeedsLayout(); + return; + } + super.markNeedsLayout(); + } + + @override + void layout(Constraints constraints, {bool parentUsesSize = false}) { + if (hasSize && constraints != this.constraints && + _cachedBaselines != null && _cachedBaselines!.isNotEmpty) { + // The cached baselines data may need update if the constraints change. + _cachedBaselines?.clear(); + } + super.layout(constraints, parentUsesSize: parentUsesSize); + } + + /// {@macro flutter.rendering.RenderObject.performResize} + /// + /// By default this method sets [size] to the result of [computeDryLayout] + /// called with the current [constraints]. Instead of overriding this method, + /// consider overriding [computeDryLayout]. + @override + void performResize() { + // default behavior for subclasses that have sizedByParent = true + size = computeDryLayout(constraints); + assert(size.isFinite); + } + + @override + void performLayout() { + assert(() { + if (!sizedByParent) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$runtimeType did not implement performLayout().'), + ErrorHint( + 'RenderBox subclasses need to either override performLayout() to ' + 'set a size and lay out any children, or, set sizedByParent to true ' + 'so that performResize() sizes the render object.', + ), + ]); + } + return true; + }()); + } + + /// Determines the set of render objects located at the given position. + /// + /// Returns true, and adds any render objects that contain the point to the + /// given hit test result, if this render object or one of its descendants + /// absorbs the hit (preventing objects below this one from being hit). + /// Returns false if the hit can continue to other objects below this one. + /// + /// The caller is responsible for transforming [position] from global + /// coordinates to its location relative to the origin of this [RenderBox]. + /// This [RenderBox] is responsible for checking whether the given position is + /// within its bounds. + /// + /// If transforming is necessary, [BoxHitTestResult.addWithPaintTransform], + /// [BoxHitTestResult.addWithPaintOffset], or + /// [BoxHitTestResult.addWithRawTransform] need to be invoked by the caller + /// to record the required transform operations in the [HitTestResult]. These + /// methods will also help with applying the transform to `position`. + /// + /// Hit testing requires layout to be up-to-date but does not require painting + /// to be up-to-date. That means a render object can rely upon [performLayout] + /// having been called in [hitTest] but cannot rely upon [paint] having been + /// called. For example, a render object might be a child of a [RenderOpacity] + /// object, which calls [hitTest] on its children when its opacity is zero + /// even through it does not [paint] its children. + bool hitTest(BoxHitTestResult result, { required Offset position }) { + assert(() { + if (!hasSize) { + if (debugNeedsLayout) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Cannot hit test a render box that has never been laid out.'), + describeForError('The hitTest() method was called on this RenderBox'), + ErrorDescription( + "Unfortunately, this object's geometry is not known at this time, " + 'probably because it has never been laid out. ' + 'This means it cannot be accurately hit-tested.', + ), + ErrorHint( + 'If you are trying ' + 'to perform a hit test during the layout phase itself, make sure ' + "you only hit test nodes that have completed layout (e.g. the node's " + 'children, after their layout() method has been called).', + ), + ]); + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Cannot hit test a render box with no size.'), + describeForError('The hitTest() method was called on this RenderBox'), + ErrorDescription( + 'Although this node is not marked as needing layout, ' + 'its size is not set.', + ), + ErrorHint( + 'A RenderBox object must have an ' + 'explicit size before it can be hit-tested. Make sure ' + 'that the RenderBox in question sets its size during layout.', + ), + ]); + } + return true; + }()); + if (_size!.contains(position)) { + if (hitTestChildren(result, position: position) || hitTestSelf(position)) { + result.add(BoxHitTestEntry(this, position)); + return true; + } + } + return false; + } + + /// Override this method if this render object can be hit even if its + /// children were not hit. + /// + /// Returns true if the specified `position` should be considered a hit + /// on this render object. + /// + /// The caller is responsible for transforming [position] from global + /// coordinates to its location relative to the origin of this [RenderBox]. + /// This [RenderBox] is responsible for checking whether the given position is + /// within its bounds. + /// + /// Used by [hitTest]. If you override [hitTest] and do not call this + /// function, then you don't need to implement this function. + @protected + bool hitTestSelf(Offset position) => false; + + /// Override this method to check whether any children are located at the + /// given position. + /// + /// Subclasses should return true if at least one child reported a hit at the + /// specified position. + /// + /// Typically children should be hit-tested in reverse paint order so that + /// hit tests at locations where children overlap hit the child that is + /// visually "on top" (i.e., paints later). + /// + /// The caller is responsible for transforming [position] from global + /// coordinates to its location relative to the origin of this [RenderBox]. + /// Likewise, this [RenderBox] is responsible for transforming the position + /// that it passes to its children when it calls [hitTest] on each child. + /// + /// If transforming is necessary, [BoxHitTestResult.addWithPaintTransform], + /// [BoxHitTestResult.addWithPaintOffset], or + /// [BoxHitTestResult.addWithRawTransform] need to be invoked by subclasses to + /// record the required transform operations in the [BoxHitTestResult]. These + /// methods will also help with applying the transform to `position`. + /// + /// Used by [hitTest]. If you override [hitTest] and do not call this + /// function, then you don't need to implement this function. + @protected + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) => false; + + /// Multiply the transform from the parent's coordinate system to this box's + /// coordinate system into the given transform. + /// + /// This function is used to convert coordinate systems between boxes. + /// Subclasses that apply transforms during painting should override this + /// function to factor those transforms into the calculation. + /// + /// The [RenderBox] implementation takes care of adjusting the matrix for the + /// position of the given child as determined during layout and stored on the + /// child's [parentData] in the [BoxParentData.offset] field. + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + assert(child.parent == this); + assert(() { + if (child.parentData is! BoxParentData) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$runtimeType does not implement applyPaintTransform.'), + describeForError('The following $runtimeType object'), + child.describeForError('...did not use a BoxParentData class for the parentData field of the following child'), + ErrorDescription('The $runtimeType class inherits from RenderBox.'), + ErrorHint( + 'The default applyPaintTransform implementation provided by RenderBox assumes that the ' + 'children all use BoxParentData objects for their parentData field. ' + 'Since $runtimeType does not in fact use that ParentData class for its children, it must ' + 'provide an implementation of applyPaintTransform that supports the specific ParentData ' + 'subclass used by its children (which apparently is ${child.parentData.runtimeType}).', + ), + ]); + } + return true; + }()); + final BoxParentData childParentData = child.parentData! as BoxParentData; + final Offset offset = childParentData.offset; + transform.translate(offset.dx, offset.dy); + } + + /// Convert the given point from the global coordinate system in logical pixels + /// to the local coordinate system for this box. + /// + /// This method will un-project the point from the screen onto the widget, + /// which makes it different from [MatrixUtils.transformPoint]. + /// + /// If the transform from global coordinates to local coordinates is + /// degenerate, this function returns [Offset.zero]. + /// + /// If `ancestor` is non-null, this function converts the given point from the + /// coordinate system of `ancestor` (which must be an ancestor of this render + /// object) instead of from the global coordinate system. + /// + /// This method is implemented in terms of [getTransformTo]. + Offset globalToLocal(Offset point, { RenderObject? ancestor }) { + // We want to find point (p) that corresponds to a given point on the + // screen (s), but that also physically resides on the local render plane, + // so that it is useful for visually accurate gesture processing in the + // local space. For that, we can't simply transform 2D screen point to + // the 3D local space since the screen space lacks the depth component |z|, + // and so there are many 3D points that correspond to the screen point. + // We must first unproject the screen point onto the render plane to find + // the true 3D point that corresponds to the screen point. + // We do orthogonal unprojection after undoing perspective, in local space. + // The render plane is specified by renderBox offset (o) and Z axis (n). + // Unprojection is done by finding the intersection of the view vector (d) + // with the local X-Y plane: (o-s).dot(n) == (p-s).dot(n), (p-s) == |z|*d. + final Matrix4 transform = getTransformTo(ancestor); + final double det = transform.invert(); + if (det == 0.0) { + return Offset.zero; + } + final Vector3 n = Vector3(0.0, 0.0, 1.0); + final Vector3 i = transform.perspectiveTransform(Vector3(0.0, 0.0, 0.0)); + final Vector3 d = transform.perspectiveTransform(Vector3(0.0, 0.0, 1.0)) - i; + final Vector3 s = transform.perspectiveTransform(Vector3(point.dx, point.dy, 0.0)); + final Vector3 p = s - d * (n.dot(s) / n.dot(d)); + return Offset(p.x, p.y); + } + + /// Convert the given point from the local coordinate system for this box to + /// the global coordinate system in logical pixels. + /// + /// If `ancestor` is non-null, this function converts the given point to the + /// coordinate system of `ancestor` (which must be an ancestor of this render + /// object) instead of to the global coordinate system. + /// + /// This method is implemented in terms of [getTransformTo]. If the transform + /// matrix puts the given `point` on the line at infinity (for instance, when + /// the transform matrix is the zero matrix), this method returns (NaN, NaN). + Offset localToGlobal(Offset point, { RenderObject? ancestor }) { + return MatrixUtils.transformPoint(getTransformTo(ancestor), point); + } + + /// Returns a rectangle that contains all the pixels painted by this box. + /// + /// The paint bounds can be larger or smaller than [size], which is the amount + /// of space this box takes up during layout. For example, if this box casts a + /// shadow, that shadow might extend beyond the space allocated to this box + /// during layout. + /// + /// The paint bounds are used to size the buffers into which this box paints. + /// If the box attempts to paints outside its paint bounds, there might not be + /// enough memory allocated to represent the box's visual appearance, which + /// can lead to undefined behavior. + /// + /// The returned paint bounds are in the local coordinate system of this box. + @override + Rect get paintBounds => Offset.zero & size; + + /// Override this method to handle pointer events that hit this render object. + /// + /// For [RenderBox] objects, the `entry` argument is a [BoxHitTestEntry]. From this + /// object you can determine the [PointerDownEvent]'s position in local coordinates. + /// (This is useful because [PointerEvent.position] is in global coordinates.) + /// + /// Implementations of this method should call [debugHandleEvent] as follows, + /// so that they support [debugPaintPointersEnabled]: + /// + /// ```dart + /// class RenderFoo extends RenderBox { + /// // ... + /// + /// @override + /// void handleEvent(PointerEvent event, HitTestEntry entry) { + /// assert(debugHandleEvent(event, entry)); + /// // ... handle the event ... + /// } + /// + /// // ... + /// } + /// ``` + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + super.handleEvent(event, entry); + } + + int _debugActivePointers = 0; + + /// Implements the [debugPaintPointersEnabled] debugging feature. + /// + /// [RenderBox] subclasses that implement [handleEvent] should call + /// [debugHandleEvent] from their [handleEvent] method, as follows: + /// + /// ```dart + /// class RenderFoo extends RenderBox { + /// // ... + /// + /// @override + /// void handleEvent(PointerEvent event, HitTestEntry entry) { + /// assert(debugHandleEvent(event, entry)); + /// // ... handle the event ... + /// } + /// + /// // ... + /// } + /// ``` + /// + /// If you call this for a [PointerDownEvent], make sure you also call it for + /// the corresponding [PointerUpEvent] or [PointerCancelEvent]. + bool debugHandleEvent(PointerEvent event, HitTestEntry entry) { + assert(() { + if (debugPaintPointersEnabled) { + if (event is PointerDownEvent) { + _debugActivePointers += 1; + } else if (event is PointerUpEvent || event is PointerCancelEvent) { + _debugActivePointers -= 1; + } + markNeedsPaint(); + } + return true; + }()); + return true; + } + + @override + void debugPaint(PaintingContext context, Offset offset) { + assert(() { + if (debugPaintSizeEnabled) { + debugPaintSize(context, offset); + } + if (debugPaintBaselinesEnabled) { + debugPaintBaselines(context, offset); + } + if (debugPaintPointersEnabled) { + debugPaintPointers(context, offset); + } + return true; + }()); + } + + /// In debug mode, paints a border around this render box. + /// + /// Called for every [RenderBox] when [debugPaintSizeEnabled] is true. + @protected + @visibleForTesting + void debugPaintSize(PaintingContext context, Offset offset) { + assert(() { + final Paint paint = Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 1.0 + ..color = const Color(0xFF00FFFF); + context.canvas.drawRect((offset & size).deflate(0.5), paint); + return true; + }()); + } + + /// In debug mode, paints a line for each baseline. + /// + /// Called for every [RenderBox] when [debugPaintBaselinesEnabled] is true. + @protected + void debugPaintBaselines(PaintingContext context, Offset offset) { + assert(() { + final Paint paint = Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 0.25; + Path path; + // ideographic baseline + final double? baselineI = getDistanceToBaseline(TextBaseline.ideographic, onlyReal: true); + if (baselineI != null) { + paint.color = const Color(0xFFFFD000); + path = Path(); + path.moveTo(offset.dx, offset.dy + baselineI); + path.lineTo(offset.dx + size.width, offset.dy + baselineI); + context.canvas.drawPath(path, paint); + } + // alphabetic baseline + final double? baselineA = getDistanceToBaseline(TextBaseline.alphabetic, onlyReal: true); + if (baselineA != null) { + paint.color = const Color(0xFF00FF00); + path = Path(); + path.moveTo(offset.dx, offset.dy + baselineA); + path.lineTo(offset.dx + size.width, offset.dy + baselineA); + context.canvas.drawPath(path, paint); + } + return true; + }()); + } + + /// In debug mode, paints a rectangle if this render box has counted more + /// pointer downs than pointer up events. + /// + /// Called for every [RenderBox] when [debugPaintPointersEnabled] is true. + /// + /// By default, events are not counted. For details on how to ensure that + /// events are counted for your class, see [debugHandleEvent]. + @protected + void debugPaintPointers(PaintingContext context, Offset offset) { + assert(() { + if (_debugActivePointers > 0) { + final Paint paint = Paint() + ..color = Color(0x00BBBB | ((0x04000000 * depth) & 0xFF000000)); + context.canvas.drawRect(offset & size, paint); + } + return true; + }()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Size>('size', _size, missingIfNull: true)); + } +} + +/// A mixin that provides useful default behaviors for boxes with children +/// managed by the [ContainerRenderObjectMixin] mixin. +/// +/// By convention, this class doesn't override any members of the superclass. +/// Instead, it provides helpful functions that subclasses can call as +/// appropriate. +mixin RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, ParentDataType extends ContainerBoxParentData<ChildType>> implements ContainerRenderObjectMixin<ChildType, ParentDataType> { + /// Returns the baseline of the first child with a baseline. + /// + /// Useful when the children are displayed vertically in the same order they + /// appear in the child list. + double? defaultComputeDistanceToFirstActualBaseline(TextBaseline baseline) { + assert(!debugNeedsLayout); + ChildType? child = firstChild; + while (child != null) { + final ParentDataType? childParentData = child.parentData as ParentDataType?; + final double? result = child.getDistanceToActualBaseline(baseline); + if (result != null) { + return result + childParentData!.offset.dy; + } + child = childParentData!.nextSibling; + } + return null; + } + + /// Returns the minimum baseline value among every child. + /// + /// Useful when the vertical position of the children isn't determined by the + /// order in the child list. + double? defaultComputeDistanceToHighestActualBaseline(TextBaseline baseline) { + assert(!debugNeedsLayout); + double? result; + ChildType? child = firstChild; + while (child != null) { + final ParentDataType childParentData = child.parentData! as ParentDataType; + double? candidate = child.getDistanceToActualBaseline(baseline); + if (candidate != null) { + candidate += childParentData.offset.dy; + if (result != null) { + result = math.min(result, candidate); + } else { + result = candidate; + } + } + child = childParentData.nextSibling; + } + return result; + } + + /// Performs a hit test on each child by walking the child list backwards. + /// + /// Stops walking once after the first child reports that it contains the + /// given point. Returns whether any children contain the given point. + /// + /// See also: + /// + /// * [defaultPaint], which paints the children appropriate for this + /// hit-testing strategy. + bool defaultHitTestChildren(BoxHitTestResult result, { required Offset position }) { + ChildType? child = lastChild; + while (child != null) { + // The x, y parameters have the top left of the node's box as the origin. + final ParentDataType childParentData = child.parentData! as ParentDataType; + final bool isHit = result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - childParentData.offset); + return child!.hitTest(result, position: transformed); + }, + ); + if (isHit) { + return true; + } + child = childParentData.previousSibling; + } + return false; + } + + /// Paints each child by walking the child list forwards. + /// + /// See also: + /// + /// * [defaultHitTestChildren], which implements hit-testing of the children + /// in a manner appropriate for this painting strategy. + void defaultPaint(PaintingContext context, Offset offset) { + ChildType? child = firstChild; + while (child != null) { + final ParentDataType childParentData = child.parentData! as ParentDataType; + context.paintChild(child, childParentData.offset + offset); + child = childParentData.nextSibling; + } + } + + /// Returns a list containing the children of this render object. + /// + /// This function is useful when you need random-access to the children of + /// this render object. If you're accessing the children in order, consider + /// walking the child list directly. + List<ChildType> getChildrenAsList() { + final List<ChildType> result = <ChildType>[]; + RenderBox? child = firstChild; + while (child != null) { + final ParentDataType childParentData = child.parentData! as ParentDataType; + result.add(child as ChildType); + child = childParentData.nextSibling; + } + return result; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/custom_layout.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/custom_layout.dart new file mode 100644 index 0000000000000000000000000000000000000000..f37869dddc214a5c7dd33c32881ee5c3f81c3ba0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/custom_layout.dart @@ -0,0 +1,416 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'object.dart'; + +// For SingleChildLayoutDelegate and RenderCustomSingleChildLayoutBox, see shifted_box.dart + +/// [ParentData] used by [RenderCustomMultiChildLayoutBox]. +class MultiChildLayoutParentData extends ContainerBoxParentData<RenderBox> { + /// An object representing the identity of this child. + Object? id; + + @override + String toString() => '${super.toString()}; id=$id'; +} + +/// A delegate that controls the layout of multiple children. +/// +/// Used with [CustomMultiChildLayout] (in the widgets library) and +/// [RenderCustomMultiChildLayoutBox] (in the rendering library). +/// +/// Delegates must be idempotent. Specifically, if two delegates are equal, then +/// they must produce the same layout. To change the layout, replace the +/// delegate with a different instance whose [shouldRelayout] returns true when +/// given the previous instance. +/// +/// Override [getSize] to control the overall size of the layout. The size of +/// the layout cannot depend on layout properties of the children. This was +/// a design decision to simplify the delegate implementations: This way, +/// the delegate implementations do not have to also handle various intrinsic +/// sizing functions if the parent's size depended on the children. +/// If you want to build a custom layout where you define the size of that widget +/// based on its children, then you will have to create a custom render object. +/// See [MultiChildRenderObjectWidget] with [ContainerRenderObjectMixin] and +/// [RenderBoxContainerDefaultsMixin] to get started or [RenderStack] for an +/// example implementation. +/// +/// Override [performLayout] to size and position the children. An +/// implementation of [performLayout] must call [layoutChild] exactly once for +/// each child, but it may call [layoutChild] on children in an arbitrary order. +/// Typically a delegate will use the size returned from [layoutChild] on one +/// child to determine the constraints for [performLayout] on another child or +/// to determine the offset for [positionChild] for that child or another child. +/// +/// Override [shouldRelayout] to determine when the layout of the children needs +/// to be recomputed when the delegate changes. +/// +/// The most efficient way to trigger a relayout is to supply a `relayout` +/// argument to the constructor of the [MultiChildLayoutDelegate]. The custom +/// layout will listen to this value and relayout whenever the Listenable +/// notifies its listeners, such as when an [Animation] ticks. This allows +/// the custom layout to avoid the build phase of the pipeline. +/// +/// Each child must be wrapped in a [LayoutId] widget to assign the id that +/// identifies it to the delegate. The [LayoutId.id] needs to be unique among +/// the children that the [CustomMultiChildLayout] manages. +/// +/// {@tool snippet} +/// +/// Below is an example implementation of [performLayout] that causes one widget +/// (the follower) to be the same size as another (the leader): +/// +/// ```dart +/// // Define your own slot numbers, depending upon the id assigned by LayoutId. +/// // Typical usage is to define an enum like the one below, and use those +/// // values as the ids. +/// enum _Slot { +/// leader, +/// follower, +/// } +/// +/// class FollowTheLeader extends MultiChildLayoutDelegate { +/// @override +/// void performLayout(Size size) { +/// Size leaderSize = Size.zero; +/// +/// if (hasChild(_Slot.leader)) { +/// leaderSize = layoutChild(_Slot.leader, BoxConstraints.loose(size)); +/// positionChild(_Slot.leader, Offset.zero); +/// } +/// +/// if (hasChild(_Slot.follower)) { +/// layoutChild(_Slot.follower, BoxConstraints.tight(leaderSize)); +/// positionChild(_Slot.follower, Offset(size.width - leaderSize.width, +/// size.height - leaderSize.height)); +/// } +/// } +/// +/// @override +/// bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) => false; +/// } +/// ``` +/// {@end-tool} +/// +/// The delegate gives the leader widget loose constraints, which means the +/// child determines what size to be (subject to fitting within the given size). +/// The delegate then remembers the size of that child and places it in the +/// upper left corner. +/// +/// The delegate then gives the follower widget tight constraints, forcing it to +/// match the size of the leader widget. The delegate then places the follower +/// widget in the bottom right corner. +/// +/// The leader and follower widget will paint in the order they appear in the +/// child list, regardless of the order in which [layoutChild] is called on +/// them. +/// +/// See also: +/// +/// * [CustomMultiChildLayout], the widget that uses this delegate. +/// * [RenderCustomMultiChildLayoutBox], render object that uses this +/// delegate. +abstract class MultiChildLayoutDelegate { + /// Creates a layout delegate. + /// + /// The layout will update whenever [relayout] notifies its listeners. + MultiChildLayoutDelegate({ Listenable? relayout }) : _relayout = relayout; + + final Listenable? _relayout; + + Map<Object, RenderBox>? _idToChild; + Set<RenderBox>? _debugChildrenNeedingLayout; + + /// True if a non-null LayoutChild was provided for the specified id. + /// + /// Call this from the [performLayout] method to determine which children + /// are available, if the child list might vary. + /// + /// This method cannot be called from [getSize] as the size is not allowed + /// to depend on the children. + bool hasChild(Object childId) => _idToChild![childId] != null; + + /// Ask the child to update its layout within the limits specified by + /// the constraints parameter. The child's size is returned. + /// + /// Call this from your [performLayout] function to lay out each + /// child. Every child must be laid out using this function exactly + /// once each time the [performLayout] function is called. + Size layoutChild(Object childId, BoxConstraints constraints) { + final RenderBox? child = _idToChild![childId]; + assert(() { + if (child == null) { + throw FlutterError( + 'The $this custom multichild layout delegate tried to lay out a non-existent child.\n' + 'There is no child with the id "$childId".', + ); + } + if (!_debugChildrenNeedingLayout!.remove(child)) { + throw FlutterError( + 'The $this custom multichild layout delegate tried to lay out the child with id "$childId" more than once.\n' + 'Each child must be laid out exactly once.', + ); + } + try { + assert(constraints.debugAssertIsValid(isAppliedConstraint: true)); + } on AssertionError catch (exception) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The $this custom multichild layout delegate provided invalid box constraints for the child with id "$childId".'), + DiagnosticsProperty<AssertionError>('Exception', exception, showName: false), + ErrorDescription( + 'The minimum width and height must be greater than or equal to zero.\n' + 'The maximum width must be greater than or equal to the minimum width.\n' + 'The maximum height must be greater than or equal to the minimum height.', + ), + ]); + } + return true; + }()); + child!.layout(constraints, parentUsesSize: true); + return child.size; + } + + /// Specify the child's origin relative to this origin. + /// + /// Call this from your [performLayout] function to position each + /// child. If you do not call this for a child, its position will + /// remain unchanged. Children initially have their position set to + /// (0,0), i.e. the top left of the [RenderCustomMultiChildLayoutBox]. + void positionChild(Object childId, Offset offset) { + final RenderBox? child = _idToChild![childId]; + assert(() { + if (child == null) { + throw FlutterError( + 'The $this custom multichild layout delegate tried to position out a non-existent child:\n' + 'There is no child with the id "$childId".', + ); + } + return true; + }()); + final MultiChildLayoutParentData childParentData = child!.parentData! as MultiChildLayoutParentData; + childParentData.offset = offset; + } + + DiagnosticsNode _debugDescribeChild(RenderBox child) { + final MultiChildLayoutParentData childParentData = child.parentData! as MultiChildLayoutParentData; + return DiagnosticsProperty<RenderBox>('${childParentData.id}', child); + } + + void _callPerformLayout(Size size, RenderBox? firstChild) { + // A particular layout delegate could be called reentrantly, e.g. if it used + // by both a parent and a child. So, we must restore the _idToChild map when + // we return. + final Map<Object, RenderBox>? previousIdToChild = _idToChild; + + Set<RenderBox>? debugPreviousChildrenNeedingLayout; + assert(() { + debugPreviousChildrenNeedingLayout = _debugChildrenNeedingLayout; + _debugChildrenNeedingLayout = <RenderBox>{}; + return true; + }()); + + try { + _idToChild = <Object, RenderBox>{}; + RenderBox? child = firstChild; + while (child != null) { + final MultiChildLayoutParentData childParentData = child.parentData! as MultiChildLayoutParentData; + assert(() { + if (childParentData.id == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Every child of a RenderCustomMultiChildLayoutBox must have an ID in its parent data.'), + child!.describeForError('The following child has no ID'), + ]); + } + return true; + }()); + _idToChild![childParentData.id!] = child; + assert(() { + _debugChildrenNeedingLayout!.add(child!); + return true; + }()); + child = childParentData.nextSibling; + } + performLayout(size); + assert(() { + if (_debugChildrenNeedingLayout!.isNotEmpty) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Each child must be laid out exactly once.'), + DiagnosticsBlock( + name: + 'The $this custom multichild layout delegate forgot ' + 'to lay out the following ' + '${_debugChildrenNeedingLayout!.length > 1 ? 'children' : 'child'}', + properties: _debugChildrenNeedingLayout!.map<DiagnosticsNode>(_debugDescribeChild).toList(), + ), + ]); + } + return true; + }()); + } finally { + _idToChild = previousIdToChild; + assert(() { + _debugChildrenNeedingLayout = debugPreviousChildrenNeedingLayout; + return true; + }()); + } + } + + /// Override this method to return the size of this object given the + /// incoming constraints. + /// + /// The size cannot reflect the sizes of the children. If this layout has a + /// fixed width or height the returned size can reflect that; the size will be + /// constrained to the given constraints. + /// + /// By default, attempts to size the box to the biggest size + /// possible given the constraints. + Size getSize(BoxConstraints constraints) => constraints.biggest; + + /// Override this method to lay out and position all children given this + /// widget's size. + /// + /// This method must call [layoutChild] for each child. It should also specify + /// the final position of each child with [positionChild]. + void performLayout(Size size); + + /// Override this method to return true when the children need to be + /// laid out. + /// + /// This should compare the fields of the current delegate and the given + /// `oldDelegate` and return true if the fields are such that the layout would + /// be different. + bool shouldRelayout(covariant MultiChildLayoutDelegate oldDelegate); + + /// Override this method to include additional information in the + /// debugging data printed by [debugDumpRenderTree] and friends. + /// + /// By default, returns the [runtimeType] of the class. + @override + String toString() => objectRuntimeType(this, 'MultiChildLayoutDelegate'); +} + +/// Defers the layout of multiple children to a delegate. +/// +/// The delegate can determine the layout constraints for each child and can +/// decide where to position each child. The delegate can also determine the +/// size of the parent, but the size of the parent cannot depend on the sizes of +/// the children. +class RenderCustomMultiChildLayoutBox extends RenderBox + with ContainerRenderObjectMixin<RenderBox, MultiChildLayoutParentData>, + RenderBoxContainerDefaultsMixin<RenderBox, MultiChildLayoutParentData> { + /// Creates a render object that customizes the layout of multiple children. + RenderCustomMultiChildLayoutBox({ + List<RenderBox>? children, + required MultiChildLayoutDelegate delegate, + }) : _delegate = delegate { + addAll(children); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! MultiChildLayoutParentData) { + child.parentData = MultiChildLayoutParentData(); + } + } + + /// The delegate that controls the layout of the children. + MultiChildLayoutDelegate get delegate => _delegate; + MultiChildLayoutDelegate _delegate; + set delegate(MultiChildLayoutDelegate newDelegate) { + if (_delegate == newDelegate) { + return; + } + final MultiChildLayoutDelegate oldDelegate = _delegate; + if (newDelegate.runtimeType != oldDelegate.runtimeType || newDelegate.shouldRelayout(oldDelegate)) { + markNeedsLayout(); + } + _delegate = newDelegate; + if (attached) { + oldDelegate._relayout?.removeListener(markNeedsLayout); + newDelegate._relayout?.addListener(markNeedsLayout); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _delegate._relayout?.addListener(markNeedsLayout); + } + + @override + void detach() { + _delegate._relayout?.removeListener(markNeedsLayout); + super.detach(); + } + + Size _getSize(BoxConstraints constraints) { + assert(constraints.debugAssertIsValid()); + return constraints.constrain(_delegate.getSize(constraints)); + } + + // TODO(ianh): It's a bit dubious to be using the getSize function from the delegate to + // figure out the intrinsic dimensions. We really should either not support intrinsics, + // or we should expose intrinsic delegate callbacks and throw if they're not implemented. + + @override + double computeMinIntrinsicWidth(double height) { + final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width; + if (width.isFinite) { + return width; + } + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width; + if (width.isFinite) { + return width; + } + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height; + if (height.isFinite) { + return height; + } + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height; + if (height.isFinite) { + return height; + } + return 0.0; + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return _getSize(constraints); + } + + @override + void performLayout() { + size = _getSize(constraints); + delegate._callPerformLayout(size, firstChild); + } + + @override + void paint(PaintingContext context, Offset offset) { + defaultPaint(context, offset); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + return defaultHitTestChildren(result, position: position); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/custom_paint.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/custom_paint.dart new file mode 100644 index 0000000000000000000000000000000000000000..dac9d6634df41879682d31ce90d11b82d3e1dd58 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/custom_paint.dart @@ -0,0 +1,1066 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/semantics.dart'; + +import 'box.dart'; +import 'object.dart'; +import 'proxy_box.dart'; + +/// Signature of the function returned by [CustomPainter.semanticsBuilder]. +/// +/// Builds semantics information describing the picture drawn by a +/// [CustomPainter]. Each [CustomPainterSemantics] in the returned list is +/// converted into a [SemanticsNode] by copying its properties. +/// +/// The returned list must not be mutated after this function completes. To +/// change the semantic information, the function must return a new list +/// instead. +typedef SemanticsBuilderCallback = List<CustomPainterSemantics> Function(Size size); + +/// The interface used by [CustomPaint] (in the widgets library) and +/// [RenderCustomPaint] (in the rendering library). +/// +/// To implement a custom painter, either subclass or implement this interface +/// to define your custom paint delegate. [CustomPainter] subclasses must +/// implement the [paint] and [shouldRepaint] methods, and may optionally also +/// implement the [hitTest] and [shouldRebuildSemantics] methods, and the +/// [semanticsBuilder] getter. +/// +/// The [paint] method is called whenever the custom object needs to be repainted. +/// +/// The [shouldRepaint] method is called when a new instance of the class +/// is provided, to check if the new instance actually represents different +/// information. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=vvI_NUXK00s} +/// +/// The most efficient way to trigger a repaint is to either: +/// +/// * Extend this class and supply a `repaint` argument to the constructor of +/// the [CustomPainter], where that object notifies its listeners when it is +/// time to repaint. +/// * Extend [Listenable] (e.g. via [ChangeNotifier]) and implement +/// [CustomPainter], so that the object itself provides the notifications +/// directly. +/// +/// In either case, the [CustomPaint] widget or [RenderCustomPaint] +/// render object will listen to the [Listenable] and repaint whenever the +/// animation ticks, avoiding both the build and layout phases of the pipeline. +/// +/// The [hitTest] method is called when the user interacts with the underlying +/// render object, to determine if the user hit the object or missed it. +/// +/// The [semanticsBuilder] is called whenever the custom object needs to rebuild +/// its semantics information. +/// +/// The [shouldRebuildSemantics] method is called when a new instance of the +/// class is provided, to check if the new instance contains different +/// information that affects the semantics tree. +/// +/// {@tool snippet} +/// +/// This sample extends the same code shown for [RadialGradient] to create a +/// custom painter that paints a sky. +/// +/// ```dart +/// class Sky extends CustomPainter { +/// @override +/// void paint(Canvas canvas, Size size) { +/// final Rect rect = Offset.zero & size; +/// const RadialGradient gradient = RadialGradient( +/// center: Alignment(0.7, -0.6), +/// radius: 0.2, +/// colors: <Color>[Color(0xFFFFFF00), Color(0xFF0099FF)], +/// stops: <double>[0.4, 1.0], +/// ); +/// canvas.drawRect( +/// rect, +/// Paint()..shader = gradient.createShader(rect), +/// ); +/// } +/// +/// @override +/// SemanticsBuilderCallback get semanticsBuilder { +/// return (Size size) { +/// // Annotate a rectangle containing the picture of the sun +/// // with the label "Sun". When text to speech feature is enabled on the +/// // device, a user will be able to locate the sun on this picture by +/// // touch. +/// Rect rect = Offset.zero & size; +/// final double width = size.shortestSide * 0.4; +/// rect = const Alignment(0.8, -0.9).inscribe(Size(width, width), rect); +/// return <CustomPainterSemantics>[ +/// CustomPainterSemantics( +/// rect: rect, +/// properties: const SemanticsProperties( +/// label: 'Sun', +/// textDirection: TextDirection.ltr, +/// ), +/// ), +/// ]; +/// }; +/// } +/// +/// // Since this Sky painter has no fields, it always paints +/// // the same thing and semantics information is the same. +/// // Therefore we return false here. If we had fields (set +/// // from the constructor) then we would return true if any +/// // of them differed from the same fields on the oldDelegate. +/// @override +/// bool shouldRepaint(Sky oldDelegate) => false; +/// @override +/// bool shouldRebuildSemantics(Sky oldDelegate) => false; +/// } +/// ``` +/// {@end-tool} +/// +/// ## Composition and the sharing of canvases +/// +/// Widgets (or rather, render objects) are composited together using a minimum +/// number of [Canvas]es, for performance reasons. As a result, a +/// [CustomPainter]'s [Canvas] may be the same as that used by other widgets +/// (including other [CustomPaint] widgets). +/// +/// This is mostly unnoticeable, except when using unusual [BlendMode]s. For +/// example, trying to use [BlendMode.dstOut] to "punch a hole" through a +/// previously-drawn image may erase more than was intended, because previous +/// widgets will have been painted onto the same canvas. +/// +/// To avoid this issue, consider using [Canvas.saveLayer] and +/// [Canvas.restore] when using such blend modes. Creating new layers is +/// relatively expensive, however, and should be done sparingly to avoid +/// introducing jank. +/// +/// See also: +/// +/// * [Canvas], the class that a custom painter uses to paint. +/// * [CustomPaint], the widget that uses [CustomPainter], and whose sample +/// code shows how to use the above `Sky` class. +/// * [RadialGradient], whose sample code section shows a different take +/// on the sample code above. +abstract class CustomPainter extends Listenable { + /// Creates a custom painter. + /// + /// The painter will repaint whenever `repaint` notifies its listeners. + const CustomPainter({ Listenable? repaint }) : _repaint = repaint; + + final Listenable? _repaint; + + /// Register a closure to be notified when it is time to repaint. + /// + /// The [CustomPainter] implementation merely forwards to the same method on + /// the [Listenable] provided to the constructor in the `repaint` argument, if + /// it was not null. + @override + void addListener(VoidCallback listener) => _repaint?.addListener(listener); + + /// Remove a previously registered closure from the list of closures that the + /// object notifies when it is time to repaint. + /// + /// The [CustomPainter] implementation merely forwards to the same method on + /// the [Listenable] provided to the constructor in the `repaint` argument, if + /// it was not null. + @override + void removeListener(VoidCallback listener) => _repaint?.removeListener(listener); + + /// Called whenever the object needs to paint. The given [Canvas] has its + /// coordinate space configured such that the origin is at the top left of the + /// box. The area of the box is the size of the [size] argument. + /// + /// Paint operations should remain inside the given area. Graphical + /// operations outside the bounds may be silently ignored, clipped, or not + /// clipped. It may sometimes be difficult to guarantee that a certain + /// operation is inside the bounds (e.g., drawing a rectangle whose size is + /// determined by user inputs). In that case, consider calling + /// [Canvas.clipRect] at the beginning of [paint] so everything that follows + /// will be guaranteed to only draw within the clipped area. + /// + /// Implementations should be wary of correctly pairing any calls to + /// [Canvas.save]/[Canvas.saveLayer] and [Canvas.restore], otherwise all + /// subsequent painting on this canvas may be affected, with potentially + /// hilarious but confusing results. + /// + /// To paint text on a [Canvas], use a [TextPainter]. + /// + /// To paint an image on a [Canvas]: + /// + /// 1. Obtain an [ImageStream], for example by calling [ImageProvider.resolve] + /// on an [AssetImage] or [NetworkImage] object. + /// + /// 2. Whenever the [ImageStream]'s underlying [ImageInfo] object changes + /// (see [ImageStream.addListener]), create a new instance of your custom + /// paint delegate, giving it the new [ImageInfo] object. + /// + /// 3. In your delegate's [paint] method, call the [Canvas.drawImage], + /// [Canvas.drawImageRect], or [Canvas.drawImageNine] methods to paint the + /// [ImageInfo.image] object, applying the [ImageInfo.scale] value to + /// obtain the correct rendering size. + void paint(Canvas canvas, Size size); + + /// Returns a function that builds semantic information for the picture drawn + /// by this painter. + /// + /// If the returned function is null, this painter will not contribute new + /// [SemanticsNode]s to the semantics tree and the [CustomPaint] corresponding + /// to this painter will not create a semantics boundary. However, if the + /// child of a [CustomPaint] is not null, the child may contribute + /// [SemanticsNode]s to the tree. + /// + /// See also: + /// + /// * [SemanticsConfiguration.isSemanticBoundary], which causes new + /// [SemanticsNode]s to be added to the semantics tree. + /// * [RenderCustomPaint], which uses this getter to build semantics. + SemanticsBuilderCallback? get semanticsBuilder => null; + + /// Called whenever a new instance of the custom painter delegate class is + /// provided to the [RenderCustomPaint] object, or any time that a new + /// [CustomPaint] object is created with a new instance of the custom painter + /// delegate class (which amounts to the same thing, because the latter is + /// implemented in terms of the former). + /// + /// If the new instance would cause [semanticsBuilder] to create different + /// semantics information, then this method should return true, otherwise it + /// should return false. + /// + /// If the method returns false, then the [semanticsBuilder] call might be + /// optimized away. + /// + /// It's possible that the [semanticsBuilder] will get called even if + /// [shouldRebuildSemantics] would return false. For example, it is called + /// when the [CustomPaint] is rendered for the very first time, or when the + /// box changes its size. + /// + /// By default this method delegates to [shouldRepaint] under the assumption + /// that in most cases semantics change when something new is drawn. + bool shouldRebuildSemantics(covariant CustomPainter oldDelegate) => shouldRepaint(oldDelegate); + + /// Called whenever a new instance of the custom painter delegate class is + /// provided to the [RenderCustomPaint] object, or any time that a new + /// [CustomPaint] object is created with a new instance of the custom painter + /// delegate class (which amounts to the same thing, because the latter is + /// implemented in terms of the former). + /// + /// If the new instance represents different information than the old + /// instance, then the method should return true, otherwise it should return + /// false. + /// + /// If the method returns false, then the [paint] call might be optimized + /// away. + /// + /// It's possible that the [paint] method will get called even if + /// [shouldRepaint] returns false (e.g. if an ancestor or descendant needed to + /// be repainted). It's also possible that the [paint] method will get called + /// without [shouldRepaint] being called at all (e.g. if the box changes + /// size). + /// + /// If a custom delegate has a particularly expensive paint function such that + /// repaints should be avoided as much as possible, a [RepaintBoundary] or + /// [RenderRepaintBoundary] (or other render object with + /// [RenderObject.isRepaintBoundary] set to true) might be helpful. + /// + /// The `oldDelegate` argument will never be null. + bool shouldRepaint(covariant CustomPainter oldDelegate); + + /// Called whenever a hit test is being performed on an object that is using + /// this custom paint delegate. + /// + /// The given point is relative to the same coordinate space as the last + /// [paint] call. + /// + /// The default behavior is to consider all points to be hits for + /// background painters, and no points to be hits for foreground painters. + /// + /// Return true if the given position corresponds to a point on the drawn + /// image that should be considered a "hit", false if it corresponds to a + /// point that should be considered outside the painted image, and null to use + /// the default behavior. + bool? hitTest(Offset position) => null; + + @override + String toString() => '${describeIdentity(this)}(${ _repaint?.toString() ?? "" })'; +} + +/// Contains properties describing information drawn in a rectangle contained by +/// the [Canvas] used by a [CustomPaint]. +/// +/// This information is used, for example, by assistive technologies to improve +/// the accessibility of applications. +/// +/// Implement [CustomPainter.semanticsBuilder] to build the semantic +/// description of the whole picture drawn by a [CustomPaint], rather than one +/// particular rectangle. +/// +/// See also: +/// +/// * [SemanticsNode], which is created using the properties of this class. +/// * [CustomPainter], which creates instances of this class. +@immutable +class CustomPainterSemantics { + /// Creates semantics information describing a rectangle on a canvas. + const CustomPainterSemantics({ + this.key, + required this.rect, + required this.properties, + this.transform, + this.tags, + }); + + /// Identifies this object in a list of siblings. + /// + /// [SemanticsNode] inherits this key, so that when the list of nodes is + /// updated, its nodes are updated from [CustomPainterSemantics] with matching + /// keys. + /// + /// If this is null, the update algorithm does not guarantee which + /// [SemanticsNode] will be updated using this instance. + /// + /// This value is assigned to [SemanticsNode.key] during update. + final Key? key; + + /// The location and size of the box on the canvas where this piece of semantic + /// information applies. + /// + /// This value is assigned to [SemanticsNode.rect] during update. + final Rect rect; + + /// The transform from the canvas' coordinate system to its parent's + /// coordinate system. + /// + /// This value is assigned to [SemanticsNode.transform] during update. + final Matrix4? transform; + + /// Contains properties that are assigned to the [SemanticsNode] created or + /// updated from this object. + /// + /// See also: + /// + /// * [Semantics], which is a widget that also uses [SemanticsProperties] to + /// annotate. + final SemanticsProperties properties; + + /// Tags used by the parent [SemanticsNode] to determine the layout of the + /// semantics tree. + /// + /// This value is assigned to [SemanticsNode.tags] during update. + final Set<SemanticsTag>? tags; +} + +/// Provides a canvas on which to draw during the paint phase. +/// +/// When asked to paint, [RenderCustomPaint] first asks its [painter] to paint +/// on the current canvas, then it paints its child, and then, after painting +/// its child, it asks its [foregroundPainter] to paint. The coordinate system of +/// the canvas matches the coordinate system of the [CustomPaint] object. The +/// painters are expected to paint within a rectangle starting at the origin and +/// encompassing a region of the given size. (If the painters paint outside +/// those bounds, there might be insufficient memory allocated to rasterize the +/// painting commands and the resulting behavior is undefined.) +/// +/// Painters are implemented by subclassing or implementing [CustomPainter]. +/// +/// Because custom paint calls its painters during paint, you cannot mark the +/// tree as needing a new layout during the callback (the layout for this frame +/// has already happened). +/// +/// Custom painters normally size themselves to their child. If they do not have +/// a child, they attempt to size themselves to the [preferredSize], which +/// defaults to [Size.zero]. +/// +/// See also: +/// +/// * [CustomPainter], the class that custom painter delegates should extend. +/// * [Canvas], the API provided to custom painter delegates. +class RenderCustomPaint extends RenderProxyBox { + /// Creates a render object that delegates its painting. + RenderCustomPaint({ + CustomPainter? painter, + CustomPainter? foregroundPainter, + Size preferredSize = Size.zero, + this.isComplex = false, + this.willChange = false, + RenderBox? child, + }) : _painter = painter, + _foregroundPainter = foregroundPainter, + _preferredSize = preferredSize, + super(child); + + /// The background custom paint delegate. + /// + /// This painter, if non-null, is called to paint behind the children. + CustomPainter? get painter => _painter; + CustomPainter? _painter; + /// Set a new background custom paint delegate. + /// + /// If the new delegate is the same as the previous one, this does nothing. + /// + /// If the new delegate is the same class as the previous one, then the new + /// delegate has its [CustomPainter.shouldRepaint] called; if the result is + /// true, then the delegate will be called. + /// + /// If the new delegate is a different class than the previous one, then the + /// delegate will be called. + /// + /// If the new value is null, then there is no background custom painter. + set painter(CustomPainter? value) { + if (_painter == value) { + return; + } + final CustomPainter? oldPainter = _painter; + _painter = value; + _didUpdatePainter(_painter, oldPainter); + } + + /// The foreground custom paint delegate. + /// + /// This painter, if non-null, is called to paint in front of the children. + CustomPainter? get foregroundPainter => _foregroundPainter; + CustomPainter? _foregroundPainter; + /// Set a new foreground custom paint delegate. + /// + /// If the new delegate is the same as the previous one, this does nothing. + /// + /// If the new delegate is the same class as the previous one, then the new + /// delegate has its [CustomPainter.shouldRepaint] called; if the result is + /// true, then the delegate will be called. + /// + /// If the new delegate is a different class than the previous one, then the + /// delegate will be called. + /// + /// If the new value is null, then there is no foreground custom painter. + set foregroundPainter(CustomPainter? value) { + if (_foregroundPainter == value) { + return; + } + final CustomPainter? oldPainter = _foregroundPainter; + _foregroundPainter = value; + _didUpdatePainter(_foregroundPainter, oldPainter); + } + + void _didUpdatePainter(CustomPainter? newPainter, CustomPainter? oldPainter) { + // Check if we need to repaint. + if (newPainter == null) { + assert(oldPainter != null); // We should be called only for changes. + markNeedsPaint(); + } else if (oldPainter == null || + newPainter.runtimeType != oldPainter.runtimeType || + newPainter.shouldRepaint(oldPainter)) { + markNeedsPaint(); + } + if (attached) { + oldPainter?.removeListener(markNeedsPaint); + newPainter?.addListener(markNeedsPaint); + } + + // Check if we need to rebuild semantics. + if (newPainter == null) { + assert(oldPainter != null); // We should be called only for changes. + if (attached) { + markNeedsSemanticsUpdate(); + } + } else if (oldPainter == null || + newPainter.runtimeType != oldPainter.runtimeType || + newPainter.shouldRebuildSemantics(oldPainter)) { + markNeedsSemanticsUpdate(); + } + } + + /// The size that this [RenderCustomPaint] should aim for, given the layout + /// constraints, if there is no child. + /// + /// Defaults to [Size.zero]. + /// + /// If there's a child, this is ignored, and the size of the child is used + /// instead. + Size get preferredSize => _preferredSize; + Size _preferredSize; + set preferredSize(Size value) { + if (preferredSize == value) { + return; + } + _preferredSize = value; + markNeedsLayout(); + } + + /// Whether to hint that this layer's painting should be cached. + /// + /// The compositor contains a raster cache that holds bitmaps of layers in + /// order to avoid the cost of repeatedly rendering those layers on each + /// frame. If this flag is not set, then the compositor will apply its own + /// heuristics to decide whether the layer containing this render object is + /// complex enough to benefit from caching. + bool isComplex; + + /// Whether the raster cache should be told that this painting is likely + /// to change in the next frame. + /// + /// This hint tells the compositor not to cache the layer containing this + /// render object because the cache will not be used in the future. If this + /// hint is not set, the compositor will apply its own heuristics to decide + /// whether this layer is likely to be reused in the future. + bool willChange; + + @override + double computeMinIntrinsicWidth(double height) { + if (child == null) { + return preferredSize.width.isFinite ? preferredSize.width : 0; + } + return super.computeMinIntrinsicWidth(height); + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (child == null) { + return preferredSize.width.isFinite ? preferredSize.width : 0; + } + return super.computeMaxIntrinsicWidth(height); + } + + @override + double computeMinIntrinsicHeight(double width) { + if (child == null) { + return preferredSize.height.isFinite ? preferredSize.height : 0; + } + return super.computeMinIntrinsicHeight(width); + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (child == null) { + return preferredSize.height.isFinite ? preferredSize.height : 0; + } + return super.computeMaxIntrinsicHeight(width); + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _painter?.addListener(markNeedsPaint); + _foregroundPainter?.addListener(markNeedsPaint); + } + + @override + void detach() { + _painter?.removeListener(markNeedsPaint); + _foregroundPainter?.removeListener(markNeedsPaint); + super.detach(); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + if (_foregroundPainter != null && (_foregroundPainter!.hitTest(position) ?? false)) { + return true; + } + return super.hitTestChildren(result, position: position); + } + + @override + bool hitTestSelf(Offset position) { + return _painter != null && (_painter!.hitTest(position) ?? true); + } + + @override + void performLayout() { + super.performLayout(); + markNeedsSemanticsUpdate(); + } + + @override + Size computeSizeForNoChild(BoxConstraints constraints) { + return constraints.constrain(preferredSize); + } + + void _paintWithPainter(Canvas canvas, Offset offset, CustomPainter painter) { + late int debugPreviousCanvasSaveCount; + canvas.save(); + assert(() { + debugPreviousCanvasSaveCount = canvas.getSaveCount(); + return true; + }()); + if (offset != Offset.zero) { + canvas.translate(offset.dx, offset.dy); + } + painter.paint(canvas, size); + assert(() { + // This isn't perfect. For example, we can't catch the case of + // someone first restoring, then setting a transform or whatnot, + // then saving. + // If this becomes a real problem, we could add logic to the + // Canvas class to lock the canvas at a particular save count + // such that restore() fails if it would take the lock count + // below that number. + final int debugNewCanvasSaveCount = canvas.getSaveCount(); + if (debugNewCanvasSaveCount > debugPreviousCanvasSaveCount) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'The $painter custom painter called canvas.save() or canvas.saveLayer() at least ' + '${debugNewCanvasSaveCount - debugPreviousCanvasSaveCount} more ' + 'time${debugNewCanvasSaveCount - debugPreviousCanvasSaveCount == 1 ? '' : 's' } ' + 'than it called canvas.restore().', + ), + ErrorDescription('This leaves the canvas in an inconsistent state and will probably result in a broken display.'), + ErrorHint('You must pair each call to save()/saveLayer() with a later matching call to restore().'), + ]); + } + if (debugNewCanvasSaveCount < debugPreviousCanvasSaveCount) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'The $painter custom painter called canvas.restore() ' + '${debugPreviousCanvasSaveCount - debugNewCanvasSaveCount} more ' + 'time${debugPreviousCanvasSaveCount - debugNewCanvasSaveCount == 1 ? '' : 's' } ' + 'than it called canvas.save() or canvas.saveLayer().', + ), + ErrorDescription('This leaves the canvas in an inconsistent state and will result in a broken display.'), + ErrorHint('You should only call restore() if you first called save() or saveLayer().'), + ]); + } + return debugNewCanvasSaveCount == debugPreviousCanvasSaveCount; + }()); + canvas.restore(); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (_painter != null) { + _paintWithPainter(context.canvas, offset, _painter!); + _setRasterCacheHints(context); + } + super.paint(context, offset); + if (_foregroundPainter != null) { + _paintWithPainter(context.canvas, offset, _foregroundPainter!); + _setRasterCacheHints(context); + } + } + + void _setRasterCacheHints(PaintingContext context) { + if (isComplex) { + context.setIsComplexHint(); + } + if (willChange) { + context.setWillChangeHint(); + } + } + + /// Builds semantics for the picture drawn by [painter]. + SemanticsBuilderCallback? _backgroundSemanticsBuilder; + + /// Builds semantics for the picture drawn by [foregroundPainter]. + SemanticsBuilderCallback? _foregroundSemanticsBuilder; + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + _backgroundSemanticsBuilder = painter?.semanticsBuilder; + _foregroundSemanticsBuilder = foregroundPainter?.semanticsBuilder; + config.isSemanticBoundary = _backgroundSemanticsBuilder != null || _foregroundSemanticsBuilder != null; + } + + /// Describe the semantics of the picture painted by the [painter]. + List<SemanticsNode>? _backgroundSemanticsNodes; + + /// Describe the semantics of the picture painted by the [foregroundPainter]. + List<SemanticsNode>? _foregroundSemanticsNodes; + + @override + void assembleSemanticsNode( + SemanticsNode node, + SemanticsConfiguration config, + Iterable<SemanticsNode> children, + ) { + assert(() { + if (child == null && children.isNotEmpty) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + '$runtimeType does not have a child widget but received a non-empty list of child SemanticsNode:\n' + '${children.join('\n')}', + ), + ]); + } + return true; + }()); + + final List<CustomPainterSemantics> backgroundSemantics = _backgroundSemanticsBuilder != null + ? _backgroundSemanticsBuilder!(size) + : const <CustomPainterSemantics>[]; + _backgroundSemanticsNodes = _updateSemanticsChildren(_backgroundSemanticsNodes, backgroundSemantics); + + final List<CustomPainterSemantics> foregroundSemantics = _foregroundSemanticsBuilder != null + ? _foregroundSemanticsBuilder!(size) + : const <CustomPainterSemantics>[]; + _foregroundSemanticsNodes = _updateSemanticsChildren(_foregroundSemanticsNodes, foregroundSemantics); + + final bool hasBackgroundSemantics = _backgroundSemanticsNodes != null && _backgroundSemanticsNodes!.isNotEmpty; + final bool hasForegroundSemantics = _foregroundSemanticsNodes != null && _foregroundSemanticsNodes!.isNotEmpty; + final List<SemanticsNode> finalChildren = <SemanticsNode>[ + if (hasBackgroundSemantics) ..._backgroundSemanticsNodes!, + ...children, + if (hasForegroundSemantics) ..._foregroundSemanticsNodes!, + ]; + super.assembleSemanticsNode(node, config, finalChildren); + } + + @override + void clearSemantics() { + super.clearSemantics(); + _backgroundSemanticsNodes = null; + _foregroundSemanticsNodes = null; + } + + /// Updates the nodes of `oldSemantics` using data in `newChildSemantics`, and + /// returns a new list containing child nodes sorted according to the order + /// specified by `newChildSemantics`. + /// + /// [SemanticsNode]s that match [CustomPainterSemantics] by [Key]s preserve + /// their [SemanticsNode.key] field. If a node with the same key appears in + /// a different position in the list, it is moved to the new position, but the + /// same object is reused. + /// + /// [SemanticsNode]s whose `key` is null may be updated from + /// [CustomPainterSemantics] whose `key` is also null. However, the algorithm + /// does not guarantee it. If your semantics require that specific nodes are + /// updated from specific [CustomPainterSemantics], it is recommended to match + /// them by specifying non-null keys. + /// + /// The algorithm tries to be as close to [RenderObjectElement.updateChildren] + /// as possible, deviating only where the concepts diverge between widgets and + /// semantics. For example, a [SemanticsNode] can be updated from a + /// [CustomPainterSemantics] based on `Key` alone; their types are not + /// considered because there is only one type of [SemanticsNode]. There is no + /// concept of a "forgotten" node in semantics, deactivated nodes, or global + /// keys. + static List<SemanticsNode> _updateSemanticsChildren( + List<SemanticsNode>? oldSemantics, + List<CustomPainterSemantics>? newChildSemantics, + ) { + oldSemantics = oldSemantics ?? const <SemanticsNode>[]; + newChildSemantics = newChildSemantics ?? const <CustomPainterSemantics>[]; + + assert(() { + final Map<Key, int> keys = HashMap<Key, int>(); + final List<DiagnosticsNode> information = <DiagnosticsNode>[]; + for (int i = 0; i < newChildSemantics!.length; i += 1) { + final CustomPainterSemantics child = newChildSemantics[i]; + if (child.key != null) { + if (keys.containsKey(child.key)) { + information.add(ErrorDescription('- duplicate key ${child.key} found at position $i')); + } + keys[child.key!] = i; + } + } + + if (information.isNotEmpty) { + information.insert(0, ErrorSummary('Failed to update the list of CustomPainterSemantics:')); + throw FlutterError.fromParts(information); + } + + return true; + }()); + + int newChildrenTop = 0; + int oldChildrenTop = 0; + int newChildrenBottom = newChildSemantics.length - 1; + int oldChildrenBottom = oldSemantics.length - 1; + + final List<SemanticsNode?> newChildren = List<SemanticsNode?>.filled(newChildSemantics.length, null); + + // Update the top of the list. + while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) { + final SemanticsNode oldChild = oldSemantics[oldChildrenTop]; + final CustomPainterSemantics newSemantics = newChildSemantics[newChildrenTop]; + if (!_canUpdateSemanticsChild(oldChild, newSemantics)) { + break; + } + final SemanticsNode newChild = _updateSemanticsChild(oldChild, newSemantics); + newChildren[newChildrenTop] = newChild; + newChildrenTop += 1; + oldChildrenTop += 1; + } + + // Scan the bottom of the list. + while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) { + final SemanticsNode oldChild = oldSemantics[oldChildrenBottom]; + final CustomPainterSemantics newChild = newChildSemantics[newChildrenBottom]; + if (!_canUpdateSemanticsChild(oldChild, newChild)) { + break; + } + oldChildrenBottom -= 1; + newChildrenBottom -= 1; + } + + // Scan the old children in the middle of the list. + final bool haveOldChildren = oldChildrenTop <= oldChildrenBottom; + late final Map<Key, SemanticsNode> oldKeyedChildren; + if (haveOldChildren) { + oldKeyedChildren = <Key, SemanticsNode>{}; + while (oldChildrenTop <= oldChildrenBottom) { + final SemanticsNode oldChild = oldSemantics[oldChildrenTop]; + if (oldChild.key != null) { + oldKeyedChildren[oldChild.key!] = oldChild; + } + oldChildrenTop += 1; + } + } + + // Update the middle of the list. + while (newChildrenTop <= newChildrenBottom) { + SemanticsNode? oldChild; + final CustomPainterSemantics newSemantics = newChildSemantics[newChildrenTop]; + if (haveOldChildren) { + final Key? key = newSemantics.key; + if (key != null) { + oldChild = oldKeyedChildren[key]; + if (oldChild != null) { + if (_canUpdateSemanticsChild(oldChild, newSemantics)) { + // we found a match! + // remove it from oldKeyedChildren so we don't unsync it later + oldKeyedChildren.remove(key); + } else { + // Not a match, let's pretend we didn't see it for now. + oldChild = null; + } + } + } + } + assert(oldChild == null || _canUpdateSemanticsChild(oldChild, newSemantics)); + final SemanticsNode newChild = _updateSemanticsChild(oldChild, newSemantics); + assert(oldChild == newChild || oldChild == null); + newChildren[newChildrenTop] = newChild; + newChildrenTop += 1; + } + + // We've scanned the whole list. + assert(oldChildrenTop == oldChildrenBottom + 1); + assert(newChildrenTop == newChildrenBottom + 1); + assert(newChildSemantics.length - newChildrenTop == oldSemantics.length - oldChildrenTop); + newChildrenBottom = newChildSemantics.length - 1; + oldChildrenBottom = oldSemantics.length - 1; + + // Update the bottom of the list. + while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) { + final SemanticsNode oldChild = oldSemantics[oldChildrenTop]; + final CustomPainterSemantics newSemantics = newChildSemantics[newChildrenTop]; + assert(_canUpdateSemanticsChild(oldChild, newSemantics)); + final SemanticsNode newChild = _updateSemanticsChild(oldChild, newSemantics); + assert(oldChild == newChild); + newChildren[newChildrenTop] = newChild; + newChildrenTop += 1; + oldChildrenTop += 1; + } + + assert(() { + for (final SemanticsNode? node in newChildren) { + assert(node != null); + } + return true; + }()); + + return newChildren.cast<SemanticsNode>(); + } + + /// Whether `oldChild` can be updated with properties from `newSemantics`. + /// + /// If `oldChild` can be updated, it is updated using [_updateSemanticsChild]. + /// Otherwise, the node is replaced by a new instance of [SemanticsNode]. + static bool _canUpdateSemanticsChild(SemanticsNode oldChild, CustomPainterSemantics newSemantics) { + return oldChild.key == newSemantics.key; + } + + /// Updates `oldChild` using the properties of `newSemantics`. + /// + /// This method requires that `_canUpdateSemanticsChild(oldChild, newSemantics)` + /// is true prior to calling it. + static SemanticsNode _updateSemanticsChild(SemanticsNode? oldChild, CustomPainterSemantics newSemantics) { + assert(oldChild == null || _canUpdateSemanticsChild(oldChild, newSemantics)); + + final SemanticsNode newChild = oldChild ?? SemanticsNode( + key: newSemantics.key, + ); + + final SemanticsProperties properties = newSemantics.properties; + final SemanticsConfiguration config = SemanticsConfiguration(); + if (properties.sortKey != null) { + config.sortKey = properties.sortKey; + } + if (properties.checked != null) { + config.isChecked = properties.checked; + } + if (properties.mixed != null) { + config.isCheckStateMixed = properties.mixed; + } + if (properties.selected != null) { + config.isSelected = properties.selected!; + } + if (properties.button != null) { + config.isButton = properties.button!; + } + if (properties.expanded != null) { + config.isExpanded = properties.expanded; + } + if (properties.link != null) { + config.isLink = properties.link!; + } + if (properties.textField != null) { + config.isTextField = properties.textField!; + } + if (properties.slider != null) { + config.isSlider = properties.slider!; + } + if (properties.keyboardKey != null) { + config.isKeyboardKey = properties.keyboardKey!; + } + if (properties.readOnly != null) { + config.isReadOnly = properties.readOnly!; + } + if (properties.focusable != null) { + config.isFocusable = properties.focusable!; + } + if (properties.focused != null) { + config.isFocused = properties.focused!; + } + if (properties.enabled != null) { + config.isEnabled = properties.enabled; + } + if (properties.inMutuallyExclusiveGroup != null) { + config.isInMutuallyExclusiveGroup = properties.inMutuallyExclusiveGroup!; + } + if (properties.obscured != null) { + config.isObscured = properties.obscured!; + } + if (properties.multiline != null) { + config.isMultiline = properties.multiline!; + } + if (properties.hidden != null) { + config.isHidden = properties.hidden!; + } + if (properties.header != null) { + config.isHeader = properties.header!; + } + if (properties.scopesRoute != null) { + config.scopesRoute = properties.scopesRoute!; + } + if (properties.namesRoute != null) { + config.namesRoute = properties.namesRoute!; + } + if (properties.liveRegion != null) { + config.liveRegion = properties.liveRegion!; + } + if (properties.maxValueLength != null) { + config.maxValueLength = properties.maxValueLength; + } + if (properties.currentValueLength != null) { + config.currentValueLength = properties.currentValueLength; + } + if (properties.toggled != null) { + config.isToggled = properties.toggled; + } + if (properties.image != null) { + config.isImage = properties.image!; + } + if (properties.label != null) { + config.label = properties.label!; + } + if (properties.value != null) { + config.value = properties.value!; + } + if (properties.increasedValue != null) { + config.increasedValue = properties.increasedValue!; + } + if (properties.decreasedValue != null) { + config.decreasedValue = properties.decreasedValue!; + } + if (properties.hint != null) { + config.hint = properties.hint!; + } + if (properties.textDirection != null) { + config.textDirection = properties.textDirection; + } + if (properties.onTap != null) { + config.onTap = properties.onTap; + } + if (properties.onLongPress != null) { + config.onLongPress = properties.onLongPress; + } + if (properties.onScrollLeft != null) { + config.onScrollLeft = properties.onScrollLeft; + } + if (properties.onScrollRight != null) { + config.onScrollRight = properties.onScrollRight; + } + if (properties.onScrollUp != null) { + config.onScrollUp = properties.onScrollUp; + } + if (properties.onScrollDown != null) { + config.onScrollDown = properties.onScrollDown; + } + if (properties.onIncrease != null) { + config.onIncrease = properties.onIncrease; + } + if (properties.onDecrease != null) { + config.onDecrease = properties.onDecrease; + } + if (properties.onCopy != null) { + config.onCopy = properties.onCopy; + } + if (properties.onCut != null) { + config.onCut = properties.onCut; + } + if (properties.onPaste != null) { + config.onPaste = properties.onPaste; + } + if (properties.onMoveCursorForwardByCharacter != null) { + config.onMoveCursorForwardByCharacter = properties.onMoveCursorForwardByCharacter; + } + if (properties.onMoveCursorBackwardByCharacter != null) { + config.onMoveCursorBackwardByCharacter = properties.onMoveCursorBackwardByCharacter; + } + if (properties.onMoveCursorForwardByWord != null) { + config.onMoveCursorForwardByWord = properties.onMoveCursorForwardByWord; + } + if (properties.onMoveCursorBackwardByWord != null) { + config.onMoveCursorBackwardByWord = properties.onMoveCursorBackwardByWord; + } + if (properties.onSetSelection != null) { + config.onSetSelection = properties.onSetSelection; + } + if (properties.onSetText != null) { + config.onSetText = properties.onSetText; + } + if (properties.onDidGainAccessibilityFocus != null) { + config.onDidGainAccessibilityFocus = properties.onDidGainAccessibilityFocus; + } + if (properties.onDidLoseAccessibilityFocus != null) { + config.onDidLoseAccessibilityFocus = properties.onDidLoseAccessibilityFocus; + } + if (properties.onDismiss != null) { + config.onDismiss = properties.onDismiss; + } + + newChild.updateWith( + config: config, + // As of now CustomPainter does not support multiple tree levels. + childrenInInversePaintOrder: const <SemanticsNode>[], + ); + + newChild + ..rect = newSemantics.rect + ..transform = newSemantics.transform + ..tags = newSemantics.tags; + + return newChild; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(MessageProperty('painter', '$painter')); + properties.add(MessageProperty('foregroundPainter', '$foregroundPainter', level: foregroundPainter != null ? DiagnosticLevel.info : DiagnosticLevel.fine)); + properties.add(DiagnosticsProperty<Size>('preferredSize', preferredSize, defaultValue: Size.zero)); + properties.add(DiagnosticsProperty<bool>('isComplex', isComplex, defaultValue: false)); + properties.add(DiagnosticsProperty<bool>('willChange', willChange, defaultValue: false)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/debug.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/debug.dart new file mode 100644 index 0000000000000000000000000000000000000000..f07293415a4742777582613f56354c313a467a86 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/debug.dart @@ -0,0 +1,398 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'box.dart'; +import 'object.dart'; + +export 'package:flutter/foundation.dart' show debugPrint; + +// Any changes to this file should be reflected in the debugAssertAllRenderVarsUnset() +// function below. + +const HSVColor _kDebugDefaultRepaintColor = HSVColor.fromAHSV(0.4, 60.0, 1.0, 1.0); + +/// Causes each RenderBox to paint a box around its bounds, and some extra +/// boxes, such as [RenderPadding], to draw construction lines. +/// +/// The edges of the boxes are painted as a one-pixel-thick `const Color(0xFF00FFFF)` outline. +/// +/// Spacing is painted as a solid `const Color(0x90909090)` area. +/// +/// Padding is filled in solid `const Color(0x900090FF)`, with the inner edge +/// outlined in `const Color(0xFF0090FF)`, using [debugPaintPadding]. +bool debugPaintSizeEnabled = false; + +/// Causes each RenderBox to paint a line at each of its baselines. +bool debugPaintBaselinesEnabled = false; + +/// Causes each Layer to paint a box around its bounds. +bool debugPaintLayerBordersEnabled = false; + +/// Causes objects like [RenderPointerListener] to flash while they are being +/// tapped. This can be useful to see how large the hit box is, e.g. when +/// debugging buttons that are harder to hit than expected. +/// +/// For details on how to support this in your [RenderBox] subclass, see +/// [RenderBox.debugHandleEvent]. +bool debugPaintPointersEnabled = false; + +/// Overlay a rotating set of colors when repainting layers in debug mode. +/// +/// See also: +/// +/// * [RepaintBoundary], which can be used to contain repaints when unchanged +/// areas are being excessively repainted. +bool debugRepaintRainbowEnabled = false; + +/// Overlay a rotating set of colors when repainting text in debug mode. +bool debugRepaintTextRainbowEnabled = false; + +/// The current color to overlay when repainting a layer. +/// +/// This is used by painting debug code that implements +/// [debugRepaintRainbowEnabled] or [debugRepaintTextRainbowEnabled]. +/// +/// The value is incremented by [RenderView.compositeFrame] if either of those +/// flags is enabled. +HSVColor debugCurrentRepaintColor = _kDebugDefaultRepaintColor; + +/// Log the call stacks that mark render objects as needing layout. +/// +/// For sanity, this only logs the stack traces of cases where an object is +/// added to the list of nodes needing layout. This avoids printing multiple +/// redundant stack traces as a single [RenderObject.markNeedsLayout] call walks +/// up the tree. +bool debugPrintMarkNeedsLayoutStacks = false; + +/// Log the call stacks that mark render objects as needing paint. +bool debugPrintMarkNeedsPaintStacks = false; + +/// Log the dirty render objects that are laid out each frame. +/// +/// Combined with [debugPrintBeginFrameBanner], this allows you to distinguish +/// layouts triggered by the initial mounting of a render tree (e.g. in a call +/// to [runApp]) from the regular layouts triggered by the pipeline. +/// +/// Combined with [debugPrintMarkNeedsLayoutStacks], this lets you watch a +/// render object's dirty/clean lifecycle. +/// +/// See also: +/// +/// * [debugProfileLayoutsEnabled], which does something similar for layout +/// but using the timeline view. +/// * [debugProfilePaintsEnabled], which does something similar for painting +/// but using the timeline view. +/// * [debugPrintRebuildDirtyWidgets], which does something similar for widgets +/// being rebuilt. +/// * The discussion at [RendererBinding.drawFrame]. +bool debugPrintLayouts = false; + +/// Check the intrinsic sizes of each [RenderBox] during layout. +/// +/// By default this is turned off since these checks are expensive. If you are +/// implementing your own children of [RenderBox] with custom intrinsics, turn +/// this on in your unit tests for additional validations. +bool debugCheckIntrinsicSizes = false; + +/// Adds [Timeline] events for every [RenderObject] layout. +/// +/// The timing information this flag exposes is not representative of the actual +/// cost of layout, because the overhead of adding timeline events is +/// significant relative to the time each object takes to lay out. However, it +/// can expose unexpected layout behavior in the timeline. +/// +/// In debug builds, additional information is included in the trace (such as +/// the properties of render objects being laid out). Collecting this data is +/// expensive and further makes these traces non-representative of actual +/// performance. This data is omitted in profile builds. +/// +/// For more information about performance debugging in Flutter, see +/// <https://flutter.dev/docs/perf/rendering>. +/// +/// See also: +/// +/// * [debugPrintLayouts], which does something similar for layout but using +/// console output. +/// * [debugProfileBuildsEnabled], which does something similar for widgets +/// being rebuilt. +/// * [debugProfilePaintsEnabled], which does something similar for painting. +/// * [debugEnhanceLayoutTimelineArguments], which enhances the trace with +/// debugging information related to [RenderObject] layouts. +bool debugProfileLayoutsEnabled = false; + +/// Adds [Timeline] events for every [RenderObject] painted. +/// +/// The timing information this flag exposes is not representative of actual +/// paints, because the overhead of adding timeline events is significant +/// relative to the time each object takes to paint. However, it can expose +/// unexpected painting in the timeline. +/// +/// In debug builds, additional information is included in the trace (such as +/// the properties of render objects being painted). Collecting this data is +/// expensive and further makes these traces non-representative of actual +/// performance. This data is omitted in profile builds. +/// +/// For more information about performance debugging in Flutter, see +/// <https://flutter.dev/docs/perf/rendering>. +/// +/// See also: +/// +/// * [debugProfileBuildsEnabled], which does something similar for widgets +/// being rebuilt, and [debugPrintRebuildDirtyWidgets], its console +/// equivalent. +/// * [debugProfileLayoutsEnabled], which does something similar for layout, +/// and [debugPrintLayouts], its console equivalent. +/// * The discussion at [RendererBinding.drawFrame]. +/// * [RepaintBoundary], which can be used to contain repaints when unchanged +/// areas are being excessively repainted. +/// * [debugEnhancePaintTimelineArguments], which enhances the trace with +/// debugging information related to [RenderObject] paints. +bool debugProfilePaintsEnabled = false; + +/// Adds debugging information to [Timeline] events related to [RenderObject] +/// layouts. +/// +/// This flag will only add [Timeline] event arguments for debug builds. +/// Additional arguments will be added for the "LAYOUT" timeline event and for +/// all [RenderObject] layout [Timeline] events, which are the events that are +/// added when [debugProfileLayoutsEnabled] is true. The debugging information +/// that will be added in trace arguments includes stats around [RenderObject] +/// dirty states and [RenderObject] diagnostic information (i.e. [RenderObject] +/// properties). +/// +/// See also: +/// +/// * [debugProfileLayoutsEnabled], which adds [Timeline] events for every +/// [RenderObject] layout. +/// * [debugEnhancePaintTimelineArguments], which does something similar for +/// events related to [RenderObject] paints. +/// * [debugEnhanceBuildTimelineArguments], which does something similar for +/// events related to [Widget] builds. +bool debugEnhanceLayoutTimelineArguments = false; + +/// Adds debugging information to [Timeline] events related to [RenderObject] +/// paints. +/// +/// This flag will only add [Timeline] event arguments for debug builds. +/// Additional arguments will be added for the "PAINT" timeline event and for +/// all [RenderObject] paint [Timeline] events, which are the [Timeline] events +/// that are added when [debugProfilePaintsEnabled] is true. The debugging +/// information that will be added in trace arguments includes stats around +/// [RenderObject] dirty states and [RenderObject] diagnostic information +/// (i.e. [RenderObject] properties). +/// +/// See also: +/// +/// * [debugProfilePaintsEnabled], which adds [Timeline] events for every +/// [RenderObject] paint. +/// * [debugEnhanceLayoutTimelineArguments], which does something similar for +/// events related to [RenderObject] layouts. +/// * [debugEnhanceBuildTimelineArguments], which does something similar for +/// events related to [Widget] builds. +bool debugEnhancePaintTimelineArguments = false; + +/// Signature for [debugOnProfilePaint] implementations. +typedef ProfilePaintCallback = void Function(RenderObject renderObject); + +/// Callback invoked for every [RenderObject] painted each frame. +/// +/// This callback is only invoked in debug builds. +/// +/// See also: +/// +/// * [debugProfilePaintsEnabled], which does something similar but adds +/// [dart:developer.Timeline] events instead of invoking a callback. +/// * [debugOnRebuildDirtyWidget], which does something similar for widgets +/// being built. +/// * [WidgetInspectorService], which uses the [debugOnProfilePaint] +/// callback to generate aggregate profile statistics describing what paints +/// occurred when the `ext.flutter.inspector.trackRepaintWidgets` service +/// extension is enabled. +ProfilePaintCallback? debugOnProfilePaint; + +/// Setting to true will cause all clipping effects from the layer tree to be +/// ignored. +/// +/// Can be used to debug whether objects being clipped are painting excessively +/// in clipped areas. Can also be used to check whether excessive use of +/// clipping is affecting performance. +/// +/// This will not reduce the number of [Layer] objects created; the compositing +/// strategy is unaffected. It merely causes the clipping layers to be skipped +/// when building the scene. +bool debugDisableClipLayers = false; + +/// Setting to true will cause all physical modeling effects from the layer +/// tree, such as shadows from elevations, to be ignored. +/// +/// Can be used to check whether excessive use of physical models is affecting +/// performance. +/// +/// This will not reduce the number of [Layer] objects created; the compositing +/// strategy is unaffected. It merely causes the physical shape layers to be +/// skipped when building the scene. +bool debugDisablePhysicalShapeLayers = false; + +/// Setting to true will cause all opacity effects from the layer tree to be +/// ignored. +/// +/// An optimization to not paint the child at all when opacity is 0 will still +/// remain. +/// +/// Can be used to check whether excessive use of opacity effects is affecting +/// performance. +/// +/// This will not reduce the number of [Layer] objects created; the compositing +/// strategy is unaffected. It merely causes the opacity layers to be skipped +/// when building the scene. +bool debugDisableOpacityLayers = false; + +void _debugDrawDoubleRect(Canvas canvas, Rect outerRect, Rect innerRect, Color color) { + final Path path = Path() + ..fillType = PathFillType.evenOdd + ..addRect(outerRect) + ..addRect(innerRect); + final Paint paint = Paint() + ..color = color; + canvas.drawPath(path, paint); +} + +/// Paint a diagram showing the given area as padding. +/// +/// The `innerRect` argument represents the position of the child, if any. +/// +/// When `innerRect` is null, the method draws the entire `outerRect` in a +/// grayish color representing _spacing_. +/// +/// When `innerRect` is non-null, the method draws the padding region around the +/// `innerRect` in a tealish color, with a solid outline around the inner +/// region. +/// +/// This method is used by [RenderPadding.debugPaintSize] when +/// [debugPaintSizeEnabled] is true. +void debugPaintPadding(Canvas canvas, Rect outerRect, Rect? innerRect, { double outlineWidth = 2.0 }) { + assert(() { + if (innerRect != null && !innerRect.isEmpty) { + _debugDrawDoubleRect(canvas, outerRect, innerRect, const Color(0x900090FF)); + _debugDrawDoubleRect(canvas, innerRect.inflate(outlineWidth).intersect(outerRect), innerRect, const Color(0xFF0090FF)); + } else { + final Paint paint = Paint() + ..color = const Color(0x90909090); + canvas.drawRect(outerRect, paint); + } + return true; + }()); +} + +/// Returns true if none of the rendering library debug variables have been changed. +/// +/// This function is used by the test framework to ensure that debug variables +/// haven't been inadvertently changed. +/// +/// See [the rendering library](rendering/rendering-library.html) for a complete +/// list. +/// +/// The `debugCheckIntrinsicSizesOverride` argument can be provided to override +/// the expected value for [debugCheckIntrinsicSizes]. (This exists because the +/// test framework itself overrides this value in some cases.) +bool debugAssertAllRenderVarsUnset(String reason, { bool debugCheckIntrinsicSizesOverride = false }) { + assert(() { + if (debugPaintSizeEnabled || + debugPaintBaselinesEnabled || + debugPaintLayerBordersEnabled || + debugPaintPointersEnabled || + debugRepaintRainbowEnabled || + debugRepaintTextRainbowEnabled || + debugCurrentRepaintColor != _kDebugDefaultRepaintColor || + debugPrintMarkNeedsLayoutStacks || + debugPrintMarkNeedsPaintStacks || + debugPrintLayouts || + debugCheckIntrinsicSizes != debugCheckIntrinsicSizesOverride || + debugProfileLayoutsEnabled || + debugProfilePaintsEnabled || + debugOnProfilePaint != null || + debugDisableClipLayers || + debugDisablePhysicalShapeLayers || + debugDisableOpacityLayers) { + throw FlutterError(reason); + } + return true; + }()); + return true; +} + +/// Returns true if the given [Axis] is bounded within the given +/// [BoxConstraints] in both the main and cross axis, throwing an exception +/// otherwise. +/// +/// This is used by viewports during `performLayout` and `computeDryLayout` +/// because bounded constraints are required in order to layout their children. +bool debugCheckHasBoundedAxis(Axis axis, BoxConstraints constraints) { + assert(() { + if (!constraints.hasBoundedHeight || !constraints.hasBoundedWidth) { + switch (axis) { + case Axis.vertical: + if (!constraints.hasBoundedHeight) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Vertical viewport was given unbounded height.'), + ErrorDescription( + 'Viewports expand in the scrolling direction to fill their container. ' + 'In this case, a vertical viewport was given an unlimited amount of ' + 'vertical space in which to expand. This situation typically happens ' + 'when a scrollable widget is nested inside another scrollable widget.', + ), + ErrorHint( + 'If this widget is always nested in a scrollable widget there ' + 'is no need to use a viewport because there will always be enough ' + 'vertical space for the children. In this case, consider using a ' + 'Column or Wrap instead. Otherwise, consider using a ' + 'CustomScrollView to concatenate arbitrary slivers into a ' + 'single scrollable.', + ), + ]); + } + if (!constraints.hasBoundedWidth) { + throw FlutterError( + 'Vertical viewport was given unbounded width.\n' + 'Viewports expand in the cross axis to fill their container and ' + 'constrain their children to match their extent in the cross axis. ' + 'In this case, a vertical viewport was given an unlimited amount of ' + 'horizontal space in which to expand.', + ); + } + case Axis.horizontal: + if (!constraints.hasBoundedWidth) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Horizontal viewport was given unbounded width.'), + ErrorDescription( + 'Viewports expand in the scrolling direction to fill their container. ' + 'In this case, a horizontal viewport was given an unlimited amount of ' + 'horizontal space in which to expand. This situation typically happens ' + 'when a scrollable widget is nested inside another scrollable widget.', + ), + ErrorHint( + 'If this widget is always nested in a scrollable widget there ' + 'is no need to use a viewport because there will always be enough ' + 'horizontal space for the children. In this case, consider using a ' + 'Row or Wrap instead. Otherwise, consider using a ' + 'CustomScrollView to concatenate arbitrary slivers into a ' + 'single scrollable.', + ), + ]); + } + if (!constraints.hasBoundedHeight) { + throw FlutterError( + 'Horizontal viewport was given unbounded height.\n' + 'Viewports expand in the cross axis to fill their container and ' + 'constrain their children to match their extent in the cross axis. ' + 'In this case, a horizontal viewport was given an unlimited amount of ' + 'vertical space in which to expand.', + ); + } + } + } + return true; + }()); + return true; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/debug_overflow_indicator.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/debug_overflow_indicator.dart new file mode 100644 index 0000000000000000000000000000000000000000..c68caa8874d877ec3d691635a514c2a5938051ae --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/debug_overflow_indicator.dart @@ -0,0 +1,326 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; + +import 'object.dart'; +import 'stack.dart'; + +// Describes which side the region data overflows on. +enum _OverflowSide { + left, + top, + bottom, + right, +} + +// Data used by the DebugOverflowIndicator to manage the regions and labels for +// the indicators. +class _OverflowRegionData { + const _OverflowRegionData({ + required this.rect, + this.label = '', + this.labelOffset = Offset.zero, + this.rotation = 0.0, + required this.side, + }); + + final Rect rect; + final String label; + final Offset labelOffset; + final double rotation; + final _OverflowSide side; +} + +/// An mixin indicator that is drawn when a [RenderObject] overflows its +/// container. +/// +/// This is used by some RenderObjects that are containers to show where, and by +/// how much, their children overflow their containers. These indicators are +/// typically only shown in a debug build (where the call to +/// [paintOverflowIndicator] is surrounded by an assert). +/// +/// This class will also print a debug message to the console when the container +/// overflows. It will print on the first occurrence, and once after each time that +/// [reassemble] is called. +/// +/// {@tool snippet} +/// +/// ```dart +/// class MyRenderObject extends RenderAligningShiftedBox with DebugOverflowIndicatorMixin { +/// MyRenderObject({ +/// super.alignment = Alignment.center, +/// required super.textDirection, +/// super.child, +/// }); +/// +/// late Rect _containerRect; +/// late Rect _childRect; +/// +/// @override +/// void performLayout() { +/// // ... +/// final BoxParentData childParentData = child!.parentData! as BoxParentData; +/// _containerRect = Offset.zero & size; +/// _childRect = childParentData.offset & child!.size; +/// } +/// +/// @override +/// void paint(PaintingContext context, Offset offset) { +/// // Do normal painting here... +/// // ... +/// +/// assert(() { +/// paintOverflowIndicator(context, offset, _containerRect, _childRect); +/// return true; +/// }()); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [RenderConstraintsTransformBox] and [RenderFlex] for examples of classes +/// that use this indicator mixin. +mixin DebugOverflowIndicatorMixin on RenderObject { + static const Color _black = Color(0xBF000000); + static const Color _yellow = Color(0xBFFFFF00); + // The fraction of the container that the indicator covers. + static const double _indicatorFraction = 0.1; + static const double _indicatorFontSizePixels = 7.5; + static const double _indicatorLabelPaddingPixels = 1.0; + static const TextStyle _indicatorTextStyle = TextStyle( + color: Color(0xFF900000), + fontSize: _indicatorFontSizePixels, + fontWeight: FontWeight.w800, + ); + static final Paint _indicatorPaint = Paint() + ..shader = ui.Gradient.linear( + Offset.zero, + const Offset(10.0, 10.0), + <Color>[_black, _yellow, _yellow, _black], + <double>[0.25, 0.25, 0.75, 0.75], + TileMode.repeated, + ); + static final Paint _labelBackgroundPaint = Paint()..color = const Color(0xFFFFFFFF); + + final List<TextPainter> _indicatorLabel = List<TextPainter>.filled( + _OverflowSide.values.length, + TextPainter(textDirection: TextDirection.ltr), // This label is in English. + ); + + @override + void dispose() { + for (final TextPainter painter in _indicatorLabel) { + painter.dispose(); + } + super.dispose(); + } + + // Set to true to trigger a debug message in the console upon + // the next paint call. Will be reset after each paint. + bool _overflowReportNeeded = true; + + String _formatPixels(double value) { + assert(value > 0.0); + final String pixels; + if (value > 10.0) { + pixels = value.toStringAsFixed(0); + } else if (value > 1.0) { + pixels = value.toStringAsFixed(1); + } else { + pixels = value.toStringAsPrecision(3); + } + return pixels; + } + + List<_OverflowRegionData> _calculateOverflowRegions(RelativeRect overflow, Rect containerRect) { + final List<_OverflowRegionData> regions = <_OverflowRegionData>[]; + if (overflow.left > 0.0) { + final Rect markerRect = Rect.fromLTWH( + 0.0, + 0.0, + containerRect.width * _indicatorFraction, + containerRect.height, + ); + regions.add(_OverflowRegionData( + rect: markerRect, + label: 'LEFT OVERFLOWED BY ${_formatPixels(overflow.left)} PIXELS', + labelOffset: markerRect.centerLeft + + const Offset(_indicatorFontSizePixels + _indicatorLabelPaddingPixels, 0.0), + rotation: math.pi / 2.0, + side: _OverflowSide.left, + )); + } + if (overflow.right > 0.0) { + final Rect markerRect = Rect.fromLTWH( + containerRect.width * (1.0 - _indicatorFraction), + 0.0, + containerRect.width * _indicatorFraction, + containerRect.height, + ); + regions.add(_OverflowRegionData( + rect: markerRect, + label: 'RIGHT OVERFLOWED BY ${_formatPixels(overflow.right)} PIXELS', + labelOffset: markerRect.centerRight - + const Offset(_indicatorFontSizePixels + _indicatorLabelPaddingPixels, 0.0), + rotation: -math.pi / 2.0, + side: _OverflowSide.right, + )); + } + if (overflow.top > 0.0) { + final Rect markerRect = Rect.fromLTWH( + 0.0, + 0.0, + containerRect.width, + containerRect.height * _indicatorFraction, + ); + regions.add(_OverflowRegionData( + rect: markerRect, + label: 'TOP OVERFLOWED BY ${_formatPixels(overflow.top)} PIXELS', + labelOffset: markerRect.topCenter + const Offset(0.0, _indicatorLabelPaddingPixels), + side: _OverflowSide.top, + )); + } + if (overflow.bottom > 0.0) { + final Rect markerRect = Rect.fromLTWH( + 0.0, + containerRect.height * (1.0 - _indicatorFraction), + containerRect.width, + containerRect.height * _indicatorFraction, + ); + regions.add(_OverflowRegionData( + rect: markerRect, + label: 'BOTTOM OVERFLOWED BY ${_formatPixels(overflow.bottom)} PIXELS', + labelOffset: markerRect.bottomCenter - + const Offset(0.0, _indicatorFontSizePixels + _indicatorLabelPaddingPixels), + side: _OverflowSide.bottom, + )); + } + return regions; + } + + void _reportOverflow(RelativeRect overflow, List<DiagnosticsNode>? overflowHints) { + overflowHints ??= <DiagnosticsNode>[]; + if (overflowHints.isEmpty) { + overflowHints.add(ErrorDescription( + 'The edge of the $runtimeType that is ' + 'overflowing has been marked in the rendering with a yellow and black ' + 'striped pattern. This is usually caused by the contents being too big ' + 'for the $runtimeType.', + )); + overflowHints.add(ErrorHint( + 'This is considered an error condition because it indicates that there ' + 'is content that cannot be seen. If the content is legitimately bigger ' + 'than the available space, consider clipping it with a ClipRect widget ' + 'before putting it in the $runtimeType, or using a scrollable ' + 'container, like a ListView.', + )); + } + + final List<String> overflows = <String>[ + if (overflow.left > 0.0) '${_formatPixels(overflow.left)} pixels on the left', + if (overflow.top > 0.0) '${_formatPixels(overflow.top)} pixels on the top', + if (overflow.bottom > 0.0) '${_formatPixels(overflow.bottom)} pixels on the bottom', + if (overflow.right > 0.0) '${_formatPixels(overflow.right)} pixels on the right', + ]; + String overflowText = ''; + assert(overflows.isNotEmpty, "Somehow $runtimeType didn't actually overflow like it thought it did."); + switch (overflows.length) { + case 1: + overflowText = overflows.first; + case 2: + overflowText = '${overflows.first} and ${overflows.last}'; + default: + overflows[overflows.length - 1] = 'and ${overflows[overflows.length - 1]}'; + overflowText = overflows.join(', '); + } + // TODO(jacobr): add the overflows in pixels as structured data so they can + // be visualized in debugging tools. + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError('A $runtimeType overflowed by $overflowText.'), + library: 'rendering library', + context: ErrorDescription('during layout'), + informationCollector: () => <DiagnosticsNode>[ + // debugCreator should only be set in DebugMode, but we want the + // treeshaker to know that. + if (kDebugMode && debugCreator != null) + DiagnosticsDebugCreator(debugCreator!), + ...overflowHints!, + describeForError('The specific $runtimeType in question is'), + // TODO(jacobr): this line is ascii art that it would be nice to + // handle a little more generically in GUI debugging clients in the + // future. + DiagnosticsNode.message('◢◤' * (FlutterError.wrapWidth ~/ 2), allowWrap: false), + ], + ), + ); + } + + /// To be called when the overflow indicators should be painted. + /// + /// Typically only called if there is an overflow, and only from within a + /// debug build. + /// + /// See example code in [DebugOverflowIndicatorMixin] documentation. + void paintOverflowIndicator( + PaintingContext context, + Offset offset, + Rect containerRect, + Rect childRect, { + List<DiagnosticsNode>? overflowHints, + }) { + final RelativeRect overflow = RelativeRect.fromRect(containerRect, childRect); + + if (overflow.left <= 0.0 && + overflow.right <= 0.0 && + overflow.top <= 0.0 && + overflow.bottom <= 0.0) { + return; + } + + final List<_OverflowRegionData> overflowRegions = _calculateOverflowRegions(overflow, containerRect); + for (final _OverflowRegionData region in overflowRegions) { + context.canvas.drawRect(region.rect.shift(offset), _indicatorPaint); + final TextSpan? textSpan = _indicatorLabel[region.side.index].text as TextSpan?; + if (textSpan?.text != region.label) { + _indicatorLabel[region.side.index].text = TextSpan( + text: region.label, + style: _indicatorTextStyle, + ); + _indicatorLabel[region.side.index].layout(); + } + + final Offset labelOffset = region.labelOffset + offset; + final Offset centerOffset = Offset(-_indicatorLabel[region.side.index].width / 2.0, 0.0); + final Rect textBackgroundRect = centerOffset & _indicatorLabel[region.side.index].size; + context.canvas.save(); + context.canvas.translate(labelOffset.dx, labelOffset.dy); + context.canvas.rotate(region.rotation); + context.canvas.drawRect(textBackgroundRect, _labelBackgroundPaint); + _indicatorLabel[region.side.index].paint(context.canvas, centerOffset); + context.canvas.restore(); + } + + if (_overflowReportNeeded) { + _overflowReportNeeded = false; + _reportOverflow(overflow, overflowHints); + } + } + + @override + void reassemble() { + super.reassemble(); + // Users expect error messages to be shown again after hot reload. + assert(() { + _overflowReportNeeded = true; + return true; + }()); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/decorated_sliver.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/decorated_sliver.dart new file mode 100644 index 0000000000000000000000000000000000000000..68a85f7348ef2607ede1072ef2ee0321651059cf --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/decorated_sliver.dart @@ -0,0 +1,124 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'object.dart'; +import 'proxy_box.dart'; +import 'proxy_sliver.dart'; +import 'sliver.dart'; + +/// Paints a [Decoration] either before or after its child paints. +/// +/// If the child has infinite scroll extent, then the [Decoration] paints itself up to the +/// bottom cache extent. +class RenderDecoratedSliver extends RenderProxySliver { + /// Creates a decorated sliver. + /// + /// The [decoration], [position], and [configuration] arguments must not be + /// null. By default the decoration paints behind the child. + /// + /// The [ImageConfiguration] will be passed to the decoration (with the size + /// filled in) to let it resolve images. + RenderDecoratedSliver({ + required Decoration decoration, + DecorationPosition position = DecorationPosition.background, + ImageConfiguration configuration = ImageConfiguration.empty, + }) : _decoration = decoration, + _position = position, + _configuration = configuration; + + /// What decoration to paint. + /// + /// Commonly a [BoxDecoration]. + Decoration get decoration => _decoration; + Decoration _decoration; + set decoration(Decoration value) { + if (value == decoration) { + return; + } + _decoration = value; + _painter?.dispose(); + _painter = decoration.createBoxPainter(markNeedsPaint); + markNeedsPaint(); + } + + /// Whether to paint the box decoration behind or in front of the child. + DecorationPosition get position => _position; + DecorationPosition _position; + set position(DecorationPosition value) { + if (value == position) { + return; + } + _position = value; + markNeedsPaint(); + } + + /// The settings to pass to the decoration when painting, so that it can + /// resolve images appropriately. See [ImageProvider.resolve] and + /// [BoxPainter.paint]. + /// + /// The [ImageConfiguration.textDirection] field is also used by + /// direction-sensitive [Decoration]s for painting and hit-testing. + ImageConfiguration get configuration => _configuration; + ImageConfiguration _configuration; + set configuration(ImageConfiguration value) { + if (value == configuration) { + return; + } + _configuration = value; + markNeedsPaint(); + } + + BoxPainter? _painter; + + @override + void attach(covariant PipelineOwner owner) { + _painter = decoration.createBoxPainter(markNeedsPaint); + super.attach(owner); + } + + @override + void detach() { + _painter?.dispose(); + _painter = null; + super.detach(); + } + + @override + void dispose() { + _painter?.dispose(); + _painter = null; + super.dispose(); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null && child!.geometry!.visible) { + final SliverPhysicalParentData childParentData = child!.parentData! as SliverPhysicalParentData; + final Size childSize; + final Offset scrollOffset; + + // In the case where the child sliver has infinite scroll extent, the decoration + // should only extend down to the bottom cache extent. + final double cappedMainAxisExtent = child!.geometry!.scrollExtent.isInfinite + ? constraints.scrollOffset + child!.geometry!.cacheExtent + constraints.cacheOrigin + : child!.geometry!.scrollExtent; + switch (constraints.axis) { + case Axis.vertical: + childSize = Size(constraints.crossAxisExtent, cappedMainAxisExtent); + scrollOffset = Offset(0.0, -constraints.scrollOffset); + case Axis.horizontal: + childSize = Size(cappedMainAxisExtent, constraints.crossAxisExtent); + scrollOffset = Offset(-constraints.scrollOffset, 0.0); + } + final Offset childOffset = offset + childParentData.paintOffset; + if (position == DecorationPosition.background) { + _painter!.paint(context.canvas, childOffset + scrollOffset, configuration.copyWith(size: childSize)); + } + context.paintChild(child!, childOffset); + if (position == DecorationPosition.foreground) { + _painter!.paint(context.canvas, childOffset + scrollOffset, configuration.copyWith(size: childSize)); + } + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/editable.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/editable.dart new file mode 100644 index 0000000000000000000000000000000000000000..76a8d6c881b856102d1b55cb24090704a2fe14e8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/editable.dart @@ -0,0 +1,3041 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:math' as math; +import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle, LineMetrics, PlaceholderAlignment, TextBox; + +import 'package:characters/characters.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/semantics.dart'; +import 'package:flutter/services.dart'; + +import 'box.dart'; +import 'custom_paint.dart'; +import 'layer.dart'; +import 'layout_helper.dart'; +import 'object.dart'; +import 'paragraph.dart'; +import 'viewport_offset.dart'; + +const double _kCaretGap = 1.0; // pixels +const double _kCaretHeightOffset = 2.0; // pixels + +// The additional size on the x and y axis with which to expand the prototype +// cursor to render the floating cursor in pixels. +const EdgeInsets _kFloatingCursorSizeIncrease = EdgeInsets.symmetric(horizontal: 0.5, vertical: 1.0); + +// The corner radius of the floating cursor in pixels. +const Radius _kFloatingCursorRadius = Radius.circular(1.0); + +// This constant represents the shortest squared distance required between the floating cursor +// and the regular cursor when both are present in the text field. +// If the squared distance between the two cursors is less than this value, +// it's not necessary to display both cursors at the same time. +// This behavior is consistent with the one observed in iOS UITextField. +const double _kShortestDistanceSquaredWithFloatingAndRegularCursors = 15.0 * 15.0; + +/// Represents the coordinates of the point in a selection, and the text +/// direction at that point, relative to top left of the [RenderEditable] that +/// holds the selection. +@immutable +class TextSelectionPoint { + /// Creates a description of a point in a text selection. + const TextSelectionPoint(this.point, this.direction); + + /// Coordinates of the lower left or lower right corner of the selection, + /// relative to the top left of the [RenderEditable] object. + final Offset point; + + /// Direction of the text at this edge of the selection. + final TextDirection? direction; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is TextSelectionPoint + && other.point == point + && other.direction == direction; + } + + @override + String toString() { + switch (direction) { + case TextDirection.ltr: + return '$point-ltr'; + case TextDirection.rtl: + return '$point-rtl'; + case null: + return '$point'; + } + } + + @override + int get hashCode => Object.hash(point, direction); + +} + +/// The consecutive sequence of [TextPosition]s that the caret should move to +/// when the user navigates the paragraph using the upward arrow key or the +/// downward arrow key. +/// +/// {@template flutter.rendering.RenderEditable.verticalArrowKeyMovement} +/// When the user presses the upward arrow key or the downward arrow key, on +/// many platforms (macOS for instance), the caret will move to the previous +/// line or the next line, while maintaining its original horizontal location. +/// When it encounters a shorter line, the caret moves to the closest horizontal +/// location within that line, and restores the original horizontal location +/// when a long enough line is encountered. +/// +/// Additionally, the caret will move to the beginning of the document if the +/// upward arrow key is pressed and the caret is already on the first line. If +/// the downward arrow key is pressed next, the caret will restore its original +/// horizontal location and move to the second line. Similarly the caret moves +/// to the end of the document if the downward arrow key is pressed when it's +/// already on the last line. +/// +/// Consider a left-aligned paragraph: +/// aa| +/// a +/// aaa +/// where the caret was initially placed at the end of the first line. Pressing +/// the downward arrow key once will move the caret to the end of the second +/// line, and twice the arrow key moves to the third line after the second "a" +/// on that line. Pressing the downward arrow key again, the caret will move to +/// the end of the third line (the end of the document). Pressing the upward +/// arrow key in this state will result in the caret moving to the end of the +/// second line. +/// +/// Vertical caret runs are typically interrupted when the layout of the text +/// changes (including when the text itself changes), or when the selection is +/// changed by other input events or programmatically (for example, when the +/// user pressed the left arrow key). +/// {@endtemplate} +/// +/// The [movePrevious] method moves the caret location (which is +/// [VerticalCaretMovementRun.current]) to the previous line, and in case +/// the caret is already on the first line, the method does nothing and returns +/// false. Similarly the [moveNext] method moves the caret to the next line, and +/// returns false if the caret is already on the last line. +/// +/// The [moveByOffset] method takes a pixel offset from the current position to move +/// the caret up or down. +/// +/// If the underlying paragraph's layout changes, [isValid] becomes false and +/// the [VerticalCaretMovementRun] must not be used. The [isValid] property must +/// be checked before calling [movePrevious], [moveNext] and [moveByOffset], +/// or accessing [current]. +class VerticalCaretMovementRun implements Iterator<TextPosition> { + VerticalCaretMovementRun._( + this._editable, + this._lineMetrics, + this._currentTextPosition, + this._currentLine, + this._currentOffset, + ); + + Offset _currentOffset; + int _currentLine; + TextPosition _currentTextPosition; + + final List<ui.LineMetrics> _lineMetrics; + final RenderEditable _editable; + + bool _isValid = true; + /// Whether this [VerticalCaretMovementRun] can still continue. + /// + /// A [VerticalCaretMovementRun] run is valid if the underlying text layout + /// hasn't changed. + /// + /// The [current] value and the [movePrevious], [moveNext] and [moveByOffset] + /// methods must not be accessed when [isValid] is false. + bool get isValid { + if (!_isValid) { + return false; + } + final List<ui.LineMetrics> newLineMetrics = _editable._textPainter.computeLineMetrics(); + // Use the implementation detail of the computeLineMetrics method to figure + // out if the current text layout has been invalidated. + if (!identical(newLineMetrics, _lineMetrics)) { + _isValid = false; + } + return _isValid; + } + + final Map<int, MapEntry<Offset, TextPosition>> _positionCache = <int, MapEntry<Offset, TextPosition>>{}; + + MapEntry<Offset, TextPosition> _getTextPositionForLine(int lineNumber) { + assert(isValid); + assert(lineNumber >= 0); + final MapEntry<Offset, TextPosition>? cachedPosition = _positionCache[lineNumber]; + if (cachedPosition != null) { + return cachedPosition; + } + assert(lineNumber != _currentLine); + + final Offset newOffset = Offset(_currentOffset.dx, _lineMetrics[lineNumber].baseline); + final TextPosition closestPosition = _editable._textPainter.getPositionForOffset(newOffset); + final MapEntry<Offset, TextPosition> position = MapEntry<Offset, TextPosition>(newOffset, closestPosition); + _positionCache[lineNumber] = position; + return position; + } + + @override + TextPosition get current { + assert(isValid); + return _currentTextPosition; + } + + @override + bool moveNext() { + assert(isValid); + if (_currentLine + 1 >= _lineMetrics.length) { + return false; + } + final MapEntry<Offset, TextPosition> position = _getTextPositionForLine(_currentLine + 1); + _currentLine += 1; + _currentOffset = position.key; + _currentTextPosition = position.value; + return true; + } + + /// Move back to the previous element. + /// + /// Returns true and updates [current] if successful. + bool movePrevious() { + assert(isValid); + if (_currentLine <= 0) { + return false; + } + final MapEntry<Offset, TextPosition> position = _getTextPositionForLine(_currentLine - 1); + _currentLine -= 1; + _currentOffset = position.key; + _currentTextPosition = position.value; + return true; + } + + /// Move forward or backward by a number of elements determined + /// by pixel [offset]. + /// + /// If [offset] is negative, move backward; otherwise move forward. + /// + /// Returns true and updates [current] if successful. + bool moveByOffset(double offset) { + final Offset initialOffset = _currentOffset; + if (offset >= 0.0) { + while (_currentOffset.dy < initialOffset.dy + offset) { + if (!moveNext()) { + break; + } + } + } else { + while (_currentOffset.dy > initialOffset.dy + offset) { + if (!movePrevious()) { + break; + } + } + } + return initialOffset != _currentOffset; + } +} + +/// Displays some text in a scrollable container with a potentially blinking +/// cursor and with gesture recognizers. +/// +/// This is the renderer for an editable text field. It does not directly +/// provide affordances for editing the text, but it does handle text selection +/// and manipulation of the text cursor. +/// +/// The [text] is displayed, scrolled by the given [offset], aligned according +/// to [textAlign]. The [maxLines] property controls whether the text displays +/// on one line or many. The [selection], if it is not collapsed, is painted in +/// the [selectionColor]. If it _is_ collapsed, then it represents the cursor +/// position. The cursor is shown while [showCursor] is true. It is painted in +/// the [cursorColor]. +/// +/// Keyboard handling, IME handling, scrolling, toggling the [showCursor] value +/// to actually blink the cursor, and other features not mentioned above are the +/// responsibility of higher layers and not handled by this object. +class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, ContainerRenderObjectMixin<RenderBox, TextParentData>, RenderInlineChildrenContainerDefaults implements TextLayoutMetrics { + /// Creates a render object that implements the visual aspects of a text field. + /// + /// The [textAlign] argument defaults to [TextAlign.start]. + /// + /// If [showCursor] is not specified, then it defaults to hiding the cursor. + /// + /// The [maxLines] property can be set to null to remove the restriction on + /// the number of lines. By default, it is 1, meaning this is a single-line + /// text field. If it is not null, it must be greater than zero. + /// + /// Use [ViewportOffset.zero] for the [offset] if there is no need for + /// scrolling. + RenderEditable({ + InlineSpan? text, + required TextDirection textDirection, + TextAlign textAlign = TextAlign.start, + Color? cursorColor, + Color? backgroundCursorColor, + ValueNotifier<bool>? showCursor, + bool? hasFocus, + required LayerLink startHandleLayerLink, + required LayerLink endHandleLayerLink, + int? maxLines = 1, + int? minLines, + bool expands = false, + StrutStyle? strutStyle, + Color? selectionColor, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double textScaleFactor = 1.0, + TextScaler textScaler = TextScaler.noScaling, + TextSelection? selection, + required ViewportOffset offset, + this.ignorePointer = false, + bool readOnly = false, + bool forceLine = true, + TextHeightBehavior? textHeightBehavior, + TextWidthBasis textWidthBasis = TextWidthBasis.parent, + String obscuringCharacter = '•', + bool obscureText = false, + Locale? locale, + double cursorWidth = 1.0, + double? cursorHeight, + Radius? cursorRadius, + bool paintCursorAboveText = false, + Offset cursorOffset = Offset.zero, + double devicePixelRatio = 1.0, + ui.BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight, + ui.BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight, + bool? enableInteractiveSelection, + this.floatingCursorAddedMargin = const EdgeInsets.fromLTRB(4, 4, 4, 5), + TextRange? promptRectRange, + Color? promptRectColor, + Clip clipBehavior = Clip.hardEdge, + required this.textSelectionDelegate, + RenderEditablePainter? painter, + RenderEditablePainter? foregroundPainter, + List<RenderBox>? children, + }) : assert(maxLines == null || maxLines > 0), + assert(minLines == null || minLines > 0), + assert( + (maxLines == null) || (minLines == null) || (maxLines >= minLines), + "minLines can't be greater than maxLines", + ), + assert( + !expands || (maxLines == null && minLines == null), + 'minLines and maxLines must be null when expands is true.', + ), + assert( + identical(textScaler, TextScaler.noScaling) || textScaleFactor == 1.0, + 'textScaleFactor is deprecated and cannot be specified when textScaler is specified.', + ), + assert(obscuringCharacter.characters.length == 1), + assert(cursorWidth >= 0.0), + assert(cursorHeight == null || cursorHeight >= 0.0), + _textPainter = TextPainter( + text: text, + textAlign: textAlign, + textDirection: textDirection, + textScaler: textScaler == TextScaler.noScaling ? TextScaler.linear(textScaleFactor) : textScaler, + locale: locale, + maxLines: maxLines == 1 ? 1 : null, + strutStyle: strutStyle, + textHeightBehavior: textHeightBehavior, + textWidthBasis: textWidthBasis, + ), + _showCursor = showCursor ?? ValueNotifier<bool>(false), + _maxLines = maxLines, + _minLines = minLines, + _expands = expands, + _selection = selection, + _offset = offset, + _cursorWidth = cursorWidth, + _cursorHeight = cursorHeight, + _paintCursorOnTop = paintCursorAboveText, + _enableInteractiveSelection = enableInteractiveSelection, + _devicePixelRatio = devicePixelRatio, + _startHandleLayerLink = startHandleLayerLink, + _endHandleLayerLink = endHandleLayerLink, + _obscuringCharacter = obscuringCharacter, + _obscureText = obscureText, + _readOnly = readOnly, + _forceLine = forceLine, + _clipBehavior = clipBehavior, + _hasFocus = hasFocus ?? false, + _disposeShowCursor = showCursor == null { + assert(!_showCursor.value || cursorColor != null); + + _selectionPainter.highlightColor = selectionColor; + _selectionPainter.highlightedRange = selection; + _selectionPainter.selectionHeightStyle = selectionHeightStyle; + _selectionPainter.selectionWidthStyle = selectionWidthStyle; + + _autocorrectHighlightPainter.highlightColor = promptRectColor; + _autocorrectHighlightPainter.highlightedRange = promptRectRange; + + _caretPainter.caretColor = cursorColor; + _caretPainter.cursorRadius = cursorRadius; + _caretPainter.cursorOffset = cursorOffset; + _caretPainter.backgroundCursorColor = backgroundCursorColor; + + _updateForegroundPainter(foregroundPainter); + _updatePainter(painter); + addAll(children); + } + + /// Child render objects + _RenderEditableCustomPaint? _foregroundRenderObject; + _RenderEditableCustomPaint? _backgroundRenderObject; + + @override + void dispose() { + _leaderLayerHandler.layer = null; + _foregroundRenderObject?.dispose(); + _foregroundRenderObject = null; + _backgroundRenderObject?.dispose(); + _backgroundRenderObject = null; + _clipRectLayer.layer = null; + _cachedBuiltInForegroundPainters?.dispose(); + _cachedBuiltInPainters?.dispose(); + _selectionStartInViewport.dispose(); + _selectionEndInViewport.dispose(); + _autocorrectHighlightPainter.dispose(); + _selectionPainter.dispose(); + _caretPainter.dispose(); + _textPainter.dispose(); + if (_disposeShowCursor) { + _showCursor.dispose(); + _disposeShowCursor = false; + } + super.dispose(); + } + + void _updateForegroundPainter(RenderEditablePainter? newPainter) { + final _CompositeRenderEditablePainter effectivePainter = newPainter == null + ? _builtInForegroundPainters + : _CompositeRenderEditablePainter(painters: <RenderEditablePainter>[ + _builtInForegroundPainters, + newPainter, + ]); + + if (_foregroundRenderObject == null) { + final _RenderEditableCustomPaint foregroundRenderObject = _RenderEditableCustomPaint(painter: effectivePainter); + adoptChild(foregroundRenderObject); + _foregroundRenderObject = foregroundRenderObject; + } else { + _foregroundRenderObject?.painter = effectivePainter; + } + _foregroundPainter = newPainter; + } + + /// The [RenderEditablePainter] to use for painting above this + /// [RenderEditable]'s text content. + /// + /// The new [RenderEditablePainter] will replace the previously specified + /// foreground painter, and schedule a repaint if the new painter's + /// `shouldRepaint` method returns true. + RenderEditablePainter? get foregroundPainter => _foregroundPainter; + RenderEditablePainter? _foregroundPainter; + set foregroundPainter(RenderEditablePainter? newPainter) { + if (newPainter == _foregroundPainter) { + return; + } + _updateForegroundPainter(newPainter); + } + + void _updatePainter(RenderEditablePainter? newPainter) { + final _CompositeRenderEditablePainter effectivePainter = newPainter == null + ? _builtInPainters + : _CompositeRenderEditablePainter(painters: <RenderEditablePainter>[_builtInPainters, newPainter]); + + if (_backgroundRenderObject == null) { + final _RenderEditableCustomPaint backgroundRenderObject = _RenderEditableCustomPaint(painter: effectivePainter); + adoptChild(backgroundRenderObject); + _backgroundRenderObject = backgroundRenderObject; + } else { + _backgroundRenderObject?.painter = effectivePainter; + } + _painter = newPainter; + } + + /// Sets the [RenderEditablePainter] to use for painting beneath this + /// [RenderEditable]'s text content. + /// + /// The new [RenderEditablePainter] will replace the previously specified + /// painter, and schedule a repaint if the new painter's `shouldRepaint` + /// method returns true. + RenderEditablePainter? get painter => _painter; + RenderEditablePainter? _painter; + set painter(RenderEditablePainter? newPainter) { + if (newPainter == _painter) { + return; + } + _updatePainter(newPainter); + } + + // Caret Painters: + // A single painter for both the regular caret and the floating cursor. + late final _CaretPainter _caretPainter = _CaretPainter(); + + // Text Highlight painters: + final _TextHighlightPainter _selectionPainter = _TextHighlightPainter(); + final _TextHighlightPainter _autocorrectHighlightPainter = _TextHighlightPainter(); + + _CompositeRenderEditablePainter get _builtInForegroundPainters => _cachedBuiltInForegroundPainters ??= _createBuiltInForegroundPainters(); + _CompositeRenderEditablePainter? _cachedBuiltInForegroundPainters; + _CompositeRenderEditablePainter _createBuiltInForegroundPainters() { + return _CompositeRenderEditablePainter( + painters: <RenderEditablePainter>[ + if (paintCursorAboveText) _caretPainter, + ], + ); + } + + _CompositeRenderEditablePainter get _builtInPainters => _cachedBuiltInPainters ??= _createBuiltInPainters(); + _CompositeRenderEditablePainter? _cachedBuiltInPainters; + _CompositeRenderEditablePainter _createBuiltInPainters() { + return _CompositeRenderEditablePainter( + painters: <RenderEditablePainter>[ + _autocorrectHighlightPainter, + _selectionPainter, + if (!paintCursorAboveText) _caretPainter, + ], + ); + } + + double? _textLayoutLastMaxWidth; + double? _textLayoutLastMinWidth; + + /// Assert that the last layout still matches the constraints. + void debugAssertLayoutUpToDate() { + assert( + _textLayoutLastMaxWidth == constraints.maxWidth && + _textLayoutLastMinWidth == constraints.minWidth, + 'Last width ($_textLayoutLastMinWidth, $_textLayoutLastMaxWidth) not the same as max width constraint (${constraints.minWidth}, ${constraints.maxWidth}).', + ); + } + + /// Whether the [handleEvent] will propagate pointer events to selection + /// handlers. + /// + /// If this property is true, the [handleEvent] assumes that this renderer + /// will be notified of input gestures via [handleTapDown], [handleTap], + /// [handleDoubleTap], and [handleLongPress]. + /// + /// If there are any gesture recognizers in the text span, the [handleEvent] + /// will still propagate pointer events to those recognizers. + /// + /// The default value of this property is false. + bool ignorePointer; + + /// {@macro dart.ui.textHeightBehavior} + TextHeightBehavior? get textHeightBehavior => _textPainter.textHeightBehavior; + set textHeightBehavior(TextHeightBehavior? value) { + if (_textPainter.textHeightBehavior == value) { + return; + } + _textPainter.textHeightBehavior = value; + markNeedsTextLayout(); + } + + /// {@macro flutter.painting.textPainter.textWidthBasis} + TextWidthBasis get textWidthBasis => _textPainter.textWidthBasis; + set textWidthBasis(TextWidthBasis value) { + if (_textPainter.textWidthBasis == value) { + return; + } + _textPainter.textWidthBasis = value; + markNeedsTextLayout(); + } + + /// The pixel ratio of the current device. + /// + /// Should be obtained by querying MediaQuery for the devicePixelRatio. + double get devicePixelRatio => _devicePixelRatio; + double _devicePixelRatio; + set devicePixelRatio(double value) { + if (devicePixelRatio == value) { + return; + } + _devicePixelRatio = value; + markNeedsTextLayout(); + } + + /// Character used for obscuring text if [obscureText] is true. + /// + /// Must have a length of exactly one. + String get obscuringCharacter => _obscuringCharacter; + String _obscuringCharacter; + set obscuringCharacter(String value) { + if (_obscuringCharacter == value) { + return; + } + assert(value.characters.length == 1); + _obscuringCharacter = value; + markNeedsLayout(); + } + + /// Whether to hide the text being edited (e.g., for passwords). + bool get obscureText => _obscureText; + bool _obscureText; + set obscureText(bool value) { + if (_obscureText == value) { + return; + } + _obscureText = value; + _cachedAttributedValue = null; + markNeedsSemanticsUpdate(); + } + + /// Controls how tall the selection highlight boxes are computed to be. + /// + /// See [ui.BoxHeightStyle] for details on available styles. + ui.BoxHeightStyle get selectionHeightStyle => _selectionPainter.selectionHeightStyle; + set selectionHeightStyle(ui.BoxHeightStyle value) { + _selectionPainter.selectionHeightStyle = value; + } + + /// Controls how wide the selection highlight boxes are computed to be. + /// + /// See [ui.BoxWidthStyle] for details on available styles. + ui.BoxWidthStyle get selectionWidthStyle => _selectionPainter.selectionWidthStyle; + set selectionWidthStyle(ui.BoxWidthStyle value) { + _selectionPainter.selectionWidthStyle = value; + } + + /// The object that controls the text selection, used by this render object + /// for implementing cut, copy, and paste keyboard shortcuts. + /// + /// It will make cut, copy and paste functionality work with the most recently + /// set [TextSelectionDelegate]. + TextSelectionDelegate textSelectionDelegate; + + /// Track whether position of the start of the selected text is within the viewport. + /// + /// For example, if the text contains "Hello World", and the user selects + /// "Hello", then scrolls so only "World" is visible, this will become false. + /// If the user scrolls back so that the "H" is visible again, this will + /// become true. + /// + /// This bool indicates whether the text is scrolled so that the handle is + /// inside the text field viewport, as opposed to whether it is actually + /// visible on the screen. + ValueListenable<bool> get selectionStartInViewport => _selectionStartInViewport; + final ValueNotifier<bool> _selectionStartInViewport = ValueNotifier<bool>(true); + + /// Track whether position of the end of the selected text is within the viewport. + /// + /// For example, if the text contains "Hello World", and the user selects + /// "World", then scrolls so only "Hello" is visible, this will become + /// 'false'. If the user scrolls back so that the "d" is visible again, this + /// will become 'true'. + /// + /// This bool indicates whether the text is scrolled so that the handle is + /// inside the text field viewport, as opposed to whether it is actually + /// visible on the screen. + ValueListenable<bool> get selectionEndInViewport => _selectionEndInViewport; + final ValueNotifier<bool> _selectionEndInViewport = ValueNotifier<bool>(true); + + /// Returns the TextPosition above or below the given offset. + TextPosition _getTextPositionVertical(TextPosition position, double verticalOffset) { + final Offset caretOffset = _textPainter.getOffsetForCaret(position, _caretPrototype); + final Offset caretOffsetTranslated = caretOffset.translate(0.0, verticalOffset); + return _textPainter.getPositionForOffset(caretOffsetTranslated); + } + + // Start TextLayoutMetrics. + + /// {@macro flutter.services.TextLayoutMetrics.getLineAtOffset} + @override + TextSelection getLineAtOffset(TextPosition position) { + debugAssertLayoutUpToDate(); + final TextRange line = _textPainter.getLineBoundary(position); + // If text is obscured, the entire string should be treated as one line. + if (obscureText) { + return TextSelection(baseOffset: 0, extentOffset: plainText.length); + } + return TextSelection(baseOffset: line.start, extentOffset: line.end); + } + + /// {@macro flutter.painting.TextPainter.getWordBoundary} + @override + TextRange getWordBoundary(TextPosition position) { + return _textPainter.getWordBoundary(position); + } + + /// {@macro flutter.services.TextLayoutMetrics.getTextPositionAbove} + @override + TextPosition getTextPositionAbove(TextPosition position) { + // The caret offset gives a location in the upper left hand corner of + // the caret so the middle of the line above is a half line above that + // point and the line below is 1.5 lines below that point. + final double preferredLineHeight = _textPainter.preferredLineHeight; + final double verticalOffset = -0.5 * preferredLineHeight; + return _getTextPositionVertical(position, verticalOffset); + } + + /// {@macro flutter.services.TextLayoutMetrics.getTextPositionBelow} + @override + TextPosition getTextPositionBelow(TextPosition position) { + // The caret offset gives a location in the upper left hand corner of + // the caret so the middle of the line above is a half line above that + // point and the line below is 1.5 lines below that point. + final double preferredLineHeight = _textPainter.preferredLineHeight; + final double verticalOffset = 1.5 * preferredLineHeight; + return _getTextPositionVertical(position, verticalOffset); + } + + // End TextLayoutMetrics. + + void _updateSelectionExtentsVisibility(Offset effectiveOffset) { + assert(selection != null); + if (!selection!.isValid) { + _selectionStartInViewport.value = false; + _selectionEndInViewport.value = false; + return; + } + final Rect visibleRegion = Offset.zero & size; + + final Offset startOffset = _textPainter.getOffsetForCaret( + TextPosition(offset: selection!.start, affinity: selection!.affinity), + _caretPrototype, + ); + // Check if the selection is visible with an approximation because a + // difference between rounded and unrounded values causes the caret to be + // reported as having a slightly (< 0.5) negative y offset. This rounding + // happens in paragraph.cc's layout and TextPainter's + // _applyFloatingPointHack. Ideally, the rounding mismatch will be fixed and + // this can be changed to be a strict check instead of an approximation. + const double visibleRegionSlop = 0.5; + _selectionStartInViewport.value = visibleRegion + .inflate(visibleRegionSlop) + .contains(startOffset + effectiveOffset); + + final Offset endOffset = _textPainter.getOffsetForCaret( + TextPosition(offset: selection!.end, affinity: selection!.affinity), + _caretPrototype, + ); + _selectionEndInViewport.value = visibleRegion + .inflate(visibleRegionSlop) + .contains(endOffset + effectiveOffset); + } + + void _setTextEditingValue(TextEditingValue newValue, SelectionChangedCause cause) { + textSelectionDelegate.userUpdateTextEditingValue(newValue, cause); + } + + void _setSelection(TextSelection nextSelection, SelectionChangedCause cause) { + if (nextSelection.isValid) { + // The nextSelection is calculated based on plainText, which can be out + // of sync with the textSelectionDelegate.textEditingValue by one frame. + // This is due to the render editable and editable text handle pointer + // event separately. If the editable text changes the text during the + // event handler, the render editable will use the outdated text stored in + // the plainText when handling the pointer event. + // + // If this happens, we need to make sure the new selection is still valid. + final int textLength = textSelectionDelegate.textEditingValue.text.length; + nextSelection = nextSelection.copyWith( + baseOffset: math.min(nextSelection.baseOffset, textLength), + extentOffset: math.min(nextSelection.extentOffset, textLength), + ); + } + _setTextEditingValue( + textSelectionDelegate.textEditingValue.copyWith(selection: nextSelection), + cause, + ); + } + + @override + void markNeedsPaint() { + super.markNeedsPaint(); + // Tell the painters to repaint since text layout may have changed. + _foregroundRenderObject?.markNeedsPaint(); + _backgroundRenderObject?.markNeedsPaint(); + } + + /// Marks the render object as needing to be laid out again and have its text + /// metrics recomputed. + /// + /// Implies [markNeedsLayout]. + @protected + void markNeedsTextLayout() { + _textLayoutLastMaxWidth = null; + _textLayoutLastMinWidth = null; + markNeedsLayout(); + } + + @override + void systemFontsDidChange() { + super.systemFontsDidChange(); + _textPainter.markNeedsLayout(); + _textLayoutLastMaxWidth = null; + _textLayoutLastMinWidth = null; + } + + /// Returns a plain text version of the text in [TextPainter]. + /// + /// If [obscureText] is true, returns the obscured text. See + /// [obscureText] and [obscuringCharacter]. + /// In order to get the styled text as an [InlineSpan] tree, use [text]. + String get plainText => _textPainter.plainText; + + /// The text to paint in the form of a tree of [InlineSpan]s. + /// + /// In order to get the plain text representation, use [plainText]. + InlineSpan? get text => _textPainter.text; + final TextPainter _textPainter; + AttributedString? _cachedAttributedValue; + List<InlineSpanSemanticsInformation>? _cachedCombinedSemanticsInfos; + set text(InlineSpan? value) { + if (_textPainter.text == value) { + return; + } + _cachedLineBreakCount = null; + _textPainter.text = value; + _cachedAttributedValue = null; + _cachedCombinedSemanticsInfos = null; + _canComputeIntrinsicsCached = null; + markNeedsTextLayout(); + markNeedsSemanticsUpdate(); + } + + /// How the text should be aligned horizontally. + TextAlign get textAlign => _textPainter.textAlign; + set textAlign(TextAlign value) { + if (_textPainter.textAlign == value) { + return; + } + _textPainter.textAlign = value; + markNeedsTextLayout(); + } + + /// The directionality of the text. + /// + /// This decides how the [TextAlign.start], [TextAlign.end], and + /// [TextAlign.justify] values of [textAlign] are interpreted. + /// + /// This is also used to disambiguate how to render bidirectional text. For + /// example, if the [text] is an English phrase followed by a Hebrew phrase, + /// in a [TextDirection.ltr] context the English phrase will be on the left + /// and the Hebrew phrase to its right, while in a [TextDirection.rtl] + /// context, the English phrase will be on the right and the Hebrew phrase on + /// its left. + // TextPainter.textDirection is nullable, but it is set to a + // non-null value in the RenderEditable constructor and we refuse to + // set it to null here, so _textPainter.textDirection cannot be null. + TextDirection get textDirection => _textPainter.textDirection!; + set textDirection(TextDirection value) { + if (_textPainter.textDirection == value) { + return; + } + _textPainter.textDirection = value; + markNeedsTextLayout(); + markNeedsSemanticsUpdate(); + } + + /// Used by this renderer's internal [TextPainter] to select a locale-specific + /// font. + /// + /// In some cases the same Unicode character may be rendered differently depending + /// on the locale. For example the '骨' character is rendered differently in + /// the Chinese and Japanese locales. In these cases the [locale] may be used + /// to select a locale-specific font. + /// + /// If this value is null, a system-dependent algorithm is used to select + /// the font. + Locale? get locale => _textPainter.locale; + set locale(Locale? value) { + if (_textPainter.locale == value) { + return; + } + _textPainter.locale = value; + markNeedsTextLayout(); + } + + /// The [StrutStyle] used by the renderer's internal [TextPainter] to + /// determine the strut to use. + StrutStyle? get strutStyle => _textPainter.strutStyle; + set strutStyle(StrutStyle? value) { + if (_textPainter.strutStyle == value) { + return; + } + _textPainter.strutStyle = value; + markNeedsTextLayout(); + } + + /// The color to use when painting the cursor. + Color? get cursorColor => _caretPainter.caretColor; + set cursorColor(Color? value) { + _caretPainter.caretColor = value; + } + + /// The color to use when painting the cursor aligned to the text while + /// rendering the floating cursor. + /// + /// Typically this would be set to [CupertinoColors.inactiveGray]. + /// + /// If this is null, the background cursor is not painted. + Color? get backgroundCursorColor => _caretPainter.backgroundCursorColor; + set backgroundCursorColor(Color? value) { + _caretPainter.backgroundCursorColor = value; + } + + bool _disposeShowCursor; + + /// Whether to paint the cursor. + ValueNotifier<bool> get showCursor => _showCursor; + ValueNotifier<bool> _showCursor; + set showCursor(ValueNotifier<bool> value) { + if (_showCursor == value) { + return; + } + if (attached) { + _showCursor.removeListener(_showHideCursor); + } + if (_disposeShowCursor) { + _showCursor.dispose(); + _disposeShowCursor = false; + } + _showCursor = value; + if (attached) { + _showHideCursor(); + _showCursor.addListener(_showHideCursor); + } + } + + void _showHideCursor() { + _caretPainter.shouldPaint = showCursor.value; + } + + /// Whether the editable is currently focused. + bool get hasFocus => _hasFocus; + bool _hasFocus = false; + set hasFocus(bool value) { + if (_hasFocus == value) { + return; + } + _hasFocus = value; + markNeedsSemanticsUpdate(); + } + + /// Whether this rendering object will take a full line regardless the text width. + bool get forceLine => _forceLine; + bool _forceLine = false; + set forceLine(bool value) { + if (_forceLine == value) { + return; + } + _forceLine = value; + markNeedsLayout(); + } + + /// Whether this rendering object is read only. + bool get readOnly => _readOnly; + bool _readOnly = false; + set readOnly(bool value) { + if (_readOnly == value) { + return; + } + _readOnly = value; + markNeedsSemanticsUpdate(); + } + + /// The maximum number of lines for the text to span, wrapping if necessary. + /// + /// If this is 1 (the default), the text will not wrap, but will extend + /// indefinitely instead. + /// + /// If this is null, there is no limit to the number of lines. + /// + /// When this is not null, the intrinsic height of the render object is the + /// height of one line of text multiplied by this value. In other words, this + /// also controls the height of the actual editing widget. + int? get maxLines => _maxLines; + int? _maxLines; + /// The value may be null. If it is not null, then it must be greater than zero. + set maxLines(int? value) { + assert(value == null || value > 0); + if (maxLines == value) { + return; + } + _maxLines = value; + + // Special case maxLines == 1 to keep only the first line so we can get the + // height of the first line in case there are hard line breaks in the text. + // See the `_preferredHeight` method. + _textPainter.maxLines = value == 1 ? 1 : null; + markNeedsTextLayout(); + } + + /// {@macro flutter.widgets.editableText.minLines} + int? get minLines => _minLines; + int? _minLines; + /// The value may be null. If it is not null, then it must be greater than zero. + set minLines(int? value) { + assert(value == null || value > 0); + if (minLines == value) { + return; + } + _minLines = value; + markNeedsTextLayout(); + } + + /// {@macro flutter.widgets.editableText.expands} + bool get expands => _expands; + bool _expands; + set expands(bool value) { + if (expands == value) { + return; + } + _expands = value; + markNeedsTextLayout(); + } + + /// The color to use when painting the selection. + Color? get selectionColor => _selectionPainter.highlightColor; + set selectionColor(Color? value) { + _selectionPainter.highlightColor = value; + } + + /// Deprecated. Will be removed in a future version of Flutter. Use + /// [textScaler] instead. + /// + /// The number of font pixels for each logical pixel. + /// + /// For example, if the text scale factor is 1.5, text will be 50% larger than + /// the specified font size. + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double get textScaleFactor => _textPainter.textScaleFactor; + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + set textScaleFactor(double value) { + textScaler = TextScaler.linear(value); + } + + /// {@macro flutter.painting.textPainter.textScaler} + TextScaler get textScaler => _textPainter.textScaler; + set textScaler(TextScaler value) { + if (_textPainter.textScaler == value) { + return; + } + _textPainter.textScaler = value; + markNeedsTextLayout(); + } + + /// The region of text that is selected, if any. + /// + /// The caret position is represented by a collapsed selection. + /// + /// If [selection] is null, there is no selection and attempts to + /// manipulate the selection will throw. + TextSelection? get selection => _selection; + TextSelection? _selection; + set selection(TextSelection? value) { + if (_selection == value) { + return; + } + _selection = value; + _selectionPainter.highlightedRange = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// The offset at which the text should be painted. + /// + /// If the text content is larger than the editable line itself, the editable + /// line clips the text. This property controls which part of the text is + /// visible by shifting the text by the given offset before clipping. + ViewportOffset get offset => _offset; + ViewportOffset _offset; + set offset(ViewportOffset value) { + if (_offset == value) { + return; + } + if (attached) { + _offset.removeListener(markNeedsPaint); + } + _offset = value; + if (attached) { + _offset.addListener(markNeedsPaint); + } + markNeedsLayout(); + } + + /// How thick the cursor will be. + double get cursorWidth => _cursorWidth; + double _cursorWidth = 1.0; + set cursorWidth(double value) { + if (_cursorWidth == value) { + return; + } + _cursorWidth = value; + markNeedsLayout(); + } + + /// How tall the cursor will be. + /// + /// This can be null, in which case the getter will actually return [preferredLineHeight]. + /// + /// Setting this to itself fixes the value to the current [preferredLineHeight]. Setting + /// this to null returns the behavior of deferring to [preferredLineHeight]. + // TODO(ianh): This is a confusing API. We should have a separate getter for the effective cursor height. + double get cursorHeight => _cursorHeight ?? preferredLineHeight; + double? _cursorHeight; + set cursorHeight(double? value) { + if (_cursorHeight == value) { + return; + } + _cursorHeight = value; + markNeedsLayout(); + } + + /// {@template flutter.rendering.RenderEditable.paintCursorAboveText} + /// If the cursor should be painted on top of the text or underneath it. + /// + /// By default, the cursor should be painted on top for iOS platforms and + /// underneath for Android platforms. + /// {@endtemplate} + bool get paintCursorAboveText => _paintCursorOnTop; + bool _paintCursorOnTop; + set paintCursorAboveText(bool value) { + if (_paintCursorOnTop == value) { + return; + } + _paintCursorOnTop = value; + // Clear cached built-in painters and reconfigure painters. + _cachedBuiltInForegroundPainters = null; + _cachedBuiltInPainters = null; + // Call update methods to rebuild and set the effective painters. + _updateForegroundPainter(_foregroundPainter); + _updatePainter(_painter); + } + + /// {@template flutter.rendering.RenderEditable.cursorOffset} + /// The offset that is used, in pixels, when painting the cursor on screen. + /// + /// By default, the cursor position should be set to an offset of + /// (-[cursorWidth] * 0.5, 0.0) on iOS platforms and (0, 0) on Android + /// platforms. The origin from where the offset is applied to is the arbitrary + /// location where the cursor ends up being rendered from by default. + /// {@endtemplate} + Offset get cursorOffset => _caretPainter.cursorOffset; + set cursorOffset(Offset value) { + _caretPainter.cursorOffset = value; + } + + /// How rounded the corners of the cursor should be. + /// + /// A null value is the same as [Radius.zero]. + Radius? get cursorRadius => _caretPainter.cursorRadius; + set cursorRadius(Radius? value) { + _caretPainter.cursorRadius = value; + } + + /// The [LayerLink] of start selection handle. + /// + /// [RenderEditable] is responsible for calculating the [Offset] of this + /// [LayerLink], which will be used as [CompositedTransformTarget] of start handle. + LayerLink get startHandleLayerLink => _startHandleLayerLink; + LayerLink _startHandleLayerLink; + set startHandleLayerLink(LayerLink value) { + if (_startHandleLayerLink == value) { + return; + } + _startHandleLayerLink = value; + markNeedsPaint(); + } + + /// The [LayerLink] of end selection handle. + /// + /// [RenderEditable] is responsible for calculating the [Offset] of this + /// [LayerLink], which will be used as [CompositedTransformTarget] of end handle. + LayerLink get endHandleLayerLink => _endHandleLayerLink; + LayerLink _endHandleLayerLink; + set endHandleLayerLink(LayerLink value) { + if (_endHandleLayerLink == value) { + return; + } + _endHandleLayerLink = value; + markNeedsPaint(); + } + + /// The padding applied to text field. Used to determine the bounds when + /// moving the floating cursor. + /// + /// Defaults to a padding with left, top and right set to 4, bottom to 5. + EdgeInsets floatingCursorAddedMargin; + + bool _floatingCursorOn = false; + late TextPosition _floatingCursorTextPosition; + + /// Whether to allow the user to change the selection. + /// + /// Since [RenderEditable] does not handle selection manipulation + /// itself, this actually only affects whether the accessibility + /// hints provided to the system (via + /// [describeSemanticsConfiguration]) will enable selection + /// manipulation. It's the responsibility of this object's owner + /// to provide selection manipulation affordances. + /// + /// This field is used by [selectionEnabled] (which then controls + /// the accessibility hints mentioned above). When null, + /// [obscureText] is used to determine the value of + /// [selectionEnabled] instead. + bool? get enableInteractiveSelection => _enableInteractiveSelection; + bool? _enableInteractiveSelection; + set enableInteractiveSelection(bool? value) { + if (_enableInteractiveSelection == value) { + return; + } + _enableInteractiveSelection = value; + markNeedsTextLayout(); + markNeedsSemanticsUpdate(); + } + + /// Whether interactive selection are enabled based on the values of + /// [enableInteractiveSelection] and [obscureText]. + /// + /// Since [RenderEditable] does not handle selection manipulation + /// itself, this actually only affects whether the accessibility + /// hints provided to the system (via + /// [describeSemanticsConfiguration]) will enable selection + /// manipulation. It's the responsibility of this object's owner + /// to provide selection manipulation affordances. + /// + /// By default, [enableInteractiveSelection] is null, [obscureText] is false, + /// and this getter returns true. + /// + /// If [enableInteractiveSelection] is null and [obscureText] is true, then this + /// getter returns false. This is the common case for password fields. + /// + /// If [enableInteractiveSelection] is non-null then its value is + /// returned. An application might [enableInteractiveSelection] to + /// true to enable interactive selection for a password field, or to + /// false to unconditionally disable interactive selection. + bool get selectionEnabled { + return enableInteractiveSelection ?? !obscureText; + } + + /// The color used to paint the prompt rectangle. + /// + /// The prompt rectangle will only be requested on non-web iOS applications. + // TODO(ianh): We should change the getter to return null when _promptRectRange is null + // (otherwise, if you set it to null and then get it, you get back non-null). + // Alternatively, we could stop supporting setting this to null. + Color? get promptRectColor => _autocorrectHighlightPainter.highlightColor; + set promptRectColor(Color? newValue) { + _autocorrectHighlightPainter.highlightColor = newValue; + } + + /// Dismisses the currently displayed prompt rectangle and displays a new prompt rectangle + /// over [newRange] in the given color [promptRectColor]. + /// + /// The prompt rectangle will only be requested on non-web iOS applications. + /// + /// When set to null, the currently displayed prompt rectangle (if any) will be dismissed. + // ignore: use_setters_to_change_properties, (API predates enforcing the lint) + void setPromptRectRange(TextRange? newRange) { + _autocorrectHighlightPainter.highlightedRange = newRange; + } + + /// The maximum amount the text is allowed to scroll. + /// + /// This value is only valid after layout and can change as additional + /// text is entered or removed in order to accommodate expanding when + /// [expands] is set to true. + double get maxScrollExtent => _maxScrollExtent; + double _maxScrollExtent = 0; + + double get _caretMargin => _kCaretGap + cursorWidth; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.hardEdge; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + /// Collected during [describeSemanticsConfiguration], used by + /// [assembleSemanticsNode] and [_combineSemanticsInfo]. + List<InlineSpanSemanticsInformation>? _semanticsInfo; + + // Caches [SemanticsNode]s created during [assembleSemanticsNode] so they + // can be re-used when [assembleSemanticsNode] is called again. This ensures + // stable ids for the [SemanticsNode]s of [TextSpan]s across + // [assembleSemanticsNode] invocations. + LinkedHashMap<Key, SemanticsNode>? _cachedChildNodes; + + /// Returns a list of rects that bound the given selection, and the text + /// direction. The text direction is used by the engine to calculate + /// the closest position to a given point. + /// + /// See [TextPainter.getBoxesForSelection] for more details. + List<TextBox> getBoxesForSelection(TextSelection selection) { + _computeTextMetricsIfNeeded(); + return _textPainter.getBoxesForSelection(selection) + .map((TextBox textBox) => TextBox.fromLTRBD( + textBox.left + _paintOffset.dx, + textBox.top + _paintOffset.dy, + textBox.right + _paintOffset.dx, + textBox.bottom + _paintOffset.dy, + textBox.direction + )).toList(); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + _semanticsInfo = _textPainter.text!.getSemanticsInformation(); + // TODO(chunhtai): the macOS does not provide a public API to support text + // selections across multiple semantics nodes. Remove this platform check + // once we can support it. + // https://github.com/flutter/flutter/issues/77957 + if (_semanticsInfo!.any((InlineSpanSemanticsInformation info) => info.recognizer != null) && + defaultTargetPlatform != TargetPlatform.macOS) { + assert(readOnly && !obscureText); + // For Selectable rich text with recognizer, we need to create a semantics + // node for each text fragment. + config + ..isSemanticBoundary = true + ..explicitChildNodes = true; + return; + } + if (_cachedAttributedValue == null) { + if (obscureText) { + _cachedAttributedValue = AttributedString(obscuringCharacter * plainText.length); + } else { + final StringBuffer buffer = StringBuffer(); + int offset = 0; + final List<StringAttribute> attributes = <StringAttribute>[]; + for (final InlineSpanSemanticsInformation info in _semanticsInfo!) { + final String label = info.semanticsLabel ?? info.text; + for (final StringAttribute infoAttribute in info.stringAttributes) { + final TextRange originalRange = infoAttribute.range; + attributes.add( + infoAttribute.copy( + range: TextRange(start: offset + originalRange.start, end: offset + originalRange.end), + ), + ); + } + buffer.write(label); + offset += label.length; + } + _cachedAttributedValue = AttributedString(buffer.toString(), attributes: attributes); + } + } + config + ..attributedValue = _cachedAttributedValue! + ..isObscured = obscureText + ..isMultiline = _isMultiline + ..textDirection = textDirection + ..isFocused = hasFocus + ..isTextField = true + ..isReadOnly = readOnly; + + if (hasFocus && selectionEnabled) { + config.onSetSelection = _handleSetSelection; + } + + if (hasFocus && !readOnly) { + config.onSetText = _handleSetText; + } + + if (selectionEnabled && (selection?.isValid ?? false)) { + config.textSelection = selection; + if (_textPainter.getOffsetBefore(selection!.extentOffset) != null) { + config + ..onMoveCursorBackwardByWord = _handleMoveCursorBackwardByWord + ..onMoveCursorBackwardByCharacter = _handleMoveCursorBackwardByCharacter; + } + if (_textPainter.getOffsetAfter(selection!.extentOffset) != null) { + config + ..onMoveCursorForwardByWord = _handleMoveCursorForwardByWord + ..onMoveCursorForwardByCharacter = _handleMoveCursorForwardByCharacter; + } + } + } + + void _handleSetText(String text) { + textSelectionDelegate.userUpdateTextEditingValue( + TextEditingValue( + text: text, + selection: TextSelection.collapsed(offset: text.length), + ), + SelectionChangedCause.keyboard, + ); + } + + @override + void assembleSemanticsNode(SemanticsNode node, SemanticsConfiguration config, Iterable<SemanticsNode> children) { + assert(_semanticsInfo != null && _semanticsInfo!.isNotEmpty); + final List<SemanticsNode> newChildren = <SemanticsNode>[]; + TextDirection currentDirection = textDirection; + Rect currentRect; + double ordinal = 0.0; + int start = 0; + int placeholderIndex = 0; + int childIndex = 0; + RenderBox? child = firstChild; + final LinkedHashMap<Key, SemanticsNode> newChildCache = LinkedHashMap<Key, SemanticsNode>(); + _cachedCombinedSemanticsInfos ??= combineSemanticsInfo(_semanticsInfo!); + for (final InlineSpanSemanticsInformation info in _cachedCombinedSemanticsInfos!) { + final TextSelection selection = TextSelection( + baseOffset: start, + extentOffset: start + info.text.length, + ); + start += info.text.length; + + if (info.isPlaceholder) { + // A placeholder span may have 0 to multiple semantics nodes, we need + // to annotate all of the semantics nodes belong to this span. + while (children.length > childIndex && + children.elementAt(childIndex).isTagged(PlaceholderSpanIndexSemanticsTag(placeholderIndex))) { + final SemanticsNode childNode = children.elementAt(childIndex); + final TextParentData parentData = child!.parentData! as TextParentData; + assert(parentData.offset != null); + newChildren.add(childNode); + childIndex += 1; + } + child = childAfter(child!); + placeholderIndex += 1; + } else { + final TextDirection initialDirection = currentDirection; + final List<ui.TextBox> rects = _textPainter.getBoxesForSelection(selection); + if (rects.isEmpty) { + continue; + } + Rect rect = rects.first.toRect(); + currentDirection = rects.first.direction; + for (final ui.TextBox textBox in rects.skip(1)) { + rect = rect.expandToInclude(textBox.toRect()); + currentDirection = textBox.direction; + } + // Any of the text boxes may have had infinite dimensions. + // We shouldn't pass infinite dimensions up to the bridges. + rect = Rect.fromLTWH( + math.max(0.0, rect.left), + math.max(0.0, rect.top), + math.min(rect.width, constraints.maxWidth), + math.min(rect.height, constraints.maxHeight), + ); + // Round the current rectangle to make this API testable and add some + // padding so that the accessibility rects do not overlap with the text. + currentRect = Rect.fromLTRB( + rect.left.floorToDouble() - 4.0, + rect.top.floorToDouble() - 4.0, + rect.right.ceilToDouble() + 4.0, + rect.bottom.ceilToDouble() + 4.0, + ); + final SemanticsConfiguration configuration = SemanticsConfiguration() + ..sortKey = OrdinalSortKey(ordinal++) + ..textDirection = initialDirection + ..attributedLabel = AttributedString(info.semanticsLabel ?? info.text, attributes: info.stringAttributes); + final GestureRecognizer? recognizer = info.recognizer; + if (recognizer != null) { + if (recognizer is TapGestureRecognizer) { + if (recognizer.onTap != null) { + configuration.onTap = recognizer.onTap; + configuration.isLink = true; + } + } else if (recognizer is DoubleTapGestureRecognizer) { + if (recognizer.onDoubleTap != null) { + configuration.onTap = recognizer.onDoubleTap; + configuration.isLink = true; + } + } else if (recognizer is LongPressGestureRecognizer) { + if (recognizer.onLongPress != null) { + configuration.onLongPress = recognizer.onLongPress; + } + } else { + assert(false, '${recognizer.runtimeType} is not supported.'); + } + } + if (node.parentPaintClipRect != null) { + final Rect paintRect = node.parentPaintClipRect!.intersect(currentRect); + configuration.isHidden = paintRect.isEmpty && !currentRect.isEmpty; + } + late final SemanticsNode newChild; + if (_cachedChildNodes?.isNotEmpty ?? false) { + newChild = _cachedChildNodes!.remove(_cachedChildNodes!.keys.first)!; + } else { + final UniqueKey key = UniqueKey(); + newChild = SemanticsNode( + key: key, + showOnScreen: _createShowOnScreenFor(key), + ); + } + newChild + ..updateWith(config: configuration) + ..rect = currentRect; + newChildCache[newChild.key!] = newChild; + newChildren.add(newChild); + } + } + _cachedChildNodes = newChildCache; + node.updateWith(config: config, childrenInInversePaintOrder: newChildren); + } + + VoidCallback? _createShowOnScreenFor(Key key) { + return () { + final SemanticsNode node = _cachedChildNodes![key]!; + showOnScreen(descendant: this, rect: node.rect); + }; + } + + // TODO(ianh): in theory, [selection] could become null between when + // we last called describeSemanticsConfiguration and when the + // callbacks are invoked, in which case the callbacks will crash... + + void _handleSetSelection(TextSelection selection) { + _setSelection(selection, SelectionChangedCause.keyboard); + } + + void _handleMoveCursorForwardByCharacter(bool extendSelection) { + assert(selection != null); + final int? extentOffset = _textPainter.getOffsetAfter(selection!.extentOffset); + if (extentOffset == null) { + return; + } + final int baseOffset = !extendSelection ? extentOffset : selection!.baseOffset; + _setSelection( + TextSelection(baseOffset: baseOffset, extentOffset: extentOffset), + SelectionChangedCause.keyboard, + ); + } + + void _handleMoveCursorBackwardByCharacter(bool extendSelection) { + assert(selection != null); + final int? extentOffset = _textPainter.getOffsetBefore(selection!.extentOffset); + if (extentOffset == null) { + return; + } + final int baseOffset = !extendSelection ? extentOffset : selection!.baseOffset; + _setSelection( + TextSelection(baseOffset: baseOffset, extentOffset: extentOffset), + SelectionChangedCause.keyboard, + ); + } + + void _handleMoveCursorForwardByWord(bool extendSelection) { + assert(selection != null); + final TextRange currentWord = _textPainter.getWordBoundary(selection!.extent); + final TextRange? nextWord = _getNextWord(currentWord.end); + if (nextWord == null) { + return; + } + final int baseOffset = extendSelection ? selection!.baseOffset : nextWord.start; + _setSelection( + TextSelection( + baseOffset: baseOffset, + extentOffset: nextWord.start, + ), + SelectionChangedCause.keyboard, + ); + } + + void _handleMoveCursorBackwardByWord(bool extendSelection) { + assert(selection != null); + final TextRange currentWord = _textPainter.getWordBoundary(selection!.extent); + final TextRange? previousWord = _getPreviousWord(currentWord.start - 1); + if (previousWord == null) { + return; + } + final int baseOffset = extendSelection ? selection!.baseOffset : previousWord.start; + _setSelection( + TextSelection( + baseOffset: baseOffset, + extentOffset: previousWord.start, + ), + SelectionChangedCause.keyboard, + ); + } + + TextRange? _getNextWord(int offset) { + while (true) { + final TextRange range = _textPainter.getWordBoundary(TextPosition(offset: offset)); + if (!range.isValid || range.isCollapsed) { + return null; + } + if (!_onlyWhitespace(range)) { + return range; + } + offset = range.end; + } + } + + TextRange? _getPreviousWord(int offset) { + while (offset >= 0) { + final TextRange range = _textPainter.getWordBoundary(TextPosition(offset: offset)); + if (!range.isValid || range.isCollapsed) { + return null; + } + if (!_onlyWhitespace(range)) { + return range; + } + offset = range.start - 1; + } + return null; + } + + // Check if the given text range only contains white space or separator + // characters. + // + // Includes newline characters from ASCII and separators from the + // [unicode separator category](https://www.compart.com/en/unicode/category/Zs) + // TODO(zanderso): replace when we expose this ICU information. + bool _onlyWhitespace(TextRange range) { + for (int i = range.start; i < range.end; i++) { + final int codeUnit = text!.codeUnitAt(i)!; + if (!TextLayoutMetrics.isWhitespace(codeUnit)) { + return false; + } + } + return true; + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _foregroundRenderObject?.attach(owner); + _backgroundRenderObject?.attach(owner); + + _tap = TapGestureRecognizer(debugOwner: this) + ..onTapDown = _handleTapDown + ..onTap = _handleTap; + _longPress = LongPressGestureRecognizer(debugOwner: this)..onLongPress = _handleLongPress; + _offset.addListener(markNeedsPaint); + _showHideCursor(); + _showCursor.addListener(_showHideCursor); + } + + @override + void detach() { + _tap.dispose(); + _longPress.dispose(); + _offset.removeListener(markNeedsPaint); + _showCursor.removeListener(_showHideCursor); + super.detach(); + _foregroundRenderObject?.detach(); + _backgroundRenderObject?.detach(); + } + + @override + void redepthChildren() { + final RenderObject? foregroundChild = _foregroundRenderObject; + final RenderObject? backgroundChild = _backgroundRenderObject; + if (foregroundChild != null) { + redepthChild(foregroundChild); + } + if (backgroundChild != null) { + redepthChild(backgroundChild); + } + super.redepthChildren(); + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + final RenderObject? foregroundChild = _foregroundRenderObject; + final RenderObject? backgroundChild = _backgroundRenderObject; + if (foregroundChild != null) { + visitor(foregroundChild); + } + if (backgroundChild != null) { + visitor(backgroundChild); + } + super.visitChildren(visitor); + } + + bool get _isMultiline => maxLines != 1; + + Axis get _viewportAxis => _isMultiline ? Axis.vertical : Axis.horizontal; + + Offset get _paintOffset { + switch (_viewportAxis) { + case Axis.horizontal: + return Offset(-offset.pixels, 0.0); + case Axis.vertical: + return Offset(0.0, -offset.pixels); + } + } + + double get _viewportExtent { + assert(hasSize); + switch (_viewportAxis) { + case Axis.horizontal: + return size.width; + case Axis.vertical: + return size.height; + } + } + + double _getMaxScrollExtent(Size contentSize) { + assert(hasSize); + switch (_viewportAxis) { + case Axis.horizontal: + return math.max(0.0, contentSize.width - size.width); + case Axis.vertical: + return math.max(0.0, contentSize.height - size.height); + } + } + + // We need to check the paint offset here because during animation, the start of + // the text may position outside the visible region even when the text fits. + bool get _hasVisualOverflow => _maxScrollExtent > 0 || _paintOffset != Offset.zero; + + /// Returns the local coordinates of the endpoints of the given selection. + /// + /// If the selection is collapsed (and therefore occupies a single point), the + /// returned list is of length one. Otherwise, the selection is not collapsed + /// and the returned list is of length two. In this case, however, the two + /// points might actually be co-located (e.g., because of a bidirectional + /// selection that contains some text but whose ends meet in the middle). + /// + /// See also: + /// + /// * [getLocalRectForCaret], which is the equivalent but for + /// a [TextPosition] rather than a [TextSelection]. + List<TextSelectionPoint> getEndpointsForSelection(TextSelection selection) { + _computeTextMetricsIfNeeded(); + + final Offset paintOffset = _paintOffset; + + final List<ui.TextBox> boxes = selection.isCollapsed ? + <ui.TextBox>[] : _textPainter.getBoxesForSelection(selection, boxHeightStyle: selectionHeightStyle, boxWidthStyle: selectionWidthStyle); + if (boxes.isEmpty) { + // TODO(mpcomplete): This doesn't work well at an RTL/LTR boundary. + final Offset caretOffset = _textPainter.getOffsetForCaret(selection.extent, _caretPrototype); + final Offset start = Offset(0.0, preferredLineHeight) + caretOffset + paintOffset; + return <TextSelectionPoint>[TextSelectionPoint(start, null)]; + } else { + final Offset start = Offset(clampDouble(boxes.first.start, 0, _textPainter.size.width), boxes.first.bottom) + paintOffset; + final Offset end = Offset(clampDouble(boxes.last.end, 0, _textPainter.size.width), boxes.last.bottom) + paintOffset; + return <TextSelectionPoint>[ + TextSelectionPoint(start, boxes.first.direction), + TextSelectionPoint(end, boxes.last.direction), + ]; + } + } + + /// Returns the smallest [Rect], in the local coordinate system, that covers + /// the text within the [TextRange] specified. + /// + /// This method is used to calculate the approximate position of the IME bar + /// on iOS. + /// + /// Returns null if [TextRange.isValid] is false for the given `range`, or the + /// given `range` is collapsed. + Rect? getRectForComposingRange(TextRange range) { + if (!range.isValid || range.isCollapsed) { + return null; + } + _computeTextMetricsIfNeeded(); + + final List<ui.TextBox> boxes = _textPainter.getBoxesForSelection( + TextSelection(baseOffset: range.start, extentOffset: range.end), + boxHeightStyle: selectionHeightStyle, + boxWidthStyle: selectionWidthStyle, + ); + + return boxes.fold( + null, + (Rect? accum, TextBox incoming) => accum?.expandToInclude(incoming.toRect()) ?? incoming.toRect(), + )?.shift(_paintOffset); + } + + /// Returns the position in the text for the given global coordinate. + /// + /// See also: + /// + /// * [getLocalRectForCaret], which is the reverse operation, taking + /// a [TextPosition] and returning a [Rect]. + /// * [TextPainter.getPositionForOffset], which is the equivalent method + /// for a [TextPainter] object. + TextPosition getPositionForPoint(Offset globalPosition) { + _computeTextMetricsIfNeeded(); + globalPosition += -_paintOffset; + return _textPainter.getPositionForOffset(globalToLocal(globalPosition)); + } + + /// Returns the [Rect] in local coordinates for the caret at the given text + /// position. + /// + /// See also: + /// + /// * [getPositionForPoint], which is the reverse operation, taking + /// an [Offset] in global coordinates and returning a [TextPosition]. + /// * [getEndpointsForSelection], which is the equivalent but for + /// a selection rather than a particular text position. + /// * [TextPainter.getOffsetForCaret], the equivalent method for a + /// [TextPainter] object. + Rect getLocalRectForCaret(TextPosition caretPosition) { + _computeTextMetricsIfNeeded(); + final Rect caretPrototype = _caretPrototype; + final Offset caretOffset = _textPainter.getOffsetForCaret(caretPosition, caretPrototype); + Rect caretRect = caretPrototype.shift(caretOffset + cursorOffset); + final double scrollableWidth = math.max(_textPainter.width + _caretMargin, size.width); + + final double caretX = clampDouble(caretRect.left, 0, math.max(scrollableWidth - _caretMargin, 0)); + caretRect = Offset(caretX, caretRect.top) & caretRect.size; + + final double caretHeight = cursorHeight; + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + final double fullHeight = _textPainter.getFullHeightForCaret(caretPosition, caretPrototype) ?? _textPainter.preferredLineHeight; + final double heightDiff = fullHeight - caretRect.height; + // Center the caret vertically along the text. + caretRect = Rect.fromLTWH( + caretRect.left, + caretRect.top + heightDiff / 2, + caretRect.width, + caretRect.height, + ); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + // Override the height to take the full height of the glyph at the TextPosition + // when not on iOS. iOS has special handling that creates a taller caret. + // TODO(garyq): See the TODO for _computeCaretPrototype(). + caretRect = Rect.fromLTWH( + caretRect.left, + caretRect.top - _kCaretHeightOffset, + caretRect.width, + caretHeight, + ); + } + + caretRect = caretRect.shift(_paintOffset); + return caretRect.shift(_snapToPhysicalPixel(caretRect.topLeft)); + } + + @override + double computeMinIntrinsicWidth(double height) { + if (!_canComputeIntrinsics) { + return 0.0; + } + _textPainter.setPlaceholderDimensions(layoutInlineChildren( + double.infinity, + (RenderBox child, BoxConstraints constraints) => Size(child.getMinIntrinsicWidth(double.infinity), 0.0), + )); + _layoutText(); + return _textPainter.minIntrinsicWidth; + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (!_canComputeIntrinsics) { + return 0.0; + } + _textPainter.setPlaceholderDimensions(layoutInlineChildren( + double.infinity, + // Height and baseline is irrelevant as all text will be laid + // out in a single line. Therefore, using 0.0 as a dummy for the height. + (RenderBox child, BoxConstraints constraints) => Size(child.getMaxIntrinsicWidth(double.infinity), 0.0), + )); + _layoutText(); + return _textPainter.maxIntrinsicWidth + _caretMargin; + } + + /// An estimate of the height of a line in the text. See [TextPainter.preferredLineHeight]. + /// This does not require the layout to be updated. + double get preferredLineHeight => _textPainter.preferredLineHeight; + + int? _cachedLineBreakCount; + // TODO(LongCatIsLooong): see if we can let ui.Paragraph estimate the number + // of lines + int _countHardLineBreaks(String text) { + final int? cachedValue = _cachedLineBreakCount; + if (cachedValue != null) { + return cachedValue; + } + int count = 0; + for (int index = 0; index < text.length; index += 1) { + switch (text.codeUnitAt(index)) { + case 0x000A: // LF + case 0x0085: // NEL + case 0x000B: // VT + case 0x000C: // FF, treating it as a regular line separator + case 0x2028: // LS + case 0x2029: // PS + count += 1; + } + } + return _cachedLineBreakCount = count; + } + + double _preferredHeight(double width) { + final int? maxLines = this.maxLines; + final int? minLines = this.minLines ?? maxLines; + final double minHeight = preferredLineHeight * (minLines ?? 0); + + if (maxLines == null) { + final double estimatedHeight; + if (width == double.infinity) { + estimatedHeight = preferredLineHeight * (_countHardLineBreaks(plainText) + 1); + } else { + _layoutText(maxWidth: width); + estimatedHeight = _textPainter.height; + } + return math.max(estimatedHeight, minHeight); + } + + // Special case maxLines == 1 since it forces the scrollable direction + // to be horizontal. Report the real height to prevent the text from being + // clipped. + if (maxLines == 1) { + // The _layoutText call lays out the paragraph using infinite width when + // maxLines == 1. Also _textPainter.maxLines will be set to 1 so should + // there be any line breaks only the first line is shown. + assert(_textPainter.maxLines == 1); + _layoutText(maxWidth: width); + return _textPainter.height; + } + if (minLines == maxLines) { + return minHeight; + } + _layoutText(maxWidth: width); + final double maxHeight = preferredLineHeight * maxLines; + return clampDouble(_textPainter.height, minHeight, maxHeight); + } + + @override + double computeMinIntrinsicHeight(double width) => computeMaxIntrinsicHeight(width); + + @override + double computeMaxIntrinsicHeight(double width) { + if (!_canComputeIntrinsics) { + return 0.0; + } + _textPainter.setPlaceholderDimensions(layoutInlineChildren(width, ChildLayoutHelper.dryLayoutChild)); + return _preferredHeight(width); + } + + @override + double computeDistanceToActualBaseline(TextBaseline baseline) { + _computeTextMetricsIfNeeded(); + return _textPainter.computeDistanceToActualBaseline(baseline); + } + + @override + bool hitTestSelf(Offset position) => true; + + @override + @protected + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + final Offset effectivePosition = position - _paintOffset; + final GlyphInfo? glyph = _textPainter.getClosestGlyphForOffset(effectivePosition); + // The hit-test can't fall through the horizontal gaps between visually + // adjacent characters on the same line, even with a large letter-spacing or + // text justification, as graphemeClusterLayoutBounds.width is the advance + // width to the next character, so there's no gap between their + // graphemeClusterLayoutBounds rects. + final InlineSpan? spanHit = glyph != null && glyph.graphemeClusterLayoutBounds.contains(effectivePosition) + ? _textPainter.text!.getSpanForPosition(TextPosition(offset: glyph.graphemeClusterCodeUnitRange.start)) + : null; + switch (spanHit) { + case final HitTestTarget span: + result.add(HitTestEntry(span)); + return true; + case _: + return hitTestInlineChildren(result, effectivePosition); + } + } + + late TapGestureRecognizer _tap; + late LongPressGestureRecognizer _longPress; + + @override + void handleEvent(PointerEvent event, BoxHitTestEntry entry) { + assert(debugHandleEvent(event, entry)); + if (event is PointerDownEvent) { + assert(!debugNeedsLayout); + + if (!ignorePointer) { + // Propagates the pointer event to selection handlers. + _tap.addPointer(event); + _longPress.addPointer(event); + } + } + } + + Offset? _lastTapDownPosition; + Offset? _lastSecondaryTapDownPosition; + + /// {@template flutter.rendering.RenderEditable.lastSecondaryTapDownPosition} + /// The position of the most recent secondary tap down event on this text + /// input. + /// {@endtemplate} + Offset? get lastSecondaryTapDownPosition => _lastSecondaryTapDownPosition; + + /// Tracks the position of a secondary tap event. + /// + /// Should be called before attempting to change the selection based on the + /// position of a secondary tap. + void handleSecondaryTapDown(TapDownDetails details) { + _lastTapDownPosition = details.globalPosition; + _lastSecondaryTapDownPosition = details.globalPosition; + } + + /// If [ignorePointer] is false (the default) then this method is called by + /// the internal gesture recognizer's [TapGestureRecognizer.onTapDown] + /// callback. + /// + /// When [ignorePointer] is true, an ancestor widget must respond to tap + /// down events by calling this method. + void handleTapDown(TapDownDetails details) { + _lastTapDownPosition = details.globalPosition; + } + void _handleTapDown(TapDownDetails details) { + assert(!ignorePointer); + handleTapDown(details); + } + + /// If [ignorePointer] is false (the default) then this method is called by + /// the internal gesture recognizer's [TapGestureRecognizer.onTap] + /// callback. + /// + /// When [ignorePointer] is true, an ancestor widget must respond to tap + /// events by calling this method. + void handleTap() { + selectPosition(cause: SelectionChangedCause.tap); + } + void _handleTap() { + assert(!ignorePointer); + handleTap(); + } + + /// If [ignorePointer] is false (the default) then this method is called by + /// the internal gesture recognizer's [DoubleTapGestureRecognizer.onDoubleTap] + /// callback. + /// + /// When [ignorePointer] is true, an ancestor widget must respond to double + /// tap events by calling this method. + void handleDoubleTap() { + selectWord(cause: SelectionChangedCause.doubleTap); + } + + /// If [ignorePointer] is false (the default) then this method is called by + /// the internal gesture recognizer's [LongPressGestureRecognizer.onLongPress] + /// callback. + /// + /// When [ignorePointer] is true, an ancestor widget must respond to long + /// press events by calling this method. + void handleLongPress() { + selectWord(cause: SelectionChangedCause.longPress); + } + void _handleLongPress() { + assert(!ignorePointer); + handleLongPress(); + } + + /// Move selection to the location of the last tap down. + /// + /// {@template flutter.rendering.RenderEditable.selectPosition} + /// This method is mainly used to translate user inputs in global positions + /// into a [TextSelection]. When used in conjunction with a [EditableText], + /// the selection change is fed back into [TextEditingController.selection]. + /// + /// If you have a [TextEditingController], it's generally easier to + /// programmatically manipulate its `value` or `selection` directly. + /// {@endtemplate} + void selectPosition({ required SelectionChangedCause cause }) { + selectPositionAt(from: _lastTapDownPosition!, cause: cause); + } + + /// Select text between the global positions [from] and [to]. + /// + /// [from] corresponds to the [TextSelection.baseOffset], and [to] corresponds + /// to the [TextSelection.extentOffset]. + void selectPositionAt({ required Offset from, Offset? to, required SelectionChangedCause cause }) { + _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); + final TextPosition fromPosition = _textPainter.getPositionForOffset(globalToLocal(from - _paintOffset)); + final TextPosition? toPosition = to == null + ? null + : _textPainter.getPositionForOffset(globalToLocal(to - _paintOffset)); + + final int baseOffset = fromPosition.offset; + final int extentOffset = toPosition?.offset ?? fromPosition.offset; + + final TextSelection newSelection = TextSelection( + baseOffset: baseOffset, + extentOffset: extentOffset, + affinity: fromPosition.affinity, + ); + + _setSelection(newSelection, cause); + } + + /// {@macro flutter.painting.TextPainter.wordBoundaries} + WordBoundary get wordBoundaries => _textPainter.wordBoundaries; + + /// Select a word around the location of the last tap down. + /// + /// {@macro flutter.rendering.RenderEditable.selectPosition} + void selectWord({ required SelectionChangedCause cause }) { + selectWordsInRange(from: _lastTapDownPosition!, cause: cause); + } + + /// Selects the set words of a paragraph that intersect a given range of global positions. + /// + /// The set of words selected are not strictly bounded by the range of global positions. + /// + /// The first and last endpoints of the selection will always be at the + /// beginning and end of a word respectively. + /// + /// {@macro flutter.rendering.RenderEditable.selectPosition} + void selectWordsInRange({ required Offset from, Offset? to, required SelectionChangedCause cause }) { + _computeTextMetricsIfNeeded(); + final TextPosition fromPosition = _textPainter.getPositionForOffset(globalToLocal(from - _paintOffset)); + final TextSelection fromWord = getWordAtOffset(fromPosition); + final TextPosition toPosition = to == null ? fromPosition : _textPainter.getPositionForOffset(globalToLocal(to - _paintOffset)); + final TextSelection toWord = toPosition == fromPosition ? fromWord : getWordAtOffset(toPosition); + final bool isFromWordBeforeToWord = fromWord.start < toWord.end; + + _setSelection( + TextSelection( + baseOffset: isFromWordBeforeToWord ? fromWord.base.offset : fromWord.extent.offset, + extentOffset: isFromWordBeforeToWord ? toWord.extent.offset : toWord.base.offset, + affinity: fromWord.affinity, + ), + cause, + ); + } + + /// Move the selection to the beginning or end of a word. + /// + /// {@macro flutter.rendering.RenderEditable.selectPosition} + void selectWordEdge({ required SelectionChangedCause cause }) { + _computeTextMetricsIfNeeded(); + assert(_lastTapDownPosition != null); + final TextPosition position = _textPainter.getPositionForOffset(globalToLocal(_lastTapDownPosition! - _paintOffset)); + final TextRange word = _textPainter.getWordBoundary(position); + late TextSelection newSelection; + if (position.offset <= word.start) { + newSelection = TextSelection.collapsed(offset: word.start); + } else { + newSelection = TextSelection.collapsed(offset: word.end, affinity: TextAffinity.upstream); + } + _setSelection(newSelection, cause); + } + + /// Returns a [TextSelection] that encompasses the word at the given + /// [TextPosition]. + @visibleForTesting + TextSelection getWordAtOffset(TextPosition position) { + debugAssertLayoutUpToDate(); + // When long-pressing past the end of the text, we want a collapsed cursor. + if (position.offset >= plainText.length) { + return TextSelection.fromPosition( + TextPosition(offset: plainText.length, affinity: TextAffinity.upstream) + ); + } + // If text is obscured, the entire sentence should be treated as one word. + if (obscureText) { + return TextSelection(baseOffset: 0, extentOffset: plainText.length); + } + final TextRange word = _textPainter.getWordBoundary(position); + final int effectiveOffset; + switch (position.affinity) { + case TextAffinity.upstream: + // upstream affinity is effectively -1 in text position. + effectiveOffset = position.offset - 1; + case TextAffinity.downstream: + effectiveOffset = position.offset; + } + assert(effectiveOffset >= 0); + + // On iOS, select the previous word if there is a previous word, or select + // to the end of the next word if there is a next word. Select nothing if + // there is neither a previous word nor a next word. + // + // If the platform is Android and the text is read only, try to select the + // previous word if there is one; otherwise, select the single whitespace at + // the position. + if (effectiveOffset > 0 + && TextLayoutMetrics.isWhitespace(plainText.codeUnitAt(effectiveOffset))) { + final TextRange? previousWord = _getPreviousWord(word.start); + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + if (previousWord == null) { + final TextRange? nextWord = _getNextWord(word.start); + if (nextWord == null) { + return TextSelection.collapsed(offset: position.offset); + } + return TextSelection( + baseOffset: position.offset, + extentOffset: nextWord.end, + ); + } + return TextSelection( + baseOffset: previousWord.start, + extentOffset: position.offset, + ); + case TargetPlatform.android: + if (readOnly) { + if (previousWord == null) { + return TextSelection( + baseOffset: position.offset, + extentOffset: position.offset + 1, + ); + } + return TextSelection( + baseOffset: previousWord.start, + extentOffset: position.offset, + ); + } + case TargetPlatform.fuchsia: + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + break; + } + } + + return TextSelection(baseOffset: word.start, extentOffset: word.end); + } + + // Placeholder dimensions representing the sizes of child inline widgets. + // + // These need to be cached because the text painter's placeholder dimensions + // will be overwritten during intrinsic width/height calculations and must be + // restored to the original values before final layout and painting. + List<PlaceholderDimensions>? _placeholderDimensions; + + void _layoutText({ double minWidth = 0.0, double maxWidth = double.infinity }) { + final double availableMaxWidth = math.max(0.0, maxWidth - _caretMargin); + final double availableMinWidth = math.min(minWidth, availableMaxWidth); + final double textMaxWidth = _isMultiline ? availableMaxWidth : double.infinity; + final double textMinWidth = forceLine ? availableMaxWidth : availableMinWidth; + _textPainter.layout( + minWidth: textMinWidth, + maxWidth: textMaxWidth, + ); + _textLayoutLastMinWidth = minWidth; + _textLayoutLastMaxWidth = maxWidth; + } + + // Computes the text metrics if `_textPainter`'s layout information was marked + // as dirty. + // + // This method must be called in `RenderEditable`'s public methods that expose + // `_textPainter`'s metrics. For instance, `systemFontsDidChange` sets + // _textPainter._paragraph to null, so accessing _textPainter's metrics + // immediately after `systemFontsDidChange` without first calling this method + // may crash. + // + // This method is also called in various paint methods (`RenderEditable.paint` + // as well as its foreground/background painters' `paint`). It's needed + // because invisible render objects kept in the tree by `KeepAlive` may not + // get a chance to do layout but can still paint. + // See https://github.com/flutter/flutter/issues/84896. + // + // This method only re-computes layout if the underlying `_textPainter`'s + // layout cache is invalidated (by calling `TextPainter.markNeedsLayout`), or + // the constraints used to layout the `_textPainter` is different. See + // `TextPainter.layout`. + void _computeTextMetricsIfNeeded() { + _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); + } + + late Rect _caretPrototype; + + // TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/120836 + // + /// On iOS, the cursor is taller than the cursor on Android. The height + /// of the cursor for iOS is approximate and obtained through an eyeball + /// comparison. + void _computeCaretPrototype() { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + _caretPrototype = Rect.fromLTWH(0.0, 0.0, cursorWidth, cursorHeight + 2); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + _caretPrototype = Rect.fromLTWH(0.0, _kCaretHeightOffset, cursorWidth, cursorHeight - 2.0 * _kCaretHeightOffset); + } + } + + // Computes the offset to apply to the given [sourceOffset] so it perfectly + // snaps to physical pixels. + Offset _snapToPhysicalPixel(Offset sourceOffset) { + final Offset globalOffset = localToGlobal(sourceOffset); + final double pixelMultiple = 1.0 / _devicePixelRatio; + return Offset( + globalOffset.dx.isFinite + ? (globalOffset.dx / pixelMultiple).round() * pixelMultiple - globalOffset.dx + : 0, + globalOffset.dy.isFinite + ? (globalOffset.dy / pixelMultiple).round() * pixelMultiple - globalOffset.dy + : 0, + ); + } + + bool _canComputeDryLayoutForInlineWidgets() { + return text?.visitChildren((InlineSpan span) { + return (span is! PlaceholderSpan) || switch (span.alignment) { + ui.PlaceholderAlignment.baseline || + ui.PlaceholderAlignment.aboveBaseline || + ui.PlaceholderAlignment.belowBaseline => false, + ui.PlaceholderAlignment.top || + ui.PlaceholderAlignment.middle || + ui.PlaceholderAlignment.bottom => true, + }; + }) ?? true; + } + + bool? _canComputeIntrinsicsCached; + bool get _canComputeIntrinsics => _canComputeIntrinsicsCached ??= _canComputeDryLayoutForInlineWidgets(); + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (!_canComputeIntrinsics) { + assert(debugCannotComputeDryLayout( + reason: 'Dry layout not available for alignments that require baseline.', + )); + return Size.zero; + } + _textPainter.setPlaceholderDimensions(layoutInlineChildren(constraints.maxWidth, ChildLayoutHelper.dryLayoutChild)); + _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); + final double width = forceLine ? constraints.maxWidth : constraints + .constrainWidth(_textPainter.size.width + _caretMargin); + return Size(width, constraints.constrainHeight(_preferredHeight(constraints.maxWidth))); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + _placeholderDimensions = layoutInlineChildren(constraints.maxWidth, ChildLayoutHelper.layoutChild); + _textPainter.setPlaceholderDimensions(_placeholderDimensions); + _computeTextMetricsIfNeeded(); + positionInlineChildren(_textPainter.inlinePlaceholderBoxes!); + _computeCaretPrototype(); + // We grab _textPainter.size here because assigning to `size` on the next + // line will trigger us to validate our intrinsic sizes, which will change + // _textPainter's layout because the intrinsic size calculations are + // destructive, which would mean we would get different results if we later + // used properties on _textPainter in this method. + // Other _textPainter state like didExceedMaxLines will also be affected, + // though we currently don't use those here. + // See also RenderParagraph which has a similar issue. + final Size textPainterSize = _textPainter.size; + final double width = forceLine ? constraints.maxWidth : constraints + .constrainWidth(_textPainter.size.width + _caretMargin); + final double preferredHeight = _preferredHeight(constraints.maxWidth); + size = Size(width, constraints.constrainHeight(preferredHeight)); + final Size contentSize = Size(textPainterSize.width + _caretMargin, textPainterSize.height); + + final BoxConstraints painterConstraints = BoxConstraints.tight(contentSize); + + _foregroundRenderObject?.layout(painterConstraints); + _backgroundRenderObject?.layout(painterConstraints); + + _maxScrollExtent = _getMaxScrollExtent(contentSize); + offset.applyViewportDimension(_viewportExtent); + offset.applyContentDimensions(0.0, _maxScrollExtent); + } + + // The relative origin in relation to the distance the user has theoretically + // dragged the floating cursor offscreen. This value is used to account for the + // difference in the rendering position and the raw offset value. + Offset _relativeOrigin = Offset.zero; + Offset? _previousOffset; + bool _shouldResetOrigin = true; + bool _resetOriginOnLeft = false; + bool _resetOriginOnRight = false; + bool _resetOriginOnTop = false; + bool _resetOriginOnBottom = false; + double? _resetFloatingCursorAnimationValue; + + static Offset _calculateAdjustedCursorOffset(Offset offset, Rect boundingRects) { + final double adjustedX = clampDouble(offset.dx, boundingRects.left, boundingRects.right); + final double adjustedY = clampDouble(offset.dy, boundingRects.top, boundingRects.bottom); + return Offset(adjustedX, adjustedY); + } + + /// Returns the position within the text field closest to the raw cursor offset. + Offset calculateBoundedFloatingCursorOffset(Offset rawCursorOffset, {bool? shouldResetOrigin}) { + Offset deltaPosition = Offset.zero; + final double topBound = -floatingCursorAddedMargin.top; + final double bottomBound = math.min(size.height, _textPainter.height) - preferredLineHeight + floatingCursorAddedMargin.bottom; + final double leftBound = -floatingCursorAddedMargin.left; + final double rightBound = math.min(size.width, _textPainter.width) + floatingCursorAddedMargin.right; + final Rect boundingRects = Rect.fromLTRB(leftBound, topBound, rightBound, bottomBound); + + if (shouldResetOrigin != null) { + _shouldResetOrigin = shouldResetOrigin; + } + + if (!_shouldResetOrigin) { + return _calculateAdjustedCursorOffset(rawCursorOffset, boundingRects); + } + + if (_previousOffset != null) { + deltaPosition = rawCursorOffset - _previousOffset!; + } + + // If the raw cursor offset has gone off an edge, we want to reset the relative + // origin of the dragging when the user drags back into the field. + if (_resetOriginOnLeft && deltaPosition.dx > 0) { + _relativeOrigin = Offset(rawCursorOffset.dx - boundingRects.left, _relativeOrigin.dy); + _resetOriginOnLeft = false; + } else if (_resetOriginOnRight && deltaPosition.dx < 0) { + _relativeOrigin = Offset(rawCursorOffset.dx - boundingRects.right, _relativeOrigin.dy); + _resetOriginOnRight = false; + } + if (_resetOriginOnTop && deltaPosition.dy > 0) { + _relativeOrigin = Offset(_relativeOrigin.dx, rawCursorOffset.dy - boundingRects.top); + _resetOriginOnTop = false; + } else if (_resetOriginOnBottom && deltaPosition.dy < 0) { + _relativeOrigin = Offset(_relativeOrigin.dx, rawCursorOffset.dy - boundingRects.bottom); + _resetOriginOnBottom = false; + } + + final double currentX = rawCursorOffset.dx - _relativeOrigin.dx; + final double currentY = rawCursorOffset.dy - _relativeOrigin.dy; + final Offset adjustedOffset = _calculateAdjustedCursorOffset(Offset(currentX, currentY), boundingRects); + + if (currentX < boundingRects.left && deltaPosition.dx < 0) { + _resetOriginOnLeft = true; + } else if (currentX > boundingRects.right && deltaPosition.dx > 0) { + _resetOriginOnRight = true; + } + if (currentY < boundingRects.top && deltaPosition.dy < 0) { + _resetOriginOnTop = true; + } else if (currentY > boundingRects.bottom && deltaPosition.dy > 0) { + _resetOriginOnBottom = true; + } + + _previousOffset = rawCursorOffset; + + return adjustedOffset; + } + + /// Sets the screen position of the floating cursor and the text position + /// closest to the cursor. + void setFloatingCursor(FloatingCursorDragState state, Offset boundedOffset, TextPosition lastTextPosition, { double? resetLerpValue }) { + if (state == FloatingCursorDragState.End) { + _relativeOrigin = Offset.zero; + _previousOffset = null; + _shouldResetOrigin = true; + _resetOriginOnBottom = false; + _resetOriginOnTop = false; + _resetOriginOnRight = false; + _resetOriginOnBottom = false; + } + _floatingCursorOn = state != FloatingCursorDragState.End; + _resetFloatingCursorAnimationValue = resetLerpValue; + if (_floatingCursorOn) { + _floatingCursorTextPosition = lastTextPosition; + final double? animationValue = _resetFloatingCursorAnimationValue; + final EdgeInsets sizeAdjustment = animationValue != null + ? EdgeInsets.lerp(_kFloatingCursorSizeIncrease, EdgeInsets.zero, animationValue)! + : _kFloatingCursorSizeIncrease; + _caretPainter.floatingCursorRect = sizeAdjustment.inflateRect(_caretPrototype).shift(boundedOffset); + } else { + _caretPainter.floatingCursorRect = null; + } + _caretPainter.showRegularCaret = _resetFloatingCursorAnimationValue == null; + } + + MapEntry<int, Offset> _lineNumberFor(TextPosition startPosition, List<ui.LineMetrics> metrics) { + // TODO(LongCatIsLooong): include line boundaries information in + // ui.LineMetrics, then we can get rid of this. + final Offset offset = _textPainter.getOffsetForCaret(startPosition, Rect.zero); + for (final ui.LineMetrics lineMetrics in metrics) { + if (lineMetrics.baseline > offset.dy) { + return MapEntry<int, Offset>(lineMetrics.lineNumber, Offset(offset.dx, lineMetrics.baseline)); + } + } + assert(startPosition.offset == 0, 'unable to find the line for $startPosition'); + return MapEntry<int, Offset>( + math.max(0, metrics.length - 1), + Offset(offset.dx, metrics.isNotEmpty ? metrics.last.baseline + metrics.last.descent : 0.0), + ); + } + + /// Starts a [VerticalCaretMovementRun] at the given location in the text, for + /// handling consecutive vertical caret movements. + /// + /// This can be used to handle consecutive upward/downward arrow key movements + /// in an input field. + /// + /// {@macro flutter.rendering.RenderEditable.verticalArrowKeyMovement} + /// + /// The [VerticalCaretMovementRun.isValid] property indicates whether the text + /// layout has changed and the vertical caret run is invalidated. + /// + /// The caller should typically discard a [VerticalCaretMovementRun] when + /// its [VerticalCaretMovementRun.isValid] becomes false, or on other + /// occasions where the vertical caret run should be interrupted. + VerticalCaretMovementRun startVerticalCaretMovement(TextPosition startPosition) { + final List<ui.LineMetrics> metrics = _textPainter.computeLineMetrics(); + final MapEntry<int, Offset> currentLine = _lineNumberFor(startPosition, metrics); + return VerticalCaretMovementRun._( + this, + metrics, + startPosition, + currentLine.key, + currentLine.value, + ); + } + + void _paintContents(PaintingContext context, Offset offset) { + debugAssertLayoutUpToDate(); + final Offset effectiveOffset = offset + _paintOffset; + + if (selection != null && !_floatingCursorOn) { + _updateSelectionExtentsVisibility(effectiveOffset); + } + + final RenderBox? foregroundChild = _foregroundRenderObject; + final RenderBox? backgroundChild = _backgroundRenderObject; + + // The painters paint in the viewport's coordinate space, since the + // textPainter's coordinate space is not known to high level widgets. + if (backgroundChild != null) { + context.paintChild(backgroundChild, offset); + } + + _textPainter.paint(context.canvas, effectiveOffset); + paintInlineChildren(context, effectiveOffset); + + if (foregroundChild != null) { + context.paintChild(foregroundChild, offset); + } + } + + final LayerHandle<LeaderLayer> _leaderLayerHandler = LayerHandle<LeaderLayer>(); + + void _paintHandleLayers(PaintingContext context, List<TextSelectionPoint> endpoints, Offset offset) { + Offset startPoint = endpoints[0].point; + startPoint = Offset( + clampDouble(startPoint.dx, 0.0, size.width), + clampDouble(startPoint.dy, 0.0, size.height), + ); + _leaderLayerHandler.layer = LeaderLayer(link: startHandleLayerLink, offset: startPoint + offset); + context.pushLayer( + _leaderLayerHandler.layer!, + super.paint, + Offset.zero, + ); + if (endpoints.length == 2) { + Offset endPoint = endpoints[1].point; + endPoint = Offset( + clampDouble(endPoint.dx, 0.0, size.width), + clampDouble(endPoint.dy, 0.0, size.height), + ); + context.pushLayer( + LeaderLayer(link: endHandleLayerLink, offset: endPoint + offset), + super.paint, + Offset.zero, + ); + } + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + if (child == _foregroundRenderObject || child == _backgroundRenderObject) { + return; + } + defaultApplyPaintTransform(child, transform); + } + + @override + void paint(PaintingContext context, Offset offset) { + _computeTextMetricsIfNeeded(); + if (_hasVisualOverflow && clipBehavior != Clip.none) { + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + _paintContents, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + } else { + _clipRectLayer.layer = null; + _paintContents(context, offset); + } + final TextSelection? selection = this.selection; + if (selection != null && selection.isValid) { + _paintHandleLayers(context, getEndpointsForSelection(selection), offset); + } + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + Rect? describeApproximatePaintClip(RenderObject child) { + switch (clipBehavior) { + case Clip.none: + return null; + case Clip.hardEdge: + case Clip.antiAlias: + case Clip.antiAliasWithSaveLayer: + return _hasVisualOverflow ? Offset.zero & size : null; + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('cursorColor', cursorColor)); + properties.add(DiagnosticsProperty<ValueNotifier<bool>>('showCursor', showCursor)); + properties.add(IntProperty('maxLines', maxLines)); + properties.add(IntProperty('minLines', minLines)); + properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false)); + properties.add(ColorProperty('selectionColor', selectionColor)); + properties.add(DiagnosticsProperty<TextScaler>('textScaler', textScaler, defaultValue: TextScaler.noScaling)); + properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null)); + properties.add(DiagnosticsProperty<TextSelection>('selection', selection)); + properties.add(DiagnosticsProperty<ViewportOffset>('offset', offset)); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return <DiagnosticsNode>[ + if (text != null) + text!.toDiagnosticsNode( + name: 'text', + style: DiagnosticsTreeStyle.transition, + ), + ]; + } +} + +class _RenderEditableCustomPaint extends RenderBox { + _RenderEditableCustomPaint({ + RenderEditablePainter? painter, + }) : _painter = painter, + super(); + + @override + RenderEditable? get parent => super.parent as RenderEditable?; + + @override + bool get isRepaintBoundary => true; + + @override + bool get sizedByParent => true; + + RenderEditablePainter? get painter => _painter; + RenderEditablePainter? _painter; + set painter(RenderEditablePainter? newValue) { + if (newValue == painter) { + return; + } + + final RenderEditablePainter? oldPainter = painter; + _painter = newValue; + + if (newValue?.shouldRepaint(oldPainter) ?? true) { + markNeedsPaint(); + } + + if (attached) { + oldPainter?.removeListener(markNeedsPaint); + newValue?.addListener(markNeedsPaint); + } + } + + @override + void paint(PaintingContext context, Offset offset) { + final RenderEditable? parent = this.parent; + assert(parent != null); + final RenderEditablePainter? painter = this.painter; + if (painter != null && parent != null) { + parent._computeTextMetricsIfNeeded(); + painter.paint(context.canvas, size, parent); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _painter?.addListener(markNeedsPaint); + } + + @override + void detach() { + _painter?.removeListener(markNeedsPaint); + super.detach(); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) => constraints.biggest; +} + +/// An interface that paints within a [RenderEditable]'s bounds, above or +/// beneath its text content. +/// +/// This painter is typically used for painting auxiliary content that depends +/// on text layout metrics (for instance, for painting carets and text highlight +/// blocks). It can paint independently from its [RenderEditable], allowing it +/// to repaint without triggering a repaint on the entire [RenderEditable] stack +/// when only auxiliary content changes (e.g. a blinking cursor) are present. It +/// will be scheduled to repaint when: +/// +/// * It's assigned to a new [RenderEditable] (replacing a prior +/// [RenderEditablePainter]) and the [shouldRepaint] method returns true. +/// * Any of the [RenderEditable]s it is attached to repaints. +/// * The [notifyListeners] method is called, which typically happens when the +/// painter's attributes change. +/// +/// See also: +/// +/// * [RenderEditable.foregroundPainter], which takes a [RenderEditablePainter] +/// and sets it as the foreground painter of the [RenderEditable]. +/// * [RenderEditable.painter], which takes a [RenderEditablePainter] +/// and sets it as the background painter of the [RenderEditable]. +/// * [CustomPainter], a similar class which paints within a [RenderCustomPaint]. +abstract class RenderEditablePainter extends ChangeNotifier { + /// Determines whether repaint is needed when a new [RenderEditablePainter] + /// is provided to a [RenderEditable]. + /// + /// If the new instance represents different information than the old + /// instance, then the method should return true, otherwise it should return + /// false. When [oldDelegate] is null, this method should always return true + /// unless the new painter initially does not paint anything. + /// + /// If the method returns false, then the [paint] call might be optimized + /// away. However, the [paint] method will get called whenever the + /// [RenderEditable]s it attaches to repaint, even if [shouldRepaint] returns + /// false. + bool shouldRepaint(RenderEditablePainter? oldDelegate); + + /// Paints within the bounds of a [RenderEditable]. + /// + /// The given [Canvas] has the same coordinate space as the [RenderEditable], + /// which may be different from the coordinate space the [RenderEditable]'s + /// [TextPainter] uses, when the text moves inside the [RenderEditable]. + /// + /// Paint operations performed outside of the region defined by the [canvas]'s + /// origin and the [size] parameter may get clipped, when [RenderEditable]'s + /// [RenderEditable.clipBehavior] is not [Clip.none]. + void paint(Canvas canvas, Size size, RenderEditable renderEditable); +} + +class _TextHighlightPainter extends RenderEditablePainter { + _TextHighlightPainter({ + TextRange? highlightedRange, + Color? highlightColor, + }) : _highlightedRange = highlightedRange, + _highlightColor = highlightColor; + + final Paint highlightPaint = Paint(); + + Color? get highlightColor => _highlightColor; + Color? _highlightColor; + set highlightColor(Color? newValue) { + if (newValue == _highlightColor) { + return; + } + _highlightColor = newValue; + notifyListeners(); + } + + TextRange? get highlightedRange => _highlightedRange; + TextRange? _highlightedRange; + set highlightedRange(TextRange? newValue) { + if (newValue == _highlightedRange) { + return; + } + _highlightedRange = newValue; + notifyListeners(); + } + + /// Controls how tall the selection highlight boxes are computed to be. + /// + /// See [ui.BoxHeightStyle] for details on available styles. + ui.BoxHeightStyle get selectionHeightStyle => _selectionHeightStyle; + ui.BoxHeightStyle _selectionHeightStyle = ui.BoxHeightStyle.tight; + set selectionHeightStyle(ui.BoxHeightStyle value) { + if (_selectionHeightStyle == value) { + return; + } + _selectionHeightStyle = value; + notifyListeners(); + } + + /// Controls how wide the selection highlight boxes are computed to be. + /// + /// See [ui.BoxWidthStyle] for details on available styles. + ui.BoxWidthStyle get selectionWidthStyle => _selectionWidthStyle; + ui.BoxWidthStyle _selectionWidthStyle = ui.BoxWidthStyle.tight; + set selectionWidthStyle(ui.BoxWidthStyle value) { + if (_selectionWidthStyle == value) { + return; + } + _selectionWidthStyle = value; + notifyListeners(); + } + + @override + void paint(Canvas canvas, Size size, RenderEditable renderEditable) { + final TextRange? range = highlightedRange; + final Color? color = highlightColor; + if (range == null || color == null || range.isCollapsed) { + return; + } + + highlightPaint.color = color; + final TextPainter textPainter = renderEditable._textPainter; + final List<TextBox> boxes = textPainter.getBoxesForSelection( + TextSelection(baseOffset: range.start, extentOffset: range.end), + boxHeightStyle: selectionHeightStyle, + boxWidthStyle: selectionWidthStyle, + ); + + for (final TextBox box in boxes) { + canvas.drawRect( + box.toRect().shift(renderEditable._paintOffset) + .intersect(Rect.fromLTWH(0, 0, textPainter.width, textPainter.height)), + highlightPaint, + ); + } + } + + @override + bool shouldRepaint(RenderEditablePainter? oldDelegate) { + if (identical(oldDelegate, this)) { + return false; + } + if (oldDelegate == null) { + return highlightColor != null && highlightedRange != null; + } + return oldDelegate is! _TextHighlightPainter + || oldDelegate.highlightColor != highlightColor + || oldDelegate.highlightedRange != highlightedRange + || oldDelegate.selectionHeightStyle != selectionHeightStyle + || oldDelegate.selectionWidthStyle != selectionWidthStyle; + } +} + +class _CaretPainter extends RenderEditablePainter { + _CaretPainter(); + + bool get shouldPaint => _shouldPaint; + bool _shouldPaint = true; + set shouldPaint(bool value) { + if (shouldPaint == value) { + return; + } + _shouldPaint = value; + notifyListeners(); + } + + // This is directly manipulated by the RenderEditable during + // setFloatingCursor. + // + // When changing this value, the caller is responsible for ensuring that + // listeners are notified. + bool showRegularCaret = false; + + final Paint caretPaint = Paint(); + late final Paint floatingCursorPaint = Paint(); + + Color? get caretColor => _caretColor; + Color? _caretColor; + set caretColor(Color? value) { + if (caretColor?.value == value?.value) { + return; + } + + _caretColor = value; + notifyListeners(); + } + + Radius? get cursorRadius => _cursorRadius; + Radius? _cursorRadius; + set cursorRadius(Radius? value) { + if (_cursorRadius == value) { + return; + } + _cursorRadius = value; + notifyListeners(); + } + + Offset get cursorOffset => _cursorOffset; + Offset _cursorOffset = Offset.zero; + set cursorOffset(Offset value) { + if (_cursorOffset == value) { + return; + } + _cursorOffset = value; + notifyListeners(); + } + + Color? get backgroundCursorColor => _backgroundCursorColor; + Color? _backgroundCursorColor; + set backgroundCursorColor(Color? value) { + if (backgroundCursorColor?.value == value?.value) { + return; + } + + _backgroundCursorColor = value; + if (showRegularCaret) { + notifyListeners(); + } + } + + Rect? get floatingCursorRect => _floatingCursorRect; + Rect? _floatingCursorRect; + set floatingCursorRect(Rect? value) { + if (_floatingCursorRect == value) { + return; + } + _floatingCursorRect = value; + notifyListeners(); + } + + void paintRegularCursor(Canvas canvas, RenderEditable renderEditable, Color caretColor, TextPosition textPosition) { + final Rect integralRect = renderEditable.getLocalRectForCaret(textPosition); + if (shouldPaint) { + if (floatingCursorRect != null) { + final double distanceSquared = (floatingCursorRect!.center - integralRect.center).distanceSquared; + if (distanceSquared < _kShortestDistanceSquaredWithFloatingAndRegularCursors) { + return; + } + } + final Radius? radius = cursorRadius; + caretPaint.color = caretColor; + if (radius == null) { + canvas.drawRect(integralRect, caretPaint); + } else { + final RRect caretRRect = RRect.fromRectAndRadius(integralRect, radius); + canvas.drawRRect(caretRRect, caretPaint); + } + } + } + + @override + void paint(Canvas canvas, Size size, RenderEditable renderEditable) { + // Compute the caret location even when `shouldPaint` is false. + + final TextSelection? selection = renderEditable.selection; + + // TODO(LongCatIsLooong): skip painting caret when selection is (-1, -1): https://github.com/flutter/flutter/issues/79495 + if (selection == null || !selection.isCollapsed) { + return; + } + + final Rect? floatingCursorRect = this.floatingCursorRect; + + final Color? caretColor = floatingCursorRect == null + ? this.caretColor + : showRegularCaret ? backgroundCursorColor : null; + final TextPosition caretTextPosition = floatingCursorRect == null + ? selection.extent + : renderEditable._floatingCursorTextPosition; + + if (caretColor != null) { + paintRegularCursor(canvas, renderEditable, caretColor, caretTextPosition); + } + + final Color? floatingCursorColor = this.caretColor?.withOpacity(0.75); + // Floating Cursor. + if (floatingCursorRect == null || floatingCursorColor == null || !shouldPaint) { + return; + } + + canvas.drawRRect( + RRect.fromRectAndRadius(floatingCursorRect, _kFloatingCursorRadius), + floatingCursorPaint..color = floatingCursorColor, + ); + } + + @override + bool shouldRepaint(RenderEditablePainter? oldDelegate) { + if (identical(this, oldDelegate)) { + return false; + } + + if (oldDelegate == null) { + return shouldPaint; + } + return oldDelegate is! _CaretPainter + || oldDelegate.shouldPaint != shouldPaint + || oldDelegate.showRegularCaret != showRegularCaret + || oldDelegate.caretColor != caretColor + || oldDelegate.cursorRadius != cursorRadius + || oldDelegate.cursorOffset != cursorOffset + || oldDelegate.backgroundCursorColor != backgroundCursorColor + || oldDelegate.floatingCursorRect != floatingCursorRect; + } +} + +class _CompositeRenderEditablePainter extends RenderEditablePainter { + _CompositeRenderEditablePainter({ required this.painters }); + + final List<RenderEditablePainter> painters; + + @override + void addListener(VoidCallback listener) { + for (final RenderEditablePainter painter in painters) { + painter.addListener(listener); + } + } + + @override + void removeListener(VoidCallback listener) { + for (final RenderEditablePainter painter in painters) { + painter.removeListener(listener); + } + } + + @override + void paint(Canvas canvas, Size size, RenderEditable renderEditable) { + for (final RenderEditablePainter painter in painters) { + painter.paint(canvas, size, renderEditable); + } + } + + @override + bool shouldRepaint(RenderEditablePainter? oldDelegate) { + if (identical(oldDelegate, this)) { + return false; + } + if (oldDelegate is! _CompositeRenderEditablePainter || oldDelegate.painters.length != painters.length) { + return true; + } + + final Iterator<RenderEditablePainter> oldPainters = oldDelegate.painters.iterator; + final Iterator<RenderEditablePainter> newPainters = painters.iterator; + while (oldPainters.moveNext() && newPainters.moveNext()) { + if (newPainters.current.shouldRepaint(oldPainters.current)) { + return true; + } + } + + return false; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/error.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/error.dart new file mode 100644 index 0000000000000000000000000000000000000000..e9be76f231bf7c2db571aecb1030aa6b8c48afd7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/error.dart @@ -0,0 +1,175 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle, TextStyle; + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'object.dart'; + +const double _kMaxWidth = 100000.0; +const double _kMaxHeight = 100000.0; + +/// A render object used as a placeholder when an error occurs. +/// +/// The box will be painted in the color given by the +/// [RenderErrorBox.backgroundColor] static property. +/// +/// A message can be provided. To simplify the class and thus help reduce the +/// likelihood of this class itself being the source of errors, the message +/// cannot be changed once the object has been created. If provided, the text +/// will be painted on top of the background, using the styles given by the +/// [RenderErrorBox.textStyle] and [RenderErrorBox.paragraphStyle] static +/// properties. +/// +/// Again to help simplify the class, if the parent has left the constraints +/// unbounded, this box tries to be 100000.0 pixels wide and high, to +/// approximate being infinitely high but without using infinities. +class RenderErrorBox extends RenderBox { + /// Creates a RenderErrorBox render object. + /// + /// A message can optionally be provided. If a message is provided, an attempt + /// will be made to render the message when the box paints. + RenderErrorBox([ this.message = '' ]) { + try { + if (message != '') { + // This class is intentionally doing things using the low-level + // primitives to avoid depending on any subsystems that may have ended + // up in an unstable state -- after all, this class is mainly used when + // things have gone wrong. + // + // Generally, the much better way to draw text in a RenderObject is to + // use the TextPainter class. If you're looking for code to crib from, + // see the paragraph.dart file and the RenderParagraph class. + final ui.ParagraphBuilder builder = ui.ParagraphBuilder(paragraphStyle); + builder.pushStyle(textStyle); + builder.addText(message); + _paragraph = builder.build(); + } else { + _paragraph = null; + } + } catch (error) { + // If an error happens here we're in a terrible state, so we really should + // just forget about it and let the developer deal with the already-reported + // errors. It's unlikely that these errors are going to help with that. + } + } + + /// The message to attempt to display at paint time. + final String message; + + late final ui.Paragraph? _paragraph; + + @override + double computeMaxIntrinsicWidth(double height) { + return _kMaxWidth; + } + + @override + double computeMaxIntrinsicHeight(double width) { + return _kMaxHeight; + } + + @override + bool get sizedByParent => true; + + @override + bool hitTestSelf(Offset position) => true; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return constraints.constrain(const Size(_kMaxWidth, _kMaxHeight)); + } + + /// The distance to place around the text. + /// + /// This is intended to ensure that if the [RenderErrorBox] is placed at the top left + /// of the screen, under the system's status bar, the error text is still visible in + /// the area below the status bar. + /// + /// The padding is ignored if the error box is smaller than the padding. + /// + /// See also: + /// + /// * [minimumWidth], which controls how wide the box must be before the + /// horizontal padding is applied. + static EdgeInsets padding = const EdgeInsets.fromLTRB(64.0, 96.0, 64.0, 12.0); + + /// The width below which the horizontal padding is not applied. + /// + /// If the left and right padding would reduce the available width to less than + /// this value, then the text is rendered flush with the left edge. + static double minimumWidth = 200.0; + + /// The color to use when painting the background of [RenderErrorBox] objects. + /// + /// Defaults to red in debug mode, a light gray otherwise. + static Color backgroundColor = _initBackgroundColor(); + + static Color _initBackgroundColor() { + Color result = const Color(0xF0C0C0C0); + assert(() { + result = const Color(0xF0900000); + return true; + }()); + return result; + } + + /// The text style to use when painting [RenderErrorBox] objects. + /// + /// Defaults to a yellow monospace font in debug mode, and a dark gray + /// sans-serif font otherwise. + static ui.TextStyle textStyle = _initTextStyle(); + + static ui.TextStyle _initTextStyle() { + ui.TextStyle result = ui.TextStyle( + color: const Color(0xFF303030), + fontFamily: 'sans-serif', + fontSize: 18.0, + ); + assert(() { + result = ui.TextStyle( + color: const Color(0xFFFFFF66), + fontFamily: 'monospace', + fontSize: 14.0, + fontWeight: FontWeight.bold, + ); + return true; + }()); + return result; + } + + /// The paragraph style to use when painting [RenderErrorBox] objects. + static ui.ParagraphStyle paragraphStyle = ui.ParagraphStyle( + textDirection: TextDirection.ltr, + textAlign: TextAlign.left, + ); + + @override + void paint(PaintingContext context, Offset offset) { + try { + context.canvas.drawRect(offset & size, Paint() .. color = backgroundColor); + if (_paragraph != null) { + double width = size.width; + double left = 0.0; + double top = 0.0; + if (width > padding.left + minimumWidth + padding.right) { + width -= padding.left + padding.right; + left += padding.left; + } + _paragraph.layout(ui.ParagraphConstraints(width: width)); + if (size.height > padding.top + _paragraph.height + padding.bottom) { + top += padding.top; + } + context.canvas.drawParagraph(_paragraph, offset + Offset(left, top)); + } + } catch (error) { + // If an error happens here we're in a terrible state, so we really should + // just forget about it and let the developer deal with the already-reported + // errors. It's unlikely that these errors are going to help with that. + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/flex.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/flex.dart new file mode 100644 index 0000000000000000000000000000000000000000..9c6887ee3899486c5eff6b803a0e29a2e3077ad5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/flex.dart @@ -0,0 +1,1153 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'debug_overflow_indicator.dart'; +import 'layer.dart'; +import 'layout_helper.dart'; +import 'object.dart'; + +/// How the child is inscribed into the available space. +/// +/// See also: +/// +/// * [RenderFlex], the flex render object. +/// * [Column], [Row], and [Flex], the flex widgets. +/// * [Expanded], the widget equivalent of [tight]. +/// * [Flexible], the widget equivalent of [loose]. +enum FlexFit { + /// The child is forced to fill the available space. + /// + /// The [Expanded] widget assigns this kind of [FlexFit] to its child. + tight, + + /// The child can be at most as large as the available space (but is + /// allowed to be smaller). + /// + /// The [Flexible] widget assigns this kind of [FlexFit] to its child. + loose, +} + +/// Parent data for use with [RenderFlex]. +class FlexParentData extends ContainerBoxParentData<RenderBox> { + /// The flex factor to use for this child. + /// + /// If null or zero, the child is inflexible and determines its own size. If + /// non-zero, the amount of space the child's can occupy in the main axis is + /// determined by dividing the free space (after placing the inflexible + /// children) according to the flex factors of the flexible children. + int? flex; + + /// How a flexible child is inscribed into the available space. + /// + /// If [flex] is non-zero, the [fit] determines whether the child fills the + /// space the parent makes available during layout. If the fit is + /// [FlexFit.tight], the child is required to fill the available space. If the + /// fit is [FlexFit.loose], the child can be at most as large as the available + /// space (but is allowed to be smaller). + FlexFit? fit; + + @override + String toString() => '${super.toString()}; flex=$flex; fit=$fit'; +} + +/// How much space should be occupied in the main axis. +/// +/// During a flex layout, available space along the main axis is allocated to +/// children. After allocating space, there might be some remaining free space. +/// This value controls whether to maximize or minimize the amount of free +/// space, subject to the incoming layout constraints. +/// +/// See also: +/// +/// * [Column], [Row], and [Flex], the flex widgets. +/// * [Expanded] and [Flexible], the widgets that controls a flex widgets' +/// children's flex. +/// * [RenderFlex], the flex render object. +/// * [MainAxisAlignment], which controls how the free space is distributed. +enum MainAxisSize { + /// Minimize the amount of free space along the main axis, subject to the + /// incoming layout constraints. + /// + /// If the incoming layout constraints have a large enough + /// [BoxConstraints.minWidth] or [BoxConstraints.minHeight], there might still + /// be a non-zero amount of free space. + /// + /// If the incoming layout constraints are unbounded, and any children have a + /// non-zero [FlexParentData.flex] and a [FlexFit.tight] fit (as applied by + /// [Expanded]), the [RenderFlex] will assert, because there would be infinite + /// remaining free space and boxes cannot be given infinite size. + min, + + /// Maximize the amount of free space along the main axis, subject to the + /// incoming layout constraints. + /// + /// If the incoming layout constraints have a small enough + /// [BoxConstraints.maxWidth] or [BoxConstraints.maxHeight], there might still + /// be no free space. + /// + /// If the incoming layout constraints are unbounded, the [RenderFlex] will + /// assert, because there would be infinite remaining free space and boxes + /// cannot be given infinite size. + max, +} + +/// How the children should be placed along the main axis in a flex layout. +/// +/// See also: +/// +/// * [Column], [Row], and [Flex], the flex widgets. +/// * [RenderFlex], the flex render object. +enum MainAxisAlignment { + /// Place the children as close to the start of the main axis as possible. + /// + /// If this value is used in a horizontal direction, a [TextDirection] must be + /// available to determine if the start is the left or the right. + /// + /// If this value is used in a vertical direction, a [VerticalDirection] must be + /// available to determine if the start is the top or the bottom. + start, + + /// Place the children as close to the end of the main axis as possible. + /// + /// If this value is used in a horizontal direction, a [TextDirection] must be + /// available to determine if the end is the left or the right. + /// + /// If this value is used in a vertical direction, a [VerticalDirection] must be + /// available to determine if the end is the top or the bottom. + end, + + /// Place the children as close to the middle of the main axis as possible. + center, + + /// Place the free space evenly between the children. + spaceBetween, + + /// Place the free space evenly between the children as well as half of that + /// space before and after the first and last child. + spaceAround, + + /// Place the free space evenly between the children as well as before and + /// after the first and last child. + spaceEvenly, +} + +/// How the children should be placed along the cross axis in a flex layout. +/// +/// See also: +/// +/// * [Column], [Row], and [Flex], the flex widgets. +/// * [RenderFlex], the flex render object. +enum CrossAxisAlignment { + /// Place the children with their start edge aligned with the start side of + /// the cross axis. + /// + /// For example, in a column (a flex with a vertical axis) whose + /// [TextDirection] is [TextDirection.ltr], this aligns the left edge of the + /// children along the left edge of the column. + /// + /// If this value is used in a horizontal direction, a [TextDirection] must be + /// available to determine if the start is the left or the right. + /// + /// If this value is used in a vertical direction, a [VerticalDirection] must be + /// available to determine if the start is the top or the bottom. + start, + + /// Place the children as close to the end of the cross axis as possible. + /// + /// For example, in a column (a flex with a vertical axis) whose + /// [TextDirection] is [TextDirection.ltr], this aligns the right edge of the + /// children along the right edge of the column. + /// + /// If this value is used in a horizontal direction, a [TextDirection] must be + /// available to determine if the end is the left or the right. + /// + /// If this value is used in a vertical direction, a [VerticalDirection] must be + /// available to determine if the end is the top or the bottom. + end, + + /// Place the children so that their centers align with the middle of the + /// cross axis. + /// + /// This is the default cross-axis alignment. + center, + + /// Require the children to fill the cross axis. + /// + /// This causes the constraints passed to the children to be tight in the + /// cross axis. + stretch, + + /// Place the children along the cross axis such that their baselines match. + /// + /// Because baselines are always horizontal, this alignment is intended for + /// horizontal main axes. If the main axis is vertical, then this value is + /// treated like [start]. + /// + /// For horizontal main axes, if the minimum height constraint passed to the + /// flex layout exceeds the intrinsic height of the cross axis, children will + /// be aligned as close to the top as they can be while honoring the baseline + /// alignment. In other words, the extra space will be below all the children. + /// + /// Children who report no baseline will be top-aligned. + baseline, +} + +bool? _startIsTopLeft(Axis direction, TextDirection? textDirection, VerticalDirection? verticalDirection) { + // If the relevant value of textDirection or verticalDirection is null, this returns null too. + switch (direction) { + case Axis.horizontal: + switch (textDirection) { + case TextDirection.ltr: + return true; + case TextDirection.rtl: + return false; + case null: + return null; + } + case Axis.vertical: + switch (verticalDirection) { + case VerticalDirection.down: + return true; + case VerticalDirection.up: + return false; + case null: + return null; + } + } +} + +typedef _ChildSizingFunction = double Function(RenderBox child, double extent); + +/// Displays its children in a one-dimensional array. +/// +/// ## Layout algorithm +/// +/// _This section describes how the framework causes [RenderFlex] to position +/// its children._ +/// _See [BoxConstraints] for an introduction to box layout models._ +/// +/// Layout for a [RenderFlex] proceeds in six steps: +/// +/// 1. Layout each child with a null or zero flex factor with unbounded main +/// axis constraints and the incoming cross axis constraints. If the +/// [crossAxisAlignment] is [CrossAxisAlignment.stretch], instead use tight +/// cross axis constraints that match the incoming max extent in the cross +/// axis. +/// 2. Divide the remaining main axis space among the children with non-zero +/// flex factors according to their flex factor. For example, a child with a +/// flex factor of 2.0 will receive twice the amount of main axis space as a +/// child with a flex factor of 1.0. +/// 3. Layout each of the remaining children with the same cross axis +/// constraints as in step 1, but instead of using unbounded main axis +/// constraints, use max axis constraints based on the amount of space +/// allocated in step 2. Children with [Flexible.fit] properties that are +/// [FlexFit.tight] are given tight constraints (i.e., forced to fill the +/// allocated space), and children with [Flexible.fit] properties that are +/// [FlexFit.loose] are given loose constraints (i.e., not forced to fill the +/// allocated space). +/// 4. The cross axis extent of the [RenderFlex] is the maximum cross axis +/// extent of the children (which will always satisfy the incoming +/// constraints). +/// 5. The main axis extent of the [RenderFlex] is determined by the +/// [mainAxisSize] property. If the [mainAxisSize] property is +/// [MainAxisSize.max], then the main axis extent of the [RenderFlex] is the +/// max extent of the incoming main axis constraints. If the [mainAxisSize] +/// property is [MainAxisSize.min], then the main axis extent of the [Flex] +/// is the sum of the main axis extents of the children (subject to the +/// incoming constraints). +/// 6. Determine the position for each child according to the +/// [mainAxisAlignment] and the [crossAxisAlignment]. For example, if the +/// [mainAxisAlignment] is [MainAxisAlignment.spaceBetween], any main axis +/// space that has not been allocated to children is divided evenly and +/// placed between the children. +/// +/// See also: +/// +/// * [Flex], the widget equivalent. +/// * [Row] and [Column], direction-specific variants of [Flex]. +class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, FlexParentData>, + RenderBoxContainerDefaultsMixin<RenderBox, FlexParentData>, + DebugOverflowIndicatorMixin { + /// Creates a flex render object. + /// + /// By default, the flex layout is horizontal and children are aligned to the + /// start of the main axis and the center of the cross axis. + RenderFlex({ + List<RenderBox>? children, + Axis direction = Axis.horizontal, + MainAxisSize mainAxisSize = MainAxisSize.max, + MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start, + CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center, + TextDirection? textDirection, + VerticalDirection verticalDirection = VerticalDirection.down, + TextBaseline? textBaseline, + Clip clipBehavior = Clip.none, + }) : _direction = direction, + _mainAxisAlignment = mainAxisAlignment, + _mainAxisSize = mainAxisSize, + _crossAxisAlignment = crossAxisAlignment, + _textDirection = textDirection, + _verticalDirection = verticalDirection, + _textBaseline = textBaseline, + _clipBehavior = clipBehavior { + addAll(children); + } + + /// The direction to use as the main axis. + Axis get direction => _direction; + Axis _direction; + set direction(Axis value) { + if (_direction != value) { + _direction = value; + markNeedsLayout(); + } + } + + /// How the children should be placed along the main axis. + /// + /// If the [direction] is [Axis.horizontal], and the [mainAxisAlignment] is + /// either [MainAxisAlignment.start] or [MainAxisAlignment.end], then the + /// [textDirection] must not be null. + /// + /// If the [direction] is [Axis.vertical], and the [mainAxisAlignment] is + /// either [MainAxisAlignment.start] or [MainAxisAlignment.end], then the + /// [verticalDirection] must not be null. + MainAxisAlignment get mainAxisAlignment => _mainAxisAlignment; + MainAxisAlignment _mainAxisAlignment; + set mainAxisAlignment(MainAxisAlignment value) { + if (_mainAxisAlignment != value) { + _mainAxisAlignment = value; + markNeedsLayout(); + } + } + + /// How much space should be occupied in the main axis. + /// + /// After allocating space to children, there might be some remaining free + /// space. This value controls whether to maximize or minimize the amount of + /// free space, subject to the incoming layout constraints. + /// + /// If some children have a non-zero flex factors (and none have a fit of + /// [FlexFit.loose]), they will expand to consume all the available space and + /// there will be no remaining free space to maximize or minimize, making this + /// value irrelevant to the final layout. + MainAxisSize get mainAxisSize => _mainAxisSize; + MainAxisSize _mainAxisSize; + set mainAxisSize(MainAxisSize value) { + if (_mainAxisSize != value) { + _mainAxisSize = value; + markNeedsLayout(); + } + } + + /// How the children should be placed along the cross axis. + /// + /// If the [direction] is [Axis.horizontal], and the [crossAxisAlignment] is + /// either [CrossAxisAlignment.start] or [CrossAxisAlignment.end], then the + /// [verticalDirection] must not be null. + /// + /// If the [direction] is [Axis.vertical], and the [crossAxisAlignment] is + /// either [CrossAxisAlignment.start] or [CrossAxisAlignment.end], then the + /// [textDirection] must not be null. + CrossAxisAlignment get crossAxisAlignment => _crossAxisAlignment; + CrossAxisAlignment _crossAxisAlignment; + set crossAxisAlignment(CrossAxisAlignment value) { + if (_crossAxisAlignment != value) { + _crossAxisAlignment = value; + markNeedsLayout(); + } + } + + /// Determines the order to lay children out horizontally and how to interpret + /// `start` and `end` in the horizontal direction. + /// + /// If the [direction] is [Axis.horizontal], this controls the order in which + /// children are positioned (left-to-right or right-to-left), and the meaning + /// of the [mainAxisAlignment] property's [MainAxisAlignment.start] and + /// [MainAxisAlignment.end] values. + /// + /// If the [direction] is [Axis.horizontal], and either the + /// [mainAxisAlignment] is either [MainAxisAlignment.start] or + /// [MainAxisAlignment.end], or there's more than one child, then the + /// [textDirection] must not be null. + /// + /// If the [direction] is [Axis.vertical], this controls the meaning of the + /// [crossAxisAlignment] property's [CrossAxisAlignment.start] and + /// [CrossAxisAlignment.end] values. + /// + /// If the [direction] is [Axis.vertical], and the [crossAxisAlignment] is + /// either [CrossAxisAlignment.start] or [CrossAxisAlignment.end], then the + /// [textDirection] must not be null. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection != value) { + _textDirection = value; + markNeedsLayout(); + } + } + + /// Determines the order to lay children out vertically and how to interpret + /// `start` and `end` in the vertical direction. + /// + /// If the [direction] is [Axis.vertical], this controls which order children + /// are painted in (down or up), the meaning of the [mainAxisAlignment] + /// property's [MainAxisAlignment.start] and [MainAxisAlignment.end] values. + /// + /// If the [direction] is [Axis.vertical], and either the [mainAxisAlignment] + /// is either [MainAxisAlignment.start] or [MainAxisAlignment.end], or there's + /// more than one child, then the [verticalDirection] must not be null. + /// + /// If the [direction] is [Axis.horizontal], this controls the meaning of the + /// [crossAxisAlignment] property's [CrossAxisAlignment.start] and + /// [CrossAxisAlignment.end] values. + /// + /// If the [direction] is [Axis.horizontal], and the [crossAxisAlignment] is + /// either [CrossAxisAlignment.start] or [CrossAxisAlignment.end], then the + /// [verticalDirection] must not be null. + VerticalDirection get verticalDirection => _verticalDirection; + VerticalDirection _verticalDirection; + set verticalDirection(VerticalDirection value) { + if (_verticalDirection != value) { + _verticalDirection = value; + markNeedsLayout(); + } + } + + /// If aligning items according to their baseline, which baseline to use. + /// + /// Must not be null if [crossAxisAlignment] is [CrossAxisAlignment.baseline]. + TextBaseline? get textBaseline => _textBaseline; + TextBaseline? _textBaseline; + set textBaseline(TextBaseline? value) { + assert(_crossAxisAlignment != CrossAxisAlignment.baseline || value != null); + if (_textBaseline != value) { + _textBaseline = value; + markNeedsLayout(); + } + } + + bool get _debugHasNecessaryDirections { + if (firstChild != null && lastChild != firstChild) { + // i.e. there's more than one child + switch (direction) { + case Axis.horizontal: + assert(textDirection != null, 'Horizontal $runtimeType with multiple children has a null textDirection, so the layout order is undefined.'); + case Axis.vertical: + break; + } + } + if (mainAxisAlignment == MainAxisAlignment.start || + mainAxisAlignment == MainAxisAlignment.end) { + switch (direction) { + case Axis.horizontal: + assert(textDirection != null, 'Horizontal $runtimeType with $mainAxisAlignment has a null textDirection, so the alignment cannot be resolved.'); + case Axis.vertical: + break; + } + } + if (crossAxisAlignment == CrossAxisAlignment.start || + crossAxisAlignment == CrossAxisAlignment.end) { + switch (direction) { + case Axis.horizontal: + break; + case Axis.vertical: + assert(textDirection != null, 'Vertical $runtimeType with $crossAxisAlignment has a null textDirection, so the alignment cannot be resolved.'); + } + } + return true; + } + + // Set during layout if overflow occurred on the main axis. + double _overflow = 0; + // Check whether any meaningful overflow is present. Values below an epsilon + // are treated as not overflowing. + bool get _hasOverflow => _overflow > precisionErrorTolerance; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.none; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! FlexParentData) { + child.parentData = FlexParentData(); + } + } + + bool get _canComputeIntrinsics => crossAxisAlignment != CrossAxisAlignment.baseline; + + double _getIntrinsicSize({ + required Axis sizingDirection, + required double extent, // the extent in the direction that isn't the sizing direction + required _ChildSizingFunction childSize, // a method to find the size in the sizing direction + }) { + if (!_canComputeIntrinsics) { + // Intrinsics cannot be calculated without a full layout for + // baseline alignment. Throw an assertion and return 0.0 as documented + // on [RenderBox.computeMinIntrinsicWidth]. + assert( + RenderObject.debugCheckingIntrinsics, + 'Intrinsics are not available for CrossAxisAlignment.baseline.', + ); + return 0.0; + } + if (_direction == sizingDirection) { + // INTRINSIC MAIN SIZE + // Intrinsic main size is the smallest size the flex container can take + // while maintaining the min/max-content contributions of its flex items. + double totalFlex = 0.0; + double inflexibleSpace = 0.0; + double maxFlexFractionSoFar = 0.0; + RenderBox? child = firstChild; + while (child != null) { + final int flex = _getFlex(child); + totalFlex += flex; + if (flex > 0) { + final double flexFraction = childSize(child, extent) / _getFlex(child); + maxFlexFractionSoFar = math.max(maxFlexFractionSoFar, flexFraction); + } else { + inflexibleSpace += childSize(child, extent); + } + final FlexParentData childParentData = child.parentData! as FlexParentData; + child = childParentData.nextSibling; + } + return maxFlexFractionSoFar * totalFlex + inflexibleSpace; + } else { + // INTRINSIC CROSS SIZE + // Intrinsic cross size is the max of the intrinsic cross sizes of the + // children, after the flexible children are fit into the available space, + // with the children sized using their max intrinsic dimensions. + + // Get inflexible space using the max intrinsic dimensions of fixed children in the main direction. + final double availableMainSpace = extent; + int totalFlex = 0; + double inflexibleSpace = 0.0; + double maxCrossSize = 0.0; + RenderBox? child = firstChild; + while (child != null) { + final int flex = _getFlex(child); + totalFlex += flex; + late final double mainSize; + late final double crossSize; + if (flex == 0) { + switch (_direction) { + case Axis.horizontal: + mainSize = child.getMaxIntrinsicWidth(double.infinity); + crossSize = childSize(child, mainSize); + case Axis.vertical: + mainSize = child.getMaxIntrinsicHeight(double.infinity); + crossSize = childSize(child, mainSize); + } + inflexibleSpace += mainSize; + maxCrossSize = math.max(maxCrossSize, crossSize); + } + final FlexParentData childParentData = child.parentData! as FlexParentData; + child = childParentData.nextSibling; + } + + // Determine the spacePerFlex by allocating the remaining available space. + // When you're overconstrained spacePerFlex can be negative. + final double spacePerFlex = math.max(0.0, (availableMainSpace - inflexibleSpace) / totalFlex); + + // Size remaining (flexible) items, find the maximum cross size. + child = firstChild; + while (child != null) { + final int flex = _getFlex(child); + if (flex > 0) { + maxCrossSize = math.max(maxCrossSize, childSize(child, spacePerFlex * flex)); + } + final FlexParentData childParentData = child.parentData! as FlexParentData; + child = childParentData.nextSibling; + } + + return maxCrossSize; + } + } + + @override + double computeMinIntrinsicWidth(double height) { + return _getIntrinsicSize( + sizingDirection: Axis.horizontal, + extent: height, + childSize: (RenderBox child, double extent) => child.getMinIntrinsicWidth(extent), + ); + } + + @override + double computeMaxIntrinsicWidth(double height) { + return _getIntrinsicSize( + sizingDirection: Axis.horizontal, + extent: height, + childSize: (RenderBox child, double extent) => child.getMaxIntrinsicWidth(extent), + ); + } + + @override + double computeMinIntrinsicHeight(double width) { + return _getIntrinsicSize( + sizingDirection: Axis.vertical, + extent: width, + childSize: (RenderBox child, double extent) => child.getMinIntrinsicHeight(extent), + ); + } + + @override + double computeMaxIntrinsicHeight(double width) { + return _getIntrinsicSize( + sizingDirection: Axis.vertical, + extent: width, + childSize: (RenderBox child, double extent) => child.getMaxIntrinsicHeight(extent), + ); + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + if (_direction == Axis.horizontal) { + return defaultComputeDistanceToHighestActualBaseline(baseline); + } + return defaultComputeDistanceToFirstActualBaseline(baseline); + } + + int _getFlex(RenderBox child) { + final FlexParentData childParentData = child.parentData! as FlexParentData; + return childParentData.flex ?? 0; + } + + FlexFit _getFit(RenderBox child) { + final FlexParentData childParentData = child.parentData! as FlexParentData; + return childParentData.fit ?? FlexFit.tight; + } + + double _getCrossSize(Size size) { + switch (_direction) { + case Axis.horizontal: + return size.height; + case Axis.vertical: + return size.width; + } + } + + double _getMainSize(Size size) { + switch (_direction) { + case Axis.horizontal: + return size.width; + case Axis.vertical: + return size.height; + } + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (!_canComputeIntrinsics) { + assert(debugCannotComputeDryLayout( + reason: 'Dry layout cannot be computed for CrossAxisAlignment.baseline, which requires a full layout.', + )); + return Size.zero; + } + FlutterError? constraintsError; + assert(() { + constraintsError = _debugCheckConstraints( + constraints: constraints, + reportParentConstraints: false, + ); + return true; + }()); + if (constraintsError != null) { + assert(debugCannotComputeDryLayout(error: constraintsError)); + return Size.zero; + } + + final _LayoutSizes sizes = _computeSizes( + layoutChild: ChildLayoutHelper.dryLayoutChild, + constraints: constraints, + ); + + switch (_direction) { + case Axis.horizontal: + return constraints.constrain(Size(sizes.mainSize, sizes.crossSize)); + case Axis.vertical: + return constraints.constrain(Size(sizes.crossSize, sizes.mainSize)); + } + } + + FlutterError? _debugCheckConstraints({required BoxConstraints constraints, required bool reportParentConstraints}) { + FlutterError? result; + assert(() { + final double maxMainSize = _direction == Axis.horizontal ? constraints.maxWidth : constraints.maxHeight; + final bool canFlex = maxMainSize < double.infinity; + RenderBox? child = firstChild; + while (child != null) { + final int flex = _getFlex(child); + if (flex > 0) { + final String identity = _direction == Axis.horizontal ? 'row' : 'column'; + final String axis = _direction == Axis.horizontal ? 'horizontal' : 'vertical'; + final String dimension = _direction == Axis.horizontal ? 'width' : 'height'; + DiagnosticsNode error, message; + final List<DiagnosticsNode> addendum = <DiagnosticsNode>[]; + if (!canFlex && (mainAxisSize == MainAxisSize.max || _getFit(child) == FlexFit.tight)) { + error = ErrorSummary('RenderFlex children have non-zero flex but incoming $dimension constraints are unbounded.'); + message = ErrorDescription( + 'When a $identity is in a parent that does not provide a finite $dimension constraint, for example ' + 'if it is in a $axis scrollable, it will try to shrink-wrap its children along the $axis ' + 'axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to ' + 'expand to fill the remaining space in the $axis direction.', + ); + if (reportParentConstraints) { // Constraints of parents are unavailable in dry layout. + RenderBox? node = this; + switch (_direction) { + case Axis.horizontal: + while (!node!.constraints.hasBoundedWidth && node.parent is RenderBox) { + node = node.parent! as RenderBox; + } + if (!node.constraints.hasBoundedWidth) { + node = null; + } + case Axis.vertical: + while (!node!.constraints.hasBoundedHeight && node.parent is RenderBox) { + node = node.parent! as RenderBox; + } + if (!node.constraints.hasBoundedHeight) { + node = null; + } + } + if (node != null) { + addendum.add(node.describeForError('The nearest ancestor providing an unbounded width constraint is')); + } + } + addendum.add(ErrorHint('See also: https://flutter.dev/unbounded-constraints')); + } else { + return true; + } + result = FlutterError.fromParts(<DiagnosticsNode>[ + error, + message, + ErrorDescription( + 'These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child ' + 'cannot simultaneously expand to fit its parent.', + ), + ErrorHint( + 'Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible ' + 'children (using Flexible rather than Expanded). This will allow the flexible children ' + 'to size themselves to less than the infinite remaining space they would otherwise be ' + 'forced to take, and then will cause the RenderFlex to shrink-wrap the children ' + 'rather than expanding to fit the maximum constraints provided by the parent.', + ), + ErrorDescription( + 'If this message did not help you determine the problem, consider using debugDumpRenderTree():\n' + ' https://flutter.dev/debugging/#rendering-layer\n' + ' http://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html', + ), + describeForError('The affected RenderFlex is', style: DiagnosticsTreeStyle.errorProperty), + DiagnosticsProperty<dynamic>('The creator information is set to', debugCreator, style: DiagnosticsTreeStyle.errorProperty), + ...addendum, + ErrorDescription( + "If none of the above helps enough to fix this problem, please don't hesitate to file a bug:\n" + ' https://github.com/flutter/flutter/issues/new?template=2_bug.yml', + ), + ]); + return true; + } + child = childAfter(child); + } + return true; + }()); + return result; + } + + _LayoutSizes _computeSizes({required BoxConstraints constraints, required ChildLayouter layoutChild}) { + assert(_debugHasNecessaryDirections); + + // Determine used flex factor, size inflexible items, calculate free space. + int totalFlex = 0; + final double maxMainSize = _direction == Axis.horizontal ? constraints.maxWidth : constraints.maxHeight; + final bool canFlex = maxMainSize < double.infinity; + + double crossSize = 0.0; + double allocatedSize = 0.0; // Sum of the sizes of the non-flexible children. + RenderBox? child = firstChild; + RenderBox? lastFlexChild; + while (child != null) { + final FlexParentData childParentData = child.parentData! as FlexParentData; + final int flex = _getFlex(child); + if (flex > 0) { + totalFlex += flex; + lastFlexChild = child; + } else { + final BoxConstraints innerConstraints; + if (crossAxisAlignment == CrossAxisAlignment.stretch) { + switch (_direction) { + case Axis.horizontal: + innerConstraints = BoxConstraints.tightFor(height: constraints.maxHeight); + case Axis.vertical: + innerConstraints = BoxConstraints.tightFor(width: constraints.maxWidth); + } + } else { + switch (_direction) { + case Axis.horizontal: + innerConstraints = BoxConstraints(maxHeight: constraints.maxHeight); + case Axis.vertical: + innerConstraints = BoxConstraints(maxWidth: constraints.maxWidth); + } + } + final Size childSize = layoutChild(child, innerConstraints); + allocatedSize += _getMainSize(childSize); + crossSize = math.max(crossSize, _getCrossSize(childSize)); + } + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + + // Distribute free space to flexible children. + final double freeSpace = math.max(0.0, (canFlex ? maxMainSize : 0.0) - allocatedSize); + double allocatedFlexSpace = 0.0; + if (totalFlex > 0) { + final double spacePerFlex = canFlex ? (freeSpace / totalFlex) : double.nan; + child = firstChild; + while (child != null) { + final int flex = _getFlex(child); + if (flex > 0) { + final double maxChildExtent = canFlex ? (child == lastFlexChild ? (freeSpace - allocatedFlexSpace) : spacePerFlex * flex) : double.infinity; + late final double minChildExtent; + switch (_getFit(child)) { + case FlexFit.tight: + assert(maxChildExtent < double.infinity); + minChildExtent = maxChildExtent; + case FlexFit.loose: + minChildExtent = 0.0; + } + final BoxConstraints innerConstraints; + if (crossAxisAlignment == CrossAxisAlignment.stretch) { + switch (_direction) { + case Axis.horizontal: + innerConstraints = BoxConstraints( + minWidth: minChildExtent, + maxWidth: maxChildExtent, + minHeight: constraints.maxHeight, + maxHeight: constraints.maxHeight, + ); + case Axis.vertical: + innerConstraints = BoxConstraints( + minWidth: constraints.maxWidth, + maxWidth: constraints.maxWidth, + minHeight: minChildExtent, + maxHeight: maxChildExtent, + ); + } + } else { + switch (_direction) { + case Axis.horizontal: + innerConstraints = BoxConstraints( + minWidth: minChildExtent, + maxWidth: maxChildExtent, + maxHeight: constraints.maxHeight, + ); + case Axis.vertical: + innerConstraints = BoxConstraints( + maxWidth: constraints.maxWidth, + minHeight: minChildExtent, + maxHeight: maxChildExtent, + ); + } + } + final Size childSize = layoutChild(child, innerConstraints); + final double childMainSize = _getMainSize(childSize); + assert(childMainSize <= maxChildExtent); + allocatedSize += childMainSize; + allocatedFlexSpace += maxChildExtent; + crossSize = math.max(crossSize, _getCrossSize(childSize)); + } + final FlexParentData childParentData = child.parentData! as FlexParentData; + child = childParentData.nextSibling; + } + } + + final double idealSize = canFlex && mainAxisSize == MainAxisSize.max ? maxMainSize : allocatedSize; + return _LayoutSizes( + mainSize: idealSize, + crossSize: crossSize, + allocatedSize: allocatedSize, + ); + } + + @override + void performLayout() { + assert(_debugHasNecessaryDirections); + final BoxConstraints constraints = this.constraints; + assert(() { + final FlutterError? constraintsError = _debugCheckConstraints( + constraints: constraints, + reportParentConstraints: true, + ); + if (constraintsError != null) { + throw constraintsError; + } + return true; + }()); + + final _LayoutSizes sizes = _computeSizes( + layoutChild: ChildLayoutHelper.layoutChild, + constraints: constraints, + ); + + final double allocatedSize = sizes.allocatedSize; + double actualSize = sizes.mainSize; + double crossSize = sizes.crossSize; + double maxBaselineDistance = 0.0; + if (crossAxisAlignment == CrossAxisAlignment.baseline) { + RenderBox? child = firstChild; + double maxSizeAboveBaseline = 0; + double maxSizeBelowBaseline = 0; + while (child != null) { + assert(() { + if (textBaseline == null) { + throw FlutterError('To use CrossAxisAlignment.baseline, you must also specify which baseline to use using the "textBaseline" argument.'); + } + return true; + }()); + final double? distance = child.getDistanceToBaseline(textBaseline!, onlyReal: true); + if (distance != null) { + maxBaselineDistance = math.max(maxBaselineDistance, distance); + maxSizeAboveBaseline = math.max( + distance, + maxSizeAboveBaseline, + ); + maxSizeBelowBaseline = math.max( + child.size.height - distance, + maxSizeBelowBaseline, + ); + crossSize = math.max(maxSizeAboveBaseline + maxSizeBelowBaseline, crossSize); + } + final FlexParentData childParentData = child.parentData! as FlexParentData; + child = childParentData.nextSibling; + } + } + + // Align items along the main axis. + switch (_direction) { + case Axis.horizontal: + size = constraints.constrain(Size(actualSize, crossSize)); + actualSize = size.width; + crossSize = size.height; + case Axis.vertical: + size = constraints.constrain(Size(crossSize, actualSize)); + actualSize = size.height; + crossSize = size.width; + } + final double actualSizeDelta = actualSize - allocatedSize; + _overflow = math.max(0.0, -actualSizeDelta); + final double remainingSpace = math.max(0.0, actualSizeDelta); + late final double leadingSpace; + late final double betweenSpace; + // flipMainAxis is used to decide whether to lay out + // left-to-right/top-to-bottom (false), or right-to-left/bottom-to-top + // (true). The _startIsTopLeft will return null if there's only one child + // and the relevant direction is null, in which case we arbitrarily decide + // to flip, but that doesn't have any detectable effect. + final bool flipMainAxis = !(_startIsTopLeft(direction, textDirection, verticalDirection) ?? true); + switch (_mainAxisAlignment) { + case MainAxisAlignment.start: + leadingSpace = 0.0; + betweenSpace = 0.0; + case MainAxisAlignment.end: + leadingSpace = remainingSpace; + betweenSpace = 0.0; + case MainAxisAlignment.center: + leadingSpace = remainingSpace / 2.0; + betweenSpace = 0.0; + case MainAxisAlignment.spaceBetween: + leadingSpace = 0.0; + betweenSpace = childCount > 1 ? remainingSpace / (childCount - 1) : 0.0; + case MainAxisAlignment.spaceAround: + betweenSpace = childCount > 0 ? remainingSpace / childCount : 0.0; + leadingSpace = betweenSpace / 2.0; + case MainAxisAlignment.spaceEvenly: + betweenSpace = childCount > 0 ? remainingSpace / (childCount + 1) : 0.0; + leadingSpace = betweenSpace; + } + + // Position elements + double childMainPosition = flipMainAxis ? actualSize - leadingSpace : leadingSpace; + RenderBox? child = firstChild; + while (child != null) { + final FlexParentData childParentData = child.parentData! as FlexParentData; + final double childCrossPosition; + switch (_crossAxisAlignment) { + case CrossAxisAlignment.start: + case CrossAxisAlignment.end: + childCrossPosition = _startIsTopLeft(flipAxis(direction), textDirection, verticalDirection) + == (_crossAxisAlignment == CrossAxisAlignment.start) + ? 0.0 + : crossSize - _getCrossSize(child.size); + case CrossAxisAlignment.center: + childCrossPosition = crossSize / 2.0 - _getCrossSize(child.size) / 2.0; + case CrossAxisAlignment.stretch: + childCrossPosition = 0.0; + case CrossAxisAlignment.baseline: + if (_direction == Axis.horizontal) { + assert(textBaseline != null); + final double? distance = child.getDistanceToBaseline(textBaseline!, onlyReal: true); + if (distance != null) { + childCrossPosition = maxBaselineDistance - distance; + } else { + childCrossPosition = 0.0; + } + } else { + childCrossPosition = 0.0; + } + } + if (flipMainAxis) { + childMainPosition -= _getMainSize(child.size); + } + switch (_direction) { + case Axis.horizontal: + childParentData.offset = Offset(childMainPosition, childCrossPosition); + case Axis.vertical: + childParentData.offset = Offset(childCrossPosition, childMainPosition); + } + if (flipMainAxis) { + childMainPosition -= betweenSpace; + } else { + childMainPosition += _getMainSize(child.size) + betweenSpace; + } + child = childParentData.nextSibling; + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + return defaultHitTestChildren(result, position: position); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (!_hasOverflow) { + defaultPaint(context, offset); + return; + } + + // There's no point in drawing the children if we're empty. + if (size.isEmpty) { + return; + } + + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + defaultPaint, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + + assert(() { + final List<DiagnosticsNode> debugOverflowHints = <DiagnosticsNode>[ + ErrorDescription( + 'The overflowing $runtimeType has an orientation of $_direction.', + ), + ErrorDescription( + 'The edge of the $runtimeType that is overflowing has been marked ' + 'in the rendering with a yellow and black striped pattern. This is ' + 'usually caused by the contents being too big for the $runtimeType.', + ), + ErrorHint( + 'Consider applying a flex factor (e.g. using an Expanded widget) to ' + 'force the children of the $runtimeType to fit within the available ' + 'space instead of being sized to their natural size.', + ), + ErrorHint( + 'This is considered an error condition because it indicates that there ' + 'is content that cannot be seen. If the content is legitimately bigger ' + 'than the available space, consider clipping it with a ClipRect widget ' + 'before putting it in the flex, or using a scrollable container rather ' + 'than a Flex, like a ListView.', + ), + ]; + + // Simulate a child rect that overflows by the right amount. This child + // rect is never used for drawing, just for determining the overflow + // location and amount. + final Rect overflowChildRect; + switch (_direction) { + case Axis.horizontal: + overflowChildRect = Rect.fromLTWH(0.0, 0.0, size.width + _overflow, 0.0); + case Axis.vertical: + overflowChildRect = Rect.fromLTWH(0.0, 0.0, 0.0, size.height + _overflow); + } + paintOverflowIndicator(context, offset, Offset.zero & size, overflowChildRect, overflowHints: debugOverflowHints); + return true; + }()); + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void dispose() { + _clipRectLayer.layer = null; + super.dispose(); + } + + @override + Rect? describeApproximatePaintClip(RenderObject child) { + switch (clipBehavior) { + case Clip.none: + return null; + case Clip.hardEdge: + case Clip.antiAlias: + case Clip.antiAliasWithSaveLayer: + return _hasOverflow ? Offset.zero & size : null; + } + } + + + @override + String toStringShort() { + String header = super.toStringShort(); + if (!kReleaseMode) { + if (_hasOverflow) { + header += ' OVERFLOWING'; + } + } + return header; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<Axis>('direction', direction)); + properties.add(EnumProperty<MainAxisAlignment>('mainAxisAlignment', mainAxisAlignment)); + properties.add(EnumProperty<MainAxisSize>('mainAxisSize', mainAxisSize)); + properties.add(EnumProperty<CrossAxisAlignment>('crossAxisAlignment', crossAxisAlignment)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(EnumProperty<VerticalDirection>('verticalDirection', verticalDirection, defaultValue: null)); + properties.add(EnumProperty<TextBaseline>('textBaseline', textBaseline, defaultValue: null)); + } +} + +class _LayoutSizes { + const _LayoutSizes({ + required this.mainSize, + required this.crossSize, + required this.allocatedSize, + }); + + final double mainSize; + final double crossSize; + final double allocatedSize; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/flow.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/flow.dart new file mode 100644 index 0000000000000000000000000000000000000000..fcc3a1bbae8bcf2e9de761a8af0b077f1a18bf36 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/flow.dart @@ -0,0 +1,451 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show Color; + +import 'package:flutter/foundation.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'box.dart'; +import 'layer.dart'; +import 'object.dart'; + +/// A context in which a [FlowDelegate] paints. +/// +/// Provides information about the current size of the container and the +/// children and a mechanism for painting children. +/// +/// See also: +/// +/// * [FlowDelegate] +/// * [Flow] +/// * [RenderFlow] +abstract class FlowPaintingContext { + /// The size of the container in which the children can be painted. + Size get size; + + /// The number of children available to paint. + int get childCount; + + /// The size of the [i]th child. + /// + /// If [i] is negative or exceeds [childCount], returns null. + Size? getChildSize(int i); + + /// Paint the [i]th child using the given transform. + /// + /// The child will be painted in a coordinate system that concatenates the + /// container's coordinate system with the given transform. The origin of the + /// parent's coordinate system is the upper left corner of the parent, with + /// x increasing rightward and y increasing downward. + /// + /// The container will clip the children to its bounds. + void paintChild(int i, { Matrix4 transform, double opacity = 1.0 }); +} + +/// A delegate that controls the appearance of a flow layout. +/// +/// Flow layouts are optimized for moving children around the screen using +/// transformation matrices. For optimal performance, construct the +/// [FlowDelegate] with an [Animation] that ticks whenever the delegate wishes +/// to change the transformation matrices for the children and avoid rebuilding +/// the [Flow] widget itself every animation frame. +/// +/// See also: +/// +/// * [Flow] +/// * [RenderFlow] +abstract class FlowDelegate { + /// The flow will repaint whenever [repaint] notifies its listeners. + const FlowDelegate({ Listenable? repaint }) : _repaint = repaint; + + final Listenable? _repaint; + + /// Override to control the size of the container for the children. + /// + /// By default, the flow will be as large as possible. If this function + /// returns a size that does not respect the given constraints, the size will + /// be adjusted to be as close to the returned size as possible while still + /// respecting the constraints. + /// + /// If this function depends on information other than the given constraints, + /// override [shouldRelayout] to indicate when the container should + /// relayout. + Size getSize(BoxConstraints constraints) => constraints.biggest; + + /// Override to control the layout constraints given to each child. + /// + /// By default, the children will receive the given constraints, which are the + /// constraints used to size the container. The children need + /// not respect the given constraints, but they are required to respect the + /// returned constraints. For example, the incoming constraints might require + /// the container to have a width of exactly 100.0 and a height of exactly + /// 100.0, but this function might give the children looser constraints that + /// let them be larger or smaller than 100.0 by 100.0. + /// + /// If this function depends on information other than the given constraints, + /// override [shouldRelayout] to indicate when the container should + /// relayout. + BoxConstraints getConstraintsForChild(int i, BoxConstraints constraints) => constraints; + + /// Override to paint the children of the flow. + /// + /// Children can be painted in any order, but each child can be painted at + /// most once. Although the container clips the children to its own bounds, it + /// is more efficient to skip painting a child altogether rather than having + /// it paint entirely outside the container's clip. + /// + /// To paint a child, call [FlowPaintingContext.paintChild] on the given + /// [FlowPaintingContext] (the `context` argument). The given context is valid + /// only within the scope of this function call and contains information (such + /// as the size of the container) that is useful for picking transformation + /// matrices for the children. + /// + /// If this function depends on information other than the given context, + /// override [shouldRepaint] to indicate when the container should + /// relayout. + void paintChildren(FlowPaintingContext context); + + /// Override this method to return true when the children need to be laid out. + /// This should compare the fields of the current delegate and the given + /// oldDelegate and return true if the fields are such that the layout would + /// be different. + bool shouldRelayout(covariant FlowDelegate oldDelegate) => false; + + /// Override this method to return true when the children need to be + /// repainted. This should compare the fields of the current delegate and the + /// given oldDelegate and return true if the fields are such that + /// paintChildren would act differently. + /// + /// The delegate can also trigger a repaint if the delegate provides the + /// repaint animation argument to this object's constructor and that animation + /// ticks. Triggering a repaint using this animation-based mechanism is more + /// efficient than rebuilding the [Flow] widget to change its delegate. + /// + /// The flow container might repaint even if this function returns false, for + /// example if layout triggers painting (e.g., if [shouldRelayout] returns + /// true). + bool shouldRepaint(covariant FlowDelegate oldDelegate); + + /// Override this method to include additional information in the + /// debugging data printed by [debugDumpRenderTree] and friends. + /// + /// By default, returns the [runtimeType] of the class. + @override + String toString() => objectRuntimeType(this, 'FlowDelegate'); +} + +/// Parent data for use with [RenderFlow]. +/// +/// The [offset] property is ignored by [RenderFlow] and is always set to +/// [Offset.zero]. Children of a [RenderFlow] are positioned using a +/// transformation matrix, which is private to the [RenderFlow]. To set the +/// matrix, use the [FlowPaintingContext.paintChild] function from an override +/// of the [FlowDelegate.paintChildren] function. +class FlowParentData extends ContainerBoxParentData<RenderBox> { + Matrix4? _transform; +} + +/// Implements the flow layout algorithm. +/// +/// Flow layouts are optimized for repositioning children using transformation +/// matrices. +/// +/// The flow container is sized independently from the children by the +/// [FlowDelegate.getSize] function of the delegate. The children are then sized +/// independently given the constraints from the +/// [FlowDelegate.getConstraintsForChild] function. +/// +/// Rather than positioning the children during layout, the children are +/// positioned using transformation matrices during the paint phase using the +/// matrices from the [FlowDelegate.paintChildren] function. The children are thus +/// repositioned efficiently by repainting the flow, skipping layout. +/// +/// The most efficient way to trigger a repaint of the flow is to supply a +/// repaint argument to the constructor of the [FlowDelegate]. The flow will +/// listen to this animation and repaint whenever the animation ticks, avoiding +/// both the build and layout phases of the pipeline. +/// +/// See also: +/// +/// * [FlowDelegate] +/// * [RenderStack] +class RenderFlow extends RenderBox + with ContainerRenderObjectMixin<RenderBox, FlowParentData>, + RenderBoxContainerDefaultsMixin<RenderBox, FlowParentData> + implements FlowPaintingContext { + /// Creates a render object for a flow layout. + /// + /// For optimal performance, consider using children that return true from + /// [isRepaintBoundary]. + RenderFlow({ + List<RenderBox>? children, + required FlowDelegate delegate, + Clip clipBehavior = Clip.hardEdge, + }) : _delegate = delegate, + _clipBehavior = clipBehavior { + addAll(children); + } + + @override + void setupParentData(RenderBox child) { + final ParentData? childParentData = child.parentData; + if (childParentData is FlowParentData) { + childParentData._transform = null; + } else { + child.parentData = FlowParentData(); + } + } + + /// The delegate that controls the transformation matrices of the children. + FlowDelegate get delegate => _delegate; + FlowDelegate _delegate; + /// When the delegate is changed to a new delegate with the same runtimeType + /// as the old delegate, this object will call the delegate's + /// [FlowDelegate.shouldRelayout] and [FlowDelegate.shouldRepaint] functions + /// to determine whether the new delegate requires this object to update its + /// layout or painting. + set delegate(FlowDelegate newDelegate) { + if (_delegate == newDelegate) { + return; + } + final FlowDelegate oldDelegate = _delegate; + _delegate = newDelegate; + + if (newDelegate.runtimeType != oldDelegate.runtimeType || newDelegate.shouldRelayout(oldDelegate)) { + markNeedsLayout(); + } else if (newDelegate.shouldRepaint(oldDelegate)) { + markNeedsPaint(); + } + + if (attached) { + oldDelegate._repaint?.removeListener(markNeedsPaint); + newDelegate._repaint?.addListener(markNeedsPaint); + } + } + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.hardEdge; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _delegate._repaint?.addListener(markNeedsPaint); + } + + @override + void detach() { + _delegate._repaint?.removeListener(markNeedsPaint); + super.detach(); + } + + Size _getSize(BoxConstraints constraints) { + assert(constraints.debugAssertIsValid()); + return constraints.constrain(_delegate.getSize(constraints)); + } + + @override + bool get isRepaintBoundary => true; + + // TODO(ianh): It's a bit dubious to be using the getSize function from the delegate to + // figure out the intrinsic dimensions. We really should either not support intrinsics, + // or we should expose intrinsic delegate callbacks and throw if they're not implemented. + + @override + double computeMinIntrinsicWidth(double height) { + final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width; + if (width.isFinite) { + return width; + } + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width; + if (width.isFinite) { + return width; + } + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height; + if (height.isFinite) { + return height; + } + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height; + if (height.isFinite) { + return height; + } + return 0.0; + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return _getSize(constraints); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + size = _getSize(constraints); + int i = 0; + _randomAccessChildren.clear(); + RenderBox? child = firstChild; + while (child != null) { + _randomAccessChildren.add(child); + final BoxConstraints innerConstraints = _delegate.getConstraintsForChild(i, constraints); + child.layout(innerConstraints, parentUsesSize: true); + final FlowParentData childParentData = child.parentData! as FlowParentData; + childParentData.offset = Offset.zero; + child = childParentData.nextSibling; + i += 1; + } + } + + // Updated during layout. Only valid if layout is not dirty. + final List<RenderBox> _randomAccessChildren = <RenderBox>[]; + + // Updated during paint. + final List<int> _lastPaintOrder = <int>[]; + + // Only valid during paint. + PaintingContext? _paintingContext; + Offset? _paintingOffset; + + @override + Size? getChildSize(int i) { + if (i < 0 || i >= _randomAccessChildren.length) { + return null; + } + return _randomAccessChildren[i].size; + } + + @override + void paintChild(int i, { Matrix4? transform, double opacity = 1.0 }) { + transform ??= Matrix4.identity(); + final RenderBox child = _randomAccessChildren[i]; + final FlowParentData childParentData = child.parentData! as FlowParentData; + assert(() { + if (childParentData._transform != null) { + throw FlutterError( + 'Cannot call paintChild twice for the same child.\n' + 'The flow delegate of type ${_delegate.runtimeType} attempted to ' + 'paint child $i multiple times, which is not permitted.', + ); + } + return true; + }()); + _lastPaintOrder.add(i); + childParentData._transform = transform; + + // We return after assigning _transform so that the transparent child can + // still be hit tested at the correct location. + if (opacity == 0.0) { + return; + } + + void painter(PaintingContext context, Offset offset) { + context.paintChild(child, offset); + } + if (opacity == 1.0) { + _paintingContext!.pushTransform(needsCompositing, _paintingOffset!, transform, painter); + } else { + _paintingContext!.pushOpacity(_paintingOffset!, ui.Color.getAlphaFromOpacity(opacity), (PaintingContext context, Offset offset) { + context.pushTransform(needsCompositing, offset, transform!, painter); + }); + } + } + + void _paintWithDelegate(PaintingContext context, Offset offset) { + _lastPaintOrder.clear(); + _paintingContext = context; + _paintingOffset = offset; + for (final RenderBox child in _randomAccessChildren) { + final FlowParentData childParentData = child.parentData! as FlowParentData; + childParentData._transform = null; + } + try { + _delegate.paintChildren(this); + } finally { + _paintingContext = null; + _paintingOffset = null; + } + } + + @override + void paint(PaintingContext context, Offset offset) { + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + _paintWithDelegate, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void dispose() { + _clipRectLayer.layer = null; + super.dispose(); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + final List<RenderBox> children = getChildrenAsList(); + for (int i = _lastPaintOrder.length - 1; i >= 0; --i) { + final int childIndex = _lastPaintOrder[i]; + if (childIndex >= children.length) { + continue; + } + final RenderBox child = children[childIndex]; + final FlowParentData childParentData = child.parentData! as FlowParentData; + final Matrix4? transform = childParentData._transform; + if (transform == null) { + continue; + } + final bool absorbed = result.addWithPaintTransform( + transform: transform, + position: position, + hitTest: (BoxHitTestResult result, Offset position) { + return child.hitTest(result, position: position); + }, + ); + if (absorbed) { + return true; + } + } + return false; + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + final FlowParentData childParentData = child.parentData! as FlowParentData; + if (childParentData._transform != null) { + transform.multiply(childParentData._transform!); + } + super.applyPaintTransform(child, transform); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/image.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/image.dart new file mode 100644 index 0000000000000000000000000000000000000000..eb94fb915e28ad6335fc8983fe36b78ca159705a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/image.dart @@ -0,0 +1,480 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show Image; + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'object.dart'; + +export 'package:flutter/painting.dart' show + BoxFit, + ImageRepeat; + +/// An image in the render tree. +/// +/// The render image attempts to find a size for itself that fits in the given +/// constraints and preserves the image's intrinsic aspect ratio. +/// +/// The image is painted using [paintImage], which describes the meanings of the +/// various fields on this class in more detail. +class RenderImage extends RenderBox { + /// Creates a render box that displays an image. + /// + /// The [textDirection] argument must not be null if [alignment] will need + /// resolving or if [matchTextDirection] is true. + RenderImage({ + ui.Image? image, + this.debugImageLabel, + double? width, + double? height, + double scale = 1.0, + Color? color, + Animation<double>? opacity, + BlendMode? colorBlendMode, + BoxFit? fit, + AlignmentGeometry alignment = Alignment.center, + ImageRepeat repeat = ImageRepeat.noRepeat, + Rect? centerSlice, + bool matchTextDirection = false, + TextDirection? textDirection, + bool invertColors = false, + bool isAntiAlias = false, + FilterQuality filterQuality = FilterQuality.low, + }) : _image = image, + _width = width, + _height = height, + _scale = scale, + _color = color, + _opacity = opacity, + _colorBlendMode = colorBlendMode, + _fit = fit, + _alignment = alignment, + _repeat = repeat, + _centerSlice = centerSlice, + _matchTextDirection = matchTextDirection, + _invertColors = invertColors, + _textDirection = textDirection, + _isAntiAlias = isAntiAlias, + _filterQuality = filterQuality { + _updateColorFilter(); + } + + Alignment? _resolvedAlignment; + bool? _flipHorizontally; + + void _resolve() { + if (_resolvedAlignment != null) { + return; + } + _resolvedAlignment = alignment.resolve(textDirection); + _flipHorizontally = matchTextDirection && textDirection == TextDirection.rtl; + } + + void _markNeedResolution() { + _resolvedAlignment = null; + _flipHorizontally = null; + markNeedsPaint(); + } + + /// The image to display. + ui.Image? get image => _image; + ui.Image? _image; + set image(ui.Image? value) { + if (value == _image) { + return; + } + // If we get a clone of our image, it's the same underlying native data - + // dispose of the new clone and return early. + if (value != null && _image != null && value.isCloneOf(_image!)) { + value.dispose(); + return; + } + _image?.dispose(); + _image = value; + markNeedsPaint(); + if (_width == null || _height == null) { + markNeedsLayout(); + } + } + + /// A string used to identify the source of the image. + String? debugImageLabel; + + /// If non-null, requires the image to have this width. + /// + /// If null, the image will pick a size that best preserves its intrinsic + /// aspect ratio. + double? get width => _width; + double? _width; + set width(double? value) { + if (value == _width) { + return; + } + _width = value; + markNeedsLayout(); + } + + /// If non-null, require the image to have this height. + /// + /// If null, the image will pick a size that best preserves its intrinsic + /// aspect ratio. + double? get height => _height; + double? _height; + set height(double? value) { + if (value == _height) { + return; + } + _height = value; + markNeedsLayout(); + } + + /// Specifies the image's scale. + /// + /// Used when determining the best display size for the image. + double get scale => _scale; + double _scale; + set scale(double value) { + if (value == _scale) { + return; + } + _scale = value; + markNeedsLayout(); + } + + ColorFilter? _colorFilter; + + void _updateColorFilter() { + if (_color == null) { + _colorFilter = null; + } else { + _colorFilter = ColorFilter.mode(_color!, _colorBlendMode ?? BlendMode.srcIn); + } + } + + /// If non-null, this color is blended with each image pixel using [colorBlendMode]. + Color? get color => _color; + Color? _color; + set color(Color? value) { + if (value == _color) { + return; + } + _color = value; + _updateColorFilter(); + markNeedsPaint(); + } + + /// If non-null, the value from the [Animation] is multiplied with the opacity + /// of each image pixel before painting onto the canvas. + Animation<double>? get opacity => _opacity; + Animation<double>? _opacity; + set opacity(Animation<double>? value) { + if (value == _opacity) { + return; + } + + if (attached) { + _opacity?.removeListener(markNeedsPaint); + } + _opacity = value; + if (attached) { + value?.addListener(markNeedsPaint); + } + } + + /// Used to set the filterQuality of the image. + /// + /// Use the [FilterQuality.low] quality setting to scale the image, which corresponds to + /// bilinear interpolation, rather than the default [FilterQuality.none] which corresponds + /// to nearest-neighbor. + FilterQuality get filterQuality => _filterQuality; + FilterQuality _filterQuality; + set filterQuality(FilterQuality value) { + if (value == _filterQuality) { + return; + } + _filterQuality = value; + markNeedsPaint(); + } + + + /// Used to combine [color] with this image. + /// + /// The default is [BlendMode.srcIn]. In terms of the blend mode, [color] is + /// the source and this image is the destination. + /// + /// See also: + /// + /// * [BlendMode], which includes an illustration of the effect of each blend mode. + BlendMode? get colorBlendMode => _colorBlendMode; + BlendMode? _colorBlendMode; + set colorBlendMode(BlendMode? value) { + if (value == _colorBlendMode) { + return; + } + _colorBlendMode = value; + _updateColorFilter(); + markNeedsPaint(); + } + + /// How to inscribe the image into the space allocated during layout. + /// + /// The default varies based on the other fields. See the discussion at + /// [paintImage]. + BoxFit? get fit => _fit; + BoxFit? _fit; + set fit(BoxFit? value) { + if (value == _fit) { + return; + } + _fit = value; + markNeedsPaint(); + } + + /// How to align the image within its bounds. + /// + /// If this is set to a text-direction-dependent value, [textDirection] must + /// not be null. + AlignmentGeometry get alignment => _alignment; + AlignmentGeometry _alignment; + set alignment(AlignmentGeometry value) { + if (value == _alignment) { + return; + } + _alignment = value; + _markNeedResolution(); + } + + /// How to repeat this image if it doesn't fill its layout bounds. + ImageRepeat get repeat => _repeat; + ImageRepeat _repeat; + set repeat(ImageRepeat value) { + if (value == _repeat) { + return; + } + _repeat = value; + markNeedsPaint(); + } + + /// The center slice for a nine-patch image. + /// + /// The region of the image inside the center slice will be stretched both + /// horizontally and vertically to fit the image into its destination. The + /// region of the image above and below the center slice will be stretched + /// only horizontally and the region of the image to the left and right of + /// the center slice will be stretched only vertically. + Rect? get centerSlice => _centerSlice; + Rect? _centerSlice; + set centerSlice(Rect? value) { + if (value == _centerSlice) { + return; + } + _centerSlice = value; + markNeedsPaint(); + } + + /// Whether to invert the colors of the image. + /// + /// Inverting the colors of an image applies a new color filter to the paint. + /// If there is another specified color filter, the invert will be applied + /// after it. This is primarily used for implementing smart invert on iOS. + bool get invertColors => _invertColors; + bool _invertColors; + set invertColors(bool value) { + if (value == _invertColors) { + return; + } + _invertColors = value; + markNeedsPaint(); + } + + /// Whether to paint the image in the direction of the [TextDirection]. + /// + /// If this is true, then in [TextDirection.ltr] contexts, the image will be + /// drawn with its origin in the top left (the "normal" painting direction for + /// images); and in [TextDirection.rtl] contexts, the image will be drawn with + /// a scaling factor of -1 in the horizontal direction so that the origin is + /// in the top right. + /// + /// This is occasionally used with images in right-to-left environments, for + /// images that were designed for left-to-right locales. Be careful, when + /// using this, to not flip images with integral shadows, text, or other + /// effects that will look incorrect when flipped. + /// + /// If this is set to true, [textDirection] must not be null. + bool get matchTextDirection => _matchTextDirection; + bool _matchTextDirection; + set matchTextDirection(bool value) { + if (value == _matchTextDirection) { + return; + } + _matchTextDirection = value; + _markNeedResolution(); + } + + /// The text direction with which to resolve [alignment]. + /// + /// This may be changed to null, but only after the [alignment] and + /// [matchTextDirection] properties have been changed to values that do not + /// depend on the direction. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + _markNeedResolution(); + } + + /// Whether to paint the image with anti-aliasing. + /// + /// Anti-aliasing alleviates the sawtooth artifact when the image is rotated. + bool get isAntiAlias => _isAntiAlias; + bool _isAntiAlias; + set isAntiAlias(bool value) { + if (_isAntiAlias == value) { + return; + } + _isAntiAlias = value; + markNeedsPaint(); + } + + /// Find a size for the render image within the given constraints. + /// + /// - The dimensions of the RenderImage must fit within the constraints. + /// - The aspect ratio of the RenderImage matches the intrinsic aspect + /// ratio of the image. + /// - The RenderImage's dimension are maximal subject to being smaller than + /// the intrinsic size of the image. + Size _sizeForConstraints(BoxConstraints constraints) { + // Folds the given |width| and |height| into |constraints| so they can all + // be treated uniformly. + constraints = BoxConstraints.tightFor( + width: _width, + height: _height, + ).enforce(constraints); + + if (_image == null) { + return constraints.smallest; + } + + return constraints.constrainSizeAndAttemptToPreserveAspectRatio(Size( + _image!.width.toDouble() / _scale, + _image!.height.toDouble() / _scale, + )); + } + + @override + double computeMinIntrinsicWidth(double height) { + assert(height >= 0.0); + if (_width == null && _height == null) { + return 0.0; + } + return _sizeForConstraints(BoxConstraints.tightForFinite(height: height)).width; + } + + @override + double computeMaxIntrinsicWidth(double height) { + assert(height >= 0.0); + return _sizeForConstraints(BoxConstraints.tightForFinite(height: height)).width; + } + + @override + double computeMinIntrinsicHeight(double width) { + assert(width >= 0.0); + if (_width == null && _height == null) { + return 0.0; + } + return _sizeForConstraints(BoxConstraints.tightForFinite(width: width)).height; + } + + @override + double computeMaxIntrinsicHeight(double width) { + assert(width >= 0.0); + return _sizeForConstraints(BoxConstraints.tightForFinite(width: width)).height; + } + + @override + bool hitTestSelf(Offset position) => true; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return _sizeForConstraints(constraints); + } + + @override + void performLayout() { + size = _sizeForConstraints(constraints); + } + + @override + void attach(covariant PipelineOwner owner) { + super.attach(owner); + _opacity?.addListener(markNeedsPaint); + } + + @override + void detach() { + _opacity?.removeListener(markNeedsPaint); + super.detach(); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (_image == null) { + return; + } + _resolve(); + assert(_resolvedAlignment != null); + assert(_flipHorizontally != null); + paintImage( + canvas: context.canvas, + rect: offset & size, + image: _image!, + debugImageLabel: debugImageLabel, + scale: _scale, + opacity: _opacity?.value ?? 1.0, + colorFilter: _colorFilter, + fit: _fit, + alignment: _resolvedAlignment!, + centerSlice: _centerSlice, + repeat: _repeat, + flipHorizontally: _flipHorizontally!, + invertColors: invertColors, + filterQuality: _filterQuality, + isAntiAlias: _isAntiAlias, + ); + } + + @override + void dispose() { + _image?.dispose(); + _image = null; + super.dispose(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ui.Image>('image', image)); + properties.add(DoubleProperty('width', width, defaultValue: null)); + properties.add(DoubleProperty('height', height, defaultValue: null)); + properties.add(DoubleProperty('scale', scale, defaultValue: 1.0)); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(DiagnosticsProperty<Animation<double>?>('opacity', opacity, defaultValue: null)); + properties.add(EnumProperty<BlendMode>('colorBlendMode', colorBlendMode, defaultValue: null)); + properties.add(EnumProperty<BoxFit>('fit', fit, defaultValue: null)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: null)); + properties.add(EnumProperty<ImageRepeat>('repeat', repeat, defaultValue: ImageRepeat.noRepeat)); + properties.add(DiagnosticsProperty<Rect>('centerSlice', centerSlice, defaultValue: null)); + properties.add(FlagProperty('matchTextDirection', value: matchTextDirection, ifTrue: 'match text direction')); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('invertColors', invertColors)); + properties.add(EnumProperty<FilterQuality>('filterQuality', filterQuality)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/layer.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/layer.dart new file mode 100644 index 0000000000000000000000000000000000000000..a50db424a276f33c0f29778d7815ff468133ac9e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/layer.dart @@ -0,0 +1,2904 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/painting.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'debug.dart'; + +/// Information collected for an annotation that is found in the layer tree. +/// +/// See also: +/// +/// * [Layer.findAnnotations], which create and use objects of this class. +@immutable +class AnnotationEntry<T> { + /// Create an entry of found annotation by providing the object and related + /// information. + const AnnotationEntry({ + required this.annotation, + required this.localPosition, + }); + + /// The annotation object that is found. + final T annotation; + + /// The target location described by the local coordinate space of the + /// annotation object. + final Offset localPosition; + + @override + String toString() { + return '${objectRuntimeType(this, 'AnnotationEntry')}(annotation: $annotation, localPosition: $localPosition)'; + } +} + +/// Information collected about a list of annotations that are found in the +/// layer tree. +/// +/// See also: +/// +/// * [AnnotationEntry], which are members of this class. +/// * [Layer.findAllAnnotations], and [Layer.findAnnotations], which create and +/// use an object of this class. +class AnnotationResult<T> { + final List<AnnotationEntry<T>> _entries = <AnnotationEntry<T>>[]; + + /// Add a new entry to the end of the result. + /// + /// Usually, entries should be added in order from most specific to least + /// specific, typically during an upward walk of the tree. + void add(AnnotationEntry<T> entry) => _entries.add(entry); + + /// An unmodifiable list of [AnnotationEntry] objects recorded. + /// + /// The first entry is the most specific, typically the one at the leaf of + /// tree. + Iterable<AnnotationEntry<T>> get entries => _entries; + + /// An unmodifiable list of annotations recorded. + /// + /// The first entry is the most specific, typically the one at the leaf of + /// tree. + /// + /// It is similar to [entries] but does not contain other information. + Iterable<T> get annotations { + return _entries.map((AnnotationEntry<T> entry) => entry.annotation); + } +} + +const String _flutterRenderingLibrary = 'package:flutter/rendering.dart'; + +/// A composited layer. +/// +/// During painting, the render tree generates a tree of composited layers that +/// are uploaded into the engine and displayed by the compositor. This class is +/// the base class for all composited layers. +/// +/// Most layers can have their properties mutated, and layers can be moved to +/// different parents. The scene must be explicitly recomposited after such +/// changes are made; the layer tree does not maintain its own dirty state. +/// +/// To composite the tree, create a [SceneBuilder] object, pass it to the +/// root [Layer] object's [addToScene] method, and then call +/// [SceneBuilder.build] to obtain a [Scene]. A [Scene] can then be painted +/// using [dart:ui.FlutterView.render]. +/// +/// ## Memory +/// +/// Layers retain resources between frames to speed up rendering. A layer will +/// retain these resources until all [LayerHandle]s referring to the layer have +/// nulled out their references. +/// +/// Layers must not be used after disposal. If a RenderObject needs to maintain +/// a layer for later usage, it must create a handle to that layer. This is +/// handled automatically for the [RenderObject.layer] property, but additional +/// layers must use their own [LayerHandle]. +/// +/// {@tool snippet} +/// +/// This [RenderObject] is a repaint boundary that pushes an additional +/// [ClipRectLayer]. +/// +/// ```dart +/// class ClippingRenderObject extends RenderBox { +/// final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); +/// +/// @override +/// bool get isRepaintBoundary => true; // The [layer] property will be used. +/// +/// @override +/// void paint(PaintingContext context, Offset offset) { +/// _clipRectLayer.layer = context.pushClipRect( +/// needsCompositing, +/// offset, +/// Offset.zero & size, +/// super.paint, +/// oldLayer: _clipRectLayer.layer, +/// ); +/// } +/// +/// @override +/// void dispose() { +/// _clipRectLayer.layer = null; +/// super.dispose(); +/// } +/// } +/// ``` +/// {@end-tool} +/// See also: +/// +/// * [RenderView.compositeFrame], which implements this recomposition protocol +/// for painting [RenderObject] trees on the display. +abstract class Layer with DiagnosticableTreeMixin { + /// Creates an instance of Layer. + Layer() { + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: _flutterRenderingLibrary, + className: '$Layer', + object: this, + ); + } + } + + final Map<int, VoidCallback> _callbacks = <int, VoidCallback>{}; + static int _nextCallbackId = 0; + + /// Whether the subtree rooted at this layer has any composition callback + /// observers. + /// + /// This only evaluates to true if the subtree rooted at this node has + /// observers. For example, it may evaluate to true on a parent node but false + /// on a child if the parent has observers but the child does not. + /// + /// See also: + /// + /// * [Layer.addCompositionCallback]. + bool get subtreeHasCompositionCallbacks => _compositionCallbackCount > 0; + + int _compositionCallbackCount = 0; + void _updateSubtreeCompositionObserverCount(int delta) { + assert(delta != 0); + _compositionCallbackCount += delta; + assert(_compositionCallbackCount >= 0); + parent?._updateSubtreeCompositionObserverCount(delta); + } + + void _fireCompositionCallbacks({required bool includeChildren}) { + if (_callbacks.isEmpty) { + return; + } + for (final VoidCallback callback in List<VoidCallback>.of(_callbacks.values)) { + callback(); + } + } + + bool _debugMutationsLocked = false; + + /// Whether or not this layer, or any child layers, can be rasterized with + /// [Scene.toImage] or [Scene.toImageSync]. + /// + /// If `false`, calling the above methods may yield an image which is + /// incomplete. + /// + /// This value may change throughout the lifetime of the object, as the + /// child layers themselves are added or removed. + bool supportsRasterization() { + return true; + } + + /// Describes the clip that would be applied to contents of this layer, + /// if any. + Rect? describeClipBounds() => null; + + /// Adds a callback for when the layer tree that this layer is part of gets + /// composited, or when it is detached and will not be rendered again. + /// + /// This callback will fire even if an ancestor layer is added with retained + /// rendering, meaning that it will fire even if this layer gets added to the + /// scene via some call to [ui.SceneBuilder.addRetained] on one of its + /// ancestor layers. + /// + /// The callback receives a reference to this layer. The recipient must not + /// mutate the layer during the scope of the callback, but may traverse the + /// tree to find information about the current transform or clip. The layer + /// may not be [attached] anymore in this state, but even if it is detached it + /// may still have an also detached parent it can visit. + /// + /// If new callbacks are added or removed within the [callback], the new + /// callbacks will fire (or stop firing) on the _next_ compositing event. + /// + /// {@template flutter.rendering.Layer.compositionCallbacks} + /// Composition callbacks are useful in place of pushing a layer that would + /// otherwise try to observe the layer tree without actually affecting + /// compositing. For example, a composition callback may be used to observe + /// the total transform and clip of the current container layer to determine + /// whether a render object drawn into it is visible or not. + /// + /// Calling the returned callback will remove [callback] from the composition + /// callbacks. + /// {@endtemplate} + VoidCallback addCompositionCallback(CompositionCallback callback) { + _updateSubtreeCompositionObserverCount(1); + final int callbackId = _nextCallbackId += 1; + _callbacks[callbackId] = () { + assert(() { + _debugMutationsLocked = true; + return true; + }()); + callback(this); + assert(() { + _debugMutationsLocked = false; + return true; + }()); + }; + return () { + assert(debugDisposed || _callbacks.containsKey(callbackId)); + _callbacks.remove(callbackId); + _updateSubtreeCompositionObserverCount(-1); + }; + } + + /// If asserts are enabled, returns whether [dispose] has + /// been called since the last time any retained resources were created. + /// + /// Throws an exception if asserts are disabled. + bool get debugDisposed { + late bool disposed; + assert(() { + disposed = _debugDisposed; + return true; + }()); + return disposed; + } + bool _debugDisposed = false; + + /// Set when this layer is appended to a [ContainerLayer], and + /// unset when it is removed. + /// + /// This cannot be set from [attach] or [detach] which is called when an + /// entire subtree is attached to or detached from an owner. Layers may be + /// appended to or removed from a [ContainerLayer] regardless of whether they + /// are attached or detached, and detaching a layer from an owner does not + /// imply that it has been removed from its parent. + final LayerHandle<Layer> _parentHandle = LayerHandle<Layer>(); + + /// Incremented by [LayerHandle]. + int _refCount = 0; + + /// Called by [LayerHandle]. + void _unref() { + assert(!_debugMutationsLocked); + assert(_refCount > 0); + _refCount -= 1; + if (_refCount == 0) { + dispose(); + } + } + + /// Returns the number of objects holding a [LayerHandle] to this layer. + /// + /// This method throws if asserts are disabled. + int get debugHandleCount { + late int count; + assert(() { + count = _refCount; + return true; + }()); + return count; + } + + /// Clears any retained resources that this layer holds. + /// + /// This method must dispose resources such as [EngineLayer] and [Picture] + /// objects. The layer is still usable after this call, but any graphics + /// related resources it holds will need to be recreated. + /// + /// This method _only_ disposes resources for this layer. For example, if it + /// is a [ContainerLayer], it does not dispose resources of any children. + /// However, [ContainerLayer]s do remove any children they have when + /// this method is called, and if this layer was the last holder of a removed + /// child handle, the child may recursively clean up its resources. + /// + /// This method automatically gets called when all outstanding [LayerHandle]s + /// are disposed. [LayerHandle] objects are typically held by the [parent] + /// layer of this layer and any [RenderObject]s that participated in creating + /// it. + /// + /// After calling this method, the object is unusable. + @mustCallSuper + @protected + @visibleForTesting + void dispose() { + assert(!_debugMutationsLocked); + assert( + !_debugDisposed, + 'Layers must only be disposed once. This is typically handled by ' + 'LayerHandle and createHandle. Subclasses should not directly call ' + 'dispose, except to call super.dispose() in an overridden dispose ' + 'method. Tests must only call dispose once.', + ); + assert(() { + assert( + _refCount == 0, + 'Do not directly call dispose on a $runtimeType. Instead, ' + 'use createHandle and LayerHandle.dispose.', + ); + _debugDisposed = true; + return true; + }()); + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _engineLayer?.dispose(); + _engineLayer = null; + } + + /// This layer's parent in the layer tree. + /// + /// The [parent] of the root node in the layer tree is null. + /// + /// Only subclasses of [ContainerLayer] can have children in the layer tree. + /// All other layer classes are used for leaves in the layer tree. + ContainerLayer? get parent => _parent; + ContainerLayer? _parent; + + // Whether this layer has any changes since its last call to [addToScene]. + // + // Initialized to true as a new layer has never called [addToScene], and is + // set to false after calling [addToScene]. The value can become true again + // if [markNeedsAddToScene] is called, or when [updateSubtreeNeedsAddToScene] + // is called on this layer or on an ancestor layer. + // + // The values of [_needsAddToScene] in a tree of layers are said to be + // _consistent_ if every layer in the tree satisfies the following: + // + // - If [alwaysNeedsAddToScene] is true, then [_needsAddToScene] is also true. + // - If [_needsAddToScene] is true and [parent] is not null, then + // `parent._needsAddToScene` is true. + // + // Typically, this value is set during the paint phase and during compositing. + // During the paint phase render objects create new layers and call + // [markNeedsAddToScene] on existing layers, causing this value to become + // true. After the paint phase the tree may be in an inconsistent state. + // During compositing [ContainerLayer.buildScene] first calls + // [updateSubtreeNeedsAddToScene] to bring this tree to a consistent state, + // then it calls [addToScene], and finally sets this field to false. + bool _needsAddToScene = true; + + /// Mark that this layer has changed and [addToScene] needs to be called. + @protected + @visibleForTesting + void markNeedsAddToScene() { + assert(!_debugMutationsLocked); + assert( + !alwaysNeedsAddToScene, + '$runtimeType with alwaysNeedsAddToScene set called markNeedsAddToScene.\n' + "The layer's alwaysNeedsAddToScene is set to true, and therefore it should not call markNeedsAddToScene.", + ); + assert(!_debugDisposed); + + // Already marked. Short-circuit. + if (_needsAddToScene) { + return; + } + + _needsAddToScene = true; + } + + /// Mark that this layer is in sync with engine. + /// + /// This is for debugging and testing purposes only. In release builds + /// this method has no effect. + @visibleForTesting + void debugMarkClean() { + assert(!_debugMutationsLocked); + assert(() { + _needsAddToScene = false; + return true; + }()); + } + + /// Subclasses may override this to true to disable retained rendering. + @protected + bool get alwaysNeedsAddToScene => false; + + /// Whether this or any descendant layer in the subtree needs [addToScene]. + /// + /// This is for debug and test purpose only. It only becomes valid after + /// calling [updateSubtreeNeedsAddToScene]. + @visibleForTesting + bool? get debugSubtreeNeedsAddToScene { + bool? result; + assert(() { + result = _needsAddToScene; + return true; + }()); + return result; + } + + /// Stores the engine layer created for this layer in order to reuse engine + /// resources across frames for better app performance. + /// + /// This value may be passed to [ui.SceneBuilder.addRetained] to communicate + /// to the engine that nothing in this layer or any of its descendants + /// changed. The native engine could, for example, reuse the texture rendered + /// in a previous frame. The web engine could, for example, reuse the HTML + /// DOM nodes created for a previous frame. + /// + /// This value may be passed as `oldLayer` argument to a "push" method to + /// communicate to the engine that a layer is updating a previously rendered + /// layer. The web engine could, for example, update the properties of + /// previously rendered HTML DOM nodes rather than creating new nodes. + @protected + @visibleForTesting + ui.EngineLayer? get engineLayer => _engineLayer; + + /// Sets the engine layer used to render this layer. + /// + /// Typically this field is set to the value returned by [addToScene], which + /// in turn returns the engine layer produced by one of [ui.SceneBuilder]'s + /// "push" methods, such as [ui.SceneBuilder.pushOpacity]. + @protected + @visibleForTesting + set engineLayer(ui.EngineLayer? value) { + assert(!_debugMutationsLocked); + assert(!_debugDisposed); + + _engineLayer?.dispose(); + _engineLayer = value; + if (!alwaysNeedsAddToScene) { + // The parent must construct a new engine layer to add this layer to, and + // so we mark it as needing [addToScene]. + // + // This is designed to handle two situations: + // + // 1. When rendering the complete layer tree as normal. In this case we + // call child `addToScene` methods first, then we call `set engineLayer` + // for the parent. The children will call `markNeedsAddToScene` on the + // parent to signal that they produced new engine layers and therefore + // the parent needs to update. In this case, the parent is already adding + // itself to the scene via [addToScene], and so after it's done, its + // `set engineLayer` is called and it clears the `_needsAddToScene` flag. + // + // 2. When rendering an interior layer (e.g. `OffsetLayer.toImage`). In + // this case we call `addToScene` for one of the children but not the + // parent, i.e. we produce new engine layers for children but not for the + // parent. Here the children will mark the parent as needing + // `addToScene`, but the parent does not clear the flag until some future + // frame decides to render it, at which point the parent knows that it + // cannot retain its engine layer and will call `addToScene` again. + if (parent != null && !parent!.alwaysNeedsAddToScene) { + parent!.markNeedsAddToScene(); + } + } + } + ui.EngineLayer? _engineLayer; + + /// Traverses the layer subtree starting from this layer and determines whether it needs [addToScene]. + /// + /// A layer needs [addToScene] if any of the following is true: + /// + /// - [alwaysNeedsAddToScene] is true. + /// - [markNeedsAddToScene] has been called. + /// - Any of its descendants need [addToScene]. + /// + /// [ContainerLayer] overrides this method to recursively call it on its children. + @protected + @visibleForTesting + void updateSubtreeNeedsAddToScene() { + assert(!_debugMutationsLocked); + _needsAddToScene = _needsAddToScene || alwaysNeedsAddToScene; + } + + /// The owner for this layer (null if unattached). + /// + /// The entire layer tree that this layer belongs to will have the same owner. + /// + /// Typically the owner is a [RenderView]. + Object? get owner => _owner; + Object? _owner; + + /// Whether the layer tree containing this layer is attached to an owner. + /// + /// This becomes true during the call to [attach]. + /// + /// This becomes false during the call to [detach]. + bool get attached => _owner != null; + + /// Mark this layer as attached to the given owner. + /// + /// Typically called only from the [parent]'s [attach] method, and by the + /// [owner] to mark the root of a tree as attached. + /// + /// Subclasses with children should override this method to + /// [attach] all their children to the same [owner] + /// after calling the inherited method, as in `super.attach(owner)`. + @mustCallSuper + void attach(covariant Object owner) { + assert(_owner == null); + _owner = owner; + } + + /// Mark this layer as detached from its owner. + /// + /// Typically called only from the [parent]'s [detach], and by the [owner] to + /// mark the root of a tree as detached. + /// + /// Subclasses with children should override this method to + /// [detach] all their children after calling the inherited method, + /// as in `super.detach()`. + @mustCallSuper + void detach() { + assert(_owner != null); + _owner = null; + assert(parent == null || attached == parent!.attached); + } + + /// The depth of this layer in the layer tree. + /// + /// The depth of nodes in a tree monotonically increases as you traverse down + /// the tree. There's no guarantee regarding depth between siblings. + /// + /// The depth is used to ensure that nodes are processed in depth order. + int get depth => _depth; + int _depth = 0; + + /// Adjust the [depth] of this node's children, if any. + /// + /// Override this method in subclasses with child nodes to call + /// [ContainerLayer.redepthChild] for each child. Do not call this method + /// directly. + @protected + void redepthChildren() { + // ContainerLayer provides an implementation since its the only one that + // can actually have children. + } + + /// This layer's next sibling in the parent layer's child list. + Layer? get nextSibling => _nextSibling; + Layer? _nextSibling; + + /// This layer's previous sibling in the parent layer's child list. + Layer? get previousSibling => _previousSibling; + Layer? _previousSibling; + + /// Removes this layer from its parent layer's child list. + /// + /// This has no effect if the layer's parent is already null. + @mustCallSuper + void remove() { + assert(!_debugMutationsLocked); + parent?._removeChild(this); + } + + /// Search this layer and its subtree for annotations of type `S` at the + /// location described by `localPosition`. + /// + /// This method is called by the default implementation of [find] and + /// [findAllAnnotations]. Override this method to customize how the layer + /// should search for annotations, or if the layer has its own annotations to + /// add. + /// + /// The default implementation always returns `false`, which means neither + /// the layer nor its children has annotations, and the annotation search + /// is not absorbed either (see below for explanation). + /// + /// ## About layer annotations + /// + /// {@template flutter.rendering.Layer.findAnnotations.aboutAnnotations} + /// An annotation is an optional object of any type that can be carried with a + /// layer. An annotation can be found at a location as long as the owner layer + /// contains the location and is walked to. + /// + /// The annotations are searched by first visiting each child recursively, + /// then this layer, resulting in an order from visually front to back. + /// Annotations must meet the given restrictions, such as type and position. + /// + /// The common way for a value to be found here is by pushing an + /// [AnnotatedRegionLayer] into the layer tree, or by adding the desired + /// annotation by overriding [findAnnotations]. + /// {@endtemplate} + /// + /// ## Parameters and return value + /// + /// The [result] parameter is where the method outputs the resulting + /// annotations. New annotations found during the walk are added to the tail. + /// + /// The [onlyFirst] parameter indicates that, if true, the search will stop + /// when it finds the first qualified annotation; otherwise, it will walk the + /// entire subtree. + /// + /// The return value indicates the opacity of this layer and its subtree at + /// this position. If it returns true, then this layer's parent should skip + /// the children behind this layer. In other words, it is opaque to this type + /// of annotation and has absorbed the search so that its siblings behind it + /// are not aware of the search. If the return value is false, then the parent + /// might continue with other siblings. + /// + /// The return value does not affect whether the parent adds its own + /// annotations; in other words, if a layer is supposed to add an annotation, + /// it will always add it even if its children are opaque to this type of + /// annotation. However, the opacity that the parents return might be affected + /// by their children, hence making all of its ancestors opaque to this type + /// of annotation. + @protected + bool findAnnotations<S extends Object>( + AnnotationResult<S> result, + Offset localPosition, { + required bool onlyFirst, + }) { + return false; + } + + /// Search this layer and its subtree for the first annotation of type `S` + /// under the point described by `localPosition`. + /// + /// Returns null if no matching annotations are found. + /// + /// By default this method calls [findAnnotations] with `onlyFirst: + /// true` and returns the annotation of the first result. Prefer overriding + /// [findAnnotations] instead of this method, because during an annotation + /// search, only [findAnnotations] is recursively called, while custom + /// behavior in this method is ignored. + /// + /// ## About layer annotations + /// + /// {@macro flutter.rendering.Layer.findAnnotations.aboutAnnotations} + /// + /// See also: + /// + /// * [findAllAnnotations], which is similar but returns all annotations found + /// at the given position. + /// * [AnnotatedRegionLayer], for placing values in the layer tree. + S? find<S extends Object>(Offset localPosition) { + final AnnotationResult<S> result = AnnotationResult<S>(); + findAnnotations<S>(result, localPosition, onlyFirst: true); + return result.entries.isEmpty ? null : result.entries.first.annotation; + } + + /// Search this layer and its subtree for all annotations of type `S` under + /// the point described by `localPosition`. + /// + /// Returns a result with empty entries if no matching annotations are found. + /// + /// By default this method calls [findAnnotations] with `onlyFirst: + /// false` and returns the annotations of its result. Prefer overriding + /// [findAnnotations] instead of this method, because during an annotation + /// search, only [findAnnotations] is recursively called, while custom + /// behavior in this method is ignored. + /// + /// ## About layer annotations + /// + /// {@macro flutter.rendering.Layer.findAnnotations.aboutAnnotations} + /// + /// See also: + /// + /// * [find], which is similar but returns the first annotation found at the + /// given position. + /// * [AnnotatedRegionLayer], for placing values in the layer tree. + AnnotationResult<S> findAllAnnotations<S extends Object>(Offset localPosition) { + final AnnotationResult<S> result = AnnotationResult<S>(); + findAnnotations<S>(result, localPosition, onlyFirst: false); + return result; + } + + /// Override this method to upload this layer to the engine. + @protected + void addToScene(ui.SceneBuilder builder); + + void _addToSceneWithRetainedRendering(ui.SceneBuilder builder) { + assert(!_debugMutationsLocked); + // There can't be a loop by adding a retained layer subtree whose + // _needsAddToScene is false. + // + // Proof by contradiction: + // + // If we introduce a loop, this retained layer must be appended to one of + // its descendant layers, say A. That means the child structure of A has + // changed so A's _needsAddToScene is true. This contradicts + // _needsAddToScene being false. + if (!_needsAddToScene && _engineLayer != null) { + builder.addRetained(_engineLayer!); + return; + } + addToScene(builder); + // Clearing the flag _after_ calling `addToScene`, not _before_. This is + // because `addToScene` calls children's `addToScene` methods, which may + // mark this layer as dirty. + _needsAddToScene = false; + } + + /// The object responsible for creating this layer. + /// + /// Defaults to the value of [RenderObject.debugCreator] for the render object + /// that created this layer. Used in debug messages. + Object? debugCreator; + + @override + String toStringShort() => '${super.toStringShort()}${ owner == null ? " DETACHED" : ""}'; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Object>('owner', owner, level: parent != null ? DiagnosticLevel.hidden : DiagnosticLevel.info, defaultValue: null)); + properties.add(DiagnosticsProperty<Object?>('creator', debugCreator, defaultValue: null, level: DiagnosticLevel.debug)); + if (_engineLayer != null) { + properties.add(DiagnosticsProperty<String>('engine layer', describeIdentity(_engineLayer))); + } + properties.add(DiagnosticsProperty<int>('handles', debugHandleCount)); + } +} + +/// A handle to prevent a [Layer]'s platform graphics resources from being +/// disposed. +/// +/// [Layer] objects retain native resources such as [EngineLayer]s and [Picture] +/// objects. These objects may in turn retain large chunks of texture memory, +/// either directly or indirectly. +/// +/// The layer's native resources must be retained as long as there is some +/// object that can add it to a scene. Typically, this is either its +/// [Layer.parent] or an undisposed [RenderObject] that will append it to a +/// [ContainerLayer]. Layers automatically hold a handle to their children, and +/// RenderObjects automatically hold a handle to their [RenderObject.layer] as +/// well as any [PictureLayer]s that they paint into using the +/// [PaintingContext.canvas]. A layer automatically releases its resources once +/// at least one handle has been acquired and all handles have been disposed. +/// [RenderObject]s that create additional layer objects must manually manage +/// the handles for that layer similarly to the implementation of +/// [RenderObject.layer]. +/// +/// A handle is automatically managed for [RenderObject.layer]. +/// +/// If a [RenderObject] creates layers in addition to its [RenderObject.layer] +/// and it intends to reuse those layers separately from [RenderObject.layer], +/// it must create a handle to that layer and dispose of it when the layer is +/// no longer needed. For example, if it re-creates or nulls out an existing +/// layer in [RenderObject.paint], it should dispose of the handle to the +/// old layer. It should also dispose of any layer handles it holds in +/// [RenderObject.dispose]. +class LayerHandle<T extends Layer> { + /// Create a new layer handle, optionally referencing a [Layer]. + LayerHandle([this._layer]) { + if (_layer != null) { + _layer!._refCount += 1; + } + } + + T? _layer; + + /// The [Layer] whose resources this object keeps alive. + /// + /// Setting a new value or null will dispose the previously held layer if + /// there are no other open handles to that layer. + T? get layer => _layer; + + set layer(T? layer) { + assert( + layer?.debugDisposed != true, + 'Attempted to create a handle to an already disposed layer: $layer.', + ); + if (identical(layer, _layer)) { + return; + } + _layer?._unref(); + _layer = layer; + if (_layer != null) { + _layer!._refCount += 1; + } + } + + @override + String toString() => 'LayerHandle(${_layer != null ? _layer.toString() : 'DISPOSED'})'; +} + +/// A composited layer containing a [Picture]. +/// +/// Picture layers are always leaves in the layer tree. They are also +/// responsible for disposing of the [Picture] object they hold. This is +/// typically done when their parent and all [RenderObject]s that participated +/// in painting the picture have been disposed. +class PictureLayer extends Layer { + /// Creates a leaf layer for the layer tree. + PictureLayer(this.canvasBounds); + + /// The bounds that were used for the canvas that drew this layer's [picture]. + /// + /// This is purely advisory. It is included in the information dumped with + /// [debugDumpLayerTree] (which can be triggered by pressing "L" when using + /// "flutter run" at the console), which can help debug why certain drawing + /// commands are being culled. + final Rect canvasBounds; + + /// The picture recorded for this layer. + /// + /// The picture's coordinate system matches this layer's coordinate system. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + ui.Picture? get picture => _picture; + ui.Picture? _picture; + set picture(ui.Picture? picture) { + assert(!_debugDisposed); + markNeedsAddToScene(); + _picture?.dispose(); + _picture = picture; + } + + /// Hints that the painting in this layer is complex and would benefit from + /// caching. + /// + /// If this hint is not set, the compositor will apply its own heuristics to + /// decide whether the this layer is complex enough to benefit from caching. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + bool get isComplexHint => _isComplexHint; + bool _isComplexHint = false; + set isComplexHint(bool value) { + if (value != _isComplexHint) { + _isComplexHint = value; + markNeedsAddToScene(); + } + } + + /// Hints that the painting in this layer is likely to change next frame. + /// + /// This hint tells the compositor not to cache this layer because the cache + /// will not be used in the future. If this hint is not set, the compositor + /// will apply its own heuristics to decide whether this layer is likely to be + /// reused in the future. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + bool get willChangeHint => _willChangeHint; + bool _willChangeHint = false; + set willChangeHint(bool value) { + if (value != _willChangeHint) { + _willChangeHint = value; + markNeedsAddToScene(); + } + } + + @override + void dispose() { + picture = null; // Will dispose _picture. + super.dispose(); + } + + @override + void addToScene(ui.SceneBuilder builder) { + assert(picture != null); + builder.addPicture(Offset.zero, picture!, isComplexHint: isComplexHint, willChangeHint: willChangeHint); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Rect>('paint bounds', canvasBounds)); + properties.add(DiagnosticsProperty<String>('picture', describeIdentity(_picture))); + properties.add(DiagnosticsProperty<String>( + 'raster cache hints', + 'isComplex = $isComplexHint, willChange = $willChangeHint', + )); + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + return false; + } +} + +/// A composited layer that maps a backend texture to a rectangle. +/// +/// Backend textures are images that can be applied (mapped) to an area of the +/// Flutter view. They are created, managed, and updated using a +/// platform-specific texture registry. This is typically done by a plugin +/// that integrates with host platform video player, camera, or OpenGL APIs, +/// or similar image sources. +/// +/// A texture layer refers to its backend texture using an integer ID. Texture +/// IDs are obtained from the texture registry and are scoped to the Flutter +/// view. Texture IDs may be reused after deregistration, at the discretion +/// of the registry. The use of texture IDs currently unknown to the registry +/// will silently result in a blank rectangle. +/// +/// Once inserted into the layer tree, texture layers are repainted autonomously +/// as dictated by the backend (e.g. on arrival of a video frame). Such +/// repainting generally does not involve executing Dart code. +/// +/// Texture layers are always leaves in the layer tree. +/// +/// See also: +/// +/// * [TextureRegistry](/javadoc/io/flutter/view/TextureRegistry.html) +/// for how to create and manage backend textures on Android. +/// * [TextureRegistry Protocol](/ios-embedder/protocol_flutter_texture_registry-p.html) +/// for how to create and manage backend textures on iOS. +class TextureLayer extends Layer { + /// Creates a texture layer bounded by [rect] and with backend texture + /// identified by [textureId], if [freeze] is true new texture frames will not be + /// populated to the texture, and use [filterQuality] to set layer's [FilterQuality]. + TextureLayer({ + required this.rect, + required this.textureId, + this.freeze = false, + this.filterQuality = ui.FilterQuality.low, + }); + + /// Bounding rectangle of this layer. + final Rect rect; + + /// The identity of the backend texture. + final int textureId; + + /// When true the texture will not be updated with new frames. + /// + /// This is used for resizing embedded Android views: when resizing there + /// is a short period during which the framework cannot tell if the newest + /// texture frame has the previous or new size; to work around this, the + /// framework "freezes" the texture just before resizing the Android view and + /// un-freezes it when it is certain that a frame with the new size is ready. + final bool freeze; + + /// {@macro flutter.widgets.Texture.filterQuality} + final ui.FilterQuality filterQuality; + + @override + void addToScene(ui.SceneBuilder builder) { + builder.addTexture( + textureId, + offset: rect.topLeft, + width: rect.width, + height: rect.height, + freeze: freeze, + filterQuality: filterQuality, + ); + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + return false; + } +} + +/// A layer that shows an embedded [UIView](https://developer.apple.com/documentation/uikit/uiview) +/// on iOS. +class PlatformViewLayer extends Layer { + /// Creates a platform view layer. + PlatformViewLayer({ + required this.rect, + required this.viewId, + }); + + /// Bounding rectangle of this layer in the global coordinate space. + final Rect rect; + + /// The unique identifier of the UIView displayed on this layer. + /// + /// A UIView with this identifier must have been created by [PlatformViewsService.initUiKitView]. + final int viewId; + + @override + bool supportsRasterization() { + return false; + } + + @override + void addToScene(ui.SceneBuilder builder) { + builder.addPlatformView( + viewId, + offset: rect.topLeft, + width: rect.width, + height: rect.height, + ); + } +} + +/// A layer that indicates to the compositor that it should display +/// certain performance statistics within it. +/// +/// Performance overlay layers are always leaves in the layer tree. +class PerformanceOverlayLayer extends Layer { + /// Creates a layer that displays a performance overlay. + PerformanceOverlayLayer({ + required Rect overlayRect, + required this.optionsMask, + required this.rasterizerThreshold, + required this.checkerboardRasterCacheImages, + required this.checkerboardOffscreenLayers, + }) : _overlayRect = overlayRect; + + /// The rectangle in this layer's coordinate system that the overlay should occupy. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + Rect get overlayRect => _overlayRect; + Rect _overlayRect; + set overlayRect(Rect value) { + if (value != _overlayRect) { + _overlayRect = value; + markNeedsAddToScene(); + } + } + + /// The mask is created by shifting 1 by the index of the specific + /// [PerformanceOverlayOption] to enable. + final int optionsMask; + + /// The rasterizer threshold is an integer specifying the number of frame + /// intervals that the rasterizer must miss before it decides that the frame + /// is suitable for capturing an SkPicture trace for further analysis. + final int rasterizerThreshold; + + /// Whether the raster cache should checkerboard cached entries. + /// + /// The compositor can sometimes decide to cache certain portions of the + /// widget hierarchy. Such portions typically don't change often from frame to + /// frame and are expensive to render. This can speed up overall rendering. However, + /// there is certain upfront cost to constructing these cache entries. And, if + /// the cache entries are not used very often, this cost may not be worth the + /// speedup in rendering of subsequent frames. If the developer wants to be certain + /// that populating the raster cache is not causing stutters, this option can be + /// set. Depending on the observations made, hints can be provided to the compositor + /// that aid it in making better decisions about caching. + final bool checkerboardRasterCacheImages; + + /// Whether the compositor should checkerboard layers that are rendered to offscreen + /// bitmaps. This can be useful for debugging rendering performance. + /// + /// Render target switches are caused by using opacity layers (via a [FadeTransition] or + /// [Opacity] widget), clips, shader mask layers, etc. Selecting a new render target + /// and merging it with the rest of the scene has a performance cost. This can sometimes + /// be avoided by using equivalent widgets that do not require these layers (for example, + /// replacing an [Opacity] widget with an [widgets.Image] using a [BlendMode]). + final bool checkerboardOffscreenLayers; + + @override + void addToScene(ui.SceneBuilder builder) { + builder.addPerformanceOverlay(optionsMask, overlayRect); + builder.setRasterizerTracingThreshold(rasterizerThreshold); + builder.setCheckerboardRasterCacheImages(checkerboardRasterCacheImages); + builder.setCheckerboardOffscreenLayers(checkerboardOffscreenLayers); + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + return false; + } +} + +/// The signature of the callback added in [Layer.addCompositionCallback]. +typedef CompositionCallback = void Function(Layer layer); + +/// A composited layer that has a list of children. +/// +/// A [ContainerLayer] instance merely takes a list of children and inserts them +/// into the composited rendering in order. There are subclasses of +/// [ContainerLayer] which apply more elaborate effects in the process. +class ContainerLayer extends Layer { + @override + void _fireCompositionCallbacks({required bool includeChildren}) { + super._fireCompositionCallbacks(includeChildren: includeChildren); + if (!includeChildren) { + return; + } + Layer? child = firstChild; + while (child != null) { + child._fireCompositionCallbacks(includeChildren: includeChildren); + child = child.nextSibling; + } + } + + /// The first composited layer in this layer's child list. + Layer? get firstChild => _firstChild; + Layer? _firstChild; + + /// The last composited layer in this layer's child list. + Layer? get lastChild => _lastChild; + Layer? _lastChild; + + /// Returns whether this layer has at least one child layer. + bool get hasChildren => _firstChild != null; + + @override + bool supportsRasterization() { + for (Layer? child = lastChild; child != null; child = child.previousSibling) { + if (!child.supportsRasterization()) { + return false; + } + } + return true; + } + + /// Consider this layer as the root and build a scene (a tree of layers) + /// in the engine. + // The reason this method is in the `ContainerLayer` class rather than + // `PipelineOwner` or other singleton level is because this method can be used + // both to render the whole layer tree (e.g. a normal application frame) and + // to render a subtree (e.g. `OffsetLayer.toImage`). + ui.Scene buildScene(ui.SceneBuilder builder) { + updateSubtreeNeedsAddToScene(); + addToScene(builder); + if (subtreeHasCompositionCallbacks) { + _fireCompositionCallbacks(includeChildren: true); + } + // Clearing the flag _after_ calling `addToScene`, not _before_. This is + // because `addToScene` calls children's `addToScene` methods, which may + // mark this layer as dirty. + _needsAddToScene = false; + final ui.Scene scene = builder.build(); + return scene; + } + + bool _debugUltimatePreviousSiblingOf(Layer child, { Layer? equals }) { + assert(child.attached == attached); + while (child.previousSibling != null) { + assert(child.previousSibling != child); + child = child.previousSibling!; + assert(child.attached == attached); + } + return child == equals; + } + + bool _debugUltimateNextSiblingOf(Layer child, { Layer? equals }) { + assert(child.attached == attached); + while (child._nextSibling != null) { + assert(child._nextSibling != child); + child = child._nextSibling!; + assert(child.attached == attached); + } + return child == equals; + } + + @override + void dispose() { + removeAllChildren(); + _callbacks.clear(); + super.dispose(); + } + + @override + void updateSubtreeNeedsAddToScene() { + super.updateSubtreeNeedsAddToScene(); + Layer? child = firstChild; + while (child != null) { + child.updateSubtreeNeedsAddToScene(); + _needsAddToScene = _needsAddToScene || child._needsAddToScene; + child = child.nextSibling; + } + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + for (Layer? child = lastChild; child != null; child = child.previousSibling) { + final bool isAbsorbed = child.findAnnotations<S>(result, localPosition, onlyFirst: onlyFirst); + if (isAbsorbed) { + return true; + } + if (onlyFirst && result.entries.isNotEmpty) { + return isAbsorbed; + } + } + return false; + } + + @override + void attach(Object owner) { + assert(!_debugMutationsLocked); + super.attach(owner); + Layer? child = firstChild; + while (child != null) { + child.attach(owner); + child = child.nextSibling; + } + } + + @override + void detach() { + assert(!_debugMutationsLocked); + super.detach(); + Layer? child = firstChild; + while (child != null) { + child.detach(); + child = child.nextSibling; + } + // Detach indicates that we may never be composited again. Clients + // interested in observing composition need to get an update here because + // they might otherwise never get another one even though the layer is no + // longer visible. + // + // Children fired them already in child.detach(). + _fireCompositionCallbacks(includeChildren: false); + } + + /// Adds the given layer to the end of this layer's child list. + void append(Layer child) { + assert(!_debugMutationsLocked); + assert(child != this); + assert(child != firstChild); + assert(child != lastChild); + assert(child.parent == null); + assert(!child.attached); + assert(child.nextSibling == null); + assert(child.previousSibling == null); + assert(child._parentHandle.layer == null); + assert(() { + Layer node = this; + while (node.parent != null) { + node = node.parent!; + } + assert(node != child); // indicates we are about to create a cycle + return true; + }()); + _adoptChild(child); + child._previousSibling = lastChild; + if (lastChild != null) { + lastChild!._nextSibling = child; + } + _lastChild = child; + _firstChild ??= child; + child._parentHandle.layer = child; + assert(child.attached == attached); + } + + void _adoptChild(Layer child) { + assert(!_debugMutationsLocked); + if (!alwaysNeedsAddToScene) { + markNeedsAddToScene(); + } + if (child._compositionCallbackCount != 0) { + _updateSubtreeCompositionObserverCount(child._compositionCallbackCount); + } + assert(child._parent == null); + assert(() { + Layer node = this; + while (node.parent != null) { + node = node.parent!; + } + assert(node != child); // indicates we are about to create a cycle + return true; + }()); + child._parent = this; + if (attached) { + child.attach(_owner!); + } + redepthChild(child); + } + + @override + void redepthChildren() { + Layer? child = firstChild; + while (child != null) { + redepthChild(child); + child = child.nextSibling; + } + } + + /// Adjust the [depth] of the given [child] to be greater than this node's own + /// [depth]. + /// + /// Only call this method from overrides of [redepthChildren]. + @protected + void redepthChild(Layer child) { + assert(child.owner == owner); + if (child._depth <= _depth) { + child._depth = _depth + 1; + child.redepthChildren(); + } + } + + // Implementation of [Layer.remove]. + void _removeChild(Layer child) { + assert(child.parent == this); + assert(child.attached == attached); + assert(_debugUltimatePreviousSiblingOf(child, equals: firstChild)); + assert(_debugUltimateNextSiblingOf(child, equals: lastChild)); + assert(child._parentHandle.layer != null); + if (child._previousSibling == null) { + assert(_firstChild == child); + _firstChild = child._nextSibling; + } else { + child._previousSibling!._nextSibling = child.nextSibling; + } + if (child._nextSibling == null) { + assert(lastChild == child); + _lastChild = child.previousSibling; + } else { + child.nextSibling!._previousSibling = child.previousSibling; + } + assert((firstChild == null) == (lastChild == null)); + assert(firstChild == null || firstChild!.attached == attached); + assert(lastChild == null || lastChild!.attached == attached); + assert(firstChild == null || _debugUltimateNextSiblingOf(firstChild!, equals: lastChild)); + assert(lastChild == null || _debugUltimatePreviousSiblingOf(lastChild!, equals: firstChild)); + child._previousSibling = null; + child._nextSibling = null; + _dropChild(child); + child._parentHandle.layer = null; + assert(!child.attached); + } + + void _dropChild(Layer child) { + assert(!_debugMutationsLocked); + if (!alwaysNeedsAddToScene) { + markNeedsAddToScene(); + } + if (child._compositionCallbackCount != 0) { + _updateSubtreeCompositionObserverCount(-child._compositionCallbackCount); + } + assert(child._parent == this); + assert(child.attached == attached); + child._parent = null; + if (attached) { + child.detach(); + } + } + + /// Removes all of this layer's children from its child list. + void removeAllChildren() { + assert(!_debugMutationsLocked); + Layer? child = firstChild; + while (child != null) { + final Layer? next = child.nextSibling; + child._previousSibling = null; + child._nextSibling = null; + assert(child.attached == attached); + _dropChild(child); + child._parentHandle.layer = null; + child = next; + } + _firstChild = null; + _lastChild = null; + } + + @override + void addToScene(ui.SceneBuilder builder) { + addChildrenToScene(builder); + } + + /// Uploads all of this layer's children to the engine. + /// + /// This method is typically used by [addToScene] to insert the children into + /// the scene. Subclasses of [ContainerLayer] typically override [addToScene] + /// to apply effects to the scene using the [SceneBuilder] API, then insert + /// their children using [addChildrenToScene], then reverse the aforementioned + /// effects before returning from [addToScene]. + void addChildrenToScene(ui.SceneBuilder builder) { + Layer? child = firstChild; + while (child != null) { + child._addToSceneWithRetainedRendering(builder); + child = child.nextSibling; + } + } + + /// Applies the transform that would be applied when compositing the given + /// child to the given matrix. + /// + /// Specifically, this should apply the transform that is applied to child's + /// _origin_. When using [applyTransform] with a chain of layers, results will + /// be unreliable unless the deepest layer in the chain collapses the + /// `layerOffset` in [addToScene] to zero, meaning that it passes + /// [Offset.zero] to its children, and bakes any incoming `layerOffset` into + /// the [SceneBuilder] as (for instance) a transform (which is then also + /// included in the transformation applied by [applyTransform]). + /// + /// For example, if [addToScene] applies the `layerOffset` and then + /// passes [Offset.zero] to the children, then it should be included in the + /// transform applied here, whereas if [addToScene] just passes the + /// `layerOffset` to the child, then it should not be included in the + /// transform applied here. + /// + /// This method is only valid immediately after [addToScene] has been called, + /// before any of the properties have been changed. + /// + /// The default implementation does nothing, since [ContainerLayer], by + /// default, composites its children at the origin of the [ContainerLayer] + /// itself. + /// + /// The `child` argument should generally not be null, since in principle a + /// layer could transform each child independently. However, certain layers + /// may explicitly allow null as a value, for example if they know that they + /// transform all their children identically. + /// + /// Used by [FollowerLayer] to transform its child to a [LeaderLayer]'s + /// position. + void applyTransform(Layer? child, Matrix4 transform) { + assert(child != null); + } + + /// Returns the descendants of this layer in depth first order. + @visibleForTesting + List<Layer> depthFirstIterateChildren() { + if (firstChild == null) { + return <Layer>[]; + } + final List<Layer> children = <Layer>[]; + Layer? child = firstChild; + while (child != null) { + children.add(child); + if (child is ContainerLayer) { + children.addAll(child.depthFirstIterateChildren()); + } + child = child.nextSibling; + } + return children; + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<DiagnosticsNode> children = <DiagnosticsNode>[]; + if (firstChild == null) { + return children; + } + Layer? child = firstChild; + int count = 1; + while (true) { + children.add(child!.toDiagnosticsNode(name: 'child $count')); + if (child == lastChild) { + break; + } + count += 1; + child = child.nextSibling; + } + return children; + } +} + +/// A layer that is displayed at an offset from its parent layer. +/// +/// Offset layers are key to efficient repainting because they are created by +/// repaint boundaries in the [RenderObject] tree (see +/// [RenderObject.isRepaintBoundary]). When a render object that is a repaint +/// boundary is asked to paint at given offset in a [PaintingContext], the +/// render object first checks whether it needs to repaint itself. If not, it +/// reuses its existing [OffsetLayer] (and its entire subtree) by mutating its +/// [offset] property, cutting off the paint walk. +class OffsetLayer extends ContainerLayer { + /// Creates an offset layer. + /// + /// By default, [offset] is zero. It must be non-null before the compositing + /// phase of the pipeline. + OffsetLayer({ Offset offset = Offset.zero }) : _offset = offset; + + /// Offset from parent in the parent's coordinate system. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + /// + /// The [offset] property must be non-null before the compositing phase of the + /// pipeline. + Offset get offset => _offset; + Offset _offset; + set offset(Offset value) { + if (value != _offset) { + markNeedsAddToScene(); + } + _offset = value; + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + return super.findAnnotations<S>(result, localPosition - offset, onlyFirst: onlyFirst); + } + + @override + void applyTransform(Layer? child, Matrix4 transform) { + assert(child != null); + transform.translate(offset.dx, offset.dy); + } + + @override + void addToScene(ui.SceneBuilder builder) { + // Skia has a fast path for concatenating scale/translation only matrices. + // Hence pushing a translation-only transform layer should be fast. For + // retained rendering, we don't want to push the offset down to each leaf + // node. Otherwise, changing an offset layer on the very high level could + // cascade the change to too many leaves. + engineLayer = builder.pushOffset( + offset.dx, + offset.dy, + oldLayer: _engineLayer as ui.OffsetEngineLayer?, + ); + addChildrenToScene(builder); + builder.pop(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Offset>('offset', offset)); + } + + ui.Scene _createSceneForImage(Rect bounds, { double pixelRatio = 1.0 }) { + final ui.SceneBuilder builder = ui.SceneBuilder(); + final Matrix4 transform = Matrix4.diagonal3Values(pixelRatio, pixelRatio, 1); + transform.translate(-(bounds.left + offset.dx), -(bounds.top + offset.dy)); + builder.pushTransform(transform.storage); + return buildScene(builder); + } + + /// Capture an image of the current state of this layer and its children. + /// + /// The returned [ui.Image] has uncompressed raw RGBA bytes, will be offset + /// by the top-left corner of [bounds], and have dimensions equal to the size + /// of [bounds] multiplied by [pixelRatio]. + /// + /// The [pixelRatio] describes the scale between the logical pixels and the + /// size of the output image. It is independent of the + /// [dart:ui.FlutterView.devicePixelRatio] for the device, so specifying 1.0 + /// (the default) will give you a 1:1 mapping between logical pixels and the + /// output pixels in the image. + /// + /// This API functions like [toImageSync], except that it only returns after + /// rasterization is complete. + /// + /// See also: + /// + /// * [RenderRepaintBoundary.toImage] for a similar API at the render object level. + /// * [dart:ui.Scene.toImage] for more information about the image returned. + Future<ui.Image> toImage(Rect bounds, { double pixelRatio = 1.0 }) async { + final ui.Scene scene = _createSceneForImage(bounds, pixelRatio: pixelRatio); + + try { + // Size is rounded up to the next pixel to make sure we don't clip off + // anything. + return await scene.toImage( + (pixelRatio * bounds.width).ceil(), + (pixelRatio * bounds.height).ceil(), + ); + } finally { + scene.dispose(); + } + } + + /// Capture an image of the current state of this layer and its children. + /// + /// The returned [ui.Image] has uncompressed raw RGBA bytes, will be offset + /// by the top-left corner of [bounds], and have dimensions equal to the size + /// of [bounds] multiplied by [pixelRatio]. + /// + /// The [pixelRatio] describes the scale between the logical pixels and the + /// size of the output image. It is independent of the + /// [dart:ui.FlutterView.devicePixelRatio] for the device, so specifying 1.0 + /// (the default) will give you a 1:1 mapping between logical pixels and the + /// output pixels in the image. + /// + /// This API functions like [toImage], except that rasterization begins eagerly + /// on the raster thread and the image is returned before this is completed. + /// + /// See also: + /// + /// * [RenderRepaintBoundary.toImage] for a similar API at the render object level. + /// * [dart:ui.Scene.toImage] for more information about the image returned. + ui.Image toImageSync(Rect bounds, { double pixelRatio = 1.0 }) { + final ui.Scene scene = _createSceneForImage(bounds, pixelRatio: pixelRatio); + + try { + // Size is rounded up to the next pixel to make sure we don't clip off + // anything. + return scene.toImageSync( + (pixelRatio * bounds.width).ceil(), + (pixelRatio * bounds.height).ceil(), + ); + } finally { + scene.dispose(); + } + } +} + +/// A composite layer that clips its children using a rectangle. +/// +/// When debugging, setting [debugDisableClipLayers] to true will cause this +/// layer to be skipped (directly replaced by its children). This can be helpful +/// to track down the cause of performance problems. +class ClipRectLayer extends ContainerLayer { + /// Creates a layer with a rectangular clip. + /// + /// The [clipRect] argument must not be null before the compositing phase of + /// the pipeline. + /// + /// The [clipBehavior] argument must not be [Clip.none]. + ClipRectLayer({ + Rect? clipRect, + Clip clipBehavior = Clip.hardEdge, + }) : _clipRect = clipRect, + _clipBehavior = clipBehavior, + assert(clipBehavior != Clip.none); + + /// The rectangle to clip in the parent's coordinate system. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + Rect? get clipRect => _clipRect; + Rect? _clipRect; + set clipRect(Rect? value) { + if (value != _clipRect) { + _clipRect = value; + markNeedsAddToScene(); + } + } + + @override + Rect? describeClipBounds() => clipRect; + + /// {@template flutter.rendering.ClipRectLayer.clipBehavior} + /// Controls how to clip. + /// + /// Must not be set to null or [Clip.none]. + /// {@endtemplate} + /// + /// Defaults to [Clip.hardEdge]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior; + set clipBehavior(Clip value) { + assert(value != Clip.none); + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsAddToScene(); + } + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + if (!clipRect!.contains(localPosition)) { + return false; + } + return super.findAnnotations<S>(result, localPosition, onlyFirst: onlyFirst); + } + + @override + void addToScene(ui.SceneBuilder builder) { + assert(clipRect != null); + bool enabled = true; + assert(() { + enabled = !debugDisableClipLayers; + return true; + }()); + if (enabled) { + engineLayer = builder.pushClipRect( + clipRect!, + clipBehavior: clipBehavior, + oldLayer: _engineLayer as ui.ClipRectEngineLayer?, + ); + } else { + engineLayer = null; + } + addChildrenToScene(builder); + if (enabled) { + builder.pop(); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Rect>('clipRect', clipRect)); + properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior)); + } +} + +/// A composite layer that clips its children using a rounded rectangle. +/// +/// When debugging, setting [debugDisableClipLayers] to true will cause this +/// layer to be skipped (directly replaced by its children). This can be helpful +/// to track down the cause of performance problems. +class ClipRRectLayer extends ContainerLayer { + /// Creates a layer with a rounded-rectangular clip. + /// + /// The [clipRRect] and [clipBehavior] properties must be non-null before the + /// compositing phase of the pipeline. + ClipRRectLayer({ + RRect? clipRRect, + Clip clipBehavior = Clip.antiAlias, + }) : _clipRRect = clipRRect, + _clipBehavior = clipBehavior, + assert(clipBehavior != Clip.none); + + /// The rounded-rect to clip in the parent's coordinate system. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + RRect? get clipRRect => _clipRRect; + RRect? _clipRRect; + set clipRRect(RRect? value) { + if (value != _clipRRect) { + _clipRRect = value; + markNeedsAddToScene(); + } + } + + @override + Rect? describeClipBounds() => clipRRect?.outerRect; + + /// {@macro flutter.rendering.ClipRectLayer.clipBehavior} + /// + /// Defaults to [Clip.antiAlias]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior; + set clipBehavior(Clip value) { + assert(value != Clip.none); + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsAddToScene(); + } + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + if (!clipRRect!.contains(localPosition)) { + return false; + } + return super.findAnnotations<S>(result, localPosition, onlyFirst: onlyFirst); + } + + @override + void addToScene(ui.SceneBuilder builder) { + assert(clipRRect != null); + bool enabled = true; + assert(() { + enabled = !debugDisableClipLayers; + return true; + }()); + if (enabled) { + engineLayer = builder.pushClipRRect( + clipRRect!, + clipBehavior: clipBehavior, + oldLayer: _engineLayer as ui.ClipRRectEngineLayer?, + ); + } else { + engineLayer = null; + } + addChildrenToScene(builder); + if (enabled) { + builder.pop(); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<RRect>('clipRRect', clipRRect)); + properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior)); + } +} + +/// A composite layer that clips its children using a path. +/// +/// When debugging, setting [debugDisableClipLayers] to true will cause this +/// layer to be skipped (directly replaced by its children). This can be helpful +/// to track down the cause of performance problems. +class ClipPathLayer extends ContainerLayer { + /// Creates a layer with a path-based clip. + /// + /// The [clipPath] and [clipBehavior] properties must be non-null before the + /// compositing phase of the pipeline. + ClipPathLayer({ + Path? clipPath, + Clip clipBehavior = Clip.antiAlias, + }) : _clipPath = clipPath, + _clipBehavior = clipBehavior, + assert(clipBehavior != Clip.none); + + /// The path to clip in the parent's coordinate system. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + Path? get clipPath => _clipPath; + Path? _clipPath; + set clipPath(Path? value) { + if (value != _clipPath) { + _clipPath = value; + markNeedsAddToScene(); + } + } + + @override + Rect? describeClipBounds() => clipPath?.getBounds(); + + /// {@macro flutter.rendering.ClipRectLayer.clipBehavior} + /// + /// Defaults to [Clip.antiAlias]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior; + set clipBehavior(Clip value) { + assert(value != Clip.none); + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsAddToScene(); + } + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + if (!clipPath!.contains(localPosition)) { + return false; + } + return super.findAnnotations<S>(result, localPosition, onlyFirst: onlyFirst); + } + + @override + void addToScene(ui.SceneBuilder builder) { + assert(clipPath != null); + bool enabled = true; + assert(() { + enabled = !debugDisableClipLayers; + return true; + }()); + if (enabled) { + engineLayer = builder.pushClipPath( + clipPath!, + clipBehavior: clipBehavior, + oldLayer: _engineLayer as ui.ClipPathEngineLayer?, + ); + } else { + engineLayer = null; + } + addChildrenToScene(builder); + if (enabled) { + builder.pop(); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior)); + } +} + +/// A composite layer that applies a [ColorFilter] to its children. +class ColorFilterLayer extends ContainerLayer { + /// Creates a layer that applies a [ColorFilter] to its children. + /// + /// The [colorFilter] property must be non-null before the compositing phase + /// of the pipeline. + ColorFilterLayer({ + ColorFilter? colorFilter, + }) : _colorFilter = colorFilter; + + /// The color filter to apply to children. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + ColorFilter? get colorFilter => _colorFilter; + ColorFilter? _colorFilter; + set colorFilter(ColorFilter? value) { + assert(value != null); + if (value != _colorFilter) { + _colorFilter = value; + markNeedsAddToScene(); + } + } + + @override + void addToScene(ui.SceneBuilder builder) { + assert(colorFilter != null); + engineLayer = builder.pushColorFilter( + colorFilter!, + oldLayer: _engineLayer as ui.ColorFilterEngineLayer?, + ); + addChildrenToScene(builder); + builder.pop(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ColorFilter>('colorFilter', colorFilter)); + } +} + +/// A composite layer that applies an [ImageFilter] to its children. +class ImageFilterLayer extends OffsetLayer { + /// Creates a layer that applies an [ImageFilter] to its children. + /// + /// The [imageFilter] property must be non-null before the compositing phase + /// of the pipeline. + ImageFilterLayer({ + ui.ImageFilter? imageFilter, + super.offset, + }) : _imageFilter = imageFilter; + + /// The image filter to apply to children. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + ui.ImageFilter? get imageFilter => _imageFilter; + ui.ImageFilter? _imageFilter; + set imageFilter(ui.ImageFilter? value) { + assert(value != null); + if (value != _imageFilter) { + _imageFilter = value; + markNeedsAddToScene(); + } + } + + @override + void addToScene(ui.SceneBuilder builder) { + assert(imageFilter != null); + engineLayer = builder.pushImageFilter( + imageFilter!, + offset: offset, + oldLayer: _engineLayer as ui.ImageFilterEngineLayer?, + ); + addChildrenToScene(builder); + builder.pop(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ui.ImageFilter>('imageFilter', imageFilter)); + } +} + +/// A composited layer that applies a given transformation matrix to its +/// children. +/// +/// This class inherits from [OffsetLayer] to make it one of the layers that +/// can be used at the root of a [RenderObject] hierarchy. +class TransformLayer extends OffsetLayer { + /// Creates a transform layer. + /// + /// The [transform] and [offset] properties must be non-null before the + /// compositing phase of the pipeline. + TransformLayer({ Matrix4? transform, super.offset }) + : _transform = transform; + + /// The matrix to apply. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + /// + /// This transform is applied before [offset], if both are set. + /// + /// The [transform] property must be non-null before the compositing phase of + /// the pipeline. + Matrix4? get transform => _transform; + Matrix4? _transform; + set transform(Matrix4? value) { + assert(value != null); + assert(value!.storage.every((double component) => component.isFinite)); + if (value == _transform) { + return; + } + _transform = value; + _inverseDirty = true; + markNeedsAddToScene(); + } + + Matrix4? _lastEffectiveTransform; + Matrix4? _invertedTransform; + bool _inverseDirty = true; + + @override + void addToScene(ui.SceneBuilder builder) { + assert(transform != null); + _lastEffectiveTransform = transform; + if (offset != Offset.zero) { + _lastEffectiveTransform = Matrix4.translationValues(offset.dx, offset.dy, 0.0) + ..multiply(_lastEffectiveTransform!); + } + engineLayer = builder.pushTransform( + _lastEffectiveTransform!.storage, + oldLayer: _engineLayer as ui.TransformEngineLayer?, + ); + addChildrenToScene(builder); + builder.pop(); + } + + Offset? _transformOffset(Offset localPosition) { + if (_inverseDirty) { + _invertedTransform = Matrix4.tryInvert( + PointerEvent.removePerspectiveTransform(transform!), + ); + _inverseDirty = false; + } + if (_invertedTransform == null) { + return null; + } + + return MatrixUtils.transformPoint(_invertedTransform!, localPosition); + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + final Offset? transformedOffset = _transformOffset(localPosition); + if (transformedOffset == null) { + return false; + } + return super.findAnnotations<S>(result, transformedOffset, onlyFirst: onlyFirst); + } + + @override + void applyTransform(Layer? child, Matrix4 transform) { + assert(child != null); + assert(_lastEffectiveTransform != null || this.transform != null); + if (_lastEffectiveTransform == null) { + transform.multiply(this.transform!); + } else { + transform.multiply(_lastEffectiveTransform!); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(TransformProperty('transform', transform)); + } +} + +/// A composited layer that makes its children partially transparent. +/// +/// When debugging, setting [debugDisableOpacityLayers] to true will cause this +/// layer to be skipped (directly replaced by its children). This can be helpful +/// to track down the cause of performance problems. +/// +/// Try to avoid an [OpacityLayer] with no children. Remove that layer if +/// possible to save some tree walks. +class OpacityLayer extends OffsetLayer { + /// Creates an opacity layer. + /// + /// The [alpha] property must be non-null before the compositing phase of + /// the pipeline. + OpacityLayer({ + int? alpha, + super.offset, + }) : _alpha = alpha; + + /// The amount to multiply into the alpha channel. + /// + /// The opacity is expressed as an integer from 0 to 255, where 0 is fully + /// transparent and 255 is fully opaque. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + int? get alpha => _alpha; + int? _alpha; + set alpha(int? value) { + assert(value != null); + if (value != _alpha) { + if (value == 255 || _alpha == 255) { + engineLayer = null; + } + _alpha = value; + markNeedsAddToScene(); + } + } + + @override + void addToScene(ui.SceneBuilder builder) { + assert(alpha != null); + + // Don't add this layer if there's no child. + bool enabled = firstChild != null; + if (!enabled) { + // Ensure the engineLayer is disposed. + engineLayer = null; + // TODO(dnfield): Remove this if/when we can fix https://github.com/flutter/flutter/issues/90004 + return; + } + + assert(() { + enabled = enabled && !debugDisableOpacityLayers; + return true; + }()); + + final int realizedAlpha = alpha!; + // The type assertions work because the [alpha] setter nulls out the + // engineLayer if it would have changed type (i.e. changed to or from 255). + if (enabled && realizedAlpha < 255) { + assert(_engineLayer is ui.OpacityEngineLayer?); + engineLayer = builder.pushOpacity( + realizedAlpha, + offset: offset, + oldLayer: _engineLayer as ui.OpacityEngineLayer?, + ); + } else { + assert(_engineLayer is ui.OffsetEngineLayer?); + engineLayer = builder.pushOffset( + offset.dx, + offset.dy, + oldLayer: _engineLayer as ui.OffsetEngineLayer?, + ); + } + addChildrenToScene(builder); + builder.pop(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('alpha', alpha)); + } +} + +/// A composited layer that applies a shader to its children. +/// +/// The shader is only applied inside the given [maskRect]. The shader itself +/// uses the top left of the [maskRect] as its origin. +/// +/// The [maskRect] does not affect the positions of any child layers. +class ShaderMaskLayer extends ContainerLayer { + /// Creates a shader mask layer. + /// + /// The [shader], [maskRect], and [blendMode] properties must be non-null + /// before the compositing phase of the pipeline. + ShaderMaskLayer({ + Shader? shader, + Rect? maskRect, + BlendMode? blendMode, + }) : _shader = shader, + _maskRect = maskRect, + _blendMode = blendMode; + + /// The shader to apply to the children. + /// + /// The origin of the shader (e.g. of the coordinate system used by the `from` + /// and `to` arguments to [ui.Gradient.linear]) is at the top left of the + /// [maskRect]. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + /// + /// See also: + /// + /// * [ui.Gradient] and [ui.ImageShader], two shader types that can be used. + Shader? get shader => _shader; + Shader? _shader; + set shader(Shader? value) { + if (value != _shader) { + _shader = value; + markNeedsAddToScene(); + } + } + + /// The position and size of the shader. + /// + /// The [shader] is only rendered inside this rectangle, using the top left of + /// the rectangle as its origin. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + Rect? get maskRect => _maskRect; + Rect? _maskRect; + set maskRect(Rect? value) { + if (value != _maskRect) { + _maskRect = value; + markNeedsAddToScene(); + } + } + + /// The blend mode to apply when blending the shader with the children. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + BlendMode? get blendMode => _blendMode; + BlendMode? _blendMode; + set blendMode(BlendMode? value) { + if (value != _blendMode) { + _blendMode = value; + markNeedsAddToScene(); + } + } + + @override + void addToScene(ui.SceneBuilder builder) { + assert(shader != null); + assert(maskRect != null); + assert(blendMode != null); + engineLayer = builder.pushShaderMask( + shader!, + maskRect! , + blendMode!, + oldLayer: _engineLayer as ui.ShaderMaskEngineLayer?, + ); + addChildrenToScene(builder); + builder.pop(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Shader>('shader', shader)); + properties.add(DiagnosticsProperty<Rect>('maskRect', maskRect)); + properties.add(EnumProperty<BlendMode>('blendMode', blendMode)); + } +} + +/// A composited layer that applies a filter to the existing contents of the scene. +class BackdropFilterLayer extends ContainerLayer { + /// Creates a backdrop filter layer. + /// + /// The [filter] property must be non-null before the compositing phase of the + /// pipeline. + /// + /// The [blendMode] property defaults to [BlendMode.srcOver]. + BackdropFilterLayer({ + ui.ImageFilter? filter, + BlendMode blendMode = BlendMode.srcOver, + }) : _filter = filter, + _blendMode = blendMode; + + /// The filter to apply to the existing contents of the scene. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + ui.ImageFilter? get filter => _filter; + ui.ImageFilter? _filter; + set filter(ui.ImageFilter? value) { + if (value != _filter) { + _filter = value; + markNeedsAddToScene(); + } + } + + /// The blend mode to use to apply the filtered background content onto the background + /// surface. + /// + /// The default value of this property is [BlendMode.srcOver]. + /// {@macro flutter.widgets.BackdropFilter.blendMode} + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + BlendMode get blendMode => _blendMode; + BlendMode _blendMode; + set blendMode(BlendMode value) { + if (value != _blendMode) { + _blendMode = value; + markNeedsAddToScene(); + } + } + + @override + void addToScene(ui.SceneBuilder builder) { + assert(filter != null); + engineLayer = builder.pushBackdropFilter( + filter!, + blendMode: blendMode, + oldLayer: _engineLayer as ui.BackdropFilterEngineLayer?, + ); + addChildrenToScene(builder); + builder.pop(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ui.ImageFilter>('filter', filter)); + properties.add(EnumProperty<BlendMode>('blendMode', blendMode)); + } +} + +/// An object that a [LeaderLayer] can register with. +/// +/// An instance of this class should be provided as the [LeaderLayer.link] and +/// the [FollowerLayer.link] properties to cause the [FollowerLayer] to follow +/// the [LeaderLayer]. +/// +/// See also: +/// +/// * [CompositedTransformTarget], the widget that creates a [LeaderLayer]. +/// * [CompositedTransformFollower], the widget that creates a [FollowerLayer]. +/// * [RenderLeaderLayer] and [RenderFollowerLayer], the corresponding +/// render objects. +class LayerLink { + /// The [LeaderLayer] connected to this link. + LeaderLayer? get leader => _leader; + LeaderLayer? _leader; + + void _registerLeader(LeaderLayer leader) { + assert(_leader != leader); + assert((){ + if (_leader != null) { + _debugPreviousLeaders ??= <LeaderLayer>{}; + _debugScheduleLeadersCleanUpCheck(); + return _debugPreviousLeaders!.add(_leader!); + } + return true; + }()); + _leader = leader; + } + + void _unregisterLeader(LeaderLayer leader) { + if (_leader == leader) { + _leader = null; + } else { + assert(_debugPreviousLeaders!.remove(leader)); + } + } + + /// Stores the previous leaders that were replaced by the current [_leader] + /// in the current frame. + /// + /// These leaders need to give up their leaderships of this link by the end of + /// the current frame. + Set<LeaderLayer>? _debugPreviousLeaders; + bool _debugLeaderCheckScheduled = false; + + /// Schedules the check as post frame callback to make sure the + /// [_debugPreviousLeaders] is empty. + void _debugScheduleLeadersCleanUpCheck() { + assert(_debugPreviousLeaders != null); + assert(() { + if (_debugLeaderCheckScheduled) { + return true; + } + _debugLeaderCheckScheduled = true; + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + _debugLeaderCheckScheduled = false; + assert(_debugPreviousLeaders!.isEmpty); + }, debugLabel: 'LayerLink.leadersCleanUpCheck'); + return true; + }()); + } + + /// The total size of the content of the connected [LeaderLayer]. + /// + /// Generally this should be set by the [RenderObject] that paints on the + /// registered [LeaderLayer] (for instance a [RenderLeaderLayer] that shares + /// this link with its followers). This size may be outdated before and during + /// layout. + Size? leaderSize; + + @override + String toString({ DiagnosticLevel minLevel = DiagnosticLevel.info }) { + return '${describeIdentity(this)}(${ _leader != null ? "<linked>" : "<dangling>" })'; + } +} + +/// A composited layer that can be followed by a [FollowerLayer]. +/// +/// This layer collapses the accumulated offset into a transform and passes +/// [Offset.zero] to its child layers in the [addToScene]/[addChildrenToScene] +/// methods, so that [applyTransform] will work reliably. +class LeaderLayer extends ContainerLayer { + /// Creates a leader layer. + /// + /// The [link] property must not have been provided to any other [LeaderLayer] + /// layers that are [attached] to the layer tree at the same time. + /// + /// The [offset] property must be non-null before the compositing phase of the + /// pipeline. + LeaderLayer({ required LayerLink link, Offset offset = Offset.zero }) : _link = link, _offset = offset; + + /// The object with which this layer should register. + /// + /// The link will be established when this layer is [attach]ed, and will be + /// cleared when this layer is [detach]ed. + LayerLink get link => _link; + LayerLink _link; + set link(LayerLink value) { + if (_link == value) { + return; + } + if (attached) { + _link._unregisterLeader(this); + value._registerLeader(this); + } + _link = value; + } + + /// Offset from parent in the parent's coordinate system. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + /// + /// The [offset] property must be non-null before the compositing phase of the + /// pipeline. + Offset get offset => _offset; + Offset _offset; + set offset(Offset value) { + if (value == _offset) { + return; + } + _offset = value; + if (!alwaysNeedsAddToScene) { + markNeedsAddToScene(); + } + } + + @override + void attach(Object owner) { + super.attach(owner); + _link._registerLeader(this); + } + + @override + void detach() { + _link._unregisterLeader(this); + super.detach(); + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + return super.findAnnotations<S>(result, localPosition - offset, onlyFirst: onlyFirst); + } + + @override + void addToScene(ui.SceneBuilder builder) { + if (offset != Offset.zero) { + engineLayer = builder.pushTransform( + Matrix4.translationValues(offset.dx, offset.dy, 0.0).storage, + oldLayer: _engineLayer as ui.TransformEngineLayer?, + ); + } else { + engineLayer = null; + } + addChildrenToScene(builder); + if (offset != Offset.zero) { + builder.pop(); + } + } + + /// Applies the transform that would be applied when compositing the given + /// child to the given matrix. + /// + /// See [ContainerLayer.applyTransform] for details. + /// + /// The `child` argument may be null, as the same transform is applied to all + /// children. + @override + void applyTransform(Layer? child, Matrix4 transform) { + if (offset != Offset.zero) { + transform.translate(offset.dx, offset.dy); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Offset>('offset', offset)); + properties.add(DiagnosticsProperty<LayerLink>('link', link)); + } +} + +/// A composited layer that applies a transformation matrix to its children such +/// that they are positioned to match a [LeaderLayer]. +/// +/// If any of the ancestors of this layer have a degenerate matrix (e.g. scaling +/// by zero), then the [FollowerLayer] will not be able to transform its child +/// to the coordinate space of the [LeaderLayer]. +/// +/// A [linkedOffset] property can be provided to further offset the child layer +/// from the leader layer, for example if the child is to follow the linked +/// layer at a distance rather than directly overlapping it. +class FollowerLayer extends ContainerLayer { + /// Creates a follower layer. + /// + /// The [unlinkedOffset], [linkedOffset], and [showWhenUnlinked] properties + /// must be non-null before the compositing phase of the pipeline. + FollowerLayer({ + required this.link, + this.showWhenUnlinked = true, + this.unlinkedOffset = Offset.zero, + this.linkedOffset = Offset.zero, + }); + + /// The link to the [LeaderLayer]. + /// + /// The same object should be provided to a [LeaderLayer] that is earlier in + /// the layer tree. When this layer is composited, it will apply a transform + /// that moves its children to match the position of the [LeaderLayer]. + LayerLink link; + + /// Whether to show the layer's contents when the [link] does not point to a + /// [LeaderLayer]. + /// + /// When the layer is linked, children layers are positioned such that they + /// have the same global position as the linked [LeaderLayer]. + /// + /// When the layer is not linked, then: if [showWhenUnlinked] is true, + /// children are positioned as if the [FollowerLayer] was a [ContainerLayer]; + /// if it is false, then children are hidden. + /// + /// The [showWhenUnlinked] property must be non-null before the compositing + /// phase of the pipeline. + bool? showWhenUnlinked; + + /// Offset from parent in the parent's coordinate system, used when the layer + /// is not linked to a [LeaderLayer]. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + /// + /// The [unlinkedOffset] property must be non-null before the compositing + /// phase of the pipeline. + /// + /// See also: + /// + /// * [linkedOffset], for when the layers are linked. + Offset? unlinkedOffset; + + /// Offset from the origin of the leader layer to the origin of the child + /// layers, used when the layer is linked to a [LeaderLayer]. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + /// + /// The [linkedOffset] property must be non-null before the compositing phase + /// of the pipeline. + /// + /// See also: + /// + /// * [unlinkedOffset], for when the layer is not linked. + Offset? linkedOffset; + + Offset? _lastOffset; + Matrix4? _lastTransform; + Matrix4? _invertedTransform; + bool _inverseDirty = true; + + Offset? _transformOffset(Offset localPosition) { + if (_inverseDirty) { + _invertedTransform = Matrix4.tryInvert(getLastTransform()!); + _inverseDirty = false; + } + if (_invertedTransform == null) { + return null; + } + final Vector4 vector = Vector4(localPosition.dx, localPosition.dy, 0.0, 1.0); + final Vector4 result = _invertedTransform!.transform(vector); + return Offset(result[0] - linkedOffset!.dx, result[1] - linkedOffset!.dy); + } + + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + if (link.leader == null) { + if (showWhenUnlinked!) { + return super.findAnnotations(result, localPosition - unlinkedOffset!, onlyFirst: onlyFirst); + } + return false; + } + final Offset? transformedOffset = _transformOffset(localPosition); + if (transformedOffset == null) { + return false; + } + return super.findAnnotations<S>(result, transformedOffset, onlyFirst: onlyFirst); + } + + /// The transform that was used during the last composition phase. + /// + /// If the [link] was not linked to a [LeaderLayer], or if this layer has + /// a degenerate matrix applied, then this will be null. + /// + /// This method returns a new [Matrix4] instance each time it is invoked. + Matrix4? getLastTransform() { + if (_lastTransform == null) { + return null; + } + final Matrix4 result = Matrix4.translationValues(-_lastOffset!.dx, -_lastOffset!.dy, 0.0); + result.multiply(_lastTransform!); + return result; + } + + /// Call [applyTransform] for each layer in the provided list. + /// + /// The list is in reverse order (deepest first). The first layer will be + /// treated as the child of the second, and so forth. The first layer in the + /// list won't have [applyTransform] called on it. The first layer may be + /// null. + static Matrix4 _collectTransformForLayerChain(List<ContainerLayer?> layers) { + // Initialize our result matrix. + final Matrix4 result = Matrix4.identity(); + // Apply each layer to the matrix in turn, starting from the last layer, + // and providing the previous layer as the child. + for (int index = layers.length - 1; index > 0; index -= 1) { + layers[index]?.applyTransform(layers[index - 1], result); + } + return result; + } + + /// Find the common ancestor of two layers [a] and [b] by searching towards + /// the root of the tree, and append each ancestor of [a] or [b] visited along + /// the path to [ancestorsA] and [ancestorsB] respectively. + /// + /// Returns null if [a] [b] do not share a common ancestor, in which case the + /// results in [ancestorsA] and [ancestorsB] are undefined. + static Layer? _pathsToCommonAncestor( + Layer? a, + Layer? b, + List<ContainerLayer?> ancestorsA, + List<ContainerLayer?> ancestorsB, + ) { + // No common ancestor found. + if (a == null || b == null) { + return null; + } + + if (identical(a, b)) { + return a; + } + + if (a.depth < b.depth) { + ancestorsB.add(b.parent); + return _pathsToCommonAncestor(a, b.parent, ancestorsA, ancestorsB); + } else if (a.depth > b.depth) { + ancestorsA.add(a.parent); + return _pathsToCommonAncestor(a.parent, b, ancestorsA, ancestorsB); + } + + ancestorsA.add(a.parent); + ancestorsB.add(b.parent); + return _pathsToCommonAncestor(a.parent, b.parent, ancestorsA, ancestorsB); + } + + bool _debugCheckLeaderBeforeFollower( + List<ContainerLayer> leaderToCommonAncestor, + List<ContainerLayer> followerToCommonAncestor, + ) { + if (followerToCommonAncestor.length <= 1) { + // Follower is the common ancestor, ergo the leader must come AFTER the follower. + return false; + } + if (leaderToCommonAncestor.length <= 1) { + // Leader is the common ancestor, ergo the leader must come BEFORE the follower. + return true; + } + + // Common ancestor is neither the leader nor the follower. + final ContainerLayer leaderSubtreeBelowAncestor = leaderToCommonAncestor[leaderToCommonAncestor.length - 2]; + final ContainerLayer followerSubtreeBelowAncestor = followerToCommonAncestor[followerToCommonAncestor.length - 2]; + + Layer? sibling = leaderSubtreeBelowAncestor; + while (sibling != null) { + if (sibling == followerSubtreeBelowAncestor) { + return true; + } + sibling = sibling.nextSibling; + } + // The follower subtree didn't come after the leader subtree. + return false; + } + + /// Populate [_lastTransform] given the current state of the tree. + void _establishTransform() { + _lastTransform = null; + final LeaderLayer? leader = link.leader; + // Check to see if we are linked. + if (leader == null) { + return; + } + // If we're linked, check the link is valid. + assert( + leader.owner == owner, + 'Linked LeaderLayer anchor is not in the same layer tree as the FollowerLayer.', + ); + + // Stores [leader, ..., commonAncestor] after calling _pathsToCommonAncestor. + final List<ContainerLayer> forwardLayers = <ContainerLayer>[leader]; + // Stores [this (follower), ..., commonAncestor] after calling + // _pathsToCommonAncestor. + final List<ContainerLayer> inverseLayers = <ContainerLayer>[this]; + + final Layer? ancestor = _pathsToCommonAncestor( + leader, this, + forwardLayers, inverseLayers, + ); + assert( + ancestor != null, + 'LeaderLayer and FollowerLayer do not have a common ancestor.', + ); + assert( + _debugCheckLeaderBeforeFollower(forwardLayers, inverseLayers), + 'LeaderLayer anchor must come before FollowerLayer in paint order, but the reverse was true.', + ); + + final Matrix4 forwardTransform = _collectTransformForLayerChain(forwardLayers); + // Further transforms the coordinate system to a hypothetical child (null) + // of the leader layer, to account for the leader's additional paint offset + // and layer offset (LeaderLayer.offset). + leader.applyTransform(null, forwardTransform); + forwardTransform.translate(linkedOffset!.dx, linkedOffset!.dy); + + final Matrix4 inverseTransform = _collectTransformForLayerChain(inverseLayers); + + if (inverseTransform.invert() == 0.0) { + // We are in a degenerate transform, so there's not much we can do. + return; + } + // Combine the matrices and store the result. + inverseTransform.multiply(forwardTransform); + _lastTransform = inverseTransform; + _inverseDirty = true; + } + + /// {@template flutter.rendering.FollowerLayer.alwaysNeedsAddToScene} + /// This disables retained rendering. + /// + /// A [FollowerLayer] copies changes from a [LeaderLayer] that could be anywhere + /// in the Layer tree, and that leader layer could change without notifying the + /// follower layer. Therefore we have to always call a follower layer's + /// [addToScene]. In order to call follower layer's [addToScene], leader layer's + /// [addToScene] must be called first so leader layer must also be considered + /// as [alwaysNeedsAddToScene]. + /// {@endtemplate} + @override + bool get alwaysNeedsAddToScene => true; + + @override + void addToScene(ui.SceneBuilder builder) { + assert(showWhenUnlinked != null); + if (link.leader == null && !showWhenUnlinked!) { + _lastTransform = null; + _lastOffset = null; + _inverseDirty = true; + engineLayer = null; + return; + } + _establishTransform(); + if (_lastTransform != null) { + _lastOffset = unlinkedOffset; + engineLayer = builder.pushTransform( + _lastTransform!.storage, + oldLayer: _engineLayer as ui.TransformEngineLayer?, + ); + addChildrenToScene(builder); + builder.pop(); + } else { + _lastOffset = null; + final Matrix4 matrix = Matrix4.translationValues(unlinkedOffset!.dx, unlinkedOffset!.dy, .0); + engineLayer = builder.pushTransform( + matrix.storage, + oldLayer: _engineLayer as ui.TransformEngineLayer?, + ); + addChildrenToScene(builder); + builder.pop(); + } + _inverseDirty = true; + } + + @override + void applyTransform(Layer? child, Matrix4 transform) { + assert(child != null); + if (_lastTransform != null) { + transform.multiply(_lastTransform!); + } else { + transform.multiply(Matrix4.translationValues(unlinkedOffset!.dx, unlinkedOffset!.dy, 0)); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<LayerLink>('link', link)); + properties.add(TransformProperty('transform', getLastTransform(), defaultValue: null)); + } +} + +/// A composited layer which annotates its children with a value. Pushing this +/// layer to the tree is the common way of adding an annotation. +/// +/// An annotation is an optional object of any type that, when attached with a +/// layer, can be retrieved using [Layer.find] or [Layer.findAllAnnotations] +/// with a position. The search process is done recursively, controlled by a +/// concept of being opaque to a type of annotation, explained in the document +/// of [Layer.findAnnotations]. +/// +/// When an annotation search arrives, this layer defers the same search to each +/// of this layer's children, respecting their opacity. Then it adds this +/// layer's annotation if all of the following restrictions are met: +/// +/// {@template flutter.rendering.AnnotatedRegionLayer.restrictions} +/// * The target type must be identical to the annotated type `T`. +/// * If [size] is provided, the target position must be contained within the +/// rectangle formed by [size] and [offset]. +/// {@endtemplate} +/// +/// This layer is opaque to a type of annotation if any child is also opaque, or +/// if [opaque] is true and the layer's annotation is added. +class AnnotatedRegionLayer<T extends Object> extends ContainerLayer { + /// Creates a new layer that annotates its children with [value]. + AnnotatedRegionLayer( + this.value, { + this.size, + Offset? offset, + this.opaque = false, + }) : offset = offset ?? Offset.zero; + + /// The annotated object, which is added to the result if all restrictions are + /// met. + final T value; + + /// The size of the annotated object. + /// + /// If [size] is provided, then the annotation is found only if the target + /// position is contained by the rectangle formed by [size] and [offset]. + /// Otherwise no such restriction is applied, and clipping can only be done by + /// the ancestor layers. + final Size? size; + + /// The position of the annotated object. + /// + /// The [offset] defaults to [Offset.zero] if not provided, and is ignored if + /// [size] is not set. + /// + /// The [offset] only offsets the clipping rectangle, and does not affect + /// how the painting or annotation search is propagated to its children. + final Offset offset; + + /// Whether the annotation of this layer should be opaque during an annotation + /// search of type `T`, preventing siblings visually behind it from being + /// searched. + /// + /// If [opaque] is true, and this layer does add its annotation [value], + /// then the layer will always be opaque during the search. + /// + /// If [opaque] is false, or if this layer does not add its annotation, + /// then the opacity of this layer will be the one returned by the children, + /// meaning that it will be opaque if any child is opaque. + /// + /// The [opaque] defaults to false. + /// + /// The [opaque] is effectively useless during [Layer.find] (more + /// specifically, [Layer.findAnnotations] with `onlyFirst: true`), since the + /// search process then skips the remaining tree after finding the first + /// annotation. + /// + /// See also: + /// + /// * [Layer.findAnnotations], which explains the concept of being opaque + /// to a type of annotation as the return value. + /// * [HitTestBehavior], which controls similar logic when hit-testing in the + /// render tree. + final bool opaque; + + /// Searches the subtree for annotations of type `S` at the location + /// `localPosition`, then adds the annotation [value] if applicable. + /// + /// This method always searches its children, and if any child returns `true`, + /// the remaining children are skipped. Regardless of what the children + /// return, this method then adds this layer's annotation if all of the + /// following restrictions are met: + /// + /// {@macro flutter.rendering.AnnotatedRegionLayer.restrictions} + /// + /// This search process respects `onlyFirst`, meaning that when `onlyFirst` is + /// true, the search will stop when it finds the first annotation from the + /// children, and the layer's own annotation is checked only when none is + /// given by the children. + /// + /// The return value is true if any child returns `true`, or if [opaque] is + /// true and the layer's annotation is added. + /// + /// For explanation of layer annotations, parameters and return value, refer + /// to [Layer.findAnnotations]. + @override + bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) { + bool isAbsorbed = super.findAnnotations(result, localPosition, onlyFirst: onlyFirst); + if (result.entries.isNotEmpty && onlyFirst) { + return isAbsorbed; + } + if (size != null && !(offset & size!).contains(localPosition)) { + return isAbsorbed; + } + if (T == S) { + isAbsorbed = isAbsorbed || opaque; + final Object untypedValue = value; + final S typedValue = untypedValue as S; + result.add(AnnotationEntry<S>( + annotation: typedValue, + localPosition: localPosition - offset, + )); + } + return isAbsorbed; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<T>('value', value)); + properties.add(DiagnosticsProperty<Size>('size', size, defaultValue: null)); + properties.add(DiagnosticsProperty<Offset>('offset', offset, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('opaque', opaque, defaultValue: false)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/layout_helper.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/layout_helper.dart new file mode 100644 index 0000000000000000000000000000000000000000..fc7f35152f18444633db8e00f96f453a3cb2bb70 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/layout_helper.dart @@ -0,0 +1,55 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'box.dart'; + +/// Signature for a function that takes a [RenderBox] and returns the [Size] +/// that the [RenderBox] would have if it were laid out with the given +/// [BoxConstraints]. +/// +/// The methods of [ChildLayoutHelper] adhere to this signature. +typedef ChildLayouter = Size Function(RenderBox child, BoxConstraints constraints); + +/// A collection of static functions to layout a [RenderBox] child with the +/// given set of [BoxConstraints]. +/// +/// All of the functions adhere to the [ChildLayouter] signature. +abstract final class ChildLayoutHelper { + /// Returns the [Size] that the [RenderBox] would have if it were to + /// be laid out with the given [BoxConstraints]. + /// + /// This method calls [RenderBox.getDryLayout] on the given [RenderBox]. + /// + /// This method should only be called by the parent of the provided + /// [RenderBox] child as it binds parent and child together (if the child + /// is marked as dirty, the child will also be marked as dirty). + /// + /// See also: + /// + /// * [layoutChild], which actually lays out the child with the given + /// constraints. + static Size dryLayoutChild(RenderBox child, BoxConstraints constraints) { + return child.getDryLayout(constraints); + } + + /// Lays out the [RenderBox] with the given constraints and returns its + /// [Size]. + /// + /// This method calls [RenderBox.layout] on the given [RenderBox] with + /// `parentUsesSize` set to true to receive its [Size]. + /// + /// This method should only be called by the parent of the provided + /// [RenderBox] child as it binds parent and child together (if the child + /// is marked as dirty, the child will also be marked as dirty). + /// + /// See also: + /// + /// * [dryLayoutChild], which does not perform a real layout of the child. + static Size layoutChild(RenderBox child, BoxConstraints constraints) { + child.layout(constraints, parentUsesSize: true); + return child.size; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/list_body.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/list_body.dart new file mode 100644 index 0000000000000000000000000000000000000000..97f961a156958ddc13d87a622baec03bcbc42f78 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/list_body.dart @@ -0,0 +1,308 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'object.dart'; + +/// Parent data for use with [RenderListBody]. +class ListBodyParentData extends ContainerBoxParentData<RenderBox> { } + +typedef _ChildSizingFunction = double Function(RenderBox child); + +/// Displays its children sequentially along a given axis, forcing them to the +/// dimensions of the parent in the other axis. +/// +/// This layout algorithm arranges its children linearly along the main axis +/// (either horizontally or vertically). In the cross axis, children are +/// stretched to match the box's cross-axis extent. In the main axis, children +/// are given unlimited space and the box expands its main axis to contain all +/// its children. Because [RenderListBody] boxes expand in the main axis, they +/// must be given unlimited space in the main axis, typically by being contained +/// in a viewport with a scrolling direction that matches the box's main axis. +class RenderListBody extends RenderBox + with ContainerRenderObjectMixin<RenderBox, ListBodyParentData>, + RenderBoxContainerDefaultsMixin<RenderBox, ListBodyParentData> { + /// Creates a render object that arranges its children sequentially along a + /// given axis. + /// + /// By default, children are arranged along the vertical axis. + RenderListBody({ + List<RenderBox>? children, + AxisDirection axisDirection = AxisDirection.down, + }) : _axisDirection = axisDirection { + addAll(children); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! ListBodyParentData) { + child.parentData = ListBodyParentData(); + } + } + + /// The direction in which the children are laid out. + /// + /// For example, if the [axisDirection] is [AxisDirection.down], each child + /// will be laid out below the next, vertically. + AxisDirection get axisDirection => _axisDirection; + AxisDirection _axisDirection; + set axisDirection(AxisDirection value) { + if (_axisDirection == value) { + return; + } + _axisDirection = value; + markNeedsLayout(); + } + + /// The axis (horizontal or vertical) corresponding to the current + /// [axisDirection]. + Axis get mainAxis => axisDirectionToAxis(axisDirection); + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + assert(_debugCheckConstraints(constraints)); + double mainAxisExtent = 0.0; + RenderBox? child = firstChild; + switch (axisDirection) { + case AxisDirection.right: + case AxisDirection.left: + final BoxConstraints innerConstraints = BoxConstraints.tightFor(height: constraints.maxHeight); + while (child != null) { + final Size childSize = child.getDryLayout(innerConstraints); + mainAxisExtent += childSize.width; + child = childAfter(child); + } + return constraints.constrain(Size(mainAxisExtent, constraints.maxHeight)); + case AxisDirection.up: + case AxisDirection.down: + final BoxConstraints innerConstraints = BoxConstraints.tightFor(width: constraints.maxWidth); + while (child != null) { + final Size childSize = child.getDryLayout(innerConstraints); + mainAxisExtent += childSize.height; + child = childAfter(child); + } + return constraints.constrain(Size(constraints.maxWidth, mainAxisExtent)); + } + } + + bool _debugCheckConstraints(BoxConstraints constraints) { + assert(() { + switch (mainAxis) { + case Axis.horizontal: + if (!constraints.hasBoundedWidth) { + return true; + } + case Axis.vertical: + if (!constraints.hasBoundedHeight) { + return true; + } + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('RenderListBody must have unlimited space along its main axis.'), + ErrorDescription( + 'RenderListBody does not clip or resize its children, so it must be ' + 'placed in a parent that does not constrain the main ' + 'axis.', + ), + ErrorHint( + 'You probably want to put the RenderListBody inside a ' + 'RenderViewport with a matching main axis.', + ), + ]); + }()); + assert(() { + switch (mainAxis) { + case Axis.horizontal: + if (constraints.hasBoundedHeight) { + return true; + } + case Axis.vertical: + if (constraints.hasBoundedWidth) { + return true; + } + } + // TODO(ianh): Detect if we're actually nested blocks and say something + // more specific to the exact situation in that case, and don't mention + // nesting blocks in the negative case. + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('RenderListBody must have a bounded constraint for its cross axis.'), + ErrorDescription( + "RenderListBody forces its children to expand to fit the RenderListBody's container, " + 'so it must be placed in a parent that constrains the cross ' + 'axis to a finite dimension.', + ), + // TODO(jacobr): this hint is a great candidate to promote to being an + // automated quick fix in the future. + ErrorHint( + 'If you are attempting to nest a RenderListBody with ' + 'one direction inside one of another direction, you will want to ' + 'wrap the inner one inside a box that fixes the dimension in that direction, ' + 'for example, a RenderIntrinsicWidth or RenderIntrinsicHeight object. ' + 'This is relatively expensive, however.', // (that's why we don't do it automatically) + ), + ]); + }()); + return true; + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + assert(_debugCheckConstraints(constraints)); + double mainAxisExtent = 0.0; + RenderBox? child = firstChild; + switch (axisDirection) { + case AxisDirection.right: + final BoxConstraints innerConstraints = BoxConstraints.tightFor(height: constraints.maxHeight); + while (child != null) { + child.layout(innerConstraints, parentUsesSize: true); + final ListBodyParentData childParentData = child.parentData! as ListBodyParentData; + childParentData.offset = Offset(mainAxisExtent, 0.0); + mainAxisExtent += child.size.width; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + size = constraints.constrain(Size(mainAxisExtent, constraints.maxHeight)); + case AxisDirection.left: + final BoxConstraints innerConstraints = BoxConstraints.tightFor(height: constraints.maxHeight); + while (child != null) { + child.layout(innerConstraints, parentUsesSize: true); + final ListBodyParentData childParentData = child.parentData! as ListBodyParentData; + mainAxisExtent += child.size.width; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + double position = 0.0; + child = firstChild; + while (child != null) { + final ListBodyParentData childParentData = child.parentData! as ListBodyParentData; + position += child.size.width; + childParentData.offset = Offset(mainAxisExtent - position, 0.0); + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + size = constraints.constrain(Size(mainAxisExtent, constraints.maxHeight)); + case AxisDirection.down: + final BoxConstraints innerConstraints = BoxConstraints.tightFor(width: constraints.maxWidth); + while (child != null) { + child.layout(innerConstraints, parentUsesSize: true); + final ListBodyParentData childParentData = child.parentData! as ListBodyParentData; + childParentData.offset = Offset(0.0, mainAxisExtent); + mainAxisExtent += child.size.height; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + size = constraints.constrain(Size(constraints.maxWidth, mainAxisExtent)); + case AxisDirection.up: + final BoxConstraints innerConstraints = BoxConstraints.tightFor(width: constraints.maxWidth); + while (child != null) { + child.layout(innerConstraints, parentUsesSize: true); + final ListBodyParentData childParentData = child.parentData! as ListBodyParentData; + mainAxisExtent += child.size.height; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + double position = 0.0; + child = firstChild; + while (child != null) { + final ListBodyParentData childParentData = child.parentData! as ListBodyParentData; + position += child.size.height; + childParentData.offset = Offset(0.0, mainAxisExtent - position); + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + size = constraints.constrain(Size(constraints.maxWidth, mainAxisExtent)); + } + assert(size.isFinite); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<AxisDirection>('axisDirection', axisDirection)); + } + + double _getIntrinsicCrossAxis(_ChildSizingFunction childSize) { + double extent = 0.0; + RenderBox? child = firstChild; + while (child != null) { + extent = math.max(extent, childSize(child)); + final ListBodyParentData childParentData = child.parentData! as ListBodyParentData; + child = childParentData.nextSibling; + } + return extent; + } + + double _getIntrinsicMainAxis(_ChildSizingFunction childSize) { + double extent = 0.0; + RenderBox? child = firstChild; + while (child != null) { + extent += childSize(child); + final ListBodyParentData childParentData = child.parentData! as ListBodyParentData; + child = childParentData.nextSibling; + } + return extent; + } + + @override + double computeMinIntrinsicWidth(double height) { + switch (mainAxis) { + case Axis.horizontal: + return _getIntrinsicMainAxis((RenderBox child) => child.getMinIntrinsicWidth(height)); + case Axis.vertical: + return _getIntrinsicCrossAxis((RenderBox child) => child.getMinIntrinsicWidth(height)); + } + } + + @override + double computeMaxIntrinsicWidth(double height) { + switch (mainAxis) { + case Axis.horizontal: + return _getIntrinsicMainAxis((RenderBox child) => child.getMaxIntrinsicWidth(height)); + case Axis.vertical: + return _getIntrinsicCrossAxis((RenderBox child) => child.getMaxIntrinsicWidth(height)); + } + } + + @override + double computeMinIntrinsicHeight(double width) { + switch (mainAxis) { + case Axis.horizontal: + return _getIntrinsicMainAxis((RenderBox child) => child.getMinIntrinsicHeight(width)); + case Axis.vertical: + return _getIntrinsicCrossAxis((RenderBox child) => child.getMinIntrinsicHeight(width)); + } + } + + @override + double computeMaxIntrinsicHeight(double width) { + switch (mainAxis) { + case Axis.horizontal: + return _getIntrinsicMainAxis((RenderBox child) => child.getMaxIntrinsicHeight(width)); + case Axis.vertical: + return _getIntrinsicCrossAxis((RenderBox child) => child.getMaxIntrinsicHeight(width)); + } + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + return defaultComputeDistanceToFirstActualBaseline(baseline); + } + + @override + void paint(PaintingContext context, Offset offset) { + defaultPaint(context, offset); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + return defaultHitTestChildren(result, position: position); + } + +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/list_wheel_viewport.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/list_wheel_viewport.dart new file mode 100644 index 0000000000000000000000000000000000000000..fa6077dac4b93255337455517974ab6273dfa314 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/list_wheel_viewport.dart @@ -0,0 +1,1178 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; +import 'package:vector_math/vector_math_64.dart' show Matrix4; + +import 'box.dart'; +import 'layer.dart'; +import 'object.dart'; +import 'proxy_box.dart'; +import 'viewport.dart'; +import 'viewport_offset.dart'; + +typedef _ChildSizingFunction = double Function(RenderBox child); + +/// A delegate used by [RenderListWheelViewport] to manage its children. +/// +/// [RenderListWheelViewport] during layout will ask the delegate to create +/// children that are visible in the viewport and remove those that are not. +abstract class ListWheelChildManager { + /// The maximum number of children that can be provided to + /// [RenderListWheelViewport]. + /// + /// If non-null, the children will have index in the range + /// `[0, childCount - 1]`. + /// + /// If null, then there's no explicit limits to the range of the children + /// except that it has to be contiguous. If [childExistsAt] for a certain + /// index returns false, that index is already past the limit. + int? get childCount; + + /// Checks whether the delegate is able to provide a child widget at the given + /// index. + /// + /// This function is not about whether the child at the given index is + /// attached to the [RenderListWheelViewport] or not. + bool childExistsAt(int index); + + /// Creates a new child at the given index and updates it to the child list + /// of [RenderListWheelViewport]. If no child corresponds to `index`, then do + /// nothing. + /// + /// It is possible to create children with negative indices. + void createChild(int index, { required RenderBox? after }); + + /// Removes the child element corresponding with the given RenderBox. + void removeChild(RenderBox child); +} + +/// [ParentData] for use with [RenderListWheelViewport]. +class ListWheelParentData extends ContainerBoxParentData<RenderBox> { + /// Index of this child in its parent's child list. + /// + /// This must be maintained by the [ListWheelChildManager]. + int? index; + + /// Transform applied to this child during painting. + /// + /// Can be used to find the local bounds of this child in the viewport, + /// and then use it, for example, in hit testing. + /// + /// May be null if child was laid out, but not painted + /// by the parent, but normally this shouldn't happen, + /// because [RenderListWheelViewport] paints all of the + /// children it has laid out. + Matrix4? transform; +} + +/// Render, onto a wheel, a bigger sequential set of objects inside this viewport. +/// +/// Takes a scrollable set of fixed sized [RenderBox]es and renders them +/// sequentially from top down on a vertical scrolling axis. +/// +/// It starts with the first scrollable item in the center of the main axis +/// and ends with the last scrollable item in the center of the main axis. This +/// is in contrast to typical lists that start with the first scrollable item +/// at the start of the main axis and ends with the last scrollable item at the +/// end of the main axis. +/// +/// Instead of rendering its children on a flat plane, it renders them +/// as if each child is broken into its own plane and that plane is +/// perpendicularly fixed onto a cylinder which rotates along the scrolling +/// axis. +/// +/// This class works in 3 coordinate systems: +/// +/// 1. The **scrollable layout coordinates**. This coordinate system is used to +/// communicate with [ViewportOffset] and describes its children's abstract +/// offset from the beginning of the scrollable list at (0.0, 0.0). +/// +/// The list is scrollable from the start of the first child item to the +/// start of the last child item. +/// +/// Children's layout coordinates don't change as the viewport scrolls. +/// +/// 2. The **untransformed plane's viewport painting coordinates**. Children are +/// not painted in this coordinate system. It's an abstract intermediary used +/// before transforming into the next cylindrical coordinate system. +/// +/// This system is the **scrollable layout coordinates** translated by the +/// scroll offset such that (0.0, 0.0) is the top left corner of the +/// viewport. +/// +/// Because the viewport is centered at the scrollable list's scroll offset +/// instead of starting at the scroll offset, there are paintable children +/// ~1/2 viewport length before and after the scroll offset instead of ~1 +/// viewport length after the scroll offset. +/// +/// Children's visibility inclusion in the viewport is determined in this +/// system regardless of the cylinder's properties such as [diameterRatio] +/// or [perspective]. In other words, a 100px long viewport will always +/// paint 10-11 visible 10px children if there are enough children in the +/// viewport. +/// +/// 3. The **transformed cylindrical space viewport painting coordinates**. +/// Children from system 2 get their positions transformed into a cylindrical +/// projection matrix instead of its Cartesian offset with respect to the +/// scroll offset. +/// +/// Children in this coordinate system are painted. +/// +/// The wheel's size and the maximum and minimum visible angles are both +/// controlled by [diameterRatio]. Children visible in the **untransformed +/// plane's viewport painting coordinates**'s viewport will be radially +/// evenly laid out between the maximum and minimum angles determined by +/// intersecting the viewport's main axis length with a cylinder whose +/// diameter is [diameterRatio] times longer, as long as those angles are +/// between -pi/2 and pi/2. +/// +/// For example, if [diameterRatio] is 2.0 and this [RenderListWheelViewport] +/// is 100.0px in the main axis, then the diameter is 200.0. And children +/// will be evenly laid out between that cylinder's -arcsin(1/2) and +/// arcsin(1/2) angles. +/// +/// The cylinder's 0 degree side is always centered in the +/// [RenderListWheelViewport]. The transformation from **untransformed +/// plane's viewport painting coordinates** is also done such that the child +/// in the center of that plane will be mostly untransformed with children +/// above and below it being transformed more as the angle increases. +class RenderListWheelViewport + extends RenderBox + with ContainerRenderObjectMixin<RenderBox, ListWheelParentData> + implements RenderAbstractViewport { + /// Creates a [RenderListWheelViewport] which renders children on a wheel. + /// + /// Optional arguments have reasonable defaults. + RenderListWheelViewport({ + required this.childManager, + required ViewportOffset offset, + double diameterRatio = defaultDiameterRatio, + double perspective = defaultPerspective, + double offAxisFraction = 0, + bool useMagnifier = false, + double magnification = 1, + double overAndUnderCenterOpacity = 1, + required double itemExtent, + double squeeze = 1, + bool renderChildrenOutsideViewport = false, + Clip clipBehavior = Clip.none, + List<RenderBox>? children, + }) : assert(diameterRatio > 0, diameterRatioZeroMessage), + assert(perspective > 0), + assert(perspective <= 0.01, perspectiveTooHighMessage), + assert(magnification > 0), + assert(overAndUnderCenterOpacity >= 0 && overAndUnderCenterOpacity <= 1), + assert(squeeze > 0), + assert(itemExtent > 0), + assert( + !renderChildrenOutsideViewport || clipBehavior == Clip.none, + clipBehaviorAndRenderChildrenOutsideViewportConflict, + ), + _offset = offset, + _diameterRatio = diameterRatio, + _perspective = perspective, + _offAxisFraction = offAxisFraction, + _useMagnifier = useMagnifier, + _magnification = magnification, + _overAndUnderCenterOpacity = overAndUnderCenterOpacity, + _itemExtent = itemExtent, + _squeeze = squeeze, + _renderChildrenOutsideViewport = renderChildrenOutsideViewport, + _clipBehavior = clipBehavior { + addAll(children); + } + + /// An arbitrary but aesthetically reasonable default value for [diameterRatio]. + static const double defaultDiameterRatio = 2.0; + + /// An arbitrary but aesthetically reasonable default value for [perspective]. + static const double defaultPerspective = 0.003; + + /// An error message to show when the provided [diameterRatio] is zero. + static const String diameterRatioZeroMessage = "You can't set a diameterRatio " + 'of 0 or of a negative number. It would imply a cylinder of 0 in diameter ' + 'in which case nothing will be drawn.'; + + /// An error message to show when the [perspective] value is too high. + static const String perspectiveTooHighMessage = 'A perspective too high will ' + 'be clipped in the z-axis and therefore not renderable. Value must be ' + 'between 0 and 0.01.'; + + /// An error message to show when [clipBehavior] and [renderChildrenOutsideViewport] + /// are set to conflicting values. + static const String clipBehaviorAndRenderChildrenOutsideViewportConflict = + 'Cannot renderChildrenOutsideViewport and clip since children ' + 'rendered outside will be clipped anyway.'; + + /// The delegate that manages the children of this object. + /// + /// This delegate must maintain the [ListWheelParentData.index] value. + final ListWheelChildManager childManager; + + /// The associated ViewportOffset object for the viewport describing the part + /// of the content inside that's visible. + /// + /// The [ViewportOffset.pixels] value determines the scroll offset that the + /// viewport uses to select which part of its content to display. As the user + /// scrolls the viewport, this value changes, which changes the content that + /// is displayed. + ViewportOffset get offset => _offset; + ViewportOffset _offset; + set offset(ViewportOffset value) { + if (value == _offset) { + return; + } + if (attached) { + _offset.removeListener(_hasScrolled); + } + _offset = value; + if (attached) { + _offset.addListener(_hasScrolled); + } + markNeedsLayout(); + } + + /// {@template flutter.rendering.RenderListWheelViewport.diameterRatio} + /// A ratio between the diameter of the cylinder and the viewport's size + /// in the main axis. + /// + /// A value of 1 means the cylinder has the same diameter as the viewport's + /// size. + /// + /// A value smaller than 1 means items at the edges of the cylinder are + /// entirely contained inside the viewport. + /// + /// A value larger than 1 means angles less than ±[pi] / 2 from the + /// center of the cylinder are visible. + /// + /// The same number of children will be visible in the viewport regardless of + /// the [diameterRatio]. The number of children visible is based on the + /// viewport's length along the main axis divided by the children's + /// [itemExtent]. Then the children are evenly distributed along the visible + /// angles up to ±[pi] / 2. + /// + /// Just as it's impossible to stretch a paper to cover the an entire + /// half of a cylinder's surface where the cylinder has the same diameter + /// as the paper's length, choosing a [diameterRatio] smaller than [pi] + /// will leave same gaps between the children. + /// + /// Defaults to an arbitrary but aesthetically reasonable number of 2.0. + /// + /// Must be a positive number. + /// {@endtemplate} + double get diameterRatio => _diameterRatio; + double _diameterRatio; + set diameterRatio(double value) { + assert( + value > 0, + diameterRatioZeroMessage, + ); + if (value == _diameterRatio) { + return; + } + _diameterRatio = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// {@template flutter.rendering.RenderListWheelViewport.perspective} + /// Perspective of the cylindrical projection. + /// + /// A number between 0 and 0.01 where 0 means looking at the cylinder from + /// infinitely far with an infinitely small field of view and 1 means looking + /// at the cylinder from infinitely close with an infinitely large field of + /// view (which cannot be rendered). + /// + /// Defaults to an arbitrary but aesthetically reasonable number of 0.003. + /// A larger number brings the vanishing point closer and a smaller number + /// pushes the vanishing point further. + /// + /// Must be a positive number. + /// {@endtemplate} + double get perspective => _perspective; + double _perspective; + set perspective(double value) { + assert(value > 0); + assert( + value <= 0.01, + perspectiveTooHighMessage, + ); + if (value == _perspective) { + return; + } + _perspective = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// {@template flutter.rendering.RenderListWheelViewport.offAxisFraction} + /// How much the wheel is horizontally off-center, as a fraction of its width. + + /// This property creates the visual effect of looking at a vertical wheel from + /// its side where its vanishing points at the edge curves to one side instead + /// of looking at the wheel head-on. + /// + /// The value is horizontal distance between the wheel's center and the vertical + /// vanishing line at the edges of the wheel, represented as a fraction of the + /// wheel's width. + /// + /// The value `0.0` means the wheel is looked at head-on and its vanishing + /// line runs through the center of the wheel. Negative values means moving + /// the wheel to the left of the observer, thus the edges curve to the right. + /// Positive values means moving the wheel to the right of the observer, + /// thus the edges curve to the left. + /// + /// The visual effect causes the wheel's edges to curve rather than moving + /// the center. So a value of `0.5` means the edges' vanishing line will touch + /// the wheel's size's left edge. + /// + /// Defaults to `0.0`, which means looking at the wheel head-on. + /// The visual effect can be unaesthetic if this value is too far from the + /// range `[-0.5, 0.5]`. + /// {@endtemplate} + double get offAxisFraction => _offAxisFraction; + double _offAxisFraction = 0.0; + set offAxisFraction(double value) { + if (value == _offAxisFraction) { + return; + } + _offAxisFraction = value; + markNeedsPaint(); + } + + /// {@template flutter.rendering.RenderListWheelViewport.useMagnifier} + /// Whether to use the magnifier for the center item of the wheel. + /// {@endtemplate} + bool get useMagnifier => _useMagnifier; + bool _useMagnifier = false; + set useMagnifier(bool value) { + if (value == _useMagnifier) { + return; + } + _useMagnifier = value; + markNeedsPaint(); + } + /// {@template flutter.rendering.RenderListWheelViewport.magnification} + /// The zoomed-in rate of the magnifier, if it is used. + /// + /// The default value is 1.0, which will not change anything. + /// If the value is > 1.0, the center item will be zoomed in by that rate, and + /// it will also be rendered as flat, not cylindrical like the rest of the list. + /// The item will be zoomed out if magnification < 1.0. + /// + /// Must be positive. + /// {@endtemplate} + double get magnification => _magnification; + double _magnification = 1.0; + set magnification(double value) { + assert(value > 0); + if (value == _magnification) { + return; + } + _magnification = value; + markNeedsPaint(); + } + + /// {@template flutter.rendering.RenderListWheelViewport.overAndUnderCenterOpacity} + /// The opacity value that will be applied to the wheel that appears below and + /// above the magnifier. + /// + /// The default value is 1.0, which will not change anything. + /// + /// Must be greater than or equal to 0, and less than or equal to 1. + /// {@endtemplate} + double get overAndUnderCenterOpacity => _overAndUnderCenterOpacity; + double _overAndUnderCenterOpacity = 1.0; + set overAndUnderCenterOpacity(double value) { + assert(value >= 0 && value <= 1); + if (value == _overAndUnderCenterOpacity) { + return; + } + _overAndUnderCenterOpacity = value; + markNeedsPaint(); + } + + /// {@template flutter.rendering.RenderListWheelViewport.itemExtent} + /// The size of the children along the main axis. Children [RenderBox]es will + /// be given the [BoxConstraints] of this exact size. + /// + /// Must be a positive number. + /// {@endtemplate} + double get itemExtent => _itemExtent; + double _itemExtent; + set itemExtent(double value) { + assert(value > 0); + if (value == _itemExtent) { + return; + } + _itemExtent = value; + markNeedsLayout(); + } + + + /// {@template flutter.rendering.RenderListWheelViewport.squeeze} + /// The angular compactness of the children on the wheel. + /// + /// This denotes a ratio of the number of children on the wheel vs the number + /// of children that would fit on a flat list of equivalent size, assuming + /// [diameterRatio] of 1. + /// + /// For instance, if this RenderListWheelViewport has a height of 100px and + /// [itemExtent] is 20px, 5 items would fit on an equivalent flat list. + /// With a [squeeze] of 1, 5 items would also be shown in the + /// RenderListWheelViewport. With a [squeeze] of 2, 10 items would be shown + /// in the RenderListWheelViewport. + /// + /// Changing this value will change the number of children built and shown + /// inside the wheel. + /// + /// Must be a positive number. + /// {@endtemplate} + /// + /// Defaults to 1. + double get squeeze => _squeeze; + double _squeeze; + set squeeze(double value) { + assert(value > 0); + if (value == _squeeze) { + return; + } + _squeeze = value; + markNeedsLayout(); + markNeedsSemanticsUpdate(); + } + + /// {@template flutter.rendering.RenderListWheelViewport.renderChildrenOutsideViewport} + /// Whether to paint children inside the viewport only. + /// + /// If false, every child will be painted. However the [Scrollable] is still + /// the size of the viewport and detects gestures inside only. + /// + /// Defaults to false. Cannot be true if [clipBehavior] is not [Clip.none] + /// since children outside the viewport will be clipped, and therefore cannot + /// render children outside the viewport. + /// {@endtemplate} + bool get renderChildrenOutsideViewport => _renderChildrenOutsideViewport; + bool _renderChildrenOutsideViewport; + set renderChildrenOutsideViewport(bool value) { + assert( + !renderChildrenOutsideViewport || clipBehavior == Clip.none, + clipBehaviorAndRenderChildrenOutsideViewportConflict, + ); + if (value == _renderChildrenOutsideViewport) { + return; + } + _renderChildrenOutsideViewport = value; + markNeedsLayout(); + markNeedsSemanticsUpdate(); + } + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.hardEdge; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + void _hasScrolled() { + markNeedsLayout(); + markNeedsSemanticsUpdate(); + } + + @override + void setupParentData(RenderObject child) { + if (child.parentData is! ListWheelParentData) { + child.parentData = ListWheelParentData(); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _offset.addListener(_hasScrolled); + } + + @override + void detach() { + _offset.removeListener(_hasScrolled); + super.detach(); + } + + @override + bool get isRepaintBoundary => true; + + /// Main axis length in the untransformed plane. + double get _viewportExtent { + assert(hasSize); + return size.height; + } + + /// Main axis scroll extent in the **scrollable layout coordinates** that puts + /// the first item in the center. + double get _minEstimatedScrollExtent { + assert(hasSize); + if (childManager.childCount == null) { + return double.negativeInfinity; + } + return 0.0; + } + + /// Main axis scroll extent in the **scrollable layout coordinates** that puts + /// the last item in the center. + double get _maxEstimatedScrollExtent { + assert(hasSize); + if (childManager.childCount == null) { + return double.infinity; + } + + return math.max(0.0, (childManager.childCount! - 1) * _itemExtent); + } + + /// Scroll extent distance in the untransformed plane between the center + /// position in the viewport and the top position in the viewport. + /// + /// It's also the distance in the untransformed plane that children's painting + /// is offset by with respect to those children's [BoxParentData.offset]. + double get _topScrollMarginExtent { + assert(hasSize); + // Consider adding alignment options other than center. + return -size.height / 2.0 + _itemExtent / 2.0; + } + + /// Transforms a **scrollable layout coordinates**' y position to the + /// **untransformed plane's viewport painting coordinates**' y position given + /// the current scroll offset. + double _getUntransformedPaintingCoordinateY(double layoutCoordinateY) { + return layoutCoordinateY - _topScrollMarginExtent - offset.pixels; + } + + /// Given the _diameterRatio, return the largest absolute angle of the item + /// at the edge of the portion of the visible cylinder. + /// + /// For a _diameterRatio of 1 or less than 1 (i.e. the viewport is bigger + /// than the cylinder diameter), this value reaches and clips at pi / 2. + /// + /// When the center of children passes this angle, they are no longer painted + /// if [renderChildrenOutsideViewport] is false. + double get _maxVisibleRadian { + if (_diameterRatio < 1.0) { + return math.pi / 2.0; + } + return math.asin(1.0 / _diameterRatio); + } + + double _getIntrinsicCrossAxis(_ChildSizingFunction childSize) { + double extent = 0.0; + RenderBox? child = firstChild; + while (child != null) { + extent = math.max(extent, childSize(child)); + child = childAfter(child); + } + return extent; + } + + @override + double computeMinIntrinsicWidth(double height) { + return _getIntrinsicCrossAxis( + (RenderBox child) => child.getMinIntrinsicWidth(height), + ); + } + + @override + double computeMaxIntrinsicWidth(double height) { + return _getIntrinsicCrossAxis( + (RenderBox child) => child.getMaxIntrinsicWidth(height), + ); + } + + @override + double computeMinIntrinsicHeight(double width) { + if (childManager.childCount == null) { + return 0.0; + } + return childManager.childCount! * _itemExtent; + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (childManager.childCount == null) { + return 0.0; + } + return childManager.childCount! * _itemExtent; + } + + @override + bool get sizedByParent => true; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return constraints.biggest; + } + + /// Gets the index of a child by looking at its [parentData]. + /// + /// This relies on the [childManager] maintaining [ListWheelParentData.index]. + int indexOf(RenderBox child) { + final ListWheelParentData childParentData = child.parentData! as ListWheelParentData; + assert(childParentData.index != null); + return childParentData.index!; + } + + /// Returns the index of the child at the given offset. + int scrollOffsetToIndex(double scrollOffset) => (scrollOffset / itemExtent).floor(); + + /// Returns the scroll offset of the child with the given index. + double indexToScrollOffset(int index) => index * itemExtent; + + void _createChild(int index, { RenderBox? after }) { + invokeLayoutCallback<BoxConstraints>((BoxConstraints constraints) { + assert(constraints == this.constraints); + childManager.createChild(index, after: after); + }); + } + + void _destroyChild(RenderBox child) { + invokeLayoutCallback<BoxConstraints>((BoxConstraints constraints) { + assert(constraints == this.constraints); + childManager.removeChild(child); + }); + } + + void _layoutChild(RenderBox child, BoxConstraints constraints, int index) { + child.layout(constraints, parentUsesSize: true); + final ListWheelParentData childParentData = child.parentData! as ListWheelParentData; + // Centers the child horizontally. + final double crossPosition = size.width / 2.0 - child.size.width / 2.0; + childParentData.offset = Offset(crossPosition, indexToScrollOffset(index)); + } + + /// Performs layout based on how [childManager] provides children. + /// + /// From the current scroll offset, the minimum index and maximum index that + /// is visible in the viewport can be calculated. The index range of the + /// currently active children can also be acquired by looking directly at + /// the current child list. This function has to modify the current index + /// range to match the target index range by removing children that are no + /// longer visible and creating those that are visible but not yet provided + /// by [childManager]. + @override + void performLayout() { + offset.applyViewportDimension(_viewportExtent); + // Apply the content dimensions first if it has exact dimensions in case it + // changes the scroll offset which determines what should be shown. Such as + // if the child count decrease, we should correct the pixels first, otherwise, + // it may be shown blank null children. + if (childManager.childCount != null) { + offset.applyContentDimensions(_minEstimatedScrollExtent, _maxEstimatedScrollExtent); + } + + // The height, in pixel, that children will be visible and might be laid out + // and painted. + double visibleHeight = size.height * _squeeze; + // If renderChildrenOutsideViewport is true, we spawn extra children by + // doubling the visibility range, those that are in the backside of the + // cylinder won't be painted anyway. + if (renderChildrenOutsideViewport) { + visibleHeight *= 2; + } + + final double firstVisibleOffset = + offset.pixels + _itemExtent / 2 - visibleHeight / 2; + final double lastVisibleOffset = firstVisibleOffset + visibleHeight; + + // The index range that we want to spawn children. We find indexes that + // are in the interval [firstVisibleOffset, lastVisibleOffset). + int targetFirstIndex = scrollOffsetToIndex(firstVisibleOffset); + int targetLastIndex = scrollOffsetToIndex(lastVisibleOffset); + // Because we exclude lastVisibleOffset, if there's a new child starting at + // that offset, it is removed. + if (targetLastIndex * _itemExtent == lastVisibleOffset) { + targetLastIndex--; + } + + // Validates the target index range. + while (!childManager.childExistsAt(targetFirstIndex) && targetFirstIndex <= targetLastIndex) { + targetFirstIndex++; + } + while (!childManager.childExistsAt(targetLastIndex) && targetFirstIndex <= targetLastIndex) { + targetLastIndex--; + } + + // If it turns out there's no children to layout, we remove old children and + // return. + if (targetFirstIndex > targetLastIndex) { + while (firstChild != null) { + _destroyChild(firstChild!); + } + return; + } + + // Now there are 2 cases: + // - The target index range and our current index range have intersection: + // We shorten and extend our current child list so that the two lists + // match. Most of the time we are in this case. + // - The target list and our current child list have no intersection: + // We first remove all children and then add one child from the target + // list => this case becomes the other case. + + // Case when there is no intersection. + if (childCount > 0 && + (indexOf(firstChild!) > targetLastIndex || indexOf(lastChild!) < targetFirstIndex)) { + while (firstChild != null) { + _destroyChild(firstChild!); + } + } + + final BoxConstraints childConstraints = constraints.copyWith( + minHeight: _itemExtent, + maxHeight: _itemExtent, + minWidth: 0.0, + ); + // If there is no child at this stage, we add the first one that is in + // target range. + if (childCount == 0) { + _createChild(targetFirstIndex); + _layoutChild(firstChild!, childConstraints, targetFirstIndex); + } + + int currentFirstIndex = indexOf(firstChild!); + int currentLastIndex = indexOf(lastChild!); + + // Remove all unnecessary children by shortening the current child list, in + // both directions. + while (currentFirstIndex < targetFirstIndex) { + _destroyChild(firstChild!); + currentFirstIndex++; + } + while (currentLastIndex > targetLastIndex) { + _destroyChild(lastChild!); + currentLastIndex--; + } + + // Relayout all active children. + RenderBox? child = firstChild; + int index = currentFirstIndex; + while (child != null) { + _layoutChild(child, childConstraints, index++); + child = childAfter(child); + } + + // Spawning new children that are actually visible but not in child list yet. + while (currentFirstIndex > targetFirstIndex) { + _createChild(currentFirstIndex - 1); + _layoutChild(firstChild!, childConstraints, --currentFirstIndex); + } + while (currentLastIndex < targetLastIndex) { + _createChild(currentLastIndex + 1, after: lastChild); + _layoutChild(lastChild!, childConstraints, ++currentLastIndex); + } + + // Applying content dimensions bases on how the childManager builds widgets: + // if it is available to provide a child just out of target range, then + // we don't know whether there's a limit yet, and set the dimension to the + // estimated value. Otherwise, we set the dimension limited to our target + // range. + final double minScrollExtent = childManager.childExistsAt(targetFirstIndex - 1) + ? _minEstimatedScrollExtent + : indexToScrollOffset(targetFirstIndex); + final double maxScrollExtent = childManager.childExistsAt(targetLastIndex + 1) + ? _maxEstimatedScrollExtent + : indexToScrollOffset(targetLastIndex); + offset.applyContentDimensions(minScrollExtent, maxScrollExtent); + } + + bool _shouldClipAtCurrentOffset() { + final double highestUntransformedPaintY = + _getUntransformedPaintingCoordinateY(0.0); + return highestUntransformedPaintY < 0.0 + || size.height < highestUntransformedPaintY + _maxEstimatedScrollExtent + _itemExtent; + } + + @override + void paint(PaintingContext context, Offset offset) { + if (childCount > 0) { + if (_shouldClipAtCurrentOffset() && clipBehavior != Clip.none) { + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + _paintVisibleChildren, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + } else { + _clipRectLayer.layer = null; + _paintVisibleChildren(context, offset); + } + } + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void dispose() { + _clipRectLayer.layer = null; + _childOpacityLayerHandler.layer = null; + super.dispose(); + } + final LayerHandle<OpacityLayer> _childOpacityLayerHandler = LayerHandle<OpacityLayer>(); + /// Paints all children visible in the current viewport. + void _paintVisibleChildren(PaintingContext context, Offset offset) { + // The magnifier cannot be turned off if the opacity is less than 1.0. + if (overAndUnderCenterOpacity >= 1) { + _paintAllChildren(context, offset); + return; + } + + // In order to reduce the number of opacity layers, we first paint all + // partially opaque children, then finally paint the fully opaque children. + _childOpacityLayerHandler.layer = context.pushOpacity(offset, (overAndUnderCenterOpacity * 255).round(), (PaintingContext context, Offset offset) { + _paintAllChildren(context, offset, center: false); + }); + _paintAllChildren(context, offset, center: true); + } + + void _paintAllChildren(PaintingContext context, Offset offset, { bool? center }) { + RenderBox? childToPaint = firstChild; + while (childToPaint != null) { + final ListWheelParentData childParentData = childToPaint.parentData! as ListWheelParentData; + _paintTransformedChild(childToPaint, context, offset, childParentData.offset, center: center); + childToPaint = childAfter(childToPaint); + } + } + + // Takes in a child with a **scrollable layout offset** and paints it in the + // **transformed cylindrical space viewport painting coordinates**. + // + // The value of `center` is passed through to _paintChildWithMagnifier only + // if the magnifier is enabled and/or opacity is < 1.0. + void _paintTransformedChild( + RenderBox child, + PaintingContext context, + Offset offset, + Offset layoutOffset, { + required bool? center, + }) { + final Offset untransformedPaintingCoordinates = offset + + Offset( + layoutOffset.dx, + _getUntransformedPaintingCoordinateY(layoutOffset.dy), + ); + + // Get child's center as a fraction of the viewport's height. + final double fractionalY = + (untransformedPaintingCoordinates.dy + _itemExtent / 2.0) / size.height; + final double angle = -(fractionalY - 0.5) * 2.0 * _maxVisibleRadian / squeeze; + // Don't paint the backside of the cylinder when + // renderChildrenOutsideViewport is true. Otherwise, only children within + // suitable angles (via _first/lastVisibleLayoutOffset) reach the paint + // phase. + if (angle > math.pi / 2.0 || angle < -math.pi / 2.0) { + return; + } + + final Matrix4 transform = MatrixUtils.createCylindricalProjectionTransform( + radius: size.height * _diameterRatio / 2.0, + angle: angle, + perspective: _perspective, + ); + + // Offset that helps painting everything in the center (e.g. angle = 0). + final Offset offsetToCenter = Offset( + untransformedPaintingCoordinates.dx, + -_topScrollMarginExtent, + ); + + final bool shouldApplyOffCenterDim = overAndUnderCenterOpacity < 1; + if (useMagnifier || shouldApplyOffCenterDim) { + _paintChildWithMagnifier(context, offset, child, transform, offsetToCenter, untransformedPaintingCoordinates, center: center); + } else { + assert(center == null); + _paintChildCylindrically(context, offset, child, transform, offsetToCenter); + } + } + + // Paint child with the magnifier active - the child will be rendered + // differently if it intersects with the magnifier. + // + // `center` controls how items that partially intersect the center magnifier + // are rendered. If `center` is false, items are only painted cynlindrically. + // If `center` is true, only the clipped magnifier items are painted. + // If `center` is null, partially intersecting items are painted both as the + // magnifier and cynlidrical item, while non-intersecting items are painted + // only cylindrically. + // + // This property is used to lift the opacity that would be applied to each + // cylindrical item into a single layer, reducing the rendering cost of the + // pickers which use this viewport. + void _paintChildWithMagnifier( + PaintingContext context, + Offset offset, + RenderBox child, + Matrix4 cylindricalTransform, + Offset offsetToCenter, + Offset untransformedPaintingCoordinates, { + required bool? center, + }) { + final double magnifierTopLinePosition = + size.height / 2 - _itemExtent * _magnification / 2; + final double magnifierBottomLinePosition = + size.height / 2 + _itemExtent * _magnification / 2; + + final bool isAfterMagnifierTopLine = untransformedPaintingCoordinates.dy + >= magnifierTopLinePosition - _itemExtent * _magnification; + final bool isBeforeMagnifierBottomLine = untransformedPaintingCoordinates.dy + <= magnifierBottomLinePosition; + + final Rect centerRect = Rect.fromLTWH( + 0.0, + magnifierTopLinePosition, + size.width, + _itemExtent * _magnification, + ); + final Rect topHalfRect = Rect.fromLTWH( + 0.0, + 0.0, + size.width, + magnifierTopLinePosition, + ); + final Rect bottomHalfRect = Rect.fromLTWH( + 0.0, + magnifierBottomLinePosition, + size.width, + magnifierTopLinePosition, + ); + // Some part of the child is in the center magnifier. + final bool inCenter = isAfterMagnifierTopLine && isBeforeMagnifierBottomLine; + + if ((center == null || center) && inCenter) { + // Clipping the part in the center. + context.pushClipRect( + needsCompositing, + offset, + centerRect, + (PaintingContext context, Offset offset) { + context.pushTransform( + needsCompositing, + offset, + _magnifyTransform(), + (PaintingContext context, Offset offset) { + context.paintChild(child, offset + untransformedPaintingCoordinates); + }, + ); + }, + ); + } + + // Clipping the part in either the top-half or bottom-half of the wheel. + if ((center == null || !center) && inCenter) { + context.pushClipRect( + needsCompositing, + offset, + untransformedPaintingCoordinates.dy <= magnifierTopLinePosition + ? topHalfRect + : bottomHalfRect, + (PaintingContext context, Offset offset) { + _paintChildCylindrically( + context, + offset, + child, + cylindricalTransform, + offsetToCenter, + ); + }, + ); + } + + if ((center == null || !center) && !inCenter) { + _paintChildCylindrically( + context, + offset, + child, + cylindricalTransform, + offsetToCenter, + ); + } + } + + // / Paint the child cylindrically at given offset. + void _paintChildCylindrically( + PaintingContext context, + Offset offset, + RenderBox child, + Matrix4 cylindricalTransform, + Offset offsetToCenter, + ) { + final Offset paintOriginOffset = offset + offsetToCenter; + + // Paint child cylindrically, without [overAndUnderCenterOpacity]. + void painter(PaintingContext context, Offset offset) { + context.paintChild( + child, + // Paint everything in the center (e.g. angle = 0), then transform. + paintOriginOffset, + ); + } + + context.pushTransform( + needsCompositing, + offset, + _centerOriginTransform(cylindricalTransform), + // Pre-transform painting function. + painter, + ); + + final ListWheelParentData childParentData = child.parentData! as ListWheelParentData; + // Save the final transform that accounts both for the offset and cylindrical transform. + final Matrix4 transform = _centerOriginTransform(cylindricalTransform) + ..translate(paintOriginOffset.dx, paintOriginOffset.dy); + childParentData.transform = transform; + } + + /// Return the Matrix4 transformation that would zoom in content in the + /// magnified area. + Matrix4 _magnifyTransform() { + final Matrix4 magnify = Matrix4.identity(); + magnify.translate(size.width * (-_offAxisFraction + 0.5), size.height / 2); + magnify.scale(_magnification, _magnification, _magnification); + magnify.translate(-size.width * (-_offAxisFraction + 0.5), -size.height / 2); + return magnify; + } + + /// Apply incoming transformation with the transformation's origin at the + /// viewport's center or horizontally off to the side based on offAxisFraction. + Matrix4 _centerOriginTransform(Matrix4 originalMatrix) { + final Matrix4 result = Matrix4.identity(); + final Offset centerOriginTranslation = Alignment.center.alongSize(size); + result.translate( + centerOriginTranslation.dx * (-_offAxisFraction * 2 + 1), + centerOriginTranslation.dy, + ); + result.multiply(originalMatrix); + result.translate( + -centerOriginTranslation.dx * (-_offAxisFraction * 2 + 1), + -centerOriginTranslation.dy, + ); + return result; + } + + static bool _debugAssertValidHitTestOffsets(String context, Offset offset1, Offset offset2) { + if (offset1 != offset2) { + throw FlutterError("$context - hit test expected values didn't match: $offset1 != $offset2"); + } + return true; + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + final ListWheelParentData parentData = child.parentData! as ListWheelParentData; + final Matrix4? paintTransform = parentData.transform; + if (paintTransform != null) { + transform.multiply(paintTransform); + } + } + + @override + Rect? describeApproximatePaintClip(RenderObject child) { + if (_shouldClipAtCurrentOffset()) { + return Offset.zero & size; + } + return null; + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + RenderBox? child = lastChild; + while (child != null) { + final ListWheelParentData childParentData = child.parentData! as ListWheelParentData; + final Matrix4? transform = childParentData.transform; + // Skip not painted children + if (transform != null) { + final bool isHit = result.addWithPaintTransform( + transform: transform, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(() { + final Matrix4? inverted = Matrix4.tryInvert(PointerEvent.removePerspectiveTransform(transform)); + if (inverted == null) { + return _debugAssertValidHitTestOffsets('Null inverted transform', transformed, position); + } + return _debugAssertValidHitTestOffsets('MatrixUtils.transformPoint', transformed, MatrixUtils.transformPoint(inverted, position)); + }()); + return child!.hitTest(result, position: transformed); + }, + ); + if (isHit) { + return true; + } + } + child = childParentData.previousSibling; + } + return false; + } + + @override + RevealedOffset getOffsetToReveal( + RenderObject target, + double alignment, { + Rect? rect, + Axis? axis, // Unused, only Axis.vertical supported by this viewport. + }) { + // `target` is only fully revealed when in the selected/center position. Therefore, + // this method always returns the offset that shows `target` in the center position, + // which is the same offset for all `alignment` values. + rect ??= target.paintBounds; + + // `child` will be the last RenderObject before the viewport when walking up from `target`. + RenderObject child = target; + while (child.parent != this) { + child = child.parent!; + } + + final ListWheelParentData parentData = child.parentData! as ListWheelParentData; + final double targetOffset = parentData.offset.dy; // the so-called "centerPosition" + + final Matrix4 transform = target.getTransformTo(child); + final Rect bounds = MatrixUtils.transformRect(transform, rect); + final Rect targetRect = bounds.translate(0.0, (size.height - itemExtent) / 2); + + return RevealedOffset(offset: targetOffset, rect: targetRect); + } + + @override + void showOnScreen({ + RenderObject? descendant, + Rect? rect, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + }) { + if (descendant != null) { + // Shows the descendant in the selected/center position. + final RevealedOffset revealedOffset = getOffsetToReveal(descendant, 0.5, rect: rect); + if (duration == Duration.zero) { + offset.jumpTo(revealedOffset.offset); + } else { + offset.animateTo(revealedOffset.offset, duration: duration, curve: curve); + } + rect = revealedOffset.rect; + } + + super.showOnScreen( + rect: rect, + duration: duration, + curve: curve, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/mouse_tracker.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/mouse_tracker.dart new file mode 100644 index 0000000000000000000000000000000000000000..e79683ecd31d7a2259f59c7758c7aff54d571964 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/mouse_tracker.dart @@ -0,0 +1,427 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection' show LinkedHashMap; +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/services.dart'; + +import 'object.dart'; + +export 'package:flutter/services.dart' show + MouseCursor, + SystemMouseCursors; + +/// Signature for hit testing at the given offset for the specified view. +/// +/// It is used by the [MouseTracker] to fetch annotations for the mouse +/// position. +typedef MouseTrackerHitTest = HitTestResult Function(Offset offset, int viewId); + +// Various states of a connected mouse device used by [MouseTracker]. +class _MouseState { + _MouseState({ + required PointerEvent initialEvent, + }) : _latestEvent = initialEvent; + + // The list of annotations that contains this device. + // + // It uses [LinkedHashMap] to keep the insertion order. + LinkedHashMap<MouseTrackerAnnotation, Matrix4> get annotations => _annotations; + LinkedHashMap<MouseTrackerAnnotation, Matrix4> _annotations = LinkedHashMap<MouseTrackerAnnotation, Matrix4>(); + + LinkedHashMap<MouseTrackerAnnotation, Matrix4> replaceAnnotations(LinkedHashMap<MouseTrackerAnnotation, Matrix4> value) { + final LinkedHashMap<MouseTrackerAnnotation, Matrix4> previous = _annotations; + _annotations = value; + return previous; + } + + // The most recently processed mouse event observed from this device. + PointerEvent get latestEvent => _latestEvent; + PointerEvent _latestEvent; + + PointerEvent replaceLatestEvent(PointerEvent value) { + assert(value.device == _latestEvent.device); + final PointerEvent previous = _latestEvent; + _latestEvent = value; + return previous; + } + + int get device => latestEvent.device; + + @override + String toString() { + final String describeLatestEvent = 'latestEvent: ${describeIdentity(latestEvent)}'; + final String describeAnnotations = 'annotations: [list of ${annotations.length}]'; + return '${describeIdentity(this)}($describeLatestEvent, $describeAnnotations)'; + } +} + +// The information in `MouseTracker._handleDeviceUpdate` to provide the details +// of an update of a mouse device. +// +// This class contains the information needed to handle the update that might +// change the state of a mouse device, or the [MouseTrackerAnnotation]s that +// the mouse device is hovering. +@immutable +class _MouseTrackerUpdateDetails with Diagnosticable { + /// When device update is triggered by a new frame. + /// + /// All parameters are required. + const _MouseTrackerUpdateDetails.byNewFrame({ + required this.lastAnnotations, + required this.nextAnnotations, + required PointerEvent this.previousEvent, + }) : triggeringEvent = null; + + /// When device update is triggered by a pointer event. + /// + /// The [lastAnnotations], [nextAnnotations], and [triggeringEvent] are + /// required. + const _MouseTrackerUpdateDetails.byPointerEvent({ + required this.lastAnnotations, + required this.nextAnnotations, + this.previousEvent, + required PointerEvent this.triggeringEvent, + }); + + /// The annotations that the device is hovering before the update. + /// + /// It is never null. + final LinkedHashMap<MouseTrackerAnnotation, Matrix4> lastAnnotations; + + /// The annotations that the device is hovering after the update. + /// + /// It is never null. + final LinkedHashMap<MouseTrackerAnnotation, Matrix4> nextAnnotations; + + /// The last event that the device observed before the update. + /// + /// If the update is triggered by a frame, the [previousEvent] is never null, + /// since the pointer must have been added before. + /// + /// If the update is triggered by a pointer event, the [previousEvent] is not + /// null except for cases where the event is the first event observed by the + /// pointer (which is not necessarily a [PointerAddedEvent]). + final PointerEvent? previousEvent; + + /// The event that triggered this update. + /// + /// It is non-null if and only if the update is triggered by a pointer event. + final PointerEvent? triggeringEvent; + + /// The pointing device of this update. + int get device { + final int result = (previousEvent ?? triggeringEvent)!.device; + return result; + } + + /// The last event that the device observed after the update. + /// + /// The [latestEvent] is never null. + PointerEvent get latestEvent { + final PointerEvent result = triggeringEvent ?? previousEvent!; + return result; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('device', device)); + properties.add(DiagnosticsProperty<PointerEvent>('previousEvent', previousEvent)); + properties.add(DiagnosticsProperty<PointerEvent>('triggeringEvent', triggeringEvent)); + properties.add(DiagnosticsProperty<Map<MouseTrackerAnnotation, Matrix4>>('lastAnnotations', lastAnnotations)); + properties.add(DiagnosticsProperty<Map<MouseTrackerAnnotation, Matrix4>>('nextAnnotations', nextAnnotations)); + } +} + +/// Tracks the relationship between mouse devices and annotations, and +/// triggers mouse events and cursor changes accordingly. +/// +/// The [MouseTracker] tracks the relationship between mouse devices and +/// [MouseTrackerAnnotation], notified by [updateWithEvent] and +/// [updateAllDevices]. At every update, [MouseTracker] triggers the following +/// changes if applicable: +/// +/// * Dispatches mouse-related pointer events (pointer enter, hover, and exit). +/// * Changes mouse cursors. +/// * Notifies when [mouseIsConnected] changes. +/// +/// This class is a [ChangeNotifier] that notifies its listeners if the value of +/// [mouseIsConnected] changes. +/// +/// An instance of [MouseTracker] is owned by the global singleton +/// [RendererBinding]. +class MouseTracker extends ChangeNotifier { + /// Create a mouse tracker. + /// + /// The `hitTestInView` is used to find the render objects on a given + /// position in the specific view. It is typically provided by the + /// [RendererBinding]. + MouseTracker(MouseTrackerHitTest hitTestInView) + : _hitTestInView = hitTestInView; + + final MouseTrackerHitTest _hitTestInView; + + final MouseCursorManager _mouseCursorMixin = MouseCursorManager( + SystemMouseCursors.basic, + ); + + // Tracks the state of connected mouse devices. + // + // It is the source of truth for the list of connected mouse devices, and + // consists of two parts: + // + // * The mouse devices that are connected. + // * In which annotations each device is contained. + final Map<int, _MouseState> _mouseStates = <int, _MouseState>{}; + + // Used to wrap any procedure that might change `mouseIsConnected`. + // + // This method records `mouseIsConnected`, runs `task`, and calls + // [notifyListeners] at the end if the `mouseIsConnected` has changed. + void _monitorMouseConnection(VoidCallback task) { + final bool mouseWasConnected = mouseIsConnected; + task(); + if (mouseWasConnected != mouseIsConnected) { + notifyListeners(); + } + } + + bool _debugDuringDeviceUpdate = false; + // Used to wrap any procedure that might call `_handleDeviceUpdate`. + // + // In debug mode, this method uses `_debugDuringDeviceUpdate` to prevent + // `_deviceUpdatePhase` being recursively called. + void _deviceUpdatePhase(VoidCallback task) { + assert(!_debugDuringDeviceUpdate); + assert(() { + _debugDuringDeviceUpdate = true; + return true; + }()); + task(); + assert(() { + _debugDuringDeviceUpdate = false; + return true; + }()); + } + + // Whether an observed event might update a device. + static bool _shouldMarkStateDirty(_MouseState? state, PointerEvent event) { + if (state == null) { + return true; + } + final PointerEvent lastEvent = state.latestEvent; + assert(event.device == lastEvent.device); + // An Added can only follow a Removed, and a Removed can only be followed + // by an Added. + assert((event is PointerAddedEvent) == (lastEvent is PointerRemovedEvent)); + + // Ignore events that are unrelated to mouse tracking. + if (event is PointerSignalEvent) { + return false; + } + return lastEvent is PointerAddedEvent + || event is PointerRemovedEvent + || lastEvent.position != event.position; + } + + LinkedHashMap<MouseTrackerAnnotation, Matrix4> _hitTestInViewResultToAnnotations(HitTestResult result) { + final LinkedHashMap<MouseTrackerAnnotation, Matrix4> annotations = LinkedHashMap<MouseTrackerAnnotation, Matrix4>(); + for (final HitTestEntry entry in result.path) { + final Object target = entry.target; + if (target is MouseTrackerAnnotation) { + annotations[target] = entry.transform!; + } + } + return annotations; + } + + // Find the annotations that is hovered by the device of the `state`, and + // their respective global transform matrices. + // + // If the device is not connected or not a mouse, an empty map is returned + // without calling `hitTest`. + LinkedHashMap<MouseTrackerAnnotation, Matrix4> _findAnnotations(_MouseState state) { + final Offset globalPosition = state.latestEvent.position; + final int device = state.device; + final int viewId = state.latestEvent.viewId; + if (!_mouseStates.containsKey(device)) { + return LinkedHashMap<MouseTrackerAnnotation, Matrix4>(); + } + + return _hitTestInViewResultToAnnotations(_hitTestInView(globalPosition, viewId)); + } + + // A callback that is called on the update of a device. + // + // An event (not necessarily a pointer event) that might change the + // relationship between mouse devices and [MouseTrackerAnnotation]s is called + // a _device update_. This method should be called at each such update. + // + // The update can be caused by two kinds of triggers: + // + // * Triggered by the addition, movement, or removal of a pointer. Such calls + // occur during the handler of the event, indicated by + // `details.triggeringEvent` being non-null. + // * Triggered by the appearance, movement, or disappearance of an annotation. + // Such calls occur after each new frame, during the post-frame callbacks, + // indicated by `details.triggeringEvent` being null. + // + // Calls of this method must be wrapped in `_deviceUpdatePhase`. + void _handleDeviceUpdate(_MouseTrackerUpdateDetails details) { + assert(_debugDuringDeviceUpdate); + _handleDeviceUpdateMouseEvents(details); + _mouseCursorMixin.handleDeviceCursorUpdate( + details.device, + details.triggeringEvent, + details.nextAnnotations.keys.map((MouseTrackerAnnotation annotation) => annotation.cursor), + ); + } + + /// Whether or not at least one mouse is connected and has produced events. + bool get mouseIsConnected => _mouseStates.isNotEmpty; + + /// Perform a device update for one device according to the given new event. + /// + /// The [updateWithEvent] is typically called by [RendererBinding] during the + /// handler of a pointer event. All pointer events should call this method, + /// and let [MouseTracker] filter which to react to. + /// + /// The `hitTestResult` serves as an optional optimization, and is the hit + /// test result already performed by [RendererBinding] for other gestures. It + /// can be null, but when it's not null, it should be identical to the result + /// from directly calling `hitTestInView` given in the constructor (which + /// means that it should not use the cached result for [PointerMoveEvent]). + /// + /// The [updateWithEvent] is one of the two ways of updating mouse + /// states, the other one being [updateAllDevices]. + void updateWithEvent(PointerEvent event, HitTestResult? hitTestResult) { + if (event.kind != PointerDeviceKind.mouse) { + return; + } + if (event is PointerSignalEvent) { + return; + } + final HitTestResult result; + if (event is PointerRemovedEvent) { + result = HitTestResult(); + } else { + final int viewId = event.viewId; + result = hitTestResult ?? _hitTestInView(event.position, viewId); + } + final int device = event.device; + final _MouseState? existingState = _mouseStates[device]; + if (!_shouldMarkStateDirty(existingState, event)) { + return; + } + + _monitorMouseConnection(() { + _deviceUpdatePhase(() { + // Update mouseState to the latest devices that have not been removed, + // so that [mouseIsConnected], which is decided by `_mouseStates`, is + // correct during the callbacks. + if (existingState == null) { + if (event is PointerRemovedEvent) { + return; + } + _mouseStates[device] = _MouseState(initialEvent: event); + } else { + assert(event is! PointerAddedEvent); + if (event is PointerRemovedEvent) { + _mouseStates.remove(event.device); + } + } + final _MouseState targetState = _mouseStates[device] ?? existingState!; + + final PointerEvent lastEvent = targetState.replaceLatestEvent(event); + final LinkedHashMap<MouseTrackerAnnotation, Matrix4> nextAnnotations = event is PointerRemovedEvent ? + LinkedHashMap<MouseTrackerAnnotation, Matrix4>() : + _hitTestInViewResultToAnnotations(result); + final LinkedHashMap<MouseTrackerAnnotation, Matrix4> lastAnnotations = targetState.replaceAnnotations(nextAnnotations); + + _handleDeviceUpdate(_MouseTrackerUpdateDetails.byPointerEvent( + lastAnnotations: lastAnnotations, + nextAnnotations: nextAnnotations, + previousEvent: lastEvent, + triggeringEvent: event, + )); + }); + }); + } + + /// Perform a device update for all detected devices. + /// + /// The [updateAllDevices] is typically called during the post frame phase, + /// indicating a frame has passed and all objects have potentially moved. For + /// each connected device, the [updateAllDevices] will make a hit test on the + /// device's last seen position, and check if necessary changes need to be + /// made. + /// + /// The [updateAllDevices] is one of the two ways of updating mouse + /// states, the other one being [updateWithEvent]. + void updateAllDevices() { + _deviceUpdatePhase(() { + for (final _MouseState dirtyState in _mouseStates.values) { + final PointerEvent lastEvent = dirtyState.latestEvent; + final LinkedHashMap<MouseTrackerAnnotation, Matrix4> nextAnnotations = _findAnnotations(dirtyState); + final LinkedHashMap<MouseTrackerAnnotation, Matrix4> lastAnnotations = dirtyState.replaceAnnotations(nextAnnotations); + + _handleDeviceUpdate(_MouseTrackerUpdateDetails.byNewFrame( + lastAnnotations: lastAnnotations, + nextAnnotations: nextAnnotations, + previousEvent: lastEvent, + )); + } + }); + } + + /// Returns the active mouse cursor for a device. + /// + /// The return value is the last [MouseCursor] activated onto this device, even + /// if the activation failed. + /// + /// This function is only active when asserts are enabled. In release builds, + /// it always returns null. + @visibleForTesting + MouseCursor? debugDeviceActiveCursor(int device) { + return _mouseCursorMixin.debugDeviceActiveCursor(device); + } + + // Handles device update and dispatches mouse event callbacks. + static void _handleDeviceUpdateMouseEvents(_MouseTrackerUpdateDetails details) { + final PointerEvent latestEvent = details.latestEvent; + + final LinkedHashMap<MouseTrackerAnnotation, Matrix4> lastAnnotations = details.lastAnnotations; + final LinkedHashMap<MouseTrackerAnnotation, Matrix4> nextAnnotations = details.nextAnnotations; + + // Order is important for mouse event callbacks. The + // `_hitTestInViewResultToAnnotations` returns annotations in the visual order + // from front to back, called the "hit-test order". The algorithm here is + // explained in https://github.com/flutter/flutter/issues/41420 + + // Send exit events to annotations that are in last but not in next, in + // hit-test order. + final PointerExitEvent baseExitEvent = PointerExitEvent.fromMouseEvent(latestEvent); + lastAnnotations.forEach((MouseTrackerAnnotation annotation, Matrix4 transform) { + if (annotation.validForMouseTracker && !nextAnnotations.containsKey(annotation)) { + annotation.onExit?.call(baseExitEvent.transformed(lastAnnotations[annotation])); + } + }); + + // Send enter events to annotations that are not in last but in next, in + // reverse hit-test order. + final List<MouseTrackerAnnotation> enteringAnnotations = nextAnnotations.keys.where( + (MouseTrackerAnnotation annotation) => !lastAnnotations.containsKey(annotation), + ).toList(); + final PointerEnterEvent baseEnterEvent = PointerEnterEvent.fromMouseEvent(latestEvent); + for (final MouseTrackerAnnotation annotation in enteringAnnotations.reversed) { + if (annotation.validForMouseTracker) { + annotation.onEnter?.call(baseEnterEvent.transformed(nextAnnotations[annotation])); + } + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/object.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/object.dart new file mode 100644 index 0000000000000000000000000000000000000000..4d01ad06f5fd099dc6c4420fac69f4d69e7353be --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/object.dart @@ -0,0 +1,5264 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show PictureRecorder; + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/painting.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/semantics.dart'; + +import 'debug.dart'; +import 'layer.dart'; + +export 'package:flutter/foundation.dart' show + DiagnosticPropertiesBuilder, + DiagnosticsNode, + DiagnosticsProperty, + DoubleProperty, + EnumProperty, + ErrorDescription, + ErrorHint, + ErrorSummary, + FlagProperty, + FlutterError, + InformationCollector, + IntProperty, + StringProperty; +export 'package:flutter/gestures.dart' show HitTestEntry, HitTestResult; +export 'package:flutter/painting.dart'; + +/// Base class for data associated with a [RenderObject] by its parent. +/// +/// Some render objects wish to store data on their children, such as the +/// children's input parameters to the parent's layout algorithm or the +/// children's position relative to other children. +/// +/// See also: +/// +/// * [RenderObject.setupParentData], which [RenderObject] subclasses may +/// override to attach specific types of parent data to children. +class ParentData { + /// Called when the RenderObject is removed from the tree. + @protected + @mustCallSuper + void detach() { } + + @override + String toString() => '<none>'; +} + +/// Signature for painting into a [PaintingContext]. +/// +/// The `offset` argument is the offset from the origin of the coordinate system +/// of the [PaintingContext.canvas] to the coordinate system of the callee. +/// +/// Used by many of the methods of [PaintingContext]. +typedef PaintingContextCallback = void Function(PaintingContext context, Offset offset); + +/// A place to paint. +/// +/// Rather than holding a canvas directly, [RenderObject]s paint using a painting +/// context. The painting context has a [Canvas], which receives the +/// individual draw operations, and also has functions for painting child +/// render objects. +/// +/// When painting a child render object, the canvas held by the painting context +/// can change because the draw operations issued before and after painting the +/// child might be recorded in separate compositing layers. For this reason, do +/// not hold a reference to the canvas across operations that might paint +/// child render objects. +/// +/// New [PaintingContext] objects are created automatically when using +/// [PaintingContext.repaintCompositedChild] and [pushLayer]. +class PaintingContext extends ClipContext { + + /// Creates a painting context. + /// + /// Typically only called by [PaintingContext.repaintCompositedChild] + /// and [pushLayer]. + @protected + PaintingContext(this._containerLayer, this.estimatedBounds); + + final ContainerLayer _containerLayer; + + /// An estimate of the bounds within which the painting context's [canvas] + /// will record painting commands. This can be useful for debugging. + /// + /// The canvas will allow painting outside these bounds. + /// + /// The [estimatedBounds] rectangle is in the [canvas] coordinate system. + final Rect estimatedBounds; + + /// Repaint the given render object. + /// + /// The render object must be attached to a [PipelineOwner], must have a + /// composited layer, and must be in need of painting. The render object's + /// layer, if any, is re-used, along with any layers in the subtree that don't + /// need to be repainted. + /// + /// See also: + /// + /// * [RenderObject.isRepaintBoundary], which determines if a [RenderObject] + /// has a composited layer. + static void repaintCompositedChild(RenderObject child, { bool debugAlsoPaintedParent = false }) { + assert(child._needsPaint); + _repaintCompositedChild( + child, + debugAlsoPaintedParent: debugAlsoPaintedParent, + ); + } + + static void _repaintCompositedChild( + RenderObject child, { + bool debugAlsoPaintedParent = false, + PaintingContext? childContext, + }) { + assert(child.isRepaintBoundary); + assert(() { + // register the call for RepaintBoundary metrics + child.debugRegisterRepaintBoundaryPaint( + includedParent: debugAlsoPaintedParent, + includedChild: true, + ); + return true; + }()); + OffsetLayer? childLayer = child._layerHandle.layer as OffsetLayer?; + if (childLayer == null) { + assert(debugAlsoPaintedParent); + assert(child._layerHandle.layer == null); + + // Not using the `layer` setter because the setter asserts that we not + // replace the layer for repaint boundaries. That assertion does not + // apply here because this is exactly the place designed to create a + // layer for repaint boundaries. + final OffsetLayer layer = child.updateCompositedLayer(oldLayer: null); + child._layerHandle.layer = childLayer = layer; + } else { + assert(debugAlsoPaintedParent || childLayer.attached); + Offset? debugOldOffset; + assert(() { + debugOldOffset = childLayer!.offset; + return true; + }()); + childLayer.removeAllChildren(); + final OffsetLayer updatedLayer = child.updateCompositedLayer(oldLayer: childLayer); + assert(identical(updatedLayer, childLayer), + '$child created a new layer instance $updatedLayer instead of reusing the ' + 'existing layer $childLayer. See the documentation of RenderObject.updateCompositedLayer ' + 'for more information on how to correctly implement this method.' + ); + assert(debugOldOffset == updatedLayer.offset); + } + child._needsCompositedLayerUpdate = false; + + assert(identical(childLayer, child._layerHandle.layer)); + assert(child._layerHandle.layer is OffsetLayer); + assert(() { + childLayer!.debugCreator = child.debugCreator ?? child.runtimeType; + return true; + }()); + + childContext ??= PaintingContext(childLayer, child.paintBounds); + child._paintWithContext(childContext, Offset.zero); + + // Double-check that the paint method did not replace the layer (the first + // check is done in the [layer] setter itself). + assert(identical(childLayer, child._layerHandle.layer)); + childContext.stopRecordingIfNeeded(); + } + + /// Update the composited layer of [child] without repainting its children. + /// + /// The render object must be attached to a [PipelineOwner], must have a + /// composited layer, and must be in need of a composited layer update but + /// not in need of painting. The render object's layer is re-used, and none + /// of its children are repaint or their layers updated. + /// + /// See also: + /// + /// * [RenderObject.isRepaintBoundary], which determines if a [RenderObject] + /// has a composited layer. + static void updateLayerProperties(RenderObject child) { + assert(child.isRepaintBoundary && child._wasRepaintBoundary); + assert(!child._needsPaint); + assert(child._layerHandle.layer != null); + + final OffsetLayer childLayer = child._layerHandle.layer! as OffsetLayer; + Offset? debugOldOffset; + assert(() { + debugOldOffset = childLayer.offset; + return true; + }()); + final OffsetLayer updatedLayer = child.updateCompositedLayer(oldLayer: childLayer); + assert(identical(updatedLayer, childLayer), + '$child created a new layer instance $updatedLayer instead of reusing the ' + 'existing layer $childLayer. See the documentation of RenderObject.updateCompositedLayer ' + 'for more information on how to correctly implement this method.' + ); + assert(debugOldOffset == updatedLayer.offset); + child._needsCompositedLayerUpdate = false; + } + + /// In debug mode, repaint the given render object using a custom painting + /// context that can record the results of the painting operation in addition + /// to performing the regular paint of the child. + /// + /// See also: + /// + /// * [repaintCompositedChild], for repainting a composited child without + /// instrumentation. + static void debugInstrumentRepaintCompositedChild( + RenderObject child, { + bool debugAlsoPaintedParent = false, + required PaintingContext customContext, + }) { + assert(() { + _repaintCompositedChild( + child, + debugAlsoPaintedParent: debugAlsoPaintedParent, + childContext: customContext, + ); + return true; + }()); + } + + /// Paint a child [RenderObject]. + /// + /// If the child has its own composited layer, the child will be composited + /// into the layer subtree associated with this painting context. Otherwise, + /// the child will be painted into the current PictureLayer for this context. + void paintChild(RenderObject child, Offset offset) { + assert(() { + debugOnProfilePaint?.call(child); + return true; + }()); + + if (child.isRepaintBoundary) { + stopRecordingIfNeeded(); + _compositeChild(child, offset); + // If a render object was a repaint boundary but no longer is one, this + // is where the framework managed layer is automatically disposed. + } else if (child._wasRepaintBoundary) { + assert(child._layerHandle.layer is OffsetLayer); + child._layerHandle.layer = null; + child._paintWithContext(this, offset); + } else { + child._paintWithContext(this, offset); + } + } + + void _compositeChild(RenderObject child, Offset offset) { + assert(!_isRecording); + assert(child.isRepaintBoundary); + assert(_canvas == null || _canvas!.getSaveCount() == 1); + + // Create a layer for our child, and paint the child into it. + if (child._needsPaint || !child._wasRepaintBoundary) { + repaintCompositedChild(child, debugAlsoPaintedParent: true); + } else { + if (child._needsCompositedLayerUpdate) { + updateLayerProperties(child); + } + assert(() { + // register the call for RepaintBoundary metrics + child.debugRegisterRepaintBoundaryPaint(); + child._layerHandle.layer!.debugCreator = child.debugCreator ?? child; + return true; + }()); + } + assert(child._layerHandle.layer is OffsetLayer); + final OffsetLayer childOffsetLayer = child._layerHandle.layer! as OffsetLayer; + childOffsetLayer.offset = offset; + appendLayer(childOffsetLayer); + } + + /// Adds a layer to the recording requiring that the recording is already + /// stopped. + /// + /// Do not call this function directly: call [addLayer] or [pushLayer] + /// instead. This function is called internally when all layers not + /// generated from the [canvas] are added. + /// + /// Subclasses that need to customize how layers are added should override + /// this method. + @protected + void appendLayer(Layer layer) { + assert(!_isRecording); + layer.remove(); + _containerLayer.append(layer); + } + + bool get _isRecording { + final bool hasCanvas = _canvas != null; + assert(() { + if (hasCanvas) { + assert(_currentLayer != null); + assert(_recorder != null); + assert(_canvas != null); + } else { + assert(_currentLayer == null); + assert(_recorder == null); + assert(_canvas == null); + } + return true; + }()); + return hasCanvas; + } + + // Recording state + PictureLayer? _currentLayer; + ui.PictureRecorder? _recorder; + Canvas? _canvas; + + /// The canvas on which to paint. + /// + /// The current canvas can change whenever you paint a child using this + /// context, which means it's fragile to hold a reference to the canvas + /// returned by this getter. + @override + Canvas get canvas { + if (_canvas == null) { + _startRecording(); + } + assert(_currentLayer != null); + return _canvas!; + } + + void _startRecording() { + assert(!_isRecording); + _currentLayer = PictureLayer(estimatedBounds); + _recorder = ui.PictureRecorder(); + _canvas = Canvas(_recorder!); + _containerLayer.append(_currentLayer!); + } + + /// Adds a [CompositionCallback] for the current [ContainerLayer] used by this + /// context. + /// + /// Composition callbacks are called whenever the layer tree containing the + /// current layer of this painting context gets composited, or when it gets + /// detached and will not be rendered again. This happens regardless of + /// whether the layer is added via retained rendering or not. + /// + /// {@macro flutter.rendering.Layer.compositionCallbacks} + /// + /// See also: + /// * [Layer.addCompositionCallback]. + VoidCallback addCompositionCallback(CompositionCallback callback) { + return _containerLayer.addCompositionCallback(callback); + } + + /// Stop recording to a canvas if recording has started. + /// + /// Do not call this function directly: functions in this class will call + /// this method as needed. This function is called internally to ensure that + /// recording is stopped before adding layers or finalizing the results of a + /// paint. + /// + /// Subclasses that need to customize how recording to a canvas is performed + /// should override this method to save the results of the custom canvas + /// recordings. + @protected + @mustCallSuper + void stopRecordingIfNeeded() { + if (!_isRecording) { + return; + } + assert(() { + if (debugRepaintRainbowEnabled) { + final Paint paint = Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 6.0 + ..color = debugCurrentRepaintColor.toColor(); + canvas.drawRect(estimatedBounds.deflate(3.0), paint); + } + if (debugPaintLayerBordersEnabled) { + final Paint paint = Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 1.0 + ..color = const Color(0xFFFF9800); + canvas.drawRect(estimatedBounds, paint); + } + return true; + }()); + _currentLayer!.picture = _recorder!.endRecording(); + _currentLayer = null; + _recorder = null; + _canvas = null; + } + + /// Hints that the painting in the current layer is complex and would benefit + /// from caching. + /// + /// If this hint is not set, the compositor will apply its own heuristics to + /// decide whether the current layer is complex enough to benefit from + /// caching. + /// + /// Calling this ensures a [Canvas] is available. Only draw calls on the + /// current canvas will be hinted; the hint is not propagated to new canvases + /// created after a new layer is added to the painting context (e.g. with + /// [addLayer] or [pushLayer]). + void setIsComplexHint() { + if (_currentLayer == null) { + _startRecording(); + } + _currentLayer!.isComplexHint = true; + } + + /// Hints that the painting in the current layer is likely to change next frame. + /// + /// This hint tells the compositor not to cache the current layer because the + /// cache will not be used in the future. If this hint is not set, the + /// compositor will apply its own heuristics to decide whether the current + /// layer is likely to be reused in the future. + /// + /// Calling this ensures a [Canvas] is available. Only draw calls on the + /// current canvas will be hinted; the hint is not propagated to new canvases + /// created after a new layer is added to the painting context (e.g. with + /// [addLayer] or [pushLayer]). + void setWillChangeHint() { + if (_currentLayer == null) { + _startRecording(); + } + _currentLayer!.willChangeHint = true; + } + + /// Adds a composited leaf layer to the recording. + /// + /// After calling this function, the [canvas] property will change to refer to + /// a new [Canvas] that draws on top of the given layer. + /// + /// A [RenderObject] that uses this function is very likely to require its + /// [RenderObject.alwaysNeedsCompositing] property to return true. That informs + /// ancestor render objects that this render object will include a composited + /// layer, which, for example, causes them to use composited clips. + /// + /// See also: + /// + /// * [pushLayer], for adding a layer and painting further contents within + /// it. + void addLayer(Layer layer) { + stopRecordingIfNeeded(); + appendLayer(layer); + } + + /// Appends the given layer to the recording, and calls the `painter` callback + /// with that layer, providing the `childPaintBounds` as the estimated paint + /// bounds of the child. The `childPaintBounds` can be used for debugging but + /// have no effect on painting. + /// + /// The given layer must be an unattached orphan. (Providing a newly created + /// object, rather than reusing an existing layer, satisfies that + /// requirement.) + /// + /// {@template flutter.rendering.PaintingContext.pushLayer.offset} + /// The `offset` is the offset to pass to the `painter`. In particular, it is + /// not an offset applied to the layer itself. Layers conceptually by default + /// have no position or size, though they can transform their contents. For + /// example, an [OffsetLayer] applies an offset to its children. + /// {@endtemplate} + /// + /// If the `childPaintBounds` are not specified then the current layer's paint + /// bounds are used. This is appropriate if the child layer does not apply any + /// transformation or clipping to its contents. The `childPaintBounds`, if + /// specified, must be in the coordinate system of the new layer (i.e. as seen + /// by its children after it applies whatever transform to its contents), and + /// should not go outside the current layer's paint bounds. + /// + /// See also: + /// + /// * [addLayer], for pushing a layer without painting further contents + /// within it. + void pushLayer(ContainerLayer childLayer, PaintingContextCallback painter, Offset offset, { Rect? childPaintBounds }) { + // If a layer is being reused, it may already contain children. We remove + // them so that `painter` can add children that are relevant for this frame. + if (childLayer.hasChildren) { + childLayer.removeAllChildren(); + } + stopRecordingIfNeeded(); + appendLayer(childLayer); + final PaintingContext childContext = createChildContext(childLayer, childPaintBounds ?? estimatedBounds); + + painter(childContext, offset); + childContext.stopRecordingIfNeeded(); + } + + /// Creates a painting context configured to paint into [childLayer]. + /// + /// The `bounds` are estimated paint bounds for debugging purposes. + @protected + PaintingContext createChildContext(ContainerLayer childLayer, Rect bounds) { + return PaintingContext(childLayer, bounds); + } + + /// Clip further painting using a rectangle. + /// + /// {@template flutter.rendering.PaintingContext.pushClipRect.needsCompositing} + /// The `needsCompositing` argument specifies whether the child needs + /// compositing. Typically this matches the value of + /// [RenderObject.needsCompositing] for the caller. If false, this method + /// returns null, indicating that a layer is no longer necessary. If a render + /// object calling this method stores the `oldLayer` in its + /// [RenderObject.layer] field, it should set that field to null. + /// + /// When `needsCompositing` is false, this method will use a more efficient + /// way to apply the layer effect than actually creating a layer. + /// {@endtemplate} + /// + /// {@template flutter.rendering.PaintingContext.pushClipRect.offset} + /// The `offset` argument is the offset from the origin of the canvas' + /// coordinate system to the origin of the caller's coordinate system. + /// {@endtemplate} + /// + /// The `clipRect` is the rectangle (in the caller's coordinate system) to use + /// to clip the painting done by [painter]. It should not include the + /// `offset`. + /// + /// The `painter` callback will be called while the `clipRect` is applied. It + /// is called synchronously during the call to [pushClipRect]. + /// + /// The `clipBehavior` argument controls how the rectangle is clipped. + /// + /// {@template flutter.rendering.PaintingContext.pushClipRect.oldLayer} + /// For the `oldLayer` argument, specify the layer created in the previous + /// frame. This gives the engine more information for performance + /// optimizations. Typically this is the value of [RenderObject.layer] that a + /// render object creates once, then reuses for all subsequent frames until a + /// layer is no longer needed (e.g. the render object no longer needs + /// compositing) or until the render object changes the type of the layer + /// (e.g. from opacity layer to a clip rect layer). + /// {@endtemplate} + ClipRectLayer? pushClipRect(bool needsCompositing, Offset offset, Rect clipRect, PaintingContextCallback painter, { Clip clipBehavior = Clip.hardEdge, ClipRectLayer? oldLayer }) { + if (clipBehavior == Clip.none) { + painter(this, offset); + return null; + } + final Rect offsetClipRect = clipRect.shift(offset); + if (needsCompositing) { + final ClipRectLayer layer = oldLayer ?? ClipRectLayer(); + layer + ..clipRect = offsetClipRect + ..clipBehavior = clipBehavior; + pushLayer(layer, painter, offset, childPaintBounds: offsetClipRect); + return layer; + } else { + clipRectAndPaint(offsetClipRect, clipBehavior, offsetClipRect, () => painter(this, offset)); + return null; + } + } + + /// Clip further painting using a rounded rectangle. + /// + /// {@macro flutter.rendering.PaintingContext.pushClipRect.needsCompositing} + /// + /// {@macro flutter.rendering.PaintingContext.pushClipRect.offset} + /// + /// The `bounds` argument is used to specify the region of the canvas (in the + /// caller's coordinate system) into which `painter` will paint. + /// + /// The `clipRRect` argument specifies the rounded-rectangle (in the caller's + /// coordinate system) to use to clip the painting done by `painter`. It + /// should not include the `offset`. + /// + /// The `painter` callback will be called while the `clipRRect` is applied. It + /// is called synchronously during the call to [pushClipRRect]. + /// + /// The `clipBehavior` argument controls how the rounded rectangle is clipped. + /// + /// {@macro flutter.rendering.PaintingContext.pushClipRect.oldLayer} + ClipRRectLayer? pushClipRRect(bool needsCompositing, Offset offset, Rect bounds, RRect clipRRect, PaintingContextCallback painter, { Clip clipBehavior = Clip.antiAlias, ClipRRectLayer? oldLayer }) { + if (clipBehavior == Clip.none) { + painter(this, offset); + return null; + } + final Rect offsetBounds = bounds.shift(offset); + final RRect offsetClipRRect = clipRRect.shift(offset); + if (needsCompositing) { + final ClipRRectLayer layer = oldLayer ?? ClipRRectLayer(); + layer + ..clipRRect = offsetClipRRect + ..clipBehavior = clipBehavior; + pushLayer(layer, painter, offset, childPaintBounds: offsetBounds); + return layer; + } else { + clipRRectAndPaint(offsetClipRRect, clipBehavior, offsetBounds, () => painter(this, offset)); + return null; + } + } + + /// Clip further painting using a path. + /// + /// {@macro flutter.rendering.PaintingContext.pushClipRect.needsCompositing} + /// + /// {@macro flutter.rendering.PaintingContext.pushClipRect.offset} + /// + /// The `bounds` argument is used to specify the region of the canvas (in the + /// caller's coordinate system) into which `painter` will paint. + /// + /// The `clipPath` argument specifies the [Path] (in the caller's coordinate + /// system) to use to clip the painting done by `painter`. It should not + /// include the `offset`. + /// + /// The `painter` callback will be called while the `clipPath` is applied. It + /// is called synchronously during the call to [pushClipPath]. + /// + /// The `clipBehavior` argument controls how the path is clipped. + /// + /// {@macro flutter.rendering.PaintingContext.pushClipRect.oldLayer} + ClipPathLayer? pushClipPath(bool needsCompositing, Offset offset, Rect bounds, Path clipPath, PaintingContextCallback painter, { Clip clipBehavior = Clip.antiAlias, ClipPathLayer? oldLayer }) { + if (clipBehavior == Clip.none) { + painter(this, offset); + return null; + } + final Rect offsetBounds = bounds.shift(offset); + final Path offsetClipPath = clipPath.shift(offset); + if (needsCompositing) { + final ClipPathLayer layer = oldLayer ?? ClipPathLayer(); + layer + ..clipPath = offsetClipPath + ..clipBehavior = clipBehavior; + pushLayer(layer, painter, offset, childPaintBounds: offsetBounds); + return layer; + } else { + clipPathAndPaint(offsetClipPath, clipBehavior, offsetBounds, () => painter(this, offset)); + return null; + } + } + + /// Blend further painting with a color filter. + /// + /// {@macro flutter.rendering.PaintingContext.pushLayer.offset} + /// + /// The `colorFilter` argument is the [ColorFilter] value to use when blending + /// the painting done by `painter`. + /// + /// The `painter` callback will be called while the `colorFilter` is applied. + /// It is called synchronously during the call to [pushColorFilter]. + /// + /// {@macro flutter.rendering.PaintingContext.pushClipRect.oldLayer} + /// + /// A [RenderObject] that uses this function is very likely to require its + /// [RenderObject.alwaysNeedsCompositing] property to return true. That informs + /// ancestor render objects that this render object will include a composited + /// layer, which, for example, causes them to use composited clips. + ColorFilterLayer pushColorFilter(Offset offset, ColorFilter colorFilter, PaintingContextCallback painter, { ColorFilterLayer? oldLayer }) { + final ColorFilterLayer layer = oldLayer ?? ColorFilterLayer(); + layer.colorFilter = colorFilter; + pushLayer(layer, painter, offset); + return layer; + } + + /// Transform further painting using a matrix. + /// + /// {@macro flutter.rendering.PaintingContext.pushClipRect.needsCompositing} + /// + /// The `offset` argument is the offset to pass to `painter` and the offset to + /// the origin used by `transform`. + /// + /// The `transform` argument is the [Matrix4] with which to transform the + /// coordinate system while calling `painter`. It should not include `offset`. + /// It is applied effectively after applying `offset`. + /// + /// The `painter` callback will be called while the `transform` is applied. It + /// is called synchronously during the call to [pushTransform]. + /// + /// {@macro flutter.rendering.PaintingContext.pushClipRect.oldLayer} + TransformLayer? pushTransform(bool needsCompositing, Offset offset, Matrix4 transform, PaintingContextCallback painter, { TransformLayer? oldLayer }) { + final Matrix4 effectiveTransform = Matrix4.translationValues(offset.dx, offset.dy, 0.0) + ..multiply(transform)..translate(-offset.dx, -offset.dy); + if (needsCompositing) { + final TransformLayer layer = oldLayer ?? TransformLayer(); + layer.transform = effectiveTransform; + pushLayer( + layer, + painter, + offset, + childPaintBounds: MatrixUtils.inverseTransformRect(effectiveTransform, estimatedBounds), + ); + return layer; + } else { + canvas + ..save() + ..transform(effectiveTransform.storage); + painter(this, offset); + canvas.restore(); + return null; + } + } + + /// Blend further painting with an alpha value. + /// + /// The `offset` argument indicates an offset to apply to all the children + /// (the rendering created by `painter`). + /// + /// The `alpha` argument is the alpha value to use when blending the painting + /// done by `painter`. An alpha value of 0 means the painting is fully + /// transparent and an alpha value of 255 means the painting is fully opaque. + /// + /// The `painter` callback will be called while the `alpha` is applied. It + /// is called synchronously during the call to [pushOpacity]. + /// + /// {@macro flutter.rendering.PaintingContext.pushClipRect.oldLayer} + /// + /// A [RenderObject] that uses this function is very likely to require its + /// [RenderObject.alwaysNeedsCompositing] property to return true. That informs + /// ancestor render objects that this render object will include a composited + /// layer, which, for example, causes them to use composited clips. + OpacityLayer pushOpacity(Offset offset, int alpha, PaintingContextCallback painter, { OpacityLayer? oldLayer }) { + final OpacityLayer layer = oldLayer ?? OpacityLayer(); + layer + ..alpha = alpha + ..offset = offset; + pushLayer(layer, painter, Offset.zero); + return layer; + } + + @override + String toString() => '${objectRuntimeType(this, 'PaintingContext')}#$hashCode(layer: $_containerLayer, canvas bounds: $estimatedBounds)'; +} + +/// An abstract set of layout constraints. +/// +/// Concrete layout models (such as box) will create concrete subclasses to +/// communicate layout constraints between parents and children. +/// +/// ## Writing a Constraints subclass +/// +/// When creating a new [RenderObject] subclass with a new layout protocol, one +/// will usually need to create a new [Constraints] subclass to express the +/// input to the layout algorithms. +/// +/// A [Constraints] subclass should be immutable (all fields final). There are +/// several members to implement, in addition to whatever fields, constructors, +/// and helper methods one may find useful for a particular layout protocol: +/// +/// * The [isTight] getter, which should return true if the object represents a +/// case where the [RenderObject] class has no choice for how to lay itself +/// out. For example, [BoxConstraints] returns true for [isTight] when both +/// the minimum and maximum widths and the minimum and maximum heights are +/// equal. +/// +/// * The [isNormalized] getter, which should return true if the object +/// represents its data in its canonical form. Sometimes, it is possible for +/// fields to be redundant with each other, such that several different +/// representations have the same implications. For example, a +/// [BoxConstraints] instance with its minimum width greater than its maximum +/// width is equivalent to one where the maximum width is set to that minimum +/// width (`2<w<1` is equivalent to `2<w<2`, since minimum constraints have +/// priority). This getter is used by the default implementation of +/// [debugAssertIsValid]. +/// +/// * The [debugAssertIsValid] method, which should assert if there's anything +/// wrong with the constraints object. (We use this approach rather than +/// asserting in constructors so that our constructors can be `const` and so +/// that it is possible to create invalid constraints temporarily while +/// building valid ones.) See the implementation of +/// [BoxConstraints.debugAssertIsValid] for an example of the detailed checks +/// that can be made. +/// +/// * The [==] operator and the [hashCode] getter, so that constraints can be +/// compared for equality. If a render object is given constraints that are +/// equal, then the rendering library will avoid laying the object out again +/// if it is not dirty. +/// +/// * The [toString] method, which should describe the constraints so that they +/// appear in a usefully readable form in the output of [debugDumpRenderTree]. +@immutable +abstract class Constraints { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const Constraints(); + + /// Whether there is exactly one size possible given these constraints. + bool get isTight; + + /// Whether the constraint is expressed in a consistent manner. + bool get isNormalized; + + /// Asserts that the constraints are valid. + /// + /// This might involve checks more detailed than [isNormalized]. + /// + /// For example, the [BoxConstraints] subclass verifies that the constraints + /// are not [double.nan]. + /// + /// If the `isAppliedConstraint` argument is true, then even stricter rules + /// are enforced. This argument is set to true when checking constraints that + /// are about to be applied to a [RenderObject] during layout, as opposed to + /// constraints that may be further affected by other constraints. For + /// example, the asserts for verifying the validity of + /// [RenderConstrainedBox.additionalConstraints] do not set this argument, but + /// the asserts for verifying the argument passed to the [RenderObject.layout] + /// method do. + /// + /// The `informationCollector` argument takes an optional callback which is + /// called when an exception is to be thrown. The collected information is + /// then included in the message after the error line. + /// + /// Returns the same as [isNormalized] if asserts are disabled. + bool debugAssertIsValid({ + bool isAppliedConstraint = false, + InformationCollector? informationCollector, + }) { + assert(isNormalized); + return isNormalized; + } +} + +/// Signature for a function that is called for each [RenderObject]. +/// +/// Used by [RenderObject.visitChildren] and [RenderObject.visitChildrenForSemantics]. +typedef RenderObjectVisitor = void Function(RenderObject child); + +/// Signature for a function that is called during layout. +/// +/// Used by [RenderObject.invokeLayoutCallback]. +typedef LayoutCallback<T extends Constraints> = void Function(T constraints); + +class _LocalSemanticsHandle implements SemanticsHandle { + _LocalSemanticsHandle._(PipelineOwner owner, this.listener) + : _owner = owner { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/rendering.dart', + className: '$_LocalSemanticsHandle', + object: this, + ); + } + + if (listener != null) { + _owner.semanticsOwner!.addListener(listener!); + } + } + + final PipelineOwner _owner; + + /// The callback that will be notified when the semantics tree updates. + final VoidCallback? listener; + + @override + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + + if (listener != null) { + _owner.semanticsOwner!.removeListener(listener!); + } + _owner._didDisposeSemanticsHandle(); + } +} + +/// The pipeline owner manages the rendering pipeline. +/// +/// The pipeline owner provides an interface for driving the rendering pipeline +/// and stores the state about which render objects have requested to be visited +/// in each stage of the pipeline. To flush the pipeline, call the following +/// functions in order: +/// +/// 1. [flushLayout] updates any render objects that need to compute their +/// layout. During this phase, the size and position of each render +/// object is calculated. Render objects might dirty their painting or +/// compositing state during this phase. +/// 2. [flushCompositingBits] updates any render objects that have dirty +/// compositing bits. During this phase, each render object learns whether +/// any of its children require compositing. This information is used during +/// the painting phase when selecting how to implement visual effects such as +/// clipping. If a render object has a composited child, it needs to use a +/// [Layer] to create the clip in order for the clip to apply to the +/// composited child (which will be painted into its own [Layer]). +/// 3. [flushPaint] visits any render objects that need to paint. During this +/// phase, render objects get a chance to record painting commands into +/// [PictureLayer]s and construct other composited [Layer]s. +/// 4. Finally, if semantics are enabled, [flushSemantics] will compile the +/// semantics for the render objects. This semantic information is used by +/// assistive technology to improve the accessibility of the render tree. +/// +/// The [RendererBinding] holds the pipeline owner for the render objects that +/// are visible on screen. You can create other pipeline owners to manage +/// off-screen objects, which can flush their pipelines independently of the +/// on-screen render objects. +/// +/// [PipelineOwner]s can be organized in a tree to manage multiple render trees, +/// where each [PipelineOwner] is responsible for one of the render trees. To +/// build or modify the tree, call [adoptChild] or [dropChild]. During each of +/// the different flush phases described above, a [PipelineOwner] will first +/// perform the phase on the nodes it manages in its own render tree before +/// calling the same flush method on its children. No assumption must be made +/// about the order in which child [PipelineOwner]s are flushed. +/// +/// A [PipelineOwner] may also be [attach]ed to a [PipelineManifold], which +/// gives it access to platform functionality usually exposed by the bindings +/// without tying it to a specific binding implementation. All [PipelineOwner]s +/// in a given tree must be attached to the same [PipelineManifold]. This +/// happens automatically during [adoptChild]. +class PipelineOwner with DiagnosticableTreeMixin { + /// Creates a pipeline owner. + /// + /// Typically created by the binding (e.g., [RendererBinding]), but can be + /// created separately from the binding to drive off-screen render objects + /// through the rendering pipeline. + PipelineOwner({ + this.onNeedVisualUpdate, + this.onSemanticsOwnerCreated, + this.onSemanticsUpdate, + this.onSemanticsOwnerDisposed, + }){ + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/rendering.dart', + className: '$PipelineOwner', + object: this, + ); + } + } + + /// Called when a render object associated with this pipeline owner wishes to + /// update its visual appearance. + /// + /// Typical implementations of this function will schedule a task to flush the + /// various stages of the pipeline. This function might be called multiple + /// times in quick succession. Implementations should take care to discard + /// duplicate calls quickly. + /// + /// When the [PipelineOwner] is attached to a [PipelineManifold] and + /// [onNeedVisualUpdate] is provided, the [onNeedVisualUpdate] callback is + /// invoked instead of calling [PipelineManifold.requestVisualUpdate]. + final VoidCallback? onNeedVisualUpdate; + + /// Called whenever this pipeline owner creates a semantics object. + /// + /// Typical implementations will schedule the creation of the initial + /// semantics tree. + final VoidCallback? onSemanticsOwnerCreated; + + /// Called whenever this pipeline owner's semantics owner emits a [SemanticsUpdate]. + /// + /// Typical implementations will delegate the [SemanticsUpdate] to a [FlutterView] + /// that can handle the [SemanticsUpdate]. + final SemanticsUpdateCallback? onSemanticsUpdate; + + /// Called whenever this pipeline owner disposes its semantics owner. + /// + /// Typical implementations will tear down the semantics tree. + final VoidCallback? onSemanticsOwnerDisposed; + + /// Calls [onNeedVisualUpdate] if [onNeedVisualUpdate] is not null. + /// + /// Used to notify the pipeline owner that an associated render object wishes + /// to update its visual appearance. + void requestVisualUpdate() { + if (onNeedVisualUpdate != null) { + onNeedVisualUpdate!(); + } else { + _manifold?.requestVisualUpdate(); + } + } + + /// The unique object managed by this pipeline that has no parent. + RenderObject? get rootNode => _rootNode; + RenderObject? _rootNode; + set rootNode(RenderObject? value) { + if (_rootNode == value) { + return; + } + _rootNode?.detach(); + _rootNode = value; + _rootNode?.attach(this); + } + + // Whether the current [flushLayout] call should pause to incorporate the + // [RenderObject]s in `_nodesNeedingLayout` into the current dirty list, + // before continuing to process dirty relayout boundaries. + // + // This flag is set to true when a [RenderObject.invokeLayoutCallback] + // returns, to avoid laying out dirty relayout boundaries in an incorrect + // order and causing them to be laid out more than once per frame. See + // layout_builder_mutations_test.dart for an example. + // + // The new dirty nodes are not immediately merged after a + // [RenderObject.invokeLayoutCallback] call because we may encounter multiple + // such calls while processing a single relayout boundary in [flushLayout]. + // Batching new dirty nodes can reduce the number of merges [flushLayout] + // has to perform. + bool _shouldMergeDirtyNodes = false; + List<RenderObject> _nodesNeedingLayout = <RenderObject>[]; + + /// Whether this pipeline is currently in the layout phase. + /// + /// Specifically, whether [flushLayout] is currently running. + /// + /// Only valid when asserts are enabled; in release builds, this + /// always returns false. + bool get debugDoingLayout => _debugDoingLayout; + bool _debugDoingLayout = false; + bool _debugDoingChildLayout = false; + + /// Update the layout information for all dirty render objects. + /// + /// This function is one of the core stages of the rendering pipeline. Layout + /// information is cleaned prior to painting so that render objects will + /// appear on screen in their up-to-date locations. + /// + /// See [RendererBinding] for an example of how this function is used. + void flushLayout() { + if (!kReleaseMode) { + Map<String, String>? debugTimelineArguments; + assert(() { + if (debugEnhanceLayoutTimelineArguments) { + debugTimelineArguments = <String, String>{ + 'dirty count': '${_nodesNeedingLayout.length}', + 'dirty list': '$_nodesNeedingLayout', + }; + } + return true; + }()); + FlutterTimeline.startSync( + 'LAYOUT$_debugRootSuffixForTimelineEventNames', + arguments: debugTimelineArguments, + ); + } + assert(() { + _debugDoingLayout = true; + return true; + }()); + try { + while (_nodesNeedingLayout.isNotEmpty) { + assert(!_shouldMergeDirtyNodes); + final List<RenderObject> dirtyNodes = _nodesNeedingLayout; + _nodesNeedingLayout = <RenderObject>[]; + dirtyNodes.sort((RenderObject a, RenderObject b) => a.depth - b.depth); + for (int i = 0; i < dirtyNodes.length; i++) { + if (_shouldMergeDirtyNodes) { + _shouldMergeDirtyNodes = false; + if (_nodesNeedingLayout.isNotEmpty) { + _nodesNeedingLayout.addAll(dirtyNodes.getRange(i, dirtyNodes.length)); + break; + } + } + final RenderObject node = dirtyNodes[i]; + if (node._needsLayout && node.owner == this) { + node._layoutWithoutResize(); + } + } + // No need to merge dirty nodes generated from processing the last + // relayout boundary back. + _shouldMergeDirtyNodes = false; + } + + assert(() { + _debugDoingChildLayout = true; + return true; + }()); + for (final PipelineOwner child in _children) { + child.flushLayout(); + } + assert(_nodesNeedingLayout.isEmpty, 'Child PipelineOwners must not dirty nodes in their parent.'); + } finally { + _shouldMergeDirtyNodes = false; + assert(() { + _debugDoingLayout = false; + _debugDoingChildLayout = false; + return true; + }()); + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + } + } + + // This flag is used to allow the kinds of mutations performed by GlobalKey + // reparenting while a LayoutBuilder is being rebuilt and in so doing tries to + // move a node from another LayoutBuilder subtree that hasn't been updated + // yet. To set this, call [_enableMutationsToDirtySubtrees], which is called + // by [RenderObject.invokeLayoutCallback]. + bool _debugAllowMutationsToDirtySubtrees = false; + + // See [RenderObject.invokeLayoutCallback]. + void _enableMutationsToDirtySubtrees(VoidCallback callback) { + assert(_debugDoingLayout); + bool? oldState; + assert(() { + oldState = _debugAllowMutationsToDirtySubtrees; + _debugAllowMutationsToDirtySubtrees = true; + return true; + }()); + try { + callback(); + } finally { + _shouldMergeDirtyNodes = true; + assert(() { + _debugAllowMutationsToDirtySubtrees = oldState!; + return true; + }()); + } + } + + final List<RenderObject> _nodesNeedingCompositingBitsUpdate = <RenderObject>[]; + /// Updates the [RenderObject.needsCompositing] bits. + /// + /// Called as part of the rendering pipeline after [flushLayout] and before + /// [flushPaint]. + void flushCompositingBits() { + if (!kReleaseMode) { + FlutterTimeline.startSync('UPDATING COMPOSITING BITS$_debugRootSuffixForTimelineEventNames'); + } + _nodesNeedingCompositingBitsUpdate.sort((RenderObject a, RenderObject b) => a.depth - b.depth); + for (final RenderObject node in _nodesNeedingCompositingBitsUpdate) { + if (node._needsCompositingBitsUpdate && node.owner == this) { + node._updateCompositingBits(); + } + } + _nodesNeedingCompositingBitsUpdate.clear(); + for (final PipelineOwner child in _children) { + child.flushCompositingBits(); + } + assert(_nodesNeedingCompositingBitsUpdate.isEmpty, 'Child PipelineOwners must not dirty nodes in their parent.'); + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + } + + List<RenderObject> _nodesNeedingPaint = <RenderObject>[]; + + /// Whether this pipeline is currently in the paint phase. + /// + /// Specifically, whether [flushPaint] is currently running. + /// + /// Only valid when asserts are enabled. In release builds, + /// this always returns false. + bool get debugDoingPaint => _debugDoingPaint; + bool _debugDoingPaint = false; + + /// Update the display lists for all render objects. + /// + /// This function is one of the core stages of the rendering pipeline. + /// Painting occurs after layout and before the scene is recomposited so that + /// scene is composited with up-to-date display lists for every render object. + /// + /// See [RendererBinding] for an example of how this function is used. + void flushPaint() { + if (!kReleaseMode) { + Map<String, String>? debugTimelineArguments; + assert(() { + if (debugEnhancePaintTimelineArguments) { + debugTimelineArguments = <String, String>{ + 'dirty count': '${_nodesNeedingPaint.length}', + 'dirty list': '$_nodesNeedingPaint', + }; + } + return true; + }()); + FlutterTimeline.startSync( + 'PAINT$_debugRootSuffixForTimelineEventNames', + arguments: debugTimelineArguments, + ); + } + try { + assert(() { + _debugDoingPaint = true; + return true; + }()); + final List<RenderObject> dirtyNodes = _nodesNeedingPaint; + _nodesNeedingPaint = <RenderObject>[]; + + // Sort the dirty nodes in reverse order (deepest first). + for (final RenderObject node in dirtyNodes..sort((RenderObject a, RenderObject b) => b.depth - a.depth)) { + assert(node._layerHandle.layer != null); + if ((node._needsPaint || node._needsCompositedLayerUpdate) && node.owner == this) { + if (node._layerHandle.layer!.attached) { + assert(node.isRepaintBoundary); + if (node._needsPaint) { + PaintingContext.repaintCompositedChild(node); + } else { + PaintingContext.updateLayerProperties(node); + } + } else { + node._skippedPaintingOnLayer(); + } + } + } + for (final PipelineOwner child in _children) { + child.flushPaint(); + } + assert(_nodesNeedingPaint.isEmpty, 'Child PipelineOwners must not dirty nodes in their parent.'); + } finally { + assert(() { + _debugDoingPaint = false; + return true; + }()); + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + } + } + + /// The object that is managing semantics for this pipeline owner, if any. + /// + /// An owner is created by [ensureSemantics] or when the [PipelineManifold] to + /// which this owner is connected has [PipelineManifold.semanticsEnabled] set + /// to true. The owner is valid for as long as + /// [PipelineManifold.semanticsEnabled] remains true or while there are + /// outstanding [SemanticsHandle]s from calls to [ensureSemantics]. The + /// [semanticsOwner] field will revert to null once both conditions are no + /// longer met. + /// + /// When [semanticsOwner] is null, the [PipelineOwner] skips all steps + /// relating to semantics. + SemanticsOwner? get semanticsOwner => _semanticsOwner; + SemanticsOwner? _semanticsOwner; + + /// The number of clients registered to listen for semantics. + /// + /// The number is increased whenever [ensureSemantics] is called and decreased + /// when [SemanticsHandle.dispose] is called. + int get debugOutstandingSemanticsHandles => _outstandingSemanticsHandles; + int _outstandingSemanticsHandles = 0; + + /// Opens a [SemanticsHandle] and calls [listener] whenever the semantics tree + /// generated from the render tree owned by this [PipelineOwner] updates. + /// + /// Calling this method only ensures that this particular [PipelineOwner] will + /// generate a semantics tree. Consider calling + /// [SemanticsBinding.ensureSemantics] instead to turn on semantics globally + /// for the entire app. + /// + /// The [PipelineOwner] updates the semantics tree only when there are clients + /// that wish to use the semantics tree. These clients express their interest + /// by holding [SemanticsHandle] objects that notify them whenever the + /// semantics tree updates. + /// + /// Clients can close their [SemanticsHandle] by calling + /// [SemanticsHandle.dispose]. Once all the outstanding [SemanticsHandle] + /// objects for a given [PipelineOwner] are closed, the [PipelineOwner] stops + /// maintaining the semantics tree. + SemanticsHandle ensureSemantics({ VoidCallback? listener }) { + _outstandingSemanticsHandles += 1; + _updateSemanticsOwner(); + return _LocalSemanticsHandle._(this, listener); + } + + void _updateSemanticsOwner() { + if ((_manifold?.semanticsEnabled ?? false) || _outstandingSemanticsHandles > 0) { + if (_semanticsOwner == null) { + assert(onSemanticsUpdate != null, 'Attempted to enable semantics without configuring an onSemanticsUpdate callback.'); + _semanticsOwner = SemanticsOwner(onSemanticsUpdate: onSemanticsUpdate!); + onSemanticsOwnerCreated?.call(); + } + } else if (_semanticsOwner != null) { + _semanticsOwner?.dispose(); + _semanticsOwner = null; + onSemanticsOwnerDisposed?.call(); + } + } + + void _didDisposeSemanticsHandle() { + assert(_semanticsOwner != null); + _outstandingSemanticsHandles -= 1; + _updateSemanticsOwner(); + } + + bool _debugDoingSemantics = false; + final Set<RenderObject> _nodesNeedingSemantics = <RenderObject>{}; + + /// Update the semantics for render objects marked as needing a semantics + /// update. + /// + /// Initially, only the root node, as scheduled by + /// [RenderObject.scheduleInitialSemantics], needs a semantics update. + /// + /// This function is one of the core stages of the rendering pipeline. The + /// semantics are compiled after painting and only after + /// [RenderObject.scheduleInitialSemantics] has been called. + /// + /// See [RendererBinding] for an example of how this function is used. + void flushSemantics() { + if (_semanticsOwner == null) { + return; + } + if (!kReleaseMode) { + FlutterTimeline.startSync('SEMANTICS$_debugRootSuffixForTimelineEventNames'); + } + assert(_semanticsOwner != null); + assert(() { + _debugDoingSemantics = true; + return true; + }()); + try { + final List<RenderObject> nodesToProcess = _nodesNeedingSemantics.toList() + ..sort((RenderObject a, RenderObject b) => a.depth - b.depth); + _nodesNeedingSemantics.clear(); + for (final RenderObject node in nodesToProcess) { + if (node._needsSemanticsUpdate && node.owner == this) { + node._updateSemantics(); + } + } + _semanticsOwner!.sendSemanticsUpdate(); + for (final PipelineOwner child in _children) { + child.flushSemantics(); + } + assert(_nodesNeedingSemantics.isEmpty, 'Child PipelineOwners must not dirty nodes in their parent.'); + } finally { + assert(() { + _debugDoingSemantics = false; + return true; + }()); + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + } + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return <DiagnosticsNode>[ + for (final PipelineOwner child in _children) + child.toDiagnosticsNode(), + ]; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<RenderObject>('rootNode', rootNode, defaultValue: null)); + } + + // TREE MANAGEMENT + + final Set<PipelineOwner> _children = <PipelineOwner>{}; + PipelineManifold? _manifold; + + PipelineOwner? _debugParent; + bool _debugSetParent(PipelineOwner child, PipelineOwner? parent) { + child._debugParent = parent; + return true; + } + + String get _debugRootSuffixForTimelineEventNames => _debugParent == null ? ' (root)' : ''; + + /// Mark this [PipelineOwner] as attached to the given [PipelineManifold]. + /// + /// Typically, this is only called directly on the root [PipelineOwner]. + /// Children are automatically attached to their parent's [PipelineManifold] + /// when [adoptChild] is called. + void attach(PipelineManifold manifold) { + assert(_manifold == null); + _manifold = manifold; + _manifold!.addListener(_updateSemanticsOwner); + _updateSemanticsOwner(); + + for (final PipelineOwner child in _children) { + child.attach(manifold); + } + } + + /// Mark this [PipelineOwner] as detached. + /// + /// Typically, this is only called directly on the root [PipelineOwner]. + /// Children are automatically detached from their parent's [PipelineManifold] + /// when [dropChild] is called. + void detach() { + assert(_manifold != null); + _manifold!.removeListener(_updateSemanticsOwner); + _manifold = null; + // Not updating the semantics owner here to not disrupt any of its clients + // in case we get re-attached. If necessary, semantics owner will be updated + // in "attach", or disposed in "dispose", if not reattached. + + for (final PipelineOwner child in _children) { + child.detach(); + } + } + + // In theory, child list modifications are also disallowed between + // _debugDoingChildrenLayout and _debugDoingPaint as well as between + // _debugDoingPaint and _debugDoingSemantics. However, since the associated + // flush methods are usually called back to back, this gets us close enough. + bool get _debugAllowChildListModifications => !_debugDoingChildLayout && !_debugDoingPaint && !_debugDoingSemantics; + + /// Adds `child` to this [PipelineOwner]. + /// + /// During the phases of frame production (see [RendererBinding.drawFrame]), + /// the parent [PipelineOwner] will complete a phase for the nodes it owns + /// directly before invoking the flush method corresponding to the current + /// phase on its child [PipelineOwner]s. For example, during layout, the + /// parent [PipelineOwner] will first lay out its own nodes before calling + /// [flushLayout] on its children. During paint, it will first paint its own + /// nodes before calling [flushPaint] on its children. This order also applies + /// for all the other phases. + /// + /// No assumptions must be made about the order in which child + /// [PipelineOwner]s are flushed. + /// + /// No new children may be added after the [PipelineOwner] has started calling + /// [flushLayout] on any of its children until the end of the current frame. + /// + /// To remove a child, call [dropChild]. + void adoptChild(PipelineOwner child) { + assert(child._debugParent == null); + assert(!_children.contains(child)); + assert(_debugAllowChildListModifications, 'Cannot modify child list after layout.'); + _children.add(child); + if (!kReleaseMode) { + _debugSetParent(child, this); + } + if (_manifold != null) { + child.attach(_manifold!); + } + } + + /// Removes a child [PipelineOwner] previously added via [adoptChild]. + /// + /// This node will cease to call the flush methods on the `child` during frame + /// production. + /// + /// No children may be removed after the [PipelineOwner] has started calling + /// [flushLayout] on any of its children until the end of the current frame. + void dropChild(PipelineOwner child) { + assert(child._debugParent == this); + assert(_children.contains(child)); + assert(_debugAllowChildListModifications, 'Cannot modify child list after layout.'); + _children.remove(child); + if (!kReleaseMode) { + _debugSetParent(child, null); + } + if (_manifold != null) { + child.detach(); + } + } + + /// Calls `visitor` for each immediate child of this [PipelineOwner]. + /// + /// See also: + /// + /// * [adoptChild] to add a child. + /// * [dropChild] to remove a child. + void visitChildren(PipelineOwnerVisitor visitor) { + _children.forEach(visitor); + } + + /// Release any resources held by this pipeline owner. + /// + /// Prior to calling this method the pipeline owner must be removed from the + /// pipeline owner tree, i.e. it must have neither a parent nor any children + /// (see [dropChild]). It also must be [detach]ed from any [PipelineManifold]. + /// + /// The object is no longer usable after calling dispose. + void dispose() { + assert(_children.isEmpty); + assert(rootNode == null); + assert(_manifold == null); + assert(_debugParent == null); + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _semanticsOwner?.dispose(); + _semanticsOwner = null; + _nodesNeedingLayout.clear(); + _nodesNeedingCompositingBitsUpdate.clear(); + _nodesNeedingPaint.clear(); + _nodesNeedingSemantics.clear(); + } +} + +/// Signature for the callback to [PipelineOwner.visitChildren]. +/// +/// The argument is the child being visited. +typedef PipelineOwnerVisitor = void Function(PipelineOwner child); + +/// Manages a tree of [PipelineOwner]s. +/// +/// All [PipelineOwner]s within a tree are attached to the same +/// [PipelineManifold], which gives them access to shared functionality such +/// as requesting a visual update (by calling [requestVisualUpdate]). As such, +/// the [PipelineManifold] gives the [PipelineOwner]s access to functionality +/// usually provided by the bindings without tying the [PipelineOwner]s to a +/// particular binding implementation. +/// +/// The root of the [PipelineOwner] tree is attached to a [PipelineManifold] by +/// passing the manifold to [PipelineOwner.attach]. Children are attached to the +/// same [PipelineManifold] as their parent when they are adopted via +/// [PipelineOwner.adoptChild]. +/// +/// [PipelineOwner]s can register listeners with the [PipelineManifold] to be +/// informed when certain values provided by the [PipelineManifold] change. +abstract class PipelineManifold implements Listenable { + /// Whether [PipelineOwner]s connected to this [PipelineManifold] should + /// collect semantics information and produce a semantics tree. + /// + /// The [PipelineManifold] notifies its listeners (managed with [addListener] + /// and [removeListener]) when this property changes its value. + /// + /// See also: + /// + /// * [SemanticsBinding.semanticsEnabled], which [PipelineManifold] + /// implementations typically use to back this property. + bool get semanticsEnabled; + + /// Called by a [PipelineOwner] connected to this [PipelineManifold] when a + /// [RenderObject] associated with that pipeline owner wishes to update its + /// visual appearance. + /// + /// Typical implementations of this function will schedule a task to flush the + /// various stages of the pipeline. This function might be called multiple + /// times in quick succession. Implementations should take care to discard + /// duplicate calls quickly. + /// + /// A [PipelineOwner] connected to this [PipelineManifold] will call + /// [PipelineOwner.onNeedVisualUpdate] instead of this method if it has been + /// configured with a non-null [PipelineOwner.onNeedVisualUpdate] callback. + /// + /// See also: + /// + /// * [SchedulerBinding.ensureVisualUpdate], which [PipelineManifold] + /// implementations typically call to implement this method. + void requestVisualUpdate(); +} + +const String _flutterRenderingLibrary = 'package:flutter/rendering.dart'; + +/// An object in the render tree. +/// +/// The [RenderObject] class hierarchy is the core of the rendering +/// library's reason for being. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=zmbmrw07qBc} +/// +/// [RenderObject]s have a [parent], and have a slot called [parentData] in +/// which the parent [RenderObject] can store child-specific data, for example, +/// the child position. The [RenderObject] class also implements the basic +/// layout and paint protocols. +/// +/// The [RenderObject] class, however, does not define a child model (e.g. +/// whether a node has zero, one, or more children). It also doesn't define a +/// coordinate system (e.g. whether children are positioned in Cartesian +/// coordinates, in polar coordinates, etc) or a specific layout protocol (e.g. +/// whether the layout is width-in-height-out, or constraint-in-size-out, or +/// whether the parent sets the size and position of the child before or after +/// the child lays out, etc; or indeed whether the children are allowed to read +/// their parent's [parentData] slot). +/// +/// The [RenderBox] subclass introduces the opinion that the layout +/// system uses Cartesian coordinates. +/// +/// ## Lifecycle +/// +/// A [RenderObject] must [dispose] when it is no longer needed. The creator +/// of the object is responsible for disposing of it. Typically, the creator is +/// a [RenderObjectElement], and that element will dispose the object it creates +/// when it is unmounted. +/// +/// [RenderObject]s are responsible for cleaning up any expensive resources +/// they hold when [dispose] is called, such as [Picture] or [Image] objects. +/// This includes any [Layer]s that the render object has directly created. The +/// base implementation of dispose will nullify the [layer] property. Subclasses +/// must also nullify any other layer(s) it directly creates. +/// +/// ## Writing a RenderObject subclass +/// +/// In most cases, subclassing [RenderObject] itself is overkill, and +/// [RenderBox] would be a better starting point. However, if a render object +/// doesn't want to use a Cartesian coordinate system, then it should indeed +/// inherit from [RenderObject] directly. This allows it to define its own +/// layout protocol by using a new subclass of [Constraints] rather than using +/// [BoxConstraints], and by potentially using an entirely new set of objects +/// and values to represent the result of the output rather than just a [Size]. +/// This increased flexibility comes at the cost of not being able to rely on +/// the features of [RenderBox]. For example, [RenderBox] implements an +/// intrinsic sizing protocol that allows you to measure a child without fully +/// laying it out, in such a way that if that child changes size, the parent +/// will be laid out again (to take into account the new dimensions of the +/// child). This is a subtle and bug-prone feature to get right. +/// +/// Most aspects of writing a [RenderBox] apply to writing a [RenderObject] as +/// well, and therefore the discussion at [RenderBox] is recommended background +/// reading. The main differences are around layout and hit testing, since those +/// are the aspects that [RenderBox] primarily specializes. +/// +/// ### Layout +/// +/// A layout protocol begins with a subclass of [Constraints]. See the +/// discussion at [Constraints] for more information on how to write a +/// [Constraints] subclass. +/// +/// The [performLayout] method should take the [constraints], and apply them. +/// The output of the layout algorithm is fields set on the object that describe +/// the geometry of the object for the purposes of the parent's layout. For +/// example, with [RenderBox] the output is the [RenderBox.size] field. This +/// output should only be read by the parent if the parent specified +/// `parentUsesSize` as true when calling [layout] on the child. +/// +/// Anytime anything changes on a render object that would affect the layout of +/// that object, it should call [markNeedsLayout]. +/// +/// ### Hit Testing +/// +/// Hit testing is even more open-ended than layout. There is no method to +/// override, you are expected to provide one. +/// +/// The general behavior of your hit-testing method should be similar to the +/// behavior described for [RenderBox]. The main difference is that the input +/// need not be an [Offset]. You are also allowed to use a different subclass of +/// [HitTestEntry] when adding entries to the [HitTestResult]. When the +/// [handleEvent] method is called, the same object that was added to the +/// [HitTestResult] will be passed in, so it can be used to track information +/// like the precise coordinate of the hit, in whatever coordinate system is +/// used by the new layout protocol. +/// +/// ### Adapting from one protocol to another +/// +/// In general, the root of a Flutter render object tree is a [RenderView]. This +/// object has a single child, which must be a [RenderBox]. Thus, if you want to +/// have a custom [RenderObject] subclass in the render tree, you have two +/// choices: you either need to replace the [RenderView] itself, or you need to +/// have a [RenderBox] that has your class as its child. (The latter is the much +/// more common case.) +/// +/// This [RenderBox] subclass converts from the box protocol to the protocol of +/// your class. +/// +/// In particular, this means that for hit testing it overrides +/// [RenderBox.hitTest], and calls whatever method you have in your class for +/// hit testing. +/// +/// Similarly, it overrides [performLayout] to create a [Constraints] object +/// appropriate for your class and passes that to the child's [layout] method. +/// +/// ### Layout interactions between render objects +/// +/// In general, the layout of a render object should only depend on the output of +/// its child's layout, and then only if `parentUsesSize` is set to true in the +/// [layout] call. Furthermore, if it is set to true, the parent must call the +/// child's [layout] if the child is to be rendered, because otherwise the +/// parent will not be notified when the child changes its layout outputs. +/// +/// It is possible to set up render object protocols that transfer additional +/// information. For example, in the [RenderBox] protocol you can query your +/// children's intrinsic dimensions and baseline geometry. However, if this is +/// done then it is imperative that the child call [markNeedsLayout] on the +/// parent any time that additional information changes, if the parent used it +/// in the last layout phase. For an example of how to implement this, see the +/// [RenderBox.markNeedsLayout] method. It overrides +/// [RenderObject.markNeedsLayout] so that if a parent has queried the intrinsic +/// or baseline information, it gets marked dirty whenever the child's geometry +/// changes. +abstract class RenderObject with DiagnosticableTreeMixin implements HitTestTarget { + /// Initializes internal fields for subclasses. + RenderObject() { + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: _flutterRenderingLibrary, + className: '$RenderObject', + object: this, + ); + } + _needsCompositing = isRepaintBoundary || alwaysNeedsCompositing; + _wasRepaintBoundary = isRepaintBoundary; + } + + /// Cause the entire subtree rooted at the given [RenderObject] to be marked + /// dirty for layout, paint, etc, so that the effects of a hot reload can be + /// seen, or so that the effect of changing a global debug flag (such as + /// [debugPaintSizeEnabled]) can be applied. + /// + /// This is called by the [RendererBinding] in response to the + /// `ext.flutter.reassemble` hook, which is used by development tools when the + /// application code has changed, to cause the widget tree to pick up any + /// changed implementations. + /// + /// This is expensive and should not be called except during development. + /// + /// See also: + /// + /// * [BindingBase.reassembleApplication] + void reassemble() { + markNeedsLayout(); + markNeedsCompositingBitsUpdate(); + markNeedsPaint(); + markNeedsSemanticsUpdate(); + visitChildren((RenderObject child) { + child.reassemble(); + }); + } + + /// Whether this has been disposed. + /// + /// If asserts are disabled, this property is always null. + bool? get debugDisposed { + bool? disposed; + assert(() { + disposed = _debugDisposed; + return true; + }()); + return disposed; + } + + bool _debugDisposed = false; + + /// Release any resources held by this render object. + /// + /// The object that creates a RenderObject is in charge of disposing it. + /// If this render object has created any children directly, it must dispose + /// of those children in this method as well. It must not dispose of any + /// children that were created by some other object, such as + /// a [RenderObjectElement]. Those children will be disposed when that + /// element unmounts, which may be delayed if the element is moved to another + /// part of the tree. + /// + /// Implementations of this method must end with a call to the inherited + /// method, as in `super.dispose()`. + /// + /// The object is no longer usable after calling dispose. + @mustCallSuper + void dispose() { + assert(!_debugDisposed); + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _layerHandle.layer = null; + assert(() { + // TODO(dnfield): Enable this assert once clients have had a chance to + // migrate. + // visitChildren((RenderObject child) { + // assert( + // child.debugDisposed!, + // '${child.runtimeType} (child of $runtimeType) must be disposed before calling super.dispose().', + // ); + // }); + _debugDisposed = true; + return true; + }()); + } + + // LAYOUT + + /// Data for use by the parent render object. + /// + /// The parent data is used by the render object that lays out this object + /// (typically this object's parent in the render tree) to store information + /// relevant to itself and to any other nodes who happen to know exactly what + /// the data means. The parent data is opaque to the child. + /// + /// * The parent data field must not be directly set, except by calling + /// [setupParentData] on the parent node. + /// * The parent data can be set before the child is added to the parent, by + /// calling [setupParentData] on the future parent node. + /// * The conventions for using the parent data depend on the layout protocol + /// used between the parent and child. For example, in box layout, the + /// parent data is completely opaque but in sector layout the child is + /// permitted to read some fields of the parent data. + ParentData? parentData; + + /// Override to setup parent data correctly for your children. + /// + /// You can call this function to set up the parent data for child before the + /// child is added to the parent's child list. + void setupParentData(covariant RenderObject child) { + assert(_debugCanPerformMutations); + if (child.parentData is! ParentData) { + child.parentData = ParentData(); + } + } + + /// The depth of this render object in the render tree. + /// + /// The depth of nodes in a tree monotonically increases as you traverse down + /// the tree: a node always has a [depth] greater than its ancestors. + /// There's no guarantee regarding depth between siblings. + /// + /// The [depth] of a child can be more than one greater than the [depth] of + /// the parent, because the [depth] values are never decreased: all that + /// matters is that it's greater than the parent. Consider a tree with a root + /// node A, a child B, and a grandchild C. Initially, A will have [depth] 0, + /// B [depth] 1, and C [depth] 2. If C is moved to be a child of A, + /// sibling of B, then the numbers won't change. C's [depth] will still be 2. + /// + /// The depth of a node is used to ensure that nodes are processed in + /// depth order. The [depth] is automatically maintained by the [adoptChild] + /// and [dropChild] methods. + int get depth => _depth; + int _depth = 0; + + /// Adjust the [depth] of the given [child] to be greater than this node's own + /// [depth]. + /// + /// Only call this method from overrides of [redepthChildren]. + @protected + void redepthChild(RenderObject child) { + assert(child.owner == owner); + if (child._depth <= _depth) { + child._depth = _depth + 1; + child.redepthChildren(); + } + } + + /// Adjust the [depth] of this node's children, if any. + /// + /// Override this method in subclasses with child nodes to call [redepthChild] + /// for each child. Do not call this method directly. + @protected + void redepthChildren() { } + + /// The parent of this render object in the render tree. + /// + /// The [parent] of the root node in the render tree is null. + RenderObject? get parent => _parent; + RenderObject? _parent; + + /// Called by subclasses when they decide a render object is a child. + /// + /// Only for use by subclasses when changing their child lists. Calling this + /// in other cases will lead to an inconsistent tree and probably cause crashes. + @mustCallSuper + @protected + void adoptChild(RenderObject child) { + assert(child._parent == null); + assert(() { + RenderObject node = this; + while (node.parent != null) { + node = node.parent!; + } + assert(node != child); // indicates we are about to create a cycle + return true; + }()); + + setupParentData(child); + markNeedsLayout(); + markNeedsCompositingBitsUpdate(); + markNeedsSemanticsUpdate(); + child._parent = this; + if (attached) { + child.attach(_owner!); + } + redepthChild(child); + } + + /// Called by subclasses when they decide a render object is no longer a child. + /// + /// Only for use by subclasses when changing their child lists. Calling this + /// in other cases will lead to an inconsistent tree and probably cause crashes. + @mustCallSuper + @protected + void dropChild(RenderObject child) { + assert(child._parent == this); + assert(child.attached == attached); + assert(child.parentData != null); + child._cleanRelayoutBoundary(); + child.parentData!.detach(); + child.parentData = null; + child._parent = null; + if (attached) { + child.detach(); + } + markNeedsLayout(); + markNeedsCompositingBitsUpdate(); + markNeedsSemanticsUpdate(); + } + + /// Calls visitor for each immediate child of this render object. + /// + /// Override in subclasses with children and call the visitor for each child. + void visitChildren(RenderObjectVisitor visitor) { } + + /// The object responsible for creating this render object. + /// + /// Used in debug messages. + /// + /// See also: + /// + /// * [DebugCreator], which the [widgets] library uses as values for this field. + Object? debugCreator; + + void _reportException(String method, Object exception, StackTrace stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'rendering library', + context: ErrorDescription('during $method()'), + informationCollector: () => <DiagnosticsNode>[ + // debugCreator should always be null outside of debugMode, but we want + // the tree shaker to notice this. + if (kDebugMode && debugCreator != null) + DiagnosticsDebugCreator(debugCreator!), + describeForError('The following RenderObject was being processed when the exception was fired'), + // TODO(jacobr): this error message has a code smell. Consider whether + // displaying the truncated children is really useful for command line + // users. Inspector users can see the full tree by clicking on the + // render object so this may not be that useful. + describeForError('RenderObject', style: DiagnosticsTreeStyle.truncateChildren), + ], + )); + } + + /// Whether [performResize] for this render object is currently running. + /// + /// Only valid when asserts are enabled. In release builds, always returns + /// false. + bool get debugDoingThisResize => _debugDoingThisResize; + bool _debugDoingThisResize = false; + + /// Whether [performLayout] for this render object is currently running. + /// + /// Only valid when asserts are enabled. In release builds, always returns + /// false. + bool get debugDoingThisLayout => _debugDoingThisLayout; + bool _debugDoingThisLayout = false; + + /// The render object that is actively computing layout. + /// + /// Only valid when asserts are enabled. In release builds, always returns + /// null. + static RenderObject? get debugActiveLayout => _debugActiveLayout; + static RenderObject? _debugActiveLayout; + + /// Set [debugActiveLayout] to null when [inner] callback is called. + /// This is useful when you have to temporarily clear that variable to + /// disable some false-positive checks, such as when computing toStringDeep + /// or using custom trees. + @pragma('vm:prefer-inline') + static T _withDebugActiveLayoutCleared<T>(T Function() inner) { + RenderObject? debugPreviousActiveLayout; + assert(() { + debugPreviousActiveLayout = _debugActiveLayout; + _debugActiveLayout = null; + return true; + }()); + final T result = inner(); + assert(() { + _debugActiveLayout = debugPreviousActiveLayout; + return true; + }()); + return result; + } + + /// Whether the parent render object is permitted to use this render object's + /// size. + /// + /// Determined by the `parentUsesSize` parameter to [layout]. + /// + /// Only valid when asserts are enabled. In release builds, throws. + bool get debugCanParentUseSize => _debugCanParentUseSize!; + bool? _debugCanParentUseSize; + + bool _debugMutationsLocked = false; + + /// Whether tree mutations are currently permitted. + /// + /// This is only useful during layout. One should also not mutate the tree at + /// other times (e.g. during paint or while assembling the semantic tree) but + /// this function does not currently enforce those conventions. + /// + /// Only valid when asserts are enabled. This will throw in release builds. + bool get _debugCanPerformMutations { + late bool result; + assert(() { + if (_debugDisposed) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('A disposed RenderObject was mutated.'), + DiagnosticsProperty<RenderObject>( + 'The disposed RenderObject was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]); + } + + final PipelineOwner? owner = this.owner; + // Detached nodes are allowed to mutate and the "can perform mutations" + // check will be performed when they re-attach. This assert is only useful + // during layout. + if (owner == null || !owner.debugDoingLayout) { + result = true; + return true; + } + + RenderObject? activeLayoutRoot = this; + while (activeLayoutRoot != null) { + final bool mutationsToDirtySubtreesAllowed = activeLayoutRoot.owner?._debugAllowMutationsToDirtySubtrees ?? false; + final bool doingLayoutWithCallback = activeLayoutRoot._doingThisLayoutWithCallback; + // Mutations on this subtree is allowed when: + // - the "activeLayoutRoot" subtree is being mutated in a layout callback. + // - a different part of the render tree is doing a layout callback, + // and this subtree is being reparented to that subtree, as a result + // of global key reparenting. + if (doingLayoutWithCallback || mutationsToDirtySubtreesAllowed && activeLayoutRoot._needsLayout) { + result = true; + return true; + } + + if (!activeLayoutRoot._debugMutationsLocked) { + final RenderObject? p = activeLayoutRoot.debugLayoutParent; + activeLayoutRoot = p is RenderObject ? p : null; + } else { + // activeLayoutRoot found. + break; + } + } + + final RenderObject debugActiveLayout = RenderObject.debugActiveLayout!; + final String culpritMethodName = debugActiveLayout.debugDoingThisLayout ? 'performLayout' : 'performResize'; + final String culpritFullMethodName = '${debugActiveLayout.runtimeType}.$culpritMethodName'; + result = false; + + if (activeLayoutRoot == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('A $runtimeType was mutated in $culpritFullMethodName.'), + ErrorDescription( + 'The RenderObject was mutated when none of its ancestors is actively performing layout.', + ), + DiagnosticsProperty<RenderObject>( + 'The RenderObject being mutated was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + DiagnosticsProperty<RenderObject>( + 'The RenderObject that was mutating the said $runtimeType was', + debugActiveLayout, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]); + } + + if (activeLayoutRoot == this) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('A $runtimeType was mutated in its own $culpritMethodName implementation.'), + ErrorDescription('A RenderObject must not re-dirty itself while still being laid out.'), + DiagnosticsProperty<RenderObject>( + 'The RenderObject being mutated was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + ErrorHint('Consider using the LayoutBuilder widget to dynamically change a subtree during layout.'), + ]); + } + + final ErrorSummary summary = ErrorSummary('A $runtimeType was mutated in $culpritFullMethodName.'); + final bool isMutatedByAncestor = activeLayoutRoot == debugActiveLayout; + final String description = isMutatedByAncestor + ? 'A RenderObject must not mutate its descendants in its $culpritMethodName method.' + : 'A RenderObject must not mutate another RenderObject from a different render subtree ' + 'in its $culpritMethodName method.'; + + throw FlutterError.fromParts(<DiagnosticsNode>[ + summary, + ErrorDescription(description), + DiagnosticsProperty<RenderObject>( + 'The RenderObject being mutated was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + DiagnosticsProperty<RenderObject>( + 'The ${isMutatedByAncestor ? 'ancestor ' : ''}RenderObject that was mutating the said $runtimeType was', + debugActiveLayout, + style: DiagnosticsTreeStyle.errorProperty, + ), + if (!isMutatedByAncestor) DiagnosticsProperty<RenderObject>( + 'Their common ancestor was', + activeLayoutRoot, + style: DiagnosticsTreeStyle.errorProperty, + ), + ErrorHint( + 'Mutating the layout of another RenderObject may cause some RenderObjects in its subtree to be laid out more than once. ' + 'Consider using the LayoutBuilder widget to dynamically mutate a subtree during layout.' + ), + ]); + }()); + return result; + } + + /// The [RenderObject] that's expected to call [layout] on this [RenderObject] + /// in its [performLayout] implementation. + /// + /// This method is used to implement an assert that ensures the render subtree + /// actively performing layout can not get accidentally mutated. It's only + /// implemented in debug mode and always returns null in release mode. + /// + /// The default implementation returns [parent] and overriding is rarely + /// needed. A [RenderObject] subclass that expects its + /// [RenderObject.performLayout] to be called from a different [RenderObject] + /// that's not its [parent] should override this property to return the actual + /// layout parent. + @protected + RenderObject? get debugLayoutParent { + RenderObject? layoutParent; + assert(() { + layoutParent = parent; + return true; + }()); + return layoutParent; + } + + /// The owner for this render object (null if unattached). + /// + /// The entire render tree that this render object belongs to + /// will have the same owner. + PipelineOwner? get owner => _owner; + PipelineOwner? _owner; + + /// Whether the render tree this render object belongs to is attached to a [PipelineOwner]. + /// + /// This becomes true during the call to [attach]. + /// + /// This becomes false during the call to [detach]. + bool get attached => _owner != null; + + /// Mark this render object as attached to the given owner. + /// + /// Typically called only from the [parent]'s [attach] method, and by the + /// [owner] to mark the root of a tree as attached. + /// + /// Subclasses with children should override this method to + /// [attach] all their children to the same [owner] + /// after calling the inherited method, as in `super.attach(owner)`. + @mustCallSuper + void attach(PipelineOwner owner) { + assert(!_debugDisposed); + assert(_owner == null); + _owner = owner; + // If the node was dirtied in some way while unattached, make sure to add + // it to the appropriate dirty list now that an owner is available + if (_needsLayout && _relayoutBoundary != null) { + // Don't enter this block if we've never laid out at all; + // scheduleInitialLayout() will handle it + _needsLayout = false; + markNeedsLayout(); + } + if (_needsCompositingBitsUpdate) { + _needsCompositingBitsUpdate = false; + markNeedsCompositingBitsUpdate(); + } + if (_needsPaint && _layerHandle.layer != null) { + // Don't enter this block if we've never painted at all; + // scheduleInitialPaint() will handle it + _needsPaint = false; + markNeedsPaint(); + } + if (_needsSemanticsUpdate && _semanticsConfiguration.isSemanticBoundary) { + // Don't enter this block if we've never updated semantics at all; + // scheduleInitialSemantics() will handle it + _needsSemanticsUpdate = false; + markNeedsSemanticsUpdate(); + } + } + + /// Mark this render object as detached from its [PipelineOwner]. + /// + /// Typically called only from the [parent]'s [detach], and by the [owner] to + /// mark the root of a tree as detached. + /// + /// Subclasses with children should override this method to + /// [detach] all their children after calling the inherited method, + /// as in `super.detach()`. + @mustCallSuper + void detach() { + assert(_owner != null); + _owner = null; + assert(parent == null || attached == parent!.attached); + } + + /// Whether this render object's layout information is dirty. + /// + /// This is only set in debug mode. In general, render objects should not need + /// to condition their runtime behavior on whether they are dirty or not, + /// since they should only be marked dirty immediately prior to being laid + /// out and painted. In release builds, this throws. + /// + /// It is intended to be used by tests and asserts. + bool get debugNeedsLayout { + late bool result; + assert(() { + result = _needsLayout; + return true; + }()); + return result; + } + bool _needsLayout = true; + + RenderObject? _relayoutBoundary; + + /// Whether [invokeLayoutCallback] for this render object is currently running. + bool get debugDoingThisLayoutWithCallback => _doingThisLayoutWithCallback; + bool _doingThisLayoutWithCallback = false; + + /// The layout constraints most recently supplied by the parent. + /// + /// If layout has not yet happened, accessing this getter will + /// throw a [StateError] exception. + @protected + Constraints get constraints { + if (_constraints == null) { + throw StateError('A RenderObject does not have any constraints before it has been laid out.'); + } + return _constraints!; + } + Constraints? _constraints; + + /// Verify that the object's constraints are being met. Override + /// this function in a subclass to verify that your state matches + /// the constraints object. This function is only called in checked + /// mode and only when needsLayout is false. If the constraints are + /// not met, it should assert or throw an exception. + @protected + void debugAssertDoesMeetConstraints(); + + /// When true, debugAssertDoesMeetConstraints() is currently + /// executing asserts for verifying the consistent behavior of + /// intrinsic dimensions methods. + /// + /// This should only be set by debugAssertDoesMeetConstraints() + /// implementations. It is used by tests to selectively ignore + /// custom layout callbacks. It should not be set outside of + /// debugAssertDoesMeetConstraints(), and should not be checked in + /// release mode (where it will always be false). + static bool debugCheckingIntrinsics = false; + bool _debugSubtreeRelayoutRootAlreadyMarkedNeedsLayout() { + if (_relayoutBoundary == null) { + // We don't know where our relayout boundary is yet. + return true; + } + RenderObject node = this; + while (node != _relayoutBoundary) { + assert(node._relayoutBoundary == _relayoutBoundary); + assert(node.parent != null); + node = node.parent!; + if ((!node._needsLayout) && (!node._debugDoingThisLayout)) { + return false; + } + } + assert(node._relayoutBoundary == node); + return true; + } + + /// Mark this render object's layout information as dirty, and either register + /// this object with its [PipelineOwner], or defer to the parent, depending on + /// whether this object is a relayout boundary or not respectively. + /// + /// ## Background + /// + /// Rather than eagerly updating layout information in response to writes into + /// a render object, we instead mark the layout information as dirty, which + /// schedules a visual update. As part of the visual update, the rendering + /// pipeline updates the render object's layout information. + /// + /// This mechanism batches the layout work so that multiple sequential writes + /// are coalesced, removing redundant computation. + /// + /// If a render object's parent indicates that it uses the size of one of its + /// render object children when computing its layout information, this + /// function, when called for the child, will also mark the parent as needing + /// layout. In that case, since both the parent and the child need to have + /// their layout recomputed, the pipeline owner is only notified about the + /// parent; when the parent is laid out, it will call the child's [layout] + /// method and thus the child will be laid out as well. + /// + /// Once [markNeedsLayout] has been called on a render object, + /// [debugNeedsLayout] returns true for that render object until just after + /// the pipeline owner has called [layout] on the render object. + /// + /// ## Special cases + /// + /// Some subclasses of [RenderObject], notably [RenderBox], have other + /// situations in which the parent needs to be notified if the child is + /// dirtied (e.g., if the child's intrinsic dimensions or baseline changes). + /// Such subclasses override markNeedsLayout and either call + /// `super.markNeedsLayout()`, in the normal case, or call + /// [markParentNeedsLayout], in the case where the parent needs to be laid out + /// as well as the child. + /// + /// If [sizedByParent] has changed, calls + /// [markNeedsLayoutForSizedByParentChange] instead of [markNeedsLayout]. + void markNeedsLayout() { + assert(_debugCanPerformMutations); + if (_needsLayout) { + assert(_debugSubtreeRelayoutRootAlreadyMarkedNeedsLayout()); + return; + } + if (_relayoutBoundary == null) { + _needsLayout = true; + if (parent != null) { + // _relayoutBoundary is cleaned by an ancestor in RenderObject.layout. + // Conservatively mark everything dirty until it reaches the closest + // known relayout boundary. + markParentNeedsLayout(); + } + return; + } + if (_relayoutBoundary != this) { + markParentNeedsLayout(); + } else { + _needsLayout = true; + if (owner != null) { + assert(() { + if (debugPrintMarkNeedsLayoutStacks) { + debugPrintStack(label: 'markNeedsLayout() called for $this'); + } + return true; + }()); + owner!._nodesNeedingLayout.add(this); + owner!.requestVisualUpdate(); + } + } + } + + /// Mark this render object's layout information as dirty, and then defer to + /// the parent. + /// + /// This function should only be called from [markNeedsLayout] or + /// [markNeedsLayoutForSizedByParentChange] implementations of subclasses that + /// introduce more reasons for deferring the handling of dirty layout to the + /// parent. See [markNeedsLayout] for details. + /// + /// Only call this if [parent] is not null. + @protected + void markParentNeedsLayout() { + assert(_debugCanPerformMutations); + _needsLayout = true; + assert(this.parent != null); + final RenderObject parent = this.parent!; + if (!_doingThisLayoutWithCallback) { + parent.markNeedsLayout(); + } else { + assert(parent._debugDoingThisLayout); + } + assert(parent == this.parent); + } + + /// Mark this render object's layout information as dirty (like + /// [markNeedsLayout]), and additionally also handle any necessary work to + /// handle the case where [sizedByParent] has changed value. + /// + /// This should be called whenever [sizedByParent] might have changed. + /// + /// Only call this if [parent] is not null. + void markNeedsLayoutForSizedByParentChange() { + markNeedsLayout(); + markParentNeedsLayout(); + } + + void _cleanRelayoutBoundary() { + if (_relayoutBoundary != this) { + _relayoutBoundary = null; + visitChildren(_cleanChildRelayoutBoundary); + } + } + + void _propagateRelayoutBoundary() { + if (_relayoutBoundary == this) { + return; + } + final RenderObject? parentRelayoutBoundary = parent?._relayoutBoundary; + assert(parentRelayoutBoundary != null); + if (parentRelayoutBoundary != _relayoutBoundary) { + _relayoutBoundary = parentRelayoutBoundary; + visitChildren(_propagateRelayoutBoundaryToChild); + } + } + + // Reduces closure allocation for visitChildren use cases. + static void _cleanChildRelayoutBoundary(RenderObject child) { + child._cleanRelayoutBoundary(); + } + + static void _propagateRelayoutBoundaryToChild(RenderObject child) { + child._propagateRelayoutBoundary(); + } + + /// Bootstrap the rendering pipeline by scheduling the very first layout. + /// + /// Requires this render object to be attached and that this render object + /// is the root of the render tree. + /// + /// See [RenderView] for an example of how this function is used. + void scheduleInitialLayout() { + assert(!_debugDisposed); + assert(attached); + assert(parent is! RenderObject); + assert(!owner!._debugDoingLayout); + assert(_relayoutBoundary == null); + _relayoutBoundary = this; + assert(() { + _debugCanParentUseSize = false; + return true; + }()); + owner!._nodesNeedingLayout.add(this); + } + + @pragma('vm:notify-debugger-on-exception') + void _layoutWithoutResize() { + assert(_relayoutBoundary == this); + RenderObject? debugPreviousActiveLayout; + assert(!_debugMutationsLocked); + assert(!_doingThisLayoutWithCallback); + assert(_debugCanParentUseSize != null); + assert(() { + _debugMutationsLocked = true; + _debugDoingThisLayout = true; + debugPreviousActiveLayout = _debugActiveLayout; + _debugActiveLayout = this; + if (debugPrintLayouts) { + debugPrint('Laying out (without resize) $this'); + } + return true; + }()); + try { + performLayout(); + markNeedsSemanticsUpdate(); + } catch (e, stack) { + _reportException('performLayout', e, stack); + } + assert(() { + _debugActiveLayout = debugPreviousActiveLayout; + _debugDoingThisLayout = false; + _debugMutationsLocked = false; + return true; + }()); + _needsLayout = false; + markNeedsPaint(); + } + + /// Compute the layout for this render object. + /// + /// This method is the main entry point for parents to ask their children to + /// update their layout information. The parent passes a constraints object, + /// which informs the child as to which layouts are permissible. The child is + /// required to obey the given constraints. + /// + /// If the parent reads information computed during the child's layout, the + /// parent must pass true for `parentUsesSize`. In that case, the parent will + /// be marked as needing layout whenever the child is marked as needing layout + /// because the parent's layout information depends on the child's layout + /// information. If the parent uses the default value (false) for + /// `parentUsesSize`, the child can change its layout information (subject to + /// the given constraints) without informing the parent. + /// + /// Subclasses should not override [layout] directly. Instead, they should + /// override [performResize] and/or [performLayout]. The [layout] method + /// delegates the actual work to [performResize] and [performLayout]. + /// + /// The parent's [performLayout] method should call the [layout] of all its + /// children unconditionally. It is the [layout] method's responsibility (as + /// implemented here) to return early if the child does not need to do any + /// work to update its layout information. + @pragma('vm:notify-debugger-on-exception') + void layout(Constraints constraints, { bool parentUsesSize = false }) { + assert(!_debugDisposed); + if (!kReleaseMode && debugProfileLayoutsEnabled) { + Map<String, String>? debugTimelineArguments; + assert(() { + if (debugEnhanceLayoutTimelineArguments) { + debugTimelineArguments = toDiagnosticsNode().toTimelineArguments(); + } + return true; + }()); + FlutterTimeline.startSync( + '$runtimeType', + arguments: debugTimelineArguments, + ); + } + assert(constraints.debugAssertIsValid( + isAppliedConstraint: true, + informationCollector: () { + final List<String> stack = StackTrace.current.toString().split('\n'); + int? targetFrame; + final Pattern layoutFramePattern = RegExp(r'^#[0-9]+ +Render(?:Object|Box).layout \('); + for (int i = 0; i < stack.length; i += 1) { + if (layoutFramePattern.matchAsPrefix(stack[i]) != null) { + targetFrame = i + 1; + } else if (targetFrame != null) { + break; + } + } + if (targetFrame != null && targetFrame < stack.length) { + final Pattern targetFramePattern = RegExp(r'^#[0-9]+ +(.+)$'); + final Match? targetFrameMatch = targetFramePattern.matchAsPrefix(stack[targetFrame]); + final String? problemFunction = (targetFrameMatch != null && targetFrameMatch.groupCount > 0) ? targetFrameMatch.group(1) : stack[targetFrame].trim(); + return <DiagnosticsNode>[ + ErrorDescription( + "These invalid constraints were provided to $runtimeType's layout() " + 'function by the following function, which probably computed the ' + 'invalid constraints in question:\n' + ' $problemFunction', + ), + ]; + } + return <DiagnosticsNode>[]; + }, + )); + assert(!_debugDoingThisResize); + assert(!_debugDoingThisLayout); + final bool isRelayoutBoundary = !parentUsesSize || sizedByParent || constraints.isTight || parent is! RenderObject; + final RenderObject relayoutBoundary = isRelayoutBoundary ? this : parent!._relayoutBoundary!; + assert(() { + _debugCanParentUseSize = parentUsesSize; + return true; + }()); + + if (!_needsLayout && constraints == _constraints) { + assert(() { + // in case parentUsesSize changed since the last invocation, set size + // to itself, so it has the right internal debug values. + _debugDoingThisResize = sizedByParent; + _debugDoingThisLayout = !sizedByParent; + final RenderObject? debugPreviousActiveLayout = _debugActiveLayout; + _debugActiveLayout = this; + debugResetSize(); + _debugActiveLayout = debugPreviousActiveLayout; + _debugDoingThisLayout = false; + _debugDoingThisResize = false; + return true; + }()); + + if (relayoutBoundary != _relayoutBoundary) { + _relayoutBoundary = relayoutBoundary; + visitChildren(_propagateRelayoutBoundaryToChild); + } + + if (!kReleaseMode && debugProfileLayoutsEnabled) { + FlutterTimeline.finishSync(); + } + return; + } + _constraints = constraints; + if (_relayoutBoundary != null && relayoutBoundary != _relayoutBoundary) { + // The local relayout boundary has changed, must notify children in case + // they also need updating. Otherwise, they will be confused about what + // their actual relayout boundary is later. + visitChildren(_cleanChildRelayoutBoundary); + } + _relayoutBoundary = relayoutBoundary; + assert(!_debugMutationsLocked); + assert(!_doingThisLayoutWithCallback); + assert(() { + _debugMutationsLocked = true; + if (debugPrintLayouts) { + debugPrint('Laying out (${sizedByParent ? "with separate resize" : "with resize allowed"}) $this'); + } + return true; + }()); + if (sizedByParent) { + assert(() { + _debugDoingThisResize = true; + return true; + }()); + try { + performResize(); + assert(() { + debugAssertDoesMeetConstraints(); + return true; + }()); + } catch (e, stack) { + _reportException('performResize', e, stack); + } + assert(() { + _debugDoingThisResize = false; + return true; + }()); + } + RenderObject? debugPreviousActiveLayout; + assert(() { + _debugDoingThisLayout = true; + debugPreviousActiveLayout = _debugActiveLayout; + _debugActiveLayout = this; + return true; + }()); + try { + performLayout(); + markNeedsSemanticsUpdate(); + assert(() { + debugAssertDoesMeetConstraints(); + return true; + }()); + } catch (e, stack) { + _reportException('performLayout', e, stack); + } + assert(() { + _debugActiveLayout = debugPreviousActiveLayout; + _debugDoingThisLayout = false; + _debugMutationsLocked = false; + return true; + }()); + _needsLayout = false; + markNeedsPaint(); + + if (!kReleaseMode && debugProfileLayoutsEnabled) { + FlutterTimeline.finishSync(); + } + } + + /// If a subclass has a "size" (the state controlled by `parentUsesSize`, + /// whatever it is in the subclass, e.g. the actual `size` property of + /// [RenderBox]), and the subclass verifies that in debug mode this "size" + /// property isn't used when [debugCanParentUseSize] isn't set, then that + /// subclass should override [debugResetSize] to reapply the current values of + /// [debugCanParentUseSize] to that state. + @protected + void debugResetSize() { } + + /// Whether the constraints are the only input to the sizing algorithm (in + /// particular, child nodes have no impact). + /// + /// Returning false is always correct, but returning true can be more + /// efficient when computing the size of this render object because we don't + /// need to recompute the size if the constraints don't change. + /// + /// Typically, subclasses will always return the same value. If the value can + /// change, then, when it does change, the subclass should make sure to call + /// [markNeedsLayoutForSizedByParentChange]. + /// + /// Subclasses that return true must not change the dimensions of this render + /// object in [performLayout]. Instead, that work should be done by + /// [performResize] or - for subclasses of [RenderBox] - in + /// [RenderBox.computeDryLayout]. + @protected + bool get sizedByParent => false; + + /// {@template flutter.rendering.RenderObject.performResize} + /// Updates the render objects size using only the constraints. + /// + /// Do not call this function directly: call [layout] instead. This function + /// is called by [layout] when there is actually work to be done by this + /// render object during layout. The layout constraints provided by your + /// parent are available via the [constraints] getter. + /// + /// This function is called only if [sizedByParent] is true. + /// {@endtemplate} + /// + /// Subclasses that set [sizedByParent] to true should override this method to + /// compute their size. Subclasses of [RenderBox] should consider overriding + /// [RenderBox.computeDryLayout] instead. + @protected + void performResize(); + + /// Do the work of computing the layout for this render object. + /// + /// Do not call this function directly: call [layout] instead. This function + /// is called by [layout] when there is actually work to be done by this + /// render object during layout. The layout constraints provided by your + /// parent are available via the [constraints] getter. + /// + /// If [sizedByParent] is true, then this function should not actually change + /// the dimensions of this render object. Instead, that work should be done by + /// [performResize]. If [sizedByParent] is false, then this function should + /// both change the dimensions of this render object and instruct its children + /// to layout. + /// + /// In implementing this function, you must call [layout] on each of your + /// children, passing true for parentUsesSize if your layout information is + /// dependent on your child's layout information. Passing true for + /// parentUsesSize ensures that this render object will undergo layout if the + /// child undergoes layout. Otherwise, the child can change its layout + /// information without informing this render object. + @protected + void performLayout(); + + /// Allows mutations to be made to this object's child list (and any + /// descendants) as well as to any other dirty nodes in the render tree owned + /// by the same [PipelineOwner] as this object. The `callback` argument is + /// invoked synchronously, and the mutations are allowed only during that + /// callback's execution. + /// + /// This exists to allow child lists to be built on-demand during layout (e.g. + /// based on the object's size), and to enable nodes to be moved around the + /// tree as this happens (e.g. to handle [GlobalKey] reparenting), while still + /// ensuring that any particular node is only laid out once per frame. + /// + /// Calling this function disables a number of assertions that are intended to + /// catch likely bugs. As such, using this function is generally discouraged. + /// + /// This function can only be called during layout. + @protected + void invokeLayoutCallback<T extends Constraints>(LayoutCallback<T> callback) { + assert(_debugMutationsLocked); + assert(_debugDoingThisLayout); + assert(!_doingThisLayoutWithCallback); + _doingThisLayoutWithCallback = true; + try { + owner!._enableMutationsToDirtySubtrees(() { callback(constraints as T); }); + } finally { + _doingThisLayoutWithCallback = false; + } + } + + // PAINTING + + /// Whether [paint] for this render object is currently running. + /// + /// Only valid when asserts are enabled. In release builds, always returns + /// false. + bool get debugDoingThisPaint => _debugDoingThisPaint; + bool _debugDoingThisPaint = false; + + /// The render object that is actively painting. + /// + /// Only valid when asserts are enabled. In release builds, always returns + /// null. + static RenderObject? get debugActivePaint => _debugActivePaint; + static RenderObject? _debugActivePaint; + + /// Whether this render object repaints separately from its parent. + /// + /// Override this in subclasses to indicate that instances of your class ought + /// to repaint independently. For example, render objects that repaint + /// frequently might want to repaint themselves without requiring their parent + /// to repaint. + /// + /// If this getter returns true, the [paintBounds] are applied to this object + /// and all descendants. The framework invokes [RenderObject.updateCompositedLayer] + /// to create an [OffsetLayer] and assigns it to the [layer] field. + /// Render objects that declare themselves as repaint boundaries must not replace + /// the layer created by the framework. + /// + /// If the value of this getter changes, [markNeedsCompositingBitsUpdate] must + /// be called. + /// + /// See [RepaintBoundary] for more information about how repaint boundaries function. + bool get isRepaintBoundary => false; + + /// Called, in debug mode, if [isRepaintBoundary] is true, when either the + /// this render object or its parent attempt to paint. + /// + /// This can be used to record metrics about whether the node should actually + /// be a repaint boundary. + void debugRegisterRepaintBoundaryPaint({ bool includedParent = true, bool includedChild = false }) { } + + /// Whether this render object always needs compositing. + /// + /// Override this in subclasses to indicate that your paint function always + /// creates at least one composited layer. For example, videos should return + /// true if they use hardware decoders. + /// + /// You must call [markNeedsCompositingBitsUpdate] if the value of this getter + /// changes. (This is implied when [adoptChild] or [dropChild] are called.) + @protected + bool get alwaysNeedsCompositing => false; + + late bool _wasRepaintBoundary; + + /// Update the composited layer owned by this render object. + /// + /// This method is called by the framework when [isRepaintBoundary] is true. + /// + /// If [oldLayer] is `null`, this method must return a new [OffsetLayer] + /// (or subtype thereof). If [oldLayer] is not `null`, then this method must + /// reuse the layer instance that is provided - it is an error to create a new + /// layer in this instance. The layer will be disposed by the framework when + /// either the render object is disposed or if it is no longer a repaint + /// boundary. + /// + /// The [OffsetLayer.offset] property will be managed by the framework and + /// must not be updated by this method. + /// + /// If a property of the composited layer needs to be updated, the render object + /// must call [markNeedsCompositedLayerUpdate] which will schedule this method + /// to be called without repainting children. If this widget was marked as + /// needing to paint and needing a composited layer update, this method is only + /// called once. + // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/102102 revisit the + // constraint that the instance/type of layer cannot be changed at runtime. + OffsetLayer updateCompositedLayer({required covariant OffsetLayer? oldLayer}) { + assert(isRepaintBoundary); + return oldLayer ?? OffsetLayer(); + } + + /// The compositing layer that this render object uses to repaint. + /// + /// If this render object is not a repaint boundary, it is the responsibility + /// of the [paint] method to populate this field. If [needsCompositing] is + /// true, this field may be populated with the root-most layer used by the + /// render object implementation. When repainting, instead of creating a new + /// layer the render object may update the layer stored in this field for better + /// performance. It is also OK to leave this field as null and create a new + /// layer on every repaint, but without the performance benefit. If + /// [needsCompositing] is false, this field must be set to null either by + /// never populating this field, or by setting it to null when the value of + /// [needsCompositing] changes from true to false. + /// + /// If a new layer is created and stored in some other field on the render + /// object, the render object must use a [LayerHandle] to store it. A layer + /// handle will prevent the layer from being disposed before the render + /// object is finished with it, and it will also make sure that the layer + /// gets appropriately disposed when the render object creates a replacement + /// or nulls it out. The render object must null out the [LayerHandle.layer] + /// in its [dispose] method. + /// + /// If this render object is a repaint boundary, the framework automatically + /// creates an [OffsetLayer] and populates this field prior to calling the + /// [paint] method. The [paint] method must not replace the value of this + /// field. + @protected + ContainerLayer? get layer { + assert(!isRepaintBoundary || _layerHandle.layer == null || _layerHandle.layer is OffsetLayer); + return _layerHandle.layer; + } + + @protected + set layer(ContainerLayer? newLayer) { + assert( + !isRepaintBoundary, + 'Attempted to set a layer to a repaint boundary render object.\n' + 'The framework creates and assigns an OffsetLayer to a repaint ' + 'boundary automatically.', + ); + _layerHandle.layer = newLayer; + } + + final LayerHandle<ContainerLayer> _layerHandle = LayerHandle<ContainerLayer>(); + + /// In debug mode, the compositing layer that this render object uses to repaint. + /// + /// This getter is intended for debugging purposes only. In release builds, it + /// always returns null. In debug builds, it returns the layer even if the layer + /// is dirty. + /// + /// For production code, consider [layer]. + ContainerLayer? get debugLayer { + ContainerLayer? result; + assert(() { + result = _layerHandle.layer; + return true; + }()); + return result; + } + + bool _needsCompositingBitsUpdate = false; // set to true when a child is added + /// Mark the compositing state for this render object as dirty. + /// + /// This is called to indicate that the value for [needsCompositing] needs to + /// be recomputed during the next [PipelineOwner.flushCompositingBits] engine + /// phase. + /// + /// When the subtree is mutated, we need to recompute our + /// [needsCompositing] bit, and some of our ancestors need to do the + /// same (in case ours changed in a way that will change theirs). To + /// this end, [adoptChild] and [dropChild] call this method, and, as + /// necessary, this method calls the parent's, etc, walking up the + /// tree to mark all the nodes that need updating. + /// + /// This method does not schedule a rendering frame, because since + /// it cannot be the case that _only_ the compositing bits changed, + /// something else will have scheduled a frame for us. + void markNeedsCompositingBitsUpdate() { + assert(!_debugDisposed); + if (_needsCompositingBitsUpdate) { + return; + } + _needsCompositingBitsUpdate = true; + if (parent is RenderObject) { + final RenderObject parent = this.parent!; + if (parent._needsCompositingBitsUpdate) { + return; + } + + if ((!_wasRepaintBoundary || !isRepaintBoundary) && !parent.isRepaintBoundary) { + parent.markNeedsCompositingBitsUpdate(); + return; + } + } + // parent is fine (or there isn't one), but we are dirty + if (owner != null) { + owner!._nodesNeedingCompositingBitsUpdate.add(this); + } + } + + late bool _needsCompositing; // initialized in the constructor + /// Whether we or one of our descendants has a compositing layer. + /// + /// If this node needs compositing as indicated by this bit, then all ancestor + /// nodes will also need compositing. + /// + /// Only legal to call after [PipelineOwner.flushLayout] and + /// [PipelineOwner.flushCompositingBits] have been called. + bool get needsCompositing { + assert(!_needsCompositingBitsUpdate); // make sure we don't use this bit when it is dirty + return _needsCompositing; + } + + void _updateCompositingBits() { + if (!_needsCompositingBitsUpdate) { + return; + } + final bool oldNeedsCompositing = _needsCompositing; + _needsCompositing = false; + visitChildren((RenderObject child) { + child._updateCompositingBits(); + if (child.needsCompositing) { + _needsCompositing = true; + } + }); + if (isRepaintBoundary || alwaysNeedsCompositing) { + _needsCompositing = true; + } + // If a node was previously a repaint boundary, but no longer is one, then + // regardless of its compositing state we need to find a new parent to + // paint from. To do this, we mark it clean again so that the traversal + // in markNeedsPaint is not short-circuited. It is removed from _nodesNeedingPaint + // so that we do not attempt to paint from it after locating a parent. + if (!isRepaintBoundary && _wasRepaintBoundary) { + _needsPaint = false; + _needsCompositedLayerUpdate = false; + owner?._nodesNeedingPaint.remove(this); + _needsCompositingBitsUpdate = false; + markNeedsPaint(); + } else if (oldNeedsCompositing != _needsCompositing) { + _needsCompositingBitsUpdate = false; + markNeedsPaint(); + } else { + _needsCompositingBitsUpdate = false; + } + } + + /// Whether this render object's paint information is dirty. + /// + /// This is only set in debug mode. In general, render objects should not need + /// to condition their runtime behavior on whether they are dirty or not, + /// since they should only be marked dirty immediately prior to being laid + /// out and painted. (In release builds, this throws.) + /// + /// It is intended to be used by tests and asserts. + /// + /// It is possible (and indeed, quite common) for [debugNeedsPaint] to be + /// false and [debugNeedsLayout] to be true. The render object will still be + /// repainted in the next frame when this is the case, because the + /// [markNeedsPaint] method is implicitly called by the framework after a + /// render object is laid out, prior to the paint phase. + bool get debugNeedsPaint { + late bool result; + assert(() { + result = _needsPaint; + return true; + }()); + return result; + } + bool _needsPaint = true; + + /// Whether this render object's layer information is dirty. + /// + /// This is only set in debug mode. In general, render objects should not need + /// to condition their runtime behavior on whether they are dirty or not, + /// since they should only be marked dirty immediately prior to being laid + /// out and painted. (In release builds, this throws.) + /// + /// It is intended to be used by tests and asserts. + bool get debugNeedsCompositedLayerUpdate { + late bool result; + assert(() { + result = _needsCompositedLayerUpdate; + return true; + }()); + return result; + } + bool _needsCompositedLayerUpdate = false; + + /// Mark this render object as having changed its visual appearance. + /// + /// Rather than eagerly updating this render object's display list + /// in response to writes, we instead mark the render object as needing to + /// paint, which schedules a visual update. As part of the visual update, the + /// rendering pipeline will give this render object an opportunity to update + /// its display list. + /// + /// This mechanism batches the painting work so that multiple sequential + /// writes are coalesced, removing redundant computation. + /// + /// Once [markNeedsPaint] has been called on a render object, + /// [debugNeedsPaint] returns true for that render object until just after + /// the pipeline owner has called [paint] on the render object. + /// + /// See also: + /// + /// * [RepaintBoundary], to scope a subtree of render objects to their own + /// layer, thus limiting the number of nodes that [markNeedsPaint] must mark + /// dirty. + void markNeedsPaint() { + assert(!_debugDisposed); + assert(owner == null || !owner!.debugDoingPaint); + if (_needsPaint) { + return; + } + _needsPaint = true; + // If this was not previously a repaint boundary it will not have + // a layer we can paint from. + if (isRepaintBoundary && _wasRepaintBoundary) { + assert(() { + if (debugPrintMarkNeedsPaintStacks) { + debugPrintStack(label: 'markNeedsPaint() called for $this'); + } + return true; + }()); + // If we always have our own layer, then we can just repaint + // ourselves without involving any other nodes. + assert(_layerHandle.layer is OffsetLayer); + if (owner != null) { + owner!._nodesNeedingPaint.add(this); + owner!.requestVisualUpdate(); + } + } else if (parent is RenderObject) { + parent!.markNeedsPaint(); + } else { + assert(() { + if (debugPrintMarkNeedsPaintStacks) { + debugPrintStack(label: 'markNeedsPaint() called for $this (root of render tree)'); + } + return true; + }()); + // If we are the root of the render tree and not a repaint boundary + // then we have to paint ourselves, since nobody else can paint us. + // We don't add ourselves to _nodesNeedingPaint in this case, + // because the root is always told to paint regardless. + // + // Trees rooted at a RenderView do not go through this + // code path because RenderViews are repaint boundaries. + if (owner != null) { + owner!.requestVisualUpdate(); + } + } + } + + /// Mark this render object as having changed a property on its composited + /// layer. + /// + /// Render objects that have a composited layer have [isRepaintBoundary] equal + /// to true may update the properties of that composited layer without repainting + /// their children. If this render object is a repaint boundary but does + /// not yet have a composited layer created for it, this method will instead + /// mark the nearest repaint boundary parent as needing to be painted. + /// + /// If this method is called on a render object that is not a repaint boundary + /// or is a repaint boundary but hasn't been composited yet, it is equivalent + /// to calling [markNeedsPaint]. + /// + /// See also: + /// + /// * [RenderOpacity], which uses this method when its opacity is updated to + /// update the layer opacity without repainting children. + void markNeedsCompositedLayerUpdate() { + assert(!_debugDisposed); + assert(owner == null || !owner!.debugDoingPaint); + if (_needsCompositedLayerUpdate || _needsPaint) { + return; + } + _needsCompositedLayerUpdate = true; + // If this was not previously a repaint boundary it will not have + // a layer we can paint from. + if (isRepaintBoundary && _wasRepaintBoundary) { + // If we always have our own layer, then we can just repaint + // ourselves without involving any other nodes. + assert(_layerHandle.layer != null); + if (owner != null) { + owner!._nodesNeedingPaint.add(this); + owner!.requestVisualUpdate(); + } + } else { + markNeedsPaint(); + } + } + + // Called when flushPaint() tries to make us paint but our layer is detached. + // To make sure that our subtree is repainted when it's finally reattached, + // even in the case where some ancestor layer is itself never marked dirty, we + // have to mark our entire detached subtree as dirty and needing to be + // repainted. That way, we'll eventually be repainted. + void _skippedPaintingOnLayer() { + assert(attached); + assert(isRepaintBoundary); + assert(_needsPaint || _needsCompositedLayerUpdate); + assert(_layerHandle.layer != null); + assert(!_layerHandle.layer!.attached); + RenderObject? node = parent; + while (node is RenderObject) { + if (node.isRepaintBoundary) { + if (node._layerHandle.layer == null) { + // Looks like the subtree here has never been painted. Let it handle itself. + break; + } + if (node._layerHandle.layer!.attached) { + // It's the one that detached us, so it's the one that will decide to repaint us. + break; + } + node._needsPaint = true; + } + node = node.parent; + } + } + + /// Bootstrap the rendering pipeline by scheduling the very first paint. + /// + /// Requires that this render object is attached, is the root of the render + /// tree, and has a composited layer. + /// + /// See [RenderView] for an example of how this function is used. + void scheduleInitialPaint(ContainerLayer rootLayer) { + assert(rootLayer.attached); + assert(attached); + assert(parent is! RenderObject); + assert(!owner!._debugDoingPaint); + assert(isRepaintBoundary); + assert(_layerHandle.layer == null); + _layerHandle.layer = rootLayer; + assert(_needsPaint); + owner!._nodesNeedingPaint.add(this); + } + + /// Replace the layer. This is only valid for the root of a render + /// object subtree (whatever object [scheduleInitialPaint] was + /// called on). + /// + /// This might be called if, e.g., the device pixel ratio changed. + void replaceRootLayer(OffsetLayer rootLayer) { + assert(!_debugDisposed); + assert(rootLayer.attached); + assert(attached); + assert(parent is! RenderObject); + assert(!owner!._debugDoingPaint); + assert(isRepaintBoundary); + assert(_layerHandle.layer != null); // use scheduleInitialPaint the first time + _layerHandle.layer!.detach(); + _layerHandle.layer = rootLayer; + markNeedsPaint(); + } + + void _paintWithContext(PaintingContext context, Offset offset) { + assert(!_debugDisposed); + assert(() { + if (_debugDoingThisPaint) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Tried to paint a RenderObject reentrantly.'), + describeForError( + 'The following RenderObject was already being painted when it was ' + 'painted again', + ), + ErrorDescription( + 'Since this typically indicates an infinite recursion, it is ' + 'disallowed.', + ), + ]); + } + return true; + }()); + // If we still need layout, then that means that we were skipped in the + // layout phase and therefore don't need painting. We might not know that + // yet (that is, our layer might not have been detached yet), because the + // same node that skipped us in layout is above us in the tree (obviously) + // and therefore may not have had a chance to paint yet (since the tree + // paints in reverse order). In particular this will happen if they have + // a different layer, because there's a repaint boundary between us. + if (_needsLayout) { + return; + } + if (!kReleaseMode && debugProfilePaintsEnabled) { + Map<String, String>? debugTimelineArguments; + assert(() { + if (debugEnhancePaintTimelineArguments) { + debugTimelineArguments = toDiagnosticsNode().toTimelineArguments(); + } + return true; + }()); + FlutterTimeline.startSync( + '$runtimeType', + arguments: debugTimelineArguments, + ); + } + assert(() { + if (_needsCompositingBitsUpdate) { + if (parent is RenderObject) { + final RenderObject parent = this.parent!; + bool visitedByParent = false; + parent.visitChildren((RenderObject child) { + if (child == this) { + visitedByParent = true; + } + }); + if (!visitedByParent) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + "A RenderObject was not visited by the parent's visitChildren " + 'during paint.', + ), + parent.describeForError( + 'The parent was', + ), + describeForError( + 'The child that was not visited was', + ), + ErrorDescription( + 'A RenderObject with children must implement visitChildren and ' + 'call the visitor exactly once for each child; it also should not ' + 'paint children that were removed with dropChild.', + ), + ErrorHint( + 'This usually indicates an error in the Flutter framework itself.', + ), + ]); + } + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'Tried to paint a RenderObject before its compositing bits were ' + 'updated.', + ), + describeForError( + 'The following RenderObject was marked as having dirty compositing ' + 'bits at the time that it was painted', + ), + ErrorDescription( + 'A RenderObject that still has dirty compositing bits cannot be ' + 'painted because this indicates that the tree has not yet been ' + 'properly configured for creating the layer tree.', + ), + ErrorHint( + 'This usually indicates an error in the Flutter framework itself.', + ), + ]); + } + return true; + }()); + RenderObject? debugLastActivePaint; + assert(() { + _debugDoingThisPaint = true; + debugLastActivePaint = _debugActivePaint; + _debugActivePaint = this; + assert(!isRepaintBoundary || _layerHandle.layer != null); + return true; + }()); + _needsPaint = false; + _needsCompositedLayerUpdate = false; + _wasRepaintBoundary = isRepaintBoundary; + try { + paint(context, offset); + assert(!_needsLayout); // check that the paint() method didn't mark us dirty again + assert(!_needsPaint); // check that the paint() method didn't mark us dirty again + } catch (e, stack) { + _reportException('paint', e, stack); + } + assert(() { + debugPaint(context, offset); + _debugActivePaint = debugLastActivePaint; + _debugDoingThisPaint = false; + return true; + }()); + if (!kReleaseMode && debugProfilePaintsEnabled) { + FlutterTimeline.finishSync(); + } + } + + /// An estimate of the bounds within which this render object will paint. + /// Useful for debugging flags such as [debugPaintLayerBordersEnabled]. + /// + /// These are also the bounds used by [showOnScreen] to make a [RenderObject] + /// visible on screen. + Rect get paintBounds; + + /// Override this method to paint debugging information. + void debugPaint(PaintingContext context, Offset offset) { } + + /// Paint this render object into the given context at the given offset. + /// + /// Subclasses should override this method to provide a visual appearance + /// for themselves. The render object's local coordinate system is + /// axis-aligned with the coordinate system of the context's canvas and the + /// render object's local origin (i.e, x=0 and y=0) is placed at the given + /// offset in the context's canvas. + /// + /// Do not call this function directly. If you wish to paint yourself, call + /// [markNeedsPaint] instead to schedule a call to this function. If you wish + /// to paint one of your children, call [PaintingContext.paintChild] on the + /// given `context`. + /// + /// When painting one of your children (via a paint child function on the + /// given context), the current canvas held by the context might change + /// because draw operations before and after painting children might need to + /// be recorded on separate compositing layers. + void paint(PaintingContext context, Offset offset) { } + + /// Applies the transform that would be applied when painting the given child + /// to the given matrix. + /// + /// Used by coordinate conversion functions to translate coordinates local to + /// one render object into coordinates local to another render object. + /// + /// Some RenderObjects will provide a zeroed out matrix in this method, + /// indicating that the child should not paint anything or respond to hit + /// tests currently. A parent may supply a non-zero matrix even though it + /// does not paint its child currently, for example if the parent is a + /// [RenderOffstage] with `offstage` set to true. In both of these cases, + /// the parent must return `false` from [paintsChild]. + void applyPaintTransform(covariant RenderObject child, Matrix4 transform) { + assert(child.parent == this); + } + + /// Whether the given child would be painted if [paint] were called. + /// + /// Some RenderObjects skip painting their children if they are configured to + /// not produce any visible effects. For example, a [RenderOffstage] with + /// its `offstage` property set to true, or a [RenderOpacity] with its opacity + /// value set to zero. + /// + /// In these cases, the parent may still supply a non-zero matrix in + /// [applyPaintTransform] to inform callers about where it would paint the + /// child if the child were painted at all. Alternatively, the parent may + /// supply a zeroed out matrix if it would not otherwise be able to determine + /// a valid matrix for the child and thus cannot meaningfully determine where + /// the child would paint. + bool paintsChild(covariant RenderObject child) { + assert(child.parent == this); + return true; + } + + /// {@template flutter.rendering.RenderObject.getTransformTo} + /// Applies the paint transform up the tree to `ancestor`. + /// + /// Returns a matrix that maps the local paint coordinate system to the + /// coordinate system of `ancestor`. + /// + /// If `ancestor` is null, this method returns a matrix that maps from the + /// local paint coordinate system to the coordinate system of the + /// [PipelineOwner.rootNode]. + /// {@endtemplate} + /// + /// For the render tree owned by the [RendererBinding] (i.e. for the main + /// render tree displayed on the device) this means that this method maps to + /// the global coordinate system in logical pixels. To get physical pixels, + /// use [applyPaintTransform] from the [RenderView] to further transform the + /// coordinate. + Matrix4 getTransformTo(RenderObject? ancestor) { + final bool ancestorSpecified = ancestor != null; + assert(attached); + if (ancestor == null) { + final RenderObject? rootNode = owner!.rootNode; + if (rootNode is RenderObject) { + ancestor = rootNode; + } + } + final List<RenderObject> renderers = <RenderObject>[]; + for (RenderObject renderer = this; renderer != ancestor; renderer = renderer.parent!) { + renderers.add(renderer); + assert(renderer.parent != null); // Failed to find ancestor in parent chain. + } + if (ancestorSpecified) { + renderers.add(ancestor!); + } + final Matrix4 transform = Matrix4.identity(); + for (int index = renderers.length - 1; index > 0; index -= 1) { + renderers[index].applyPaintTransform(renderers[index - 1], transform); + } + return transform; + } + + + /// Returns a rect in this object's coordinate system that describes + /// the approximate bounding box of the clip rect that would be + /// applied to the given child during the paint phase, if any. + /// + /// Returns null if the child would not be clipped. + /// + /// This is used in the semantics phase to avoid including children + /// that are not physically visible. + /// + /// RenderObjects that respect a [Clip] behavior when painting _must_ respect + /// that same behavior when describing this value. For example, if passing + /// [Clip.none] to [PaintingContext.pushClipRect] as the `clipBehavior`, then + /// the implementation of this method must return null. + Rect? describeApproximatePaintClip(covariant RenderObject child) => null; + + /// Returns a rect in this object's coordinate system that describes + /// which [SemanticsNode]s produced by the `child` should be included in the + /// semantics tree. [SemanticsNode]s from the `child` that are positioned + /// outside of this rect will be dropped. Child [SemanticsNode]s that are + /// positioned inside this rect, but outside of [describeApproximatePaintClip] + /// will be included in the tree marked as hidden. Child [SemanticsNode]s + /// that are inside of both rect will be included in the tree as regular + /// nodes. + /// + /// This method only returns a non-null value if the semantics clip rect + /// is different from the rect returned by [describeApproximatePaintClip]. + /// If the semantics clip rect and the paint clip rect are the same, this + /// method returns null. + /// + /// A viewport would typically implement this method to include semantic nodes + /// in the semantics tree that are currently hidden just before the leading + /// or just after the trailing edge. These nodes have to be included in the + /// semantics tree to implement implicit accessibility scrolling on iOS where + /// the viewport scrolls implicitly when moving the accessibility focus from + /// the last visible node in the viewport to the first hidden one. + /// + /// See also: + /// + /// * [RenderViewportBase.cacheExtent], used by viewports to extend their + /// semantics clip beyond their approximate paint clip. + Rect? describeSemanticsClip(covariant RenderObject? child) => null; + + // SEMANTICS + + /// Bootstrap the semantics reporting mechanism by marking this node + /// as needing a semantics update. + /// + /// Requires that this render object is attached, and is the root of + /// the render tree. + /// + /// See [RendererBinding] for an example of how this function is used. + void scheduleInitialSemantics() { + assert(!_debugDisposed); + assert(attached); + assert(parent is! RenderObject); + assert(!owner!._debugDoingSemantics); + assert(_semantics == null); + assert(_needsSemanticsUpdate); + assert(owner!._semanticsOwner != null); + owner!._nodesNeedingSemantics.add(this); + owner!.requestVisualUpdate(); + } + + /// Report the semantics of this node, for example for accessibility purposes. + /// + /// This method should be overridden by subclasses that have interesting + /// semantic information. + /// + /// The given [SemanticsConfiguration] object is mutable and should be + /// annotated in a manner that describes the current state. No reference + /// should be kept to that object; mutating it outside of the context of the + /// [describeSemanticsConfiguration] call (for example as a result of + /// asynchronous computation) will at best have no useful effect and at worse + /// will cause crashes as the data will be in an inconsistent state. + /// + /// {@tool snippet} + /// + /// The following snippet will describe the node as a button that responds to + /// tap actions. + /// + /// ```dart + /// abstract class SemanticButtonRenderObject extends RenderObject { + /// @override + /// void describeSemanticsConfiguration(SemanticsConfiguration config) { + /// super.describeSemanticsConfiguration(config); + /// config + /// ..onTap = _handleTap + /// ..label = 'I am a button' + /// ..isButton = true; + /// } + /// + /// void _handleTap() { + /// // Do something. + /// } + /// } + /// ``` + /// {@end-tool} + @protected + void describeSemanticsConfiguration(SemanticsConfiguration config) { + // Nothing to do by default. + } + + /// Sends a [SemanticsEvent] associated with this render object's [SemanticsNode]. + /// + /// If this render object has no semantics information, the first parent + /// render object with a non-null semantic node is used. + /// + /// If semantics are disabled, no events are dispatched. + /// + /// See [SemanticsNode.sendEvent] for a full description of the behavior. + void sendSemanticsEvent(SemanticsEvent semanticsEvent) { + if (owner!.semanticsOwner == null) { + return; + } + if (_semantics != null && !_semantics!.isMergedIntoParent) { + _semantics!.sendEvent(semanticsEvent); + } else if (parent != null) { + parent!.sendSemanticsEvent(semanticsEvent); + } + } + + // Use [_semanticsConfiguration] to access. + SemanticsConfiguration? _cachedSemanticsConfiguration; + + SemanticsConfiguration get _semanticsConfiguration { + if (_cachedSemanticsConfiguration == null) { + _cachedSemanticsConfiguration = SemanticsConfiguration(); + describeSemanticsConfiguration(_cachedSemanticsConfiguration!); + assert( + !_cachedSemanticsConfiguration!.explicitChildNodes || _cachedSemanticsConfiguration!.childConfigurationsDelegate == null, + 'A SemanticsConfiguration with explicitChildNode set to true cannot have a non-null childConfigsDelegate.', + ); + } + return _cachedSemanticsConfiguration!; + } + + /// The bounding box, in the local coordinate system, of this + /// object, for accessibility purposes. + Rect get semanticBounds; + + bool _needsSemanticsUpdate = true; + SemanticsNode? _semantics; + + /// The semantics of this render object. + /// + /// Exposed only for testing and debugging. To learn about the semantics of + /// render objects in production, obtain a [SemanticsHandle] from + /// [PipelineOwner.ensureSemantics]. + /// + /// Only valid in debug and profile mode. In release builds, always returns + /// null. + SemanticsNode? get debugSemantics { + if (!kReleaseMode) { + return _semantics; + } + return null; + } + + /// Removes all semantics from this render object and its descendants. + /// + /// Should only be called on objects whose [parent] is not a [RenderObject]. + /// + /// Override this method if you instantiate new [SemanticsNode]s in an + /// overridden [assembleSemanticsNode] method, to dispose of those nodes. + @mustCallSuper + void clearSemantics() { + _needsSemanticsUpdate = true; + _semantics = null; + visitChildren((RenderObject child) { + child.clearSemantics(); + }); + } + + /// Mark this node as needing an update to its semantics description. + /// + /// This must be called whenever the semantics configuration of this + /// [RenderObject] as annotated by [describeSemanticsConfiguration] changes in + /// any way to update the semantics tree. + void markNeedsSemanticsUpdate() { + assert(!_debugDisposed); + assert(!attached || !owner!._debugDoingSemantics); + if (!attached || owner!._semanticsOwner == null) { + _cachedSemanticsConfiguration = null; + return; + } + + // Dirty the semantics tree starting at `this` until we have reached a + // RenderObject that is a semantics boundary. All semantics past this + // RenderObject are still up-to date. Therefore, we will later only rebuild + // the semantics subtree starting at the identified semantics boundary. + + final bool wasSemanticsBoundary = _semantics != null && (_cachedSemanticsConfiguration?.isSemanticBoundary ?? false); + + bool mayProduceSiblingNodes = + _cachedSemanticsConfiguration?.childConfigurationsDelegate != null || + _semanticsConfiguration.childConfigurationsDelegate != null; + _cachedSemanticsConfiguration = null; + + bool isEffectiveSemanticsBoundary = _semanticsConfiguration.isSemanticBoundary && wasSemanticsBoundary; + RenderObject node = this; + + // The sibling nodes will be attached to the parent of immediate semantics + // node, thus marking this semantics boundary dirty is not enough, it needs + // to find the first parent semantics boundary that does not have any + // possible sibling node. + while (node.parent != null && (mayProduceSiblingNodes || !isEffectiveSemanticsBoundary)) { + if (node != this && node._needsSemanticsUpdate) { + break; + } + node._needsSemanticsUpdate = true; + // Since this node is a semantics boundary, the produced sibling nodes will + // be attached to the parent semantics boundary. Thus, these sibling nodes + // will not be carried to the next loop. + if (isEffectiveSemanticsBoundary) { + mayProduceSiblingNodes = false; + } + + node = node.parent!; + isEffectiveSemanticsBoundary = node._semanticsConfiguration.isSemanticBoundary; + if (isEffectiveSemanticsBoundary && node._semantics == null) { + // We have reached a semantics boundary that doesn't own a semantics node. + // That means the semantics of this branch are currently blocked and will + // not appear in the semantics tree. We can abort the walk here. + return; + } + } + if (node != this && _semantics != null && _needsSemanticsUpdate) { + // If `this` node has already been added to [owner._nodesNeedingSemantics] + // remove it as it is no longer guaranteed that its semantics + // node will continue to be in the tree. If it still is in the tree, the + // ancestor `node` added to [owner._nodesNeedingSemantics] at the end of + // this block will ensure that the semantics of `this` node actually gets + // updated. + // (See semantics_10_test.dart for an example why this is required). + owner!._nodesNeedingSemantics.remove(this); + } + if (!node._needsSemanticsUpdate) { + node._needsSemanticsUpdate = true; + if (owner != null) { + assert(node._semanticsConfiguration.isSemanticBoundary || node.parent == null); + owner!._nodesNeedingSemantics.add(node); + owner!.requestVisualUpdate(); + } + } + } + + /// Updates the semantic information of the render object. + void _updateSemantics() { + assert(_semanticsConfiguration.isSemanticBoundary || parent == null); + if (_needsLayout) { + // There's not enough information in this subtree to compute semantics. + // The subtree is probably being kept alive by a viewport but not laid out. + return; + } + if (!kReleaseMode) { + FlutterTimeline.startSync('Semantics.GetFragment'); + } + final _SemanticsFragment fragment = _getSemanticsForParent( + mergeIntoParent: _semantics?.parent?.isPartOfNodeMerging ?? false, + blockUserActions: _semantics?.areUserActionsBlocked ?? false, + ); + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + assert(fragment is _InterestingSemanticsFragment); + final _InterestingSemanticsFragment interestingFragment = fragment as _InterestingSemanticsFragment; + final List<SemanticsNode> result = <SemanticsNode>[]; + final List<SemanticsNode> siblingNodes = <SemanticsNode>[]; + + if (!kReleaseMode) { + FlutterTimeline.startSync('Semantics.compileChildren'); + } + interestingFragment.compileChildren( + parentSemanticsClipRect: _semantics?.parentSemanticsClipRect, + parentPaintClipRect: _semantics?.parentPaintClipRect, + elevationAdjustment: _semantics?.elevationAdjustment ?? 0.0, + result: result, + siblingNodes: siblingNodes, + ); + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + // Result may contain sibling nodes that are irrelevant for this update. + assert(interestingFragment.config == null && result.any((SemanticsNode node) => node == _semantics)); + } + + /// Returns the semantics that this node would like to add to its parent. + _SemanticsFragment _getSemanticsForParent({ + required bool mergeIntoParent, + required bool blockUserActions, + }) { + assert(!_needsLayout, 'Updated layout information required for $this to calculate semantics.'); + + final SemanticsConfiguration config = _semanticsConfiguration; + bool dropSemanticsOfPreviousSiblings = config.isBlockingSemanticsOfPreviouslyPaintedNodes; + bool producesForkingFragment = !config.hasBeenAnnotated && !config.isSemanticBoundary; + final bool blockChildInteractions = blockUserActions || config.isBlockingUserActions; + final bool childrenMergeIntoParent = mergeIntoParent || config.isMergingSemanticsOfDescendants; + final List<SemanticsConfiguration> childConfigurations = <SemanticsConfiguration>[]; + final bool explicitChildNode = config.explicitChildNodes || parent == null; + final ChildSemanticsConfigurationsDelegate? childConfigurationsDelegate = config.childConfigurationsDelegate; + final Map<SemanticsConfiguration, _InterestingSemanticsFragment> configToFragment = <SemanticsConfiguration, _InterestingSemanticsFragment>{}; + final List<_InterestingSemanticsFragment> mergeUpFragments = <_InterestingSemanticsFragment>[]; + final List<List<_InterestingSemanticsFragment>> siblingMergeFragmentGroups = <List<_InterestingSemanticsFragment>>[]; + final bool hasTags = config.tagsForChildren?.isNotEmpty ?? false; + visitChildrenForSemantics((RenderObject renderChild) { + assert(!_needsLayout); + final _SemanticsFragment parentFragment = renderChild._getSemanticsForParent( + mergeIntoParent: childrenMergeIntoParent, + blockUserActions: blockChildInteractions, + ); + if (parentFragment.dropsSemanticsOfPreviousSiblings) { + childConfigurations.clear(); + mergeUpFragments.clear(); + siblingMergeFragmentGroups.clear(); + if (!config.isSemanticBoundary) { + dropSemanticsOfPreviousSiblings = true; + } + } + for (final _InterestingSemanticsFragment fragment in parentFragment.mergeUpFragments) { + fragment.addAncestor(this); + if (hasTags) { + fragment.addTags(config.tagsForChildren!); + } + if (childConfigurationsDelegate != null && fragment.config != null) { + // This fragment need to go through delegate to determine whether it + // merge up or not. + childConfigurations.add(fragment.config!); + configToFragment[fragment.config!] = fragment; + } else { + mergeUpFragments.add(fragment); + } + } + if (parentFragment is _ContainerSemanticsFragment) { + // Container fragments needs to propagate sibling merge group to be + // compiled by _SwitchableSemanticsFragment. + for (final List<_InterestingSemanticsFragment> siblingMergeGroup in parentFragment.siblingMergeGroups) { + for (final _InterestingSemanticsFragment siblingMergingFragment in siblingMergeGroup) { + siblingMergingFragment.addAncestor(this); + if (hasTags) { + siblingMergingFragment.addTags(config.tagsForChildren!); + } + } + siblingMergeFragmentGroups.add(siblingMergeGroup); + } + } + }); + + assert(childConfigurationsDelegate != null || configToFragment.isEmpty); + + if (explicitChildNode) { + for (final _InterestingSemanticsFragment fragment in mergeUpFragments) { + fragment.markAsExplicit(); + } + } else if (childConfigurationsDelegate != null) { + final ChildSemanticsConfigurationsResult result = childConfigurationsDelegate(childConfigurations); + mergeUpFragments.addAll( + result.mergeUp.map<_InterestingSemanticsFragment>((SemanticsConfiguration config) { + final _InterestingSemanticsFragment? fragment = configToFragment[config]; + if (fragment == null) { + // Parent fragment of Incomplete fragments can't be a forking + // fragment since they need to be merged. + producesForkingFragment = false; + return _IncompleteSemanticsFragment(config: config, owner: this); + } + return fragment; + }), + ); + for (final Iterable<SemanticsConfiguration> group in result.siblingMergeGroups) { + siblingMergeFragmentGroups.add( + group.map<_InterestingSemanticsFragment>((SemanticsConfiguration config) { + return configToFragment[config] ?? _IncompleteSemanticsFragment(config: config, owner: this); + }).toList(), + ); + } + } + + _needsSemanticsUpdate = false; + + final _SemanticsFragment result; + if (parent == null) { + assert(!config.hasBeenAnnotated); + assert(!mergeIntoParent); + assert(siblingMergeFragmentGroups.isEmpty); + _marksExplicitInMergeGroup(mergeUpFragments, isMergeUp: true); + siblingMergeFragmentGroups.forEach(_marksExplicitInMergeGroup); + result = _RootSemanticsFragment( + owner: this, + dropsSemanticsOfPreviousSiblings: dropSemanticsOfPreviousSiblings, + ); + } else if (producesForkingFragment) { + result = _ContainerSemanticsFragment( + siblingMergeGroups: siblingMergeFragmentGroups, + dropsSemanticsOfPreviousSiblings: dropSemanticsOfPreviousSiblings, + ); + } else { + _marksExplicitInMergeGroup(mergeUpFragments, isMergeUp: true); + siblingMergeFragmentGroups.forEach(_marksExplicitInMergeGroup); + result = _SwitchableSemanticsFragment( + config: config, + blockUserActions: blockUserActions, + mergeIntoParent: mergeIntoParent, + siblingMergeGroups: siblingMergeFragmentGroups, + owner: this, + dropsSemanticsOfPreviousSiblings: dropSemanticsOfPreviousSiblings, + ); + if (config.isSemanticBoundary) { + final _SwitchableSemanticsFragment fragment = result as _SwitchableSemanticsFragment; + fragment.markAsExplicit(); + } + } + result.addAll(mergeUpFragments); + return result; + } + + void _marksExplicitInMergeGroup(List<_InterestingSemanticsFragment> mergeGroup, {bool isMergeUp = false}) { + final Set<_InterestingSemanticsFragment> toBeExplicit = <_InterestingSemanticsFragment>{}; + for (int i = 0; i < mergeGroup.length; i += 1) { + final _InterestingSemanticsFragment fragment = mergeGroup[i]; + if (!fragment.hasConfigForParent) { + continue; + } + if (isMergeUp && !_semanticsConfiguration.isCompatibleWith(fragment.config)) { + toBeExplicit.add(fragment); + } + final int siblingLength = i; + for (int j = 0; j < siblingLength; j += 1) { + final _InterestingSemanticsFragment siblingFragment = mergeGroup[j]; + if (!fragment.config!.isCompatibleWith(siblingFragment.config)) { + toBeExplicit.add(fragment); + toBeExplicit.add(siblingFragment); + } + } + } + for (final _InterestingSemanticsFragment fragment in toBeExplicit) { + fragment.markAsExplicit(); + } + } + + /// Called when collecting the semantics of this node. + /// + /// The implementation has to return the children in paint order skipping all + /// children that are not semantically relevant (e.g. because they are + /// invisible). + /// + /// The default implementation mirrors the behavior of + /// [visitChildren] (which is supposed to walk all the children). + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + visitChildren(visitor); + } + + /// Assemble the [SemanticsNode] for this [RenderObject]. + /// + /// If [describeSemanticsConfiguration] sets + /// [SemanticsConfiguration.isSemanticBoundary] to true, this method is called + /// with the `node` created for this [RenderObject], the `config` to be + /// applied to that node and the `children` [SemanticsNode]s that descendants + /// of this RenderObject have generated. + /// + /// By default, the method will annotate `node` with `config` and add the + /// `children` to it. + /// + /// Subclasses can override this method to add additional [SemanticsNode]s + /// to the tree. If new [SemanticsNode]s are instantiated in this method + /// they must be disposed in [clearSemantics]. + void assembleSemanticsNode( + SemanticsNode node, + SemanticsConfiguration config, + Iterable<SemanticsNode> children, + ) { + assert(node == _semantics); + // TODO(a14n): remove the following cast by updating type of parameter in either updateWith or assembleSemanticsNode + node.updateWith(config: config, childrenInInversePaintOrder: children as List<SemanticsNode>); + } + + // EVENTS + + /// Override this method to handle pointer events that hit this render object. + @override + void handleEvent(PointerEvent event, covariant HitTestEntry entry) { } + + + // HIT TESTING + + // RenderObject subclasses are expected to have a method like the following + // (with the signature being whatever passes for coordinates for this + // particular class): + // + // bool hitTest(HitTestResult result, { Offset position }) { + // // If the given position is not inside this node, then return false. + // // Otherwise: + // // For each child that intersects the position, in z-order starting from + // // the top, call hitTest() for that child, passing it /result/, and the + // // coordinates converted to the child's coordinate origin, and stop at + // // the first child that returns true. + // // Then, add yourself to /result/, and return true. + // } + // + // If you add yourself to /result/ and still return false, then that means you + // will see events but so will objects below you. + + + /// Returns a human understandable name. + @override + String toStringShort() { + String header = describeIdentity(this); + if (!kReleaseMode) { + if (_debugDisposed) { + header += ' DISPOSED'; + return header; + } + if (_relayoutBoundary != null && _relayoutBoundary != this) { + int count = 1; + RenderObject? target = parent; + while (target != null && target != _relayoutBoundary) { + target = target.parent; + count += 1; + } + header += ' relayoutBoundary=up$count'; + } + if (_needsLayout) { + header += ' NEEDS-LAYOUT'; + } + if (_needsPaint) { + header += ' NEEDS-PAINT'; + } + if (_needsCompositingBitsUpdate) { + header += ' NEEDS-COMPOSITING-BITS-UPDATE'; + } + if (!attached) { + header += ' DETACHED'; + } + } + return header; + } + + @override + String toString({ DiagnosticLevel minLevel = DiagnosticLevel.info }) => toStringShort(); + + /// Returns a description of the tree rooted at this node. + /// If the prefix argument is provided, then every line in the output + /// will be prefixed by that string. + @override + String toStringDeep({ + String prefixLineOne = '', + String? prefixOtherLines = '', + DiagnosticLevel minLevel = DiagnosticLevel.debug, + }) { + return _withDebugActiveLayoutCleared(() => super.toStringDeep( + prefixLineOne: prefixLineOne, + prefixOtherLines: prefixOtherLines, + minLevel: minLevel, + )); + } + + /// Returns a one-line detailed description of the render object. + /// This description is often somewhat long. + /// + /// This includes the same information for this RenderObject as given by + /// [toStringDeep], but does not recurse to any children. + @override + String toStringShallow({ + String joiner = ', ', + DiagnosticLevel minLevel = DiagnosticLevel.debug, + }) { + return _withDebugActiveLayoutCleared(() => super.toStringShallow(joiner: joiner, minLevel: minLevel)); + } + + @protected + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('needsCompositing', value: _needsCompositing, ifTrue: 'needs compositing')); + properties.add(DiagnosticsProperty<Object?>('creator', debugCreator, defaultValue: null, level: DiagnosticLevel.debug)); + properties.add(DiagnosticsProperty<ParentData>('parentData', parentData, tooltip: (_debugCanParentUseSize ?? false) ? 'can use size' : null, missingIfNull: true)); + properties.add(DiagnosticsProperty<Constraints>('constraints', _constraints, missingIfNull: true)); + // don't access it via the "layer" getter since that's only valid when we don't need paint + properties.add(DiagnosticsProperty<ContainerLayer>('layer', _layerHandle.layer, defaultValue: null)); + properties.add(DiagnosticsProperty<SemanticsNode>('semantics node', _semantics, defaultValue: null)); + properties.add(FlagProperty( + 'isBlockingSemanticsOfPreviouslyPaintedNodes', + value: _semanticsConfiguration.isBlockingSemanticsOfPreviouslyPaintedNodes, + ifTrue: 'blocks semantics of earlier render objects below the common boundary', + )); + properties.add(FlagProperty('isSemanticBoundary', value: _semanticsConfiguration.isSemanticBoundary, ifTrue: 'semantic boundary')); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() => <DiagnosticsNode>[]; + + /// Attempt to make (a portion of) this or a descendant [RenderObject] visible + /// on screen. + /// + /// If `descendant` is provided, that [RenderObject] is made visible. If + /// `descendant` is omitted, this [RenderObject] is made visible. + /// + /// The optional `rect` parameter describes which area of that [RenderObject] + /// should be shown on screen. If `rect` is null, the entire + /// [RenderObject] (as defined by its [paintBounds]) will be revealed. The + /// `rect` parameter is interpreted relative to the coordinate system of + /// `descendant` if that argument is provided and relative to this + /// [RenderObject] otherwise. + /// + /// The `duration` parameter can be set to a non-zero value to bring the + /// target object on screen in an animation defined by `curve`. + /// + /// See also: + /// + /// * [RenderViewportBase.showInViewport], which [RenderViewportBase] and + /// [SingleChildScrollView] delegate this method to. + void showOnScreen({ + RenderObject? descendant, + Rect? rect, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + }) { + if (parent is RenderObject) { + parent!.showOnScreen( + descendant: descendant ?? this, + rect: rect, + duration: duration, + curve: curve, + ); + } + } + + /// Adds a debug representation of a [RenderObject] optimized for including in + /// error messages. + /// + /// The default [style] of [DiagnosticsTreeStyle.shallow] ensures that all of + /// the properties of the render object are included in the error output but + /// none of the children of the object are. + /// + /// You should always include a RenderObject in an error message if it is the + /// [RenderObject] causing the failure or contract violation of the error. + DiagnosticsNode describeForError(String name, { DiagnosticsTreeStyle style = DiagnosticsTreeStyle.shallow }) { + return toDiagnosticsNode(name: name, style: style); + } +} + +/// Generic mixin for render objects with one child. +/// +/// Provides a child model for a render object subclass that has +/// a unique child, which is accessible via the [child] getter. +/// +/// This mixin is typically used to implement render objects created +/// in a [SingleChildRenderObjectWidget]. +mixin RenderObjectWithChildMixin<ChildType extends RenderObject> on RenderObject { + /// Checks whether the given render object has the correct [runtimeType] to be + /// a child of this render object. + /// + /// Does nothing if assertions are disabled. + /// + /// Always returns true. + bool debugValidateChild(RenderObject child) { + assert(() { + if (child is! ChildType) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'A $runtimeType expected a child of type $ChildType but received a ' + 'child of type ${child.runtimeType}.', + ), + ErrorDescription( + 'RenderObjects expect specific types of children because they ' + 'coordinate with their children during layout and paint. For ' + 'example, a RenderSliver cannot be the child of a RenderBox because ' + 'a RenderSliver does not understand the RenderBox layout protocol.', + ), + ErrorSpacer(), + DiagnosticsProperty<Object?>( + 'The $runtimeType that expected a $ChildType child was created by', + debugCreator, + style: DiagnosticsTreeStyle.errorProperty, + ), + ErrorSpacer(), + DiagnosticsProperty<Object?>( + 'The ${child.runtimeType} that did not match the expected child type ' + 'was created by', + child.debugCreator, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]); + } + return true; + }()); + return true; + } + + ChildType? _child; + /// The render object's unique child. + ChildType? get child => _child; + set child(ChildType? value) { + if (_child != null) { + dropChild(_child!); + } + _child = value; + if (_child != null) { + adoptChild(_child!); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _child?.attach(owner); + } + + @override + void detach() { + super.detach(); + _child?.detach(); + } + + @override + void redepthChildren() { + if (_child != null) { + redepthChild(_child!); + } + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + if (_child != null) { + visitor(_child!); + } + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return child != null ? <DiagnosticsNode>[child!.toDiagnosticsNode(name: 'child')] : <DiagnosticsNode>[]; + } +} + +/// Parent data to support a doubly-linked list of children. +/// +/// The children can be traversed using [nextSibling] or [previousSibling], +/// which can be called on the parent data of the render objects +/// obtained via [ContainerRenderObjectMixin.firstChild] or +/// [ContainerRenderObjectMixin.lastChild]. +mixin ContainerParentDataMixin<ChildType extends RenderObject> on ParentData { + /// The previous sibling in the parent's child list. + ChildType? previousSibling; + /// The next sibling in the parent's child list. + ChildType? nextSibling; + + /// Clear the sibling pointers. + @override + void detach() { + assert(previousSibling == null, 'Pointers to siblings must be nulled before detaching ParentData.'); + assert(nextSibling == null, 'Pointers to siblings must be nulled before detaching ParentData.'); + super.detach(); + } +} + +/// Generic mixin for render objects with a list of children. +/// +/// Provides a child model for a render object subclass that has a doubly-linked +/// list of children. +/// +/// The [ChildType] specifies the type of the children (extending [RenderObject]), +/// e.g. [RenderBox]. +/// +/// [ParentDataType] stores parent container data on its child render objects. +/// It must extend [ContainerParentDataMixin], which provides the interface +/// for visiting children. This data is populated by +/// [RenderObject.setupParentData] implemented by the class using this mixin. +/// +/// When using [RenderBox] as the child type, you will usually want to make use of +/// [RenderBoxContainerDefaultsMixin] and extend [ContainerBoxParentData] for the +/// parent data. +/// +/// Moreover, this is a required mixin for render objects returned to [MultiChildRenderObjectWidget]. +/// +/// See also: +/// +/// * [SlottedContainerRenderObjectMixin], which organizes its children +/// in different named slots. +mixin ContainerRenderObjectMixin<ChildType extends RenderObject, ParentDataType extends ContainerParentDataMixin<ChildType>> on RenderObject { + bool _debugUltimatePreviousSiblingOf(ChildType child, { ChildType? equals }) { + ParentDataType childParentData = child.parentData! as ParentDataType; + while (childParentData.previousSibling != null) { + assert(childParentData.previousSibling != child); + child = childParentData.previousSibling!; + childParentData = child.parentData! as ParentDataType; + } + return child == equals; + } + bool _debugUltimateNextSiblingOf(ChildType child, { ChildType? equals }) { + ParentDataType childParentData = child.parentData! as ParentDataType; + while (childParentData.nextSibling != null) { + assert(childParentData.nextSibling != child); + child = childParentData.nextSibling!; + childParentData = child.parentData! as ParentDataType; + } + return child == equals; + } + + int _childCount = 0; + /// The number of children. + int get childCount => _childCount; + + /// Checks whether the given render object has the correct [runtimeType] to be + /// a child of this render object. + /// + /// Does nothing if assertions are disabled. + /// + /// Always returns true. + bool debugValidateChild(RenderObject child) { + assert(() { + if (child is! ChildType) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'A $runtimeType expected a child of type $ChildType but received a ' + 'child of type ${child.runtimeType}.', + ), + ErrorDescription( + 'RenderObjects expect specific types of children because they ' + 'coordinate with their children during layout and paint. For ' + 'example, a RenderSliver cannot be the child of a RenderBox because ' + 'a RenderSliver does not understand the RenderBox layout protocol.', + ), + ErrorSpacer(), + DiagnosticsProperty<Object?>( + 'The $runtimeType that expected a $ChildType child was created by', + debugCreator, + style: DiagnosticsTreeStyle.errorProperty, + ), + ErrorSpacer(), + DiagnosticsProperty<Object?>( + 'The ${child.runtimeType} that did not match the expected child type ' + 'was created by', + child.debugCreator, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]); + } + return true; + }()); + return true; + } + + ChildType? _firstChild; + ChildType? _lastChild; + void _insertIntoChildList(ChildType child, { ChildType? after }) { + final ParentDataType childParentData = child.parentData! as ParentDataType; + assert(childParentData.nextSibling == null); + assert(childParentData.previousSibling == null); + _childCount += 1; + assert(_childCount > 0); + if (after == null) { + // insert at the start (_firstChild) + childParentData.nextSibling = _firstChild; + if (_firstChild != null) { + final ParentDataType firstChildParentData = _firstChild!.parentData! as ParentDataType; + firstChildParentData.previousSibling = child; + } + _firstChild = child; + _lastChild ??= child; + } else { + assert(_firstChild != null); + assert(_lastChild != null); + assert(_debugUltimatePreviousSiblingOf(after, equals: _firstChild)); + assert(_debugUltimateNextSiblingOf(after, equals: _lastChild)); + final ParentDataType afterParentData = after.parentData! as ParentDataType; + if (afterParentData.nextSibling == null) { + // insert at the end (_lastChild); we'll end up with two or more children + assert(after == _lastChild); + childParentData.previousSibling = after; + afterParentData.nextSibling = child; + _lastChild = child; + } else { + // insert in the middle; we'll end up with three or more children + // set up links from child to siblings + childParentData.nextSibling = afterParentData.nextSibling; + childParentData.previousSibling = after; + // set up links from siblings to child + final ParentDataType childPreviousSiblingParentData = childParentData.previousSibling!.parentData! as ParentDataType; + final ParentDataType childNextSiblingParentData = childParentData.nextSibling!.parentData! as ParentDataType; + childPreviousSiblingParentData.nextSibling = child; + childNextSiblingParentData.previousSibling = child; + assert(afterParentData.nextSibling == child); + } + } + } + + /// Insert child into this render object's child list after the given child. + /// + /// If `after` is null, then this inserts the child at the start of the list, + /// and the child becomes the new [firstChild]. + void insert(ChildType child, { ChildType? after }) { + assert(child != this, 'A RenderObject cannot be inserted into itself.'); + assert(after != this, 'A RenderObject cannot simultaneously be both the parent and the sibling of another RenderObject.'); + assert(child != after, 'A RenderObject cannot be inserted after itself.'); + assert(child != _firstChild); + assert(child != _lastChild); + adoptChild(child); + _insertIntoChildList(child, after: after); + } + + /// Append child to the end of this render object's child list. + void add(ChildType child) { + insert(child, after: _lastChild); + } + + /// Add all the children to the end of this render object's child list. + void addAll(List<ChildType>? children) { + children?.forEach(add); + } + + void _removeFromChildList(ChildType child) { + final ParentDataType childParentData = child.parentData! as ParentDataType; + assert(_debugUltimatePreviousSiblingOf(child, equals: _firstChild)); + assert(_debugUltimateNextSiblingOf(child, equals: _lastChild)); + assert(_childCount >= 0); + if (childParentData.previousSibling == null) { + assert(_firstChild == child); + _firstChild = childParentData.nextSibling; + } else { + final ParentDataType childPreviousSiblingParentData = childParentData.previousSibling!.parentData! as ParentDataType; + childPreviousSiblingParentData.nextSibling = childParentData.nextSibling; + } + if (childParentData.nextSibling == null) { + assert(_lastChild == child); + _lastChild = childParentData.previousSibling; + } else { + final ParentDataType childNextSiblingParentData = childParentData.nextSibling!.parentData! as ParentDataType; + childNextSiblingParentData.previousSibling = childParentData.previousSibling; + } + childParentData.previousSibling = null; + childParentData.nextSibling = null; + _childCount -= 1; + } + + /// Remove this child from the child list. + /// + /// Requires the child to be present in the child list. + void remove(ChildType child) { + _removeFromChildList(child); + dropChild(child); + } + + /// Remove all their children from this render object's child list. + /// + /// More efficient than removing them individually. + void removeAll() { + ChildType? child = _firstChild; + while (child != null) { + final ParentDataType childParentData = child.parentData! as ParentDataType; + final ChildType? next = childParentData.nextSibling; + childParentData.previousSibling = null; + childParentData.nextSibling = null; + dropChild(child); + child = next; + } + _firstChild = null; + _lastChild = null; + _childCount = 0; + } + + /// Move the given `child` in the child list to be after another child. + /// + /// More efficient than removing and re-adding the child. Requires the child + /// to already be in the child list at some position. Pass null for `after` to + /// move the child to the start of the child list. + void move(ChildType child, { ChildType? after }) { + assert(child != this); + assert(after != this); + assert(child != after); + assert(child.parent == this); + final ParentDataType childParentData = child.parentData! as ParentDataType; + if (childParentData.previousSibling == after) { + return; + } + _removeFromChildList(child); + _insertIntoChildList(child, after: after); + markNeedsLayout(); + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + ChildType? child = _firstChild; + while (child != null) { + child.attach(owner); + final ParentDataType childParentData = child.parentData! as ParentDataType; + child = childParentData.nextSibling; + } + } + + @override + void detach() { + super.detach(); + ChildType? child = _firstChild; + while (child != null) { + child.detach(); + final ParentDataType childParentData = child.parentData! as ParentDataType; + child = childParentData.nextSibling; + } + } + + @override + void redepthChildren() { + ChildType? child = _firstChild; + while (child != null) { + redepthChild(child); + final ParentDataType childParentData = child.parentData! as ParentDataType; + child = childParentData.nextSibling; + } + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + ChildType? child = _firstChild; + while (child != null) { + visitor(child); + final ParentDataType childParentData = child.parentData! as ParentDataType; + child = childParentData.nextSibling; + } + } + + /// The first child in the child list. + ChildType? get firstChild => _firstChild; + + /// The last child in the child list. + ChildType? get lastChild => _lastChild; + + /// The previous child before the given child in the child list. + ChildType? childBefore(ChildType child) { + assert(child.parent == this); + final ParentDataType childParentData = child.parentData! as ParentDataType; + return childParentData.previousSibling; + } + + /// The next child after the given child in the child list. + ChildType? childAfter(ChildType child) { + assert(child.parent == this); + final ParentDataType childParentData = child.parentData! as ParentDataType; + return childParentData.nextSibling; + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<DiagnosticsNode> children = <DiagnosticsNode>[]; + if (firstChild != null) { + ChildType child = firstChild!; + int count = 1; + while (true) { + children.add(child.toDiagnosticsNode(name: 'child $count')); + if (child == lastChild) { + break; + } + count += 1; + final ParentDataType childParentData = child.parentData! as ParentDataType; + child = childParentData.nextSibling!; + } + } + return children; + } +} + +/// Mixin for [RenderObject] that will call [systemFontsDidChange] whenever the +/// system fonts change. +/// +/// System fonts can change when the OS installs or removes a font. Use this +/// mixin if the [RenderObject] uses [TextPainter] or [Paragraph] to correctly +/// update the text when it happens. +mixin RelayoutWhenSystemFontsChangeMixin on RenderObject { + + /// A callback that is called when system fonts have changed. + /// + /// The framework defers the invocation of the callback to the + /// [SchedulerPhase.transientCallbacks] phase to ensure that the + /// [RenderObject]'s text layout is still valid when user interactions are in + /// progress (which usually take place during the [SchedulerPhase.idle] phase). + /// + /// By default, [markNeedsLayout] is called on the [RenderObject] + /// implementing this mixin. + /// + /// Subclass should override this method to clear any extra cache that depend + /// on font-related metrics. + @protected + @mustCallSuper + void systemFontsDidChange() { + markNeedsLayout(); + } + + bool _hasPendingSystemFontsDidChangeCallBack = false; + void _scheduleSystemFontsUpdate() { + assert( + SchedulerBinding.instance.schedulerPhase == SchedulerPhase.idle, + '${objectRuntimeType(this, "RelayoutWhenSystemFontsChangeMixin")}._scheduleSystemFontsUpdate() ' + 'called during ${SchedulerBinding.instance.schedulerPhase}.', + ); + if (_hasPendingSystemFontsDidChangeCallBack) { + return; + } + _hasPendingSystemFontsDidChangeCallBack = true; + SchedulerBinding.instance.scheduleFrameCallback((Duration timeStamp) { + assert(_hasPendingSystemFontsDidChangeCallBack); + _hasPendingSystemFontsDidChangeCallBack = false; + assert( + attached || (debugDisposed ?? true), + '$this is detached during ${SchedulerBinding.instance.schedulerPhase} but is not disposed.', + ); + if (attached) { + systemFontsDidChange(); + } + }); + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + // If there's a pending callback that would imply this node was detached + // between the idle phase and the next transientCallbacks phase. The tree + // can not be mutated between those two phases so that should never happen. + assert(!_hasPendingSystemFontsDidChangeCallBack); + PaintingBinding.instance.systemFonts.addListener(_scheduleSystemFontsUpdate); + } + + @override + void detach() { + assert(!_hasPendingSystemFontsDidChangeCallBack); + PaintingBinding.instance.systemFonts.removeListener(_scheduleSystemFontsUpdate); + super.detach(); + } +} + +/// Describes the semantics information a [RenderObject] wants to add to its +/// parent. +/// +/// It has two notable subclasses: +/// * [_InterestingSemanticsFragment] describing actual semantic information to +/// be added to the parent. +/// * [_ContainerSemanticsFragment]: a container class to transport the semantic +/// information of multiple [_InterestingSemanticsFragment] to a parent. +abstract class _SemanticsFragment { + _SemanticsFragment({ + required this.dropsSemanticsOfPreviousSiblings, + }); + + /// Incorporate the fragments of children into this fragment. + void addAll(Iterable<_InterestingSemanticsFragment> fragments); + + /// Whether this fragment wants to make the semantics information of + /// previously painted [RenderObject]s unreachable for accessibility purposes. + /// + /// See also: + /// + /// * [SemanticsConfiguration.isBlockingSemanticsOfPreviouslyPaintedNodes] + /// describes what semantics are dropped in more detail. + final bool dropsSemanticsOfPreviousSiblings; + + /// Returns [_InterestingSemanticsFragment] describing the actual semantic + /// information that this fragment wants to add to the parent. + List<_InterestingSemanticsFragment> get mergeUpFragments; +} + +/// A container used when a [RenderObject] wants to add multiple independent +/// [_InterestingSemanticsFragment] to its parent. +/// +/// The [_InterestingSemanticsFragment] to be added to the parent can be +/// obtained via [mergeUpFragments]. +class _ContainerSemanticsFragment extends _SemanticsFragment { + _ContainerSemanticsFragment({ + required super.dropsSemanticsOfPreviousSiblings, + required this.siblingMergeGroups, + }); + + final List<List<_InterestingSemanticsFragment>> siblingMergeGroups; + + @override + void addAll(Iterable<_InterestingSemanticsFragment> fragments) { + mergeUpFragments.addAll(fragments); + } + + @override + final List<_InterestingSemanticsFragment> mergeUpFragments = <_InterestingSemanticsFragment>[]; +} + +/// A [_SemanticsFragment] that describes which concrete semantic information +/// a [RenderObject] wants to add to the [SemanticsNode] of its parent. +/// +/// Specifically, it describes which children (as returned by [compileChildren]) +/// should be added to the parent's [SemanticsNode] and which [config] should be +/// merged into the parent's [SemanticsNode]. +abstract class _InterestingSemanticsFragment extends _SemanticsFragment { + _InterestingSemanticsFragment({ + required RenderObject owner, + required super.dropsSemanticsOfPreviousSiblings, + }) : _ancestorChain = <RenderObject>[owner]; + + /// The [RenderObject] that owns this fragment (and any new [SemanticsNode] + /// introduced by it). + RenderObject get owner => _ancestorChain.first; + + final List<RenderObject> _ancestorChain; + + /// The children to be added to the parent. + /// + /// See also: + /// + /// * [SemanticsNode.parentSemanticsClipRect] for the source and definition + /// of the `parentSemanticsClipRect` argument. + /// * [SemanticsNode.parentPaintClipRect] for the source and definition + /// of the `parentPaintClipRect` argument. + /// * [SemanticsNode.elevationAdjustment] for the source and definition + /// of the `elevationAdjustment` argument. + void compileChildren({ + required Rect? parentSemanticsClipRect, + required Rect? parentPaintClipRect, + required double elevationAdjustment, + required List<SemanticsNode> result, + required List<SemanticsNode> siblingNodes, + }); + + /// The [SemanticsConfiguration] the child wants to merge into the parent's + /// [SemanticsNode] or null if it doesn't want to merge anything. + SemanticsConfiguration? get config; + + /// Disallows this fragment to merge any configuration into its parent's + /// [SemanticsNode]. + /// + /// After calling this, the fragment will only produce children to be added + /// to the parent and it will return null for [config]. + void markAsExplicit(); + + /// Consume the fragments of children. + /// + /// For each provided fragment it will add that fragment's children to + /// this fragment's children (as returned by [compileChildren]) and merge that + /// fragment's [config] into this fragment's [config]. + /// + /// If a provided fragment should not merge anything into [config] call + /// [markAsExplicit] before passing the fragment to this method. + @override + void addAll(Iterable<_InterestingSemanticsFragment> fragments); + + /// Whether this fragment wants to add any semantic information to the parent + /// [SemanticsNode]. + bool get hasConfigForParent => config != null; + + @override + List<_InterestingSemanticsFragment> get mergeUpFragments => <_InterestingSemanticsFragment>[this]; + + Set<SemanticsTag>? _tagsForChildren; + + /// Tag all children produced by [compileChildren] with `tags`. + /// + /// `tags` must not be empty. + void addTags(Iterable<SemanticsTag> tags) { + assert(tags.isNotEmpty); + _tagsForChildren ??= <SemanticsTag>{}; + _tagsForChildren!.addAll(tags); + } + + /// Adds the geometric information of `ancestor` to this object. + /// + /// Those information are required to properly compute the value for + /// [SemanticsNode.transform], [SemanticsNode.clipRect], and + /// [SemanticsNode.rect]. + /// + /// Ancestors have to be added in order from [owner] up until the next + /// [RenderObject] that owns a [SemanticsNode] is reached. + void addAncestor(RenderObject ancestor) { + _ancestorChain.add(ancestor); + } +} + +/// An [_InterestingSemanticsFragment] that produces the root [SemanticsNode] of +/// the semantics tree. +/// +/// The root node is available as the only element in the Iterable returned by +/// [children]. +class _RootSemanticsFragment extends _InterestingSemanticsFragment { + _RootSemanticsFragment({ + required super.owner, + required super.dropsSemanticsOfPreviousSiblings, + }); + + @override + void compileChildren({ + Rect? parentSemanticsClipRect, + Rect? parentPaintClipRect, + required double elevationAdjustment, + required List<SemanticsNode> result, + required List<SemanticsNode> siblingNodes, + }) { + assert(_tagsForChildren == null || _tagsForChildren!.isEmpty); + assert(parentSemanticsClipRect == null); + assert(parentPaintClipRect == null); + assert(_ancestorChain.length == 1); + assert(elevationAdjustment == 0.0); + + owner._semantics ??= SemanticsNode.root( + showOnScreen: owner.showOnScreen, + owner: owner.owner!.semanticsOwner!, + ); + final SemanticsNode node = owner._semantics!; + assert(MatrixUtils.matrixEquals(node.transform, Matrix4.identity())); + assert(node.parentSemanticsClipRect == null); + assert(node.parentPaintClipRect == null); + + node.rect = owner.semanticBounds; + + final List<SemanticsNode> children = <SemanticsNode>[]; + for (final _InterestingSemanticsFragment fragment in _children) { + assert(fragment.config == null); + fragment.compileChildren( + parentSemanticsClipRect: parentSemanticsClipRect, + parentPaintClipRect: parentPaintClipRect, + elevationAdjustment: 0.0, + result: children, + siblingNodes: siblingNodes, + ); + } + // Root node does not have a parent and thus can't attach sibling nodes. + assert(siblingNodes.isEmpty); + node.updateWith(config: null, childrenInInversePaintOrder: children); + + // The root node is the only semantics node allowed to be invisible. This + // can happen when the canvas the app is drawn on has a size of 0 by 0 + // pixel. If this happens, the root node must not have any children (because + // these would be invisible as well and are therefore excluded from the + // tree). + assert(!node.isInvisible || children.isEmpty); + result.add(node); + } + + @override + SemanticsConfiguration? get config => null; + + final List<_InterestingSemanticsFragment> _children = <_InterestingSemanticsFragment>[]; + + @override + void markAsExplicit() { + // nothing to do, we are always explicit. + } + + @override + void addAll(Iterable<_InterestingSemanticsFragment> fragments) { + _children.addAll(fragments); + } +} + +/// A fragment with partial information that must not form an explicit +/// semantics node without merging into another _SwitchableSemanticsFragment. +/// +/// This fragment is generated from synthetic SemanticsConfiguration returned from +/// [SemanticsConfiguration.childConfigurationsDelegate]. +class _IncompleteSemanticsFragment extends _InterestingSemanticsFragment { + _IncompleteSemanticsFragment({ + required this.config, + required super.owner, + }) : super(dropsSemanticsOfPreviousSiblings: false); + + @override + void addAll(Iterable<_InterestingSemanticsFragment> fragments) { + assert(false, 'This fragment must be a leaf node'); + } + + @override + void compileChildren({ + required Rect? parentSemanticsClipRect, + required Rect? parentPaintClipRect, + required double elevationAdjustment, + required List<SemanticsNode> result, + required List<SemanticsNode> siblingNodes, + }) { + // There is nothing to do because this fragment must be a leaf node and + // must not be explicit. + } + + @override + final SemanticsConfiguration config; + + @override + void markAsExplicit() { + assert( + false, + 'SemanticsConfiguration created in ' + 'SemanticsConfiguration.childConfigurationsDelegate must not produce ' + 'its own semantics node' + ); + } +} + +/// An [_InterestingSemanticsFragment] that can be told to only add explicit +/// [SemanticsNode]s to the parent. +/// +/// If [markAsExplicit] was not called before this fragment is added to +/// another fragment it will merge [config] into the parent's [SemanticsNode] +/// and add its [children] to it. +/// +/// If [markAsExplicit] was called before adding this fragment to another +/// fragment it will create a new [SemanticsNode]. The newly created node will +/// be annotated with the [SemanticsConfiguration] that - without the call to +/// [markAsExplicit] - would have been merged into the parent's [SemanticsNode]. +/// Similarly, the new node will also take over the children that otherwise +/// would have been added to the parent's [SemanticsNode]. +/// +/// After a call to [markAsExplicit] the only element returned by [children] +/// is the newly created node and [config] will return null as the fragment +/// no longer wants to merge any semantic information into the parent's +/// [SemanticsNode]. +class _SwitchableSemanticsFragment extends _InterestingSemanticsFragment { + _SwitchableSemanticsFragment({ + required bool mergeIntoParent, + required bool blockUserActions, + required SemanticsConfiguration config, + required List<List<_InterestingSemanticsFragment>> siblingMergeGroups, + required super.owner, + required super.dropsSemanticsOfPreviousSiblings, + }) : _siblingMergeGroups = siblingMergeGroups, + _mergeIntoParent = mergeIntoParent, + _config = config { + if (blockUserActions && !_config.isBlockingUserActions) { + _ensureConfigIsWritable(); + _config.isBlockingUserActions = true; + } + } + + final bool _mergeIntoParent; + SemanticsConfiguration _config; + bool _isConfigWritable = false; + bool _mergesToSibling = false; + + final List<List<_InterestingSemanticsFragment>> _siblingMergeGroups; + + void _mergeSiblingGroup(Rect? parentSemanticsClipRect, Rect? parentPaintClipRect, List<SemanticsNode> result, Set<int> usedSemanticsIds) { + for (final List<_InterestingSemanticsFragment> group in _siblingMergeGroups) { + Rect? rect; + Rect? semanticsClipRect; + Rect? paintClipRect; + SemanticsConfiguration? configuration; + // Use empty set because the _tagsForChildren may not contains all of the + // tags if this fragment is not explicit. The _tagsForChildren are added + // to sibling nodes at the end of compileChildren if this fragment is + // explicit. + final Set<SemanticsTag> tags = <SemanticsTag>{}; + SemanticsNode? node; + for (final _InterestingSemanticsFragment fragment in group) { + if (fragment.config != null) { + final _SwitchableSemanticsFragment switchableFragment = fragment as _SwitchableSemanticsFragment; + switchableFragment._mergesToSibling = true; + node ??= fragment.owner._semantics; + configuration ??= SemanticsConfiguration(); + configuration.absorb(switchableFragment.config!); + // It is a child fragment of a _SwitchableFragment, it must have a + // geometry. + final _SemanticsGeometry geometry = switchableFragment._computeSemanticsGeometry( + parentSemanticsClipRect: parentSemanticsClipRect, + parentPaintClipRect: parentPaintClipRect, + )!; + final Rect fragmentRect = MatrixUtils.transformRect(geometry.transform, geometry.rect); + rect = rect?.expandToInclude(fragmentRect) ?? fragmentRect; + if (geometry.semanticsClipRect != null) { + final Rect rect = MatrixUtils.transformRect(geometry.transform, geometry.semanticsClipRect!); + semanticsClipRect = semanticsClipRect?.intersect(rect) ?? rect; + } + if (geometry.paintClipRect != null) { + final Rect rect = MatrixUtils.transformRect(geometry.transform, geometry.paintClipRect!); + paintClipRect = paintClipRect?.intersect(rect) ?? rect; + } + if (switchableFragment._tagsForChildren != null) { + tags.addAll(switchableFragment._tagsForChildren!); + } + } + } + // Can be null if all fragments in group are marked as explicit. + if (configuration != null && !rect!.isEmpty) { + if (node == null || usedSemanticsIds.contains(node.id)) { + node = SemanticsNode(showOnScreen: owner.showOnScreen); + } + usedSemanticsIds.add(node.id); + node + ..tags = tags + ..rect = rect + ..transform = null // Will be set when compiling immediate parent node. + ..parentSemanticsClipRect = semanticsClipRect + ..parentPaintClipRect = paintClipRect; + for (final _InterestingSemanticsFragment fragment in group) { + if (fragment.config != null) { + fragment.owner._semantics = node; + } + } + node.updateWith(config: configuration); + result.add(node); + } + } + } + + final List<_InterestingSemanticsFragment> _children = <_InterestingSemanticsFragment>[]; + + @override + void compileChildren({ + Rect? parentSemanticsClipRect, + Rect? parentPaintClipRect, + required double elevationAdjustment, + required List<SemanticsNode> result, + required List<SemanticsNode> siblingNodes, + }) { + final Set<int> usedSemanticsIds = <int>{}; + Iterable<_InterestingSemanticsFragment> compilingFragments = _children; + for (final List<_InterestingSemanticsFragment> siblingGroup in _siblingMergeGroups) { + compilingFragments = compilingFragments.followedBy(siblingGroup); + } + if (!_isExplicit) { + if (!_mergesToSibling) { + owner._semantics = null; + } + _mergeSiblingGroup( + parentSemanticsClipRect, + parentPaintClipRect, + siblingNodes, + usedSemanticsIds, + ); + for (final _InterestingSemanticsFragment fragment in compilingFragments) { + assert(_ancestorChain.first == fragment._ancestorChain.last); + if (fragment is _SwitchableSemanticsFragment) { + // Cached semantics node may be part of sibling merging group prior + // to this update. In this case, the semantics node may continue to + // be reused in that sibling merging group. + if (fragment._isExplicit && + fragment.owner._semantics != null && + usedSemanticsIds.contains(fragment.owner._semantics!.id)) { + fragment.owner._semantics = null; + } + } + fragment._ancestorChain.addAll(_ancestorChain.skip(1)); + fragment.compileChildren( + parentSemanticsClipRect: parentSemanticsClipRect, + parentPaintClipRect: parentPaintClipRect, + // The fragment is not explicit, its elevation has been absorbed by + // the parent config (as thickness). We still need to make sure that + // its children are placed at the elevation dictated by this config. + elevationAdjustment: elevationAdjustment + _config.elevation, + result: result, + siblingNodes: siblingNodes, + ); + } + return; + } + + final _SemanticsGeometry? geometry = _computeSemanticsGeometry( + parentSemanticsClipRect: parentSemanticsClipRect, + parentPaintClipRect: parentPaintClipRect, + ); + + if (!_mergeIntoParent && (geometry?.dropFromTree ?? false)) { + return; // Drop the node, it's not going to be visible. + } + + final SemanticsNode node = (owner._semantics ??= SemanticsNode(showOnScreen: owner.showOnScreen)) + ..tags = _tagsForChildren; + + node.elevationAdjustment = elevationAdjustment; + if (elevationAdjustment != 0.0) { + _ensureConfigIsWritable(); + _config.elevation += elevationAdjustment; + } + + if (geometry != null) { + assert(_needsGeometryUpdate); + node + ..rect = geometry.rect + ..transform = geometry.transform + ..parentSemanticsClipRect = geometry.semanticsClipRect + ..parentPaintClipRect = geometry.paintClipRect; + if (!_mergeIntoParent && geometry.markAsHidden) { + _ensureConfigIsWritable(); + _config.isHidden = true; + } + } + final List<SemanticsNode> children = <SemanticsNode>[]; + _mergeSiblingGroup( + node.parentSemanticsClipRect, + node.parentPaintClipRect, + siblingNodes, + usedSemanticsIds, + ); + for (final _InterestingSemanticsFragment fragment in compilingFragments) { + if (fragment is _SwitchableSemanticsFragment) { + // Cached semantics node may be part of sibling merging group prior + // to this update. In this case, the semantics node may continue to + // be reused in that sibling merging group. + if (fragment._isExplicit && + fragment.owner._semantics != null && + usedSemanticsIds.contains(fragment.owner._semantics!.id)) { + fragment.owner._semantics = null; + } + } + final List<SemanticsNode> childSiblingNodes = <SemanticsNode>[]; + fragment.compileChildren( + parentSemanticsClipRect: node.parentSemanticsClipRect, + parentPaintClipRect: node.parentPaintClipRect, + elevationAdjustment: 0.0, + result: children, + siblingNodes: childSiblingNodes, + ); + siblingNodes.addAll(childSiblingNodes); + } + + if (_config.isSemanticBoundary) { + owner.assembleSemanticsNode(node, _config, children); + } else { + node.updateWith(config: _config, childrenInInversePaintOrder: children); + } + result.add(node); + // Sibling node needs to attach to the parent of an explicit node. + for (final SemanticsNode siblingNode in siblingNodes) { + // sibling nodes are in the same coordinate of the immediate explicit node. + // They need to share the same transform if they are going to attach to the + // parent of the immediate explicit node. + assert(siblingNode.transform == null); + siblingNode.transform = node.transform; + if (_tagsForChildren != null) { + siblingNode.tags ??= <SemanticsTag>{}; + siblingNode.tags!.addAll(_tagsForChildren!); + } + } + result.addAll(siblingNodes); + siblingNodes.clear(); + } + + _SemanticsGeometry? _computeSemanticsGeometry({ + required Rect? parentSemanticsClipRect, + required Rect? parentPaintClipRect, + }) { + return _needsGeometryUpdate + ? _SemanticsGeometry(parentSemanticsClipRect: parentSemanticsClipRect, parentPaintClipRect: parentPaintClipRect, ancestors: _ancestorChain) + : null; + } + + @override + SemanticsConfiguration? get config { + return _isExplicit ? null : _config; + } + + @override + void addAll(Iterable<_InterestingSemanticsFragment> fragments) { + for (final _InterestingSemanticsFragment fragment in fragments) { + _children.add(fragment); + if (fragment.config == null) { + continue; + } + _ensureConfigIsWritable(); + _config.absorb(fragment.config!); + } + } + + @override + void addTags(Iterable<SemanticsTag> tags) { + super.addTags(tags); + // _ContainerSemanticsFragments add their tags to child fragments through + // this method. This fragment must make sure its _config is in sync. + if (tags.isNotEmpty) { + _ensureConfigIsWritable(); + tags.forEach(_config.addTagForChildren); + } + } + + void _ensureConfigIsWritable() { + if (!_isConfigWritable) { + _config = _config.copy(); + _isConfigWritable = true; + } + } + + bool _isExplicit = false; + + @override + void markAsExplicit() { + _isExplicit = true; + } + + bool get _needsGeometryUpdate => _ancestorChain.length > 1; +} + +/// Helper class that keeps track of the geometry of a [SemanticsNode]. +/// +/// It is used to annotate a [SemanticsNode] with the current information for +/// [SemanticsNode.rect] and [SemanticsNode.transform]. +class _SemanticsGeometry { + + /// The `parentClippingRect` may be null if no clip is to be applied. + /// + /// The `ancestors` list has to include all [RenderObject] in order that are + /// located between the [SemanticsNode] whose geometry is represented here + /// (first [RenderObject] in the list) and its closest ancestor [RenderObject] + /// that also owns its own [SemanticsNode] (last [RenderObject] in the list). + _SemanticsGeometry({ + required Rect? parentSemanticsClipRect, + required Rect? parentPaintClipRect, + required List<RenderObject> ancestors, + }) { + _computeValues(parentSemanticsClipRect, parentPaintClipRect, ancestors); + } + + Rect? _paintClipRect; + Rect? _semanticsClipRect; + late Matrix4 _transform; + late Rect _rect; + + /// Value for [SemanticsNode.transform]. + Matrix4 get transform => _transform; + + /// Value for [SemanticsNode.parentSemanticsClipRect]. + Rect? get semanticsClipRect => _semanticsClipRect; + + /// Value for [SemanticsNode.parentPaintClipRect]. + Rect? get paintClipRect => _paintClipRect; + + /// Value for [SemanticsNode.rect]. + Rect get rect => _rect; + + /// Computes values, ensuring `rect` is properly bounded by ancestor clipping rects. + /// + /// See also: + /// + /// * [RenderObject.describeSemanticsClip], typically used to determine `parentSemanticsClipRect`. + /// * [RenderObject.describeApproximatePaintClip], typically used to determine `parentPaintClipRect`. + void _computeValues(Rect? parentSemanticsClipRect, Rect? parentPaintClipRect, List<RenderObject> ancestors) { + assert(ancestors.length > 1); + + _transform = Matrix4.identity(); + _semanticsClipRect = parentSemanticsClipRect; + _paintClipRect = parentPaintClipRect; + + for (int index = ancestors.length-1; index > 0; index -= 1) { + final RenderObject semanticsParent = ancestors[index]; + final RenderObject semanticsChild = ancestors[index-1]; + _applyIntermediatePaintTransforms(semanticsParent, semanticsChild, _transform); + + if (identical(semanticsParent, semanticsChild.parent)) { + // The easier and more common case: semanticsParent is directly + // responsible for painting (and potentially clipping) the semanticsChild + // RenderObject. + _computeClipRect(semanticsParent, semanticsChild, _semanticsClipRect, _paintClipRect); + } else { + // Otherwise we have to find the closest ancestor RenderObject that + // has up-to-date semantics geometry and compute the clip rects from there. + // + // Currently it can only happen when the subtree contains an OverlayPortal. + final List<RenderObject> clipPath = <RenderObject>[semanticsChild]; + + RenderObject? ancestor = semanticsChild.parent; + while (ancestor != null && ancestor._semantics == null) { + clipPath.add(ancestor); + ancestor = ancestor.parent; + } + _paintClipRect = ancestor?._semantics?.parentPaintClipRect; + _semanticsClipRect = ancestor?._semantics?.parentSemanticsClipRect; + if (ancestor != null) { + assert(ancestor._semantics != null); + assert(!ancestor._needsSemanticsUpdate); + RenderObject parent = ancestor; + for (int i = clipPath.length - 1; i >= 0; i -= 1) { + _computeClipRect(parent, clipPath[i], _semanticsClipRect, _paintClipRect); + parent = clipPath[i]; + } + } + } + } + + final RenderObject owner = ancestors.first; + _rect = _semanticsClipRect?.intersect(owner.semanticBounds) ?? owner.semanticBounds; + if (_paintClipRect != null) { + final Rect paintRect = _paintClipRect!.intersect(_rect); + _markAsHidden = paintRect.isEmpty && !_rect.isEmpty; + if (!_markAsHidden) { + _rect = paintRect; + } + } + } + + /// From parent to child coordinate system. + static Rect? _transformRect(Rect? rect, Matrix4 transform) { + if (rect == null) { + return null; + } + if (rect.isEmpty || transform.isZero()) { + return Rect.zero; + } + return MatrixUtils.inverseTransformRect(transform, rect); + } + + // Computes the paint transform from `childFragmentOwner` to + // `parentFragmentOwner` and applies the paint transform to `transform` in + // place. + // + // The `parentFragmentOwner` and `childFragmentOwner` [RenderObject]s must be + // in the same render tree (so they have a common ancestor). + static void _applyIntermediatePaintTransforms( + RenderObject parentFragmentOwner, + RenderObject childFragmentOwner, + Matrix4 transform, + ) { + Matrix4? parentToCommonAncestorTransform; + RenderObject from = childFragmentOwner; + RenderObject to = parentFragmentOwner; + + while (!identical(from, to)) { + final int fromDepth = from.depth; + final int toDepth = to.depth; + + if (fromDepth >= toDepth) { + assert(from.parent != null, '$parentFragmentOwner and $childFragmentOwner are not in the same render tree.'); + final RenderObject fromParent = from.parent!; + fromParent.applyPaintTransform(from, transform); + from = fromParent; + } + if (fromDepth <= toDepth) { + assert(to.parent != null, '$parentFragmentOwner and $childFragmentOwner are not in the same render tree.'); + final RenderObject toParent = to.parent!; + toParent.applyPaintTransform(to, parentToCommonAncestorTransform ??= Matrix4.identity()); + to = toParent; + } + } + + if (parentToCommonAncestorTransform != null) { + if (parentToCommonAncestorTransform.invert() != 0) { + transform.multiply(parentToCommonAncestorTransform); + } else { + transform.setZero(); + } + } + } + + // A matrix used to store transient transform data. + // + // Reusing this matrix avoids allocating a new matrix every time a temporary + // matrix is needed. + // + // This instance should never be returned to the caller. Otherwise, the data + // stored in it will be overwritten unpredictably by subsequent reuses. + static final Matrix4 _temporaryTransformHolder = Matrix4.zero(); + + // Computes the semantics and painting clip rects for the given child and + // assigns the rects to _semanticsClipRect and _paintClipRect respectively. + // + // The caller must guarantee that child.parent == parent. The resulting rects + // are in `child`'s coordinate system. + void _computeClipRect(RenderObject parent, RenderObject child, Rect? parentSemanticsClipRect, Rect? parentPaintClipRect) { + assert(identical(child.parent, parent)); + // Computes the paint transform from child to parent. The _transformRect + // method will compute the inverse. + _temporaryTransformHolder.setIdentity(); // clears data from previous call(s) + parent.applyPaintTransform(child, _temporaryTransformHolder); + + final Rect? additionalPaintClip = parent.describeApproximatePaintClip(child); + _paintClipRect = _transformRect( + _intersectRects(additionalPaintClip, parentPaintClipRect), + _temporaryTransformHolder, + ); + + if (_paintClipRect == null) { + _semanticsClipRect = null; + } else { + final Rect? semanticsClip = parent.describeSemanticsClip(child) ?? _intersectRects(parentSemanticsClipRect, additionalPaintClip); + _semanticsClipRect = _transformRect(semanticsClip, _temporaryTransformHolder); + } + } + + static Rect? _intersectRects(Rect? a, Rect? b) { + if (b == null) { + return a; + } + return a?.intersect(b) ?? b; + } + + /// Whether the [SemanticsNode] annotated with the geometric information tracked + /// by this object can be dropped from the semantics tree without losing + /// semantics information. + bool get dropFromTree { + return _rect.isEmpty || _transform.isZero(); + } + + /// Whether the [SemanticsNode] annotated with the geometric information + /// tracked by this object should be marked as hidden because it is not + /// visible on screen. + /// + /// Hidden elements should still be included in the tree to work around + /// platform limitations (e.g. accessibility scrolling on iOS). + /// + /// See also: + /// + /// * [SemanticsFlag.isHidden] for the purpose of marking a node as hidden. + bool get markAsHidden => _markAsHidden; + bool _markAsHidden = false; +} + +/// A class that creates [DiagnosticsNode] by wrapping [RenderObject.debugCreator]. +/// +/// Attach a [DiagnosticsDebugCreator] into [FlutterErrorDetails.informationCollector] +/// when a [RenderObject.debugCreator] is available. This will lead to improved +/// error message. +class DiagnosticsDebugCreator extends DiagnosticsProperty<Object> { + /// Create a [DiagnosticsProperty] with its [value] initialized to input + /// [RenderObject.debugCreator]. + DiagnosticsDebugCreator(Object value) + : super( + 'debugCreator', + value, + level: DiagnosticLevel.hidden, + ); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/paragraph.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/paragraph.dart new file mode 100644 index 0000000000000000000000000000000000000000..b3206fa79065bcd746b4931161b9770bf23ae818 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/paragraph.dart @@ -0,0 +1,2135 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:math' as math; +import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle, Gradient, LineMetrics, PlaceholderAlignment, Shader, TextBox, TextHeightBehavior; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/semantics.dart'; +import 'package:flutter/services.dart'; + +import 'box.dart'; +import 'debug.dart'; +import 'layer.dart'; +import 'layout_helper.dart'; +import 'object.dart'; +import 'selection.dart'; + +/// The start and end positions for a word. +typedef _WordBoundaryRecord = ({TextPosition wordStart, TextPosition wordEnd}); + +const String _kEllipsis = '\u2026'; + +/// Used by the [RenderParagraph] to map its rendering children to their +/// corresponding semantics nodes. +/// +/// The [RichText] uses this to tag the relation between its placeholder spans +/// and their semantics nodes. +@immutable +class PlaceholderSpanIndexSemanticsTag extends SemanticsTag { + /// Creates a semantics tag with the input `index`. + /// + /// Different [PlaceholderSpanIndexSemanticsTag]s with the same `index` are + /// consider the same. + const PlaceholderSpanIndexSemanticsTag(this.index) : super('PlaceholderSpanIndexSemanticsTag($index)'); + + /// The index of this tag. + final int index; + + @override + bool operator ==(Object other) { + return other is PlaceholderSpanIndexSemanticsTag + && other.index == index; + } + + @override + int get hashCode => Object.hash(PlaceholderSpanIndexSemanticsTag, index); +} + +/// Parent data used by [RenderParagraph] and [RenderEditable] to annotate +/// inline contents (such as [WidgetSpan]s) with. +class TextParentData extends ParentData with ContainerParentDataMixin<RenderBox> { + /// The offset at which to paint the child in the parent's coordinate system. + /// + /// A `null` value indicates this inline widget is not laid out. For instance, + /// when the inline widget has never been laid out, or the inline widget is + /// ellipsized away. + Offset? get offset => _offset; + Offset? _offset; + + /// The [PlaceholderSpan] associated with this render child. + /// + /// This field is usually set by a [ParentDataWidget], and is typically not + /// null when `performLayout` is called. + PlaceholderSpan? span; + + @override + void detach() { + span = null; + _offset = null; + super.detach(); + } + + @override + String toString() => 'widget: $span, ${offset == null ? "not laid out" : "offset: $offset"}'; +} + +/// A mixin that provides useful default behaviors for text [RenderBox]es +/// ([RenderParagraph] and [RenderEditable] for example) with inline content +/// children managed by the [ContainerRenderObjectMixin] mixin. +/// +/// This mixin assumes every child managed by the [ContainerRenderObjectMixin] +/// mixin corresponds to a [PlaceholderSpan], and they are organized in logical +/// order of the text (the order each [PlaceholderSpan] is encountered when the +/// user reads the text). +/// +/// To use this mixin in a [RenderBox] class: +/// +/// * Call [layoutInlineChildren] in the `performLayout` and `computeDryLayout` +/// implementation, and during intrinsic size calculations, to get the size +/// information of the inline widgets as a `List` of `PlaceholderDimensions`. +/// Determine the positioning of the inline widgets (which is usually done by +/// a [TextPainter] using its line break algorithm). +/// +/// * Call [positionInlineChildren] with the positioning information of the +/// inline widgets. +/// +/// * Implement [RenderBox.applyPaintTransform], optionally with +/// [defaultApplyPaintTransform]. +/// +/// * Call [paintInlineChildren] in [RenderBox.paint] to paint the inline widgets. +/// +/// * Call [hitTestInlineChildren] in [RenderBox.hitTestChildren] to hit test the +/// inline widgets. +/// +/// See also: +/// +/// * [WidgetSpan.extractFromInlineSpan], a helper function for extracting +/// [WidgetSpan]s from an [InlineSpan] tree. +mixin RenderInlineChildrenContainerDefaults on RenderBox, ContainerRenderObjectMixin<RenderBox, TextParentData> { + @override + void setupParentData(RenderBox child) { + if (child.parentData is! TextParentData) { + child.parentData = TextParentData(); + } + } + + static PlaceholderDimensions _layoutChild(RenderBox child, double maxWidth, ChildLayouter layoutChild) { + final TextParentData parentData = child.parentData! as TextParentData; + final PlaceholderSpan? span = parentData.span; + assert(span != null); + return span == null + ? PlaceholderDimensions.empty + : PlaceholderDimensions( + size: layoutChild(child, BoxConstraints(maxWidth: maxWidth)), + alignment: span.alignment, + baseline: span.baseline, + baselineOffset: switch (span.alignment) { + ui.PlaceholderAlignment.aboveBaseline || + ui.PlaceholderAlignment.belowBaseline || + ui.PlaceholderAlignment.bottom || + ui.PlaceholderAlignment.middle || + ui.PlaceholderAlignment.top => null, + ui.PlaceholderAlignment.baseline => child.getDistanceToBaseline(span.baseline!), + }, + ); + } + + /// Computes the layout for every inline child using the given `layoutChild` + /// function and the `maxWidth` constraint. + /// + /// Returns a list of [PlaceholderDimensions], representing the layout results + /// for each child managed by the [ContainerRenderObjectMixin] mixin. + /// + /// Since this method does not impose a maximum height constraint on the + /// inline children, some children may become taller than this [RenderBox]. + /// + /// See also: + /// + /// * [TextPainter.setPlaceholderDimensions], the method that usually takes + /// the layout results from this method as the input. + @protected + List<PlaceholderDimensions> layoutInlineChildren(double maxWidth, ChildLayouter layoutChild) { + return <PlaceholderDimensions>[ + for (RenderBox? child = firstChild; child != null; child = childAfter(child)) + _layoutChild(child, maxWidth, layoutChild), + ]; + } + + /// Positions each inline child according to the coordinates provided in the + /// `boxes` list. + /// + /// The `boxes` list must be in logical order, which is the order each child + /// is encountered when the user reads the text. Usually the length of the + /// list equals [childCount], but it can be less than that, when some children + /// are ommitted due to ellipsing. It never exceeds [childCount]. + /// + /// See also: + /// + /// * [TextPainter.inlinePlaceholderBoxes], the method that can be used to + /// get the input `boxes`. + @protected + void positionInlineChildren(List<ui.TextBox> boxes) { + RenderBox? child = firstChild; + for (final ui.TextBox box in boxes) { + if (child == null) { + assert(false, 'The length of boxes (${boxes.length}) should be greater than childCount ($childCount)'); + return; + } + final TextParentData textParentData = child.parentData! as TextParentData; + textParentData._offset = Offset(box.left, box.top); + child = childAfter(child); + } + while (child != null) { + final TextParentData textParentData = child.parentData! as TextParentData; + textParentData._offset = null; + child = childAfter(child); + } + } + + /// Applies the transform that would be applied when painting the given child + /// to the given matrix. + /// + /// Render children whose [TextParentData.offset] is null zeros out the + /// `transform` to indicate they're invisible thus should not be painted. + @protected + void defaultApplyPaintTransform(RenderBox child, Matrix4 transform) { + final TextParentData childParentData = child.parentData! as TextParentData; + final Offset? offset = childParentData.offset; + if (offset == null) { + transform.setZero(); + } else { + transform.translate(offset.dx, offset.dy); + } + } + + /// Paints each inline child. + /// + /// Render children whose [TextParentData.offset] is null will be skipped by + /// this method. + @protected + void paintInlineChildren(PaintingContext context, Offset offset) { + RenderBox? child = firstChild; + while (child != null) { + final TextParentData childParentData = child.parentData! as TextParentData; + final Offset? childOffset = childParentData.offset; + if (childOffset == null) { + return; + } + context.paintChild(child, childOffset + offset); + child = childAfter(child); + } + } + + /// Performs a hit test on each inline child. + /// + /// Render children whose [TextParentData.offset] is null will be skipped by + /// this method. + @protected + bool hitTestInlineChildren(BoxHitTestResult result, Offset position) { + RenderBox? child = firstChild; + while (child != null) { + final TextParentData childParentData = child.parentData! as TextParentData; + final Offset? childOffset = childParentData.offset; + if (childOffset == null) { + return false; + } + final bool isHit = result.addWithPaintOffset( + offset: childOffset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) => child!.hitTest(result, position: transformed), + ); + if (isHit) { + return true; + } + child = childAfter(child); + } + return false; + } +} + +/// A render object that displays a paragraph of text. +class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBox, TextParentData>, RenderInlineChildrenContainerDefaults, RelayoutWhenSystemFontsChangeMixin { + /// Creates a paragraph render object. + /// + /// The [maxLines] property may be null (and indeed defaults to null), but if + /// it is not null, it must be greater than zero. + RenderParagraph(InlineSpan text, { + TextAlign textAlign = TextAlign.start, + required TextDirection textDirection, + bool softWrap = true, + TextOverflow overflow = TextOverflow.clip, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double textScaleFactor = 1.0, + TextScaler textScaler = TextScaler.noScaling, + int? maxLines, + Locale? locale, + StrutStyle? strutStyle, + TextWidthBasis textWidthBasis = TextWidthBasis.parent, + ui.TextHeightBehavior? textHeightBehavior, + List<RenderBox>? children, + Color? selectionColor, + SelectionRegistrar? registrar, + }) : assert(text.debugAssertIsValid()), + assert(maxLines == null || maxLines > 0), + assert( + identical(textScaler, TextScaler.noScaling) || textScaleFactor == 1.0, + 'textScaleFactor is deprecated and cannot be specified when textScaler is specified.', + ), + _softWrap = softWrap, + _overflow = overflow, + _selectionColor = selectionColor, + _textPainter = TextPainter( + text: text, + textAlign: textAlign, + textDirection: textDirection, + textScaler: textScaler == TextScaler.noScaling ? TextScaler.linear(textScaleFactor) : textScaler, + maxLines: maxLines, + ellipsis: overflow == TextOverflow.ellipsis ? _kEllipsis : null, + locale: locale, + strutStyle: strutStyle, + textWidthBasis: textWidthBasis, + textHeightBehavior: textHeightBehavior, + ) { + addAll(children); + this.registrar = registrar; + } + + static final String _placeholderCharacter = String.fromCharCode(PlaceholderSpan.placeholderCodeUnit); + + final TextPainter _textPainter; + + List<AttributedString>? _cachedAttributedLabels; + + List<InlineSpanSemanticsInformation>? _cachedCombinedSemanticsInfos; + + /// The text to display. + InlineSpan get text => _textPainter.text!; + set text(InlineSpan value) { + switch (_textPainter.text!.compareTo(value)) { + case RenderComparison.identical: + return; + case RenderComparison.metadata: + _textPainter.text = value; + _cachedCombinedSemanticsInfos = null; + markNeedsSemanticsUpdate(); + case RenderComparison.paint: + _textPainter.text = value; + _cachedAttributedLabels = null; + _canComputeIntrinsicsCached = null; + _cachedCombinedSemanticsInfos = null; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + case RenderComparison.layout: + _textPainter.text = value; + _overflowShader = null; + _cachedAttributedLabels = null; + _cachedCombinedSemanticsInfos = null; + _canComputeIntrinsicsCached = null; + markNeedsLayout(); + _removeSelectionRegistrarSubscription(); + _disposeSelectableFragments(); + _updateSelectionRegistrarSubscription(); + } + } + + /// The ongoing selections in this paragraph. + /// + /// The selection does not include selections in [PlaceholderSpan] if there + /// are any. + @visibleForTesting + List<TextSelection> get selections { + if (_lastSelectableFragments == null) { + return const <TextSelection>[]; + } + final List<TextSelection> results = <TextSelection>[]; + for (final _SelectableFragment fragment in _lastSelectableFragments!) { + if (fragment._textSelectionStart != null && + fragment._textSelectionEnd != null) { + results.add( + TextSelection( + baseOffset: fragment._textSelectionStart!.offset, + extentOffset: fragment._textSelectionEnd!.offset + ) + ); + } + } + return results; + } + + // Should be null if selection is not enabled, i.e. _registrar = null. The + // paragraph splits on [PlaceholderSpan.placeholderCodeUnit], and stores each + // fragment in this list. + List<_SelectableFragment>? _lastSelectableFragments; + + /// The [SelectionRegistrar] this paragraph will be, or is, registered to. + SelectionRegistrar? get registrar => _registrar; + SelectionRegistrar? _registrar; + set registrar(SelectionRegistrar? value) { + if (value == _registrar) { + return; + } + _removeSelectionRegistrarSubscription(); + _disposeSelectableFragments(); + _registrar = value; + _updateSelectionRegistrarSubscription(); + } + + void _updateSelectionRegistrarSubscription() { + if (_registrar == null) { + return; + } + _lastSelectableFragments ??= _getSelectableFragments(); + _lastSelectableFragments!.forEach(_registrar!.add); + if (_lastSelectableFragments!.isNotEmpty) { + markNeedsCompositingBitsUpdate(); + } + } + + void _removeSelectionRegistrarSubscription() { + if (_registrar == null || _lastSelectableFragments == null) { + return; + } + _lastSelectableFragments!.forEach(_registrar!.remove); + } + + List<_SelectableFragment> _getSelectableFragments() { + final String plainText = text.toPlainText(includeSemanticsLabels: false); + final List<_SelectableFragment> result = <_SelectableFragment>[]; + int start = 0; + while (start < plainText.length) { + int end = plainText.indexOf(_placeholderCharacter, start); + if (start != end) { + if (end == -1) { + end = plainText.length; + } + result.add( + _SelectableFragment( + paragraph: this, + range: TextRange(start: start, end: end), + fullText: plainText, + ), + ); + start = end; + } + start += 1; + } + return result; + } + + void _disposeSelectableFragments() { + if (_lastSelectableFragments == null) { + return; + } + for (final _SelectableFragment fragment in _lastSelectableFragments!) { + fragment.dispose(); + } + _lastSelectableFragments = null; + } + + @override + bool get alwaysNeedsCompositing => _lastSelectableFragments?.isNotEmpty ?? false; + + @override + void markNeedsLayout() { + _lastSelectableFragments?.forEach((_SelectableFragment element) => element.didChangeParagraphLayout()); + super.markNeedsLayout(); + } + + @override + void dispose() { + _removeSelectionRegistrarSubscription(); + _disposeSelectableFragments(); + _textPainter.dispose(); + super.dispose(); + } + + /// How the text should be aligned horizontally. + TextAlign get textAlign => _textPainter.textAlign; + set textAlign(TextAlign value) { + if (_textPainter.textAlign == value) { + return; + } + _textPainter.textAlign = value; + markNeedsPaint(); + } + + /// The directionality of the text. + /// + /// This decides how the [TextAlign.start], [TextAlign.end], and + /// [TextAlign.justify] values of [textAlign] are interpreted. + /// + /// This is also used to disambiguate how to render bidirectional text. For + /// example, if the [text] is an English phrase followed by a Hebrew phrase, + /// in a [TextDirection.ltr] context the English phrase will be on the left + /// and the Hebrew phrase to its right, while in a [TextDirection.rtl] + /// context, the English phrase will be on the right and the Hebrew phrase on + /// its left. + TextDirection get textDirection => _textPainter.textDirection!; + set textDirection(TextDirection value) { + if (_textPainter.textDirection == value) { + return; + } + _textPainter.textDirection = value; + markNeedsLayout(); + } + + /// Whether the text should break at soft line breaks. + /// + /// If false, the glyphs in the text will be positioned as if there was + /// unlimited horizontal space. + /// + /// If [softWrap] is false, [overflow] and [textAlign] may have unexpected + /// effects. + bool get softWrap => _softWrap; + bool _softWrap; + set softWrap(bool value) { + if (_softWrap == value) { + return; + } + _softWrap = value; + markNeedsLayout(); + } + + /// How visual overflow should be handled. + TextOverflow get overflow => _overflow; + TextOverflow _overflow; + set overflow(TextOverflow value) { + if (_overflow == value) { + return; + } + _overflow = value; + _textPainter.ellipsis = value == TextOverflow.ellipsis ? _kEllipsis : null; + markNeedsLayout(); + } + + /// Deprecated. Will be removed in a future version of Flutter. Use + /// [textScaler] instead. + /// + /// The number of font pixels for each logical pixel. + /// + /// For example, if the text scale factor is 1.5, text will be 50% larger than + /// the specified font size. + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double get textScaleFactor => _textPainter.textScaleFactor; + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + set textScaleFactor(double value) { + textScaler = TextScaler.linear(value); + } + + /// {@macro flutter.painting.textPainter.textScaler} + TextScaler get textScaler => _textPainter.textScaler; + set textScaler(TextScaler value) { + if (_textPainter.textScaler == value) { + return; + } + _textPainter.textScaler = value; + _overflowShader = null; + markNeedsLayout(); + } + + /// An optional maximum number of lines for the text to span, wrapping if + /// necessary. If the text exceeds the given number of lines, it will be + /// truncated according to [overflow] and [softWrap]. + int? get maxLines => _textPainter.maxLines; + /// The value may be null. If it is not null, then it must be greater than + /// zero. + set maxLines(int? value) { + assert(value == null || value > 0); + if (_textPainter.maxLines == value) { + return; + } + _textPainter.maxLines = value; + _overflowShader = null; + markNeedsLayout(); + } + + /// Used by this paragraph's internal [TextPainter] to select a + /// locale-specific font. + /// + /// In some cases, the same Unicode character may be rendered differently + /// depending on the locale. For example, the '骨' character is rendered + /// differently in the Chinese and Japanese locales. In these cases, the + /// [locale] may be used to select a locale-specific font. + Locale? get locale => _textPainter.locale; + /// The value may be null. + set locale(Locale? value) { + if (_textPainter.locale == value) { + return; + } + _textPainter.locale = value; + _overflowShader = null; + markNeedsLayout(); + } + + /// {@macro flutter.painting.textPainter.strutStyle} + StrutStyle? get strutStyle => _textPainter.strutStyle; + /// The value may be null. + set strutStyle(StrutStyle? value) { + if (_textPainter.strutStyle == value) { + return; + } + _textPainter.strutStyle = value; + _overflowShader = null; + markNeedsLayout(); + } + + /// {@macro flutter.painting.textPainter.textWidthBasis} + TextWidthBasis get textWidthBasis => _textPainter.textWidthBasis; + set textWidthBasis(TextWidthBasis value) { + if (_textPainter.textWidthBasis == value) { + return; + } + _textPainter.textWidthBasis = value; + _overflowShader = null; + markNeedsLayout(); + } + + /// {@macro dart.ui.textHeightBehavior} + ui.TextHeightBehavior? get textHeightBehavior => _textPainter.textHeightBehavior; + set textHeightBehavior(ui.TextHeightBehavior? value) { + if (_textPainter.textHeightBehavior == value) { + return; + } + _textPainter.textHeightBehavior = value; + _overflowShader = null; + markNeedsLayout(); + } + + /// The color to use when painting the selection. + /// + /// Ignored if the text is not selectable (e.g. if [registrar] is null). + Color? get selectionColor => _selectionColor; + Color? _selectionColor; + set selectionColor(Color? value) { + if (_selectionColor == value) { + return; + } + _selectionColor = value; + if (_lastSelectableFragments?.any((_SelectableFragment fragment) => fragment.value.hasSelection) ?? false) { + markNeedsPaint(); + } + } + + Offset _getOffsetForPosition(TextPosition position) { + return getOffsetForCaret(position, Rect.zero) + Offset(0, getFullHeightForCaret(position) ?? 0.0); + } + + List<ui.LineMetrics> _computeLineMetrics() { + return _textPainter.computeLineMetrics(); + } + + @override + double computeMinIntrinsicWidth(double height) { + if (!_canComputeIntrinsics()) { + return 0.0; + } + _textPainter.setPlaceholderDimensions(layoutInlineChildren( + double.infinity, + (RenderBox child, BoxConstraints constraints) => Size(child.getMinIntrinsicWidth(double.infinity), 0.0), + )); + _layoutText(); // layout with infinite width. + return _textPainter.minIntrinsicWidth; + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (!_canComputeIntrinsics()) { + return 0.0; + } + _textPainter.setPlaceholderDimensions(layoutInlineChildren( + double.infinity, + // Height and baseline is irrelevant as all text will be laid + // out in a single line. Therefore, using 0.0 as a dummy for the height. + (RenderBox child, BoxConstraints constraints) => Size(child.getMaxIntrinsicWidth(double.infinity), 0.0), + )); + _layoutText(); // layout with infinite width. + return _textPainter.maxIntrinsicWidth; + } + + double _computeIntrinsicHeight(double width) { + if (!_canComputeIntrinsics()) { + return 0.0; + } + _textPainter.setPlaceholderDimensions(layoutInlineChildren(width, ChildLayoutHelper.dryLayoutChild)); + _layoutText(minWidth: width, maxWidth: width); + return _textPainter.height; + } + + @override + double computeMinIntrinsicHeight(double width) { + return _computeIntrinsicHeight(width); + } + + @override + double computeMaxIntrinsicHeight(double width) { + return _computeIntrinsicHeight(width); + } + + @override + double computeDistanceToActualBaseline(TextBaseline baseline) { + assert(!debugNeedsLayout); + assert(constraints.debugAssertIsValid()); + _layoutTextWithConstraints(constraints); + // TODO(garyq): Since our metric for ideographic baseline is currently + // inaccurate and the non-alphabetic baselines are based off of the + // alphabetic baseline, we use the alphabetic for now to produce correct + // layouts. We should eventually change this back to pass the `baseline` + // property when the ideographic baseline is properly implemented + // (https://github.com/flutter/flutter/issues/22625). + return _textPainter.computeDistanceToActualBaseline(TextBaseline.alphabetic); + } + + /// Whether all inline widget children of this [RenderBox] support dry layout + /// calculation. + bool _canComputeDryLayoutForInlineWidgets() { + // Dry layout cannot be calculated without a full layout for + // alignments that require the baseline (baseline, aboveBaseline, + // belowBaseline). + return text.visitChildren((InlineSpan span) { + return (span is! PlaceholderSpan) || switch (span.alignment) { + ui.PlaceholderAlignment.baseline || + ui.PlaceholderAlignment.aboveBaseline || + ui.PlaceholderAlignment.belowBaseline => false, + ui.PlaceholderAlignment.top || + ui.PlaceholderAlignment.middle || + ui.PlaceholderAlignment.bottom => true, + }; + }); + } + + bool? _canComputeIntrinsicsCached; + // Intrinsics cannot be calculated without a full layout for + // alignments that require the baseline (baseline, aboveBaseline, + // belowBaseline). + bool _canComputeIntrinsics() { + final bool returnValue = _canComputeIntrinsicsCached ??= _canComputeDryLayoutForInlineWidgets(); + assert( + returnValue || RenderObject.debugCheckingIntrinsics, + 'Intrinsics are not available for PlaceholderAlignment.baseline, ' + 'PlaceholderAlignment.aboveBaseline, or PlaceholderAlignment.belowBaseline.', + ); + return returnValue; + } + + @override + bool hitTestSelf(Offset position) => true; + + @override + @protected + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + final GlyphInfo? glyph = _textPainter.getClosestGlyphForOffset(position); + // The hit-test can't fall through the horizontal gaps between visually + // adjacent characters on the same line, even with a large letter-spacing or + // text justification, as graphemeClusterLayoutBounds.width is the advance + // width to the next character, so there's no gap between their + // graphemeClusterLayoutBounds rects. + final InlineSpan? spanHit = glyph != null && glyph.graphemeClusterLayoutBounds.contains(position) + ? _textPainter.text!.getSpanForPosition(TextPosition(offset: glyph.graphemeClusterCodeUnitRange.start)) + : null; + switch (spanHit) { + case final HitTestTarget span: + result.add(HitTestEntry(span)); + return true; + case _: + return hitTestInlineChildren(result, position); + } + } + + bool _needsClipping = false; + ui.Shader? _overflowShader; + + /// Whether this paragraph currently has a [dart:ui.Shader] for its overflow + /// effect. + /// + /// Used to test this object. Not for use in production. + @visibleForTesting + bool get debugHasOverflowShader => _overflowShader != null; + + void _layoutText({ double minWidth = 0.0, double maxWidth = double.infinity }) { + final bool widthMatters = softWrap || overflow == TextOverflow.ellipsis; + _textPainter.layout( + minWidth: minWidth, + maxWidth: widthMatters ? maxWidth : double.infinity, + ); + } + + @override + void systemFontsDidChange() { + super.systemFontsDidChange(); + _textPainter.markNeedsLayout(); + } + + // Placeholder dimensions representing the sizes of child inline widgets. + // + // These need to be cached because the text painter's placeholder dimensions + // will be overwritten during intrinsic width/height calculations and must be + // restored to the original values before final layout and painting. + List<PlaceholderDimensions>? _placeholderDimensions; + + void _layoutTextWithConstraints(BoxConstraints constraints) { + _textPainter.setPlaceholderDimensions(_placeholderDimensions); + _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (!_canComputeIntrinsics()) { + assert(debugCannotComputeDryLayout( + reason: 'Dry layout not available for alignments that require baseline.', + )); + return Size.zero; + } + _textPainter.setPlaceholderDimensions(layoutInlineChildren(constraints.maxWidth, ChildLayoutHelper.dryLayoutChild)); + _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); + return constraints.constrain(_textPainter.size); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + _placeholderDimensions = layoutInlineChildren(constraints.maxWidth, ChildLayoutHelper.layoutChild); + _layoutTextWithConstraints(constraints); + positionInlineChildren(_textPainter.inlinePlaceholderBoxes!); + + // We grab _textPainter.size and _textPainter.didExceedMaxLines here because + // assigning to `size` will trigger us to validate our intrinsic sizes, + // which will change _textPainter's layout because the intrinsic size + // calculations are destructive. Other _textPainter state will also be + // affected. See also RenderEditable which has a similar issue. + final Size textSize = _textPainter.size; + final bool textDidExceedMaxLines = _textPainter.didExceedMaxLines; + size = constraints.constrain(textSize); + + final bool didOverflowHeight = size.height < textSize.height || textDidExceedMaxLines; + final bool didOverflowWidth = size.width < textSize.width; + // TODO(abarth): We're only measuring the sizes of the line boxes here. If + // the glyphs draw outside the line boxes, we might think that there isn't + // visual overflow when there actually is visual overflow. This can become + // a problem if we start having horizontal overflow and introduce a clip + // that affects the actual (but undetected) vertical overflow. + final bool hasVisualOverflow = didOverflowWidth || didOverflowHeight; + if (hasVisualOverflow) { + switch (_overflow) { + case TextOverflow.visible: + _needsClipping = false; + _overflowShader = null; + case TextOverflow.clip: + case TextOverflow.ellipsis: + _needsClipping = true; + _overflowShader = null; + case TextOverflow.fade: + _needsClipping = true; + final TextPainter fadeSizePainter = TextPainter( + text: TextSpan(style: _textPainter.text!.style, text: '\u2026'), + textDirection: textDirection, + textScaler: textScaler, + locale: locale, + )..layout(); + if (didOverflowWidth) { + double fadeEnd, fadeStart; + switch (textDirection) { + case TextDirection.rtl: + fadeEnd = 0.0; + fadeStart = fadeSizePainter.width; + case TextDirection.ltr: + fadeEnd = size.width; + fadeStart = fadeEnd - fadeSizePainter.width; + } + _overflowShader = ui.Gradient.linear( + Offset(fadeStart, 0.0), + Offset(fadeEnd, 0.0), + <Color>[const Color(0xFFFFFFFF), const Color(0x00FFFFFF)], + ); + } else { + final double fadeEnd = size.height; + final double fadeStart = fadeEnd - fadeSizePainter.height / 2.0; + _overflowShader = ui.Gradient.linear( + Offset(0.0, fadeStart), + Offset(0.0, fadeEnd), + <Color>[const Color(0xFFFFFFFF), const Color(0x00FFFFFF)], + ); + } + fadeSizePainter.dispose(); + } + } else { + _needsClipping = false; + _overflowShader = null; + } + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + defaultApplyPaintTransform(child, transform); + } + + @override + void paint(PaintingContext context, Offset offset) { + // Ideally we could compute the min/max intrinsic width/height with a + // non-destructive operation. However, currently, computing these values + // will destroy state inside the painter. If that happens, we need to get + // back the correct state by calling _layout again. + // + // TODO(abarth): Make computing the min/max intrinsic width/height a + // non-destructive operation. + // + // If you remove this call, make sure that changing the textAlign still + // works properly. + _layoutTextWithConstraints(constraints); + + assert(() { + if (debugRepaintTextRainbowEnabled) { + final Paint paint = Paint() + ..color = debugCurrentRepaintColor.toColor(); + context.canvas.drawRect(offset & size, paint); + } + return true; + }()); + + if (_needsClipping) { + final Rect bounds = offset & size; + if (_overflowShader != null) { + // This layer limits what the shader below blends with to be just the + // text (as opposed to the text and its background). + context.canvas.saveLayer(bounds, Paint()); + } else { + context.canvas.save(); + } + context.canvas.clipRect(bounds); + } + + if (_lastSelectableFragments != null) { + for (final _SelectableFragment fragment in _lastSelectableFragments!) { + fragment.paint(context, offset); + } + } + + _textPainter.paint(context.canvas, offset); + + paintInlineChildren(context, offset); + + if (_needsClipping) { + if (_overflowShader != null) { + context.canvas.translate(offset.dx, offset.dy); + final Paint paint = Paint() + ..blendMode = BlendMode.modulate + ..shader = _overflowShader; + context.canvas.drawRect(Offset.zero & size, paint); + } + context.canvas.restore(); + } + } + + /// Returns the offset at which to paint the caret. + /// + /// Valid only after [layout]. + Offset getOffsetForCaret(TextPosition position, Rect caretPrototype) { + assert(!debugNeedsLayout); + _layoutTextWithConstraints(constraints); + return _textPainter.getOffsetForCaret(position, caretPrototype); + } + + /// {@macro flutter.painting.textPainter.getFullHeightForCaret} + /// + /// Valid only after [layout]. + double? getFullHeightForCaret(TextPosition position) { + assert(!debugNeedsLayout); + _layoutTextWithConstraints(constraints); + return _textPainter.getFullHeightForCaret(position, Rect.zero); + } + + /// Returns a list of rects that bound the given selection. + /// + /// The [boxHeightStyle] and [boxWidthStyle] arguments may be used to select + /// the shape of the [TextBox]es. These properties default to + /// [ui.BoxHeightStyle.tight] and [ui.BoxWidthStyle.tight] respectively. + /// + /// A given selection might have more than one rect if the [RenderParagraph] + /// contains multiple [InlineSpan]s or bidirectional text, because logically + /// contiguous text might not be visually contiguous. + /// + /// Valid only after [layout]. + /// + /// See also: + /// + /// * [TextPainter.getBoxesForSelection], the method in TextPainter to get + /// the equivalent boxes. + List<ui.TextBox> getBoxesForSelection( + TextSelection selection, { + ui.BoxHeightStyle boxHeightStyle = ui.BoxHeightStyle.tight, + ui.BoxWidthStyle boxWidthStyle = ui.BoxWidthStyle.tight, + }) { + assert(!debugNeedsLayout); + _layoutTextWithConstraints(constraints); + return _textPainter.getBoxesForSelection( + selection, + boxHeightStyle: boxHeightStyle, + boxWidthStyle: boxWidthStyle, + ); + } + + /// Returns the position within the text for the given pixel offset. + /// + /// Valid only after [layout]. + TextPosition getPositionForOffset(Offset offset) { + assert(!debugNeedsLayout); + _layoutTextWithConstraints(constraints); + return _textPainter.getPositionForOffset(offset); + } + + /// Returns the text range of the word at the given offset. Characters not + /// part of a word, such as spaces, symbols, and punctuation, have word breaks + /// on both sides. In such cases, this method will return a text range that + /// contains the given text position. + /// + /// Word boundaries are defined more precisely in Unicode Standard Annex #29 + /// <http://www.unicode.org/reports/tr29/#Word_Boundaries>. + /// + /// Valid only after [layout]. + TextRange getWordBoundary(TextPosition position) { + assert(!debugNeedsLayout); + _layoutTextWithConstraints(constraints); + return _textPainter.getWordBoundary(position); + } + + TextRange _getLineAtOffset(TextPosition position) => _textPainter.getLineBoundary(position); + + TextPosition _getTextPositionAbove(TextPosition position) { + // -0.5 of preferredLineHeight points to the middle of the line above. + final double preferredLineHeight = _textPainter.preferredLineHeight; + final double verticalOffset = -0.5 * preferredLineHeight; + return _getTextPositionVertical(position, verticalOffset); + } + + TextPosition _getTextPositionBelow(TextPosition position) { + // 1.5 of preferredLineHeight points to the middle of the line below. + final double preferredLineHeight = _textPainter.preferredLineHeight; + final double verticalOffset = 1.5 * preferredLineHeight; + return _getTextPositionVertical(position, verticalOffset); + } + + TextPosition _getTextPositionVertical(TextPosition position, double verticalOffset) { + final Offset caretOffset = _textPainter.getOffsetForCaret(position, Rect.zero); + final Offset caretOffsetTranslated = caretOffset.translate(0.0, verticalOffset); + return _textPainter.getPositionForOffset(caretOffsetTranslated); + } + + /// Returns the size of the text as laid out. + /// + /// This can differ from [size] if the text overflowed or if the [constraints] + /// provided by the parent [RenderObject] forced the layout to be bigger than + /// necessary for the given [text]. + /// + /// This returns the [TextPainter.size] of the underlying [TextPainter]. + /// + /// Valid only after [layout]. + Size get textSize { + assert(!debugNeedsLayout); + return _textPainter.size; + } + + /// Whether the text was truncated or ellipsized as laid out. + /// + /// This returns the [TextPainter.didExceedMaxLines] of the underlying [TextPainter]. + /// + /// Valid only after [layout]. + bool get didExceedMaxLines { + assert(!debugNeedsLayout); + return _textPainter.didExceedMaxLines; + } + + /// Collected during [describeSemanticsConfiguration], used by + /// [assembleSemanticsNode] and [_combineSemanticsInfo]. + List<InlineSpanSemanticsInformation>? _semanticsInfo; + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + _semanticsInfo = text.getSemanticsInformation(); + bool needsAssembleSemanticsNode = false; + bool needsChildConfigrationsDelegate = false; + for (final InlineSpanSemanticsInformation info in _semanticsInfo!) { + if (info.recognizer != null) { + needsAssembleSemanticsNode = true; + break; + } + needsChildConfigrationsDelegate = needsChildConfigrationsDelegate || info.isPlaceholder; + } + + if (needsAssembleSemanticsNode) { + config.explicitChildNodes = true; + config.isSemanticBoundary = true; + } else if (needsChildConfigrationsDelegate) { + config.childConfigurationsDelegate = _childSemanticsConfigurationsDelegate; + } else { + if (_cachedAttributedLabels == null) { + final StringBuffer buffer = StringBuffer(); + int offset = 0; + final List<StringAttribute> attributes = <StringAttribute>[]; + for (final InlineSpanSemanticsInformation info in _semanticsInfo!) { + final String label = info.semanticsLabel ?? info.text; + for (final StringAttribute infoAttribute in info.stringAttributes) { + final TextRange originalRange = infoAttribute.range; + attributes.add( + infoAttribute.copy( + range: TextRange( + start: offset + originalRange.start, + end: offset + originalRange.end, + ), + ), + ); + } + buffer.write(label); + offset += label.length; + } + _cachedAttributedLabels = <AttributedString>[AttributedString(buffer.toString(), attributes: attributes)]; + } + config.attributedLabel = _cachedAttributedLabels![0]; + config.textDirection = textDirection; + } + } + + ChildSemanticsConfigurationsResult _childSemanticsConfigurationsDelegate(List<SemanticsConfiguration> childConfigs) { + final ChildSemanticsConfigurationsResultBuilder builder = ChildSemanticsConfigurationsResultBuilder(); + int placeholderIndex = 0; + int childConfigsIndex = 0; + int attributedLabelCacheIndex = 0; + InlineSpanSemanticsInformation? seenTextInfo; + _cachedCombinedSemanticsInfos ??= combineSemanticsInfo(_semanticsInfo!); + for (final InlineSpanSemanticsInformation info in _cachedCombinedSemanticsInfos!) { + if (info.isPlaceholder) { + if (seenTextInfo != null) { + builder.markAsMergeUp(_createSemanticsConfigForTextInfo(seenTextInfo, attributedLabelCacheIndex)); + attributedLabelCacheIndex += 1; + } + // Mark every childConfig belongs to this placeholder to merge up group. + while (childConfigsIndex < childConfigs.length && + childConfigs[childConfigsIndex].tagsChildrenWith(PlaceholderSpanIndexSemanticsTag(placeholderIndex))) { + builder.markAsMergeUp(childConfigs[childConfigsIndex]); + childConfigsIndex += 1; + } + placeholderIndex += 1; + } else { + seenTextInfo = info; + } + } + + // Handle plain text info at the end. + if (seenTextInfo != null) { + builder.markAsMergeUp(_createSemanticsConfigForTextInfo(seenTextInfo, attributedLabelCacheIndex)); + } + return builder.build(); + } + + SemanticsConfiguration _createSemanticsConfigForTextInfo(InlineSpanSemanticsInformation textInfo, int cacheIndex) { + assert(!textInfo.requiresOwnNode); + final List<AttributedString> cachedStrings = _cachedAttributedLabels ??= <AttributedString>[]; + assert(cacheIndex <= cachedStrings.length); + final bool hasCache = cacheIndex < cachedStrings.length; + + late AttributedString attributedLabel; + if (hasCache) { + attributedLabel = cachedStrings[cacheIndex]; + } else { + assert(cachedStrings.length == cacheIndex); + attributedLabel = AttributedString( + textInfo.semanticsLabel ?? textInfo.text, + attributes: textInfo.stringAttributes, + ); + cachedStrings.add(attributedLabel); + } + return SemanticsConfiguration() + ..textDirection = textDirection + ..attributedLabel = attributedLabel; + } + + // Caches [SemanticsNode]s created during [assembleSemanticsNode] so they + // can be re-used when [assembleSemanticsNode] is called again. This ensures + // stable ids for the [SemanticsNode]s of [TextSpan]s across + // [assembleSemanticsNode] invocations. + LinkedHashMap<Key, SemanticsNode>? _cachedChildNodes; + + @override + void assembleSemanticsNode(SemanticsNode node, SemanticsConfiguration config, Iterable<SemanticsNode> children) { + assert(_semanticsInfo != null && _semanticsInfo!.isNotEmpty); + final List<SemanticsNode> newChildren = <SemanticsNode>[]; + TextDirection currentDirection = textDirection; + Rect currentRect; + double ordinal = 0.0; + int start = 0; + int placeholderIndex = 0; + int childIndex = 0; + RenderBox? child = firstChild; + final LinkedHashMap<Key, SemanticsNode> newChildCache = LinkedHashMap<Key, SemanticsNode>(); + _cachedCombinedSemanticsInfos ??= combineSemanticsInfo(_semanticsInfo!); + for (final InlineSpanSemanticsInformation info in _cachedCombinedSemanticsInfos!) { + final TextSelection selection = TextSelection( + baseOffset: start, + extentOffset: start + info.text.length, + ); + start += info.text.length; + + if (info.isPlaceholder) { + // A placeholder span may have 0 to multiple semantics nodes, we need + // to annotate all of the semantics nodes belong to this span. + while (children.length > childIndex && + children.elementAt(childIndex).isTagged(PlaceholderSpanIndexSemanticsTag(placeholderIndex))) { + final SemanticsNode childNode = children.elementAt(childIndex); + final TextParentData parentData = child!.parentData! as TextParentData; + // parentData.scale may be null if the render object is truncated. + if (parentData.offset != null) { + newChildren.add(childNode); + } + childIndex += 1; + } + child = childAfter(child!); + placeholderIndex += 1; + } else { + final TextDirection initialDirection = currentDirection; + final List<ui.TextBox> rects = getBoxesForSelection(selection); + if (rects.isEmpty) { + continue; + } + Rect rect = rects.first.toRect(); + currentDirection = rects.first.direction; + for (final ui.TextBox textBox in rects.skip(1)) { + rect = rect.expandToInclude(textBox.toRect()); + currentDirection = textBox.direction; + } + // Any of the text boxes may have had infinite dimensions. + // We shouldn't pass infinite dimensions up to the bridges. + rect = Rect.fromLTWH( + math.max(0.0, rect.left), + math.max(0.0, rect.top), + math.min(rect.width, constraints.maxWidth), + math.min(rect.height, constraints.maxHeight), + ); + // round the current rectangle to make this API testable and add some + // padding so that the accessibility rects do not overlap with the text. + currentRect = Rect.fromLTRB( + rect.left.floorToDouble() - 4.0, + rect.top.floorToDouble() - 4.0, + rect.right.ceilToDouble() + 4.0, + rect.bottom.ceilToDouble() + 4.0, + ); + final SemanticsConfiguration configuration = SemanticsConfiguration() + ..sortKey = OrdinalSortKey(ordinal++) + ..textDirection = initialDirection + ..attributedLabel = AttributedString(info.semanticsLabel ?? info.text, attributes: info.stringAttributes); + final GestureRecognizer? recognizer = info.recognizer; + if (recognizer != null) { + if (recognizer is TapGestureRecognizer) { + if (recognizer.onTap != null) { + configuration.onTap = recognizer.onTap; + configuration.isLink = true; + } + } else if (recognizer is DoubleTapGestureRecognizer) { + if (recognizer.onDoubleTap != null) { + configuration.onTap = recognizer.onDoubleTap; + configuration.isLink = true; + } + } else if (recognizer is LongPressGestureRecognizer) { + if (recognizer.onLongPress != null) { + configuration.onLongPress = recognizer.onLongPress; + } + } else { + assert(false, '${recognizer.runtimeType} is not supported.'); + } + } + if (node.parentPaintClipRect != null) { + final Rect paintRect = node.parentPaintClipRect!.intersect(currentRect); + configuration.isHidden = paintRect.isEmpty && !currentRect.isEmpty; + } + final SemanticsNode newChild; + if (_cachedChildNodes?.isNotEmpty ?? false) { + newChild = _cachedChildNodes!.remove(_cachedChildNodes!.keys.first)!; + } else { + final UniqueKey key = UniqueKey(); + newChild = SemanticsNode( + key: key, + showOnScreen: _createShowOnScreenFor(key), + ); + } + newChild + ..updateWith(config: configuration) + ..rect = currentRect; + newChildCache[newChild.key!] = newChild; + newChildren.add(newChild); + } + } + // Makes sure we annotated all of the semantics children. + assert(childIndex == children.length); + assert(child == null); + + _cachedChildNodes = newChildCache; + node.updateWith(config: config, childrenInInversePaintOrder: newChildren); + } + + VoidCallback? _createShowOnScreenFor(Key key) { + return () { + final SemanticsNode node = _cachedChildNodes![key]!; + showOnScreen(descendant: this, rect: node.rect); + }; + } + + @override + void clearSemantics() { + super.clearSemantics(); + _cachedChildNodes = null; + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return <DiagnosticsNode>[ + text.toDiagnosticsNode( + name: 'text', + style: DiagnosticsTreeStyle.transition, + ), + ]; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<TextAlign>('textAlign', textAlign)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection)); + properties.add( + FlagProperty( + 'softWrap', + value: softWrap, + ifTrue: 'wrapping at box width', + ifFalse: 'no wrapping except at line break characters', + showName: true, + ), + ); + properties.add(EnumProperty<TextOverflow>('overflow', overflow)); + properties.add( + DiagnosticsProperty<TextScaler>('textScaler', textScaler, defaultValue: TextScaler.noScaling), + ); + properties.add( + DiagnosticsProperty<Locale>( + 'locale', + locale, + defaultValue: null, + ), + ); + properties.add(IntProperty('maxLines', maxLines, ifNull: 'unlimited')); + } +} + +/// A continuous, selectable piece of paragraph. +/// +/// Since the selections in [PlaceholderSpan] are handled independently in its +/// subtree, a selection in [RenderParagraph] can't continue across a +/// [PlaceholderSpan]. The [RenderParagraph] splits itself on [PlaceholderSpan] +/// to create multiple `_SelectableFragment`s so that they can be selected +/// separately. +class _SelectableFragment with Selectable, Diagnosticable, ChangeNotifier implements TextLayoutMetrics { + _SelectableFragment({ + required this.paragraph, + required this.fullText, + required this.range, + }) : assert(range.isValid && !range.isCollapsed && range.isNormalized) { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + _selectionGeometry = _getSelectionGeometry(); + } + + final TextRange range; + final RenderParagraph paragraph; + final String fullText; + + TextPosition? _textSelectionStart; + TextPosition? _textSelectionEnd; + + bool _selectableContainsOriginWord = false; + + LayerLink? _startHandleLayerLink; + LayerLink? _endHandleLayerLink; + + @override + SelectionGeometry get value => _selectionGeometry; + late SelectionGeometry _selectionGeometry; + void _updateSelectionGeometry() { + final SelectionGeometry newValue = _getSelectionGeometry(); + if (_selectionGeometry == newValue) { + return; + } + _selectionGeometry = newValue; + notifyListeners(); + } + + SelectionGeometry _getSelectionGeometry() { + if (_textSelectionStart == null || _textSelectionEnd == null) { + return const SelectionGeometry( + status: SelectionStatus.none, + hasContent: true, + ); + } + + final int selectionStart = _textSelectionStart!.offset; + final int selectionEnd = _textSelectionEnd!.offset; + final bool isReversed = selectionStart > selectionEnd; + final Offset startOffsetInParagraphCoordinates = paragraph._getOffsetForPosition(TextPosition(offset: selectionStart)); + final Offset endOffsetInParagraphCoordinates = selectionStart == selectionEnd + ? startOffsetInParagraphCoordinates + : paragraph._getOffsetForPosition(TextPosition(offset: selectionEnd)); + final bool flipHandles = isReversed != (TextDirection.rtl == paragraph.textDirection); + final TextSelection selection = TextSelection( + baseOffset: selectionStart, + extentOffset: selectionEnd, + ); + final List<Rect> selectionRects = <Rect>[]; + for (final TextBox textBox in paragraph.getBoxesForSelection(selection)) { + selectionRects.add(textBox.toRect()); + } + return SelectionGeometry( + startSelectionPoint: SelectionPoint( + localPosition: startOffsetInParagraphCoordinates, + lineHeight: paragraph._textPainter.preferredLineHeight, + handleType: flipHandles ? TextSelectionHandleType.right : TextSelectionHandleType.left + ), + endSelectionPoint: SelectionPoint( + localPosition: endOffsetInParagraphCoordinates, + lineHeight: paragraph._textPainter.preferredLineHeight, + handleType: flipHandles ? TextSelectionHandleType.left : TextSelectionHandleType.right, + ), + selectionRects: selectionRects, + status: _textSelectionStart!.offset == _textSelectionEnd!.offset + ? SelectionStatus.collapsed + : SelectionStatus.uncollapsed, + hasContent: true, + ); + } + + @override + SelectionResult dispatchSelectionEvent(SelectionEvent event) { + late final SelectionResult result; + final TextPosition? existingSelectionStart = _textSelectionStart; + final TextPosition? existingSelectionEnd = _textSelectionEnd; + switch (event.type) { + case SelectionEventType.startEdgeUpdate: + case SelectionEventType.endEdgeUpdate: + final SelectionEdgeUpdateEvent edgeUpdate = event as SelectionEdgeUpdateEvent; + final TextGranularity granularity = event.granularity; + + switch (granularity) { + case TextGranularity.character: + result = _updateSelectionEdge(edgeUpdate.globalPosition, isEnd: edgeUpdate.type == SelectionEventType.endEdgeUpdate); + case TextGranularity.word: + result = _updateSelectionEdgeByWord(edgeUpdate.globalPosition, isEnd: edgeUpdate.type == SelectionEventType.endEdgeUpdate); + case TextGranularity.document: + case TextGranularity.line: + assert(false, 'Moving the selection edge by line or document is not supported.'); + } + case SelectionEventType.clear: + result = _handleClearSelection(); + case SelectionEventType.selectAll: + result = _handleSelectAll(); + case SelectionEventType.selectWord: + final SelectWordSelectionEvent selectWord = event as SelectWordSelectionEvent; + result = _handleSelectWord(selectWord.globalPosition); + case SelectionEventType.granularlyExtendSelection: + final GranularlyExtendSelectionEvent granularlyExtendSelection = event as GranularlyExtendSelectionEvent; + result = _handleGranularlyExtendSelection( + granularlyExtendSelection.forward, + granularlyExtendSelection.isEnd, + granularlyExtendSelection.granularity, + ); + case SelectionEventType.directionallyExtendSelection: + final DirectionallyExtendSelectionEvent directionallyExtendSelection = event as DirectionallyExtendSelectionEvent; + result = _handleDirectionallyExtendSelection( + directionallyExtendSelection.dx, + directionallyExtendSelection.isEnd, + directionallyExtendSelection.direction, + ); + } + + if (existingSelectionStart != _textSelectionStart || + existingSelectionEnd != _textSelectionEnd) { + _didChangeSelection(); + } + return result; + } + + @override + SelectedContent? getSelectedContent() { + if (_textSelectionStart == null || _textSelectionEnd == null) { + return null; + } + final int start = math.min(_textSelectionStart!.offset, _textSelectionEnd!.offset); + final int end = math.max(_textSelectionStart!.offset, _textSelectionEnd!.offset); + return SelectedContent( + plainText: fullText.substring(start, end), + ); + } + + void _didChangeSelection() { + paragraph.markNeedsPaint(); + _updateSelectionGeometry(); + } + + SelectionResult _updateSelectionEdge(Offset globalPosition, {required bool isEnd}) { + _setSelectionPosition(null, isEnd: isEnd); + final Matrix4 transform = paragraph.getTransformTo(null); + transform.invert(); + final Offset localPosition = MatrixUtils.transformPoint(transform, globalPosition); + if (_rect.isEmpty) { + return SelectionUtils.getResultBasedOnRect(_rect, localPosition); + } + final Offset adjustedOffset = SelectionUtils.adjustDragOffset( + _rect, + localPosition, + direction: paragraph.textDirection, + ); + + final TextPosition position = _clampTextPosition(paragraph.getPositionForOffset(adjustedOffset)); + _setSelectionPosition(position, isEnd: isEnd); + if (position.offset == range.end) { + return SelectionResult.next; + } + if (position.offset == range.start) { + return SelectionResult.previous; + } + // TODO(chunhtai): The geometry information should not be used to determine + // selection result. This is a workaround to RenderParagraph, where it does + // not have a way to get accurate text length if its text is truncated due to + // layout constraint. + return SelectionUtils.getResultBasedOnRect(_rect, localPosition); + } + + TextPosition _closestWordBoundary( + _WordBoundaryRecord wordBoundary, + TextPosition position, + ) { + final int differenceA = (position.offset - wordBoundary.wordStart.offset).abs(); + final int differenceB = (position.offset - wordBoundary.wordEnd.offset).abs(); + return differenceA < differenceB ? wordBoundary.wordStart : wordBoundary.wordEnd; + } + + TextPosition _updateSelectionStartEdgeByWord( + _WordBoundaryRecord? wordBoundary, + TextPosition position, + TextPosition? existingSelectionStart, + TextPosition? existingSelectionEnd, + ) { + TextPosition? targetPosition; + if (wordBoundary != null) { + assert(wordBoundary.wordStart.offset >= range.start && wordBoundary.wordEnd.offset <= range.end); + if (_selectableContainsOriginWord && existingSelectionStart != null && existingSelectionEnd != null) { + final bool isSamePosition = position.offset == existingSelectionEnd.offset; + final bool isSelectionInverted = existingSelectionStart.offset > existingSelectionEnd.offset; + final bool shouldSwapEdges = !isSamePosition && (isSelectionInverted != (position.offset > existingSelectionEnd.offset)); + if (shouldSwapEdges) { + if (position.offset < existingSelectionEnd.offset) { + targetPosition = wordBoundary.wordStart; + } else { + targetPosition = wordBoundary.wordEnd; + } + // When the selection is inverted by the new position it is necessary to + // swap the start edge (moving edge) with the end edge (static edge) to + // maintain the origin word within the selection. + final _WordBoundaryRecord localWordBoundary = _getWordBoundaryAtPosition(existingSelectionEnd); + assert(localWordBoundary.wordStart.offset >= range.start && localWordBoundary.wordEnd.offset <= range.end); + _setSelectionPosition(existingSelectionEnd.offset == localWordBoundary.wordStart.offset ? localWordBoundary.wordEnd : localWordBoundary.wordStart, isEnd: true); + } else { + if (position.offset < existingSelectionEnd.offset) { + targetPosition = wordBoundary.wordStart; + } else if (position.offset > existingSelectionEnd.offset) { + targetPosition = wordBoundary.wordEnd; + } else { + // Keep the origin word in bounds when position is at the static edge. + targetPosition = existingSelectionStart; + } + } + } else { + if (existingSelectionEnd != null) { + // If the end edge exists and the start edge is being moved, then the + // start edge is moved to encompass the entire word at the new position. + if (position.offset < existingSelectionEnd.offset) { + targetPosition = wordBoundary.wordStart; + } else { + targetPosition = wordBoundary.wordEnd; + } + } else { + // Move the start edge to the closest word boundary. + targetPosition = _closestWordBoundary(wordBoundary, position); + } + } + } else { + // The position is not contained within the current rect. The targetPosition + // will either be at the end or beginning of the current rect. See [SelectionUtils.adjustDragOffset] + // for a more in depth explanation on this adjustment. + if (_selectableContainsOriginWord && existingSelectionStart != null && existingSelectionEnd != null) { + // When the selection is inverted by the new position it is necessary to + // swap the start edge (moving edge) with the end edge (static edge) to + // maintain the origin word within the selection. + final bool isSamePosition = position.offset == existingSelectionEnd.offset; + final bool isSelectionInverted = existingSelectionStart.offset > existingSelectionEnd.offset; + final bool shouldSwapEdges = !isSamePosition && (isSelectionInverted != (position.offset > existingSelectionEnd.offset)); + + if (shouldSwapEdges) { + final _WordBoundaryRecord localWordBoundary = _getWordBoundaryAtPosition(existingSelectionEnd); + assert(localWordBoundary.wordStart.offset >= range.start && localWordBoundary.wordEnd.offset <= range.end); + _setSelectionPosition(isSelectionInverted ? localWordBoundary.wordEnd : localWordBoundary.wordStart, isEnd: true); + } + } + } + return targetPosition ?? position; + } + + TextPosition _updateSelectionEndEdgeByWord( + _WordBoundaryRecord? wordBoundary, + TextPosition position, + TextPosition? existingSelectionStart, + TextPosition? existingSelectionEnd, + ) { + TextPosition? targetPosition; + if (wordBoundary != null) { + assert(wordBoundary.wordStart.offset >= range.start && wordBoundary.wordEnd.offset <= range.end); + if (_selectableContainsOriginWord && existingSelectionStart != null && existingSelectionEnd != null) { + final bool isSamePosition = position.offset == existingSelectionStart.offset; + final bool isSelectionInverted = existingSelectionStart.offset > existingSelectionEnd.offset; + final bool shouldSwapEdges = !isSamePosition && (isSelectionInverted != (position.offset < existingSelectionStart.offset)); + if (shouldSwapEdges) { + if (position.offset < existingSelectionStart.offset) { + targetPosition = wordBoundary.wordStart; + } else { + targetPosition = wordBoundary.wordEnd; + } + // When the selection is inverted by the new position it is necessary to + // swap the end edge (moving edge) with the start edge (static edge) to + // maintain the origin word within the selection. + final _WordBoundaryRecord localWordBoundary = _getWordBoundaryAtPosition(existingSelectionStart); + assert(localWordBoundary.wordStart.offset >= range.start && localWordBoundary.wordEnd.offset <= range.end); + _setSelectionPosition(existingSelectionStart.offset == localWordBoundary.wordStart.offset ? localWordBoundary.wordEnd : localWordBoundary.wordStart, isEnd: false); + } else { + if (position.offset < existingSelectionStart.offset) { + targetPosition = wordBoundary.wordStart; + } else if (position.offset > existingSelectionStart.offset) { + targetPosition = wordBoundary.wordEnd; + } else { + // Keep the origin word in bounds when position is at the static edge. + targetPosition = existingSelectionEnd; + } + } + } else { + if (existingSelectionStart != null) { + // If the start edge exists and the end edge is being moved, then the + // end edge is moved to encompass the entire word at the new position. + if (position.offset < existingSelectionStart.offset) { + targetPosition = wordBoundary.wordStart; + } else { + targetPosition = wordBoundary.wordEnd; + } + } else { + // Move the end edge to the closest word boundary. + targetPosition = _closestWordBoundary(wordBoundary, position); + } + } + } else { + // The position is not contained within the current rect. The targetPosition + // will either be at the end or beginning of the current rect. See [SelectionUtils.adjustDragOffset] + // for a more in depth explanation on this adjustment. + if (_selectableContainsOriginWord && existingSelectionStart != null && existingSelectionEnd != null) { + // When the selection is inverted by the new position it is necessary to + // swap the end edge (moving edge) with the start edge (static edge) to + // maintain the origin word within the selection. + final bool isSamePosition = position.offset == existingSelectionStart.offset; + final bool isSelectionInverted = existingSelectionStart.offset > existingSelectionEnd.offset; + final bool shouldSwapEdges = isSelectionInverted != (position.offset < existingSelectionStart.offset) || isSamePosition; + if (shouldSwapEdges) { + final _WordBoundaryRecord localWordBoundary = _getWordBoundaryAtPosition(existingSelectionStart); + assert(localWordBoundary.wordStart.offset >= range.start && localWordBoundary.wordEnd.offset <= range.end); + _setSelectionPosition(isSelectionInverted ? localWordBoundary.wordStart : localWordBoundary.wordEnd, isEnd: false); + } + } + } + return targetPosition ?? position; + } + + SelectionResult _updateSelectionEdgeByWord(Offset globalPosition, {required bool isEnd}) { + // When the start/end edges are swapped, i.e. the start is after the end, and + // the scrollable synthesizes an event for the opposite edge, this will potentially + // move the opposite edge outside of the origin word boundary and we are unable to recover. + final TextPosition? existingSelectionStart = _textSelectionStart; + final TextPosition? existingSelectionEnd = _textSelectionEnd; + + _setSelectionPosition(null, isEnd: isEnd); + final Matrix4 transform = paragraph.getTransformTo(null); + transform.invert(); + final Offset localPosition = MatrixUtils.transformPoint(transform, globalPosition); + if (_rect.isEmpty) { + return SelectionUtils.getResultBasedOnRect(_rect, localPosition); + } + final Offset adjustedOffset = SelectionUtils.adjustDragOffset( + _rect, + localPosition, + direction: paragraph.textDirection, + ); + + final TextPosition position = paragraph.getPositionForOffset(adjustedOffset); + // Check if the original local position is within the rect, if it is not then + // we do not need to look up the word boundary for that position. This is to + // maintain a selectables selection collapsed at 0 when the local position is + // not located inside its rect. + _WordBoundaryRecord? wordBoundary = _rect.contains(localPosition) ? _getWordBoundaryAtPosition(position) : null; + if (wordBoundary != null + && (wordBoundary.wordStart.offset < range.start && wordBoundary.wordEnd.offset <= range.start + || wordBoundary.wordStart.offset >= range.end && wordBoundary.wordEnd.offset > range.end)) { + // When the position is located at a placeholder inside of the text, then we may compute + // a word boundary that does not belong to the current selectable fragment. In this case + // we should invalidate the word boundary so that it is not taken into account when + // computing the target position. + wordBoundary = null; + } + final TextPosition targetPosition = _clampTextPosition(isEnd ? _updateSelectionEndEdgeByWord(wordBoundary, position, existingSelectionStart, existingSelectionEnd) : _updateSelectionStartEdgeByWord(wordBoundary, position, existingSelectionStart, existingSelectionEnd)); + + _setSelectionPosition(targetPosition, isEnd: isEnd); + if (targetPosition.offset == range.end) { + return SelectionResult.next; + } + + if (targetPosition.offset == range.start) { + return SelectionResult.previous; + } + // TODO(chunhtai): The geometry information should not be used to determine + // selection result. This is a workaround to RenderParagraph, where it does + // not have a way to get accurate text length if its text is truncated due to + // layout constraint. + return SelectionUtils.getResultBasedOnRect(_rect, localPosition); + } + + TextPosition _clampTextPosition(TextPosition position) { + // Affinity of range.end is upstream. + if (position.offset > range.end || + (position.offset == range.end && position.affinity == TextAffinity.downstream)) { + return TextPosition(offset: range.end, affinity: TextAffinity.upstream); + } + if (position.offset < range.start) { + return TextPosition(offset: range.start); + } + return position; + } + + void _setSelectionPosition(TextPosition? position, {required bool isEnd}) { + if (isEnd) { + _textSelectionEnd = position; + } else { + _textSelectionStart = position; + } + } + + SelectionResult _handleClearSelection() { + _textSelectionStart = null; + _textSelectionEnd = null; + _selectableContainsOriginWord = false; + return SelectionResult.none; + } + + SelectionResult _handleSelectAll() { + _textSelectionStart = TextPosition(offset: range.start); + _textSelectionEnd = TextPosition(offset: range.end, affinity: TextAffinity.upstream); + return SelectionResult.none; + } + + SelectionResult _handleSelectWord(Offset globalPosition) { + final TextPosition position = paragraph.getPositionForOffset(paragraph.globalToLocal(globalPosition)); + if (_positionIsWithinCurrentSelection(position) && _textSelectionStart != _textSelectionEnd) { + return SelectionResult.end; + } + final _WordBoundaryRecord wordBoundary = _getWordBoundaryAtPosition(position); + // This fragment may not contain the word, decide what direction the target + // fragment is located in. Because fragments are separated by placeholder + // spans, we also check if the beginning or end of the word is touching + // either edge of this fragment. + if (wordBoundary.wordStart.offset < range.start && wordBoundary.wordEnd.offset <= range.start) { + return SelectionResult.previous; + } else if (wordBoundary.wordStart.offset >= range.end && wordBoundary.wordEnd.offset > range.end) { + return SelectionResult.next; + } + // Fragments are separated by placeholder span, the word boundary shouldn't + // expand across fragments. + assert(wordBoundary.wordStart.offset >= range.start && wordBoundary.wordEnd.offset <= range.end); + _textSelectionStart = wordBoundary.wordStart; + _textSelectionEnd = wordBoundary.wordEnd; + _selectableContainsOriginWord = true; + return SelectionResult.end; + } + + _WordBoundaryRecord _getWordBoundaryAtPosition(TextPosition position) { + final TextRange word = paragraph.getWordBoundary(position); + assert(word.isNormalized); + late TextPosition start; + late TextPosition end; + if (position.offset > word.end) { + start = end = TextPosition(offset: position.offset); + } else { + start = TextPosition(offset: word.start); + end = TextPosition(offset: word.end, affinity: TextAffinity.upstream); + } + return (wordStart: start, wordEnd: end); + } + + SelectionResult _handleDirectionallyExtendSelection(double horizontalBaseline, bool isExtent, SelectionExtendDirection movement) { + final Matrix4 transform = paragraph.getTransformTo(null); + if (transform.invert() == 0.0) { + switch (movement) { + case SelectionExtendDirection.previousLine: + case SelectionExtendDirection.backward: + return SelectionResult.previous; + case SelectionExtendDirection.nextLine: + case SelectionExtendDirection.forward: + return SelectionResult.next; + } + } + final double baselineInParagraphCoordinates = MatrixUtils.transformPoint(transform, Offset(horizontalBaseline, 0)).dx; + assert(!baselineInParagraphCoordinates.isNaN); + final TextPosition newPosition; + final SelectionResult result; + switch (movement) { + case SelectionExtendDirection.previousLine: + case SelectionExtendDirection.nextLine: + assert(_textSelectionEnd != null && _textSelectionStart != null); + final TextPosition targetedEdge = isExtent ? _textSelectionEnd! : _textSelectionStart!; + final MapEntry<TextPosition, SelectionResult> moveResult = _handleVerticalMovement( + targetedEdge, + horizontalBaselineInParagraphCoordinates: baselineInParagraphCoordinates, + below: movement == SelectionExtendDirection.nextLine, + ); + newPosition = moveResult.key; + result = moveResult.value; + case SelectionExtendDirection.forward: + case SelectionExtendDirection.backward: + _textSelectionEnd ??= movement == SelectionExtendDirection.forward + ? TextPosition(offset: range.start) + : TextPosition(offset: range.end, affinity: TextAffinity.upstream); + _textSelectionStart ??= _textSelectionEnd; + final TextPosition targetedEdge = isExtent ? _textSelectionEnd! : _textSelectionStart!; + final Offset edgeOffsetInParagraphCoordinates = paragraph._getOffsetForPosition(targetedEdge); + final Offset baselineOffsetInParagraphCoordinates = Offset( + baselineInParagraphCoordinates, + // Use half of line height to point to the middle of the line. + edgeOffsetInParagraphCoordinates.dy - paragraph._textPainter.preferredLineHeight / 2, + ); + newPosition = paragraph.getPositionForOffset(baselineOffsetInParagraphCoordinates); + result = SelectionResult.end; + } + if (isExtent) { + _textSelectionEnd = newPosition; + } else { + _textSelectionStart = newPosition; + } + return result; + } + + SelectionResult _handleGranularlyExtendSelection(bool forward, bool isExtent, TextGranularity granularity) { + _textSelectionEnd ??= forward + ? TextPosition(offset: range.start) + : TextPosition(offset: range.end, affinity: TextAffinity.upstream); + _textSelectionStart ??= _textSelectionEnd; + final TextPosition targetedEdge = isExtent ? _textSelectionEnd! : _textSelectionStart!; + if (forward && (targetedEdge.offset == range.end)) { + return SelectionResult.next; + } + if (!forward && (targetedEdge.offset == range.start)) { + return SelectionResult.previous; + } + final SelectionResult result; + final TextPosition newPosition; + switch (granularity) { + case TextGranularity.character: + final String text = range.textInside(fullText); + newPosition = _moveBeyondTextBoundaryAtDirection(targetedEdge, forward, CharacterBoundary(text)); + result = SelectionResult.end; + case TextGranularity.word: + final TextBoundary textBoundary = paragraph._textPainter.wordBoundaries.moveByWordBoundary; + newPosition = _moveBeyondTextBoundaryAtDirection(targetedEdge, forward, textBoundary); + result = SelectionResult.end; + case TextGranularity.line: + newPosition = _moveToTextBoundaryAtDirection(targetedEdge, forward, LineBoundary(this)); + result = SelectionResult.end; + case TextGranularity.document: + final String text = range.textInside(fullText); + newPosition = _moveBeyondTextBoundaryAtDirection(targetedEdge, forward, DocumentBoundary(text)); + if (forward && newPosition.offset == range.end) { + result = SelectionResult.next; + } else if (!forward && newPosition.offset == range.start) { + result = SelectionResult.previous; + } else { + result = SelectionResult.end; + } + } + + if (isExtent) { + _textSelectionEnd = newPosition; + } else { + _textSelectionStart = newPosition; + } + return result; + } + + // Move **beyond** the local boundary of the given type (unless range.start or + // range.end is reached). Used for most TextGranularity types except for + // TextGranularity.line, to ensure the selection movement doesn't get stuck at + // a local fixed point. + TextPosition _moveBeyondTextBoundaryAtDirection(TextPosition end, bool forward, TextBoundary textBoundary) { + final int newOffset = forward + ? textBoundary.getTrailingTextBoundaryAt(end.offset) ?? range.end + : textBoundary.getLeadingTextBoundaryAt(end.offset - 1) ?? range.start; + return TextPosition(offset: newOffset); + } + + // Move **to** the local boundary of the given type. Typically used for line + // boundaries, such that performing "move to line start" more than once never + // moves the selection to the previous line. + TextPosition _moveToTextBoundaryAtDirection(TextPosition end, bool forward, TextBoundary textBoundary) { + assert(end.offset >= 0); + final int caretOffset; + switch (end.affinity) { + case TextAffinity.upstream: + if (end.offset < 1 && !forward) { + assert (end.offset == 0); + return const TextPosition(offset: 0); + } + final CharacterBoundary characterBoundary = CharacterBoundary(fullText); + caretOffset = math.max( + 0, + characterBoundary.getLeadingTextBoundaryAt(range.start + end.offset) ?? range.start, + ) - 1; + case TextAffinity.downstream: + caretOffset = end.offset; + } + final int offset = forward + ? textBoundary.getTrailingTextBoundaryAt(caretOffset) ?? range.end + : textBoundary.getLeadingTextBoundaryAt(caretOffset) ?? range.start; + return TextPosition(offset: offset); + } + + MapEntry<TextPosition, SelectionResult> _handleVerticalMovement(TextPosition position, {required double horizontalBaselineInParagraphCoordinates, required bool below}) { + final List<ui.LineMetrics> lines = paragraph._computeLineMetrics(); + final Offset offset = paragraph.getOffsetForCaret(position, Rect.zero); + int currentLine = lines.length - 1; + for (final ui.LineMetrics lineMetrics in lines) { + if (lineMetrics.baseline > offset.dy) { + currentLine = lineMetrics.lineNumber; + break; + } + } + final TextPosition newPosition; + if (below && currentLine == lines.length - 1) { + newPosition = TextPosition(offset: range.end, affinity: TextAffinity.upstream); + } else if (!below && currentLine == 0) { + newPosition = TextPosition(offset: range.start); + } else { + final int newLine = below ? currentLine + 1 : currentLine - 1; + newPosition = _clampTextPosition( + paragraph.getPositionForOffset(Offset(horizontalBaselineInParagraphCoordinates, lines[newLine].baseline)) + ); + } + final SelectionResult result; + if (newPosition.offset == range.start) { + result = SelectionResult.previous; + } else if (newPosition.offset == range.end) { + result = SelectionResult.next; + } else { + result = SelectionResult.end; + } + assert(result != SelectionResult.next || below); + assert(result != SelectionResult.previous || !below); + return MapEntry<TextPosition, SelectionResult>(newPosition, result); + } + + /// Whether the given text position is contained in current selection + /// range. + /// + /// The parameter `start` must be smaller than `end`. + bool _positionIsWithinCurrentSelection(TextPosition position) { + if (_textSelectionStart == null || _textSelectionEnd == null) { + return false; + } + // Normalize current selection. + late TextPosition currentStart; + late TextPosition currentEnd; + if (_compareTextPositions(_textSelectionStart!, _textSelectionEnd!) > 0) { + currentStart = _textSelectionStart!; + currentEnd = _textSelectionEnd!; + } else { + currentStart = _textSelectionEnd!; + currentEnd = _textSelectionStart!; + } + return _compareTextPositions(currentStart, position) >= 0 && _compareTextPositions(currentEnd, position) <= 0; + } + + /// Compares two text positions. + /// + /// Returns 1 if `position` < `otherPosition`, -1 if `position` > `otherPosition`, + /// or 0 if they are equal. + static int _compareTextPositions(TextPosition position, TextPosition otherPosition) { + if (position.offset < otherPosition.offset) { + return 1; + } else if (position.offset > otherPosition.offset) { + return -1; + } else if (position.affinity == otherPosition.affinity){ + return 0; + } else { + return position.affinity == TextAffinity.upstream ? 1 : -1; + } + } + + @override + Matrix4 getTransformTo(RenderObject? ancestor) { + return paragraph.getTransformTo(ancestor); + } + + @override + void pushHandleLayers(LayerLink? startHandle, LayerLink? endHandle) { + if (!paragraph.attached) { + assert(startHandle == null && endHandle == null, 'Only clean up can be called.'); + return; + } + if (_startHandleLayerLink != startHandle) { + _startHandleLayerLink = startHandle; + paragraph.markNeedsPaint(); + } + if (_endHandleLayerLink != endHandle) { + _endHandleLayerLink = endHandle; + paragraph.markNeedsPaint(); + } + } + + List<Rect>? _cachedBoundingBoxes; + @override + List<Rect> get boundingBoxes { + if (_cachedBoundingBoxes == null) { + final List<TextBox> boxes = paragraph.getBoxesForSelection( + TextSelection(baseOffset: range.start, extentOffset: range.end), + ); + if (boxes.isNotEmpty) { + _cachedBoundingBoxes = <Rect>[]; + for (final TextBox textBox in boxes) { + _cachedBoundingBoxes!.add(textBox.toRect()); + } + } else { + final Offset offset = paragraph._getOffsetForPosition(TextPosition(offset: range.start)); + final Rect rect = Rect.fromPoints(offset, offset.translate(0, - paragraph._textPainter.preferredLineHeight)); + _cachedBoundingBoxes = <Rect>[rect]; + } + } + return _cachedBoundingBoxes!; + } + + Rect? _cachedRect; + Rect get _rect { + if (_cachedRect == null) { + final List<TextBox> boxes = paragraph.getBoxesForSelection( + TextSelection(baseOffset: range.start, extentOffset: range.end), + ); + if (boxes.isNotEmpty) { + Rect result = boxes.first.toRect(); + for (int index = 1; index < boxes.length; index += 1) { + result = result.expandToInclude(boxes[index].toRect()); + } + _cachedRect = result; + } else { + final Offset offset = paragraph._getOffsetForPosition(TextPosition(offset: range.start)); + _cachedRect = Rect.fromPoints(offset, offset.translate(0, - paragraph._textPainter.preferredLineHeight)); + } + } + return _cachedRect!; + } + + void didChangeParagraphLayout() { + _cachedRect = null; + } + + @override + Size get size { + return _rect.size; + } + + void paint(PaintingContext context, Offset offset) { + if (_textSelectionStart == null || _textSelectionEnd == null) { + return; + } + if (paragraph.selectionColor != null) { + final TextSelection selection = TextSelection( + baseOffset: _textSelectionStart!.offset, + extentOffset: _textSelectionEnd!.offset, + ); + final Paint selectionPaint = Paint() + ..style = PaintingStyle.fill + ..color = paragraph.selectionColor!; + for (final TextBox textBox in paragraph.getBoxesForSelection(selection)) { + context.canvas.drawRect( + textBox.toRect().shift(offset), selectionPaint); + } + } + if (_startHandleLayerLink != null && value.startSelectionPoint != null) { + context.pushLayer( + LeaderLayer( + link: _startHandleLayerLink!, + offset: offset + value.startSelectionPoint!.localPosition, + ), + (PaintingContext context, Offset offset) { }, + Offset.zero, + ); + } + if (_endHandleLayerLink != null && value.endSelectionPoint != null) { + context.pushLayer( + LeaderLayer( + link: _endHandleLayerLink!, + offset: offset + value.endSelectionPoint!.localPosition, + ), + (PaintingContext context, Offset offset) { }, + Offset.zero, + ); + } + } + + @override + TextSelection getLineAtOffset(TextPosition position) { + final TextRange line = paragraph._getLineAtOffset(position); + final int start = line.start.clamp(range.start, range.end); + final int end = line.end.clamp(range.start, range.end); + return TextSelection(baseOffset: start, extentOffset: end); + } + + @override + TextPosition getTextPositionAbove(TextPosition position) { + return _clampTextPosition(paragraph._getTextPositionAbove(position)); + } + + @override + TextPosition getTextPositionBelow(TextPosition position) { + return _clampTextPosition(paragraph._getTextPositionBelow(position)); + } + + @override + TextRange getWordBoundary(TextPosition position) => paragraph.getWordBoundary(position); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('textInsideRange', range.textInside(fullText))); + properties.add(DiagnosticsProperty<TextRange>('range', range)); + properties.add(DiagnosticsProperty<String>('fullText', fullText)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/performance_overlay.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/performance_overlay.dart new file mode 100644 index 0000000000000000000000000000000000000000..380b22e77674e083c30aaeaa215feb3ad53792bd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/performance_overlay.dart @@ -0,0 +1,178 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'layer.dart'; +import 'object.dart'; + +/// The options that control whether the performance overlay displays certain +/// aspects of the compositor. +enum PerformanceOverlayOption { + // these must be in the order needed for their index values to match the + // constants in //engine/src/sky/compositor/performance_overlay_layer.h + + /// Display the frame time and FPS of the last frame rendered. This field is + /// updated every frame. + /// + /// This is the time spent by the rasterizer as it tries + /// to convert the layer tree obtained from the widgets into OpenGL commands + /// and tries to flush them onto the screen. When the total time taken by this + /// step exceeds the frame slice, a frame is lost. + displayRasterizerStatistics, + + /// Display the rasterizer frame times as they change over a set period of + /// time in the form of a graph. The y axis of the graph denotes the total + /// time spent by the rasterizer as a fraction of the total frame slice. When + /// the bar turns red, a frame is lost. + visualizeRasterizerStatistics, + + /// Display the frame time and FPS at which the interface can construct a + /// layer tree for the rasterizer (whose behavior is described above) to + /// consume. + /// + /// This involves all layout, animations, etc. When the total time taken by + /// this step exceeds the frame slice, a frame is lost. + displayEngineStatistics, + + /// Display the engine frame times as they change over a set period of time + /// in the form of a graph. The y axis of the graph denotes the total time + /// spent by the engine as a fraction of the total frame slice. When the bar + /// turns red, a frame is lost. + visualizeEngineStatistics, +} + +/// Displays performance statistics. +/// +/// The overlay shows two time series. The first shows how much time was +/// required on this thread to produce each frame. The second shows how much +/// time was required on the raster thread (formerly known as the GPU thread) +/// to produce each frame. Ideally, both these values would be less than +/// the total frame budget for the hardware on which the app is running. +/// For example, if the hardware has a screen that updates at 60 Hz, each +/// thread should ideally spend less than 16ms producing each frame. +/// This ideal condition is indicated by a green vertical line for each thread. +/// Otherwise, the performance overlay shows a red vertical line. +/// +/// The simplest way to show the performance overlay is to set +/// [MaterialApp.showPerformanceOverlay] or [WidgetsApp.showPerformanceOverlay] +/// to true. +class RenderPerformanceOverlay extends RenderBox { + /// Creates a performance overlay render object. + RenderPerformanceOverlay({ + int optionsMask = 0, + int rasterizerThreshold = 0, + bool checkerboardRasterCacheImages = false, + bool checkerboardOffscreenLayers = false, + }) : _optionsMask = optionsMask, + _rasterizerThreshold = rasterizerThreshold, + _checkerboardRasterCacheImages = checkerboardRasterCacheImages, + _checkerboardOffscreenLayers = checkerboardOffscreenLayers; + + /// The mask is created by shifting 1 by the index of the specific + /// [PerformanceOverlayOption] to enable. + int get optionsMask => _optionsMask; + int _optionsMask; + set optionsMask(int value) { + if (value == _optionsMask) { + return; + } + _optionsMask = value; + markNeedsPaint(); + } + + /// The rasterizer threshold is an integer specifying the number of frame + /// intervals that the rasterizer must miss before it decides that the frame + /// is suitable for capturing an SkPicture trace for further analysis. + int get rasterizerThreshold => _rasterizerThreshold; + int _rasterizerThreshold; + set rasterizerThreshold(int value) { + if (value == _rasterizerThreshold) { + return; + } + _rasterizerThreshold = value; + markNeedsPaint(); + } + + /// Whether the raster cache should checkerboard cached entries. + bool get checkerboardRasterCacheImages => _checkerboardRasterCacheImages; + bool _checkerboardRasterCacheImages; + set checkerboardRasterCacheImages(bool value) { + if (value == _checkerboardRasterCacheImages) { + return; + } + _checkerboardRasterCacheImages = value; + markNeedsPaint(); + } + + /// Whether the compositor should checkerboard layers rendered to offscreen bitmaps. + bool get checkerboardOffscreenLayers => _checkerboardOffscreenLayers; + bool _checkerboardOffscreenLayers; + set checkerboardOffscreenLayers(bool value) { + if (value == _checkerboardOffscreenLayers) { + return; + } + _checkerboardOffscreenLayers = value; + markNeedsPaint(); + } + + @override + bool get sizedByParent => true; + + @override + bool get alwaysNeedsCompositing => true; + + @override + double computeMinIntrinsicWidth(double height) { + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + return 0.0; + } + + double get _intrinsicHeight { + const double kDefaultGraphHeight = 80.0; + double result = 0.0; + if ((optionsMask | (1 << PerformanceOverlayOption.displayRasterizerStatistics.index) > 0) || + (optionsMask | (1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index) > 0)) { + result += kDefaultGraphHeight; + } + if ((optionsMask | (1 << PerformanceOverlayOption.displayEngineStatistics.index) > 0) || + (optionsMask | (1 << PerformanceOverlayOption.visualizeEngineStatistics.index) > 0)) { + result += kDefaultGraphHeight; + } + return result; + } + + @override + double computeMinIntrinsicHeight(double width) { + return _intrinsicHeight; + } + + @override + double computeMaxIntrinsicHeight(double width) { + return _intrinsicHeight; + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return constraints.constrain(Size(double.infinity, _intrinsicHeight)); + } + + @override + void paint(PaintingContext context, Offset offset) { + assert(needsCompositing); + context.addLayer(PerformanceOverlayLayer( + overlayRect: Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height), + optionsMask: optionsMask, + rasterizerThreshold: rasterizerThreshold, + checkerboardRasterCacheImages: checkerboardRasterCacheImages, + checkerboardOffscreenLayers: checkerboardOffscreenLayers, + )); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/platform_view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/platform_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..77866294bdbc5ad67b834e84b15fb106d62b8f13 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/platform_view.dart @@ -0,0 +1,825 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/semantics.dart'; +import 'package:flutter/services.dart'; + +import 'box.dart'; +import 'layer.dart'; +import 'object.dart'; + +/// How an embedded platform view behave during hit tests. +enum PlatformViewHitTestBehavior { + /// Opaque targets can be hit by hit tests, causing them to both receive + /// events within their bounds and prevent targets visually behind them from + /// also receiving events. + opaque, + + /// Translucent targets both receive events within their bounds and permit + /// targets visually behind them to also receive events. + translucent, + + /// Transparent targets don't receive events within their bounds and permit + /// targets visually behind them to receive events. + transparent, +} + +enum _PlatformViewState { + uninitialized, + resizing, + ready, +} + +bool _factoryTypesSetEquals<T>(Set<Factory<T>>? a, Set<Factory<T>>? b) { + if (a == b) { + return true; + } + if (a == null || b == null) { + return false; + } + return setEquals(_factoriesTypeSet(a), _factoriesTypeSet(b)); +} + +Set<Type> _factoriesTypeSet<T>(Set<Factory<T>> factories) { + return factories.map<Type>((Factory<T> factory) => factory.type).toSet(); +} + +/// A render object for an Android view. +/// +/// Requires Android API level 23 or greater. +/// +/// [RenderAndroidView] is responsible for sizing, displaying and passing touch events to an +/// Android [View](https://developer.android.com/reference/android/view/View). +/// +/// {@template flutter.rendering.RenderAndroidView.layout} +/// The render object's layout behavior is to fill all available space, the parent of this object must +/// provide bounded layout constraints. +/// {@endtemplate} +/// +/// {@template flutter.rendering.RenderAndroidView.gestures} +/// The render object participates in Flutter's gesture arenas, and dispatches touch events to the +/// platform view iff it won the arena. Specific gestures that should be dispatched to the platform +/// view can be specified with factories in the `gestureRecognizers` constructor parameter or +/// by calling `updateGestureRecognizers`. If the set of gesture recognizers is empty, the gesture +/// will be dispatched to the platform view iff it was not claimed by any other gesture recognizer. +/// {@endtemplate} +/// +/// See also: +/// +/// * [AndroidView] which is a widget that is used to show an Android view. +/// * [PlatformViewsService] which is a service for controlling platform views. +class RenderAndroidView extends PlatformViewRenderBox { + /// Creates a render object for an Android view. + RenderAndroidView({ + required AndroidViewController viewController, + required PlatformViewHitTestBehavior hitTestBehavior, + required Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers, + Clip clipBehavior = Clip.hardEdge, + }) : _viewController = viewController, + _clipBehavior = clipBehavior, + super(controller: viewController, hitTestBehavior: hitTestBehavior, gestureRecognizers: gestureRecognizers) { + _viewController.pointTransformer = (Offset offset) => globalToLocal(offset); + updateGestureRecognizers(gestureRecognizers); + _viewController.addOnPlatformViewCreatedListener(_onPlatformViewCreated); + this.hitTestBehavior = hitTestBehavior; + _setOffset(); + } + + _PlatformViewState _state = _PlatformViewState.uninitialized; + + Size? _currentTextureSize; + + bool _isDisposed = false; + + /// The Android view controller for the Android view associated with this render object. + @override + AndroidViewController get controller => _viewController; + + AndroidViewController _viewController; + + /// Sets a new Android view controller. + @override + set controller(AndroidViewController controller) { + assert(!_isDisposed); + if (_viewController == controller) { + return; + } + _viewController.removeOnPlatformViewCreatedListener(_onPlatformViewCreated); + super.controller = controller; + _viewController = controller; + _viewController.pointTransformer = (Offset offset) => globalToLocal(offset); + _sizePlatformView(); + if (_viewController.isCreated) { + markNeedsSemanticsUpdate(); + } + _viewController.addOnPlatformViewCreatedListener(_onPlatformViewCreated); + } + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.hardEdge; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + void _onPlatformViewCreated(int id) { + assert(!_isDisposed); + markNeedsSemanticsUpdate(); + } + + @override + bool get sizedByParent => true; + + @override + bool get alwaysNeedsCompositing => true; + + @override + bool get isRepaintBoundary => true; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return constraints.biggest; + } + + @override + void performResize() { + super.performResize(); + _sizePlatformView(); + } + + Future<void> _sizePlatformView() async { + // Android virtual displays cannot have a zero size. + // Trying to size it to 0 crashes the app, which was happening when starting the app + // with a locked screen (see: https://github.com/flutter/flutter/issues/20456). + if (_state == _PlatformViewState.resizing || size.isEmpty) { + return; + } + + _state = _PlatformViewState.resizing; + markNeedsPaint(); + + Size targetSize; + do { + targetSize = size; + _currentTextureSize = await _viewController.setSize(targetSize); + if (_isDisposed) { + return; + } + // We've resized the platform view to targetSize, but it is possible that + // while we were resizing the render object's size was changed again. + // In that case we will resize the platform view again. + } while (size != targetSize); + + _state = _PlatformViewState.ready; + markNeedsPaint(); + } + + // Sets the offset of the underlying platform view on the platform side. + // + // This allows the Android native view to draw the a11y highlights in the same + // location on the screen as the platform view widget in the Flutter framework. + // + // It also allows platform code to obtain the correct position of the Android + // native view on the screen. + void _setOffset() { + SchedulerBinding.instance.addPostFrameCallback((_) async { + if (!_isDisposed) { + if (attached) { + await _viewController.setOffset(localToGlobal(Offset.zero)); + } + // Schedule a new post frame callback. + _setOffset(); + } + }, debugLabel: 'RenderAndroidView.setOffset'); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (_viewController.textureId == null || _currentTextureSize == null) { + return; + } + + // As resizing the Android view happens asynchronously we don't know exactly when is a + // texture frame with the new size is ready for consumption. + // TextureLayer is unaware of the texture frame's size and always maps it to the + // specified rect. If the rect we provide has a different size from the current texture frame's + // size the texture frame will be scaled. + // To prevent unwanted scaling artifacts while resizing, clip the texture. + // This guarantees that the size of the texture frame we're painting is always + // _currentAndroidTextureSize. + final bool isTextureLargerThanWidget = _currentTextureSize!.width > size.width || + _currentTextureSize!.height > size.height; + if (isTextureLargerThanWidget && clipBehavior != Clip.none) { + _clipRectLayer.layer = context.pushClipRect( + true, + offset, + offset & size, + _paintTexture, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + return; + } + _clipRectLayer.layer = null; + _paintTexture(context, offset); + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void dispose() { + _isDisposed = true; + _clipRectLayer.layer = null; + _viewController.removeOnPlatformViewCreatedListener(_onPlatformViewCreated); + super.dispose(); + } + + void _paintTexture(PaintingContext context, Offset offset) { + if (_currentTextureSize == null) { + return; + } + + context.addLayer(TextureLayer( + rect: offset & _currentTextureSize!, + textureId: _viewController.textureId!, + )); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + // Don't call the super implementation since `platformViewId` should + // be set only when the platform view is created, but the concept of + // a "created" platform view belongs to this subclass. + config.isSemanticBoundary = true; + + if (_viewController.isCreated) { + config.platformViewId = _viewController.viewId; + } + } +} + +/// Common render-layer functionality for iOS and macOS platform views. +/// +/// Provides the basic rendering logic for iOS and macOS platformviews. +/// Subclasses shall override handleEvent in order to execute custom event logic. +/// T represents the class of the view controller for the corresponding widget. +abstract class RenderDarwinPlatformView<T extends DarwinPlatformViewController> extends RenderBox { + /// Creates a render object for a platform view. + RenderDarwinPlatformView({ + required T viewController, + required this.hitTestBehavior, + required Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers, + }) : _viewController = viewController { + updateGestureRecognizers(gestureRecognizers); + } + + + /// The unique identifier of the platform view controlled by this controller. + T get viewController => _viewController; + T _viewController; + set viewController(T value) { + if (_viewController == value) { + return; + } + final bool needsSemanticsUpdate = _viewController.id != value.id; + _viewController = value; + markNeedsPaint(); + if (needsSemanticsUpdate) { + markNeedsSemanticsUpdate(); + } + } + + /// How to behave during hit testing. + // The implicit setter is enough here as changing this value will just affect + // any newly arriving events there's nothing we need to invalidate. + PlatformViewHitTestBehavior hitTestBehavior; + + @override + bool get sizedByParent => true; + + @override + bool get alwaysNeedsCompositing => true; + + @override + bool get isRepaintBoundary => true; + + PointerEvent? _lastPointerDownEvent; + + _UiKitViewGestureRecognizer? _gestureRecognizer; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return constraints.biggest; + } + + @override + void paint(PaintingContext context, Offset offset) { + context.addLayer(PlatformViewLayer( + rect: offset & size, + viewId: _viewController.id, + )); + } + + @override + bool hitTest(BoxHitTestResult result, { Offset? position }) { + if (hitTestBehavior == PlatformViewHitTestBehavior.transparent || !size.contains(position!)) { + return false; + } + result.add(BoxHitTestEntry(this, position)); + return hitTestBehavior == PlatformViewHitTestBehavior.opaque; + } + + @override + bool hitTestSelf(Offset position) => hitTestBehavior != PlatformViewHitTestBehavior.transparent; + + // This is registered as a global PointerRoute while the render object is attached. + void _handleGlobalPointerEvent(PointerEvent event) { + if (event is! PointerDownEvent) { + return; + } + if (!(Offset.zero & size).contains(globalToLocal(event.position))) { + return; + } + if ((event.original ?? event) != _lastPointerDownEvent) { + // The pointer event is in the bounds of this render box, but we didn't get it in handleEvent. + // This means that the pointer event was absorbed by a different render object. + // Since on the platform side the FlutterTouchIntercepting view is seeing all events that are + // within its bounds we need to tell it to reject the current touch sequence. + _viewController.rejectGesture(); + } + _lastPointerDownEvent = null; + } + + @override + void describeSemanticsConfiguration (SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.isSemanticBoundary = true; + config.platformViewId = _viewController.id; + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + GestureBinding.instance.pointerRouter.addGlobalRoute(_handleGlobalPointerEvent); + } + + @override + void detach() { + GestureBinding.instance.pointerRouter.removeGlobalRoute(_handleGlobalPointerEvent); + super.detach(); + } + + /// {@macro flutter.rendering.PlatformViewRenderBox.updateGestureRecognizers} + void updateGestureRecognizers(Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers); +} + +/// A render object for an iOS UIKit UIView. +/// +/// [RenderUiKitView] is responsible for sizing and displaying an iOS +/// [UIView](https://developer.apple.com/documentation/uikit/uiview). +/// +/// UIViews are added as subviews of the FlutterView and are composited by Quartz. +/// +/// The viewController is typically generated by [PlatformViewsRegistry.getNextPlatformViewId], the UIView +/// must have been created by calling [PlatformViewsService.initUiKitView]. +/// +/// {@macro flutter.rendering.RenderAndroidView.layout} +/// +/// {@macro flutter.rendering.RenderAndroidView.gestures} +/// +/// See also: +/// +/// * [UiKitView], which is a widget that is used to show a UIView. +/// * [PlatformViewsService], which is a service for controlling platform views. +class RenderUiKitView extends RenderDarwinPlatformView<UiKitViewController> { + /// Creates a render object for an iOS UIView. + RenderUiKitView({ + required super.viewController, + required super.hitTestBehavior, + required super.gestureRecognizers, + }); + + /// {@macro flutter.rendering.PlatformViewRenderBox.updateGestureRecognizers} + @override + void updateGestureRecognizers(Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers) { + assert( + _factoriesTypeSet(gestureRecognizers).length == gestureRecognizers.length, + 'There were multiple gesture recognizer factories for the same type, there must only be a single ' + 'gesture recognizer factory for each gesture recognizer type.', + ); + if (_factoryTypesSetEquals(gestureRecognizers, _gestureRecognizer?.gestureRecognizerFactories)) { + return; + } + _gestureRecognizer?.dispose(); + _gestureRecognizer = _UiKitViewGestureRecognizer(viewController, gestureRecognizers); + } + + @override + void handleEvent(PointerEvent event, HitTestEntry entry) { + if (event is! PointerDownEvent) { + return; + } + _gestureRecognizer!.addPointer(event); + _lastPointerDownEvent = event.original ?? event; + } + + @override + void detach() { + _gestureRecognizer!.reset(); + super.detach(); + } + + @override + void dispose() { + _gestureRecognizer?.dispose(); + super.dispose(); + } +} + +/// A render object for a macOS platform view. +class RenderAppKitView extends RenderDarwinPlatformView<AppKitViewController> { + /// Creates a render object for a macOS AppKitView. + RenderAppKitView({ + required super.viewController, + required super.hitTestBehavior, + required super.gestureRecognizers, + }); + + // TODO(schectman): Add gesture functionality to macOS platform view when implemented. + // https://github.com/flutter/flutter/issues/128519 + // This method will need to behave the same as the same-named method for RenderUiKitView, + // but use a _AppKitViewGestureRecognizer or equivalent, whose constructor shall accept an + // AppKitViewController. + @override + void updateGestureRecognizers(Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers) {} +} + +// This recognizer constructs gesture recognizers from a set of gesture recognizer factories +// it was give, adds all of them to a gesture arena team with the _UiKitViewGestureRecognizer +// as the team captain. +// When the team wins a gesture the recognizer notifies the engine that it should release +// the touch sequence to the embedded UIView. +class _UiKitViewGestureRecognizer extends OneSequenceGestureRecognizer { + _UiKitViewGestureRecognizer( + this.controller, + this.gestureRecognizerFactories + ) { + team = GestureArenaTeam() + ..captain = this; + _gestureRecognizers = gestureRecognizerFactories.map( + (Factory<OneSequenceGestureRecognizer> recognizerFactory) { + final OneSequenceGestureRecognizer gestureRecognizer = recognizerFactory.constructor(); + gestureRecognizer.team = team; + // The below gesture recognizers requires at least one non-empty callback to + // compete in the gesture arena. + // https://github.com/flutter/flutter/issues/35394#issuecomment-562285087 + if (gestureRecognizer is LongPressGestureRecognizer) { + gestureRecognizer.onLongPress ??= (){}; + } else if (gestureRecognizer is DragGestureRecognizer) { + gestureRecognizer.onDown ??= (_){}; + } else if (gestureRecognizer is TapGestureRecognizer) { + gestureRecognizer.onTapDown ??= (_){}; + } + return gestureRecognizer; + }, + ).toSet(); + } + + // We use OneSequenceGestureRecognizers as they support gesture arena teams. + // TODO(amirh): get a list of GestureRecognizers here. + // https://github.com/flutter/flutter/issues/20953 + final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizerFactories; + late Set<OneSequenceGestureRecognizer> _gestureRecognizers; + + final UiKitViewController controller; + + @override + void addAllowedPointer(PointerDownEvent event) { + super.addAllowedPointer(event); + for (final OneSequenceGestureRecognizer recognizer in _gestureRecognizers) { + recognizer.addPointer(event); + } + } + + @override + String get debugDescription => 'UIKit view'; + + @override + void didStopTrackingLastPointer(int pointer) { } + + @override + void handleEvent(PointerEvent event) { + stopTrackingIfPointerNoLongerDown(event); + } + + @override + void acceptGesture(int pointer) { + controller.acceptGesture(); + } + + @override + void rejectGesture(int pointer) { + controller.rejectGesture(); + } + + void reset() { + resolve(GestureDisposition.rejected); + } +} + +typedef _HandlePointerEvent = Future<void> Function(PointerEvent event); + +// This recognizer constructs gesture recognizers from a set of gesture recognizer factories +// it was give, adds all of them to a gesture arena team with the _PlatformViewGestureRecognizer +// as the team captain. +// As long as the gesture arena is unresolved, the recognizer caches all pointer events. +// When the team wins, the recognizer sends all the cached pointer events to `_handlePointerEvent`, and +// sets itself to a "forwarding mode" where it will forward any new pointer event to `_handlePointerEvent`. +class _PlatformViewGestureRecognizer extends OneSequenceGestureRecognizer { + _PlatformViewGestureRecognizer( + _HandlePointerEvent handlePointerEvent, + this.gestureRecognizerFactories + ) { + team = GestureArenaTeam() + ..captain = this; + _gestureRecognizers = gestureRecognizerFactories.map( + (Factory<OneSequenceGestureRecognizer> recognizerFactory) { + final OneSequenceGestureRecognizer gestureRecognizer = recognizerFactory.constructor(); + gestureRecognizer.team = team; + // The below gesture recognizers requires at least one non-empty callback to + // compete in the gesture arena. + // https://github.com/flutter/flutter/issues/35394#issuecomment-562285087 + if (gestureRecognizer is LongPressGestureRecognizer) { + gestureRecognizer.onLongPress ??= (){}; + } else if (gestureRecognizer is DragGestureRecognizer) { + gestureRecognizer.onDown ??= (_){}; + } else if (gestureRecognizer is TapGestureRecognizer) { + gestureRecognizer.onTapDown ??= (_){}; + } + return gestureRecognizer; + }, + ).toSet(); + _handlePointerEvent = handlePointerEvent; + } + + late _HandlePointerEvent _handlePointerEvent; + + // Maps a pointer to a list of its cached pointer events. + // Before the arena for a pointer is resolved all events are cached here, if we win the arena + // the cached events are dispatched to `_handlePointerEvent`, if we lose the arena we clear the cache for + // the pointer. + final Map<int, List<PointerEvent>> cachedEvents = <int, List<PointerEvent>>{}; + + // Pointer for which we have already won the arena, events for pointers in this set are + // immediately dispatched to `_handlePointerEvent`. + final Set<int> forwardedPointers = <int>{}; + + // We use OneSequenceGestureRecognizers as they support gesture arena teams. + // TODO(amirh): get a list of GestureRecognizers here. + // https://github.com/flutter/flutter/issues/20953 + final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizerFactories; + late Set<OneSequenceGestureRecognizer> _gestureRecognizers; + + @override + void addAllowedPointer(PointerDownEvent event) { + super.addAllowedPointer(event); + for (final OneSequenceGestureRecognizer recognizer in _gestureRecognizers) { + recognizer.addPointer(event); + } + } + + @override + String get debugDescription => 'Platform view'; + + @override + void didStopTrackingLastPointer(int pointer) { } + + @override + void handleEvent(PointerEvent event) { + if (!forwardedPointers.contains(event.pointer)) { + _cacheEvent(event); + } else { + _handlePointerEvent(event); + } + stopTrackingIfPointerNoLongerDown(event); + } + + @override + void acceptGesture(int pointer) { + _flushPointerCache(pointer); + forwardedPointers.add(pointer); + } + + @override + void rejectGesture(int pointer) { + stopTrackingPointer(pointer); + cachedEvents.remove(pointer); + } + + void _cacheEvent(PointerEvent event) { + if (!cachedEvents.containsKey(event.pointer)) { + cachedEvents[event.pointer] = <PointerEvent> []; + } + cachedEvents[event.pointer]!.add(event); + } + + void _flushPointerCache(int pointer) { + cachedEvents.remove(pointer)?.forEach(_handlePointerEvent); + } + + @override + void stopTrackingPointer(int pointer) { + super.stopTrackingPointer(pointer); + forwardedPointers.remove(pointer); + } + + void reset() { + forwardedPointers.forEach(super.stopTrackingPointer); + forwardedPointers.clear(); + cachedEvents.keys.forEach(super.stopTrackingPointer); + cachedEvents.clear(); + resolve(GestureDisposition.rejected); + } +} + +/// A render object for embedding a platform view. +/// +/// [PlatformViewRenderBox] presents a platform view by adding a [PlatformViewLayer] layer, +/// integrates it with the gesture arenas system and adds relevant semantic nodes to the semantics tree. +class PlatformViewRenderBox extends RenderBox with _PlatformViewGestureMixin { + /// Creating a render object for a [PlatformViewSurface]. + PlatformViewRenderBox({ + required PlatformViewController controller, + required PlatformViewHitTestBehavior hitTestBehavior, + required Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers, + }) : assert(controller.viewId > -1), + _controller = controller { + this.hitTestBehavior = hitTestBehavior; + updateGestureRecognizers(gestureRecognizers); + } + + /// The controller for this render object. + PlatformViewController get controller => _controller; + PlatformViewController _controller; + /// Setting this value to a new value will result in a repaint. + set controller(covariant PlatformViewController controller) { + assert(controller.viewId > -1); + + if (_controller == controller) { + return; + } + final bool needsSemanticsUpdate = _controller.viewId != controller.viewId; + _controller = controller; + markNeedsPaint(); + if (needsSemanticsUpdate) { + markNeedsSemanticsUpdate(); + } + } + + /// {@template flutter.rendering.PlatformViewRenderBox.updateGestureRecognizers} + /// Updates which gestures should be forwarded to the platform view. + /// + /// Gesture recognizers created by factories in this set participate in the gesture arena for each + /// pointer that was put down on the render box. If any of the recognizers on this list wins the + /// gesture arena, the entire pointer event sequence starting from the pointer down event + /// will be dispatched to the Android view. + /// + /// The `gestureRecognizers` property must not contain more than one factory with the same [Factory.type]. + /// + /// Setting a new set of gesture recognizer factories with the same [Factory.type]s as the current + /// set has no effect, because the factories' constructors would have already been called with the previous set. + /// {@endtemplate} + /// + /// Any active gesture arena the `PlatformView` participates in is rejected when the + /// set of gesture recognizers is changed. + void updateGestureRecognizers(Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers) { + _updateGestureRecognizersWithCallBack(gestureRecognizers, _controller.dispatchPointerEvent); + } + + @override + bool get sizedByParent => true; + + @override + bool get alwaysNeedsCompositing => true; + + @override + bool get isRepaintBoundary => true; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return constraints.biggest; + } + + @override + void paint(PaintingContext context, Offset offset) { + context.addLayer(PlatformViewLayer( + rect: offset & size, + viewId: _controller.viewId, + )); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.isSemanticBoundary = true; + config.platformViewId = _controller.viewId; + } +} + +/// The Mixin handling the pointer events and gestures of a platform view render box. +mixin _PlatformViewGestureMixin on RenderBox implements MouseTrackerAnnotation { + + /// How to behave during hit testing. + // Changing _hitTestBehavior might affect which objects are considered hovered over. + set hitTestBehavior(PlatformViewHitTestBehavior value) { + if (value != _hitTestBehavior) { + _hitTestBehavior = value; + if (owner != null) { + markNeedsPaint(); + } + } + } + PlatformViewHitTestBehavior? _hitTestBehavior; + + _HandlePointerEvent? _handlePointerEvent; + + /// {@macro flutter.rendering.RenderAndroidView.updateGestureRecognizers} + /// + /// Any active gesture arena the `PlatformView` participates in is rejected when the + /// set of gesture recognizers is changed. + void _updateGestureRecognizersWithCallBack(Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers, _HandlePointerEvent handlePointerEvent) { + assert( + _factoriesTypeSet(gestureRecognizers).length == gestureRecognizers.length, + 'There were multiple gesture recognizer factories for the same type, there must only be a single ' + 'gesture recognizer factory for each gesture recognizer type.', + ); + if (_factoryTypesSetEquals(gestureRecognizers, _gestureRecognizer?.gestureRecognizerFactories)) { + return; + } + _gestureRecognizer?.dispose(); + _gestureRecognizer = _PlatformViewGestureRecognizer(handlePointerEvent, gestureRecognizers); + _handlePointerEvent = handlePointerEvent; + } + + _PlatformViewGestureRecognizer? _gestureRecognizer; + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (_hitTestBehavior == PlatformViewHitTestBehavior.transparent || !size.contains(position)) { + return false; + } + result.add(BoxHitTestEntry(this, position)); + return _hitTestBehavior == PlatformViewHitTestBehavior.opaque; + } + + @override + bool hitTestSelf(Offset position) => _hitTestBehavior != PlatformViewHitTestBehavior.transparent; + + @override + PointerEnterEventListener? get onEnter => null; + + @override + PointerExitEventListener? get onExit => null; + + @override + MouseCursor get cursor => MouseCursor.uncontrolled; + + @override + bool get validForMouseTracker => true; + + @override + void handleEvent(PointerEvent event, HitTestEntry entry) { + if (event is PointerDownEvent) { + _gestureRecognizer!.addPointer(event); + } + if (event is PointerHoverEvent) { + _handlePointerEvent?.call(event); + } + } + + @override + void detach() { + _gestureRecognizer!.reset(); + super.detach(); + } + + @override + void dispose() { + _gestureRecognizer?.dispose(); + super.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/proxy_box.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/proxy_box.dart new file mode 100644 index 0000000000000000000000000000000000000000..ee183a51d3b79109bb0657b03611640243b1567f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/proxy_box.dart @@ -0,0 +1,5056 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show Color, Gradient, Image, ImageFilter; + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/semantics.dart'; +import 'package:flutter/services.dart'; + +import 'box.dart'; +import 'layer.dart'; +import 'layout_helper.dart'; +import 'object.dart'; + +export 'package:flutter/gestures.dart' show + PointerCancelEvent, + PointerDownEvent, + PointerEvent, + PointerMoveEvent, + PointerUpEvent; + +/// A base class for render boxes that resemble their children. +/// +/// A proxy box has a single child and mimics all the properties of that +/// child by calling through to the child for each function in the render box +/// protocol. For example, a proxy box determines its size by asking its child +/// to layout with the same constraints and then matching the size. +/// +/// A proxy box isn't useful on its own because you might as well just replace +/// the proxy box with its child. However, RenderProxyBox is a useful base class +/// for render objects that wish to mimic most, but not all, of the properties +/// of their child. +/// +/// See also: +/// +/// * [RenderProxySliver], a base class for render slivers that resemble their +/// children. +class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin<RenderBox>, RenderProxyBoxMixin<RenderBox> { + /// Creates a proxy render box. + /// + /// Proxy render boxes are rarely created directly because they proxy + /// the render box protocol to [child]. Instead, consider using one of the + /// subclasses. + RenderProxyBox([RenderBox? child]) { + this.child = child; + } +} + +/// Implementation of [RenderProxyBox]. +/// +/// Use this mixin in situations where the proxying behavior +/// of [RenderProxyBox] is desired but inheriting from [RenderProxyBox] is +/// impractical (e.g. because you want to inherit from a different class). +/// +/// If a class already inherits from [RenderProxyBox] and also uses this mixin, +/// you can safely delete the use of the mixin. +@optionalTypeArgs +mixin RenderProxyBoxMixin<T extends RenderBox> on RenderBox, RenderObjectWithChildMixin<T> { + @override + void setupParentData(RenderObject child) { + // We don't actually use the offset argument in BoxParentData, so let's + // avoid allocating it at all. + if (child.parentData is! ParentData) { + child.parentData = ParentData(); + } + } + + @override + double computeMinIntrinsicWidth(double height) { + return child?.getMinIntrinsicWidth(height) ?? 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + return child?.getMaxIntrinsicWidth(height) ?? 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + return child?.getMinIntrinsicHeight(width) ?? 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + return child?.getMaxIntrinsicHeight(width) ?? 0.0; + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + return child?.getDistanceToActualBaseline(baseline) + ?? super.computeDistanceToActualBaseline(baseline); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return child?.getDryLayout(constraints) ?? computeSizeForNoChild(constraints); + } + + @override + void performLayout() { + size = (child?..layout(constraints, parentUsesSize: true))?.size + ?? computeSizeForNoChild(constraints); + return; + } + + /// Calculate the size the [RenderProxyBox] would have under the given + /// [BoxConstraints] for the case where it does not have a child. + Size computeSizeForNoChild(BoxConstraints constraints) { + return constraints.smallest; + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + return child?.hitTest(result, position: position) ?? false; + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { } + + @override + void paint(PaintingContext context, Offset offset) { + final RenderBox? child = this.child; + if (child == null) { + return; + } + context.paintChild(child, offset); + } +} + +/// How to behave during hit tests. +enum HitTestBehavior { + /// Targets that defer to their children receive events within their bounds + /// only if one of their children is hit by the hit test. + deferToChild, + + /// Opaque targets can be hit by hit tests, causing them to both receive + /// events within their bounds and prevent targets visually behind them from + /// also receiving events. + opaque, + + /// Translucent targets both receive events within their bounds and permit + /// targets visually behind them to also receive events. + translucent, +} + +/// A RenderProxyBox subclass that allows you to customize the +/// hit-testing behavior. +abstract class RenderProxyBoxWithHitTestBehavior extends RenderProxyBox { + /// Initializes member variables for subclasses. + /// + /// By default, the [behavior] is [HitTestBehavior.deferToChild]. + RenderProxyBoxWithHitTestBehavior({ + this.behavior = HitTestBehavior.deferToChild, + RenderBox? child, + }) : super(child); + + /// How to behave during hit testing when deciding how the hit test propagates + /// to children and whether to consider targets behind this one. + /// + /// Defaults to [HitTestBehavior.deferToChild]. + /// + /// See [HitTestBehavior] for the allowed values and their meanings. + HitTestBehavior behavior; + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + bool hitTarget = false; + if (size.contains(position)) { + hitTarget = hitTestChildren(result, position: position) || hitTestSelf(position); + if (hitTarget || behavior == HitTestBehavior.translucent) { + result.add(BoxHitTestEntry(this, position)); + } + } + return hitTarget; + } + + @override + bool hitTestSelf(Offset position) => behavior == HitTestBehavior.opaque; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<HitTestBehavior>('behavior', behavior, defaultValue: null)); + } +} + +/// Imposes additional constraints on its child. +/// +/// A render constrained box proxies most functions in the render box protocol +/// to its child, except that when laying out its child, it tightens the +/// constraints provided by its parent by enforcing the [additionalConstraints] +/// as well. +/// +/// For example, if you wanted [child] to have a minimum height of 50.0 logical +/// pixels, you could use `const BoxConstraints(minHeight: 50.0)` as the +/// [additionalConstraints]. +class RenderConstrainedBox extends RenderProxyBox { + /// Creates a render box that constrains its child. + /// + /// The [additionalConstraints] argument must be valid. + RenderConstrainedBox({ + RenderBox? child, + required BoxConstraints additionalConstraints, + }) : assert(additionalConstraints.debugAssertIsValid()), + _additionalConstraints = additionalConstraints, + super(child); + + /// Additional constraints to apply to [child] during layout. + BoxConstraints get additionalConstraints => _additionalConstraints; + BoxConstraints _additionalConstraints; + set additionalConstraints(BoxConstraints value) { + assert(value.debugAssertIsValid()); + if (_additionalConstraints == value) { + return; + } + _additionalConstraints = value; + markNeedsLayout(); + } + + @override + double computeMinIntrinsicWidth(double height) { + if (_additionalConstraints.hasBoundedWidth && _additionalConstraints.hasTightWidth) { + return _additionalConstraints.minWidth; + } + final double width = super.computeMinIntrinsicWidth(height); + assert(width.isFinite); + if (!_additionalConstraints.hasInfiniteWidth) { + return _additionalConstraints.constrainWidth(width); + } + return width; + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (_additionalConstraints.hasBoundedWidth && _additionalConstraints.hasTightWidth) { + return _additionalConstraints.minWidth; + } + final double width = super.computeMaxIntrinsicWidth(height); + assert(width.isFinite); + if (!_additionalConstraints.hasInfiniteWidth) { + return _additionalConstraints.constrainWidth(width); + } + return width; + } + + @override + double computeMinIntrinsicHeight(double width) { + if (_additionalConstraints.hasBoundedHeight && _additionalConstraints.hasTightHeight) { + return _additionalConstraints.minHeight; + } + final double height = super.computeMinIntrinsicHeight(width); + assert(height.isFinite); + if (!_additionalConstraints.hasInfiniteHeight) { + return _additionalConstraints.constrainHeight(height); + } + return height; + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (_additionalConstraints.hasBoundedHeight && _additionalConstraints.hasTightHeight) { + return _additionalConstraints.minHeight; + } + final double height = super.computeMaxIntrinsicHeight(width); + assert(height.isFinite); + if (!_additionalConstraints.hasInfiniteHeight) { + return _additionalConstraints.constrainHeight(height); + } + return height; + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + if (child != null) { + child!.layout(_additionalConstraints.enforce(constraints), parentUsesSize: true); + size = child!.size; + } else { + size = _additionalConstraints.enforce(constraints).constrain(Size.zero); + } + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (child != null) { + return child!.getDryLayout(_additionalConstraints.enforce(constraints)); + } else { + return _additionalConstraints.enforce(constraints).constrain(Size.zero); + } + } + + @override + void debugPaintSize(PaintingContext context, Offset offset) { + super.debugPaintSize(context, offset); + assert(() { + final Paint paint; + if (child == null || child!.size.isEmpty) { + paint = Paint() + ..color = const Color(0x90909090); + context.canvas.drawRect(offset & size, paint); + } + return true; + }()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<BoxConstraints>('additionalConstraints', additionalConstraints)); + } +} + +/// Constrains the child's [BoxConstraints.maxWidth] and +/// [BoxConstraints.maxHeight] if they're otherwise unconstrained. +/// +/// This has the effect of giving the child a natural dimension in unbounded +/// environments. For example, by providing a [maxHeight] to a widget that +/// normally tries to be as big as possible, the widget will normally size +/// itself to fit its parent, but when placed in a vertical list, it will take +/// on the given height. +/// +/// This is useful when composing widgets that normally try to match their +/// parents' size, so that they behave reasonably in lists (which are +/// unbounded). +class RenderLimitedBox extends RenderProxyBox { + /// Creates a render box that imposes a maximum width or maximum height on its + /// child if the child is otherwise unconstrained. + /// + /// The [maxWidth] and [maxHeight] arguments not be null and must be + /// non-negative. + RenderLimitedBox({ + RenderBox? child, + double maxWidth = double.infinity, + double maxHeight = double.infinity, + }) : assert(maxWidth >= 0.0), + assert(maxHeight >= 0.0), + _maxWidth = maxWidth, + _maxHeight = maxHeight, + super(child); + + /// The value to use for maxWidth if the incoming maxWidth constraint is infinite. + double get maxWidth => _maxWidth; + double _maxWidth; + set maxWidth(double value) { + assert(value >= 0.0); + if (_maxWidth == value) { + return; + } + _maxWidth = value; + markNeedsLayout(); + } + + /// The value to use for maxHeight if the incoming maxHeight constraint is infinite. + double get maxHeight => _maxHeight; + double _maxHeight; + set maxHeight(double value) { + assert(value >= 0.0); + if (_maxHeight == value) { + return; + } + _maxHeight = value; + markNeedsLayout(); + } + + BoxConstraints _limitConstraints(BoxConstraints constraints) { + return BoxConstraints( + minWidth: constraints.minWidth, + maxWidth: constraints.hasBoundedWidth ? constraints.maxWidth : constraints.constrainWidth(maxWidth), + minHeight: constraints.minHeight, + maxHeight: constraints.hasBoundedHeight ? constraints.maxHeight : constraints.constrainHeight(maxHeight), + ); + } + + Size _computeSize({required BoxConstraints constraints, required ChildLayouter layoutChild }) { + if (child != null) { + final Size childSize = layoutChild(child!, _limitConstraints(constraints)); + return constraints.constrain(childSize); + } + return _limitConstraints(constraints).constrain(Size.zero); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.dryLayoutChild, + ); + } + + @override + void performLayout() { + size = _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.layoutChild, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('maxWidth', maxWidth, defaultValue: double.infinity)); + properties.add(DoubleProperty('maxHeight', maxHeight, defaultValue: double.infinity)); + } +} + +/// Attempts to size the child to a specific aspect ratio. +/// +/// The render object first tries the largest width permitted by the layout +/// constraints. The height of the render object is determined by applying the +/// given aspect ratio to the width, expressed as a ratio of width to height. +/// +/// For example, a 16:9 width:height aspect ratio would have a value of +/// 16.0/9.0. If the maximum width is infinite, the initial width is determined +/// by applying the aspect ratio to the maximum height. +/// +/// Now consider a second example, this time with an aspect ratio of 2.0 and +/// layout constraints that require the width to be between 0.0 and 100.0 and +/// the height to be between 0.0 and 100.0. We'll select a width of 100.0 (the +/// biggest allowed) and a height of 50.0 (to match the aspect ratio). +/// +/// In that same situation, if the aspect ratio is 0.5, we'll also select a +/// width of 100.0 (still the biggest allowed) and we'll attempt to use a height +/// of 200.0. Unfortunately, that violates the constraints because the child can +/// be at most 100.0 pixels tall. The render object will then take that value +/// and apply the aspect ratio again to obtain a width of 50.0. That width is +/// permitted by the constraints and the child receives a width of 50.0 and a +/// height of 100.0. If the width were not permitted, the render object would +/// continue iterating through the constraints. If the render object does not +/// find a feasible size after consulting each constraint, the render object +/// will eventually select a size for the child that meets the layout +/// constraints but fails to meet the aspect ratio constraints. +class RenderAspectRatio extends RenderProxyBox { + /// Creates as render object with a specific aspect ratio. + /// + /// The [aspectRatio] argument must be a finite, positive value. + RenderAspectRatio({ + RenderBox? child, + required double aspectRatio, + }) : assert(aspectRatio > 0.0), + assert(aspectRatio.isFinite), + _aspectRatio = aspectRatio, + super(child); + + /// The aspect ratio to attempt to use. + /// + /// The aspect ratio is expressed as a ratio of width to height. For example, + /// a 16:9 width:height aspect ratio would have a value of 16.0/9.0. + double get aspectRatio => _aspectRatio; + double _aspectRatio; + set aspectRatio(double value) { + assert(value > 0.0); + assert(value.isFinite); + if (_aspectRatio == value) { + return; + } + _aspectRatio = value; + markNeedsLayout(); + } + + @override + double computeMinIntrinsicWidth(double height) { + if (height.isFinite) { + return height * _aspectRatio; + } + if (child != null) { + return child!.getMinIntrinsicWidth(height); + } + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (height.isFinite) { + return height * _aspectRatio; + } + if (child != null) { + return child!.getMaxIntrinsicWidth(height); + } + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + if (width.isFinite) { + return width / _aspectRatio; + } + if (child != null) { + return child!.getMinIntrinsicHeight(width); + } + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (width.isFinite) { + return width / _aspectRatio; + } + if (child != null) { + return child!.getMaxIntrinsicHeight(width); + } + return 0.0; + } + + Size _applyAspectRatio(BoxConstraints constraints) { + assert(constraints.debugAssertIsValid()); + assert(() { + if (!constraints.hasBoundedWidth && !constraints.hasBoundedHeight) { + throw FlutterError( + '$runtimeType has unbounded constraints.\n' + 'This $runtimeType was given an aspect ratio of $aspectRatio but was given ' + 'both unbounded width and unbounded height constraints. Because both ' + "constraints were unbounded, this render object doesn't know how much " + 'size to consume.', + ); + } + return true; + }()); + + if (constraints.isTight) { + return constraints.smallest; + } + + double width = constraints.maxWidth; + double height; + + // We default to picking the height based on the width, but if the width + // would be infinite, that's not sensible so we try to infer the height + // from the width. + if (width.isFinite) { + height = width / _aspectRatio; + } else { + height = constraints.maxHeight; + width = height * _aspectRatio; + } + + // Similar to RenderImage, we iteratively attempt to fit within the given + // constraints while maintaining the given aspect ratio. The order of + // applying the constraints is also biased towards inferring the height + // from the width. + + if (width > constraints.maxWidth) { + width = constraints.maxWidth; + height = width / _aspectRatio; + } + + if (height > constraints.maxHeight) { + height = constraints.maxHeight; + width = height * _aspectRatio; + } + + if (width < constraints.minWidth) { + width = constraints.minWidth; + height = width / _aspectRatio; + } + + if (height < constraints.minHeight) { + height = constraints.minHeight; + width = height * _aspectRatio; + } + + return constraints.constrain(Size(width, height)); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return _applyAspectRatio(constraints); + } + + @override + void performLayout() { + size = computeDryLayout(constraints); + if (child != null) { + child!.layout(BoxConstraints.tight(size)); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('aspectRatio', aspectRatio)); + } +} + +/// Sizes its child to the child's maximum intrinsic width. +/// +/// This class is useful, for example, when unlimited width is available and +/// you would like a child that would otherwise attempt to expand infinitely to +/// instead size itself to a more reasonable width. +/// +/// The constraints that this object passes to its child will adhere to the +/// parent's constraints, so if the constraints are not large enough to satisfy +/// the child's maximum intrinsic width, then the child will get less width +/// than it otherwise would. Likewise, if the minimum width constraint is +/// larger than the child's maximum intrinsic width, the child will be given +/// more width than it otherwise would. +/// +/// If [stepWidth] is non-null, the child's width will be snapped to a multiple +/// of the [stepWidth]. Similarly, if [stepHeight] is non-null, the child's +/// height will be snapped to a multiple of the [stepHeight]. +/// +/// This class is relatively expensive, because it adds a speculative layout +/// pass before the final layout phase. Avoid using it where possible. In the +/// worst case, this render object can result in a layout that is O(N²) in the +/// depth of the tree. +/// +/// See also: +/// +/// * [Align], a widget that aligns its child within itself. This can be used +/// to loosen the constraints passed to the [RenderIntrinsicWidth], +/// allowing the [RenderIntrinsicWidth]'s child to be smaller than that of +/// its parent. +/// * [Row], which when used with [CrossAxisAlignment.stretch] can be used +/// to loosen just the width constraints that are passed to the +/// [RenderIntrinsicWidth], allowing the [RenderIntrinsicWidth]'s child's +/// width to be smaller than that of its parent. +class RenderIntrinsicWidth extends RenderProxyBox { + /// Creates a render object that sizes itself to its child's intrinsic width. + /// + /// If [stepWidth] is non-null it must be > 0.0. Similarly If [stepHeight] is + /// non-null it must be > 0.0. + RenderIntrinsicWidth({ + double? stepWidth, + double? stepHeight, + RenderBox? child, + }) : assert(stepWidth == null || stepWidth > 0.0), + assert(stepHeight == null || stepHeight > 0.0), + _stepWidth = stepWidth, + _stepHeight = stepHeight, + super(child); + + /// If non-null, force the child's width to be a multiple of this value. + /// + /// This value must be null or > 0.0. + double? get stepWidth => _stepWidth; + double? _stepWidth; + set stepWidth(double? value) { + assert(value == null || value > 0.0); + if (value == _stepWidth) { + return; + } + _stepWidth = value; + markNeedsLayout(); + } + + /// If non-null, force the child's height to be a multiple of this value. + /// + /// This value must be null or > 0.0. + double? get stepHeight => _stepHeight; + double? _stepHeight; + set stepHeight(double? value) { + assert(value == null || value > 0.0); + if (value == _stepHeight) { + return; + } + _stepHeight = value; + markNeedsLayout(); + } + + static double _applyStep(double input, double? step) { + assert(input.isFinite); + if (step == null) { + return input; + } + return (input / step).ceil() * step; + } + + @override + double computeMinIntrinsicWidth(double height) { + return computeMaxIntrinsicWidth(height); + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (child == null) { + return 0.0; + } + final double width = child!.getMaxIntrinsicWidth(height); + return _applyStep(width, _stepWidth); + } + + @override + double computeMinIntrinsicHeight(double width) { + if (child == null) { + return 0.0; + } + if (!width.isFinite) { + width = computeMaxIntrinsicWidth(double.infinity); + } + assert(width.isFinite); + final double height = child!.getMinIntrinsicHeight(width); + return _applyStep(height, _stepHeight); + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (child == null) { + return 0.0; + } + if (!width.isFinite) { + width = computeMaxIntrinsicWidth(double.infinity); + } + assert(width.isFinite); + final double height = child!.getMaxIntrinsicHeight(width); + return _applyStep(height, _stepHeight); + } + + Size _computeSize({required ChildLayouter layoutChild, required BoxConstraints constraints}) { + if (child != null) { + if (!constraints.hasTightWidth) { + final double width = child!.getMaxIntrinsicWidth(constraints.maxHeight); + assert(width.isFinite); + constraints = constraints.tighten(width: _applyStep(width, _stepWidth)); + } + if (_stepHeight != null) { + final double height = child!.getMaxIntrinsicHeight(constraints.maxWidth); + assert(height.isFinite); + constraints = constraints.tighten(height: _applyStep(height, _stepHeight)); + } + return layoutChild(child!, constraints); + } else { + return constraints.smallest; + } + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return _computeSize( + layoutChild: ChildLayoutHelper.dryLayoutChild, + constraints: constraints, + ); + } + + @override + void performLayout() { + size = _computeSize( + layoutChild: ChildLayoutHelper.layoutChild, + constraints: constraints, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('stepWidth', stepWidth)); + properties.add(DoubleProperty('stepHeight', stepHeight)); + } +} + +/// Sizes its child to the child's intrinsic height. +/// +/// This class is useful, for example, when unlimited height is available and +/// you would like a child that would otherwise attempt to expand infinitely to +/// instead size itself to a more reasonable height. +/// +/// The constraints that this object passes to its child will adhere to the +/// parent's constraints, so if the constraints are not large enough to satisfy +/// the child's maximum intrinsic height, then the child will get less height +/// than it otherwise would. Likewise, if the minimum height constraint is +/// larger than the child's maximum intrinsic height, the child will be given +/// more height than it otherwise would. +/// +/// This class is relatively expensive, because it adds a speculative layout +/// pass before the final layout phase. Avoid using it where possible. In the +/// worst case, this render object can result in a layout that is O(N²) in the +/// depth of the tree. +/// +/// See also: +/// +/// * [Align], a widget that aligns its child within itself. This can be used +/// to loosen the constraints passed to the [RenderIntrinsicHeight], +/// allowing the [RenderIntrinsicHeight]'s child to be smaller than that of +/// its parent. +/// * [Column], which when used with [CrossAxisAlignment.stretch] can be used +/// to loosen just the height constraints that are passed to the +/// [RenderIntrinsicHeight], allowing the [RenderIntrinsicHeight]'s child's +/// height to be smaller than that of its parent. +class RenderIntrinsicHeight extends RenderProxyBox { + /// Creates a render object that sizes itself to its child's intrinsic height. + RenderIntrinsicHeight({ + RenderBox? child, + }) : super(child); + + @override + double computeMinIntrinsicWidth(double height) { + if (child == null) { + return 0.0; + } + if (!height.isFinite) { + height = child!.getMaxIntrinsicHeight(double.infinity); + } + assert(height.isFinite); + return child!.getMinIntrinsicWidth(height); + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (child == null) { + return 0.0; + } + if (!height.isFinite) { + height = child!.getMaxIntrinsicHeight(double.infinity); + } + assert(height.isFinite); + return child!.getMaxIntrinsicWidth(height); + } + + @override + double computeMinIntrinsicHeight(double width) { + return computeMaxIntrinsicHeight(width); + } + + Size _computeSize({required ChildLayouter layoutChild, required BoxConstraints constraints}) { + if (child != null) { + if (!constraints.hasTightHeight) { + final double height = child!.getMaxIntrinsicHeight(constraints.maxWidth); + assert(height.isFinite); + constraints = constraints.tighten(height: height); + } + return layoutChild(child!, constraints); + } else { + return constraints.smallest; + } + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return _computeSize( + layoutChild: ChildLayoutHelper.dryLayoutChild, + constraints: constraints, + ); + } + + @override + void performLayout() { + size = _computeSize( + layoutChild: ChildLayoutHelper.layoutChild, + constraints: constraints, + ); + } +} + +/// Excludes the child from baseline computations in the parent. +class RenderIgnoreBaseline extends RenderProxyBox { + /// Create a render object that causes the parent to ignore the child for baseline computations. + RenderIgnoreBaseline({ + RenderBox? child, + }) : super(child); + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + return null; + } +} + +/// Makes its child partially transparent. +/// +/// This class paints its child into an intermediate buffer and then blends the +/// child back into the scene partially transparent. +/// +/// For values of opacity other than 0.0 and 1.0, this class is relatively +/// expensive because it requires painting the child into an intermediate +/// buffer. For the value 0.0, the child is not painted at all. For the +/// value 1.0, the child is painted immediately without an intermediate buffer. +class RenderOpacity extends RenderProxyBox { + /// Creates a partially transparent render object. + /// + /// The [opacity] argument must be between 0.0 and 1.0, inclusive. + RenderOpacity({ + double opacity = 1.0, + bool alwaysIncludeSemantics = false, + RenderBox? child, + }) : assert(opacity >= 0.0 && opacity <= 1.0), + _opacity = opacity, + _alwaysIncludeSemantics = alwaysIncludeSemantics, + _alpha = ui.Color.getAlphaFromOpacity(opacity), + super(child); + + @override + bool get alwaysNeedsCompositing => child != null && _alpha > 0; + + @override + bool get isRepaintBoundary => alwaysNeedsCompositing; + + int _alpha; + + /// The fraction to scale the child's alpha value. + /// + /// An opacity of 1.0 is fully opaque. An opacity of 0.0 is fully transparent + /// (i.e., invisible). + /// + /// Values 1.0 and 0.0 are painted with a fast path. Other values + /// require painting the child into an intermediate buffer, which is + /// expensive. + double get opacity => _opacity; + double _opacity; + set opacity(double value) { + assert(value >= 0.0 && value <= 1.0); + if (_opacity == value) { + return; + } + final bool didNeedCompositing = alwaysNeedsCompositing; + final bool wasVisible = _alpha != 0; + _opacity = value; + _alpha = ui.Color.getAlphaFromOpacity(_opacity); + if (didNeedCompositing != alwaysNeedsCompositing) { + markNeedsCompositingBitsUpdate(); + } + markNeedsCompositedLayerUpdate(); + if (wasVisible != (_alpha != 0) && !alwaysIncludeSemantics) { + markNeedsSemanticsUpdate(); + } + } + + /// Whether child semantics are included regardless of the opacity. + /// + /// If false, semantics are excluded when [opacity] is 0.0. + /// + /// Defaults to false. + bool get alwaysIncludeSemantics => _alwaysIncludeSemantics; + bool _alwaysIncludeSemantics; + set alwaysIncludeSemantics(bool value) { + if (value == _alwaysIncludeSemantics) { + return; + } + _alwaysIncludeSemantics = value; + markNeedsSemanticsUpdate(); + } + + @override + bool paintsChild(RenderBox child) { + assert(child.parent == this); + return _alpha > 0; + } + + @override + OffsetLayer updateCompositedLayer({required covariant OpacityLayer? oldLayer}) { + final OpacityLayer layer = oldLayer ?? OpacityLayer(); + layer.alpha = _alpha; + return layer; + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child == null || _alpha == 0) { + return; + } + super.paint(context, offset); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (child != null && (_alpha != 0 || alwaysIncludeSemantics)) { + visitor(child!); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('opacity', opacity)); + properties.add(FlagProperty('alwaysIncludeSemantics', value: alwaysIncludeSemantics, ifTrue: 'alwaysIncludeSemantics')); + } +} + +/// Implementation of [RenderAnimatedOpacity] and [RenderSliverAnimatedOpacity]. +/// +/// This mixin allows the logic of animating opacity to be used with different +/// layout models, e.g. the way that [RenderAnimatedOpacity] uses it for [RenderBox] +/// and [RenderSliverAnimatedOpacity] uses it for [RenderSliver]. +mixin RenderAnimatedOpacityMixin<T extends RenderObject> on RenderObjectWithChildMixin<T> { + int? _alpha; + + @override + bool get isRepaintBoundary => child != null && _currentlyIsRepaintBoundary!; + bool? _currentlyIsRepaintBoundary; + + @override + OffsetLayer updateCompositedLayer({required covariant OpacityLayer? oldLayer}) { + final OpacityLayer updatedLayer = oldLayer ?? OpacityLayer(); + updatedLayer.alpha = _alpha; + return updatedLayer; + } + + /// The animation that drives this render object's opacity. + /// + /// An opacity of 1.0 is fully opaque. An opacity of 0.0 is fully transparent + /// (i.e., invisible). + /// + /// To change the opacity of a child in a static manner, not animated, + /// consider [RenderOpacity] instead. + /// + /// This getter cannot be read until the value has been set. It should be set + /// by the constructor of the class in which this mixin is included. + Animation<double> get opacity => _opacity!; + Animation<double>? _opacity; + set opacity(Animation<double> value) { + if (_opacity == value) { + return; + } + if (attached && _opacity != null) { + opacity.removeListener(_updateOpacity); + } + _opacity = value; + if (attached) { + opacity.addListener(_updateOpacity); + } + _updateOpacity(); + } + + /// Whether child semantics are included regardless of the opacity. + /// + /// If false, semantics are excluded when [opacity] is 0.0. + /// + /// Defaults to false. + /// + /// This getter cannot be read until the value has been set. It should be set + /// by the constructor of the class in which this mixin is included. + bool get alwaysIncludeSemantics => _alwaysIncludeSemantics!; + bool? _alwaysIncludeSemantics; + set alwaysIncludeSemantics(bool value) { + if (value == _alwaysIncludeSemantics) { + return; + } + _alwaysIncludeSemantics = value; + markNeedsSemanticsUpdate(); + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + opacity.addListener(_updateOpacity); + _updateOpacity(); // in case it changed while we weren't listening + } + + @override + void detach() { + opacity.removeListener(_updateOpacity); + super.detach(); + } + + void _updateOpacity() { + final int? oldAlpha = _alpha; + _alpha = ui.Color.getAlphaFromOpacity(opacity.value); + if (oldAlpha != _alpha) { + final bool? wasRepaintBoundary = _currentlyIsRepaintBoundary; + _currentlyIsRepaintBoundary = _alpha! > 0; + if (child != null && wasRepaintBoundary != _currentlyIsRepaintBoundary) { + markNeedsCompositingBitsUpdate(); + } + markNeedsCompositedLayerUpdate(); + if (oldAlpha == 0 || _alpha == 0) { + markNeedsSemanticsUpdate(); + } + } + } + + @override + bool paintsChild(RenderObject child) { + assert(child.parent == this); + return opacity.value > 0; + } + + @override + void paint(PaintingContext context, Offset offset) { + if (_alpha == 0) { + return; + } + super.paint(context, offset); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (child != null && (_alpha != 0 || alwaysIncludeSemantics)) { + visitor(child!); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Animation<double>>('opacity', opacity)); + properties.add(FlagProperty('alwaysIncludeSemantics', value: alwaysIncludeSemantics, ifTrue: 'alwaysIncludeSemantics')); + } +} + +/// Makes its child partially transparent, driven from an [Animation]. +/// +/// This is a variant of [RenderOpacity] that uses an [Animation<double>] rather +/// than a [double] to control the opacity. +class RenderAnimatedOpacity extends RenderProxyBox with RenderAnimatedOpacityMixin<RenderBox> { + /// Creates a partially transparent render object. + RenderAnimatedOpacity({ + required Animation<double> opacity, + bool alwaysIncludeSemantics = false, + RenderBox? child, + }) : super(child) { + this.opacity = opacity; + this.alwaysIncludeSemantics = alwaysIncludeSemantics; + } +} + +/// Signature for a function that creates a [Shader] for a given [Rect]. +/// +/// Used by [RenderShaderMask] and the [ShaderMask] widget. +typedef ShaderCallback = Shader Function(Rect bounds); + +/// Applies a mask generated by a [Shader] to its child. +/// +/// For example, [RenderShaderMask] can be used to gradually fade out the edge +/// of a child by using a [ui.Gradient.linear] mask. +class RenderShaderMask extends RenderProxyBox { + /// Creates a render object that applies a mask generated by a [Shader] to its child. + RenderShaderMask({ + RenderBox? child, + required ShaderCallback shaderCallback, + BlendMode blendMode = BlendMode.modulate, + }) : _shaderCallback = shaderCallback, + _blendMode = blendMode, + super(child); + + @override + ShaderMaskLayer? get layer => super.layer as ShaderMaskLayer?; + + /// Called to creates the [Shader] that generates the mask. + /// + /// The shader callback is called with the current size of the child so that + /// it can customize the shader to the size and location of the child. + /// + /// The rectangle will always be at the origin when called by + /// [RenderShaderMask]. + // TODO(abarth): Use the delegate pattern here to avoid generating spurious + // repaints when the ShaderCallback changes identity. + ShaderCallback get shaderCallback => _shaderCallback; + ShaderCallback _shaderCallback; + set shaderCallback(ShaderCallback value) { + if (_shaderCallback == value) { + return; + } + _shaderCallback = value; + markNeedsPaint(); + } + + /// The [BlendMode] to use when applying the shader to the child. + /// + /// The default, [BlendMode.modulate], is useful for applying an alpha blend + /// to the child. Other blend modes can be used to create other effects. + BlendMode get blendMode => _blendMode; + BlendMode _blendMode; + set blendMode(BlendMode value) { + if (_blendMode == value) { + return; + } + _blendMode = value; + markNeedsPaint(); + } + + @override + bool get alwaysNeedsCompositing => child != null; + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + assert(needsCompositing); + layer ??= ShaderMaskLayer(); + layer! + ..shader = _shaderCallback(Offset.zero & size) + ..maskRect = offset & size + ..blendMode = _blendMode; + context.pushLayer(layer!, super.paint, offset); + assert(() { + layer!.debugCreator = debugCreator; + return true; + }()); + } else { + layer = null; + } + } +} + +/// Applies a filter to the existing painted content and then paints [child]. +/// +/// This effect is relatively expensive, especially if the filter is non-local, +/// such as a blur. +class RenderBackdropFilter extends RenderProxyBox { + /// Creates a backdrop filter. + // + /// The [blendMode] argument defaults to [BlendMode.srcOver]. + RenderBackdropFilter({ RenderBox? child, required ui.ImageFilter filter, BlendMode blendMode = BlendMode.srcOver }) + : _filter = filter, + _blendMode = blendMode, + super(child); + + @override + BackdropFilterLayer? get layer => super.layer as BackdropFilterLayer?; + + /// The image filter to apply to the existing painted content before painting + /// the child. + /// + /// For example, consider using [ui.ImageFilter.blur] to create a backdrop + /// blur effect. + ui.ImageFilter get filter => _filter; + ui.ImageFilter _filter; + set filter(ui.ImageFilter value) { + if (_filter == value) { + return; + } + _filter = value; + markNeedsPaint(); + } + + /// The blend mode to use to apply the filtered background content onto the background + /// surface. + /// + /// {@macro flutter.widgets.BackdropFilter.blendMode} + BlendMode get blendMode => _blendMode; + BlendMode _blendMode; + set blendMode(BlendMode value) { + if (_blendMode == value) { + return; + } + _blendMode = value; + markNeedsPaint(); + } + + @override + bool get alwaysNeedsCompositing => child != null; + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + assert(needsCompositing); + layer ??= BackdropFilterLayer(); + layer!.filter = _filter; + layer!.blendMode = _blendMode; + context.pushLayer(layer!, super.paint, offset); + assert(() { + layer!.debugCreator = debugCreator; + return true; + }()); + } else { + layer = null; + } + } +} + +/// An interface for providing custom clips. +/// +/// This class is used by a number of clip widgets (e.g., [ClipRect] and +/// [ClipPath]). +/// +/// The [getClip] method is called whenever the custom clip needs to be updated. +/// +/// The [shouldReclip] method is called when a new instance of the class +/// is provided, to check if the new instance actually represents different +/// information. +/// +/// The most efficient way to update the clip provided by this class is to +/// supply a `reclip` argument to the constructor of the [CustomClipper]. The +/// custom object will listen to this animation and update the clip whenever the +/// animation ticks, avoiding both the build and layout phases of the pipeline. +/// +/// See also: +/// +/// * [ClipRect], which can be customized with a [CustomClipper<Rect>]. +/// * [ClipRRect], which can be customized with a [CustomClipper<RRect>]. +/// * [ClipOval], which can be customized with a [CustomClipper<Rect>]. +/// * [ClipPath], which can be customized with a [CustomClipper<Path>]. +/// * [ShapeBorderClipper], for specifying a clip path using a [ShapeBorder]. +abstract class CustomClipper<T> extends Listenable { + /// Creates a custom clipper. + /// + /// The clipper will update its clip whenever [reclip] notifies its listeners. + const CustomClipper({ Listenable? reclip }) : _reclip = reclip; + + final Listenable? _reclip; + + /// Register a closure to be notified when it is time to reclip. + /// + /// The [CustomClipper] implementation merely forwards to the same method on + /// the [Listenable] provided to the constructor in the `reclip` argument, if + /// it was not null. + @override + void addListener(VoidCallback listener) => _reclip?.addListener(listener); + + /// Remove a previously registered closure from the list of closures that the + /// object notifies when it is time to reclip. + /// + /// The [CustomClipper] implementation merely forwards to the same method on + /// the [Listenable] provided to the constructor in the `reclip` argument, if + /// it was not null. + @override + void removeListener(VoidCallback listener) => _reclip?.removeListener(listener); + + /// Returns a description of the clip given that the render object being + /// clipped is of the given size. + T getClip(Size size); + + /// Returns an approximation of the clip returned by [getClip], as + /// an axis-aligned Rect. This is used by the semantics layer to + /// determine whether widgets should be excluded. + /// + /// By default, this returns a rectangle that is the same size as + /// the RenderObject. If getClip returns a shape that is roughly the + /// same size as the RenderObject (e.g. it's a rounded rectangle + /// with very small arcs in the corners), then this may be adequate. + Rect getApproximateClipRect(Size size) => Offset.zero & size; + + /// Called whenever a new instance of the custom clipper delegate class is + /// provided to the clip object, or any time that a new clip object is created + /// with a new instance of the custom clipper delegate class (which amounts to + /// the same thing, because the latter is implemented in terms of the former). + /// + /// If the new instance represents different information than the old + /// instance, then the method should return true, otherwise it should return + /// false. + /// + /// If the method returns false, then the [getClip] call might be optimized + /// away. + /// + /// It's possible that the [getClip] method will get called even if + /// [shouldReclip] returns false or if the [shouldReclip] method is never + /// called at all (e.g. if the box changes size). + bool shouldReclip(covariant CustomClipper<T> oldClipper); + + @override + String toString() => objectRuntimeType(this, 'CustomClipper'); +} + +/// A [CustomClipper] that clips to the outer path of a [ShapeBorder]. +class ShapeBorderClipper extends CustomClipper<Path> { + /// Creates a [ShapeBorder] clipper. + /// + /// The [textDirection] argument must be provided non-null if [shape] + /// has a text direction dependency (for example if it is expressed in terms + /// of "start" and "end" instead of "left" and "right"). It may be null if + /// the border will not need the text direction to paint itself. + const ShapeBorderClipper({ + required this.shape, + this.textDirection, + }); + + /// The shape border whose outer path this clipper clips to. + final ShapeBorder shape; + + /// The text direction to use for getting the outer path for [shape]. + /// + /// [ShapeBorder]s can depend on the text direction (e.g having a "dent" + /// towards the start of the shape). + final TextDirection? textDirection; + + /// Returns the outer path of [shape] as the clip. + @override + Path getClip(Size size) { + return shape.getOuterPath(Offset.zero & size, textDirection: textDirection); + } + + @override + bool shouldReclip(CustomClipper<Path> oldClipper) { + if (oldClipper.runtimeType != ShapeBorderClipper) { + return true; + } + final ShapeBorderClipper typedOldClipper = oldClipper as ShapeBorderClipper; + return typedOldClipper.shape != shape + || typedOldClipper.textDirection != textDirection; + } +} + +abstract class _RenderCustomClip<T> extends RenderProxyBox { + _RenderCustomClip({ + RenderBox? child, + CustomClipper<T>? clipper, + Clip clipBehavior = Clip.antiAlias, + }) : _clipper = clipper, + _clipBehavior = clipBehavior, + super(child); + + /// If non-null, determines which clip to use on the child. + CustomClipper<T>? get clipper => _clipper; + CustomClipper<T>? _clipper; + set clipper(CustomClipper<T>? newClipper) { + if (_clipper == newClipper) { + return; + } + final CustomClipper<T>? oldClipper = _clipper; + _clipper = newClipper; + assert(newClipper != null || oldClipper != null); + if (newClipper == null || oldClipper == null || + newClipper.runtimeType != oldClipper.runtimeType || + newClipper.shouldReclip(oldClipper)) { + _markNeedsClip(); + } + if (attached) { + oldClipper?.removeListener(_markNeedsClip); + newClipper?.addListener(_markNeedsClip); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _clipper?.addListener(_markNeedsClip); + } + + @override + void detach() { + _clipper?.removeListener(_markNeedsClip); + super.detach(); + } + + void _markNeedsClip() { + _clip = null; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + T get _defaultClip; + T? _clip; + + Clip get clipBehavior => _clipBehavior; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + } + } + Clip _clipBehavior; + + @override + void performLayout() { + final Size? oldSize = hasSize ? size : null; + super.performLayout(); + if (oldSize != size) { + _clip = null; + } + } + + void _updateClip() { + _clip ??= _clipper?.getClip(size) ?? _defaultClip; + } + + @override + Rect? describeApproximatePaintClip(RenderObject child) { + switch (clipBehavior) { + case Clip.none: + return null; + case Clip.hardEdge: + case Clip.antiAlias: + case Clip.antiAliasWithSaveLayer: + return _clipper?.getApproximateClipRect(size) ?? Offset.zero & size; + } + } + + Paint? _debugPaint; + TextPainter? _debugText; + @override + void debugPaintSize(PaintingContext context, Offset offset) { + assert(() { + _debugPaint ??= Paint() + ..shader = ui.Gradient.linear( + Offset.zero, + const Offset(10.0, 10.0), + <Color>[const Color(0x00000000), const Color(0xFFFF00FF), const Color(0xFFFF00FF), const Color(0x00000000)], + <double>[0.25, 0.25, 0.75, 0.75], + TileMode.repeated, + ) + ..strokeWidth = 2.0 + ..style = PaintingStyle.stroke; + _debugText ??= TextPainter( + text: const TextSpan( + text: '✂', + style: TextStyle( + color: Color(0xFFFF00FF), + fontSize: 14.0, + ), + ), + textDirection: TextDirection.rtl, // doesn't matter, it's one character + ) + ..layout(); + return true; + }()); + } + + @override + void dispose() { + _debugText?.dispose(); + _debugText = null; + super.dispose(); + } +} + +/// Clips its child using a rectangle. +/// +/// By default, [RenderClipRect] prevents its child from painting outside its +/// bounds, but the size and location of the clip rect can be customized using a +/// custom [clipper]. +class RenderClipRect extends _RenderCustomClip<Rect> { + /// Creates a rectangular clip. + /// + /// If [clipper] is null, the clip will match the layout size and position of + /// the child. + /// + /// If [clipBehavior] is [Clip.none], no clipping will be applied. + RenderClipRect({ + super.child, + super.clipper, + super.clipBehavior, + }); + + @override + Rect get _defaultClip => Offset.zero & size; + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (_clipper != null) { + _updateClip(); + assert(_clip != null); + if (!_clip!.contains(position)) { + return false; + } + } + return super.hitTest(result, position: position); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + if (clipBehavior != Clip.none) { + _updateClip(); + layer = context.pushClipRect( + needsCompositing, + offset, + _clip!, + super.paint, + clipBehavior: clipBehavior, + oldLayer: layer as ClipRectLayer?, + ); + } else { + context.paintChild(child!, offset); + layer = null; + } + } else { + layer = null; + } + } + + @override + void debugPaintSize(PaintingContext context, Offset offset) { + assert(() { + if (child != null) { + super.debugPaintSize(context, offset); + if (clipBehavior != Clip.none) { + context.canvas.drawRect(_clip!.shift(offset), _debugPaint!); + _debugText!.paint(context.canvas, offset + Offset(_clip!.width / 8.0, -_debugText!.text!.style!.fontSize! * 1.1)); + } + } + return true; + }()); + } +} + +/// Clips its child using a rounded rectangle. +/// +/// By default, [RenderClipRRect] uses its own bounds as the base rectangle for +/// the clip, but the size and location of the clip can be customized using a +/// custom [clipper]. +class RenderClipRRect extends _RenderCustomClip<RRect> { + /// Creates a rounded-rectangular clip. + /// + /// The [borderRadius] defaults to [BorderRadius.zero], i.e. a rectangle with + /// right-angled corners. + /// + /// If [clipper] is non-null, then [borderRadius] is ignored. + /// + /// If [clipBehavior] is [Clip.none], no clipping will be applied. + RenderClipRRect({ + super.child, + BorderRadiusGeometry borderRadius = BorderRadius.zero, + super.clipper, + super.clipBehavior, + TextDirection? textDirection, + }) : _borderRadius = borderRadius, + _textDirection = textDirection; + + /// The border radius of the rounded corners. + /// + /// Values are clamped so that horizontal and vertical radii sums do not + /// exceed width/height. + /// + /// This value is ignored if [clipper] is non-null. + BorderRadiusGeometry get borderRadius => _borderRadius; + BorderRadiusGeometry _borderRadius; + set borderRadius(BorderRadiusGeometry value) { + if (_borderRadius == value) { + return; + } + _borderRadius = value; + _markNeedsClip(); + } + + /// The text direction with which to resolve [borderRadius]. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + _markNeedsClip(); + } + + @override + RRect get _defaultClip => _borderRadius.resolve(textDirection).toRRect(Offset.zero & size); + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (_clipper != null) { + _updateClip(); + assert(_clip != null); + if (!_clip!.contains(position)) { + return false; + } + } + return super.hitTest(result, position: position); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + if (clipBehavior != Clip.none) { + _updateClip(); + layer = context.pushClipRRect( + needsCompositing, + offset, + _clip!.outerRect, + _clip!, + super.paint, + clipBehavior: clipBehavior, + oldLayer: layer as ClipRRectLayer?, + ); + } else { + context.paintChild(child!, offset); + layer = null; + } + } else { + layer = null; + } + } + + @override + void debugPaintSize(PaintingContext context, Offset offset) { + assert(() { + if (child != null) { + super.debugPaintSize(context, offset); + if (clipBehavior != Clip.none) { + context.canvas.drawRRect(_clip!.shift(offset), _debugPaint!); + _debugText!.paint(context.canvas, offset + Offset(_clip!.tlRadiusX, -_debugText!.text!.style!.fontSize! * 1.1)); + } + } + return true; + }()); + } +} + +/// Clips its child using an oval. +/// +/// By default, inscribes an axis-aligned oval into its layout dimensions and +/// prevents its child from painting outside that oval, but the size and +/// location of the clip oval can be customized using a custom [clipper]. +class RenderClipOval extends _RenderCustomClip<Rect> { + /// Creates an oval-shaped clip. + /// + /// If [clipper] is null, the oval will be inscribed into the layout size and + /// position of the child. + /// + /// If [clipBehavior] is [Clip.none], no clipping will be applied. + RenderClipOval({ + super.child, + super.clipper, + super.clipBehavior, + }); + + Rect? _cachedRect; + late Path _cachedPath; + + Path _getClipPath(Rect rect) { + if (rect != _cachedRect) { + _cachedRect = rect; + _cachedPath = Path()..addOval(_cachedRect!); + } + return _cachedPath; + } + + @override + Rect get _defaultClip => Offset.zero & size; + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + _updateClip(); + assert(_clip != null); + final Offset center = _clip!.center; + // convert the position to an offset from the center of the unit circle + final Offset offset = Offset( + (position.dx - center.dx) / _clip!.width, + (position.dy - center.dy) / _clip!.height, + ); + // check if the point is outside the unit circle + if (offset.distanceSquared > 0.25) { // x^2 + y^2 > r^2 + return false; + } + return super.hitTest(result, position: position); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + if (clipBehavior != Clip.none) { + _updateClip(); + layer = context.pushClipPath( + needsCompositing, + offset, + _clip!, + _getClipPath(_clip!), + super.paint, + clipBehavior: clipBehavior, + oldLayer: layer as ClipPathLayer?, + ); + } else { + context.paintChild(child!, offset); + layer = null; + } + } else { + layer = null; + } + } + + @override + void debugPaintSize(PaintingContext context, Offset offset) { + assert(() { + if (child != null) { + super.debugPaintSize(context, offset); + if (clipBehavior != Clip.none) { + context.canvas.drawPath(_getClipPath(_clip!).shift(offset), _debugPaint!); + _debugText!.paint(context.canvas, offset + Offset((_clip!.width - _debugText!.width) / 2.0, -_debugText!.text!.style!.fontSize! * 1.1)); + } + } + return true; + }()); + } +} + +/// Clips its child using a path. +/// +/// Takes a delegate whose primary method returns a path that should +/// be used to prevent the child from painting outside the path. +/// +/// Clipping to a path is expensive. Certain shapes have more +/// optimized render objects: +/// +/// * To clip to a rectangle, consider [RenderClipRect]. +/// * To clip to an oval or circle, consider [RenderClipOval]. +/// * To clip to a rounded rectangle, consider [RenderClipRRect]. +class RenderClipPath extends _RenderCustomClip<Path> { + /// Creates a path clip. + /// + /// If [clipper] is null, the clip will be a rectangle that matches the layout + /// size and location of the child. However, rather than use this default, + /// consider using a [RenderClipRect], which can achieve the same effect more + /// efficiently. + /// + /// If [clipBehavior] is [Clip.none], no clipping will be applied. + RenderClipPath({ + super.child, + super.clipper, + super.clipBehavior, + }); + + @override + Path get _defaultClip => Path()..addRect(Offset.zero & size); + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (_clipper != null) { + _updateClip(); + assert(_clip != null); + if (!_clip!.contains(position)) { + return false; + } + } + return super.hitTest(result, position: position); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + if (clipBehavior != Clip.none) { + _updateClip(); + layer = context.pushClipPath( + needsCompositing, + offset, + Offset.zero & size, + _clip!, + super.paint, + clipBehavior: clipBehavior, + oldLayer: layer as ClipPathLayer?, + ); + } else { + context.paintChild(child!, offset); + layer = null; + } + } else { + layer = null; + } + } + + @override + void debugPaintSize(PaintingContext context, Offset offset) { + assert(() { + if (child != null) { + super.debugPaintSize(context, offset); + if (clipBehavior != Clip.none) { + context.canvas.drawPath(_clip!.shift(offset), _debugPaint!); + _debugText!.paint(context.canvas, offset); + } + } + return true; + }()); + } +} + +/// A physical model layer casts a shadow based on its [elevation]. +/// +/// The concrete implementations [RenderPhysicalModel] and [RenderPhysicalShape] +/// determine the actual shape of the physical model. +abstract class _RenderPhysicalModelBase<T> extends _RenderCustomClip<T> { + /// The [elevation] parameter must be non-negative. + _RenderPhysicalModelBase({ + required super.child, + required double elevation, + required Color color, + required Color shadowColor, + super.clipBehavior = Clip.none, + super.clipper, + }) : assert(elevation >= 0.0), + _elevation = elevation, + _color = color, + _shadowColor = shadowColor; + + /// The z-coordinate relative to the parent at which to place this material. + /// + /// The value is non-negative. + /// + /// If [debugDisableShadows] is set, this value is ignored and no shadow is + /// drawn (an outline is rendered instead). + double get elevation => _elevation; + double _elevation; + set elevation(double value) { + assert(value >= 0.0); + if (elevation == value) { + return; + } + final bool didNeedCompositing = alwaysNeedsCompositing; + _elevation = value; + if (didNeedCompositing != alwaysNeedsCompositing) { + markNeedsCompositingBitsUpdate(); + } + markNeedsPaint(); + } + + /// The shadow color. + Color get shadowColor => _shadowColor; + Color _shadowColor; + set shadowColor(Color value) { + if (shadowColor == value) { + return; + } + _shadowColor = value; + markNeedsPaint(); + } + + /// The background color. + Color get color => _color; + Color _color; + set color(Color value) { + if (color == value) { + return; + } + _color = value; + markNeedsPaint(); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.elevation = elevation; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DoubleProperty('elevation', elevation)); + description.add(ColorProperty('color', color)); + description.add(ColorProperty('shadowColor', color)); + } +} + +/// Creates a physical model layer that clips its child to a rounded +/// rectangle. +/// +/// A physical model layer casts a shadow based on its [elevation]. +class RenderPhysicalModel extends _RenderPhysicalModelBase<RRect> { + /// Creates a rounded-rectangular clip. + /// + /// The [color] is required. + /// + /// The [elevation] parameter must be non-negative. + RenderPhysicalModel({ + super.child, + BoxShape shape = BoxShape.rectangle, + super.clipBehavior, + BorderRadius? borderRadius, + super.elevation = 0.0, + required super.color, + super.shadowColor = const Color(0xFF000000), + }) : assert(elevation >= 0.0), + _shape = shape, + _borderRadius = borderRadius; + + /// The shape of the layer. + /// + /// Defaults to [BoxShape.rectangle]. The [borderRadius] affects the corners + /// of the rectangle. + BoxShape get shape => _shape; + BoxShape _shape; + set shape(BoxShape value) { + if (shape == value) { + return; + } + _shape = value; + _markNeedsClip(); + } + + /// The border radius of the rounded corners. + /// + /// Values are clamped so that horizontal and vertical radii sums do not + /// exceed width/height. + /// + /// This property is ignored if the [shape] is not [BoxShape.rectangle]. + /// + /// The value null is treated like [BorderRadius.zero]. + BorderRadius? get borderRadius => _borderRadius; + BorderRadius? _borderRadius; + set borderRadius(BorderRadius? value) { + if (borderRadius == value) { + return; + } + _borderRadius = value; + _markNeedsClip(); + } + + @override + RRect get _defaultClip { + assert(hasSize); + final Rect rect = Offset.zero & size; + switch (_shape) { + case BoxShape.rectangle: + return (borderRadius ?? BorderRadius.zero).toRRect(rect); + case BoxShape.circle: + return RRect.fromRectXY(rect, rect.width / 2, rect.height / 2); + } + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (_clipper != null) { + _updateClip(); + assert(_clip != null); + if (!_clip!.contains(position)) { + return false; + } + } + return super.hitTest(result, position: position); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child == null) { + layer = null; + return; + } + + _updateClip(); + final RRect offsetRRect = _clip!.shift(offset); + final Path offsetRRectAsPath = Path()..addRRect(offsetRRect); + bool paintShadows = true; + assert(() { + if (debugDisableShadows) { + if (elevation > 0.0) { + context.canvas.drawRRect( + offsetRRect, + Paint() + ..color = shadowColor + ..style = PaintingStyle.stroke + ..strokeWidth = elevation * 2.0, + ); + } + paintShadows = false; + } + return true; + }()); + + final Canvas canvas = context.canvas; + if (elevation != 0.0 && paintShadows) { + canvas.drawShadow( + offsetRRectAsPath, + shadowColor, + elevation, + color.alpha != 0xFF, + ); + } + final bool usesSaveLayer = clipBehavior == Clip.antiAliasWithSaveLayer; + if (!usesSaveLayer) { + canvas.drawRRect( + offsetRRect, + Paint()..color = color + ); + } + layer = context.pushClipRRect( + needsCompositing, + offset, + Offset.zero & size, + _clip!, + (PaintingContext context, Offset offset) { + if (usesSaveLayer) { + // If we want to avoid the bleeding edge artifact + // (https://github.com/flutter/flutter/issues/18057#issue-328003931) + // using saveLayer, we have to call drawPaint instead of drawPath as + // anti-aliased drawPath will always have such artifacts. + context.canvas.drawPaint( Paint()..color = color); + } + super.paint(context, offset); + }, + oldLayer: layer as ClipRRectLayer?, + clipBehavior: clipBehavior, + ); + + assert(() { + layer?.debugCreator = debugCreator; + return true; + }()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DiagnosticsProperty<BoxShape>('shape', shape)); + description.add(DiagnosticsProperty<BorderRadius>('borderRadius', borderRadius)); + } +} + +/// Creates a physical shape layer that clips its child to a [Path]. +/// +/// A physical shape layer casts a shadow based on its [elevation]. +/// +/// See also: +/// +/// * [RenderPhysicalModel], which is optimized for rounded rectangles and +/// circles. +class RenderPhysicalShape extends _RenderPhysicalModelBase<Path> { + /// Creates an arbitrary shape clip. + /// + /// The [color] and [clipper] parameters are required. + /// + /// The [elevation] parameter must be non-negative. + RenderPhysicalShape({ + super.child, + required CustomClipper<Path> super.clipper, + super.clipBehavior, + super.elevation = 0.0, + required super.color, + super.shadowColor = const Color(0xFF000000), + }) : assert(elevation >= 0.0); + + @override + Path get _defaultClip => Path()..addRect(Offset.zero & size); + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + if (_clipper != null) { + _updateClip(); + assert(_clip != null); + if (!_clip!.contains(position)) { + return false; + } + } + return super.hitTest(result, position: position); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child == null) { + layer = null; + return; + } + + _updateClip(); + final Path offsetPath = _clip!.shift(offset); + bool paintShadows = true; + assert(() { + if (debugDisableShadows) { + if (elevation > 0.0) { + context.canvas.drawPath( + offsetPath, + Paint() + ..color = shadowColor + ..style = PaintingStyle.stroke + ..strokeWidth = elevation * 2.0, + ); + } + paintShadows = false; + } + return true; + }()); + + final Canvas canvas = context.canvas; + if (elevation != 0.0 && paintShadows) { + canvas.drawShadow( + offsetPath, + shadowColor, + elevation, + color.alpha != 0xFF, + ); + } + final bool usesSaveLayer = clipBehavior == Clip.antiAliasWithSaveLayer; + if (!usesSaveLayer) { + canvas.drawPath( + offsetPath, + Paint()..color = color + ); + } + layer = context.pushClipPath( + needsCompositing, + offset, + Offset.zero & size, + _clip!, + (PaintingContext context, Offset offset) { + if (usesSaveLayer) { + // If we want to avoid the bleeding edge artifact + // (https://github.com/flutter/flutter/issues/18057#issue-328003931) + // using saveLayer, we have to call drawPaint instead of drawPath as + // anti-aliased drawPath will always have such artifacts. + context.canvas.drawPaint( Paint()..color = color); + } + super.paint(context, offset); + }, + oldLayer: layer as ClipPathLayer?, + clipBehavior: clipBehavior, + ); + + assert(() { + layer?.debugCreator = debugCreator; + return true; + }()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DiagnosticsProperty<CustomClipper<Path>>('clipper', clipper)); + } +} + +/// Where to paint a box decoration. +enum DecorationPosition { + /// Paint the box decoration behind the children. + background, + + /// Paint the box decoration in front of the children. + foreground, +} + +/// Paints a [Decoration] either before or after its child paints. +class RenderDecoratedBox extends RenderProxyBox { + /// Creates a decorated box. + /// + /// The [decoration], [position], and [configuration] arguments must not be + /// null. By default the decoration paints behind the child. + /// + /// The [ImageConfiguration] will be passed to the decoration (with the size + /// filled in) to let it resolve images. + RenderDecoratedBox({ + required Decoration decoration, + DecorationPosition position = DecorationPosition.background, + ImageConfiguration configuration = ImageConfiguration.empty, + RenderBox? child, + }) : _decoration = decoration, + _position = position, + _configuration = configuration, + super(child); + + BoxPainter? _painter; + + /// What decoration to paint. + /// + /// Commonly a [BoxDecoration]. + Decoration get decoration => _decoration; + Decoration _decoration; + set decoration(Decoration value) { + if (value == _decoration) { + return; + } + _painter?.dispose(); + _painter = null; + _decoration = value; + markNeedsPaint(); + } + + /// Whether to paint the box decoration behind or in front of the child. + DecorationPosition get position => _position; + DecorationPosition _position; + set position(DecorationPosition value) { + if (value == _position) { + return; + } + _position = value; + markNeedsPaint(); + } + + /// The settings to pass to the decoration when painting, so that it can + /// resolve images appropriately. See [ImageProvider.resolve] and + /// [BoxPainter.paint]. + /// + /// The [ImageConfiguration.textDirection] field is also used by + /// direction-sensitive [Decoration]s for painting and hit-testing. + ImageConfiguration get configuration => _configuration; + ImageConfiguration _configuration; + set configuration(ImageConfiguration value) { + if (value == _configuration) { + return; + } + _configuration = value; + markNeedsPaint(); + } + + @override + void detach() { + _painter?.dispose(); + _painter = null; + super.detach(); + // Since we're disposing of our painter, we won't receive change + // notifications. We mark ourselves as needing paint so that we will + // resubscribe to change notifications. If we didn't do this, then, for + // example, animated GIFs would stop animating when a DecoratedBox gets + // moved around the tree due to GlobalKey reparenting. + markNeedsPaint(); + } + + @override + void dispose() { + _painter?.dispose(); + super.dispose(); + } + + @override + bool hitTestSelf(Offset position) { + return _decoration.hitTest(size, position, textDirection: configuration.textDirection); + } + + @override + void paint(PaintingContext context, Offset offset) { + _painter ??= _decoration.createBoxPainter(markNeedsPaint); + final ImageConfiguration filledConfiguration = configuration.copyWith(size: size); + if (position == DecorationPosition.background) { + int? debugSaveCount; + assert(() { + debugSaveCount = context.canvas.getSaveCount(); + return true; + }()); + _painter!.paint(context.canvas, offset, filledConfiguration); + assert(() { + if (debugSaveCount != context.canvas.getSaveCount()) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('${_decoration.runtimeType} painter had mismatching save and restore calls.'), + ErrorDescription( + 'Before painting the decoration, the canvas save count was $debugSaveCount. ' + 'After painting it, the canvas save count was ${context.canvas.getSaveCount()}. ' + 'Every call to save() or saveLayer() must be matched by a call to restore().', + ), + DiagnosticsProperty<Decoration>('The decoration was', decoration, style: DiagnosticsTreeStyle.errorProperty), + DiagnosticsProperty<BoxPainter>('The painter was', _painter, style: DiagnosticsTreeStyle.errorProperty), + ]); + } + return true; + }()); + if (decoration.isComplex) { + context.setIsComplexHint(); + } + } + super.paint(context, offset); + if (position == DecorationPosition.foreground) { + _painter!.paint(context.canvas, offset, filledConfiguration); + if (decoration.isComplex) { + context.setIsComplexHint(); + } + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(_decoration.toDiagnosticsNode(name: 'decoration')); + properties.add(DiagnosticsProperty<ImageConfiguration>('configuration', configuration)); + } +} + +/// Applies a transformation before painting its child. +class RenderTransform extends RenderProxyBox { + /// Creates a render object that transforms its child. + RenderTransform({ + required Matrix4 transform, + Offset? origin, + AlignmentGeometry? alignment, + TextDirection? textDirection, + this.transformHitTests = true, + FilterQuality? filterQuality, + RenderBox? child, + }) : super(child) { + this.transform = transform; + this.alignment = alignment; + this.textDirection = textDirection; + this.filterQuality = filterQuality; + this.origin = origin; + } + + /// The origin of the coordinate system (relative to the upper left corner of + /// this render object) in which to apply the matrix. + /// + /// Setting an origin is equivalent to conjugating the transform matrix by a + /// translation. This property is provided just for convenience. + Offset? get origin => _origin; + Offset? _origin; + set origin(Offset? value) { + if (_origin == value) { + return; + } + _origin = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// The alignment of the origin, relative to the size of the box. + /// + /// This is equivalent to setting an origin based on the size of the box. + /// If it is specified at the same time as an offset, both are applied. + /// + /// An [AlignmentDirectional.centerStart] value is the same as an [Alignment] + /// whose [Alignment.x] value is `-1.0` if [textDirection] is + /// [TextDirection.ltr], and `1.0` if [textDirection] is [TextDirection.rtl]. + /// Similarly [AlignmentDirectional.centerEnd] is the same as an [Alignment] + /// whose [Alignment.x] value is `1.0` if [textDirection] is + /// [TextDirection.ltr], and `-1.0` if [textDirection] is [TextDirection.rtl]. + AlignmentGeometry? get alignment => _alignment; + AlignmentGeometry? _alignment; + set alignment(AlignmentGeometry? value) { + if (_alignment == value) { + return; + } + _alignment = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// The text direction with which to resolve [alignment]. + /// + /// This may be changed to null, but only after [alignment] has been changed + /// to a value that does not depend on the direction. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + @override + bool get alwaysNeedsCompositing => child != null && _filterQuality != null; + + /// When set to true, hit tests are performed based on the position of the + /// child as it is painted. When set to false, hit tests are performed + /// ignoring the transformation. + /// + /// [applyPaintTransform], and therefore [localToGlobal] and [globalToLocal], + /// always honor the transformation, regardless of the value of this property. + bool transformHitTests; + + Matrix4? _transform; + /// The matrix to transform the child by during painting. The provided value + /// is copied on assignment. + /// + /// There is no getter for [transform], because [Matrix4] is mutable, and + /// mutations outside of the control of the render object could not reliably + /// be reflected in the rendering. + set transform(Matrix4 value) { // ignore: avoid_setters_without_getters + if (_transform == value) { + return; + } + _transform = Matrix4.copy(value); + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// The filter quality with which to apply the transform as a bitmap operation. + /// + /// {@macro flutter.widgets.Transform.optional.FilterQuality} + FilterQuality? get filterQuality => _filterQuality; + FilterQuality? _filterQuality; + set filterQuality(FilterQuality? value) { + if (_filterQuality == value) { + return; + } + final bool didNeedCompositing = alwaysNeedsCompositing; + _filterQuality = value; + if (didNeedCompositing != alwaysNeedsCompositing) { + markNeedsCompositingBitsUpdate(); + } + markNeedsPaint(); + } + + /// Sets the transform to the identity matrix. + void setIdentity() { + _transform!.setIdentity(); + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// Concatenates a rotation about the x axis into the transform. + void rotateX(double radians) { + _transform!.rotateX(radians); + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// Concatenates a rotation about the y axis into the transform. + void rotateY(double radians) { + _transform!.rotateY(radians); + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// Concatenates a rotation about the z axis into the transform. + void rotateZ(double radians) { + _transform!.rotateZ(radians); + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// Concatenates a translation by (x, y, z) into the transform. + void translate(double x, [ double y = 0.0, double z = 0.0 ]) { + _transform!.translate(x, y, z); + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + /// Concatenates a scale into the transform. + void scale(double x, [ double? y, double? z ]) { + _transform!.scale(x, y, z); + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + Matrix4? get _effectiveTransform { + final Alignment? resolvedAlignment = alignment?.resolve(textDirection); + if (_origin == null && resolvedAlignment == null) { + return _transform; + } + final Matrix4 result = Matrix4.identity(); + if (_origin != null) { + result.translate(_origin!.dx, _origin!.dy); + } + Offset? translation; + if (resolvedAlignment != null) { + translation = resolvedAlignment.alongSize(size); + result.translate(translation.dx, translation.dy); + } + result.multiply(_transform!); + if (resolvedAlignment != null) { + result.translate(-translation!.dx, -translation.dy); + } + if (_origin != null) { + result.translate(-_origin!.dx, -_origin!.dy); + } + return result; + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + // RenderTransform objects don't check if they are + // themselves hit, because it's confusing to think about + // how the untransformed size and the child's transformed + // position interact. + return hitTestChildren(result, position: position); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + assert(!transformHitTests || _effectiveTransform != null); + return result.addWithPaintTransform( + transform: transformHitTests ? _effectiveTransform : null, + position: position, + hitTest: (BoxHitTestResult result, Offset position) { + return super.hitTestChildren(result, position: position); + }, + ); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + final Matrix4 transform = _effectiveTransform!; + if (filterQuality == null) { + final Offset? childOffset = MatrixUtils.getAsTranslation(transform); + if (childOffset == null) { + // if the matrix is singular the children would be compressed to a line or + // single point, instead short-circuit and paint nothing. + final double det = transform.determinant(); + if (det == 0 || !det.isFinite) { + layer = null; + return; + } + layer = context.pushTransform( + needsCompositing, + offset, + transform, + super.paint, + oldLayer: layer is TransformLayer ? layer as TransformLayer? : null, + ); + } else { + super.paint(context, offset + childOffset); + layer = null; + } + } else { + final Matrix4 effectiveTransform = Matrix4.translationValues(offset.dx, offset.dy, 0.0) + ..multiply(transform)..translate(-offset.dx, -offset.dy); + final ui.ImageFilter filter = ui.ImageFilter.matrix( + effectiveTransform.storage, + filterQuality: filterQuality!, + ); + if (layer is ImageFilterLayer) { + final ImageFilterLayer filterLayer = layer! as ImageFilterLayer; + filterLayer.imageFilter = filter; + } else { + layer = ImageFilterLayer(imageFilter: filter); + } + context.pushLayer(layer!, super.paint, offset); + assert(() { + layer!.debugCreator = debugCreator; + return true; + }()); + } + } + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + transform.multiply(_effectiveTransform!); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(TransformProperty('transform matrix', _transform)); + properties.add(DiagnosticsProperty<Offset>('origin', origin)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('transformHitTests', transformHitTests)); + } +} + +/// Scales and positions its child within itself according to [fit]. +class RenderFittedBox extends RenderProxyBox { + /// Scales and positions its child within itself. + RenderFittedBox({ + BoxFit fit = BoxFit.contain, + AlignmentGeometry alignment = Alignment.center, + TextDirection? textDirection, + RenderBox? child, + Clip clipBehavior = Clip.none, + }) : _fit = fit, + _alignment = alignment, + _textDirection = textDirection, + _clipBehavior = clipBehavior, + super(child); + + Alignment? _resolvedAlignment; + + void _resolve() { + if (_resolvedAlignment != null) { + return; + } + _resolvedAlignment = alignment.resolve(textDirection); + } + + void _markNeedResolution() { + _resolvedAlignment = null; + markNeedsPaint(); + } + + bool _fitAffectsLayout(BoxFit fit) { + switch (fit) { + case BoxFit.scaleDown: + return true; + case BoxFit.contain: + case BoxFit.cover: + case BoxFit.fill: + case BoxFit.fitHeight: + case BoxFit.fitWidth: + case BoxFit.none: + return false; + } + } + + /// How to inscribe the child into the space allocated during layout. + BoxFit get fit => _fit; + BoxFit _fit; + set fit(BoxFit value) { + if (_fit == value) { + return; + } + final BoxFit lastFit = _fit; + _fit = value; + if (_fitAffectsLayout(lastFit) || _fitAffectsLayout(value)) { + markNeedsLayout(); + } else { + _clearPaintData(); + markNeedsPaint(); + } + } + + /// How to align the child within its parent's bounds. + /// + /// An alignment of (0.0, 0.0) aligns the child to the top-left corner of its + /// parent's bounds. An alignment of (1.0, 0.5) aligns the child to the middle + /// of the right edge of its parent's bounds. + /// + /// If this is set to an [AlignmentDirectional] object, then + /// [textDirection] must not be null. + AlignmentGeometry get alignment => _alignment; + AlignmentGeometry _alignment; + set alignment(AlignmentGeometry value) { + if (_alignment == value) { + return; + } + _alignment = value; + _clearPaintData(); + _markNeedResolution(); + } + + /// The text direction with which to resolve [alignment]. + /// + /// This may be changed to null, but only after [alignment] has been changed + /// to a value that does not depend on the direction. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + _clearPaintData(); + _markNeedResolution(); + } + + // TODO(ianh): The intrinsic dimensions of this box are wrong. + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (child != null) { + final Size childSize = child!.getDryLayout(const BoxConstraints()); + + // During [RenderObject.debugCheckingIntrinsics] a child that doesn't + // support dry layout may provide us with an invalid size that triggers + // assertions if we try to work with it. Instead of throwing, we bail + // out early in that case. + bool invalidChildSize = false; + assert(() { + if (RenderObject.debugCheckingIntrinsics && childSize.width * childSize.height == 0.0) { + invalidChildSize = true; + } + return true; + }()); + if (invalidChildSize) { + assert(debugCannotComputeDryLayout( + reason: 'Child provided invalid size of $childSize.', + )); + return Size.zero; + } + + switch (fit) { + case BoxFit.scaleDown: + final BoxConstraints sizeConstraints = constraints.loosen(); + final Size unconstrainedSize = sizeConstraints.constrainSizeAndAttemptToPreserveAspectRatio(childSize); + return constraints.constrain(unconstrainedSize); + case BoxFit.contain: + case BoxFit.cover: + case BoxFit.fill: + case BoxFit.fitHeight: + case BoxFit.fitWidth: + case BoxFit.none: + return constraints.constrainSizeAndAttemptToPreserveAspectRatio(childSize); + } + } else { + return constraints.smallest; + } + } + + @override + void performLayout() { + if (child != null) { + child!.layout(const BoxConstraints(), parentUsesSize: true); + switch (fit) { + case BoxFit.scaleDown: + final BoxConstraints sizeConstraints = constraints.loosen(); + final Size unconstrainedSize = sizeConstraints.constrainSizeAndAttemptToPreserveAspectRatio(child!.size); + size = constraints.constrain(unconstrainedSize); + case BoxFit.contain: + case BoxFit.cover: + case BoxFit.fill: + case BoxFit.fitHeight: + case BoxFit.fitWidth: + case BoxFit.none: + size = constraints.constrainSizeAndAttemptToPreserveAspectRatio(child!.size); + } + _clearPaintData(); + } else { + size = constraints.smallest; + } + } + + bool? _hasVisualOverflow; + Matrix4? _transform; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.none; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + void _clearPaintData() { + _hasVisualOverflow = null; + _transform = null; + } + + void _updatePaintData() { + if (_transform != null) { + return; + } + + if (child == null) { + _hasVisualOverflow = false; + _transform = Matrix4.identity(); + } else { + _resolve(); + final Size childSize = child!.size; + final FittedSizes sizes = applyBoxFit(_fit, childSize, size); + final double scaleX = sizes.destination.width / sizes.source.width; + final double scaleY = sizes.destination.height / sizes.source.height; + final Rect sourceRect = _resolvedAlignment!.inscribe(sizes.source, Offset.zero & childSize); + final Rect destinationRect = _resolvedAlignment!.inscribe(sizes.destination, Offset.zero & size); + _hasVisualOverflow = sourceRect.width < childSize.width || sourceRect.height < childSize.height; + assert(scaleX.isFinite && scaleY.isFinite); + _transform = Matrix4.translationValues(destinationRect.left, destinationRect.top, 0.0) + ..scale(scaleX, scaleY, 1.0) + ..translate(-sourceRect.left, -sourceRect.top); + assert(_transform!.storage.every((double value) => value.isFinite)); + } + } + + TransformLayer? _paintChildWithTransform(PaintingContext context, Offset offset) { + final Offset? childOffset = MatrixUtils.getAsTranslation(_transform!); + if (childOffset == null) { + return context.pushTransform( + needsCompositing, + offset, + _transform!, + super.paint, + oldLayer: layer is TransformLayer ? layer! as TransformLayer : null, + ); + } else { + super.paint(context, offset + childOffset); + } + return null; + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child == null || size.isEmpty || child!.size.isEmpty) { + return; + } + _updatePaintData(); + assert(child != null); + if (_hasVisualOverflow! && clipBehavior != Clip.none) { + layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + _paintChildWithTransform, + oldLayer: layer is ClipRectLayer ? layer! as ClipRectLayer : null, + clipBehavior: clipBehavior, + ); + } else { + layer = _paintChildWithTransform(context, offset); + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + if (size.isEmpty || (child?.size.isEmpty ?? false)) { + return false; + } + _updatePaintData(); + return result.addWithPaintTransform( + transform: _transform, + position: position, + hitTest: (BoxHitTestResult result, Offset position) { + return super.hitTestChildren(result, position: position); + }, + ); + } + + @override + bool paintsChild(RenderBox child) { + assert(child.parent == this); + return !size.isEmpty && !child.size.isEmpty; + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + if (!paintsChild(child)) { + transform.setZero(); + } else { + _updatePaintData(); + transform.multiply(_transform!); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<BoxFit>('fit', fit)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + } +} + +/// Applies a translation transformation before painting its child. +/// +/// The translation is expressed as an [Offset] scaled to the child's size. For +/// example, an [Offset] with a `dx` of 0.25 will result in a horizontal +/// translation of one quarter the width of the child. +/// +/// Hit tests will only be detected inside the bounds of the +/// [RenderFractionalTranslation], even if the contents are offset such that +/// they overflow. +class RenderFractionalTranslation extends RenderProxyBox { + /// Creates a render object that translates its child's painting. + RenderFractionalTranslation({ + required Offset translation, + this.transformHitTests = true, + RenderBox? child, + }) : _translation = translation, + super(child); + + /// The translation to apply to the child, scaled to the child's size. + /// + /// For example, an [Offset] with a `dx` of 0.25 will result in a horizontal + /// translation of one quarter the width of the child. + Offset get translation => _translation; + Offset _translation; + set translation(Offset value) { + if (_translation == value) { + return; + } + _translation = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + // RenderFractionalTranslation objects don't check if they are + // themselves hit, because it's confusing to think about + // how the untransformed size and the child's transformed + // position interact. + return hitTestChildren(result, position: position); + } + + /// When set to true, hit tests are performed based on the position of the + /// child as it is painted. When set to false, hit tests are performed + /// ignoring the transformation. + /// + /// applyPaintTransform(), and therefore localToGlobal() and globalToLocal(), + /// always honor the transformation, regardless of the value of this property. + bool transformHitTests; + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + assert(!debugNeedsLayout); + return result.addWithPaintOffset( + offset: transformHitTests + ? Offset(translation.dx * size.width, translation.dy * size.height) + : null, + position: position, + hitTest: (BoxHitTestResult result, Offset position) { + return super.hitTestChildren(result, position: position); + }, + ); + } + + @override + void paint(PaintingContext context, Offset offset) { + assert(!debugNeedsLayout); + if (child != null) { + super.paint(context, Offset( + offset.dx + translation.dx * size.width, + offset.dy + translation.dy * size.height, + )); + } + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + transform.translate( + translation.dx * size.width, + translation.dy * size.height, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Offset>('translation', translation)); + properties.add(DiagnosticsProperty<bool>('transformHitTests', transformHitTests)); + } +} + +/// Signature for listening to [PointerDownEvent] events. +/// +/// Used by [Listener] and [RenderPointerListener]. +typedef PointerDownEventListener = void Function(PointerDownEvent event); + +/// Signature for listening to [PointerMoveEvent] events. +/// +/// Used by [Listener] and [RenderPointerListener]. +typedef PointerMoveEventListener = void Function(PointerMoveEvent event); + +/// Signature for listening to [PointerUpEvent] events. +/// +/// Used by [Listener] and [RenderPointerListener]. +typedef PointerUpEventListener = void Function(PointerUpEvent event); + +/// Signature for listening to [PointerCancelEvent] events. +/// +/// Used by [Listener] and [RenderPointerListener]. +typedef PointerCancelEventListener = void Function(PointerCancelEvent event); + +/// Signature for listening to [PointerPanZoomStartEvent] events. +/// +/// Used by [Listener] and [RenderPointerListener]. +typedef PointerPanZoomStartEventListener = void Function(PointerPanZoomStartEvent event); + +/// Signature for listening to [PointerPanZoomUpdateEvent] events. +/// +/// Used by [Listener] and [RenderPointerListener]. +typedef PointerPanZoomUpdateEventListener = void Function(PointerPanZoomUpdateEvent event); + +/// Signature for listening to [PointerPanZoomEndEvent] events. +/// +/// Used by [Listener] and [RenderPointerListener]. +typedef PointerPanZoomEndEventListener = void Function(PointerPanZoomEndEvent event); + +/// Signature for listening to [PointerSignalEvent] events. +/// +/// Used by [Listener] and [RenderPointerListener]. +typedef PointerSignalEventListener = void Function(PointerSignalEvent event); + +/// Calls callbacks in response to common pointer events. +/// +/// It responds to events that can construct gestures, such as when the +/// pointer is pointer is pressed and moved, and then released or canceled. +/// +/// It does not respond to events that are exclusive to mouse, such as when the +/// mouse enters and exits a region without pressing any buttons. For +/// these events, use [RenderMouseRegion]. +/// +/// If it has a child, defers to the child for sizing behavior. +/// +/// If it does not have a child, grows to fit the parent-provided constraints. +class RenderPointerListener extends RenderProxyBoxWithHitTestBehavior { + /// Creates a render object that forwards pointer events to callbacks. + /// + /// The [behavior] argument defaults to [HitTestBehavior.deferToChild]. + RenderPointerListener({ + this.onPointerDown, + this.onPointerMove, + this.onPointerUp, + this.onPointerHover, + this.onPointerCancel, + this.onPointerPanZoomStart, + this.onPointerPanZoomUpdate, + this.onPointerPanZoomEnd, + this.onPointerSignal, + super.behavior, + super.child, + }); + + /// Called when a pointer comes into contact with the screen (for touch + /// pointers), or has its button pressed (for mouse pointers) at this widget's + /// location. + PointerDownEventListener? onPointerDown; + + /// Called when a pointer that triggered an [onPointerDown] changes position. + PointerMoveEventListener? onPointerMove; + + /// Called when a pointer that triggered an [onPointerDown] is no longer in + /// contact with the screen. + PointerUpEventListener? onPointerUp; + + /// Called when a pointer that has not an [onPointerDown] changes position. + PointerHoverEventListener? onPointerHover; + + /// Called when the input from a pointer that triggered an [onPointerDown] is + /// no longer directed towards this receiver. + PointerCancelEventListener? onPointerCancel; + + /// Called when a pan/zoom begins such as from a trackpad gesture. + PointerPanZoomStartEventListener? onPointerPanZoomStart; + + /// Called when a pan/zoom is updated. + PointerPanZoomUpdateEventListener? onPointerPanZoomUpdate; + + /// Called when a pan/zoom finishes. + PointerPanZoomEndEventListener? onPointerPanZoomEnd; + + /// Called when a pointer signal occurs over this object. + PointerSignalEventListener? onPointerSignal; + + @override + Size computeSizeForNoChild(BoxConstraints constraints) { + return constraints.biggest; + } + + @override + void handleEvent(PointerEvent event, HitTestEntry entry) { + assert(debugHandleEvent(event, entry)); + if (event is PointerDownEvent) { + return onPointerDown?.call(event); + } + if (event is PointerMoveEvent) { + return onPointerMove?.call(event); + } + if (event is PointerUpEvent) { + return onPointerUp?.call(event); + } + if (event is PointerHoverEvent) { + return onPointerHover?.call(event); + } + if (event is PointerCancelEvent) { + return onPointerCancel?.call(event); + } + if (event is PointerPanZoomStartEvent) { + return onPointerPanZoomStart?.call(event); + } + if (event is PointerPanZoomUpdateEvent) { + return onPointerPanZoomUpdate?.call(event); + } + if (event is PointerPanZoomEndEvent) { + return onPointerPanZoomEnd?.call(event); + } + if (event is PointerSignalEvent) { + return onPointerSignal?.call(event); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagsSummary<Function?>( + 'listeners', + <String, Function?>{ + 'down': onPointerDown, + 'move': onPointerMove, + 'up': onPointerUp, + 'hover': onPointerHover, + 'cancel': onPointerCancel, + 'panZoomStart': onPointerPanZoomStart, + 'panZoomUpdate': onPointerPanZoomUpdate, + 'panZoomEnd': onPointerPanZoomEnd, + 'signal': onPointerSignal, + }, + ifEmpty: '<none>', + )); + } +} + +/// Calls callbacks in response to pointer events that are exclusive to mice. +/// +/// It responds to events that are related to hovering, i.e. when the mouse +/// enters, exits (with or without pressing buttons), or moves over a region +/// without pressing buttons. +/// +/// It does not respond to common events that construct gestures, such as when +/// the pointer is pressed, moved, then released or canceled. For these events, +/// use [RenderPointerListener]. +/// +/// If it has a child, it defers to the child for sizing behavior. +/// +/// If it does not have a child, it grows to fit the parent-provided constraints. +/// +/// See also: +/// +/// * [MouseRegion], a widget that listens to hover events using +/// [RenderMouseRegion]. +class RenderMouseRegion extends RenderProxyBoxWithHitTestBehavior implements MouseTrackerAnnotation { + /// Creates a render object that forwards pointer events to callbacks. + /// + /// All parameters are optional. By default this method creates an opaque + /// mouse region with no callbacks and cursor being [MouseCursor.defer]. + RenderMouseRegion({ + this.onEnter, + this.onHover, + this.onExit, + MouseCursor cursor = MouseCursor.defer, + bool validForMouseTracker = true, + bool opaque = true, + super.child, + HitTestBehavior? hitTestBehavior = HitTestBehavior.opaque, + }) : _cursor = cursor, + _validForMouseTracker = validForMouseTracker, + _opaque = opaque, + super(behavior: hitTestBehavior ?? HitTestBehavior.opaque); + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + return super.hitTest(result, position: position) && _opaque; + } + + @override + void handleEvent(PointerEvent event, HitTestEntry entry) { + assert(debugHandleEvent(event, entry)); + if (onHover != null && event is PointerHoverEvent) { + return onHover!(event); + } + } + + /// Whether this object should prevent [RenderMouseRegion]s visually behind it + /// from detecting the pointer, thus affecting how their [onHover], [onEnter], + /// and [onExit] behave. + /// + /// If [opaque] is true, this object will absorb the mouse pointer and + /// prevent this object's siblings (or any other objects that are not + /// ancestors or descendants of this object) from detecting the mouse + /// pointer even when the pointer is within their areas. + /// + /// If [opaque] is false, this object will not affect how [RenderMouseRegion]s + /// behind it behave, which will detect the mouse pointer as long as the + /// pointer is within their areas. + /// + /// This defaults to true. + bool get opaque => _opaque; + bool _opaque; + set opaque(bool value) { + if (_opaque != value) { + _opaque = value; + // Trigger [MouseTracker]'s device update to recalculate mouse states. + markNeedsPaint(); + } + } + + /// How to behave during hit testing. + /// + /// This defaults to [HitTestBehavior.opaque] if null. + HitTestBehavior? get hitTestBehavior => behavior; + set hitTestBehavior(HitTestBehavior? value) { + final HitTestBehavior newValue = value ?? HitTestBehavior.opaque; + if (behavior != newValue) { + behavior = newValue; + // Trigger [MouseTracker]'s device update to recalculate mouse states. + markNeedsPaint(); + } + } + + @override + PointerEnterEventListener? onEnter; + + /// Triggered when a pointer has moved onto or within the region without + /// buttons pressed. + /// + /// This callback is not triggered by the movement of the object. + PointerHoverEventListener? onHover; + + @override + PointerExitEventListener? onExit; + + @override + MouseCursor get cursor => _cursor; + MouseCursor _cursor; + set cursor(MouseCursor value) { + if (_cursor != value) { + _cursor = value; + // A repaint is needed in order to trigger a device update of + // [MouseTracker] so that this new value can be found. + markNeedsPaint(); + } + } + + @override + bool get validForMouseTracker => _validForMouseTracker; + bool _validForMouseTracker; + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _validForMouseTracker = true; + } + + @override + void detach() { + // It's possible that the renderObject be detached during mouse events + // dispatching, set the [MouseTrackerAnnotation.validForMouseTracker] false to prevent + // the callbacks from being called. + _validForMouseTracker = false; + super.detach(); + } + + @override + Size computeSizeForNoChild(BoxConstraints constraints) { + return constraints.biggest; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagsSummary<Function?>( + 'listeners', + <String, Function?>{ + 'enter': onEnter, + 'hover': onHover, + 'exit': onExit, + }, + ifEmpty: '<none>', + )); + properties.add(DiagnosticsProperty<MouseCursor>('cursor', cursor, defaultValue: MouseCursor.defer)); + properties.add(DiagnosticsProperty<bool>('opaque', opaque, defaultValue: true)); + properties.add(FlagProperty('validForMouseTracker', value: validForMouseTracker, defaultValue: true, ifFalse: 'invalid for MouseTracker')); + } +} + +/// Creates a separate display list for its child. +/// +/// This render object creates a separate display list for its child, which +/// can improve performance if the subtree repaints at different times than +/// the surrounding parts of the tree. Specifically, when the child does not +/// repaint but its parent does, we can re-use the display list we recorded +/// previously. Similarly, when the child repaints but the surround tree does +/// not, we can re-record its display list without re-recording the display list +/// for the surround tree. +/// +/// In some cases, it is necessary to place _two_ (or more) repaint boundaries +/// to get a useful effect. Consider, for example, an e-mail application that +/// shows an unread count and a list of e-mails. Whenever a new e-mail comes in, +/// the list would update, but so would the unread count. If only one of these +/// two parts of the application was behind a repaint boundary, the entire +/// application would repaint each time. On the other hand, if both were behind +/// a repaint boundary, a new e-mail would only change those two parts of the +/// application and the rest of the application would not repaint. +/// +/// To tell if a particular RenderRepaintBoundary is useful, run your +/// application in debug mode, interacting with it in typical ways, and then +/// call [debugDumpRenderTree]. Each RenderRepaintBoundary will include the +/// ratio of cases where the repaint boundary was useful vs the cases where it +/// was not. These counts can also be inspected programmatically using +/// [debugAsymmetricPaintCount] and [debugSymmetricPaintCount] respectively. +class RenderRepaintBoundary extends RenderProxyBox { + /// Creates a repaint boundary around [child]. + RenderRepaintBoundary({ RenderBox? child }) : super(child); + + @override + bool get isRepaintBoundary => true; + + /// Capture an image of the current state of this render object and its + /// children. + /// + /// The returned [ui.Image] has uncompressed raw RGBA bytes in the dimensions + /// of the render object, multiplied by the [pixelRatio]. + /// + /// To use [toImage], the render object must have gone through the paint phase + /// (i.e. [debugNeedsPaint] must be false). + /// + /// The [pixelRatio] describes the scale between the logical pixels and the + /// size of the output image. It is independent of the + /// [dart:ui.FlutterView.devicePixelRatio] for the device, so specifying 1.0 + /// (the default) will give you a 1:1 mapping between logical pixels and the + /// output pixels in the image. + /// + /// {@tool snippet} + /// + /// The following is an example of how to go from a `GlobalKey` on a + /// `RepaintBoundary` to a PNG: + /// + /// ```dart + /// class PngHome extends StatefulWidget { + /// const PngHome({super.key}); + /// + /// @override + /// State<PngHome> createState() => _PngHomeState(); + /// } + /// + /// class _PngHomeState extends State<PngHome> { + /// GlobalKey globalKey = GlobalKey(); + /// + /// Future<void> _capturePng() async { + /// final RenderRepaintBoundary boundary = globalKey.currentContext!.findRenderObject()! as RenderRepaintBoundary; + /// final ui.Image image = await boundary.toImage(); + /// final ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png); + /// final Uint8List pngBytes = byteData!.buffer.asUint8List(); + /// print(pngBytes); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// return RepaintBoundary( + /// key: globalKey, + /// child: Center( + /// child: TextButton( + /// onPressed: _capturePng, + /// child: const Text('Hello World', textDirection: TextDirection.ltr), + /// ), + /// ), + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [OffsetLayer.toImage] for a similar API at the layer level. + /// * [dart:ui.Scene.toImage] for more information about the image returned. + Future<ui.Image> toImage({ double pixelRatio = 1.0 }) { + assert(!debugNeedsPaint); + final OffsetLayer offsetLayer = layer! as OffsetLayer; + return offsetLayer.toImage(Offset.zero & size, pixelRatio: pixelRatio); + } + + /// Capture an image of the current state of this render object and its + /// children synchronously. + /// + /// The returned [ui.Image] has uncompressed raw RGBA bytes in the dimensions + /// of the render object, multiplied by the [pixelRatio]. + /// + /// To use [toImageSync], the render object must have gone through the paint phase + /// (i.e. [debugNeedsPaint] must be false). + /// + /// The [pixelRatio] describes the scale between the logical pixels and the + /// size of the output image. It is independent of the + /// [dart:ui.FlutterView.devicePixelRatio] for the device, so specifying 1.0 + /// (the default) will give you a 1:1 mapping between logical pixels and the + /// output pixels in the image. + /// + /// This API functions like [toImage], except that rasterization begins eagerly + /// on the raster thread and the image is returned before this is completed. + /// + /// {@tool snippet} + /// + /// The following is an example of how to go from a `GlobalKey` on a + /// `RepaintBoundary` to an image handle: + /// + /// ```dart + /// class ImageCaptureHome extends StatefulWidget { + /// const ImageCaptureHome({super.key}); + /// + /// @override + /// State<ImageCaptureHome> createState() => _ImageCaptureHomeState(); + /// } + /// + /// class _ImageCaptureHomeState extends State<ImageCaptureHome> { + /// GlobalKey globalKey = GlobalKey(); + /// + /// void _captureImage() { + /// final RenderRepaintBoundary boundary = globalKey.currentContext!.findRenderObject()! as RenderRepaintBoundary; + /// final ui.Image image = boundary.toImageSync(); + /// print('Image dimensions: ${image.width}x${image.height}'); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// return RepaintBoundary( + /// key: globalKey, + /// child: Center( + /// child: TextButton( + /// onPressed: _captureImage, + /// child: const Text('Hello World', textDirection: TextDirection.ltr), + /// ), + /// ), + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [OffsetLayer.toImageSync] for a similar API at the layer level. + /// * [dart:ui.Scene.toImageSync] for more information about the image returned. + ui.Image toImageSync({ double pixelRatio = 1.0 }) { + assert(!debugNeedsPaint); + final OffsetLayer offsetLayer = layer! as OffsetLayer; + return offsetLayer.toImageSync(Offset.zero & size, pixelRatio: pixelRatio); + } + + /// The number of times that this render object repainted at the same time as + /// its parent. Repaint boundaries are only useful when the parent and child + /// paint at different times. When both paint at the same time, the repaint + /// boundary is redundant, and may be actually making performance worse. + /// + /// Only valid when asserts are enabled. In release builds, always returns + /// zero. + /// + /// Can be reset using [debugResetMetrics]. See [debugAsymmetricPaintCount] + /// for the corresponding count of times where only the parent or only the + /// child painted. + int get debugSymmetricPaintCount => _debugSymmetricPaintCount; + int _debugSymmetricPaintCount = 0; + + /// The number of times that either this render object repainted without the + /// parent being painted, or the parent repainted without this object being + /// painted. When a repaint boundary is used at a seam in the render tree + /// where the parent tends to repaint at entirely different times than the + /// child, it can improve performance by reducing the number of paint + /// operations that have to be recorded each frame. + /// + /// Only valid when asserts are enabled. In release builds, always returns + /// zero. + /// + /// Can be reset using [debugResetMetrics]. See [debugSymmetricPaintCount] for + /// the corresponding count of times where both the parent and the child + /// painted together. + int get debugAsymmetricPaintCount => _debugAsymmetricPaintCount; + int _debugAsymmetricPaintCount = 0; + + /// Resets the [debugSymmetricPaintCount] and [debugAsymmetricPaintCount] + /// counts to zero. + /// + /// Only valid when asserts are enabled. Does nothing in release builds. + void debugResetMetrics() { + assert(() { + _debugSymmetricPaintCount = 0; + _debugAsymmetricPaintCount = 0; + return true; + }()); + } + + @override + void debugRegisterRepaintBoundaryPaint({ bool includedParent = true, bool includedChild = false }) { + assert(() { + if (includedParent && includedChild) { + _debugSymmetricPaintCount += 1; + } else { + _debugAsymmetricPaintCount += 1; + } + return true; + }()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + bool inReleaseMode = true; + assert(() { + inReleaseMode = false; + if (debugSymmetricPaintCount + debugAsymmetricPaintCount == 0) { + properties.add(MessageProperty('usefulness ratio', 'no metrics collected yet (never painted)')); + } else { + final double fraction = debugAsymmetricPaintCount / (debugSymmetricPaintCount + debugAsymmetricPaintCount); + final String diagnosis; + if (debugSymmetricPaintCount + debugAsymmetricPaintCount < 5) { + diagnosis = 'insufficient data to draw conclusion (less than five repaints)'; + } else if (fraction > 0.9) { + diagnosis = 'this is an outstandingly useful repaint boundary and should definitely be kept'; + } else if (fraction > 0.5) { + diagnosis = 'this is a useful repaint boundary and should be kept'; + } else if (fraction > 0.30) { + diagnosis = 'this repaint boundary is probably useful, but maybe it would be more useful in tandem with adding more repaint boundaries elsewhere'; + } else if (fraction > 0.1) { + diagnosis = 'this repaint boundary does sometimes show value, though currently not that often'; + } else if (debugAsymmetricPaintCount == 0) { + diagnosis = 'this repaint boundary is astoundingly ineffectual and should be removed'; + } else { + diagnosis = 'this repaint boundary is not very effective and should probably be removed'; + } + properties.add(PercentProperty('metrics', fraction, unit: 'useful', tooltip: '$debugSymmetricPaintCount bad vs $debugAsymmetricPaintCount good')); + properties.add(MessageProperty('diagnosis', diagnosis)); + } + return true; + }()); + if (inReleaseMode) { + properties.add(DiagnosticsNode.message('(run in debug mode to collect repaint boundary statistics)')); + } + } +} + +/// A render object that is invisible during hit testing. +/// +/// When [ignoring] is true, this render object (and its subtree) is invisible +/// to hit testing. It still consumes space during layout and paints its child +/// as usual. It just cannot be the target of located events, because its render +/// object returns false from [hitTest]. +/// +/// ## Semantics +/// +/// Using this class may also affect how the semantics subtree underneath is +/// collected. +/// +/// {@macro flutter.widgets.IgnorePointer.semantics} +/// +/// {@macro flutter.widgets.IgnorePointer.ignoringSemantics} +/// +/// See also: +/// +/// * [RenderAbsorbPointer], which takes the pointer events but prevents any +/// nodes in the subtree from seeing them. +class RenderIgnorePointer extends RenderProxyBox { + /// Creates a render object that is invisible to hit testing. + RenderIgnorePointer({ + RenderBox? child, + bool ignoring = true, + @Deprecated( + 'Use ExcludeSemantics or create a custom ignore pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + bool? ignoringSemantics, + }) : _ignoring = ignoring, + _ignoringSemantics = ignoringSemantics, + super(child); + + /// Whether this render object is ignored during hit testing. + /// + /// Regardless of whether this render object is ignored during hit testing, it + /// will still consume space during layout and be visible during painting. + /// + /// {@macro flutter.widgets.IgnorePointer.semantics} + bool get ignoring => _ignoring; + bool _ignoring; + set ignoring(bool value) { + if (value == _ignoring) { + return; + } + _ignoring = value; + if (ignoringSemantics == null) { + markNeedsSemanticsUpdate(); + } + } + + /// Whether the semantics of this render object is ignored when compiling the semantics tree. + /// + /// {@macro flutter.widgets.IgnorePointer.ignoringSemantics} + /// + /// See [SemanticsNode] for additional information about the semantics tree. + @Deprecated( + 'Use ExcludeSemantics or create a custom ignore pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + bool? get ignoringSemantics => _ignoringSemantics; + bool? _ignoringSemantics; + set ignoringSemantics(bool? value) { + if (value == _ignoringSemantics) { + return; + } + _ignoringSemantics = value; + markNeedsSemanticsUpdate(); + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + return !ignoring && super.hitTest(result, position: position); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (_ignoringSemantics ?? false) { + return; + } + super.visitChildrenForSemantics(visitor); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + // Do not block user interactions if _ignoringSemantics is false; otherwise, + // delegate to _ignoring + config.isBlockingUserActions = _ignoring && (_ignoringSemantics ?? true); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('ignoring', _ignoring)); + properties.add( + DiagnosticsProperty<bool>( + 'ignoringSemantics', + _ignoringSemantics, + description: _ignoringSemantics == null ? null : 'implicitly $_ignoringSemantics', + ), + ); + } +} + +/// Lays the child out as if it was in the tree, but without painting anything, +/// without making the child available for hit testing, and without taking any +/// room in the parent. +class RenderOffstage extends RenderProxyBox { + /// Creates an offstage render object. + RenderOffstage({ + bool offstage = true, + RenderBox? child, + }) : _offstage = offstage, + super(child); + + /// Whether the child is hidden from the rest of the tree. + /// + /// If true, the child is laid out as if it was in the tree, but without + /// painting anything, without making the child available for hit testing, and + /// without taking any room in the parent. + /// + /// If false, the child is included in the tree as normal. + bool get offstage => _offstage; + bool _offstage; + set offstage(bool value) { + if (value == _offstage) { + return; + } + _offstage = value; + markNeedsLayoutForSizedByParentChange(); + } + + @override + double computeMinIntrinsicWidth(double height) { + if (offstage) { + return 0.0; + } + return super.computeMinIntrinsicWidth(height); + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (offstage) { + return 0.0; + } + return super.computeMaxIntrinsicWidth(height); + } + + @override + double computeMinIntrinsicHeight(double width) { + if (offstage) { + return 0.0; + } + return super.computeMinIntrinsicHeight(width); + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (offstage) { + return 0.0; + } + return super.computeMaxIntrinsicHeight(width); + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + if (offstage) { + return null; + } + return super.computeDistanceToActualBaseline(baseline); + } + + @override + bool get sizedByParent => offstage; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (offstage) { + return constraints.smallest; + } + return super.computeDryLayout(constraints); + } + + @override + void performResize() { + assert(offstage); + super.performResize(); + } + + @override + void performLayout() { + if (offstage) { + child?.layout(constraints); + } else { + super.performLayout(); + } + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + return !offstage && super.hitTest(result, position: position); + } + + @override + bool paintsChild(RenderBox child) { + assert(child.parent == this); + return !offstage; + } + + @override + void paint(PaintingContext context, Offset offset) { + if (offstage) { + return; + } + super.paint(context, offset); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (offstage) { + return; + } + super.visitChildrenForSemantics(visitor); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('offstage', offstage)); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + if (child == null) { + return <DiagnosticsNode>[]; + } + return <DiagnosticsNode>[ + child!.toDiagnosticsNode( + name: 'child', + style: offstage ? DiagnosticsTreeStyle.offstage : DiagnosticsTreeStyle.sparse, + ), + ]; + } +} + +/// A render object that absorbs pointers during hit testing. +/// +/// When [absorbing] is true, this render object prevents its subtree from +/// receiving pointer events by terminating hit testing at itself. It still +/// consumes space during layout and paints its child as usual. It just prevents +/// its children from being the target of located events, because its render +/// object returns true from [hitTest]. +/// +/// ## Semantics +/// +/// Using this class may also affect how the semantics subtree underneath is +/// collected. +/// +/// {@macro flutter.widgets.AbsorbPointer.semantics} +/// +/// {@macro flutter.widgets.AbsorbPointer.ignoringSemantics} +/// +/// See also: +/// +/// * [RenderIgnorePointer], which has the opposite effect: removing the +/// subtree from considering entirely for the purposes of hit testing. +class RenderAbsorbPointer extends RenderProxyBox { + /// Creates a render object that absorbs pointers during hit testing. + RenderAbsorbPointer({ + RenderBox? child, + bool absorbing = true, + @Deprecated( + 'Use ExcludeSemantics or create a custom absorb pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + bool? ignoringSemantics, + }) : _absorbing = absorbing, + _ignoringSemantics = ignoringSemantics, + super(child); + + /// Whether this render object absorbs pointers during hit testing. + /// + /// Regardless of whether this render object absorbs pointers during hit + /// testing, it will still consume space during layout and be visible during + /// painting. + /// + /// {@macro flutter.widgets.AbsorbPointer.semantics} + bool get absorbing => _absorbing; + bool _absorbing; + set absorbing(bool value) { + if (_absorbing == value) { + return; + } + _absorbing = value; + if (ignoringSemantics == null) { + markNeedsSemanticsUpdate(); + } + } + + /// Whether the semantics of this render object is ignored when compiling the + /// semantics tree. + /// + /// {@macro flutter.widgets.AbsorbPointer.ignoringSemantics} + /// + /// See [SemanticsNode] for additional information about the semantics tree. + @Deprecated( + 'Use ExcludeSemantics or create a custom absorb pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + bool? get ignoringSemantics => _ignoringSemantics; + bool? _ignoringSemantics; + set ignoringSemantics(bool? value) { + if (value == _ignoringSemantics) { + return; + } + _ignoringSemantics = value; + markNeedsSemanticsUpdate(); + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + return absorbing + ? size.contains(position) + : super.hitTest(result, position: position); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (_ignoringSemantics ?? false) { + return; + } + super.visitChildrenForSemantics(visitor); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + // Do not block user interactions if _ignoringSemantics is false; otherwise, + // delegate to absorbing + config.isBlockingUserActions = absorbing && (_ignoringSemantics ?? true); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('absorbing', absorbing)); + properties.add( + DiagnosticsProperty<bool>( + 'ignoringSemantics', + ignoringSemantics, + description: ignoringSemantics == null ? null : 'implicitly $ignoringSemantics', + ), + ); + } +} + +/// Holds opaque meta data in the render tree. +/// +/// Useful for decorating the render tree with information that will be consumed +/// later. For example, you could store information in the render tree that will +/// be used when the user interacts with the render tree but has no visual +/// impact prior to the interaction. +class RenderMetaData extends RenderProxyBoxWithHitTestBehavior { + /// Creates a render object that hold opaque meta data. + /// + /// The [behavior] argument defaults to [HitTestBehavior.deferToChild]. + RenderMetaData({ + this.metaData, + super.behavior, + super.child, + }); + + /// Opaque meta data ignored by the render tree. + dynamic metaData; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<dynamic>('metaData', metaData)); + } +} + +/// Listens for the specified gestures from the semantics server (e.g. +/// an accessibility tool). +class RenderSemanticsGestureHandler extends RenderProxyBoxWithHitTestBehavior { + /// Creates a render object that listens for specific semantic gestures. + RenderSemanticsGestureHandler({ + super.child, + GestureTapCallback? onTap, + GestureLongPressCallback? onLongPress, + GestureDragUpdateCallback? onHorizontalDragUpdate, + GestureDragUpdateCallback? onVerticalDragUpdate, + this.scrollFactor = 0.8, + super.behavior, + }) : _onTap = onTap, + _onLongPress = onLongPress, + _onHorizontalDragUpdate = onHorizontalDragUpdate, + _onVerticalDragUpdate = onVerticalDragUpdate; + + /// If non-null, the set of actions to allow. Other actions will be omitted, + /// even if their callback is provided. + /// + /// For example, if [onTap] is non-null but [validActions] does not contain + /// [SemanticsAction.tap], then the semantic description of this node will + /// not claim to support taps. + /// + /// This is normally used to filter the actions made available by + /// [onHorizontalDragUpdate] and [onVerticalDragUpdate]. Normally, these make + /// both the right and left, or up and down, actions available. For example, + /// if [onHorizontalDragUpdate] is set but [validActions] only contains + /// [SemanticsAction.scrollLeft], then the [SemanticsAction.scrollRight] + /// action will be omitted. + Set<SemanticsAction>? get validActions => _validActions; + Set<SemanticsAction>? _validActions; + set validActions(Set<SemanticsAction>? value) { + if (setEquals<SemanticsAction>(value, _validActions)) { + return; + } + _validActions = value; + markNeedsSemanticsUpdate(); + } + + /// Called when the user taps on the render object. + GestureTapCallback? get onTap => _onTap; + GestureTapCallback? _onTap; + set onTap(GestureTapCallback? value) { + if (_onTap == value) { + return; + } + final bool hadHandler = _onTap != null; + _onTap = value; + if ((value != null) != hadHandler) { + markNeedsSemanticsUpdate(); + } + } + + /// Called when the user presses on the render object for a long period of time. + GestureLongPressCallback? get onLongPress => _onLongPress; + GestureLongPressCallback? _onLongPress; + set onLongPress(GestureLongPressCallback? value) { + if (_onLongPress == value) { + return; + } + final bool hadHandler = _onLongPress != null; + _onLongPress = value; + if ((value != null) != hadHandler) { + markNeedsSemanticsUpdate(); + } + } + + /// Called when the user scrolls to the left or to the right. + GestureDragUpdateCallback? get onHorizontalDragUpdate => _onHorizontalDragUpdate; + GestureDragUpdateCallback? _onHorizontalDragUpdate; + set onHorizontalDragUpdate(GestureDragUpdateCallback? value) { + if (_onHorizontalDragUpdate == value) { + return; + } + final bool hadHandler = _onHorizontalDragUpdate != null; + _onHorizontalDragUpdate = value; + if ((value != null) != hadHandler) { + markNeedsSemanticsUpdate(); + } + } + + /// Called when the user scrolls up or down. + GestureDragUpdateCallback? get onVerticalDragUpdate => _onVerticalDragUpdate; + GestureDragUpdateCallback? _onVerticalDragUpdate; + set onVerticalDragUpdate(GestureDragUpdateCallback? value) { + if (_onVerticalDragUpdate == value) { + return; + } + final bool hadHandler = _onVerticalDragUpdate != null; + _onVerticalDragUpdate = value; + if ((value != null) != hadHandler) { + markNeedsSemanticsUpdate(); + } + } + + /// The fraction of the dimension of this render box to use when + /// scrolling. For example, if this is 0.8 and the box is 200 pixels + /// wide, then when a left-scroll action is received from the + /// accessibility system, it will translate into a 160 pixel + /// leftwards drag. + double scrollFactor; + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + + if (onTap != null && _isValidAction(SemanticsAction.tap)) { + config.onTap = onTap; + } + if (onLongPress != null && _isValidAction(SemanticsAction.longPress)) { + config.onLongPress = onLongPress; + } + if (onHorizontalDragUpdate != null) { + if (_isValidAction(SemanticsAction.scrollRight)) { + config.onScrollRight = _performSemanticScrollRight; + } + if (_isValidAction(SemanticsAction.scrollLeft)) { + config.onScrollLeft = _performSemanticScrollLeft; + } + } + if (onVerticalDragUpdate != null) { + if (_isValidAction(SemanticsAction.scrollUp)) { + config.onScrollUp = _performSemanticScrollUp; + } + if (_isValidAction(SemanticsAction.scrollDown)) { + config.onScrollDown = _performSemanticScrollDown; + } + } + } + + bool _isValidAction(SemanticsAction action) { + return validActions == null || validActions!.contains(action); + } + + void _performSemanticScrollLeft() { + if (onHorizontalDragUpdate != null) { + final double primaryDelta = size.width * -scrollFactor; + onHorizontalDragUpdate!(DragUpdateDetails( + delta: Offset(primaryDelta, 0.0), primaryDelta: primaryDelta, + globalPosition: localToGlobal(size.center(Offset.zero)), + )); + } + } + + void _performSemanticScrollRight() { + if (onHorizontalDragUpdate != null) { + final double primaryDelta = size.width * scrollFactor; + onHorizontalDragUpdate!(DragUpdateDetails( + delta: Offset(primaryDelta, 0.0), primaryDelta: primaryDelta, + globalPosition: localToGlobal(size.center(Offset.zero)), + )); + } + } + + void _performSemanticScrollUp() { + if (onVerticalDragUpdate != null) { + final double primaryDelta = size.height * -scrollFactor; + onVerticalDragUpdate!(DragUpdateDetails( + delta: Offset(0.0, primaryDelta), primaryDelta: primaryDelta, + globalPosition: localToGlobal(size.center(Offset.zero)), + )); + } + } + + void _performSemanticScrollDown() { + if (onVerticalDragUpdate != null) { + final double primaryDelta = size.height * scrollFactor; + onVerticalDragUpdate!(DragUpdateDetails( + delta: Offset(0.0, primaryDelta), primaryDelta: primaryDelta, + globalPosition: localToGlobal(size.center(Offset.zero)), + )); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final List<String> gestures = <String>[ + if (onTap != null) 'tap', + if (onLongPress != null) 'long press', + if (onHorizontalDragUpdate != null) 'horizontal scroll', + if (onVerticalDragUpdate != null) 'vertical scroll', + ]; + if (gestures.isEmpty) { + gestures.add('<none>'); + } + properties.add(IterableProperty<String>('gestures', gestures)); + } +} + +/// Add annotations to the [SemanticsNode] for this subtree. +class RenderSemanticsAnnotations extends RenderProxyBox { + /// Creates a render object that attaches a semantic annotation. + /// + /// If the [SemanticsProperties.attributedLabel] is not null, the [textDirection] must also not be null. + RenderSemanticsAnnotations({ + RenderBox? child, + required SemanticsProperties properties, + bool container = false, + bool explicitChildNodes = false, + bool excludeSemantics = false, + bool blockUserActions = false, + TextDirection? textDirection, + }) : _container = container, + _explicitChildNodes = explicitChildNodes, + _excludeSemantics = excludeSemantics, + _blockUserActions = blockUserActions, + _textDirection = textDirection, + _properties = properties, + super(child) { + _updateAttributedFields(_properties); + } + + /// All of the [SemanticsProperties] for this [RenderSemanticsAnnotations]. + SemanticsProperties get properties => _properties; + SemanticsProperties _properties; + set properties(SemanticsProperties value) { + if (_properties == value) { + return; + } + _properties = value; + _updateAttributedFields(_properties); + markNeedsSemanticsUpdate(); + } + + /// If 'container' is true, this [RenderObject] will introduce a new + /// node in the semantics tree. Otherwise, the semantics will be + /// merged with the semantics of any ancestors. + /// + /// Whether descendants of this [RenderObject] can add their semantic information + /// to the [SemanticsNode] introduced by this configuration is controlled by + /// [explicitChildNodes]. + bool get container => _container; + bool _container; + set container(bool value) { + if (container == value) { + return; + } + _container = value; + markNeedsSemanticsUpdate(); + } + + /// Whether descendants of this [RenderObject] are allowed to add semantic + /// information to the [SemanticsNode] annotated by this widget. + /// + /// When set to false descendants are allowed to annotate [SemanticsNode]s of + /// their parent with the semantic information they want to contribute to the + /// semantic tree. + /// When set to true the only way for descendants to contribute semantic + /// information to the semantic tree is to introduce new explicit + /// [SemanticsNode]s to the tree. + /// + /// This setting is often used in combination with + /// [SemanticsConfiguration.isSemanticBoundary] to create semantic boundaries + /// that are either writable or not for children. + bool get explicitChildNodes => _explicitChildNodes; + bool _explicitChildNodes; + set explicitChildNodes(bool value) { + if (_explicitChildNodes == value) { + return; + } + _explicitChildNodes = value; + markNeedsSemanticsUpdate(); + } + + /// Whether descendants of this [RenderObject] should have their semantic + /// information ignored. + /// + /// When this flag is set to true, all child semantics nodes are ignored. + /// This can be used as a convenience for cases where a child is wrapped in + /// an [ExcludeSemantics] widget and then another [Semantics] widget. + bool get excludeSemantics => _excludeSemantics; + bool _excludeSemantics; + set excludeSemantics(bool value) { + if (_excludeSemantics == value) { + return; + } + _excludeSemantics = value; + markNeedsSemanticsUpdate(); + } + + /// Whether to block user interactions for the semantics subtree. + /// + /// Setting this true prevents user from activating pointer related + /// [SemanticsAction]s, such as [SemanticsAction.tap] or + /// [SemanticsAction.longPress]. + bool get blockUserActions => _blockUserActions; + bool _blockUserActions; + set blockUserActions(bool value) { + if (_blockUserActions == value) { + return; + } + _blockUserActions = value; + markNeedsSemanticsUpdate(); + } + + void _updateAttributedFields(SemanticsProperties value) { + _attributedLabel = _effectiveAttributedLabel(value); + _attributedValue = _effectiveAttributedValue(value); + _attributedIncreasedValue = _effectiveAttributedIncreasedValue(value); + _attributedDecreasedValue = _effectiveAttributedDecreasedValue(value); + _attributedHint = _effectiveAttributedHint(value); + } + + AttributedString? _effectiveAttributedLabel(SemanticsProperties value) { + return value.attributedLabel ?? + (value.label == null ? null : AttributedString(value.label!)); + } + + AttributedString? _effectiveAttributedValue(SemanticsProperties value) { + return value.attributedValue ?? + (value.value == null ? null : AttributedString(value.value!)); + } + + AttributedString? _effectiveAttributedIncreasedValue( + SemanticsProperties value) { + return value.attributedIncreasedValue ?? + (value.increasedValue == null + ? null + : AttributedString(value.increasedValue!)); + } + + AttributedString? _effectiveAttributedDecreasedValue( + SemanticsProperties value) { + return properties.attributedDecreasedValue ?? + (value.decreasedValue == null + ? null + : AttributedString(value.decreasedValue!)); + } + + AttributedString? _effectiveAttributedHint(SemanticsProperties value) { + return value.attributedHint ?? + (value.hint == null ? null : AttributedString(value.hint!)); + } + + AttributedString? _attributedLabel; + AttributedString? _attributedValue; + AttributedString? _attributedIncreasedValue; + AttributedString? _attributedDecreasedValue; + AttributedString? _attributedHint; + + /// If non-null, sets the [SemanticsNode.textDirection] semantic to the given + /// value. + /// + /// This must not be null if [SemanticsProperties.attributedLabel], + /// [SemanticsProperties.attributedHint], + /// [SemanticsProperties.attributedValue], + /// [SemanticsProperties.attributedIncreasedValue], or + /// [SemanticsProperties.attributedDecreasedValue] are not null. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (textDirection == value) { + return; + } + _textDirection = value; + markNeedsSemanticsUpdate(); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (excludeSemantics) { + return; + } + super.visitChildrenForSemantics(visitor); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.isSemanticBoundary = container; + config.explicitChildNodes = explicitChildNodes; + config.isBlockingUserActions = blockUserActions; + assert( + ((_properties.scopesRoute ?? false) && explicitChildNodes) || !(_properties.scopesRoute ?? false), + 'explicitChildNodes must be set to true if scopes route is true', + ); + assert( + !((_properties.toggled ?? false) && (_properties.checked ?? false)), + 'A semantics node cannot be toggled and checked at the same time', + ); + + if (_properties.enabled != null) { + config.isEnabled = _properties.enabled; + } + if (_properties.checked != null) { + config.isChecked = _properties.checked; + } + if (_properties.mixed != null) { + config.isCheckStateMixed = _properties.mixed; + } + if (_properties.toggled != null) { + config.isToggled = _properties.toggled; + } + if (_properties.selected != null) { + config.isSelected = _properties.selected!; + } + if (_properties.button != null) { + config.isButton = _properties.button!; + } + if (_properties.expanded != null) { + config.isExpanded = _properties.expanded; + } + if (_properties.link != null) { + config.isLink = _properties.link!; + } + if (_properties.slider != null) { + config.isSlider = _properties.slider!; + } + if (_properties.keyboardKey != null) { + config.isKeyboardKey = _properties.keyboardKey!; + } + if (_properties.header != null) { + config.isHeader = _properties.header!; + } + if (_properties.textField != null) { + config.isTextField = _properties.textField!; + } + if (_properties.readOnly != null) { + config.isReadOnly = _properties.readOnly!; + } + if (_properties.focusable != null) { + config.isFocusable = _properties.focusable!; + } + if (_properties.focused != null) { + config.isFocused = _properties.focused!; + } + if (_properties.inMutuallyExclusiveGroup != null) { + config.isInMutuallyExclusiveGroup = _properties.inMutuallyExclusiveGroup!; + } + if (_properties.obscured != null) { + config.isObscured = _properties.obscured!; + } + if (_properties.multiline != null) { + config.isMultiline = _properties.multiline!; + } + if (_properties.hidden != null) { + config.isHidden = _properties.hidden!; + } + if (_properties.image != null) { + config.isImage = _properties.image!; + } + if (_properties.identifier != null) { + config.identifier = _properties.identifier!; + } + if (_attributedLabel != null) { + config.attributedLabel = _attributedLabel!; + } + if (_attributedValue != null) { + config.attributedValue = _attributedValue!; + } + if (_attributedIncreasedValue != null) { + config.attributedIncreasedValue = _attributedIncreasedValue!; + } + if (_attributedDecreasedValue != null) { + config.attributedDecreasedValue = _attributedDecreasedValue!; + } + if (_attributedHint != null) { + config.attributedHint = _attributedHint!; + } + if (_properties.tooltip != null) { + config.tooltip = _properties.tooltip!; + } + if (_properties.hintOverrides != null && _properties.hintOverrides!.isNotEmpty) { + config.hintOverrides = _properties.hintOverrides; + } + if (_properties.scopesRoute != null) { + config.scopesRoute = _properties.scopesRoute!; + } + if (_properties.namesRoute != null) { + config.namesRoute = _properties.namesRoute!; + } + if (_properties.liveRegion != null) { + config.liveRegion = _properties.liveRegion!; + } + if (_properties.maxValueLength != null) { + config.maxValueLength = _properties.maxValueLength; + } + if (_properties.currentValueLength != null) { + config.currentValueLength = _properties.currentValueLength; + } + if (textDirection != null) { + config.textDirection = textDirection; + } + if (_properties.sortKey != null) { + config.sortKey = _properties.sortKey; + } + if (_properties.tagForChildren != null) { + config.addTagForChildren(_properties.tagForChildren!); + } + // Registering _perform* as action handlers instead of the user provided + // ones to ensure that changing a user provided handler from a non-null to + // another non-null value doesn't require a semantics update. + if (_properties.onTap != null) { + config.onTap = _performTap; + } + if (_properties.onLongPress != null) { + config.onLongPress = _performLongPress; + } + if (_properties.onDismiss != null) { + config.onDismiss = _performDismiss; + } + if (_properties.onScrollLeft != null) { + config.onScrollLeft = _performScrollLeft; + } + if (_properties.onScrollRight != null) { + config.onScrollRight = _performScrollRight; + } + if (_properties.onScrollUp != null) { + config.onScrollUp = _performScrollUp; + } + if (_properties.onScrollDown != null) { + config.onScrollDown = _performScrollDown; + } + if (_properties.onIncrease != null) { + config.onIncrease = _performIncrease; + } + if (_properties.onDecrease != null) { + config.onDecrease = _performDecrease; + } + if (_properties.onCopy != null) { + config.onCopy = _performCopy; + } + if (_properties.onCut != null) { + config.onCut = _performCut; + } + if (_properties.onPaste != null) { + config.onPaste = _performPaste; + } + if (_properties.onMoveCursorForwardByCharacter != null) { + config.onMoveCursorForwardByCharacter = _performMoveCursorForwardByCharacter; + } + if (_properties.onMoveCursorBackwardByCharacter != null) { + config.onMoveCursorBackwardByCharacter = _performMoveCursorBackwardByCharacter; + } + if (_properties.onMoveCursorForwardByWord != null) { + config.onMoveCursorForwardByWord = _performMoveCursorForwardByWord; + } + if (_properties.onMoveCursorBackwardByWord != null) { + config.onMoveCursorBackwardByWord = _performMoveCursorBackwardByWord; + } + if (_properties.onSetSelection != null) { + config.onSetSelection = _performSetSelection; + } + if (_properties.onSetText != null) { + config.onSetText = _performSetText; + } + if (_properties.onDidGainAccessibilityFocus != null) { + config.onDidGainAccessibilityFocus = _performDidGainAccessibilityFocus; + } + if (_properties.onDidLoseAccessibilityFocus != null) { + config.onDidLoseAccessibilityFocus = _performDidLoseAccessibilityFocus; + } + if (_properties.customSemanticsActions != null) { + config.customSemanticsActions = _properties.customSemanticsActions!; + } + } + + void _performTap() { + _properties.onTap?.call(); + } + + void _performLongPress() { + _properties.onLongPress?.call(); + } + + void _performDismiss() { + _properties.onDismiss?.call(); + } + + void _performScrollLeft() { + _properties.onScrollLeft?.call(); + } + + void _performScrollRight() { + _properties.onScrollRight?.call(); + } + + void _performScrollUp() { + _properties.onScrollUp?.call(); + } + + void _performScrollDown() { + _properties.onScrollDown?.call(); + } + + void _performIncrease() { + _properties.onIncrease?.call(); + } + + void _performDecrease() { + _properties.onDecrease?.call(); + } + + void _performCopy() { + _properties.onCopy?.call(); + } + + void _performCut() { + _properties.onCut?.call(); + } + + void _performPaste() { + _properties.onPaste?.call(); + } + + void _performMoveCursorForwardByCharacter(bool extendSelection) { + _properties.onMoveCursorForwardByCharacter?.call(extendSelection); + } + + void _performMoveCursorBackwardByCharacter(bool extendSelection) { + _properties.onMoveCursorBackwardByCharacter?.call(extendSelection); + } + + void _performMoveCursorForwardByWord(bool extendSelection) { + _properties.onMoveCursorForwardByWord?.call(extendSelection); + } + + void _performMoveCursorBackwardByWord(bool extendSelection) { + _properties.onMoveCursorBackwardByWord?.call(extendSelection); + } + + void _performSetSelection(TextSelection selection) { + _properties.onSetSelection?.call(selection); + } + + void _performSetText(String text) { + _properties.onSetText?.call(text); + } + + void _performDidGainAccessibilityFocus() { + _properties.onDidGainAccessibilityFocus?.call(); + } + + void _performDidLoseAccessibilityFocus() { + _properties.onDidLoseAccessibilityFocus?.call(); + } +} + +/// Causes the semantics of all earlier render objects below the same semantic +/// boundary to be dropped. +/// +/// This is useful in a stack where an opaque mask should prevent interactions +/// with the render objects painted below the mask. +class RenderBlockSemantics extends RenderProxyBox { + /// Create a render object that blocks semantics for nodes below it in paint + /// order. + RenderBlockSemantics({ + RenderBox? child, + bool blocking = true, + }) : _blocking = blocking, + super(child); + + /// Whether this render object is blocking semantics of previously painted + /// [RenderObject]s below a common semantics boundary from the semantic tree. + bool get blocking => _blocking; + bool _blocking; + set blocking(bool value) { + if (value == _blocking) { + return; + } + _blocking = value; + markNeedsSemanticsUpdate(); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.isBlockingSemanticsOfPreviouslyPaintedNodes = blocking; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('blocking', blocking)); + } +} + +/// Causes the semantics of all descendants to be merged into this +/// node such that the entire subtree becomes a single leaf in the +/// semantics tree. +/// +/// Useful for combining the semantics of multiple render objects that +/// form part of a single conceptual widget, e.g. a checkbox, a label, +/// and the gesture detector that goes with them. +class RenderMergeSemantics extends RenderProxyBox { + /// Creates a render object that merges the semantics from its descendants. + RenderMergeSemantics({ RenderBox? child }) : super(child); + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config + ..isSemanticBoundary = true + ..isMergingSemanticsOfDescendants = true; + } +} + +/// Excludes this subtree from the semantic tree. +/// +/// When [excluding] is true, this render object (and its subtree) is excluded +/// from the semantic tree. +/// +/// Useful e.g. for hiding text that is redundant with other text next +/// to it (e.g. text included only for the visual effect). +class RenderExcludeSemantics extends RenderProxyBox { + /// Creates a render object that ignores the semantics of its subtree. + RenderExcludeSemantics({ + RenderBox? child, + bool excluding = true, + }) : _excluding = excluding, + super(child); + + /// Whether this render object is excluded from the semantic tree. + bool get excluding => _excluding; + bool _excluding; + set excluding(bool value) { + if (value == _excluding) { + return; + } + _excluding = value; + markNeedsSemanticsUpdate(); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (excluding) { + return; + } + super.visitChildrenForSemantics(visitor); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('excluding', excluding)); + } +} + +/// A render objects that annotates semantics with an index. +/// +/// Certain widgets will automatically provide a child index for building +/// semantics. For example, the [ScrollView] uses the index of the first +/// visible child semantics node to determine the +/// [SemanticsConfiguration.scrollIndex]. +/// +/// See also: +/// +/// * [CustomScrollView], for an explanation of scroll semantics. +class RenderIndexedSemantics extends RenderProxyBox { + /// Creates a render object that annotates the child semantics with an index. + RenderIndexedSemantics({ + RenderBox? child, + required int index, + }) : _index = index, + super(child); + + /// The index used to annotated child semantics. + int get index => _index; + int _index; + set index(int value) { + if (value == index) { + return; + } + _index = value; + markNeedsSemanticsUpdate(); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.indexInParent = index; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<int>('index', index)); + } +} + +/// Provides an anchor for a [RenderFollowerLayer]. +/// +/// See also: +/// +/// * [CompositedTransformTarget], the corresponding widget. +/// * [LeaderLayer], the layer that this render object creates. +class RenderLeaderLayer extends RenderProxyBox { + /// Creates a render object that uses a [LeaderLayer]. + RenderLeaderLayer({ + required LayerLink link, + RenderBox? child, + }) : _link = link, + super(child); + + /// The link object that connects this [RenderLeaderLayer] with one or more + /// [RenderFollowerLayer]s. + /// + /// The object must not be associated with another [RenderLeaderLayer] that is + /// also being painted. + LayerLink get link => _link; + LayerLink _link; + set link(LayerLink value) { + if (_link == value) { + return; + } + _link.leaderSize = null; + _link = value; + if (_previousLayoutSize != null) { + _link.leaderSize = _previousLayoutSize; + } + markNeedsPaint(); + } + + @override + bool get alwaysNeedsCompositing => true; + + // The latest size of this [RenderBox], computed during the previous layout + // pass. It should always be equal to [size], but can be accessed even when + // [debugDoingThisResize] and [debugDoingThisLayout] are false. + Size? _previousLayoutSize; + + @override + void performLayout() { + super.performLayout(); + _previousLayoutSize = size; + link.leaderSize = size; + } + + @override + void paint(PaintingContext context, Offset offset) { + if (layer == null) { + layer = LeaderLayer(link: link, offset: offset); + } else { + final LeaderLayer leaderLayer = layer! as LeaderLayer; + leaderLayer + ..link = link + ..offset = offset; + } + context.pushLayer(layer!, super.paint, Offset.zero); + assert(() { + layer!.debugCreator = debugCreator; + return true; + }()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<LayerLink>('link', link)); + } +} + +/// Transform the child so that its origin is [offset] from the origin of the +/// [RenderLeaderLayer] with the same [LayerLink]. +/// +/// The [RenderLeaderLayer] in question must be earlier in the paint order. +/// +/// Hit testing on descendants of this render object will only work if the +/// target position is within the box that this render object's parent considers +/// to be hittable. +/// +/// See also: +/// +/// * [CompositedTransformFollower], the corresponding widget. +/// * [FollowerLayer], the layer that this render object creates. +class RenderFollowerLayer extends RenderProxyBox { + /// Creates a render object that uses a [FollowerLayer]. + RenderFollowerLayer({ + required LayerLink link, + bool showWhenUnlinked = true, + Offset offset = Offset.zero, + Alignment leaderAnchor = Alignment.topLeft, + Alignment followerAnchor = Alignment.topLeft, + RenderBox? child, + }) : _link = link, + _showWhenUnlinked = showWhenUnlinked, + _offset = offset, + _leaderAnchor = leaderAnchor, + _followerAnchor = followerAnchor, + super(child); + + /// The link object that connects this [RenderFollowerLayer] with a + /// [RenderLeaderLayer] earlier in the paint order. + LayerLink get link => _link; + LayerLink _link; + set link(LayerLink value) { + if (_link == value) { + return; + } + _link = value; + markNeedsPaint(); + } + + /// Whether to show the render object's contents when there is no + /// corresponding [RenderLeaderLayer] with the same [link]. + /// + /// When the render object is linked, the child is positioned such that it has + /// the same global position as the linked [RenderLeaderLayer]. + /// + /// When the render object is not linked, then: if [showWhenUnlinked] is true, + /// the child is visible and not repositioned; if it is false, then child is + /// hidden, and its hit testing is also disabled. + bool get showWhenUnlinked => _showWhenUnlinked; + bool _showWhenUnlinked; + set showWhenUnlinked(bool value) { + if (_showWhenUnlinked == value) { + return; + } + _showWhenUnlinked = value; + markNeedsPaint(); + } + + /// The offset to apply to the origin of the linked [RenderLeaderLayer] to + /// obtain this render object's origin. + Offset get offset => _offset; + Offset _offset; + set offset(Offset value) { + if (_offset == value) { + return; + } + _offset = value; + markNeedsPaint(); + } + + /// The anchor point on the linked [RenderLeaderLayer] that [followerAnchor] + /// will line up with. + /// + /// {@template flutter.rendering.RenderFollowerLayer.leaderAnchor} + /// For example, when [leaderAnchor] and [followerAnchor] are both + /// [Alignment.topLeft], this [RenderFollowerLayer] will be top left aligned + /// with the linked [RenderLeaderLayer]. When [leaderAnchor] is + /// [Alignment.bottomLeft] and [followerAnchor] is [Alignment.topLeft], this + /// [RenderFollowerLayer] will be left aligned with the linked + /// [RenderLeaderLayer], and its top edge will line up with the + /// [RenderLeaderLayer]'s bottom edge. + /// {@endtemplate} + /// + /// Defaults to [Alignment.topLeft]. + Alignment get leaderAnchor => _leaderAnchor; + Alignment _leaderAnchor; + set leaderAnchor(Alignment value) { + if (_leaderAnchor == value) { + return; + } + _leaderAnchor = value; + markNeedsPaint(); + } + + /// The anchor point on this [RenderFollowerLayer] that will line up with + /// [followerAnchor] on the linked [RenderLeaderLayer]. + /// + /// {@macro flutter.rendering.RenderFollowerLayer.leaderAnchor} + /// + /// Defaults to [Alignment.topLeft]. + Alignment get followerAnchor => _followerAnchor; + Alignment _followerAnchor; + set followerAnchor(Alignment value) { + if (_followerAnchor == value) { + return; + } + _followerAnchor = value; + markNeedsPaint(); + } + + @override + void detach() { + layer = null; + super.detach(); + } + + @override + bool get alwaysNeedsCompositing => true; + + /// The layer we created when we were last painted. + @override + FollowerLayer? get layer => super.layer as FollowerLayer?; + + /// Return the transform that was used in the last composition phase, if any. + /// + /// If the [FollowerLayer] has not yet been created, was never composited, or + /// was unable to determine the transform (see + /// [FollowerLayer.getLastTransform]), this returns the identity matrix (see + /// [Matrix4.identity]. + Matrix4 getCurrentTransform() { + return layer?.getLastTransform() ?? Matrix4.identity(); + } + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) { + // Disables the hit testing if this render object is hidden. + if (link.leader == null && !showWhenUnlinked) { + return false; + } + // RenderFollowerLayer objects don't check if they are + // themselves hit, because it's confusing to think about + // how the untransformed size and the child's transformed + // position interact. + return hitTestChildren(result, position: position); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + return result.addWithPaintTransform( + transform: getCurrentTransform(), + position: position, + hitTest: (BoxHitTestResult result, Offset position) { + return super.hitTestChildren(result, position: position); + }, + ); + } + + @override + void paint(PaintingContext context, Offset offset) { + final Size? leaderSize = link.leaderSize; + assert( + link.leaderSize != null || link.leader == null || leaderAnchor == Alignment.topLeft, + '$link: layer is linked to ${link.leader} but a valid leaderSize is not set. ' + 'leaderSize is required when leaderAnchor is not Alignment.topLeft ' + '(current value is $leaderAnchor).', + ); + final Offset effectiveLinkedOffset = leaderSize == null + ? this.offset + : leaderAnchor.alongSize(leaderSize) - followerAnchor.alongSize(size) + this.offset; + if (layer == null) { + layer = FollowerLayer( + link: link, + showWhenUnlinked: showWhenUnlinked, + linkedOffset: effectiveLinkedOffset, + unlinkedOffset: offset, + ); + } else { + layer + ?..link = link + ..showWhenUnlinked = showWhenUnlinked + ..linkedOffset = effectiveLinkedOffset + ..unlinkedOffset = offset; + } + context.pushLayer( + layer!, + super.paint, + Offset.zero, + childPaintBounds: const Rect.fromLTRB( + // We don't know where we'll end up, so we have no idea what our cull rect should be. + double.negativeInfinity, + double.negativeInfinity, + double.infinity, + double.infinity, + ), + ); + assert(() { + layer!.debugCreator = debugCreator; + return true; + }()); + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + transform.multiply(getCurrentTransform()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<LayerLink>('link', link)); + properties.add(DiagnosticsProperty<bool>('showWhenUnlinked', showWhenUnlinked)); + properties.add(DiagnosticsProperty<Offset>('offset', offset)); + properties.add(TransformProperty('current transform matrix', getCurrentTransform())); + } +} + +/// Render object which inserts an [AnnotatedRegionLayer] into the layer tree. +/// +/// See also: +/// +/// * [Layer.find], for an example of how this value is retrieved. +/// * [AnnotatedRegionLayer], the layer this render object creates. +class RenderAnnotatedRegion<T extends Object> extends RenderProxyBox { + + /// Creates a new [RenderAnnotatedRegion] to insert [value] into the + /// layer tree. + /// + /// If [sized] is true, the layer is provided with the size of this render + /// object to clip the results of [Layer.find]. + /// + /// Neither [value] nor [sized] can be null. + RenderAnnotatedRegion({ + required T value, + required bool sized, + RenderBox? child, + }) : _value = value, + _sized = sized, + _layerHandle = LayerHandle<AnnotatedRegionLayer<T>>(), + super(child); + + /// A value which can be retrieved using [Layer.find]. + T get value => _value; + T _value; + set value (T newValue) { + if (_value == newValue) { + return; + } + _value = newValue; + markNeedsPaint(); + } + + /// Whether the render object will pass its [size] to the [AnnotatedRegionLayer]. + bool get sized => _sized; + bool _sized; + set sized(bool value) { + if (_sized == value) { + return; + } + _sized = value; + markNeedsPaint(); + } + + final LayerHandle<AnnotatedRegionLayer<T>> _layerHandle; + + @override + final bool alwaysNeedsCompositing = true; + + @override + void paint(PaintingContext context, Offset offset) { + // Annotated region layers are not retained because they do not create engine layers. + final AnnotatedRegionLayer<T> layer = AnnotatedRegionLayer<T>( + value, + size: sized ? size : null, + offset: sized ? offset : null, + ); + _layerHandle.layer = layer; + context.pushLayer(layer, super.paint, offset); + } + + @override + void dispose() { + _layerHandle.layer = null; + super.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/proxy_sliver.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/proxy_sliver.dart new file mode 100644 index 0000000000000000000000000000000000000000..a33ee947cb8d71e2221772f6b0d6bf8718591092 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/proxy_sliver.dart @@ -0,0 +1,457 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math'; +import 'dart:ui' as ui show Color; + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/semantics.dart'; + +import 'layer.dart'; +import 'object.dart'; +import 'proxy_box.dart'; +import 'sliver.dart'; + +/// A base class for sliver render objects that resemble their children. +/// +/// A proxy sliver has a single child and mimics all the properties of +/// that child by calling through to the child for each function in the render +/// sliver protocol. For example, a proxy sliver determines its geometry by +/// asking its sliver child to layout with the same constraints and then +/// matching the geometry. +/// +/// A proxy sliver isn't useful on its own because you might as well just +/// replace the proxy sliver with its child. However, RenderProxySliver is a +/// useful base class for render objects that wish to mimic most, but not all, +/// of the properties of their sliver child. +/// +/// See also: +/// +/// * [RenderProxyBox], a base class for render boxes that resemble their +/// children. +abstract class RenderProxySliver extends RenderSliver with RenderObjectWithChildMixin<RenderSliver> { + /// Creates a proxy render sliver. + /// + /// Proxy render slivers aren't created directly because they proxy + /// the render sliver protocol to their sliver [child]. Instead, use one of + /// the subclasses. + RenderProxySliver([RenderSliver? child]) { + this.child = child; + } + + @override + void setupParentData(RenderObject child) { + if (child.parentData is! SliverPhysicalParentData) { + child.parentData = SliverPhysicalParentData(); + } + } + + @override + void performLayout() { + assert(child != null); + child!.layout(constraints, parentUsesSize: true); + geometry = child!.geometry; + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + context.paintChild(child!, offset); + } + } + + @override + bool hitTestChildren(SliverHitTestResult result, {required double mainAxisPosition, required double crossAxisPosition}) { + return child != null + && child!.geometry!.hitTestExtent > 0 + && child!.hitTest( + result, + mainAxisPosition: mainAxisPosition, + crossAxisPosition: crossAxisPosition, + ); + } + + @override + double childMainAxisPosition(RenderSliver child) { + assert(child == this.child); + return 0.0; + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + childParentData.applyPaintTransform(transform); + } +} + +/// Makes its sliver child partially transparent. +/// +/// This class paints its sliver child into an intermediate buffer and then +/// blends the sliver child back into the scene, partially transparent. +/// +/// For values of opacity other than 0.0 and 1.0, this class is relatively +/// expensive, because it requires painting the sliver child into an intermediate +/// buffer. For the value 0.0, the sliver child is not painted at all. +/// For the value 1.0, the sliver child is painted immediately without an +/// intermediate buffer. +class RenderSliverOpacity extends RenderProxySliver { + /// Creates a partially transparent render object. + /// + /// The [opacity] argument must be between 0.0 and 1.0, inclusive. + RenderSliverOpacity({ + double opacity = 1.0, + bool alwaysIncludeSemantics = false, + RenderSliver? sliver, + }) : assert(opacity >= 0.0 && opacity <= 1.0), + _opacity = opacity, + _alwaysIncludeSemantics = alwaysIncludeSemantics, + _alpha = ui.Color.getAlphaFromOpacity(opacity) { + child = sliver; + } + + @override + bool get alwaysNeedsCompositing => child != null && (_alpha > 0); + + int _alpha; + + /// The fraction to scale the child's alpha value. + /// + /// An opacity of one is fully opaque. An opacity of zero is fully transparent + /// (i.e. invisible). + /// + /// Values one and zero are painted with a fast path. Other values require + /// painting the child into an intermediate buffer, which is expensive. + double get opacity => _opacity; + double _opacity; + set opacity(double value) { + assert(value >= 0.0 && value <= 1.0); + if (_opacity == value) { + return; + } + final bool didNeedCompositing = alwaysNeedsCompositing; + final bool wasVisible = _alpha != 0; + _opacity = value; + _alpha = ui.Color.getAlphaFromOpacity(_opacity); + if (didNeedCompositing != alwaysNeedsCompositing) { + markNeedsCompositingBitsUpdate(); + } + markNeedsPaint(); + if (wasVisible != (_alpha != 0) && !alwaysIncludeSemantics) { + markNeedsSemanticsUpdate(); + } + } + + /// Whether child semantics are included regardless of the opacity. + /// + /// If false, semantics are excluded when [opacity] is 0.0. + /// + /// Defaults to false. + bool get alwaysIncludeSemantics => _alwaysIncludeSemantics; + bool _alwaysIncludeSemantics; + set alwaysIncludeSemantics(bool value) { + if (value == _alwaysIncludeSemantics) { + return; + } + _alwaysIncludeSemantics = value; + markNeedsSemanticsUpdate(); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null && child!.geometry!.visible) { + if (_alpha == 0) { + // No need to keep the layer. We'll create a new one if necessary. + layer = null; + return; + } + assert(needsCompositing); + layer = context.pushOpacity( + offset, + _alpha, + super.paint, + oldLayer: layer as OpacityLayer?, + ); + assert(() { + layer!.debugCreator = debugCreator; + return true; + }()); + } + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (child != null && (_alpha != 0 || alwaysIncludeSemantics)) { + visitor(child!); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('opacity', opacity)); + properties.add(FlagProperty('alwaysIncludeSemantics', value: alwaysIncludeSemantics, ifTrue: 'alwaysIncludeSemantics')); + } +} + +/// A render object that is invisible during hit testing. +/// +/// When [ignoring] is true, this render object (and its subtree) is invisible +/// to hit testing. It still consumes space during layout and paints its sliver +/// child as usual. It just cannot be the target of located events, because its +/// render object returns false from [hitTest]. +/// +/// ## Semantics +/// +/// Using this class may also affect how the semantics subtree underneath is +/// collected. +/// +/// {@macro flutter.widgets.IgnorePointer.semantics} +/// +/// {@macro flutter.widgets.IgnorePointer.ignoringSemantics} +class RenderSliverIgnorePointer extends RenderProxySliver { + /// Creates a render object that is invisible to hit testing. + RenderSliverIgnorePointer({ + RenderSliver? sliver, + bool ignoring = true, + @Deprecated( + 'Create a custom sliver ignore pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + bool? ignoringSemantics, + }) : _ignoring = ignoring, + _ignoringSemantics = ignoringSemantics { + child = sliver; + } + + /// Whether this render object is ignored during hit testing. + /// + /// Regardless of whether this render object is ignored during hit testing, it + /// will still consume space during layout and be visible during painting. + /// + /// {@macro flutter.widgets.IgnorePointer.semantics} + bool get ignoring => _ignoring; + bool _ignoring; + set ignoring(bool value) { + if (value == _ignoring) { + return; + } + _ignoring = value; + if (ignoringSemantics == null) { + markNeedsSemanticsUpdate(); + } + } + + /// Whether the semantics of this render object is ignored when compiling the + /// semantics tree. + /// + /// {@macro flutter.widgets.IgnorePointer.ignoringSemantics} + @Deprecated( + 'Create a custom sliver ignore pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + bool? get ignoringSemantics => _ignoringSemantics; + bool? _ignoringSemantics; + set ignoringSemantics(bool? value) { + if (value == _ignoringSemantics) { + return; + } + _ignoringSemantics = value; + markNeedsSemanticsUpdate(); + } + + @override + bool hitTest(SliverHitTestResult result, {required double mainAxisPosition, required double crossAxisPosition}) { + return !ignoring + && super.hitTest( + result, + mainAxisPosition: mainAxisPosition, + crossAxisPosition: crossAxisPosition, + ); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (_ignoringSemantics ?? false) { + return; + } + super.visitChildrenForSemantics(visitor); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + // Do not block user interactions if _ignoringSemantics is false; otherwise, + // delegate to absorbing + config.isBlockingUserActions = ignoring && (_ignoringSemantics ?? true); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('ignoring', ignoring)); + properties.add( + DiagnosticsProperty<bool>( + 'ignoringSemantics', + ignoringSemantics, + description: ignoringSemantics == null ? null : 'implicitly $ignoringSemantics', + ), + ); + } +} + +/// Lays the sliver child out as if it was in the tree, but without painting +/// anything, without making the sliver child available for hit testing, and +/// without taking any room in the parent. +class RenderSliverOffstage extends RenderProxySliver { + /// Creates an offstage render object. + RenderSliverOffstage({ + bool offstage = true, + RenderSliver? sliver, + }) : _offstage = offstage { + child = sliver; + } + + /// Whether the sliver child is hidden from the rest of the tree. + /// + /// If true, the sliver child is laid out as if it was in the tree, but + /// without painting anything, without making the sliver child available for + /// hit testing, and without taking any room in the parent. + /// + /// If false, the sliver child is included in the tree as normal. + bool get offstage => _offstage; + bool _offstage; + + set offstage(bool value) { + if (value == _offstage) { + return; + } + _offstage = value; + markNeedsLayoutForSizedByParentChange(); + } + + @override + void performLayout() { + assert(child != null); + child!.layout(constraints, parentUsesSize: true); + if (!offstage) { + geometry = child!.geometry; + } else { + geometry = SliverGeometry.zero; + } + } + + @override + bool hitTest(SliverHitTestResult result, {required double mainAxisPosition, required double crossAxisPosition}) { + return !offstage && super.hitTest( + result, + mainAxisPosition: mainAxisPosition, + crossAxisPosition: crossAxisPosition, + ); + } + + @override + bool hitTestChildren(SliverHitTestResult result, {required double mainAxisPosition, required double crossAxisPosition}) { + return !offstage + && child != null + && child!.geometry!.hitTestExtent > 0 + && child!.hitTest( + result, + mainAxisPosition: mainAxisPosition, + crossAxisPosition: crossAxisPosition, + ); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (offstage) { + return; + } + context.paintChild(child!, offset); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (offstage) { + return; + } + super.visitChildrenForSemantics(visitor); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('offstage', offstage)); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + if (child == null) { + return <DiagnosticsNode>[]; + } + return <DiagnosticsNode>[ + child!.toDiagnosticsNode( + name: 'child', + style: offstage ? DiagnosticsTreeStyle.offstage : DiagnosticsTreeStyle.sparse, + ), + ]; + } +} + +/// Makes its sliver child partially transparent, driven from an [Animation]. +/// +/// This is a variant of [RenderSliverOpacity] that uses an [Animation<double>] +/// rather than a [double] to control the opacity. +class RenderSliverAnimatedOpacity extends RenderProxySliver with RenderAnimatedOpacityMixin<RenderSliver> { + /// Creates a partially transparent render object. + RenderSliverAnimatedOpacity({ + required Animation<double> opacity, + bool alwaysIncludeSemantics = false, + RenderSliver? sliver, + }) { + this.opacity = opacity; + this.alwaysIncludeSemantics = alwaysIncludeSemantics; + child = sliver; + } +} + +/// Applies a cross-axis constraint to its sliver child. +/// +/// This render object takes a [maxExtent] parameter and uses the smaller of +/// [maxExtent] and the parent's [SliverConstraints.crossAxisExtent] as the +/// cross axis extent of the [SliverConstraints] passed to the sliver child. +class RenderSliverConstrainedCrossAxis extends RenderProxySliver { + /// Creates a render object that constrains the cross axis extent of its sliver child. + /// + /// The [maxExtent] parameter must be nonnegative. + RenderSliverConstrainedCrossAxis({ + required double maxExtent + }) : _maxExtent = maxExtent, + assert(maxExtent >= 0.0); + + /// The cross axis extent to apply to the sliver child. + /// + /// This value must be nonnegative. + double get maxExtent => _maxExtent; + double _maxExtent; + set maxExtent(double value) { + if (_maxExtent == value) { + return; + } + _maxExtent = value; + markNeedsLayout(); + } + + @override + void performLayout() { + assert(child != null); + assert(maxExtent >= 0.0); + child!.layout( + constraints.copyWith(crossAxisExtent: min(_maxExtent, constraints.crossAxisExtent)), + parentUsesSize: true, + ); + final SliverGeometry childLayoutGeometry = child!.geometry!; + geometry = childLayoutGeometry.copyWith(crossAxisExtent: min(_maxExtent, constraints.crossAxisExtent)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/rotated_box.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/rotated_box.dart new file mode 100644 index 0000000000000000000000000000000000000000..8a7d14e3ec44eb841d18cf56321237e74ad7bd81 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/rotated_box.dart @@ -0,0 +1,151 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'box.dart'; +import 'layer.dart'; +import 'object.dart'; + +const double _kQuarterTurnsInRadians = math.pi / 2.0; + +/// Rotates its child by a integral number of quarter turns. +/// +/// Unlike [RenderTransform], which applies a transform just prior to painting, +/// this object applies its rotation prior to layout, which means the entire +/// rotated box consumes only as much space as required by the rotated child. +class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderBox> { + /// Creates a rotated render box. + RenderRotatedBox({ + required int quarterTurns, + RenderBox? child, + }) : _quarterTurns = quarterTurns { + this.child = child; + } + + /// The number of clockwise quarter turns the child should be rotated. + int get quarterTurns => _quarterTurns; + int _quarterTurns; + set quarterTurns(int value) { + if (_quarterTurns == value) { + return; + } + _quarterTurns = value; + markNeedsLayout(); + } + + bool get _isVertical => quarterTurns.isOdd; + + @override + double computeMinIntrinsicWidth(double height) { + if (child == null) { + return 0.0; + } + return _isVertical ? child!.getMinIntrinsicHeight(height) : child!.getMinIntrinsicWidth(height); + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (child == null) { + return 0.0; + } + return _isVertical ? child!.getMaxIntrinsicHeight(height) : child!.getMaxIntrinsicWidth(height); + } + + @override + double computeMinIntrinsicHeight(double width) { + if (child == null) { + return 0.0; + } + return _isVertical ? child!.getMinIntrinsicWidth(width) : child!.getMinIntrinsicHeight(width); + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (child == null) { + return 0.0; + } + return _isVertical ? child!.getMaxIntrinsicWidth(width) : child!.getMaxIntrinsicHeight(width); + } + + Matrix4? _paintTransform; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (child == null) { + return constraints.smallest; + } + final Size childSize = child!.getDryLayout(_isVertical ? constraints.flipped : constraints); + return _isVertical ? Size(childSize.height, childSize.width) : childSize; + } + + @override + void performLayout() { + _paintTransform = null; + if (child != null) { + child!.layout(_isVertical ? constraints.flipped : constraints, parentUsesSize: true); + size = _isVertical ? Size(child!.size.height, child!.size.width) : child!.size; + _paintTransform = Matrix4.identity() + ..translate(size.width / 2.0, size.height / 2.0) + ..rotateZ(_kQuarterTurnsInRadians * (quarterTurns % 4)) + ..translate(-child!.size.width / 2.0, -child!.size.height / 2.0); + } else { + size = constraints.smallest; + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + assert(_paintTransform != null || debugNeedsLayout || child == null); + if (child == null || _paintTransform == null) { + return false; + } + return result.addWithPaintTransform( + transform: _paintTransform, + position: position, + hitTest: (BoxHitTestResult result, Offset position) { + return child!.hitTest(result, position: position); + }, + ); + } + + void _paintChild(PaintingContext context, Offset offset) { + context.paintChild(child!, offset); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + _transformLayer.layer = context.pushTransform( + needsCompositing, + offset, + _paintTransform!, + _paintChild, + oldLayer: _transformLayer.layer, + ); + } else { + _transformLayer.layer = null; + } + } + + final LayerHandle<TransformLayer> _transformLayer = LayerHandle<TransformLayer>(); + + @override + void dispose() { + _transformLayer.layer = null; + super.dispose(); + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + if (_paintTransform != null) { + transform.multiply(_paintTransform!); + } + super.applyPaintTransform(child, transform); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/selection.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/selection.dart new file mode 100644 index 0000000000000000000000000000000000000000..610432c370972560d3403943a4f8478f81bed5fc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/selection.dart @@ -0,0 +1,789 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'layer.dart'; +import 'object.dart'; + +/// The result after handling a [SelectionEvent]. +/// +/// [SelectionEvent]s are sent from [SelectionRegistrar] to be handled by +/// [SelectionHandler.dispatchSelectionEvent]. The subclasses of +/// [SelectionHandler] or [Selectable] must return appropriate +/// [SelectionResult]s after handling the events. +/// +/// This is used by the [SelectionContainer] to determine how a selection +/// expands across its [Selectable] children. +enum SelectionResult { + /// There is nothing left to select forward in this [Selectable], and further + /// selection should extend to the next [Selectable] in screen order. + /// + /// {@template flutter.rendering.selection.SelectionResult.footNote} + /// This is used after subclasses [SelectionHandler] or [Selectable] handled + /// [SelectionEdgeUpdateEvent]. + /// {@endtemplate} + next, + /// Selection does not reach this [Selectable] and is located before it in + /// screen order. + /// + /// {@macro flutter.rendering.selection.SelectionResult.footNote} + previous, + /// Selection ends in this [Selectable]. + /// + /// Part of the [Selectable] may or may not be selected, but there is still + /// content to select forward or backward. + /// + /// {@macro flutter.rendering.selection.SelectionResult.footNote} + end, + /// The result can't be determined in this frame. + /// + /// This is typically used when the subtree is scrolling to reveal more + /// content. + /// + /// {@macro flutter.rendering.selection.SelectionResult.footNote} + // See `_SelectableRegionState._triggerSelectionEndEdgeUpdate` for how this + // result affects the selection. + pending, + /// There is no result for the selection event. + /// + /// This is used when a selection result is not applicable, e.g. + /// [SelectAllSelectionEvent], [ClearSelectionEvent], and + /// [SelectWordSelectionEvent]. + none, +} + +/// The abstract interface to handle [SelectionEvent]s. +/// +/// This interface is extended by [Selectable] and [SelectionContainerDelegate] +/// and is typically not used directly. +/// +/// {@template flutter.rendering.SelectionHandler} +/// This class returns a [SelectionGeometry] as its [value], and is responsible +/// to notify its listener when its selection geometry has changed as the result +/// of receiving selection events. +/// {@endtemplate} +abstract class SelectionHandler implements ValueListenable<SelectionGeometry> { + /// Marks this handler to be responsible for pushing [LeaderLayer]s for the + /// selection handles. + /// + /// This handler is responsible for pushing the leader layers with the + /// given layer links if they are not null. It is possible that only one layer + /// is non-null if this handler is only responsible for pushing one layer + /// link. + /// + /// The `startHandle` needs to be placed at the visual location of selection + /// start, the `endHandle` needs to be placed at the visual location of selection + /// end. Typically, the visual locations should be the same as + /// [SelectionGeometry.startSelectionPoint] and + /// [SelectionGeometry.endSelectionPoint]. + void pushHandleLayers(LayerLink? startHandle, LayerLink? endHandle); + + /// Gets the selected content in this object. + /// + /// Return `null` if nothing is selected. + SelectedContent? getSelectedContent(); + + /// Handles the [SelectionEvent] sent to this object. + /// + /// The subclasses need to update their selections or delegate the + /// [SelectionEvent]s to their subtrees. + /// + /// The `event`s are subclasses of [SelectionEvent]. Check + /// [SelectionEvent.type] to determine what kinds of event are dispatched to + /// this handler and handle them accordingly. + /// + /// See also: + /// * [SelectionEventType], which contains all of the possible types. + SelectionResult dispatchSelectionEvent(SelectionEvent event); +} + +/// The selected content in a [Selectable] or [SelectionHandler]. +// TODO(chunhtai): Add more support for rich content. +// https://github.com/flutter/flutter/issues/104206. +class SelectedContent { + /// Creates a selected content object. + /// + /// Only supports plain text. + const SelectedContent({required this.plainText}); + + /// The selected content in plain text format. + final String plainText; +} + +/// A mixin that can be selected by users when under a [SelectionArea] widget. +/// +/// This object receives selection events and the [value] must reflect the +/// current selection in this [Selectable]. The object must also notify its +/// listener if the [value] ever changes. +/// +/// This object is responsible for drawing the selection highlight. +/// +/// In order to receive the selection event, the mixer needs to register +/// itself to [SelectionRegistrar]s. Use +/// [SelectionContainer.maybeOf] to get the selection registrar, and +/// mix the [SelectionRegistrant] to subscribe to the [SelectionRegistrar] +/// automatically. +/// +/// This mixin is typically mixed by [RenderObject]s. The [RenderObject.paint] +/// methods are responsible to push the [LayerLink]s provided to +/// [pushHandleLayers]. +/// +/// {@macro flutter.rendering.SelectionHandler} +/// +/// See also: +/// * [SelectionArea], which provides an overview of selection system. +mixin Selectable implements SelectionHandler { + /// {@macro flutter.rendering.RenderObject.getTransformTo} + Matrix4 getTransformTo(RenderObject? ancestor); + + /// The size of this [Selectable]. + Size get size; + + /// A list of [Rect]s that represent the bounding box of this [Selectable] + /// in local coordinates. + List<Rect> get boundingBoxes; + + /// Disposes resources held by the mixer. + void dispose(); +} + +/// A mixin to auto-register the mixer to the [registrar]. +/// +/// To use this mixin, the mixer needs to set the [registrar] to the +/// [SelectionRegistrar] it wants to register to. +/// +/// This mixin only registers the mixer with the [registrar] if the +/// [SelectionGeometry.hasContent] returned by the mixer is true. +mixin SelectionRegistrant on Selectable { + /// The [SelectionRegistrar] the mixer will be or is registered to. + /// + /// This [Selectable] only registers the mixer if the + /// [SelectionGeometry.hasContent] returned by the [Selectable] is true. + SelectionRegistrar? get registrar => _registrar; + SelectionRegistrar? _registrar; + set registrar(SelectionRegistrar? value) { + if (value == _registrar) { + return; + } + if (value == null) { + // When registrar goes from non-null to null; + removeListener(_updateSelectionRegistrarSubscription); + } else if (_registrar == null) { + // When registrar goes from null to non-null; + addListener(_updateSelectionRegistrarSubscription); + } + _removeSelectionRegistrarSubscription(); + _registrar = value; + _updateSelectionRegistrarSubscription(); + } + + @override + void dispose() { + _removeSelectionRegistrarSubscription(); + super.dispose(); + } + + bool _subscribedToSelectionRegistrar = false; + void _updateSelectionRegistrarSubscription() { + if (_registrar == null) { + _subscribedToSelectionRegistrar = false; + return; + } + if (_subscribedToSelectionRegistrar && !value.hasContent) { + _registrar!.remove(this); + _subscribedToSelectionRegistrar = false; + } else if (!_subscribedToSelectionRegistrar && value.hasContent) { + _registrar!.add(this); + _subscribedToSelectionRegistrar = true; + } + } + + void _removeSelectionRegistrarSubscription() { + if (_subscribedToSelectionRegistrar) { + _registrar!.remove(this); + _subscribedToSelectionRegistrar = false; + } + } +} + +/// A utility class that provides useful methods for handling selection events. +abstract final class SelectionUtils { + /// Determines [SelectionResult] purely based on the target rectangle. + /// + /// This method returns [SelectionResult.end] if the `point` is inside the + /// `targetRect`. Returns [SelectionResult.previous] if the `point` is + /// considered to be lower than `targetRect` in screen order. Returns + /// [SelectionResult.next] if the point is considered to be higher than + /// `targetRect` in screen order. + static SelectionResult getResultBasedOnRect(Rect targetRect, Offset point) { + if (targetRect.contains(point)) { + return SelectionResult.end; + } + if (point.dy < targetRect.top) { + return SelectionResult.previous; + } + if (point.dy > targetRect.bottom) { + return SelectionResult.next; + } + return point.dx >= targetRect.right + ? SelectionResult.next + : SelectionResult.previous; + } + + /// Adjusts the dragging offset based on the target rect. + /// + /// This method moves the offsets to be within the target rect in case they are + /// outside the rect. + /// + /// This is used in the case where a drag happens outside of the rectangle + /// of a [Selectable]. + /// + /// The logic works as the following: + /// ![](https://flutter.github.io/assets-for-api-docs/assets/rendering/adjust_drag_offset.png) + /// + /// For points inside the rect: + /// Their effective locations are unchanged. + /// + /// For points in Area 1: + /// Move them to top-left of the rect if text direction is ltr, or top-right + /// if rtl. + /// + /// For points in Area 2: + /// Move them to bottom-right of the rect if text direction is ltr, or + /// bottom-left if rtl. + static Offset adjustDragOffset(Rect targetRect, Offset point, {TextDirection direction = TextDirection.ltr}) { + if (targetRect.contains(point)) { + return point; + } + if (point.dy <= targetRect.top || + point.dy <= targetRect.bottom && point.dx <= targetRect.left) { + // Area 1 + return direction == TextDirection.ltr ? targetRect.topLeft : targetRect.topRight; + } else { + // Area 2 + return direction == TextDirection.ltr ? targetRect.bottomRight : targetRect.bottomLeft; + } + } +} + +/// The type of a [SelectionEvent]. +/// +/// Used by [SelectionEvent.type] to distinguish different types of events. +enum SelectionEventType { + /// An event to update the selection start edge. + /// + /// Used by [SelectionEdgeUpdateEvent]. + startEdgeUpdate, + + /// An event to update the selection end edge. + /// + /// Used by [SelectionEdgeUpdateEvent]. + endEdgeUpdate, + + /// An event to clear the current selection. + /// + /// Used by [ClearSelectionEvent]. + clear, + + /// An event to select all the available content. + /// + /// Used by [SelectAllSelectionEvent]. + selectAll, + + /// An event to select a word at the location + /// [SelectWordSelectionEvent.globalPosition]. + /// + /// Used by [SelectWordSelectionEvent]. + selectWord, + + /// An event that extends the selection by a specific [TextGranularity]. + granularlyExtendSelection, + + /// An event that extends the selection in a specific direction. + directionallyExtendSelection, +} + +/// The unit of how selection handles move in text. +/// +/// The [GranularlyExtendSelectionEvent] uses this enum to describe how +/// [Selectable] should extend its selection. +enum TextGranularity { + /// Treats each character as an atomic unit when moving the selection handles. + character, + + /// Treats word as an atomic unit when moving the selection handles. + word, + + /// Treats each line break as an atomic unit when moving the selection handles. + line, + + /// Treats the entire document as an atomic unit when moving the selection handles. + document, +} + +/// An abstract base class for selection events. +/// +/// This should not be directly used. To handle a selection event, it should +/// be downcast to a specific subclass. One can use [type] to look up which +/// subclasses to downcast to. +/// +/// See also: +/// * [SelectAllSelectionEvent], for events to select all contents. +/// * [ClearSelectionEvent], for events to clear selections. +/// * [SelectWordSelectionEvent], for events to select words at the locations. +/// * [SelectionEdgeUpdateEvent], for events to update selection edges. +/// * [SelectionEventType], for determining the subclass types. +abstract class SelectionEvent { + const SelectionEvent._(this.type); + + /// The type of this selection event. + final SelectionEventType type; +} + +/// Selects all selectable contents. +/// +/// This event can be sent as the result of keyboard select-all, i.e. +/// ctrl + A, or cmd + A in macOS. +class SelectAllSelectionEvent extends SelectionEvent { + /// Creates a select all selection event. + const SelectAllSelectionEvent(): super._(SelectionEventType.selectAll); +} + +/// Clears the selection from the [Selectable] and removes any existing +/// highlight as if there is no selection at all. +class ClearSelectionEvent extends SelectionEvent { + /// Create a clear selection event. + const ClearSelectionEvent(): super._(SelectionEventType.clear); +} + +/// Selects the whole word at the location. +/// +/// This event can be sent as the result of mobile long press selection. +class SelectWordSelectionEvent extends SelectionEvent { + /// Creates a select word event at the [globalPosition]. + const SelectWordSelectionEvent({required this.globalPosition}): super._(SelectionEventType.selectWord); + + /// The position in global coordinates to select word at. + final Offset globalPosition; +} + +/// Updates a selection edge. +/// +/// An active selection contains two edges, start and end. Use the [type] to +/// determine which edge this event applies to. If the [type] is +/// [SelectionEventType.startEdgeUpdate], the event updates start edge. If the +/// [type] is [SelectionEventType.endEdgeUpdate], the event updates end edge. +/// +/// The [globalPosition] contains the new offset of the edge. +/// +/// The [granularity] contains the granularity that the selection edge should move by. +/// Only [TextGranularity.character] and [TextGranularity.word] are currently supported. +/// +/// This event is dispatched when the framework detects [TapDragStartDetails] in +/// [SelectionArea]'s gesture recognizers for mouse devices, or the selection +/// handles have been dragged to new locations. +class SelectionEdgeUpdateEvent extends SelectionEvent { + /// Creates a selection start edge update event. + /// + /// The [globalPosition] contains the location of the selection start edge. + /// + /// The [granularity] contains the granularity which the selection edge should move by. + /// This value defaults to [TextGranularity.character]. + const SelectionEdgeUpdateEvent.forStart({ + required this.globalPosition, + TextGranularity? granularity + }) : granularity = granularity ?? TextGranularity.character, super._(SelectionEventType.startEdgeUpdate); + + /// Creates a selection end edge update event. + /// + /// The [globalPosition] contains the new location of the selection end edge. + /// + /// The [granularity] contains the granularity which the selection edge should move by. + /// This value defaults to [TextGranularity.character]. + const SelectionEdgeUpdateEvent.forEnd({ + required this.globalPosition, + TextGranularity? granularity + }) : granularity = granularity ?? TextGranularity.character, super._(SelectionEventType.endEdgeUpdate); + + /// The new location of the selection edge. + final Offset globalPosition; + + /// The granularity for which the selection moves. + /// + /// Only [TextGranularity.character] and [TextGranularity.word] are currently supported. + /// + /// Defaults to [TextGranularity.character]. + final TextGranularity granularity; +} + +/// Extends the start or end of the selection by a given [TextGranularity]. +/// +/// To handle this event, move the associated selection edge, as dictated by +/// [isEnd], according to the [granularity]. +class GranularlyExtendSelectionEvent extends SelectionEvent { + /// Creates a [GranularlyExtendSelectionEvent]. + const GranularlyExtendSelectionEvent({ + required this.forward, + required this.isEnd, + required this.granularity, + }) : super._(SelectionEventType.granularlyExtendSelection); + + /// Whether to extend the selection forward. + final bool forward; + + /// Whether this event is updating the end selection edge. + final bool isEnd; + + /// The granularity for which the selection extend. + final TextGranularity granularity; +} + +/// The direction to extend a selection. +/// +/// The [DirectionallyExtendSelectionEvent] uses this enum to describe how +/// [Selectable] should extend their selection. +enum SelectionExtendDirection { + /// Move one edge of the selection vertically to the previous adjacent line. + /// + /// For text selection, it should consider both soft and hard linebreak. + /// + /// See [DirectionallyExtendSelectionEvent.dx] on how to + /// calculate the horizontal offset. + previousLine, + + /// Move one edge of the selection vertically to the next adjacent line. + /// + /// For text selection, it should consider both soft and hard linebreak. + /// + /// See [DirectionallyExtendSelectionEvent.dx] on how to + /// calculate the horizontal offset. + nextLine, + + /// Move the selection edges forward to a certain horizontal offset in the + /// same line. + /// + /// If there is no on-going selection, the selection must start with the first + /// line (or equivalence of first line in a non-text selectable) and select + /// toward the horizontal offset in the same line. + /// + /// The selectable that receives [DirectionallyExtendSelectionEvent] with this + /// enum must return [SelectionResult.end]. + /// + /// See [DirectionallyExtendSelectionEvent.dx] on how to + /// calculate the horizontal offset. + forward, + + /// Move the selection edges backward to a certain horizontal offset in the + /// same line. + /// + /// If there is no on-going selection, the selection must start with the last + /// line (or equivalence of last line in a non-text selectable) and select + /// backward the horizontal offset in the same line. + /// + /// The selectable that receives [DirectionallyExtendSelectionEvent] with this + /// enum must return [SelectionResult.end]. + /// + /// See [DirectionallyExtendSelectionEvent.dx] on how to + /// calculate the horizontal offset. + backward, +} + +/// Extends the current selection with respect to a [direction]. +/// +/// To handle this event, move the associated selection edge, as dictated by +/// [isEnd], according to the [direction]. +/// +/// The movements are always based on [dx]. The value is in +/// global coordinates and is the horizontal offset the selection edge should +/// move to when moving to across lines. +class DirectionallyExtendSelectionEvent extends SelectionEvent { + /// Creates a [DirectionallyExtendSelectionEvent]. + const DirectionallyExtendSelectionEvent({ + required this.dx, + required this.isEnd, + required this.direction, + }) : super._(SelectionEventType.directionallyExtendSelection); + + /// The horizontal offset the selection should move to. + /// + /// The offset is in global coordinates. + final double dx; + + /// Whether this event is updating the end selection edge. + final bool isEnd; + + /// The directional movement of this event. + /// + /// See also: + /// * [SelectionExtendDirection], which explains how to handle each enum. + final SelectionExtendDirection direction; + + /// Makes a copy of this object with its property replaced with the new + /// values. + DirectionallyExtendSelectionEvent copyWith({ + double? dx, + bool? isEnd, + SelectionExtendDirection? direction, + }) { + return DirectionallyExtendSelectionEvent( + dx: dx ?? this.dx, + isEnd: isEnd ?? this.isEnd, + direction: direction ?? this.direction, + ); + } +} + +/// A registrar that keeps track of [Selectable]s in the subtree. +/// +/// A [Selectable] is only included in the [SelectableRegion] if they are +/// registered with a [SelectionRegistrar]. Once a [Selectable] is registered, +/// it will receive [SelectionEvent]s in +/// [SelectionHandler.dispatchSelectionEvent]. +/// +/// Use [SelectionContainer.maybeOf] to get the immediate [SelectionRegistrar] +/// in the ancestor chain above the build context. +/// +/// See also: +/// * [SelectableRegion], which provides an overview of the selection system. +/// * [SelectionRegistrarScope], which hosts the [SelectionRegistrar] for the +/// subtree. +/// * [SelectionRegistrant], which auto registers the object with the mixin to +/// [SelectionRegistrar]. +abstract class SelectionRegistrar { + /// Adds the [selectable] into the registrar. + /// + /// A [Selectable] must register with the [SelectionRegistrar] in order to + /// receive selection events. + void add(Selectable selectable); + + /// Removes the [selectable] from the registrar. + /// + /// A [Selectable] must unregister itself if it is removed from the rendering + /// tree. + void remove(Selectable selectable); +} + +/// The status that indicates whether there is a selection and whether the +/// selection is collapsed. +/// +/// A collapsed selection means the selection starts and ends at the same +/// location. +enum SelectionStatus { + /// The selection is not collapsed. + /// + /// For example if `{}` represent the selection edges: + /// 'ab{cd}', the collapsing status is [uncollapsed]. + /// '{abcd}', the collapsing status is [uncollapsed]. + uncollapsed, + + /// The selection is collapsed. + /// + /// For example if `{}` represent the selection edges: + /// 'ab{}cd', the collapsing status is [collapsed]. + /// '{}abcd', the collapsing status is [collapsed]. + /// 'abcd{}', the collapsing status is [collapsed]. + collapsed, + + /// No selection. + none, +} + +/// The geometry of the current selection. +/// +/// This includes details such as the locations of the selection start and end, +/// line height, the rects that encompass the selection, etc. This information +/// is used for drawing selection controls for mobile platforms. +/// +/// The positions in geometry are in local coordinates of the [SelectionHandler] +/// or [Selectable]. +@immutable +class SelectionGeometry { + /// Creates a selection geometry object. + /// + /// If any of the [startSelectionPoint] and [endSelectionPoint] is not null, + /// the [status] must not be [SelectionStatus.none]. + const SelectionGeometry({ + this.startSelectionPoint, + this.endSelectionPoint, + this.selectionRects = const <Rect>[], + required this.status, + required this.hasContent, + }) : assert((startSelectionPoint == null && endSelectionPoint == null) || status != SelectionStatus.none); + + /// The geometry information at the selection start. + /// + /// This information is used for drawing mobile selection controls. The + /// [SelectionPoint.localPosition] of the selection start is typically at the + /// start of the selection highlight at where the start selection handle + /// should be drawn. + /// + /// The [SelectionPoint.handleType] should be [TextSelectionHandleType.left] + /// for forward selection or [TextSelectionHandleType.right] for backward + /// selection in most cases. + /// + /// Can be null if the selection start is offstage, for example, when the + /// selection is outside of the viewport or is kept alive by a scrollable. + final SelectionPoint? startSelectionPoint; + + /// The geometry information at the selection end. + /// + /// This information is used for drawing mobile selection controls. The + /// [SelectionPoint.localPosition] of the selection end is typically at the end + /// of the selection highlight at where the end selection handle should be + /// drawn. + /// + /// The [SelectionPoint.handleType] should be [TextSelectionHandleType.right] + /// for forward selection or [TextSelectionHandleType.left] for backward + /// selection in most cases. + /// + /// Can be null if the selection end is offstage, for example, when the + /// selection is outside of the viewport or is kept alive by a scrollable. + final SelectionPoint? endSelectionPoint; + + /// The status of ongoing selection in the [Selectable] or [SelectionHandler]. + final SelectionStatus status; + + /// The rects in the local coordinates of the containing [Selectable] that + /// represent the selection if there is any. + final List<Rect> selectionRects; + + /// Whether there is any selectable content in the [Selectable] or + /// [SelectionHandler]. + final bool hasContent; + + /// Whether there is an ongoing selection. + bool get hasSelection => status != SelectionStatus.none; + + /// Makes a copy of this object with the given values updated. + SelectionGeometry copyWith({ + SelectionPoint? startSelectionPoint, + SelectionPoint? endSelectionPoint, + List<Rect>? selectionRects, + SelectionStatus? status, + bool? hasContent, + }) { + return SelectionGeometry( + startSelectionPoint: startSelectionPoint ?? this.startSelectionPoint, + endSelectionPoint: endSelectionPoint ?? this.endSelectionPoint, + selectionRects: selectionRects ?? this.selectionRects, + status: status ?? this.status, + hasContent: hasContent ?? this.hasContent, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is SelectionGeometry + && other.startSelectionPoint == startSelectionPoint + && other.endSelectionPoint == endSelectionPoint + && other.selectionRects == selectionRects + && other.status == status + && other.hasContent == hasContent; + } + + @override + int get hashCode { + return Object.hash( + startSelectionPoint, + endSelectionPoint, + selectionRects, + status, + hasContent, + ); + } +} + +/// The geometry information of a selection point. +@immutable +class SelectionPoint with Diagnosticable { + /// Creates a selection point object. + const SelectionPoint({ + required this.localPosition, + required this.lineHeight, + required this.handleType, + }); + + /// The position of the selection point in the local coordinates of the + /// containing [Selectable]. + final Offset localPosition; + + /// The line height at the selection point. + final double lineHeight; + + /// The selection handle type that should be used at the selection point. + /// + /// This is used for building the mobile selection handle. + final TextSelectionHandleType handleType; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is SelectionPoint + && other.localPosition == localPosition + && other.lineHeight == lineHeight + && other.handleType == handleType; + } + + @override + int get hashCode { + return Object.hash( + localPosition, + lineHeight, + handleType, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Offset>('localPosition', localPosition)); + properties.add(DoubleProperty('lineHeight', lineHeight)); + properties.add(EnumProperty<TextSelectionHandleType>('handleType', handleType)); + } +} + +/// The type of selection handle to be displayed. +/// +/// With mixed-direction text, both handles may be the same type. Examples: +/// +/// * LTR text: 'the <quick brown> fox': +/// +/// The '<' is drawn with the [left] type, the '>' with the [right] +/// +/// * RTL text: 'XOF <NWORB KCIUQ> EHT': +/// +/// Same as above. +/// +/// * mixed text: '<the NWOR<B KCIUQ fox' +/// +/// Here 'the QUICK B' is selected, but 'QUICK BROWN' is RTL. Both are drawn +/// with the [left] type. +/// +/// See also: +/// +/// * [TextDirection], which discusses left-to-right and right-to-left text in +/// more detail. +enum TextSelectionHandleType { + /// The selection handle is to the left of the selection end point. + left, + + /// The selection handle is to the right of the selection end point. + right, + + /// The start and end of the selection are co-incident at this point. + collapsed, +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/service_extensions.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/service_extensions.dart new file mode 100644 index 0000000000000000000000000000000000000000..2f58135e3ebe288770db890586467c1f2e91abcf --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/service_extensions.dart @@ -0,0 +1,152 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Service extension constants for the rendering library. +/// +/// These constants will be used when registering service extensions in the +/// framework, and they will also be used by tools and services that call these +/// service extensions. +/// +/// The String value for each of these extension names should be accessed by +/// calling the `.name` property on the enum value. +enum RenderingServiceExtensions { + /// Name of service extension that, when called, will toggle whether the + /// framework will color invert and horizontally flip images that have been + /// decoded to a size taking at least [debugImageOverheadAllowance] bytes more + /// than necessary. + /// + /// See also: + /// + /// * [debugInvertOversizedImages], which is the flag that this service + /// extension exposes. + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + invertOversizedImages, + + /// Name of service extension that, when called, will toggle whether each + /// [RenderBox] will paint a box around its bounds as well as additional boxes + /// showing construction lines. + /// + /// See also: + /// + /// * [debugPaintSizeEnabled], which is the flag that this service extension + /// exposes. + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + debugPaint, + + /// Name of service extension that, when called, will toggle whether each + /// [RenderBox] will paint a line at each of its baselines. + /// + /// See also: + /// + /// * [debugPaintBaselinesEnabled], which is the flag that this service + /// extension exposes. + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + debugPaintBaselinesEnabled, + + /// Name of service extension that, when called, will toggle whether a rotating + /// set of colors will be overlaid on the device when repainting layers in debug + /// mode. + /// + /// See also: + /// + /// * [debugRepaintRainbowEnabled], which is the flag that this service + /// extension exposes. + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + repaintRainbow, + + /// Name of service extension that, when called, will dump a [String] + /// representation of the layer tree to console. + /// + /// See also: + /// + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + debugDumpLayerTree, + + /// Name of service extension that, when called, will toggle whether all + /// clipping effects from the layer tree will be ignored. + /// + /// See also: + /// + /// * [debugDisableClipLayers], which is the flag that this service extension + /// exposes. + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + debugDisableClipLayers, + + /// Name of service extension that, when called, will toggle whether all + /// physical modeling effects from the layer tree will be ignored. + /// + /// See also: + /// + /// * [debugDisablePhysicalShapeLayers], which is the flag that this service + /// extension exposes. + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + debugDisablePhysicalShapeLayers, + + /// Name of service extension that, when called, will toggle whether all opacity + /// effects from the layer tree will be ignored. + /// + /// See also: + /// + /// * [debugDisableOpacityLayers], which is the flag that this service extension + /// exposes. + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + debugDisableOpacityLayers, + + /// Name of service extension that, when called, will dump a [String] + /// representation of the render tree to console. + /// + /// See also: + /// + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + debugDumpRenderTree, + + /// Name of service extension that, when called, will dump a [String] + /// representation of the semantics tree (in traversal order) to console. + /// + /// See also: + /// + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + debugDumpSemanticsTreeInTraversalOrder, + + /// Name of service extension that, when called, will dump a [String] + /// representation of the semantics tree (in inverse hit test order) to console. + /// + /// See also: + /// + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + debugDumpSemanticsTreeInInverseHitTestOrder, + + /// Name of service extension that, when called, will toggle whether [Timeline] + /// events are added for every [RenderObject] painted. + /// + /// See also: + /// + /// * [debugProfilePaintsEnabled], which is the flag that this service extension + /// exposes. + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + profileRenderObjectPaints, + + /// Name of service extension that, when called, will toggle whether [Timeline] + /// events are added for every [RenderObject] laid out. + /// + /// See also: + /// + /// * [debugProfileLayoutsEnabled], which is the flag that this service + /// extension exposes. + /// * [RendererBinding.initServiceExtensions], where the service extension is + /// registered. + profileRenderObjectLayouts, +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/shifted_box.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/shifted_box.dart new file mode 100644 index 0000000000000000000000000000000000000000..f24f5e3aa5c9ef4ac781842b50ea4c01b950999e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/shifted_box.dart @@ -0,0 +1,1461 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'debug.dart'; +import 'debug_overflow_indicator.dart'; +import 'layer.dart'; +import 'object.dart'; +import 'stack.dart' show RelativeRect; + +/// Signature for a function that transforms a [BoxConstraints] to another +/// [BoxConstraints]. +/// +/// Used by [RenderConstraintsTransformBox] and [ConstraintsTransformBox]. +/// Typically the caller requires the returned [BoxConstraints] to be +/// [BoxConstraints.isNormalized]. +typedef BoxConstraintsTransform = BoxConstraints Function(BoxConstraints constraints); + +/// Abstract class for one-child-layout render boxes that provide control over +/// the child's position. +abstract class RenderShiftedBox extends RenderBox with RenderObjectWithChildMixin<RenderBox> { + /// Initializes the [child] property for subclasses. + RenderShiftedBox(RenderBox? child) { + this.child = child; + } + + @override + double computeMinIntrinsicWidth(double height) { + return child?.getMinIntrinsicWidth(height) ?? 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + return child?.getMaxIntrinsicWidth(height) ?? 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + return child?.getMinIntrinsicHeight(width) ?? 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + return child?.getMaxIntrinsicHeight(width) ?? 0.0; + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + double? result; + final RenderBox? child = this.child; + if (child != null) { + assert(!debugNeedsLayout); + result = child.getDistanceToActualBaseline(baseline); + final BoxParentData childParentData = child.parentData! as BoxParentData; + if (result != null) { + result += childParentData.offset.dy; + } + } else { + result = super.computeDistanceToActualBaseline(baseline); + } + return result; + } + + @override + void paint(PaintingContext context, Offset offset) { + final RenderBox? child = this.child; + if (child != null) { + final BoxParentData childParentData = child.parentData! as BoxParentData; + context.paintChild(child, childParentData.offset + offset); + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + final RenderBox? child = this.child; + if (child != null) { + final BoxParentData childParentData = child.parentData! as BoxParentData; + return result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - childParentData.offset); + return child.hitTest(result, position: transformed); + }, + ); + } + return false; + } +} + +/// Insets its child by the given padding. +/// +/// When passing layout constraints to its child, padding shrinks the +/// constraints by the given padding, causing the child to layout at a smaller +/// size. Padding then sizes itself to its child's size, inflated by the +/// padding, effectively creating empty space around the child. +class RenderPadding extends RenderShiftedBox { + /// Creates a render object that insets its child. + /// + /// The [padding] argument must have non-negative insets. + RenderPadding({ + required EdgeInsetsGeometry padding, + TextDirection? textDirection, + RenderBox? child, + }) : assert(padding.isNonNegative), + _textDirection = textDirection, + _padding = padding, + super(child); + + EdgeInsets? _resolvedPadding; + + void _resolve() { + if (_resolvedPadding != null) { + return; + } + _resolvedPadding = padding.resolve(textDirection); + assert(_resolvedPadding!.isNonNegative); + } + + void _markNeedResolution() { + _resolvedPadding = null; + markNeedsLayout(); + } + + /// The amount to pad the child in each dimension. + /// + /// If this is set to an [EdgeInsetsDirectional] object, then [textDirection] + /// must not be null. + EdgeInsetsGeometry get padding => _padding; + EdgeInsetsGeometry _padding; + set padding(EdgeInsetsGeometry value) { + assert(value.isNonNegative); + if (_padding == value) { + return; + } + _padding = value; + _markNeedResolution(); + } + + /// The text direction with which to resolve [padding]. + /// + /// This may be changed to null, but only after the [padding] has been changed + /// to a value that does not depend on the direction. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + _markNeedResolution(); + } + + @override + double computeMinIntrinsicWidth(double height) { + _resolve(); + final double totalHorizontalPadding = _resolvedPadding!.left + _resolvedPadding!.right; + final double totalVerticalPadding = _resolvedPadding!.top + _resolvedPadding!.bottom; + if (child != null) { + // Relies on double.infinity absorption. + return child!.getMinIntrinsicWidth(math.max(0.0, height - totalVerticalPadding)) + totalHorizontalPadding; + } + return totalHorizontalPadding; + } + + @override + double computeMaxIntrinsicWidth(double height) { + _resolve(); + final double totalHorizontalPadding = _resolvedPadding!.left + _resolvedPadding!.right; + final double totalVerticalPadding = _resolvedPadding!.top + _resolvedPadding!.bottom; + if (child != null) { + // Relies on double.infinity absorption. + return child!.getMaxIntrinsicWidth(math.max(0.0, height - totalVerticalPadding)) + totalHorizontalPadding; + } + return totalHorizontalPadding; + } + + @override + double computeMinIntrinsicHeight(double width) { + _resolve(); + final double totalHorizontalPadding = _resolvedPadding!.left + _resolvedPadding!.right; + final double totalVerticalPadding = _resolvedPadding!.top + _resolvedPadding!.bottom; + if (child != null) { + // Relies on double.infinity absorption. + return child!.getMinIntrinsicHeight(math.max(0.0, width - totalHorizontalPadding)) + totalVerticalPadding; + } + return totalVerticalPadding; + } + + @override + double computeMaxIntrinsicHeight(double width) { + _resolve(); + final double totalHorizontalPadding = _resolvedPadding!.left + _resolvedPadding!.right; + final double totalVerticalPadding = _resolvedPadding!.top + _resolvedPadding!.bottom; + if (child != null) { + // Relies on double.infinity absorption. + return child!.getMaxIntrinsicHeight(math.max(0.0, width - totalHorizontalPadding)) + totalVerticalPadding; + } + return totalVerticalPadding; + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + _resolve(); + assert(_resolvedPadding != null); + if (child == null) { + return constraints.constrain(Size( + _resolvedPadding!.left + _resolvedPadding!.right, + _resolvedPadding!.top + _resolvedPadding!.bottom, + )); + } + final BoxConstraints innerConstraints = constraints.deflate(_resolvedPadding!); + final Size childSize = child!.getDryLayout(innerConstraints); + return constraints.constrain(Size( + _resolvedPadding!.left + childSize.width + _resolvedPadding!.right, + _resolvedPadding!.top + childSize.height + _resolvedPadding!.bottom, + )); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + _resolve(); + assert(_resolvedPadding != null); + if (child == null) { + size = constraints.constrain(Size( + _resolvedPadding!.left + _resolvedPadding!.right, + _resolvedPadding!.top + _resolvedPadding!.bottom, + )); + return; + } + final BoxConstraints innerConstraints = constraints.deflate(_resolvedPadding!); + child!.layout(innerConstraints, parentUsesSize: true); + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = Offset(_resolvedPadding!.left, _resolvedPadding!.top); + size = constraints.constrain(Size( + _resolvedPadding!.left + child!.size.width + _resolvedPadding!.right, + _resolvedPadding!.top + child!.size.height + _resolvedPadding!.bottom, + )); + } + + @override + void debugPaintSize(PaintingContext context, Offset offset) { + super.debugPaintSize(context, offset); + assert(() { + final Rect outerRect = offset & size; + debugPaintPadding(context.canvas, outerRect, child != null ? _resolvedPadding!.deflateRect(outerRect) : null); + return true; + }()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + } +} + +/// Abstract class for one-child-layout render boxes that use a +/// [AlignmentGeometry] to align their children. +abstract class RenderAligningShiftedBox extends RenderShiftedBox { + /// Initializes member variables for subclasses. + /// + /// The [textDirection] must be non-null if the [alignment] is + /// direction-sensitive. + RenderAligningShiftedBox({ + AlignmentGeometry alignment = Alignment.center, + required TextDirection? textDirection, + RenderBox? child, + }) : _alignment = alignment, + _textDirection = textDirection, + super(child); + + Alignment? _resolvedAlignment; + + void _resolve() { + if (_resolvedAlignment != null) { + return; + } + _resolvedAlignment = alignment.resolve(textDirection); + } + + void _markNeedResolution() { + _resolvedAlignment = null; + markNeedsLayout(); + } + + /// How to align the child. + /// + /// The x and y values of the alignment control the horizontal and vertical + /// alignment, respectively. An x value of -1.0 means that the left edge of + /// the child is aligned with the left edge of the parent whereas an x value + /// of 1.0 means that the right edge of the child is aligned with the right + /// edge of the parent. Other values interpolate (and extrapolate) linearly. + /// For example, a value of 0.0 means that the center of the child is aligned + /// with the center of the parent. + /// + /// If this is set to an [AlignmentDirectional] object, then + /// [textDirection] must not be null. + AlignmentGeometry get alignment => _alignment; + AlignmentGeometry _alignment; + /// Sets the alignment to a new value, and triggers a layout update. + set alignment(AlignmentGeometry value) { + if (_alignment == value) { + return; + } + _alignment = value; + _markNeedResolution(); + } + + /// The text direction with which to resolve [alignment]. + /// + /// This may be changed to null, but only after [alignment] has been changed + /// to a value that does not depend on the direction. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + _markNeedResolution(); + } + + /// Apply the current [alignment] to the [child]. + /// + /// Subclasses should call this method if they have a child, to have + /// this class perform the actual alignment. If there is no child, + /// do not call this method. + /// + /// This method must be called after the child has been laid out and + /// this object's own size has been set. + @protected + void alignChild() { + _resolve(); + assert(child != null); + assert(!child!.debugNeedsLayout); + assert(child!.hasSize); + assert(hasSize); + assert(_resolvedAlignment != null); + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = _resolvedAlignment!.alongOffset(size - child!.size as Offset); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + } +} + +/// Positions its child using an [AlignmentGeometry]. +/// +/// For example, to align a box at the bottom right, you would pass this box a +/// tight constraint that is bigger than the child's natural size, +/// with an alignment of [Alignment.bottomRight]. +/// +/// By default, sizes to be as big as possible in both axes. If either axis is +/// unconstrained, then in that direction it will be sized to fit the child's +/// dimensions. Using widthFactor and heightFactor you can force this latter +/// behavior in all cases. +class RenderPositionedBox extends RenderAligningShiftedBox { + /// Creates a render object that positions its child. + RenderPositionedBox({ + super.child, + double? widthFactor, + double? heightFactor, + super.alignment, + super.textDirection, + }) : assert(widthFactor == null || widthFactor >= 0.0), + assert(heightFactor == null || heightFactor >= 0.0), + _widthFactor = widthFactor, + _heightFactor = heightFactor; + + /// If non-null, sets its width to the child's width multiplied by this factor. + /// + /// Can be both greater and less than 1.0 but must be positive. + double? get widthFactor => _widthFactor; + double? _widthFactor; + set widthFactor(double? value) { + assert(value == null || value >= 0.0); + if (_widthFactor == value) { + return; + } + _widthFactor = value; + markNeedsLayout(); + } + + /// If non-null, sets its height to the child's height multiplied by this factor. + /// + /// Can be both greater and less than 1.0 but must be positive. + double? get heightFactor => _heightFactor; + double? _heightFactor; + set heightFactor(double? value) { + assert(value == null || value >= 0.0); + if (_heightFactor == value) { + return; + } + _heightFactor = value; + markNeedsLayout(); + } + + @override + double computeMinIntrinsicWidth(double height) { + return super.computeMinIntrinsicWidth(height) * (_widthFactor ?? 1); + } + + @override + double computeMaxIntrinsicWidth(double height) { + return super.computeMaxIntrinsicWidth(height) * (_widthFactor ?? 1); + } + + @override + double computeMinIntrinsicHeight(double width) { + return super.computeMinIntrinsicHeight(width) * (_heightFactor ?? 1); + } + + @override + double computeMaxIntrinsicHeight(double width) { + return super.computeMaxIntrinsicHeight(width) * (_heightFactor ?? 1); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + final bool shrinkWrapWidth = _widthFactor != null || constraints.maxWidth == double.infinity; + final bool shrinkWrapHeight = _heightFactor != null || constraints.maxHeight == double.infinity; + if (child != null) { + final Size childSize = child!.getDryLayout(constraints.loosen()); + return constraints.constrain(Size( + shrinkWrapWidth ? childSize.width * (_widthFactor ?? 1.0) : double.infinity, + shrinkWrapHeight ? childSize.height * (_heightFactor ?? 1.0) : double.infinity, + )); + } + return constraints.constrain(Size( + shrinkWrapWidth ? 0.0 : double.infinity, + shrinkWrapHeight ? 0.0 : double.infinity, + )); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + final bool shrinkWrapWidth = _widthFactor != null || constraints.maxWidth == double.infinity; + final bool shrinkWrapHeight = _heightFactor != null || constraints.maxHeight == double.infinity; + + if (child != null) { + child!.layout(constraints.loosen(), parentUsesSize: true); + size = constraints.constrain(Size( + shrinkWrapWidth ? child!.size.width * (_widthFactor ?? 1.0) : double.infinity, + shrinkWrapHeight ? child!.size.height * (_heightFactor ?? 1.0) : double.infinity, + )); + alignChild(); + } else { + size = constraints.constrain(Size( + shrinkWrapWidth ? 0.0 : double.infinity, + shrinkWrapHeight ? 0.0 : double.infinity, + )); + } + } + + @override + void debugPaintSize(PaintingContext context, Offset offset) { + super.debugPaintSize(context, offset); + assert(() { + final Paint paint; + if (child != null && !child!.size.isEmpty) { + final Path path; + paint = Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 1.0 + ..color = const Color(0xFFFFFF00); + path = Path(); + final BoxParentData childParentData = child!.parentData! as BoxParentData; + if (childParentData.offset.dy > 0.0) { + // vertical alignment arrows + final double headSize = math.min(childParentData.offset.dy * 0.2, 10.0); + path + ..moveTo(offset.dx + size.width / 2.0, offset.dy) + ..relativeLineTo(0.0, childParentData.offset.dy - headSize) + ..relativeLineTo(headSize, 0.0) + ..relativeLineTo(-headSize, headSize) + ..relativeLineTo(-headSize, -headSize) + ..relativeLineTo(headSize, 0.0) + ..moveTo(offset.dx + size.width / 2.0, offset.dy + size.height) + ..relativeLineTo(0.0, -childParentData.offset.dy + headSize) + ..relativeLineTo(headSize, 0.0) + ..relativeLineTo(-headSize, -headSize) + ..relativeLineTo(-headSize, headSize) + ..relativeLineTo(headSize, 0.0); + context.canvas.drawPath(path, paint); + } + if (childParentData.offset.dx > 0.0) { + // horizontal alignment arrows + final double headSize = math.min(childParentData.offset.dx * 0.2, 10.0); + path + ..moveTo(offset.dx, offset.dy + size.height / 2.0) + ..relativeLineTo(childParentData.offset.dx - headSize, 0.0) + ..relativeLineTo(0.0, headSize) + ..relativeLineTo(headSize, -headSize) + ..relativeLineTo(-headSize, -headSize) + ..relativeLineTo(0.0, headSize) + ..moveTo(offset.dx + size.width, offset.dy + size.height / 2.0) + ..relativeLineTo(-childParentData.offset.dx + headSize, 0.0) + ..relativeLineTo(0.0, headSize) + ..relativeLineTo(-headSize, -headSize) + ..relativeLineTo(headSize, -headSize) + ..relativeLineTo(0.0, headSize); + context.canvas.drawPath(path, paint); + } + } else { + paint = Paint() + ..color = const Color(0x90909090); + context.canvas.drawRect(offset & size, paint); + } + return true; + }()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('widthFactor', _widthFactor, ifNull: 'expand')); + properties.add(DoubleProperty('heightFactor', _heightFactor, ifNull: 'expand')); + } +} + +/// How much space should be occupied by the [OverflowBox] if there is no +/// overflow. +enum OverflowBoxFit { + /// The widget will size itself to be as large as the parent allows. + max, + + /// The widget will follow the child's size. + /// + /// More specifically, the render object will size itself to match the size of + /// its child within the constraints of its parent, or as small as the + /// parent allows if no child is set. + deferToChild, +} + +/// A render object that imposes different constraints on its child than it gets +/// from its parent, possibly allowing the child to overflow the parent. +/// +/// A render overflow box proxies most functions in the render box protocol to +/// its child, except that when laying out its child, it passes constraints +/// based on the minWidth, maxWidth, minHeight, and maxHeight fields instead of +/// just passing the parent's constraints in. Specifically, it overrides any of +/// the equivalent fields on the constraints given by the parent with the +/// constraints given by these fields for each such field that is not null. It +/// then sizes itself based on the parent's constraints' maxWidth and maxHeight, +/// ignoring the child's dimensions. +/// +/// For example, if you wanted a box to always render 50 pixels high, regardless +/// of where it was rendered, you would wrap it in a +/// RenderConstrainedOverflowBox with minHeight and maxHeight set to 50.0. +/// Generally speaking, to avoid confusing behavior around hit testing, a +/// RenderConstrainedOverflowBox should usually be wrapped in a RenderClipRect. +/// +/// The child is positioned according to [alignment]. To position a smaller +/// child inside a larger parent, use [RenderPositionedBox] and +/// [RenderConstrainedBox] rather than RenderConstrainedOverflowBox. +/// +/// See also: +/// +/// * [RenderConstraintsTransformBox] for a render object that applies an +/// arbitrary transform to its constraints before sizing its child using +/// the new constraints, treating any overflow as error. +/// * [RenderSizedOverflowBox], a render object that is a specific size but +/// passes its original constraints through to its child, which it allows to +/// overflow. +class RenderConstrainedOverflowBox extends RenderAligningShiftedBox { + /// Creates a render object that lets its child overflow itself. + RenderConstrainedOverflowBox({ + super.child, + double? minWidth, + double? maxWidth, + double? minHeight, + double? maxHeight, + OverflowBoxFit fit = OverflowBoxFit.max, + super.alignment, + super.textDirection, + }) : _minWidth = minWidth, + _maxWidth = maxWidth, + _minHeight = minHeight, + _maxHeight = maxHeight, + _fit = fit; + + /// The minimum width constraint to give the child. Set this to null (the + /// default) to use the constraint from the parent instead. + double? get minWidth => _minWidth; + double? _minWidth; + set minWidth(double? value) { + if (_minWidth == value) { + return; + } + _minWidth = value; + markNeedsLayout(); + } + + /// The maximum width constraint to give the child. Set this to null (the + /// default) to use the constraint from the parent instead. + double? get maxWidth => _maxWidth; + double? _maxWidth; + set maxWidth(double? value) { + if (_maxWidth == value) { + return; + } + _maxWidth = value; + markNeedsLayout(); + } + + /// The minimum height constraint to give the child. Set this to null (the + /// default) to use the constraint from the parent instead. + double? get minHeight => _minHeight; + double? _minHeight; + set minHeight(double? value) { + if (_minHeight == value) { + return; + } + _minHeight = value; + markNeedsLayout(); + } + + /// The maximum height constraint to give the child. Set this to null (the + /// default) to use the constraint from the parent instead. + double? get maxHeight => _maxHeight; + double? _maxHeight; + set maxHeight(double? value) { + if (_maxHeight == value) { + return; + } + _maxHeight = value; + markNeedsLayout(); + } + + /// The way to size the render object. + /// + /// This only affects scenario when the child does not indeed overflow. + /// If set to [OverflowBoxFit.deferToChild], the render object will size + /// itself to match the size of its child within the constraints of its + /// parent, or as small as the parent allows if no child is set. + /// If set to [OverflowBoxFit.max] (the default), the + /// render object will size itself to be as large as the parent allows. + OverflowBoxFit get fit => _fit; + OverflowBoxFit _fit; + set fit(OverflowBoxFit value) { + if (_fit == value) { + return; + } + _fit = value; + markNeedsLayoutForSizedByParentChange(); + } + + BoxConstraints _getInnerConstraints(BoxConstraints constraints) { + return BoxConstraints( + minWidth: _minWidth ?? constraints.minWidth, + maxWidth: _maxWidth ?? constraints.maxWidth, + minHeight: _minHeight ?? constraints.minHeight, + maxHeight: _maxHeight ?? constraints.maxHeight, + ); + } + + @override + bool get sizedByParent { + switch (fit) { + case OverflowBoxFit.max: + return true; + case OverflowBoxFit.deferToChild: + // If deferToChild, the size will be as small as its child when non-overflowing, + // thus it cannot be sizedByParent. + return false; + } + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + switch (fit) { + case OverflowBoxFit.max: + return constraints.biggest; + case OverflowBoxFit.deferToChild: + return child?.getDryLayout(constraints) ?? constraints.smallest; + } + } + + @override + void performLayout() { + if (child != null) { + child!.layout(_getInnerConstraints(constraints), parentUsesSize: true); + switch (fit) { + case OverflowBoxFit.max: + assert(sizedByParent); + case OverflowBoxFit.deferToChild: + size = constraints.constrain(child!.size); + } + alignChild(); + } else { + switch (fit) { + case OverflowBoxFit.max: + assert(sizedByParent); + case OverflowBoxFit.deferToChild: + size = constraints.smallest; + } + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('minWidth', minWidth, ifNull: 'use parent minWidth constraint')); + properties.add(DoubleProperty('maxWidth', maxWidth, ifNull: 'use parent maxWidth constraint')); + properties.add(DoubleProperty('minHeight', minHeight, ifNull: 'use parent minHeight constraint')); + properties.add(DoubleProperty('maxHeight', maxHeight, ifNull: 'use parent maxHeight constraint')); + properties.add(EnumProperty<OverflowBoxFit>('fit', fit)); + } +} + +/// A [RenderBox] that applies an arbitrary transform to its constraints, +/// and sizes its child using the resulting [BoxConstraints], optionally +/// clipping, or treating the overflow as an error. +/// +/// This [RenderBox] sizes its child using a [BoxConstraints] created by +/// applying [constraintsTransform] to this [RenderBox]'s own [constraints]. +/// This box will then attempt to adopt the same size, within the limits of its +/// own constraints. If it ends up with a different size, it will align the +/// child based on [alignment]. If the box cannot expand enough to accommodate +/// the entire child, the child will be clipped if [clipBehavior] is not +/// [Clip.none]. +/// +/// In debug mode, if [clipBehavior] is [Clip.none] and the child overflows the +/// container, a warning will be printed on the console, and black and yellow +/// striped areas will appear where the overflow occurs. +/// +/// When [child] is null, this [RenderBox] takes the smallest possible size and +/// never overflows. +/// +/// This [RenderBox] can be used to ensure some of [child]'s natural dimensions +/// are honored, and get an early warning during development otherwise. For +/// instance, if [child] requires a minimum height to fully display its content, +/// [constraintsTransform] can be set to a function that removes the `maxHeight` +/// constraint from the incoming [BoxConstraints], so that if the parent +/// [RenderObject] fails to provide enough vertical space, a warning will be +/// displayed in debug mode, while still allowing [child] to grow vertically. +/// +/// See also: +/// +/// * [ConstraintsTransformBox], the widget that makes use of this +/// [RenderObject] and exposes the same functionality. +/// * [RenderConstrainedBox], which renders a box which imposes constraints +/// on its child. +/// * [RenderConstrainedOverflowBox], which renders a box that imposes different +/// constraints on its child than it gets from its parent, possibly allowing +/// the child to overflow the parent. +/// * [RenderConstraintsTransformBox] for a render object that applies an +/// arbitrary transform to its constraints before sizing its child using +/// the new constraints, treating any overflow as error. +class RenderConstraintsTransformBox extends RenderAligningShiftedBox with DebugOverflowIndicatorMixin { + /// Creates a [RenderBox] that sizes itself to the child and modifies the + /// [constraints] before passing it down to that child. + RenderConstraintsTransformBox({ + required super.alignment, + required super.textDirection, + required BoxConstraintsTransform constraintsTransform, + super.child, + Clip clipBehavior = Clip.none, + }) : _constraintsTransform = constraintsTransform, + _clipBehavior = clipBehavior; + + /// {@macro flutter.widgets.constraintsTransform} + BoxConstraintsTransform get constraintsTransform => _constraintsTransform; + BoxConstraintsTransform _constraintsTransform; + set constraintsTransform(BoxConstraintsTransform value) { + if (_constraintsTransform == value) { + return; + } + _constraintsTransform = value; + // The RenderObject only needs layout if the new transform maps the current + // `constraints` to a different value, or the render object has never been + // laid out before. + final bool needsLayout = _childConstraints == null + || _childConstraints != value(constraints); + if (needsLayout) { + markNeedsLayout(); + } + } + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// {@macro flutter.widgets.ConstraintsTransformBox.clipBehavior} + /// + /// Defaults to [Clip.none]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + @override + double computeMinIntrinsicHeight(double width) { + return super.computeMinIntrinsicHeight( + constraintsTransform(BoxConstraints(maxWidth: width)).maxWidth, + ); + } + + @override + double computeMaxIntrinsicHeight(double width) { + return super.computeMaxIntrinsicHeight( + constraintsTransform(BoxConstraints(maxWidth: width)).maxWidth, + ); + } + + @override + double computeMinIntrinsicWidth(double height) { + return super.computeMinIntrinsicWidth( + constraintsTransform(BoxConstraints(maxHeight: height)).maxHeight, + ); + } + + @override + double computeMaxIntrinsicWidth(double height) { + return super.computeMaxIntrinsicWidth( + constraintsTransform(BoxConstraints(maxHeight: height)).maxHeight, + ); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + final Size? childSize = child?.getDryLayout(constraintsTransform(constraints)); + return childSize == null ? constraints.smallest : constraints.constrain(childSize); + } + + Rect _overflowContainerRect = Rect.zero; + Rect _overflowChildRect = Rect.zero; + bool _isOverflowing = false; + + BoxConstraints? _childConstraints; + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + final RenderBox? child = this.child; + if (child != null) { + final BoxConstraints childConstraints = constraintsTransform(constraints); + assert(childConstraints.isNormalized, '$childConstraints is not normalized'); + _childConstraints = childConstraints; + child.layout(childConstraints, parentUsesSize: true); + size = constraints.constrain(child.size); + alignChild(); + final BoxParentData childParentData = child.parentData! as BoxParentData; + _overflowContainerRect = Offset.zero & size; + _overflowChildRect = childParentData.offset & child.size; + } else { + size = constraints.smallest; + _overflowContainerRect = Rect.zero; + _overflowChildRect = Rect.zero; + } + _isOverflowing = RelativeRect.fromRect(_overflowContainerRect, _overflowChildRect).hasInsets; + } + + @override + void paint(PaintingContext context, Offset offset) { + // There's no point in drawing the child if we're empty, or there is no + // child. + if (child == null || size.isEmpty) { + return; + } + + if (!_isOverflowing) { + super.paint(context, offset); + return; + } + + // We have overflow and the clipBehavior isn't none. Clip it. + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + super.paint, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + + // Display the overflow indicator if clipBehavior is Clip.none. + assert(() { + switch (clipBehavior) { + case Clip.none: + paintOverflowIndicator(context, offset, _overflowContainerRect, _overflowChildRect); + case Clip.hardEdge: + case Clip.antiAlias: + case Clip.antiAliasWithSaveLayer: + break; + } + return true; + }()); + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void dispose() { + _clipRectLayer.layer = null; + super.dispose(); + } + + @override + Rect? describeApproximatePaintClip(RenderObject child) { + switch (clipBehavior) { + case Clip.none: + return null; + case Clip.hardEdge: + case Clip.antiAlias: + case Clip.antiAliasWithSaveLayer: + return _isOverflowing ? Offset.zero & size : null; + } + } + + @override + String toStringShort() { + String header = super.toStringShort(); + if (!kReleaseMode) { + if (_isOverflowing) { + header += ' OVERFLOWING'; + } + } + return header; + } +} + +/// A render object that is a specific size but passes its original constraints +/// through to its child, which it allows to overflow. +/// +/// If the child's resulting size differs from this render object's size, then +/// the child is aligned according to the [alignment] property. +/// +/// See also: +/// +/// * [RenderConstraintsTransformBox] for a render object that applies an +/// arbitrary transform to its constraints before sizing its child using +/// the new constraints, treating any overflow as error. +/// * [RenderConstrainedOverflowBox] for a render object that imposes +/// different constraints on its child than it gets from its parent, +/// possibly allowing the child to overflow the parent. +class RenderSizedOverflowBox extends RenderAligningShiftedBox { + /// Creates a render box of a given size that lets its child overflow. + /// + /// The [textDirection] argument must not be null if the [alignment] is + /// direction-sensitive. + RenderSizedOverflowBox({ + super.child, + required Size requestedSize, + super.alignment, + super.textDirection, + }) : _requestedSize = requestedSize; + + /// The size this render box should attempt to be. + Size get requestedSize => _requestedSize; + Size _requestedSize; + set requestedSize(Size value) { + if (_requestedSize == value) { + return; + } + _requestedSize = value; + markNeedsLayout(); + } + + @override + double computeMinIntrinsicWidth(double height) { + return _requestedSize.width; + } + + @override + double computeMaxIntrinsicWidth(double height) { + return _requestedSize.width; + } + + @override + double computeMinIntrinsicHeight(double width) { + return _requestedSize.height; + } + + @override + double computeMaxIntrinsicHeight(double width) { + return _requestedSize.height; + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + if (child != null) { + return child!.getDistanceToActualBaseline(baseline); + } + return super.computeDistanceToActualBaseline(baseline); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return constraints.constrain(_requestedSize); + } + + @override + void performLayout() { + size = constraints.constrain(_requestedSize); + if (child != null) { + child!.layout(constraints, parentUsesSize: true); + alignChild(); + } + } +} + +/// Sizes its child to a fraction of the total available space. +/// +/// For both its width and height, this render object imposes a tight +/// constraint on its child that is a multiple (typically less than 1.0) of the +/// maximum constraint it received from its parent on that axis. If the factor +/// for a given axis is null, then the constraints from the parent are just +/// passed through instead. +/// +/// It then tries to size itself to the size of its child. Where this is not +/// possible (e.g. if the constraints from the parent are themselves tight), the +/// child is aligned according to [alignment]. +class RenderFractionallySizedOverflowBox extends RenderAligningShiftedBox { + /// Creates a render box that sizes its child to a fraction of the total available space. + /// + /// If non-null, the [widthFactor] and [heightFactor] arguments must be + /// non-negative. + /// + /// The [textDirection] must be non-null if the [alignment] is + /// direction-sensitive. + RenderFractionallySizedOverflowBox({ + super.child, + double? widthFactor, + double? heightFactor, + super.alignment, + super.textDirection, + }) : _widthFactor = widthFactor, + _heightFactor = heightFactor { + assert(_widthFactor == null || _widthFactor! >= 0.0); + assert(_heightFactor == null || _heightFactor! >= 0.0); + } + + /// If non-null, the factor of the incoming width to use. + /// + /// If non-null, the child is given a tight width constraint that is the max + /// incoming width constraint multiplied by this factor. If null, the child is + /// given the incoming width constraints. + double? get widthFactor => _widthFactor; + double? _widthFactor; + set widthFactor(double? value) { + assert(value == null || value >= 0.0); + if (_widthFactor == value) { + return; + } + _widthFactor = value; + markNeedsLayout(); + } + + /// If non-null, the factor of the incoming height to use. + /// + /// If non-null, the child is given a tight height constraint that is the max + /// incoming width constraint multiplied by this factor. If null, the child is + /// given the incoming width constraints. + double? get heightFactor => _heightFactor; + double? _heightFactor; + set heightFactor(double? value) { + assert(value == null || value >= 0.0); + if (_heightFactor == value) { + return; + } + _heightFactor = value; + markNeedsLayout(); + } + + BoxConstraints _getInnerConstraints(BoxConstraints constraints) { + double minWidth = constraints.minWidth; + double maxWidth = constraints.maxWidth; + if (_widthFactor != null) { + final double width = maxWidth * _widthFactor!; + minWidth = width; + maxWidth = width; + } + double minHeight = constraints.minHeight; + double maxHeight = constraints.maxHeight; + if (_heightFactor != null) { + final double height = maxHeight * _heightFactor!; + minHeight = height; + maxHeight = height; + } + return BoxConstraints( + minWidth: minWidth, + maxWidth: maxWidth, + minHeight: minHeight, + maxHeight: maxHeight, + ); + } + + @override + double computeMinIntrinsicWidth(double height) { + final double result; + if (child == null) { + result = super.computeMinIntrinsicWidth(height); + } else { // the following line relies on double.infinity absorption + result = child!.getMinIntrinsicWidth(height * (_heightFactor ?? 1.0)); + } + assert(result.isFinite); + return result / (_widthFactor ?? 1.0); + } + + @override + double computeMaxIntrinsicWidth(double height) { + final double result; + if (child == null) { + result = super.computeMaxIntrinsicWidth(height); + } else { // the following line relies on double.infinity absorption + result = child!.getMaxIntrinsicWidth(height * (_heightFactor ?? 1.0)); + } + assert(result.isFinite); + return result / (_widthFactor ?? 1.0); + } + + @override + double computeMinIntrinsicHeight(double width) { + final double result; + if (child == null) { + result = super.computeMinIntrinsicHeight(width); + } else { // the following line relies on double.infinity absorption + result = child!.getMinIntrinsicHeight(width * (_widthFactor ?? 1.0)); + } + assert(result.isFinite); + return result / (_heightFactor ?? 1.0); + } + + @override + double computeMaxIntrinsicHeight(double width) { + final double result; + if (child == null) { + result = super.computeMaxIntrinsicHeight(width); + } else { // the following line relies on double.infinity absorption + result = child!.getMaxIntrinsicHeight(width * (_widthFactor ?? 1.0)); + } + assert(result.isFinite); + return result / (_heightFactor ?? 1.0); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (child != null) { + final Size childSize = child!.getDryLayout(_getInnerConstraints(constraints)); + return constraints.constrain(childSize); + } + return constraints.constrain(_getInnerConstraints(constraints).constrain(Size.zero)); + } + + @override + void performLayout() { + if (child != null) { + child!.layout(_getInnerConstraints(constraints), parentUsesSize: true); + size = constraints.constrain(child!.size); + alignChild(); + } else { + size = constraints.constrain(_getInnerConstraints(constraints).constrain(Size.zero)); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('widthFactor', _widthFactor, ifNull: 'pass-through')); + properties.add(DoubleProperty('heightFactor', _heightFactor, ifNull: 'pass-through')); + } +} + +/// A delegate for computing the layout of a render object with a single child. +/// +/// Used by [CustomSingleChildLayout] (in the widgets library) and +/// [RenderCustomSingleChildLayoutBox] (in the rendering library). +/// +/// When asked to layout, [CustomSingleChildLayout] first calls [getSize] with +/// its incoming constraints to determine its size. It then calls +/// [getConstraintsForChild] to determine the constraints to apply to the child. +/// After the child completes its layout, [RenderCustomSingleChildLayoutBox] +/// calls [getPositionForChild] to determine the child's position. +/// +/// The [shouldRelayout] method is called when a new instance of the class +/// is provided, to check if the new instance actually represents different +/// information. +/// +/// The most efficient way to trigger a relayout is to supply a `relayout` +/// argument to the constructor of the [SingleChildLayoutDelegate]. The custom +/// layout will listen to this value and relayout whenever the Listenable +/// notifies its listeners, such as when an [Animation] ticks. This allows +/// the custom layout to avoid the build phase of the pipeline. +/// +/// See also: +/// +/// * [CustomSingleChildLayout], the widget that uses this delegate. +/// * [RenderCustomSingleChildLayoutBox], render object that uses this +/// delegate. +abstract class SingleChildLayoutDelegate { + /// Creates a layout delegate. + /// + /// The layout will update whenever [relayout] notifies its listeners. + const SingleChildLayoutDelegate({ Listenable? relayout }) : _relayout = relayout; + + final Listenable? _relayout; + + /// The size of this object given the incoming constraints. + /// + /// Defaults to the biggest size that satisfies the given constraints. + Size getSize(BoxConstraints constraints) => constraints.biggest; + + /// The constraints for the child given the incoming constraints. + /// + /// During layout, the child is given the layout constraints returned by this + /// function. The child is required to pick a size for itself that satisfies + /// these constraints. + /// + /// Defaults to the given constraints. + BoxConstraints getConstraintsForChild(BoxConstraints constraints) => constraints; + + /// The position where the child should be placed. + /// + /// The `size` argument is the size of the parent, which might be different + /// from the value returned by [getSize] if that size doesn't satisfy the + /// constraints passed to [getSize]. The `childSize` argument is the size of + /// the child, which will satisfy the constraints returned by + /// [getConstraintsForChild]. + /// + /// Defaults to positioning the child in the upper left corner of the parent. + Offset getPositionForChild(Size size, Size childSize) => Offset.zero; + + /// Called whenever a new instance of the custom layout delegate class is + /// provided to the [RenderCustomSingleChildLayoutBox] object, or any time + /// that a new [CustomSingleChildLayout] object is created with a new instance + /// of the custom layout delegate class (which amounts to the same thing, + /// because the latter is implemented in terms of the former). + /// + /// If the new instance represents different information than the old + /// instance, then the method should return true, otherwise it should return + /// false. + /// + /// If the method returns false, then the [getSize], + /// [getConstraintsForChild], and [getPositionForChild] calls might be + /// optimized away. + /// + /// It's possible that the layout methods will get called even if + /// [shouldRelayout] returns false (e.g. if an ancestor changed its layout). + /// It's also possible that the layout method will get called + /// without [shouldRelayout] being called at all (e.g. if the parent changes + /// size). + bool shouldRelayout(covariant SingleChildLayoutDelegate oldDelegate); +} + +/// Defers the layout of its single child to a delegate. +/// +/// The delegate can determine the layout constraints for the child and can +/// decide where to position the child. The delegate can also determine the size +/// of the parent, but the size of the parent cannot depend on the size of the +/// child. +class RenderCustomSingleChildLayoutBox extends RenderShiftedBox { + /// Creates a render box that defers its layout to a delegate. + /// + /// The [delegate] argument must not be null. + RenderCustomSingleChildLayoutBox({ + RenderBox? child, + required SingleChildLayoutDelegate delegate, + }) : _delegate = delegate, + super(child); + + /// A delegate that controls this object's layout. + SingleChildLayoutDelegate get delegate => _delegate; + SingleChildLayoutDelegate _delegate; + set delegate(SingleChildLayoutDelegate newDelegate) { + if (_delegate == newDelegate) { + return; + } + final SingleChildLayoutDelegate oldDelegate = _delegate; + if (newDelegate.runtimeType != oldDelegate.runtimeType || newDelegate.shouldRelayout(oldDelegate)) { + markNeedsLayout(); + } + _delegate = newDelegate; + if (attached) { + oldDelegate._relayout?.removeListener(markNeedsLayout); + newDelegate._relayout?.addListener(markNeedsLayout); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _delegate._relayout?.addListener(markNeedsLayout); + } + + @override + void detach() { + _delegate._relayout?.removeListener(markNeedsLayout); + super.detach(); + } + + Size _getSize(BoxConstraints constraints) { + return constraints.constrain(_delegate.getSize(constraints)); + } + + // TODO(ianh): It's a bit dubious to be using the getSize function from the delegate to + // figure out the intrinsic dimensions. We really should either not support intrinsics, + // or we should expose intrinsic delegate callbacks and throw if they're not implemented. + + @override + double computeMinIntrinsicWidth(double height) { + final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width; + if (width.isFinite) { + return width; + } + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width; + if (width.isFinite) { + return width; + } + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height; + if (height.isFinite) { + return height; + } + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height; + if (height.isFinite) { + return height; + } + return 0.0; + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return _getSize(constraints); + } + + @override + void performLayout() { + size = _getSize(constraints); + if (child != null) { + final BoxConstraints childConstraints = delegate.getConstraintsForChild(constraints); + assert(childConstraints.debugAssertIsValid(isAppliedConstraint: true)); + child!.layout(childConstraints, parentUsesSize: !childConstraints.isTight); + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = delegate.getPositionForChild(size, childConstraints.isTight ? childConstraints.smallest : child!.size); + } + } +} + +/// Shifts the child down such that the child's baseline (or the +/// bottom of the child, if the child has no baseline) is [baseline] +/// logical pixels below the top of this box, then sizes this box to +/// contain the child. +/// +/// If [baseline] is less than the distance from the top of the child +/// to the baseline of the child, then the child will overflow the top +/// of the box. This is typically not desirable, in particular, that +/// part of the child will not be found when doing hit tests, so the +/// user cannot interact with that part of the child. +/// +/// This box will be sized so that its bottom is coincident with the +/// bottom of the child. This means if this box shifts the child down, +/// there will be space between the top of this box and the top of the +/// child, but there is never space between the bottom of the child +/// and the bottom of the box. +class RenderBaseline extends RenderShiftedBox { + /// Creates a [RenderBaseline] object. + RenderBaseline({ + RenderBox? child, + required double baseline, + required TextBaseline baselineType, + }) : _baseline = baseline, + _baselineType = baselineType, + super(child); + + /// The number of logical pixels from the top of this box at which to position + /// the child's baseline. + double get baseline => _baseline; + double _baseline; + set baseline(double value) { + if (_baseline == value) { + return; + } + _baseline = value; + markNeedsLayout(); + } + + /// The type of baseline to use for positioning the child. + TextBaseline get baselineType => _baselineType; + TextBaseline _baselineType; + set baselineType(TextBaseline value) { + if (_baselineType == value) { + return; + } + _baselineType = value; + markNeedsLayout(); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (child != null) { + assert(debugCannotComputeDryLayout( + reason: 'Baseline metrics are only available after a full layout.', + )); + return Size.zero; + } + return constraints.smallest; + } + + @override + void performLayout() { + if (child != null) { + final BoxConstraints constraints = this.constraints; + child!.layout(constraints.loosen(), parentUsesSize: true); + final double childBaseline = child!.getDistanceToBaseline(baselineType)!; + final double actualBaseline = baseline; + final double top = actualBaseline - childBaseline; + final BoxParentData childParentData = child!.parentData! as BoxParentData; + childParentData.offset = Offset(0.0, top); + final Size childSize = child!.size; + size = constraints.constrain(Size(childSize.width, top + childSize.height)); + } else { + size = constraints.smallest; + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('baseline', baseline)); + properties.add(EnumProperty<TextBaseline>('baselineType', baselineType)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver.dart new file mode 100644 index 0000000000000000000000000000000000000000..8c197447ed21e0dfab072b4cd25017f47270f3bf --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver.dart @@ -0,0 +1,1944 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; + +import 'box.dart'; +import 'debug.dart'; +import 'object.dart'; +import 'viewport.dart'; +import 'viewport_offset.dart'; + +// CORE TYPES FOR SLIVERS +// The RenderSliver base class and its helper types. + +/// Called to get the item extent by the index of item. +/// +/// Used by [ListView.itemExtentBuilder] and [SliverVariedExtentList.itemExtentBuilder]. +typedef ItemExtentBuilder = double Function(int index, SliverLayoutDimensions dimensions); + +/// Relates the dimensions of the [RenderSliver] during layout. +/// +/// Used by [ListView.itemExtentBuilder] and [SliverVariedExtentList.itemExtentBuilder]. +@immutable +class SliverLayoutDimensions { + /// Constructs a [SliverLayoutDimensions] with the specified parameters. + const SliverLayoutDimensions({ + required this.scrollOffset, + required this.precedingScrollExtent, + required this.viewportMainAxisExtent, + required this.crossAxisExtent + }); + + /// {@macro flutter.rendering.SliverConstraints.scrollOffset} + final double scrollOffset; + + /// {@macro flutter.rendering.SliverConstraints.precedingScrollExtent} + final double precedingScrollExtent; + + /// The number of pixels the viewport can display in the main axis. + /// + /// For a vertical list, this is the height of the viewport. + final double viewportMainAxisExtent; + + /// The number of pixels in the cross-axis. + /// + /// For a vertical list, this is the width of the sliver. + final double crossAxisExtent; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other is! SliverLayoutDimensions) { + return false; + } + return other.scrollOffset == scrollOffset && + other.precedingScrollExtent == precedingScrollExtent && + other.viewportMainAxisExtent == viewportMainAxisExtent && + other.crossAxisExtent == crossAxisExtent; + } + + @override + String toString() { + return 'scrollOffset: $scrollOffset' + ' precedingScrollExtent: $precedingScrollExtent' + ' viewportMainAxisExtent: $viewportMainAxisExtent' + ' crossAxisExtent: $crossAxisExtent'; + } + + @override + int get hashCode => Object.hash( + scrollOffset, + precedingScrollExtent, + viewportMainAxisExtent, + viewportMainAxisExtent + ); +} + +/// The direction in which a sliver's contents are ordered, relative to the +/// scroll offset axis. +/// +/// For example, a vertical alphabetical list that is going [AxisDirection.down] +/// with a [GrowthDirection.forward] would have the A at the top and the Z at +/// the bottom, with the A adjacent to the origin, as would such a list going +/// [AxisDirection.up] with a [GrowthDirection.reverse]. On the other hand, a +/// vertical alphabetical list that is going [AxisDirection.down] with a +/// [GrowthDirection.reverse] would have the Z at the top (at scroll offset +/// zero) and the A below it. +/// +/// {@template flutter.rendering.GrowthDirection.sample} +/// Most scroll views by default are ordered [GrowthDirection.forward]. +/// Changing the default values of [ScrollView.anchor], +/// [ScrollView.center], or both, can configure a scroll view for +/// [GrowthDirection.reverse]. +/// +/// {@tool dartpad} +/// This sample shows a [CustomScrollView], with [Radio] buttons in the +/// [AppBar.bottom] that change the [AxisDirection] to illustrate different +/// configurations. The [CustomScrollView.anchor] and [CustomScrollView.center] +/// properties are also set to have the 0 scroll offset positioned in the middle +/// of the viewport, with [GrowthDirection.forward] and [GrowthDirection.reverse] +/// illustrated on either side. The sliver that shares the +/// [CustomScrollView.center] key is positioned at the [CustomScrollView.anchor]. +/// +/// ** See code in examples/api/lib/rendering/growth_direction/growth_direction.0.dart ** +/// {@end-tool} +/// {@endtemplate} +/// +/// See also: +/// +/// * [applyGrowthDirectionToAxisDirection], which returns the direction in +/// which the scroll offset increases. +enum GrowthDirection { + /// This sliver's contents are ordered in the same direction as the + /// [AxisDirection]. For example, a vertical alphabetical list that is going + /// [AxisDirection.down] with a [GrowthDirection.forward] would have the A at + /// the top and the Z at the bottom, with the A adjacent to the origin. + /// + /// See also: + /// + /// * [applyGrowthDirectionToAxisDirection], which returns the direction in + /// which the scroll offset increases. + forward, + + /// This sliver's contents are ordered in the opposite direction of the + /// [AxisDirection]. + /// + /// See also: + /// + /// * [applyGrowthDirectionToAxisDirection], which returns the direction in + /// which the scroll offset increases. + reverse, +} + +/// Flips the [AxisDirection] if the [GrowthDirection] is [GrowthDirection.reverse]. +/// +/// Specifically, returns `axisDirection` if `growthDirection` is +/// [GrowthDirection.forward], otherwise returns [flipAxisDirection] applied to +/// `axisDirection`. +/// +/// This function is useful in [RenderSliver] subclasses that are given both an +/// [AxisDirection] and a [GrowthDirection] and wish to compute the +/// [AxisDirection] in which growth will occur. +AxisDirection applyGrowthDirectionToAxisDirection(AxisDirection axisDirection, GrowthDirection growthDirection) { + switch (growthDirection) { + case GrowthDirection.forward: + return axisDirection; + case GrowthDirection.reverse: + return flipAxisDirection(axisDirection); + } +} + +/// Flips the [ScrollDirection] if the [GrowthDirection] is +/// [GrowthDirection.reverse]. +/// +/// Specifically, returns `scrollDirection` if `scrollDirection` is +/// [GrowthDirection.forward], otherwise returns [flipScrollDirection] applied +/// to `scrollDirection`. +/// +/// This function is useful in [RenderSliver] subclasses that are given both an +/// [ScrollDirection] and a [GrowthDirection] and wish to compute the +/// [ScrollDirection] in which growth will occur. +ScrollDirection applyGrowthDirectionToScrollDirection(ScrollDirection scrollDirection, GrowthDirection growthDirection) { + switch (growthDirection) { + case GrowthDirection.forward: + return scrollDirection; + case GrowthDirection.reverse: + return flipScrollDirection(scrollDirection); + } +} + +/// Immutable layout constraints for [RenderSliver] layout. +/// +/// The [SliverConstraints] describe the current scroll state of the viewport +/// from the point of view of the sliver receiving the constraints. For example, +/// a [scrollOffset] of zero means that the leading edge of the sliver is +/// visible in the viewport, not that the viewport itself has a zero scroll +/// offset. +class SliverConstraints extends Constraints { + /// Creates sliver constraints with the given information. + const SliverConstraints({ + required this.axisDirection, + required this.growthDirection, + required this.userScrollDirection, + required this.scrollOffset, + required this.precedingScrollExtent, + required this.overlap, + required this.remainingPaintExtent, + required this.crossAxisExtent, + required this.crossAxisDirection, + required this.viewportMainAxisExtent, + required this.remainingCacheExtent, + required this.cacheOrigin, + }); + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + SliverConstraints copyWith({ + AxisDirection? axisDirection, + GrowthDirection? growthDirection, + ScrollDirection? userScrollDirection, + double? scrollOffset, + double? precedingScrollExtent, + double? overlap, + double? remainingPaintExtent, + double? crossAxisExtent, + AxisDirection? crossAxisDirection, + double? viewportMainAxisExtent, + double? remainingCacheExtent, + double? cacheOrigin, + }) { + return SliverConstraints( + axisDirection: axisDirection ?? this.axisDirection, + growthDirection: growthDirection ?? this.growthDirection, + userScrollDirection: userScrollDirection ?? this.userScrollDirection, + scrollOffset: scrollOffset ?? this.scrollOffset, + precedingScrollExtent: precedingScrollExtent ?? this.precedingScrollExtent, + overlap: overlap ?? this.overlap, + remainingPaintExtent: remainingPaintExtent ?? this.remainingPaintExtent, + crossAxisExtent: crossAxisExtent ?? this.crossAxisExtent, + crossAxisDirection: crossAxisDirection ?? this.crossAxisDirection, + viewportMainAxisExtent: viewportMainAxisExtent ?? this.viewportMainAxisExtent, + remainingCacheExtent: remainingCacheExtent ?? this.remainingCacheExtent, + cacheOrigin: cacheOrigin ?? this.cacheOrigin, + ); + } + + /// The direction in which the [scrollOffset] and [remainingPaintExtent] + /// increase. + /// + /// {@tool dartpad} + /// This sample shows a [CustomScrollView], with [Radio] buttons in the + /// [AppBar.bottom] that change the [AxisDirection] to illustrate different + /// configurations. + /// + /// ** See code in examples/api/lib/painting/axis_direction/axis_direction.0.dart ** + /// {@end-tool} + final AxisDirection axisDirection; + + /// The direction in which the contents of slivers are ordered, relative to + /// the [axisDirection]. + /// + /// For example, if the [axisDirection] is [AxisDirection.up], and the + /// [growthDirection] is [GrowthDirection.forward], then an alphabetical list + /// will have A at the bottom, then B, then C, and so forth, with Z at the + /// top, with the bottom of the A at scroll offset zero, and the top of the Z + /// at the highest scroll offset. + /// + /// If a viewport has an overall [AxisDirection] of [AxisDirection.down], then + /// slivers above the absolute zero offset will have an axis of + /// [AxisDirection.up] and a growth direction of [GrowthDirection.reverse], + /// while slivers below the absolute zero offset will have the same axis + /// direction as the viewport and a growth direction of + /// [GrowthDirection.forward]. (The slivers with a reverse growth direction + /// still see only positive scroll offsets; the scroll offsets are reversed as + /// well, with zero at the absolute zero point, and positive numbers going + /// away from there.) + /// + /// Normally, the absolute zero offset is determined by the viewport's + /// [RenderViewport.center] and [RenderViewport.anchor] properties. + /// + /// {@macro flutter.rendering.GrowthDirection.sample} + final GrowthDirection growthDirection; + + /// The direction in which the user is attempting to scroll, relative to the + /// [axisDirection] and [growthDirection]. + /// + /// For example, if [growthDirection] is [GrowthDirection.forward] and + /// [axisDirection] is [AxisDirection.down], then a + /// [ScrollDirection.reverse] means that the user is scrolling down, in the + /// positive [scrollOffset] direction. + /// + /// If the _user_ is not scrolling, this will return [ScrollDirection.idle] + /// even if there is (for example) a [ScrollActivity] currently animating the + /// position. + /// + /// This is used by some slivers to determine how to react to a change in + /// scroll offset. For example, [RenderSliverFloatingPersistentHeader] will + /// only expand a floating app bar when the [userScrollDirection] is in the + /// positive scroll offset direction. + /// + /// {@macro flutter.rendering.ScrollDirection.sample} + final ScrollDirection userScrollDirection; + + /// {@template flutter.rendering.SliverConstraints.scrollOffset} + /// The scroll offset, in this sliver's coordinate system, that corresponds to + /// the earliest visible part of this sliver in the [AxisDirection] if + /// [SliverConstraints.growthDirection] is [GrowthDirection.forward] or in the opposite + /// [AxisDirection] direction if [SliverConstraints.growthDirection] is [GrowthDirection.reverse]. + /// + /// For example, if [AxisDirection] is [AxisDirection.down] and [SliverConstraints.growthDirection] + /// is [GrowthDirection.forward], then scroll offset is the amount the top of + /// the sliver has been scrolled past the top of the viewport. + /// + /// This value is typically used to compute whether this sliver should still + /// protrude into the viewport via [SliverGeometry.paintExtent] and + /// [SliverGeometry.layoutExtent] considering how far the beginning of the + /// sliver is above the beginning of the viewport. + /// + /// For slivers whose top is not past the top of the viewport, the + /// [scrollOffset] is `0` when [AxisDirection] is [AxisDirection.down] and + /// [SliverConstraints.growthDirection] is [GrowthDirection.forward]. The set of slivers with + /// [scrollOffset] `0` includes all the slivers that are below the bottom of the + /// viewport. + /// + /// [SliverConstraints.remainingPaintExtent] is typically used to accomplish + /// the same goal of computing whether scrolled out slivers should still + /// partially 'protrude in' from the bottom of the viewport. + /// + /// Whether this corresponds to the beginning or the end of the sliver's + /// contents depends on the [SliverConstraints.growthDirection]. + /// {@endtemplate} + final double scrollOffset; + + /// {@template flutter.rendering.SliverConstraints.precedingScrollExtent} + /// The scroll distance that has been consumed by all [RenderSliver]s that + /// came before this [RenderSliver]. + /// + /// # Edge Cases + /// + /// [RenderSliver]s often lazily create their internal content as layout + /// occurs, e.g., [SliverList]. In this case, when [RenderSliver]s exceed the + /// viewport, their children are built lazily, and the [RenderSliver] does not + /// have enough information to estimate its total extent, + /// [precedingScrollExtent] will be [double.infinity] for all [RenderSliver]s + /// that appear after the lazily constructed child. This is because a total + /// [SliverGeometry.scrollExtent] cannot be calculated unless all inner + /// children have been created and sized, or the number of children and + /// estimated extents are provided. The infinite [SliverGeometry.scrollExtent] + /// will become finite as soon as enough information is available to estimate + /// the overall extent of all children within the given [RenderSliver]. + /// + /// [RenderSliver]s may legitimately be infinite, meaning that they can scroll + /// content forever without reaching the end. For any [RenderSliver]s that + /// appear after the infinite [RenderSliver], the [precedingScrollExtent] will + /// be [double.infinity]. + /// {@endtemplate} + final double precedingScrollExtent; + + /// The number of pixels from where the pixels corresponding to the + /// [scrollOffset] will be painted up to the first pixel that has not yet been + /// painted on by an earlier sliver, in the [axisDirection]. + /// + /// For example, if the previous sliver had a [SliverGeometry.paintExtent] of + /// 100.0 pixels but a [SliverGeometry.layoutExtent] of only 50.0 pixels, + /// then the [overlap] of this sliver will be 50.0. + /// + /// This is typically ignored unless the sliver is itself going to be pinned + /// or floating and wants to avoid doing so under the previous sliver. + final double overlap; + + /// The number of pixels of content that the sliver should consider providing. + /// (Providing more pixels than this is inefficient.) + /// + /// The actual number of pixels provided should be specified in the + /// [RenderSliver.geometry] as [SliverGeometry.paintExtent]. + /// + /// This value may be infinite, for example if the viewport is an + /// unconstrained [RenderShrinkWrappingViewport]. + /// + /// This value may be 0.0, for example if the sliver is scrolled off the + /// bottom of a downwards vertical viewport. + final double remainingPaintExtent; + + /// The number of pixels in the cross-axis. + /// + /// For a vertical list, this is the width of the sliver. + final double crossAxisExtent; + + /// The direction in which children should be placed in the cross axis. + /// + /// Typically used in vertical lists to describe whether the ambient + /// [TextDirection] is [TextDirection.rtl] or [TextDirection.ltr]. + final AxisDirection crossAxisDirection; + + /// The number of pixels the viewport can display in the main axis. + /// + /// For a vertical list, this is the height of the viewport. + final double viewportMainAxisExtent; + + /// Where the cache area starts relative to the [scrollOffset]. + /// + /// Slivers that fall into the cache area located before the leading edge and + /// after the trailing edge of the viewport should still render content + /// because they are about to become visible when the user scrolls. + /// + /// The [cacheOrigin] describes where the [remainingCacheExtent] starts relative + /// to the [scrollOffset]. A cache origin of 0 means that the sliver does not + /// have to provide any content before the current [scrollOffset]. A + /// [cacheOrigin] of -250.0 means that even though the first visible part of + /// the sliver will be at the provided [scrollOffset], the sliver should + /// render content starting 250.0 before the [scrollOffset] to fill the + /// cache area of the viewport. + /// + /// The [cacheOrigin] is always negative or zero and will never exceed + /// -[scrollOffset]. In other words, a sliver is never asked to provide + /// content before its zero [scrollOffset]. + /// + /// See also: + /// + /// * [RenderViewport.cacheExtent] for a description of a viewport's cache area. + final double cacheOrigin; + + + /// Describes how much content the sliver should provide starting from the + /// [cacheOrigin]. + /// + /// Not all content in the [remainingCacheExtent] will be visible as some + /// of it might fall into the cache area of the viewport. + /// + /// Each sliver should start laying out content at the [cacheOrigin] and + /// try to provide as much content as the [remainingCacheExtent] allows. + /// + /// The [remainingCacheExtent] is always larger or equal to the + /// [remainingPaintExtent]. Content, that falls in the [remainingCacheExtent], + /// but is outside of the [remainingPaintExtent] is currently not visible + /// in the viewport. + /// + /// See also: + /// + /// * [RenderViewport.cacheExtent] for a description of a viewport's cache area. + final double remainingCacheExtent; + + /// The axis along which the [scrollOffset] and [remainingPaintExtent] are measured. + Axis get axis => axisDirectionToAxis(axisDirection); + + /// Return what the [growthDirection] would be if the [axisDirection] was + /// either [AxisDirection.down] or [AxisDirection.right]. + /// + /// This is the same as [growthDirection] unless the [axisDirection] is either + /// [AxisDirection.up] or [AxisDirection.left], in which case it is the + /// opposite growth direction. + /// + /// This can be useful in combination with [axis] to view the [axisDirection] + /// and [growthDirection] in different terms. + GrowthDirection get normalizedGrowthDirection { + switch (axisDirection) { + case AxisDirection.down: + case AxisDirection.right: + return growthDirection; + case AxisDirection.up: + case AxisDirection.left: + switch (growthDirection) { + case GrowthDirection.forward: + return GrowthDirection.reverse; + case GrowthDirection.reverse: + return GrowthDirection.forward; + } + } + } + + @override + bool get isTight => false; + + @override + bool get isNormalized { + return scrollOffset >= 0.0 + && crossAxisExtent >= 0.0 + && axisDirectionToAxis(axisDirection) != axisDirectionToAxis(crossAxisDirection) + && viewportMainAxisExtent >= 0.0 + && remainingPaintExtent >= 0.0; + } + + /// Returns [BoxConstraints] that reflects the sliver constraints. + /// + /// The `minExtent` and `maxExtent` are used as the constraints in the main + /// axis. If non-null, the given `crossAxisExtent` is used as a tight + /// constraint in the cross axis. Otherwise, the [crossAxisExtent] from this + /// object is used as a constraint in the cross axis. + /// + /// Useful for slivers that have [RenderBox] children. + BoxConstraints asBoxConstraints({ + double minExtent = 0.0, + double maxExtent = double.infinity, + double? crossAxisExtent, + }) { + crossAxisExtent ??= this.crossAxisExtent; + switch (axis) { + case Axis.horizontal: + return BoxConstraints( + minHeight: crossAxisExtent, + maxHeight: crossAxisExtent, + minWidth: minExtent, + maxWidth: maxExtent, + ); + case Axis.vertical: + return BoxConstraints( + minWidth: crossAxisExtent, + maxWidth: crossAxisExtent, + minHeight: minExtent, + maxHeight: maxExtent, + ); + } + } + + @override + bool debugAssertIsValid({ + bool isAppliedConstraint = false, + InformationCollector? informationCollector, + }) { + assert(() { + bool hasErrors = false; + final StringBuffer errorMessage = StringBuffer('\n'); + void verify(bool check, String message) { + if (check) { + return; + } + hasErrors = true; + errorMessage.writeln(' $message'); + } + void verifyDouble(double property, String name, {bool mustBePositive = false, bool mustBeNegative = false}) { + if (property.isNaN) { + String additional = '.'; + if (mustBePositive) { + additional = ', expected greater than or equal to zero.'; + } else if (mustBeNegative) { + additional = ', expected less than or equal to zero.'; + } + verify(false, 'The "$name" is NaN$additional'); + } else if (mustBePositive) { + verify(property >= 0.0, 'The "$name" is negative.'); + } else if (mustBeNegative) { + verify(property <= 0.0, 'The "$name" is positive.'); + } + } + verifyDouble(scrollOffset, 'scrollOffset'); + verifyDouble(overlap, 'overlap'); + verifyDouble(crossAxisExtent, 'crossAxisExtent'); + verifyDouble(scrollOffset, 'scrollOffset', mustBePositive: true); + verify(axisDirectionToAxis(axisDirection) != axisDirectionToAxis(crossAxisDirection), 'The "axisDirection" and the "crossAxisDirection" are along the same axis.'); + verifyDouble(viewportMainAxisExtent, 'viewportMainAxisExtent', mustBePositive: true); + verifyDouble(remainingPaintExtent, 'remainingPaintExtent', mustBePositive: true); + verifyDouble(remainingCacheExtent, 'remainingCacheExtent', mustBePositive: true); + verifyDouble(cacheOrigin, 'cacheOrigin', mustBeNegative: true); + verifyDouble(precedingScrollExtent, 'precedingScrollExtent', mustBePositive: true); + verify(isNormalized, 'The constraints are not normalized.'); // should be redundant with earlier checks + if (hasErrors) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$runtimeType is not valid: $errorMessage'), + if (informationCollector != null) + ...informationCollector(), + DiagnosticsProperty<SliverConstraints>('The offending constraints were', this, style: DiagnosticsTreeStyle.errorProperty), + ]); + } + return true; + }()); + return true; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other is! SliverConstraints) { + return false; + } + assert(other.debugAssertIsValid()); + return other.axisDirection == axisDirection + && other.growthDirection == growthDirection + && other.scrollOffset == scrollOffset + && other.overlap == overlap + && other.remainingPaintExtent == remainingPaintExtent + && other.crossAxisExtent == crossAxisExtent + && other.crossAxisDirection == crossAxisDirection + && other.viewportMainAxisExtent == viewportMainAxisExtent + && other.remainingCacheExtent == remainingCacheExtent + && other.cacheOrigin == cacheOrigin; + } + + @override + int get hashCode => Object.hash( + axisDirection, + growthDirection, + scrollOffset, + overlap, + remainingPaintExtent, + crossAxisExtent, + crossAxisDirection, + viewportMainAxisExtent, + remainingCacheExtent, + cacheOrigin, + ); + + @override + String toString() { + final List<String> properties = <String>[ + '$axisDirection', + '$growthDirection', + '$userScrollDirection', + 'scrollOffset: ${scrollOffset.toStringAsFixed(1)}', + 'remainingPaintExtent: ${remainingPaintExtent.toStringAsFixed(1)}', + if (overlap != 0.0) 'overlap: ${overlap.toStringAsFixed(1)}', + 'crossAxisExtent: ${crossAxisExtent.toStringAsFixed(1)}', + 'crossAxisDirection: $crossAxisDirection', + 'viewportMainAxisExtent: ${viewportMainAxisExtent.toStringAsFixed(1)}', + 'remainingCacheExtent: ${remainingCacheExtent.toStringAsFixed(1)}', + 'cacheOrigin: ${cacheOrigin.toStringAsFixed(1)}', + ]; + return 'SliverConstraints(${properties.join(', ')})'; + } +} + +/// Describes the amount of space occupied by a [RenderSliver]. +/// +/// A sliver can occupy space in several different ways, which is why this class +/// contains multiple values. +@immutable +class SliverGeometry with Diagnosticable { + /// Creates an object that describes the amount of space occupied by a sliver. + /// + /// If the [layoutExtent] argument is null, [layoutExtent] defaults to the + /// [paintExtent]. If the [hitTestExtent] argument is null, [hitTestExtent] + /// defaults to the [paintExtent]. If [visible] is null, [visible] defaults to + /// whether [paintExtent] is greater than zero. + const SliverGeometry({ + this.scrollExtent = 0.0, + this.paintExtent = 0.0, + this.paintOrigin = 0.0, + double? layoutExtent, + this.maxPaintExtent = 0.0, + this.maxScrollObstructionExtent = 0.0, + this.crossAxisExtent, + double? hitTestExtent, + bool? visible, + this.hasVisualOverflow = false, + this.scrollOffsetCorrection, + double? cacheExtent, + }) : assert(scrollOffsetCorrection != 0.0), + layoutExtent = layoutExtent ?? paintExtent, + hitTestExtent = hitTestExtent ?? paintExtent, + cacheExtent = cacheExtent ?? layoutExtent ?? paintExtent, + visible = visible ?? paintExtent > 0.0; + + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + SliverGeometry copyWith({ + double? scrollExtent, + double? paintExtent, + double? paintOrigin, + double? layoutExtent, + double? maxPaintExtent, + double? maxScrollObstructionExtent, + double? crossAxisExtent, + double? hitTestExtent, + bool? visible, + bool? hasVisualOverflow, + double? cacheExtent, + }) { + return SliverGeometry( + scrollExtent: scrollExtent ?? this.scrollExtent, + paintExtent: paintExtent ?? this.paintExtent, + paintOrigin: paintOrigin ?? this.paintOrigin, + layoutExtent: layoutExtent ?? this.layoutExtent, + maxPaintExtent: maxPaintExtent ?? this.maxPaintExtent, + maxScrollObstructionExtent: maxScrollObstructionExtent ?? this.maxScrollObstructionExtent, + crossAxisExtent: crossAxisExtent ?? this.crossAxisExtent, + hitTestExtent: hitTestExtent ?? this.hitTestExtent, + visible: visible ?? this.visible, + hasVisualOverflow: hasVisualOverflow ?? this.hasVisualOverflow, + cacheExtent: cacheExtent ?? this.cacheExtent, + ); + } + + /// A sliver that occupies no space at all. + static const SliverGeometry zero = SliverGeometry(); + + /// The (estimated) total scrollable extent that this sliver has content for. + /// + /// This is the amount of scrolling the user needs to do to get from the + /// beginning of this sliver to the end of this sliver. + /// + /// The value is used to calculate the [SliverConstraints.scrollOffset] of + /// all slivers in the scrollable and thus should be provided whether the + /// sliver is currently in the viewport or not. + /// + /// In a typical scrolling scenario, the [scrollExtent] is constant for a + /// sliver throughout the scrolling while [paintExtent] and [layoutExtent] + /// will progress from `0` when offscreen to between `0` and [scrollExtent] + /// as the sliver scrolls partially into and out of the screen and is + /// equal to [scrollExtent] while the sliver is entirely on screen. However, + /// these relationships can be customized to achieve more special effects. + /// + /// This value must be accurate if the [paintExtent] is less than the + /// [SliverConstraints.remainingPaintExtent] provided during layout. + final double scrollExtent; + + /// The visual location of the first visible part of this sliver relative to + /// its layout position. + /// + /// For example, if the sliver wishes to paint visually before its layout + /// position, the [paintOrigin] is negative. The coordinate system this sliver + /// uses for painting is relative to this [paintOrigin]. In other words, + /// when [RenderSliver.paint] is called, the (0, 0) position of the [Offset] + /// given to it is at this [paintOrigin]. + /// + /// The coordinate system used for the [paintOrigin] itself is relative + /// to the start of this sliver's layout position rather than relative to + /// its current position on the viewport. In other words, in a typical + /// scrolling scenario, [paintOrigin] remains constant at 0.0 rather than + /// tracking from 0.0 to [SliverConstraints.viewportMainAxisExtent] as the + /// sliver scrolls past the viewport. + /// + /// This value does not affect the layout of subsequent slivers. The next + /// sliver is still placed at [layoutExtent] after this sliver's layout + /// position. This value does affect where the [paintExtent] extent is + /// measured from when computing the [SliverConstraints.overlap] for the next + /// sliver. + /// + /// Defaults to 0.0, which means slivers start painting at their layout + /// position by default. + final double paintOrigin; + + /// The amount of currently visible visual space that was taken by the sliver + /// to render the subset of the sliver that covers all or part of the + /// [SliverConstraints.remainingPaintExtent] in the current viewport. + /// + /// This value does not affect how the next sliver is positioned. In other + /// words, if this value was 100 and [layoutExtent] was 0, typical slivers + /// placed after it would end up drawing in the same 100 pixel space while + /// painting. + /// + /// This must be between zero and [SliverConstraints.remainingPaintExtent]. + /// + /// This value is typically 0 when outside of the viewport and grows or + /// shrinks from 0 or to 0 as the sliver is being scrolled into and out of the + /// viewport unless the sliver wants to achieve a special effect and paint + /// even when scrolled away. + /// + /// This contributes to the calculation for the next sliver's + /// [SliverConstraints.overlap]. + final double paintExtent; + + /// The distance from the first visible part of this sliver to the first + /// visible part of the next sliver, assuming the next sliver's + /// [SliverConstraints.scrollOffset] is zero. + /// + /// This must be between zero and [paintExtent]. It defaults to [paintExtent]. + /// + /// This value is typically 0 when outside of the viewport and grows or + /// shrinks from 0 or to 0 as the sliver is being scrolled into and out of the + /// viewport unless the sliver wants to achieve a special effect and push + /// down the layout start position of subsequent slivers before the sliver is + /// even scrolled into the viewport. + final double layoutExtent; + + /// The (estimated) total paint extent that this sliver would be able to + /// provide if the [SliverConstraints.remainingPaintExtent] was infinite. + /// + /// This is used by viewports that implement shrink-wrapping. + /// + /// By definition, this cannot be less than [paintExtent]. + final double maxPaintExtent; + + /// The maximum extent by which this sliver can reduce the area in which + /// content can scroll if the sliver were pinned at the edge. + /// + /// Slivers that never get pinned at the edge, should return zero. + /// + /// A pinned app bar is an example for a sliver that would use this setting: + /// When the app bar is pinned to the top, the area in which content can + /// actually scroll is reduced by the height of the app bar. + final double maxScrollObstructionExtent; + + /// The distance from where this sliver started painting to the bottom of + /// where it should accept hits. + /// + /// This must be between zero and [paintExtent]. It defaults to [paintExtent]. + final double hitTestExtent; + + /// Whether this sliver should be painted. + /// + /// By default, this is true if [paintExtent] is greater than zero, and + /// false if [paintExtent] is zero. + final bool visible; + + /// Whether this sliver has visual overflow. + /// + /// By default, this is false, which means the viewport does not need to clip + /// its children. If any slivers have visual overflow, the viewport will apply + /// a clip to its children. + final bool hasVisualOverflow; + + /// If this is non-zero after [RenderSliver.performLayout] returns, the scroll + /// offset will be adjusted by the parent and then the entire layout of the + /// parent will be rerun. + /// + /// When the value is non-zero, the [RenderSliver] does not need to compute + /// the rest of the values when constructing the [SliverGeometry] or call + /// [RenderObject.layout] on its children since [RenderSliver.performLayout] + /// will be called again on this sliver in the same frame after the + /// [SliverConstraints.scrollOffset] correction has been applied, when the + /// proper [SliverGeometry] and layout of its children can be computed. + /// + /// If the parent is also a [RenderSliver], it must propagate this value + /// in its own [RenderSliver.geometry] property until a viewport which adjusts + /// its offset based on this value. + final double? scrollOffsetCorrection; + + /// How many pixels the sliver has consumed in the + /// [SliverConstraints.remainingCacheExtent]. + /// + /// This value should be equal to or larger than the [layoutExtent] because + /// the sliver always consumes at least the [layoutExtent] from the + /// [SliverConstraints.remainingCacheExtent] and possibly more if it falls + /// into the cache area of the viewport. + /// + /// See also: + /// + /// * [RenderViewport.cacheExtent] for a description of a viewport's cache area. + final double cacheExtent; + + /// The amount of space allocated to the cross axis. + /// + /// This value will be typically null unless it is different from + /// [SliverConstraints.crossAxisExtent]. If null, then the cross axis extent of + /// the sliver is assumed to be the same as the [SliverConstraints.crossAxisExtent]. + /// This is because slivers typically consume all of the extent that is available + /// in the cross axis. + /// + /// See also: + /// + /// * [SliverConstrainedCrossAxis] for an example of a sliver which takes up + /// a smaller cross axis extent than the provided constraint. + /// * [SliverCrossAxisGroup] for an example of a sliver which makes use of this + /// [crossAxisExtent] to lay out their children. + final double? crossAxisExtent; + + /// Asserts that this geometry is internally consistent. + /// + /// Does nothing if asserts are disabled. Always returns true. + bool debugAssertIsValid({ + InformationCollector? informationCollector, + }) { + assert(() { + void verify(bool check, String summary, {List<DiagnosticsNode>? details}) { + if (check) { + return; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('${objectRuntimeType(this, 'SliverGeometry')} is not valid: $summary'), + ...?details, + if (informationCollector != null) + ...informationCollector(), + ]); + } + + verify(scrollExtent >= 0.0, 'The "scrollExtent" is negative.'); + verify(paintExtent >= 0.0, 'The "paintExtent" is negative.'); + verify(layoutExtent >= 0.0, 'The "layoutExtent" is negative.'); + verify(cacheExtent >= 0.0, 'The "cacheExtent" is negative.'); + if (layoutExtent > paintExtent) { + verify(false, + 'The "layoutExtent" exceeds the "paintExtent".', + details: _debugCompareFloats('paintExtent', paintExtent, 'layoutExtent', layoutExtent), + ); + } + // If the paintExtent is slightly more than the maxPaintExtent, but the difference is still less + // than precisionErrorTolerance, we will not throw the assert below. + if (paintExtent - maxPaintExtent > precisionErrorTolerance) { + verify(false, + 'The "maxPaintExtent" is less than the "paintExtent".', + details: + _debugCompareFloats('maxPaintExtent', maxPaintExtent, 'paintExtent', paintExtent) + ..add(ErrorDescription("By definition, a sliver can't paint more than the maximum that it can paint!")), + ); + } + verify(hitTestExtent >= 0.0, 'The "hitTestExtent" is negative.'); + verify(scrollOffsetCorrection != 0.0, 'The "scrollOffsetCorrection" is zero.'); + return true; + }()); + return true; + } + + @override + String toStringShort() => objectRuntimeType(this, 'SliverGeometry'); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('scrollExtent', scrollExtent)); + if (paintExtent > 0.0) { + properties.add(DoubleProperty('paintExtent', paintExtent, unit : visible ? null : ' but not painting')); + } else if (paintExtent == 0.0) { + if (visible) { + properties.add(DoubleProperty('paintExtent', paintExtent, unit: visible ? null : ' but visible')); + } + properties.add(FlagProperty('visible', value: visible, ifFalse: 'hidden')); + } else { + // Negative paintExtent! + properties.add(DoubleProperty('paintExtent', paintExtent, tooltip: '!')); + } + properties.add(DoubleProperty('paintOrigin', paintOrigin, defaultValue: 0.0)); + properties.add(DoubleProperty('layoutExtent', layoutExtent, defaultValue: paintExtent)); + properties.add(DoubleProperty('maxPaintExtent', maxPaintExtent)); + properties.add(DoubleProperty('hitTestExtent', hitTestExtent, defaultValue: paintExtent)); + properties.add(DiagnosticsProperty<bool>('hasVisualOverflow', hasVisualOverflow, defaultValue: false)); + properties.add(DoubleProperty('scrollOffsetCorrection', scrollOffsetCorrection, defaultValue: null)); + properties.add(DoubleProperty('cacheExtent', cacheExtent, defaultValue: 0.0)); + } +} + +/// Method signature for hit testing a [RenderSliver]. +/// +/// Used by [SliverHitTestResult.addWithAxisOffset] to hit test [RenderSliver] +/// children. +/// +/// See also: +/// +/// * [RenderSliver.hitTest], which documents more details around hit testing +/// [RenderSliver]s. +typedef SliverHitTest = bool Function(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }); + +/// The result of performing a hit test on [RenderSliver]s. +/// +/// An instance of this class is provided to [RenderSliver.hitTest] to record +/// the result of the hit test. +class SliverHitTestResult extends HitTestResult { + /// Creates an empty hit test result for hit testing on [RenderSliver]. + SliverHitTestResult() : super(); + + /// Wraps `result` to create a [HitTestResult] that implements the + /// [SliverHitTestResult] protocol for hit testing on [RenderSliver]s. + /// + /// This method is used by [RenderObject]s that adapt between the + /// [RenderSliver]-world and the non-[RenderSliver]-world to convert a + /// (subtype of) [HitTestResult] to a [SliverHitTestResult] for hit testing on + /// [RenderSliver]s. + /// + /// The [HitTestEntry] instances added to the returned [SliverHitTestResult] + /// are also added to the wrapped `result` (both share the same underlying + /// data structure to store [HitTestEntry] instances). + /// + /// See also: + /// + /// * [HitTestResult.wrap], which turns a [SliverHitTestResult] back into a + /// generic [HitTestResult]. + /// * [BoxHitTestResult.wrap], which turns a [SliverHitTestResult] into a + /// [BoxHitTestResult] for hit testing on [RenderBox] children. + SliverHitTestResult.wrap(super.result) : super.wrap(); + + /// Transforms `mainAxisPosition` and `crossAxisPosition` to the local + /// coordinate system of a child for hit-testing the child. + /// + /// The actual hit testing of the child needs to be implemented in the + /// provided `hitTest` callback, which is invoked with the transformed + /// `position` as argument. + /// + /// For the transform `mainAxisOffset` is subtracted from `mainAxisPosition` + /// and `crossAxisOffset` is subtracted from `crossAxisPosition`. + /// + /// The `paintOffset` describes how the paint position of a point painted at + /// the provided `mainAxisPosition` and `crossAxisPosition` would change after + /// `mainAxisOffset` and `crossAxisOffset` have been applied. This + /// `paintOffset` is used to properly convert [PointerEvent]s to the local + /// coordinate system of the event receiver. + /// + /// The `paintOffset` may be null if `mainAxisOffset` and `crossAxisOffset` are + /// both zero. + /// + /// The function returns the return value of `hitTest`. + bool addWithAxisOffset({ + required Offset? paintOffset, + required double mainAxisOffset, + required double crossAxisOffset, + required double mainAxisPosition, + required double crossAxisPosition, + required SliverHitTest hitTest, + }) { + if (paintOffset != null) { + pushOffset(-paintOffset); + } + final bool isHit = hitTest( + this, + mainAxisPosition: mainAxisPosition - mainAxisOffset, + crossAxisPosition: crossAxisPosition - crossAxisOffset, + ); + if (paintOffset != null) { + popTransform(); + } + return isHit; + } +} + +/// A hit test entry used by [RenderSliver]. +/// +/// The coordinate system used by this hit test entry is relative to the +/// [AxisDirection] of the target sliver. +class SliverHitTestEntry extends HitTestEntry<RenderSliver> { + /// Creates a sliver hit test entry. + SliverHitTestEntry( + super.target, { + required this.mainAxisPosition, + required this.crossAxisPosition, + }); + + /// The distance in the [AxisDirection] from the edge of the sliver's painted + /// area (as given by the [SliverConstraints.scrollOffset]) to the hit point. + /// This can be an unusual direction, for example in the [AxisDirection.up] + /// case this is a distance from the _bottom_ of the sliver's painted area. + final double mainAxisPosition; + + /// The distance to the hit point in the axis opposite the + /// [SliverConstraints.axis]. + /// + /// If the cross axis is horizontal (i.e. the + /// [SliverConstraints.axisDirection] is either [AxisDirection.down] or + /// [AxisDirection.up]), then the [crossAxisPosition] is a distance from the + /// left edge of the sliver. If the cross axis is vertical (i.e. the + /// [SliverConstraints.axisDirection] is either [AxisDirection.right] or + /// [AxisDirection.left]), then the [crossAxisPosition] is a distance from the + /// top edge of the sliver. + /// + /// This is always a distance from the left or top of the parent, never a + /// distance from the right or bottom. + final double crossAxisPosition; + + @override + String toString() => '${target.runtimeType}@(mainAxis: $mainAxisPosition, crossAxis: $crossAxisPosition)'; +} + +/// Parent data structure used by parents of slivers that position their +/// children using layout offsets. +/// +/// This data structure is optimized for fast layout. It is best used by parents +/// that expect to have many children whose relative positions don't change even +/// when the scroll offset does. +class SliverLogicalParentData extends ParentData { + /// The position of the child relative to the zero scroll offset. + /// + /// The number of pixels from the zero scroll offset of the parent sliver + /// (the line at which its [SliverConstraints.scrollOffset] is zero) to the + /// side of the child closest to that offset. A [layoutOffset] can be null + /// when it cannot be determined. The value will be set after layout. + /// + /// In a typical list, this does not change as the parent is scrolled. + /// + /// Defaults to null. + double? layoutOffset; + + @override + String toString() => 'layoutOffset=${layoutOffset == null ? 'None': layoutOffset!.toStringAsFixed(1)}'; +} + +/// Parent data for slivers that have multiple children and that position their +/// children using layout offsets. +class SliverLogicalContainerParentData extends SliverLogicalParentData with ContainerParentDataMixin<RenderSliver> { } + +/// Parent data structure used by parents of slivers that position their +/// children using absolute coordinates. +/// +/// For example, used by [RenderViewport]. +/// +/// This data structure is optimized for fast painting, at the cost of requiring +/// additional work during layout when the children change their offsets. It is +/// best used by parents that expect to have few children, especially if those +/// children will themselves be very tall relative to the parent. +class SliverPhysicalParentData extends ParentData { + /// The position of the child relative to the parent. + /// + /// This is the distance from the top left visible corner of the parent to the + /// top left visible corner of the sliver. + Offset paintOffset = Offset.zero; + + /// The [crossAxisFlex] factor to use for this sliver child. + /// + /// If used outside of a [SliverCrossAxisGroup] widget, this value has no meaning. + /// + /// If null or zero, the child is inflexible and determines its own size in the cross axis. + /// If non-zero, the amount of space the child can occupy in the cross axis is + /// determined by dividing the free space (after placing the inflexible children) + /// according to the flex factors of the flexible children. + /// + /// This value is only used by the [SliverCrossAxisGroup] widget to determine + /// how to allocate its [SliverConstraints.crossAxisExtent] to its children. + /// + /// See also: + /// + /// * [SliverCrossAxisGroup], which lays out multiple slivers along the + /// cross axis direction. + int? crossAxisFlex; + + /// Apply the [paintOffset] to the given [transform]. + /// + /// Used to implement [RenderObject.applyPaintTransform] by slivers that use + /// [SliverPhysicalParentData]. + void applyPaintTransform(Matrix4 transform) { + // Hit test logic relies on this always providing an invertible matrix. + transform.translate(paintOffset.dx, paintOffset.dy); + } + + @override + String toString() => 'paintOffset=$paintOffset'; +} + +/// Parent data for slivers that have multiple children and that position their +/// children using absolute coordinates. +class SliverPhysicalContainerParentData extends SliverPhysicalParentData with ContainerParentDataMixin<RenderSliver> { } + +List<DiagnosticsNode> _debugCompareFloats(String labelA, double valueA, String labelB, double valueB) { + return <DiagnosticsNode>[ + if (valueA.toStringAsFixed(1) != valueB.toStringAsFixed(1)) + ErrorDescription( + 'The $labelA is ${valueA.toStringAsFixed(1)}, but ' + 'the $labelB is ${valueB.toStringAsFixed(1)}.', + ) + else ...<DiagnosticsNode>[ + ErrorDescription('The $labelA is $valueA, but the $labelB is $valueB.'), + ErrorHint( + 'Maybe you have fallen prey to floating point rounding errors, and should explicitly ' + 'apply the min() or max() functions, or the clamp() method, to the $labelB?', + ), + ], + ]; +} + +/// Base class for the render objects that implement scroll effects in viewports. +/// +/// A [RenderViewport] has a list of child slivers. Each sliver — literally a +/// slice of the viewport's contents — is laid out in turn, covering the +/// viewport in the process. (Every sliver is laid out each time, including +/// those that have zero extent because they are "scrolled off" or are beyond +/// the end of the viewport.) +/// +/// Slivers participate in the _sliver protocol_, wherein during [layout] each +/// sliver receives a [SliverConstraints] object and computes a corresponding +/// [SliverGeometry] that describes where it fits in the viewport. This is +/// analogous to the box protocol used by [RenderBox], which gets a +/// [BoxConstraints] as input and computes a [Size]. +/// +/// Slivers have a leading edge, which is where the position described by +/// [SliverConstraints.scrollOffset] for this sliver begins. Slivers have +/// several dimensions, the primary of which is [SliverGeometry.paintExtent], +/// which describes the extent of the sliver along the main axis, starting from +/// the leading edge, reaching either the end of the viewport or the end of the +/// sliver, whichever comes first. +/// +/// Slivers can change dimensions based on the changing constraints in a +/// non-linear fashion, to achieve various scroll effects. For example, the +/// various [RenderSliverPersistentHeader] subclasses, on which [SliverAppBar] +/// is based, achieve effects such as staying visible despite the scroll offset, +/// or reappearing at different offsets based on the user's scroll direction +/// ([SliverConstraints.userScrollDirection]). +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=Mz3kHQxBjGg} +/// +/// ## Writing a RenderSliver subclass +/// +/// Slivers can have sliver children, or children from another coordinate +/// system, typically box children. (For details on the box protocol, see +/// [RenderBox].) Slivers can also have different child models, typically having +/// either one child, or a list of children. +/// +/// ### Examples of slivers +/// +/// A good example of a sliver with a single child that is also itself a sliver +/// is [RenderSliverPadding], which indents its child. A sliver-to-sliver render +/// object such as this must construct a [SliverConstraints] object for its +/// child, then must take its child's [SliverGeometry] and use it to form its +/// own [geometry]. +/// +/// The other common kind of one-child sliver is a sliver that has a single +/// [RenderBox] child. An example of that would be [RenderSliverToBoxAdapter], +/// which lays out a single box and sizes itself around the box. Such a sliver +/// must use its [SliverConstraints] to create a [BoxConstraints] for the +/// child, lay the child out (using the child's [layout] method), and then use +/// the child's [RenderBox.size] to generate the sliver's [SliverGeometry]. +/// +/// The most common kind of sliver though is one with multiple children. The +/// most straight-forward example of this is [RenderSliverList], which arranges +/// its children one after the other in the main axis direction. As with the +/// one-box-child sliver case, it uses its [constraints] to create a +/// [BoxConstraints] for the children, and then it uses the aggregate +/// information from all its children to generate its [geometry]. Unlike the +/// one-child cases, however, it is judicious in which children it actually lays +/// out (and later paints). If the scroll offset is 1000 pixels, and it +/// previously determined that the first three children are each 400 pixels +/// tall, then it will skip the first two and start the layout with its third +/// child. +/// +/// ### Layout +/// +/// As they are laid out, slivers decide their [geometry], which includes their +/// size ([SliverGeometry.paintExtent]) and the position of the next sliver +/// ([SliverGeometry.layoutExtent]), as well as the position of each of their +/// children, based on the input [constraints] from the viewport such as the +/// scroll offset ([SliverConstraints.scrollOffset]). +/// +/// For example, a sliver that just paints a box 100 pixels high would say its +/// [SliverGeometry.paintExtent] was 100 pixels when the scroll offset was zero, +/// but would say its [SliverGeometry.paintExtent] was 25 pixels when the scroll +/// offset was 75 pixels, and would say it was zero when the scroll offset was +/// 100 pixels or more. (This is assuming that +/// [SliverConstraints.remainingPaintExtent] was more than 100 pixels.) +/// +/// The various dimensions that are provided as input to this system are in the +/// [constraints]. They are described in detail in the documentation for the +/// [SliverConstraints] class. +/// +/// The [performLayout] function must take these [constraints] and create a +/// [SliverGeometry] object that it must then assign to the [geometry] property. +/// The different dimensions of the geometry that can be configured are +/// described in detail in the documentation for the [SliverGeometry] class. +/// +/// ### Painting +/// +/// In addition to implementing layout, a sliver must also implement painting. +/// This is achieved by overriding the [paint] method. +/// +/// The [paint] method is called with an [Offset] from the [Canvas] origin to +/// the top-left corner of the sliver, _regardless of the axis direction_. +/// +/// Subclasses should also override [applyPaintTransform] to provide the +/// [Matrix4] describing the position of each child relative to the sliver. +/// (This is used by, among other things, the accessibility layer, to determine +/// the bounds of the child.) +/// +/// ### Hit testing +/// +/// To implement hit testing, either override the [hitTestSelf] and +/// [hitTestChildren] methods, or, for more complex cases, instead override the +/// [hitTest] method directly. +/// +/// To actually react to pointer events, the [handleEvent] method may be +/// implemented. By default it does nothing. (Typically gestures are handled by +/// widgets in the box protocol, not by slivers directly.) +/// +/// ### Helper methods +/// +/// There are a number of methods that a sliver should implement which will make +/// the other methods easier to implement. Each method listed below has detailed +/// documentation. In addition, the [RenderSliverHelpers] class can be used to +/// mix in some helpful methods. +/// +/// #### childScrollOffset +/// +/// If the subclass positions children anywhere other than at scroll offset +/// zero, it should override [childScrollOffset]. For example, +/// [RenderSliverList] and [RenderSliverGrid] override this method, but +/// [RenderSliverToBoxAdapter] does not. +/// +/// This is used by, among other things, [Scrollable.ensureVisible]. +/// +/// #### childMainAxisPosition +/// +/// Subclasses should implement [childMainAxisPosition] to describe where their +/// children are positioned. +/// +/// #### childCrossAxisPosition +/// +/// If the subclass positions children in the cross-axis at a position other +/// than zero, then it should override [childCrossAxisPosition]. For example +/// [RenderSliverGrid] overrides this method. +abstract class RenderSliver extends RenderObject { + // layout input + @override + SliverConstraints get constraints => super.constraints as SliverConstraints; + + /// The amount of space this sliver occupies. + /// + /// This value is stale whenever this object is marked as needing layout. + /// During [performLayout], do not read the [geometry] of a child unless you + /// pass true for parentUsesSize when calling the child's [layout] function. + /// + /// The geometry of a sliver should be set only during the sliver's + /// [performLayout] or [performResize] functions. If you wish to change the + /// geometry of a sliver outside of those functions, call [markNeedsLayout] + /// instead to schedule a layout of the sliver. + SliverGeometry? get geometry => _geometry; + SliverGeometry? _geometry; + set geometry(SliverGeometry? value) { + assert(!(debugDoingThisResize && debugDoingThisLayout)); + assert(sizedByParent || !debugDoingThisResize); + assert(() { + if ((sizedByParent && debugDoingThisResize) || + (!sizedByParent && debugDoingThisLayout)) { + return true; + } + assert(!debugDoingThisResize); + DiagnosticsNode? contract, violation, hint; + if (debugDoingThisLayout) { + assert(sizedByParent); + violation = ErrorDescription('It appears that the geometry setter was called from performLayout().'); + } else { + violation = ErrorDescription('The geometry setter was called from outside layout (neither performResize() nor performLayout() were being run for this object).'); + if (owner != null && owner!.debugDoingLayout) { + hint = ErrorDescription('Only the object itself can set its geometry. It is a contract violation for other objects to set it.'); + } + } + if (sizedByParent) { + contract = ErrorDescription('Because this RenderSliver has sizedByParent set to true, it must set its geometry in performResize().'); + } else { + contract = ErrorDescription('Because this RenderSliver has sizedByParent set to false, it must set its geometry in performLayout().'); + } + + final List<DiagnosticsNode> information = <DiagnosticsNode>[ + ErrorSummary('RenderSliver geometry setter called incorrectly.'), + violation, + if (hint != null) hint, + contract, + describeForError('The RenderSliver in question is'), + ]; + throw FlutterError.fromParts(information); + }()); + _geometry = value; + } + + @override + Rect get semanticBounds => paintBounds; + + @override + Rect get paintBounds { + switch (constraints.axis) { + case Axis.horizontal: + return Rect.fromLTWH( + 0.0, 0.0, + geometry!.paintExtent, + constraints.crossAxisExtent, + ); + case Axis.vertical: + return Rect.fromLTWH( + 0.0, 0.0, + constraints.crossAxisExtent, + geometry!.paintExtent, + ); + } + } + + @override + void debugResetSize() { } + + @override + void debugAssertDoesMeetConstraints() { + assert(geometry!.debugAssertIsValid( + informationCollector: () => <DiagnosticsNode>[ + describeForError('The RenderSliver that returned the offending geometry was'), + ], + )); + assert(() { + if (geometry!.paintOrigin + geometry!.paintExtent > constraints.remainingPaintExtent) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('SliverGeometry has a paintOffset that exceeds the remainingPaintExtent from the constraints.'), + describeForError('The render object whose geometry violates the constraints is the following'), + ..._debugCompareFloats( + 'remainingPaintExtent', constraints.remainingPaintExtent, + 'paintOrigin + paintExtent', geometry!.paintOrigin + geometry!.paintExtent, + ), + ErrorDescription( + 'The paintOrigin and paintExtent must cause the child sliver to paint ' + 'within the viewport, and so cannot exceed the remainingPaintExtent.', + ), + ]); + } + return true; + }()); + } + + @override + void performResize() { + assert(false); + } + + /// For a center sliver, the distance before the absolute zero scroll offset + /// that this sliver can cover. + /// + /// For example, if an [AxisDirection.down] viewport with an + /// [RenderViewport.anchor] of 0.5 has a single sliver with a height of 100.0 + /// and its [centerOffsetAdjustment] returns 50.0, then the sliver will be + /// centered in the viewport when the scroll offset is 0.0. + /// + /// The distance here is in the opposite direction of the + /// [RenderViewport.axisDirection], so values will typically be positive. + double get centerOffsetAdjustment => 0.0; + + /// Determines the set of render objects located at the given position. + /// + /// Returns true if the given point is contained in this render object or one + /// of its descendants. Adds any render objects that contain the point to the + /// given hit test result. + /// + /// The caller is responsible for providing the position in the local + /// coordinate space of the callee. The callee is responsible for checking + /// whether the given position is within its bounds. + /// + /// Hit testing requires layout to be up-to-date but does not require painting + /// to be up-to-date. That means a render object can rely upon [performLayout] + /// having been called in [hitTest] but cannot rely upon [paint] having been + /// called. For example, a render object might be a child of a [RenderOpacity] + /// object, which calls [hitTest] on its children when its opacity is zero + /// even through it does not [paint] its children. + /// + /// ## Coordinates for RenderSliver objects + /// + /// The `mainAxisPosition` is the distance in the [AxisDirection] (after + /// applying the [GrowthDirection]) from the edge of the sliver's painted + /// area. This can be an unusual direction, for example in the + /// [AxisDirection.up] case this is a distance from the _bottom_ of the + /// sliver's painted area. + /// + /// The `crossAxisPosition` is the distance in the other axis. If the cross + /// axis is horizontal (i.e. the [SliverConstraints.axisDirection] is either + /// [AxisDirection.down] or [AxisDirection.up]), then the `crossAxisPosition` + /// is a distance from the left edge of the sliver. If the cross axis is + /// vertical (i.e. the [SliverConstraints.axisDirection] is either + /// [AxisDirection.right] or [AxisDirection.left]), then the + /// `crossAxisPosition` is a distance from the top edge of the sliver. + /// + /// ## Implementing hit testing for slivers + /// + /// The most straight-forward way to implement hit testing for a new sliver + /// render object is to override its [hitTestSelf] and [hitTestChildren] + /// methods. + bool hitTest(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }) { + if (mainAxisPosition >= 0.0 && mainAxisPosition < geometry!.hitTestExtent && + crossAxisPosition >= 0.0 && crossAxisPosition < constraints.crossAxisExtent) { + if (hitTestChildren(result, mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition) || + hitTestSelf(mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition)) { + result.add(SliverHitTestEntry( + this, + mainAxisPosition: mainAxisPosition, + crossAxisPosition: crossAxisPosition, + )); + return true; + } + } + return false; + } + + /// Override this method if this render object can be hit even if its + /// children were not hit. + /// + /// Used by [hitTest]. If you override [hitTest] and do not call this + /// function, then you don't need to implement this function. + /// + /// For a discussion of the semantics of the arguments, see [hitTest]. + @protected + bool hitTestSelf({ required double mainAxisPosition, required double crossAxisPosition }) => false; + + /// Override this method to check whether any children are located at the + /// given position. + /// + /// Typically children should be hit-tested in reverse paint order so that + /// hit tests at locations where children overlap hit the child that is + /// visually "on top" (i.e., paints later). + /// + /// Used by [hitTest]. If you override [hitTest] and do not call this + /// function, then you don't need to implement this function. + /// + /// For a discussion of the semantics of the arguments, see [hitTest]. + @protected + bool hitTestChildren(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }) => false; + + /// Computes the portion of the region from `from` to `to` that is visible, + /// assuming that only the region from the [SliverConstraints.scrollOffset] + /// that is [SliverConstraints.remainingPaintExtent] high is visible, and that + /// the relationship between scroll offsets and paint offsets is linear. + /// + /// For example, if the constraints have a scroll offset of 100 and a + /// remaining paint extent of 100, and the arguments to this method describe + /// the region 50..150, then the returned value would be 50 (from scroll + /// offset 100 to scroll offset 150). + /// + /// This method is not useful if there is not a 1:1 relationship between + /// consumed scroll offset and consumed paint extent. For example, if the + /// sliver always paints the same amount but consumes a scroll offset extent + /// that is proportional to the [SliverConstraints.scrollOffset], then this + /// function's results will not be consistent. + // This could be a static method but isn't, because it would be less convenient + // to call it from subclasses if it was. + double calculatePaintOffset(SliverConstraints constraints, { required double from, required double to }) { + assert(from <= to); + final double a = constraints.scrollOffset; + final double b = constraints.scrollOffset + constraints.remainingPaintExtent; + // the clamp on the next line is to avoid floating point rounding errors + return clampDouble(clampDouble(to, a, b) - clampDouble(from, a, b), 0.0, constraints.remainingPaintExtent); + } + + /// Computes the portion of the region from `from` to `to` that is within + /// the cache extent of the viewport, assuming that only the region from the + /// [SliverConstraints.cacheOrigin] that is + /// [SliverConstraints.remainingCacheExtent] high is visible, and that + /// the relationship between scroll offsets and paint offsets is linear. + /// + /// This method is not useful if there is not a 1:1 relationship between + /// consumed scroll offset and consumed cache extent. + double calculateCacheOffset(SliverConstraints constraints, { required double from, required double to }) { + assert(from <= to); + final double a = constraints.scrollOffset + constraints.cacheOrigin; + final double b = constraints.scrollOffset + constraints.remainingCacheExtent; + // the clamp on the next line is to avoid floating point rounding errors + return clampDouble(clampDouble(to, a, b) - clampDouble(from, a, b), 0.0, constraints.remainingCacheExtent); + } + + /// Returns the distance from the leading _visible_ edge of the sliver to the + /// side of the given child closest to that edge. + /// + /// For example, if the [constraints] describe this sliver as having an axis + /// direction of [AxisDirection.down], then this is the distance from the top + /// of the visible portion of the sliver to the top of the child. On the other + /// hand, if the [constraints] describe this sliver as having an axis + /// direction of [AxisDirection.up], then this is the distance from the bottom + /// of the visible portion of the sliver to the bottom of the child. In both + /// cases, this is the direction of increasing + /// [SliverConstraints.scrollOffset] and + /// [SliverLogicalParentData.layoutOffset]. + /// + /// For children that are [RenderSliver]s, the leading edge of the _child_ + /// will be the leading _visible_ edge of the child, not the part of the child + /// that would locally be a scroll offset 0.0. For children that are not + /// [RenderSliver]s, for example a [RenderBox] child, it's the actual distance + /// to the edge of the box, since those boxes do not know how to handle being + /// scrolled. + /// + /// This method differs from [childScrollOffset] in that + /// [childMainAxisPosition] gives the distance from the leading _visible_ edge + /// of the sliver whereas [childScrollOffset] gives the distance from the + /// sliver's zero scroll offset. + /// + /// Calling this for a child that is not visible is not valid. + @protected + double childMainAxisPosition(covariant RenderObject child) { + assert(() { + throw FlutterError('${objectRuntimeType(this, 'RenderSliver')} does not implement childPosition.'); + }()); + return 0.0; + } + + /// Returns the distance along the cross axis from the zero of the cross axis + /// in this sliver's [paint] coordinate space to the nearest side of the given + /// child. + /// + /// For example, if the [constraints] describe this sliver as having an axis + /// direction of [AxisDirection.down], then this is the distance from the left + /// of the sliver to the left of the child. Similarly, if the [constraints] + /// describe this sliver as having an axis direction of [AxisDirection.up], + /// then this is value is the same. If the axis direction is + /// [AxisDirection.left] or [AxisDirection.right], then it is the distance + /// from the top of the sliver to the top of the child. + /// + /// Calling this for a child that is not visible is not valid. + @protected + double childCrossAxisPosition(covariant RenderObject child) => 0.0; + + /// Returns the scroll offset for the leading edge of the given child. + /// + /// The `child` must be a child of this sliver. + /// + /// This method differs from [childMainAxisPosition] in that + /// [childMainAxisPosition] gives the distance from the leading _visible_ edge + /// of the sliver whereas [childScrollOffset] gives the distance from sliver's + /// zero scroll offset. + double? childScrollOffset(covariant RenderObject child) { + assert(child.parent == this); + return 0.0; + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + assert(() { + throw FlutterError('${objectRuntimeType(this, 'RenderSliver')} does not implement applyPaintTransform.'); + }()); + } + + /// This returns a [Size] with dimensions relative to the leading edge of the + /// sliver, specifically the same offset that is given to the [paint] method. + /// This means that the dimensions may be negative. + /// + /// This is only valid after [layout] has completed. + /// + /// See also: + /// + /// * [getAbsoluteSize], which returns absolute size. + @protected + Size getAbsoluteSizeRelativeToOrigin() { + assert(geometry != null); + assert(!debugNeedsLayout); + switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) { + case AxisDirection.up: + return Size(constraints.crossAxisExtent, -geometry!.paintExtent); + case AxisDirection.right: + return Size(geometry!.paintExtent, constraints.crossAxisExtent); + case AxisDirection.down: + return Size(constraints.crossAxisExtent, geometry!.paintExtent); + case AxisDirection.left: + return Size(-geometry!.paintExtent, constraints.crossAxisExtent); + } + } + + /// This returns the absolute [Size] of the sliver. + /// + /// The dimensions are always positive and calling this is only valid after + /// [layout] has completed. + /// + /// See also: + /// + /// * [getAbsoluteSizeRelativeToOrigin], which returns the size relative to + /// the leading edge of the sliver. + @protected + Size getAbsoluteSize() { + assert(geometry != null); + assert(!debugNeedsLayout); + switch (constraints.axisDirection) { + case AxisDirection.up: + case AxisDirection.down: + return Size(constraints.crossAxisExtent, geometry!.paintExtent); + case AxisDirection.right: + case AxisDirection.left: + return Size(geometry!.paintExtent, constraints.crossAxisExtent); + } + } + + void _debugDrawArrow(Canvas canvas, Paint paint, Offset p0, Offset p1, GrowthDirection direction) { + assert(() { + if (p0 == p1) { + return true; + } + assert(p0.dx == p1.dx || p0.dy == p1.dy); // must be axis-aligned + final double d = (p1 - p0).distance * 0.2; + final Offset temp; + double dx1, dx2, dy1, dy2; + switch (direction) { + case GrowthDirection.forward: + dx1 = dx2 = dy1 = dy2 = d; + case GrowthDirection.reverse: + temp = p0; + p0 = p1; + p1 = temp; + dx1 = dx2 = dy1 = dy2 = -d; + } + if (p0.dx == p1.dx) { + dx2 = -dx2; + } else { + dy2 = -dy2; + } + canvas.drawPath( + Path() + ..moveTo(p0.dx, p0.dy) + ..lineTo(p1.dx, p1.dy) + ..moveTo(p1.dx - dx1, p1.dy - dy1) + ..lineTo(p1.dx, p1.dy) + ..lineTo(p1.dx - dx2, p1.dy - dy2), + paint, + ); + return true; + }()); + } + + @override + void debugPaint(PaintingContext context, Offset offset) { + assert(() { + if (debugPaintSizeEnabled) { + final double strokeWidth = math.min(4.0, geometry!.paintExtent / 30.0); + final Paint paint = Paint() + ..color = const Color(0xFF33CC33) + ..strokeWidth = strokeWidth + ..style = PaintingStyle.stroke + ..maskFilter = MaskFilter.blur(BlurStyle.solid, strokeWidth); + final double arrowExtent = geometry!.paintExtent; + final double padding = math.max(2.0, strokeWidth); + final Canvas canvas = context.canvas; + canvas.drawCircle( + offset.translate(padding, padding), + padding * 0.5, + paint, + ); + switch (constraints.axis) { + case Axis.vertical: + canvas.drawLine( + offset, + offset.translate(constraints.crossAxisExtent, 0.0), + paint, + ); + _debugDrawArrow( + canvas, + paint, + offset.translate(constraints.crossAxisExtent * 1.0 / 4.0, padding), + offset.translate(constraints.crossAxisExtent * 1.0 / 4.0, arrowExtent - padding), + constraints.normalizedGrowthDirection, + ); + _debugDrawArrow( + canvas, + paint, + offset.translate(constraints.crossAxisExtent * 3.0 / 4.0, padding), + offset.translate(constraints.crossAxisExtent * 3.0 / 4.0, arrowExtent - padding), + constraints.normalizedGrowthDirection, + ); + case Axis.horizontal: + canvas.drawLine( + offset, + offset.translate(0.0, constraints.crossAxisExtent), + paint, + ); + _debugDrawArrow( + canvas, + paint, + offset.translate(padding, constraints.crossAxisExtent * 1.0 / 4.0), + offset.translate(arrowExtent - padding, constraints.crossAxisExtent * 1.0 / 4.0), + constraints.normalizedGrowthDirection, + ); + _debugDrawArrow( + canvas, + paint, + offset.translate(padding, constraints.crossAxisExtent * 3.0 / 4.0), + offset.translate(arrowExtent - padding, constraints.crossAxisExtent * 3.0 / 4.0), + constraints.normalizedGrowthDirection, + ); + } + } + return true; + }()); + } + + // This override exists only to change the type of the second argument. + @override + void handleEvent(PointerEvent event, SliverHitTestEntry entry) { } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<SliverGeometry>('geometry', geometry)); + } +} + +/// Mixin for [RenderSliver] subclasses that provides some utility functions. +mixin RenderSliverHelpers implements RenderSliver { + bool _getRightWayUp(SliverConstraints constraints) { + bool rightWayUp; + switch (constraints.axisDirection) { + case AxisDirection.up: + case AxisDirection.left: + rightWayUp = false; + case AxisDirection.down: + case AxisDirection.right: + rightWayUp = true; + } + switch (constraints.growthDirection) { + case GrowthDirection.forward: + break; + case GrowthDirection.reverse: + rightWayUp = !rightWayUp; + } + return rightWayUp; + } + + /// Utility function for [hitTestChildren] for use when the children are + /// [RenderBox] widgets. + /// + /// This function takes care of converting the position from the sliver + /// coordinate system to the Cartesian coordinate system used by [RenderBox]. + /// + /// This function relies on [childMainAxisPosition] to determine the position of + /// child in question. + /// + /// Calling this for a child that is not visible is not valid. + @protected + bool hitTestBoxChild(BoxHitTestResult result, RenderBox child, { required double mainAxisPosition, required double crossAxisPosition }) { + final bool rightWayUp = _getRightWayUp(constraints); + double delta = childMainAxisPosition(child); + final double crossAxisDelta = childCrossAxisPosition(child); + double absolutePosition = mainAxisPosition - delta; + final double absoluteCrossAxisPosition = crossAxisPosition - crossAxisDelta; + Offset paintOffset, transformedPosition; + switch (constraints.axis) { + case Axis.horizontal: + if (!rightWayUp) { + absolutePosition = child.size.width - absolutePosition; + delta = geometry!.paintExtent - child.size.width - delta; + } + paintOffset = Offset(delta, crossAxisDelta); + transformedPosition = Offset(absolutePosition, absoluteCrossAxisPosition); + case Axis.vertical: + if (!rightWayUp) { + absolutePosition = child.size.height - absolutePosition; + delta = geometry!.paintExtent - child.size.height - delta; + } + paintOffset = Offset(crossAxisDelta, delta); + transformedPosition = Offset(absoluteCrossAxisPosition, absolutePosition); + } + return result.addWithOutOfBandPosition( + paintOffset: paintOffset, + hitTest: (BoxHitTestResult result) { + return child.hitTest(result, position: transformedPosition); + }, + ); + } + + /// Utility function for [applyPaintTransform] for use when the children are + /// [RenderBox] widgets. + /// + /// This function turns the value returned by [childMainAxisPosition] and + /// [childCrossAxisPosition]for the child in question into a translation that + /// it then applies to the given matrix. + /// + /// Calling this for a child that is not visible is not valid. + @protected + void applyPaintTransformForBoxChild(RenderBox child, Matrix4 transform) { + final bool rightWayUp = _getRightWayUp(constraints); + double delta = childMainAxisPosition(child); + final double crossAxisDelta = childCrossAxisPosition(child); + switch (constraints.axis) { + case Axis.horizontal: + if (!rightWayUp) { + delta = geometry!.paintExtent - child.size.width - delta; + } + transform.translate(delta, crossAxisDelta); + case Axis.vertical: + if (!rightWayUp) { + delta = geometry!.paintExtent - child.size.height - delta; + } + transform.translate(crossAxisDelta, delta); + } + } +} + +// ADAPTER FOR RENDER BOXES INSIDE SLIVERS +// Transitions from the RenderSliver world to the RenderBox world. + +/// An abstract class for [RenderSliver]s that contains a single [RenderBox]. +/// +/// See also: +/// +/// * [RenderSliver], which explains more about the Sliver protocol. +/// * [RenderBox], which explains more about the Box protocol. +/// * [RenderSliverToBoxAdapter], which extends this class to size the child +/// according to its preferred size. +/// * [RenderSliverFillRemaining], which extends this class to size the child +/// to fill the remaining space in the viewport. +abstract class RenderSliverSingleBoxAdapter extends RenderSliver with RenderObjectWithChildMixin<RenderBox>, RenderSliverHelpers { + /// Creates a [RenderSliver] that wraps a [RenderBox]. + RenderSliverSingleBoxAdapter({ + RenderBox? child, + }) { + this.child = child; + } + + @override + void setupParentData(RenderObject child) { + if (child.parentData is! SliverPhysicalParentData) { + child.parentData = SliverPhysicalParentData(); + } + } + + /// Sets the [SliverPhysicalParentData.paintOffset] for the given child + /// according to the [SliverConstraints.axisDirection] and + /// [SliverConstraints.growthDirection] and the given geometry. + @protected + void setChildParentData(RenderObject child, SliverConstraints constraints, SliverGeometry geometry) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) { + case AxisDirection.up: + childParentData.paintOffset = Offset(0.0, -(geometry.scrollExtent - (geometry.paintExtent + constraints.scrollOffset))); + case AxisDirection.right: + childParentData.paintOffset = Offset(-constraints.scrollOffset, 0.0); + case AxisDirection.down: + childParentData.paintOffset = Offset(0.0, -constraints.scrollOffset); + case AxisDirection.left: + childParentData.paintOffset = Offset(-(geometry.scrollExtent - (geometry.paintExtent + constraints.scrollOffset)), 0.0); + } + } + + @override + bool hitTestChildren(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }) { + assert(geometry!.hitTestExtent > 0.0); + if (child != null) { + return hitTestBoxChild(BoxHitTestResult.wrap(result), child!, mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition); + } + return false; + } + + @override + double childMainAxisPosition(RenderBox child) { + return -constraints.scrollOffset; + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + assert(child == this.child); + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + childParentData.applyPaintTransform(transform); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null && geometry!.visible) { + final SliverPhysicalParentData childParentData = child!.parentData! as SliverPhysicalParentData; + context.paintChild(child!, offset + childParentData.paintOffset); + } + } +} + +/// A [RenderSliver] that contains a single [RenderBox]. +/// +/// The child will not be laid out if it is not visible. It is sized according +/// to the child's preferences in the main axis, and with a tight constraint +/// forcing it to the dimensions of the viewport in the cross axis. +/// +/// See also: +/// +/// * [RenderSliver], which explains more about the Sliver protocol. +/// * [RenderBox], which explains more about the Box protocol. +/// * [RenderViewport], which allows [RenderSliver] objects to be placed inside +/// a [RenderBox] (the opposite of this class). +class RenderSliverToBoxAdapter extends RenderSliverSingleBoxAdapter { + /// Creates a [RenderSliver] that wraps a [RenderBox]. + RenderSliverToBoxAdapter({ + super.child, + }); + + @override + void performLayout() { + if (child == null) { + geometry = SliverGeometry.zero; + return; + } + final SliverConstraints constraints = this.constraints; + child!.layout(constraints.asBoxConstraints(), parentUsesSize: true); + final double childExtent; + switch (constraints.axis) { + case Axis.horizontal: + childExtent = child!.size.width; + case Axis.vertical: + childExtent = child!.size.height; + } + final double paintedChildSize = calculatePaintOffset(constraints, from: 0.0, to: childExtent); + final double cacheExtent = calculateCacheOffset(constraints, from: 0.0, to: childExtent); + + assert(paintedChildSize.isFinite); + assert(paintedChildSize >= 0.0); + geometry = SliverGeometry( + scrollExtent: childExtent, + paintExtent: paintedChildSize, + cacheExtent: cacheExtent, + maxPaintExtent: childExtent, + hitTestExtent: paintedChildSize, + hasVisualOverflow: childExtent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0, + ); + setChildParentData(child!, constraints, geometry!); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_fill.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_fill.dart new file mode 100644 index 0000000000000000000000000000000000000000..b5f2763ca07780fe6308cbbf7df3a0354309a2fc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_fill.dart @@ -0,0 +1,254 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'box.dart'; +import 'object.dart'; +import 'sliver.dart'; +import 'sliver_fixed_extent_list.dart'; + +/// A sliver that contains multiple box children that each fill the viewport. +/// +/// [RenderSliverFillViewport] places its children in a linear array along the +/// main axis. Each child is sized to fill the viewport, both in the main and +/// cross axis. A [viewportFraction] factor can be provided to size the children +/// to a multiple of the viewport's main axis dimension (typically a fraction +/// less than 1.0). +/// +/// See also: +/// +/// * [RenderSliverFillRemaining], which sizes the children based on the +/// remaining space rather than the viewport itself. +/// * [RenderSliverFixedExtentList], which has a configurable [itemExtent]. +/// * [RenderSliverList], which does not require its children to have the same +/// extent in the main axis. +class RenderSliverFillViewport extends RenderSliverFixedExtentBoxAdaptor { + /// Creates a sliver that contains multiple box children that each fill the + /// viewport. + RenderSliverFillViewport({ + required super.childManager, + double viewportFraction = 1.0, + }) : assert(viewportFraction > 0.0), + _viewportFraction = viewportFraction; + + @override + double get itemExtent => constraints.viewportMainAxisExtent * viewportFraction; + + /// The fraction of the viewport that each child should fill in the main axis. + /// + /// If this fraction is less than 1.0, more than one child will be visible at + /// once. If this fraction is greater than 1.0, each child will be larger than + /// the viewport in the main axis. + double get viewportFraction => _viewportFraction; + double _viewportFraction; + set viewportFraction(double value) { + if (_viewportFraction == value) { + return; + } + _viewportFraction = value; + markNeedsLayout(); + } +} + +/// A sliver that contains a single box child that contains a scrollable and +/// fills the viewport. +/// +/// [RenderSliverFillRemainingWithScrollable] sizes its child to fill the +/// viewport in the cross axis and to fill the remaining space in the viewport +/// in the main axis. +/// +/// Typically this will be the last sliver in a viewport, since (by definition) +/// there is never any room for anything beyond this sliver. +/// +/// See also: +/// +/// * [NestedScrollView], which uses this sliver for the inner scrollable. +/// * [RenderSliverFillRemaining], which lays out its +/// non-scrollable child slightly different than this widget. +/// * [RenderSliverFillRemainingAndOverscroll], which incorporates the +/// overscroll into the remaining space to fill. +/// * [RenderSliverFillViewport], which sizes its children based on the +/// size of the viewport, regardless of what else is in the scroll view. +/// * [RenderSliverList], which shows a list of variable-sized children in a +/// viewport. +class RenderSliverFillRemainingWithScrollable extends RenderSliverSingleBoxAdapter { + /// Creates a [RenderSliver] that wraps a scrollable [RenderBox] which is + /// sized to fit the remaining space in the viewport. + RenderSliverFillRemainingWithScrollable({ super.child }); + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + final double extent = constraints.remainingPaintExtent - math.min(constraints.overlap, 0.0); + + if (child != null) { + child!.layout(constraints.asBoxConstraints( + minExtent: extent, + maxExtent: extent, + )); + } + + final double paintedChildSize = calculatePaintOffset(constraints, from: 0.0, to: extent); + assert(paintedChildSize.isFinite); + assert(paintedChildSize >= 0.0); + geometry = SliverGeometry( + scrollExtent: constraints.viewportMainAxisExtent, + paintExtent: paintedChildSize, + maxPaintExtent: paintedChildSize, + hasVisualOverflow: extent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0, + ); + if (child != null) { + setChildParentData(child!, constraints, geometry!); + } + } +} + +/// A sliver that contains a single box child that is non-scrollable and fills +/// the remaining space in the viewport. +/// +/// [RenderSliverFillRemaining] sizes its child to fill the +/// viewport in the cross axis and to fill the remaining space in the viewport +/// in the main axis. +/// +/// Typically this will be the last sliver in a viewport, since (by definition) +/// there is never any room for anything beyond this sliver. +/// +/// See also: +/// +/// * [RenderSliverFillRemainingWithScrollable], which lays out its scrollable +/// child slightly different than this widget. +/// * [RenderSliverFillRemainingAndOverscroll], which incorporates the +/// overscroll into the remaining space to fill. +/// * [RenderSliverFillViewport], which sizes its children based on the +/// size of the viewport, regardless of what else is in the scroll view. +/// * [RenderSliverList], which shows a list of variable-sized children in a +/// viewport. +class RenderSliverFillRemaining extends RenderSliverSingleBoxAdapter { + /// Creates a [RenderSliver] that wraps a non-scrollable [RenderBox] which is + /// sized to fit the remaining space in the viewport. + RenderSliverFillRemaining({ super.child }); + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + // The remaining space in the viewportMainAxisExtent. Can be <= 0 if we have + // scrolled beyond the extent of the screen. + double extent = constraints.viewportMainAxisExtent - constraints.precedingScrollExtent; + + if (child != null) { + final double childExtent; + switch (constraints.axis) { + case Axis.horizontal: + childExtent = child!.getMaxIntrinsicWidth(constraints.crossAxisExtent); + case Axis.vertical: + childExtent = child!.getMaxIntrinsicHeight(constraints.crossAxisExtent); + } + + // If the childExtent is greater than the computed extent, we want to use + // that instead of potentially cutting off the child. This allows us to + // safely specify a maxExtent. + extent = math.max(extent, childExtent); + child!.layout(constraints.asBoxConstraints( + minExtent: extent, + maxExtent: extent, + )); + } + + assert(extent.isFinite, + 'The calculated extent for the child of SliverFillRemaining is not finite. ' + 'This can happen if the child is a scrollable, in which case, the ' + 'hasScrollBody property of SliverFillRemaining should not be set to ' + 'false.', + ); + final double paintedChildSize = calculatePaintOffset(constraints, from: 0.0, to: extent); + assert(paintedChildSize.isFinite); + assert(paintedChildSize >= 0.0); + geometry = SliverGeometry( + scrollExtent: extent, + paintExtent: paintedChildSize, + maxPaintExtent: paintedChildSize, + hasVisualOverflow: extent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0, + ); + if (child != null) { + setChildParentData(child!, constraints, geometry!); + } + } +} + +/// A sliver that contains a single box child that is non-scrollable and fills +/// the remaining space in the viewport including any overscrolled area. +/// +/// [RenderSliverFillRemainingAndOverscroll] sizes its child to fill the +/// viewport in the cross axis and to fill the remaining space in the viewport +/// in the main axis with the overscroll area included. +/// +/// Typically this will be the last sliver in a viewport, since (by definition) +/// there is never any room for anything beyond this sliver. +/// +/// See also: +/// +/// * [RenderSliverFillRemainingWithScrollable], which lays out its scrollable +/// child without overscroll. +/// * [RenderSliverFillRemaining], which lays out its +/// non-scrollable child without overscroll. +/// * [RenderSliverFillViewport], which sizes its children based on the +/// size of the viewport, regardless of what else is in the scroll view. +/// * [RenderSliverList], which shows a list of variable-sized children in a +/// viewport. +class RenderSliverFillRemainingAndOverscroll extends RenderSliverSingleBoxAdapter { + /// Creates a [RenderSliver] that wraps a non-scrollable [RenderBox] which is + /// sized to fit the remaining space plus any overscroll in the viewport. + RenderSliverFillRemainingAndOverscroll({ super.child }); + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + // The remaining space in the viewportMainAxisExtent. Can be <= 0 if we have + // scrolled beyond the extent of the screen. + double extent = constraints.viewportMainAxisExtent - constraints.precedingScrollExtent; + // The maxExtent includes any overscrolled area. Can be < 0 if we have + // overscroll in the opposite direction, away from the end of the list. + double maxExtent = constraints.remainingPaintExtent - math.min(constraints.overlap, 0.0); + + if (child != null) { + final double childExtent; + switch (constraints.axis) { + case Axis.horizontal: + childExtent = child!.getMaxIntrinsicWidth(constraints.crossAxisExtent); + case Axis.vertical: + childExtent = child!.getMaxIntrinsicHeight(constraints.crossAxisExtent); + } + + // If the childExtent is greater than the computed extent, we want to use + // that instead of potentially cutting off the child. This allows us to + // safely specify a maxExtent. + extent = math.max(extent, childExtent); + // The extent could be larger than the maxExtent due to a larger child + // size or overscrolling at the top of the scrollable (rather than at the + // end where this sliver is). + maxExtent = math.max(extent, maxExtent); + child!.layout(constraints.asBoxConstraints(minExtent: extent, maxExtent: maxExtent)); + } + + assert(extent.isFinite, + 'The calculated extent for the child of SliverFillRemaining is not finite. ' + 'This can happen if the child is a scrollable, in which case, the ' + 'hasScrollBody property of SliverFillRemaining should not be set to ' + 'false.', + ); + final double paintedChildSize = calculatePaintOffset(constraints, from: 0.0, to: extent); + assert(paintedChildSize.isFinite); + assert(paintedChildSize >= 0.0); + geometry = SliverGeometry( + scrollExtent: extent, + paintExtent: math.min(maxExtent, constraints.remainingPaintExtent), + maxPaintExtent: maxExtent, + hasVisualOverflow: extent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0, + ); + if (child != null) { + setChildParentData(child!, constraints, geometry!); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_fixed_extent_list.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_fixed_extent_list.dart new file mode 100644 index 0000000000000000000000000000000000000000..5b775f779abbeffcfbffc473e34fa9c1a51253e5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_fixed_extent_list.dart @@ -0,0 +1,427 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'sliver.dart'; +import 'sliver_multi_box_adaptor.dart'; + +/// A sliver that contains multiple box children that have the explicit extent in +/// the main axis. +/// +/// [RenderSliverFixedExtentBoxAdaptor] places its children in a linear array +/// along the main axis. Each child is forced to have the returned value of [itemExtentBuilder] +/// when the [itemExtentBuilder] is non-null or the [itemExtent] when [itemExtentBuilder] +/// is null in the main axis and the [SliverConstraints.crossAxisExtent] in the cross axis. +/// +/// Subclasses should override [itemExtent] or [itemExtentBuilder] to control +/// the size of the children in the main axis. For a concrete subclass with a +/// configurable [itemExtent], see [RenderSliverFixedExtentList] or [RenderSliverVariedExtentList]. +/// +/// [RenderSliverFixedExtentBoxAdaptor] is more efficient than +/// [RenderSliverList] because [RenderSliverFixedExtentBoxAdaptor] does not need +/// to perform layout on its children to obtain their extent in the main axis. +/// +/// See also: +/// +/// * [RenderSliverFixedExtentList], which has a configurable [itemExtent]. +/// * [RenderSliverFillViewport], which determines the [itemExtent] based on +/// [SliverConstraints.viewportMainAxisExtent]. +/// * [RenderSliverFillRemaining], which determines the [itemExtent] based on +/// [SliverConstraints.remainingPaintExtent]. +/// * [RenderSliverList], which does not require its children to have the same +/// extent in the main axis. +abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAdaptor { + /// Creates a sliver that contains multiple box children that have the same + /// extent in the main axis. + RenderSliverFixedExtentBoxAdaptor({ + required super.childManager, + }); + + /// The main-axis extent of each item. + /// + /// If this is non-null, the [itemExtentBuilder] must be null. + /// If this is null, the [itemExtentBuilder] must be non-null. + double? get itemExtent; + + /// The main-axis extent builder of each item. + /// + /// If this is non-null, the [itemExtent] must be null. + /// If this is null, the [itemExtent] must be non-null. + ItemExtentBuilder? get itemExtentBuilder => null; + + /// The layout offset for the child with the given index. + /// + /// This function uses the returned value of [itemExtentBuilder] or the [itemExtent] + /// as an argument to avoid recomputing item size repeatedly during layout. + /// + /// By default, places the children in order, without gaps, starting from + /// layout offset zero. + @protected + double indexToLayoutOffset(double itemExtent, int index) { + if (itemExtentBuilder == null) { + return itemExtent * index; + } else { + double offset = 0.0; + for (int i = 0; i < index; i++) { + offset += itemExtentBuilder!(i, _currentLayoutDimensions); + } + return offset; + } + } + + /// The minimum child index that is visible at the given scroll offset. + /// + /// This function uses the returned value of [itemExtentBuilder] or the [itemExtent] + /// as an argument to avoid recomputing item size repeatedly during layout. + /// + /// By default, returns a value consistent with the children being placed in + /// order, without gaps, starting from layout offset zero. + @protected + int getMinChildIndexForScrollOffset(double scrollOffset, double itemExtent) { + if (itemExtentBuilder == null) { + if (itemExtent > 0.0) { + final double actual = scrollOffset / itemExtent; + final int round = actual.round(); + if ((actual * itemExtent - round * itemExtent).abs() < precisionErrorTolerance) { + return round; + } + return actual.floor(); + } + return 0; + } else { + return _getChildIndexForScrollOffset(scrollOffset, itemExtentBuilder!); + } + } + + /// The maximum child index that is visible at the given scroll offset. + /// + /// This function uses the returned value of [itemExtentBuilder] or the [itemExtent] + /// as an argument to avoid recomputing item size repeatedly during layout. + /// + /// By default, returns a value consistent with the children being placed in + /// order, without gaps, starting from layout offset zero. + @protected + int getMaxChildIndexForScrollOffset(double scrollOffset, double itemExtent) { + if (itemExtentBuilder == null) { + if (itemExtent > 0.0) { + final double actual = scrollOffset / itemExtent - 1; + final int round = actual.round(); + if ((actual * itemExtent - round * itemExtent).abs() < precisionErrorTolerance) { + return math.max(0, round); + } + return math.max(0, actual.ceil()); + } + return 0; + } else { + return _getChildIndexForScrollOffset(scrollOffset, itemExtentBuilder!); + } + } + + /// Called to estimate the total scrollable extents of this object. + /// + /// Must return the total distance from the start of the child with the + /// earliest possible index to the end of the child with the last possible + /// index. + /// + /// By default, defers to [RenderSliverBoxChildManager.estimateMaxScrollOffset]. + /// + /// See also: + /// + /// * [computeMaxScrollOffset], which is similar but must provide a precise + /// value. + @protected + double estimateMaxScrollOffset( + SliverConstraints constraints, { + int? firstIndex, + int? lastIndex, + double? leadingScrollOffset, + double? trailingScrollOffset, + }) { + return childManager.estimateMaxScrollOffset( + constraints, + firstIndex: firstIndex, + lastIndex: lastIndex, + leadingScrollOffset: leadingScrollOffset, + trailingScrollOffset: trailingScrollOffset, + ); + } + + /// Called to obtain a precise measure of the total scrollable extents of this + /// object. + /// + /// Must return the precise total distance from the start of the child with + /// the earliest possible index to the end of the child with the last possible + /// index. + /// + /// This is used when no child is available for the index corresponding to the + /// current scroll offset, to determine the precise dimensions of the sliver. + /// It must return a precise value. It will not be called if the + /// [childManager] returns an infinite number of children for positive + /// indices. + /// + /// If [itemExtentBuilder] is null, multiplies the [itemExtent] by the number + /// of children reported by [RenderSliverBoxChildManager.childCount]. + /// If [itemExtentBuilder] is non-null, sum the extents of the first + /// [RenderSliverBoxChildManager.childCount] children. + /// + /// See also: + /// + /// * [estimateMaxScrollOffset], which is similar but may provide inaccurate + /// values. + @protected + double computeMaxScrollOffset(SliverConstraints constraints, double itemExtent) { + if (itemExtentBuilder == null) { + return childManager.childCount * itemExtent; + } else { + double offset = 0.0; + for (int i = 0; i < childManager.childCount; i++) { + offset += itemExtentBuilder!(i, _currentLayoutDimensions); + } + return offset; + } + } + + int _calculateLeadingGarbage(int firstIndex) { + RenderBox? walker = firstChild; + int leadingGarbage = 0; + while (walker != null && indexOf(walker) < firstIndex) { + leadingGarbage += 1; + walker = childAfter(walker); + } + return leadingGarbage; + } + + int _calculateTrailingGarbage(int targetLastIndex) { + RenderBox? walker = lastChild; + int trailingGarbage = 0; + while (walker != null && indexOf(walker) > targetLastIndex) { + trailingGarbage += 1; + walker = childBefore(walker); + } + return trailingGarbage; + } + + int _getChildIndexForScrollOffset(double scrollOffset, ItemExtentBuilder callback) { + if (scrollOffset == 0.0) { + return 0; + } + double position = 0.0; + int index = 0; + while (position < scrollOffset) { + position += callback(index, _currentLayoutDimensions); + ++index; + } + return index - 1; + } + + BoxConstraints _getChildConstraints(int index) { + double extent; + if (itemExtentBuilder == null) { + extent = itemExtent!; + } else { + extent = itemExtentBuilder!(index, _currentLayoutDimensions); + } + return constraints.asBoxConstraints( + minExtent: extent, + maxExtent: extent, + ); + } + + late SliverLayoutDimensions _currentLayoutDimensions; + + @override + void performLayout() { + assert((itemExtent != null && itemExtentBuilder == null) || + (itemExtent == null && itemExtentBuilder != null)); + assert(itemExtentBuilder != null || (itemExtent!.isFinite && itemExtent! >= 0)); + + final SliverConstraints constraints = this.constraints; + childManager.didStartLayout(); + childManager.setDidUnderflow(false); + + final double itemFixedExtent = itemExtent ?? 0; + final double scrollOffset = constraints.scrollOffset + constraints.cacheOrigin; + assert(scrollOffset >= 0.0); + final double remainingExtent = constraints.remainingCacheExtent; + assert(remainingExtent >= 0.0); + final double targetEndScrollOffset = scrollOffset + remainingExtent; + + _currentLayoutDimensions = SliverLayoutDimensions( + scrollOffset: constraints.scrollOffset, + precedingScrollExtent: constraints.precedingScrollExtent, + viewportMainAxisExtent: constraints.viewportMainAxisExtent, + crossAxisExtent: constraints.crossAxisExtent + ); + + final int firstIndex = getMinChildIndexForScrollOffset(scrollOffset, itemFixedExtent); + final int? targetLastIndex = targetEndScrollOffset.isFinite ? + getMaxChildIndexForScrollOffset(targetEndScrollOffset, itemFixedExtent) : null; + + if (firstChild != null) { + final int leadingGarbage = _calculateLeadingGarbage(firstIndex); + final int trailingGarbage = targetLastIndex != null ? _calculateTrailingGarbage(targetLastIndex) : 0; + collectGarbage(leadingGarbage, trailingGarbage); + } else { + collectGarbage(0, 0); + } + + if (firstChild == null) { + if (!addInitialChild(index: firstIndex, layoutOffset: indexToLayoutOffset(itemFixedExtent, firstIndex))) { + // There are either no children, or we are past the end of all our children. + final double max; + if (firstIndex <= 0) { + max = 0.0; + } else { + max = computeMaxScrollOffset(constraints, itemFixedExtent); + } + geometry = SliverGeometry( + scrollExtent: max, + maxPaintExtent: max, + ); + childManager.didFinishLayout(); + return; + } + } + + RenderBox? trailingChildWithLayout; + + for (int index = indexOf(firstChild!) - 1; index >= firstIndex; --index) { + final RenderBox? child = insertAndLayoutLeadingChild(_getChildConstraints(index)); + if (child == null) { + // Items before the previously first child are no longer present. + // Reset the scroll offset to offset all items prior and up to the + // missing item. Let parent re-layout everything. + geometry = SliverGeometry(scrollOffsetCorrection: indexToLayoutOffset(itemFixedExtent, index)); + return; + } + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + childParentData.layoutOffset = indexToLayoutOffset(itemFixedExtent, index); + assert(childParentData.index == index); + trailingChildWithLayout ??= child; + } + + if (trailingChildWithLayout == null) { + firstChild!.layout(_getChildConstraints(indexOf(firstChild!))); + final SliverMultiBoxAdaptorParentData childParentData = firstChild!.parentData! as SliverMultiBoxAdaptorParentData; + childParentData.layoutOffset = indexToLayoutOffset(itemFixedExtent, firstIndex); + trailingChildWithLayout = firstChild; + } + + double estimatedMaxScrollOffset = double.infinity; + for (int index = indexOf(trailingChildWithLayout!) + 1; targetLastIndex == null || index <= targetLastIndex; ++index) { + RenderBox? child = childAfter(trailingChildWithLayout!); + if (child == null || indexOf(child) != index) { + child = insertAndLayoutChild(_getChildConstraints(index), after: trailingChildWithLayout); + if (child == null) { + // We have run out of children. + estimatedMaxScrollOffset = indexToLayoutOffset(itemFixedExtent, index); + break; + } + } else { + child.layout(_getChildConstraints(index)); + } + trailingChildWithLayout = child; + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + assert(childParentData.index == index); + childParentData.layoutOffset = indexToLayoutOffset(itemFixedExtent, childParentData.index!); + } + + final int lastIndex = indexOf(lastChild!); + final double leadingScrollOffset = indexToLayoutOffset(itemFixedExtent, firstIndex); + final double trailingScrollOffset = indexToLayoutOffset(itemFixedExtent, lastIndex + 1); + + assert(firstIndex == 0 || childScrollOffset(firstChild!)! - scrollOffset <= precisionErrorTolerance); + assert(debugAssertChildListIsNonEmptyAndContiguous()); + assert(indexOf(firstChild!) == firstIndex); + assert(targetLastIndex == null || lastIndex <= targetLastIndex); + + estimatedMaxScrollOffset = math.min( + estimatedMaxScrollOffset, + estimateMaxScrollOffset( + constraints, + firstIndex: firstIndex, + lastIndex: lastIndex, + leadingScrollOffset: leadingScrollOffset, + trailingScrollOffset: trailingScrollOffset, + ), + ); + + final double paintExtent = calculatePaintOffset( + constraints, + from: leadingScrollOffset, + to: trailingScrollOffset, + ); + + final double cacheExtent = calculateCacheOffset( + constraints, + from: leadingScrollOffset, + to: trailingScrollOffset, + ); + + final double targetEndScrollOffsetForPaint = constraints.scrollOffset + constraints.remainingPaintExtent; + final int? targetLastIndexForPaint = targetEndScrollOffsetForPaint.isFinite ? + getMaxChildIndexForScrollOffset(targetEndScrollOffsetForPaint, itemFixedExtent) : null; + + geometry = SliverGeometry( + scrollExtent: estimatedMaxScrollOffset, + paintExtent: paintExtent, + cacheExtent: cacheExtent, + maxPaintExtent: estimatedMaxScrollOffset, + // Conservative to avoid flickering away the clip during scroll. + hasVisualOverflow: (targetLastIndexForPaint != null && lastIndex >= targetLastIndexForPaint) + || constraints.scrollOffset > 0.0, + ); + + // We may have started the layout while scrolled to the end, which would not + // expose a new child. + if (estimatedMaxScrollOffset == trailingScrollOffset) { + childManager.setDidUnderflow(true); + } + childManager.didFinishLayout(); + } +} + +/// A sliver that places multiple box children with the same main axis extent in +/// a linear array. +/// +/// [RenderSliverFixedExtentList] places its children in a linear array along +/// the main axis starting at offset zero and without gaps. Each child is forced +/// to have the [itemExtent] in the main axis and the +/// [SliverConstraints.crossAxisExtent] in the cross axis. +/// +/// [RenderSliverFixedExtentList] is more efficient than [RenderSliverList] +/// because [RenderSliverFixedExtentList] does not need to perform layout on its +/// children to obtain their extent in the main axis. +/// +/// See also: +/// +/// * [RenderSliverList], which does not require its children to have the same +/// extent in the main axis. +/// * [RenderSliverFillViewport], which determines the [itemExtent] based on +/// [SliverConstraints.viewportMainAxisExtent]. +/// * [RenderSliverFillRemaining], which determines the [itemExtent] based on +/// [SliverConstraints.remainingPaintExtent]. +class RenderSliverFixedExtentList extends RenderSliverFixedExtentBoxAdaptor { + /// Creates a sliver that contains multiple box children that have a given + /// extent in the main axis. + RenderSliverFixedExtentList({ + required super.childManager, + required double itemExtent, + }) : _itemExtent = itemExtent; + + @override + double get itemExtent => _itemExtent; + double _itemExtent; + set itemExtent(double value) { + if (_itemExtent == value) { + return; + } + _itemExtent = value; + markNeedsLayout(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_grid.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_grid.dart new file mode 100644 index 0000000000000000000000000000000000000000..524dd70e4d80b90be8424d5c2705cd4d66003781 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_grid.dart @@ -0,0 +1,731 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'object.dart'; +import 'sliver.dart'; +import 'sliver_multi_box_adaptor.dart'; + +/// Describes the placement of a child in a [RenderSliverGrid]. +/// +/// This class is similar to [Rect], in that it gives a two-dimensional position +/// and a two-dimensional dimension, but is direction-agnostic. +/// +/// {@tool dartpad} +/// This example shows how a custom [SliverGridLayout] uses [SliverGridGeometry] +/// to lay out the children. +/// +/// ** See code in examples/api/lib/widgets/scroll_view/grid_view.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverGridLayout], which represents the geometry of all the tiles in a +/// grid. +/// * [SliverGridLayout.getGeometryForChildIndex], which returns this object +/// to describe the child's placement. +/// * [RenderSliverGrid], which uses this class during its +/// [RenderSliverGrid.performLayout] method. +@immutable +class SliverGridGeometry { + /// Creates an object that describes the placement of a child in a [RenderSliverGrid]. + const SliverGridGeometry({ + required this.scrollOffset, + required this.crossAxisOffset, + required this.mainAxisExtent, + required this.crossAxisExtent, + }); + + /// The scroll offset of the leading edge of the child relative to the leading + /// edge of the parent. + final double scrollOffset; + + /// The offset of the child in the non-scrolling axis. + /// + /// If the scroll axis is vertical, this offset is from the left-most edge of + /// the parent to the left-most edge of the child. If the scroll axis is + /// horizontal, this offset is from the top-most edge of the parent to the + /// top-most edge of the child. + final double crossAxisOffset; + + /// The extent of the child in the scrolling axis. + /// + /// If the scroll axis is vertical, this extent is the child's height. If the + /// scroll axis is horizontal, this extent is the child's width. + final double mainAxisExtent; + + /// The extent of the child in the non-scrolling axis. + /// + /// If the scroll axis is vertical, this extent is the child's width. If the + /// scroll axis is horizontal, this extent is the child's height. + final double crossAxisExtent; + + /// The scroll offset of the trailing edge of the child relative to the + /// leading edge of the parent. + double get trailingScrollOffset => scrollOffset + mainAxisExtent; + + /// Returns a tight [BoxConstraints] that forces the child to have the + /// required size, given a [SliverConstraints]. + BoxConstraints getBoxConstraints(SliverConstraints constraints) { + return constraints.asBoxConstraints( + minExtent: mainAxisExtent, + maxExtent: mainAxisExtent, + crossAxisExtent: crossAxisExtent, + ); + } + + @override + String toString() { + final List<String> properties = <String>[ + 'scrollOffset: $scrollOffset', + 'crossAxisOffset: $crossAxisOffset', + 'mainAxisExtent: $mainAxisExtent', + 'crossAxisExtent: $crossAxisExtent', + ]; + return 'SliverGridGeometry(${properties.join(', ')})'; + } +} + +/// The size and position of all the tiles in a [RenderSliverGrid]. +/// +/// Rather that providing a grid with a [SliverGridLayout] directly, the grid is +/// provided a [SliverGridDelegate], which computes a [SliverGridLayout] given a +/// set of [SliverConstraints]. This allows the algorithm to dynamically respond +/// to changes in the environment (e.g. the user rotating the device). +/// +/// The tiles can be placed arbitrarily, but it is more efficient to place tiles +/// roughly in order by scroll offset because grids reify a contiguous sequence +/// of children. +/// +/// {@tool dartpad} +/// This example shows how to construct a custom [SliverGridLayout] to lay tiles +/// in a grid form with some cells stretched to fit the entire width of the +/// grid (sometimes called "hero tiles"). +/// +/// ** See code in examples/api/lib/widgets/scroll_view/grid_view.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverGridRegularTileLayout], which represents a layout that uses +/// equally sized and spaced tiles. +/// * [SliverGridGeometry], which represents the size and position of a single +/// tile in a grid. +/// * [SliverGridDelegate.getLayout], which returns this object to describe the +/// delegate's layout. +/// * [RenderSliverGrid], which uses this class during its +/// [RenderSliverGrid.performLayout] method. +@immutable +abstract class SliverGridLayout { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const SliverGridLayout(); + + /// The minimum child index that intersects with (or is after) this scroll offset. + int getMinChildIndexForScrollOffset(double scrollOffset); + + /// The maximum child index that intersects with (or is before) this scroll offset. + int getMaxChildIndexForScrollOffset(double scrollOffset); + + /// The size and position of the child with the given index. + SliverGridGeometry getGeometryForChildIndex(int index); + + /// The scroll extent needed to fully display all the tiles if there are + /// `childCount` children in total. + /// + /// The child count will never be null. + double computeMaxScrollOffset(int childCount); +} + +/// A [SliverGridLayout] that uses equally sized and spaced tiles. +/// +/// Rather that providing a grid with a [SliverGridLayout] directly, you instead +/// provide the grid a [SliverGridDelegate], which can compute a +/// [SliverGridLayout] given the current [SliverConstraints]. +/// +/// This layout is used by [SliverGridDelegateWithFixedCrossAxisCount] and +/// [SliverGridDelegateWithMaxCrossAxisExtent]. +/// +/// See also: +/// +/// * [SliverGridDelegateWithFixedCrossAxisCount], which uses this layout. +/// * [SliverGridDelegateWithMaxCrossAxisExtent], which uses this layout. +/// * [SliverGridLayout], which represents an arbitrary tile layout. +/// * [SliverGridGeometry], which represents the size and position of a single +/// tile in a grid. +/// * [SliverGridDelegate.getLayout], which returns this object to describe the +/// delegate's layout. +/// * [RenderSliverGrid], which uses this class during its +/// [RenderSliverGrid.performLayout] method. +class SliverGridRegularTileLayout extends SliverGridLayout { + /// Creates a layout that uses equally sized and spaced tiles. + /// + /// All of the arguments must not be negative. The `crossAxisCount` argument + /// must be greater than zero. + const SliverGridRegularTileLayout({ + required this.crossAxisCount, + required this.mainAxisStride, + required this.crossAxisStride, + required this.childMainAxisExtent, + required this.childCrossAxisExtent, + required this.reverseCrossAxis, + }) : assert(crossAxisCount > 0), + assert(mainAxisStride >= 0), + assert(crossAxisStride >= 0), + assert(childMainAxisExtent >= 0), + assert(childCrossAxisExtent >= 0); + + /// The number of children in the cross axis. + final int crossAxisCount; + + /// The number of pixels from the leading edge of one tile to the leading edge + /// of the next tile in the main axis. + final double mainAxisStride; + + /// The number of pixels from the leading edge of one tile to the leading edge + /// of the next tile in the cross axis. + final double crossAxisStride; + + /// The number of pixels from the leading edge of one tile to the trailing + /// edge of the same tile in the main axis. + final double childMainAxisExtent; + + /// The number of pixels from the leading edge of one tile to the trailing + /// edge of the same tile in the cross axis. + final double childCrossAxisExtent; + + /// Whether the children should be placed in the opposite order of increasing + /// coordinates in the cross axis. + /// + /// For example, if the cross axis is horizontal, the children are placed from + /// left to right when [reverseCrossAxis] is false and from right to left when + /// [reverseCrossAxis] is true. + /// + /// Typically set to the return value of [axisDirectionIsReversed] applied to + /// the [SliverConstraints.crossAxisDirection]. + final bool reverseCrossAxis; + + @override + int getMinChildIndexForScrollOffset(double scrollOffset) { + return mainAxisStride > precisionErrorTolerance ? crossAxisCount * (scrollOffset ~/ mainAxisStride) : 0; + } + + @override + int getMaxChildIndexForScrollOffset(double scrollOffset) { + if (mainAxisStride > 0.0) { + final int mainAxisCount = (scrollOffset / mainAxisStride).ceil(); + return math.max(0, crossAxisCount * mainAxisCount - 1); + } + return 0; + } + + double _getOffsetFromStartInCrossAxis(double crossAxisStart) { + if (reverseCrossAxis) { + return crossAxisCount * crossAxisStride - crossAxisStart - childCrossAxisExtent - (crossAxisStride - childCrossAxisExtent); + } + return crossAxisStart; + } + + @override + SliverGridGeometry getGeometryForChildIndex(int index) { + final double crossAxisStart = (index % crossAxisCount) * crossAxisStride; + return SliverGridGeometry( + scrollOffset: (index ~/ crossAxisCount) * mainAxisStride, + crossAxisOffset: _getOffsetFromStartInCrossAxis(crossAxisStart), + mainAxisExtent: childMainAxisExtent, + crossAxisExtent: childCrossAxisExtent, + ); + } + + @override + double computeMaxScrollOffset(int childCount) { + if (childCount == 0) { + // There are no children in the grid. The max scroll offset should be + // zero. + return 0.0; + } + final int mainAxisCount = ((childCount - 1) ~/ crossAxisCount) + 1; + final double mainAxisSpacing = mainAxisStride - childMainAxisExtent; + return mainAxisStride * mainAxisCount - mainAxisSpacing; + } +} + +/// Controls the layout of tiles in a grid. +/// +/// Given the current constraints on the grid, a [SliverGridDelegate] computes +/// the layout for the tiles in the grid. The tiles can be placed arbitrarily, +/// but it is more efficient to place tiles roughly in order by scroll offset +/// because grids reify a contiguous sequence of children. +/// +/// {@tool dartpad} +/// This example shows how a [SliverGridDelegate] returns a [SliverGridLayout] +/// configured based on the provided [SliverConstraints] in [getLayout]. +/// +/// ** See code in examples/api/lib/widgets/scroll_view/grid_view.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverGridDelegateWithFixedCrossAxisCount], which creates a layout with +/// a fixed number of tiles in the cross axis. +/// * [SliverGridDelegateWithMaxCrossAxisExtent], which creates a layout with +/// tiles that have a maximum cross-axis extent. +/// * [GridView], which uses this delegate to control the layout of its tiles. +/// * [SliverGrid], which uses this delegate to control the layout of its +/// tiles. +/// * [RenderSliverGrid], which uses this delegate to control the layout of its +/// tiles. +abstract class SliverGridDelegate { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const SliverGridDelegate(); + + /// Returns information about the size and position of the tiles in the grid. + SliverGridLayout getLayout(SliverConstraints constraints); + + /// Override this method to return true when the children need to be + /// laid out. + /// + /// This should compare the fields of the current delegate and the given + /// `oldDelegate` and return true if the fields are such that the layout would + /// be different. + bool shouldRelayout(covariant SliverGridDelegate oldDelegate); +} + +/// Creates grid layouts with a fixed number of tiles in the cross axis. +/// +/// For example, if the grid is vertical, this delegate will create a layout +/// with a fixed number of columns. If the grid is horizontal, this delegate +/// will create a layout with a fixed number of rows. +/// +/// This delegate creates grids with equally sized and spaced tiles. +/// +/// {@tool dartpad} +/// Here is an example using the [childAspectRatio] property. On a device with a +/// screen width of 800.0, it creates a GridView with each tile with a width of +/// 200.0 and a height of 100.0. +/// +/// ** See code in examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// Here is an example using the [mainAxisExtent] property. On a device with a +/// screen width of 800.0, it creates a GridView with each tile with a width of +/// 200.0 and a height of 150.0. +/// +/// ** See code in examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverGridDelegateWithMaxCrossAxisExtent], which creates a layout with +/// tiles that have a maximum cross-axis extent. +/// * [SliverGridDelegate], which creates arbitrary layouts. +/// * [GridView], which can use this delegate to control the layout of its +/// tiles. +/// * [SliverGrid], which can use this delegate to control the layout of its +/// tiles. +/// * [RenderSliverGrid], which can use this delegate to control the layout of +/// its tiles. +class SliverGridDelegateWithFixedCrossAxisCount extends SliverGridDelegate { + /// Creates a delegate that makes grid layouts with a fixed number of tiles in + /// the cross axis. + /// + /// The `mainAxisSpacing`, `mainAxisExtent` and `crossAxisSpacing` arguments + /// must not be negative. The `crossAxisCount` and `childAspectRatio` + /// arguments must be greater than zero. + const SliverGridDelegateWithFixedCrossAxisCount({ + required this.crossAxisCount, + this.mainAxisSpacing = 0.0, + this.crossAxisSpacing = 0.0, + this.childAspectRatio = 1.0, + this.mainAxisExtent, + }) : assert(crossAxisCount > 0), + assert(mainAxisSpacing >= 0), + assert(crossAxisSpacing >= 0), + assert(childAspectRatio > 0); + + /// The number of children in the cross axis. + final int crossAxisCount; + + /// The number of logical pixels between each child along the main axis. + final double mainAxisSpacing; + + /// The number of logical pixels between each child along the cross axis. + final double crossAxisSpacing; + + /// The ratio of the cross-axis to the main-axis extent of each child. + final double childAspectRatio; + + /// The extent of each tile in the main axis. If provided it would define the + /// logical pixels taken by each tile in the main-axis. + /// + /// If null, [childAspectRatio] is used instead. + final double? mainAxisExtent; + + bool _debugAssertIsValid() { + assert(crossAxisCount > 0); + assert(mainAxisSpacing >= 0.0); + assert(crossAxisSpacing >= 0.0); + assert(childAspectRatio > 0.0); + return true; + } + + @override + SliverGridLayout getLayout(SliverConstraints constraints) { + assert(_debugAssertIsValid()); + final double usableCrossAxisExtent = math.max( + 0.0, + constraints.crossAxisExtent - crossAxisSpacing * (crossAxisCount - 1), + ); + final double childCrossAxisExtent = usableCrossAxisExtent / crossAxisCount; + final double childMainAxisExtent = mainAxisExtent ?? childCrossAxisExtent / childAspectRatio; + return SliverGridRegularTileLayout( + crossAxisCount: crossAxisCount, + mainAxisStride: childMainAxisExtent + mainAxisSpacing, + crossAxisStride: childCrossAxisExtent + crossAxisSpacing, + childMainAxisExtent: childMainAxisExtent, + childCrossAxisExtent: childCrossAxisExtent, + reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), + ); + } + + @override + bool shouldRelayout(SliverGridDelegateWithFixedCrossAxisCount oldDelegate) { + return oldDelegate.crossAxisCount != crossAxisCount + || oldDelegate.mainAxisSpacing != mainAxisSpacing + || oldDelegate.crossAxisSpacing != crossAxisSpacing + || oldDelegate.childAspectRatio != childAspectRatio + || oldDelegate.mainAxisExtent != mainAxisExtent; + } +} + +/// Creates grid layouts with tiles that each have a maximum cross-axis extent. +/// +/// This delegate will select a cross-axis extent for the tiles that is as +/// large as possible subject to the following conditions: +/// +/// - The extent evenly divides the cross-axis extent of the grid. +/// - The extent is at most [maxCrossAxisExtent]. +/// +/// For example, if the grid is vertical, the grid is 500.0 pixels wide, and +/// [maxCrossAxisExtent] is 150.0, this delegate will create a grid with 4 +/// columns that are 125.0 pixels wide. +/// +/// This delegate creates grids with equally sized and spaced tiles. +/// +/// See also: +/// +/// * [SliverGridDelegateWithFixedCrossAxisCount], which creates a layout with +/// a fixed number of tiles in the cross axis. +/// * [SliverGridDelegate], which creates arbitrary layouts. +/// * [GridView], which can use this delegate to control the layout of its +/// tiles. +/// * [SliverGrid], which can use this delegate to control the layout of its +/// tiles. +/// * [RenderSliverGrid], which can use this delegate to control the layout of +/// its tiles. +class SliverGridDelegateWithMaxCrossAxisExtent extends SliverGridDelegate { + /// Creates a delegate that makes grid layouts with tiles that have a maximum + /// cross-axis extent. + /// + /// The [maxCrossAxisExtent], [mainAxisExtent], [mainAxisSpacing], + /// and [crossAxisSpacing] arguments must not be negative. + /// The [childAspectRatio] argument must be greater than zero. + const SliverGridDelegateWithMaxCrossAxisExtent({ + required this.maxCrossAxisExtent, + this.mainAxisSpacing = 0.0, + this.crossAxisSpacing = 0.0, + this.childAspectRatio = 1.0, + this.mainAxisExtent, + }) : assert(maxCrossAxisExtent > 0), + assert(mainAxisSpacing >= 0), + assert(crossAxisSpacing >= 0), + assert(childAspectRatio > 0); + + /// The maximum extent of tiles in the cross axis. + /// + /// This delegate will select a cross-axis extent for the tiles that is as + /// large as possible subject to the following conditions: + /// + /// - The extent evenly divides the cross-axis extent of the grid. + /// - The extent is at most [maxCrossAxisExtent]. + /// + /// For example, if the grid is vertical, the grid is 500.0 pixels wide, and + /// [maxCrossAxisExtent] is 150.0, this delegate will create a grid with 4 + /// columns that are 125.0 pixels wide. + final double maxCrossAxisExtent; + + /// The number of logical pixels between each child along the main axis. + final double mainAxisSpacing; + + /// The number of logical pixels between each child along the cross axis. + final double crossAxisSpacing; + + /// The ratio of the cross-axis to the main-axis extent of each child. + final double childAspectRatio; + + /// The extent of each tile in the main axis. If provided it would define the + /// logical pixels taken by each tile in the main-axis. + /// + /// If null, [childAspectRatio] is used instead. + final double? mainAxisExtent; + + bool _debugAssertIsValid(double crossAxisExtent) { + assert(crossAxisExtent > 0.0); + assert(maxCrossAxisExtent > 0.0); + assert(mainAxisSpacing >= 0.0); + assert(crossAxisSpacing >= 0.0); + assert(childAspectRatio > 0.0); + return true; + } + + @override + SliverGridLayout getLayout(SliverConstraints constraints) { + assert(_debugAssertIsValid(constraints.crossAxisExtent)); + int crossAxisCount = (constraints.crossAxisExtent / (maxCrossAxisExtent + crossAxisSpacing)).ceil(); + // Ensure a minimum count of 1, can be zero and result in an infinite extent + // below when the window size is 0. + crossAxisCount = math.max(1, crossAxisCount); + final double usableCrossAxisExtent = math.max( + 0.0, + constraints.crossAxisExtent - crossAxisSpacing * (crossAxisCount - 1), + ); + final double childCrossAxisExtent = usableCrossAxisExtent / crossAxisCount; + final double childMainAxisExtent = mainAxisExtent ?? childCrossAxisExtent / childAspectRatio; + return SliverGridRegularTileLayout( + crossAxisCount: crossAxisCount, + mainAxisStride: childMainAxisExtent + mainAxisSpacing, + crossAxisStride: childCrossAxisExtent + crossAxisSpacing, + childMainAxisExtent: childMainAxisExtent, + childCrossAxisExtent: childCrossAxisExtent, + reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), + ); + } + + @override + bool shouldRelayout(SliverGridDelegateWithMaxCrossAxisExtent oldDelegate) { + return oldDelegate.maxCrossAxisExtent != maxCrossAxisExtent + || oldDelegate.mainAxisSpacing != mainAxisSpacing + || oldDelegate.crossAxisSpacing != crossAxisSpacing + || oldDelegate.childAspectRatio != childAspectRatio + || oldDelegate.mainAxisExtent != mainAxisExtent; + } +} + +/// Parent data structure used by [RenderSliverGrid]. +class SliverGridParentData extends SliverMultiBoxAdaptorParentData { + /// The offset of the child in the non-scrolling axis. + /// + /// If the scroll axis is vertical, this offset is from the left-most edge of + /// the parent to the left-most edge of the child. If the scroll axis is + /// horizontal, this offset is from the top-most edge of the parent to the + /// top-most edge of the child. + double? crossAxisOffset; + + @override + String toString() => 'crossAxisOffset=$crossAxisOffset; ${super.toString()}'; +} + +/// A sliver that places multiple box children in a two dimensional arrangement. +/// +/// [RenderSliverGrid] places its children in arbitrary positions determined by +/// [gridDelegate]. Each child is forced to have the size specified by the +/// [gridDelegate]. +/// +/// See also: +/// +/// * [RenderSliverList], which places its children in a linear +/// array. +/// * [RenderSliverFixedExtentList], which places its children in a linear +/// array with a fixed extent in the main axis. +class RenderSliverGrid extends RenderSliverMultiBoxAdaptor { + /// Creates a sliver that contains multiple box children that whose size and + /// position are determined by a delegate. + RenderSliverGrid({ + required super.childManager, + required SliverGridDelegate gridDelegate, + }) : _gridDelegate = gridDelegate; + + @override + void setupParentData(RenderObject child) { + if (child.parentData is! SliverGridParentData) { + child.parentData = SliverGridParentData(); + } + } + + /// The delegate that controls the size and position of the children. + SliverGridDelegate get gridDelegate => _gridDelegate; + SliverGridDelegate _gridDelegate; + set gridDelegate(SliverGridDelegate value) { + if (_gridDelegate == value) { + return; + } + if (value.runtimeType != _gridDelegate.runtimeType || + value.shouldRelayout(_gridDelegate)) { + markNeedsLayout(); + } + _gridDelegate = value; + } + + @override + double childCrossAxisPosition(RenderBox child) { + final SliverGridParentData childParentData = child.parentData! as SliverGridParentData; + return childParentData.crossAxisOffset!; + } + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + childManager.didStartLayout(); + childManager.setDidUnderflow(false); + + final double scrollOffset = constraints.scrollOffset + constraints.cacheOrigin; + assert(scrollOffset >= 0.0); + final double remainingExtent = constraints.remainingCacheExtent; + assert(remainingExtent >= 0.0); + final double targetEndScrollOffset = scrollOffset + remainingExtent; + + final SliverGridLayout layout = _gridDelegate.getLayout(constraints); + + final int firstIndex = layout.getMinChildIndexForScrollOffset(scrollOffset); + final int? targetLastIndex = targetEndScrollOffset.isFinite ? + layout.getMaxChildIndexForScrollOffset(targetEndScrollOffset) : null; + if (firstChild != null) { + final int leadingGarbage = _calculateLeadingGarbage(firstIndex); + final int trailingGarbage = targetLastIndex != null ? _calculateTrailingGarbage(targetLastIndex) : 0; + collectGarbage(leadingGarbage, trailingGarbage); + } else { + collectGarbage(0, 0); + } + + final SliverGridGeometry firstChildGridGeometry = layout.getGeometryForChildIndex(firstIndex); + + if (firstChild == null) { + if (!addInitialChild(index: firstIndex, layoutOffset: firstChildGridGeometry.scrollOffset)) { + // There are either no children, or we are past the end of all our children. + final double max = layout.computeMaxScrollOffset(childManager.childCount); + geometry = SliverGeometry( + scrollExtent: max, + maxPaintExtent: max, + ); + childManager.didFinishLayout(); + return; + } + } + + final double leadingScrollOffset = firstChildGridGeometry.scrollOffset; + double trailingScrollOffset = firstChildGridGeometry.trailingScrollOffset; + RenderBox? trailingChildWithLayout; + bool reachedEnd = false; + + for (int index = indexOf(firstChild!) - 1; index >= firstIndex; --index) { + final SliverGridGeometry gridGeometry = layout.getGeometryForChildIndex(index); + final RenderBox child = insertAndLayoutLeadingChild( + gridGeometry.getBoxConstraints(constraints), + )!; + final SliverGridParentData childParentData = child.parentData! as SliverGridParentData; + childParentData.layoutOffset = gridGeometry.scrollOffset; + childParentData.crossAxisOffset = gridGeometry.crossAxisOffset; + assert(childParentData.index == index); + trailingChildWithLayout ??= child; + trailingScrollOffset = math.max(trailingScrollOffset, gridGeometry.trailingScrollOffset); + } + + if (trailingChildWithLayout == null) { + firstChild!.layout(firstChildGridGeometry.getBoxConstraints(constraints)); + final SliverGridParentData childParentData = firstChild!.parentData! as SliverGridParentData; + childParentData.layoutOffset = firstChildGridGeometry.scrollOffset; + childParentData.crossAxisOffset = firstChildGridGeometry.crossAxisOffset; + trailingChildWithLayout = firstChild; + } + + for (int index = indexOf(trailingChildWithLayout!) + 1; targetLastIndex == null || index <= targetLastIndex; ++index) { + final SliverGridGeometry gridGeometry = layout.getGeometryForChildIndex(index); + final BoxConstraints childConstraints = gridGeometry.getBoxConstraints(constraints); + RenderBox? child = childAfter(trailingChildWithLayout!); + if (child == null || indexOf(child) != index) { + child = insertAndLayoutChild(childConstraints, after: trailingChildWithLayout); + if (child == null) { + reachedEnd = true; + // We have run out of children. + break; + } + } else { + child.layout(childConstraints); + } + trailingChildWithLayout = child; + final SliverGridParentData childParentData = child.parentData! as SliverGridParentData; + childParentData.layoutOffset = gridGeometry.scrollOffset; + childParentData.crossAxisOffset = gridGeometry.crossAxisOffset; + assert(childParentData.index == index); + trailingScrollOffset = math.max(trailingScrollOffset, gridGeometry.trailingScrollOffset); + } + + final int lastIndex = indexOf(lastChild!); + + assert(debugAssertChildListIsNonEmptyAndContiguous()); + assert(indexOf(firstChild!) == firstIndex); + assert(targetLastIndex == null || lastIndex <= targetLastIndex); + + final double estimatedTotalExtent = reachedEnd + ? trailingScrollOffset + : childManager.estimateMaxScrollOffset( + constraints, + firstIndex: firstIndex, + lastIndex: lastIndex, + leadingScrollOffset: leadingScrollOffset, + trailingScrollOffset: trailingScrollOffset, + ); + final double paintExtent = calculatePaintOffset( + constraints, + from: math.min(constraints.scrollOffset, leadingScrollOffset), + to: trailingScrollOffset, + ); + final double cacheExtent = calculateCacheOffset( + constraints, + from: leadingScrollOffset, + to: trailingScrollOffset, + ); + + geometry = SliverGeometry( + scrollExtent: estimatedTotalExtent, + paintExtent: paintExtent, + maxPaintExtent: estimatedTotalExtent, + cacheExtent: cacheExtent, + hasVisualOverflow: estimatedTotalExtent > paintExtent || constraints.scrollOffset > 0.0 || constraints.overlap != 0.0, + ); + + // We may have started the layout while scrolled to the end, which + // would not expose a new child. + if (estimatedTotalExtent == trailingScrollOffset) { + childManager.setDidUnderflow(true); + } + childManager.didFinishLayout(); + } + + int _calculateLeadingGarbage(int firstIndex) { + RenderBox? walker = firstChild; + int leadingGarbage = 0; + while (walker != null && indexOf(walker) < firstIndex) { + leadingGarbage += 1; + walker = childAfter(walker); + } + return leadingGarbage; + } + + int _calculateTrailingGarbage(int targetLastIndex) { + RenderBox? walker = lastChild; + int trailingGarbage = 0; + while (walker != null && indexOf(walker) > targetLastIndex) { + trailingGarbage += 1; + walker = childBefore(walker); + } + return trailingGarbage; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_group.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_group.dart new file mode 100644 index 0000000000000000000000000000000000000000..40e8ee85ec7bf2a48573e72ebff7889a8695b20b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_group.dart @@ -0,0 +1,344 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'package:vector_math/vector_math_64.dart'; + +import 'object.dart'; +import 'sliver.dart'; + +/// A sliver that places multiple sliver children in a linear array along the cross +/// axis. +/// +/// Since the extent of the viewport in the cross axis direction is finite, +/// this extent will be divided up and allocated to the children slivers. +/// +/// The algorithm for dividing up the cross axis extent is as follows. +/// Every widget has a [SliverPhysicalParentData.crossAxisFlex] value associated with them. +/// First, lay out all of the slivers with flex of 0 or null, in which case the slivers themselves will +/// figure out how much cross axis extent to take up. For example, [SliverConstrainedCrossAxis] +/// is an example of a widget which sets its own flex to 0. Then [RenderSliverCrossAxisGroup] will +/// divide up the remaining space to all the remaining children proportionally +/// to each child's flex factor. By default, children of [SliverCrossAxisGroup] +/// are setup to have a flex factor of 1, but a different flex factor can be +/// specified via the [SliverCrossAxisExpanded] widgets. +class RenderSliverCrossAxisGroup extends RenderSliver with ContainerRenderObjectMixin<RenderSliver, SliverPhysicalContainerParentData> { + @override + void setupParentData(RenderObject child) { + if (child.parentData is! SliverPhysicalContainerParentData) { + child.parentData = SliverPhysicalContainerParentData(); + (child.parentData! as SliverPhysicalParentData).crossAxisFlex = 1; + } + } + + @override + double childMainAxisPosition(RenderSliver child) => 0.0; + + @override + double childCrossAxisPosition(RenderSliver child) { + switch (constraints.axisDirection) { + case AxisDirection.up: + case AxisDirection.down: + return (child.parentData! as SliverPhysicalParentData).paintOffset.dx; + case AxisDirection.left: + case AxisDirection.right: + return (child.parentData! as SliverPhysicalParentData).paintOffset.dy; + } + } + + @override + void performLayout() { + // Iterate through each sliver. + // Get the parent's dimensions. + final double crossAxisExtent = constraints.crossAxisExtent; + assert(crossAxisExtent.isFinite); + + // First, layout each child with flex == 0 or null. + int totalFlex = 0; + double remainingExtent = crossAxisExtent; + RenderSliver? child = firstChild; + while (child != null) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + final int flex = childParentData.crossAxisFlex ?? 0; + if (flex == 0) { + // If flex is 0 or null, then the child sliver must provide their own crossAxisExtent. + assert(_assertOutOfExtent(remainingExtent)); + child.layout(constraints.copyWith(crossAxisExtent: remainingExtent), parentUsesSize: true); + final double? childCrossAxisExtent = child.geometry!.crossAxisExtent; + assert(childCrossAxisExtent != null); + remainingExtent = math.max(0.0, remainingExtent - childCrossAxisExtent!); + } else { + totalFlex += flex; + } + child = childAfter(child); + } + final double extentPerFlexValue = remainingExtent / totalFlex; + + child = firstChild; + + // At this point, all slivers with constrained cross axis should already be laid out. + // Layout the rest and keep track of the child geometry with greatest scrollExtent. + geometry = SliverGeometry.zero; + while (child != null) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + final int flex = childParentData.crossAxisFlex ?? 0; + double childExtent; + if (flex != 0) { + childExtent = extentPerFlexValue * flex; + assert(_assertOutOfExtent(childExtent)); + child.layout(constraints.copyWith( + crossAxisExtent: extentPerFlexValue * flex, + ), parentUsesSize: true); + } else { + childExtent = child.geometry!.crossAxisExtent!; + } + final SliverGeometry childLayoutGeometry = child.geometry!; + if (geometry!.scrollExtent < childLayoutGeometry.scrollExtent) { + geometry = childLayoutGeometry; + } + child = childAfter(child); + } + + // Go back and correct any slivers using a negative paint offset if it tries + // to paint outside the bounds of the sliver group. + child = firstChild; + double offset = 0.0; + while (child != null) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + final SliverGeometry childLayoutGeometry = child.geometry!; + final double remainingExtent = geometry!.scrollExtent - constraints.scrollOffset; + final double paintCorrection = childLayoutGeometry.paintExtent > remainingExtent + ? childLayoutGeometry.paintExtent - remainingExtent + : 0.0; + final double childExtent = child.geometry!.crossAxisExtent ?? extentPerFlexValue * (childParentData.crossAxisFlex ?? 0); + // Set child parent data. + switch (constraints.axis) { + case Axis.vertical: + childParentData.paintOffset = Offset(offset, -paintCorrection); + case Axis.horizontal: + childParentData.paintOffset = Offset(-paintCorrection, offset); + } + offset += childExtent; + child = childAfter(child); + } + } + + @override + void paint(PaintingContext context, Offset offset) { + RenderSliver? child = firstChild; + + while (child != null) { + if (child.geometry!.visible) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + context.paintChild(child, offset + childParentData.paintOffset); + } + child = childAfter(child); + } + } + + @override + void applyPaintTransform(RenderSliver child, Matrix4 transform) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + childParentData.applyPaintTransform(transform); + } + + @override + bool hitTestChildren(SliverHitTestResult result, {required double mainAxisPosition, required double crossAxisPosition}) { + RenderSliver? child = lastChild; + while (child != null) { + final bool isHit = result.addWithAxisOffset( + mainAxisPosition: mainAxisPosition, + crossAxisPosition: crossAxisPosition, + paintOffset: null, + mainAxisOffset: childMainAxisPosition(child), + crossAxisOffset: childCrossAxisPosition(child), + hitTest: child.hitTest, + ); + if (isHit) { + return true; + } + child = childBefore(child); + } + return false; + } +} + +bool _assertOutOfExtent(double extent) { + if (extent <= 0.0) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('SliverCrossAxisGroup ran out of extent before child could be laid out.'), + ErrorDescription( + 'SliverCrossAxisGroup lays out any slivers with a constrained cross ' + 'axis before laying out those which expand. In this case, cross axis ' + 'extent was used up before the next sliver could be laid out.' + ), + ErrorHint( + 'Make sure that the total amount of extent allocated by constrained ' + 'child slivers does not exceed the cross axis extent that is available ' + 'for the SliverCrossAxisGroup.' + ), + ]); + } + return true; +} + +/// A sliver that places multiple sliver children in a linear array along the +/// main axis. +/// +/// The layout algorithm lays out slivers one by one. If the sliver is at the top +/// of the viewport or above the top, then we pass in a nonzero [SliverConstraints.scrollOffset] +/// to inform the sliver at what point along the main axis we should start layout. +/// For the slivers that come after it, we compute the amount of space taken up so +/// far to be used as the [SliverPhysicalParentData.paintOffset] and the +/// [SliverConstraints.remainingPaintExtent] to be passed in as a constraint. +/// +/// Finally, this sliver will also ensure that all child slivers are painted within +/// the total scroll extent of the group by adjusting the child's +/// [SliverPhysicalParentData.paintOffset] as necessary. This can happen for +/// slivers such as [SliverPersistentHeader] which, when pinned, positions itself +/// at the top of the [Viewport] regardless of the scroll offset. +class RenderSliverMainAxisGroup extends RenderSliver with ContainerRenderObjectMixin<RenderSliver, SliverPhysicalContainerParentData> { + @override + void setupParentData(RenderObject child) { + if (child.parentData is! SliverPhysicalContainerParentData) { + child.parentData = SliverPhysicalContainerParentData(); + } + } + + @override + double childMainAxisPosition(RenderSliver child) { + switch (constraints.axisDirection) { + case AxisDirection.up: + case AxisDirection.down: + return (child.parentData! as SliverPhysicalParentData).paintOffset.dy; + case AxisDirection.left: + case AxisDirection.right: + return (child.parentData! as SliverPhysicalParentData).paintOffset.dx; + } + } + + @override + double childCrossAxisPosition(RenderSliver child) => 0.0; + + @override + void performLayout() { + double offset = 0; + double maxPaintExtent = 0; + + RenderSliver? child = firstChild; + + + while (child != null) { + final double beforeOffsetPaintExtent = calculatePaintOffset( + constraints, + from: 0.0, + to: offset, + ); + child.layout( + constraints.copyWith( + scrollOffset: math.max(0.0, constraints.scrollOffset - offset), + cacheOrigin: math.min(0.0, constraints.cacheOrigin + offset), + overlap: math.max(0.0, constraints.overlap - beforeOffsetPaintExtent), + remainingPaintExtent: constraints.remainingPaintExtent - beforeOffsetPaintExtent, + remainingCacheExtent: constraints.remainingCacheExtent - calculateCacheOffset(constraints, from: 0.0, to: offset), + precedingScrollExtent: offset + constraints.precedingScrollExtent, + ), + parentUsesSize: true, + ); + final SliverGeometry childLayoutGeometry = child.geometry!; + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + switch (constraints.axis) { + case Axis.vertical: + childParentData.paintOffset = Offset(0.0, beforeOffsetPaintExtent); + case Axis.horizontal: + childParentData.paintOffset = Offset(beforeOffsetPaintExtent, 0.0); + } + offset += childLayoutGeometry.scrollExtent; + maxPaintExtent += child.geometry!.maxPaintExtent; + child = childAfter(child); + } + + final double totalScrollExtent = offset; + offset = 0.0; + child = firstChild; + // Second pass to correct out of bound paintOffsets. + while (child != null) { + final double beforeOffsetPaintExtent = calculatePaintOffset( + constraints, + from: 0.0, + to: offset, + ); + final SliverGeometry childLayoutGeometry = child.geometry!; + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + final double remainingExtent = totalScrollExtent - constraints.scrollOffset; + if (childLayoutGeometry.paintExtent > remainingExtent) { + final double paintCorrection = childLayoutGeometry.paintExtent - remainingExtent; + switch (constraints.axis) { + case Axis.vertical: + childParentData.paintOffset = Offset(0.0, beforeOffsetPaintExtent - paintCorrection); + case Axis.horizontal: + childParentData.paintOffset = Offset(beforeOffsetPaintExtent - paintCorrection, 0.0); + } + } + offset += child.geometry!.scrollExtent; + child = childAfter(child); + } + geometry = SliverGeometry( + scrollExtent: totalScrollExtent, + paintExtent: calculatePaintOffset(constraints, from: 0, to: totalScrollExtent), + maxPaintExtent: maxPaintExtent, + hasVisualOverflow: totalScrollExtent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0, + ); + } + + @override + void paint(PaintingContext context, Offset offset) { + RenderSliver? child = lastChild; + + while (child != null) { + if (child.geometry!.visible) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + context.paintChild(child, offset + childParentData.paintOffset); + } + child = childBefore(child); + } + } + + @override + void applyPaintTransform(RenderSliver child, Matrix4 transform) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + childParentData.applyPaintTransform(transform); + } + + @override + bool hitTestChildren(SliverHitTestResult result, {required double mainAxisPosition, required double crossAxisPosition}) { + RenderSliver? child = firstChild; + while (child != null) { + final bool isHit = result.addWithAxisOffset( + mainAxisPosition: mainAxisPosition, + crossAxisPosition: crossAxisPosition, + paintOffset: null, + mainAxisOffset: childMainAxisPosition(child), + crossAxisOffset: childCrossAxisPosition(child), + hitTest: child.hitTest, + ); + if (isHit) { + return true; + } + child = childAfter(child); + } + return false; + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + RenderSliver? child = firstChild; + while (child != null) { + if (child.geometry!.visible) { + visitor(child); + } + child = childAfter(child); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_list.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_list.dart new file mode 100644 index 0000000000000000000000000000000000000000..e1fdedad1ca2f790463c27aa12ba7817e7a72175 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_list.dart @@ -0,0 +1,342 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'sliver.dart'; +import 'sliver_multi_box_adaptor.dart'; + +/// A sliver that places multiple box children in a linear array along the main +/// axis. +/// +/// Each child is forced to have the [SliverConstraints.crossAxisExtent] in the +/// cross axis but determines its own main axis extent. +/// +/// [RenderSliverList] determines its scroll offset by "dead reckoning" because +/// children outside the visible part of the sliver are not materialized, which +/// means [RenderSliverList] cannot learn their main axis extent. Instead, newly +/// materialized children are placed adjacent to existing children. If this dead +/// reckoning results in a logical inconsistency (e.g., attempting to place the +/// zeroth child at a scroll offset other than zero), the [RenderSliverList] +/// generates a [SliverGeometry.scrollOffsetCorrection] to restore consistency. +/// +/// If the children have a fixed extent in the main axis, consider using +/// [RenderSliverFixedExtentList] rather than [RenderSliverList] because +/// [RenderSliverFixedExtentList] does not need to perform layout on its +/// children to obtain their extent in the main axis and is therefore more +/// efficient. +/// +/// See also: +/// +/// * [RenderSliverFixedExtentList], which is more efficient for children with +/// the same extent in the main axis. +/// * [RenderSliverGrid], which places its children in arbitrary positions. +class RenderSliverList extends RenderSliverMultiBoxAdaptor { + /// Creates a sliver that places multiple box children in a linear array along + /// the main axis. + RenderSliverList({ + required super.childManager, + }); + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + childManager.didStartLayout(); + childManager.setDidUnderflow(false); + + final double scrollOffset = constraints.scrollOffset + constraints.cacheOrigin; + assert(scrollOffset >= 0.0); + final double remainingExtent = constraints.remainingCacheExtent; + assert(remainingExtent >= 0.0); + final double targetEndScrollOffset = scrollOffset + remainingExtent; + final BoxConstraints childConstraints = constraints.asBoxConstraints(); + int leadingGarbage = 0; + int trailingGarbage = 0; + bool reachedEnd = false; + + // This algorithm in principle is straight-forward: find the first child + // that overlaps the given scrollOffset, creating more children at the top + // of the list if necessary, then walk down the list updating and laying out + // each child and adding more at the end if necessary until we have enough + // children to cover the entire viewport. + // + // It is complicated by one minor issue, which is that any time you update + // or create a child, it's possible that the some of the children that + // haven't yet been laid out will be removed, leaving the list in an + // inconsistent state, and requiring that missing nodes be recreated. + // + // To keep this mess tractable, this algorithm starts from what is currently + // the first child, if any, and then walks up and/or down from there, so + // that the nodes that might get removed are always at the edges of what has + // already been laid out. + + // Make sure we have at least one child to start from. + if (firstChild == null) { + if (!addInitialChild()) { + // There are no children. + geometry = SliverGeometry.zero; + childManager.didFinishLayout(); + return; + } + } + + // We have at least one child. + + // These variables track the range of children that we have laid out. Within + // this range, the children have consecutive indices. Outside this range, + // it's possible for a child to get removed without notice. + RenderBox? leadingChildWithLayout, trailingChildWithLayout; + + RenderBox? earliestUsefulChild = firstChild; + + // A firstChild with null layout offset is likely a result of children + // reordering. + // + // We rely on firstChild to have accurate layout offset. In the case of null + // layout offset, we have to find the first child that has valid layout + // offset. + if (childScrollOffset(firstChild!) == null) { + int leadingChildrenWithoutLayoutOffset = 0; + while (earliestUsefulChild != null && childScrollOffset(earliestUsefulChild) == null) { + earliestUsefulChild = childAfter(earliestUsefulChild); + leadingChildrenWithoutLayoutOffset += 1; + } + // We should be able to destroy children with null layout offset safely, + // because they are likely outside of viewport + collectGarbage(leadingChildrenWithoutLayoutOffset, 0); + // If can not find a valid layout offset, start from the initial child. + if (firstChild == null) { + if (!addInitialChild()) { + // There are no children. + geometry = SliverGeometry.zero; + childManager.didFinishLayout(); + return; + } + } + } + + // Find the last child that is at or before the scrollOffset. + earliestUsefulChild = firstChild; + for (double earliestScrollOffset = childScrollOffset(earliestUsefulChild!)!; + earliestScrollOffset > scrollOffset; + earliestScrollOffset = childScrollOffset(earliestUsefulChild)!) { + // We have to add children before the earliestUsefulChild. + earliestUsefulChild = insertAndLayoutLeadingChild(childConstraints, parentUsesSize: true); + if (earliestUsefulChild == null) { + final SliverMultiBoxAdaptorParentData childParentData = firstChild!.parentData! as SliverMultiBoxAdaptorParentData; + childParentData.layoutOffset = 0.0; + + if (scrollOffset == 0.0) { + // insertAndLayoutLeadingChild only lays out the children before + // firstChild. In this case, nothing has been laid out. We have + // to lay out firstChild manually. + firstChild!.layout(childConstraints, parentUsesSize: true); + earliestUsefulChild = firstChild; + leadingChildWithLayout = earliestUsefulChild; + trailingChildWithLayout ??= earliestUsefulChild; + break; + } else { + // We ran out of children before reaching the scroll offset. + // We must inform our parent that this sliver cannot fulfill + // its contract and that we need a scroll offset correction. + geometry = SliverGeometry( + scrollOffsetCorrection: -scrollOffset, + ); + return; + } + } + + final double firstChildScrollOffset = earliestScrollOffset - paintExtentOf(firstChild!); + // firstChildScrollOffset may contain double precision error + if (firstChildScrollOffset < -precisionErrorTolerance) { + // Let's assume there is no child before the first child. We will + // correct it on the next layout if it is not. + geometry = SliverGeometry( + scrollOffsetCorrection: -firstChildScrollOffset, + ); + final SliverMultiBoxAdaptorParentData childParentData = firstChild!.parentData! as SliverMultiBoxAdaptorParentData; + childParentData.layoutOffset = 0.0; + return; + } + + final SliverMultiBoxAdaptorParentData childParentData = earliestUsefulChild.parentData! as SliverMultiBoxAdaptorParentData; + childParentData.layoutOffset = firstChildScrollOffset; + assert(earliestUsefulChild == firstChild); + leadingChildWithLayout = earliestUsefulChild; + trailingChildWithLayout ??= earliestUsefulChild; + } + + assert(childScrollOffset(firstChild!)! > -precisionErrorTolerance); + + // If the scroll offset is at zero, we should make sure we are + // actually at the beginning of the list. + if (scrollOffset < precisionErrorTolerance) { + // We iterate from the firstChild in case the leading child has a 0 paint + // extent. + while (indexOf(firstChild!) > 0) { + final double earliestScrollOffset = childScrollOffset(firstChild!)!; + // We correct one child at a time. If there are more children before + // the earliestUsefulChild, we will correct it once the scroll offset + // reaches zero again. + earliestUsefulChild = insertAndLayoutLeadingChild(childConstraints, parentUsesSize: true); + assert(earliestUsefulChild != null); + final double firstChildScrollOffset = earliestScrollOffset - paintExtentOf(firstChild!); + final SliverMultiBoxAdaptorParentData childParentData = firstChild!.parentData! as SliverMultiBoxAdaptorParentData; + childParentData.layoutOffset = 0.0; + // We only need to correct if the leading child actually has a + // paint extent. + if (firstChildScrollOffset < -precisionErrorTolerance) { + geometry = SliverGeometry( + scrollOffsetCorrection: -firstChildScrollOffset, + ); + return; + } + } + } + + // At this point, earliestUsefulChild is the first child, and is a child + // whose scrollOffset is at or before the scrollOffset, and + // leadingChildWithLayout and trailingChildWithLayout are either null or + // cover a range of render boxes that we have laid out with the first being + // the same as earliestUsefulChild and the last being either at or after the + // scroll offset. + + assert(earliestUsefulChild == firstChild); + assert(childScrollOffset(earliestUsefulChild!)! <= scrollOffset); + + // Make sure we've laid out at least one child. + if (leadingChildWithLayout == null) { + earliestUsefulChild!.layout(childConstraints, parentUsesSize: true); + leadingChildWithLayout = earliestUsefulChild; + trailingChildWithLayout = earliestUsefulChild; + } + + // Here, earliestUsefulChild is still the first child, it's got a + // scrollOffset that is at or before our actual scrollOffset, and it has + // been laid out, and is in fact our leadingChildWithLayout. It's possible + // that some children beyond that one have also been laid out. + + bool inLayoutRange = true; + RenderBox? child = earliestUsefulChild; + int index = indexOf(child!); + double endScrollOffset = childScrollOffset(child)! + paintExtentOf(child); + bool advance() { // returns true if we advanced, false if we have no more children + // This function is used in two different places below, to avoid code duplication. + assert(child != null); + if (child == trailingChildWithLayout) { + inLayoutRange = false; + } + child = childAfter(child!); + if (child == null) { + inLayoutRange = false; + } + index += 1; + if (!inLayoutRange) { + if (child == null || indexOf(child!) != index) { + // We are missing a child. Insert it (and lay it out) if possible. + child = insertAndLayoutChild(childConstraints, + after: trailingChildWithLayout, + parentUsesSize: true, + ); + if (child == null) { + // We have run out of children. + return false; + } + } else { + // Lay out the child. + child!.layout(childConstraints, parentUsesSize: true); + } + trailingChildWithLayout = child; + } + assert(child != null); + final SliverMultiBoxAdaptorParentData childParentData = child!.parentData! as SliverMultiBoxAdaptorParentData; + childParentData.layoutOffset = endScrollOffset; + assert(childParentData.index == index); + endScrollOffset = childScrollOffset(child!)! + paintExtentOf(child!); + return true; + } + + // Find the first child that ends after the scroll offset. + while (endScrollOffset < scrollOffset) { + leadingGarbage += 1; + if (!advance()) { + assert(leadingGarbage == childCount); + assert(child == null); + // we want to make sure we keep the last child around so we know the end scroll offset + collectGarbage(leadingGarbage - 1, 0); + assert(firstChild == lastChild); + final double extent = childScrollOffset(lastChild!)! + paintExtentOf(lastChild!); + geometry = SliverGeometry( + scrollExtent: extent, + maxPaintExtent: extent, + ); + return; + } + } + + // Now find the first child that ends after our end. + while (endScrollOffset < targetEndScrollOffset) { + if (!advance()) { + reachedEnd = true; + break; + } + } + + // Finally count up all the remaining children and label them as garbage. + if (child != null) { + child = childAfter(child!); + while (child != null) { + trailingGarbage += 1; + child = childAfter(child!); + } + } + + // At this point everything should be good to go, we just have to clean up + // the garbage and report the geometry. + + collectGarbage(leadingGarbage, trailingGarbage); + + assert(debugAssertChildListIsNonEmptyAndContiguous()); + final double estimatedMaxScrollOffset; + if (reachedEnd) { + estimatedMaxScrollOffset = endScrollOffset; + } else { + estimatedMaxScrollOffset = childManager.estimateMaxScrollOffset( + constraints, + firstIndex: indexOf(firstChild!), + lastIndex: indexOf(lastChild!), + leadingScrollOffset: childScrollOffset(firstChild!), + trailingScrollOffset: endScrollOffset, + ); + assert(estimatedMaxScrollOffset >= endScrollOffset - childScrollOffset(firstChild!)!); + } + final double paintExtent = calculatePaintOffset( + constraints, + from: childScrollOffset(firstChild!)!, + to: endScrollOffset, + ); + final double cacheExtent = calculateCacheOffset( + constraints, + from: childScrollOffset(firstChild!)!, + to: endScrollOffset, + ); + final double targetEndScrollOffsetForPaint = constraints.scrollOffset + constraints.remainingPaintExtent; + geometry = SliverGeometry( + scrollExtent: estimatedMaxScrollOffset, + paintExtent: paintExtent, + cacheExtent: cacheExtent, + maxPaintExtent: estimatedMaxScrollOffset, + // Conservative to avoid flickering away the clip during scroll. + hasVisualOverflow: endScrollOffset > targetEndScrollOffsetForPaint || constraints.scrollOffset > 0.0, + ); + + // We may have started the layout while scrolled to the end, which would not + // expose a new child. + if (estimatedMaxScrollOffset == endScrollOffset) { + childManager.setDidUnderflow(true); + } + childManager.didFinishLayout(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart new file mode 100644 index 0000000000000000000000000000000000000000..76188fcbcaa74636ff58f3515dea5bb18e0be5a9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart @@ -0,0 +1,704 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'box.dart'; +import 'object.dart'; +import 'sliver.dart'; + +/// A delegate used by [RenderSliverMultiBoxAdaptor] to manage its children. +/// +/// [RenderSliverMultiBoxAdaptor] objects reify their children lazily to avoid +/// spending resources on children that are not visible in the viewport. This +/// delegate lets these objects create and remove children as well as estimate +/// the total scroll offset extent occupied by the full child list. +abstract class RenderSliverBoxChildManager { + /// Called during layout when a new child is needed. The child should be + /// inserted into the child list in the appropriate position, after the + /// `after` child (at the start of the list if `after` is null). Its index and + /// scroll offsets will automatically be set appropriately. + /// + /// The `index` argument gives the index of the child to show. It is possible + /// for negative indices to be requested. For example: if the user scrolls + /// from child 0 to child 10, and then those children get much smaller, and + /// then the user scrolls back up again, this method will eventually be asked + /// to produce a child for index -1. + /// + /// If no child corresponds to `index`, then do nothing. + /// + /// Which child is indicated by index zero depends on the [GrowthDirection] + /// specified in the `constraints` of the [RenderSliverMultiBoxAdaptor]. For + /// example if the children are the alphabet, then if + /// [SliverConstraints.growthDirection] is [GrowthDirection.forward] then + /// index zero is A, and index 25 is Z. On the other hand if + /// [SliverConstraints.growthDirection] is [GrowthDirection.reverse] then + /// index zero is Z, and index 25 is A. + /// + /// During a call to [createChild] it is valid to remove other children from + /// the [RenderSliverMultiBoxAdaptor] object if they were not created during + /// this frame and have not yet been updated during this frame. It is not + /// valid to add any other children to this render object. + void createChild(int index, { required RenderBox? after }); + + /// Remove the given child from the child list. + /// + /// Called by [RenderSliverMultiBoxAdaptor.collectGarbage], which itself is + /// called from [RenderSliverMultiBoxAdaptor]'s `performLayout`. + /// + /// The index of the given child can be obtained using the + /// [RenderSliverMultiBoxAdaptor.indexOf] method, which reads it from the + /// [SliverMultiBoxAdaptorParentData.index] field of the child's + /// [RenderObject.parentData]. + void removeChild(RenderBox child); + + /// Called to estimate the total scrollable extents of this object. + /// + /// Must return the total distance from the start of the child with the + /// earliest possible index to the end of the child with the last possible + /// index. + double estimateMaxScrollOffset( + SliverConstraints constraints, { + int? firstIndex, + int? lastIndex, + double? leadingScrollOffset, + double? trailingScrollOffset, + }); + + /// Called to obtain a precise measure of the total number of children. + /// + /// Must return the number that is one greater than the greatest `index` for + /// which `createChild` will actually create a child. + /// + /// This is used when [createChild] cannot add a child for a positive `index`, + /// to determine the precise dimensions of the sliver. It must return an + /// accurate and precise non-null value. It will not be called if + /// [createChild] is always able to create a child (e.g. for an infinite + /// list). + int get childCount; + + /// Called during [RenderSliverMultiBoxAdaptor.adoptChild] or + /// [RenderSliverMultiBoxAdaptor.move]. + /// + /// Subclasses must ensure that the [SliverMultiBoxAdaptorParentData.index] + /// field of the child's [RenderObject.parentData] accurately reflects the + /// child's index in the child list after this function returns. + void didAdoptChild(RenderBox child); + + /// Called during layout to indicate whether this object provided insufficient + /// children for the [RenderSliverMultiBoxAdaptor] to fill the + /// [SliverConstraints.remainingPaintExtent]. + /// + /// Typically called unconditionally at the start of layout with false and + /// then later called with true when the [RenderSliverMultiBoxAdaptor] + /// fails to create a child required to fill the + /// [SliverConstraints.remainingPaintExtent]. + /// + /// Useful for subclasses to determine whether newly added children could + /// affect the visible contents of the [RenderSliverMultiBoxAdaptor]. + void setDidUnderflow(bool value); + + /// Called at the beginning of layout to indicate that layout is about to + /// occur. + void didStartLayout() { } + + /// Called at the end of layout to indicate that layout is now complete. + void didFinishLayout() { } + + /// In debug mode, asserts that this manager is not expecting any + /// modifications to the [RenderSliverMultiBoxAdaptor]'s child list. + /// + /// This function always returns true. + /// + /// The manager is not required to track whether it is expecting modifications + /// to the [RenderSliverMultiBoxAdaptor]'s child list and can return + /// true without making any assertions. + bool debugAssertChildListLocked() => true; +} + +/// Parent data structure used by [RenderSliverWithKeepAliveMixin]. +mixin KeepAliveParentDataMixin implements ParentData { + /// Whether to keep the child alive even when it is no longer visible. + bool keepAlive = false; + + /// Whether the widget is currently being kept alive, i.e. has [keepAlive] set + /// to true and is offscreen. + bool get keptAlive; +} + +/// This class exists to dissociate [KeepAlive] from [RenderSliverMultiBoxAdaptor]. +/// +/// [RenderSliverWithKeepAliveMixin.setupParentData] must be implemented to use +/// a parentData class that uses the right mixin or whatever is appropriate. +mixin RenderSliverWithKeepAliveMixin implements RenderSliver { + /// Alerts the developer that the child's parentData needs to be of type + /// [KeepAliveParentDataMixin]. + @override + void setupParentData(RenderObject child) { + assert(child.parentData is KeepAliveParentDataMixin); + } +} + +/// Parent data structure used by [RenderSliverMultiBoxAdaptor]. +class SliverMultiBoxAdaptorParentData extends SliverLogicalParentData with ContainerParentDataMixin<RenderBox>, KeepAliveParentDataMixin { + /// The index of this child according to the [RenderSliverBoxChildManager]. + int? index; + + @override + bool get keptAlive => _keptAlive; + bool _keptAlive = false; + + @override + String toString() => 'index=$index; ${keepAlive ? "keepAlive; " : ""}${super.toString()}'; +} + +/// A sliver with multiple box children. +/// +/// [RenderSliverMultiBoxAdaptor] is a base class for slivers that have multiple +/// box children. The children are managed by a [RenderSliverBoxChildManager], +/// which lets subclasses create children lazily during layout. Typically +/// subclasses will create only those children that are actually needed to fill +/// the [SliverConstraints.remainingPaintExtent]. +/// +/// The contract for adding and removing children from this render object is +/// more strict than for normal render objects: +/// +/// * Children can be removed except during a layout pass if they have already +/// been laid out during that layout pass. +/// * Children cannot be added except during a call to [childManager], and +/// then only if there is no child corresponding to that index (or the child +/// corresponding to that index was first removed). +/// +/// See also: +/// +/// * [RenderSliverToBoxAdapter], which has a single box child. +/// * [RenderSliverList], which places its children in a linear +/// array. +/// * [RenderSliverFixedExtentList], which places its children in a linear +/// array with a fixed extent in the main axis. +/// * [RenderSliverGrid], which places its children in arbitrary positions. +abstract class RenderSliverMultiBoxAdaptor extends RenderSliver + with ContainerRenderObjectMixin<RenderBox, SliverMultiBoxAdaptorParentData>, + RenderSliverHelpers, RenderSliverWithKeepAliveMixin { + + /// Creates a sliver with multiple box children. + RenderSliverMultiBoxAdaptor({ + required RenderSliverBoxChildManager childManager, + }) : _childManager = childManager { + assert(() { + _debugDanglingKeepAlives = <RenderBox>[]; + return true; + }()); + } + + @override + void setupParentData(RenderObject child) { + if (child.parentData is! SliverMultiBoxAdaptorParentData) { + child.parentData = SliverMultiBoxAdaptorParentData(); + } + } + + /// The delegate that manages the children of this object. + /// + /// Rather than having a concrete list of children, a + /// [RenderSliverMultiBoxAdaptor] uses a [RenderSliverBoxChildManager] to + /// create children during layout in order to fill the + /// [SliverConstraints.remainingPaintExtent]. + @protected + RenderSliverBoxChildManager get childManager => _childManager; + final RenderSliverBoxChildManager _childManager; + + /// The nodes being kept alive despite not being visible. + final Map<int, RenderBox> _keepAliveBucket = <int, RenderBox>{}; + + late List<RenderBox> _debugDanglingKeepAlives; + + /// Indicates whether integrity check is enabled. + /// + /// Setting this property to true will immediately perform an integrity check. + /// + /// The integrity check consists of: + /// + /// 1. Verify that the children index in childList is in ascending order. + /// 2. Verify that there is no dangling keepalive child as the result of [move]. + bool get debugChildIntegrityEnabled => _debugChildIntegrityEnabled; + bool _debugChildIntegrityEnabled = true; + set debugChildIntegrityEnabled(bool enabled) { + assert(() { + _debugChildIntegrityEnabled = enabled; + return _debugVerifyChildOrder() && + (!_debugChildIntegrityEnabled || _debugDanglingKeepAlives.isEmpty); + }()); + } + + @override + void adoptChild(RenderObject child) { + super.adoptChild(child); + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + if (!childParentData._keptAlive) { + childManager.didAdoptChild(child as RenderBox); + } + } + + bool _debugAssertChildListLocked() => childManager.debugAssertChildListLocked(); + + /// Verify that the child list index is in strictly increasing order. + /// + /// This has no effect in release builds. + bool _debugVerifyChildOrder() { + if (_debugChildIntegrityEnabled) { + RenderBox? child = firstChild; + int index; + while (child != null) { + index = indexOf(child); + child = childAfter(child); + assert(child == null || indexOf(child) > index); + } + } + return true; + } + + @override + void insert(RenderBox child, { RenderBox? after }) { + assert(!_keepAliveBucket.containsValue(child)); + super.insert(child, after: after); + assert(firstChild != null); + assert(_debugVerifyChildOrder()); + } + + @override + void move(RenderBox child, { RenderBox? after }) { + // There are two scenarios: + // + // 1. The child is not keptAlive. + // The child is in the childList maintained by ContainerRenderObjectMixin. + // We can call super.move and update parentData with the new slot. + // + // 2. The child is keptAlive. + // In this case, the child is no longer in the childList but might be stored in + // [_keepAliveBucket]. We need to update the location of the child in the bucket. + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + if (!childParentData.keptAlive) { + super.move(child, after: after); + childManager.didAdoptChild(child); // updates the slot in the parentData + // Its slot may change even if super.move does not change the position. + // In this case, we still want to mark as needs layout. + markNeedsLayout(); + } else { + // If the child in the bucket is not current child, that means someone has + // already moved and replaced current child, and we cannot remove this child. + if (_keepAliveBucket[childParentData.index] == child) { + _keepAliveBucket.remove(childParentData.index); + } + assert(() { + _debugDanglingKeepAlives.remove(child); + return true; + }()); + // Update the slot and reinsert back to _keepAliveBucket in the new slot. + childManager.didAdoptChild(child); + // If there is an existing child in the new slot, that mean that child will + // be moved to other index. In other cases, the existing child should have been + // removed by updateChild. Thus, it is ok to overwrite it. + assert(() { + if (_keepAliveBucket.containsKey(childParentData.index)) { + _debugDanglingKeepAlives.add(_keepAliveBucket[childParentData.index]!); + } + return true; + }()); + _keepAliveBucket[childParentData.index!] = child; + } + } + + @override + void remove(RenderBox child) { + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + if (!childParentData._keptAlive) { + super.remove(child); + return; + } + assert(_keepAliveBucket[childParentData.index] == child); + assert(() { + _debugDanglingKeepAlives.remove(child); + return true; + }()); + _keepAliveBucket.remove(childParentData.index); + dropChild(child); + } + + @override + void removeAll() { + super.removeAll(); + _keepAliveBucket.values.forEach(dropChild); + _keepAliveBucket.clear(); + } + + void _createOrObtainChild(int index, { required RenderBox? after }) { + invokeLayoutCallback<SliverConstraints>((SliverConstraints constraints) { + assert(constraints == this.constraints); + if (_keepAliveBucket.containsKey(index)) { + final RenderBox child = _keepAliveBucket.remove(index)!; + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + assert(childParentData._keptAlive); + dropChild(child); + child.parentData = childParentData; + insert(child, after: after); + childParentData._keptAlive = false; + } else { + _childManager.createChild(index, after: after); + } + }); + } + + void _destroyOrCacheChild(RenderBox child) { + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + if (childParentData.keepAlive) { + assert(!childParentData._keptAlive); + remove(child); + _keepAliveBucket[childParentData.index!] = child; + child.parentData = childParentData; + super.adoptChild(child); + childParentData._keptAlive = true; + } else { + assert(child.parent == this); + _childManager.removeChild(child); + assert(child.parent == null); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + for (final RenderBox child in _keepAliveBucket.values) { + child.attach(owner); + } + } + + @override + void detach() { + super.detach(); + for (final RenderBox child in _keepAliveBucket.values) { + child.detach(); + } + } + + @override + void redepthChildren() { + super.redepthChildren(); + _keepAliveBucket.values.forEach(redepthChild); + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + super.visitChildren(visitor); + _keepAliveBucket.values.forEach(visitor); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + super.visitChildren(visitor); + // Do not visit children in [_keepAliveBucket]. + } + + /// Called during layout to create and add the child with the given index and + /// scroll offset. + /// + /// Calls [RenderSliverBoxChildManager.createChild] to actually create and add + /// the child if necessary. The child may instead be obtained from a cache; + /// see [SliverMultiBoxAdaptorParentData.keepAlive]. + /// + /// Returns false if there was no cached child and `createChild` did not add + /// any child, otherwise returns true. + /// + /// Does not layout the new child. + /// + /// When this is called, there are no visible children, so no children can be + /// removed during the call to `createChild`. No child should be added during + /// that call either, except for the one that is created and returned by + /// `createChild`. + @protected + bool addInitialChild({ int index = 0, double layoutOffset = 0.0 }) { + assert(_debugAssertChildListLocked()); + assert(firstChild == null); + _createOrObtainChild(index, after: null); + if (firstChild != null) { + assert(firstChild == lastChild); + assert(indexOf(firstChild!) == index); + final SliverMultiBoxAdaptorParentData firstChildParentData = firstChild!.parentData! as SliverMultiBoxAdaptorParentData; + firstChildParentData.layoutOffset = layoutOffset; + return true; + } + childManager.setDidUnderflow(true); + return false; + } + + /// Called during layout to create, add, and layout the child before + /// [firstChild]. + /// + /// Calls [RenderSliverBoxChildManager.createChild] to actually create and add + /// the child if necessary. The child may instead be obtained from a cache; + /// see [SliverMultiBoxAdaptorParentData.keepAlive]. + /// + /// Returns the new child or null if no child was obtained. + /// + /// The child that was previously the first child, as well as any subsequent + /// children, may be removed by this call if they have not yet been laid out + /// during this layout pass. No child should be added during that call except + /// for the one that is created and returned by `createChild`. + @protected + RenderBox? insertAndLayoutLeadingChild( + BoxConstraints childConstraints, { + bool parentUsesSize = false, + }) { + assert(_debugAssertChildListLocked()); + final int index = indexOf(firstChild!) - 1; + _createOrObtainChild(index, after: null); + if (indexOf(firstChild!) == index) { + firstChild!.layout(childConstraints, parentUsesSize: parentUsesSize); + return firstChild; + } + childManager.setDidUnderflow(true); + return null; + } + + /// Called during layout to create, add, and layout the child after + /// the given child. + /// + /// Calls [RenderSliverBoxChildManager.createChild] to actually create and add + /// the child if necessary. The child may instead be obtained from a cache; + /// see [SliverMultiBoxAdaptorParentData.keepAlive]. + /// + /// Returns the new child. It is the responsibility of the caller to configure + /// the child's scroll offset. + /// + /// Children after the `after` child may be removed in the process. Only the + /// new child may be added. + @protected + RenderBox? insertAndLayoutChild( + BoxConstraints childConstraints, { + required RenderBox? after, + bool parentUsesSize = false, + }) { + assert(_debugAssertChildListLocked()); + assert(after != null); + final int index = indexOf(after!) + 1; + _createOrObtainChild(index, after: after); + final RenderBox? child = childAfter(after); + if (child != null && indexOf(child) == index) { + child.layout(childConstraints, parentUsesSize: parentUsesSize); + return child; + } + childManager.setDidUnderflow(true); + return null; + } + + /// Called after layout with the number of children that can be garbage + /// collected at the head and tail of the child list. + /// + /// Children whose [SliverMultiBoxAdaptorParentData.keepAlive] property is + /// set to true will be removed to a cache instead of being dropped. + /// + /// This method also collects any children that were previously kept alive but + /// are now no longer necessary. As such, it should be called every time + /// [performLayout] is run, even if the arguments are both zero. + @protected + void collectGarbage(int leadingGarbage, int trailingGarbage) { + assert(_debugAssertChildListLocked()); + assert(childCount >= leadingGarbage + trailingGarbage); + invokeLayoutCallback<SliverConstraints>((SliverConstraints constraints) { + while (leadingGarbage > 0) { + _destroyOrCacheChild(firstChild!); + leadingGarbage -= 1; + } + while (trailingGarbage > 0) { + _destroyOrCacheChild(lastChild!); + trailingGarbage -= 1; + } + // Ask the child manager to remove the children that are no longer being + // kept alive. (This should cause _keepAliveBucket to change, so we have + // to prepare our list ahead of time.) + _keepAliveBucket.values.where((RenderBox child) { + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + return !childParentData.keepAlive; + }).toList().forEach(_childManager.removeChild); + assert(_keepAliveBucket.values.where((RenderBox child) { + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + return !childParentData.keepAlive; + }).isEmpty); + }); + } + + /// Returns the index of the given child, as given by the + /// [SliverMultiBoxAdaptorParentData.index] field of the child's [parentData]. + int indexOf(RenderBox child) { + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + assert(childParentData.index != null); + return childParentData.index!; + } + + /// Returns the dimension of the given child in the main axis, as given by the + /// child's [RenderBox.size] property. This is only valid after layout. + @protected + double paintExtentOf(RenderBox child) { + assert(child.hasSize); + switch (constraints.axis) { + case Axis.horizontal: + return child.size.width; + case Axis.vertical: + return child.size.height; + } + } + + @override + bool hitTestChildren(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }) { + RenderBox? child = lastChild; + final BoxHitTestResult boxResult = BoxHitTestResult.wrap(result); + while (child != null) { + if (hitTestBoxChild(boxResult, child, mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition)) { + return true; + } + child = childBefore(child); + } + return false; + } + + @override + double childMainAxisPosition(RenderBox child) { + return childScrollOffset(child)! - constraints.scrollOffset; + } + + @override + double? childScrollOffset(RenderObject child) { + assert(child.parent == this); + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + return childParentData.layoutOffset; + } + + @override + bool paintsChild(RenderBox child) { + final SliverMultiBoxAdaptorParentData? childParentData = child.parentData as SliverMultiBoxAdaptorParentData?; + return childParentData?.index != null && + !_keepAliveBucket.containsKey(childParentData!.index); + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + if (!paintsChild(child)) { + // This can happen if some child asks for the global transform even though + // they are not getting painted. In that case, the transform sets set to + // zero since [applyPaintTransformForBoxChild] would end up throwing due + // to the child not being configured correctly for applying a transform. + // There's no assert here because asking for the paint transform is a + // valid thing to do even if a child would not be painted, but there is no + // meaningful non-zero matrix to use in this case. + transform.setZero(); + } else { + applyPaintTransformForBoxChild(child, transform); + } + } + + @override + void paint(PaintingContext context, Offset offset) { + if (firstChild == null) { + return; + } + // offset is to the top-left corner, regardless of our axis direction. + // originOffset gives us the delta from the real origin to the origin in the axis direction. + final Offset mainAxisUnit, crossAxisUnit, originOffset; + final bool addExtent; + switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) { + case AxisDirection.up: + mainAxisUnit = const Offset(0.0, -1.0); + crossAxisUnit = const Offset(1.0, 0.0); + originOffset = offset + Offset(0.0, geometry!.paintExtent); + addExtent = true; + case AxisDirection.right: + mainAxisUnit = const Offset(1.0, 0.0); + crossAxisUnit = const Offset(0.0, 1.0); + originOffset = offset; + addExtent = false; + case AxisDirection.down: + mainAxisUnit = const Offset(0.0, 1.0); + crossAxisUnit = const Offset(1.0, 0.0); + originOffset = offset; + addExtent = false; + case AxisDirection.left: + mainAxisUnit = const Offset(-1.0, 0.0); + crossAxisUnit = const Offset(0.0, 1.0); + originOffset = offset + Offset(geometry!.paintExtent, 0.0); + addExtent = true; + } + RenderBox? child = firstChild; + while (child != null) { + final double mainAxisDelta = childMainAxisPosition(child); + final double crossAxisDelta = childCrossAxisPosition(child); + Offset childOffset = Offset( + originOffset.dx + mainAxisUnit.dx * mainAxisDelta + crossAxisUnit.dx * crossAxisDelta, + originOffset.dy + mainAxisUnit.dy * mainAxisDelta + crossAxisUnit.dy * crossAxisDelta, + ); + if (addExtent) { + childOffset += mainAxisUnit * paintExtentOf(child); + } + + // If the child's visible interval (mainAxisDelta, mainAxisDelta + paintExtentOf(child)) + // does not intersect the paint extent interval (0, constraints.remainingPaintExtent), it's hidden. + if (mainAxisDelta < constraints.remainingPaintExtent && mainAxisDelta + paintExtentOf(child) > 0) { + context.paintChild(child, childOffset); + } + + child = childAfter(child); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsNode.message(firstChild != null ? 'currently live children: ${indexOf(firstChild!)} to ${indexOf(lastChild!)}' : 'no children current live')); + } + + /// Asserts that the reified child list is not empty and has a contiguous + /// sequence of indices. + /// + /// Always returns true. + bool debugAssertChildListIsNonEmptyAndContiguous() { + assert(() { + assert(firstChild != null); + int index = indexOf(firstChild!); + RenderBox? child = childAfter(firstChild!); + while (child != null) { + index += 1; + assert(indexOf(child) == index); + child = childAfter(child); + } + return true; + }()); + return true; + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<DiagnosticsNode> children = <DiagnosticsNode>[]; + if (firstChild != null) { + RenderBox? child = firstChild; + while (true) { + final SliverMultiBoxAdaptorParentData childParentData = child!.parentData! as SliverMultiBoxAdaptorParentData; + children.add(child.toDiagnosticsNode(name: 'child with index ${childParentData.index}')); + if (child == lastChild) { + break; + } + child = childParentData.nextSibling; + } + } + if (_keepAliveBucket.isNotEmpty) { + final List<int> indices = _keepAliveBucket.keys.toList()..sort(); + for (final int index in indices) { + children.add(_keepAliveBucket[index]!.toDiagnosticsNode( + name: 'child with index $index (kept alive but not laid out)', + style: DiagnosticsTreeStyle.offstage, + )); + } + } + return children; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_padding.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_padding.dart new file mode 100644 index 0000000000000000000000000000000000000000..62540d965571695da9edf950ae69391b4f7aa3f0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_padding.dart @@ -0,0 +1,370 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:vector_math/vector_math_64.dart'; + +import 'debug.dart'; +import 'object.dart'; +import 'sliver.dart'; + +/// Insets a [RenderSliver] by applying [resolvedPadding] on each side. +/// +/// A [RenderSliverEdgeInsetsPadding] subclass wraps the [SliverGeometry.layoutExtent] +/// of its child. Any incoming [SliverConstraints.overlap] is ignored and not +/// passed on to the child. +/// +/// {@template flutter.rendering.RenderSliverEdgeInsetsPadding} +/// Applying padding in the main extent of the viewport to slivers that have scroll effects is likely to have +/// undesired effects. For example, wrapping a [SliverPersistentHeader] with +/// `pinned:true` will cause only the appbar to stay pinned while the padding will scroll away. +/// {@endtemplate} +abstract class RenderSliverEdgeInsetsPadding extends RenderSliver with RenderObjectWithChildMixin<RenderSliver> { + /// The amount to pad the child in each dimension. + /// + /// The offsets are specified in terms of visual edges, left, top, right, and + /// bottom. These values are not affected by the [TextDirection]. + /// + /// Must not be null or contain negative values when [performLayout] is called. + EdgeInsets? get resolvedPadding; + + /// The padding in the scroll direction on the side nearest the 0.0 scroll direction. + /// + /// Only valid after layout has started, since before layout the render object + /// doesn't know what direction it will be laid out in. + double get beforePadding { + assert(resolvedPadding != null); + switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) { + case AxisDirection.up: + return resolvedPadding!.bottom; + case AxisDirection.right: + return resolvedPadding!.left; + case AxisDirection.down: + return resolvedPadding!.top; + case AxisDirection.left: + return resolvedPadding!.right; + } + } + + /// The padding in the scroll direction on the side furthest from the 0.0 scroll offset. + /// + /// Only valid after layout has started, since before layout the render object + /// doesn't know what direction it will be laid out in. + double get afterPadding { + assert(resolvedPadding != null); + switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) { + case AxisDirection.up: + return resolvedPadding!.top; + case AxisDirection.right: + return resolvedPadding!.right; + case AxisDirection.down: + return resolvedPadding!.bottom; + case AxisDirection.left: + return resolvedPadding!.left; + } + } + + /// The total padding in the [SliverConstraints.axisDirection]. (In other + /// words, for a vertical downwards-growing list, the sum of the padding on + /// the top and bottom.) + /// + /// Only valid after layout has started, since before layout the render object + /// doesn't know what direction it will be laid out in. + double get mainAxisPadding { + assert(resolvedPadding != null); + return resolvedPadding!.along(constraints.axis); + } + + /// The total padding in the cross-axis direction. (In other words, for a + /// vertical downwards-growing list, the sum of the padding on the left and + /// right.) + /// + /// Only valid after layout has started, since before layout the render object + /// doesn't know what direction it will be laid out in. + double get crossAxisPadding { + assert(resolvedPadding != null); + switch (constraints.axis) { + case Axis.horizontal: + return resolvedPadding!.vertical; + case Axis.vertical: + return resolvedPadding!.horizontal; + } + } + + @override + void setupParentData(RenderObject child) { + if (child.parentData is! SliverPhysicalParentData) { + child.parentData = SliverPhysicalParentData(); + } + } + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + assert(resolvedPadding != null); + final double beforePadding = this.beforePadding; + final double afterPadding = this.afterPadding; + final double mainAxisPadding = this.mainAxisPadding; + final double crossAxisPadding = this.crossAxisPadding; + if (child == null) { + final double paintExtent = calculatePaintOffset( + constraints, + from: 0.0, + to: mainAxisPadding, + ); + final double cacheExtent = calculateCacheOffset( + constraints, + from: 0.0, + to: mainAxisPadding, + ); + geometry = SliverGeometry( + scrollExtent: mainAxisPadding, + paintExtent: math.min(paintExtent, constraints.remainingPaintExtent), + maxPaintExtent: mainAxisPadding, + cacheExtent: cacheExtent, + ); + return; + } + final double beforePaddingPaintExtent = calculatePaintOffset( + constraints, + from: 0.0, + to: beforePadding, + ); + double overlap = constraints.overlap; + if (overlap > 0) { + overlap = math.max(0.0, constraints.overlap - beforePaddingPaintExtent); + } + child!.layout( + constraints.copyWith( + scrollOffset: math.max(0.0, constraints.scrollOffset - beforePadding), + cacheOrigin: math.min(0.0, constraints.cacheOrigin + beforePadding), + overlap: overlap, + remainingPaintExtent: constraints.remainingPaintExtent - calculatePaintOffset(constraints, from: 0.0, to: beforePadding), + remainingCacheExtent: constraints.remainingCacheExtent - calculateCacheOffset(constraints, from: 0.0, to: beforePadding), + crossAxisExtent: math.max(0.0, constraints.crossAxisExtent - crossAxisPadding), + precedingScrollExtent: beforePadding + constraints.precedingScrollExtent, + ), + parentUsesSize: true, + ); + final SliverGeometry childLayoutGeometry = child!.geometry!; + if (childLayoutGeometry.scrollOffsetCorrection != null) { + geometry = SliverGeometry( + scrollOffsetCorrection: childLayoutGeometry.scrollOffsetCorrection, + ); + return; + } + final double afterPaddingPaintExtent = calculatePaintOffset( + constraints, + from: beforePadding + childLayoutGeometry.scrollExtent, + to: mainAxisPadding + childLayoutGeometry.scrollExtent, + ); + final double mainAxisPaddingPaintExtent = beforePaddingPaintExtent + afterPaddingPaintExtent; + final double beforePaddingCacheExtent = calculateCacheOffset( + constraints, + from: 0.0, + to: beforePadding, + ); + final double afterPaddingCacheExtent = calculateCacheOffset( + constraints, + from: beforePadding + childLayoutGeometry.scrollExtent, + to: mainAxisPadding + childLayoutGeometry.scrollExtent, + ); + final double mainAxisPaddingCacheExtent = afterPaddingCacheExtent + beforePaddingCacheExtent; + final double paintExtent = math.min( + beforePaddingPaintExtent + math.max(childLayoutGeometry.paintExtent, childLayoutGeometry.layoutExtent + afterPaddingPaintExtent), + constraints.remainingPaintExtent, + ); + geometry = SliverGeometry( + paintOrigin: childLayoutGeometry.paintOrigin, + scrollExtent: mainAxisPadding + childLayoutGeometry.scrollExtent, + paintExtent: paintExtent, + layoutExtent: math.min(mainAxisPaddingPaintExtent + childLayoutGeometry.layoutExtent, paintExtent), + cacheExtent: math.min(mainAxisPaddingCacheExtent + childLayoutGeometry.cacheExtent, constraints.remainingCacheExtent), + maxPaintExtent: mainAxisPadding + childLayoutGeometry.maxPaintExtent, + hitTestExtent: math.max( + mainAxisPaddingPaintExtent + childLayoutGeometry.paintExtent, + beforePaddingPaintExtent + childLayoutGeometry.hitTestExtent, + ), + hasVisualOverflow: childLayoutGeometry.hasVisualOverflow, + ); + + final SliverPhysicalParentData childParentData = child!.parentData! as SliverPhysicalParentData; + switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) { + case AxisDirection.up: + childParentData.paintOffset = Offset(resolvedPadding!.left, calculatePaintOffset(constraints, from: resolvedPadding!.bottom + childLayoutGeometry.scrollExtent, to: resolvedPadding!.bottom + childLayoutGeometry.scrollExtent + resolvedPadding!.top)); + case AxisDirection.right: + childParentData.paintOffset = Offset(calculatePaintOffset(constraints, from: 0.0, to: resolvedPadding!.left), resolvedPadding!.top); + case AxisDirection.down: + childParentData.paintOffset = Offset(resolvedPadding!.left, calculatePaintOffset(constraints, from: 0.0, to: resolvedPadding!.top)); + case AxisDirection.left: + childParentData.paintOffset = Offset(calculatePaintOffset(constraints, from: resolvedPadding!.right + childLayoutGeometry.scrollExtent, to: resolvedPadding!.right + childLayoutGeometry.scrollExtent + resolvedPadding!.left), resolvedPadding!.top); + } + assert(beforePadding == this.beforePadding); + assert(afterPadding == this.afterPadding); + assert(mainAxisPadding == this.mainAxisPadding); + assert(crossAxisPadding == this.crossAxisPadding); + } + + @override + bool hitTestChildren(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }) { + if (child != null && child!.geometry!.hitTestExtent > 0.0) { + final SliverPhysicalParentData childParentData = child!.parentData! as SliverPhysicalParentData; + result.addWithAxisOffset( + mainAxisPosition: mainAxisPosition, + crossAxisPosition: crossAxisPosition, + mainAxisOffset: childMainAxisPosition(child!), + crossAxisOffset: childCrossAxisPosition(child!), + paintOffset: childParentData.paintOffset, + hitTest: child!.hitTest, + ); + } + return false; + } + + @override + double childMainAxisPosition(RenderSliver child) { + assert(child == this.child); + return calculatePaintOffset(constraints, from: 0.0, to: beforePadding); + } + + @override + double childCrossAxisPosition(RenderSliver child) { + assert(child == this.child); + assert(resolvedPadding != null); + switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) { + case AxisDirection.up: + case AxisDirection.down: + return resolvedPadding!.left; + case AxisDirection.left: + case AxisDirection.right: + return resolvedPadding!.top; + } + } + + @override + double? childScrollOffset(RenderObject child) { + assert(child.parent == this); + return beforePadding; + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + assert(child == this.child); + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + childParentData.applyPaintTransform(transform); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null && child!.geometry!.visible) { + final SliverPhysicalParentData childParentData = child!.parentData! as SliverPhysicalParentData; + context.paintChild(child!, offset + childParentData.paintOffset); + } + } + + @override + void debugPaint(PaintingContext context, Offset offset) { + super.debugPaint(context, offset); + assert(() { + if (debugPaintSizeEnabled) { + final Size parentSize = getAbsoluteSize(); + final Rect outerRect = offset & parentSize; + Rect? innerRect; + if (child != null) { + final Size childSize = child!.getAbsoluteSize(); + final SliverPhysicalParentData childParentData = child!.parentData! as SliverPhysicalParentData; + innerRect = (offset + childParentData.paintOffset) & childSize; + assert(innerRect.top >= outerRect.top); + assert(innerRect.left >= outerRect.left); + assert(innerRect.right <= outerRect.right); + assert(innerRect.bottom <= outerRect.bottom); + } + debugPaintPadding(context.canvas, outerRect, innerRect); + } + return true; + }()); + } +} + +/// Insets a [RenderSliver], applying padding on each side. +/// +/// A [RenderSliverPadding] object wraps the [SliverGeometry.layoutExtent] of +/// its child. Any incoming [SliverConstraints.overlap] is ignored and not +/// passed on to the child. +/// +/// {@macro flutter.rendering.RenderSliverEdgeInsetsPadding} +class RenderSliverPadding extends RenderSliverEdgeInsetsPadding { + /// Creates a render object that insets its child in a viewport. + /// + /// The [padding] argument must have non-negative insets. + RenderSliverPadding({ + required EdgeInsetsGeometry padding, + TextDirection? textDirection, + RenderSliver? child, + }) : assert(padding.isNonNegative), + _padding = padding, + _textDirection = textDirection { + this.child = child; + } + + @override + EdgeInsets? get resolvedPadding => _resolvedPadding; + EdgeInsets? _resolvedPadding; + + void _resolve() { + if (resolvedPadding != null) { + return; + } + _resolvedPadding = padding.resolve(textDirection); + assert(resolvedPadding!.isNonNegative); + } + + void _markNeedsResolution() { + _resolvedPadding = null; + markNeedsLayout(); + } + + /// The amount to pad the child in each dimension. + /// + /// If this is set to an [EdgeInsetsDirectional] object, then [textDirection] + /// must not be null. + EdgeInsetsGeometry get padding => _padding; + EdgeInsetsGeometry _padding; + set padding(EdgeInsetsGeometry value) { + assert(padding.isNonNegative); + if (_padding == value) { + return; + } + _padding = value; + _markNeedsResolution(); + } + + /// The text direction with which to resolve [padding]. + /// + /// This may be changed to null, but only after the [padding] has been changed + /// to a value that does not depend on the direction. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + _markNeedsResolution(); + } + + @override + void performLayout() { + _resolve(); + super.performLayout(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_persistent_header.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_persistent_header.dart new file mode 100644 index 0000000000000000000000000000000000000000..141bcb6ea0e863cc27203b0d091244cd64add768 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_persistent_header.dart @@ -0,0 +1,822 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/semantics.dart'; + +import 'box.dart'; +import 'object.dart'; +import 'sliver.dart'; +import 'viewport.dart'; +import 'viewport_offset.dart'; + +// Trims the specified edges of the given `Rect` [original], so that they do not +// exceed the given values. +Rect? _trim( + Rect? original, { + double top = -double.infinity, + double right = double.infinity, + double bottom = double.infinity, + double left = -double.infinity, +}) => original?.intersect(Rect.fromLTRB(left, top, right, bottom)); + +/// Specifies how a stretched header is to trigger an [AsyncCallback]. +/// +/// See also: +/// +/// * [SliverAppBar], which creates a header that can be stretched into an +/// overscroll area and trigger a callback function. +class OverScrollHeaderStretchConfiguration { + /// Creates an object that specifies how a stretched header may activate an + /// [AsyncCallback]. + OverScrollHeaderStretchConfiguration({ + this.stretchTriggerOffset = 100.0, + this.onStretchTrigger, + }); + + /// The offset of overscroll required to trigger the [onStretchTrigger]. + final double stretchTriggerOffset; + + /// The callback function to be executed when a user over-scrolls to the + /// offset specified by [stretchTriggerOffset]. + final AsyncCallback? onStretchTrigger; +} + +/// {@template flutter.rendering.PersistentHeaderShowOnScreenConfiguration} +/// Specifies how a pinned header or a floating header should react to +/// [RenderObject.showOnScreen] calls. +/// {@endtemplate} +@immutable +class PersistentHeaderShowOnScreenConfiguration { + /// Creates an object that specifies how a pinned or floating persistent header + /// should behave in response to [RenderObject.showOnScreen] calls. + const PersistentHeaderShowOnScreenConfiguration({ + this.minShowOnScreenExtent = double.negativeInfinity, + this.maxShowOnScreenExtent = double.infinity, + }) : assert(minShowOnScreenExtent <= maxShowOnScreenExtent); + + /// The smallest the floating header can expand to in the main axis direction, + /// in response to a [RenderObject.showOnScreen] call, in addition to its + /// [RenderSliverPersistentHeader.minExtent]. + /// + /// When a floating persistent header is told to show a [Rect] on screen, it + /// may expand itself to accommodate the [Rect]. The minimum extent that is + /// allowed for such expansion is either + /// [RenderSliverPersistentHeader.minExtent] or [minShowOnScreenExtent], + /// whichever is larger. If the persistent header's current extent is already + /// larger than that maximum extent, it will remain unchanged. + /// + /// This parameter can be set to the persistent header's `maxExtent` (or + /// `double.infinity`) so the persistent header will always try to expand when + /// [RenderObject.showOnScreen] is called on it. + /// + /// Defaults to [double.negativeInfinity], must be less than or equal to + /// [maxShowOnScreenExtent]. Has no effect unless the persistent header is a + /// floating header. + final double minShowOnScreenExtent; + + /// The biggest the floating header can expand to in the main axis direction, + /// in response to a [RenderObject.showOnScreen] call, in addition to its + /// [RenderSliverPersistentHeader.maxExtent]. + /// + /// When a floating persistent header is told to show a [Rect] on screen, it + /// may expand itself to accommodate the [Rect]. The maximum extent that is + /// allowed for such expansion is either + /// [RenderSliverPersistentHeader.maxExtent] or [maxShowOnScreenExtent], + /// whichever is smaller. If the persistent header's current extent is already + /// larger than that maximum extent, it will remain unchanged. + /// + /// This parameter can be set to the persistent header's `minExtent` (or + /// `double.negativeInfinity`) so the persistent header will never try to + /// expand when [RenderObject.showOnScreen] is called on it. + /// + /// Defaults to [double.infinity], must be greater than or equal to + /// [minShowOnScreenExtent]. Has no effect unless the persistent header is a + /// floating header. + final double maxShowOnScreenExtent; +} + +/// A base class for slivers that have a [RenderBox] child which scrolls +/// normally, except that when it hits the leading edge (typically the top) of +/// the viewport, it shrinks to a minimum size ([minExtent]). +/// +/// This class primarily provides helpers for managing the child, in particular: +/// +/// * [layoutChild], which applies min and max extents and a scroll offset to +/// lay out the child. This is normally called from [performLayout]. +/// +/// * [childExtent], to convert the child's box layout dimensions to the sliver +/// geometry model. +/// +/// * hit testing, painting, and other details of the sliver protocol. +/// +/// Subclasses must implement [performLayout], [minExtent], and [maxExtent], and +/// typically also will implement [updateChild]. +abstract class RenderSliverPersistentHeader extends RenderSliver with RenderObjectWithChildMixin<RenderBox>, RenderSliverHelpers { + /// Creates a sliver that changes its size when scrolled to the start of the + /// viewport. + /// + /// This is an abstract class; this constructor only initializes the [child]. + RenderSliverPersistentHeader({ + RenderBox? child, + this.stretchConfiguration, + }) { + this.child = child; + } + + late double _lastStretchOffset; + + /// The biggest that this render object can become, in the main axis direction. + /// + /// This value should not be based on the child. If it changes, call + /// [markNeedsLayout]. + double get maxExtent; + + /// The smallest that this render object can become, in the main axis direction. + /// + /// If this is based on the intrinsic dimensions of the child, the child + /// should be measured during [updateChild] and the value cached and returned + /// here. The [updateChild] method will automatically be invoked any time the + /// child changes its intrinsic dimensions. + double get minExtent; + + /// The dimension of the child in the main axis. + @protected + double get childExtent { + if (child == null) { + return 0.0; + } + assert(child!.hasSize); + switch (constraints.axis) { + case Axis.vertical: + return child!.size.height; + case Axis.horizontal: + return child!.size.width; + } + } + + bool _needsUpdateChild = true; + double _lastShrinkOffset = 0.0; + bool _lastOverlapsContent = false; + + /// Defines the parameters used to execute an [AsyncCallback] when a + /// stretching header over-scrolls. + /// + /// If [stretchConfiguration] is null then callback is not triggered. + /// + /// See also: + /// + /// * [SliverAppBar], which creates a header that can stretched into an + /// overscroll area and trigger a callback function. + OverScrollHeaderStretchConfiguration? stretchConfiguration; + + /// Update the child render object if necessary. + /// + /// Called before the first layout, any time [markNeedsLayout] is called, and + /// any time the scroll offset changes. The `shrinkOffset` is the difference + /// between the [maxExtent] and the current size. Zero means the header is + /// fully expanded, any greater number up to [maxExtent] means that the header + /// has been scrolled by that much. The `overlapsContent` argument is true if + /// the sliver's leading edge is beyond its normal place in the viewport + /// contents, and false otherwise. It may still paint beyond its normal place + /// if the [minExtent] after this call is greater than the amount of space that + /// would normally be left. + /// + /// The render object will size itself to the larger of (a) the [maxExtent] + /// minus the child's intrinsic height and (b) the [maxExtent] minus the + /// shrink offset. + /// + /// When this method is called by [layoutChild], the [child] can be set, + /// mutated, or replaced. (It should not be called outside [layoutChild].) + /// + /// Any time this method would mutate the child, call [markNeedsLayout]. + @protected + void updateChild(double shrinkOffset, bool overlapsContent) { } + + @override + void markNeedsLayout() { + // This is automatically called whenever the child's intrinsic dimensions + // change, at which point we should remeasure them during the next layout. + _needsUpdateChild = true; + super.markNeedsLayout(); + } + + /// Lays out the [child]. + /// + /// This is called by [performLayout]. It applies the given `scrollOffset` + /// (which need not match the offset given by the [constraints]) and the + /// `maxExtent` (which need not match the value returned by the [maxExtent] + /// getter). + /// + /// The `overlapsContent` argument is passed to [updateChild]. + @protected + void layoutChild(double scrollOffset, double maxExtent, { bool overlapsContent = false }) { + final double shrinkOffset = math.min(scrollOffset, maxExtent); + if (_needsUpdateChild || _lastShrinkOffset != shrinkOffset || _lastOverlapsContent != overlapsContent) { + invokeLayoutCallback<SliverConstraints>((SliverConstraints constraints) { + assert(constraints == this.constraints); + updateChild(shrinkOffset, overlapsContent); + }); + _lastShrinkOffset = shrinkOffset; + _lastOverlapsContent = overlapsContent; + _needsUpdateChild = false; + } + assert(() { + if (minExtent <= maxExtent) { + return true; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The maxExtent for this $runtimeType is less than its minExtent.'), + DoubleProperty('The specified maxExtent was', maxExtent), + DoubleProperty('The specified minExtent was', minExtent), + ]); + }()); + double stretchOffset = 0.0; + if (stretchConfiguration != null && constraints.scrollOffset == 0.0) { + stretchOffset += constraints.overlap.abs(); + } + + child?.layout( + constraints.asBoxConstraints( + maxExtent: math.max(minExtent, maxExtent - shrinkOffset) + stretchOffset, + ), + parentUsesSize: true, + ); + + if (stretchConfiguration != null && + stretchConfiguration!.onStretchTrigger != null && + stretchOffset >= stretchConfiguration!.stretchTriggerOffset && + _lastStretchOffset <= stretchConfiguration!.stretchTriggerOffset) { + stretchConfiguration!.onStretchTrigger!(); + } + _lastStretchOffset = stretchOffset; + } + + /// Returns the distance from the leading _visible_ edge of the sliver to the + /// side of the child closest to that edge, in the scroll axis direction. + /// + /// For example, if the [constraints] describe this sliver as having an axis + /// direction of [AxisDirection.down], then this is the distance from the top + /// of the visible portion of the sliver to the top of the child. If the child + /// is scrolled partially off the top of the viewport, then this will be + /// negative. On the other hand, if the [constraints] describe this sliver as + /// having an axis direction of [AxisDirection.up], then this is the distance + /// from the bottom of the visible portion of the sliver to the bottom of the + /// child. In both cases, this is the direction of increasing + /// [SliverConstraints.scrollOffset]. + /// + /// Calling this when the child is not visible is not valid. + /// + /// The argument must be the value of the [child] property. + /// + /// This must be implemented by [RenderSliverPersistentHeader] subclasses. + /// + /// If there is no child, this should return 0.0. + @override + double childMainAxisPosition(covariant RenderObject child) => super.childMainAxisPosition(child); + + @override + bool hitTestChildren(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }) { + assert(geometry!.hitTestExtent > 0.0); + if (child != null) { + return hitTestBoxChild(BoxHitTestResult.wrap(result), child!, mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition); + } + return false; + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + assert(child == this.child); + applyPaintTransformForBoxChild(child as RenderBox, transform); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null && geometry!.visible) { + switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) { + case AxisDirection.up: + offset += Offset(0.0, geometry!.paintExtent - childMainAxisPosition(child!) - childExtent); + case AxisDirection.down: + offset += Offset(0.0, childMainAxisPosition(child!)); + case AxisDirection.left: + offset += Offset(geometry!.paintExtent - childMainAxisPosition(child!) - childExtent, 0.0); + case AxisDirection.right: + offset += Offset(childMainAxisPosition(child!), 0.0); + } + context.paintChild(child!, offset); + } + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.addTagForChildren(RenderViewport.excludeFromScrolling); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty.lazy('maxExtent', () => maxExtent)); + properties.add(DoubleProperty.lazy('child position', () => childMainAxisPosition(child!))); + } +} + +/// A sliver with a [RenderBox] child which scrolls normally, except that when +/// it hits the leading edge (typically the top) of the viewport, it shrinks to +/// a minimum size before continuing to scroll. +/// +/// This sliver makes no effort to avoid overlapping other content. +abstract class RenderSliverScrollingPersistentHeader extends RenderSliverPersistentHeader { + /// Creates a sliver that shrinks when it hits the start of the viewport, then + /// scrolls off. + RenderSliverScrollingPersistentHeader({ + super.child, + super.stretchConfiguration, + }); + + // Distance from our leading edge to the child's leading edge, in the axis + // direction. Negative if we're scrolled off the top. + double? _childPosition; + + /// Updates [geometry], and returns the new value for [childMainAxisPosition]. + /// + /// This is used by [performLayout]. + @protected + double updateGeometry() { + double stretchOffset = 0.0; + if (stretchConfiguration != null) { + stretchOffset += constraints.overlap.abs(); + } + final double maxExtent = this.maxExtent; + final double paintExtent = maxExtent - constraints.scrollOffset; + geometry = SliverGeometry( + scrollExtent: maxExtent, + paintOrigin: math.min(constraints.overlap, 0.0), + paintExtent: clampDouble(paintExtent, 0.0, constraints.remainingPaintExtent), + maxPaintExtent: maxExtent + stretchOffset, + hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity. + ); + return stretchOffset > 0 ? 0.0 : math.min(0.0, paintExtent - childExtent); + } + + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + final double maxExtent = this.maxExtent; + layoutChild(constraints.scrollOffset, maxExtent); + final double paintExtent = maxExtent - constraints.scrollOffset; + geometry = SliverGeometry( + scrollExtent: maxExtent, + paintOrigin: math.min(constraints.overlap, 0.0), + paintExtent: clampDouble(paintExtent, 0.0, constraints.remainingPaintExtent), + maxPaintExtent: maxExtent, + hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity. + ); + _childPosition = updateGeometry(); + } + + @override + double childMainAxisPosition(RenderBox child) { + assert(child == this.child); + assert(_childPosition != null); + return _childPosition!; + } +} + +/// A sliver with a [RenderBox] child which never scrolls off the viewport in +/// the positive scroll direction, and which first scrolls on at a full size but +/// then shrinks as the viewport continues to scroll. +/// +/// This sliver avoids overlapping other earlier slivers where possible. +abstract class RenderSliverPinnedPersistentHeader extends RenderSliverPersistentHeader { + /// Creates a sliver that shrinks when it hits the start of the viewport, then + /// stays pinned there. + RenderSliverPinnedPersistentHeader({ + super.child, + super.stretchConfiguration, + this.showOnScreenConfiguration = const PersistentHeaderShowOnScreenConfiguration(), + }); + + /// Specifies the persistent header's behavior when `showOnScreen` is called. + /// + /// If set to null, the persistent header will delegate the `showOnScreen` call + /// to it's parent [RenderObject]. + PersistentHeaderShowOnScreenConfiguration? showOnScreenConfiguration; + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + final double maxExtent = this.maxExtent; + final bool overlapsContent = constraints.overlap > 0.0; + layoutChild(constraints.scrollOffset, maxExtent, overlapsContent: overlapsContent); + final double effectiveRemainingPaintExtent = math.max(0, constraints.remainingPaintExtent - constraints.overlap); + final double layoutExtent = clampDouble(maxExtent - constraints.scrollOffset, 0.0, effectiveRemainingPaintExtent); + final double stretchOffset = stretchConfiguration != null ? + constraints.overlap.abs() : + 0.0; + geometry = SliverGeometry( + scrollExtent: maxExtent, + paintOrigin: constraints.overlap, + paintExtent: math.min(childExtent, effectiveRemainingPaintExtent), + layoutExtent: layoutExtent, + maxPaintExtent: maxExtent + stretchOffset, + maxScrollObstructionExtent: minExtent, + cacheExtent: layoutExtent > 0.0 ? -constraints.cacheOrigin + layoutExtent : layoutExtent, + hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity. + ); + } + + @override + double childMainAxisPosition(RenderBox child) => 0.0; + + @override + void showOnScreen({ + RenderObject? descendant, + Rect? rect, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + }) { + final Rect? localBounds = descendant != null + ? MatrixUtils.transformRect(descendant.getTransformTo(this), rect ?? descendant.paintBounds) + : rect; + + Rect? newRect; + switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) { + case AxisDirection.up: + newRect = _trim(localBounds, bottom: childExtent); + case AxisDirection.right: + newRect = _trim(localBounds, left: 0); + case AxisDirection.down: + newRect = _trim(localBounds, top: 0); + case AxisDirection.left: + newRect = _trim(localBounds, right: childExtent); + } + + super.showOnScreen( + descendant: this, + rect: newRect, + duration: duration, + curve: curve, + ); + } +} + +/// Specifies how a floating header is to be "snapped" (animated) into or out +/// of view. +/// +/// See also: +/// +/// * [RenderSliverFloatingPersistentHeader.maybeStartSnapAnimation] and +/// [RenderSliverFloatingPersistentHeader.maybeStopSnapAnimation], which +/// start or stop the floating header's animation. +/// * [SliverAppBar], which creates a header that can be pinned, floating, +/// and snapped into view via the corresponding parameters. +class FloatingHeaderSnapConfiguration { + /// Creates an object that specifies how a floating header is to be "snapped" + /// (animated) into or out of view. + FloatingHeaderSnapConfiguration({ + this.curve = Curves.ease, + this.duration = const Duration(milliseconds: 300), + }); + + /// The snap animation curve. + final Curve curve; + + /// The snap animation's duration. + final Duration duration; +} + +/// A sliver with a [RenderBox] child which shrinks and scrolls like a +/// [RenderSliverScrollingPersistentHeader], but immediately comes back when the +/// user scrolls in the reverse direction. +/// +/// See also: +/// +/// * [RenderSliverFloatingPinnedPersistentHeader], which is similar but sticks +/// to the start of the viewport rather than scrolling off. +abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersistentHeader { + /// Creates a sliver that shrinks when it hits the start of the viewport, then + /// scrolls off, and comes back immediately when the user reverses the scroll + /// direction. + RenderSliverFloatingPersistentHeader({ + super.child, + TickerProvider? vsync, + this.snapConfiguration, + super.stretchConfiguration, + required this.showOnScreenConfiguration, + }) : _vsync = vsync; + + AnimationController? _controller; + late Animation<double> _animation; + double? _lastActualScrollOffset; + double? _effectiveScrollOffset; + // Important for pointer scrolling, which does not have the same concept of + // a hold and release scroll movement, like dragging. + // This keeps track of the last ScrollDirection when scrolling started. + ScrollDirection? _lastStartedScrollDirection; + + // Distance from our leading edge to the child's leading edge, in the axis + // direction. Negative if we're scrolled off the top. + double? _childPosition; + + @override + void detach() { + _controller?.dispose(); + _controller = null; // lazily recreated if we're reattached. + super.detach(); + } + + + /// A [TickerProvider] to use when animating the scroll position. + TickerProvider? get vsync => _vsync; + TickerProvider? _vsync; + set vsync(TickerProvider? value) { + if (value == _vsync) { + return; + } + _vsync = value; + if (value == null) { + _controller?.dispose(); + _controller = null; + } else { + _controller?.resync(value); + } + } + + /// Defines the parameters used to snap (animate) the floating header in and + /// out of view. + /// + /// If [snapConfiguration] is null then the floating header does not snap. + /// + /// See also: + /// + /// * [RenderSliverFloatingPersistentHeader.maybeStartSnapAnimation] and + /// [RenderSliverFloatingPersistentHeader.maybeStopSnapAnimation], which + /// start or stop the floating header's animation. + /// * [SliverAppBar], which creates a header that can be pinned, floating, + /// and snapped into view via the corresponding parameters. + FloatingHeaderSnapConfiguration? snapConfiguration; + + /// {@macro flutter.rendering.PersistentHeaderShowOnScreenConfiguration} + /// + /// If set to null, the persistent header will delegate the `showOnScreen` call + /// to it's parent [RenderObject]. + PersistentHeaderShowOnScreenConfiguration? showOnScreenConfiguration; + + /// Updates [geometry], and returns the new value for [childMainAxisPosition]. + /// + /// This is used by [performLayout]. + @protected + double updateGeometry() { + double stretchOffset = 0.0; + if (stretchConfiguration != null) { + stretchOffset += constraints.overlap.abs(); + } + final double maxExtent = this.maxExtent; + final double paintExtent = maxExtent - _effectiveScrollOffset!; + final double layoutExtent = maxExtent - constraints.scrollOffset; + geometry = SliverGeometry( + scrollExtent: maxExtent, + paintOrigin: math.min(constraints.overlap, 0.0), + paintExtent: clampDouble(paintExtent, 0.0, constraints.remainingPaintExtent), + layoutExtent: clampDouble(layoutExtent, 0.0, constraints.remainingPaintExtent), + maxPaintExtent: maxExtent + stretchOffset, + hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity. + ); + return stretchOffset > 0 ? 0.0 : math.min(0.0, paintExtent - childExtent); + } + + void _updateAnimation(Duration duration, double endValue, Curve curve) { + assert( + vsync != null, + 'vsync must not be null if the floating header changes size animatedly.', + ); + + final AnimationController effectiveController = + _controller ??= AnimationController(vsync: vsync!, duration: duration) + ..addListener(() { + if (_effectiveScrollOffset == _animation.value) { + return; + } + _effectiveScrollOffset = _animation.value; + markNeedsLayout(); + }); + + _animation = effectiveController.drive( + Tween<double>( + begin: _effectiveScrollOffset, + end: endValue, + ).chain(CurveTween(curve: curve)), + ); + } + + /// Update the last known ScrollDirection when scrolling began. + // ignore: use_setters_to_change_properties, (API predates enforcing the lint) + void updateScrollStartDirection(ScrollDirection direction) { + _lastStartedScrollDirection = direction; + } + + /// If the header isn't already fully exposed, then scroll it into view. + void maybeStartSnapAnimation(ScrollDirection direction) { + final FloatingHeaderSnapConfiguration? snap = snapConfiguration; + if (snap == null) { + return; + } + if (direction == ScrollDirection.forward && _effectiveScrollOffset! <= 0.0) { + return; + } + if (direction == ScrollDirection.reverse && _effectiveScrollOffset! >= maxExtent) { + return; + } + + _updateAnimation( + snap.duration, + direction == ScrollDirection.forward ? 0.0 : maxExtent, + snap.curve, + ); + _controller?.forward(from: 0.0); + } + + /// If a header snap animation or a [showOnScreen] expand animation is underway + /// then stop it. + void maybeStopSnapAnimation(ScrollDirection direction) { + _controller?.stop(); + } + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + final double maxExtent = this.maxExtent; + if (_lastActualScrollOffset != null && // We've laid out at least once to get an initial position, and either + ((constraints.scrollOffset < _lastActualScrollOffset!) || // we are scrolling back, so should reveal, or + (_effectiveScrollOffset! < maxExtent))) { // some part of it is visible, so should shrink or reveal as appropriate. + double delta = _lastActualScrollOffset! - constraints.scrollOffset; + + final bool allowFloatingExpansion = constraints.userScrollDirection == ScrollDirection.forward + || (_lastStartedScrollDirection != null && _lastStartedScrollDirection == ScrollDirection.forward); + if (allowFloatingExpansion) { + if (_effectiveScrollOffset! > maxExtent) { + // We're scrolled off-screen, but should reveal, so pretend we're just at the limit. + _effectiveScrollOffset = maxExtent; + } + } else { + if (delta > 0.0) { + // Disallow the expansion. (But allow shrinking, i.e. delta < 0.0 is fine.) + delta = 0.0; + } + } + _effectiveScrollOffset = clampDouble(_effectiveScrollOffset! - delta, 0.0, constraints.scrollOffset); + } else { + _effectiveScrollOffset = constraints.scrollOffset; + } + final bool overlapsContent = _effectiveScrollOffset! < constraints.scrollOffset; + + layoutChild( + _effectiveScrollOffset!, + maxExtent, + overlapsContent: overlapsContent, + ); + _childPosition = updateGeometry(); + _lastActualScrollOffset = constraints.scrollOffset; + } + + @override + void showOnScreen({ + RenderObject? descendant, + Rect? rect, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + }) { + final PersistentHeaderShowOnScreenConfiguration? showOnScreen = showOnScreenConfiguration; + if (showOnScreen == null) { + return super.showOnScreen(descendant: descendant, rect: rect, duration: duration, curve: curve); + } + + assert(child != null || descendant == null); + // We prefer the child's coordinate space (instead of the sliver's) because + // it's easier for us to convert the target rect into target extents: when + // the sliver is sitting above the leading edge (not possible with pinned + // headers), the leading edge of the sliver and the leading edge of the child + // will not be aligned. The only exception is when child is null (and thus + // descendant == null). + final Rect? childBounds = descendant != null + ? MatrixUtils.transformRect(descendant.getTransformTo(child), rect ?? descendant.paintBounds) + : rect; + + double targetExtent; + Rect? targetRect; + switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) { + case AxisDirection.up: + targetExtent = childExtent - (childBounds?.top ?? 0); + targetRect = _trim(childBounds, bottom: childExtent); + case AxisDirection.right: + targetExtent = childBounds?.right ?? childExtent; + targetRect = _trim(childBounds, left: 0); + case AxisDirection.down: + targetExtent = childBounds?.bottom ?? childExtent; + targetRect = _trim(childBounds, top: 0); + case AxisDirection.left: + targetExtent = childExtent - (childBounds?.left ?? 0); + targetRect = _trim(childBounds, right: childExtent); + } + + // A stretch header can have a bigger childExtent than maxExtent. + final double effectiveMaxExtent = math.max(childExtent, maxExtent); + + targetExtent = clampDouble( + clampDouble( + targetExtent, + showOnScreen.minShowOnScreenExtent, + showOnScreen.maxShowOnScreenExtent, + ), + // Clamp the value back to the valid range after applying additional + // constraints. Contracting is not allowed. + childExtent, + effectiveMaxExtent); + + // Expands the header if needed, with animation. + if (targetExtent > childExtent && _controller?.status != AnimationStatus.forward) { + final double targetScrollOffset = maxExtent - targetExtent; + assert( + vsync != null, + 'vsync must not be null if the floating header changes size animatedly.', + ); + _updateAnimation(duration, targetScrollOffset, curve); + _controller?.forward(from: 0.0); + } + + super.showOnScreen( + descendant: descendant == null ? this : child, + rect: targetRect, + duration: duration, + curve: curve, + ); + } + + @override + double childMainAxisPosition(RenderBox child) { + assert(child == this.child); + return _childPosition ?? 0.0; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('effective scroll offset', _effectiveScrollOffset)); + } +} + +/// A sliver with a [RenderBox] child which shrinks and then remains pinned to +/// the start of the viewport like a [RenderSliverPinnedPersistentHeader], but +/// immediately grows when the user scrolls in the reverse direction. +/// +/// See also: +/// +/// * [RenderSliverFloatingPersistentHeader], which is similar but scrolls off +/// the top rather than sticking to it. +abstract class RenderSliverFloatingPinnedPersistentHeader extends RenderSliverFloatingPersistentHeader { + /// Creates a sliver that shrinks when it hits the start of the viewport, then + /// stays pinned there, and grows immediately when the user reverses the + /// scroll direction. + RenderSliverFloatingPinnedPersistentHeader({ + super.child, + super.vsync, + super.snapConfiguration, + super.stretchConfiguration, + super.showOnScreenConfiguration, + }); + + @override + double updateGeometry() { + final double minExtent = this.minExtent; + final double minAllowedExtent = constraints.remainingPaintExtent > minExtent ? + minExtent : + constraints.remainingPaintExtent; + final double maxExtent = this.maxExtent; + final double paintExtent = maxExtent - _effectiveScrollOffset!; + final double clampedPaintExtent = clampDouble(paintExtent, + minAllowedExtent, + constraints.remainingPaintExtent, + ); + final double layoutExtent = maxExtent - constraints.scrollOffset; + final double stretchOffset = stretchConfiguration != null ? + constraints.overlap.abs() : + 0.0; + geometry = SliverGeometry( + scrollExtent: maxExtent, + paintOrigin: math.min(constraints.overlap, 0.0), + paintExtent: clampedPaintExtent, + layoutExtent: clampDouble(layoutExtent, 0.0, clampedPaintExtent), + maxPaintExtent: maxExtent + stretchOffset, + maxScrollObstructionExtent: minExtent, + hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity. + ); + return 0.0; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_tree.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_tree.dart new file mode 100644 index 0000000000000000000000000000000000000000..bb7e06a7804d942cd870b802ba23f71413140acd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/sliver_tree.dart @@ -0,0 +1,404 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'layer.dart'; +import 'object.dart'; +import 'sliver.dart'; +import 'sliver_fixed_extent_list.dart'; +import 'sliver_multi_box_adaptor.dart'; + +/// Represents the animation of the children of a parent [TreeSliverNode] that +/// are animating into or out of view. +/// +/// The `fromIndex` and `toIndex` are identify the animating children following +/// the parent, with the `value` representing the status of the current +/// animation. The value of `toIndex` is inclusive, meaning the child at that +/// index is included in the animating segment. +/// +/// Provided to [RenderTreeSliver] as part of +/// [RenderTreeSliver.activeAnimations] by [TreeSliver] to properly offset +/// animating children. +typedef TreeSliverNodesAnimation = ({ + int fromIndex, + int toIndex, + double value, +}); + +/// Used to pass information down to [RenderTreeSliver]. +class TreeSliverNodeParentData extends SliverMultiBoxAdaptorParentData { + /// The depth of the node, used by [RenderTreeSliver] to offset children by + /// by the [TreeSliverIndentationType]. + int depth = 0; +} + +/// The style of indentation for [TreeSliverNode]s in a [TreeSliver], as +/// handled by [RenderTreeSliver]. +/// +/// {@template flutter.rendering.TreeSliverIndentationType} +/// By default, the indentation is handled by [RenderTreeSliver]. Child nodes +/// are offset by the indentation specified by +/// [TreeSliverIndentationType.value] in the cross axis of the viewport. This +/// means the space allotted to the indentation will not be part of the space +/// made available to the Widget returned by [TreeSliver.treeNodeBuilder]. +/// +/// Alternatively, the indentation can be implemented in +/// [TreeSliver.treeNodeBuilder], with the depth of the given tree row +/// accessed by [TreeSliverNode.depth]. This allows for more customization in +/// building tree rows, such as filling the indented area with decorations or +/// ink effects. +/// +/// {@tool dartpad} +/// This example shows a highly customized [TreeSliver] configured to +/// [TreeSliverIndentationType.none]. This allows the indentation to be handled +/// by the developer in [TreeSliver.treeNodeBuilder], where a decoration is +/// used to fill the indented space. +/// +/// ** See code in examples/api/lib/widgets/sliver/sliver_tree.1.dart ** +/// {@end-tool} +/// +/// {@endtemplate} +class TreeSliverIndentationType { + const TreeSliverIndentationType._internal(double value) : _value = value; + + /// The number of pixels by which [TreeSliverNode]s will be offset according + /// to their [TreeSliverNode.depth]. + double get value => _value; + final double _value; + + /// The default indentation of child [TreeSliverNode]s in a [TreeSliver]. + /// + /// Child nodes will be offset by 10 pixels for each level in the tree. + static const TreeSliverIndentationType standard = TreeSliverIndentationType._internal(10.0); + + /// Configures no offsetting of child nodes in a [TreeSliver]. + /// + /// Useful if the indentation is implemented in the + /// [TreeSliver.treeNodeBuilder] instead for more customization options. + /// + /// Child nodes will not be offset in the tree. + static const TreeSliverIndentationType none = TreeSliverIndentationType._internal(0.0); + + /// Configures a custom offset for indenting child nodes in a + /// [TreeSliver]. + /// + /// Child nodes will be offset by the provided number of pixels in the tree. + /// The [value] must be a non negative number. + static TreeSliverIndentationType custom(double value) { + assert(value >= 0.0); + return TreeSliverIndentationType._internal(value); + } +} + +// Used during paint to delineate animating portions of the tree. +typedef _PaintSegment = ({int leadingIndex, int trailingIndex}); + +/// A sliver that places multiple [TreeSliverNode]s in a linear array along the +/// main access, while staggering nodes that are animating into and out of view. +/// +/// The extent of each child node is determined by the [itemExtentBuilder]. +/// +/// See also: +/// +/// * [TreeSliver], the widget that creates and manages this render +/// object. +class RenderTreeSliver extends RenderSliverVariedExtentList { + /// Creates the render object that lays out the [TreeSliverNode]s of a + /// [TreeSliver]. + RenderTreeSliver({ + required super.childManager, + required super.itemExtentBuilder, + required Map<UniqueKey, TreeSliverNodesAnimation> activeAnimations, + required double indentation, + }) : _activeAnimations = activeAnimations, + _indentation = indentation; + + // TODO(Piinks): There are some opportunities to cache even further as far as + // extents and layout offsets when using itemExtentBuilder from the super + // class as we do here. I want to yak shave that in a separate change. + + /// The currently active [TreeSliverNode] animations. + /// + /// Since the index of animating nodes can change at any time, the unique key + /// is used to track an animation of nodes across frames. + Map<UniqueKey, TreeSliverNodesAnimation> get activeAnimations => _activeAnimations; + Map<UniqueKey, TreeSliverNodesAnimation> _activeAnimations; + set activeAnimations(Map<UniqueKey, TreeSliverNodesAnimation> value) { + if (_activeAnimations == value) { + return; + } + _activeAnimations = value; + markNeedsLayout(); + } + + /// The number of pixels by which child nodes will be offset in the cross axis + /// based on their [TreeSliverNodeParentData.depth]. + /// + /// If zero, can alternatively offset children in + /// [TreeSliver.treeNodeBuilder] for more options to customize the + /// indented space. + double get indentation => _indentation; + double _indentation; + set indentation(double value) { + if (_indentation == value) { + return; + } + assert(indentation >= 0.0); + _indentation = value; + markNeedsLayout(); + } + + // Maps the index of parents to the animation key of their children. + final Map<int, UniqueKey> _animationLeadingIndices = <int, UniqueKey>{}; + // Maps the key of child node animations to the fixed distance they are + // traversing during the animation. Determined at the start of the animation. + final Map<UniqueKey, double> _animationOffsets = <UniqueKey, double>{}; + void _updateAnimationCache() { + _animationLeadingIndices.clear(); + _activeAnimations.forEach((UniqueKey key, TreeSliverNodesAnimation animation) { + _animationLeadingIndices[animation.fromIndex - 1] = key; + }); + // Remove any stored offsets or clip layers that are no longer actively + // animating. + _animationOffsets.removeWhere((UniqueKey key, _) => !_activeAnimations.keys.contains(key)); + _clipHandles.removeWhere((UniqueKey key, LayerHandle<ClipRectLayer> handle) { + if (!_activeAnimations.keys.contains(key)) { + handle.layer = null; + return true; + } + return false; + }); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! TreeSliverNodeParentData) { + child.parentData = TreeSliverNodeParentData(); + } + } + + @override + void dispose() { + _clipHandles.removeWhere((UniqueKey key, LayerHandle<ClipRectLayer> handle) { + handle.layer = null; + return true; + }); + super.dispose(); + } + + // TODO(Piinks): This should be made a public getter on the super class. + // Multiple subclasses are making use of it now, yak shave that refactor + // separately. + late SliverLayoutDimensions _currentLayoutDimensions; + + @override + void performLayout() { + assert( + constraints.axisDirection == AxisDirection.down, + 'TreeSliver is only supported in Viewports with an AxisDirection.down. ' + 'The current axis direction is: ${constraints.axisDirection}.', + ); + _updateAnimationCache(); + _currentLayoutDimensions = SliverLayoutDimensions( + scrollOffset: constraints.scrollOffset, + precedingScrollExtent: constraints.precedingScrollExtent, + viewportMainAxisExtent: constraints.viewportMainAxisExtent, + crossAxisExtent: constraints.crossAxisExtent, + ); + super.performLayout(); + } + + @override + int getMinChildIndexForScrollOffset(double scrollOffset, double itemExtent) { + // itemExtent is deprecated in the super class, we ignore it because we use + // the builder anyways. + return _getChildIndexForScrollOffset(scrollOffset); + } + + @override + int getMaxChildIndexForScrollOffset(double scrollOffset, double itemExtent) { + // itemExtent is deprecated in the super class, we ignore it because we use + // the builder anyways. + return _getChildIndexForScrollOffset(scrollOffset); + } + + int _getChildIndexForScrollOffset(double scrollOffset) { + if (scrollOffset == 0.0) { + return 0; + } + double position = 0.0; + int index = 0; + double totalAnimationOffset = 0.0; + double? itemExtent; + final int? childCount = childManager.estimatedChildCount; + while (position < scrollOffset) { + if (childCount != null && index > childCount - 1) { + break; + } + + itemExtent = itemExtentBuilder(index, _currentLayoutDimensions); + if (itemExtent == null) { + break; + } + if (_animationLeadingIndices.keys.contains(index)) { + final UniqueKey animationKey = _animationLeadingIndices[index]!; + if (_animationOffsets[animationKey] == null) { + // We have not computed the distance this block is traversing over the + // lifetime of the animation. + _computeAnimationOffsetFor(animationKey, position); + } + // We add the offset accounting for the animation value. + totalAnimationOffset += _animationOffsets[animationKey]! * (1 - _activeAnimations[animationKey]!.value); + } + position += itemExtent - totalAnimationOffset; + ++index; + } + return index - 1; + } + + void _computeAnimationOffsetFor(UniqueKey key, double position) { + assert(_activeAnimations[key] != null); + final double targetPosition = constraints.scrollOffset + constraints.remainingCacheExtent; + double currentPosition = position; + final int startingIndex = _activeAnimations[key]!.fromIndex; + final int lastIndex = _activeAnimations[key]!.toIndex; + int currentIndex = startingIndex; + double totalAnimatingOffset = 0.0; + // We animate only a portion of children that would be visible/in the cache + // extent, unless all children would fit on the screen. + while (currentIndex <= lastIndex && currentPosition < targetPosition) { + final double itemExtent = itemExtentBuilder(currentIndex, _currentLayoutDimensions)!; + totalAnimatingOffset += itemExtent; + currentPosition += itemExtent; + currentIndex++; + } + // For the life of this animation, which affects all children following + // startingIndex (regardless of if they are a child of the triggering + // parent), they will be offset by totalAnimatingOffset * the + // animation value. This is because even though more children can be + // scrolled into view, the same distance must be maintained for a smooth + // animation. + _animationOffsets[key] = totalAnimatingOffset; + } + + @override + double indexToLayoutOffset(double itemExtent, int index) { + // itemExtent is deprecated in the super class, we ignore it because we use + // the builder anyways. + double position = 0.0; + int currentIndex = 0; + double totalAnimationOffset = 0.0; + double? itemExtent; + final int? childCount = childManager.estimatedChildCount; + while (currentIndex < index) { + if (childCount != null && currentIndex > childCount - 1) { + break; + } + + itemExtent = itemExtentBuilder(currentIndex, _currentLayoutDimensions); + if (itemExtent == null) { + break; + } + if (_animationLeadingIndices.keys.contains(currentIndex)) { + final UniqueKey animationKey = _animationLeadingIndices[currentIndex]!; + assert(_animationOffsets[animationKey] != null); + // We add the offset accounting for the animation value. + totalAnimationOffset += _animationOffsets[animationKey]! * (1 - _activeAnimations[animationKey]!.value); + } + position += itemExtent; + currentIndex++; + } + return position - totalAnimationOffset; + } + + final Map<UniqueKey, LayerHandle<ClipRectLayer>> _clipHandles = <UniqueKey, LayerHandle<ClipRectLayer>>{}; + + @override + void paint(PaintingContext context, Offset offset) { + if (firstChild == null) { + return; + } + + RenderBox? nextChild = firstChild; + void paintUpTo( + int index, + RenderBox? startWith, + PaintingContext context, + Offset offset, + ) { + RenderBox? child = startWith; + while (child != null && indexOf(child) <= index) { + final double mainAxisDelta = childMainAxisPosition(child); + final TreeSliverNodeParentData parentData = child.parentData! as TreeSliverNodeParentData; + final Offset childOffset = Offset( + parentData.depth * indentation, + parentData.layoutOffset!, + ); + + // If the child's visible interval (mainAxisDelta, mainAxisDelta + paintExtentOf(child)) + // does not intersect the paint extent interval (0, constraints.remainingPaintExtent), it's hidden. + if (mainAxisDelta < constraints.remainingPaintExtent && mainAxisDelta + paintExtentOf(child) > 0) { + context.paintChild(child, childOffset); + } + child = childAfter(child); + } + nextChild = child; + } + if (_animationLeadingIndices.isEmpty) { + // There are no animations running. + paintUpTo(indexOf(lastChild!), firstChild, context, offset); + return; + } + + // We are animating. + // Separate animating segments to clip for any overlap. + int leadingIndex = indexOf(firstChild!); + final List<int> animationIndices = _animationLeadingIndices.keys.toList()..sort(); + final List<_PaintSegment> paintSegments = <_PaintSegment>[]; + while (animationIndices.isNotEmpty) { + final int trailingIndex = animationIndices.removeAt(0); + paintSegments.add((leadingIndex: leadingIndex, trailingIndex: trailingIndex)); + leadingIndex = trailingIndex + 1; + } + paintSegments.add((leadingIndex: leadingIndex, trailingIndex: indexOf(lastChild!))); + + // Paint, clipping for all but the first segment. + paintUpTo(paintSegments.removeAt(0).trailingIndex, nextChild, context, offset); + // Paint the rest with clip layers. + while (paintSegments.isNotEmpty) { + final _PaintSegment segment = paintSegments.removeAt(0); + + // Rect is calculated by the trailing edge of the parent (preceding + // leadingIndex), and the trailing edge of the trailing index. We cannot + // rely on the leading edge of the leading index, because it is currently + // moving. + final int parentIndex = math.max(segment.leadingIndex - 1, 0); + final double leadingOffset = indexToLayoutOffset(0.0, parentIndex) + + (parentIndex == 0 ? 0.0 : itemExtentBuilder(parentIndex, _currentLayoutDimensions)!); + final double trailingOffset = indexToLayoutOffset(0.0, segment.trailingIndex) + + itemExtentBuilder(segment.trailingIndex, _currentLayoutDimensions)!; + final Rect rect = Rect.fromPoints( + Offset(0.0, leadingOffset), + Offset(constraints.crossAxisExtent, trailingOffset), + ); + // We use the same animation key to keep track of the clip layer, unless + // this is the odd man out segment. + final UniqueKey key = _animationLeadingIndices[parentIndex]!; + _clipHandles[key] ??= LayerHandle<ClipRectLayer>(); + _clipHandles[key]!.layer = context.pushClipRect( + needsCompositing, + offset, + rect, + (PaintingContext context, Offset offset) { + paintUpTo(segment.trailingIndex, nextChild, context, offset); + }, + oldLayer: _clipHandles[key]!.layer, + ); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/stack.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/stack.dart new file mode 100644 index 0000000000000000000000000000000000000000..b17b620cb18dd47677c393c72a40dd283a5a2c45 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/stack.dart @@ -0,0 +1,788 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show lerpDouble; + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'layer.dart'; +import 'layout_helper.dart'; +import 'object.dart'; + +/// An immutable 2D, axis-aligned, floating-point rectangle whose coordinates +/// are given relative to another rectangle's edges, known as the container. +/// Since the dimensions of the rectangle are relative to those of the +/// container, this class has no width and height members. To determine the +/// width or height of the rectangle, convert it to a [Rect] using [toRect()] +/// (passing the container's own Rect), and then examine that object. +@immutable +class RelativeRect { + /// Creates a RelativeRect with the given values. + const RelativeRect.fromLTRB(this.left, this.top, this.right, this.bottom); + + /// Creates a RelativeRect from a Rect and a Size. The Rect (first argument) + /// and the RelativeRect (the output) are in the coordinate space of the + /// rectangle described by the Size, with 0,0 being at the top left. + factory RelativeRect.fromSize(Rect rect, Size container) { + return RelativeRect.fromLTRB(rect.left, rect.top, container.width - rect.right, container.height - rect.bottom); + } + + /// Creates a RelativeRect from two Rects. The second Rect provides the + /// container, the first provides the rectangle, in the same coordinate space, + /// that is to be converted to a RelativeRect. The output will be in the + /// container's coordinate space. + /// + /// For example, if the top left of the rect is at 0,0, and the top left of + /// the container is at 100,100, then the top left of the output will be at + /// -100,-100. + /// + /// If the first rect is actually in the container's coordinate space, then + /// use [RelativeRect.fromSize] and pass the container's size as the second + /// argument instead. + factory RelativeRect.fromRect(Rect rect, Rect container) { + return RelativeRect.fromLTRB( + rect.left - container.left, + rect.top - container.top, + container.right - rect.right, + container.bottom - rect.bottom, + ); + } + + /// Creates a RelativeRect from horizontal position using `start` and `end` + /// rather than `left` and `right`. + /// + /// If `textDirection` is [TextDirection.rtl], then the `start` argument is + /// used for the [right] property and the `end` argument is used for the + /// [left] property. Otherwise, if `textDirection` is [TextDirection.ltr], + /// then the `start` argument is used for the [left] property and the `end` + /// argument is used for the [right] property. + factory RelativeRect.fromDirectional({ + required TextDirection textDirection, + required double start, + required double top, + required double end, + required double bottom, + }) { + double left; + double right; + switch (textDirection) { + case TextDirection.rtl: + left = end; + right = start; + case TextDirection.ltr: + left = start; + right = end; + } + + return RelativeRect.fromLTRB(left, top, right, bottom); + } + + /// A rect that covers the entire container. + static const RelativeRect fill = RelativeRect.fromLTRB(0.0, 0.0, 0.0, 0.0); + + /// Distance from the left side of the container to the left side of this rectangle. + /// + /// May be negative if the left side of the rectangle is outside of the container. + final double left; + + /// Distance from the top side of the container to the top side of this rectangle. + /// + /// May be negative if the top side of the rectangle is outside of the container. + final double top; + + /// Distance from the right side of the container to the right side of this rectangle. + /// + /// May be positive if the right side of the rectangle is outside of the container. + final double right; + + /// Distance from the bottom side of the container to the bottom side of this rectangle. + /// + /// May be positive if the bottom side of the rectangle is outside of the container. + final double bottom; + + /// Returns whether any of the values are greater than zero. + /// + /// This corresponds to one of the sides ([left], [top], [right], or [bottom]) having + /// some positive inset towards the center. + bool get hasInsets => left > 0.0 || top > 0.0 || right > 0.0 || bottom > 0.0; + + /// Returns a new rectangle object translated by the given offset. + RelativeRect shift(Offset offset) { + return RelativeRect.fromLTRB(left + offset.dx, top + offset.dy, right - offset.dx, bottom - offset.dy); + } + + /// Returns a new rectangle with edges moved outwards by the given delta. + RelativeRect inflate(double delta) { + return RelativeRect.fromLTRB(left - delta, top - delta, right - delta, bottom - delta); + } + + /// Returns a new rectangle with edges moved inwards by the given delta. + RelativeRect deflate(double delta) { + return inflate(-delta); + } + + /// Returns a new rectangle that is the intersection of the given rectangle and this rectangle. + RelativeRect intersect(RelativeRect other) { + return RelativeRect.fromLTRB( + math.max(left, other.left), + math.max(top, other.top), + math.max(right, other.right), + math.max(bottom, other.bottom), + ); + } + + /// Convert this [RelativeRect] to a [Rect], in the coordinate space of the container. + /// + /// See also: + /// + /// * [toSize], which returns the size part of the rect, based on the size of + /// the container. + Rect toRect(Rect container) { + return Rect.fromLTRB(left, top, container.width - right, container.height - bottom); + } + + /// Convert this [RelativeRect] to a [Size], assuming a container with the given size. + /// + /// See also: + /// + /// * [toRect], which also computes the position relative to the container. + Size toSize(Size container) { + return Size(container.width - left - right, container.height - top - bottom); + } + + /// Linearly interpolate between two RelativeRects. + /// + /// If either rect is null, this function interpolates from [RelativeRect.fill]. + /// + /// {@macro dart.ui.shadow.lerp} + static RelativeRect? lerp(RelativeRect? a, RelativeRect? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return RelativeRect.fromLTRB(b!.left * t, b.top * t, b.right * t, b.bottom * t); + } + if (b == null) { + final double k = 1.0 - t; + return RelativeRect.fromLTRB(b!.left * k, b.top * k, b.right * k, b.bottom * k); + } + return RelativeRect.fromLTRB( + lerpDouble(a.left, b.left, t)!, + lerpDouble(a.top, b.top, t)!, + lerpDouble(a.right, b.right, t)!, + lerpDouble(a.bottom, b.bottom, t)!, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is RelativeRect + && other.left == left + && other.top == top + && other.right == right + && other.bottom == bottom; + } + + @override + int get hashCode => Object.hash(left, top, right, bottom); + + @override + String toString() => 'RelativeRect.fromLTRB(${left.toStringAsFixed(1)}, ${top.toStringAsFixed(1)}, ${right.toStringAsFixed(1)}, ${bottom.toStringAsFixed(1)})'; +} + +/// Parent data for use with [RenderStack]. +class StackParentData extends ContainerBoxParentData<RenderBox> { + /// The distance by which the child's top edge is inset from the top of the stack. + double? top; + + /// The distance by which the child's right edge is inset from the right of the stack. + double? right; + + /// The distance by which the child's bottom edge is inset from the bottom of the stack. + double? bottom; + + /// The distance by which the child's left edge is inset from the left of the stack. + double? left; + + /// The child's width. + /// + /// Ignored if both left and right are non-null. + double? width; + + /// The child's height. + /// + /// Ignored if both top and bottom are non-null. + double? height; + + /// Get or set the current values in terms of a RelativeRect object. + RelativeRect get rect => RelativeRect.fromLTRB(left!, top!, right!, bottom!); + set rect(RelativeRect value) { + top = value.top; + right = value.right; + bottom = value.bottom; + left = value.left; + } + + /// Whether this child is considered positioned. + /// + /// A child is positioned if any of the top, right, bottom, or left properties + /// are non-null. Positioned children do not factor into determining the size + /// of the stack but are instead placed relative to the non-positioned + /// children in the stack. + bool get isPositioned => top != null || right != null || bottom != null || left != null || width != null || height != null; + + @override + String toString() { + final List<String> values = <String>[ + if (top != null) 'top=${debugFormatDouble(top)}', + if (right != null) 'right=${debugFormatDouble(right)}', + if (bottom != null) 'bottom=${debugFormatDouble(bottom)}', + if (left != null) 'left=${debugFormatDouble(left)}', + if (width != null) 'width=${debugFormatDouble(width)}', + if (height != null) 'height=${debugFormatDouble(height)}', + ]; + if (values.isEmpty) { + values.add('not positioned'); + } + values.add(super.toString()); + return values.join('; '); + } +} + +/// How to size the non-positioned children of a [Stack]. +/// +/// This enum is used with [Stack.fit] and [RenderStack.fit] to control +/// how the [BoxConstraints] passed from the stack's parent to the stack's child +/// are adjusted. +/// +/// See also: +/// +/// * [Stack], the widget that uses this. +/// * [RenderStack], the render object that implements the stack algorithm. +enum StackFit { + /// The constraints passed to the stack from its parent are loosened. + /// + /// For example, if the stack has constraints that force it to 350x600, then + /// this would allow the non-positioned children of the stack to have any + /// width from zero to 350 and any height from zero to 600. + /// + /// See also: + /// + /// * [Center], which loosens the constraints passed to its child and then + /// centers the child in itself. + /// * [BoxConstraints.loosen], which implements the loosening of box + /// constraints. + loose, + + /// The constraints passed to the stack from its parent are tightened to the + /// biggest size allowed. + /// + /// For example, if the stack has loose constraints with a width in the range + /// 10 to 100 and a height in the range 0 to 600, then the non-positioned + /// children of the stack would all be sized as 100 pixels wide and 600 high. + expand, + + /// The constraints passed to the stack from its parent are passed unmodified + /// to the non-positioned children. + /// + /// For example, if a [Stack] is an [Expanded] child of a [Row], the + /// horizontal constraints will be tight and the vertical constraints will be + /// loose. + passthrough, +} + +/// Implements the stack layout algorithm. +/// +/// In a stack layout, the children are positioned on top of each other in the +/// order in which they appear in the child list. First, the non-positioned +/// children (those with null values for top, right, bottom, and left) are +/// laid out and initially placed in the upper-left corner of the stack. The +/// stack is then sized to enclose all of the non-positioned children. If there +/// are no non-positioned children, the stack becomes as large as possible. +/// +/// The final location of non-positioned children is determined by the alignment +/// parameter. The left of each non-positioned child becomes the +/// difference between the child's width and the stack's width scaled by +/// alignment.x. The top of each non-positioned child is computed +/// similarly and scaled by alignment.y. So if the alignment x and y properties +/// are 0.0 (the default) then the non-positioned children remain in the +/// upper-left corner. If the alignment x and y properties are 0.5 then the +/// non-positioned children are centered within the stack. +/// +/// Next, the positioned children are laid out. If a child has top and bottom +/// values that are both non-null, the child is given a fixed height determined +/// by subtracting the sum of the top and bottom values from the height of the stack. +/// Similarly, if the child has right and left values that are both non-null, +/// the child is given a fixed width derived from the stack's width. +/// Otherwise, the child is given unbounded constraints in the non-fixed dimensions. +/// +/// Once the child is laid out, the stack positions the child +/// according to the top, right, bottom, and left properties of their +/// [StackParentData]. For example, if the bottom value is 10.0, the +/// bottom edge of the child will be inset 10.0 pixels from the bottom +/// edge of the stack. If the child extends beyond the bounds of the +/// stack, the stack will clip the child's painting to the bounds of +/// the stack. +/// +/// See also: +/// +/// * [RenderFlow] +class RenderStack extends RenderBox + with ContainerRenderObjectMixin<RenderBox, StackParentData>, + RenderBoxContainerDefaultsMixin<RenderBox, StackParentData> { + /// Creates a stack render object. + /// + /// By default, the non-positioned children of the stack are aligned by their + /// top left corners. + RenderStack({ + List<RenderBox>? children, + AlignmentGeometry alignment = AlignmentDirectional.topStart, + TextDirection? textDirection, + StackFit fit = StackFit.loose, + Clip clipBehavior = Clip.hardEdge, + }) : _alignment = alignment, + _textDirection = textDirection, + _fit = fit, + _clipBehavior = clipBehavior { + addAll(children); + } + + bool _hasVisualOverflow = false; + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! StackParentData) { + child.parentData = StackParentData(); + } + } + + Alignment? _resolvedAlignment; + + void _resolve() { + if (_resolvedAlignment != null) { + return; + } + _resolvedAlignment = alignment.resolve(textDirection); + } + + void _markNeedResolution() { + _resolvedAlignment = null; + markNeedsLayout(); + } + + /// How to align the non-positioned or partially-positioned children in the + /// stack. + /// + /// The non-positioned children are placed relative to each other such that + /// the points determined by [alignment] are co-located. For example, if the + /// [alignment] is [Alignment.topLeft], then the top left corner of + /// each non-positioned child will be located at the same global coordinate. + /// + /// Partially-positioned children, those that do not specify an alignment in a + /// particular axis (e.g. that have neither `top` nor `bottom` set), use the + /// alignment to determine how they should be positioned in that + /// under-specified axis. + /// + /// If this is set to an [AlignmentDirectional] object, then [textDirection] + /// must not be null. + AlignmentGeometry get alignment => _alignment; + AlignmentGeometry _alignment; + set alignment(AlignmentGeometry value) { + if (_alignment == value) { + return; + } + _alignment = value; + _markNeedResolution(); + } + + /// The text direction with which to resolve [alignment]. + /// + /// This may be changed to null, but only after the [alignment] has been changed + /// to a value that does not depend on the direction. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + _markNeedResolution(); + } + + /// How to size the non-positioned children in the stack. + /// + /// The constraints passed into the [RenderStack] from its parent are either + /// loosened ([StackFit.loose]) or tightened to their biggest size + /// ([StackFit.expand]). + StackFit get fit => _fit; + StackFit _fit; + set fit(StackFit value) { + if (_fit != value) { + _fit = value; + markNeedsLayout(); + } + } + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Stacks only clip children whose geometry overflow the stack. A child that + /// paints outside its bounds (e.g. a box with a shadow) will not be clipped, + /// regardless of the value of this property. Similarly, a child that itself + /// has a descendant that overflows the stack will not be clipped, as only the + /// geometry of the stack's direct children are considered. + /// + /// To clip children whose geometry does not overflow the stack, consider + /// using a [RenderClipRect] render object. + /// + /// Defaults to [Clip.hardEdge]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.hardEdge; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + /// Helper function for calculating the intrinsics metrics of a Stack. + static double getIntrinsicDimension(RenderBox? firstChild, double Function(RenderBox child) mainChildSizeGetter) { + double extent = 0.0; + RenderBox? child = firstChild; + while (child != null) { + final StackParentData childParentData = child.parentData! as StackParentData; + if (!childParentData.isPositioned) { + extent = math.max(extent, mainChildSizeGetter(child)); + } + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + return extent; + } + + @override + double computeMinIntrinsicWidth(double height) { + return getIntrinsicDimension(firstChild, (RenderBox child) => child.getMinIntrinsicWidth(height)); + } + + @override + double computeMaxIntrinsicWidth(double height) { + return getIntrinsicDimension(firstChild, (RenderBox child) => child.getMaxIntrinsicWidth(height)); + } + + @override + double computeMinIntrinsicHeight(double width) { + return getIntrinsicDimension(firstChild, (RenderBox child) => child.getMinIntrinsicHeight(width)); + } + + @override + double computeMaxIntrinsicHeight(double width) { + return getIntrinsicDimension(firstChild, (RenderBox child) => child.getMaxIntrinsicHeight(width)); + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + return defaultComputeDistanceToHighestActualBaseline(baseline); + } + + /// Lays out the positioned `child` according to `alignment` within a Stack of `size`. + /// + /// Returns true when the child has visual overflow. + static bool layoutPositionedChild(RenderBox child, StackParentData childParentData, Size size, Alignment alignment) { + assert(childParentData.isPositioned); + assert(child.parentData == childParentData); + + bool hasVisualOverflow = false; + BoxConstraints childConstraints = const BoxConstraints(); + + if (childParentData.left != null && childParentData.right != null) { + childConstraints = childConstraints.tighten(width: size.width - childParentData.right! - childParentData.left!); + } else if (childParentData.width != null) { + childConstraints = childConstraints.tighten(width: childParentData.width); + } + + if (childParentData.top != null && childParentData.bottom != null) { + childConstraints = childConstraints.tighten(height: size.height - childParentData.bottom! - childParentData.top!); + } else if (childParentData.height != null) { + childConstraints = childConstraints.tighten(height: childParentData.height); + } + + child.layout(childConstraints, parentUsesSize: true); + + final double x; + if (childParentData.left != null) { + x = childParentData.left!; + } else if (childParentData.right != null) { + x = size.width - childParentData.right! - child.size.width; + } else { + x = alignment.alongOffset(size - child.size as Offset).dx; + } + + if (x < 0.0 || x + child.size.width > size.width) { + hasVisualOverflow = true; + } + + final double y; + if (childParentData.top != null) { + y = childParentData.top!; + } else if (childParentData.bottom != null) { + y = size.height - childParentData.bottom! - child.size.height; + } else { + y = alignment.alongOffset(size - child.size as Offset).dy; + } + + if (y < 0.0 || y + child.size.height > size.height) { + hasVisualOverflow = true; + } + + childParentData.offset = Offset(x, y); + + return hasVisualOverflow; + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.dryLayoutChild, + ); + } + + Size _computeSize({required BoxConstraints constraints, required ChildLayouter layoutChild}) { + _resolve(); + assert(_resolvedAlignment != null); + bool hasNonPositionedChildren = false; + if (childCount == 0) { + return (constraints.biggest.isFinite) ? constraints.biggest : constraints.smallest; + } + + double width = constraints.minWidth; + double height = constraints.minHeight; + + final BoxConstraints nonPositionedConstraints = switch (fit) { + StackFit.loose => constraints.loosen(), + StackFit.expand => BoxConstraints.tight(constraints.biggest), + StackFit.passthrough => constraints, + }; + + RenderBox? child = firstChild; + while (child != null) { + final StackParentData childParentData = child.parentData! as StackParentData; + + if (!childParentData.isPositioned) { + hasNonPositionedChildren = true; + + final Size childSize = layoutChild(child, nonPositionedConstraints); + + width = math.max(width, childSize.width); + height = math.max(height, childSize.height); + } + + child = childParentData.nextSibling; + } + + final Size size; + if (hasNonPositionedChildren) { + size = Size(width, height); + assert(size.width == constraints.constrainWidth(width)); + assert(size.height == constraints.constrainHeight(height)); + } else { + size = constraints.biggest; + } + + assert(size.isFinite); + return size; + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + _hasVisualOverflow = false; + + size = _computeSize( + constraints: constraints, + layoutChild: ChildLayoutHelper.layoutChild, + ); + + assert(_resolvedAlignment != null); + RenderBox? child = firstChild; + while (child != null) { + final StackParentData childParentData = child.parentData! as StackParentData; + + if (!childParentData.isPositioned) { + childParentData.offset = _resolvedAlignment!.alongOffset(size - child.size as Offset); + } else { + _hasVisualOverflow = layoutPositionedChild(child, childParentData, size, _resolvedAlignment!) || _hasVisualOverflow; + } + + assert(child.parentData == childParentData); + child = childParentData.nextSibling; + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + return defaultHitTestChildren(result, position: position); + } + + /// Override in subclasses to customize how the stack paints. + /// + /// By default, the stack uses [defaultPaint]. This function is called by + /// [paint] after potentially applying a clip to contain visual overflow. + @protected + void paintStack(PaintingContext context, Offset offset) { + defaultPaint(context, offset); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (clipBehavior != Clip.none && _hasVisualOverflow) { + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + paintStack, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + } else { + _clipRectLayer.layer = null; + paintStack(context, offset); + } + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void dispose() { + _clipRectLayer.layer = null; + super.dispose(); + } + + @override + Rect? describeApproximatePaintClip(RenderObject child) { + switch (clipBehavior) { + case Clip.none: + return null; + case Clip.hardEdge: + case Clip.antiAlias: + case Clip.antiAliasWithSaveLayer: + return _hasVisualOverflow ? Offset.zero & size : null; + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection)); + properties.add(EnumProperty<StackFit>('fit', fit)); + properties.add(EnumProperty<Clip>('clipBehavior', clipBehavior, defaultValue: Clip.hardEdge)); + } +} + +/// Implements the same layout algorithm as RenderStack but only paints the child +/// specified by index. +/// +/// Although only one child is displayed, the cost of the layout algorithm is +/// still O(N), like an ordinary stack. +class RenderIndexedStack extends RenderStack { + /// Creates a stack render object that paints a single child. + /// + /// If the [index] parameter is null, nothing is displayed. + RenderIndexedStack({ + super.children, + super.alignment, + super.textDirection, + super.fit, + super.clipBehavior, + int? index = 0, + }) : _index = index; + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (index != null && firstChild != null) { + visitor(_childAtIndex()); + } + } + + /// The index of the child to show, null if nothing is to be displayed. + int? get index => _index; + int? _index; + set index(int? value) { + if (_index != value) { + _index = value; + markNeedsLayout(); + } + } + + RenderBox _childAtIndex() { + assert(index != null); + RenderBox? child = firstChild; + int i = 0; + while (child != null && i < index!) { + final StackParentData childParentData = child.parentData! as StackParentData; + child = childParentData.nextSibling; + i += 1; + } + assert(i == index); + assert(child != null); + return child!; + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + if (firstChild == null || index == null) { + return false; + } + final RenderBox child = _childAtIndex(); + final StackParentData childParentData = child.parentData! as StackParentData; + return result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - childParentData.offset); + return child.hitTest(result, position: transformed); + }, + ); + } + + @override + void paintStack(PaintingContext context, Offset offset) { + if (firstChild == null || index == null) { + return; + } + final RenderBox child = _childAtIndex(); + final StackParentData childParentData = child.parentData! as StackParentData; + context.paintChild(child, childParentData.offset + offset); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('index', index)); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<DiagnosticsNode> children = <DiagnosticsNode>[]; + int i = 0; + RenderObject? child = firstChild; + while (child != null) { + children.add(child.toDiagnosticsNode( + name: 'child ${i + 1}', + style: i != index ? DiagnosticsTreeStyle.offstage : null, + )); + child = (child.parentData! as StackParentData).nextSibling; + i += 1; + } + return children; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/table.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/table.dart new file mode 100644 index 0000000000000000000000000000000000000000..702504b6a71dcf3d8c872714b55ab488b9db27e6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/table.dart @@ -0,0 +1,1278 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'object.dart'; +import 'table_border.dart'; + +/// Parent data used by [RenderTable] for its children. +class TableCellParentData extends BoxParentData { + /// Where this cell should be placed vertically. + /// + /// When using [TableCellVerticalAlignment.baseline], the text baseline must be set as well. + TableCellVerticalAlignment? verticalAlignment; + + /// The column that the child was in the last time it was laid out. + int? x; + + /// The row that the child was in the last time it was laid out. + int? y; + + @override + String toString() => '${super.toString()}; ${verticalAlignment == null ? "default vertical alignment" : "$verticalAlignment"}'; +} + +/// Base class to describe how wide a column in a [RenderTable] should be. +/// +/// To size a column to a specific number of pixels, use a [FixedColumnWidth]. +/// This is the cheapest way to size a column. +/// +/// Other algorithms that are relatively cheap include [FlexColumnWidth], which +/// distributes the space equally among the flexible columns, +/// [FractionColumnWidth], which sizes a column based on the size of the +/// table's container. +@immutable +abstract class TableColumnWidth { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const TableColumnWidth(); + + /// The smallest width that the column can have. + /// + /// The `cells` argument is an iterable that provides all the cells + /// in the table for this column. Walking the cells is by definition + /// O(N), so algorithms that do that should be considered expensive. + /// + /// The `containerWidth` argument is the `maxWidth` of the incoming + /// constraints for the table, and might be infinite. + double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth); + + /// The ideal width that the column should have. This must be equal + /// to or greater than the [minIntrinsicWidth]. The column might be + /// bigger than this width, e.g. if the column is flexible or if the + /// table's width ends up being forced to be bigger than the sum of + /// all the maxIntrinsicWidth values. + /// + /// The `cells` argument is an iterable that provides all the cells + /// in the table for this column. Walking the cells is by definition + /// O(N), so algorithms that do that should be considered expensive. + /// + /// The `containerWidth` argument is the `maxWidth` of the incoming + /// constraints for the table, and might be infinite. + double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth); + + /// The flex factor to apply to the cell if there is any room left + /// over when laying out the table. The remaining space is + /// distributed to any columns with flex in proportion to their flex + /// value (higher values get more space). + /// + /// The `cells` argument is an iterable that provides all the cells + /// in the table for this column. Walking the cells is by definition + /// O(N), so algorithms that do that should be considered expensive. + double? flex(Iterable<RenderBox> cells) => null; + + @override + String toString() => objectRuntimeType(this, 'TableColumnWidth'); +} + +/// Sizes the column according to the intrinsic dimensions of all the +/// cells in that column. +/// +/// This is a very expensive way to size a column. +/// +/// A flex value can be provided. If specified (and non-null), the +/// column will participate in the distribution of remaining space +/// once all the non-flexible columns have been sized. +class IntrinsicColumnWidth extends TableColumnWidth { + /// Creates a column width based on intrinsic sizing. + /// + /// This sizing algorithm is very expensive. + /// + /// The `flex` argument specifies the flex factor to apply to the column if + /// there is any room left over when laying out the table. If `flex` is + /// null (the default), the table will not distribute any extra space to the + /// column. + const IntrinsicColumnWidth({ double? flex }) : _flex = flex; + + @override + double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + double result = 0.0; + for (final RenderBox cell in cells) { + result = math.max(result, cell.getMinIntrinsicWidth(double.infinity)); + } + return result; + } + + @override + double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + double result = 0.0; + for (final RenderBox cell in cells) { + result = math.max(result, cell.getMaxIntrinsicWidth(double.infinity)); + } + return result; + } + + final double? _flex; + + @override + double? flex(Iterable<RenderBox> cells) => _flex; + + @override + String toString() => '${objectRuntimeType(this, 'IntrinsicColumnWidth')}(flex: ${_flex?.toStringAsFixed(1)})'; +} + +/// Sizes the column to a specific number of pixels. +/// +/// This is the cheapest way to size a column. +class FixedColumnWidth extends TableColumnWidth { + /// Creates a column width based on a fixed number of logical pixels. + const FixedColumnWidth(this.value); + + /// The width the column should occupy in logical pixels. + final double value; + + @override + double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + return value; + } + + @override + double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + return value; + } + + @override + String toString() => '${objectRuntimeType(this, 'FixedColumnWidth')}(${debugFormatDouble(value)})'; +} + +/// Sizes the column to a fraction of the table's constraints' maxWidth. +/// +/// This is a cheap way to size a column. +class FractionColumnWidth extends TableColumnWidth { + /// Creates a column width based on a fraction of the table's constraints' + /// maxWidth. + const FractionColumnWidth(this.value); + + /// The fraction of the table's constraints' maxWidth that this column should + /// occupy. + final double value; + + @override + double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + if (!containerWidth.isFinite) { + return 0.0; + } + return value * containerWidth; + } + + @override + double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + if (!containerWidth.isFinite) { + return 0.0; + } + return value * containerWidth; + } + + @override + String toString() => '${objectRuntimeType(this, 'FractionColumnWidth')}($value)'; +} + +/// Sizes the column by taking a part of the remaining space once all +/// the other columns have been laid out. +/// +/// For example, if two columns have a [FlexColumnWidth], then half the +/// space will go to one and half the space will go to the other. +/// +/// This is a cheap way to size a column. +class FlexColumnWidth extends TableColumnWidth { + /// Creates a column width based on a fraction of the remaining space once all + /// the other columns have been laid out. + const FlexColumnWidth([this.value = 1.0]); + + /// The fraction of the remaining space once all the other columns have + /// been laid out that this column should occupy. + final double value; + + @override + double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + return 0.0; + } + + @override + double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + return 0.0; + } + + @override + double flex(Iterable<RenderBox> cells) { + return value; + } + + @override + String toString() => '${objectRuntimeType(this, 'FlexColumnWidth')}(${debugFormatDouble(value)})'; +} + +/// Sizes the column such that it is the size that is the maximum of +/// two column width specifications. +/// +/// For example, to have a column be 10% of the container width or +/// 100px, whichever is bigger, you could use: +/// +/// const MaxColumnWidth(const FixedColumnWidth(100.0), FractionColumnWidth(0.1)) +/// +/// Both specifications are evaluated, so if either specification is +/// expensive, so is this. +class MaxColumnWidth extends TableColumnWidth { + /// Creates a column width that is the maximum of two other column widths. + const MaxColumnWidth(this.a, this.b); + + /// A lower bound for the width of this column. + final TableColumnWidth a; + + /// Another lower bound for the width of this column. + final TableColumnWidth b; + + @override + double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + return math.max( + a.minIntrinsicWidth(cells, containerWidth), + b.minIntrinsicWidth(cells, containerWidth), + ); + } + + @override + double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + return math.max( + a.maxIntrinsicWidth(cells, containerWidth), + b.maxIntrinsicWidth(cells, containerWidth), + ); + } + + @override + double? flex(Iterable<RenderBox> cells) { + final double? aFlex = a.flex(cells); + final double? bFlex = b.flex(cells); + if (aFlex == null) { + return bFlex; + } else if (bFlex == null) { + return aFlex; + } + return math.max(aFlex, bFlex); + } + + @override + String toString() => '${objectRuntimeType(this, 'MaxColumnWidth')}($a, $b)'; +} + +/// Sizes the column such that it is the size that is the minimum of +/// two column width specifications. +/// +/// For example, to have a column be 10% of the container width but +/// never bigger than 100px, you could use: +/// +/// const MinColumnWidth(const FixedColumnWidth(100.0), FractionColumnWidth(0.1)) +/// +/// Both specifications are evaluated, so if either specification is +/// expensive, so is this. +class MinColumnWidth extends TableColumnWidth { + /// Creates a column width that is the minimum of two other column widths. + const MinColumnWidth(this.a, this.b); + + /// An upper bound for the width of this column. + final TableColumnWidth a; + + /// Another upper bound for the width of this column. + final TableColumnWidth b; + + @override + double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + return math.min( + a.minIntrinsicWidth(cells, containerWidth), + b.minIntrinsicWidth(cells, containerWidth), + ); + } + + @override + double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) { + return math.min( + a.maxIntrinsicWidth(cells, containerWidth), + b.maxIntrinsicWidth(cells, containerWidth), + ); + } + + @override + double? flex(Iterable<RenderBox> cells) { + final double? aFlex = a.flex(cells); + final double? bFlex = b.flex(cells); + if (aFlex == null) { + return bFlex; + } else if (bFlex == null) { + return aFlex; + } + return math.min(aFlex, bFlex); + } + + @override + String toString() => '${objectRuntimeType(this, 'MinColumnWidth')}($a, $b)'; +} + +/// Vertical alignment options for cells in [RenderTable] objects. +/// +/// This is specified using [TableCellParentData] objects on the +/// [RenderObject.parentData] of the children of the [RenderTable]. +enum TableCellVerticalAlignment { + /// Cells with this alignment are placed with their top at the top of the row. + top, + + /// Cells with this alignment are vertically centered in the row. + middle, + + /// Cells with this alignment are placed with their bottom at the bottom of the row. + bottom, + + /// Cells with this alignment are aligned such that they all share the same + /// baseline. Cells with no baseline are top-aligned instead. The baseline + /// used is specified by [RenderTable.textBaseline]. It is not valid to use + /// the baseline value if [RenderTable.textBaseline] is not specified. + /// + /// This vertical alignment is relatively expensive because it causes the table + /// to compute the baseline for each cell in the row. + baseline, + + /// Cells with this alignment are sized to be as tall as the row, then made to fit the row. + /// If all the cells have this alignment, then the row will have zero height. + fill, + + /// Cells with this alignment are sized to be the same height as the tallest cell in the row. + intrinsicHeight +} + +/// A table where the columns and rows are sized to fit the contents of the cells. +class RenderTable extends RenderBox { + /// Creates a table render object. + /// + /// * `columns` must either be null or non-negative. If `columns` is null, + /// the number of columns will be inferred from length of the first sublist + /// of `children`. + /// * `rows` must either be null or non-negative. If `rows` is null, the + /// number of rows will be inferred from the `children`. If `rows` is not + /// null, then `children` must be null. + /// * `children` must either be null or contain lists of all the same length. + /// if `children` is not null, then `rows` must be null. + /// * [columnWidths] may be null, in which case it defaults to an empty map. + RenderTable({ + int? columns, + int? rows, + Map<int, TableColumnWidth>? columnWidths, + TableColumnWidth defaultColumnWidth = const FlexColumnWidth(), + required TextDirection textDirection, + TableBorder? border, + List<Decoration?>? rowDecorations, + ImageConfiguration configuration = ImageConfiguration.empty, + TableCellVerticalAlignment defaultVerticalAlignment = TableCellVerticalAlignment.top, + TextBaseline? textBaseline, + List<List<RenderBox>>? children, + }) : assert(columns == null || columns >= 0), + assert(rows == null || rows >= 0), + assert(rows == null || children == null), + _textDirection = textDirection, + _columns = columns ?? (children != null && children.isNotEmpty ? children.first.length : 0), + _rows = rows ?? 0, + _columnWidths = columnWidths ?? HashMap<int, TableColumnWidth>(), + _defaultColumnWidth = defaultColumnWidth, + _border = border, + _textBaseline = textBaseline, + _defaultVerticalAlignment = defaultVerticalAlignment, + _configuration = configuration { + _children = <RenderBox?>[]..length = _columns * _rows; + this.rowDecorations = rowDecorations; // must use setter to initialize box painters array + children?.forEach(addRow); + } + + // Children are stored in row-major order. + // _children.length must be rows * columns + List<RenderBox?> _children = const <RenderBox?>[]; + + /// The number of vertical alignment lines in this table. + /// + /// Changing the number of columns will remove any children that no longer fit + /// in the table. + /// + /// Changing the number of columns is an expensive operation because the table + /// needs to rearrange its internal representation. + int get columns => _columns; + int _columns; + set columns(int value) { + assert(value >= 0); + if (value == columns) { + return; + } + final int oldColumns = columns; + final List<RenderBox?> oldChildren = _children; + _columns = value; + _children = List<RenderBox?>.filled(columns * rows, null); + final int columnsToCopy = math.min(columns, oldColumns); + for (int y = 0; y < rows; y += 1) { + for (int x = 0; x < columnsToCopy; x += 1) { + _children[x + y * columns] = oldChildren[x + y * oldColumns]; + } + } + if (oldColumns > columns) { + for (int y = 0; y < rows; y += 1) { + for (int x = columns; x < oldColumns; x += 1) { + final int xy = x + y * oldColumns; + if (oldChildren[xy] != null) { + dropChild(oldChildren[xy]!); + } + } + } + } + markNeedsLayout(); + } + + /// The number of horizontal alignment lines in this table. + /// + /// Changing the number of rows will remove any children that no longer fit + /// in the table. + int get rows => _rows; + int _rows; + set rows(int value) { + assert(value >= 0); + if (value == rows) { + return; + } + if (_rows > value) { + for (int xy = columns * value; xy < _children.length; xy += 1) { + if (_children[xy] != null) { + dropChild(_children[xy]!); + } + } + } + _rows = value; + _children.length = columns * rows; + markNeedsLayout(); + } + + /// How the horizontal extents of the columns of this table should be determined. + /// + /// If the [Map] has a null entry for a given column, the table uses the + /// [defaultColumnWidth] instead. + /// + /// The layout performance of the table depends critically on which column + /// sizing algorithms are used here. In particular, [IntrinsicColumnWidth] is + /// quite expensive because it needs to measure each cell in the column to + /// determine the intrinsic size of the column. + /// + /// This property can never return null. If it is set to null, and the existing + /// map is not empty, then the value is replaced by an empty map. (If it is set + /// to null while the current value is an empty map, the value is not changed.) + Map<int, TableColumnWidth>? get columnWidths => Map<int, TableColumnWidth>.unmodifiable(_columnWidths); + Map<int, TableColumnWidth> _columnWidths; + set columnWidths(Map<int, TableColumnWidth>? value) { + if (_columnWidths == value) { + return; + } + if (_columnWidths.isEmpty && value == null) { + return; + } + _columnWidths = value ?? HashMap<int, TableColumnWidth>(); + markNeedsLayout(); + } + + /// Determines how the width of column with the given index is determined. + void setColumnWidth(int column, TableColumnWidth value) { + if (_columnWidths[column] == value) { + return; + } + _columnWidths[column] = value; + markNeedsLayout(); + } + + /// How to determine with widths of columns that don't have an explicit sizing algorithm. + /// + /// Specifically, the [defaultColumnWidth] is used for column `i` if + /// `columnWidths[i]` is null. + TableColumnWidth get defaultColumnWidth => _defaultColumnWidth; + TableColumnWidth _defaultColumnWidth; + set defaultColumnWidth(TableColumnWidth value) { + if (defaultColumnWidth == value) { + return; + } + _defaultColumnWidth = value; + markNeedsLayout(); + } + + /// The direction in which the columns are ordered. + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsLayout(); + } + + /// The style to use when painting the boundary and interior divisions of the table. + TableBorder? get border => _border; + TableBorder? _border; + set border(TableBorder? value) { + if (border == value) { + return; + } + _border = value; + markNeedsPaint(); + } + + /// The decorations to use for each row of the table. + /// + /// Row decorations fill the horizontal and vertical extent of each row in + /// the table, unlike decorations for individual cells, which might not fill + /// either. + List<Decoration> get rowDecorations => List<Decoration>.unmodifiable(_rowDecorations ?? const <Decoration>[]); + // _rowDecorations and _rowDecorationPainters need to be in sync. They have to + // either both be null or have same length. + List<Decoration?>? _rowDecorations; + List<BoxPainter?>? _rowDecorationPainters; + set rowDecorations(List<Decoration?>? value) { + if (_rowDecorations == value) { + return; + } + _rowDecorations = value; + if (_rowDecorationPainters != null) { + for (final BoxPainter? painter in _rowDecorationPainters!) { + painter?.dispose(); + } + } + _rowDecorationPainters = _rowDecorations != null ? List<BoxPainter?>.filled(_rowDecorations!.length, null) : null; + } + + /// The settings to pass to the [rowDecorations] when painting, so that they + /// can resolve images appropriately. See [ImageProvider.resolve] and + /// [BoxPainter.paint]. + ImageConfiguration get configuration => _configuration; + ImageConfiguration _configuration; + set configuration(ImageConfiguration value) { + if (value == _configuration) { + return; + } + _configuration = value; + markNeedsPaint(); + } + + /// How cells that do not explicitly specify a vertical alignment are aligned vertically. + TableCellVerticalAlignment get defaultVerticalAlignment => _defaultVerticalAlignment; + TableCellVerticalAlignment _defaultVerticalAlignment; + set defaultVerticalAlignment(TableCellVerticalAlignment value) { + if (_defaultVerticalAlignment == value) { + return; + } + _defaultVerticalAlignment = value; + markNeedsLayout(); + } + + /// The text baseline to use when aligning rows using [TableCellVerticalAlignment.baseline]. + TextBaseline? get textBaseline => _textBaseline; + TextBaseline? _textBaseline; + set textBaseline(TextBaseline? value) { + if (_textBaseline == value) { + return; + } + _textBaseline = value; + markNeedsLayout(); + } + + @override + void setupParentData(RenderObject child) { + if (child.parentData is! TableCellParentData) { + child.parentData = TableCellParentData(); + } + } + + /// Replaces the children of this table with the given cells. + /// + /// The cells are divided into the specified number of columns before + /// replacing the existing children. + /// + /// If the new cells contain any existing children of the table, those + /// children are moved to their new location in the table rather than + /// removed from the table and re-added. + void setFlatChildren(int columns, List<RenderBox?> cells) { + if (cells == _children && columns == _columns) { + return; + } + assert(columns >= 0); + // consider the case of a newly empty table + if (columns == 0 || cells.isEmpty) { + assert(cells.isEmpty); + _columns = columns; + if (_children.isEmpty) { + assert(_rows == 0); + return; + } + for (final RenderBox? oldChild in _children) { + if (oldChild != null) { + dropChild(oldChild); + } + } + _rows = 0; + _children.clear(); + markNeedsLayout(); + return; + } + assert(cells.length % columns == 0); + // fill a set with the cells that are moving (it's important not + // to dropChild a child that's remaining with us, because that + // would clear their parentData field) + final Set<RenderBox> lostChildren = HashSet<RenderBox>(); + for (int y = 0; y < _rows; y += 1) { + for (int x = 0; x < _columns; x += 1) { + final int xyOld = x + y * _columns; + final int xyNew = x + y * columns; + if (_children[xyOld] != null && (x >= columns || xyNew >= cells.length || _children[xyOld] != cells[xyNew])) { + lostChildren.add(_children[xyOld]!); + } + } + } + // adopt cells that are arriving, and cross cells that are just moving off our list of lostChildren + int y = 0; + while (y * columns < cells.length) { + for (int x = 0; x < columns; x += 1) { + final int xyNew = x + y * columns; + final int xyOld = x + y * _columns; + if (cells[xyNew] != null && (x >= _columns || y >= _rows || _children[xyOld] != cells[xyNew])) { + if (!lostChildren.remove(cells[xyNew])) { + adoptChild(cells[xyNew]!); + } + } + } + y += 1; + } + // drop all the lost children + lostChildren.forEach(dropChild); + // update our internal values + _columns = columns; + _rows = cells.length ~/ columns; + _children = List<RenderBox?>.of(cells); + assert(_children.length == rows * columns); + markNeedsLayout(); + } + + /// Replaces the children of this table with the given cells. + void setChildren(List<List<RenderBox>>? cells) { + // TODO(ianh): Make this smarter, like setFlatChildren + if (cells == null) { + setFlatChildren(0, const <RenderBox?>[]); + return; + } + for (final RenderBox? oldChild in _children) { + if (oldChild != null) { + dropChild(oldChild); + } + } + _children.clear(); + _columns = cells.isNotEmpty ? cells.first.length : 0; + _rows = 0; + cells.forEach(addRow); + assert(_children.length == rows * columns); + } + + /// Adds a row to the end of the table. + /// + /// The newly added children must not already have parents. + void addRow(List<RenderBox?> cells) { + assert(cells.length == columns); + assert(_children.length == rows * columns); + _rows += 1; + _children.addAll(cells); + for (final RenderBox? cell in cells) { + if (cell != null) { + adoptChild(cell); + } + } + markNeedsLayout(); + } + + /// Replaces the child at the given position with the given child. + /// + /// If the given child is already located at the given position, this function + /// does not modify the table. Otherwise, the given child must not already + /// have a parent. + void setChild(int x, int y, RenderBox? value) { + assert(x >= 0 && x < columns && y >= 0 && y < rows); + assert(_children.length == rows * columns); + final int xy = x + y * columns; + final RenderBox? oldChild = _children[xy]; + if (oldChild == value) { + return; + } + if (oldChild != null) { + dropChild(oldChild); + } + _children[xy] = value; + if (value != null) { + adoptChild(value); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + for (final RenderBox? child in _children) { + child?.attach(owner); + } + } + + @override + void detach() { + super.detach(); + if (_rowDecorationPainters != null) { + for (final BoxPainter? painter in _rowDecorationPainters!) { + painter?.dispose(); + } + _rowDecorationPainters = List<BoxPainter?>.filled(_rowDecorations!.length, null); + } + for (final RenderBox? child in _children) { + child?.detach(); + } + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + assert(_children.length == rows * columns); + for (final RenderBox? child in _children) { + if (child != null) { + visitor(child); + } + } + } + + @override + double computeMinIntrinsicWidth(double height) { + assert(_children.length == rows * columns); + double totalMinWidth = 0.0; + for (int x = 0; x < columns; x += 1) { + final TableColumnWidth columnWidth = _columnWidths[x] ?? defaultColumnWidth; + final Iterable<RenderBox> columnCells = column(x); + totalMinWidth += columnWidth.minIntrinsicWidth(columnCells, double.infinity); + } + return totalMinWidth; + } + + @override + double computeMaxIntrinsicWidth(double height) { + assert(_children.length == rows * columns); + double totalMaxWidth = 0.0; + for (int x = 0; x < columns; x += 1) { + final TableColumnWidth columnWidth = _columnWidths[x] ?? defaultColumnWidth; + final Iterable<RenderBox> columnCells = column(x); + totalMaxWidth += columnWidth.maxIntrinsicWidth(columnCells, double.infinity); + } + return totalMaxWidth; + } + + @override + double computeMinIntrinsicHeight(double width) { + // winner of the 2016 world's most expensive intrinsic dimension function award + // honorable mention, most likely to improve if taught about memoization award + assert(_children.length == rows * columns); + final List<double> widths = _computeColumnWidths(BoxConstraints.tightForFinite(width: width)); + double rowTop = 0.0; + for (int y = 0; y < rows; y += 1) { + double rowHeight = 0.0; + for (int x = 0; x < columns; x += 1) { + final int xy = x + y * columns; + final RenderBox? child = _children[xy]; + if (child != null) { + rowHeight = math.max(rowHeight, child.getMaxIntrinsicHeight(widths[x])); + } + } + rowTop += rowHeight; + } + return rowTop; + } + + @override + double computeMaxIntrinsicHeight(double width) { + return computeMinIntrinsicHeight(width); + } + + double? _baselineDistance; + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + // returns the baseline of the first cell that has a baseline in the first row + assert(!debugNeedsLayout); + return _baselineDistance; + } + + /// Returns the list of [RenderBox] objects that are in the given + /// column, in row order, starting from the first row. + /// + /// This is a lazily-evaluated iterable. + // The following uses sync* because it is public API documented to return a + // lazy iterable. + Iterable<RenderBox> column(int x) sync* { + for (int y = 0; y < rows; y += 1) { + final int xy = x + y * columns; + final RenderBox? child = _children[xy]; + if (child != null) { + yield child; + } + } + } + + /// Returns the list of [RenderBox] objects that are on the given + /// row, in column order, starting with the first column. + /// + /// This is a lazily-evaluated iterable. + // The following uses sync* because it is public API documented to return a + // lazy iterable. + Iterable<RenderBox> row(int y) sync* { + final int start = y * columns; + final int end = (y + 1) * columns; + for (int xy = start; xy < end; xy += 1) { + final RenderBox? child = _children[xy]; + if (child != null) { + yield child; + } + } + } + + List<double> _computeColumnWidths(BoxConstraints constraints) { + assert(_children.length == rows * columns); + // We apply the constraints to the column widths in the order of + // least important to most important: + // 1. apply the ideal widths (maxIntrinsicWidth) + // 2. grow the flex columns so that the table has the maxWidth (if + // finite) or the minWidth (if not) + // 3. if there were no flex columns, then grow the table to the + // minWidth. + // 4. apply the maximum width of the table, shrinking columns as + // necessary, applying minimum column widths as we go + + // 1. apply ideal widths, and collect information we'll need later + final List<double> widths = List<double>.filled(columns, 0.0); + final List<double> minWidths = List<double>.filled(columns, 0.0); + final List<double?> flexes = List<double?>.filled(columns, null); + double tableWidth = 0.0; // running tally of the sum of widths[x] for all x + double unflexedTableWidth = 0.0; // sum of the maxIntrinsicWidths of any column that has null flex + double totalFlex = 0.0; + for (int x = 0; x < columns; x += 1) { + final TableColumnWidth columnWidth = _columnWidths[x] ?? defaultColumnWidth; + final Iterable<RenderBox> columnCells = column(x); + // apply ideal width (maxIntrinsicWidth) + final double maxIntrinsicWidth = columnWidth.maxIntrinsicWidth(columnCells, constraints.maxWidth); + assert(maxIntrinsicWidth.isFinite); + assert(maxIntrinsicWidth >= 0.0); + widths[x] = maxIntrinsicWidth; + tableWidth += maxIntrinsicWidth; + // collect min width information while we're at it + final double minIntrinsicWidth = columnWidth.minIntrinsicWidth(columnCells, constraints.maxWidth); + assert(minIntrinsicWidth.isFinite); + assert(minIntrinsicWidth >= 0.0); + minWidths[x] = minIntrinsicWidth; + assert(maxIntrinsicWidth >= minIntrinsicWidth); + // collect flex information while we're at it + final double? flex = columnWidth.flex(columnCells); + if (flex != null) { + assert(flex.isFinite); + assert(flex > 0.0); + flexes[x] = flex; + totalFlex += flex; + } else { + unflexedTableWidth = unflexedTableWidth + maxIntrinsicWidth; + } + } + final double maxWidthConstraint = constraints.maxWidth; + final double minWidthConstraint = constraints.minWidth; + + // 2. grow the flex columns so that the table has the maxWidth (if + // finite) or the minWidth (if not) + if (totalFlex > 0.0) { + // this can only grow the table, but it _will_ grow the table at + // least as big as the target width. + final double targetWidth; + if (maxWidthConstraint.isFinite) { + targetWidth = maxWidthConstraint; + } else { + targetWidth = minWidthConstraint; + } + if (tableWidth < targetWidth) { + final double remainingWidth = targetWidth - unflexedTableWidth; + assert(remainingWidth.isFinite); + assert(remainingWidth >= 0.0); + for (int x = 0; x < columns; x += 1) { + if (flexes[x] != null) { + final double flexedWidth = remainingWidth * flexes[x]! / totalFlex; + assert(flexedWidth.isFinite); + assert(flexedWidth >= 0.0); + if (widths[x] < flexedWidth) { + final double delta = flexedWidth - widths[x]; + tableWidth += delta; + widths[x] = flexedWidth; + } + } + } + assert(tableWidth + precisionErrorTolerance >= targetWidth); + } + } // step 2 and 3 are mutually exclusive + + // 3. if there were no flex columns, then grow the table to the + // minWidth. + else if (tableWidth < minWidthConstraint) { + final double delta = (minWidthConstraint - tableWidth) / columns; + for (int x = 0; x < columns; x += 1) { + widths[x] = widths[x] + delta; + } + tableWidth = minWidthConstraint; + } + + // beyond this point, unflexedTableWidth is no longer valid + + // 4. apply the maximum width of the table, shrinking columns as + // necessary, applying minimum column widths as we go + if (tableWidth > maxWidthConstraint) { + double deficit = tableWidth - maxWidthConstraint; + // Some columns may have low flex but have all the free space. + // (Consider a case with a 1px wide column of flex 1000.0 and + // a 1000px wide column of flex 1.0; the sizes coming from the + // maxIntrinsicWidths. If the maximum table width is 2px, then + // just applying the flexes to the deficit would result in a + // table with one column at -998px and one column at 990px, + // which is wildly unhelpful.) + // Similarly, some columns may be flexible, but not actually + // be shrinkable due to a large minimum width. (Consider a + // case with two columns, one is flex and one isn't, both have + // 1000px maxIntrinsicWidths, but the flex one has 1000px + // minIntrinsicWidth also. The whole deficit will have to come + // from the non-flex column.) + // So what we do is we repeatedly iterate through the flexible + // columns shrinking them proportionally until we have no + // available columns, then do the same to the non-flexible ones. + int availableColumns = columns; + while (deficit > precisionErrorTolerance && totalFlex > precisionErrorTolerance) { + double newTotalFlex = 0.0; + for (int x = 0; x < columns; x += 1) { + if (flexes[x] != null) { + final double newWidth = widths[x] - deficit * flexes[x]! / totalFlex; + assert(newWidth.isFinite); + if (newWidth <= minWidths[x]) { + // shrank to minimum + deficit -= widths[x] - minWidths[x]; + widths[x] = minWidths[x]; + flexes[x] = null; + availableColumns -= 1; + } else { + deficit -= widths[x] - newWidth; + widths[x] = newWidth; + newTotalFlex += flexes[x]!; + } + assert(widths[x] >= 0.0); + } + } + totalFlex = newTotalFlex; + } + while (deficit > precisionErrorTolerance && availableColumns > 0) { + // Now we have to take out the remaining space from the + // columns that aren't minimum sized. + // To make this fair, we repeatedly remove equal amounts from + // each column, clamped to the minimum width, until we run out + // of columns that aren't at their minWidth. + final double delta = deficit / availableColumns; + assert(delta != 0); + int newAvailableColumns = 0; + for (int x = 0; x < columns; x += 1) { + final double availableDelta = widths[x] - minWidths[x]; + if (availableDelta > 0.0) { + if (availableDelta <= delta) { + // shrank to minimum + deficit -= widths[x] - minWidths[x]; + widths[x] = minWidths[x]; + } else { + deficit -= delta; + widths[x] = widths[x] - delta; + newAvailableColumns += 1; + } + } + } + availableColumns = newAvailableColumns; + } + } + return widths; + } + + // cache the table geometry for painting purposes + final List<double> _rowTops = <double>[]; + Iterable<double>? _columnLefts; + late double _tableWidth; + + /// Returns the position and dimensions of the box that the given + /// row covers, in this render object's coordinate space (so the + /// left coordinate is always 0.0). + /// + /// The row being queried must exist. + /// + /// This is only valid after layout. + Rect getRowBox(int row) { + assert(row >= 0); + assert(row < rows); + assert(!debugNeedsLayout); + return Rect.fromLTRB(0.0, _rowTops[row], size.width, _rowTops[row + 1]); + } + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + if (rows * columns == 0) { + return constraints.constrain(Size.zero); + } + final List<double> widths = _computeColumnWidths(constraints); + final double tableWidth = widths.fold(0.0, (double a, double b) => a + b); + double rowTop = 0.0; + for (int y = 0; y < rows; y += 1) { + double rowHeight = 0.0; + for (int x = 0; x < columns; x += 1) { + final int xy = x + y * columns; + final RenderBox? child = _children[xy]; + if (child != null) { + final TableCellParentData childParentData = child.parentData! as TableCellParentData; + switch (childParentData.verticalAlignment ?? defaultVerticalAlignment) { + case TableCellVerticalAlignment.baseline: + assert(debugCannotComputeDryLayout( + reason: 'TableCellVerticalAlignment.baseline requires a full layout for baseline metrics to be available.', + )); + return Size.zero; + case TableCellVerticalAlignment.top: + case TableCellVerticalAlignment.middle: + case TableCellVerticalAlignment.bottom: + case TableCellVerticalAlignment.intrinsicHeight: + final Size childSize = child.getDryLayout(BoxConstraints.tightFor(width: widths[x])); + rowHeight = math.max(rowHeight, childSize.height); + case TableCellVerticalAlignment.fill: + break; + } + } + } + rowTop += rowHeight; + } + return constraints.constrain(Size(tableWidth, rowTop)); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + final int rows = this.rows; + final int columns = this.columns; + assert(_children.length == rows * columns); + if (rows * columns == 0) { + // TODO(ianh): if columns is zero, this should be zero width + // TODO(ianh): if columns is not zero, this should be based on the column width specifications + _tableWidth = 0.0; + size = constraints.constrain(Size.zero); + return; + } + final List<double> widths = _computeColumnWidths(constraints); + final List<double> positions = List<double>.filled(columns, 0.0); + switch (textDirection) { + case TextDirection.rtl: + positions[columns - 1] = 0.0; + for (int x = columns - 2; x >= 0; x -= 1) { + positions[x] = positions[x+1] + widths[x+1]; + } + _columnLefts = positions.reversed; + _tableWidth = positions.first + widths.first; + case TextDirection.ltr: + positions[0] = 0.0; + for (int x = 1; x < columns; x += 1) { + positions[x] = positions[x-1] + widths[x-1]; + } + _columnLefts = positions; + _tableWidth = positions.last + widths.last; + } + _rowTops.clear(); + _baselineDistance = null; + // then, lay out each row + double rowTop = 0.0; + for (int y = 0; y < rows; y += 1) { + _rowTops.add(rowTop); + double rowHeight = 0.0; + bool haveBaseline = false; + double beforeBaselineDistance = 0.0; + double afterBaselineDistance = 0.0; + final List<double> baselines = List<double>.filled(columns, 0.0); + for (int x = 0; x < columns; x += 1) { + final int xy = x + y * columns; + final RenderBox? child = _children[xy]; + if (child != null) { + final TableCellParentData childParentData = child.parentData! as TableCellParentData; + childParentData.x = x; + childParentData.y = y; + switch (childParentData.verticalAlignment ?? defaultVerticalAlignment) { + case TableCellVerticalAlignment.baseline: + assert(textBaseline != null, 'An explicit textBaseline is required when using baseline alignment.'); + child.layout(BoxConstraints.tightFor(width: widths[x]), parentUsesSize: true); + final double? childBaseline = child.getDistanceToBaseline(textBaseline!, onlyReal: true); + if (childBaseline != null) { + beforeBaselineDistance = math.max(beforeBaselineDistance, childBaseline); + afterBaselineDistance = math.max(afterBaselineDistance, child.size.height - childBaseline); + baselines[x] = childBaseline; + haveBaseline = true; + } else { + rowHeight = math.max(rowHeight, child.size.height); + childParentData.offset = Offset(positions[x], rowTop); + } + case TableCellVerticalAlignment.top: + case TableCellVerticalAlignment.middle: + case TableCellVerticalAlignment.bottom: + case TableCellVerticalAlignment.intrinsicHeight: + child.layout(BoxConstraints.tightFor(width: widths[x]), parentUsesSize: true); + rowHeight = math.max(rowHeight, child.size.height); + case TableCellVerticalAlignment.fill: + break; + } + } + } + if (haveBaseline) { + if (y == 0) { + _baselineDistance = beforeBaselineDistance; + } + rowHeight = math.max(rowHeight, beforeBaselineDistance + afterBaselineDistance); + } + for (int x = 0; x < columns; x += 1) { + final int xy = x + y * columns; + final RenderBox? child = _children[xy]; + if (child != null) { + final TableCellParentData childParentData = child.parentData! as TableCellParentData; + switch (childParentData.verticalAlignment ?? defaultVerticalAlignment) { + case TableCellVerticalAlignment.baseline: + childParentData.offset = Offset(positions[x], rowTop + beforeBaselineDistance - baselines[x]); + case TableCellVerticalAlignment.top: + childParentData.offset = Offset(positions[x], rowTop); + case TableCellVerticalAlignment.middle: + childParentData.offset = Offset(positions[x], rowTop + (rowHeight - child.size.height) / 2.0); + case TableCellVerticalAlignment.bottom: + childParentData.offset = Offset(positions[x], rowTop + rowHeight - child.size.height); + case TableCellVerticalAlignment.fill: + case TableCellVerticalAlignment.intrinsicHeight: + child.layout(BoxConstraints.tightFor(width: widths[x], height: rowHeight)); + childParentData.offset = Offset(positions[x], rowTop); + } + } + } + rowTop += rowHeight; + } + _rowTops.add(rowTop); + size = constraints.constrain(Size(_tableWidth, rowTop)); + assert(_rowTops.length == rows + 1); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + assert(_children.length == rows * columns); + for (int index = _children.length - 1; index >= 0; index -= 1) { + final RenderBox? child = _children[index]; + if (child != null) { + final BoxParentData childParentData = child.parentData! as BoxParentData; + final bool isHit = result.addWithPaintOffset( + offset: childParentData.offset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - childParentData.offset); + return child.hitTest(result, position: transformed); + }, + ); + if (isHit) { + return true; + } + } + } + return false; + } + + @override + void paint(PaintingContext context, Offset offset) { + assert(_children.length == rows * columns); + if (rows * columns == 0) { + if (border != null) { + final Rect borderRect = Rect.fromLTWH(offset.dx, offset.dy, _tableWidth, 0.0); + border!.paint(context.canvas, borderRect, rows: const <double>[], columns: const <double>[]); + } + return; + } + assert(_rowTops.length == rows + 1); + if (_rowDecorations != null) { + assert(_rowDecorations!.length == _rowDecorationPainters!.length); + final Canvas canvas = context.canvas; + for (int y = 0; y < rows; y += 1) { + if (_rowDecorations!.length <= y) { + break; + } + if (_rowDecorations![y] != null) { + _rowDecorationPainters![y] ??= _rowDecorations![y]!.createBoxPainter(markNeedsPaint); + _rowDecorationPainters![y]!.paint( + canvas, + Offset(offset.dx, offset.dy + _rowTops[y]), + configuration.copyWith(size: Size(size.width, _rowTops[y+1] - _rowTops[y])), + ); + } + } + } + for (int index = 0; index < _children.length; index += 1) { + final RenderBox? child = _children[index]; + if (child != null) { + final BoxParentData childParentData = child.parentData! as BoxParentData; + context.paintChild(child, childParentData.offset + offset); + } + } + assert(_rows == _rowTops.length - 1); + assert(_columns == _columnLefts!.length); + if (border != null) { + // The border rect might not fill the entire height of this render object + // if the rows underflow. We always force the columns to fill the width of + // the render object, which means the columns cannot underflow. + final Rect borderRect = Rect.fromLTWH(offset.dx, offset.dy, _tableWidth, _rowTops.last); + final Iterable<double> rows = _rowTops.getRange(1, _rowTops.length - 1); + final Iterable<double> columns = _columnLefts!.skip(1); + border!.paint(context.canvas, borderRect, rows: rows, columns: columns); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<TableBorder>('border', border, defaultValue: null)); + properties.add(DiagnosticsProperty<Map<int, TableColumnWidth>>('specified column widths', _columnWidths, level: _columnWidths.isEmpty ? DiagnosticLevel.hidden : DiagnosticLevel.info)); + properties.add(DiagnosticsProperty<TableColumnWidth>('default column width', defaultColumnWidth)); + properties.add(MessageProperty('table size', '$columns\u00D7$rows')); + properties.add(IterableProperty<String>('column offsets', _columnLefts?.map(debugFormatDouble), ifNull: 'unknown')); + properties.add(IterableProperty<String>('row offsets', _rowTops.map(debugFormatDouble), ifNull: 'unknown')); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + if (_children.isEmpty) { + return <DiagnosticsNode>[DiagnosticsNode.message('table is empty')]; + } + + final List<DiagnosticsNode> children = <DiagnosticsNode>[]; + for (int y = 0; y < rows; y += 1) { + for (int x = 0; x < columns; x += 1) { + final int xy = x + y * columns; + final RenderBox? child = _children[xy]; + final String name = 'child ($x, $y)'; + if (child != null) { + children.add(child.toDiagnosticsNode(name: name)); + } else { + children.add(DiagnosticsProperty<Object>(name, null, ifNull: 'is null', showSeparator: false)); + } + } + } + return children; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/table_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/table_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..97f2c6b9e47bf545871709715c24015ff1e1faa7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/table_border.dart @@ -0,0 +1,286 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart' hide Border; + +/// Border specification for [Table] widgets. +/// +/// This is like [Border], with the addition of two sides: the inner horizontal +/// borders between rows and the inner vertical borders between columns. +/// +/// The sides are represented by [BorderSide] objects. +@immutable +class TableBorder { + /// Creates a border for a table. + /// + /// All the sides of the border default to [BorderSide.none]. + const TableBorder({ + this.top = BorderSide.none, + this.right = BorderSide.none, + this.bottom = BorderSide.none, + this.left = BorderSide.none, + this.horizontalInside = BorderSide.none, + this.verticalInside = BorderSide.none, + this.borderRadius = BorderRadius.zero, + }); + + /// A uniform border with all sides the same color and width. + /// + /// The sides default to black solid borders, one logical pixel wide. + factory TableBorder.all({ + Color color = const Color(0xFF000000), + double width = 1.0, + BorderStyle style = BorderStyle.solid, + BorderRadius borderRadius = BorderRadius.zero, + }) { + final BorderSide side = BorderSide(color: color, width: width, style: style); + return TableBorder(top: side, right: side, bottom: side, left: side, horizontalInside: side, verticalInside: side, borderRadius: borderRadius); + } + + /// Creates a border for a table where all the interior sides use the same + /// styling and all the exterior sides use the same styling. + factory TableBorder.symmetric({ + BorderSide inside = BorderSide.none, + BorderSide outside = BorderSide.none, + }) { + return TableBorder( + top: outside, + right: outside, + bottom: outside, + left: outside, + horizontalInside: inside, + verticalInside: inside, + ); + } + + /// The top side of this border. + final BorderSide top; + + /// The right side of this border. + final BorderSide right; + + /// The bottom side of this border. + final BorderSide bottom; + + /// The left side of this border. + final BorderSide left; + + /// The horizontal interior sides of this border. + final BorderSide horizontalInside; + + /// The vertical interior sides of this border. + final BorderSide verticalInside; + + /// The [BorderRadius] to use when painting the corners of this border. + /// + /// It is also applied to [DataTable]'s [Material]. + final BorderRadius borderRadius; + + /// The widths of the sides of this border represented as an [EdgeInsets]. + /// + /// This can be used, for example, with a [Padding] widget to inset a box by + /// the size of these borders. + EdgeInsets get dimensions { + return EdgeInsets.fromLTRB(left.width, top.width, right.width, bottom.width); + } + + /// Whether all the sides of the border (outside and inside) are identical. + /// Uniform borders are typically more efficient to paint. + bool get isUniform { + + final Color topColor = top.color; + if (right.color != topColor || + bottom.color != topColor || + left.color != topColor || + horizontalInside.color != topColor || + verticalInside.color != topColor) { + return false; + } + + final double topWidth = top.width; + if (right.width != topWidth || + bottom.width != topWidth || + left.width != topWidth || + horizontalInside.width != topWidth || + verticalInside.width != topWidth) { + return false; + } + + final BorderStyle topStyle = top.style; + if (right.style != topStyle || + bottom.style != topStyle || + left.style != topStyle || + horizontalInside.style != topStyle || + verticalInside.style != topStyle) { + return false; + } + + return true; + } + + /// Creates a copy of this border but with the widths scaled by the factor `t`. + /// + /// The `t` argument represents the multiplicand, or the position on the + /// timeline for an interpolation from nothing to `this`, with 0.0 meaning + /// that the object returned should be the nil variant of this object, 1.0 + /// meaning that no change should be applied, returning `this` (or something + /// equivalent to `this`), and other values meaning that the object should be + /// multiplied by `t`. Negative values are treated like zero. + /// + /// Values for `t` are usually obtained from an [Animation<double>], such as + /// an [AnimationController]. + /// + /// See also: + /// + /// * [BorderSide.scale], which is used to implement this method. + TableBorder scale(double t) { + return TableBorder( + top: top.scale(t), + right: right.scale(t), + bottom: bottom.scale(t), + left: left.scale(t), + horizontalInside: horizontalInside.scale(t), + verticalInside: verticalInside.scale(t), + ); + } + + /// Linearly interpolate between two table borders. + /// + /// If a border is null, it is treated as having only [BorderSide.none] + /// borders. + /// + /// {@macro dart.ui.shadow.lerp} + static TableBorder? lerp(TableBorder? a, TableBorder? b, double t) { + if (identical(a, b)) { + return a; + } + if (a == null) { + return b!.scale(t); + } + if (b == null) { + return a.scale(1.0 - t); + } + return TableBorder( + top: BorderSide.lerp(a.top, b.top, t), + right: BorderSide.lerp(a.right, b.right, t), + bottom: BorderSide.lerp(a.bottom, b.bottom, t), + left: BorderSide.lerp(a.left, b.left, t), + horizontalInside: BorderSide.lerp(a.horizontalInside, b.horizontalInside, t), + verticalInside: BorderSide.lerp(a.verticalInside, b.verticalInside, t), + ); + } + + /// Paints the border around the given [Rect] on the given [Canvas], with the + /// given rows and columns. + /// + /// Uniform borders are more efficient to paint than more complex borders. + /// + /// The `rows` argument specifies the vertical positions between the rows, + /// relative to the given rectangle. For example, if the table contained two + /// rows of height 100.0 each, then `rows` would contain a single value, + /// 100.0, which is the vertical position between the two rows (relative to + /// the top edge of `rect`). + /// + /// The `columns` argument specifies the horizontal positions between the + /// columns, relative to the given rectangle. For example, if the table + /// contained two columns of height 100.0 each, then `columns` would contain a + /// single value, 100.0, which is the vertical position between the two + /// columns (relative to the left edge of `rect`). + /// + /// The [verticalInside] border is only drawn if there are at least two + /// columns. The [horizontalInside] border is only drawn if there are at least + /// two rows. The horizontal borders are drawn after the vertical borders. + /// + /// The outer borders (in the order [top], [right], [bottom], [left], with + /// [left] above the others) are painted after the inner borders. + /// + /// The paint order is particularly notable in the case of + /// partially-transparent borders. + void paint( + Canvas canvas, + Rect rect, { + required Iterable<double> rows, + required Iterable<double> columns, + }) { + // properties can't be null + + // arguments can't be null + assert(rows.isEmpty || (rows.first >= 0.0 && rows.last <= rect.height)); + assert(columns.isEmpty || (columns.first >= 0.0 && columns.last <= rect.width)); + + if (columns.isNotEmpty || rows.isNotEmpty) { + final Paint paint = Paint(); + final Path path = Path(); + + if (columns.isNotEmpty) { + switch (verticalInside.style) { + case BorderStyle.solid: + paint + ..color = verticalInside.color + ..strokeWidth = verticalInside.width + ..style = PaintingStyle.stroke; + path.reset(); + for (final double x in columns) { + path.moveTo(rect.left + x, rect.top); + path.lineTo(rect.left + x, rect.bottom); + } + canvas.drawPath(path, paint); + case BorderStyle.none: + break; + } + } + + if (rows.isNotEmpty) { + switch (horizontalInside.style) { + case BorderStyle.solid: + paint + ..color = horizontalInside.color + ..strokeWidth = horizontalInside.width + ..style = PaintingStyle.stroke; + path.reset(); + for (final double y in rows) { + path.moveTo(rect.left, rect.top + y); + path.lineTo(rect.right, rect.top + y); + } + canvas.drawPath(path, paint); + case BorderStyle.none: + break; + } + } + } + if (!isUniform || borderRadius == BorderRadius.zero) { + paintBorder(canvas, rect, top: top, right: right, bottom: bottom, left: left); + } else { + final RRect outer = borderRadius.toRRect(rect); + final RRect inner = outer.deflate(top.width); + final Paint paint = Paint()..color = top.color; + canvas.drawDRRect(outer, inner, paint); + } + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is TableBorder + && other.top == top + && other.right == right + && other.bottom == bottom + && other.left == left + && other.horizontalInside == horizontalInside + && other.verticalInside == verticalInside + && other.borderRadius == borderRadius; + } + + @override + int get hashCode => Object.hash(top, right, bottom, left, horizontalInside, verticalInside, borderRadius); + + @override + String toString() => 'TableBorder($top, $right, $bottom, $left, $horizontalInside, $verticalInside, $borderRadius)'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/texture.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/texture.dart new file mode 100644 index 0000000000000000000000000000000000000000..9016cb87ab144067aa571e600cb40689596475da --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/texture.dart @@ -0,0 +1,106 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'layer.dart'; +import 'object.dart'; + +/// A rectangle upon which a backend texture is mapped. +/// +/// Backend textures are images that can be applied (mapped) to an area of the +/// Flutter view. They are created, managed, and updated using a +/// platform-specific texture registry. This is typically done by a plugin +/// that integrates with host platform video player, camera, or OpenGL APIs, +/// or similar image sources. +/// +/// A texture box refers to its backend texture using an integer ID. Texture +/// IDs are obtained from the texture registry and are scoped to the Flutter +/// view. Texture IDs may be reused after deregistration, at the discretion +/// of the registry. The use of texture IDs currently unknown to the registry +/// will silently result in a blank rectangle. +/// +/// Texture boxes are repainted autonomously as dictated by the backend (e.g. on +/// arrival of a video frame). Such repainting generally does not involve +/// executing Dart code. +/// +/// The size of the rectangle is determined by the parent, and the texture is +/// automatically scaled to fit. +/// +/// See also: +/// +/// * [TextureRegistry](/javadoc/io/flutter/view/TextureRegistry.html) +/// for how to create and manage backend textures on Android. +/// * [TextureRegistry Protocol](/ios-embedder/protocol_flutter_texture_registry-p.html) +/// for how to create and manage backend textures on iOS. +class TextureBox extends RenderBox { + /// Creates a box backed by the texture identified by [textureId], and use + /// [filterQuality] to set texture's [FilterQuality]. + TextureBox({ + required int textureId, + bool freeze = false, + FilterQuality filterQuality = FilterQuality.low, + }) : _textureId = textureId, + _freeze = freeze, + _filterQuality = filterQuality; + + /// The identity of the backend texture. + int get textureId => _textureId; + int _textureId; + set textureId(int value) { + if (value != _textureId) { + _textureId = value; + markNeedsPaint(); + } + } + + /// When true the texture will not be updated with new frames. + bool get freeze => _freeze; + bool _freeze; + set freeze(bool value) { + if (value != _freeze) { + _freeze = value; + markNeedsPaint(); + } + } + + /// {@macro flutter.widgets.Texture.filterQuality} + FilterQuality get filterQuality => _filterQuality; + FilterQuality _filterQuality; + set filterQuality(FilterQuality value) { + if (value != _filterQuality) { + _filterQuality = value; + markNeedsPaint(); + } + } + + @override + bool get sizedByParent => true; + + @override + bool get alwaysNeedsCompositing => true; + + @override + bool get isRepaintBoundary => true; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return constraints.biggest; + } + + @override + bool hitTestSelf(Offset position) => true; + + @override + void paint(PaintingContext context, Offset offset) { + context.addLayer(TextureLayer( + rect: Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height), + textureId: _textureId, + freeze: freeze, + filterQuality: _filterQuality, + )); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/tweens.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/tweens.dart new file mode 100644 index 0000000000000000000000000000000000000000..4f1e520745fac74d4f9a9a17aa6300060d2c9aee --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/tweens.dart @@ -0,0 +1,76 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/animation.dart'; +import 'package:flutter/painting.dart'; + +/// An interpolation between two fractional offsets. +/// +/// This class specializes the interpolation of [Tween<FractionalOffset>] to be +/// appropriate for fractional offsets. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +/// +/// See also: +/// +/// * [AlignmentTween], which interpolates between to [Alignment] objects. +class FractionalOffsetTween extends Tween<FractionalOffset?> { + /// Creates a fractional offset tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as meaning the center. + FractionalOffsetTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + FractionalOffset? lerp(double t) => FractionalOffset.lerp(begin, end, t); +} + +/// An interpolation between two alignments. +/// +/// This class specializes the interpolation of [Tween<Alignment>] to be +/// appropriate for alignments. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +/// +/// See also: +/// +/// * [AlignmentGeometryTween], which interpolates between two +/// [AlignmentGeometry] objects. +class AlignmentTween extends Tween<Alignment> { + /// Creates a fractional offset tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as meaning the center. + AlignmentTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + Alignment lerp(double t) => Alignment.lerp(begin, end, t)!; +} + +/// An interpolation between two [AlignmentGeometry]. +/// +/// This class specializes the interpolation of [Tween<AlignmentGeometry>] +/// to be appropriate for alignments. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +/// +/// See also: +/// +/// * [AlignmentTween], which interpolates between two [Alignment] objects. +class AlignmentGeometryTween extends Tween<AlignmentGeometry?> { + /// Creates a fractional offset geometry tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as meaning the center. + AlignmentGeometryTween({ + super.begin, + super.end, + }); + + /// Returns the value this variable has at the given animation clock value. + @override + AlignmentGeometry? lerp(double t) => AlignmentGeometry.lerp(begin, end, t); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/view.dart new file mode 100644 index 0000000000000000000000000000000000000000..03db7f1d608ca38c4a9af7c98c226d2eedc8f1fc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/view.dart @@ -0,0 +1,446 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:io' show Platform; +import 'dart:ui' as ui show FlutterView, Scene, SceneBuilder, SemanticsUpdate; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'binding.dart'; +import 'box.dart'; +import 'debug.dart'; +import 'layer.dart'; +import 'object.dart'; + +/// The layout constraints for the root render object. +@immutable +class ViewConfiguration { + /// Creates a view configuration. + /// + /// By default, the view has zero [size] and a [devicePixelRatio] of 1.0. + const ViewConfiguration({ + this.size = Size.zero, + this.devicePixelRatio = 1.0, + }); + + /// The size of the output surface. + final Size size; + + /// The pixel density of the output surface. + final double devicePixelRatio; + + /// Creates a transformation matrix that applies the [devicePixelRatio]. + /// + /// The matrix translates points from the local coordinate system of the + /// app (in logical pixels) to the global coordinate system of the + /// [FlutterView] (in physical pixels). + Matrix4 toMatrix() { + return Matrix4.diagonal3Values(devicePixelRatio, devicePixelRatio, 1.0); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ViewConfiguration + && other.size == size + && other.devicePixelRatio == devicePixelRatio; + } + + @override + int get hashCode => Object.hash(size, devicePixelRatio); + + @override + String toString() => '$size at ${debugFormatDouble(devicePixelRatio)}x'; +} + +/// The root of the render tree. +/// +/// The view represents the total output surface of the render tree and handles +/// bootstrapping the rendering pipeline. The view has a unique child +/// [RenderBox], which is required to fill the entire output surface. +class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox> { + /// Creates the root of the render tree. + /// + /// Typically created by the binding (e.g., [RendererBinding]). + /// + /// Providing a [configuration] is optional, but a configuration must be set + /// before calling [prepareInitialFrame]. This decouples creating the + /// [RenderView] object from configuring it. Typically, the object is created + /// by the [View] widget and configured by the [RendererBinding] when the + /// [RenderView] is registered with it by the [View] widget. + RenderView({ + RenderBox? child, + ViewConfiguration? configuration, + required ui.FlutterView view, + }) : _configuration = configuration, + _view = view { + this.child = child; + } + + /// The current layout size of the view. + Size get size => _size; + Size _size = Size.zero; + + /// The constraints used for the root layout. + /// + /// Typically, this configuration is set by the [RendererBinding], when the + /// [RenderView] is registered with it. It will also update the configuration + /// if necessary. Therefore, if used in conjunction with the [RendererBinding] + /// this property must not be set manually as the [RendererBinding] will just + /// override it. + /// + /// For tests that want to change the size of the view, set + /// [TestFlutterView.physicalSize] on the appropriate [TestFlutterView] + /// (typically [WidgetTester.view]) instead of setting a configuration + /// directly on the [RenderView]. + ViewConfiguration get configuration => _configuration!; + ViewConfiguration? _configuration; + set configuration(ViewConfiguration value) { + if (_configuration == value) { + return; + } + final ViewConfiguration? oldConfiguration = _configuration; + _configuration = value; + if (_rootTransform == null) { + // [prepareInitialFrame] has not been called yet, nothing to do for now. + return; + } + if (oldConfiguration?.toMatrix() != configuration.toMatrix()) { + replaceRootLayer(_updateMatricesAndCreateNewRootLayer()); + } + assert(_rootTransform != null); + markNeedsLayout(); + } + + /// Whether a [configuration] has been set. + bool get hasConfiguration => _configuration != null; + + /// The [FlutterView] into which this [RenderView] will render. + ui.FlutterView get flutterView => _view; + final ui.FlutterView _view; + + /// Whether Flutter should automatically compute the desired system UI. + /// + /// When this setting is enabled, Flutter will hit-test the layer tree at the + /// top and bottom of the screen on each frame looking for an + /// [AnnotatedRegionLayer] with an instance of a [SystemUiOverlayStyle]. The + /// hit-test result from the top of the screen provides the status bar settings + /// and the hit-test result from the bottom of the screen provides the system + /// nav bar settings. + /// + /// If there is no [AnnotatedRegionLayer] on the bottom, the hit-test result + /// from the top provides the system nav bar settings. If there is no + /// [AnnotatedRegionLayer] on the top, the hit-test result from the bottom + /// provides the system status bar settings. + /// + /// Setting this to false does not cause previous automatic adjustments to be + /// reset, nor does setting it to true cause the app to update immediately. + /// + /// If you want to imperatively set the system ui style instead, it is + /// recommended that [automaticSystemUiAdjustment] is set to false. + /// + /// See also: + /// + /// * [AnnotatedRegion], for placing [SystemUiOverlayStyle] in the layer tree. + /// * [SystemChrome.setSystemUIOverlayStyle], for imperatively setting the system ui style. + bool automaticSystemUiAdjustment = true; + + /// Bootstrap the rendering pipeline by preparing the first frame. + /// + /// This should only be called once, and must be called before changing + /// [configuration]. It is typically called immediately after calling the + /// constructor. + /// + /// This does not actually schedule the first frame. Call + /// [PipelineOwner.requestVisualUpdate] on [owner] to do that. + void prepareInitialFrame() { + assert(owner != null); + assert(_rootTransform == null); + scheduleInitialLayout(); + scheduleInitialPaint(_updateMatricesAndCreateNewRootLayer()); + assert(_rootTransform != null); + } + + Matrix4? _rootTransform; + + TransformLayer _updateMatricesAndCreateNewRootLayer() { + _rootTransform = configuration.toMatrix(); + final TransformLayer rootLayer = TransformLayer(transform: _rootTransform); + rootLayer.attach(this); + assert(_rootTransform != null); + return rootLayer; + } + + // We never call layout() on this class, so this should never get + // checked. (This class is laid out using scheduleInitialLayout().) + @override + void debugAssertDoesMeetConstraints() { assert(false); } + + @override + void performResize() { + assert(false); + } + + @override + void performLayout() { + assert(_rootTransform != null); + _size = configuration.size; + assert(_size.isFinite); + + if (child != null) { + child!.layout(BoxConstraints.tight(_size)); + } + } + + /// Determines the set of render objects located at the given position. + /// + /// Returns true if the given point is contained in this render object or one + /// of its descendants. Adds any render objects that contain the point to the + /// given hit test result. + /// + /// The [position] argument is in the coordinate system of the render view, + /// which is to say, in logical pixels. This is not necessarily the same + /// coordinate system as that expected by the root [Layer], which will + /// normally be in physical (device) pixels. + bool hitTest(HitTestResult result, { required Offset position }) { + if (child != null) { + child!.hitTest(BoxHitTestResult.wrap(result), position: position); + } + result.add(HitTestEntry(this)); + return true; + } + + @override + bool get isRepaintBoundary => true; + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + context.paintChild(child!, offset); + } + assert(() { + final List<DebugPaintCallback> localCallbacks = _debugPaintCallbacks.toList(); + for (final DebugPaintCallback paintCallback in localCallbacks) { + if (_debugPaintCallbacks.contains(paintCallback)) { + paintCallback(context, offset, this); + } + } + return true; + }()); + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + assert(_rootTransform != null); + transform.multiply(_rootTransform!); + super.applyPaintTransform(child, transform); + } + + /// Uploads the composited layer tree to the engine. + /// + /// Actually causes the output of the rendering pipeline to appear on screen. + void compositeFrame() { + if (!kReleaseMode) { + FlutterTimeline.startSync('COMPOSITING'); + } + try { + final ui.SceneBuilder builder = ui.SceneBuilder(); + final ui.Scene scene = layer!.buildScene(builder); + if (automaticSystemUiAdjustment) { + _updateSystemChrome(); + } + _view.render(scene); + scene.dispose(); + assert(() { + if (debugRepaintRainbowEnabled || debugRepaintTextRainbowEnabled) { + debugCurrentRepaintColor = debugCurrentRepaintColor.withHue((debugCurrentRepaintColor.hue + 2.0) % 360.0); + } + return true; + }()); + } finally { + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + } + } + + /// Sends the provided [SemanticsUpdate] to the [FlutterView] associated with + /// this [RenderView]. + /// + /// A [SemanticsUpdate] is produced by a [SemanticsOwner] during the + /// [EnginePhase.flushSemantics] phase. + void updateSemantics(ui.SemanticsUpdate update) { + _view.updateSemantics(update); + } + + void _updateSystemChrome() { + // Take overlay style from the place where a system status bar and system + // navigation bar are placed to update system style overlay. + // The center of the system navigation bar and the center of the status bar + // are used to get SystemUiOverlayStyle's to update system overlay appearance. + // + // Horizontal center of the screen + // V + // ++++++++++++++++++++++++++ + // | | + // | System status bar | <- Vertical center of the status bar + // | | + // ++++++++++++++++++++++++++ + // | | + // | Content | + // ~ ~ + // | | + // ++++++++++++++++++++++++++ + // | | + // | System navigation bar | <- Vertical center of the navigation bar + // | | + // ++++++++++++++++++++++++++ <- bounds.bottom + final Rect bounds = paintBounds; + // Center of the status bar + final Offset top = Offset( + // Horizontal center of the screen + bounds.center.dx, + // The vertical center of the system status bar. The system status bar + // height is kept as top window padding. + _view.padding.top / 2.0, + ); + // Center of the navigation bar + final Offset bottom = Offset( + // Horizontal center of the screen + bounds.center.dx, + // Vertical center of the system navigation bar. The system navigation bar + // height is kept as bottom window padding. The "1" needs to be subtracted + // from the bottom because available pixels are in (0..bottom) range. + // I.e. for a device with 1920 height, bound.bottom is 1920, but the most + // bottom drawn pixel is at 1919 position. + bounds.bottom - 1.0 - _view.padding.bottom / 2.0, + ); + final SystemUiOverlayStyle? upperOverlayStyle = layer!.find<SystemUiOverlayStyle>(top); + // Only android has a customizable system navigation bar. + SystemUiOverlayStyle? lowerOverlayStyle; + switch (defaultTargetPlatform) { + case TargetPlatform.android: + lowerOverlayStyle = layer!.find<SystemUiOverlayStyle>(bottom); + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + break; + } + // If there are no overlay style in the UI don't bother updating. + if (upperOverlayStyle == null && lowerOverlayStyle == null) { + return; + } + + // If both are not null, the upper provides the status bar properties and the lower provides + // the system navigation bar properties. This is done for advanced use cases where a widget + // on the top (for instance an app bar) will create an annotated region to set the status bar + // style and another widget on the bottom will create an annotated region to set the system + // navigation bar style. + if (upperOverlayStyle != null && lowerOverlayStyle != null) { + final SystemUiOverlayStyle overlayStyle = SystemUiOverlayStyle( + statusBarBrightness: upperOverlayStyle.statusBarBrightness, + statusBarIconBrightness: upperOverlayStyle.statusBarIconBrightness, + statusBarColor: upperOverlayStyle.statusBarColor, + systemStatusBarContrastEnforced: upperOverlayStyle.systemStatusBarContrastEnforced, + systemNavigationBarColor: lowerOverlayStyle.systemNavigationBarColor, + systemNavigationBarDividerColor: lowerOverlayStyle.systemNavigationBarDividerColor, + systemNavigationBarIconBrightness: lowerOverlayStyle.systemNavigationBarIconBrightness, + systemNavigationBarContrastEnforced: lowerOverlayStyle.systemNavigationBarContrastEnforced, + ); + SystemChrome.setSystemUIOverlayStyle(overlayStyle); + return; + } + // If only one of the upper or the lower overlay style is not null, it provides all properties. + // This is done for developer convenience as it allows setting both status bar style and + // navigation bar style using only one annotated region layer (for instance the one + // automatically created by an [AppBar]). + final bool isAndroid = defaultTargetPlatform == TargetPlatform.android; + final SystemUiOverlayStyle definedOverlayStyle = (upperOverlayStyle ?? lowerOverlayStyle)!; + final SystemUiOverlayStyle overlayStyle = SystemUiOverlayStyle( + statusBarBrightness: definedOverlayStyle.statusBarBrightness, + statusBarIconBrightness: definedOverlayStyle.statusBarIconBrightness, + statusBarColor: definedOverlayStyle.statusBarColor, + systemStatusBarContrastEnforced: definedOverlayStyle.systemStatusBarContrastEnforced, + systemNavigationBarColor: isAndroid ? definedOverlayStyle.systemNavigationBarColor : null, + systemNavigationBarDividerColor: isAndroid ? definedOverlayStyle.systemNavigationBarDividerColor : null, + systemNavigationBarIconBrightness: isAndroid ? definedOverlayStyle.systemNavigationBarIconBrightness : null, + systemNavigationBarContrastEnforced: isAndroid ? definedOverlayStyle.systemNavigationBarContrastEnforced : null, + ); + SystemChrome.setSystemUIOverlayStyle(overlayStyle); + } + + @override + Rect get paintBounds => Offset.zero & (size * configuration.devicePixelRatio); + + @override + Rect get semanticBounds { + assert(_rootTransform != null); + return MatrixUtils.transformRect(_rootTransform!, Offset.zero & size); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + // call to ${super.debugFillProperties(description)} is omitted because the + // root superclasses don't include any interesting information for this + // class + assert(() { + properties.add(DiagnosticsNode.message('debug mode enabled - ${kIsWeb ? 'Web' : Platform.operatingSystem}')); + return true; + }()); + properties.add(DiagnosticsProperty<Size>('view size', _view.physicalSize, tooltip: 'in physical pixels')); + properties.add(DoubleProperty('device pixel ratio', _view.devicePixelRatio, tooltip: 'physical pixels per logical pixel')); + properties.add(DiagnosticsProperty<ViewConfiguration>('configuration', configuration, tooltip: 'in logical pixels')); + if (_view.platformDispatcher.semanticsEnabled) { + properties.add(DiagnosticsNode.message('semantics enabled')); + } + } + + static final List<DebugPaintCallback> _debugPaintCallbacks = <DebugPaintCallback>[]; + + /// Registers a [DebugPaintCallback] that is called every time a [RenderView] + /// repaints in debug mode. + /// + /// The callback may paint a debug overlay on top of the content of the + /// [RenderView] provided to the callback. Callbacks are invoked in the + /// order they were registered in. + /// + /// Neither registering a callback nor the continued presence of a callback + /// changes how often [RenderView]s are repainted. It is up to the owner of + /// the callback to call [markNeedsPaint] on any [RenderView] for which it + /// wants to update the painted overlay. + /// + /// Does nothing in release mode. + static void debugAddPaintCallback(DebugPaintCallback callback) { + assert(() { + _debugPaintCallbacks.add(callback); + return true; + }()); + } + + /// Removes a callback registered with [debugAddPaintCallback]. + /// + /// It does not schedule a frame to repaint the [RenderView]s without the + /// overlay painted by the removed callback. It is up to the owner of the + /// callback to call [markNeedsPaint] on the relevant [RenderView]s to + /// repaint them without the overlay. + /// + /// Does nothing in release mode. + static void debugRemovePaintCallback(DebugPaintCallback callback) { + assert(() { + _debugPaintCallbacks.remove(callback); + return true; + }()); + } +} + +/// A callback for painting a debug overlay on top of the provided [RenderView]. +/// +/// Used by [RenderView.debugAddPaintCallback] and +/// [RenderView.debugRemovePaintCallback]. +typedef DebugPaintCallback = void Function(PaintingContext context, Offset offset, RenderView renderView); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/viewport.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/viewport.dart new file mode 100644 index 0000000000000000000000000000000000000000..3bfd1dbcbed70e75e66bc526b0f91f97cf9f36d3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/viewport.dart @@ -0,0 +1,2042 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/semantics.dart'; + +import 'box.dart'; +import 'debug.dart'; +import 'layer.dart'; +import 'object.dart'; +import 'sliver.dart'; +import 'viewport_offset.dart'; + +/// The unit of measurement for a [Viewport.cacheExtent]. +enum CacheExtentStyle { + /// Treat the [Viewport.cacheExtent] as logical pixels. + pixel, + /// Treat the [Viewport.cacheExtent] as a multiplier of the main axis extent. + viewport, +} + +/// An interface for render objects that are bigger on the inside. +/// +/// Some render objects, such as [RenderViewport], present a portion of their +/// content, which can be controlled by a [ViewportOffset]. This interface lets +/// the framework recognize such render objects and interact with them without +/// having specific knowledge of all the various types of viewports. +abstract interface class RenderAbstractViewport extends RenderObject { + /// Returns the [RenderAbstractViewport] that most tightly encloses the given + /// render object. + /// + /// If the object does not have a [RenderAbstractViewport] as an ancestor, + /// this function returns null. + /// + /// See also: + /// + /// * [RenderAbstractViewport.of], which is similar to this method, but + /// asserts if no [RenderAbstractViewport] ancestor is found. + static RenderAbstractViewport? maybeOf(RenderObject? object) { + while (object != null) { + if (object is RenderAbstractViewport) { + return object; + } + object = object.parent; + } + return null; + } + + /// Returns the [RenderAbstractViewport] that most tightly encloses the given + /// render object. + /// + /// If the object does not have a [RenderAbstractViewport] as an ancestor, + /// this function will assert in debug mode, and throw an exception in release + /// mode. + /// + /// See also: + /// + /// * [RenderAbstractViewport.maybeOf], which is similar to this method, but + /// returns null if no [RenderAbstractViewport] ancestor is found. + static RenderAbstractViewport of(RenderObject? object) { + final RenderAbstractViewport? viewport = maybeOf(object); + assert(() { + if (viewport == null) { + throw FlutterError( + 'RenderAbstractViewport.of() was called with a render object that was ' + 'not a descendant of a RenderAbstractViewport.\n' + 'No RenderAbstractViewport render object ancestor could be found starting ' + 'from the object that was passed to RenderAbstractViewport.of().\n' + 'The render object where the viewport search started was:\n' + ' $object', + ); + } + return true; + }()); + return viewport!; + } + + /// Returns the offset that would be needed to reveal the `target` + /// [RenderObject]. + /// + /// This is used by [RenderViewportBase.showInViewport], which is + /// itself used by [RenderObject.showOnScreen] for + /// [RenderViewportBase], which is in turn used by the semantics + /// system to implement scrolling for accessibility tools. + /// + /// The optional `rect` parameter describes which area of that `target` object + /// should be revealed in the viewport. If `rect` is null, the entire + /// `target` [RenderObject] (as defined by its [RenderObject.paintBounds]) + /// will be revealed. If `rect` is provided it has to be given in the + /// coordinate system of the `target` object. + /// + /// The `alignment` argument describes where the target should be positioned + /// after applying the returned offset. If `alignment` is 0.0, the child must + /// be positioned as close to the leading edge of the viewport as possible. If + /// `alignment` is 1.0, the child must be positioned as close to the trailing + /// edge of the viewport as possible. If `alignment` is 0.5, the child must be + /// positioned as close to the center of the viewport as possible. + /// + /// The `target` might not be a direct child of this viewport but it must be a + /// descendant of the viewport. Other viewports in between this viewport and + /// the `target` will not be adjusted. + /// + /// This method assumes that the content of the viewport moves linearly, i.e. + /// when the offset of the viewport is changed by x then `target` also moves + /// by x within the viewport. + /// + /// The optional [Axis] is used by + /// [RenderTwoDimensionalViewport.getOffsetToReveal] to + /// determine which of the two axes to compute an offset for. One dimensional + /// subclasses like [RenderViewportBase] and [RenderListWheelViewport] + /// will ignore the `axis` value if provided, since there is only one [Axis]. + /// + /// If the `axis` is omitted when called on [RenderTwoDimensionalViewport], + /// the [RenderTwoDimensionalViewport.mainAxis] is used. To reveal an object + /// properly in both axes, this method should be called for each [Axis] as the + /// returned [RevealedOffset.offset] only represents the offset of one of the + /// the two [ScrollPosition]s. + /// + /// See also: + /// + /// * [RevealedOffset], which describes the return value of this method. + RevealedOffset getOffsetToReveal( + RenderObject target, + double alignment, { + Rect? rect, + Axis? axis, + }); + + /// The default value for the cache extent of the viewport. + /// + /// This default assumes [CacheExtentStyle.pixel]. + /// + /// See also: + /// + /// * [RenderViewportBase.cacheExtent] for a definition of the cache extent. + static const double defaultCacheExtent = 250.0; +} + +/// Return value for [RenderAbstractViewport.getOffsetToReveal]. +/// +/// It indicates the [offset] required to reveal an element in a viewport and +/// the [rect] position said element would have in the viewport at that +/// [offset]. +class RevealedOffset { + /// Instantiates a return value for [RenderAbstractViewport.getOffsetToReveal]. + const RevealedOffset({ + required this.offset, + required this.rect, + }); + + /// Offset for the viewport to reveal a specific element in the viewport. + /// + /// See also: + /// + /// * [RenderAbstractViewport.getOffsetToReveal], which calculates this + /// value for a specific element. + final double offset; + + /// The [Rect] in the outer coordinate system of the viewport at which the + /// to-be-revealed element would be located if the viewport's offset is set + /// to [offset]. + /// + /// A viewport usually has two coordinate systems and works as an adapter + /// between the two: + /// + /// The inner coordinate system has its origin at the top left corner of the + /// content that moves inside the viewport. The origin of this coordinate + /// system usually moves around relative to the leading edge of the viewport + /// when the viewport offset changes. + /// + /// The outer coordinate system has its origin at the top left corner of the + /// visible part of the viewport. This origin stays at the same position + /// regardless of the current viewport offset. + /// + /// In other words: [rect] describes where the revealed element would be + /// located relative to the top left corner of the visible part of the + /// viewport if the viewport's offset is set to [offset]. + /// + /// See also: + /// + /// * [RenderAbstractViewport.getOffsetToReveal], which calculates this + /// value for a specific element. + final Rect rect; + + /// Determines which provided leading or trailing edge of the viewport, as + /// [RevealedOffset]s, will be used for [RenderViewportBase.showInViewport] + /// accounting for the size and already visible portion of the [RenderObject] + /// that is being revealed. + /// + /// Also used by [RenderTwoDimensionalViewport.showInViewport] for each + /// horizontal and vertical [Axis]. + /// + /// If the target [RenderObject] is already fully visible, this will return + /// null. + static RevealedOffset? clampOffset({ + required RevealedOffset leadingEdgeOffset, + required RevealedOffset trailingEdgeOffset, + required double currentOffset, + }) { + // scrollOffset + // 0 +---------+ + // | | + // _ | | + // viewport position | | | + // with `descendant` at | | | _ + // trailing edge |_ | xxxxxxx | | viewport position + // | | | with `descendant` at + // | | _| leading edge + // | | + // 800 +---------+ + // + // `trailingEdgeOffset`: Distance from scrollOffset 0 to the start of the + // viewport on the left in image above. + // `leadingEdgeOffset`: Distance from scrollOffset 0 to the start of the + // viewport on the right in image above. + // + // The viewport position on the left is achieved by setting `offset.pixels` + // to `trailingEdgeOffset`, the one on the right by setting it to + // `leadingEdgeOffset`. + final bool inverted = leadingEdgeOffset.offset < trailingEdgeOffset.offset; + final RevealedOffset smaller; + final RevealedOffset larger; + (smaller, larger) = inverted + ? (leadingEdgeOffset, trailingEdgeOffset) + : (trailingEdgeOffset, leadingEdgeOffset); + if (currentOffset > larger.offset) { + return larger; + } else if (currentOffset < smaller.offset) { + return smaller; + } else { + return null; + } + } + + @override + String toString() { + return '${objectRuntimeType(this, 'RevealedOffset')}(offset: $offset, rect: $rect)'; + } +} + +/// A base class for render objects that are bigger on the inside. +/// +/// This render object provides the shared code for render objects that host +/// [RenderSliver] render objects inside a [RenderBox]. The viewport establishes +/// an [axisDirection], which orients the sliver's coordinate system, which is +/// based on scroll offsets rather than Cartesian coordinates. +/// +/// The viewport also listens to an [offset], which determines the +/// [SliverConstraints.scrollOffset] input to the sliver layout protocol. +/// +/// Subclasses typically override [performLayout] and call +/// [layoutChildSequence], perhaps multiple times. +/// +/// See also: +/// +/// * [RenderSliver], which explains more about the Sliver protocol. +/// * [RenderBox], which explains more about the Box protocol. +/// * [RenderSliverToBoxAdapter], which allows a [RenderBox] object to be +/// placed inside a [RenderSliver] (the opposite of this class). +abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMixin<RenderSliver>> + extends RenderBox with ContainerRenderObjectMixin<RenderSliver, ParentDataClass> + implements RenderAbstractViewport { + /// Initializes fields for subclasses. + /// + /// The [cacheExtent], if null, defaults to [RenderAbstractViewport.defaultCacheExtent]. + /// + /// The [cacheExtent] must be specified if [cacheExtentStyle] is not [CacheExtentStyle.pixel]. + RenderViewportBase({ + AxisDirection axisDirection = AxisDirection.down, + required AxisDirection crossAxisDirection, + required ViewportOffset offset, + double? cacheExtent, + CacheExtentStyle cacheExtentStyle = CacheExtentStyle.pixel, + Clip clipBehavior = Clip.hardEdge, + }) : assert(axisDirectionToAxis(axisDirection) != axisDirectionToAxis(crossAxisDirection)), + assert(cacheExtent != null || cacheExtentStyle == CacheExtentStyle.pixel), + _axisDirection = axisDirection, + _crossAxisDirection = crossAxisDirection, + _offset = offset, + _cacheExtent = cacheExtent ?? RenderAbstractViewport.defaultCacheExtent, + _cacheExtentStyle = cacheExtentStyle, + _clipBehavior = clipBehavior; + + /// Report the semantics of this node, for example for accessibility purposes. + /// + /// [RenderViewportBase] adds [RenderViewport.useTwoPaneSemantics] to the + /// provided [SemanticsConfiguration] to support children using + /// [RenderViewport.excludeFromScrolling]. + /// + /// This method should be overridden by subclasses that have interesting + /// semantic information. Overriding subclasses should call + /// `super.describeSemanticsConfiguration(config)` to ensure + /// [RenderViewport.useTwoPaneSemantics] is still added to `config`. + /// + /// See also: + /// + /// * [RenderObject.describeSemanticsConfiguration], for important + /// details about not mutating a [SemanticsConfiguration] out of context. + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + + config.addTagForChildren(RenderViewport.useTwoPaneSemantics); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + childrenInPaintOrder + .where((RenderSliver sliver) => sliver.geometry!.visible || sliver.geometry!.cacheExtent > 0.0) + .forEach(visitor); + } + + /// The direction in which the [SliverConstraints.scrollOffset] increases. + /// + /// For example, if the [axisDirection] is [AxisDirection.down], a scroll + /// offset of zero is at the top of the viewport and increases towards the + /// bottom of the viewport. + AxisDirection get axisDirection => _axisDirection; + AxisDirection _axisDirection; + set axisDirection(AxisDirection value) { + if (value == _axisDirection) { + return; + } + _axisDirection = value; + markNeedsLayout(); + } + + /// The direction in which child should be laid out in the cross axis. + /// + /// For example, if the [axisDirection] is [AxisDirection.down], this property + /// is typically [AxisDirection.left] if the ambient [TextDirection] is + /// [TextDirection.rtl] and [AxisDirection.right] if the ambient + /// [TextDirection] is [TextDirection.ltr]. + AxisDirection get crossAxisDirection => _crossAxisDirection; + AxisDirection _crossAxisDirection; + set crossAxisDirection(AxisDirection value) { + if (value == _crossAxisDirection) { + return; + } + _crossAxisDirection = value; + markNeedsLayout(); + } + + /// The axis along which the viewport scrolls. + /// + /// For example, if the [axisDirection] is [AxisDirection.down], then the + /// [axis] is [Axis.vertical] and the viewport scrolls vertically. + Axis get axis => axisDirectionToAxis(axisDirection); + + /// Which part of the content inside the viewport should be visible. + /// + /// The [ViewportOffset.pixels] value determines the scroll offset that the + /// viewport uses to select which part of its content to display. As the user + /// scrolls the viewport, this value changes, which changes the content that + /// is displayed. + ViewportOffset get offset => _offset; + ViewportOffset _offset; + set offset(ViewportOffset value) { + if (value == _offset) { + return; + } + if (attached) { + _offset.removeListener(markNeedsLayout); + } + _offset = value; + if (attached) { + _offset.addListener(markNeedsLayout); + } + // We need to go through layout even if the new offset has the same pixels + // value as the old offset so that we will apply our viewport and content + // dimensions. + markNeedsLayout(); + } + + // TODO(ianh): cacheExtent/cacheExtentStyle should be a single + // object that specifies both the scalar value and the unit, not a + // pair of independent setters. Changing that would allow a more + // rational API and would let us make the getter non-nullable. + + /// {@template flutter.rendering.RenderViewportBase.cacheExtent} + /// The viewport has an area before and after the visible area to cache items + /// that are about to become visible when the user scrolls. + /// + /// Items that fall in this cache area are laid out even though they are not + /// (yet) visible on screen. The [cacheExtent] describes how many pixels + /// the cache area extends before the leading edge and after the trailing edge + /// of the viewport. + /// + /// The total extent, which the viewport will try to cover with children, is + /// [cacheExtent] before the leading edge + extent of the main axis + + /// [cacheExtent] after the trailing edge. + /// + /// The cache area is also used to implement implicit accessibility scrolling + /// on iOS: When the accessibility focus moves from an item in the visible + /// viewport to an invisible item in the cache area, the framework will bring + /// that item into view with an (implicit) scroll action. + /// {@endtemplate} + /// + /// The getter can never return null, but the field is nullable + /// because the setter can be set to null to reset the value to + /// [RenderAbstractViewport.defaultCacheExtent] (in which case + /// [cacheExtentStyle] must be [CacheExtentStyle.pixel]). + /// + /// See also: + /// + /// * [cacheExtentStyle], which controls the units of the [cacheExtent]. + double? get cacheExtent => _cacheExtent; + double _cacheExtent; + set cacheExtent(double? value) { + value ??= RenderAbstractViewport.defaultCacheExtent; + if (value == _cacheExtent) { + return; + } + _cacheExtent = value; + markNeedsLayout(); + } + + /// This value is set during layout based on the [CacheExtentStyle]. + /// + /// When the style is [CacheExtentStyle.viewport], it is the main axis extent + /// of the viewport multiplied by the requested cache extent, which is still + /// expressed in pixels. + double? _calculatedCacheExtent; + + /// {@template flutter.rendering.RenderViewportBase.cacheExtentStyle} + /// Controls how the [cacheExtent] is interpreted. + /// + /// If set to [CacheExtentStyle.pixel], the [cacheExtent] will be + /// treated as a logical pixels, and the default [cacheExtent] is + /// [RenderAbstractViewport.defaultCacheExtent]. + /// + /// If set to [CacheExtentStyle.viewport], the [cacheExtent] will be + /// treated as a multiplier for the main axis extent of the + /// viewport. In this case there is no default [cacheExtent]; it + /// must be explicitly specified. + /// {@endtemplate} + /// + /// Changing the [cacheExtentStyle] without also changing the [cacheExtent] + /// is rarely the correct choice. + CacheExtentStyle get cacheExtentStyle => _cacheExtentStyle; + CacheExtentStyle _cacheExtentStyle; + set cacheExtentStyle(CacheExtentStyle value) { + if (value == _cacheExtentStyle) { + return; + } + _cacheExtentStyle = value; + markNeedsLayout(); + } + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.hardEdge; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _offset.addListener(markNeedsLayout); + } + + @override + void detach() { + _offset.removeListener(markNeedsLayout); + super.detach(); + } + + /// Throws an exception saying that the object does not support returning + /// intrinsic dimensions if, in debug mode, we are not in the + /// [RenderObject.debugCheckingIntrinsics] mode. + /// + /// This is used by [computeMinIntrinsicWidth] et al because viewports do not + /// generally support returning intrinsic dimensions. See the discussion at + /// [computeMinIntrinsicWidth]. + @protected + bool debugThrowIfNotCheckingIntrinsics() { + assert(() { + if (!RenderObject.debugCheckingIntrinsics) { + assert(this is! RenderShrinkWrappingViewport); // it has its own message + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$runtimeType does not support returning intrinsic dimensions.'), + ErrorDescription( + 'Calculating the intrinsic dimensions would require instantiating every child of ' + 'the viewport, which defeats the point of viewports being lazy.', + ), + ErrorHint( + 'If you are merely trying to shrink-wrap the viewport in the main axis direction, ' + 'consider a RenderShrinkWrappingViewport render object (ShrinkWrappingViewport widget), ' + 'which achieves that effect without implementing the intrinsic dimension API.', + ), + ]); + } + return true; + }()); + return true; + } + + @override + double computeMinIntrinsicWidth(double height) { + assert(debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + assert(debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + assert(debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + assert(debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + bool get isRepaintBoundary => true; + + /// Determines the size and position of some of the children of the viewport. + /// + /// This function is the workhorse of `performLayout` implementations in + /// subclasses. + /// + /// Layout starts with `child`, proceeds according to the `advance` callback, + /// and stops once `advance` returns null. + /// + /// * `scrollOffset` is the [SliverConstraints.scrollOffset] to pass the + /// first child. The scroll offset is adjusted by + /// [SliverGeometry.scrollExtent] for subsequent children. + /// * `overlap` is the [SliverConstraints.overlap] to pass the first child. + /// The overlay is adjusted by the [SliverGeometry.paintOrigin] and + /// [SliverGeometry.paintExtent] for subsequent children. + /// * `layoutOffset` is the layout offset at which to place the first child. + /// The layout offset is updated by the [SliverGeometry.layoutExtent] for + /// subsequent children. + /// * `remainingPaintExtent` is [SliverConstraints.remainingPaintExtent] to + /// pass the first child. The remaining paint extent is updated by the + /// [SliverGeometry.layoutExtent] for subsequent children. + /// * `mainAxisExtent` is the [SliverConstraints.viewportMainAxisExtent] to + /// pass to each child. + /// * `crossAxisExtent` is the [SliverConstraints.crossAxisExtent] to pass to + /// each child. + /// * `growthDirection` is the [SliverConstraints.growthDirection] to pass to + /// each child. + /// + /// Returns the first non-zero [SliverGeometry.scrollOffsetCorrection] + /// encountered, if any. Otherwise returns 0.0. Typical callers will call this + /// function repeatedly until it returns 0.0. + @protected + double layoutChildSequence({ + required RenderSliver? child, + required double scrollOffset, + required double overlap, + required double layoutOffset, + required double remainingPaintExtent, + required double mainAxisExtent, + required double crossAxisExtent, + required GrowthDirection growthDirection, + required RenderSliver? Function(RenderSliver child) advance, + required double remainingCacheExtent, + required double cacheOrigin, + }) { + assert(scrollOffset.isFinite); + assert(scrollOffset >= 0.0); + final double initialLayoutOffset = layoutOffset; + final ScrollDirection adjustedUserScrollDirection = + applyGrowthDirectionToScrollDirection(offset.userScrollDirection, growthDirection); + double maxPaintOffset = layoutOffset + overlap; + double precedingScrollExtent = 0.0; + + while (child != null) { + final double sliverScrollOffset = scrollOffset <= 0.0 ? 0.0 : scrollOffset; + // If the scrollOffset is too small we adjust the paddedOrigin because it + // doesn't make sense to ask a sliver for content before its scroll + // offset. + final double correctedCacheOrigin = math.max(cacheOrigin, -sliverScrollOffset); + final double cacheExtentCorrection = cacheOrigin - correctedCacheOrigin; + + assert(sliverScrollOffset >= correctedCacheOrigin.abs()); + assert(correctedCacheOrigin <= 0.0); + assert(sliverScrollOffset >= 0.0); + assert(cacheExtentCorrection <= 0.0); + + child.layout(SliverConstraints( + axisDirection: axisDirection, + growthDirection: growthDirection, + userScrollDirection: adjustedUserScrollDirection, + scrollOffset: sliverScrollOffset, + precedingScrollExtent: precedingScrollExtent, + overlap: maxPaintOffset - layoutOffset, + remainingPaintExtent: math.max(0.0, remainingPaintExtent - layoutOffset + initialLayoutOffset), + crossAxisExtent: crossAxisExtent, + crossAxisDirection: crossAxisDirection, + viewportMainAxisExtent: mainAxisExtent, + remainingCacheExtent: math.max(0.0, remainingCacheExtent + cacheExtentCorrection), + cacheOrigin: correctedCacheOrigin, + ), parentUsesSize: true); + + final SliverGeometry childLayoutGeometry = child.geometry!; + assert(childLayoutGeometry.debugAssertIsValid()); + + // If there is a correction to apply, we'll have to start over. + if (childLayoutGeometry.scrollOffsetCorrection != null) { + return childLayoutGeometry.scrollOffsetCorrection!; + } + + // We use the child's paint origin in our coordinate system as the + // layoutOffset we store in the child's parent data. + final double effectiveLayoutOffset = layoutOffset + childLayoutGeometry.paintOrigin; + + // `effectiveLayoutOffset` becomes meaningless once we moved past the trailing edge + // because `childLayoutGeometry.layoutExtent` is zero. Using the still increasing + // 'scrollOffset` to roughly position these invisible slivers in the right order. + if (childLayoutGeometry.visible || scrollOffset > 0) { + updateChildLayoutOffset(child, effectiveLayoutOffset, growthDirection); + } else { + updateChildLayoutOffset(child, -scrollOffset + initialLayoutOffset, growthDirection); + } + + maxPaintOffset = math.max(effectiveLayoutOffset + childLayoutGeometry.paintExtent, maxPaintOffset); + scrollOffset -= childLayoutGeometry.scrollExtent; + precedingScrollExtent += childLayoutGeometry.scrollExtent; + layoutOffset += childLayoutGeometry.layoutExtent; + if (childLayoutGeometry.cacheExtent != 0.0) { + remainingCacheExtent -= childLayoutGeometry.cacheExtent - cacheExtentCorrection; + cacheOrigin = math.min(correctedCacheOrigin + childLayoutGeometry.cacheExtent, 0.0); + } + + updateOutOfBandData(growthDirection, childLayoutGeometry); + + // move on to the next child + child = advance(child); + } + + // we made it without a correction, whee! + return 0.0; + } + + @override + Rect? describeApproximatePaintClip(RenderSliver child) { + switch (clipBehavior) { + case Clip.none: + return null; + case Clip.hardEdge: + case Clip.antiAlias: + case Clip.antiAliasWithSaveLayer: + break; + } + + final Rect viewportClip = Offset.zero & size; + // The child's viewportMainAxisExtent can be infinite when a + // RenderShrinkWrappingViewport is given infinite constraints, such as when + // it is the child of a Row or Column (depending on orientation). + // + // For example, a shrink wrapping render sliver may have infinite + // constraints along the viewport's main axis but may also have bouncing + // scroll physics, which will allow for some scrolling effect to occur. + // We should just use the viewportClip - the start of the overlap is at + // double.infinity and so it is effectively meaningless. + if (child.constraints.overlap == 0 || !child.constraints.viewportMainAxisExtent.isFinite) { + return viewportClip; + } + + // Adjust the clip rect for this sliver by the overlap from the previous sliver. + double left = viewportClip.left; + double right = viewportClip.right; + double top = viewportClip.top; + double bottom = viewportClip.bottom; + final double startOfOverlap = child.constraints.viewportMainAxisExtent - child.constraints.remainingPaintExtent; + final double overlapCorrection = startOfOverlap + child.constraints.overlap; + switch (applyGrowthDirectionToAxisDirection(axisDirection, child.constraints.growthDirection)) { + case AxisDirection.down: + top += overlapCorrection; + case AxisDirection.up: + bottom -= overlapCorrection; + case AxisDirection.right: + left += overlapCorrection; + case AxisDirection.left: + right -= overlapCorrection; + } + return Rect.fromLTRB(left, top, right, bottom); + } + + @override + Rect describeSemanticsClip(RenderSliver? child) { + + if (_calculatedCacheExtent == null) { + return semanticBounds; + } + + switch (axis) { + case Axis.vertical: + return Rect.fromLTRB( + semanticBounds.left, + semanticBounds.top - _calculatedCacheExtent!, + semanticBounds.right, + semanticBounds.bottom + _calculatedCacheExtent!, + ); + case Axis.horizontal: + return Rect.fromLTRB( + semanticBounds.left - _calculatedCacheExtent!, + semanticBounds.top, + semanticBounds.right + _calculatedCacheExtent!, + semanticBounds.bottom, + ); + } + } + + @override + void paint(PaintingContext context, Offset offset) { + if (firstChild == null) { + return; + } + if (hasVisualOverflow && clipBehavior != Clip.none) { + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + _paintContents, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + } else { + _clipRectLayer.layer = null; + _paintContents(context, offset); + } + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void dispose() { + _clipRectLayer.layer = null; + super.dispose(); + } + + void _paintContents(PaintingContext context, Offset offset) { + for (final RenderSliver child in childrenInPaintOrder) { + if (child.geometry!.visible) { + context.paintChild(child, offset + paintOffsetOf(child)); + } + } + } + + @override + void debugPaintSize(PaintingContext context, Offset offset) { + assert(() { + super.debugPaintSize(context, offset); + final Paint paint = Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 1.0 + ..color = const Color(0xFF00FF00); + final Canvas canvas = context.canvas; + RenderSliver? child = firstChild; + while (child != null) { + final Size size; + switch (axis) { + case Axis.vertical: + size = Size(child.constraints.crossAxisExtent, child.geometry!.layoutExtent); + case Axis.horizontal: + size = Size(child.geometry!.layoutExtent, child.constraints.crossAxisExtent); + } + canvas.drawRect(((offset + paintOffsetOf(child)) & size).deflate(0.5), paint); + child = childAfter(child); + } + return true; + }()); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + double mainAxisPosition, crossAxisPosition; + switch (axis) { + case Axis.vertical: + mainAxisPosition = position.dy; + crossAxisPosition = position.dx; + case Axis.horizontal: + mainAxisPosition = position.dx; + crossAxisPosition = position.dy; + } + final SliverHitTestResult sliverResult = SliverHitTestResult.wrap(result); + for (final RenderSliver child in childrenInHitTestOrder) { + if (!child.geometry!.visible) { + continue; + } + final Matrix4 transform = Matrix4.identity(); + applyPaintTransform(child, transform); // must be invertible + final bool isHit = result.addWithOutOfBandPosition( + paintTransform: transform, + hitTest: (BoxHitTestResult result) { + return child.hitTest( + sliverResult, + mainAxisPosition: computeChildMainAxisPosition(child, mainAxisPosition), + crossAxisPosition: crossAxisPosition, + ); + }, + ); + if (isHit) { + return true; + } + } + return false; + } + + @override + RevealedOffset getOffsetToReveal( + RenderObject target, + double alignment, { + Rect? rect, + Axis? axis, + }) { + // One dimensional viewport has only one axis, override if it was + // provided/may be mismatched. + axis = this.axis; + + // Steps to convert `rect` (from a RenderBox coordinate system) to its + // scroll offset within this viewport (not in the exact order): + // + // 1. Pick the outermost RenderBox (between which, and the viewport, there + // is nothing but RenderSlivers) as an intermediate reference frame + // (the `pivot`), convert `rect` to that coordinate space. + // + // 2. Convert `rect` from the `pivot` coordinate space to its sliver + // parent's sliver coordinate system (i.e., to a scroll offset), based on + // the axis direction and growth direction of the parent. + // + // 3. Convert the scroll offset to its sliver parent's coordinate space + // using `childScrollOffset`, until we reach the viewport. + // + // 4. Make the final conversion from the outmost sliver to the viewport + // using `scrollOffsetOf`. + + double leadingScrollOffset = 0.0; + // Starting at `target` and walking towards the root: + // - `child` will be the last object before we reach this viewport, and + // - `pivot` will be the last RenderBox before we reach this viewport. + RenderObject child = target; + RenderBox? pivot; + bool onlySlivers = target is RenderSliver; // ... between viewport and `target` (`target` included). + while (child.parent != this) { + final RenderObject parent = child.parent!; + if (child is RenderBox) { + pivot = child; + } + if (parent is RenderSliver) { + leadingScrollOffset += parent.childScrollOffset(child)!; + } else { + onlySlivers = false; + leadingScrollOffset = 0.0; + } + child = parent; + } + + // `rect` in the new intermediate coordinate system. + final Rect rectLocal; + // Our new reference frame render object's main axis extent. + final double pivotExtent; + final GrowthDirection growthDirection; + + // `leadingScrollOffset` is currently the scrollOffset of our new reference + // frame (`pivot` or `target`), within `child`. + if (pivot != null) { + assert(pivot.parent != null); + assert(pivot.parent != this); + assert(pivot != this); + assert(pivot.parent is RenderSliver); // TODO(abarth): Support other kinds of render objects besides slivers. + final RenderSliver pivotParent = pivot.parent! as RenderSliver; + growthDirection = pivotParent.constraints.growthDirection; + switch (axis) { + case Axis.horizontal: + pivotExtent = pivot.size.width; + case Axis.vertical: + pivotExtent = pivot.size.height; + } + rect ??= target.paintBounds; + rectLocal = MatrixUtils.transformRect(target.getTransformTo(pivot), rect); + } else if (onlySlivers) { + // `pivot` does not exist. We'll have to make up one from `target`, the + // innermost sliver. + final RenderSliver targetSliver = target as RenderSliver; + growthDirection = targetSliver.constraints.growthDirection; + // TODO(LongCatIsLooong): make sure this works if `targetSliver` is a + // persistent header, when #56413 relands. + pivotExtent = targetSliver.geometry!.scrollExtent; + if (rect == null) { + switch (axis) { + case Axis.horizontal: + rect = Rect.fromLTWH( + 0, 0, + targetSliver.geometry!.scrollExtent, + targetSliver.constraints.crossAxisExtent, + ); + case Axis.vertical: + rect = Rect.fromLTWH( + 0, 0, + targetSliver.constraints.crossAxisExtent, + targetSliver.geometry!.scrollExtent, + ); + } + } + rectLocal = rect; + } else { + assert(rect != null); + return RevealedOffset(offset: offset.pixels, rect: rect!); + } + + assert(child.parent == this); + assert(child is RenderSliver); + final RenderSliver sliver = child as RenderSliver; + + final double targetMainAxisExtent; + // The scroll offset of `rect` within `child`. + switch (applyGrowthDirectionToAxisDirection(axisDirection, growthDirection)) { + case AxisDirection.up: + leadingScrollOffset += pivotExtent - rectLocal.bottom; + targetMainAxisExtent = rectLocal.height; + case AxisDirection.right: + leadingScrollOffset += rectLocal.left; + targetMainAxisExtent = rectLocal.width; + case AxisDirection.down: + leadingScrollOffset += rectLocal.top; + targetMainAxisExtent = rectLocal.height; + case AxisDirection.left: + leadingScrollOffset += pivotExtent - rectLocal.right; + targetMainAxisExtent = rectLocal.width; + } + + // So far leadingScrollOffset is the scroll offset of `rect` in the `child` + // sliver's sliver coordinate system. The sign of this value indicates + // whether the `rect` protrudes the leading edge of the `child` sliver. When + // this value is non-negative and `child`'s `maxScrollObstructionExtent` is + // greater than 0, we assume `rect` can't be obstructed by the leading edge + // of the viewport (i.e. its pinned to the leading edge). + final bool isPinned = sliver.geometry!.maxScrollObstructionExtent > 0 && leadingScrollOffset >= 0; + + // The scroll offset in the viewport to `rect`. + leadingScrollOffset = scrollOffsetOf(sliver, leadingScrollOffset); + + // This step assumes the viewport's layout is up-to-date, i.e., if + // offset.pixels is changed after the last performLayout, the new scroll + // position will not be accounted for. + final Matrix4 transform = target.getTransformTo(this); + Rect targetRect = MatrixUtils.transformRect(transform, rect); + final double extentOfPinnedSlivers = maxScrollObstructionExtentBefore(sliver); + + switch (sliver.constraints.growthDirection) { + case GrowthDirection.forward: + if (isPinned && alignment <= 0) { + return RevealedOffset(offset: double.infinity, rect: targetRect); + } + leadingScrollOffset -= extentOfPinnedSlivers; + case GrowthDirection.reverse: + if (isPinned && alignment >= 1) { + return RevealedOffset(offset: double.negativeInfinity, rect: targetRect); + } + // If child's growth direction is reverse, when viewport.offset is + // `leadingScrollOffset`, it is positioned just outside of the leading + // edge of the viewport. + switch (axis) { + case Axis.vertical: + leadingScrollOffset -= targetRect.height; + case Axis.horizontal: + leadingScrollOffset -= targetRect.width; + } + } + + final double mainAxisExtent; + switch (axis) { + case Axis.horizontal: + mainAxisExtent = size.width - extentOfPinnedSlivers; + case Axis.vertical: + mainAxisExtent = size.height - extentOfPinnedSlivers; + } + + final double targetOffset = leadingScrollOffset - (mainAxisExtent - targetMainAxisExtent) * alignment; + final double offsetDifference = offset.pixels - targetOffset; + + switch (axisDirection) { + case AxisDirection.down: + targetRect = targetRect.translate(0.0, offsetDifference); + case AxisDirection.right: + targetRect = targetRect.translate(offsetDifference, 0.0); + case AxisDirection.up: + targetRect = targetRect.translate(0.0, -offsetDifference); + case AxisDirection.left: + targetRect = targetRect.translate(-offsetDifference, 0.0); + } + + return RevealedOffset(offset: targetOffset, rect: targetRect); + } + + /// The offset at which the given `child` should be painted. + /// + /// The returned offset is from the top left corner of the inside of the + /// viewport to the top left corner of the paint coordinate system of the + /// `child`. + /// + /// See also: + /// + /// * [paintOffsetOf], which uses the layout offset and growth direction + /// computed for the child during layout. + @protected + Offset computeAbsolutePaintOffset(RenderSliver child, double layoutOffset, GrowthDirection growthDirection) { + assert(hasSize); // this is only usable once we have a size + assert(child.geometry != null); + switch (applyGrowthDirectionToAxisDirection(axisDirection, growthDirection)) { + case AxisDirection.up: + return Offset(0.0, size.height - (layoutOffset + child.geometry!.paintExtent)); + case AxisDirection.right: + return Offset(layoutOffset, 0.0); + case AxisDirection.down: + return Offset(0.0, layoutOffset); + case AxisDirection.left: + return Offset(size.width - (layoutOffset + child.geometry!.paintExtent), 0.0); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<AxisDirection>('axisDirection', axisDirection)); + properties.add(EnumProperty<AxisDirection>('crossAxisDirection', crossAxisDirection)); + properties.add(DiagnosticsProperty<ViewportOffset>('offset', offset)); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<DiagnosticsNode> children = <DiagnosticsNode>[]; + RenderSliver? child = firstChild; + if (child == null) { + return children; + } + + int count = indexOfFirstChild; + while (true) { + children.add(child!.toDiagnosticsNode(name: labelForChild(count))); + if (child == lastChild) { + break; + } + count += 1; + child = childAfter(child); + } + return children; + } + + // API TO BE IMPLEMENTED BY SUBCLASSES + + // setupParentData + + // performLayout (and optionally sizedByParent and performResize) + + /// Whether the contents of this viewport would paint outside the bounds of + /// the viewport if [paint] did not clip. + /// + /// This property enables an optimization whereby [paint] can skip apply a + /// clip of the contents of the viewport are known to paint entirely within + /// the bounds of the viewport. + @protected + bool get hasVisualOverflow; + + /// Called during [layoutChildSequence] for each child. + /// + /// Typically used by subclasses to update any out-of-band data, such as the + /// max scroll extent, for each child. + @protected + void updateOutOfBandData(GrowthDirection growthDirection, SliverGeometry childLayoutGeometry); + + /// Called during [layoutChildSequence] to store the layout offset for the + /// given child. + /// + /// Different subclasses using different representations for their children's + /// layout offset (e.g., logical or physical coordinates). This function lets + /// subclasses transform the child's layout offset before storing it in the + /// child's parent data. + @protected + void updateChildLayoutOffset(RenderSliver child, double layoutOffset, GrowthDirection growthDirection); + + /// The offset at which the given `child` should be painted. + /// + /// The returned offset is from the top left corner of the inside of the + /// viewport to the top left corner of the paint coordinate system of the + /// `child`. + /// + /// See also: + /// + /// * [computeAbsolutePaintOffset], which computes the paint offset from an + /// explicit layout offset and growth direction instead of using the values + /// computed for the child during layout. + @protected + Offset paintOffsetOf(RenderSliver child); + + /// Returns the scroll offset within the viewport for the given + /// `scrollOffsetWithinChild` within the given `child`. + /// + /// The returned value is an estimate that assumes the slivers within the + /// viewport do not change the layout extent in response to changes in their + /// scroll offset. + @protected + double scrollOffsetOf(RenderSliver child, double scrollOffsetWithinChild); + + /// Returns the total scroll obstruction extent of all slivers in the viewport + /// before [child]. + /// + /// This is the extent by which the actual area in which content can scroll + /// is reduced. For example, an app bar that is pinned at the top will reduce + /// the area in which content can actually scroll by the height of the app bar. + @protected + double maxScrollObstructionExtentBefore(RenderSliver child); + + /// Converts the `parentMainAxisPosition` into the child's coordinate system. + /// + /// The `parentMainAxisPosition` is a distance from the top edge (for vertical + /// viewports) or left edge (for horizontal viewports) of the viewport bounds. + /// This describes a line, perpendicular to the viewport's main axis, heretofore + /// known as the target line. + /// + /// The child's coordinate system's origin in the main axis is at the leading + /// edge of the given child, as given by the child's + /// [SliverConstraints.axisDirection] and [SliverConstraints.growthDirection]. + /// + /// This method returns the distance from the leading edge of the given child to + /// the target line described above. + /// + /// (The `parentMainAxisPosition` is not from the leading edge of the + /// viewport, it's always the top or left edge.) + @protected + double computeChildMainAxisPosition(RenderSliver child, double parentMainAxisPosition); + + /// The index of the first child of the viewport relative to the center child. + /// + /// For example, the center child has index zero and the first child in the + /// reverse growth direction has index -1. + @protected + int get indexOfFirstChild; + + /// A short string to identify the child with the given index. + /// + /// Used by [debugDescribeChildren] to label the children. + @protected + String labelForChild(int index); + + /// Provides an iterable that walks the children of the viewport, in the order + /// that they should be painted. + /// + /// This should be the reverse order of [childrenInHitTestOrder]. + @protected + Iterable<RenderSliver> get childrenInPaintOrder; + + /// Provides an iterable that walks the children of the viewport, in the order + /// that hit-testing should use. + /// + /// This should be the reverse order of [childrenInPaintOrder]. + @protected + Iterable<RenderSliver> get childrenInHitTestOrder; + + @override + void showOnScreen({ + RenderObject? descendant, + Rect? rect, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + }) { + if (!offset.allowImplicitScrolling) { + return super.showOnScreen( + descendant: descendant, + rect: rect, + duration: duration, + curve: curve, + ); + } + + final Rect? newRect = RenderViewportBase.showInViewport( + descendant: descendant, + viewport: this, + offset: offset, + rect: rect, + duration: duration, + curve: curve, + ); + super.showOnScreen( + rect: newRect, + duration: duration, + curve: curve, + ); + } + + /// Make (a portion of) the given `descendant` of the given `viewport` fully + /// visible in the `viewport` by manipulating the provided [ViewportOffset] + /// `offset`. + /// + /// The optional `rect` parameter describes which area of the `descendant` + /// should be shown in the viewport. If `rect` is null, the entire + /// `descendant` will be revealed. The `rect` parameter is interpreted + /// relative to the coordinate system of `descendant`. + /// + /// The returned [Rect] describes the new location of `descendant` or `rect` + /// in the viewport after it has been revealed. See [RevealedOffset.rect] + /// for a full definition of this [Rect]. + /// + /// If `descendant` is null, this is a no-op and `rect` is returned. + /// + /// If both `descendant` and `rect` are null, null is returned because there is + /// nothing to be shown in the viewport. + /// + /// The `duration` parameter can be set to a non-zero value to animate the + /// target object into the viewport with an animation defined by `curve`. + /// + /// See also: + /// + /// * [RenderObject.showOnScreen], overridden by [RenderViewportBase] and the + /// renderer for [SingleChildScrollView] to delegate to this method. + static Rect? showInViewport({ + RenderObject? descendant, + Rect? rect, + required RenderAbstractViewport viewport, + required ViewportOffset offset, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + }) { + if (descendant == null) { + return rect; + } + final RevealedOffset leadingEdgeOffset = viewport.getOffsetToReveal(descendant, 0.0, rect: rect); + final RevealedOffset trailingEdgeOffset = viewport.getOffsetToReveal(descendant, 1.0, rect: rect); + final double currentOffset = offset.pixels; + final RevealedOffset? targetOffset = RevealedOffset.clampOffset( + leadingEdgeOffset: leadingEdgeOffset, + trailingEdgeOffset: trailingEdgeOffset, + currentOffset: currentOffset, + ); + if (targetOffset == null) { + // `descendant` is between leading and trailing edge and hence already + // fully shown on screen. No action necessary. + assert(viewport.parent != null); + final Matrix4 transform = descendant.getTransformTo(viewport.parent); + return MatrixUtils.transformRect(transform, rect ?? descendant.paintBounds); + } + + offset.moveTo(targetOffset.offset, duration: duration, curve: curve); + return targetOffset.rect; + } +} + +/// A render object that is bigger on the inside. +/// +/// [RenderViewport] is the visual workhorse of the scrolling machinery. It +/// displays a subset of its children according to its own dimensions and the +/// given [offset]. As the offset varies, different children are visible through +/// the viewport. +/// +/// [RenderViewport] hosts a bidirectional list of slivers in a single shared +/// [Axis], anchored on a [center] sliver, which is placed at the zero scroll +/// offset. The center widget is displayed in the viewport according to the +/// [anchor] property. +/// +/// Slivers that are earlier in the child list than [center] are displayed in +/// reverse order in the reverse [axisDirection] starting from the [center]. For +/// example, if the [axisDirection] is [AxisDirection.down], the first sliver +/// before [center] is placed above the [center]. The slivers that are later in +/// the child list than [center] are placed in order in the [axisDirection]. For +/// example, in the preceding scenario, the first sliver after [center] is +/// placed below the [center]. +/// +/// {@macro flutter.rendering.GrowthDirection.sample} +/// +/// [RenderViewport] cannot contain [RenderBox] children directly. Instead, use +/// a [RenderSliverList], [RenderSliverFixedExtentList], [RenderSliverGrid], or +/// a [RenderSliverToBoxAdapter], for example. +/// +/// See also: +/// +/// * [RenderSliver], which explains more about the Sliver protocol. +/// * [RenderBox], which explains more about the Box protocol. +/// * [RenderSliverToBoxAdapter], which allows a [RenderBox] object to be +/// placed inside a [RenderSliver] (the opposite of this class). +/// * [RenderShrinkWrappingViewport], a variant of [RenderViewport] that +/// shrink-wraps its contents along the main axis. +class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentData> { + /// Creates a viewport for [RenderSliver] objects. + /// + /// If the [center] is not specified, then the first child in the `children` + /// list, if any, is used. + /// + /// The [offset] must be specified. For testing purposes, consider passing a + /// [ViewportOffset.zero] or [ViewportOffset.fixed]. + RenderViewport({ + super.axisDirection, + required super.crossAxisDirection, + required super.offset, + double anchor = 0.0, + List<RenderSliver>? children, + RenderSliver? center, + super.cacheExtent, + super.cacheExtentStyle, + super.clipBehavior, + }) : assert(anchor >= 0.0 && anchor <= 1.0), + assert(cacheExtentStyle != CacheExtentStyle.viewport || cacheExtent != null), + _anchor = anchor, + _center = center { + addAll(children); + if (center == null && firstChild != null) { + _center = firstChild; + } + } + + /// If a [RenderAbstractViewport] overrides + /// [RenderObject.describeSemanticsConfiguration] to add the [SemanticsTag] + /// [useTwoPaneSemantics] to its [SemanticsConfiguration], two semantics nodes + /// will be used to represent the viewport with its associated scrolling + /// actions in the semantics tree. + /// + /// Two semantics nodes (an inner and an outer node) are necessary to exclude + /// certain child nodes (via the [excludeFromScrolling] tag) from the + /// scrollable area for semantic purposes: The [SemanticsNode]s of children + /// that should be excluded from scrolling will be attached to the outer node. + /// The semantic scrolling actions and the [SemanticsNode]s of scrollable + /// children will be attached to the inner node, which itself is a child of + /// the outer node. + /// + /// See also: + /// + /// * [RenderViewportBase.describeSemanticsConfiguration], which adds this + /// tag to its [SemanticsConfiguration]. + static const SemanticsTag useTwoPaneSemantics = SemanticsTag('RenderViewport.twoPane'); + + /// When a top-level [SemanticsNode] below a [RenderAbstractViewport] is + /// tagged with [excludeFromScrolling] it will not be part of the scrolling + /// area for semantic purposes. + /// + /// This behavior is only active if the [RenderAbstractViewport] + /// tagged its [SemanticsConfiguration] with [useTwoPaneSemantics]. + /// Otherwise, the [excludeFromScrolling] tag is ignored. + /// + /// As an example, a [RenderSliver] that stays on the screen within a + /// [Scrollable] even though the user has scrolled past it (e.g. a pinned app + /// bar) can tag its [SemanticsNode] with [excludeFromScrolling] to indicate + /// that it should no longer be considered for semantic actions related to + /// scrolling. + static const SemanticsTag excludeFromScrolling = SemanticsTag('RenderViewport.excludeFromScrolling'); + + @override + void setupParentData(RenderObject child) { + if (child.parentData is! SliverPhysicalContainerParentData) { + child.parentData = SliverPhysicalContainerParentData(); + } + } + + /// The relative position of the zero scroll offset. + /// + /// For example, if [anchor] is 0.5 and the [axisDirection] is + /// [AxisDirection.down] or [AxisDirection.up], then the zero scroll offset is + /// vertically centered within the viewport. If the [anchor] is 1.0, and the + /// [axisDirection] is [AxisDirection.right], then the zero scroll offset is + /// on the left edge of the viewport. + /// + /// {@macro flutter.rendering.GrowthDirection.sample} + double get anchor => _anchor; + double _anchor; + set anchor(double value) { + assert(value >= 0.0 && value <= 1.0); + if (value == _anchor) { + return; + } + _anchor = value; + markNeedsLayout(); + } + + /// The first child in the [GrowthDirection.forward] growth direction. + /// + /// This child that will be at the position defined by [anchor] when the + /// [ViewportOffset.pixels] of [offset] is `0`. + /// + /// Children after [center] will be placed in the [axisDirection] relative to + /// the [center]. + /// + /// Children before [center] will be placed in the opposite of + /// the [axisDirection] relative to the [center]. These children above + /// [center] will have a growth direction of [GrowthDirection.reverse]. + /// + /// The [center] must be a direct child of the viewport. + /// + /// {@macro flutter.rendering.GrowthDirection.sample} + RenderSliver? get center => _center; + RenderSliver? _center; + set center(RenderSliver? value) { + if (value == _center) { + return; + } + _center = value; + markNeedsLayout(); + } + + @override + bool get sizedByParent => true; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + assert(debugCheckHasBoundedAxis(axis, constraints)); + return constraints.biggest; + } + + static const int _maxLayoutCycles = 10; + + // Out-of-band data computed during layout. + late double _minScrollExtent; + late double _maxScrollExtent; + bool _hasVisualOverflow = false; + + @override + void performLayout() { + // Ignore the return value of applyViewportDimension because we are + // doing a layout regardless. + switch (axis) { + case Axis.vertical: + offset.applyViewportDimension(size.height); + case Axis.horizontal: + offset.applyViewportDimension(size.width); + } + + if (center == null) { + assert(firstChild == null); + _minScrollExtent = 0.0; + _maxScrollExtent = 0.0; + _hasVisualOverflow = false; + offset.applyContentDimensions(0.0, 0.0); + return; + } + assert(center!.parent == this); + + final double mainAxisExtent; + final double crossAxisExtent; + switch (axis) { + case Axis.vertical: + mainAxisExtent = size.height; + crossAxisExtent = size.width; + case Axis.horizontal: + mainAxisExtent = size.width; + crossAxisExtent = size.height; + } + + final double centerOffsetAdjustment = center!.centerOffsetAdjustment; + + double correction; + int count = 0; + do { + correction = _attemptLayout(mainAxisExtent, crossAxisExtent, offset.pixels + centerOffsetAdjustment); + if (correction != 0.0) { + offset.correctBy(correction); + } else { + if (offset.applyContentDimensions( + math.min(0.0, _minScrollExtent + mainAxisExtent * anchor), + math.max(0.0, _maxScrollExtent - mainAxisExtent * (1.0 - anchor)), + )) { + break; + } + } + count += 1; + } while (count < _maxLayoutCycles); + assert(() { + if (count >= _maxLayoutCycles) { + assert(count != 1); + throw FlutterError( + 'A RenderViewport exceeded its maximum number of layout cycles.\n' + 'RenderViewport render objects, during layout, can retry if either their ' + 'slivers or their ViewportOffset decide that the offset should be corrected ' + 'to take into account information collected during that layout.\n' + 'In the case of this RenderViewport object, however, this happened $count ' + 'times and still there was no consensus on the scroll offset. This usually ' + 'indicates a bug. Specifically, it means that one of the following three ' + 'problems is being experienced by the RenderViewport object:\n' + ' * One of the RenderSliver children or the ViewportOffset have a bug such' + ' that they always think that they need to correct the offset regardless.\n' + ' * Some combination of the RenderSliver children and the ViewportOffset' + ' have a bad interaction such that one applies a correction then another' + ' applies a reverse correction, leading to an infinite loop of corrections.\n' + ' * There is a pathological case that would eventually resolve, but it is' + ' so complicated that it cannot be resolved in any reasonable number of' + ' layout passes.', + ); + } + return true; + }()); + } + + double _attemptLayout(double mainAxisExtent, double crossAxisExtent, double correctedOffset) { + assert(!mainAxisExtent.isNaN); + assert(mainAxisExtent >= 0.0); + assert(crossAxisExtent.isFinite); + assert(crossAxisExtent >= 0.0); + assert(correctedOffset.isFinite); + _minScrollExtent = 0.0; + _maxScrollExtent = 0.0; + _hasVisualOverflow = false; + + // centerOffset is the offset from the leading edge of the RenderViewport + // to the zero scroll offset (the line between the forward slivers and the + // reverse slivers). + final double centerOffset = mainAxisExtent * anchor - correctedOffset; + final double reverseDirectionRemainingPaintExtent = clampDouble(centerOffset, 0.0, mainAxisExtent); + final double forwardDirectionRemainingPaintExtent = clampDouble(mainAxisExtent - centerOffset, 0.0, mainAxisExtent); + + switch (cacheExtentStyle) { + case CacheExtentStyle.pixel: + _calculatedCacheExtent = cacheExtent; + case CacheExtentStyle.viewport: + _calculatedCacheExtent = mainAxisExtent * _cacheExtent; + } + + final double fullCacheExtent = mainAxisExtent + 2 * _calculatedCacheExtent!; + final double centerCacheOffset = centerOffset + _calculatedCacheExtent!; + final double reverseDirectionRemainingCacheExtent = clampDouble(centerCacheOffset, 0.0, fullCacheExtent); + final double forwardDirectionRemainingCacheExtent = clampDouble(fullCacheExtent - centerCacheOffset, 0.0, fullCacheExtent); + + final RenderSliver? leadingNegativeChild = childBefore(center!); + + if (leadingNegativeChild != null) { + // negative scroll offsets + final double result = layoutChildSequence( + child: leadingNegativeChild, + scrollOffset: math.max(mainAxisExtent, centerOffset) - mainAxisExtent, + overlap: 0.0, + layoutOffset: forwardDirectionRemainingPaintExtent, + remainingPaintExtent: reverseDirectionRemainingPaintExtent, + mainAxisExtent: mainAxisExtent, + crossAxisExtent: crossAxisExtent, + growthDirection: GrowthDirection.reverse, + advance: childBefore, + remainingCacheExtent: reverseDirectionRemainingCacheExtent, + cacheOrigin: clampDouble(mainAxisExtent - centerOffset, -_calculatedCacheExtent!, 0.0), + ); + if (result != 0.0) { + return -result; + } + } + + // positive scroll offsets + return layoutChildSequence( + child: center, + scrollOffset: math.max(0.0, -centerOffset), + overlap: leadingNegativeChild == null ? math.min(0.0, -centerOffset) : 0.0, + layoutOffset: centerOffset >= mainAxisExtent ? centerOffset: reverseDirectionRemainingPaintExtent, + remainingPaintExtent: forwardDirectionRemainingPaintExtent, + mainAxisExtent: mainAxisExtent, + crossAxisExtent: crossAxisExtent, + growthDirection: GrowthDirection.forward, + advance: childAfter, + remainingCacheExtent: forwardDirectionRemainingCacheExtent, + cacheOrigin: clampDouble(centerOffset, -_calculatedCacheExtent!, 0.0), + ); + } + + @override + bool get hasVisualOverflow => _hasVisualOverflow; + + @override + void updateOutOfBandData(GrowthDirection growthDirection, SliverGeometry childLayoutGeometry) { + switch (growthDirection) { + case GrowthDirection.forward: + _maxScrollExtent += childLayoutGeometry.scrollExtent; + case GrowthDirection.reverse: + _minScrollExtent -= childLayoutGeometry.scrollExtent; + } + if (childLayoutGeometry.hasVisualOverflow) { + _hasVisualOverflow = true; + } + } + + @override + void updateChildLayoutOffset(RenderSliver child, double layoutOffset, GrowthDirection growthDirection) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + childParentData.paintOffset = computeAbsolutePaintOffset(child, layoutOffset, growthDirection); + } + + @override + Offset paintOffsetOf(RenderSliver child) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + return childParentData.paintOffset; + } + + @override + double scrollOffsetOf(RenderSliver child, double scrollOffsetWithinChild) { + assert(child.parent == this); + final GrowthDirection growthDirection = child.constraints.growthDirection; + switch (growthDirection) { + case GrowthDirection.forward: + double scrollOffsetToChild = 0.0; + RenderSliver? current = center; + while (current != child) { + scrollOffsetToChild += current!.geometry!.scrollExtent; + current = childAfter(current); + } + return scrollOffsetToChild + scrollOffsetWithinChild; + case GrowthDirection.reverse: + double scrollOffsetToChild = 0.0; + RenderSliver? current = childBefore(center!); + while (current != child) { + scrollOffsetToChild -= current!.geometry!.scrollExtent; + current = childBefore(current); + } + return scrollOffsetToChild - scrollOffsetWithinChild; + } + } + + @override + double maxScrollObstructionExtentBefore(RenderSliver child) { + assert(child.parent == this); + final GrowthDirection growthDirection = child.constraints.growthDirection; + switch (growthDirection) { + case GrowthDirection.forward: + double pinnedExtent = 0.0; + RenderSliver? current = center; + while (current != child) { + pinnedExtent += current!.geometry!.maxScrollObstructionExtent; + current = childAfter(current); + } + return pinnedExtent; + case GrowthDirection.reverse: + double pinnedExtent = 0.0; + RenderSliver? current = childBefore(center!); + while (current != child) { + pinnedExtent += current!.geometry!.maxScrollObstructionExtent; + current = childBefore(current); + } + return pinnedExtent; + } + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + // Hit test logic relies on this always providing an invertible matrix. + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + childParentData.applyPaintTransform(transform); + } + + @override + double computeChildMainAxisPosition(RenderSliver child, double parentMainAxisPosition) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + switch (applyGrowthDirectionToAxisDirection(child.constraints.axisDirection, child.constraints.growthDirection)) { + case AxisDirection.down: + return parentMainAxisPosition - childParentData.paintOffset.dy; + case AxisDirection.right: + return parentMainAxisPosition - childParentData.paintOffset.dx; + case AxisDirection.up: + return child.geometry!.paintExtent - (parentMainAxisPosition - childParentData.paintOffset.dy); + case AxisDirection.left: + return child.geometry!.paintExtent - (parentMainAxisPosition - childParentData.paintOffset.dx); + } + } + + @override + int get indexOfFirstChild { + assert(center != null); + assert(center!.parent == this); + assert(firstChild != null); + int count = 0; + RenderSliver? child = center; + while (child != firstChild) { + count -= 1; + child = childBefore(child!); + } + return count; + } + + @override + String labelForChild(int index) { + if (index == 0) { + return 'center child'; + } + return 'child $index'; + } + + @override + Iterable<RenderSliver> get childrenInPaintOrder { + final List<RenderSliver> children = <RenderSliver>[]; + if (firstChild == null) { + return children; + } + RenderSliver? child = firstChild; + while (child != center) { + children.add(child!); + child = childAfter(child); + } + child = lastChild; + while (true) { + children.add(child!); + if (child == center) { + return children; + } + child = childBefore(child); + } + } + + @override + Iterable<RenderSliver> get childrenInHitTestOrder { + final List<RenderSliver> children = <RenderSliver>[]; + if (firstChild == null) { + return children; + } + RenderSliver? child = center; + while (child != null) { + children.add(child); + child = childAfter(child); + } + child = childBefore(center!); + while (child != null) { + children.add(child); + child = childBefore(child); + } + return children; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('anchor', anchor)); + } +} + +/// A render object that is bigger on the inside and shrink wraps its children +/// in the main axis. +/// +/// [RenderShrinkWrappingViewport] displays a subset of its children according +/// to its own dimensions and the given [offset]. As the offset varies, different +/// children are visible through the viewport. +/// +/// [RenderShrinkWrappingViewport] differs from [RenderViewport] in that +/// [RenderViewport] expands to fill the main axis whereas +/// [RenderShrinkWrappingViewport] sizes itself to match its children in the +/// main axis. This shrink wrapping behavior is expensive because the children, +/// and hence the viewport, could potentially change size whenever the [offset] +/// changes (e.g., because of a collapsing header). +/// +/// [RenderShrinkWrappingViewport] cannot contain [RenderBox] children directly. +/// Instead, use a [RenderSliverList], [RenderSliverFixedExtentList], +/// [RenderSliverGrid], or a [RenderSliverToBoxAdapter], for example. +/// +/// See also: +/// +/// * [RenderViewport], a viewport that does not shrink-wrap its contents. +/// * [RenderSliver], which explains more about the Sliver protocol. +/// * [RenderBox], which explains more about the Box protocol. +/// * [RenderSliverToBoxAdapter], which allows a [RenderBox] object to be +/// placed inside a [RenderSliver] (the opposite of this class). +class RenderShrinkWrappingViewport extends RenderViewportBase<SliverLogicalContainerParentData> { + /// Creates a viewport (for [RenderSliver] objects) that shrink-wraps its + /// contents. + /// + /// The [offset] must be specified. For testing purposes, consider passing a + /// [ViewportOffset.zero] or [ViewportOffset.fixed]. + RenderShrinkWrappingViewport({ + super.axisDirection, + required super.crossAxisDirection, + required super.offset, + super.clipBehavior, + List<RenderSliver>? children, + }) { + addAll(children); + } + + @override + void setupParentData(RenderObject child) { + if (child.parentData is! SliverLogicalContainerParentData) { + child.parentData = SliverLogicalContainerParentData(); + } + } + + @override + bool debugThrowIfNotCheckingIntrinsics() { + assert(() { + if (!RenderObject.debugCheckingIntrinsics) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$runtimeType does not support returning intrinsic dimensions.'), + ErrorDescription( + 'Calculating the intrinsic dimensions would require instantiating every child of ' + 'the viewport, which defeats the point of viewports being lazy.', + ), + ErrorHint( + 'If you are merely trying to shrink-wrap the viewport in the main axis direction, ' + 'you should be able to achieve that effect by just giving the viewport loose ' + 'constraints, without needing to measure its intrinsic dimensions.', + ), + ]); + } + return true; + }()); + return true; + } + + // Out-of-band data computed during layout. + late double _maxScrollExtent; + late double _shrinkWrapExtent; + bool _hasVisualOverflow = false; + + bool _debugCheckHasBoundedCrossAxis() { + assert(() { + switch (axis) { + case Axis.vertical: + if (!constraints.hasBoundedWidth) { + throw FlutterError( + 'Vertical viewport was given unbounded width.\n' + 'Viewports expand in the cross axis to fill their container and ' + 'constrain their children to match their extent in the cross axis. ' + 'In this case, a vertical shrinkwrapping viewport was given an ' + 'unlimited amount of horizontal space in which to expand.', + ); + } + case Axis.horizontal: + if (!constraints.hasBoundedHeight) { + throw FlutterError( + 'Horizontal viewport was given unbounded height.\n' + 'Viewports expand in the cross axis to fill their container and ' + 'constrain their children to match their extent in the cross axis. ' + 'In this case, a horizontal shrinkwrapping viewport was given an ' + 'unlimited amount of vertical space in which to expand.', + ); + } + } + return true; + }()); + return true; + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + if (firstChild == null) { + // Shrinkwrapping viewport only requires the cross axis to be bounded. + assert(_debugCheckHasBoundedCrossAxis()); + switch (axis) { + case Axis.vertical: + size = Size(constraints.maxWidth, constraints.minHeight); + case Axis.horizontal: + size = Size(constraints.minWidth, constraints.maxHeight); + } + offset.applyViewportDimension(0.0); + _maxScrollExtent = 0.0; + _shrinkWrapExtent = 0.0; + _hasVisualOverflow = false; + offset.applyContentDimensions(0.0, 0.0); + return; + } + + final double mainAxisExtent; + final double crossAxisExtent; + // Shrinkwrapping viewport only requires the cross axis to be bounded. + assert(_debugCheckHasBoundedCrossAxis()); + switch (axis) { + case Axis.vertical: + mainAxisExtent = constraints.maxHeight; + crossAxisExtent = constraints.maxWidth; + case Axis.horizontal: + mainAxisExtent = constraints.maxWidth; + crossAxisExtent = constraints.maxHeight; + } + + double correction; + double effectiveExtent; + while (true) { + correction = _attemptLayout(mainAxisExtent, crossAxisExtent, offset.pixels); + if (correction != 0.0) { + offset.correctBy(correction); + } else { + switch (axis) { + case Axis.vertical: + effectiveExtent = constraints.constrainHeight(_shrinkWrapExtent); + case Axis.horizontal: + effectiveExtent = constraints.constrainWidth(_shrinkWrapExtent); + } + final bool didAcceptViewportDimension = offset.applyViewportDimension(effectiveExtent); + final bool didAcceptContentDimension = offset.applyContentDimensions(0.0, math.max(0.0, _maxScrollExtent - effectiveExtent)); + if (didAcceptViewportDimension && didAcceptContentDimension) { + break; + } + } + } + switch (axis) { + case Axis.vertical: + size = constraints.constrainDimensions(crossAxisExtent, effectiveExtent); + case Axis.horizontal: + size = constraints.constrainDimensions(effectiveExtent, crossAxisExtent); + } + } + + double _attemptLayout(double mainAxisExtent, double crossAxisExtent, double correctedOffset) { + // We can't assert mainAxisExtent is finite, because it could be infinite if + // it is within a column or row for example. In such a case, there's not + // even any scrolling to do, although some scroll physics (i.e. + // BouncingScrollPhysics) could still temporarily scroll the content in a + // simulation. + assert(!mainAxisExtent.isNaN); + assert(mainAxisExtent >= 0.0); + assert(crossAxisExtent.isFinite); + assert(crossAxisExtent >= 0.0); + assert(correctedOffset.isFinite); + _maxScrollExtent = 0.0; + _shrinkWrapExtent = 0.0; + // Since the viewport is shrinkwrapped, we know that any negative overscroll + // into the potentially infinite mainAxisExtent will overflow the end of + // the viewport. + _hasVisualOverflow = correctedOffset < 0.0; + switch (cacheExtentStyle) { + case CacheExtentStyle.pixel: + _calculatedCacheExtent = cacheExtent; + case CacheExtentStyle.viewport: + _calculatedCacheExtent = mainAxisExtent * _cacheExtent; + } + + return layoutChildSequence( + child: firstChild, + scrollOffset: math.max(0.0, correctedOffset), + overlap: math.min(0.0, correctedOffset), + layoutOffset: math.max(0.0, -correctedOffset), + remainingPaintExtent: mainAxisExtent + math.min(0.0, correctedOffset), + mainAxisExtent: mainAxisExtent, + crossAxisExtent: crossAxisExtent, + growthDirection: GrowthDirection.forward, + advance: childAfter, + remainingCacheExtent: mainAxisExtent + 2 * _calculatedCacheExtent!, + cacheOrigin: -_calculatedCacheExtent!, + ); + } + + @override + bool get hasVisualOverflow => _hasVisualOverflow; + + @override + void updateOutOfBandData(GrowthDirection growthDirection, SliverGeometry childLayoutGeometry) { + assert(growthDirection == GrowthDirection.forward); + _maxScrollExtent += childLayoutGeometry.scrollExtent; + if (childLayoutGeometry.hasVisualOverflow) { + _hasVisualOverflow = true; + } + _shrinkWrapExtent += childLayoutGeometry.maxPaintExtent; + } + + @override + void updateChildLayoutOffset(RenderSliver child, double layoutOffset, GrowthDirection growthDirection) { + assert(growthDirection == GrowthDirection.forward); + final SliverLogicalParentData childParentData = child.parentData! as SliverLogicalParentData; + childParentData.layoutOffset = layoutOffset; + } + + @override + Offset paintOffsetOf(RenderSliver child) { + final SliverLogicalParentData childParentData = child.parentData! as SliverLogicalParentData; + return computeAbsolutePaintOffset(child, childParentData.layoutOffset!, GrowthDirection.forward); + } + + @override + double scrollOffsetOf(RenderSliver child, double scrollOffsetWithinChild) { + assert(child.parent == this); + assert(child.constraints.growthDirection == GrowthDirection.forward); + double scrollOffsetToChild = 0.0; + RenderSliver? current = firstChild; + while (current != child) { + scrollOffsetToChild += current!.geometry!.scrollExtent; + current = childAfter(current); + } + return scrollOffsetToChild + scrollOffsetWithinChild; + } + + @override + double maxScrollObstructionExtentBefore(RenderSliver child) { + assert(child.parent == this); + assert(child.constraints.growthDirection == GrowthDirection.forward); + double pinnedExtent = 0.0; + RenderSliver? current = firstChild; + while (current != child) { + pinnedExtent += current!.geometry!.maxScrollObstructionExtent; + current = childAfter(current); + } + return pinnedExtent; + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + // Hit test logic relies on this always providing an invertible matrix. + final Offset offset = paintOffsetOf(child as RenderSliver); + transform.translate(offset.dx, offset.dy); + } + + @override + double computeChildMainAxisPosition(RenderSliver child, double parentMainAxisPosition) { + assert(hasSize); + final SliverLogicalParentData childParentData = child.parentData! as SliverLogicalParentData; + switch (applyGrowthDirectionToAxisDirection(child.constraints.axisDirection, child.constraints.growthDirection)) { + case AxisDirection.down: + case AxisDirection.right: + return parentMainAxisPosition - childParentData.layoutOffset!; + case AxisDirection.up: + return (size.height - parentMainAxisPosition) - childParentData.layoutOffset!; + case AxisDirection.left: + return (size.width - parentMainAxisPosition) - childParentData.layoutOffset!; + } + } + + @override + int get indexOfFirstChild => 0; + + @override + String labelForChild(int index) => 'child $index'; + + @override + Iterable<RenderSliver> get childrenInPaintOrder { + final List<RenderSliver> children = <RenderSliver>[]; + RenderSliver? child = lastChild; + while (child != null) { + children.add(child); + child = childBefore(child); + } + return children; + } + + @override + Iterable<RenderSliver> get childrenInHitTestOrder { + final List<RenderSliver> children = <RenderSliver>[]; + RenderSliver? child = firstChild; + while (child != null) { + children.add(child); + child = childAfter(child); + } + return children; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/viewport_offset.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/viewport_offset.dart new file mode 100644 index 0000000000000000000000000000000000000000..a58f8720d9f6a62d4d0ee5467c80e23a143ddde8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/viewport_offset.dart @@ -0,0 +1,330 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; + +/// The direction of a scroll, relative to the positive scroll offset axis given +/// by an [AxisDirection] and a [GrowthDirection]. +/// +/// This is similar to [GrowthDirection], but contrasts in that it has a third +/// value, [idle], for the case where no scroll is occurring. +/// +/// This is used by [RenderSliverFloatingPersistentHeader] to only expand when +/// the user is scrolling in the same direction as the detected scroll offset +/// change. +/// +/// {@template flutter.rendering.ScrollDirection.sample} +/// {@tool dartpad} +/// This sample shows a [CustomScrollView], with [Radio] buttons in the +/// [AppBar.bottom] that change the [AxisDirection] to illustrate different +/// configurations. With a [NotificationListener] to listen to +/// [UserScrollNotification]s, which occur when the [ScrollDirection] changes +/// or stops. +/// +/// ** See code in examples/api/lib/rendering/scroll_direction/scroll_direction.0.dart ** +/// {@end-tool} +/// {@endtemplate} +/// +/// See also: +/// +/// * [AxisDirection], which is a directional version of this enum (with values +/// like left and right, rather than just horizontal). +/// * [GrowthDirection], the direction in which slivers and their content are +/// ordered, relative to the scroll offset axis as specified by +/// [AxisDirection]. +/// * [UserScrollNotification], which will notify listeners when the +/// [ScrollDirection] changes. +enum ScrollDirection { + /// No scrolling is underway. + idle, + + /// Scrolling is happening in the negative scroll offset direction. + /// + /// For example, for the [GrowthDirection.forward] part of a vertical + /// [AxisDirection.down] list, which is the default directional configuration + /// of all scroll views, this means the content is going down, exposing + /// earlier content as it approaches the zero position. + /// + /// An anecdote for this most common case is 'forward is toward' the zero + /// position. + forward, + + /// Scrolling is happening in the positive scroll offset direction. + /// + /// For example, for the [GrowthDirection.forward] part of a vertical + /// [AxisDirection.down] list, which is the default directional configuration + /// of all scroll views, this means the content is moving up, exposing + /// lower content. + /// + /// An anecdote for this most common case is reversing, or backing away, from + /// the zero position. + reverse, +} + +/// Returns the opposite of the given [ScrollDirection]. +/// +/// Specifically, returns [ScrollDirection.reverse] for [ScrollDirection.forward] +/// (and vice versa) and returns [ScrollDirection.idle] for +/// [ScrollDirection.idle]. +ScrollDirection flipScrollDirection(ScrollDirection direction) { + switch (direction) { + case ScrollDirection.idle: + return ScrollDirection.idle; + case ScrollDirection.forward: + return ScrollDirection.reverse; + case ScrollDirection.reverse: + return ScrollDirection.forward; + } +} + +/// Which part of the content inside the viewport should be visible. +/// +/// The [pixels] value determines the scroll offset that the viewport uses to +/// select which part of its content to display. As the user scrolls the +/// viewport, this value changes, which changes the content that is displayed. +/// +/// This object is a [Listenable] that notifies its listeners when [pixels] +/// changes. +/// +/// See also: +/// +/// * [ScrollPosition], which is a commonly used concrete subclass. +/// * [RenderViewportBase], which is a render object that uses viewport +/// offsets. +abstract class ViewportOffset extends ChangeNotifier { + /// Default constructor. + /// + /// Allows subclasses to construct this object directly. + ViewportOffset() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + /// Creates a viewport offset with the given [pixels] value. + /// + /// The [pixels] value does not change unless the viewport issues a + /// correction. + factory ViewportOffset.fixed(double value) = _FixedViewportOffset; + + /// Creates a viewport offset with a [pixels] value of 0.0. + /// + /// The [pixels] value does not change unless the viewport issues a + /// correction. + factory ViewportOffset.zero() = _FixedViewportOffset.zero; + + /// The number of pixels to offset the children in the opposite of the axis direction. + /// + /// For example, if the axis direction is down, then the pixel value + /// represents the number of logical pixels to move the children _up_ the + /// screen. Similarly, if the axis direction is left, then the pixels value + /// represents the number of logical pixels to move the children to _right_. + /// + /// This object notifies its listeners when this value changes (except when + /// the value changes due to [correctBy]). + double get pixels; + + /// Whether the [pixels] property is available. + bool get hasPixels; + + /// Called when the viewport's extents are established. + /// + /// The argument is the dimension of the [RenderViewport] in the main axis + /// (e.g. the height, for a vertical viewport). + /// + /// This may be called redundantly, with the same value, each frame. This is + /// called during layout for the [RenderViewport]. If the viewport is + /// configured to shrink-wrap its contents, it may be called several times, + /// since the layout is repeated each time the scroll offset is corrected. + /// + /// If this is called, it is called before [applyContentDimensions]. If this + /// is called, [applyContentDimensions] will be called soon afterwards in the + /// same layout phase. If the viewport is not configured to shrink-wrap its + /// contents, then this will only be called when the viewport recomputes its + /// size (i.e. when its parent lays out), and not during normal scrolling. + /// + /// If applying the viewport dimensions changes the scroll offset, return + /// false. Otherwise, return true. If you return false, the [RenderViewport] + /// will be laid out again with the new scroll offset. This is expensive. (The + /// return value is answering the question "did you accept these viewport + /// dimensions unconditionally?"; if the new dimensions change the + /// [ViewportOffset]'s actual [pixels] value, then the viewport will need to + /// be laid out again.) + bool applyViewportDimension(double viewportDimension); + + /// Called when the viewport's content extents are established. + /// + /// The arguments are the minimum and maximum scroll extents respectively. The + /// minimum will be equal to or less than the maximum. In the case of slivers, + /// the minimum will be equal to or less than zero, the maximum will be equal + /// to or greater than zero. + /// + /// The maximum scroll extent has the viewport dimension subtracted from it. + /// For instance, if there is 100.0 pixels of scrollable content, and the + /// viewport is 80.0 pixels high, then the minimum scroll extent will + /// typically be 0.0 and the maximum scroll extent will typically be 20.0, + /// because there's only 20.0 pixels of actual scroll slack. + /// + /// If applying the content dimensions changes the scroll offset, return + /// false. Otherwise, return true. If you return false, the [RenderViewport] + /// will be laid out again with the new scroll offset. This is expensive. (The + /// return value is answering the question "did you accept these content + /// dimensions unconditionally?"; if the new dimensions change the + /// [ViewportOffset]'s actual [pixels] value, then the viewport will need to + /// be laid out again.) + /// + /// This is called at least once each time the [RenderViewport] is laid out, + /// even if the values have not changed. It may be called many times if the + /// scroll offset is corrected (if this returns false). This is always called + /// after [applyViewportDimension], if that method is called. + bool applyContentDimensions(double minScrollExtent, double maxScrollExtent); + + /// Apply a layout-time correction to the scroll offset. + /// + /// This method should change the [pixels] value by `correction`, but without + /// calling [notifyListeners]. It is called during layout by the + /// [RenderViewport], before [applyContentDimensions]. After this method is + /// called, the layout will be recomputed and that may result in this method + /// being called again, though this should be very rare. + /// + /// See also: + /// + /// * [jumpTo], for also changing the scroll position when not in layout. + /// [jumpTo] applies the change immediately and notifies its listeners. + void correctBy(double correction); + + /// Jumps [pixels] from its current value to the given value, + /// without animation, and without checking if the new value is in range. + /// + /// See also: + /// + /// * [correctBy], for changing the current offset in the middle of layout + /// and that defers the notification of its listeners until after layout. + void jumpTo(double pixels); + + /// Animates [pixels] from its current value to the given value. + /// + /// The returned [Future] will complete when the animation ends, whether it + /// completed successfully or whether it was interrupted prematurely. + /// + /// The duration must not be zero. To jump to a particular value without an + /// animation, use [jumpTo]. + Future<void> animateTo( + double to, { + required Duration duration, + required Curve curve, + }); + + /// Calls [jumpTo] if duration is null or [Duration.zero], otherwise + /// [animateTo] is called. + /// + /// If [animateTo] is called then [curve] defaults to [Curves.ease]. The + /// [clamp] parameter is ignored by this stub implementation but subclasses + /// like [ScrollPosition] handle it by adjusting [to] to prevent over or + /// underscroll. + Future<void> moveTo( + double to, { + Duration? duration, + Curve? curve, + bool? clamp, + }) { + if (duration == null || duration == Duration.zero) { + jumpTo(to); + return Future<void>.value(); + } else { + return animateTo(to, duration: duration, curve: curve ?? Curves.ease); + } + } + + /// The direction in which the user is trying to change [pixels], relative to + /// the viewport's [RenderViewportBase.axisDirection]. + /// + /// If the _user_ is not scrolling, this will return [ScrollDirection.idle] + /// even if there is (for example) a [ScrollActivity] currently animating the + /// position. + /// + /// This is exposed in [SliverConstraints.userScrollDirection], which is used + /// by some slivers to determine how to react to a change in scroll offset. + /// For example, [RenderSliverFloatingPersistentHeader] will only expand a + /// floating app bar when the [userScrollDirection] is in the positive scroll + /// offset direction. + /// + /// {@macro flutter.rendering.ScrollDirection.sample} + ScrollDirection get userScrollDirection; + + /// Whether a viewport is allowed to change [pixels] implicitly to respond to + /// a call to [RenderObject.showOnScreen]. + /// + /// [RenderObject.showOnScreen] is, for example, used to bring a text field + /// fully on screen after it has received focus. This property controls + /// whether the viewport associated with this offset is allowed to change the + /// offset's [pixels] value to fulfill such a request. + bool get allowImplicitScrolling; + + @override + String toString() { + final List<String> description = <String>[]; + debugFillDescription(description); + return '${describeIdentity(this)}(${description.join(", ")})'; + } + + /// Add additional information to the given description for use by [toString]. + /// + /// This method makes it easier for subclasses to coordinate to provide a + /// high-quality [toString] implementation. The [toString] implementation on + /// the [State] base class calls [debugFillDescription] to collect useful + /// information from subclasses to incorporate into its return value. + /// + /// Implementations of this method should start with a call to the inherited + /// method, as in `super.debugFillDescription(description)`. + @mustCallSuper + void debugFillDescription(List<String> description) { + if (hasPixels) { + description.add('offset: ${pixels.toStringAsFixed(1)}'); + } + } +} + +class _FixedViewportOffset extends ViewportOffset { + _FixedViewportOffset(this._pixels); + _FixedViewportOffset.zero() : _pixels = 0.0; + + double _pixels; + + @override + double get pixels => _pixels; + + @override + bool get hasPixels => true; + + @override + bool applyViewportDimension(double viewportDimension) => true; + + @override + bool applyContentDimensions(double minScrollExtent, double maxScrollExtent) => true; + + @override + void correctBy(double correction) { + _pixels += correction; + } + + @override + void jumpTo(double pixels) { + // Do nothing, viewport is fixed. + } + + @override + Future<void> animateTo( + double to, { + required Duration duration, + required Curve curve, + }) async { } + + @override + ScrollDirection get userScrollDirection => ScrollDirection.idle; + + @override + bool get allowImplicitScrolling => false; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/wrap.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/wrap.dart new file mode 100644 index 0000000000000000000000000000000000000000..b6589150e8f96d4d1fd2e76a16ca4b71577e9943 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/rendering/wrap.dart @@ -0,0 +1,777 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'box.dart'; +import 'layer.dart'; +import 'layout_helper.dart'; +import 'object.dart'; + +/// How [Wrap] should align objects. +/// +/// Used both to align children within a run in the main axis as well as to +/// align the runs themselves in the cross axis. +enum WrapAlignment { + /// Place the objects as close to the start of the axis as possible. + /// + /// If this value is used in a horizontal direction, a [TextDirection] must be + /// available to determine if the start is the left or the right. + /// + /// If this value is used in a vertical direction, a [VerticalDirection] must be + /// available to determine if the start is the top or the bottom. + start, + + /// Place the objects as close to the end of the axis as possible. + /// + /// If this value is used in a horizontal direction, a [TextDirection] must be + /// available to determine if the end is the left or the right. + /// + /// If this value is used in a vertical direction, a [VerticalDirection] must be + /// available to determine if the end is the top or the bottom. + end, + + /// Place the objects as close to the middle of the axis as possible. + center, + + /// Place the free space evenly between the objects. + spaceBetween, + + /// Place the free space evenly between the objects as well as half of that + /// space before and after the first and last objects. + spaceAround, + + /// Place the free space evenly between the objects as well as before and + /// after the first and last objects. + spaceEvenly, +} + +/// Who [Wrap] should align children within a run in the cross axis. +enum WrapCrossAlignment { + /// Place the children as close to the start of the run in the cross axis as + /// possible. + /// + /// If this value is used in a horizontal direction, a [TextDirection] must be + /// available to determine if the start is the left or the right. + /// + /// If this value is used in a vertical direction, a [VerticalDirection] must be + /// available to determine if the start is the top or the bottom. + start, + + /// Place the children as close to the end of the run in the cross axis as + /// possible. + /// + /// If this value is used in a horizontal direction, a [TextDirection] must be + /// available to determine if the end is the left or the right. + /// + /// If this value is used in a vertical direction, a [VerticalDirection] must be + /// available to determine if the end is the top or the bottom. + end, + + /// Place the children as close to the middle of the run in the cross axis as + /// possible. + center, + + // TODO(ianh): baseline. +} + +class _RunMetrics { + _RunMetrics(this.mainAxisExtent, this.crossAxisExtent, this.childCount); + + final double mainAxisExtent; + final double crossAxisExtent; + final int childCount; +} + +/// Parent data for use with [RenderWrap]. +class WrapParentData extends ContainerBoxParentData<RenderBox> { + int _runIndex = 0; +} + +/// Displays its children in multiple horizontal or vertical runs. +/// +/// A [RenderWrap] lays out each child and attempts to place the child adjacent +/// to the previous child in the main axis, given by [direction], leaving +/// [spacing] space in between. If there is not enough space to fit the child, +/// [RenderWrap] creates a new _run_ adjacent to the existing children in the +/// cross axis. +/// +/// After all the children have been allocated to runs, the children within the +/// runs are positioned according to the [alignment] in the main axis and +/// according to the [crossAxisAlignment] in the cross axis. +/// +/// The runs themselves are then positioned in the cross axis according to the +/// [runSpacing] and [runAlignment]. +class RenderWrap extends RenderBox + with ContainerRenderObjectMixin<RenderBox, WrapParentData>, + RenderBoxContainerDefaultsMixin<RenderBox, WrapParentData> { + /// Creates a wrap render object. + /// + /// By default, the wrap layout is horizontal and both the children and the + /// runs are aligned to the start. + RenderWrap({ + List<RenderBox>? children, + Axis direction = Axis.horizontal, + WrapAlignment alignment = WrapAlignment.start, + double spacing = 0.0, + WrapAlignment runAlignment = WrapAlignment.start, + double runSpacing = 0.0, + WrapCrossAlignment crossAxisAlignment = WrapCrossAlignment.start, + TextDirection? textDirection, + VerticalDirection verticalDirection = VerticalDirection.down, + Clip clipBehavior = Clip.none, + }) : _direction = direction, + _alignment = alignment, + _spacing = spacing, + _runAlignment = runAlignment, + _runSpacing = runSpacing, + _crossAxisAlignment = crossAxisAlignment, + _textDirection = textDirection, + _verticalDirection = verticalDirection, + _clipBehavior = clipBehavior { + addAll(children); + } + + /// The direction to use as the main axis. + /// + /// For example, if [direction] is [Axis.horizontal], the default, the + /// children are placed adjacent to one another in a horizontal run until the + /// available horizontal space is consumed, at which point a subsequent + /// children are placed in a new run vertically adjacent to the previous run. + Axis get direction => _direction; + Axis _direction; + set direction (Axis value) { + if (_direction == value) { + return; + } + _direction = value; + markNeedsLayout(); + } + + /// How the children within a run should be placed in the main axis. + /// + /// For example, if [alignment] is [WrapAlignment.center], the children in + /// each run are grouped together in the center of their run in the main axis. + /// + /// Defaults to [WrapAlignment.start]. + /// + /// See also: + /// + /// * [runAlignment], which controls how the runs are placed relative to each + /// other in the cross axis. + /// * [crossAxisAlignment], which controls how the children within each run + /// are placed relative to each other in the cross axis. + WrapAlignment get alignment => _alignment; + WrapAlignment _alignment; + set alignment (WrapAlignment value) { + if (_alignment == value) { + return; + } + _alignment = value; + markNeedsLayout(); + } + + /// How much space to place between children in a run in the main axis. + /// + /// For example, if [spacing] is 10.0, the children will be spaced at least + /// 10.0 logical pixels apart in the main axis. + /// + /// If there is additional free space in a run (e.g., because the wrap has a + /// minimum size that is not filled or because some runs are longer than + /// others), the additional free space will be allocated according to the + /// [alignment]. + /// + /// Defaults to 0.0. + double get spacing => _spacing; + double _spacing; + set spacing (double value) { + if (_spacing == value) { + return; + } + _spacing = value; + markNeedsLayout(); + } + + /// How the runs themselves should be placed in the cross axis. + /// + /// For example, if [runAlignment] is [WrapAlignment.center], the runs are + /// grouped together in the center of the overall [RenderWrap] in the cross + /// axis. + /// + /// Defaults to [WrapAlignment.start]. + /// + /// See also: + /// + /// * [alignment], which controls how the children within each run are placed + /// relative to each other in the main axis. + /// * [crossAxisAlignment], which controls how the children within each run + /// are placed relative to each other in the cross axis. + WrapAlignment get runAlignment => _runAlignment; + WrapAlignment _runAlignment; + set runAlignment (WrapAlignment value) { + if (_runAlignment == value) { + return; + } + _runAlignment = value; + markNeedsLayout(); + } + + /// How much space to place between the runs themselves in the cross axis. + /// + /// For example, if [runSpacing] is 10.0, the runs will be spaced at least + /// 10.0 logical pixels apart in the cross axis. + /// + /// If there is additional free space in the overall [RenderWrap] (e.g., + /// because the wrap has a minimum size that is not filled), the additional + /// free space will be allocated according to the [runAlignment]. + /// + /// Defaults to 0.0. + double get runSpacing => _runSpacing; + double _runSpacing; + set runSpacing (double value) { + if (_runSpacing == value) { + return; + } + _runSpacing = value; + markNeedsLayout(); + } + + /// How the children within a run should be aligned relative to each other in + /// the cross axis. + /// + /// For example, if this is set to [WrapCrossAlignment.end], and the + /// [direction] is [Axis.horizontal], then the children within each + /// run will have their bottom edges aligned to the bottom edge of the run. + /// + /// Defaults to [WrapCrossAlignment.start]. + /// + /// See also: + /// + /// * [alignment], which controls how the children within each run are placed + /// relative to each other in the main axis. + /// * [runAlignment], which controls how the runs are placed relative to each + /// other in the cross axis. + WrapCrossAlignment get crossAxisAlignment => _crossAxisAlignment; + WrapCrossAlignment _crossAxisAlignment; + set crossAxisAlignment (WrapCrossAlignment value) { + if (_crossAxisAlignment == value) { + return; + } + _crossAxisAlignment = value; + markNeedsLayout(); + } + + /// Determines the order to lay children out horizontally and how to interpret + /// `start` and `end` in the horizontal direction. + /// + /// If the [direction] is [Axis.horizontal], this controls the order in which + /// children are positioned (left-to-right or right-to-left), and the meaning + /// of the [alignment] property's [WrapAlignment.start] and + /// [WrapAlignment.end] values. + /// + /// If the [direction] is [Axis.horizontal], and either the + /// [alignment] is either [WrapAlignment.start] or [WrapAlignment.end], or + /// there's more than one child, then the [textDirection] must not be null. + /// + /// If the [direction] is [Axis.vertical], this controls the order in + /// which runs are positioned, the meaning of the [runAlignment] property's + /// [WrapAlignment.start] and [WrapAlignment.end] values, as well as the + /// [crossAxisAlignment] property's [WrapCrossAlignment.start] and + /// [WrapCrossAlignment.end] values. + /// + /// If the [direction] is [Axis.vertical], and either the + /// [runAlignment] is either [WrapAlignment.start] or [WrapAlignment.end], the + /// [crossAxisAlignment] is either [WrapCrossAlignment.start] or + /// [WrapCrossAlignment.end], or there's more than one child, then the + /// [textDirection] must not be null. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + if (_textDirection != value) { + _textDirection = value; + markNeedsLayout(); + } + } + + /// Determines the order to lay children out vertically and how to interpret + /// `start` and `end` in the vertical direction. + /// + /// If the [direction] is [Axis.vertical], this controls which order children + /// are painted in (down or up), the meaning of the [alignment] property's + /// [WrapAlignment.start] and [WrapAlignment.end] values. + /// + /// If the [direction] is [Axis.vertical], and either the [alignment] + /// is either [WrapAlignment.start] or [WrapAlignment.end], or there's + /// more than one child, then the [verticalDirection] must not be null. + /// + /// If the [direction] is [Axis.horizontal], this controls the order in which + /// runs are positioned, the meaning of the [runAlignment] property's + /// [WrapAlignment.start] and [WrapAlignment.end] values, as well as the + /// [crossAxisAlignment] property's [WrapCrossAlignment.start] and + /// [WrapCrossAlignment.end] values. + /// + /// If the [direction] is [Axis.horizontal], and either the + /// [runAlignment] is either [WrapAlignment.start] or [WrapAlignment.end], the + /// [crossAxisAlignment] is either [WrapCrossAlignment.start] or + /// [WrapCrossAlignment.end], or there's more than one child, then the + /// [verticalDirection] must not be null. + VerticalDirection get verticalDirection => _verticalDirection; + VerticalDirection _verticalDirection; + set verticalDirection(VerticalDirection value) { + if (_verticalDirection != value) { + _verticalDirection = value; + markNeedsLayout(); + } + } + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.none; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + bool get _debugHasNecessaryDirections { + if (firstChild != null && lastChild != firstChild) { + // i.e. there's more than one child + switch (direction) { + case Axis.horizontal: + assert(textDirection != null, 'Horizontal $runtimeType with multiple children has a null textDirection, so the layout order is undefined.'); + case Axis.vertical: + break; + } + } + if (alignment == WrapAlignment.start || alignment == WrapAlignment.end) { + switch (direction) { + case Axis.horizontal: + assert(textDirection != null, 'Horizontal $runtimeType with alignment $alignment has a null textDirection, so the alignment cannot be resolved.'); + case Axis.vertical: + break; + } + } + if (runAlignment == WrapAlignment.start || runAlignment == WrapAlignment.end) { + switch (direction) { + case Axis.horizontal: + break; + case Axis.vertical: + assert(textDirection != null, 'Vertical $runtimeType with runAlignment $runAlignment has a null textDirection, so the alignment cannot be resolved.'); + } + } + if (crossAxisAlignment == WrapCrossAlignment.start || crossAxisAlignment == WrapCrossAlignment.end) { + switch (direction) { + case Axis.horizontal: + break; + case Axis.vertical: + assert(textDirection != null, 'Vertical $runtimeType with crossAxisAlignment $crossAxisAlignment has a null textDirection, so the alignment cannot be resolved.'); + } + } + return true; + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! WrapParentData) { + child.parentData = WrapParentData(); + } + } + + @override + double computeMinIntrinsicWidth(double height) { + switch (direction) { + case Axis.horizontal: + double width = 0.0; + RenderBox? child = firstChild; + while (child != null) { + width = math.max(width, child.getMinIntrinsicWidth(double.infinity)); + child = childAfter(child); + } + return width; + case Axis.vertical: + return computeDryLayout(BoxConstraints(maxHeight: height)).width; + } + } + + @override + double computeMaxIntrinsicWidth(double height) { + switch (direction) { + case Axis.horizontal: + double width = 0.0; + RenderBox? child = firstChild; + while (child != null) { + width += child.getMaxIntrinsicWidth(double.infinity); + child = childAfter(child); + } + return width; + case Axis.vertical: + return computeDryLayout(BoxConstraints(maxHeight: height)).width; + } + } + + @override + double computeMinIntrinsicHeight(double width) { + switch (direction) { + case Axis.horizontal: + return computeDryLayout(BoxConstraints(maxWidth: width)).height; + case Axis.vertical: + double height = 0.0; + RenderBox? child = firstChild; + while (child != null) { + height = math.max(height, child.getMinIntrinsicHeight(double.infinity)); + child = childAfter(child); + } + return height; + } + } + + @override + double computeMaxIntrinsicHeight(double width) { + switch (direction) { + case Axis.horizontal: + return computeDryLayout(BoxConstraints(maxWidth: width)).height; + case Axis.vertical: + double height = 0.0; + RenderBox? child = firstChild; + while (child != null) { + height += child.getMaxIntrinsicHeight(double.infinity); + child = childAfter(child); + } + return height; + } + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + return defaultComputeDistanceToHighestActualBaseline(baseline); + } + + double _getMainAxisExtent(Size childSize) { + switch (direction) { + case Axis.horizontal: + return childSize.width; + case Axis.vertical: + return childSize.height; + } + } + + double _getCrossAxisExtent(Size childSize) { + switch (direction) { + case Axis.horizontal: + return childSize.height; + case Axis.vertical: + return childSize.width; + } + } + + Offset _getOffset(double mainAxisOffset, double crossAxisOffset) { + switch (direction) { + case Axis.horizontal: + return Offset(mainAxisOffset, crossAxisOffset); + case Axis.vertical: + return Offset(crossAxisOffset, mainAxisOffset); + } + } + + double _getChildCrossAxisOffset(bool flipCrossAxis, double runCrossAxisExtent, double childCrossAxisExtent) { + final double freeSpace = runCrossAxisExtent - childCrossAxisExtent; + switch (crossAxisAlignment) { + case WrapCrossAlignment.start: + return flipCrossAxis ? freeSpace : 0.0; + case WrapCrossAlignment.end: + return flipCrossAxis ? 0.0 : freeSpace; + case WrapCrossAlignment.center: + return freeSpace / 2.0; + } + } + + bool _hasVisualOverflow = false; + + @override + @protected + Size computeDryLayout(covariant BoxConstraints constraints) { + return _computeDryLayout(constraints); + } + + Size _computeDryLayout(BoxConstraints constraints, [ChildLayouter layoutChild = ChildLayoutHelper.dryLayoutChild]) { + final BoxConstraints childConstraints; + double mainAxisLimit = 0.0; + switch (direction) { + case Axis.horizontal: + childConstraints = BoxConstraints(maxWidth: constraints.maxWidth); + mainAxisLimit = constraints.maxWidth; + case Axis.vertical: + childConstraints = BoxConstraints(maxHeight: constraints.maxHeight); + mainAxisLimit = constraints.maxHeight; + } + + double mainAxisExtent = 0.0; + double crossAxisExtent = 0.0; + double runMainAxisExtent = 0.0; + double runCrossAxisExtent = 0.0; + int childCount = 0; + RenderBox? child = firstChild; + while (child != null) { + final Size childSize = layoutChild(child, childConstraints); + final double childMainAxisExtent = _getMainAxisExtent(childSize); + final double childCrossAxisExtent = _getCrossAxisExtent(childSize); + // There must be at least one child before we move on to the next run. + if (childCount > 0 && runMainAxisExtent + childMainAxisExtent + spacing > mainAxisLimit) { + mainAxisExtent = math.max(mainAxisExtent, runMainAxisExtent); + crossAxisExtent += runCrossAxisExtent + runSpacing; + runMainAxisExtent = 0.0; + runCrossAxisExtent = 0.0; + childCount = 0; + } + runMainAxisExtent += childMainAxisExtent; + runCrossAxisExtent = math.max(runCrossAxisExtent, childCrossAxisExtent); + if (childCount > 0) { + runMainAxisExtent += spacing; + } + childCount += 1; + child = childAfter(child); + } + crossAxisExtent += runCrossAxisExtent; + mainAxisExtent = math.max(mainAxisExtent, runMainAxisExtent); + + switch (direction) { + case Axis.horizontal: + return constraints.constrain(Size(mainAxisExtent, crossAxisExtent)); + case Axis.vertical: + return constraints.constrain(Size(crossAxisExtent, mainAxisExtent)); + } + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + assert(_debugHasNecessaryDirections); + _hasVisualOverflow = false; + RenderBox? child = firstChild; + if (child == null) { + size = constraints.smallest; + return; + } + final BoxConstraints childConstraints; + double mainAxisLimit = 0.0; + bool flipMainAxis = false; + bool flipCrossAxis = false; + switch (direction) { + case Axis.horizontal: + childConstraints = BoxConstraints(maxWidth: constraints.maxWidth); + mainAxisLimit = constraints.maxWidth; + if (textDirection == TextDirection.rtl) { + flipMainAxis = true; + } + if (verticalDirection == VerticalDirection.up) { + flipCrossAxis = true; + } + case Axis.vertical: + childConstraints = BoxConstraints(maxHeight: constraints.maxHeight); + mainAxisLimit = constraints.maxHeight; + if (verticalDirection == VerticalDirection.up) { + flipMainAxis = true; + } + if (textDirection == TextDirection.rtl) { + flipCrossAxis = true; + } + } + final double spacing = this.spacing; + final double runSpacing = this.runSpacing; + final List<_RunMetrics> runMetrics = <_RunMetrics>[]; + double mainAxisExtent = 0.0; + double crossAxisExtent = 0.0; + double runMainAxisExtent = 0.0; + double runCrossAxisExtent = 0.0; + int childCount = 0; + while (child != null) { + child.layout(childConstraints, parentUsesSize: true); + final double childMainAxisExtent = _getMainAxisExtent(child.size); + final double childCrossAxisExtent = _getCrossAxisExtent(child.size); + if (childCount > 0 && runMainAxisExtent + spacing + childMainAxisExtent > mainAxisLimit) { + mainAxisExtent = math.max(mainAxisExtent, runMainAxisExtent); + crossAxisExtent += runCrossAxisExtent; + if (runMetrics.isNotEmpty) { + crossAxisExtent += runSpacing; + } + runMetrics.add(_RunMetrics(runMainAxisExtent, runCrossAxisExtent, childCount)); + runMainAxisExtent = 0.0; + runCrossAxisExtent = 0.0; + childCount = 0; + } + runMainAxisExtent += childMainAxisExtent; + if (childCount > 0) { + runMainAxisExtent += spacing; + } + runCrossAxisExtent = math.max(runCrossAxisExtent, childCrossAxisExtent); + childCount += 1; + final WrapParentData childParentData = child.parentData! as WrapParentData; + childParentData._runIndex = runMetrics.length; + child = childParentData.nextSibling; + } + if (childCount > 0) { + mainAxisExtent = math.max(mainAxisExtent, runMainAxisExtent); + crossAxisExtent += runCrossAxisExtent; + if (runMetrics.isNotEmpty) { + crossAxisExtent += runSpacing; + } + runMetrics.add(_RunMetrics(runMainAxisExtent, runCrossAxisExtent, childCount)); + } + + final int runCount = runMetrics.length; + assert(runCount > 0); + + double containerMainAxisExtent = 0.0; + double containerCrossAxisExtent = 0.0; + + switch (direction) { + case Axis.horizontal: + size = constraints.constrain(Size(mainAxisExtent, crossAxisExtent)); + containerMainAxisExtent = size.width; + containerCrossAxisExtent = size.height; + case Axis.vertical: + size = constraints.constrain(Size(crossAxisExtent, mainAxisExtent)); + containerMainAxisExtent = size.height; + containerCrossAxisExtent = size.width; + } + + _hasVisualOverflow = containerMainAxisExtent < mainAxisExtent || containerCrossAxisExtent < crossAxisExtent; + + final double crossAxisFreeSpace = math.max(0.0, containerCrossAxisExtent - crossAxisExtent); + double runLeadingSpace = 0.0; + double runBetweenSpace = 0.0; + switch (runAlignment) { + case WrapAlignment.start: + break; + case WrapAlignment.end: + runLeadingSpace = crossAxisFreeSpace; + case WrapAlignment.center: + runLeadingSpace = crossAxisFreeSpace / 2.0; + case WrapAlignment.spaceBetween: + runBetweenSpace = runCount > 1 ? crossAxisFreeSpace / (runCount - 1) : 0.0; + case WrapAlignment.spaceAround: + runBetweenSpace = crossAxisFreeSpace / runCount; + runLeadingSpace = runBetweenSpace / 2.0; + case WrapAlignment.spaceEvenly: + runBetweenSpace = crossAxisFreeSpace / (runCount + 1); + runLeadingSpace = runBetweenSpace; + } + + runBetweenSpace += runSpacing; + double crossAxisOffset = flipCrossAxis ? containerCrossAxisExtent - runLeadingSpace : runLeadingSpace; + + child = firstChild; + for (int i = 0; i < runCount; ++i) { + final _RunMetrics metrics = runMetrics[i]; + final double runMainAxisExtent = metrics.mainAxisExtent; + final double runCrossAxisExtent = metrics.crossAxisExtent; + final int childCount = metrics.childCount; + + final double mainAxisFreeSpace = math.max(0.0, containerMainAxisExtent - runMainAxisExtent); + double childLeadingSpace = 0.0; + double childBetweenSpace = 0.0; + + switch (alignment) { + case WrapAlignment.start: + break; + case WrapAlignment.end: + childLeadingSpace = mainAxisFreeSpace; + case WrapAlignment.center: + childLeadingSpace = mainAxisFreeSpace / 2.0; + case WrapAlignment.spaceBetween: + childBetweenSpace = childCount > 1 ? mainAxisFreeSpace / (childCount - 1) : 0.0; + case WrapAlignment.spaceAround: + childBetweenSpace = mainAxisFreeSpace / childCount; + childLeadingSpace = childBetweenSpace / 2.0; + case WrapAlignment.spaceEvenly: + childBetweenSpace = mainAxisFreeSpace / (childCount + 1); + childLeadingSpace = childBetweenSpace; + } + + childBetweenSpace += spacing; + double childMainPosition = flipMainAxis ? containerMainAxisExtent - childLeadingSpace : childLeadingSpace; + + if (flipCrossAxis) { + crossAxisOffset -= runCrossAxisExtent; + } + + while (child != null) { + final WrapParentData childParentData = child.parentData! as WrapParentData; + if (childParentData._runIndex != i) { + break; + } + final double childMainAxisExtent = _getMainAxisExtent(child.size); + final double childCrossAxisExtent = _getCrossAxisExtent(child.size); + final double childCrossAxisOffset = _getChildCrossAxisOffset(flipCrossAxis, runCrossAxisExtent, childCrossAxisExtent); + if (flipMainAxis) { + childMainPosition -= childMainAxisExtent; + } + childParentData.offset = _getOffset(childMainPosition, crossAxisOffset + childCrossAxisOffset); + if (flipMainAxis) { + childMainPosition -= childBetweenSpace; + } else { + childMainPosition += childMainAxisExtent + childBetweenSpace; + } + child = childParentData.nextSibling; + } + + if (flipCrossAxis) { + crossAxisOffset -= runBetweenSpace; + } else { + crossAxisOffset += runCrossAxisExtent + runBetweenSpace; + } + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + return defaultHitTestChildren(result, position: position); + } + + @override + void paint(PaintingContext context, Offset offset) { + // TODO(ianh): move the debug flex overflow paint logic somewhere common so + // it can be reused here + if (_hasVisualOverflow && clipBehavior != Clip.none) { + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + defaultPaint, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + } else { + _clipRectLayer.layer = null; + defaultPaint(context, offset); + } + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void dispose() { + _clipRectLayer.layer = null; + super.dispose(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<Axis>('direction', direction)); + properties.add(EnumProperty<WrapAlignment>('alignment', alignment)); + properties.add(DoubleProperty('spacing', spacing)); + properties.add(EnumProperty<WrapAlignment>('runAlignment', runAlignment)); + properties.add(DoubleProperty('runSpacing', runSpacing)); + properties.add(DoubleProperty('crossAxisAlignment', runSpacing)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(EnumProperty<VerticalDirection>('verticalDirection', verticalDirection, defaultValue: VerticalDirection.down)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/binding.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/binding.dart new file mode 100644 index 0000000000000000000000000000000000000000..6bad5b1c6faff35f227d7752f967e1b02a03502a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/binding.dart @@ -0,0 +1,1422 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:collection'; +import 'dart:developer' show Flow, Timeline, TimelineTask; +import 'dart:ui' show AppLifecycleState, DartPerformanceMode, FramePhase, FrameTiming, PlatformDispatcher, TimingsCallback; + +import 'package:collection/collection.dart' show HeapPriorityQueue, PriorityQueue; +import 'package:flutter/foundation.dart'; + +import 'debug.dart'; +import 'priority.dart'; +import 'service_extensions.dart'; + +export 'dart:ui' show AppLifecycleState, FrameTiming, TimingsCallback; + +export 'priority.dart' show Priority; + +/// Slows down animations by this factor to help in development. +double get timeDilation => _timeDilation; +double _timeDilation = 1.0; +/// If the [SchedulerBinding] has been initialized, setting the time dilation +/// automatically calls [SchedulerBinding.resetEpoch] to ensure that time stamps +/// seen by consumers of the scheduler binding are always increasing. +/// +/// It is safe to set this before initializing the binding. +set timeDilation(double value) { + assert(value > 0.0); + if (_timeDilation == value) { + return; + } + // If the binding has been created, we need to resetEpoch first so that we + // capture start of the epoch with the current time dilation. + SchedulerBinding._instance?.resetEpoch(); + _timeDilation = value; +} + +/// Signature for frame-related callbacks from the scheduler. +/// +/// The `timeStamp` is the number of milliseconds since the beginning of the +/// scheduler's epoch. Use timeStamp to determine how far to advance animation +/// timelines so that all the animations in the system are synchronized to a +/// common time base. +typedef FrameCallback = void Function(Duration timeStamp); + +/// Signature for [SchedulerBinding.scheduleTask] callbacks. +/// +/// The type argument `T` is the task's return value. Consider `void` if the +/// task does not return a value. +typedef TaskCallback<T> = FutureOr<T> Function(); + +/// Signature for the [SchedulerBinding.schedulingStrategy] callback. Called +/// whenever the system needs to decide whether a task at a given +/// priority needs to be run. +/// +/// Return true if a task with the given priority should be executed at this +/// time, false otherwise. +/// +/// See also: +/// +/// * [defaultSchedulingStrategy], the default [SchedulingStrategy] for [SchedulerBinding.schedulingStrategy]. +typedef SchedulingStrategy = bool Function({ required int priority, required SchedulerBinding scheduler }); + +class _TaskEntry<T> { + _TaskEntry(this.task, this.priority, this.debugLabel, this.flow) { + assert(() { + debugStack = StackTrace.current; + return true; + }()); + } + final TaskCallback<T> task; + final int priority; + final String? debugLabel; + final Flow? flow; + + late StackTrace debugStack; + final Completer<T> completer = Completer<T>(); + + void run() { + if (!kReleaseMode) { + Timeline.timeSync( + debugLabel ?? 'Scheduled Task', + () { + completer.complete(task()); + }, + flow: flow != null ? Flow.step(flow!.id) : null, + ); + } else { + completer.complete(task()); + } + } +} + +class _FrameCallbackEntry { + _FrameCallbackEntry(this.callback, { bool rescheduling = false }) { + assert(() { + if (rescheduling) { + assert(() { + if (debugCurrentCallbackStack == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('scheduleFrameCallback called with rescheduling true, but no callback is in scope.'), + ErrorDescription( + 'The "rescheduling" argument should only be set to true if the ' + 'callback is being reregistered from within the callback itself, ' + 'and only then if the callback itself is entirely synchronous.', + ), + ErrorHint( + 'If this is the initial registration of the callback, or if the ' + 'callback is asynchronous, then do not use the "rescheduling" ' + 'argument.', + ), + ]); + } + return true; + }()); + debugStack = debugCurrentCallbackStack; + } else { + // TODO(ianh): trim the frames from this library, so that the call to scheduleFrameCallback is the top one + debugStack = StackTrace.current; + } + return true; + }()); + } + + final FrameCallback callback; + + static StackTrace? debugCurrentCallbackStack; + StackTrace? debugStack; +} + +/// The various phases that a [SchedulerBinding] goes through during +/// [SchedulerBinding.handleBeginFrame]. +/// +/// This is exposed by [SchedulerBinding.schedulerPhase]. +/// +/// The values of this enum are ordered in the same order as the phases occur, +/// so their relative index values can be compared to each other. +/// +/// See also: +/// +/// * [WidgetsBinding.drawFrame], which pumps the build and rendering pipeline +/// to generate a frame. +enum SchedulerPhase { + /// No frame is being processed. Tasks (scheduled by + /// [SchedulerBinding.scheduleTask]), microtasks (scheduled by + /// [scheduleMicrotask]), [Timer] callbacks, event handlers (e.g. from user + /// input), and other callbacks (e.g. from [Future]s, [Stream]s, and the like) + /// may be executing. + idle, + + /// The transient callbacks (scheduled by + /// [SchedulerBinding.scheduleFrameCallback]) are currently executing. + /// + /// Typically, these callbacks handle updating objects to new animation + /// states. + /// + /// See [SchedulerBinding.handleBeginFrame]. + transientCallbacks, + + /// Microtasks scheduled during the processing of transient callbacks are + /// current executing. + /// + /// This may include, for instance, callbacks from futures resolved during the + /// [transientCallbacks] phase. + midFrameMicrotasks, + + /// The persistent callbacks (scheduled by + /// [SchedulerBinding.addPersistentFrameCallback]) are currently executing. + /// + /// Typically, this is the build/layout/paint pipeline. See + /// [WidgetsBinding.drawFrame] and [SchedulerBinding.handleDrawFrame]. + persistentCallbacks, + + /// The post-frame callbacks (scheduled by + /// [SchedulerBinding.addPostFrameCallback]) are currently executing. + /// + /// Typically, these callbacks handle cleanup and scheduling of work for the + /// next frame. + /// + /// See [SchedulerBinding.handleDrawFrame]. + postFrameCallbacks, +} + +/// This callback is invoked when a request for [DartPerformanceMode] is disposed. +/// +/// See also: +/// +/// * [PerformanceModeRequestHandle] for more information on the lifecycle of the handle. +typedef _PerformanceModeCleanupCallback = VoidCallback; + +/// An opaque handle that keeps a request for [DartPerformanceMode] active until +/// disposed. +/// +/// To create a [PerformanceModeRequestHandle], use [SchedulerBinding.requestPerformanceMode]. +/// The component that makes the request is responsible for disposing the handle. +class PerformanceModeRequestHandle { + PerformanceModeRequestHandle._(_PerformanceModeCleanupCallback this._cleanup) { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/scheduler.dart', + className: '$PerformanceModeRequestHandle', + object: this, + ); + } + } + + _PerformanceModeCleanupCallback? _cleanup; + + /// Call this method to signal to [SchedulerBinding] that a request for a [DartPerformanceMode] + /// is no longer needed. + /// + /// This method must only be called once per object. + void dispose() { + assert(_cleanup != null); + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _cleanup!(); + _cleanup = null; + } +} + +/// Scheduler for running the following: +/// +/// * _Transient callbacks_, triggered by the system's +/// [dart:ui.PlatformDispatcher.onBeginFrame] callback, for synchronizing the +/// application's behavior to the system's display. For example, [Ticker]s and +/// [AnimationController]s trigger from these. +/// +/// * _Persistent callbacks_, triggered by the system's +/// [dart:ui.PlatformDispatcher.onDrawFrame] callback, for updating the +/// system's display after transient callbacks have executed. For example, the +/// rendering layer uses this to drive its rendering pipeline. +/// +/// * _Post-frame callbacks_, which are run after persistent callbacks, just +/// before returning from the [dart:ui.PlatformDispatcher.onDrawFrame] callback. +/// +/// * Non-rendering tasks, to be run between frames. These are given a +/// priority and are executed in priority order according to a +/// [schedulingStrategy]. +mixin SchedulerBinding on BindingBase { + @override + void initInstances() { + super.initInstances(); + _instance = this; + + if (!kReleaseMode) { + addTimingsCallback((List<FrameTiming> timings) { + timings.forEach(_profileFramePostEvent); + }); + } + } + + /// The current [SchedulerBinding], if one has been created. + /// + /// Provides access to the features exposed by this mixin. The binding must + /// be initialized before using this getter; this is typically done by calling + /// [runApp] or [WidgetsFlutterBinding.ensureInitialized]. + static SchedulerBinding get instance => BindingBase.checkInstance(_instance); + static SchedulerBinding? _instance; + + final List<TimingsCallback> _timingsCallbacks = <TimingsCallback>[]; + + /// Add a [TimingsCallback] that receives [FrameTiming] sent from + /// the engine. + /// + /// This API enables applications to monitor their graphics + /// performance. Data from the engine is batched into lists of + /// [FrameTiming] objects which are reported approximately once a + /// second in release mode and approximately once every 100ms in + /// debug and profile builds. The list is sorted in ascending + /// chronological order (earliest frame first). The timing of the + /// first frame is sent immediately without batching. + /// + /// The data returned can be used to catch missed frames (by seeing + /// if [FrameTiming.buildDuration] or [FrameTiming.rasterDuration] + /// exceed the frame budget, e.g. 16ms at 60Hz), and to catch high + /// latency (by seeing if [FrameTiming.totalSpan] exceeds the frame + /// budget). It is possible for no frames to be missed but for the + /// latency to be more than one frame in the case where the Flutter + /// engine is pipelining the graphics updates, e.g. because the sum + /// of the [FrameTiming.buildDuration] and the + /// [FrameTiming.rasterDuration] together exceed the frame budget. + /// In those cases, animations will be smooth but touch input will + /// feel more sluggish. + /// + /// Using [addTimingsCallback] is preferred over using + /// [dart:ui.PlatformDispatcher.onReportTimings] directly because the + /// [dart:ui.PlatformDispatcher.onReportTimings] API only allows one callback, + /// which prevents multiple libraries from registering listeners + /// simultaneously, while this API allows multiple callbacks to be registered + /// independently. + /// + /// This API is implemented in terms of + /// [dart:ui.PlatformDispatcher.onReportTimings]. In release builds, when no + /// libraries have registered with this API, the + /// [dart:ui.PlatformDispatcher.onReportTimings] callback is not set, which + /// disables the performance tracking and reduces the runtime overhead to + /// approximately zero. The performance overhead of the performance tracking + /// when one or more callbacks are registered (i.e. when it is enabled) is + /// very approximately 0.01% CPU usage per second (measured on an iPhone 6s). + /// + /// In debug and profile builds, the [SchedulerBinding] itself + /// registers a timings callback to update the [Timeline]. + /// + /// If the same callback is added twice, it will be executed twice. + /// + /// See also: + /// + /// * [removeTimingsCallback], which can be used to remove a callback + /// added using this method. + void addTimingsCallback(TimingsCallback callback) { + _timingsCallbacks.add(callback); + if (_timingsCallbacks.length == 1) { + assert(platformDispatcher.onReportTimings == null); + platformDispatcher.onReportTimings = _executeTimingsCallbacks; + } + assert(platformDispatcher.onReportTimings == _executeTimingsCallbacks); + } + + /// Removes a callback that was earlier added by [addTimingsCallback]. + void removeTimingsCallback(TimingsCallback callback) { + assert(_timingsCallbacks.contains(callback)); + _timingsCallbacks.remove(callback); + if (_timingsCallbacks.isEmpty) { + platformDispatcher.onReportTimings = null; + } + } + + @pragma('vm:notify-debugger-on-exception') + void _executeTimingsCallbacks(List<FrameTiming> timings) { + final List<TimingsCallback> clonedCallbacks = + List<TimingsCallback>.of(_timingsCallbacks); + for (final TimingsCallback callback in clonedCallbacks) { + try { + if (_timingsCallbacks.contains(callback)) { + callback(timings); + } + } catch (exception, stack) { + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<TimingsCallback>( + 'The TimingsCallback that gets executed was', + callback, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + context: ErrorDescription('while executing callbacks for FrameTiming'), + informationCollector: collector, + )); + } + } + } + + @override + void initServiceExtensions() { + super.initServiceExtensions(); + + if (!kReleaseMode) { + registerNumericServiceExtension( + name: SchedulerServiceExtensions.timeDilation.name, + getter: () async => timeDilation, + setter: (double value) async { + timeDilation = value; + }, + ); + } + } + + /// Whether the application is visible, and if so, whether it is currently + /// interactive. + /// + /// This is set by [handleAppLifecycleStateChanged] when the + /// [SystemChannels.lifecycle] notification is dispatched. + /// + /// The preferred ways to watch for changes to this value are using + /// [WidgetsBindingObserver.didChangeAppLifecycleState], or through an + /// [AppLifecycleListener] object. + AppLifecycleState? get lifecycleState => _lifecycleState; + AppLifecycleState? _lifecycleState; + + /// Allows the test framework to reset the lifecycle state back to its + /// initial value. + @visibleForTesting + void resetLifecycleState() { + _lifecycleState = null; + } + + /// Called when the application lifecycle state changes. + /// + /// Notifies all the observers using + /// [WidgetsBindingObserver.didChangeAppLifecycleState]. + /// + /// This method exposes notifications from [SystemChannels.lifecycle]. + @protected + @mustCallSuper + void handleAppLifecycleStateChanged(AppLifecycleState state) { + if (lifecycleState == state) { + return; + } + _lifecycleState = state; + switch (state) { + case AppLifecycleState.resumed: + case AppLifecycleState.inactive: + _setFramesEnabledState(true); + case AppLifecycleState.hidden: + case AppLifecycleState.paused: + case AppLifecycleState.detached: + _setFramesEnabledState(false); + } + } + + /// The strategy to use when deciding whether to run a task or not. + /// + /// Defaults to [defaultSchedulingStrategy]. + SchedulingStrategy schedulingStrategy = defaultSchedulingStrategy; + + static int _taskSorter (_TaskEntry<dynamic> e1, _TaskEntry<dynamic> e2) { + return -e1.priority.compareTo(e2.priority); + } + final PriorityQueue<_TaskEntry<dynamic>> _taskQueue = HeapPriorityQueue<_TaskEntry<dynamic>>(_taskSorter); + + /// Schedules the given `task` with the given `priority`. + /// + /// If `task` returns a future, the future returned by [scheduleTask] will + /// complete after the former future has been scheduled to completion. + /// Otherwise, the returned future for [scheduleTask] will complete with the + /// same value returned by `task` after it has been scheduled. + /// + /// The `debugLabel` and `flow` are used to report the task to the [Timeline], + /// for use when profiling. + /// + /// ## Processing model + /// + /// Tasks will be executed between frames, in priority order, + /// excluding tasks that are skipped by the current + /// [schedulingStrategy]. Tasks should be short (as in, up to a + /// millisecond), so as to not cause the regular frame callbacks to + /// get delayed. + /// + /// If an animation is running, including, for instance, a [ProgressIndicator] + /// indicating that there are pending tasks, then tasks with a priority below + /// [Priority.animation] won't run (at least, not with the + /// [defaultSchedulingStrategy]; this can be configured using + /// [schedulingStrategy]). + Future<T> scheduleTask<T>( + TaskCallback<T> task, + Priority priority, { + String? debugLabel, + Flow? flow, + }) { + final bool isFirstTask = _taskQueue.isEmpty; + final _TaskEntry<T> entry = _TaskEntry<T>( + task, + priority.value, + debugLabel, + flow, + ); + _taskQueue.add(entry); + if (isFirstTask && !locked) { + _ensureEventLoopCallback(); + } + return entry.completer.future; + } + + @override + void unlocked() { + super.unlocked(); + if (_taskQueue.isNotEmpty) { + _ensureEventLoopCallback(); + } + } + + // Whether this scheduler already requested to be called from the event loop. + bool _hasRequestedAnEventLoopCallback = false; + + // Ensures that the scheduler services a task scheduled by + // [SchedulerBinding.scheduleTask]. + void _ensureEventLoopCallback() { + assert(!locked); + assert(_taskQueue.isNotEmpty); + if (_hasRequestedAnEventLoopCallback) { + return; + } + _hasRequestedAnEventLoopCallback = true; + Timer.run(_runTasks); + } + + // Scheduled by _ensureEventLoopCallback. + void _runTasks() { + _hasRequestedAnEventLoopCallback = false; + if (handleEventLoopCallback()) { + _ensureEventLoopCallback(); + } // runs next task when there's time + } + + /// Execute the highest-priority task, if it is of a high enough priority. + /// + /// Returns true if a task was executed and there are other tasks remaining + /// (even if they are not high-enough priority). + /// + /// Returns false if no task was executed, which can occur if there are no + /// tasks scheduled, if the scheduler is [locked], or if the highest-priority + /// task is of too low a priority given the current [schedulingStrategy]. + /// + /// Also returns false if there are no tasks remaining. + @visibleForTesting + @pragma('vm:notify-debugger-on-exception') + bool handleEventLoopCallback() { + if (_taskQueue.isEmpty || locked) { + return false; + } + final _TaskEntry<dynamic> entry = _taskQueue.first; + if (schedulingStrategy(priority: entry.priority, scheduler: this)) { + try { + _taskQueue.removeFirst(); + entry.run(); + } catch (exception, exceptionStack) { + StackTrace? callbackStack; + assert(() { + callbackStack = entry.debugStack; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: exceptionStack, + library: 'scheduler library', + context: ErrorDescription('during a task callback'), + informationCollector: (callbackStack == null) ? null : () { + return <DiagnosticsNode>[ + DiagnosticsStackTrace( + '\nThis exception was thrown in the context of a scheduler callback. ' + 'When the scheduler callback was _registered_ (as opposed to when the ' + 'exception was thrown), this was the stack', + callbackStack, + ), + ]; + }, + )); + } + return _taskQueue.isNotEmpty; + } + return false; + } + + int _nextFrameCallbackId = 0; // positive + Map<int, _FrameCallbackEntry> _transientCallbacks = <int, _FrameCallbackEntry>{}; + final Set<int> _removedIds = HashSet<int>(); + + /// The current number of transient frame callbacks scheduled. + /// + /// This is reset to zero just before all the currently scheduled + /// transient callbacks are called, at the start of a frame. + /// + /// This number is primarily exposed so that tests can verify that + /// there are no unexpected transient callbacks still registered + /// after a test's resources have been gracefully disposed. + int get transientCallbackCount => _transientCallbacks.length; + + /// Schedules the given transient frame callback. + /// + /// Adds the given callback to the list of frame callbacks and ensures that a + /// frame is scheduled. + /// + /// If this is called during the frame's animation phase (when transient frame + /// callbacks are still being invoked), a new frame will be scheduled, and + /// `callback` will be called in the newly scheduled frame, not in the current + /// frame. + /// + /// If this is a one-off registration, ignore the `rescheduling` argument. + /// + /// If this is a callback that will be re-registered each time it fires, then + /// when you re-register the callback, set the `rescheduling` argument to + /// true. This has no effect in release builds, but in debug builds, it + /// ensures that the stack trace that is stored for this callback is the + /// original stack trace for when the callback was _first_ registered, rather + /// than the stack trace for when the callback is re-registered. This makes it + /// easier to track down the original reason that a particular callback was + /// called. If `rescheduling` is true, the call must be in the context of a + /// frame callback. + /// + /// Callbacks registered with this method can be canceled using + /// [cancelFrameCallbackWithId]. + /// + /// See also: + /// + /// * [WidgetsBinding.drawFrame], which explains the phases of each frame + /// for those apps that use Flutter widgets (and where transient frame + /// callbacks fit into those phases). + int scheduleFrameCallback(FrameCallback callback, { bool rescheduling = false }) { + scheduleFrame(); + _nextFrameCallbackId += 1; + _transientCallbacks[_nextFrameCallbackId] = _FrameCallbackEntry(callback, rescheduling: rescheduling); + return _nextFrameCallbackId; + } + + /// Cancels the transient frame callback with the given [id]. + /// + /// Removes the given callback from the list of frame callbacks. If a frame + /// has been requested, this does not also cancel that request. + /// + /// Transient frame callbacks are those registered using + /// [scheduleFrameCallback]. + void cancelFrameCallbackWithId(int id) { + assert(id > 0); + _transientCallbacks.remove(id); + _removedIds.add(id); + } + + /// Asserts that there are no registered transient callbacks; if + /// there are, prints their locations and throws an exception. + /// + /// A transient frame callback is one that was registered with + /// [scheduleFrameCallback]. + /// + /// This is expected to be called at the end of tests (the + /// flutter_test framework does it automatically in normal cases). + /// + /// Call this method when you expect there to be no transient + /// callbacks registered, in an assert statement with a message that + /// you want printed when a transient callback is registered: + /// + /// ```dart + /// assert(SchedulerBinding.instance.debugAssertNoTransientCallbacks( + /// 'A leak of transient callbacks was detected while doing foo.' + /// )); + /// ``` + /// + /// Does nothing if asserts are disabled. Always returns true. + bool debugAssertNoTransientCallbacks(String reason) { + assert(() { + if (transientCallbackCount > 0) { + // We cache the values so that we can produce them later + // even if the information collector is called after + // the problem has been resolved. + final int count = transientCallbackCount; + final Map<int, _FrameCallbackEntry> callbacks = Map<int, _FrameCallbackEntry>.of(_transientCallbacks); + FlutterError.reportError(FlutterErrorDetails( + exception: reason, + library: 'scheduler library', + informationCollector: () => <DiagnosticsNode>[ + if (count == 1) + // TODO(jacobr): I have added an extra line break in this case. + ErrorDescription( + 'There was one transient callback left. ' + 'The stack trace for when it was registered is as follows:', + ) + else + ErrorDescription( + 'There were $count transient callbacks left. ' + 'The stack traces for when they were registered are as follows:', + ), + for (final int id in callbacks.keys) + DiagnosticsStackTrace('── callback $id ──', callbacks[id]!.debugStack, showSeparator: false), + ], + )); + } + return true; + }()); + return true; + } + + /// Asserts that there are no pending performance mode requests in debug mode. + /// + /// Throws a [FlutterError] if there are pending performance mode requests, + /// as this indicates a potential memory leak. + bool debugAssertNoPendingPerformanceModeRequests(String reason) { + assert(() { + if (_performanceMode != null) { + throw FlutterError(reason); + } + return true; + }()); + return true; + } + + /// Asserts that there is no artificial time dilation in debug mode. + /// + /// Throws a [FlutterError] if there are such dilation, as this will make + /// subsequent tests see dilation and thus flaky. + bool debugAssertNoTimeDilation(String reason) { + assert(() { + if (timeDilation != 1.0) { + throw FlutterError(reason); + } + return true; + }()); + return true; + } + + /// Prints the stack for where the current transient callback was registered. + /// + /// A transient frame callback is one that was registered with + /// [scheduleFrameCallback]. + /// + /// When called in debug more and in the context of a transient callback, this + /// function prints the stack trace from where the current transient callback + /// was registered (i.e. where it first called [scheduleFrameCallback]). + /// + /// When called in debug mode in other contexts, it prints a message saying + /// that this function was not called in the context a transient callback. + /// + /// In release mode, this function does nothing. + /// + /// To call this function, use the following code: + /// + /// ```dart + /// SchedulerBinding.debugPrintTransientCallbackRegistrationStack(); + /// ``` + static void debugPrintTransientCallbackRegistrationStack() { + assert(() { + if (_FrameCallbackEntry.debugCurrentCallbackStack != null) { + debugPrint('When the current transient callback was registered, this was the stack:'); + debugPrint( + FlutterError.defaultStackFilter( + FlutterError.demangleStackTrace( + _FrameCallbackEntry.debugCurrentCallbackStack!, + ).toString().trimRight().split('\n'), + ).join('\n'), + ); + } else { + debugPrint('No transient callback is currently executing.'); + } + return true; + }()); + } + + final List<FrameCallback> _persistentCallbacks = <FrameCallback>[]; + + /// Adds a persistent frame callback. + /// + /// Persistent callbacks are called after transient + /// (non-persistent) frame callbacks. + /// + /// Does *not* request a new frame. Conceptually, persistent frame + /// callbacks are observers of "begin frame" events. Since they are + /// executed after the transient frame callbacks they can drive the + /// rendering pipeline. + /// + /// Persistent frame callbacks cannot be unregistered. Once registered, they + /// are called for every frame for the lifetime of the application. + /// + /// See also: + /// + /// * [WidgetsBinding.drawFrame], which explains the phases of each frame + /// for those apps that use Flutter widgets (and where persistent frame + /// callbacks fit into those phases). + void addPersistentFrameCallback(FrameCallback callback) { + _persistentCallbacks.add(callback); + } + + final List<FrameCallback> _postFrameCallbacks = <FrameCallback>[]; + + /// Schedule a callback for the end of this frame. + /// + /// The provided callback is run immediately after a frame, just after the + /// persistent frame callbacks (which is when the main rendering pipeline has + /// been flushed). + /// + /// This method does *not* request a new frame. If a frame is already in + /// progress and the execution of post-frame callbacks has not yet begun, then + /// the registered callback is executed at the end of the current frame. + /// Otherwise, the registered callback is executed after the next frame + /// (whenever that may be, if ever). + /// + /// The callbacks are executed in the order in which they have been + /// added. + /// + /// Post-frame callbacks cannot be unregistered. They are called exactly once. + /// + /// In debug mode, if [debugTracePostFrameCallbacks] is set to true, then the + /// registered callback will show up in the timeline events chart, which can + /// be viewed in [DevTools](https://docs.flutter.dev/tools/devtools/overview). + /// In that case, the `debugLabel` argument specifies the name of the callback + /// as it will appear in the timeline. In profile and release builds, + /// post-frame are never traced, and the `debugLabel` argument is ignored. + /// + /// See also: + /// + /// * [scheduleFrameCallback], which registers a callback for the start of + /// the next frame. + /// * [WidgetsBinding.drawFrame], which explains the phases of each frame + /// for those apps that use Flutter widgets (and where post frame + /// callbacks fit into those phases). + void addPostFrameCallback(FrameCallback callback, {String debugLabel = 'callback'}) { + assert(() { + if (debugTracePostFrameCallbacks) { + final FrameCallback originalCallback = callback; + callback = (Duration timeStamp) { + Timeline.startSync(debugLabel); + try { + originalCallback(timeStamp); + } finally { + Timeline.finishSync(); + } + }; + } + return true; + }()); + _postFrameCallbacks.add(callback); + } + + Completer<void>? _nextFrameCompleter; + + /// Returns a Future that completes after the frame completes. + /// + /// If this is called between frames, a frame is immediately scheduled if + /// necessary. If this is called during a frame, the Future completes after + /// the current frame. + /// + /// If the device's screen is currently turned off, this may wait a very long + /// time, since frames are not scheduled while the device's screen is turned + /// off. + Future<void> get endOfFrame { + if (_nextFrameCompleter == null) { + if (schedulerPhase == SchedulerPhase.idle) { + scheduleFrame(); + } + _nextFrameCompleter = Completer<void>(); + addPostFrameCallback((Duration timeStamp) { + _nextFrameCompleter!.complete(); + _nextFrameCompleter = null; + }, debugLabel: 'SchedulerBinding.completeFrame'); + } + return _nextFrameCompleter!.future; + } + + /// Whether this scheduler has requested that [handleBeginFrame] be called soon. + bool get hasScheduledFrame => _hasScheduledFrame; + bool _hasScheduledFrame = false; + + /// The phase that the scheduler is currently operating under. + SchedulerPhase get schedulerPhase => _schedulerPhase; + SchedulerPhase _schedulerPhase = SchedulerPhase.idle; + + /// Whether frames are currently being scheduled when [scheduleFrame] is called. + /// + /// This value depends on the value of the [lifecycleState]. + bool get framesEnabled => _framesEnabled; + + bool _framesEnabled = true; + void _setFramesEnabledState(bool enabled) { + if (_framesEnabled == enabled) { + return; + } + _framesEnabled = enabled; + if (enabled) { + scheduleFrame(); + } + } + + /// Ensures callbacks for [PlatformDispatcher.onBeginFrame] and + /// [PlatformDispatcher.onDrawFrame] are registered. + @protected + void ensureFrameCallbacksRegistered() { + platformDispatcher.onBeginFrame ??= _handleBeginFrame; + platformDispatcher.onDrawFrame ??= _handleDrawFrame; + } + + /// Schedules a new frame using [scheduleFrame] if this object is not + /// currently producing a frame. + /// + /// Calling this method ensures that [handleDrawFrame] will eventually be + /// called, unless it's already in progress. + /// + /// This has no effect if [schedulerPhase] is + /// [SchedulerPhase.transientCallbacks] or [SchedulerPhase.midFrameMicrotasks] + /// (because a frame is already being prepared in that case), or + /// [SchedulerPhase.persistentCallbacks] (because a frame is actively being + /// rendered in that case). It will schedule a frame if the [schedulerPhase] + /// is [SchedulerPhase.idle] (in between frames) or + /// [SchedulerPhase.postFrameCallbacks] (after a frame). + void ensureVisualUpdate() { + switch (schedulerPhase) { + case SchedulerPhase.idle: + case SchedulerPhase.postFrameCallbacks: + scheduleFrame(); + return; + case SchedulerPhase.transientCallbacks: + case SchedulerPhase.midFrameMicrotasks: + case SchedulerPhase.persistentCallbacks: + return; + } + } + + /// If necessary, schedules a new frame by calling + /// [dart:ui.PlatformDispatcher.scheduleFrame]. + /// + /// After this is called, the engine will (eventually) call + /// [handleBeginFrame]. (This call might be delayed, e.g. if the device's + /// screen is turned off it will typically be delayed until the screen is on + /// and the application is visible.) Calling this during a frame forces + /// another frame to be scheduled, even if the current frame has not yet + /// completed. + /// + /// Scheduled frames are serviced when triggered by a "Vsync" signal provided + /// by the operating system. The "Vsync" signal, or vertical synchronization + /// signal, was historically related to the display refresh, at a time when + /// hardware physically moved a beam of electrons vertically between updates + /// of the display. The operation of contemporary hardware is somewhat more + /// subtle and complicated, but the conceptual "Vsync" refresh signal continue + /// to be used to indicate when applications should update their rendering. + /// + /// To have a stack trace printed to the console any time this function + /// schedules a frame, set [debugPrintScheduleFrameStacks] to true. + /// + /// See also: + /// + /// * [scheduleForcedFrame], which ignores the [lifecycleState] when + /// scheduling a frame. + /// * [scheduleWarmUpFrame], which ignores the "Vsync" signal entirely and + /// triggers a frame immediately. + void scheduleFrame() { + if (_hasScheduledFrame || !framesEnabled) { + return; + } + assert(() { + if (debugPrintScheduleFrameStacks) { + debugPrintStack(label: 'scheduleFrame() called. Current phase is $schedulerPhase.'); + } + return true; + }()); + ensureFrameCallbacksRegistered(); + platformDispatcher.scheduleFrame(); + _hasScheduledFrame = true; + } + + /// Schedules a new frame by calling + /// [dart:ui.PlatformDispatcher.scheduleFrame]. + /// + /// After this is called, the engine will call [handleBeginFrame], even if + /// frames would normally not be scheduled by [scheduleFrame] (e.g. even if + /// the device's screen is turned off). + /// + /// The framework uses this to force a frame to be rendered at the correct + /// size when the phone is rotated, so that a correctly-sized rendering is + /// available when the screen is turned back on. + /// + /// To have a stack trace printed to the console any time this function + /// schedules a frame, set [debugPrintScheduleFrameStacks] to true. + /// + /// Prefer using [scheduleFrame] unless it is imperative that a frame be + /// scheduled immediately, since using [scheduleForcedFrame] will cause + /// significantly higher battery usage when the device should be idle. + /// + /// Consider using [scheduleWarmUpFrame] instead if the goal is to update the + /// rendering as soon as possible (e.g. at application startup). + void scheduleForcedFrame() { + if (_hasScheduledFrame) { + return; + } + assert(() { + if (debugPrintScheduleFrameStacks) { + debugPrintStack(label: 'scheduleForcedFrame() called. Current phase is $schedulerPhase.'); + } + return true; + }()); + ensureFrameCallbacksRegistered(); + platformDispatcher.scheduleFrame(); + _hasScheduledFrame = true; + } + + bool _warmUpFrame = false; + + /// Schedule a frame to run as soon as possible, rather than waiting for + /// the engine to request a frame in response to a system "Vsync" signal. + /// + /// This is used during application startup so that the first frame (which is + /// likely to be quite expensive) gets a few extra milliseconds to run. + /// + /// Locks events dispatching until the scheduled frame has completed. + /// + /// If a frame has already been scheduled with [scheduleFrame] or + /// [scheduleForcedFrame], this call may delay that frame. + /// + /// If any scheduled frame has already begun or if another + /// [scheduleWarmUpFrame] was already called, this call will be ignored. + /// + /// Prefer [scheduleFrame] to update the display in normal operation. + /// + /// ## Design discussion + /// + /// The Flutter engine prompts the framework to generate frames when it + /// receives a request from the operating system (known for historical reasons + /// as a vsync). However, this may not happen for several milliseconds after + /// the app starts (or after a hot reload). To make use of the time between + /// when the widget tree is first configured and when the engine requests an + /// update, the framework schedules a _warm-up frame_. + /// + /// A warm-up frame may never actually render (as the engine did not request + /// it and therefore does not have a valid context in which to paint), but it + /// will cause the framework to go through the steps of building, laying out, + /// and painting, which can together take several milliseconds. Thus, when the + /// engine requests a real frame, much of the work will already have been + /// completed, and the framework can generate the frame with minimal + /// additional effort. + /// + /// Warm-up frames are scheduled by [runApp] on startup, and by + /// [RendererBinding.performReassemble] during a hot reload. + /// + /// Warm-up frames are also scheduled when the framework is unblocked by a + /// call to [RendererBinding.allowFirstFrame] (corresponding to a call to + /// [RendererBinding.deferFirstFrame] that blocked the rendering). + void scheduleWarmUpFrame() { + if (_warmUpFrame || schedulerPhase != SchedulerPhase.idle) { + return; + } + + _warmUpFrame = true; + TimelineTask? debugTimelineTask; + if (!kReleaseMode) { + debugTimelineTask = TimelineTask()..start('Warm-up frame'); + } + final bool hadScheduledFrame = _hasScheduledFrame; + // We use timers here to ensure that microtasks flush in between. + Timer.run(() { + assert(_warmUpFrame); + handleBeginFrame(null); + }); + Timer.run(() { + assert(_warmUpFrame); + handleDrawFrame(); + // We call resetEpoch after this frame so that, in the hot reload case, + // the very next frame pretends to have occurred immediately after this + // warm-up frame. The warm-up frame's timestamp will typically be far in + // the past (the time of the last real frame), so if we didn't reset the + // epoch we would see a sudden jump from the old time in the warm-up frame + // to the new time in the "real" frame. The biggest problem with this is + // that implicit animations end up being triggered at the old time and + // then skipping every frame and finishing in the new time. + resetEpoch(); + _warmUpFrame = false; + if (hadScheduledFrame) { + scheduleFrame(); + } + }); + + // Lock events so touch events etc don't insert themselves until the + // scheduled frame has finished. + lockEvents(() async { + await endOfFrame; + if (!kReleaseMode) { + debugTimelineTask!.finish(); + } + }); + } + + Duration? _firstRawTimeStampInEpoch; + Duration _epochStart = Duration.zero; + Duration _lastRawTimeStamp = Duration.zero; + + /// Prepares the scheduler for a non-monotonic change to how time stamps are + /// calculated. + /// + /// Callbacks received from the scheduler assume that their time stamps are + /// monotonically increasing. The raw time stamp passed to [handleBeginFrame] + /// is monotonic, but the scheduler might adjust those time stamps to provide + /// [timeDilation]. Without careful handling, these adjusts could cause time + /// to appear to run backwards. + /// + /// The [resetEpoch] function ensures that the time stamps are monotonic by + /// resetting the base time stamp used for future time stamp adjustments to the + /// current value. For example, if the [timeDilation] decreases, rather than + /// scaling down the [Duration] since the beginning of time, [resetEpoch] will + /// ensure that we only scale down the duration since [resetEpoch] was called. + /// + /// Setting [timeDilation] calls [resetEpoch] automatically. You don't need to + /// call [resetEpoch] yourself. + void resetEpoch() { + _epochStart = _adjustForEpoch(_lastRawTimeStamp); + _firstRawTimeStampInEpoch = null; + } + + /// Adjusts the given time stamp into the current epoch. + /// + /// This both offsets the time stamp to account for when the epoch started + /// (both in raw time and in the epoch's own time line) and scales the time + /// stamp to reflect the time dilation in the current epoch. + /// + /// These mechanisms together combine to ensure that the durations we give + /// during frame callbacks are monotonically increasing. + Duration _adjustForEpoch(Duration rawTimeStamp) { + final Duration rawDurationSinceEpoch = _firstRawTimeStampInEpoch == null ? Duration.zero : rawTimeStamp - _firstRawTimeStampInEpoch!; + return Duration(microseconds: (rawDurationSinceEpoch.inMicroseconds / timeDilation).round() + _epochStart.inMicroseconds); + } + + /// The time stamp for the frame currently being processed. + /// + /// This is only valid while between the start of [handleBeginFrame] and the + /// end of the corresponding [handleDrawFrame], i.e. while a frame is being + /// produced. + Duration get currentFrameTimeStamp { + assert(_currentFrameTimeStamp != null); + return _currentFrameTimeStamp!; + } + Duration? _currentFrameTimeStamp; + + /// The raw time stamp as provided by the engine to + /// [dart:ui.PlatformDispatcher.onBeginFrame] for the frame currently being + /// processed. + /// + /// Unlike [currentFrameTimeStamp], this time stamp is neither adjusted to + /// offset when the epoch started nor scaled to reflect the [timeDilation] in + /// the current epoch. + /// + /// On most platforms, this is a more or less arbitrary value, and should + /// generally be ignored. On Fuchsia, this corresponds to the system-provided + /// presentation time, and can be used to ensure that animations running in + /// different processes are synchronized. + Duration get currentSystemFrameTimeStamp { + return _lastRawTimeStamp; + } + + int _debugFrameNumber = 0; + String? _debugBanner; + + // Whether the current engine frame needs to be postponed till after the + // warm-up frame. + // + // Engine may begin a frame in the middle of the warm-up frame because the + // warm-up frame is scheduled by timers while the engine frame is scheduled + // by platform specific frame scheduler (e.g. `requestAnimationFrame` on the + // web). When this happens, we let the warm-up frame finish, and postpone the + // engine frame. + bool _rescheduleAfterWarmUpFrame = false; + + void _handleBeginFrame(Duration rawTimeStamp) { + if (_warmUpFrame) { + // "begin frame" and "draw frame" must strictly alternate. Therefore + // _rescheduleAfterWarmUpFrame cannot possibly be true here as it is + // reset by _handleDrawFrame. + assert(!_rescheduleAfterWarmUpFrame); + _rescheduleAfterWarmUpFrame = true; + return; + } + handleBeginFrame(rawTimeStamp); + } + + void _handleDrawFrame() { + if (_rescheduleAfterWarmUpFrame) { + _rescheduleAfterWarmUpFrame = false; + // Reschedule in a post-frame callback to allow the draw-frame phase of + // the warm-up frame to finish. + addPostFrameCallback((Duration timeStamp) { + // Force an engine frame. + // + // We need to reset _hasScheduledFrame here because we cancelled the + // original engine frame, and therefore did not run handleBeginFrame + // who is responsible for resetting it. So if a frame callback set this + // to true in the "begin frame" part of the warm-up frame, it will + // still be true here and cause us to skip scheduling an engine frame. + _hasScheduledFrame = false; + scheduleFrame(); + }, debugLabel: 'SchedulerBinding.scheduleFrame'); + return; + } + handleDrawFrame(); + } + + final TimelineTask? _frameTimelineTask = kReleaseMode ? null : TimelineTask(); + + /// Called by the engine to prepare the framework to produce a new frame. + /// + /// This function calls all the transient frame callbacks registered by + /// [scheduleFrameCallback]. It then returns, any scheduled microtasks are run + /// (e.g. handlers for any [Future]s resolved by transient frame callbacks), + /// and [handleDrawFrame] is called to continue the frame. + /// + /// If the given time stamp is null, the time stamp from the last frame is + /// reused. + /// + /// To have a banner shown at the start of every frame in debug mode, set + /// [debugPrintBeginFrameBanner] to true. The banner will be printed to the + /// console using [debugPrint] and will contain the frame number (which + /// increments by one for each frame), and the time stamp of the frame. If the + /// given time stamp was null, then the string "warm-up frame" is shown + /// instead of the time stamp. This allows frames eagerly pushed by the + /// framework to be distinguished from those requested by the engine in + /// response to the "Vsync" signal from the operating system. + /// + /// You can also show a banner at the end of every frame by setting + /// [debugPrintEndFrameBanner] to true. This allows you to distinguish log + /// statements printed during a frame from those printed between frames (e.g. + /// in response to events or timers). + void handleBeginFrame(Duration? rawTimeStamp) { + _frameTimelineTask?.start('Frame'); + _firstRawTimeStampInEpoch ??= rawTimeStamp; + _currentFrameTimeStamp = _adjustForEpoch(rawTimeStamp ?? _lastRawTimeStamp); + if (rawTimeStamp != null) { + _lastRawTimeStamp = rawTimeStamp; + } + + assert(() { + _debugFrameNumber += 1; + + if (debugPrintBeginFrameBanner || debugPrintEndFrameBanner) { + final StringBuffer frameTimeStampDescription = StringBuffer(); + if (rawTimeStamp != null) { + _debugDescribeTimeStamp(_currentFrameTimeStamp!, frameTimeStampDescription); + } else { + frameTimeStampDescription.write('(warm-up frame)'); + } + _debugBanner = '▄▄▄▄▄▄▄▄ Frame ${_debugFrameNumber.toString().padRight(7)} ${frameTimeStampDescription.toString().padLeft(18)} ▄▄▄▄▄▄▄▄'; + if (debugPrintBeginFrameBanner) { + debugPrint(_debugBanner); + } + } + return true; + }()); + + assert(schedulerPhase == SchedulerPhase.idle); + _hasScheduledFrame = false; + try { + // TRANSIENT FRAME CALLBACKS + _frameTimelineTask?.start('Animate'); + _schedulerPhase = SchedulerPhase.transientCallbacks; + final Map<int, _FrameCallbackEntry> callbacks = _transientCallbacks; + _transientCallbacks = <int, _FrameCallbackEntry>{}; + callbacks.forEach((int id, _FrameCallbackEntry callbackEntry) { + if (!_removedIds.contains(id)) { + _invokeFrameCallback(callbackEntry.callback, _currentFrameTimeStamp!, callbackEntry.debugStack); + } + }); + _removedIds.clear(); + } finally { + _schedulerPhase = SchedulerPhase.midFrameMicrotasks; + } + } + + DartPerformanceMode? _performanceMode; + int _numPerformanceModeRequests = 0; + + /// Request a specific [DartPerformanceMode]. + /// + /// Returns `null` if the request was not successful due to conflicting performance mode requests. + /// Two requests are said to be in conflict if they are not of the same [DartPerformanceMode] type, + /// and an explicit request for a performance mode has been made prior. + /// + /// Requestor is responsible for calling [PerformanceModeRequestHandle.dispose] when it no longer + /// requires the performance mode. + PerformanceModeRequestHandle? requestPerformanceMode(DartPerformanceMode mode) { + // conflicting requests are not allowed. + if (_performanceMode != null && _performanceMode != mode) { + return null; + } + + if (_performanceMode == mode) { + assert(_numPerformanceModeRequests > 0); + _numPerformanceModeRequests++; + } else if (_performanceMode == null) { + assert(_numPerformanceModeRequests == 0); + _performanceMode = mode; + _numPerformanceModeRequests = 1; + } + + return PerformanceModeRequestHandle._(_disposePerformanceModeRequest); + } + + /// Remove a request for a specific [DartPerformanceMode]. + /// + /// If all the pending requests have been disposed, the engine will revert to the + /// [DartPerformanceMode.balanced] performance mode. + void _disposePerformanceModeRequest() { + _numPerformanceModeRequests--; + if (_numPerformanceModeRequests == 0) { + _performanceMode = null; + PlatformDispatcher.instance.requestDartPerformanceMode(DartPerformanceMode.balanced); + } + } + + /// Returns the current [DartPerformanceMode] requested or `null` if no requests have + /// been made. + /// + /// This is only supported in debug and profile modes, returns `null` in release mode. + DartPerformanceMode? debugGetRequestedPerformanceMode() { + if (!(kDebugMode || kProfileMode)) { + return null; + } else { + return _performanceMode; + } + } + + /// Called by the engine to produce a new frame. + /// + /// This method is called immediately after [handleBeginFrame]. It calls all + /// the callbacks registered by [addPersistentFrameCallback], which typically + /// drive the rendering pipeline, and then calls the callbacks registered by + /// [addPostFrameCallback]. + /// + /// See [handleBeginFrame] for a discussion about debugging hooks that may be + /// useful when working with frame callbacks. + void handleDrawFrame() { + assert(_schedulerPhase == SchedulerPhase.midFrameMicrotasks); + _frameTimelineTask?.finish(); // end the "Animate" phase + try { + // PERSISTENT FRAME CALLBACKS + _schedulerPhase = SchedulerPhase.persistentCallbacks; + for (final FrameCallback callback in List<FrameCallback>.of(_persistentCallbacks)) { + _invokeFrameCallback(callback, _currentFrameTimeStamp!); + } + + // POST-FRAME CALLBACKS + _schedulerPhase = SchedulerPhase.postFrameCallbacks; + final List<FrameCallback> localPostFrameCallbacks = + List<FrameCallback>.of(_postFrameCallbacks); + _postFrameCallbacks.clear(); + Timeline.startSync('POST_FRAME'); + try { + for (final FrameCallback callback in localPostFrameCallbacks) { + _invokeFrameCallback(callback, _currentFrameTimeStamp!); + } + } finally { + Timeline.finishSync(); + } + } finally { + _schedulerPhase = SchedulerPhase.idle; + _frameTimelineTask?.finish(); // end the Frame + assert(() { + if (debugPrintEndFrameBanner) { + debugPrint('▀' * _debugBanner!.length); + } + _debugBanner = null; + return true; + }()); + _currentFrameTimeStamp = null; + } + } + + void _profileFramePostEvent(FrameTiming frameTiming) { + postEvent('Flutter.Frame', <String, dynamic>{ + 'number': frameTiming.frameNumber, + 'startTime': frameTiming.timestampInMicroseconds(FramePhase.buildStart), + 'elapsed': frameTiming.totalSpan.inMicroseconds, + 'build': frameTiming.buildDuration.inMicroseconds, + 'raster': frameTiming.rasterDuration.inMicroseconds, + 'vsyncOverhead': frameTiming.vsyncOverhead.inMicroseconds, + }); + } + + static void _debugDescribeTimeStamp(Duration timeStamp, StringBuffer buffer) { + if (timeStamp.inDays > 0) { + buffer.write('${timeStamp.inDays}d '); + } + if (timeStamp.inHours > 0) { + buffer.write('${timeStamp.inHours - timeStamp.inDays * Duration.hoursPerDay}h '); + } + if (timeStamp.inMinutes > 0) { + buffer.write('${timeStamp.inMinutes - timeStamp.inHours * Duration.minutesPerHour}m '); + } + if (timeStamp.inSeconds > 0) { + buffer.write('${timeStamp.inSeconds - timeStamp.inMinutes * Duration.secondsPerMinute}s '); + } + buffer.write('${timeStamp.inMilliseconds - timeStamp.inSeconds * Duration.millisecondsPerSecond}'); + final int microseconds = timeStamp.inMicroseconds - timeStamp.inMilliseconds * Duration.microsecondsPerMillisecond; + if (microseconds > 0) { + buffer.write('.${microseconds.toString().padLeft(3, "0")}'); + } + buffer.write('ms'); + } + + // Calls the given [callback] with [timestamp] as argument. + // + // Wraps the callback in a try/catch and forwards any error to + // [debugSchedulerExceptionHandler], if set. If not set, prints + // the error. + @pragma('vm:notify-debugger-on-exception') + void _invokeFrameCallback(FrameCallback callback, Duration timeStamp, [ StackTrace? callbackStack ]) { + assert(_FrameCallbackEntry.debugCurrentCallbackStack == null); + assert(() { + _FrameCallbackEntry.debugCurrentCallbackStack = callbackStack; + return true; + }()); + try { + callback(timeStamp); + } catch (exception, exceptionStack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: exceptionStack, + library: 'scheduler library', + context: ErrorDescription('during a scheduler callback'), + informationCollector: (callbackStack == null) ? null : () { + return <DiagnosticsNode>[ + DiagnosticsStackTrace( + '\nThis exception was thrown in the context of a scheduler callback. ' + 'When the scheduler callback was _registered_ (as opposed to when the ' + 'exception was thrown), this was the stack', + callbackStack, + ), + ]; + }, + )); + } + assert(() { + _FrameCallbackEntry.debugCurrentCallbackStack = null; + return true; + }()); + } +} + +/// The default [SchedulingStrategy] for [SchedulerBinding.schedulingStrategy]. +/// +/// If there are any frame callbacks registered, only runs tasks with +/// a [Priority] of [Priority.animation] or higher. Otherwise, runs +/// all tasks. +bool defaultSchedulingStrategy({ required int priority, required SchedulerBinding scheduler }) { + if (scheduler.transientCallbackCount > 0) { + return priority >= Priority.animation.value; + } + return true; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/debug.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/debug.dart new file mode 100644 index 0000000000000000000000000000000000000000..3be545f304ebfe5ab0fd60bf39744b419afb7355 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/debug.dart @@ -0,0 +1,81 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +// Any changes to this file should be reflected in the debugAssertAllSchedulerVarsUnset() +// function below. + +/// Print a banner at the beginning of each frame. +/// +/// Frames triggered by the engine and handler by the scheduler binding will +/// have a banner giving the frame number and the time stamp of the frame. +/// +/// Frames triggered eagerly by the widget framework (e.g. when calling +/// [runApp]) will have a label saying "warm-up frame" instead of the time stamp +/// (the time stamp sent to frame callbacks in that case is the time of the last +/// frame, or 0:00 if it is the first frame). +/// +/// To include a banner at the end of each frame as well, to distinguish +/// intra-frame output from inter-frame output, set [debugPrintEndFrameBanner] +/// to true as well. +/// +/// See also: +/// +/// * [debugProfilePaintsEnabled], which does something similar for +/// painting but using the timeline view. +/// * [debugPrintLayouts], which does something similar for layout but using +/// console output. +/// * The discussions at [WidgetsBinding.drawFrame] and at +/// [SchedulerBinding.handleBeginFrame]. +bool debugPrintBeginFrameBanner = false; + +/// Print a banner at the end of each frame. +/// +/// Combined with [debugPrintBeginFrameBanner], this can be helpful for +/// determining if code is running during a frame or between frames. +bool debugPrintEndFrameBanner = false; + +/// Log the call stacks that cause a frame to be scheduled. +/// +/// This is called whenever [SchedulerBinding.scheduleFrame] schedules a frame. This +/// can happen for various reasons, e.g. when a [Ticker] or +/// [AnimationController] is started, or when [RenderObject.markNeedsLayout] is +/// called, or when [State.setState] is called. +/// +/// To get a stack specifically when widgets are scheduled to be built, see +/// [debugPrintScheduleBuildForStacks]. +bool debugPrintScheduleFrameStacks = false; + +/// Record timeline trace events for post-frame callbacks. +/// +/// When this flag is set to false (the default), the developer timeline +/// records when post-frame callbacks are running, but it does not tell you any +/// information about how that time is spent within specific callbacks: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/scheduler/debug_trace_post_frame_callbacks_off.png) +/// +/// When this flag is set to true, timeline events will be recorded for each +/// post-frame callback that runs, like so: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/scheduler/debug_trace_post_frame_callbacks_on.png) +bool debugTracePostFrameCallbacks = false; + +/// Returns true if none of the scheduler library debug variables have been changed. +/// +/// This function is used by the test framework to ensure that debug variables +/// haven't been inadvertently changed. +/// +/// See [the scheduler library](scheduler/scheduler-library.html) for a complete +/// list. +bool debugAssertAllSchedulerVarsUnset(String reason) { + assert(() { + if (debugPrintBeginFrameBanner || + debugPrintEndFrameBanner) { + throw FlutterError(reason); + } + return true; + }()); + return true; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/priority.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/priority.dart new file mode 100644 index 0000000000000000000000000000000000000000..12cecc968669ef9aaf8416f6a20bf61e57352658 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/priority.dart @@ -0,0 +1,51 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +/// A task priority, as passed to [SchedulerBinding.scheduleTask]. +@immutable +class Priority { + const Priority._(this._value); + + /// Integer that describes this Priority value. + int get value => _value; + final int _value; + + /// A task to run after all other tasks, when no animations are running. + static const Priority idle = Priority._(0); + + /// A task to run even when animations are running. + static const Priority animation = Priority._(100000); + + /// A task to run even when the user is interacting with the device. + static const Priority touch = Priority._(200000); + + /// Maximum offset by which to clamp relative priorities. + /// + /// It is still possible to have priorities that are offset by more + /// than this amount by repeatedly taking relative offsets, but that + /// is generally discouraged. + static const int kMaxOffset = 10000; + + /// Returns a priority relative to this priority. + /// + /// A positive [offset] indicates a higher priority. + /// + /// The parameter [offset] is clamped to ±[kMaxOffset]. + Priority operator +(int offset) { + if (offset.abs() > kMaxOffset) { + // Clamp the input offset. + offset = kMaxOffset * offset.sign; + } + return Priority._(_value + offset); + } + + /// Returns a priority relative to this priority. + /// + /// A positive offset indicates a lower priority. + /// + /// The parameter [offset] is clamped to ±[kMaxOffset]. + Priority operator -(int offset) => this + (-offset); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/service_extensions.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/service_extensions.dart new file mode 100644 index 0000000000000000000000000000000000000000..bafe0bb082d39b139d71c22cc3833a9884777c19 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/service_extensions.dart @@ -0,0 +1,24 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Service extension constants for the scheduler library. +/// +/// These constants will be used when registering service extensions in the +/// framework, and they will also be used by tools and services that call these +/// service extensions. +/// +/// The String value for each of these extension names should be accessed by +/// calling the `.name` property on the enum value. +enum SchedulerServiceExtensions { + /// Name of service extension that, when called, will change the value of + /// [timeDilation], which determines the factor by which to slow down + /// animations for help in development. + /// + /// See also: + /// + /// * [timeDilation], which is the field that this service extension exposes. + /// * [SchedulerBinding.initServiceExtensions], where the service extension is + /// registered. + timeDilation, +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/ticker.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/ticker.dart new file mode 100644 index 0000000000000000000000000000000000000000..c08122911b45a22371b5ab02ef2e4b950e6b534a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/scheduler/ticker.dart @@ -0,0 +1,510 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; + +import 'binding.dart'; + +export 'dart:ui' show VoidCallback; + +export 'package:flutter/foundation.dart' show DiagnosticsNode; + +/// Signature for the callback passed to the [Ticker] class's constructor. +/// +/// The argument is the time that the object had spent enabled so far +/// at the time of the callback being called. +typedef TickerCallback = void Function(Duration elapsed); + +/// An interface implemented by classes that can vend [Ticker] objects. +/// +/// Tickers can be used by any object that wants to be notified whenever a frame +/// triggers, but are most commonly used indirectly via an +/// [AnimationController]. [AnimationController]s need a [TickerProvider] to +/// obtain their [Ticker]. If you are creating an [AnimationController] from a +/// [State], then you can use the [TickerProviderStateMixin] and +/// [SingleTickerProviderStateMixin] classes to obtain a suitable +/// [TickerProvider]. The widget test framework [WidgetTester] object can be +/// used as a ticker provider in the context of tests. In other contexts, you +/// will have to either pass a [TickerProvider] from a higher level (e.g. +/// indirectly from a [State] that mixes in [TickerProviderStateMixin]), or +/// create a custom [TickerProvider] subclass. +abstract class TickerProvider { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const TickerProvider(); + + /// Creates a ticker with the given callback. + /// + /// The kind of ticker provided depends on the kind of ticker provider. + @factory + Ticker createTicker(TickerCallback onTick); +} + +// TODO(jacobr): make Ticker use Diagnosticable to simplify reporting errors +// related to a ticker. +/// Calls its callback once per animation frame. +/// +/// When created, a ticker is initially disabled. Call [start] to +/// enable the ticker. +/// +/// A [Ticker] can be silenced by setting [muted] to true. While silenced, time +/// still elapses, and [start] and [stop] can still be called, but no callbacks +/// are called. +/// +/// By convention, the [start] and [stop] methods are used by the ticker's +/// consumer, and the [muted] property is controlled by the [TickerProvider] +/// that created the ticker. +/// +/// Tickers are driven by the [SchedulerBinding]. See +/// [SchedulerBinding.scheduleFrameCallback]. +class Ticker { + /// Creates a ticker that will call the provided callback once per frame while + /// running. + /// + /// An optional label can be provided for debugging purposes. That label + /// will appear in the [toString] output in debug builds. + Ticker(this._onTick, { this.debugLabel }) { + assert(() { + _debugCreationStack = StackTrace.current; + return true; + }()); + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/scheduler.dart', + className: '$Ticker', + object: this, + ); + } + } + + TickerFuture? _future; + + /// Whether this ticker has been silenced. + /// + /// While silenced, a ticker's clock can still run, but the callback will not + /// be called. + bool get muted => _muted; + bool _muted = false; + /// When set to true, silences the ticker, so that it is no longer ticking. If + /// a tick is already scheduled, it will unschedule it. This will not + /// unschedule the next frame, though. + /// + /// When set to false, unsilences the ticker, potentially scheduling a frame + /// to handle the next tick. + /// + /// By convention, the [muted] property is controlled by the object that + /// created the [Ticker] (typically a [TickerProvider]), not the object that + /// listens to the ticker's ticks. + set muted(bool value) { + if (value == muted) { + return; + } + _muted = value; + if (value) { + unscheduleTick(); + } else if (shouldScheduleTick) { + scheduleTick(); + } + } + + /// Whether this [Ticker] has scheduled a call to call its callback + /// on the next frame. + /// + /// A ticker that is [muted] can be active (see [isActive]) yet not be + /// ticking. In that case, the ticker will not call its callback, and + /// [isTicking] will be false, but time will still be progressing. + /// + /// This will return false if the [SchedulerBinding.lifecycleState] is one + /// that indicates the application is not currently visible (e.g. if the + /// device's screen is turned off). + bool get isTicking { + if (_future == null) { + return false; + } + if (muted) { + return false; + } + if (SchedulerBinding.instance.framesEnabled) { + return true; + } + if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.idle) { + return true; + } // for example, we might be in a warm-up frame or forced frame + return false; + } + + /// Whether time is elapsing for this [Ticker]. Becomes true when [start] is + /// called and false when [stop] is called. + /// + /// A ticker can be active yet not be actually ticking (i.e. not be calling + /// the callback). To determine if a ticker is actually ticking, use + /// [isTicking]. + bool get isActive => _future != null; + + Duration? _startTime; + + /// Starts the clock for this [Ticker]. If the ticker is not [muted], then this + /// also starts calling the ticker's callback once per animation frame. + /// + /// The returned future resolves once the ticker [stop]s ticking. If the + /// ticker is disposed, the future does not resolve. A derivative future is + /// available from the returned [TickerFuture] object that resolves with an + /// error in that case, via [TickerFuture.orCancel]. + /// + /// Calling this sets [isActive] to true. + /// + /// This method cannot be called while the ticker is active. To restart the + /// ticker, first [stop] it. + /// + /// By convention, this method is used by the object that receives the ticks + /// (as opposed to the [TickerProvider] which created the ticker). + TickerFuture start() { + assert(() { + if (isActive) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('A ticker was started twice.'), + ErrorDescription('A ticker that is already active cannot be started again without first stopping it.'), + describeForError('The affected ticker was'), + ]); + } + return true; + }()); + assert(_startTime == null); + _future = TickerFuture._(); + if (shouldScheduleTick) { + scheduleTick(); + } + if (SchedulerBinding.instance.schedulerPhase.index > SchedulerPhase.idle.index && + SchedulerBinding.instance.schedulerPhase.index < SchedulerPhase.postFrameCallbacks.index) { + _startTime = SchedulerBinding.instance.currentFrameTimeStamp; + } + return _future!; + } + + /// Adds a debug representation of a [Ticker] optimized for including in error + /// messages. + DiagnosticsNode describeForError(String name) { + // TODO(jacobr): make this more structured. + return DiagnosticsProperty<Ticker>(name, this, description: toString(debugIncludeStack: true)); + } + + /// Stops calling this [Ticker]'s callback. + /// + /// If called with the `canceled` argument set to false (the default), causes + /// the future returned by [start] to resolve. If called with the `canceled` + /// argument set to true, the future does not resolve, and the future obtained + /// from [TickerFuture.orCancel], if any, resolves with a [TickerCanceled] + /// error. + /// + /// Calling this sets [isActive] to false. + /// + /// This method does nothing if called when the ticker is inactive. + /// + /// By convention, this method is used by the object that receives the ticks + /// (as opposed to the [TickerProvider] which created the ticker). + void stop({ bool canceled = false }) { + if (!isActive) { + return; + } + + // We take the _future into a local variable so that isTicking is false + // when we actually complete the future (isTicking uses _future to + // determine its state). + final TickerFuture localFuture = _future!; + _future = null; + _startTime = null; + assert(!isActive); + + unscheduleTick(); + if (canceled) { + localFuture._cancel(this); + } else { + localFuture._complete(); + } + } + + + final TickerCallback _onTick; + + int? _animationId; + + /// Whether this [Ticker] has already scheduled a frame callback. + @protected + bool get scheduled => _animationId != null; + + /// Whether a tick should be scheduled. + /// + /// If this is true, then calling [scheduleTick] should succeed. + /// + /// Reasons why a tick should not be scheduled include: + /// + /// * A tick has already been scheduled for the coming frame. + /// * The ticker is not active ([start] has not been called). + /// * The ticker is not ticking, e.g. because it is [muted] (see [isTicking]). + @protected + bool get shouldScheduleTick => !muted && isActive && !scheduled; + + void _tick(Duration timeStamp) { + assert(isTicking); + assert(scheduled); + _animationId = null; + + _startTime ??= timeStamp; + _onTick(timeStamp - _startTime!); + + // The onTick callback may have scheduled another tick already, for + // example by calling stop then start again. + if (shouldScheduleTick) { + scheduleTick(rescheduling: true); + } + } + + /// Schedules a tick for the next frame. + /// + /// This should only be called if [shouldScheduleTick] is true. + @protected + void scheduleTick({ bool rescheduling = false }) { + assert(!scheduled); + assert(shouldScheduleTick); + _animationId = SchedulerBinding.instance.scheduleFrameCallback(_tick, rescheduling: rescheduling); + } + + /// Cancels the frame callback that was requested by [scheduleTick], if any. + /// + /// Calling this method when no tick is [scheduled] is harmless. + /// + /// This method should not be called when [shouldScheduleTick] would return + /// true if no tick was scheduled. + @protected + void unscheduleTick() { + if (scheduled) { + SchedulerBinding.instance.cancelFrameCallbackWithId(_animationId!); + _animationId = null; + } + assert(!shouldScheduleTick); + } + + /// Makes this [Ticker] take the state of another ticker, and disposes the + /// other ticker. + /// + /// This is useful if an object with a [Ticker] is given a new + /// [TickerProvider] but needs to maintain continuity. In particular, this + /// maintains the identity of the [TickerFuture] returned by the [start] + /// function of the original [Ticker] if the original ticker is active. + /// + /// This ticker must not be active when this method is called. + void absorbTicker(Ticker originalTicker) { + assert(!isActive); + assert(_future == null); + assert(_startTime == null); + assert(_animationId == null); + assert((originalTicker._future == null) == (originalTicker._startTime == null), 'Cannot absorb Ticker after it has been disposed.'); + if (originalTicker._future != null) { + _future = originalTicker._future; + _startTime = originalTicker._startTime; + if (shouldScheduleTick) { + scheduleTick(); + } + originalTicker._future = null; // so that it doesn't get disposed when we dispose of originalTicker + originalTicker.unscheduleTick(); + } + originalTicker.dispose(); + } + + /// Release the resources used by this object. The object is no longer usable + /// after this method is called. + /// + /// It is legal to call this method while [isActive] is true, in which case: + /// + /// * The frame callback that was requested by [scheduleTick], if any, is + /// canceled. + /// * The future that was returned by [start] does not resolve. + /// * The future obtained from [TickerFuture.orCancel], if any, resolves + /// with a [TickerCanceled] error. + @mustCallSuper + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + + if (_future != null) { + final TickerFuture localFuture = _future!; + _future = null; + assert(!isActive); + unscheduleTick(); + localFuture._cancel(this); + } + assert(() { + // We intentionally don't null out _startTime. This means that if start() + // was ever called, the object is now in a bogus state. This weakly helps + // catch cases of use-after-dispose. + _startTime = Duration.zero; + return true; + }()); + } + + /// An optional label can be provided for debugging purposes. + /// + /// This label will appear in the [toString] output in debug builds. + final String? debugLabel; + late StackTrace _debugCreationStack; + + @override + String toString({ bool debugIncludeStack = false }) { + final StringBuffer buffer = StringBuffer(); + buffer.write('${objectRuntimeType(this, 'Ticker')}('); + assert(() { + buffer.write(debugLabel ?? ''); + return true; + }()); + buffer.write(')'); + assert(() { + if (debugIncludeStack) { + buffer.writeln(); + buffer.writeln('The stack trace when the $runtimeType was actually created was:'); + FlutterError.defaultStackFilter(_debugCreationStack.toString().trimRight().split('\n')).forEach(buffer.writeln); + } + return true; + }()); + return buffer.toString(); + } +} + +/// An object representing an ongoing [Ticker] sequence. +/// +/// The [Ticker.start] method returns a [TickerFuture]. The [TickerFuture] will +/// complete successfully if the [Ticker] is stopped using [Ticker.stop] with +/// the `canceled` argument set to false (the default). +/// +/// If the [Ticker] is disposed without being stopped, or if it is stopped with +/// `canceled` set to true, then this Future will never complete. +/// +/// This class works like a normal [Future], but has an additional property, +/// [orCancel], which returns a derivative [Future] that completes with an error +/// if the [Ticker] that returned the [TickerFuture] was stopped with `canceled` +/// set to true, or if it was disposed without being stopped. +/// +/// To run a callback when either this future resolves or when the ticker is +/// canceled, use [whenCompleteOrCancel]. +class TickerFuture implements Future<void> { + TickerFuture._(); + + /// Creates a [TickerFuture] instance that represents an already-complete + /// [Ticker] sequence. + /// + /// This is useful for implementing objects that normally defer to a [Ticker] + /// but sometimes can skip the ticker because the animation is of zero + /// duration, but which still need to represent the completed animation in the + /// form of a [TickerFuture]. + TickerFuture.complete() { + _complete(); + } + + final Completer<void> _primaryCompleter = Completer<void>(); + Completer<void>? _secondaryCompleter; + bool? _completed; // null means unresolved, true means complete, false means canceled + + void _complete() { + assert(_completed == null); + _completed = true; + _primaryCompleter.complete(); + _secondaryCompleter?.complete(); + } + + void _cancel(Ticker ticker) { + assert(_completed == null); + _completed = false; + _secondaryCompleter?.completeError(TickerCanceled(ticker)); + } + + /// Calls `callback` either when this future resolves or when the ticker is + /// canceled. + /// + /// Calling this method registers an exception handler for the [orCancel] + /// future, so even if the [orCancel] property is accessed, canceling the + /// ticker will not cause an uncaught exception in the current zone. + void whenCompleteOrCancel(VoidCallback callback) { + void thunk(dynamic value) { + callback(); + } + orCancel.then<void>(thunk, onError: thunk); + } + + /// A future that resolves when this future resolves or throws when the ticker + /// is canceled. + /// + /// If this property is never accessed, then canceling the ticker does not + /// throw any exceptions. Once this property is accessed, though, if the + /// corresponding ticker is canceled, then the [Future] returned by this + /// getter will complete with an error, and if that error is not caught, there + /// will be an uncaught exception in the current zone. + Future<void> get orCancel { + if (_secondaryCompleter == null) { + _secondaryCompleter = Completer<void>(); + if (_completed != null) { + if (_completed!) { + _secondaryCompleter!.complete(); + } else { + _secondaryCompleter!.completeError(const TickerCanceled()); + } + } + } + return _secondaryCompleter!.future; + } + + @override + Stream<void> asStream() { + return _primaryCompleter.future.asStream(); + } + + @override + Future<void> catchError(Function onError, { bool Function(Object)? test }) { + return _primaryCompleter.future.catchError(onError, test: test); + } + + @override + Future<R> then<R>(FutureOr<R> Function(void value) onValue, { Function? onError }) { + return _primaryCompleter.future.then<R>(onValue, onError: onError); + } + + @override + Future<void> timeout(Duration timeLimit, { FutureOr<void> Function()? onTimeout }) { + return _primaryCompleter.future.timeout(timeLimit, onTimeout: onTimeout); + } + + @override + Future<void> whenComplete(dynamic Function() action) { + return _primaryCompleter.future.whenComplete(action); + } + + @override + String toString() => '${describeIdentity(this)}(${ _completed == null ? "active" : _completed! ? "complete" : "canceled" })'; +} + +/// Exception thrown by [Ticker] objects on the [TickerFuture.orCancel] future +/// when the ticker is canceled. +class TickerCanceled implements Exception { + /// Creates a canceled-ticker exception. + const TickerCanceled([this.ticker]); + + /// Reference to the [Ticker] object that was canceled. + /// + /// This may be null in the case that the [Future] created for + /// [TickerFuture.orCancel] was created after the ticker was canceled. + final Ticker? ticker; + + @override + String toString() { + if (ticker != null) { + return 'This ticker was canceled: $ticker'; + } + return 'The ticker was canceled before the "orCancel" property was first used.'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/binding.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/binding.dart new file mode 100644 index 0000000000000000000000000000000000000000..c12ec7b0355050fa05eb2da1d8a4e4c3e8e7a663 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/binding.dart @@ -0,0 +1,222 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show AccessibilityFeatures, SemanticsActionEvent, SemanticsUpdateBuilder; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'debug.dart'; + +export 'dart:ui' show AccessibilityFeatures, SemanticsActionEvent, SemanticsUpdateBuilder; + +/// The glue between the semantics layer and the Flutter engine. +mixin SemanticsBinding on BindingBase { + @override + void initInstances() { + super.initInstances(); + _instance = this; + _accessibilityFeatures = platformDispatcher.accessibilityFeatures; + platformDispatcher + ..onSemanticsEnabledChanged = _handleSemanticsEnabledChanged + ..onSemanticsActionEvent = _handleSemanticsActionEvent + ..onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged; + _handleSemanticsEnabledChanged(); + } + + /// The current [SemanticsBinding], if one has been created. + /// + /// Provides access to the features exposed by this mixin. The binding must + /// be initialized before using this getter; this is typically done by calling + /// [runApp] or [WidgetsFlutterBinding.ensureInitialized]. + static SemanticsBinding get instance => BindingBase.checkInstance(_instance); + static SemanticsBinding? _instance; + + /// Whether semantics information must be collected. + /// + /// Returns true if either the platform has requested semantics information + /// to be generated or if [ensureSemantics] has been called otherwise. + /// + /// To get notified when this value changes register a listener with + /// [addSemanticsEnabledListener]. + bool get semanticsEnabled { + assert(_semanticsEnabled.value == (_outstandingHandles > 0)); + return _semanticsEnabled.value; + } + late final ValueNotifier<bool> _semanticsEnabled = ValueNotifier<bool>(platformDispatcher.semanticsEnabled); + + /// Adds a `listener` to be called when [semanticsEnabled] changes. + /// + /// See also: + /// + /// * [removeSemanticsEnabledListener] to remove the listener again. + /// * [ValueNotifier.addListener], which documents how and when listeners are + /// called. + void addSemanticsEnabledListener(VoidCallback listener) { + _semanticsEnabled.addListener(listener); + } + + /// Removes a `listener` added by [addSemanticsEnabledListener]. + /// + /// See also: + /// + /// * [ValueNotifier.removeListener], which documents how listeners are + /// removed. + void removeSemanticsEnabledListener(VoidCallback listener) { + _semanticsEnabled.removeListener(listener); + } + + /// The number of clients registered to listen for semantics. + /// + /// The number is increased whenever [ensureSemantics] is called and decreased + /// when [SemanticsHandle.dispose] is called. + int get debugOutstandingSemanticsHandles => _outstandingHandles; + int _outstandingHandles = 0; + + /// Creates a new [SemanticsHandle] and requests the collection of semantics + /// information. + /// + /// Semantics information are only collected when there are clients interested + /// in them. These clients express their interest by holding a + /// [SemanticsHandle]. + /// + /// Clients can close their [SemanticsHandle] by calling + /// [SemanticsHandle.dispose]. Once all outstanding [SemanticsHandle] objects + /// are closed, semantics information are no longer collected. + SemanticsHandle ensureSemantics() { + assert(_outstandingHandles >= 0); + _outstandingHandles++; + assert(_outstandingHandles > 0); + _semanticsEnabled.value = true; + return SemanticsHandle._(_didDisposeSemanticsHandle); + } + + void _didDisposeSemanticsHandle() { + assert(_outstandingHandles > 0); + _outstandingHandles--; + assert(_outstandingHandles >= 0); + _semanticsEnabled.value = _outstandingHandles > 0; + } + + // Handle for semantics request from the platform. + SemanticsHandle? _semanticsHandle; + + void _handleSemanticsEnabledChanged() { + if (platformDispatcher.semanticsEnabled) { + _semanticsHandle ??= ensureSemantics(); + } else { + _semanticsHandle?.dispose(); + _semanticsHandle = null; + } + } + + void _handleSemanticsActionEvent(ui.SemanticsActionEvent action) { + final Object? arguments = action.arguments; + final ui.SemanticsActionEvent decodedAction = arguments is ByteData + ? action.copyWith(arguments: const StandardMessageCodec().decodeMessage(arguments)) + : action; + performSemanticsAction(decodedAction); + } + + /// Called whenever the platform requests an action to be performed on a + /// [SemanticsNode]. + /// + /// This callback is invoked when a user interacts with the app via an + /// accessibility service (e.g. TalkBack and VoiceOver) and initiates an + /// action on the focused node. + /// + /// Bindings that mixin the [SemanticsBinding] must implement this method and + /// perform the given `action` on the [SemanticsNode] specified by + /// [SemanticsActionEvent.nodeId]. + /// + /// See [dart:ui.PlatformDispatcher.onSemanticsActionEvent]. + @protected + void performSemanticsAction(ui.SemanticsActionEvent action); + + /// The currently active set of [AccessibilityFeatures]. + /// + /// This is set when the binding is first initialized and updated whenever a + /// flag is changed. + /// + /// To listen to changes to accessibility features, create a + /// [WidgetsBindingObserver] and listen to + /// [WidgetsBindingObserver.didChangeAccessibilityFeatures]. + ui.AccessibilityFeatures get accessibilityFeatures => _accessibilityFeatures; + late ui.AccessibilityFeatures _accessibilityFeatures; + + /// Called when the platform accessibility features change. + /// + /// See [dart:ui.PlatformDispatcher.onAccessibilityFeaturesChanged]. + @protected + @mustCallSuper + void handleAccessibilityFeaturesChanged() { + _accessibilityFeatures = platformDispatcher.accessibilityFeatures; + } + + /// Creates an empty semantics update builder. + /// + /// The caller is responsible for filling out the semantics node updates. + /// + /// This method is used by the [SemanticsOwner] to create builder for all its + /// semantics updates. + ui.SemanticsUpdateBuilder createSemanticsUpdateBuilder() { + return ui.SemanticsUpdateBuilder(); + } + + /// The platform is requesting that animations be disabled or simplified. + /// + /// This setting can be overridden for testing or debugging by setting + /// [debugSemanticsDisableAnimations]. + bool get disableAnimations { + bool value = _accessibilityFeatures.disableAnimations; + assert(() { + if (debugSemanticsDisableAnimations != null) { + value = debugSemanticsDisableAnimations!; + } + return true; + }()); + return value; + } +} + +/// A reference to the semantics information generated by the framework. +/// +/// Semantics information are only collected when there are clients interested +/// in them. These clients express their interest by holding a +/// [SemanticsHandle]. When the client no longer needs the +/// semantics information, it must call [dispose] on the [SemanticsHandle] to +/// close it. When all open [SemanticsHandle]s are disposed, the framework will +/// stop updating the semantics information. +/// +/// To obtain a [SemanticsHandle], call [SemanticsBinding.ensureSemantics]. +class SemanticsHandle { + SemanticsHandle._(this._onDispose) { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/semantics.dart', + className: '$SemanticsHandle', + object: this, + ); + } + } + + final VoidCallback _onDispose; + + /// Closes the semantics handle. + /// + /// When all the outstanding [SemanticsHandle] objects are closed, the + /// framework will stop generating semantics information. + @mustCallSuper + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + + _onDispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/debug.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/debug.dart new file mode 100644 index 0000000000000000000000000000000000000000..dca4177f563b1fb7e5b9602e13a9c19ad5b75c2d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/debug.dart @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +/// Overrides the setting of [SemanticsBinding.disableAnimations] for debugging +/// and testing. +/// +/// This value is ignored in non-debug builds. +bool? debugSemanticsDisableAnimations; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/semantics.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/semantics.dart new file mode 100644 index 0000000000000000000000000000000000000000..b7aab9c21a64513c3d738e0154ef5f128cb762f8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/semantics.dart @@ -0,0 +1,5178 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show Offset, Rect, SemanticsAction, SemanticsFlag, SemanticsUpdate, SemanticsUpdateBuilder, StringAttribute, TextDirection; + +import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart' show MatrixUtils, TransformProperty; +import 'package:flutter/services.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'binding.dart' show SemanticsBinding; +import 'semantics_event.dart'; + +export 'dart:ui' show Offset, Rect, SemanticsAction, SemanticsFlag, StringAttribute, TextDirection, VoidCallback; + +export 'package:flutter/foundation.dart' show DiagnosticLevel, DiagnosticPropertiesBuilder, DiagnosticsNode, DiagnosticsTreeStyle, Key, TextTreeConfiguration; +export 'package:flutter/services.dart' show TextSelection; +export 'package:vector_math/vector_math_64.dart' show Matrix4; + +export 'semantics_event.dart' show SemanticsEvent; + +/// Signature for a function that is called for each [SemanticsNode]. +/// +/// Return false to stop visiting nodes. +/// +/// Used by [SemanticsNode.visitChildren]. +typedef SemanticsNodeVisitor = bool Function(SemanticsNode node); + +/// Signature for [SemanticsAction]s that move the cursor. +/// +/// If `extendSelection` is set to true the cursor movement should extend the +/// current selection or (if nothing is currently selected) start a selection. +typedef MoveCursorHandler = void Function(bool extendSelection); + +/// Signature for the [SemanticsAction.setSelection] handlers to change the +/// text selection (or re-position the cursor) to `selection`. +typedef SetSelectionHandler = void Function(TextSelection selection); + +/// Signature for the [SemanticsAction.setText] handlers to replace the +/// current text with the input `text`. +typedef SetTextHandler = void Function(String text); + +/// Signature for a handler of a [SemanticsAction]. +/// +/// Returned by [SemanticsConfiguration.getActionHandler]. +typedef SemanticsActionHandler = void Function(Object? args); + +/// Signature for a function that receives a semantics update and returns no result. +/// +/// Used by [SemanticsOwner.onSemanticsUpdate]. +typedef SemanticsUpdateCallback = void Function(SemanticsUpdate update); + +/// Signature for the [SemanticsConfiguration.childConfigurationsDelegate]. +/// +/// The input list contains all [SemanticsConfiguration]s that rendering +/// children want to merge upward. One can tag a render child with a +/// [SemanticsTag] and look up its [SemanticsConfiguration]s through +/// [SemanticsConfiguration.tagsChildrenWith]. +/// +/// The return value is the arrangement of these configs, including which +/// configs continue to merge upward and which configs form sibling merge group. +/// +/// Use [ChildSemanticsConfigurationsResultBuilder] to generate the return +/// value. +typedef ChildSemanticsConfigurationsDelegate = ChildSemanticsConfigurationsResult Function(List<SemanticsConfiguration>); + +final int _kUnblockedUserActions = SemanticsAction.didGainAccessibilityFocus.index + | SemanticsAction.didLoseAccessibilityFocus.index; + +/// A tag for a [SemanticsNode]. +/// +/// Tags can be interpreted by the parent of a [SemanticsNode] +/// and depending on the presence of a tag the parent can for example decide +/// how to add the tagged node as a child. Tags are not sent to the engine. +/// +/// As an example, the [RenderSemanticsGestureHandler] uses tags to determine +/// if a child node should be excluded from the scrollable area for semantic +/// purposes. +/// +/// The provided [name] is only used for debugging. Two tags created with the +/// same [name] and the `new` operator are not considered identical. However, +/// two tags created with the same [name] and the `const` operator are always +/// identical. +class SemanticsTag { + /// Creates a [SemanticsTag]. + /// + /// The provided [name] is only used for debugging. Two tags created with the + /// same [name] and the `new` operator are not considered identical. However, + /// two tags created with the same [name] and the `const` operator are always + /// identical. + const SemanticsTag(this.name); + + /// A human-readable name for this tag used for debugging. + /// + /// This string is not used to determine if two tags are identical. + final String name; + + @override + String toString() => '${objectRuntimeType(this, 'SemanticsTag')}($name)'; +} + +/// The result that contains the arrangement for the child +/// [SemanticsConfiguration]s. +/// +/// When the [PipelineOwner] builds the semantics tree, it uses the returned +/// [ChildSemanticsConfigurationsResult] from +/// [SemanticsConfiguration.childConfigurationsDelegate] to decide how semantics nodes +/// should form. +/// +/// Use [ChildSemanticsConfigurationsResultBuilder] to build the result. +class ChildSemanticsConfigurationsResult { + ChildSemanticsConfigurationsResult._(this.mergeUp, this.siblingMergeGroups); + + /// Returns the [SemanticsConfiguration]s that are supposed to be merged into + /// the parent semantics node. + /// + /// [SemanticsConfiguration]s that are either semantics boundaries or are + /// conflicting with other [SemanticsConfiguration]s will form explicit + /// semantics nodes. All others will be merged into the parent. + final List<SemanticsConfiguration> mergeUp; + + /// The groups of child semantics configurations that want to merge together + /// and form a sibling [SemanticsNode]. + /// + /// All the [SemanticsConfiguration]s in a given group that are either + /// semantics boundaries or are conflicting with other + /// [SemanticsConfiguration]s of the same group will be excluded from the + /// sibling merge group and form independent semantics nodes as usual. + /// + /// The result [SemanticsNode]s from the merges are attached as the sibling + /// nodes of the immediate parent semantics node. For example, a `RenderObjectA` + /// has a rendering child, `RenderObjectB`. If both of them form their own + /// semantics nodes, `SemanticsNodeA` and `SemanticsNodeB`, any semantics node + /// created from sibling merge groups of `RenderObjectB` will be attach to + /// `SemanticsNodeA` as a sibling of `SemanticsNodeB`. + final List<List<SemanticsConfiguration>> siblingMergeGroups; +} + +/// The builder to build a [ChildSemanticsConfigurationsResult] based on its +/// annotations. +/// +/// To use this builder, one can use [markAsMergeUp] and +/// [markAsSiblingMergeGroup] to annotate the arrangement of +/// [SemanticsConfiguration]s. Once all the configs are annotated, use [build] +/// to generate the [ChildSemanticsConfigurationsResult]. +class ChildSemanticsConfigurationsResultBuilder { + /// Creates a [ChildSemanticsConfigurationsResultBuilder]. + ChildSemanticsConfigurationsResultBuilder(); + + final List<SemanticsConfiguration> _mergeUp = <SemanticsConfiguration>[]; + final List<List<SemanticsConfiguration>> _siblingMergeGroups = <List<SemanticsConfiguration>>[]; + + /// Marks the [SemanticsConfiguration] to be merged into the parent semantics + /// node. + /// + /// The [SemanticsConfiguration] will be added to the + /// [ChildSemanticsConfigurationsResult.mergeUp] that this builder builds. + void markAsMergeUp(SemanticsConfiguration config) => _mergeUp.add(config); + + /// Marks a group of [SemanticsConfiguration]s to merge together + /// and form a sibling [SemanticsNode]. + /// + /// The group of [SemanticsConfiguration]s will be added to the + /// [ChildSemanticsConfigurationsResult.siblingMergeGroups] that this builder builds. + void markAsSiblingMergeGroup(List<SemanticsConfiguration> configs) => _siblingMergeGroups.add(configs); + + /// Builds a [ChildSemanticsConfigurationsResult] contains the arrangement. + ChildSemanticsConfigurationsResult build() { + assert((){ + final Set<SemanticsConfiguration> seenConfigs = <SemanticsConfiguration>{}; + for (final SemanticsConfiguration config in <SemanticsConfiguration>[..._mergeUp, ..._siblingMergeGroups.flattened]) { + assert( + seenConfigs.add(config), + 'Duplicated SemanticsConfigurations. This can happen if the same ' + 'SemanticsConfiguration was marked twice in markAsMergeUp and/or ' + 'markAsSiblingMergeGroup' + ); + } + return true; + }()); + return ChildSemanticsConfigurationsResult._(_mergeUp, _siblingMergeGroups); + } +} + +/// An identifier of a custom semantics action. +/// +/// Custom semantics actions can be provided to make complex user +/// interactions more accessible. For instance, if an application has a +/// drag-and-drop list that requires the user to press and hold an item +/// to move it, users interacting with the application using a hardware +/// switch may have difficulty. This can be made accessible by creating custom +/// actions and pairing them with handlers that move a list item up or down in +/// the list. +/// +/// In Android, these actions are presented in the local context menu. In iOS, +/// these are presented in the radial context menu. +/// +/// Localization and text direction do not automatically apply to the provided +/// label or hint. +/// +/// Instances of this class should either be instantiated with const or +/// new instances cached in static fields. +/// +/// See also: +/// +/// * [SemanticsProperties], where the handler for a custom action is provided. +@immutable +class CustomSemanticsAction { + /// Creates a new [CustomSemanticsAction]. + /// + /// The [label] must not be empty. + const CustomSemanticsAction({required String this.label}) + : assert(label != ''), + hint = null, + action = null; + + /// Creates a new [CustomSemanticsAction] that overrides a standard semantics + /// action. + /// + /// The [hint] must not be empty. + const CustomSemanticsAction.overridingAction({required String this.hint, required SemanticsAction this.action}) + : assert(hint != ''), + label = null; + + /// The user readable name of this custom semantics action. + final String? label; + + /// The hint description of this custom semantics action. + final String? hint; + + /// The standard semantics action this action replaces. + final SemanticsAction? action; + + @override + int get hashCode => Object.hash(label, hint, action); + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is CustomSemanticsAction + && other.label == label + && other.hint == hint + && other.action == action; + } + + @override + String toString() { + return 'CustomSemanticsAction(${_ids[this]}, label:$label, hint:$hint, action:$action)'; + } + + // Logic to assign a unique id to each custom action without requiring + // user specification. + static int _nextId = 0; + static final Map<int, CustomSemanticsAction> _actions = <int, CustomSemanticsAction>{}; + static final Map<CustomSemanticsAction, int> _ids = <CustomSemanticsAction, int>{}; + + /// Get the identifier for a given `action`. + static int getIdentifier(CustomSemanticsAction action) { + int? result = _ids[action]; + if (result == null) { + result = _nextId++; + _ids[action] = result; + _actions[result] = action; + } + return result; + } + + /// Get the `action` for a given identifier. + static CustomSemanticsAction? getAction(int id) { + return _actions[id]; + } + + /// Resets internal state between tests. Does nothing if asserts are disabled. + @visibleForTesting + static void resetForTests() { + assert(() { + _actions.clear(); + _ids.clear(); + _nextId = 0; + return true; + }()); + } +} + +/// A string that carries a list of [StringAttribute]s. +@immutable +class AttributedString { + /// Creates a attributed string. + /// + /// The [TextRange] in the [attributes] must be inside the length of the + /// [string]. + /// + /// The [attributes] must not be changed after the attributed string is + /// created. + AttributedString( + this.string, { + this.attributes = const <StringAttribute>[], + }) : assert(string.isNotEmpty || attributes.isEmpty), + assert(() { + for (final StringAttribute attribute in attributes) { + assert( + string.length >= attribute.range.start && + string.length >= attribute.range.end, + 'The range in $attribute is outside of the string $string', + ); + } + return true; + }()); + + /// The plain string stored in the attributed string. + final String string; + + /// The attributes this string carries. + /// + /// The list must not be modified after this string is created. + final List<StringAttribute> attributes; + + /// Returns a new [AttributedString] by concatenate the operands + /// + /// The string attribute list of the returned [AttributedString] will contains + /// the string attributes from both operands with updated text ranges. + AttributedString operator +(AttributedString other) { + if (string.isEmpty) { + return other; + } + if (other.string.isEmpty) { + return this; + } + + // None of the strings is empty. + final String newString = string + other.string; + final List<StringAttribute> newAttributes = List<StringAttribute>.of(attributes); + if (other.attributes.isNotEmpty) { + final int offset = string.length; + for (final StringAttribute attribute in other.attributes) { + final TextRange newRange = TextRange( + start: attribute.range.start + offset, + end: attribute.range.end + offset, + ); + final StringAttribute adjustedAttribute = attribute.copy(range: newRange); + newAttributes.add(adjustedAttribute); + } + } + return AttributedString(newString, attributes: newAttributes); + } + + /// Two [AttributedString]s are equal if their string and attributes are. + @override + bool operator ==(Object other) { + return other.runtimeType == runtimeType + && other is AttributedString + && other.string == string + && listEquals<StringAttribute>(other.attributes, attributes); + } + + @override + int get hashCode => Object.hash(string, attributes); + + @override + String toString() { + return "${objectRuntimeType(this, 'AttributedString')}('$string', attributes: $attributes)"; + } +} + +/// A [DiagnosticsProperty] for [AttributedString]s, which shows a string +/// when there are no attributes, and more details otherwise. +class AttributedStringProperty extends DiagnosticsProperty<AttributedString> { + /// Create a diagnostics property for an [AttributedString] object. + /// + /// Such properties are used with [SemanticsData] objects. + AttributedStringProperty( + String super.name, + super.value, { + super.showName, + this.showWhenEmpty = false, + super.defaultValue, + super.level, + super.description, + }); + + /// Whether to show the property when the [value] is an [AttributedString] + /// whose [AttributedString.string] is the empty string. + /// + /// This overrides [defaultValue]. + final bool showWhenEmpty; + + @override + bool get isInteresting => super.isInteresting && (showWhenEmpty || (value != null && value!.string.isNotEmpty)); + + @override + String valueToString({TextTreeConfiguration? parentConfiguration}) { + if (value == null) { + return 'null'; + } + String text = value!.string; + if (parentConfiguration != null && + !parentConfiguration.lineBreakProperties) { + // This follows a similar pattern to StringProperty. + text = text.replaceAll('\n', r'\n'); + } + if (value!.attributes.isEmpty) { + return '"$text"'; + } + return '"$text" ${value!.attributes}'; // the attributes will be in square brackets since they're a list + } +} + +/// Summary information about a [SemanticsNode] object. +/// +/// A semantics node might [SemanticsNode.mergeAllDescendantsIntoThisNode], +/// which means the individual fields on the semantics node don't fully describe +/// the semantics at that node. This data structure contains the full semantics +/// for the node. +/// +/// Typically obtained from [SemanticsNode.getSemanticsData]. +@immutable +class SemanticsData with Diagnosticable { + /// Creates a semantics data object. + /// + /// If [label] is not empty, then [textDirection] must also not be null. + SemanticsData({ + required this.flags, + required this.actions, + required this.identifier, + required this.attributedLabel, + required this.attributedValue, + required this.attributedIncreasedValue, + required this.attributedDecreasedValue, + required this.attributedHint, + required this.tooltip, + required this.textDirection, + required this.rect, + required this.elevation, + required this.thickness, + required this.textSelection, + required this.scrollIndex, + required this.scrollChildCount, + required this.scrollPosition, + required this.scrollExtentMax, + required this.scrollExtentMin, + required this.platformViewId, + required this.maxValueLength, + required this.currentValueLength, + this.tags, + this.transform, + this.customSemanticsActionIds, + }) : assert(tooltip == '' || textDirection != null, 'A SemanticsData object with tooltip "$tooltip" had a null textDirection.'), + assert(attributedLabel.string == '' || textDirection != null, 'A SemanticsData object with label "${attributedLabel.string}" had a null textDirection.'), + assert(attributedValue.string == '' || textDirection != null, 'A SemanticsData object with value "${attributedValue.string}" had a null textDirection.'), + assert(attributedDecreasedValue.string == '' || textDirection != null, 'A SemanticsData object with decreasedValue "${attributedDecreasedValue.string}" had a null textDirection.'), + assert(attributedIncreasedValue.string == '' || textDirection != null, 'A SemanticsData object with increasedValue "${attributedIncreasedValue.string}" had a null textDirection.'), + assert(attributedHint.string == '' || textDirection != null, 'A SemanticsData object with hint "${attributedHint.string}" had a null textDirection.'); + + /// A bit field of [SemanticsFlag]s that apply to this node. + final int flags; + + /// A bit field of [SemanticsAction]s that apply to this node. + final int actions; + + /// {@macro flutter.semantics.SemanticsProperties.identifier} + final String identifier; + + /// A textual description for the current label of the node. + /// + /// The reading direction is given by [textDirection]. + /// + /// This exposes the raw text of the [attributedLabel]. + String get label => attributedLabel.string; + + /// A textual description for the current label of the node in + /// [AttributedString] format. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also [label], which exposes just the raw text. + final AttributedString attributedLabel; + + /// A textual description for the current value of the node. + /// + /// The reading direction is given by [textDirection]. + /// + /// This exposes the raw text of the [attributedValue]. + String get value => attributedValue.string; + + /// A textual description for the current value of the node in + /// [AttributedString] format. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also [value], which exposes just the raw text. + final AttributedString attributedValue; + + /// The value that [value] will become after performing a + /// [SemanticsAction.increase] action. + /// + /// The reading direction is given by [textDirection]. + /// + /// This exposes the raw text of the [attributedIncreasedValue]. + String get increasedValue => attributedIncreasedValue.string; + + /// The value that [value] will become after performing a + /// [SemanticsAction.increase] action in [AttributedString] format. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also [increasedValue], which exposes just the raw text. + final AttributedString attributedIncreasedValue; + + /// The value that [value] will become after performing a + /// [SemanticsAction.decrease] action. + /// + /// The reading direction is given by [textDirection]. + /// + /// This exposes the raw text of the [attributedDecreasedValue]. + String get decreasedValue => attributedDecreasedValue.string; + + /// The value that [value] will become after performing a + /// [SemanticsAction.decrease] action in [AttributedString] format. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also [decreasedValue], which exposes just the raw text. + final AttributedString attributedDecreasedValue; + + /// A brief description of the result of performing an action on this node. + /// + /// The reading direction is given by [textDirection]. + /// + /// This exposes the raw text of the [attributedHint]. + String get hint => attributedHint.string; + + /// A brief description of the result of performing an action on this node + /// in [AttributedString] format. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also [hint], which exposes just the raw text. + final AttributedString attributedHint; + + /// A textual description of the widget's tooltip. + /// + /// The reading direction is given by [textDirection]. + final String tooltip; + + /// The reading direction for the text in [label], [value], + /// [increasedValue], [decreasedValue], and [hint]. + final TextDirection? textDirection; + + /// The currently selected text (or the position of the cursor) within [value] + /// if this node represents a text field. + final TextSelection? textSelection; + + /// The total number of scrollable children that contribute to semantics. + /// + /// If the number of children are unknown or unbounded, this value will be + /// null. + final int? scrollChildCount; + + /// The index of the first visible semantic child of a scroll node. + final int? scrollIndex; + + /// Indicates the current scrolling position in logical pixels if the node is + /// scrollable. + /// + /// The properties [scrollExtentMin] and [scrollExtentMax] indicate the valid + /// in-range values for this property. The value for [scrollPosition] may + /// (temporarily) be outside that range, e.g. during an overscroll. + /// + /// See also: + /// + /// * [ScrollPosition.pixels], from where this value is usually taken. + final double? scrollPosition; + + /// Indicates the maximum in-range value for [scrollPosition] if the node is + /// scrollable. + /// + /// This value may be infinity if the scroll is unbound. + /// + /// See also: + /// + /// * [ScrollPosition.maxScrollExtent], from where this value is usually taken. + final double? scrollExtentMax; + + /// Indicates the minimum in-range value for [scrollPosition] if the node is + /// scrollable. + /// + /// This value may be infinity if the scroll is unbound. + /// + /// See also: + /// + /// * [ScrollPosition.minScrollExtent], from where this value is usually taken. + final double? scrollExtentMin; + + /// The id of the platform view, whose semantics nodes will be added as + /// children to this node. + /// + /// If this value is non-null, the SemanticsNode must not have any children + /// as those would be replaced by the semantics nodes of the referenced + /// platform view. + /// + /// See also: + /// + /// * [AndroidView], which is the platform view for Android. + /// * [UiKitView], which is the platform view for iOS. + final int? platformViewId; + + /// The maximum number of characters that can be entered into an editable + /// text field. + /// + /// For the purpose of this function a character is defined as one Unicode + /// scalar value. + /// + /// This should only be set when [SemanticsFlag.isTextField] is set. Defaults + /// to null, which means no limit is imposed on the text field. + final int? maxValueLength; + + /// The current number of characters that have been entered into an editable + /// text field. + /// + /// For the purpose of this function a character is defined as one Unicode + /// scalar value. + /// + /// This should only be set when [SemanticsFlag.isTextField] is set. This must + /// be set when [maxValueLength] is set. + final int? currentValueLength; + + /// The bounding box for this node in its coordinate system. + final Rect rect; + + /// The set of [SemanticsTag]s associated with this node. + final Set<SemanticsTag>? tags; + + /// The transform from this node's coordinate system to its parent's coordinate system. + /// + /// By default, the transform is null, which represents the identity + /// transformation (i.e., that this node has the same coordinate system as its + /// parent). + final Matrix4? transform; + + /// The elevation of this node relative to the parent semantics node. + /// + /// See also: + /// + /// * [SemanticsConfiguration.elevation] for a detailed discussion regarding + /// elevation and semantics. + final double elevation; + + /// The extent of this node along the z-axis beyond its [elevation] + /// + /// See also: + /// + /// * [SemanticsConfiguration.thickness] for a more detailed definition. + final double thickness; + + /// The identifiers for the custom semantics actions and standard action + /// overrides for this node. + /// + /// The list must be sorted in increasing order. + /// + /// See also: + /// + /// * [CustomSemanticsAction], for an explanation of custom actions. + final List<int>? customSemanticsActionIds; + + /// Whether [flags] contains the given flag. + bool hasFlag(SemanticsFlag flag) => (flags & flag.index) != 0; + + /// Whether [actions] contains the given action. + bool hasAction(SemanticsAction action) => (actions & action.index) != 0; + + @override + String toStringShort() => objectRuntimeType(this, 'SemanticsData'); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Rect>('rect', rect, showName: false)); + properties.add(TransformProperty('transform', transform, showName: false, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: 0.0)); + properties.add(DoubleProperty('thickness', thickness, defaultValue: 0.0)); + final List<String> actionSummary = <String>[ + for (final SemanticsAction action in SemanticsAction.values) + if ((actions & action.index) != 0) + action.name, + ]; + final List<String?> customSemanticsActionSummary = customSemanticsActionIds! + .map<String?>((int actionId) => CustomSemanticsAction.getAction(actionId)!.label) + .toList(); + properties.add(IterableProperty<String>('actions', actionSummary, ifEmpty: null)); + properties.add(IterableProperty<String?>('customActions', customSemanticsActionSummary, ifEmpty: null)); + + final List<String> flagSummary = <String>[ + for (final SemanticsFlag flag in SemanticsFlag.values) + if ((flags & flag.index) != 0) + flag.name, + ]; + properties.add(IterableProperty<String>('flags', flagSummary, ifEmpty: null)); + properties.add(StringProperty('identifier', identifier, defaultValue: '')); + properties.add(AttributedStringProperty('label', attributedLabel)); + properties.add(AttributedStringProperty('value', attributedValue)); + properties.add(AttributedStringProperty('increasedValue', attributedIncreasedValue)); + properties.add(AttributedStringProperty('decreasedValue', attributedDecreasedValue)); + properties.add(AttributedStringProperty('hint', attributedHint)); + properties.add(StringProperty('tooltip', tooltip, defaultValue: '')); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + if (textSelection?.isValid ?? false) { + properties.add(MessageProperty('textSelection', '[${textSelection!.start}, ${textSelection!.end}]')); + } + properties.add(IntProperty('platformViewId', platformViewId, defaultValue: null)); + properties.add(IntProperty('maxValueLength', maxValueLength, defaultValue: null)); + properties.add(IntProperty('currentValueLength', currentValueLength, defaultValue: null)); + properties.add(IntProperty('scrollChildren', scrollChildCount, defaultValue: null)); + properties.add(IntProperty('scrollIndex', scrollIndex, defaultValue: null)); + properties.add(DoubleProperty('scrollExtentMin', scrollExtentMin, defaultValue: null)); + properties.add(DoubleProperty('scrollPosition', scrollPosition, defaultValue: null)); + properties.add(DoubleProperty('scrollExtentMax', scrollExtentMax, defaultValue: null)); + } + + @override + bool operator ==(Object other) { + return other is SemanticsData + && other.flags == flags + && other.actions == actions + && other.identifier == identifier + && other.attributedLabel == attributedLabel + && other.attributedValue == attributedValue + && other.attributedIncreasedValue == attributedIncreasedValue + && other.attributedDecreasedValue == attributedDecreasedValue + && other.attributedHint == attributedHint + && other.tooltip == tooltip + && other.textDirection == textDirection + && other.rect == rect + && setEquals(other.tags, tags) + && other.scrollChildCount == scrollChildCount + && other.scrollIndex == scrollIndex + && other.textSelection == textSelection + && other.scrollPosition == scrollPosition + && other.scrollExtentMax == scrollExtentMax + && other.scrollExtentMin == scrollExtentMin + && other.platformViewId == platformViewId + && other.maxValueLength == maxValueLength + && other.currentValueLength == currentValueLength + && other.transform == transform + && other.elevation == elevation + && other.thickness == thickness + && _sortedListsEqual(other.customSemanticsActionIds, customSemanticsActionIds); + } + + @override + int get hashCode => Object.hash( + flags, + actions, + identifier, + attributedLabel, + attributedValue, + attributedIncreasedValue, + attributedDecreasedValue, + attributedHint, + tooltip, + textDirection, + rect, + tags, + textSelection, + scrollChildCount, + scrollIndex, + scrollPosition, + scrollExtentMax, + scrollExtentMin, + platformViewId, + Object.hash( + maxValueLength, + currentValueLength, + transform, + elevation, + thickness, + customSemanticsActionIds == null ? null : Object.hashAll(customSemanticsActionIds!), + ), + ); + + static bool _sortedListsEqual(List<int>? left, List<int>? right) { + if (left == null && right == null) { + return true; + } + if (left != null && right != null) { + if (left.length != right.length) { + return false; + } + for (int i = 0; i < left.length; i++) { + if (left[i] != right[i]) { + return false; + } + } + return true; + } + return false; + } +} + +class _SemanticsDiagnosticableNode extends DiagnosticableNode<SemanticsNode> { + _SemanticsDiagnosticableNode({ + super.name, + required super.value, + required super.style, + required this.childOrder, + }); + + final DebugSemanticsDumpOrder childOrder; + + @override + List<DiagnosticsNode> getChildren() => value.debugDescribeChildren(childOrder: childOrder); +} + +/// Provides hint values which override the default hints on supported +/// platforms. +/// +/// On iOS, these values are always ignored. +@immutable +class SemanticsHintOverrides extends DiagnosticableTree { + /// Creates a semantics hint overrides. + const SemanticsHintOverrides({ + this.onTapHint, + this.onLongPressHint, + }) : assert(onTapHint != ''), + assert(onLongPressHint != ''); + + /// The hint text for a tap action. + /// + /// If null, the standard hint is used instead. + /// + /// The hint should describe what happens when a tap occurs, not the + /// manner in which a tap is accomplished. + /// + /// Bad: 'Double tap to show movies'. + /// Good: 'show movies'. + final String? onTapHint; + + /// The hint text for a long press action. + /// + /// If null, the standard hint is used instead. + /// + /// The hint should describe what happens when a long press occurs, not + /// the manner in which the long press is accomplished. + /// + /// Bad: 'Double tap and hold to show tooltip'. + /// Good: 'show tooltip'. + final String? onLongPressHint; + + /// Whether there are any non-null hint values. + bool get isNotEmpty => onTapHint != null || onLongPressHint != null; + + @override + int get hashCode => Object.hash(onTapHint, onLongPressHint); + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is SemanticsHintOverrides + && other.onTapHint == onTapHint + && other.onLongPressHint == onLongPressHint; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('onTapHint', onTapHint, defaultValue: null)); + properties.add(StringProperty('onLongPressHint', onLongPressHint, defaultValue: null)); + } +} + +/// Contains properties used by assistive technologies to make the application +/// more accessible. +/// +/// The properties of this class are used to generate a [SemanticsNode]s in the +/// semantics tree. +@immutable +class SemanticsProperties extends DiagnosticableTree { + /// Creates a semantic annotation. + const SemanticsProperties({ + this.enabled, + this.checked, + this.mixed, + this.expanded, + this.selected, + this.toggled, + this.button, + this.link, + this.header, + this.textField, + this.slider, + this.keyboardKey, + this.readOnly, + this.focusable, + this.focused, + this.inMutuallyExclusiveGroup, + this.hidden, + this.obscured, + this.multiline, + this.scopesRoute, + this.namesRoute, + this.image, + this.liveRegion, + this.maxValueLength, + this.currentValueLength, + this.identifier, + this.label, + this.attributedLabel, + this.value, + this.attributedValue, + this.increasedValue, + this.attributedIncreasedValue, + this.decreasedValue, + this.attributedDecreasedValue, + this.hint, + this.tooltip, + this.attributedHint, + this.hintOverrides, + this.textDirection, + this.sortKey, + this.tagForChildren, + this.onTap, + this.onLongPress, + this.onScrollLeft, + this.onScrollRight, + this.onScrollUp, + this.onScrollDown, + this.onIncrease, + this.onDecrease, + this.onCopy, + this.onCut, + this.onPaste, + this.onMoveCursorForwardByCharacter, + this.onMoveCursorBackwardByCharacter, + this.onMoveCursorForwardByWord, + this.onMoveCursorBackwardByWord, + this.onSetSelection, + this.onSetText, + this.onDidGainAccessibilityFocus, + this.onDidLoseAccessibilityFocus, + this.onDismiss, + this.customSemanticsActions, + }) : assert(label == null || attributedLabel == null, 'Only one of label or attributedLabel should be provided'), + assert(value == null || attributedValue == null, 'Only one of value or attributedValue should be provided'), + assert(increasedValue == null || attributedIncreasedValue == null, 'Only one of increasedValue or attributedIncreasedValue should be provided'), + assert(decreasedValue == null || attributedDecreasedValue == null, 'Only one of decreasedValue or attributedDecreasedValue should be provided'), + assert(hint == null || attributedHint == null, 'Only one of hint or attributedHint should be provided'); + + /// If non-null, indicates that this subtree represents something that can be + /// in an enabled or disabled state. + /// + /// For example, a button that a user can currently interact with would set + /// this field to true. A button that currently does not respond to user + /// interactions would set this field to false. + final bool? enabled; + + /// If non-null, indicates that this subtree represents a checkbox + /// or similar widget with a "checked" state, and what its current + /// state is. + /// + /// When the [Checkbox.value] of a tristate Checkbox is null, + /// indicating a mixed-state, this value shall be false, in which + /// case, [mixed] will be true. + /// + /// This is mutually exclusive with [toggled] and [mixed]. + final bool? checked; + + /// If non-null, indicates that this subtree represents a checkbox + /// or similar widget with a "half-checked" state or similar, and + /// whether it is currently in this half-checked state. + /// + /// This must be null when [Checkbox.tristate] is false, or + /// when the widget is not a checkbox. When a tristate + /// checkbox is fully unchecked/checked, this value shall + /// be false. + /// + /// This is mutually exclusive with [checked] and [toggled]. + final bool? mixed; + + /// If non-null, indicates that this subtree represents something + /// that can be in an "expanded" or "collapsed" state. + /// + /// For example, if a [SubmenuButton] is opened, this property + /// should be set to true; otherwise, this property should be + /// false. + final bool? expanded; + + /// If non-null, indicates that this subtree represents a toggle switch + /// or similar widget with an "on" state, and what its current + /// state is. + /// + /// This is mutually exclusive with [checked] and [mixed]. + final bool? toggled; + + /// If non-null indicates that this subtree represents something that can be + /// in a selected or unselected state, and what its current state is. + /// + /// The active tab in a tab bar for example is considered "selected", whereas + /// all other tabs are unselected. + final bool? selected; + + /// If non-null, indicates that this subtree represents a button. + /// + /// TalkBack/VoiceOver provides users with the hint "button" when a button + /// is focused. + final bool? button; + + /// If non-null, indicates that this subtree represents a link. + /// + /// iOS's VoiceOver provides users with a unique hint when a link is focused. + /// Android's Talkback will announce a link hint the same way it does a + /// button. + final bool? link; + + /// If non-null, indicates that this subtree represents a header. + /// + /// A header divides into sections. For example, an address book application + /// might define headers A, B, C, etc. to divide the list of alphabetically + /// sorted contacts into sections. + final bool? header; + + /// If non-null, indicates that this subtree represents a text field. + /// + /// TalkBack/VoiceOver provide special affordances to enter text into a + /// text field. + final bool? textField; + + /// If non-null, indicates that this subtree represents a slider. + /// + /// Talkback/\VoiceOver provides users with the hint "slider" when a + /// slider is focused. + final bool? slider; + + /// If non-null, indicates that this subtree represents a keyboard key. + final bool? keyboardKey; + + /// If non-null, indicates that this subtree is read only. + /// + /// Only applicable when [textField] is true. + /// + /// TalkBack/VoiceOver will treat it as non-editable text field. + final bool? readOnly; + + /// If non-null, whether the node is able to hold input focus. + /// + /// If [focusable] is set to false, then [focused] must not be true. + /// + /// Input focus indicates that the node will receive keyboard events. It is not + /// to be confused with accessibility focus. Accessibility focus is the + /// green/black rectangular highlight that TalkBack/VoiceOver draws around the + /// element it is reading, and is separate from input focus. + final bool? focusable; + + /// If non-null, whether the node currently holds input focus. + /// + /// At most one node in the tree should hold input focus at any point in time, + /// and it should not be set to true if [focusable] is false. + /// + /// Input focus indicates that the node will receive keyboard events. It is not + /// to be confused with accessibility focus. Accessibility focus is the + /// green/black rectangular highlight that TalkBack/VoiceOver draws around the + /// element it is reading, and is separate from input focus. + final bool? focused; + + /// If non-null, whether a semantic node is in a mutually exclusive group. + /// + /// For example, a radio button is in a mutually exclusive group because only + /// one radio button in that group can be marked as [checked]. + final bool? inMutuallyExclusiveGroup; + + /// If non-null, whether the node is considered hidden. + /// + /// Hidden elements are currently not visible on screen. They may be covered + /// by other elements or positioned outside of the visible area of a viewport. + /// + /// Hidden elements cannot gain accessibility focus though regular touch. The + /// only way they can be focused is by moving the focus to them via linear + /// navigation. + /// + /// Platforms are free to completely ignore hidden elements and new platforms + /// are encouraged to do so. + /// + /// Instead of marking an element as hidden it should usually be excluded from + /// the semantics tree altogether. Hidden elements are only included in the + /// semantics tree to work around platform limitations and they are mainly + /// used to implement accessibility scrolling on iOS. + final bool? hidden; + + /// If non-null, whether [value] should be obscured. + /// + /// This option is usually set in combination with [textField] to indicate + /// that the text field contains a password (or other sensitive information). + /// Doing so instructs screen readers to not read out the [value]. + final bool? obscured; + + /// Whether the [value] is coming from a field that supports multiline text + /// editing. + /// + /// This option is only meaningful when [textField] is true to indicate + /// whether it's a single-line or multiline text field. + /// + /// This option is null when [textField] is false. + final bool? multiline; + + /// If non-null, whether the node corresponds to the root of a subtree for + /// which a route name should be announced. + /// + /// Generally, this is set in combination with + /// [SemanticsConfiguration.explicitChildNodes], since nodes with this flag + /// are not considered focusable by Android or iOS. + /// + /// See also: + /// + /// * [SemanticsFlag.scopesRoute] for a description of how the announced + /// value is selected. + final bool? scopesRoute; + + /// If non-null, whether the node contains the semantic label for a route. + /// + /// See also: + /// + /// * [SemanticsFlag.namesRoute] for a description of how the name is used. + final bool? namesRoute; + + /// If non-null, whether the node represents an image. + /// + /// See also: + /// + /// * [SemanticsFlag.isImage], for the flag this setting controls. + final bool? image; + + /// If non-null, whether the node should be considered a live region. + /// + /// A live region indicates that updates to semantics node are important. + /// Platforms may use this information to make polite announcements to the + /// user to inform them of updates to this node. + /// + /// An example of a live region is a [SnackBar] widget. On Android and iOS, + /// live region causes a polite announcement to be generated automatically, + /// even if the widget does not have accessibility focus. This announcement + /// may not be spoken if the OS accessibility services are already + /// announcing something else, such as reading the label of a focused widget + /// or providing a system announcement. + /// + /// See also: + /// + /// * [SemanticsFlag.isLiveRegion], the semantics flag this setting controls. + /// * [SemanticsConfiguration.liveRegion], for a full description of a live region. + final bool? liveRegion; + + /// The maximum number of characters that can be entered into an editable + /// text field. + /// + /// For the purpose of this function a character is defined as one Unicode + /// scalar value. + /// + /// This should only be set when [textField] is true. Defaults to null, + /// which means no limit is imposed on the text field. + final int? maxValueLength; + + /// The current number of characters that have been entered into an editable + /// text field. + /// + /// For the purpose of this function a character is defined as one Unicode + /// scalar value. + /// + /// This should only be set when [textField] is true. Must be set when + /// [maxValueLength] is set. + final int? currentValueLength; + + /// {@template flutter.semantics.SemanticsProperties.identifier} + /// Provides an identifier for the semantics node in native accessibility hierarchy. + /// + /// This value is not exposed to the users of the app. + /// + /// It's usually used for UI testing with tools that work by querying the + /// native accessibility, like UIAutomator, XCUITest, or Appium. + /// + /// On Android, this is used for `AccessibilityNodeInfo.setViewIdResourceName`. + /// It'll be appear in accessibility hierarchy as `resource-id`. + /// + /// On iOS, this will set `UIAccessibilityElement.accessibilityIdentifier`. + /// {@endtemplate} + final String? identifier; + + /// Provides a textual description of the widget. + /// + /// If a label is provided, there must either by an ambient [Directionality] + /// or an explicit [textDirection] should be provided. + /// + /// Callers must not provide both [label] and [attributedLabel]. One or both + /// must be null. + /// + /// See also: + /// + /// * [SemanticsConfiguration.label] for a description of how this is exposed + /// in TalkBack and VoiceOver. + /// * [attributedLabel] for an [AttributedString] version of this property. + final String? label; + + /// Provides an [AttributedString] version of textual description of the widget. + /// + /// If a [attributedLabel] is provided, there must either by an ambient + /// [Directionality] or an explicit [textDirection] should be provided. + /// + /// Callers must not provide both [label] and [attributedLabel]. One or both + /// must be null. + /// + /// See also: + /// + /// * [SemanticsConfiguration.attributedLabel] for a description of how this + /// is exposed in TalkBack and VoiceOver. + /// * [label] for a plain string version of this property. + final AttributedString? attributedLabel; + + /// Provides a textual description of the value of the widget. + /// + /// If a value is provided, there must either by an ambient [Directionality] + /// or an explicit [textDirection] should be provided. + /// + /// Callers must not provide both [value] and [attributedValue], One or both + /// must be null. + /// + /// See also: + /// + /// * [SemanticsConfiguration.value] for a description of how this is exposed + /// in TalkBack and VoiceOver. + /// * [attributedLabel] for an [AttributedString] version of this property. + final String? value; + + /// Provides an [AttributedString] version of textual description of the value + /// of the widget. + /// + /// If a [attributedValue] is provided, there must either by an ambient + /// [Directionality] or an explicit [textDirection] should be provided. + /// + /// Callers must not provide both [value] and [attributedValue], One or both + /// must be null. + /// + /// See also: + /// + /// * [SemanticsConfiguration.attributedValue] for a description of how this + /// is exposed in TalkBack and VoiceOver. + /// * [value] for a plain string version of this property. + final AttributedString? attributedValue; + + /// The value that [value] or [attributedValue] will become after a + /// [SemanticsAction.increase] action has been performed on this widget. + /// + /// If a value is provided, [onIncrease] must also be set and there must + /// either be an ambient [Directionality] or an explicit [textDirection] + /// must be provided. + /// + /// Callers must not provide both [increasedValue] and + /// [attributedIncreasedValue], One or both must be null. + /// + /// See also: + /// + /// * [SemanticsConfiguration.increasedValue] for a description of how this + /// is exposed in TalkBack and VoiceOver. + /// * [attributedIncreasedValue] for an [AttributedString] version of this + /// property. + final String? increasedValue; + + /// The [AttributedString] that [value] or [attributedValue] will become after + /// a [SemanticsAction.increase] action has been performed on this widget. + /// + /// If a [attributedIncreasedValue] is provided, [onIncrease] must also be set + /// and there must either be an ambient [Directionality] or an explicit + /// [textDirection] must be provided. + /// + /// Callers must not provide both [increasedValue] and + /// [attributedIncreasedValue], One or both must be null. + /// + /// See also: + /// + /// * [SemanticsConfiguration.attributedIncreasedValue] for a description of + /// how this is exposed in TalkBack and VoiceOver. + /// * [increasedValue] for a plain string version of this property. + final AttributedString? attributedIncreasedValue; + + /// The value that [value] or [attributedValue] will become after a + /// [SemanticsAction.decrease] action has been performed on this widget. + /// + /// If a value is provided, [onDecrease] must also be set and there must + /// either be an ambient [Directionality] or an explicit [textDirection] + /// must be provided. + /// + /// Callers must not provide both [decreasedValue] and + /// [attributedDecreasedValue], One or both must be null. + /// + /// See also: + /// + /// * [SemanticsConfiguration.decreasedValue] for a description of how this + /// is exposed in TalkBack and VoiceOver. + /// * [attributedDecreasedValue] for an [AttributedString] version of this + /// property. + final String? decreasedValue; + + /// The [AttributedString] that [value] or [attributedValue] will become after + /// a [SemanticsAction.decrease] action has been performed on this widget. + /// + /// If a [attributedDecreasedValue] is provided, [onDecrease] must also be set + /// and there must either be an ambient [Directionality] or an explicit + /// [textDirection] must be provided. + /// + /// Callers must not provide both [decreasedValue] and + /// [attributedDecreasedValue], One or both must be null/// provided. + /// + /// See also: + /// + /// * [SemanticsConfiguration.attributedDecreasedValue] for a description of + /// how this is exposed in TalkBack and VoiceOver. + /// * [decreasedValue] for a plain string version of this property. + final AttributedString? attributedDecreasedValue; + + /// Provides a brief textual description of the result of an action performed + /// on the widget. + /// + /// If a hint is provided, there must either be an ambient [Directionality] + /// or an explicit [textDirection] should be provided. + /// + /// Callers must not provide both [hint] and [attributedHint], One or both + /// must be null. + /// + /// See also: + /// + /// * [SemanticsConfiguration.hint] for a description of how this is exposed + /// in TalkBack and VoiceOver. + /// * [attributedHint] for an [AttributedString] version of this property. + final String? hint; + + /// Provides an [AttributedString] version of brief textual description of the + /// result of an action performed on the widget. + /// + /// If a [attributedHint] is provided, there must either by an ambient + /// [Directionality] or an explicit [textDirection] should be provided. + /// + /// Callers must not provide both [hint] and [attributedHint], One or both + /// must be null. + /// + /// See also: + /// + /// * [SemanticsConfiguration.attributedHint] for a description of how this + /// is exposed in TalkBack and VoiceOver. + /// * [hint] for a plain string version of this property. + final AttributedString? attributedHint; + + /// Provides a textual description of the widget's tooltip. + /// + /// In Android, this property sets the `AccessibilityNodeInfo.setTooltipText`. + /// In iOS, this property is appended to the end of the + /// `UIAccessibilityElement.accessibilityLabel`. + /// + /// If a [tooltip] is provided, there must either by an ambient + /// [Directionality] or an explicit [textDirection] should be provided. + final String? tooltip; + + /// Provides hint values which override the default hints on supported + /// platforms. + /// + /// On Android, If no hint overrides are used then default [hint] will be + /// combined with the [label]. Otherwise, the [hint] will be ignored as long + /// as there as at least one non-null hint override. + /// + /// On iOS, these are always ignored and the default [hint] is used instead. + final SemanticsHintOverrides? hintOverrides; + + /// The reading direction of the [label], [value], [increasedValue], + /// [decreasedValue], and [hint]. + /// + /// Defaults to the ambient [Directionality]. + final TextDirection? textDirection; + + /// Determines the position of this node among its siblings in the traversal + /// sort order. + /// + /// This is used to describe the order in which the semantic node should be + /// traversed by the accessibility services on the platform (e.g. VoiceOver + /// on iOS and TalkBack on Android). + final SemanticsSortKey? sortKey; + + /// A tag to be applied to the child [SemanticsNode]s of this widget. + /// + /// The tag is added to all child [SemanticsNode]s that pass through the + /// [RenderObject] corresponding to this widget while looking to be attached + /// to a parent SemanticsNode. + /// + /// Tags are used to communicate to a parent SemanticsNode that a child + /// SemanticsNode was passed through a particular RenderObject. The parent can + /// use this information to determine the shape of the semantics tree. + /// + /// See also: + /// + /// * [SemanticsConfiguration.addTagForChildren], to which the tags provided + /// here will be passed. + final SemanticsTag? tagForChildren; + + /// The handler for [SemanticsAction.tap]. + /// + /// This is the semantic equivalent of a user briefly tapping the screen with + /// the finger without moving it. For example, a button should implement this + /// action. + /// + /// VoiceOver users on iOS and TalkBack users on Android *may* trigger this + /// action by double-tapping the screen while an element is focused. + /// + /// Note: different OSes or assistive technologies may decide to interpret + /// user inputs differently. Some may simulate real screen taps, while others + /// may call semantics tap. One way to handle taps properly is to provide the + /// same handler to both gesture tap and semantics tap. + final VoidCallback? onTap; + + /// The handler for [SemanticsAction.longPress]. + /// + /// This is the semantic equivalent of a user pressing and holding the screen + /// with the finger for a few seconds without moving it. + /// + /// VoiceOver users on iOS and TalkBack users on Android *may* trigger this + /// action by double-tapping the screen without lifting the finger after the + /// second tap. + /// + /// Note: different OSes or assistive technologies may decide to interpret + /// user inputs differently. Some may simulate real long presses, while others + /// may call semantics long press. One way to handle long press properly is to + /// provide the same handler to both gesture long press and semantics long + /// press. + final VoidCallback? onLongPress; + + /// The handler for [SemanticsAction.scrollLeft]. + /// + /// This is the semantic equivalent of a user moving their finger across the + /// screen from right to left. It should be recognized by controls that are + /// horizontally scrollable. + /// + /// VoiceOver users on iOS can trigger this action by swiping left with three + /// fingers. TalkBack users on Android can trigger this action by swiping + /// right and then left in one motion path. On Android, [onScrollUp] and + /// [onScrollLeft] share the same gesture. Therefore, only on of them should + /// be provided. + final VoidCallback? onScrollLeft; + + /// The handler for [SemanticsAction.scrollRight]. + /// + /// This is the semantic equivalent of a user moving their finger across the + /// screen from left to right. It should be recognized by controls that are + /// horizontally scrollable. + /// + /// VoiceOver users on iOS can trigger this action by swiping right with three + /// fingers. TalkBack users on Android can trigger this action by swiping + /// left and then right in one motion path. On Android, [onScrollDown] and + /// [onScrollRight] share the same gesture. Therefore, only on of them should + /// be provided. + final VoidCallback? onScrollRight; + + /// The handler for [SemanticsAction.scrollUp]. + /// + /// This is the semantic equivalent of a user moving their finger across the + /// screen from bottom to top. It should be recognized by controls that are + /// vertically scrollable. + /// + /// VoiceOver users on iOS can trigger this action by swiping up with three + /// fingers. TalkBack users on Android can trigger this action by swiping + /// right and then left in one motion path. On Android, [onScrollUp] and + /// [onScrollLeft] share the same gesture. Therefore, only on of them should + /// be provided. + final VoidCallback? onScrollUp; + + /// The handler for [SemanticsAction.scrollDown]. + /// + /// This is the semantic equivalent of a user moving their finger across the + /// screen from top to bottom. It should be recognized by controls that are + /// vertically scrollable. + /// + /// VoiceOver users on iOS can trigger this action by swiping down with three + /// fingers. TalkBack users on Android can trigger this action by swiping + /// left and then right in one motion path. On Android, [onScrollDown] and + /// [onScrollRight] share the same gesture. Therefore, only on of them should + /// be provided. + final VoidCallback? onScrollDown; + + /// The handler for [SemanticsAction.increase]. + /// + /// This is a request to increase the value represented by the widget. For + /// example, this action might be recognized by a slider control. + /// + /// If a [value] is set, [increasedValue] must also be provided and + /// [onIncrease] must ensure that [value] will be set to [increasedValue]. + /// + /// VoiceOver users on iOS can trigger this action by swiping up with one + /// finger. TalkBack users on Android can trigger this action by pressing the + /// volume up button. + final VoidCallback? onIncrease; + + /// The handler for [SemanticsAction.decrease]. + /// + /// This is a request to decrease the value represented by the widget. For + /// example, this action might be recognized by a slider control. + /// + /// If a [value] is set, [decreasedValue] must also be provided and + /// [onDecrease] must ensure that [value] will be set to [decreasedValue]. + /// + /// VoiceOver users on iOS can trigger this action by swiping down with one + /// finger. TalkBack users on Android can trigger this action by pressing the + /// volume down button. + final VoidCallback? onDecrease; + + /// The handler for [SemanticsAction.copy]. + /// + /// This is a request to copy the current selection to the clipboard. + /// + /// TalkBack users on Android can trigger this action from the local context + /// menu of a text field, for example. + final VoidCallback? onCopy; + + /// The handler for [SemanticsAction.cut]. + /// + /// This is a request to cut the current selection and place it in the + /// clipboard. + /// + /// TalkBack users on Android can trigger this action from the local context + /// menu of a text field, for example. + final VoidCallback? onCut; + + /// The handler for [SemanticsAction.paste]. + /// + /// This is a request to paste the current content of the clipboard. + /// + /// TalkBack users on Android can trigger this action from the local context + /// menu of a text field, for example. + final VoidCallback? onPaste; + + /// The handler for [SemanticsAction.moveCursorForwardByCharacter]. + /// + /// This handler is invoked when the user wants to move the cursor in a + /// text field forward by one character. + /// + /// TalkBack users can trigger this by pressing the volume up key while the + /// input focus is in a text field. + final MoveCursorHandler? onMoveCursorForwardByCharacter; + + /// The handler for [SemanticsAction.moveCursorBackwardByCharacter]. + /// + /// This handler is invoked when the user wants to move the cursor in a + /// text field backward by one character. + /// + /// TalkBack users can trigger this by pressing the volume down key while the + /// input focus is in a text field. + final MoveCursorHandler? onMoveCursorBackwardByCharacter; + + /// The handler for [SemanticsAction.moveCursorForwardByWord]. + /// + /// This handler is invoked when the user wants to move the cursor in a + /// text field backward by one word. + /// + /// TalkBack users can trigger this by pressing the volume down key while the + /// input focus is in a text field. + final MoveCursorHandler? onMoveCursorForwardByWord; + + /// The handler for [SemanticsAction.moveCursorBackwardByWord]. + /// + /// This handler is invoked when the user wants to move the cursor in a + /// text field backward by one word. + /// + /// TalkBack users can trigger this by pressing the volume down key while the + /// input focus is in a text field. + final MoveCursorHandler? onMoveCursorBackwardByWord; + + /// The handler for [SemanticsAction.setSelection]. + /// + /// This handler is invoked when the user either wants to change the currently + /// selected text in a text field or change the position of the cursor. + /// + /// TalkBack users can trigger this handler by selecting "Move cursor to + /// beginning/end" or "Select all" from the local context menu. + final SetSelectionHandler? onSetSelection; + + /// The handler for [SemanticsAction.setText]. + /// + /// This handler is invoked when the user wants to replace the current text in + /// the text field with a new text. + /// + /// Voice access users can trigger this handler by speaking "type <text>" to + /// their Android devices. + final SetTextHandler? onSetText; + + /// The handler for [SemanticsAction.didGainAccessibilityFocus]. + /// + /// This handler is invoked when the node annotated with this handler gains + /// the accessibility focus. The accessibility focus is the + /// green (on Android with TalkBack) or black (on iOS with VoiceOver) + /// rectangle shown on screen to indicate what element an accessibility + /// user is currently interacting with. + /// + /// The accessibility focus is different from the input focus. The input focus + /// is usually held by the element that currently responds to keyboard inputs. + /// Accessibility focus and input focus can be held by two different nodes! + /// + /// See also: + /// + /// * [onDidLoseAccessibilityFocus], which is invoked when the accessibility + /// focus is removed from the node. + /// * [FocusNode], [FocusScope], [FocusManager], which manage the input focus. + final VoidCallback? onDidGainAccessibilityFocus; + + /// The handler for [SemanticsAction.didLoseAccessibilityFocus]. + /// + /// This handler is invoked when the node annotated with this handler + /// loses the accessibility focus. The accessibility focus is + /// the green (on Android with TalkBack) or black (on iOS with VoiceOver) + /// rectangle shown on screen to indicate what element an accessibility + /// user is currently interacting with. + /// + /// The accessibility focus is different from the input focus. The input focus + /// is usually held by the element that currently responds to keyboard inputs. + /// Accessibility focus and input focus can be held by two different nodes! + /// + /// See also: + /// + /// * [onDidGainAccessibilityFocus], which is invoked when the node gains + /// accessibility focus. + /// * [FocusNode], [FocusScope], [FocusManager], which manage the input focus. + final VoidCallback? onDidLoseAccessibilityFocus; + + /// The handler for [SemanticsAction.dismiss]. + /// + /// This is a request to dismiss the currently focused node. + /// + /// TalkBack users on Android can trigger this action in the local context + /// menu, and VoiceOver users on iOS can trigger this action with a standard + /// gesture or menu option. + final VoidCallback? onDismiss; + + /// A map from each supported [CustomSemanticsAction] to a provided handler. + /// + /// The handler associated with each custom action is called whenever a + /// semantics action of type [SemanticsAction.customAction] is received. The + /// provided argument will be an identifier used to retrieve an instance of + /// a custom action which can then retrieve the correct handler from this map. + /// + /// See also: + /// + /// * [CustomSemanticsAction], for an explanation of custom actions. + final Map<CustomSemanticsAction, VoidCallback>? customSemanticsActions; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('checked', checked, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('mixed', mixed, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('expanded', expanded, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('selected', selected, defaultValue: null)); + properties.add(StringProperty('identifier', identifier, defaultValue: null)); + properties.add(StringProperty('label', label, defaultValue: null)); + properties.add(AttributedStringProperty('attributedLabel', attributedLabel, defaultValue: null)); + properties.add(StringProperty('value', value, defaultValue: null)); + properties.add(AttributedStringProperty('attributedValue', attributedValue, defaultValue: null)); + properties.add(StringProperty('increasedValue', value, defaultValue: null)); + properties.add(AttributedStringProperty('attributedIncreasedValue', attributedIncreasedValue, defaultValue: null)); + properties.add(StringProperty('decreasedValue', value, defaultValue: null)); + properties.add(AttributedStringProperty('attributedDecreasedValue', attributedDecreasedValue, defaultValue: null)); + properties.add(StringProperty('hint', hint, defaultValue: null)); + properties.add(AttributedStringProperty('attributedHint', attributedHint, defaultValue: null)); + properties.add(StringProperty('tooltip', tooltip, defaultValue: null)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(DiagnosticsProperty<SemanticsSortKey>('sortKey', sortKey, defaultValue: null)); + properties.add(DiagnosticsProperty<SemanticsHintOverrides>('hintOverrides', hintOverrides, defaultValue: null)); + } + + @override + String toStringShort() => objectRuntimeType(this, 'SemanticsProperties'); // the hashCode isn't important since we're immutable +} + +/// In tests use this function to reset the counter used to generate +/// [SemanticsNode.id]. +void debugResetSemanticsIdCounter() { + SemanticsNode._lastIdentifier = 0; +} + +/// A node that represents some semantic data. +/// +/// The semantics tree is maintained during the semantics phase of the pipeline +/// (i.e., during [PipelineOwner.flushSemantics]), which happens after +/// compositing. The semantics tree is then uploaded into the engine for use +/// by assistive technology. +class SemanticsNode with DiagnosticableTreeMixin { + /// Creates a semantic node. + /// + /// Each semantic node has a unique identifier that is assigned when the node + /// is created. + SemanticsNode({ + this.key, + VoidCallback? showOnScreen, + }) : _id = _generateNewId(), + _showOnScreen = showOnScreen; + + /// Creates a semantic node to represent the root of the semantics tree. + /// + /// The root node is assigned an identifier of zero. + SemanticsNode.root({ + this.key, + VoidCallback? showOnScreen, + required SemanticsOwner owner, + }) : _id = 0, + _showOnScreen = showOnScreen { + attach(owner); + } + + + // The maximal semantic node identifier generated by the framework. + // + // The identifier range for semantic node IDs is split into 2, the least significant 16 bits are + // reserved for framework generated IDs(generated with _generateNewId), and most significant 32 + // bits are reserved for engine generated IDs. + static const int _maxFrameworkAccessibilityIdentifier = (1<<16) - 1; + + static int _lastIdentifier = 0; + static int _generateNewId() { + _lastIdentifier = (_lastIdentifier + 1) % _maxFrameworkAccessibilityIdentifier; + return _lastIdentifier; + } + + /// Uniquely identifies this node in the list of sibling nodes. + /// + /// Keys are used during the construction of the semantics tree. They are not + /// transferred to the engine. + final Key? key; + + /// The unique identifier for this node. + /// + /// The root node has an id of zero. Other nodes are given a unique id + /// when they are attached to a [SemanticsOwner]. If they are detached, their + /// ids are invalid and should not be used. + /// + /// In rare circumstances, id may change if this node is detached and + /// re-attached to the [SemanticsOwner]. This should only happen when the + /// application has generated too many semantics nodes. + int get id => _id; + int _id; + + final VoidCallback? _showOnScreen; + + // GEOMETRY + + /// The transform from this node's coordinate system to its parent's coordinate system. + /// + /// By default, the transform is null, which represents the identity + /// transformation (i.e., that this node has the same coordinate system as its + /// parent). + Matrix4? get transform => _transform; + Matrix4? _transform; + set transform(Matrix4? value) { + if (!MatrixUtils.matrixEquals(_transform, value)) { + _transform = value == null || MatrixUtils.isIdentity(value) ? null : value; + _markDirty(); + } + } + + /// The bounding box for this node in its coordinate system. + Rect get rect => _rect; + Rect _rect = Rect.zero; + set rect(Rect value) { + assert(value.isFinite, '$this (with $owner) tried to set a non-finite rect.'); + if (_rect != value) { + _rect = value; + _markDirty(); + } + } + + /// The semantic clip from an ancestor that was applied to this node. + /// + /// Expressed in the coordinate system of the node. May be null if no clip has + /// been applied. + /// + /// Descendant [SemanticsNode]s that are positioned outside of this rect will + /// be excluded from the semantics tree. Descendant [SemanticsNode]s that are + /// overlapping with this rect, but are outside of [parentPaintClipRect] will + /// be included in the tree, but they will be marked as hidden because they + /// are assumed to be not visible on screen. + /// + /// If this rect is null, all descendant [SemanticsNode]s outside of + /// [parentPaintClipRect] will be excluded from the tree. + /// + /// If this rect is non-null it has to completely enclose + /// [parentPaintClipRect]. If [parentPaintClipRect] is null this property is + /// also null. + Rect? parentSemanticsClipRect; + + /// The paint clip from an ancestor that was applied to this node. + /// + /// Expressed in the coordinate system of the node. May be null if no clip has + /// been applied. + /// + /// Descendant [SemanticsNode]s that are positioned outside of this rect will + /// either be excluded from the semantics tree (if they have no overlap with + /// [parentSemanticsClipRect]) or they will be included and marked as hidden + /// (if they are overlapping with [parentSemanticsClipRect]). + /// + /// This rect is completely enclosed by [parentSemanticsClipRect]. + /// + /// If this rect is null [parentSemanticsClipRect] also has to be null. + Rect? parentPaintClipRect; + + /// The elevation adjustment that the parent imposes on this node. + /// + /// The [elevation] property is relative to the elevation of the parent + /// [SemanticsNode]. However, as [SemanticsConfiguration]s from various + /// ascending [RenderObject]s are merged into each other to form that + /// [SemanticsNode] the parent’s elevation may change. This requires an + /// adjustment of the child’s relative elevation which is represented by this + /// value. + /// + /// The value is rarely accessed directly. Instead, for most use cases the + /// [elevation] value should be used, which includes this adjustment. + /// + /// See also: + /// + /// * [elevation], the actual elevation of this [SemanticsNode]. + double? elevationAdjustment; + + /// The index of this node within the parent's list of semantic children. + /// + /// This includes all semantic nodes, not just those currently in the + /// child list. For example, if a scrollable has five children but the first + /// two are not visible (and thus not included in the list of children), then + /// the index of the last node will still be 4. + int? indexInParent; + + /// Whether the node is invisible. + /// + /// A node whose [rect] is outside of the bounds of the screen and hence not + /// reachable for users is considered invisible if its semantic information + /// is not merged into a (partially) visible parent as indicated by + /// [isMergedIntoParent]. + /// + /// An invisible node can be safely dropped from the semantic tree without + /// loosing semantic information that is relevant for describing the content + /// currently shown on screen. + bool get isInvisible => !isMergedIntoParent && rect.isEmpty; + + // MERGING + + /// Whether this node merges its semantic information into an ancestor node. + /// + /// This value indicates whether this node has any ancestors with + /// [mergeAllDescendantsIntoThisNode] set to true. + bool get isMergedIntoParent => parent != null && _isMergedIntoParent; + bool _isMergedIntoParent = false; + + /// Whether the user can interact with this node in assistive technologies. + /// + /// This node can still receive accessibility focus even if this is true. + /// Setting this to true prevents the user from activating pointer related + /// [SemanticsAction]s, such as [SemanticsAction.tap] or + /// [SemanticsAction.longPress]. + bool get areUserActionsBlocked => _areUserActionsBlocked; + bool _areUserActionsBlocked = false; + set areUserActionsBlocked(bool value) { + if (_areUserActionsBlocked == value) { + return; + } + _areUserActionsBlocked = value; + _markDirty(); + } + + /// Whether this node is taking part in a merge of semantic information. + /// + /// This returns true if the node is either merged into an ancestor node or if + /// decedent nodes are merged into this node. + /// + /// See also: + /// + /// * [isMergedIntoParent] + /// * [mergeAllDescendantsIntoThisNode] + bool get isPartOfNodeMerging => mergeAllDescendantsIntoThisNode || isMergedIntoParent; + + /// Whether this node and all of its descendants should be treated as one logical entity. + bool get mergeAllDescendantsIntoThisNode => _mergeAllDescendantsIntoThisNode; + bool _mergeAllDescendantsIntoThisNode = _kEmptyConfig.isMergingSemanticsOfDescendants; + + + // CHILDREN + + /// Contains the children in inverse hit test order (i.e. paint order). + List<SemanticsNode>? _children; + + /// A snapshot of `newChildren` passed to [_replaceChildren] that we keep in + /// debug mode. It supports the assertion that user does not mutate the list + /// of children. + late List<SemanticsNode> _debugPreviousSnapshot; + + void _replaceChildren(List<SemanticsNode> newChildren) { + assert(!newChildren.any((SemanticsNode child) => child == this)); + assert(() { + final Set<SemanticsNode> seenChildren = <SemanticsNode>{}; + for (final SemanticsNode child in newChildren) { + assert(seenChildren.add(child)); + } // check for duplicate adds + return true; + }()); + + // The goal of this function is updating sawChange. + if (_children != null) { + for (final SemanticsNode child in _children!) { + child._dead = true; + } + } + for (final SemanticsNode child in newChildren) { + child._dead = false; + } + bool sawChange = false; + if (_children != null) { + for (final SemanticsNode child in _children!) { + if (child._dead) { + if (child.parent == this) { + // we might have already had our child stolen from us by + // another node that is deeper in the tree. + _dropChild(child); + } + sawChange = true; + } + } + } + for (final SemanticsNode child in newChildren) { + if (child.parent != this) { + if (child.parent != null) { + // we're rebuilding the tree from the bottom up, so it's possible + // that our child was, in the last pass, a child of one of our + // ancestors. In that case, we drop the child eagerly here. + // TODO(ianh): Find a way to assert that the same node didn't + // actually appear in the tree in two places. + child.parent?._dropChild(child); + } + assert(!child.attached); + _adoptChild(child); + sawChange = true; + } + } + // Wait until the new children are adopted so isMergedIntoParent becomes + // up-to-date. + assert(() { + if (identical(newChildren, _children)) { + final List<DiagnosticsNode> mutationErrors = <DiagnosticsNode>[]; + if (newChildren.length != _debugPreviousSnapshot.length) { + mutationErrors.add(ErrorDescription( + "The list's length has changed from ${_debugPreviousSnapshot.length} " + 'to ${newChildren.length}.', + )); + } else { + for (int i = 0; i < newChildren.length; i++) { + if (!identical(newChildren[i], _debugPreviousSnapshot[i])) { + if (mutationErrors.isNotEmpty) { + mutationErrors.add(ErrorSpacer()); + } + mutationErrors.add(ErrorDescription('Child node at position $i was replaced:')); + mutationErrors.add(_debugPreviousSnapshot[i].toDiagnosticsNode(name: 'Previous child', style: DiagnosticsTreeStyle.singleLine)); + mutationErrors.add(newChildren[i].toDiagnosticsNode(name: 'New child', style: DiagnosticsTreeStyle.singleLine)); + } + } + } + if (mutationErrors.isNotEmpty) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Failed to replace child semantics nodes because the list of `SemanticsNode`s was mutated.'), + ErrorHint('Instead of mutating the existing list, create a new list containing the desired `SemanticsNode`s.'), + ErrorDescription('Error details:'), + ...mutationErrors, + ]); + } + } + _debugPreviousSnapshot = List<SemanticsNode>.of(newChildren); + + SemanticsNode ancestor = this; + while (ancestor.parent is SemanticsNode) { + ancestor = ancestor.parent!; + } + assert(!newChildren.any((SemanticsNode child) => child == ancestor)); + return true; + }()); + + if (!sawChange && _children != null) { + assert(newChildren.length == _children!.length); + // Did the order change? + for (int i = 0; i < _children!.length; i++) { + if (_children![i].id != newChildren[i].id) { + sawChange = true; + break; + } + } + } + _children = newChildren; + if (sawChange) { + _markDirty(); + } + } + + /// Whether this node has a non-zero number of children. + bool get hasChildren => _children?.isNotEmpty ?? false; + bool _dead = false; + + /// The number of children this node has. + int get childrenCount => hasChildren ? _children!.length : 0; + + /// Visits the immediate children of this node. + /// + /// This function calls visitor for each immediate child until visitor returns + /// false. Returns true if all the visitor calls returned true, otherwise + /// returns false. + void visitChildren(SemanticsNodeVisitor visitor) { + if (_children != null) { + for (final SemanticsNode child in _children!) { + if (!visitor(child)) { + return; + } + } + } + } + + /// Visit all the descendants of this node. + /// + /// This function calls visitor for each descendant in a pre-order traversal + /// until visitor returns false. Returns true if all the visitor calls + /// returned true, otherwise returns false. + bool _visitDescendants(SemanticsNodeVisitor visitor) { + if (_children != null) { + for (final SemanticsNode child in _children!) { + if (!visitor(child) || !child._visitDescendants(visitor)) { + return false; + } + } + } + return true; + } + + /// The owner for this node (null if unattached). + /// + /// The entire semantics tree that this node belongs to will have the same owner. + SemanticsOwner? get owner => _owner; + SemanticsOwner? _owner; + + /// Whether the semantics tree this node belongs to is attached to a [SemanticsOwner]. + /// + /// This becomes true during the call to [attach]. + /// + /// This becomes false during the call to [detach]. + bool get attached => _owner != null; + + /// The parent of this node in the semantics tree. + /// + /// The [parent] of the root node in the semantics tree is null. + SemanticsNode? get parent => _parent; + SemanticsNode? _parent; + + /// The depth of this node in the semantics tree. + /// + /// The depth of nodes in a tree monotonically increases as you traverse down + /// the tree. There's no guarantee regarding depth between siblings. + /// + /// The depth is used to ensure that nodes are processed in depth order. + int get depth => _depth; + int _depth = 0; + + void _redepthChild(SemanticsNode child) { + assert(child.owner == owner); + if (child._depth <= _depth) { + child._depth = _depth + 1; + child._redepthChildren(); + } + } + + void _redepthChildren() { + _children?.forEach(_redepthChild); + } + + void _updateChildMergeFlagRecursively(SemanticsNode child) { + assert(child.owner == owner); + final bool childShouldMergeToParent = isPartOfNodeMerging; + + if (childShouldMergeToParent == child._isMergedIntoParent) { + return; + } + + child._isMergedIntoParent = childShouldMergeToParent; + _markDirty(); + + if (child.mergeAllDescendantsIntoThisNode) { + // No need to update the descendants since `child` has the merge flag set. + } else { + child._updateChildrenMergeFlags(); + } + } + + void _updateChildrenMergeFlags() { + _children?.forEach(_updateChildMergeFlagRecursively); + } + + void _adoptChild(SemanticsNode child) { + assert(child._parent == null); + assert(() { + SemanticsNode node = this; + while (node.parent != null) { + node = node.parent!; + } + assert(node != child); // indicates we are about to create a cycle + return true; + }()); + child._parent = this; + if (attached) { + child.attach(_owner!); + } + _redepthChild(child); + _updateChildMergeFlagRecursively(child); + } + + void _dropChild(SemanticsNode child) { + assert(child._parent == this); + assert(child.attached == attached); + child._parent = null; + if (attached) { + child.detach(); + } + } + + /// Mark this node as attached to the given owner. + @visibleForTesting + void attach(SemanticsOwner owner) { + assert(_owner == null); + _owner = owner; + while (owner._nodes.containsKey(id)) { + // Ids may repeat if the Flutter has generated > 2^16 ids. We need to keep + // regenerating the id until we found an id that is not used. + _id = _generateNewId(); + } + owner._nodes[id] = this; + owner._detachedNodes.remove(this); + if (_dirty) { + _dirty = false; + _markDirty(); + } + if (_children != null) { + for (final SemanticsNode child in _children!) { + child.attach(owner); + } + } + } + + /// Mark this node as detached from its owner. + @visibleForTesting + void detach() { + assert(_owner != null); + assert(owner!._nodes.containsKey(id)); + assert(!owner!._detachedNodes.contains(this)); + owner!._nodes.remove(id); + owner!._detachedNodes.add(this); + _owner = null; + assert(parent == null || attached == parent!.attached); + if (_children != null) { + for (final SemanticsNode child in _children!) { + // The list of children may be stale and may contain nodes that have + // been assigned to a different parent. + if (child.parent == this) { + child.detach(); + } + } + } + // The other side will have forgotten this node if we ever send + // it again, so make sure to mark it dirty so that it'll get + // sent if it is resurrected. + _markDirty(); + } + + // DIRTY MANAGEMENT + + bool _dirty = false; + void _markDirty() { + if (_dirty) { + return; + } + _dirty = true; + if (attached) { + assert(!owner!._detachedNodes.contains(this)); + owner!._dirtyNodes.add(this); + } + } + + bool _isDifferentFromCurrentSemanticAnnotation(SemanticsConfiguration config) { + return _attributedLabel != config.attributedLabel + || _attributedHint != config.attributedHint + || _elevation != config.elevation + || _thickness != config.thickness + || _attributedValue != config.attributedValue + || _attributedIncreasedValue != config.attributedIncreasedValue + || _attributedDecreasedValue != config.attributedDecreasedValue + || _tooltip != config.tooltip + || _flags != config._flags + || _textDirection != config.textDirection + || _sortKey != config._sortKey + || _textSelection != config._textSelection + || _scrollPosition != config._scrollPosition + || _scrollExtentMax != config._scrollExtentMax + || _scrollExtentMin != config._scrollExtentMin + || _actionsAsBits != config._actionsAsBits + || indexInParent != config.indexInParent + || platformViewId != config.platformViewId + || _maxValueLength != config._maxValueLength + || _currentValueLength != config._currentValueLength + || _mergeAllDescendantsIntoThisNode != config.isMergingSemanticsOfDescendants + || _areUserActionsBlocked != config.isBlockingUserActions; + } + + // TAGS, LABELS, ACTIONS + + Map<SemanticsAction, SemanticsActionHandler> _actions = _kEmptyConfig._actions; + Map<CustomSemanticsAction, VoidCallback> _customSemanticsActions = _kEmptyConfig._customSemanticsActions; + + int get _effectiveActionsAsBits => _areUserActionsBlocked ? _actionsAsBits & _kUnblockedUserActions : _actionsAsBits; + int _actionsAsBits = _kEmptyConfig._actionsAsBits; + + /// The [SemanticsTag]s this node is tagged with. + /// + /// Tags are used during the construction of the semantics tree. They are not + /// transferred to the engine. + Set<SemanticsTag>? tags; + + /// Whether this node is tagged with `tag`. + bool isTagged(SemanticsTag tag) => tags != null && tags!.contains(tag); + + int _flags = _kEmptyConfig._flags; + + /// Whether this node currently has a given [SemanticsFlag]. + bool hasFlag(SemanticsFlag flag) => _flags & flag.index != 0; + + /// {@macro flutter.semantics.SemanticsProperties.identifier} + String get identifier => _identifier; + String _identifier = _kEmptyConfig.identifier; + + /// A textual description of this node. + /// + /// The reading direction is given by [textDirection]. + /// + /// This exposes the raw text of the [attributedLabel]. + String get label => _attributedLabel.string; + + /// A textual description of this node in [AttributedString] format. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also [label], which exposes just the raw text. + AttributedString get attributedLabel => _attributedLabel; + AttributedString _attributedLabel = _kEmptyConfig.attributedLabel; + + /// A textual description for the current value of the node. + /// + /// The reading direction is given by [textDirection]. + /// + /// This exposes the raw text of the [attributedValue]. + String get value => _attributedValue.string; + + /// A textual description for the current value of the node in + /// [AttributedString] format. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also [value], which exposes just the raw text. + AttributedString get attributedValue => _attributedValue; + AttributedString _attributedValue = _kEmptyConfig.attributedValue; + + /// The value that [value] will have after a [SemanticsAction.increase] action + /// has been performed. + /// + /// This property is only valid if the [SemanticsAction.increase] action is + /// available on this node. + /// + /// The reading direction is given by [textDirection]. + /// + /// This exposes the raw text of the [attributedIncreasedValue]. + String get increasedValue => _attributedIncreasedValue.string; + + /// The value in [AttributedString] format that [value] or [attributedValue] + /// will have after a [SemanticsAction.increase] action has been performed. + /// + /// This property is only valid if the [SemanticsAction.increase] action is + /// available on this node. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also [increasedValue], which exposes just the raw text. + AttributedString get attributedIncreasedValue => _attributedIncreasedValue; + AttributedString _attributedIncreasedValue = _kEmptyConfig.attributedIncreasedValue; + + /// The value that [value] will have after a [SemanticsAction.decrease] action + /// has been performed. + /// + /// This property is only valid if the [SemanticsAction.decrease] action is + /// available on this node. + /// + /// The reading direction is given by [textDirection]. + /// + /// This exposes the raw text of the [attributedDecreasedValue]. + String get decreasedValue => _attributedDecreasedValue.string; + + /// The value in [AttributedString] format that [value] or [attributedValue] + /// will have after a [SemanticsAction.decrease] action has been performed. + /// + /// This property is only valid if the [SemanticsAction.decrease] action is + /// available on this node. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also [decreasedValue], which exposes just the raw text. + AttributedString get attributedDecreasedValue => _attributedDecreasedValue; + AttributedString _attributedDecreasedValue = _kEmptyConfig.attributedDecreasedValue; + + /// A brief description of the result of performing an action on this node. + /// + /// The reading direction is given by [textDirection]. + /// + /// This exposes the raw text of the [attributedHint]. + String get hint => _attributedHint.string; + + /// A brief description of the result of performing an action on this node + /// in [AttributedString] format. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also [hint], which exposes just the raw text. + AttributedString get attributedHint => _attributedHint; + AttributedString _attributedHint = _kEmptyConfig.attributedHint; + + /// A textual description of the widget's tooltip. + /// + /// The reading direction is given by [textDirection]. + String get tooltip => _tooltip; + String _tooltip = _kEmptyConfig.tooltip; + + /// The elevation along the z-axis at which the [rect] of this [SemanticsNode] + /// is located above its parent. + /// + /// The value is relative to the parent's [elevation]. The sum of the + /// [elevation]s of all ancestor node plus this value determines the absolute + /// elevation of this [SemanticsNode]. + /// + /// See also: + /// + /// * [thickness], which describes how much space in z-direction this + /// [SemanticsNode] occupies starting at this [elevation]. + /// * [elevationAdjustment], which has been used to calculate this value. + double get elevation => _elevation; + double _elevation = _kEmptyConfig.elevation; + + /// Describes how much space the [SemanticsNode] takes up along the z-axis. + /// + /// A [SemanticsNode] represents multiple [RenderObject]s, which can be + /// located at various elevations in 3D. The [thickness] is the difference + /// between the absolute elevations of the lowest and highest [RenderObject] + /// represented by this [SemanticsNode]. In other words, the thickness + /// describes how high the box is that this [SemanticsNode] occupies in three + /// dimensional space. The two other dimensions are defined by [rect]. + /// + /// {@tool snippet} + /// The following code stacks three [PhysicalModel]s on top of each other + /// separated by non-zero elevations. + /// + /// [PhysicalModel] C is elevated 10.0 above [PhysicalModel] B, which in turn + /// is elevated 5.0 above [PhysicalModel] A. The side view of this + /// constellation looks as follows: + /// + /// ![A diagram illustrating the elevations of three PhysicalModels and their + /// corresponding SemanticsNodes.](https://flutter.github.io/assets-for-api-docs/assets/semantics/SemanticsNode.thickness.png) + /// + /// In this example the [RenderObject]s for [PhysicalModel] C and B share one + /// [SemanticsNode] Y. Given the elevations of those [RenderObject]s, this + /// [SemanticsNode] has a [thickness] of 10.0 and an elevation of 5.0 over + /// its parent [SemanticsNode] X. + /// ```dart + /// PhysicalModel( // A + /// color: Colors.amber, + /// child: Semantics( + /// explicitChildNodes: true, + /// child: const PhysicalModel( // B + /// color: Colors.brown, + /// elevation: 5.0, + /// child: PhysicalModel( // C + /// color: Colors.cyan, + /// elevation: 10.0, + /// child: Placeholder(), + /// ), + /// ), + /// ), + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [elevation], which describes the elevation of the box defined by + /// [thickness] and [rect] relative to the parent of this [SemanticsNode]. + double get thickness => _thickness; + double _thickness = _kEmptyConfig.thickness; + + /// Provides hint values which override the default hints on supported + /// platforms. + SemanticsHintOverrides? get hintOverrides => _hintOverrides; + SemanticsHintOverrides? _hintOverrides; + + /// The reading direction for [label], [value], [hint], [increasedValue], and + /// [decreasedValue]. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection = _kEmptyConfig.textDirection; + + /// Determines the position of this node among its siblings in the traversal + /// sort order. + /// + /// This is used to describe the order in which the semantic node should be + /// traversed by the accessibility services on the platform (e.g. VoiceOver + /// on iOS and TalkBack on Android). + SemanticsSortKey? get sortKey => _sortKey; + SemanticsSortKey? _sortKey; + + /// The currently selected text (or the position of the cursor) within [value] + /// if this node represents a text field. + TextSelection? get textSelection => _textSelection; + TextSelection? _textSelection; + + /// If this node represents a text field, this indicates whether or not it's + /// a multiline text field. + bool? get isMultiline => _isMultiline; + bool? _isMultiline; + + /// The total number of scrollable children that contribute to semantics. + /// + /// If the number of children are unknown or unbounded, this value will be + /// null. + int? get scrollChildCount => _scrollChildCount; + int? _scrollChildCount; + + /// The index of the first visible semantic child of a scroll node. + int? get scrollIndex => _scrollIndex; + int? _scrollIndex; + + /// Indicates the current scrolling position in logical pixels if the node is + /// scrollable. + /// + /// The properties [scrollExtentMin] and [scrollExtentMax] indicate the valid + /// in-range values for this property. The value for [scrollPosition] may + /// (temporarily) be outside that range, e.g. during an overscroll. + /// + /// See also: + /// + /// * [ScrollPosition.pixels], from where this value is usually taken. + double? get scrollPosition => _scrollPosition; + double? _scrollPosition; + + /// Indicates the maximum in-range value for [scrollPosition] if the node is + /// scrollable. + /// + /// This value may be infinity if the scroll is unbound. + /// + /// See also: + /// + /// * [ScrollPosition.maxScrollExtent], from where this value is usually taken. + double? get scrollExtentMax => _scrollExtentMax; + double? _scrollExtentMax; + + /// Indicates the minimum in-range value for [scrollPosition] if the node is + /// scrollable. + /// + /// This value may be infinity if the scroll is unbound. + /// + /// See also: + /// + /// * [ScrollPosition.minScrollExtent] from where this value is usually taken. + double? get scrollExtentMin => _scrollExtentMin; + double? _scrollExtentMin; + + /// The id of the platform view, whose semantics nodes will be added as + /// children to this node. + /// + /// If this value is non-null, the SemanticsNode must not have any children + /// as those would be replaced by the semantics nodes of the referenced + /// platform view. + /// + /// See also: + /// + /// * [AndroidView], which is the platform view for Android. + /// * [UiKitView], which is the platform view for iOS. + int? get platformViewId => _platformViewId; + int? _platformViewId; + + /// The maximum number of characters that can be entered into an editable + /// text field. + /// + /// For the purpose of this function a character is defined as one Unicode + /// scalar value. + /// + /// This should only be set when [SemanticsFlag.isTextField] is set. Defaults + /// to null, which means no limit is imposed on the text field. + int? get maxValueLength => _maxValueLength; + int? _maxValueLength; + + /// The current number of characters that have been entered into an editable + /// text field. + /// + /// For the purpose of this function a character is defined as one Unicode + /// scalar value. + /// + /// This should only be set when [SemanticsFlag.isTextField] is set. Must be + /// set when [maxValueLength] is set. + int? get currentValueLength => _currentValueLength; + int? _currentValueLength; + + bool _canPerformAction(SemanticsAction action) => _actions.containsKey(action); + + static final SemanticsConfiguration _kEmptyConfig = SemanticsConfiguration(); + + /// Reconfigures the properties of this object to describe the configuration + /// provided in the `config` argument and the children listed in the + /// `childrenInInversePaintOrder` argument. + /// + /// The arguments may be null; this represents an empty configuration (all + /// values at their defaults, no children). + /// + /// No reference is kept to the [SemanticsConfiguration] object, but the child + /// list is used as-is and should therefore not be changed after this call. + void updateWith({ + required SemanticsConfiguration? config, + List<SemanticsNode>? childrenInInversePaintOrder, + }) { + config ??= _kEmptyConfig; + if (_isDifferentFromCurrentSemanticAnnotation(config)) { + _markDirty(); + } + + assert( + config.platformViewId == null || childrenInInversePaintOrder == null || childrenInInversePaintOrder.isEmpty, + 'SemanticsNodes with children must not specify a platformViewId.', + ); + + final bool mergeAllDescendantsIntoThisNodeValueChanged = _mergeAllDescendantsIntoThisNode != config.isMergingSemanticsOfDescendants; + + _identifier = config.identifier; + _attributedLabel = config.attributedLabel; + _attributedValue = config.attributedValue; + _attributedIncreasedValue = config.attributedIncreasedValue; + _attributedDecreasedValue = config.attributedDecreasedValue; + _attributedHint = config.attributedHint; + _tooltip = config.tooltip; + _hintOverrides = config.hintOverrides; + _elevation = config.elevation; + _thickness = config.thickness; + _flags = config._flags; + _textDirection = config.textDirection; + _sortKey = config.sortKey; + _actions = Map<SemanticsAction, SemanticsActionHandler>.of(config._actions); + _customSemanticsActions = Map<CustomSemanticsAction, VoidCallback>.of(config._customSemanticsActions); + _actionsAsBits = config._actionsAsBits; + _textSelection = config._textSelection; + _isMultiline = config.isMultiline; + _scrollPosition = config._scrollPosition; + _scrollExtentMax = config._scrollExtentMax; + _scrollExtentMin = config._scrollExtentMin; + _mergeAllDescendantsIntoThisNode = config.isMergingSemanticsOfDescendants; + _scrollChildCount = config.scrollChildCount; + _scrollIndex = config.scrollIndex; + indexInParent = config.indexInParent; + _platformViewId = config._platformViewId; + _maxValueLength = config._maxValueLength; + _currentValueLength = config._currentValueLength; + _areUserActionsBlocked = config.isBlockingUserActions; + _replaceChildren(childrenInInversePaintOrder ?? const <SemanticsNode>[]); + + if (mergeAllDescendantsIntoThisNodeValueChanged) { + _updateChildrenMergeFlags(); + } + + assert( + !_canPerformAction(SemanticsAction.increase) || (value == '') == (increasedValue == ''), + 'A SemanticsNode with action "increase" needs to be annotated with either both "value" and "increasedValue" or neither', + ); + assert( + !_canPerformAction(SemanticsAction.decrease) || (value == '') == (decreasedValue == ''), + 'A SemanticsNode with action "decrease" needs to be annotated with either both "value" and "decreasedValue" or neither', + ); + } + + + /// Returns a summary of the semantics for this node. + /// + /// If this node has [mergeAllDescendantsIntoThisNode], then the returned data + /// includes the information from this node's descendants. Otherwise, the + /// returned data matches the data on this node. + SemanticsData getSemanticsData() { + int flags = _flags; + // Can't use _effectiveActionsAsBits here. The filtering of action bits + // must be done after the merging the its descendants. + int actions = _actionsAsBits; + String identifier = _identifier; + AttributedString attributedLabel = _attributedLabel; + AttributedString attributedValue = _attributedValue; + AttributedString attributedIncreasedValue = _attributedIncreasedValue; + AttributedString attributedDecreasedValue = _attributedDecreasedValue; + AttributedString attributedHint = _attributedHint; + String tooltip = _tooltip; + TextDirection? textDirection = _textDirection; + Set<SemanticsTag>? mergedTags = tags == null ? null : Set<SemanticsTag>.of(tags!); + TextSelection? textSelection = _textSelection; + int? scrollChildCount = _scrollChildCount; + int? scrollIndex = _scrollIndex; + double? scrollPosition = _scrollPosition; + double? scrollExtentMax = _scrollExtentMax; + double? scrollExtentMin = _scrollExtentMin; + int? platformViewId = _platformViewId; + int? maxValueLength = _maxValueLength; + int? currentValueLength = _currentValueLength; + final double elevation = _elevation; + double thickness = _thickness; + final Set<int> customSemanticsActionIds = <int>{}; + for (final CustomSemanticsAction action in _customSemanticsActions.keys) { + customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action)); + } + if (hintOverrides != null) { + if (hintOverrides!.onTapHint != null) { + final CustomSemanticsAction action = CustomSemanticsAction.overridingAction( + hint: hintOverrides!.onTapHint!, + action: SemanticsAction.tap, + ); + customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action)); + } + if (hintOverrides!.onLongPressHint != null) { + final CustomSemanticsAction action = CustomSemanticsAction.overridingAction( + hint: hintOverrides!.onLongPressHint!, + action: SemanticsAction.longPress, + ); + customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action)); + } + } + + if (mergeAllDescendantsIntoThisNode) { + _visitDescendants((SemanticsNode node) { + assert(node.isMergedIntoParent); + flags |= node._flags; + actions |= node._effectiveActionsAsBits; + + textDirection ??= node._textDirection; + textSelection ??= node._textSelection; + scrollChildCount ??= node._scrollChildCount; + scrollIndex ??= node._scrollIndex; + scrollPosition ??= node._scrollPosition; + scrollExtentMax ??= node._scrollExtentMax; + scrollExtentMin ??= node._scrollExtentMin; + platformViewId ??= node._platformViewId; + maxValueLength ??= node._maxValueLength; + currentValueLength ??= node._currentValueLength; + if (identifier == '') { + identifier = node._identifier; + } + if (attributedValue.string == '') { + attributedValue = node._attributedValue; + } + if (attributedIncreasedValue.string == '') { + attributedIncreasedValue = node._attributedIncreasedValue; + } + if (attributedDecreasedValue.string == '') { + attributedDecreasedValue = node._attributedDecreasedValue; + } + if (tooltip == '') { + tooltip = node._tooltip; + } + if (node.tags != null) { + mergedTags ??= <SemanticsTag>{}; + mergedTags!.addAll(node.tags!); + } + for (final CustomSemanticsAction action in _customSemanticsActions.keys) { + customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action)); + } + if (node.hintOverrides != null) { + if (node.hintOverrides!.onTapHint != null) { + final CustomSemanticsAction action = CustomSemanticsAction.overridingAction( + hint: node.hintOverrides!.onTapHint!, + action: SemanticsAction.tap, + ); + customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action)); + } + if (node.hintOverrides!.onLongPressHint != null) { + final CustomSemanticsAction action = CustomSemanticsAction.overridingAction( + hint: node.hintOverrides!.onLongPressHint!, + action: SemanticsAction.longPress, + ); + customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action)); + } + } + attributedLabel = _concatAttributedString( + thisAttributedString: attributedLabel, + thisTextDirection: textDirection, + otherAttributedString: node._attributedLabel, + otherTextDirection: node._textDirection, + ); + attributedHint = _concatAttributedString( + thisAttributedString: attributedHint, + thisTextDirection: textDirection, + otherAttributedString: node._attributedHint, + otherTextDirection: node._textDirection, + ); + + thickness = math.max(thickness, node._thickness + node._elevation); + + return true; + }); + } + + return SemanticsData( + flags: flags, + actions: _areUserActionsBlocked ? actions & _kUnblockedUserActions : actions, + identifier: identifier, + attributedLabel: attributedLabel, + attributedValue: attributedValue, + attributedIncreasedValue: attributedIncreasedValue, + attributedDecreasedValue: attributedDecreasedValue, + attributedHint: attributedHint, + tooltip: tooltip, + textDirection: textDirection, + rect: rect, + transform: transform, + elevation: elevation, + thickness: thickness, + tags: mergedTags, + textSelection: textSelection, + scrollChildCount: scrollChildCount, + scrollIndex: scrollIndex, + scrollPosition: scrollPosition, + scrollExtentMax: scrollExtentMax, + scrollExtentMin: scrollExtentMin, + platformViewId: platformViewId, + maxValueLength: maxValueLength, + currentValueLength: currentValueLength, + customSemanticsActionIds: customSemanticsActionIds.toList()..sort(), + ); + } + + static Float64List _initIdentityTransform() { + return Matrix4.identity().storage; + } + + static final Int32List _kEmptyChildList = Int32List(0); + static final Int32List _kEmptyCustomSemanticsActionsList = Int32List(0); + static final Float64List _kIdentityTransform = _initIdentityTransform(); + + void _addToUpdate(SemanticsUpdateBuilder builder, Set<int> customSemanticsActionIdsUpdate) { + assert(_dirty); + final SemanticsData data = getSemanticsData(); + final Int32List childrenInTraversalOrder; + final Int32List childrenInHitTestOrder; + if (!hasChildren || mergeAllDescendantsIntoThisNode) { + childrenInTraversalOrder = _kEmptyChildList; + childrenInHitTestOrder = _kEmptyChildList; + } else { + final int childCount = _children!.length; + final List<SemanticsNode> sortedChildren = _childrenInTraversalOrder(); + childrenInTraversalOrder = Int32List(childCount); + for (int i = 0; i < childCount; i += 1) { + childrenInTraversalOrder[i] = sortedChildren[i].id; + } + // _children is sorted in paint order, so we invert it to get the hit test + // order. + childrenInHitTestOrder = Int32List(childCount); + for (int i = childCount - 1; i >= 0; i -= 1) { + childrenInHitTestOrder[i] = _children![childCount - i - 1].id; + } + } + Int32List? customSemanticsActionIds; + if (data.customSemanticsActionIds?.isNotEmpty ?? false) { + customSemanticsActionIds = Int32List(data.customSemanticsActionIds!.length); + for (int i = 0; i < data.customSemanticsActionIds!.length; i++) { + customSemanticsActionIds[i] = data.customSemanticsActionIds![i]; + customSemanticsActionIdsUpdate.add(data.customSemanticsActionIds![i]); + } + } + builder.updateNode( + id: id, + flags: data.flags, + actions: data.actions, + rect: data.rect, + identifier: data.identifier, + label: data.attributedLabel.string, + labelAttributes: data.attributedLabel.attributes, + value: data.attributedValue.string, + valueAttributes: data.attributedValue.attributes, + increasedValue: data.attributedIncreasedValue.string, + increasedValueAttributes: data.attributedIncreasedValue.attributes, + decreasedValue: data.attributedDecreasedValue.string, + decreasedValueAttributes: data.attributedDecreasedValue.attributes, + hint: data.attributedHint.string, + hintAttributes: data.attributedHint.attributes, + tooltip: data.tooltip, + textDirection: data.textDirection, + textSelectionBase: data.textSelection != null ? data.textSelection!.baseOffset : -1, + textSelectionExtent: data.textSelection != null ? data.textSelection!.extentOffset : -1, + platformViewId: data.platformViewId ?? -1, + maxValueLength: data.maxValueLength ?? -1, + currentValueLength: data.currentValueLength ?? -1, + scrollChildren: data.scrollChildCount ?? 0, + scrollIndex: data.scrollIndex ?? 0 , + scrollPosition: data.scrollPosition ?? double.nan, + scrollExtentMax: data.scrollExtentMax ?? double.nan, + scrollExtentMin: data.scrollExtentMin ?? double.nan, + transform: data.transform?.storage ?? _kIdentityTransform, + elevation: data.elevation, + thickness: data.thickness, + childrenInTraversalOrder: childrenInTraversalOrder, + childrenInHitTestOrder: childrenInHitTestOrder, + additionalActions: customSemanticsActionIds ?? _kEmptyCustomSemanticsActionsList, + ); + _dirty = false; + } + + /// Builds a new list made of [_children] sorted in semantic traversal order. + List<SemanticsNode> _childrenInTraversalOrder() { + TextDirection? inheritedTextDirection = textDirection; + SemanticsNode? ancestor = parent; + while (inheritedTextDirection == null && ancestor != null) { + inheritedTextDirection = ancestor.textDirection; + ancestor = ancestor.parent; + } + + List<SemanticsNode>? childrenInDefaultOrder; + if (inheritedTextDirection != null) { + childrenInDefaultOrder = _childrenInDefaultOrder(_children!, inheritedTextDirection); + } else { + // In the absence of text direction default to paint order. + childrenInDefaultOrder = _children; + } + + // List.sort does not guarantee stable sort order. Therefore, children are + // first partitioned into groups that have compatible sort keys, i.e. keys + // in the same group can be compared to each other. These groups stay in + // the same place. Only children within the same group are sorted. + final List<_TraversalSortNode> everythingSorted = <_TraversalSortNode>[]; + final List<_TraversalSortNode> sortNodes = <_TraversalSortNode>[]; + SemanticsSortKey? lastSortKey; + for (int position = 0; position < childrenInDefaultOrder!.length; position += 1) { + final SemanticsNode child = childrenInDefaultOrder[position]; + final SemanticsSortKey? sortKey = child.sortKey; + lastSortKey = position > 0 + ? childrenInDefaultOrder[position - 1].sortKey + : null; + final bool isCompatibleWithPreviousSortKey = position == 0 || + sortKey.runtimeType == lastSortKey.runtimeType && + (sortKey == null || sortKey.name == lastSortKey!.name); + if (!isCompatibleWithPreviousSortKey && sortNodes.isNotEmpty) { + // Do not sort groups with null sort keys. List.sort does not guarantee + // a stable sort order. + if (lastSortKey != null) { + sortNodes.sort(); + } + everythingSorted.addAll(sortNodes); + sortNodes.clear(); + } + + sortNodes.add(_TraversalSortNode( + node: child, + sortKey: sortKey, + position: position, + )); + } + + // Do not sort groups with null sort keys. List.sort does not guarantee + // a stable sort order. + if (lastSortKey != null) { + sortNodes.sort(); + } + everythingSorted.addAll(sortNodes); + + return everythingSorted + .map<SemanticsNode>((_TraversalSortNode sortNode) => sortNode.node) + .toList(); + } + + /// Sends a [SemanticsEvent] associated with this [SemanticsNode]. + /// + /// Semantics events should be sent to inform interested parties (like + /// the accessibility system of the operating system) about changes to the UI. + void sendEvent(SemanticsEvent event) { + if (!attached) { + return; + } + SystemChannels.accessibility.send(event.toMap(nodeId: id)); + } + + bool _debugIsActionBlocked(SemanticsAction action) { + bool result = false; + assert((){ + result = (_effectiveActionsAsBits & action.index) == 0; + return true; + }()); + return result; + } + + @override + String toStringShort() => '${objectRuntimeType(this, 'SemanticsNode')}#$id'; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + bool hideOwner = true; + if (_dirty) { + final bool inDirtyNodes = owner != null && owner!._dirtyNodes.contains(this); + properties.add(FlagProperty('inDirtyNodes', value: inDirtyNodes, ifTrue: 'dirty', ifFalse: 'STALE')); + hideOwner = inDirtyNodes; + } + properties.add(DiagnosticsProperty<SemanticsOwner>('owner', owner, level: hideOwner ? DiagnosticLevel.hidden : DiagnosticLevel.info)); + properties.add(FlagProperty('isMergedIntoParent', value: isMergedIntoParent, ifTrue: 'merged up ⬆️')); + properties.add(FlagProperty('mergeAllDescendantsIntoThisNode', value: mergeAllDescendantsIntoThisNode, ifTrue: 'merge boundary ⛔️')); + final Offset? offset = transform != null ? MatrixUtils.getAsTranslation(transform!) : null; + if (offset != null) { + properties.add(DiagnosticsProperty<Rect>('rect', rect.shift(offset), showName: false)); + } else { + final double? scale = transform != null ? MatrixUtils.getAsScale(transform!) : null; + String? description; + if (scale != null) { + description = '$rect scaled by ${scale.toStringAsFixed(1)}x'; + } else if (transform != null && !MatrixUtils.isIdentity(transform!)) { + final String matrix = transform.toString().split('\n').take(4).map<String>((String line) => line.substring(4)).join('; '); + description = '$rect with transform [$matrix]'; + } + properties.add(DiagnosticsProperty<Rect>('rect', rect, description: description, showName: false)); + } + properties.add(IterableProperty<String>('tags', tags?.map((SemanticsTag tag) => tag.name), defaultValue: null)); + final List<String> actions = _actions.keys.map<String>((SemanticsAction action) => '${action.name}${_debugIsActionBlocked(action) ? '🚫️' : ''}').toList()..sort(); + final List<String?> customSemanticsActions = _customSemanticsActions.keys + .map<String?>((CustomSemanticsAction action) => action.label) + .toList(); + properties.add(IterableProperty<String>('actions', actions, ifEmpty: null)); + properties.add(IterableProperty<String?>('customActions', customSemanticsActions, ifEmpty: null)); + final List<String> flags = SemanticsFlag.values.where((SemanticsFlag flag) => hasFlag(flag)).map((SemanticsFlag flag) => flag.name).toList(); + properties.add(IterableProperty<String>('flags', flags, ifEmpty: null)); + properties.add(FlagProperty('isInvisible', value: isInvisible, ifTrue: 'invisible')); + properties.add(FlagProperty('isHidden', value: hasFlag(SemanticsFlag.isHidden), ifTrue: 'HIDDEN')); + properties.add(StringProperty('identifier', _identifier, defaultValue: '')); + properties.add(AttributedStringProperty('label', _attributedLabel)); + properties.add(AttributedStringProperty('value', _attributedValue)); + properties.add(AttributedStringProperty('increasedValue', _attributedIncreasedValue)); + properties.add(AttributedStringProperty('decreasedValue', _attributedDecreasedValue)); + properties.add(AttributedStringProperty('hint', _attributedHint)); + properties.add(StringProperty('tooltip', _tooltip, defaultValue: '')); + properties.add(EnumProperty<TextDirection>('textDirection', _textDirection, defaultValue: null)); + properties.add(DiagnosticsProperty<SemanticsSortKey>('sortKey', sortKey, defaultValue: null)); + if (_textSelection?.isValid ?? false) { + properties.add(MessageProperty('text selection', '[${_textSelection!.start}, ${_textSelection!.end}]')); + } + properties.add(IntProperty('platformViewId', platformViewId, defaultValue: null)); + properties.add(IntProperty('maxValueLength', maxValueLength, defaultValue: null)); + properties.add(IntProperty('currentValueLength', currentValueLength, defaultValue: null)); + properties.add(IntProperty('scrollChildren', scrollChildCount, defaultValue: null)); + properties.add(IntProperty('scrollIndex', scrollIndex, defaultValue: null)); + properties.add(DoubleProperty('scrollExtentMin', scrollExtentMin, defaultValue: null)); + properties.add(DoubleProperty('scrollPosition', scrollPosition, defaultValue: null)); + properties.add(DoubleProperty('scrollExtentMax', scrollExtentMax, defaultValue: null)); + properties.add(DoubleProperty('elevation', elevation, defaultValue: 0.0)); + properties.add(DoubleProperty('thickness', thickness, defaultValue: 0.0)); + } + + /// Returns a string representation of this node and its descendants. + /// + /// The order in which the children of the [SemanticsNode] will be printed is + /// controlled by the [childOrder] parameter. + @override + String toStringDeep({ + String prefixLineOne = '', + String? prefixOtherLines, + DiagnosticLevel minLevel = DiagnosticLevel.debug, + DebugSemanticsDumpOrder childOrder = DebugSemanticsDumpOrder.traversalOrder, + }) { + return toDiagnosticsNode(childOrder: childOrder).toStringDeep(prefixLineOne: prefixLineOne, prefixOtherLines: prefixOtherLines, minLevel: minLevel); + } + + @override + DiagnosticsNode toDiagnosticsNode({ + String? name, + DiagnosticsTreeStyle? style = DiagnosticsTreeStyle.sparse, + DebugSemanticsDumpOrder childOrder = DebugSemanticsDumpOrder.traversalOrder, + }) { + return _SemanticsDiagnosticableNode( + name: name, + value: this, + style: style, + childOrder: childOrder, + ); + } + + @override + List<DiagnosticsNode> debugDescribeChildren({ DebugSemanticsDumpOrder childOrder = DebugSemanticsDumpOrder.inverseHitTest }) { + return debugListChildrenInOrder(childOrder) + .map<DiagnosticsNode>((SemanticsNode node) => node.toDiagnosticsNode(childOrder: childOrder)) + .toList(); + } + + /// Returns the list of direct children of this node in the specified order. + List<SemanticsNode> debugListChildrenInOrder(DebugSemanticsDumpOrder childOrder) { + if (_children == null) { + return const <SemanticsNode>[]; + } + + switch (childOrder) { + case DebugSemanticsDumpOrder.inverseHitTest: + return _children!; + case DebugSemanticsDumpOrder.traversalOrder: + return _childrenInTraversalOrder(); + } + } +} + +/// An edge of a box, such as top, bottom, left or right, used to compute +/// [SemanticsNode]s that overlap vertically or horizontally. +/// +/// For computing horizontal overlap in an LTR setting we create two [_BoxEdge] +/// objects for each [SemanticsNode]: one representing the left edge (marked +/// with [isLeadingEdge] equal to true) and one for the right edge (with [isLeadingEdge] +/// equal to false). Similarly, for vertical overlap we also create two objects +/// for each [SemanticsNode], one for the top and one for the bottom edge. +class _BoxEdge implements Comparable<_BoxEdge> { + _BoxEdge({ + required this.isLeadingEdge, + required this.offset, + required this.node, + }) : assert(offset.isFinite); + + /// True if the edge comes before the seconds edge along the traversal + /// direction, and false otherwise. + /// + /// This field is never null. + /// + /// For example, in LTR traversal the left edge's [isLeadingEdge] is set to true, + /// the right edge's [isLeadingEdge] is set to false. When considering vertical + /// ordering of boxes, the top edge is the start edge, and the bottom edge is + /// the end edge. + final bool isLeadingEdge; + + /// The offset from the start edge of the parent [SemanticsNode] in the + /// direction of the traversal. + final double offset; + + /// The node whom this edge belongs. + final SemanticsNode node; + + @override + int compareTo(_BoxEdge other) { + return offset.compareTo(other.offset); + } +} + +/// A group of [nodes] that are disjoint vertically or horizontally from other +/// nodes that share the same [SemanticsNode] parent. +/// +/// The [nodes] are sorted among each other separately from other nodes. +class _SemanticsSortGroup implements Comparable<_SemanticsSortGroup> { + _SemanticsSortGroup({ + required this.startOffset, + required this.textDirection, + }); + + /// The offset from the start edge of the parent [SemanticsNode] in the + /// direction of the traversal. + /// + /// This value is equal to the [_BoxEdge.offset] of the first node in the + /// [nodes] list being considered. + final double startOffset; + + final TextDirection textDirection; + + /// The nodes that are sorted among each other. + final List<SemanticsNode> nodes = <SemanticsNode>[]; + + @override + int compareTo(_SemanticsSortGroup other) { + return startOffset.compareTo(other.startOffset); + } + + /// Sorts this group assuming that [nodes] belong to the same vertical group. + /// + /// This method breaks up this group into horizontal [_SemanticsSortGroup]s + /// then sorts them using [sortedWithinKnot]. + List<SemanticsNode> sortedWithinVerticalGroup() { + final List<_BoxEdge> edges = <_BoxEdge>[]; + for (final SemanticsNode child in nodes) { + // Using a small delta to shrink child rects removes overlapping cases. + final Rect childRect = child.rect.deflate(0.1); + edges.add(_BoxEdge( + isLeadingEdge: true, + offset: _pointInParentCoordinates(child, childRect.topLeft).dx, + node: child, + )); + edges.add(_BoxEdge( + isLeadingEdge: false, + offset: _pointInParentCoordinates(child, childRect.bottomRight).dx, + node: child, + )); + } + edges.sort(); + + List<_SemanticsSortGroup> horizontalGroups = <_SemanticsSortGroup>[]; + _SemanticsSortGroup? group; + int depth = 0; + for (final _BoxEdge edge in edges) { + if (edge.isLeadingEdge) { + depth += 1; + group ??= _SemanticsSortGroup( + startOffset: edge.offset, + textDirection: textDirection, + ); + group.nodes.add(edge.node); + } else { + depth -= 1; + } + if (depth == 0) { + horizontalGroups.add(group!); + group = null; + } + } + horizontalGroups.sort(); + + if (textDirection == TextDirection.rtl) { + horizontalGroups = horizontalGroups.reversed.toList(); + } + + return horizontalGroups + .expand((_SemanticsSortGroup group) => group.sortedWithinKnot()) + .toList(); + } + + /// Sorts [nodes] where nodes intersect both vertically and horizontally. + /// + /// In the special case when [nodes] contains one or less nodes, this method + /// returns [nodes] unchanged. + /// + /// This method constructs a graph, where vertices are [SemanticsNode]s and + /// edges are "traversed before" relation between pairs of nodes. The sort + /// order is the topological sorting of the graph, with the original order of + /// [nodes] used as the tie breaker. + /// + /// Whether a node is traversed before another node is determined by the + /// vector that connects the two nodes' centers. If the vector "points to the + /// right or down", defined as the [Offset.direction] being between `-pi/4` + /// and `3*pi/4`), then the semantics node whose center is at the end of the + /// vector is said to be traversed after. + List<SemanticsNode> sortedWithinKnot() { + if (nodes.length <= 1) { + // Trivial knot. Nothing to do. + return nodes; + } + final Map<int, SemanticsNode> nodeMap = <int, SemanticsNode>{}; + final Map<int, int> edges = <int, int>{}; + for (final SemanticsNode node in nodes) { + nodeMap[node.id] = node; + final Offset center = _pointInParentCoordinates(node, node.rect.center); + for (final SemanticsNode nextNode in nodes) { + if (identical(node, nextNode) || edges[nextNode.id] == node.id) { + // Skip self or when we've already established that the next node + // points to current node. + continue; + } + + final Offset nextCenter = _pointInParentCoordinates(nextNode, nextNode.rect.center); + final Offset centerDelta = nextCenter - center; + // When centers coincide, direction is 0.0. + final double direction = centerDelta.direction; + final bool isLtrAndForward = textDirection == TextDirection.ltr && + -math.pi / 4 < direction && direction < 3 * math.pi / 4; + final bool isRtlAndForward = textDirection == TextDirection.rtl && + (direction < -3 * math.pi / 4 || direction > 3 * math.pi / 4); + if (isLtrAndForward || isRtlAndForward) { + edges[node.id] = nextNode.id; + } + } + } + + final List<int> sortedIds = <int>[]; + final Set<int> visitedIds = <int>{}; + final List<SemanticsNode> startNodes = nodes.toList()..sort((SemanticsNode a, SemanticsNode b) { + final Offset aTopLeft = _pointInParentCoordinates(a, a.rect.topLeft); + final Offset bTopLeft = _pointInParentCoordinates(b, b.rect.topLeft); + final int verticalDiff = aTopLeft.dy.compareTo(bTopLeft.dy); + if (verticalDiff != 0) { + return -verticalDiff; + } + return -aTopLeft.dx.compareTo(bTopLeft.dx); + }); + + void search(int id) { + if (visitedIds.contains(id)) { + return; + } + visitedIds.add(id); + if (edges.containsKey(id)) { + search(edges[id]!); + } + sortedIds.add(id); + } + + startNodes.map<int>((SemanticsNode node) => node.id).forEach(search); + return sortedIds.map<SemanticsNode>((int id) => nodeMap[id]!).toList().reversed.toList(); + } +} + +/// Converts `point` to the `node`'s parent's coordinate system. +Offset _pointInParentCoordinates(SemanticsNode node, Offset point) { + if (node.transform == null) { + return point; + } + final Vector3 vector = Vector3(point.dx, point.dy, 0.0); + node.transform!.transform3(vector); + return Offset(vector.x, vector.y); +} + +/// Sorts `children` using the default sorting algorithm, and returns them as a +/// new list. +/// +/// The algorithm first breaks up children into groups such that no two nodes +/// from different groups overlap vertically. These groups are sorted vertically +/// according to their [_SemanticsSortGroup.startOffset]. +/// +/// Within each group, the nodes are sorted using +/// [_SemanticsSortGroup.sortedWithinVerticalGroup]. +/// +/// For an illustration of the algorithm see http://bit.ly/flutter-default-traversal. +List<SemanticsNode> _childrenInDefaultOrder(List<SemanticsNode> children, TextDirection textDirection) { + final List<_BoxEdge> edges = <_BoxEdge>[]; + for (final SemanticsNode child in children) { + assert(child.rect.isFinite); + // Using a small delta to shrink child rects removes overlapping cases. + final Rect childRect = child.rect.deflate(0.1); + edges.add(_BoxEdge( + isLeadingEdge: true, + offset: _pointInParentCoordinates(child, childRect.topLeft).dy, + node: child, + )); + edges.add(_BoxEdge( + isLeadingEdge: false, + offset: _pointInParentCoordinates(child, childRect.bottomRight).dy, + node: child, + )); + } + edges.sort(); + + final List<_SemanticsSortGroup> verticalGroups = <_SemanticsSortGroup>[]; + _SemanticsSortGroup? group; + int depth = 0; + for (final _BoxEdge edge in edges) { + if (edge.isLeadingEdge) { + depth += 1; + group ??= _SemanticsSortGroup( + startOffset: edge.offset, + textDirection: textDirection, + ); + group.nodes.add(edge.node); + } else { + depth -= 1; + } + if (depth == 0) { + verticalGroups.add(group!); + group = null; + } + } + verticalGroups.sort(); + + return verticalGroups + .expand((_SemanticsSortGroup group) => group.sortedWithinVerticalGroup()) + .toList(); +} + +/// The implementation of [Comparable] that implements the ordering of +/// [SemanticsNode]s in the accessibility traversal. +/// +/// [SemanticsNode]s are sorted prior to sending them to the engine side. +/// +/// This implementation considers a [node]'s [sortKey] and its position within +/// the list of its siblings. [sortKey] takes precedence over position. +class _TraversalSortNode implements Comparable<_TraversalSortNode> { + _TraversalSortNode({ + required this.node, + this.sortKey, + required this.position, + }); + + /// The node whose position this sort node determines. + final SemanticsNode node; + + /// Determines the position of this node among its siblings. + /// + /// Sort keys take precedence over other attributes, such as + /// [position]. + final SemanticsSortKey? sortKey; + + /// Position within the list of siblings as determined by the default sort + /// order. + final int position; + + @override + int compareTo(_TraversalSortNode other) { + if (sortKey == null || other.sortKey == null) { + return position - other.position; + } + return sortKey!.compareTo(other.sortKey!); + } +} + +/// Owns [SemanticsNode] objects and notifies listeners of changes to the +/// render tree semantics. +/// +/// To listen for semantic updates, call [SemanticsBinding.ensureSemantics] or +/// [PipelineOwner.ensureSemantics] to obtain a [SemanticsHandle]. This will +/// create a [SemanticsOwner] if necessary. +class SemanticsOwner extends ChangeNotifier { + /// Creates a [SemanticsOwner] that manages zero or more [SemanticsNode] objects. + SemanticsOwner({ + required this.onSemanticsUpdate, + }){ + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/semantics.dart', + className: '$SemanticsOwner', + object: this, + ); + } + } + + /// The [onSemanticsUpdate] callback is expected to dispatch [SemanticsUpdate]s + /// to the [FlutterView] that is associated with this [PipelineOwner] and/or + /// [SemanticsOwner]. + /// + /// A [SemanticsOwner] calls [onSemanticsUpdate] during [sendSemanticsUpdate] + /// after the [SemanticsUpdate] has been build, but before the [SemanticsOwner]'s + /// listeners have been notified. + final SemanticsUpdateCallback onSemanticsUpdate; + final Set<SemanticsNode> _dirtyNodes = <SemanticsNode>{}; + final Map<int, SemanticsNode> _nodes = <int, SemanticsNode>{}; + final Set<SemanticsNode> _detachedNodes = <SemanticsNode>{}; + + /// The root node of the semantics tree, if any. + /// + /// If the semantics tree is empty, returns null. + SemanticsNode? get rootSemanticsNode => _nodes[0]; + + @override + void dispose() { + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _dirtyNodes.clear(); + _nodes.clear(); + _detachedNodes.clear(); + super.dispose(); + } + + /// Update the semantics using [onSemanticsUpdate]. + void sendSemanticsUpdate() { + // Once the tree is up-to-date, verify that every node is visible. + assert(() { + final List<SemanticsNode> invisibleNodes = <SemanticsNode>[]; + // Finds the invisible nodes in the tree rooted at `node` and adds them to + // the invisibleNodes list. If a node is itself invisible, all its + // descendants will be skipped. + bool findInvisibleNodes(SemanticsNode node) { + if (node.rect.isEmpty) { + invisibleNodes.add(node); + } else if (!node.mergeAllDescendantsIntoThisNode) { + node.visitChildren(findInvisibleNodes); + } + return true; + } + + final SemanticsNode? rootSemanticsNode = this.rootSemanticsNode; + if (rootSemanticsNode != null) { + // The root node is allowed to be invisible when it has no children. + if (rootSemanticsNode.childrenCount > 0 && rootSemanticsNode.rect.isEmpty) { + invisibleNodes.add(rootSemanticsNode); + } else if (!rootSemanticsNode.mergeAllDescendantsIntoThisNode) { + rootSemanticsNode.visitChildren(findInvisibleNodes); + } + } + + if (invisibleNodes.isEmpty) { + return true; + } + + List<DiagnosticsNode> nodeToMessage(SemanticsNode invisibleNode) { + final SemanticsNode? parent = invisibleNode.parent; + return<DiagnosticsNode>[ + invisibleNode.toDiagnosticsNode(style: DiagnosticsTreeStyle.errorProperty), + parent?.toDiagnosticsNode(name: 'which was added as a child of', style: DiagnosticsTreeStyle.errorProperty) ?? ErrorDescription('which was added as the root SemanticsNode'), + ]; + } + + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Invisible SemanticsNodes should not be added to the tree.'), + ErrorDescription('The following invisible SemanticsNodes were added to the tree:'), + ...invisibleNodes.expand(nodeToMessage), + ErrorHint( + 'An invisible SemanticsNode is one whose rect is not on screen hence not reachable for users, ' + 'and its semantic information is not merged into a visible parent.' + ), + ErrorHint( + 'An invisible SemantiscNode makes the accessibility experience confusing, ' + 'as it does not provide any visual indication when the user selects it ' + 'via accessibility technologies.' + ), + ErrorHint( + 'Consider removing the above invisible SemanticsNodes if they were added by your ' + 'RenderObject.assembleSemanticsNode implementation, or filing a bug on GitHub:\n' + ' https://github.com/flutter/flutter/issues/new?template=2_bug.yml', + ), + ]); + }()); + + if (_dirtyNodes.isEmpty) { + return; + } + final Set<int> customSemanticsActionIds = <int>{}; + final List<SemanticsNode> visitedNodes = <SemanticsNode>[]; + while (_dirtyNodes.isNotEmpty) { + final List<SemanticsNode> localDirtyNodes = _dirtyNodes.where((SemanticsNode node) => !_detachedNodes.contains(node)).toList(); + _dirtyNodes.clear(); + _detachedNodes.clear(); + localDirtyNodes.sort((SemanticsNode a, SemanticsNode b) => a.depth - b.depth); + visitedNodes.addAll(localDirtyNodes); + for (final SemanticsNode node in localDirtyNodes) { + assert(node._dirty); + assert(node.parent == null || !node.parent!.isPartOfNodeMerging || node.isMergedIntoParent); + if (node.isPartOfNodeMerging) { + assert(node.mergeAllDescendantsIntoThisNode || node.parent != null); + // if we're merged into our parent, make sure our parent is added to the dirty list + if (node.parent != null && node.parent!.isPartOfNodeMerging) { + node.parent!._markDirty(); // this can add the node to the dirty list + node._dirty = false; // We don't want to send update for this node. + } + } + } + } + visitedNodes.sort((SemanticsNode a, SemanticsNode b) => a.depth - b.depth); + final SemanticsUpdateBuilder builder = SemanticsBinding.instance.createSemanticsUpdateBuilder(); + for (final SemanticsNode node in visitedNodes) { + assert(node.parent?._dirty != true); // could be null (no parent) or false (not dirty) + // The _serialize() method marks the node as not dirty, and + // recurses through the tree to do a deep serialization of all + // contiguous dirty nodes. This means that when we return here, + // it's quite possible that subsequent nodes are no longer + // dirty. We skip these here. + // We also skip any nodes that were reset and subsequently + // dropped entirely (RenderObject.markNeedsSemanticsUpdate() + // calls reset() on its SemanticsNode if onlyChanges isn't set, + // which happens e.g. when the node is no longer contributing + // semantics). + if (node._dirty && node.attached) { + node._addToUpdate(builder, customSemanticsActionIds); + } + } + _dirtyNodes.clear(); + for (final int actionId in customSemanticsActionIds) { + final CustomSemanticsAction action = CustomSemanticsAction.getAction(actionId)!; + builder.updateCustomAction(id: actionId, label: action.label, hint: action.hint, overrideId: action.action?.index ?? -1); + } + onSemanticsUpdate(builder.build()); + notifyListeners(); + } + + SemanticsActionHandler? _getSemanticsActionHandlerForId(int id, SemanticsAction action) { + SemanticsNode? result = _nodes[id]; + if (result != null && result.isPartOfNodeMerging && !result._canPerformAction(action)) { + result._visitDescendants((SemanticsNode node) { + if (node._canPerformAction(action)) { + result = node; + return false; // found node, abort walk + } + return true; // continue walk + }); + } + if (result == null || !result!._canPerformAction(action)) { + return null; + } + return result!._actions[action]; + } + + /// Asks the [SemanticsNode] with the given id to perform the given action. + /// + /// If the [SemanticsNode] has not indicated that it can perform the action, + /// this function does nothing. + /// + /// If the given `action` requires arguments they need to be passed in via + /// the `args` parameter. + void performAction(int id, SemanticsAction action, [ Object? args ]) { + final SemanticsActionHandler? handler = _getSemanticsActionHandlerForId(id, action); + if (handler != null) { + handler(args); + return; + } + + // Default actions if no [handler] was provided. + if (action == SemanticsAction.showOnScreen && _nodes[id]?._showOnScreen != null) { + _nodes[id]!._showOnScreen!(); + } + } + + SemanticsActionHandler? _getSemanticsActionHandlerForPosition(SemanticsNode node, Offset position, SemanticsAction action) { + if (node.transform != null) { + final Matrix4 inverse = Matrix4.identity(); + if (inverse.copyInverse(node.transform!) == 0.0) { + return null; + } + position = MatrixUtils.transformPoint(inverse, position); + } + if (!node.rect.contains(position)) { + return null; + } + if (node.mergeAllDescendantsIntoThisNode) { + SemanticsNode? result; + node._visitDescendants((SemanticsNode child) { + if (child._canPerformAction(action)) { + result = child; + return false; + } + return true; + }); + return result?._actions[action]; + } + if (node.hasChildren) { + for (final SemanticsNode child in node._children!.reversed) { + final SemanticsActionHandler? handler = _getSemanticsActionHandlerForPosition(child, position, action); + if (handler != null) { + return handler; + } + } + } + return node._actions[action]; + } + + /// Asks the [SemanticsNode] at the given position to perform the given action. + /// + /// If the [SemanticsNode] has not indicated that it can perform the action, + /// this function does nothing. + /// + /// If the given `action` requires arguments they need to be passed in via + /// the `args` parameter. + void performActionAt(Offset position, SemanticsAction action, [ Object? args ]) { + final SemanticsNode? node = rootSemanticsNode; + if (node == null) { + return; + } + final SemanticsActionHandler? handler = _getSemanticsActionHandlerForPosition(node, position, action); + if (handler != null) { + handler(args); + } + } + + @override + String toString() => describeIdentity(this); +} + +/// Describes the semantic information associated with the owning +/// [RenderObject]. +/// +/// The information provided in the configuration is used to generate the +/// semantics tree. +class SemanticsConfiguration { + + // SEMANTIC BOUNDARY BEHAVIOR + + /// Whether the [RenderObject] owner of this configuration wants to own its + /// own [SemanticsNode]. + /// + /// When set to true semantic information associated with the [RenderObject] + /// owner of this configuration or any of its descendants will not leak into + /// parents. The [SemanticsNode] generated out of this configuration will + /// act as a boundary. + /// + /// Whether descendants of the owning [RenderObject] can add their semantic + /// information to the [SemanticsNode] introduced by this configuration + /// is controlled by [explicitChildNodes]. + /// + /// This has to be true if [isMergingSemanticsOfDescendants] is also true. + bool get isSemanticBoundary => _isSemanticBoundary; + bool _isSemanticBoundary = false; + set isSemanticBoundary(bool value) { + assert(!isMergingSemanticsOfDescendants || value); + _isSemanticBoundary = value; + } + + /// Whether to block pointer related user actions for the rendering subtree. + /// + /// Setting this to true will prevent users from interacting with the + /// rendering object produces this semantics configuration and its subtree + /// through pointer-related [SemanticsAction]s in assistive technologies. + /// + /// The [SemanticsNode] created from this semantics configuration is still + /// focusable by assistive technologies. Only pointer-related + /// [SemanticsAction]s, such as [SemanticsAction.tap] or its friends, are + /// blocked. + /// + /// If this semantics configuration is merged into a parent semantics node, + /// only the [SemanticsAction]s from this rendering object and the rendering + /// objects in the subtree are blocked. + bool isBlockingUserActions = false; + + /// Whether the configuration forces all children of the owning [RenderObject] + /// that want to contribute semantic information to the semantics tree to do + /// so in the form of explicit [SemanticsNode]s. + /// + /// When set to false children of the owning [RenderObject] are allowed to + /// annotate [SemanticsNode]s of their parent with the semantic information + /// they want to contribute to the semantic tree. + /// When set to true the only way for children of the owning [RenderObject] + /// to contribute semantic information to the semantic tree is to introduce + /// new explicit [SemanticsNode]s to the tree. + /// + /// This setting is often used in combination with [isSemanticBoundary] to + /// create semantic boundaries that are either writable or not for children. + bool explicitChildNodes = false; + + /// Whether the owning [RenderObject] makes other [RenderObject]s previously + /// painted within the same semantic boundary unreachable for accessibility + /// purposes. + /// + /// If set to true, the semantic information for all siblings and cousins of + /// this node, that are earlier in a depth-first pre-order traversal, are + /// dropped from the semantics tree up until a semantic boundary (as defined + /// by [isSemanticBoundary]) is reached. + /// + /// If [isSemanticBoundary] and [isBlockingSemanticsOfPreviouslyPaintedNodes] + /// is set on the same node, all previously painted siblings and cousins up + /// until the next ancestor that is a semantic boundary are dropped. + /// + /// Paint order as established by [RenderObject.visitChildrenForSemantics] is + /// used to determine if a node is previous to this one. + bool isBlockingSemanticsOfPreviouslyPaintedNodes = false; + + // SEMANTIC ANNOTATIONS + // These will end up on [SemanticsNode]s generated from + // [SemanticsConfiguration]s. + + /// Whether this configuration is empty. + /// + /// An empty configuration doesn't contain any semantic information that it + /// wants to contribute to the semantics tree. + bool get hasBeenAnnotated => _hasBeenAnnotated; + bool _hasBeenAnnotated = false; + + /// The actions (with associated action handlers) that this configuration + /// would like to contribute to the semantics tree. + /// + /// See also: + /// + /// * [addAction] to add an action. + final Map<SemanticsAction, SemanticsActionHandler> _actions = <SemanticsAction, SemanticsActionHandler>{}; + + int get _effectiveActionsAsBits => isBlockingUserActions ? _actionsAsBits & _kUnblockedUserActions : _actionsAsBits; + int _actionsAsBits = 0; + + /// Adds an `action` to the semantics tree. + /// + /// The provided `handler` is called to respond to the user triggered + /// `action`. + void _addAction(SemanticsAction action, SemanticsActionHandler handler) { + _actions[action] = handler; + _actionsAsBits |= action.index; + _hasBeenAnnotated = true; + } + + /// Adds an `action` to the semantics tree, whose `handler` does not expect + /// any arguments. + /// + /// The provided `handler` is called to respond to the user triggered + /// `action`. + void _addArgumentlessAction(SemanticsAction action, VoidCallback handler) { + _addAction(action, (Object? args) { + assert(args == null); + handler(); + }); + } + + /// The handler for [SemanticsAction.tap]. + /// + /// This is the semantic equivalent of a user briefly tapping the screen with + /// the finger without moving it. For example, a button should implement this + /// action. + /// + /// VoiceOver users on iOS and TalkBack users on Android can trigger this + /// action by double-tapping the screen while an element is focused. + /// + /// On Android prior to Android Oreo a double-tap on the screen while an + /// element with an [onTap] handler is focused will not call the registered + /// handler. Instead, Android will simulate a pointer down and up event at the + /// center of the focused element. Those pointer events will get dispatched + /// just like a regular tap with TalkBack disabled would: The events will get + /// processed by any [GestureDetector] listening for gestures in the center of + /// the focused element. Therefore, to ensure that [onTap] handlers work + /// properly on Android versions prior to Oreo, a [GestureDetector] with an + /// onTap handler should always be wrapping an element that defines a + /// semantic [onTap] handler. By default a [GestureDetector] will register its + /// own semantic [onTap] handler that follows this principle. + VoidCallback? get onTap => _onTap; + VoidCallback? _onTap; + set onTap(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.tap, value!); + _onTap = value; + } + + /// The handler for [SemanticsAction.longPress]. + /// + /// This is the semantic equivalent of a user pressing and holding the screen + /// with the finger for a few seconds without moving it. + /// + /// VoiceOver users on iOS and TalkBack users on Android can trigger this + /// action by double-tapping the screen without lifting the finger after the + /// second tap. + VoidCallback? get onLongPress => _onLongPress; + VoidCallback? _onLongPress; + set onLongPress(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.longPress, value!); + _onLongPress = value; + } + + /// The handler for [SemanticsAction.scrollLeft]. + /// + /// This is the semantic equivalent of a user moving their finger across the + /// screen from right to left. It should be recognized by controls that are + /// horizontally scrollable. + /// + /// VoiceOver users on iOS can trigger this action by swiping left with three + /// fingers. TalkBack users on Android can trigger this action by swiping + /// right and then left in one motion path. On Android, [onScrollUp] and + /// [onScrollLeft] share the same gesture. Therefore, only on of them should + /// be provided. + VoidCallback? get onScrollLeft => _onScrollLeft; + VoidCallback? _onScrollLeft; + set onScrollLeft(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.scrollLeft, value!); + _onScrollLeft = value; + } + + /// The handler for [SemanticsAction.dismiss]. + /// + /// This is a request to dismiss the currently focused node. + /// + /// TalkBack users on Android can trigger this action in the local context + /// menu, and VoiceOver users on iOS can trigger this action with a standard + /// gesture or menu option. + VoidCallback? get onDismiss => _onDismiss; + VoidCallback? _onDismiss; + set onDismiss(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.dismiss, value!); + _onDismiss = value; + } + + /// The handler for [SemanticsAction.scrollRight]. + /// + /// This is the semantic equivalent of a user moving their finger across the + /// screen from left to right. It should be recognized by controls that are + /// horizontally scrollable. + /// + /// VoiceOver users on iOS can trigger this action by swiping right with three + /// fingers. TalkBack users on Android can trigger this action by swiping + /// left and then right in one motion path. On Android, [onScrollDown] and + /// [onScrollRight] share the same gesture. Therefore, only on of them should + /// be provided. + VoidCallback? get onScrollRight => _onScrollRight; + VoidCallback? _onScrollRight; + set onScrollRight(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.scrollRight, value!); + _onScrollRight = value; + } + + /// The handler for [SemanticsAction.scrollUp]. + /// + /// This is the semantic equivalent of a user moving their finger across the + /// screen from bottom to top. It should be recognized by controls that are + /// vertically scrollable. + /// + /// VoiceOver users on iOS can trigger this action by swiping up with three + /// fingers. TalkBack users on Android can trigger this action by swiping + /// right and then left in one motion path. On Android, [onScrollUp] and + /// [onScrollLeft] share the same gesture. Therefore, only on of them should + /// be provided. + VoidCallback? get onScrollUp => _onScrollUp; + VoidCallback? _onScrollUp; + set onScrollUp(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.scrollUp, value!); + _onScrollUp = value; + } + + /// The handler for [SemanticsAction.scrollDown]. + /// + /// This is the semantic equivalent of a user moving their finger across the + /// screen from top to bottom. It should be recognized by controls that are + /// vertically scrollable. + /// + /// VoiceOver users on iOS can trigger this action by swiping down with three + /// fingers. TalkBack users on Android can trigger this action by swiping + /// left and then right in one motion path. On Android, [onScrollDown] and + /// [onScrollRight] share the same gesture. Therefore, only on of them should + /// be provided. + VoidCallback? get onScrollDown => _onScrollDown; + VoidCallback? _onScrollDown; + set onScrollDown(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.scrollDown, value!); + _onScrollDown = value; + } + + /// The handler for [SemanticsAction.increase]. + /// + /// This is a request to increase the value represented by the widget. For + /// example, this action might be recognized by a slider control. + /// + /// If [this.value] is set, [increasedValue] must also be provided and + /// [onIncrease] must ensure that [this.value] will be set to + /// [increasedValue]. + /// + /// VoiceOver users on iOS can trigger this action by swiping up with one + /// finger. TalkBack users on Android can trigger this action by pressing the + /// volume up button. + VoidCallback? get onIncrease => _onIncrease; + VoidCallback? _onIncrease; + set onIncrease(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.increase, value!); + _onIncrease = value; + } + + /// The handler for [SemanticsAction.decrease]. + /// + /// This is a request to decrease the value represented by the widget. For + /// example, this action might be recognized by a slider control. + /// + /// If [this.value] is set, [decreasedValue] must also be provided and + /// [onDecrease] must ensure that [this.value] will be set to + /// [decreasedValue]. + /// + /// VoiceOver users on iOS can trigger this action by swiping down with one + /// finger. TalkBack users on Android can trigger this action by pressing the + /// volume down button. + VoidCallback? get onDecrease => _onDecrease; + VoidCallback? _onDecrease; + set onDecrease(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.decrease, value!); + _onDecrease = value; + } + + /// The handler for [SemanticsAction.copy]. + /// + /// This is a request to copy the current selection to the clipboard. + /// + /// TalkBack users on Android can trigger this action from the local context + /// menu of a text field, for example. + VoidCallback? get onCopy => _onCopy; + VoidCallback? _onCopy; + set onCopy(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.copy, value!); + _onCopy = value; + } + + /// The handler for [SemanticsAction.cut]. + /// + /// This is a request to cut the current selection and place it in the + /// clipboard. + /// + /// TalkBack users on Android can trigger this action from the local context + /// menu of a text field, for example. + VoidCallback? get onCut => _onCut; + VoidCallback? _onCut; + set onCut(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.cut, value!); + _onCut = value; + } + + /// The handler for [SemanticsAction.paste]. + /// + /// This is a request to paste the current content of the clipboard. + /// + /// TalkBack users on Android can trigger this action from the local context + /// menu of a text field, for example. + VoidCallback? get onPaste => _onPaste; + VoidCallback? _onPaste; + set onPaste(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.paste, value!); + _onPaste = value; + } + + /// The handler for [SemanticsAction.showOnScreen]. + /// + /// A request to fully show the semantics node on screen. For example, this + /// action might be send to a node in a scrollable list that is partially off + /// screen to bring it on screen. + /// + /// For elements in a scrollable list the framework provides a default + /// implementation for this action and it is not advised to provide a + /// custom one via this setter. + VoidCallback? get onShowOnScreen => _onShowOnScreen; + VoidCallback? _onShowOnScreen; + set onShowOnScreen(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.showOnScreen, value!); + _onShowOnScreen = value; + } + + /// The handler for [SemanticsAction.moveCursorForwardByCharacter]. + /// + /// This handler is invoked when the user wants to move the cursor in a + /// text field forward by one character. + /// + /// TalkBack users can trigger this by pressing the volume up key while the + /// input focus is in a text field. + MoveCursorHandler? get onMoveCursorForwardByCharacter => _onMoveCursorForwardByCharacter; + MoveCursorHandler? _onMoveCursorForwardByCharacter; + set onMoveCursorForwardByCharacter(MoveCursorHandler? value) { + assert(value != null); + _addAction(SemanticsAction.moveCursorForwardByCharacter, (Object? args) { + final bool extendSelection = args! as bool; + value!(extendSelection); + }); + _onMoveCursorForwardByCharacter = value; + } + + /// The handler for [SemanticsAction.moveCursorBackwardByCharacter]. + /// + /// This handler is invoked when the user wants to move the cursor in a + /// text field backward by one character. + /// + /// TalkBack users can trigger this by pressing the volume down key while the + /// input focus is in a text field. + MoveCursorHandler? get onMoveCursorBackwardByCharacter => _onMoveCursorBackwardByCharacter; + MoveCursorHandler? _onMoveCursorBackwardByCharacter; + set onMoveCursorBackwardByCharacter(MoveCursorHandler? value) { + assert(value != null); + _addAction(SemanticsAction.moveCursorBackwardByCharacter, (Object? args) { + final bool extendSelection = args! as bool; + value!(extendSelection); + }); + _onMoveCursorBackwardByCharacter = value; + } + + /// The handler for [SemanticsAction.moveCursorForwardByWord]. + /// + /// This handler is invoked when the user wants to move the cursor in a + /// text field backward by one word. + /// + /// TalkBack users can trigger this by pressing the volume down key while the + /// input focus is in a text field. + MoveCursorHandler? get onMoveCursorForwardByWord => _onMoveCursorForwardByWord; + MoveCursorHandler? _onMoveCursorForwardByWord; + set onMoveCursorForwardByWord(MoveCursorHandler? value) { + assert(value != null); + _addAction(SemanticsAction.moveCursorForwardByWord, (Object? args) { + final bool extendSelection = args! as bool; + value!(extendSelection); + }); + _onMoveCursorForwardByCharacter = value; + } + + /// The handler for [SemanticsAction.moveCursorBackwardByWord]. + /// + /// This handler is invoked when the user wants to move the cursor in a + /// text field backward by one word. + /// + /// TalkBack users can trigger this by pressing the volume down key while the + /// input focus is in a text field. + MoveCursorHandler? get onMoveCursorBackwardByWord => _onMoveCursorBackwardByWord; + MoveCursorHandler? _onMoveCursorBackwardByWord; + set onMoveCursorBackwardByWord(MoveCursorHandler? value) { + assert(value != null); + _addAction(SemanticsAction.moveCursorBackwardByWord, (Object? args) { + final bool extendSelection = args! as bool; + value!(extendSelection); + }); + _onMoveCursorBackwardByCharacter = value; + } + + /// The handler for [SemanticsAction.setSelection]. + /// + /// This handler is invoked when the user either wants to change the currently + /// selected text in a text field or change the position of the cursor. + /// + /// TalkBack users can trigger this handler by selecting "Move cursor to + /// beginning/end" or "Select all" from the local context menu. + SetSelectionHandler? get onSetSelection => _onSetSelection; + SetSelectionHandler? _onSetSelection; + set onSetSelection(SetSelectionHandler? value) { + assert(value != null); + _addAction(SemanticsAction.setSelection, (Object? args) { + assert(args != null && args is Map); + final Map<String, int> selection = (args! as Map<dynamic, dynamic>).cast<String, int>(); + assert(selection['base'] != null && selection['extent'] != null); + value!(TextSelection( + baseOffset: selection['base']!, + extentOffset: selection['extent']!, + )); + }); + _onSetSelection = value; + } + + /// The handler for [SemanticsAction.setText]. + /// + /// This handler is invoked when the user wants to replace the current text in + /// the text field with a new text. + /// + /// Voice access users can trigger this handler by speaking "type <text>" to + /// their Android devices. + SetTextHandler? get onSetText => _onSetText; + SetTextHandler? _onSetText; + set onSetText(SetTextHandler? value) { + assert(value != null); + _addAction(SemanticsAction.setText, (Object? args) { + assert(args != null && args is String); + final String text = args! as String; + value!(text); + }); + _onSetText = value; + } + + /// The handler for [SemanticsAction.didGainAccessibilityFocus]. + /// + /// This handler is invoked when the node annotated with this handler gains + /// the accessibility focus. The accessibility focus is the + /// green (on Android with TalkBack) or black (on iOS with VoiceOver) + /// rectangle shown on screen to indicate what element an accessibility + /// user is currently interacting with. + /// + /// The accessibility focus is different from the input focus. The input focus + /// is usually held by the element that currently responds to keyboard inputs. + /// Accessibility focus and input focus can be held by two different nodes! + /// + /// See also: + /// + /// * [onDidLoseAccessibilityFocus], which is invoked when the accessibility + /// focus is removed from the node. + /// * [FocusNode], [FocusScope], [FocusManager], which manage the input focus. + VoidCallback? get onDidGainAccessibilityFocus => _onDidGainAccessibilityFocus; + VoidCallback? _onDidGainAccessibilityFocus; + set onDidGainAccessibilityFocus(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.didGainAccessibilityFocus, value!); + _onDidGainAccessibilityFocus = value; + } + + /// The handler for [SemanticsAction.didLoseAccessibilityFocus]. + /// + /// This handler is invoked when the node annotated with this handler + /// loses the accessibility focus. The accessibility focus is + /// the green (on Android with TalkBack) or black (on iOS with VoiceOver) + /// rectangle shown on screen to indicate what element an accessibility + /// user is currently interacting with. + /// + /// The accessibility focus is different from the input focus. The input focus + /// is usually held by the element that currently responds to keyboard inputs. + /// Accessibility focus and input focus can be held by two different nodes! + /// + /// See also: + /// + /// * [onDidGainAccessibilityFocus], which is invoked when the node gains + /// accessibility focus. + /// * [FocusNode], [FocusScope], [FocusManager], which manage the input focus. + VoidCallback? get onDidLoseAccessibilityFocus => _onDidLoseAccessibilityFocus; + VoidCallback? _onDidLoseAccessibilityFocus; + set onDidLoseAccessibilityFocus(VoidCallback? value) { + _addArgumentlessAction(SemanticsAction.didLoseAccessibilityFocus, value!); + _onDidLoseAccessibilityFocus = value; + } + + /// A delegate that decides how to handle [SemanticsConfiguration]s produced + /// in the widget subtree. + /// + /// The [SemanticsConfiguration]s are produced by rendering objects in the + /// subtree and want to merge up to their parent. This delegate can decide + /// which of these should be merged together to form sibling SemanticsNodes and + /// which of them should be merged upwards into the parent SemanticsNode. + /// + /// The input list of [SemanticsConfiguration]s can be empty if the rendering + /// object of this semantics configuration is a leaf node or child rendering + /// objects do not contribute to the semantics. + ChildSemanticsConfigurationsDelegate? get childConfigurationsDelegate => _childConfigurationsDelegate; + ChildSemanticsConfigurationsDelegate? _childConfigurationsDelegate; + set childConfigurationsDelegate(ChildSemanticsConfigurationsDelegate? value) { + assert(value != null); + _childConfigurationsDelegate = value; + // Setting the childConfigsDelegate does not annotate any meaningful + // semantics information of the config. + } + + /// Returns the action handler registered for [action] or null if none was + /// registered. + SemanticsActionHandler? getActionHandler(SemanticsAction action) => _actions[action]; + + /// Determines the position of this node among its siblings in the traversal + /// sort order. + /// + /// This is used to describe the order in which the semantic node should be + /// traversed by the accessibility services on the platform (e.g. VoiceOver + /// on iOS and TalkBack on Android). + /// + /// Whether this sort key has an effect on the [SemanticsNode] sort order is + /// subject to how this configuration is used. For example, the [absorb] + /// method may decide to not use this key when it combines multiple + /// [SemanticsConfiguration] objects. + SemanticsSortKey? get sortKey => _sortKey; + SemanticsSortKey? _sortKey; + set sortKey(SemanticsSortKey? value) { + assert(value != null); + _sortKey = value; + _hasBeenAnnotated = true; + } + + /// The index of this node within the parent's list of semantic children. + /// + /// This includes all semantic nodes, not just those currently in the + /// child list. For example, if a scrollable has five children but the first + /// two are not visible (and thus not included in the list of children), then + /// the index of the last node will still be 4. + int? get indexInParent => _indexInParent; + int? _indexInParent; + set indexInParent(int? value) { + _indexInParent = value; + _hasBeenAnnotated = true; + } + + /// The total number of scrollable children that contribute to semantics. + /// + /// If the number of children are unknown or unbounded, this value will be + /// null. + int? get scrollChildCount => _scrollChildCount; + int? _scrollChildCount; + set scrollChildCount(int? value) { + if (value == scrollChildCount) { + return; + } + _scrollChildCount = value; + _hasBeenAnnotated = true; + } + + /// The index of the first visible scrollable child that contributes to + /// semantics. + int? get scrollIndex => _scrollIndex; + int? _scrollIndex; + set scrollIndex(int? value) { + if (value == scrollIndex) { + return; + } + _scrollIndex = value; + _hasBeenAnnotated = true; + } + + /// The id of the platform view, whose semantics nodes will be added as + /// children to this node. + int? get platformViewId => _platformViewId; + int? _platformViewId; + set platformViewId(int? value) { + if (value == platformViewId) { + return; + } + _platformViewId = value; + _hasBeenAnnotated = true; + } + + /// The maximum number of characters that can be entered into an editable + /// text field. + /// + /// For the purpose of this function a character is defined as one Unicode + /// scalar value. + /// + /// This should only be set when [isTextField] is true. Defaults to null, + /// which means no limit is imposed on the text field. + int? get maxValueLength => _maxValueLength; + int? _maxValueLength; + set maxValueLength(int? value) { + if (value == maxValueLength) { + return; + } + _maxValueLength = value; + _hasBeenAnnotated = true; + } + + /// The current number of characters that have been entered into an editable + /// text field. + /// + /// For the purpose of this function a character is defined as one Unicode + /// scalar value. + /// + /// This should only be set when [isTextField] is true. Must be set when + /// [maxValueLength] is set. + int? get currentValueLength => _currentValueLength; + int? _currentValueLength; + set currentValueLength(int? value) { + if (value == currentValueLength) { + return; + } + _currentValueLength = value; + _hasBeenAnnotated = true; + } + + /// Whether the semantic information provided by the owning [RenderObject] and + /// all of its descendants should be treated as one logical entity. + /// + /// If set to true, the descendants of the owning [RenderObject]'s + /// [SemanticsNode] will merge their semantic information into the + /// [SemanticsNode] representing the owning [RenderObject]. + /// + /// Setting this to true requires that [isSemanticBoundary] is also true. + bool get isMergingSemanticsOfDescendants => _isMergingSemanticsOfDescendants; + bool _isMergingSemanticsOfDescendants = false; + set isMergingSemanticsOfDescendants(bool value) { + assert(isSemanticBoundary); + _isMergingSemanticsOfDescendants = value; + _hasBeenAnnotated = true; + } + + /// The handlers for each supported [CustomSemanticsAction]. + /// + /// Whenever a custom accessibility action is added to a node, the action + /// [SemanticsAction.customAction] is automatically added. A handler is + /// created which uses the passed argument to lookup the custom action + /// handler from this map and invoke it, if present. + Map<CustomSemanticsAction, VoidCallback> get customSemanticsActions => _customSemanticsActions; + Map<CustomSemanticsAction, VoidCallback> _customSemanticsActions = <CustomSemanticsAction, VoidCallback>{}; + set customSemanticsActions(Map<CustomSemanticsAction, VoidCallback> value) { + _hasBeenAnnotated = true; + _actionsAsBits |= SemanticsAction.customAction.index; + _customSemanticsActions = value; + _actions[SemanticsAction.customAction] = _onCustomSemanticsAction; + } + + void _onCustomSemanticsAction(Object? args) { + final CustomSemanticsAction? action = CustomSemanticsAction.getAction(args! as int); + if (action == null) { + return; + } + final VoidCallback? callback = _customSemanticsActions[action]; + if (callback != null) { + callback(); + } + } + + /// {@macro flutter.semantics.SemanticsProperties.identifier} + String get identifier => _identifier; + String _identifier = ''; + set identifier(String identifier) { + _identifier = identifier; + _hasBeenAnnotated = true; + } + + /// A textual description of the owning [RenderObject]. + /// + /// Setting this attribute will override the [attributedLabel]. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also: + /// + /// * [attributedLabel], which is the [AttributedString] of this property. + String get label => _attributedLabel.string; + set label(String label) { + _attributedLabel = AttributedString(label); + _hasBeenAnnotated = true; + } + + /// A textual description of the owning [RenderObject] in [AttributedString] + /// format. + /// + /// On iOS this is used for the `accessibilityAttributedLabel` property + /// defined in the `UIAccessibility` Protocol. On Android it is concatenated + /// together with [attributedValue] and [attributedHint] in the following + /// order: [attributedValue], [attributedLabel], [attributedHint]. The + /// concatenated value is then used as the `Text` description. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also: + /// + /// * [label], which is the raw text of this property. + AttributedString get attributedLabel => _attributedLabel; + AttributedString _attributedLabel = AttributedString(''); + set attributedLabel(AttributedString attributedLabel) { + _attributedLabel = attributedLabel; + _hasBeenAnnotated = true; + } + + /// A textual description for the current value of the owning [RenderObject]. + /// + /// Setting this attribute will override the [attributedValue]. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also: + /// + /// * [attributedValue], which is the [AttributedString] of this property. + /// * [increasedValue] and [attributedIncreasedValue], which describe what + /// [value] will be after performing [SemanticsAction.increase]. + /// * [decreasedValue] and [attributedDecreasedValue], which describe what + /// [value] will be after performing [SemanticsAction.decrease]. + String get value => _attributedValue.string; + set value(String value) { + _attributedValue = AttributedString(value); + _hasBeenAnnotated = true; + } + + /// A textual description for the current value of the owning [RenderObject] + /// in [AttributedString] format. + /// + /// On iOS this is used for the `accessibilityAttributedValue` property + /// defined in the `UIAccessibility` Protocol. On Android it is concatenated + /// together with [attributedLabel] and [attributedHint] in the following + /// order: [attributedValue], [attributedLabel], [attributedHint]. The + /// concatenated value is then used as the `Text` description. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also: + /// + /// * [value], which is the raw text of this property. + /// * [attributedIncreasedValue], which describes what [value] will be after + /// performing [SemanticsAction.increase]. + /// * [attributedDecreasedValue], which describes what [value] will be after + /// performing [SemanticsAction.decrease]. + AttributedString get attributedValue => _attributedValue; + AttributedString _attributedValue = AttributedString(''); + set attributedValue(AttributedString attributedValue) { + _attributedValue = attributedValue; + _hasBeenAnnotated = true; + } + + /// The value that [value] will have after performing a + /// [SemanticsAction.increase] action. + /// + /// Setting this attribute will override the [attributedIncreasedValue]. + /// + /// One of the [attributedIncreasedValue] or [increasedValue] must be set if + /// a handler for [SemanticsAction.increase] is provided and one of the + /// [value] or [attributedValue] is set. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also: + /// + /// * [attributedIncreasedValue], which is the [AttributedString] of this property. + String get increasedValue => _attributedIncreasedValue.string; + set increasedValue(String increasedValue) { + _attributedIncreasedValue = AttributedString(increasedValue); + _hasBeenAnnotated = true; + } + + /// The value that [value] will have after performing a + /// [SemanticsAction.increase] action in [AttributedString] format. + /// + /// One of the [attributedIncreasedValue] or [increasedValue] must be set if + /// a handler for [SemanticsAction.increase] is provided and one of the + /// [value] or [attributedValue] is set. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also: + /// + /// * [increasedValue], which is the raw text of this property. + AttributedString get attributedIncreasedValue => _attributedIncreasedValue; + AttributedString _attributedIncreasedValue = AttributedString(''); + set attributedIncreasedValue(AttributedString attributedIncreasedValue) { + _attributedIncreasedValue = attributedIncreasedValue; + _hasBeenAnnotated = true; + } + + /// The value that [value] will have after performing a + /// [SemanticsAction.decrease] action. + /// + /// Setting this attribute will override the [attributedDecreasedValue]. + /// + /// One of the [attributedDecreasedValue] or [decreasedValue] must be set if + /// a handler for [SemanticsAction.decrease] is provided and one of the + /// [value] or [attributedValue] is set. + /// + /// The reading direction is given by [textDirection]. + /// + /// * [attributedDecreasedValue], which is the [AttributedString] of this property. + String get decreasedValue => _attributedDecreasedValue.string; + set decreasedValue(String decreasedValue) { + _attributedDecreasedValue = AttributedString(decreasedValue); + _hasBeenAnnotated = true; + } + + /// The value that [value] will have after performing a + /// [SemanticsAction.decrease] action in [AttributedString] format. + /// + /// One of the [attributedDecreasedValue] or [decreasedValue] must be set if + /// a handler for [SemanticsAction.decrease] is provided and one of the + /// [value] or [attributedValue] is set. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also: + /// + /// * [decreasedValue], which is the raw text of this property. + AttributedString get attributedDecreasedValue => _attributedDecreasedValue; + AttributedString _attributedDecreasedValue = AttributedString(''); + set attributedDecreasedValue(AttributedString attributedDecreasedValue) { + _attributedDecreasedValue = attributedDecreasedValue; + _hasBeenAnnotated = true; + } + + /// A brief description of the result of performing an action on this node. + /// + /// Setting this attribute will override the [attributedHint]. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also: + /// + /// * [attributedHint], which is the [AttributedString] of this property. + String get hint => _attributedHint.string; + set hint(String hint) { + _attributedHint = AttributedString(hint); + _hasBeenAnnotated = true; + } + + /// A brief description of the result of performing an action on this node in + /// [AttributedString] format. + /// + /// On iOS this is used for the `accessibilityAttributedHint` property + /// defined in the `UIAccessibility` Protocol. On Android it is concatenated + /// together with [attributedLabel] and [attributedValue] in the following + /// order: [attributedValue], [attributedLabel], [attributedHint]. The + /// concatenated value is then used as the `Text` description. + /// + /// The reading direction is given by [textDirection]. + /// + /// See also: + /// + /// * [hint], which is the raw text of this property. + AttributedString get attributedHint => _attributedHint; + AttributedString _attributedHint = AttributedString(''); + set attributedHint(AttributedString attributedHint) { + _attributedHint = attributedHint; + _hasBeenAnnotated = true; + } + + /// A textual description of the widget's tooltip. + /// + /// The reading direction is given by [textDirection]. + String get tooltip => _tooltip; + String _tooltip = ''; + set tooltip(String tooltip) { + _tooltip = tooltip; + _hasBeenAnnotated = true; + } + + /// Provides hint values which override the default hints on supported + /// platforms. + SemanticsHintOverrides? get hintOverrides => _hintOverrides; + SemanticsHintOverrides? _hintOverrides; + set hintOverrides(SemanticsHintOverrides? value) { + if (value == null) { + return; + } + _hintOverrides = value; + _hasBeenAnnotated = true; + } + + /// The elevation in z-direction at which the owning [RenderObject] is + /// located relative to its parent. + double get elevation => _elevation; + double _elevation = 0.0; + set elevation(double value) { + assert(value >= 0.0); + if (value == _elevation) { + return; + } + _elevation = value; + _hasBeenAnnotated = true; + } + + /// The extend that the owning [RenderObject] occupies in z-direction starting + /// at [elevation]. + /// + /// It's extremely rare to set this value directly. Instead, it is calculated + /// implicitly when other [SemanticsConfiguration]s are merged into this one + /// via [absorb]. + double get thickness => _thickness; + double _thickness = 0.0; + set thickness(double value) { + assert(value >= 0.0); + if (value == _thickness) { + return; + } + _thickness = value; + _hasBeenAnnotated = true; + } + + /// Whether the semantics node is the root of a subtree for which values + /// should be announced. + /// + /// See also: + /// + /// * [SemanticsFlag.scopesRoute], for a full description of route scoping. + bool get scopesRoute => _hasFlag(SemanticsFlag.scopesRoute); + set scopesRoute(bool value) { + _setFlag(SemanticsFlag.scopesRoute, value); + } + + /// Whether the semantics node contains the label of a route. + /// + /// See also: + /// + /// * [SemanticsFlag.namesRoute], for a full description of route naming. + bool get namesRoute => _hasFlag(SemanticsFlag.namesRoute); + set namesRoute(bool value) { + _setFlag(SemanticsFlag.namesRoute, value); + } + + /// Whether the semantics node represents an image. + bool get isImage => _hasFlag(SemanticsFlag.isImage); + set isImage(bool value) { + _setFlag(SemanticsFlag.isImage, value); + } + + /// Whether the semantics node is a live region. + /// + /// A live region indicates that updates to semantics node are important. + /// Platforms may use this information to make polite announcements to the + /// user to inform them of updates to this node. + /// + /// An example of a live region is a [SnackBar] widget. On Android and iOS, + /// live region causes a polite announcement to be generated automatically, + /// even if the widget does not have accessibility focus. This announcement + /// may not be spoken if the OS accessibility services are already + /// announcing something else, such as reading the label of a focused widget + /// or providing a system announcement. + /// + /// See also: + /// + /// * [SemanticsFlag.isLiveRegion], the semantics flag that this setting controls. + bool get liveRegion => _hasFlag(SemanticsFlag.isLiveRegion); + set liveRegion(bool value) { + _setFlag(SemanticsFlag.isLiveRegion, value); + } + + /// The reading direction for the text in [label], [value], [hint], + /// [increasedValue], and [decreasedValue]. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? textDirection) { + _textDirection = textDirection; + _hasBeenAnnotated = true; + } + + /// Whether the owning [RenderObject] is selected (true) or not (false). + /// + /// This is different from having accessibility focus. The element that is + /// accessibility focused may or may not be selected; e.g. a [ListTile] can have + /// accessibility focus but have its [ListTile.selected] property set to false, + /// in which case it will not be flagged as selected. + bool get isSelected => _hasFlag(SemanticsFlag.isSelected); + set isSelected(bool value) { + _setFlag(SemanticsFlag.isSelected, value); + } + + /// If this node has Boolean state that can be controlled by the user, whether + /// that state is expanded or collapsed, corresponding to true and false, respectively. + /// + /// Do not call the setter for this field if the owning [RenderObject] doesn't + /// have expanded/collapsed state that can be controlled by the user. + /// + /// The getter returns null if the owning [RenderObject] does not have + /// expanded/collapsed state. + bool? get isExpanded => _hasFlag(SemanticsFlag.hasExpandedState) ? _hasFlag(SemanticsFlag.isExpanded) : null; + set isExpanded(bool? value) { + _setFlag(SemanticsFlag.hasExpandedState, true); + _setFlag(SemanticsFlag.isExpanded, value!); + } + + /// Whether the owning [RenderObject] is currently enabled. + /// + /// A disabled object does not respond to user interactions. Only objects that + /// usually respond to user interactions, but which currently do not (like a + /// disabled button) should be marked as disabled. + /// + /// The setter should not be called for objects (like static text) that never + /// respond to user interactions. + /// + /// The getter will return null if the owning [RenderObject] doesn't support + /// the concept of being enabled/disabled. + /// + /// This property does not control whether semantics are enabled. If you wish to + /// disable semantics for a particular widget, you should use an [ExcludeSemantics] + /// widget. + bool? get isEnabled => _hasFlag(SemanticsFlag.hasEnabledState) ? _hasFlag(SemanticsFlag.isEnabled) : null; + set isEnabled(bool? value) { + _setFlag(SemanticsFlag.hasEnabledState, true); + _setFlag(SemanticsFlag.isEnabled, value!); + } + + /// If this node has Boolean state that can be controlled by the user, whether + /// that state is checked or unchecked, corresponding to true and false, + /// respectively. + /// + /// Do not call the setter for this field if the owning [RenderObject] doesn't + /// have checked/unchecked state that can be controlled by the user. + /// + /// The getter returns null if the owning [RenderObject] does not have + /// checked/unchecked state. + bool? get isChecked => _hasFlag(SemanticsFlag.hasCheckedState) ? _hasFlag(SemanticsFlag.isChecked) : null; + set isChecked(bool? value) { + assert(value != true || isCheckStateMixed != true); + _setFlag(SemanticsFlag.hasCheckedState, true); + _setFlag(SemanticsFlag.isChecked, value!); + } + + /// If this node has tristate that can be controlled by the user, whether + /// that state is in its mixed state. + /// + /// Do not call the setter for this field if the owning [RenderObject] doesn't + /// have checked/unchecked state that can be controlled by the user. + /// + /// The getter returns null if the owning [RenderObject] does not have + /// mixed checked state. + bool? get isCheckStateMixed => _hasFlag(SemanticsFlag.hasCheckedState) ? _hasFlag(SemanticsFlag.isCheckStateMixed) : null; + set isCheckStateMixed(bool? value) { + assert(value != true || isChecked != true); + _setFlag(SemanticsFlag.hasCheckedState, true); + _setFlag(SemanticsFlag.isCheckStateMixed, value!); + } + + /// If this node has Boolean state that can be controlled by the user, whether + /// that state is on or off, corresponding to true and false, respectively. + /// + /// Do not call the setter for this field if the owning [RenderObject] doesn't + /// have on/off state that can be controlled by the user. + /// + /// The getter returns null if the owning [RenderObject] does not have + /// on/off state. + bool? get isToggled => _hasFlag(SemanticsFlag.hasToggledState) ? _hasFlag(SemanticsFlag.isToggled) : null; + set isToggled(bool? value) { + _setFlag(SemanticsFlag.hasToggledState, true); + _setFlag(SemanticsFlag.isToggled, value!); + } + + /// Whether the owning RenderObject corresponds to UI that allows the user to + /// pick one of several mutually exclusive options. + /// + /// For example, a [Radio] button is in a mutually exclusive group because + /// only one radio button in that group can be marked as [isChecked]. + bool get isInMutuallyExclusiveGroup => _hasFlag(SemanticsFlag.isInMutuallyExclusiveGroup); + set isInMutuallyExclusiveGroup(bool value) { + _setFlag(SemanticsFlag.isInMutuallyExclusiveGroup, value); + } + + /// Whether the owning [RenderObject] can hold the input focus. + bool get isFocusable => _hasFlag(SemanticsFlag.isFocusable); + set isFocusable(bool value) { + _setFlag(SemanticsFlag.isFocusable, value); + } + + /// Whether the owning [RenderObject] currently holds the input focus. + bool get isFocused => _hasFlag(SemanticsFlag.isFocused); + set isFocused(bool value) { + _setFlag(SemanticsFlag.isFocused, value); + } + + /// Whether the owning [RenderObject] is a button (true) or not (false). + bool get isButton => _hasFlag(SemanticsFlag.isButton); + set isButton(bool value) { + _setFlag(SemanticsFlag.isButton, value); + } + + /// Whether the owning [RenderObject] is a link (true) or not (false). + bool get isLink => _hasFlag(SemanticsFlag.isLink); + set isLink(bool value) { + _setFlag(SemanticsFlag.isLink, value); + } + + /// Whether the owning [RenderObject] is a header (true) or not (false). + bool get isHeader => _hasFlag(SemanticsFlag.isHeader); + set isHeader(bool value) { + _setFlag(SemanticsFlag.isHeader, value); + } + + /// Whether the owning [RenderObject] is a slider (true) or not (false). + bool get isSlider => _hasFlag(SemanticsFlag.isSlider); + set isSlider(bool value) { + _setFlag(SemanticsFlag.isSlider, value); + } + + /// Whether the owning [RenderObject] is a keyboard key (true) or not + //(false). + bool get isKeyboardKey => _hasFlag(SemanticsFlag.isKeyboardKey); + set isKeyboardKey(bool value) { + _setFlag(SemanticsFlag.isKeyboardKey, value); + } + + /// Whether the owning [RenderObject] is considered hidden. + /// + /// Hidden elements are currently not visible on screen. They may be covered + /// by other elements or positioned outside of the visible area of a viewport. + /// + /// Hidden elements cannot gain accessibility focus though regular touch. The + /// only way they can be focused is by moving the focus to them via linear + /// navigation. + /// + /// Platforms are free to completely ignore hidden elements and new platforms + /// are encouraged to do so. + /// + /// Instead of marking an element as hidden it should usually be excluded from + /// the semantics tree altogether. Hidden elements are only included in the + /// semantics tree to work around platform limitations and they are mainly + /// used to implement accessibility scrolling on iOS. + bool get isHidden => _hasFlag(SemanticsFlag.isHidden); + set isHidden(bool value) { + _setFlag(SemanticsFlag.isHidden, value); + } + + /// Whether the owning [RenderObject] is a text field. + bool get isTextField => _hasFlag(SemanticsFlag.isTextField); + set isTextField(bool value) { + _setFlag(SemanticsFlag.isTextField, value); + } + + /// Whether the owning [RenderObject] is read only. + /// + /// Only applicable when [isTextField] is true. + bool get isReadOnly => _hasFlag(SemanticsFlag.isReadOnly); + set isReadOnly(bool value) { + _setFlag(SemanticsFlag.isReadOnly, value); + } + + /// Whether [this.value] should be obscured. + /// + /// This option is usually set in combination with [isTextField] to indicate + /// that the text field contains a password (or other sensitive information). + /// Doing so instructs screen readers to not read out [this.value]. + bool get isObscured => _hasFlag(SemanticsFlag.isObscured); + set isObscured(bool value) { + _setFlag(SemanticsFlag.isObscured, value); + } + + /// Whether the text field is multiline. + /// + /// This option is usually set in combination with [isTextField] to indicate + /// that the text field is configured to be multiline. + bool get isMultiline => _hasFlag(SemanticsFlag.isMultiline); + set isMultiline(bool value) { + _setFlag(SemanticsFlag.isMultiline, value); + } + + /// Whether the platform can scroll the semantics node when the user attempts + /// to move focus to an offscreen child. + /// + /// For example, a [ListView] widget has implicit scrolling so that users can + /// easily move to the next visible set of children. A [TabBar] widget does + /// not have implicit scrolling, so that users can navigate into the tab + /// body when reaching the end of the tab bar. + bool get hasImplicitScrolling => _hasFlag(SemanticsFlag.hasImplicitScrolling); + set hasImplicitScrolling(bool value) { + _setFlag(SemanticsFlag.hasImplicitScrolling, value); + } + + /// The currently selected text (or the position of the cursor) within + /// [this.value] if this node represents a text field. + TextSelection? get textSelection => _textSelection; + TextSelection? _textSelection; + set textSelection(TextSelection? value) { + assert(value != null); + _textSelection = value; + _hasBeenAnnotated = true; + } + + /// Indicates the current scrolling position in logical pixels if the node is + /// scrollable. + /// + /// The properties [scrollExtentMin] and [scrollExtentMax] indicate the valid + /// in-range values for this property. The value for [scrollPosition] may + /// (temporarily) be outside that range, e.g. during an overscroll. + /// + /// See also: + /// + /// * [ScrollPosition.pixels], from where this value is usually taken. + double? get scrollPosition => _scrollPosition; + double? _scrollPosition; + set scrollPosition(double? value) { + assert(value != null); + _scrollPosition = value; + _hasBeenAnnotated = true; + } + + /// Indicates the maximum in-range value for [scrollPosition] if the node is + /// scrollable. + /// + /// This value may be infinity if the scroll is unbound. + /// + /// See also: + /// + /// * [ScrollPosition.maxScrollExtent], from where this value is usually taken. + double? get scrollExtentMax => _scrollExtentMax; + double? _scrollExtentMax; + set scrollExtentMax(double? value) { + assert(value != null); + _scrollExtentMax = value; + _hasBeenAnnotated = true; + } + + /// Indicates the minimum in-range value for [scrollPosition] if the node is + /// scrollable. + /// + /// This value may be infinity if the scroll is unbound. + /// + /// See also: + /// + /// * [ScrollPosition.minScrollExtent], from where this value is usually taken. + double? get scrollExtentMin => _scrollExtentMin; + double? _scrollExtentMin; + set scrollExtentMin(double? value) { + assert(value != null); + _scrollExtentMin = value; + _hasBeenAnnotated = true; + } + + // TAGS + + /// The set of tags that this configuration wants to add to all child + /// [SemanticsNode]s. + /// + /// See also: + /// + /// * [addTagForChildren] to add a tag and for more information about their + /// usage. + Iterable<SemanticsTag>? get tagsForChildren => _tagsForChildren; + + /// Whether this configuration will tag the child semantics nodes with a + /// given [SemanticsTag]. + bool tagsChildrenWith(SemanticsTag tag) => _tagsForChildren?.contains(tag) ?? false; + + Set<SemanticsTag>? _tagsForChildren; + + /// Specifies a [SemanticsTag] that this configuration wants to apply to all + /// child [SemanticsNode]s. + /// + /// The tag is added to all [SemanticsNode] that pass through the + /// [RenderObject] owning this configuration while looking to be attached to a + /// parent [SemanticsNode]. + /// + /// Tags are used to communicate to a parent [SemanticsNode] that a child + /// [SemanticsNode] was passed through a particular [RenderObject]. The parent + /// can use this information to determine the shape of the semantics tree. + /// + /// See also: + /// + /// * [RenderViewport.excludeFromScrolling] for an example of + /// how tags are used. + void addTagForChildren(SemanticsTag tag) { + _tagsForChildren ??= <SemanticsTag>{}; + _tagsForChildren!.add(tag); + } + + // INTERNAL FLAG MANAGEMENT + + int _flags = 0; + void _setFlag(SemanticsFlag flag, bool value) { + if (value) { + _flags |= flag.index; + } else { + _flags &= ~flag.index; + } + _hasBeenAnnotated = true; + } + + bool _hasFlag(SemanticsFlag flag) => (_flags & flag.index) != 0; + + // CONFIGURATION COMBINATION LOGIC + + /// Whether this configuration is compatible with the provided `other` + /// configuration. + /// + /// Two configurations are said to be compatible if they can be added to the + /// same [SemanticsNode] without losing any semantics information. + bool isCompatibleWith(SemanticsConfiguration? other) { + if (other == null || !other.hasBeenAnnotated || !hasBeenAnnotated) { + return true; + } + if (_actionsAsBits & other._actionsAsBits != 0) { + return false; + } + if ((_flags & other._flags) != 0) { + return false; + } + if (_platformViewId != null && other._platformViewId != null) { + return false; + } + if (_maxValueLength != null && other._maxValueLength != null) { + return false; + } + if (_currentValueLength != null && other._currentValueLength != null) { + return false; + } + if (_attributedValue.string.isNotEmpty && other._attributedValue.string.isNotEmpty) { + return false; + } + return true; + } + + /// Absorb the semantic information from `child` into this configuration. + /// + /// This adds the semantic information of both configurations and saves the + /// result in this configuration. + /// + /// The [RenderObject] owning the `child` configuration must be a descendant + /// of the [RenderObject] that owns this configuration. + /// + /// Only configurations that have [explicitChildNodes] set to false can + /// absorb other configurations and it is recommended to only absorb compatible + /// configurations as determined by [isCompatibleWith]. + void absorb(SemanticsConfiguration child) { + assert(!explicitChildNodes); + + if (!child.hasBeenAnnotated) { + return; + } + if (child.isBlockingUserActions) { + child._actions.forEach((SemanticsAction key, SemanticsActionHandler value) { + if (_kUnblockedUserActions & key.index > 0) { + _actions[key] = value; + } + }); + } else { + _actions.addAll(child._actions); + } + _actionsAsBits |= child._effectiveActionsAsBits; + _customSemanticsActions.addAll(child._customSemanticsActions); + _flags |= child._flags; + _textSelection ??= child._textSelection; + _scrollPosition ??= child._scrollPosition; + _scrollExtentMax ??= child._scrollExtentMax; + _scrollExtentMin ??= child._scrollExtentMin; + _hintOverrides ??= child._hintOverrides; + _indexInParent ??= child.indexInParent; + _scrollIndex ??= child._scrollIndex; + _scrollChildCount ??= child._scrollChildCount; + _platformViewId ??= child._platformViewId; + _maxValueLength ??= child._maxValueLength; + _currentValueLength ??= child._currentValueLength; + + textDirection ??= child.textDirection; + _sortKey ??= child._sortKey; + if (_identifier == '') { + _identifier = child._identifier; + } + _attributedLabel = _concatAttributedString( + thisAttributedString: _attributedLabel, + thisTextDirection: textDirection, + otherAttributedString: child._attributedLabel, + otherTextDirection: child.textDirection, + ); + if (_attributedValue.string == '') { + _attributedValue = child._attributedValue; + } + if (_attributedIncreasedValue.string == '') { + _attributedIncreasedValue = child._attributedIncreasedValue; + } + if (_attributedDecreasedValue.string == '') { + _attributedDecreasedValue = child._attributedDecreasedValue; + } + _attributedHint = _concatAttributedString( + thisAttributedString: _attributedHint, + thisTextDirection: textDirection, + otherAttributedString: child._attributedHint, + otherTextDirection: child.textDirection, + ); + if (_tooltip == '') { + _tooltip = child._tooltip; + } + + _thickness = math.max(_thickness, child._thickness + child._elevation); + + _hasBeenAnnotated = _hasBeenAnnotated || child._hasBeenAnnotated; + } + + /// Returns an exact copy of this configuration. + SemanticsConfiguration copy() { + return SemanticsConfiguration() + .._isSemanticBoundary = _isSemanticBoundary + ..explicitChildNodes = explicitChildNodes + ..isBlockingSemanticsOfPreviouslyPaintedNodes = isBlockingSemanticsOfPreviouslyPaintedNodes + .._hasBeenAnnotated = _hasBeenAnnotated + .._isMergingSemanticsOfDescendants = _isMergingSemanticsOfDescendants + .._textDirection = _textDirection + .._sortKey = _sortKey + .._identifier = _identifier + .._attributedLabel = _attributedLabel + .._attributedIncreasedValue = _attributedIncreasedValue + .._attributedValue = _attributedValue + .._attributedDecreasedValue = _attributedDecreasedValue + .._attributedHint = _attributedHint + .._hintOverrides = _hintOverrides + .._tooltip = _tooltip + .._elevation = _elevation + .._thickness = _thickness + .._flags = _flags + .._tagsForChildren = _tagsForChildren + .._textSelection = _textSelection + .._scrollPosition = _scrollPosition + .._scrollExtentMax = _scrollExtentMax + .._scrollExtentMin = _scrollExtentMin + .._actionsAsBits = _actionsAsBits + .._indexInParent = indexInParent + .._scrollIndex = _scrollIndex + .._scrollChildCount = _scrollChildCount + .._platformViewId = _platformViewId + .._maxValueLength = _maxValueLength + .._currentValueLength = _currentValueLength + .._actions.addAll(_actions) + .._customSemanticsActions.addAll(_customSemanticsActions) + ..isBlockingUserActions = isBlockingUserActions; + } +} + +/// Used by [debugDumpSemanticsTree] to specify the order in which child nodes +/// are printed. +enum DebugSemanticsDumpOrder { + /// Print nodes in inverse hit test order. + /// + /// In inverse hit test order, the last child of a [SemanticsNode] will be + /// asked first if it wants to respond to a user's interaction, followed by + /// the second last, etc. until a taker is found. + inverseHitTest, + + /// Print nodes in semantic traversal order. + /// + /// This is the order in which a user would navigate the UI using the "next" + /// and "previous" gestures. + traversalOrder, +} + +AttributedString _concatAttributedString({ + required AttributedString thisAttributedString, + required AttributedString otherAttributedString, + required TextDirection? thisTextDirection, + required TextDirection? otherTextDirection, +}) { + if (otherAttributedString.string.isEmpty) { + return thisAttributedString; + } + if (thisTextDirection != otherTextDirection && otherTextDirection != null) { + switch (otherTextDirection) { + case TextDirection.rtl: + otherAttributedString = AttributedString(Unicode.RLE) + otherAttributedString + AttributedString(Unicode.PDF); + case TextDirection.ltr: + otherAttributedString = AttributedString(Unicode.LRE) + otherAttributedString + AttributedString(Unicode.PDF); + } + } + if (thisAttributedString.string.isEmpty) { + return otherAttributedString; + } + + return thisAttributedString + AttributedString('\n') + otherAttributedString; +} + +/// Base class for all sort keys for [SemanticsProperties.sortKey] accessibility +/// traversal order sorting. +/// +/// Sort keys are sorted by [name], then by the comparison that the subclass +/// implements. If [SemanticsProperties.sortKey] is specified, sort keys within +/// the same semantic group must all be of the same type. +/// +/// Keys with no [name] are compared to other keys with no [name], and will +/// be traversed before those with a [name]. +/// +/// If no sort key is applied to a semantics node, then it will be ordered using +/// a platform dependent default algorithm. +/// +/// See also: +/// +/// * [OrdinalSortKey] for a sort key that sorts using an ordinal. +abstract class SemanticsSortKey with Diagnosticable implements Comparable<SemanticsSortKey> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const SemanticsSortKey({this.name}); + + /// An optional name that will group this sort key with other sort keys of the + /// same [name]. + /// + /// Sort keys must have the same `runtimeType` when compared. + /// + /// Keys with no [name] are compared to other keys with no [name], and will + /// be traversed before those with a [name]. + final String? name; + + @override + int compareTo(SemanticsSortKey other) { + // Sort by name first and then subclass ordering. + assert(runtimeType == other.runtimeType, 'Semantics sort keys can only be compared to other sort keys of the same type.'); + + // Defer to the subclass implementation for ordering only if the names are + // identical (or both null). + if (name == other.name) { + return doCompare(other); + } + + // Keys that don't have a name are sorted together and come before those with + // a name. + if (name == null && other.name != null) { + return -1; + } else if (name != null && other.name == null) { + return 1; + } + + return name!.compareTo(other.name!); + } + + /// The implementation of [compareTo]. + /// + /// The argument is guaranteed to be of the same type as this object and have + /// the same [name]. + /// + /// The method should return a negative number if this object comes earlier in + /// the sort order than the argument; and a positive number if it comes later + /// in the sort order. Returning zero causes the system to use default sort + /// order. + @protected + int doCompare(covariant SemanticsSortKey other); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('name', name, defaultValue: null)); + } +} + +/// A [SemanticsSortKey] that sorts based on the `double` value it is +/// given. +/// +/// The [OrdinalSortKey] compares itself with other [OrdinalSortKey]s +/// to sort based on the order it is given. +/// +/// [OrdinalSortKey]s are sorted by the optional [name], then by their [order]. +/// If [SemanticsProperties.sortKey] is a [OrdinalSortKey], then all the other +/// specified sort keys in the same semantics group must also be +/// [OrdinalSortKey]s. +/// +/// Keys with no [name] are compared to other keys with no [name], and will +/// be traversed before those with a [name]. +/// +/// The ordinal value [order] is typically a whole number, though it can be +/// fractional, e.g. in order to fit between two other consecutive whole +/// numbers. The value must be finite (it cannot be [double.nan], +/// [double.infinity], or [double.negativeInfinity]). +class OrdinalSortKey extends SemanticsSortKey { + /// Creates a const semantics sort key that uses a [double] as its key value. + /// + /// The [order] must be a finite number. + const OrdinalSortKey( + this.order, { + super.name, + }) : assert(order > double.negativeInfinity), + assert(order < double.infinity); + + /// Determines the placement of this key in a sequence of keys that defines + /// the order in which this node is traversed by the platform's accessibility + /// services. + /// + /// Lower values will be traversed first. Keys with the same [name] will be + /// grouped together and sorted by name first, and then sorted by [order]. + final double order; + + @override + int doCompare(OrdinalSortKey other) { + if (other.order == order) { + return 0; + } + return order.compareTo(other.order); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('order', order, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/semantics_event.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/semantics_event.dart new file mode 100644 index 0000000000000000000000000000000000000000..8a3a1c3ad19335da311a3f37412683f518cd6a2a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/semantics_event.dart @@ -0,0 +1,224 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; + +export 'dart:ui' show TextDirection; + +/// Determines the assertiveness level of the accessibility announcement. +/// +/// It is used by [AnnounceSemanticsEvent] to determine the priority with which +/// assistive technology should treat announcements. +enum Assertiveness { + /// The assistive technology will speak changes whenever the user is idle. + polite, + + /// The assistive technology will interrupt any announcement that it is + /// currently making to notify the user about the change. + /// + /// It should only be used for time-sensitive/critical notifications. + assertive, +} + +/// An event sent by the application to notify interested listeners that +/// something happened to the user interface (e.g. a view scrolled). +/// +/// These events are usually interpreted by assistive technologies to give the +/// user additional clues about the current state of the UI. +abstract class SemanticsEvent { + /// Initializes internal fields. + /// + /// [type] is a string that identifies this class of [SemanticsEvent]s. + const SemanticsEvent(this.type); + + /// The type of this event. + /// + /// The type is used by the engine to translate this event into the + /// appropriate native event (`UIAccessibility*Notification` on iOS and + /// `AccessibilityEvent` on Android). + final String type; + + /// Converts this event to a Map that can be encoded with + /// [StandardMessageCodec]. + /// + /// [nodeId] is the unique identifier of the semantics node associated with + /// the event, or null if the event is not associated with a semantics node. + Map<String, dynamic> toMap({ int? nodeId }) { + final Map<String, dynamic> event = <String, dynamic>{ + 'type': type, + 'data': getDataMap(), + }; + if (nodeId != null) { + event['nodeId'] = nodeId; + } + + return event; + } + + /// Returns the event's data object. + Map<String, dynamic> getDataMap(); + + @override + String toString() { + final List<String> pairs = <String>[]; + final Map<String, dynamic> dataMap = getDataMap(); + final List<String> sortedKeys = dataMap.keys.toList()..sort(); + for (final String key in sortedKeys) { + pairs.add('$key: ${dataMap[key]}'); + } + return '${objectRuntimeType(this, 'SemanticsEvent')}(${pairs.join(', ')})'; + } +} + +/// An event for a semantic announcement. +/// +/// This should be used for announcement that are not seamlessly announced by +/// the system as a result of a UI state change. +/// +/// For example a camera application can use this method to make accessibility +/// announcements regarding objects in the viewfinder. +/// +/// When possible, prefer using mechanisms like [Semantics] to implicitly +/// trigger announcements over using this event. +class AnnounceSemanticsEvent extends SemanticsEvent { + + /// Constructs an event that triggers an announcement by the platform. + const AnnounceSemanticsEvent(this.message, this.textDirection, {this.assertiveness = Assertiveness.polite}) + : super('announce'); + + /// The message to announce. + final String message; + + /// Text direction for [message]. + final TextDirection textDirection; + + /// Determines whether the announcement should interrupt any existing announcement, + /// or queue after it. + /// + /// On the web this option uses the aria-live level to set the assertiveness + /// of the announcement. On iOS, Android, Windows, Linux, macOS, and Fuchsia + /// this option currently has no effect. + final Assertiveness assertiveness; + + @override + Map<String, dynamic> getDataMap() { + return <String, dynamic> { + 'message': message, + 'textDirection': textDirection.index, + if (assertiveness != Assertiveness.polite) + 'assertiveness': assertiveness.index, + }; + } +} + +/// An event for a semantic announcement of a tooltip. +/// +/// This is only used by Android to announce tooltip values. +class TooltipSemanticsEvent extends SemanticsEvent { + /// Constructs an event that triggers a tooltip announcement by the platform. + const TooltipSemanticsEvent(this.message) : super('tooltip'); + + /// The text content of the tooltip. + final String message; + + @override + Map<String, dynamic> getDataMap() { + return <String, dynamic>{ + 'message': message, + }; + } +} + +/// An event which triggers long press semantic feedback. +/// +/// Currently only honored on Android. Triggers a long-press specific sound +/// when TalkBack is enabled. +class LongPressSemanticsEvent extends SemanticsEvent { + /// Constructs an event that triggers a long-press semantic feedback by the platform. + const LongPressSemanticsEvent() : super('longPress'); + + @override + Map<String, dynamic> getDataMap() => const <String, dynamic>{}; +} + +/// An event which triggers tap semantic feedback. +/// +/// Currently only honored on Android. Triggers a tap specific sound when +/// TalkBack is enabled. +class TapSemanticEvent extends SemanticsEvent { + /// Constructs an event that triggers a long-press semantic feedback by the platform. + const TapSemanticEvent() : super('tap'); + + @override + Map<String, dynamic> getDataMap() => const <String, dynamic>{}; +} + +/// An event to move the accessibility focus. +/// +/// Using this API is generally not recommended, as it may break a users' expectation of +/// how a11y focus works and therefore should be just very carefully. +/// +/// One possible use case: +/// For example, the currently focused rendering object is replaced by another rendering +/// object. In general, such design should be avoided if possible. If not, one may want +/// to refocus the newly added rendering object. +/// +/// One example that is not recommended: +/// When a new popup or dropdown opens, moving the focus in these cases may confuse users +/// and make it less accessible. +/// +/// {@tool snippet} +/// +/// The following code snippet shows how one can request focus on a +/// certain widget. +/// +/// ```dart +/// class MyWidget extends StatefulWidget { +/// const MyWidget({super.key}); +/// +/// @override +/// State<MyWidget> createState() => _MyWidgetState(); +/// } +/// +/// class _MyWidgetState extends State<MyWidget> { +/// final GlobalKey mykey = GlobalKey(); +/// +/// @override +/// void initState() { +/// super.initState(); +/// // Using addPostFrameCallback because changing focus need to wait for the widget to finish rendering. +/// WidgetsBinding.instance.addPostFrameCallback((_) { +/// mykey.currentContext?.findRenderObject()?.sendSemanticsEvent(const FocusSemanticEvent()); +/// }); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return Scaffold( +/// appBar: AppBar( +/// title: const Text('example'), +/// ), +/// body: Column( +/// children: <Widget>[ +/// const Text('Hello World'), +/// const SizedBox(height: 50), +/// Text('set focus here', key: mykey), +/// ], +/// ), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// This currently only supports Android and iOS. +class FocusSemanticEvent extends SemanticsEvent { + /// Constructs an event that triggers a focus change by the platform. + const FocusSemanticEvent() : super('focus'); + + @override + Map<String, dynamic> getDataMap() => const <String, dynamic>{}; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/semantics_service.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/semantics_service.dart new file mode 100644 index 0000000000000000000000000000000000000000..9448853e68618cf47501a4a98c03f08cacf0efe3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/semantics/semantics_service.dart @@ -0,0 +1,45 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show TextDirection; + +import 'package:flutter/services.dart' show SystemChannels; + +import 'semantics_event.dart' show AnnounceSemanticsEvent, Assertiveness, TooltipSemanticsEvent; + +export 'dart:ui' show TextDirection; + +/// Allows access to the platform's accessibility services. +/// +/// Events sent by this service are handled by the platform-specific +/// accessibility bridge in Flutter's engine. +/// +/// When possible, prefer using mechanisms like [Semantics] to implicitly +/// trigger announcements over using this event. +abstract final class SemanticsService { + /// Sends a semantic announcement. + /// + /// This should be used for announcement that are not seamlessly announced by + /// the system as a result of a UI state change. + /// + /// For example a camera application can use this method to make accessibility + /// announcements regarding objects in the viewfinder. + /// + /// The assertiveness level of the announcement is determined by [assertiveness]. + /// Currently, this is only supported by the web engine and has no effect on + /// other platforms. The default mode is [Assertiveness.polite]. + static Future<void> announce(String message, TextDirection textDirection, {Assertiveness assertiveness = Assertiveness.polite}) async { + final AnnounceSemanticsEvent event = AnnounceSemanticsEvent(message, textDirection, assertiveness: assertiveness); + await SystemChannels.accessibility.send(event.toMap()); + } + + /// Sends a semantic announcement of a tooltip. + /// + /// Currently only honored on Android. The contents of [message] will be + /// read by TalkBack. + static Future<void> tooltip(String message) async { + final TooltipSemanticsEvent event = TooltipSemanticsEvent(message); + await SystemChannels.accessibility.send(event.toMap()); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/_background_isolate_binary_messenger_io.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/_background_isolate_binary_messenger_io.dart new file mode 100644 index 0000000000000000000000000000000000000000..c1e938ae9fc380123f02328634959ad6efc83fc9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/_background_isolate_binary_messenger_io.dart @@ -0,0 +1,97 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async' show Completer; +import 'dart:isolate' show ReceivePort; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'binary_messenger.dart'; +import 'binding.dart'; + +/// A [BinaryMessenger] for use on background (non-root) isolates. +class BackgroundIsolateBinaryMessenger extends BinaryMessenger { + BackgroundIsolateBinaryMessenger._(); + + final ReceivePort _receivePort = ReceivePort(); + final Map<int, Completer<ByteData?>> _completers = + <int, Completer<ByteData?>>{}; + int _messageCount = 0; + + /// The existing instance of this class, if any. + /// + /// Throws if [ensureInitialized] has not been called at least once. + static BinaryMessenger get instance { + if (_instance == null) { + throw StateError( + 'The BackgroundIsolateBinaryMessenger.instance value is invalid ' + 'until BackgroundIsolateBinaryMessenger.ensureInitialized is ' + 'executed.'); + } + return _instance!; + } + + static BinaryMessenger? _instance; + + /// Ensures that [BackgroundIsolateBinaryMessenger.instance] has been initialized. + /// + /// The argument should be the value obtained from [ServicesBinding.rootIsolateToken] + /// on the root isolate. + /// + /// This function is idempotent (calling it multiple times is harmless but has no effect). + static void ensureInitialized(ui.RootIsolateToken token) { + if (_instance == null) { + ui.PlatformDispatcher.instance.registerBackgroundIsolate(token); + final BackgroundIsolateBinaryMessenger portBinaryMessenger = + BackgroundIsolateBinaryMessenger._(); + _instance = portBinaryMessenger; + portBinaryMessenger._receivePort.listen((dynamic message) { + try { + final List<dynamic> args = message as List<dynamic>; + final int identifier = args[0] as int; + final Uint8List bytes = args[1] as Uint8List; + final ByteData byteData = ByteData.sublistView(bytes); + portBinaryMessenger._completers + .remove(identifier)! + .complete(byteData); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'services library', + context: + ErrorDescription('during a platform message response callback'), + )); + } + }); + } + } + + @override + Future<void> handlePlatformMessage(String channel, ByteData? data, + ui.PlatformMessageResponseCallback? callback) { + throw UnimplementedError('handlePlatformMessage is deprecated.'); + } + + @override + Future<ByteData?>? send(String channel, ByteData? message) { + final Completer<ByteData?> completer = Completer<ByteData?>(); + _messageCount += 1; + final int messageIdentifier = _messageCount; + _completers[messageIdentifier] = completer; + ui.PlatformDispatcher.instance.sendPortPlatformMessage( + channel, + message, + messageIdentifier, + _receivePort.sendPort, + ); + return completer.future; + } + + @override + void setMessageHandler(String channel, MessageHandler? handler) { + throw UnsupportedError( + 'Background isolates do not support setMessageHandler(). Messages from the host platform always go to the root isolate.'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/_background_isolate_binary_messenger_web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/_background_isolate_binary_messenger_web.dart new file mode 100644 index 0000000000000000000000000000000000000000..e9079c6f4d4143f86583f3f03eadf9b9ff861f65 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/_background_isolate_binary_messenger_web.dart @@ -0,0 +1,13 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'binding.dart'; + +/// Stand-in for non-web platforms' [BackgroundIsolateBinaryMessenger]. +class BackgroundIsolateBinaryMessenger { + /// Throws an [UnsupportedError]. + static BinaryMessenger get instance { + throw UnsupportedError('Isolates not supported on web.'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/asset_bundle.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/asset_bundle.dart new file mode 100644 index 0000000000000000000000000000000000000000..0c65ca323ca74cd82c49cd4d1006b08394b0c1be --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/asset_bundle.dart @@ -0,0 +1,410 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:convert'; +import 'dart:io'; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; + +import 'binding.dart'; + +export 'dart:typed_data' show ByteData; +export 'dart:ui' show ImmutableBuffer; + +/// A collection of resources used by the application. +/// +/// Asset bundles contain resources, such as images and strings, that can be +/// used by an application. Access to these resources is asynchronous so that +/// they can be transparently loaded over a network (e.g., from a +/// [NetworkAssetBundle]) or from the local file system without blocking the +/// application's user interface. +/// +/// Applications have a [rootBundle], which contains the resources that were +/// packaged with the application when it was built. To add resources to the +/// [rootBundle] for your application, add them to the `assets` subsection of +/// the `flutter` section of your application's `pubspec.yaml` manifest. +/// +/// For example: +/// +/// ```yaml +/// name: my_awesome_application +/// flutter: +/// assets: +/// - images/hamilton.jpeg +/// - images/lafayette.jpeg +/// ``` +/// +/// Rather than accessing the [rootBundle] global static directly, consider +/// obtaining the [AssetBundle] for the current [BuildContext] using +/// [DefaultAssetBundle.of]. This layer of indirection lets ancestor widgets +/// substitute a different [AssetBundle] (e.g., for testing or localization) at +/// runtime rather than directly replying upon the [rootBundle] created at build +/// time. For convenience, the [WidgetsApp] or [MaterialApp] widget at the top +/// of the widget hierarchy configures the [DefaultAssetBundle] to be the +/// [rootBundle]. +/// +/// See also: +/// +/// * [DefaultAssetBundle] +/// * [NetworkAssetBundle] +/// * [rootBundle] +abstract class AssetBundle { + /// Retrieve a binary resource from the asset bundle as a data stream. + /// + /// Throws an exception if the asset is not found. + /// + /// The returned [ByteData] can be converted to a [Uint8List] (a list of bytes) + /// using [Uint8List.sublistView]. Lists of bytes can be used with APIs that + /// accept [Uint8List] objects, such as [decodeImageFromList], as well as any + /// API that accepts a [List<int>], such as [File.writeAsBytes] or + /// [Utf8Codec.decode] (accessible via [utf8]). + Future<ByteData> load(String key); + + /// Retrieve a binary resource from the asset bundle as an immutable + /// buffer. + /// + /// Throws an exception if the asset is not found. + Future<ui.ImmutableBuffer> loadBuffer(String key) async { + final ByteData data = await load(key); + return ui.ImmutableBuffer.fromUint8List(Uint8List.sublistView(data)); + } + + /// Retrieve a string from the asset bundle. + /// + /// Throws an exception if the asset is not found. + /// + /// If the `cache` argument is set to false, then the data will not be + /// cached, and reading the data may bypass the cache. This is useful if the + /// caller is going to be doing its own caching. (It might not be cached if + /// it's set to true either, depending on the asset bundle implementation.) + /// + /// The function expects the stored string to be UTF-8-encoded as + /// [Utf8Codec] will be used for decoding the string. If the string is + /// larger than 50 KB, the decoding process is delegated to an + /// isolate to avoid jank on the main thread. + Future<String> loadString(String key, { bool cache = true }) async { + final ByteData data = await load(key); + // 50 KB of data should take 2-3 ms to parse on a Moto G4, and about 400 μs + // on a Pixel 4. On the web we can't bail to isolates, though... + if (data.lengthInBytes < 50 * 1024 || kIsWeb) { + return utf8.decode(Uint8List.sublistView(data)); + } + // For strings larger than 50 KB, run the computation in an isolate to + // avoid causing main thread jank. + return compute(_utf8decode, data, debugLabel: 'UTF8 decode for "$key"'); + } + + static String _utf8decode(ByteData data) { + return utf8.decode(Uint8List.sublistView(data)); + } + + /// Retrieve a string from the asset bundle, parse it with the given function, + /// and return that function's result. + /// + /// The result is not cached by the default implementation; the parser is run + /// each time the resource is fetched. However, some subclasses may implement + /// caching (notably, subclasses of [CachingAssetBundle]). + Future<T> loadStructuredData<T>(String key, Future<T> Function(String value) parser) async { + return parser(await loadString(key)); + } + + /// Retrieve [ByteData] from the asset bundle, parse it with the given function, + /// and return that function's result. + /// + /// The result is not cached by the default implementation; the parser is run + /// each time the resource is fetched. However, some subclasses may implement + /// caching (notably, subclasses of [CachingAssetBundle]). + Future<T> loadStructuredBinaryData<T>(String key, FutureOr<T> Function(ByteData data) parser) async { + return parser(await load(key)); + } + + /// If this is a caching asset bundle, and the given key describes a cached + /// asset, then evict the asset from the cache so that the next time it is + /// loaded, the cache will be reread from the asset bundle. + void evict(String key) { } + + /// If this is a caching asset bundle, clear all cached data. + void clear() { } + + @override + String toString() => '${describeIdentity(this)}()'; +} + +/// An [AssetBundle] that loads resources over the network. +/// +/// This asset bundle does not cache any resources, though the underlying +/// network stack may implement some level of caching itself. +class NetworkAssetBundle extends AssetBundle { + /// Creates a network asset bundle that resolves asset keys as URLs relative + /// to the given base URL. + NetworkAssetBundle(Uri baseUrl) + : _baseUrl = baseUrl, + _httpClient = HttpClient(); + + final Uri _baseUrl; + final HttpClient _httpClient; + + Uri _urlFromKey(String key) => _baseUrl.resolve(key); + + @override + Future<ByteData> load(String key) async { + final HttpClientRequest request = await _httpClient.getUrl(_urlFromKey(key)); + final HttpClientResponse response = await request.close(); + if (response.statusCode != HttpStatus.ok) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + _errorSummaryWithKey(key), + IntProperty('HTTP status code', response.statusCode), + ]); + } + final Uint8List bytes = await consolidateHttpClientResponseBytes(response); + return ByteData.sublistView(bytes); + } + + // TODO(ianh): Once the underlying network logic learns about caching, we + // should implement evict(). + + @override + String toString() => '${describeIdentity(this)}($_baseUrl)'; +} + +/// An [AssetBundle] that permanently caches string and structured resources +/// that have been fetched. +/// +/// Strings (for [loadString] and [loadStructuredData]) are decoded as UTF-8. +/// Data that is cached is cached for the lifetime of the asset bundle +/// (typically the lifetime of the application). +/// +/// Binary resources (from [load]) are not cached. +abstract class CachingAssetBundle extends AssetBundle { + // TODO(ianh): Replace this with an intelligent cache, see https://github.com/flutter/flutter/issues/3568 + final Map<String, Future<String>> _stringCache = <String, Future<String>>{}; + final Map<String, Future<dynamic>> _structuredDataCache = <String, Future<dynamic>>{}; + final Map<String, Future<dynamic>> _structuredBinaryDataCache = <String, Future<dynamic>>{}; + + @override + Future<String> loadString(String key, { bool cache = true }) { + if (cache) { + return _stringCache.putIfAbsent(key, () => super.loadString(key)); + } + return super.loadString(key); + } + + /// Retrieve a string from the asset bundle, parse it with the given function, + /// and return the function's result. + /// + /// The result of parsing the string is cached (the string itself is not, + /// unless you also fetch it with [loadString]). For any given `key`, the + /// `parser` is only run the first time. + /// + /// Once the value has been successfully parsed, the future returned by this + /// function for subsequent calls will be a [SynchronousFuture], which + /// resolves its callback synchronously. + /// + /// Failures are not cached, and are returned as [Future]s with errors. + @override + Future<T> loadStructuredData<T>(String key, Future<T> Function(String value) parser) { + if (_structuredDataCache.containsKey(key)) { + return _structuredDataCache[key]! as Future<T>; + } + // loadString can return a SynchronousFuture in certain cases, like in the + // flutter_test framework. So, we need to support both async and sync flows. + Completer<T>? completer; // For async flow. + Future<T>? synchronousResult; // For sync flow. + loadString(key, cache: false).then<T>(parser).then<void>((T value) { + synchronousResult = SynchronousFuture<T>(value); + _structuredDataCache[key] = synchronousResult!; + if (completer != null) { + // We already returned from the loadStructuredData function, which means + // we are in the asynchronous mode. Pass the value to the completer. The + // completer's future is what we returned. + completer.complete(value); + } + }, onError: (Object error, StackTrace stack) { + assert(completer != null, 'unexpected synchronous failure'); + // Either loading or parsing failed. We must report the error back to the + // caller and anyone waiting on this call. We clear the cache for this + // key, however, because we want future attempts to try again. + _structuredDataCache.remove(key); + completer!.completeError(error, stack); + }); + if (synchronousResult != null) { + // The above code ran synchronously. We can synchronously return the result. + return synchronousResult!; + } + // The code above hasn't yet run its "then" handler yet. Let's prepare a + // completer for it to use when it does run. + completer = Completer<T>(); + _structuredDataCache[key] = completer.future; + return completer.future; + } + + /// Retrieve bytedata from the asset bundle, parse it with the given function, + /// and return the function's result. + /// + /// The result of parsing the bytedata is cached (the bytedata itself is not). + /// For any given `key`, the `parser` is only run the first time. + /// + /// Once the value has been successfully parsed, the future returned by this + /// function for subsequent calls will be a [SynchronousFuture], which + /// resolves its callback synchronously. + /// + /// Failures are not cached, and are returned as [Future]s with errors. + @override + Future<T> loadStructuredBinaryData<T>(String key, FutureOr<T> Function(ByteData data) parser) { + if (_structuredBinaryDataCache.containsKey(key)) { + return _structuredBinaryDataCache[key]! as Future<T>; + } + // load can return a SynchronousFuture in certain cases, like in the + // flutter_test framework. So, we need to support both async and sync flows. + Completer<T>? completer; // For async flow. + Future<T>? synchronousResult; // For sync flow. + load(key).then<T>(parser).then<void>((T value) { + synchronousResult = SynchronousFuture<T>(value); + _structuredBinaryDataCache[key] = synchronousResult!; + if (completer != null) { + // The load and parse operation ran asynchronously. We already returned + // from the loadStructuredBinaryData function and therefore the caller + // was given the future of the completer. + completer.complete(value); + } + }, onError: (Object error, StackTrace stack) { + assert(completer != null, 'unexpected synchronous failure'); + // Either loading or parsing failed. We must report the error back to the + // caller and anyone waiting on this call. We clear the cache for this + // key, however, because we want future attempts to try again. + _structuredBinaryDataCache.remove(key); + completer!.completeError(error, stack); + }); + if (synchronousResult != null) { + // The above code ran synchronously. We can synchronously return the result. + return synchronousResult!; + } + // Since the above code is being run asynchronously and thus hasn't run its + // `then` handler yet, we'll return a completer that will be completed + // when the handler does run. + completer = Completer<T>(); + _structuredBinaryDataCache[key] = completer.future; + return completer.future; + } + + @override + void evict(String key) { + _stringCache.remove(key); + _structuredDataCache.remove(key); + _structuredBinaryDataCache.remove(key); + } + + @override + void clear() { + _stringCache.clear(); + _structuredDataCache.clear(); + _structuredBinaryDataCache.clear(); + } + + @override + Future<ui.ImmutableBuffer> loadBuffer(String key) async { + final ByteData data = await load(key); + return ui.ImmutableBuffer.fromUint8List(Uint8List.sublistView(data)); + } +} + +/// An [AssetBundle] that loads resources using platform messages. +class PlatformAssetBundle extends CachingAssetBundle { + @override + Future<ByteData> load(String key) { + final Uint8List encoded = utf8.encode(Uri(path: Uri.encodeFull(key)).path); + final Future<ByteData>? future = ServicesBinding.instance.defaultBinaryMessenger.send( + 'flutter/assets', + ByteData.sublistView(encoded), + )?.then((ByteData? asset) { + if (asset == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + _errorSummaryWithKey(key), + ErrorDescription('The asset does not exist or has empty data.'), + ]); + } + return asset; + }); + if (future == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + _errorSummaryWithKey(key), + ErrorDescription('The asset does not exist or has empty data.'), + ]); + } + return future; + } + + @override + Future<ui.ImmutableBuffer> loadBuffer(String key) async { + if (kIsWeb) { + final ByteData bytes = await load(key); + return ui.ImmutableBuffer.fromUint8List(Uint8List.sublistView(bytes)); + } + bool debugUsePlatformChannel = false; + assert(() { + // dart:io is safe to use here since we early return for web + // above. If that code is changed, this needs to be guarded on + // web presence. Override how assets are loaded in tests so that + // the old loader behavior that allows tests to load assets from + // the current package using the package prefix. + if (Platform.environment.containsKey('UNIT_TEST_ASSETS')) { + debugUsePlatformChannel = true; + } + return true; + }()); + if (debugUsePlatformChannel) { + final ByteData bytes = await load(key); + return ui.ImmutableBuffer.fromUint8List(Uint8List.sublistView(bytes)); + } + try { + return await ui.ImmutableBuffer.fromAsset(key); + } on Exception catch (e) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + _errorSummaryWithKey(key), + ErrorDescription(e.toString()), + ]); + } + } +} + +AssetBundle _initRootBundle() { + return PlatformAssetBundle(); +} + +ErrorSummary _errorSummaryWithKey(String key) { + return ErrorSummary('Unable to load asset: "$key".'); +} + +/// The [AssetBundle] from which this application was loaded. +/// +/// The [rootBundle] contains the resources that were packaged with the +/// application when it was built. To add resources to the [rootBundle] for your +/// application, add them to the `assets` subsection of the `flutter` section of +/// your application's `pubspec.yaml` manifest. +/// +/// For example: +/// +/// ```yaml +/// name: my_awesome_application +/// flutter: +/// assets: +/// - images/hamilton.jpeg +/// - images/lafayette.jpeg +/// ``` +/// +/// Rather than using [rootBundle] directly, consider obtaining the +/// [AssetBundle] for the current [BuildContext] using [DefaultAssetBundle.of]. +/// This layer of indirection lets ancestor widgets substitute a different +/// [AssetBundle] at runtime (e.g., for testing or localization) rather than +/// directly replying upon the [rootBundle] created at build time. For +/// convenience, the [WidgetsApp] or [MaterialApp] widget at the top of the +/// widget hierarchy configures the [DefaultAssetBundle] to be the [rootBundle]. +/// +/// See also: +/// +/// * [DefaultAssetBundle] +/// * [NetworkAssetBundle] +final AssetBundle rootBundle = _initRootBundle(); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/asset_manifest.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/asset_manifest.dart new file mode 100644 index 0000000000000000000000000000000000000000..c948067e4cb3910bb26a397c049ebdcc501b4c22 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/asset_manifest.dart @@ -0,0 +1,153 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:convert'; + +import 'package:flutter/foundation.dart'; + +import 'asset_bundle.dart'; +import 'message_codecs.dart'; + +// We use .bin as the extension since it is well-known to represent +// data in some arbitrary binary format. +const String _kAssetManifestFilename = 'AssetManifest.bin'; + +// We use the same bin file for the web, but re-encoded as JSON(base64(bytes)) +// so it can be downloaded by even the dumbest of browsers. +// See https://github.com/flutter/flutter/issues/128456 +const String _kAssetManifestWebFilename = 'AssetManifest.bin.json'; + +/// Contains details about available assets and their variants. +/// See [Resolution-aware image assets](https://docs.flutter.dev/ui/assets-and-images#resolution-aware) +/// to learn about asset variants and how to declare them. +abstract class AssetManifest { + /// Loads asset manifest data from an [AssetBundle] object and creates an + /// [AssetManifest] object from that data. + static Future<AssetManifest> loadFromAssetBundle(AssetBundle bundle) { + // The AssetManifest file contains binary data. + // + // On the web, the build process wraps this binary data in json+base64 so + // it can be transmitted over the network without special configuration + // (see #131382). + if (kIsWeb) { + // On the web, the AssetManifest is downloaded as a String, then + // json+base64-decoded to get to the binary data. + return bundle.loadStructuredData(_kAssetManifestWebFilename, (String jsonData) async { + // Decode the manifest JSON file to the underlying BIN, and convert to ByteData. + final ByteData message = ByteData.sublistView(base64.decode(json.decode(jsonData) as String)); + // Now we can keep operating as usual. + return _AssetManifestBin.fromStandardMessageCodecMessage(message); + }); + } + // On every other platform, the binary file contents are used directly. + return bundle.loadStructuredBinaryData(_kAssetManifestFilename, _AssetManifestBin.fromStandardMessageCodecMessage); + } + + /// Lists the keys of all main assets. This does not include assets + /// that are variants of other assets. + /// + /// The logical key maps to the path of an asset specified in the pubspec.yaml + /// file at build time. + /// + /// See [Specifying assets](https://docs.flutter.dev/development/ui/assets-and-images#specifying-assets) + /// and [Loading assets](https://docs.flutter.dev/development/ui/assets-and-images#loading-assets) + /// for more information. + List<String> listAssets(); + + /// Retrieves metadata about an asset and its variants. Returns null if the + /// key was not found in the asset manifest. + /// + /// This method considers a main asset to be a variant of itself. The returned + /// list will include it if it exists. + List<AssetMetadata>? getAssetVariants(String key); +} + +// Lazily parses the binary asset manifest into a data structure that's easier to work +// with. +// +// The binary asset manifest is a map of asset keys to a list of objects +// representing the asset's variants. +// +// The entries with each variant object are: +// - "asset": the location of this variant to load it from. +// - "dpr": The device-pixel-ratio that the asset is best-suited for. +// +// New fields could be added to this object schema to support new asset variation +// features, such as themes, locale/region support, reading directions, and so on. +class _AssetManifestBin implements AssetManifest { + _AssetManifestBin(Map<Object?, Object?> standardMessageData): _data = standardMessageData; + + factory _AssetManifestBin.fromStandardMessageCodecMessage(ByteData message) { + final dynamic data = const StandardMessageCodec().decodeMessage(message); + return _AssetManifestBin(data as Map<Object?, Object?>); + } + + final Map<Object?, Object?> _data; + final Map<String, List<AssetMetadata>> _typeCastedData = <String, List<AssetMetadata>>{}; + + @override + List<AssetMetadata>? getAssetVariants(String key) { + // We lazily delay typecasting to prevent a performance hiccup when parsing + // large asset manifests. This is important to keep an app's first asset + // load fast. + if (!_typeCastedData.containsKey(key)) { + final Object? variantData = _data[key]; + if (variantData == null) { + return null; + } + _typeCastedData[key] = ((_data[key] ?? <Object?>[]) as Iterable<Object?>) + .cast<Map<Object?, Object?>>() + .map((Map<Object?, Object?> data) { + final String asset = data['asset']! as String; + final Object? dpr = data['dpr']; + return AssetMetadata( + key: data['asset']! as String, + targetDevicePixelRatio: dpr as double?, + main: key == asset, + ); + }) + .toList(); + + _data.remove(key); + } + + return _typeCastedData[key]!; + } + + @override + List<String> listAssets() { + return <String>[..._data.keys.cast<String>(), ..._typeCastedData.keys]; + } +} + +/// Contains information about an asset. +@immutable +class AssetMetadata { + /// Creates an object containing information about an asset. + const AssetMetadata({ + required this.key, + required this.targetDevicePixelRatio, + required this.main, + }); + + /// The device pixel ratio that this asset is most ideal for. This is determined + /// by the name of the parent folder of the asset file. For example, if the + /// parent folder is named "3.0x", the target device pixel ratio of that + /// asset will be interpreted as 3. + /// + /// This will be null if the parent folder name is not a ratio value followed + /// by an "x". + /// + /// See [Resolution-aware image assets](https://docs.flutter.dev/development/ui/assets-and-images#resolution-aware) + /// for more information. + final double? targetDevicePixelRatio; + + /// The asset's key, which is the path to the asset specified in the pubspec.yaml + /// file at build time. + final String key; + + /// Whether or not this is a main asset. In other words, this is true if + /// this asset is not a variant of another asset. + final bool main; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/autofill.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/autofill.dart new file mode 100644 index 0000000000000000000000000000000000000000..992d72557b613e7f820a935d34386549bbc3bd2e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/autofill.dart @@ -0,0 +1,850 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'text_input.dart'; + +export 'text_input.dart' show TextEditingValue, TextInputClient, TextInputConfiguration, TextInputConnection; + +/// A collection of commonly used autofill hint strings on different platforms. +/// +/// Each hint is pre-defined on at least one supported platform. See their +/// documentation for their availability on each platform, and the platform +/// values each autofill hint corresponds to. +class AutofillHints { + // This class is not meant to be instantiated or extended; this constructor + // prevents instantiation and extension. + AutofillHints._(); + + /// The input field expects an address locality (city/town). + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY). + /// * iOS: [addressCity](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * Otherwise, the hint string will be used as-is. + static const String addressCity = 'addressCity'; + + /// The input field expects a city name combined with a state name. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * iOS: [addressCityAndState](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * Otherwise, the hint string will be used as-is. + static const String addressCityAndState = 'addressCityAndState'; + + /// The input field expects a region/state. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_REGION](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_REGION). + /// * iOS: [addressState](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * Otherwise, the hint string will be used as-is. + static const String addressState = 'addressState'; + + /// The input field expects a person's full birth date. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_BIRTH_DATE_FULL](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_BIRTH_DATE_FULL). + /// * web: ["bday"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String birthday = 'birthday'; + + /// The input field expects a person's birth day(of the month). + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_BIRTH_DATE_DAY](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_BIRTH_DATE_DAY). + /// * web: ["bday-day"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String birthdayDay = 'birthdayDay'; + + /// The input field expects a person's birth month. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_BIRTH_DATE_MONTH](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_BIRTH_DATE_MONTH). + /// * web: ["bday-month"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String birthdayMonth = 'birthdayMonth'; + + /// The input field expects a person's birth year. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_BIRTH_DATE_YEAR](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_BIRTH_DATE_YEAR). + /// * web: ["bday-year"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String birthdayYear = 'birthdayYear'; + + /// The input field expects an + /// [ISO 3166-1-alpha-2](https://www.iso.org/standard/63545.html) country code. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["country"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String countryCode = 'countryCode'; + + /// The input field expects a country name. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY). + /// * iOS: [countryName](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["country-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String countryName = 'countryName'; + + /// The input field expects a credit card expiration date. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_CREDIT_CARD_NUMBER](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_NUMBER). + /// * web: ["cc-exp"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardExpirationDate = 'creditCardExpirationDate'; + + /// The input field expects a credit card expiration day. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardExpirationDay = 'creditCardExpirationDay'; + + /// The input field expects a credit card expiration month. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH). + /// * web: ["cc-exp-month"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardExpirationMonth = 'creditCardExpirationMonth'; + + /// The input field expects a credit card expiration year. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR). + /// * web: ["cc-exp-year"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardExpirationYear = 'creditCardExpirationYear'; + + /// The input field expects the holder's last/family name as given on a credit + /// card. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["cc-family-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardFamilyName = 'creditCardFamilyName'; + + /// The input field expects the holder's first/given name as given on a credit + /// card. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["cc-given-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardGivenName = 'creditCardGivenName'; + + /// The input field expects the holder's middle name as given on a credit + /// card. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["cc-additional-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardMiddleName = 'creditCardMiddleName'; + + /// The input field expects the holder's full name as given on a credit card. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["cc-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardName = 'creditCardName'; + + /// The input field expects a credit card number. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_CREDIT_CARD_NUMBER](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_NUMBER). + /// * iOS: [creditCardNumber](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["cc-number"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardNumber = 'creditCardNumber'; + + /// The input field expects a credit card security code. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE). + /// * web: ["cc-csc"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardSecurityCode = 'creditCardSecurityCode'; + + /// The input field expects the type of a credit card, for example "Visa". + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["cc-type"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String creditCardType = 'creditCardType'; + + /// The input field expects an email address. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_EMAIL_ADDRESS](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_EMAIL_ADDRESS). + /// * iOS: [emailAddress](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["email"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String email = 'email'; + + /// The input field expects a person's last/family name. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PERSON_NAME_FAMILY](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_FAMILY). + /// * iOS: [familyName](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["family-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String familyName = 'familyName'; + + /// The input field expects a street address that fully identifies a location. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS). + /// * iOS: [fullStreetAddress](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["street-address"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String fullStreetAddress = 'fullStreetAddress'; + + /// The input field expects a gender. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_GENDER](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_GENDER). + /// * web: ["sex"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String gender = 'gender'; + + /// The input field expects a person's first/given name. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PERSON_NAME_GIVEN](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_GIVEN). + /// * iOS: [givenName](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["given-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String givenName = 'givenName'; + + /// The input field expects a URL representing an instant messaging protocol + /// endpoint. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["impp"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String impp = 'impp'; + + /// The input field expects a job title. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * iOS: [jobTitle](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["organization-title"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String jobTitle = 'jobTitle'; + + /// The input field expects the preferred language of the user. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["language"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String language = 'language'; + + /// The input field expects a location, such as a point of interest, an + /// address,or another way to identify a location. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * iOS: [location](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * Otherwise, the hint string will be used as-is. + static const String location = 'location'; + + /// The input field expects a person's middle initial. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PERSON_NAME_MIDDLE_INITIAL](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_MIDDLE_INITIAL). + /// * Otherwise, the hint string will be used as-is. + static const String middleInitial = 'middleInitial'; + + /// The input field expects a person's middle name. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PERSON_NAME_MIDDLE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_MIDDLE). + /// * iOS: [middleName](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["additional-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String middleName = 'middleName'; + + /// The input field expects a person's full name. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PERSON_NAME](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME). + /// * iOS: [name](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String name = 'name'; + + /// The input field expects a person's name prefix or title, such as "Dr.". + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PERSON_NAME_PREFIX](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_PREFIX). + /// * iOS: [namePrefix](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["honorific-prefix"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String namePrefix = 'namePrefix'; + + /// The input field expects a person's name suffix, such as "Jr.". + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PERSON_NAME_SUFFIX](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_SUFFIX). + /// * iOS: [nameSuffix](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["honorific-suffix"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String nameSuffix = 'nameSuffix'; + + /// The input field expects a newly created password for save/update. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_NEW_PASSWORD](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_NEW_PASSWORD). + /// * iOS: [newPassword](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["new-password"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String newPassword = 'newPassword'; + + /// The input field expects a newly created username for save/update. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_NEW_USERNAME](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_NEW_USERNAME). + /// * Otherwise, the hint string will be used as-is. + static const String newUsername = 'newUsername'; + + /// The input field expects a nickname. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * iOS: [nickname](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["nickname"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String nickname = 'nickname'; + + /// The input field expects a SMS one-time code. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_SMS_OTP](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_SMS_OTP). + /// * iOS: [oneTimeCode](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["one-time-code"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String oneTimeCode = 'oneTimeCode'; + + /// The input field expects an organization name corresponding to the person, + /// address, or contact information in the other fields associated with this + /// field. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * iOS: [organizationName](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["organization"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String organizationName = 'organizationName'; + + /// The input field expects a password. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PASSWORD](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PASSWORD). + /// * iOS: [password](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["current-password"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String password = 'password'; + + /// The input field expects a photograph, icon, or other image corresponding + /// to the company, person, address, or contact information in the other + /// fields associated with this field. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["photo"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String photo = 'photo'; + + /// The input field expects a postal address. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS). + /// * Otherwise, the hint string will be used as-is. + static const String postalAddress = 'postalAddress'; + + /// The input field expects an auxiliary address details. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS). + /// * Otherwise, the hint string will be used as-is. + static const String postalAddressExtended = 'postalAddressExtended'; + + /// The input field expects an extended ZIP/POSTAL code. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE). + /// * Otherwise, the hint string will be used as-is. + static const String postalAddressExtendedPostalCode = 'postalAddressExtendedPostalCode'; + + /// The input field expects a postal code. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_POSTAL_CODE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_CODE). + /// * iOS: [postalCode](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["postal-code"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String postalCode = 'postalCode'; + + /// The first administrative level in the address. This is typically the + /// province in which the address is located. In the United States, this would + /// be the state. In Switzerland, the canton. In the United Kingdom, the post + /// town. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["address-level1"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String streetAddressLevel1 = 'streetAddressLevel1'; + + /// The second administrative level, in addresses with at least two of them. + /// In countries with two administrative levels, this would typically be the + /// city, town, village, or other locality in which the address is located. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["address-level2"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String streetAddressLevel2 = 'streetAddressLevel2'; + + /// The third administrative level, in addresses with at least three + /// administrative levels. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["address-level3"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String streetAddressLevel3 = 'streetAddressLevel3'; + + /// The finest-grained administrative level, in addresses which have four + /// levels. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["address-level4"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String streetAddressLevel4 = 'streetAddressLevel4'; + + /// The input field expects the first line of a street address. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * iOS: [streetAddressLine1](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["address-line1"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String streetAddressLine1 = 'streetAddressLine1'; + + /// The input field expects the second line of a street address. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * iOS: [streetAddressLine2](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// As of iOS 14.2 this hint does not trigger autofill. + /// * web: ["address-line2"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String streetAddressLine2 = 'streetAddressLine2'; + + /// The input field expects the third line of a street address. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["address-line3"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String streetAddressLine3 = 'streetAddressLine3'; + + /// The input field expects a sublocality. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * iOS: [sublocality](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * Otherwise, the hint string will be used as-is. + static const String sublocality = 'sublocality'; + + /// The input field expects a telephone number. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PHONE_NUMBER](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PHONE_NUMBER). + /// * iOS: [telephoneNumber](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["tel"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String telephoneNumber = 'telephoneNumber'; + + /// The input field expects a phone number's area code, with a country + /// -internal prefix applied if applicable. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["tel-area-code"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String telephoneNumberAreaCode = 'telephoneNumberAreaCode'; + + /// The input field expects a phone number's country code. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PHONE_COUNTRY_CODE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PHONE_COUNTRY_CODE). + /// * web: ["tel-country-code"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String telephoneNumberCountryCode = 'telephoneNumberCountryCode'; + + /// The input field expects the current device's phone number, usually for + /// Sign Up / OTP flows. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PHONE_NUMBER_DEVICE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PHONE_NUMBER_DEVICE). + /// * Otherwise, the hint string will be used as-is. + static const String telephoneNumberDevice = 'telephoneNumberDevice'; + + /// The input field expects a phone number's internal extension code. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["tel-extension"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String telephoneNumberExtension = 'telephoneNumberExtension'; + + /// The input field expects a phone number without the country code and area + /// code components. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["tel-local"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String telephoneNumberLocal = 'telephoneNumberLocal'; + + /// The input field expects the first part of the component of the telephone + /// number that follows the area code, when that component is split into two + /// components. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["tel-local-prefix"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String telephoneNumberLocalPrefix = 'telephoneNumberLocalPrefix'; + + /// The input field expects the second part of the component of the telephone + /// number that follows the area code, when that component is split into two + /// components. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["tel-local-suffix"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String telephoneNumberLocalSuffix = 'telephoneNumberLocalSuffix'; + + /// The input field expects a phone number without country code. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_PHONE_NATIONAL](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PHONE_NATIONAL). + /// * web: ["tel-national"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String telephoneNumberNational = 'telephoneNumberNational'; + + /// The amount that the user would like for the transaction (e.g. when + /// entering a bid or sale price). + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["transaction-amount"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String transactionAmount = 'transactionAmount'; + + /// The currency that the user would prefer the transaction to use, in [ISO + /// 4217 currency code](https://www.iso.org/iso-4217-currency-codes.html). + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * web: ["transaction-currency"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String transactionCurrency = 'transactionCurrency'; + + /// The input field expects a URL. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * iOS: [URL](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["url"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String url = 'url'; + + /// The input field expects a username or an account name. + /// + /// This hint will be translated to the below values on different platforms: + /// + /// * Android: [AUTOFILL_HINT_USERNAME](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_USERNAME). + /// * iOS: [username](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// * web: ["username"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute). + /// * Otherwise, the hint string will be used as-is. + static const String username = 'username'; +} + +/// A collection of autofill related information that represents an [AutofillClient]. +/// +/// Typically used in [TextInputConfiguration.autofillConfiguration]. +@immutable +class AutofillConfiguration { + /// Creates autofill related configuration information that can be sent to the + /// platform. + const AutofillConfiguration({ + required String uniqueIdentifier, + required List<String> autofillHints, + required TextEditingValue currentEditingValue, + String? hintText, + }) : this._( + enabled: true, + uniqueIdentifier: uniqueIdentifier, + autofillHints: autofillHints, + currentEditingValue: currentEditingValue, + hintText: hintText, + ); + + const AutofillConfiguration._({ + required this.enabled, + required this.uniqueIdentifier, + this.autofillHints = const <String>[], + this.hintText, + required this.currentEditingValue, + }); + + /// An [AutofillConfiguration] that indicates the [AutofillClient] does not + /// wish to be autofilled. + static const AutofillConfiguration disabled = AutofillConfiguration._( + enabled: false, + uniqueIdentifier: '', + currentEditingValue: TextEditingValue.empty, + ); + + /// Whether autofill should be enabled for the [AutofillClient]. + /// + /// To retrieve a disabled [AutofillConfiguration], use [disabled]. + final bool enabled; + + /// A string that uniquely identifies the current [AutofillClient]. + /// + /// The identifier needs to be unique within the [AutofillScope] for the + /// [AutofillClient] to receive the correct autofill value. + final String uniqueIdentifier; + + /// A list of strings that helps the autofill service identify the type of the + /// [AutofillClient]. + /// + /// {@template flutter.services.AutofillConfiguration.autofillHints} + /// For the best results, hint strings need to be understood by the platform's + /// autofill service. The common values of hint strings can be found in + /// [AutofillHints], as well as their availability on different platforms. + /// + /// If an autofillable input field needs to use a custom hint that translates to + /// different strings on different platforms, the easiest way to achieve that + /// is to return different hint strings based on the value of + /// [defaultTargetPlatform]. + /// + /// Each hint in the list, if not ignored, will be translated to the platform's + /// autofill hint type understood by its autofill services: + /// + /// * On iOS, only the first hint in the list is accounted for. The hint will + /// be translated to a + /// [UITextContentType](https://developer.apple.com/documentation/uikit/uitextcontenttype). + /// + /// * On Android, all hints in the list are translated to Android hint strings. + /// + /// * On web, only the first hint is accounted for and will be translated to + /// an "autocomplete" string. + /// + /// Providing an autofill hint that is predefined on the platform does not + /// automatically grant the input field eligibility for autofill. Ultimately, + /// it comes down to the autofill service currently in charge to determine + /// whether an input field is suitable for autofill and what the autofill + /// candidates are. + /// + /// See also: + /// + /// * [AutofillHints], a list of autofill hint strings that is predefined on at + /// least one platform. + /// + /// * [UITextContentType](https://developer.apple.com/documentation/uikit/uitextcontenttype), + /// the iOS equivalent. + /// + /// * Android [autofillHints](https://developer.android.com/reference/android/view/View#setAutofillHints(java.lang.String...)), + /// the Android equivalent. + /// + /// * The [autocomplete](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) attribute, + /// the web equivalent. + /// {@endtemplate} + final List<String> autofillHints; + + /// The current [TextEditingValue] of the [AutofillClient]. + final TextEditingValue currentEditingValue; + + /// The optional hint text placed on the view that typically suggests what + /// sort of input the field accepts, for example "enter your password here". + /// + /// If the developer does not specify any [autofillHints], the [hintText] can + /// be a useful indication to the platform autofill service. + final String? hintText; + + /// Returns a representation of this object as a JSON object. + Map<String, dynamic>? toJson() { + return enabled + ? <String, dynamic>{ + 'uniqueIdentifier': uniqueIdentifier, + 'hints': autofillHints, + 'editingValue': currentEditingValue.toJSON(), + if (hintText != null) 'hintText': hintText, + } + : null; + } +} + +/// An object that represents an autofillable input field in the autofill workflow. +/// +/// An [AutofillClient] provides autofill-related information of the input field +/// it represents to the platform, and consumes autofill inputs from the platform. +abstract class AutofillClient { + /// The unique identifier of this [AutofillClient]. + /// + /// The identifier must not be changed. + String get autofillId; + + /// The [TextInputConfiguration] that describes this [AutofillClient]. + /// + /// In order to participate in autofill, its + /// [TextInputConfiguration.autofillConfiguration] must not be null. + TextInputConfiguration get textInputConfiguration; + + /// Requests this [AutofillClient] update its [TextEditingValue] to the given + /// value. + void autofill(TextEditingValue newEditingValue); +} + +/// An ordered group within which [AutofillClient]s are logically connected. +/// +/// {@template flutter.services.AutofillScope} +/// [AutofillClient]s within the same [AutofillScope] are isolated from other +/// input fields during autofill. That is, when an autofillable [TextInputClient] +/// gains focus, only the [AutofillClient]s within the same [AutofillScope] will +/// be visible to the autofill service, in the same order as they appear in +/// [AutofillScope.autofillClients]. +/// +/// [AutofillScope] also allows [TextInput] to redirect autofill values from the +/// platform to the [AutofillClient] with the given identifier, by calling +/// [AutofillScope.getAutofillClient]. +/// +/// An [AutofillClient] that's not tied to any [AutofillScope] will only +/// participate in autofill if the autofill is directly triggered by its own +/// [TextInputClient]. +/// {@endtemplate} +abstract class AutofillScope { + /// Gets the [AutofillScope] associated with the given [autofillId], in + /// this [AutofillScope]. + /// + /// Returns null if there's no matching [AutofillClient]. + AutofillClient? getAutofillClient(String autofillId); + + /// The collection of [AutofillClient]s currently tied to this [AutofillScope]. + /// + /// Every [AutofillClient] in this list must have autofill enabled (i.e. its + /// [AutofillClient.textInputConfiguration] must have a non-null + /// [AutofillConfiguration].) + Iterable<AutofillClient> get autofillClients; + + /// Allows a [TextInputClient] to attach to this scope. This method should be + /// called in lieu of [TextInput.attach], when the [TextInputClient] wishes to + /// participate in autofill. + TextInputConnection attach(TextInputClient trigger, TextInputConfiguration configuration); +} + +@immutable +class _AutofillScopeTextInputConfiguration extends TextInputConfiguration { + _AutofillScopeTextInputConfiguration({ + required this.allConfigurations, + required TextInputConfiguration currentClientConfiguration, + }) : super(inputType: currentClientConfiguration.inputType, + obscureText: currentClientConfiguration.obscureText, + autocorrect: currentClientConfiguration.autocorrect, + smartDashesType: currentClientConfiguration.smartDashesType, + smartQuotesType: currentClientConfiguration.smartQuotesType, + enableSuggestions: currentClientConfiguration.enableSuggestions, + inputAction: currentClientConfiguration.inputAction, + textCapitalization: currentClientConfiguration.textCapitalization, + keyboardAppearance: currentClientConfiguration.keyboardAppearance, + actionLabel: currentClientConfiguration.actionLabel, + autofillConfiguration: currentClientConfiguration.autofillConfiguration, + ); + + final Iterable<TextInputConfiguration> allConfigurations; + + @override + Map<String, dynamic> toJson() { + final Map<String, dynamic> result = super.toJson(); + result['fields'] = allConfigurations + .map((TextInputConfiguration configuration) => configuration.toJson()) + .toList(growable: false); + return result; + } +} + +/// A partial implementation of [AutofillScope]. +/// +/// The mixin provides a default implementation for [AutofillScope.attach]. +mixin AutofillScopeMixin implements AutofillScope { + @override + TextInputConnection attach(TextInputClient trigger, TextInputConfiguration configuration) { + assert( + !autofillClients.any((AutofillClient client) => !client.textInputConfiguration.autofillConfiguration.enabled), + 'Every client in AutofillScope.autofillClients must enable autofill', + ); + + final TextInputConfiguration inputConfiguration = _AutofillScopeTextInputConfiguration( + allConfigurations: autofillClients.map((AutofillClient client) => client.textInputConfiguration), + currentClientConfiguration: configuration, + ); + return TextInput.attach(trigger, inputConfiguration); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/binary_messenger.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/binary_messenger.dart new file mode 100644 index 0000000000000000000000000000000000000000..d7774eae8ea471db8aaf3c15c125f471705ebbd8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/binary_messenger.dart @@ -0,0 +1,74 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:typed_data'; +import 'dart:ui' as ui; + +export 'dart:typed_data' show ByteData; +export 'dart:ui' show PlatformMessageResponseCallback; + +/// A function which takes a platform message and asynchronously returns an encoded response. +typedef MessageHandler = Future<ByteData?>? Function(ByteData? message); + +/// A messenger which sends binary data across the Flutter platform barrier. +/// +/// This class also registers handlers for incoming messages. +abstract class BinaryMessenger { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const BinaryMessenger(); + + /// Queues a message. + /// + /// The returned future completes immediately. + /// + /// This method adds the provided message to the given channel (named by the + /// `channel` argument) of the [ChannelBuffers] object. This simulates what + /// happens when a plugin on the platform thread (e.g. Kotlin or Swift code) + /// sends a message to the plugin package on the Dart thread. + /// + /// The `data` argument contains the message as encoded bytes. (The format + /// used for the message depends on the channel.) + /// + /// The `callback` argument, if non-null, is eventually invoked with the + /// response that would have been sent to the platform thread. + /// + /// In production code, it is more efficient to call + /// `ServicesBinding.instance.channelBuffers.push` directly. + /// + /// In tests, consider using + /// `tester.binding.defaultBinaryMessenger.handlePlatformMessage` (see + /// [WidgetTester], [TestWidgetsFlutterBinding], [TestDefaultBinaryMessenger], + /// and [TestDefaultBinaryMessenger.handlePlatformMessage] respectively). + /// + /// To register a handler for a given message channel, see [setMessageHandler]. + /// + /// To send a message _to_ a plugin on the platform thread, see [send]. + @Deprecated( + 'Instead of calling this method, use ServicesBinding.instance.channelBuffers.push. ' + 'In tests, consider using tester.binding.defaultBinaryMessenger.handlePlatformMessage ' + 'or TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.handlePlatformMessage. ' + 'This feature was deprecated after v3.9.0-19.0.pre.' + ) + Future<void> handlePlatformMessage(String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback); + + /// Send a binary message to the platform plugins on the given channel. + /// + /// Returns a [Future] which completes to the received response, undecoded, + /// in binary form. + Future<ByteData?>? send(String channel, ByteData? message); + + /// Set a callback for receiving messages from the platform plugins on the + /// given channel, without decoding them. + /// + /// The given callback will replace the currently registered callback for that + /// channel, if any. To remove the handler, pass null as the [handler] + /// argument. + /// + /// The handler's return value, if non-null, is sent as a response, unencoded. + void setMessageHandler(String channel, MessageHandler? handler); + + // Looking for setMockMessageHandler or checkMockMessageHandler? + // See this shim package: packages/flutter_test/lib/src/deprecated.dart +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/binding.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/binding.dart new file mode 100644 index 0000000000000000000000000000000000000000..60ee9572cd019b71b8bf477c1dffc2fe624a095a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/binding.dart @@ -0,0 +1,617 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:convert'; +import 'dart:io'; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; + +import 'asset_bundle.dart'; +import 'binary_messenger.dart'; +import 'debug.dart'; +import 'hardware_keyboard.dart'; +import 'message_codec.dart'; +import 'platform_channel.dart'; +import 'raw_keyboard.dart' show RawKeyboard; +import 'restoration.dart'; +import 'service_extensions.dart'; +import 'system_channels.dart'; +import 'text_input.dart'; + +export 'dart:ui' show ChannelBuffers, RootIsolateToken; + +export 'binary_messenger.dart' show BinaryMessenger; +export 'hardware_keyboard.dart' show HardwareKeyboard, KeyEventManager; +export 'restoration.dart' show RestorationManager; + +/// Listens for platform messages and directs them to the [defaultBinaryMessenger]. +/// +/// The [ServicesBinding] also registers a [LicenseEntryCollector] that exposes +/// the licenses found in the `LICENSE` file stored at the root of the asset +/// bundle, and implements the `ext.flutter.evict` service extension (see +/// [evict]). +mixin ServicesBinding on BindingBase, SchedulerBinding { + @override + void initInstances() { + super.initInstances(); + _instance = this; + _defaultBinaryMessenger = createBinaryMessenger(); + _restorationManager = createRestorationManager(); + _initKeyboard(); + initLicenses(); + SystemChannels.system.setMessageHandler((dynamic message) => handleSystemMessage(message as Object)); + SystemChannels.accessibility.setMessageHandler((dynamic message) => _handleAccessibilityMessage(message as Object)); + SystemChannels.lifecycle.setMessageHandler(_handleLifecycleMessage); + SystemChannels.platform.setMethodCallHandler(_handlePlatformMessage); + TextInput.ensureInitialized(); + readInitialLifecycleStateFromNativeWindow(); + initializationComplete(); + } + + /// The current [ServicesBinding], if one has been created. + /// + /// Provides access to the features exposed by this mixin. The binding must + /// be initialized before using this getter; this is typically done by calling + /// [runApp] or [WidgetsFlutterBinding.ensureInitialized]. + static ServicesBinding get instance => BindingBase.checkInstance(_instance); + static ServicesBinding? _instance; + + /// The global singleton instance of [HardwareKeyboard], which can be used to + /// query keyboard states. + HardwareKeyboard get keyboard => _keyboard; + late final HardwareKeyboard _keyboard; + + /// The global singleton instance of [KeyEventManager], which is used + /// internally to dispatch key messages. + /// + /// This property is deprecated, and will be removed. See + /// [HardwareKeyboard.addHandler] instead. + @Deprecated( + 'No longer supported. Add a handler to HardwareKeyboard instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + KeyEventManager get keyEventManager => _keyEventManager; + late final KeyEventManager _keyEventManager; + + void _initKeyboard() { + _keyboard = HardwareKeyboard(); + _keyEventManager = KeyEventManager(_keyboard, RawKeyboard.instance); + _keyboard.syncKeyboardState().then((_) { + platformDispatcher.onKeyData = _keyEventManager.handleKeyData; + SystemChannels.keyEvent.setMessageHandler(_keyEventManager.handleRawKeyMessage); + }); + } + + /// The default instance of [BinaryMessenger]. + /// + /// This is used to send messages from the application to the platform, and + /// keeps track of which handlers have been registered on each channel so + /// it may dispatch incoming messages to the registered handler. + /// + /// The default implementation returns a [BinaryMessenger] that delivers the + /// messages in the same order in which they are sent. + BinaryMessenger get defaultBinaryMessenger => _defaultBinaryMessenger; + late final BinaryMessenger _defaultBinaryMessenger; + + /// A token that represents the root isolate, used for coordinating with + /// background isolates. + /// + /// This property is primarily intended for use with + /// [BackgroundIsolateBinaryMessenger.ensureInitialized], which takes a + /// [RootIsolateToken] as its argument. The value `null` is returned when + /// executed from background isolates. + static ui.RootIsolateToken? get rootIsolateToken => ui.RootIsolateToken.instance; + + /// The low level buffering and dispatch mechanism for messages sent by + /// plugins on the engine side to their corresponding plugin code on + /// the framework side. + /// + /// This exposes the [dart:ui.channelBuffers] object. Bindings can override + /// this getter to intercept calls to the [ChannelBuffers] mechanism (for + /// example, for tests). + /// + /// In production, direct access to this object should not be necessary. + /// Messages are received and dispatched by the [defaultBinaryMessenger]. This + /// object is primarily used to send mock messages in tests, via the + /// [ChannelBuffers.push] method (simulating a plugin sending a message to the + /// framework). + /// + /// See also: + /// + /// * [PlatformDispatcher.sendPlatformMessage], which is used for sending + /// messages to plugins from the framework (the opposite of + /// [channelBuffers]). + /// * [platformDispatcher], the [PlatformDispatcher] singleton. + ui.ChannelBuffers get channelBuffers => ui.channelBuffers; + + /// Creates a default [BinaryMessenger] instance that can be used for sending + /// platform messages. + /// + /// Many Flutter framework components that communicate with the platform + /// assume messages are received by the platform in the same order in which + /// they are sent. When overriding this method, be sure the [BinaryMessenger] + /// implementation guarantees FIFO delivery. + @protected + BinaryMessenger createBinaryMessenger() { + return const _DefaultBinaryMessenger._(); + } + + /// Called when the operating system notifies the application of a memory + /// pressure situation. + /// + /// This method exposes the `memoryPressure` notification from + /// [SystemChannels.system]. + @protected + @mustCallSuper + void handleMemoryPressure() { + rootBundle.clear(); + } + + /// Handler called for messages received on the [SystemChannels.system] + /// message channel. + /// + /// Other bindings may override this to respond to incoming system messages. + @protected + @mustCallSuper + Future<void> handleSystemMessage(Object systemMessage) async { + final Map<String, dynamic> message = systemMessage as Map<String, dynamic>; + final String type = message['type'] as String; + switch (type) { + case 'memoryPressure': + handleMemoryPressure(); + } + return; + } + + /// Adds relevant licenses to the [LicenseRegistry]. + /// + /// By default, the [ServicesBinding]'s implementation of [initLicenses] adds + /// all the licenses collected by the `flutter` tool during compilation. + @protected + @mustCallSuper + void initLicenses() { + LicenseRegistry.addLicense(_addLicenses); + } + + Stream<LicenseEntry> _addLicenses() { + late final StreamController<LicenseEntry> controller; + controller = StreamController<LicenseEntry>( + onListen: () async { + late final String rawLicenses; + if (kIsWeb) { + // NOTICES for web isn't compressed since we don't have access to + // dart:io on the client side and it's already compressed between + // the server and client. + rawLicenses = await rootBundle.loadString('NOTICES', cache: false); + } else { + // The compressed version doesn't have a more common .gz extension + // because gradle for Android non-transparently manipulates .gz files. + final ByteData licenseBytes = await rootBundle.load('NOTICES.Z'); + final List<int> unzippedBytes = await compute<List<int>, List<int>>(gzip.decode, licenseBytes.buffer.asUint8List(), debugLabel: 'decompressLicenses'); + rawLicenses = await compute<List<int>, String>(utf8.decode, unzippedBytes, debugLabel: 'utf8DecodeLicenses'); + } + final List<LicenseEntry> licenses = await compute<String, List<LicenseEntry>>(_parseLicenses, rawLicenses, debugLabel: 'parseLicenses'); + licenses.forEach(controller.add); + await controller.close(); + }, + ); + return controller.stream; + } + + // This is run in another isolate created by _addLicenses above. + static List<LicenseEntry> _parseLicenses(String rawLicenses) { + final String licenseSeparator = '\n${'-' * 80}\n'; + final List<LicenseEntry> result = <LicenseEntry>[]; + final List<String> licenses = rawLicenses.split(licenseSeparator); + for (final String license in licenses) { + final int split = license.indexOf('\n\n'); + if (split >= 0) { + result.add(LicenseEntryWithLineBreaks( + license.substring(0, split).split('\n'), + license.substring(split + 2), + )); + } else { + result.add(LicenseEntryWithLineBreaks(const <String>[], license)); + } + } + return result; + } + + @override + void initServiceExtensions() { + super.initServiceExtensions(); + + assert(() { + registerStringServiceExtension( + name: ServicesServiceExtensions.evict.name, + getter: () async => '', + setter: (String value) async { + evict(value); + }, + ); + return true; + }()); + + if (!kReleaseMode) { + registerBoolServiceExtension( + name: ServicesServiceExtensions.profilePlatformChannels.name, + getter: () async => debugProfilePlatformChannels, + setter: (bool value) async { + debugProfilePlatformChannels = value; + }, + ); + } + } + + /// Called in response to the `ext.flutter.evict` service extension. + /// + /// This is used by the `flutter` tool during hot reload so that any images + /// that have changed on disk get cleared from caches. + @protected + @mustCallSuper + void evict(String asset) { + rootBundle.evict(asset); + } + + // App life cycle + + /// Initializes the [lifecycleState] with the + /// [dart:ui.PlatformDispatcher.initialLifecycleState]. + /// + /// Once the [lifecycleState] is populated through any means (including this + /// method), this method will do nothing. This is because the + /// [dart:ui.PlatformDispatcher.initialLifecycleState] may already be stale + /// and it no longer makes sense to use the initial state at dart vm startup + /// as the current state anymore. + /// + /// The latest state should be obtained by subscribing to + /// [WidgetsBindingObserver.didChangeAppLifecycleState]. + @protected + void readInitialLifecycleStateFromNativeWindow() { + if (lifecycleState != null || platformDispatcher.initialLifecycleState.isEmpty) { + return; + } + _handleLifecycleMessage(platformDispatcher.initialLifecycleState); + } + + Future<String?> _handleLifecycleMessage(String? message) async { + final AppLifecycleState? state = _parseAppLifecycleMessage(message!); + final List<AppLifecycleState> generated = _generateStateTransitions(lifecycleState, state!); + generated.forEach(handleAppLifecycleStateChanged); + return null; + } + + List<AppLifecycleState> _generateStateTransitions(AppLifecycleState? previousState, AppLifecycleState state) { + if (previousState == state) { + return const <AppLifecycleState>[]; + } + if (previousState == AppLifecycleState.paused && state == AppLifecycleState.detached) { + // Handle the wrap-around from paused to detached + return const <AppLifecycleState>[ + AppLifecycleState.detached, + ]; + } + final List<AppLifecycleState> stateChanges = <AppLifecycleState>[]; + if (previousState == null) { + // If there was no previous state, just jump directly to the new state. + stateChanges.add(state); + } else { + final int previousStateIndex = AppLifecycleState.values.indexOf(previousState); + final int stateIndex = AppLifecycleState.values.indexOf(state); + assert(previousStateIndex != -1, 'State $previousState missing in stateOrder array'); + assert(stateIndex != -1, 'State $state missing in stateOrder array'); + if (previousStateIndex > stateIndex) { + for (int i = stateIndex; i < previousStateIndex; ++i) { + stateChanges.insert(0, AppLifecycleState.values[i]); + } + } else { + for (int i = previousStateIndex + 1; i <= stateIndex; ++i) { + stateChanges.add(AppLifecycleState.values[i]); + } + } + } + assert((){ + AppLifecycleState? starting = previousState; + for (final AppLifecycleState ending in stateChanges) { + if (!_debugVerifyLifecycleChange(starting, ending)) { + return false; + } + starting = ending; + } + return true; + }(), 'Invalid lifecycle state transition generated from $previousState to $state (generated $stateChanges)'); + return stateChanges; + } + + static bool _debugVerifyLifecycleChange(AppLifecycleState? starting, AppLifecycleState ending) { + if (starting == null) { + // Any transition from null is fine, since it is initializing the state. + return true; + } + if (starting == ending) { + // Any transition to itself shouldn't happen. + return false; + } + switch (starting) { + case AppLifecycleState.detached: + if (ending == AppLifecycleState.resumed || ending == AppLifecycleState.paused) { + return true; + } + case AppLifecycleState.resumed: + // Can't go from resumed to detached directly (must go through paused). + if (ending == AppLifecycleState.inactive) { + return true; + } + case AppLifecycleState.inactive: + if (ending == AppLifecycleState.resumed || ending == AppLifecycleState.hidden) { + return true; + } + case AppLifecycleState.hidden: + if (ending == AppLifecycleState.inactive || ending == AppLifecycleState.paused) { + return true; + } + case AppLifecycleState.paused: + if (ending == AppLifecycleState.hidden || ending == AppLifecycleState.detached) { + return true; + } + } + return false; + } + + + /// Listenable that notifies when the accessibility focus on the system have changed. + final ValueNotifier<int?> accessibilityFocus = ValueNotifier<int?>(null); + + Future<void> _handleAccessibilityMessage(Object accessibilityMessage) async { + final Map<String, dynamic> message = + (accessibilityMessage as Map<Object?, Object?>).cast<String, dynamic>(); + final String type = message['type'] as String; + switch (type) { + case 'didGainFocus': + accessibilityFocus.value = message['nodeId'] as int; + } + return; + } + + Future<dynamic> _handlePlatformMessage(MethodCall methodCall) async { + final String method = methodCall.method; + assert(method == 'SystemChrome.systemUIChange' || method == 'System.requestAppExit'); + switch (method) { + case 'SystemChrome.systemUIChange': + final List<dynamic> args = methodCall.arguments as List<dynamic>; + if (_systemUiChangeCallback != null) { + await _systemUiChangeCallback!(args[0] as bool); + } + case 'System.requestAppExit': + return <String, dynamic>{'response': (await handleRequestAppExit()).name}; + } + } + + static AppLifecycleState? _parseAppLifecycleMessage(String message) { + switch (message) { + case 'AppLifecycleState.resumed': + return AppLifecycleState.resumed; + case 'AppLifecycleState.inactive': + return AppLifecycleState.inactive; + case 'AppLifecycleState.hidden': + return AppLifecycleState.hidden; + case 'AppLifecycleState.paused': + return AppLifecycleState.paused; + case 'AppLifecycleState.detached': + return AppLifecycleState.detached; + } + return null; + } + + /// Handles any requests for application exit that may be received on the + /// [SystemChannels.platform] method channel. + /// + /// By default, returns [ui.AppExitResponse.exit]. + /// + /// {@template flutter.services.binding.ServicesBinding.requestAppExit} + /// Not all exits are cancelable, so not all exits will call this function. Do + /// not rely on this function as a place to save critical data, because you + /// will be disappointed. There are a number of ways that the application can + /// exit without letting the application know first: power can be unplugged, + /// the battery removed, the application can be killed in a task manager or + /// command line, or the device could have a rapid unplanned disassembly (i.e. + /// it could explode). In all of those cases (and probably others), no + /// notification will be given to the application that it is about to exit. + /// {@endtemplate} + /// + /// {@tool sample} + /// This examples shows how an application can cancel (or not) OS requests for + /// quitting an application. Currently this is only supported on macOS and + /// Linux. + /// + /// ** See code in examples/api/lib/services/binding/handle_request_app_exit.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [WidgetsBindingObserver.didRequestAppExit], which can be overridden to + /// respond to this message. + /// * [WidgetsBinding.handleRequestAppExit] which overrides this method to + /// notify its observers. + Future<ui.AppExitResponse> handleRequestAppExit() async { + return ui.AppExitResponse.exit; + } + + /// Exits the application by calling the native application API method for + /// exiting an application cleanly. + /// + /// This differs from calling `dart:io`'s [exit] function in that it gives the + /// engine a chance to clean up resources so that it doesn't crash on exit, so + /// calling this is always preferred over calling [exit]. It also optionally + /// gives handlers of [handleRequestAppExit] a chance to cancel the + /// application exit. + /// + /// The [exitType] indicates what kind of exit to perform. For + /// [ui.AppExitType.cancelable] exits, the application is queried through a + /// call to [handleRequestAppExit], where the application can optionally + /// cancel the request for exit. If the [exitType] is + /// [ui.AppExitType.required], then the application exits immediately without + /// querying the application. + /// + /// For [ui.AppExitType.cancelable] exits, the returned response value is the + /// response obtained from the application as to whether the exit was canceled + /// or not. Practically, the response will never be [ui.AppExitResponse.exit], + /// since the application will have already exited by the time the result + /// would have been received. + /// + /// The optional [exitCode] argument will be used as the application exit code + /// on platforms where an exit code is supported. On other platforms it may be + /// ignored. It defaults to zero. + /// + /// See also: + /// + /// * [WidgetsBindingObserver.didRequestAppExit] for a handler you can + /// override on a [WidgetsBindingObserver] to receive exit requests. + Future<ui.AppExitResponse> exitApplication(ui.AppExitType exitType, [int exitCode = 0]) async { + final Map<String, Object?>? result = await SystemChannels.platform.invokeMethod<Map<String, Object?>>( + 'System.exitApplication', + <String, Object?>{'type': exitType.name, 'exitCode': exitCode}, + ); + if (result == null ) { + return ui.AppExitResponse.cancel; + } + switch (result['response']) { + case 'cancel': + return ui.AppExitResponse.cancel; + case 'exit': + default: + // In practice, this will never get returned, because the application + // will have exited before it returns. + return ui.AppExitResponse.exit; + } + } + + /// The [RestorationManager] synchronizes the restoration data between + /// engine and framework. + /// + /// See the docs for [RestorationManager] for a discussion of restoration + /// state and how it is organized in Flutter. + /// + /// To use a different [RestorationManager] subclasses can override + /// [createRestorationManager], which is called to create the instance + /// returned by this getter. + RestorationManager get restorationManager => _restorationManager; + late RestorationManager _restorationManager; + + /// Creates the [RestorationManager] instance available via + /// [restorationManager]. + /// + /// Can be overridden in subclasses to create a different [RestorationManager]. + @protected + RestorationManager createRestorationManager() { + return RestorationManager(); + } + + SystemUiChangeCallback? _systemUiChangeCallback; + + /// Sets the callback for the `SystemChrome.systemUIChange` method call + /// received on the [SystemChannels.platform] channel. + /// + /// This is typically not called directly. System UI changes that this method + /// responds to are associated with [SystemUiMode]s, which are configured + /// using [SystemChrome]. Use [SystemChrome.setSystemUIChangeCallback] to configure + /// along with other SystemChrome settings. + /// + /// See also: + /// + /// * [SystemChrome.setEnabledSystemUIMode], which specifies the + /// [SystemUiMode] to have visible when the application is running. + // ignore: use_setters_to_change_properties, (API predates enforcing the lint) + void setSystemUiChangeCallback(SystemUiChangeCallback? callback) { + _systemUiChangeCallback = callback; + } + + /// Alert the engine that the binding is registered. This instructs the engine to + /// register its top level window handler on Windows. This signals that the app + /// is able to process "System.requestAppExit" signals from the engine. + @protected + Future<void> initializationComplete() async { + await SystemChannels.platform.invokeMethod('System.initializationComplete'); + } +} + +/// Signature for listening to changes in the [SystemUiMode]. +/// +/// Set by [SystemChrome.setSystemUIChangeCallback]. +typedef SystemUiChangeCallback = Future<void> Function(bool systemOverlaysAreVisible); + +/// The default implementation of [BinaryMessenger]. +/// +/// This messenger sends messages from the app-side to the platform-side and +/// dispatches incoming messages from the platform-side to the appropriate +/// handler. +class _DefaultBinaryMessenger extends BinaryMessenger { + const _DefaultBinaryMessenger._(); + + @override + Future<void> handlePlatformMessage( + String channel, + ByteData? message, + ui.PlatformMessageResponseCallback? callback, + ) async { + ui.channelBuffers.push(channel, message, (ByteData? data) { + if (callback != null) { + callback(data); + } + }); + } + + @override + Future<ByteData?> send(String channel, ByteData? message) { + final Completer<ByteData?> completer = Completer<ByteData?>(); + // ui.PlatformDispatcher.instance is accessed directly instead of using + // ServicesBinding.instance.platformDispatcher because this method might be + // invoked before any binding is initialized. This issue was reported in + // #27541. It is not ideal to statically access + // ui.PlatformDispatcher.instance because the PlatformDispatcher may be + // dependency injected elsewhere with a different instance. However, static + // access at this location seems to be the least bad option. + // TODO(ianh): Use ServicesBinding.instance once we have better diagnostics + // on that getter. + ui.PlatformDispatcher.instance.sendPlatformMessage(channel, message, (ByteData? reply) { + try { + completer.complete(reply); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'services library', + context: ErrorDescription('during a platform message response callback'), + )); + } + }); + return completer.future; + } + + @override + void setMessageHandler(String channel, MessageHandler? handler) { + if (handler == null) { + ui.channelBuffers.clearListener(channel); + } else { + ui.channelBuffers.setListener(channel, (ByteData? data, ui.PlatformMessageResponseCallback callback) async { + ByteData? response; + try { + response = await handler(data); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'services library', + context: ErrorDescription('during a platform message callback'), + )); + } finally { + callback(response); + } + }); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/browser_context_menu.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/browser_context_menu.dart new file mode 100644 index 0000000000000000000000000000000000000000..982fbc24c1509c722dadf5f766b46c001075fc66 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/browser_context_menu.dart @@ -0,0 +1,83 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'system_channels.dart'; + +/// Controls the browser's context menu on the web platform. +/// +/// The context menu is the menu that appears on right clicking or selecting +/// text in the browser, for example. +/// +/// On web, by default, the browser's context menu is enabled and Flutter's +/// context menus are hidden. +/// +/// On all non-web platforms, this does nothing. +class BrowserContextMenu { + BrowserContextMenu._(); + + static final BrowserContextMenu _instance = BrowserContextMenu._(); + + /// Whether showing the browser's context menu is enabled. + /// + /// When true, any event that the browser typically uses to trigger its + /// context menu (e.g. right click) will do so. When false, the browser's + /// context menu will not show. + /// + /// It's possible for this to be true but for the browser's context menu to + /// not show due to direct manipulation of the DOM. For example, handlers for + /// the browser's `contextmenu` event could be added/removed in the browser's + /// JavaScript console, and this boolean wouldn't know about it. This boolean + /// only indicates the results of calling [disableContextMenu] and + /// [enableContextMenu] here. + /// + /// Defaults to true. + static bool get enabled => _instance._enabled; + + bool _enabled = true; + + final MethodChannel _channel = SystemChannels.contextMenu; + + /// Disable the browser's context menu. + /// + /// By default, when the app starts, the browser's context menu is already + /// enabled. + /// + /// This is an asynchronous action. The context menu can be considered to be + /// disabled at the time that the Future resolves. [enabled] won't reflect the + /// change until that time. + /// + /// See also: + /// * [enableContextMenu], which performs the opposite operation. + static Future<void> disableContextMenu() { + assert(kIsWeb, 'This has no effect on platforms other than web.'); + return _instance._channel.invokeMethod<void>( + 'disableContextMenu', + ).then((_) { + _instance._enabled = false; + }); + } + + /// Enable the browser's context menu. + /// + /// By default, when the app starts, the browser's context menu is already + /// enabled. Typically this method would be called after first calling + /// [disableContextMenu]. + /// + /// This is an asynchronous action. The context menu can be considered to be + /// enabled at the time that the Future resolves. [enabled] won't reflect the + /// change until that time. + /// + /// See also: + /// * [disableContextMenu], which performs the opposite operation. + static Future<void> enableContextMenu() { + assert(kIsWeb, 'This has no effect on platforms other than web.'); + return _instance._channel.invokeMethod<void>( + 'enableContextMenu', + ).then((_) { + _instance._enabled = true; + }); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/clipboard.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/clipboard.dart new file mode 100644 index 0000000000000000000000000000000000000000..88ede40fca002e7594493fa0fccb50167cedeb98 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/clipboard.dart @@ -0,0 +1,77 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'system_channels.dart'; + +/// Data stored on the system clipboard. +/// +/// The system clipboard can contain data of various media types. This data +/// structure currently supports only plain text data, in the [text] property. +@immutable +class ClipboardData { + /// Creates data for the system clipboard. + const ClipboardData({ required String this.text }); + + /// Plain text variant of this clipboard data. + // This is nullable as other clipboard data variants, like images, may be + // added in the future. Currently, plain text is the only supported variant + // and this is guaranteed to be non-null. + final String? text; +} + +/// Utility methods for interacting with the system's clipboard. +abstract final class Clipboard { + // Constants for common [getData] [format] types. + + /// Plain text data format string. + /// + /// Used with [getData]. + static const String kTextPlain = 'text/plain'; + + /// Stores the given clipboard data on the clipboard. + static Future<void> setData(ClipboardData data) async { + await SystemChannels.platform.invokeMethod<void>( + 'Clipboard.setData', + <String, dynamic>{ + 'text': data.text, + }, + ); + } + + /// Retrieves data from the clipboard that matches the given format. + /// + /// The `format` argument specifies the media type, such as `text/plain`, of + /// the data to obtain. + /// + /// Returns a future which completes to null if the data could not be + /// obtained, and to a [ClipboardData] object if it could. + static Future<ClipboardData?> getData(String format) async { + final Map<String, dynamic>? result = await SystemChannels.platform.invokeMethod( + 'Clipboard.getData', + format, + ); + if (result == null) { + return null; + } + return ClipboardData(text: result['text'] as String); + } + + /// Returns a future that resolves to true iff the clipboard contains string + /// data. + /// + /// See also: + /// * [The iOS hasStrings method](https://developer.apple.com/documentation/uikit/uipasteboard/1829416-hasstrings?language=objc). + static Future<bool> hasStrings() async { + final Map<String, dynamic>? result = await SystemChannels.platform.invokeMethod( + 'Clipboard.hasStrings', + Clipboard.kTextPlain, + ); + if (result == null) { + return false; + } + return result['value'] as bool; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/debug.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/debug.dart new file mode 100644 index 0000000000000000000000000000000000000000..cc35a03f344b5cdbfa927d968a6c96a17474410a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/debug.dart @@ -0,0 +1,63 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'hardware_keyboard.dart'; + +export 'hardware_keyboard.dart' show KeyDataTransitMode; + +/// Override the transit mode with which key events are simulated. +/// +/// Setting [debugKeyEventSimulatorTransitModeOverride] is a good way to make +/// certain tests simulate the behavior of different type of platforms in terms +/// of their extent of support for keyboard API. +/// +/// This value is deprecated and will be removed. +@Deprecated( + 'No longer supported. Transit mode is always key data only. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +KeyDataTransitMode? debugKeyEventSimulatorTransitModeOverride; + +/// Setting to true will cause extensive logging to occur when key events are +/// received. +/// +/// Can be used to debug keyboard issues: each time a key event is received on +/// the framework side, the event details and the current pressed state will +/// be printed. +bool debugPrintKeyboardEvents = false; + +/// Returns true if none of the widget library debug variables have been changed. +/// +/// This function is used by the test framework to ensure that debug variables +/// haven't been inadvertently changed. +/// +/// See [the services library](services/services-library.html) for a complete list. +bool debugAssertAllServicesVarsUnset(String reason) { + assert(() { + if (debugKeyEventSimulatorTransitModeOverride != null) { + throw FlutterError(reason); + } + if (debugPrintKeyboardEvents) { + throw FlutterError(reason); + } + return true; + }()); + return true; +} + +/// Controls whether platform channel usage can be debugged in non-release mode. +/// +/// This value is modified by calls to the +/// [ServicesServiceExtensions.profilePlatformChannels] service extension. +/// +/// See also: +/// +/// * [shouldProfilePlatformChannels], which checks both +/// [kProfilePlatformChannels] and [debugProfilePlatformChannels] for the +/// current run mode. +/// * [kProfilePlatformChannels], which determines whether platform channel +/// usage can be debugged in release mode. +bool debugProfilePlatformChannels = false; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/deferred_component.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/deferred_component.dart new file mode 100644 index 0000000000000000000000000000000000000000..1c39184921248d021e6556321a83bd8dca175a13 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/deferred_component.dart @@ -0,0 +1,104 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'system_channels.dart'; + +// Examples can assume: +// // so that we can import the fake "split_component.dart" in an example below: +// // ignore_for_file: uri_does_not_exist + +/// Manages the installation and loading of deferred components. +/// +/// Deferred components allow Flutter applications to download precompiled AOT +/// dart code and assets at runtime, reducing the install size of apps and +/// avoiding installing unnecessary code/assets on end user devices. Common +/// use cases include deferring installation of advanced or infrequently +/// used features and limiting locale specific features to users of matching +/// locales. Deferred components can only deliver split off parts of the same +/// app that was built and installed on the device. It cannot load new code +/// written after the app is distributed. +/// +/// Deferred components are currently an Android-only feature. The methods in +/// this class are a no-op and all assets and dart code are already available +/// without installation if called on other platforms. +abstract final class DeferredComponent { + // TODO(garyq): We should eventually expand this to install components by loadingUnitId + // as well as componentName, but currently, loadingUnitId is opaque to the dart code + // so this is not possible. The API has been left flexible to allow adding + // loadingUnitId as a parameter. + + /// Requests that an assets-only deferred component identified by the [componentName] + /// be downloaded and installed. + /// + /// This method returns a Future<void> that will complete when the feature is + /// installed and any assets are ready to be used. When an error occurs, the + /// future will complete with an error. + /// + /// This method should be used for asset-only deferred components or loading just + /// the assets from a component with both dart code and assets. Deferred components + /// containing dart code should call `loadLibrary()` on a deferred imported + /// library's prefix to ensure that the dart code is properly loaded as + /// `loadLibrary()` will provide the loading unit ID needed for the Dart + /// library loading process. For example: + /// + /// ```dart + /// import 'split_component.dart' deferred as split_component; + /// // ... + /// void _showSplit() { + /// // ... + /// split_component.loadLibrary(); + /// // ... + /// } + /// ``` + /// + /// This method will not load associated dart libraries contained in the component, + /// though it will download the files necessary and subsequent calls to `loadLibrary()` + /// to load will complete faster. + /// + /// Assets installed by this method may be accessed in the same way as any other + /// local asset by providing a string path to the asset. + /// + /// See also: + /// + /// * [uninstallDeferredComponent], a method to request the uninstall of a component. + /// * [loadLibrary](https://dart.dev/guides/language/language-tour#lazily-loading-a-library), + /// the Dart method to trigger the installation of the corresponding deferred component that + /// contains the Dart library. + static Future<void> installDeferredComponent({required String componentName}) async { + await SystemChannels.deferredComponent.invokeMethod<void>( + 'installDeferredComponent', + <String, dynamic>{ 'loadingUnitId': -1, 'componentName': componentName }, + ); + } + + /// Requests that a deferred component identified by the [componentName] be + /// uninstalled. + /// + /// Since uninstallation typically requires significant disk i/o, this method only + /// signals the intent to uninstall. Completion of the returned future indicates + /// that the request to uninstall has been registered. Actual uninstallation (e.g., + /// removal of assets and files) may occur at a later time. However, once uninstallation + /// is requested, the deferred component should not be used anymore until + /// [installDeferredComponent] or `loadLibrary()` is called again. + /// + /// It is safe to request an uninstall when dart code from the component is in use, + /// but assets from the component should not be used once the component uninstall is + /// requested. The dart code will remain usable in the app's current session but + /// is not guaranteed to work in future sessions. + /// + /// See also: + /// + /// * [installDeferredComponent], a method to install asset-only components. + /// * [loadLibrary](https://api.dart.dev/dart-mirrors/LibraryDependencyMirror/loadLibrary.html), + /// the dart method to trigger the installation of the corresponding deferred component that + /// contains the dart library. + static Future<void> uninstallDeferredComponent({required String componentName}) async { + await SystemChannels.deferredComponent.invokeMethod<void>( + 'uninstallDeferredComponent', + <String, dynamic>{ 'loadingUnitId': -1, 'componentName': componentName }, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/flavor.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/flavor.dart new file mode 100644 index 0000000000000000000000000000000000000000..292c3b37c43e80b24dc2390d1e8e2e8bbd44a2a2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/flavor.dart @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// The flavor this app was built with. +/// +/// This is equivalent to the value argued to the `--flavor` option at build time. +/// This will be `null` if the `--flavor` option was not provided. +const String? appFlavor = String.fromEnvironment('FLUTTER_APP_FLAVOR') != '' ? + String.fromEnvironment('FLUTTER_APP_FLAVOR') : null; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/font_loader.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/font_loader.dart new file mode 100644 index 0000000000000000000000000000000000000000..cb0e099fcae0afb8b815411317e25c480ed9bed3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/font_loader.dart @@ -0,0 +1,82 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; + +export 'dart:typed_data' show ByteData; + +/// A class that enables the dynamic loading of fonts at runtime. +/// +/// The [FontLoader] class provides a builder pattern, where the caller builds +/// up the assets that make up a font family, then calls [load] to load the +/// entire font family into a running Flutter application. +class FontLoader { + /// Creates a new [FontLoader] that will load font assets for the specified + /// [family]. + /// + /// The font family will not be available for use until [load] has been + /// called. + FontLoader(this.family) + : _loaded = false, + _fontFutures = <Future<Uint8List>>[]; + + /// The font family being loaded. + /// + /// The family groups a series of related font assets, each of which defines + /// how to render a specific [FontWeight] and [FontStyle] within the family. + final String family; + + /// Registers a font asset to be loaded by this font loader. + /// + /// The [bytes] argument specifies the actual font asset bytes. Currently, + /// only OpenType (OTF) and TrueType (TTF) fonts are supported. + void addFont(Future<ByteData> bytes) { + if (_loaded) { + throw StateError('FontLoader is already loaded'); + } + + _fontFutures.add(bytes.then( + (ByteData data) => Uint8List.view(data.buffer, data.offsetInBytes, data.lengthInBytes), + )); + } + + /// Loads this font loader's font [family] and all of its associated assets + /// into the Flutter engine, making the font available to the current + /// application. + /// + /// This method should only be called once per font loader. Attempts to + /// load fonts from the same loader more than once will cause a [StateError] + /// to be thrown. + /// + /// The returned future will complete with an error if any of the font asset + /// futures yield an error. + Future<void> load() async { + if (_loaded) { + throw StateError('FontLoader is already loaded'); + } + _loaded = true; + + final Iterable<Future<void>> loadFutures = _fontFutures.map( + (Future<Uint8List> f) => f.then<void>( + (Uint8List list) => loadFont(list, family), + ), + ); + await Future.wait(loadFutures.toList()); + } + + /// Hook called to load a font asset into the engine. + /// + /// Subclasses may override this to replace the default loading logic with + /// custom logic (for example, to mock the underlying engine API in tests). + @protected + @visibleForTesting + Future<void> loadFont(Uint8List list, String family) { + return loadFontFromList(list, fontFamily: family); + } + + bool _loaded; + final List<Future<Uint8List>> _fontFutures; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/haptic_feedback.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/haptic_feedback.dart new file mode 100644 index 0000000000000000000000000000000000000000..e3aad6c28e37f1f17eb3ac9ee8c1c6429c571f90 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/haptic_feedback.dart @@ -0,0 +1,79 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'system_channels.dart'; + +/// Allows access to the haptic feedback interface on the device. +/// +/// This API is intentionally terse since it calls default platform behavior. It +/// is not suitable for precise control of the system's haptic feedback module. +abstract final class HapticFeedback { + /// Provides vibration haptic feedback to the user for a short duration. + /// + /// On iOS devices that support haptic feedback, this uses the default system + /// vibration value (`kSystemSoundID_Vibrate`). + /// + /// On Android, this uses the platform haptic feedback API to simulate a + /// response to a long press (`HapticFeedbackConstants.LONG_PRESS`). + static Future<void> vibrate() async { + await SystemChannels.platform.invokeMethod<void>('HapticFeedback.vibrate'); + } + + /// Provides a haptic feedback corresponding a collision impact with a light mass. + /// + /// On iOS versions 10 and above, this uses a `UIImpactFeedbackGenerator` with + /// `UIImpactFeedbackStyleLight`. This call has no effects on iOS versions + /// below 10. + /// + /// On Android, this uses `HapticFeedbackConstants.VIRTUAL_KEY`. + static Future<void> lightImpact() async { + await SystemChannels.platform.invokeMethod<void>( + 'HapticFeedback.vibrate', + 'HapticFeedbackType.lightImpact', + ); + } + + /// Provides a haptic feedback corresponding a collision impact with a medium mass. + /// + /// On iOS versions 10 and above, this uses a `UIImpactFeedbackGenerator` with + /// `UIImpactFeedbackStyleMedium`. This call has no effects on iOS versions + /// below 10. + /// + /// On Android, this uses `HapticFeedbackConstants.KEYBOARD_TAP`. + static Future<void> mediumImpact() async { + await SystemChannels.platform.invokeMethod<void>( + 'HapticFeedback.vibrate', + 'HapticFeedbackType.mediumImpact', + ); + } + + /// Provides a haptic feedback corresponding a collision impact with a heavy mass. + /// + /// On iOS versions 10 and above, this uses a `UIImpactFeedbackGenerator` with + /// `UIImpactFeedbackStyleHeavy`. This call has no effects on iOS versions + /// below 10. + /// + /// On Android, this uses `HapticFeedbackConstants.CONTEXT_CLICK` on API levels + /// 23 and above. This call has no effects on Android API levels below 23. + static Future<void> heavyImpact() async { + await SystemChannels.platform.invokeMethod<void>( + 'HapticFeedback.vibrate', + 'HapticFeedbackType.heavyImpact', + ); + } + + /// Provides a haptic feedback indication selection changing through discrete values. + /// + /// On iOS versions 10 and above, this uses a `UISelectionFeedbackGenerator`. + /// This call has no effects on iOS versions below 10. + /// + /// On Android, this uses `HapticFeedbackConstants.CLOCK_TICK`. + static Future<void> selectionClick() async { + await SystemChannels.platform.invokeMethod<void>( + 'HapticFeedback.vibrate', + 'HapticFeedbackType.selectionClick', + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/hardware_keyboard.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/hardware_keyboard.dart new file mode 100644 index 0000000000000000000000000000000000000000..32a0898e24fa5c51887bcc8bb8c6044d6b6bf1f8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/hardware_keyboard.dart @@ -0,0 +1,1345 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; + +import 'binding.dart'; +import 'debug.dart'; +import 'raw_keyboard.dart'; +import 'raw_keyboard_android.dart'; +import 'system_channels.dart'; + +export 'dart:ui' show KeyData; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; + +export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey; + +// When using _keyboardDebug, always call it like so: +// +// assert(_keyboardDebug(() => 'Blah $foo')); +// +// It needs to be inside the assert in order to be removed in release mode, and +// it needs to use a closure to generate the string in order to avoid string +// interpolation when debugPrintKeyboardEvents is false. +// +// It will throw a StateError if you try to call it when the app is in release +// mode. +bool _keyboardDebug( + String Function() messageFunc, [ + Iterable<Object> Function()? detailsFunc, +]) { + if (kReleaseMode) { + throw StateError( + '_keyboardDebug was called in Release mode, which means they are called ' + 'without being wrapped in an assert. Always call _keyboardDebug like so:\n' + r" assert(_keyboardDebug(() => 'Blah $foo'));" + ); + } + if (!debugPrintKeyboardEvents) { + return true; + } + debugPrint('KEYBOARD: ${messageFunc()}'); + final Iterable<Object> details = detailsFunc?.call() ?? const <Object>[]; + if (details.isNotEmpty) { + for (final Object detail in details) { + debugPrint(' $detail'); + } + } + // Return true so that it can be used inside of an assert. + return true; +} + +/// Represents a lock mode of a keyboard, such as [KeyboardLockMode.capsLock]. +/// +/// A lock mode locks some of a keyboard's keys into a distinct mode of operation, +/// depending on the lock settings selected. The status of the mode is toggled +/// with each key down of its corresponding logical key. A [KeyboardLockMode] +/// object is used to query whether this mode is enabled on the keyboard. +/// +/// Only a limited number of modes are supported, which are enumerated as +/// static members of this class. Manual constructing of this class is +/// prohibited. +enum KeyboardLockMode { + /// Represents the number lock mode on the keyboard. + /// + /// On supporting systems, enabling number lock mode usually allows key + /// presses of the number pad to input numbers, instead of acting as up, down, + /// left, right, page up, end, etc. + numLock._(LogicalKeyboardKey.numLock), + + /// Represents the scrolling lock mode on the keyboard. + /// + /// On supporting systems and applications (such as a spreadsheet), enabling + /// scrolling lock mode usually allows key presses of the cursor keys to + /// scroll the document instead of the cursor. + scrollLock._(LogicalKeyboardKey.scrollLock), + + /// Represents the capital letters lock mode on the keyboard. + /// + /// On supporting systems, enabling capital lock mode allows key presses of + /// the letter keys to input uppercase letters instead of lowercase. + capsLock._(LogicalKeyboardKey.capsLock); + + // KeyboardLockMode has a fixed pool of supported keys, enumerated as static + // members of this class, therefore constructing is prohibited. + const KeyboardLockMode._(this.logicalKey); + + /// The logical key that triggers this lock mode. + final LogicalKeyboardKey logicalKey; + + static final Map<int, KeyboardLockMode> _knownLockModes = <int, KeyboardLockMode>{ + numLock.logicalKey.keyId: numLock, + scrollLock.logicalKey.keyId: scrollLock, + capsLock.logicalKey.keyId: capsLock, + }; + + /// Returns the [KeyboardLockMode] constant from the logical key, or + /// null, if not found. + static KeyboardLockMode? findLockByLogicalKey(LogicalKeyboardKey logicalKey) => _knownLockModes[logicalKey.keyId]; +} + +/// Defines the interface for keyboard key events. +/// +/// The [KeyEvent] provides a universal model for key event information from a +/// hardware keyboard across platforms. +/// +/// See also: +/// +/// * [HardwareKeyboard] for full introduction to key event model and handling. +/// * [KeyDownEvent], a subclass for events representing the user pressing a +/// key. +/// * [KeyRepeatEvent], a subclass for events representing the user holding a +/// key, causing repeated events. +/// * [KeyUpEvent], a subclass for events representing the user releasing a +/// key. +@immutable +abstract class KeyEvent with Diagnosticable { + /// Create a const KeyEvent by providing each field. + const KeyEvent({ + required this.physicalKey, + required this.logicalKey, + this.character, + required this.timeStamp, + this.deviceType = ui.KeyEventDeviceType.keyboard, + this.synthesized = false, + }); + + /// Returns an object representing the physical location of this key. + /// + /// A [PhysicalKeyboardKey] represents a USB HID code sent from the keyboard, + /// ignoring the key map, modifier keys (like SHIFT), and the label on the key. + /// + /// [PhysicalKeyboardKey]s are used to describe and test for keys in a + /// particular location. A [PhysicalKeyboardKey] may have a name, but the name + /// is a mnemonic ("keyA" is easier to remember than 0x70004), derived from the + /// key's effect on a QWERTY keyboard. The name does not represent the key's + /// effect whatsoever (a physical "keyA" can be the Q key on an AZERTY + /// keyboard). + /// + /// For instance, if you wanted to make a game where the key to the right of + /// the CAPS LOCK key made the player move left, you would be comparing a + /// physical key with [PhysicalKeyboardKey.keyA], since that is the key next to + /// the CAPS LOCK key on a QWERTY keyboard. This would return the same thing + /// even on an AZERTY keyboard where the key next to the CAPS LOCK produces a + /// "Q" when pressed. + /// + /// If you want to make your app respond to a key with a particular character + /// on it regardless of location of the key, use [KeyEvent.logicalKey] instead. + /// + /// Also, even though physical keys are defined with USB HID codes, their + /// values are not necessarily the same HID codes produced by the hardware and + /// presented to the driver. On most platforms, Flutter has to map the + /// platform representation back to a HID code because the original HID + /// code is not provided. USB HID was chosen because it is a well-defined + /// standard for referring to keys such as those a Flutter app may encounter. + /// + /// See also: + /// + /// * [logicalKey] for the non-location specific key generated by this event. + /// * [character] for the character generated by this keypress (if any). + final PhysicalKeyboardKey physicalKey; + + /// Returns an object representing the logical key that was pressed. + /// + /// {@template flutter.services.KeyEvent.logicalKey} + /// This method takes into account the key map and modifier keys (like SHIFT) + /// to determine which logical key to return. + /// + /// If you are looking for the character produced by a key event, use + /// [KeyEvent.character] instead. + /// + /// If you are collecting text strings, use the [TextField] or + /// [CupertinoTextField] widgets, since those automatically handle many of the + /// complexities of managing keyboard input, like showing a soft keyboard or + /// interacting with an input method editor (IME). + /// {@endtemplate} + final LogicalKeyboardKey logicalKey; + + /// Returns the Unicode character (grapheme cluster) completed by this + /// keystroke, if any. + /// + /// This will only return a character if this keystroke, combined with any + /// preceding keystroke(s), generates a character, and only on a "key down" + /// event. It will return null if no character has been generated by the + /// keystroke (e.g. a "dead" or "combining" key), or if the corresponding key + /// is a key without a visual representation, such as a modifier key or a + /// control key. It will also return null if this is a "key up" event. + /// + /// This can return multiple Unicode code points, since some characters (more + /// accurately referred to as grapheme clusters) are made up of more than one + /// code point. + /// + /// The [character] doesn't take into account edits by an input method editor + /// (IME), or manage the visibility of the soft keyboard on touch devices. For + /// composing text, use the [TextField] or [CupertinoTextField] widgets, since + /// those automatically handle many of the complexities of managing keyboard + /// input. + /// + /// The [character] is not available on [KeyUpEvent]s. + final String? character; + + /// Time of event, relative to an arbitrary start point. + /// + /// All events share the same timeStamp origin. + final Duration timeStamp; + + /// The source device type for the key event. + /// + /// Not all platforms supply an accurate type. + /// + /// Defaults to [ui.KeyEventDeviceType.keyboard]. + final ui.KeyEventDeviceType deviceType; + + /// Whether this event is synthesized by Flutter to synchronize key states. + /// + /// An non-[synthesized] event is converted from a native event, and a native + /// event can only be converted to one non-[synthesized] event. Some properties + /// might be changed during the conversion (for example, a native repeat event + /// might be converted to a Flutter down event when necessary.) + /// + /// A [synthesized] event is created without a source native event in order to + /// synchronize key states. For example, if the native platform shows that a + /// shift key that was previously held has been released somehow without the + /// key up event dispatched (probably due to loss of focus), a synthesized key + /// up event will be added to regularized the event stream. + /// + /// For detailed introduction to the regularized event model, see + /// [HardwareKeyboard]. + /// + /// Defaults to false. + final bool synthesized; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<PhysicalKeyboardKey>('physicalKey', physicalKey)); + properties.add(DiagnosticsProperty<LogicalKeyboardKey>('logicalKey', logicalKey)); + properties.add(StringProperty('character', character)); + properties.add(DiagnosticsProperty<Duration>('timeStamp', timeStamp)); + properties.add(FlagProperty('synthesized', value: synthesized, ifTrue: 'synthesized')); + } +} + +/// An event indicating that the user has pressed a key down on the keyboard. +/// +/// See also: +/// +/// * [KeyRepeatEvent], a key event representing the user +/// holding a key, causing repeated events. +/// * [KeyUpEvent], a key event representing the user +/// releasing a key. +/// * [HardwareKeyboard], which produces this event. +class KeyDownEvent extends KeyEvent { + /// Creates a key event that represents the user pressing a key. + const KeyDownEvent({ + required super.physicalKey, + required super.logicalKey, + super.character, + required super.timeStamp, + super.synthesized, + super.deviceType, + }); +} + +/// An event indicating that the user has released a key on the keyboard. +/// +/// See also: +/// +/// * [KeyDownEvent], a key event representing the user +/// pressing a key. +/// * [KeyRepeatEvent], a key event representing the user +/// holding a key, causing repeated events. +/// * [HardwareKeyboard], which produces this event. +class KeyUpEvent extends KeyEvent { + /// Creates a key event that represents the user pressing a key. + const KeyUpEvent({ + required super.physicalKey, + required super.logicalKey, + required super.timeStamp, + super.synthesized, + super.deviceType, + }); +} + +/// An event indicating that the user has been holding a key on the keyboard +/// and causing repeated events. +/// +/// Repeat events are not guaranteed and are provided only if supported by the +/// underlying platform. +/// +/// See also: +/// +/// * [KeyDownEvent], a key event representing the user +/// pressing a key. +/// * [KeyUpEvent], a key event representing the user +/// releasing a key. +/// * [HardwareKeyboard], which produces this event. +class KeyRepeatEvent extends KeyEvent { + /// Creates a key event that represents the user pressing a key. + const KeyRepeatEvent({ + required super.physicalKey, + required super.logicalKey, + super.character, + required super.timeStamp, + super.deviceType, + }); +} + +/// The signature for [HardwareKeyboard.addHandler], a callback to decide whether +/// the entire framework handles a key event. +typedef KeyEventCallback = bool Function(KeyEvent event); + +/// Manages key events from hardware keyboards. +/// +/// [HardwareKeyboard] manages all key events of the Flutter application from +/// hardware keyboards (in contrast to on-screen keyboards). It receives key +/// data from the native platform, dispatches key events to registered +/// handlers, and records the keyboard state. +/// +/// To stay notified whenever keys are pressed, held, or released, add a +/// handler with [addHandler]. To only be notified when a specific part of the +/// app is focused, use a [Focus] widget's `onFocusChanged` attribute instead +/// of [addHandler]. Handlers should be removed with [removeHandler] when +/// notification is no longer necessary, or when the handler is being disposed. +/// +/// To query whether a key is being held, or a lock mode is enabled, use +/// [physicalKeysPressed], [logicalKeysPressed], or [lockModesEnabled]. +/// These states will have been updated with the event when used during a key +/// event handler. +/// +/// The singleton [HardwareKeyboard] instance is held by the [ServicesBinding] +/// as [ServicesBinding.keyboard], and can be conveniently accessed using the +/// [HardwareKeyboard.instance] static accessor. +/// +/// ## Event model +/// +/// Flutter uses a universal event model ([KeyEvent]) and key options +/// ([LogicalKeyboardKey] and [PhysicalKeyboardKey]) regardless of the native +/// platform, while preserving platform-specific features as much as +/// possible. +/// +/// [HardwareKeyboard] guarantees that the key model is "regularized": The key +/// event stream consists of "key tap sequences", where a key tap sequence is +/// defined as one [KeyDownEvent], zero or more [KeyRepeatEvent]s, and one +/// [KeyUpEvent] in order, all with the same physical key and logical key. +/// +/// Example: +/// +/// * Tap and hold key A, US layout: +/// * KeyDownEvent(physicalKey: keyA, logicalKey: keyA, character: "a") +/// * KeyRepeatEvent(physicalKey: keyA, logicalKey: keyA, character: "a") +/// * KeyUpEvent(physicalKey: keyA, logicalKey: keyA) +/// * Press ShiftLeft, tap key A, then release ShiftLeft, US layout: +/// * KeyDownEvent(physicalKey: shiftLeft, logicalKey: shiftLeft) +/// * KeyDownEvent(physicalKey: keyA, logicalKey: keyA, character: "A") +/// * KeyRepeatEvent(physicalKey: keyA, logicalKey: keyA, character: "A") +/// * KeyUpEvent(physicalKey: keyA, logicalKey: keyA) +/// * KeyUpEvent(physicalKey: shiftLeft, logicalKey: shiftLeft) +/// * Tap key Q, French layout: +/// * KeyDownEvent(physicalKey: keyA, logicalKey: keyQ, character: "q") +/// * KeyUpEvent(physicalKey: keyA, logicalKey: keyQ) +/// * Tap CapsLock: +/// * KeyDownEvent(physicalKey: capsLock, logicalKey: capsLock) +/// * KeyUpEvent(physicalKey: capsLock, logicalKey: capsLock) +/// +/// When the Flutter application starts, all keys are released, and all lock +/// modes are disabled. Upon key events, [HardwareKeyboard] will update its +/// states, then dispatch callbacks: [KeyDownEvent]s and [KeyUpEvent]s set +/// or reset the pressing state, while [KeyDownEvent]s also toggle lock modes. +/// +/// Flutter will try to synchronize with the ground truth of keyboard states +/// using synthesized events ([KeyEvent.synthesized]), subject to the +/// availability of the platform. The desynchronization can be caused by +/// non-empty initial state or a change in the focused window or application. +/// For example, if CapsLock is enabled when the application starts, then +/// immediately before the first key event, a synthesized [KeyDownEvent] and +/// [KeyUpEvent] of CapsLock will be dispatched. +/// +/// The resulting event stream does not map one-to-one to the native key event +/// stream. Some native events might be skipped, while some events might be +/// synthesized and do not correspond to native events. Synthesized events will +/// be indicated by [KeyEvent.synthesized]. +/// +/// Example: +/// +/// * Flutter starts with CapsLock on, the first press of keyA: +/// * KeyDownEvent(physicalKey: capsLock, logicalKey: capsLock, synthesized: true) +/// * KeyUpEvent(physicalKey: capsLock, logicalKey: capsLock, synthesized: true) +/// * KeyDownEvent(physicalKey: keyA, logicalKey: keyA, character: "a") +/// * While holding ShiftLeft, lose window focus, release shiftLeft, then focus +/// back and press keyA: +/// * KeyUpEvent(physicalKey: shiftLeft, logicalKey: shiftLeft, synthesized: true) +/// * KeyDownEvent(physicalKey: keyA, logicalKey: keyA, character: "a") +/// +/// Flutter does not distinguish between multiple keyboards. Flutter will +/// process all events as if they come from a single keyboard, and try to +/// resolve any conflicts and provide a regularized key event stream, which +/// can deviate from the ground truth. +/// +/// See also: +/// +/// * [KeyDownEvent], [KeyRepeatEvent], and [KeyUpEvent], the classes used to +/// describe specific key events. +/// * [instance], the singleton instance of this class. +class HardwareKeyboard { + /// Provides convenient access to the current [HardwareKeyboard] singleton from + /// the [ServicesBinding] instance. + static HardwareKeyboard get instance => ServicesBinding.instance.keyboard; + + final Map<PhysicalKeyboardKey, LogicalKeyboardKey> _pressedKeys = <PhysicalKeyboardKey, LogicalKeyboardKey>{}; + + /// The set of [PhysicalKeyboardKey]s that are pressed. + /// + /// If called from a key event handler, the result will already include the effect + /// of the event. + /// + /// See also: + /// + /// * [logicalKeysPressed], which tells if a logical key is being pressed. + Set<PhysicalKeyboardKey> get physicalKeysPressed => _pressedKeys.keys.toSet(); + + /// The set of [LogicalKeyboardKey]s that are pressed. + /// + /// If called from a key event handler, the result will already include the effect + /// of the event. + /// + /// See also: + /// + /// * [physicalKeysPressed], which tells if a physical key is being pressed. + Set<LogicalKeyboardKey> get logicalKeysPressed => _pressedKeys.values.toSet(); + + /// Returns the logical key that corresponds to the given pressed physical key. + /// + /// Returns null if the physical key is not currently pressed. + LogicalKeyboardKey? lookUpLayout(PhysicalKeyboardKey physicalKey) => _pressedKeys[physicalKey]; + + final Set<KeyboardLockMode> _lockModes = <KeyboardLockMode>{}; + /// The set of [KeyboardLockMode] that are enabled. + /// + /// Lock keys, such as CapsLock, are logical keys that toggle their + /// respective boolean states on key down events. Such flags are usually used + /// as modifier to other keys or events. + /// + /// If called from a key event handler, the result will already include the effect + /// of the event. + Set<KeyboardLockMode> get lockModesEnabled => _lockModes; + + /// Returns true if the given [LogicalKeyboardKey] is pressed, according to + /// the [HardwareKeyboard]. + bool isLogicalKeyPressed(LogicalKeyboardKey key) => _pressedKeys.values.contains(key); + + /// Returns true if the given [PhysicalKeyboardKey] is pressed, according to + /// the [HardwareKeyboard]. + bool isPhysicalKeyPressed(PhysicalKeyboardKey key) => _pressedKeys.containsKey(key); + + /// Returns true if a logical CTRL modifier key is pressed, regardless of + /// which side of the keyboard it is on. + /// + /// Use [isLogicalKeyPressed] if you need to know which control key was + /// pressed. + bool get isControlPressed { + return isLogicalKeyPressed(LogicalKeyboardKey.controlLeft) || isLogicalKeyPressed(LogicalKeyboardKey.controlRight); + } + + /// Returns true if a logical SHIFT modifier key is pressed, regardless of + /// which side of the keyboard it is on. + /// + /// Use [isLogicalKeyPressed] if you need to know which shift key was pressed. + bool get isShiftPressed { + return isLogicalKeyPressed(LogicalKeyboardKey.shiftLeft) || isLogicalKeyPressed(LogicalKeyboardKey.shiftRight); + } + + /// Returns true if a logical ALT modifier key is pressed, regardless of which + /// side of the keyboard it is on. + /// + /// The `AltGr` key that appears on some keyboards is considered to be the + /// same as [LogicalKeyboardKey.altRight] on some platforms (notably Android). + /// On platforms that can distinguish between `altRight` and `altGr`, a press + /// of `AltGr` will not return true here, and will need to be tested for + /// separately. + /// + /// Use [isLogicalKeyPressed] if you need to know which alt key was pressed. + bool get isAltPressed { + return isLogicalKeyPressed(LogicalKeyboardKey.altLeft) || isLogicalKeyPressed(LogicalKeyboardKey.altRight); + } + + /// Returns true if a logical META modifier key is pressed, regardless of + /// which side of the keyboard it is on. + /// + /// Use [isLogicalKeyPressed] if you need to know which meta key was pressed. + bool get isMetaPressed { + return isLogicalKeyPressed(LogicalKeyboardKey.metaLeft) || isLogicalKeyPressed(LogicalKeyboardKey.metaRight); + } + + void _assertEventIsRegular(KeyEvent event) { + assert(() { + const String common = 'If this occurs in real application, please report this ' + 'bug to Flutter. If this occurs in unit tests, please ensure that ' + "simulated events follow Flutter's event model as documented in " + '`HardwareKeyboard`. This was the event: '; + if (event is KeyDownEvent) { + assert(!_pressedKeys.containsKey(event.physicalKey), + 'A ${event.runtimeType} is dispatched, but the state shows that the physical ' + 'key is already pressed. $common$event'); + } else if (event is KeyRepeatEvent || event is KeyUpEvent) { + assert(_pressedKeys.containsKey(event.physicalKey), + 'A ${event.runtimeType} is dispatched, but the state shows that the physical ' + 'key is not pressed. $common$event'); + assert(_pressedKeys[event.physicalKey] == event.logicalKey, + 'A ${event.runtimeType} is dispatched, but the state shows that the physical ' + 'key is pressed on a different logical key. $common$event ' + 'and the recorded logical key ${_pressedKeys[event.physicalKey]}'); + } else { + assert(false, 'Unexpected key event class ${event.runtimeType}'); + } + return true; + }()); + } + + List<KeyEventCallback> _handlers = <KeyEventCallback>[]; + bool _duringDispatch = false; + List<KeyEventCallback>? _modifiedHandlers; + + /// Register a listener that is called every time a hardware key event + /// occurs. + /// + /// All registered handlers will be invoked in order regardless of + /// their return value. The return value indicates whether Flutter + /// "handles" the event. If any handler returns true, the event + /// will not be propagated to other native components in the add-to-app + /// scenario. + /// + /// If an object added a handler, it must remove the handler before it is + /// disposed. + /// + /// If used during event dispatching, the addition will not take effect + /// until after the dispatching. + /// + /// See also: + /// + /// * [removeHandler], which removes the handler. + void addHandler(KeyEventCallback handler) { + if (_duringDispatch) { + _modifiedHandlers ??= <KeyEventCallback>[..._handlers]; + _modifiedHandlers!.add(handler); + } else { + _handlers.add(handler); + } + } + + /// Stop calling the given listener every time a hardware key event + /// occurs. + /// + /// The `handler` argument must be [identical] to the one used in + /// [addHandler]. If multiple exist, the first one will be removed. + /// If none is found, then this method is a no-op. + /// + /// If used during event dispatching, the removal will not take effect + /// until after the event has been dispatched. + void removeHandler(KeyEventCallback handler) { + if (_duringDispatch) { + _modifiedHandlers ??= <KeyEventCallback>[..._handlers]; + _modifiedHandlers!.remove(handler); + } else { + _handlers.remove(handler); + } + } + + /// Query the engine and update _pressedKeys accordingly to the engine answer. + // + /// Both the framework and the engine maintain a state of the current pressed + /// keys. There are edge cases, related to startup and restart, where the framework + /// needs to resynchronize its keyboard state. + Future<void> syncKeyboardState() async { + final Map<int, int>? keyboardState = await SystemChannels.keyboard.invokeMapMethod<int, int>( + 'getKeyboardState', + ); + if (keyboardState != null) { + for (final int key in keyboardState.keys) { + final PhysicalKeyboardKey physicalKey = PhysicalKeyboardKey(key); + final LogicalKeyboardKey logicalKey = LogicalKeyboardKey(keyboardState[key]!); + _pressedKeys[physicalKey] = logicalKey; + } + } + } + + bool _dispatchKeyEvent(KeyEvent event) { + // This dispatching could have used the same algorithm as [ChangeNotifier], + // but since 1) it shouldn't be necessary to support reentrantly + // dispatching, 2) there shouldn't be many handlers (most apps should use + // only 1, this function just uses a simpler algorithm. + assert(!_duringDispatch, 'Nested keyboard dispatching is not supported'); + _duringDispatch = true; + bool handled = false; + for (final KeyEventCallback handler in _handlers) { + try { + final bool thisResult = handler(event); + handled = handled || thisResult; + } catch (exception, stack) { + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<KeyEvent>('Event', event), + ]; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'services library', + context: ErrorDescription('while processing a key handler'), + informationCollector: collector, + )); + } + } + _duringDispatch = false; + if (_modifiedHandlers != null) { + _handlers = _modifiedHandlers!; + _modifiedHandlers = null; + } + return handled; + } + + List<String> _debugPressedKeysDetails() { + if (_pressedKeys.isEmpty) { + return <String>['Empty']; + } + final List<String> details = <String>[]; + for (final PhysicalKeyboardKey physicalKey in _pressedKeys.keys) { + details.add('$physicalKey: ${_pressedKeys[physicalKey]}'); + } + return details; + } + + /// Process a new [KeyEvent] by recording the state changes and dispatching + /// to handlers. + bool handleKeyEvent(KeyEvent event) { + assert(_keyboardDebug(() => 'Key event received: $event')); + assert(_keyboardDebug(() => 'Pressed state before processing the event:', _debugPressedKeysDetails)); + _assertEventIsRegular(event); + final PhysicalKeyboardKey physicalKey = event.physicalKey; + final LogicalKeyboardKey logicalKey = event.logicalKey; + if (event is KeyDownEvent) { + _pressedKeys[physicalKey] = logicalKey; + final KeyboardLockMode? lockMode = KeyboardLockMode.findLockByLogicalKey(event.logicalKey); + if (lockMode != null) { + if (_lockModes.contains(lockMode)) { + _lockModes.remove(lockMode); + } else { + _lockModes.add(lockMode); + } + } + } else if (event is KeyUpEvent) { + _pressedKeys.remove(physicalKey); + } else if (event is KeyRepeatEvent) { + // Empty + } + + assert(_keyboardDebug(() => 'Pressed state after processing the event:', _debugPressedKeysDetails)); + return _dispatchKeyEvent(event); + } + + /// Clear all keyboard states and additional handlers. + /// + /// All handlers are removed except for the first one, which is added by + /// [ServicesBinding]. + /// + /// This is used by the testing framework to make sure that tests are hermetic. + @visibleForTesting + void clearState() { + _pressedKeys.clear(); + _lockModes.clear(); + _handlers.clear(); + assert(_modifiedHandlers == null); + } +} + +/// The mode in which information of key messages is delivered. +/// +/// This enum is deprecated and will be removed. There is no direct substitute +/// planned, since this enum will no longer be necessary once [RawKeyEvent] and +/// associated APIs are removed. +/// +/// Different platforms use different methods, classes, and models to inform the +/// framework of native key events, which is called "transit mode". +/// +/// The framework must determine which transit mode the current platform +/// implements and behave accordingly (such as transforming and synthesizing +/// events if necessary). Unit tests related to keyboard might also want to +/// simulate platform of each transit mode. +/// +/// The transit mode of the current platform is inferred by [KeyEventManager] at +/// the start of the application. +/// +/// See also: +/// +/// * [KeyEventManager], which infers the transit mode of the current platform +/// and guides how key messages are dispatched. +/// * [debugKeyEventSimulatorTransitModeOverride], overrides the transit mode +/// used to simulate key events. +/// * [KeySimulatorTransitModeVariant], an easier way to set +/// [debugKeyEventSimulatorTransitModeOverride] in widget tests. +@Deprecated( + 'No longer supported. Transit mode is always key data only. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +enum KeyDataTransitMode { + /// Key event information is delivered as raw key data. + /// + /// Raw key data is platform's native key event information sent in JSON + /// through a method channel, which is then interpreted as a platform subclass + /// of [RawKeyEventData]. + /// + /// If the current transit mode is [rawKeyData], the raw key data is converted + /// to both [KeyMessage.events] and [KeyMessage.rawEvent]. + @Deprecated( + 'No longer supported. Transit mode is always key data only. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + rawKeyData, + + /// Key event information is delivered as converted key data, followed by raw + /// key data. + /// + /// Key data ([ui.KeyData]) is a standardized event stream converted from + /// platform's native key event information, sent through the embedder API. + /// Its event model is described in [HardwareKeyboard]. + /// + /// Raw key data is platform's native key event information sent in JSON + /// through a method channel. It is interpreted by subclasses of + /// [RawKeyEventData]. + /// + /// If the current transit mode is [keyDataThenRawKeyData], then the + /// [KeyEventManager] will use the [ui.KeyData] for [KeyMessage.events], and + /// the raw data for [KeyMessage.rawEvent]. + @Deprecated( + 'No longer supported. Transit mode is always key data only. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + keyDataThenRawKeyData, +} + +/// The assembled information converted from a native key message. +/// +/// This class is deprecated, and will be removed. There is no direct substitute +/// planned, since this class will no longer be necessary once [RawKeyEvent] and +/// associated APIs are removed. +/// +/// Native key messages, produced by physically pressing or releasing keyboard +/// keys, are translated into two different event streams in Flutter: +/// +/// * The [KeyEvent] stream, represented by [KeyMessage.events] (recommended). +/// * The [RawKeyEvent] stream, represented by [KeyMessage.rawEvent] (legacy, to +/// be deprecated). +/// +/// Either the [KeyEvent] stream or the [RawKeyEvent] stream alone provides a +/// complete description of the keyboard messages, but in different event +/// models. Flutter is still transitioning from the legacy model to the new +/// model, therefore it dispatches both streams simultaneously until the +/// transition is completed. [KeyMessage] is used to bundle the stream segments +/// of both models from a native key message together for the convenience of +/// propagation. +/// +/// Typically, an application either processes [KeyMessage.events] or +/// [KeyMessage.rawEvent], not both. For example, handling a [KeyMessage], means +/// handling each event in [KeyMessage.events]. +/// +/// In advanced cases, a widget needs to process both streams at the same time. +/// For example, [FocusNode] has an `onKey` that dispatches [RawKeyEvent]s and +/// an `onKeyEvent` that dispatches [KeyEvent]s. To processes a [KeyMessage], it +/// first calls `onKeyEvent` with each [KeyEvent] of [events], and then `onKey` +/// with [rawEvent]. All callbacks are invoked regardless of their +/// [KeyEventResult]. Their results are combined into the result of the node +/// using [combineKeyEventResults]. +/// +/// ```dart +/// // ignore: deprecated_member_use +/// void handleMessage(FocusNode node, KeyMessage message) { +/// final List<KeyEventResult> results = <KeyEventResult>[]; +/// if (node.onKeyEvent != null) { +/// for (final KeyEvent event in message.events) { +/// results.add(node.onKeyEvent!(node, event)); +/// } +/// } +/// // ignore: deprecated_member_use +/// if (node.onKey != null && message.rawEvent != null) { +/// // ignore: deprecated_member_use +/// results.add(node.onKey!(node, message.rawEvent!)); +/// } +/// final KeyEventResult result = combineKeyEventResults(results); +/// // Progress based on `result`... +/// } +/// ``` +@Deprecated( + 'No longer supported. Once RawKeyEvent is removed, it will no longer be needed. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +@immutable +class KeyMessage { + /// Create a [KeyMessage] by providing all information. + /// + /// The [events] might be empty. + @Deprecated( + 'No longer supported. Once RawKeyEvent is removed, will no longer be needed. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const KeyMessage(this.events, this.rawEvent); + + /// The list of [KeyEvent]s converted from the native key message. + /// + /// A native key message is converted into multiple [KeyEvent]s in a regular + /// event model. The [events] might contain zero or any number of + /// [KeyEvent]s. + /// + /// See also: + /// + /// * [HardwareKeyboard], which describes the regular event model. + /// * [HardwareKeyboard.addHandler], [KeyboardListener], [Focus.onKeyEvent], + /// where [KeyEvent]s are commonly used. + final List<KeyEvent> events; + + /// The native key message in the form of a raw key event. + /// + /// A native key message is sent to the framework in JSON and represented + /// in a platform-specific form as [RawKeyEventData] and a platform-neutral + /// form as [RawKeyEvent]. Their stream is not as regular as [KeyEvent]'s, + /// but keeps as much native information and structure as possible. + /// + /// The [rawEvent] field might be empty, for example, when the event + /// converting system dispatches solitary synthesized events. + /// + /// The [rawEvent] field will be deprecated in the future. + /// + /// See also: + /// + /// * [RawKeyboard.addListener], [RawKeyboardListener], [Focus.onKey], + /// where [RawKeyEvent]s are commonly used. + final RawKeyEvent? rawEvent; + + @override + String toString() { + return 'KeyMessage($events)'; + } +} + +/// The signature for [KeyEventManager.keyMessageHandler]. +/// +/// A [KeyMessageHandler] processes a [KeyMessage] and returns whether the +/// message is considered handled. Handled messages should not be propagated to +/// other native components. +/// +/// This message handler signature is deprecated, and will be removed. There is +/// no direct substitute planned, since this handler type will no longer be +/// necessary once [RawKeyEvent] and associated APIs are removed. +@Deprecated( + 'No longer supported. Once KeyMessage is removed, will no longer be needed. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +typedef KeyMessageHandler = bool Function(KeyMessage message); + +/// A singleton class that processes key messages from the platform and +/// dispatches converted messages accordingly. +/// +/// This class is deprecated, and will be removed. There is no direct substitute +/// planned, since this class will no longer be necessary once [RawKeyEvent] and +/// associated APIs are removed. +/// +/// [KeyEventManager] receives platform key messages by [handleKeyData] and +/// [handleRawKeyMessage], sends converted events to [HardwareKeyboard] and +/// [RawKeyboard] for recording keeping, and then dispatches the [KeyMessage] to +/// [keyMessageHandler], the global message handler. +/// +/// [KeyEventManager] is typically created, owned, and invoked by +/// [ServicesBinding]. +/// +/// ## On embedder implementation +/// +/// Currently, Flutter has two sets of key event API pathways running in +/// parallel. +/// +/// * The "hardware key event" pathway receives messages from the +/// "flutter/keydata" message channel (embedder API +/// `FlutterEngineSendKeyEvent`) and dispatches [KeyEvent] to +/// [HardwareKeyboard] and some methods such as [Focus.onKeyEvent]. +/// * The deprecated "raw key event" pathway receives messages from the +/// "flutter/keyevent" message channel ([SystemChannels.keyEvent]) and +/// dispatches [RawKeyEvent] to [RawKeyboard] and [Focus.onKey] as well as +/// similar methods. This pathway will be removed at a future date. +/// +/// [KeyEventManager] resolves cross-platform compatibility of keyboard +/// implementations, since legacy platforms might have not implemented the new +/// key data API and only send raw key data on each key message. +/// [KeyEventManager] recognizes the platform support by detecting whether a +/// message comes from platform channel "flutter/keyevent" before one from +/// "flutter/keydata", or vice versa, at the beginning of the app. +/// +/// * If a "flutter/keydata" message is received first, then this platform is +/// considered a modern platform. The hardware key events are stored, and +/// dispatched only when a raw key message is received. +/// * If a "flutter/keyevent" message is received first, then this platform is +/// considered a legacy platform. The raw key event is transformed into a +/// hardware key event at best effort. No messages from "flutter/keydata" are +/// expected. This behavior has been deprecated, and will be removed at a +/// future date. +/// +/// Therefore, to correctly implement a platform that supports +/// `FlutterEngineSendKeyEvent`, the platform must ensure that +/// `FlutterEngineSendKeyEvent` is called before sending a message to +/// "flutter/keyevent" at the beginning of the app, and every physical key event +/// is ended with a "flutter/keyevent" message. +@Deprecated( + 'No longer supported. Once RawKeyEvent is removed, will no longer be needed. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class KeyEventManager { + /// Create an instance. + /// + /// This is typically only called by [ServicesBinding]. + @Deprecated( + 'No longer supported. Once RawKeyEvent is removed, will no longer be needed. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + KeyEventManager(this._hardwareKeyboard, this._rawKeyboard); + + /// The global entrance which handles all key events sent to Flutter. + /// + /// This handler is deprecated and will be removed. Use + /// [HardwareKeyboard.addHandler]/[HardwareKeyboard.removeHandler] instead. + /// + /// Typical applications use [WidgetsBinding], where this field is set by the + /// focus system (see `FocusManager`) on startup to a function that dispatches + /// incoming events to the focus system, including `FocusNode.onKey`, + /// `FocusNode.onKeyEvent`, and `Shortcuts`. In this case, the application + /// does not need to read, assign, or invoke this value. + /// + /// For advanced uses, the application can "patch" this callback. See below + /// for details. + /// + /// ## Handlers and event results + /// + /// Roughly speaking, Flutter processes each native key event with the + /// following phases: + /// + /// 1. Platform-side pre-filtering, sometimes used for IME. + /// 2. The key event system. + /// 3. The text input system. + /// 4. Other native components (possibly non-Flutter). + /// + /// Each phase will conclude with a boolean called an "event result". If the + /// result is true, this phase _handles_ the event and prevents the event from + /// being propagated to the next phase. This mechanism allows shortcuts such + /// as "Ctrl-C" to not generate a text "C" in the text field, or shortcuts + /// that are not handled by any components to trigger special alerts (such as + /// the "bonk" noise on macOS). + /// + /// In the second phase, known as "the key event system", the event is + /// dispatched to several destinations: [RawKeyboard]'s listeners, + /// [HardwareKeyboard]'s handlers, and [keyMessageHandler]. All destinations + /// will always receive the event regardless of the handlers' results. If any + /// handler's result is true, then the overall result of the second phase is + /// true, and event propagation is stopped. + /// + /// See also: + /// + /// * [RawKeyboard.addListener], which adds a raw keyboard listener. + /// * [RawKeyboardListener], which is also implemented by adding a raw + /// keyboard listener. + /// * [HardwareKeyboard.addHandler], which adds a hardware keyboard handler. + /// + /// ## Advanced usages: Manual assignment or patching + /// + /// If you are not using the focus system to manage focus, set this attribute + /// to a [KeyMessageHandler] that returns true if the propagation on the + /// platform should not be continued. If this field is null, key events will + /// be assumed to not have been handled by Flutter, a result of "false". + /// + /// Even if you are using the focus system, you might also want to do more + /// than the focus system allows. In these cases, you can _patch_ + /// [keyMessageHandler] by setting it to a callback that performs your tasks + /// and calls the original callback in between (or not at all.) + /// + /// Patching [keyMessageHandler] can not be reverted. You should always assume + /// that another component might have patched it before you and after you. + /// This means that you might want to write your own global notification + /// manager, to which callbacks can be added and removed. + /// + /// You should not patch [keyMessageHandler] until the `FocusManager` has + /// assigned its callback. This is assured during any time within the widget + /// lifecycle (such as `initState`), or after calling + /// `WidgetManager.instance`. + /// + /// {@tool dartpad} + /// This example shows how to process key events that are not + /// handled by any focus handler (such as `Shortcuts`) by patching + /// [keyMessageHandler]. + /// + /// The app prints out any key events that are not handled by the app body. + /// Try typing something in the first text field. These key presses are not + /// handled by `Shortcuts` and will be sent to the fallback handler and + /// printed out. Now try some text shortcuts, such as Ctrl+A. The KeyA press + /// is handled as a shortcut, and is not sent to the fallback handler and so + /// is not printed out. + /// + /// The key widget is `FallbackKeyEventRegistrar`, a necessity class to allow + /// reversible patching. `FallbackFocus` and `FallbackFocusNode` are also + /// useful to recognize the widget tree's structure. `FallbackDemo` is an + /// example of using them in an app. + /// + /// ** See code in examples/api/lib/widgets/hardware_keyboard/key_event_manager.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [HardwareKeyboard.addHandler], which accepts multiple global handlers to + /// process [KeyEvent]s + @Deprecated( + 'No longer supported. Once RawKeyEvent is removed, will no longer be needed. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + KeyMessageHandler? keyMessageHandler; + + final HardwareKeyboard _hardwareKeyboard; + final RawKeyboard _rawKeyboard; + + // The [KeyDataTransitMode] of the current platform. + // + // The `_transitMode` is guaranteed to be non-null during key event callbacks. + // + // The `_transitMode` is null before the first event, after which it is inferred + // and will not change throughout the lifecycle of the application. + // + // The `_transitMode` can be reset to null in tests using [clearState]. + KeyDataTransitMode? _transitMode; + + // The accumulated [KeyEvent]s since the last time the message is dispatched. + // + // If _transitMode is [KeyDataTransitMode.keyDataThenRawKeyData], then [KeyEvent]s + // are directly received from [handleKeyData]. If _transitMode is + // [KeyDataTransitMode.rawKeyData], then [KeyEvent]s are converted from the raw + // key data of [handleRawKeyMessage]. Either way, the accumulated key + // events are only dispatched along with the next [KeyMessage] when a + // dispatchable [RawKeyEvent] is available. + final List<KeyEvent> _keyEventsSinceLastMessage = <KeyEvent>[]; + + // When a RawKeyDownEvent is skipped ([RawKeyEventData.shouldDispatchEvent] + // is false), its physical key will be recorded here, so that its up event + // can also be properly skipped. + final Set<PhysicalKeyboardKey> _skippedRawKeysPressed = <PhysicalKeyboardKey>{}; + + /// Dispatch a key data to global and leaf listeners. + /// + /// This method is the handler to the global `onKeyData` API. + /// + /// This handler is deprecated, and will be removed. Use + /// [HardwareKeyboard.addHandler] instead. + @Deprecated( + 'No longer supported. Use HardwareKeyboard.instance.addHandler instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool handleKeyData(ui.KeyData data) { + _transitMode ??= KeyDataTransitMode.keyDataThenRawKeyData; + switch (_transitMode!) { + case KeyDataTransitMode.rawKeyData: + assert(false, 'Should never encounter KeyData when transitMode is rawKeyData.'); + return false; + case KeyDataTransitMode.keyDataThenRawKeyData: + // Having 0 as the physical and logical ID indicates an empty key data + // (the only occasion either field can be 0,) transmitted to ensure + // that the transit mode is correctly inferred. These events should be + // ignored. + if (data.physical == 0 && data.logical == 0) { + return false; + } + assert(data.physical != 0 && data.logical != 0); + final KeyEvent event = _eventFromData(data); + if (data.synthesized && _keyEventsSinceLastMessage.isEmpty) { + // Dispatch the event instantly if both conditions are met: + // + // - The event is synthesized, therefore the result does not matter. + // - The current queue is empty, therefore the order does not matter. + // + // This allows solitary synthesized `KeyEvent`s to be dispatched, + // since they won't be followed by `RawKeyEvent`s. + _hardwareKeyboard.handleKeyEvent(event); + _dispatchKeyMessage(<KeyEvent>[event], null); + } else { + // Otherwise, postpone key event dispatching until the next raw + // event. Normal key presses always send 0 or more `KeyEvent`s first, + // then 1 `RawKeyEvent`. + _keyEventsSinceLastMessage.add(event); + } + return false; + } + } + + bool _dispatchKeyMessage(List<KeyEvent> keyEvents, RawKeyEvent? rawEvent) { + if (keyMessageHandler != null) { + final KeyMessage message = KeyMessage(keyEvents, rawEvent); + try { + return keyMessageHandler!(message); + } catch (exception, stack) { + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<KeyMessage>('KeyMessage', message), + ]; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'services library', + context: ErrorDescription('while processing the key message handler'), + informationCollector: collector, + )); + } + } + return false; + } + + /// Handles a raw key message. + /// + /// This method is the handler to [SystemChannels.keyEvent], processing the + /// JSON form of the native key message and returns the responds for the + /// channel. + /// + /// This handler is deprecated, and will be removed. Use + /// [HardwareKeyboard.addHandler] instead. + @Deprecated( + 'No longer supported. Use HardwareKeyboard.instance.addHandler instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + Future<Map<String, dynamic>> handleRawKeyMessage(dynamic message) async { + if (_transitMode == null) { + _transitMode = KeyDataTransitMode.rawKeyData; + // Convert raw events using a listener so that conversion only occurs if + // the raw event should be dispatched. + _rawKeyboard.addListener(_convertRawEventAndStore); + } + final RawKeyEvent rawEvent = RawKeyEvent.fromMessage(message as Map<String, dynamic>); + + bool shouldDispatch = true; + if (rawEvent is RawKeyDownEvent) { + if (!rawEvent.data.shouldDispatchEvent()) { + shouldDispatch = false; + _skippedRawKeysPressed.add(rawEvent.physicalKey); + } else { + _skippedRawKeysPressed.remove(rawEvent.physicalKey); + } + } else if (rawEvent is RawKeyUpEvent) { + if (_skippedRawKeysPressed.contains(rawEvent.physicalKey)) { + _skippedRawKeysPressed.remove(rawEvent.physicalKey); + shouldDispatch = false; + } + } + + bool handled = true; + if (shouldDispatch) { + // The following `handleRawKeyEvent` will call `_convertRawEventAndStore` + // unless the event is not dispatched. + handled = _rawKeyboard.handleRawKeyEvent(rawEvent); + + for (final KeyEvent event in _keyEventsSinceLastMessage) { + handled = _hardwareKeyboard.handleKeyEvent(event) || handled; + } + if (_transitMode == KeyDataTransitMode.rawKeyData) { + assert(setEquals(_rawKeyboard.physicalKeysPressed, _hardwareKeyboard.physicalKeysPressed), + 'RawKeyboard reported ${_rawKeyboard.physicalKeysPressed}, ' + 'while HardwareKeyboard reported ${_hardwareKeyboard.physicalKeysPressed}'); + } + + handled = _dispatchKeyMessage(_keyEventsSinceLastMessage, rawEvent) || handled; + _keyEventsSinceLastMessage.clear(); + } + + return <String, dynamic>{ 'handled': handled }; + } + + ui.KeyEventDeviceType _convertDeviceType(RawKeyEvent rawEvent) { + final RawKeyEventData data = rawEvent.data; + // Device type is only available from Android. + if (data is! RawKeyEventDataAndroid) { + return ui.KeyEventDeviceType.keyboard; + } + + switch (data.eventSource) { + // https://developer.android.com/reference/android/view/InputDevice#SOURCE_KEYBOARD + case 0x00000101: + return ui.KeyEventDeviceType.keyboard; + // https://developer.android.com/reference/android/view/InputDevice#SOURCE_DPAD + case 0x00000201: + return ui.KeyEventDeviceType.directionalPad; + // https://developer.android.com/reference/android/view/InputDevice#SOURCE_GAMEPAD + case 0x00000401: + return ui.KeyEventDeviceType.gamepad; + // https://developer.android.com/reference/android/view/InputDevice#SOURCE_JOYSTICK + case 0x01000010: + return ui.KeyEventDeviceType.joystick; + // https://developer.android.com/reference/android/view/InputDevice#SOURCE_HDMI + case 0x02000001: + return ui.KeyEventDeviceType.hdmi; + } + return ui.KeyEventDeviceType.keyboard; + } + + // Convert the raw event to key events, including synthesizing events for + // modifiers, and store the key events in `_keyEventsSinceLastMessage`. + // + // This is only called when `_transitMode` is `rawKeyEvent` and if the raw + // event should be dispatched. + void _convertRawEventAndStore(RawKeyEvent rawEvent) { + final PhysicalKeyboardKey physicalKey = rawEvent.physicalKey; + final LogicalKeyboardKey logicalKey = rawEvent.logicalKey; + final Set<PhysicalKeyboardKey> physicalKeysPressed = _hardwareKeyboard.physicalKeysPressed; + final List<KeyEvent> eventAfterwards = <KeyEvent>[]; + final KeyEvent? mainEvent; + final LogicalKeyboardKey? recordedLogicalMain = _hardwareKeyboard.lookUpLayout(physicalKey); + final Duration timeStamp = ServicesBinding.instance.currentSystemFrameTimeStamp; + final String? character = rawEvent.character == '' ? null : rawEvent.character; + final ui.KeyEventDeviceType deviceType = _convertDeviceType(rawEvent); + if (rawEvent is RawKeyDownEvent) { + if (recordedLogicalMain == null) { + mainEvent = KeyDownEvent( + physicalKey: physicalKey, + logicalKey: logicalKey, + character: character, + timeStamp: timeStamp, + deviceType: deviceType, + ); + physicalKeysPressed.add(physicalKey); + } else { + assert(physicalKeysPressed.contains(physicalKey)); + mainEvent = KeyRepeatEvent( + physicalKey: physicalKey, + logicalKey: recordedLogicalMain, + character: character, + timeStamp: timeStamp, + deviceType: deviceType, + ); + } + } else { + assert(rawEvent is RawKeyUpEvent, 'Unexpected subclass of RawKeyEvent: ${rawEvent.runtimeType}'); + if (recordedLogicalMain == null) { + mainEvent = null; + } else { + mainEvent = KeyUpEvent( + logicalKey: recordedLogicalMain, + physicalKey: physicalKey, + timeStamp: timeStamp, + deviceType: deviceType, + ); + physicalKeysPressed.remove(physicalKey); + } + } + for (final PhysicalKeyboardKey key in physicalKeysPressed.difference(_rawKeyboard.physicalKeysPressed)) { + if (key == physicalKey) { + // Somehow, a down event is dispatched but the key is absent from + // keysPressed. Synthesize a up event for the key, but this event must + // be added after the main key down event. + eventAfterwards.add(KeyUpEvent( + physicalKey: key, + logicalKey: logicalKey, + timeStamp: timeStamp, + synthesized: true, + deviceType: deviceType, + )); + } else { + _keyEventsSinceLastMessage.add(KeyUpEvent( + physicalKey: key, + logicalKey: _hardwareKeyboard.lookUpLayout(key)!, + timeStamp: timeStamp, + synthesized: true, + deviceType: deviceType, + )); + } + } + for (final PhysicalKeyboardKey key in _rawKeyboard.physicalKeysPressed.difference(physicalKeysPressed)) { + _keyEventsSinceLastMessage.add(KeyDownEvent( + physicalKey: key, + logicalKey: _rawKeyboard.lookUpLayout(key)!, + timeStamp: timeStamp, + synthesized: true, + deviceType: deviceType, + )); + } + if (mainEvent != null) { + _keyEventsSinceLastMessage.add(mainEvent); + } + _keyEventsSinceLastMessage.addAll(eventAfterwards); + } + + /// Reset the inferred platform transit mode and related states. + /// + /// This method is only used in unit tests. In release mode, this is a no-op. + @visibleForTesting + void clearState() { + assert(() { + _transitMode = null; + _rawKeyboard.removeListener(_convertRawEventAndStore); + _keyEventsSinceLastMessage.clear(); + return true; + }()); + } + + static KeyEvent _eventFromData(ui.KeyData keyData) { + final PhysicalKeyboardKey physicalKey = + PhysicalKeyboardKey.findKeyByCode(keyData.physical) ?? + PhysicalKeyboardKey(keyData.physical); + final LogicalKeyboardKey logicalKey = + LogicalKeyboardKey.findKeyByKeyId(keyData.logical) ?? + LogicalKeyboardKey(keyData.logical); + final Duration timeStamp = keyData.timeStamp; + switch (keyData.type) { + case ui.KeyEventType.down: + return KeyDownEvent( + physicalKey: physicalKey, + logicalKey: logicalKey, + timeStamp: timeStamp, + character: keyData.character, + synthesized: keyData.synthesized, + deviceType: keyData.deviceType, + ); + case ui.KeyEventType.up: + assert(keyData.character == null); + return KeyUpEvent( + physicalKey: physicalKey, + logicalKey: logicalKey, + timeStamp: timeStamp, + synthesized: keyData.synthesized, + deviceType: keyData.deviceType, + ); + case ui.KeyEventType.repeat: + return KeyRepeatEvent( + physicalKey: physicalKey, + logicalKey: logicalKey, + timeStamp: timeStamp, + character: keyData.character, + deviceType: keyData.deviceType, + ); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/keyboard_inserted_content.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/keyboard_inserted_content.dart new file mode 100644 index 0000000000000000000000000000000000000000..47553ac30fba7d1b4eafe72765f20bf4019de195 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/keyboard_inserted_content.dart @@ -0,0 +1,58 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +/// A class representing rich content (such as a PNG image) inserted via the +/// system input method. +/// +/// The following data is represented in this class: +/// - MIME Type +/// - Bytes +/// - URI +@immutable +class KeyboardInsertedContent { + /// Creates an object to represent content that is inserted from the virtual + /// keyboard. + /// + /// The mime type and URI will always be provided, but the bytedata may be null. + const KeyboardInsertedContent({required this.mimeType, required this.uri, this.data}); + + /// Converts JSON received from the Flutter Engine into the Dart class. + KeyboardInsertedContent.fromJson(Map<String, dynamic> metadata): + mimeType = metadata['mimeType'] as String, + uri = metadata['uri'] as String, + data = metadata['data'] != null + ? Uint8List.fromList(List<int>.from(metadata['data'] as Iterable<dynamic>)) + : null; + + /// The mime type of the inserted content. + final String mimeType; + + /// The URI (location) of the inserted content, usually a "content://" URI. + final String uri; + + /// The bytedata of the inserted content. + final Uint8List? data; + + /// Convenience getter to check if bytedata is available for the inserted content. + bool get hasData => data?.isNotEmpty ?? false; + + @override + String toString() => '${objectRuntimeType(this, 'KeyboardInsertedContent')}($mimeType, $uri, $data)'; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is KeyboardInsertedContent + && other.mimeType == mimeType + && other.uri == uri + && other.data == data; + } + + @override + int get hashCode => Object.hash(mimeType, uri, data); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/keyboard_key.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/keyboard_key.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..4feaa7b0ad42181f0ba8a2f916daee633d46efb5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/keyboard_key.g.dart @@ -0,0 +1,5597 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; + +// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT +// This file is generated by dev/tools/gen_keycodes/bin/gen_keycodes.dart and +// should not be edited directly. +// +// Edit the template dev/tools/gen_keycodes/data/keyboard_key.tmpl instead. +// See dev/tools/gen_keycodes/README.md for more information. + +/// A base class for all keyboard key types. +/// +/// See also: +/// +/// * [PhysicalKeyboardKey], a class with static values that describe the keys +/// that are returned from [RawKeyEvent.physicalKey]. +/// * [LogicalKeyboardKey], a class with static values that describe the keys +/// that are returned from [RawKeyEvent.logicalKey]. +abstract class KeyboardKey with Diagnosticable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const KeyboardKey(); +} + +/// A class with static values that describe the keys that are returned from +/// [RawKeyEvent.logicalKey]. +/// +/// These represent *logical* keys, which are keys which are interpreted in the +/// context of any modifiers, modes, or keyboard layouts which may be in effect. +/// +/// This is contrast to [PhysicalKeyboardKey], which represents a physical key +/// in a particular location on the keyboard, without regard for the modifier +/// state, mode, or keyboard layout. +/// +/// As an example, if you wanted to implement an app where the "Q" key "quit" +/// something, you'd want to look at the logical key to detect this, since you +/// would like to have it match the key with "Q" on it, instead of always +/// looking for "the key next to the TAB key", since on a French keyboard, +/// the key next to the TAB key has an "A" on it. +/// +/// Conversely, if you wanted a game where the key next to the CAPS LOCK (the +/// "A" key on a QWERTY keyboard) moved the player to the left, you'd want to +/// look at the physical key to make sure that regardless of the character the +/// key produces, you got the key that is in that location on the keyboard. +/// +/// {@tool dartpad} +/// This example shows how to detect if the user has selected the logical "Q" +/// key and handle the key if they have. +/// +/// ** See code in examples/api/lib/services/keyboard_key/logical_keyboard_key.0.dart ** +/// {@end-tool} +/// See also: +/// +/// * [RawKeyEvent], the keyboard event object received by widgets that listen +/// to keyboard events. +/// * [Focus.onKey], the handler on a widget that lets you handle key events. +/// * [RawKeyboardListener], a widget used to listen to keyboard events (but +/// not handle them). +@immutable +class LogicalKeyboardKey extends KeyboardKey { + /// Creates a new LogicalKeyboardKey object for a key ID. + const LogicalKeyboardKey(this.keyId); + + /// A unique code representing this key. + /// + /// This is an opaque code. It should not be unpacked to derive information + /// from it, as the representation of the code could change at any time. + final int keyId; + + // Returns the bits that are not included in [valueMask], shifted to the + // right. + // + // For example, if the input is 0x12abcdabcd, then the result is 0x12. + // + // This is mostly equivalent to a right shift, resolving the problem that + // JavaScript only support 32-bit bitwise operation and needs to use division + // instead. + static int _nonValueBits(int n) { + // `n >> valueMaskWidth` is equivalent to `n / divisorForValueMask`. + const int divisorForValueMask = valueMask + 1; + const int valueMaskWidth = 32; + + // Equivalent to assert(divisorForValueMask == (1 << valueMaskWidth)). + const int firstDivisorWidth = 28; + assert(divisorForValueMask == + (1 << firstDivisorWidth) * (1 << (valueMaskWidth - firstDivisorWidth))); + + // JS only supports up to 2^53 - 1, therefore non-value bits can only + // contain (maxSafeIntegerWidth - valueMaskWidth) bits. + const int maxSafeIntegerWidth = 52; + const int nonValueMask = (1 << (maxSafeIntegerWidth - valueMaskWidth)) - 1; + + if (kIsWeb) { + return (n / divisorForValueMask).floor() & nonValueMask; + } else { + return (n >> valueMaskWidth) & nonValueMask; + } + } + + static String? _unicodeKeyLabel(int keyId) { + if (_nonValueBits(keyId) == 0) { + return String.fromCharCode(keyId).toUpperCase(); + } + return null; + } + + /// A description representing the character produced by a [RawKeyEvent]. + /// + /// This value is useful for providing readable strings for keys or keyboard + /// shortcuts. Do not use this value to compare equality of keys; compare + /// [keyId] instead. + /// + /// For printable keys, this is usually the printable character in upper case + /// ignoring modifiers or combining keys, such as 'A', '1', or '/'. This + /// might also return accented letters (such as 'Ù') for keys labeled as so, + /// but not if such character is a result from preceding combining keys ('`̀' + /// followed by key U). + /// + /// For other keys, [keyLabel] looks up the full key name from a predefined + /// map, such as 'F1', 'Shift Left', or 'Media Down'. This value is an empty + /// string if there's no key label data for a key. + /// + /// For the printable representation that takes into consideration the + /// modifiers and combining keys, see [RawKeyEvent.character]. + /// + /// {@macro flutter.services.RawKeyEventData.keyLabel} + String get keyLabel { + return _unicodeKeyLabel(keyId) + ?? _keyLabels[keyId] + ?? ''; + } + + /// The debug string to print for this keyboard key, which will be null in + /// release mode. + /// + /// For printable keys, this is usually a more descriptive name related to + /// [keyLabel], such as 'Key A', 'Digit 1', 'Backslash'. This might + /// also return accented letters (such as 'Key Ù') for keys labeled as so. + /// + /// For other keys, this looks up the full key name from a predefined map (the + /// same value as [keyLabel]), such as 'F1', 'Shift Left', or 'Media Down'. If + /// there's no key label data for a key, this returns a name that explains the + /// ID (such as 'Key with ID 0x00100012345'). + String? get debugName { + String? result; + assert(() { + result = _keyLabels[keyId]; + if (result == null) { + final String? unicodeKeyLabel = _unicodeKeyLabel(keyId); + if (unicodeKeyLabel != null) { + result = 'Key $unicodeKeyLabel'; + } else { + result = 'Key with ID 0x${keyId.toRadixString(16).padLeft(11, '0')}'; + } + } + return true; + }()); + return result; + } + + @override + int get hashCode => keyId.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is LogicalKeyboardKey + && other.keyId == keyId; + } + + /// Returns the [LogicalKeyboardKey] constant that matches the given ID, or + /// null, if not found. + static LogicalKeyboardKey? findKeyByKeyId(int keyId) => _knownLogicalKeys[keyId]; + + /// Returns true if the given label represents a Unicode control character. + /// + /// Examples of control characters are characters like "U+000A LINE FEED (LF)" + /// or "U+001B ESCAPE (ESC)". + /// + /// See <https://en.wikipedia.org/wiki/Unicode_control_characters> for more + /// information. + /// + /// Used by [RawKeyEvent] subclasses to help construct IDs. + static bool isControlCharacter(String label) { + if (label.length != 1) { + return false; + } + final int codeUnit = label.codeUnitAt(0); + return (codeUnit <= 0x1f && codeUnit >= 0x00) || (codeUnit >= 0x7f && codeUnit <= 0x9f); + } + + /// Returns true if the [keyId] of this object is one that is auto-generated by + /// Flutter. + /// + /// Auto-generated key IDs are generated in response to platform key codes + /// which Flutter doesn't recognize, and their IDs shouldn't be used in a + /// persistent way. + /// + /// Auto-generated IDs should be a rare occurrence: Flutter supports most keys. + /// + /// Keys that generate Unicode characters (even if unknown to Flutter) will + /// not return true for [isAutogenerated], since they will be assigned a + /// Unicode-based code that will remain stable. + /// + /// If Flutter adds support for a previously unsupported key code, the ID it + /// reports will change, but the ID will remain stable on the platform it is + /// produced on until Flutter adds support for recognizing it. + /// + /// So, hypothetically, if Android added a new key code of 0xffff, + /// representing a new "do what I mean" key, then the auto-generated code + /// would be 0x1020000ffff, but once Flutter added the "doWhatIMean" key to + /// the definitions below, the new code would be 0x0020000ffff for all + /// platforms that had a "do what I mean" key from then on. + bool get isAutogenerated => (keyId & planeMask) >= startOfPlatformPlanes; + + /// Returns a set of pseudo-key synonyms for the given `key`. + /// + /// This allows finding the pseudo-keys that also represent a concrete `key` + /// so that a class with a key map can match pseudo-keys as well as the actual + /// generated keys. + /// + /// Pseudo-keys returned in the set are typically used to represent keys which + /// appear in multiple places on the keyboard, such as the [shift], [alt], + /// [control], and [meta] keys. Pseudo-keys in the returned set won't ever be + /// generated directly, but if a more specific key event is received, then + /// this set can be used to find the more general pseudo-key. For example, if + /// this is a [shiftLeft] key, this accessor will return the set + /// `<LogicalKeyboardKey>{ shift }`. + Set<LogicalKeyboardKey> get synonyms => _synonyms[this] ?? <LogicalKeyboardKey>{}; + + /// Takes a set of keys, and returns the same set, but with any keys that have + /// synonyms replaced. + /// + /// It is used, for example, to take sets of keys with members like + /// [controlRight] and [controlLeft] and convert that set to contain just + /// [control], so that the question "is any control key down?" can be asked. + static Set<LogicalKeyboardKey> collapseSynonyms(Set<LogicalKeyboardKey> input) { + return input.expand((LogicalKeyboardKey element) { + return _synonyms[element] ?? <LogicalKeyboardKey>{element}; + }).toSet(); + } + + /// Returns the given set with any pseudo-keys expanded into their synonyms. + /// + /// It is used, for example, to take sets of keys with members like [control] + /// and [shift] and convert that set to contain [controlLeft], [controlRight], + /// [shiftLeft], and [shiftRight]. + static Set<LogicalKeyboardKey> expandSynonyms(Set<LogicalKeyboardKey> input) { + return input.expand((LogicalKeyboardKey element) { + return _reverseSynonyms[element] ?? <LogicalKeyboardKey>{element}; + }).toSet(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('keyId', '0x${keyId.toRadixString(16).padLeft(8, '0')}')); + properties.add(StringProperty('keyLabel', keyLabel)); + properties.add(StringProperty('debugName', debugName, defaultValue: null)); + } + + /// Mask for the 32-bit value portion of the key code. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int valueMask = 0x000ffffffff; + + /// Mask for the plane prefix portion of the key code. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int planeMask = 0x0ff00000000; + + /// The plane value for keys which have a Unicode representation. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int unicodePlane = 0x00000000000; + + /// The plane value for keys defined by Chromium and does not have a Unicode + /// representation. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int unprintablePlane = 0x00100000000; + + /// The plane value for keys defined by Flutter. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int flutterPlane = 0x00200000000; + + /// The platform plane with the lowest mask value, beyond which the keys are + /// considered autogenerated. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int startOfPlatformPlanes = 0x01100000000; + + /// The plane value for the private keys defined by the Android embedding. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int androidPlane = 0x01100000000; + + /// The plane value for the private keys defined by the Fuchsia embedding. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int fuchsiaPlane = 0x01200000000; + + /// The plane value for the private keys defined by the iOS embedding. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int iosPlane = 0x01300000000; + + /// The plane value for the private keys defined by the macOS embedding. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int macosPlane = 0x01400000000; + + /// The plane value for the private keys defined by the Gtk embedding. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int gtkPlane = 0x01500000000; + + /// The plane value for the private keys defined by the Windows embedding. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int windowsPlane = 0x01600000000; + + /// The plane value for the private keys defined by the Web embedding. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int webPlane = 0x01700000000; + + /// The plane value for the private keys defined by the GLFW embedding. + /// + /// This is used by platform-specific code to generate Flutter key codes. + static const int glfwPlane = 0x01800000000; + + /// Represents the logical "Space" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey space = LogicalKeyboardKey(0x00000000020); + + /// Represents the logical "Exclamation" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey exclamation = LogicalKeyboardKey(0x00000000021); + + /// Represents the logical "Quote" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey quote = LogicalKeyboardKey(0x00000000022); + + /// Represents the logical "Number Sign" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numberSign = LogicalKeyboardKey(0x00000000023); + + /// Represents the logical "Dollar" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey dollar = LogicalKeyboardKey(0x00000000024); + + /// Represents the logical "Percent" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey percent = LogicalKeyboardKey(0x00000000025); + + /// Represents the logical "Ampersand" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey ampersand = LogicalKeyboardKey(0x00000000026); + + /// Represents the logical "Quote Single" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey quoteSingle = LogicalKeyboardKey(0x00000000027); + + /// Represents the logical "Parenthesis Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey parenthesisLeft = LogicalKeyboardKey(0x00000000028); + + /// Represents the logical "Parenthesis Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey parenthesisRight = LogicalKeyboardKey(0x00000000029); + + /// Represents the logical "Asterisk" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey asterisk = LogicalKeyboardKey(0x0000000002a); + + /// Represents the logical "Add" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey add = LogicalKeyboardKey(0x0000000002b); + + /// Represents the logical "Comma" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey comma = LogicalKeyboardKey(0x0000000002c); + + /// Represents the logical "Minus" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey minus = LogicalKeyboardKey(0x0000000002d); + + /// Represents the logical "Period" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey period = LogicalKeyboardKey(0x0000000002e); + + /// Represents the logical "Slash" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey slash = LogicalKeyboardKey(0x0000000002f); + + /// Represents the logical "Digit 0" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey digit0 = LogicalKeyboardKey(0x00000000030); + + /// Represents the logical "Digit 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey digit1 = LogicalKeyboardKey(0x00000000031); + + /// Represents the logical "Digit 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey digit2 = LogicalKeyboardKey(0x00000000032); + + /// Represents the logical "Digit 3" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey digit3 = LogicalKeyboardKey(0x00000000033); + + /// Represents the logical "Digit 4" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey digit4 = LogicalKeyboardKey(0x00000000034); + + /// Represents the logical "Digit 5" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey digit5 = LogicalKeyboardKey(0x00000000035); + + /// Represents the logical "Digit 6" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey digit6 = LogicalKeyboardKey(0x00000000036); + + /// Represents the logical "Digit 7" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey digit7 = LogicalKeyboardKey(0x00000000037); + + /// Represents the logical "Digit 8" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey digit8 = LogicalKeyboardKey(0x00000000038); + + /// Represents the logical "Digit 9" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey digit9 = LogicalKeyboardKey(0x00000000039); + + /// Represents the logical "Colon" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey colon = LogicalKeyboardKey(0x0000000003a); + + /// Represents the logical "Semicolon" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey semicolon = LogicalKeyboardKey(0x0000000003b); + + /// Represents the logical "Less" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey less = LogicalKeyboardKey(0x0000000003c); + + /// Represents the logical "Equal" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey equal = LogicalKeyboardKey(0x0000000003d); + + /// Represents the logical "Greater" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey greater = LogicalKeyboardKey(0x0000000003e); + + /// Represents the logical "Question" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey question = LogicalKeyboardKey(0x0000000003f); + + /// Represents the logical "At" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey at = LogicalKeyboardKey(0x00000000040); + + /// Represents the logical "Bracket Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey bracketLeft = LogicalKeyboardKey(0x0000000005b); + + /// Represents the logical "Backslash" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey backslash = LogicalKeyboardKey(0x0000000005c); + + /// Represents the logical "Bracket Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey bracketRight = LogicalKeyboardKey(0x0000000005d); + + /// Represents the logical "Caret" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey caret = LogicalKeyboardKey(0x0000000005e); + + /// Represents the logical "Underscore" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey underscore = LogicalKeyboardKey(0x0000000005f); + + /// Represents the logical "Backquote" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey backquote = LogicalKeyboardKey(0x00000000060); + + /// Represents the logical "Key A" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyA = LogicalKeyboardKey(0x00000000061); + + /// Represents the logical "Key B" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyB = LogicalKeyboardKey(0x00000000062); + + /// Represents the logical "Key C" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyC = LogicalKeyboardKey(0x00000000063); + + /// Represents the logical "Key D" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyD = LogicalKeyboardKey(0x00000000064); + + /// Represents the logical "Key E" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyE = LogicalKeyboardKey(0x00000000065); + + /// Represents the logical "Key F" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyF = LogicalKeyboardKey(0x00000000066); + + /// Represents the logical "Key G" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyG = LogicalKeyboardKey(0x00000000067); + + /// Represents the logical "Key H" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyH = LogicalKeyboardKey(0x00000000068); + + /// Represents the logical "Key I" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyI = LogicalKeyboardKey(0x00000000069); + + /// Represents the logical "Key J" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyJ = LogicalKeyboardKey(0x0000000006a); + + /// Represents the logical "Key K" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyK = LogicalKeyboardKey(0x0000000006b); + + /// Represents the logical "Key L" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyL = LogicalKeyboardKey(0x0000000006c); + + /// Represents the logical "Key M" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyM = LogicalKeyboardKey(0x0000000006d); + + /// Represents the logical "Key N" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyN = LogicalKeyboardKey(0x0000000006e); + + /// Represents the logical "Key O" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyO = LogicalKeyboardKey(0x0000000006f); + + /// Represents the logical "Key P" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyP = LogicalKeyboardKey(0x00000000070); + + /// Represents the logical "Key Q" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyQ = LogicalKeyboardKey(0x00000000071); + + /// Represents the logical "Key R" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyR = LogicalKeyboardKey(0x00000000072); + + /// Represents the logical "Key S" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyS = LogicalKeyboardKey(0x00000000073); + + /// Represents the logical "Key T" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyT = LogicalKeyboardKey(0x00000000074); + + /// Represents the logical "Key U" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyU = LogicalKeyboardKey(0x00000000075); + + /// Represents the logical "Key V" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyV = LogicalKeyboardKey(0x00000000076); + + /// Represents the logical "Key W" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyW = LogicalKeyboardKey(0x00000000077); + + /// Represents the logical "Key X" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyX = LogicalKeyboardKey(0x00000000078); + + /// Represents the logical "Key Y" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyY = LogicalKeyboardKey(0x00000000079); + + /// Represents the logical "Key Z" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey keyZ = LogicalKeyboardKey(0x0000000007a); + + /// Represents the logical "Brace Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey braceLeft = LogicalKeyboardKey(0x0000000007b); + + /// Represents the logical "Bar" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey bar = LogicalKeyboardKey(0x0000000007c); + + /// Represents the logical "Brace Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey braceRight = LogicalKeyboardKey(0x0000000007d); + + /// Represents the logical "Tilde" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tilde = LogicalKeyboardKey(0x0000000007e); + + /// Represents the logical "Unidentified" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey unidentified = LogicalKeyboardKey(0x00100000001); + + /// Represents the logical "Backspace" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey backspace = LogicalKeyboardKey(0x00100000008); + + /// Represents the logical "Tab" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tab = LogicalKeyboardKey(0x00100000009); + + /// Represents the logical "Enter" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey enter = LogicalKeyboardKey(0x0010000000d); + + /// Represents the logical "Escape" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey escape = LogicalKeyboardKey(0x0010000001b); + + /// Represents the logical "Delete" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey delete = LogicalKeyboardKey(0x0010000007f); + + /// Represents the logical "Accel" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey accel = LogicalKeyboardKey(0x00100000101); + + /// Represents the logical "Alt Graph" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey altGraph = LogicalKeyboardKey(0x00100000103); + + /// Represents the logical "Caps Lock" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey capsLock = LogicalKeyboardKey(0x00100000104); + + /// Represents the logical "Fn" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey fn = LogicalKeyboardKey(0x00100000106); + + /// Represents the logical "Fn Lock" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey fnLock = LogicalKeyboardKey(0x00100000107); + + /// Represents the logical "Hyper" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey hyper = LogicalKeyboardKey(0x00100000108); + + /// Represents the logical "Num Lock" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numLock = LogicalKeyboardKey(0x0010000010a); + + /// Represents the logical "Scroll Lock" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey scrollLock = LogicalKeyboardKey(0x0010000010c); + + /// Represents the logical "Super" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey superKey = LogicalKeyboardKey(0x0010000010e); + + /// Represents the logical "Symbol" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey symbol = LogicalKeyboardKey(0x0010000010f); + + /// Represents the logical "Symbol Lock" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey symbolLock = LogicalKeyboardKey(0x00100000110); + + /// Represents the logical "Shift Level 5" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey shiftLevel5 = LogicalKeyboardKey(0x00100000111); + + /// Represents the logical "Arrow Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey arrowDown = LogicalKeyboardKey(0x00100000301); + + /// Represents the logical "Arrow Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey arrowLeft = LogicalKeyboardKey(0x00100000302); + + /// Represents the logical "Arrow Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey arrowRight = LogicalKeyboardKey(0x00100000303); + + /// Represents the logical "Arrow Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey arrowUp = LogicalKeyboardKey(0x00100000304); + + /// Represents the logical "End" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey end = LogicalKeyboardKey(0x00100000305); + + /// Represents the logical "Home" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey home = LogicalKeyboardKey(0x00100000306); + + /// Represents the logical "Page Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey pageDown = LogicalKeyboardKey(0x00100000307); + + /// Represents the logical "Page Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey pageUp = LogicalKeyboardKey(0x00100000308); + + /// Represents the logical "Clear" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey clear = LogicalKeyboardKey(0x00100000401); + + /// Represents the logical "Copy" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey copy = LogicalKeyboardKey(0x00100000402); + + /// Represents the logical "Cr Sel" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey crSel = LogicalKeyboardKey(0x00100000403); + + /// Represents the logical "Cut" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey cut = LogicalKeyboardKey(0x00100000404); + + /// Represents the logical "Erase Eof" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey eraseEof = LogicalKeyboardKey(0x00100000405); + + /// Represents the logical "Ex Sel" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey exSel = LogicalKeyboardKey(0x00100000406); + + /// Represents the logical "Insert" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey insert = LogicalKeyboardKey(0x00100000407); + + /// Represents the logical "Paste" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey paste = LogicalKeyboardKey(0x00100000408); + + /// Represents the logical "Redo" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey redo = LogicalKeyboardKey(0x00100000409); + + /// Represents the logical "Undo" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey undo = LogicalKeyboardKey(0x0010000040a); + + /// Represents the logical "Accept" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey accept = LogicalKeyboardKey(0x00100000501); + + /// Represents the logical "Again" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey again = LogicalKeyboardKey(0x00100000502); + + /// Represents the logical "Attn" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey attn = LogicalKeyboardKey(0x00100000503); + + /// Represents the logical "Cancel" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey cancel = LogicalKeyboardKey(0x00100000504); + + /// Represents the logical "Context Menu" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey contextMenu = LogicalKeyboardKey(0x00100000505); + + /// Represents the logical "Execute" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey execute = LogicalKeyboardKey(0x00100000506); + + /// Represents the logical "Find" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey find = LogicalKeyboardKey(0x00100000507); + + /// Represents the logical "Help" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey help = LogicalKeyboardKey(0x00100000508); + + /// Represents the logical "Pause" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey pause = LogicalKeyboardKey(0x00100000509); + + /// Represents the logical "Play" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey play = LogicalKeyboardKey(0x0010000050a); + + /// Represents the logical "Props" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey props = LogicalKeyboardKey(0x0010000050b); + + /// Represents the logical "Select" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey select = LogicalKeyboardKey(0x0010000050c); + + /// Represents the logical "Zoom In" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey zoomIn = LogicalKeyboardKey(0x0010000050d); + + /// Represents the logical "Zoom Out" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey zoomOut = LogicalKeyboardKey(0x0010000050e); + + /// Represents the logical "Brightness Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey brightnessDown = LogicalKeyboardKey(0x00100000601); + + /// Represents the logical "Brightness Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey brightnessUp = LogicalKeyboardKey(0x00100000602); + + /// Represents the logical "Camera" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey camera = LogicalKeyboardKey(0x00100000603); + + /// Represents the logical "Eject" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey eject = LogicalKeyboardKey(0x00100000604); + + /// Represents the logical "Log Off" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey logOff = LogicalKeyboardKey(0x00100000605); + + /// Represents the logical "Power" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey power = LogicalKeyboardKey(0x00100000606); + + /// Represents the logical "Power Off" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey powerOff = LogicalKeyboardKey(0x00100000607); + + /// Represents the logical "Print Screen" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey printScreen = LogicalKeyboardKey(0x00100000608); + + /// Represents the logical "Hibernate" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey hibernate = LogicalKeyboardKey(0x00100000609); + + /// Represents the logical "Standby" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey standby = LogicalKeyboardKey(0x0010000060a); + + /// Represents the logical "Wake Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey wakeUp = LogicalKeyboardKey(0x0010000060b); + + /// Represents the logical "All Candidates" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey allCandidates = LogicalKeyboardKey(0x00100000701); + + /// Represents the logical "Alphanumeric" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey alphanumeric = LogicalKeyboardKey(0x00100000702); + + /// Represents the logical "Code Input" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey codeInput = LogicalKeyboardKey(0x00100000703); + + /// Represents the logical "Compose" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey compose = LogicalKeyboardKey(0x00100000704); + + /// Represents the logical "Convert" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey convert = LogicalKeyboardKey(0x00100000705); + + /// Represents the logical "Final Mode" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey finalMode = LogicalKeyboardKey(0x00100000706); + + /// Represents the logical "Group First" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey groupFirst = LogicalKeyboardKey(0x00100000707); + + /// Represents the logical "Group Last" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey groupLast = LogicalKeyboardKey(0x00100000708); + + /// Represents the logical "Group Next" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey groupNext = LogicalKeyboardKey(0x00100000709); + + /// Represents the logical "Group Previous" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey groupPrevious = LogicalKeyboardKey(0x0010000070a); + + /// Represents the logical "Mode Change" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey modeChange = LogicalKeyboardKey(0x0010000070b); + + /// Represents the logical "Next Candidate" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey nextCandidate = LogicalKeyboardKey(0x0010000070c); + + /// Represents the logical "Non Convert" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey nonConvert = LogicalKeyboardKey(0x0010000070d); + + /// Represents the logical "Previous Candidate" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey previousCandidate = LogicalKeyboardKey(0x0010000070e); + + /// Represents the logical "Process" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey process = LogicalKeyboardKey(0x0010000070f); + + /// Represents the logical "Single Candidate" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey singleCandidate = LogicalKeyboardKey(0x00100000710); + + /// Represents the logical "Hangul Mode" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey hangulMode = LogicalKeyboardKey(0x00100000711); + + /// Represents the logical "Hanja Mode" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey hanjaMode = LogicalKeyboardKey(0x00100000712); + + /// Represents the logical "Junja Mode" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey junjaMode = LogicalKeyboardKey(0x00100000713); + + /// Represents the logical "Eisu" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey eisu = LogicalKeyboardKey(0x00100000714); + + /// Represents the logical "Hankaku" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey hankaku = LogicalKeyboardKey(0x00100000715); + + /// Represents the logical "Hiragana" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey hiragana = LogicalKeyboardKey(0x00100000716); + + /// Represents the logical "Hiragana Katakana" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey hiraganaKatakana = LogicalKeyboardKey(0x00100000717); + + /// Represents the logical "Kana Mode" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey kanaMode = LogicalKeyboardKey(0x00100000718); + + /// Represents the logical "Kanji Mode" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey kanjiMode = LogicalKeyboardKey(0x00100000719); + + /// Represents the logical "Katakana" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey katakana = LogicalKeyboardKey(0x0010000071a); + + /// Represents the logical "Romaji" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey romaji = LogicalKeyboardKey(0x0010000071b); + + /// Represents the logical "Zenkaku" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey zenkaku = LogicalKeyboardKey(0x0010000071c); + + /// Represents the logical "Zenkaku Hankaku" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey zenkakuHankaku = LogicalKeyboardKey(0x0010000071d); + + /// Represents the logical "F1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f1 = LogicalKeyboardKey(0x00100000801); + + /// Represents the logical "F2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f2 = LogicalKeyboardKey(0x00100000802); + + /// Represents the logical "F3" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f3 = LogicalKeyboardKey(0x00100000803); + + /// Represents the logical "F4" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f4 = LogicalKeyboardKey(0x00100000804); + + /// Represents the logical "F5" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f5 = LogicalKeyboardKey(0x00100000805); + + /// Represents the logical "F6" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f6 = LogicalKeyboardKey(0x00100000806); + + /// Represents the logical "F7" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f7 = LogicalKeyboardKey(0x00100000807); + + /// Represents the logical "F8" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f8 = LogicalKeyboardKey(0x00100000808); + + /// Represents the logical "F9" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f9 = LogicalKeyboardKey(0x00100000809); + + /// Represents the logical "F10" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f10 = LogicalKeyboardKey(0x0010000080a); + + /// Represents the logical "F11" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f11 = LogicalKeyboardKey(0x0010000080b); + + /// Represents the logical "F12" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f12 = LogicalKeyboardKey(0x0010000080c); + + /// Represents the logical "F13" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f13 = LogicalKeyboardKey(0x0010000080d); + + /// Represents the logical "F14" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f14 = LogicalKeyboardKey(0x0010000080e); + + /// Represents the logical "F15" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f15 = LogicalKeyboardKey(0x0010000080f); + + /// Represents the logical "F16" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f16 = LogicalKeyboardKey(0x00100000810); + + /// Represents the logical "F17" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f17 = LogicalKeyboardKey(0x00100000811); + + /// Represents the logical "F18" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f18 = LogicalKeyboardKey(0x00100000812); + + /// Represents the logical "F19" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f19 = LogicalKeyboardKey(0x00100000813); + + /// Represents the logical "F20" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f20 = LogicalKeyboardKey(0x00100000814); + + /// Represents the logical "F21" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f21 = LogicalKeyboardKey(0x00100000815); + + /// Represents the logical "F22" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f22 = LogicalKeyboardKey(0x00100000816); + + /// Represents the logical "F23" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f23 = LogicalKeyboardKey(0x00100000817); + + /// Represents the logical "F24" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey f24 = LogicalKeyboardKey(0x00100000818); + + /// Represents the logical "Soft 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey soft1 = LogicalKeyboardKey(0x00100000901); + + /// Represents the logical "Soft 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey soft2 = LogicalKeyboardKey(0x00100000902); + + /// Represents the logical "Soft 3" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey soft3 = LogicalKeyboardKey(0x00100000903); + + /// Represents the logical "Soft 4" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey soft4 = LogicalKeyboardKey(0x00100000904); + + /// Represents the logical "Soft 5" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey soft5 = LogicalKeyboardKey(0x00100000905); + + /// Represents the logical "Soft 6" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey soft6 = LogicalKeyboardKey(0x00100000906); + + /// Represents the logical "Soft 7" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey soft7 = LogicalKeyboardKey(0x00100000907); + + /// Represents the logical "Soft 8" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey soft8 = LogicalKeyboardKey(0x00100000908); + + /// Represents the logical "Close" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey close = LogicalKeyboardKey(0x00100000a01); + + /// Represents the logical "Mail Forward" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mailForward = LogicalKeyboardKey(0x00100000a02); + + /// Represents the logical "Mail Reply" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mailReply = LogicalKeyboardKey(0x00100000a03); + + /// Represents the logical "Mail Send" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mailSend = LogicalKeyboardKey(0x00100000a04); + + /// Represents the logical "Media Play Pause" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaPlayPause = LogicalKeyboardKey(0x00100000a05); + + /// Represents the logical "Media Stop" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaStop = LogicalKeyboardKey(0x00100000a07); + + /// Represents the logical "Media Track Next" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaTrackNext = LogicalKeyboardKey(0x00100000a08); + + /// Represents the logical "Media Track Previous" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaTrackPrevious = LogicalKeyboardKey(0x00100000a09); + + /// Represents the logical "New" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey newKey = LogicalKeyboardKey(0x00100000a0a); + + /// Represents the logical "Open" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey open = LogicalKeyboardKey(0x00100000a0b); + + /// Represents the logical "Print" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey print = LogicalKeyboardKey(0x00100000a0c); + + /// Represents the logical "Save" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey save = LogicalKeyboardKey(0x00100000a0d); + + /// Represents the logical "Spell Check" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey spellCheck = LogicalKeyboardKey(0x00100000a0e); + + /// Represents the logical "Audio Volume Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioVolumeDown = LogicalKeyboardKey(0x00100000a0f); + + /// Represents the logical "Audio Volume Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioVolumeUp = LogicalKeyboardKey(0x00100000a10); + + /// Represents the logical "Audio Volume Mute" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioVolumeMute = LogicalKeyboardKey(0x00100000a11); + + /// Represents the logical "Launch Application 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchApplication2 = LogicalKeyboardKey(0x00100000b01); + + /// Represents the logical "Launch Calendar" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchCalendar = LogicalKeyboardKey(0x00100000b02); + + /// Represents the logical "Launch Mail" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchMail = LogicalKeyboardKey(0x00100000b03); + + /// Represents the logical "Launch Media Player" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchMediaPlayer = LogicalKeyboardKey(0x00100000b04); + + /// Represents the logical "Launch Music Player" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchMusicPlayer = LogicalKeyboardKey(0x00100000b05); + + /// Represents the logical "Launch Application 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchApplication1 = LogicalKeyboardKey(0x00100000b06); + + /// Represents the logical "Launch Screen Saver" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchScreenSaver = LogicalKeyboardKey(0x00100000b07); + + /// Represents the logical "Launch Spreadsheet" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchSpreadsheet = LogicalKeyboardKey(0x00100000b08); + + /// Represents the logical "Launch Web Browser" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchWebBrowser = LogicalKeyboardKey(0x00100000b09); + + /// Represents the logical "Launch Web Cam" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchWebCam = LogicalKeyboardKey(0x00100000b0a); + + /// Represents the logical "Launch Word Processor" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchWordProcessor = LogicalKeyboardKey(0x00100000b0b); + + /// Represents the logical "Launch Contacts" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchContacts = LogicalKeyboardKey(0x00100000b0c); + + /// Represents the logical "Launch Phone" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchPhone = LogicalKeyboardKey(0x00100000b0d); + + /// Represents the logical "Launch Assistant" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchAssistant = LogicalKeyboardKey(0x00100000b0e); + + /// Represents the logical "Launch Control Panel" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey launchControlPanel = LogicalKeyboardKey(0x00100000b0f); + + /// Represents the logical "Browser Back" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey browserBack = LogicalKeyboardKey(0x00100000c01); + + /// Represents the logical "Browser Favorites" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey browserFavorites = LogicalKeyboardKey(0x00100000c02); + + /// Represents the logical "Browser Forward" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey browserForward = LogicalKeyboardKey(0x00100000c03); + + /// Represents the logical "Browser Home" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey browserHome = LogicalKeyboardKey(0x00100000c04); + + /// Represents the logical "Browser Refresh" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey browserRefresh = LogicalKeyboardKey(0x00100000c05); + + /// Represents the logical "Browser Search" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey browserSearch = LogicalKeyboardKey(0x00100000c06); + + /// Represents the logical "Browser Stop" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey browserStop = LogicalKeyboardKey(0x00100000c07); + + /// Represents the logical "Audio Balance Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioBalanceLeft = LogicalKeyboardKey(0x00100000d01); + + /// Represents the logical "Audio Balance Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioBalanceRight = LogicalKeyboardKey(0x00100000d02); + + /// Represents the logical "Audio Bass Boost Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioBassBoostDown = LogicalKeyboardKey(0x00100000d03); + + /// Represents the logical "Audio Bass Boost Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioBassBoostUp = LogicalKeyboardKey(0x00100000d04); + + /// Represents the logical "Audio Fader Front" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioFaderFront = LogicalKeyboardKey(0x00100000d05); + + /// Represents the logical "Audio Fader Rear" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioFaderRear = LogicalKeyboardKey(0x00100000d06); + + /// Represents the logical "Audio Surround Mode Next" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioSurroundModeNext = LogicalKeyboardKey(0x00100000d07); + + /// Represents the logical "AVR Input" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey avrInput = LogicalKeyboardKey(0x00100000d08); + + /// Represents the logical "AVR Power" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey avrPower = LogicalKeyboardKey(0x00100000d09); + + /// Represents the logical "Channel Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey channelDown = LogicalKeyboardKey(0x00100000d0a); + + /// Represents the logical "Channel Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey channelUp = LogicalKeyboardKey(0x00100000d0b); + + /// Represents the logical "Color F0 Red" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey colorF0Red = LogicalKeyboardKey(0x00100000d0c); + + /// Represents the logical "Color F1 Green" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey colorF1Green = LogicalKeyboardKey(0x00100000d0d); + + /// Represents the logical "Color F2 Yellow" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey colorF2Yellow = LogicalKeyboardKey(0x00100000d0e); + + /// Represents the logical "Color F3 Blue" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey colorF3Blue = LogicalKeyboardKey(0x00100000d0f); + + /// Represents the logical "Color F4 Grey" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey colorF4Grey = LogicalKeyboardKey(0x00100000d10); + + /// Represents the logical "Color F5 Brown" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey colorF5Brown = LogicalKeyboardKey(0x00100000d11); + + /// Represents the logical "Closed Caption Toggle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey closedCaptionToggle = LogicalKeyboardKey(0x00100000d12); + + /// Represents the logical "Dimmer" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey dimmer = LogicalKeyboardKey(0x00100000d13); + + /// Represents the logical "Display Swap" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey displaySwap = LogicalKeyboardKey(0x00100000d14); + + /// Represents the logical "Exit" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey exit = LogicalKeyboardKey(0x00100000d15); + + /// Represents the logical "Favorite Clear 0" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteClear0 = LogicalKeyboardKey(0x00100000d16); + + /// Represents the logical "Favorite Clear 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteClear1 = LogicalKeyboardKey(0x00100000d17); + + /// Represents the logical "Favorite Clear 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteClear2 = LogicalKeyboardKey(0x00100000d18); + + /// Represents the logical "Favorite Clear 3" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteClear3 = LogicalKeyboardKey(0x00100000d19); + + /// Represents the logical "Favorite Recall 0" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteRecall0 = LogicalKeyboardKey(0x00100000d1a); + + /// Represents the logical "Favorite Recall 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteRecall1 = LogicalKeyboardKey(0x00100000d1b); + + /// Represents the logical "Favorite Recall 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteRecall2 = LogicalKeyboardKey(0x00100000d1c); + + /// Represents the logical "Favorite Recall 3" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteRecall3 = LogicalKeyboardKey(0x00100000d1d); + + /// Represents the logical "Favorite Store 0" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteStore0 = LogicalKeyboardKey(0x00100000d1e); + + /// Represents the logical "Favorite Store 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteStore1 = LogicalKeyboardKey(0x00100000d1f); + + /// Represents the logical "Favorite Store 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteStore2 = LogicalKeyboardKey(0x00100000d20); + + /// Represents the logical "Favorite Store 3" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey favoriteStore3 = LogicalKeyboardKey(0x00100000d21); + + /// Represents the logical "Guide" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey guide = LogicalKeyboardKey(0x00100000d22); + + /// Represents the logical "Guide Next Day" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey guideNextDay = LogicalKeyboardKey(0x00100000d23); + + /// Represents the logical "Guide Previous Day" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey guidePreviousDay = LogicalKeyboardKey(0x00100000d24); + + /// Represents the logical "Info" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey info = LogicalKeyboardKey(0x00100000d25); + + /// Represents the logical "Instant Replay" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey instantReplay = LogicalKeyboardKey(0x00100000d26); + + /// Represents the logical "Link" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey link = LogicalKeyboardKey(0x00100000d27); + + /// Represents the logical "List Program" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey listProgram = LogicalKeyboardKey(0x00100000d28); + + /// Represents the logical "Live Content" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey liveContent = LogicalKeyboardKey(0x00100000d29); + + /// Represents the logical "Lock" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey lock = LogicalKeyboardKey(0x00100000d2a); + + /// Represents the logical "Media Apps" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaApps = LogicalKeyboardKey(0x00100000d2b); + + /// Represents the logical "Media Fast Forward" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaFastForward = LogicalKeyboardKey(0x00100000d2c); + + /// Represents the logical "Media Last" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaLast = LogicalKeyboardKey(0x00100000d2d); + + /// Represents the logical "Media Pause" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaPause = LogicalKeyboardKey(0x00100000d2e); + + /// Represents the logical "Media Play" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaPlay = LogicalKeyboardKey(0x00100000d2f); + + /// Represents the logical "Media Record" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaRecord = LogicalKeyboardKey(0x00100000d30); + + /// Represents the logical "Media Rewind" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaRewind = LogicalKeyboardKey(0x00100000d31); + + /// Represents the logical "Media Skip" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaSkip = LogicalKeyboardKey(0x00100000d32); + + /// Represents the logical "Next Favorite Channel" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey nextFavoriteChannel = LogicalKeyboardKey(0x00100000d33); + + /// Represents the logical "Next User Profile" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey nextUserProfile = LogicalKeyboardKey(0x00100000d34); + + /// Represents the logical "On Demand" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey onDemand = LogicalKeyboardKey(0x00100000d35); + + /// Represents the logical "P In P Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey pInPDown = LogicalKeyboardKey(0x00100000d36); + + /// Represents the logical "P In P Move" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey pInPMove = LogicalKeyboardKey(0x00100000d37); + + /// Represents the logical "P In P Toggle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey pInPToggle = LogicalKeyboardKey(0x00100000d38); + + /// Represents the logical "P In P Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey pInPUp = LogicalKeyboardKey(0x00100000d39); + + /// Represents the logical "Play Speed Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey playSpeedDown = LogicalKeyboardKey(0x00100000d3a); + + /// Represents the logical "Play Speed Reset" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey playSpeedReset = LogicalKeyboardKey(0x00100000d3b); + + /// Represents the logical "Play Speed Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey playSpeedUp = LogicalKeyboardKey(0x00100000d3c); + + /// Represents the logical "Random Toggle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey randomToggle = LogicalKeyboardKey(0x00100000d3d); + + /// Represents the logical "Rc Low Battery" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey rcLowBattery = LogicalKeyboardKey(0x00100000d3e); + + /// Represents the logical "Record Speed Next" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey recordSpeedNext = LogicalKeyboardKey(0x00100000d3f); + + /// Represents the logical "Rf Bypass" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey rfBypass = LogicalKeyboardKey(0x00100000d40); + + /// Represents the logical "Scan Channels Toggle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey scanChannelsToggle = LogicalKeyboardKey(0x00100000d41); + + /// Represents the logical "Screen Mode Next" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey screenModeNext = LogicalKeyboardKey(0x00100000d42); + + /// Represents the logical "Settings" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey settings = LogicalKeyboardKey(0x00100000d43); + + /// Represents the logical "Split Screen Toggle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey splitScreenToggle = LogicalKeyboardKey(0x00100000d44); + + /// Represents the logical "STB Input" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey stbInput = LogicalKeyboardKey(0x00100000d45); + + /// Represents the logical "STB Power" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey stbPower = LogicalKeyboardKey(0x00100000d46); + + /// Represents the logical "Subtitle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey subtitle = LogicalKeyboardKey(0x00100000d47); + + /// Represents the logical "Teletext" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey teletext = LogicalKeyboardKey(0x00100000d48); + + /// Represents the logical "TV" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tv = LogicalKeyboardKey(0x00100000d49); + + /// Represents the logical "TV Input" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvInput = LogicalKeyboardKey(0x00100000d4a); + + /// Represents the logical "TV Power" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvPower = LogicalKeyboardKey(0x00100000d4b); + + /// Represents the logical "Video Mode Next" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey videoModeNext = LogicalKeyboardKey(0x00100000d4c); + + /// Represents the logical "Wink" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey wink = LogicalKeyboardKey(0x00100000d4d); + + /// Represents the logical "Zoom Toggle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey zoomToggle = LogicalKeyboardKey(0x00100000d4e); + + /// Represents the logical "DVR" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey dvr = LogicalKeyboardKey(0x00100000d4f); + + /// Represents the logical "Media Audio Track" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaAudioTrack = LogicalKeyboardKey(0x00100000d50); + + /// Represents the logical "Media Skip Backward" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaSkipBackward = LogicalKeyboardKey(0x00100000d51); + + /// Represents the logical "Media Skip Forward" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaSkipForward = LogicalKeyboardKey(0x00100000d52); + + /// Represents the logical "Media Step Backward" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaStepBackward = LogicalKeyboardKey(0x00100000d53); + + /// Represents the logical "Media Step Forward" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaStepForward = LogicalKeyboardKey(0x00100000d54); + + /// Represents the logical "Media Top Menu" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaTopMenu = LogicalKeyboardKey(0x00100000d55); + + /// Represents the logical "Navigate In" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey navigateIn = LogicalKeyboardKey(0x00100000d56); + + /// Represents the logical "Navigate Next" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey navigateNext = LogicalKeyboardKey(0x00100000d57); + + /// Represents the logical "Navigate Out" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey navigateOut = LogicalKeyboardKey(0x00100000d58); + + /// Represents the logical "Navigate Previous" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey navigatePrevious = LogicalKeyboardKey(0x00100000d59); + + /// Represents the logical "Pairing" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey pairing = LogicalKeyboardKey(0x00100000d5a); + + /// Represents the logical "Media Close" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mediaClose = LogicalKeyboardKey(0x00100000d5b); + + /// Represents the logical "Audio Bass Boost Toggle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioBassBoostToggle = LogicalKeyboardKey(0x00100000e02); + + /// Represents the logical "Audio Treble Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioTrebleDown = LogicalKeyboardKey(0x00100000e04); + + /// Represents the logical "Audio Treble Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey audioTrebleUp = LogicalKeyboardKey(0x00100000e05); + + /// Represents the logical "Microphone Toggle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey microphoneToggle = LogicalKeyboardKey(0x00100000e06); + + /// Represents the logical "Microphone Volume Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey microphoneVolumeDown = LogicalKeyboardKey(0x00100000e07); + + /// Represents the logical "Microphone Volume Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey microphoneVolumeUp = LogicalKeyboardKey(0x00100000e08); + + /// Represents the logical "Microphone Volume Mute" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey microphoneVolumeMute = LogicalKeyboardKey(0x00100000e09); + + /// Represents the logical "Speech Correction List" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey speechCorrectionList = LogicalKeyboardKey(0x00100000f01); + + /// Represents the logical "Speech Input Toggle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey speechInputToggle = LogicalKeyboardKey(0x00100000f02); + + /// Represents the logical "App Switch" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey appSwitch = LogicalKeyboardKey(0x00100001001); + + /// Represents the logical "Call" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey call = LogicalKeyboardKey(0x00100001002); + + /// Represents the logical "Camera Focus" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey cameraFocus = LogicalKeyboardKey(0x00100001003); + + /// Represents the logical "End Call" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey endCall = LogicalKeyboardKey(0x00100001004); + + /// Represents the logical "Go Back" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey goBack = LogicalKeyboardKey(0x00100001005); + + /// Represents the logical "Go Home" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey goHome = LogicalKeyboardKey(0x00100001006); + + /// Represents the logical "Headset Hook" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey headsetHook = LogicalKeyboardKey(0x00100001007); + + /// Represents the logical "Last Number Redial" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey lastNumberRedial = LogicalKeyboardKey(0x00100001008); + + /// Represents the logical "Notification" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey notification = LogicalKeyboardKey(0x00100001009); + + /// Represents the logical "Manner Mode" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey mannerMode = LogicalKeyboardKey(0x0010000100a); + + /// Represents the logical "Voice Dial" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey voiceDial = LogicalKeyboardKey(0x0010000100b); + + /// Represents the logical "TV 3 D Mode" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tv3DMode = LogicalKeyboardKey(0x00100001101); + + /// Represents the logical "TV Antenna Cable" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvAntennaCable = LogicalKeyboardKey(0x00100001102); + + /// Represents the logical "TV Audio Description" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvAudioDescription = LogicalKeyboardKey(0x00100001103); + + /// Represents the logical "TV Audio Description Mix Down" key on the + /// keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvAudioDescriptionMixDown = LogicalKeyboardKey(0x00100001104); + + /// Represents the logical "TV Audio Description Mix Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvAudioDescriptionMixUp = LogicalKeyboardKey(0x00100001105); + + /// Represents the logical "TV Contents Menu" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvContentsMenu = LogicalKeyboardKey(0x00100001106); + + /// Represents the logical "TV Data Service" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvDataService = LogicalKeyboardKey(0x00100001107); + + /// Represents the logical "TV Input Component 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvInputComponent1 = LogicalKeyboardKey(0x00100001108); + + /// Represents the logical "TV Input Component 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvInputComponent2 = LogicalKeyboardKey(0x00100001109); + + /// Represents the logical "TV Input Composite 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvInputComposite1 = LogicalKeyboardKey(0x0010000110a); + + /// Represents the logical "TV Input Composite 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvInputComposite2 = LogicalKeyboardKey(0x0010000110b); + + /// Represents the logical "TV Input HDMI 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvInputHDMI1 = LogicalKeyboardKey(0x0010000110c); + + /// Represents the logical "TV Input HDMI 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvInputHDMI2 = LogicalKeyboardKey(0x0010000110d); + + /// Represents the logical "TV Input HDMI 3" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvInputHDMI3 = LogicalKeyboardKey(0x0010000110e); + + /// Represents the logical "TV Input HDMI 4" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvInputHDMI4 = LogicalKeyboardKey(0x0010000110f); + + /// Represents the logical "TV Input VGA 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvInputVGA1 = LogicalKeyboardKey(0x00100001110); + + /// Represents the logical "TV Media Context" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvMediaContext = LogicalKeyboardKey(0x00100001111); + + /// Represents the logical "TV Network" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvNetwork = LogicalKeyboardKey(0x00100001112); + + /// Represents the logical "TV Number Entry" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvNumberEntry = LogicalKeyboardKey(0x00100001113); + + /// Represents the logical "TV Radio Service" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvRadioService = LogicalKeyboardKey(0x00100001114); + + /// Represents the logical "TV Satellite" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvSatellite = LogicalKeyboardKey(0x00100001115); + + /// Represents the logical "TV Satellite BS" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvSatelliteBS = LogicalKeyboardKey(0x00100001116); + + /// Represents the logical "TV Satellite CS" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvSatelliteCS = LogicalKeyboardKey(0x00100001117); + + /// Represents the logical "TV Satellite Toggle" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvSatelliteToggle = LogicalKeyboardKey(0x00100001118); + + /// Represents the logical "TV Terrestrial Analog" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvTerrestrialAnalog = LogicalKeyboardKey(0x00100001119); + + /// Represents the logical "TV Terrestrial Digital" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvTerrestrialDigital = LogicalKeyboardKey(0x0010000111a); + + /// Represents the logical "TV Timer" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey tvTimer = LogicalKeyboardKey(0x0010000111b); + + /// Represents the logical "Key 11" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey key11 = LogicalKeyboardKey(0x00100001201); + + /// Represents the logical "Key 12" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey key12 = LogicalKeyboardKey(0x00100001202); + + /// Represents the logical "Suspend" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey suspend = LogicalKeyboardKey(0x00200000000); + + /// Represents the logical "Resume" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey resume = LogicalKeyboardKey(0x00200000001); + + /// Represents the logical "Sleep" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey sleep = LogicalKeyboardKey(0x00200000002); + + /// Represents the logical "Abort" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey abort = LogicalKeyboardKey(0x00200000003); + + /// Represents the logical "Lang 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey lang1 = LogicalKeyboardKey(0x00200000010); + + /// Represents the logical "Lang 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey lang2 = LogicalKeyboardKey(0x00200000011); + + /// Represents the logical "Lang 3" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey lang3 = LogicalKeyboardKey(0x00200000012); + + /// Represents the logical "Lang 4" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey lang4 = LogicalKeyboardKey(0x00200000013); + + /// Represents the logical "Lang 5" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey lang5 = LogicalKeyboardKey(0x00200000014); + + /// Represents the logical "Intl Backslash" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey intlBackslash = LogicalKeyboardKey(0x00200000020); + + /// Represents the logical "Intl Ro" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey intlRo = LogicalKeyboardKey(0x00200000021); + + /// Represents the logical "Intl Yen" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey intlYen = LogicalKeyboardKey(0x00200000022); + + /// Represents the logical "Control Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey controlLeft = LogicalKeyboardKey(0x00200000100); + + /// Represents the logical "Control Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey controlRight = LogicalKeyboardKey(0x00200000101); + + /// Represents the logical "Shift Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey shiftLeft = LogicalKeyboardKey(0x00200000102); + + /// Represents the logical "Shift Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey shiftRight = LogicalKeyboardKey(0x00200000103); + + /// Represents the logical "Alt Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey altLeft = LogicalKeyboardKey(0x00200000104); + + /// Represents the logical "Alt Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey altRight = LogicalKeyboardKey(0x00200000105); + + /// Represents the logical "Meta Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey metaLeft = LogicalKeyboardKey(0x00200000106); + + /// Represents the logical "Meta Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey metaRight = LogicalKeyboardKey(0x00200000107); + + /// Represents the logical "Control" key on the keyboard. + /// + /// This key represents the union of the keys {controlLeft, controlRight} when + /// comparing keys. This key will never be generated directly, its main use is + /// in defining key maps. + static const LogicalKeyboardKey control = LogicalKeyboardKey(0x002000001f0); + + /// Represents the logical "Shift" key on the keyboard. + /// + /// This key represents the union of the keys {shiftLeft, shiftRight} when + /// comparing keys. This key will never be generated directly, its main use is + /// in defining key maps. + static const LogicalKeyboardKey shift = LogicalKeyboardKey(0x002000001f2); + + /// Represents the logical "Alt" key on the keyboard. + /// + /// This key represents the union of the keys {altLeft, altRight} when + /// comparing keys. This key will never be generated directly, its main use is + /// in defining key maps. + static const LogicalKeyboardKey alt = LogicalKeyboardKey(0x002000001f4); + + /// Represents the logical "Meta" key on the keyboard. + /// + /// This key represents the union of the keys {metaLeft, metaRight} when + /// comparing keys. This key will never be generated directly, its main use is + /// in defining key maps. + static const LogicalKeyboardKey meta = LogicalKeyboardKey(0x002000001f6); + + /// Represents the logical "Numpad Enter" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpadEnter = LogicalKeyboardKey(0x0020000020d); + + /// Represents the logical "Numpad Paren Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpadParenLeft = LogicalKeyboardKey(0x00200000228); + + /// Represents the logical "Numpad Paren Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpadParenRight = LogicalKeyboardKey(0x00200000229); + + /// Represents the logical "Numpad Multiply" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpadMultiply = LogicalKeyboardKey(0x0020000022a); + + /// Represents the logical "Numpad Add" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpadAdd = LogicalKeyboardKey(0x0020000022b); + + /// Represents the logical "Numpad Comma" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpadComma = LogicalKeyboardKey(0x0020000022c); + + /// Represents the logical "Numpad Subtract" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpadSubtract = LogicalKeyboardKey(0x0020000022d); + + /// Represents the logical "Numpad Decimal" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpadDecimal = LogicalKeyboardKey(0x0020000022e); + + /// Represents the logical "Numpad Divide" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpadDivide = LogicalKeyboardKey(0x0020000022f); + + /// Represents the logical "Numpad 0" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpad0 = LogicalKeyboardKey(0x00200000230); + + /// Represents the logical "Numpad 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpad1 = LogicalKeyboardKey(0x00200000231); + + /// Represents the logical "Numpad 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpad2 = LogicalKeyboardKey(0x00200000232); + + /// Represents the logical "Numpad 3" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpad3 = LogicalKeyboardKey(0x00200000233); + + /// Represents the logical "Numpad 4" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpad4 = LogicalKeyboardKey(0x00200000234); + + /// Represents the logical "Numpad 5" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpad5 = LogicalKeyboardKey(0x00200000235); + + /// Represents the logical "Numpad 6" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpad6 = LogicalKeyboardKey(0x00200000236); + + /// Represents the logical "Numpad 7" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpad7 = LogicalKeyboardKey(0x00200000237); + + /// Represents the logical "Numpad 8" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpad8 = LogicalKeyboardKey(0x00200000238); + + /// Represents the logical "Numpad 9" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpad9 = LogicalKeyboardKey(0x00200000239); + + /// Represents the logical "Numpad Equal" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey numpadEqual = LogicalKeyboardKey(0x0020000023d); + + /// Represents the logical "Game Button 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton1 = LogicalKeyboardKey(0x00200000301); + + /// Represents the logical "Game Button 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton2 = LogicalKeyboardKey(0x00200000302); + + /// Represents the logical "Game Button 3" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton3 = LogicalKeyboardKey(0x00200000303); + + /// Represents the logical "Game Button 4" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton4 = LogicalKeyboardKey(0x00200000304); + + /// Represents the logical "Game Button 5" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton5 = LogicalKeyboardKey(0x00200000305); + + /// Represents the logical "Game Button 6" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton6 = LogicalKeyboardKey(0x00200000306); + + /// Represents the logical "Game Button 7" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton7 = LogicalKeyboardKey(0x00200000307); + + /// Represents the logical "Game Button 8" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton8 = LogicalKeyboardKey(0x00200000308); + + /// Represents the logical "Game Button 9" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton9 = LogicalKeyboardKey(0x00200000309); + + /// Represents the logical "Game Button 10" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton10 = LogicalKeyboardKey(0x0020000030a); + + /// Represents the logical "Game Button 11" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton11 = LogicalKeyboardKey(0x0020000030b); + + /// Represents the logical "Game Button 12" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton12 = LogicalKeyboardKey(0x0020000030c); + + /// Represents the logical "Game Button 13" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton13 = LogicalKeyboardKey(0x0020000030d); + + /// Represents the logical "Game Button 14" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton14 = LogicalKeyboardKey(0x0020000030e); + + /// Represents the logical "Game Button 15" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton15 = LogicalKeyboardKey(0x0020000030f); + + /// Represents the logical "Game Button 16" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButton16 = LogicalKeyboardKey(0x00200000310); + + /// Represents the logical "Game Button A" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonA = LogicalKeyboardKey(0x00200000311); + + /// Represents the logical "Game Button B" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonB = LogicalKeyboardKey(0x00200000312); + + /// Represents the logical "Game Button C" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonC = LogicalKeyboardKey(0x00200000313); + + /// Represents the logical "Game Button Left 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonLeft1 = LogicalKeyboardKey(0x00200000314); + + /// Represents the logical "Game Button Left 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonLeft2 = LogicalKeyboardKey(0x00200000315); + + /// Represents the logical "Game Button Mode" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonMode = LogicalKeyboardKey(0x00200000316); + + /// Represents the logical "Game Button Right 1" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonRight1 = LogicalKeyboardKey(0x00200000317); + + /// Represents the logical "Game Button Right 2" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonRight2 = LogicalKeyboardKey(0x00200000318); + + /// Represents the logical "Game Button Select" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonSelect = LogicalKeyboardKey(0x00200000319); + + /// Represents the logical "Game Button Start" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonStart = LogicalKeyboardKey(0x0020000031a); + + /// Represents the logical "Game Button Thumb Left" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonThumbLeft = LogicalKeyboardKey(0x0020000031b); + + /// Represents the logical "Game Button Thumb Right" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonThumbRight = LogicalKeyboardKey(0x0020000031c); + + /// Represents the logical "Game Button X" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonX = LogicalKeyboardKey(0x0020000031d); + + /// Represents the logical "Game Button Y" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonY = LogicalKeyboardKey(0x0020000031e); + + /// Represents the logical "Game Button Z" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey gameButtonZ = LogicalKeyboardKey(0x0020000031f); + + /// A list of all predefined constant [LogicalKeyboardKey]s. + static Iterable<LogicalKeyboardKey> get knownLogicalKeys => _knownLogicalKeys.values; + + // A list of all predefined constant LogicalKeyboardKeys so they can be + // searched. + static const Map<int, LogicalKeyboardKey> _knownLogicalKeys = <int, LogicalKeyboardKey>{ + 0x00000000020: space, + 0x00000000021: exclamation, + 0x00000000022: quote, + 0x00000000023: numberSign, + 0x00000000024: dollar, + 0x00000000025: percent, + 0x00000000026: ampersand, + 0x00000000027: quoteSingle, + 0x00000000028: parenthesisLeft, + 0x00000000029: parenthesisRight, + 0x0000000002a: asterisk, + 0x0000000002b: add, + 0x0000000002c: comma, + 0x0000000002d: minus, + 0x0000000002e: period, + 0x0000000002f: slash, + 0x00000000030: digit0, + 0x00000000031: digit1, + 0x00000000032: digit2, + 0x00000000033: digit3, + 0x00000000034: digit4, + 0x00000000035: digit5, + 0x00000000036: digit6, + 0x00000000037: digit7, + 0x00000000038: digit8, + 0x00000000039: digit9, + 0x0000000003a: colon, + 0x0000000003b: semicolon, + 0x0000000003c: less, + 0x0000000003d: equal, + 0x0000000003e: greater, + 0x0000000003f: question, + 0x00000000040: at, + 0x0000000005b: bracketLeft, + 0x0000000005c: backslash, + 0x0000000005d: bracketRight, + 0x0000000005e: caret, + 0x0000000005f: underscore, + 0x00000000060: backquote, + 0x00000000061: keyA, + 0x00000000062: keyB, + 0x00000000063: keyC, + 0x00000000064: keyD, + 0x00000000065: keyE, + 0x00000000066: keyF, + 0x00000000067: keyG, + 0x00000000068: keyH, + 0x00000000069: keyI, + 0x0000000006a: keyJ, + 0x0000000006b: keyK, + 0x0000000006c: keyL, + 0x0000000006d: keyM, + 0x0000000006e: keyN, + 0x0000000006f: keyO, + 0x00000000070: keyP, + 0x00000000071: keyQ, + 0x00000000072: keyR, + 0x00000000073: keyS, + 0x00000000074: keyT, + 0x00000000075: keyU, + 0x00000000076: keyV, + 0x00000000077: keyW, + 0x00000000078: keyX, + 0x00000000079: keyY, + 0x0000000007a: keyZ, + 0x0000000007b: braceLeft, + 0x0000000007c: bar, + 0x0000000007d: braceRight, + 0x0000000007e: tilde, + 0x00100000001: unidentified, + 0x00100000008: backspace, + 0x00100000009: tab, + 0x0010000000d: enter, + 0x0010000001b: escape, + 0x0010000007f: delete, + 0x00100000101: accel, + 0x00100000103: altGraph, + 0x00100000104: capsLock, + 0x00100000106: fn, + 0x00100000107: fnLock, + 0x00100000108: hyper, + 0x0010000010a: numLock, + 0x0010000010c: scrollLock, + 0x0010000010e: superKey, + 0x0010000010f: symbol, + 0x00100000110: symbolLock, + 0x00100000111: shiftLevel5, + 0x00100000301: arrowDown, + 0x00100000302: arrowLeft, + 0x00100000303: arrowRight, + 0x00100000304: arrowUp, + 0x00100000305: end, + 0x00100000306: home, + 0x00100000307: pageDown, + 0x00100000308: pageUp, + 0x00100000401: clear, + 0x00100000402: copy, + 0x00100000403: crSel, + 0x00100000404: cut, + 0x00100000405: eraseEof, + 0x00100000406: exSel, + 0x00100000407: insert, + 0x00100000408: paste, + 0x00100000409: redo, + 0x0010000040a: undo, + 0x00100000501: accept, + 0x00100000502: again, + 0x00100000503: attn, + 0x00100000504: cancel, + 0x00100000505: contextMenu, + 0x00100000506: execute, + 0x00100000507: find, + 0x00100000508: help, + 0x00100000509: pause, + 0x0010000050a: play, + 0x0010000050b: props, + 0x0010000050c: select, + 0x0010000050d: zoomIn, + 0x0010000050e: zoomOut, + 0x00100000601: brightnessDown, + 0x00100000602: brightnessUp, + 0x00100000603: camera, + 0x00100000604: eject, + 0x00100000605: logOff, + 0x00100000606: power, + 0x00100000607: powerOff, + 0x00100000608: printScreen, + 0x00100000609: hibernate, + 0x0010000060a: standby, + 0x0010000060b: wakeUp, + 0x00100000701: allCandidates, + 0x00100000702: alphanumeric, + 0x00100000703: codeInput, + 0x00100000704: compose, + 0x00100000705: convert, + 0x00100000706: finalMode, + 0x00100000707: groupFirst, + 0x00100000708: groupLast, + 0x00100000709: groupNext, + 0x0010000070a: groupPrevious, + 0x0010000070b: modeChange, + 0x0010000070c: nextCandidate, + 0x0010000070d: nonConvert, + 0x0010000070e: previousCandidate, + 0x0010000070f: process, + 0x00100000710: singleCandidate, + 0x00100000711: hangulMode, + 0x00100000712: hanjaMode, + 0x00100000713: junjaMode, + 0x00100000714: eisu, + 0x00100000715: hankaku, + 0x00100000716: hiragana, + 0x00100000717: hiraganaKatakana, + 0x00100000718: kanaMode, + 0x00100000719: kanjiMode, + 0x0010000071a: katakana, + 0x0010000071b: romaji, + 0x0010000071c: zenkaku, + 0x0010000071d: zenkakuHankaku, + 0x00100000801: f1, + 0x00100000802: f2, + 0x00100000803: f3, + 0x00100000804: f4, + 0x00100000805: f5, + 0x00100000806: f6, + 0x00100000807: f7, + 0x00100000808: f8, + 0x00100000809: f9, + 0x0010000080a: f10, + 0x0010000080b: f11, + 0x0010000080c: f12, + 0x0010000080d: f13, + 0x0010000080e: f14, + 0x0010000080f: f15, + 0x00100000810: f16, + 0x00100000811: f17, + 0x00100000812: f18, + 0x00100000813: f19, + 0x00100000814: f20, + 0x00100000815: f21, + 0x00100000816: f22, + 0x00100000817: f23, + 0x00100000818: f24, + 0x00100000901: soft1, + 0x00100000902: soft2, + 0x00100000903: soft3, + 0x00100000904: soft4, + 0x00100000905: soft5, + 0x00100000906: soft6, + 0x00100000907: soft7, + 0x00100000908: soft8, + 0x00100000a01: close, + 0x00100000a02: mailForward, + 0x00100000a03: mailReply, + 0x00100000a04: mailSend, + 0x00100000a05: mediaPlayPause, + 0x00100000a07: mediaStop, + 0x00100000a08: mediaTrackNext, + 0x00100000a09: mediaTrackPrevious, + 0x00100000a0a: newKey, + 0x00100000a0b: open, + 0x00100000a0c: print, + 0x00100000a0d: save, + 0x00100000a0e: spellCheck, + 0x00100000a0f: audioVolumeDown, + 0x00100000a10: audioVolumeUp, + 0x00100000a11: audioVolumeMute, + 0x00100000b01: launchApplication2, + 0x00100000b02: launchCalendar, + 0x00100000b03: launchMail, + 0x00100000b04: launchMediaPlayer, + 0x00100000b05: launchMusicPlayer, + 0x00100000b06: launchApplication1, + 0x00100000b07: launchScreenSaver, + 0x00100000b08: launchSpreadsheet, + 0x00100000b09: launchWebBrowser, + 0x00100000b0a: launchWebCam, + 0x00100000b0b: launchWordProcessor, + 0x00100000b0c: launchContacts, + 0x00100000b0d: launchPhone, + 0x00100000b0e: launchAssistant, + 0x00100000b0f: launchControlPanel, + 0x00100000c01: browserBack, + 0x00100000c02: browserFavorites, + 0x00100000c03: browserForward, + 0x00100000c04: browserHome, + 0x00100000c05: browserRefresh, + 0x00100000c06: browserSearch, + 0x00100000c07: browserStop, + 0x00100000d01: audioBalanceLeft, + 0x00100000d02: audioBalanceRight, + 0x00100000d03: audioBassBoostDown, + 0x00100000d04: audioBassBoostUp, + 0x00100000d05: audioFaderFront, + 0x00100000d06: audioFaderRear, + 0x00100000d07: audioSurroundModeNext, + 0x00100000d08: avrInput, + 0x00100000d09: avrPower, + 0x00100000d0a: channelDown, + 0x00100000d0b: channelUp, + 0x00100000d0c: colorF0Red, + 0x00100000d0d: colorF1Green, + 0x00100000d0e: colorF2Yellow, + 0x00100000d0f: colorF3Blue, + 0x00100000d10: colorF4Grey, + 0x00100000d11: colorF5Brown, + 0x00100000d12: closedCaptionToggle, + 0x00100000d13: dimmer, + 0x00100000d14: displaySwap, + 0x00100000d15: exit, + 0x00100000d16: favoriteClear0, + 0x00100000d17: favoriteClear1, + 0x00100000d18: favoriteClear2, + 0x00100000d19: favoriteClear3, + 0x00100000d1a: favoriteRecall0, + 0x00100000d1b: favoriteRecall1, + 0x00100000d1c: favoriteRecall2, + 0x00100000d1d: favoriteRecall3, + 0x00100000d1e: favoriteStore0, + 0x00100000d1f: favoriteStore1, + 0x00100000d20: favoriteStore2, + 0x00100000d21: favoriteStore3, + 0x00100000d22: guide, + 0x00100000d23: guideNextDay, + 0x00100000d24: guidePreviousDay, + 0x00100000d25: info, + 0x00100000d26: instantReplay, + 0x00100000d27: link, + 0x00100000d28: listProgram, + 0x00100000d29: liveContent, + 0x00100000d2a: lock, + 0x00100000d2b: mediaApps, + 0x00100000d2c: mediaFastForward, + 0x00100000d2d: mediaLast, + 0x00100000d2e: mediaPause, + 0x00100000d2f: mediaPlay, + 0x00100000d30: mediaRecord, + 0x00100000d31: mediaRewind, + 0x00100000d32: mediaSkip, + 0x00100000d33: nextFavoriteChannel, + 0x00100000d34: nextUserProfile, + 0x00100000d35: onDemand, + 0x00100000d36: pInPDown, + 0x00100000d37: pInPMove, + 0x00100000d38: pInPToggle, + 0x00100000d39: pInPUp, + 0x00100000d3a: playSpeedDown, + 0x00100000d3b: playSpeedReset, + 0x00100000d3c: playSpeedUp, + 0x00100000d3d: randomToggle, + 0x00100000d3e: rcLowBattery, + 0x00100000d3f: recordSpeedNext, + 0x00100000d40: rfBypass, + 0x00100000d41: scanChannelsToggle, + 0x00100000d42: screenModeNext, + 0x00100000d43: settings, + 0x00100000d44: splitScreenToggle, + 0x00100000d45: stbInput, + 0x00100000d46: stbPower, + 0x00100000d47: subtitle, + 0x00100000d48: teletext, + 0x00100000d49: tv, + 0x00100000d4a: tvInput, + 0x00100000d4b: tvPower, + 0x00100000d4c: videoModeNext, + 0x00100000d4d: wink, + 0x00100000d4e: zoomToggle, + 0x00100000d4f: dvr, + 0x00100000d50: mediaAudioTrack, + 0x00100000d51: mediaSkipBackward, + 0x00100000d52: mediaSkipForward, + 0x00100000d53: mediaStepBackward, + 0x00100000d54: mediaStepForward, + 0x00100000d55: mediaTopMenu, + 0x00100000d56: navigateIn, + 0x00100000d57: navigateNext, + 0x00100000d58: navigateOut, + 0x00100000d59: navigatePrevious, + 0x00100000d5a: pairing, + 0x00100000d5b: mediaClose, + 0x00100000e02: audioBassBoostToggle, + 0x00100000e04: audioTrebleDown, + 0x00100000e05: audioTrebleUp, + 0x00100000e06: microphoneToggle, + 0x00100000e07: microphoneVolumeDown, + 0x00100000e08: microphoneVolumeUp, + 0x00100000e09: microphoneVolumeMute, + 0x00100000f01: speechCorrectionList, + 0x00100000f02: speechInputToggle, + 0x00100001001: appSwitch, + 0x00100001002: call, + 0x00100001003: cameraFocus, + 0x00100001004: endCall, + 0x00100001005: goBack, + 0x00100001006: goHome, + 0x00100001007: headsetHook, + 0x00100001008: lastNumberRedial, + 0x00100001009: notification, + 0x0010000100a: mannerMode, + 0x0010000100b: voiceDial, + 0x00100001101: tv3DMode, + 0x00100001102: tvAntennaCable, + 0x00100001103: tvAudioDescription, + 0x00100001104: tvAudioDescriptionMixDown, + 0x00100001105: tvAudioDescriptionMixUp, + 0x00100001106: tvContentsMenu, + 0x00100001107: tvDataService, + 0x00100001108: tvInputComponent1, + 0x00100001109: tvInputComponent2, + 0x0010000110a: tvInputComposite1, + 0x0010000110b: tvInputComposite2, + 0x0010000110c: tvInputHDMI1, + 0x0010000110d: tvInputHDMI2, + 0x0010000110e: tvInputHDMI3, + 0x0010000110f: tvInputHDMI4, + 0x00100001110: tvInputVGA1, + 0x00100001111: tvMediaContext, + 0x00100001112: tvNetwork, + 0x00100001113: tvNumberEntry, + 0x00100001114: tvRadioService, + 0x00100001115: tvSatellite, + 0x00100001116: tvSatelliteBS, + 0x00100001117: tvSatelliteCS, + 0x00100001118: tvSatelliteToggle, + 0x00100001119: tvTerrestrialAnalog, + 0x0010000111a: tvTerrestrialDigital, + 0x0010000111b: tvTimer, + 0x00100001201: key11, + 0x00100001202: key12, + 0x00200000000: suspend, + 0x00200000001: resume, + 0x00200000002: sleep, + 0x00200000003: abort, + 0x00200000010: lang1, + 0x00200000011: lang2, + 0x00200000012: lang3, + 0x00200000013: lang4, + 0x00200000014: lang5, + 0x00200000020: intlBackslash, + 0x00200000021: intlRo, + 0x00200000022: intlYen, + 0x00200000100: controlLeft, + 0x00200000101: controlRight, + 0x00200000102: shiftLeft, + 0x00200000103: shiftRight, + 0x00200000104: altLeft, + 0x00200000105: altRight, + 0x00200000106: metaLeft, + 0x00200000107: metaRight, + 0x002000001f0: control, + 0x002000001f2: shift, + 0x002000001f4: alt, + 0x002000001f6: meta, + 0x0020000020d: numpadEnter, + 0x00200000228: numpadParenLeft, + 0x00200000229: numpadParenRight, + 0x0020000022a: numpadMultiply, + 0x0020000022b: numpadAdd, + 0x0020000022c: numpadComma, + 0x0020000022d: numpadSubtract, + 0x0020000022e: numpadDecimal, + 0x0020000022f: numpadDivide, + 0x00200000230: numpad0, + 0x00200000231: numpad1, + 0x00200000232: numpad2, + 0x00200000233: numpad3, + 0x00200000234: numpad4, + 0x00200000235: numpad5, + 0x00200000236: numpad6, + 0x00200000237: numpad7, + 0x00200000238: numpad8, + 0x00200000239: numpad9, + 0x0020000023d: numpadEqual, + 0x00200000301: gameButton1, + 0x00200000302: gameButton2, + 0x00200000303: gameButton3, + 0x00200000304: gameButton4, + 0x00200000305: gameButton5, + 0x00200000306: gameButton6, + 0x00200000307: gameButton7, + 0x00200000308: gameButton8, + 0x00200000309: gameButton9, + 0x0020000030a: gameButton10, + 0x0020000030b: gameButton11, + 0x0020000030c: gameButton12, + 0x0020000030d: gameButton13, + 0x0020000030e: gameButton14, + 0x0020000030f: gameButton15, + 0x00200000310: gameButton16, + 0x00200000311: gameButtonA, + 0x00200000312: gameButtonB, + 0x00200000313: gameButtonC, + 0x00200000314: gameButtonLeft1, + 0x00200000315: gameButtonLeft2, + 0x00200000316: gameButtonMode, + 0x00200000317: gameButtonRight1, + 0x00200000318: gameButtonRight2, + 0x00200000319: gameButtonSelect, + 0x0020000031a: gameButtonStart, + 0x0020000031b: gameButtonThumbLeft, + 0x0020000031c: gameButtonThumbRight, + 0x0020000031d: gameButtonX, + 0x0020000031e: gameButtonY, + 0x0020000031f: gameButtonZ, + }; + + // A map of keys to the pseudo-key synonym for that key. + static final Map<LogicalKeyboardKey, Set<LogicalKeyboardKey>> _synonyms = <LogicalKeyboardKey, Set<LogicalKeyboardKey>>{ + shiftLeft: <LogicalKeyboardKey>{shift}, + shiftRight: <LogicalKeyboardKey>{shift}, + metaLeft: <LogicalKeyboardKey>{meta}, + metaRight: <LogicalKeyboardKey>{meta}, + altLeft: <LogicalKeyboardKey>{alt}, + altRight: <LogicalKeyboardKey>{alt}, + controlLeft: <LogicalKeyboardKey>{control}, + controlRight: <LogicalKeyboardKey>{control}, + }; + + // A map of pseudo-key to the set of keys that are synonyms for that pseudo-key. + static final Map<LogicalKeyboardKey, Set<LogicalKeyboardKey>> _reverseSynonyms = <LogicalKeyboardKey, Set<LogicalKeyboardKey>>{ + shift: <LogicalKeyboardKey>{shiftLeft, shiftRight}, + meta: <LogicalKeyboardKey>{metaLeft, metaRight}, + alt: <LogicalKeyboardKey>{altLeft, altRight}, + control: <LogicalKeyboardKey>{controlLeft, controlRight}, + }; + + static const Map<int, String> _keyLabels = <int, String>{ + 0x00000000020: 'Space', + 0x00000000021: 'Exclamation', + 0x00000000022: 'Quote', + 0x00000000023: 'Number Sign', + 0x00000000024: 'Dollar', + 0x00000000025: 'Percent', + 0x00000000026: 'Ampersand', + 0x00000000027: 'Quote Single', + 0x00000000028: 'Parenthesis Left', + 0x00000000029: 'Parenthesis Right', + 0x0000000002a: 'Asterisk', + 0x0000000002b: 'Add', + 0x0000000002c: 'Comma', + 0x0000000002d: 'Minus', + 0x0000000002e: 'Period', + 0x0000000002f: 'Slash', + 0x00000000030: 'Digit 0', + 0x00000000031: 'Digit 1', + 0x00000000032: 'Digit 2', + 0x00000000033: 'Digit 3', + 0x00000000034: 'Digit 4', + 0x00000000035: 'Digit 5', + 0x00000000036: 'Digit 6', + 0x00000000037: 'Digit 7', + 0x00000000038: 'Digit 8', + 0x00000000039: 'Digit 9', + 0x0000000003a: 'Colon', + 0x0000000003b: 'Semicolon', + 0x0000000003c: 'Less', + 0x0000000003d: 'Equal', + 0x0000000003e: 'Greater', + 0x0000000003f: 'Question', + 0x00000000040: 'At', + 0x0000000005b: 'Bracket Left', + 0x0000000005c: 'Backslash', + 0x0000000005d: 'Bracket Right', + 0x0000000005e: 'Caret', + 0x0000000005f: 'Underscore', + 0x00000000060: 'Backquote', + 0x00000000061: 'Key A', + 0x00000000062: 'Key B', + 0x00000000063: 'Key C', + 0x00000000064: 'Key D', + 0x00000000065: 'Key E', + 0x00000000066: 'Key F', + 0x00000000067: 'Key G', + 0x00000000068: 'Key H', + 0x00000000069: 'Key I', + 0x0000000006a: 'Key J', + 0x0000000006b: 'Key K', + 0x0000000006c: 'Key L', + 0x0000000006d: 'Key M', + 0x0000000006e: 'Key N', + 0x0000000006f: 'Key O', + 0x00000000070: 'Key P', + 0x00000000071: 'Key Q', + 0x00000000072: 'Key R', + 0x00000000073: 'Key S', + 0x00000000074: 'Key T', + 0x00000000075: 'Key U', + 0x00000000076: 'Key V', + 0x00000000077: 'Key W', + 0x00000000078: 'Key X', + 0x00000000079: 'Key Y', + 0x0000000007a: 'Key Z', + 0x0000000007b: 'Brace Left', + 0x0000000007c: 'Bar', + 0x0000000007d: 'Brace Right', + 0x0000000007e: 'Tilde', + 0x00100000001: 'Unidentified', + 0x00100000008: 'Backspace', + 0x00100000009: 'Tab', + 0x0010000000d: 'Enter', + 0x0010000001b: 'Escape', + 0x0010000007f: 'Delete', + 0x00100000101: 'Accel', + 0x00100000103: 'Alt Graph', + 0x00100000104: 'Caps Lock', + 0x00100000106: 'Fn', + 0x00100000107: 'Fn Lock', + 0x00100000108: 'Hyper', + 0x0010000010a: 'Num Lock', + 0x0010000010c: 'Scroll Lock', + 0x0010000010e: 'Super', + 0x0010000010f: 'Symbol', + 0x00100000110: 'Symbol Lock', + 0x00100000111: 'Shift Level 5', + 0x00100000301: 'Arrow Down', + 0x00100000302: 'Arrow Left', + 0x00100000303: 'Arrow Right', + 0x00100000304: 'Arrow Up', + 0x00100000305: 'End', + 0x00100000306: 'Home', + 0x00100000307: 'Page Down', + 0x00100000308: 'Page Up', + 0x00100000401: 'Clear', + 0x00100000402: 'Copy', + 0x00100000403: 'Cr Sel', + 0x00100000404: 'Cut', + 0x00100000405: 'Erase Eof', + 0x00100000406: 'Ex Sel', + 0x00100000407: 'Insert', + 0x00100000408: 'Paste', + 0x00100000409: 'Redo', + 0x0010000040a: 'Undo', + 0x00100000501: 'Accept', + 0x00100000502: 'Again', + 0x00100000503: 'Attn', + 0x00100000504: 'Cancel', + 0x00100000505: 'Context Menu', + 0x00100000506: 'Execute', + 0x00100000507: 'Find', + 0x00100000508: 'Help', + 0x00100000509: 'Pause', + 0x0010000050a: 'Play', + 0x0010000050b: 'Props', + 0x0010000050c: 'Select', + 0x0010000050d: 'Zoom In', + 0x0010000050e: 'Zoom Out', + 0x00100000601: 'Brightness Down', + 0x00100000602: 'Brightness Up', + 0x00100000603: 'Camera', + 0x00100000604: 'Eject', + 0x00100000605: 'Log Off', + 0x00100000606: 'Power', + 0x00100000607: 'Power Off', + 0x00100000608: 'Print Screen', + 0x00100000609: 'Hibernate', + 0x0010000060a: 'Standby', + 0x0010000060b: 'Wake Up', + 0x00100000701: 'All Candidates', + 0x00100000702: 'Alphanumeric', + 0x00100000703: 'Code Input', + 0x00100000704: 'Compose', + 0x00100000705: 'Convert', + 0x00100000706: 'Final Mode', + 0x00100000707: 'Group First', + 0x00100000708: 'Group Last', + 0x00100000709: 'Group Next', + 0x0010000070a: 'Group Previous', + 0x0010000070b: 'Mode Change', + 0x0010000070c: 'Next Candidate', + 0x0010000070d: 'Non Convert', + 0x0010000070e: 'Previous Candidate', + 0x0010000070f: 'Process', + 0x00100000710: 'Single Candidate', + 0x00100000711: 'Hangul Mode', + 0x00100000712: 'Hanja Mode', + 0x00100000713: 'Junja Mode', + 0x00100000714: 'Eisu', + 0x00100000715: 'Hankaku', + 0x00100000716: 'Hiragana', + 0x00100000717: 'Hiragana Katakana', + 0x00100000718: 'Kana Mode', + 0x00100000719: 'Kanji Mode', + 0x0010000071a: 'Katakana', + 0x0010000071b: 'Romaji', + 0x0010000071c: 'Zenkaku', + 0x0010000071d: 'Zenkaku Hankaku', + 0x00100000801: 'F1', + 0x00100000802: 'F2', + 0x00100000803: 'F3', + 0x00100000804: 'F4', + 0x00100000805: 'F5', + 0x00100000806: 'F6', + 0x00100000807: 'F7', + 0x00100000808: 'F8', + 0x00100000809: 'F9', + 0x0010000080a: 'F10', + 0x0010000080b: 'F11', + 0x0010000080c: 'F12', + 0x0010000080d: 'F13', + 0x0010000080e: 'F14', + 0x0010000080f: 'F15', + 0x00100000810: 'F16', + 0x00100000811: 'F17', + 0x00100000812: 'F18', + 0x00100000813: 'F19', + 0x00100000814: 'F20', + 0x00100000815: 'F21', + 0x00100000816: 'F22', + 0x00100000817: 'F23', + 0x00100000818: 'F24', + 0x00100000901: 'Soft 1', + 0x00100000902: 'Soft 2', + 0x00100000903: 'Soft 3', + 0x00100000904: 'Soft 4', + 0x00100000905: 'Soft 5', + 0x00100000906: 'Soft 6', + 0x00100000907: 'Soft 7', + 0x00100000908: 'Soft 8', + 0x00100000a01: 'Close', + 0x00100000a02: 'Mail Forward', + 0x00100000a03: 'Mail Reply', + 0x00100000a04: 'Mail Send', + 0x00100000a05: 'Media Play Pause', + 0x00100000a07: 'Media Stop', + 0x00100000a08: 'Media Track Next', + 0x00100000a09: 'Media Track Previous', + 0x00100000a0a: 'New', + 0x00100000a0b: 'Open', + 0x00100000a0c: 'Print', + 0x00100000a0d: 'Save', + 0x00100000a0e: 'Spell Check', + 0x00100000a0f: 'Audio Volume Down', + 0x00100000a10: 'Audio Volume Up', + 0x00100000a11: 'Audio Volume Mute', + 0x00100000b01: 'Launch Application 2', + 0x00100000b02: 'Launch Calendar', + 0x00100000b03: 'Launch Mail', + 0x00100000b04: 'Launch Media Player', + 0x00100000b05: 'Launch Music Player', + 0x00100000b06: 'Launch Application 1', + 0x00100000b07: 'Launch Screen Saver', + 0x00100000b08: 'Launch Spreadsheet', + 0x00100000b09: 'Launch Web Browser', + 0x00100000b0a: 'Launch Web Cam', + 0x00100000b0b: 'Launch Word Processor', + 0x00100000b0c: 'Launch Contacts', + 0x00100000b0d: 'Launch Phone', + 0x00100000b0e: 'Launch Assistant', + 0x00100000b0f: 'Launch Control Panel', + 0x00100000c01: 'Browser Back', + 0x00100000c02: 'Browser Favorites', + 0x00100000c03: 'Browser Forward', + 0x00100000c04: 'Browser Home', + 0x00100000c05: 'Browser Refresh', + 0x00100000c06: 'Browser Search', + 0x00100000c07: 'Browser Stop', + 0x00100000d01: 'Audio Balance Left', + 0x00100000d02: 'Audio Balance Right', + 0x00100000d03: 'Audio Bass Boost Down', + 0x00100000d04: 'Audio Bass Boost Up', + 0x00100000d05: 'Audio Fader Front', + 0x00100000d06: 'Audio Fader Rear', + 0x00100000d07: 'Audio Surround Mode Next', + 0x00100000d08: 'AVR Input', + 0x00100000d09: 'AVR Power', + 0x00100000d0a: 'Channel Down', + 0x00100000d0b: 'Channel Up', + 0x00100000d0c: 'Color F0 Red', + 0x00100000d0d: 'Color F1 Green', + 0x00100000d0e: 'Color F2 Yellow', + 0x00100000d0f: 'Color F3 Blue', + 0x00100000d10: 'Color F4 Grey', + 0x00100000d11: 'Color F5 Brown', + 0x00100000d12: 'Closed Caption Toggle', + 0x00100000d13: 'Dimmer', + 0x00100000d14: 'Display Swap', + 0x00100000d15: 'Exit', + 0x00100000d16: 'Favorite Clear 0', + 0x00100000d17: 'Favorite Clear 1', + 0x00100000d18: 'Favorite Clear 2', + 0x00100000d19: 'Favorite Clear 3', + 0x00100000d1a: 'Favorite Recall 0', + 0x00100000d1b: 'Favorite Recall 1', + 0x00100000d1c: 'Favorite Recall 2', + 0x00100000d1d: 'Favorite Recall 3', + 0x00100000d1e: 'Favorite Store 0', + 0x00100000d1f: 'Favorite Store 1', + 0x00100000d20: 'Favorite Store 2', + 0x00100000d21: 'Favorite Store 3', + 0x00100000d22: 'Guide', + 0x00100000d23: 'Guide Next Day', + 0x00100000d24: 'Guide Previous Day', + 0x00100000d25: 'Info', + 0x00100000d26: 'Instant Replay', + 0x00100000d27: 'Link', + 0x00100000d28: 'List Program', + 0x00100000d29: 'Live Content', + 0x00100000d2a: 'Lock', + 0x00100000d2b: 'Media Apps', + 0x00100000d2c: 'Media Fast Forward', + 0x00100000d2d: 'Media Last', + 0x00100000d2e: 'Media Pause', + 0x00100000d2f: 'Media Play', + 0x00100000d30: 'Media Record', + 0x00100000d31: 'Media Rewind', + 0x00100000d32: 'Media Skip', + 0x00100000d33: 'Next Favorite Channel', + 0x00100000d34: 'Next User Profile', + 0x00100000d35: 'On Demand', + 0x00100000d36: 'P In P Down', + 0x00100000d37: 'P In P Move', + 0x00100000d38: 'P In P Toggle', + 0x00100000d39: 'P In P Up', + 0x00100000d3a: 'Play Speed Down', + 0x00100000d3b: 'Play Speed Reset', + 0x00100000d3c: 'Play Speed Up', + 0x00100000d3d: 'Random Toggle', + 0x00100000d3e: 'Rc Low Battery', + 0x00100000d3f: 'Record Speed Next', + 0x00100000d40: 'Rf Bypass', + 0x00100000d41: 'Scan Channels Toggle', + 0x00100000d42: 'Screen Mode Next', + 0x00100000d43: 'Settings', + 0x00100000d44: 'Split Screen Toggle', + 0x00100000d45: 'STB Input', + 0x00100000d46: 'STB Power', + 0x00100000d47: 'Subtitle', + 0x00100000d48: 'Teletext', + 0x00100000d49: 'TV', + 0x00100000d4a: 'TV Input', + 0x00100000d4b: 'TV Power', + 0x00100000d4c: 'Video Mode Next', + 0x00100000d4d: 'Wink', + 0x00100000d4e: 'Zoom Toggle', + 0x00100000d4f: 'DVR', + 0x00100000d50: 'Media Audio Track', + 0x00100000d51: 'Media Skip Backward', + 0x00100000d52: 'Media Skip Forward', + 0x00100000d53: 'Media Step Backward', + 0x00100000d54: 'Media Step Forward', + 0x00100000d55: 'Media Top Menu', + 0x00100000d56: 'Navigate In', + 0x00100000d57: 'Navigate Next', + 0x00100000d58: 'Navigate Out', + 0x00100000d59: 'Navigate Previous', + 0x00100000d5a: 'Pairing', + 0x00100000d5b: 'Media Close', + 0x00100000e02: 'Audio Bass Boost Toggle', + 0x00100000e04: 'Audio Treble Down', + 0x00100000e05: 'Audio Treble Up', + 0x00100000e06: 'Microphone Toggle', + 0x00100000e07: 'Microphone Volume Down', + 0x00100000e08: 'Microphone Volume Up', + 0x00100000e09: 'Microphone Volume Mute', + 0x00100000f01: 'Speech Correction List', + 0x00100000f02: 'Speech Input Toggle', + 0x00100001001: 'App Switch', + 0x00100001002: 'Call', + 0x00100001003: 'Camera Focus', + 0x00100001004: 'End Call', + 0x00100001005: 'Go Back', + 0x00100001006: 'Go Home', + 0x00100001007: 'Headset Hook', + 0x00100001008: 'Last Number Redial', + 0x00100001009: 'Notification', + 0x0010000100a: 'Manner Mode', + 0x0010000100b: 'Voice Dial', + 0x00100001101: 'TV 3 D Mode', + 0x00100001102: 'TV Antenna Cable', + 0x00100001103: 'TV Audio Description', + 0x00100001104: 'TV Audio Description Mix Down', + 0x00100001105: 'TV Audio Description Mix Up', + 0x00100001106: 'TV Contents Menu', + 0x00100001107: 'TV Data Service', + 0x00100001108: 'TV Input Component 1', + 0x00100001109: 'TV Input Component 2', + 0x0010000110a: 'TV Input Composite 1', + 0x0010000110b: 'TV Input Composite 2', + 0x0010000110c: 'TV Input HDMI 1', + 0x0010000110d: 'TV Input HDMI 2', + 0x0010000110e: 'TV Input HDMI 3', + 0x0010000110f: 'TV Input HDMI 4', + 0x00100001110: 'TV Input VGA 1', + 0x00100001111: 'TV Media Context', + 0x00100001112: 'TV Network', + 0x00100001113: 'TV Number Entry', + 0x00100001114: 'TV Radio Service', + 0x00100001115: 'TV Satellite', + 0x00100001116: 'TV Satellite BS', + 0x00100001117: 'TV Satellite CS', + 0x00100001118: 'TV Satellite Toggle', + 0x00100001119: 'TV Terrestrial Analog', + 0x0010000111a: 'TV Terrestrial Digital', + 0x0010000111b: 'TV Timer', + 0x00100001201: 'Key 11', + 0x00100001202: 'Key 12', + 0x00200000000: 'Suspend', + 0x00200000001: 'Resume', + 0x00200000002: 'Sleep', + 0x00200000003: 'Abort', + 0x00200000010: 'Lang 1', + 0x00200000011: 'Lang 2', + 0x00200000012: 'Lang 3', + 0x00200000013: 'Lang 4', + 0x00200000014: 'Lang 5', + 0x00200000020: 'Intl Backslash', + 0x00200000021: 'Intl Ro', + 0x00200000022: 'Intl Yen', + 0x00200000100: 'Control Left', + 0x00200000101: 'Control Right', + 0x00200000102: 'Shift Left', + 0x00200000103: 'Shift Right', + 0x00200000104: 'Alt Left', + 0x00200000105: 'Alt Right', + 0x00200000106: 'Meta Left', + 0x00200000107: 'Meta Right', + 0x002000001f0: 'Control', + 0x002000001f2: 'Shift', + 0x002000001f4: 'Alt', + 0x002000001f6: 'Meta', + 0x0020000020d: 'Numpad Enter', + 0x00200000228: 'Numpad Paren Left', + 0x00200000229: 'Numpad Paren Right', + 0x0020000022a: 'Numpad Multiply', + 0x0020000022b: 'Numpad Add', + 0x0020000022c: 'Numpad Comma', + 0x0020000022d: 'Numpad Subtract', + 0x0020000022e: 'Numpad Decimal', + 0x0020000022f: 'Numpad Divide', + 0x00200000230: 'Numpad 0', + 0x00200000231: 'Numpad 1', + 0x00200000232: 'Numpad 2', + 0x00200000233: 'Numpad 3', + 0x00200000234: 'Numpad 4', + 0x00200000235: 'Numpad 5', + 0x00200000236: 'Numpad 6', + 0x00200000237: 'Numpad 7', + 0x00200000238: 'Numpad 8', + 0x00200000239: 'Numpad 9', + 0x0020000023d: 'Numpad Equal', + 0x00200000301: 'Game Button 1', + 0x00200000302: 'Game Button 2', + 0x00200000303: 'Game Button 3', + 0x00200000304: 'Game Button 4', + 0x00200000305: 'Game Button 5', + 0x00200000306: 'Game Button 6', + 0x00200000307: 'Game Button 7', + 0x00200000308: 'Game Button 8', + 0x00200000309: 'Game Button 9', + 0x0020000030a: 'Game Button 10', + 0x0020000030b: 'Game Button 11', + 0x0020000030c: 'Game Button 12', + 0x0020000030d: 'Game Button 13', + 0x0020000030e: 'Game Button 14', + 0x0020000030f: 'Game Button 15', + 0x00200000310: 'Game Button 16', + 0x00200000311: 'Game Button A', + 0x00200000312: 'Game Button B', + 0x00200000313: 'Game Button C', + 0x00200000314: 'Game Button Left 1', + 0x00200000315: 'Game Button Left 2', + 0x00200000316: 'Game Button Mode', + 0x00200000317: 'Game Button Right 1', + 0x00200000318: 'Game Button Right 2', + 0x00200000319: 'Game Button Select', + 0x0020000031a: 'Game Button Start', + 0x0020000031b: 'Game Button Thumb Left', + 0x0020000031c: 'Game Button Thumb Right', + 0x0020000031d: 'Game Button X', + 0x0020000031e: 'Game Button Y', + 0x0020000031f: 'Game Button Z', + }; +} + +/// A class with static values that describe the keys that are returned from +/// [RawKeyEvent.physicalKey]. +/// +/// These represent *physical* keys, which are keys which represent a particular +/// key location on a QWERTY keyboard. It ignores any modifiers, modes, or +/// keyboard layouts which may be in effect. This is contrast to +/// [LogicalKeyboardKey], which represents a logical key interpreted in the +/// context of modifiers, modes, and/or keyboard layouts. +/// +/// As an example, if you wanted a game where the key next to the CAPS LOCK (the +/// "A" key on a QWERTY keyboard) moved the player to the left, you'd want to +/// look at the physical key to make sure that regardless of the character the +/// key produces, you got the key that is in that location on the keyboard. +/// +/// Conversely, if you wanted to implement an app where the "Q" key "quit" +/// something, you'd want to look at the logical key to detect this, since you +/// would like to have it match the key with "Q" on it, instead of always +/// looking for "the key next to the TAB key", since on a French keyboard, +/// the key next to the TAB key has an "A" on it. +/// +/// {@tool dartpad} +/// This example shows how to detect if the user has selected the physical key +/// to the right of the CAPS LOCK key. +/// +/// ** See code in examples/api/lib/services/keyboard_key/physical_keyboard_key.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [RawKeyEvent], the keyboard event object received by widgets that listen +/// to keyboard events. +/// * [Focus.onKey], the handler on a widget that lets you handle key events. +/// * [RawKeyboardListener], a widget used to listen to keyboard events (but +/// not handle them). +@immutable +class PhysicalKeyboardKey extends KeyboardKey { + /// Creates a new PhysicalKeyboardKey object for a USB HID usage. + const PhysicalKeyboardKey(this.usbHidUsage); + + /// The unique USB HID usage ID of this physical key on the keyboard. + /// + /// Due to the variations in platform APIs, this may not be the actual HID + /// usage code from the hardware, but a value derived from available + /// information on the platform. + /// + /// See <https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf> + /// for the HID usage values and their meanings. + final int usbHidUsage; + + /// The debug string to print for this keyboard key, which will be null in + /// release mode. + String? get debugName { + String? result; + assert(() { + result = _debugNames[usbHidUsage] ?? + 'Key with ID 0x${usbHidUsage.toRadixString(16).padLeft(8, '0')}'; + return true; + }()); + return result; + } + + @override + int get hashCode => usbHidUsage.hashCode; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is PhysicalKeyboardKey + && other.usbHidUsage == usbHidUsage; + } + + /// Finds a known [PhysicalKeyboardKey] that matches the given USB HID usage + /// code. + static PhysicalKeyboardKey? findKeyByCode(int usageCode) => _knownPhysicalKeys[usageCode]; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('usbHidUsage', '0x${usbHidUsage.toRadixString(16).padLeft(8, '0')}')); + properties.add(StringProperty('debugName', debugName, defaultValue: null)); + } + + // Key constants for all keyboard keys in the USB HID specification at the + // time Flutter was built. + + /// Represents the location of the "Hyper" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey hyper = PhysicalKeyboardKey(0x00000010); + + /// Represents the location of the "Super Key" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey superKey = PhysicalKeyboardKey(0x00000011); + + /// Represents the location of the "Fn" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey fn = PhysicalKeyboardKey(0x00000012); + + /// Represents the location of the "Fn Lock" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey fnLock = PhysicalKeyboardKey(0x00000013); + + /// Represents the location of the "Suspend" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey suspend = PhysicalKeyboardKey(0x00000014); + + /// Represents the location of the "Resume" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey resume = PhysicalKeyboardKey(0x00000015); + + /// Represents the location of the "Turbo" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey turbo = PhysicalKeyboardKey(0x00000016); + + /// Represents the location of the "Privacy Screen Toggle" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey privacyScreenToggle = PhysicalKeyboardKey(0x00000017); + + /// Represents the location of the "Microphone Mute Toggle" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey microphoneMuteToggle = PhysicalKeyboardKey(0x00000018); + + /// Represents the location of the "Sleep" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey sleep = PhysicalKeyboardKey(0x00010082); + + /// Represents the location of the "Wake Up" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey wakeUp = PhysicalKeyboardKey(0x00010083); + + /// Represents the location of the "Display Toggle Int Ext" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey displayToggleIntExt = PhysicalKeyboardKey(0x000100b5); + + /// Represents the location of the "Game Button 1" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton1 = PhysicalKeyboardKey(0x0005ff01); + + /// Represents the location of the "Game Button 2" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton2 = PhysicalKeyboardKey(0x0005ff02); + + /// Represents the location of the "Game Button 3" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton3 = PhysicalKeyboardKey(0x0005ff03); + + /// Represents the location of the "Game Button 4" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton4 = PhysicalKeyboardKey(0x0005ff04); + + /// Represents the location of the "Game Button 5" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton5 = PhysicalKeyboardKey(0x0005ff05); + + /// Represents the location of the "Game Button 6" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton6 = PhysicalKeyboardKey(0x0005ff06); + + /// Represents the location of the "Game Button 7" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton7 = PhysicalKeyboardKey(0x0005ff07); + + /// Represents the location of the "Game Button 8" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton8 = PhysicalKeyboardKey(0x0005ff08); + + /// Represents the location of the "Game Button 9" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton9 = PhysicalKeyboardKey(0x0005ff09); + + /// Represents the location of the "Game Button 10" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton10 = PhysicalKeyboardKey(0x0005ff0a); + + /// Represents the location of the "Game Button 11" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton11 = PhysicalKeyboardKey(0x0005ff0b); + + /// Represents the location of the "Game Button 12" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton12 = PhysicalKeyboardKey(0x0005ff0c); + + /// Represents the location of the "Game Button 13" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton13 = PhysicalKeyboardKey(0x0005ff0d); + + /// Represents the location of the "Game Button 14" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton14 = PhysicalKeyboardKey(0x0005ff0e); + + /// Represents the location of the "Game Button 15" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton15 = PhysicalKeyboardKey(0x0005ff0f); + + /// Represents the location of the "Game Button 16" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButton16 = PhysicalKeyboardKey(0x0005ff10); + + /// Represents the location of the "Game Button A" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonA = PhysicalKeyboardKey(0x0005ff11); + + /// Represents the location of the "Game Button B" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonB = PhysicalKeyboardKey(0x0005ff12); + + /// Represents the location of the "Game Button C" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonC = PhysicalKeyboardKey(0x0005ff13); + + /// Represents the location of the "Game Button Left 1" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonLeft1 = PhysicalKeyboardKey(0x0005ff14); + + /// Represents the location of the "Game Button Left 2" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonLeft2 = PhysicalKeyboardKey(0x0005ff15); + + /// Represents the location of the "Game Button Mode" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonMode = PhysicalKeyboardKey(0x0005ff16); + + /// Represents the location of the "Game Button Right 1" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonRight1 = PhysicalKeyboardKey(0x0005ff17); + + /// Represents the location of the "Game Button Right 2" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonRight2 = PhysicalKeyboardKey(0x0005ff18); + + /// Represents the location of the "Game Button Select" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonSelect = PhysicalKeyboardKey(0x0005ff19); + + /// Represents the location of the "Game Button Start" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonStart = PhysicalKeyboardKey(0x0005ff1a); + + /// Represents the location of the "Game Button Thumb Left" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonThumbLeft = PhysicalKeyboardKey(0x0005ff1b); + + /// Represents the location of the "Game Button Thumb Right" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonThumbRight = PhysicalKeyboardKey(0x0005ff1c); + + /// Represents the location of the "Game Button X" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonX = PhysicalKeyboardKey(0x0005ff1d); + + /// Represents the location of the "Game Button Y" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonY = PhysicalKeyboardKey(0x0005ff1e); + + /// Represents the location of the "Game Button Z" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey gameButtonZ = PhysicalKeyboardKey(0x0005ff1f); + + /// Represents the location of the "Usb Reserved" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey usbReserved = PhysicalKeyboardKey(0x00070000); + + /// Represents the location of the "Usb Error Roll Over" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey usbErrorRollOver = PhysicalKeyboardKey(0x00070001); + + /// Represents the location of the "Usb Post Fail" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey usbPostFail = PhysicalKeyboardKey(0x00070002); + + /// Represents the location of the "Usb Error Undefined" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey usbErrorUndefined = PhysicalKeyboardKey(0x00070003); + + /// Represents the location of the "Key A" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyA = PhysicalKeyboardKey(0x00070004); + + /// Represents the location of the "Key B" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyB = PhysicalKeyboardKey(0x00070005); + + /// Represents the location of the "Key C" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyC = PhysicalKeyboardKey(0x00070006); + + /// Represents the location of the "Key D" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyD = PhysicalKeyboardKey(0x00070007); + + /// Represents the location of the "Key E" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyE = PhysicalKeyboardKey(0x00070008); + + /// Represents the location of the "Key F" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyF = PhysicalKeyboardKey(0x00070009); + + /// Represents the location of the "Key G" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyG = PhysicalKeyboardKey(0x0007000a); + + /// Represents the location of the "Key H" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyH = PhysicalKeyboardKey(0x0007000b); + + /// Represents the location of the "Key I" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyI = PhysicalKeyboardKey(0x0007000c); + + /// Represents the location of the "Key J" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyJ = PhysicalKeyboardKey(0x0007000d); + + /// Represents the location of the "Key K" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyK = PhysicalKeyboardKey(0x0007000e); + + /// Represents the location of the "Key L" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyL = PhysicalKeyboardKey(0x0007000f); + + /// Represents the location of the "Key M" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyM = PhysicalKeyboardKey(0x00070010); + + /// Represents the location of the "Key N" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyN = PhysicalKeyboardKey(0x00070011); + + /// Represents the location of the "Key O" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyO = PhysicalKeyboardKey(0x00070012); + + /// Represents the location of the "Key P" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyP = PhysicalKeyboardKey(0x00070013); + + /// Represents the location of the "Key Q" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyQ = PhysicalKeyboardKey(0x00070014); + + /// Represents the location of the "Key R" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyR = PhysicalKeyboardKey(0x00070015); + + /// Represents the location of the "Key S" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyS = PhysicalKeyboardKey(0x00070016); + + /// Represents the location of the "Key T" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyT = PhysicalKeyboardKey(0x00070017); + + /// Represents the location of the "Key U" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyU = PhysicalKeyboardKey(0x00070018); + + /// Represents the location of the "Key V" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyV = PhysicalKeyboardKey(0x00070019); + + /// Represents the location of the "Key W" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyW = PhysicalKeyboardKey(0x0007001a); + + /// Represents the location of the "Key X" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyX = PhysicalKeyboardKey(0x0007001b); + + /// Represents the location of the "Key Y" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyY = PhysicalKeyboardKey(0x0007001c); + + /// Represents the location of the "Key Z" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyZ = PhysicalKeyboardKey(0x0007001d); + + /// Represents the location of the "Digit 1" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey digit1 = PhysicalKeyboardKey(0x0007001e); + + /// Represents the location of the "Digit 2" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey digit2 = PhysicalKeyboardKey(0x0007001f); + + /// Represents the location of the "Digit 3" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey digit3 = PhysicalKeyboardKey(0x00070020); + + /// Represents the location of the "Digit 4" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey digit4 = PhysicalKeyboardKey(0x00070021); + + /// Represents the location of the "Digit 5" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey digit5 = PhysicalKeyboardKey(0x00070022); + + /// Represents the location of the "Digit 6" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey digit6 = PhysicalKeyboardKey(0x00070023); + + /// Represents the location of the "Digit 7" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey digit7 = PhysicalKeyboardKey(0x00070024); + + /// Represents the location of the "Digit 8" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey digit8 = PhysicalKeyboardKey(0x00070025); + + /// Represents the location of the "Digit 9" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey digit9 = PhysicalKeyboardKey(0x00070026); + + /// Represents the location of the "Digit 0" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey digit0 = PhysicalKeyboardKey(0x00070027); + + /// Represents the location of the "Enter" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey enter = PhysicalKeyboardKey(0x00070028); + + /// Represents the location of the "Escape" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey escape = PhysicalKeyboardKey(0x00070029); + + /// Represents the location of the "Backspace" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey backspace = PhysicalKeyboardKey(0x0007002a); + + /// Represents the location of the "Tab" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey tab = PhysicalKeyboardKey(0x0007002b); + + /// Represents the location of the "Space" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey space = PhysicalKeyboardKey(0x0007002c); + + /// Represents the location of the "Minus" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey minus = PhysicalKeyboardKey(0x0007002d); + + /// Represents the location of the "Equal" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey equal = PhysicalKeyboardKey(0x0007002e); + + /// Represents the location of the "Bracket Left" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey bracketLeft = PhysicalKeyboardKey(0x0007002f); + + /// Represents the location of the "Bracket Right" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey bracketRight = PhysicalKeyboardKey(0x00070030); + + /// Represents the location of the "Backslash" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey backslash = PhysicalKeyboardKey(0x00070031); + + /// Represents the location of the "Semicolon" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey semicolon = PhysicalKeyboardKey(0x00070033); + + /// Represents the location of the "Quote" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey quote = PhysicalKeyboardKey(0x00070034); + + /// Represents the location of the "Backquote" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey backquote = PhysicalKeyboardKey(0x00070035); + + /// Represents the location of the "Comma" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey comma = PhysicalKeyboardKey(0x00070036); + + /// Represents the location of the "Period" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey period = PhysicalKeyboardKey(0x00070037); + + /// Represents the location of the "Slash" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey slash = PhysicalKeyboardKey(0x00070038); + + /// Represents the location of the "Caps Lock" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey capsLock = PhysicalKeyboardKey(0x00070039); + + /// Represents the location of the "F1" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f1 = PhysicalKeyboardKey(0x0007003a); + + /// Represents the location of the "F2" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f2 = PhysicalKeyboardKey(0x0007003b); + + /// Represents the location of the "F3" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f3 = PhysicalKeyboardKey(0x0007003c); + + /// Represents the location of the "F4" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f4 = PhysicalKeyboardKey(0x0007003d); + + /// Represents the location of the "F5" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f5 = PhysicalKeyboardKey(0x0007003e); + + /// Represents the location of the "F6" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f6 = PhysicalKeyboardKey(0x0007003f); + + /// Represents the location of the "F7" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f7 = PhysicalKeyboardKey(0x00070040); + + /// Represents the location of the "F8" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f8 = PhysicalKeyboardKey(0x00070041); + + /// Represents the location of the "F9" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f9 = PhysicalKeyboardKey(0x00070042); + + /// Represents the location of the "F10" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f10 = PhysicalKeyboardKey(0x00070043); + + /// Represents the location of the "F11" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f11 = PhysicalKeyboardKey(0x00070044); + + /// Represents the location of the "F12" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f12 = PhysicalKeyboardKey(0x00070045); + + /// Represents the location of the "Print Screen" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey printScreen = PhysicalKeyboardKey(0x00070046); + + /// Represents the location of the "Scroll Lock" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey scrollLock = PhysicalKeyboardKey(0x00070047); + + /// Represents the location of the "Pause" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey pause = PhysicalKeyboardKey(0x00070048); + + /// Represents the location of the "Insert" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey insert = PhysicalKeyboardKey(0x00070049); + + /// Represents the location of the "Home" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey home = PhysicalKeyboardKey(0x0007004a); + + /// Represents the location of the "Page Up" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey pageUp = PhysicalKeyboardKey(0x0007004b); + + /// Represents the location of the "Delete" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey delete = PhysicalKeyboardKey(0x0007004c); + + /// Represents the location of the "End" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey end = PhysicalKeyboardKey(0x0007004d); + + /// Represents the location of the "Page Down" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey pageDown = PhysicalKeyboardKey(0x0007004e); + + /// Represents the location of the "Arrow Right" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey arrowRight = PhysicalKeyboardKey(0x0007004f); + + /// Represents the location of the "Arrow Left" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey arrowLeft = PhysicalKeyboardKey(0x00070050); + + /// Represents the location of the "Arrow Down" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey arrowDown = PhysicalKeyboardKey(0x00070051); + + /// Represents the location of the "Arrow Up" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey arrowUp = PhysicalKeyboardKey(0x00070052); + + /// Represents the location of the "Num Lock" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numLock = PhysicalKeyboardKey(0x00070053); + + /// Represents the location of the "Numpad Divide" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadDivide = PhysicalKeyboardKey(0x00070054); + + /// Represents the location of the "Numpad Multiply" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadMultiply = PhysicalKeyboardKey(0x00070055); + + /// Represents the location of the "Numpad Subtract" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadSubtract = PhysicalKeyboardKey(0x00070056); + + /// Represents the location of the "Numpad Add" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadAdd = PhysicalKeyboardKey(0x00070057); + + /// Represents the location of the "Numpad Enter" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadEnter = PhysicalKeyboardKey(0x00070058); + + /// Represents the location of the "Numpad 1" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpad1 = PhysicalKeyboardKey(0x00070059); + + /// Represents the location of the "Numpad 2" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpad2 = PhysicalKeyboardKey(0x0007005a); + + /// Represents the location of the "Numpad 3" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpad3 = PhysicalKeyboardKey(0x0007005b); + + /// Represents the location of the "Numpad 4" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpad4 = PhysicalKeyboardKey(0x0007005c); + + /// Represents the location of the "Numpad 5" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpad5 = PhysicalKeyboardKey(0x0007005d); + + /// Represents the location of the "Numpad 6" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpad6 = PhysicalKeyboardKey(0x0007005e); + + /// Represents the location of the "Numpad 7" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpad7 = PhysicalKeyboardKey(0x0007005f); + + /// Represents the location of the "Numpad 8" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpad8 = PhysicalKeyboardKey(0x00070060); + + /// Represents the location of the "Numpad 9" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpad9 = PhysicalKeyboardKey(0x00070061); + + /// Represents the location of the "Numpad 0" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpad0 = PhysicalKeyboardKey(0x00070062); + + /// Represents the location of the "Numpad Decimal" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadDecimal = PhysicalKeyboardKey(0x00070063); + + /// Represents the location of the "Intl Backslash" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey intlBackslash = PhysicalKeyboardKey(0x00070064); + + /// Represents the location of the "Context Menu" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey contextMenu = PhysicalKeyboardKey(0x00070065); + + /// Represents the location of the "Power" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey power = PhysicalKeyboardKey(0x00070066); + + /// Represents the location of the "Numpad Equal" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadEqual = PhysicalKeyboardKey(0x00070067); + + /// Represents the location of the "F13" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f13 = PhysicalKeyboardKey(0x00070068); + + /// Represents the location of the "F14" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f14 = PhysicalKeyboardKey(0x00070069); + + /// Represents the location of the "F15" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f15 = PhysicalKeyboardKey(0x0007006a); + + /// Represents the location of the "F16" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f16 = PhysicalKeyboardKey(0x0007006b); + + /// Represents the location of the "F17" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f17 = PhysicalKeyboardKey(0x0007006c); + + /// Represents the location of the "F18" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f18 = PhysicalKeyboardKey(0x0007006d); + + /// Represents the location of the "F19" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f19 = PhysicalKeyboardKey(0x0007006e); + + /// Represents the location of the "F20" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f20 = PhysicalKeyboardKey(0x0007006f); + + /// Represents the location of the "F21" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f21 = PhysicalKeyboardKey(0x00070070); + + /// Represents the location of the "F22" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f22 = PhysicalKeyboardKey(0x00070071); + + /// Represents the location of the "F23" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f23 = PhysicalKeyboardKey(0x00070072); + + /// Represents the location of the "F24" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey f24 = PhysicalKeyboardKey(0x00070073); + + /// Represents the location of the "Open" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey open = PhysicalKeyboardKey(0x00070074); + + /// Represents the location of the "Help" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey help = PhysicalKeyboardKey(0x00070075); + + /// Represents the location of the "Select" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey select = PhysicalKeyboardKey(0x00070077); + + /// Represents the location of the "Again" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey again = PhysicalKeyboardKey(0x00070079); + + /// Represents the location of the "Undo" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey undo = PhysicalKeyboardKey(0x0007007a); + + /// Represents the location of the "Cut" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey cut = PhysicalKeyboardKey(0x0007007b); + + /// Represents the location of the "Copy" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey copy = PhysicalKeyboardKey(0x0007007c); + + /// Represents the location of the "Paste" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey paste = PhysicalKeyboardKey(0x0007007d); + + /// Represents the location of the "Find" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey find = PhysicalKeyboardKey(0x0007007e); + + /// Represents the location of the "Audio Volume Mute" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey audioVolumeMute = PhysicalKeyboardKey(0x0007007f); + + /// Represents the location of the "Audio Volume Up" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey audioVolumeUp = PhysicalKeyboardKey(0x00070080); + + /// Represents the location of the "Audio Volume Down" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey audioVolumeDown = PhysicalKeyboardKey(0x00070081); + + /// Represents the location of the "Numpad Comma" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadComma = PhysicalKeyboardKey(0x00070085); + + /// Represents the location of the "Intl Ro" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey intlRo = PhysicalKeyboardKey(0x00070087); + + /// Represents the location of the "Kana Mode" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey kanaMode = PhysicalKeyboardKey(0x00070088); + + /// Represents the location of the "Intl Yen" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey intlYen = PhysicalKeyboardKey(0x00070089); + + /// Represents the location of the "Convert" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey convert = PhysicalKeyboardKey(0x0007008a); + + /// Represents the location of the "Non Convert" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey nonConvert = PhysicalKeyboardKey(0x0007008b); + + /// Represents the location of the "Lang 1" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey lang1 = PhysicalKeyboardKey(0x00070090); + + /// Represents the location of the "Lang 2" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey lang2 = PhysicalKeyboardKey(0x00070091); + + /// Represents the location of the "Lang 3" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey lang3 = PhysicalKeyboardKey(0x00070092); + + /// Represents the location of the "Lang 4" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey lang4 = PhysicalKeyboardKey(0x00070093); + + /// Represents the location of the "Lang 5" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey lang5 = PhysicalKeyboardKey(0x00070094); + + /// Represents the location of the "Abort" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey abort = PhysicalKeyboardKey(0x0007009b); + + /// Represents the location of the "Props" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey props = PhysicalKeyboardKey(0x000700a3); + + /// Represents the location of the "Numpad Paren Left" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadParenLeft = PhysicalKeyboardKey(0x000700b6); + + /// Represents the location of the "Numpad Paren Right" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadParenRight = PhysicalKeyboardKey(0x000700b7); + + /// Represents the location of the "Numpad Backspace" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadBackspace = PhysicalKeyboardKey(0x000700bb); + + /// Represents the location of the "Numpad Memory Store" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadMemoryStore = PhysicalKeyboardKey(0x000700d0); + + /// Represents the location of the "Numpad Memory Recall" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadMemoryRecall = PhysicalKeyboardKey(0x000700d1); + + /// Represents the location of the "Numpad Memory Clear" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadMemoryClear = PhysicalKeyboardKey(0x000700d2); + + /// Represents the location of the "Numpad Memory Add" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadMemoryAdd = PhysicalKeyboardKey(0x000700d3); + + /// Represents the location of the "Numpad Memory Subtract" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadMemorySubtract = PhysicalKeyboardKey(0x000700d4); + + /// Represents the location of the "Numpad Sign Change" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadSignChange = PhysicalKeyboardKey(0x000700d7); + + /// Represents the location of the "Numpad Clear" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadClear = PhysicalKeyboardKey(0x000700d8); + + /// Represents the location of the "Numpad Clear Entry" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey numpadClearEntry = PhysicalKeyboardKey(0x000700d9); + + /// Represents the location of the "Control Left" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey controlLeft = PhysicalKeyboardKey(0x000700e0); + + /// Represents the location of the "Shift Left" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey shiftLeft = PhysicalKeyboardKey(0x000700e1); + + /// Represents the location of the "Alt Left" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey altLeft = PhysicalKeyboardKey(0x000700e2); + + /// Represents the location of the "Meta Left" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey metaLeft = PhysicalKeyboardKey(0x000700e3); + + /// Represents the location of the "Control Right" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey controlRight = PhysicalKeyboardKey(0x000700e4); + + /// Represents the location of the "Shift Right" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey shiftRight = PhysicalKeyboardKey(0x000700e5); + + /// Represents the location of the "Alt Right" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey altRight = PhysicalKeyboardKey(0x000700e6); + + /// Represents the location of the "Meta Right" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey metaRight = PhysicalKeyboardKey(0x000700e7); + + /// Represents the location of the "Info" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey info = PhysicalKeyboardKey(0x000c0060); + + /// Represents the location of the "Closed Caption Toggle" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey closedCaptionToggle = PhysicalKeyboardKey(0x000c0061); + + /// Represents the location of the "Brightness Up" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey brightnessUp = PhysicalKeyboardKey(0x000c006f); + + /// Represents the location of the "Brightness Down" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey brightnessDown = PhysicalKeyboardKey(0x000c0070); + + /// Represents the location of the "Brightness Toggle" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey brightnessToggle = PhysicalKeyboardKey(0x000c0072); + + /// Represents the location of the "Brightness Minimum" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey brightnessMinimum = PhysicalKeyboardKey(0x000c0073); + + /// Represents the location of the "Brightness Maximum" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey brightnessMaximum = PhysicalKeyboardKey(0x000c0074); + + /// Represents the location of the "Brightness Auto" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey brightnessAuto = PhysicalKeyboardKey(0x000c0075); + + /// Represents the location of the "Kbd Illum Up" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey kbdIllumUp = PhysicalKeyboardKey(0x000c0079); + + /// Represents the location of the "Kbd Illum Down" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey kbdIllumDown = PhysicalKeyboardKey(0x000c007a); + + /// Represents the location of the "Media Last" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaLast = PhysicalKeyboardKey(0x000c0083); + + /// Represents the location of the "Launch Phone" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchPhone = PhysicalKeyboardKey(0x000c008c); + + /// Represents the location of the "Program Guide" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey programGuide = PhysicalKeyboardKey(0x000c008d); + + /// Represents the location of the "Exit" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey exit = PhysicalKeyboardKey(0x000c0094); + + /// Represents the location of the "Channel Up" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey channelUp = PhysicalKeyboardKey(0x000c009c); + + /// Represents the location of the "Channel Down" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey channelDown = PhysicalKeyboardKey(0x000c009d); + + /// Represents the location of the "Media Play" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaPlay = PhysicalKeyboardKey(0x000c00b0); + + /// Represents the location of the "Media Pause" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaPause = PhysicalKeyboardKey(0x000c00b1); + + /// Represents the location of the "Media Record" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaRecord = PhysicalKeyboardKey(0x000c00b2); + + /// Represents the location of the "Media Fast Forward" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaFastForward = PhysicalKeyboardKey(0x000c00b3); + + /// Represents the location of the "Media Rewind" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaRewind = PhysicalKeyboardKey(0x000c00b4); + + /// Represents the location of the "Media Track Next" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaTrackNext = PhysicalKeyboardKey(0x000c00b5); + + /// Represents the location of the "Media Track Previous" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaTrackPrevious = PhysicalKeyboardKey(0x000c00b6); + + /// Represents the location of the "Media Stop" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaStop = PhysicalKeyboardKey(0x000c00b7); + + /// Represents the location of the "Eject" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey eject = PhysicalKeyboardKey(0x000c00b8); + + /// Represents the location of the "Media Play Pause" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaPlayPause = PhysicalKeyboardKey(0x000c00cd); + + /// Represents the location of the "Speech Input Toggle" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey speechInputToggle = PhysicalKeyboardKey(0x000c00cf); + + /// Represents the location of the "Bass Boost" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey bassBoost = PhysicalKeyboardKey(0x000c00e5); + + /// Represents the location of the "Media Select" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mediaSelect = PhysicalKeyboardKey(0x000c0183); + + /// Represents the location of the "Launch Word Processor" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchWordProcessor = PhysicalKeyboardKey(0x000c0184); + + /// Represents the location of the "Launch Spreadsheet" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchSpreadsheet = PhysicalKeyboardKey(0x000c0186); + + /// Represents the location of the "Launch Mail" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchMail = PhysicalKeyboardKey(0x000c018a); + + /// Represents the location of the "Launch Contacts" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchContacts = PhysicalKeyboardKey(0x000c018d); + + /// Represents the location of the "Launch Calendar" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchCalendar = PhysicalKeyboardKey(0x000c018e); + + /// Represents the location of the "Launch App2" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchApp2 = PhysicalKeyboardKey(0x000c0192); + + /// Represents the location of the "Launch App1" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchApp1 = PhysicalKeyboardKey(0x000c0194); + + /// Represents the location of the "Launch Internet Browser" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchInternetBrowser = PhysicalKeyboardKey(0x000c0196); + + /// Represents the location of the "Log Off" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey logOff = PhysicalKeyboardKey(0x000c019c); + + /// Represents the location of the "Lock Screen" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey lockScreen = PhysicalKeyboardKey(0x000c019e); + + /// Represents the location of the "Launch Control Panel" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchControlPanel = PhysicalKeyboardKey(0x000c019f); + + /// Represents the location of the "Select Task" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey selectTask = PhysicalKeyboardKey(0x000c01a2); + + /// Represents the location of the "Launch Documents" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchDocuments = PhysicalKeyboardKey(0x000c01a7); + + /// Represents the location of the "Spell Check" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey spellCheck = PhysicalKeyboardKey(0x000c01ab); + + /// Represents the location of the "Launch Keyboard Layout" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchKeyboardLayout = PhysicalKeyboardKey(0x000c01ae); + + /// Represents the location of the "Launch Screen Saver" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchScreenSaver = PhysicalKeyboardKey(0x000c01b1); + + /// Represents the location of the "Launch Audio Browser" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchAudioBrowser = PhysicalKeyboardKey(0x000c01b7); + + /// Represents the location of the "Launch Assistant" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey launchAssistant = PhysicalKeyboardKey(0x000c01cb); + + /// Represents the location of the "New Key" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey newKey = PhysicalKeyboardKey(0x000c0201); + + /// Represents the location of the "Close" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey close = PhysicalKeyboardKey(0x000c0203); + + /// Represents the location of the "Save" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey save = PhysicalKeyboardKey(0x000c0207); + + /// Represents the location of the "Print" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey print = PhysicalKeyboardKey(0x000c0208); + + /// Represents the location of the "Browser Search" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey browserSearch = PhysicalKeyboardKey(0x000c0221); + + /// Represents the location of the "Browser Home" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey browserHome = PhysicalKeyboardKey(0x000c0223); + + /// Represents the location of the "Browser Back" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey browserBack = PhysicalKeyboardKey(0x000c0224); + + /// Represents the location of the "Browser Forward" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey browserForward = PhysicalKeyboardKey(0x000c0225); + + /// Represents the location of the "Browser Stop" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey browserStop = PhysicalKeyboardKey(0x000c0226); + + /// Represents the location of the "Browser Refresh" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey browserRefresh = PhysicalKeyboardKey(0x000c0227); + + /// Represents the location of the "Browser Favorites" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey browserFavorites = PhysicalKeyboardKey(0x000c022a); + + /// Represents the location of the "Zoom In" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey zoomIn = PhysicalKeyboardKey(0x000c022d); + + /// Represents the location of the "Zoom Out" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey zoomOut = PhysicalKeyboardKey(0x000c022e); + + /// Represents the location of the "Zoom Toggle" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey zoomToggle = PhysicalKeyboardKey(0x000c0232); + + /// Represents the location of the "Redo" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey redo = PhysicalKeyboardKey(0x000c0279); + + /// Represents the location of the "Mail Reply" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mailReply = PhysicalKeyboardKey(0x000c0289); + + /// Represents the location of the "Mail Forward" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mailForward = PhysicalKeyboardKey(0x000c028b); + + /// Represents the location of the "Mail Send" key on a generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey mailSend = PhysicalKeyboardKey(0x000c028c); + + /// Represents the location of the "Keyboard Layout Select" key on a + /// generalized keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey keyboardLayoutSelect = PhysicalKeyboardKey(0x000c029d); + + /// Represents the location of the "Show All Windows" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey showAllWindows = PhysicalKeyboardKey(0x000c029f); + + /// A list of all predefined constant [PhysicalKeyboardKey]s. + static Iterable<PhysicalKeyboardKey> get knownPhysicalKeys => _knownPhysicalKeys.values; + + // A list of all the predefined constant PhysicalKeyboardKeys so that they + // can be searched. + static const Map<int, PhysicalKeyboardKey> _knownPhysicalKeys = <int, PhysicalKeyboardKey>{ + 0x00000010: hyper, + 0x00000011: superKey, + 0x00000012: fn, + 0x00000013: fnLock, + 0x00000014: suspend, + 0x00000015: resume, + 0x00000016: turbo, + 0x00000017: privacyScreenToggle, + 0x00000018: microphoneMuteToggle, + 0x00010082: sleep, + 0x00010083: wakeUp, + 0x000100b5: displayToggleIntExt, + 0x0005ff01: gameButton1, + 0x0005ff02: gameButton2, + 0x0005ff03: gameButton3, + 0x0005ff04: gameButton4, + 0x0005ff05: gameButton5, + 0x0005ff06: gameButton6, + 0x0005ff07: gameButton7, + 0x0005ff08: gameButton8, + 0x0005ff09: gameButton9, + 0x0005ff0a: gameButton10, + 0x0005ff0b: gameButton11, + 0x0005ff0c: gameButton12, + 0x0005ff0d: gameButton13, + 0x0005ff0e: gameButton14, + 0x0005ff0f: gameButton15, + 0x0005ff10: gameButton16, + 0x0005ff11: gameButtonA, + 0x0005ff12: gameButtonB, + 0x0005ff13: gameButtonC, + 0x0005ff14: gameButtonLeft1, + 0x0005ff15: gameButtonLeft2, + 0x0005ff16: gameButtonMode, + 0x0005ff17: gameButtonRight1, + 0x0005ff18: gameButtonRight2, + 0x0005ff19: gameButtonSelect, + 0x0005ff1a: gameButtonStart, + 0x0005ff1b: gameButtonThumbLeft, + 0x0005ff1c: gameButtonThumbRight, + 0x0005ff1d: gameButtonX, + 0x0005ff1e: gameButtonY, + 0x0005ff1f: gameButtonZ, + 0x00070000: usbReserved, + 0x00070001: usbErrorRollOver, + 0x00070002: usbPostFail, + 0x00070003: usbErrorUndefined, + 0x00070004: keyA, + 0x00070005: keyB, + 0x00070006: keyC, + 0x00070007: keyD, + 0x00070008: keyE, + 0x00070009: keyF, + 0x0007000a: keyG, + 0x0007000b: keyH, + 0x0007000c: keyI, + 0x0007000d: keyJ, + 0x0007000e: keyK, + 0x0007000f: keyL, + 0x00070010: keyM, + 0x00070011: keyN, + 0x00070012: keyO, + 0x00070013: keyP, + 0x00070014: keyQ, + 0x00070015: keyR, + 0x00070016: keyS, + 0x00070017: keyT, + 0x00070018: keyU, + 0x00070019: keyV, + 0x0007001a: keyW, + 0x0007001b: keyX, + 0x0007001c: keyY, + 0x0007001d: keyZ, + 0x0007001e: digit1, + 0x0007001f: digit2, + 0x00070020: digit3, + 0x00070021: digit4, + 0x00070022: digit5, + 0x00070023: digit6, + 0x00070024: digit7, + 0x00070025: digit8, + 0x00070026: digit9, + 0x00070027: digit0, + 0x00070028: enter, + 0x00070029: escape, + 0x0007002a: backspace, + 0x0007002b: tab, + 0x0007002c: space, + 0x0007002d: minus, + 0x0007002e: equal, + 0x0007002f: bracketLeft, + 0x00070030: bracketRight, + 0x00070031: backslash, + 0x00070033: semicolon, + 0x00070034: quote, + 0x00070035: backquote, + 0x00070036: comma, + 0x00070037: period, + 0x00070038: slash, + 0x00070039: capsLock, + 0x0007003a: f1, + 0x0007003b: f2, + 0x0007003c: f3, + 0x0007003d: f4, + 0x0007003e: f5, + 0x0007003f: f6, + 0x00070040: f7, + 0x00070041: f8, + 0x00070042: f9, + 0x00070043: f10, + 0x00070044: f11, + 0x00070045: f12, + 0x00070046: printScreen, + 0x00070047: scrollLock, + 0x00070048: pause, + 0x00070049: insert, + 0x0007004a: home, + 0x0007004b: pageUp, + 0x0007004c: delete, + 0x0007004d: end, + 0x0007004e: pageDown, + 0x0007004f: arrowRight, + 0x00070050: arrowLeft, + 0x00070051: arrowDown, + 0x00070052: arrowUp, + 0x00070053: numLock, + 0x00070054: numpadDivide, + 0x00070055: numpadMultiply, + 0x00070056: numpadSubtract, + 0x00070057: numpadAdd, + 0x00070058: numpadEnter, + 0x00070059: numpad1, + 0x0007005a: numpad2, + 0x0007005b: numpad3, + 0x0007005c: numpad4, + 0x0007005d: numpad5, + 0x0007005e: numpad6, + 0x0007005f: numpad7, + 0x00070060: numpad8, + 0x00070061: numpad9, + 0x00070062: numpad0, + 0x00070063: numpadDecimal, + 0x00070064: intlBackslash, + 0x00070065: contextMenu, + 0x00070066: power, + 0x00070067: numpadEqual, + 0x00070068: f13, + 0x00070069: f14, + 0x0007006a: f15, + 0x0007006b: f16, + 0x0007006c: f17, + 0x0007006d: f18, + 0x0007006e: f19, + 0x0007006f: f20, + 0x00070070: f21, + 0x00070071: f22, + 0x00070072: f23, + 0x00070073: f24, + 0x00070074: open, + 0x00070075: help, + 0x00070077: select, + 0x00070079: again, + 0x0007007a: undo, + 0x0007007b: cut, + 0x0007007c: copy, + 0x0007007d: paste, + 0x0007007e: find, + 0x0007007f: audioVolumeMute, + 0x00070080: audioVolumeUp, + 0x00070081: audioVolumeDown, + 0x00070085: numpadComma, + 0x00070087: intlRo, + 0x00070088: kanaMode, + 0x00070089: intlYen, + 0x0007008a: convert, + 0x0007008b: nonConvert, + 0x00070090: lang1, + 0x00070091: lang2, + 0x00070092: lang3, + 0x00070093: lang4, + 0x00070094: lang5, + 0x0007009b: abort, + 0x000700a3: props, + 0x000700b6: numpadParenLeft, + 0x000700b7: numpadParenRight, + 0x000700bb: numpadBackspace, + 0x000700d0: numpadMemoryStore, + 0x000700d1: numpadMemoryRecall, + 0x000700d2: numpadMemoryClear, + 0x000700d3: numpadMemoryAdd, + 0x000700d4: numpadMemorySubtract, + 0x000700d7: numpadSignChange, + 0x000700d8: numpadClear, + 0x000700d9: numpadClearEntry, + 0x000700e0: controlLeft, + 0x000700e1: shiftLeft, + 0x000700e2: altLeft, + 0x000700e3: metaLeft, + 0x000700e4: controlRight, + 0x000700e5: shiftRight, + 0x000700e6: altRight, + 0x000700e7: metaRight, + 0x000c0060: info, + 0x000c0061: closedCaptionToggle, + 0x000c006f: brightnessUp, + 0x000c0070: brightnessDown, + 0x000c0072: brightnessToggle, + 0x000c0073: brightnessMinimum, + 0x000c0074: brightnessMaximum, + 0x000c0075: brightnessAuto, + 0x000c0079: kbdIllumUp, + 0x000c007a: kbdIllumDown, + 0x000c0083: mediaLast, + 0x000c008c: launchPhone, + 0x000c008d: programGuide, + 0x000c0094: exit, + 0x000c009c: channelUp, + 0x000c009d: channelDown, + 0x000c00b0: mediaPlay, + 0x000c00b1: mediaPause, + 0x000c00b2: mediaRecord, + 0x000c00b3: mediaFastForward, + 0x000c00b4: mediaRewind, + 0x000c00b5: mediaTrackNext, + 0x000c00b6: mediaTrackPrevious, + 0x000c00b7: mediaStop, + 0x000c00b8: eject, + 0x000c00cd: mediaPlayPause, + 0x000c00cf: speechInputToggle, + 0x000c00e5: bassBoost, + 0x000c0183: mediaSelect, + 0x000c0184: launchWordProcessor, + 0x000c0186: launchSpreadsheet, + 0x000c018a: launchMail, + 0x000c018d: launchContacts, + 0x000c018e: launchCalendar, + 0x000c0192: launchApp2, + 0x000c0194: launchApp1, + 0x000c0196: launchInternetBrowser, + 0x000c019c: logOff, + 0x000c019e: lockScreen, + 0x000c019f: launchControlPanel, + 0x000c01a2: selectTask, + 0x000c01a7: launchDocuments, + 0x000c01ab: spellCheck, + 0x000c01ae: launchKeyboardLayout, + 0x000c01b1: launchScreenSaver, + 0x000c01b7: launchAudioBrowser, + 0x000c01cb: launchAssistant, + 0x000c0201: newKey, + 0x000c0203: close, + 0x000c0207: save, + 0x000c0208: print, + 0x000c0221: browserSearch, + 0x000c0223: browserHome, + 0x000c0224: browserBack, + 0x000c0225: browserForward, + 0x000c0226: browserStop, + 0x000c0227: browserRefresh, + 0x000c022a: browserFavorites, + 0x000c022d: zoomIn, + 0x000c022e: zoomOut, + 0x000c0232: zoomToggle, + 0x000c0279: redo, + 0x000c0289: mailReply, + 0x000c028b: mailForward, + 0x000c028c: mailSend, + 0x000c029d: keyboardLayoutSelect, + 0x000c029f: showAllWindows, + }; + + static const Map<int, String> _debugNames = kReleaseMode ? + <int, String>{} : + <int, String>{ + 0x00000010: 'Hyper', + 0x00000011: 'Super Key', + 0x00000012: 'Fn', + 0x00000013: 'Fn Lock', + 0x00000014: 'Suspend', + 0x00000015: 'Resume', + 0x00000016: 'Turbo', + 0x00000017: 'Privacy Screen Toggle', + 0x00000018: 'Microphone Mute Toggle', + 0x00010082: 'Sleep', + 0x00010083: 'Wake Up', + 0x000100b5: 'Display Toggle Int Ext', + 0x0005ff01: 'Game Button 1', + 0x0005ff02: 'Game Button 2', + 0x0005ff03: 'Game Button 3', + 0x0005ff04: 'Game Button 4', + 0x0005ff05: 'Game Button 5', + 0x0005ff06: 'Game Button 6', + 0x0005ff07: 'Game Button 7', + 0x0005ff08: 'Game Button 8', + 0x0005ff09: 'Game Button 9', + 0x0005ff0a: 'Game Button 10', + 0x0005ff0b: 'Game Button 11', + 0x0005ff0c: 'Game Button 12', + 0x0005ff0d: 'Game Button 13', + 0x0005ff0e: 'Game Button 14', + 0x0005ff0f: 'Game Button 15', + 0x0005ff10: 'Game Button 16', + 0x0005ff11: 'Game Button A', + 0x0005ff12: 'Game Button B', + 0x0005ff13: 'Game Button C', + 0x0005ff14: 'Game Button Left 1', + 0x0005ff15: 'Game Button Left 2', + 0x0005ff16: 'Game Button Mode', + 0x0005ff17: 'Game Button Right 1', + 0x0005ff18: 'Game Button Right 2', + 0x0005ff19: 'Game Button Select', + 0x0005ff1a: 'Game Button Start', + 0x0005ff1b: 'Game Button Thumb Left', + 0x0005ff1c: 'Game Button Thumb Right', + 0x0005ff1d: 'Game Button X', + 0x0005ff1e: 'Game Button Y', + 0x0005ff1f: 'Game Button Z', + 0x00070000: 'Usb Reserved', + 0x00070001: 'Usb Error Roll Over', + 0x00070002: 'Usb Post Fail', + 0x00070003: 'Usb Error Undefined', + 0x00070004: 'Key A', + 0x00070005: 'Key B', + 0x00070006: 'Key C', + 0x00070007: 'Key D', + 0x00070008: 'Key E', + 0x00070009: 'Key F', + 0x0007000a: 'Key G', + 0x0007000b: 'Key H', + 0x0007000c: 'Key I', + 0x0007000d: 'Key J', + 0x0007000e: 'Key K', + 0x0007000f: 'Key L', + 0x00070010: 'Key M', + 0x00070011: 'Key N', + 0x00070012: 'Key O', + 0x00070013: 'Key P', + 0x00070014: 'Key Q', + 0x00070015: 'Key R', + 0x00070016: 'Key S', + 0x00070017: 'Key T', + 0x00070018: 'Key U', + 0x00070019: 'Key V', + 0x0007001a: 'Key W', + 0x0007001b: 'Key X', + 0x0007001c: 'Key Y', + 0x0007001d: 'Key Z', + 0x0007001e: 'Digit 1', + 0x0007001f: 'Digit 2', + 0x00070020: 'Digit 3', + 0x00070021: 'Digit 4', + 0x00070022: 'Digit 5', + 0x00070023: 'Digit 6', + 0x00070024: 'Digit 7', + 0x00070025: 'Digit 8', + 0x00070026: 'Digit 9', + 0x00070027: 'Digit 0', + 0x00070028: 'Enter', + 0x00070029: 'Escape', + 0x0007002a: 'Backspace', + 0x0007002b: 'Tab', + 0x0007002c: 'Space', + 0x0007002d: 'Minus', + 0x0007002e: 'Equal', + 0x0007002f: 'Bracket Left', + 0x00070030: 'Bracket Right', + 0x00070031: 'Backslash', + 0x00070033: 'Semicolon', + 0x00070034: 'Quote', + 0x00070035: 'Backquote', + 0x00070036: 'Comma', + 0x00070037: 'Period', + 0x00070038: 'Slash', + 0x00070039: 'Caps Lock', + 0x0007003a: 'F1', + 0x0007003b: 'F2', + 0x0007003c: 'F3', + 0x0007003d: 'F4', + 0x0007003e: 'F5', + 0x0007003f: 'F6', + 0x00070040: 'F7', + 0x00070041: 'F8', + 0x00070042: 'F9', + 0x00070043: 'F10', + 0x00070044: 'F11', + 0x00070045: 'F12', + 0x00070046: 'Print Screen', + 0x00070047: 'Scroll Lock', + 0x00070048: 'Pause', + 0x00070049: 'Insert', + 0x0007004a: 'Home', + 0x0007004b: 'Page Up', + 0x0007004c: 'Delete', + 0x0007004d: 'End', + 0x0007004e: 'Page Down', + 0x0007004f: 'Arrow Right', + 0x00070050: 'Arrow Left', + 0x00070051: 'Arrow Down', + 0x00070052: 'Arrow Up', + 0x00070053: 'Num Lock', + 0x00070054: 'Numpad Divide', + 0x00070055: 'Numpad Multiply', + 0x00070056: 'Numpad Subtract', + 0x00070057: 'Numpad Add', + 0x00070058: 'Numpad Enter', + 0x00070059: 'Numpad 1', + 0x0007005a: 'Numpad 2', + 0x0007005b: 'Numpad 3', + 0x0007005c: 'Numpad 4', + 0x0007005d: 'Numpad 5', + 0x0007005e: 'Numpad 6', + 0x0007005f: 'Numpad 7', + 0x00070060: 'Numpad 8', + 0x00070061: 'Numpad 9', + 0x00070062: 'Numpad 0', + 0x00070063: 'Numpad Decimal', + 0x00070064: 'Intl Backslash', + 0x00070065: 'Context Menu', + 0x00070066: 'Power', + 0x00070067: 'Numpad Equal', + 0x00070068: 'F13', + 0x00070069: 'F14', + 0x0007006a: 'F15', + 0x0007006b: 'F16', + 0x0007006c: 'F17', + 0x0007006d: 'F18', + 0x0007006e: 'F19', + 0x0007006f: 'F20', + 0x00070070: 'F21', + 0x00070071: 'F22', + 0x00070072: 'F23', + 0x00070073: 'F24', + 0x00070074: 'Open', + 0x00070075: 'Help', + 0x00070077: 'Select', + 0x00070079: 'Again', + 0x0007007a: 'Undo', + 0x0007007b: 'Cut', + 0x0007007c: 'Copy', + 0x0007007d: 'Paste', + 0x0007007e: 'Find', + 0x0007007f: 'Audio Volume Mute', + 0x00070080: 'Audio Volume Up', + 0x00070081: 'Audio Volume Down', + 0x00070085: 'Numpad Comma', + 0x00070087: 'Intl Ro', + 0x00070088: 'Kana Mode', + 0x00070089: 'Intl Yen', + 0x0007008a: 'Convert', + 0x0007008b: 'Non Convert', + 0x00070090: 'Lang 1', + 0x00070091: 'Lang 2', + 0x00070092: 'Lang 3', + 0x00070093: 'Lang 4', + 0x00070094: 'Lang 5', + 0x0007009b: 'Abort', + 0x000700a3: 'Props', + 0x000700b6: 'Numpad Paren Left', + 0x000700b7: 'Numpad Paren Right', + 0x000700bb: 'Numpad Backspace', + 0x000700d0: 'Numpad Memory Store', + 0x000700d1: 'Numpad Memory Recall', + 0x000700d2: 'Numpad Memory Clear', + 0x000700d3: 'Numpad Memory Add', + 0x000700d4: 'Numpad Memory Subtract', + 0x000700d7: 'Numpad Sign Change', + 0x000700d8: 'Numpad Clear', + 0x000700d9: 'Numpad Clear Entry', + 0x000700e0: 'Control Left', + 0x000700e1: 'Shift Left', + 0x000700e2: 'Alt Left', + 0x000700e3: 'Meta Left', + 0x000700e4: 'Control Right', + 0x000700e5: 'Shift Right', + 0x000700e6: 'Alt Right', + 0x000700e7: 'Meta Right', + 0x000c0060: 'Info', + 0x000c0061: 'Closed Caption Toggle', + 0x000c006f: 'Brightness Up', + 0x000c0070: 'Brightness Down', + 0x000c0072: 'Brightness Toggle', + 0x000c0073: 'Brightness Minimum', + 0x000c0074: 'Brightness Maximum', + 0x000c0075: 'Brightness Auto', + 0x000c0079: 'Kbd Illum Up', + 0x000c007a: 'Kbd Illum Down', + 0x000c0083: 'Media Last', + 0x000c008c: 'Launch Phone', + 0x000c008d: 'Program Guide', + 0x000c0094: 'Exit', + 0x000c009c: 'Channel Up', + 0x000c009d: 'Channel Down', + 0x000c00b0: 'Media Play', + 0x000c00b1: 'Media Pause', + 0x000c00b2: 'Media Record', + 0x000c00b3: 'Media Fast Forward', + 0x000c00b4: 'Media Rewind', + 0x000c00b5: 'Media Track Next', + 0x000c00b6: 'Media Track Previous', + 0x000c00b7: 'Media Stop', + 0x000c00b8: 'Eject', + 0x000c00cd: 'Media Play Pause', + 0x000c00cf: 'Speech Input Toggle', + 0x000c00e5: 'Bass Boost', + 0x000c0183: 'Media Select', + 0x000c0184: 'Launch Word Processor', + 0x000c0186: 'Launch Spreadsheet', + 0x000c018a: 'Launch Mail', + 0x000c018d: 'Launch Contacts', + 0x000c018e: 'Launch Calendar', + 0x000c0192: 'Launch App2', + 0x000c0194: 'Launch App1', + 0x000c0196: 'Launch Internet Browser', + 0x000c019c: 'Log Off', + 0x000c019e: 'Lock Screen', + 0x000c019f: 'Launch Control Panel', + 0x000c01a2: 'Select Task', + 0x000c01a7: 'Launch Documents', + 0x000c01ab: 'Spell Check', + 0x000c01ae: 'Launch Keyboard Layout', + 0x000c01b1: 'Launch Screen Saver', + 0x000c01b7: 'Launch Audio Browser', + 0x000c01cb: 'Launch Assistant', + 0x000c0201: 'New Key', + 0x000c0203: 'Close', + 0x000c0207: 'Save', + 0x000c0208: 'Print', + 0x000c0221: 'Browser Search', + 0x000c0223: 'Browser Home', + 0x000c0224: 'Browser Back', + 0x000c0225: 'Browser Forward', + 0x000c0226: 'Browser Stop', + 0x000c0227: 'Browser Refresh', + 0x000c022a: 'Browser Favorites', + 0x000c022d: 'Zoom In', + 0x000c022e: 'Zoom Out', + 0x000c0232: 'Zoom Toggle', + 0x000c0279: 'Redo', + 0x000c0289: 'Mail Reply', + 0x000c028b: 'Mail Forward', + 0x000c028c: 'Mail Send', + 0x000c029d: 'Keyboard Layout Select', + 0x000c029f: 'Show All Windows', + }; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/keyboard_maps.g.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/keyboard_maps.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..b94e1c82e532678ad0dbe8a379ad6765ccee57ac --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/keyboard_maps.g.dart @@ -0,0 +1,3119 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT +// This file is generated by dev/tools/gen_keycodes/bin/gen_keycodes.dart and +// should not be edited directly. +// +// Edit the template dev/tools/gen_keycodes/data/keyboard_maps.tmpl instead. +// See dev/tools/gen_keycodes/README.md for more information. + +import 'keyboard_key.g.dart'; + +export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey; + +/// Maps Android-specific key codes to the matching [LogicalKeyboardKey]. +const Map<int, LogicalKeyboardKey> kAndroidToLogicalKey = <int, LogicalKeyboardKey>{ + 3: LogicalKeyboardKey.goHome, + 4: LogicalKeyboardKey.goBack, + 5: LogicalKeyboardKey.call, + 6: LogicalKeyboardKey.endCall, + 7: LogicalKeyboardKey.digit0, + 8: LogicalKeyboardKey.digit1, + 9: LogicalKeyboardKey.digit2, + 10: LogicalKeyboardKey.digit3, + 11: LogicalKeyboardKey.digit4, + 12: LogicalKeyboardKey.digit5, + 13: LogicalKeyboardKey.digit6, + 14: LogicalKeyboardKey.digit7, + 15: LogicalKeyboardKey.digit8, + 16: LogicalKeyboardKey.digit9, + 17: LogicalKeyboardKey.asterisk, + 18: LogicalKeyboardKey.numberSign, + 19: LogicalKeyboardKey.arrowUp, + 20: LogicalKeyboardKey.arrowDown, + 21: LogicalKeyboardKey.arrowLeft, + 22: LogicalKeyboardKey.arrowRight, + 23: LogicalKeyboardKey.select, + 24: LogicalKeyboardKey.audioVolumeUp, + 25: LogicalKeyboardKey.audioVolumeDown, + 26: LogicalKeyboardKey.power, + 27: LogicalKeyboardKey.camera, + 28: LogicalKeyboardKey.clear, + 29: LogicalKeyboardKey.keyA, + 30: LogicalKeyboardKey.keyB, + 31: LogicalKeyboardKey.keyC, + 32: LogicalKeyboardKey.keyD, + 33: LogicalKeyboardKey.keyE, + 34: LogicalKeyboardKey.keyF, + 35: LogicalKeyboardKey.keyG, + 36: LogicalKeyboardKey.keyH, + 37: LogicalKeyboardKey.keyI, + 38: LogicalKeyboardKey.keyJ, + 39: LogicalKeyboardKey.keyK, + 40: LogicalKeyboardKey.keyL, + 41: LogicalKeyboardKey.keyM, + 42: LogicalKeyboardKey.keyN, + 43: LogicalKeyboardKey.keyO, + 44: LogicalKeyboardKey.keyP, + 45: LogicalKeyboardKey.keyQ, + 46: LogicalKeyboardKey.keyR, + 47: LogicalKeyboardKey.keyS, + 48: LogicalKeyboardKey.keyT, + 49: LogicalKeyboardKey.keyU, + 50: LogicalKeyboardKey.keyV, + 51: LogicalKeyboardKey.keyW, + 52: LogicalKeyboardKey.keyX, + 53: LogicalKeyboardKey.keyY, + 54: LogicalKeyboardKey.keyZ, + 55: LogicalKeyboardKey.comma, + 56: LogicalKeyboardKey.period, + 57: LogicalKeyboardKey.altLeft, + 58: LogicalKeyboardKey.altRight, + 59: LogicalKeyboardKey.shiftLeft, + 60: LogicalKeyboardKey.shiftRight, + 61: LogicalKeyboardKey.tab, + 62: LogicalKeyboardKey.space, + 63: LogicalKeyboardKey.symbol, + 64: LogicalKeyboardKey.launchWebBrowser, + 65: LogicalKeyboardKey.launchMail, + 66: LogicalKeyboardKey.enter, + 67: LogicalKeyboardKey.backspace, + 68: LogicalKeyboardKey.backquote, + 69: LogicalKeyboardKey.minus, + 70: LogicalKeyboardKey.equal, + 71: LogicalKeyboardKey.bracketLeft, + 72: LogicalKeyboardKey.bracketRight, + 73: LogicalKeyboardKey.backslash, + 74: LogicalKeyboardKey.semicolon, + 75: LogicalKeyboardKey.quote, + 76: LogicalKeyboardKey.slash, + 77: LogicalKeyboardKey.at, + 79: LogicalKeyboardKey.headsetHook, + 80: LogicalKeyboardKey.cameraFocus, + 81: LogicalKeyboardKey.add, + 82: LogicalKeyboardKey.contextMenu, + 83: LogicalKeyboardKey.notification, + 84: LogicalKeyboardKey.browserSearch, + 85: LogicalKeyboardKey.mediaPlayPause, + 86: LogicalKeyboardKey.mediaStop, + 87: LogicalKeyboardKey.mediaTrackNext, + 88: LogicalKeyboardKey.mediaTrackPrevious, + 89: LogicalKeyboardKey.mediaRewind, + 90: LogicalKeyboardKey.mediaFastForward, + 91: LogicalKeyboardKey.microphoneVolumeMute, + 92: LogicalKeyboardKey.pageUp, + 93: LogicalKeyboardKey.pageDown, + 95: LogicalKeyboardKey.modeChange, + 96: LogicalKeyboardKey.gameButtonA, + 97: LogicalKeyboardKey.gameButtonB, + 98: LogicalKeyboardKey.gameButtonC, + 99: LogicalKeyboardKey.gameButtonX, + 100: LogicalKeyboardKey.gameButtonY, + 101: LogicalKeyboardKey.gameButtonZ, + 102: LogicalKeyboardKey.gameButtonLeft1, + 103: LogicalKeyboardKey.gameButtonRight1, + 104: LogicalKeyboardKey.gameButtonLeft2, + 105: LogicalKeyboardKey.gameButtonRight2, + 106: LogicalKeyboardKey.gameButtonThumbLeft, + 107: LogicalKeyboardKey.gameButtonThumbRight, + 108: LogicalKeyboardKey.gameButtonStart, + 109: LogicalKeyboardKey.gameButtonSelect, + 110: LogicalKeyboardKey.gameButtonMode, + 111: LogicalKeyboardKey.escape, + 112: LogicalKeyboardKey.delete, + 113: LogicalKeyboardKey.controlLeft, + 114: LogicalKeyboardKey.controlRight, + 115: LogicalKeyboardKey.capsLock, + 116: LogicalKeyboardKey.scrollLock, + 117: LogicalKeyboardKey.metaLeft, + 118: LogicalKeyboardKey.metaRight, + 119: LogicalKeyboardKey.fn, + 120: LogicalKeyboardKey.printScreen, + 121: LogicalKeyboardKey.pause, + 122: LogicalKeyboardKey.home, + 123: LogicalKeyboardKey.end, + 124: LogicalKeyboardKey.insert, + 125: LogicalKeyboardKey.browserForward, + 126: LogicalKeyboardKey.mediaPlay, + 127: LogicalKeyboardKey.mediaPause, + 128: LogicalKeyboardKey.close, + 129: LogicalKeyboardKey.eject, + 130: LogicalKeyboardKey.mediaRecord, + 131: LogicalKeyboardKey.f1, + 132: LogicalKeyboardKey.f2, + 133: LogicalKeyboardKey.f3, + 134: LogicalKeyboardKey.f4, + 135: LogicalKeyboardKey.f5, + 136: LogicalKeyboardKey.f6, + 137: LogicalKeyboardKey.f7, + 138: LogicalKeyboardKey.f8, + 139: LogicalKeyboardKey.f9, + 140: LogicalKeyboardKey.f10, + 141: LogicalKeyboardKey.f11, + 142: LogicalKeyboardKey.f12, + 143: LogicalKeyboardKey.numLock, + 144: LogicalKeyboardKey.numpad0, + 145: LogicalKeyboardKey.numpad1, + 146: LogicalKeyboardKey.numpad2, + 147: LogicalKeyboardKey.numpad3, + 148: LogicalKeyboardKey.numpad4, + 149: LogicalKeyboardKey.numpad5, + 150: LogicalKeyboardKey.numpad6, + 151: LogicalKeyboardKey.numpad7, + 152: LogicalKeyboardKey.numpad8, + 153: LogicalKeyboardKey.numpad9, + 154: LogicalKeyboardKey.numpadDivide, + 155: LogicalKeyboardKey.numpadMultiply, + 156: LogicalKeyboardKey.numpadSubtract, + 157: LogicalKeyboardKey.numpadAdd, + 158: LogicalKeyboardKey.numpadDecimal, + 159: LogicalKeyboardKey.numpadComma, + 160: LogicalKeyboardKey.numpadEnter, + 161: LogicalKeyboardKey.numpadEqual, + 162: LogicalKeyboardKey.numpadParenLeft, + 163: LogicalKeyboardKey.numpadParenRight, + 164: LogicalKeyboardKey.audioVolumeMute, + 165: LogicalKeyboardKey.info, + 166: LogicalKeyboardKey.channelUp, + 167: LogicalKeyboardKey.channelDown, + 168: LogicalKeyboardKey.zoomIn, + 169: LogicalKeyboardKey.zoomOut, + 170: LogicalKeyboardKey.tv, + 172: LogicalKeyboardKey.guide, + 173: LogicalKeyboardKey.dvr, + 174: LogicalKeyboardKey.browserFavorites, + 175: LogicalKeyboardKey.closedCaptionToggle, + 176: LogicalKeyboardKey.settings, + 177: LogicalKeyboardKey.tvPower, + 178: LogicalKeyboardKey.tvInput, + 179: LogicalKeyboardKey.stbPower, + 180: LogicalKeyboardKey.stbInput, + 181: LogicalKeyboardKey.avrPower, + 182: LogicalKeyboardKey.avrInput, + 183: LogicalKeyboardKey.colorF0Red, + 184: LogicalKeyboardKey.colorF1Green, + 185: LogicalKeyboardKey.colorF2Yellow, + 186: LogicalKeyboardKey.colorF3Blue, + 187: LogicalKeyboardKey.appSwitch, + 188: LogicalKeyboardKey.gameButton1, + 189: LogicalKeyboardKey.gameButton2, + 190: LogicalKeyboardKey.gameButton3, + 191: LogicalKeyboardKey.gameButton4, + 192: LogicalKeyboardKey.gameButton5, + 193: LogicalKeyboardKey.gameButton6, + 194: LogicalKeyboardKey.gameButton7, + 195: LogicalKeyboardKey.gameButton8, + 196: LogicalKeyboardKey.gameButton9, + 197: LogicalKeyboardKey.gameButton10, + 198: LogicalKeyboardKey.gameButton11, + 199: LogicalKeyboardKey.gameButton12, + 200: LogicalKeyboardKey.gameButton13, + 201: LogicalKeyboardKey.gameButton14, + 202: LogicalKeyboardKey.gameButton15, + 203: LogicalKeyboardKey.gameButton16, + 204: LogicalKeyboardKey.groupNext, + 205: LogicalKeyboardKey.mannerMode, + 206: LogicalKeyboardKey.tv3DMode, + 207: LogicalKeyboardKey.launchContacts, + 208: LogicalKeyboardKey.launchCalendar, + 209: LogicalKeyboardKey.launchMusicPlayer, + 211: LogicalKeyboardKey.zenkakuHankaku, + 212: LogicalKeyboardKey.eisu, + 213: LogicalKeyboardKey.nonConvert, + 214: LogicalKeyboardKey.convert, + 215: LogicalKeyboardKey.hiraganaKatakana, + 216: LogicalKeyboardKey.intlYen, + 217: LogicalKeyboardKey.intlRo, + 218: LogicalKeyboardKey.kanjiMode, + 219: LogicalKeyboardKey.launchAssistant, + 220: LogicalKeyboardKey.brightnessDown, + 221: LogicalKeyboardKey.brightnessUp, + 222: LogicalKeyboardKey.mediaAudioTrack, + 223: LogicalKeyboardKey.sleep, + 224: LogicalKeyboardKey.wakeUp, + 225: LogicalKeyboardKey.pairing, + 226: LogicalKeyboardKey.mediaTopMenu, + 229: LogicalKeyboardKey.mediaLast, + 230: LogicalKeyboardKey.tvDataService, + 232: LogicalKeyboardKey.tvRadioService, + 233: LogicalKeyboardKey.teletext, + 234: LogicalKeyboardKey.tvNumberEntry, + 235: LogicalKeyboardKey.tvTerrestrialAnalog, + 236: LogicalKeyboardKey.tvTerrestrialDigital, + 237: LogicalKeyboardKey.tvSatellite, + 238: LogicalKeyboardKey.tvSatelliteBS, + 239: LogicalKeyboardKey.tvSatelliteCS, + 240: LogicalKeyboardKey.tvSatelliteToggle, + 241: LogicalKeyboardKey.tvNetwork, + 242: LogicalKeyboardKey.tvAntennaCable, + 243: LogicalKeyboardKey.tvInputHDMI1, + 244: LogicalKeyboardKey.tvInputHDMI2, + 245: LogicalKeyboardKey.tvInputHDMI3, + 246: LogicalKeyboardKey.tvInputHDMI4, + 247: LogicalKeyboardKey.tvInputComposite1, + 248: LogicalKeyboardKey.tvInputComposite2, + 249: LogicalKeyboardKey.tvInputComponent1, + 250: LogicalKeyboardKey.tvInputComponent2, + 251: LogicalKeyboardKey.tvInputVGA1, + 252: LogicalKeyboardKey.tvAudioDescription, + 253: LogicalKeyboardKey.tvAudioDescriptionMixUp, + 254: LogicalKeyboardKey.tvAudioDescriptionMixDown, + 255: LogicalKeyboardKey.zoomToggle, + 256: LogicalKeyboardKey.tvContentsMenu, + 258: LogicalKeyboardKey.tvTimer, + 259: LogicalKeyboardKey.help, + 260: LogicalKeyboardKey.navigatePrevious, + 261: LogicalKeyboardKey.navigateNext, + 262: LogicalKeyboardKey.navigateIn, + 263: LogicalKeyboardKey.navigateOut, + 272: LogicalKeyboardKey.mediaSkipForward, + 273: LogicalKeyboardKey.mediaSkipBackward, + 274: LogicalKeyboardKey.mediaStepForward, + 275: LogicalKeyboardKey.mediaStepBackward, + 277: LogicalKeyboardKey.cut, + 278: LogicalKeyboardKey.copy, + 279: LogicalKeyboardKey.paste, +}; + +/// Maps Android-specific scan codes to the matching [PhysicalKeyboardKey]. +const Map<int, PhysicalKeyboardKey> kAndroidToPhysicalKey = <int, PhysicalKeyboardKey>{ + 1: PhysicalKeyboardKey.escape, + 2: PhysicalKeyboardKey.digit1, + 3: PhysicalKeyboardKey.digit2, + 4: PhysicalKeyboardKey.digit3, + 5: PhysicalKeyboardKey.digit4, + 6: PhysicalKeyboardKey.digit5, + 7: PhysicalKeyboardKey.digit6, + 8: PhysicalKeyboardKey.digit7, + 9: PhysicalKeyboardKey.digit8, + 10: PhysicalKeyboardKey.digit9, + 11: PhysicalKeyboardKey.digit0, + 12: PhysicalKeyboardKey.minus, + 13: PhysicalKeyboardKey.equal, + 14: PhysicalKeyboardKey.backspace, + 15: PhysicalKeyboardKey.tab, + 16: PhysicalKeyboardKey.keyQ, + 17: PhysicalKeyboardKey.keyW, + 18: PhysicalKeyboardKey.keyE, + 19: PhysicalKeyboardKey.keyR, + 20: PhysicalKeyboardKey.keyT, + 21: PhysicalKeyboardKey.keyY, + 22: PhysicalKeyboardKey.keyU, + 23: PhysicalKeyboardKey.keyI, + 24: PhysicalKeyboardKey.keyO, + 25: PhysicalKeyboardKey.keyP, + 26: PhysicalKeyboardKey.bracketLeft, + 27: PhysicalKeyboardKey.bracketRight, + 28: PhysicalKeyboardKey.enter, + 29: PhysicalKeyboardKey.controlLeft, + 30: PhysicalKeyboardKey.keyA, + 31: PhysicalKeyboardKey.keyS, + 32: PhysicalKeyboardKey.keyD, + 33: PhysicalKeyboardKey.keyF, + 34: PhysicalKeyboardKey.keyG, + 35: PhysicalKeyboardKey.keyH, + 36: PhysicalKeyboardKey.keyJ, + 37: PhysicalKeyboardKey.keyK, + 38: PhysicalKeyboardKey.keyL, + 39: PhysicalKeyboardKey.semicolon, + 40: PhysicalKeyboardKey.quote, + 41: PhysicalKeyboardKey.backquote, + 42: PhysicalKeyboardKey.shiftLeft, + 43: PhysicalKeyboardKey.backslash, + 44: PhysicalKeyboardKey.keyZ, + 45: PhysicalKeyboardKey.keyX, + 46: PhysicalKeyboardKey.keyC, + 47: PhysicalKeyboardKey.keyV, + 48: PhysicalKeyboardKey.keyB, + 49: PhysicalKeyboardKey.keyN, + 50: PhysicalKeyboardKey.keyM, + 51: PhysicalKeyboardKey.comma, + 52: PhysicalKeyboardKey.period, + 53: PhysicalKeyboardKey.slash, + 54: PhysicalKeyboardKey.shiftRight, + 55: PhysicalKeyboardKey.numpadMultiply, + 56: PhysicalKeyboardKey.altLeft, + 57: PhysicalKeyboardKey.space, + 58: PhysicalKeyboardKey.capsLock, + 59: PhysicalKeyboardKey.f1, + 60: PhysicalKeyboardKey.f2, + 61: PhysicalKeyboardKey.f3, + 62: PhysicalKeyboardKey.f4, + 63: PhysicalKeyboardKey.f5, + 64: PhysicalKeyboardKey.f6, + 65: PhysicalKeyboardKey.f7, + 66: PhysicalKeyboardKey.f8, + 67: PhysicalKeyboardKey.f9, + 68: PhysicalKeyboardKey.f10, + 69: PhysicalKeyboardKey.numLock, + 70: PhysicalKeyboardKey.scrollLock, + 71: PhysicalKeyboardKey.numpad7, + 72: PhysicalKeyboardKey.numpad8, + 73: PhysicalKeyboardKey.numpad9, + 74: PhysicalKeyboardKey.numpadSubtract, + 75: PhysicalKeyboardKey.numpad4, + 76: PhysicalKeyboardKey.numpad5, + 77: PhysicalKeyboardKey.numpad6, + 78: PhysicalKeyboardKey.numpadAdd, + 79: PhysicalKeyboardKey.numpad1, + 80: PhysicalKeyboardKey.numpad2, + 81: PhysicalKeyboardKey.numpad3, + 82: PhysicalKeyboardKey.numpad0, + 83: PhysicalKeyboardKey.numpadDecimal, + 86: PhysicalKeyboardKey.backslash, + 87: PhysicalKeyboardKey.f11, + 88: PhysicalKeyboardKey.f12, + 89: PhysicalKeyboardKey.intlRo, + 90: PhysicalKeyboardKey.lang3, + 91: PhysicalKeyboardKey.lang4, + 92: PhysicalKeyboardKey.convert, + 94: PhysicalKeyboardKey.nonConvert, + 95: PhysicalKeyboardKey.numpadComma, + 96: PhysicalKeyboardKey.numpadEnter, + 97: PhysicalKeyboardKey.controlRight, + 98: PhysicalKeyboardKey.numpadDivide, + 99: PhysicalKeyboardKey.printScreen, + 100: PhysicalKeyboardKey.altRight, + 102: PhysicalKeyboardKey.home, + 103: PhysicalKeyboardKey.arrowUp, + 104: PhysicalKeyboardKey.pageUp, + 105: PhysicalKeyboardKey.arrowLeft, + 106: PhysicalKeyboardKey.arrowRight, + 107: PhysicalKeyboardKey.end, + 108: PhysicalKeyboardKey.arrowDown, + 109: PhysicalKeyboardKey.pageDown, + 110: PhysicalKeyboardKey.insert, + 111: PhysicalKeyboardKey.delete, + 113: PhysicalKeyboardKey.audioVolumeMute, + 114: PhysicalKeyboardKey.audioVolumeDown, + 115: PhysicalKeyboardKey.audioVolumeUp, + 116: PhysicalKeyboardKey.power, + 117: PhysicalKeyboardKey.numpadEqual, + 119: PhysicalKeyboardKey.pause, + 121: PhysicalKeyboardKey.numpadComma, + 124: PhysicalKeyboardKey.intlYen, + 125: PhysicalKeyboardKey.metaLeft, + 126: PhysicalKeyboardKey.metaRight, + 127: PhysicalKeyboardKey.contextMenu, + 128: PhysicalKeyboardKey.mediaStop, + 129: PhysicalKeyboardKey.again, + 130: PhysicalKeyboardKey.props, + 131: PhysicalKeyboardKey.undo, + 133: PhysicalKeyboardKey.copy, + 134: PhysicalKeyboardKey.open, + 135: PhysicalKeyboardKey.paste, + 136: PhysicalKeyboardKey.find, + 137: PhysicalKeyboardKey.cut, + 138: PhysicalKeyboardKey.help, + 139: PhysicalKeyboardKey.contextMenu, + 142: PhysicalKeyboardKey.sleep, + 143: PhysicalKeyboardKey.wakeUp, + 152: PhysicalKeyboardKey.power, + 155: PhysicalKeyboardKey.launchMail, + 156: PhysicalKeyboardKey.browserFavorites, + 159: PhysicalKeyboardKey.browserForward, + 160: PhysicalKeyboardKey.close, + 161: PhysicalKeyboardKey.eject, + 162: PhysicalKeyboardKey.eject, + 163: PhysicalKeyboardKey.mediaTrackNext, + 164: PhysicalKeyboardKey.mediaPlayPause, + 165: PhysicalKeyboardKey.mediaTrackPrevious, + 166: PhysicalKeyboardKey.mediaStop, + 167: PhysicalKeyboardKey.mediaRecord, + 168: PhysicalKeyboardKey.mediaRewind, + 174: PhysicalKeyboardKey.exit, + 177: PhysicalKeyboardKey.pageUp, + 178: PhysicalKeyboardKey.pageDown, + 179: PhysicalKeyboardKey.numpadParenLeft, + 180: PhysicalKeyboardKey.numpadParenRight, + 182: PhysicalKeyboardKey.redo, + 183: PhysicalKeyboardKey.f13, + 184: PhysicalKeyboardKey.f14, + 185: PhysicalKeyboardKey.f15, + 186: PhysicalKeyboardKey.f16, + 187: PhysicalKeyboardKey.f17, + 188: PhysicalKeyboardKey.f18, + 189: PhysicalKeyboardKey.f19, + 190: PhysicalKeyboardKey.f20, + 191: PhysicalKeyboardKey.f21, + 192: PhysicalKeyboardKey.f22, + 193: PhysicalKeyboardKey.f23, + 194: PhysicalKeyboardKey.f24, + 200: PhysicalKeyboardKey.mediaPlay, + 201: PhysicalKeyboardKey.mediaPause, + 205: PhysicalKeyboardKey.suspend, + 206: PhysicalKeyboardKey.close, + 207: PhysicalKeyboardKey.mediaPlay, + 208: PhysicalKeyboardKey.mediaFastForward, + 209: PhysicalKeyboardKey.bassBoost, + 210: PhysicalKeyboardKey.print, + 215: PhysicalKeyboardKey.launchMail, + 217: PhysicalKeyboardKey.browserSearch, + 224: PhysicalKeyboardKey.brightnessDown, + 225: PhysicalKeyboardKey.brightnessUp, + 256: PhysicalKeyboardKey.gameButton1, + 257: PhysicalKeyboardKey.gameButton2, + 258: PhysicalKeyboardKey.gameButton3, + 259: PhysicalKeyboardKey.gameButton4, + 260: PhysicalKeyboardKey.gameButton5, + 261: PhysicalKeyboardKey.gameButton6, + 262: PhysicalKeyboardKey.gameButton7, + 263: PhysicalKeyboardKey.gameButton8, + 264: PhysicalKeyboardKey.gameButton9, + 265: PhysicalKeyboardKey.gameButton10, + 266: PhysicalKeyboardKey.gameButton11, + 267: PhysicalKeyboardKey.gameButton12, + 268: PhysicalKeyboardKey.gameButton13, + 269: PhysicalKeyboardKey.gameButton14, + 270: PhysicalKeyboardKey.gameButton15, + 271: PhysicalKeyboardKey.gameButton16, + 288: PhysicalKeyboardKey.gameButton1, + 289: PhysicalKeyboardKey.gameButton2, + 290: PhysicalKeyboardKey.gameButton3, + 291: PhysicalKeyboardKey.gameButton4, + 292: PhysicalKeyboardKey.gameButton5, + 293: PhysicalKeyboardKey.gameButton6, + 294: PhysicalKeyboardKey.gameButton7, + 295: PhysicalKeyboardKey.gameButton8, + 296: PhysicalKeyboardKey.gameButton9, + 297: PhysicalKeyboardKey.gameButton10, + 298: PhysicalKeyboardKey.gameButton11, + 299: PhysicalKeyboardKey.gameButton12, + 300: PhysicalKeyboardKey.gameButton13, + 301: PhysicalKeyboardKey.gameButton14, + 302: PhysicalKeyboardKey.gameButton15, + 303: PhysicalKeyboardKey.gameButton16, + 304: PhysicalKeyboardKey.gameButtonA, + 305: PhysicalKeyboardKey.gameButtonB, + 306: PhysicalKeyboardKey.gameButtonC, + 307: PhysicalKeyboardKey.gameButtonX, + 308: PhysicalKeyboardKey.gameButtonY, + 309: PhysicalKeyboardKey.gameButtonZ, + 310: PhysicalKeyboardKey.gameButtonLeft1, + 311: PhysicalKeyboardKey.gameButtonRight1, + 312: PhysicalKeyboardKey.gameButtonLeft2, + 313: PhysicalKeyboardKey.gameButtonRight2, + 314: PhysicalKeyboardKey.gameButtonSelect, + 315: PhysicalKeyboardKey.gameButtonStart, + 316: PhysicalKeyboardKey.gameButtonMode, + 317: PhysicalKeyboardKey.gameButtonThumbLeft, + 318: PhysicalKeyboardKey.gameButtonThumbRight, + 353: PhysicalKeyboardKey.select, + 358: PhysicalKeyboardKey.info, + 370: PhysicalKeyboardKey.closedCaptionToggle, + 397: PhysicalKeyboardKey.launchCalendar, + 402: PhysicalKeyboardKey.channelUp, + 403: PhysicalKeyboardKey.channelDown, + 405: PhysicalKeyboardKey.mediaLast, + 411: PhysicalKeyboardKey.pause, + 429: PhysicalKeyboardKey.launchContacts, + 464: PhysicalKeyboardKey.fn, + 583: PhysicalKeyboardKey.launchAssistant, +}; + +/// A map of Android key codes which have printable representations, but appear +/// on the number pad. Used to provide different key objects for keys like +/// KEY_EQUALS and NUMPAD_EQUALS. +const Map<int, LogicalKeyboardKey> kAndroidNumPadMap = <int, LogicalKeyboardKey>{ + 144: LogicalKeyboardKey.numpad0, + 145: LogicalKeyboardKey.numpad1, + 146: LogicalKeyboardKey.numpad2, + 147: LogicalKeyboardKey.numpad3, + 148: LogicalKeyboardKey.numpad4, + 149: LogicalKeyboardKey.numpad5, + 150: LogicalKeyboardKey.numpad6, + 151: LogicalKeyboardKey.numpad7, + 152: LogicalKeyboardKey.numpad8, + 153: LogicalKeyboardKey.numpad9, + 154: LogicalKeyboardKey.numpadDivide, + 155: LogicalKeyboardKey.numpadMultiply, + 156: LogicalKeyboardKey.numpadSubtract, + 157: LogicalKeyboardKey.numpadAdd, + 158: LogicalKeyboardKey.numpadDecimal, + 159: LogicalKeyboardKey.numpadComma, + 161: LogicalKeyboardKey.numpadEqual, + 162: LogicalKeyboardKey.numpadParenLeft, + 163: LogicalKeyboardKey.numpadParenRight, +}; + +/// Maps Fuchsia-specific IDs to the matching [LogicalKeyboardKey]. +const Map<int, LogicalKeyboardKey> kFuchsiaToLogicalKey = <int, LogicalKeyboardKey>{ + 0x1200000010: LogicalKeyboardKey.hyper, + 0x1200000011: LogicalKeyboardKey.superKey, + 0x1200000012: LogicalKeyboardKey.fn, + 0x1200000013: LogicalKeyboardKey.fnLock, + 0x1200000014: LogicalKeyboardKey.suspend, + 0x1200000015: LogicalKeyboardKey.resume, + 0x1200010082: LogicalKeyboardKey.sleep, + 0x1200010083: LogicalKeyboardKey.wakeUp, + 0x120005ff01: LogicalKeyboardKey.gameButton1, + 0x120005ff02: LogicalKeyboardKey.gameButton2, + 0x120005ff03: LogicalKeyboardKey.gameButton3, + 0x120005ff04: LogicalKeyboardKey.gameButton4, + 0x120005ff05: LogicalKeyboardKey.gameButton5, + 0x120005ff06: LogicalKeyboardKey.gameButton6, + 0x120005ff07: LogicalKeyboardKey.gameButton7, + 0x120005ff08: LogicalKeyboardKey.gameButton8, + 0x120005ff09: LogicalKeyboardKey.gameButton9, + 0x120005ff0a: LogicalKeyboardKey.gameButton10, + 0x120005ff0b: LogicalKeyboardKey.gameButton11, + 0x120005ff0c: LogicalKeyboardKey.gameButton12, + 0x120005ff0d: LogicalKeyboardKey.gameButton13, + 0x120005ff0e: LogicalKeyboardKey.gameButton14, + 0x120005ff0f: LogicalKeyboardKey.gameButton15, + 0x120005ff10: LogicalKeyboardKey.gameButton16, + 0x120005ff11: LogicalKeyboardKey.gameButtonA, + 0x120005ff12: LogicalKeyboardKey.gameButtonB, + 0x120005ff13: LogicalKeyboardKey.gameButtonC, + 0x120005ff14: LogicalKeyboardKey.gameButtonLeft1, + 0x120005ff15: LogicalKeyboardKey.gameButtonLeft2, + 0x120005ff16: LogicalKeyboardKey.gameButtonMode, + 0x120005ff17: LogicalKeyboardKey.gameButtonRight1, + 0x120005ff18: LogicalKeyboardKey.gameButtonRight2, + 0x120005ff19: LogicalKeyboardKey.gameButtonSelect, + 0x120005ff1a: LogicalKeyboardKey.gameButtonStart, + 0x120005ff1b: LogicalKeyboardKey.gameButtonThumbLeft, + 0x120005ff1c: LogicalKeyboardKey.gameButtonThumbRight, + 0x120005ff1d: LogicalKeyboardKey.gameButtonX, + 0x120005ff1e: LogicalKeyboardKey.gameButtonY, + 0x120005ff1f: LogicalKeyboardKey.gameButtonZ, + 0x1200070004: LogicalKeyboardKey.keyA, + 0x1200070005: LogicalKeyboardKey.keyB, + 0x1200070006: LogicalKeyboardKey.keyC, + 0x1200070007: LogicalKeyboardKey.keyD, + 0x1200070008: LogicalKeyboardKey.keyE, + 0x1200070009: LogicalKeyboardKey.keyF, + 0x120007000a: LogicalKeyboardKey.keyG, + 0x120007000b: LogicalKeyboardKey.keyH, + 0x120007000c: LogicalKeyboardKey.keyI, + 0x120007000d: LogicalKeyboardKey.keyJ, + 0x120007000e: LogicalKeyboardKey.keyK, + 0x120007000f: LogicalKeyboardKey.keyL, + 0x1200070010: LogicalKeyboardKey.keyM, + 0x1200070011: LogicalKeyboardKey.keyN, + 0x1200070012: LogicalKeyboardKey.keyO, + 0x1200070013: LogicalKeyboardKey.keyP, + 0x1200070014: LogicalKeyboardKey.keyQ, + 0x1200070015: LogicalKeyboardKey.keyR, + 0x1200070016: LogicalKeyboardKey.keyS, + 0x1200070017: LogicalKeyboardKey.keyT, + 0x1200070018: LogicalKeyboardKey.keyU, + 0x1200070019: LogicalKeyboardKey.keyV, + 0x120007001a: LogicalKeyboardKey.keyW, + 0x120007001b: LogicalKeyboardKey.keyX, + 0x120007001c: LogicalKeyboardKey.keyY, + 0x120007001d: LogicalKeyboardKey.keyZ, + 0x120007001e: LogicalKeyboardKey.digit1, + 0x120007001f: LogicalKeyboardKey.digit2, + 0x1200070020: LogicalKeyboardKey.digit3, + 0x1200070021: LogicalKeyboardKey.digit4, + 0x1200070022: LogicalKeyboardKey.digit5, + 0x1200070023: LogicalKeyboardKey.digit6, + 0x1200070024: LogicalKeyboardKey.digit7, + 0x1200070025: LogicalKeyboardKey.digit8, + 0x1200070026: LogicalKeyboardKey.digit9, + 0x1200070027: LogicalKeyboardKey.digit0, + 0x1200070028: LogicalKeyboardKey.enter, + 0x1200070029: LogicalKeyboardKey.escape, + 0x120007002a: LogicalKeyboardKey.backspace, + 0x120007002b: LogicalKeyboardKey.tab, + 0x120007002c: LogicalKeyboardKey.space, + 0x120007002d: LogicalKeyboardKey.minus, + 0x120007002e: LogicalKeyboardKey.equal, + 0x120007002f: LogicalKeyboardKey.bracketLeft, + 0x1200070030: LogicalKeyboardKey.bracketRight, + 0x1200070031: LogicalKeyboardKey.backslash, + 0x1200070033: LogicalKeyboardKey.semicolon, + 0x1200070034: LogicalKeyboardKey.quote, + 0x1200070035: LogicalKeyboardKey.backquote, + 0x1200070036: LogicalKeyboardKey.comma, + 0x1200070037: LogicalKeyboardKey.period, + 0x1200070038: LogicalKeyboardKey.slash, + 0x1200070039: LogicalKeyboardKey.capsLock, + 0x120007003a: LogicalKeyboardKey.f1, + 0x120007003b: LogicalKeyboardKey.f2, + 0x120007003c: LogicalKeyboardKey.f3, + 0x120007003d: LogicalKeyboardKey.f4, + 0x120007003e: LogicalKeyboardKey.f5, + 0x120007003f: LogicalKeyboardKey.f6, + 0x1200070040: LogicalKeyboardKey.f7, + 0x1200070041: LogicalKeyboardKey.f8, + 0x1200070042: LogicalKeyboardKey.f9, + 0x1200070043: LogicalKeyboardKey.f10, + 0x1200070044: LogicalKeyboardKey.f11, + 0x1200070045: LogicalKeyboardKey.f12, + 0x1200070046: LogicalKeyboardKey.printScreen, + 0x1200070047: LogicalKeyboardKey.scrollLock, + 0x1200070048: LogicalKeyboardKey.pause, + 0x1200070049: LogicalKeyboardKey.insert, + 0x120007004a: LogicalKeyboardKey.home, + 0x120007004b: LogicalKeyboardKey.pageUp, + 0x120007004c: LogicalKeyboardKey.delete, + 0x120007004d: LogicalKeyboardKey.end, + 0x120007004e: LogicalKeyboardKey.pageDown, + 0x120007004f: LogicalKeyboardKey.arrowRight, + 0x1200070050: LogicalKeyboardKey.arrowLeft, + 0x1200070051: LogicalKeyboardKey.arrowDown, + 0x1200070052: LogicalKeyboardKey.arrowUp, + 0x1200070053: LogicalKeyboardKey.numLock, + 0x1200070054: LogicalKeyboardKey.numpadDivide, + 0x1200070055: LogicalKeyboardKey.numpadMultiply, + 0x1200070056: LogicalKeyboardKey.numpadSubtract, + 0x1200070057: LogicalKeyboardKey.numpadAdd, + 0x1200070058: LogicalKeyboardKey.numpadEnter, + 0x1200070059: LogicalKeyboardKey.numpad1, + 0x120007005a: LogicalKeyboardKey.numpad2, + 0x120007005b: LogicalKeyboardKey.numpad3, + 0x120007005c: LogicalKeyboardKey.numpad4, + 0x120007005d: LogicalKeyboardKey.numpad5, + 0x120007005e: LogicalKeyboardKey.numpad6, + 0x120007005f: LogicalKeyboardKey.numpad7, + 0x1200070060: LogicalKeyboardKey.numpad8, + 0x1200070061: LogicalKeyboardKey.numpad9, + 0x1200070062: LogicalKeyboardKey.numpad0, + 0x1200070063: LogicalKeyboardKey.numpadDecimal, + 0x1200070064: LogicalKeyboardKey.intlBackslash, + 0x1200070065: LogicalKeyboardKey.contextMenu, + 0x1200070066: LogicalKeyboardKey.power, + 0x1200070067: LogicalKeyboardKey.numpadEqual, + 0x1200070068: LogicalKeyboardKey.f13, + 0x1200070069: LogicalKeyboardKey.f14, + 0x120007006a: LogicalKeyboardKey.f15, + 0x120007006b: LogicalKeyboardKey.f16, + 0x120007006c: LogicalKeyboardKey.f17, + 0x120007006d: LogicalKeyboardKey.f18, + 0x120007006e: LogicalKeyboardKey.f19, + 0x120007006f: LogicalKeyboardKey.f20, + 0x1200070070: LogicalKeyboardKey.f21, + 0x1200070071: LogicalKeyboardKey.f22, + 0x1200070072: LogicalKeyboardKey.f23, + 0x1200070073: LogicalKeyboardKey.f24, + 0x1200070074: LogicalKeyboardKey.open, + 0x1200070075: LogicalKeyboardKey.help, + 0x1200070077: LogicalKeyboardKey.select, + 0x1200070079: LogicalKeyboardKey.again, + 0x120007007a: LogicalKeyboardKey.undo, + 0x120007007b: LogicalKeyboardKey.cut, + 0x120007007c: LogicalKeyboardKey.copy, + 0x120007007d: LogicalKeyboardKey.paste, + 0x120007007e: LogicalKeyboardKey.find, + 0x120007007f: LogicalKeyboardKey.audioVolumeMute, + 0x1200070080: LogicalKeyboardKey.audioVolumeUp, + 0x1200070081: LogicalKeyboardKey.audioVolumeDown, + 0x1200070085: LogicalKeyboardKey.numpadComma, + 0x1200070087: LogicalKeyboardKey.intlRo, + 0x1200070088: LogicalKeyboardKey.kanaMode, + 0x1200070089: LogicalKeyboardKey.intlYen, + 0x120007008a: LogicalKeyboardKey.convert, + 0x120007008b: LogicalKeyboardKey.nonConvert, + 0x1200070090: LogicalKeyboardKey.lang1, + 0x1200070091: LogicalKeyboardKey.lang2, + 0x1200070092: LogicalKeyboardKey.lang3, + 0x1200070093: LogicalKeyboardKey.lang4, + 0x1200070094: LogicalKeyboardKey.lang5, + 0x120007009b: LogicalKeyboardKey.abort, + 0x12000700a3: LogicalKeyboardKey.props, + 0x12000700b6: LogicalKeyboardKey.numpadParenLeft, + 0x12000700b7: LogicalKeyboardKey.numpadParenRight, + 0x12000700e0: LogicalKeyboardKey.controlLeft, + 0x12000700e1: LogicalKeyboardKey.shiftLeft, + 0x12000700e2: LogicalKeyboardKey.altLeft, + 0x12000700e3: LogicalKeyboardKey.metaLeft, + 0x12000700e4: LogicalKeyboardKey.controlRight, + 0x12000700e5: LogicalKeyboardKey.shiftRight, + 0x12000700e6: LogicalKeyboardKey.altRight, + 0x12000700e7: LogicalKeyboardKey.metaRight, + 0x12000c0060: LogicalKeyboardKey.info, + 0x12000c0061: LogicalKeyboardKey.closedCaptionToggle, + 0x12000c006f: LogicalKeyboardKey.brightnessUp, + 0x12000c0070: LogicalKeyboardKey.brightnessDown, + 0x12000c0083: LogicalKeyboardKey.mediaLast, + 0x12000c008c: LogicalKeyboardKey.launchPhone, + 0x12000c0094: LogicalKeyboardKey.exit, + 0x12000c009c: LogicalKeyboardKey.channelUp, + 0x12000c009d: LogicalKeyboardKey.channelDown, + 0x12000c00b0: LogicalKeyboardKey.mediaPlay, + 0x12000c00b1: LogicalKeyboardKey.mediaPause, + 0x12000c00b2: LogicalKeyboardKey.mediaRecord, + 0x12000c00b3: LogicalKeyboardKey.mediaFastForward, + 0x12000c00b4: LogicalKeyboardKey.mediaRewind, + 0x12000c00b5: LogicalKeyboardKey.mediaTrackNext, + 0x12000c00b6: LogicalKeyboardKey.mediaTrackPrevious, + 0x12000c00b7: LogicalKeyboardKey.mediaStop, + 0x12000c00b8: LogicalKeyboardKey.eject, + 0x12000c00cd: LogicalKeyboardKey.mediaPlayPause, + 0x12000c00cf: LogicalKeyboardKey.speechInputToggle, + 0x12000c0184: LogicalKeyboardKey.launchWordProcessor, + 0x12000c0186: LogicalKeyboardKey.launchSpreadsheet, + 0x12000c018a: LogicalKeyboardKey.launchMail, + 0x12000c018d: LogicalKeyboardKey.launchContacts, + 0x12000c018e: LogicalKeyboardKey.launchCalendar, + 0x12000c019c: LogicalKeyboardKey.logOff, + 0x12000c019f: LogicalKeyboardKey.launchControlPanel, + 0x12000c01ab: LogicalKeyboardKey.spellCheck, + 0x12000c01b1: LogicalKeyboardKey.launchScreenSaver, + 0x12000c01cb: LogicalKeyboardKey.launchAssistant, + 0x12000c0201: LogicalKeyboardKey.newKey, + 0x12000c0203: LogicalKeyboardKey.close, + 0x12000c0207: LogicalKeyboardKey.save, + 0x12000c0208: LogicalKeyboardKey.print, + 0x12000c0221: LogicalKeyboardKey.browserSearch, + 0x12000c0223: LogicalKeyboardKey.browserHome, + 0x12000c0224: LogicalKeyboardKey.browserBack, + 0x12000c0225: LogicalKeyboardKey.browserForward, + 0x12000c0226: LogicalKeyboardKey.browserStop, + 0x12000c0227: LogicalKeyboardKey.browserRefresh, + 0x12000c022a: LogicalKeyboardKey.browserFavorites, + 0x12000c022d: LogicalKeyboardKey.zoomIn, + 0x12000c022e: LogicalKeyboardKey.zoomOut, + 0x12000c0232: LogicalKeyboardKey.zoomToggle, + 0x12000c0279: LogicalKeyboardKey.redo, + 0x12000c0289: LogicalKeyboardKey.mailReply, + 0x12000c028b: LogicalKeyboardKey.mailForward, + 0x12000c028c: LogicalKeyboardKey.mailSend, +}; + +/// Maps Fuchsia-specific USB HID Usage IDs to the matching +/// [PhysicalKeyboardKey]. +const Map<int, PhysicalKeyboardKey> kFuchsiaToPhysicalKey = <int, PhysicalKeyboardKey>{ + 0x00000010: PhysicalKeyboardKey.hyper, + 0x00000011: PhysicalKeyboardKey.superKey, + 0x00000012: PhysicalKeyboardKey.fn, + 0x00000013: PhysicalKeyboardKey.fnLock, + 0x00000014: PhysicalKeyboardKey.suspend, + 0x00000015: PhysicalKeyboardKey.resume, + 0x00000016: PhysicalKeyboardKey.turbo, + 0x00000017: PhysicalKeyboardKey.privacyScreenToggle, + 0x00000018: PhysicalKeyboardKey.microphoneMuteToggle, + 0x00010082: PhysicalKeyboardKey.sleep, + 0x00010083: PhysicalKeyboardKey.wakeUp, + 0x000100b5: PhysicalKeyboardKey.displayToggleIntExt, + 0x0005ff01: PhysicalKeyboardKey.gameButton1, + 0x0005ff02: PhysicalKeyboardKey.gameButton2, + 0x0005ff03: PhysicalKeyboardKey.gameButton3, + 0x0005ff04: PhysicalKeyboardKey.gameButton4, + 0x0005ff05: PhysicalKeyboardKey.gameButton5, + 0x0005ff06: PhysicalKeyboardKey.gameButton6, + 0x0005ff07: PhysicalKeyboardKey.gameButton7, + 0x0005ff08: PhysicalKeyboardKey.gameButton8, + 0x0005ff09: PhysicalKeyboardKey.gameButton9, + 0x0005ff0a: PhysicalKeyboardKey.gameButton10, + 0x0005ff0b: PhysicalKeyboardKey.gameButton11, + 0x0005ff0c: PhysicalKeyboardKey.gameButton12, + 0x0005ff0d: PhysicalKeyboardKey.gameButton13, + 0x0005ff0e: PhysicalKeyboardKey.gameButton14, + 0x0005ff0f: PhysicalKeyboardKey.gameButton15, + 0x0005ff10: PhysicalKeyboardKey.gameButton16, + 0x0005ff11: PhysicalKeyboardKey.gameButtonA, + 0x0005ff12: PhysicalKeyboardKey.gameButtonB, + 0x0005ff13: PhysicalKeyboardKey.gameButtonC, + 0x0005ff14: PhysicalKeyboardKey.gameButtonLeft1, + 0x0005ff15: PhysicalKeyboardKey.gameButtonLeft2, + 0x0005ff16: PhysicalKeyboardKey.gameButtonMode, + 0x0005ff17: PhysicalKeyboardKey.gameButtonRight1, + 0x0005ff18: PhysicalKeyboardKey.gameButtonRight2, + 0x0005ff19: PhysicalKeyboardKey.gameButtonSelect, + 0x0005ff1a: PhysicalKeyboardKey.gameButtonStart, + 0x0005ff1b: PhysicalKeyboardKey.gameButtonThumbLeft, + 0x0005ff1c: PhysicalKeyboardKey.gameButtonThumbRight, + 0x0005ff1d: PhysicalKeyboardKey.gameButtonX, + 0x0005ff1e: PhysicalKeyboardKey.gameButtonY, + 0x0005ff1f: PhysicalKeyboardKey.gameButtonZ, + 0x00070000: PhysicalKeyboardKey.usbReserved, + 0x00070001: PhysicalKeyboardKey.usbErrorRollOver, + 0x00070002: PhysicalKeyboardKey.usbPostFail, + 0x00070003: PhysicalKeyboardKey.usbErrorUndefined, + 0x00070004: PhysicalKeyboardKey.keyA, + 0x00070005: PhysicalKeyboardKey.keyB, + 0x00070006: PhysicalKeyboardKey.keyC, + 0x00070007: PhysicalKeyboardKey.keyD, + 0x00070008: PhysicalKeyboardKey.keyE, + 0x00070009: PhysicalKeyboardKey.keyF, + 0x0007000a: PhysicalKeyboardKey.keyG, + 0x0007000b: PhysicalKeyboardKey.keyH, + 0x0007000c: PhysicalKeyboardKey.keyI, + 0x0007000d: PhysicalKeyboardKey.keyJ, + 0x0007000e: PhysicalKeyboardKey.keyK, + 0x0007000f: PhysicalKeyboardKey.keyL, + 0x00070010: PhysicalKeyboardKey.keyM, + 0x00070011: PhysicalKeyboardKey.keyN, + 0x00070012: PhysicalKeyboardKey.keyO, + 0x00070013: PhysicalKeyboardKey.keyP, + 0x00070014: PhysicalKeyboardKey.keyQ, + 0x00070015: PhysicalKeyboardKey.keyR, + 0x00070016: PhysicalKeyboardKey.keyS, + 0x00070017: PhysicalKeyboardKey.keyT, + 0x00070018: PhysicalKeyboardKey.keyU, + 0x00070019: PhysicalKeyboardKey.keyV, + 0x0007001a: PhysicalKeyboardKey.keyW, + 0x0007001b: PhysicalKeyboardKey.keyX, + 0x0007001c: PhysicalKeyboardKey.keyY, + 0x0007001d: PhysicalKeyboardKey.keyZ, + 0x0007001e: PhysicalKeyboardKey.digit1, + 0x0007001f: PhysicalKeyboardKey.digit2, + 0x00070020: PhysicalKeyboardKey.digit3, + 0x00070021: PhysicalKeyboardKey.digit4, + 0x00070022: PhysicalKeyboardKey.digit5, + 0x00070023: PhysicalKeyboardKey.digit6, + 0x00070024: PhysicalKeyboardKey.digit7, + 0x00070025: PhysicalKeyboardKey.digit8, + 0x00070026: PhysicalKeyboardKey.digit9, + 0x00070027: PhysicalKeyboardKey.digit0, + 0x00070028: PhysicalKeyboardKey.enter, + 0x00070029: PhysicalKeyboardKey.escape, + 0x0007002a: PhysicalKeyboardKey.backspace, + 0x0007002b: PhysicalKeyboardKey.tab, + 0x0007002c: PhysicalKeyboardKey.space, + 0x0007002d: PhysicalKeyboardKey.minus, + 0x0007002e: PhysicalKeyboardKey.equal, + 0x0007002f: PhysicalKeyboardKey.bracketLeft, + 0x00070030: PhysicalKeyboardKey.bracketRight, + 0x00070031: PhysicalKeyboardKey.backslash, + 0x00070033: PhysicalKeyboardKey.semicolon, + 0x00070034: PhysicalKeyboardKey.quote, + 0x00070035: PhysicalKeyboardKey.backquote, + 0x00070036: PhysicalKeyboardKey.comma, + 0x00070037: PhysicalKeyboardKey.period, + 0x00070038: PhysicalKeyboardKey.slash, + 0x00070039: PhysicalKeyboardKey.capsLock, + 0x0007003a: PhysicalKeyboardKey.f1, + 0x0007003b: PhysicalKeyboardKey.f2, + 0x0007003c: PhysicalKeyboardKey.f3, + 0x0007003d: PhysicalKeyboardKey.f4, + 0x0007003e: PhysicalKeyboardKey.f5, + 0x0007003f: PhysicalKeyboardKey.f6, + 0x00070040: PhysicalKeyboardKey.f7, + 0x00070041: PhysicalKeyboardKey.f8, + 0x00070042: PhysicalKeyboardKey.f9, + 0x00070043: PhysicalKeyboardKey.f10, + 0x00070044: PhysicalKeyboardKey.f11, + 0x00070045: PhysicalKeyboardKey.f12, + 0x00070046: PhysicalKeyboardKey.printScreen, + 0x00070047: PhysicalKeyboardKey.scrollLock, + 0x00070048: PhysicalKeyboardKey.pause, + 0x00070049: PhysicalKeyboardKey.insert, + 0x0007004a: PhysicalKeyboardKey.home, + 0x0007004b: PhysicalKeyboardKey.pageUp, + 0x0007004c: PhysicalKeyboardKey.delete, + 0x0007004d: PhysicalKeyboardKey.end, + 0x0007004e: PhysicalKeyboardKey.pageDown, + 0x0007004f: PhysicalKeyboardKey.arrowRight, + 0x00070050: PhysicalKeyboardKey.arrowLeft, + 0x00070051: PhysicalKeyboardKey.arrowDown, + 0x00070052: PhysicalKeyboardKey.arrowUp, + 0x00070053: PhysicalKeyboardKey.numLock, + 0x00070054: PhysicalKeyboardKey.numpadDivide, + 0x00070055: PhysicalKeyboardKey.numpadMultiply, + 0x00070056: PhysicalKeyboardKey.numpadSubtract, + 0x00070057: PhysicalKeyboardKey.numpadAdd, + 0x00070058: PhysicalKeyboardKey.numpadEnter, + 0x00070059: PhysicalKeyboardKey.numpad1, + 0x0007005a: PhysicalKeyboardKey.numpad2, + 0x0007005b: PhysicalKeyboardKey.numpad3, + 0x0007005c: PhysicalKeyboardKey.numpad4, + 0x0007005d: PhysicalKeyboardKey.numpad5, + 0x0007005e: PhysicalKeyboardKey.numpad6, + 0x0007005f: PhysicalKeyboardKey.numpad7, + 0x00070060: PhysicalKeyboardKey.numpad8, + 0x00070061: PhysicalKeyboardKey.numpad9, + 0x00070062: PhysicalKeyboardKey.numpad0, + 0x00070063: PhysicalKeyboardKey.numpadDecimal, + 0x00070064: PhysicalKeyboardKey.intlBackslash, + 0x00070065: PhysicalKeyboardKey.contextMenu, + 0x00070066: PhysicalKeyboardKey.power, + 0x00070067: PhysicalKeyboardKey.numpadEqual, + 0x00070068: PhysicalKeyboardKey.f13, + 0x00070069: PhysicalKeyboardKey.f14, + 0x0007006a: PhysicalKeyboardKey.f15, + 0x0007006b: PhysicalKeyboardKey.f16, + 0x0007006c: PhysicalKeyboardKey.f17, + 0x0007006d: PhysicalKeyboardKey.f18, + 0x0007006e: PhysicalKeyboardKey.f19, + 0x0007006f: PhysicalKeyboardKey.f20, + 0x00070070: PhysicalKeyboardKey.f21, + 0x00070071: PhysicalKeyboardKey.f22, + 0x00070072: PhysicalKeyboardKey.f23, + 0x00070073: PhysicalKeyboardKey.f24, + 0x00070074: PhysicalKeyboardKey.open, + 0x00070075: PhysicalKeyboardKey.help, + 0x00070077: PhysicalKeyboardKey.select, + 0x00070079: PhysicalKeyboardKey.again, + 0x0007007a: PhysicalKeyboardKey.undo, + 0x0007007b: PhysicalKeyboardKey.cut, + 0x0007007c: PhysicalKeyboardKey.copy, + 0x0007007d: PhysicalKeyboardKey.paste, + 0x0007007e: PhysicalKeyboardKey.find, + 0x0007007f: PhysicalKeyboardKey.audioVolumeMute, + 0x00070080: PhysicalKeyboardKey.audioVolumeUp, + 0x00070081: PhysicalKeyboardKey.audioVolumeDown, + 0x00070085: PhysicalKeyboardKey.numpadComma, + 0x00070087: PhysicalKeyboardKey.intlRo, + 0x00070088: PhysicalKeyboardKey.kanaMode, + 0x00070089: PhysicalKeyboardKey.intlYen, + 0x0007008a: PhysicalKeyboardKey.convert, + 0x0007008b: PhysicalKeyboardKey.nonConvert, + 0x00070090: PhysicalKeyboardKey.lang1, + 0x00070091: PhysicalKeyboardKey.lang2, + 0x00070092: PhysicalKeyboardKey.lang3, + 0x00070093: PhysicalKeyboardKey.lang4, + 0x00070094: PhysicalKeyboardKey.lang5, + 0x0007009b: PhysicalKeyboardKey.abort, + 0x000700a3: PhysicalKeyboardKey.props, + 0x000700b6: PhysicalKeyboardKey.numpadParenLeft, + 0x000700b7: PhysicalKeyboardKey.numpadParenRight, + 0x000700bb: PhysicalKeyboardKey.numpadBackspace, + 0x000700d0: PhysicalKeyboardKey.numpadMemoryStore, + 0x000700d1: PhysicalKeyboardKey.numpadMemoryRecall, + 0x000700d2: PhysicalKeyboardKey.numpadMemoryClear, + 0x000700d3: PhysicalKeyboardKey.numpadMemoryAdd, + 0x000700d4: PhysicalKeyboardKey.numpadMemorySubtract, + 0x000700d7: PhysicalKeyboardKey.numpadSignChange, + 0x000700d8: PhysicalKeyboardKey.numpadClear, + 0x000700d9: PhysicalKeyboardKey.numpadClearEntry, + 0x000700e0: PhysicalKeyboardKey.controlLeft, + 0x000700e1: PhysicalKeyboardKey.shiftLeft, + 0x000700e2: PhysicalKeyboardKey.altLeft, + 0x000700e3: PhysicalKeyboardKey.metaLeft, + 0x000700e4: PhysicalKeyboardKey.controlRight, + 0x000700e5: PhysicalKeyboardKey.shiftRight, + 0x000700e6: PhysicalKeyboardKey.altRight, + 0x000700e7: PhysicalKeyboardKey.metaRight, + 0x000c0060: PhysicalKeyboardKey.info, + 0x000c0061: PhysicalKeyboardKey.closedCaptionToggle, + 0x000c006f: PhysicalKeyboardKey.brightnessUp, + 0x000c0070: PhysicalKeyboardKey.brightnessDown, + 0x000c0072: PhysicalKeyboardKey.brightnessToggle, + 0x000c0073: PhysicalKeyboardKey.brightnessMinimum, + 0x000c0074: PhysicalKeyboardKey.brightnessMaximum, + 0x000c0075: PhysicalKeyboardKey.brightnessAuto, + 0x000c0079: PhysicalKeyboardKey.kbdIllumUp, + 0x000c007a: PhysicalKeyboardKey.kbdIllumDown, + 0x000c0083: PhysicalKeyboardKey.mediaLast, + 0x000c008c: PhysicalKeyboardKey.launchPhone, + 0x000c008d: PhysicalKeyboardKey.programGuide, + 0x000c0094: PhysicalKeyboardKey.exit, + 0x000c009c: PhysicalKeyboardKey.channelUp, + 0x000c009d: PhysicalKeyboardKey.channelDown, + 0x000c00b0: PhysicalKeyboardKey.mediaPlay, + 0x000c00b1: PhysicalKeyboardKey.mediaPause, + 0x000c00b2: PhysicalKeyboardKey.mediaRecord, + 0x000c00b3: PhysicalKeyboardKey.mediaFastForward, + 0x000c00b4: PhysicalKeyboardKey.mediaRewind, + 0x000c00b5: PhysicalKeyboardKey.mediaTrackNext, + 0x000c00b6: PhysicalKeyboardKey.mediaTrackPrevious, + 0x000c00b7: PhysicalKeyboardKey.mediaStop, + 0x000c00b8: PhysicalKeyboardKey.eject, + 0x000c00cd: PhysicalKeyboardKey.mediaPlayPause, + 0x000c00cf: PhysicalKeyboardKey.speechInputToggle, + 0x000c00e5: PhysicalKeyboardKey.bassBoost, + 0x000c0183: PhysicalKeyboardKey.mediaSelect, + 0x000c0184: PhysicalKeyboardKey.launchWordProcessor, + 0x000c0186: PhysicalKeyboardKey.launchSpreadsheet, + 0x000c018a: PhysicalKeyboardKey.launchMail, + 0x000c018d: PhysicalKeyboardKey.launchContacts, + 0x000c018e: PhysicalKeyboardKey.launchCalendar, + 0x000c0192: PhysicalKeyboardKey.launchApp2, + 0x000c0194: PhysicalKeyboardKey.launchApp1, + 0x000c0196: PhysicalKeyboardKey.launchInternetBrowser, + 0x000c019c: PhysicalKeyboardKey.logOff, + 0x000c019e: PhysicalKeyboardKey.lockScreen, + 0x000c019f: PhysicalKeyboardKey.launchControlPanel, + 0x000c01a2: PhysicalKeyboardKey.selectTask, + 0x000c01a7: PhysicalKeyboardKey.launchDocuments, + 0x000c01ab: PhysicalKeyboardKey.spellCheck, + 0x000c01ae: PhysicalKeyboardKey.launchKeyboardLayout, + 0x000c01b1: PhysicalKeyboardKey.launchScreenSaver, + 0x000c01b7: PhysicalKeyboardKey.launchAudioBrowser, + 0x000c01cb: PhysicalKeyboardKey.launchAssistant, + 0x000c0201: PhysicalKeyboardKey.newKey, + 0x000c0203: PhysicalKeyboardKey.close, + 0x000c0207: PhysicalKeyboardKey.save, + 0x000c0208: PhysicalKeyboardKey.print, + 0x000c0221: PhysicalKeyboardKey.browserSearch, + 0x000c0223: PhysicalKeyboardKey.browserHome, + 0x000c0224: PhysicalKeyboardKey.browserBack, + 0x000c0225: PhysicalKeyboardKey.browserForward, + 0x000c0226: PhysicalKeyboardKey.browserStop, + 0x000c0227: PhysicalKeyboardKey.browserRefresh, + 0x000c022a: PhysicalKeyboardKey.browserFavorites, + 0x000c022d: PhysicalKeyboardKey.zoomIn, + 0x000c022e: PhysicalKeyboardKey.zoomOut, + 0x000c0232: PhysicalKeyboardKey.zoomToggle, + 0x000c0279: PhysicalKeyboardKey.redo, + 0x000c0289: PhysicalKeyboardKey.mailReply, + 0x000c028b: PhysicalKeyboardKey.mailForward, + 0x000c028c: PhysicalKeyboardKey.mailSend, + 0x000c029d: PhysicalKeyboardKey.keyboardLayoutSelect, + 0x000c029f: PhysicalKeyboardKey.showAllWindows, +}; + +/// Maps macOS-specific key code values representing [PhysicalKeyboardKey]. +/// +/// MacOS doesn't provide a scan code, but a virtual keycode to represent a physical key. +const Map<int, PhysicalKeyboardKey> kMacOsToPhysicalKey = <int, PhysicalKeyboardKey>{ + 0x00000000: PhysicalKeyboardKey.keyA, + 0x00000001: PhysicalKeyboardKey.keyS, + 0x00000002: PhysicalKeyboardKey.keyD, + 0x00000003: PhysicalKeyboardKey.keyF, + 0x00000004: PhysicalKeyboardKey.keyH, + 0x00000005: PhysicalKeyboardKey.keyG, + 0x00000006: PhysicalKeyboardKey.keyZ, + 0x00000007: PhysicalKeyboardKey.keyX, + 0x00000008: PhysicalKeyboardKey.keyC, + 0x00000009: PhysicalKeyboardKey.keyV, + 0x0000000a: PhysicalKeyboardKey.intlBackslash, + 0x0000000b: PhysicalKeyboardKey.keyB, + 0x0000000c: PhysicalKeyboardKey.keyQ, + 0x0000000d: PhysicalKeyboardKey.keyW, + 0x0000000e: PhysicalKeyboardKey.keyE, + 0x0000000f: PhysicalKeyboardKey.keyR, + 0x00000010: PhysicalKeyboardKey.keyY, + 0x00000011: PhysicalKeyboardKey.keyT, + 0x00000012: PhysicalKeyboardKey.digit1, + 0x00000013: PhysicalKeyboardKey.digit2, + 0x00000014: PhysicalKeyboardKey.digit3, + 0x00000015: PhysicalKeyboardKey.digit4, + 0x00000016: PhysicalKeyboardKey.digit6, + 0x00000017: PhysicalKeyboardKey.digit5, + 0x00000018: PhysicalKeyboardKey.equal, + 0x00000019: PhysicalKeyboardKey.digit9, + 0x0000001a: PhysicalKeyboardKey.digit7, + 0x0000001b: PhysicalKeyboardKey.minus, + 0x0000001c: PhysicalKeyboardKey.digit8, + 0x0000001d: PhysicalKeyboardKey.digit0, + 0x0000001e: PhysicalKeyboardKey.bracketRight, + 0x0000001f: PhysicalKeyboardKey.keyO, + 0x00000020: PhysicalKeyboardKey.keyU, + 0x00000021: PhysicalKeyboardKey.bracketLeft, + 0x00000022: PhysicalKeyboardKey.keyI, + 0x00000023: PhysicalKeyboardKey.keyP, + 0x00000024: PhysicalKeyboardKey.enter, + 0x00000025: PhysicalKeyboardKey.keyL, + 0x00000026: PhysicalKeyboardKey.keyJ, + 0x00000027: PhysicalKeyboardKey.quote, + 0x00000028: PhysicalKeyboardKey.keyK, + 0x00000029: PhysicalKeyboardKey.semicolon, + 0x0000002a: PhysicalKeyboardKey.backslash, + 0x0000002b: PhysicalKeyboardKey.comma, + 0x0000002c: PhysicalKeyboardKey.slash, + 0x0000002d: PhysicalKeyboardKey.keyN, + 0x0000002e: PhysicalKeyboardKey.keyM, + 0x0000002f: PhysicalKeyboardKey.period, + 0x00000030: PhysicalKeyboardKey.tab, + 0x00000031: PhysicalKeyboardKey.space, + 0x00000032: PhysicalKeyboardKey.backquote, + 0x00000033: PhysicalKeyboardKey.backspace, + 0x00000035: PhysicalKeyboardKey.escape, + 0x00000036: PhysicalKeyboardKey.metaRight, + 0x00000037: PhysicalKeyboardKey.metaLeft, + 0x00000038: PhysicalKeyboardKey.shiftLeft, + 0x00000039: PhysicalKeyboardKey.capsLock, + 0x0000003a: PhysicalKeyboardKey.altLeft, + 0x0000003b: PhysicalKeyboardKey.controlLeft, + 0x0000003c: PhysicalKeyboardKey.shiftRight, + 0x0000003d: PhysicalKeyboardKey.altRight, + 0x0000003e: PhysicalKeyboardKey.controlRight, + 0x0000003f: PhysicalKeyboardKey.fn, + 0x00000040: PhysicalKeyboardKey.f17, + 0x00000041: PhysicalKeyboardKey.numpadDecimal, + 0x00000043: PhysicalKeyboardKey.numpadMultiply, + 0x00000045: PhysicalKeyboardKey.numpadAdd, + 0x00000047: PhysicalKeyboardKey.numLock, + 0x00000048: PhysicalKeyboardKey.audioVolumeUp, + 0x00000049: PhysicalKeyboardKey.audioVolumeDown, + 0x0000004a: PhysicalKeyboardKey.audioVolumeMute, + 0x0000004b: PhysicalKeyboardKey.numpadDivide, + 0x0000004c: PhysicalKeyboardKey.numpadEnter, + 0x0000004e: PhysicalKeyboardKey.numpadSubtract, + 0x0000004f: PhysicalKeyboardKey.f18, + 0x00000050: PhysicalKeyboardKey.f19, + 0x00000051: PhysicalKeyboardKey.numpadEqual, + 0x00000052: PhysicalKeyboardKey.numpad0, + 0x00000053: PhysicalKeyboardKey.numpad1, + 0x00000054: PhysicalKeyboardKey.numpad2, + 0x00000055: PhysicalKeyboardKey.numpad3, + 0x00000056: PhysicalKeyboardKey.numpad4, + 0x00000057: PhysicalKeyboardKey.numpad5, + 0x00000058: PhysicalKeyboardKey.numpad6, + 0x00000059: PhysicalKeyboardKey.numpad7, + 0x0000005a: PhysicalKeyboardKey.f20, + 0x0000005b: PhysicalKeyboardKey.numpad8, + 0x0000005c: PhysicalKeyboardKey.numpad9, + 0x0000005d: PhysicalKeyboardKey.intlYen, + 0x0000005e: PhysicalKeyboardKey.intlRo, + 0x0000005f: PhysicalKeyboardKey.numpadComma, + 0x00000060: PhysicalKeyboardKey.f5, + 0x00000061: PhysicalKeyboardKey.f6, + 0x00000062: PhysicalKeyboardKey.f7, + 0x00000063: PhysicalKeyboardKey.f3, + 0x00000064: PhysicalKeyboardKey.f8, + 0x00000065: PhysicalKeyboardKey.f9, + 0x00000066: PhysicalKeyboardKey.lang2, + 0x00000067: PhysicalKeyboardKey.f11, + 0x00000068: PhysicalKeyboardKey.lang1, + 0x00000069: PhysicalKeyboardKey.f13, + 0x0000006a: PhysicalKeyboardKey.f16, + 0x0000006b: PhysicalKeyboardKey.f14, + 0x0000006d: PhysicalKeyboardKey.f10, + 0x0000006e: PhysicalKeyboardKey.contextMenu, + 0x0000006f: PhysicalKeyboardKey.f12, + 0x00000071: PhysicalKeyboardKey.f15, + 0x00000072: PhysicalKeyboardKey.insert, + 0x00000073: PhysicalKeyboardKey.home, + 0x00000074: PhysicalKeyboardKey.pageUp, + 0x00000075: PhysicalKeyboardKey.delete, + 0x00000076: PhysicalKeyboardKey.f4, + 0x00000077: PhysicalKeyboardKey.end, + 0x00000078: PhysicalKeyboardKey.f2, + 0x00000079: PhysicalKeyboardKey.pageDown, + 0x0000007a: PhysicalKeyboardKey.f1, + 0x0000007b: PhysicalKeyboardKey.arrowLeft, + 0x0000007c: PhysicalKeyboardKey.arrowRight, + 0x0000007d: PhysicalKeyboardKey.arrowDown, + 0x0000007e: PhysicalKeyboardKey.arrowUp, +}; + +/// A map of macOS key codes which have printable representations, but appear +/// on the number pad. Used to provide different key objects for keys like +/// KEY_EQUALS and NUMPAD_EQUALS. +const Map<int, LogicalKeyboardKey> kMacOsNumPadMap = <int, LogicalKeyboardKey>{ + 0x00000041: LogicalKeyboardKey.numpadDecimal, + 0x00000043: LogicalKeyboardKey.numpadMultiply, + 0x00000045: LogicalKeyboardKey.numpadAdd, + 0x0000004b: LogicalKeyboardKey.numpadDivide, + 0x0000004e: LogicalKeyboardKey.numpadSubtract, + 0x00000051: LogicalKeyboardKey.numpadEqual, + 0x00000052: LogicalKeyboardKey.numpad0, + 0x00000053: LogicalKeyboardKey.numpad1, + 0x00000054: LogicalKeyboardKey.numpad2, + 0x00000055: LogicalKeyboardKey.numpad3, + 0x00000056: LogicalKeyboardKey.numpad4, + 0x00000057: LogicalKeyboardKey.numpad5, + 0x00000058: LogicalKeyboardKey.numpad6, + 0x00000059: LogicalKeyboardKey.numpad7, + 0x0000005b: LogicalKeyboardKey.numpad8, + 0x0000005c: LogicalKeyboardKey.numpad9, + 0x0000005f: LogicalKeyboardKey.numpadComma, +}; + +/// A map of macOS key codes which are numbered function keys, so that they +/// can be excluded when asking "is the Fn modifier down?". +const Map<int, LogicalKeyboardKey> kMacOsFunctionKeyMap = <int, LogicalKeyboardKey>{ + 0x00000040: LogicalKeyboardKey.f17, + 0x0000004f: LogicalKeyboardKey.f18, + 0x00000050: LogicalKeyboardKey.f19, + 0x0000005a: LogicalKeyboardKey.f20, + 0x00000060: LogicalKeyboardKey.f5, + 0x00000061: LogicalKeyboardKey.f6, + 0x00000062: LogicalKeyboardKey.f7, + 0x00000063: LogicalKeyboardKey.f3, + 0x00000064: LogicalKeyboardKey.f8, + 0x00000065: LogicalKeyboardKey.f9, + 0x00000067: LogicalKeyboardKey.f11, + 0x00000069: LogicalKeyboardKey.f13, + 0x0000006a: LogicalKeyboardKey.f16, + 0x0000006b: LogicalKeyboardKey.f14, + 0x0000006d: LogicalKeyboardKey.f10, + 0x0000006f: LogicalKeyboardKey.f12, + 0x00000071: LogicalKeyboardKey.f15, + 0x00000076: LogicalKeyboardKey.f4, + 0x00000078: LogicalKeyboardKey.f2, + 0x0000007a: LogicalKeyboardKey.f1, +}; + +/// A map of macOS key codes presenting [LogicalKeyboardKey]. +/// +/// Logical key codes are not available in macOS key events. Most of the logical keys +/// are derived from its `characterIgnoringModifiers`, but those keys that don't +/// have a character representation will be derived from their key codes using +/// this map. +const Map<int, LogicalKeyboardKey> kMacOsToLogicalKey = <int, LogicalKeyboardKey>{ + 36: LogicalKeyboardKey.enter, + 48: LogicalKeyboardKey.tab, + 51: LogicalKeyboardKey.backspace, + 53: LogicalKeyboardKey.escape, + 54: LogicalKeyboardKey.metaRight, + 55: LogicalKeyboardKey.metaLeft, + 56: LogicalKeyboardKey.shiftLeft, + 57: LogicalKeyboardKey.capsLock, + 58: LogicalKeyboardKey.altLeft, + 59: LogicalKeyboardKey.controlLeft, + 60: LogicalKeyboardKey.shiftRight, + 61: LogicalKeyboardKey.altRight, + 62: LogicalKeyboardKey.controlRight, + 63: LogicalKeyboardKey.fn, + 64: LogicalKeyboardKey.f17, + 65: LogicalKeyboardKey.numpadDecimal, + 67: LogicalKeyboardKey.numpadMultiply, + 69: LogicalKeyboardKey.numpadAdd, + 71: LogicalKeyboardKey.numLock, + 72: LogicalKeyboardKey.audioVolumeUp, + 73: LogicalKeyboardKey.audioVolumeDown, + 74: LogicalKeyboardKey.audioVolumeMute, + 75: LogicalKeyboardKey.numpadDivide, + 76: LogicalKeyboardKey.numpadEnter, + 78: LogicalKeyboardKey.numpadSubtract, + 79: LogicalKeyboardKey.f18, + 80: LogicalKeyboardKey.f19, + 81: LogicalKeyboardKey.numpadEqual, + 82: LogicalKeyboardKey.numpad0, + 83: LogicalKeyboardKey.numpad1, + 84: LogicalKeyboardKey.numpad2, + 85: LogicalKeyboardKey.numpad3, + 86: LogicalKeyboardKey.numpad4, + 87: LogicalKeyboardKey.numpad5, + 88: LogicalKeyboardKey.numpad6, + 89: LogicalKeyboardKey.numpad7, + 90: LogicalKeyboardKey.f20, + 91: LogicalKeyboardKey.numpad8, + 92: LogicalKeyboardKey.numpad9, + 93: LogicalKeyboardKey.intlYen, + 94: LogicalKeyboardKey.intlRo, + 95: LogicalKeyboardKey.numpadComma, + 96: LogicalKeyboardKey.f5, + 97: LogicalKeyboardKey.f6, + 98: LogicalKeyboardKey.f7, + 99: LogicalKeyboardKey.f3, + 100: LogicalKeyboardKey.f8, + 101: LogicalKeyboardKey.f9, + 102: LogicalKeyboardKey.lang2, + 103: LogicalKeyboardKey.f11, + 104: LogicalKeyboardKey.lang1, + 105: LogicalKeyboardKey.f13, + 106: LogicalKeyboardKey.f16, + 107: LogicalKeyboardKey.f14, + 109: LogicalKeyboardKey.f10, + 110: LogicalKeyboardKey.contextMenu, + 111: LogicalKeyboardKey.f12, + 113: LogicalKeyboardKey.f15, + 114: LogicalKeyboardKey.insert, + 115: LogicalKeyboardKey.home, + 116: LogicalKeyboardKey.pageUp, + 117: LogicalKeyboardKey.delete, + 118: LogicalKeyboardKey.f4, + 119: LogicalKeyboardKey.end, + 120: LogicalKeyboardKey.f2, + 121: LogicalKeyboardKey.pageDown, + 122: LogicalKeyboardKey.f1, + 123: LogicalKeyboardKey.arrowLeft, + 124: LogicalKeyboardKey.arrowRight, + 125: LogicalKeyboardKey.arrowDown, + 126: LogicalKeyboardKey.arrowUp, +}; + +/// Maps iOS-specific key code values representing [PhysicalKeyboardKey]. +/// +/// iOS doesn't provide a scan code, but a virtual keycode to represent a physical key. +const Map<int, PhysicalKeyboardKey> kIosToPhysicalKey = <int, PhysicalKeyboardKey>{ + 0x00000000: PhysicalKeyboardKey.usbReserved, + 0x00000001: PhysicalKeyboardKey.usbErrorRollOver, + 0x00000002: PhysicalKeyboardKey.usbPostFail, + 0x00000003: PhysicalKeyboardKey.usbErrorUndefined, + 0x00000004: PhysicalKeyboardKey.keyA, + 0x00000005: PhysicalKeyboardKey.keyB, + 0x00000006: PhysicalKeyboardKey.keyC, + 0x00000007: PhysicalKeyboardKey.keyD, + 0x00000008: PhysicalKeyboardKey.keyE, + 0x00000009: PhysicalKeyboardKey.keyF, + 0x0000000a: PhysicalKeyboardKey.keyG, + 0x0000000b: PhysicalKeyboardKey.keyH, + 0x0000000c: PhysicalKeyboardKey.keyI, + 0x0000000d: PhysicalKeyboardKey.keyJ, + 0x0000000e: PhysicalKeyboardKey.keyK, + 0x0000000f: PhysicalKeyboardKey.keyL, + 0x00000010: PhysicalKeyboardKey.keyM, + 0x00000011: PhysicalKeyboardKey.keyN, + 0x00000012: PhysicalKeyboardKey.keyO, + 0x00000013: PhysicalKeyboardKey.keyP, + 0x00000014: PhysicalKeyboardKey.keyQ, + 0x00000015: PhysicalKeyboardKey.keyR, + 0x00000016: PhysicalKeyboardKey.keyS, + 0x00000017: PhysicalKeyboardKey.keyT, + 0x00000018: PhysicalKeyboardKey.keyU, + 0x00000019: PhysicalKeyboardKey.keyV, + 0x0000001a: PhysicalKeyboardKey.keyW, + 0x0000001b: PhysicalKeyboardKey.keyX, + 0x0000001c: PhysicalKeyboardKey.keyY, + 0x0000001d: PhysicalKeyboardKey.keyZ, + 0x0000001e: PhysicalKeyboardKey.digit1, + 0x0000001f: PhysicalKeyboardKey.digit2, + 0x00000020: PhysicalKeyboardKey.digit3, + 0x00000021: PhysicalKeyboardKey.digit4, + 0x00000022: PhysicalKeyboardKey.digit5, + 0x00000023: PhysicalKeyboardKey.digit6, + 0x00000024: PhysicalKeyboardKey.digit7, + 0x00000025: PhysicalKeyboardKey.digit8, + 0x00000026: PhysicalKeyboardKey.digit9, + 0x00000027: PhysicalKeyboardKey.digit0, + 0x00000028: PhysicalKeyboardKey.enter, + 0x00000029: PhysicalKeyboardKey.escape, + 0x0000002a: PhysicalKeyboardKey.backspace, + 0x0000002b: PhysicalKeyboardKey.tab, + 0x0000002c: PhysicalKeyboardKey.space, + 0x0000002d: PhysicalKeyboardKey.minus, + 0x0000002e: PhysicalKeyboardKey.equal, + 0x0000002f: PhysicalKeyboardKey.bracketLeft, + 0x00000030: PhysicalKeyboardKey.bracketRight, + 0x00000031: PhysicalKeyboardKey.backslash, + 0x00000033: PhysicalKeyboardKey.semicolon, + 0x00000034: PhysicalKeyboardKey.quote, + 0x00000035: PhysicalKeyboardKey.backquote, + 0x00000036: PhysicalKeyboardKey.comma, + 0x00000037: PhysicalKeyboardKey.period, + 0x00000038: PhysicalKeyboardKey.slash, + 0x00000039: PhysicalKeyboardKey.capsLock, + 0x0000003a: PhysicalKeyboardKey.f1, + 0x0000003b: PhysicalKeyboardKey.f2, + 0x0000003c: PhysicalKeyboardKey.f3, + 0x0000003d: PhysicalKeyboardKey.f4, + 0x0000003e: PhysicalKeyboardKey.f5, + 0x0000003f: PhysicalKeyboardKey.f6, + 0x00000040: PhysicalKeyboardKey.f7, + 0x00000041: PhysicalKeyboardKey.f8, + 0x00000042: PhysicalKeyboardKey.f9, + 0x00000043: PhysicalKeyboardKey.f10, + 0x00000044: PhysicalKeyboardKey.f11, + 0x00000045: PhysicalKeyboardKey.f12, + 0x00000046: PhysicalKeyboardKey.printScreen, + 0x00000047: PhysicalKeyboardKey.scrollLock, + 0x00000048: PhysicalKeyboardKey.pause, + 0x00000049: PhysicalKeyboardKey.insert, + 0x0000004a: PhysicalKeyboardKey.home, + 0x0000004b: PhysicalKeyboardKey.pageUp, + 0x0000004c: PhysicalKeyboardKey.delete, + 0x0000004d: PhysicalKeyboardKey.end, + 0x0000004e: PhysicalKeyboardKey.pageDown, + 0x0000004f: PhysicalKeyboardKey.arrowRight, + 0x00000050: PhysicalKeyboardKey.arrowLeft, + 0x00000051: PhysicalKeyboardKey.arrowDown, + 0x00000052: PhysicalKeyboardKey.arrowUp, + 0x00000053: PhysicalKeyboardKey.numLock, + 0x00000054: PhysicalKeyboardKey.numpadDivide, + 0x00000055: PhysicalKeyboardKey.numpadMultiply, + 0x00000056: PhysicalKeyboardKey.numpadSubtract, + 0x00000057: PhysicalKeyboardKey.numpadAdd, + 0x00000058: PhysicalKeyboardKey.numpadEnter, + 0x00000059: PhysicalKeyboardKey.numpad1, + 0x0000005a: PhysicalKeyboardKey.numpad2, + 0x0000005b: PhysicalKeyboardKey.numpad3, + 0x0000005c: PhysicalKeyboardKey.numpad4, + 0x0000005d: PhysicalKeyboardKey.numpad5, + 0x0000005e: PhysicalKeyboardKey.numpad6, + 0x0000005f: PhysicalKeyboardKey.numpad7, + 0x00000060: PhysicalKeyboardKey.numpad8, + 0x00000061: PhysicalKeyboardKey.numpad9, + 0x00000062: PhysicalKeyboardKey.numpad0, + 0x00000063: PhysicalKeyboardKey.numpadDecimal, + 0x00000064: PhysicalKeyboardKey.intlBackslash, + 0x00000065: PhysicalKeyboardKey.contextMenu, + 0x00000066: PhysicalKeyboardKey.power, + 0x00000067: PhysicalKeyboardKey.numpadEqual, + 0x00000068: PhysicalKeyboardKey.f13, + 0x00000069: PhysicalKeyboardKey.f14, + 0x0000006a: PhysicalKeyboardKey.f15, + 0x0000006b: PhysicalKeyboardKey.f16, + 0x0000006c: PhysicalKeyboardKey.f17, + 0x0000006d: PhysicalKeyboardKey.f18, + 0x0000006e: PhysicalKeyboardKey.f19, + 0x0000006f: PhysicalKeyboardKey.f20, + 0x00000070: PhysicalKeyboardKey.f21, + 0x00000071: PhysicalKeyboardKey.f22, + 0x00000072: PhysicalKeyboardKey.f23, + 0x00000073: PhysicalKeyboardKey.f24, + 0x00000074: PhysicalKeyboardKey.open, + 0x00000075: PhysicalKeyboardKey.help, + 0x00000077: PhysicalKeyboardKey.select, + 0x00000079: PhysicalKeyboardKey.again, + 0x0000007a: PhysicalKeyboardKey.undo, + 0x0000007b: PhysicalKeyboardKey.cut, + 0x0000007c: PhysicalKeyboardKey.copy, + 0x0000007d: PhysicalKeyboardKey.paste, + 0x0000007e: PhysicalKeyboardKey.find, + 0x0000007f: PhysicalKeyboardKey.audioVolumeMute, + 0x00000080: PhysicalKeyboardKey.audioVolumeUp, + 0x00000081: PhysicalKeyboardKey.audioVolumeDown, + 0x00000085: PhysicalKeyboardKey.numpadComma, + 0x00000087: PhysicalKeyboardKey.intlRo, + 0x00000088: PhysicalKeyboardKey.kanaMode, + 0x00000089: PhysicalKeyboardKey.intlYen, + 0x0000008a: PhysicalKeyboardKey.convert, + 0x0000008b: PhysicalKeyboardKey.nonConvert, + 0x00000090: PhysicalKeyboardKey.lang1, + 0x00000091: PhysicalKeyboardKey.lang2, + 0x00000092: PhysicalKeyboardKey.lang3, + 0x00000093: PhysicalKeyboardKey.lang4, + 0x00000094: PhysicalKeyboardKey.lang5, + 0x0000009b: PhysicalKeyboardKey.abort, + 0x000000a3: PhysicalKeyboardKey.props, + 0x000000b6: PhysicalKeyboardKey.numpadParenLeft, + 0x000000b7: PhysicalKeyboardKey.numpadParenRight, + 0x000000bb: PhysicalKeyboardKey.numpadBackspace, + 0x000000d0: PhysicalKeyboardKey.numpadMemoryStore, + 0x000000d1: PhysicalKeyboardKey.numpadMemoryRecall, + 0x000000d2: PhysicalKeyboardKey.numpadMemoryClear, + 0x000000d3: PhysicalKeyboardKey.numpadMemoryAdd, + 0x000000d4: PhysicalKeyboardKey.numpadMemorySubtract, + 0x000000d7: PhysicalKeyboardKey.numpadSignChange, + 0x000000d8: PhysicalKeyboardKey.numpadClear, + 0x000000d9: PhysicalKeyboardKey.numpadClearEntry, + 0x000000e0: PhysicalKeyboardKey.controlLeft, + 0x000000e1: PhysicalKeyboardKey.shiftLeft, + 0x000000e2: PhysicalKeyboardKey.altLeft, + 0x000000e3: PhysicalKeyboardKey.metaLeft, + 0x000000e4: PhysicalKeyboardKey.controlRight, + 0x000000e5: PhysicalKeyboardKey.shiftRight, + 0x000000e6: PhysicalKeyboardKey.altRight, + 0x000000e7: PhysicalKeyboardKey.metaRight, +}; + +/// Maps iOS specific string values of nonvisible keys to logical keys +/// +/// Some unprintable keys on iOS has literal names on their key label, such as +/// "UIKeyInputEscape". See: +/// https://developer.apple.com/documentation/uikit/uikeycommand/input_strings_for_special_keys?language=objc +const Map<String, LogicalKeyboardKey> kIosSpecialLogicalMap = <String, LogicalKeyboardKey>{ + 'UIKeyInputEscape': LogicalKeyboardKey.escape, + 'UIKeyInputF1': LogicalKeyboardKey.f1, + 'UIKeyInputF2': LogicalKeyboardKey.f2, + 'UIKeyInputF3': LogicalKeyboardKey.f3, + 'UIKeyInputF4': LogicalKeyboardKey.f4, + 'UIKeyInputF5': LogicalKeyboardKey.f5, + 'UIKeyInputF6': LogicalKeyboardKey.f6, + 'UIKeyInputF7': LogicalKeyboardKey.f7, + 'UIKeyInputF8': LogicalKeyboardKey.f8, + 'UIKeyInputF9': LogicalKeyboardKey.f9, + 'UIKeyInputF10': LogicalKeyboardKey.f10, + 'UIKeyInputF11': LogicalKeyboardKey.f11, + 'UIKeyInputF12': LogicalKeyboardKey.f12, + 'UIKeyInputUpArrow': LogicalKeyboardKey.arrowUp, + 'UIKeyInputDownArrow': LogicalKeyboardKey.arrowDown, + 'UIKeyInputLeftArrow': LogicalKeyboardKey.arrowLeft, + 'UIKeyInputRightArrow': LogicalKeyboardKey.arrowRight, + 'UIKeyInputHome': LogicalKeyboardKey.home, + 'UIKeyInputEnd': LogicalKeyboardKey.enter, + 'UIKeyInputPageUp': LogicalKeyboardKey.pageUp, + 'UIKeyInputPageDown': LogicalKeyboardKey.pageDown, +}; + +/// A map of iOS key codes which have printable representations, but appear +/// on the number pad. Used to provide different key objects for keys like +/// KEY_EQUALS and NUMPAD_EQUALS. +const Map<int, LogicalKeyboardKey> kIosNumPadMap = <int, LogicalKeyboardKey>{ + 0x00000054: LogicalKeyboardKey.numpadDivide, + 0x00000055: LogicalKeyboardKey.numpadMultiply, + 0x00000056: LogicalKeyboardKey.numpadSubtract, + 0x00000057: LogicalKeyboardKey.numpadAdd, + 0x00000059: LogicalKeyboardKey.numpad1, + 0x0000005a: LogicalKeyboardKey.numpad2, + 0x0000005b: LogicalKeyboardKey.numpad3, + 0x0000005c: LogicalKeyboardKey.numpad4, + 0x0000005d: LogicalKeyboardKey.numpad5, + 0x0000005e: LogicalKeyboardKey.numpad6, + 0x0000005f: LogicalKeyboardKey.numpad7, + 0x00000060: LogicalKeyboardKey.numpad8, + 0x00000061: LogicalKeyboardKey.numpad9, + 0x00000062: LogicalKeyboardKey.numpad0, + 0x00000063: LogicalKeyboardKey.numpadDecimal, + 0x00000067: LogicalKeyboardKey.numpadEqual, + 0x00000085: LogicalKeyboardKey.numpadComma, + 0x000000b6: LogicalKeyboardKey.numpadParenLeft, + 0x000000b7: LogicalKeyboardKey.numpadParenRight, +}; + +/// A map of iOS key codes presenting [LogicalKeyboardKey]. +/// +/// Logical key codes are not available in iOS key events. Most of the logical keys +/// are derived from its `characterIgnoringModifiers`, but those keys that don't +/// have a character representation will be derived from their key codes using +/// this map. +const Map<int, LogicalKeyboardKey> kIosToLogicalKey = <int, LogicalKeyboardKey>{ + 40: LogicalKeyboardKey.enter, + 41: LogicalKeyboardKey.escape, + 42: LogicalKeyboardKey.backspace, + 43: LogicalKeyboardKey.tab, + 57: LogicalKeyboardKey.capsLock, + 58: LogicalKeyboardKey.f1, + 59: LogicalKeyboardKey.f2, + 60: LogicalKeyboardKey.f3, + 61: LogicalKeyboardKey.f4, + 62: LogicalKeyboardKey.f5, + 63: LogicalKeyboardKey.f6, + 64: LogicalKeyboardKey.f7, + 65: LogicalKeyboardKey.f8, + 66: LogicalKeyboardKey.f9, + 67: LogicalKeyboardKey.f10, + 68: LogicalKeyboardKey.f11, + 69: LogicalKeyboardKey.f12, + 73: LogicalKeyboardKey.insert, + 74: LogicalKeyboardKey.home, + 75: LogicalKeyboardKey.pageUp, + 76: LogicalKeyboardKey.delete, + 77: LogicalKeyboardKey.end, + 78: LogicalKeyboardKey.pageDown, + 79: LogicalKeyboardKey.arrowRight, + 80: LogicalKeyboardKey.arrowLeft, + 81: LogicalKeyboardKey.arrowDown, + 82: LogicalKeyboardKey.arrowUp, + 83: LogicalKeyboardKey.numLock, + 84: LogicalKeyboardKey.numpadDivide, + 85: LogicalKeyboardKey.numpadMultiply, + 86: LogicalKeyboardKey.numpadSubtract, + 87: LogicalKeyboardKey.numpadAdd, + 88: LogicalKeyboardKey.numpadEnter, + 89: LogicalKeyboardKey.numpad1, + 90: LogicalKeyboardKey.numpad2, + 91: LogicalKeyboardKey.numpad3, + 92: LogicalKeyboardKey.numpad4, + 93: LogicalKeyboardKey.numpad5, + 94: LogicalKeyboardKey.numpad6, + 95: LogicalKeyboardKey.numpad7, + 96: LogicalKeyboardKey.numpad8, + 97: LogicalKeyboardKey.numpad9, + 98: LogicalKeyboardKey.numpad0, + 99: LogicalKeyboardKey.numpadDecimal, + 101: LogicalKeyboardKey.contextMenu, + 103: LogicalKeyboardKey.numpadEqual, + 104: LogicalKeyboardKey.f13, + 105: LogicalKeyboardKey.f14, + 106: LogicalKeyboardKey.f15, + 107: LogicalKeyboardKey.f16, + 108: LogicalKeyboardKey.f17, + 109: LogicalKeyboardKey.f18, + 110: LogicalKeyboardKey.f19, + 111: LogicalKeyboardKey.f20, + 127: LogicalKeyboardKey.audioVolumeMute, + 128: LogicalKeyboardKey.audioVolumeUp, + 129: LogicalKeyboardKey.audioVolumeDown, + 133: LogicalKeyboardKey.numpadComma, + 135: LogicalKeyboardKey.intlRo, + 137: LogicalKeyboardKey.intlYen, + 144: LogicalKeyboardKey.lang1, + 145: LogicalKeyboardKey.lang2, + 146: LogicalKeyboardKey.lang3, + 147: LogicalKeyboardKey.lang4, + 148: LogicalKeyboardKey.lang5, + 224: LogicalKeyboardKey.controlLeft, + 225: LogicalKeyboardKey.shiftLeft, + 226: LogicalKeyboardKey.altLeft, + 227: LogicalKeyboardKey.metaLeft, + 228: LogicalKeyboardKey.controlRight, + 229: LogicalKeyboardKey.shiftRight, + 230: LogicalKeyboardKey.altRight, + 231: LogicalKeyboardKey.metaRight, +}; + +/// Maps GLFW-specific key codes to the matching [LogicalKeyboardKey]. +const Map<int, LogicalKeyboardKey> kGlfwToLogicalKey = <int, LogicalKeyboardKey>{ + 32: LogicalKeyboardKey.space, + 39: LogicalKeyboardKey.quote, + 44: LogicalKeyboardKey.comma, + 45: LogicalKeyboardKey.minus, + 46: LogicalKeyboardKey.period, + 47: LogicalKeyboardKey.slash, + 48: LogicalKeyboardKey.digit0, + 49: LogicalKeyboardKey.digit1, + 50: LogicalKeyboardKey.digit2, + 51: LogicalKeyboardKey.digit3, + 52: LogicalKeyboardKey.digit4, + 53: LogicalKeyboardKey.digit5, + 54: LogicalKeyboardKey.digit6, + 55: LogicalKeyboardKey.digit7, + 56: LogicalKeyboardKey.digit8, + 57: LogicalKeyboardKey.digit9, + 59: LogicalKeyboardKey.semicolon, + 61: LogicalKeyboardKey.equal, + 65: LogicalKeyboardKey.keyA, + 66: LogicalKeyboardKey.keyB, + 67: LogicalKeyboardKey.keyC, + 68: LogicalKeyboardKey.keyD, + 69: LogicalKeyboardKey.keyE, + 70: LogicalKeyboardKey.keyF, + 71: LogicalKeyboardKey.keyG, + 72: LogicalKeyboardKey.keyH, + 73: LogicalKeyboardKey.keyI, + 74: LogicalKeyboardKey.keyJ, + 75: LogicalKeyboardKey.keyK, + 76: LogicalKeyboardKey.keyL, + 77: LogicalKeyboardKey.keyM, + 78: LogicalKeyboardKey.keyN, + 79: LogicalKeyboardKey.keyO, + 80: LogicalKeyboardKey.keyP, + 81: LogicalKeyboardKey.keyQ, + 82: LogicalKeyboardKey.keyR, + 83: LogicalKeyboardKey.keyS, + 84: LogicalKeyboardKey.keyT, + 85: LogicalKeyboardKey.keyU, + 86: LogicalKeyboardKey.keyV, + 87: LogicalKeyboardKey.keyW, + 88: LogicalKeyboardKey.keyX, + 89: LogicalKeyboardKey.keyY, + 90: LogicalKeyboardKey.keyZ, + 91: LogicalKeyboardKey.bracketLeft, + 92: LogicalKeyboardKey.backslash, + 93: LogicalKeyboardKey.bracketRight, + 96: LogicalKeyboardKey.backquote, + 256: LogicalKeyboardKey.escape, + 257: LogicalKeyboardKey.enter, + 258: LogicalKeyboardKey.tab, + 259: LogicalKeyboardKey.backspace, + 260: LogicalKeyboardKey.insert, + 261: LogicalKeyboardKey.delete, + 262: LogicalKeyboardKey.arrowRight, + 263: LogicalKeyboardKey.arrowLeft, + 264: LogicalKeyboardKey.arrowDown, + 265: LogicalKeyboardKey.arrowUp, + 266: LogicalKeyboardKey.pageUp, + 267: LogicalKeyboardKey.pageDown, + 268: LogicalKeyboardKey.home, + 269: LogicalKeyboardKey.end, + 280: LogicalKeyboardKey.capsLock, + 282: LogicalKeyboardKey.numLock, + 283: LogicalKeyboardKey.printScreen, + 284: LogicalKeyboardKey.pause, + 290: LogicalKeyboardKey.f1, + 291: LogicalKeyboardKey.f2, + 292: LogicalKeyboardKey.f3, + 293: LogicalKeyboardKey.f4, + 294: LogicalKeyboardKey.f5, + 295: LogicalKeyboardKey.f6, + 296: LogicalKeyboardKey.f7, + 297: LogicalKeyboardKey.f8, + 298: LogicalKeyboardKey.f9, + 299: LogicalKeyboardKey.f10, + 300: LogicalKeyboardKey.f11, + 301: LogicalKeyboardKey.f12, + 302: LogicalKeyboardKey.f13, + 303: LogicalKeyboardKey.f14, + 304: LogicalKeyboardKey.f15, + 305: LogicalKeyboardKey.f16, + 306: LogicalKeyboardKey.f17, + 307: LogicalKeyboardKey.f18, + 308: LogicalKeyboardKey.f19, + 309: LogicalKeyboardKey.f20, + 310: LogicalKeyboardKey.f21, + 311: LogicalKeyboardKey.f22, + 312: LogicalKeyboardKey.f23, + 320: LogicalKeyboardKey.numpad0, + 321: LogicalKeyboardKey.numpad1, + 322: LogicalKeyboardKey.numpad2, + 323: LogicalKeyboardKey.numpad3, + 324: LogicalKeyboardKey.numpad4, + 325: LogicalKeyboardKey.numpad5, + 326: LogicalKeyboardKey.numpad6, + 327: LogicalKeyboardKey.numpad7, + 328: LogicalKeyboardKey.numpad8, + 329: LogicalKeyboardKey.numpad9, + 330: LogicalKeyboardKey.numpadDecimal, + 331: LogicalKeyboardKey.numpadDivide, + 332: LogicalKeyboardKey.numpadMultiply, + 334: LogicalKeyboardKey.numpadAdd, + 335: LogicalKeyboardKey.numpadEnter, + 336: LogicalKeyboardKey.numpadEqual, + 340: LogicalKeyboardKey.shiftLeft, + 341: LogicalKeyboardKey.controlLeft, + 342: LogicalKeyboardKey.altLeft, + 343: LogicalKeyboardKey.metaLeft, + 344: LogicalKeyboardKey.shiftRight, + 345: LogicalKeyboardKey.controlRight, + 346: LogicalKeyboardKey.altRight, + 347: LogicalKeyboardKey.metaRight, + 348: LogicalKeyboardKey.contextMenu, +}; + +/// A map of GLFW key codes which have printable representations, but appear +/// on the number pad. Used to provide different key objects for keys like +/// KEY_EQUALS and NUMPAD_EQUALS. +const Map<int, LogicalKeyboardKey> kGlfwNumpadMap = <int, LogicalKeyboardKey>{ + 320: LogicalKeyboardKey.numpad0, + 321: LogicalKeyboardKey.numpad1, + 322: LogicalKeyboardKey.numpad2, + 323: LogicalKeyboardKey.numpad3, + 324: LogicalKeyboardKey.numpad4, + 325: LogicalKeyboardKey.numpad5, + 326: LogicalKeyboardKey.numpad6, + 327: LogicalKeyboardKey.numpad7, + 328: LogicalKeyboardKey.numpad8, + 329: LogicalKeyboardKey.numpad9, + 330: LogicalKeyboardKey.numpadDecimal, + 331: LogicalKeyboardKey.numpadDivide, + 332: LogicalKeyboardKey.numpadMultiply, + 334: LogicalKeyboardKey.numpadAdd, + 336: LogicalKeyboardKey.numpadEqual, +}; + +/// Maps GTK-specific key codes to the matching [LogicalKeyboardKey]. +const Map<int, LogicalKeyboardKey> kGtkToLogicalKey = <int, LogicalKeyboardKey>{ + 165: LogicalKeyboardKey.intlYen, + 64774: LogicalKeyboardKey.eraseEof, + 64782: LogicalKeyboardKey.attn, + 64789: LogicalKeyboardKey.copy, + 64790: LogicalKeyboardKey.mediaPlay, + 64795: LogicalKeyboardKey.exSel, + 64797: LogicalKeyboardKey.printScreen, + 64798: LogicalKeyboardKey.enter, + 65027: LogicalKeyboardKey.altRight, + 65032: LogicalKeyboardKey.groupNext, + 65034: LogicalKeyboardKey.groupPrevious, + 65036: LogicalKeyboardKey.groupFirst, + 65038: LogicalKeyboardKey.groupLast, + 65056: LogicalKeyboardKey.tab, + 65076: LogicalKeyboardKey.enter, + 65288: LogicalKeyboardKey.backspace, + 65289: LogicalKeyboardKey.tab, + 65291: LogicalKeyboardKey.clear, + 65293: LogicalKeyboardKey.enter, + 65299: LogicalKeyboardKey.pause, + 65300: LogicalKeyboardKey.scrollLock, + 65307: LogicalKeyboardKey.escape, + 65313: LogicalKeyboardKey.kanjiMode, + 65316: LogicalKeyboardKey.romaji, + 65317: LogicalKeyboardKey.hiragana, + 65318: LogicalKeyboardKey.katakana, + 65319: LogicalKeyboardKey.hiraganaKatakana, + 65320: LogicalKeyboardKey.zenkaku, + 65321: LogicalKeyboardKey.hankaku, + 65322: LogicalKeyboardKey.zenkakuHankaku, + 65327: LogicalKeyboardKey.eisu, + 65329: LogicalKeyboardKey.hangulMode, + 65332: LogicalKeyboardKey.hanjaMode, + 65335: LogicalKeyboardKey.codeInput, + 65340: LogicalKeyboardKey.singleCandidate, + 65342: LogicalKeyboardKey.previousCandidate, + 65360: LogicalKeyboardKey.home, + 65361: LogicalKeyboardKey.arrowLeft, + 65362: LogicalKeyboardKey.arrowUp, + 65363: LogicalKeyboardKey.arrowRight, + 65364: LogicalKeyboardKey.arrowDown, + 65365: LogicalKeyboardKey.pageUp, + 65366: LogicalKeyboardKey.pageDown, + 65367: LogicalKeyboardKey.end, + 65376: LogicalKeyboardKey.select, + 65377: LogicalKeyboardKey.print, + 65378: LogicalKeyboardKey.execute, + 65379: LogicalKeyboardKey.insert, + 65381: LogicalKeyboardKey.undo, + 65382: LogicalKeyboardKey.redo, + 65383: LogicalKeyboardKey.contextMenu, + 65384: LogicalKeyboardKey.find, + 65385: LogicalKeyboardKey.cancel, + 65386: LogicalKeyboardKey.help, + 65406: LogicalKeyboardKey.modeChange, + 65407: LogicalKeyboardKey.numLock, + 65408: LogicalKeyboardKey.space, + 65417: LogicalKeyboardKey.tab, + 65421: LogicalKeyboardKey.numpadEnter, + 65425: LogicalKeyboardKey.f1, + 65426: LogicalKeyboardKey.f2, + 65427: LogicalKeyboardKey.f3, + 65428: LogicalKeyboardKey.f4, + 65429: LogicalKeyboardKey.numpad7, + 65430: LogicalKeyboardKey.numpad4, + 65431: LogicalKeyboardKey.numpad8, + 65432: LogicalKeyboardKey.numpad6, + 65433: LogicalKeyboardKey.numpad2, + 65434: LogicalKeyboardKey.numpad9, + 65435: LogicalKeyboardKey.numpad3, + 65436: LogicalKeyboardKey.numpad1, + 65438: LogicalKeyboardKey.numpad0, + 65439: LogicalKeyboardKey.numpadDecimal, + 65450: LogicalKeyboardKey.numpadMultiply, + 65451: LogicalKeyboardKey.numpadAdd, + 65453: LogicalKeyboardKey.numpadSubtract, + 65454: LogicalKeyboardKey.period, + 65455: LogicalKeyboardKey.numpadDivide, + 65456: LogicalKeyboardKey.numpad0, + 65457: LogicalKeyboardKey.numpad1, + 65458: LogicalKeyboardKey.numpad2, + 65459: LogicalKeyboardKey.numpad3, + 65460: LogicalKeyboardKey.numpad4, + 65461: LogicalKeyboardKey.numpad5, + 65462: LogicalKeyboardKey.numpad6, + 65463: LogicalKeyboardKey.numpad7, + 65464: LogicalKeyboardKey.numpad8, + 65465: LogicalKeyboardKey.numpad9, + 65469: LogicalKeyboardKey.numpadEqual, + 65470: LogicalKeyboardKey.f1, + 65471: LogicalKeyboardKey.f2, + 65472: LogicalKeyboardKey.f3, + 65473: LogicalKeyboardKey.f4, + 65474: LogicalKeyboardKey.f5, + 65475: LogicalKeyboardKey.f6, + 65476: LogicalKeyboardKey.f7, + 65477: LogicalKeyboardKey.f8, + 65478: LogicalKeyboardKey.f9, + 65479: LogicalKeyboardKey.f10, + 65480: LogicalKeyboardKey.f11, + 65481: LogicalKeyboardKey.f12, + 65482: LogicalKeyboardKey.f13, + 65483: LogicalKeyboardKey.f14, + 65484: LogicalKeyboardKey.f15, + 65485: LogicalKeyboardKey.f16, + 65486: LogicalKeyboardKey.f17, + 65487: LogicalKeyboardKey.f18, + 65488: LogicalKeyboardKey.f19, + 65489: LogicalKeyboardKey.f20, + 65490: LogicalKeyboardKey.f21, + 65491: LogicalKeyboardKey.f22, + 65492: LogicalKeyboardKey.f23, + 65493: LogicalKeyboardKey.f24, + 65505: LogicalKeyboardKey.shiftLeft, + 65506: LogicalKeyboardKey.shiftRight, + 65507: LogicalKeyboardKey.controlLeft, + 65508: LogicalKeyboardKey.controlRight, + 65509: LogicalKeyboardKey.capsLock, + 65511: LogicalKeyboardKey.metaLeft, + 65512: LogicalKeyboardKey.metaRight, + 65513: LogicalKeyboardKey.altLeft, + 65514: LogicalKeyboardKey.altRight, + 65515: LogicalKeyboardKey.superKey, + 65516: LogicalKeyboardKey.superKey, + 65517: LogicalKeyboardKey.hyper, + 65518: LogicalKeyboardKey.hyper, + 65535: LogicalKeyboardKey.delete, + 269025026: LogicalKeyboardKey.brightnessUp, + 269025027: LogicalKeyboardKey.brightnessDown, + 269025040: LogicalKeyboardKey.standby, + 269025041: LogicalKeyboardKey.audioVolumeDown, + 269025042: LogicalKeyboardKey.audioVolumeMute, + 269025043: LogicalKeyboardKey.audioVolumeUp, + 269025044: LogicalKeyboardKey.mediaPlay, + 269025045: LogicalKeyboardKey.mediaStop, + 269025046: LogicalKeyboardKey.mediaTrackPrevious, + 269025047: LogicalKeyboardKey.mediaTrackNext, + 269025048: LogicalKeyboardKey.browserHome, + 269025049: LogicalKeyboardKey.launchMail, + 269025051: LogicalKeyboardKey.browserSearch, + 269025052: LogicalKeyboardKey.mediaRecord, + 269025056: LogicalKeyboardKey.launchCalendar, + 269025062: LogicalKeyboardKey.browserBack, + 269025063: LogicalKeyboardKey.browserForward, + 269025064: LogicalKeyboardKey.browserStop, + 269025065: LogicalKeyboardKey.browserRefresh, + 269025066: LogicalKeyboardKey.powerOff, + 269025067: LogicalKeyboardKey.wakeUp, + 269025068: LogicalKeyboardKey.eject, + 269025069: LogicalKeyboardKey.launchScreenSaver, + 269025071: LogicalKeyboardKey.sleep, + 269025072: LogicalKeyboardKey.browserFavorites, + 269025073: LogicalKeyboardKey.mediaPause, + 269025086: LogicalKeyboardKey.mediaRewind, + 269025110: LogicalKeyboardKey.close, + 269025111: LogicalKeyboardKey.copy, + 269025112: LogicalKeyboardKey.cut, + 269025121: LogicalKeyboardKey.logOff, + 269025128: LogicalKeyboardKey.newKey, + 269025131: LogicalKeyboardKey.open, + 269025133: LogicalKeyboardKey.paste, + 269025134: LogicalKeyboardKey.launchPhone, + 269025138: LogicalKeyboardKey.mailReply, + 269025143: LogicalKeyboardKey.save, + 269025147: LogicalKeyboardKey.mailSend, + 269025148: LogicalKeyboardKey.spellCheck, + 269025163: LogicalKeyboardKey.zoomIn, + 269025164: LogicalKeyboardKey.zoomOut, + 269025168: LogicalKeyboardKey.mailForward, + 269025175: LogicalKeyboardKey.mediaFastForward, + 269025191: LogicalKeyboardKey.suspend, +}; + +/// A map of GTK key codes which have printable representations, but appear +/// on the number pad. Used to provide different key objects for keys like +/// KEY_EQUALS and NUMPAD_EQUALS. +const Map<int, LogicalKeyboardKey> kGtkNumpadMap = <int, LogicalKeyboardKey>{ + 65429: LogicalKeyboardKey.numpad7, + 65430: LogicalKeyboardKey.numpad4, + 65431: LogicalKeyboardKey.numpad8, + 65432: LogicalKeyboardKey.numpad6, + 65433: LogicalKeyboardKey.numpad2, + 65434: LogicalKeyboardKey.numpad9, + 65435: LogicalKeyboardKey.numpad3, + 65436: LogicalKeyboardKey.numpad1, + 65438: LogicalKeyboardKey.numpad0, + 65439: LogicalKeyboardKey.numpadDecimal, + 65450: LogicalKeyboardKey.numpadMultiply, + 65451: LogicalKeyboardKey.numpadAdd, + 65453: LogicalKeyboardKey.numpadSubtract, + 65455: LogicalKeyboardKey.numpadDivide, + 65456: LogicalKeyboardKey.numpad0, + 65457: LogicalKeyboardKey.numpad1, + 65458: LogicalKeyboardKey.numpad2, + 65459: LogicalKeyboardKey.numpad3, + 65460: LogicalKeyboardKey.numpad4, + 65461: LogicalKeyboardKey.numpad5, + 65462: LogicalKeyboardKey.numpad6, + 65463: LogicalKeyboardKey.numpad7, + 65464: LogicalKeyboardKey.numpad8, + 65465: LogicalKeyboardKey.numpad9, + 65469: LogicalKeyboardKey.numpadEqual, +}; + +/// Maps XKB specific key code values representing [PhysicalKeyboardKey]. +const Map<int, PhysicalKeyboardKey> kLinuxToPhysicalKey = <int, PhysicalKeyboardKey>{ + 0x00000009: PhysicalKeyboardKey.escape, + 0x0000000a: PhysicalKeyboardKey.digit1, + 0x0000000b: PhysicalKeyboardKey.digit2, + 0x0000000c: PhysicalKeyboardKey.digit3, + 0x0000000d: PhysicalKeyboardKey.digit4, + 0x0000000e: PhysicalKeyboardKey.digit5, + 0x0000000f: PhysicalKeyboardKey.digit6, + 0x00000010: PhysicalKeyboardKey.digit7, + 0x00000011: PhysicalKeyboardKey.digit8, + 0x00000012: PhysicalKeyboardKey.digit9, + 0x00000013: PhysicalKeyboardKey.digit0, + 0x00000014: PhysicalKeyboardKey.minus, + 0x00000015: PhysicalKeyboardKey.equal, + 0x00000016: PhysicalKeyboardKey.backspace, + 0x00000017: PhysicalKeyboardKey.tab, + 0x00000018: PhysicalKeyboardKey.keyQ, + 0x00000019: PhysicalKeyboardKey.keyW, + 0x0000001a: PhysicalKeyboardKey.keyE, + 0x0000001b: PhysicalKeyboardKey.keyR, + 0x0000001c: PhysicalKeyboardKey.keyT, + 0x0000001d: PhysicalKeyboardKey.keyY, + 0x0000001e: PhysicalKeyboardKey.keyU, + 0x0000001f: PhysicalKeyboardKey.keyI, + 0x00000020: PhysicalKeyboardKey.keyO, + 0x00000021: PhysicalKeyboardKey.keyP, + 0x00000022: PhysicalKeyboardKey.bracketLeft, + 0x00000023: PhysicalKeyboardKey.bracketRight, + 0x00000024: PhysicalKeyboardKey.enter, + 0x00000025: PhysicalKeyboardKey.controlLeft, + 0x00000026: PhysicalKeyboardKey.keyA, + 0x00000027: PhysicalKeyboardKey.keyS, + 0x00000028: PhysicalKeyboardKey.keyD, + 0x00000029: PhysicalKeyboardKey.keyF, + 0x0000002a: PhysicalKeyboardKey.keyG, + 0x0000002b: PhysicalKeyboardKey.keyH, + 0x0000002c: PhysicalKeyboardKey.keyJ, + 0x0000002d: PhysicalKeyboardKey.keyK, + 0x0000002e: PhysicalKeyboardKey.keyL, + 0x0000002f: PhysicalKeyboardKey.semicolon, + 0x00000030: PhysicalKeyboardKey.quote, + 0x00000031: PhysicalKeyboardKey.backquote, + 0x00000032: PhysicalKeyboardKey.shiftLeft, + 0x00000033: PhysicalKeyboardKey.backslash, + 0x00000034: PhysicalKeyboardKey.keyZ, + 0x00000035: PhysicalKeyboardKey.keyX, + 0x00000036: PhysicalKeyboardKey.keyC, + 0x00000037: PhysicalKeyboardKey.keyV, + 0x00000038: PhysicalKeyboardKey.keyB, + 0x00000039: PhysicalKeyboardKey.keyN, + 0x0000003a: PhysicalKeyboardKey.keyM, + 0x0000003b: PhysicalKeyboardKey.comma, + 0x0000003c: PhysicalKeyboardKey.period, + 0x0000003d: PhysicalKeyboardKey.slash, + 0x0000003e: PhysicalKeyboardKey.shiftRight, + 0x0000003f: PhysicalKeyboardKey.numpadMultiply, + 0x00000040: PhysicalKeyboardKey.altLeft, + 0x00000041: PhysicalKeyboardKey.space, + 0x00000042: PhysicalKeyboardKey.capsLock, + 0x00000043: PhysicalKeyboardKey.f1, + 0x00000044: PhysicalKeyboardKey.f2, + 0x00000045: PhysicalKeyboardKey.f3, + 0x00000046: PhysicalKeyboardKey.f4, + 0x00000047: PhysicalKeyboardKey.f5, + 0x00000048: PhysicalKeyboardKey.f6, + 0x00000049: PhysicalKeyboardKey.f7, + 0x0000004a: PhysicalKeyboardKey.f8, + 0x0000004b: PhysicalKeyboardKey.f9, + 0x0000004c: PhysicalKeyboardKey.f10, + 0x0000004d: PhysicalKeyboardKey.numLock, + 0x0000004e: PhysicalKeyboardKey.scrollLock, + 0x0000004f: PhysicalKeyboardKey.numpad7, + 0x00000050: PhysicalKeyboardKey.numpad8, + 0x00000051: PhysicalKeyboardKey.numpad9, + 0x00000052: PhysicalKeyboardKey.numpadSubtract, + 0x00000053: PhysicalKeyboardKey.numpad4, + 0x00000054: PhysicalKeyboardKey.numpad5, + 0x00000055: PhysicalKeyboardKey.numpad6, + 0x00000056: PhysicalKeyboardKey.numpadAdd, + 0x00000057: PhysicalKeyboardKey.numpad1, + 0x00000058: PhysicalKeyboardKey.numpad2, + 0x00000059: PhysicalKeyboardKey.numpad3, + 0x0000005a: PhysicalKeyboardKey.numpad0, + 0x0000005b: PhysicalKeyboardKey.numpadDecimal, + 0x0000005d: PhysicalKeyboardKey.lang5, + 0x0000005e: PhysicalKeyboardKey.intlBackslash, + 0x0000005f: PhysicalKeyboardKey.f11, + 0x00000060: PhysicalKeyboardKey.f12, + 0x00000061: PhysicalKeyboardKey.intlRo, + 0x00000062: PhysicalKeyboardKey.lang3, + 0x00000063: PhysicalKeyboardKey.lang4, + 0x00000064: PhysicalKeyboardKey.convert, + 0x00000065: PhysicalKeyboardKey.kanaMode, + 0x00000066: PhysicalKeyboardKey.nonConvert, + 0x00000068: PhysicalKeyboardKey.numpadEnter, + 0x00000069: PhysicalKeyboardKey.controlRight, + 0x0000006a: PhysicalKeyboardKey.numpadDivide, + 0x0000006b: PhysicalKeyboardKey.printScreen, + 0x0000006c: PhysicalKeyboardKey.altRight, + 0x0000006e: PhysicalKeyboardKey.home, + 0x0000006f: PhysicalKeyboardKey.arrowUp, + 0x00000070: PhysicalKeyboardKey.pageUp, + 0x00000071: PhysicalKeyboardKey.arrowLeft, + 0x00000072: PhysicalKeyboardKey.arrowRight, + 0x00000073: PhysicalKeyboardKey.end, + 0x00000074: PhysicalKeyboardKey.arrowDown, + 0x00000075: PhysicalKeyboardKey.pageDown, + 0x00000076: PhysicalKeyboardKey.insert, + 0x00000077: PhysicalKeyboardKey.delete, + 0x00000079: PhysicalKeyboardKey.audioVolumeMute, + 0x0000007a: PhysicalKeyboardKey.audioVolumeDown, + 0x0000007b: PhysicalKeyboardKey.audioVolumeUp, + 0x0000007c: PhysicalKeyboardKey.power, + 0x0000007d: PhysicalKeyboardKey.numpadEqual, + 0x0000007e: PhysicalKeyboardKey.numpadSignChange, + 0x0000007f: PhysicalKeyboardKey.pause, + 0x00000080: PhysicalKeyboardKey.showAllWindows, + 0x00000081: PhysicalKeyboardKey.numpadComma, + 0x00000082: PhysicalKeyboardKey.lang1, + 0x00000083: PhysicalKeyboardKey.lang2, + 0x00000084: PhysicalKeyboardKey.intlYen, + 0x00000085: PhysicalKeyboardKey.metaLeft, + 0x00000086: PhysicalKeyboardKey.metaRight, + 0x00000087: PhysicalKeyboardKey.contextMenu, + 0x00000088: PhysicalKeyboardKey.browserStop, + 0x00000089: PhysicalKeyboardKey.again, + 0x0000008b: PhysicalKeyboardKey.undo, + 0x0000008c: PhysicalKeyboardKey.select, + 0x0000008d: PhysicalKeyboardKey.copy, + 0x0000008e: PhysicalKeyboardKey.open, + 0x0000008f: PhysicalKeyboardKey.paste, + 0x00000090: PhysicalKeyboardKey.find, + 0x00000091: PhysicalKeyboardKey.cut, + 0x00000092: PhysicalKeyboardKey.help, + 0x00000094: PhysicalKeyboardKey.launchApp2, + 0x00000096: PhysicalKeyboardKey.sleep, + 0x00000097: PhysicalKeyboardKey.wakeUp, + 0x00000098: PhysicalKeyboardKey.launchApp1, + 0x0000009e: PhysicalKeyboardKey.launchInternetBrowser, + 0x000000a0: PhysicalKeyboardKey.lockScreen, + 0x000000a3: PhysicalKeyboardKey.launchMail, + 0x000000a4: PhysicalKeyboardKey.browserFavorites, + 0x000000a6: PhysicalKeyboardKey.browserBack, + 0x000000a7: PhysicalKeyboardKey.browserForward, + 0x000000a9: PhysicalKeyboardKey.eject, + 0x000000ab: PhysicalKeyboardKey.mediaTrackNext, + 0x000000ac: PhysicalKeyboardKey.mediaPlayPause, + 0x000000ad: PhysicalKeyboardKey.mediaTrackPrevious, + 0x000000ae: PhysicalKeyboardKey.mediaStop, + 0x000000af: PhysicalKeyboardKey.mediaRecord, + 0x000000b0: PhysicalKeyboardKey.mediaRewind, + 0x000000b1: PhysicalKeyboardKey.launchPhone, + 0x000000b3: PhysicalKeyboardKey.mediaSelect, + 0x000000b4: PhysicalKeyboardKey.browserHome, + 0x000000b5: PhysicalKeyboardKey.browserRefresh, + 0x000000b6: PhysicalKeyboardKey.exit, + 0x000000bb: PhysicalKeyboardKey.numpadParenLeft, + 0x000000bc: PhysicalKeyboardKey.numpadParenRight, + 0x000000bd: PhysicalKeyboardKey.newKey, + 0x000000be: PhysicalKeyboardKey.redo, + 0x000000bf: PhysicalKeyboardKey.f13, + 0x000000c0: PhysicalKeyboardKey.f14, + 0x000000c1: PhysicalKeyboardKey.f15, + 0x000000c2: PhysicalKeyboardKey.f16, + 0x000000c3: PhysicalKeyboardKey.f17, + 0x000000c4: PhysicalKeyboardKey.f18, + 0x000000c5: PhysicalKeyboardKey.f19, + 0x000000c6: PhysicalKeyboardKey.f20, + 0x000000c7: PhysicalKeyboardKey.f21, + 0x000000c8: PhysicalKeyboardKey.f22, + 0x000000c9: PhysicalKeyboardKey.f23, + 0x000000ca: PhysicalKeyboardKey.f24, + 0x000000d1: PhysicalKeyboardKey.mediaPause, + 0x000000d6: PhysicalKeyboardKey.close, + 0x000000d7: PhysicalKeyboardKey.mediaPlay, + 0x000000d8: PhysicalKeyboardKey.mediaFastForward, + 0x000000d9: PhysicalKeyboardKey.bassBoost, + 0x000000da: PhysicalKeyboardKey.print, + 0x000000e1: PhysicalKeyboardKey.browserSearch, + 0x000000e8: PhysicalKeyboardKey.brightnessDown, + 0x000000e9: PhysicalKeyboardKey.brightnessUp, + 0x000000eb: PhysicalKeyboardKey.displayToggleIntExt, + 0x000000ed: PhysicalKeyboardKey.kbdIllumDown, + 0x000000ee: PhysicalKeyboardKey.kbdIllumUp, + 0x000000ef: PhysicalKeyboardKey.mailSend, + 0x000000f0: PhysicalKeyboardKey.mailReply, + 0x000000f1: PhysicalKeyboardKey.mailForward, + 0x000000f2: PhysicalKeyboardKey.save, + 0x000000f3: PhysicalKeyboardKey.launchDocuments, + 0x000000fc: PhysicalKeyboardKey.brightnessAuto, + 0x00000100: PhysicalKeyboardKey.microphoneMuteToggle, + 0x0000016e: PhysicalKeyboardKey.info, + 0x00000172: PhysicalKeyboardKey.programGuide, + 0x0000017a: PhysicalKeyboardKey.closedCaptionToggle, + 0x0000017c: PhysicalKeyboardKey.zoomToggle, + 0x0000017e: PhysicalKeyboardKey.launchKeyboardLayout, + 0x00000190: PhysicalKeyboardKey.launchAudioBrowser, + 0x00000195: PhysicalKeyboardKey.launchCalendar, + 0x0000019d: PhysicalKeyboardKey.mediaLast, + 0x000001a2: PhysicalKeyboardKey.channelUp, + 0x000001a3: PhysicalKeyboardKey.channelDown, + 0x000001aa: PhysicalKeyboardKey.zoomIn, + 0x000001ab: PhysicalKeyboardKey.zoomOut, + 0x000001ad: PhysicalKeyboardKey.launchWordProcessor, + 0x000001af: PhysicalKeyboardKey.launchSpreadsheet, + 0x000001b5: PhysicalKeyboardKey.launchContacts, + 0x000001b7: PhysicalKeyboardKey.brightnessToggle, + 0x000001b8: PhysicalKeyboardKey.spellCheck, + 0x000001b9: PhysicalKeyboardKey.logOff, + 0x0000024b: PhysicalKeyboardKey.launchControlPanel, + 0x0000024c: PhysicalKeyboardKey.selectTask, + 0x0000024d: PhysicalKeyboardKey.launchScreenSaver, + 0x0000024e: PhysicalKeyboardKey.speechInputToggle, + 0x0000024f: PhysicalKeyboardKey.launchAssistant, + 0x00000250: PhysicalKeyboardKey.keyboardLayoutSelect, + 0x00000258: PhysicalKeyboardKey.brightnessMinimum, + 0x00000259: PhysicalKeyboardKey.brightnessMaximum, + 0x00000281: PhysicalKeyboardKey.privacyScreenToggle, +}; + +/// Maps Web KeyboardEvent codes to the matching [LogicalKeyboardKey]. +const Map<String, LogicalKeyboardKey> kWebToLogicalKey = <String, LogicalKeyboardKey>{ + 'AVRInput': LogicalKeyboardKey.avrInput, + 'AVRPower': LogicalKeyboardKey.avrPower, + 'Accel': LogicalKeyboardKey.accel, + 'Accept': LogicalKeyboardKey.accept, + 'Again': LogicalKeyboardKey.again, + 'AllCandidates': LogicalKeyboardKey.allCandidates, + 'Alphanumeric': LogicalKeyboardKey.alphanumeric, + 'AltGraph': LogicalKeyboardKey.altGraph, + 'AppSwitch': LogicalKeyboardKey.appSwitch, + 'ArrowDown': LogicalKeyboardKey.arrowDown, + 'ArrowLeft': LogicalKeyboardKey.arrowLeft, + 'ArrowRight': LogicalKeyboardKey.arrowRight, + 'ArrowUp': LogicalKeyboardKey.arrowUp, + 'Attn': LogicalKeyboardKey.attn, + 'AudioBalanceLeft': LogicalKeyboardKey.audioBalanceLeft, + 'AudioBalanceRight': LogicalKeyboardKey.audioBalanceRight, + 'AudioBassBoostDown': LogicalKeyboardKey.audioBassBoostDown, + 'AudioBassBoostToggle': LogicalKeyboardKey.audioBassBoostToggle, + 'AudioBassBoostUp': LogicalKeyboardKey.audioBassBoostUp, + 'AudioFaderFront': LogicalKeyboardKey.audioFaderFront, + 'AudioFaderRear': LogicalKeyboardKey.audioFaderRear, + 'AudioSurroundModeNext': LogicalKeyboardKey.audioSurroundModeNext, + 'AudioTrebleDown': LogicalKeyboardKey.audioTrebleDown, + 'AudioTrebleUp': LogicalKeyboardKey.audioTrebleUp, + 'AudioVolumeDown': LogicalKeyboardKey.audioVolumeDown, + 'AudioVolumeMute': LogicalKeyboardKey.audioVolumeMute, + 'AudioVolumeUp': LogicalKeyboardKey.audioVolumeUp, + 'Backspace': LogicalKeyboardKey.backspace, + 'BrightnessDown': LogicalKeyboardKey.brightnessDown, + 'BrightnessUp': LogicalKeyboardKey.brightnessUp, + 'BrowserBack': LogicalKeyboardKey.browserBack, + 'BrowserFavorites': LogicalKeyboardKey.browserFavorites, + 'BrowserForward': LogicalKeyboardKey.browserForward, + 'BrowserHome': LogicalKeyboardKey.browserHome, + 'BrowserRefresh': LogicalKeyboardKey.browserRefresh, + 'BrowserSearch': LogicalKeyboardKey.browserSearch, + 'BrowserStop': LogicalKeyboardKey.browserStop, + 'Call': LogicalKeyboardKey.call, + 'Camera': LogicalKeyboardKey.camera, + 'CameraFocus': LogicalKeyboardKey.cameraFocus, + 'Cancel': LogicalKeyboardKey.cancel, + 'CapsLock': LogicalKeyboardKey.capsLock, + 'ChannelDown': LogicalKeyboardKey.channelDown, + 'ChannelUp': LogicalKeyboardKey.channelUp, + 'Clear': LogicalKeyboardKey.clear, + 'Close': LogicalKeyboardKey.close, + 'ClosedCaptionToggle': LogicalKeyboardKey.closedCaptionToggle, + 'CodeInput': LogicalKeyboardKey.codeInput, + 'ColorF0Red': LogicalKeyboardKey.colorF0Red, + 'ColorF1Green': LogicalKeyboardKey.colorF1Green, + 'ColorF2Yellow': LogicalKeyboardKey.colorF2Yellow, + 'ColorF3Blue': LogicalKeyboardKey.colorF3Blue, + 'ColorF4Grey': LogicalKeyboardKey.colorF4Grey, + 'ColorF5Brown': LogicalKeyboardKey.colorF5Brown, + 'Compose': LogicalKeyboardKey.compose, + 'ContextMenu': LogicalKeyboardKey.contextMenu, + 'Convert': LogicalKeyboardKey.convert, + 'Copy': LogicalKeyboardKey.copy, + 'CrSel': LogicalKeyboardKey.crSel, + 'Cut': LogicalKeyboardKey.cut, + 'DVR': LogicalKeyboardKey.dvr, + 'Delete': LogicalKeyboardKey.delete, + 'Dimmer': LogicalKeyboardKey.dimmer, + 'DisplaySwap': LogicalKeyboardKey.displaySwap, + 'Eisu': LogicalKeyboardKey.eisu, + 'Eject': LogicalKeyboardKey.eject, + 'End': LogicalKeyboardKey.end, + 'EndCall': LogicalKeyboardKey.endCall, + 'Enter': LogicalKeyboardKey.enter, + 'EraseEof': LogicalKeyboardKey.eraseEof, + 'Esc': LogicalKeyboardKey.escape, + 'Escape': LogicalKeyboardKey.escape, + 'ExSel': LogicalKeyboardKey.exSel, + 'Execute': LogicalKeyboardKey.execute, + 'Exit': LogicalKeyboardKey.exit, + 'F1': LogicalKeyboardKey.f1, + 'F10': LogicalKeyboardKey.f10, + 'F11': LogicalKeyboardKey.f11, + 'F12': LogicalKeyboardKey.f12, + 'F13': LogicalKeyboardKey.f13, + 'F14': LogicalKeyboardKey.f14, + 'F15': LogicalKeyboardKey.f15, + 'F16': LogicalKeyboardKey.f16, + 'F17': LogicalKeyboardKey.f17, + 'F18': LogicalKeyboardKey.f18, + 'F19': LogicalKeyboardKey.f19, + 'F2': LogicalKeyboardKey.f2, + 'F20': LogicalKeyboardKey.f20, + 'F21': LogicalKeyboardKey.f21, + 'F22': LogicalKeyboardKey.f22, + 'F23': LogicalKeyboardKey.f23, + 'F24': LogicalKeyboardKey.f24, + 'F3': LogicalKeyboardKey.f3, + 'F4': LogicalKeyboardKey.f4, + 'F5': LogicalKeyboardKey.f5, + 'F6': LogicalKeyboardKey.f6, + 'F7': LogicalKeyboardKey.f7, + 'F8': LogicalKeyboardKey.f8, + 'F9': LogicalKeyboardKey.f9, + 'FavoriteClear0': LogicalKeyboardKey.favoriteClear0, + 'FavoriteClear1': LogicalKeyboardKey.favoriteClear1, + 'FavoriteClear2': LogicalKeyboardKey.favoriteClear2, + 'FavoriteClear3': LogicalKeyboardKey.favoriteClear3, + 'FavoriteRecall0': LogicalKeyboardKey.favoriteRecall0, + 'FavoriteRecall1': LogicalKeyboardKey.favoriteRecall1, + 'FavoriteRecall2': LogicalKeyboardKey.favoriteRecall2, + 'FavoriteRecall3': LogicalKeyboardKey.favoriteRecall3, + 'FavoriteStore0': LogicalKeyboardKey.favoriteStore0, + 'FavoriteStore1': LogicalKeyboardKey.favoriteStore1, + 'FavoriteStore2': LogicalKeyboardKey.favoriteStore2, + 'FavoriteStore3': LogicalKeyboardKey.favoriteStore3, + 'FinalMode': LogicalKeyboardKey.finalMode, + 'Find': LogicalKeyboardKey.find, + 'Fn': LogicalKeyboardKey.fn, + 'FnLock': LogicalKeyboardKey.fnLock, + 'GoBack': LogicalKeyboardKey.goBack, + 'GoHome': LogicalKeyboardKey.goHome, + 'GroupFirst': LogicalKeyboardKey.groupFirst, + 'GroupLast': LogicalKeyboardKey.groupLast, + 'GroupNext': LogicalKeyboardKey.groupNext, + 'GroupPrevious': LogicalKeyboardKey.groupPrevious, + 'Guide': LogicalKeyboardKey.guide, + 'GuideNextDay': LogicalKeyboardKey.guideNextDay, + 'GuidePreviousDay': LogicalKeyboardKey.guidePreviousDay, + 'HangulMode': LogicalKeyboardKey.hangulMode, + 'HanjaMode': LogicalKeyboardKey.hanjaMode, + 'Hankaku': LogicalKeyboardKey.hankaku, + 'HeadsetHook': LogicalKeyboardKey.headsetHook, + 'Help': LogicalKeyboardKey.help, + 'Hibernate': LogicalKeyboardKey.hibernate, + 'Hiragana': LogicalKeyboardKey.hiragana, + 'HiraganaKatakana': LogicalKeyboardKey.hiraganaKatakana, + 'Home': LogicalKeyboardKey.home, + 'Hyper': LogicalKeyboardKey.hyper, + 'Info': LogicalKeyboardKey.info, + 'Insert': LogicalKeyboardKey.insert, + 'InstantReplay': LogicalKeyboardKey.instantReplay, + 'JunjaMode': LogicalKeyboardKey.junjaMode, + 'KanaMode': LogicalKeyboardKey.kanaMode, + 'KanjiMode': LogicalKeyboardKey.kanjiMode, + 'Katakana': LogicalKeyboardKey.katakana, + 'Key11': LogicalKeyboardKey.key11, + 'Key12': LogicalKeyboardKey.key12, + 'LastNumberRedial': LogicalKeyboardKey.lastNumberRedial, + 'LaunchApplication1': LogicalKeyboardKey.launchApplication1, + 'LaunchApplication2': LogicalKeyboardKey.launchApplication2, + 'LaunchAssistant': LogicalKeyboardKey.launchAssistant, + 'LaunchCalendar': LogicalKeyboardKey.launchCalendar, + 'LaunchContacts': LogicalKeyboardKey.launchContacts, + 'LaunchControlPanel': LogicalKeyboardKey.launchControlPanel, + 'LaunchMail': LogicalKeyboardKey.launchMail, + 'LaunchMediaPlayer': LogicalKeyboardKey.launchMediaPlayer, + 'LaunchMusicPlayer': LogicalKeyboardKey.launchMusicPlayer, + 'LaunchPhone': LogicalKeyboardKey.launchPhone, + 'LaunchScreenSaver': LogicalKeyboardKey.launchScreenSaver, + 'LaunchSpreadsheet': LogicalKeyboardKey.launchSpreadsheet, + 'LaunchWebBrowser': LogicalKeyboardKey.launchWebBrowser, + 'LaunchWebCam': LogicalKeyboardKey.launchWebCam, + 'LaunchWordProcessor': LogicalKeyboardKey.launchWordProcessor, + 'Link': LogicalKeyboardKey.link, + 'ListProgram': LogicalKeyboardKey.listProgram, + 'LiveContent': LogicalKeyboardKey.liveContent, + 'Lock': LogicalKeyboardKey.lock, + 'LogOff': LogicalKeyboardKey.logOff, + 'MailForward': LogicalKeyboardKey.mailForward, + 'MailReply': LogicalKeyboardKey.mailReply, + 'MailSend': LogicalKeyboardKey.mailSend, + 'MannerMode': LogicalKeyboardKey.mannerMode, + 'MediaApps': LogicalKeyboardKey.mediaApps, + 'MediaAudioTrack': LogicalKeyboardKey.mediaAudioTrack, + 'MediaClose': LogicalKeyboardKey.mediaClose, + 'MediaFastForward': LogicalKeyboardKey.mediaFastForward, + 'MediaLast': LogicalKeyboardKey.mediaLast, + 'MediaPause': LogicalKeyboardKey.mediaPause, + 'MediaPlay': LogicalKeyboardKey.mediaPlay, + 'MediaPlayPause': LogicalKeyboardKey.mediaPlayPause, + 'MediaRecord': LogicalKeyboardKey.mediaRecord, + 'MediaRewind': LogicalKeyboardKey.mediaRewind, + 'MediaSkip': LogicalKeyboardKey.mediaSkip, + 'MediaSkipBackward': LogicalKeyboardKey.mediaSkipBackward, + 'MediaSkipForward': LogicalKeyboardKey.mediaSkipForward, + 'MediaStepBackward': LogicalKeyboardKey.mediaStepBackward, + 'MediaStepForward': LogicalKeyboardKey.mediaStepForward, + 'MediaStop': LogicalKeyboardKey.mediaStop, + 'MediaTopMenu': LogicalKeyboardKey.mediaTopMenu, + 'MediaTrackNext': LogicalKeyboardKey.mediaTrackNext, + 'MediaTrackPrevious': LogicalKeyboardKey.mediaTrackPrevious, + 'MicrophoneToggle': LogicalKeyboardKey.microphoneToggle, + 'MicrophoneVolumeDown': LogicalKeyboardKey.microphoneVolumeDown, + 'MicrophoneVolumeMute': LogicalKeyboardKey.microphoneVolumeMute, + 'MicrophoneVolumeUp': LogicalKeyboardKey.microphoneVolumeUp, + 'ModeChange': LogicalKeyboardKey.modeChange, + 'NavigateIn': LogicalKeyboardKey.navigateIn, + 'NavigateNext': LogicalKeyboardKey.navigateNext, + 'NavigateOut': LogicalKeyboardKey.navigateOut, + 'NavigatePrevious': LogicalKeyboardKey.navigatePrevious, + 'New': LogicalKeyboardKey.newKey, + 'NextCandidate': LogicalKeyboardKey.nextCandidate, + 'NextFavoriteChannel': LogicalKeyboardKey.nextFavoriteChannel, + 'NextUserProfile': LogicalKeyboardKey.nextUserProfile, + 'NonConvert': LogicalKeyboardKey.nonConvert, + 'Notification': LogicalKeyboardKey.notification, + 'NumLock': LogicalKeyboardKey.numLock, + 'OnDemand': LogicalKeyboardKey.onDemand, + 'Open': LogicalKeyboardKey.open, + 'PageDown': LogicalKeyboardKey.pageDown, + 'PageUp': LogicalKeyboardKey.pageUp, + 'Pairing': LogicalKeyboardKey.pairing, + 'Paste': LogicalKeyboardKey.paste, + 'Pause': LogicalKeyboardKey.pause, + 'PinPDown': LogicalKeyboardKey.pInPDown, + 'PinPMove': LogicalKeyboardKey.pInPMove, + 'PinPToggle': LogicalKeyboardKey.pInPToggle, + 'PinPUp': LogicalKeyboardKey.pInPUp, + 'Play': LogicalKeyboardKey.play, + 'PlaySpeedDown': LogicalKeyboardKey.playSpeedDown, + 'PlaySpeedReset': LogicalKeyboardKey.playSpeedReset, + 'PlaySpeedUp': LogicalKeyboardKey.playSpeedUp, + 'Power': LogicalKeyboardKey.power, + 'PowerOff': LogicalKeyboardKey.powerOff, + 'PreviousCandidate': LogicalKeyboardKey.previousCandidate, + 'Print': LogicalKeyboardKey.print, + 'PrintScreen': LogicalKeyboardKey.printScreen, + 'Process': LogicalKeyboardKey.process, + 'Props': LogicalKeyboardKey.props, + 'RandomToggle': LogicalKeyboardKey.randomToggle, + 'RcLowBattery': LogicalKeyboardKey.rcLowBattery, + 'RecordSpeedNext': LogicalKeyboardKey.recordSpeedNext, + 'Redo': LogicalKeyboardKey.redo, + 'RfBypass': LogicalKeyboardKey.rfBypass, + 'Romaji': LogicalKeyboardKey.romaji, + 'STBInput': LogicalKeyboardKey.stbInput, + 'STBPower': LogicalKeyboardKey.stbPower, + 'Save': LogicalKeyboardKey.save, + 'ScanChannelsToggle': LogicalKeyboardKey.scanChannelsToggle, + 'ScreenModeNext': LogicalKeyboardKey.screenModeNext, + 'ScrollLock': LogicalKeyboardKey.scrollLock, + 'Select': LogicalKeyboardKey.select, + 'Settings': LogicalKeyboardKey.settings, + 'ShiftLevel5': LogicalKeyboardKey.shiftLevel5, + 'SingleCandidate': LogicalKeyboardKey.singleCandidate, + 'Soft1': LogicalKeyboardKey.soft1, + 'Soft2': LogicalKeyboardKey.soft2, + 'Soft3': LogicalKeyboardKey.soft3, + 'Soft4': LogicalKeyboardKey.soft4, + 'Soft5': LogicalKeyboardKey.soft5, + 'Soft6': LogicalKeyboardKey.soft6, + 'Soft7': LogicalKeyboardKey.soft7, + 'Soft8': LogicalKeyboardKey.soft8, + 'SpeechCorrectionList': LogicalKeyboardKey.speechCorrectionList, + 'SpeechInputToggle': LogicalKeyboardKey.speechInputToggle, + 'SpellCheck': LogicalKeyboardKey.spellCheck, + 'SplitScreenToggle': LogicalKeyboardKey.splitScreenToggle, + 'Standby': LogicalKeyboardKey.standby, + 'Subtitle': LogicalKeyboardKey.subtitle, + 'Super': LogicalKeyboardKey.superKey, + 'Symbol': LogicalKeyboardKey.symbol, + 'SymbolLock': LogicalKeyboardKey.symbolLock, + 'TV': LogicalKeyboardKey.tv, + 'TV3DMode': LogicalKeyboardKey.tv3DMode, + 'TVAntennaCable': LogicalKeyboardKey.tvAntennaCable, + 'TVAudioDescription': LogicalKeyboardKey.tvAudioDescription, + 'TVAudioDescriptionMixDown': LogicalKeyboardKey.tvAudioDescriptionMixDown, + 'TVAudioDescriptionMixUp': LogicalKeyboardKey.tvAudioDescriptionMixUp, + 'TVContentsMenu': LogicalKeyboardKey.tvContentsMenu, + 'TVDataService': LogicalKeyboardKey.tvDataService, + 'TVInput': LogicalKeyboardKey.tvInput, + 'TVInputComponent1': LogicalKeyboardKey.tvInputComponent1, + 'TVInputComponent2': LogicalKeyboardKey.tvInputComponent2, + 'TVInputComposite1': LogicalKeyboardKey.tvInputComposite1, + 'TVInputComposite2': LogicalKeyboardKey.tvInputComposite2, + 'TVInputHDMI1': LogicalKeyboardKey.tvInputHDMI1, + 'TVInputHDMI2': LogicalKeyboardKey.tvInputHDMI2, + 'TVInputHDMI3': LogicalKeyboardKey.tvInputHDMI3, + 'TVInputHDMI4': LogicalKeyboardKey.tvInputHDMI4, + 'TVInputVGA1': LogicalKeyboardKey.tvInputVGA1, + 'TVMediaContext': LogicalKeyboardKey.tvMediaContext, + 'TVNetwork': LogicalKeyboardKey.tvNetwork, + 'TVNumberEntry': LogicalKeyboardKey.tvNumberEntry, + 'TVPower': LogicalKeyboardKey.tvPower, + 'TVRadioService': LogicalKeyboardKey.tvRadioService, + 'TVSatellite': LogicalKeyboardKey.tvSatellite, + 'TVSatelliteBS': LogicalKeyboardKey.tvSatelliteBS, + 'TVSatelliteCS': LogicalKeyboardKey.tvSatelliteCS, + 'TVSatelliteToggle': LogicalKeyboardKey.tvSatelliteToggle, + 'TVTerrestrialAnalog': LogicalKeyboardKey.tvTerrestrialAnalog, + 'TVTerrestrialDigital': LogicalKeyboardKey.tvTerrestrialDigital, + 'TVTimer': LogicalKeyboardKey.tvTimer, + 'Tab': LogicalKeyboardKey.tab, + 'Teletext': LogicalKeyboardKey.teletext, + 'Undo': LogicalKeyboardKey.undo, + 'Unidentified': LogicalKeyboardKey.unidentified, + 'VideoModeNext': LogicalKeyboardKey.videoModeNext, + 'VoiceDial': LogicalKeyboardKey.voiceDial, + 'WakeUp': LogicalKeyboardKey.wakeUp, + 'Wink': LogicalKeyboardKey.wink, + 'Zenkaku': LogicalKeyboardKey.zenkaku, + 'ZenkakuHankaku': LogicalKeyboardKey.zenkakuHankaku, + 'ZoomIn': LogicalKeyboardKey.zoomIn, + 'ZoomOut': LogicalKeyboardKey.zoomOut, + 'ZoomToggle': LogicalKeyboardKey.zoomToggle, +}; + +/// Maps Web KeyboardEvent codes to the matching [PhysicalKeyboardKey]. +const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyboardKey>{ + 'Abort': PhysicalKeyboardKey.abort, + 'Again': PhysicalKeyboardKey.again, + 'AltLeft': PhysicalKeyboardKey.altLeft, + 'AltRight': PhysicalKeyboardKey.altRight, + 'ArrowDown': PhysicalKeyboardKey.arrowDown, + 'ArrowLeft': PhysicalKeyboardKey.arrowLeft, + 'ArrowRight': PhysicalKeyboardKey.arrowRight, + 'ArrowUp': PhysicalKeyboardKey.arrowUp, + 'AudioVolumeDown': PhysicalKeyboardKey.audioVolumeDown, + 'AudioVolumeMute': PhysicalKeyboardKey.audioVolumeMute, + 'AudioVolumeUp': PhysicalKeyboardKey.audioVolumeUp, + 'Backquote': PhysicalKeyboardKey.backquote, + 'Backslash': PhysicalKeyboardKey.backslash, + 'Backspace': PhysicalKeyboardKey.backspace, + 'BracketLeft': PhysicalKeyboardKey.bracketLeft, + 'BracketRight': PhysicalKeyboardKey.bracketRight, + 'BrightnessDown': PhysicalKeyboardKey.brightnessDown, + 'BrightnessUp': PhysicalKeyboardKey.brightnessUp, + 'BrowserBack': PhysicalKeyboardKey.browserBack, + 'BrowserFavorites': PhysicalKeyboardKey.browserFavorites, + 'BrowserForward': PhysicalKeyboardKey.browserForward, + 'BrowserHome': PhysicalKeyboardKey.browserHome, + 'BrowserRefresh': PhysicalKeyboardKey.browserRefresh, + 'BrowserSearch': PhysicalKeyboardKey.browserSearch, + 'BrowserStop': PhysicalKeyboardKey.browserStop, + 'CapsLock': PhysicalKeyboardKey.capsLock, + 'Comma': PhysicalKeyboardKey.comma, + 'ContextMenu': PhysicalKeyboardKey.contextMenu, + 'ControlLeft': PhysicalKeyboardKey.controlLeft, + 'ControlRight': PhysicalKeyboardKey.controlRight, + 'Convert': PhysicalKeyboardKey.convert, + 'Copy': PhysicalKeyboardKey.copy, + 'Cut': PhysicalKeyboardKey.cut, + 'Delete': PhysicalKeyboardKey.delete, + 'Digit0': PhysicalKeyboardKey.digit0, + 'Digit1': PhysicalKeyboardKey.digit1, + 'Digit2': PhysicalKeyboardKey.digit2, + 'Digit3': PhysicalKeyboardKey.digit3, + 'Digit4': PhysicalKeyboardKey.digit4, + 'Digit5': PhysicalKeyboardKey.digit5, + 'Digit6': PhysicalKeyboardKey.digit6, + 'Digit7': PhysicalKeyboardKey.digit7, + 'Digit8': PhysicalKeyboardKey.digit8, + 'Digit9': PhysicalKeyboardKey.digit9, + 'DisplayToggleIntExt': PhysicalKeyboardKey.displayToggleIntExt, + 'Eject': PhysicalKeyboardKey.eject, + 'End': PhysicalKeyboardKey.end, + 'Enter': PhysicalKeyboardKey.enter, + 'Equal': PhysicalKeyboardKey.equal, + 'Escape': PhysicalKeyboardKey.escape, + 'Esc': PhysicalKeyboardKey.escape, + 'F1': PhysicalKeyboardKey.f1, + 'F10': PhysicalKeyboardKey.f10, + 'F11': PhysicalKeyboardKey.f11, + 'F12': PhysicalKeyboardKey.f12, + 'F13': PhysicalKeyboardKey.f13, + 'F14': PhysicalKeyboardKey.f14, + 'F15': PhysicalKeyboardKey.f15, + 'F16': PhysicalKeyboardKey.f16, + 'F17': PhysicalKeyboardKey.f17, + 'F18': PhysicalKeyboardKey.f18, + 'F19': PhysicalKeyboardKey.f19, + 'F2': PhysicalKeyboardKey.f2, + 'F20': PhysicalKeyboardKey.f20, + 'F21': PhysicalKeyboardKey.f21, + 'F22': PhysicalKeyboardKey.f22, + 'F23': PhysicalKeyboardKey.f23, + 'F24': PhysicalKeyboardKey.f24, + 'F3': PhysicalKeyboardKey.f3, + 'F4': PhysicalKeyboardKey.f4, + 'F5': PhysicalKeyboardKey.f5, + 'F6': PhysicalKeyboardKey.f6, + 'F7': PhysicalKeyboardKey.f7, + 'F8': PhysicalKeyboardKey.f8, + 'F9': PhysicalKeyboardKey.f9, + 'Find': PhysicalKeyboardKey.find, + 'Fn': PhysicalKeyboardKey.fn, + 'FnLock': PhysicalKeyboardKey.fnLock, + 'GameButton1': PhysicalKeyboardKey.gameButton1, + 'GameButton10': PhysicalKeyboardKey.gameButton10, + 'GameButton11': PhysicalKeyboardKey.gameButton11, + 'GameButton12': PhysicalKeyboardKey.gameButton12, + 'GameButton13': PhysicalKeyboardKey.gameButton13, + 'GameButton14': PhysicalKeyboardKey.gameButton14, + 'GameButton15': PhysicalKeyboardKey.gameButton15, + 'GameButton16': PhysicalKeyboardKey.gameButton16, + 'GameButton2': PhysicalKeyboardKey.gameButton2, + 'GameButton3': PhysicalKeyboardKey.gameButton3, + 'GameButton4': PhysicalKeyboardKey.gameButton4, + 'GameButton5': PhysicalKeyboardKey.gameButton5, + 'GameButton6': PhysicalKeyboardKey.gameButton6, + 'GameButton7': PhysicalKeyboardKey.gameButton7, + 'GameButton8': PhysicalKeyboardKey.gameButton8, + 'GameButton9': PhysicalKeyboardKey.gameButton9, + 'GameButtonA': PhysicalKeyboardKey.gameButtonA, + 'GameButtonB': PhysicalKeyboardKey.gameButtonB, + 'GameButtonC': PhysicalKeyboardKey.gameButtonC, + 'GameButtonLeft1': PhysicalKeyboardKey.gameButtonLeft1, + 'GameButtonLeft2': PhysicalKeyboardKey.gameButtonLeft2, + 'GameButtonMode': PhysicalKeyboardKey.gameButtonMode, + 'GameButtonRight1': PhysicalKeyboardKey.gameButtonRight1, + 'GameButtonRight2': PhysicalKeyboardKey.gameButtonRight2, + 'GameButtonSelect': PhysicalKeyboardKey.gameButtonSelect, + 'GameButtonStart': PhysicalKeyboardKey.gameButtonStart, + 'GameButtonThumbLeft': PhysicalKeyboardKey.gameButtonThumbLeft, + 'GameButtonThumbRight': PhysicalKeyboardKey.gameButtonThumbRight, + 'GameButtonX': PhysicalKeyboardKey.gameButtonX, + 'GameButtonY': PhysicalKeyboardKey.gameButtonY, + 'GameButtonZ': PhysicalKeyboardKey.gameButtonZ, + 'Help': PhysicalKeyboardKey.help, + 'Home': PhysicalKeyboardKey.home, + 'Hyper': PhysicalKeyboardKey.hyper, + 'Insert': PhysicalKeyboardKey.insert, + 'IntlBackslash': PhysicalKeyboardKey.intlBackslash, + 'IntlRo': PhysicalKeyboardKey.intlRo, + 'IntlYen': PhysicalKeyboardKey.intlYen, + 'KanaMode': PhysicalKeyboardKey.kanaMode, + 'KeyA': PhysicalKeyboardKey.keyA, + 'KeyB': PhysicalKeyboardKey.keyB, + 'KeyC': PhysicalKeyboardKey.keyC, + 'KeyD': PhysicalKeyboardKey.keyD, + 'KeyE': PhysicalKeyboardKey.keyE, + 'KeyF': PhysicalKeyboardKey.keyF, + 'KeyG': PhysicalKeyboardKey.keyG, + 'KeyH': PhysicalKeyboardKey.keyH, + 'KeyI': PhysicalKeyboardKey.keyI, + 'KeyJ': PhysicalKeyboardKey.keyJ, + 'KeyK': PhysicalKeyboardKey.keyK, + 'KeyL': PhysicalKeyboardKey.keyL, + 'KeyM': PhysicalKeyboardKey.keyM, + 'KeyN': PhysicalKeyboardKey.keyN, + 'KeyO': PhysicalKeyboardKey.keyO, + 'KeyP': PhysicalKeyboardKey.keyP, + 'KeyQ': PhysicalKeyboardKey.keyQ, + 'KeyR': PhysicalKeyboardKey.keyR, + 'KeyS': PhysicalKeyboardKey.keyS, + 'KeyT': PhysicalKeyboardKey.keyT, + 'KeyU': PhysicalKeyboardKey.keyU, + 'KeyV': PhysicalKeyboardKey.keyV, + 'KeyW': PhysicalKeyboardKey.keyW, + 'KeyX': PhysicalKeyboardKey.keyX, + 'KeyY': PhysicalKeyboardKey.keyY, + 'KeyZ': PhysicalKeyboardKey.keyZ, + 'KeyboardLayoutSelect': PhysicalKeyboardKey.keyboardLayoutSelect, + 'Lang1': PhysicalKeyboardKey.lang1, + 'Lang2': PhysicalKeyboardKey.lang2, + 'Lang3': PhysicalKeyboardKey.lang3, + 'Lang4': PhysicalKeyboardKey.lang4, + 'Lang5': PhysicalKeyboardKey.lang5, + 'LaunchApp1': PhysicalKeyboardKey.launchApp1, + 'LaunchApp2': PhysicalKeyboardKey.launchApp2, + 'LaunchAssistant': PhysicalKeyboardKey.launchAssistant, + 'LaunchControlPanel': PhysicalKeyboardKey.launchControlPanel, + 'LaunchMail': PhysicalKeyboardKey.launchMail, + 'LaunchScreenSaver': PhysicalKeyboardKey.launchScreenSaver, + 'MailForward': PhysicalKeyboardKey.mailForward, + 'MailReply': PhysicalKeyboardKey.mailReply, + 'MailSend': PhysicalKeyboardKey.mailSend, + 'MediaFastForward': PhysicalKeyboardKey.mediaFastForward, + 'MediaPause': PhysicalKeyboardKey.mediaPause, + 'MediaPlay': PhysicalKeyboardKey.mediaPlay, + 'MediaPlayPause': PhysicalKeyboardKey.mediaPlayPause, + 'MediaRecord': PhysicalKeyboardKey.mediaRecord, + 'MediaRewind': PhysicalKeyboardKey.mediaRewind, + 'MediaSelect': PhysicalKeyboardKey.mediaSelect, + 'MediaStop': PhysicalKeyboardKey.mediaStop, + 'MediaTrackNext': PhysicalKeyboardKey.mediaTrackNext, + 'MediaTrackPrevious': PhysicalKeyboardKey.mediaTrackPrevious, + 'MetaLeft': PhysicalKeyboardKey.metaLeft, + 'MetaRight': PhysicalKeyboardKey.metaRight, + 'MicrophoneMuteToggle': PhysicalKeyboardKey.microphoneMuteToggle, + 'Minus': PhysicalKeyboardKey.minus, + 'NonConvert': PhysicalKeyboardKey.nonConvert, + 'NumLock': PhysicalKeyboardKey.numLock, + 'Numpad0': PhysicalKeyboardKey.numpad0, + 'Numpad1': PhysicalKeyboardKey.numpad1, + 'Numpad2': PhysicalKeyboardKey.numpad2, + 'Numpad3': PhysicalKeyboardKey.numpad3, + 'Numpad4': PhysicalKeyboardKey.numpad4, + 'Numpad5': PhysicalKeyboardKey.numpad5, + 'Numpad6': PhysicalKeyboardKey.numpad6, + 'Numpad7': PhysicalKeyboardKey.numpad7, + 'Numpad8': PhysicalKeyboardKey.numpad8, + 'Numpad9': PhysicalKeyboardKey.numpad9, + 'NumpadAdd': PhysicalKeyboardKey.numpadAdd, + 'NumpadBackspace': PhysicalKeyboardKey.numpadBackspace, + 'NumpadClear': PhysicalKeyboardKey.numpadClear, + 'NumpadClearEntry': PhysicalKeyboardKey.numpadClearEntry, + 'NumpadComma': PhysicalKeyboardKey.numpadComma, + 'NumpadDecimal': PhysicalKeyboardKey.numpadDecimal, + 'NumpadDivide': PhysicalKeyboardKey.numpadDivide, + 'NumpadEnter': PhysicalKeyboardKey.numpadEnter, + 'NumpadEqual': PhysicalKeyboardKey.numpadEqual, + 'NumpadMemoryAdd': PhysicalKeyboardKey.numpadMemoryAdd, + 'NumpadMemoryClear': PhysicalKeyboardKey.numpadMemoryClear, + 'NumpadMemoryRecall': PhysicalKeyboardKey.numpadMemoryRecall, + 'NumpadMemoryStore': PhysicalKeyboardKey.numpadMemoryStore, + 'NumpadMemorySubtract': PhysicalKeyboardKey.numpadMemorySubtract, + 'NumpadMultiply': PhysicalKeyboardKey.numpadMultiply, + 'NumpadParenLeft': PhysicalKeyboardKey.numpadParenLeft, + 'NumpadParenRight': PhysicalKeyboardKey.numpadParenRight, + 'NumpadSubtract': PhysicalKeyboardKey.numpadSubtract, + 'Open': PhysicalKeyboardKey.open, + 'PageDown': PhysicalKeyboardKey.pageDown, + 'PageUp': PhysicalKeyboardKey.pageUp, + 'Paste': PhysicalKeyboardKey.paste, + 'Pause': PhysicalKeyboardKey.pause, + 'Period': PhysicalKeyboardKey.period, + 'Power': PhysicalKeyboardKey.power, + 'PrintScreen': PhysicalKeyboardKey.printScreen, + 'PrivacyScreenToggle': PhysicalKeyboardKey.privacyScreenToggle, + 'Props': PhysicalKeyboardKey.props, + 'Quote': PhysicalKeyboardKey.quote, + 'Resume': PhysicalKeyboardKey.resume, + 'ScrollLock': PhysicalKeyboardKey.scrollLock, + 'Select': PhysicalKeyboardKey.select, + 'SelectTask': PhysicalKeyboardKey.selectTask, + 'Semicolon': PhysicalKeyboardKey.semicolon, + 'ShiftLeft': PhysicalKeyboardKey.shiftLeft, + 'ShiftRight': PhysicalKeyboardKey.shiftRight, + 'ShowAllWindows': PhysicalKeyboardKey.showAllWindows, + 'Slash': PhysicalKeyboardKey.slash, + 'Sleep': PhysicalKeyboardKey.sleep, + 'Space': PhysicalKeyboardKey.space, + 'Super': PhysicalKeyboardKey.superKey, + 'Suspend': PhysicalKeyboardKey.suspend, + 'Tab': PhysicalKeyboardKey.tab, + 'Turbo': PhysicalKeyboardKey.turbo, + 'Undo': PhysicalKeyboardKey.undo, + 'WakeUp': PhysicalKeyboardKey.wakeUp, + 'ZoomToggle': PhysicalKeyboardKey.zoomToggle, +}; + +/// A map of Web KeyboardEvent codes which have printable representations, but appear +/// on the number pad. Used to provide different key objects for keys like +/// KEY_EQUALS and NUMPAD_EQUALS. +const Map<String, LogicalKeyboardKey> kWebNumPadMap = <String, LogicalKeyboardKey>{ + 'Numpad0': LogicalKeyboardKey.numpad0, + 'Numpad1': LogicalKeyboardKey.numpad1, + 'Numpad2': LogicalKeyboardKey.numpad2, + 'Numpad3': LogicalKeyboardKey.numpad3, + 'Numpad4': LogicalKeyboardKey.numpad4, + 'Numpad5': LogicalKeyboardKey.numpad5, + 'Numpad6': LogicalKeyboardKey.numpad6, + 'Numpad7': LogicalKeyboardKey.numpad7, + 'Numpad8': LogicalKeyboardKey.numpad8, + 'Numpad9': LogicalKeyboardKey.numpad9, + 'NumpadAdd': LogicalKeyboardKey.numpadAdd, + 'NumpadComma': LogicalKeyboardKey.numpadComma, + 'NumpadDecimal': LogicalKeyboardKey.numpadDecimal, + 'NumpadDivide': LogicalKeyboardKey.numpadDivide, + 'NumpadEqual': LogicalKeyboardKey.numpadEqual, + 'NumpadMultiply': LogicalKeyboardKey.numpadMultiply, + 'NumpadParenLeft': LogicalKeyboardKey.numpadParenLeft, + 'NumpadParenRight': LogicalKeyboardKey.numpadParenRight, + 'NumpadSubtract': LogicalKeyboardKey.numpadSubtract, +}; + +/// A map of Web KeyboardEvent keys which needs to be decided based on location, +/// typically for numpad keys and modifier keys. Used to provide different key +/// objects for keys like KEY_EQUALS and NUMPAD_EQUALS. +const Map<String, List<LogicalKeyboardKey?>> kWebLocationMap = <String, List<LogicalKeyboardKey?>>{ + '*': <LogicalKeyboardKey?>[LogicalKeyboardKey.asterisk, null, null, LogicalKeyboardKey.numpadMultiply], + '+': <LogicalKeyboardKey?>[LogicalKeyboardKey.add, null, null, LogicalKeyboardKey.numpadAdd], + '-': <LogicalKeyboardKey?>[LogicalKeyboardKey.minus, null, null, LogicalKeyboardKey.numpadSubtract], + '.': <LogicalKeyboardKey?>[LogicalKeyboardKey.period, null, null, LogicalKeyboardKey.numpadDecimal], + '/': <LogicalKeyboardKey?>[LogicalKeyboardKey.slash, null, null, LogicalKeyboardKey.numpadDivide], + '0': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit0, null, null, LogicalKeyboardKey.numpad0], + '1': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit1, null, null, LogicalKeyboardKey.numpad1], + '2': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit2, null, null, LogicalKeyboardKey.numpad2], + '3': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit3, null, null, LogicalKeyboardKey.numpad3], + '4': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit4, null, null, LogicalKeyboardKey.numpad4], + '5': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit5, null, null, LogicalKeyboardKey.numpad5], + '6': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit6, null, null, LogicalKeyboardKey.numpad6], + '7': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit7, null, null, LogicalKeyboardKey.numpad7], + '8': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit8, null, null, LogicalKeyboardKey.numpad8], + '9': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit9, null, null, LogicalKeyboardKey.numpad9], + 'Alt': <LogicalKeyboardKey?>[LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altRight, null], + 'AltGraph': <LogicalKeyboardKey?>[LogicalKeyboardKey.altGraph, null, LogicalKeyboardKey.altGraph, null], + 'ArrowDown': <LogicalKeyboardKey?>[LogicalKeyboardKey.arrowDown, null, null, LogicalKeyboardKey.numpad2], + 'ArrowLeft': <LogicalKeyboardKey?>[LogicalKeyboardKey.arrowLeft, null, null, LogicalKeyboardKey.numpad4], + 'ArrowRight': <LogicalKeyboardKey?>[LogicalKeyboardKey.arrowRight, null, null, LogicalKeyboardKey.numpad6], + 'ArrowUp': <LogicalKeyboardKey?>[LogicalKeyboardKey.arrowUp, null, null, LogicalKeyboardKey.numpad8], + 'Clear': <LogicalKeyboardKey?>[LogicalKeyboardKey.clear, null, null, LogicalKeyboardKey.numpad5], + 'Control': <LogicalKeyboardKey?>[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.controlRight, null], + 'Delete': <LogicalKeyboardKey?>[LogicalKeyboardKey.delete, null, null, LogicalKeyboardKey.numpadDecimal], + 'End': <LogicalKeyboardKey?>[LogicalKeyboardKey.end, null, null, LogicalKeyboardKey.numpad1], + 'Enter': <LogicalKeyboardKey?>[LogicalKeyboardKey.enter, null, null, LogicalKeyboardKey.numpadEnter], + 'Home': <LogicalKeyboardKey?>[LogicalKeyboardKey.home, null, null, LogicalKeyboardKey.numpad7], + 'Insert': <LogicalKeyboardKey?>[LogicalKeyboardKey.insert, null, null, LogicalKeyboardKey.numpad0], + 'Meta': <LogicalKeyboardKey?>[LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.metaRight, null], + 'PageDown': <LogicalKeyboardKey?>[LogicalKeyboardKey.pageDown, null, null, LogicalKeyboardKey.numpad3], + 'PageUp': <LogicalKeyboardKey?>[LogicalKeyboardKey.pageUp, null, null, LogicalKeyboardKey.numpad9], + 'Shift': <LogicalKeyboardKey?>[LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftRight, null], +}; + +/// Maps Windows KeyboardEvent codes to the matching [LogicalKeyboardKey]. +const Map<int, LogicalKeyboardKey> kWindowsToLogicalKey = <int, LogicalKeyboardKey>{ + 3: LogicalKeyboardKey.cancel, + 8: LogicalKeyboardKey.backspace, + 9: LogicalKeyboardKey.tab, + 12: LogicalKeyboardKey.clear, + 13: LogicalKeyboardKey.enter, + 16: LogicalKeyboardKey.shiftLeft, + 17: LogicalKeyboardKey.controlLeft, + 19: LogicalKeyboardKey.pause, + 20: LogicalKeyboardKey.capsLock, + 21: LogicalKeyboardKey.lang1, + 23: LogicalKeyboardKey.junjaMode, + 24: LogicalKeyboardKey.finalMode, + 25: LogicalKeyboardKey.kanjiMode, + 27: LogicalKeyboardKey.escape, + 28: LogicalKeyboardKey.convert, + 30: LogicalKeyboardKey.accept, + 31: LogicalKeyboardKey.modeChange, + 32: LogicalKeyboardKey.space, + 33: LogicalKeyboardKey.pageUp, + 34: LogicalKeyboardKey.pageDown, + 35: LogicalKeyboardKey.end, + 36: LogicalKeyboardKey.home, + 37: LogicalKeyboardKey.arrowLeft, + 38: LogicalKeyboardKey.arrowUp, + 39: LogicalKeyboardKey.arrowRight, + 40: LogicalKeyboardKey.arrowDown, + 41: LogicalKeyboardKey.select, + 42: LogicalKeyboardKey.print, + 43: LogicalKeyboardKey.execute, + 44: LogicalKeyboardKey.printScreen, + 45: LogicalKeyboardKey.insert, + 46: LogicalKeyboardKey.delete, + 47: LogicalKeyboardKey.help, + 48: LogicalKeyboardKey.digit0, + 49: LogicalKeyboardKey.digit1, + 50: LogicalKeyboardKey.digit2, + 51: LogicalKeyboardKey.digit3, + 52: LogicalKeyboardKey.digit4, + 53: LogicalKeyboardKey.digit5, + 54: LogicalKeyboardKey.digit6, + 55: LogicalKeyboardKey.digit7, + 56: LogicalKeyboardKey.digit8, + 57: LogicalKeyboardKey.digit9, + 65: LogicalKeyboardKey.keyA, + 66: LogicalKeyboardKey.keyB, + 67: LogicalKeyboardKey.keyC, + 68: LogicalKeyboardKey.keyD, + 69: LogicalKeyboardKey.keyE, + 70: LogicalKeyboardKey.keyF, + 71: LogicalKeyboardKey.keyG, + 72: LogicalKeyboardKey.keyH, + 73: LogicalKeyboardKey.keyI, + 74: LogicalKeyboardKey.keyJ, + 75: LogicalKeyboardKey.keyK, + 76: LogicalKeyboardKey.keyL, + 77: LogicalKeyboardKey.keyM, + 78: LogicalKeyboardKey.keyN, + 79: LogicalKeyboardKey.keyO, + 80: LogicalKeyboardKey.keyP, + 81: LogicalKeyboardKey.keyQ, + 82: LogicalKeyboardKey.keyR, + 83: LogicalKeyboardKey.keyS, + 84: LogicalKeyboardKey.keyT, + 85: LogicalKeyboardKey.keyU, + 86: LogicalKeyboardKey.keyV, + 87: LogicalKeyboardKey.keyW, + 88: LogicalKeyboardKey.keyX, + 89: LogicalKeyboardKey.keyY, + 90: LogicalKeyboardKey.keyZ, + 91: LogicalKeyboardKey.metaLeft, + 92: LogicalKeyboardKey.metaRight, + 93: LogicalKeyboardKey.contextMenu, + 95: LogicalKeyboardKey.sleep, + 96: LogicalKeyboardKey.numpad0, + 97: LogicalKeyboardKey.numpad1, + 98: LogicalKeyboardKey.numpad2, + 99: LogicalKeyboardKey.numpad3, + 100: LogicalKeyboardKey.numpad4, + 101: LogicalKeyboardKey.numpad5, + 102: LogicalKeyboardKey.numpad6, + 103: LogicalKeyboardKey.numpad7, + 104: LogicalKeyboardKey.numpad8, + 105: LogicalKeyboardKey.numpad9, + 106: LogicalKeyboardKey.numpadMultiply, + 107: LogicalKeyboardKey.numpadAdd, + 108: LogicalKeyboardKey.numpadComma, + 109: LogicalKeyboardKey.numpadSubtract, + 110: LogicalKeyboardKey.numpadDecimal, + 111: LogicalKeyboardKey.numpadDivide, + 112: LogicalKeyboardKey.f1, + 113: LogicalKeyboardKey.f2, + 114: LogicalKeyboardKey.f3, + 115: LogicalKeyboardKey.f4, + 116: LogicalKeyboardKey.f5, + 117: LogicalKeyboardKey.f6, + 118: LogicalKeyboardKey.f7, + 119: LogicalKeyboardKey.f8, + 120: LogicalKeyboardKey.f9, + 121: LogicalKeyboardKey.f10, + 122: LogicalKeyboardKey.f11, + 123: LogicalKeyboardKey.f12, + 124: LogicalKeyboardKey.f13, + 125: LogicalKeyboardKey.f14, + 126: LogicalKeyboardKey.f15, + 127: LogicalKeyboardKey.f16, + 128: LogicalKeyboardKey.f17, + 129: LogicalKeyboardKey.f18, + 130: LogicalKeyboardKey.f19, + 131: LogicalKeyboardKey.f20, + 132: LogicalKeyboardKey.f21, + 133: LogicalKeyboardKey.f22, + 134: LogicalKeyboardKey.f23, + 135: LogicalKeyboardKey.f24, + 144: LogicalKeyboardKey.numLock, + 145: LogicalKeyboardKey.scrollLock, + 146: LogicalKeyboardKey.numpadEqual, + 160: LogicalKeyboardKey.shiftLeft, + 161: LogicalKeyboardKey.shiftRight, + 162: LogicalKeyboardKey.controlLeft, + 163: LogicalKeyboardKey.controlRight, + 164: LogicalKeyboardKey.altLeft, + 165: LogicalKeyboardKey.altRight, + 166: LogicalKeyboardKey.browserBack, + 167: LogicalKeyboardKey.browserForward, + 168: LogicalKeyboardKey.browserRefresh, + 169: LogicalKeyboardKey.browserStop, + 170: LogicalKeyboardKey.browserSearch, + 171: LogicalKeyboardKey.browserFavorites, + 172: LogicalKeyboardKey.browserHome, + 173: LogicalKeyboardKey.audioVolumeMute, + 174: LogicalKeyboardKey.audioVolumeDown, + 175: LogicalKeyboardKey.audioVolumeUp, + 178: LogicalKeyboardKey.mediaStop, + 179: LogicalKeyboardKey.mediaPlayPause, + 180: LogicalKeyboardKey.launchMail, + 186: LogicalKeyboardKey.semicolon, + 187: LogicalKeyboardKey.equal, + 188: LogicalKeyboardKey.comma, + 189: LogicalKeyboardKey.minus, + 190: LogicalKeyboardKey.period, + 191: LogicalKeyboardKey.slash, + 192: LogicalKeyboardKey.backquote, + 195: LogicalKeyboardKey.gameButton8, + 196: LogicalKeyboardKey.gameButton9, + 197: LogicalKeyboardKey.gameButton10, + 198: LogicalKeyboardKey.gameButton11, + 199: LogicalKeyboardKey.gameButton12, + 200: LogicalKeyboardKey.gameButton13, + 201: LogicalKeyboardKey.gameButton14, + 202: LogicalKeyboardKey.gameButton15, + 203: LogicalKeyboardKey.gameButton16, + 219: LogicalKeyboardKey.bracketLeft, + 220: LogicalKeyboardKey.backslash, + 221: LogicalKeyboardKey.bracketRight, + 222: LogicalKeyboardKey.quote, + 246: LogicalKeyboardKey.attn, + 250: LogicalKeyboardKey.play, +}; + +/// Maps Windows KeyboardEvent codes to the matching [PhysicalKeyboardKey]. +const Map<int, PhysicalKeyboardKey> kWindowsToPhysicalKey = <int, PhysicalKeyboardKey>{ + 1: PhysicalKeyboardKey.escape, + 2: PhysicalKeyboardKey.digit1, + 3: PhysicalKeyboardKey.digit2, + 4: PhysicalKeyboardKey.digit3, + 5: PhysicalKeyboardKey.digit4, + 6: PhysicalKeyboardKey.digit5, + 7: PhysicalKeyboardKey.digit6, + 8: PhysicalKeyboardKey.digit7, + 9: PhysicalKeyboardKey.digit8, + 10: PhysicalKeyboardKey.digit9, + 11: PhysicalKeyboardKey.digit0, + 12: PhysicalKeyboardKey.minus, + 13: PhysicalKeyboardKey.equal, + 14: PhysicalKeyboardKey.backspace, + 15: PhysicalKeyboardKey.tab, + 16: PhysicalKeyboardKey.keyQ, + 17: PhysicalKeyboardKey.keyW, + 18: PhysicalKeyboardKey.keyE, + 19: PhysicalKeyboardKey.keyR, + 20: PhysicalKeyboardKey.keyT, + 21: PhysicalKeyboardKey.keyY, + 22: PhysicalKeyboardKey.keyU, + 23: PhysicalKeyboardKey.keyI, + 24: PhysicalKeyboardKey.keyO, + 25: PhysicalKeyboardKey.keyP, + 26: PhysicalKeyboardKey.bracketLeft, + 27: PhysicalKeyboardKey.bracketRight, + 28: PhysicalKeyboardKey.enter, + 29: PhysicalKeyboardKey.controlLeft, + 30: PhysicalKeyboardKey.keyA, + 31: PhysicalKeyboardKey.keyS, + 32: PhysicalKeyboardKey.keyD, + 33: PhysicalKeyboardKey.keyF, + 34: PhysicalKeyboardKey.keyG, + 35: PhysicalKeyboardKey.keyH, + 36: PhysicalKeyboardKey.keyJ, + 37: PhysicalKeyboardKey.keyK, + 38: PhysicalKeyboardKey.keyL, + 39: PhysicalKeyboardKey.semicolon, + 40: PhysicalKeyboardKey.quote, + 41: PhysicalKeyboardKey.backquote, + 42: PhysicalKeyboardKey.shiftLeft, + 43: PhysicalKeyboardKey.backslash, + 44: PhysicalKeyboardKey.keyZ, + 45: PhysicalKeyboardKey.keyX, + 46: PhysicalKeyboardKey.keyC, + 47: PhysicalKeyboardKey.keyV, + 48: PhysicalKeyboardKey.keyB, + 49: PhysicalKeyboardKey.keyN, + 50: PhysicalKeyboardKey.keyM, + 51: PhysicalKeyboardKey.comma, + 52: PhysicalKeyboardKey.period, + 53: PhysicalKeyboardKey.slash, + 54: PhysicalKeyboardKey.shiftRight, + 55: PhysicalKeyboardKey.numpadMultiply, + 56: PhysicalKeyboardKey.altLeft, + 57: PhysicalKeyboardKey.space, + 58: PhysicalKeyboardKey.capsLock, + 59: PhysicalKeyboardKey.f1, + 60: PhysicalKeyboardKey.f2, + 61: PhysicalKeyboardKey.f3, + 62: PhysicalKeyboardKey.f4, + 63: PhysicalKeyboardKey.f5, + 64: PhysicalKeyboardKey.f6, + 65: PhysicalKeyboardKey.f7, + 66: PhysicalKeyboardKey.f8, + 67: PhysicalKeyboardKey.f9, + 68: PhysicalKeyboardKey.f10, + 69: PhysicalKeyboardKey.pause, + 70: PhysicalKeyboardKey.scrollLock, + 71: PhysicalKeyboardKey.numpad7, + 72: PhysicalKeyboardKey.numpad8, + 73: PhysicalKeyboardKey.numpad9, + 74: PhysicalKeyboardKey.numpadSubtract, + 75: PhysicalKeyboardKey.numpad4, + 76: PhysicalKeyboardKey.numpad5, + 77: PhysicalKeyboardKey.numpad6, + 78: PhysicalKeyboardKey.numpadAdd, + 79: PhysicalKeyboardKey.numpad1, + 80: PhysicalKeyboardKey.numpad2, + 81: PhysicalKeyboardKey.numpad3, + 82: PhysicalKeyboardKey.numpad0, + 83: PhysicalKeyboardKey.numpadDecimal, + 86: PhysicalKeyboardKey.intlBackslash, + 87: PhysicalKeyboardKey.f11, + 88: PhysicalKeyboardKey.f12, + 89: PhysicalKeyboardKey.numpadEqual, + 100: PhysicalKeyboardKey.f13, + 101: PhysicalKeyboardKey.f14, + 102: PhysicalKeyboardKey.f15, + 103: PhysicalKeyboardKey.f16, + 104: PhysicalKeyboardKey.f17, + 105: PhysicalKeyboardKey.f18, + 106: PhysicalKeyboardKey.f19, + 107: PhysicalKeyboardKey.f20, + 108: PhysicalKeyboardKey.f21, + 109: PhysicalKeyboardKey.f22, + 110: PhysicalKeyboardKey.f23, + 112: PhysicalKeyboardKey.kanaMode, + 113: PhysicalKeyboardKey.lang2, + 114: PhysicalKeyboardKey.lang1, + 115: PhysicalKeyboardKey.intlRo, + 118: PhysicalKeyboardKey.f24, + 119: PhysicalKeyboardKey.lang4, + 120: PhysicalKeyboardKey.lang3, + 121: PhysicalKeyboardKey.convert, + 123: PhysicalKeyboardKey.nonConvert, + 125: PhysicalKeyboardKey.intlYen, + 126: PhysicalKeyboardKey.numpadComma, + 252: PhysicalKeyboardKey.usbPostFail, + 255: PhysicalKeyboardKey.usbErrorRollOver, + 57352: PhysicalKeyboardKey.undo, + 57354: PhysicalKeyboardKey.paste, + 57360: PhysicalKeyboardKey.mediaTrackPrevious, + 57367: PhysicalKeyboardKey.cut, + 57368: PhysicalKeyboardKey.copy, + 57369: PhysicalKeyboardKey.mediaTrackNext, + 57372: PhysicalKeyboardKey.numpadEnter, + 57373: PhysicalKeyboardKey.controlRight, + 57376: PhysicalKeyboardKey.audioVolumeMute, + 57377: PhysicalKeyboardKey.launchApp2, + 57378: PhysicalKeyboardKey.mediaPlayPause, + 57380: PhysicalKeyboardKey.mediaStop, + 57388: PhysicalKeyboardKey.eject, + 57390: PhysicalKeyboardKey.audioVolumeDown, + 57392: PhysicalKeyboardKey.audioVolumeUp, + 57394: PhysicalKeyboardKey.browserHome, + 57397: PhysicalKeyboardKey.numpadDivide, + 57399: PhysicalKeyboardKey.printScreen, + 57400: PhysicalKeyboardKey.altRight, + 57403: PhysicalKeyboardKey.help, + 57413: PhysicalKeyboardKey.numLock, + 57415: PhysicalKeyboardKey.home, + 57416: PhysicalKeyboardKey.arrowUp, + 57417: PhysicalKeyboardKey.pageUp, + 57419: PhysicalKeyboardKey.arrowLeft, + 57421: PhysicalKeyboardKey.arrowRight, + 57423: PhysicalKeyboardKey.end, + 57424: PhysicalKeyboardKey.arrowDown, + 57425: PhysicalKeyboardKey.pageDown, + 57426: PhysicalKeyboardKey.insert, + 57427: PhysicalKeyboardKey.delete, + 57435: PhysicalKeyboardKey.metaLeft, + 57436: PhysicalKeyboardKey.metaRight, + 57437: PhysicalKeyboardKey.contextMenu, + 57438: PhysicalKeyboardKey.power, + 57439: PhysicalKeyboardKey.sleep, + 57443: PhysicalKeyboardKey.wakeUp, + 57445: PhysicalKeyboardKey.browserSearch, + 57446: PhysicalKeyboardKey.browserFavorites, + 57447: PhysicalKeyboardKey.browserRefresh, + 57448: PhysicalKeyboardKey.browserStop, + 57449: PhysicalKeyboardKey.browserForward, + 57450: PhysicalKeyboardKey.browserBack, + 57451: PhysicalKeyboardKey.launchApp1, + 57452: PhysicalKeyboardKey.launchMail, + 57453: PhysicalKeyboardKey.mediaSelect, +}; + +/// A map of Windows KeyboardEvent codes which have printable representations, but appear +/// on the number pad. Used to provide different key objects for keys like +/// KEY_EQUALS and NUMPAD_EQUALS. +const Map<int, LogicalKeyboardKey> kWindowsNumPadMap = <int, LogicalKeyboardKey>{ + 96: LogicalKeyboardKey.numpad0, + 97: LogicalKeyboardKey.numpad1, + 98: LogicalKeyboardKey.numpad2, + 99: LogicalKeyboardKey.numpad3, + 100: LogicalKeyboardKey.numpad4, + 101: LogicalKeyboardKey.numpad5, + 102: LogicalKeyboardKey.numpad6, + 103: LogicalKeyboardKey.numpad7, + 104: LogicalKeyboardKey.numpad8, + 105: LogicalKeyboardKey.numpad9, + 106: LogicalKeyboardKey.numpadMultiply, + 107: LogicalKeyboardKey.numpadAdd, + 108: LogicalKeyboardKey.numpadComma, + 109: LogicalKeyboardKey.numpadSubtract, + 110: LogicalKeyboardKey.numpadDecimal, + 111: LogicalKeyboardKey.numpadDivide, + 146: LogicalKeyboardKey.numpadEqual, +}; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/live_text.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/live_text.dart new file mode 100644 index 0000000000000000000000000000000000000000..413f7f0698565cb05ba4cb5d8272f58d1b7e52ed --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/live_text.dart @@ -0,0 +1,35 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'system_channels.dart'; + +/// Utility methods for interacting with the system's Live Text. +/// +/// For example, the Live Text input feature of iOS turns the keyboard into a camera view for +/// directly inserting text obtained through OCR into the active field. +/// +/// See also: +/// * <https://developer.apple.com/documentation/uikit/uiresponder/3778577-capturetextfromcamera> +/// * <https://support.apple.com/guide/iphone/use-live-text-iphcf0b71b0e/ios> +class LiveText { + // This class is not meant to be instantiated or extended; this constructor + // prevents instantiation and extension. + LiveText._(); + + /// Returns true if the Live Text input feature is available on the current device. + static Future<bool> isLiveTextInputAvailable() async { + final bool supportLiveTextInput = + await SystemChannels.platform.invokeMethod('LiveText.isLiveTextInputAvailable') ?? false; + return supportLiveTextInput; + } + + /// Start Live Text input. + /// + /// If any [TextInputConnection] is currently active, calling this method will tell the text field + /// to start Live Text input. If the current device doesn't support Live Text input, + /// nothing will happen. + static void startLiveTextInput() { + SystemChannels.textInput.invokeMethod('TextInput.startLiveTextInput'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/message_codec.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/message_codec.dart new file mode 100644 index 0000000000000000000000000000000000000000..d9b87721e6f031f047adf3204ffac55b7fb045d9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/message_codec.dart @@ -0,0 +1,220 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'platform_channel.dart'; + +export 'dart:typed_data' show ByteData; + +/// A message encoding/decoding mechanism. +/// +/// Both operations throw an exception, if conversion fails. Such situations +/// should be treated as programming errors. +/// +/// See also: +/// +/// * [BasicMessageChannel], which use [MessageCodec]s for communication +/// between Flutter and platform plugins. +abstract class MessageCodec<T> { + /// Encodes the specified [message] in binary. + /// + /// Returns null if the message is null. + ByteData? encodeMessage(T message); + + /// Decodes the specified [message] from binary. + /// + /// Returns null if the message is null. + T? decodeMessage(ByteData? message); +} + +/// A command object representing the invocation of a named method. +@pragma('vm:keep-name') +@immutable +class MethodCall { + /// Creates a [MethodCall] representing the invocation of [method] with the + /// specified [arguments]. + const MethodCall(this.method, [this.arguments]); + + /// The name of the method to be called. + final String method; + + /// The arguments for the method. + /// + /// Must be a valid value for the [MethodCodec] used. + /// + /// This property is `dynamic`, which means type-checking is skipped when accessing + /// this property. To minimize the risk of type errors at runtime, the value should + /// be cast to `Object?` when accessed. + final dynamic arguments; + + @override + String toString() => '${objectRuntimeType(this, 'MethodCall')}($method, $arguments)'; +} + +/// A codec for method calls and enveloped results. +/// +/// All operations throw an exception, if conversion fails. +/// +/// See also: +/// +/// * [MethodChannel], which use [MethodCodec]s for communication +/// between Flutter and platform plugins. +/// * [EventChannel], which use [MethodCodec]s for communication +/// between Flutter and platform plugins. +abstract class MethodCodec { + /// Encodes the specified [methodCall] into binary. + ByteData encodeMethodCall(MethodCall methodCall); + + /// Decodes the specified [methodCall] from binary. + MethodCall decodeMethodCall(ByteData? methodCall); + + /// Decodes the specified result [envelope] from binary. + /// + /// Throws [PlatformException], if [envelope] represents an error, otherwise + /// returns the enveloped result. + /// + /// The type returned from [decodeEnvelope] is `dynamic` (not `Object?`), + /// which means *no type checking is performed on its return value*. It is + /// strongly recommended that the return value be immediately cast to a known + /// type to prevent runtime errors due to typos that the type checker could + /// otherwise catch. + dynamic decodeEnvelope(ByteData envelope); + + /// Encodes a successful [result] into a binary envelope. + ByteData encodeSuccessEnvelope(Object? result); + + /// Encodes an error result into a binary envelope. + /// + /// The specified error [code], human-readable error [message] and error + /// [details] correspond to the fields of [PlatformException]. + ByteData encodeErrorEnvelope({ required String code, String? message, Object? details}); +} + +/// Thrown to indicate that a platform interaction failed in the platform +/// plugin. +/// +/// See also: +/// +/// * [MethodCodec], which throws a [PlatformException], if a received result +/// envelope represents an error. +/// * [MethodChannel.invokeMethod], which completes the returned future +/// with a [PlatformException], if invoking the platform plugin method +/// results in an error envelope. +/// * [EventChannel.receiveBroadcastStream], which emits +/// [PlatformException]s as error events, whenever an event received from the +/// platform plugin is wrapped in an error envelope. +class PlatformException implements Exception { + /// Creates a [PlatformException] with the specified error [code] and optional + /// [message], and with the optional error [details] which must be a valid + /// value for the [MethodCodec] involved in the interaction. + PlatformException({ + required this.code, + this.message, + this.details, + this.stacktrace, + }); + + /// An error code. + final String code; + + /// A human-readable error message, possibly null. + final String? message; + + /// Error details, possibly null. + /// + /// This property is `dynamic`, which means type-checking is skipped when accessing + /// this property. To minimize the risk of type errors at runtime, the value should + /// be cast to `Object?` when accessed. + final dynamic details; + + /// Native stacktrace for the error, possibly null. + /// + /// This contains the native platform stack trace, not the Dart stack trace. + /// + /// The stack trace for Dart exceptions can be obtained using try-catch blocks, for example: + /// + /// ```dart + /// try { + /// // ... + /// } catch (e, stacktrace) { + /// print(stacktrace); + /// } + /// ``` + /// + /// On Android this field is populated when a `RuntimeException` or a subclass of it is thrown in the method call handler, + /// as shown in the following example: + /// + /// ```kotlin + /// import androidx.annotation.NonNull + /// import io.flutter.embedding.android.FlutterActivity + /// import io.flutter.embedding.engine.FlutterEngine + /// import io.flutter.plugin.common.MethodChannel + /// + /// class MainActivity: FlutterActivity() { + /// private val CHANNEL = "channel_name" + /// + /// override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { + /// super.configureFlutterEngine(flutterEngine) + /// MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { + /// call, result -> throw RuntimeException("Oh no") + /// } + /// } + /// } + /// ``` + /// + /// It is also populated on Android if the method channel result is not serializable. + /// If the result is not serializable, an exception gets thrown during the serialization process. + /// This can be seen in the following example: + /// + /// ```kotlin + /// import androidx.annotation.NonNull + /// import io.flutter.embedding.android.FlutterActivity + /// import io.flutter.embedding.engine.FlutterEngine + /// import io.flutter.plugin.common.MethodChannel + /// + /// class MainActivity: FlutterActivity() { + /// private val CHANNEL = "channel_name" + /// + /// override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { + /// super.configureFlutterEngine(flutterEngine) + /// MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { + /// call, result -> result.success(Object()) + /// } + /// } + /// } + /// ``` + /// + /// In the cases described above, the content of [stacktrace] will be the unprocessed output of calling `toString()` on the exception. + /// + /// MacOS, iOS, Linux and Windows don't support querying the native stacktrace. + /// + /// On custom Flutter embedders this value will be null on platforms that don't support querying the call stack. + final String? stacktrace; + + @override + String toString() => 'PlatformException($code, $message, $details, $stacktrace)'; +} + +/// Thrown to indicate that a platform interaction failed to find a handling +/// plugin. +/// +/// See also: +/// +/// * [MethodChannel.invokeMethod], which completes the returned future +/// with a [MissingPluginException], if no plugin handler for the method call +/// was found. +/// * [OptionalMethodChannel.invokeMethod], which completes the returned future +/// with null, if no plugin handler for the method call was found. +class MissingPluginException implements Exception { + /// Creates a [MissingPluginException] with an optional human-readable + /// error message. + MissingPluginException([this.message]); + + /// A human-readable error message, possibly null. + final String? message; + + @override + String toString() => 'MissingPluginException($message)'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/message_codecs.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/message_codecs.dart new file mode 100644 index 0000000000000000000000000000000000000000..2b103d9624cc53d1022a84817517aea123fba71e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/message_codecs.dart @@ -0,0 +1,656 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:convert'; +import 'dart:typed_data'; + +import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; + +import 'message_codec.dart'; + +export 'dart:typed_data' show ByteData; + +export 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; + +export 'message_codec.dart' show MethodCall; + +const int _writeBufferStartCapacity = 64; + +/// [MessageCodec] with unencoded binary messages represented using [ByteData]. +/// +/// On Android, messages will be represented using `java.nio.ByteBuffer`. +/// On iOS, messages will be represented using `NSData`. +/// +/// When sending outgoing messages from Android, be sure to use direct `ByteBuffer` +/// as opposed to indirect. The `wrap()` API provides indirect buffers by default +/// and you will get empty `ByteData` objects in Dart. +class BinaryCodec implements MessageCodec<ByteData> { + /// Creates a [MessageCodec] with unencoded binary messages represented using + /// [ByteData]. + const BinaryCodec(); + + @override + ByteData? decodeMessage(ByteData? message) => message; + + @override + ByteData? encodeMessage(ByteData? message) => message; +} + +/// [MessageCodec] with UTF-8 encoded String messages. +/// +/// On Android, messages will be represented using `java.util.String`. +/// On iOS, messages will be represented using `NSString`. +class StringCodec implements MessageCodec<String> { + /// Creates a [MessageCodec] with UTF-8 encoded String messages. + const StringCodec(); + + @override + String? decodeMessage(ByteData? message) { + if (message == null) { + return null; + } + return utf8.decode(Uint8List.sublistView(message)); + } + + @override + ByteData? encodeMessage(String? message) { + if (message == null) { + return null; + } + return ByteData.sublistView(utf8.encode(message)); + } +} + +/// [MessageCodec] with UTF-8 encoded JSON messages. +/// +/// Supported messages are acyclic values of these forms: +/// +/// * null +/// * [bool]s +/// * [num]s +/// * [String]s +/// * [List]s of supported values +/// * [Map]s from strings to supported values +/// +/// On Android, messages are decoded using the `org.json` library. +/// On iOS, messages are decoded using the `NSJSONSerialization` library. +/// In both cases, the use of top-level simple messages (null, [bool], [num], +/// and [String]) is supported (by the Flutter SDK). The decoded value will be +/// null/nil for null, and identical to what would result from decoding a +/// singleton JSON array with a Boolean, number, or string value, and then +/// extracting its single element. +/// +/// The type returned from [decodeMessage] is `dynamic` (not `Object?`), which +/// means *no type checking is performed on its return value*. It is strongly +/// recommended that the return value be immediately cast to a known type to +/// prevent runtime errors due to typos that the type checker could otherwise +/// catch. +class JSONMessageCodec implements MessageCodec<Object?> { + // The codec serializes messages as defined by the JSON codec of the + // dart:convert package. The format used must match the Android and + // iOS counterparts. + + /// Creates a [MessageCodec] with UTF-8 encoded JSON messages. + const JSONMessageCodec(); + + @override + ByteData? encodeMessage(Object? message) { + if (message == null) { + return null; + } + return const StringCodec().encodeMessage(json.encode(message)); + } + + @override + dynamic decodeMessage(ByteData? message) { + if (message == null) { + return message; + } + return json.decode(const StringCodec().decodeMessage(message)!); + } +} + +/// [MethodCodec] with UTF-8 encoded JSON method calls and result envelopes. +/// +/// Values supported as method arguments and result payloads are those supported +/// by [JSONMessageCodec]. +class JSONMethodCodec implements MethodCodec { + // The codec serializes method calls, and result envelopes as outlined below. + // This format must match the Android and iOS counterparts. + // + // * Individual values are serialized as defined by the JSON codec of the + // dart:convert package. + // * Method calls are serialized as two-element maps, with the method name + // keyed by 'method' and the arguments keyed by 'args'. + // * Reply envelopes are serialized as either: + // * one-element lists containing the successful result as its single + // element, or + // * three-element lists containing, in order, an error code String, an + // error message String, and an error details value. + + /// Creates a [MethodCodec] with UTF-8 encoded JSON method calls and result + /// envelopes. + const JSONMethodCodec(); + + @override + ByteData encodeMethodCall(MethodCall methodCall) { + return const JSONMessageCodec().encodeMessage(<String, Object?>{ + 'method': methodCall.method, + 'args': methodCall.arguments, + })!; + } + + @override + MethodCall decodeMethodCall(ByteData? methodCall) { + final Object? decoded = const JSONMessageCodec().decodeMessage(methodCall); + if (decoded is! Map) { + throw FormatException('Expected method call Map, got $decoded'); + } + final Object? method = decoded['method']; + final Object? arguments = decoded['args']; + if (method is String) { + return MethodCall(method, arguments); + } + throw FormatException('Invalid method call: $decoded'); + } + + @override + dynamic decodeEnvelope(ByteData envelope) { + final Object? decoded = const JSONMessageCodec().decodeMessage(envelope); + if (decoded is! List) { + throw FormatException('Expected envelope List, got $decoded'); + } + if (decoded.length == 1) { + return decoded[0]; + } + if (decoded.length == 3 + && decoded[0] is String + && (decoded[1] == null || decoded[1] is String)) { + throw PlatformException( + code: decoded[0] as String, + message: decoded[1] as String?, + details: decoded[2], + ); + } + if (decoded.length == 4 + && decoded[0] is String + && (decoded[1] == null || decoded[1] is String) + && (decoded[3] == null || decoded[3] is String)) { + throw PlatformException( + code: decoded[0] as String, + message: decoded[1] as String?, + details: decoded[2], + stacktrace: decoded[3] as String?, + ); + } + throw FormatException('Invalid envelope: $decoded'); + } + + @override + ByteData encodeSuccessEnvelope(Object? result) { + return const JSONMessageCodec().encodeMessage(<Object?>[result])!; + } + + @override + ByteData encodeErrorEnvelope({ required String code, String? message, Object? details}) { + return const JSONMessageCodec().encodeMessage(<Object?>[code, message, details])!; + } +} + +/// [MessageCodec] using the Flutter standard binary encoding. +/// +/// Supported messages are acyclic values of these forms: +/// +/// * null +/// * [bool]s +/// * [num]s +/// * [String]s +/// * [Uint8List]s, [Int32List]s, [Int64List]s, [Float64List]s +/// * [List]s of supported values +/// * [Map]s from supported values to supported values +/// +/// Decoded values will use `List<Object?>` and `Map<Object?, Object?>` +/// irrespective of content. +/// +/// The type returned from [decodeMessage] is `dynamic` (not `Object?`), which +/// means *no type checking is performed on its return value*. It is strongly +/// recommended that the return value be immediately cast to a known type to +/// prevent runtime errors due to typos that the type checker could otherwise +/// catch. +/// +/// The codec is extensible by subclasses overriding [writeValue] and +/// [readValueOfType]. +/// +/// ## Android specifics +/// +/// On Android, messages are represented as follows: +/// +/// * null: null +/// * [bool]\: `java.lang.Boolean` +/// * [int]\: `java.lang.Integer` for values that are representable using 32-bit +/// two's complement; `java.lang.Long` otherwise +/// * [double]\: `java.lang.Double` +/// * [String]\: `java.lang.String` +/// * [Uint8List]\: `byte[]` +/// * [Int32List]\: `int[]` +/// * [Int64List]\: `long[]` +/// * [Float64List]\: `double[]` +/// * [List]\: `java.util.ArrayList` +/// * [Map]\: `java.util.HashMap` +/// +/// When sending a `java.math.BigInteger` from Java, it is converted into a +/// [String] with the hexadecimal representation of the integer. (The value is +/// tagged as being a big integer; subclasses of this class could be made to +/// support it natively; see the discussion at [writeValue].) This codec does +/// not support sending big integers from Dart. +/// +/// ## iOS specifics +/// +/// On iOS, messages are represented as follows: +/// +/// * null: nil +/// * [bool]\: `NSNumber numberWithBool:` +/// * [int]\: `NSNumber numberWithInt:` for values that are representable using +/// 32-bit two's complement; `NSNumber numberWithLong:` otherwise +/// * [double]\: `NSNumber numberWithDouble:` +/// * [String]\: `NSString` +/// * [Uint8List], [Int32List], [Int64List], [Float64List]\: +/// `FlutterStandardTypedData` +/// * [List]\: `NSArray` +/// * [Map]\: `NSDictionary` +class StandardMessageCodec implements MessageCodec<Object?> { + /// Creates a [MessageCodec] using the Flutter standard binary encoding. + const StandardMessageCodec(); + + // The codec serializes messages as outlined below. This format must match the + // Android and iOS counterparts and cannot change (as it's possible for + // someone to end up using this for persistent storage). + // + // * A single byte with one of the constant values below determines the + // type of the value. + // * The serialization of the value itself follows the type byte. + // * Numbers are represented using the host endianness throughout. + // * Lengths and sizes of serialized parts are encoded using an expanding + // format optimized for the common case of small non-negative integers: + // * values 0..253 inclusive using one byte with that value; + // * values 254..2^16 inclusive using three bytes, the first of which is + // 254, the next two the usual unsigned representation of the value; + // * values 2^16+1..2^32 inclusive using five bytes, the first of which is + // 255, the next four the usual unsigned representation of the value. + // * null, true, and false have empty serialization; they are encoded directly + // in the type byte (using _valueNull, _valueTrue, _valueFalse) + // * Integers representable in 32 bits are encoded using 4 bytes two's + // complement representation. + // * Larger integers are encoded using 8 bytes two's complement + // representation. + // * doubles are encoded using the IEEE 754 64-bit double-precision binary + // format. Zero bytes are added before the encoded double value to align it + // to a 64 bit boundary in the full message. + // * Strings are encoded using their UTF-8 representation. First the length + // of that in bytes is encoded using the expanding format, then follows the + // UTF-8 encoding itself. + // * Uint8Lists, Int32Lists, Int64Lists, Float32Lists, and Float64Lists are + // encoded by first encoding the list's element count in the expanding + // format, then the smallest number of zero bytes needed to align the + // position in the full message with a multiple of the number of bytes per + // element, then the encoding of the list elements themselves, end-to-end + // with no additional type information, using two's complement or IEEE 754 + // as applicable. + // * Lists are encoded by first encoding their length in the expanding format, + // then follows the recursive encoding of each element value, including the + // type byte (Lists are assumed to be heterogeneous). + // * Maps are encoded by first encoding their length in the expanding format, + // then follows the recursive encoding of each key/value pair, including the + // type byte for both (Maps are assumed to be heterogeneous). + // + // The type labels below must not change, since it's possible for this interface + // to be used for persistent storage. + static const int _valueNull = 0; + static const int _valueTrue = 1; + static const int _valueFalse = 2; + static const int _valueInt32 = 3; + static const int _valueInt64 = 4; + static const int _valueLargeInt = 5; + static const int _valueFloat64 = 6; + static const int _valueString = 7; + static const int _valueUint8List = 8; + static const int _valueInt32List = 9; + static const int _valueInt64List = 10; + static const int _valueFloat64List = 11; + static const int _valueList = 12; + static const int _valueMap = 13; + static const int _valueFloat32List = 14; + + @override + ByteData? encodeMessage(Object? message) { + if (message == null) { + return null; + } + final WriteBuffer buffer = WriteBuffer(startCapacity: _writeBufferStartCapacity); + writeValue(buffer, message); + return buffer.done(); + } + + @override + dynamic decodeMessage(ByteData? message) { + if (message == null) { + return null; + } + final ReadBuffer buffer = ReadBuffer(message); + final Object? result = readValue(buffer); + if (buffer.hasRemaining) { + throw const FormatException('Message corrupted'); + } + return result; + } + + /// Writes [value] to [buffer] by first writing a type discriminator + /// byte, then the value itself. + /// + /// This method may be called recursively to serialize container values. + /// + /// Type discriminators 0 through 127 inclusive are reserved for use by the + /// base class, as follows: + /// + /// * null = 0 + /// * true = 1 + /// * false = 2 + /// * 32 bit integer = 3 + /// * 64 bit integer = 4 + /// * larger integers = 5 (see below) + /// * 64 bit floating-point number = 6 + /// * String = 7 + /// * Uint8List = 8 + /// * Int32List = 9 + /// * Int64List = 10 + /// * Float64List = 11 + /// * List = 12 + /// * Map = 13 + /// * Float32List = 14 + /// * Reserved for future expansion: 15..127 + /// + /// The codec can be extended by overriding this method, calling super + /// for values that the extension does not handle. Type discriminators + /// used by extensions must be greater than or equal to 128 in order to avoid + /// clashes with any later extensions to the base class. + /// + /// The "larger integers" type, 5, is never used by [writeValue]. A subclass + /// could represent big integers from another package using that type. The + /// format is first the type byte (0x05), then the actual number as an ASCII + /// string giving the hexadecimal representation of the integer, with the + /// string's length as encoded by [writeSize] followed by the string bytes. On + /// Android, that would get converted to a `java.math.BigInteger` object. On + /// iOS, the string representation is returned. + void writeValue(WriteBuffer buffer, Object? value) { + if (value == null) { + buffer.putUint8(_valueNull); + } else if (value is bool) { + buffer.putUint8(value ? _valueTrue : _valueFalse); + } else if (value is double) { // Double precedes int because in JS everything is a double. + // Therefore in JS, both `is int` and `is double` always + // return `true`. If we check int first, we'll end up treating + // all numbers as ints and attempt the int32/int64 conversion, + // which is wrong. This precedence rule is irrelevant when + // decoding because we use tags to detect the type of value. + buffer.putUint8(_valueFloat64); + buffer.putFloat64(value); + } else if (value is int) { // ignore: avoid_double_and_int_checks, JS code always goes through the `double` path above + if (-0x7fffffff - 1 <= value && value <= 0x7fffffff) { + buffer.putUint8(_valueInt32); + buffer.putInt32(value); + } else { + buffer.putUint8(_valueInt64); + buffer.putInt64(value); + } + } else if (value is String) { + buffer.putUint8(_valueString); + final Uint8List asciiBytes = Uint8List(value.length); + Uint8List? utf8Bytes; + int utf8Offset = 0; + // Only do utf8 encoding if we encounter non-ascii characters. + for (int i = 0; i < value.length; i += 1) { + final int char = value.codeUnitAt(i); + if (char <= 0x7f) { + asciiBytes[i] = char; + } else { + utf8Bytes = utf8.encode(value.substring(i)); + utf8Offset = i; + break; + } + } + if (utf8Bytes != null) { + writeSize(buffer, utf8Offset + utf8Bytes.length); + buffer.putUint8List(Uint8List.sublistView(asciiBytes, 0, utf8Offset)); + buffer.putUint8List(utf8Bytes); + } else { + writeSize(buffer, asciiBytes.length); + buffer.putUint8List(asciiBytes); + } + } else if (value is Uint8List) { + buffer.putUint8(_valueUint8List); + writeSize(buffer, value.length); + buffer.putUint8List(value); + } else if (value is Int32List) { + buffer.putUint8(_valueInt32List); + writeSize(buffer, value.length); + buffer.putInt32List(value); + } else if (value is Int64List) { + buffer.putUint8(_valueInt64List); + writeSize(buffer, value.length); + buffer.putInt64List(value); + } else if (value is Float32List) { + buffer.putUint8(_valueFloat32List); + writeSize(buffer, value.length); + buffer.putFloat32List(value); + } else if (value is Float64List) { + buffer.putUint8(_valueFloat64List); + writeSize(buffer, value.length); + buffer.putFloat64List(value); + } else if (value is List) { + buffer.putUint8(_valueList); + writeSize(buffer, value.length); + for (final Object? item in value) { + writeValue(buffer, item); + } + } else if (value is Map) { + buffer.putUint8(_valueMap); + writeSize(buffer, value.length); + value.forEach((Object? key, Object? value) { + writeValue(buffer, key); + writeValue(buffer, value); + }); + } else { + throw ArgumentError.value(value); + } + } + + /// Reads a value from [buffer] as written by [writeValue]. + /// + /// This method is intended for use by subclasses overriding + /// [readValueOfType]. + Object? readValue(ReadBuffer buffer) { + if (!buffer.hasRemaining) { + throw const FormatException('Message corrupted'); + } + final int type = buffer.getUint8(); + return readValueOfType(type, buffer); + } + + /// Reads a value of the indicated [type] from [buffer]. + /// + /// The codec can be extended by overriding this method, calling super for + /// types that the extension does not handle. See the discussion at + /// [writeValue]. + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case _valueNull: + return null; + case _valueTrue: + return true; + case _valueFalse: + return false; + case _valueInt32: + return buffer.getInt32(); + case _valueInt64: + return buffer.getInt64(); + case _valueFloat64: + return buffer.getFloat64(); + case _valueLargeInt: + case _valueString: + final int length = readSize(buffer); + return utf8.decoder.convert(buffer.getUint8List(length)); + case _valueUint8List: + final int length = readSize(buffer); + return buffer.getUint8List(length); + case _valueInt32List: + final int length = readSize(buffer); + return buffer.getInt32List(length); + case _valueInt64List: + final int length = readSize(buffer); + return buffer.getInt64List(length); + case _valueFloat32List: + final int length = readSize(buffer); + return buffer.getFloat32List(length); + case _valueFloat64List: + final int length = readSize(buffer); + return buffer.getFloat64List(length); + case _valueList: + final int length = readSize(buffer); + final List<Object?> result = List<Object?>.filled(length, null); + for (int i = 0; i < length; i++) { + result[i] = readValue(buffer); + } + return result; + case _valueMap: + final int length = readSize(buffer); + final Map<Object?, Object?> result = <Object?, Object?>{}; + for (int i = 0; i < length; i++) { + result[readValue(buffer)] = readValue(buffer); + } + return result; + default: throw const FormatException('Message corrupted'); + } + } + + /// Writes a non-negative 32-bit integer [value] to [buffer] + /// using an expanding 1-5 byte encoding that optimizes for small values. + /// + /// This method is intended for use by subclasses overriding + /// [writeValue]. + void writeSize(WriteBuffer buffer, int value) { + assert(0 <= value && value <= 0xffffffff); + if (value < 254) { + buffer.putUint8(value); + } else if (value <= 0xffff) { + buffer.putUint8(254); + buffer.putUint16(value); + } else { + buffer.putUint8(255); + buffer.putUint32(value); + } + } + + /// Reads a non-negative int from [buffer] as written by [writeSize]. + /// + /// This method is intended for use by subclasses overriding + /// [readValueOfType]. + int readSize(ReadBuffer buffer) { + final int value = buffer.getUint8(); + switch (value) { + case 254: + return buffer.getUint16(); + case 255: + return buffer.getUint32(); + default: + return value; + } + } +} + +/// [MethodCodec] using the Flutter standard binary encoding. +/// +/// The standard codec is guaranteed to be compatible with the corresponding +/// standard codec for FlutterMethodChannels on the host platform. These parts +/// of the Flutter SDK are evolved synchronously. +/// +/// Values supported as method arguments and result payloads are those supported +/// by [StandardMessageCodec]. +class StandardMethodCodec implements MethodCodec { + // The codec method calls, and result envelopes as outlined below. This format + // must match the Android and iOS counterparts. + // + // * Individual values are encoded using [StandardMessageCodec]. + // * Method calls are encoded using the concatenation of the encoding + // of the method name String and the arguments value. + // * Reply envelopes are encoded using first a single byte to distinguish the + // success case (0) from the error case (1). Then follows: + // * In the success case, the encoding of the result value. + // * In the error case, the concatenation of the encoding of the error code + // string, the error message string, and the error details value. + + /// Creates a [MethodCodec] using the Flutter standard binary encoding. + const StandardMethodCodec([this.messageCodec = const StandardMessageCodec()]); + + /// The message codec that this method codec uses for encoding values. + final StandardMessageCodec messageCodec; + + @override + ByteData encodeMethodCall(MethodCall methodCall) { + final WriteBuffer buffer = WriteBuffer(startCapacity: _writeBufferStartCapacity); + messageCodec.writeValue(buffer, methodCall.method); + messageCodec.writeValue(buffer, methodCall.arguments); + return buffer.done(); + } + + @override + MethodCall decodeMethodCall(ByteData? methodCall) { + final ReadBuffer buffer = ReadBuffer(methodCall!); + final Object? method = messageCodec.readValue(buffer); + final Object? arguments = messageCodec.readValue(buffer); + if (method is String && !buffer.hasRemaining) { + return MethodCall(method, arguments); + } else { + throw const FormatException('Invalid method call'); + } + } + + @override + ByteData encodeSuccessEnvelope(Object? result) { + final WriteBuffer buffer = WriteBuffer(startCapacity: _writeBufferStartCapacity); + buffer.putUint8(0); + messageCodec.writeValue(buffer, result); + return buffer.done(); + } + + @override + ByteData encodeErrorEnvelope({ required String code, String? message, Object? details}) { + final WriteBuffer buffer = WriteBuffer(startCapacity: _writeBufferStartCapacity); + buffer.putUint8(1); + messageCodec.writeValue(buffer, code); + messageCodec.writeValue(buffer, message); + messageCodec.writeValue(buffer, details); + return buffer.done(); + } + + @override + dynamic decodeEnvelope(ByteData envelope) { + // First byte is zero in success case, and non-zero otherwise. + if (envelope.lengthInBytes == 0) { + throw const FormatException('Expected envelope, got nothing'); + } + final ReadBuffer buffer = ReadBuffer(envelope); + if (buffer.getUint8() == 0) { + return messageCodec.readValue(buffer); + } + final Object? errorCode = messageCodec.readValue(buffer); + final Object? errorMessage = messageCodec.readValue(buffer); + final Object? errorDetails = messageCodec.readValue(buffer); + final String? errorStacktrace = (buffer.hasRemaining) ? messageCodec.readValue(buffer) as String? : null; + if (errorCode is String && (errorMessage == null || errorMessage is String) && !buffer.hasRemaining) { + throw PlatformException(code: errorCode, message: errorMessage as String?, details: errorDetails, stacktrace: errorStacktrace); + } else { + throw const FormatException('Invalid envelope'); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/mouse_cursor.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/mouse_cursor.dart new file mode 100644 index 0000000000000000000000000000000000000000..a9cd9e94231a731f62771681c0d8ac7338cd8efd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/mouse_cursor.dart @@ -0,0 +1,930 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; + +import 'system_channels.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticLevel, DiagnosticPropertiesBuilder; +export 'package:flutter/gestures.dart' show PointerEvent; + +/// Maintains the state of mouse cursors and manages how cursors are searched +/// for. +/// +/// This is typically created as a global singleton and owned by [MouseTracker]. +class MouseCursorManager { + /// Create a [MouseCursorManager] by specifying the fallback cursor. + /// + /// The `fallbackMouseCursor` must not be [MouseCursor.defer] (typically + /// [SystemMouseCursors.basic]). + MouseCursorManager(this.fallbackMouseCursor) + : assert(fallbackMouseCursor != MouseCursor.defer); + + /// The mouse cursor to use if all cursor candidates choose to defer. + /// + /// See also: + /// + /// * [MouseCursor.defer], the mouse cursor object to use to defer. + final MouseCursor fallbackMouseCursor; + + /// Returns the active mouse cursor of a device. + /// + /// The return value is the last [MouseCursor] activated onto this + /// device, even if the activation failed. + /// + /// Only valid when asserts are enabled. In release builds, always returns + /// null. + MouseCursor? debugDeviceActiveCursor(int device) { + MouseCursor? result; + assert(() { + result = _lastSession[device]?.cursor; + return true; + }()); + return result; + } + + final Map<int, MouseCursorSession> _lastSession = <int, MouseCursorSession>{}; + + /// Handles the changes that cause a pointer device to have a new list of mouse + /// cursor candidates. + /// + /// This change can be caused by a pointer event, in which case + /// `triggeringEvent` should not be null, or by other changes, such as when a + /// widget has moved under a still mouse, which is detected after the current + /// frame is complete. In either case, `cursorCandidates` should be the list of + /// cursors at the location of the mouse in hit-test order. + void handleDeviceCursorUpdate( + int device, + PointerEvent? triggeringEvent, + Iterable<MouseCursor> cursorCandidates, + ) { + if (triggeringEvent is PointerRemovedEvent) { + _lastSession.remove(device); + return; + } + + final MouseCursorSession? lastSession = _lastSession[device]; + final MouseCursor nextCursor = _DeferringMouseCursor.firstNonDeferred(cursorCandidates) + ?? fallbackMouseCursor; + assert(nextCursor is! _DeferringMouseCursor); + if (lastSession?.cursor == nextCursor) { + return; + } + + final MouseCursorSession nextSession = nextCursor.createSession(device); + _lastSession[device] = nextSession; + + lastSession?.dispose(); + nextSession.activate(); + } +} + +/// Manages the duration that a pointing device should display a specific mouse +/// cursor. +/// +/// While [MouseCursor] classes describe the kind of cursors, [MouseCursorSession] +/// classes represents a continuous use of the cursor on a pointing device. The +/// [MouseCursorSession] classes can be stateful. For example, a cursor that +/// needs to load resources might want to set a temporary cursor first, then +/// switch to the correct cursor after the load is completed. +/// +/// A [MouseCursorSession] has the following lifecycle: +/// +/// * When a pointing device should start displaying a cursor, [MouseTracker] +/// creates a session by calling [MouseCursor.createSession] on the target +/// cursor, and stores it in a table associated with the device. +/// * [MouseTracker] then immediately calls the session's [activate], where the +/// session should fetch resources and make system calls. +/// * When the pointing device should start displaying a different cursor, +/// [MouseTracker] calls [dispose] on this session. After [dispose], this session +/// will no longer be used in the future. +abstract class MouseCursorSession { + /// Create a session. + MouseCursorSession(this.cursor, this.device); + + /// The cursor that created this session. + final MouseCursor cursor; + + /// The device ID of the pointing device. + final int device; + + /// Override this method to do the work of changing the cursor of the device. + /// + /// Called right after this session is created. + /// + /// This method has full control over the cursor until the [dispose] call, and + /// can make system calls to change the pointer cursor as many times as + /// necessary (usually through [SystemChannels.mouseCursor]). It can also + /// collect resources, and store the result in this object. + @protected + Future<void> activate(); + + /// Called when device stops displaying the cursor. + /// + /// After this call, this session instance will no longer be used in the + /// future. + /// + /// When implementing this method in subclasses, you should release resources + /// and prevent [activate] from causing side effects after disposal. + @protected + void dispose(); +} + +/// An interface for mouse cursor definitions. +/// +/// A mouse cursor is a graphical image on the screen that echoes the movement +/// of a pointing device, such as a mouse or a stylus. A [MouseCursor] object +/// defines a kind of mouse cursor, such as an arrow, a pointing hand, or an +/// I-beam. +/// +/// During the painting phase, [MouseCursor] objects are assigned to regions on +/// the screen via annotations. Later during a device update (e.g. when a mouse +/// moves), [MouseTracker] finds the _active cursor_ of each mouse device, which +/// is the front-most region associated with the position of each mouse cursor, +/// or defaults to [SystemMouseCursors.basic] if no cursors are associated with +/// the position. [MouseTracker] changes the cursor of the pointer if the new +/// active cursor is different from the previous active cursor, whose effect is +/// defined by the session created by [createSession]. +/// +/// ## Cursor classes +/// +/// A [SystemMouseCursor] is a cursor that is natively supported by the +/// platform that the program is running on. All supported system mouse cursors +/// are enumerated in [SystemMouseCursors]. +/// +/// ## Using cursors +/// +/// A [MouseCursor] object is used by being assigned to a [MouseRegion] or +/// another widget that exposes the [MouseRegion] API, such as +/// [InkResponse.mouseCursor]. +/// +/// {@tool dartpad} +/// This sample creates a rectangular region that is wrapped by a [MouseRegion] +/// with a system mouse cursor. The mouse pointer becomes an I-beam when +/// hovering over the region. +/// +/// ** See code in examples/api/lib/services/mouse_cursor/mouse_cursor.0.dart ** +/// {@end-tool} +/// +/// Assigning regions with mouse cursors on platforms that do not support mouse +/// cursors, or when there are no mice connected, will have no effect. +/// +/// ## Related classes +/// +/// [MouseCursorSession] represents the duration when a pointing device displays +/// a cursor, and defines the states and behaviors of the cursor. Every mouse +/// cursor class usually has a corresponding [MouseCursorSession] class. +/// +/// [MouseCursorManager] is a class that adds the feature of changing +/// cursors to [MouseTracker], which tracks the relationship between mouse +/// devices and annotations. [MouseCursorManager] is usually used as a part +/// of [MouseTracker]. +@immutable +abstract class MouseCursor with Diagnosticable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const MouseCursor(); + + /// Associate a pointing device to this cursor. + /// + /// A mouse cursor class usually has a corresponding [MouseCursorSession] + /// class, and instantiates such class in this method. + /// + /// This method is called each time a pointing device starts displaying this + /// cursor. A given cursor can be displayed by multiple devices at the same + /// time, in which case this method will be called separately for each device. + @protected + @factory + MouseCursorSession createSession(int device); + + /// A very short description of the mouse cursor. + /// + /// The [debugDescription] should be a few words that can describe this cursor + /// to make debug information more readable. It is returned as the [toString] + /// when the diagnostic level is at or above [DiagnosticLevel.info]. + /// + /// The [debugDescription] must not be empty. + String get debugDescription; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + final String debugDescription = this.debugDescription; + if (minLevel.index >= DiagnosticLevel.info.index) { + return debugDescription; + } + return super.toString(minLevel: minLevel); + } + + /// A special class that indicates that the region with this cursor defers the + /// choice of cursor to the next region behind it. + /// + /// When an event occurs, [MouseTracker] will update each pointer's cursor by + /// finding the list of regions that contain the pointer's location, from front + /// to back in hit-test order. The pointer's cursor will be the first cursor in + /// the list that is not a [MouseCursor.defer]. + static const MouseCursor defer = _DeferringMouseCursor._(); + + /// A special value that doesn't change cursor by itself, but make a region + /// that blocks other regions behind it from changing the cursor. + /// + /// When a pointer enters a region with a cursor of [uncontrolled], the pointer + /// retains its previous cursor and keeps so until it moves out of the region. + /// Technically, this region absorb the mouse cursor hit test without changing + /// the pointer's cursor. + /// + /// This is useful in a region that displays a platform view, which let the + /// operating system handle pointer events and change cursors accordingly. To + /// achieve this, the region's cursor must not be any Flutter cursor, since + /// that might overwrite the system request upon pointer entering; the cursor + /// must not be null either, since that allows the widgets behind the region to + /// change cursors. + static const MouseCursor uncontrolled = _NoopMouseCursor._(); +} + +class _DeferringMouseCursor extends MouseCursor { + const _DeferringMouseCursor._(); + + @override + MouseCursorSession createSession(int device) { + assert(false, '_DeferringMouseCursor can not create a session'); + throw UnimplementedError(); + } + + @override + String get debugDescription => 'defer'; + + /// Returns the first cursor that is not a [MouseCursor.defer]. + static MouseCursor? firstNonDeferred(Iterable<MouseCursor> cursors) { + for (final MouseCursor cursor in cursors) { + if (cursor != MouseCursor.defer) { + return cursor; + } + } + return null; + } +} + +class _NoopMouseCursorSession extends MouseCursorSession { + _NoopMouseCursorSession(_NoopMouseCursor super.cursor, super.device); + + @override + Future<void> activate() async { /* Nothing */ } + + @override + void dispose() { /* Nothing */ } +} + +/// A mouse cursor that doesn't change the cursor when activated. +/// +/// Although setting a region's cursor to [NoopMouseCursor] doesn't change the +/// cursor, it blocks regions behind it from changing the cursor, in contrast to +/// setting the cursor to null. More information about the usage of this class +/// can be found at [MouseCursors.uncontrolled]. +/// +/// To use this class, use [MouseCursors.uncontrolled]. Directly +/// instantiating this class is not allowed. +class _NoopMouseCursor extends MouseCursor { + // Application code shouldn't directly instantiate this class, since its only + // instance is accessible at [SystemMouseCursors.releaseControl]. + const _NoopMouseCursor._(); + + @override + @protected + _NoopMouseCursorSession createSession(int device) => _NoopMouseCursorSession(this, device); + + @override + String get debugDescription => 'uncontrolled'; +} + +class _SystemMouseCursorSession extends MouseCursorSession { + _SystemMouseCursorSession(SystemMouseCursor super.cursor, super.device); + + @override + SystemMouseCursor get cursor => super.cursor as SystemMouseCursor; + + @override + Future<void> activate() { + return SystemChannels.mouseCursor.invokeMethod<void>( + 'activateSystemCursor', + <String, dynamic>{ + 'device': device, + 'kind': cursor.kind, + }, + ); + } + + @override + void dispose() { /* Nothing */ } +} + +/// A mouse cursor that is natively supported on the platform that the +/// application is running on. +/// +/// System cursors can be used without external resources, and their appearances +/// match the experience of native apps. Examples of system cursors are a +/// pointing arrow, a pointing hand, a double arrow for resizing, or a text +/// I-beam, etc. +/// +/// An instance of [SystemMouseCursor] refers to one cursor from each platform +/// that represents the same concept, such as being text, being clickable, +/// or being a forbidden operation. Since the set of system cursors supported by +/// each platform varies, multiple instances can correspond to the same system +/// cursor. +/// +/// Each cursor is noted with its corresponding native cursors on each platform: +/// +/// * Android: API name in Java +/// * Web: CSS cursor +/// * Windows: Win32 API +/// * Windows UWP: WinRT API, `winrt::Windows::UI::Core::CoreCursorType` +/// * Linux: GDK, `gdk_cursor_new_from_name` +/// * macOS: API name in Objective C +/// +/// If the platform that the application is running on is not listed for a cursor, +/// using this cursor falls back to [SystemMouseCursors.basic]. +/// +/// [SystemMouseCursors] enumerates the complete set of system cursors supported +/// by Flutter, which are hard-coded in the engine. Therefore, manually +/// instantiating this class is not supported. +class SystemMouseCursor extends MouseCursor { + // Application code shouldn't directly instantiate system mouse cursors, since + // the supported system cursors are enumerated in [SystemMouseCursors]. + const SystemMouseCursor._({ + required this.kind, + }); + + /// A string that identifies the kind of the cursor. + /// + /// The interpretation of [kind] is platform-dependent. + final String kind; + + @override + String get debugDescription => '${objectRuntimeType(this, 'SystemMouseCursor')}($kind)'; + + @override + @protected + MouseCursorSession createSession(int device) => _SystemMouseCursorSession(this, device); + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is SystemMouseCursor + && other.kind == kind; + } + + @override + int get hashCode => kind.hashCode; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('kind', kind, level: DiagnosticLevel.debug)); + } +} + +/// A collection of system [MouseCursor]s. +/// +/// System cursors are standard mouse cursors that are provided by the current +/// platform. They don't require external resources. +/// +/// [SystemMouseCursors] is a superset of the system cursors of every platform +/// that Flutter supports, therefore some of these objects might map to the same +/// result, or fallback to the [basic] arrow. This mapping is defined by the +/// Flutter engine. +/// +/// The cursors should be named based on the cursors' use cases instead of their +/// appearance, because different platforms might (although not commonly) use +/// different shapes for the same use case. +class SystemMouseCursors { + // This class only contains static members, and should not be instantiated or + // extended. + SystemMouseCursors._(); + + // The mapping in this class must be kept in sync with the following files in + // the engine: + // + // * Android: shell/platform/android/io/flutter/plugin/mouse/MouseCursorPlugin.java + // * Web: lib/web_ui/lib/src/engine/mouse_cursor.dart + // * Windows: shell/platform/windows/win32_flutter_window_win32.cc + // * Windows UWP: shell/platform/windows/win32_flutter_window_winuwp.cc + // * Linux: shell/platform/linux/fl_mouse_cursor_plugin.cc + // * macOS: shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.mm + + + /// Hide the cursor. + /// + /// Any cursor other than [none] or [MouseCursor.uncontrolled] unhides the + /// cursor. + static const SystemMouseCursor none = SystemMouseCursor._(kind: 'none'); + + + // STATUS + + /// The platform-dependent basic cursor. + /// + /// Typically the shape of an arrow. + /// + /// Corresponds to: + /// + /// * Android: TYPE_DEFAULT, TYPE_ARROW + /// * Web: default + /// * Windows: IDC_ARROW + /// * Windows UWP: CoreCursorType::Arrow + /// * Linux: default + /// * macOS: arrowCursor + static const SystemMouseCursor basic = SystemMouseCursor._(kind: 'basic'); + + /// A cursor that emphasizes an element being clickable, such as a hyperlink. + /// + /// Typically the shape of a pointing hand. + /// + /// Corresponds to: + /// + /// * Android: TYPE_HAND + /// * Web: pointer + /// * Windows: IDC_HAND + /// * Windows UWP: CoreCursorType::Hand + /// * Linux: pointer + /// * macOS: pointingHandCursor + static const SystemMouseCursor click = SystemMouseCursor._(kind: 'click'); + + /// A cursor indicating an operation that will not be carried out. + /// + /// Typically the shape of a circle with a diagonal line. May fall back to + /// [noDrop]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_NO_DROP + /// * Web: not-allowed + /// * Windows: IDC_NO + /// * Windows UWP: CoreCursorType::UniversalNo + /// * Linux: not-allowed + /// * macOS: operationNotAllowedCursor + /// + /// See also: + /// + /// * [noDrop], which indicates somewhere that the current item may not be + /// dropped. + static const SystemMouseCursor forbidden = SystemMouseCursor._(kind: 'forbidden'); + + /// A cursor indicating the status that the program is busy and therefore + /// can not be interacted with. + /// + /// Typically the shape of an hourglass or a watch. + /// + /// This cursor is not available as a system cursor on macOS. Although macOS + /// displays a "spinning ball" cursor when busy, it's handled by the OS and not + /// exposed for applications to choose. + /// + /// Corresponds to: + /// + /// * Android: TYPE_WAIT + /// * Windows: IDC_WAIT + /// * Web: wait + /// * Linux: wait + /// + /// See also: + /// + /// * [progress], which is similar to [wait] but the program can still be + /// interacted with. + static const SystemMouseCursor wait = SystemMouseCursor._(kind: 'wait'); + + /// A cursor indicating the status that the program is busy but can still be + /// interacted with. + /// + /// Typically the shape of an arrow with an hourglass or a watch at the corner. + /// Does *not* fall back to [wait] if unavailable. + /// + /// Corresponds to: + /// + /// * Web: progress + /// * Windows: IDC_APPSTARTING + /// * Linux: progress + /// + /// See also: + /// + /// * [wait], which is similar to [progress] but the program can not be + /// interacted with. + static const SystemMouseCursor progress = SystemMouseCursor._(kind: 'progress'); + + /// A cursor indicating somewhere the user can trigger a context menu. + /// + /// Typically the shape of an arrow with a small menu at the corner. + /// + /// Corresponds to: + /// + /// * Android: TYPE_CONTEXT_MENU + /// * Web: context-menu + /// * Linux: context-menu + /// * macOS: contextualMenuCursor + static const SystemMouseCursor contextMenu = SystemMouseCursor._(kind: 'contextMenu'); + + /// A cursor indicating help information. + /// + /// Typically the shape of a question mark, or an arrow therewith. + /// + /// Corresponds to: + /// + /// * Android: TYPE_HELP + /// * Windows: IDC_HELP + /// * Windows UWP: CoreCursorType::Help + /// * Web: help + /// * Linux: help + static const SystemMouseCursor help = SystemMouseCursor._(kind: 'help'); + + + // SELECTION + + /// A cursor indicating selectable text. + /// + /// Typically the shape of a capital I. + /// + /// Corresponds to: + /// + /// * Android: TYPE_TEXT + /// * Web: text + /// * Windows: IDC_IBEAM + /// * Windows UWP: CoreCursorType::IBeam + /// * Linux: text + /// * macOS: IBeamCursor + static const SystemMouseCursor text = SystemMouseCursor._(kind: 'text'); + + /// A cursor indicating selectable vertical text. + /// + /// Typically the shape of a capital I rotated to be horizontal. May fall back + /// to [text]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_VERTICAL_TEXT + /// * Web: vertical-text + /// * Linux: vertical-text + /// * macOS: IBeamCursorForVerticalLayout + static const SystemMouseCursor verticalText = SystemMouseCursor._(kind: 'verticalText'); + + /// A cursor indicating selectable table cells. + /// + /// Typically the shape of a hollow plus sign. + /// + /// Corresponds to: + /// + /// * Android: TYPE_CELL + /// * Web: cell + /// * Linux: cell + static const SystemMouseCursor cell = SystemMouseCursor._(kind: 'cell'); + + /// A cursor indicating precise selection, such as selecting a pixel in a + /// bitmap. + /// + /// Typically the shape of a crosshair. + /// + /// Corresponds to: + /// + /// * Android: TYPE_CROSSHAIR + /// * Web: crosshair + /// * Windows: IDC_CROSS + /// * Windows UWP: CoreCursorType::Cross + /// * Linux: crosshair + /// * macOS: crosshairCursor + static const SystemMouseCursor precise = SystemMouseCursor._(kind: 'precise'); + + + // DRAG-AND-DROP + + /// A cursor indicating moving something. + /// + /// Typically the shape of four-way arrow. May fall back to [allScroll]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_ALL_SCROLL + /// * Windows: IDC_SIZEALL + /// * Windows UWP: CoreCursorType::SizeAll + /// * Web: move + /// * Linux: move + static const SystemMouseCursor move = SystemMouseCursor._(kind: 'move'); + + /// A cursor indicating something that can be dragged. + /// + /// Typically the shape of an open hand. + /// + /// Corresponds to: + /// + /// * Android: TYPE_GRAB + /// * Web: grab + /// * Linux: grab + /// * macOS: openHandCursor + static const SystemMouseCursor grab = SystemMouseCursor._(kind: 'grab'); + + /// A cursor indicating something that is being dragged. + /// + /// Typically the shape of a closed hand. + /// + /// Corresponds to: + /// + /// * Android: TYPE_GRABBING + /// * Web: grabbing + /// * Linux: grabbing + /// * macOS: closedHandCursor + static const SystemMouseCursor grabbing = SystemMouseCursor._(kind: 'grabbing'); + + /// A cursor indicating somewhere that the current item may not be dropped. + /// + /// Typically the shape of a hand with a [forbidden] sign at the corner. May + /// fall back to [forbidden]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_NO_DROP + /// * Web: no-drop + /// * Windows: IDC_NO + /// * Windows UWP: CoreCursorType::UniversalNo + /// * Linux: no-drop + /// * macOS: operationNotAllowedCursor + /// + /// See also: + /// + /// * [forbidden], which indicates an action that will not be carried out. + static const SystemMouseCursor noDrop = SystemMouseCursor._(kind: 'noDrop'); + + /// A cursor indicating that the current operation will create an alias of, or + /// a shortcut of the item. + /// + /// Typically the shape of an arrow with a shortcut icon at the corner. + /// + /// Corresponds to: + /// + /// * Android: TYPE_ALIAS + /// * Web: alias + /// * Linux: alias + /// * macOS: dragLinkCursor + static const SystemMouseCursor alias = SystemMouseCursor._(kind: 'alias'); + + /// A cursor indicating that the current operation will copy the item. + /// + /// Typically the shape of an arrow with a boxed plus sign at the corner. + /// + /// Corresponds to: + /// + /// * Android: TYPE_COPY + /// * Web: copy + /// * Linux: copy + /// * macOS: dragCopyCursor + static const SystemMouseCursor copy = SystemMouseCursor._(kind: 'copy'); + + /// A cursor indicating that the current operation will result in the + /// disappearance of the item. + /// + /// Typically the shape of an arrow with a cloud of smoke at the corner. + /// + /// Corresponds to: + /// + /// * macOS: disappearingItemCursor + static const SystemMouseCursor disappearing = SystemMouseCursor._(kind: 'disappearing'); + + + // RESIZING AND SCROLLING + + /// A cursor indicating scrolling in any direction. + /// + /// Typically the shape of a dot surrounded by 4 arrows. + /// + /// Corresponds to: + /// + /// * Android: TYPE_ALL_SCROLL + /// * Windows: IDC_SIZEALL + /// * Windows UWP: CoreCursorType::SizeAll + /// * Web: all-scroll + /// * Linux: all-scroll + /// + /// See also: + /// + /// * [move], which indicates moving in any direction. + static const SystemMouseCursor allScroll = SystemMouseCursor._(kind: 'allScroll'); + + /// A cursor indicating resizing an object bidirectionally from its left or + /// right edge. + /// + /// Typically the shape of a bidirectional arrow pointing left and right. + /// + /// Corresponds to: + /// + /// * Android: TYPE_HORIZONTAL_DOUBLE_ARROW + /// * Web: ew-resize + /// * Windows: IDC_SIZEWE + /// * Windows UWP: CoreCursorType::SizeWestEast + /// * Linux: ew-resize + /// * macOS: resizeLeftRightCursor + static const SystemMouseCursor resizeLeftRight = SystemMouseCursor._(kind: 'resizeLeftRight'); + + /// A cursor indicating resizing an object bidirectionally from its top or + /// bottom edge. + /// + /// Typically the shape of a bidirectional arrow pointing up and down. + /// + /// Corresponds to: + /// + /// * Android: TYPE_VERTICAL_DOUBLE_ARROW + /// * Web: ns-resize + /// * Windows: IDC_SIZENS + /// * Windows UWP: CoreCursorType::SizeNorthSouth + /// * Linux: ns-resize + /// * macOS: resizeUpDownCursor + static const SystemMouseCursor resizeUpDown = SystemMouseCursor._(kind: 'resizeUpDown'); + + /// A cursor indicating resizing an object bidirectionally from its top left or + /// bottom right corner. + /// + /// Typically the shape of a bidirectional arrow pointing upper left and lower right. + /// + /// Corresponds to: + /// + /// * Android: TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW + /// * Web: nwse-resize + /// * Windows: IDC_SIZENWSE + /// * Windows UWP: CoreCursorType::SizeNorthwestSoutheast + /// * Linux: nwse-resize + static const SystemMouseCursor resizeUpLeftDownRight = SystemMouseCursor._(kind: 'resizeUpLeftDownRight'); + + /// A cursor indicating resizing an object bidirectionally from its top right or + /// bottom left corner. + /// + /// Typically the shape of a bidirectional arrow pointing upper right and lower left. + /// + /// Corresponds to: + /// + /// * Android: TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW + /// * Windows: IDC_SIZENESW + /// * Windows UWP: CoreCursorType::SizeNortheastSouthwest + /// * Web: nesw-resize + /// * Linux: nesw-resize + static const SystemMouseCursor resizeUpRightDownLeft = SystemMouseCursor._(kind: 'resizeUpRightDownLeft'); + + /// A cursor indicating resizing an object from its top edge. + /// + /// Typically the shape of an arrow pointing up. May fallback to [resizeUpDown]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_VERTICAL_DOUBLE_ARROW + /// * Web: n-resize + /// * Windows: IDC_SIZENS + /// * Windows UWP: CoreCursorType::SizeNorthSouth + /// * Linux: n-resize + /// * macOS: resizeUpCursor + static const SystemMouseCursor resizeUp = SystemMouseCursor._(kind: 'resizeUp'); + + /// A cursor indicating resizing an object from its bottom edge. + /// + /// Typically the shape of an arrow pointing down. May fallback to [resizeUpDown]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_VERTICAL_DOUBLE_ARROW + /// * Web: s-resize + /// * Windows: IDC_SIZENS + /// * Windows UWP: CoreCursorType::SizeNorthSouth + /// * Linux: s-resize + /// * macOS: resizeDownCursor + static const SystemMouseCursor resizeDown = SystemMouseCursor._(kind: 'resizeDown'); + + /// A cursor indicating resizing an object from its left edge. + /// + /// Typically the shape of an arrow pointing left. May fallback to [resizeLeftRight]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_HORIZONTAL_DOUBLE_ARROW + /// * Web: w-resize + /// * Windows: IDC_SIZEWE + /// * Windows UWP: CoreCursorType::SizeWestEast + /// * Linux: w-resize + /// * macOS: resizeLeftCursor + static const SystemMouseCursor resizeLeft = SystemMouseCursor._(kind: 'resizeLeft'); + + /// A cursor indicating resizing an object from its right edge. + /// + /// Typically the shape of an arrow pointing right. May fallback to [resizeLeftRight]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_HORIZONTAL_DOUBLE_ARROW + /// * Web: e-resize + /// * Windows: IDC_SIZEWE + /// * Windows UWP: CoreCursorType::SizeWestEast + /// * Linux: e-resize + /// * macOS: resizeRightCursor + static const SystemMouseCursor resizeRight = SystemMouseCursor._(kind: 'resizeRight'); + + /// A cursor indicating resizing an object from its top-left corner. + /// + /// Typically the shape of an arrow pointing upper left. May fallback to [resizeUpLeftDownRight]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW + /// * Web: nw-resize + /// * Windows: IDC_SIZENWSE + /// * Windows UWP: CoreCursorType::SizeNorthwestSoutheast + /// * Linux: nw-resize + static const SystemMouseCursor resizeUpLeft = SystemMouseCursor._(kind: 'resizeUpLeft'); + + /// A cursor indicating resizing an object from its top-right corner. + /// + /// Typically the shape of an arrow pointing upper right. May fallback to [resizeUpRightDownLeft]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW + /// * Web: ne-resize + /// * Windows: IDC_SIZENESW + /// * Windows UWP: CoreCursorType::SizeNortheastSouthwest + /// * Linux: ne-resize + static const SystemMouseCursor resizeUpRight = SystemMouseCursor._(kind: 'resizeUpRight'); + + /// A cursor indicating resizing an object from its bottom-left corner. + /// + /// Typically the shape of an arrow pointing lower left. May fallback to [resizeUpRightDownLeft]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW + /// * Web: sw-resize + /// * Windows: IDC_SIZENESW + /// * Windows UWP: CoreCursorType::SizeNortheastSouthwest + /// * Linux: sw-resize + static const SystemMouseCursor resizeDownLeft = SystemMouseCursor._(kind: 'resizeDownLeft'); + + /// A cursor indicating resizing an object from its bottom-right corner. + /// + /// Typically the shape of an arrow pointing lower right. May fallback to [resizeUpLeftDownRight]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW + /// * Web: se-resize + /// * Windows: IDC_SIZENWSE + /// * Windows UWP: CoreCursorType::SizeNorthwestSoutheast + /// * Linux: se-resize + static const SystemMouseCursor resizeDownRight = SystemMouseCursor._(kind: 'resizeDownRight'); + + /// A cursor indicating resizing a column, or an item horizontally. + /// + /// Typically the shape of arrows pointing left and right with a vertical bar + /// separating them. May fallback to [resizeLeftRight]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_HORIZONTAL_DOUBLE_ARROW + /// * Web: col-resize + /// * Windows: IDC_SIZEWE + /// * Windows UWP: CoreCursorType::SizeWestEast + /// * Linux: col-resize + /// * macOS: resizeLeftRightCursor + static const SystemMouseCursor resizeColumn = SystemMouseCursor._(kind: 'resizeColumn'); + + /// A cursor indicating resizing a row, or an item vertically. + /// + /// Typically the shape of arrows pointing up and down with a horizontal bar + /// separating them. May fallback to [resizeUpDown]. + /// + /// Corresponds to: + /// + /// * Android: TYPE_VERTICAL_DOUBLE_ARROW + /// * Web: row-resize + /// * Windows: IDC_SIZENS + /// * Windows UWP: CoreCursorType::SizeNorthSouth + /// * Linux: row-resize + /// * macOS: resizeUpDownCursor + static const SystemMouseCursor resizeRow = SystemMouseCursor._(kind: 'resizeRow'); + + + // OTHER OPERATIONS + + /// A cursor indicating zooming in. + /// + /// Typically a magnifying glass with a plus sign. + /// + /// Corresponds to: + /// + /// * Android: TYPE_ZOOM_IN + /// * Web: zoom-in + /// * Linux: zoom-in + static const SystemMouseCursor zoomIn = SystemMouseCursor._(kind: 'zoomIn'); + + /// A cursor indicating zooming out. + /// + /// Typically a magnifying glass with a minus sign. + /// + /// Corresponds to: + /// + /// * Android: TYPE_ZOOM_OUT + /// * Web: zoom-out + /// * Linux: zoom-out + static const SystemMouseCursor zoomOut = SystemMouseCursor._(kind: 'zoomOut'); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/mouse_tracking.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/mouse_tracking.dart new file mode 100644 index 0000000000000000000000000000000000000000..a6a066e48286cd070e7337d37c1ba8c5f75f568d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/mouse_tracking.dart @@ -0,0 +1,122 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; + +import 'mouse_cursor.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; +export 'package:flutter/gestures.dart' show PointerEnterEvent, PointerExitEvent, PointerHoverEvent; + +export 'mouse_cursor.dart' show MouseCursor; + +/// Signature for listening to [PointerEnterEvent] events. +/// +/// Used by [MouseTrackerAnnotation], [MouseRegion] and [RenderMouseRegion]. +typedef PointerEnterEventListener = void Function(PointerEnterEvent event); + +/// Signature for listening to [PointerExitEvent] events. +/// +/// Used by [MouseTrackerAnnotation], [MouseRegion] and [RenderMouseRegion]. +typedef PointerExitEventListener = void Function(PointerExitEvent event); + +/// Signature for listening to [PointerHoverEvent] events. +/// +/// Used by [MouseTrackerAnnotation], [MouseRegion] and [RenderMouseRegion]. +typedef PointerHoverEventListener = void Function(PointerHoverEvent event); + +/// The annotation object used to annotate regions that are interested in mouse +/// movements. +/// +/// To use an annotation, return this object as a [HitTestEntry] in a hit test. +/// Typically this is implemented by making a [RenderBox] implement this class +/// (see [RenderMouseRegion]). +/// +/// [MouseTracker] uses this class as a label to filter the hit test results. Hit +/// test entries that are also [MouseTrackerAnnotation]s are considered as valid +/// targets in terms of computing mouse related effects, such as enter events, +/// exit events, and mouse cursor events. +/// +/// See also: +/// +/// * [MouseTracker], which uses [MouseTrackerAnnotation]. +class MouseTrackerAnnotation with Diagnosticable { + /// Creates an immutable [MouseTrackerAnnotation]. + const MouseTrackerAnnotation({ + this.onEnter, + this.onExit, + this.cursor = MouseCursor.defer, + this.validForMouseTracker = true, + }); + + /// Triggered when a mouse pointer, with or without buttons pressed, has + /// entered the region and [validForMouseTracker] is true. + /// + /// This callback is triggered when the pointer has started to be contained by + /// the region, either due to a pointer event, or due to the movement or + /// disappearance of the region. This method is always matched by a later + /// [onExit]. + /// + /// See also: + /// + /// * [onExit], which is triggered when a mouse pointer exits the region. + /// * [MouseRegion.onEnter], which uses this callback. + final PointerEnterEventListener? onEnter; + + /// Triggered when a mouse pointer, with or without buttons pressed, has + /// exited the region and [validForMouseTracker] is true. + /// + /// This callback is triggered when the pointer has stopped being contained + /// by the region, either due to a pointer event, or due to the movement or + /// disappearance of the region. This method always matches an earlier + /// [onEnter]. + /// + /// See also: + /// + /// * [onEnter], which is triggered when a mouse pointer enters the region. + /// * [MouseRegion.onExit], which uses this callback, but is not triggered in + /// certain cases and does not always match its earlier [MouseRegion.onEnter]. + final PointerExitEventListener? onExit; + + /// The mouse cursor for mouse pointers that are hovering over the region. + /// + /// When a mouse enters the region, its cursor will be changed to the [cursor]. + /// When the mouse leaves the region, the cursor will be set by the region + /// found at the new location. + /// + /// Defaults to [MouseCursor.defer], deferring the choice of cursor to the next + /// region behind it in hit-test order. + /// + /// See also: + /// + /// * [MouseRegion.cursor], which provide values to this field. + final MouseCursor cursor; + + /// Whether this is included when [MouseTracker] collects the list of + /// annotations. + /// + /// If [validForMouseTracker] is false, this object is excluded from the + /// current annotation list even if it's included in the hit test, affecting + /// mouse-related behavior such as enter events, exit events, and mouse + /// cursors. The [validForMouseTracker] does not affect hit testing. + /// + /// The [validForMouseTracker] is true for [MouseTrackerAnnotation]s built by + /// the constructor. + final bool validForMouseTracker; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagsSummary<Function?>( + 'callbacks', + <String, Function?> { + 'enter': onEnter, + 'exit': onExit, + }, + ifEmpty: '<none>', + )); + properties.add(DiagnosticsProperty<MouseCursor>('cursor', cursor, defaultValue: MouseCursor.defer)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/platform_channel.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/platform_channel.dart new file mode 100644 index 0000000000000000000000000000000000000000..ce7e89ad315ce0ed77d987e565803c5b63deb5a4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/platform_channel.dart @@ -0,0 +1,700 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:developer'; + +import 'package:flutter/foundation.dart'; + +import '_background_isolate_binary_messenger_io.dart' + if (dart.library.js_util) '_background_isolate_binary_messenger_web.dart'; + +import 'binary_messenger.dart'; +import 'binding.dart'; +import 'debug.dart'; +import 'message_codec.dart'; +import 'message_codecs.dart'; + +export '_background_isolate_binary_messenger_io.dart' + if (dart.library.js_util) '_background_isolate_binary_messenger_web.dart'; + +export 'binary_messenger.dart' show BinaryMessenger; +export 'binding.dart' show RootIsolateToken; +export 'message_codec.dart' show MessageCodec, MethodCall, MethodCodec; + +/// Profile and print statistics on Platform Channel usage. +/// +/// When this is true statistics about the usage of Platform Channels will be +/// printed out periodically to the console and Timeline events will show the +/// time between sending and receiving a message (encoding and decoding time +/// excluded). +/// +/// The statistics include the total bytes transmitted and the average number of +/// bytes per invocation in the last quantum. "Up" means in the direction of +/// Flutter to the host platform, "down" is the host platform to flutter. +bool get shouldProfilePlatformChannels => kProfilePlatformChannels || (!kReleaseMode && debugProfilePlatformChannels); + +/// Controls whether platform channel usage can be debugged in release mode. +/// +/// See also: +/// +/// * [shouldProfilePlatformChannels], which checks both +/// [kProfilePlatformChannels] and [debugProfilePlatformChannels] for the +/// current run mode. +/// * [debugProfilePlatformChannels], which determines whether platform +/// channel usage can be debugged in non-release mode. +const bool kProfilePlatformChannels = false; + +bool _profilePlatformChannelsIsRunning = false; +const Duration _profilePlatformChannelsRate = Duration(seconds: 1); +final Expando<BinaryMessenger> _profiledBinaryMessengers = Expando<BinaryMessenger>(); + +class _ProfiledBinaryMessenger implements BinaryMessenger { + const _ProfiledBinaryMessenger(this.proxy, this.channelTypeName, this.codecTypeName); + final BinaryMessenger proxy; + final String channelTypeName; + final String codecTypeName; + + @override + Future<void> handlePlatformMessage(String channel, ByteData? data, PlatformMessageResponseCallback? callback) { + return proxy.handlePlatformMessage(channel, data, callback); + } + + Future<ByteData?>? sendWithPostfix(String channel, String postfix, ByteData? message) async { + _debugRecordUpStream(channelTypeName, '$channel$postfix', codecTypeName, message); + final TimelineTask timelineTask = TimelineTask()..start('Platform Channel send $channel$postfix'); + final ByteData? result; + try { + result = await proxy.send(channel, message); + } finally { + timelineTask.finish(); + } + _debugRecordDownStream(channelTypeName, '$channel$postfix', codecTypeName, result); + return result; + } + + @override + Future<ByteData?>? send(String channel, ByteData? message) => + sendWithPostfix(channel, '', message); + + @override + void setMessageHandler(String channel, MessageHandler? handler) { + proxy.setMessageHandler(channel, handler); + } +} + +class _PlatformChannelStats { + _PlatformChannelStats(this.channel, this.codec, this.type); + + final String channel; + final String codec; + final String type; + + int _upCount = 0; + int _upBytes = 0; + int get upBytes => _upBytes; + void addUpStream(int bytes) { + _upCount += 1; + _upBytes += bytes; + } + + int _downCount = 0; + int _downBytes = 0; + int get downBytes => _downBytes; + void addDownStream(int bytes) { + _downCount += 1; + _downBytes += bytes; + } + + double get averageUpPayload => _upBytes / _upCount; + double get averageDownPayload => _downBytes / _downCount; +} + +final Map<String, _PlatformChannelStats> _profilePlatformChannelsStats = <String, _PlatformChannelStats>{}; + +Future<void> _debugLaunchProfilePlatformChannels() async { + if (!_profilePlatformChannelsIsRunning) { + _profilePlatformChannelsIsRunning = true; + await Future<dynamic>.delayed(_profilePlatformChannelsRate); + _profilePlatformChannelsIsRunning = false; + final StringBuffer log = StringBuffer(); + log.writeln('Platform Channel Stats:'); + final List<_PlatformChannelStats> allStats = + _profilePlatformChannelsStats.values.toList(); + // Sort highest combined bandwidth first. + allStats.sort((_PlatformChannelStats x, _PlatformChannelStats y) => + (y.upBytes + y.downBytes) - (x.upBytes + x.downBytes)); + for (final _PlatformChannelStats stats in allStats) { + log.writeln( + ' (name:"${stats.channel}" type:"${stats.type}" codec:"${stats.codec}" upBytes:${stats.upBytes} upBytes_avg:${stats.averageUpPayload.toStringAsFixed(1)} downBytes:${stats.downBytes} downBytes_avg:${stats.averageDownPayload.toStringAsFixed(1)})'); + } + debugPrint(log.toString()); + _profilePlatformChannelsStats.clear(); + } +} + +void _debugRecordUpStream(String channelTypeName, String name, + String codecTypeName, ByteData? bytes) { + final _PlatformChannelStats stats = + _profilePlatformChannelsStats[name] ??= + _PlatformChannelStats(name, codecTypeName, channelTypeName); + stats.addUpStream(bytes?.lengthInBytes ?? 0); + _debugLaunchProfilePlatformChannels(); +} + +void _debugRecordDownStream(String channelTypeName, String name, + String codecTypeName, ByteData? bytes) { + final _PlatformChannelStats stats = + _profilePlatformChannelsStats[name] ??= + _PlatformChannelStats(name, codecTypeName, channelTypeName); + stats.addDownStream(bytes?.lengthInBytes ?? 0); + _debugLaunchProfilePlatformChannels(); +} + +BinaryMessenger _findBinaryMessenger() { + return !kIsWeb && ServicesBinding.rootIsolateToken == null + ? BackgroundIsolateBinaryMessenger.instance + : ServicesBinding.instance.defaultBinaryMessenger; +} + +/// A named channel for communicating with platform plugins using asynchronous +/// message passing. +/// +/// Messages are encoded into binary before being sent, and binary messages +/// received are decoded into Dart values. The [MessageCodec] used must be +/// compatible with the one used by the platform plugin. This can be achieved +/// by creating a basic message channel counterpart of this channel on the +/// platform side. The Dart type of messages sent and received is [T], +/// but only the values supported by the specified [MessageCodec] can be used. +/// The use of unsupported values should be considered programming errors, and +/// will result in exceptions being thrown. The null message is supported +/// for all codecs. +/// +/// The logical identity of the channel is given by its name. Identically named +/// channels will interfere with each other's communication. +/// +/// All [BasicMessageChannel]s provided by the Flutter framework guarantee FIFO +/// ordering. Applications can assume messages sent via a built-in +/// [BasicMessageChannel] are delivered in the same order as they're sent. +/// +/// See: <https://flutter.dev/platform-channels/> +class BasicMessageChannel<T> { + /// Creates a [BasicMessageChannel] with the specified [name], [codec] and + /// [binaryMessenger]. + /// + /// The default [ServicesBinding.defaultBinaryMessenger] instance is used if + /// [binaryMessenger] is null. + const BasicMessageChannel(this.name, this.codec, { BinaryMessenger? binaryMessenger }) + : _binaryMessenger = binaryMessenger; + + /// The logical channel on which communication happens, not null. + final String name; + + /// The message codec used by this channel, not null. + final MessageCodec<T> codec; + + /// The messenger which sends the bytes for this channel. + /// + /// On the root isolate or web, this defaults to the + /// [ServicesBinding.defaultBinaryMessenger]. In other contexts the default + /// value is a [BackgroundIsolateBinaryMessenger] from + /// [BackgroundIsolateBinaryMessenger.ensureInitialized]. + BinaryMessenger get binaryMessenger { + final BinaryMessenger result = _binaryMessenger ?? _findBinaryMessenger(); + return shouldProfilePlatformChannels + ? _profiledBinaryMessengers[this] ??= _ProfiledBinaryMessenger( + // ignore: no_runtimetype_tostring + result, runtimeType.toString(), codec.runtimeType.toString()) + : result; + } + final BinaryMessenger? _binaryMessenger; + + /// Sends the specified [message] to the platform plugins on this channel. + /// + /// Returns a [Future] which completes to the received response, which may + /// be null. + Future<T?> send(T message) async { + return codec.decodeMessage(await binaryMessenger.send(name, codec.encodeMessage(message))); + } + + /// Sets a callback for receiving messages from the platform plugins on this + /// channel. Messages may be null. + /// + /// The given callback will replace the currently registered callback for this + /// channel, if any. To remove the handler, pass null as the `handler` + /// argument. + /// + /// The handler's return value is sent back to the platform plugins as a + /// message reply. It may be null. + void setMessageHandler(Future<T> Function(T? message)? handler) { + if (handler == null) { + binaryMessenger.setMessageHandler(name, null); + } else { + binaryMessenger.setMessageHandler(name, (ByteData? message) async { + return codec.encodeMessage(await handler(codec.decodeMessage(message))); + }); + } + } + + // Looking for setMockMessageHandler? + // See this shim package: packages/flutter_test/lib/src/deprecated.dart +} + +/// A named channel for communicating with platform plugins using asynchronous +/// method calls. +/// +/// Method calls are encoded into binary before being sent, and binary results +/// received are decoded into Dart values. The [MethodCodec] used must be +/// compatible with the one used by the platform plugin. This can be achieved +/// by creating a method channel counterpart of this channel on the +/// platform side. The Dart type of arguments and results is `dynamic`, +/// but only values supported by the specified [MethodCodec] can be used. +/// The use of unsupported values should be considered programming errors, and +/// will result in exceptions being thrown. The null value is supported +/// for all codecs. +/// +/// The logical identity of the channel is given by its name. Identically named +/// channels will interfere with each other's communication. +/// +/// {@template flutter.services.method_channel.FIFO} +/// All [MethodChannel]s provided by the Flutter framework guarantee FIFO +/// ordering. Applications can assume method calls sent via a built-in +/// [MethodChannel] are received by the platform plugins in the same order as +/// they're sent. +/// {@endtemplate} +/// +/// See: <https://flutter.dev/platform-channels/> +@pragma('vm:keep-name') +class MethodChannel { + /// Creates a [MethodChannel] with the specified [name]. + /// + /// The [codec] used will be [StandardMethodCodec], unless otherwise + /// specified. + /// + /// The default [ServicesBinding.defaultBinaryMessenger] instance is used if + /// [binaryMessenger] is null. + const MethodChannel(this.name, [this.codec = const StandardMethodCodec(), BinaryMessenger? binaryMessenger ]) + : _binaryMessenger = binaryMessenger; + + /// The logical channel on which communication happens, not null. + final String name; + + /// The message codec used by this channel, not null. + final MethodCodec codec; + + /// The messenger which sends the bytes for this channel. + /// + /// On the root isolate or web, this defaults to the + /// [ServicesBinding.defaultBinaryMessenger]. In other contexts the default + /// value is a [BackgroundIsolateBinaryMessenger] from + /// [BackgroundIsolateBinaryMessenger.ensureInitialized]. + BinaryMessenger get binaryMessenger { + final BinaryMessenger result = _binaryMessenger ?? _findBinaryMessenger(); + return shouldProfilePlatformChannels + ? _profiledBinaryMessengers[this] ??= _ProfiledBinaryMessenger( + // ignore: no_runtimetype_tostring + result, runtimeType.toString(), codec.runtimeType.toString()) + : result; + } + final BinaryMessenger? _binaryMessenger; + + /// Backend implementation of [invokeMethod]. + /// + /// The `method` and `arguments` arguments are used to create a [MethodCall] + /// object that is passed to the [codec]'s [MethodCodec.encodeMethodCall] + /// method. The resulting message is then sent to the embedding using the + /// [binaryMessenger]'s [BinaryMessenger.send] method. + /// + /// If the result is null and `missingOk` is true, this returns null. (This is + /// the behavior of [OptionalMethodChannel.invokeMethod].) + /// + /// If the result is null and `missingOk` is false, this throws a + /// [MissingPluginException]. (This is the behavior of + /// [MethodChannel.invokeMethod].) + /// + /// Otherwise, the result is decoded using the [codec]'s + /// [MethodCodec.decodeEnvelope] method. + /// + /// The `T` type argument is the expected return type. It is treated as + /// nullable. + @optionalTypeArgs + Future<T?> _invokeMethod<T>(String method, { required bool missingOk, dynamic arguments }) async { + final ByteData input = codec.encodeMethodCall(MethodCall(method, arguments)); + final ByteData? result = + shouldProfilePlatformChannels ? + await (binaryMessenger as _ProfiledBinaryMessenger).sendWithPostfix(name, '#$method', input) : + await binaryMessenger.send(name, input); + if (result == null) { + if (missingOk) { + return null; + } + throw MissingPluginException('No implementation found for method $method on channel $name'); + } + return codec.decodeEnvelope(result) as T?; + } + + /// Invokes a [method] on this channel with the specified [arguments]. + /// + /// The static type of [arguments] is `dynamic`, but only values supported by + /// the [codec] of this channel can be used. The same applies to the returned + /// result. The values supported by the default codec and their platform-specific + /// counterparts are documented with [StandardMessageCodec]. + /// + /// The generic argument `T` of the method can be inferred by the surrounding + /// context, or provided explicitly. If it does not match the returned type of + /// the channel, a [TypeError] will be thrown at runtime. `T` cannot be a class + /// with generics other than `dynamic`. For example, `Map<String, String>` + /// is not supported but `Map<dynamic, dynamic>` or `Map` is. + /// + /// Returns a [Future] which completes to one of the following: + /// + /// * a result (possibly null), on successful invocation; + /// * a [PlatformException], if the invocation failed in the platform plugin; + /// * a [MissingPluginException], if the method has not been implemented by a + /// platform plugin. + /// + /// The following code snippets demonstrate how to invoke platform methods + /// in Dart using a MethodChannel and how to implement those methods in Java + /// (for Android) and Objective-C (for iOS). + /// + /// {@tool snippet} + /// + /// The code might be packaged up as a musical plugin, see + /// <https://flutter.dev/developing-packages/>: + /// + /// ```dart + /// abstract final class Music { + /// static const MethodChannel _channel = MethodChannel('music'); + /// + /// static Future<bool> isLicensed() async { + /// // invokeMethod returns a Future<T?>, so we handle the case where + /// // the return value is null by treating null as false. + /// return _channel.invokeMethod<bool>('isLicensed').then<bool>((bool? value) => value ?? false); + /// } + /// + /// static Future<List<Song>> songs() async { + /// // invokeMethod here returns a Future<dynamic> that completes to a + /// // List<dynamic> with Map<dynamic, dynamic> entries. Post-processing + /// // code thus cannot assume e.g. List<Map<String, String>> even though + /// // the actual values involved would support such a typed container. + /// // The correct type cannot be inferred with any value of `T`. + /// final List<dynamic>? songs = await _channel.invokeMethod<List<dynamic>>('getSongs'); + /// return songs?.cast<Map<String, Object?>>().map<Song>(Song.fromJson).toList() ?? <Song>[]; + /// } + /// + /// static Future<void> play(Song song, double volume) async { + /// // Errors occurring on the platform side cause invokeMethod to throw + /// // PlatformExceptions. + /// try { + /// return _channel.invokeMethod('play', <String, dynamic>{ + /// 'song': song.id, + /// 'volume': volume, + /// }); + /// } on PlatformException catch (e) { + /// throw ArgumentError('Unable to play ${song.title}: ${e.message}'); + /// } + /// } + /// } + /// + /// class Song { + /// Song(this.id, this.title, this.artist); + /// + /// final String id; + /// final String title; + /// final String artist; + /// + /// static Song fromJson(Map<String, Object?> json) { + /// return Song(json['id']! as String, json['title']! as String, json['artist']! as String); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// {@tool snippet} + /// + /// Java (for Android): + /// + /// ```java + /// // Assumes existence of an Android MusicApi. + /// public class MusicPlugin implements MethodCallHandler { + /// @Override + /// public void onMethodCall(MethodCall call, Result result) { + /// switch (call.method) { + /// case "isLicensed": + /// result.success(MusicApi.checkLicense()); + /// break; + /// case "getSongs": + /// final List<MusicApi.Track> tracks = MusicApi.getTracks(); + /// final List<Object> json = ArrayList<>(tracks.size()); + /// for (MusicApi.Track track : tracks) { + /// json.add(track.toJson()); // Map<String, Object> entries + /// } + /// result.success(json); + /// break; + /// case "play": + /// final String song = call.argument("song"); + /// final double volume = call.argument("volume"); + /// try { + /// MusicApi.playSongAtVolume(song, volume); + /// result.success(null); + /// } catch (MusicalException e) { + /// result.error("playError", e.getMessage(), null); + /// } + /// break; + /// default: + /// result.notImplemented(); + /// } + /// } + /// // Other methods elided. + /// } + /// ``` + /// {@end-tool} + /// + /// {@tool snippet} + /// + /// Objective-C (for iOS): + /// + /// ```objectivec + /// @interface MusicPlugin : NSObject<FlutterPlugin> + /// @end + /// + /// // Assumes existence of an iOS Broadway Play Api. + /// @implementation MusicPlugin + /// - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { + /// if ([@"isLicensed" isEqualToString:call.method]) { + /// result([NSNumber numberWithBool:[BWPlayApi isLicensed]]); + /// } else if ([@"getSongs" isEqualToString:call.method]) { + /// NSArray* items = [BWPlayApi items]; + /// NSMutableArray* json = [NSMutableArray arrayWithCapacity:items.count]; + /// for (final BWPlayItem* item in items) { + /// [json addObject:@{ @"id":item.itemId, @"title":item.name, @"artist":item.artist }]; + /// } + /// result(json); + /// } else if ([@"play" isEqualToString:call.method]) { + /// NSString* itemId = call.arguments[@"song"]; + /// NSNumber* volume = call.arguments[@"volume"]; + /// NSError* error = nil; + /// BOOL success = [BWPlayApi playItem:itemId volume:volume.doubleValue error:&error]; + /// if (success) { + /// result(nil); + /// } else { + /// result([FlutterError errorWithCode:[NSString stringWithFormat:@"Error %ld", error.code] + /// message:error.domain + /// details:error.localizedDescription]); + /// } + /// } else { + /// result(FlutterMethodNotImplemented); + /// } + /// } + /// // Other methods elided. + /// @end + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [invokeListMethod], for automatically returning typed lists. + /// * [invokeMapMethod], for automatically returning typed maps. + /// * [StandardMessageCodec] which defines the payload values supported by + /// [StandardMethodCodec]. + /// * [JSONMessageCodec] which defines the payload values supported by + /// [JSONMethodCodec]. + /// * <https://api.flutter.dev/javadoc/io/flutter/plugin/common/MethodCall.html> + /// for how to access method call arguments on Android. + @optionalTypeArgs + Future<T?> invokeMethod<T>(String method, [ dynamic arguments ]) { + return _invokeMethod<T>(method, missingOk: false, arguments: arguments); + } + + /// An implementation of [invokeMethod] that can return typed lists. + /// + /// Dart generics are reified, meaning that an untyped `List<dynamic>` cannot + /// masquerade as a `List<T>`. Since [invokeMethod] can only return dynamic + /// maps, we instead create a new typed list using [List.cast]. + /// + /// See also: + /// + /// * [invokeMethod], which this call delegates to. + Future<List<T>?> invokeListMethod<T>(String method, [ dynamic arguments ]) async { + final List<dynamic>? result = await invokeMethod<List<dynamic>>(method, arguments); + return result?.cast<T>(); + } + + /// An implementation of [invokeMethod] that can return typed maps. + /// + /// Dart generics are reified, meaning that an untyped `Map<dynamic, dynamic>` + /// cannot masquerade as a `Map<K, V>`. Since [invokeMethod] can only return + /// dynamic maps, we instead create a new typed map using [Map.cast]. + /// + /// See also: + /// + /// * [invokeMethod], which this call delegates to. + Future<Map<K, V>?> invokeMapMethod<K, V>(String method, [ dynamic arguments ]) async { + final Map<dynamic, dynamic>? result = await invokeMethod<Map<dynamic, dynamic>>(method, arguments); + return result?.cast<K, V>(); + } + + /// Sets a callback for receiving method calls on this channel. + /// + /// The given callback will replace the currently registered callback for this + /// channel, if any. To remove the handler, pass null as the + /// `handler` argument. + /// + /// If the future returned by the handler completes with a result, that value + /// is sent back to the platform plugin caller wrapped in a success envelope + /// as defined by the [codec] of this channel. If the future completes with + /// a [PlatformException], the fields of that exception will be used to + /// populate an error envelope which is sent back instead. If the future + /// completes with a [MissingPluginException], an empty reply is sent + /// similarly to what happens if no method call handler has been set. + /// Any other exception results in an error envelope being sent. + void setMethodCallHandler(Future<dynamic> Function(MethodCall call)? handler) { + assert( + _binaryMessenger != null || BindingBase.debugBindingType() != null, + 'Cannot set the method call handler before the binary messenger has been initialized. ' + 'This happens when you call setMethodCallHandler() before the WidgetsFlutterBinding ' + 'has been initialized. You can fix this by either calling WidgetsFlutterBinding.ensureInitialized() ' + 'before this or by passing a custom BinaryMessenger instance to MethodChannel().', + ); + binaryMessenger.setMessageHandler( + name, + handler == null + ? null + : (ByteData? message) => _handleAsMethodCall(message, handler), + ); + } + + Future<ByteData?> _handleAsMethodCall(ByteData? message, Future<dynamic> Function(MethodCall call) handler) async { + final MethodCall call = codec.decodeMethodCall(message); + try { + return codec.encodeSuccessEnvelope(await handler(call)); + } on PlatformException catch (e) { + return codec.encodeErrorEnvelope( + code: e.code, + message: e.message, + details: e.details, + ); + } on MissingPluginException { + return null; + } catch (error) { + return codec.encodeErrorEnvelope(code: 'error', message: error.toString()); + } + } + + // Looking for setMockMethodCallHandler or checkMethodCallHandler? + // See this shim package: packages/flutter_test/lib/src/deprecated.dart +} + +/// A [MethodChannel] that ignores missing platform plugins. +/// +/// When [invokeMethod] fails to find the platform plugin, it returns null +/// instead of throwing an exception. +/// +/// {@macro flutter.services.method_channel.FIFO} +class OptionalMethodChannel extends MethodChannel { + /// Creates a [MethodChannel] that ignores missing platform plugins. + const OptionalMethodChannel(super.name, [super.codec, super.binaryMessenger]); + + @override + Future<T?> invokeMethod<T>(String method, [ dynamic arguments ]) async { + return super._invokeMethod<T>(method, missingOk: true, arguments: arguments); + } +} + +/// A named channel for communicating with platform plugins using event streams. +/// +/// Stream setup requests are encoded into binary before being sent, +/// and binary events and errors received are decoded into Dart values. +/// The [MethodCodec] used must be compatible with the one used by the platform +/// plugin. This can be achieved by creating an [EventChannel] counterpart of +/// this channel on the platform side. The Dart type of events sent and received +/// is `dynamic`, but only values supported by the specified [MethodCodec] can +/// be used. +/// +/// The logical identity of the channel is given by its name. Identically named +/// channels will interfere with each other's communication. +/// +/// See: <https://flutter.dev/platform-channels/> +class EventChannel { + /// Creates an [EventChannel] with the specified [name]. + /// + /// The [codec] used will be [StandardMethodCodec], unless otherwise + /// specified. + /// + /// Neither [name] nor [codec] may be null. The default [ServicesBinding.defaultBinaryMessenger] + /// instance is used if [binaryMessenger] is null. + const EventChannel(this.name, [this.codec = const StandardMethodCodec(), BinaryMessenger? binaryMessenger]) + : _binaryMessenger = binaryMessenger; + + /// The logical channel on which communication happens, not null. + final String name; + + /// The message codec used by this channel, not null. + final MethodCodec codec; + + /// The messenger which sends the bytes for this channel. + /// + /// On the root isolate or web, this defaults to the + /// [ServicesBinding.defaultBinaryMessenger]. In other contexts the default + /// value is a [BackgroundIsolateBinaryMessenger] from + /// [BackgroundIsolateBinaryMessenger.ensureInitialized]. + BinaryMessenger get binaryMessenger => + _binaryMessenger ?? _findBinaryMessenger(); + final BinaryMessenger? _binaryMessenger; + + /// Sets up a broadcast stream for receiving events on this channel. + /// + /// Returns a broadcast [Stream] which emits events to listeners as follows: + /// + /// * a decoded data event (possibly null) for each successful event + /// received from the platform plugin; + /// * an error event containing a [PlatformException] for each error event + /// received from the platform plugin. + /// + /// Errors occurring during stream activation or deactivation are reported + /// through the [FlutterError] facility. Stream activation happens only when + /// stream listener count changes from 0 to 1. Stream deactivation happens + /// only when stream listener count changes from 1 to 0. + Stream<dynamic> receiveBroadcastStream([ dynamic arguments ]) { + final MethodChannel methodChannel = MethodChannel(name, codec); + late StreamController<dynamic> controller; + controller = StreamController<dynamic>.broadcast(onListen: () async { + binaryMessenger.setMessageHandler(name, (ByteData? reply) async { + if (reply == null) { + controller.close(); + } else { + try { + controller.add(codec.decodeEnvelope(reply)); + } on PlatformException catch (e) { + controller.addError(e); + } + } + return null; + }); + try { + await methodChannel.invokeMethod<void>('listen', arguments); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'services library', + context: ErrorDescription('while activating platform stream on channel $name'), + )); + } + }, onCancel: () async { + binaryMessenger.setMessageHandler(name, null); + try { + await methodChannel.invokeMethod<void>('cancel', arguments); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'services library', + context: ErrorDescription('while de-activating platform stream on channel $name'), + )); + } + }); + return controller.stream; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/platform_views.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/platform_views.dart new file mode 100644 index 0000000000000000000000000000000000000000..15faa35fa01cf7bd5fc3f1f3df40f7c93060c9fd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/platform_views.dart @@ -0,0 +1,1524 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; + +import 'message_codec.dart'; +import 'system_channels.dart'; + +export 'dart:ui' show Offset, Size, TextDirection, VoidCallback; + +export 'package:flutter/gestures.dart' show PointerEvent; + +export 'message_codec.dart' show MessageCodec; + +/// Converts a given point from the global coordinate system in logical pixels +/// to the local coordinate system for a box. +/// +/// Used by [AndroidViewController.pointTransformer]. +typedef PointTransformer = Offset Function(Offset position); + +/// The [PlatformViewsRegistry] responsible for generating unique identifiers for platform views. +final PlatformViewsRegistry platformViewsRegistry = PlatformViewsRegistry._instance(); + +/// A registry responsible for generating unique identifier for platform views. +/// +/// A Flutter application has a single [PlatformViewsRegistry] which can be accesses +/// through the [platformViewsRegistry] getter. +class PlatformViewsRegistry { + PlatformViewsRegistry._instance(); + + // Always non-negative. The id value -1 is used in the accessibility bridge + // to indicate the absence of a platform view. + int _nextPlatformViewId = 0; + + /// Allocates a unique identifier for a platform view. + /// + /// A platform view identifier can refer to a platform view that was never created, + /// a platform view that was disposed, or a platform view that is alive. + /// + /// Typically a platform view identifier is passed to a platform view widget + /// which creates the platform view and manages its lifecycle. + int getNextPlatformViewId() { + // On the Android side, the interface exposed to users uses 32-bit integers. + // See https://github.com/flutter/engine/pull/39476 for more details. + + // We can safely assume that a Flutter application will not require more + // than MAX_INT32 platform views during its lifetime. + const int MAX_INT32 = 0x7FFFFFFF; + assert(_nextPlatformViewId <= MAX_INT32); + return _nextPlatformViewId++; + } +} + +/// Callback signature for when a platform view was created. +/// +/// The `id` parameter is the platform view's unique identifier. +typedef PlatformViewCreatedCallback = void Function(int id); + +/// Provides access to the platform views service. +/// +/// This service allows creating and controlling platform-specific views. +class PlatformViewsService { + PlatformViewsService._() { + SystemChannels.platform_views.setMethodCallHandler(_onMethodCall); + } + + static final PlatformViewsService _instance = PlatformViewsService._(); + + Future<void> _onMethodCall(MethodCall call) { + switch (call.method) { + case 'viewFocused': + final int id = call.arguments as int; + if (_focusCallbacks.containsKey(id)) { + _focusCallbacks[id]!(); + } + default: + throw UnimplementedError("${call.method} was invoked but isn't implemented by PlatformViewsService"); + } + return Future<void>.value(); + } + + /// Maps platform view IDs to focus callbacks. + /// + /// The callbacks are invoked when the platform view asks to be focused. + final Map<int, VoidCallback> _focusCallbacks = <int, VoidCallback>{}; + + /// {@template flutter.services.PlatformViewsService.initAndroidView} + /// Creates a controller for a new Android view. + /// + /// The `id` argument is an unused unique identifier generated with + /// [platformViewsRegistry]. + /// + /// The `viewType` argument is the identifier of the Android view type to be + /// created, a factory for this view type must have been registered on the + /// platform side. Platform view factories are typically registered by plugin + /// code. Plugins can register a platform view factory with + /// [PlatformViewRegistry#registerViewFactory](/javadoc/io/flutter/plugin/platform/PlatformViewRegistry.html#registerViewFactory-java.lang.String-io.flutter.plugin.platform.PlatformViewFactory-). + /// + /// The `creationParams` argument will be passed as the args argument of + /// [PlatformViewFactory#create](/javadoc/io/flutter/plugin/platform/PlatformViewFactory.html#create-android.content.Context-int-java.lang.Object-) + /// + /// The `creationParamsCodec` argument is the codec used to encode + /// `creationParams` before sending it to the platform side. It should match + /// the codec passed to the constructor of + /// [PlatformViewFactory](/javadoc/io/flutter/plugin/platform/PlatformViewFactory.html#PlatformViewFactory-io.flutter.plugin.common.MessageCodec-). + /// This is typically one of: [StandardMessageCodec], [JSONMessageCodec], + /// [StringCodec], or [BinaryCodec]. + /// + /// The `onFocus` argument is a callback that will be invoked when the Android + /// View asks to get the input focus. + /// + /// The Android view will only be created after + /// [AndroidViewController.setSize] is called for the first time. + /// + /// If `creationParams` is non null then `creationParamsCodec` must not be + /// null. + /// {@endtemplate} + /// + /// This attempts to use the newest and most efficient platform view + /// implementation when possible. In cases where that is not supported, it + /// falls back to using Virtual Display. + static AndroidViewController initAndroidView({ + required int id, + required String viewType, + required TextDirection layoutDirection, + dynamic creationParams, + MessageCodec<dynamic>? creationParamsCodec, + VoidCallback? onFocus, + }) { + assert(creationParams == null || creationParamsCodec != null); + + final TextureAndroidViewController controller = TextureAndroidViewController._( + viewId: id, + viewType: viewType, + layoutDirection: layoutDirection, + creationParams: creationParams, + creationParamsCodec: creationParamsCodec, + ); + + _instance._focusCallbacks[id] = onFocus ?? () {}; + return controller; + } + + /// {@macro flutter.services.PlatformViewsService.initAndroidView} + /// + /// This attempts to use the newest and most efficient platform view + /// implementation when possible. In cases where that is not supported, it + /// falls back to using Hybrid Composition, which is the mode used by + /// [initExpensiveAndroidView]. + static SurfaceAndroidViewController initSurfaceAndroidView({ + required int id, + required String viewType, + required TextDirection layoutDirection, + dynamic creationParams, + MessageCodec<dynamic>? creationParamsCodec, + VoidCallback? onFocus, + }) { + assert(creationParams == null || creationParamsCodec != null); + + final SurfaceAndroidViewController controller = SurfaceAndroidViewController._( + viewId: id, + viewType: viewType, + layoutDirection: layoutDirection, + creationParams: creationParams, + creationParamsCodec: creationParamsCodec, + ); + _instance._focusCallbacks[id] = onFocus ?? () {}; + return controller; + } + + /// {@macro flutter.services.PlatformViewsService.initAndroidView} + /// + /// When this factory is used, the Android view and Flutter widgets are + /// composed at the Android view hierarchy level. + /// + /// Using this method has a performance cost on devices running Android 9 or + /// earlier, or on underpowered devices. In most situations, you should use + /// [initAndroidView] or [initSurfaceAndroidView] instead. + static ExpensiveAndroidViewController initExpensiveAndroidView({ + required int id, + required String viewType, + required TextDirection layoutDirection, + dynamic creationParams, + MessageCodec<dynamic>? creationParamsCodec, + VoidCallback? onFocus, + }) { + final ExpensiveAndroidViewController controller = ExpensiveAndroidViewController._( + viewId: id, + viewType: viewType, + layoutDirection: layoutDirection, + creationParams: creationParams, + creationParamsCodec: creationParamsCodec, + ); + + _instance._focusCallbacks[id] = onFocus ?? () {}; + return controller; + } + + /// Factory method to create a `UiKitView`. + /// + /// The `id` parameter is an unused unique identifier generated with + /// [platformViewsRegistry]. + /// + /// The `viewType` parameter is the identifier of the iOS view type to be + /// created, a factory for this view type must have been registered on the + /// platform side. Platform view factories are typically registered by plugin + /// code. + /// + /// The `onFocus` parameter is a callback that will be invoked when the UIKit + /// view asks to get the input focus. If `creationParams` is non null then + /// `creationParamsCodec` must not be null. + /// + /// See: https://docs.flutter.dev/platform-integration/ios/platform-views + static Future<UiKitViewController> initUiKitView({ + required int id, + required String viewType, + required TextDirection layoutDirection, + dynamic creationParams, + MessageCodec<dynamic>? creationParamsCodec, + VoidCallback? onFocus, + }) async { + assert(creationParams == null || creationParamsCodec != null); + + // TODO(amirh): pass layoutDirection once the system channel supports it. + // https://github.com/flutter/flutter/issues/133682 + final Map<String, dynamic> args = <String, dynamic>{ + 'id': id, + 'viewType': viewType, + }; + if (creationParams != null) { + final ByteData paramsByteData = creationParamsCodec!.encodeMessage(creationParams)!; + args['params'] = Uint8List.view( + paramsByteData.buffer, + 0, + paramsByteData.lengthInBytes, + ); + } + await SystemChannels.platform_views.invokeMethod<void>('create', args); + if (onFocus != null) { + _instance._focusCallbacks[id] = onFocus; + } + return UiKitViewController._(id, layoutDirection); + } + + // TODO(cbracken): Write and link website docs. https://github.com/flutter/website/issues/9424. + // + /// Factory method to create an `AppKitView`. + /// + /// The `id` parameter is an unused unique identifier generated with + /// [platformViewsRegistry]. + /// + /// The `viewType` parameter is the identifier of the iOS view type to be + /// created, a factory for this view type must have been registered on the + /// platform side. Platform view factories are typically registered by plugin + /// code. + /// + /// The `onFocus` parameter is a callback that will be invoked when the UIKit + /// view asks to get the input focus. If `creationParams` is non null then + /// `creationParamsCodec` must not be null. + static Future<AppKitViewController> initAppKitView({ + required int id, + required String viewType, + required TextDirection layoutDirection, + dynamic creationParams, + MessageCodec<dynamic>? creationParamsCodec, + VoidCallback? onFocus, + }) async { + assert(creationParams == null || creationParamsCodec != null); + + // TODO(amirh): pass layoutDirection once the system channel supports it. + // https://github.com/flutter/flutter/issues/133682 + final Map<String, dynamic> args = <String, dynamic>{ + 'id': id, + 'viewType': viewType, + }; + if (creationParams != null) { + final ByteData paramsByteData = creationParamsCodec!.encodeMessage(creationParams)!; + args['params'] = Uint8List.view( + paramsByteData.buffer, + 0, + paramsByteData.lengthInBytes, + ); + } + await SystemChannels.platform_views.invokeMethod<void>('create', args); + if (onFocus != null) { + _instance._focusCallbacks[id] = onFocus; + } + return AppKitViewController._(id, layoutDirection); + } +} + +/// Properties of an Android pointer. +/// +/// A Dart version of Android's [MotionEvent.PointerProperties](https://developer.android.com/reference/android/view/MotionEvent.PointerProperties). +class AndroidPointerProperties { + /// Creates an [AndroidPointerProperties] object. + const AndroidPointerProperties({ + required this.id, + required this.toolType, + }); + + /// See Android's [MotionEvent.PointerProperties#id](https://developer.android.com/reference/android/view/MotionEvent.PointerProperties.html#id). + final int id; + + /// The type of tool used to make contact such as a finger or stylus, if known. + /// See Android's [MotionEvent.PointerProperties#toolType](https://developer.android.com/reference/android/view/MotionEvent.PointerProperties.html#toolType). + final int toolType; + + /// Value for `toolType` when the tool type is unknown. + static const int kToolTypeUnknown = 0; + + /// Value for `toolType` when the tool type is a finger. + static const int kToolTypeFinger = 1; + + /// Value for `toolType` when the tool type is a stylus. + static const int kToolTypeStylus = 2; + + /// Value for `toolType` when the tool type is a mouse. + static const int kToolTypeMouse = 3; + + /// Value for `toolType` when the tool type is an eraser. + static const int kToolTypeEraser = 4; + + List<int> _asList() => <int>[id, toolType]; + + @override + String toString() { + return '${objectRuntimeType(this, 'AndroidPointerProperties')}(id: $id, toolType: $toolType)'; + } +} + +/// Position information for an Android pointer. +/// +/// A Dart version of Android's [MotionEvent.PointerCoords](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords). +class AndroidPointerCoords { + /// Creates an AndroidPointerCoords. + const AndroidPointerCoords({ + required this.orientation, + required this.pressure, + required this.size, + required this.toolMajor, + required this.toolMinor, + required this.touchMajor, + required this.touchMinor, + required this.x, + required this.y, + }); + + /// The orientation of the touch area and tool area in radians clockwise from vertical. + /// + /// See Android's [MotionEvent.PointerCoords#orientation](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html#orientation). + final double orientation; + + /// A normalized value that describes the pressure applied to the device by a finger or other tool. + /// + /// See Android's [MotionEvent.PointerCoords#pressure](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html#pressure). + final double pressure; + + /// A normalized value that describes the approximate size of the pointer touch area in relation to the maximum detectable size of the device. + /// + /// See Android's [MotionEvent.PointerCoords#size](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html#size). + final double size; + + /// See Android's [MotionEvent.PointerCoords#toolMajor](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html#toolMajor). + final double toolMajor; + + /// See Android's [MotionEvent.PointerCoords#toolMinor](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html#toolMinor). + final double toolMinor; + + /// See Android's [MotionEvent.PointerCoords#touchMajor](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html#touchMajor). + final double touchMajor; + + /// See Android's [MotionEvent.PointerCoords#touchMinor](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html#touchMinor). + final double touchMinor; + + /// The X component of the pointer movement. + /// + /// See Android's [MotionEvent.PointerCoords#x](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html#x). + final double x; + + /// The Y component of the pointer movement. + /// + /// See Android's [MotionEvent.PointerCoords#y](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html#y). + final double y; + + List<double> _asList() { + return <double>[ + orientation, + pressure, + size, + toolMajor, + toolMinor, + touchMajor, + touchMinor, + x, + y, + ]; + } + + @override + String toString() { + return '${objectRuntimeType(this, 'AndroidPointerCoords')}(orientation: $orientation, pressure: $pressure, size: $size, toolMajor: $toolMajor, toolMinor: $toolMinor, touchMajor: $touchMajor, touchMinor: $touchMinor, x: $x, y: $y)'; + } +} + +/// A Dart version of Android's [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent). +/// +/// This is used by [AndroidViewController] to describe pointer events that are forwarded to a platform view +/// when Flutter receives an event that it determines is to be handled by that platform view rather than by +/// another Flutter widget. +/// +/// See also: +/// +/// * [AndroidViewController.sendMotionEvent], which can be used to send an [AndroidMotionEvent] explicitly. +class AndroidMotionEvent { + /// Creates an AndroidMotionEvent. + AndroidMotionEvent({ + required this.downTime, + required this.eventTime, + required this.action, + required this.pointerCount, + required this.pointerProperties, + required this.pointerCoords, + required this.metaState, + required this.buttonState, + required this.xPrecision, + required this.yPrecision, + required this.deviceId, + required this.edgeFlags, + required this.source, + required this.flags, + required this.motionEventId, + }) : assert(pointerProperties.length == pointerCount), + assert(pointerCoords.length == pointerCount); + + /// The time (in ms) when the user originally pressed down to start a stream of position events, + /// relative to an arbitrary timeline. + /// + /// See Android's [MotionEvent#getDownTime](https://developer.android.com/reference/android/view/MotionEvent.html#getDownTime()). + final int downTime; + + /// The time this event occurred, relative to an arbitrary timeline. + /// + /// See Android's [MotionEvent#getEventTime](https://developer.android.com/reference/android/view/MotionEvent.html#getEventTime()). + final int eventTime; + + /// A value representing the kind of action being performed. + /// + /// See Android's [MotionEvent#getAction](https://developer.android.com/reference/android/view/MotionEvent.html#getAction()). + final int action; + + /// The number of pointers that are part of this event. + /// This must be equivalent to the length of `pointerProperties` and `pointerCoords`. + /// + /// See Android's [MotionEvent#getPointerCount](https://developer.android.com/reference/android/view/MotionEvent.html#getPointerCount()). + final int pointerCount; + + /// List of [AndroidPointerProperties] for each pointer that is part of this event. + final List<AndroidPointerProperties> pointerProperties; + + /// List of [AndroidPointerCoords] for each pointer that is part of this event. + final List<AndroidPointerCoords> pointerCoords; + + /// The state of any meta / modifier keys that were in effect when the event was generated. + /// + /// See Android's [MotionEvent#getMetaState](https://developer.android.com/reference/android/view/MotionEvent.html#getMetaState()). + final int metaState; + + /// The state of all buttons that are pressed such as a mouse or stylus button. + /// + /// See Android's [MotionEvent#getButtonState](https://developer.android.com/reference/android/view/MotionEvent.html#getButtonState()). + final int buttonState; + + /// The precision of the X coordinates being reported, in physical pixels. + /// + /// See Android's [MotionEvent#getXPrecision](https://developer.android.com/reference/android/view/MotionEvent.html#getXPrecision()). + final double xPrecision; + + /// The precision of the Y coordinates being reported, in physical pixels. + /// + /// See Android's [MotionEvent#getYPrecision](https://developer.android.com/reference/android/view/MotionEvent.html#getYPrecision()). + final double yPrecision; + + /// See Android's [MotionEvent#getDeviceId](https://developer.android.com/reference/android/view/MotionEvent.html#getDeviceId()). + final int deviceId; + + /// A bit field indicating which edges, if any, were touched by this MotionEvent. + /// + /// See Android's [MotionEvent#getEdgeFlags](https://developer.android.com/reference/android/view/MotionEvent.html#getEdgeFlags()). + final int edgeFlags; + + /// The source of this event (e.g a touchpad or stylus). + /// + /// See Android's [MotionEvent#getSource](https://developer.android.com/reference/android/view/MotionEvent.html#getSource()). + final int source; + + /// See Android's [MotionEvent#getFlags](https://developer.android.com/reference/android/view/MotionEvent.html#getFlags()). + final int flags; + + /// Used to identify this [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent.html) uniquely in the Flutter Engine. + final int motionEventId; + + List<dynamic> _asList(int viewId) { + return <dynamic>[ + viewId, + downTime, + eventTime, + action, + pointerCount, + pointerProperties.map<List<int>>((AndroidPointerProperties p) => p._asList()).toList(), + pointerCoords.map<List<double>>((AndroidPointerCoords p) => p._asList()).toList(), + metaState, + buttonState, + xPrecision, + yPrecision, + deviceId, + edgeFlags, + source, + flags, + motionEventId, + ]; + } + + @override + String toString() { + return 'AndroidPointerEvent(downTime: $downTime, eventTime: $eventTime, action: $action, pointerCount: $pointerCount, pointerProperties: $pointerProperties, pointerCoords: $pointerCoords, metaState: $metaState, buttonState: $buttonState, xPrecision: $xPrecision, yPrecision: $yPrecision, deviceId: $deviceId, edgeFlags: $edgeFlags, source: $source, flags: $flags, motionEventId: $motionEventId)'; + } +} + +enum _AndroidViewState { + waitingForSize, + creating, + created, + disposed, +} + +// Helper for converting PointerEvents into AndroidMotionEvents. +class _AndroidMotionEventConverter { + _AndroidMotionEventConverter(); + + final Map<int, AndroidPointerCoords> pointerPositions = + <int, AndroidPointerCoords>{}; + final Map<int, AndroidPointerProperties> pointerProperties = + <int, AndroidPointerProperties>{}; + final Set<int> usedAndroidPointerIds = <int>{}; + + late PointTransformer pointTransformer; + + int? downTimeMillis; + + void handlePointerDownEvent(PointerDownEvent event) { + if (pointerProperties.isEmpty) { + downTimeMillis = event.timeStamp.inMilliseconds; + } + int androidPointerId = 0; + while (usedAndroidPointerIds.contains(androidPointerId)) { + androidPointerId++; + } + usedAndroidPointerIds.add(androidPointerId); + pointerProperties[event.pointer] = propertiesFor(event, androidPointerId); + } + + void updatePointerPositions(PointerEvent event) { + final Offset position = pointTransformer(event.position); + pointerPositions[event.pointer] = AndroidPointerCoords( + orientation: event.orientation, + pressure: event.pressure, + size: event.size, + toolMajor: event.radiusMajor, + toolMinor: event.radiusMinor, + touchMajor: event.radiusMajor, + touchMinor: event.radiusMinor, + x: position.dx, + y: position.dy, + ); + } + + void _remove(int pointer) { + pointerPositions.remove(pointer); + usedAndroidPointerIds.remove(pointerProperties[pointer]!.id); + pointerProperties.remove(pointer); + if (pointerProperties.isEmpty) { + downTimeMillis = null; + } + } + + void handlePointerUpEvent(PointerUpEvent event) { + _remove(event.pointer); + } + + void handlePointerCancelEvent(PointerCancelEvent event) { + // The pointer cancel event is handled like pointer up. Normally, + // the difference is that pointer cancel doesn't perform any action, + // but in this case neither up or cancel perform any action. + _remove(event.pointer); + } + + AndroidMotionEvent? toAndroidMotionEvent(PointerEvent event) { + final List<int> pointers = pointerPositions.keys.toList(); + final int pointerIdx = pointers.indexOf(event.pointer); + final int numPointers = pointers.length; + + // This value must match the value in engine's FlutterView.java. + // This flag indicates whether the original Android pointer events were batched together. + const int kPointerDataFlagBatched = 1; + + // Android MotionEvent objects can batch information on multiple pointers. + // Flutter breaks these such batched events into multiple PointerEvent objects. + // When there are multiple active pointers we accumulate the information for all pointers + // as we get PointerEvents, and only send it to the embedded Android view when + // we see the last pointer. This way we achieve the same batching as Android. + if (event.platformData == kPointerDataFlagBatched || + (isSinglePointerAction(event) && pointerIdx < numPointers - 1)) { + return null; + } + + final int action; + if (event is PointerDownEvent) { + action = numPointers == 1 + ? AndroidViewController.kActionDown + : AndroidViewController.pointerAction(pointerIdx, AndroidViewController.kActionPointerDown); + } else if (event is PointerUpEvent) { + action = numPointers == 1 + ? AndroidViewController.kActionUp + : AndroidViewController.pointerAction(pointerIdx, AndroidViewController.kActionPointerUp); + } else if (event is PointerMoveEvent) { + action = AndroidViewController.kActionMove; + } else if (event is PointerCancelEvent) { + action = AndroidViewController.kActionCancel; + } else { + return null; + } + + return AndroidMotionEvent( + downTime: downTimeMillis!, + eventTime: event.timeStamp.inMilliseconds, + action: action, + pointerCount: pointerPositions.length, + pointerProperties: pointers + .map<AndroidPointerProperties>((int i) => pointerProperties[i]!) + .toList(), + pointerCoords: pointers + .map<AndroidPointerCoords>((int i) => pointerPositions[i]!) + .toList(), + metaState: 0, + buttonState: 0, + xPrecision: 1.0, + yPrecision: 1.0, + deviceId: 0, + edgeFlags: 0, + source: _AndroidMotionEventConverter.sourceFor(event), + flags: 0, + motionEventId: event.embedderId, + ); + } + + static int sourceFor(PointerEvent event) { + int source = AndroidViewController.kInputDeviceSourceUnknown; + switch (event.kind) { + case PointerDeviceKind.touch: + source = AndroidViewController.kInputDeviceSourceTouchScreen; + case PointerDeviceKind.trackpad: + source = AndroidViewController.kInputDeviceSourceTouchPad; + case PointerDeviceKind.mouse: + source = AndroidViewController.kInputDeviceSourceMouse; + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + source = AndroidViewController.kInputDeviceSourceStylus; + case PointerDeviceKind.unknown: + source = AndroidViewController.kInputDeviceSourceUnknown; + } + return source; + } + + + AndroidPointerProperties propertiesFor(PointerEvent event, int pointerId) { + int toolType = AndroidPointerProperties.kToolTypeUnknown; + switch (event.kind) { + case PointerDeviceKind.touch: + case PointerDeviceKind.trackpad: + toolType = AndroidPointerProperties.kToolTypeFinger; + case PointerDeviceKind.mouse: + toolType = AndroidPointerProperties.kToolTypeMouse; + case PointerDeviceKind.stylus: + toolType = AndroidPointerProperties.kToolTypeStylus; + case PointerDeviceKind.invertedStylus: + toolType = AndroidPointerProperties.kToolTypeEraser; + case PointerDeviceKind.unknown: + toolType = AndroidPointerProperties.kToolTypeUnknown; + } + return AndroidPointerProperties(id: pointerId, toolType: toolType); + } + + bool isSinglePointerAction(PointerEvent event) => + event is! PointerDownEvent && event is! PointerUpEvent; +} + +class _CreationParams { + const _CreationParams(this.data, this.codec); + final dynamic data; + final MessageCodec<dynamic> codec; +} + +/// Controls an Android view that is composed using a GL texture. +/// +/// Typically created with [PlatformViewsService.initAndroidView]. +// TODO(bparrishMines): Remove abstract methods that are not required by all subclasses. +abstract class AndroidViewController extends PlatformViewController { + AndroidViewController._({ + required this.viewId, + required String viewType, + required TextDirection layoutDirection, + dynamic creationParams, + MessageCodec<dynamic>? creationParamsCodec, + }) : assert(creationParams == null || creationParamsCodec != null), + _viewType = viewType, + _layoutDirection = layoutDirection, + _creationParams = creationParams == null ? null : _CreationParams(creationParams, creationParamsCodec!); + + /// Action code for when a primary pointer touched the screen. + /// + /// Android's [MotionEvent.ACTION_DOWN](https://developer.android.com/reference/android/view/MotionEvent#ACTION_DOWN) + static const int kActionDown = 0; + + /// Action code for when a primary pointer stopped touching the screen. + /// + /// Android's [MotionEvent.ACTION_UP](https://developer.android.com/reference/android/view/MotionEvent#ACTION_UP) + static const int kActionUp = 1; + + /// Action code for when the event only includes information about pointer movement. + /// + /// Android's [MotionEvent.ACTION_MOVE](https://developer.android.com/reference/android/view/MotionEvent#ACTION_MOVE) + static const int kActionMove = 2; + + /// Action code for when a motion event has been canceled. + /// + /// Android's [MotionEvent.ACTION_CANCEL](https://developer.android.com/reference/android/view/MotionEvent#ACTION_CANCEL) + static const int kActionCancel = 3; + + /// Action code for when a secondary pointer touched the screen. + /// + /// Android's [MotionEvent.ACTION_POINTER_DOWN](https://developer.android.com/reference/android/view/MotionEvent#ACTION_POINTER_DOWN) + static const int kActionPointerDown = 5; + + /// Action code for when a secondary pointer stopped touching the screen. + /// + /// Android's [MotionEvent.ACTION_POINTER_UP](https://developer.android.com/reference/android/view/MotionEvent#ACTION_POINTER_UP) + static const int kActionPointerUp = 6; + + /// Android's [View.LAYOUT_DIRECTION_LTR](https://developer.android.com/reference/android/view/View.html#LAYOUT_DIRECTION_LTR) value. + static const int kAndroidLayoutDirectionLtr = 0; + + /// Android's [View.LAYOUT_DIRECTION_RTL](https://developer.android.com/reference/android/view/View.html#LAYOUT_DIRECTION_RTL) value. + static const int kAndroidLayoutDirectionRtl = 1; + + /// Android's [InputDevice.SOURCE_UNKNOWN](https://developer.android.com/reference/android/view/InputDevice#SOURCE_UNKNOWN) + static const int kInputDeviceSourceUnknown = 0; + + /// Android's [InputDevice.SOURCE_TOUCHSCREEN](https://developer.android.com/reference/android/view/InputDevice#SOURCE_TOUCHSCREEN) + static const int kInputDeviceSourceTouchScreen = 4098; + + /// Android's [InputDevice.SOURCE_MOUSE](https://developer.android.com/reference/android/view/InputDevice#SOURCE_MOUSE) + static const int kInputDeviceSourceMouse = 8194; + + /// Android's [InputDevice.SOURCE_STYLUS](https://developer.android.com/reference/android/view/InputDevice#SOURCE_STYLUS) + static const int kInputDeviceSourceStylus = 16386; + + /// Android's [InputDevice.SOURCE_TOUCHPAD](https://developer.android.com/reference/android/view/InputDevice#SOURCE_TOUCHPAD) + static const int kInputDeviceSourceTouchPad = 1048584; + + /// The unique identifier of the Android view controlled by this controller. + @override + final int viewId; + + final String _viewType; + + // Helps convert PointerEvents to AndroidMotionEvents. + final _AndroidMotionEventConverter _motionEventConverter = + _AndroidMotionEventConverter(); + + TextDirection _layoutDirection; + + _AndroidViewState _state = _AndroidViewState.waitingForSize; + + final _CreationParams? _creationParams; + + final List<PlatformViewCreatedCallback> _platformViewCreatedCallbacks = + <PlatformViewCreatedCallback>[]; + + static int _getAndroidDirection(TextDirection direction) { + switch (direction) { + case TextDirection.ltr: + return kAndroidLayoutDirectionLtr; + case TextDirection.rtl: + return kAndroidLayoutDirectionRtl; + } + } + + /// Creates a masked Android MotionEvent action value for an indexed pointer. + static int pointerAction(int pointerId, int action) { + return ((pointerId << 8) & 0xff00) | (action & 0xff); + } + + /// Sends the message to dispose the platform view. + Future<void> _sendDisposeMessage(); + + /// True if [_sendCreateMessage] can only be called with a non-null size. + bool get _createRequiresSize; + + /// Sends the message to create the platform view with an initial [size]. + /// + /// If [_createRequiresSize] is true, `size` is non-nullable, and the call + /// should instead be deferred until the size is available. + Future<void> _sendCreateMessage({required covariant Size? size, Offset? position}); + + /// Sends the message to resize the platform view to [size]. + Future<Size> _sendResizeMessage(Size size); + + @override + bool get awaitingCreation => _state == _AndroidViewState.waitingForSize; + + @override + Future<void> create({Size? size, Offset? position}) async { + assert(_state != _AndroidViewState.disposed, 'trying to create a disposed Android view'); + assert(_state == _AndroidViewState.waitingForSize, 'Android view is already sized. View id: $viewId'); + + if (_createRequiresSize && size == null) { + // Wait for a setSize call. + return; + } + + _state = _AndroidViewState.creating; + await _sendCreateMessage(size: size, position: position); + _state = _AndroidViewState.created; + + for (final PlatformViewCreatedCallback callback in _platformViewCreatedCallbacks) { + callback(viewId); + } + } + + /// Sizes the Android View. + /// + /// [size] is the view's new size in logical pixel. It must be greater than + /// zero. + /// + /// The first time a size is set triggers the creation of the Android view. + /// + /// Returns the buffer size in logical pixel that backs the texture where the platform + /// view pixels are written to. + /// + /// The buffer size may or may not be the same as [size]. + /// + /// As a result, consumers are expected to clip the texture using [size], while using + /// the return value to size the texture. + Future<Size> setSize(Size size) async { + assert(_state != _AndroidViewState.disposed, 'Android view is disposed. View id: $viewId'); + if (_state == _AndroidViewState.waitingForSize) { + // Either `create` hasn't been called, or it couldn't run due to missing + // size information, so create the view now. + await create(size: size); + return size; + } else { + return _sendResizeMessage(size); + } + } + + /// Sets the offset of the platform view. + /// + /// [off] is the view's new offset in logical pixel. + /// + /// On Android, this allows the Android native view to draw the a11y highlights in the same + /// location on the screen as the platform view widget in the Flutter framework. + Future<void> setOffset(Offset off); + + /// Returns the texture entry id that the Android view is rendering into. + /// + /// Returns null if the Android view has not been successfully created, if it has been + /// disposed, or if the implementation does not use textures. + int? get textureId; + + /// True if the view requires native view composition rather than using a + /// texture to render. + /// + /// This value may change during [create], but will not change after that + /// call's future has completed. + bool get requiresViewComposition => false; + + /// Sends an Android [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent) + /// to the view. + /// + /// The Android MotionEvent object is created with [MotionEvent.obtain](https://developer.android.com/reference/android/view/MotionEvent.html#obtain(long,%20long,%20int,%20float,%20float,%20float,%20float,%20int,%20float,%20float,%20int,%20int)). + /// See documentation of [MotionEvent.obtain](https://developer.android.com/reference/android/view/MotionEvent.html#obtain(long,%20long,%20int,%20float,%20float,%20float,%20float,%20int,%20float,%20float,%20int,%20int)) + /// for description of the parameters. + /// + /// See [AndroidViewController.dispatchPointerEvent] for sending a + /// [PointerEvent]. + Future<void> sendMotionEvent(AndroidMotionEvent event) async { + await SystemChannels.platform_views.invokeMethod<dynamic>( + 'touch', + event._asList(viewId), + ); + } + + /// Converts a given point from the global coordinate system in logical pixels + /// to the local coordinate system for this box. + /// + /// This is required to convert a [PointerEvent] to an [AndroidMotionEvent]. + /// It is typically provided by using [RenderBox.globalToLocal]. + PointTransformer get pointTransformer => _motionEventConverter.pointTransformer; + set pointTransformer(PointTransformer transformer) { + _motionEventConverter.pointTransformer = transformer; + } + + /// Whether the platform view has already been created. + bool get isCreated => _state == _AndroidViewState.created; + + /// Adds a callback that will get invoke after the platform view has been + /// created. + void addOnPlatformViewCreatedListener(PlatformViewCreatedCallback listener) { + assert(_state != _AndroidViewState.disposed); + _platformViewCreatedCallbacks.add(listener); + } + + /// Removes a callback added with [addOnPlatformViewCreatedListener]. + void removeOnPlatformViewCreatedListener(PlatformViewCreatedCallback listener) { + assert(_state != _AndroidViewState.disposed); + _platformViewCreatedCallbacks.remove(listener); + } + + /// The created callbacks that are invoked after the platform view has been + /// created. + @visibleForTesting + List<PlatformViewCreatedCallback> get createdCallbacks => _platformViewCreatedCallbacks; + + /// Sets the layout direction for the Android view. + Future<void> setLayoutDirection(TextDirection layoutDirection) async { + assert( + _state != _AndroidViewState.disposed, + 'trying to set a layout direction for a disposed Android view. View id: $viewId', + ); + + if (layoutDirection == _layoutDirection) { + return; + } + + _layoutDirection = layoutDirection; + + // If the view was not yet created we just update _layoutDirection and return, as the new + // direction will be used in _create. + if (_state == _AndroidViewState.waitingForSize) { + return; + } + + await SystemChannels.platform_views + .invokeMethod<void>('setDirection', <String, dynamic>{ + 'id': viewId, + 'direction': _getAndroidDirection(layoutDirection), + }); + } + + /// Converts the [PointerEvent] and sends an Android [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent) + /// to the view. + /// + /// This method can only be used if a [PointTransformer] is provided to + /// [AndroidViewController.pointTransformer]. Otherwise, an [AssertionError] + /// is thrown. See [AndroidViewController.sendMotionEvent] for sending a + /// `MotionEvent` without a [PointTransformer]. + /// + /// The Android MotionEvent object is created with [MotionEvent.obtain](https://developer.android.com/reference/android/view/MotionEvent.html#obtain(long,%20long,%20int,%20float,%20float,%20float,%20float,%20int,%20float,%20float,%20int,%20int)). + /// See documentation of [MotionEvent.obtain](https://developer.android.com/reference/android/view/MotionEvent.html#obtain(long,%20long,%20int,%20float,%20float,%20float,%20float,%20int,%20float,%20float,%20int,%20int)) + /// for description of the parameters. + @override + Future<void> dispatchPointerEvent(PointerEvent event) async { + if (event is PointerHoverEvent) { + return; + } + + if (event is PointerDownEvent) { + _motionEventConverter.handlePointerDownEvent(event); + } + + _motionEventConverter.updatePointerPositions(event); + + final AndroidMotionEvent? androidEvent = + _motionEventConverter.toAndroidMotionEvent(event); + + if (event is PointerUpEvent) { + _motionEventConverter.handlePointerUpEvent(event); + } else if (event is PointerCancelEvent) { + _motionEventConverter.handlePointerCancelEvent(event); + } + + if (androidEvent != null) { + await sendMotionEvent(androidEvent); + } + } + + /// Clears the focus from the Android View if it is focused. + @override + Future<void> clearFocus() { + if (_state != _AndroidViewState.created) { + return Future<void>.value(); + } + return SystemChannels.platform_views.invokeMethod<void>('clearFocus', viewId); + } + + /// Disposes the Android view. + /// + /// The [AndroidViewController] object is unusable after calling this. + /// The identifier of the platform view cannot be reused after the view is + /// disposed. + @override + Future<void> dispose() async { + final _AndroidViewState state = _state; + _state = _AndroidViewState.disposed; + _platformViewCreatedCallbacks.clear(); + PlatformViewsService._instance._focusCallbacks.remove(viewId); + if (state == _AndroidViewState.creating || state == _AndroidViewState.created) { + await _sendDisposeMessage(); + } + } +} + +/// Controls an Android view that is composed using a GL texture. +/// This controller is created from the [PlatformViewsService.initSurfaceAndroidView] factory, +/// and is defined for backward compatibility. +class SurfaceAndroidViewController extends AndroidViewController { + SurfaceAndroidViewController._({ + required super.viewId, + required super.viewType, + required super.layoutDirection, + super.creationParams, + super.creationParamsCodec, + }) : super._(); + + // By default, assume the implementation will be texture-based. + _AndroidViewControllerInternals _internals = _TextureAndroidViewControllerInternals(); + + @override + bool get _createRequiresSize => true; + + @override + Future<bool> _sendCreateMessage({required Size size, Offset? position}) async { + assert(!size.isEmpty, 'trying to create $TextureAndroidViewController without setting a valid size.'); + + final dynamic response = await _AndroidViewControllerInternals.sendCreateMessage( + viewId: viewId, + viewType: _viewType, + hybrid: false, + hybridFallback: true, + layoutDirection: _layoutDirection, + creationParams: _creationParams, + size: size, + position: position, + ); + if (response is int) { + (_internals as _TextureAndroidViewControllerInternals).textureId = response; + } else { + // A null response indicates fallback to Hybrid Composition, so swap out + // the implementation. + _internals = _HybridAndroidViewControllerInternals(); + } + return true; + } + + @override + int? get textureId { + return _internals.textureId; + } + + @override + bool get requiresViewComposition { + return _internals.requiresViewComposition; + } + + @override + Future<void> _sendDisposeMessage() { + return _internals.sendDisposeMessage(viewId: viewId); + } + + @override + Future<Size> _sendResizeMessage(Size size) { + return _internals.setSize(size, viewId: viewId, viewState: _state); + } + + @override + Future<void> setOffset(Offset off) { + return _internals.setOffset(off, viewId: viewId, viewState: _state); + } +} + +/// Controls an Android view that is composed using the Android view hierarchy. +/// This controller is created from the [PlatformViewsService.initExpensiveAndroidView] factory. +class ExpensiveAndroidViewController extends AndroidViewController { + ExpensiveAndroidViewController._({ + required super.viewId, + required super.viewType, + required super.layoutDirection, + super.creationParams, + super.creationParamsCodec, + }) : super._(); + + final _AndroidViewControllerInternals _internals = _HybridAndroidViewControllerInternals(); + + @override + bool get _createRequiresSize => false; + + @override + Future<void> _sendCreateMessage({required Size? size, Offset? position}) async { + await _AndroidViewControllerInternals.sendCreateMessage( + viewId: viewId, + viewType: _viewType, + hybrid: true, + layoutDirection: _layoutDirection, + creationParams: _creationParams, + position: position, + ); + } + + @override + int? get textureId { + return _internals.textureId; + } + + @override + bool get requiresViewComposition { + return _internals.requiresViewComposition; + } + + @override + Future<void> _sendDisposeMessage() { + return _internals.sendDisposeMessage(viewId: viewId); + } + + @override + Future<Size> _sendResizeMessage(Size size) { + return _internals.setSize(size, viewId: viewId, viewState: _state); + } + + @override + Future<void> setOffset(Offset off) { + return _internals.setOffset(off, viewId: viewId, viewState: _state); + } +} + +/// Controls an Android view that is rendered as a texture. +/// This is typically used by [AndroidView] to display a View in the Android view hierarchy. +/// +/// The platform view is created by calling [create] with an initial size. +/// +/// The controller is typically created with [PlatformViewsService.initAndroidView]. +class TextureAndroidViewController extends AndroidViewController { + TextureAndroidViewController._({ + required super.viewId, + required super.viewType, + required super.layoutDirection, + super.creationParams, + super.creationParamsCodec, + }) : super._(); + + final _TextureAndroidViewControllerInternals _internals = _TextureAndroidViewControllerInternals(); + + @override + bool get _createRequiresSize => true; + + @override + Future<void> _sendCreateMessage({required Size size, Offset? position}) async { + assert(!size.isEmpty, 'trying to create $TextureAndroidViewController without setting a valid size.'); + + _internals.textureId = await _AndroidViewControllerInternals.sendCreateMessage( + viewId: viewId, + viewType: _viewType, + hybrid: false, + layoutDirection: _layoutDirection, + creationParams: _creationParams, + size: size, + position: position, + ) as int; + } + + @override + int? get textureId { + return _internals.textureId; + } + + @override + bool get requiresViewComposition { + return _internals.requiresViewComposition; + } + + @override + Future<void> _sendDisposeMessage() { + return _internals.sendDisposeMessage(viewId: viewId); + } + + @override + Future<Size> _sendResizeMessage(Size size) { + return _internals.setSize(size, viewId: viewId, viewState: _state); + } + + @override + Future<void> setOffset(Offset off) { + return _internals.setOffset(off, viewId: viewId, viewState: _state); + } +} + +// The base class for an implementation of AndroidViewController. +// +// Subclasses should correspond to different rendering modes for platform +// views, and match different mode logic on the engine side. +abstract class _AndroidViewControllerInternals { + // Sends a create message with the given parameters, and returns the result + // if any. + // + // This uses a dynamic return because depending on the mode that is selected + // on the native side, the return type is different. Callers should cast + // depending on the possible return types for their arguments. + static Future<dynamic> sendCreateMessage({ + required int viewId, + required String viewType, + required TextDirection layoutDirection, + required bool hybrid, + bool hybridFallback = false, + _CreationParams? creationParams, + Size? size, + Offset? position}) { + final Map<String, dynamic> args = <String, dynamic>{ + 'id': viewId, + 'viewType': viewType, + 'direction': AndroidViewController._getAndroidDirection(layoutDirection), + if (hybrid) 'hybrid': hybrid, + if (size != null) 'width': size.width, + if (size != null) 'height': size.height, + if (hybridFallback) 'hybridFallback': hybridFallback, + if (position != null) 'left': position.dx, + if (position != null) 'top': position.dy, + }; + if (creationParams != null) { + final ByteData paramsByteData = creationParams.codec.encodeMessage(creationParams.data)!; + args['params'] = Uint8List.view( + paramsByteData.buffer, + 0, + paramsByteData.lengthInBytes, + ); + } + return SystemChannels.platform_views.invokeMethod<dynamic>('create', args); + } + + int? get textureId; + + bool get requiresViewComposition; + + Future<Size> setSize( + Size size, { + required int viewId, + required _AndroidViewState viewState, + }); + + Future<void> setOffset( + Offset offset, { + required int viewId, + required _AndroidViewState viewState, + }); + + Future<void> sendDisposeMessage({required int viewId}); +} + +// An AndroidViewController implementation for views whose contents are +// displayed via a texture rather than directly in a native view. +// +// This is used for both Virtual Display and Texture Layer Hybrid Composition. +class _TextureAndroidViewControllerInternals extends _AndroidViewControllerInternals { + _TextureAndroidViewControllerInternals(); + + /// The current offset of the platform view. + Offset _offset = Offset.zero; + + @override + int? textureId; + + @override + bool get requiresViewComposition => false; + + @override + Future<Size> setSize( + Size size, { + required int viewId, + required _AndroidViewState viewState, + }) async { + assert(viewState != _AndroidViewState.waitingForSize, 'Android view must have an initial size. View id: $viewId'); + assert(!size.isEmpty); + + final Map<Object?, Object?>? meta = await SystemChannels.platform_views.invokeMapMethod<Object?, Object?>( + 'resize', + <String, dynamic>{ + 'id': viewId, + 'width': size.width, + 'height': size.height, + }, + ); + assert(meta != null); + assert(meta!.containsKey('width')); + assert(meta!.containsKey('height')); + return Size(meta!['width']! as double, meta['height']! as double); + } + + @override + Future<void> setOffset( + Offset offset, { + required int viewId, + required _AndroidViewState viewState, + }) async { + if (offset == _offset) { + return; + } + + // Don't set the offset unless the Android view has been created. + // The implementation of this method channel throws if the Android view for this viewId + // isn't addressable. + if (viewState != _AndroidViewState.created) { + return; + } + + _offset = offset; + + await SystemChannels.platform_views.invokeMethod<void>( + 'offset', + <String, dynamic>{ + 'id': viewId, + 'top': offset.dy, + 'left': offset.dx, + }, + ); + } + + @override + Future<void> sendDisposeMessage({required int viewId}) { + return SystemChannels + .platform_views.invokeMethod<void>('dispose', <String, dynamic>{ + 'id': viewId, + 'hybrid': false, + }); + } +} + +// An AndroidViewController implementation for views whose contents are +// displayed directly in a native view. +// +// This is used for Hybrid Composition. +class _HybridAndroidViewControllerInternals extends _AndroidViewControllerInternals { + @override + int get textureId { + throw UnimplementedError('Not supported for hybrid composition.'); + } + + @override + bool get requiresViewComposition => true; + + @override + Future<Size> setSize( + Size size, { + required int viewId, + required _AndroidViewState viewState, + }) { + throw UnimplementedError('Not supported for hybrid composition.'); + } + + @override + Future<void> setOffset( + Offset offset, { + required int viewId, + required _AndroidViewState viewState, + }) { + throw UnimplementedError('Not supported for hybrid composition.'); + } + + @override + Future<void> sendDisposeMessage({required int viewId}) { + return SystemChannels.platform_views.invokeMethod<void>('dispose', <String, dynamic>{ + 'id': viewId, + 'hybrid': true, + }); + } +} + +/// Base class for iOS and macOS view controllers. +/// +/// View controllers are used to create and interact with the UIView or NSView +/// underlying a platform view. +abstract class DarwinPlatformViewController { + /// Public default for subclasses to override. + DarwinPlatformViewController( + this.id, + TextDirection layoutDirection, + ) : _layoutDirection = layoutDirection; + + /// The unique identifier of the iOS view controlled by this controller. + /// + /// This identifier is typically generated by + /// [PlatformViewsRegistry.getNextPlatformViewId]. + final int id; + + bool _debugDisposed = false; + + TextDirection _layoutDirection; + + /// Sets the layout direction for the iOS UIView. + Future<void> setLayoutDirection(TextDirection layoutDirection) async { + assert(!_debugDisposed, 'trying to set a layout direction for a disposed iOS UIView. View id: $id'); + + if (layoutDirection == _layoutDirection) { + return; + } + + _layoutDirection = layoutDirection; + + // TODO(amirh): invoke the iOS platform views channel direction method once available. + } + + /// Accept an active gesture. + /// + /// When a touch sequence is happening on the embedded UIView all touch events are delayed. + /// Calling this method releases the delayed events to the embedded UIView and makes it consume + /// any following touch events for the pointers involved in the active gesture. + Future<void> acceptGesture() { + final Map<String, dynamic> args = <String, dynamic>{ + 'id': id, + }; + return SystemChannels.platform_views.invokeMethod('acceptGesture', args); + } + + /// Rejects an active gesture. + /// + /// When a touch sequence is happening on the embedded UIView all touch events are delayed. + /// Calling this method drops the buffered touch events and prevents any future touch events for + /// the pointers that are part of the active touch sequence from arriving to the embedded view. + Future<void> rejectGesture() { + final Map<String, dynamic> args = <String, dynamic>{ + 'id': id, + }; + return SystemChannels.platform_views.invokeMethod('rejectGesture', args); + } + + /// Disposes the view. + /// + /// The [UiKitViewController] object is unusable after calling this. + /// The `id` of the platform view cannot be reused after the view is + /// disposed. + Future<void> dispose() async { + _debugDisposed = true; + await SystemChannels.platform_views.invokeMethod<void>('dispose', id); + PlatformViewsService._instance._focusCallbacks.remove(id); + } +} + +/// Controller for an iOS platform view. +/// +/// View controllers create and interact with the underlying UIView. +/// +/// Typically created with [PlatformViewsService.initUiKitView]. +class UiKitViewController extends DarwinPlatformViewController { + UiKitViewController._( + super.id, + super.layoutDirection, + ); +} + +/// Controller for a macOS platform view. +class AppKitViewController extends DarwinPlatformViewController { + AppKitViewController._( + super.id, + super.layoutDirection, + ); +} + +/// An interface for controlling a single platform view. +/// +/// Used by [PlatformViewSurface] to interface with the platform view it embeds. +abstract class PlatformViewController { + /// The viewId associated with this controller. + /// + /// The viewId should always be unique and non-negative. + /// + /// See also: + /// + /// * [PlatformViewsRegistry], which is a helper for managing platform view IDs. + int get viewId; + + /// True if [create] has not been successfully called the platform view. + /// + /// This can indicate either that [create] was never called, or that [create] + /// was deferred for implementation-specific reasons. + /// + /// A `false` return value does not necessarily indicate that the [Future] + /// returned by [create] has completed, only that creation has been started. + bool get awaitingCreation => false; + + /// Dispatches the `event` to the platform view. + Future<void> dispatchPointerEvent(PointerEvent event); + + /// Creates the platform view with the initial [size]. + /// + /// [size] is the view's initial size in logical pixel. + /// [size] can be omitted if the concrete implementation doesn't require an initial size + /// to create the platform view. + /// + /// [position] is the view's initial position in logical pixels. + /// [position] can be omitted if the concrete implementation doesn't require + /// an initial position. + Future<void> create({Size? size, Offset? position}) async {} + + /// Disposes the platform view. + /// + /// The [PlatformViewController] is unusable after calling dispose. + Future<void> dispose(); + + /// Clears the view's focus on the platform side. + Future<void> clearFocus(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/predictive_back_event.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/predictive_back_event.dart new file mode 100644 index 0000000000000000000000000000000000000000..f73cf51affa98dd26966084b07c43db686d418e5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/predictive_back_event.dart @@ -0,0 +1,115 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; + +/// Enum representing the edge from which a swipe starts in a back gesture. +/// +/// This is used in [PredictiveBackEvent] to indicate the starting edge of the +/// swipe gesture. +enum SwipeEdge { + /// Indicates that the swipe gesture starts from the left edge of the screen. + left, + + /// Indicates that the swipe gesture starts from the right edge of the screen. + right, +} + +/// Object used to report back gesture progress in Android. +/// +/// Holds information about the touch event, swipe direction, and the animation +/// progress that predictive back animations should follow. +@immutable +final class PredictiveBackEvent { + /// Creates a new [PredictiveBackEvent] instance. + const PredictiveBackEvent._({ + required this.touchOffset, + required this.progress, + required this.swipeEdge, + }) : assert(progress >= 0.0 && progress <= 1.0); + + /// Creates an [PredictiveBackEvent] from a Map, typically used when converting + /// data received from a platform channel. + factory PredictiveBackEvent.fromMap(Map<String?, Object?> map) { + final List<Object?>? touchOffset = map['touchOffset'] as List<Object?>?; + return PredictiveBackEvent._( + touchOffset: touchOffset == null + ? null + : Offset( + (touchOffset[0]! as num).toDouble(), + (touchOffset[1]! as num).toDouble(), + ), + progress: (map['progress']! as num).toDouble(), + swipeEdge: SwipeEdge.values[map['swipeEdge']! as int], + ); + } + + /// The global position of the touch point as an `Offset`, or `null` if the + /// event is triggered by a button press. + /// + /// This represents the touch location that initiates or interacts with the + /// back gesture. When `null`, it indicates the gesture was not started by a + /// touch event, such as a back button press in devices with hardware buttons. + final Offset? touchOffset; + + /// Returns a value between 0.0 and 1.0 representing how far along the back + /// gesture is. + /// + /// This value is driven by the horizontal location of the touch point, and + /// should be used as the fraction to seek the predictive back animation with. + /// Specifically, + /// + /// - The progress is 0.0 when the touch is at the starting edge of the screen + /// (left or right), and the animation should seek to its start state. + /// - The progress is approximately 1.0 when the touch is at the opposite side + /// of the screen, and the animation should seek to its end state. Exact end + /// value may vary depending on screen size. + /// + /// When the gesture is canceled, the progress value continues to update, + /// animating back to 0.0 until the cancellation animation completes. + /// + /// In-between locations are linearly interpolated based on horizontal + /// distance from the starting edge and smooth clamped to 1.0 when the + /// distance exceeds a system-wide threshold. + final double progress; + + /// The screen edge from which the swipe gesture starts. + final SwipeEdge swipeEdge; + + /// Indicates if the event was triggered by a system back button press. + /// + /// Returns false for a predictive back gesture. + bool get isButtonEvent => + // The Android documentation for BackEvent + // (https://developer.android.com/reference/android/window/BackEvent#getTouchX()) + // says that getTouchX and getTouchY should return NaN when the system + // back button is pressed, but in practice it seems to return 0.0, hence + // the check for Offset.zero here. This was tested directly in the engine + // on Android emulator running API 34. + touchOffset == null || (progress == 0.0 && touchOffset == Offset.zero); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is PredictiveBackEvent && + touchOffset == other.touchOffset && + progress == other.progress && + swipeEdge == other.swipeEdge; + } + + @override + int get hashCode => Object.hash(touchOffset, progress, swipeEdge); + + @override + String toString() { + return 'PredictiveBackEvent{touchOffset: $touchOffset, progress: $progress, swipeEdge: $swipeEdge}'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/process_text.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/process_text.dart new file mode 100644 index 0000000000000000000000000000000000000000..98abd9d27871bd09d6745841d2b782141d03af80 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/process_text.dart @@ -0,0 +1,145 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'system_channels.dart'; + +/// A data structure describing text processing actions. +@immutable +class ProcessTextAction { + /// Creates text processing actions based on those returned by the engine. + const ProcessTextAction(this.id, this.label); + + /// The action unique id. + final String id; + + /// The action localized label. + final String label; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is ProcessTextAction && + other.id == id && + other.label == label; + } + + @override + int get hashCode => Object.hash(id, label); +} + +/// Determines how to interact with the text processing feature. +abstract class ProcessTextService { + /// Returns a [Future] that resolves to a [List] of [ProcessTextAction]s + /// containing all text processing actions available. + /// + /// If there are no actions available, an empty list will be returned. + Future<List<ProcessTextAction>> queryTextActions(); + + /// Returns a [Future] that resolves to a [String] when the text action + /// returns a transformed text or null when the text action did not return + /// a transformed text. + /// + /// The `id` parameter is the text action unique identifier returned by + /// [queryTextActions]. + /// + /// The `text` parameter is the text to be processed. + /// + /// The `readOnly` parameter indicates that the transformed text, if it exists, + /// will be used as read-only. + Future<String?> processTextAction(String id, String text, bool readOnly); +} + +/// The service used by default for the text processing feature. +/// +/// Any widget may use this service to get a list of text processing actions +/// and send requests to activate these text actions. +/// +/// This is currently only supported on Android and it requires adding the +/// following '<queries>' element to the Android manifest file: +/// +/// <manifest ...> +/// <application ...> +/// ... +/// </application> +/// <!-- Required to query activities that can process text, see: +/// https://developer.android.com/training/package-visibility?hl=en and +/// https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT. +/// +/// In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. --> +/// <queries> +/// <intent> +/// <action android:name="android.intent.action.PROCESS_TEXT"/> +/// <data android:mimeType="text/plain"/> +/// </intent> +/// </queries> +/// </manifest> +/// +/// The '<queries>' element is part of the Android manifest file generated when +/// running the 'flutter create' command. +/// +/// If the '<queries>' element is not found, `queryTextActions()` will return an +/// empty list of `ProcessTextAction`. +/// +/// See also: +/// +/// * [ProcessTextService], the service that this implements. +class DefaultProcessTextService implements ProcessTextService { + /// Creates the default service to interact with the platform text processing + /// feature via communication over the text processing [MethodChannel]. + DefaultProcessTextService() { + _processTextChannel = SystemChannels.processText; + } + + /// The channel used to communicate with the engine side. + late MethodChannel _processTextChannel; + + /// Set the [MethodChannel] used to communicate with the engine text processing + /// feature. + /// + /// This is only meant for testing within the Flutter SDK. + @visibleForTesting + void setChannel(MethodChannel newChannel) { + assert(() { + _processTextChannel = newChannel; + return true; + }()); + } + + @override + Future<List<ProcessTextAction>> queryTextActions() async { + final List<ProcessTextAction> textActions = <ProcessTextAction>[]; + final Map<Object?, Object?>? rawResults; + + try { + rawResults = await _processTextChannel.invokeMethod( + 'ProcessText.queryTextActions', + ) as Map<Object?, Object?>; + } catch (e) { + return textActions; + } + + for (final Object? id in rawResults.keys) { + textActions.add(ProcessTextAction(id! as String, rawResults[id]! as String)); + } + + return textActions; + } + + @override + /// On Android, the readOnly parameter might be used by the targeted activity, see: + /// https://developer.android.com/reference/android/content/Intent#EXTRA_PROCESS_TEXT_READONLY. + Future<String?> processTextAction(String id, String text, bool readOnly) async { + final String? processedText = await _processTextChannel.invokeMethod( + 'ProcessText.processTextAction', + <dynamic>[id, text, readOnly], + ) as String?; + + return processedText; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard.dart new file mode 100644 index 0000000000000000000000000000000000000000..a2881c8171ead76cb5f29e992df3451ca68d68e2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard.dart @@ -0,0 +1,1090 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:io'; + +import 'package:flutter/foundation.dart'; + +import 'binding.dart'; +import 'hardware_keyboard.dart'; +import 'raw_keyboard_android.dart'; +import 'raw_keyboard_fuchsia.dart'; +import 'raw_keyboard_ios.dart'; +import 'raw_keyboard_linux.dart'; +import 'raw_keyboard_macos.dart'; +import 'raw_keyboard_web.dart'; +import 'raw_keyboard_windows.dart'; +import 'system_channels.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder, ValueChanged; + +export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey; + +/// An enum describing the side of the keyboard that a key is on, to allow +/// discrimination between which key is pressed (e.g. the left or right SHIFT +/// key). +/// +/// This enum is deprecated and will be removed. There is no direct substitute +/// planned, since this enum will no longer be necessary once [RawKeyEvent] and +/// associated APIs are removed. +/// +/// See also: +/// +/// * [RawKeyEventData.isModifierPressed], which accepts this enum as an +/// argument. +@Deprecated( + 'No longer supported. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +enum KeyboardSide { + /// Matches if either the left, right or both versions of the key are pressed. + any, + + /// Matches the left version of the key. + left, + + /// Matches the right version of the key. + right, + + /// Matches the left and right version of the key pressed simultaneously. + all, +} + +/// An enum describing the type of modifier key that is being pressed. +/// +/// This enum is deprecated and will be removed. There is no direct substitute +/// planned, since this enum will no longer be necessary once [RawKeyEvent] and +/// associated APIs are removed. +/// +/// See also: +/// +/// * [RawKeyEventData.isModifierPressed], which accepts this enum as an +/// argument. +@Deprecated( + 'No longer supported. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +enum ModifierKey { + /// The CTRL modifier key. + /// + /// Typically, there are two of these. + controlModifier, + + /// The SHIFT modifier key. + /// + /// Typically, there are two of these. + shiftModifier, + + /// The ALT modifier key. + /// + /// Typically, there are two of these. + altModifier, + + /// The META modifier key. + /// + /// Typically, there are two of these. This is, for example, the Windows key + /// on Windows (⊞), the Command (⌘) key on macOS and iOS, and the Search (🔍) + /// key on Android. + metaModifier, + + /// The CAPS LOCK modifier key. + /// + /// Typically, there is one of these. Only shown as "pressed" when the caps + /// lock is on, so on a key up when the mode is turned on, on each key press + /// when it's enabled, and on a key down when it is turned off. + capsLockModifier, + + /// The NUM LOCK modifier key. + /// + /// Typically, there is one of these. Only shown as "pressed" when the num + /// lock is on, so on a key up when the mode is turned on, on each key press + /// when it's enabled, and on a key down when it is turned off. + numLockModifier, + + /// The SCROLL LOCK modifier key. + /// + /// Typically, there is one of these. Only shown as "pressed" when the scroll + /// lock is on, so on a key up when the mode is turned on, on each key press + /// when it's enabled, and on a key down when it is turned off. + scrollLockModifier, + + /// The FUNCTION (Fn) modifier key. + /// + /// Typically, there is one of these. + functionModifier, + + /// The SYMBOL modifier key. + /// + /// Typically, there is one of these. + symbolModifier, +} + +/// Base class for platform-specific key event data. +/// +/// This class is deprecated, and will be removed. Platform specific key event +/// data will no be longer available. See [KeyEvent] for what is available. +/// +/// This base class exists to have a common type to use for each of the +/// target platform's key event data structures. +/// +/// See also: +/// +/// * [RawKeyEventDataAndroid], a specialization for Android. +/// * [RawKeyEventDataFuchsia], a specialization for Fuchsia. +/// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes that hold the +/// reference to [RawKeyEventData] subclasses. +/// * [RawKeyboard], which uses these interfaces to expose key data. +@Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +@immutable +abstract class RawKeyEventData with Diagnosticable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + @Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyEventData(); + + /// Returns true if the given [ModifierKey] was pressed at the time of this + /// event. + /// + /// This method is deprecated and will be removed. For equivalent information, + /// inspect [HardwareKeyboard.logicalKeysPressed] instead. + /// + /// If [side] is specified, then this restricts its check to the specified + /// side of the keyboard. Defaults to checking for the key being down on + /// either side of the keyboard. If there is only one instance of the key on + /// the keyboard, then [side] is ignored. + @Deprecated( + 'No longer available. Inspect HardwareKeyboard.instance.logicalKeysPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool isModifierPressed(ModifierKey key, { KeyboardSide side = KeyboardSide.any }); + + /// Returns a [KeyboardSide] enum value that describes which side or sides of + /// the given keyboard modifier key were pressed at the time of this event. + /// + /// This method is deprecated and will be removed. + /// + /// If the modifier key wasn't pressed at the time of this event, returns + /// null. If the given key only appears in one place on the keyboard, returns + /// [KeyboardSide.all] if pressed. If the given platform does not specify + /// the side, return [KeyboardSide.any]. + @Deprecated( + 'No longer available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + KeyboardSide? getModifierSide(ModifierKey key); + + /// Returns true if a CTRL modifier key was pressed at the time of this event, + /// regardless of which side of the keyboard it is on. + /// + /// This method is deprecated and will be removed. Use + /// [HardwareKeyboard.isControlPressed] instead. + /// + /// Use [isModifierPressed] if you need to know which control key was pressed. + @Deprecated( + 'Use HardwareKeyboard.instance.isControlPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool get isControlPressed => isModifierPressed(ModifierKey.controlModifier); + + /// Returns true if a SHIFT modifier key was pressed at the time of this + /// event, regardless of which side of the keyboard it is on. + /// + /// This method is deprecated and will be removed. Use + /// [HardwareKeyboard.isShiftPressed] instead. + /// + /// Use [isModifierPressed] if you need to know which shift key was pressed. + @Deprecated( + 'Use HardwareKeyboard.instance.isShiftPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool get isShiftPressed => isModifierPressed(ModifierKey.shiftModifier); + + /// Returns true if a ALT modifier key was pressed at the time of this event, + /// regardless of which side of the keyboard it is on. + /// + /// This method is deprecated and will be removed. Use + /// [HardwareKeyboard.isAltPressed] instead. + /// + /// Use [isModifierPressed] if you need to know which alt key was pressed. + @Deprecated( + 'Use HardwareKeyboard.instance.isAltPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool get isAltPressed => isModifierPressed(ModifierKey.altModifier); + + /// Returns true if a META modifier key was pressed at the time of this event, + /// regardless of which side of the keyboard it is on. + /// + /// This method is deprecated and will be removed. Use + /// [HardwareKeyboard.isMetaPressed] instead. + /// + /// Use [isModifierPressed] if you need to know which meta key was pressed. + @Deprecated( + 'Use HardwareKeyboard.instance.isMetaPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool get isMetaPressed => isModifierPressed(ModifierKey.metaModifier); + + /// Returns a map of modifier keys that were pressed at the time of this + /// event, and the keyboard side or sides that the key was on. + /// + /// This method is deprecated and will be removed. For equivalent information, + /// inspect [HardwareKeyboard.logicalKeysPressed] instead. + @Deprecated( + 'No longer available. Inspect HardwareKeyboard.instance.logicalKeysPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + Map<ModifierKey, KeyboardSide> get modifiersPressed { + final Map<ModifierKey, KeyboardSide> result = <ModifierKey, KeyboardSide>{}; + for (final ModifierKey key in ModifierKey.values) { + if (isModifierPressed(key)) { + final KeyboardSide? side = getModifierSide(key); + if (side != null) { + result[key] = side; + } + assert(() { + if (side == null) { + debugPrint( + 'Raw key data is returning inconsistent information for ' + 'pressed modifiers. isModifierPressed returns true for $key ' + 'being pressed, but when getModifierSide is called, it says ' + 'that no modifiers are pressed.', + ); + if (this is RawKeyEventDataAndroid) { + debugPrint('Android raw key metaState: ${(this as RawKeyEventDataAndroid).metaState}'); + } + } + return true; + }()); + } + } + return result; + } + + /// Returns an object representing the physical location of this key on a + /// QWERTY keyboard. + /// + /// {@macro flutter.services.RawKeyEvent.physicalKey} + /// + /// See also: + /// + /// * [logicalKey] for the non-location-specific key generated by this event. + /// * [RawKeyEvent.physicalKey], where this value is available on the event. + PhysicalKeyboardKey get physicalKey; + + /// Returns an object representing the logical key that was pressed. + /// + /// {@macro flutter.services.RawKeyEvent.logicalKey} + /// + /// See also: + /// + /// * [physicalKey] for the location-specific key generated by this event. + /// * [RawKeyEvent.logicalKey], where this value is available on the event. + LogicalKeyboardKey get logicalKey; + + /// Returns the Unicode string representing the label on this key. + /// + /// This value is an empty string if there's no key label data for a key. + /// + /// {@template flutter.services.RawKeyEventData.keyLabel} + /// Do not use the [keyLabel] to compose a text string: it will be missing + /// special processing for Unicode strings for combining characters and other + /// special characters, and the effects of modifiers. + /// + /// If you are looking for the character produced by a key event, use + /// [RawKeyEvent.character] instead. + /// + /// If you are composing text strings, use the [TextField] or + /// [CupertinoTextField] widgets, since those automatically handle many of the + /// complexities of managing keyboard input, like showing a soft keyboard or + /// interacting with an input method editor (IME). + /// {@endtemplate} + String get keyLabel; + + /// Whether a key down event, and likewise its accompanying key up event, + /// should be dispatched. + /// + /// Certain events on some platforms should not be dispatched to listeners + /// according to Flutter's event model. For example, on macOS, Fn keys are + /// skipped to be consistent with other platform. On Win32, events dispatched + /// for IME (`VK_PROCESSKEY`) are also skipped. + /// + /// This method will be called upon every down events. By default, this method + /// always return true. Subclasses should override this method to define the + /// filtering rule for the platform. If this method returns false for an event + /// message, the event will not be dispatched to listeners, but respond with + /// "handled: true" immediately. Moreover, the following up event with the + /// same physical key will also be skipped. + bool shouldDispatchEvent() { + return true; + } +} + +/// Defines the interface for raw key events. +/// +/// This type of event has been deprecated, and will be removed at a future +/// date. Instead of using this, use the [KeyEvent] class instead, which means +/// you will use [Focus.onKeyEvent], [HardwareKeyboard] and [KeyboardListener] +/// to get these events instead of the raw key event equivalents. +/// +/// Raw key events pass through as much information as possible from the +/// underlying platform's key events, which allows them to provide a high level +/// of fidelity but a low level of portability. +/// +/// The event also provides an abstraction for the [physicalKey] and the +/// [logicalKey], describing the physical location of the key, and the logical +/// meaning of the key, respectively. These are more portable representations of +/// the key events, and should produce the same results regardless of platform. +/// +/// See also: +/// +/// * [LogicalKeyboardKey], an object that describes the logical meaning of a +/// key. +/// * [PhysicalKeyboardKey], an object that describes the physical location of a +/// key. +/// * [RawKeyDownEvent], a specialization for events representing the user +/// pressing a key. +/// * [RawKeyUpEvent], a specialization for events representing the user +/// releasing a key. +/// * [RawKeyboard], which uses this interface to expose key data. +/// * [RawKeyboardListener], a widget that listens for raw key events. +@Deprecated( + 'Use KeyEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +@immutable +abstract class RawKeyEvent with Diagnosticable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + @Deprecated( + 'Use KeyEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyEvent({ + required this.data, + this.character, + this.repeat = false, + }); + + /// Creates a concrete [RawKeyEvent] class from a message in the form received + /// on the [SystemChannels.keyEvent] channel. + /// + /// [RawKeyEvent.repeat] will be derived from the current keyboard state, + /// instead of using the message information. + @Deprecated( + 'No longer supported. Use KeyEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + factory RawKeyEvent.fromMessage(Map<String, Object?> message) { + String? character; + RawKeyEventData dataFromWeb() { + final String? key = message['key'] as String?; + if (key != null && key.isNotEmpty && key.length == 1) { + character = key; + } + return RawKeyEventDataWeb( + code: message['code'] as String? ?? '', + key: key ?? '', + location: message['location'] as int? ?? 0, + metaState: message['metaState'] as int? ?? 0, + keyCode: message['keyCode'] as int? ?? 0, + ); + } + + final RawKeyEventData data; + if (kIsWeb) { + data = dataFromWeb(); + } else { + final String keymap = message['keymap']! as String; + switch (keymap) { + case 'android': + data = RawKeyEventDataAndroid( + flags: message['flags'] as int? ?? 0, + codePoint: message['codePoint'] as int? ?? 0, + keyCode: message['keyCode'] as int? ?? 0, + plainCodePoint: message['plainCodePoint'] as int? ?? 0, + scanCode: message['scanCode'] as int? ?? 0, + metaState: message['metaState'] as int? ?? 0, + eventSource: message['source'] as int? ?? 0, + vendorId: message['vendorId'] as int? ?? 0, + productId: message['productId'] as int? ?? 0, + deviceId: message['deviceId'] as int? ?? 0, + repeatCount: message['repeatCount'] as int? ?? 0, + ); + if (message.containsKey('character')) { + character = message['character'] as String?; + } + case 'fuchsia': + final int codePoint = message['codePoint'] as int? ?? 0; + data = RawKeyEventDataFuchsia( + hidUsage: message['hidUsage'] as int? ?? 0, + codePoint: codePoint, + modifiers: message['modifiers'] as int? ?? 0, + ); + if (codePoint != 0) { + character = String.fromCharCode(codePoint); + } + case 'macos': + data = RawKeyEventDataMacOs( + characters: message['characters'] as String? ?? '', + charactersIgnoringModifiers: message['charactersIgnoringModifiers'] as String? ?? '', + keyCode: message['keyCode'] as int? ?? 0, + modifiers: message['modifiers'] as int? ?? 0, + specifiedLogicalKey: message['specifiedLogicalKey'] as int?, + ); + character = message['characters'] as String?; + case 'ios': + data = RawKeyEventDataIos( + characters: message['characters'] as String? ?? '', + charactersIgnoringModifiers: message['charactersIgnoringModifiers'] as String? ?? '', + keyCode: message['keyCode'] as int? ?? 0, + modifiers: message['modifiers'] as int? ?? 0, + ); + final Object? characters = message['characters']; + if (characters is String && characters.isNotEmpty) { + character = characters; + } + case 'linux': + final int unicodeScalarValues = message['unicodeScalarValues'] as int? ?? 0; + data = RawKeyEventDataLinux( + keyHelper: KeyHelper(message['toolkit'] as String? ?? ''), + unicodeScalarValues: unicodeScalarValues, + keyCode: message['keyCode'] as int? ?? 0, + scanCode: message['scanCode'] as int? ?? 0, + modifiers: message['modifiers'] as int? ?? 0, + isDown: message['type'] == 'keydown', + specifiedLogicalKey: message['specifiedLogicalKey'] as int?, + ); + if (unicodeScalarValues != 0) { + character = String.fromCharCode(unicodeScalarValues); + } + case 'windows': + final int characterCodePoint = message['characterCodePoint'] as int? ?? 0; + data = RawKeyEventDataWindows( + keyCode: message['keyCode'] as int? ?? 0, + scanCode: message['scanCode'] as int? ?? 0, + characterCodePoint: characterCodePoint, + modifiers: message['modifiers'] as int? ?? 0, + ); + if (characterCodePoint != 0) { + character = String.fromCharCode(characterCodePoint); + } + case 'web': + data = dataFromWeb(); + default: + /// This exception would only be hit on platforms that haven't yet + /// implemented raw key events, but will only be triggered if the + /// engine for those platforms sends raw key event messages in the + /// first place. + throw FlutterError('Unknown keymap for key events: $keymap'); + } + } + final bool repeat = RawKeyboard.instance.physicalKeysPressed.contains(data.physicalKey); + final String type = message['type']! as String; + switch (type) { + case 'keydown': + return RawKeyDownEvent(data: data, character: character, repeat: repeat); + case 'keyup': + return RawKeyUpEvent(data: data); + default: + throw FlutterError('Unknown key event type: $type'); + } + } + + /// Returns true if the given [LogicalKeyboardKey] is pressed. + /// + /// This method is deprecated and will be removed. Use + /// [HardwareKeyboard.isLogicalKeyPressed] instead. + @Deprecated( + 'Use HardwareKeyboard.instance.isLogicalKeyPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool isKeyPressed(LogicalKeyboardKey key) => RawKeyboard.instance.keysPressed.contains(key); + + /// Returns true if a CTRL modifier key is pressed, regardless of which side + /// of the keyboard it is on. + /// + /// This method is deprecated and will be removed. Use + /// [HardwareKeyboard.isControlPressed] instead. + /// + /// Use [isKeyPressed] if you need to know which control key was pressed. + @Deprecated( + 'Use HardwareKeyboard.instance.isControlPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool get isControlPressed { + return isKeyPressed(LogicalKeyboardKey.controlLeft) || isKeyPressed(LogicalKeyboardKey.controlRight); + } + + /// Returns true if a SHIFT modifier key is pressed, regardless of which side + /// of the keyboard it is on. + /// + /// This method is deprecated and will be removed. Use + /// [HardwareKeyboard.isShiftPressed] instead. + /// + /// Use [isKeyPressed] if you need to know which shift key was pressed. + @Deprecated( + 'Use HardwareKeyboard.instance.isShiftPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool get isShiftPressed { + return isKeyPressed(LogicalKeyboardKey.shiftLeft) || isKeyPressed(LogicalKeyboardKey.shiftRight); + } + + /// Returns true if a ALT modifier key is pressed, regardless of which side + /// of the keyboard it is on. + /// + /// This method is deprecated and will be removed. Use + /// [HardwareKeyboard.isAltPressed] instead. + /// + /// The `AltGr` key that appears on some keyboards is considered to be + /// the same as [LogicalKeyboardKey.altRight] on some platforms (notably + /// Android). On platforms that can distinguish between `altRight` and + /// `altGr`, a press of `AltGr` will not return true here, and will need to be + /// tested for separately. + /// + /// Use [isKeyPressed] if you need to know which alt key was pressed. + @Deprecated( + 'Use HardwareKeyboard.instance.isAltPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool get isAltPressed { + return isKeyPressed(LogicalKeyboardKey.altLeft) || isKeyPressed(LogicalKeyboardKey.altRight); + } + + /// Returns true if a META modifier key is pressed, regardless of which side + /// of the keyboard it is on. + /// + /// This method is deprecated and will be removed. Use + /// [HardwareKeyboard.isMetaPressed] instead. + /// + /// Use [isKeyPressed] if you need to know which meta key was pressed. + @Deprecated( + 'Use HardwareKeyboard.instance.isMetaPressed instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool get isMetaPressed { + return isKeyPressed(LogicalKeyboardKey.metaLeft) || isKeyPressed(LogicalKeyboardKey.metaRight); + } + + /// Returns an object representing the physical location of this key. + /// + /// {@template flutter.services.RawKeyEvent.physicalKey} + /// The [PhysicalKeyboardKey] ignores the key map, modifier keys (like SHIFT), + /// and the label on the key. It describes the location of the key as if it + /// were on a QWERTY keyboard regardless of the keyboard mapping in effect. + /// + /// [PhysicalKeyboardKey]s are used to describe and test for keys in a + /// particular location. + /// + /// For instance, if you wanted to make a game where the key to the right of + /// the CAPS LOCK key made the player move left, you would be comparing the + /// result of this [physicalKey] with [PhysicalKeyboardKey.keyA], since that + /// is the key next to the CAPS LOCK key on a QWERTY keyboard. This would + /// return the same thing even on a French keyboard where the key next to the + /// CAPS LOCK produces a "Q" when pressed. + /// + /// If you want to make your app respond to a key with a particular character + /// on it regardless of location of the key, use [RawKeyEvent.logicalKey] instead. + /// {@endtemplate} + /// + /// See also: + /// + /// * [logicalKey] for the non-location specific key generated by this event. + /// * [character] for the character generated by this keypress (if any). + PhysicalKeyboardKey get physicalKey => data.physicalKey; + + /// Returns an object representing the logical key that was pressed. + /// + /// {@template flutter.services.RawKeyEvent.logicalKey} + /// This method takes into account the key map and modifier keys (like SHIFT) + /// to determine which logical key to return. + /// + /// If you are looking for the character produced by a key event, use + /// [RawKeyEvent.character] instead. + /// + /// If you are collecting text strings, use the [TextField] or + /// [CupertinoTextField] widgets, since those automatically handle many of the + /// complexities of managing keyboard input, like showing a soft keyboard or + /// interacting with an input method editor (IME). + /// {@endtemplate} + LogicalKeyboardKey get logicalKey => data.logicalKey; + + /// Returns the Unicode character (grapheme cluster) completed by this + /// keystroke, if any. + /// + /// This will only return a character if this keystroke, combined with any + /// preceding keystroke(s), generated a character, and only on a "key down" + /// event. It will return null if no character has been generated by the + /// keystroke (e.g. a "dead" or "combining" key), or if the corresponding key + /// is a key without a visual representation, such as a modifier key or a + /// control key. + /// + /// This can return multiple Unicode code points, since some characters (more + /// accurately referred to as grapheme clusters) are made up of more than one + /// code point. + /// + /// The [character] doesn't take into account edits by an input method editor + /// (IME), or manage the visibility of the soft keyboard on touch devices. For + /// composing text, use the [TextField] or [CupertinoTextField] widgets, since + /// those automatically handle many of the complexities of managing keyboard + /// input. + final String? character; + + /// Whether this is a repeated down event. + /// + /// When a key is held down, the systems usually fire a down event and then + /// a series of repeated down events. The [repeat] is false for the + /// first event and true for the following events. + /// + /// The [repeat] attribute is always false for [RawKeyUpEvent]s. + final bool repeat; + + /// Platform-specific information about the key event. + final RawKeyEventData data; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<LogicalKeyboardKey>('logicalKey', logicalKey)); + properties.add(DiagnosticsProperty<PhysicalKeyboardKey>('physicalKey', physicalKey)); + if (this is RawKeyDownEvent) { + properties.add(DiagnosticsProperty<bool>('repeat', repeat)); + } + } +} + +/// The user has pressed a key on the keyboard. +/// +/// This class has been deprecated and will be removed. Use [KeyDownEvent] +/// instead. +/// +/// See also: +/// +/// * [RawKeyboard], which uses this interface to expose key data. +@Deprecated( + 'Use KeyDownEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class RawKeyDownEvent extends RawKeyEvent { + /// Creates a key event that represents the user pressing a key. + @Deprecated( + 'Use KeyDownEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyDownEvent({ + required super.data, + super.character, + super.repeat, + }); +} + +/// The user has released a key on the keyboard. +/// +/// This class has been deprecated and will be removed. Use [KeyUpEvent] +/// instead. +/// +/// See also: +/// +/// * [RawKeyboard], which uses this interface to expose key data. +@Deprecated( + 'Use KeyUpEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class RawKeyUpEvent extends RawKeyEvent { + /// Creates a key event that represents the user releasing a key. + @Deprecated( + 'Use KeyUpEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyUpEvent({ + required super.data, + super.character, + }) : super(repeat: false); +} + +/// A callback type used by [RawKeyboard.keyEventHandler] to send key events to +/// a handler that can determine if the key has been handled or not. +/// +/// This typedef has been deprecated and will be removed. Use [KeyEventCallback] +/// instead. +/// +/// The handler should return true if the key has been handled, and false if the +/// key was not handled. It must not return null. +@Deprecated( + 'Use KeyEventCallback instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +typedef RawKeyEventHandler = bool Function(RawKeyEvent event); + +/// An interface for listening to raw key events. +/// +/// This class is deprecated and will be removed at a future date. The +/// [HardwareKeyboard] class is its replacement. +/// +/// Raw key events pass through as much information as possible from the +/// underlying platform's key events, which makes them provide a high level of +/// fidelity but a low level of portability. +/// +/// A [RawKeyboard] is useful for listening to raw key events and hardware +/// buttons that are represented as keys. Typically used by games and other apps +/// that use keyboards for purposes other than text entry. +/// +/// These key events are typically only key events generated by a hardware +/// keyboard, and not those from software keyboards or input method editors. +/// +/// ## Compared to [HardwareKeyboard] +/// +/// Behavior-wise, [RawKeyboard] provides a less unified, less regular event +/// model than [HardwareKeyboard]. For example: +/// +/// * Down events might not be matched with an up event, and vice versa (the set +/// of pressed keys is silently updated). +/// * The logical key of the down event might not be the same as that of the up +/// event. +/// * Down events and repeat events are not easily distinguishable (must be +/// tracked manually). +/// * Lock modes (such as CapsLock) only have their "enabled" state recorded. +/// There's no way to acquire their pressing state. +/// +/// See also: +/// +/// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes used to describe +/// specific raw key events. +/// * [RawKeyboardListener], a widget that listens for raw key events. +/// * [SystemChannels.keyEvent], the low-level channel used for receiving events +/// from the system. +/// * [HardwareKeyboard], the recommended replacement. +@Deprecated( + 'Use HardwareKeyboard instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class RawKeyboard { + @Deprecated( + 'Use HardwareKeyboard instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + RawKeyboard._(); + + /// The shared instance of [RawKeyboard]. + @Deprecated( + 'Use HardwareKeyboard.instance instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + static final RawKeyboard instance = RawKeyboard._(); + + final List<ValueChanged<RawKeyEvent>> _listeners = <ValueChanged<RawKeyEvent>>[]; + + /// Register a listener that is called every time the user presses or releases + /// a hardware keyboard key. + /// + /// Since the listeners have no way to indicate what they did with the event, + /// listeners are assumed to not handle the key event. These events will also + /// be distributed to other listeners, and to the [keyEventHandler]. + /// + /// Most applications prefer to use the focus system (see [Focus] and + /// [FocusManager]) to receive key events to the focused control instead of + /// this kind of passive listener. + /// + /// Listeners can be removed with [removeListener]. + void addListener(ValueChanged<RawKeyEvent> listener) { + _listeners.add(listener); + } + + /// Stop calling the given listener every time the user presses or releases a + /// hardware keyboard key. + /// + /// Listeners can be added with [addListener]. + void removeListener(ValueChanged<RawKeyEvent> listener) { + _listeners.remove(listener); + } + + /// A handler for raw hardware keyboard events that will stop propagation if + /// the handler returns true. + /// + /// This property is only a wrapper over [KeyEventManager.keyMessageHandler], + /// and is kept only for backward compatibility. New code should use + /// [KeyEventManager.keyMessageHandler] to set custom global key event + /// handler. Setting [keyEventHandler] will cause + /// [KeyEventManager.keyMessageHandler] to be set with a converted handler. + /// If [KeyEventManager.keyMessageHandler] is set by [FocusManager] (the most + /// common situation), then the exact value of [keyEventHandler] is a dummy + /// callback and must not be invoked. + RawKeyEventHandler? get keyEventHandler { + if (ServicesBinding.instance.keyEventManager.keyMessageHandler != _cachedKeyMessageHandler) { + _cachedKeyMessageHandler = ServicesBinding.instance.keyEventManager.keyMessageHandler; + _cachedKeyEventHandler = _cachedKeyMessageHandler == null ? + null : + (RawKeyEvent event) { + assert(false, + 'The RawKeyboard.instance.keyEventHandler assigned by Flutter is a dummy ' + 'callback kept for compatibility and should not be directly called. Use ' + 'ServicesBinding.instance!.keyMessageHandler instead.'); + return true; + }; + } + return _cachedKeyEventHandler; + } + RawKeyEventHandler? _cachedKeyEventHandler; + KeyMessageHandler? _cachedKeyMessageHandler; + set keyEventHandler(RawKeyEventHandler? handler) { + _cachedKeyEventHandler = handler; + _cachedKeyMessageHandler = handler == null ? + null : + (KeyMessage message) { + if (message.rawEvent != null) { + return handler(message.rawEvent!); + } + return false; + }; + ServicesBinding.instance.keyEventManager.keyMessageHandler = _cachedKeyMessageHandler; + } + + /// Process a new [RawKeyEvent] by recording the state changes and + /// dispatching to listeners. + bool handleRawKeyEvent(RawKeyEvent event) { + if (event is RawKeyDownEvent) { + _keysPressed[event.physicalKey] = event.logicalKey; + } else if (event is RawKeyUpEvent) { + // Use the physical key in the key up event to find the physical key from + // the corresponding key down event and remove it, even if the logical + // keys don't match. + _keysPressed.remove(event.physicalKey); + } + // Make sure that the modifiers reflect reality, in case a modifier key was + // pressed/released while the app didn't have focus. + _synchronizeModifiers(event); + assert( + event is! RawKeyDownEvent || _keysPressed.isNotEmpty, + 'Attempted to send a key down event when no keys are in keysPressed. ' + "This state can occur if the key event being sent doesn't properly " + 'set its modifier flags. This was the event: $event and its data: ' + '${event.data}', + ); + // Send the event to passive listeners. + for (final ValueChanged<RawKeyEvent> listener in List<ValueChanged<RawKeyEvent>>.of(_listeners)) { + try { + if (_listeners.contains(listener)) { + listener(event); + } + } catch (exception, stack) { + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<RawKeyEvent>('Event', event), + ]; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'services library', + context: ErrorDescription('while processing a raw key listener'), + informationCollector: collector, + )); + } + } + + return false; + } + + static final Map<_ModifierSidePair, Set<PhysicalKeyboardKey>> _modifierKeyMap = <_ModifierSidePair, Set<PhysicalKeyboardKey>>{ + const _ModifierSidePair(ModifierKey.altModifier, KeyboardSide.left): <PhysicalKeyboardKey>{PhysicalKeyboardKey.altLeft}, + const _ModifierSidePair(ModifierKey.altModifier, KeyboardSide.right): <PhysicalKeyboardKey>{PhysicalKeyboardKey.altRight}, + const _ModifierSidePair(ModifierKey.altModifier, KeyboardSide.all): <PhysicalKeyboardKey>{PhysicalKeyboardKey.altLeft, PhysicalKeyboardKey.altRight}, + const _ModifierSidePair(ModifierKey.altModifier, KeyboardSide.any): <PhysicalKeyboardKey>{PhysicalKeyboardKey.altLeft}, + const _ModifierSidePair(ModifierKey.shiftModifier, KeyboardSide.left): <PhysicalKeyboardKey>{PhysicalKeyboardKey.shiftLeft}, + const _ModifierSidePair(ModifierKey.shiftModifier, KeyboardSide.right): <PhysicalKeyboardKey>{PhysicalKeyboardKey.shiftRight}, + const _ModifierSidePair(ModifierKey.shiftModifier, KeyboardSide.all): <PhysicalKeyboardKey>{PhysicalKeyboardKey.shiftLeft, PhysicalKeyboardKey.shiftRight}, + const _ModifierSidePair(ModifierKey.shiftModifier, KeyboardSide.any): <PhysicalKeyboardKey>{PhysicalKeyboardKey.shiftLeft}, + const _ModifierSidePair(ModifierKey.controlModifier, KeyboardSide.left): <PhysicalKeyboardKey>{PhysicalKeyboardKey.controlLeft}, + const _ModifierSidePair(ModifierKey.controlModifier, KeyboardSide.right): <PhysicalKeyboardKey>{PhysicalKeyboardKey.controlRight}, + const _ModifierSidePair(ModifierKey.controlModifier, KeyboardSide.all): <PhysicalKeyboardKey>{PhysicalKeyboardKey.controlLeft, PhysicalKeyboardKey.controlRight}, + const _ModifierSidePair(ModifierKey.controlModifier, KeyboardSide.any): <PhysicalKeyboardKey>{PhysicalKeyboardKey.controlLeft}, + const _ModifierSidePair(ModifierKey.metaModifier, KeyboardSide.left): <PhysicalKeyboardKey>{PhysicalKeyboardKey.metaLeft}, + const _ModifierSidePair(ModifierKey.metaModifier, KeyboardSide.right): <PhysicalKeyboardKey>{PhysicalKeyboardKey.metaRight}, + const _ModifierSidePair(ModifierKey.metaModifier, KeyboardSide.all): <PhysicalKeyboardKey>{PhysicalKeyboardKey.metaLeft, PhysicalKeyboardKey.metaRight}, + const _ModifierSidePair(ModifierKey.metaModifier, KeyboardSide.any): <PhysicalKeyboardKey>{PhysicalKeyboardKey.metaLeft}, + const _ModifierSidePair(ModifierKey.capsLockModifier, KeyboardSide.all): <PhysicalKeyboardKey>{PhysicalKeyboardKey.capsLock}, + const _ModifierSidePair(ModifierKey.numLockModifier, KeyboardSide.all): <PhysicalKeyboardKey>{PhysicalKeyboardKey.numLock}, + const _ModifierSidePair(ModifierKey.scrollLockModifier, KeyboardSide.all): <PhysicalKeyboardKey>{PhysicalKeyboardKey.scrollLock}, + const _ModifierSidePair(ModifierKey.functionModifier, KeyboardSide.all): <PhysicalKeyboardKey>{PhysicalKeyboardKey.fn}, + // The symbolModifier doesn't have a key representation on any of the + // platforms, so don't map it here. + }; + + // The map of all modifier keys except Fn, since that is treated differently + // on some platforms. + static final Map<PhysicalKeyboardKey, LogicalKeyboardKey> _allModifiersExceptFn = <PhysicalKeyboardKey, LogicalKeyboardKey>{ + PhysicalKeyboardKey.altLeft: LogicalKeyboardKey.altLeft, + PhysicalKeyboardKey.altRight: LogicalKeyboardKey.altRight, + PhysicalKeyboardKey.shiftLeft: LogicalKeyboardKey.shiftLeft, + PhysicalKeyboardKey.shiftRight: LogicalKeyboardKey.shiftRight, + PhysicalKeyboardKey.controlLeft: LogicalKeyboardKey.controlLeft, + PhysicalKeyboardKey.controlRight: LogicalKeyboardKey.controlRight, + PhysicalKeyboardKey.metaLeft: LogicalKeyboardKey.metaLeft, + PhysicalKeyboardKey.metaRight: LogicalKeyboardKey.metaRight, + PhysicalKeyboardKey.capsLock: LogicalKeyboardKey.capsLock, + PhysicalKeyboardKey.numLock: LogicalKeyboardKey.numLock, + PhysicalKeyboardKey.scrollLock: LogicalKeyboardKey.scrollLock, + }; + + // The map of all modifier keys that are represented in modifier key bit + // masks on all platforms, so that they can be cleared out of pressedKeys when + // synchronizing. + static final Map<PhysicalKeyboardKey, LogicalKeyboardKey> _allModifiers = <PhysicalKeyboardKey, LogicalKeyboardKey>{ + PhysicalKeyboardKey.fn: LogicalKeyboardKey.fn, + ..._allModifiersExceptFn, + }; + + void _synchronizeModifiers(RawKeyEvent event) { + // Compare modifier states to the ground truth as specified by + // [RawKeyEvent.data.modifiersPressed] and update unsynchronized ones. + // + // This function will update the state of modifier keys in `_keysPressed` so + // that they match the ones given by [RawKeyEvent.data.modifiersPressed]. + // For a `modifiersPressed` result of anything but [KeyboardSide.any], the + // states in `_keysPressed` will be updated to exactly match the result, + // i.e. exactly one of "no down", "left down", "right down" or "both down". + // + // If `modifiersPressed` returns [KeyboardSide.any], the states in + // `_keysPressed` will be updated to a rough match, i.e. "either side down" + // or "no down". If `_keysPressed` has no modifier down, a + // [KeyboardSide.any] will synchronize by forcing the left modifier down. If + // `_keysPressed` has any modifier down, a [KeyboardSide.any] will not cause + // a state change. + + final Map<ModifierKey, KeyboardSide?> modifiersPressed = event.data.modifiersPressed; + final Map<PhysicalKeyboardKey, LogicalKeyboardKey> modifierKeys = <PhysicalKeyboardKey, LogicalKeyboardKey>{}; + // Physical keys that whose modifiers are pressed at any side. + final Set<PhysicalKeyboardKey> anySideKeys = <PhysicalKeyboardKey>{}; + final Set<PhysicalKeyboardKey> keysPressedAfterEvent = <PhysicalKeyboardKey>{ + ..._keysPressed.keys, + if (event is RawKeyDownEvent) event.physicalKey, + }; + ModifierKey? thisKeyModifier; + for (final ModifierKey key in ModifierKey.values) { + final Set<PhysicalKeyboardKey>? thisModifierKeys = _modifierKeyMap[_ModifierSidePair(key, KeyboardSide.all)]; + if (thisModifierKeys == null) { + continue; + } + if (thisModifierKeys.contains(event.physicalKey)) { + thisKeyModifier = key; + } + if (modifiersPressed[key] == KeyboardSide.any) { + anySideKeys.addAll(thisModifierKeys); + if (thisModifierKeys.any(keysPressedAfterEvent.contains)) { + continue; + } + } + final Set<PhysicalKeyboardKey>? mappedKeys = modifiersPressed[key] == null ? + <PhysicalKeyboardKey>{} : _modifierKeyMap[_ModifierSidePair(key, modifiersPressed[key])]; + assert(() { + if (mappedKeys == null) { + debugPrint( + 'Platform key support for ${Platform.operatingSystem} is ' + 'producing unsupported modifier combinations for ' + 'modifier $key on side ${modifiersPressed[key]}.', + ); + if (event.data is RawKeyEventDataAndroid) { + debugPrint('Android raw key metaState: ${(event.data as RawKeyEventDataAndroid).metaState}'); + } + } + return true; + }()); + if (mappedKeys == null) { + continue; + } + for (final PhysicalKeyboardKey physicalModifier in mappedKeys) { + modifierKeys[physicalModifier] = _allModifiers[physicalModifier]!; + } + } + // On Linux, CapsLock key can be mapped to a non-modifier logical key: + // https://github.com/flutter/flutter/issues/114591. + // This is also affecting Flutter Web on Linux. + final bool nonModifierCapsLock = (event.data is RawKeyEventDataLinux || event.data is RawKeyEventDataWeb) + && _keysPressed[PhysicalKeyboardKey.capsLock] != null + && _keysPressed[PhysicalKeyboardKey.capsLock] != LogicalKeyboardKey.capsLock; + for (final PhysicalKeyboardKey physicalKey in _allModifiersExceptFn.keys) { + final bool skipReleasingKey = nonModifierCapsLock && physicalKey == PhysicalKeyboardKey.capsLock; + if (!anySideKeys.contains(physicalKey) && !skipReleasingKey) { + _keysPressed.remove(physicalKey); + } + } + if (event.data is! RawKeyEventDataFuchsia && event.data is! RawKeyEventDataMacOs) { + // On Fuchsia and macOS, the Fn key is not considered a modifier key. + _keysPressed.remove(PhysicalKeyboardKey.fn); + } + _keysPressed.addAll(modifierKeys); + // In rare cases, the event presses a modifier key but the key does not + // exist in the modifier list. Enforce the pressing state. + if (event is RawKeyDownEvent && thisKeyModifier != null + && !_keysPressed.containsKey(event.physicalKey)) { + // This inconsistency is found on Linux GTK for AltRight: + // https://github.com/flutter/flutter/issues/93278 + // And also on Android and iOS: + // https://github.com/flutter/flutter/issues/101090 + if ((event.data is RawKeyEventDataLinux && event.physicalKey == PhysicalKeyboardKey.altRight) + || event.data is RawKeyEventDataIos + || event.data is RawKeyEventDataAndroid) { + final LogicalKeyboardKey? logicalKey = _allModifiersExceptFn[event.physicalKey]; + if (logicalKey != null) { + _keysPressed[event.physicalKey] = logicalKey; + } + } + // On Web, PhysicalKeyboardKey.altRight can be map to LogicalKeyboardKey.altGraph or + // LogicalKeyboardKey.altRight: + // https://github.com/flutter/flutter/issues/113836 + if (event.data is RawKeyEventDataWeb && event.physicalKey == PhysicalKeyboardKey.altRight) { + _keysPressed[event.physicalKey] = event.logicalKey; + } + } + } + + final Map<PhysicalKeyboardKey, LogicalKeyboardKey> _keysPressed = <PhysicalKeyboardKey, LogicalKeyboardKey>{}; + + /// Returns the set of keys currently pressed. + Set<LogicalKeyboardKey> get keysPressed => _keysPressed.values.toSet(); + + /// Returns the set of physical keys currently pressed. + Set<PhysicalKeyboardKey> get physicalKeysPressed => _keysPressed.keys.toSet(); + + /// Returns the logical key that corresponds to the given pressed physical key. + /// + /// Returns null if the physical key is not currently pressed. + LogicalKeyboardKey? lookUpLayout(PhysicalKeyboardKey physicalKey) => _keysPressed[physicalKey]; + + /// Clears the list of keys returned from [keysPressed]. + /// + /// This is used by the testing framework to make sure tests are hermetic. + @visibleForTesting + void clearKeysPressed() => _keysPressed.clear(); +} + +@immutable +class _ModifierSidePair { + const _ModifierSidePair(this.modifier, this.side); + + final ModifierKey modifier; + final KeyboardSide? side; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _ModifierSidePair + && other.modifier == modifier + && other.side == side; + } + + @override + int get hashCode => Object.hash(modifier, side); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_android.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_android.dart new file mode 100644 index 0000000000000000000000000000000000000000..9f7b1bbc859239f1594ea8f2441095fc06d66227 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_android.dart @@ -0,0 +1,476 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'keyboard_maps.g.dart'; +import 'raw_keyboard.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; + +export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey; + +// Android sets the 0x80000000 bit on a character to indicate that it is a +// combining character, so we use this mask to remove that bit to make it a +// valid Unicode character again. +const int _kCombiningCharacterMask = 0x7fffffff; + +/// Platform-specific key event data for Android. +/// +/// This class is deprecated and will be removed. Platform specific key event +/// data will no longer be available. See [KeyEvent] for what is available. +/// +/// This object contains information about key events obtained from Android's +/// `KeyEvent` interface. +/// +/// See also: +/// +/// * [RawKeyboard], which uses this interface to expose key data. +@Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class RawKeyEventDataAndroid extends RawKeyEventData { + /// Creates a key event data structure specific for Android. + @Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyEventDataAndroid({ + this.flags = 0, + this.codePoint = 0, + this.plainCodePoint = 0, + this.keyCode = 0, + this.scanCode = 0, + this.metaState = 0, + this.eventSource = 0, + this.vendorId = 0, + this.productId = 0, + this.deviceId = 0, + this.repeatCount = 0, + }); + + /// The current set of additional flags for this event. + /// + /// Flags indicate things like repeat state, etc. + /// + /// See <https://developer.android.com/reference/android/view/KeyEvent.html#getFlags()> + /// for more information. + final int flags; + + /// The Unicode code point represented by the key event, if any. + /// + /// If there is no Unicode code point, this value is zero. + /// + /// Dead keys are represented as Unicode combining characters. + /// + /// See <https://developer.android.com/reference/android/view/KeyEvent.html#getUnicodeChar()> + /// for more information. + final int codePoint; + + /// The Unicode code point represented by the key event, if any, without + /// regard to any modifier keys which are currently pressed. + /// + /// If there is no Unicode code point, this value is zero. + /// + /// Dead keys are represented as Unicode combining characters. + /// + /// This is the result of calling KeyEvent.getUnicodeChar(0) on Android. + /// + /// See <https://developer.android.com/reference/android/view/KeyEvent.html#getUnicodeChar(int)> + /// for more information. + final int plainCodePoint; + + /// The hardware key code corresponding to this key event. + /// + /// This is the physical key that was pressed, not the Unicode character. + /// See [codePoint] for the Unicode character. + /// + /// See <https://developer.android.com/reference/android/view/KeyEvent.html#getKeyCode()> + /// for more information. + final int keyCode; + + /// The hardware scan code id corresponding to this key event. + /// + /// These values are not reliable and vary from device to device, so this + /// information is mainly useful for debugging. + /// + /// See <https://developer.android.com/reference/android/view/KeyEvent.html#getScanCode()> + /// for more information. + final int scanCode; + + /// The modifiers that were present when the key event occurred. + /// + /// See <https://developer.android.com/reference/android/view/KeyEvent.html#getMetaState()> + /// for the numerical values of the [metaState]. Many of these constants are + /// also replicated as static constants in this class. + /// + /// See also: + /// + /// * [modifiersPressed], which returns a Map of currently pressed modifiers + /// and their keyboard side. + /// * [isModifierPressed], to see if a specific modifier is pressed. + /// * [isControlPressed], to see if a CTRL key is pressed. + /// * [isShiftPressed], to see if a SHIFT key is pressed. + /// * [isAltPressed], to see if an ALT key is pressed. + /// * [isMetaPressed], to see if a META key is pressed. + final int metaState; + + /// The source of the event. + /// + /// See <https://developer.android.com/reference/android/view/KeyEvent.html#getSource()> + /// for the numerical values of the `source`. Many of these constants are also + /// replicated as static constants in this class. + final int eventSource; + + /// The vendor ID of the device that produced the event. + /// + /// See <https://developer.android.com/reference/android/view/InputDevice.html#getVendorId()> + /// for the numerical values of the [vendorId]. + final int vendorId; + + /// The product ID of the device that produced the event. + /// + /// See <https://developer.android.com/reference/android/view/InputDevice.html#getProductId()> + /// for the numerical values of the [productId]. + final int productId; + + /// The ID of the device that produced the event. + /// + /// See https://developer.android.com/reference/android/view/InputDevice.html#getId() + final int deviceId; + + /// The repeat count of the event. + /// + /// See <https://developer.android.com/reference/android/view/KeyEvent#getRepeatCount()> + /// for more information. + final int repeatCount; + + // The source code that indicates that an event came from a joystick. + // from https://developer.android.com/reference/android/view/InputDevice.html#SOURCE_JOYSTICK + static const int _sourceJoystick = 0x01000010; + + // Android only reports a single code point for the key label. + @override + String get keyLabel => plainCodePoint == 0 ? '' : String.fromCharCode(plainCodePoint & _kCombiningCharacterMask); + + @override + PhysicalKeyboardKey get physicalKey { + if (kAndroidToPhysicalKey.containsKey(scanCode)) { + return kAndroidToPhysicalKey[scanCode]!; + } + + // Android sends DPAD_UP, etc. as the keyCode for joystick DPAD events, but + // it doesn't set the scanCode for those, so we have to detect this, and set + // our own DPAD physical keys. The logical key will still match "arrowUp", + // etc. + if (eventSource & _sourceJoystick == _sourceJoystick) { + final LogicalKeyboardKey? foundKey = kAndroidToLogicalKey[keyCode]; + if (foundKey == LogicalKeyboardKey.arrowUp) { + return PhysicalKeyboardKey.arrowUp; + } + if (foundKey == LogicalKeyboardKey.arrowDown) { + return PhysicalKeyboardKey.arrowDown; + } + if (foundKey == LogicalKeyboardKey.arrowLeft) { + return PhysicalKeyboardKey.arrowLeft; + } + if (foundKey == LogicalKeyboardKey.arrowRight) { + return PhysicalKeyboardKey.arrowRight; + } + } + return PhysicalKeyboardKey(LogicalKeyboardKey.androidPlane + scanCode); + } + + @override + LogicalKeyboardKey get logicalKey { + // Look to see if the keyCode is a printable number pad key, so that a + // difference between regular keys (e.g. "=") and the number pad version + // (e.g. the "=" on the number pad) can be determined. + final LogicalKeyboardKey? numPadKey = kAndroidNumPadMap[keyCode]; + if (numPadKey != null) { + return numPadKey; + } + + // If it has a non-control-character label, then either return the existing + // constant, or construct a new Unicode-based key from it. Don't mark it as + // autogenerated, since the label uniquely identifies an ID from the Unicode + // plane. + if (keyLabel.isNotEmpty && !LogicalKeyboardKey.isControlCharacter(keyLabel)) { + final int combinedCodePoint = plainCodePoint & _kCombiningCharacterMask; + final int keyId = LogicalKeyboardKey.unicodePlane | (combinedCodePoint & LogicalKeyboardKey.valueMask); + return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(keyId); + } + + // Look to see if the keyCode is one we know about and have a mapping for. + final LogicalKeyboardKey? newKey = kAndroidToLogicalKey[keyCode]; + if (newKey != null) { + return newKey; + } + + return LogicalKeyboardKey(keyCode | LogicalKeyboardKey.androidPlane); + } + + bool _isLeftRightModifierPressed(KeyboardSide side, int anyMask, int leftMask, int rightMask) { + if (metaState & anyMask == 0) { + return false; + } + switch (side) { + case KeyboardSide.any: + return true; + case KeyboardSide.all: + return metaState & leftMask != 0 && metaState & rightMask != 0; + case KeyboardSide.left: + return metaState & leftMask != 0; + case KeyboardSide.right: + return metaState & rightMask != 0; + } + } + + @override + bool isModifierPressed(ModifierKey key, { KeyboardSide side = KeyboardSide.any }) { + switch (key) { + case ModifierKey.controlModifier: + return _isLeftRightModifierPressed(side, modifierControl, modifierLeftControl, modifierRightControl); + case ModifierKey.shiftModifier: + return _isLeftRightModifierPressed(side, modifierShift, modifierLeftShift, modifierRightShift); + case ModifierKey.altModifier: + return _isLeftRightModifierPressed(side, modifierAlt, modifierLeftAlt, modifierRightAlt); + case ModifierKey.metaModifier: + return _isLeftRightModifierPressed(side, modifierMeta, modifierLeftMeta, modifierRightMeta); + case ModifierKey.capsLockModifier: + return metaState & modifierCapsLock != 0; + case ModifierKey.numLockModifier: + return metaState & modifierNumLock != 0; + case ModifierKey.scrollLockModifier: + return metaState & modifierScrollLock != 0; + case ModifierKey.functionModifier: + return metaState & modifierFunction != 0; + case ModifierKey.symbolModifier: + return metaState & modifierSym != 0; + } + } + + @override + KeyboardSide? getModifierSide(ModifierKey key) { + KeyboardSide? findSide(int anyMask, int leftMask, int rightMask) { + final int combinedMask = leftMask | rightMask; + final int combined = metaState & combinedMask; + if (combined == leftMask) { + return KeyboardSide.left; + } else if (combined == rightMask) { + return KeyboardSide.right; + } else if (combined == combinedMask) { + return KeyboardSide.all; + } + // If the platform code sets the "any" modifier, but not a specific side, + // then we return "all", assuming that there is only one of that modifier + // key on the keyboard. + if (metaState & anyMask != 0) { + return KeyboardSide.all; + } + return null; + } + + switch (key) { + case ModifierKey.controlModifier: + return findSide(modifierControl, modifierLeftControl, modifierRightControl); + case ModifierKey.shiftModifier: + return findSide(modifierShift, modifierLeftShift, modifierRightShift); + case ModifierKey.altModifier: + return findSide(modifierAlt, modifierLeftAlt, modifierRightAlt); + case ModifierKey.metaModifier: + return findSide(modifierMeta, modifierLeftMeta, modifierRightMeta); + case ModifierKey.capsLockModifier: + case ModifierKey.numLockModifier: + case ModifierKey.scrollLockModifier: + case ModifierKey.functionModifier: + case ModifierKey.symbolModifier: + return KeyboardSide.all; + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<int>('flags', flags)); + properties.add(DiagnosticsProperty<int>('codePoint', codePoint)); + properties.add(DiagnosticsProperty<int>('plainCodePoint', plainCodePoint)); + properties.add(DiagnosticsProperty<int>('keyCode', keyCode)); + properties.add(DiagnosticsProperty<int>('scanCode', scanCode)); + properties.add(DiagnosticsProperty<int>('metaState', metaState)); + } + + @override + bool operator==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is RawKeyEventDataAndroid + && other.flags == flags + && other.codePoint == codePoint + && other.plainCodePoint == plainCodePoint + && other.keyCode == keyCode + && other.scanCode == scanCode + && other.metaState == metaState; + } + + @override + int get hashCode => Object.hash( + flags, + codePoint, + plainCodePoint, + keyCode, + scanCode, + metaState, + ); + + // Modifier key masks. + + /// No modifier keys are pressed in the [metaState] field. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierNone = 0; + + /// This mask is used to check the [metaState] field to test whether one of + /// the ALT modifier keys is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierAlt = 0x02; + + /// This mask is used to check the [metaState] field to test whether the left + /// ALT modifier key is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierLeftAlt = 0x10; + + /// This mask is used to check the [metaState] field to test whether the right + /// ALT modifier key is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierRightAlt = 0x20; + + /// This mask is used to check the [metaState] field to test whether one of + /// the SHIFT modifier keys is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierShift = 0x01; + + /// This mask is used to check the [metaState] field to test whether the left + /// SHIFT modifier key is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierLeftShift = 0x40; + + /// This mask is used to check the [metaState] field to test whether the right + /// SHIFT modifier key is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierRightShift = 0x80; + + /// This mask is used to check the [metaState] field to test whether the SYM + /// modifier key is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierSym = 0x04; + + /// This mask is used to check the [metaState] field to test whether the + /// Function modifier key (Fn) is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierFunction = 0x08; + + /// This mask is used to check the [metaState] field to test whether one of + /// the CTRL modifier keys is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierControl = 0x1000; + + /// This mask is used to check the [metaState] field to test whether the left + /// CTRL modifier key is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierLeftControl = 0x2000; + + /// This mask is used to check the [metaState] field to test whether the right + /// CTRL modifier key is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierRightControl = 0x4000; + + /// This mask is used to check the [metaState] field to test whether one of + /// the META modifier keys is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierMeta = 0x10000; + + /// This mask is used to check the [metaState] field to test whether the left + /// META modifier key is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierLeftMeta = 0x20000; + + /// This mask is used to check the [metaState] field to test whether the right + /// META modifier key is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierRightMeta = 0x40000; + + /// This mask is used to check the [metaState] field to test whether the CAPS + /// LOCK modifier key is on. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierCapsLock = 0x100000; + + /// This mask is used to check the [metaState] field to test whether the NUM + /// LOCK modifier key is on. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierNumLock = 0x200000; + + /// This mask is used to check the [metaState] field to test whether the + /// SCROLL LOCK modifier key is on. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierScrollLock = 0x400000; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_fuchsia.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_fuchsia.dart new file mode 100644 index 0000000000000000000000000000000000000000..9a297b91b27ebacf98f3b963148acfc2ffbab818 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_fuchsia.dart @@ -0,0 +1,312 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'keyboard_maps.g.dart'; +import 'raw_keyboard.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; + +export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey; + +/// Platform-specific key event data for Fuchsia. +/// +/// This class is deprecated and will be removed. Platform specific key event +/// data will no longer be available. See [KeyEvent] for what is available. +/// +/// This object contains information about key events obtained from Fuchsia's +/// `KeyData` interface. +/// +/// See also: +/// +/// * [RawKeyboard], which uses this interface to expose key data. +@Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class RawKeyEventDataFuchsia extends RawKeyEventData { + /// Creates a key event data structure specific for Fuchsia. + @Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyEventDataFuchsia({ + this.hidUsage = 0, + this.codePoint = 0, + this.modifiers = 0, + }); + + /// The USB HID usage. + /// + /// See <http://www.usb.org/developers/hidpage/Hut1_12v2.pdf> for more + /// information. + final int hidUsage; + + /// The Unicode code point represented by the key event, if any. + /// + /// If there is no Unicode code point, this value is zero. + /// + /// Dead keys are represented as Unicode combining characters. + final int codePoint; + + /// The modifiers that were present when the key event occurred. + /// + /// See <https://fuchsia.googlesource.com/garnet/+/master/public/fidl/fuchsia.ui.input/input_event_constants.fidl> + /// for the numerical values of the modifiers. Many of these are also + /// replicated as static constants in this class. + /// + /// See also: + /// + /// * [modifiersPressed], which returns a Map of currently pressed modifiers + /// and their keyboard side. + /// * [isModifierPressed], to see if a specific modifier is pressed. + /// * [isControlPressed], to see if a CTRL key is pressed. + /// * [isShiftPressed], to see if a SHIFT key is pressed. + /// * [isAltPressed], to see if an ALT key is pressed. + /// * [isMetaPressed], to see if a META key is pressed. + final int modifiers; + + // Fuchsia only reports a single code point for the key label. + @override + String get keyLabel => codePoint == 0 ? '' : String.fromCharCode(codePoint); + + @override + LogicalKeyboardKey get logicalKey { + // If the key has a printable representation, then make a logical key based + // on that. + if (codePoint != 0) { + final int flutterId = LogicalKeyboardKey.unicodePlane | codePoint & LogicalKeyboardKey.valueMask; + return kFuchsiaToLogicalKey[flutterId] ?? LogicalKeyboardKey(LogicalKeyboardKey.unicodePlane | codePoint & LogicalKeyboardKey.valueMask); + } + + // Look to see if the hidUsage is one we know about and have a mapping for. + final LogicalKeyboardKey? newKey = kFuchsiaToLogicalKey[hidUsage | LogicalKeyboardKey.fuchsiaPlane]; + if (newKey != null) { + return newKey; + } + + // This is a non-printable key that we don't know about, so we mint a new + // code. + return LogicalKeyboardKey(hidUsage | LogicalKeyboardKey.fuchsiaPlane); + } + + @override + PhysicalKeyboardKey get physicalKey => kFuchsiaToPhysicalKey[hidUsage] ?? PhysicalKeyboardKey(LogicalKeyboardKey.fuchsiaPlane + hidUsage); + + bool _isLeftRightModifierPressed(KeyboardSide side, int anyMask, int leftMask, int rightMask) { + if (modifiers & anyMask == 0) { + return false; + } + switch (side) { + case KeyboardSide.any: + return true; + case KeyboardSide.all: + return modifiers & leftMask != 0 && modifiers & rightMask != 0; + case KeyboardSide.left: + return modifiers & leftMask != 0; + case KeyboardSide.right: + return modifiers & rightMask != 0; + } + } + + @override + bool isModifierPressed(ModifierKey key, { KeyboardSide side = KeyboardSide.any }) { + switch (key) { + case ModifierKey.controlModifier: + return _isLeftRightModifierPressed(side, modifierControl, modifierLeftControl, modifierRightControl); + case ModifierKey.shiftModifier: + return _isLeftRightModifierPressed(side, modifierShift, modifierLeftShift, modifierRightShift); + case ModifierKey.altModifier: + return _isLeftRightModifierPressed(side, modifierAlt, modifierLeftAlt, modifierRightAlt); + case ModifierKey.metaModifier: + return _isLeftRightModifierPressed(side, modifierMeta, modifierLeftMeta, modifierRightMeta); + case ModifierKey.capsLockModifier: + return modifiers & modifierCapsLock != 0; + case ModifierKey.numLockModifier: + case ModifierKey.scrollLockModifier: + case ModifierKey.functionModifier: + case ModifierKey.symbolModifier: + // Fuchsia doesn't have masks for these keys (yet). + return false; + } + } + + @override + KeyboardSide? getModifierSide(ModifierKey key) { + KeyboardSide? findSide(int anyMask, int leftMask, int rightMask) { + final int combined = modifiers & anyMask; + if (combined == leftMask) { + return KeyboardSide.left; + } else if (combined == rightMask) { + return KeyboardSide.right; + } else if (combined == anyMask) { + return KeyboardSide.all; + } + return null; + } + + switch (key) { + case ModifierKey.controlModifier: + return findSide(modifierControl, modifierLeftControl, modifierRightControl, ); + case ModifierKey.shiftModifier: + return findSide(modifierShift, modifierLeftShift, modifierRightShift); + case ModifierKey.altModifier: + return findSide(modifierAlt, modifierLeftAlt, modifierRightAlt); + case ModifierKey.metaModifier: + return findSide(modifierMeta, modifierLeftMeta, modifierRightMeta); + case ModifierKey.capsLockModifier: + return (modifiers & modifierCapsLock == 0) ? null : KeyboardSide.all; + case ModifierKey.numLockModifier: + case ModifierKey.scrollLockModifier: + case ModifierKey.functionModifier: + case ModifierKey.symbolModifier: + // Fuchsia doesn't support these modifiers, so they can't be pressed. + return null; + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<int>('hidUsage', hidUsage)); + properties.add(DiagnosticsProperty<int>('codePoint', codePoint)); + properties.add(DiagnosticsProperty<int>('modifiers', modifiers)); + } + + @override + bool operator==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is RawKeyEventDataFuchsia + && other.hidUsage == hidUsage + && other.codePoint == codePoint + && other.modifiers == modifiers; + } + + @override + int get hashCode => Object.hash( + hidUsage, + codePoint, + modifiers, + ); + + // Keyboard modifier masks for Fuchsia modifiers. + + /// The [modifiers] field indicates that no modifier keys are pressed if it + /// equals this value. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierNone = 0x0; + + /// This mask is used to check the [modifiers] field to test whether the CAPS + /// LOCK modifier key is on. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierCapsLock = 0x1; + + /// This mask is used to check the [modifiers] field to test whether the left + /// SHIFT modifier key is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierLeftShift = 0x2; + + /// This mask is used to check the [modifiers] field to test whether the right + /// SHIFT modifier key is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierRightShift = 0x4; + + /// This mask is used to check the [modifiers] field to test whether one of + /// the SHIFT modifier keys is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierShift = modifierLeftShift | modifierRightShift; + + /// This mask is used to check the [modifiers] field to test whether the left + /// CTRL modifier key is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierLeftControl = 0x8; + + /// This mask is used to check the [modifiers] field to test whether the right + /// CTRL modifier key is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierRightControl = 0x10; + + /// This mask is used to check the [modifiers] field to test whether one of + /// the CTRL modifier keys is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierControl = modifierLeftControl | modifierRightControl; + + /// This mask is used to check the [modifiers] field to test whether the left + /// ALT modifier key is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierLeftAlt = 0x20; + + /// This mask is used to check the [modifiers] field to test whether the right + /// ALT modifier key is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierRightAlt = 0x40; + + /// This mask is used to check the [modifiers] field to test whether one of + /// the ALT modifier keys is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierAlt = modifierLeftAlt | modifierRightAlt; + + /// This mask is used to check the [modifiers] field to test whether the left + /// META modifier key is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierLeftMeta = 0x80; + + /// This mask is used to check the [modifiers] field to test whether the right + /// META modifier key is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierRightMeta = 0x100; + + /// This mask is used to check the [modifiers] field to test whether one of + /// the META modifier keys is pressed. + /// + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierMeta = modifierLeftMeta | modifierRightMeta; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_ios.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_ios.dart new file mode 100644 index 0000000000000000000000000000000000000000..300fa5f94d59a87da4a4d67a08224bed4e752860 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_ios.dart @@ -0,0 +1,372 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'keyboard_maps.g.dart'; +import 'raw_keyboard.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; + +export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey; + +/// Platform-specific key event data for iOS. +/// +/// This class is deprecated and will be removed. Platform specific key event +/// data will no longer be available. See [KeyEvent] for what is available. +/// +/// This object contains information about key events obtained from iOS' +/// `UIKey` interface. +/// +/// See also: +/// +/// * [RawKeyboard], which uses this interface to expose key data. +@Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class RawKeyEventDataIos extends RawKeyEventData { + /// Creates a key event data structure specific for iOS. + @Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyEventDataIos({ + this.characters = '', + this.charactersIgnoringModifiers = '', + this.keyCode = 0, + this.modifiers = 0, + }); + + /// The Unicode characters associated with a key-up or key-down event. + /// + /// See also: + /// + /// * [Apple's UIKey documentation](https://developer.apple.com/documentation/uikit/uikey/3526130-characters?language=objc) + final String characters; + + /// The characters generated by a key event as if no modifier key (except for + /// Shift) applies. + /// + /// See also: + /// + /// * [Apple's UIKey documentation](https://developer.apple.com/documentation/uikit/uikey/3526131-charactersignoringmodifiers?language=objc) + final String charactersIgnoringModifiers; + + /// The virtual key code for the keyboard key associated with a key event. + /// + /// See also: + /// + /// * [Apple's UIKey documentation](https://developer.apple.com/documentation/uikit/uikey/3526132-keycode?language=objc) + final int keyCode; + + /// A mask of the current modifiers using the values in Modifier Flags. + /// + /// See also: + /// + /// * [Apple's UIKey documentation](https://developer.apple.com/documentation/uikit/uikey/3526133-modifierflags?language=objc) + final int modifiers; + + @override + String get keyLabel => charactersIgnoringModifiers; + + @override + PhysicalKeyboardKey get physicalKey => kIosToPhysicalKey[keyCode] ?? PhysicalKeyboardKey(LogicalKeyboardKey.iosPlane + keyCode); + + @override + LogicalKeyboardKey get logicalKey { + // Look to see if the keyCode is a printable number pad key, so that a + // difference between regular keys (e.g. "=") and the number pad version + // (e.g. the "=" on the number pad) can be determined. + final LogicalKeyboardKey? numPadKey = kIosNumPadMap[keyCode]; + if (numPadKey != null) { + return numPadKey; + } + + // Look to see if the [keyLabel] is one we know about and have a mapping for. + final LogicalKeyboardKey? specialKey = kIosSpecialLogicalMap[keyLabel]; + if (specialKey != null) { + return specialKey; + } + + // Keys that can't be derived with characterIgnoringModifiers will be + // derived from their key codes using this map. + final LogicalKeyboardKey? knownKey = kIosToLogicalKey[keyCode]; + if (knownKey != null) { + return knownKey; + } + + // If this key is printable, generate the LogicalKeyboardKey from its + // Unicode value. Control keys such as ESC, CTRL, and SHIFT are not + // printable. HOME, DEL, arrow keys, and function keys are considered + // modifier function keys, which generate invalid Unicode scalar values. + if (keyLabel.isNotEmpty && + !LogicalKeyboardKey.isControlCharacter(keyLabel) && + !_isUnprintableKey(keyLabel)) { + // Given that charactersIgnoringModifiers can contain a String of + // arbitrary length, limit to a maximum of two Unicode scalar values. It + // is unlikely that a keyboard would produce a code point bigger than 32 + // bits, but it is still worth defending against this case. + assert(charactersIgnoringModifiers.length <= 2); + int codeUnit = charactersIgnoringModifiers.codeUnitAt(0); + if (charactersIgnoringModifiers.length == 2) { + final int secondCode = charactersIgnoringModifiers.codeUnitAt(1); + codeUnit = (codeUnit << 16) | secondCode; + } + + final int keyId = LogicalKeyboardKey.unicodePlane | (codeUnit & LogicalKeyboardKey.valueMask); + return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(keyId); + } + + // This is a non-printable key that we don't know about, so we mint a new + // code. + return LogicalKeyboardKey(keyCode | LogicalKeyboardKey.iosPlane); + } + + /// Returns true if the given label represents an unprintable key. + /// + /// Examples of unprintable keys are "NSUpArrowFunctionKey = 0xF700" + /// or "NSHomeFunctionKey = 0xF729". + /// + /// See <https://developer.apple.com/documentation/appkit/1535851-function-key_unicodes?language=objc> for more + /// information. + /// + /// Used by [RawKeyEvent] subclasses to help construct IDs. + static bool _isUnprintableKey(String label) { + if (label.length != 1) { + return false; + } + final int codeUnit = label.codeUnitAt(0); + return codeUnit >= 0xF700 && codeUnit <= 0xF8FF; + } + + bool _isLeftRightModifierPressed(KeyboardSide side, int anyMask, int leftMask, int rightMask) { + if (modifiers & anyMask == 0) { + return false; + } + // If only the "anyMask" bit is set, then we respond true for requests of + // whether either left or right is pressed. Handles the case where iOS + // supplies just the "either" modifier flag, but not the left/right flag. + // (e.g. modifierShift but not modifierLeftShift). + final bool anyOnly = modifiers & (leftMask | rightMask | anyMask) == anyMask; + switch (side) { + case KeyboardSide.any: + return true; + case KeyboardSide.all: + return modifiers & leftMask != 0 && modifiers & rightMask != 0 || anyOnly; + case KeyboardSide.left: + return modifiers & leftMask != 0 || anyOnly; + case KeyboardSide.right: + return modifiers & rightMask != 0 || anyOnly; + } + } + + @override + bool isModifierPressed(ModifierKey key, {KeyboardSide side = KeyboardSide.any}) { + final int independentModifier = modifiers & deviceIndependentMask; + bool result; + switch (key) { + case ModifierKey.controlModifier: + result = _isLeftRightModifierPressed(side, independentModifier & modifierControl, modifierLeftControl, modifierRightControl); + case ModifierKey.shiftModifier: + result = _isLeftRightModifierPressed(side, independentModifier & modifierShift, modifierLeftShift, modifierRightShift); + case ModifierKey.altModifier: + result = _isLeftRightModifierPressed(side, independentModifier & modifierOption, modifierLeftOption, modifierRightOption); + case ModifierKey.metaModifier: + result = _isLeftRightModifierPressed(side, independentModifier & modifierCommand, modifierLeftCommand, modifierRightCommand); + case ModifierKey.capsLockModifier: + result = independentModifier & modifierCapsLock != 0; + // On iOS, the function modifier bit is set for any function key, like F1, + // F2, etc., but the meaning of ModifierKey.modifierFunction in Flutter is + // that of the Fn modifier key, so there's no good way to emulate that on + // iOS. + case ModifierKey.functionModifier: + case ModifierKey.numLockModifier: + case ModifierKey.symbolModifier: + case ModifierKey.scrollLockModifier: + // These modifier masks are not used in iOS keyboards. + result = false; + } + assert(!result || getModifierSide(key) != null, "$runtimeType thinks that a modifier is pressed, but can't figure out what side it's on."); + return result; + } + + @override + KeyboardSide? getModifierSide(ModifierKey key) { + KeyboardSide? findSide(int anyMask, int leftMask, int rightMask) { + final int combinedMask = leftMask | rightMask; + final int combined = modifiers & combinedMask; + if (combined == leftMask) { + return KeyboardSide.left; + } else if (combined == rightMask) { + return KeyboardSide.right; + } else if (combined == combinedMask || modifiers & (combinedMask | anyMask) == anyMask) { + // Handles the case where iOS supplies just the "either" modifier + // flag, but not the left/right flag. (e.g. modifierShift but not + // modifierLeftShift), or if left and right flags are provided, but not + // the "either" modifier flag. + return KeyboardSide.all; + } + return null; + } + + switch (key) { + case ModifierKey.controlModifier: + return findSide(modifierControl, modifierLeftControl, modifierRightControl); + case ModifierKey.shiftModifier: + return findSide(modifierShift, modifierLeftShift, modifierRightShift); + case ModifierKey.altModifier: + return findSide(modifierOption, modifierLeftOption, modifierRightOption); + case ModifierKey.metaModifier: + return findSide(modifierCommand, modifierLeftCommand, modifierRightCommand); + case ModifierKey.capsLockModifier: + case ModifierKey.numLockModifier: + case ModifierKey.scrollLockModifier: + case ModifierKey.functionModifier: + case ModifierKey.symbolModifier: + return KeyboardSide.all; + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('characters', characters)); + properties.add(DiagnosticsProperty<String>('charactersIgnoringModifiers', charactersIgnoringModifiers)); + properties.add(DiagnosticsProperty<int>('keyCode', keyCode)); + properties.add(DiagnosticsProperty<int>('modifiers', modifiers)); + } + + @override + bool operator==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is RawKeyEventDataIos + && other.characters == characters + && other.charactersIgnoringModifiers == charactersIgnoringModifiers + && other.keyCode == keyCode + && other.modifiers == modifiers; + } + + @override + int get hashCode => Object.hash( + characters, + charactersIgnoringModifiers, + keyCode, + modifiers, + ); + + // Modifier key masks. See Apple's UIKey documentation + // https://developer.apple.com/documentation/uikit/uikeymodifierflags?language=objc + // https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-86/IOHIDSystem/IOKit/hidsystem/IOLLEvent.h.auto.html + + /// This mask is used to check the [modifiers] field to test whether the CAPS + /// LOCK modifier key is on. + /// + /// {@template flutter.services.RawKeyEventDataIos.modifierCapsLock} + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + /// {@endtemplate} + static const int modifierCapsLock = 0x10000; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// SHIFT modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierShift = 0x20000; + + /// This mask is used to check the [modifiers] field to test whether the left + /// SHIFT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierLeftShift = 0x02; + + /// This mask is used to check the [modifiers] field to test whether the right + /// SHIFT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierRightShift = 0x04; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// CTRL modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierControl = 0x40000; + + /// This mask is used to check the [modifiers] field to test whether the left + /// CTRL modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierLeftControl = 0x01; + + /// This mask is used to check the [modifiers] field to test whether the right + /// CTRL modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierRightControl = 0x2000; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// ALT modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierOption = 0x80000; + + /// This mask is used to check the [modifiers] field to test whether the left + /// ALT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierLeftOption = 0x20; + + /// This mask is used to check the [modifiers] field to test whether the right + /// ALT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierRightOption = 0x40; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// CMD modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierCommand = 0x100000; + + /// This mask is used to check the [modifiers] field to test whether the left + /// CMD modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierLeftCommand = 0x08; + + /// This mask is used to check the [modifiers] field to test whether the right + /// CMD modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierRightCommand = 0x10; + + /// This mask is used to check the [modifiers] field to test whether any key in + /// the numeric keypad is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierNumericPad = 0x200000; + + /// This mask is used to check the [modifiers] field to test whether the + /// HELP modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierHelp = 0x400000; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// FUNCTION modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataIos.modifierCapsLock} + static const int modifierFunction = 0x800000; + + /// Used to retrieve only the device-independent modifier flags, allowing + /// applications to mask off the device-dependent modifier flags, including + /// event coalescing information. + static const int deviceIndependentMask = 0xffff0000; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_linux.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_linux.dart new file mode 100644 index 0000000000000000000000000000000000000000..26503a20c59f592f4e2f7ddb15b7bfcfa3523bd1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_linux.dart @@ -0,0 +1,524 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'keyboard_maps.g.dart'; +import 'raw_keyboard.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; + +export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey; + +/// Platform-specific key event data for Linux. +/// +/// This class is deprecated and will be removed. Platform specific key event +/// data will no longer be available. See [KeyEvent] for what is available. +/// +/// Different window toolkit implementations can map to different key codes. This class +/// will use the correct mapping depending on the [keyHelper] provided. +/// +/// See also: +/// +/// * [RawKeyboard], which uses this interface to expose key data. +@Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class RawKeyEventDataLinux extends RawKeyEventData { + /// Creates a key event data structure specific for Linux. + @Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyEventDataLinux({ + required this.keyHelper, + this.unicodeScalarValues = 0, + this.scanCode = 0, + this.keyCode = 0, + this.modifiers = 0, + required this.isDown, + this.specifiedLogicalKey, + }) : assert((unicodeScalarValues & ~LogicalKeyboardKey.valueMask) == 0); + + /// A helper class that abstracts the fetching of the toolkit-specific mappings. + /// + /// There is no real concept of a "native" window toolkit on Linux, and each implementation + /// (GLFW, GTK, QT, etc) may have a different key code mapping. + final KeyHelper keyHelper; + + /// An int with up to two Unicode scalar values generated by a single keystroke. An assertion + /// will fire if more than two values are encoded in a single keystroke. + /// + /// This is typically the character that [keyCode] would produce without any modifier keys. + /// For dead keys, it is typically the diacritic it would add to a character. Defaults to 0, + /// asserted to be not null. + final int unicodeScalarValues; + + /// The hardware scan code id corresponding to this key event. + /// + /// These values are not reliable and vary from device to device, so this + /// information is mainly useful for debugging. + final int scanCode; + + /// The hardware key code corresponding to this key event. + /// + /// This is the physical key that was pressed, not the Unicode character. + /// This value may be different depending on the window toolkit used. See [KeyHelper]. + final int keyCode; + + /// A mask of the current modifiers using the values in Modifier Flags. + /// This value may be different depending on the window toolkit used. See [KeyHelper]. + final int modifiers; + + /// Whether or not this key event is a key down (true) or key up (false). + final bool isDown; + + /// A logical key specified by the embedding that should be used instead of + /// deriving from raw data. + /// + /// The GTK embedding detects the keyboard layout and maps some keys to + /// logical keys in a way that can not be derived from per-key information. + /// + /// This is not part of the native GTK key event. + final int? specifiedLogicalKey; + + @override + String get keyLabel => unicodeScalarValues == 0 ? '' : String.fromCharCode(unicodeScalarValues); + + @override + PhysicalKeyboardKey get physicalKey => kLinuxToPhysicalKey[scanCode] ?? PhysicalKeyboardKey(LogicalKeyboardKey.webPlane + scanCode); + + @override + LogicalKeyboardKey get logicalKey { + if (specifiedLogicalKey != null) { + final int key = specifiedLogicalKey!; + return LogicalKeyboardKey.findKeyByKeyId(key) ?? LogicalKeyboardKey(key); + } + // Look to see if the keyCode is a printable number pad key, so that a + // difference between regular keys (e.g. "=") and the number pad version + // (e.g. the "=" on the number pad) can be determined. + final LogicalKeyboardKey? numPadKey = keyHelper.numpadKey(keyCode); + if (numPadKey != null) { + return numPadKey; + } + + // If it has a non-control-character label, then either return the existing + // constant, or construct a new Unicode-based key from it. Don't mark it as + // autogenerated, since the label uniquely identifies an ID from the Unicode + // plane. + if (keyLabel.isNotEmpty && + !LogicalKeyboardKey.isControlCharacter(keyLabel)) { + final int keyId = LogicalKeyboardKey.unicodePlane | (unicodeScalarValues & LogicalKeyboardKey.valueMask); + return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(keyId); + } + + // Look to see if the keyCode is one we know about and have a mapping for. + final LogicalKeyboardKey? newKey = keyHelper.logicalKey(keyCode); + if (newKey != null) { + return newKey; + } + + // This is a non-printable key that we don't know about, so we mint a new + // code. + return LogicalKeyboardKey(keyCode | keyHelper.platformPlane); + } + + @override + bool isModifierPressed(ModifierKey key, {KeyboardSide side = KeyboardSide.any}) { + return keyHelper.isModifierPressed(key, modifiers, side: side, keyCode: keyCode, isDown: isDown); + } + + @override + KeyboardSide getModifierSide(ModifierKey key) { + return keyHelper.getModifierSide(key); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('toolkit', keyHelper.debugToolkit)); + properties.add(DiagnosticsProperty<int>('unicodeScalarValues', unicodeScalarValues)); + properties.add(DiagnosticsProperty<int>('scanCode', scanCode)); + properties.add(DiagnosticsProperty<int>('keyCode', keyCode)); + properties.add(DiagnosticsProperty<int>('modifiers', modifiers)); + properties.add(DiagnosticsProperty<bool>('isDown', isDown)); + properties.add(DiagnosticsProperty<int?>('specifiedLogicalKey', specifiedLogicalKey, defaultValue: null)); + } + + @override + bool operator==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is RawKeyEventDataLinux + && other.keyHelper.runtimeType == keyHelper.runtimeType + && other.unicodeScalarValues == unicodeScalarValues + && other.scanCode == scanCode + && other.keyCode == keyCode + && other.modifiers == modifiers + && other.isDown == isDown; + } + + @override + int get hashCode => Object.hash( + keyHelper.runtimeType, + unicodeScalarValues, + scanCode, + keyCode, + modifiers, + isDown, + ); +} + +/// Abstract class for window-specific key mappings. +/// +/// Given that there might be multiple window toolkit implementations (GLFW, +/// GTK, QT, etc), this creates a common interface for each of the +/// different toolkits. +/// +/// This class is deprecated and will be removed. Platform specific key event +/// data will no longer be available. See [KeyEvent] for what is available. +@Deprecated( + 'No longer supported. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +abstract class KeyHelper { + /// Create a KeyHelper implementation depending on the given toolkit. + @Deprecated( + 'No longer supported. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + factory KeyHelper(String toolkit) { + if (toolkit == 'glfw') { + return GLFWKeyHelper(); + } else if (toolkit == 'gtk') { + return GtkKeyHelper(); + } else { + throw FlutterError('Window toolkit not recognized: $toolkit'); + } + } + + /// Returns the name for the toolkit. + /// + /// This is used in debug mode to generate readable string. + String get debugToolkit; + + /// Returns a [KeyboardSide] enum value that describes which side or sides of + /// the given keyboard modifier key were pressed at the time of this event. + @Deprecated( + 'No longer supported. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + KeyboardSide getModifierSide(ModifierKey key); + + /// Returns true if the given [ModifierKey] was pressed at the time of this + /// event. + @Deprecated( + 'No longer supported. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + bool isModifierPressed(ModifierKey key, int modifiers, {KeyboardSide side = KeyboardSide.any, required int keyCode, required bool isDown}); + + /// The numpad key from the specific key code mapping. + LogicalKeyboardKey? numpadKey(int keyCode); + + /// The logical key from the specific key code mapping. + LogicalKeyboardKey? logicalKey(int keyCode); + + /// The platform plane mask value of this platform. + int get platformPlane; +} + +/// Helper class that uses GLFW-specific key mappings. +/// +/// This class is deprecated and will be removed. Platform specific key event +/// data will no longer be available. See [KeyEvent] for what is available. +@Deprecated( + 'No longer supported. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class GLFWKeyHelper implements KeyHelper { + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether the CAPS LOCK modifier key is on. + /// + /// {@template flutter.services.GLFWKeyHelper.modifierCapsLock} + /// Use this value if you need to decode the [RawKeyEventDataLinux.modifiers] + /// field yourself, but it's much easier to use [isModifierPressed] if you + /// just want to know if a modifier is pressed. This is especially true on + /// GLFW, since its modifiers don't include the effects of the current key + /// event. + /// {@endtemplate} + static const int modifierCapsLock = 0x0010; + + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether one of the SHIFT modifier keys is pressed. + /// + /// {@macro flutter.services.GLFWKeyHelper.modifierCapsLock} + static const int modifierShift = 0x0001; + + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether one of the CTRL modifier keys is pressed. + /// + /// {@macro flutter.services.GLFWKeyHelper.modifierCapsLock} + static const int modifierControl = 0x0002; + + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether one of the ALT modifier keys is pressed. + /// + /// {@macro flutter.services.GLFWKeyHelper.modifierCapsLock} + static const int modifierAlt = 0x0004; + + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether one of the Meta(SUPER) modifier keys is pressed. + /// + /// {@macro flutter.services.GLFWKeyHelper.modifierCapsLock} + static const int modifierMeta = 0x0008; + + + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether any key in the numeric keypad is pressed. + /// + /// {@macro flutter.services.GLFWKeyHelper.modifierCapsLock} + static const int modifierNumericPad = 0x0020; + + @override + String get debugToolkit => 'GLFW'; + + int _mergeModifiers({required int modifiers, required int keyCode, required bool isDown}) { + // GLFW Key codes for modifier keys. + const int shiftLeftKeyCode = 340; + const int shiftRightKeyCode = 344; + const int controlLeftKeyCode = 341; + const int controlRightKeyCode = 345; + const int altLeftKeyCode = 342; + const int altRightKeyCode = 346; + const int metaLeftKeyCode = 343; + const int metaRightKeyCode = 347; + const int capsLockKeyCode = 280; + const int numLockKeyCode = 282; + + // On GLFW, the "modifiers" bitfield is the state as it is BEFORE this event + // happened, not AFTER, like every other platform. Consequently, if this is + // a key down, then we need to add the correct modifier bits, and if it's a + // key up, we need to remove them. + + int modifierChange = 0; + switch (keyCode) { + case shiftLeftKeyCode: + case shiftRightKeyCode: + modifierChange = modifierShift; + case controlLeftKeyCode: + case controlRightKeyCode: + modifierChange = modifierControl; + case altLeftKeyCode: + case altRightKeyCode: + modifierChange = modifierAlt; + case metaLeftKeyCode: + case metaRightKeyCode: + modifierChange = modifierMeta; + case capsLockKeyCode: + modifierChange = modifierCapsLock; + case numLockKeyCode: + modifierChange = modifierNumericPad; + default: + break; + } + + return isDown ? modifiers | modifierChange : modifiers & ~modifierChange; + } + + @override + bool isModifierPressed(ModifierKey key, int modifiers, {KeyboardSide side = KeyboardSide.any, required int keyCode, required bool isDown}) { + modifiers = _mergeModifiers(modifiers: modifiers, keyCode: keyCode, isDown: isDown); + switch (key) { + case ModifierKey.controlModifier: + return modifiers & modifierControl != 0; + case ModifierKey.shiftModifier: + return modifiers & modifierShift != 0; + case ModifierKey.altModifier: + return modifiers & modifierAlt != 0; + case ModifierKey.metaModifier: + return modifiers & modifierMeta != 0; + case ModifierKey.capsLockModifier: + return modifiers & modifierCapsLock != 0; + case ModifierKey.numLockModifier: + return modifiers & modifierNumericPad != 0; + case ModifierKey.functionModifier: + case ModifierKey.symbolModifier: + case ModifierKey.scrollLockModifier: + // These are not used in GLFW keyboards. + return false; + } + } + + @override + KeyboardSide getModifierSide(ModifierKey key) { + // Neither GLFW nor X11 provide a distinction between left and right + // modifiers, so defaults to KeyboardSide.all. + // https://code.woboq.org/qt5/include/X11/X.h.html#_M/ShiftMask + return KeyboardSide.all; + } + + @override + LogicalKeyboardKey? numpadKey(int keyCode) { + return kGlfwNumpadMap[keyCode]; + } + + @override + LogicalKeyboardKey? logicalKey(int keyCode) { + return kGlfwToLogicalKey[keyCode]; + } + + @override + int get platformPlane => LogicalKeyboardKey.glfwPlane; +} + +/// Helper class that uses GTK-specific key mappings. +/// +/// This class is deprecated and will be removed. Platform specific key event +/// data will no longer be available. See [KeyEvent] for what is available. +@Deprecated( + 'No longer supported. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class GtkKeyHelper implements KeyHelper { + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether one of the SHIFT modifier keys is pressed. + /// + /// {@template flutter.services.GtkKeyHelper.modifierShift} + /// Use this value if you need to decode the [RawKeyEventDataLinux.modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if a + /// modifier is pressed. This is especially true on GTK, since its modifiers + /// don't include the effects of the current key event. + /// {@endtemplate} + static const int modifierShift = 1 << 0; + + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether the CAPS LOCK modifier key is on. + /// + /// {@macro flutter.services.GtkKeyHelper.modifierShift} + static const int modifierCapsLock = 1 << 1; + + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether one of the CTRL modifier keys is pressed. + /// + /// {@macro flutter.services.GtkKeyHelper.modifierShift} + static const int modifierControl = 1 << 2; + + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether the first modifier key is pressed (usually mapped to alt). + /// + /// {@macro flutter.services.GtkKeyHelper.modifierShift} + static const int modifierMod1 = 1 << 3; + + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether the second modifier key is pressed (assumed to be mapped to + /// num lock). + /// + /// {@macro flutter.services.GtkKeyHelper.modifierShift} + static const int modifierMod2 = 1 << 4; + + /// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to + /// test whether one of the Meta(SUPER) modifier keys is pressed. + /// + /// {@macro flutter.services.GtkKeyHelper.modifierShift} + static const int modifierMeta = 1 << 26; + + @override + String get debugToolkit => 'GTK'; + + int _mergeModifiers({required int modifiers, required int keyCode, required bool isDown}) { + // GTK Key codes for modifier keys. + const int shiftLeftKeyCode = 0xffe1; + const int shiftRightKeyCode = 0xffe2; + const int controlLeftKeyCode = 0xffe3; + const int controlRightKeyCode = 0xffe4; + const int capsLockKeyCode = 0xffe5; + const int shiftLockKeyCode = 0xffe6; + const int altLeftKeyCode = 0xffe9; + const int altRightKeyCode = 0xffea; + const int metaLeftKeyCode = 0xffeb; + const int metaRightKeyCode = 0xffec; + const int numLockKeyCode = 0xff7f; + + // On GTK, the "modifiers" bitfield is the state as it is BEFORE this event + // happened, not AFTER, like every other platform. Consequently, if this is + // a key down, then we need to add the correct modifier bits, and if it's a + // key up, we need to remove them. + + int modifierChange = 0; + switch (keyCode) { + case shiftLeftKeyCode: + case shiftRightKeyCode: + modifierChange = modifierShift; + case controlLeftKeyCode: + case controlRightKeyCode: + modifierChange = modifierControl; + case altLeftKeyCode: + case altRightKeyCode: + modifierChange = modifierMod1; + case metaLeftKeyCode: + case metaRightKeyCode: + modifierChange = modifierMeta; + case capsLockKeyCode: + case shiftLockKeyCode: + modifierChange = modifierCapsLock; + case numLockKeyCode: + modifierChange = modifierMod2; + default: + break; + } + + return isDown ? modifiers | modifierChange : modifiers & ~modifierChange; + } + + @override + bool isModifierPressed(ModifierKey key, int modifiers, {KeyboardSide side = KeyboardSide.any, required int keyCode, required bool isDown}) { + modifiers = _mergeModifiers(modifiers: modifiers, keyCode: keyCode, isDown: isDown); + switch (key) { + case ModifierKey.controlModifier: + return modifiers & modifierControl != 0; + case ModifierKey.shiftModifier: + return modifiers & modifierShift != 0; + case ModifierKey.altModifier: + return modifiers & modifierMod1 != 0; + case ModifierKey.metaModifier: + return modifiers & modifierMeta != 0; + case ModifierKey.capsLockModifier: + return modifiers & modifierCapsLock != 0; + case ModifierKey.numLockModifier: + return modifiers & modifierMod2 != 0; + case ModifierKey.functionModifier: + case ModifierKey.symbolModifier: + case ModifierKey.scrollLockModifier: + // These are not used in GTK keyboards. + return false; + } + } + + @override + KeyboardSide getModifierSide(ModifierKey key) { + // Neither GTK nor X11 provide a distinction between left and right + // modifiers, so defaults to KeyboardSide.all. + // https://code.woboq.org/qt5/include/X11/X.h.html#_M/ShiftMask + return KeyboardSide.all; + } + + @override + LogicalKeyboardKey? numpadKey(int keyCode) { + return kGtkNumpadMap[keyCode]; + } + + @override + LogicalKeyboardKey? logicalKey(int keyCode) { + return kGtkToLogicalKey[keyCode]; + } + + @override + int get platformPlane => LogicalKeyboardKey.gtkPlane; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_macos.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_macos.dart new file mode 100644 index 0000000000000000000000000000000000000000..0ab2fe5f098a01886c08bafdc4b77a17f555364a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_macos.dart @@ -0,0 +1,403 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'keyboard_maps.g.dart'; +import 'raw_keyboard.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; + +export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey; + +/// Convert a UTF32 rune to its lower case. +int runeToLowerCase(int rune) { + // Assume only Basic Multilingual Plane runes have lower and upper cases. + // For other characters, return them as is. + const int utf16BmpUpperBound = 0xD7FF; + if (rune > utf16BmpUpperBound) { + return rune; + } + return String.fromCharCode(rune).toLowerCase().codeUnitAt(0); +} + +/// Platform-specific key event data for macOS. +/// +/// This class is deprecated and will be removed. Platform specific key event +/// data will no longer be available. See [KeyEvent] for what is available. +/// +/// This object contains information about key events obtained from macOS's +/// `NSEvent` interface. +/// +/// See also: +/// +/// * [RawKeyboard], which uses this interface to expose key data. +@Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class RawKeyEventDataMacOs extends RawKeyEventData { + /// Creates a key event data structure specific for macOS. + @Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyEventDataMacOs({ + this.characters = '', + this.charactersIgnoringModifiers = '', + this.keyCode = 0, + this.modifiers = 0, + this.specifiedLogicalKey, + }); + + /// The Unicode characters associated with a key-up or key-down event. + /// + /// See also: + /// + /// * [Apple's NSEvent documentation](https://developer.apple.com/documentation/appkit/nsevent/1534183-characters?language=objc) + final String characters; + + /// The characters generated by a key event as if no modifier key (except for + /// Shift) applies. + /// + /// See also: + /// + /// * [Apple's NSEvent documentation](https://developer.apple.com/documentation/appkit/nsevent/1524605-charactersignoringmodifiers?language=objc) + final String charactersIgnoringModifiers; + + /// The virtual key code for the keyboard key associated with a key event. + /// + /// See also: + /// + /// * [Apple's NSEvent documentation](https://developer.apple.com/documentation/appkit/nsevent/1534513-keycode?language=objc) + final int keyCode; + + /// A mask of the current modifiers using the values in Modifier Flags. + /// + /// See also: + /// + /// * [Apple's NSEvent documentation](https://developer.apple.com/documentation/appkit/nsevent/1535211-modifierflags?language=objc) + final int modifiers; + + /// A logical key specified by the embedding that should be used instead of + /// deriving from raw data. + /// + /// The macOS embedding detects the keyboard layout and maps some keys to + /// logical keys in a way that can not be derived from per-key information. + /// + /// This is not part of the native macOS key event. + final int? specifiedLogicalKey; + + @override + String get keyLabel => charactersIgnoringModifiers; + + @override + PhysicalKeyboardKey get physicalKey => kMacOsToPhysicalKey[keyCode] ?? PhysicalKeyboardKey(LogicalKeyboardKey.windowsPlane + keyCode); + + @override + LogicalKeyboardKey get logicalKey { + if (specifiedLogicalKey != null) { + final int key = specifiedLogicalKey!; + return LogicalKeyboardKey.findKeyByKeyId(key) ?? LogicalKeyboardKey(key); + } + // Look to see if the keyCode is a printable number pad key, so that a + // difference between regular keys (e.g. "=") and the number pad version + // (e.g. the "=" on the number pad) can be determined. + final LogicalKeyboardKey? numPadKey = kMacOsNumPadMap[keyCode]; + if (numPadKey != null) { + return numPadKey; + } + + // Keys that can't be derived with characterIgnoringModifiers will be + // derived from their key codes using this map. + final LogicalKeyboardKey? knownKey = kMacOsToLogicalKey[keyCode]; + if (knownKey != null) { + return knownKey; + } + + // If this key is a single printable character, generate the + // LogicalKeyboardKey from its Unicode value. Control keys such as ESC, + // CTRL, and SHIFT are not printable. HOME, DEL, arrow keys, and function + // keys are considered modifier function keys, which generate invalid + // Unicode scalar values. Multi-char characters are also discarded. + int? character; + if (keyLabel.isNotEmpty) { + final List<int> codePoints = keyLabel.runes.toList(); + if (codePoints.length == 1 && + // Ideally we should test whether `codePoints[0]` is in the range. + // Since LogicalKeyboardKey.isControlCharacter and _isUnprintableKey + // only tests BMP, it is fine to test keyLabel instead. + !LogicalKeyboardKey.isControlCharacter(keyLabel) && + !_isUnprintableKey(keyLabel)) { + character = runeToLowerCase(codePoints[0]); + } + } + if (character != null) { + final int keyId = LogicalKeyboardKey.unicodePlane | (character & LogicalKeyboardKey.valueMask); + return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(keyId); + } + + // This is a non-printable key that we don't know about, so we mint a new + // code. + return LogicalKeyboardKey(keyCode | LogicalKeyboardKey.macosPlane); + } + + bool _isLeftRightModifierPressed(KeyboardSide side, int anyMask, int leftMask, int rightMask) { + if (modifiers & anyMask == 0) { + return false; + } + // If only the "anyMask" bit is set, then we respond true for requests of + // whether either left or right is pressed. Handles the case where macOS + // supplies just the "either" modifier flag, but not the left/right flag. + // (e.g. modifierShift but not modifierLeftShift). + final bool anyOnly = modifiers & (leftMask | rightMask | anyMask) == anyMask; + switch (side) { + case KeyboardSide.any: + return true; + case KeyboardSide.all: + return modifiers & leftMask != 0 && modifiers & rightMask != 0 || anyOnly; + case KeyboardSide.left: + return modifiers & leftMask != 0 || anyOnly; + case KeyboardSide.right: + return modifiers & rightMask != 0 || anyOnly; + } + } + + @override + bool isModifierPressed(ModifierKey key, {KeyboardSide side = KeyboardSide.any}) { + final int independentModifier = modifiers & deviceIndependentMask; + final bool result; + switch (key) { + case ModifierKey.controlModifier: + result = _isLeftRightModifierPressed(side, independentModifier & modifierControl, modifierLeftControl, modifierRightControl); + case ModifierKey.shiftModifier: + result = _isLeftRightModifierPressed(side, independentModifier & modifierShift, modifierLeftShift, modifierRightShift); + case ModifierKey.altModifier: + result = _isLeftRightModifierPressed(side, independentModifier & modifierOption, modifierLeftOption, modifierRightOption); + case ModifierKey.metaModifier: + result = _isLeftRightModifierPressed(side, independentModifier & modifierCommand, modifierLeftCommand, modifierRightCommand); + case ModifierKey.capsLockModifier: + result = independentModifier & modifierCapsLock != 0; + // On macOS, the function modifier bit is set for any function key, like F1, + // F2, etc., but the meaning of ModifierKey.modifierFunction in Flutter is + // that of the Fn modifier key, so there's no good way to emulate that on + // macOS. + case ModifierKey.functionModifier: + case ModifierKey.numLockModifier: + case ModifierKey.symbolModifier: + case ModifierKey.scrollLockModifier: + // These modifier masks are not used in macOS keyboards. + result = false; + } + assert(!result || getModifierSide(key) != null, "$runtimeType thinks that a modifier is pressed, but can't figure out what side it's on."); + return result; + } + + @override + KeyboardSide? getModifierSide(ModifierKey key) { + KeyboardSide? findSide(int anyMask, int leftMask, int rightMask) { + final int combinedMask = leftMask | rightMask; + final int combined = modifiers & combinedMask; + if (combined == leftMask) { + return KeyboardSide.left; + } else if (combined == rightMask) { + return KeyboardSide.right; + } else if (combined == combinedMask || modifiers & (combinedMask | anyMask) == anyMask) { + // Handles the case where macOS supplies just the "either" modifier + // flag, but not the left/right flag. (e.g. modifierShift but not + // modifierLeftShift), or if left and right flags are provided, but not + // the "either" modifier flag. + return KeyboardSide.all; + } + return null; + } + + switch (key) { + case ModifierKey.controlModifier: + return findSide(modifierControl, modifierLeftControl, modifierRightControl); + case ModifierKey.shiftModifier: + return findSide(modifierShift, modifierLeftShift, modifierRightShift); + case ModifierKey.altModifier: + return findSide(modifierOption, modifierLeftOption, modifierRightOption); + case ModifierKey.metaModifier: + return findSide(modifierCommand, modifierLeftCommand, modifierRightCommand); + case ModifierKey.capsLockModifier: + case ModifierKey.numLockModifier: + case ModifierKey.scrollLockModifier: + case ModifierKey.functionModifier: + case ModifierKey.symbolModifier: + return KeyboardSide.all; + } + } + + @override + bool shouldDispatchEvent() { + // On macOS laptop keyboards, the fn key is used to generate home/end and + // f1-f12, but it ALSO generates a separate down/up event for the fn key + // itself. Other platforms hide the fn key, and just produce the key that + // it is combined with, so to keep it possible to write cross platform + // code that looks at which keys are pressed, the fn key is ignored on + // macOS. + return logicalKey != LogicalKeyboardKey.fn; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('characters', characters)); + properties.add(DiagnosticsProperty<String>('charactersIgnoringModifiers', charactersIgnoringModifiers)); + properties.add(DiagnosticsProperty<int>('keyCode', keyCode)); + properties.add(DiagnosticsProperty<int>('modifiers', modifiers)); + properties.add(DiagnosticsProperty<int?>('specifiedLogicalKey', specifiedLogicalKey, defaultValue: null)); + } + + @override + bool operator==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is RawKeyEventDataMacOs + && other.characters == characters + && other.charactersIgnoringModifiers == charactersIgnoringModifiers + && other.keyCode == keyCode + && other.modifiers == modifiers; + } + + @override + int get hashCode => Object.hash( + characters, + charactersIgnoringModifiers, + keyCode, + modifiers, + ); + + /// Returns true if the given label represents an unprintable key. + /// + /// Examples of unprintable keys are "NSUpArrowFunctionKey = 0xF700" + /// or "NSHomeFunctionKey = 0xF729". + /// + /// See <https://developer.apple.com/documentation/appkit/1535851-function-key_unicodes?language=objc> for more + /// information. + /// + /// Used by [RawKeyEvent] subclasses to help construct IDs. + static bool _isUnprintableKey(String label) { + if (label.length != 1) { + return false; + } + final int codeUnit = label.codeUnitAt(0); + return codeUnit >= 0xF700 && codeUnit <= 0xF8FF; + } + + // Modifier key masks. See Apple's NSEvent documentation + // https://developer.apple.com/documentation/appkit/nseventmodifierflags?language=objc + // https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-86/IOHIDSystem/IOKit/hidsystem/IOLLEvent.h.auto.html + + /// This mask is used to check the [modifiers] field to test whether the CAPS + /// LOCK modifier key is on. + /// + /// {@template flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + /// {@endtemplate} + static const int modifierCapsLock = 0x10000; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// SHIFT modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierShift = 0x20000; + + /// This mask is used to check the [modifiers] field to test whether the left + /// SHIFT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierLeftShift = 0x02; + + /// This mask is used to check the [modifiers] field to test whether the right + /// SHIFT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierRightShift = 0x04; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// CTRL modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierControl = 0x40000; + + /// This mask is used to check the [modifiers] field to test whether the left + /// CTRL modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierLeftControl = 0x01; + + /// This mask is used to check the [modifiers] field to test whether the right + /// CTRL modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierRightControl = 0x2000; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// ALT modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierOption = 0x80000; + + /// This mask is used to check the [modifiers] field to test whether the left + /// ALT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierLeftOption = 0x20; + + /// This mask is used to check the [modifiers] field to test whether the right + /// ALT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierRightOption = 0x40; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// CMD modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierCommand = 0x100000; + + /// This mask is used to check the [modifiers] field to test whether the left + /// CMD modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierLeftCommand = 0x08; + + /// This mask is used to check the [modifiers] field to test whether the right + /// CMD modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierRightCommand = 0x10; + + /// This mask is used to check the [modifiers] field to test whether any key in + /// the numeric keypad is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierNumericPad = 0x200000; + + /// This mask is used to check the [modifiers] field to test whether the + /// HELP modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierHelp = 0x400000; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// FUNCTION modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataMacOs.modifierCapsLock} + static const int modifierFunction = 0x800000; + + /// Used to retrieve only the device-independent modifier flags, allowing + /// applications to mask off the device-dependent modifier flags, including + /// event coalescing information. + static const int deviceIndependentMask = 0xffff0000; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_web.dart new file mode 100644 index 0000000000000000000000000000000000000000..e361d9aa4fb9865c2c7b3c06fc0e903b68ceaf81 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_web.dart @@ -0,0 +1,269 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'keyboard_maps.g.dart'; +import 'raw_keyboard.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; + +export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey; + +String? _unicodeChar(String key) { + if (key.length == 1) { + return key.substring(0, 1); + } + return null; +} + +/// Platform-specific key event data for Web. +/// +/// This class is DEPRECATED. Platform specific key event data will no longer +/// available. See [KeyEvent] for what is available. +/// +/// See also: +/// +/// * [RawKeyboard], which uses this interface to expose key data. +@Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +@immutable +class RawKeyEventDataWeb extends RawKeyEventData { + /// Creates a key event data structure specific for Web. + @Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyEventDataWeb({ + required this.code, + required this.key, + this.location = 0, + this.metaState = modifierNone, + this.keyCode = 0, + }); + + /// The `KeyboardEvent.code` corresponding to this event. + /// + /// The [code] represents a physical key on the keyboard, a value that isn't + /// altered by keyboard layout or the state of the modifier keys. + /// + /// See <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code> + /// for more information. + final String code; + + /// The `KeyboardEvent.key` corresponding to this event. + /// + /// The [key] represents the key pressed by the user, taking into + /// consideration the state of modifier keys such as Shift as well as the + /// keyboard locale and layout. + /// + /// See <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key> + /// for more information. + final String key; + + /// The `KeyboardEvent.location` corresponding to this event. + /// + /// The [location] represents the location of the key on the keyboard or other + /// input device, such as left or right modifier keys, or Numpad keys. + /// + /// See <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/location> + /// for more information. + final int location; + + /// The modifiers that were present when the key event occurred. + /// + /// See `lib/src/engine/keyboard.dart` in the web engine for the numerical + /// values of the [metaState]. These constants are also replicated as static + /// constants in this class. + /// + /// See also: + /// + /// * [modifiersPressed], which returns a Map of currently pressed modifiers + /// and their keyboard side. + /// * [isModifierPressed], to see if a specific modifier is pressed. + /// * [isControlPressed], to see if a CTRL key is pressed. + /// * [isShiftPressed], to see if a SHIFT key is pressed. + /// * [isAltPressed], to see if an ALT key is pressed. + /// * [isMetaPressed], to see if a META key is pressed. + final int metaState; + + /// The `KeyboardEvent.keyCode` corresponding to this event. + /// + /// See <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode> + /// for more information. + final int keyCode; + + @override + String get keyLabel => key == 'Unidentified' ? '' : _unicodeChar(key) ?? ''; + + @override + PhysicalKeyboardKey get physicalKey { + return kWebToPhysicalKey[code] ?? PhysicalKeyboardKey(LogicalKeyboardKey.webPlane + code.hashCode); + } + + @override + LogicalKeyboardKey get logicalKey { + // Look to see if the keyCode is a key based on location. Typically they are + // numpad keys (versus main area keys) and left/right modifiers. + final LogicalKeyboardKey? maybeLocationKey = kWebLocationMap[key]?[location]; + if (maybeLocationKey != null) { + return maybeLocationKey; + } + + // Look to see if the [key] is one we know about and have a mapping for. + final LogicalKeyboardKey? newKey = kWebToLogicalKey[key]; + if (newKey != null) { + return newKey; + } + + final bool isPrintable = key.length == 1; + if (isPrintable) { + return LogicalKeyboardKey(key.toLowerCase().codeUnitAt(0)); + } + + // This is a non-printable key that we don't know about, so we mint a new + // key from `code`. Don't mint with `key`, because the `key` will always be + // "Unidentified" . + return LogicalKeyboardKey(code.hashCode + LogicalKeyboardKey.webPlane); + } + + @override + bool isModifierPressed( + ModifierKey key, { + KeyboardSide side = KeyboardSide.any, + }) { + switch (key) { + case ModifierKey.controlModifier: + return metaState & modifierControl != 0; + case ModifierKey.shiftModifier: + return metaState & modifierShift != 0; + case ModifierKey.altModifier: + return metaState & modifierAlt != 0; + case ModifierKey.metaModifier: + return metaState & modifierMeta != 0; + case ModifierKey.numLockModifier: + return metaState & modifierNumLock != 0; + case ModifierKey.capsLockModifier: + return metaState & modifierCapsLock != 0; + case ModifierKey.scrollLockModifier: + return metaState & modifierScrollLock != 0; + case ModifierKey.functionModifier: + case ModifierKey.symbolModifier: + // On Web, the browser doesn't report the state of the FN and SYM modifiers. + return false; + } + } + + @override + KeyboardSide getModifierSide(ModifierKey key) { + // On Web, we don't distinguish the sides of modifier keys. Both left shift + // and right shift, for example, are reported as the "Shift" modifier. + // + // See <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState> + // for more information. + return KeyboardSide.any; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('code', code)); + properties.add(DiagnosticsProperty<String>('key', key)); + properties.add(DiagnosticsProperty<int>('location', location)); + properties.add(DiagnosticsProperty<int>('metaState', metaState)); + properties.add(DiagnosticsProperty<int>('keyCode', keyCode)); + } + + @override + bool operator==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is RawKeyEventDataWeb + && other.code == code + && other.key == key + && other.location == location + && other.metaState == metaState + && other.keyCode == keyCode; + } + + @override + int get hashCode => Object.hash( + code, + key, + location, + metaState, + keyCode, + ); + + // Modifier key masks. + + /// No modifier keys are pressed in the [metaState] field. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierNone = 0; + + /// This mask is used to check the [metaState] field to test whether one of + /// the SHIFT modifier keys is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierShift = 0x01; + + /// This mask is used to check the [metaState] field to test whether one of + /// the ALT modifier keys is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierAlt = 0x02; + + /// This mask is used to check the [metaState] field to test whether one of + /// the CTRL modifier keys is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierControl = 0x04; + + /// This mask is used to check the [metaState] field to test whether one of + /// the META modifier keys is pressed. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierMeta = 0x08; + + /// This mask is used to check the [metaState] field to test whether the NUM + /// LOCK modifier key is on. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierNumLock = 0x10; + + /// This mask is used to check the [metaState] field to test whether the CAPS + /// LOCK modifier key is on. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierCapsLock = 0x20; + + /// This mask is used to check the [metaState] field to test whether the + /// SCROLL LOCK modifier key is on. + /// + /// Use this value if you need to decode the [metaState] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + static const int modifierScrollLock = 0x40; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_windows.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_windows.dart new file mode 100644 index 0000000000000000000000000000000000000000..8d43ea1a886c619702a843d7baa84e6e997af76e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/raw_keyboard_windows.dart @@ -0,0 +1,325 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'keyboard_maps.g.dart'; +import 'raw_keyboard.dart'; + +export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder; + +export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey; + +// Virtual key VK_PROCESSKEY in Win32 API. +// +// Key down events related to IME operations use this as keyCode. +const int _vkProcessKey = 0xe5; + +/// Platform-specific key event data for Windows. +/// +/// This class is DEPRECATED. Platform specific key event data will no longer +/// available. See [KeyEvent] for what is available. +/// +/// This object contains information about key events obtained from Windows's +/// win32 API. +/// +/// See also: +/// +/// * [RawKeyboard], which uses this interface to expose key data. +@Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class RawKeyEventDataWindows extends RawKeyEventData { + /// Creates a key event data structure specific for Windows. + @Deprecated( + 'Platform specific key event data is no longer available. See KeyEvent for what is available. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyEventDataWindows({ + this.keyCode = 0, + this.scanCode = 0, + this.characterCodePoint = 0, + this.modifiers = 0, + }); + + /// The hardware key code corresponding to this key event. + /// + /// This is the physical key that was pressed, not the Unicode character. + /// See [characterCodePoint] for the Unicode character. + final int keyCode; + + /// The hardware scan code id corresponding to this key event. + /// + /// These values are not reliable and vary from device to device, so this + /// information is mainly useful for debugging. + final int scanCode; + + /// The Unicode code point represented by the key event, if any. + /// + /// If there is no Unicode code point, this value is zero. + final int characterCodePoint; + + /// A mask of the current modifiers. The modifier values must be in sync with + /// the ones defined in https://github.com/flutter/engine/blob/master/shell/platform/windows/key_event_handler.cc + final int modifiers; + + @override + String get keyLabel => characterCodePoint == 0 ? '' : String.fromCharCode(characterCodePoint); + + @override + PhysicalKeyboardKey get physicalKey => kWindowsToPhysicalKey[scanCode] ?? PhysicalKeyboardKey(LogicalKeyboardKey.windowsPlane + scanCode); + + @override + LogicalKeyboardKey get logicalKey { + // Look to see if the keyCode is a printable number pad key, so that a + // difference between regular keys (e.g. "=") and the number pad version + // (e.g. the "=" on the number pad) can be determined. + final LogicalKeyboardKey? numPadKey = kWindowsNumPadMap[keyCode]; + if (numPadKey != null) { + return numPadKey; + } + + // If it has a non-control-character label, then either return the existing + // constant, or construct a new Unicode-based key from it. Don't mark it as + // autogenerated, since the label uniquely identifies an ID from the Unicode + // plane. + if (keyLabel.isNotEmpty && !LogicalKeyboardKey.isControlCharacter(keyLabel)) { + final int keyId = LogicalKeyboardKey.unicodePlane | (characterCodePoint & LogicalKeyboardKey.valueMask); + return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(keyId); + } + // Look to see if the keyCode is one we know about and have a mapping for. + final LogicalKeyboardKey? newKey = kWindowsToLogicalKey[keyCode]; + if (newKey != null) { + return newKey; + } + + // This is a non-printable key that we don't know about, so we mint a new + // code. + return LogicalKeyboardKey(keyCode | LogicalKeyboardKey.windowsPlane); + } + + bool _isLeftRightModifierPressed(KeyboardSide side, int anyMask, int leftMask, int rightMask) { + if (modifiers & anyMask == 0 && + modifiers & leftMask == 0 && + modifiers & rightMask == 0) { + return false; + } + // If only the "anyMask" bit is set, then we respond true for requests of + // whether either left or right is pressed. Handles the case where Windows + // supplies just the "either" modifier flag, but not the left/right flag. + // (e.g. modifierShift but not modifierLeftShift). + final bool anyOnly = modifiers & (leftMask | rightMask | anyMask) == anyMask; + switch (side) { + case KeyboardSide.any: + return true; + case KeyboardSide.all: + return modifiers & leftMask != 0 && modifiers & rightMask != 0 || anyOnly; + case KeyboardSide.left: + return modifiers & leftMask != 0 || anyOnly; + case KeyboardSide.right: + return modifiers & rightMask != 0 || anyOnly; + } + } + + @override + bool isModifierPressed(ModifierKey key, {KeyboardSide side = KeyboardSide.any}) { + final bool result; + switch (key) { + case ModifierKey.controlModifier: + result = _isLeftRightModifierPressed(side, modifierControl, modifierLeftControl, modifierRightControl); + case ModifierKey.shiftModifier: + result = _isLeftRightModifierPressed(side, modifierShift, modifierLeftShift, modifierRightShift); + case ModifierKey.altModifier: + result = _isLeftRightModifierPressed(side, modifierAlt, modifierLeftAlt, modifierRightAlt); + case ModifierKey.metaModifier: + // Windows does not provide an "any" key for win key press. + result = _isLeftRightModifierPressed(side, modifierLeftMeta | modifierRightMeta , modifierLeftMeta, modifierRightMeta); + case ModifierKey.capsLockModifier: + result = modifiers & modifierCaps != 0; + case ModifierKey.scrollLockModifier: + result = modifiers & modifierScrollLock != 0; + case ModifierKey.numLockModifier: + result = modifiers & modifierNumLock != 0; + // The OS does not expose the Fn key to the drivers, it doesn't generate a key message. + case ModifierKey.functionModifier: + case ModifierKey.symbolModifier: + // These modifier masks are not used in Windows keyboards. + result = false; + } + assert(!result || getModifierSide(key) != null, "$runtimeType thinks that a modifier is pressed, but can't figure out what side it's on."); + return result; + } + + + @override + KeyboardSide? getModifierSide(ModifierKey key) { + KeyboardSide? findSide(int leftMask, int rightMask, int anyMask) { + final int combinedMask = leftMask | rightMask; + final int combined = modifiers & combinedMask; + if (combined == leftMask) { + return KeyboardSide.left; + } else if (combined == rightMask) { + return KeyboardSide.right; + } else if (combined == combinedMask || modifiers & (combinedMask | anyMask) == anyMask) { + // Handles the case where Windows supplies just the "either" modifier + // flag, but not the left/right flag. (e.g. modifierShift but not + // modifierLeftShift). + return KeyboardSide.all; + } + return null; + } + + switch (key) { + case ModifierKey.controlModifier: + return findSide(modifierLeftControl, modifierRightControl, modifierControl); + case ModifierKey.shiftModifier: + return findSide(modifierLeftShift, modifierRightShift, modifierShift); + case ModifierKey.altModifier: + return findSide(modifierLeftAlt, modifierRightAlt, modifierAlt); + case ModifierKey.metaModifier: + return findSide(modifierLeftMeta, modifierRightMeta, 0); + case ModifierKey.capsLockModifier: + case ModifierKey.numLockModifier: + case ModifierKey.scrollLockModifier: + case ModifierKey.functionModifier: + case ModifierKey.symbolModifier: + return KeyboardSide.all; + } + } + + @override + bool shouldDispatchEvent() { + // In Win32 API, down events related to IME operations use VK_PROCESSKEY as + // keyCode. This event, as well as the following key up event (which uses a + // normal keyCode), should be skipped, because the effect of IME operations + // will be handled by the text input API. + return keyCode != _vkProcessKey; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<int>('keyCode', keyCode)); + properties.add(DiagnosticsProperty<int>('scanCode', scanCode)); + properties.add(DiagnosticsProperty<int>('characterCodePoint', characterCodePoint)); + properties.add(DiagnosticsProperty<int>('modifiers', modifiers)); + } + + @override + bool operator==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is RawKeyEventDataWindows + && other.keyCode == keyCode + && other.scanCode == scanCode + && other.characterCodePoint == characterCodePoint + && other.modifiers == modifiers; + } + + @override + int get hashCode => Object.hash( + keyCode, + scanCode, + characterCodePoint, + modifiers, + ); + + // These are not the values defined by the Windows header for each modifier. Since they + // can't be packaged into a single int, we are re-defining them here to reduce the size + // of the message from the embedder. Embedders should map these values to the native key codes. + // Keep this in sync with https://github.com/flutter/engine/blob/master/shell/platform/windows/key_event_handler.cc + + /// This mask is used to check the [modifiers] field to test whether one of the + /// SHIFT modifier keys is pressed. + /// + /// {@template flutter.services.RawKeyEventDataWindows.modifierShift} + /// Use this value if you need to decode the [modifiers] field yourself, but + /// it's much easier to use [isModifierPressed] if you just want to know if + /// a modifier is pressed. + /// {@endtemplate} + static const int modifierShift = 1 << 0; + + /// This mask is used to check the [modifiers] field to test whether the left + /// SHIFT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierLeftShift = 1 << 1; + + /// This mask is used to check the [modifiers] field to test whether the right + /// SHIFT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierRightShift = 1 << 2; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// CTRL modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierControl = 1 << 3; + + /// This mask is used to check the [modifiers] field to test whether the left + /// CTRL modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierLeftControl = 1 << 4; + + /// This mask is used to check the [modifiers] field to test whether the right + /// CTRL modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierRightControl = 1 << 5; + + /// This mask is used to check the [modifiers] field to test whether one of the + /// ALT modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierAlt = 1 << 6; + + /// This mask is used to check the [modifiers] field to test whether the left + /// ALT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierLeftAlt = 1 << 7; + + /// This mask is used to check the [modifiers] field to test whether the right + /// ALT modifier key is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierRightAlt = 1 << 8; + + /// This mask is used to check the [modifiers] field to test whether the left + /// WIN modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierLeftMeta = 1 << 9; + + /// This mask is used to check the [modifiers] field to test whether the right + /// WIN modifier keys is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierRightMeta = 1 << 10; + + /// This mask is used to check the [modifiers] field to test whether the CAPS LOCK key + /// is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierCaps = 1 << 11; + + /// This mask is used to check the [modifiers] field to test whether the NUM LOCK key + /// is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierNumLock = 1 << 12; + + /// This mask is used to check the [modifiers] field to test whether the SCROLL LOCK key + /// is pressed. + /// + /// {@macro flutter.services.RawKeyEventDataWindows.modifierShift} + static const int modifierScrollLock = 1 << 13; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/restoration.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/restoration.dart new file mode 100644 index 0000000000000000000000000000000000000000..d49af9183dd6f8cb8ebd9e64ff431b86ef4bc4ba --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/restoration.dart @@ -0,0 +1,1032 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; + +import 'message_codecs.dart'; +import 'system_channels.dart'; + +export 'dart:typed_data' show Uint8List; + +typedef _BucketVisitor = void Function(RestorationBucket bucket); + +/// Manages the restoration data in the framework and synchronizes it with the +/// engine. +/// +/// Restoration data can be serialized out and - at a later point in time - be +/// used to restore the application to the previous state described by the +/// serialized data. Mobile operating systems use the concept of state +/// restoration to provide the illusion that apps continue to run in the +/// background forever: after an app has been backgrounded, the user can always +/// return to it and find it in the same state. In practice, the operating +/// system may, however, terminate the app to free resources for other apps +/// running in the foreground. Before that happens, the app gets a chance to +/// serialize out its restoration data. When the user navigates back to the +/// backgrounded app, it is restarted and the serialized restoration data is +/// provided to it again. Ideally, the app will use that data to restore itself +/// to the same state it was in when the user backgrounded the app. +/// +/// In Flutter, restoration data is organized in a tree of [RestorationBucket]s +/// which is rooted in the [rootBucket]. All information that the application +/// needs to restore its current state must be stored in a bucket in this +/// hierarchy. To store data in the hierarchy, entities (e.g. [Widget]s) must +/// claim ownership of a child bucket from a parent bucket (which may be the +/// [rootBucket] provided by this [RestorationManager]). The owner of a bucket +/// may store arbitrary values in the bucket as long as they can be serialized +/// with the [StandardMessageCodec]. The values are stored in the bucket under a +/// given restoration ID as key. A restoration ID is a [String] that must be +/// unique within a given bucket. To access the stored value again during state +/// restoration, the same restoration ID must be provided again. The owner of +/// the bucket may also make the bucket available to other entities so that they +/// can claim child buckets from it for their own restoration needs. Within a +/// bucket, child buckets are also identified by unique restoration IDs. The +/// restoration ID must be provided when claiming a child bucket. +/// +/// When restoration data is provided to the [RestorationManager] (e.g. after +/// the application relaunched when foregrounded again), the bucket hierarchy +/// with all the data stored in it is restored. Entities can retrieve the data +/// again by using the same restoration IDs that they originally used to store +/// the data. +/// +/// In addition to providing restoration data when the app is launched, +/// restoration data may also be provided to a running app to restore it to a +/// previous state (e.g. when the user hits the back/forward button in the web +/// browser). When this happens, the [RestorationManager] notifies its listeners +/// (added via [addListener]) that a new [rootBucket] is available. In response +/// to the notification, listeners must stop using the old bucket and restore +/// their state from the information in the new [rootBucket]. +/// +/// Some platforms restrict the size of the restoration data. Therefore, the +/// data stored in the buckets should be as small as possible while still +/// allowing the app to restore its current state from it. Data that can be +/// retrieved from other services (e.g. a database or a web server) should not +/// be included in the restoration data. Instead, a small identifier (e.g. a +/// UUID, database record number, or resource locator) should be stored that can +/// be used to retrieve the data again from its original source during state +/// restoration. +/// +/// The [RestorationManager] sends a serialized version of the bucket hierarchy +/// over to the engine at the end of a frame in which the data in the hierarchy +/// or its shape has changed. The engine caches the data until the operating +/// system needs it. The application is responsible for keeping the data in the +/// bucket always up-to-date to reflect its current state. +/// +/// ## Discussion +/// +/// Due to Flutter's threading model and restrictions in the APIs of the +/// platforms Flutter runs on, restoration data must be stored in the buckets +/// proactively as described above. When the operating system asks for the +/// restoration data, it will do so on the platform thread expecting a +/// synchronous response. To avoid the risk of deadlocks, the platform thread +/// cannot block and call into the UI thread (where the dart code is running) to +/// retrieve the restoration data. For this reason, the [RestorationManager] +/// always sends the latest copy of the restoration data from the UI thread over +/// to the platform thread whenever it changes. That way, the restoration data +/// is always ready to go on the platform thread when the operating system needs +/// it. +/// +/// ## State Restoration on iOS +/// +/// To enable state restoration on iOS, a restoration identifier has to be +/// assigned to the [FlutterViewController](/ios-embedder/interface_flutter_view_controller.html). +/// If the standard embedding (produced by `flutter create`) is used, this can +/// be accomplished with the following steps: +/// +/// 1. In the app's directory, open `ios/Runner.xcodeproj` with Xcode. +/// 2. Select `Main.storyboard` under `Runner/Runner` in the Project Navigator +/// on the left. +/// 3. Select the `Flutter View Controller` under +/// `Flutter View Controller Scene` in the view hierarchy. +/// 4. Navigate to the Identity Inspector in the panel on the right. +/// 5. Enter a unique restoration ID in the provided field. +/// 6. Save the project. +/// +/// ## Development with hot restart and hot reload +/// +/// Changes applied to your app with hot reload and hot restart are not +/// persisted on the device. They are lost when the app is fully terminated and +/// restarted, e.g. by the operating system. Therefore, your app may not restore +/// correctly during development if you have made changes and applied them with +/// hot restart or hot reload. To test state restoration, always make sure to +/// fully re-compile your application (e.g. by re-executing `flutter run`) after +/// making a change. +/// +/// ## Testing State Restoration +/// +/// {@template flutter.widgets.RestorationManager} +/// To test state restoration on Android: +/// 1. Turn on "Don't keep activities", which destroys the Android activity +/// as soon as the user leaves it. This option should become available +/// when Developer Options are turned on for the device. +/// 2. Run the code sample on an Android device. +/// 3. Create some in-memory state in the app on the phone, +/// e.g. by navigating to a different screen. +/// 4. Background the Flutter app, then return to it. It will restart +/// and restore its state. +/// +/// To test state restoration on iOS: +/// 1. Open `ios/Runner.xcworkspace/` in Xcode. +/// 2. (iOS 14+ only): Switch to build in profile or release mode, as +/// launching an app from the home screen is not supported in debug +/// mode. +/// 2. Press the Play button in Xcode to build and run the app. +/// 3. Create some in-memory state in the app on the phone, +/// e.g. by navigating to a different screen. +/// 4. Background the app on the phone, e.g. by going back to the home screen. +/// 5. Press the Stop button in Xcode to terminate the app while running in +/// the background. +/// 6. Open the app again on the phone (not via Xcode). It will restart +/// and restore its state. +/// {@endtemplate} +/// +/// See also: +/// +/// * [ServicesBinding.restorationManager], which holds the singleton instance +/// of the [RestorationManager] for the currently running application. +/// * [RestorationBucket], which make up the restoration data hierarchy. +/// * [RestorationMixin], which uses [RestorationBucket]s behind the scenes +/// to make [State] objects of [StatefulWidget]s restorable. +class RestorationManager extends ChangeNotifier { + /// Construct the restoration manager and set up the communications channels + /// with the engine to get restoration messages (by calling [initChannels]). + RestorationManager() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + initChannels(); + } + + /// Sets up the method call handler for [SystemChannels.restoration]. + /// + /// This is called by the constructor to configure the communications channel + /// with the Flutter engine to get restoration messages. + /// + /// Subclasses (especially in tests) can override this to avoid setting up + /// that communications channel, or to set it up differently, as necessary. + @protected + void initChannels() { + SystemChannels.restoration.setMethodCallHandler(_methodHandler); + } + + /// The root of the [RestorationBucket] hierarchy containing the restoration + /// data. + /// + /// Child buckets can be claimed from this bucket via + /// [RestorationBucket.claimChild]. If the [RestorationManager] has been asked + /// to restore the application to a previous state, these buckets will contain + /// the previously stored data. Otherwise the root bucket (and all children + /// claimed from it) will be empty. + /// + /// The [RestorationManager] informs its listeners (added via [addListener]) + /// when the value returned by this getter changes. This happens when new + /// restoration data has been provided to the [RestorationManager] to restore + /// the application to a different state. In response to the notification, + /// listeners must stop using the old root bucket and obtain the new one via + /// this getter ([rootBucket] will have been updated to return the new bucket + /// just before the listeners are notified). + /// + /// The restoration data describing the current bucket hierarchy is retrieved + /// asynchronously from the engine the first time the root bucket is accessed + /// via this getter. After the data has been copied over from the engine, this + /// getter will return a [SynchronousFuture], that immediately resolves to the + /// root [RestorationBucket]. + /// + /// The returned [Future] may resolve to null if state restoration is + /// currently turned off. + /// + /// See also: + /// + /// * [RootRestorationScope], which makes the root bucket available in the + /// [Widget] tree. + Future<RestorationBucket?> get rootBucket { + if (_rootBucketIsValid) { + return SynchronousFuture<RestorationBucket?>(_rootBucket); + } + if (_pendingRootBucket == null) { + _pendingRootBucket = Completer<RestorationBucket?>(); + _getRootBucketFromEngine(); + } + return _pendingRootBucket!.future; + } + RestorationBucket? _rootBucket; // May be null to indicate that restoration is turned off. + Completer<RestorationBucket?>? _pendingRootBucket; + bool _rootBucketIsValid = false; + + /// Returns true for the frame after [rootBucket] has been replaced with a + /// new non-null bucket. + /// + /// When true, entities should forget their current state and restore + /// their state according to the information in the new [rootBucket]. + /// + /// The [RestorationManager] informs its listeners (added via [addListener]) + /// when this flag changes from false to true. + bool get isReplacing => _isReplacing; + bool _isReplacing = false; + + Future<void> _getRootBucketFromEngine() async { + final Map<Object?, Object?>? config = await SystemChannels.restoration.invokeMethod<Map<Object?, Object?>>('get'); + if (_pendingRootBucket == null) { + // The restoration data was obtained via other means (e.g. by calling + // [handleRestorationDataUpdate] while the request to the engine was + // outstanding. Ignore the engine's response. + return; + } + assert(_rootBucket == null); + _parseAndHandleRestorationUpdateFromEngine(config); + } + + void _parseAndHandleRestorationUpdateFromEngine(Map<Object?, Object?>? update) { + handleRestorationUpdateFromEngine( + enabled: update != null && update['enabled']! as bool, + data: update == null ? null : update['data'] as Uint8List?, + ); + } + + /// Called by the [RestorationManager] on itself to parse the restoration + /// information obtained from the engine. + /// + /// The `enabled` parameter indicates whether the engine wants to receive + /// restoration data. When `enabled` is false, state restoration is turned + /// off and the [rootBucket] is set to null. When `enabled` is true, the + /// provided restoration `data` will be parsed into a new [rootBucket]. If + /// `data` is null, an empty [rootBucket] will be instantiated. + /// + /// Subclasses in test frameworks may call this method at any time to inject + /// restoration data (obtained e.g. by overriding [sendToEngine]) into the + /// [RestorationManager]. When the method is called before the [rootBucket] is + /// accessed, [rootBucket] will complete synchronously the next time it is + /// called. + @protected + void handleRestorationUpdateFromEngine({required bool enabled, required Uint8List? data}) { + assert(enabled || data == null); + + _isReplacing = _rootBucketIsValid && enabled; + if (_isReplacing) { + SchedulerBinding.instance.addPostFrameCallback((Duration _) { + _isReplacing = false; + }, debugLabel: 'RestorationManager.resetIsReplacing'); + } + + final RestorationBucket? oldRoot = _rootBucket; + _rootBucket = enabled + ? RestorationBucket.root(manager: this, rawData: _decodeRestorationData(data)) + : null; + _rootBucketIsValid = true; + assert(_pendingRootBucket == null || !_pendingRootBucket!.isCompleted); + _pendingRootBucket?.complete(_rootBucket); + _pendingRootBucket = null; + + if (_rootBucket != oldRoot) { + notifyListeners(); + oldRoot?.dispose(); + } + } + + /// Called by the [RestorationManager] on itself to send the provided + /// encoded restoration data to the engine. + /// + /// The `encodedData` describes the entire bucket hierarchy that makes up the + /// current restoration data. + /// + /// Subclasses in test frameworks may override this method to capture the + /// restoration data that would have been send to the engine. The captured + /// data can be re-injected into the [RestorationManager] via the + /// [handleRestorationUpdateFromEngine] method to restore the state described + /// by the data. + @protected + Future<void> sendToEngine(Uint8List encodedData) { + return SystemChannels.restoration.invokeMethod<void>( + 'put', + encodedData, + ); + } + + Future<void> _methodHandler(MethodCall call) async { + switch (call.method) { + case 'push': + _parseAndHandleRestorationUpdateFromEngine(call.arguments as Map<Object?, Object?>); + default: + throw UnimplementedError("${call.method} was invoked but isn't implemented by $runtimeType"); + } + } + + Map<Object?, Object?>? _decodeRestorationData(Uint8List? data) { + if (data == null) { + return null; + } + final ByteData encoded = data.buffer.asByteData(data.offsetInBytes, data.lengthInBytes); + return const StandardMessageCodec().decodeMessage(encoded) as Map<Object?, Object?>?; + } + + Uint8List _encodeRestorationData(Map<Object?, Object?> data) { + final ByteData encoded = const StandardMessageCodec().encodeMessage(data)!; + return encoded.buffer.asUint8List(encoded.offsetInBytes, encoded.lengthInBytes); + } + + bool _debugDoingUpdate = false; + bool _serializationScheduled = false; + + final Set<RestorationBucket> _bucketsNeedingSerialization = <RestorationBucket>{}; + + /// Called by a [RestorationBucket] to request serialization for that bucket. + /// + /// This method is called by a bucket in the hierarchy whenever the data + /// in it or the shape of the hierarchy has changed. + /// + /// Calling this is a no-op when the bucket is already scheduled for + /// serialization. + /// + /// It is exposed to allow testing of [RestorationBucket]s in isolation. + @protected + @visibleForTesting + void scheduleSerializationFor(RestorationBucket bucket) { + assert(bucket._manager == this); + assert(!_debugDoingUpdate); + _bucketsNeedingSerialization.add(bucket); + if (!_serializationScheduled) { + _serializationScheduled = true; + SchedulerBinding.instance.addPostFrameCallback( + (Duration _) => _doSerialization(), + debugLabel: 'RestorationManager.doSerialization' + ); + } + } + + /// Called by a [RestorationBucket] to unschedule a request for serialization. + /// + /// This method is called by a bucket in the hierarchy whenever it no longer + /// needs to be serialized (e.g. because the bucket got disposed). + /// + /// It is safe to call this even when the bucket wasn't scheduled for + /// serialization before. + /// + /// It is exposed to allow testing of [RestorationBucket]s in isolation. + @protected + @visibleForTesting + void unscheduleSerializationFor(RestorationBucket bucket) { + assert(bucket._manager == this); + assert(!_debugDoingUpdate); + _bucketsNeedingSerialization.remove(bucket); + } + + void _doSerialization() { + if (!_serializationScheduled) { + return; + } + assert(() { + _debugDoingUpdate = true; + return true; + }()); + _serializationScheduled = false; + + for (final RestorationBucket bucket in _bucketsNeedingSerialization) { + bucket.finalize(); + } + _bucketsNeedingSerialization.clear(); + sendToEngine(_encodeRestorationData(_rootBucket!._rawData)); + + assert(() { + _debugDoingUpdate = false; + return true; + }()); + } + + /// Called to manually flush the restoration data to the engine. + /// + /// A change in restoration data is usually accompanied by scheduling a frame + /// (because the restoration data is modified inside a [State.setState] call, + /// because it is usually something that affects the interface). Restoration + /// data is automatically flushed to the engine at the end of a frame. As a + /// result, it is uncommon to need to call this method directly. However, if + /// restoration data is changed without triggering a frame, this method must + /// be called to ensure that the updated restoration data is sent to the + /// engine in a timely manner. An example of such a use case is the + /// [Scrollable], where the final scroll offset after a scroll activity + /// finishes is determined between frames without scheduling a new frame. + /// + /// Calling this method is a no-op if a frame is already scheduled. In that + /// case, the restoration data will be flushed to the engine at the end of + /// that frame. If this method is called and no frame is scheduled, the + /// current restoration data is directly sent to the engine. + void flushData() { + assert(!_debugDoingUpdate); + if (SchedulerBinding.instance.hasScheduledFrame) { + return; + } + _doSerialization(); + assert(!_serializationScheduled); + } + + @override + void dispose() { + _rootBucket?.dispose(); + super.dispose(); + } +} + +/// A [RestorationBucket] holds pieces of the restoration data that a part of +/// the application needs to restore its state. +/// +/// For a general overview of how state restoration works in Flutter, see the +/// [RestorationManager]. +/// +/// [RestorationBucket]s are organized in a tree that is rooted in +/// [RestorationManager.rootBucket] and managed by a [RestorationManager]. The +/// tree is serializable and must contain all the data an application needs to +/// restore its current state at a later point in time. +/// +/// A [RestorationBucket] stores restoration data as key-value pairs. The key is +/// a [String] representing a restoration ID that identifies a piece of data +/// uniquely within a bucket. The value can be anything that is serializable via +/// the [StandardMessageCodec]. Furthermore, a [RestorationBucket] may have +/// child buckets, which are identified within their parent via a unique +/// restoration ID as well. +/// +/// During state restoration, the data previously stored in the +/// [RestorationBucket] hierarchy will be made available again to the +/// application to restore it to the state it had when the data was collected. +/// State restoration to a previous state may happen when the app is launched +/// (e.g. after it has been terminated gracefully while running in the +/// background) or after the app has already been running for a while. +/// +/// ## Lifecycle +/// +/// A [RestorationBucket] is rarely instantiated directly via its constructors. +/// Instead, when an entity wants to store data in or retrieve data from a +/// restoration bucket, it typically obtains a child bucket from a parent by +/// calling [claimChild]. If no parent is available, +/// [RestorationManager.rootBucket] may be used as a parent. When claiming a +/// child, the claimer must provide the restoration ID of the child it would +/// like to own. A child bucket with a given restoration ID can at most have +/// one owner. If another owner tries to claim a bucket with the same ID from +/// the same parent, an exception is thrown (see discussion in [claimChild]). +/// The restoration IDs that a given owner uses to claim a child (and to store +/// data in that child, see below) must be stable across app launches to ensure +/// that after the app restarts the owner can retrieve the same data again that +/// it stored during a previous run. +/// +/// Per convention, the owner of the bucket has exclusive access to the values +/// stored in the bucket. It can read, add, modify, and remove values via the +/// [read], [write], and [remove] methods. In general, the owner should store +/// all the data in the bucket that it needs to restore its current state. If +/// its current state changes, the data in the bucket must be updated. At the +/// same time, the data in the bucket should be kept to a minimum. For example, +/// for data that can be retrieved from other sources (like a database or +/// web service) only enough information (e.g. an ID or resource locator) to +/// re-obtain that data should be stored in the bucket. In addition to managing +/// the data in a bucket, an owner may also make the bucket available to other +/// entities so they can claim child buckets from it via [claimChild] for their +/// own restoration needs. +/// +/// The bucket returned by [claimChild] may either contain state information +/// that the owner had previously (e.g. during a previous run of the +/// application) stored in it or it may be empty. If the bucket contains data, +/// the owner is expected to restore its state with the information previously +/// stored in the bucket. If the bucket is empty, it may initialize itself to +/// default values. +/// +/// When the data stored in a bucket is no longer needed to restore the +/// application to its current state (e.g. because the owner of the bucket is no +/// longer shown on screen), the bucket must be [dispose]d. This will remove all +/// information stored in the bucket from the app's restoration data and that +/// information will not be available again when the application is restored to +/// this state in the future. +class RestorationBucket { + /// Creates an empty [RestorationBucket] to be provided to [adoptChild] to add + /// it to the bucket hierarchy. + /// + /// {@template flutter.services.RestorationBucket.empty.bucketCreation} + /// Instantiating a bucket directly is rare, most buckets are created by + /// claiming a child from a parent via [claimChild]. If no parent bucket is + /// available, [RestorationManager.rootBucket] may be used as a parent. + /// {@endtemplate} + RestorationBucket.empty({ + required String restorationId, + required Object? debugOwner, + }) : _restorationId = restorationId, + _rawData = <String, Object?>{} { + assert(() { + _debugOwner = debugOwner; + return true; + }()); + if (kFlutterMemoryAllocationsEnabled) { + _maybeDispatchObjectCreation(); + } + } + + /// Creates the root [RestorationBucket] for the provided restoration + /// `manager`. + /// + /// The `rawData` must either be null (in which case an empty bucket will be + /// instantiated) or it must be a nested map describing the entire bucket + /// hierarchy in the following format: + /// + /// ```javascript + /// { + /// 'v': { // key-value pairs + /// // * key is a string representation a restoration ID + /// // * value is any primitive that can be encoded with [StandardMessageCodec] + /// '<restoration-id>: <Object>, + /// }, + /// 'c': { // child buckets + /// 'restoration-id': <nested map representing a child bucket> + /// } + /// } + /// ``` + /// + /// {@macro flutter.services.RestorationBucket.empty.bucketCreation} + RestorationBucket.root({ + required RestorationManager manager, + required Map<Object?, Object?>? rawData, + }) : _manager = manager, + _rawData = rawData ?? <Object?, Object?>{}, + _restorationId = 'root' { + assert(() { + _debugOwner = manager; + return true; + }()); + if (kFlutterMemoryAllocationsEnabled) { + _maybeDispatchObjectCreation(); + } + } + + /// Creates a child bucket initialized with the data that the provided + /// `parent` has stored under the provided [restorationId]. + /// + /// This constructor cannot be used if the `parent` does not have any child + /// data stored under the given ID. In that case, create an empty bucket (via + /// [RestorationBucket.empty] and have the parent adopt it via [adoptChild]. + /// + /// {@macro flutter.services.RestorationBucket.empty.bucketCreation} + RestorationBucket.child({ + required String restorationId, + required RestorationBucket parent, + required Object? debugOwner, + }) : assert(parent._rawChildren[restorationId] != null), + _manager = parent._manager, + _parent = parent, + _rawData = parent._rawChildren[restorationId]! as Map<Object?, Object?>, + _restorationId = restorationId { + assert(() { + _debugOwner = debugOwner; + return true; + }()); + if (kFlutterMemoryAllocationsEnabled) { + _maybeDispatchObjectCreation(); + } + } + + static const String _childrenMapKey = 'c'; + static const String _valuesMapKey = 'v'; + + final Map<Object?, Object?> _rawData; + + /// The owner of the bucket that was provided when the bucket was claimed via + /// [claimChild]. + /// + /// The value is used in error messages. Accessing the value is only valid + /// in debug mode, otherwise it will return null. + Object? get debugOwner { + assert(_debugAssertNotDisposed()); + return _debugOwner; + } + Object? _debugOwner; + + RestorationManager? _manager; + RestorationBucket? _parent; + + /// Returns true when entities processing this bucket should restore their + /// state from the information in the bucket (e.g. via [read] and + /// [claimChild]) instead of copying their current state information into the + /// bucket (e.g. via [write] and [adoptChild]. + /// + /// This flag is true for the frame after the [RestorationManager] has been + /// instructed to restore the application from newly provided restoration + /// data. + bool get isReplacing => _manager?.isReplacing ?? false; + + /// The restoration ID under which the bucket is currently stored in the + /// parent of this bucket (or wants to be stored if it is currently + /// parent-less). + /// + /// This value is never null. + String get restorationId { + assert(_debugAssertNotDisposed()); + return _restorationId; + } + String _restorationId; + + // Maps a restoration ID to the raw map representation of a child bucket. + Map<Object?, Object?> get _rawChildren => _rawData.putIfAbsent(_childrenMapKey, () => <Object?, Object?>{})! as Map<Object?, Object?>; + // Maps a restoration ID to a value that is stored in this bucket. + Map<Object?, Object?> get _rawValues => _rawData.putIfAbsent(_valuesMapKey, () => <Object?, Object?>{})! as Map<Object?, Object?>; + + // Get and store values. + + /// Returns the value of type `P` that is currently stored in the bucket under + /// the provided `restorationId`. + /// + /// Returns null if nothing is stored under that id. Throws, if the value + /// stored under the ID is not of type `P`. + /// + /// See also: + /// + /// * [write], which stores a value in the bucket. + /// * [remove], which removes a value from the bucket. + /// * [contains], which checks whether any value is stored under a given + /// restoration ID. + P? read<P>(String restorationId) { + assert(_debugAssertNotDisposed()); + return _rawValues[restorationId] as P?; + } + + /// Stores the provided `value` of type `P` under the provided `restorationId` + /// in the bucket. + /// + /// Any value that has previously been stored under that ID is overwritten + /// with the new value. The provided `value` must be serializable with the + /// [StandardMessageCodec]. + /// + /// Null values will be stored in the bucket as-is. To remove a value, use + /// [remove]. + /// + /// See also: + /// + /// * [read], which retrieves a stored value from the bucket. + /// * [remove], which removes a value from the bucket. + /// * [contains], which checks whether any value is stored under a given + /// restoration ID. + void write<P>(String restorationId, P value) { + assert(_debugAssertNotDisposed()); + assert(debugIsSerializableForRestoration(value)); + if (_rawValues[restorationId] != value || !_rawValues.containsKey(restorationId)) { + _rawValues[restorationId] = value; + _markNeedsSerialization(); + } + } + + /// Deletes the value currently stored under the provided `restorationId` from + /// the bucket. + /// + /// The value removed from the bucket is casted to `P` and returned. If no + /// value was stored under that id, null is returned. + /// + /// See also: + /// + /// * [read], which retrieves a stored value from the bucket. + /// * [write], which stores a value in the bucket. + /// * [contains], which checks whether any value is stored under a given + /// restoration ID. + P? remove<P>(String restorationId) { + assert(_debugAssertNotDisposed()); + final bool needsUpdate = _rawValues.containsKey(restorationId); + final P? result = _rawValues.remove(restorationId) as P?; + if (_rawValues.isEmpty) { + _rawData.remove(_valuesMapKey); + } + if (needsUpdate) { + _markNeedsSerialization(); + } + return result; + } + + /// Checks whether a value stored in the bucket under the provided + /// `restorationId`. + /// + /// See also: + /// + /// * [read], which retrieves a stored value from the bucket. + /// * [write], which stores a value in the bucket. + /// * [remove], which removes a value from the bucket. + bool contains(String restorationId) { + assert(_debugAssertNotDisposed()); + return _rawValues.containsKey(restorationId); + } + + // Child management. + + // The restoration IDs and associated buckets of children that have been + // claimed via [claimChild]. + final Map<String, RestorationBucket> _claimedChildren = <String, RestorationBucket>{}; + // Newly created child buckets whose restoration ID is still in use, see + // comment in [claimChild] for details. + final Map<String, List<RestorationBucket>> _childrenToAdd = <String, List<RestorationBucket>>{}; + + /// Claims ownership of the child with the provided `restorationId` from this + /// bucket. + /// + /// If the application is getting restored to a previous state, the bucket + /// will contain all the data that was previously stored in the bucket. + /// Otherwise, an empty bucket is returned. + /// + /// The claimer of the bucket is expected to use the data stored in the bucket + /// to restore itself to its previous state described by the data in the + /// bucket. If the bucket is empty, it should initialize itself to default + /// values. Whenever the information that the claimer needs to restore its + /// state changes, the data in the bucket should be updated to reflect that. + /// + /// A child bucket with a given `restorationId` can only have one owner. If + /// another owner claims a child bucket with the same `restorationId` an + /// exception will be thrown at the end of the current frame unless the + /// previous owner has either deleted its bucket by calling [dispose] or has + /// moved it to a new parent via [adoptChild]. + /// + /// When the returned bucket is no longer needed, it must be [dispose]d to + /// delete the information stored in it from the app's restoration data. + RestorationBucket claimChild(String restorationId, {required Object? debugOwner}) { + assert(_debugAssertNotDisposed()); + // There are three cases to consider: + // 1. Claiming an ID that has already been claimed. + // 2. Claiming an ID that doesn't yet exist in [_rawChildren]. + // 3. Claiming an ID that does exist in [_rawChildren] and hasn't been + // claimed yet. + // If an ID has already been claimed (case 1) the current owner may give up + // that ID later this frame and it can be re-used. In anticipation of the + // previous owner's surrender of the id, we return an empty bucket for this + // new claim and check in [_debugAssertIntegrity] that at the end of the + // frame the old owner actually did surrendered the id. + // Case 2 also requires the creation of a new empty bucket. + // In Case 3 we create a new bucket wrapping the existing data in + // [_rawChildren]. + + // Case 1+2: Adopt and return an empty bucket. + if (_claimedChildren.containsKey(restorationId) || !_rawChildren.containsKey(restorationId)) { + final RestorationBucket child = RestorationBucket.empty( + debugOwner: debugOwner, + restorationId: restorationId, + ); + adoptChild(child); + return child; + } + + // Case 3: Return bucket wrapping the existing data. + assert(_rawChildren[restorationId] != null); + final RestorationBucket child = RestorationBucket.child( + restorationId: restorationId, + parent: this, + debugOwner: debugOwner, + ); + _claimedChildren[restorationId] = child; + return child; + } + + /// Adopts the provided `child` bucket. + /// + /// The `child` will be dropped from its old parent, if it had one. + /// + /// The `child` is stored under its [restorationId] in this bucket. If this + /// bucket already contains a child bucket under the same id, the owner of + /// that existing bucket must give it up (e.g. by moving the child bucket to a + /// different parent or by disposing it) before the end of the current frame. + /// Otherwise an exception indicating the illegal use of duplicated + /// restoration IDs will trigger in debug mode. + /// + /// No-op if the provided bucket is already a child of this bucket. + void adoptChild(RestorationBucket child) { + assert(_debugAssertNotDisposed()); + if (child._parent != this) { + child._parent?._removeChildData(child); + child._parent = this; + _addChildData(child); + if (child._manager != _manager) { + _recursivelyUpdateManager(child); + } + } + assert(child._parent == this); + assert(child._manager == _manager); + } + + void _dropChild(RestorationBucket child) { + assert(child._parent == this); + _removeChildData(child); + child._parent = null; + if (child._manager != null) { + child._updateManager(null); + child._visitChildren(_recursivelyUpdateManager); + } + } + + bool _needsSerialization = false; + void _markNeedsSerialization() { + if (!_needsSerialization) { + _needsSerialization = true; + _manager?.scheduleSerializationFor(this); + } + } + + /// Called by the [RestorationManager] just before the data of the bucket + /// is serialized and send to the engine. + /// + /// It is exposed to allow testing of [RestorationBucket]s in isolation. + @visibleForTesting + void finalize() { + assert(_debugAssertNotDisposed()); + assert(_needsSerialization); + _needsSerialization = false; + assert(_debugAssertIntegrity()); + } + + void _recursivelyUpdateManager(RestorationBucket bucket) { + bucket._updateManager(_manager); + bucket._visitChildren(_recursivelyUpdateManager); + } + + void _updateManager(RestorationManager? newManager) { + if (_manager == newManager) { + return; + } + if (_needsSerialization) { + _manager?.unscheduleSerializationFor(this); + } + _manager = newManager; + if (_needsSerialization && _manager != null) { + _needsSerialization = false; + _markNeedsSerialization(); + } + } + + bool _debugAssertIntegrity() { + assert(() { + if (_childrenToAdd.isEmpty) { + return true; + } + final List<DiagnosticsNode> error = <DiagnosticsNode>[ + ErrorSummary('Multiple owners claimed child RestorationBuckets with the same IDs.'), + ErrorDescription('The following IDs were claimed multiple times from the parent $this:'), + ]; + for (final MapEntry<String, List<RestorationBucket>> child in _childrenToAdd.entries) { + final String id = child.key; + final List<RestorationBucket> buckets = child.value; + assert(buckets.isNotEmpty); + assert(_claimedChildren.containsKey(id)); + error.addAll(<DiagnosticsNode>[ + ErrorDescription(' * "$id" was claimed by:'), + ...buckets.map((RestorationBucket bucket) => ErrorDescription(' * ${bucket.debugOwner}')), + ErrorDescription(' * ${_claimedChildren[id]!.debugOwner} (current owner)'), + ]); + } + throw FlutterError.fromParts(error); + }()); + return true; + } + + void _removeChildData(RestorationBucket child) { + assert(child._parent == this); + if (_claimedChildren.remove(child.restorationId) == child) { + _rawChildren.remove(child.restorationId); + final List<RestorationBucket>? pendingChildren = _childrenToAdd[child.restorationId]; + if (pendingChildren != null) { + final RestorationBucket toAdd = pendingChildren.removeLast(); + _finalizeAddChildData(toAdd); + if (pendingChildren.isEmpty) { + _childrenToAdd.remove(child.restorationId); + } + } + if (_rawChildren.isEmpty) { + _rawData.remove(_childrenMapKey); + } + _markNeedsSerialization(); + return; + } + _childrenToAdd[child.restorationId]?.remove(child); + if (_childrenToAdd[child.restorationId]?.isEmpty ?? false) { + _childrenToAdd.remove(child.restorationId); + } + } + + void _addChildData(RestorationBucket child) { + assert(child._parent == this); + if (_claimedChildren.containsKey(child.restorationId)) { + // Delay addition until the end of the frame in the hopes that the current + // owner of the child with the same ID will have given up that child by + // then. + _childrenToAdd.putIfAbsent(child.restorationId, () => <RestorationBucket>[]).add(child); + _markNeedsSerialization(); + return; + } + _finalizeAddChildData(child); + _markNeedsSerialization(); + } + + void _finalizeAddChildData(RestorationBucket child) { + assert(_claimedChildren[child.restorationId] == null); + assert(_rawChildren[child.restorationId] == null); + _claimedChildren[child.restorationId] = child; + _rawChildren[child.restorationId] = child._rawData; + } + + void _visitChildren(_BucketVisitor visitor, {bool concurrentModification = false}) { + Iterable<RestorationBucket> children = _claimedChildren.values + .followedBy(_childrenToAdd.values.expand((List<RestorationBucket> buckets) => buckets)); + if (concurrentModification) { + children = children.toList(growable: false); + } + children.forEach(visitor); + } + + // Bucket management + + /// Changes the restoration ID under which the bucket is (or will be) stored + /// in its parent to `newRestorationId`. + /// + /// No-op if the bucket is already stored under the provided id. + /// + /// If another owner has already claimed a bucket with the provided `newId` an + /// exception will be thrown at the end of the current frame unless the other + /// owner has deleted its bucket by calling [dispose], [rename]ed it using + /// another ID, or has moved it to a new parent via [adoptChild]. + void rename(String newRestorationId) { + assert(_debugAssertNotDisposed()); + if (newRestorationId == restorationId) { + return; + } + _parent?._removeChildData(this); + _restorationId = newRestorationId; + _parent?._addChildData(this); + } + + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + /// Dispatches event of object creation to [FlutterMemoryAllocations.instance]. + void _maybeDispatchObjectCreation() { + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/services.dart', + className: '$RestorationBucket', + object: this, + ); + } + } + + /// Deletes the bucket and all the data stored in it from the bucket + /// hierarchy. + /// + /// After [dispose] has been called, the data stored in this bucket and its + /// children are no longer part of the app's restoration data. The data + /// originally stored in the bucket will not be available again when the + /// application is restored to this state in the future. It is up to the + /// owners of the children to either move them (via [adoptChild]) to a new + /// parent that is still part of the bucket hierarchy or to [dispose] of them + /// as well. + /// + /// This method must only be called by the object's owner. + void dispose() { + assert(_debugAssertNotDisposed()); + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _visitChildren(_dropChild, concurrentModification: true); + _claimedChildren.clear(); + _childrenToAdd.clear(); + _parent?._removeChildData(this); + _parent = null; + _updateManager(null); + _debugDisposed = true; + } + + @override + String toString() => '${objectRuntimeType(this, 'RestorationBucket')}(restorationId: $restorationId, owner: $debugOwner)'; + + bool _debugDisposed = false; + bool _debugAssertNotDisposed() { + assert(() { + if (_debugDisposed) { + throw FlutterError( + 'A $runtimeType was used after being disposed.\n' + 'Once you have called dispose() on a $runtimeType, it can no longer be used.', + ); + } + return true; + }()); + return true; + } +} + +/// Returns true when the provided `object` is serializable for state +/// restoration. +/// +/// Should only be called from within asserts. Always returns false outside +/// of debug builds. +bool debugIsSerializableForRestoration(Object? object) { + bool result = false; + + assert(() { + try { + const StandardMessageCodec().encodeMessage(object); + result = true; + } catch (error) { + // This is only used in asserts, so reporting the exception isn't + // particularly useful, since the assert itself will likely fail. + result = false; + } + return true; + }()); + + return result; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/service_extensions.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/service_extensions.dart new file mode 100644 index 0000000000000000000000000000000000000000..3c1c9cfa1007f82ee88f371060546ae6c10d2ae0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/service_extensions.dart @@ -0,0 +1,39 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Service extension constants for the services library. +/// +/// These constants will be used when registering service extensions in the +/// framework, and they will also be used by tools and services that call these +/// service extensions. +/// +/// The String value for each of these extension names should be accessed by +/// calling the `.name` property on the enum value. +enum ServicesServiceExtensions { + /// Name of service extension that, when called, will toggle whether + /// statistics about the usage of Platform Channels will be printed out + /// periodically to the console and Timeline events will show the time between + /// sending and receiving a message (encoding and decoding time excluded). + /// + /// See also: + /// + /// * [debugProfilePlatformChannels], which is the flag that this service + /// extension exposes. + /// * [ServicesBinding.initServiceExtensions], where the service extension is + /// registered. + profilePlatformChannels, + + /// Name of service extension that, when called, will evict an image from the + /// rootBundle cache and cause the image cache to be cleared. + /// + /// This is used by hot reload mode to clear out the cache of resources that + /// have changed. This service extension should be called with a String value + /// of the image path (e.g. foo.png). + /// + /// See also: + /// + /// * [ServicesBinding.initServiceExtensions], where the service extension is + /// registered. + evict, +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/spell_check.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/spell_check.dart new file mode 100644 index 0000000000000000000000000000000000000000..24e36c3754b1e43699b0c26ae17fd18032c0843c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/spell_check.dart @@ -0,0 +1,213 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; +import 'system_channels.dart'; + +/// A data structure representing a range of misspelled text and the suggested +/// replacements for this range. +/// +/// For example, one [SuggestionSpan] of the +/// [List<SuggestionSpan>] suggestions of the [SpellCheckResults] corresponding +/// to "Hello, wrold!" may be: +/// ```dart +/// SuggestionSpan suggestionSpan = +/// const SuggestionSpan( +/// TextRange(start: 7, end: 12), +/// <String>['word', 'world', 'old'], +/// ); +/// ``` +@immutable +class SuggestionSpan { + /// Creates a span representing a misspelled range of text and the replacements + /// suggested by a spell checker. + /// + /// The [range] and replacement [suggestions] must all not + /// be null. + const SuggestionSpan(this.range, this.suggestions); + + /// The misspelled range of text. + final TextRange range; + + /// The alternate suggestions for the misspelled range of text. + final List<String> suggestions; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is SuggestionSpan && + other.range.start == range.start && + other.range.end == range.end && + listEquals<String>(other.suggestions, suggestions); + } + + @override + int get hashCode => Object.hash(range.start, range.end, Object.hashAll(suggestions)); +} + +/// A data structure grouping together the [SuggestionSpan]s and related text of +/// results returned by a spell checker. +@immutable +class SpellCheckResults { + /// Creates results based off those received by spell checking some text input. + const SpellCheckResults(this.spellCheckedText, this.suggestionSpans); + + /// The text that the [suggestionSpans] correspond to. + final String spellCheckedText; + + /// The spell check results of the [spellCheckedText]. + /// + /// See also: + /// + /// * [SuggestionSpan], the ranges of misspelled text and corresponding + /// replacement suggestions. + final List<SuggestionSpan> suggestionSpans; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is SpellCheckResults && + other.spellCheckedText == spellCheckedText && + listEquals<SuggestionSpan>(other.suggestionSpans, suggestionSpans); + } + + @override + int get hashCode => Object.hash(spellCheckedText, Object.hashAll(suggestionSpans)); +} + +/// Determines how spell check results are received for text input. +abstract class SpellCheckService { + /// Facilitates a spell check request. + /// + /// Returns a [Future] that resolves with a [List] of [SuggestionSpan]s for + /// all misspelled words in the given [String] for the given [Locale]. + Future<List<SuggestionSpan>?> fetchSpellCheckSuggestions( + Locale locale, String text + ); +} + +/// The service used by default to fetch spell check results for text input. +/// +/// Any widget may use this service to spell check text by calling +/// `fetchSpellCheckSuggestions(locale, text)` with an instance of this class. +/// This is currently only supported by Android and iOS. +/// +/// See also: +/// +/// * [SpellCheckService], the service that this implements that may be +/// overridden for use by [EditableText]. +/// * [EditableText], which may use this service to fetch results. +class DefaultSpellCheckService implements SpellCheckService { + /// Creates service to spell check text input by default via communication + /// over the spell check [MethodChannel]. + DefaultSpellCheckService() { + spellCheckChannel = SystemChannels.spellCheck; + } + + /// The last received results from the shell side. + SpellCheckResults? lastSavedResults; + + /// The channel used to communicate with the shell side to complete spell + /// check requests. + late MethodChannel spellCheckChannel; + + /// Merges two lists of spell check [SuggestionSpan]s. + /// + /// Used in cases where the text has not changed, but the spell check results + /// received from the shell side have. This case is caused by IMEs (GBoard, + /// for instance) that ignore the composing region when spell checking text. + /// + /// Assumes that the lists provided as parameters are sorted by range start + /// and that both list of [SuggestionSpan]s apply to the same text. + static List<SuggestionSpan> mergeResults( + List<SuggestionSpan> oldResults, List<SuggestionSpan> newResults) { + final List<SuggestionSpan> mergedResults = <SuggestionSpan>[]; + + SuggestionSpan oldSpan; + SuggestionSpan newSpan; + int oldSpanPointer = 0; + int newSpanPointer = 0; + + while (oldSpanPointer < oldResults.length && + newSpanPointer < newResults.length) { + oldSpan = oldResults[oldSpanPointer]; + newSpan = newResults[newSpanPointer]; + + if (oldSpan.range.start == newSpan.range.start) { + mergedResults.add(oldSpan); + oldSpanPointer++; + newSpanPointer++; + } else { + if (oldSpan.range.start < newSpan.range.start) { + mergedResults.add(oldSpan); + oldSpanPointer++; + } else { + mergedResults.add(newSpan); + newSpanPointer++; + } + } + } + + mergedResults.addAll(oldResults.sublist(oldSpanPointer)); + mergedResults.addAll(newResults.sublist(newSpanPointer)); + + return mergedResults; + } + + @override + Future<List<SuggestionSpan>?> fetchSpellCheckSuggestions( + Locale locale, String text) async { + + final List<dynamic> rawResults; + final String languageTag = locale.toLanguageTag(); + + try { + rawResults = await spellCheckChannel.invokeMethod( + 'SpellCheck.initiateSpellCheck', + <String>[languageTag, text], + ) as List<dynamic>; + } catch (e) { + // Spell check request canceled due to pending request. + return null; + } + + List<SuggestionSpan> suggestionSpans = <SuggestionSpan>[]; + + for (final dynamic result in rawResults) { + final Map<String, dynamic> resultMap = + Map<String,dynamic>.from(result as Map<dynamic, dynamic>); + suggestionSpans.add( + SuggestionSpan( + TextRange( + start: resultMap['startIndex'] as int, + end: resultMap['endIndex'] as int), + (resultMap['suggestions'] as List<dynamic>).cast<String>(), + ) + ); + } + + if (lastSavedResults != null) { + // Merge current and previous spell check results if between requests, + // the text has not changed but the spell check results have. + final bool textHasNotChanged = lastSavedResults!.spellCheckedText == text; + final bool spansHaveChanged = + listEquals(lastSavedResults!.suggestionSpans, suggestionSpans); + + if (textHasNotChanged && spansHaveChanged) { + suggestionSpans = mergeResults(lastSavedResults!.suggestionSpans, suggestionSpans); + } + } + lastSavedResults = SpellCheckResults(text, suggestionSpans); + + return suggestionSpans; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_channels.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_channels.dart new file mode 100644 index 0000000000000000000000000000000000000000..24cf7224427c7326a034d1b7c46e6ce4528e93b1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_channels.dart @@ -0,0 +1,525 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'message_codecs.dart'; +import 'platform_channel.dart'; + +export 'platform_channel.dart' show BasicMessageChannel, MethodChannel; + +/// Platform channels used by the Flutter system. +abstract final class SystemChannels { + /// A JSON [MethodChannel] for navigation. + /// + /// The following incoming methods are defined for this channel (registered + /// using [MethodChannel.setMethodCallHandler]): + /// + /// * `popRoute`, which is called when the system wants the current route to + /// be removed (e.g. if the user hits a system-level back button). + /// + /// * `pushRoute`, which is called with a single string argument when the + /// operating system instructs the application to open a particular page. + /// + /// * `pushRouteInformation`, which is called with a map, which contains a + /// location string and a state object, when the operating system instructs + /// the application to open a particular page. These parameters are stored + /// under the key `location` and `state` in the map. + /// + /// The following methods are used for the opposite direction data flow. The + /// framework notifies the engine about the route changes. + /// + /// * `selectSingleEntryHistory`, which enables a single-entry history mode. + /// + /// * `selectMultiEntryHistory`, which enables a multiple-entry history mode. + /// + /// * `routeInformationUpdated`, which is called when the application + /// navigates to a new location, and which takes two arguments, `location` + /// (a URL) and `state` (an object). + /// + /// * `routeUpdated`, a deprecated API which can be called in the same + /// situations as `routeInformationUpdated` but whose arguments are + /// `routeName` (a URL) and `previousRouteName` (which is ignored). + /// + /// These APIs are exposed by the [SystemNavigator] class. + /// + /// See also: + /// + /// * [WidgetsBindingObserver.didPopRoute] and + /// [WidgetsBindingObserver.didPushRoute], which expose this channel's + /// methods. + /// * [Navigator] which manages transitions from one page to another. + /// [Navigator.push], [Navigator.pushReplacement], [Navigator.pop] and + /// [Navigator.replace], utilize this channel's methods to send route + /// change information from framework to engine. + static const MethodChannel navigation = OptionalMethodChannel( + 'flutter/navigation', + JSONMethodCodec(), + ); + + /// A JSON [MethodChannel] for invoking miscellaneous platform methods. + /// + /// The following outgoing methods are defined for this channel (invoked using + /// [OptionalMethodChannel.invokeMethod]): + /// + /// * `Clipboard.setData`: Places the data from the `text` entry of the + /// argument, which must be a [Map], onto the system clipboard. See + /// [Clipboard.setData]. + /// + /// * `Clipboard.getData`: Returns the data that has the format specified in + /// the argument, a [String], from the system clipboard. The only format + /// currently supported is `text/plain` ([Clipboard.kTextPlain]). The + /// result is a [Map] with a single key, `text`. See [Clipboard.getData]. + /// + /// * `HapticFeedback.vibrate`: Triggers a system-default haptic response. + /// See [HapticFeedback.vibrate]. + /// + /// * `SystemSound.play`: Triggers a system audio effect. The argument must + /// be a [String] describing the desired effect; currently only `click` is + /// supported. See [SystemSound.play]. + /// + /// * `SystemChrome.setPreferredOrientations`: Informs the operating system + /// of the desired orientation of the display. The argument is a [List] of + /// values which are string representations of values of the + /// [DeviceOrientation] enum. See [SystemChrome.setPreferredOrientations]. + /// + /// * `SystemChrome.setApplicationSwitcherDescription`: Informs the operating + /// system of the desired label and color to be used to describe the + /// application in any system-level application lists (e.g. application + /// switchers). The argument is a [Map] with two keys, `label` giving a + /// [String] description, and `primaryColor` giving a 32 bit integer value + /// (the lower eight bits being the blue channel, the next eight bits being + /// the green channel, the next eight bits being the red channel, and the + /// high eight bits being set, as from [Color.value] for an opaque color). + /// The `primaryColor` can also be zero to indicate that the system default + /// should be used. See [SystemChrome.setApplicationSwitcherDescription]. + /// + /// * `SystemChrome.setEnabledSystemUIOverlays`: Specifies the set of system + /// overlays to have visible when the application is running. The argument + /// is a [List] of values which are string representations of values of the + /// [SystemUiOverlay] enum. See [SystemChrome.setEnabledSystemUIMode]. + /// [SystemUiOverlay]s can only be configured individually when using + /// [SystemUiMode.manual]. + /// + /// * `SystemChrome.setEnabledSystemUIMode`: Specifies the [SystemUiMode] for + /// the application. The optional `overlays` argument is a [List] of values + /// which are string representations of values of the [SystemUiOverlay] + /// enum when using [SystemUiMode.manual]. See + /// [SystemChrome.setEnabledSystemUIMode]. + /// + /// * `SystemChrome.setSystemUIOverlayStyle`: Specifies whether system + /// overlays (e.g. the status bar on Android or iOS) should be `light` or + /// `dark`. The argument is one of those two strings. See + /// [SystemChrome.setSystemUIOverlayStyle]. + /// + /// * `SystemNavigator.pop`: Tells the operating system to close the + /// application, or the closest equivalent. See [SystemNavigator.pop]. + /// + /// * `System.exitApplication`: Tells the engine to send a request back to + /// the application to request an application exit (using + /// `System.requestAppExit` below), and if it is not canceled, to terminate + /// the application using the platform UI toolkit's termination API. + /// + /// The following incoming methods are defined for this channel (registered + /// using [MethodChannel.setMethodCallHandler]): + /// + /// * `SystemChrome.systemUIChange`: The user has changed the visibility of + /// the system overlays. This is relevant when using [SystemUiMode]s + /// through [SystemChrome.setEnabledSystemUIMode]. See + /// [SystemChrome.setSystemUIChangeCallback] to respond to this change in + /// application state. + /// + /// * `System.requestAppExit`: The application has requested that it be + /// terminated. See [ServicesBinding.exitApplication]. + /// + /// * `System.initializationComplete`: Indicate to the engine the + /// initialization of a binding that may, among other tasks, register a + /// handler for application exit attempts. + /// + /// Calls to methods that are not implemented on the shell side are ignored + /// (so it is safe to call methods when the relevant plugin might be missing). + static const MethodChannel platform = OptionalMethodChannel( + 'flutter/platform', + JSONMethodCodec(), + ); + + /// A [MethodChannel] for handling text processing actions. + /// + /// This channel exposes the text processing feature for supported platforms. + /// Currently supported on Android only. + static const MethodChannel processText = OptionalMethodChannel( + 'flutter/processtext', + ); + + /// A JSON [MethodChannel] for handling text input. + /// + /// This channel exposes a system text input control for interacting with IMEs + /// (input method editors, for example on-screen keyboards). There is one + /// control, and at any time it can have one active transaction. Transactions + /// are represented by an integer. New Transactions are started by + /// `TextInput.setClient`. Messages that are sent are assumed to be for the + /// current transaction (the last "client" set by `TextInput.setClient`). + /// Messages received from the shell side specify the transaction to which + /// they apply, so that stale messages referencing past transactions can be + /// ignored. + /// + /// In debug builds, messages sent with a client ID of -1 are always accepted. + /// This allows tests to smuggle messages without having to mock the engine's + /// text handling (for example, allowing the engine to still handle the text + /// input messages in an integration test). + /// + /// The methods described below are wrapped in a more convenient form by the + /// [TextInput] and [TextInputConnection] class. + /// + /// The following outgoing methods are defined for this channel (invoked using + /// [OptionalMethodChannel.invokeMethod]): + /// + /// * `TextInput.setClient`: Establishes a new transaction. The arguments is + /// a [List] whose first value is an integer representing a previously + /// unused transaction identifier, and the second is a [String] with a + /// JSON-encoded object with five keys, as obtained from + /// [TextInputConfiguration.toJson]. This method must be invoked before any + /// others (except `TextInput.hide`). See [TextInput.attach]. + /// + /// * `TextInput.show`: Show the keyboard. See [TextInputConnection.show]. + /// + /// * `TextInput.setEditingState`: Update the value in the text editing + /// control. The argument is a [String] with a JSON-encoded object with + /// seven keys, as obtained from [TextEditingValue.toJSON]. See + /// [TextInputConnection.setEditingState]. + /// + /// * `TextInput.clearClient`: End the current transaction. The next method + /// called must be `TextInput.setClient` (or `TextInput.hide`). See + /// [TextInputConnection.close]. + /// + /// * `TextInput.hide`: Hide the keyboard. Unlike the other methods, this can + /// be called at any time. See [TextInputConnection.close]. + /// + /// The following incoming methods are defined for this channel (registered + /// using [MethodChannel.setMethodCallHandler]). In each case, the first argument + /// is a transaction identifier. Calls for stale transactions should be ignored. + /// + /// * `TextInputClient.updateEditingState`: The user has changed the contents + /// of the text control. The second argument is an object with seven keys, + /// in the form expected by [TextEditingValue.fromJSON]. + /// + /// * `TextInputClient.updateEditingStateWithTag`: One or more text controls + /// were autofilled by the platform's autofill service. The first argument + /// (the client ID) is ignored, the second argument is a map of tags to + /// objects in the form expected by [TextEditingValue.fromJSON]. See + /// [AutofillScope.getAutofillClient] for details on the interpretation of + /// the tag. + /// + /// * `TextInputClient.performAction`: The user has triggered an action. The + /// second argument is a [String] consisting of the stringification of one + /// of the values of the [TextInputAction] enum. + /// + /// * `TextInputClient.requestExistingInputState`: The embedding may have + /// lost its internal state about the current editing client, if there is + /// one. The framework should call `TextInput.setClient` and + /// `TextInput.setEditingState` again with its most recent information. If + /// there is no existing state on the framework side, the call should + /// fizzle. (This call is made without a client ID; indeed, without any + /// arguments at all.) + /// + /// * `TextInputClient.onConnectionClosed`: The text input connection closed + /// on the platform side. For example the application is moved to + /// background or used closed the virtual keyboard. This method informs + /// [TextInputClient] to clear connection and finalize editing. + /// `TextInput.clearClient` and `TextInput.hide` is not called after + /// clearing the connection since on the platform side the connection is + /// already finalized. + /// + /// Calls to methods that are not implemented on the shell side are ignored + /// (so it is safe to call methods when the relevant plugin might be missing). + static const MethodChannel textInput = OptionalMethodChannel( + 'flutter/textinput', + JSONMethodCodec(), + ); + + /// A [MethodChannel] for handling spell check for text input. + /// + /// This channel exposes the spell check framework for supported platforms. + /// Currently supported on Android and iOS only. + /// + /// Spell check requests are initiated by `SpellCheck.initiateSpellCheck`. + /// These requests may either be completed or canceled. If the request is + /// completed, the shell side will respond with the results of the request. + /// Otherwise, the shell side will respond with null. + /// + /// The following outgoing methods are defined for this channel (invoked by + /// [OptionalMethodChannel.invokeMethod]): + /// + /// * `SpellCheck.initiateSpellCheck`: Sends request for specified text to be + /// spell checked and returns the result, either a [List<SuggestionSpan>] + /// representing the spell check results of the text or null if the request + /// was canceled. The arguments are the [String] to be spell checked + /// and the [Locale] for the text to be spell checked with. + static const MethodChannel spellCheck = OptionalMethodChannel( + 'flutter/spellcheck', + ); + + /// A JSON [MethodChannel] for handling undo events. + static const MethodChannel undoManager = OptionalMethodChannel( + 'flutter/undomanager', + JSONMethodCodec(), + ); + + /// A JSON [BasicMessageChannel] for keyboard events. + /// + /// Each incoming message received on this channel (registered using + /// [BasicMessageChannel.setMessageHandler]) consists of a [Map] with + /// platform-specific data, plus a `type` field which is either `keydown`, or + /// `keyup`. + /// + /// On Android, the available fields are those described by + /// [RawKeyEventDataAndroid]'s properties. + /// + /// On Fuchsia, the available fields are those described by + /// [RawKeyEventDataFuchsia]'s properties. + /// + /// No messages are sent on other platforms currently. + /// + /// See also: + /// + /// * [RawKeyboard], which uses this channel to expose key data. + /// * [RawKeyEvent.fromMessage], which can decode this data into the [RawKeyEvent] + /// subclasses mentioned above. + static const BasicMessageChannel<Object?> keyEvent = BasicMessageChannel<Object?>( + 'flutter/keyevent', + JSONMessageCodec(), + ); + + /// A string [BasicMessageChannel] for lifecycle events. + /// + /// Valid messages are string representations of the values of the + /// [AppLifecycleState] enumeration. A handler can be registered using + /// [BasicMessageChannel.setMessageHandler]. + /// + /// See also: + /// + /// * [WidgetsBindingObserver.didChangeAppLifecycleState], which triggers + /// whenever a message is received on this channel. + static const BasicMessageChannel<String?> lifecycle = BasicMessageChannel<String?>( + 'flutter/lifecycle', + StringCodec(), + ); + + /// A JSON [BasicMessageChannel] for system events. + /// + /// Events are exposed as [Map]s with string keys. The `type` key specifies + /// the type of the event; the currently supported system event types are + /// those listed below. A handler can be registered using + /// [BasicMessageChannel.setMessageHandler]. + /// + /// * `memoryPressure`: Indicates that the operating system would like + /// applications to release caches to free up more memory. See + /// [WidgetsBindingObserver.didHaveMemoryPressure], which triggers whenever + /// a message is received on this channel. + static const BasicMessageChannel<Object?> system = BasicMessageChannel<Object?>( + 'flutter/system', + JSONMessageCodec(), + ); + + /// A [BasicMessageChannel] for accessibility events. + /// + /// See also: + /// + /// * [SemanticsEvent] and its subclasses for a list of valid accessibility + /// events that can be sent over this channel. + /// * [SemanticsNode.sendEvent], which uses this channel to dispatch events. + static const BasicMessageChannel<Object?> accessibility = BasicMessageChannel<Object?>( + 'flutter/accessibility', + StandardMessageCodec(), + ); + + /// A [MethodChannel] for controlling platform views. + /// + /// See also: + /// + /// * [PlatformViewsService] for the available operations on this channel. + static const MethodChannel platform_views = MethodChannel( + 'flutter/platform_views', + ); + + /// A [MethodChannel] for configuring the Skia graphics library. + /// + /// The following outgoing methods are defined for this channel (invoked using + /// [OptionalMethodChannel.invokeMethod]): + /// + /// * `Skia.setResourceCacheMaxBytes`: Set the maximum number of bytes that + /// can be held in the GPU resource cache. + static const MethodChannel skia = MethodChannel( + 'flutter/skia', + JSONMethodCodec(), + ); + + /// A [MethodChannel] for configuring mouse cursors. + /// + /// All outgoing methods defined for this channel uses a `Map<String, Object?>` + /// to contain multiple parameters, including the following methods (invoked + /// using [OptionalMethodChannel.invokeMethod]): + /// + /// * `activateSystemCursor`: Request to set the cursor of a pointer + /// device to a system cursor. The parameters are + /// integer `device`, and string `kind`. + static const MethodChannel mouseCursor = OptionalMethodChannel( + 'flutter/mousecursor', + ); + + /// A [MethodChannel] for synchronizing restoration data with the engine. + /// + /// The following outgoing methods are defined for this channel (invoked using + /// [OptionalMethodChannel.invokeMethod]): + /// + /// * `get`: Retrieves the current restoration information (e.g. provided by + /// the operating system) from the engine. The method returns a map + /// containing an `enabled` boolean to indicate whether collecting + /// restoration data is supported by the embedder. If `enabled` is true, + /// the map may also contain restoration data stored under the `data` key + /// from which the state of the framework may be restored. The restoration + /// data is encoded as [Uint8List]. + /// * `put`: Sends the current restoration data to the engine. Takes the + /// restoration data encoded as [Uint8List] as argument. + /// + /// The following incoming methods are defined for this channel (registered + /// using [MethodChannel.setMethodCallHandler]). + /// + /// * `push`: Called by the engine to send newly provided restoration + /// information to the framework. The argument given to this method has + /// the same format as the object that the `get` method returns. + /// + /// See also: + /// + /// * [RestorationManager], which uses this channel and also describes how + /// restoration data is used in Flutter. + static const MethodChannel restoration = OptionalMethodChannel( + 'flutter/restoration', + ); + + /// A [MethodChannel] for installing and managing deferred components. + /// + /// The following outgoing methods are defined for this channel (invoked using + /// [OptionalMethodChannel.invokeMethod]): + /// + /// * `installDeferredComponent`: Requests that a deferred component identified by + /// the provided loadingUnitId or componentName be downloaded and installed. + /// Providing a loadingUnitId with null componentName will install a component that + /// includes the desired loading unit. If a componentName is provided, then the + /// deferred component with the componentName will be installed. This method + /// returns a future that will not be completed until the feature is fully installed + /// and ready to use. When an error occurs, the future will complete an error. + /// Calling `loadLibrary()` on a deferred imported library is equivalent to calling + /// this method with a loadingUnitId and null componentName. + /// * `uninstallDeferredComponent`: Requests that a deferred component identified by + /// the provided loadingUnitId or componentName be uninstalled. Since + /// uninstallation typically requires significant disk i/o, this method only + /// signals the intent to uninstall. Actual uninstallation (eg, removal of + /// assets and files) may occur at a later time. However, once uninstallation + /// is requested, the deferred component should not be used anymore until + /// `installDeferredComponent` or `loadLibrary` is called again. + static const MethodChannel deferredComponent = OptionalMethodChannel( + 'flutter/deferredcomponent', + ); + + /// A JSON [MethodChannel] for localization. + /// + /// The following outgoing methods are defined for this channel (invoked using + /// [OptionalMethodChannel.invokeMethod]): + /// + /// * `Localization.getStringResource`: Obtains the native string resource + /// for a specific locale. The argument is a [Map] with two keys, `key` + /// giving a [String] which the resource is defined with, and an optional + /// `locale` which is a [String] containing the BCP47 locale identifier of + /// the locale requested. See [Locale.toLanguageTag]. When `locale` is not + /// specified, the current system locale is used instead. + static const MethodChannel localization = OptionalMethodChannel( + 'flutter/localization', + JSONMethodCodec(), + ); + + /// A [MethodChannel] for platform menu specification and control. + /// + /// The following outgoing method is defined for this channel (invoked using + /// [OptionalMethodChannel.invokeMethod]): + /// + /// * `Menu.setMenus`: sends the configuration of the platform menu, including + /// labels, enable/disable information, and unique integer identifiers for + /// each menu item. The configuration is sent as a `Map<String, Object?>` + /// encoding the list of top level menu items in window "0", which each + /// have a hierarchy of `Map<String, Object?>` containing the required + /// data, sent via a [StandardMessageCodec]. It is typically generated from + /// a list of [PlatformMenuItem]s, and ends up looking like this example: + /// + /// ```dart + /// Map<String, Object?> menu = <String, Object?>{ + /// '0': <Map<String, Object?>>[ + /// <String, Object?>{ + /// 'id': 1, + /// 'label': 'First Menu Label', + /// 'enabled': true, + /// 'children': <Map<String, Object?>>[ + /// <String, Object?>{ + /// 'id': 2, + /// 'label': 'Sub Menu Label', + /// 'enabled': true, + /// }, + /// ], + /// }, + /// ], + /// }; + /// ``` + /// + /// The following incoming methods are defined for this channel (registered + /// using [MethodChannel.setMethodCallHandler]). + /// + /// * `Menu.selectedCallback`: Called when a menu item is selected, along + /// with the unique ID of the menu item selected. + /// + /// * `Menu.opened`: Called when a submenu is opened, along with the unique + /// ID of the submenu. + /// + /// * `Menu.closed`: Called when a submenu is closed, along with the unique + /// ID of the submenu. + /// + /// See also: + /// + /// * [DefaultPlatformMenuDelegate], which uses this channel. + static const MethodChannel menu = OptionalMethodChannel('flutter/menu'); + + /// A [MethodChannel] for configuring the browser's context menu on web. + /// + /// The following outgoing methods are defined for this channel (invoked using + /// [OptionalMethodChannel.invokeMethod]): + /// + /// * `enableContextMenu`: enables the browser's context menu. When a Flutter + /// app starts, the browser's context menu is already enabled. + /// * `disableContextMenu`: disables the browser's context menu. + static const MethodChannel contextMenu = OptionalMethodChannel( + 'flutter/contextmenu', + JSONMethodCodec(), + ); + + /// A [MethodChannel] for retrieving keyboard pressed keys from the engine. + /// + /// The following outgoing methods are defined for this channel (invoked using + /// [OptionalMethodChannel.invokeMethod]): + /// + /// * `getKeyboardState`: Obtains keyboard pressed keys from the engine. + /// The keyboard state is sent as a `Map<int, int>?` where each entry + /// represents a pressed keyboard key. The entry key is the physical + /// key ID and the entry value is the logical key ID. + /// + /// Both the framework and the engine maintain a state of the current + /// pressed keys. There are edge cases, related to startup and restart, + /// where the framework needs to resynchronize its keyboard state. + /// + /// See also: + /// + /// * [HardwareKeyboard.syncKeyboardState], which uses this channel to synchronize + /// the `HardwareKeyboard` pressed state. + static const MethodChannel keyboard = OptionalMethodChannel( + 'flutter/keyboard', + ); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_chrome.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_chrome.dart new file mode 100644 index 0000000000000000000000000000000000000000..1ed5a0c88c9d8f791af0e1310c544df3751011cb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_chrome.dart @@ -0,0 +1,646 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; + +import 'binding.dart'; +import 'system_channels.dart'; + +export 'dart:ui' show Brightness, Color; + +export 'binding.dart' show SystemUiChangeCallback; + +/// Specifies a particular device orientation. +/// +/// To determine which values correspond to which orientations, first position +/// the device in its default orientation (this is the orientation that the +/// system first uses for its boot logo, or the orientation in which the +/// hardware logos or markings are upright, or the orientation in which the +/// cameras are at the top). If this is a portrait orientation, then this is +/// [portraitUp]. Otherwise, it's [landscapeLeft]. As you rotate the device by +/// 90 degrees in a counter-clockwise direction around the axis that pierces the +/// screen, you step through each value in this enum in the order given. +/// +/// For a device with a landscape default orientation, the orientation obtained +/// by rotating the device 90 degrees clockwise from its default orientation is +/// [portraitUp]. +/// +/// Used by [SystemChrome.setPreferredOrientations]. +enum DeviceOrientation { + /// If the device shows its boot logo in portrait, then the boot logo is shown + /// in [portraitUp]. Otherwise, the device shows its boot logo in landscape + /// and this orientation is obtained by rotating the device 90 degrees + /// clockwise from its boot orientation. + portraitUp, + + /// The orientation that is 90 degrees clockwise from [portraitUp]. + /// + /// If the device shows its boot logo in landscape, then the boot logo is + /// shown in [landscapeLeft]. + landscapeLeft, + + /// The orientation that is 180 degrees from [portraitUp]. + portraitDown, + + /// The orientation that is 90 degrees counterclockwise from [portraitUp]. + landscapeRight, +} + +/// Specifies a description of the application that is pertinent to the +/// embedder's application switcher (also known as "recent tasks") user +/// interface. +/// +/// Used by [SystemChrome.setApplicationSwitcherDescription]. +@immutable +class ApplicationSwitcherDescription { + /// Creates an ApplicationSwitcherDescription. + const ApplicationSwitcherDescription({ this.label, this.primaryColor }); + + /// A label and description of the current state of the application. + final String? label; + + /// The application's primary color. + /// + /// This may influence the color that the operating system uses to represent + /// the application. + final int? primaryColor; +} + +/// Specifies a system overlay at a particular location. +/// +/// Used by [SystemChrome.setEnabledSystemUIMode]. +enum SystemUiOverlay { + /// The status bar provided by the embedder on the top of the application + /// surface, if any. + top, + + /// The status bar provided by the embedder on the bottom of the application + /// surface, if any. + bottom, +} + +/// Describes different display configurations for both Android and iOS. +/// +/// These modes mimic Android-specific display setups. +/// +/// Used by [SystemChrome.setEnabledSystemUIMode]. +enum SystemUiMode { + /// Fullscreen display with status and navigation bars presentable by tapping + /// anywhere on the display. + /// + /// Available starting at SDK 16 or Android J. Earlier versions of Android + /// will not be affected by this setting. + /// + /// For applications running on iOS, the status bar and home indicator will be + /// hidden for a similar fullscreen experience. + /// + /// Tapping on the screen displays overlays, this gesture is not received by + /// the application. + /// + /// See also: + /// + /// * [SystemUiChangeCallback], used to listen and respond to the change in + /// system overlays. + leanBack, + + /// Fullscreen display with status and navigation bars presentable through a + /// swipe gesture at the edges of the display. + /// + /// Available starting at SDK 19 or Android K. Earlier versions of Android + /// will not be affected by this setting. + /// + /// For applications running on iOS, the status bar and home indicator will be + /// hidden for a similar fullscreen experience. + /// + /// A swipe gesture from the edge of the screen displays overlays. In contrast + /// to [SystemUiMode.immersiveSticky], this gesture is not received by the + /// application. + /// + /// See also: + /// + /// * [SystemUiChangeCallback], used to listen and respond to the change in + /// system overlays. + immersive, + + /// Fullscreen display with status and navigation bars presentable through a + /// swipe gesture at the edges of the display. + /// + /// Available starting at SDK 19 or Android K. Earlier versions of Android + /// will not be affected by this setting. + /// + /// For applications running on iOS, the status bar and home indicator will be + /// hidden for a similar fullscreen experience. + /// + /// A swipe gesture from the edge of the screen displays overlays. In contrast + /// to [SystemUiMode.immersive], this gesture is received by the application. + /// + /// See also: + /// + /// * [SystemUiChangeCallback], used to listen and respond to the change in + /// system overlays. + immersiveSticky, + + /// Fullscreen display with status and navigation elements rendered over the + /// application. + /// + /// Available starting at SDK 29 or Android 10. Earlier versions of Android + /// will not be affected by this setting. + /// + /// For applications running on iOS, the status bar and home indicator will be + /// visible. + /// + /// The system overlays will not disappear or reappear in this mode as they + /// are permanently displayed on top of the application. + /// + /// See also: + /// + /// * [SystemUiOverlayStyle], can be used to configure transparent status and + /// navigation bars with or without a contrast scrim. + edgeToEdge, + + /// Declares manually configured [SystemUiOverlay]s. + /// + /// When using this mode with [SystemChrome.setEnabledSystemUIMode], the + /// preferred overlays must be set by the developer. + /// + /// When [SystemUiOverlay.top] is enabled, the status bar will remain visible + /// on all platforms. Omitting this overlay will hide the status bar on iOS & + /// Android. + /// + /// When [SystemUiOverlay.bottom] is enabled, the navigation bar and home + /// indicator of Android and iOS applications will remain visible. Omitting this + /// overlay will hide them. + /// + /// Omitting both overlays will result in the same configuration as + /// [SystemUiMode.leanBack]. + manual, +} + +/// Specifies a preference for the style of the system overlays. +/// +/// Used by [AppBar.systemOverlayStyle] for declaratively setting the style of +/// the system overlays, and by [SystemChrome.setSystemUIOverlayStyle] for +/// imperatively setting the style of the systeme overlays. +@immutable +class SystemUiOverlayStyle { + /// Creates a new [SystemUiOverlayStyle]. + const SystemUiOverlayStyle({ + this.systemNavigationBarColor, + this.systemNavigationBarDividerColor, + this.systemNavigationBarIconBrightness, + this.systemNavigationBarContrastEnforced, + this.statusBarColor, + this.statusBarBrightness, + this.statusBarIconBrightness, + this.systemStatusBarContrastEnforced, + }); + + /// The color of the system bottom navigation bar. + /// + /// Only honored in Android versions O and greater. + final Color? systemNavigationBarColor; + + /// The color of the divider between the system's bottom navigation bar and the app's content. + /// + /// Only honored in Android versions P and greater. + final Color? systemNavigationBarDividerColor; + + /// The brightness of the system navigation bar icons. + /// + /// Only honored in Android versions O and greater. + /// When set to [Brightness.light], the system navigation bar icons are light. + /// When set to [Brightness.dark], the system navigation bar icons are dark. + final Brightness? systemNavigationBarIconBrightness; + + /// Overrides the contrast enforcement when setting a transparent navigation + /// bar. + /// + /// When setting a transparent navigation bar in SDK 29+, or Android 10 and up, + /// a translucent body scrim may be applied behind the button navigation bar + /// to ensure contrast with buttons and the background of the application. + /// + /// SDK 28-, or Android P and lower, will not apply this body scrim. + /// + /// Setting this to false overrides the default body scrim. + /// + /// See also: + /// + /// * [SystemUiOverlayStyle.systemNavigationBarColor], which is overridden + /// when transparent to enforce this contrast policy. + final bool? systemNavigationBarContrastEnforced; + + /// The color of top status bar. + /// + /// Only honored in Android version M and greater. + final Color? statusBarColor; + + /// The brightness of top status bar. + /// + /// Only honored in iOS. + final Brightness? statusBarBrightness; + + /// The brightness of the top status bar icons. + /// + /// Only honored in Android version M and greater. + final Brightness? statusBarIconBrightness; + + /// Overrides the contrast enforcement when setting a transparent status + /// bar. + /// + /// When setting a transparent status bar in SDK 29+, or Android 10 and up, + /// a translucent body scrim may be applied to ensure contrast with icons and + /// the background of the application. + /// + /// SDK 28-, or Android P and lower, will not apply this body scrim. + /// + /// Setting this to false overrides the default body scrim. + /// + /// See also: + /// + /// * [SystemUiOverlayStyle.statusBarColor], which is overridden + /// when transparent to enforce this contrast policy. + final bool? systemStatusBarContrastEnforced; + + /// System overlays should be drawn with a light color. Intended for + /// applications with a dark background. + static const SystemUiOverlayStyle light = SystemUiOverlayStyle( + systemNavigationBarColor: Color(0xFF000000), + systemNavigationBarIconBrightness: Brightness.light, + statusBarIconBrightness: Brightness.light, + statusBarBrightness: Brightness.dark, + ); + + /// System overlays should be drawn with a dark color. Intended for + /// applications with a light background. + static const SystemUiOverlayStyle dark = SystemUiOverlayStyle( + systemNavigationBarColor: Color(0xFF000000), + systemNavigationBarIconBrightness: Brightness.light, + statusBarIconBrightness: Brightness.dark, + statusBarBrightness: Brightness.light, + ); + + /// Convert this event to a map for serialization. + Map<String, dynamic> _toMap() { + return <String, dynamic>{ + 'systemNavigationBarColor': systemNavigationBarColor?.value, + 'systemNavigationBarDividerColor': systemNavigationBarDividerColor?.value, + 'systemStatusBarContrastEnforced': systemStatusBarContrastEnforced, + 'statusBarColor': statusBarColor?.value, + 'statusBarBrightness': statusBarBrightness?.toString(), + 'statusBarIconBrightness': statusBarIconBrightness?.toString(), + 'systemNavigationBarIconBrightness': systemNavigationBarIconBrightness?.toString(), + 'systemNavigationBarContrastEnforced': systemNavigationBarContrastEnforced, + }; + } + + @override + String toString() => '${objectRuntimeType(this, 'SystemUiOverlayStyle')}(${_toMap()})'; + + /// Creates a copy of this theme with the given fields replaced with new values. + SystemUiOverlayStyle copyWith({ + Color? systemNavigationBarColor, + Color? systemNavigationBarDividerColor, + bool? systemNavigationBarContrastEnforced, + Color? statusBarColor, + Brightness? statusBarBrightness, + Brightness? statusBarIconBrightness, + bool? systemStatusBarContrastEnforced, + Brightness? systemNavigationBarIconBrightness, + }) { + return SystemUiOverlayStyle( + systemNavigationBarColor: systemNavigationBarColor ?? this.systemNavigationBarColor, + systemNavigationBarDividerColor: systemNavigationBarDividerColor ?? this.systemNavigationBarDividerColor, + systemNavigationBarContrastEnforced: systemNavigationBarContrastEnforced ?? this.systemNavigationBarContrastEnforced, + statusBarColor: statusBarColor ?? this.statusBarColor, + statusBarIconBrightness: statusBarIconBrightness ?? this.statusBarIconBrightness, + statusBarBrightness: statusBarBrightness ?? this.statusBarBrightness, + systemStatusBarContrastEnforced: systemStatusBarContrastEnforced ?? this.systemStatusBarContrastEnforced, + systemNavigationBarIconBrightness: systemNavigationBarIconBrightness ?? this.systemNavigationBarIconBrightness, + ); + } + + @override + int get hashCode => Object.hash( + systemNavigationBarColor, + systemNavigationBarDividerColor, + systemNavigationBarContrastEnforced, + statusBarColor, + statusBarBrightness, + statusBarIconBrightness, + systemStatusBarContrastEnforced, + systemNavigationBarIconBrightness, + ); + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is SystemUiOverlayStyle + && other.systemNavigationBarColor == systemNavigationBarColor + && other.systemNavigationBarDividerColor == systemNavigationBarDividerColor + && other.systemNavigationBarContrastEnforced == systemNavigationBarContrastEnforced + && other.statusBarColor == statusBarColor + && other.statusBarIconBrightness == statusBarIconBrightness + && other.statusBarBrightness == statusBarBrightness + && other.systemStatusBarContrastEnforced == systemStatusBarContrastEnforced + && other.systemNavigationBarIconBrightness == systemNavigationBarIconBrightness; + } +} + +List<String> _stringify(List<dynamic> list) => <String>[ + for (final dynamic item in list) item.toString(), +]; + +/// Controls specific aspects of the operating system's graphical interface and +/// how it interacts with the application. +abstract final class SystemChrome { + /// Specifies the set of orientations the application interface can + /// be displayed in. + /// + /// The `orientation` argument is a list of [DeviceOrientation] enum values. + /// The empty list causes the application to defer to the operating system + /// default. + /// + /// ## Limitations + /// + /// ### Android + /// + /// Android screens may choose to [letterbox](https://developer.android.com/guide/practices/enhanced-letterboxing) + /// applications that lock orientation, particularly on larger screens. When + /// letterboxing occurs on Android, the [MediaQueryData.size] reports the + /// letterboxed size, not the full screen size. Applications that make + /// decisions about whether to lock orientation based on the screen size + /// must use the `display` property of the current [FlutterView]. + /// + /// ```dart + /// // A widget that locks the screen to portrait if it is less than 600 + /// // logical pixels wide. + /// class MyApp extends StatefulWidget { + /// const MyApp({ super.key }); + /// + /// @override + /// State<MyApp> createState() => _MyAppState(); + /// } + /// + /// class _MyAppState extends State<MyApp> with WidgetsBindingObserver { + /// ui.FlutterView? _view; + /// static const double kOrientationLockBreakpoint = 600; + /// + /// @override + /// void initState() { + /// super.initState(); + /// WidgetsBinding.instance.addObserver(this); + /// } + /// + /// @override + /// void didChangeDependencies() { + /// super.didChangeDependencies(); + /// _view = View.maybeOf(context); + /// } + /// + /// @override + /// void dispose() { + /// WidgetsBinding.instance.removeObserver(this); + /// _view = null; + /// super.dispose(); + /// } + /// + /// @override + /// void didChangeMetrics() { + /// final ui.Display? display = _view?.display; + /// if (display == null) { + /// return; + /// } + /// if (display.size.width / display.devicePixelRatio < kOrientationLockBreakpoint) { + /// SystemChrome.setPreferredOrientations(<DeviceOrientation>[ + /// DeviceOrientation.portraitUp, + /// ]); + /// } else { + /// SystemChrome.setPreferredOrientations(<DeviceOrientation>[]); + /// } + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// return const MaterialApp( + /// home: Placeholder(), + /// ); + /// } + /// } + /// ``` + /// + /// ### iOS + /// + /// This setting will only be respected on iPad if multitasking is disabled. + /// + /// You can decide to opt out of multitasking on iPad, then + /// setPreferredOrientations will work but your app will not + /// support Slide Over and Split View multitasking anymore. + /// + /// Should you decide to opt out of multitasking you can do this by + /// setting "Requires full screen" to true in the Xcode Deployment Info. + static Future<void> setPreferredOrientations(List<DeviceOrientation> orientations) async { + await SystemChannels.platform.invokeMethod<void>( + 'SystemChrome.setPreferredOrientations', + _stringify(orientations), + ); + } + + /// Specifies the description of the current state of the application as it + /// pertains to the application switcher (also known as "recent tasks"). + /// + /// Any part of the description that is unsupported on the current platform + /// will be ignored. + static Future<void> setApplicationSwitcherDescription(ApplicationSwitcherDescription description) async { + await SystemChannels.platform.invokeMethod<void>( + 'SystemChrome.setApplicationSwitcherDescription', + <String, dynamic>{ + 'label': description.label, + 'primaryColor': description.primaryColor, + }, + ); + } + + /// Specifies the [SystemUiMode] to have visible when the application + /// is running. + /// + /// The `overlays` argument is a list of [SystemUiOverlay] enum values + /// denoting the overlays to show when configured with [SystemUiMode.manual]. + /// + /// If a particular mode is unsupported on the platform, enabling or + /// disabling that mode will be ignored. + /// + /// The settings here can be overridden by the platform when System UI becomes + /// necessary for functionality. + /// + /// For example, on Android, when the keyboard becomes visible, it will enable the + /// navigation bar and status bar system UI overlays. When the keyboard is closed, + /// Android will not restore the previous UI visibility settings, and the UI + /// visibility cannot be changed until 1 second after the keyboard is closed to + /// prevent malware locking users from navigation buttons. + /// + /// To regain "fullscreen" after text entry, the UI overlays can be set again + /// after a delay of at least 1 second through [restoreSystemUIOverlays] or + /// calling this again. Otherwise, the original UI overlay settings will be + /// automatically restored only when the application loses and regains focus. + /// + /// Alternatively, a [SystemUiChangeCallback] can be provided to respond to + /// changes in the System UI. This will be called, for example, when in + /// [SystemUiMode.leanBack] and the user taps the screen to bring up the + /// system overlays. The callback provides a boolean to represent if the + /// application is currently in a fullscreen mode or not, so that the + /// application can respond to these changes. When `systemOverlaysAreVisible` + /// is true, the application is not fullscreen. See + /// [SystemChrome.setSystemUIChangeCallback] to respond to these changes in a + /// fullscreen application. + static Future<void> setEnabledSystemUIMode(SystemUiMode mode, { List<SystemUiOverlay>? overlays }) async { + if (mode != SystemUiMode.manual) { + await SystemChannels.platform.invokeMethod<void>( + 'SystemChrome.setEnabledSystemUIMode', + mode.toString(), + ); + } else { + assert(mode == SystemUiMode.manual && overlays != null); + await SystemChannels.platform.invokeMethod<void>( + 'SystemChrome.setEnabledSystemUIOverlays', + _stringify(overlays!), + ); + } + } + + /// Sets the callback method for responding to changes in the system UI. + /// + /// This is relevant when using [SystemUiMode.leanBack] + /// and [SystemUiMode.immersive] and [SystemUiMode.immersiveSticky] on Android + /// platforms, where the [SystemUiOverlay]s can appear and disappear based on + /// user interaction. + /// + /// This will be called, for example, when in [SystemUiMode.leanBack] and the + /// user taps the screen to bring up the system overlays. The callback + /// provides a boolean to represent if the application is currently in a + /// fullscreen mode or not, so that the application can respond to these + /// changes. When `systemOverlaysAreVisible` is true, the application is not + /// fullscreen. + /// + /// When using [SystemUiMode.edgeToEdge], system overlays are always visible + /// and do not change. When manually configuring [SystemUiOverlay]s with + /// [SystemUiMode.manual], this callback will only be triggered when all + /// overlays have been disabled. This results in the same behavior as + /// [SystemUiMode.leanBack]. + /// + static Future<void> setSystemUIChangeCallback(SystemUiChangeCallback? callback) async { + ServicesBinding.instance.setSystemUiChangeCallback(callback); + // Skip setting up the listener if there is no callback. + if (callback != null) { + await SystemChannels.platform.invokeMethod<void>( + 'SystemChrome.setSystemUIChangeListener', + ); + } + } + + /// Restores the system overlays to the last settings provided via + /// [setEnabledSystemUIMode]. May be used when the platform force enables/disables + /// UI elements. + /// + /// For example, when the Android keyboard disables hidden status and navigation bars, + /// this can be called to re-disable the bars when the keyboard is closed. + /// + /// On Android, the system UI cannot be changed until 1 second after the previous + /// change. This is to prevent malware from permanently hiding navigation buttons. + static Future<void> restoreSystemUIOverlays() async { + await SystemChannels.platform.invokeMethod<void>( + 'SystemChrome.restoreSystemUIOverlays', + ); + } + + /// Specifies the style to use for the system overlays (e.g. the status bar on + /// Android or iOS, the system navigation bar on Android) that are visible (if any). + /// + /// This method will schedule the embedder update to be run in a microtask. + /// Any subsequent calls to this method during the current event loop will + /// overwrite the pending value, such that only the last specified value takes + /// effect. + /// + /// Call this API in code whose lifecycle matches that of the desired + /// system UI styles. For instance, to change the system UI style on a new + /// page, consider calling when pushing/popping a new [PageRoute]. + /// + /// The [AppBar] widget automatically sets the system overlay style based on + /// its [AppBar.systemOverlayStyle], so configure that instead of calling this + /// method directly. Likewise, do the same for [CupertinoNavigationBar] via + /// [CupertinoNavigationBar.backgroundColor]. + /// + /// If a particular style is not supported on the platform, selecting it will + /// have no effect. + /// + /// {@tool sample} + /// The following example uses an `AppBar` to set the system status bar color and + /// the system navigation bar color. + /// + /// ** See code in examples/api/lib/services/system_chrome/system_chrome.set_system_u_i_overlay_style.0.dart ** + /// {@end-tool} + /// + /// For more complex control of the system overlay styles, consider using + /// an [AnnotatedRegion] widget instead of calling [setSystemUIOverlayStyle] + /// directly. This widget places a value directly into the layer tree where + /// it can be hit-tested by the framework. On every frame, the framework will + /// hit-test and select the annotated region it finds under the status and + /// navigation bar and synthesize them into a single style. This can be used + /// to configure the system styles when an app bar is not used. When an app + /// bar is used, apps should not enclose the app bar in an annotated region + /// because one is automatically created. If an app bar is used and the app + /// bar is enclosed in an annotated region, the app bar overlay style supersedes + /// the status bar properties defined in the enclosing annotated region overlay + /// style and the enclosing annotated region overlay style supersedes the app bar + /// overlay style navigation bar properties. + /// + /// {@tool sample} + /// The following example uses an `AnnotatedRegion<SystemUiOverlayStyle>` to set + /// the system status bar color and the system navigation bar color. + /// + /// ** See code in examples/api/lib/services/system_chrome/system_chrome.set_system_u_i_overlay_style.1.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [AppBar.systemOverlayStyle], a convenient property for declaratively setting + /// the style of the system overlays. + /// * [AnnotatedRegion], the widget used to place a `SystemUiOverlayStyle` into + /// the layer tree. + static void setSystemUIOverlayStyle(SystemUiOverlayStyle style) { + if (_pendingStyle != null) { + // The microtask has already been queued; just update the pending value. + _pendingStyle = style; + return; + } + if (style == _latestStyle) { + // Trivial success: no microtask has been queued and the given style is + // already in effect, so no need to queue a microtask. + return; + } + _pendingStyle = style; + scheduleMicrotask(() { + assert(_pendingStyle != null); + if (_pendingStyle != _latestStyle) { + SystemChannels.platform.invokeMethod<void>( + 'SystemChrome.setSystemUIOverlayStyle', + _pendingStyle!._toMap(), + ); + _latestStyle = _pendingStyle; + } + _pendingStyle = null; + }); + } + + static SystemUiOverlayStyle? _pendingStyle; + + /// The last style that was set using [SystemChrome.setSystemUIOverlayStyle]. + @visibleForTesting + static SystemUiOverlayStyle? get latestStyle => _latestStyle; + static SystemUiOverlayStyle? _latestStyle; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_navigator.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_navigator.dart new file mode 100644 index 0000000000000000000000000000000000000000..1ea16f921ac91bc37f178c8c38c3cf51b9225387 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_navigator.dart @@ -0,0 +1,137 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'system_channels.dart'; + +/// Controls specific aspects of the system navigation stack. +abstract final class SystemNavigator { + /// Informs the platform of whether or not the Flutter framework will handle + /// back events. + /// + /// Currently, this is used only on Android to inform its use of the + /// predictive back gesture when exiting the app. When true, predictive back + /// is disabled. + /// + /// See also: + /// + /// * The + /// [migration guide](https://developer.android.com/guide/navigation/predictive-back-gesture) + /// for predictive back in native Android apps. + static Future<void> setFrameworkHandlesBack(bool frameworkHandlesBack) async { + // Currently, this method call is only relevant on Android. + if (kIsWeb) { + return; + } + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return; + case TargetPlatform.android: + return SystemChannels.platform.invokeMethod<void>( + 'SystemNavigator.setFrameworkHandlesBack', + frameworkHandlesBack, + ); + } + } + + /// Removes the topmost Flutter instance, presenting what was before + /// it. + /// + /// On Android, removes this activity from the stack and returns to + /// the previous activity. + /// + /// On iOS, calls `popViewControllerAnimated:` if the root view + /// controller is a `UINavigationController`, or + /// `dismissViewControllerAnimated:completion:` if the top view + /// controller is a `FlutterViewController`. + /// + /// The optional `animated` parameter is ignored on all platforms + /// except iOS where it is an argument to the aforementioned + /// methods. + /// + /// This method should be preferred over calling `dart:io`'s [exit] + /// method, as the latter may cause the underlying platform to act + /// as if the application had crashed. + static Future<void> pop({bool? animated}) async { + await SystemChannels.platform.invokeMethod<void>('SystemNavigator.pop', animated); + } + + /// Selects the single-entry history mode. + /// + /// On web, this switches the browser history model to one that only tracks a + /// single entry, so that calling [routeInformationUpdated] replaces the + /// current entry. + /// + /// Currently, this is ignored on other platforms. + /// + /// See also: + /// + /// * [selectMultiEntryHistory], which enables the browser history to have + /// multiple entries. + static Future<void> selectSingleEntryHistory() { + return SystemChannels.navigation.invokeMethod<void>('selectSingleEntryHistory'); + } + + /// Selects the multiple-entry history mode. + /// + /// On web, this switches the browser history model to one that tracks all + /// updates to [routeInformationUpdated] to form a history stack. This is the + /// default. + /// + /// Currently, this is ignored on other platforms. + /// + /// See also: + /// + /// * [selectSingleEntryHistory], which forces the history to only have one + /// entry. + static Future<void> selectMultiEntryHistory() { + return SystemChannels.navigation.invokeMethod<void>('selectMultiEntryHistory'); + } + + /// Notifies the platform for a route information change. + /// + /// On web, this method behaves differently based on the single-entry or + /// multiple-entries history mode. Use the [selectSingleEntryHistory] and + /// [selectMultiEntryHistory] to toggle between modes. + /// + /// For single-entry mode, this method replaces the current URL and state in + /// the current history entry. The flag `replace` is ignored. + /// + /// For multiple-entries mode, this method creates a new history entry on top + /// of the current entry if the `replace` is false, thus the user will + /// be on a new history entry as if the user has visited a new page, and the + /// browser back button brings the user back to the previous entry. If + /// `replace` is true, this method only updates the URL and the state in the + /// current history entry without pushing a new one. + /// + /// This method is ignored on other platforms. + /// + /// The `replace` flag defaults to false. + static Future<void> routeInformationUpdated({ + @Deprecated( + 'Pass Uri.parse(location) to uri parameter instead. ' + 'This feature was deprecated after v3.8.0-3.0.pre.' + ) + String? location, + Uri? uri, + Object? state, + bool replace = false, + }) { + assert((location != null) != (uri != null), 'One of uri or location must be provided, but not both.'); + uri ??= Uri.parse(location!); + return SystemChannels.navigation.invokeMethod<void>( + 'routeInformationUpdated', + <String, dynamic>{ + 'uri': uri.toString(), + 'state': state, + 'replace': replace, + }, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_sound.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_sound.dart new file mode 100644 index 0000000000000000000000000000000000000000..91b024fa694b034ee1a2b075884a368924a79404 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/system_sound.dart @@ -0,0 +1,41 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'system_channels.dart'; + +/// A sound provided by the system. +/// +/// These sounds may be played with [SystemSound.play]. +enum SystemSoundType { + /// A short indication that a button was pressed. + click, + + /// A short system alert sound indicating the need for user attention. + /// + /// Desktop platforms are the only platforms that support a system alert + /// sound, so on mobile platforms (Android, iOS), this will be ignored. The + /// web platform does not support playing any sounds, so this will be + /// ignored on the web as well. + alert, + + // If you add new values here, you also need to update the `SoundType` Java + // enum in `PlatformChannel.java`. +} + +/// Provides access to the library of short system specific sounds for common +/// tasks. +abstract final class SystemSound { + /// Play the specified system sound. If that sound is not present on the + /// system, the call is ignored. + /// + /// The web platform currently does not support playing sounds, so this call + /// will yield no behavior on that platform. + static Future<void> play(SystemSoundType type) async { + await SystemChannels.platform.invokeMethod<void>( + 'SystemSound.play', + type.toString(), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_boundary.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_boundary.dart new file mode 100644 index 0000000000000000000000000000000000000000..e7e453e2a384957d94c0093aeb148265238779c8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_boundary.dart @@ -0,0 +1,219 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math'; + +import 'package:characters/characters.dart' show CharacterRange; + +import 'text_layout_metrics.dart'; + +// Examples can assume: +// late TextLayoutMetrics textLayout; +// late TextSpan text; +// bool isWhitespace(int? codeUnit) => true; + +/// Signature for a predicate that takes an offset into a UTF-16 string, and a +/// boolean that indicates the search direction. +typedef UntilPredicate = bool Function(int offset, bool forward); + +/// An interface for retrieving the logical text boundary (as opposed to the +/// visual boundary) at a given code unit offset in a document. +/// +/// Either the [getTextBoundaryAt] method, or both the +/// [getLeadingTextBoundaryAt] method and the [getTrailingTextBoundaryAt] method +/// must be implemented. +abstract class TextBoundary { + /// A constant constructor to enable subclass override. + const TextBoundary(); + + /// Returns the offset of the closest text boundary before or at the given + /// `position`, or null if no boundaries can be found. + /// + /// The return value, if not null, is usually less than or equal to `position`. + /// + /// The range of the return value is given by the closed interval + /// `[0, string.length]`. + int? getLeadingTextBoundaryAt(int position) { + if (position < 0) { + return null; + } + final int start = getTextBoundaryAt(position).start; + return start >= 0 ? start : null; + } + + /// Returns the offset of the closest text boundary after the given + /// `position`, or null if there is no boundary can be found after `position`. + /// + /// The return value, if not null, is usually greater than `position`. + /// + /// The range of the return value is given by the closed interval + /// `[0, string.length]`. + int? getTrailingTextBoundaryAt(int position) { + final int end = getTextBoundaryAt(max(0, position)).end; + return end >= 0 ? end : null; + } + + /// Returns the text boundary range that encloses the input position. + /// + /// The returned [TextRange] may contain `-1`, which indicates no boundaries + /// can be found in that direction. + TextRange getTextBoundaryAt(int position) { + final int start = getLeadingTextBoundaryAt(position) ?? -1; + final int end = getTrailingTextBoundaryAt(position) ?? -1; + return TextRange(start: start, end: end); + } +} + +/// A [TextBoundary] subclass for retrieving the range of the grapheme the given +/// `position` is in. +/// +/// The class is implemented using the +/// [characters](https://pub.dev/packages/characters) package. +class CharacterBoundary extends TextBoundary { + /// Creates a [CharacterBoundary] with the text. + const CharacterBoundary(this._text); + + final String _text; + + @override + int? getLeadingTextBoundaryAt(int position) { + if (position < 0) { + return null; + } + final int graphemeStart = CharacterRange.at(_text, min(position, _text.length)).stringBeforeLength; + assert(CharacterRange.at(_text, graphemeStart).isEmpty); + return graphemeStart; + } + + @override + int? getTrailingTextBoundaryAt(int position) { + if (position >= _text.length) { + return null; + } + final CharacterRange rangeAtPosition = CharacterRange.at(_text, max(0, position + 1)); + final int nextBoundary = rangeAtPosition.stringBeforeLength + rangeAtPosition.current.length; + assert(nextBoundary == _text.length || CharacterRange.at(_text, nextBoundary).isEmpty); + return nextBoundary; + } + + @override + TextRange getTextBoundaryAt(int position) { + if (position < 0) { + return TextRange(start: -1, end: getTrailingTextBoundaryAt(position) ?? -1); + } else if (position >= _text.length) { + return TextRange(start: getLeadingTextBoundaryAt(position) ?? -1, end: -1); + } + final CharacterRange rangeAtPosition = CharacterRange.at(_text, position); + return rangeAtPosition.isNotEmpty + ? TextRange(start: rangeAtPosition.stringBeforeLength, end: rangeAtPosition.stringBeforeLength + rangeAtPosition.current.length) + // rangeAtPosition is empty means `position` is a grapheme boundary. + : TextRange(start: rangeAtPosition.stringBeforeLength, end: getTrailingTextBoundaryAt(position) ?? -1); + } +} + +/// A [TextBoundary] subclass for locating closest line breaks to a given +/// `position`. +/// +/// When the given `position` points to a hard line break, the returned range +/// is the line's content range before the hard line break, and does not contain +/// the given `position`. For instance, the line breaks at `position = 1` for +/// "a\nb" is `[0, 1)`, which does not contain the position `1`. +class LineBoundary extends TextBoundary { + /// Creates a [LineBoundary] with the text and layout information. + const LineBoundary(this._textLayout); + + final TextLayoutMetrics _textLayout; + + @override + TextRange getTextBoundaryAt(int position) => _textLayout.getLineAtOffset(TextPosition(offset: max(position, 0))); +} + +/// A text boundary that uses paragraphs as logical boundaries. +/// +/// A paragraph is defined as the range between line terminators. If no +/// line terminators exist then the paragraph boundary is the entire document. +class ParagraphBoundary extends TextBoundary { + /// Creates a [ParagraphBoundary] with the text. + const ParagraphBoundary(this._text); + + final String _text; + + /// Returns the [int] representing the start position of the paragraph that + /// bounds the given `position`. The returned [int] is the position of the code unit + /// that follows the line terminator that encloses the desired paragraph. + @override + int? getLeadingTextBoundaryAt(int position) { + if (position < 0 || _text.isEmpty) { + return null; + } + + if (position >= _text.length) { + return _text.length; + } + + if (position == 0) { + return 0; + } + + int index = position; + + if (index > 1 && _text.codeUnitAt(index) == 0x0A && _text.codeUnitAt(index - 1) == 0x0D) { + index -= 2; + } else if (TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) { + index -= 1; + } + + while (index > 0) { + if (TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) { + return index + 1; + } + index -= 1; + } + + return max(index, 0); + } + + /// Returns the [int] representing the end position of the paragraph that + /// bounds the given `position`. The returned [int] is the position of the + /// code unit representing the trailing line terminator that encloses the + /// desired paragraph. + @override + int? getTrailingTextBoundaryAt(int position) { + if (position >= _text.length || _text.isEmpty) { + return null; + } + + if (position < 0) { + return 0; + } + + int index = position; + + while (!TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) { + index += 1; + if (index == _text.length) { + return index; + } + } + + return index < _text.length - 1 + && _text.codeUnitAt(index) == 0x0D + && _text.codeUnitAt(index + 1) == 0x0A + ? index + 2 + : index + 1; + } +} + +/// A text boundary that uses the entire document as logical boundary. +class DocumentBoundary extends TextBoundary { + /// Creates a [DocumentBoundary] with the text. + const DocumentBoundary(this._text); + + final String _text; + + @override + int? getLeadingTextBoundaryAt(int position) => position < 0 ? null : 0; + @override + int? getTrailingTextBoundaryAt(int position) => position >= _text.length ? null : _text.length; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_editing.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_editing.dart new file mode 100644 index 0000000000000000000000000000000000000000..d1d91c20ef28904ce7b346b289dbc90343ab0f7a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_editing.dart @@ -0,0 +1,258 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show TextAffinity, TextPosition, TextRange; + +import 'package:flutter/foundation.dart'; + +export 'dart:ui' show TextAffinity, TextPosition; + +/// A range of text that represents a selection. +@immutable +class TextSelection extends TextRange { + /// Creates a text selection. + const TextSelection({ + required this.baseOffset, + required this.extentOffset, + this.affinity = TextAffinity.downstream, + this.isDirectional = false, + }) : super( + start: baseOffset < extentOffset ? baseOffset : extentOffset, + end: baseOffset < extentOffset ? extentOffset : baseOffset, + ); + + /// Creates a collapsed selection at the given offset. + /// + /// A collapsed selection starts and ends at the same offset, which means it + /// contains zero characters but instead serves as an insertion point in the + /// text. + const TextSelection.collapsed({ + required int offset, + this.affinity = TextAffinity.downstream, + }) : baseOffset = offset, + extentOffset = offset, + isDirectional = false, + super.collapsed(offset); + + /// Creates a collapsed selection at the given text position. + /// + /// A collapsed selection starts and ends at the same offset, which means it + /// contains zero characters but instead serves as an insertion point in the + /// text. + TextSelection.fromPosition(TextPosition position) + : baseOffset = position.offset, + extentOffset = position.offset, + affinity = position.affinity, + isDirectional = false, + super.collapsed(position.offset); + + /// The offset at which the selection originates. + /// + /// Might be larger than, smaller than, or equal to extent. + final int baseOffset; + + /// The offset at which the selection terminates. + /// + /// When the user uses the arrow keys to adjust the selection, this is the + /// value that changes. Similarly, if the current theme paints a caret on one + /// side of the selection, this is the location at which to paint the caret. + /// + /// Might be larger than, smaller than, or equal to base. + final int extentOffset; + + /// If the text range is collapsed and has more than one visual location + /// (e.g., occurs at a line break), which of the two locations to use when + /// painting the caret. + final TextAffinity affinity; + + /// Whether this selection has disambiguated its base and extent. + /// + /// On some platforms, the base and extent are not disambiguated until the + /// first time the user adjusts the selection. At that point, either the start + /// or the end of the selection becomes the base and the other one becomes the + /// extent and is adjusted. + final bool isDirectional; + + /// The position at which the selection originates. + /// + /// {@template flutter.services.TextSelection.TextAffinity} + /// The [TextAffinity] of the resulting [TextPosition] is based on the + /// relative logical position in the text to the other selection endpoint: + /// * if [baseOffset] < [extentOffset], [base] will have + /// [TextAffinity.downstream] and [extent] will have + /// [TextAffinity.upstream]. + /// * if [baseOffset] > [extentOffset], [base] will have + /// [TextAffinity.upstream] and [extent] will have + /// [TextAffinity.downstream]. + /// * if [baseOffset] == [extentOffset], [base] and [extent] will both have + /// the collapsed selection's [affinity]. + /// {@endtemplate} + /// + /// Might be larger than, smaller than, or equal to extent. + TextPosition get base { + final TextAffinity affinity; + if (!isValid || baseOffset == extentOffset) { + affinity = this.affinity; + } else if (baseOffset < extentOffset) { + affinity = TextAffinity.downstream; + } else { + affinity = TextAffinity.upstream; + } + return TextPosition(offset: baseOffset, affinity: affinity); + } + + /// The position at which the selection terminates. + /// + /// When the user uses the arrow keys to adjust the selection, this is the + /// value that changes. Similarly, if the current theme paints a caret on one + /// side of the selection, this is the location at which to paint the caret. + /// + /// {@macro flutter.services.TextSelection.TextAffinity} + /// + /// Might be larger than, smaller than, or equal to base. + TextPosition get extent { + final TextAffinity affinity; + if (!isValid || baseOffset == extentOffset) { + affinity = this.affinity; + } else if (baseOffset < extentOffset) { + affinity = TextAffinity.upstream; + } else { + affinity = TextAffinity.downstream; + } + return TextPosition(offset: extentOffset, affinity: affinity); + } + + @override + String toString() { + final String typeName = objectRuntimeType(this, 'TextSelection'); + if (!isValid) { + return '$typeName.invalid'; + } + return isCollapsed + ? '$typeName.collapsed(offset: $baseOffset, affinity: $affinity, isDirectional: $isDirectional)' + : '$typeName(baseOffset: $baseOffset, extentOffset: $extentOffset, isDirectional: $isDirectional)'; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other is! TextSelection) { + return false; + } + if (!isValid) { + return !other.isValid; + } + return other.baseOffset == baseOffset + && other.extentOffset == extentOffset + && (!isCollapsed || other.affinity == affinity) + && other.isDirectional == isDirectional; + } + + @override + int get hashCode { + if (!isValid) { + return Object.hash(-1.hashCode, -1.hashCode, TextAffinity.downstream.hashCode); + } + + final int affinityHash = isCollapsed ? affinity.hashCode : TextAffinity.downstream.hashCode; + return Object.hash(baseOffset.hashCode, extentOffset.hashCode, affinityHash, isDirectional.hashCode); + } + + + /// Creates a new [TextSelection] based on the current selection, with the + /// provided parameters overridden. + TextSelection copyWith({ + int? baseOffset, + int? extentOffset, + TextAffinity? affinity, + bool? isDirectional, + }) { + return TextSelection( + baseOffset: baseOffset ?? this.baseOffset, + extentOffset: extentOffset ?? this.extentOffset, + affinity: affinity ?? this.affinity, + isDirectional: isDirectional ?? this.isDirectional, + ); + } + + /// Returns the smallest [TextSelection] that this could expand to in order to + /// include the given [TextPosition]. + /// + /// If the given [TextPosition] is already inside of the selection, then + /// returns `this` without change. + /// + /// The returned selection will always be a strict superset of the current + /// selection. In other words, the selection grows to include the given + /// [TextPosition]. + /// + /// If extentAtIndex is true, then the [TextSelection.extentOffset] will be + /// placed at the given index regardless of the original order of it and + /// [TextSelection.baseOffset]. Otherwise, their order will be preserved. + /// + /// ## Difference with [extendTo] + /// In contrast with this method, [extendTo] is a pivot; it holds + /// [TextSelection.baseOffset] fixed while moving [TextSelection.extentOffset] + /// to the given [TextPosition]. It doesn't strictly grow the selection and + /// may collapse it or flip its order. + TextSelection expandTo(TextPosition position, [bool extentAtIndex = false]) { + // If position is already within in the selection, there's nothing to do. + if (position.offset >= start && position.offset <= end) { + return this; + } + + final bool normalized = baseOffset <= extentOffset; + if (position.offset <= start) { + // Here the position is somewhere before the selection: ..|..[...].... + if (extentAtIndex) { + return copyWith( + baseOffset: end, + extentOffset: position.offset, + affinity: position.affinity, + ); + } + return copyWith( + baseOffset: normalized ? position.offset : baseOffset, + extentOffset: normalized ? extentOffset : position.offset, + ); + } + // Here the position is somewhere after the selection: ....[...]..|.. + if (extentAtIndex) { + return copyWith( + baseOffset: start, + extentOffset: position.offset, + affinity: position.affinity, + ); + } + return copyWith( + baseOffset: normalized ? baseOffset : position.offset, + extentOffset: normalized ? position.offset : extentOffset, + ); + } + + /// Keeping the selection's [TextSelection.baseOffset] fixed, pivot the + /// [TextSelection.extentOffset] to the given [TextPosition]. + /// + /// In some cases, the [TextSelection.baseOffset] and + /// [TextSelection.extentOffset] may flip during this operation, and/or the + /// size of the selection may shrink. + /// + /// ## Difference with [expandTo] + /// In contrast with this method, [expandTo] is strictly growth; the + /// selection is grown to include the given [TextPosition] and will never + /// shrink. + TextSelection extendTo(TextPosition position) { + // If the selection's extent is at the position already, then nothing + // happens. + if (extent == position) { + return this; + } + + return copyWith( + extentOffset: position.offset, + affinity: position.affinity, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_editing_delta.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_editing_delta.dart new file mode 100644 index 0000000000000000000000000000000000000000..aff975414674ab9bb496651dc1125f75fcc73be5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_editing_delta.dart @@ -0,0 +1,430 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show TextRange; + +import 'package:flutter/foundation.dart'; + +import 'text_editing.dart'; +import 'text_input.dart' show TextEditingValue; + +export 'dart:ui' show TextRange; + +export 'text_editing.dart' show TextSelection; +export 'text_input.dart' show TextEditingValue; + +TextAffinity? _toTextAffinity(String? affinity) { + switch (affinity) { + case 'TextAffinity.downstream': + return TextAffinity.downstream; + case 'TextAffinity.upstream': + return TextAffinity.upstream; + } + return null; +} + +// Replaces a range of text in the original string with the text given in the +// replacement string. +String _replace(String originalText, String replacementText, TextRange replacementRange) { + assert(replacementRange.isValid); + return originalText.replaceRange(replacementRange.start, replacementRange.end, replacementText); +} + +// Verify that the given range is within the text. +bool _debugTextRangeIsValid(TextRange range, String text) { + if (!range.isValid) { + return true; + } + + return (range.start >= 0 && range.start <= text.length) + && (range.end >= 0 && range.end <= text.length); +} + +/// A structure representing a granular change that has occurred to the editing +/// state as a result of text editing. +/// +/// See also: +/// +/// * [TextEditingDeltaInsertion], a delta representing an insertion. +/// * [TextEditingDeltaDeletion], a delta representing a deletion. +/// * [TextEditingDeltaReplacement], a delta representing a replacement. +/// * [TextEditingDeltaNonTextUpdate], a delta representing an update to the +/// selection and/or composing region. +/// * [TextInputConfiguration], to opt-in your [DeltaTextInputClient] to receive +/// [TextEditingDelta]'s you must set [TextInputConfiguration.enableDeltaModel] +/// to true. +abstract class TextEditingDelta with Diagnosticable { + /// Creates a delta for a given change to the editing state. + const TextEditingDelta({ + required this.oldText, + required this.selection, + required this.composing, + }); + + /// Creates an instance of this class from a JSON object by inferring the + /// type of delta based on values sent from the engine. + factory TextEditingDelta.fromJSON(Map<String, dynamic> encoded) { + // An insertion delta is one where replacement destination is collapsed. + // + // A deletion delta is one where the replacement source is empty. + // + // An insertion/deletion can still occur when the replacement destination is not + // collapsed, or the replacement source is not empty. + // + // On native platforms when composing text, the entire composing region is + // replaced on input, rather than reporting character by character + // insertion/deletion. In these cases we can detect if there was an + // insertion/deletion by checking if the text inside the original composing + // region was modified by the replacement. If the text is the same then we have + // an insertion/deletion. If the text is different then we can say we have + // a replacement. + // + // For example say we are currently composing the word: 'world'. + // Our current state is 'worl|' with the cursor at the end of 'l'. If we + // input the character 'd', the platform will tell us 'worl' was replaced + // with 'world' at range (0,4). Here we can check if the text found in the + // composing region (0,4) has been modified. We see that it hasn't because + // 'worl' == 'worl', so this means that the text in + // 'world'{replacementDestinationEnd, replacementDestinationStart + replacementSourceEnd} + // can be considered an insertion. In this case we inserted 'd'. + // + // Similarly for a deletion, say we are currently composing the word: 'worl'. + // Our current state is 'world|' with the cursor at the end of 'd'. If we + // press backspace to delete the character 'd', the platform will tell us 'world' + // was replaced with 'worl' at range (0,5). Here we can check if the text found + // in the new composing region, is the same as the replacement text. We can do this + // by using oldText{replacementDestinationStart, replacementDestinationStart + replacementSourceEnd} + // which in this case is 'worl'. We then compare 'worl' with 'worl' and + // verify that they are the same. This means that the text in + // 'world'{replacementDestinationEnd, replacementDestinationStart + replacementSourceEnd} was deleted. + // In this case the character 'd' was deleted. + // + // A replacement delta occurs when the original composing region has been + // modified. + // + // A non text update delta occurs when the selection and/or composing region + // has been changed by the platform, and there have been no changes to the + // text value. + final String oldText = encoded['oldText'] as String; + final int replacementDestinationStart = encoded['deltaStart'] as int; + final int replacementDestinationEnd = encoded['deltaEnd'] as int; + final String replacementSource = encoded['deltaText'] as String; + const int replacementSourceStart = 0; + final int replacementSourceEnd = replacementSource.length; + + // This delta is explicitly a non text update. + final bool isNonTextUpdate = replacementDestinationStart == -1 && replacementDestinationStart == replacementDestinationEnd; + final TextRange newComposing = TextRange( + start: encoded['composingBase'] as int? ?? -1, + end: encoded['composingExtent'] as int? ?? -1, + ); + final TextSelection newSelection = TextSelection( + baseOffset: encoded['selectionBase'] as int? ?? -1, + extentOffset: encoded['selectionExtent'] as int? ?? -1, + affinity: _toTextAffinity(encoded['selectionAffinity'] as String?) ?? + TextAffinity.downstream, + isDirectional: encoded['selectionIsDirectional'] as bool? ?? false, + ); + + if (isNonTextUpdate) { + assert(_debugTextRangeIsValid(newSelection, oldText), 'The selection range: $newSelection is not within the bounds of text: $oldText of length: ${oldText.length}'); + assert(_debugTextRangeIsValid(newComposing, oldText), 'The composing range: $newComposing is not within the bounds of text: $oldText of length: ${oldText.length}'); + + return TextEditingDeltaNonTextUpdate( + oldText: oldText, + selection: newSelection, + composing: newComposing, + ); + } + + assert(_debugTextRangeIsValid(TextRange(start: replacementDestinationStart, end: replacementDestinationEnd), oldText), 'The delta range: ${TextRange(start: replacementSourceStart, end: replacementSourceEnd)} is not within the bounds of text: $oldText of length: ${oldText.length}'); + + final String newText = _replace(oldText, replacementSource, TextRange(start: replacementDestinationStart, end: replacementDestinationEnd)); + + assert(_debugTextRangeIsValid(newSelection, newText), 'The selection range: $newSelection is not within the bounds of text: $newText of length: ${newText.length}'); + assert(_debugTextRangeIsValid(newComposing, newText), 'The composing range: $newComposing is not within the bounds of text: $newText of length: ${newText.length}'); + + final bool isEqual = oldText == newText; + + final bool isDeletionGreaterThanOne = (replacementDestinationEnd - replacementDestinationStart) - (replacementSourceEnd - replacementSourceStart) > 1; + final bool isDeletingByReplacingWithEmpty = replacementSource.isEmpty && replacementSourceStart == 0 && replacementSourceStart == replacementSourceEnd; + + final bool isReplacedByShorter = isDeletionGreaterThanOne && (replacementSourceEnd - replacementSourceStart < replacementDestinationEnd - replacementDestinationStart); + final bool isReplacedByLonger = replacementSourceEnd - replacementSourceStart > replacementDestinationEnd - replacementDestinationStart; + final bool isReplacedBySame = replacementSourceEnd - replacementSourceStart == replacementDestinationEnd - replacementDestinationStart; + + final bool isInsertingInsideComposingRegion = replacementDestinationStart + replacementSourceEnd > replacementDestinationEnd; + final bool isDeletingInsideComposingRegion = + !isReplacedByShorter && !isDeletingByReplacingWithEmpty && replacementDestinationStart + replacementSourceEnd < replacementDestinationEnd; + + String newComposingText; + String originalComposingText; + + if (isDeletingByReplacingWithEmpty || isDeletingInsideComposingRegion || isReplacedByShorter) { + newComposingText = replacementSource.substring(replacementSourceStart, replacementSourceEnd); + originalComposingText = oldText.substring(replacementDestinationStart, replacementDestinationStart + replacementSourceEnd); + } else { + newComposingText = replacementSource.substring(replacementSourceStart, replacementSourceStart + (replacementDestinationEnd - replacementDestinationStart)); + originalComposingText = oldText.substring(replacementDestinationStart, replacementDestinationEnd); + } + + final bool isOriginalComposingRegionTextChanged = !(originalComposingText == newComposingText); + final bool isReplaced = isOriginalComposingRegionTextChanged || + (isReplacedByLonger || isReplacedByShorter || isReplacedBySame); + + if (isEqual) { + return TextEditingDeltaNonTextUpdate( + oldText: oldText, + selection: newSelection, + composing: newComposing, + ); + } else if ((isDeletingByReplacingWithEmpty || isDeletingInsideComposingRegion) && + !isOriginalComposingRegionTextChanged) { // Deletion. + int actualStart = replacementDestinationStart; + + if (!isDeletionGreaterThanOne) { + actualStart = replacementDestinationEnd - 1; + } + + return TextEditingDeltaDeletion( + oldText: oldText, + deletedRange: TextRange( + start: actualStart, + end: replacementDestinationEnd, + ), + selection: newSelection, + composing: newComposing, + ); + } else if ((replacementDestinationStart == replacementDestinationEnd || isInsertingInsideComposingRegion) && + !isOriginalComposingRegionTextChanged) { // Insertion. + return TextEditingDeltaInsertion( + oldText: oldText, + textInserted: replacementSource.substring(replacementDestinationEnd - replacementDestinationStart, (replacementDestinationEnd - replacementDestinationStart) + (replacementSource.length - (replacementDestinationEnd - replacementDestinationStart))), + insertionOffset: replacementDestinationEnd, + selection: newSelection, + composing: newComposing, + ); + } else if (isReplaced) { // Replacement. + return TextEditingDeltaReplacement( + oldText: oldText, + replacementText: replacementSource, + replacedRange: TextRange( + start: replacementDestinationStart, + end: replacementDestinationEnd, + ), + selection: newSelection, + composing: newComposing, + ); + } + assert(false); + return TextEditingDeltaNonTextUpdate( + oldText: oldText, + selection: newSelection, + composing: newComposing, + ); + } + + /// The old text state before the delta has occurred. + final String oldText; + + /// The range of text that is currently selected after the delta has been + /// applied. + final TextSelection selection; + + /// The range of text that is still being composed after the delta has been + /// applied. + final TextRange composing; + + /// This method will take the given [TextEditingValue] and return a new + /// [TextEditingValue] with that instance of [TextEditingDelta] applied to it. + TextEditingValue apply(TextEditingValue value); +} + +/// A structure representing an insertion of a single/or contiguous sequence of +/// characters at some offset of an editing state. +@immutable +class TextEditingDeltaInsertion extends TextEditingDelta { + /// Creates an insertion delta for a given change to the editing state. + /// + /// {@template flutter.services.TextEditingDelta.optIn} + /// See also: + /// + /// * [TextInputConfiguration], to opt-in your [DeltaTextInputClient] to receive + /// [TextEditingDelta]'s you must set [TextInputConfiguration.enableDeltaModel] + /// to true. + /// {@endtemplate} + const TextEditingDeltaInsertion({ + required super.oldText, + required this.textInserted, + required this.insertionOffset, + required super.selection, + required super.composing, + }); + + /// The text that is being inserted into [oldText]. + final String textInserted; + + /// The offset in the [oldText] where the insertion begins. + final int insertionOffset; + + @override + TextEditingValue apply(TextEditingValue value) { + // To stay inline with the plain text model we should follow a last write wins + // policy and apply the delta to the oldText. This is due to the asynchronous + // nature of the connection between the framework and platform text input plugins. + String newText = oldText; + assert(_debugTextRangeIsValid(TextRange.collapsed(insertionOffset), newText), 'Applying TextEditingDeltaInsertion failed, the insertionOffset: $insertionOffset is not within the bounds of $newText of length: ${newText.length}'); + newText = _replace(newText, textInserted, TextRange.collapsed(insertionOffset)); + assert(_debugTextRangeIsValid(selection, newText), 'Applying TextEditingDeltaInsertion failed, the selection range: $selection is not within the bounds of $newText of length: ${newText.length}'); + assert(_debugTextRangeIsValid(composing, newText), 'Applying TextEditingDeltaInsertion failed, the composing range: $composing is not within the bounds of $newText of length: ${newText.length}'); + return value.copyWith(text: newText, selection: selection, composing: composing); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('oldText', oldText)); + properties.add(DiagnosticsProperty<String>('textInserted', textInserted)); + properties.add(DiagnosticsProperty<int>('insertionOffset', insertionOffset)); + properties.add(DiagnosticsProperty<TextSelection>('selection', selection)); + properties.add(DiagnosticsProperty<TextRange>('composing', composing)); + } +} + +/// A structure representing the deletion of a single/or contiguous sequence of +/// characters in an editing state. +@immutable +class TextEditingDeltaDeletion extends TextEditingDelta { + /// Creates a deletion delta for a given change to the editing state. + /// + /// {@macro flutter.services.TextEditingDelta.optIn} + const TextEditingDeltaDeletion({ + required super.oldText, + required this.deletedRange, + required super.selection, + required super.composing, + }); + + /// The range in [oldText] that is being deleted. + final TextRange deletedRange; + + /// The text from [oldText] that is being deleted. + String get textDeleted => oldText.substring(deletedRange.start, deletedRange.end); + + @override + TextEditingValue apply(TextEditingValue value) { + // To stay inline with the plain text model we should follow a last write wins + // policy and apply the delta to the oldText. This is due to the asynchronous + // nature of the connection between the framework and platform text input plugins. + String newText = oldText; + assert(_debugTextRangeIsValid(deletedRange, newText), 'Applying TextEditingDeltaDeletion failed, the deletedRange: $deletedRange is not within the bounds of $newText of length: ${newText.length}'); + newText = _replace(newText, '', deletedRange); + assert(_debugTextRangeIsValid(selection, newText), 'Applying TextEditingDeltaDeletion failed, the selection range: $selection is not within the bounds of $newText of length: ${newText.length}'); + assert(_debugTextRangeIsValid(composing, newText), 'Applying TextEditingDeltaDeletion failed, the composing range: $composing is not within the bounds of $newText of length: ${newText.length}'); + return value.copyWith(text: newText, selection: selection, composing: composing); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('oldText', oldText)); + properties.add(DiagnosticsProperty<String>('textDeleted', textDeleted)); + properties.add(DiagnosticsProperty<TextRange>('deletedRange', deletedRange)); + properties.add(DiagnosticsProperty<TextSelection>('selection', selection)); + properties.add(DiagnosticsProperty<TextRange>('composing', composing)); + } +} + +/// A structure representing a replacement of a range of characters with a +/// new sequence of text. +@immutable +class TextEditingDeltaReplacement extends TextEditingDelta { + /// Creates a replacement delta for a given change to the editing state. + /// + /// The range that is being replaced can either grow or shrink based on the + /// given replacement text. + /// + /// A replacement can occur in cases such as auto-correct, suggestions, and + /// when a selection is replaced by a single character. + /// + /// {@macro flutter.services.TextEditingDelta.optIn} + const TextEditingDeltaReplacement({ + required super.oldText, + required this.replacementText, + required this.replacedRange, + required super.selection, + required super.composing, + }); + + /// The new text that is replacing [replacedRange] in [oldText]. + final String replacementText; + + /// The range in [oldText] that is being replaced. + final TextRange replacedRange; + + /// The original text that is being replaced in [oldText]. + String get textReplaced => oldText.substring(replacedRange.start, replacedRange.end); + + @override + TextEditingValue apply(TextEditingValue value) { + // To stay inline with the plain text model we should follow a last write wins + // policy and apply the delta to the oldText. This is due to the asynchronous + // nature of the connection between the framework and platform text input plugins. + String newText = oldText; + assert(_debugTextRangeIsValid(replacedRange, newText), 'Applying TextEditingDeltaReplacement failed, the replacedRange: $replacedRange is not within the bounds of $newText of length: ${newText.length}'); + newText = _replace(newText, replacementText, replacedRange); + assert(_debugTextRangeIsValid(selection, newText), 'Applying TextEditingDeltaReplacement failed, the selection range: $selection is not within the bounds of $newText of length: ${newText.length}'); + assert(_debugTextRangeIsValid(composing, newText), 'Applying TextEditingDeltaReplacement failed, the composing range: $composing is not within the bounds of $newText of length: ${newText.length}'); + return value.copyWith(text: newText, selection: selection, composing: composing); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('oldText', oldText)); + properties.add(DiagnosticsProperty<String>('textReplaced', textReplaced)); + properties.add(DiagnosticsProperty<String>('replacementText', replacementText)); + properties.add(DiagnosticsProperty<TextRange>('replacedRange', replacedRange)); + properties.add(DiagnosticsProperty<TextSelection>('selection', selection)); + properties.add(DiagnosticsProperty<TextRange>('composing', composing)); + } +} + +/// A structure representing changes to the selection and/or composing regions +/// of an editing state and no changes to the text value. +@immutable +class TextEditingDeltaNonTextUpdate extends TextEditingDelta { + /// Creates a delta representing no updates to the text value of the current + /// editing state. This delta includes updates to the selection and/or composing + /// regions. + /// + /// A situation where this delta would be created is when dragging the selection + /// handles. There are no changes to the text, but there are updates to the selection + /// and potentially the composing region as well. + /// + /// {@macro flutter.services.TextEditingDelta.optIn} + const TextEditingDeltaNonTextUpdate({ + required super.oldText, + required super.selection, + required super.composing, + }); + + @override + TextEditingValue apply(TextEditingValue value) { + // To stay inline with the plain text model we should follow a last write wins + // policy and apply the delta to the oldText. This is due to the asynchronous + // nature of the connection between the framework and platform text input plugins. + assert(_debugTextRangeIsValid(selection, oldText), 'Applying TextEditingDeltaNonTextUpdate failed, the selection range: $selection is not within the bounds of $oldText of length: ${oldText.length}'); + assert(_debugTextRangeIsValid(composing, oldText), 'Applying TextEditingDeltaNonTextUpdate failed, the composing region: $composing is not within the bounds of $oldText of length: ${oldText.length}'); + return TextEditingValue(text: oldText, selection: selection, composing: composing); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('oldText', oldText)); + properties.add(DiagnosticsProperty<TextSelection>('selection', selection)); + properties.add(DiagnosticsProperty<TextRange>('composing', composing)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_formatter.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_formatter.dart new file mode 100644 index 0000000000000000000000000000000000000000..af0bf80147fb2416ae1a553651a224e243dc1c46 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_formatter.dart @@ -0,0 +1,620 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'dart:math' as math; + +import 'package:characters/characters.dart'; +import 'package:flutter/foundation.dart'; + +import 'text_input.dart'; + +export 'package:flutter/foundation.dart' show TargetPlatform; + +export 'text_input.dart' show TextEditingValue; + +// Examples can assume: +// late RegExp _pattern; + +/// Mechanisms for enforcing maximum length limits. +/// +/// This is used by [TextField] to specify how the [TextField.maxLength] should +/// be applied. +/// +/// {@template flutter.services.textFormatter.maxLengthEnforcement} +/// ### [MaxLengthEnforcement.enforced] versus +/// [MaxLengthEnforcement.truncateAfterCompositionEnds] +/// +/// Both [MaxLengthEnforcement.enforced] and +/// [MaxLengthEnforcement.truncateAfterCompositionEnds] make sure the final +/// length of the text does not exceed the max length specified. The difference +/// is that [MaxLengthEnforcement.enforced] truncates all text while +/// [MaxLengthEnforcement.truncateAfterCompositionEnds] allows composing text to +/// exceed the limit. Allowing this "placeholder" composing text to exceed the +/// limit may provide a better user experience on some platforms for entering +/// ideographic characters (e.g. CJK characters) via composing on phonetic +/// keyboards. +/// +/// Some input methods (Gboard on Android for example) initiate text composition +/// even for Latin characters, in which case the best experience may be to +/// truncate those composing characters with [MaxLengthEnforcement.enforced]. +/// +/// In fields that strictly support only a small subset of characters, such as +/// verification code fields, [MaxLengthEnforcement.enforced] may provide the +/// best experience. +/// {@endtemplate} +/// +/// See also: +/// +/// * [TextField.maxLengthEnforcement] which is used in conjunction with +/// [TextField.maxLength] to limit the length of user input. [TextField] also +/// provides a character counter to provide visual feedback. +enum MaxLengthEnforcement { + /// No enforcement applied to the editing value. It's possible to exceed the + /// max length. + none, + + /// Keep the length of the text input from exceeding the max length even when + /// the text has an unfinished composing region. + enforced, + + /// Users can still input text if the current value is composing even after + /// reaching the max length limit. After composing ends, the value will be + /// truncated. + truncateAfterCompositionEnds, +} + +/// A [TextInputFormatter] can be optionally injected into an [EditableText] +/// to provide as-you-type validation and formatting of the text being edited. +/// +/// Text modification should only be applied when text is being committed by the +/// IME and not on text under composition (i.e., only when +/// [TextEditingValue.composing] is collapsed). +/// +/// See also the [FilteringTextInputFormatter], a subclass that +/// removes characters that the user tries to enter if they do, or do +/// not, match a given pattern (as applicable). +/// +/// To create custom formatters, extend the [TextInputFormatter] class and +/// implement the [formatEditUpdate] method. +/// +/// ## Handling emojis and other complex characters +/// {@macro flutter.widgets.EditableText.onChanged} +/// +/// See also: +/// +/// * [EditableText] on which the formatting apply. +/// * [FilteringTextInputFormatter], a provided formatter for filtering +/// characters. +abstract class TextInputFormatter { + /// This constructor enables subclasses to provide const constructors so that they can be used in const expressions. + const TextInputFormatter(); + + /// Called when text is being typed or cut/copy/pasted in the [EditableText]. + /// + /// You can override the resulting text based on the previous text value and + /// the incoming new text value. + /// + /// When formatters are chained, `oldValue` reflects the initial value of + /// [TextEditingValue] at the beginning of the chain. + TextEditingValue formatEditUpdate( + TextEditingValue oldValue, + TextEditingValue newValue, + ); + + /// A shorthand to creating a custom [TextInputFormatter] which formats + /// incoming text input changes with the given function. + static TextInputFormatter withFunction( + TextInputFormatFunction formatFunction, + ) { + return _SimpleTextInputFormatter(formatFunction); + } +} + +/// Function signature expected for creating custom [TextInputFormatter] +/// shorthands via [TextInputFormatter.withFunction]. +typedef TextInputFormatFunction = TextEditingValue Function( + TextEditingValue oldValue, + TextEditingValue newValue, +); + +/// Wiring for [TextInputFormatter.withFunction]. +class _SimpleTextInputFormatter extends TextInputFormatter { + _SimpleTextInputFormatter(this.formatFunction); + + final TextInputFormatFunction formatFunction; + + @override + TextEditingValue formatEditUpdate( + TextEditingValue oldValue, + TextEditingValue newValue, + ) { + return formatFunction(oldValue, newValue); + } +} + +// A mutable, half-open range [`base`, `extent`) within a string. +class _MutableTextRange { + _MutableTextRange(this.base, this.extent); + + static _MutableTextRange? fromComposingRange(TextRange range) { + return range.isValid && !range.isCollapsed + ? _MutableTextRange(range.start, range.end) + : null; + } + + static _MutableTextRange? fromTextSelection(TextSelection selection) { + return selection.isValid + ? _MutableTextRange(selection.baseOffset, selection.extentOffset) + : null; + } + + /// The start index of the range, inclusive. + /// + /// The value of [base] should always be greater than or equal to 0, and can + /// be larger than, smaller than, or equal to [extent]. + int base; + + /// The end index of the range, exclusive. + /// + /// The value of [extent] should always be greater than or equal to 0, and can + /// be larger than, smaller than, or equal to [base]. + int extent; +} + +// The intermediate state of a [FilteringTextInputFormatter] when it's +// formatting a new user input. +class _TextEditingValueAccumulator { + _TextEditingValueAccumulator(this.inputValue) + : selection = _MutableTextRange.fromTextSelection(inputValue.selection), + composingRegion = _MutableTextRange.fromComposingRange(inputValue.composing); + + // The original string that was sent to the [FilteringTextInputFormatter] as + // input. + final TextEditingValue inputValue; + + /// The [StringBuffer] that contains the string which has already been + /// formatted. + /// + /// In a [FilteringTextInputFormatter], typically the replacement string, + /// instead of the original string within the given range, is written to this + /// [StringBuffer]. + final StringBuffer stringBuffer = StringBuffer(); + + /// The updated selection, as well as the original selection from the input + /// [TextEditingValue] of the [FilteringTextInputFormatter]. + /// + /// This parameter will be null if the input [TextEditingValue.selection] is + /// invalid. + final _MutableTextRange? selection; + + /// The updated composing region, as well as the original composing region + /// from the input [TextEditingValue] of the [FilteringTextInputFormatter]. + /// + /// This parameter will be null if the input [TextEditingValue.composing] is + /// invalid or collapsed. + final _MutableTextRange? composingRegion; + + // Whether this state object has reached its end-of-life. + bool debugFinalized = false; + + TextEditingValue finalize() { + debugFinalized = true; + final _MutableTextRange? selection = this.selection; + final _MutableTextRange? composingRegion = this.composingRegion; + return TextEditingValue( + text: stringBuffer.toString(), + composing: composingRegion == null || composingRegion.base == composingRegion.extent + ? TextRange.empty + : TextRange(start: composingRegion.base, end: composingRegion.extent), + selection: selection == null + ? const TextSelection.collapsed(offset: -1) + : TextSelection( + baseOffset: selection.base, + extentOffset: selection.extent, + // Try to preserve the selection affinity and isDirectional. This + // may not make sense if the selection has changed. + affinity: inputValue.selection.affinity, + isDirectional: inputValue.selection.isDirectional, + ), + ); + } +} + +/// A [TextInputFormatter] that prevents the insertion of characters matching +/// (or not matching) a particular pattern, by replacing the characters with the +/// given [replacementString]. +/// +/// Instances of filtered characters found in the new [TextEditingValue]s +/// will be replaced by the [replacementString] which defaults to the empty +/// string, and the current [TextEditingValue.selection] and +/// [TextEditingValue.composing] region will be adjusted to account for the +/// replacement. +/// +/// This formatter is typically used to match potentially recurring [Pattern]s +/// in the new [TextEditingValue]. It never completely rejects the new +/// [TextEditingValue] and falls back to the current [TextEditingValue] when the +/// given [filterPattern] fails to match. Consider using a different +/// [TextInputFormatter] such as: +/// +/// ```dart +/// // _pattern is a RegExp or other Pattern object +/// TextInputFormatter.withFunction( +/// (TextEditingValue oldValue, TextEditingValue newValue) { +/// return _pattern.hasMatch(newValue.text) ? newValue : oldValue; +/// }, +/// ), +/// ``` +/// +/// for accepting/rejecting new input based on a predicate on the full string. +/// As an example, [FilteringTextInputFormatter] typically shouldn't be used +/// with [RegExp]s that contain positional matchers (`^` or `$`) since these +/// patterns are usually meant for matching the whole string. +/// +/// ### Quote characters on iOS +/// +/// When filtering single (`'`) or double (`"`) quote characters, be aware that +/// the default iOS keyboard actually inserts special directional versions of +/// these characters (`‘` and `’` for single quote, and `“` and `”` for double +/// quote). Consider including all three variants in your regular expressions to +/// support iOS. +class FilteringTextInputFormatter extends TextInputFormatter { + /// Creates a formatter that replaces banned patterns with the given + /// [replacementString]. + /// + /// If [allow] is true, then the filter pattern is an allow list, + /// and characters must match the pattern to be accepted. See also + /// the [FilteringTextInputFormatter.allow()] constructor. + /// + /// If [allow] is false, then the filter pattern is a deny list, + /// and characters that match the pattern are rejected. See also + /// the [FilteringTextInputFormatter.deny] constructor. + FilteringTextInputFormatter( + this.filterPattern, { + required this.allow, + this.replacementString = '', + }); + + /// Creates a formatter that only allows characters matching a pattern. + FilteringTextInputFormatter.allow( + Pattern filterPattern, { + String replacementString = '', + }) : this(filterPattern, allow: true, replacementString: replacementString); + + /// Creates a formatter that blocks characters matching a pattern. + FilteringTextInputFormatter.deny( + Pattern filterPattern, { + String replacementString = '', + }) : this(filterPattern, allow: false, replacementString: replacementString); + + /// A [Pattern] to match or replace in incoming [TextEditingValue]s. + /// + /// The behavior of the pattern depends on the [allow] property. If + /// it is true, then this is an allow list, specifying a pattern that + /// characters must match to be accepted. Otherwise, it is a deny list, + /// specifying a pattern that characters must not match to be accepted. + /// + /// {@tool snippet} + /// Typically the pattern is a regular expression, as in: + /// + /// ```dart + /// FilteringTextInputFormatter onlyDigits = FilteringTextInputFormatter.allow(RegExp(r'[0-9]')); + /// ``` + /// {@end-tool} + /// + /// {@tool snippet} + /// If the pattern is a single character, a pattern consisting of a + /// [String] can be used: + /// + /// ```dart + /// FilteringTextInputFormatter noTabs = FilteringTextInputFormatter.deny('\t'); + /// ``` + /// {@end-tool} + final Pattern filterPattern; + + /// Whether the pattern is an allow list or not. + /// + /// When true, [filterPattern] denotes an allow list: characters + /// must match the filter to be allowed. + /// + /// When false, [filterPattern] denotes a deny list: characters + /// that match the filter are disallowed. + final bool allow; + + /// String used to replace banned patterns. + /// + /// For deny lists ([allow] is false), each match of the + /// [filterPattern] is replaced with this string. If [filterPattern] + /// can match more than one character at a time, then this can + /// result in multiple characters being replaced by a single + /// instance of this [replacementString]. + /// + /// For allow lists ([allow] is true), sequences between matches of + /// [filterPattern] are replaced as one, regardless of the number of + /// characters. + /// + /// For example, consider a [filterPattern] consisting of just the + /// letter "o", applied to text field whose initial value is the + /// string "Into The Woods", with the [replacementString] set to + /// `*`. + /// + /// If [allow] is true, then the result will be "*o*oo*". Each + /// sequence of characters not matching the pattern is replaced by + /// its own single copy of the replacement string, regardless of how + /// many characters are in that sequence. + /// + /// If [allow] is false, then the result will be "Int* the W**ds". + /// Every matching sequence is replaced, and each "o" matches the + /// pattern separately. + /// + /// If the pattern was the [RegExp] `o+`, the result would be the + /// same in the case where [allow] is true, but in the case where + /// [allow] is false, the result would be "Int* the W*ds" (with the + /// two "o"s replaced by a single occurrence of the replacement + /// string) because both of the "o"s would be matched simultaneously + /// by the pattern. + /// + /// The filter may adjust the selection and the composing region of the text + /// after applying the text replacement, such that they still cover the same + /// text. For instance, if the pattern was `o+` and the last character "s" was + /// selected: "Into The Wood|s|", then the result will be "Into The W*d|s|", + /// with the selection still around the same character "s" despite that it is + /// now the 12th character. + /// + /// In the case where one end point of the selection (or the composing region) + /// is strictly inside the banned pattern (for example, "Into The |Wo|ods"), + /// that endpoint will be moved to the end of the replacement string (it will + /// become "Into The |W*|ds" if the pattern was `o+` and the original text and + /// selection were "Into The |Wo|ods"). + final String replacementString; + + @override + TextEditingValue formatEditUpdate( + TextEditingValue oldValue, // unused. + TextEditingValue newValue, + ) { + final _TextEditingValueAccumulator formatState = _TextEditingValueAccumulator(newValue); + assert(!formatState.debugFinalized); + + final Iterable<Match> matches = filterPattern.allMatches(newValue.text); + Match? previousMatch; + for (final Match match in matches) { + assert(match.end >= match.start); + // Compute the non-match region between this `Match` and the previous + // `Match`. Depending on the value of `allow`, either the match region or + // the non-match region is the banned pattern. + // + // The non-matching region. + _processRegion(allow, previousMatch?.end ?? 0, match.start, formatState); + assert(!formatState.debugFinalized); + // The matched region. + _processRegion(!allow, match.start, match.end, formatState); + assert(!formatState.debugFinalized); + + previousMatch = match; + } + + // Handle the last non-matching region between the last match region and the + // end of the text. + _processRegion(allow, previousMatch?.end ?? 0, newValue.text.length, formatState); + assert(!formatState.debugFinalized); + return formatState.finalize(); + } + + void _processRegion(bool isBannedRegion, int regionStart, int regionEnd, _TextEditingValueAccumulator state) { + final String replacementString = isBannedRegion + ? (regionStart == regionEnd ? '' : this.replacementString) + : state.inputValue.text.substring(regionStart, regionEnd); + + state.stringBuffer.write(replacementString); + + if (replacementString.length == regionEnd - regionStart) { + // We don't have to adjust the indices if the replaced string and the + // replacement string have the same length. + return; + } + + int adjustIndex(int originalIndex) { + // The length added by adding the replacementString. + final int replacedLength = originalIndex <= regionStart && originalIndex < regionEnd ? 0 : replacementString.length; + // The length removed by removing the replacementRange. + final int removedLength = originalIndex.clamp(regionStart, regionEnd) - regionStart; + return replacedLength - removedLength; + } + + state.selection?.base += adjustIndex(state.inputValue.selection.baseOffset); + state.selection?.extent += adjustIndex(state.inputValue.selection.extentOffset); + state.composingRegion?.base += adjustIndex(state.inputValue.composing.start); + state.composingRegion?.extent += adjustIndex(state.inputValue.composing.end); + } + + /// A [TextInputFormatter] that forces input to be a single line. + static final TextInputFormatter singleLineFormatter = FilteringTextInputFormatter.deny('\n'); + + /// A [TextInputFormatter] that takes in digits `[0-9]` only. + static final TextInputFormatter digitsOnly = FilteringTextInputFormatter.allow(RegExp(r'[0-9]')); +} + +/// A [TextInputFormatter] that prevents the insertion of more characters +/// than allowed. +/// +/// Since this formatter only prevents new characters from being added to the +/// text, it preserves the existing [TextEditingValue.selection]. +/// +/// Characters are counted as user-perceived characters using the +/// [characters](https://pub.dev/packages/characters) package, so even complex +/// characters like extended grapheme clusters and surrogate pairs are counted +/// as single characters. +/// +/// See also: +/// * [maxLength], which discusses the precise meaning of "number of +/// characters". +class LengthLimitingTextInputFormatter extends TextInputFormatter { + /// Creates a formatter that prevents the insertion of more characters than a + /// limit. + /// + /// The [maxLength] must be null, -1 or greater than zero. If it is null or -1 + /// then no limit is enforced. + LengthLimitingTextInputFormatter( + this.maxLength, { + this.maxLengthEnforcement, + }) : assert(maxLength == null || maxLength == -1 || maxLength > 0); + + /// The limit on the number of user-perceived characters that this formatter + /// will allow. + /// + /// The value must be null or greater than zero. If it is null or -1, then no + /// limit is enforced. + /// + /// {@template flutter.services.lengthLimitingTextInputFormatter.maxLength} + /// ## Characters + /// + /// For a specific definition of what is considered a character, see the + /// [characters](https://pub.dev/packages/characters) package on Pub, which is + /// what Flutter uses to delineate characters. In general, even complex + /// characters like surrogate pairs and extended grapheme clusters are + /// correctly interpreted by Flutter as each being a single user-perceived + /// character. + /// + /// For instance, the character "ö" can be represented as '\u{006F}\u{0308}', + /// which is the letter "o" followed by a composed diaeresis "¨", or it can + /// be represented as '\u{00F6}', which is the Unicode scalar value "LATIN + /// SMALL LETTER O WITH DIAERESIS". It will be counted as a single character + /// in both cases. + /// + /// Similarly, some emoji are represented by multiple scalar values. The + /// Unicode "THUMBS UP SIGN + MEDIUM SKIN TONE MODIFIER", "👍🏽"is counted as + /// a single character, even though it is a combination of two Unicode scalar + /// values, '\u{1F44D}\u{1F3FD}'. + /// {@endtemplate} + /// + /// ### Composing text behaviors + /// + /// There is no guarantee for the final value before the composing ends. + /// So while the value is composing, the constraint of [maxLength] will be + /// temporary lifted until the composing ends. + /// + /// In addition, if the current value already reached the [maxLength], + /// composing is not allowed. + final int? maxLength; + + /// Determines how the [maxLength] limit should be enforced. + /// + /// Defaults to [MaxLengthEnforcement.enforced]. + /// + /// {@macro flutter.services.textFormatter.maxLengthEnforcement} + final MaxLengthEnforcement? maxLengthEnforcement; + + /// Returns a [MaxLengthEnforcement] that follows the specified [platform]'s + /// convention. + /// + /// {@template flutter.services.textFormatter.effectiveMaxLengthEnforcement} + /// ### Platform specific behaviors + /// + /// Different platforms follow different behaviors by default, according to + /// their native behavior. + /// * Android, Windows: [MaxLengthEnforcement.enforced]. The native behavior + /// of these platforms is enforced. The composing will be handled by the + /// IME while users are entering CJK characters. + /// * iOS: [MaxLengthEnforcement.truncateAfterCompositionEnds]. iOS has no + /// default behavior and it requires users implement the behavior + /// themselves. Allow the composition to exceed to avoid breaking CJK input. + /// * Web, macOS, linux, fuchsia: + /// [MaxLengthEnforcement.truncateAfterCompositionEnds]. These platforms + /// allow the composition to exceed by default. + /// {@endtemplate} + static MaxLengthEnforcement getDefaultMaxLengthEnforcement([ + TargetPlatform? platform, + ]) { + if (kIsWeb) { + return MaxLengthEnforcement.truncateAfterCompositionEnds; + } else { + switch (platform ?? defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.windows: + return MaxLengthEnforcement.enforced; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.fuchsia: + return MaxLengthEnforcement.truncateAfterCompositionEnds; + } + } + } + + /// Truncate the given TextEditingValue to maxLength user-perceived + /// characters. + /// + /// See also: + /// * [Dart's characters package](https://pub.dev/packages/characters). + /// * [Dart's documentation on runes and grapheme clusters](https://dart.dev/guides/language/language-tour#runes-and-grapheme-clusters). + @visibleForTesting + static TextEditingValue truncate(TextEditingValue value, int maxLength) { + final CharacterRange iterator = CharacterRange(value.text); + if (value.text.characters.length > maxLength) { + iterator.expandNext(maxLength); + } + final String truncated = iterator.current; + + return TextEditingValue( + text: truncated, + selection: value.selection.copyWith( + baseOffset: math.min(value.selection.start, truncated.length), + extentOffset: math.min(value.selection.end, truncated.length), + ), + composing: !value.composing.isCollapsed && truncated.length > value.composing.start + ? TextRange( + start: value.composing.start, + end: math.min(value.composing.end, truncated.length), + ) + : TextRange.empty, + ); + } + + @override + TextEditingValue formatEditUpdate( + TextEditingValue oldValue, + TextEditingValue newValue, + ) { + final int? maxLength = this.maxLength; + + if (maxLength == null || + maxLength == -1 || + newValue.text.characters.length <= maxLength) { + return newValue; + } + + assert(maxLength > 0); + + switch (maxLengthEnforcement ?? getDefaultMaxLengthEnforcement()) { + case MaxLengthEnforcement.none: + return newValue; + case MaxLengthEnforcement.enforced: + // If already at the maximum and tried to enter even more, and has no + // selection, keep the old value. + if (oldValue.text.characters.length == maxLength && oldValue.selection.isCollapsed) { + return oldValue; + } + + // Enforced to return a truncated value. + return truncate(newValue, maxLength); + case MaxLengthEnforcement.truncateAfterCompositionEnds: + // If already at the maximum and tried to enter even more, and the old + // value is not composing, keep the old value. + if (oldValue.text.characters.length == maxLength && + !oldValue.composing.isValid) { + return oldValue; + } + + // Temporarily exempt `newValue` from the maxLength limit if it has a + // composing text going and no enforcement to the composing value, until + // the composing is finished. + if (newValue.composing.isValid) { + return newValue; + } + + return truncate(newValue, maxLength); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_input.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_input.dart new file mode 100644 index 0000000000000000000000000000000000000000..27712c7ad28a90a8301fe82eb57024eecd785e32 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_input.dart @@ -0,0 +1,2378 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:io' show Platform; +import 'dart:ui' show + FontWeight, + Offset, + Rect, + Size, + TextAlign, + TextDirection; + +import 'package:flutter/foundation.dart'; +import 'package:vector_math/vector_math_64.dart' show Matrix4; + +import 'autofill.dart'; +import 'clipboard.dart' show Clipboard; +import 'keyboard_inserted_content.dart'; +import 'message_codec.dart'; +import 'platform_channel.dart'; +import 'system_channels.dart'; +import 'text_editing.dart'; +import 'text_editing_delta.dart'; + +export 'dart:ui' show Brightness, FontWeight, Offset, Rect, Size, TextAlign, TextDirection, TextPosition, TextRange; + +export 'package:vector_math/vector_math_64.dart' show Matrix4; + +export 'autofill.dart' show AutofillConfiguration, AutofillScope; +export 'text_editing.dart' show TextSelection; +// TODO(a14n): the following export leads to Segmentation fault, see https://github.com/flutter/flutter/issues/106332 +// export 'text_editing_delta.dart' show TextEditingDelta; + +/// Indicates how to handle the intelligent replacement of dashes in text input. +/// +/// See also: +/// +/// * [TextField.smartDashesType] +/// * [CupertinoTextField.smartDashesType] +/// * [EditableText.smartDashesType] +/// * [SmartQuotesType] +/// * <https://developer.apple.com/documentation/uikit/uitextinputtraits> +enum SmartDashesType { + /// Smart dashes is disabled. + /// + /// This corresponds to the + /// ["no" value of UITextSmartDashesType](https://developer.apple.com/documentation/uikit/uitextsmartdashestype/no). + disabled, + + /// Smart dashes is enabled. + /// + /// This corresponds to the + /// ["yes" value of UITextSmartDashesType](https://developer.apple.com/documentation/uikit/uitextsmartdashestype/yes). + enabled, +} + +/// Indicates how to handle the intelligent replacement of quotes in text input. +/// +/// See also: +/// +/// * [TextField.smartQuotesType] +/// * [CupertinoTextField.smartQuotesType] +/// * [EditableText.smartQuotesType] +/// * <https://developer.apple.com/documentation/uikit/uitextinputtraits> +enum SmartQuotesType { + /// Smart quotes is disabled. + /// + /// This corresponds to the + /// ["no" value of UITextSmartQuotesType](https://developer.apple.com/documentation/uikit/uitextsmartquotestype/no). + disabled, + + /// Smart quotes is enabled. + /// + /// This corresponds to the + /// ["yes" value of UITextSmartQuotesType](https://developer.apple.com/documentation/uikit/uitextsmartquotestype/yes). + enabled, +} + +/// The type of information for which to optimize the text input control. +/// +/// On Android, behavior may vary across device and keyboard provider. +/// +/// This class stays as close to `Enum` interface as possible, and allows +/// for additional flags for some input types. For example, numeric input +/// can specify whether it supports decimal numbers and/or signed numbers. +@immutable +class TextInputType { + const TextInputType._(this.index) + : signed = null, + decimal = null; + + /// Optimize for numerical information. + /// + /// Requests a numeric keyboard with additional settings. + /// The [signed] and [decimal] parameters are optional. + const TextInputType.numberWithOptions({ + this.signed = false, + this.decimal = false, + }) : index = 2; + + /// Enum value index, corresponds to one of the [values]. + final int index; + + /// The number is signed, allowing a positive or negative sign at the start. + /// + /// This flag is only used for the [number] input type, otherwise `null`. + /// Use `const TextInputType.numberWithOptions(signed: true)` to set this. + final bool? signed; + + /// The number is decimal, allowing a decimal point to provide fractional. + /// + /// This flag is only used for the [number] input type, otherwise `null`. + /// Use `const TextInputType.numberWithOptions(decimal: true)` to set this. + final bool? decimal; + + /// Optimize for textual information. + /// + /// Requests the default platform keyboard. + static const TextInputType text = TextInputType._(0); + + /// Optimize for multiline textual information. + /// + /// Requests the default platform keyboard, but accepts newlines when the + /// enter key is pressed. This is the input type used for all multiline text + /// fields. + static const TextInputType multiline = TextInputType._(1); + + /// Optimize for unsigned numerical information without a decimal point. + /// + /// Requests a default keyboard with ready access to the number keys. + /// Additional options, such as decimal point and/or positive/negative + /// signs, can be requested using [TextInputType.numberWithOptions]. + static const TextInputType number = TextInputType.numberWithOptions(); + + /// Optimize for telephone numbers. + /// + /// Requests a keyboard with ready access to the number keys, "*", and "#". + static const TextInputType phone = TextInputType._(3); + + /// Optimize for date and time information. + /// + /// On iOS, requests the default keyboard. + /// + /// On Android, requests a keyboard with ready access to the number keys, + /// ":", and "-". + static const TextInputType datetime = TextInputType._(4); + + /// Optimize for email addresses. + /// + /// Requests a keyboard with ready access to the "@" and "." keys. + static const TextInputType emailAddress = TextInputType._(5); + + /// Optimize for URLs. + /// + /// Requests a keyboard with ready access to the "/" and "." keys. + static const TextInputType url = TextInputType._(6); + + /// Optimize for passwords that are visible to the user. + /// + /// Requests a keyboard with ready access to both letters and numbers. + static const TextInputType visiblePassword = TextInputType._(7); + + /// Optimized for a person's name. + /// + /// On iOS, requests the + /// [UIKeyboardType.namePhonePad](https://developer.apple.com/documentation/uikit/uikeyboardtype/namephonepad) + /// keyboard, a keyboard optimized for entering a person’s name or phone number. + /// Does not support auto-capitalization. + /// + /// On Android, requests a keyboard optimized for + /// [TYPE_TEXT_VARIATION_PERSON_NAME](https://developer.android.com/reference/android/text/InputType#TYPE_TEXT_VARIATION_PERSON_NAME). + static const TextInputType name = TextInputType._(8); + + /// Optimized for postal mailing addresses. + /// + /// On iOS, requests the default keyboard. + /// + /// On Android, requests a keyboard optimized for + /// [TYPE_TEXT_VARIATION_POSTAL_ADDRESS](https://developer.android.com/reference/android/text/InputType#TYPE_TEXT_VARIATION_POSTAL_ADDRESS). + static const TextInputType streetAddress = TextInputType._(9); + + /// Prevent the OS from showing the on-screen virtual keyboard. + static const TextInputType none = TextInputType._(10); + + /// All possible enum values. + static const List<TextInputType> values = <TextInputType>[ + text, multiline, number, phone, datetime, emailAddress, url, visiblePassword, name, streetAddress, none, + ]; + + // Corresponding string name for each of the [values]. + static const List<String> _names = <String>[ + 'text', 'multiline', 'number', 'phone', 'datetime', 'emailAddress', 'url', 'visiblePassword', 'name', 'address', 'none', + ]; + + // Enum value name, this is what enum.toString() would normally return. + String get _name => 'TextInputType.${_names[index]}'; + + /// Returns a representation of this object as a JSON object. + Map<String, dynamic> toJson() { + return <String, dynamic>{ + 'name': _name, + 'signed': signed, + 'decimal': decimal, + }; + } + + @override + String toString() { + return '${objectRuntimeType(this, 'TextInputType')}(' + 'name: $_name, ' + 'signed: $signed, ' + 'decimal: $decimal)'; + } + + @override + bool operator ==(Object other) { + return other is TextInputType + && other.index == index + && other.signed == signed + && other.decimal == decimal; + } + + @override + int get hashCode => Object.hash(index, signed, decimal); +} + +/// An action the user has requested the text input control to perform. +/// +/// Each action represents a logical meaning, and also configures the soft +/// keyboard to display a certain kind of action button. The visual appearance +/// of the action button might differ between versions of the same OS. +/// +/// Despite the logical meaning of each action, choosing a particular +/// [TextInputAction] does not necessarily cause any specific behavior to +/// happen, other than changing the focus when appropriate. It is up to the +/// developer to ensure that the behavior that occurs when an action button is +/// pressed is appropriate for the action button chosen. +/// +/// For example: If the user presses the keyboard action button on iOS when it +/// reads "Emergency Call", the result should not be a focus change to the next +/// TextField. This behavior is not logically appropriate for a button that says +/// "Emergency Call". +/// +/// See [EditableText] for more information about customizing action button +/// behavior. +/// +/// Most [TextInputAction]s are supported equally by both Android and iOS. +/// However, there is not a complete, direct mapping between Android's IME input +/// types and iOS's keyboard return types. Therefore, some [TextInputAction]s +/// are inappropriate for one of the platforms. If a developer chooses an +/// inappropriate [TextInputAction] when running in debug mode, an error will be +/// thrown. If the same thing is done in release mode, then instead of sending +/// the inappropriate value, Android will use "unspecified" on the platform +/// side and iOS will use "default" on the platform side. +/// +/// See also: +/// +/// * [TextInput], which configures the platform's keyboard setup. +/// * [EditableText], which invokes callbacks when the action button is pressed. +// +// This class has been cloned to `flutter_driver/lib/src/common/action.dart` as `TextInputAction`, +// and must be kept in sync. +enum TextInputAction { + /// Logical meaning: There is no relevant input action for the current input + /// source, e.g., [TextField]. + /// + /// Android: Corresponds to Android's "IME_ACTION_NONE". The keyboard setup + /// is decided by the OS. The keyboard will likely show a return key. + /// + /// iOS: iOS does not have a keyboard return type of "none." It is + /// inappropriate to choose this [TextInputAction] when running on iOS. + none, + + /// Logical meaning: Let the OS decide which action is most appropriate. + /// + /// Android: Corresponds to Android's "IME_ACTION_UNSPECIFIED". The OS chooses + /// which keyboard action to display. The decision will likely be a done + /// button or a return key. + /// + /// iOS: Corresponds to iOS's "UIReturnKeyDefault". The title displayed in + /// the action button is "return". + unspecified, + + /// Logical meaning: The user is done providing input to a group of inputs + /// (like a form). Some kind of finalization behavior should now take place. + /// + /// Android: Corresponds to Android's "IME_ACTION_DONE". The OS displays a + /// button that represents completion, e.g., a checkmark button. + /// + /// iOS: Corresponds to iOS's "UIReturnKeyDone". The title displayed in the + /// action button is "Done". + done, + + /// Logical meaning: The user has entered some text that represents a + /// destination, e.g., a restaurant name. The "go" button is intended to take + /// the user to a part of the app that corresponds to this destination. + /// + /// Android: Corresponds to Android's "IME_ACTION_GO". The OS displays a + /// button that represents taking "the user to the target of the text they + /// typed", e.g., a right-facing arrow button. + /// + /// iOS: Corresponds to iOS's "UIReturnKeyGo". The title displayed in the + /// action button is "Go". + go, + + /// Logical meaning: Execute a search query. + /// + /// Android: Corresponds to Android's "IME_ACTION_SEARCH". The OS displays a + /// button that represents a search, e.g., a magnifying glass button. + /// + /// iOS: Corresponds to iOS's "UIReturnKeySearch". The title displayed in the + /// action button is "Search". + search, + + /// Logical meaning: Sends something that the user has composed, e.g., an + /// email or a text message. + /// + /// Android: Corresponds to Android's "IME_ACTION_SEND". The OS displays a + /// button that represents sending something, e.g., a paper plane button. + /// + /// iOS: Corresponds to iOS's "UIReturnKeySend". The title displayed in the + /// action button is "Send". + send, + + /// Logical meaning: The user is done with the current input source and wants + /// to move to the next one. + /// + /// Moves the focus to the next focusable item in the same [FocusScope]. + /// + /// Android: Corresponds to Android's "IME_ACTION_NEXT". The OS displays a + /// button that represents moving forward, e.g., a right-facing arrow button. + /// + /// iOS: Corresponds to iOS's "UIReturnKeyNext". The title displayed in the + /// action button is "Next". + next, + + /// Logical meaning: The user wishes to return to the previous input source + /// in the group, e.g., a form with multiple [TextField]s. + /// + /// Moves the focus to the previous focusable item in the same [FocusScope]. + /// + /// Android: Corresponds to Android's "IME_ACTION_PREVIOUS". The OS displays a + /// button that represents moving backward, e.g., a left-facing arrow button. + /// + /// iOS: iOS does not have a keyboard return type of "previous." It is + /// inappropriate to choose this [TextInputAction] when running on iOS. + previous, + + /// Logical meaning: In iOS apps, it is common for a "Back" button and + /// "Continue" button to appear at the top of the screen. However, when the + /// keyboard is open, these buttons are often hidden off-screen. Therefore, + /// the purpose of the "Continue" return key on iOS is to make the "Continue" + /// button available when the user is entering text. + /// + /// Historical context aside, [TextInputAction.continueAction] can be used any + /// time that the term "Continue" seems most appropriate for the given action. + /// + /// Android: Android does not have an IME input type of "continue." It is + /// inappropriate to choose this [TextInputAction] when running on Android. + /// + /// iOS: Corresponds to iOS's "UIReturnKeyContinue". The title displayed in the + /// action button is "Continue". This action is only available on iOS 9.0+. + /// + /// The reason that this value has "Action" post-fixed to it is because + /// "continue" is a reserved word in Dart, as well as many other languages. + continueAction, + + /// Logical meaning: The user wants to join something, e.g., a wireless + /// network. + /// + /// Android: Android does not have an IME input type of "join." It is + /// inappropriate to choose this [TextInputAction] when running on Android. + /// + /// iOS: Corresponds to iOS's "UIReturnKeyJoin". The title displayed in the + /// action button is "Join". + join, + + /// Logical meaning: The user wants routing options, e.g., driving directions. + /// + /// Android: Android does not have an IME input type of "route." It is + /// inappropriate to choose this [TextInputAction] when running on Android. + /// + /// iOS: Corresponds to iOS's "UIReturnKeyRoute". The title displayed in the + /// action button is "Route". + route, + + /// Logical meaning: Initiate a call to emergency services. + /// + /// Android: Android does not have an IME input type of "emergencyCall." It is + /// inappropriate to choose this [TextInputAction] when running on Android. + /// + /// iOS: Corresponds to iOS's "UIReturnKeyEmergencyCall". The title displayed + /// in the action button is "Emergency Call". + emergencyCall, + + /// Logical meaning: Insert a newline character in the focused text input, + /// e.g., [TextField]. + /// + /// Android: Corresponds to Android's "IME_ACTION_NONE". The OS displays a + /// button that represents a new line, e.g., a carriage return button. + /// + /// iOS: Corresponds to iOS's "UIReturnKeyDefault". The title displayed in the + /// action button is "return". + /// + /// The term [TextInputAction.newline] exists in Flutter but not in Android + /// or iOS. The reason for introducing this term is so that developers can + /// achieve the common result of inserting new lines without needing to + /// understand the various IME actions on Android and return keys on iOS. + /// Thus, [TextInputAction.newline] is a convenience term that alleviates the + /// need to understand the underlying platforms to achieve this common behavior. + newline, +} + +/// Configures how the platform keyboard will select an uppercase or +/// lowercase keyboard. +/// +/// Only supports text keyboards, other keyboard types will ignore this +/// configuration. Capitalization is locale-aware. +enum TextCapitalization { + /// Defaults to an uppercase keyboard for the first letter of each word. + /// + /// Corresponds to `InputType.TYPE_TEXT_FLAG_CAP_WORDS` on Android, and + /// `UITextAutocapitalizationTypeWords` on iOS. + words, + + /// Defaults to an uppercase keyboard for the first letter of each sentence. + /// + /// Corresponds to `InputType.TYPE_TEXT_FLAG_CAP_SENTENCES` on Android, and + /// `UITextAutocapitalizationTypeSentences` on iOS. + sentences, + + /// Defaults to an uppercase keyboard for each character. + /// + /// Corresponds to `InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS` on Android, and + /// `UITextAutocapitalizationTypeAllCharacters` on iOS. + characters, + + /// Defaults to a lowercase keyboard. + none, +} + +/// Controls the visual appearance of the text input control. +/// +/// Many [TextInputAction]s are common between Android and iOS. However, if an +/// [inputAction] is provided that is not supported by the current +/// platform in debug mode, an error will be thrown when the corresponding +/// text input is attached. For example, providing iOS's "emergencyCall" +/// action when running on an Android device will result in an error when in +/// debug mode. In release mode, incompatible [TextInputAction]s are replaced +/// either with "unspecified" on Android, or "default" on iOS. Appropriate +/// [inputAction]s can be chosen by checking the current platform and then +/// selecting the appropriate action. +/// +/// See also: +/// +/// * [TextInput.attach] +/// * [TextInputAction] +@immutable +class TextInputConfiguration { + /// Creates configuration information for a text input control. + /// + /// All arguments have default values, except [actionLabel]. Only + /// [actionLabel] may be null. + const TextInputConfiguration({ + this.inputType = TextInputType.text, + this.readOnly = false, + this.obscureText = false, + this.autocorrect = true, + SmartDashesType? smartDashesType, + SmartQuotesType? smartQuotesType, + this.enableSuggestions = true, + this.enableInteractiveSelection = true, + this.actionLabel, + this.inputAction = TextInputAction.done, + this.keyboardAppearance = Brightness.light, + this.textCapitalization = TextCapitalization.none, + this.autofillConfiguration = AutofillConfiguration.disabled, + this.enableIMEPersonalizedLearning = true, + this.allowedMimeTypes = const <String>[], + this.enableDeltaModel = false, + }) : smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), + smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled); + + /// The type of information for which to optimize the text input control. + final TextInputType inputType; + + /// Whether the text field can be edited or not. + /// + /// Defaults to false. + final bool readOnly; + + /// Whether to hide the text being edited (e.g., for passwords). + /// + /// Defaults to false. + final bool obscureText; + + /// Whether to enable autocorrection. + /// + /// Defaults to true. + final bool autocorrect; + + /// The configuration to use for autofill. + /// + /// Defaults to null, in which case no autofill information will be provided + /// to the platform. This will prevent the corresponding input field from + /// participating in autofills triggered by other fields. Additionally, on + /// Android and web, setting [autofillConfiguration] to null disables autofill. + final AutofillConfiguration autofillConfiguration; + + /// {@template flutter.services.TextInputConfiguration.smartDashesType} + /// Whether to allow the platform to automatically format dashes. + /// + /// This flag only affects iOS versions 11 and above. It sets + /// [`UITextSmartDashesType`](https://developer.apple.com/documentation/uikit/uitextsmartdashestype?language=objc) + /// in the engine. When true, it passes + /// [`UITextSmartDashesTypeYes`](https://developer.apple.com/documentation/uikit/uitextsmartdashestype/uitextsmartdashestypeyes?language=objc), + /// and when false, it passes + /// [`UITextSmartDashesTypeNo`](https://developer.apple.com/documentation/uikit/uitextsmartdashestype/uitextsmartdashestypeno?language=objc). + /// + /// As an example of what this does, two consecutive hyphen characters will be + /// automatically replaced with one en dash, and three consecutive hyphens + /// will become one em dash. + /// + /// Defaults to true, unless [obscureText] is true, when it defaults to false. + /// This is to avoid the problem where password fields receive autoformatted + /// characters. + /// + /// See also: + /// + /// * [smartQuotesType] + /// * <https://developer.apple.com/documentation/uikit/uitextinputtraits> + /// {@endtemplate} + final SmartDashesType smartDashesType; + + /// {@template flutter.services.TextInputConfiguration.smartQuotesType} + /// Whether to allow the platform to automatically format quotes. + /// + /// This flag only affects iOS. It sets + /// [`UITextSmartQuotesType`](https://developer.apple.com/documentation/uikit/uitextsmartquotestype?language=objc) + /// in the engine. When true, it passes + /// [`UITextSmartQuotesTypeYes`](https://developer.apple.com/documentation/uikit/uitextsmartquotestype/uitextsmartquotestypeyes?language=objc), + /// and when false, it passes + /// [`UITextSmartQuotesTypeNo`](https://developer.apple.com/documentation/uikit/uitextsmartquotestype/uitextsmartquotestypeno?language=objc). + /// + /// As an example of what this does, a standard vertical double quote + /// character will be automatically replaced by a left or right double quote + /// depending on its position in a word. + /// + /// Defaults to true, unless [obscureText] is true, when it defaults to false. + /// This is to avoid the problem where password fields receive autoformatted + /// characters. + /// + /// See also: + /// + /// * [smartDashesType] + /// * <https://developer.apple.com/documentation/uikit/uitextinputtraits> + /// {@endtemplate} + final SmartQuotesType smartQuotesType; + + /// {@template flutter.services.TextInputConfiguration.enableSuggestions} + /// Whether to show input suggestions as the user types. + /// + /// This flag only affects Android. On iOS, suggestions are tied directly to + /// [autocorrect], so that suggestions are only shown when [autocorrect] is + /// true. On Android autocorrection and suggestion are controlled separately. + /// + /// Defaults to true. + /// + /// See also: + /// + /// * <https://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_FLAG_NO_SUGGESTIONS> + /// {@endtemplate} + final bool enableSuggestions; + + /// Whether a user can change its selection. + /// + /// This flag only affects iOS VoiceOver. On Android Talkback, the selection + /// change is sent through semantics actions and is directly disabled from + /// the widget side. + /// + /// Defaults to true. + final bool enableInteractiveSelection; + + /// What text to display in the text input control's action button. + final String? actionLabel; + + /// What kind of action to request for the action button on the IME. + final TextInputAction inputAction; + + /// Specifies how platforms may automatically capitalize text entered by the + /// user. + /// + /// Defaults to [TextCapitalization.none]. + /// + /// See also: + /// + /// * [TextCapitalization], for a description of each capitalization behavior. + final TextCapitalization textCapitalization; + + /// The appearance of the keyboard. + /// + /// This setting is only honored on iOS devices. + /// + /// Defaults to [Brightness.light]. + final Brightness keyboardAppearance; + + /// {@template flutter.services.TextInputConfiguration.enableIMEPersonalizedLearning} + /// Whether to enable that the IME update personalized data such as typing + /// history and user dictionary data. + /// + /// This flag only affects Android. On iOS, there is no equivalent flag. + /// + /// Defaults to true. + /// + /// See also: + /// + /// * <https://developer.android.com/reference/android/view/inputmethod/EditorInfo#IME_FLAG_NO_PERSONALIZED_LEARNING> + /// {@endtemplate} + final bool enableIMEPersonalizedLearning; + + /// {@macro flutter.widgets.contentInsertionConfiguration.allowedMimeTypes} + final List<String> allowedMimeTypes; + + /// Creates a copy of this [TextInputConfiguration] with the given fields + /// replaced with new values. + TextInputConfiguration copyWith({ + TextInputType? inputType, + bool? readOnly, + bool? obscureText, + bool? autocorrect, + SmartDashesType? smartDashesType, + SmartQuotesType? smartQuotesType, + bool? enableSuggestions, + bool? enableInteractiveSelection, + String? actionLabel, + TextInputAction? inputAction, + Brightness? keyboardAppearance, + TextCapitalization? textCapitalization, + bool? enableIMEPersonalizedLearning, + List<String>? allowedMimeTypes, + AutofillConfiguration? autofillConfiguration, + bool? enableDeltaModel, + }) { + return TextInputConfiguration( + inputType: inputType ?? this.inputType, + readOnly: readOnly ?? this.readOnly, + obscureText: obscureText ?? this.obscureText, + autocorrect: autocorrect ?? this.autocorrect, + smartDashesType: smartDashesType ?? this.smartDashesType, + smartQuotesType: smartQuotesType ?? this.smartQuotesType, + enableSuggestions: enableSuggestions ?? this.enableSuggestions, + enableInteractiveSelection: enableInteractiveSelection ?? this.enableInteractiveSelection, + inputAction: inputAction ?? this.inputAction, + textCapitalization: textCapitalization ?? this.textCapitalization, + keyboardAppearance: keyboardAppearance ?? this.keyboardAppearance, + enableIMEPersonalizedLearning: enableIMEPersonalizedLearning?? this.enableIMEPersonalizedLearning, + allowedMimeTypes: allowedMimeTypes ?? this.allowedMimeTypes, + autofillConfiguration: autofillConfiguration ?? this.autofillConfiguration, + enableDeltaModel: enableDeltaModel ?? this.enableDeltaModel, + ); + } + + /// Whether to enable that the engine sends text input updates to the + /// framework as [TextEditingDelta]'s or as one [TextEditingValue]. + /// + /// Enabling this flag results in granular text updates being received from the + /// platform's text input control. + /// + /// When this is enabled: + /// * You must implement [DeltaTextInputClient] and not [TextInputClient] to + /// receive granular updates from the platform's text input. + /// * Platform text input updates will come through + /// [DeltaTextInputClient.updateEditingValueWithDeltas]. + /// * If [TextInputClient] is implemented with this property enabled then + /// you will experience unexpected behavior as [TextInputClient] does not implement + /// a delta channel. + /// + /// When this is disabled: + /// * If [DeltaTextInputClient] is implemented then updates for the + /// editing state will continue to come through the + /// [DeltaTextInputClient.updateEditingValue] channel. + /// * If [TextInputClient] is implemented then updates for the editing + /// state will come through [TextInputClient.updateEditingValue]. + /// + /// Defaults to false. + final bool enableDeltaModel; + + /// Returns a representation of this object as a JSON object. + Map<String, dynamic> toJson() { + final Map<String, dynamic>? autofill = autofillConfiguration.toJson(); + return <String, dynamic>{ + 'inputType': inputType.toJson(), + 'readOnly': readOnly, + 'obscureText': obscureText, + 'autocorrect': autocorrect, + 'smartDashesType': smartDashesType.index.toString(), + 'smartQuotesType': smartQuotesType.index.toString(), + 'enableSuggestions': enableSuggestions, + 'enableInteractiveSelection': enableInteractiveSelection, + 'actionLabel': actionLabel, + 'inputAction': inputAction.toString(), + 'textCapitalization': textCapitalization.toString(), + 'keyboardAppearance': keyboardAppearance.toString(), + 'enableIMEPersonalizedLearning': enableIMEPersonalizedLearning, + 'contentCommitMimeTypes': allowedMimeTypes, + if (autofill != null) 'autofill': autofill, + 'enableDeltaModel' : enableDeltaModel, + }; + } +} + +TextAffinity? _toTextAffinity(String? affinity) { + switch (affinity) { + case 'TextAffinity.downstream': + return TextAffinity.downstream; + case 'TextAffinity.upstream': + return TextAffinity.upstream; + } + return null; +} + +/// A floating cursor state the user has induced by force pressing an iOS +/// keyboard. +enum FloatingCursorDragState { + /// A user has just activated a floating cursor. + Start, + + /// A user is dragging a floating cursor. + Update, + + /// A user has lifted their finger off the screen after using a floating + /// cursor. + End, +} + +/// The current state and position of the floating cursor. +class RawFloatingCursorPoint { + /// Creates information for setting the position and state of a floating + /// cursor. + /// + /// [state] must not be null and [offset] must not be null if the state is + /// [FloatingCursorDragState.Update]. + RawFloatingCursorPoint({ + this.offset, + this.startLocation, + required this.state, + }) : assert(state != FloatingCursorDragState.Update || offset != null); + + /// The raw position of the floating cursor as determined by the iOS sdk. + final Offset? offset; + + /// Represents the starting location when initiating a floating cursor via long press. + /// This is a tuple where the first item is the local offset and the second item is the new caret position. + /// This is only non-null when a floating cursor is started. + final (Offset, TextPosition)? startLocation; + + /// The state of the floating cursor. + final FloatingCursorDragState state; +} + +/// The current text, selection, and composing state for editing a run of text. +@immutable +class TextEditingValue { + /// Creates information for editing a run of text. + /// + /// The selection and composing range must be within the text. This is not + /// checked during construction, and must be guaranteed by the caller. + /// + /// The default value of [selection] is `TextSelection.collapsed(offset: -1)`. + /// This indicates that there is no selection at all. + const TextEditingValue({ + this.text = '', + this.selection = const TextSelection.collapsed(offset: -1), + this.composing = TextRange.empty, + }); + + /// Creates an instance of this class from a JSON object. + factory TextEditingValue.fromJSON(Map<String, dynamic> encoded) { + final String text = encoded['text'] as String; + final TextSelection selection = TextSelection( + baseOffset: encoded['selectionBase'] as int? ?? -1, + extentOffset: encoded['selectionExtent'] as int? ?? -1, + affinity: _toTextAffinity(encoded['selectionAffinity'] as String?) ?? TextAffinity.downstream, + isDirectional: encoded['selectionIsDirectional'] as bool? ?? false, + ); + final TextRange composing = TextRange( + start: encoded['composingBase'] as int? ?? -1, + end: encoded['composingExtent'] as int? ?? -1, + ); + assert(_textRangeIsValid(selection, text)); + assert(_textRangeIsValid(composing, text)); + return TextEditingValue( + text: text, + selection: selection, + composing: composing, + ); + } + + /// The current text being edited. + final String text; + + /// The range of text that is currently selected. + /// + /// When [selection] is a [TextSelection] that has the same non-negative + /// `baseOffset` and `extentOffset`, the [selection] property represents the + /// caret position. + /// + /// If the current [selection] has a negative `baseOffset` or `extentOffset`, + /// then the text currently does not have a selection or a caret location, and + /// most text editing operations that rely on the current selection (for + /// instance, insert a character at the caret location) will do nothing. + final TextSelection selection; + + /// The range of text that is still being composed. + /// + /// Composing regions are created by input methods (IMEs) to indicate the text + /// within a certain range is provisional. For instance, the Android Gboard + /// app's English keyboard puts the current word under the caret into a + /// composing region to indicate the word is subject to autocorrect or + /// prediction changes. + /// + /// Composing regions can also be used for performing multistage input, which + /// is typically used by IMEs designed for phonetic keyboard to enter + /// ideographic symbols. As an example, many CJK keyboards require the user to + /// enter a Latin alphabet sequence and then convert it to CJK characters. On + /// iOS, the default software keyboards do not have a dedicated view to show + /// the unfinished Latin sequence, so it's displayed directly in the text + /// field, inside of a composing region. + /// + /// The composing region should typically only be changed by the IME, or the + /// user via interacting with the IME. + /// + /// If the range represented by this property is [TextRange.empty], then the + /// text is not currently being composed. + final TextRange composing; + + /// A value that corresponds to the empty string with no selection and no composing range. + static const TextEditingValue empty = TextEditingValue(); + + /// Creates a copy of this value but with the given fields replaced with the new values. + TextEditingValue copyWith({ + String? text, + TextSelection? selection, + TextRange? composing, + }) { + return TextEditingValue( + text: text ?? this.text, + selection: selection ?? this.selection, + composing: composing ?? this.composing, + ); + } + + /// Whether the [composing] range is a valid range within [text]. + /// + /// Returns true if and only if the [composing] range is normalized, its start + /// is greater than or equal to 0, and its end is less than or equal to + /// [text]'s length. + /// + /// If this property is false while the [composing] range's `isValid` is true, + /// it usually indicates the current [composing] range is invalid because of a + /// programming error. + bool get isComposingRangeValid => composing.isValid && composing.isNormalized && composing.end <= text.length; + + /// Returns a new [TextEditingValue], which is this [TextEditingValue] with + /// its [text] partially replaced by the `replacementString`. + /// + /// The `replacementRange` parameter specifies the range of the + /// [TextEditingValue.text] that needs to be replaced. + /// + /// The `replacementString` parameter specifies the string to replace the + /// given range of text with. + /// + /// This method also adjusts the selection range and the composing range of the + /// resulting [TextEditingValue], such that they point to the same substrings + /// as the corresponding ranges in the original [TextEditingValue]. For + /// example, if the original [TextEditingValue] is "Hello world" with the word + /// "world" selected, replacing "Hello" with a different string using this + /// method will not change the selected word. + /// + /// This method does nothing if the given `replacementRange` is not + /// [TextRange.isValid]. + TextEditingValue replaced(TextRange replacementRange, String replacementString) { + if (!replacementRange.isValid) { + return this; + } + final String newText = text.replaceRange(replacementRange.start, replacementRange.end, replacementString); + + if (replacementRange.end - replacementRange.start == replacementString.length) { + return copyWith(text: newText); + } + + int adjustIndex(int originalIndex) { + // The length added by adding the replacementString. + final int replacedLength = originalIndex <= replacementRange.start && originalIndex < replacementRange.end ? 0 : replacementString.length; + // The length removed by removing the replacementRange. + final int removedLength = originalIndex.clamp(replacementRange.start, replacementRange.end) - replacementRange.start; + return originalIndex + replacedLength - removedLength; + } + + final TextSelection adjustedSelection = TextSelection( + baseOffset: adjustIndex(selection.baseOffset), + extentOffset: adjustIndex(selection.extentOffset), + ); + final TextRange adjustedComposing = TextRange( + start: adjustIndex(composing.start), + end: adjustIndex(composing.end), + ); + assert(_textRangeIsValid(adjustedSelection, newText)); + assert(_textRangeIsValid(adjustedComposing, newText)); + return TextEditingValue( + text: newText, + selection: adjustedSelection, + composing: adjustedComposing, + ); + } + + /// Returns a representation of this object as a JSON object. + Map<String, dynamic> toJSON() { + assert(_textRangeIsValid(selection, text)); + assert(_textRangeIsValid(composing, text)); + return <String, dynamic>{ + 'text': text, + 'selectionBase': selection.baseOffset, + 'selectionExtent': selection.extentOffset, + 'selectionAffinity': selection.affinity.toString(), + 'selectionIsDirectional': selection.isDirectional, + 'composingBase': composing.start, + 'composingExtent': composing.end, + }; + } + + @override + String toString() => '${objectRuntimeType(this, 'TextEditingValue')}(text: \u2524$text\u251C, selection: $selection, composing: $composing)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is TextEditingValue + && other.text == text + && other.selection == selection + && other.composing == composing; + } + + @override + int get hashCode => Object.hash( + text.hashCode, + selection.hashCode, + composing.hashCode, + ); + + // Verify that the given range is within the text. + // + // The verification can't be perform during the constructor of + // [TextEditingValue], which are `const` and are allowed to retrieve + // properties of [TextRange]s. [TextEditingValue] should perform this + // wherever it is building other values (such as toJson) or is built in a + // non-const way (such as fromJson). + static bool _textRangeIsValid(TextRange range, String text) { + if (range.start == -1 && range.end == -1) { + return true; + } + assert(range.start >= 0 && range.start <= text.length, + 'Range start ${range.start} is out of text of length ${text.length}'); + assert(range.end >= 0 && range.end <= text.length, + 'Range end ${range.end} is out of text of length ${text.length}'); + return true; + } +} + +/// Indicates what triggered the change in selected text (including changes to +/// the cursor location). +enum SelectionChangedCause { + /// The user tapped on the text and that caused the selection (or the location + /// of the cursor) to change. + tap, + + /// The user tapped twice in quick succession on the text and that caused + /// the selection (or the location of the cursor) to change. + doubleTap, + + /// The user long-pressed the text and that caused the selection (or the + /// location of the cursor) to change. + longPress, + + /// The user force-pressed the text and that caused the selection (or the + /// location of the cursor) to change. + forcePress, + + /// The user used the keyboard to change the selection or the location of the + /// cursor. + /// + /// Keyboard-triggered selection changes may be caused by the IME as well as + /// by accessibility tools (e.g. TalkBack on Android). + keyboard, + + /// The user used the selection toolbar to change the selection or the + /// location of the cursor. + /// + /// An example is when the user taps on select all in the tool bar. + toolbar, + + /// The user used the mouse to change the selection by dragging over a piece + /// of text. + drag, + + /// The user used iPadOS 14+ Scribble to change the selection. + scribble, +} + +/// A mixin for manipulating the selection, provided for toolbar or shortcut +/// keys. +mixin TextSelectionDelegate { + /// Gets the current text input. + TextEditingValue get textEditingValue; + + /// Indicates that the user has requested the delegate to replace its current + /// text editing state with [value]. + /// + /// The new [value] is treated as user input and thus may subject to input + /// formatting. + /// + /// See also: + /// + /// * [EditableTextState.userUpdateTextEditingValue]: an implementation that + /// applies additional pre-processing to the specified [value], before + /// updating the text editing state. + void userUpdateTextEditingValue(TextEditingValue value, SelectionChangedCause cause); + + /// Hides the text selection toolbar. + /// + /// By default, hideHandles is true, and the toolbar is hidden along with its + /// handles. If hideHandles is set to false, then the toolbar will be hidden + /// but the handles will remain. + void hideToolbar([bool hideHandles = true]); + + /// Brings the provided [TextPosition] into the visible area of the text + /// input. + void bringIntoView(TextPosition position); + + /// Whether cut is enabled. + bool get cutEnabled => true; + + /// Whether copy is enabled. + bool get copyEnabled => true; + + /// Whether paste is enabled. + bool get pasteEnabled => true; + + /// Whether select all is enabled. + bool get selectAllEnabled => true; + + /// Whether look up is enabled. + bool get lookUpEnabled => true; + + /// Whether search web is enabled. + bool get searchWebEnabled => true; + + /// Whether share is enabled. + bool get shareEnabled => true; + + /// Whether Live Text input is enabled. + /// + /// See also: + /// * [LiveText], where the availability of Live Text input can be obtained. + /// * [LiveTextInputStatusNotifier], where the status of Live Text can be listened to. + bool get liveTextInputEnabled => false; + + /// Cut current selection to [Clipboard]. + /// + /// If and only if [cause] is [SelectionChangedCause.toolbar], the toolbar + /// will be hidden and the current selection will be scrolled into view. + void cutSelection(SelectionChangedCause cause); + + /// Paste text from [Clipboard]. + /// + /// If there is currently a selection, it will be replaced. + /// + /// If and only if [cause] is [SelectionChangedCause.toolbar], the toolbar + /// will be hidden and the current selection will be scrolled into view. + Future<void> pasteText(SelectionChangedCause cause); + + /// Set the current selection to contain the entire text value. + /// + /// If and only if [cause] is [SelectionChangedCause.toolbar], the selection + /// will be scrolled into view. + void selectAll(SelectionChangedCause cause); + + /// Copy current selection to [Clipboard]. + /// + /// If [cause] is [SelectionChangedCause.toolbar], the position of + /// [bringIntoView] to selection will be called and hide toolbar. + void copySelection(SelectionChangedCause cause); +} + +/// An interface to receive information from [TextInput]. +/// +/// If [TextInputConfiguration.enableDeltaModel] is set to true, +/// [DeltaTextInputClient] must be implemented instead of this class. +/// +/// See also: +/// +/// * [TextInput.attach] +/// * [EditableText], a [TextInputClient] implementation. +/// * [DeltaTextInputClient], a [TextInputClient] extension that receives +/// granular information from the platform's text input. +mixin TextInputClient { + /// The current state of the [TextEditingValue] held by this client. + TextEditingValue? get currentTextEditingValue; + + /// The [AutofillScope] this [TextInputClient] belongs to, if any. + /// + /// It should return null if this [TextInputClient] does not need autofill + /// support. For a [TextInputClient] that supports autofill, returning null + /// causes it to participate in autofill alone. + /// + /// See also: + /// + /// * [AutofillGroup], a widget that creates an [AutofillScope] for its + /// descendent autofillable [TextInputClient]s. + AutofillScope? get currentAutofillScope; + + /// Requests that this client update its editing state to the given value. + /// + /// The new [value] is treated as user input and thus may subject to input + /// formatting. + void updateEditingValue(TextEditingValue value); + + /// Requests that this client perform the given action. + void performAction(TextInputAction action); + + /// Notify client about new content insertion from Android keyboard. + void insertContent(KeyboardInsertedContent content) {} + + /// Request from the input method that this client perform the given private + /// command. + /// + /// This can be used to provide domain-specific features that are only known + /// between certain input methods and their clients. + /// + /// See also: + /// * [performPrivateCommand](https://developer.android.com/reference/android/view/inputmethod/InputConnection#performPrivateCommand\(java.lang.String,%20android.os.Bundle\)), + /// which is the Android documentation for performPrivateCommand, used to + /// send a command from the input method. + /// * [sendAppPrivateCommand](https://developer.android.com/reference/android/view/inputmethod/InputMethodManager#sendAppPrivateCommand), + /// which is the Android documentation for sendAppPrivateCommand, used to + /// send a command to the input method. + void performPrivateCommand(String action, Map<String, dynamic> data); + + /// Updates the floating cursor position and state. + void updateFloatingCursor(RawFloatingCursorPoint point); + + /// Requests that this client display a prompt rectangle for the given text range, + /// to indicate the range of text that will be changed by a pending autocorrection. + /// + /// This method will only be called on iOS. + void showAutocorrectionPromptRect(int start, int end); + + /// Platform notified framework of closed connection. + /// + /// [TextInputClient] should cleanup its connection and finalize editing. + void connectionClosed(); + + /// The framework calls this method to notify that the text input control has + /// been changed. + /// + /// The [TextInputClient] may switch to the new text input control by hiding + /// the old and showing the new input control. + /// + /// See also: + /// + /// * [TextInputControl.hide], a method to hide the old input control. + /// * [TextInputControl.show], a method to show the new input control. + void didChangeInputControl(TextInputControl? oldControl, TextInputControl? newControl) {} + + /// Requests that the client show the editing toolbar, for example when the + /// platform changes the selection through a non-flutter method such as + /// scribble. + void showToolbar() {} + + /// Requests that the client add a text placeholder to reserve visual space + /// in the text. + /// + /// For example, this is called when responding to UIKit requesting + /// a text placeholder be added at the current selection, such as when + /// requesting additional writing space with iPadOS14 Scribble. + void insertTextPlaceholder(Size size) {} + + /// Requests that the client remove the text placeholder. + void removeTextPlaceholder() {} + + /// Performs the specified MacOS-specific selector from the + /// `NSStandardKeyBindingResponding` protocol or user-specified selector + /// from `DefaultKeyBinding.Dict`. + void performSelector(String selectorName) {} +} + +/// An interface to receive focus from the engine. +/// +/// This is currently only used to handle UIIndirectScribbleInteraction. +abstract class ScribbleClient { + /// A unique identifier for this element. + String get elementIdentifier; + + /// Called by the engine when the [ScribbleClient] should receive focus. + /// + /// For example, this method is called during a UIIndirectScribbleInteraction. + void onScribbleFocus(Offset offset); + + /// Tests whether the [ScribbleClient] overlaps the given rectangle bounds. + bool isInScribbleRect(Rect rect); + + /// The current bounds of the [ScribbleClient]. + Rect get bounds; +} + +/// Represents a selection rect for a character and it's position in the text. +/// +/// This is used to report the current text selection rect and position data +/// to the engine for Scribble support on iPadOS 14. +@immutable +class SelectionRect { + /// Constructor for creating a [SelectionRect] from a text [position] and + /// [bounds]. + const SelectionRect({ + required this.position, + required this.bounds, + this.direction = TextDirection.ltr, + }); + + /// The position of this selection rect within the text String. + final int position; + + /// The rectangle representing the bounds of this selection rect within the + /// currently focused [RenderEditable]'s coordinate space. + final Rect bounds; + + /// The direction text flows within this selection rect. + final TextDirection direction; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (runtimeType != other.runtimeType) { + return false; + } + return other is SelectionRect + && other.position == position + && other.bounds == bounds + && other.direction == direction; + } + + @override + int get hashCode => Object.hash(position, bounds); + + @override + String toString() => 'SelectionRect($position, $bounds)'; +} + +/// An interface to receive granular information from [TextInput]. +/// +/// See also: +/// +/// * [TextInput.attach] +/// * [TextInputConfiguration], to opt-in to receive [TextEditingDelta]'s from +/// the platforms [TextInput] you must set [TextInputConfiguration.enableDeltaModel] +/// to true. +mixin DeltaTextInputClient implements TextInputClient { + /// Requests that this client update its editing state by applying the deltas + /// received from the engine. + /// + /// The list of [TextEditingDelta]'s are treated as changes that will be applied + /// to the client's editing state. A change is any mutation to the raw text + /// value, or any updates to the selection and/or composing region. + /// + /// {@tool snippet} + /// This example shows what an implementation of this method could look like. + /// + /// ```dart + /// class MyClient with DeltaTextInputClient { + /// TextEditingValue? _localValue; + /// + /// @override + /// void updateEditingValueWithDeltas(List<TextEditingDelta> textEditingDeltas) { + /// if (_localValue == null) { + /// return; + /// } + /// TextEditingValue newValue = _localValue!; + /// for (final TextEditingDelta delta in textEditingDeltas) { + /// newValue = delta.apply(newValue); + /// } + /// _localValue = newValue; + /// } + /// + /// // ... + /// } + /// ``` + /// {@end-tool} + void updateEditingValueWithDeltas(List<TextEditingDelta> textEditingDeltas); +} + +/// An interface for interacting with a text input control. +/// +/// See also: +/// +/// * [TextInput.attach], a method used to establish a [TextInputConnection] +/// between the system's text input and a [TextInputClient]. +/// * [EditableText], a [TextInputClient] that connects to and interacts with +/// the system's text input using a [TextInputConnection]. +class TextInputConnection { + TextInputConnection._(this._client) + : _id = _nextId++; + + Size? _cachedSize; + Matrix4? _cachedTransform; + Rect? _cachedRect; + Rect? _cachedCaretRect; + List<SelectionRect> _cachedSelectionRects = <SelectionRect>[]; + + static int _nextId = 1; + final int _id; + + /// Resets the internal ID counter for testing purposes. + /// + /// This call has no effect when asserts are disabled. Calling it from + /// application code will likely break text input for the application. + @visibleForTesting + static void debugResetId({int to = 1}) { + assert(() { + _nextId = to; + return true; + }()); + } + + final TextInputClient _client; + + /// Whether this connection is currently interacting with the text input control. + bool get attached => TextInput._instance._currentConnection == this; + + /// Whether there is currently a Scribble interaction in progress. + /// + /// This is used to make sure selection handles are shown when UIKit changes + /// the selection during a Scribble interaction. + bool get scribbleInProgress => TextInput._instance.scribbleInProgress; + + /// Requests that the text input control become visible. + void show() { + assert(attached); + TextInput._instance._show(); + } + + /// Requests the system autofill UI to appear. + /// + /// Currently only works on Android. Other platforms do not respond to this + /// message. + /// + /// See also: + /// + /// * [EditableText], a [TextInputClient] that calls this method when focused. + void requestAutofill() { + assert(attached); + TextInput._instance._requestAutofill(); + } + + /// Requests that the text input control update itself according to the new + /// [TextInputConfiguration]. + void updateConfig(TextInputConfiguration configuration) { + assert(attached); + TextInput._instance._updateConfig(configuration); + } + + /// Requests that the text input control change its internal state to match + /// the given state. + void setEditingState(TextEditingValue value) { + assert(attached); + TextInput._instance._setEditingState(value); + } + + /// Send the size and transform of the editable text to engine. + /// + /// The values are sent as platform messages so they can be used on web for + /// example to correctly position and size the html input field. + /// + /// 1. [editableBoxSize]: size of the render editable box. + /// + /// 2. [transform]: a matrix that maps the local paint coordinate system + /// to the [PipelineOwner.rootNode]. + void setEditableSizeAndTransform(Size editableBoxSize, Matrix4 transform) { + if (editableBoxSize != _cachedSize || transform != _cachedTransform) { + _cachedSize = editableBoxSize; + _cachedTransform = transform; + TextInput._instance._setEditableSizeAndTransform(editableBoxSize, transform); + } + } + + /// Send the smallest rect that covers the text in the client that's currently + /// being composed. + /// + /// If any of the 4 coordinates of the given [Rect] is not finite, a [Rect] of + /// size (-1, -1) will be sent instead. + /// + /// This information is used for positioning the IME candidates menu on each + /// platform. + void setComposingRect(Rect rect) { + if (rect == _cachedRect) { + return; + } + _cachedRect = rect; + final Rect validRect = rect.isFinite ? rect : Offset.zero & const Size(-1, -1); + TextInput._instance._setComposingTextRect(validRect); + } + + /// Sends the coordinates of caret rect. This is used on macOS for positioning + /// the accent selection menu. + void setCaretRect(Rect rect) { + if (rect == _cachedCaretRect) { + return; + } + _cachedCaretRect = rect; + final Rect validRect = rect.isFinite ? rect : Offset.zero & const Size(-1, -1); + TextInput._instance._setCaretRect(validRect); + } + + /// Send the bounding boxes of the current selected glyphs in the client to + /// the platform's text input plugin. + /// + /// These are used by the engine during a UIDirectScribbleInteraction. + void setSelectionRects(List<SelectionRect> selectionRects) { + if (!listEquals(_cachedSelectionRects, selectionRects)) { + _cachedSelectionRects = selectionRects; + TextInput._instance._setSelectionRects(selectionRects); + } + } + + /// Send text styling information. + /// + /// This information is used by the Flutter Web Engine to change the style + /// of the hidden native input's content. Hence, the content size will match + /// to the size of the editable widget's content. + void setStyle({ + required String? fontFamily, + required double? fontSize, + required FontWeight? fontWeight, + required TextDirection textDirection, + required TextAlign textAlign, + }) { + assert(attached); + + TextInput._instance._setStyle( + fontFamily: fontFamily, + fontSize: fontSize, + fontWeight: fontWeight, + textDirection: textDirection, + textAlign: textAlign, + ); + } + + /// Stop interacting with the text input control. + /// + /// After calling this method, the text input control might disappear if no + /// other client attaches to it within this animation frame. + void close() { + if (attached) { + TextInput._instance._clearClient(); + } + assert(!attached); + } + + /// Platform sent a notification informing the connection is closed. + /// + /// [TextInputConnection] should clean current client connection. + void connectionClosedReceived() { + TextInput._instance._currentConnection = null; + assert(!attached); + } +} + +TextInputAction _toTextInputAction(String action) { + switch (action) { + case 'TextInputAction.none': + return TextInputAction.none; + case 'TextInputAction.unspecified': + return TextInputAction.unspecified; + case 'TextInputAction.go': + return TextInputAction.go; + case 'TextInputAction.search': + return TextInputAction.search; + case 'TextInputAction.send': + return TextInputAction.send; + case 'TextInputAction.next': + return TextInputAction.next; + case 'TextInputAction.previous': + return TextInputAction.previous; + case 'TextInputAction.continueAction': + return TextInputAction.continueAction; + case 'TextInputAction.join': + return TextInputAction.join; + case 'TextInputAction.route': + return TextInputAction.route; + case 'TextInputAction.emergencyCall': + return TextInputAction.emergencyCall; + case 'TextInputAction.done': + return TextInputAction.done; + case 'TextInputAction.newline': + return TextInputAction.newline; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary('Unknown text input action: $action')]); +} + +FloatingCursorDragState _toTextCursorAction(String state) { + switch (state) { + case 'FloatingCursorDragState.start': + return FloatingCursorDragState.Start; + case 'FloatingCursorDragState.update': + return FloatingCursorDragState.Update; + case 'FloatingCursorDragState.end': + return FloatingCursorDragState.End; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary('Unknown text cursor action: $state')]); +} + +RawFloatingCursorPoint _toTextPoint(FloatingCursorDragState state, Map<String, dynamic> encoded) { + assert(encoded['X'] != null, 'You must provide a value for the horizontal location of the floating cursor.'); + assert(encoded['Y'] != null, 'You must provide a value for the vertical location of the floating cursor.'); + final Offset offset = state == FloatingCursorDragState.Update + ? Offset((encoded['X'] as num).toDouble(), (encoded['Y'] as num).toDouble()) + : Offset.zero; + return RawFloatingCursorPoint(offset: offset, state: state); +} + +/// An low-level interface to the system's text input control. +/// +/// To start interacting with the system's text input control, call [attach] to +/// establish a [TextInputConnection] between the system's text input control +/// and a [TextInputClient]. The majority of commands available for +/// interacting with the text input control reside in the returned +/// [TextInputConnection]. The communication between the system text input and +/// the [TextInputClient] is asynchronous. +/// +/// The platform text input plugin (which represents the system's text input) +/// and the [TextInputClient] usually maintain their own text editing states +/// ([TextEditingValue]) separately. They must be kept in sync as long as the +/// [TextInputClient] is connected. The following methods can be used to send +/// [TextEditingValue] to update the other party, when either party's text +/// editing states change: +/// +/// * The [TextInput.attach] method allows a [TextInputClient] to establish a +/// connection to the text input. An optional field in its `configuration` +/// parameter can be used to specify an initial value for the platform text +/// input plugin's [TextEditingValue]. +/// +/// * The [TextInputClient] sends its [TextEditingValue] to the platform text +/// input plugin using [TextInputConnection.setEditingState]. +/// +/// * The platform text input plugin sends its [TextEditingValue] to the +/// connected [TextInputClient] via a "TextInput.setEditingState" message. +/// +/// * When autofill happens on a disconnected [TextInputClient], the platform +/// text input plugin sends the [TextEditingValue] to the connected +/// [TextInputClient]'s [AutofillScope], and the [AutofillScope] will further +/// relay the value to the correct [TextInputClient]. +/// +/// When synchronizing the [TextEditingValue]s, the communication may get stuck +/// in an infinite when both parties are trying to send their own update. To +/// mitigate the problem, only [TextInputClient]s are allowed to alter the +/// received [TextEditingValue]s while platform text input plugins are to accept +/// the received [TextEditingValue]s unmodified. More specifically: +/// +/// * When a [TextInputClient] receives a new [TextEditingValue] from the +/// platform text input plugin, it's allowed to modify the value (for example, +/// apply [TextInputFormatter]s). If it decides to do so, it must send the +/// updated [TextEditingValue] back to the platform text input plugin to keep +/// the [TextEditingValue]s in sync. +/// +/// * When the platform text input plugin receives a new value from the +/// connected [TextInputClient], it must accept the new value as-is, to avoid +/// sending back an updated value. +/// +/// See also: +/// +/// * [TextField], a widget in which the user may enter text. +/// * [EditableText], a [TextInputClient] that connects to [TextInput] when it +/// wants to take user input from the keyboard. +class TextInput { + TextInput._() { + _channel = SystemChannels.textInput; + _channel.setMethodCallHandler(_loudlyHandleTextInputInvocation); + } + + /// Set the [MethodChannel] used to communicate with the system's text input + /// control. + /// + /// This is only meant for testing within the Flutter SDK. Changing this + /// will break the ability to input text. This has no effect if asserts are + /// disabled. + @visibleForTesting + static void setChannel(MethodChannel newChannel) { + assert(() { + _instance._channel = newChannel..setMethodCallHandler(_instance._loudlyHandleTextInputInvocation); + return true; + }()); + } + + static final TextInput _instance = TextInput._(); + + static void _addInputControl(TextInputControl control) { + if (control != _PlatformTextInputControl.instance) { + _instance._inputControls.add(control); + } + } + + static void _removeInputControl(TextInputControl control) { + if (control != _PlatformTextInputControl.instance) { + _instance._inputControls.remove(control); + } + } + + /// Sets the current text input control. + /// + /// The current text input control receives text input state changes and visual + /// text input control requests, such as showing and hiding the input control, + /// from the framework. + /// + /// Setting the current text input control as `null` removes the visual text + /// input control. + /// + /// See also: + /// + /// * [TextInputControl], an interface for implementing text input controls. + /// * [TextInput.restorePlatformInputControl], a method to restore the default + /// platform text input control. + static void setInputControl(TextInputControl? newControl) { + final TextInputControl? oldControl = _instance._currentControl; + if (newControl == oldControl) { + return; + } + if (newControl != null) { + _addInputControl(newControl); + } + if (oldControl != null) { + _removeInputControl(oldControl); + } + _instance._currentControl = newControl; + final TextInputClient? client = _instance._currentConnection?._client; + client?.didChangeInputControl(oldControl, newControl); + } + + /// Restores the default platform text input control. + /// + /// See also: + /// + /// * [TextInput.setInputControl], a method to set a custom input + /// control, or to remove the visual input control. + static void restorePlatformInputControl() { + setInputControl(_PlatformTextInputControl.instance); + } + + TextInputControl? _currentControl = _PlatformTextInputControl.instance; + final Set<TextInputControl> _inputControls = <TextInputControl>{ + _PlatformTextInputControl.instance, + }; + + static const List<TextInputAction> _androidSupportedInputActions = <TextInputAction>[ + TextInputAction.none, + TextInputAction.unspecified, + TextInputAction.done, + TextInputAction.send, + TextInputAction.go, + TextInputAction.search, + TextInputAction.next, + TextInputAction.previous, + TextInputAction.newline, + ]; + + static const List<TextInputAction> _iOSSupportedInputActions = <TextInputAction>[ + TextInputAction.unspecified, + TextInputAction.done, + TextInputAction.send, + TextInputAction.go, + TextInputAction.search, + TextInputAction.next, + TextInputAction.newline, + TextInputAction.continueAction, + TextInputAction.join, + TextInputAction.route, + TextInputAction.emergencyCall, + ]; + + /// Ensure that a [TextInput] instance has been set up so that the platform + /// can handle messages on the text input method channel. + static void ensureInitialized() { + _instance; // ignore: unnecessary_statements + } + + /// Begin interacting with the text input control. + /// + /// Calling this function helps multiple clients coordinate about which one is + /// currently interacting with the text input control. The returned + /// [TextInputConnection] provides an interface for actually interacting with + /// the text input control. + /// + /// A client that no longer wishes to interact with the text input control + /// should call [TextInputConnection.close] on the returned + /// [TextInputConnection]. + static TextInputConnection attach(TextInputClient client, TextInputConfiguration configuration) { + final TextInputConnection connection = TextInputConnection._(client); + _instance._attach(connection, configuration); + return connection; + } + + // This method actually notifies the embedding of the client. It is utilized + // by [attach] and by [_handleTextInputInvocation] for the + // `TextInputClient.requestExistingInputState` method. + void _attach(TextInputConnection connection, TextInputConfiguration configuration) { + assert(_debugEnsureInputActionWorksOnPlatform(configuration.inputAction)); + _currentConnection = connection; + _currentConfiguration = configuration; + _setClient(connection._client, configuration); + } + + static bool _debugEnsureInputActionWorksOnPlatform(TextInputAction inputAction) { + assert(() { + if (kIsWeb) { + // TODO(flutterweb): what makes sense here? + return true; + } + if (Platform.isIOS) { + assert( + _iOSSupportedInputActions.contains(inputAction), + 'The requested TextInputAction "$inputAction" is not supported on iOS.', + ); + } else if (Platform.isAndroid) { + assert( + _androidSupportedInputActions.contains(inputAction), + 'The requested TextInputAction "$inputAction" is not supported on Android.', + ); + } + return true; + }()); + return true; + } + + late MethodChannel _channel; + + TextInputConnection? _currentConnection; + late TextInputConfiguration _currentConfiguration; + + final Map<String, ScribbleClient> _scribbleClients = <String, ScribbleClient>{}; + bool _scribbleInProgress = false; + + /// Used for testing within the Flutter SDK to get the currently registered [ScribbleClient] list. + @visibleForTesting + static Map<String, ScribbleClient> get scribbleClients => TextInput._instance._scribbleClients; + + /// Returns true if a scribble interaction is currently happening. + bool get scribbleInProgress => _scribbleInProgress; + + Future<dynamic> _loudlyHandleTextInputInvocation(MethodCall call) async { + try { + return await _handleTextInputInvocation(call); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'services library', + context: ErrorDescription('during method call ${call.method}'), + informationCollector: () => <DiagnosticsNode>[ + DiagnosticsProperty<MethodCall>('call', call, style: DiagnosticsTreeStyle.errorProperty), + ], + )); + rethrow; + } + } + + Future<dynamic> _handleTextInputInvocation(MethodCall methodCall) async { + final String method = methodCall.method; + if (method == 'TextInputClient.focusElement') { + final List<dynamic> args = methodCall.arguments as List<dynamic>; + _scribbleClients[args[0]]?.onScribbleFocus(Offset((args[1] as num).toDouble(), (args[2] as num).toDouble())); + return; + } else if (method == 'TextInputClient.requestElementsInRect') { + final List<double> args = (methodCall.arguments as List<dynamic>).cast<num>().map<double>((num value) => value.toDouble()).toList(); + return _scribbleClients.keys.where((String elementIdentifier) { + final Rect rect = Rect.fromLTWH(args[0], args[1], args[2], args[3]); + if (!(_scribbleClients[elementIdentifier]?.isInScribbleRect(rect) ?? false)) { + return false; + } + final Rect bounds = _scribbleClients[elementIdentifier]?.bounds ?? Rect.zero; + return !(bounds == Rect.zero || bounds.hasNaN || bounds.isInfinite); + }).map((String elementIdentifier) { + final Rect bounds = _scribbleClients[elementIdentifier]!.bounds; + return <dynamic>[elementIdentifier, ...<dynamic>[bounds.left, bounds.top, bounds.width, bounds.height]]; + }).toList(); + } else if (method == 'TextInputClient.scribbleInteractionBegan') { + _scribbleInProgress = true; + return; + } else if (method == 'TextInputClient.scribbleInteractionFinished') { + _scribbleInProgress = false; + return; + } + if (_currentConnection == null) { + return; + } + + // The requestExistingInputState request needs to be handled regardless of + // the client ID, as long as we have a _currentConnection. + if (method == 'TextInputClient.requestExistingInputState') { + _attach(_currentConnection!, _currentConfiguration); + final TextEditingValue? editingValue = _currentConnection!._client.currentTextEditingValue; + if (editingValue != null) { + _setEditingState(editingValue); + } + return; + } + + final List<dynamic> args = methodCall.arguments as List<dynamic>; + + // The updateEditingStateWithTag request (autofill) can come up even to a + // text field that doesn't have a connection. + if (method == 'TextInputClient.updateEditingStateWithTag') { + final TextInputClient client = _currentConnection!._client; + final AutofillScope? scope = client.currentAutofillScope; + final Map<String, dynamic> editingValue = args[1] as Map<String, dynamic>; + for (final String tag in editingValue.keys) { + final TextEditingValue textEditingValue = TextEditingValue.fromJSON( + editingValue[tag] as Map<String, dynamic>, + ); + final AutofillClient? client = scope?.getAutofillClient(tag); + if (client != null && client.textInputConfiguration.autofillConfiguration.enabled) { + client.autofill(textEditingValue); + } + } + + return; + } + + final int client = args[0] as int; + if (client != _currentConnection!._id) { + // If the client IDs don't match, the incoming message was for a different + // client. + bool debugAllowAnyway = false; + assert(() { + // In debug builds we allow "-1" as a magical client ID that ignores + // this verification step so that tests can always get through, even + // when they are not mocking the engine side of text input. + if (client == -1) { + debugAllowAnyway = true; + } + return true; + }()); + if (!debugAllowAnyway) { + return; + } + } + + switch (method) { + case 'TextInputClient.updateEditingState': + final TextEditingValue value = TextEditingValue.fromJSON(args[1] as Map<String, dynamic>); + TextInput._instance._updateEditingValue(value, exclude: _PlatformTextInputControl.instance); + case 'TextInputClient.updateEditingStateWithDeltas': + assert(_currentConnection!._client is DeltaTextInputClient, 'You must be using a DeltaTextInputClient if TextInputConfiguration.enableDeltaModel is set to true'); + final List<TextEditingDelta> deltas = <TextEditingDelta>[]; + + final Map<String, dynamic> encoded = args[1] as Map<String, dynamic>; + + for (final dynamic encodedDelta in encoded['deltas'] as List<dynamic>) { + final TextEditingDelta delta = TextEditingDelta.fromJSON(encodedDelta as Map<String, dynamic>); + deltas.add(delta); + } + + (_currentConnection!._client as DeltaTextInputClient).updateEditingValueWithDeltas(deltas); + case 'TextInputClient.performAction': + if (args[1] as String == 'TextInputAction.commitContent') { + final KeyboardInsertedContent content = KeyboardInsertedContent.fromJson(args[2] as Map<String, dynamic>); + _currentConnection!._client.insertContent(content); + } else { + _currentConnection!._client.performAction(_toTextInputAction(args[1] as String)); + } + case 'TextInputClient.performSelectors': + final List<String> selectors = (args[1] as List<dynamic>).cast<String>(); + selectors.forEach(_currentConnection!._client.performSelector); + case 'TextInputClient.performPrivateCommand': + final Map<String, dynamic> firstArg = args[1] as Map<String, dynamic>; + _currentConnection!._client.performPrivateCommand( + firstArg['action'] as String, + firstArg['data'] == null + ? <String, dynamic>{} + : firstArg['data'] as Map<String, dynamic>, + ); + case 'TextInputClient.updateFloatingCursor': + _currentConnection!._client.updateFloatingCursor(_toTextPoint( + _toTextCursorAction(args[1] as String), + args[2] as Map<String, dynamic>, + )); + case 'TextInputClient.onConnectionClosed': + _currentConnection!._client.connectionClosed(); + case 'TextInputClient.showAutocorrectionPromptRect': + _currentConnection!._client.showAutocorrectionPromptRect(args[1] as int, args[2] as int); + case 'TextInputClient.showToolbar': + _currentConnection!._client.showToolbar(); + case 'TextInputClient.insertTextPlaceholder': + _currentConnection!._client.insertTextPlaceholder(Size((args[1] as num).toDouble(), (args[2] as num).toDouble())); + case 'TextInputClient.removeTextPlaceholder': + _currentConnection!._client.removeTextPlaceholder(); + default: + throw MissingPluginException(); + } + } + + bool _hidePending = false; + + void _scheduleHide() { + if (_hidePending) { + return; + } + _hidePending = true; + + // Schedule a deferred task that hides the text input. If someone else + // shows the keyboard during this update cycle, then the task will do + // nothing. + scheduleMicrotask(() { + _hidePending = false; + if (_currentConnection == null) { + _hide(); + } + }); + } + + void _setClient(TextInputClient client, TextInputConfiguration configuration) { + for (final TextInputControl control in _inputControls) { + control.attach(client, configuration); + } + } + + void _clearClient() { + final TextInputClient client = _currentConnection!._client; + for (final TextInputControl control in _inputControls) { + control.detach(client); + } + _currentConnection = null; + _scheduleHide(); + } + + void _updateConfig(TextInputConfiguration configuration) { + for (final TextInputControl control in _inputControls) { + control.updateConfig(configuration); + } + } + + void _setEditingState(TextEditingValue value) { + for (final TextInputControl control in _inputControls) { + control.setEditingState(value); + } + } + + void _show() { + for (final TextInputControl control in _inputControls) { + control.show(); + } + } + + void _hide() { + for (final TextInputControl control in _inputControls) { + control.hide(); + } + } + + void _setEditableSizeAndTransform(Size editableBoxSize, Matrix4 transform) { + for (final TextInputControl control in _inputControls) { + control.setEditableSizeAndTransform(editableBoxSize, transform); + } + } + + void _setComposingTextRect(Rect rect) { + for (final TextInputControl control in _inputControls) { + control.setComposingRect(rect); + } + } + + void _setCaretRect(Rect rect) { + for (final TextInputControl control in _inputControls) { + control.setCaretRect(rect); + } + } + + void _setSelectionRects(List<SelectionRect> selectionRects) { + for (final TextInputControl control in _inputControls) { + control.setSelectionRects(selectionRects); + } + } + + void _setStyle({ + required String? fontFamily, + required double? fontSize, + required FontWeight? fontWeight, + required TextDirection textDirection, + required TextAlign textAlign, + }) { + for (final TextInputControl control in _inputControls) { + control.setStyle( + fontFamily: fontFamily, + fontSize: fontSize, + fontWeight: fontWeight, + textDirection: textDirection, + textAlign: textAlign, + ); + } + } + + void _requestAutofill() { + for (final TextInputControl control in _inputControls) { + control.requestAutofill(); + } + } + + void _updateEditingValue(TextEditingValue value, {TextInputControl? exclude}) { + if (_currentConnection == null) { + return; + } + + for (final TextInputControl control in _instance._inputControls) { + if (control != exclude) { + control.setEditingState(value); + } + } + _instance._currentConnection!._client.updateEditingValue(value); + } + + /// Updates the editing value of the attached input client. + /// + /// This method should be called by the text input control implementation to + /// send editing value updates to the attached input client. + static void updateEditingValue(TextEditingValue value) { + _instance._updateEditingValue(value, exclude: _instance._currentControl); + } + + /// Finishes the current autofill context, and potentially saves the user + /// input for future use if `shouldSave` is true. + /// + /// Typically, this method should be called when the user has finalized their + /// input. For example, in a [Form], it's typically done immediately before or + /// after its content is submitted. + /// + /// The topmost [AutofillGroup]s also call [finishAutofillContext] + /// automatically when they are disposed. The default behavior can be + /// overridden in [AutofillGroup.onDisposeAction]. + /// + /// {@template flutter.services.TextInput.finishAutofillContext} + /// An autofill context is a collection of input fields that live in the + /// platform's text input plugin. The platform is encouraged to save the user + /// input stored in the current autofill context before the context is + /// destroyed, when [TextInput.finishAutofillContext] is called with + /// `shouldSave` set to true. + /// + /// Currently, there can only be at most one autofill context at any given + /// time. When any input field in an [AutofillGroup] requests for autofill + /// (which is done automatically when an autofillable [EditableText] gains + /// focus), the current autofill context will merge the content of that + /// [AutofillGroup] into itself. When there isn't an existing autofill context, + /// one will be created to hold the newly added input fields from the group. + /// + /// Once added to an autofill context, an input field will stay in the context + /// until the context is destroyed. To prevent leaks, call + /// [TextInput.finishAutofillContext] to signal the text input plugin that the + /// user has finalized their input in the current autofill context. The + /// platform text input plugin either encourages or discourages the platform + /// from saving the user input based on the value of the `shouldSave` + /// parameter. The platform usually shows a "Save for autofill?" prompt for + /// user confirmation. + /// {@endtemplate} + /// + /// On many platforms, calling [finishAutofillContext] shows the save user + /// input dialog and disrupts the user's flow. Ideally the dialog should only + /// be shown no more than once for every screen. Consider removing premature + /// [finishAutofillContext] calls to prevent showing the save user input UI + /// too frequently. However, calling [finishAutofillContext] when there's no + /// existing autofill context usually does not bring up the save user input + /// UI. + /// + /// See also: + /// + /// * [EditableText.autofillHints] for autofill save troubleshooting tips. + /// * [AutofillGroup.onDisposeAction], a configurable action that runs when a + /// topmost [AutofillGroup] is getting disposed. + static void finishAutofillContext({ bool shouldSave = true }) { + for (final TextInputControl control in TextInput._instance._inputControls) { + control.finishAutofillContext(shouldSave: shouldSave); + } + } + + /// Registers a [ScribbleClient] with [elementIdentifier] that can be focused + /// by the engine. + /// + /// For example, the registered [ScribbleClient] list is used to respond to + /// UIIndirectScribbleInteraction on an iPad. + static void registerScribbleElement(String elementIdentifier, ScribbleClient scribbleClient) { + TextInput._instance._scribbleClients[elementIdentifier] = scribbleClient; + } + + /// Unregisters a [ScribbleClient] with [elementIdentifier]. + static void unregisterScribbleElement(String elementIdentifier) { + TextInput._instance._scribbleClients.remove(elementIdentifier); + } +} + +/// An interface for implementing text input controls that receive text editing +/// state changes and visual input control requests. +/// +/// Editing state changes and input control requests are sent by the framework +/// when the editing state of the attached text input client changes, or it +/// requests the input control to be shown or hidden, for example. +/// +/// The input control can be installed with [TextInput.setInputControl], and the +/// default platform text input control can be restored with +/// [TextInput.restorePlatformInputControl]. +/// +/// The [TextInputControl] class must be extended. [TextInputControl] +/// implementations should call [TextInput.updateEditingValue] to send user +/// input to the attached input client. +/// +/// {@tool dartpad} +/// This example illustrates a basic [TextInputControl] implementation. +/// +/// ** See code in examples/api/lib/services/text_input/text_input_control.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [TextInput.setInputControl], a method to install a custom text input control. +/// * [TextInput.restorePlatformInputControl], a method to restore the default +/// platform text input control. +/// * [TextInput.updateEditingValue], a method to send user input to +/// the framework. +mixin TextInputControl { + /// Requests the text input control to attach to the given input client. + /// + /// This method is called when a text input client is attached. The input + /// control should update its configuration to match the client's configuration. + void attach(TextInputClient client, TextInputConfiguration configuration) {} + + /// Requests the text input control to detach from the given input client. + /// + /// This method is called when a text input client is detached. The input + /// control should release any resources allocated for the client. + void detach(TextInputClient client) {} + + /// Requests that the text input control is shown. + /// + /// This method is called when the input control should become visible. + void show() {} + + /// Requests that the text input control is hidden. + /// + /// This method is called when the input control should hide. + void hide() {} + + /// Informs the text input control about input configuration changes. + /// + /// This method is called when the configuration of the attached input client + /// has changed. + void updateConfig(TextInputConfiguration configuration) {} + + /// Informs the text input control about editing state changes. + /// + /// This method is called when the editing state of the attached input client + /// has changed. + void setEditingState(TextEditingValue value) {} + + /// Informs the text input control about client position changes. + /// + /// This method is called on when the input control should position itself in + /// relation to the attached input client. + void setEditableSizeAndTransform(Size editableBoxSize, Matrix4 transform) {} + + /// Informs the text input control about composing area changes. + /// + /// This method is called when the attached input client's composing area + /// changes. + void setComposingRect(Rect rect) {} + + /// Informs the text input control about caret area changes. + /// + /// This method is called when the attached input client's caret area + /// changes. + void setCaretRect(Rect rect) {} + + /// Informs the text input control about selection area changes. + /// + /// This method is called when the attached input client's selection area + /// changes. + void setSelectionRects(List<SelectionRect> selectionRects) {} + + /// Informs the text input control about text style changes. + /// + /// This method is called on the when the attached input client's text style + /// changes. + void setStyle({ + required String? fontFamily, + required double? fontSize, + required FontWeight? fontWeight, + required TextDirection textDirection, + required TextAlign textAlign, + }) {} + + /// Requests autofill from the text input control. + /// + /// This method is called when the autofill UI should appear. + void requestAutofill() {} + + /// Requests that the autofill context is finalized. + /// + /// See also: + /// + /// * [TextInput.finishAutofillContext] + void finishAutofillContext({bool shouldSave = true}) {} +} + +/// Provides access to the platform text input control. +class _PlatformTextInputControl with TextInputControl { + _PlatformTextInputControl._(); + + /// The shared instance of [_PlatformTextInputControl]. + static final _PlatformTextInputControl instance = _PlatformTextInputControl._(); + + MethodChannel get _channel => TextInput._instance._channel; + + Map<String, dynamic> _configurationToJson(TextInputConfiguration configuration) { + final Map<String, dynamic> json = configuration.toJson(); + if (TextInput._instance._currentControl != _PlatformTextInputControl.instance) { + final Map<String, dynamic> none = TextInputType.none.toJson(); + // See: https://github.com/flutter/flutter/issues/125875 + // On Web engine, use isMultiline to create <input> or <textarea> element + // When there's a custom [TextInputControl] installed. + // It's only needed When there's a custom [TextInputControl] installed. + if (kIsWeb) { + none['isMultiline'] = configuration.inputType == TextInputType.multiline; + } + json['inputType'] = none; + } + return json; + } + + @override + void attach(TextInputClient client, TextInputConfiguration configuration) { + _channel.invokeMethod<void>( + 'TextInput.setClient', + <Object>[ + TextInput._instance._currentConnection!._id, + _configurationToJson(configuration), + ], + ); + } + + @override + void detach(TextInputClient client) { + _channel.invokeMethod<void>('TextInput.clearClient'); + } + + @override + void updateConfig(TextInputConfiguration configuration) { + _channel.invokeMethod<void>( + 'TextInput.updateConfig', + _configurationToJson(configuration), + ); + } + + @override + void setEditingState(TextEditingValue value) { + _channel.invokeMethod<void>( + 'TextInput.setEditingState', + value.toJSON(), + ); + } + + @override + void show() { + _channel.invokeMethod<void>('TextInput.show'); + } + + @override + void hide() { + _channel.invokeMethod<void>('TextInput.hide'); + } + + @override + void setEditableSizeAndTransform(Size editableBoxSize, Matrix4 transform) { + _channel.invokeMethod<void>( + 'TextInput.setEditableSizeAndTransform', + <String, dynamic>{ + 'width': editableBoxSize.width, + 'height': editableBoxSize.height, + 'transform': transform.storage, + }, + ); + } + + @override + void setComposingRect(Rect rect) { + _channel.invokeMethod<void>( + 'TextInput.setMarkedTextRect', + <String, dynamic>{ + 'width': rect.width, + 'height': rect.height, + 'x': rect.left, + 'y': rect.top, + }, + ); + } + + @override + void setCaretRect(Rect rect) { + _channel.invokeMethod<void>( + 'TextInput.setCaretRect', + <String, dynamic>{ + 'width': rect.width, + 'height': rect.height, + 'x': rect.left, + 'y': rect.top, + }, + ); + } + + @override + void setSelectionRects(List<SelectionRect> selectionRects) { + _channel.invokeMethod<void>( + 'TextInput.setSelectionRects', + selectionRects.map((SelectionRect rect) { + return <num>[ + rect.bounds.left, + rect.bounds.top, + rect.bounds.width, + rect.bounds.height, + rect.position, + rect.direction.index, + ]; + }).toList(), + ); + } + + + @override + void setStyle({ + required String? fontFamily, + required double? fontSize, + required FontWeight? fontWeight, + required TextDirection textDirection, + required TextAlign textAlign, + }) { + _channel.invokeMethod<void>( + 'TextInput.setStyle', + <String, dynamic>{ + 'fontFamily': fontFamily, + 'fontSize': fontSize, + 'fontWeightIndex': fontWeight?.index, + 'textAlignIndex': textAlign.index, + 'textDirectionIndex': textDirection.index, + }, + ); + } + + @override + void requestAutofill() { + _channel.invokeMethod<void>('TextInput.requestAutofill'); + } + + @override + void finishAutofillContext({bool shouldSave = true}) { + _channel.invokeMethod<void>( + 'TextInput.finishAutofillContext', + shouldSave, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_layout_metrics.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_layout_metrics.dart new file mode 100644 index 0000000000000000000000000000000000000000..e025ea119748b2e7182dfcc1ff43048d44f78a16 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/text_layout_metrics.dart @@ -0,0 +1,99 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show TextRange; + +import 'text_editing.dart'; + +export 'dart:ui' show TextPosition, TextRange; + +export 'text_editing.dart' show TextSelection; + +/// A read-only interface for accessing visual information about the +/// implementing text. +abstract class TextLayoutMetrics { + // TODO(gspencergoog): replace when we expose this ICU information. + /// Check if the given code unit is a white space or separator + /// character. + /// + /// Includes newline characters from ASCII and separators from the + /// [unicode separator category](https://www.compart.com/en/unicode/category/Zs) + static bool isWhitespace(int codeUnit) { + switch (codeUnit) { + case 0x9: // horizontal tab + case 0xA: // line feed + case 0xB: // vertical tab + case 0xC: // form feed + case 0xD: // carriage return + case 0x1C: // file separator + case 0x1D: // group separator + case 0x1E: // record separator + case 0x1F: // unit separator + case 0x20: // space + case 0xA0: // no-break space + case 0x1680: // ogham space mark + case 0x2000: // en quad + case 0x2001: // em quad + case 0x2002: // en space + case 0x2003: // em space + case 0x2004: // three-per-em space + case 0x2005: // four-er-em space + case 0x2006: // six-per-em space + case 0x2007: // figure space + case 0x2008: // punctuation space + case 0x2009: // thin space + case 0x200A: // hair space + case 0x202F: // narrow no-break space + case 0x205F: // medium mathematical space + case 0x3000: // ideographic space + break; + default: + return false; + } + return true; + } + + /// Check if the given code unit is a line terminator character. + /// + /// Includes newline characters from ASCII + /// (https://www.unicode.org/standard/reports/tr13/tr13-5.html). + static bool isLineTerminator(int codeUnit) { + switch (codeUnit) { + case 0x0A: // line feed + case 0x0B: // vertical feed + case 0x0C: // form feed + case 0x0D: // carriage return + case 0x85: // new line + case 0x2028: // line separator + case 0x2029: // paragraph separator + return true; + default: + return false; + } + } + + /// {@template flutter.services.TextLayoutMetrics.getLineAtOffset} + /// Return a [TextSelection] containing the line of the given [TextPosition]. + /// {@endtemplate} + TextSelection getLineAtOffset(TextPosition position); + + /// {@macro flutter.painting.TextPainter.getWordBoundary} + TextRange getWordBoundary(TextPosition position); + + /// {@template flutter.services.TextLayoutMetrics.getTextPositionAbove} + /// Returns the TextPosition above the given offset into the text. + /// + /// If the offset is already on the first line, the given offset will be + /// returned. + /// {@endtemplate} + TextPosition getTextPositionAbove(TextPosition position); + + /// {@template flutter.services.TextLayoutMetrics.getTextPositionBelow} + /// Returns the TextPosition below the given offset into the text. + /// + /// If the offset is already on the last line, the given offset will be + /// returned. + /// {@endtemplate} + TextPosition getTextPositionBelow(TextPosition position); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/undo_manager.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/undo_manager.dart new file mode 100644 index 0000000000000000000000000000000000000000..71837ad24dbc478c9e8ebcbb1c3e66c47d3c90ae --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/services/undo_manager.dart @@ -0,0 +1,131 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import '../../services.dart'; + +/// The direction in which an undo action should be performed, whether undo or redo. +enum UndoDirection { + /// Perform an undo action. + undo, + + /// Perform a redo action. + redo +} + +/// A low-level interface to the system's undo manager. +/// +/// To receive events from the system undo manager, create an +/// [UndoManagerClient] and set it as the [client] on [UndoManager]. +/// +/// The [setUndoState] method can be used to update the system's undo manager +/// using the [canUndo] and [canRedo] parameters. +/// +/// When the system undo or redo button is tapped, the current +/// [UndoManagerClient] will receive [UndoManagerClient.handlePlatformUndo] +/// with an [UndoDirection] representing whether the event is "undo" or "redo". +/// +/// Currently, only iOS has an UndoManagerPlugin implemented on the engine side. +/// On iOS, this can be used to listen to the keyboard undo/redo buttons and the +/// undo/redo gestures. +/// +/// See also: +/// +/// * [NSUndoManager](https://developer.apple.com/documentation/foundation/nsundomanager) +class UndoManager { + UndoManager._() { + _channel = SystemChannels.undoManager; + _channel.setMethodCallHandler(_handleUndoManagerInvocation); + } + + /// Set the [MethodChannel] used to communicate with the system's undo manager. + /// + /// This is only meant for testing within the Flutter SDK. Changing this + /// will break the ability to set the undo status or receive undo and redo + /// events from the system. This has no effect if asserts are disabled. + @visibleForTesting + static void setChannel(MethodChannel newChannel) { + assert(() { + _instance._channel = newChannel..setMethodCallHandler(_instance._handleUndoManagerInvocation); + return true; + }()); + } + + static final UndoManager _instance = UndoManager._(); + + /// Receive undo and redo events from the system's [UndoManager]. + /// + /// Setting the [client] will cause [UndoManagerClient.handlePlatformUndo] + /// to be called when a system undo or redo is triggered, such as by tapping + /// the undo/redo keyboard buttons or using the 3-finger swipe gestures. + static set client(UndoManagerClient? client) { + _instance._currentClient = client; + } + + /// Return the current [UndoManagerClient]. + static UndoManagerClient? get client => _instance._currentClient; + + /// Set the current state of the system UndoManager. [canUndo] and [canRedo] + /// control the respective "undo" and "redo" buttons of the system UndoManager. + static void setUndoState({bool canUndo = false, bool canRedo = false}) { + _instance._setUndoState(canUndo: canUndo, canRedo: canRedo); + } + + late MethodChannel _channel; + + UndoManagerClient? _currentClient; + + Future<dynamic> _handleUndoManagerInvocation(MethodCall methodCall) async { + final String method = methodCall.method; + final List<dynamic> args = methodCall.arguments as List<dynamic>; + if (method == 'UndoManagerClient.handleUndo') { + assert(_currentClient != null, 'There must be a current UndoManagerClient.'); + _currentClient!.handlePlatformUndo(_toUndoDirection(args[0] as String)); + + return; + } + + throw MissingPluginException(); + } + + void _setUndoState({bool canUndo = false, bool canRedo = false}) { + _channel.invokeMethod<void>( + 'UndoManager.setUndoState', + <String, bool>{'canUndo': canUndo, 'canRedo': canRedo} + ); + } + + UndoDirection _toUndoDirection(String direction) { + switch (direction) { + case 'undo': + return UndoDirection.undo; + case 'redo': + return UndoDirection.redo; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary('Unknown undo direction: $direction')]); + } +} + +/// An interface to receive events from a native UndoManager. +mixin UndoManagerClient { + /// Requests that the client perform an undo or redo operation. + /// + /// Currently only used on iOS 9+ when the undo or redo methods are invoked + /// by the platform. For example, when using three-finger swipe gestures, + /// the iPad keyboard, or voice control. + void handlePlatformUndo(UndoDirection direction); + + /// Reverts the value on the stack to the previous value. + void undo(); + + /// Updates the value on the stack to the next value. + void redo(); + + /// Will be true if there are past values on the stack. + bool get canUndo; + + /// Will be true if there are future values on the stack. + bool get canRedo; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/web.dart new file mode 100644 index 0000000000000000000000000000000000000000..3a012d7d749cf6b9d767f31aa72715874905d656 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/web.dart @@ -0,0 +1,213 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This code is copied from `package:web` which still needs its own +// documentation for public members. Since this is a shim that users should not +// use, we ignore this lint for this file. +// ignore_for_file: public_member_api_docs + +/// A stripped down version of `package:web` to avoid pinning that repo in +/// Flutter as a dependency. +/// +/// These are manually copied over from `package:web` as needed, and should stay +/// in sync with the latest package version as much as possible. +/// +/// If missing members are needed, copy them over into the corresponding +/// extension or interface. If missing interfaces/types are needed, copy them +/// over while excluding unnecessary inheritance to make the copy minimal. These +/// types are erased at runtime, so excluding supertypes is safe. If a member is +/// needed that belongs to a supertype, then add the necessary `implements` +/// clause to the subtype when you add that supertype. Keep extensions next to +/// the interface they extend. +library; + +import 'dart:js_interop'; + +typedef EventListener = JSFunction; +typedef XMLHttpRequestResponseType = String; + +@JS() +external Document get document; + +@JS() +external Window get window; + +@JS('CSSStyleDeclaration') +@staticInterop +class CSSStyleDeclaration {} + +extension CSSStyleDeclarationExtension on CSSStyleDeclaration { + external set backgroundColor(String value); + external String get backgroundColor; + external set border(String value); + external String get border; + external set height(String value); + external String get height; + external set width(String value); + external String get width; +} + +@JS('CSSStyleSheet') +@staticInterop +class CSSStyleSheet {} + +extension CSSStyleSheetExtension on CSSStyleSheet { + external int insertRule( + String rule, [ + int index, + ]); +} + +@JS('Document') +@staticInterop +class Document implements Node {} + +extension DocumentExtension on Document { + external Element createElement( + String localName, [ + JSAny options, + ]); + external Range createRange(); + external HTMLHeadElement? get head; +} + +@JS('DOMTokenList') +@staticInterop +class DOMTokenList {} + +extension DOMTokenListExtension on DOMTokenList { + external void add(String tokens); +} + +@JS('Element') +@staticInterop +class Element implements Node {} + +extension ElementExtension on Element { + external DOMTokenList get classList; + external void append(JSAny nodes); +} + +@JS('Event') +@staticInterop +class Event {} + +@JS('EventTarget') +@staticInterop +class EventTarget {} + +extension EventTargetExtension on EventTarget { + external void addEventListener( + String type, + EventListener? callback, [ + JSAny options, + ]); +} + +@JS('HTMLElement') +@staticInterop +class HTMLElement implements Element {} + +extension HTMLElementExtension on HTMLElement { + external set innerText(String value); + external CSSStyleDeclaration get style; +} + +@JS('HTMLHeadElement') +@staticInterop +class HTMLHeadElement implements HTMLElement {} + +@JS('HTMLStyleElement') +@staticInterop +class HTMLStyleElement implements HTMLElement {} + +extension HTMLStyleElementExtension on HTMLStyleElement { + external CSSStyleSheet? get sheet; +} + +@JS('MediaQueryList') +@staticInterop +class MediaQueryList {} + +extension MediaQueryListExtension on MediaQueryList { + external bool get matches; +} + +@JS('MouseEvent') +@staticInterop +class MouseEvent {} + +extension MouseEventExtension on MouseEvent { + external num get offsetX; + external num get offsetY; + external int get button; +} + +@JS('Navigator') +@staticInterop +class Navigator {} + +extension NavigatorExtension on Navigator { + external String get platform; +} + +@JS('Node') +@staticInterop +class Node implements EventTarget {} + +@JS('Range') +@staticInterop +class Range {} + +extension RangeExtension on Range { + external void selectNode(Node node); +} + +@JS('Selection') +@staticInterop +class Selection {} + +extension SelectionExtension on Selection { + external void addRange(Range range); + external void removeAllRanges(); +} + +@JS('Window') +@staticInterop +class Window {} + +extension WindowExtension on Window { + external Navigator get navigator; + external MediaQueryList matchMedia(String query); + external Selection? getSelection(); +} + +@JS('XMLHttpRequest') +@staticInterop +class XMLHttpRequest implements XMLHttpRequestEventTarget { + external factory XMLHttpRequest(); +} + +extension XMLHttpRequestExtension on XMLHttpRequest { + external void open( + String method, + String url, [ + bool async, + String? username, + String? password, + ]); + external void setRequestHeader( + String name, + String value, + ); + external void send([JSAny? body]); + external int get status; + external set responseType(XMLHttpRequestResponseType value); + external XMLHttpRequestResponseType get responseType; + external JSAny? get response; +} + +@JS('XMLHttpRequestEventTarget') +@staticInterop +class XMLHttpRequestEventTarget implements EventTarget {} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_html_element_view_io.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_html_element_view_io.dart new file mode 100644 index 0000000000000000000000000000000000000000..e99944b92c64d61bef1ea55a4532fb9f1e1489f1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_html_element_view_io.dart @@ -0,0 +1,31 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'framework.dart'; +import 'platform_view.dart'; + +/// The platform-specific implementation of [HtmlElementView]. +extension HtmlElementViewImpl on HtmlElementView { + /// Creates an [HtmlElementView] that renders a DOM element with the given + /// [tagName]. + static HtmlElementView createFromTagName({ + Key? key, + required String tagName, + bool isVisible = true, + ElementCreatedCallback? onElementCreated, + }) { + throw UnimplementedError('HtmlElementView is only available on Flutter Web'); + } + + /// Called from [HtmlElementView.build] to build the widget tree. + /// + /// This is not expected to be invoked in non-web environments. It throws if + /// that happens. + /// + /// The implementation on Flutter Web builds a platform view and handles its + /// lifecycle. + Widget buildImpl(BuildContext context) { + throw UnimplementedError('HtmlElementView is only available on Flutter Web'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_html_element_view_web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_html_element_view_web.dart new file mode 100644 index 0000000000000000000000000000000000000000..fa7060e6adfe7bf11c98cd29812077ab2bca7ac4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_html_element_view_web.dart @@ -0,0 +1,136 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui_web' as ui_web; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; + +import 'framework.dart'; +import 'platform_view.dart'; + +/// The platform-specific implementation of [HtmlElementView]. +extension HtmlElementViewImpl on HtmlElementView { + /// Creates an [HtmlElementView] that renders a DOM element with the given + /// [tagName]. + static HtmlElementView createFromTagName({ + Key? key, + required String tagName, + bool isVisible = true, + ElementCreatedCallback? onElementCreated, + }) { + return HtmlElementView( + key: key, + viewType: isVisible ? ui_web.PlatformViewRegistry.defaultVisibleViewType : ui_web.PlatformViewRegistry.defaultInvisibleViewType, + onPlatformViewCreated: _createPlatformViewCallbackForElementCallback(onElementCreated), + creationParams: <dynamic, dynamic>{'tagName': tagName}, + ); + } + + /// The implementation of [HtmlElementView.build]. + /// + /// This is not expected to be invoked in non-web environments. It throws if + /// that happens. + /// + /// The implementation on Flutter Web builds an HTML platform view and handles + /// its lifecycle. + Widget buildImpl(BuildContext context) { + return PlatformViewLink( + viewType: viewType, + onCreatePlatformView: _createController, + surfaceFactory: (BuildContext context, PlatformViewController controller) { + return PlatformViewSurface( + controller: controller, + gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{}, + hitTestBehavior: PlatformViewHitTestBehavior.opaque, + ); + }, + ); + } + + /// Creates the controller and kicks off its initialization. + _HtmlElementViewController _createController( + PlatformViewCreationParams params, + ) { + final _HtmlElementViewController controller = _HtmlElementViewController( + params.id, + viewType, + creationParams, + ); + controller._initialize().then((_) { + params.onPlatformViewCreated(params.id); + onPlatformViewCreated?.call(params.id); + }); + return controller; + } +} + +PlatformViewCreatedCallback? _createPlatformViewCallbackForElementCallback( + ElementCreatedCallback? onElementCreated, +) { + if (onElementCreated == null) { + return null; + } + return (int id) { + onElementCreated(_platformViewsRegistry.getViewById(id)); + }; +} + +class _HtmlElementViewController extends PlatformViewController { + _HtmlElementViewController( + this.viewId, + this.viewType, + this.creationParams, + ); + + @override + final int viewId; + + /// The unique identifier for the HTML view type to be embedded by this widget. + /// + /// A PlatformViewFactory for this type must have been registered. + final String viewType; + + final dynamic creationParams; + + bool _initialized = false; + + Future<void> _initialize() async { + final Map<String, dynamic> args = <String, dynamic>{ + 'id': viewId, + 'viewType': viewType, + 'params': creationParams, + }; + await SystemChannels.platform_views.invokeMethod<void>('create', args); + _initialized = true; + } + + @override + Future<void> clearFocus() async { + // Currently this does nothing on Flutter Web. + // TODO(het): Implement this. See https://github.com/flutter/flutter/issues/39496 + } + + @override + Future<void> dispatchPointerEvent(PointerEvent event) async { + // We do not dispatch pointer events to HTML views because they may contain + // cross-origin iframes, which only accept user-generated events. + } + + @override + Future<void> dispose() async { + if (_initialized) { + await SystemChannels.platform_views.invokeMethod<void>('dispose', viewId); + } + } +} + +/// Overrides the [ui_web.PlatformViewRegistry] used by [HtmlElementView]. +/// +/// This is used for testing view factory registration. +@visibleForTesting +ui_web.PlatformViewRegistry? debugOverridePlatformViewRegistry; +ui_web.PlatformViewRegistry get _platformViewsRegistry => debugOverridePlatformViewRegistry ?? ui_web.platformViewRegistry; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_platform_selectable_region_context_menu_io.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_platform_selectable_region_context_menu_io.dart new file mode 100644 index 0000000000000000000000000000000000000000..e1efce68a28465869e109d41edb11c1120b96f49 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_platform_selectable_region_context_menu_io.dart @@ -0,0 +1,51 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// The widget in this file is an empty mock for non-web platforms. See +// `_platform_selectable_region_context_menu_web.dart` for the web +// implementation. + +import 'framework.dart'; +import 'selection_container.dart'; + +/// Function signature for `ui_web.platformViewRegistry.registerViewFactory`. +@visibleForTesting +typedef RegisterViewFactory = void Function(String, Object Function(int viewId), {bool isVisible}); + +/// A widget that provides native selection context menu for its child subtree. +/// +/// This widget currently only supports Flutter web. Using this widget in non-web +/// platforms will throw [UnimplementedError]s. +/// +/// In web platform, this widget registers a singleton platform view, i.e. a +/// HTML DOM element. The created platform view will be shared between all +/// [PlatformSelectableRegionContextMenu]s. +/// +/// Only one [SelectionContainerDelegate] can attach to the +/// [PlatformSelectableRegionContextMenu] at a time. Use [attach] method to make +/// a [SelectionContainerDelegate] to be the active client. +class PlatformSelectableRegionContextMenu extends StatelessWidget { + /// Creates a [PlatformSelectableRegionContextMenu] + // ignore: prefer_const_constructors_in_immutables + PlatformSelectableRegionContextMenu({ + // ignore: avoid_unused_constructor_parameters + required Widget child, + super.key, + }); + + /// Attaches the `client` to be able to open platform-appropriate context menus. + static void attach(SelectionContainerDelegate client) => throw UnimplementedError(); + + /// Detaches the `client` from the platform-appropriate selection context menus. + static void detach(SelectionContainerDelegate client) => throw UnimplementedError(); + + /// Override this to provide a custom implementation of `ui_web.platformViewRegistry.registerViewFactory`. + /// + /// This should only be used for testing. + @visibleForTesting + static RegisterViewFactory? debugOverrideRegisterViewFactory; + + @override + Widget build(BuildContext context) => throw UnimplementedError(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_platform_selectable_region_context_menu_web.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_platform_selectable_region_context_menu_web.dart new file mode 100644 index 0000000000000000000000000000000000000000..c4fa712ac19631fd4a6920ece7df2de8a2b16fbd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/_platform_selectable_region_context_menu_web.dart @@ -0,0 +1,149 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:js_interop'; +import 'dart:ui_web' as ui_web; + +import 'package:flutter/rendering.dart'; + +import '../web.dart' as web; +import 'basic.dart'; +import 'framework.dart'; +import 'platform_view.dart'; +import 'selection_container.dart'; + +const String _viewType = 'Browser__WebContextMenuViewType__'; +const String _kClassName = 'web-electable-region-context-menu'; +// These css rules hides the dom element with the class name. +const String _kClassSelectionRule = '.$_kClassName::selection { background: transparent; }'; +const String _kClassRule = ''' +.$_kClassName { + color: transparent; + user-select: text; + -webkit-user-select: text; /* Safari */ + -moz-user-select: text; /* Firefox */ + -ms-user-select: text; /* IE10+ */ +} +'''; +const int _kRightClickButton = 2; + +typedef _WebSelectionCallBack = void Function(web.HTMLElement, web.MouseEvent); + +/// Function signature for `ui_web.platformViewRegistry.registerViewFactory`. +@visibleForTesting +typedef RegisterViewFactory = void Function(String, Object Function(int viewId), {bool isVisible}); + +/// See `_platform_selectable_region_context_menu_io.dart` for full +/// documentation. +class PlatformSelectableRegionContextMenu extends StatelessWidget { + /// See `_platform_selectable_region_context_menu_io.dart`. + PlatformSelectableRegionContextMenu({ + required this.child, + super.key, + }) { + if (_registeredViewType == null) { + _register(); + } + } + + /// See `_platform_selectable_region_context_menu_io.dart`. + final Widget child; + + /// See `_platform_selectable_region_context_menu_io.dart`. + // ignore: use_setters_to_change_properties + static void attach(SelectionContainerDelegate client) { + _activeClient = client; + } + + /// See `_platform_selectable_region_context_menu_io.dart`. + static void detach(SelectionContainerDelegate client) { + if (_activeClient != client) { + _activeClient = null; + } + } + + static SelectionContainerDelegate? _activeClient; + + // Keeps track if this widget has already registered its view factories or not. + static String? _registeredViewType; + + static RegisterViewFactory get _registerViewFactory => + debugOverrideRegisterViewFactory ?? ui_web.platformViewRegistry.registerViewFactory; + + /// Override this to provide a custom implementation of [ui_web.platformViewRegistry.registerViewFactory]. + /// + /// This should only be used for testing. + // See `_platform_selectable_region_context_menu_io.dart`. + @visibleForTesting + static RegisterViewFactory? debugOverrideRegisterViewFactory; + + // Registers the view factories for the interceptor widgets. + static void _register() { + assert(_registeredViewType == null); + _registeredViewType = _registerWebSelectionCallback((web.HTMLElement element, web.MouseEvent event) { + final SelectionContainerDelegate? client = _activeClient; + if (client != null) { + // Converts the html right click event to flutter coordinate. + final Offset localOffset = Offset(event.offsetX.toDouble(), event.offsetY.toDouble()); + final Matrix4 transform = client.getTransformTo(null); + final Offset globalOffset = MatrixUtils.transformPoint(transform, localOffset); + client.dispatchSelectionEvent(SelectWordSelectionEvent(globalPosition: globalOffset)); + // The innerText must contain the text in order to be selected by + // the browser. + element.innerText = client.getSelectedContent()?.plainText ?? ''; + + // Programmatically select the dom element in browser. + final web.Range range = web.document.createRange(); + range.selectNode(element); + final web.Selection? selection = web.window.getSelection(); + if (selection != null) { + selection.removeAllRanges(); + selection.addRange(range); + } + } + }); + } + + static String _registerWebSelectionCallback(_WebSelectionCallBack callback) { + _registerViewFactory(_viewType, (int viewId) { + final web.HTMLElement htmlElement = web.document.createElement('div') as web.HTMLElement; + htmlElement + ..style.width = '100%' + ..style.height = '100%' + ..classList.add(_kClassName); + + // Create css style for _kClassName. + final web.HTMLStyleElement styleElement = web.document.createElement('style') as web.HTMLStyleElement; + web.document.head!.append(styleElement as JSAny); + final web.CSSStyleSheet sheet = styleElement.sheet!; + sheet.insertRule(_kClassRule, 0); + sheet.insertRule(_kClassSelectionRule, 1); + + htmlElement.addEventListener('mousedown', (web.Event event) { + final web.MouseEvent mouseEvent = event as web.MouseEvent; + if (mouseEvent.button != _kRightClickButton) { + return; + } + callback(htmlElement, mouseEvent); + }.toJS); + return htmlElement; + }, isVisible: false); + return _viewType; + } + + @override + Widget build(BuildContext context) { + return Stack( + alignment: Alignment.center, + children: <Widget>[ + const Positioned.fill( + child: HtmlElementView( + viewType: _viewType, + ), + ), + child, + ], + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/actions.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/actions.dart new file mode 100644 index 0000000000000000000000000000000000000000..2dc33da05cce5008ec505a5e8ad6a905ed757f3d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/actions.dart @@ -0,0 +1,1868 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'basic.dart'; +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; +import 'media_query.dart'; +import 'shortcuts.dart'; + +/// Returns the parent [BuildContext] of a given `context`. +/// +/// [BuildContext] (or rather, [Element]) doesn't have a `parent` accessor, but +/// the parent can be obtained using [BuildContext.visitAncestorElements]. +/// +/// [BuildContext.getElementForInheritedWidgetOfExactType] returns the same +/// [BuildContext] if it happens to be of the correct type. To obtain the +/// previous inherited widget, the search must therefore start from the parent; +/// this is what [_getParent] is used for. +/// +/// [_getParent] is O(1), because it always stops at the first ancestor. +BuildContext _getParent(BuildContext context) { + late final BuildContext parent; + context.visitAncestorElements((Element ancestor) { + parent = ancestor; + return false; + }); + return parent; +} + +/// An abstract class representing a particular configuration of an [Action]. +/// +/// This class is what the [Shortcuts.shortcuts] map has as values, and is used +/// by an [ActionDispatcher] to look up an action and invoke it, giving it this +/// object to extract configuration information from. +/// +/// See also: +/// +/// * [Shortcuts], a widget used to bind key combinations to [Intent]s. +/// * [Actions], a widget used to map [Intent]s to [Action]s. +/// * [Actions.invoke], which invokes the action associated with a specified +/// [Intent] using the [Actions] widget that most tightly encloses the given +/// [BuildContext]. +@immutable +abstract class Intent with Diagnosticable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const Intent(); + + /// An intent that is mapped to a [DoNothingAction], which, as the name + /// implies, does nothing. + /// + /// This Intent is mapped to an action in the [WidgetsApp] that does nothing, + /// so that it can be bound to a key in a [Shortcuts] widget in order to + /// disable a key binding made above it in the hierarchy. + static const DoNothingIntent doNothing = DoNothingIntent._(); +} + +/// The kind of callback that an [Action] uses to notify of changes to the +/// action's state. +/// +/// To register an action listener, call [Action.addActionListener]. +typedef ActionListenerCallback = void Function(Action<Intent> action); + +/// Base class for an action or command to be performed. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=XawP1i314WM} +/// +/// [Action]s are typically invoked as a result of a user action. For example, +/// the [Shortcuts] widget will map a keyboard shortcut into an [Intent], which +/// is given to an [ActionDispatcher] to map the [Intent] to an [Action] and +/// invoke it. +/// +/// The [ActionDispatcher] can invoke an [Action] on the primary focus, or +/// without regard for focus. +/// +/// ### Action Overriding +/// +/// When using a leaf widget to build a more specialized widget, it's sometimes +/// desirable to change the default handling of an [Intent] defined in the leaf +/// widget. For instance, [TextField]'s [SelectAllTextIntent] by default selects +/// the text it currently contains, but in a US phone number widget that +/// consists of 3 different [TextField]s (area code, prefix and line number), +/// [SelectAllTextIntent] should instead select the text within all 3 +/// [TextField]s. +/// +/// An overridable [Action] is a special kind of [Action] created using the +/// [Action.overridable] constructor. It has access to a default [Action], and a +/// nullable override [Action]. It has the same behavior as its override if that +/// exists, and mirrors the behavior of its `defaultAction` otherwise. +/// +/// The [Action.overridable] constructor creates overridable [Action]s that use +/// a [BuildContext] to find a suitable override in its ancestor [Actions] +/// widget. This can be used to provide a default implementation when creating a +/// general purpose leaf widget, and later override it when building a more +/// specialized widget using that leaf widget. Using the [TextField] example +/// above, the [TextField] widget uses an overridable [Action] to provide a +/// sensible default for [SelectAllTextIntent], while still allowing app +/// developers to change that if they add an ancestor [Actions] widget that maps +/// [SelectAllTextIntent] to a different [Action]. +/// +/// See the article on [Using Actions and +/// Shortcuts](https://docs.flutter.dev/development/ui/advanced/actions_and_shortcuts) +/// for a detailed explanation. +/// +/// See also: +/// +/// * [Shortcuts], which is a widget that contains a key map, in which it looks +/// up key combinations in order to invoke actions. +/// * [Actions], which is a widget that defines a map of [Intent] to [Action] +/// and allows redefining of actions for its descendants. +/// * [ActionDispatcher], a class that takes an [Action] and invokes it, passing +/// a given [Intent]. +/// * [Action.overridable] for an example on how to make an [Action] +/// overridable. +abstract class Action<T extends Intent> with Diagnosticable { + /// Creates an [Action]. + Action(); + + /// Creates an [Action] that allows itself to be overridden by the closest + /// ancestor [Action] in the given [context] that handles the same [Intent], + /// if one exists. + /// + /// When invoked, the resulting [Action] tries to find the closest [Action] in + /// the given `context` that handles the same type of [Intent] as the + /// `defaultAction`, then calls its [Action.invoke] method. When no override + /// [Action]s can be found, it invokes the `defaultAction`. + /// + /// An overridable action delegates everything to its override if one exists, + /// and has the same behavior as its `defaultAction` otherwise. For this + /// reason, the override has full control over whether and how an [Intent] + /// should be handled, or a key event should be consumed. An override + /// [Action]'s [callingAction] property will be set to the [Action] it + /// currently overrides, giving it access to the default behavior. See the + /// [callingAction] property for an example. + /// + /// The `context` argument is the [BuildContext] to find the override with. It + /// is typically a [BuildContext] above the [Actions] widget that contains + /// this overridable [Action]. + /// + /// The `defaultAction` argument is the [Action] to be invoked where there's + /// no ancestor [Action]s can't be found in `context` that handle the same + /// type of [Intent]. + /// + /// This is useful for providing a set of default [Action]s in a leaf widget + /// to allow further overriding, or to allow the [Intent] to propagate to + /// parent widgets that also support this [Intent]. + /// + /// {@tool dartpad} + /// This sample shows how to implement a rudimentary `CopyableText` widget + /// that responds to Ctrl-C by copying its own content to the clipboard. + /// + /// if `CopyableText` is to be provided in a package, developers using the + /// widget may want to change how copying is handled. As the author of the + /// package, you can enable that by making the corresponding [Action] + /// overridable. In the second part of the code sample, three `CopyableText` + /// widgets are used to build a verification code widget which overrides the + /// "copy" action by copying the combined numbers from all three `CopyableText` + /// widgets. + /// + /// ** See code in examples/api/lib/widgets/actions/action.action_overridable.0.dart ** + /// {@end-tool} + factory Action.overridable({ + required Action<T> defaultAction, + required BuildContext context, + }) { + return defaultAction._makeOverridableAction(context); + } + + final ObserverList<ActionListenerCallback> _listeners = ObserverList<ActionListenerCallback>(); + + Action<T>? _currentCallingAction; + // ignore: use_setters_to_change_properties, (code predates enabling of this lint) + void _updateCallingAction(Action<T>? value) { + _currentCallingAction = value; + } + + /// The [Action] overridden by this [Action]. + /// + /// The [Action.overridable] constructor creates an overridable [Action] that + /// allows itself to be overridden by the closest ancestor [Action], and falls + /// back to its own `defaultAction` when no overrides can be found. When an + /// override is present, an overridable [Action] forwards all incoming + /// method calls to the override, and allows the override to access the + /// `defaultAction` via its [callingAction] property. + /// + /// Before forwarding the call to the override, the overridable [Action] is + /// responsible for setting [callingAction] to its `defaultAction`, which is + /// already taken care of by the overridable [Action] created using + /// [Action.overridable]. + /// + /// This property is only non-null when this [Action] is an override of the + /// [callingAction], and is currently being invoked from [callingAction]. + /// + /// Invoking [callingAction]'s methods, or accessing its properties, is + /// allowed and does not introduce infinite loops or infinite recursions. + /// + /// {@tool snippet} + /// An example `Action` that handles [PasteTextIntent] but has mostly the same + /// behavior as the overridable action. It's OK to call + /// `callingAction?.isActionEnabled` in the implementation of this `Action`. + /// + /// ```dart + /// class MyPasteAction extends Action<PasteTextIntent> { + /// @override + /// Object? invoke(PasteTextIntent intent) { + /// print(intent); + /// return callingAction?.invoke(intent); + /// } + /// + /// @override + /// bool get isActionEnabled => callingAction?.isActionEnabled ?? false; + /// + /// @override + /// bool consumesKey(PasteTextIntent intent) => callingAction?.consumesKey(intent) ?? false; + /// } + /// ``` + /// {@end-tool} + @protected + Action<T>? get callingAction => _currentCallingAction; + + /// Gets the type of intent this action responds to. + Type get intentType => T; + + /// Returns true if the action is enabled and is ready to be invoked. + /// + /// This will be called by the [ActionDispatcher] before attempting to invoke + /// the action. + /// + /// If the action's enable state depends on a [BuildContext], subclass + /// [ContextAction] instead of [Action]. + bool isEnabled(T intent) => isActionEnabled; + + bool _isEnabled(T intent, BuildContext? context) { + final Action<T> self = this; + if (self is ContextAction<T>) { + return self.isEnabled(intent, context); + } + return self.isEnabled(intent); + } + + /// Whether this [Action] is inherently enabled. + /// + /// If [isActionEnabled] is false, then this [Action] is disabled for any + /// given [Intent]. + // + /// If the enabled state changes, overriding subclasses must call + /// [notifyActionListeners] to notify any listeners of the change. + /// + /// In the case of an overridable `Action`, accessing this property creates + /// an dependency on the overridable `Action`s `lookupContext`. + bool get isActionEnabled => true; + + /// Indicates whether this action should treat key events mapped to this + /// action as being "handled" when it is invoked via the key event. + /// + /// If the key is handled, then no other key event handlers in the focus chain + /// will receive the event. + /// + /// If the key event is not handled, it will be passed back to the engine, and + /// continue to be processed there, allowing text fields and non-Flutter + /// widgets to receive the key event. + /// + /// The default implementation returns true. + bool consumesKey(T intent) => true; + + /// Converts the result of [invoke] of this action to a [KeyEventResult]. + /// + /// This is typically used when the action is invoked in response to a keyboard + /// shortcut. + /// + /// The [invokeResult] argument is the value returned by the [invoke] method. + /// + /// By default, calls [consumesKey] and converts the returned boolean to + /// [KeyEventResult.handled] if it's true, and [KeyEventResult.skipRemainingHandlers] + /// if it's false. + /// + /// Concrete implementations may refine the type of [invokeResult], since + /// they know the type returned by [invoke]. + KeyEventResult toKeyEventResult(T intent, covariant Object? invokeResult) { + return consumesKey(intent) + ? KeyEventResult.handled + : KeyEventResult.skipRemainingHandlers; + } + + /// Called when the action is to be performed. + /// + /// This is called by the [ActionDispatcher] when an action is invoked via + /// [Actions.invoke], or when an action is invoked using + /// [ActionDispatcher.invokeAction] directly. + /// + /// This method is only meant to be invoked by an [ActionDispatcher], or by + /// its subclasses, and only when [isEnabled] is true. + /// + /// When overriding this method, the returned value can be any [Object], but + /// changing the return type of the override to match the type of the returned + /// value provides more type safety. + /// + /// For instance, if an override of [invoke] returned an `int`, then it might + /// be defined like so: + /// + /// ```dart + /// class IncrementIntent extends Intent { + /// const IncrementIntent({required this.index}); + /// + /// final int index; + /// } + /// + /// class MyIncrementAction extends Action<IncrementIntent> { + /// @override + /// int invoke(IncrementIntent intent) { + /// return intent.index + 1; + /// } + /// } + /// ``` + /// + /// To receive the result of invoking an action, it must be invoked using + /// [Actions.invoke], or by invoking it using an [ActionDispatcher]. An action + /// invoked via a [Shortcuts] widget will have its return value ignored. + /// + /// If the action's behavior depends on a [BuildContext], subclass + /// [ContextAction] instead of [Action]. + @protected + Object? invoke(T intent); + + Object? _invoke(T intent, BuildContext? context) { + final Action<T> self = this; + if (self is ContextAction<T>) { + return self.invoke(intent, context); + } + return self.invoke(intent); + } + + /// Register a callback to listen for changes to the state of this action. + /// + /// If you call this, you must call [removeActionListener] a matching number + /// of times, or memory leaks will occur. To help manage this and avoid memory + /// leaks, use of the [ActionListener] widget to register and unregister your + /// listener appropriately is highly recommended. + /// + /// {@template flutter.widgets.Action.addActionListener} + /// If a listener had been added twice, and is removed once during an + /// iteration (i.e. in response to a notification), it will still be called + /// again. If, on the other hand, it is removed as many times as it was + /// registered, then it will no longer be called. This odd behavior is the + /// result of the [Action] not being able to determine which listener + /// is being removed, since they are identical, and therefore conservatively + /// still calling all the listeners when it knows that any are still + /// registered. + /// + /// This surprising behavior can be unexpectedly observed when registering a + /// listener on two separate objects which are both forwarding all + /// registrations to a common upstream object. + /// {@endtemplate} + @mustCallSuper + void addActionListener(ActionListenerCallback listener) => _listeners.add(listener); + + /// Remove a previously registered closure from the list of closures that are + /// notified when the object changes. + /// + /// If the given listener is not registered, the call is ignored. + /// + /// If you call [addActionListener], you must call this method a matching + /// number of times, or memory leaks will occur. To help manage this and avoid + /// memory leaks, use of the [ActionListener] widget to register and + /// unregister your listener appropriately is highly recommended. + /// + /// {@macro flutter.widgets.Action.addActionListener} + @mustCallSuper + void removeActionListener(ActionListenerCallback listener) => _listeners.remove(listener); + + /// Call all the registered listeners. + /// + /// Subclasses should call this method whenever the object changes, to notify + /// any clients the object may have changed. Listeners that are added during this + /// iteration will not be visited. Listeners that are removed during this + /// iteration will not be visited after they are removed. + /// + /// Exceptions thrown by listeners will be caught and reported using + /// [FlutterError.reportError]. + /// + /// Surprising behavior can result when reentrantly removing a listener (i.e. + /// in response to a notification) that has been registered multiple times. + /// See the discussion at [removeActionListener]. + @protected + @visibleForTesting + @pragma('vm:notify-debugger-on-exception') + void notifyActionListeners() { + if (_listeners.isEmpty) { + return; + } + + // Make a local copy so that a listener can unregister while the list is + // being iterated over. + final List<ActionListenerCallback> localListeners = List<ActionListenerCallback>.of(_listeners); + for (final ActionListenerCallback listener in localListeners) { + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<Action<T>>( + 'The $runtimeType sending notification was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]; + return true; + }()); + try { + if (_listeners.contains(listener)) { + listener(this); + } + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets library', + context: ErrorDescription('while dispatching notifications for $runtimeType'), + informationCollector: collector, + )); + } + } + } + + Action<T> _makeOverridableAction(BuildContext context) { + return _OverridableAction<T>(defaultAction: this, lookupContext: context); + } +} + +/// A helper widget for making sure that listeners on an action are removed properly. +/// +/// Listeners on the [Action] class must have their listener callbacks removed +/// with [Action.removeActionListener] when the listener is disposed of. This widget +/// helps with that, by providing a lifetime for the connection between the +/// [listener] and the [Action], and by handling the adding and removing of +/// the [listener] at the right points in the widget lifecycle. +/// +/// If you listen to an [Action] widget in a widget hierarchy, you should use +/// this widget. If you are using an [Action] outside of a widget context, then +/// you must call removeListener yourself. +/// +/// {@tool dartpad} +/// This example shows how ActionListener handles adding and removing of +/// the [listener] in the widget lifecycle. +/// +/// ** See code in examples/api/lib/widgets/actions/action_listener.0.dart ** +/// {@end-tool} +/// +@immutable +class ActionListener extends StatefulWidget { + /// Create a const [ActionListener]. + const ActionListener({ + super.key, + required this.listener, + required this.action, + required this.child, + }); + + /// The [ActionListenerCallback] callback to register with the [action]. + final ActionListenerCallback listener; + + /// The [Action] that the callback will be registered with. + final Action<Intent> action; + + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + State<ActionListener> createState() => _ActionListenerState(); +} + +class _ActionListenerState extends State<ActionListener> { + @override + void initState() { + super.initState(); + widget.action.addActionListener(widget.listener); + } + + @override + void didUpdateWidget(ActionListener oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.action == widget.action && oldWidget.listener == widget.listener) { + return; + } + oldWidget.action.removeActionListener(oldWidget.listener); + widget.action.addActionListener(widget.listener); + } + + @override + void dispose() { + widget.action.removeActionListener(widget.listener); + super.dispose(); + } + + @override + Widget build(BuildContext context) => widget.child; +} + +/// An abstract [Action] subclass that adds an optional [BuildContext] to the +/// [isEnabled] and [invoke] methods to be able to provide context to actions. +/// +/// [ActionDispatcher.invokeAction] checks to see if the action it is invoking +/// is a [ContextAction], and if it is, supplies it with a context. +abstract class ContextAction<T extends Intent> extends Action<T> { + /// Returns true if the action is enabled and is ready to be invoked. + /// + /// This will be called by the [ActionDispatcher] before attempting to invoke + /// the action. + /// + /// The optional `context` parameter is the context of the invocation of the + /// action, and in the case of an action invoked by a [ShortcutManager], via + /// a [Shortcuts] widget, will be the context of the [Shortcuts] widget. + @override + bool isEnabled(T intent, [BuildContext? context]) => super.isEnabled(intent); + + /// Called when the action is to be performed. + /// + /// This is called by the [ActionDispatcher] when an action is invoked via + /// [Actions.invoke], or when an action is invoked using + /// [ActionDispatcher.invokeAction] directly. + /// + /// This method is only meant to be invoked by an [ActionDispatcher], or by + /// its subclasses, and only when [isEnabled] is true. + /// + /// The optional `context` parameter is the context of the invocation of the + /// action, and in the case of an action invoked by a [ShortcutManager], via + /// a [Shortcuts] widget, will be the context of the [Shortcuts] widget. + /// + /// When overriding this method, the returned value can be any Object, but + /// changing the return type of the override to match the type of the returned + /// value provides more type safety. + /// + /// For instance, if an override of [invoke] returned an `int`, then it might + /// be defined like so: + /// + /// ```dart + /// class IncrementIntent extends Intent { + /// const IncrementIntent({required this.index}); + /// + /// final int index; + /// } + /// + /// class MyIncrementAction extends ContextAction<IncrementIntent> { + /// @override + /// int invoke(IncrementIntent intent, [BuildContext? context]) { + /// return intent.index + 1; + /// } + /// } + /// ``` + @protected + @override + Object? invoke(T intent, [BuildContext? context]); + + @override + ContextAction<T> _makeOverridableAction(BuildContext context) { + return _OverridableContextAction<T>(defaultAction: this, lookupContext: context); + } +} + +/// The signature of a callback accepted by [CallbackAction.onInvoke]. +/// +/// Such callbacks are implementations of [Action.invoke]. The returned value +/// is the return value of [Action.invoke], the argument is the intent passed +/// to [Action.invoke], and so forth. +typedef OnInvokeCallback<T extends Intent> = Object? Function(T intent); + +/// An [Action] that takes a callback in order to configure it without having to +/// create an explicit [Action] subclass just to call a callback. +/// +/// See also: +/// +/// * [Shortcuts], which is a widget that contains a key map, in which it looks +/// up key combinations in order to invoke actions. +/// * [Actions], which is a widget that defines a map of [Intent] to [Action] +/// and allows redefining of actions for its descendants. +/// * [ActionDispatcher], a class that takes an [Action] and invokes it using a +/// [FocusNode] for context. +class CallbackAction<T extends Intent> extends Action<T> { + /// A constructor for a [CallbackAction]. + /// + /// The given callback is used as the implementation of [invoke]. + CallbackAction({required this.onInvoke}); + + /// The callback to be called when invoked. + /// + /// This is effectively the implementation of [invoke]. + @protected + final OnInvokeCallback<T> onInvoke; + + @override + Object? invoke(T intent) => onInvoke(intent); +} + +/// An action dispatcher that invokes the actions given to it. +/// +/// The [invokeAction] method on this class directly calls the [Action.invoke] +/// method on the [Action] object. +/// +/// For [ContextAction] actions, if no `context` is provided, the +/// [BuildContext] of the [primaryFocus] is used instead. +/// +/// See also: +/// +/// - [ShortcutManager], that uses this class to invoke actions. +/// - [Shortcuts] widget, which defines key mappings to [Intent]s. +/// - [Actions] widget, which defines a mapping between a in [Intent] type and +/// an [Action]. +class ActionDispatcher with Diagnosticable { + /// Creates an action dispatcher that invokes actions directly. + const ActionDispatcher(); + + /// Invokes the given `action`, passing it the given `intent`. + /// + /// The action will be invoked with the given `context`, if given, but only if + /// the action is a [ContextAction] subclass. If no `context` is given, and + /// the action is a [ContextAction], then the context from the [primaryFocus] + /// is used. + /// + /// Returns the object returned from [Action.invoke]. + /// + /// The caller must receive a `true` result from [Action.isEnabled] before + /// calling this function (or [ContextAction.isEnabled] with the same + /// `context`, if the `action` is a [ContextAction]). This function will + /// assert if the action is not enabled when called. + /// + /// Consider using [invokeActionIfEnabled] to invoke the action conditionally + /// based on whether it is enabled or not, without having to check first. + Object? invokeAction( + covariant Action<Intent> action, + covariant Intent intent, [ + BuildContext? context, + ]) { + final BuildContext? target = context ?? primaryFocus?.context; + assert(action._isEnabled(intent, target), 'Action must be enabled when calling invokeAction'); + return action._invoke(intent, target); + } + + /// Invokes the given `action`, passing it the given `intent`, but only if the + /// action is enabled. + /// + /// The action will be invoked with the given `context`, if given, but only if + /// the action is a [ContextAction] subclass. If no `context` is given, and + /// the action is a [ContextAction], then the context from the [primaryFocus] + /// is used. + /// + /// The return value has two components. The first is a boolean indicating if + /// the action was enabled (as per [Action.isEnabled]). If this is false, the + /// second return value is null. Otherwise, the second return value is the + /// object returned from [Action.invoke]. + /// + /// Consider using [invokeAction] if the enabled state of the action is not in + /// question; this avoids calling [Action.isEnabled] redundantly. + (bool, Object?) invokeActionIfEnabled( + covariant Action<Intent> action, + covariant Intent intent, [ + BuildContext? context, + ]) { + final BuildContext? target = context ?? primaryFocus?.context; + if (action._isEnabled(intent, target)) { + return (true, action._invoke(intent, target)); + } + return (false, null); + } +} + +/// A widget that maps [Intent]s to [Action]s to be used by its descendants +/// when invoking an [Action]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=XawP1i314WM} +/// +/// Actions are typically invoked using [Shortcuts]. They can also be invoked +/// using [Actions.invoke] on a context containing an ambient [Actions] widget. +/// +/// {@tool dartpad} +/// This example creates a custom [Action] subclass `ModifyAction` for modifying +/// a model, and another, `SaveAction` for saving it. +/// +/// This example demonstrates passing arguments to the [Intent] to be carried to +/// the [Action]. Actions can get data either from their own construction (like +/// the `model` in this example), or from the intent passed to them when invoked +/// (like the increment `amount` in this example). +/// +/// This example also demonstrates how to use Intents to limit a widget's +/// dependencies on its surroundings. The `SaveButton` widget defined in this +/// example can invoke actions defined in its ancestor widgets, which can be +/// customized to match the part of the widget tree that it is in. It doesn't +/// need to know about the `SaveAction` class, only the `SaveIntent`, and it +/// only needs to know about a value notifier, not the entire model. +/// +/// ** See code in examples/api/lib/widgets/actions/actions.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Shortcuts], a widget used to bind key combinations to [Intent]s. +/// * [Intent], a class that contains configuration information for running an +/// [Action]. +/// * [Action], a class for containing and defining an invocation of a user +/// action. +/// * [ActionDispatcher], the object that this widget uses to manage actions. +class Actions extends StatefulWidget { + /// Creates an [Actions] widget. + const Actions({ + super.key, + this.dispatcher, + required this.actions, + required this.child, + }); + + /// The [ActionDispatcher] object that invokes actions. + /// + /// This is what is returned from [Actions.of], and used by [Actions.invoke]. + /// + /// If this [dispatcher] is null, then [Actions.of] and [Actions.invoke] will + /// look up the tree until they find an Actions widget that has a dispatcher + /// set. If no such widget is found, then they will return/use a + /// default-constructed [ActionDispatcher]. + final ActionDispatcher? dispatcher; + + /// {@template flutter.widgets.actions.actions} + /// A map of [Intent] keys to [Action<Intent>] objects that defines which + /// actions this widget knows about. + /// + /// For performance reasons, it is recommended that a pre-built map is + /// passed in here (e.g. a final variable from your widget class) instead of + /// defining it inline in the build function. + /// {@endtemplate} + final Map<Type, Action<Intent>> actions; + + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + // Visits the Actions widget ancestors of the given element using + // getElementForInheritedWidgetOfExactType. Returns true if the visitor found + // what it was looking for. + static bool _visitActionsAncestors(BuildContext context, bool Function(InheritedElement element) visitor) { + if (!context.mounted) { + return false; + } + InheritedElement? actionsElement = context.getElementForInheritedWidgetOfExactType<_ActionsScope>(); + while (actionsElement != null) { + if (visitor(actionsElement)) { + break; + } + // _getParent is needed here because + // context.getElementForInheritedWidgetOfExactType will return itself if it + // happens to be of the correct type. + final BuildContext parent = _getParent(actionsElement); + actionsElement = parent.getElementForInheritedWidgetOfExactType<_ActionsScope>(); + } + return actionsElement != null; + } + + // Finds the nearest valid ActionDispatcher, or creates a new one if it + // doesn't find one. + static ActionDispatcher _findDispatcher(BuildContext context) { + ActionDispatcher? dispatcher; + _visitActionsAncestors(context, (InheritedElement element) { + final ActionDispatcher? found = (element.widget as _ActionsScope).dispatcher; + if (found != null) { + dispatcher = found; + return true; + } + return false; + }); + return dispatcher ?? const ActionDispatcher(); + } + + /// Returns a [VoidCallback] handler that invokes the bound action for the + /// given `intent` if the action is enabled, and returns null if the action is + /// not enabled, or no matching action is found. + /// + /// This is intended to be used in widgets which have something similar to an + /// `onTap` handler, which takes a `VoidCallback`, and can be set to the + /// result of calling this function. + /// + /// Creates a dependency on the [Actions] widget that maps the bound action so + /// that if the actions change, the context will be rebuilt and find the + /// updated action. + /// + /// The value returned from the [Action.invoke] method is discarded when the + /// returned callback is called. If the return value is needed, consider using + /// [Actions.invoke] instead. + static VoidCallback? handler<T extends Intent>(BuildContext context, T intent) { + final Action<T>? action = Actions.maybeFind<T>(context); + if (action != null && action._isEnabled(intent, context)) { + return () { + // Could be that the action was enabled when the closure was created, + // but is now no longer enabled, so check again. + if (action._isEnabled(intent, context)) { + Actions.of(context).invokeAction(action, intent, context); + } + }; + } + return null; + } + + /// Finds the [Action] bound to the given intent type `T` in the given `context`. + /// + /// Creates a dependency on the [Actions] widget that maps the bound action so + /// that if the actions change, the context will be rebuilt and find the + /// updated action. + /// + /// The optional `intent` argument supplies the type of the intent to look for + /// if the concrete type of the intent sought isn't available. If not + /// supplied, then `T` is used. + /// + /// If no [Actions] widget surrounds the given context, this function will + /// assert in debug mode, and throw an exception in release mode. + /// + /// See also: + /// + /// * [maybeFind], which is similar to this function, but will return null if + /// no [Actions] ancestor is found. + static Action<T> find<T extends Intent>(BuildContext context, { T? intent }) { + final Action<T>? action = maybeFind(context, intent: intent); + + assert(() { + if (action == null) { + final Type type = intent?.runtimeType ?? T; + throw FlutterError( + 'Unable to find an action for a $type in an $Actions widget ' + 'in the given context.\n' + "$Actions.find() was called on a context that doesn't contain an " + '$Actions widget with a mapping for the given intent type.\n' + 'The context used was:\n' + ' $context\n' + 'The intent type requested was:\n' + ' $type', + ); + } + return true; + }()); + return action!; + } + + /// Finds the [Action] bound to the given intent type `T` in the given `context`. + /// + /// Creates a dependency on the [Actions] widget that maps the bound action so + /// that if the actions change, the context will be rebuilt and find the + /// updated action. + /// + /// The optional `intent` argument supplies the type of the intent to look for + /// if the concrete type of the intent sought isn't available. If not + /// supplied, then `T` is used. + /// + /// If no [Actions] widget surrounds the given context, this function will + /// return null. + /// + /// See also: + /// + /// * [find], which is similar to this function, but will throw if + /// no [Actions] ancestor is found. + static Action<T>? maybeFind<T extends Intent>(BuildContext context, { T? intent }) { + Action<T>? action; + + // Specialize the type if a runtime example instance of the intent is given. + // This allows this function to be called by code that doesn't know the + // concrete type of the intent at compile time. + final Type type = intent?.runtimeType ?? T; + assert( + type != Intent, + 'The type passed to "find" resolved to "Intent": either a non-Intent ' + 'generic type argument or an example intent derived from Intent must be ' + 'specified. Intent may be used as the generic type as long as the optional ' + '"intent" argument is passed.', + ); + + _visitActionsAncestors(context, (InheritedElement element) { + final _ActionsScope actions = element.widget as _ActionsScope; + final Action<T>? result = _castAction(actions, intent: intent); + if (result != null) { + context.dependOnInheritedElement(element); + action = result; + return true; + } + return false; + }); + + return action; + } + + static Action<T>? _maybeFindWithoutDependingOn<T extends Intent>(BuildContext context, { T? intent }) { + Action<T>? action; + + // Specialize the type if a runtime example instance of the intent is given. + // This allows this function to be called by code that doesn't know the + // concrete type of the intent at compile time. + final Type type = intent?.runtimeType ?? T; + assert( + type != Intent, + 'The type passed to "find" resolved to "Intent": either a non-Intent ' + 'generic type argument or an example intent derived from Intent must be ' + 'specified. Intent may be used as the generic type as long as the optional ' + '"intent" argument is passed.', + ); + + _visitActionsAncestors(context, (InheritedElement element) { + final _ActionsScope actions = element.widget as _ActionsScope; + final Action<T>? result = _castAction(actions, intent: intent); + if (result != null) { + action = result; + return true; + } + return false; + }); + + return action; + } + + // Find the [Action] that handles the given `intent` in the given + // `_ActionsScope`, and verify it has the right type parameter. + static Action<T>? _castAction<T extends Intent>(_ActionsScope actionsMarker, { T? intent }) { + final Action<Intent>? mappedAction = actionsMarker.actions[intent?.runtimeType ?? T]; + if (mappedAction is Action<T>?) { + return mappedAction; + } else { + assert( + false, + '$T cannot be handled by an Action of runtime type ${mappedAction.runtimeType}.' + ); + return null; + } + } + + /// Returns the [ActionDispatcher] associated with the [Actions] widget that + /// most tightly encloses the given [BuildContext]. + /// + /// Will return a newly created [ActionDispatcher] if no ambient [Actions] + /// widget is found. + static ActionDispatcher of(BuildContext context) { + final _ActionsScope? marker = context.dependOnInheritedWidgetOfExactType<_ActionsScope>(); + return marker?.dispatcher ?? _findDispatcher(context); + } + + /// Invokes the action associated with the given [Intent] using the + /// [Actions] widget that most tightly encloses the given [BuildContext]. + /// + /// This method returns the result of invoking the action's [Action.invoke] + /// method. + /// + /// If the given `intent` doesn't map to an action, then it will look to the + /// next ancestor [Actions] widget in the hierarchy until it reaches the root. + /// + /// This method will throw an exception if no ambient [Actions] widget is + /// found, or when a suitable [Action] is found but it returns false for + /// [Action.isEnabled]. + static Object? invoke<T extends Intent>( + BuildContext context, + T intent, + ) { + Object? returnValue; + + final bool actionFound = _visitActionsAncestors(context, (InheritedElement element) { + final _ActionsScope actions = element.widget as _ActionsScope; + final Action<T>? result = _castAction(actions, intent: intent); + if (result != null && result._isEnabled(intent, context)) { + // Invoke the action we found using the relevant dispatcher from the Actions + // Element we found. + returnValue = _findDispatcher(element).invokeAction(result, intent, context); + } + return result != null; + }); + + assert(() { + if (!actionFound) { + throw FlutterError( + 'Unable to find an action for an Intent with type ' + '${intent.runtimeType} in an $Actions widget in the given context.\n' + '$Actions.invoke() was unable to find an $Actions widget that ' + "contained a mapping for the given intent, or the intent type isn't the " + 'same as the type argument to invoke (which is $T - try supplying a ' + 'type argument to invoke if one was not given)\n' + 'The context used was:\n' + ' $context\n' + 'The intent type requested was:\n' + ' ${intent.runtimeType}', + ); + } + return true; + }()); + return returnValue; + } + + /// Invokes the action associated with the given [Intent] using the + /// [Actions] widget that most tightly encloses the given [BuildContext]. + /// + /// This method returns the result of invoking the action's [Action.invoke] + /// method. If no action mapping was found for the specified intent, or if the + /// first action found was disabled, or the action itself returns null + /// from [Action.invoke], then this method returns null. + /// + /// If the given `intent` doesn't map to an action, then it will look to the + /// next ancestor [Actions] widget in the hierarchy until it reaches the root. + /// If a suitable [Action] is found but its [Action.isEnabled] returns false, + /// the search will stop and this method will return null. + static Object? maybeInvoke<T extends Intent>( + BuildContext context, + T intent, + ) { + Object? returnValue; + _visitActionsAncestors(context, (InheritedElement element) { + final _ActionsScope actions = element.widget as _ActionsScope; + final Action<T>? result = _castAction(actions, intent: intent); + if (result != null && result._isEnabled(intent, context)) { + // Invoke the action we found using the relevant dispatcher from the Actions + // element we found. + returnValue = _findDispatcher(element).invokeAction(result, intent, context); + } + return result != null; + }); + return returnValue; + } + + @override + State<Actions> createState() => _ActionsState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ActionDispatcher>('dispatcher', dispatcher)); + properties.add(DiagnosticsProperty<Map<Type, Action<Intent>>>('actions', actions)); + } +} + +class _ActionsState extends State<Actions> { + // The set of actions that this Actions widget is current listening to. + Set<Action<Intent>>? listenedActions = <Action<Intent>>{}; + // Used to tell the marker to rebuild its dependencies when the state of an + // action in the map changes. + Object rebuildKey = Object(); + + @override + void initState() { + super.initState(); + _updateActionListeners(); + } + + void _handleActionChanged(Action<Intent> action) { + // Generate a new key so that the marker notifies dependents. + setState(() { + rebuildKey = Object(); + }); + } + + void _updateActionListeners() { + final Set<Action<Intent>> widgetActions = widget.actions.values.toSet(); + final Set<Action<Intent>> removedActions = listenedActions!.difference(widgetActions); + final Set<Action<Intent>> addedActions = widgetActions.difference(listenedActions!); + + for (final Action<Intent> action in removedActions) { + action.removeActionListener(_handleActionChanged); + } + for (final Action<Intent> action in addedActions) { + action.addActionListener(_handleActionChanged); + } + listenedActions = widgetActions; + } + + @override + void didUpdateWidget(Actions oldWidget) { + super.didUpdateWidget(oldWidget); + _updateActionListeners(); + } + + @override + void dispose() { + super.dispose(); + for (final Action<Intent> action in listenedActions!) { + action.removeActionListener(_handleActionChanged); + } + listenedActions = null; + } + + @override + Widget build(BuildContext context) { + return _ActionsScope( + actions: widget.actions, + dispatcher: widget.dispatcher, + rebuildKey: rebuildKey, + child: widget.child, + ); + } +} + +// An inherited widget used by Actions widget for fast lookup of the Actions +// widget information. +class _ActionsScope extends InheritedWidget { + const _ActionsScope({ + required this.dispatcher, + required this.actions, + required this.rebuildKey, + required super.child, + }); + + final ActionDispatcher? dispatcher; + final Map<Type, Action<Intent>> actions; + final Object rebuildKey; + + @override + bool updateShouldNotify(_ActionsScope oldWidget) { + return rebuildKey != oldWidget.rebuildKey + || oldWidget.dispatcher != dispatcher + || !mapEquals<Type, Action<Intent>>(oldWidget.actions, actions); + } +} + +/// A widget that combines the functionality of [Actions], [Shortcuts], +/// [MouseRegion] and a [Focus] widget to create a detector that defines actions +/// and key bindings, and provides callbacks for handling focus and hover +/// highlights. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=R84AGg0lKs8} +/// +/// This widget can be used to give a control the required detection modes for +/// focus and hover handling. It is most often used when authoring a new control +/// widget, and the new control should be enabled for keyboard traversal and +/// activation. +/// +/// {@tool dartpad} +/// This example shows how keyboard interaction can be added to a custom control +/// that changes color when hovered and focused, and can toggle a light when +/// activated, either by touch or by hitting the `X` key on the keyboard when +/// the "And Me" button has the keyboard focus (be sure to use TAB to move the +/// focus to the "And Me" button before trying it out). +/// +/// This example defines its own key binding for the `X` key, but in this case, +/// there is also a default key binding for [ActivateAction] in the default key +/// bindings created by [WidgetsApp] (the parent for [MaterialApp], and +/// [CupertinoApp]), so the `ENTER` key will also activate the buttons. +/// +/// ** See code in examples/api/lib/widgets/actions/focusable_action_detector.0.dart ** +/// {@end-tool} +/// +/// This widget doesn't have any visual representation, it is just a detector that +/// provides focus and hover capabilities. +/// +/// It hosts its own [FocusNode] or uses [focusNode], if given. +class FocusableActionDetector extends StatefulWidget { + /// Create a const [FocusableActionDetector]. + const FocusableActionDetector({ + super.key, + this.enabled = true, + this.focusNode, + this.autofocus = false, + this.descendantsAreFocusable = true, + this.descendantsAreTraversable = true, + this.shortcuts, + this.actions, + this.onShowFocusHighlight, + this.onShowHoverHighlight, + this.onFocusChange, + this.mouseCursor = MouseCursor.defer, + this.includeFocusSemantics = true, + required this.child, + }); + + /// Is this widget enabled or not. + /// + /// If disabled, will not send any notifications needed to update highlight or + /// focus state, and will not define or respond to any actions or shortcuts. + /// + /// When disabled, adds [Focus] to the widget tree, but sets + /// [Focus.canRequestFocus] to false. + final bool enabled; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode? focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@macro flutter.widgets.Focus.descendantsAreFocusable} + final bool descendantsAreFocusable; + + /// {@macro flutter.widgets.Focus.descendantsAreTraversable} + final bool descendantsAreTraversable; + + /// {@macro flutter.widgets.actions.actions} + final Map<Type, Action<Intent>>? actions; + + /// {@macro flutter.widgets.shortcuts.shortcuts} + final Map<ShortcutActivator, Intent>? shortcuts; + + /// A function that will be called when the focus highlight should be shown or + /// hidden. + /// + /// This method is not triggered at the unmount of the widget. + final ValueChanged<bool>? onShowFocusHighlight; + + /// A function that will be called when the hover highlight should be shown or hidden. + /// + /// This method is not triggered at the unmount of the widget. + final ValueChanged<bool>? onShowHoverHighlight; + + /// A function that will be called when the focus changes. + /// + /// Called with true if the [focusNode] has primary focus. + final ValueChanged<bool>? onFocusChange; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// The [mouseCursor] defaults to [MouseCursor.defer], deferring the choice of + /// cursor to the next region behind it in hit-test order. + final MouseCursor mouseCursor; + + /// Whether to include semantics from [Focus]. + /// + /// Defaults to true. + final bool includeFocusSemantics; + + /// The child widget for this [FocusableActionDetector] widget. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + State<FocusableActionDetector> createState() => _FocusableActionDetectorState(); +} + +class _FocusableActionDetectorState extends State<FocusableActionDetector> { + @override + void initState() { + super.initState(); + SchedulerBinding.instance.addPostFrameCallback((Duration duration) { + _updateHighlightMode(FocusManager.instance.highlightMode); + }, debugLabel: 'FocusableActionDetector.updateHighlightMode'); + FocusManager.instance.addHighlightModeListener(_handleFocusHighlightModeChange); + } + + @override + void dispose() { + FocusManager.instance.removeHighlightModeListener(_handleFocusHighlightModeChange); + super.dispose(); + } + + bool _canShowHighlight = false; + void _updateHighlightMode(FocusHighlightMode mode) { + _mayTriggerCallback(task: () { + switch (FocusManager.instance.highlightMode) { + case FocusHighlightMode.touch: + _canShowHighlight = false; + case FocusHighlightMode.traditional: + _canShowHighlight = true; + } + }); + } + + // Have to have this separate from the _updateHighlightMode because it gets + // called in initState, where things aren't mounted yet. + // Since this method is a highlight mode listener, it is only called + // immediately following pointer events. + void _handleFocusHighlightModeChange(FocusHighlightMode mode) { + if (!mounted) { + return; + } + _updateHighlightMode(mode); + } + + bool _hovering = false; + void _handleMouseEnter(PointerEnterEvent event) { + if (!_hovering) { + _mayTriggerCallback(task: () { + _hovering = true; + }); + } + } + + void _handleMouseExit(PointerExitEvent event) { + if (_hovering) { + _mayTriggerCallback(task: () { + _hovering = false; + }); + } + } + + bool _focused = false; + void _handleFocusChange(bool focused) { + if (_focused != focused) { + _mayTriggerCallback(task: () { + _focused = focused; + }); + widget.onFocusChange?.call(_focused); + } + } + + // Record old states, do `task` if not null, then compare old states with the + // new states, and trigger callbacks if necessary. + // + // The old states are collected from `oldWidget` if it is provided, or the + // current widget (before doing `task`) otherwise. The new states are always + // collected from the current widget. + void _mayTriggerCallback({VoidCallback? task, FocusableActionDetector? oldWidget}) { + bool shouldShowHoverHighlight(FocusableActionDetector target) { + return _hovering && target.enabled && _canShowHighlight; + } + + bool canRequestFocus(FocusableActionDetector target) { + final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional; + switch (mode) { + case NavigationMode.traditional: + return target.enabled; + case NavigationMode.directional: + return true; + } + } + + bool shouldShowFocusHighlight(FocusableActionDetector target) { + return _focused && _canShowHighlight && canRequestFocus(target); + } + + assert(SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks); + final FocusableActionDetector oldTarget = oldWidget ?? widget; + final bool didShowHoverHighlight = shouldShowHoverHighlight(oldTarget); + final bool didShowFocusHighlight = shouldShowFocusHighlight(oldTarget); + if (task != null) { + task(); + } + final bool doShowHoverHighlight = shouldShowHoverHighlight(widget); + final bool doShowFocusHighlight = shouldShowFocusHighlight(widget); + if (didShowFocusHighlight != doShowFocusHighlight) { + widget.onShowFocusHighlight?.call(doShowFocusHighlight); + } + if (didShowHoverHighlight != doShowHoverHighlight) { + widget.onShowHoverHighlight?.call(doShowHoverHighlight); + } + } + + @override + void didUpdateWidget(FocusableActionDetector oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.enabled != oldWidget.enabled) { + SchedulerBinding.instance.addPostFrameCallback((Duration duration) { + _mayTriggerCallback(oldWidget: oldWidget); + }, debugLabel: 'FocusableActionDetector.mayTriggerCallback'); + } + } + + bool get _canRequestFocus { + final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional; + switch (mode) { + case NavigationMode.traditional: + return widget.enabled; + case NavigationMode.directional: + return true; + } + } + + // This global key is needed to keep only the necessary widgets in the tree + // while maintaining the subtree's state. + // + // See https://github.com/flutter/flutter/issues/64058 for an explanation of + // why using a global key over keeping the shape of the tree. + final GlobalKey _mouseRegionKey = GlobalKey(); + + @override + Widget build(BuildContext context) { + Widget child = MouseRegion( + key: _mouseRegionKey, + onEnter: _handleMouseEnter, + onExit: _handleMouseExit, + cursor: widget.mouseCursor, + child: Focus( + focusNode: widget.focusNode, + autofocus: widget.autofocus, + descendantsAreFocusable: widget.descendantsAreFocusable, + descendantsAreTraversable: widget.descendantsAreTraversable, + canRequestFocus: _canRequestFocus, + onFocusChange: _handleFocusChange, + includeSemantics: widget.includeFocusSemantics, + child: widget.child, + ), + ); + if (widget.enabled && widget.actions != null && widget.actions!.isNotEmpty) { + child = Actions(actions: widget.actions!, child: child); + } + if (widget.enabled && widget.shortcuts != null && widget.shortcuts!.isNotEmpty) { + child = Shortcuts(shortcuts: widget.shortcuts!, child: child); + } + return child; + } +} + +/// An [Intent] that keeps a [VoidCallback] to be invoked by a +/// [VoidCallbackAction] when it receives this intent. +class VoidCallbackIntent extends Intent { + /// Creates a [VoidCallbackIntent]. + const VoidCallbackIntent(this.callback); + + /// The callback that is to be called by the [VoidCallbackAction] that + /// receives this intent. + final VoidCallback callback; +} + +/// An [Action] that invokes the [VoidCallback] given to it in the +/// [VoidCallbackIntent] passed to it when invoked. +/// +/// See also: +/// +/// * [CallbackAction], which is an action that will invoke a callback with the +/// intent passed to the action's invoke method. The callback is configured +/// on the action, not the intent, like this class. +class VoidCallbackAction extends Action<VoidCallbackIntent> { + @override + Object? invoke(VoidCallbackIntent intent) { + intent.callback(); + return null; + } +} + +/// An [Intent] that is bound to a [DoNothingAction]. +/// +/// Attaching a [DoNothingIntent] to a [Shortcuts] mapping is one way to disable +/// a keyboard shortcut defined by a widget higher in the widget hierarchy and +/// consume any key event that triggers it via a shortcut. +/// +/// This intent cannot be subclassed. +/// +/// See also: +/// +/// * [DoNothingAndStopPropagationIntent], a similar intent that will not +/// handle the key event, but will still keep it from being passed to other key +/// handlers in the focus chain. +class DoNothingIntent extends Intent { + /// Creates a const [DoNothingIntent]. + const factory DoNothingIntent() = DoNothingIntent._; + + // Make DoNothingIntent constructor private so it can't be subclassed. + const DoNothingIntent._(); +} + +/// An [Intent] that is bound to a [DoNothingAction], but, in addition to not +/// performing an action, also stops the propagation of the key event bound to +/// this intent to other key event handlers in the focus chain. +/// +/// Attaching a [DoNothingAndStopPropagationIntent] to a [Shortcuts.shortcuts] +/// mapping is one way to disable a keyboard shortcut defined by a widget higher +/// in the widget hierarchy. In addition, the bound [DoNothingAction] will +/// return false from [DoNothingAction.consumesKey], causing the key bound to +/// this intent to be passed on to the platform embedding as "not handled" with +/// out passing it to other key handlers in the focus chain (e.g. parent +/// `Shortcuts` widgets higher up in the chain). +/// +/// This intent cannot be subclassed. +/// +/// See also: +/// +/// * [DoNothingIntent], a similar intent that will handle the key event. +class DoNothingAndStopPropagationIntent extends Intent { + /// Creates a const [DoNothingAndStopPropagationIntent]. + const factory DoNothingAndStopPropagationIntent() = DoNothingAndStopPropagationIntent._; + + // Make DoNothingAndStopPropagationIntent constructor private so it can't be subclassed. + const DoNothingAndStopPropagationIntent._(); +} + +/// An [Action] that doesn't perform any action when invoked. +/// +/// Attaching a [DoNothingAction] to an [Actions.actions] mapping is a way to +/// disable an action defined by a widget higher in the widget hierarchy. +/// +/// If [consumesKey] returns false, then not only will this action do nothing, +/// but it will stop the propagation of the key event used to trigger it to +/// other widgets in the focus chain and tell the embedding that the key wasn't +/// handled, allowing text input fields or other non-Flutter elements to receive +/// that key event. The return value of [consumesKey] can be set via the +/// `consumesKey` argument to the constructor. +/// +/// This action can be bound to any [Intent]. +/// +/// See also: +/// - [DoNothingIntent], which is an intent that can be bound to a [KeySet] in +/// a [Shortcuts] widget to do nothing. +/// - [DoNothingAndStopPropagationIntent], which is an intent that can be bound +/// to a [KeySet] in a [Shortcuts] widget to do nothing and also stop key event +/// propagation to other key handlers in the focus chain. +class DoNothingAction extends Action<Intent> { + /// Creates a [DoNothingAction]. + /// + /// The optional [consumesKey] argument defaults to true. + DoNothingAction({bool consumesKey = true}) : _consumesKey = consumesKey; + + @override + bool consumesKey(Intent intent) => _consumesKey; + final bool _consumesKey; + + @override + void invoke(Intent intent) {} +} + +/// An [Intent] that activates the currently focused control. +/// +/// This intent is bound by default to the [LogicalKeyboardKey.space] key on all +/// platforms, and also to the [LogicalKeyboardKey.enter] key on all platforms +/// except the web, where ENTER doesn't toggle selection. On the web, ENTER is +/// bound to [ButtonActivateIntent] instead. +/// +/// See also: +/// +/// * [WidgetsApp.defaultShortcuts], which contains the default shortcuts used +/// in apps. +/// * [WidgetsApp.shortcuts], which defines the shortcuts to use in an +/// application (and defaults to [WidgetsApp.defaultShortcuts]). +class ActivateIntent extends Intent { + /// Creates an intent that activates the currently focused control. + const ActivateIntent(); +} + +/// An [Intent] that activates the currently focused button. +/// +/// This intent is bound by default to the [LogicalKeyboardKey.enter] key on the +/// web, where ENTER can be used to activate buttons, but not toggle selection. +/// All other platforms bind [LogicalKeyboardKey.enter] to [ActivateIntent]. +/// +/// See also: +/// +/// * [WidgetsApp.defaultShortcuts], which contains the default shortcuts used +/// in apps. +/// * [WidgetsApp.shortcuts], which defines the shortcuts to use in an +/// application (and defaults to [WidgetsApp.defaultShortcuts]). +class ButtonActivateIntent extends Intent { + /// Creates an intent that activates the currently focused control, + /// if it's a button. + const ButtonActivateIntent(); +} + +/// An [Action] that activates the currently focused control. +/// +/// This is an abstract class that serves as a base class for actions that +/// activate a control. By default, is bound to [LogicalKeyboardKey.enter], +/// [LogicalKeyboardKey.gameButtonA], and [LogicalKeyboardKey.space] in the +/// default keyboard map in [WidgetsApp]. +abstract class ActivateAction extends Action<ActivateIntent> { } + +/// An [Intent] that selects the currently focused control. +class SelectIntent extends Intent { + /// Creates an intent that selects the currently focused control. + const SelectIntent(); +} + +/// An action that selects the currently focused control. +/// +/// This is an abstract class that serves as a base class for actions that +/// select something. It is not bound to any key by default. +abstract class SelectAction extends Action<SelectIntent> { } + +/// An [Intent] that dismisses the currently focused widget. +/// +/// The [WidgetsApp.defaultShortcuts] binds this intent to the +/// [LogicalKeyboardKey.escape] and [LogicalKeyboardKey.gameButtonB] keys. +/// +/// See also: +/// - [ModalRoute] which listens for this intent to dismiss modal routes +/// (dialogs, pop-up menus, drawers, etc). +class DismissIntent extends Intent { + /// Creates an intent that dismisses the currently focused widget. + const DismissIntent(); +} + +/// An [Action] that dismisses the focused widget. +/// +/// This is an abstract class that serves as a base class for dismiss actions. +abstract class DismissAction extends Action<DismissIntent> { } + +/// An [Intent] that evaluates a series of specified [orderedIntents] for +/// execution. +/// +/// The first intent that matches an enabled action is used. +class PrioritizedIntents extends Intent { + /// Creates an intent that is used with [PrioritizedAction] to specify a list + /// of intents, the first available of which will be used. + const PrioritizedIntents({ + required this.orderedIntents, + }); + + /// List of intents to be evaluated in order for execution. When an + /// [Action.isEnabled] returns true, that action will be invoked and + /// progression through the ordered intents stops. + final List<Intent> orderedIntents; +} + +/// An [Action] that iterates through a list of [Intent]s, invoking the first +/// that is enabled. +/// +/// The [isEnabled] method must be called before [invoke]. Calling [isEnabled] +/// configures the object by seeking the first intent with an enabled action. +/// If the actions have an opportunity to change enabled state, [isEnabled] +/// must be called again before calling [invoke]. +class PrioritizedAction extends ContextAction<PrioritizedIntents> { + late Action<dynamic> _selectedAction; + late Intent _selectedIntent; + + @override + bool isEnabled(PrioritizedIntents intent, [ BuildContext? context ]) { + final FocusNode? focus = primaryFocus; + if (focus == null || focus.context == null) { + return false; + } + for (final Intent candidateIntent in intent.orderedIntents) { + final Action<Intent>? candidateAction = Actions.maybeFind<Intent>( + focus.context!, + intent: candidateIntent, + ); + if (candidateAction != null && candidateAction._isEnabled(candidateIntent, context)) { + _selectedAction = candidateAction; + _selectedIntent = candidateIntent; + return true; + } + } + return false; + } + + @override + void invoke(PrioritizedIntents intent, [ BuildContext? context ]) { + _selectedAction._invoke(_selectedIntent, context); + } +} + +mixin _OverridableActionMixin<T extends Intent> on Action<T> { + // When debugAssertMutuallyRecursive is true, this action will throw an + // assertion error when the override calls this action's "invoke" method and + // the override is already being invoked from within the "invoke" method. + bool debugAssertMutuallyRecursive = false; + bool debugAssertIsActionEnabledMutuallyRecursive = false; + bool debugAssertIsEnabledMutuallyRecursive = false; + bool debugAssertConsumeKeyMutuallyRecursive = false; + + // The default action to invoke if an enabled override Action can't be found + // using [lookupContext]. + Action<T> get defaultAction; + + // The [BuildContext] used to find the override of this [Action]. + BuildContext get lookupContext; + + // How to invoke [defaultAction], given the caller [fromAction]. + Object? invokeDefaultAction(T intent, Action<T>? fromAction, BuildContext? context); + + Action<T>? getOverrideAction({ bool declareDependency = false }) { + final Action<T>? override = declareDependency + ? Actions.maybeFind(lookupContext) + : Actions._maybeFindWithoutDependingOn(lookupContext); + assert(!identical(override, this)); + return override; + } + + @override + void _updateCallingAction(Action<T>? value) { + super._updateCallingAction(value); + defaultAction._updateCallingAction(value); + } + + Object? _invokeOverride(Action<T> overrideAction, T intent, BuildContext? context) { + assert(!debugAssertMutuallyRecursive); + assert(() { + debugAssertMutuallyRecursive = true; + return true; + }()); + overrideAction._updateCallingAction(defaultAction); + final Object? returnValue = overrideAction._invoke(intent, context); + overrideAction._updateCallingAction(null); + assert(() { + debugAssertMutuallyRecursive = false; + return true; + }()); + return returnValue; + } + + @override + Object? invoke(T intent, [BuildContext? context]) { + final Action<T>? overrideAction = getOverrideAction(); + final Object? returnValue = overrideAction == null + ? invokeDefaultAction(intent, callingAction, context) + : _invokeOverride(overrideAction, intent, context); + return returnValue; + } + + bool isOverrideActionEnabled(Action<T> overrideAction) { + assert(!debugAssertIsActionEnabledMutuallyRecursive); + assert(() { + debugAssertIsActionEnabledMutuallyRecursive = true; + return true; + }()); + overrideAction._updateCallingAction(defaultAction); + final bool isOverrideEnabled = overrideAction.isActionEnabled; + overrideAction._updateCallingAction(null); + assert(() { + debugAssertIsActionEnabledMutuallyRecursive = false; + return true; + }()); + return isOverrideEnabled; + } + + @override + bool get isActionEnabled { + final Action<T>? overrideAction = getOverrideAction(declareDependency: true); + final bool returnValue = overrideAction != null + ? isOverrideActionEnabled(overrideAction) + : defaultAction.isActionEnabled; + return returnValue; + } + + @override + bool isEnabled(T intent, [BuildContext? context]) { + assert(!debugAssertIsEnabledMutuallyRecursive); + assert(() { + debugAssertIsEnabledMutuallyRecursive = true; + return true; + }()); + + final Action<T>? overrideAction = getOverrideAction(); + overrideAction?._updateCallingAction(defaultAction); + final bool returnValue = (overrideAction ?? defaultAction)._isEnabled(intent, context); + overrideAction?._updateCallingAction(null); + assert(() { + debugAssertIsEnabledMutuallyRecursive = false; + return true; + }()); + return returnValue; + } + + @override + bool consumesKey(T intent) { + assert(!debugAssertConsumeKeyMutuallyRecursive); + assert(() { + debugAssertConsumeKeyMutuallyRecursive = true; + return true; + }()); + final Action<T>? overrideAction = getOverrideAction(); + overrideAction?._updateCallingAction(defaultAction); + final bool isEnabled = (overrideAction ?? defaultAction).consumesKey(intent); + overrideAction?._updateCallingAction(null); + assert(() { + debugAssertConsumeKeyMutuallyRecursive = false; + return true; + }()); + return isEnabled; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Action<T>>('defaultAction', defaultAction)); + } +} + +class _OverridableAction<T extends Intent> extends ContextAction<T> with _OverridableActionMixin<T> { + _OverridableAction({ required this.defaultAction, required this.lookupContext }) ; + + @override + final Action<T> defaultAction; + + @override + final BuildContext lookupContext; + + @override + Object? invokeDefaultAction(T intent, Action<T>? fromAction, BuildContext? context) { + if (fromAction == null) { + return defaultAction.invoke(intent); + } else { + final Object? returnValue = defaultAction.invoke(intent); + return returnValue; + } + } + + @override + ContextAction<T> _makeOverridableAction(BuildContext context) { + return _OverridableAction<T>(defaultAction: defaultAction, lookupContext: context); + } +} + +class _OverridableContextAction<T extends Intent> extends ContextAction<T> with _OverridableActionMixin<T> { + _OverridableContextAction({ required this.defaultAction, required this.lookupContext }); + + @override + final ContextAction<T> defaultAction; + + @override + final BuildContext lookupContext; + + @override + Object? _invokeOverride(Action<T> overrideAction, T intent, BuildContext? context) { + assert(context != null); + assert(!debugAssertMutuallyRecursive); + assert(() { + debugAssertMutuallyRecursive = true; + return true; + }()); + + // Wrap the default Action together with the calling context in case + // overrideAction is not a ContextAction and thus have no access to the + // calling BuildContext. + final Action<T> wrappedDefault = _ContextActionToActionAdapter<T>(invokeContext: context!, action: defaultAction); + overrideAction._updateCallingAction(wrappedDefault); + final Object? returnValue = overrideAction._invoke(intent, context); + overrideAction._updateCallingAction(null); + + assert(() { + debugAssertMutuallyRecursive = false; + return true; + }()); + return returnValue; + } + + @override + Object? invokeDefaultAction(T intent, Action<T>? fromAction, BuildContext? context) { + if (fromAction == null) { + return defaultAction.invoke(intent, context); + } else { + final Object? returnValue = defaultAction.invoke(intent, context); + return returnValue; + } + } + + @override + ContextAction<T> _makeOverridableAction(BuildContext context) { + return _OverridableContextAction<T>(defaultAction: defaultAction, lookupContext: context); + } +} + +class _ContextActionToActionAdapter<T extends Intent> extends Action<T> { + _ContextActionToActionAdapter({required this.invokeContext, required this.action}); + + final BuildContext invokeContext; + final ContextAction<T> action; + + @override + void _updateCallingAction(Action<T>? value) { + action._updateCallingAction(value); + } + + @override + Action<T>? get callingAction => action.callingAction; + + @override + bool isEnabled(T intent) => action.isEnabled(intent, invokeContext); + + @override + bool get isActionEnabled => action.isActionEnabled; + + @override + bool consumesKey(T intent) => action.consumesKey(intent); + + @override + void addActionListener(ActionListenerCallback listener) { + super.addActionListener(listener); + action.addActionListener(listener); + } + + @override + void removeActionListener(ActionListenerCallback listener) { + super.removeActionListener(listener); + action.removeActionListener(listener); + } + + @override + @protected + void notifyActionListeners() => action.notifyActionListeners(); + + @override + Object? invoke(T intent) => action.invoke(intent, invokeContext); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/adapter.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/adapter.dart new file mode 100644 index 0000000000000000000000000000000000000000..1948312f7de4150051a6863ba0643bb617e5d3b8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/adapter.dart @@ -0,0 +1,177 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; + +/// A bridge from a [RenderObject] to an [Element] tree. +/// +/// The given container is the [RenderObject] that the [Element] tree should be +/// inserted into. It must be a [RenderObject] that implements the +/// [RenderObjectWithChildMixin] protocol. The type argument `T` is the kind of +/// [RenderObject] that the container expects as its child. +/// +/// The [RenderObjectToWidgetAdapter] is an alternative to [RootWidget] for +/// bootstrapping an element tree. Unlike [RootWidget] it requires the +/// existence of a render tree (the [container]) to attach the element tree to. +class RenderObjectToWidgetAdapter<T extends RenderObject> extends RenderObjectWidget { + /// Creates a bridge from a [RenderObject] to an [Element] tree. + RenderObjectToWidgetAdapter({ + this.child, + required this.container, + this.debugShortDescription, + }) : super(key: GlobalObjectKey(container)); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The [RenderObject] that is the parent of the [Element] created by this widget. + final RenderObjectWithChildMixin<T> container; + + /// A short description of this widget used by debugging aids. + final String? debugShortDescription; + + @override + RenderObjectToWidgetElement<T> createElement() => RenderObjectToWidgetElement<T>(this); + + @override + RenderObjectWithChildMixin<T> createRenderObject(BuildContext context) => container; + + @override + void updateRenderObject(BuildContext context, RenderObject renderObject) { } + + /// Inflate this widget and actually set the resulting [RenderObject] as the + /// child of [container]. + /// + /// If `element` is null, this function will create a new element. Otherwise, + /// the given element will have an update scheduled to switch to this widget. + RenderObjectToWidgetElement<T> attachToRenderTree(BuildOwner owner, [ RenderObjectToWidgetElement<T>? element ]) { + if (element == null) { + owner.lockState(() { + element = createElement(); + assert(element != null); + element!.assignOwner(owner); + }); + owner.buildScope(element!, () { + element!.mount(null, null); + }); + } else { + element._newWidget = this; + element.markNeedsBuild(); + } + return element!; + } + + @override + String toStringShort() => debugShortDescription ?? super.toStringShort(); +} + +/// The root of an element tree that is hosted by a [RenderObject]. +/// +/// This element class is the instantiation of a [RenderObjectToWidgetAdapter] +/// widget. It can be used only as the root of an [Element] tree (it cannot be +/// mounted into another [Element]; it's parent must be null). +/// +/// In typical usage, it will be instantiated for a [RenderObjectToWidgetAdapter] +/// whose container is the [RenderView]. +class RenderObjectToWidgetElement<T extends RenderObject> extends RenderTreeRootElement with RootElementMixin { + /// Creates an element that is hosted by a [RenderObject]. + /// + /// The [RenderObject] created by this element is not automatically set as a + /// child of the hosting [RenderObject]. To actually attach this element to + /// the render tree, call [RenderObjectToWidgetAdapter.attachToRenderTree]. + RenderObjectToWidgetElement(RenderObjectToWidgetAdapter<T> super.widget); + + Element? _child; + + static const Object _rootChildSlot = Object(); + + @override + void visitChildren(ElementVisitor visitor) { + if (_child != null) { + visitor(_child!); + } + } + + @override + void forgetChild(Element child) { + assert(child == _child); + _child = null; + super.forgetChild(child); + } + + @override + void mount(Element? parent, Object? newSlot) { + assert(parent == null); + super.mount(parent, newSlot); + _rebuild(); + assert(_child != null); + } + + @override + void update(RenderObjectToWidgetAdapter<T> newWidget) { + super.update(newWidget); + assert(widget == newWidget); + _rebuild(); + } + + // When we are assigned a new widget, we store it here + // until we are ready to update to it. + Widget? _newWidget; + + @override + void performRebuild() { + if (_newWidget != null) { + // _newWidget can be null if, for instance, we were rebuilt + // due to a reassemble. + final Widget newWidget = _newWidget!; + _newWidget = null; + update(newWidget as RenderObjectToWidgetAdapter<T>); + } + super.performRebuild(); + assert(_newWidget == null); + } + + @pragma('vm:notify-debugger-on-exception') + void _rebuild() { + try { + _child = updateChild(_child, (widget as RenderObjectToWidgetAdapter<T>).child, _rootChildSlot); + } catch (exception, stack) { + final FlutterErrorDetails details = FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets library', + context: ErrorDescription('attaching to the render tree'), + ); + FlutterError.reportError(details); + final Widget error = ErrorWidget.builder(details); + _child = updateChild(null, error, _rootChildSlot); + } + } + + @override + RenderObjectWithChildMixin<T> get renderObject => super.renderObject as RenderObjectWithChildMixin<T>; + + @override + void insertRenderObjectChild(RenderObject child, Object? slot) { + assert(slot == _rootChildSlot); + assert(renderObject.debugValidateChild(child)); + renderObject.child = child as T; + } + + @override + void moveRenderObjectChild(RenderObject child, Object? oldSlot, Object? newSlot) { + assert(false); + } + + @override + void removeRenderObjectChild(RenderObject child, Object? slot) { + assert(renderObject.child == child); + renderObject.child = null; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart new file mode 100644 index 0000000000000000000000000000000000000000..116d61bc3fee147d4559f96f99145213c9ad900b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart @@ -0,0 +1,394 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'animated_size.dart'; +import 'basic.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; +import 'ticker_provider.dart'; +import 'transitions.dart'; + +// Examples can assume: +// bool _first = false; + +/// Specifies which of two children to show. See [AnimatedCrossFade]. +/// +/// The child that is shown will fade in, while the other will fade out. +enum CrossFadeState { + /// Show the first child ([AnimatedCrossFade.firstChild]) and hide the second + /// ([AnimatedCrossFade.secondChild]]). + showFirst, + + /// Show the second child ([AnimatedCrossFade.secondChild]) and hide the first + /// ([AnimatedCrossFade.firstChild]). + showSecond, +} + +/// Signature for the [AnimatedCrossFade.layoutBuilder] callback. +/// +/// The `topChild` is the child fading in, which is normally drawn on top. The +/// `bottomChild` is the child fading out, normally drawn on the bottom. +/// +/// For good performance, the returned widget tree should contain both the +/// `topChild` and the `bottomChild`; the depth of the tree, and the types of +/// the widgets in the tree, from the returned widget to each of the children +/// should be the same; and where there is a widget with multiple children, the +/// top child and the bottom child should be keyed using the provided +/// `topChildKey` and `bottomChildKey` keys respectively. +/// +/// {@tool snippet} +/// +/// ```dart +/// Widget defaultLayoutBuilder(Widget topChild, Key topChildKey, Widget bottomChild, Key bottomChildKey) { +/// return Stack( +/// children: <Widget>[ +/// Positioned( +/// key: bottomChildKey, +/// left: 0.0, +/// top: 0.0, +/// right: 0.0, +/// child: bottomChild, +/// ), +/// Positioned( +/// key: topChildKey, +/// child: topChild, +/// ) +/// ], +/// ); +/// } +/// ``` +/// {@end-tool} +typedef AnimatedCrossFadeBuilder = Widget Function(Widget topChild, Key topChildKey, Widget bottomChild, Key bottomChildKey); + +/// A widget that cross-fades between two given children and animates itself +/// between their sizes. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=PGK2UUAyE54} +/// +/// The animation is controlled through the [crossFadeState] parameter. +/// [firstCurve] and [secondCurve] represent the opacity curves of the two +/// children. The [firstCurve] is inverted, i.e. it fades out when providing a +/// growing curve like [Curves.linear]. The [sizeCurve] is the curve used to +/// animate between the size of the fading-out child and the size of the +/// fading-in child. +/// +/// This widget is intended to be used to fade a pair of widgets with the same +/// width. In the case where the two children have different heights, the +/// animation crops overflowing children during the animation by aligning their +/// top edge, which means that the bottom will be clipped. +/// +/// The animation is automatically triggered when an existing +/// [AnimatedCrossFade] is rebuilt with a different value for the +/// [crossFadeState] property. +/// +/// {@tool snippet} +/// +/// This code fades between two representations of the Flutter logo. It depends +/// on a boolean field `_first`; when `_first` is true, the first logo is shown, +/// otherwise the second logo is shown. When the field changes state, the +/// [AnimatedCrossFade] widget cross-fades between the two forms of the logo +/// over three seconds. +/// +/// ```dart +/// AnimatedCrossFade( +/// duration: const Duration(seconds: 3), +/// firstChild: const FlutterLogo(style: FlutterLogoStyle.horizontal, size: 100.0), +/// secondChild: const FlutterLogo(style: FlutterLogoStyle.stacked, size: 100.0), +/// crossFadeState: _first ? CrossFadeState.showFirst : CrossFadeState.showSecond, +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedOpacity], which fades between nothing and a single child. +/// * [AnimatedSwitcher], which switches out a child for a new one with a +/// customizable transition, supporting multiple cross-fades at once. +/// * [AnimatedSize], the lower-level widget which [AnimatedCrossFade] uses to +/// automatically change size. +class AnimatedCrossFade extends StatefulWidget { + /// Creates a cross-fade animation widget. + /// + /// The [duration] of the animation is the same for all components (fade in, + /// fade out, and size), and you can pass [Interval]s instead of [Curve]s in + /// order to have finer control, e.g., creating an overlap between the fades. + const AnimatedCrossFade({ + super.key, + required this.firstChild, + required this.secondChild, + this.firstCurve = Curves.linear, + this.secondCurve = Curves.linear, + this.sizeCurve = Curves.linear, + this.alignment = Alignment.topCenter, + required this.crossFadeState, + required this.duration, + this.reverseDuration, + this.layoutBuilder = defaultLayoutBuilder, + this.excludeBottomFocus = true, + }); + + /// The child that is visible when [crossFadeState] is + /// [CrossFadeState.showFirst]. It fades out when transitioning + /// [crossFadeState] from [CrossFadeState.showFirst] to + /// [CrossFadeState.showSecond] and vice versa. + final Widget firstChild; + + /// The child that is visible when [crossFadeState] is + /// [CrossFadeState.showSecond]. It fades in when transitioning + /// [crossFadeState] from [CrossFadeState.showFirst] to + /// [CrossFadeState.showSecond] and vice versa. + final Widget secondChild; + + /// The child that will be shown when the animation has completed. + final CrossFadeState crossFadeState; + + /// The duration of the whole orchestrated animation. + final Duration duration; + + /// The duration of the whole orchestrated animation when running in reverse. + /// + /// If not supplied, this defaults to [duration]. + final Duration? reverseDuration; + + /// The fade curve of the first child. + /// + /// Defaults to [Curves.linear]. + final Curve firstCurve; + + /// The fade curve of the second child. + /// + /// Defaults to [Curves.linear]. + final Curve secondCurve; + + /// The curve of the animation between the two children's sizes. + /// + /// Defaults to [Curves.linear]. + final Curve sizeCurve; + + /// How the children should be aligned while the size is animating. + /// + /// Defaults to [Alignment.topCenter]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// A builder that positions the [firstChild] and [secondChild] widgets. + /// + /// The widget returned by this method is wrapped in an [AnimatedSize]. + /// + /// By default, this uses [AnimatedCrossFade.defaultLayoutBuilder], which uses + /// a [Stack] and aligns the `bottomChild` to the top of the stack while + /// providing the `topChild` as the non-positioned child to fill the provided + /// constraints. This works well when the [AnimatedCrossFade] is in a position + /// to change size and when the children are not flexible. However, if the + /// children are less fussy about their sizes (for example a + /// [CircularProgressIndicator] inside a [Center]), or if the + /// [AnimatedCrossFade] is being forced to a particular size, then it can + /// result in the widgets jumping about when the cross-fade state is changed. + final AnimatedCrossFadeBuilder layoutBuilder; + + /// When true, this is equivalent to wrapping the bottom widget with an [ExcludeFocus] + /// widget while it is at the bottom of the cross-fade stack. + /// + /// Defaults to true. When it is false, the bottom widget in the cross-fade stack + /// can remain in focus until the top widget requests focus. This is useful for + /// animating between different [TextField]s so the keyboard remains open during the + /// cross-fade animation. + final bool excludeBottomFocus; + + /// The default layout algorithm used by [AnimatedCrossFade]. + /// + /// The top child is placed in a stack that sizes itself to match the top + /// child. The bottom child is positioned at the top of the same stack, sized + /// to fit its width but without forcing the height. The stack is then + /// clipped. + /// + /// This is the default value for [layoutBuilder]. It implements + /// [AnimatedCrossFadeBuilder]. + static Widget defaultLayoutBuilder(Widget topChild, Key topChildKey, Widget bottomChild, Key bottomChildKey) { + return Stack( + clipBehavior: Clip.none, + children: <Widget>[ + Positioned( + key: bottomChildKey, + left: 0.0, + top: 0.0, + right: 0.0, + child: bottomChild, + ), + Positioned( + key: topChildKey, + child: topChild, + ), + ], + ); + } + + @override + State<AnimatedCrossFade> createState() => _AnimatedCrossFadeState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<CrossFadeState>('crossFadeState', crossFadeState)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: Alignment.topCenter)); + properties.add(IntProperty('duration', duration.inMilliseconds, unit: 'ms')); + properties.add(IntProperty('reverseDuration', reverseDuration?.inMilliseconds, unit: 'ms', defaultValue: null)); + } +} + +class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProviderStateMixin { + late AnimationController _controller; + late Animation<double> _firstAnimation; + late Animation<double> _secondAnimation; + + @override + void initState() { + super.initState(); + _controller = AnimationController( + duration: widget.duration, + reverseDuration: widget.reverseDuration, + vsync: this, + ); + if (widget.crossFadeState == CrossFadeState.showSecond) { + _controller.value = 1.0; + } + _firstAnimation = _initAnimation(widget.firstCurve, true); + _secondAnimation = _initAnimation(widget.secondCurve, false); + _controller.addStatusListener((AnimationStatus status) { + setState(() { + // Trigger a rebuild because it depends on _isTransitioning, which + // changes its value together with animation status. + }); + }); + } + + Animation<double> _initAnimation(Curve curve, bool inverted) { + Animation<double> result = _controller.drive(CurveTween(curve: curve)); + if (inverted) { + result = result.drive(Tween<double>(begin: 1.0, end: 0.0)); + } + return result; + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + void didUpdateWidget(AnimatedCrossFade oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.duration != oldWidget.duration) { + _controller.duration = widget.duration; + } + if (widget.reverseDuration != oldWidget.reverseDuration) { + _controller.reverseDuration = widget.reverseDuration; + } + if (widget.firstCurve != oldWidget.firstCurve) { + _firstAnimation = _initAnimation(widget.firstCurve, true); + } + if (widget.secondCurve != oldWidget.secondCurve) { + _secondAnimation = _initAnimation(widget.secondCurve, false); + } + if (widget.crossFadeState != oldWidget.crossFadeState) { + switch (widget.crossFadeState) { + case CrossFadeState.showFirst: + _controller.reverse(); + case CrossFadeState.showSecond: + _controller.forward(); + } + } + } + + /// Whether we're in the middle of cross-fading this frame. + bool get _isTransitioning => _controller.status == AnimationStatus.forward || _controller.status == AnimationStatus.reverse; + + @override + Widget build(BuildContext context) { + const Key kFirstChildKey = ValueKey<CrossFadeState>(CrossFadeState.showFirst); + const Key kSecondChildKey = ValueKey<CrossFadeState>(CrossFadeState.showSecond); + final bool transitioningForwards = _controller.status == AnimationStatus.completed || + _controller.status == AnimationStatus.forward; + final Key topKey; + Widget topChild; + final Animation<double> topAnimation; + final Key bottomKey; + Widget bottomChild; + final Animation<double> bottomAnimation; + if (transitioningForwards) { + topKey = kSecondChildKey; + topChild = widget.secondChild; + topAnimation = _secondAnimation; + bottomKey = kFirstChildKey; + bottomChild = widget.firstChild; + bottomAnimation = _firstAnimation; + } else { + topKey = kFirstChildKey; + topChild = widget.firstChild; + topAnimation = _firstAnimation; + bottomKey = kSecondChildKey; + bottomChild = widget.secondChild; + bottomAnimation = _secondAnimation; + } + + bottomChild = TickerMode( + key: bottomKey, + enabled: _isTransitioning, + child: IgnorePointer( + child: ExcludeSemantics( // Always exclude the semantics of the widget that's fading out. + child: ExcludeFocus( + excluding: widget.excludeBottomFocus, + child: FadeTransition( + opacity: bottomAnimation, + child: bottomChild, + ), + ), + ), + ), + ); + topChild = TickerMode( + key: topKey, + enabled: true, // Top widget always has its animations enabled. + child: IgnorePointer( + ignoring: false, + child: ExcludeSemantics( + excluding: false, // Always publish semantics for the widget that's fading in. + child: ExcludeFocus( + excluding: false, + child: FadeTransition( + opacity: topAnimation, + child: topChild, + ), + ), + ), + ), + ); + return ClipRect( + child: AnimatedSize( + alignment: widget.alignment, + duration: widget.duration, + reverseDuration: widget.reverseDuration, + curve: widget.sizeCurve, + child: widget.layoutBuilder(topChild, topKey, bottomChild, bottomKey), + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(EnumProperty<CrossFadeState>('crossFadeState', widget.crossFadeState)); + description.add(DiagnosticsProperty<AnimationController>('controller', _controller, showName: false)); + description.add(DiagnosticsProperty<AlignmentGeometry>('alignment', widget.alignment, defaultValue: Alignment.topCenter)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_scroll_view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_scroll_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..856383131583e52512e698c2dedc22fa707df280 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_scroll_view.dart @@ -0,0 +1,1231 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'media_query.dart'; +import 'scroll_controller.dart'; +import 'scroll_delegate.dart'; +import 'scroll_physics.dart'; +import 'scroll_view.dart'; +import 'sliver.dart'; +import 'ticker_provider.dart'; + +/// A scrolling container that animates items when they are inserted or removed. +/// +/// This widget's [AnimatedListState] can be used to dynamically insert or +/// remove items. To refer to the [AnimatedListState] either provide a +/// [GlobalKey] or use the static [of] method from an item's input callback. +/// +/// This widget is similar to one created by [ListView.builder]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ZtfItHwFlZ8} +/// +/// {@tool dartpad} +/// This sample application uses an [AnimatedList] to create an effect when +/// items are removed or added to the list. +/// +/// ** See code in examples/api/lib/widgets/animated_list/animated_list.0.dart ** +/// {@end-tool} +/// +/// By default, [AnimatedList] will automatically pad the limits of the +/// list's scrollable to avoid partial obstructions indicated by +/// [MediaQuery]'s padding. To avoid this behavior, override with a +/// zero [padding] property. +/// +/// {@tool snippet} +/// The following example demonstrates how to override the default top and +/// bottom padding using [MediaQuery.removePadding]. +/// +/// ```dart +/// Widget myWidget(BuildContext context) { +/// return MediaQuery.removePadding( +/// context: context, +/// removeTop: true, +/// removeBottom: true, +/// child: AnimatedList( +/// initialItemCount: 50, +/// itemBuilder: (BuildContext context, int index, Animation<double> animation) { +/// return Card( +/// color: Colors.amber, +/// child: Center(child: Text('$index')), +/// ); +/// } +/// ), +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverAnimatedList], a sliver that animates items when they are inserted +/// or removed from a list. +/// * [SliverAnimatedGrid], a sliver which animates items when they are +/// inserted or removed from a grid. +/// * [AnimatedGrid], a non-sliver scrolling container that animates items when +/// they are inserted or removed in a grid. +class AnimatedList extends _AnimatedScrollView { + /// Creates a scrolling container that animates items when they are inserted + /// or removed. + const AnimatedList({ + super.key, + required super.itemBuilder, + super.initialItemCount = 0, + super.scrollDirection = Axis.vertical, + super.reverse = false, + super.controller, + super.primary, + super.physics, + super.shrinkWrap = false, + super.padding, + super.clipBehavior = Clip.hardEdge, + }) : assert(initialItemCount >= 0); + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [AnimatedList] item widgets that insert + /// or remove items in response to user input. + /// + /// If no [AnimatedList] surrounds the context given, then this function will + /// assert in debug mode and throw an exception in release mode. + /// + /// This method can be expensive (it walks the element tree). + /// + /// This method does not create a dependency, and so will not cause rebuilding + /// when the state changes. + /// + /// See also: + /// + /// * [maybeOf], a similar function that will return null if no + /// [AnimatedList] ancestor is found. + static AnimatedListState of(BuildContext context) { + final AnimatedListState? result = AnimatedList.maybeOf(context); + assert(() { + if (result == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('AnimatedList.of() called with a context that does not contain an AnimatedList.'), + ErrorDescription( + 'No AnimatedList ancestor could be found starting from the context that was passed to AnimatedList.of().', + ), + ErrorHint( + 'This can happen when the context provided is from the same StatefulWidget that ' + 'built the AnimatedList. Please see the AnimatedList documentation for examples ' + 'of how to refer to an AnimatedListState object:\n' + ' https://api.flutter.dev/flutter/widgets/AnimatedListState-class.html', + ), + context.describeElement('The context used was'), + ]); + } + return true; + }()); + return result!; + } + + /// The [AnimatedListState] from the closest instance of [AnimatedList] that encloses the given + /// context. + /// + /// This method is typically used by [AnimatedList] item widgets that insert + /// or remove items in response to user input. + /// + /// If no [AnimatedList] surrounds the context given, then this function will + /// return null. + /// + /// This method can be expensive (it walks the element tree). + /// + /// This method does not create a dependency, and so will not cause rebuilding + /// when the state changes. + /// + /// See also: + /// + /// * [of], a similar function that will throw if no [AnimatedList] ancestor + /// is found. + static AnimatedListState? maybeOf(BuildContext context) { + return context.findAncestorStateOfType<AnimatedListState>(); + } + + @override + AnimatedListState createState() => AnimatedListState(); +} + +/// The [AnimatedListState] for [AnimatedList], a scrolling list container that animates items when they are +/// inserted or removed. +/// +/// When an item is inserted with [insertItem] an animation begins running. The +/// animation is passed to [AnimatedList.itemBuilder] whenever the item's widget +/// is needed. +/// +/// When multiple items are inserted with [insertAllItems] an animation begins running. +/// The animation is passed to [AnimatedList.itemBuilder] whenever the item's widget +/// is needed. +/// +/// When an item is removed with [removeItem] its animation is reversed. +/// The removed item's animation is passed to the [removeItem] builder +/// parameter. +/// +/// An app that needs to insert or remove items in response to an event +/// can refer to the [AnimatedList]'s state with a global key: +/// +/// ```dart +/// // (e.g. in a stateful widget) +/// GlobalKey<AnimatedListState> listKey = GlobalKey<AnimatedListState>(); +/// +/// // ... +/// +/// @override +/// Widget build(BuildContext context) { +/// return AnimatedList( +/// key: listKey, +/// itemBuilder: (BuildContext context, int index, Animation<double> animation) { +/// return const Placeholder(); +/// }, +/// ); +/// } +/// +/// // ... +/// +/// void _updateList() { +/// // adds "123" to the AnimatedList +/// listKey.currentState!.insertItem(123); +/// } +/// ``` +/// +/// [AnimatedList] item input handlers can also refer to their [AnimatedListState] +/// with the static [AnimatedList.of] method. +class AnimatedListState extends _AnimatedScrollViewState<AnimatedList> { + + @override + Widget build(BuildContext context) { + return _wrap( + SliverAnimatedList( + key: _sliverAnimatedMultiBoxKey, + itemBuilder: widget.itemBuilder, + initialItemCount: widget.initialItemCount, + ), + widget.scrollDirection, + ); + } +} + +/// A scrolling container that animates items when they are inserted into or removed from a grid. +/// in a grid. +/// +/// This widget's [AnimatedGridState] can be used to dynamically insert or +/// remove items. To refer to the [AnimatedGridState] either provide a +/// [GlobalKey] or use the static [of] method from an item's input callback. +/// +/// This widget is similar to one created by [GridView.builder]. +/// +/// {@tool dartpad} +/// This sample application uses an [AnimatedGrid] to create an effect when +/// items are removed or added to the grid. +/// +/// ** See code in examples/api/lib/widgets/animated_grid/animated_grid.0.dart ** +/// {@end-tool} +/// +/// By default, [AnimatedGrid] will automatically pad the limits of the +/// grid's scrollable to avoid partial obstructions indicated by +/// [MediaQuery]'s padding. To avoid this behavior, override with a +/// zero [padding] property. +/// +/// {@tool snippet} +/// The following example demonstrates how to override the default top and +/// bottom padding using [MediaQuery.removePadding]. +/// +/// ```dart +/// Widget myWidget(BuildContext context) { +/// return MediaQuery.removePadding( +/// context: context, +/// removeTop: true, +/// removeBottom: true, +/// child: AnimatedGrid( +/// gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( +/// crossAxisCount: 3, +/// ), +/// initialItemCount: 50, +/// itemBuilder: (BuildContext context, int index, Animation<double> animation) { +/// return Card( +/// color: Colors.amber, +/// child: Center(child: Text('$index')), +/// ); +/// } +/// ), +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverAnimatedGrid], a sliver which animates items when they are inserted +/// into or removed from a grid. +/// * [SliverAnimatedList], a sliver which animates items added and removed from +/// a list instead of a grid. +/// * [AnimatedList], which animates items added and removed from a list instead +/// of a grid. +class AnimatedGrid extends _AnimatedScrollView { + /// Creates a scrolling container that animates items when they are inserted + /// or removed. + const AnimatedGrid({ + super.key, + required super.itemBuilder, + required this.gridDelegate, + super.initialItemCount = 0, + super.scrollDirection = Axis.vertical, + super.reverse = false, + super.controller, + super.primary, + super.physics, + super.padding, + super.clipBehavior = Clip.hardEdge, + }) : assert(initialItemCount >= 0); + + /// {@template flutter.widgets.AnimatedGrid.gridDelegate} + /// A delegate that controls the layout of the children within the + /// [AnimatedGrid]. + /// + /// See also: + /// + /// * [SliverGridDelegateWithFixedCrossAxisCount], which creates a layout with + /// a fixed number of tiles in the cross axis. + /// * [SliverGridDelegateWithMaxCrossAxisExtent], which creates a layout with + /// tiles that have a maximum cross-axis extent. + /// {@endtemplate} + final SliverGridDelegate gridDelegate; + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [AnimatedGrid] item widgets that insert + /// or remove items in response to user input. + /// + /// If no [AnimatedGrid] surrounds the context given, then this function will + /// assert in debug mode and throw an exception in release mode. + /// + /// This method can be expensive (it walks the element tree). + /// + /// This method does not create a dependency, and so will not cause rebuilding + /// when the state changes. + /// + /// See also: + /// + /// * [maybeOf], a similar function that will return null if no + /// [AnimatedGrid] ancestor is found. + static AnimatedGridState of(BuildContext context) { + final AnimatedGridState? result = AnimatedGrid.maybeOf(context); + assert(() { + if (result == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('AnimatedGrid.of() called with a context that does not contain an AnimatedGrid.'), + ErrorDescription( + 'No AnimatedGrid ancestor could be found starting from the context that was passed to AnimatedGrid.of().', + ), + ErrorHint( + 'This can happen when the context provided is from the same StatefulWidget that ' + 'built the AnimatedGrid. Please see the AnimatedGrid documentation for examples ' + 'of how to refer to an AnimatedGridState object:\n' + ' https://api.flutter.dev/flutter/widgets/AnimatedGridState-class.html', + ), + context.describeElement('The context used was'), + ]); + } + return true; + }()); + return result!; + } + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [AnimatedGrid] item widgets that insert + /// or remove items in response to user input. + /// + /// If no [AnimatedGrid] surrounds the context given, then this function will + /// return null. + /// + /// This method can be expensive (it walks the element tree). + /// + /// This method does not create a dependency, and so will not cause rebuilding + /// when the state changes. + /// + /// See also: + /// + /// * [of], a similar function that will throw if no [AnimatedGrid] ancestor + /// is found. + static AnimatedGridState? maybeOf(BuildContext context) { + return context.findAncestorStateOfType<AnimatedGridState>(); + } + + @override + AnimatedGridState createState() => AnimatedGridState(); +} + +/// The [State] for an [AnimatedGrid] that animates items when they are +/// inserted or removed. +/// +/// When an item is inserted with [insertItem] an animation begins running. The +/// animation is passed to [AnimatedGrid.itemBuilder] whenever the item's widget +/// is needed. +/// +/// When an item is removed with [removeItem] its animation is reversed. +/// The removed item's animation is passed to the [removeItem] builder +/// parameter. +/// +/// An app that needs to insert or remove items in response to an event +/// can refer to the [AnimatedGrid]'s state with a global key: +/// +/// ```dart +/// // (e.g. in a stateful widget) +/// GlobalKey<AnimatedGridState> gridKey = GlobalKey<AnimatedGridState>(); +/// +/// // ... +/// +/// @override +/// Widget build(BuildContext context) { +/// return AnimatedGrid( +/// key: gridKey, +/// itemBuilder: (BuildContext context, int index, Animation<double> animation) { +/// return const Placeholder(); +/// }, +/// gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(maxCrossAxisExtent: 100.0), +/// ); +/// } +/// +/// // ... +/// +/// void _updateGrid() { +/// // adds "123" to the AnimatedGrid +/// gridKey.currentState!.insertItem(123); +/// } +/// ``` +/// +/// [AnimatedGrid] item input handlers can also refer to their [AnimatedGridState] +/// with the static [AnimatedGrid.of] method. +class AnimatedGridState extends _AnimatedScrollViewState<AnimatedGrid> { + + @override + Widget build(BuildContext context) { + return _wrap( + SliverAnimatedGrid( + key: _sliverAnimatedMultiBoxKey, + gridDelegate: widget.gridDelegate, + itemBuilder: widget.itemBuilder, + initialItemCount: widget.initialItemCount, + ), + widget.scrollDirection, + ); + } +} + +abstract class _AnimatedScrollView extends StatefulWidget { + /// Creates a scrolling container that animates items when they are inserted + /// or removed. + const _AnimatedScrollView({ + super.key, + required this.itemBuilder, + this.initialItemCount = 0, + this.scrollDirection = Axis.vertical, + this.reverse = false, + this.controller, + this.primary, + this.physics, + this.shrinkWrap = false, + this.padding, + this.clipBehavior = Clip.hardEdge, + }) : assert(initialItemCount >= 0); + + /// {@template flutter.widgets.AnimatedScrollView.itemBuilder} + /// Called, as needed, to build children widgets. + /// + /// Children are only built when they're scrolled into view. + /// + /// The [AnimatedItemBuilder] index parameter indicates the item's + /// position in the scroll view. The value of the index parameter will be + /// between 0 and [initialItemCount] plus the total number of items that have + /// been inserted with [AnimatedListState.insertItem] or + /// [AnimatedGridState.insertItem] and less the total number of items that + /// have been removed with [AnimatedListState.removeItem] or + /// [AnimatedGridState.removeItem]. + /// + /// Implementations of this callback should assume that + /// `removeItem` removes an item immediately. + /// {@endtemplate} + final AnimatedItemBuilder itemBuilder; + + /// {@template flutter.widgets.AnimatedScrollView.initialItemCount} + /// The number of items the [AnimatedList] or [AnimatedGrid] will start with. + /// + /// The appearance of the initial items is not animated. They + /// are created, as needed, by [itemBuilder] with an animation parameter + /// of [kAlwaysCompleteAnimation]. + /// {@endtemplate} + final int initialItemCount; + + /// {@macro flutter.widgets.scroll_view.scrollDirection} + final Axis scrollDirection; + + /// Whether the scroll view scrolls in the reading direction. + /// + /// For example, if the reading direction is left-to-right and + /// [scrollDirection] is [Axis.horizontal], then the scroll view scrolls from + /// left to right when [reverse] is false and from right to left when + /// [reverse] is true. + /// + /// Similarly, if [scrollDirection] is [Axis.vertical], then the scroll view + /// scrolls from top to bottom when [reverse] is false and from bottom to top + /// when [reverse] is true. + /// + /// Defaults to false. + final bool reverse; + + /// An object that can be used to control the position to which this scroll + /// view is scrolled. + /// + /// Must be null if [primary] is true. + /// + /// A [ScrollController] serves several purposes. It can be used to control + /// the initial scroll position (see [ScrollController.initialScrollOffset]). + /// It can be used to control whether the scroll view should automatically + /// save and restore its scroll position in the [PageStorage] (see + /// [ScrollController.keepScrollOffset]). It can be used to read the current + /// scroll position (see [ScrollController.offset]), or change it (see + /// [ScrollController.animateTo]). + final ScrollController? controller; + + /// Whether this is the primary scroll view associated with the parent + /// [PrimaryScrollController]. + /// + /// On iOS, this identifies the scroll view that will scroll to top in + /// response to a tap in the status bar. + /// + /// Defaults to true when [scrollDirection] is [Axis.vertical] and + /// [controller] is null. + final bool? primary; + + /// How the scroll view should respond to user input. + /// + /// For example, this determines how the scroll view continues to animate after the + /// user stops dragging the scroll view. + /// + /// Defaults to matching platform conventions. + final ScrollPhysics? physics; + + /// Whether the extent of the scroll view in the [scrollDirection] should be + /// determined by the contents being viewed. + /// + /// If the scroll view does not shrink wrap, then the scroll view will expand + /// to the maximum allowed size in the [scrollDirection]. If the scroll view + /// has unbounded constraints in the [scrollDirection], then [shrinkWrap] must + /// be true. + /// + /// Shrink wrapping the content of the scroll view is significantly more + /// expensive than expanding to the maximum allowed size because the content + /// can expand and contract during scrolling, which means the size of the + /// scroll view needs to be recomputed whenever the scroll position changes. + /// + /// Defaults to false. + final bool shrinkWrap; + + /// The amount of space by which to inset the children. + final EdgeInsetsGeometry? padding; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; +} + +abstract class _AnimatedScrollViewState<T extends _AnimatedScrollView> extends State<T> with TickerProviderStateMixin { + final GlobalKey<_SliverAnimatedMultiBoxAdaptorState<_SliverAnimatedMultiBoxAdaptor>> _sliverAnimatedMultiBoxKey = GlobalKey(); + + /// Insert an item at [index] and start an animation that will be passed + /// to [AnimatedGrid.itemBuilder] or [AnimatedList.itemBuilder] when the item + /// is visible. + /// + /// This method's semantics are the same as Dart's [List.insert] method: it + /// increases the length of the list of items by one and shifts + /// all items at or after [index] towards the end of the list of items. + void insertItem(int index, { Duration duration = _kDuration }) { + _sliverAnimatedMultiBoxKey.currentState!.insertItem(index, duration: duration); + } + + /// Insert multiple items at [index] and start an animation that will be passed + /// to [AnimatedGrid.itemBuilder] or [AnimatedList.itemBuilder] when the items + /// are visible. + void insertAllItems(int index, int length, { Duration duration = _kDuration, bool isAsync = false }) { + _sliverAnimatedMultiBoxKey.currentState!.insertAllItems(index, length, duration: duration); + } + + /// Remove the item at `index` and start an animation that will be passed to + /// `builder` when the item is visible. + /// + /// Items are removed immediately. After an item has been removed, its index + /// will no longer be passed to the `itemBuilder`. However, the + /// item will still appear for `duration` and during that time + /// `builder` must construct its widget as needed. + /// + /// This method's semantics are the same as Dart's [List.remove] method: it + /// decreases the length of items by one and shifts all items at or before + /// `index` towards the beginning of the list of items. + /// + /// See also: + /// + /// * [AnimatedRemovedItemBuilder], which describes the arguments to the + /// `builder` argument. + void removeItem(int index, AnimatedRemovedItemBuilder builder, { Duration duration = _kDuration }) { + _sliverAnimatedMultiBoxKey.currentState!.removeItem(index, builder, duration: duration); + } + + /// Remove all the items and start an animation that will be passed to + /// `builder` when the items are visible. + /// + /// Items are removed immediately. However, the + /// items will still appear for `duration`, and during that time + /// `builder` must construct its widget as needed. + /// + /// This method's semantics are the same as Dart's [List.clear] method: it + /// removes all the items in the list. + void removeAllItems(AnimatedRemovedItemBuilder builder, { Duration duration = _kDuration }) { + _sliverAnimatedMultiBoxKey.currentState!.removeAllItems(builder, duration: duration); + } + + Widget _wrap(Widget sliver, Axis direction) { + EdgeInsetsGeometry? effectivePadding = widget.padding; + if (widget.padding == null) { + final MediaQueryData? mediaQuery = MediaQuery.maybeOf(context); + if (mediaQuery != null) { + // Automatically pad sliver with padding from MediaQuery. + final EdgeInsets mediaQueryHorizontalPadding = + mediaQuery.padding.copyWith(top: 0.0, bottom: 0.0); + final EdgeInsets mediaQueryVerticalPadding = + mediaQuery.padding.copyWith(left: 0.0, right: 0.0); + // Consume the main axis padding with SliverPadding. + effectivePadding = direction == Axis.vertical + ? mediaQueryVerticalPadding + : mediaQueryHorizontalPadding; + // Leave behind the cross axis padding. + sliver = MediaQuery( + data: mediaQuery.copyWith( + padding: direction == Axis.vertical + ? mediaQueryHorizontalPadding + : mediaQueryVerticalPadding, + ), + child: sliver, + ); + } + } + + if (effectivePadding != null) { + sliver = SliverPadding(padding: effectivePadding, sliver: sliver); + } + return CustomScrollView( + scrollDirection: widget.scrollDirection, + reverse: widget.reverse, + controller: widget.controller, + primary: widget.primary, + physics: widget.physics, + clipBehavior: widget.clipBehavior, + shrinkWrap: widget.shrinkWrap, + slivers: <Widget>[ sliver ], + ); + } +} + +/// Signature for the builder callback used by [AnimatedList]. +/// +/// This is deprecated, use the identical [AnimatedItemBuilder] instead. +@Deprecated( + 'Use AnimatedItemBuilder instead. ' + 'This feature was deprecated after v3.5.0-4.0.pre.', +) +typedef AnimatedListItemBuilder = Widget Function(BuildContext context, int index, Animation<double> animation); + +/// Signature for the builder callback used by [AnimatedList] & [AnimatedGrid] to +/// build their animated children. +/// +/// The `context` argument is the build context where the widget will be +/// created, the `index` is the index of the item to be built, and the +/// `animation` is an [Animation] that should be used to animate an entry +/// transition for the widget that is built. +/// +/// See also: +/// +/// * [AnimatedRemovedItemBuilder], a builder that is for removing items with +/// animations instead of adding them. +typedef AnimatedItemBuilder = Widget Function(BuildContext context, int index, Animation<double> animation); + +/// Signature for the builder callback used by [AnimatedListState.removeItem]. +/// +/// This is deprecated, use the identical [AnimatedRemovedItemBuilder] +/// instead. +@Deprecated( + 'Use AnimatedRemovedItemBuilder instead. ' + 'This feature was deprecated after v3.5.0-4.0.pre.', +) +typedef AnimatedListRemovedItemBuilder = Widget Function(BuildContext context, Animation<double> animation); + +/// Signature for the builder callback used in [AnimatedListState.removeItem] and +/// [AnimatedGridState.removeItem] to animate their children after they have +/// been removed. +/// +/// The `context` argument is the build context where the widget will be +/// created, and the `animation` is an [Animation] that should be used to +/// animate an exit transition for the widget that is built. +/// +/// See also: +/// +/// * [AnimatedItemBuilder], a builder that is for adding items with animations +/// instead of removing them. +typedef AnimatedRemovedItemBuilder = Widget Function(BuildContext context, Animation<double> animation); + +// The default insert/remove animation duration. +const Duration _kDuration = Duration(milliseconds: 300); + +// Incoming and outgoing animated items. +class _ActiveItem implements Comparable<_ActiveItem> { + _ActiveItem.incoming(this.controller, this.itemIndex) : removedItemBuilder = null; + _ActiveItem.outgoing(this.controller, this.itemIndex, this.removedItemBuilder); + _ActiveItem.index(this.itemIndex) + : controller = null, + removedItemBuilder = null; + + final AnimationController? controller; + final AnimatedRemovedItemBuilder? removedItemBuilder; + int itemIndex; + + @override + int compareTo(_ActiveItem other) => itemIndex - other.itemIndex; +} + +/// A [SliverList] that animates items when they are inserted or removed. +/// +/// This widget's [SliverAnimatedListState] can be used to dynamically insert or +/// remove items. To refer to the [SliverAnimatedListState] either provide a +/// [GlobalKey] or use the static [SliverAnimatedList.of] method from a list item's +/// input callback. +/// +/// {@tool dartpad} +/// This sample application uses a [SliverAnimatedList] to create an animated +/// effect when items are removed or added to the list. +/// +/// ** See code in examples/api/lib/widgets/animated_list/sliver_animated_list.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverList], which does not animate items when they are inserted or +/// removed. +/// * [AnimatedList], a non-sliver scrolling container that animates items when +/// they are inserted or removed. +/// * [SliverAnimatedGrid], a sliver which animates items when they are +/// inserted into or removed from a grid. +/// * [AnimatedGrid], a non-sliver scrolling container that animates items when +/// they are inserted into or removed from a grid. +class SliverAnimatedList extends _SliverAnimatedMultiBoxAdaptor { + /// Creates a [SliverList] that animates items when they are inserted or + /// removed. + const SliverAnimatedList({ + super.key, + required super.itemBuilder, + super.findChildIndexCallback, + super.initialItemCount = 0, + }) : assert(initialItemCount >= 0); + + @override + SliverAnimatedListState createState() => SliverAnimatedListState(); + + /// The [SliverAnimatedListState] from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [SliverAnimatedList] item widgets that + /// insert or remove items in response to user input. + /// + /// If no [SliverAnimatedList] surrounds the context given, then this function + /// will assert in debug mode and throw an exception in release mode. + /// + /// This method can be expensive (it walks the element tree). + /// + /// This method does not create a dependency, and so will not cause rebuilding + /// when the state changes. + /// + /// See also: + /// + /// * [maybeOf], a similar function that will return null if no + /// [SliverAnimatedList] ancestor is found. + static SliverAnimatedListState of(BuildContext context) { + final SliverAnimatedListState? result = SliverAnimatedList.maybeOf(context); + assert(() { + if (result == null) { + throw FlutterError( + 'SliverAnimatedList.of() called with a context that does not contain a SliverAnimatedList.\n' + 'No SliverAnimatedListState ancestor could be found starting from the ' + 'context that was passed to SliverAnimatedListState.of(). This can ' + 'happen when the context provided is from the same StatefulWidget that ' + 'built the AnimatedList. Please see the SliverAnimatedList documentation ' + 'for examples of how to refer to an AnimatedListState object: ' + 'https://api.flutter.dev/flutter/widgets/SliverAnimatedListState-class.html\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return result!; + } + + /// The [SliverAnimatedListState] from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [SliverAnimatedList] item widgets that + /// insert or remove items in response to user input. + /// + /// If no [SliverAnimatedList] surrounds the context given, then this function + /// will return null. + /// + /// This method can be expensive (it walks the element tree). + /// + /// This method does not create a dependency, and so will not cause rebuilding + /// when the state changes. + /// + /// See also: + /// + /// * [of], a similar function that will throw if no [SliverAnimatedList] + /// ancestor is found. + static SliverAnimatedListState? maybeOf(BuildContext context) { + return context.findAncestorStateOfType<SliverAnimatedListState>(); + } +} + +/// The state for a [SliverAnimatedList] that animates items when they are +/// inserted or removed. +/// +/// When an item is inserted with [insertItem] an animation begins running. The +/// animation is passed to [SliverAnimatedList.itemBuilder] whenever the item's +/// widget is needed. +/// +/// When an item is removed with [removeItem] its animation is reversed. +/// The removed item's animation is passed to the [removeItem] builder +/// parameter. +/// +/// An app that needs to insert or remove items in response to an event +/// can refer to the [SliverAnimatedList]'s state with a global key: +/// +/// ```dart +/// // (e.g. in a stateful widget) +/// GlobalKey<AnimatedListState> listKey = GlobalKey<AnimatedListState>(); +/// +/// // ... +/// +/// @override +/// Widget build(BuildContext context) { +/// return AnimatedList( +/// key: listKey, +/// itemBuilder: (BuildContext context, int index, Animation<double> animation) { +/// return const Placeholder(); +/// }, +/// ); +/// } +/// +/// // ... +/// +/// void _updateList() { +/// // adds "123" to the AnimatedList +/// listKey.currentState!.insertItem(123); +/// } +/// ``` +/// +/// [SliverAnimatedList] item input handlers can also refer to their +/// [SliverAnimatedListState] with the static [SliverAnimatedList.of] method. +class SliverAnimatedListState extends _SliverAnimatedMultiBoxAdaptorState<SliverAnimatedList> { + + @override + Widget build(BuildContext context) { + return SliverList( + delegate: _createDelegate(), + ); + } +} + +/// A [SliverGrid] that animates items when they are inserted or removed. +/// +/// This widget's [SliverAnimatedGridState] can be used to dynamically insert or +/// remove items. To refer to the [SliverAnimatedGridState] either provide a +/// [GlobalKey] or use the static [SliverAnimatedGrid.of] method from an item's +/// input callback. +/// +/// {@tool dartpad} +/// This sample application uses a [SliverAnimatedGrid] to create an animated +/// effect when items are removed or added to the grid. +/// +/// ** See code in examples/api/lib/widgets/animated_grid/sliver_animated_grid.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedGrid], a non-sliver scrolling container that animates items when +/// they are inserted into or removed from a grid. +/// * [SliverGrid], which does not animate items when they are inserted or +/// removed from a grid. +/// * [SliverList], which displays a non-animated list of items. +/// * [SliverAnimatedList], which animates items added and removed from a list +/// instead of a grid. +class SliverAnimatedGrid extends _SliverAnimatedMultiBoxAdaptor { + /// Creates a [SliverGrid] that animates items when they are inserted or + /// removed. + const SliverAnimatedGrid({ + super.key, + required super.itemBuilder, + required this.gridDelegate, + super.findChildIndexCallback, + super.initialItemCount = 0, + }) : assert(initialItemCount >= 0); + + @override + SliverAnimatedGridState createState() => SliverAnimatedGridState(); + + /// {@macro flutter.widgets.AnimatedGrid.gridDelegate} + final SliverGridDelegate gridDelegate; + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [SliverAnimatedGrid] item widgets that + /// insert or remove items in response to user input. + /// + /// If no [SliverAnimatedGrid] surrounds the context given, then this function + /// will assert in debug mode and throw an exception in release mode. + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [maybeOf], a similar function that will return null if no + /// [SliverAnimatedGrid] ancestor is found. + static SliverAnimatedGridState of(BuildContext context) { + final SliverAnimatedGridState? result = context.findAncestorStateOfType<SliverAnimatedGridState>(); + assert(() { + if (result == null) { + throw FlutterError( + 'SliverAnimatedGrid.of() called with a context that does not contain a SliverAnimatedGrid.\n' + 'No SliverAnimatedGridState ancestor could be found starting from the ' + 'context that was passed to SliverAnimatedGridState.of(). This can ' + 'happen when the context provided is from the same StatefulWidget that ' + 'built the AnimatedGrid. Please see the SliverAnimatedGrid documentation ' + 'for examples of how to refer to an AnimatedGridState object: ' + 'https://api.flutter.dev/flutter/widgets/SliverAnimatedGridState-class.html\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return result!; + } + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [SliverAnimatedGrid] item widgets that + /// insert or remove items in response to user input. + /// + /// If no [SliverAnimatedGrid] surrounds the context given, then this function + /// will return null. + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [of], a similar function that will throw if no [SliverAnimatedGrid] + /// ancestor is found. + static SliverAnimatedGridState? maybeOf(BuildContext context) { + return context.findAncestorStateOfType<SliverAnimatedGridState>(); + } +} + +/// The state for a [SliverAnimatedGrid] that animates items when they are +/// inserted or removed. +/// +/// When an item is inserted with [insertItem] an animation begins running. The +/// animation is passed to [SliverAnimatedGrid.itemBuilder] whenever the item's +/// widget is needed. +/// +/// When an item is removed with [removeItem] its animation is reversed. +/// The removed item's animation is passed to the [removeItem] builder +/// parameter. +/// +/// An app that needs to insert or remove items in response to an event +/// can refer to the [SliverAnimatedGrid]'s state with a global key: +/// +/// ```dart +/// // (e.g. in a stateful widget) +/// GlobalKey<AnimatedGridState> gridKey = GlobalKey<AnimatedGridState>(); +/// +/// // ... +/// +/// @override +/// Widget build(BuildContext context) { +/// return AnimatedGrid( +/// key: gridKey, +/// itemBuilder: (BuildContext context, int index, Animation<double> animation) { +/// return const Placeholder(); +/// }, +/// gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(maxCrossAxisExtent: 100.0), +/// ); +/// } +/// +/// // ... +/// +/// void _updateGrid() { +/// // adds "123" to the AnimatedGrid +/// gridKey.currentState!.insertItem(123); +/// } +/// ``` +/// +/// [SliverAnimatedGrid] item input handlers can also refer to their +/// [SliverAnimatedGridState] with the static [SliverAnimatedGrid.of] method. +class SliverAnimatedGridState extends _SliverAnimatedMultiBoxAdaptorState<SliverAnimatedGrid> { + + @override + Widget build(BuildContext context) { + return SliverGrid( + gridDelegate: widget.gridDelegate, + delegate: _createDelegate(), + ); + } +} + +abstract class _SliverAnimatedMultiBoxAdaptor extends StatefulWidget { + /// Creates a sliver that animates items when they are inserted or removed. + const _SliverAnimatedMultiBoxAdaptor({ + super.key, + required this.itemBuilder, + this.findChildIndexCallback, + this.initialItemCount = 0, + }) : assert(initialItemCount >= 0); + + /// {@macro flutter.widgets.AnimatedScrollView.itemBuilder} + final AnimatedItemBuilder itemBuilder; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.findChildIndexCallback} + final ChildIndexGetter? findChildIndexCallback; + + /// {@macro flutter.widgets.AnimatedScrollView.initialItemCount} + final int initialItemCount; +} + +abstract class _SliverAnimatedMultiBoxAdaptorState<T extends _SliverAnimatedMultiBoxAdaptor> extends State<T> with TickerProviderStateMixin { + + @override + void initState() { + super.initState(); + _itemsCount = widget.initialItemCount; + } + + @override + void dispose() { + for (final _ActiveItem item in _incomingItems.followedBy(_outgoingItems)) { + item.controller!.dispose(); + } + super.dispose(); + } + + final List<_ActiveItem> _incomingItems = <_ActiveItem>[]; + final List<_ActiveItem> _outgoingItems = <_ActiveItem>[]; + int _itemsCount = 0; + + _ActiveItem? _removeActiveItemAt(List<_ActiveItem> items, int itemIndex) { + final int i = binarySearch(items, _ActiveItem.index(itemIndex)); + return i == -1 ? null : items.removeAt(i); + } + + _ActiveItem? _activeItemAt(List<_ActiveItem> items, int itemIndex) { + final int i = binarySearch(items, _ActiveItem.index(itemIndex)); + return i == -1 ? null : items[i]; + } + + // The insertItem() and removeItem() index parameters are defined as if the + // removeItem() operation removed the corresponding list/grid entry + // immediately. The entry is only actually removed from the + // ListView/GridView when the remove animation finishes. The entry is added + // to _outgoingItems when removeItem is called and removed from + // _outgoingItems when the remove animation finishes. + + int _indexToItemIndex(int index) { + int itemIndex = index; + for (final _ActiveItem item in _outgoingItems) { + if (item.itemIndex <= itemIndex) { + itemIndex += 1; + } else { + break; + } + } + return itemIndex; + } + + int _itemIndexToIndex(int itemIndex) { + int index = itemIndex; + for (final _ActiveItem item in _outgoingItems) { + assert(item.itemIndex != itemIndex); + if (item.itemIndex < itemIndex) { + index -= 1; + } else { + break; + } + } + return index; + } + + SliverChildDelegate _createDelegate() { + return SliverChildBuilderDelegate( + _itemBuilder, + childCount: _itemsCount, + findChildIndexCallback: widget.findChildIndexCallback == null + ? null + : (Key key) { + final int? index = widget.findChildIndexCallback!(key); + return index != null ? _indexToItemIndex(index) : null; + }, + ); + } + + Widget _itemBuilder(BuildContext context, int itemIndex) { + final _ActiveItem? outgoingItem = _activeItemAt(_outgoingItems, itemIndex); + if (outgoingItem != null) { + return outgoingItem.removedItemBuilder!( + context, + outgoingItem.controller!.view, + ); + } + + final _ActiveItem? incomingItem = _activeItemAt(_incomingItems, itemIndex); + final Animation<double> animation = incomingItem?.controller?.view ?? kAlwaysCompleteAnimation; + return widget.itemBuilder( + context, + _itemIndexToIndex(itemIndex), + animation, + ); + } + + /// Insert an item at [index] and start an animation that will be passed to + /// [SliverAnimatedGrid.itemBuilder] or [SliverAnimatedList.itemBuilder] when + /// the item is visible. + /// + /// This method's semantics are the same as Dart's [List.insert] method: it + /// increases the length of the list of items by one and shifts + /// all items at or after [index] towards the end of the list of items. + void insertItem(int index, { Duration duration = _kDuration }) { + assert(index >= 0); + + final int itemIndex = _indexToItemIndex(index); + assert(itemIndex >= 0 && itemIndex <= _itemsCount); + + // Increment the incoming and outgoing item indices to account + // for the insertion. + for (final _ActiveItem item in _incomingItems) { + if (item.itemIndex >= itemIndex) { + item.itemIndex += 1; + } + } + for (final _ActiveItem item in _outgoingItems) { + if (item.itemIndex >= itemIndex) { + item.itemIndex += 1; + } + } + + final AnimationController controller = AnimationController( + duration: duration, + vsync: this, + ); + final _ActiveItem incomingItem = _ActiveItem.incoming( + controller, + itemIndex, + ); + setState(() { + _incomingItems + ..add(incomingItem) + ..sort(); + _itemsCount += 1; + }); + + controller.forward().then<void>((_) { + _removeActiveItemAt(_incomingItems, incomingItem.itemIndex)!.controller!.dispose(); + }); + } + + /// Insert multiple items at [index] and start an animation that will be passed + /// to [AnimatedGrid.itemBuilder] or [AnimatedList.itemBuilder] when the items + /// are visible. + void insertAllItems(int index, int length, { Duration duration = _kDuration }) { + for (int i = 0; i < length; i++) { + insertItem(index + i, duration: duration); + } + } + + /// Remove the item at [index] and start an animation that will be passed + /// to [builder] when the item is visible. + /// + /// Items are removed immediately. After an item has been removed, its index + /// will no longer be passed to the subclass' [SliverAnimatedGrid.itemBuilder] + /// or [SliverAnimatedList.itemBuilder]. However the item will still appear + /// for [duration], and during that time [builder] must construct its widget + /// as needed. + /// + /// This method's semantics are the same as Dart's [List.remove] method: it + /// decreases the length of items by one and shifts + /// all items at or before [index] towards the beginning of the list of items. + void removeItem(int index, AnimatedRemovedItemBuilder builder, { Duration duration = _kDuration }) { + assert(index >= 0); + + final int itemIndex = _indexToItemIndex(index); + assert(itemIndex >= 0 && itemIndex < _itemsCount); + assert(_activeItemAt(_outgoingItems, itemIndex) == null); + + final _ActiveItem? incomingItem = _removeActiveItemAt(_incomingItems, itemIndex); + final AnimationController controller = + incomingItem?.controller ?? AnimationController(duration: duration, value: 1.0, vsync: this); + final _ActiveItem outgoingItem = _ActiveItem.outgoing(controller, itemIndex, builder); + setState(() { + _outgoingItems + ..add(outgoingItem) + ..sort(); + }); + + controller.reverse().then<void>((void value) { + _removeActiveItemAt(_outgoingItems, outgoingItem.itemIndex)!.controller!.dispose(); + + // Decrement the incoming and outgoing item indices to account + // for the removal. + for (final _ActiveItem item in _incomingItems) { + if (item.itemIndex > outgoingItem.itemIndex) { + item.itemIndex -= 1; + } + } + for (final _ActiveItem item in _outgoingItems) { + if (item.itemIndex > outgoingItem.itemIndex) { + item.itemIndex -= 1; + } + } + + setState(() => _itemsCount -= 1); + }); + } + + /// Remove all the items and start an animation that will be passed to + /// `builder` when the items are visible. + /// + /// Items are removed immediately. However, the + /// items will still appear for `duration` and during that time + /// `builder` must construct its widget as needed. + /// + /// This method's semantics are the same as Dart's [List.clear] method: it + /// removes all the items in the list. + void removeAllItems(AnimatedRemovedItemBuilder builder, { Duration duration = _kDuration }) { + for (int i = _itemsCount - 1 ; i >= 0; i--) { + removeItem(i, builder, duration: duration); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_size.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_size.dart new file mode 100644 index 0000000000000000000000000000000000000000..110ec3ca1af50b8bd19d02055cb0377bd6b6379d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_size.dart @@ -0,0 +1,167 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'ticker_provider.dart'; + +/// Animated widget that automatically transitions its size over a given +/// duration whenever the given child's size changes. +/// +/// {@tool dartpad} +/// This example makes a [Container] react to being touched, causing the child +/// of the [AnimatedSize] widget, here a [FlutterLogo], to animate. +/// +/// ** See code in examples/api/lib/widgets/animated_size/animated_size.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SizeTransition], which changes its size based on an [Animation]. +class AnimatedSize extends StatefulWidget { + /// Creates a widget that animates its size to match that of its child. + const AnimatedSize({ + super.key, + this.child, + this.alignment = Alignment.center, + this.curve = Curves.linear, + required this.duration, + this.reverseDuration, + this.clipBehavior = Clip.hardEdge, + this.onEnd, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The alignment of the child within the parent when the parent is not yet + /// the same size as the child. + /// + /// The x and y values of the alignment control the horizontal and vertical + /// alignment, respectively. An x value of -1.0 means that the left edge of + /// the child is aligned with the left edge of the parent whereas an x value + /// of 1.0 means that the right edge of the child is aligned with the right + /// edge of the parent. Other values interpolate (and extrapolate) linearly. + /// For example, a value of 0.0 means that the center of the child is aligned + /// with the center of the parent. + /// + /// Defaults to [Alignment.center]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// The animation curve when transitioning this widget's size to match the + /// child's size. + final Curve curve; + + /// The duration when transitioning this widget's size to match the child's + /// size. + final Duration duration; + + /// The duration when transitioning this widget's size to match the child's + /// size when going in reverse. + /// + /// If not specified, defaults to [duration]. + final Duration? reverseDuration; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// Called every time an animation completes. + /// + /// This can be useful to trigger additional actions (e.g. another animation) + /// at the end of the current animation. + final VoidCallback? onEnd; + + @override + State<AnimatedSize> createState() => _AnimatedSizeState(); +} + +class _AnimatedSizeState + extends State<AnimatedSize> with SingleTickerProviderStateMixin { + @override + Widget build(BuildContext context) { + return _AnimatedSize( + alignment: widget.alignment, + curve: widget.curve, + duration: widget.duration, + reverseDuration: widget.reverseDuration, + vsync: this, + clipBehavior: widget.clipBehavior, + onEnd: widget.onEnd, + child: widget.child, + ); + } +} + +class _AnimatedSize extends SingleChildRenderObjectWidget { + const _AnimatedSize({ + super.child, + this.alignment = Alignment.center, + this.curve = Curves.linear, + required this.duration, + this.reverseDuration, + required this.vsync, + this.clipBehavior = Clip.hardEdge, + this.onEnd, + }); + + final AlignmentGeometry alignment; + final Curve curve; + final Duration duration; + final Duration? reverseDuration; + + /// The [TickerProvider] for this widget. + final TickerProvider vsync; + + final Clip clipBehavior; + + final VoidCallback? onEnd; + + @override + RenderAnimatedSize createRenderObject(BuildContext context) { + return RenderAnimatedSize( + alignment: alignment, + duration: duration, + reverseDuration: reverseDuration, + curve: curve, + vsync: vsync, + textDirection: Directionality.maybeOf(context), + clipBehavior: clipBehavior, + onEnd: onEnd, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderAnimatedSize renderObject) { + renderObject + ..alignment = alignment + ..duration = duration + ..reverseDuration = reverseDuration + ..curve = curve + ..vsync = vsync + ..textDirection = Directionality.maybeOf(context) + ..clipBehavior = clipBehavior + ..onEnd = onEnd; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: Alignment.topCenter)); + properties.add(IntProperty('duration', duration.inMilliseconds, unit: 'ms')); + properties.add(IntProperty('reverseDuration', reverseDuration?.inMilliseconds, unit: 'ms', defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_switcher.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_switcher.dart new file mode 100644 index 0000000000000000000000000000000000000000..177ede770629be039e2999086f02d2347c82373e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/animated_switcher.dart @@ -0,0 +1,391 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'ticker_provider.dart'; +import 'transitions.dart'; + +// Internal representation of a child that, now or in the past, was set on the +// AnimatedSwitcher.child field, but is now in the process of +// transitioning. The internal representation includes fields that we don't want +// to expose to the public API (like the controller). +class _ChildEntry { + _ChildEntry({ + required this.controller, + required this.animation, + required this.transition, + required this.widgetChild, + }); + + // The animation controller for the child's transition. + final AnimationController controller; + + // The (curved) animation being used to drive the transition. + final Animation<double> animation; + + // The currently built transition for this child. + Widget transition; + + // The widget's child at the time this entry was created or updated. + // Used to rebuild the transition if necessary. + Widget widgetChild; + + @override + String toString() => 'Entry#${shortHash(this)}($widgetChild)'; +} + +/// Signature for builders used to generate custom transitions for +/// [AnimatedSwitcher]. +/// +/// The `child` should be transitioning in when the `animation` is running in +/// the forward direction. +/// +/// The function should return a widget which wraps the given `child`. It may +/// also use the `animation` to inform its transition. It must not return null. +typedef AnimatedSwitcherTransitionBuilder = Widget Function(Widget child, Animation<double> animation); + +/// Signature for builders used to generate custom layouts for +/// [AnimatedSwitcher]. +/// +/// The builder should return a widget which contains the given children, laid +/// out as desired. It must not return null. The builder should be able to +/// handle an empty list of `previousChildren`, or a null `currentChild`. +/// +/// The `previousChildren` list is an unmodifiable list, sorted with the oldest +/// at the beginning and the newest at the end. It does not include the +/// `currentChild`. +typedef AnimatedSwitcherLayoutBuilder = Widget Function(Widget? currentChild, List<Widget> previousChildren); + +/// A widget that by default does a cross-fade between a new widget and the +/// widget previously set on the [AnimatedSwitcher] as a child. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=2W7POjFb88g} +/// +/// If they are swapped fast enough (i.e. before [duration] elapses), more than +/// one previous child can exist and be transitioning out while the newest one +/// is transitioning in. +/// +/// If the "new" child is the same widget type and key as the "old" child, but +/// with different parameters, then [AnimatedSwitcher] will *not* do a +/// transition between them, since as far as the framework is concerned, they +/// are the same widget and the existing widget can be updated with the new +/// parameters. To force the transition to occur, set a [Key] on each child +/// widget that you wish to be considered unique (typically a [ValueKey] on the +/// widget data that distinguishes this child from the others). +/// +/// The same key can be used for a new child as was used for an already-outgoing +/// child; the two will not be considered related. (For example, if a progress +/// indicator with key A is first shown, then an image with key B, then another +/// progress indicator with key A again, all in rapid succession, then the old +/// progress indicator and the image will be fading out while a new progress +/// indicator is fading in.) +/// +/// The type of transition can be changed from a cross-fade to a custom +/// transition by setting the [transitionBuilder]. +/// +/// {@tool dartpad} +/// This sample shows a counter that animates the scale of a text widget +/// whenever the value changes. +/// +/// ** See code in examples/api/lib/widgets/animated_switcher/animated_switcher.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedCrossFade], which only fades between two children, but also +/// interpolates their sizes, and is reversible. +/// * [AnimatedOpacity], which can be used to switch between nothingness and +/// a given child by fading the child in and out. +/// * [FadeTransition], which [AnimatedSwitcher] uses to perform the transition. +class AnimatedSwitcher extends StatefulWidget { + /// Creates an [AnimatedSwitcher]. + const AnimatedSwitcher({ + super.key, + this.child, + required this.duration, + this.reverseDuration, + this.switchInCurve = Curves.linear, + this.switchOutCurve = Curves.linear, + this.transitionBuilder = AnimatedSwitcher.defaultTransitionBuilder, + this.layoutBuilder = AnimatedSwitcher.defaultLayoutBuilder, + }); + + /// The current child widget to display. If there was a previous child, then + /// that child will be faded out using the [switchOutCurve], while the new + /// child is faded in with the [switchInCurve], over the [duration]. + /// + /// If there was no previous child, then this child will fade in using the + /// [switchInCurve] over the [duration]. + /// + /// The child is considered to be "new" if it has a different type or [Key] + /// (see [Widget.canUpdate]). + /// + /// To change the kind of transition used, see [transitionBuilder]. + final Widget? child; + + /// The duration of the transition from the old [child] value to the new one. + /// + /// This duration is applied to the given [child] when that property is set to + /// a new child. The same duration is used when fading out, unless + /// [reverseDuration] is set. Changing [duration] will not affect the + /// durations of transitions already in progress. + final Duration duration; + + /// The duration of the transition from the new [child] value to the old one. + /// + /// This duration is applied to the given [child] when that property is set to + /// a new child. Changing [reverseDuration] will not affect the durations of + /// transitions already in progress. + /// + /// If not set, then the value of [duration] is used by default. + final Duration? reverseDuration; + + /// The animation curve to use when transitioning in a new [child]. + /// + /// This curve is applied to the given [child] when that property is set to a + /// new child. Changing [switchInCurve] will not affect the curve of a + /// transition already in progress. + /// + /// The [switchOutCurve] is used when fading out, except that if [child] is + /// changed while the current child is in the middle of fading in, + /// [switchInCurve] will be run in reverse from that point instead of jumping + /// to the corresponding point on [switchOutCurve]. + final Curve switchInCurve; + + /// The animation curve to use when transitioning a previous [child] out. + /// + /// This curve is applied to the [child] when the child is faded in (or when + /// the widget is created, for the first child). Changing [switchOutCurve] + /// will not affect the curves of already-visible widgets, it only affects the + /// curves of future children. + /// + /// If [child] is changed while the current child is in the middle of fading + /// in, [switchInCurve] will be run in reverse from that point instead of + /// jumping to the corresponding point on [switchOutCurve]. + final Curve switchOutCurve; + + /// A function that wraps a new [child] with an animation that transitions + /// the [child] in when the animation runs in the forward direction and out + /// when the animation runs in the reverse direction. This is only called + /// when a new [child] is set (not for each build), or when a new + /// [transitionBuilder] is set. If a new [transitionBuilder] is set, then + /// the transition is rebuilt for the current child and all previous children + /// using the new [transitionBuilder]. The function must not return null. + /// + /// The default is [AnimatedSwitcher.defaultTransitionBuilder]. + /// + /// The animation provided to the builder has the [duration] and + /// [switchInCurve] or [switchOutCurve] applied as provided when the + /// corresponding [child] was first provided. + /// + /// See also: + /// + /// * [AnimatedSwitcherTransitionBuilder] for more information about + /// how a transition builder should function. + final AnimatedSwitcherTransitionBuilder transitionBuilder; + + /// A function that wraps all of the children that are transitioning out, and + /// the [child] that's transitioning in, with a widget that lays all of them + /// out. This is called every time this widget is built. The function must not + /// return null. + /// + /// The default is [AnimatedSwitcher.defaultLayoutBuilder]. + /// + /// See also: + /// + /// * [AnimatedSwitcherLayoutBuilder] for more information about + /// how a layout builder should function. + final AnimatedSwitcherLayoutBuilder layoutBuilder; + + @override + State<AnimatedSwitcher> createState() => _AnimatedSwitcherState(); + + /// The transition builder used as the default value of [transitionBuilder]. + /// + /// The new child is given a [FadeTransition] which increases opacity as + /// the animation goes from 0.0 to 1.0, and decreases when the animation is + /// reversed. + /// + /// This is an [AnimatedSwitcherTransitionBuilder] function. + static Widget defaultTransitionBuilder(Widget child, Animation<double> animation) { + return FadeTransition( + key: ValueKey<Key?>(child.key), + opacity: animation, + child: child, + ); + } + + /// The layout builder used as the default value of [layoutBuilder]. + /// + /// The new child is placed in a [Stack] that sizes itself to match the + /// largest of the child or a previous child. The children are centered on + /// each other. + /// + /// This is an [AnimatedSwitcherLayoutBuilder] function. + static Widget defaultLayoutBuilder(Widget? currentChild, List<Widget> previousChildren) { + return Stack( + alignment: Alignment.center, + children: <Widget>[ + ...previousChildren, + if (currentChild != null) currentChild, + ], + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('duration', duration.inMilliseconds, unit: 'ms')); + properties.add(IntProperty('reverseDuration', reverseDuration?.inMilliseconds, unit: 'ms', defaultValue: null)); + } +} + +class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProviderStateMixin { + _ChildEntry? _currentEntry; + final Set<_ChildEntry> _outgoingEntries = <_ChildEntry>{}; + List<Widget>? _outgoingWidgets = const <Widget>[]; + int _childNumber = 0; + + @override + void initState() { + super.initState(); + _addEntryForNewChild(animate: false); + } + + @override + void didUpdateWidget(AnimatedSwitcher oldWidget) { + super.didUpdateWidget(oldWidget); + + // If the transition builder changed, then update all of the previous + // transitions. + if (widget.transitionBuilder != oldWidget.transitionBuilder) { + _outgoingEntries.forEach(_updateTransitionForEntry); + if (_currentEntry != null) { + _updateTransitionForEntry(_currentEntry!); + } + _markChildWidgetCacheAsDirty(); + } + + final bool hasNewChild = widget.child != null; + final bool hasOldChild = _currentEntry != null; + if (hasNewChild != hasOldChild || + hasNewChild && !Widget.canUpdate(widget.child!, _currentEntry!.widgetChild)) { + // Child has changed, fade current entry out and add new entry. + _childNumber += 1; + _addEntryForNewChild(animate: true); + } else if (_currentEntry != null) { + assert(hasOldChild && hasNewChild); + assert(Widget.canUpdate(widget.child!, _currentEntry!.widgetChild)); + // Child has been updated. Make sure we update the child widget and + // transition in _currentEntry even though we're not going to start a new + // animation, but keep the key from the previous transition so that we + // update the transition instead of replacing it. + _currentEntry!.widgetChild = widget.child!; + _updateTransitionForEntry(_currentEntry!); // uses entry.widgetChild + _markChildWidgetCacheAsDirty(); + } + } + + void _addEntryForNewChild({ required bool animate }) { + assert(animate || _currentEntry == null); + if (_currentEntry != null) { + assert(animate); + assert(!_outgoingEntries.contains(_currentEntry)); + _outgoingEntries.add(_currentEntry!); + _currentEntry!.controller.reverse(); + _markChildWidgetCacheAsDirty(); + _currentEntry = null; + } + if (widget.child == null) { + return; + } + final AnimationController controller = AnimationController( + duration: widget.duration, + reverseDuration: widget.reverseDuration, + vsync: this, + ); + final Animation<double> animation = CurvedAnimation( + parent: controller, + curve: widget.switchInCurve, + reverseCurve: widget.switchOutCurve, + ); + _currentEntry = _newEntry( + child: widget.child!, + controller: controller, + animation: animation, + builder: widget.transitionBuilder, + ); + if (animate) { + controller.forward(); + } else { + assert(_outgoingEntries.isEmpty); + controller.value = 1.0; + } + } + + _ChildEntry _newEntry({ + required Widget child, + required AnimatedSwitcherTransitionBuilder builder, + required AnimationController controller, + required Animation<double> animation, + }) { + final _ChildEntry entry = _ChildEntry( + widgetChild: child, + transition: KeyedSubtree.wrap(builder(child, animation), _childNumber), + animation: animation, + controller: controller, + ); + animation.addStatusListener((AnimationStatus status) { + if (status == AnimationStatus.dismissed) { + setState(() { + assert(mounted); + assert(_outgoingEntries.contains(entry)); + _outgoingEntries.remove(entry); + _markChildWidgetCacheAsDirty(); + }); + controller.dispose(); + } + }); + return entry; + } + + void _markChildWidgetCacheAsDirty() { + _outgoingWidgets = null; + } + + void _updateTransitionForEntry(_ChildEntry entry) { + entry.transition = KeyedSubtree( + key: entry.transition.key, + child: widget.transitionBuilder(entry.widgetChild, entry.animation), + ); + } + + void _rebuildOutgoingWidgetsIfNeeded() { + _outgoingWidgets ??= List<Widget>.unmodifiable( + _outgoingEntries.map<Widget>((_ChildEntry entry) => entry.transition), + ); + assert(_outgoingEntries.length == _outgoingWidgets!.length); + assert(_outgoingEntries.isEmpty || _outgoingEntries.last.transition == _outgoingWidgets!.last); + } + + @override + void dispose() { + if (_currentEntry != null) { + _currentEntry!.controller.dispose(); + } + for (final _ChildEntry entry in _outgoingEntries) { + entry.controller.dispose(); + } + super.dispose(); + } + + @override + Widget build(BuildContext context) { + _rebuildOutgoingWidgetsIfNeeded(); + return widget.layoutBuilder(_currentEntry?.transition, _outgoingWidgets!.where((Widget outgoing) => outgoing.key != _currentEntry?.transition.key).toSet().toList()); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/annotated_region.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/annotated_region.dart new file mode 100644 index 0000000000000000000000000000000000000000..f47be65abd8c5b31c68dbae3e51270fca93177a1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/annotated_region.dart @@ -0,0 +1,53 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; + +/// Annotates a region of the layer tree with a value. +/// +/// See also: +/// +/// * [Layer.find], for an example of how this value is retrieved. +/// * [AnnotatedRegionLayer], the layer pushed into the layer tree. +class AnnotatedRegion<T extends Object> extends SingleChildRenderObjectWidget { + /// Creates a new annotated region to insert [value] into the layer tree. + /// + /// Neither [child] nor [value] may be null. + /// + /// [sized] defaults to true and controls whether the annotated region will + /// clip its child. + const AnnotatedRegion({ + super.key, + required Widget super.child, + required this.value, + this.sized = true, + }); + + /// A value which can be retrieved using [Layer.find]. + final T value; + + /// If false, the layer pushed into the tree will not be provided with a size. + /// + /// An [AnnotatedRegionLayer] with a size checks that the offset provided in + /// [Layer.find] is within the bounds, returning null otherwise. + /// + /// See also: + /// + /// * [AnnotatedRegionLayer], for a description of this behavior. + final bool sized; + + @override + RenderObject createRenderObject(BuildContext context) { + return RenderAnnotatedRegion<T>(value: value, sized: sized); + } + + @override + void updateRenderObject(BuildContext context, RenderAnnotatedRegion<T> renderObject) { + renderObject + ..value = value + ..sized = sized; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/app.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/app.dart new file mode 100644 index 0000000000000000000000000000000000000000..3dd610c8efa8c6f57d5ec6aae7e65758893d880f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/app.dart @@ -0,0 +1,1842 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection' show HashMap; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; + +import 'actions.dart'; +import 'banner.dart'; +import 'basic.dart'; +import 'binding.dart'; +import 'default_text_editing_shortcuts.dart'; +import 'focus_scope.dart'; +import 'focus_traversal.dart'; +import 'framework.dart'; +import 'localizations.dart'; +import 'media_query.dart'; +import 'navigator.dart'; +import 'notification_listener.dart'; +import 'pages.dart'; +import 'performance_overlay.dart'; +import 'restoration.dart'; +import 'router.dart'; +import 'scrollable_helpers.dart'; +import 'semantics_debugger.dart'; +import 'shared_app_data.dart'; +import 'shortcuts.dart'; +import 'tap_region.dart'; +import 'text.dart'; +import 'title.dart'; +import 'value_listenable_builder.dart'; +import 'widget_inspector.dart'; + +export 'dart:ui' show Locale; + +// Examples can assume: +// late Widget myWidget; + +/// The signature of [WidgetsApp.localeListResolutionCallback]. +/// +/// A [LocaleListResolutionCallback] is responsible for computing the locale of the app's +/// [Localizations] object when the app starts and when user changes the list of +/// locales for the device. +/// +/// The [locales] list is the device's preferred locales when the app started, or the +/// device's preferred locales the user selected after the app was started. This list +/// is in order of preference. If this list is null or empty, then Flutter has not yet +/// received the locale information from the platform. The [supportedLocales] parameter +/// is just the value of [WidgetsApp.supportedLocales]. +/// +/// See also: +/// +/// * [LocaleResolutionCallback], which takes only one default locale (instead of a list) +/// and is attempted only after this callback fails or is null. [LocaleListResolutionCallback] +/// is recommended over [LocaleResolutionCallback]. +typedef LocaleListResolutionCallback = Locale? Function(List<Locale>? locales, Iterable<Locale> supportedLocales); + +/// {@template flutter.widgets.LocaleResolutionCallback} +/// The signature of [WidgetsApp.localeResolutionCallback]. +/// +/// It is recommended to provide a [LocaleListResolutionCallback] instead of a +/// [LocaleResolutionCallback] when possible, as [LocaleResolutionCallback] only +/// receives a subset of the information provided in [LocaleListResolutionCallback]. +/// +/// A [LocaleResolutionCallback] is responsible for computing the locale of the app's +/// [Localizations] object when the app starts and when user changes the default +/// locale for the device after [LocaleListResolutionCallback] fails or is not provided. +/// +/// This callback is also used if the app is created with a specific locale using +/// the [WidgetsApp.new] `locale` parameter. +/// +/// The [locale] is either the value of [WidgetsApp.locale], or the device's default +/// locale when the app started, or the device locale the user selected after the app +/// was started. The default locale is the first locale in the list of preferred +/// locales. If [locale] is null, then Flutter has not yet received the locale +/// information from the platform. The [supportedLocales] parameter is just the value of +/// [WidgetsApp.supportedLocales]. +/// +/// See also: +/// +/// * [LocaleListResolutionCallback], which takes a list of preferred locales (instead of one locale). +/// Resolutions by [LocaleListResolutionCallback] take precedence over [LocaleResolutionCallback]. +/// {@endtemplate} +typedef LocaleResolutionCallback = Locale? Function(Locale? locale, Iterable<Locale> supportedLocales); + +/// The default locale resolution algorithm. +/// +/// Custom resolution algorithms can be provided through +/// [WidgetsApp.localeListResolutionCallback] or +/// [WidgetsApp.localeResolutionCallback]. +/// +/// When no custom locale resolution algorithms are provided or if both fail +/// to resolve, Flutter will default to calling this algorithm. +/// +/// This algorithm prioritizes speed at the cost of slightly less appropriate +/// resolutions for edge cases. +/// +/// This algorithm will resolve to the earliest preferred locale that +/// matches the most fields, prioritizing in the order of perfect match, +/// languageCode+countryCode, languageCode+scriptCode, languageCode-only. +/// +/// In the case where a locale is matched by languageCode-only and is not the +/// default (first) locale, the next preferred locale with a +/// perfect match can supersede the languageCode-only match if it exists. +/// +/// When a preferredLocale matches more than one supported locale, it will +/// resolve to the first matching locale listed in the supportedLocales. +/// +/// When all preferred locales have been exhausted without a match, the first +/// countryCode only match will be returned. +/// +/// When no match at all is found, the first (default) locale in +/// [supportedLocales] will be returned. +/// +/// To summarize, the main matching priority is: +/// +/// 1. [Locale.languageCode], [Locale.scriptCode], and [Locale.countryCode] +/// 2. [Locale.languageCode] and [Locale.scriptCode] only +/// 3. [Locale.languageCode] and [Locale.countryCode] only +/// 4. [Locale.languageCode] only (with caveats, see above) +/// 5. [Locale.countryCode] only when all [preferredLocales] fail to match +/// 6. Returns the first element of [supportedLocales] as a fallback +/// +/// This algorithm does not take language distance (how similar languages are to each other) +/// into account, and will not handle edge cases such as resolving `de` to `fr` rather than `zh` +/// when `de` is not supported and `zh` is listed before `fr` (German is closer to French +/// than Chinese). +Locale basicLocaleListResolution(List<Locale>? preferredLocales, Iterable<Locale> supportedLocales) { + // preferredLocales can be null when called before the platform has had a chance to + // initialize the locales. Platforms without locale passing support will provide an empty list. + // We default to the first supported locale in these cases. + if (preferredLocales == null || preferredLocales.isEmpty) { + return supportedLocales.first; + } + // Hash the supported locales because apps can support many locales and would + // be expensive to search through them many times. + final Map<String, Locale> allSupportedLocales = HashMap<String, Locale>(); + final Map<String, Locale> languageAndCountryLocales = HashMap<String, Locale>(); + final Map<String, Locale> languageAndScriptLocales = HashMap<String, Locale>(); + final Map<String, Locale> languageLocales = HashMap<String, Locale>(); + final Map<String?, Locale> countryLocales = HashMap<String?, Locale>(); + for (final Locale locale in supportedLocales) { + allSupportedLocales['${locale.languageCode}_${locale.scriptCode}_${locale.countryCode}'] ??= locale; + languageAndScriptLocales['${locale.languageCode}_${locale.scriptCode}'] ??= locale; + languageAndCountryLocales['${locale.languageCode}_${locale.countryCode}'] ??= locale; + languageLocales[locale.languageCode] ??= locale; + countryLocales[locale.countryCode] ??= locale; + } + + // Since languageCode-only matches are possibly low quality, we don't return + // it instantly when we find such a match. We check to see if the next + // preferred locale in the list has a high accuracy match, and only return + // the languageCode-only match when a higher accuracy match in the next + // preferred locale cannot be found. + Locale? matchesLanguageCode; + Locale? matchesCountryCode; + // Loop over user's preferred locales + for (int localeIndex = 0; localeIndex < preferredLocales.length; localeIndex += 1) { + final Locale userLocale = preferredLocales[localeIndex]; + // Look for perfect match. + if (allSupportedLocales.containsKey('${userLocale.languageCode}_${userLocale.scriptCode}_${userLocale.countryCode}')) { + return userLocale; + } + // Look for language+script match. + if (userLocale.scriptCode != null) { + final Locale? match = languageAndScriptLocales['${userLocale.languageCode}_${userLocale.scriptCode}']; + if (match != null) { + return match; + } + } + // Look for language+country match. + if (userLocale.countryCode != null) { + final Locale? match = languageAndCountryLocales['${userLocale.languageCode}_${userLocale.countryCode}']; + if (match != null) { + return match; + } + } + // If there was a languageCode-only match in the previous iteration's higher + // ranked preferred locale, we return it if the current userLocale does not + // have a better match. + if (matchesLanguageCode != null) { + return matchesLanguageCode; + } + // Look and store language-only match. + Locale? match = languageLocales[userLocale.languageCode]; + if (match != null) { + matchesLanguageCode = match; + // Since first (default) locale is usually highly preferred, we will allow + // a languageCode-only match to be instantly matched. If the next preferred + // languageCode is the same, we defer hastily returning until the next iteration + // since at worst it is the same and at best an improved match. + if (localeIndex == 0 && + !(localeIndex + 1 < preferredLocales.length && preferredLocales[localeIndex + 1].languageCode == userLocale.languageCode)) { + return matchesLanguageCode; + } + } + // countryCode-only match. When all else except default supported locale fails, + // attempt to match by country only, as a user is likely to be familiar with a + // language from their listed country. + if (matchesCountryCode == null && userLocale.countryCode != null) { + match = countryLocales[userLocale.countryCode]; + if (match != null) { + matchesCountryCode = match; + } + } + } + // When there is no languageCode-only match. Fallback to matching countryCode only. Country + // fallback only applies on iOS. When there is no countryCode-only match, we return first + // supported locale. + final Locale resolvedLocale = matchesLanguageCode ?? matchesCountryCode ?? supportedLocales.first; + return resolvedLocale; +} + +/// The signature of [WidgetsApp.onGenerateTitle]. +/// +/// Used to generate a value for the app's [Title.title], which the device uses +/// to identify the app for the user. The `context` includes the [WidgetsApp]'s +/// [Localizations] widget so that this method can be used to produce a +/// localized title. +/// +/// This function must not return null. +typedef GenerateAppTitle = String Function(BuildContext context); + +/// The signature of [WidgetsApp.pageRouteBuilder]. +/// +/// Creates a [PageRoute] using the given [RouteSettings] and [WidgetBuilder]. +typedef PageRouteFactory = PageRoute<T> Function<T>(RouteSettings settings, WidgetBuilder builder); + +/// The signature of [WidgetsApp.onGenerateInitialRoutes]. +/// +/// Creates a series of one or more initial routes. +typedef InitialRouteListFactory = List<Route<dynamic>> Function(String initialRoute); + +/// A convenience widget that wraps a number of widgets that are commonly +/// required for an application. +/// +/// One of the primary roles that [WidgetsApp] provides is binding the system +/// back button to popping the [Navigator] or quitting the application. +/// +/// It is used by both [MaterialApp] and [CupertinoApp] to implement base +/// functionality for an app. +/// +/// Find references to many of the widgets that [WidgetsApp] wraps in the "See +/// also" section. +/// +/// See also: +/// +/// * [CheckedModeBanner], which displays a [Banner] saying "DEBUG" when +/// running in debug mode. +/// * [DefaultTextStyle], the text style to apply to descendant [Text] widgets +/// without an explicit style. +/// * [MediaQuery], which establishes a subtree in which media queries resolve +/// to a [MediaQueryData]. +/// * [Localizations], which defines the [Locale] for its `child`. +/// * [Title], a widget that describes this app in the operating system. +/// * [Navigator], a widget that manages a set of child widgets with a stack +/// discipline. +/// * [Overlay], a widget that manages a [Stack] of entries that can be managed +/// independently. +/// * [SemanticsDebugger], a widget that visualizes the semantics for the child. +class WidgetsApp extends StatefulWidget { + /// Creates a widget that wraps a number of widgets that are commonly + /// required for an application. + /// + /// Most callers will want to use the [home] or [routes] parameters, or both. + /// The [home] parameter is a convenience for the following [routes] map: + /// + /// ```dart + /// <String, WidgetBuilder>{ '/': (BuildContext context) => myWidget } + /// ``` + /// + /// It is possible to specify both [home] and [routes], but only if [routes] does + /// _not_ contain an entry for `'/'`. Conversely, if [home] is omitted, [routes] + /// _must_ contain an entry for `'/'`. + /// + /// If [home] or [routes] are not null, the routing implementation needs to know how + /// appropriately build [PageRoute]s. This can be achieved by supplying the + /// [pageRouteBuilder] parameter. The [pageRouteBuilder] is used by [MaterialApp] + /// and [CupertinoApp] to create [MaterialPageRoute]s and [CupertinoPageRoute], + /// respectively. + /// + /// The [builder] parameter is designed to provide the ability to wrap the visible + /// content of the app in some other widget. It is recommended that you use [home] + /// rather than [builder] if you intend to only display a single route in your app. + /// + /// [WidgetsApp] is also possible to provide a custom implementation of routing via the + /// [onGenerateRoute] and [onUnknownRoute] parameters. These parameters correspond + /// to [Navigator.onGenerateRoute] and [Navigator.onUnknownRoute]. If [home], [routes], + /// and [builder] are null, or if they fail to create a requested route, + /// [onGenerateRoute] will be invoked. If that fails, [onUnknownRoute] will be invoked. + /// + /// The [pageRouteBuilder] is called to create a [PageRoute] that wraps newly built routes. + /// If the [builder] is non-null and the [onGenerateRoute] argument is null, then the + /// [builder] will be provided only with the context and the child widget, whereas + /// the [pageRouteBuilder] will be provided with [RouteSettings]; in that configuration, + /// the [navigatorKey], [onUnknownRoute], [navigatorObservers], and + /// [initialRoute] properties must have their default values, as they will have no effect. + /// + /// The `supportedLocales` argument must be a list of one or more elements. + /// By default supportedLocales is `[const Locale('en', 'US')]`. + /// + /// {@tool dartpad} + /// This sample shows a basic Flutter application using [WidgetsApp]. + /// + /// ** See code in examples/api/lib/widgets/app/widgets_app.widgets_app.0.dart ** + /// {@end-tool} + WidgetsApp({ // can't be const because the asserts use methods on Iterable :-( + super.key, + this.navigatorKey, + this.onGenerateRoute, + this.onGenerateInitialRoutes, + this.onUnknownRoute, + this.onNavigationNotification, + List<NavigatorObserver> this.navigatorObservers = const <NavigatorObserver>[], + this.initialRoute, + this.pageRouteBuilder, + this.home, + Map<String, WidgetBuilder> this.routes = const <String, WidgetBuilder>{}, + this.builder, + this.title = '', + this.onGenerateTitle, + this.textStyle, + required this.color, + this.locale, + this.localizationsDelegates, + this.localeListResolutionCallback, + this.localeResolutionCallback, + this.supportedLocales = const <Locale>[Locale('en', 'US')], + this.showPerformanceOverlay = false, + this.checkerboardRasterCacheImages = false, + this.checkerboardOffscreenLayers = false, + this.showSemanticsDebugger = false, + this.debugShowWidgetInspector = false, + this.debugShowCheckedModeBanner = true, + this.inspectorSelectButtonBuilder, + this.shortcuts, + this.actions, + this.restorationScopeId, + @Deprecated( + 'Remove this parameter as it is now ignored. ' + 'WidgetsApp never introduces its own MediaQuery; the View widget takes care of that. ' + 'This feature was deprecated after v3.7.0-29.0.pre.' + ) + this.useInheritedMediaQuery = false, + }) : assert( + home == null || + onGenerateInitialRoutes == null, + 'If onGenerateInitialRoutes is specified, the home argument will be ' + 'redundant.', + ), + assert( + home == null || + !routes.containsKey(Navigator.defaultRouteName), + 'If the home property is specified, the routes table ' + 'cannot include an entry for "/", since it would be redundant.', + ), + assert( + builder != null || + home != null || + routes.containsKey(Navigator.defaultRouteName) || + onGenerateRoute != null || + onUnknownRoute != null, + 'Either the home property must be specified, ' + 'or the routes table must include an entry for "/", ' + 'or there must be on onGenerateRoute callback specified, ' + 'or there must be an onUnknownRoute callback specified, ' + 'or the builder property must be specified, ' + 'because otherwise there is nothing to fall back on if the ' + 'app is started with an intent that specifies an unknown route.', + ), + assert( + (home != null || + routes.isNotEmpty || + onGenerateRoute != null || + onUnknownRoute != null) + || + (builder != null && + navigatorKey == null && + initialRoute == null && + navigatorObservers.isEmpty), + 'If no route is provided using ' + 'home, routes, onGenerateRoute, or onUnknownRoute, ' + 'a non-null callback for the builder property must be provided, ' + 'and the other navigator-related properties, ' + 'navigatorKey, initialRoute, and navigatorObservers, ' + 'must have their initial values ' + '(null, null, and the empty list, respectively).', + ), + assert( + builder != null || + onGenerateRoute != null || + pageRouteBuilder != null, + 'If neither builder nor onGenerateRoute are provided, the ' + 'pageRouteBuilder must be specified so that the default handler ' + 'will know what kind of PageRoute transition to build.', + ), + assert(supportedLocales.isNotEmpty), + routeInformationProvider = null, + routeInformationParser = null, + routerDelegate = null, + backButtonDispatcher = null, + routerConfig = null; + + /// Creates a [WidgetsApp] that uses the [Router] instead of a [Navigator]. + /// + /// {@template flutter.widgets.WidgetsApp.router} + /// If the [routerConfig] is provided, the other router related delegates, + /// [routeInformationParser], [routeInformationProvider], [routerDelegate], + /// and [backButtonDispatcher], must all be null. + /// {@endtemplate} + WidgetsApp.router({ + super.key, + this.routeInformationProvider, + this.routeInformationParser, + this.routerDelegate, + this.routerConfig, + this.backButtonDispatcher, + this.builder, + this.title = '', + this.onGenerateTitle, + this.onNavigationNotification, + this.textStyle, + required this.color, + this.locale, + this.localizationsDelegates, + this.localeListResolutionCallback, + this.localeResolutionCallback, + this.supportedLocales = const <Locale>[Locale('en', 'US')], + this.showPerformanceOverlay = false, + this.checkerboardRasterCacheImages = false, + this.checkerboardOffscreenLayers = false, + this.showSemanticsDebugger = false, + this.debugShowWidgetInspector = false, + this.debugShowCheckedModeBanner = true, + this.inspectorSelectButtonBuilder, + this.shortcuts, + this.actions, + this.restorationScopeId, + @Deprecated( + 'Remove this parameter as it is now ignored. ' + 'WidgetsApp never introduces its own MediaQuery; the View widget takes care of that. ' + 'This feature was deprecated after v3.7.0-29.0.pre.' + ) + this.useInheritedMediaQuery = false, + }) : assert((){ + if (routerConfig != null) { + assert( + (routeInformationProvider ?? routeInformationParser ?? routerDelegate ?? backButtonDispatcher) == null, + 'If the routerConfig is provided, all the other router delegates must not be provided', + ); + return true; + } + assert(routerDelegate != null, 'Either one of routerDelegate or routerConfig must be provided'); + assert( + routeInformationProvider == null || routeInformationParser != null, + 'If routeInformationProvider is provided, routeInformationParser must also be provided', + ); + return true; + }()), + assert(supportedLocales.isNotEmpty), + navigatorObservers = null, + navigatorKey = null, + onGenerateRoute = null, + pageRouteBuilder = null, + home = null, + onGenerateInitialRoutes = null, + onUnknownRoute = null, + routes = null, + initialRoute = null; + + /// {@template flutter.widgets.widgetsApp.navigatorKey} + /// A key to use when building the [Navigator]. + /// + /// If a [navigatorKey] is specified, the [Navigator] can be directly + /// manipulated without first obtaining it from a [BuildContext] via + /// [Navigator.of]: from the [navigatorKey], use the [GlobalKey.currentState] + /// getter. + /// + /// If this is changed, a new [Navigator] will be created, losing all the + /// application state in the process; in that case, the [navigatorObservers] + /// must also be changed, since the previous observers will be attached to the + /// previous navigator. + /// + /// The [Navigator] is only built if [onGenerateRoute] is not null; if it is + /// null, [navigatorKey] must also be null. + /// {@endtemplate} + final GlobalKey<NavigatorState>? navigatorKey; + + /// {@template flutter.widgets.widgetsApp.onGenerateRoute} + /// The route generator callback used when the app is navigated to a + /// named route. + /// + /// If this returns null when building the routes to handle the specified + /// [initialRoute], then all the routes are discarded and + /// [Navigator.defaultRouteName] is used instead (`/`). See [initialRoute]. + /// + /// During normal app operation, the [onGenerateRoute] callback will only be + /// applied to route names pushed by the application, and so should never + /// return null. + /// + /// This is used if [routes] does not contain the requested route. + /// + /// The [Navigator] is only built if routes are provided (either via [home], + /// [routes], [onGenerateRoute], or [onUnknownRoute]); if they are not, + /// [builder] must not be null. + /// {@endtemplate} + /// + /// If this property is not set, either the [routes] or [home] properties must + /// be set, and the [pageRouteBuilder] must also be set so that the + /// default handler will know what routes and [PageRoute]s to build. + final RouteFactory? onGenerateRoute; + + /// {@template flutter.widgets.widgetsApp.onGenerateInitialRoutes} + /// The routes generator callback used for generating initial routes if + /// [initialRoute] is provided. + /// + /// If this property is not set, the underlying + /// [Navigator.onGenerateInitialRoutes] will default to + /// [Navigator.defaultGenerateInitialRoutes]. + /// {@endtemplate} + final InitialRouteListFactory? onGenerateInitialRoutes; + + /// The [PageRoute] generator callback used when the app is navigated to a + /// named route. + /// + /// A [PageRoute] represents the page in a [Navigator], so that it can + /// correctly animate between pages, and to represent the "return value" of + /// a route (e.g. which button a user selected in a modal dialog). + /// + /// This callback can be used, for example, to specify that a [MaterialPageRoute] + /// or a [CupertinoPageRoute] should be used for building page transitions. + /// + /// The [PageRouteFactory] type is generic, meaning the provided function must + /// itself be generic. For example (with special emphasis on the `<T>` at the + /// start of the closure): + /// + /// ```dart + /// pageRouteBuilder: <T>(RouteSettings settings, WidgetBuilder builder) => PageRouteBuilder<T>( + /// settings: settings, + /// pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) => builder(context), + /// ), + /// ``` + final PageRouteFactory? pageRouteBuilder; + + /// {@template flutter.widgets.widgetsApp.routeInformationParser} + /// A delegate to parse the route information from the + /// [routeInformationProvider] into a generic data type to be processed by + /// the [routerDelegate] at a later stage. + /// + /// This object will be used by the underlying [Router]. + /// + /// The generic type `T` must match the generic type of the [routerDelegate]. + /// + /// See also: + /// + /// * [Router.routeInformationParser], which receives this object when this + /// widget builds the [Router]. + /// {@endtemplate} + final RouteInformationParser<Object>? routeInformationParser; + + /// {@template flutter.widgets.widgetsApp.routerDelegate} + /// A delegate that configures a widget, typically a [Navigator], with + /// parsed result from the [routeInformationParser]. + /// + /// This object will be used by the underlying [Router]. + /// + /// The generic type `T` must match the generic type of the + /// [routeInformationParser]. + /// + /// See also: + /// + /// * [Router.routerDelegate], which receives this object when this widget + /// builds the [Router]. + /// {@endtemplate} + final RouterDelegate<Object>? routerDelegate; + + /// {@template flutter.widgets.widgetsApp.backButtonDispatcher} + /// A delegate that decide whether to handle the Android back button intent. + /// + /// This object will be used by the underlying [Router]. + /// + /// If this is not provided, the widgets app will create a + /// [RootBackButtonDispatcher] by default. + /// + /// See also: + /// + /// * [Router.backButtonDispatcher], which receives this object when this + /// widget builds the [Router]. + /// {@endtemplate} + final BackButtonDispatcher? backButtonDispatcher; + + /// {@template flutter.widgets.widgetsApp.routeInformationProvider} + /// A object that provides route information through the + /// [RouteInformationProvider.value] and notifies its listener when its value + /// changes. + /// + /// This object will be used by the underlying [Router]. + /// + /// If this is not provided, the widgets app will create a + /// [PlatformRouteInformationProvider] with initial route name equal to the + /// [dart:ui.PlatformDispatcher.defaultRouteName] by default. + /// + /// See also: + /// + /// * [Router.routeInformationProvider], which receives this object when this + /// widget builds the [Router]. + /// {@endtemplate} + final RouteInformationProvider? routeInformationProvider; + + /// {@template flutter.widgets.widgetsApp.routerConfig} + /// An object to configure the underlying [Router]. + /// + /// If the [routerConfig] is provided, the other router related delegates, + /// [routeInformationParser], [routeInformationProvider], [routerDelegate], + /// and [backButtonDispatcher], must all be null. + /// + /// See also: + /// + /// * [Router.withConfig], which receives this object when this + /// widget builds the [Router]. + /// {@endtemplate} + final RouterConfig<Object>? routerConfig; + + /// {@template flutter.widgets.widgetsApp.home} + /// The widget for the default route of the app ([Navigator.defaultRouteName], + /// which is `/`). + /// + /// This is the route that is displayed first when the application is started + /// normally, unless [initialRoute] is specified. It's also the route that's + /// displayed if the [initialRoute] can't be displayed. + /// + /// To be able to directly call [Theme.of], [MediaQuery.of], etc, in the code + /// that sets the [home] argument in the constructor, you can use a [Builder] + /// widget to get a [BuildContext]. + /// + /// If [home] is specified, then [routes] must not include an entry for `/`, + /// as [home] takes its place. + /// + /// The [Navigator] is only built if routes are provided (either via [home], + /// [routes], [onGenerateRoute], or [onUnknownRoute]); if they are not, + /// [builder] must not be null. + /// + /// The difference between using [home] and using [builder] is that the [home] + /// subtree is inserted into the application below a [Navigator] (and thus + /// below an [Overlay], which [Navigator] uses). With [home], therefore, + /// dialog boxes will work automatically, the [routes] table will be used, and + /// APIs such as [Navigator.push] and [Navigator.pop] will work as expected. + /// In contrast, the widget returned from [builder] is inserted _above_ the + /// app's [Navigator] (if any). + /// {@endtemplate} + /// + /// If this property is set, the [pageRouteBuilder] property must also be set + /// so that the default route handler will know what kind of [PageRoute]s to + /// build. + final Widget? home; + + /// The application's top-level routing table. + /// + /// When a named route is pushed with [Navigator.pushNamed], the route name is + /// looked up in this map. If the name is present, the associated + /// [widgets.WidgetBuilder] is used to construct a [PageRoute] specified by + /// [pageRouteBuilder] to perform an appropriate transition, including [Hero] + /// animations, to the new route. + /// + /// {@template flutter.widgets.widgetsApp.routes} + /// If the app only has one page, then you can specify it using [home] instead. + /// + /// If [home] is specified, then it implies an entry in this table for the + /// [Navigator.defaultRouteName] route (`/`), and it is an error to + /// redundantly provide such a route in the [routes] table. + /// + /// If a route is requested that is not specified in this table (or by + /// [home]), then the [onGenerateRoute] callback is called to build the page + /// instead. + /// + /// The [Navigator] is only built if routes are provided (either via [home], + /// [routes], [onGenerateRoute], or [onUnknownRoute]); if they are not, + /// [builder] must not be null. + /// {@endtemplate} + /// + /// If the routes map is not empty, the [pageRouteBuilder] property must be set + /// so that the default route handler will know what kind of [PageRoute]s to + /// build. + final Map<String, WidgetBuilder>? routes; + + /// {@template flutter.widgets.widgetsApp.onUnknownRoute} + /// Called when [onGenerateRoute] fails to generate a route, except for the + /// [initialRoute]. + /// + /// This callback is typically used for error handling. For example, this + /// callback might always generate a "not found" page that describes the route + /// that wasn't found. + /// + /// Unknown routes can arise either from errors in the app or from external + /// requests to push routes, such as from Android intents. + /// + /// The [Navigator] is only built if routes are provided (either via [home], + /// [routes], [onGenerateRoute], or [onUnknownRoute]); if they are not, + /// [builder] must not be null. + /// {@endtemplate} + final RouteFactory? onUnknownRoute; + + /// {@template flutter.widgets.widgetsApp.onNavigationNotification} + /// The callback to use when receiving a [NavigationNotification]. + /// + /// By default this updates the engine with the navigation status. + /// {@endtemplate} + final NotificationListenerCallback<NavigationNotification>? onNavigationNotification; + + /// {@template flutter.widgets.widgetsApp.initialRoute} + /// The name of the first route to show, if a [Navigator] is built. + /// + /// Defaults to [dart:ui.PlatformDispatcher.defaultRouteName], which may be + /// overridden by the code that launched the application. + /// + /// If the route name starts with a slash, then it is treated as a "deep link", + /// and before this route is pushed, the routes leading to this one are pushed + /// also. For example, if the route was `/a/b/c`, then the app would start + /// with the four routes `/`, `/a`, `/a/b`, and `/a/b/c` loaded, in that order. + /// Even if the route was just `/a`, the app would start with `/` and `/a` + /// loaded. You can use the [onGenerateInitialRoutes] property to override + /// this behavior. + /// + /// Intermediate routes aren't required to exist. In the example above, `/a` + /// and `/a/b` could be skipped if they have no matching route. But `/a/b/c` is + /// required to have a route, else [initialRoute] is ignored and + /// [Navigator.defaultRouteName] is used instead (`/`). This can happen if the + /// app is started with an intent that specifies a non-existent route. + /// + /// The [Navigator] is only built if routes are provided (either via [home], + /// [routes], [onGenerateRoute], or [onUnknownRoute]); if they are not, + /// [initialRoute] must be null and [builder] must not be null. + /// + /// Changing the [initialRoute] will have no effect, as it only controls the + /// _initial_ route. To change the route while the application is running, use + /// the [Navigator] or [Router] APIs. + /// + /// See also: + /// + /// * [Navigator.initialRoute], which is used to implement this property. + /// * [Navigator.push], for pushing additional routes. + /// * [Navigator.pop], for removing a route from the stack. + /// + /// {@endtemplate} + final String? initialRoute; + + /// {@template flutter.widgets.widgetsApp.navigatorObservers} + /// The list of observers for the [Navigator] created for this app. + /// + /// This list must be replaced by a list of newly-created observers if the + /// [navigatorKey] is changed. + /// + /// The [Navigator] is only built if routes are provided (either via [home], + /// [routes], [onGenerateRoute], or [onUnknownRoute]); if they are not, + /// [navigatorObservers] must be the empty list and [builder] must not be null. + /// {@endtemplate} + final List<NavigatorObserver>? navigatorObservers; + + /// {@template flutter.widgets.widgetsApp.builder} + /// A builder for inserting widgets above the [Navigator] or - when the + /// [WidgetsApp.router] constructor is used - above the [Router] but below the + /// other widgets created by the [WidgetsApp] widget, or for replacing the + /// [Navigator]/[Router] entirely. + /// + /// For example, from the [BuildContext] passed to this method, the + /// [Directionality], [Localizations], [DefaultTextStyle], [MediaQuery], etc, + /// are all available. They can also be overridden in a way that impacts all + /// the routes in the [Navigator] or [Router]. + /// + /// This is rarely useful, but can be used in applications that wish to + /// override those defaults, e.g. to force the application into right-to-left + /// mode despite being in English, or to override the [MediaQuery] metrics + /// (e.g. to leave a gap for advertisements shown by a plugin from OEM code). + /// + /// For specifically overriding the [title] with a value based on the + /// [Localizations], consider [onGenerateTitle] instead. + /// + /// The [builder] callback is passed two arguments, the [BuildContext] (as + /// `context`) and a [Navigator] or [Router] widget (as `child`). + /// + /// If no routes are provided to the regular [WidgetsApp] constructor using + /// [home], [routes], [onGenerateRoute], or [onUnknownRoute], the `child` will + /// be null, and it is the responsibility of the [builder] to provide the + /// application's routing machinery. + /// + /// If routes _are_ provided to the regular [WidgetsApp] constructor using one + /// or more of those properties or if the [WidgetsApp.router] constructor is + /// used, then `child` is not null, and the returned value should include the + /// `child` in the widget subtree; if it does not, then the application will + /// have no [Navigator] or [Router] and the routing related properties (i.e. + /// [navigatorKey], [home], [routes], [onGenerateRoute], [onUnknownRoute], + /// [initialRoute], [navigatorObservers], [routeInformationProvider], + /// [backButtonDispatcher], [routerDelegate], and [routeInformationParser]) + /// are ignored. + /// + /// If [builder] is null, it is as if a builder was specified that returned + /// the `child` directly. If it is null, routes must be provided using one of + /// the other properties listed above. + /// + /// Unless a [Navigator] is provided, either implicitly from [builder] being + /// null, or by a [builder] including its `child` argument, or by a [builder] + /// explicitly providing a [Navigator] of its own, or by the [routerDelegate] + /// building one, widgets and APIs such as [Hero], [Navigator.push] and + /// [Navigator.pop], will not function. + /// {@endtemplate} + final TransitionBuilder? builder; + + /// {@template flutter.widgets.widgetsApp.title} + /// A one-line description used by the device to identify the app for the user. + /// + /// On Android the titles appear above the task manager's app snapshots which are + /// displayed when the user presses the "recent apps" button. On iOS this + /// value cannot be used. `CFBundleDisplayName` from the app's `Info.plist` is + /// referred to instead whenever present, `CFBundleName` otherwise. + /// On the web it is used as the page title, which shows up in the browser's list of open tabs. + /// + /// To provide a localized title instead, use [onGenerateTitle]. + /// {@endtemplate} + final String title; + + /// {@template flutter.widgets.widgetsApp.onGenerateTitle} + /// If non-null this callback function is called to produce the app's + /// title string, otherwise [title] is used. + /// + /// The [onGenerateTitle] `context` parameter includes the [WidgetsApp]'s + /// [Localizations] widget so that this callback can be used to produce a + /// localized title. + /// + /// This callback function must not return null. + /// + /// The [onGenerateTitle] callback is called each time the [WidgetsApp] + /// rebuilds. + /// {@endtemplate} + final GenerateAppTitle? onGenerateTitle; + + /// The default text style for [Text] in the application. + final TextStyle? textStyle; + + /// {@template flutter.widgets.widgetsApp.color} + /// The primary color to use for the application in the operating system + /// interface. + /// + /// For example, on Android this is the color used for the application in the + /// application switcher. + /// {@endtemplate} + final Color color; + + /// {@template flutter.widgets.widgetsApp.locale} + /// The initial locale for this app's [Localizations] widget is based + /// on this value. + /// + /// If the 'locale' is null then the system's locale value is used. + /// + /// The value of [Localizations.locale] will equal this locale if + /// it matches one of the [supportedLocales]. Otherwise it will be + /// the first element of [supportedLocales]. + /// {@endtemplate} + /// + /// See also: + /// + /// * [localeResolutionCallback], which can override the default + /// [supportedLocales] matching algorithm. + /// * [localizationsDelegates], which collectively define all of the localized + /// resources used by this app. + final Locale? locale; + + /// {@template flutter.widgets.widgetsApp.localizationsDelegates} + /// The delegates for this app's [Localizations] widget. + /// + /// The delegates collectively define all of the localized resources + /// for this application's [Localizations] widget. + /// {@endtemplate} + final Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates; + + /// {@template flutter.widgets.widgetsApp.localeListResolutionCallback} + /// This callback is responsible for choosing the app's locale + /// when the app is started, and when the user changes the + /// device's locale. + /// + /// When a [localeListResolutionCallback] is provided, Flutter will first + /// attempt to resolve the locale with the provided + /// [localeListResolutionCallback]. If the callback or result is null, it will + /// fallback to trying the [localeResolutionCallback]. If both + /// [localeResolutionCallback] and [localeListResolutionCallback] are left + /// null or fail to resolve (return null), basic fallback algorithm will + /// be used. + /// + /// The priority of each available fallback is: + /// + /// 1. [localeListResolutionCallback] is attempted. + /// 2. [localeResolutionCallback] is attempted. + /// 3. Flutter's basic resolution algorithm, as described in + /// [supportedLocales], is attempted last. + /// + /// Properly localized projects should provide a more advanced algorithm than + /// the basic method from [supportedLocales], as it does not implement a + /// complete algorithm (such as the one defined in + /// [Unicode TR35](https://unicode.org/reports/tr35/#LanguageMatching)) + /// and is optimized for speed at the detriment of some uncommon edge-cases. + /// {@endtemplate} + /// + /// This callback considers the entire list of preferred locales. + /// + /// This algorithm should be able to handle a null or empty list of preferred locales, + /// which indicates Flutter has not yet received locale information from the platform. + /// + /// See also: + /// + /// * [MaterialApp.localeListResolutionCallback], which sets the callback of the + /// [WidgetsApp] it creates. + /// * [basicLocaleListResolution], the default locale resolution algorithm. + final LocaleListResolutionCallback? localeListResolutionCallback; + + /// {@macro flutter.widgets.widgetsApp.localeListResolutionCallback} + /// + /// This callback considers only the default locale, which is the first locale + /// in the preferred locales list. It is preferred to set [localeListResolutionCallback] + /// over [localeResolutionCallback] as it provides the full preferred locales list. + /// + /// This algorithm should be able to handle a null locale, which indicates + /// Flutter has not yet received locale information from the platform. + /// + /// See also: + /// + /// * [MaterialApp.localeResolutionCallback], which sets the callback of the + /// [WidgetsApp] it creates. + /// * [basicLocaleListResolution], the default locale resolution algorithm. + final LocaleResolutionCallback? localeResolutionCallback; + + /// {@template flutter.widgets.widgetsApp.supportedLocales} + /// The list of locales that this app has been localized for. + /// + /// By default only the American English locale is supported. Apps should + /// configure this list to match the locales they support. + /// + /// This list must not null. Its default value is just + /// `[const Locale('en', 'US')]`. + /// + /// The order of the list matters. The default locale resolution algorithm, + /// [basicLocaleListResolution], attempts to match by the following priority: + /// + /// 1. [Locale.languageCode], [Locale.scriptCode], and [Locale.countryCode] + /// 2. [Locale.languageCode] and [Locale.scriptCode] only + /// 3. [Locale.languageCode] and [Locale.countryCode] only + /// 4. [Locale.languageCode] only + /// 5. [Locale.countryCode] only when all preferred locales fail to match + /// 6. Returns the first element of [supportedLocales] as a fallback + /// + /// When more than one supported locale matches one of these criteria, only + /// the first matching locale is returned. + /// + /// The default locale resolution algorithm can be overridden by providing a + /// value for [localeListResolutionCallback]. The provided + /// [basicLocaleListResolution] is optimized for speed and does not implement + /// a full algorithm (such as the one defined in + /// [Unicode TR35](https://unicode.org/reports/tr35/#LanguageMatching)) that + /// takes distances between languages into account. + /// + /// When supporting languages with more than one script, it is recommended + /// to specify the [Locale.scriptCode] explicitly. Locales may also be defined without + /// [Locale.countryCode] to specify a generic fallback for a particular script. + /// + /// A fully supported language with multiple scripts should define a generic language-only + /// locale (e.g. 'zh'), language+script only locales (e.g. 'zh_Hans' and 'zh_Hant'), + /// and any language+script+country locales (e.g. 'zh_Hans_CN'). Fully defining all of + /// these locales as supported is not strictly required but allows for proper locale resolution in + /// the most number of cases. These locales can be specified with the [Locale.fromSubtags] + /// constructor: + /// + /// ```dart + /// // Full Chinese support for CN, TW, and HK + /// supportedLocales: <Locale>[ + /// const Locale.fromSubtags(languageCode: 'zh'), // generic Chinese 'zh' + /// const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'), // generic simplified Chinese 'zh_Hans' + /// const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'), // generic traditional Chinese 'zh_Hant' + /// const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'CN'), // 'zh_Hans_CN' + /// const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'TW'), // 'zh_Hant_TW' + /// const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'HK'), // 'zh_Hant_HK' + /// ], + /// ``` + /// + /// Omitting some these fallbacks may result in improperly resolved + /// edge-cases, for example, a simplified Chinese user in Taiwan ('zh_Hans_TW') + /// may resolve to traditional Chinese if 'zh_Hans' and 'zh_Hans_CN' are + /// omitted. + /// {@endtemplate} + /// + /// See also: + /// + /// * [MaterialApp.supportedLocales], which sets the `supportedLocales` + /// of the [WidgetsApp] it creates. + /// * [localeResolutionCallback], an app callback that resolves the app's locale + /// when the device's locale changes. + /// * [localizationsDelegates], which collectively define all of the localized + /// resources used by this app. + /// * [basicLocaleListResolution], the default locale resolution algorithm. + final Iterable<Locale> supportedLocales; + + /// Turns on a performance overlay. + /// + /// See also: + /// + /// * <https://flutter.dev/debugging/#performance-overlay> + final bool showPerformanceOverlay; + + /// Checkerboards raster cache images. + /// + /// See [PerformanceOverlay.checkerboardRasterCacheImages]. + final bool checkerboardRasterCacheImages; + + /// Checkerboards layers rendered to offscreen bitmaps. + /// + /// See [PerformanceOverlay.checkerboardOffscreenLayers]. + final bool checkerboardOffscreenLayers; + + /// Turns on an overlay that shows the accessibility information + /// reported by the framework. + final bool showSemanticsDebugger; + + /// Turns on an overlay that enables inspecting the widget tree. + /// + /// The inspector is only available in debug mode as it depends on + /// [RenderObject.debugDescribeChildren] which should not be called outside of + /// debug mode. + final bool debugShowWidgetInspector; + + /// Builds the widget the [WidgetInspector] uses to switch between view and + /// inspect modes. + /// + /// This lets [MaterialApp] to use a Material Design button to toggle the + /// inspector select mode without requiring [WidgetInspector] to depend on the + /// material package. + final InspectorSelectButtonBuilder? inspectorSelectButtonBuilder; + + /// {@template flutter.widgets.widgetsApp.debugShowCheckedModeBanner} + /// Turns on a little "DEBUG" banner in debug mode to indicate + /// that the app is in debug mode. This is on by default (in + /// debug mode), to turn it off, set the constructor argument to + /// false. In release mode this has no effect. + /// + /// To get this banner in your application if you're not using + /// WidgetsApp, include a [CheckedModeBanner] widget in your app. + /// + /// This banner is intended to deter people from complaining that your + /// app is slow when it's in debug mode. In debug mode, Flutter + /// enables a large number of expensive diagnostics to aid in + /// development, and so performance in debug mode is not + /// representative of what will happen in release mode. + /// {@endtemplate} + final bool debugShowCheckedModeBanner; + + /// {@template flutter.widgets.widgetsApp.shortcuts} + /// The default map of keyboard shortcuts to intents for the application. + /// + /// By default, this is set to [WidgetsApp.defaultShortcuts]. + /// + /// Passing this will not replace [DefaultTextEditingShortcuts]. These can be + /// overridden by using a [Shortcuts] widget lower in the widget tree. + /// {@endtemplate} + /// + /// {@tool snippet} + /// This example shows how to add a single shortcut for + /// [LogicalKeyboardKey.select] to the default shortcuts without needing to + /// add your own [Shortcuts] widget. + /// + /// Alternatively, you could insert a [Shortcuts] widget with just the mapping + /// you want to add between the [WidgetsApp] and its child and get the same + /// effect. + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return WidgetsApp( + /// shortcuts: <ShortcutActivator, Intent>{ + /// ... WidgetsApp.defaultShortcuts, + /// const SingleActivator(LogicalKeyboardKey.select): const ActivateIntent(), + /// }, + /// color: const Color(0xFFFF0000), + /// builder: (BuildContext context, Widget? child) { + /// return const Placeholder(); + /// }, + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// {@template flutter.widgets.widgetsApp.shortcuts.seeAlso} + /// See also: + /// + /// * [SingleActivator], which defines shortcut key combination of a single + /// key and modifiers, such as "Delete" or "Control+C". + /// * The [Shortcuts] widget, which defines a keyboard mapping. + /// * The [Actions] widget, which defines the mapping from intent to action. + /// * The [Intent] and [Action] classes, which allow definition of new + /// actions. + /// {@endtemplate} + final Map<ShortcutActivator, Intent>? shortcuts; + + /// {@template flutter.widgets.widgetsApp.actions} + /// The default map of intent keys to actions for the application. + /// + /// By default, this is the output of [WidgetsApp.defaultActions], called with + /// [defaultTargetPlatform]. Specifying [actions] for an app overrides the + /// default, so if you wish to modify the default [actions], you can call + /// [WidgetsApp.defaultActions] and modify the resulting map, passing it as + /// the [actions] for this app. You may also add to the bindings, or override + /// specific bindings for a widget subtree, by adding your own [Actions] + /// widget. + /// {@endtemplate} + /// + /// {@tool snippet} + /// This example shows how to add a single action handling an + /// [ActivateAction] to the default actions without needing to + /// add your own [Actions] widget. + /// + /// Alternatively, you could insert a [Actions] widget with just the mapping + /// you want to add between the [WidgetsApp] and its child and get the same + /// effect. + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return WidgetsApp( + /// actions: <Type, Action<Intent>>{ + /// ... WidgetsApp.defaultActions, + /// ActivateAction: CallbackAction<Intent>( + /// onInvoke: (Intent intent) { + /// // Do something here... + /// return null; + /// }, + /// ), + /// }, + /// color: const Color(0xFFFF0000), + /// builder: (BuildContext context, Widget? child) { + /// return const Placeholder(); + /// }, + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// {@template flutter.widgets.widgetsApp.actions.seeAlso} + /// See also: + /// + /// * The [shortcuts] parameter, which defines the default set of shortcuts + /// for the application. + /// * The [Shortcuts] widget, which defines a keyboard mapping. + /// * The [Actions] widget, which defines the mapping from intent to action. + /// * The [Intent] and [Action] classes, which allow definition of new + /// actions. + /// {@endtemplate} + final Map<Type, Action<Intent>>? actions; + + /// {@template flutter.widgets.widgetsApp.restorationScopeId} + /// The identifier to use for state restoration of this app. + /// + /// Providing a restoration ID inserts a [RootRestorationScope] into the + /// widget hierarchy, which enables state restoration for descendant widgets. + /// + /// Providing a restoration ID also enables the [Navigator] or [Router] built + /// by the [WidgetsApp] to restore its state (i.e. to restore the history + /// stack of active [Route]s). See the documentation on [Navigator] for more + /// details around state restoration of [Route]s. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + /// {@endtemplate} + final String? restorationScopeId; + + /// {@template flutter.widgets.widgetsApp.useInheritedMediaQuery} + /// Deprecated. This setting is now ignored. + /// + /// The widget never introduces its own [MediaQuery]; the [View] widget takes + /// care of that. + /// {@endtemplate} + @Deprecated( + 'This setting is now ignored. ' + 'WidgetsApp never introduces its own MediaQuery; the View widget takes care of that. ' + 'This feature was deprecated after v3.7.0-29.0.pre.' + ) + final bool useInheritedMediaQuery; + + /// If true, forces the performance overlay to be visible in all instances. + /// + /// Used by the `showPerformanceOverlay` VM service extension. + static bool showPerformanceOverlayOverride = false; + + /// If true, forces the widget inspector to be visible. + /// + /// Overrides the `debugShowWidgetInspector` value set in [WidgetsApp]. + /// + /// Used by the `debugShowWidgetInspector` debugging extension. + /// + /// The inspector allows the selection of a location on your device or emulator + /// and view what widgets and render objects associated with it. An outline of + /// the selected widget and some summary information is shown on device and + /// more detailed information is shown in the IDE or DevTools. + static bool get debugShowWidgetInspectorOverride { + return _debugShowWidgetInspectorOverrideNotifier.value; + } + static set debugShowWidgetInspectorOverride(bool value) { + _debugShowWidgetInspectorOverrideNotifier.value = value; + } + + static final ValueNotifier<bool> _debugShowWidgetInspectorOverrideNotifier = ValueNotifier<bool>(false); + + /// If false, prevents the debug banner from being visible. + /// + /// Used by the `debugAllowBanner` VM service extension. + /// + /// This is how `flutter run` turns off the banner when you take a screen shot + /// with "s". + static bool debugAllowBannerOverride = true; + + static const Map<ShortcutActivator, Intent> _defaultShortcuts = <ShortcutActivator, Intent>{ + // Activation + SingleActivator(LogicalKeyboardKey.enter): ActivateIntent(), + SingleActivator(LogicalKeyboardKey.numpadEnter): ActivateIntent(), + SingleActivator(LogicalKeyboardKey.space): ActivateIntent(), + SingleActivator(LogicalKeyboardKey.gameButtonA): ActivateIntent(), + SingleActivator(LogicalKeyboardKey.select): ActivateIntent(), + + // Dismissal + SingleActivator(LogicalKeyboardKey.escape): DismissIntent(), + + // Keyboard traversal. + SingleActivator(LogicalKeyboardKey.tab): NextFocusIntent(), + SingleActivator(LogicalKeyboardKey.tab, shift: true): PreviousFocusIntent(), + SingleActivator(LogicalKeyboardKey.arrowLeft): DirectionalFocusIntent(TraversalDirection.left), + SingleActivator(LogicalKeyboardKey.arrowRight): DirectionalFocusIntent(TraversalDirection.right), + SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent(TraversalDirection.down), + SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent(TraversalDirection.up), + + // Scrolling + SingleActivator(LogicalKeyboardKey.arrowUp, control: true): ScrollIntent(direction: AxisDirection.up), + SingleActivator(LogicalKeyboardKey.arrowDown, control: true): ScrollIntent(direction: AxisDirection.down), + SingleActivator(LogicalKeyboardKey.arrowLeft, control: true): ScrollIntent(direction: AxisDirection.left), + SingleActivator(LogicalKeyboardKey.arrowRight, control: true): ScrollIntent(direction: AxisDirection.right), + SingleActivator(LogicalKeyboardKey.pageUp): ScrollIntent(direction: AxisDirection.up, type: ScrollIncrementType.page), + SingleActivator(LogicalKeyboardKey.pageDown): ScrollIntent(direction: AxisDirection.down, type: ScrollIncrementType.page), + }; + + // Default shortcuts for the web platform. + static const Map<ShortcutActivator, Intent> _defaultWebShortcuts = <ShortcutActivator, Intent>{ + // Activation + SingleActivator(LogicalKeyboardKey.space): PrioritizedIntents( + orderedIntents: <Intent>[ + ActivateIntent(), + ScrollIntent(direction: AxisDirection.down, type: ScrollIncrementType.page), + ], + ), + // On the web, enter activates buttons, but not other controls. + SingleActivator(LogicalKeyboardKey.enter): ButtonActivateIntent(), + SingleActivator(LogicalKeyboardKey.numpadEnter): ButtonActivateIntent(), + + // Dismissal + SingleActivator(LogicalKeyboardKey.escape): DismissIntent(), + + // Keyboard traversal. + SingleActivator(LogicalKeyboardKey.tab): NextFocusIntent(), + SingleActivator(LogicalKeyboardKey.tab, shift: true): PreviousFocusIntent(), + + // Scrolling + SingleActivator(LogicalKeyboardKey.arrowUp): ScrollIntent(direction: AxisDirection.up), + SingleActivator(LogicalKeyboardKey.arrowDown): ScrollIntent(direction: AxisDirection.down), + SingleActivator(LogicalKeyboardKey.arrowLeft): ScrollIntent(direction: AxisDirection.left), + SingleActivator(LogicalKeyboardKey.arrowRight): ScrollIntent(direction: AxisDirection.right), + SingleActivator(LogicalKeyboardKey.pageUp): ScrollIntent(direction: AxisDirection.up, type: ScrollIncrementType.page), + SingleActivator(LogicalKeyboardKey.pageDown): ScrollIntent(direction: AxisDirection.down, type: ScrollIncrementType.page), + }; + + // Default shortcuts for the macOS platform. + static const Map<ShortcutActivator, Intent> _defaultAppleOsShortcuts = <ShortcutActivator, Intent>{ + // Activation + SingleActivator(LogicalKeyboardKey.enter): ActivateIntent(), + SingleActivator(LogicalKeyboardKey.numpadEnter): ActivateIntent(), + SingleActivator(LogicalKeyboardKey.space): ActivateIntent(), + + // Dismissal + SingleActivator(LogicalKeyboardKey.escape): DismissIntent(), + + // Keyboard traversal + SingleActivator(LogicalKeyboardKey.tab): NextFocusIntent(), + SingleActivator(LogicalKeyboardKey.tab, shift: true): PreviousFocusIntent(), + SingleActivator(LogicalKeyboardKey.arrowLeft): DirectionalFocusIntent(TraversalDirection.left), + SingleActivator(LogicalKeyboardKey.arrowRight): DirectionalFocusIntent(TraversalDirection.right), + SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent(TraversalDirection.down), + SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent(TraversalDirection.up), + + // Scrolling + SingleActivator(LogicalKeyboardKey.arrowUp, meta: true): ScrollIntent(direction: AxisDirection.up), + SingleActivator(LogicalKeyboardKey.arrowDown, meta: true): ScrollIntent(direction: AxisDirection.down), + SingleActivator(LogicalKeyboardKey.arrowLeft, meta: true): ScrollIntent(direction: AxisDirection.left), + SingleActivator(LogicalKeyboardKey.arrowRight, meta: true): ScrollIntent(direction: AxisDirection.right), + SingleActivator(LogicalKeyboardKey.pageUp): ScrollIntent(direction: AxisDirection.up, type: ScrollIncrementType.page), + SingleActivator(LogicalKeyboardKey.pageDown): ScrollIntent(direction: AxisDirection.down, type: ScrollIncrementType.page), + }; + + /// Generates the default shortcut key bindings based on the + /// [defaultTargetPlatform]. + /// + /// Used by [WidgetsApp] to assign a default value to [WidgetsApp.shortcuts]. + static Map<ShortcutActivator, Intent> get defaultShortcuts { + if (kIsWeb) { + return _defaultWebShortcuts; + } + + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return _defaultShortcuts; + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return _defaultAppleOsShortcuts; + } + } + + /// The default value of [WidgetsApp.actions]. + static Map<Type, Action<Intent>> defaultActions = <Type, Action<Intent>>{ + DoNothingIntent: DoNothingAction(), + DoNothingAndStopPropagationIntent: DoNothingAction(consumesKey: false), + RequestFocusIntent: RequestFocusAction(), + NextFocusIntent: NextFocusAction(), + PreviousFocusIntent: PreviousFocusAction(), + DirectionalFocusIntent: DirectionalFocusAction(), + ScrollIntent: ScrollAction(), + PrioritizedIntents: PrioritizedAction(), + VoidCallbackIntent: VoidCallbackAction(), + }; + + @override + State<WidgetsApp> createState() => _WidgetsAppState(); +} + +class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver { + // STATE LIFECYCLE + + // If window.defaultRouteName isn't '/', we should assume it was set + // intentionally via `setInitialRoute`, and should override whatever is in + // [widget.initialRoute]. + String get _initialRouteName => WidgetsBinding.instance.platformDispatcher.defaultRouteName != Navigator.defaultRouteName + ? WidgetsBinding.instance.platformDispatcher.defaultRouteName + : widget.initialRoute ?? WidgetsBinding.instance.platformDispatcher.defaultRouteName; + + AppLifecycleState? _appLifecycleState; + + /// The default value for [onNavigationNotification]. + /// + /// Does nothing and stops bubbling if the app is detached. Otherwise, updates + /// the platform with [NavigationNotification.canHandlePop] and stops + /// bubbling. + bool _defaultOnNavigationNotification(NavigationNotification notification) { + switch (_appLifecycleState) { + case null: + case AppLifecycleState.detached: + case AppLifecycleState.inactive: + // Avoid updating the engine when the app isn't ready. + return true; + case AppLifecycleState.resumed: + case AppLifecycleState.hidden: + case AppLifecycleState.paused: + SystemNavigator.setFrameworkHandlesBack(notification.canHandlePop); + return true; + } + } + + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + _appLifecycleState = state; + super.didChangeAppLifecycleState(state); + } + + @override + void initState() { + super.initState(); + _updateRouting(); + _locale = _resolveLocales(WidgetsBinding.instance.platformDispatcher.locales, widget.supportedLocales); + WidgetsBinding.instance.addObserver(this); + _appLifecycleState = WidgetsBinding.instance.lifecycleState; + } + + @override + void didUpdateWidget(WidgetsApp oldWidget) { + super.didUpdateWidget(oldWidget); + _updateRouting(oldWidget: oldWidget); + } + + @override + void dispose() { + WidgetsBinding.instance.removeObserver(this); + _defaultRouteInformationProvider?.dispose(); + super.dispose(); + } + + void _clearRouterResource() { + _defaultRouteInformationProvider?.dispose(); + _defaultRouteInformationProvider = null; + _defaultBackButtonDispatcher = null; + } + + void _clearNavigatorResource() { + _navigator = null; + } + + void _updateRouting({WidgetsApp? oldWidget}) { + if (_usesRouterWithDelegates) { + assert(!_usesNavigator && !_usesRouterWithConfig); + _clearNavigatorResource(); + if (widget.routeInformationProvider == null && widget.routeInformationParser != null) { + _defaultRouteInformationProvider ??= PlatformRouteInformationProvider( + initialRouteInformation: RouteInformation( + uri: Uri.parse(_initialRouteName), + ), + ); + } else { + _defaultRouteInformationProvider?.dispose(); + _defaultRouteInformationProvider = null; + } + if (widget.backButtonDispatcher == null) { + _defaultBackButtonDispatcher ??= RootBackButtonDispatcher(); + } + + } else if (_usesNavigator) { + assert(!_usesRouterWithDelegates && !_usesRouterWithConfig); + _clearRouterResource(); + if (_navigator == null || widget.navigatorKey != oldWidget!.navigatorKey) { + _navigator = widget.navigatorKey ?? GlobalObjectKey<NavigatorState>(this); + } + assert(_navigator != null); + } else { + assert(widget.builder != null || _usesRouterWithConfig); + assert(!_usesRouterWithDelegates && !_usesNavigator); + _clearRouterResource(); + _clearNavigatorResource(); + } + // If we use a navigator, we have a navigator key. + assert(_usesNavigator == (_navigator != null)); + } + + bool get _usesRouterWithDelegates => widget.routerDelegate != null; + bool get _usesRouterWithConfig => widget.routerConfig != null; + bool get _usesNavigator => widget.home != null + || (widget.routes?.isNotEmpty ?? false) + || widget.onGenerateRoute != null + || widget.onUnknownRoute != null; + + // ROUTER + + RouteInformationProvider? get _effectiveRouteInformationProvider => widget.routeInformationProvider ?? _defaultRouteInformationProvider; + PlatformRouteInformationProvider? _defaultRouteInformationProvider; + BackButtonDispatcher get _effectiveBackButtonDispatcher => widget.backButtonDispatcher ?? _defaultBackButtonDispatcher!; + RootBackButtonDispatcher? _defaultBackButtonDispatcher; + + // NAVIGATOR + + GlobalKey<NavigatorState>? _navigator; + + Route<dynamic>? _onGenerateRoute(RouteSettings settings) { + final String? name = settings.name; + final WidgetBuilder? pageContentBuilder = name == Navigator.defaultRouteName && widget.home != null + ? (BuildContext context) => widget.home! + : widget.routes![name]; + + if (pageContentBuilder != null) { + assert( + widget.pageRouteBuilder != null, + 'The default onGenerateRoute handler for WidgetsApp must have a ' + 'pageRouteBuilder set if the home or routes properties are set.', + ); + final Route<dynamic> route = widget.pageRouteBuilder!<dynamic>( + settings, + pageContentBuilder, + ); + return route; + } + if (widget.onGenerateRoute != null) { + return widget.onGenerateRoute!(settings); + } + return null; + } + + Route<dynamic> _onUnknownRoute(RouteSettings settings) { + assert(() { + if (widget.onUnknownRoute == null) { + throw FlutterError( + 'Could not find a generator for route $settings in the $runtimeType.\n' + 'Make sure your root app widget has provided a way to generate \n' + 'this route.\n' + 'Generators for routes are searched for in the following order:\n' + ' 1. For the "/" route, the "home" property, if non-null, is used.\n' + ' 2. Otherwise, the "routes" table is used, if it has an entry for ' + 'the route.\n' + ' 3. Otherwise, onGenerateRoute is called. It should return a ' + 'non-null value for any valid route not handled by "home" and "routes".\n' + ' 4. Finally if all else fails onUnknownRoute is called.\n' + 'Unfortunately, onUnknownRoute was not set.', + ); + } + return true; + }()); + final Route<dynamic>? result = widget.onUnknownRoute!(settings); + assert(() { + if (result == null) { + throw FlutterError( + 'The onUnknownRoute callback returned null.\n' + 'When the $runtimeType requested the route $settings from its ' + 'onUnknownRoute callback, the callback returned null. Such callbacks ' + 'must never return null.', + ); + } + return true; + }()); + return result!; + } + + // On Android: the user has pressed the back button. + @override + Future<bool> didPopRoute() async { + assert(mounted); + // The back button dispatcher should handle the pop route if we use a + // router. + if (_usesRouterWithDelegates) { + return false; + } + + final NavigatorState? navigator = _navigator?.currentState; + if (navigator == null) { + return false; + } + return navigator.maybePop(); + } + + @override + Future<bool> didPushRouteInformation(RouteInformation routeInformation) async { + assert(mounted); + // The route name provider should handle the push route if we uses a + // router. + if (_usesRouterWithDelegates) { + return false; + } + + final NavigatorState? navigator = _navigator?.currentState; + if (navigator == null) { + return false; + } + final Uri uri = routeInformation.uri; + navigator.pushNamed( + Uri.decodeComponent( + Uri( + path: uri.path.isEmpty ? '/' : uri.path, + queryParameters: uri.queryParametersAll.isEmpty ? null : uri.queryParametersAll, + fragment: uri.fragment.isEmpty ? null : uri.fragment, + ).toString(), + ), + ); + return true; + } + + // LOCALIZATION + + /// This is the resolved locale, and is one of the supportedLocales. + Locale? _locale; + + Locale _resolveLocales(List<Locale>? preferredLocales, Iterable<Locale> supportedLocales) { + // Attempt to use localeListResolutionCallback. + if (widget.localeListResolutionCallback != null) { + final Locale? locale = widget.localeListResolutionCallback!(preferredLocales, widget.supportedLocales); + if (locale != null) { + return locale; + } + } + // localeListResolutionCallback failed, falling back to localeResolutionCallback. + if (widget.localeResolutionCallback != null) { + final Locale? locale = widget.localeResolutionCallback!( + preferredLocales != null && preferredLocales.isNotEmpty ? preferredLocales.first : null, + widget.supportedLocales, + ); + if (locale != null) { + return locale; + } + } + // Both callbacks failed, falling back to default algorithm. + return basicLocaleListResolution(preferredLocales, supportedLocales); + } + + @override + void didChangeLocales(List<Locale>? locales) { + final Locale newLocale = _resolveLocales(locales, widget.supportedLocales); + if (newLocale != _locale) { + setState(() { + _locale = newLocale; + }); + } + } + + // Combine the Localizations for Widgets with the ones contributed + // by the localizationsDelegates parameter, if any. Only the first delegate + // of a particular LocalizationsDelegate.type is loaded so the + // localizationsDelegate parameter can be used to override + // WidgetsLocalizations.delegate. + Iterable<LocalizationsDelegate<dynamic>> get _localizationsDelegates { + return <LocalizationsDelegate<dynamic>>[ + if (widget.localizationsDelegates != null) + ...widget.localizationsDelegates!, + DefaultWidgetsLocalizations.delegate, + ]; + } + + // BUILDER + + bool _debugCheckLocalizations(Locale appLocale) { + assert(() { + final Set<Type> unsupportedTypes = + _localizationsDelegates.map<Type>((LocalizationsDelegate<dynamic> delegate) => delegate.type).toSet(); + for (final LocalizationsDelegate<dynamic> delegate in _localizationsDelegates) { + if (!unsupportedTypes.contains(delegate.type)) { + continue; + } + if (delegate.isSupported(appLocale)) { + unsupportedTypes.remove(delegate.type); + } + } + if (unsupportedTypes.isEmpty) { + return true; + } + + FlutterError.reportError(FlutterErrorDetails( + exception: "Warning: This application's locale, $appLocale, is not supported by all of its localization delegates.", + library: 'widgets', + informationCollector: () => <DiagnosticsNode>[ + for (final Type unsupportedType in unsupportedTypes) + ErrorDescription( + '• A $unsupportedType delegate that supports the $appLocale locale was not found.', + ), + ErrorSpacer(), + if (unsupportedTypes.length == 1 && unsupportedTypes.single.toString() == 'CupertinoLocalizations') + // We previously explicitly avoided checking for this class so it's not uncommon for applications + // to have omitted importing the required delegate. + ...<DiagnosticsNode>[ + ErrorHint( + 'If the application is built using GlobalMaterialLocalizations.delegate, consider using ' + 'GlobalMaterialLocalizations.delegates (plural) instead, as that will automatically declare ' + 'the appropriate Cupertino localizations.' + ), + ErrorSpacer(), + ], + ErrorHint( + 'The declared supported locales for this app are: ${widget.supportedLocales.join(", ")}' + ), + ErrorSpacer(), + ErrorDescription( + 'See https://flutter.dev/tutorials/internationalization/ for more ' + "information about configuring an app's locale, supportedLocales, " + 'and localizationsDelegates parameters.', + ), + ], + )); + return true; + }()); + return true; + } + + @override + Widget build(BuildContext context) { + Widget? routing; + if (_usesRouterWithDelegates) { + routing = Router<Object>( + restorationScopeId: 'router', + routeInformationProvider: _effectiveRouteInformationProvider, + routeInformationParser: widget.routeInformationParser, + routerDelegate: widget.routerDelegate!, + backButtonDispatcher: _effectiveBackButtonDispatcher, + ); + } else if (_usesNavigator) { + assert(_navigator != null); + routing = FocusScope( + debugLabel: 'Navigator Scope', + autofocus: true, + child: Navigator( + clipBehavior: Clip.none, + restorationScopeId: 'nav', + key: _navigator, + initialRoute: _initialRouteName, + onGenerateRoute: _onGenerateRoute, + onGenerateInitialRoutes: widget.onGenerateInitialRoutes == null + ? Navigator.defaultGenerateInitialRoutes + : (NavigatorState navigator, String initialRouteName) { + return widget.onGenerateInitialRoutes!(initialRouteName); + }, + onUnknownRoute: _onUnknownRoute, + observers: widget.navigatorObservers!, + routeTraversalEdgeBehavior: kIsWeb ? TraversalEdgeBehavior.leaveFlutterView : TraversalEdgeBehavior.parentScope, + reportsRouteUpdateToEngine: true, + ), + ); + } else if (_usesRouterWithConfig) { + routing = Router<Object>.withConfig( + restorationScopeId: 'router', + config: widget.routerConfig!, + ); + } + + Widget result; + if (widget.builder != null) { + result = Builder( + builder: (BuildContext context) { + return widget.builder!(context, routing); + }, + ); + } else { + assert(routing != null); + result = routing!; + } + + if (widget.textStyle != null) { + result = DefaultTextStyle( + style: widget.textStyle!, + child: result, + ); + } + + PerformanceOverlay? performanceOverlay; + // We need to push a performance overlay if any of the display or checkerboarding + // options are set. + if (widget.showPerformanceOverlay || WidgetsApp.showPerformanceOverlayOverride) { + performanceOverlay = PerformanceOverlay.allEnabled( + checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages, + checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers, + ); + } else if (widget.checkerboardRasterCacheImages || widget.checkerboardOffscreenLayers) { + performanceOverlay = PerformanceOverlay( + checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages, + checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers, + ); + } + if (performanceOverlay != null) { + result = Stack( + children: <Widget>[ + result, + Positioned(top: 0.0, left: 0.0, right: 0.0, child: performanceOverlay), + ], + ); + } + + if (widget.showSemanticsDebugger) { + result = SemanticsDebugger( + child: result, + ); + } + + assert(() { + result = ValueListenableBuilder<bool>( + valueListenable: WidgetsApp._debugShowWidgetInspectorOverrideNotifier, + builder: (BuildContext context, bool debugShowWidgetInspectorOverride, Widget? child) { + if (widget.debugShowWidgetInspector || debugShowWidgetInspectorOverride) { + return WidgetInspector( + selectButtonBuilder: widget.inspectorSelectButtonBuilder, + child: child!, + ); + } + return child!; + }, + child: result, + ); + if (widget.debugShowCheckedModeBanner && WidgetsApp.debugAllowBannerOverride) { + result = CheckedModeBanner( + child: result, + ); + } + return true; + }()); + + final Widget title; + if (widget.onGenerateTitle != null) { + title = Builder( + // This Builder exists to provide a context below the Localizations widget. + // The onGenerateTitle callback can refer to Localizations via its context + // parameter. + builder: (BuildContext context) { + final String title = widget.onGenerateTitle!(context); + return Title( + title: title, + color: widget.color.withOpacity(1.0), + child: result, + ); + }, + ); + } else { + title = Title( + title: widget.title, + color: widget.color.withOpacity(1.0), + child: result, + ); + } + + final Locale appLocale = widget.locale != null + ? _resolveLocales(<Locale>[widget.locale!], widget.supportedLocales) + : _locale!; + + assert(_debugCheckLocalizations(appLocale)); + + return RootRestorationScope( + restorationId: widget.restorationScopeId, + child: SharedAppData( + child: NotificationListener<NavigationNotification>( + onNotification: widget.onNavigationNotification ?? _defaultOnNavigationNotification, + child: Shortcuts( + debugLabel: '<Default WidgetsApp Shortcuts>', + shortcuts: widget.shortcuts ?? WidgetsApp.defaultShortcuts, + // DefaultTextEditingShortcuts is nested inside Shortcuts so that it can + // fall through to the defaultShortcuts. + child: DefaultTextEditingShortcuts( + child: Actions( + actions: widget.actions ?? <Type, Action<Intent>>{ + ...WidgetsApp.defaultActions, + ScrollIntent: Action<ScrollIntent>.overridable(context: context, defaultAction: ScrollAction()), + }, + child: FocusTraversalGroup( + policy: ReadingOrderTraversalPolicy(), + child: TapRegionSurface( + child: ShortcutRegistrar( + child: Localizations( + locale: appLocale, + delegates: _localizationsDelegates.toList(), + child: title, + ), + ), + ), + ), + ), + ), + ), + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/app_lifecycle_listener.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/app_lifecycle_listener.dart new file mode 100644 index 0000000000000000000000000000000000000000..80743894055294126194dc40815849ade503c746 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/app_lifecycle_listener.dart @@ -0,0 +1,276 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; +import 'package:flutter/foundation.dart'; + +import 'binding.dart'; + +/// A callback type that is used by [AppLifecycleListener.onExitRequested] to +/// ask the application if it wants to cancel application termination or not. +typedef AppExitRequestCallback = Future<AppExitResponse> Function(); + +/// A listener that can be used to listen to changes in the application +/// lifecycle. +/// +/// To listen for requests for the application to exit, and to decide whether or +/// not the application should exit when requested, create an +/// [AppLifecycleListener] and set the [onExitRequested] callback. +/// +/// To listen for changes in the application lifecycle state, define an +/// [onStateChange] callback. See the [AppLifecycleState] enum for details on +/// the various states. +/// +/// The [onStateChange] callback is called for each state change, and the +/// individual state transitions ([onResume], [onInactive], etc.) are also +/// called if the state transition they represent occurs. +/// +/// State changes will occur in accordance with the state machine described by +/// this diagram: +/// +/// ![Diagram of the application lifecycle defined by the AppLifecycleState enum]( +/// https://flutter.github.io/assets-for-api-docs/assets/dart-ui/app_lifecycle.png) +/// +/// The initial state of the state machine is the [AppLifecycleState.detached] +/// state, and the arrows describe valid state transitions. Transitions in blue +/// are transitions that only happen on iOS and Android. +/// +/// {@tool dartpad} +/// This example shows how an application can listen to changes in the +/// application state. +/// +/// ** See code in examples/api/lib/widgets/app_lifecycle_listener/app_lifecycle_listener.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how an application can optionally decide to abort a +/// request for exiting instead of obeying the request. +/// +/// ** See code in examples/api/lib/widgets/app_lifecycle_listener/app_lifecycle_listener.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ServicesBinding.exitApplication] for a function to call that will request +/// that the application exits. +/// * [WidgetsBindingObserver.didRequestAppExit] for the handler which this +/// class uses to receive exit requests. +/// * [WidgetsBindingObserver.didChangeAppLifecycleState] for the handler which +/// this class uses to receive lifecycle state changes. +class AppLifecycleListener with WidgetsBindingObserver, Diagnosticable { + /// Creates an [AppLifecycleListener]. + AppLifecycleListener({ + WidgetsBinding? binding, + this.onResume, + this.onInactive, + this.onHide, + this.onShow, + this.onPause, + this.onRestart, + this.onDetach, + this.onExitRequested, + this.onStateChange, + }) : binding = binding ?? WidgetsBinding.instance, + _lifecycleState = (binding ?? WidgetsBinding.instance).lifecycleState { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/widgets.dart', + className: '$AppLifecycleListener', + object: this, + ); + } + this.binding.addObserver(this); + } + + AppLifecycleState? _lifecycleState; + + /// The [WidgetsBinding] to listen to for application lifecycle events. + /// + /// Typically, this is set to [WidgetsBinding.instance], but may be + /// substituted for testing or other specialized bindings. + /// + /// Defaults to [WidgetsBinding.instance]. + final WidgetsBinding binding; + + /// Called anytime the state changes, passing the new state. + final ValueChanged<AppLifecycleState>? onStateChange; + + /// A callback that is called when the application loses input focus. + /// + /// On mobile platforms, this can be during a phone call or when a system + /// dialog is visible. + /// + /// On desktop platforms, this is when all views in an application have lost + /// input focus but at least one view of the application is still visible. + /// + /// On the web, this is when the window (or tab) has lost input focus. + final VoidCallback? onInactive; + + /// A callback that is called when a view in the application gains input + /// focus. + /// + /// A call to this callback indicates that the application is entering a state + /// where it is visible, active, and accepting user input. + final VoidCallback? onResume; + + /// A callback that is called when the application is hidden. + /// + /// On mobile platforms, this is usually just before the application is + /// replaced by another application in the foreground. + /// + /// On desktop platforms, this is just before the application is hidden by + /// being minimized or otherwise hiding all views of the application. + /// + /// On the web, this is just before a window (or tab) is hidden. + final VoidCallback? onHide; + + /// A callback that is called when the application is shown. + /// + /// On mobile platforms, this is usually just before the application replaces + /// another application in the foreground. + /// + /// On desktop platforms, this is just before the application is shown after + /// being minimized or otherwise made to show at least one view of the + /// application. + /// + /// On the web, this is just before a window (or tab) is shown. + final VoidCallback? onShow; + + /// A callback that is called when the application is paused. + /// + /// On mobile platforms, this happens right before the application is replaced + /// by another application. + /// + /// On desktop platforms and the web, this function is not called. + final VoidCallback? onPause; + + /// A callback that is called when the application is resumed after being + /// paused. + /// + /// On mobile platforms, this happens just before this application takes over + /// as the active application. + /// + /// On desktop platforms and the web, this function is not called. + final VoidCallback? onRestart; + + /// A callback used to ask the application if it will allow exiting the + /// application for cases where the exit is cancelable. + /// + /// Exiting the application isn't always cancelable, but when it is, this + /// function will be called before exit occurs. + /// + /// Responding [AppExitResponse.exit] will continue termination, and + /// responding [AppExitResponse.cancel] will cancel it. If termination is not + /// canceled, the application will immediately exit. + final AppExitRequestCallback? onExitRequested; + + /// A callback that is called when an application has exited, and detached all + /// host views from the engine. + /// + /// This callback is only called on iOS and Android. + final VoidCallback? onDetach; + + bool _debugDisposed = false; + + /// Call when the listener is no longer in use. + /// + /// Do not use the object after calling [dispose]. + /// + /// Subclasses must call this method in their overridden [dispose], if any. + @mustCallSuper + void dispose() { + assert(_debugAssertNotDisposed()); + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + binding.removeObserver(this); + assert(() { + _debugDisposed = true; + return true; + }()); + } + + bool _debugAssertNotDisposed() { + assert(() { + if (_debugDisposed) { + throw FlutterError( + 'A $runtimeType was used after being disposed.\n' + 'Once you have called dispose() on a $runtimeType, it ' + 'can no longer be used.', + ); + } + return true; + }()); + return true; + } + + @override + Future<AppExitResponse> didRequestAppExit() async { + assert(_debugAssertNotDisposed()); + if (onExitRequested == null) { + return AppExitResponse.exit; + } + return onExitRequested!(); + } + + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + assert(_debugAssertNotDisposed()); + final AppLifecycleState? previousState = _lifecycleState; + if (state == previousState) { + // Transitioning to the same state twice doesn't produce any + // notifications (but also won't actually occur). + return; + } + _lifecycleState = state; + switch (state) { + case AppLifecycleState.resumed: + assert(previousState == null || previousState == AppLifecycleState.inactive || previousState == AppLifecycleState.detached, 'Invalid state transition from $previousState to $state'); + onResume?.call(); + case AppLifecycleState.inactive: + assert(previousState == null || previousState == AppLifecycleState.hidden || previousState == AppLifecycleState.resumed, 'Invalid state transition from $previousState to $state'); + if (previousState == AppLifecycleState.hidden) { + onShow?.call(); + } else if (previousState == null || previousState == AppLifecycleState.resumed) { + onInactive?.call(); + } + case AppLifecycleState.hidden: + assert(previousState == null || previousState == AppLifecycleState.paused || previousState == AppLifecycleState.inactive, 'Invalid state transition from $previousState to $state'); + if (previousState == AppLifecycleState.paused) { + onRestart?.call(); + } else if (previousState == null || previousState == AppLifecycleState.inactive) { + onHide?.call(); + } + case AppLifecycleState.paused: + assert(previousState == null || previousState == AppLifecycleState.hidden, 'Invalid state transition from $previousState to $state'); + if (previousState == null || previousState == AppLifecycleState.hidden) { + onPause?.call(); + } + case AppLifecycleState.detached: + assert(previousState == null || previousState == AppLifecycleState.paused, 'Invalid state transition from $previousState to $state'); + onDetach?.call(); + } + // At this point, it can't be null anymore. + onStateChange?.call(_lifecycleState!); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<WidgetsBinding>('binding', binding)); + properties.add(FlagProperty('onStateChange', value: onStateChange != null, ifTrue: 'onStateChange')); + properties.add(FlagProperty('onInactive', value: onInactive != null, ifTrue: 'onInactive')); + properties.add(FlagProperty('onResume', value: onResume != null, ifTrue: 'onResume')); + properties.add(FlagProperty('onHide', value: onHide != null, ifTrue: 'onHide')); + properties.add(FlagProperty('onShow', value: onShow != null, ifTrue: 'onShow')); + properties.add(FlagProperty('onPause', value: onPause != null, ifTrue: 'onPause')); + properties.add(FlagProperty('onRestart', value: onRestart != null, ifTrue: 'onRestart')); + properties.add(FlagProperty('onExitRequested', value: onExitRequested != null, ifTrue: 'onExitRequested')); + properties.add(FlagProperty('onDetach', value: onDetach != null, ifTrue: 'onDetach')); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/async.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/async.dart new file mode 100644 index 0000000000000000000000000000000000000000..cf4e0ca6972902031f4c82d61c22f0344ed95e5f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/async.dart @@ -0,0 +1,653 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async' show StreamSubscription; + +import 'package:flutter/foundation.dart'; + +import 'framework.dart'; + +/// Base class for widgets that build themselves based on interaction with +/// a specified [Stream]. +/// +/// A [StreamBuilderBase] is stateful and maintains a summary of the interaction +/// so far. The type of the summary and how it is updated with each interaction +/// is defined by sub-classes. +/// +/// Examples of summaries include: +/// +/// * the running average of a stream of integers; +/// * the current direction and speed based on a stream of geolocation data; +/// * a graph displaying data points from a stream. +/// +/// In general, the summary is the result of a fold computation over the data +/// items and errors received from the stream along with pseudo-events +/// representing termination or change of stream. The initial summary is +/// specified by sub-classes by overriding [initial]. The summary updates on +/// receipt of stream data and errors are specified by overriding [afterData] and +/// [afterError], respectively. If needed, the summary may be updated on stream +/// termination by overriding [afterDone]. Finally, the summary may be updated +/// on change of stream by overriding [afterDisconnected] and [afterConnected]. +/// +/// `T` is the type of stream events. +/// +/// `S` is the type of interaction summary. +/// +/// See also: +/// +/// * [StreamBuilder], which is specialized for the case where only the most +/// recent interaction is needed for widget building. +abstract class StreamBuilderBase<T, S> extends StatefulWidget { + /// Creates a [StreamBuilderBase] connected to the specified [stream]. + const StreamBuilderBase({ super.key, required this.stream }); + + /// The asynchronous computation to which this builder is currently connected, + /// possibly null. When changed, the current summary is updated using + /// [afterDisconnected], if the previous stream was not null, followed by + /// [afterConnected], if the new stream is not null. + final Stream<T>? stream; + + /// Returns the initial summary of stream interaction, typically representing + /// the fact that no interaction has happened at all. + /// + /// Sub-classes must override this method to provide the initial value for + /// the fold computation. + S initial(); + + /// Returns an updated version of the [current] summary reflecting that we + /// are now connected to a stream. + /// + /// The default implementation returns [current] as is. + S afterConnected(S current) => current; + + /// Returns an updated version of the [current] summary following a data event. + /// + /// Sub-classes must override this method to specify how the current summary + /// is combined with the new data item in the fold computation. + S afterData(S current, T data); + + /// Returns an updated version of the [current] summary following an error + /// with a stack trace. + /// + /// The default implementation returns [current] as is. + S afterError(S current, Object error, StackTrace stackTrace) => current; + + /// Returns an updated version of the [current] summary following stream + /// termination. + /// + /// The default implementation returns [current] as is. + S afterDone(S current) => current; + + /// Returns an updated version of the [current] summary reflecting that we + /// are no longer connected to a stream. + /// + /// The default implementation returns [current] as is. + S afterDisconnected(S current) => current; + + /// Returns a Widget based on the [currentSummary]. + Widget build(BuildContext context, S currentSummary); + + @override + State<StreamBuilderBase<T, S>> createState() => _StreamBuilderBaseState<T, S>(); +} + +/// State for [StreamBuilderBase]. +class _StreamBuilderBaseState<T, S> extends State<StreamBuilderBase<T, S>> { + StreamSubscription<T>? _subscription; + late S _summary; + + @override + void initState() { + super.initState(); + _summary = widget.initial(); + _subscribe(); + } + + @override + void didUpdateWidget(StreamBuilderBase<T, S> oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.stream != widget.stream) { + if (_subscription != null) { + _unsubscribe(); + _summary = widget.afterDisconnected(_summary); + } + _subscribe(); + } + } + + @override + Widget build(BuildContext context) => widget.build(context, _summary); + + @override + void dispose() { + _unsubscribe(); + super.dispose(); + } + + void _subscribe() { + if (widget.stream != null) { + _subscription = widget.stream!.listen((T data) { + setState(() { + _summary = widget.afterData(_summary, data); + }); + }, onError: (Object error, StackTrace stackTrace) { + setState(() { + _summary = widget.afterError(_summary, error, stackTrace); + }); + }, onDone: () { + setState(() { + _summary = widget.afterDone(_summary); + }); + }); + _summary = widget.afterConnected(_summary); + } + } + + void _unsubscribe() { + if (_subscription != null) { + _subscription!.cancel(); + _subscription = null; + } + } +} + +/// The state of connection to an asynchronous computation. +/// +/// The usual flow of state is as follows: +/// +/// 1. [none], maybe with some initial data. +/// 2. [waiting], indicating that the asynchronous operation has begun, +/// typically with the data being null. +/// 3. [active], with data being non-null, and possible changing over time. +/// 4. [done], with data being non-null. +/// +/// See also: +/// +/// * [AsyncSnapshot], which augments a connection state with information +/// received from the asynchronous computation. +enum ConnectionState { + /// Not currently connected to any asynchronous computation. + /// + /// For example, a [FutureBuilder] whose [FutureBuilder.future] is null. + none, + + /// Connected to an asynchronous computation and awaiting interaction. + waiting, + + /// Connected to an active asynchronous computation. + /// + /// For example, a [Stream] that has returned at least one value, but is not + /// yet done. + active, + + /// Connected to a terminated asynchronous computation. + done, +} + +/// Immutable representation of the most recent interaction with an asynchronous +/// computation. +/// +/// See also: +/// +/// * [StreamBuilder], which builds itself based on a snapshot from interacting +/// with a [Stream]. +/// * [FutureBuilder], which builds itself based on a snapshot from interacting +/// with a [Future]. +@immutable +class AsyncSnapshot<T> { + /// Creates an [AsyncSnapshot] with the specified [connectionState], + /// and optionally either [data] or [error] with an optional [stackTrace] + /// (but not both data and error). + const AsyncSnapshot._(this.connectionState, this.data, this.error, this.stackTrace) + : assert(data == null || error == null), + assert(stackTrace == null || error != null); + + /// Creates an [AsyncSnapshot] in [ConnectionState.none] with null data and error. + const AsyncSnapshot.nothing() : this._(ConnectionState.none, null, null, null); + + /// Creates an [AsyncSnapshot] in [ConnectionState.waiting] with null data and error. + const AsyncSnapshot.waiting() : this._(ConnectionState.waiting, null, null, null); + + /// Creates an [AsyncSnapshot] in the specified [state] and with the specified [data]. + const AsyncSnapshot.withData(ConnectionState state, T data): this._(state, data, null, null); + + /// Creates an [AsyncSnapshot] in the specified [state] with the specified [error] + /// and a [stackTrace]. + /// + /// If no [stackTrace] is explicitly specified, [StackTrace.empty] will be used instead. + const AsyncSnapshot.withError( + ConnectionState state, + Object error, [ + StackTrace stackTrace = StackTrace.empty, + ]) : this._(state, null, error, stackTrace); + + /// Current state of connection to the asynchronous computation. + final ConnectionState connectionState; + + /// The latest data received by the asynchronous computation. + /// + /// If this is non-null, [hasData] will be true. + /// + /// If [error] is not null, this will be null. See [hasError]. + /// + /// If the asynchronous computation has never returned a value, this may be + /// set to an initial data value specified by the relevant widget. See + /// [FutureBuilder.initialData] and [StreamBuilder.initialData]. + final T? data; + + /// Returns latest data received, failing if there is no data. + /// + /// Throws [error], if [hasError]. Throws [StateError], if neither [hasData] + /// nor [hasError]. + T get requireData { + if (hasData) { + return data!; + } + if (hasError) { + Error.throwWithStackTrace(error!, stackTrace!); + } + throw StateError('Snapshot has neither data nor error'); + } + + /// The latest error object received by the asynchronous computation. + /// + /// If this is non-null, [hasError] will be true. + /// + /// If [data] is not null, this will be null. + final Object? error; + + /// The latest stack trace object received by the asynchronous computation. + /// + /// This will not be null iff [error] is not null. Consequently, [stackTrace] + /// will be non-null when [hasError] is true. + /// + /// However, even when not null, [stackTrace] might be empty. The stack trace + /// is empty when there is an error but no stack trace has been provided. + final StackTrace? stackTrace; + + /// Returns a snapshot like this one, but in the specified [state]. + /// + /// The [data], [error], and [stackTrace] fields persist unmodified, even if + /// the new state is [ConnectionState.none]. + AsyncSnapshot<T> inState(ConnectionState state) => AsyncSnapshot<T>._(state, data, error, stackTrace); + + /// Returns whether this snapshot contains a non-null [data] value. + /// + /// This can be false even when the asynchronous computation has completed + /// successfully, if the computation did not return a non-null value. For + /// example, a [Future<void>] will complete with the null value even if it + /// completes successfully. + bool get hasData => data != null; + + /// Returns whether this snapshot contains a non-null [error] value. + /// + /// This is always true if the asynchronous computation's last result was + /// failure. + bool get hasError => error != null; + + @override + String toString() => '${objectRuntimeType(this, 'AsyncSnapshot')}($connectionState, $data, $error, $stackTrace)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is AsyncSnapshot<T> + && other.connectionState == connectionState + && other.data == data + && other.error == error + && other.stackTrace == stackTrace; + } + + @override + int get hashCode => Object.hash(connectionState, data, error); +} + +/// Signature for strategies that build widgets based on asynchronous +/// interaction. +/// +/// See also: +/// +/// * [StreamBuilder], which delegates to an [AsyncWidgetBuilder] to build +/// itself based on a snapshot from interacting with a [Stream]. +/// * [FutureBuilder], which delegates to an [AsyncWidgetBuilder] to build +/// itself based on a snapshot from interacting with a [Future]. +typedef AsyncWidgetBuilder<T> = Widget Function(BuildContext context, AsyncSnapshot<T> snapshot); + +/// Widget that builds itself based on the latest snapshot of interaction with +/// a [Stream]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=MkKEWHfy99Y} +/// +/// Widget rebuilding is scheduled by each interaction, using [State.setState], +/// but is otherwise decoupled from the timing of the stream. The [builder] +/// is called at the discretion of the Flutter pipeline, and will thus receive a +/// timing-dependent sub-sequence of the snapshots that represent the +/// interaction with the stream. +/// +/// As an example, when interacting with a stream producing the integers +/// 0 through 9, the [builder] may be called with any ordered sub-sequence +/// of the following snapshots that includes the last one (the one with +/// ConnectionState.done): +/// +/// * `AsyncSnapshot<int>.withData(ConnectionState.waiting, null)` +/// * `AsyncSnapshot<int>.withData(ConnectionState.active, 0)` +/// * `AsyncSnapshot<int>.withData(ConnectionState.active, 1)` +/// * ... +/// * `AsyncSnapshot<int>.withData(ConnectionState.active, 9)` +/// * `AsyncSnapshot<int>.withData(ConnectionState.done, 9)` +/// +/// The actual sequence of invocations of the [builder] depends on the relative +/// timing of events produced by the stream and the build rate of the Flutter +/// pipeline. +/// +/// Changing the [StreamBuilder] configuration to another stream during event +/// generation introduces snapshot pairs of the form: +/// +/// * `AsyncSnapshot<int>.withData(ConnectionState.none, 5)` +/// * `AsyncSnapshot<int>.withData(ConnectionState.waiting, 5)` +/// +/// The latter will be produced only when the new stream is non-null, and the +/// former only when the old stream is non-null. +/// +/// The stream may produce errors, resulting in snapshots of the form: +/// +/// * `AsyncSnapshot<int>.withError(ConnectionState.active, 'some error', someStackTrace)` +/// +/// The data and error fields of snapshots produced are only changed when the +/// state is `ConnectionState.active`. +/// +/// The initial snapshot data can be controlled by specifying [initialData]. +/// This should be used to ensure that the first frame has the expected value, +/// as the builder will always be called before the stream listener has a chance +/// to be processed. +/// +/// {@tool dartpad} +/// This sample shows a [StreamBuilder] that listens to a Stream that emits bids +/// for an auction. Every time the StreamBuilder receives a bid from the Stream, +/// it will display the price of the bid below an icon. If the Stream emits an +/// error, the error is displayed below an error icon. When the Stream finishes +/// emitting bids, the final price is displayed. +/// +/// ** See code in examples/api/lib/widgets/async/stream_builder.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ValueListenableBuilder], which wraps a [ValueListenable] instead of a +/// [Stream]. +/// * [StreamBuilderBase], which supports widget building based on a computation +/// that spans all interactions made with the stream. +class StreamBuilder<T> extends StreamBuilderBase<T, AsyncSnapshot<T>> { + /// Creates a new [StreamBuilder] that builds itself based on the latest + /// snapshot of interaction with the specified [stream] and whose build + /// strategy is given by [builder]. + /// + /// The [initialData] is used to create the initial snapshot. + const StreamBuilder({ + super.key, + this.initialData, + required super.stream, + required this.builder, + }); + + /// The build strategy currently used by this builder. + /// + /// This builder must only return a widget and should not have any side + /// effects as it may be called multiple times. + final AsyncWidgetBuilder<T> builder; + + /// The data that will be used to create the initial snapshot. + /// + /// Providing this value (presumably obtained synchronously somehow when the + /// [Stream] was created) ensures that the first frame will show useful data. + /// Otherwise, the first frame will be built with the value null, regardless + /// of whether a value is available on the stream: since streams are + /// asynchronous, no events from the stream can be obtained before the initial + /// build. + final T? initialData; + + @override + AsyncSnapshot<T> initial() => initialData == null + ? AsyncSnapshot<T>.nothing() + : AsyncSnapshot<T>.withData(ConnectionState.none, initialData as T); + + @override + AsyncSnapshot<T> afterConnected(AsyncSnapshot<T> current) => current.inState(ConnectionState.waiting); + + @override + AsyncSnapshot<T> afterData(AsyncSnapshot<T> current, T data) { + return AsyncSnapshot<T>.withData(ConnectionState.active, data); + } + + @override + AsyncSnapshot<T> afterError(AsyncSnapshot<T> current, Object error, StackTrace stackTrace) { + return AsyncSnapshot<T>.withError(ConnectionState.active, error, stackTrace); + } + + @override + AsyncSnapshot<T> afterDone(AsyncSnapshot<T> current) => current.inState(ConnectionState.done); + + @override + AsyncSnapshot<T> afterDisconnected(AsyncSnapshot<T> current) => current.inState(ConnectionState.none); + + @override + Widget build(BuildContext context, AsyncSnapshot<T> currentSummary) => builder(context, currentSummary); +} + +/// A widget that builds itself based on the latest snapshot of interaction with +/// a [Future]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=zEdw_1B7JHY} +/// +/// ## Managing the future +/// +/// The [future] must have been obtained earlier, e.g. during [State.initState], +/// [State.didUpdateWidget], or [State.didChangeDependencies]. It must not be +/// created during the [State.build] or [StatelessWidget.build] method call when +/// constructing the [FutureBuilder]. If the [future] is created at the same +/// time as the [FutureBuilder], then every time the [FutureBuilder]'s parent is +/// rebuilt, the asynchronous task will be restarted. +/// +/// A general guideline is to assume that every `build` method could get called +/// every frame, and to treat omitted calls as an optimization. +/// +/// ## Timing +/// +/// Widget rebuilding is scheduled by the completion of the future, using +/// [State.setState], but is otherwise decoupled from the timing of the future. +/// The [builder] callback is called at the discretion of the Flutter pipeline, and +/// will thus receive a timing-dependent sub-sequence of the snapshots that +/// represent the interaction with the future. +/// +/// A side-effect of this is that providing a new but already-completed future +/// to a [FutureBuilder] will result in a single frame in the +/// [ConnectionState.waiting] state. This is because there is no way to +/// synchronously determine that a [Future] has already completed. +/// +/// ## Builder contract +/// +/// For a future that completes successfully with data, assuming [initialData] +/// is null, the [builder] will be called with either both or only the latter of +/// the following snapshots: +/// +/// * `AsyncSnapshot<String>.withData(ConnectionState.waiting, null)` +/// * `AsyncSnapshot<String>.withData(ConnectionState.done, 'some data')` +/// +/// If that same future instead completed with an error, the [builder] would be +/// called with either both or only the latter of: +/// +/// * `AsyncSnapshot<String>.withData(ConnectionState.waiting, null)` +/// * `AsyncSnapshot<String>.withError(ConnectionState.done, 'some error', someStackTrace)` +/// +/// The initial snapshot data can be controlled by specifying [initialData]. You +/// would use this facility to ensure that if the [builder] is invoked before +/// the future completes, the snapshot carries data of your choice rather than +/// the default null value. +/// +/// The data and error fields of the snapshot change only as the connection +/// state field transitions from `waiting` to `done`, and they will be retained +/// when changing the [FutureBuilder] configuration to another future. If the +/// old future has already completed successfully with data as above, changing +/// configuration to a new future results in snapshot pairs of the form: +/// +/// * `AsyncSnapshot<String>.withData(ConnectionState.none, 'data of first future')` +/// * `AsyncSnapshot<String>.withData(ConnectionState.waiting, 'data of second future')` +/// +/// In general, the latter will be produced only when the new future is +/// non-null, and the former only when the old future is non-null. +/// +/// A [FutureBuilder] behaves identically to a [StreamBuilder] configured with +/// `future?.asStream()`, except that snapshots with `ConnectionState.active` +/// may appear for the latter, depending on how the stream is implemented. +/// +/// {@tool dartpad} +/// This sample shows a [FutureBuilder] that displays a loading spinner while it +/// loads data. It displays a success icon and text if the [Future] completes +/// with a result, or an error icon and text if the [Future] completes with an +/// error. Assume the `_calculation` field is set by pressing a button elsewhere +/// in the UI. +/// +/// ** See code in examples/api/lib/widgets/async/future_builder.0.dart ** +/// {@end-tool} +class FutureBuilder<T> extends StatefulWidget { + /// Creates a widget that builds itself based on the latest snapshot of + /// interaction with a [Future]. + const FutureBuilder({ + super.key, + required this.future, + this.initialData, + required this.builder, + }); + + /// The asynchronous computation to which this builder is currently connected, + /// possibly null. + /// + /// If no future has yet completed, including in the case where [future] is + /// null, the data provided to the [builder] will be set to [initialData]. + final Future<T>? future; + + /// The build strategy currently used by this builder. + /// + /// The builder is provided with an [AsyncSnapshot] object whose + /// [AsyncSnapshot.connectionState] property will be one of the following + /// values: + /// + /// * [ConnectionState.none]: [future] is null. The [AsyncSnapshot.data] will + /// be set to [initialData], unless a future has previously completed, in + /// which case the previous result persists. + /// + /// * [ConnectionState.waiting]: [future] is not null, but has not yet + /// completed. The [AsyncSnapshot.data] will be set to [initialData], + /// unless a future has previously completed, in which case the previous + /// result persists. + /// + /// * [ConnectionState.done]: [future] is not null, and has completed. If the + /// future completed successfully, the [AsyncSnapshot.data] will be set to + /// the value to which the future completed. If it completed with an error, + /// [AsyncSnapshot.hasError] will be true and [AsyncSnapshot.error] will be + /// set to the error object. + /// + /// This builder must only return a widget and should not have any side + /// effects as it may be called multiple times. + final AsyncWidgetBuilder<T> builder; + + /// The data that will be used to create the snapshots provided until a + /// non-null [future] has completed. + /// + /// If the future completes with an error, the data in the [AsyncSnapshot] + /// provided to the [builder] will become null, regardless of [initialData]. + /// (The error itself will be available in [AsyncSnapshot.error], and + /// [AsyncSnapshot.hasError] will be true.) + final T? initialData; + + /// Whether the latest error received by the asynchronous computation should + /// be rethrown or swallowed. This property is useful for debugging purposes. + /// + /// When set to true, will rethrow the latest error only in debug mode. + /// + /// Defaults to `false`, resulting in swallowing of errors. + static bool debugRethrowError = false; + + @override + State<FutureBuilder<T>> createState() => _FutureBuilderState<T>(); +} + +/// State for [FutureBuilder]. +class _FutureBuilderState<T> extends State<FutureBuilder<T>> { + /// An object that identifies the currently active callbacks. Used to avoid + /// calling setState from stale callbacks, e.g. after disposal of this state, + /// or after widget reconfiguration to a new Future. + Object? _activeCallbackIdentity; + late AsyncSnapshot<T> _snapshot; + + @override + void initState() { + super.initState(); + _snapshot = widget.initialData == null + ? AsyncSnapshot<T>.nothing() + : AsyncSnapshot<T>.withData(ConnectionState.none, widget.initialData as T); + _subscribe(); + } + + @override + void didUpdateWidget(FutureBuilder<T> oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.future == widget.future) { + return; + } + if (_activeCallbackIdentity != null) { + _unsubscribe(); + _snapshot = _snapshot.inState(ConnectionState.none); + } + _subscribe(); + } + + @override + Widget build(BuildContext context) => widget.builder(context, _snapshot); + + @override + void dispose() { + _unsubscribe(); + super.dispose(); + } + + void _subscribe() { + if (widget.future == null) { + // There is no future to subscribe to, do nothing. + return; + } + final Object callbackIdentity = Object(); + _activeCallbackIdentity = callbackIdentity; + widget.future!.then<void>((T data) { + if (_activeCallbackIdentity == callbackIdentity) { + setState(() { + _snapshot = AsyncSnapshot<T>.withData(ConnectionState.done, data); + }); + } + }, onError: (Object error, StackTrace stackTrace) { + if (_activeCallbackIdentity == callbackIdentity) { + setState(() { + _snapshot = AsyncSnapshot<T>.withError(ConnectionState.done, error, stackTrace); + }); + } + assert(() { + if (FutureBuilder.debugRethrowError) { + Future<Object>.error(error, stackTrace); + } + return true; + }()); + }); + // An implementation like `SynchronousFuture` may have already called the + // .then closure. Do not overwrite it in that case. + if (_snapshot.connectionState != ConnectionState.done) { + _snapshot = _snapshot.inState(ConnectionState.waiting); + } + } + + void _unsubscribe() { + _activeCallbackIdentity = null; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/autocomplete.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/autocomplete.dart new file mode 100644 index 0000000000000000000000000000000000000000..d71180a083a2d940993d9715b7cfef4f900a6f77 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/autocomplete.dart @@ -0,0 +1,663 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'actions.dart'; +import 'basic.dart'; +import 'container.dart'; +import 'editable_text.dart'; +import 'focus_manager.dart'; +import 'framework.dart'; +import 'inherited_notifier.dart'; +import 'overlay.dart'; +import 'shortcuts.dart'; +import 'tap_region.dart'; + +// Examples can assume: +// late BuildContext context; + +/// The type of the [RawAutocomplete] callback which computes the list of +/// optional completions for the widget's field, based on the text the user has +/// entered so far. +/// +/// See also: +/// +/// * [RawAutocomplete.optionsBuilder], which is of this type. +typedef AutocompleteOptionsBuilder<T extends Object> = FutureOr<Iterable<T>> Function(TextEditingValue textEditingValue); + +/// The type of the callback used by the [RawAutocomplete] widget to indicate +/// that the user has selected an option. +/// +/// See also: +/// +/// * [RawAutocomplete.onSelected], which is of this type. +typedef AutocompleteOnSelected<T extends Object> = void Function(T option); + +/// The type of the [RawAutocomplete] callback which returns a [Widget] that +/// displays the specified [options] and calls [onSelected] if the user +/// selects an option. +/// +/// The returned widget from this callback will be wrapped in an +/// [AutocompleteHighlightedOption] inherited widget. This will allow +/// this callback to determine which option is currently highlighted for +/// keyboard navigation. +/// +/// See also: +/// +/// * [RawAutocomplete.optionsViewBuilder], which is of this type. +typedef AutocompleteOptionsViewBuilder<T extends Object> = Widget Function( + BuildContext context, + AutocompleteOnSelected<T> onSelected, + Iterable<T> options, +); + +/// The type of the Autocomplete callback which returns the widget that +/// contains the input [TextField] or [TextFormField]. +/// +/// See also: +/// +/// * [RawAutocomplete.fieldViewBuilder], which is of this type. +typedef AutocompleteFieldViewBuilder = Widget Function( + BuildContext context, + TextEditingController textEditingController, + FocusNode focusNode, + VoidCallback onFieldSubmitted, +); + +/// The type of the [RawAutocomplete] callback that converts an option value to +/// a string which can be displayed in the widget's options menu. +/// +/// See also: +/// +/// * [RawAutocomplete.displayStringForOption], which is of this type. +typedef AutocompleteOptionToString<T extends Object> = String Function(T option); + +/// A direction in which to open the options-view overlay. +/// +/// See also: +/// +/// * [RawAutocomplete.optionsViewOpenDirection], which is of this type. +/// * [RawAutocomplete.optionsViewBuilder] to specify how to build the +/// selectable-options widget. +/// * [RawAutocomplete.fieldViewBuilder] to optionally specify how to build the +/// corresponding field widget. +enum OptionsViewOpenDirection { + /// Open upward. + /// + /// The bottom edge of the options view will align with the top edge + /// of the text field built by [RawAutocomplete.fieldViewBuilder]. + up, + + /// Open downward. + /// + /// The top edge of the options view will align with the bottom edge + /// of the text field built by [RawAutocomplete.fieldViewBuilder]. + down, +} + +// TODO(justinmc): Mention AutocompleteCupertino when it is implemented. +/// {@template flutter.widgets.RawAutocomplete.RawAutocomplete} +/// A widget for helping the user make a selection by entering some text and +/// choosing from among a list of options. +/// +/// The user's text input is received in a field built with the +/// [fieldViewBuilder] parameter. The options to be displayed are determined +/// using [optionsBuilder] and rendered with [optionsViewBuilder]. +/// {@endtemplate} +/// +/// This is a core framework widget with very basic UI. +/// +/// {@tool dartpad} +/// This example shows how to create a very basic autocomplete widget using the +/// [fieldViewBuilder] and [optionsViewBuilder] parameters. +/// +/// ** See code in examples/api/lib/widgets/autocomplete/raw_autocomplete.0.dart ** +/// {@end-tool} +/// +/// The type parameter T represents the type of the options. Most commonly this +/// is a String, as in the example above. However, it's also possible to use +/// another type with a `toString` method, or a custom [displayStringForOption]. +/// Options will be compared using `==`, so it may be beneficial to override +/// [Object.==] and [Object.hashCode] for custom types. +/// +/// {@tool dartpad} +/// This example is similar to the previous example, but it uses a custom T data +/// type instead of directly using String. +/// +/// ** See code in examples/api/lib/widgets/autocomplete/raw_autocomplete.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows the use of RawAutocomplete in a form. +/// +/// ** See code in examples/api/lib/widgets/autocomplete/raw_autocomplete.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Autocomplete], which is a Material-styled implementation that is based +/// on RawAutocomplete. +class RawAutocomplete<T extends Object> extends StatefulWidget { + /// Create an instance of RawAutocomplete. + /// + /// [displayStringForOption], [optionsBuilder] and [optionsViewBuilder] must + /// not be null. + const RawAutocomplete({ + super.key, + required this.optionsViewBuilder, + required this.optionsBuilder, + this.optionsViewOpenDirection = OptionsViewOpenDirection.down, + this.displayStringForOption = defaultStringForOption, + this.fieldViewBuilder, + this.focusNode, + this.onSelected, + this.textEditingController, + this.initialValue, + }) : assert( + fieldViewBuilder != null + || (key != null && focusNode != null && textEditingController != null), + 'Pass in a fieldViewBuilder, or otherwise create a separate field and pass in the FocusNode, TextEditingController, and a key. Use the key with RawAutocomplete.onFieldSubmitted.', + ), + assert((focusNode == null) == (textEditingController == null)), + assert( + !(textEditingController != null && initialValue != null), + 'textEditingController and initialValue cannot be simultaneously defined.', + ); + + /// {@template flutter.widgets.RawAutocomplete.fieldViewBuilder} + /// Builds the field whose input is used to get the options. + /// + /// Pass the provided [TextEditingController] to the field built here so that + /// RawAutocomplete can listen for changes. + /// {@endtemplate} + /// + /// If this parameter is null, then a [SizedBox.shrink] is built instead. + /// For how that pattern can be useful, see [textEditingController]. + final AutocompleteFieldViewBuilder? fieldViewBuilder; + + /// The [FocusNode] that is used for the text field. + /// + /// {@template flutter.widgets.RawAutocomplete.split} + /// The main purpose of this parameter is to allow the use of a separate text + /// field located in another part of the widget tree instead of the text + /// field built by [fieldViewBuilder]. For example, it may be desirable to + /// place the text field in the AppBar and the options below in the main body. + /// + /// When following this pattern, [fieldViewBuilder] can be omitted, + /// so that a text field is not drawn where it would normally be. + /// A separate text field can be created elsewhere, and a + /// FocusNode and TextEditingController can be passed both to that text field + /// and to RawAutocomplete. + /// + /// {@tool dartpad} + /// This examples shows how to create an autocomplete widget with the text + /// field in the AppBar and the results in the main body of the app. + /// + /// ** See code in examples/api/lib/widgets/autocomplete/raw_autocomplete.focus_node.0.dart ** + /// {@end-tool} + /// {@endtemplate} + /// + /// If this parameter is not null, then [textEditingController] must also be + /// not null. + final FocusNode? focusNode; + + /// {@template flutter.widgets.RawAutocomplete.optionsViewBuilder} + /// Builds the selectable options widgets from a list of options objects. + /// + /// The options are displayed floating below or above the field using a + /// [CompositedTransformFollower] inside of an [Overlay], not at the same + /// place in the widget tree as [RawAutocomplete]. To control whether it opens + /// upward or downward, use [optionsViewOpenDirection]. + /// + /// In order to track which item is highlighted by keyboard navigation, the + /// resulting options will be wrapped in an inherited + /// [AutocompleteHighlightedOption] widget. + /// Inside this callback, the index of the highlighted option can be obtained + /// from [AutocompleteHighlightedOption.of] to display the highlighted option + /// with a visual highlight to indicate it will be the option selected from + /// the keyboard. + /// + /// {@endtemplate} + final AutocompleteOptionsViewBuilder<T> optionsViewBuilder; + + /// {@template flutter.widgets.RawAutocomplete.optionsViewOpenDirection} + /// The direction in which to open the options-view overlay. + /// + /// Defaults to [OptionsViewOpenDirection.down]. + /// {@endtemplate} + final OptionsViewOpenDirection optionsViewOpenDirection; + + /// {@template flutter.widgets.RawAutocomplete.displayStringForOption} + /// Returns the string to display in the field when the option is selected. + /// + /// This is useful when using a custom T type and the string to display is + /// different than the string to search by. + /// + /// If not provided, will use `option.toString()`. + /// {@endtemplate} + final AutocompleteOptionToString<T> displayStringForOption; + + /// {@template flutter.widgets.RawAutocomplete.onSelected} + /// Called when an option is selected by the user. + /// {@endtemplate} + final AutocompleteOnSelected<T>? onSelected; + + /// {@template flutter.widgets.RawAutocomplete.optionsBuilder} + /// A function that returns the current selectable options objects given the + /// current TextEditingValue. + /// {@endtemplate} + final AutocompleteOptionsBuilder<T> optionsBuilder; + + /// The [TextEditingController] that is used for the text field. + /// + /// {@macro flutter.widgets.RawAutocomplete.split} + /// + /// If this parameter is not null, then [focusNode] must also be not null. + final TextEditingController? textEditingController; + + /// {@template flutter.widgets.RawAutocomplete.initialValue} + /// The initial value to use for the text field. + /// {@endtemplate} + /// + /// Setting the initial value does not notify [textEditingController]'s + /// listeners, and thus will not cause the options UI to appear. + /// + /// This parameter is ignored if [textEditingController] is defined. + final TextEditingValue? initialValue; + + /// Calls [AutocompleteFieldViewBuilder]'s onFieldSubmitted callback for the + /// RawAutocomplete widget indicated by the given [GlobalKey]. + /// + /// This is not typically used unless a custom field is implemented instead of + /// using [fieldViewBuilder]. In the typical case, the onFieldSubmitted + /// callback is passed via the [AutocompleteFieldViewBuilder] signature. When + /// not using fieldViewBuilder, the same callback can be called by using this + /// static method. + /// + /// See also: + /// + /// * [focusNode] and [textEditingController], which contain a code example + /// showing how to create a separate field outside of fieldViewBuilder. + static void onFieldSubmitted<T extends Object>(GlobalKey key) { + final _RawAutocompleteState<T> rawAutocomplete = key.currentState! as _RawAutocompleteState<T>; + rawAutocomplete._onFieldSubmitted(); + } + + /// The default way to convert an option to a string in + /// [displayStringForOption]. + /// + /// Uses the `toString` method of the given `option`. + static String defaultStringForOption(Object? option) { + return option.toString(); + } + + @override + State<RawAutocomplete<T>> createState() => _RawAutocompleteState<T>(); +} + +class _RawAutocompleteState<T extends Object> extends State<RawAutocomplete<T>> { + final GlobalKey _fieldKey = GlobalKey(); + final LayerLink _optionsLayerLink = LayerLink(); + late TextEditingController _textEditingController; + late FocusNode _focusNode; + late final Map<Type, Action<Intent>> _actionMap; + late final _AutocompleteCallbackAction<AutocompletePreviousOptionIntent> _previousOptionAction; + late final _AutocompleteCallbackAction<AutocompleteNextOptionIntent> _nextOptionAction; + late final _AutocompleteCallbackAction<DismissIntent> _hideOptionsAction; + Iterable<T> _options = Iterable<T>.empty(); + T? _selection; + bool _userHidOptions = false; + String _lastFieldText = ''; + final ValueNotifier<int> _highlightedOptionIndex = ValueNotifier<int>(0); + + static const Map<ShortcutActivator, Intent> _shortcuts = <ShortcutActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.arrowUp): AutocompletePreviousOptionIntent(), + SingleActivator(LogicalKeyboardKey.arrowDown): AutocompleteNextOptionIntent(), + }; + + // The OverlayEntry containing the options. + OverlayEntry? _floatingOptions; + + // True iff the state indicates that the options should be visible. + bool get _shouldShowOptions { + return !_userHidOptions && _focusNode.hasFocus && _selection == null && _options.isNotEmpty; + } + + // Called when _textEditingController changes. + Future<void> _onChangedField() async { + final TextEditingValue value = _textEditingController.value; + final Iterable<T> options = await widget.optionsBuilder( + value, + ); + _options = options; + _updateHighlight(_highlightedOptionIndex.value); + if (_selection != null + && value.text != widget.displayStringForOption(_selection!)) { + _selection = null; + } + + // Make sure the options are no longer hidden if the content of the field + // changes (ignore selection changes). + if (value.text != _lastFieldText) { + _userHidOptions = false; + _lastFieldText = value.text; + } + _updateActions(); + _updateOverlay(); + } + + // Called when the field's FocusNode changes. + void _onChangedFocus() { + // Options should no longer be hidden when the field is re-focused. + _userHidOptions = !_focusNode.hasFocus; + _updateActions(); + _updateOverlay(); + } + + // Called from fieldViewBuilder when the user submits the field. + void _onFieldSubmitted() { + if (_options.isEmpty || _userHidOptions) { + return; + } + _select(_options.elementAt(_highlightedOptionIndex.value)); + } + + // Select the given option and update the widget. + void _select(T nextSelection) { + if (nextSelection == _selection) { + return; + } + _selection = nextSelection; + final String selectionString = widget.displayStringForOption(nextSelection); + _textEditingController.value = TextEditingValue( + selection: TextSelection.collapsed(offset: selectionString.length), + text: selectionString, + ); + _updateActions(); + _updateOverlay(); + widget.onSelected?.call(_selection!); + } + + void _updateHighlight(int newIndex) { + _highlightedOptionIndex.value = _options.isEmpty ? 0 : newIndex % _options.length; + } + + void _highlightPreviousOption(AutocompletePreviousOptionIntent intent) { + if (_userHidOptions) { + _userHidOptions = false; + _updateActions(); + _updateOverlay(); + return; + } + _updateHighlight(_highlightedOptionIndex.value - 1); + } + + void _highlightNextOption(AutocompleteNextOptionIntent intent) { + if (_userHidOptions) { + _userHidOptions = false; + _updateActions(); + _updateOverlay(); + return; + } + _updateHighlight(_highlightedOptionIndex.value + 1); + } + + Object? _hideOptions(DismissIntent intent) { + if (!_userHidOptions) { + _userHidOptions = true; + _updateActions(); + _updateOverlay(); + return null; + } + return Actions.invoke(context, intent); + } + + void _setActionsEnabled(bool enabled) { + // The enabled state determines whether the action will consume the + // key shortcut or let it continue on to the underlying text field. + // They should only be enabled when the options are showing so shortcuts + // can be used to navigate them. + _previousOptionAction.enabled = enabled; + _nextOptionAction.enabled = enabled; + _hideOptionsAction.enabled = enabled; + } + + void _updateActions() { + _setActionsEnabled(_focusNode.hasFocus && _selection == null && _options.isNotEmpty); + } + + bool _floatingOptionsUpdateScheduled = false; + // Hide or show the options overlay, if needed. + void _updateOverlay() { + if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks) { + if (!_floatingOptionsUpdateScheduled) { + _floatingOptionsUpdateScheduled = true; + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + _floatingOptionsUpdateScheduled = false; + _updateOverlay(); + }, debugLabel: 'RawAutoComplete.updateOverlay'); + } + return; + } + + _floatingOptions?.remove(); + _floatingOptions?.dispose(); + if (_shouldShowOptions) { + final OverlayEntry newFloatingOptions = OverlayEntry( + builder: (BuildContext context) { + return CompositedTransformFollower( + link: _optionsLayerLink, + showWhenUnlinked: false, + targetAnchor: switch (widget.optionsViewOpenDirection) { + OptionsViewOpenDirection.up => Alignment.topLeft, + OptionsViewOpenDirection.down => Alignment.bottomLeft, + }, + followerAnchor: switch (widget.optionsViewOpenDirection) { + OptionsViewOpenDirection.up => Alignment.bottomLeft, + OptionsViewOpenDirection.down => Alignment.topLeft, + }, + child: TextFieldTapRegion( + child: AutocompleteHighlightedOption( + highlightIndexNotifier: _highlightedOptionIndex, + child: Builder( + builder: (BuildContext context) { + return widget.optionsViewBuilder(context, _select, _options); + } + ) + ), + ), + ); + }, + ); + Overlay.of(context, rootOverlay: true, debugRequiredFor: widget).insert(newFloatingOptions); + _floatingOptions = newFloatingOptions; + } else { + _floatingOptions = null; + } + } + + // Handle a potential change in textEditingController by properly disposing of + // the old one and setting up the new one, if needed. + void _updateTextEditingController(TextEditingController? old, TextEditingController? current) { + if ((old == null && current == null) || old == current) { + return; + } + if (old == null) { + _textEditingController.removeListener(_onChangedField); + _textEditingController.dispose(); + _textEditingController = current!; + } else if (current == null) { + _textEditingController.removeListener(_onChangedField); + _textEditingController = TextEditingController(); + } else { + _textEditingController.removeListener(_onChangedField); + _textEditingController = current; + } + _textEditingController.addListener(_onChangedField); + } + + // Handle a potential change in focusNode by properly disposing of the old one + // and setting up the new one, if needed. + void _updateFocusNode(FocusNode? old, FocusNode? current) { + if ((old == null && current == null) || old == current) { + return; + } + if (old == null) { + _focusNode.removeListener(_onChangedFocus); + _focusNode.dispose(); + _focusNode = current!; + } else if (current == null) { + _focusNode.removeListener(_onChangedFocus); + _focusNode = FocusNode(); + } else { + _focusNode.removeListener(_onChangedFocus); + _focusNode = current; + } + _focusNode.addListener(_onChangedFocus); + } + + @override + void initState() { + super.initState(); + _textEditingController = widget.textEditingController ?? TextEditingController.fromValue(widget.initialValue); + _textEditingController.addListener(_onChangedField); + _focusNode = widget.focusNode ?? FocusNode(); + _focusNode.addListener(_onChangedFocus); + _previousOptionAction = _AutocompleteCallbackAction<AutocompletePreviousOptionIntent>(onInvoke: _highlightPreviousOption); + _nextOptionAction = _AutocompleteCallbackAction<AutocompleteNextOptionIntent>(onInvoke: _highlightNextOption); + _hideOptionsAction = _AutocompleteCallbackAction<DismissIntent>(onInvoke: _hideOptions); + _actionMap = <Type, Action<Intent>> { + AutocompletePreviousOptionIntent: _previousOptionAction, + AutocompleteNextOptionIntent: _nextOptionAction, + DismissIntent: _hideOptionsAction, + }; + _updateActions(); + _updateOverlay(); + } + + @override + void didUpdateWidget(RawAutocomplete<T> oldWidget) { + super.didUpdateWidget(oldWidget); + _updateTextEditingController( + oldWidget.textEditingController, + widget.textEditingController, + ); + _updateFocusNode(oldWidget.focusNode, widget.focusNode); + _updateActions(); + _updateOverlay(); + } + + @override + void dispose() { + _textEditingController.removeListener(_onChangedField); + if (widget.textEditingController == null) { + _textEditingController.dispose(); + } + _focusNode.removeListener(_onChangedFocus); + if (widget.focusNode == null) { + _focusNode.dispose(); + } + _floatingOptions?.remove(); + _floatingOptions?.dispose(); + _floatingOptions = null; + _highlightedOptionIndex.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return TextFieldTapRegion( + child: Container( + key: _fieldKey, + child: Shortcuts( + shortcuts: _shortcuts, + child: Actions( + actions: _actionMap, + child: CompositedTransformTarget( + link: _optionsLayerLink, + child: widget.fieldViewBuilder == null + ? const SizedBox.shrink() + : widget.fieldViewBuilder!( + context, + _textEditingController, + _focusNode, + _onFieldSubmitted, + ), + ), + ), + ), + ), + ); + } +} + +class _AutocompleteCallbackAction<T extends Intent> extends CallbackAction<T> { + _AutocompleteCallbackAction({ + required super.onInvoke, + this.enabled = true, + }); + + bool enabled; + + @override + bool isEnabled(covariant T intent) => enabled; + + @override + bool consumesKey(covariant T intent) => enabled; +} + +/// An [Intent] to highlight the previous option in the autocomplete list. +class AutocompletePreviousOptionIntent extends Intent { + /// Creates an instance of AutocompletePreviousOptionIntent. + const AutocompletePreviousOptionIntent(); +} + +/// An [Intent] to highlight the next option in the autocomplete list. +class AutocompleteNextOptionIntent extends Intent { + /// Creates an instance of AutocompleteNextOptionIntent. + const AutocompleteNextOptionIntent(); +} + +/// An inherited widget used to indicate which autocomplete option should be +/// highlighted for keyboard navigation. +/// +/// The `RawAutoComplete` widget will wrap the options view generated by the +/// `optionsViewBuilder` with this widget to provide the highlighted option's +/// index to the builder. +/// +/// In the builder callback the index of the highlighted option can be obtained +/// by using the static [of] method: +/// +/// ```dart +/// int highlightedIndex = AutocompleteHighlightedOption.of(context); +/// ``` +/// +/// which can then be used to tell which option should be given a visual +/// indication that will be the option selected with the keyboard. +class AutocompleteHighlightedOption extends InheritedNotifier<ValueNotifier<int>> { + /// Create an instance of AutocompleteHighlightedOption inherited widget. + const AutocompleteHighlightedOption({ + super.key, + required ValueNotifier<int> highlightIndexNotifier, + required super.child, + }) : super(notifier: highlightIndexNotifier); + + /// Returns the index of the highlighted option from the closest + /// [AutocompleteHighlightedOption] ancestor. + /// + /// If there is no ancestor, it returns 0. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// int highlightedIndex = AutocompleteHighlightedOption.of(context); + /// ``` + static int of(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<AutocompleteHighlightedOption>()?.notifier?.value ?? 0; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/autofill.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/autofill.dart new file mode 100644 index 0000000000000000000000000000000000000000..0d72987d3490eb6f72f47f5123bef0ad169d6f99 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/autofill.dart @@ -0,0 +1,253 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; +import 'framework.dart'; + +export 'package:flutter/services.dart' show AutofillHints; + +/// Predefined autofill context clean up actions. +enum AutofillContextAction { + /// Destroys the current autofill context after informing the platform to save + /// the user input from it. + /// + /// Corresponds to calling [TextInput.finishAutofillContext] with + /// `shouldSave == true`. + commit, + + /// Destroys the current autofill context without saving the user input. + /// + /// Corresponds to calling [TextInput.finishAutofillContext] with + /// `shouldSave == false`. + cancel, +} + +/// An [AutofillScope] widget that groups [AutofillClient]s together. +/// +/// [AutofillClient]s that share the same closest [AutofillGroup] ancestor must +/// be built together, and they be will be autofilled together. +/// +/// {@macro flutter.services.AutofillScope} +/// +/// The [AutofillGroup] widget only knows about [AutofillClient]s registered to +/// it using the [AutofillGroupState.register] API. Typically, [AutofillGroup] +/// will not pick up [AutofillClient]s that are not mounted, for example, an +/// [AutofillClient] within a [Scrollable] that has never been scrolled into the +/// viewport. To workaround this problem, ensure clients in the same +/// [AutofillGroup] are built together. +/// +/// The topmost [AutofillGroup] widgets (the ones that are closest to the root +/// widget) can be used to clean up the current autofill context when the +/// current autofill context is no longer relevant. +/// +/// {@macro flutter.services.TextInput.finishAutofillContext} +/// +/// By default, [onDisposeAction] is set to [AutofillContextAction.commit], in +/// which case when any of the topmost [AutofillGroup]s is being disposed, the +/// platform will be informed to save the user input from the current autofill +/// context, then the current autofill context will be destroyed, to free +/// resources. You can, for example, wrap a route that contains a [Form] full of +/// autofillable input fields in an [AutofillGroup], so the user input of the +/// [Form] can be saved for future autofill by the platform. +/// +/// {@tool dartpad} +/// An example form with autofillable fields grouped into different +/// [AutofillGroup]s. +/// +/// ** See code in examples/api/lib/widgets/autofill/autofill_group.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AutofillContextAction], an enum that contains predefined autofill context +/// clean up actions to be run when a topmost [AutofillGroup] is disposed. +class AutofillGroup extends StatefulWidget { + /// Creates a scope for autofillable input fields. + const AutofillGroup({ + super.key, + required this.child, + this.onDisposeAction = AutofillContextAction.commit, + }); + + /// Returns the [AutofillGroupState] of the closest [AutofillGroup] widget + /// which encloses the given context, or null if one cannot be found. + /// + /// Calling this method will create a dependency on the closest + /// [AutofillGroup] in the [context], if there is one. + /// + /// {@macro flutter.widgets.AutofillGroupState} + /// + /// See also: + /// + /// * [AutofillGroup.of], which is similar to this method, but asserts if an + /// [AutofillGroup] cannot be found. + /// * [EditableTextState], where this method is used to retrieve the closest + /// [AutofillGroupState]. + static AutofillGroupState? maybeOf(BuildContext context) { + final _AutofillScope? scope = context.dependOnInheritedWidgetOfExactType<_AutofillScope>(); + return scope?._scope; + } + + /// Returns the [AutofillGroupState] of the closest [AutofillGroup] widget + /// which encloses the given context. + /// + /// If no instance is found, this method will assert in debug mode and throw + /// an exception in release mode. + /// + /// Calling this method will create a dependency on the closest + /// [AutofillGroup] in the [context]. + /// + /// {@macro flutter.widgets.AutofillGroupState} + /// + /// See also: + /// + /// * [AutofillGroup.maybeOf], which is similar to this method, but returns + /// null if an [AutofillGroup] cannot be found. + /// * [EditableTextState], where this method is used to retrieve the closest + /// [AutofillGroupState]. + static AutofillGroupState of(BuildContext context) { + final AutofillGroupState? groupState = maybeOf(context); + assert(() { + if (groupState == null) { + throw FlutterError( + 'AutofillGroup.of() was called with a context that does not contain an ' + 'AutofillGroup widget.\n' + 'No AutofillGroup widget ancestor could be found starting from the ' + 'context that was passed to AutofillGroup.of(). This can happen ' + 'because you are using a widget that looks for an AutofillGroup ' + 'ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return groupState!; + } + + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The [AutofillContextAction] to be run when this [AutofillGroup] is the + /// topmost [AutofillGroup] and it's being disposed, in order to clean up the + /// current autofill context. + /// + /// {@macro flutter.services.TextInput.finishAutofillContext} + /// + /// Defaults to [AutofillContextAction.commit], which prompts the platform to + /// save the user input and destroy the current autofill context. + final AutofillContextAction onDisposeAction; + + @override + AutofillGroupState createState() => AutofillGroupState(); +} + +/// State associated with an [AutofillGroup] widget. +/// +/// {@template flutter.widgets.AutofillGroupState} +/// An [AutofillGroupState] can be used to register an [AutofillClient] when it +/// enters this [AutofillGroup] (for example, when an [EditableText] is mounted or +/// reparented onto the [AutofillGroup]'s subtree), and unregister an +/// [AutofillClient] when it exits (for example, when an [EditableText] gets +/// unmounted or reparented out of the [AutofillGroup]'s subtree). +/// +/// The [AutofillGroupState] class also provides an [AutofillGroupState.attach] +/// method that can be called by [TextInputClient]s that support autofill, +/// instead of [TextInput.attach], to create a [TextInputConnection] to interact +/// with the platform's text input system. +/// {@endtemplate} +/// +/// Typically obtained using [AutofillGroup.of]. +class AutofillGroupState extends State<AutofillGroup> with AutofillScopeMixin { + final Map<String, AutofillClient> _clients = <String, AutofillClient>{}; + + // Whether this AutofillGroup widget is the topmost AutofillGroup (i.e., it + // has no AutofillGroup ancestor). Each topmost AutofillGroup runs its + // `AutofillGroup.onDisposeAction` when it gets disposed. + bool _isTopmostAutofillGroup = false; + + @override + AutofillClient? getAutofillClient(String autofillId) => _clients[autofillId]; + + @override + Iterable<AutofillClient> get autofillClients { + return _clients.values + .where((AutofillClient client) => client.textInputConfiguration.autofillConfiguration.enabled); + } + + /// Adds the [AutofillClient] to this [AutofillGroup]. + /// + /// Typically, this is called by [TextInputClient]s that support autofill (for + /// example, [EditableTextState]) in [State.didChangeDependencies], when the + /// input field should be registered to a new [AutofillGroup]. + /// + /// See also: + /// + /// * [EditableTextState.didChangeDependencies], where this method is called + /// to update the current [AutofillScope] when needed. + void register(AutofillClient client) { + _clients.putIfAbsent(client.autofillId, () => client); + } + + /// Removes an [AutofillClient] with the given `autofillId` from this + /// [AutofillGroup]. + /// + /// Typically, this should be called by a text field when it's being disposed, + /// or before it's registered with a different [AutofillGroup]. + /// + /// See also: + /// + /// * [EditableTextState.didChangeDependencies], where this method is called + /// to unregister from the previous [AutofillScope]. + /// * [EditableTextState.dispose], where this method is called to unregister + /// from the current [AutofillScope] when the widget is about to be removed + /// from the tree. + void unregister(String autofillId) { + assert(_clients.containsKey(autofillId)); + _clients.remove(autofillId); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _isTopmostAutofillGroup = AutofillGroup.maybeOf(context) == null; + } + + @override + Widget build(BuildContext context) { + return _AutofillScope( + autofillScopeState: this, + child: widget.child, + ); + } + + @override + void dispose() { + super.dispose(); + + if (!_isTopmostAutofillGroup) { + return; + } + switch (widget.onDisposeAction) { + case AutofillContextAction.cancel: + TextInput.finishAutofillContext(shouldSave: false); + case AutofillContextAction.commit: + TextInput.finishAutofillContext(); + } + } +} + +class _AutofillScope extends InheritedWidget { + const _AutofillScope({ + required super.child, + AutofillGroupState? autofillScopeState, + }) : _scope = autofillScopeState; + + final AutofillGroupState? _scope; + + AutofillGroup get client => _scope!.widget; + + @override + bool updateShouldNotify(_AutofillScope old) => _scope != old._scope; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/automatic_keep_alive.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/automatic_keep_alive.dart new file mode 100644 index 0000000000000000000000000000000000000000..bd40d2aa80fd96f9a70ac7788f68dc62651646ff --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/automatic_keep_alive.dart @@ -0,0 +1,432 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; + +import 'framework.dart'; +import 'notification_listener.dart'; +import 'sliver.dart'; + +/// Allows subtrees to request to be kept alive in lazy lists. +/// +/// This widget is like [KeepAlive] but instead of being explicitly configured, +/// it listens to [KeepAliveNotification] messages from the [child] and other +/// descendants. +/// +/// The subtree is kept alive whenever there is one or more descendant that has +/// sent a [KeepAliveNotification] and not yet triggered its +/// [KeepAliveNotification.handle]. +/// +/// To send these notifications, consider using [AutomaticKeepAliveClientMixin]. +class AutomaticKeepAlive extends StatefulWidget { + /// Creates a widget that listens to [KeepAliveNotification]s and maintains a + /// [KeepAlive] widget appropriately. + const AutomaticKeepAlive({ + super.key, + required this.child, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + State<AutomaticKeepAlive> createState() => _AutomaticKeepAliveState(); +} + +class _AutomaticKeepAliveState extends State<AutomaticKeepAlive> { + Map<Listenable, VoidCallback>? _handles; + // In order to apply parent data out of turn, the child of the KeepAlive + // widget must be the same across frames. + late Widget _child; + bool _keepingAlive = false; + + @override + void initState() { + super.initState(); + _updateChild(); + } + + @override + void didUpdateWidget(AutomaticKeepAlive oldWidget) { + super.didUpdateWidget(oldWidget); + _updateChild(); + } + + void _updateChild() { + _child = NotificationListener<KeepAliveNotification>( + onNotification: _addClient, + child: widget.child, + ); + } + + @override + void dispose() { + if (_handles != null) { + for (final Listenable handle in _handles!.keys) { + handle.removeListener(_handles![handle]!); + } + } + super.dispose(); + } + + bool _addClient(KeepAliveNotification notification) { + final Listenable handle = notification.handle; + _handles ??= <Listenable, VoidCallback>{}; + assert(!_handles!.containsKey(handle)); + _handles![handle] = _createCallback(handle); + handle.addListener(_handles![handle]!); + if (!_keepingAlive) { + _keepingAlive = true; + final ParentDataElement<KeepAliveParentDataMixin>? childElement = _getChildElement(); + if (childElement != null) { + // If the child already exists, update it synchronously. + _updateParentDataOfChild(childElement); + } else { + // If the child doesn't exist yet, we got called during the very first + // build of this subtree. Wait until the end of the frame to update + // the child when the child is guaranteed to be present. + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + if (!mounted) { + return; + } + final ParentDataElement<KeepAliveParentDataMixin>? childElement = _getChildElement(); + assert(childElement != null); + _updateParentDataOfChild(childElement!); + }, debugLabel: 'AutomaticKeepAlive.updateParentData'); + } + } + return false; + } + + /// Get the [Element] for the only [KeepAlive] child. + /// + /// While this widget is guaranteed to have a child, this may return null if + /// the first build of that child has not completed yet. + ParentDataElement<KeepAliveParentDataMixin>? _getChildElement() { + assert(mounted); + final Element element = context as Element; + Element? childElement; + // We use Element.visitChildren rather than context.visitChildElements + // because we might be called during build, and context.visitChildElements + // verifies that it is not called during build. Element.visitChildren does + // not, instead it assumes that the caller will be careful. (See the + // documentation for these methods for more details.) + // + // Here we know it's safe (with the exception outlined below) because we + // just received a notification, which we wouldn't be able to do if we + // hadn't built our child and its child -- our build method always builds + // the same subtree and it always includes the node we're looking for + // (KeepAlive) as the parent of the node that reports the notifications + // (NotificationListener). + // + // If we are called during the first build of this subtree the links to the + // children will not be hooked up yet. In that case this method returns + // null despite the fact that we will have a child after the build + // completes. It's the caller's responsibility to deal with this case. + // + // (We're only going down one level, to get our direct child.) + element.visitChildren((Element child) { + childElement = child; + }); + assert(childElement == null || childElement is ParentDataElement<KeepAliveParentDataMixin>); + return childElement as ParentDataElement<KeepAliveParentDataMixin>?; + } + + void _updateParentDataOfChild(ParentDataElement<KeepAliveParentDataMixin> childElement) { + childElement.applyWidgetOutOfTurn(build(context) as ParentDataWidget<KeepAliveParentDataMixin>); + } + + VoidCallback _createCallback(Listenable handle) { + late final VoidCallback callback; + return callback = () { + assert(() { + if (!mounted) { + throw FlutterError( + 'AutomaticKeepAlive handle triggered after AutomaticKeepAlive was disposed.\n' + 'Widgets should always trigger their KeepAliveNotification handle when they are ' + 'deactivated, so that they (or their handle) do not send spurious events later ' + 'when they are no longer in the tree.', + ); + } + return true; + }()); + _handles!.remove(handle); + handle.removeListener(callback); + if (_handles!.isEmpty) { + if (SchedulerBinding.instance.schedulerPhase.index < SchedulerPhase.persistentCallbacks.index) { + // Build/layout haven't started yet so let's just schedule this for + // the next frame. + setState(() { _keepingAlive = false; }); + } else { + // We were probably notified by a descendant when they were yanked out + // of our subtree somehow. We're probably in the middle of build or + // layout, so there's really nothing we can do to clean up this mess + // short of just scheduling another build to do the cleanup. This is + // very unfortunate, and means (for instance) that garbage collection + // of these resources won't happen for another 16ms. + // + // The problem is there's really no way for us to distinguish these + // cases: + // + // * We haven't built yet (or missed out chance to build), but + // someone above us notified our descendant and our descendant is + // disconnecting from us. If we could mark ourselves dirty we would + // be able to clean everything this frame. (This is a pretty + // unlikely scenario in practice. Usually things change before + // build/layout, not during build/layout.) + // + // * Our child changed, and as our old child went away, it notified + // us. We can't setState, since we _just_ built. We can't apply the + // parent data information to our child because we don't _have_ a + // child at this instant. We really want to be able to change our + // mind about how we built, so we can give the KeepAlive widget a + // new value, but it's too late. + // + // * A deep descendant in another build scope just got yanked, and in + // the process notified us. We could apply new parent data + // information, but it may or may not get applied this frame, + // depending on whether said child is in the same layout scope. + // + // * A descendant is being moved from one position under us to + // another position under us. They just notified us of the removal, + // at some point in the future they will notify us of the addition. + // We don't want to do anything. (This is why we check that + // _handles is still empty below.) + // + // * We're being notified in the paint phase, or even in a post-frame + // callback. Either way it is far too late for us to make our + // parent lay out again this frame, so the garbage won't get + // collected this frame. + // + // * We are being torn out of the tree ourselves, as is our + // descendant, and it notified us while it was being deactivated. + // We don't need to do anything, but we don't know yet because we + // haven't been deactivated yet. (This is why we check mounted + // below before calling setState.) + // + // Long story short, we have to schedule a new frame and request a + // frame there, but this is generally a bad practice, and you should + // avoid it if possible. + _keepingAlive = false; + scheduleMicrotask(() { + if (mounted && _handles!.isEmpty) { + // If mounted is false, we went away as well, so there's nothing to do. + // If _handles is no longer empty, then another client (or the same + // client in a new place) registered itself before we had a chance to + // turn off keepalive, so again there's nothing to do. + setState(() { + assert(!_keepingAlive); + }); + } + }); + } + } + }; + } + + @override + Widget build(BuildContext context) { + return KeepAlive( + keepAlive: _keepingAlive, + child: _child, + ); + } + + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(FlagProperty('_keepingAlive', value: _keepingAlive, ifTrue: 'keeping subtree alive')); + description.add(DiagnosticsProperty<Map<Listenable, VoidCallback>>( + 'handles', + _handles, + description: _handles != null ? + '${_handles!.length} active client${ _handles!.length == 1 ? "" : "s" }' : + null, + ifNull: 'no notifications ever received', + )); + } +} + +/// Indicates that the subtree through which this notification bubbles must be +/// kept alive even if it would normally be discarded as an optimization. +/// +/// For example, a focused text field might fire this notification to indicate +/// that it should not be disposed even if the user scrolls the field off +/// screen. +/// +/// Each [KeepAliveNotification] is configured with a [handle] that consists of +/// a [Listenable] that is triggered when the subtree no longer needs to be kept +/// alive. +/// +/// The [handle] should be triggered any time the sending widget is removed from +/// the tree (in [State.deactivate]). If the widget is then rebuilt and still +/// needs to be kept alive, it should immediately send a new notification +/// (possible with the very same [Listenable]) during build. +/// +/// This notification is listened to by the [AutomaticKeepAlive] widget, which +/// is added to the tree automatically by [SliverList] (and [ListView]) and +/// [SliverGrid] (and [GridView]) widgets. +/// +/// Failure to trigger the [handle] in the manner described above will likely +/// cause the [AutomaticKeepAlive] to lose track of whether the widget should be +/// kept alive or not, leading to memory leaks or lost data. For example, if the +/// widget that requested keepalive is removed from the subtree but doesn't +/// trigger its [Listenable] on the way out, then the subtree will continue to +/// be kept alive until the list itself is disposed. Similarly, if the +/// [Listenable] is triggered while the widget needs to be kept alive, but a new +/// [KeepAliveNotification] is not immediately sent, then the widget risks being +/// garbage collected while it wants to be kept alive. +/// +/// It is an error to use the same [handle] in two [KeepAliveNotification]s +/// within the same [AutomaticKeepAlive] without triggering that [handle] before +/// the second notification is sent. +/// +/// For a more convenient way to interact with [AutomaticKeepAlive] widgets, +/// consider using [AutomaticKeepAliveClientMixin], which uses +/// [KeepAliveNotification] internally. +class KeepAliveNotification extends Notification { + /// Creates a notification to indicate that a subtree must be kept alive. + const KeepAliveNotification(this.handle); + + /// A [Listenable] that will inform its clients when the widget that fired the + /// notification no longer needs to be kept alive. + /// + /// The [Listenable] should be triggered any time the sending widget is + /// removed from the tree (in [State.deactivate]). If the widget is then + /// rebuilt and still needs to be kept alive, it should immediately send a new + /// notification (possible with the very same [Listenable]) during build. + /// + /// See also: + /// + /// * [KeepAliveHandle], a convenience class for use with this property. + final Listenable handle; +} + +/// A [Listenable] which can be manually triggered. +/// +/// Used with [KeepAliveNotification] objects as their +/// [KeepAliveNotification.handle]. +/// +/// For a more convenient way to interact with [AutomaticKeepAlive] widgets, +/// consider using [AutomaticKeepAliveClientMixin], which uses a +/// [KeepAliveHandle] internally. +class KeepAliveHandle extends ChangeNotifier { + /// Trigger the listeners to indicate that the widget + /// no longer needs to be kept alive. + /// + /// This method does not call [dispose]. When the handle is not needed + /// anymore, it must be [dispose]d regardless of whether notifying listeners. + @Deprecated( + 'Use dispose instead. ' + 'This feature was deprecated after v3.3.0-0.0.pre.', + ) + void release() { + notifyListeners(); + } + + @override + void dispose() { + notifyListeners(); + super.dispose(); + } +} + +/// A mixin with convenience methods for clients of [AutomaticKeepAlive]. Used +/// with [State] subclasses. +/// +/// Subclasses must implement [wantKeepAlive], and their [build] methods must +/// call `super.build` (though the return value should be ignored). +/// +/// Then, whenever [wantKeepAlive]'s value changes (or might change), the +/// subclass should call [updateKeepAlive]. +/// +/// The type argument `T` is the type of the [StatefulWidget] subclass of the +/// [State] into which this class is being mixed. +/// +/// See also: +/// +/// * [AutomaticKeepAlive], which listens to messages from this mixin. +/// * [KeepAliveNotification], the notifications sent by this mixin. +@optionalTypeArgs +mixin AutomaticKeepAliveClientMixin<T extends StatefulWidget> on State<T> { + KeepAliveHandle? _keepAliveHandle; + + void _ensureKeepAlive() { + assert(_keepAliveHandle == null); + _keepAliveHandle = KeepAliveHandle(); + KeepAliveNotification(_keepAliveHandle!).dispatch(context); + } + + void _releaseKeepAlive() { + // Dispose and release do not imply each other. + _keepAliveHandle!.dispose(); + _keepAliveHandle = null; + } + + /// Whether the current instance should be kept alive. + /// + /// Call [updateKeepAlive] whenever this getter's value changes. + @protected + bool get wantKeepAlive; + + /// Ensures that any [AutomaticKeepAlive] ancestors are in a good state, by + /// firing a [KeepAliveNotification] or triggering the [KeepAliveHandle] as + /// appropriate. + @protected + void updateKeepAlive() { + if (wantKeepAlive) { + if (_keepAliveHandle == null) { + _ensureKeepAlive(); + } + } else { + if (_keepAliveHandle != null) { + _releaseKeepAlive(); + } + } + } + + @override + void initState() { + super.initState(); + if (wantKeepAlive) { + _ensureKeepAlive(); + } + } + + @override + void deactivate() { + if (_keepAliveHandle != null) { + _releaseKeepAlive(); + } + super.deactivate(); + } + + @mustCallSuper + @override + Widget build(BuildContext context) { + if (wantKeepAlive && _keepAliveHandle == null) { + _ensureKeepAlive(); + } + return const _NullWidget(); + } +} + +class _NullWidget extends StatelessWidget { + const _NullWidget(); + + @override + Widget build(BuildContext context) { + throw FlutterError( + 'Widgets that mix AutomaticKeepAliveClientMixin into their State must ' + 'call super.build() but must ignore the return value of the superclass.', + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/banner.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/banner.dart new file mode 100644 index 0000000000000000000000000000000000000000..08846c2bef983ec7f087ebd8feced0d9636ea7f6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/banner.dart @@ -0,0 +1,394 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; + +const double _kOffset = 40.0; // distance to bottom of banner, at a 45 degree angle inwards +const double _kHeight = 12.0; // height of banner +const double _kBottomOffset = _kOffset + 0.707 * _kHeight; // offset plus sqrt(2)/2 * banner height +const Rect _kRect = Rect.fromLTWH(-_kOffset, _kOffset - _kHeight, _kOffset * 2.0, _kHeight); + +const Color _kColor = Color(0xA0B71C1C); +const TextStyle _kTextStyle = TextStyle( + color: Color(0xFFFFFFFF), + fontSize: _kHeight * 0.85, + fontWeight: FontWeight.w900, + height: 1.0, +); + +const String _flutterWidgetsLibrary = 'package:flutter/widgets.dart'; + +/// Where to show a [Banner]. +/// +/// The start and end locations are relative to the ambient [Directionality] +/// (which can be overridden by [Banner.layoutDirection]). +enum BannerLocation { + /// Show the banner in the top-right corner when the ambient [Directionality] + /// (or [Banner.layoutDirection]) is [TextDirection.rtl] and in the top-left + /// corner when the ambient [Directionality] is [TextDirection.ltr]. + topStart, + + /// Show the banner in the top-left corner when the ambient [Directionality] + /// (or [Banner.layoutDirection]) is [TextDirection.rtl] and in the top-right + /// corner when the ambient [Directionality] is [TextDirection.ltr]. + topEnd, + + /// Show the banner in the bottom-right corner when the ambient + /// [Directionality] (or [Banner.layoutDirection]) is [TextDirection.rtl] and + /// in the bottom-left corner when the ambient [Directionality] is + /// [TextDirection.ltr]. + bottomStart, + + /// Show the banner in the bottom-left corner when the ambient + /// [Directionality] (or [Banner.layoutDirection]) is [TextDirection.rtl] and + /// in the bottom-right corner when the ambient [Directionality] is + /// [TextDirection.ltr]. + bottomEnd, +} + +/// Paints a [Banner]. +class BannerPainter extends CustomPainter { + /// Creates a banner painter. + BannerPainter({ + required this.message, + required this.textDirection, + required this.location, + required this.layoutDirection, + this.color = _kColor, + this.textStyle = _kTextStyle, + }) : super(repaint: PaintingBinding.instance.systemFonts) { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: _flutterWidgetsLibrary, + className: '$BannerPainter', + object: this, + ); + } + } + + /// The message to show in the banner. + final String message; + + /// The directionality of the text. + /// + /// This value is used to disambiguate how to render bidirectional text. For + /// example, if the message is an English phrase followed by a Hebrew phrase, + /// in a [TextDirection.ltr] context the English phrase will be on the left + /// and the Hebrew phrase to its right, while in a [TextDirection.rtl] + /// context, the English phrase will be on the right and the Hebrew phrase on + /// its left. + /// + /// See also: + /// + /// * [layoutDirection], which controls the interpretation of values in + /// [location]. + final TextDirection textDirection; + + /// Where to show the banner (e.g., the upper right corner). + final BannerLocation location; + + /// The directionality of the layout. + /// + /// This value is used to interpret the [location] of the banner. + /// + /// See also: + /// + /// * [textDirection], which controls the reading direction of the [message]. + final TextDirection layoutDirection; + + /// The color to paint behind the [message]. + /// + /// Defaults to a dark red. + final Color color; + + /// The text style to use for the [message]. + /// + /// Defaults to bold, white text. + final TextStyle textStyle; + + static const BoxShadow _shadow = BoxShadow( + color: Color(0x7F000000), + blurRadius: 6.0, + ); + + bool _prepared = false; + TextPainter? _textPainter; + late Paint _paintShadow; + late Paint _paintBanner; + + /// Release resources held by this painter. + /// + /// After calling this method, this object is no longer usable. + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _textPainter?.dispose(); + _textPainter = null; + } + + void _prepare() { + _paintShadow = _shadow.toPaint(); + _paintBanner = Paint() + ..color = color; + _textPainter?.dispose(); + _textPainter = TextPainter( + text: TextSpan(style: textStyle, text: message), + textAlign: TextAlign.center, + textDirection: textDirection, + ); + _prepared = true; + } + + @override + void paint(Canvas canvas, Size size) { + if (!_prepared) { + _prepare(); + } + canvas + ..translate(_translationX(size.width), _translationY(size.height)) + ..rotate(_rotation) + ..drawRect(_kRect, _paintShadow) + ..drawRect(_kRect, _paintBanner); + const double width = _kOffset * 2.0; + _textPainter!.layout(minWidth: width, maxWidth: width); + _textPainter!.paint(canvas, _kRect.topLeft + Offset(0.0, (_kRect.height - _textPainter!.height) / 2.0)); + } + + @override + bool shouldRepaint(BannerPainter oldDelegate) { + return message != oldDelegate.message + || location != oldDelegate.location + || color != oldDelegate.color + || textStyle != oldDelegate.textStyle; + } + + @override + bool hitTest(Offset position) => false; + + double _translationX(double width) { + switch (layoutDirection) { + case TextDirection.rtl: + switch (location) { + case BannerLocation.bottomEnd: + return _kBottomOffset; + case BannerLocation.topEnd: + return 0.0; + case BannerLocation.bottomStart: + return width - _kBottomOffset; + case BannerLocation.topStart: + return width; + } + case TextDirection.ltr: + switch (location) { + case BannerLocation.bottomEnd: + return width - _kBottomOffset; + case BannerLocation.topEnd: + return width; + case BannerLocation.bottomStart: + return _kBottomOffset; + case BannerLocation.topStart: + return 0.0; + } + } + } + + double _translationY(double height) { + switch (location) { + case BannerLocation.bottomStart: + case BannerLocation.bottomEnd: + return height - _kBottomOffset; + case BannerLocation.topStart: + case BannerLocation.topEnd: + return 0.0; + } + } + + double get _rotation { + switch (layoutDirection) { + case TextDirection.rtl: + switch (location) { + case BannerLocation.bottomStart: + case BannerLocation.topEnd: + return -math.pi / 4.0; + case BannerLocation.bottomEnd: + case BannerLocation.topStart: + return math.pi / 4.0; + } + case TextDirection.ltr: + switch (location) { + case BannerLocation.bottomStart: + case BannerLocation.topEnd: + return math.pi / 4.0; + case BannerLocation.bottomEnd: + case BannerLocation.topStart: + return -math.pi / 4.0; + } + } + } +} + +/// Displays a diagonal message above the corner of another widget. +/// +/// Useful for showing the execution mode of an app (e.g., that asserts are +/// enabled.) +/// +/// See also: +/// +/// * [CheckedModeBanner], which the [WidgetsApp] widget includes by default in +/// debug mode, to show a banner that says "DEBUG". +class Banner extends StatefulWidget { + /// Creates a banner. + const Banner({ + super.key, + this.child, + required this.message, + this.textDirection, + required this.location, + this.layoutDirection, + this.color = _kColor, + this.textStyle = _kTextStyle, + }); + + /// The widget to show behind the banner. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The message to show in the banner. + final String message; + + /// The directionality of the text. + /// + /// This is used to disambiguate how to render bidirectional text. For + /// example, if the message is an English phrase followed by a Hebrew phrase, + /// in a [TextDirection.ltr] context the English phrase will be on the left + /// and the Hebrew phrase to its right, while in a [TextDirection.rtl] + /// context, the English phrase will be on the right and the Hebrew phrase on + /// its left. + /// + /// Defaults to the ambient [Directionality], if any. + /// + /// See also: + /// + /// * [layoutDirection], which controls the interpretation of the [location]. + final TextDirection? textDirection; + + /// Where to show the banner (e.g., the upper right corner). + final BannerLocation location; + + /// The directionality of the layout. + /// + /// This is used to resolve the [location] values. + /// + /// Defaults to the ambient [Directionality], if any. + /// + /// See also: + /// + /// * [textDirection], which controls the reading direction of the [message]. + final TextDirection? layoutDirection; + + /// The color of the banner. + final Color color; + + /// The style of the text shown on the banner. + final TextStyle textStyle; + + @override + State<Banner> createState() => _BannerState(); +} + +class _BannerState extends State<Banner> { + BannerPainter? _painter; + + @override + void dispose() { + _painter?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + assert((widget.textDirection != null && widget.layoutDirection != null) || debugCheckHasDirectionality(context)); + + _painter?.dispose(); + _painter = BannerPainter( + message: widget.message, + textDirection: widget.textDirection ?? Directionality.of(context), + location: widget.location, + layoutDirection: widget.layoutDirection ?? Directionality.of(context), + color: widget.color, + textStyle: widget.textStyle, + ); + + return CustomPaint( + foregroundPainter: _painter, + child: widget.child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('message', widget.message, showName: false)); + properties.add(EnumProperty<TextDirection>('textDirection', widget.textDirection, defaultValue: null)); + properties.add(EnumProperty<BannerLocation>('location', widget.location)); + properties.add(EnumProperty<TextDirection>('layoutDirection', widget.layoutDirection, defaultValue: null)); + properties.add(ColorProperty('color', widget.color, showName: false)); + widget.textStyle.debugFillProperties(properties, prefix: 'text '); + } +} + +/// Displays a [Banner] saying "DEBUG" when running in debug mode. +/// [MaterialApp] builds one of these by default. +/// +/// Does nothing in release mode. +class CheckedModeBanner extends StatelessWidget { + /// Creates a const debug mode banner. + const CheckedModeBanner({ + super.key, + required this.child, + }); + + /// The widget to show behind the banner. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + Widget result = child; + assert(() { + result = Banner( + message: 'DEBUG', + textDirection: TextDirection.ltr, + location: BannerLocation.topEnd, + child: result, + ); + return true; + }()); + return result; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + String message = 'disabled'; + assert(() { + message = '"DEBUG"'; + return true; + }()); + properties.add(DiagnosticsNode.message(message)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/basic.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/basic.dart new file mode 100644 index 0000000000000000000000000000000000000000..e881d99db0cd3b8158d3d4f7a3ea431ff81239b9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/basic.dart @@ -0,0 +1,7832 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui show Image, ImageFilter, TextHeightBehavior; + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; + +import 'binding.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'localizations.dart'; +import 'visibility.dart'; +import 'widget_span.dart'; + +export 'package:flutter/animation.dart'; +export 'package:flutter/foundation.dart' show + ChangeNotifier, + FlutterErrorDetails, + Listenable, + TargetPlatform, + ValueNotifier; +export 'package:flutter/painting.dart'; +export 'package:flutter/rendering.dart' show + AlignmentGeometryTween, + AlignmentTween, + Axis, + BoxConstraints, + BoxConstraintsTransform, + CrossAxisAlignment, + CustomClipper, + CustomPainter, + CustomPainterSemantics, + DecorationPosition, + FlexFit, + FlowDelegate, + FlowPaintingContext, + FractionalOffsetTween, + HitTestBehavior, + LayerLink, + MainAxisAlignment, + MainAxisSize, + MouseCursor, + MultiChildLayoutDelegate, + PaintingContext, + PointerCancelEvent, + PointerCancelEventListener, + PointerDownEvent, + PointerDownEventListener, + PointerEvent, + PointerMoveEvent, + PointerMoveEventListener, + PointerUpEvent, + PointerUpEventListener, + RelativeRect, + SemanticsBuilderCallback, + ShaderCallback, + ShapeBorderClipper, + SingleChildLayoutDelegate, + StackFit, + SystemMouseCursors, + TextOverflow, + ValueChanged, + ValueGetter, + WrapAlignment, + WrapCrossAlignment; +export 'package:flutter/services.dart' show + AssetBundle; + +// Examples can assume: +// class TestWidget extends StatelessWidget { const TestWidget({super.key}); @override Widget build(BuildContext context) => const Placeholder(); } +// late WidgetTester tester; +// late bool _visible; +// class Sky extends CustomPainter { @override void paint(Canvas c, Size s) {} @override bool shouldRepaint(Sky s) => false; } +// late BuildContext context; +// String userAvatarUrl = ''; + +// BIDIRECTIONAL TEXT SUPPORT + +/// An [InheritedElement] that has hundreds of dependencies but will +/// infrequently change. This provides a performance tradeoff where building +/// the [Widget]s is faster but performing updates is slower. +/// +/// | | _UbiquitousInheritedElement | InheritedElement | +/// |---------------------|------------------------------|------------------| +/// | insert (best case) | O(1) | O(1) | +/// | insert (worst case) | O(1) | O(n) | +/// | search (best case) | O(n) | O(1) | +/// | search (worst case) | O(n) | O(n) | +/// +/// Insert happens when building the [Widget] tree, search happens when updating +/// [Widget]s. +class _UbiquitousInheritedElement extends InheritedElement { + /// Creates an element that uses the given widget as its configuration. + _UbiquitousInheritedElement(super.widget); + + @override + void setDependencies(Element dependent, Object? value) { + // This is where the cost of [InheritedElement] is incurred during build + // time of the widget tree. Omitting this bookkeeping is where the + // performance savings come from. + assert(value == null); + } + + @override + Object? getDependencies(Element dependent) { + return null; + } + + @override + void notifyClients(InheritedWidget oldWidget) { + _recurseChildren(this, (Element element) { + if (element.doesDependOnInheritedElement(this)) { + notifyDependent(oldWidget, element); + } + }); + } + + static void _recurseChildren(Element element, ElementVisitor visitor) { + element.visitChildren((Element child) { + _recurseChildren(child, visitor); + }); + visitor(element); + } +} + +/// See also: +/// +/// * [_UbiquitousInheritedElement], the [Element] for [_UbiquitousInheritedWidget]. +abstract class _UbiquitousInheritedWidget extends InheritedWidget { + const _UbiquitousInheritedWidget({super.key, required super.child}); + + @override + InheritedElement createElement() => _UbiquitousInheritedElement(this); +} + +/// A widget that determines the ambient directionality of text and +/// text-direction-sensitive render objects. +/// +/// For example, [Padding] depends on the [Directionality] to resolve +/// [EdgeInsetsDirectional] objects into absolute [EdgeInsets] objects. +class Directionality extends _UbiquitousInheritedWidget { + /// Creates a widget that determines the directionality of text and + /// text-direction-sensitive render objects. + const Directionality({ + super.key, + required this.textDirection, + required super.child, + }); + + /// The text direction for this subtree. + final TextDirection textDirection; + + /// The text direction from the closest instance of this class that encloses + /// the given context. + /// + /// If there is no [Directionality] ancestor widget in the tree at the given + /// context, then this will throw a descriptive [FlutterError] in debug mode + /// and an exception in release mode. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// TextDirection textDirection = Directionality.of(context); + /// ``` + /// + /// See also: + /// + /// * [maybeOf], which will return null if no [Directionality] ancestor + /// widget is in the tree. + static TextDirection of(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + final Directionality widget = context.dependOnInheritedWidgetOfExactType<Directionality>()!; + return widget.textDirection; + } + + /// The text direction from the closest instance of this class that encloses + /// the given context. + /// + /// If there is no [Directionality] ancestor widget in the tree at the given + /// context, then this will return null. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// TextDirection? textDirection = Directionality.maybeOf(context); + /// ``` + /// + /// See also: + /// + /// * [of], which will throw if no [Directionality] ancestor widget is in the + /// tree. + static TextDirection? maybeOf(BuildContext context) { + final Directionality? widget = context.dependOnInheritedWidgetOfExactType<Directionality>(); + return widget?.textDirection; + } + + @override + bool updateShouldNotify(Directionality oldWidget) => textDirection != oldWidget.textDirection; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection)); + } +} + + +// PAINTING NODES + +/// A widget that makes its child partially transparent. +/// +/// This class paints its child into an intermediate buffer and then blends the +/// child back into the scene partially transparent. +/// +/// For values of opacity other than 0.0 and 1.0, this class is relatively +/// expensive because it requires painting the child into an intermediate +/// buffer. For the value 0.0, the child is not painted at all. For the +/// value 1.0, the child is painted immediately without an intermediate buffer. +/// +/// The presence of the intermediate buffer which has a transparent background +/// by default may cause some child widgets to behave differently. For example +/// a [BackdropFilter] child will only be able to apply its filter to the content +/// between this widget and the backdrop child and may require adjusting the +/// [BackdropFilter.blendMode] property to produce the desired results. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=9hltevOHQBw} +/// +/// {@tool snippet} +/// +/// This example shows some [Text] when the `_visible` member field is true, and +/// hides it when it is false: +/// +/// ```dart +/// Opacity( +/// opacity: _visible ? 1.0 : 0.0, +/// child: const Text("Now you see me, now you don't!"), +/// ) +/// ``` +/// {@end-tool} +/// +/// This is more efficient than adding and removing the child widget from the +/// tree on demand. +/// +/// ## Performance considerations for opacity animation +/// +/// Animating an [Opacity] widget directly causes the widget (and possibly its +/// subtree) to rebuild each frame, which is not very efficient. Consider using +/// one of these alternative widgets instead: +/// +/// * [AnimatedOpacity], which uses an animation internally to efficiently +/// animate opacity. +/// * [FadeTransition], which uses a provided animation to efficiently animate +/// opacity. +/// +/// ## Transparent image +/// +/// If only a single [Image] or [Color] needs to be composited with an opacity +/// between 0.0 and 1.0, it's much faster to directly use them without [Opacity] +/// widgets. +/// +/// For example, `Container(color: Color.fromRGBO(255, 0, 0, 0.5))` is much +/// faster than `Opacity(opacity: 0.5, child: Container(color: Colors.red))`. +/// +/// {@tool snippet} +/// +/// The following example draws an [Image] with 0.5 opacity without using +/// [Opacity]: +/// +/// ```dart +/// Image.network( +/// 'https://raw.githubusercontent.com/flutter/assets-for-api-docs/master/packages/diagrams/assets/blend_mode_destination.jpeg', +/// color: const Color.fromRGBO(255, 255, 255, 0.5), +/// colorBlendMode: BlendMode.modulate +/// ) +/// ``` +/// +/// {@end-tool} +/// +/// Directly drawing an [Image] or [Color] with opacity is faster than using +/// [Opacity] on top of them because [Opacity] could apply the opacity to a +/// group of widgets and therefore a costly offscreen buffer will be used. +/// Drawing content into the offscreen buffer may also trigger render target +/// switches and such switching is particularly slow in older GPUs. +/// +/// ## Hit testing +/// +/// Setting the [opacity] to zero does not prevent hit testing from being applied +/// to the descendants of the [Opacity] widget. This can be confusing for the +/// user, who may not see anything, and may believe the area of the interface +/// where the [Opacity] is hiding a widget to be non-interactive. +/// +/// With certain widgets, such as [Flow], that compute their positions only when +/// they are painted, this can actually lead to bugs (from unexpected geometry +/// to exceptions), because those widgets are not painted by the [Opacity] +/// widget at all when the [opacity] is zero. +/// +/// To avoid such problems, it is generally a good idea to use an +/// [IgnorePointer] widget when setting the [opacity] to zero. This prevents +/// interactions with any children in the subtree. +/// +/// See also: +/// +/// * [Visibility], which can hide a child more efficiently (albeit less +/// subtly, because it is either visible or hidden, rather than allowing +/// fractional opacity values). Specifically, the [Visibility.maintain] +/// constructor is equivalent to using an opacity widget with values of +/// `0.0` or `1.0`. +/// * [ShaderMask], which can apply more elaborate effects to its child. +/// * [Transform], which applies an arbitrary transform to its child widget at +/// paint time. +/// * [SliverOpacity], the sliver version of this widget. +class Opacity extends SingleChildRenderObjectWidget { + /// Creates a widget that makes its child partially transparent. + /// + /// The [opacity] argument must be between zero and one, inclusive. + const Opacity({ + super.key, + required this.opacity, + this.alwaysIncludeSemantics = false, + super.child, + }) : assert(opacity >= 0.0 && opacity <= 1.0); + + /// The fraction to scale the child's alpha value. + /// + /// An opacity of one is fully opaque. An opacity of zero is fully transparent + /// (i.e., invisible). + /// + /// Values one and zero are painted with a fast path. Other values require + /// painting the child into an intermediate buffer, which is expensive. + final double opacity; + + /// Whether the semantic information of the children is always included. + /// + /// Defaults to false. + /// + /// When true, regardless of the opacity settings the child semantic + /// information is exposed as if the widget were fully visible. This is + /// useful in cases where labels may be hidden during animations that + /// would otherwise contribute relevant semantics. + final bool alwaysIncludeSemantics; + + @override + RenderOpacity createRenderObject(BuildContext context) { + return RenderOpacity( + opacity: opacity, + alwaysIncludeSemantics: alwaysIncludeSemantics, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderOpacity renderObject) { + renderObject + ..opacity = opacity + ..alwaysIncludeSemantics = alwaysIncludeSemantics; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('opacity', opacity)); + properties.add(FlagProperty('alwaysIncludeSemantics', value: alwaysIncludeSemantics, ifTrue: 'alwaysIncludeSemantics')); + } +} + +/// A widget that applies a mask generated by a [Shader] to its child. +/// +/// For example, [ShaderMask] can be used to gradually fade out the edge +/// of a child by using a [ui.Gradient.linear] mask. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=7sUL66pTQ7Q} +/// +/// {@tool snippet} +/// +/// This example makes the text look like it is on fire: +/// +/// ```dart +/// ShaderMask( +/// shaderCallback: (Rect bounds) { +/// return RadialGradient( +/// center: Alignment.topLeft, +/// radius: 1.0, +/// colors: <Color>[Colors.yellow, Colors.deepOrange.shade900], +/// tileMode: TileMode.mirror, +/// ).createShader(bounds); +/// }, +/// child: const Text( +/// 'I’m burning the memories', +/// style: TextStyle(color: Colors.white), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Opacity], which can apply a uniform alpha effect to its child. +/// * [CustomPaint], which lets you draw directly on the canvas. +/// * [DecoratedBox], for another approach at decorating child widgets. +/// * [BackdropFilter], which applies an image filter to the background. +class ShaderMask extends SingleChildRenderObjectWidget { + /// Creates a widget that applies a mask generated by a [Shader] to its child. + const ShaderMask({ + super.key, + required this.shaderCallback, + this.blendMode = BlendMode.modulate, + super.child, + }); + + /// Called to create the [dart:ui.Shader] that generates the mask. + /// + /// The shader callback is called with the current size of the child so that + /// it can customize the shader to the size and location of the child. + /// + /// Typically this will use a [LinearGradient], [RadialGradient], or + /// [SweepGradient] to create the [dart:ui.Shader], though the + /// [dart:ui.ImageShader] class could also be used. + final ShaderCallback shaderCallback; + + /// The [BlendMode] to use when applying the shader to the child. + /// + /// The default, [BlendMode.modulate], is useful for applying an alpha blend + /// to the child. Other blend modes can be used to create other effects. + final BlendMode blendMode; + + @override + RenderShaderMask createRenderObject(BuildContext context) { + return RenderShaderMask( + shaderCallback: shaderCallback, + blendMode: blendMode, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderShaderMask renderObject) { + renderObject + ..shaderCallback = shaderCallback + ..blendMode = blendMode; + } +} + +/// A widget that applies a filter to the existing painted content and then +/// paints [child]. +/// +/// The filter will be applied to all the area within its parent or ancestor +/// widget's clip. If there's no clip, the filter will be applied to the full +/// screen. +/// +/// The results of the filter will be blended back into the background using +/// the [blendMode] parameter. +/// {@template flutter.widgets.BackdropFilter.blendMode} +/// The only value for [blendMode] that is supported on all platforms is +/// [BlendMode.srcOver] which works well for most scenes. But that value may +/// produce surprising results when a parent of the [BackdropFilter] uses a +/// temporary buffer, or save layer, as does an [Opacity] widget. In that +/// situation, a value of [BlendMode.src] can produce more pleasing results, +/// but at the cost of incompatibility with some platforms, most notably the +/// html renderer for web applications. +/// {@endtemplate} +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=dYRs7Q1vfYI} +/// +/// {@tool snippet} +/// If the [BackdropFilter] needs to be applied to an area that exactly matches +/// its child, wraps the [BackdropFilter] with a clip widget that clips exactly +/// to that child. +/// +/// ```dart +/// Stack( +/// fit: StackFit.expand, +/// children: <Widget>[ +/// Text('0' * 10000), +/// Center( +/// child: ClipRect( // <-- clips to the 200x200 [Container] below +/// child: BackdropFilter( +/// filter: ui.ImageFilter.blur( +/// sigmaX: 5.0, +/// sigmaY: 5.0, +/// ), +/// child: Container( +/// alignment: Alignment.center, +/// width: 200.0, +/// height: 200.0, +/// child: const Text('Hello World'), +/// ), +/// ), +/// ), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// This effect is relatively expensive, especially if the filter is non-local, +/// such as a blur. +/// +/// If all you want to do is apply an [ImageFilter] to a single widget +/// (as opposed to applying the filter to everything _beneath_ a widget), use +/// [ImageFiltered] instead. For that scenario, [ImageFiltered] is both +/// easier to use and less expensive than [BackdropFilter]. +/// +/// {@tool snippet} +/// +/// This example shows how the common case of applying a [BackdropFilter] blur +/// to a single sibling can be replaced with an [ImageFiltered] widget. This code +/// is generally simpler and the performance will be improved dramatically for +/// complex filters like blurs. +/// +/// The implementation below is unnecessarily expensive. +/// +/// ```dart +/// Widget buildBackdrop() { +/// return Stack( +/// children: <Widget>[ +/// Positioned.fill(child: Image.asset('image.png')), +/// Positioned.fill( +/// child: BackdropFilter( +/// filter: ui.ImageFilter.blur(sigmaX: 6, sigmaY: 6), +/// ), +/// ), +/// ], +/// ); +/// } +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// Instead consider the following approach which directly applies a blur +/// to the child widget. +/// +/// ```dart +/// Widget buildFilter() { +/// return ImageFiltered( +/// imageFilter: ui.ImageFilter.blur(sigmaX: 6, sigmaY: 6), +/// child: Image.asset('image.png'), +/// ); +/// } +/// ``` +/// +/// {@end-tool} +/// +/// See also: +/// +/// * [ImageFiltered], which applies an [ImageFilter] to its child. +/// * [DecoratedBox], which draws a background under (or over) a widget. +/// * [Opacity], which changes the opacity of the widget itself. +/// * https://flutter.dev/go/ios-platformview-backdrop-filter-blur for details and restrictions when an iOS PlatformView needs to be blurred. +class BackdropFilter extends SingleChildRenderObjectWidget { + /// Creates a backdrop filter. + /// + /// The [blendMode] argument will default to [BlendMode.srcOver] and must not be + /// null if provided. + const BackdropFilter({ + super.key, + required this.filter, + super.child, + this.blendMode = BlendMode.srcOver, + }); + + /// The image filter to apply to the existing painted content before painting the child. + /// + /// For example, consider using [ImageFilter.blur] to create a backdrop + /// blur effect. + final ui.ImageFilter filter; + + /// The blend mode to use to apply the filtered background content onto the background + /// surface. + /// + /// {@macro flutter.widgets.BackdropFilter.blendMode} + final BlendMode blendMode; + + @override + RenderBackdropFilter createRenderObject(BuildContext context) { + return RenderBackdropFilter(filter: filter, blendMode: blendMode); + } + + @override + void updateRenderObject(BuildContext context, RenderBackdropFilter renderObject) { + renderObject + ..filter = filter + ..blendMode = blendMode; + } +} + +/// A widget that provides a canvas on which to draw during the paint phase. +/// +/// When asked to paint, [CustomPaint] first asks its [painter] to paint on the +/// current canvas, then it paints its child, and then, after painting its +/// child, it asks its [foregroundPainter] to paint. The coordinate system of the +/// canvas matches the coordinate system of the [CustomPaint] object. The +/// painters are expected to paint within a rectangle starting at the origin and +/// encompassing a region of the given size. (If the painters paint outside +/// those bounds, there might be insufficient memory allocated to rasterize the +/// painting commands and the resulting behavior is undefined.) To enforce +/// painting within those bounds, consider wrapping this [CustomPaint] with a +/// [ClipRect] widget. +/// +/// Painters are implemented by subclassing [CustomPainter]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=kp14Y4uHpHs} +/// +/// Because custom paint calls its painters during paint, you cannot call +/// `setState` or `markNeedsLayout` during the callback (the layout for this +/// frame has already happened). +/// +/// Custom painters normally size themselves to their [child]. If they do not +/// have a child, they attempt to size themselves to the specified [size], which +/// defaults to [Size.zero]. The parent [may enforce constraints on this +/// size](https://docs.flutter.dev/ui/layout/constraints). +/// +/// The [isComplex] and [willChange] properties are hints to the compositor's +/// raster cache. +/// +/// {@tool snippet} +/// +/// This example shows how the sample custom painter shown at [CustomPainter] +/// could be used in a [CustomPaint] widget to display a background to some +/// text. +/// +/// ```dart +/// CustomPaint( +/// painter: Sky(), +/// child: const Center( +/// child: Text( +/// 'Once upon a time...', +/// style: TextStyle( +/// fontSize: 40.0, +/// fontWeight: FontWeight.w900, +/// color: Color(0xFFFFFFFF), +/// ), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [CustomPainter], the class to extend when creating custom painters. +/// * [Canvas], the class that a custom painter uses to paint. +class CustomPaint extends SingleChildRenderObjectWidget { + /// Creates a widget that delegates its painting. + const CustomPaint({ + super.key, + this.painter, + this.foregroundPainter, + this.size = Size.zero, + this.isComplex = false, + this.willChange = false, + super.child, + }) : assert(painter != null || foregroundPainter != null || (!isComplex && !willChange)); + + /// The painter that paints before the children. + final CustomPainter? painter; + + /// The painter that paints after the children. + final CustomPainter? foregroundPainter; + + /// The size that this [CustomPaint] should aim for, given the layout + /// constraints, if there is no child. + /// + /// Defaults to [Size.zero]. + /// + /// If there's a child, this is ignored, and the size of the child is used + /// instead. + final Size size; + + /// Whether the painting is complex enough to benefit from caching. + /// + /// The compositor contains a raster cache that holds bitmaps of layers in + /// order to avoid the cost of repeatedly rendering those layers on each + /// frame. If this flag is not set, then the compositor will apply its own + /// heuristics to decide whether the layer containing this widget is complex + /// enough to benefit from caching. + /// + /// This flag can't be set to true if both [painter] and [foregroundPainter] + /// are null because this flag will be ignored in such case. + final bool isComplex; + + /// Whether the raster cache should be told that this painting is likely + /// to change in the next frame. + /// + /// This hint tells the compositor not to cache the layer containing this + /// widget because the cache will not be used in the future. If this hint is + /// not set, the compositor will apply its own heuristics to decide whether + /// the layer is likely to be reused in the future. + /// + /// This flag can't be set to true if both [painter] and [foregroundPainter] + /// are null because this flag will be ignored in such case. + final bool willChange; + + @override + RenderCustomPaint createRenderObject(BuildContext context) { + return RenderCustomPaint( + painter: painter, + foregroundPainter: foregroundPainter, + preferredSize: size, + isComplex: isComplex, + willChange: willChange, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderCustomPaint renderObject) { + renderObject + ..painter = painter + ..foregroundPainter = foregroundPainter + ..preferredSize = size + ..isComplex = isComplex + ..willChange = willChange; + } + + @override + void didUnmountRenderObject(RenderCustomPaint renderObject) { + renderObject + ..painter = null + ..foregroundPainter = null; + } +} + +/// A widget that clips its child using a rectangle. +/// +/// By default, [ClipRect] prevents its child from painting outside its +/// bounds, but the size and location of the clip rect can be customized using a +/// custom [clipper]. +/// +/// [ClipRect] is commonly used with these widgets, which commonly paint outside +/// their bounds: +/// +/// * [CustomPaint] +/// * [CustomSingleChildLayout] +/// * [CustomMultiChildLayout] +/// * [Align] and [Center] (e.g., if [Align.widthFactor] or +/// [Align.heightFactor] is less than 1.0). +/// * [OverflowBox] +/// * [SizedOverflowBox] +/// +/// {@tool snippet} +/// +/// For example, by combining a [ClipRect] with an [Align], one can show just +/// the top half of an [Image]: +/// +/// ```dart +/// ClipRect( +/// child: Align( +/// alignment: Alignment.topCenter, +/// heightFactor: 0.5, +/// child: Image.network(userAvatarUrl), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [CustomClipper], for information about creating custom clips. +/// * [ClipRRect], for a clip with rounded corners. +/// * [ClipOval], for an elliptical clip. +/// * [ClipPath], for an arbitrarily shaped clip. +class ClipRect extends SingleChildRenderObjectWidget { + /// Creates a rectangular clip. + /// + /// If [clipper] is null, the clip will match the layout size and position of + /// the child. + /// + /// If [clipBehavior] is [Clip.none], no clipping will be applied. + const ClipRect({ + super.key, + this.clipper, + this.clipBehavior = Clip.hardEdge, + super.child, + }); + + /// If non-null, determines which clip to use. + final CustomClipper<Rect>? clipper; + + /// {@macro flutter.rendering.ClipRectLayer.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + @override + RenderClipRect createRenderObject(BuildContext context) { + return RenderClipRect(clipper: clipper, clipBehavior: clipBehavior); + } + + @override + void updateRenderObject(BuildContext context, RenderClipRect renderObject) { + renderObject + ..clipper = clipper + ..clipBehavior = clipBehavior; + } + + @override + void didUnmountRenderObject(RenderClipRect renderObject) { + renderObject.clipper = null; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<CustomClipper<Rect>>('clipper', clipper, defaultValue: null)); + } +} + +/// A widget that clips its child using a rounded rectangle. +/// +/// By default, [ClipRRect] uses its own bounds as the base rectangle for the +/// clip, but the size and location of the clip can be customized using a custom +/// [clipper]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=eI43jkQkrvs} +/// +/// {@tool dartpad} +/// This example shows various [ClipRRect]s applied to containers. +/// +/// ** See code in examples/api/lib/widgets/basic/clip_rrect.0.dart ** +/// {@end-tool} +/// +/// ## Troubleshooting +/// +/// ### Why doesn't my [ClipRRect] child have rounded corners? +/// +/// When a [ClipRRect] is bigger than the child it contains, its rounded corners +/// could be drawn in unexpected positions. Make sure that [ClipRRect] and its child +/// have the same bounds (by shrinking the [ClipRRect] with a [FittedBox] or by +/// growing the child). +/// +/// {@tool dartpad} +/// This example shows a [ClipRRect] that adds round corners to an image. +/// +/// ** See code in examples/api/lib/widgets/basic/clip_rrect.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CustomClipper], for information about creating custom clips. +/// * [ClipRect], for more efficient clips without rounded corners. +/// * [ClipOval], for an elliptical clip. +/// * [ClipPath], for an arbitrarily shaped clip. +class ClipRRect extends SingleChildRenderObjectWidget { + /// Creates a rounded-rectangular clip. + /// + /// The [borderRadius] defaults to [BorderRadius.zero], i.e. a rectangle with + /// right-angled corners. + /// + /// If [clipper] is non-null, then [borderRadius] is ignored. + /// + /// If [clipBehavior] is [Clip.none], no clipping will be applied. + const ClipRRect({ + super.key, + this.borderRadius = BorderRadius.zero, + this.clipper, + this.clipBehavior = Clip.antiAlias, + super.child, + }); + + /// The border radius of the rounded corners. + /// + /// Values are clamped so that horizontal and vertical radii sums do not + /// exceed width/height. + /// + /// This value is ignored if [clipper] is non-null. + final BorderRadiusGeometry borderRadius; + + /// If non-null, determines which clip to use. + final CustomClipper<RRect>? clipper; + + /// {@macro flutter.rendering.ClipRectLayer.clipBehavior} + /// + /// Defaults to [Clip.antiAlias]. + final Clip clipBehavior; + + @override + RenderClipRRect createRenderObject(BuildContext context) { + return RenderClipRRect( + borderRadius: borderRadius, + clipper: clipper, + clipBehavior: clipBehavior, + textDirection: Directionality.maybeOf(context), + ); + } + + @override + void updateRenderObject(BuildContext context, RenderClipRRect renderObject) { + renderObject + ..borderRadius = borderRadius + ..clipBehavior = clipBehavior + ..clipper = clipper + ..textDirection = Directionality.maybeOf(context); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<BorderRadiusGeometry>('borderRadius', borderRadius, showName: false, defaultValue: null)); + properties.add(DiagnosticsProperty<CustomClipper<RRect>>('clipper', clipper, defaultValue: null)); + } +} + +/// A widget that clips its child using an oval. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=vzWWDO6whIM} +/// +/// By default, inscribes an axis-aligned oval into its layout dimensions and +/// prevents its child from painting outside that oval, but the size and +/// location of the clip oval can be customized using a custom [clipper]. +/// +/// See also: +/// +/// * [CustomClipper], for information about creating custom clips. +/// * [ClipRect], for more efficient clips without rounded corners. +/// * [ClipRRect], for a clip with rounded corners. +/// * [ClipPath], for an arbitrarily shaped clip. +class ClipOval extends SingleChildRenderObjectWidget { + /// Creates an oval-shaped clip. + /// + /// If [clipper] is null, the oval will be inscribed into the layout size and + /// position of the child. + /// + /// If [clipBehavior] is [Clip.none], no clipping will be applied. + const ClipOval({ + super.key, + this.clipper, + this.clipBehavior = Clip.antiAlias, + super.child, + }); + + /// If non-null, determines which clip to use. + /// + /// The delegate returns a rectangle that describes the axis-aligned + /// bounding box of the oval. The oval's axes will themselves also + /// be axis-aligned. + /// + /// If the [clipper] delegate is null, then the oval uses the + /// widget's bounding box (the layout dimensions of the render + /// object) instead. + final CustomClipper<Rect>? clipper; + + /// {@macro flutter.rendering.ClipRectLayer.clipBehavior} + /// + /// Defaults to [Clip.antiAlias]. + final Clip clipBehavior; + + @override + RenderClipOval createRenderObject(BuildContext context) { + return RenderClipOval(clipper: clipper, clipBehavior: clipBehavior); + } + + @override + void updateRenderObject(BuildContext context, RenderClipOval renderObject) { + renderObject + ..clipper = clipper + ..clipBehavior = clipBehavior; + } + + @override + void didUnmountRenderObject(RenderClipOval renderObject) { + renderObject.clipper = null; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<CustomClipper<Rect>>('clipper', clipper, defaultValue: null)); + } +} + +/// A widget that clips its child using a path. +/// +/// Calls a callback on a delegate whenever the widget is to be +/// painted. The callback returns a path and the widget prevents the +/// child from painting outside the path. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=oAUebVIb-7s} +/// +/// Clipping to a path is expensive. Certain shapes have more +/// optimized widgets: +/// +/// * To clip to a rectangle, consider [ClipRect]. +/// * To clip to an oval or circle, consider [ClipOval]. +/// * To clip to a rounded rectangle, consider [ClipRRect]. +/// +/// To clip to a particular [ShapeBorder], consider using either the +/// [ClipPath.shape] static method or the [ShapeBorderClipper] custom clipper +/// class. +class ClipPath extends SingleChildRenderObjectWidget { + /// Creates a path clip. + /// + /// If [clipper] is null, the clip will be a rectangle that matches the layout + /// size and location of the child. However, rather than use this default, + /// consider using a [ClipRect], which can achieve the same effect more + /// efficiently. + /// + /// If [clipBehavior] is [Clip.none], no clipping will be applied. + const ClipPath({ + super.key, + this.clipper, + this.clipBehavior = Clip.antiAlias, + super.child, + }); + + /// Creates a shape clip. + /// + /// Uses a [ShapeBorderClipper] to configure the [ClipPath] to clip to the + /// given [ShapeBorder]. + static Widget shape({ + Key? key, + required ShapeBorder shape, + Clip clipBehavior = Clip.antiAlias, + Widget? child, + }) { + return Builder( + key: key, + builder: (BuildContext context) { + return ClipPath( + clipper: ShapeBorderClipper( + shape: shape, + textDirection: Directionality.maybeOf(context), + ), + clipBehavior: clipBehavior, + child: child, + ); + }, + ); + } + + /// If non-null, determines which clip to use. + /// + /// The default clip, which is used if this property is null, is the + /// bounding box rectangle of the widget. [ClipRect] is a more + /// efficient way of obtaining that effect. + final CustomClipper<Path>? clipper; + + /// {@macro flutter.rendering.ClipRectLayer.clipBehavior} + /// + /// Defaults to [Clip.antiAlias]. + final Clip clipBehavior; + + @override + RenderClipPath createRenderObject(BuildContext context) { + return RenderClipPath(clipper: clipper, clipBehavior: clipBehavior); + } + + @override + void updateRenderObject(BuildContext context, RenderClipPath renderObject) { + renderObject + ..clipper = clipper + ..clipBehavior = clipBehavior; + } + + @override + void didUnmountRenderObject(RenderClipPath renderObject) { + renderObject.clipper = null; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<CustomClipper<Path>>('clipper', clipper, defaultValue: null)); + } +} + +/// A widget representing a physical layer that clips its children to a shape. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=XgUOSS30OQk} +/// +/// Physical layers cast shadows based on an [elevation] which is nominally in +/// logical pixels, coming vertically out of the rendering surface. +/// +/// For shapes that cannot be expressed as a rectangle with rounded corners use +/// [PhysicalShape]. +/// +/// See also: +/// +/// * [AnimatedPhysicalModel], which animates property changes smoothly over +/// a given duration. +/// * [DecoratedBox], which can apply more arbitrary shadow effects. +/// * [ClipRect], which applies a clip to its child. +class PhysicalModel extends SingleChildRenderObjectWidget { + /// Creates a physical model with a rounded-rectangular clip. + /// + /// The [color] is required; physical things have a color. + /// + /// The [shape], [elevation], [color], [clipBehavior], and [shadowColor] must + /// not be null. Additionally, the [elevation] must be non-negative. + const PhysicalModel({ + super.key, + this.shape = BoxShape.rectangle, + this.clipBehavior = Clip.none, + this.borderRadius, + this.elevation = 0.0, + required this.color, + this.shadowColor = const Color(0xFF000000), + super.child, + }) : assert(elevation >= 0.0); + + /// The type of shape. + final BoxShape shape; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// The border radius of the rounded corners. + /// + /// Values are clamped so that horizontal and vertical radii sums do not + /// exceed width/height. + /// + /// This is ignored if the [shape] is not [BoxShape.rectangle]. + final BorderRadius? borderRadius; + + /// The z-coordinate relative to the parent at which to place this physical + /// object. + /// + /// The value is non-negative. + final double elevation; + + /// The background color. + final Color color; + + /// The shadow color. + final Color shadowColor; + + @override + RenderPhysicalModel createRenderObject(BuildContext context) { + return RenderPhysicalModel( + shape: shape, + clipBehavior: clipBehavior, + borderRadius: borderRadius, + elevation: elevation, + color: color, + shadowColor: shadowColor, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderPhysicalModel renderObject) { + renderObject + ..shape = shape + ..clipBehavior = clipBehavior + ..borderRadius = borderRadius + ..elevation = elevation + ..color = color + ..shadowColor = shadowColor; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<BoxShape>('shape', shape)); + properties.add(DiagnosticsProperty<BorderRadius>('borderRadius', borderRadius)); + properties.add(DoubleProperty('elevation', elevation)); + properties.add(ColorProperty('color', color)); + properties.add(ColorProperty('shadowColor', shadowColor)); + } +} + +/// A widget representing a physical layer that clips its children to a path. +/// +/// Physical layers cast shadows based on an [elevation] which is nominally in +/// logical pixels, coming vertically out of the rendering surface. +/// +/// [PhysicalModel] does the same but only supports shapes that can be expressed +/// as rectangles with rounded corners. +/// +/// {@tool dartpad} +/// This example shows how to use a [PhysicalShape] on a centered [SizedBox] +/// to clip it to a rounded rectangle using a [ShapeBorderClipper] and give it +/// an orange color along with a shadow. +/// +/// ** See code in examples/api/lib/widgets/basic/physical_shape.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ShapeBorderClipper], which converts a [ShapeBorder] to a [CustomClipper], as +/// needed by this widget. +class PhysicalShape extends SingleChildRenderObjectWidget { + /// Creates a physical model with an arbitrary shape clip. + /// + /// The [color] is required; physical things have a color. + /// + /// The [elevation] must be non-negative. + const PhysicalShape({ + super.key, + required this.clipper, + this.clipBehavior = Clip.none, + this.elevation = 0.0, + required this.color, + this.shadowColor = const Color(0xFF000000), + super.child, + }) : assert(elevation >= 0.0); + + /// Determines which clip to use. + /// + /// If the path in question is expressed as a [ShapeBorder] subclass, + /// consider using the [ShapeBorderClipper] delegate class to adapt the + /// shape for use with this widget. + final CustomClipper<Path> clipper; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// The z-coordinate relative to the parent at which to place this physical + /// object. + /// + /// The value is non-negative. + final double elevation; + + /// The background color. + final Color color; + + /// When elevation is non zero the color to use for the shadow color. + final Color shadowColor; + + @override + RenderPhysicalShape createRenderObject(BuildContext context) { + return RenderPhysicalShape( + clipper: clipper, + clipBehavior: clipBehavior, + elevation: elevation, + color: color, + shadowColor: shadowColor, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderPhysicalShape renderObject) { + renderObject + ..clipper = clipper + ..clipBehavior = clipBehavior + ..elevation = elevation + ..color = color + ..shadowColor = shadowColor; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<CustomClipper<Path>>('clipper', clipper)); + properties.add(DoubleProperty('elevation', elevation)); + properties.add(ColorProperty('color', color)); + properties.add(ColorProperty('shadowColor', shadowColor)); + } +} + + +// POSITIONING AND SIZING NODES + +/// A widget that applies a transformation before painting its child. +/// +/// Unlike [RotatedBox], which applies a rotation prior to layout, this object +/// applies its transformation just prior to painting, which means the +/// transformation is not taken into account when calculating how much space +/// this widget's child (and thus this widget) consumes. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=9z_YNlRlWfA} +/// +/// {@tool snippet} +/// +/// This example rotates and skews an orange box containing text, keeping the +/// top right corner pinned to its original position. +/// +/// ```dart +/// ColoredBox( +/// color: Colors.black, +/// child: Transform( +/// alignment: Alignment.topRight, +/// transform: Matrix4.skewY(0.3)..rotateZ(-math.pi / 12.0), +/// child: Container( +/// padding: const EdgeInsets.all(8.0), +/// color: const Color(0xFFE8581C), +/// child: const Text('Apartment for rent!'), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [RotatedBox], which rotates the child widget during layout, not just +/// during painting. +/// * [FractionalTranslation], which applies a translation to the child +/// that is relative to the child's size. +/// * [FittedBox], which sizes and positions its child widget to fit the parent +/// according to a given [BoxFit] discipline. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Transform extends SingleChildRenderObjectWidget { + /// Creates a widget that transforms its child. + const Transform({ + super.key, + required this.transform, + this.origin, + this.alignment, + this.transformHitTests = true, + this.filterQuality, + super.child, + }); + + /// Creates a widget that transforms its child using a rotation around the + /// center. + /// + /// The `angle` argument gives the rotation in clockwise radians. + /// + /// {@tool snippet} + /// + /// This example rotates an orange box containing text around its center by + /// fifteen degrees. + /// + /// ```dart + /// Transform.rotate( + /// angle: -math.pi / 12.0, + /// child: Container( + /// padding: const EdgeInsets.all(8.0), + /// color: const Color(0xFFE8581C), + /// child: const Text('Apartment for rent!'), + /// ), + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [RotationTransition], which animates changes in rotation smoothly + /// over a given duration. + Transform.rotate({ + super.key, + required double angle, + this.origin, + this.alignment = Alignment.center, + this.transformHitTests = true, + this.filterQuality, + super.child, + }) : transform = _computeRotation(angle); + + /// Creates a widget that transforms its child using a translation. + /// + /// The `offset` argument specifies the translation. + /// + /// {@tool snippet} + /// + /// This example shifts the silver-colored child down by fifteen pixels. + /// + /// ```dart + /// Transform.translate( + /// offset: const Offset(0.0, 15.0), + /// child: Container( + /// padding: const EdgeInsets.all(8.0), + /// color: const Color(0xFF7F7F7F), + /// child: const Text('Quarter'), + /// ), + /// ) + /// ``` + /// {@end-tool} + Transform.translate({ + super.key, + required Offset offset, + this.transformHitTests = true, + this.filterQuality, + super.child, + }) : transform = Matrix4.translationValues(offset.dx, offset.dy, 0.0), + origin = null, + alignment = null; + + /// Creates a widget that scales its child along the 2D plane. + /// + /// The `scaleX` argument provides the scalar by which to multiply the `x` + /// axis, and the `scaleY` argument provides the scalar by which to multiply + /// the `y` axis. Either may be omitted, in which case the scaling factor for + /// that axis defaults to 1.0. + /// + /// For convenience, to scale the child uniformly, instead of providing + /// `scaleX` and `scaleY`, the `scale` parameter may be used. + /// + /// At least one of `scale`, `scaleX`, and `scaleY` must be non-null. If + /// `scale` is provided, the other two must be null; similarly, if it is not + /// provided, one of the other two must be provided. + /// + /// The [alignment] controls the origin of the scale; by default, this is the + /// center of the box. + /// + /// {@tool snippet} + /// + /// This example shrinks an orange box containing text such that each + /// dimension is half the size it would otherwise be. + /// + /// ```dart + /// Transform.scale( + /// scale: 0.5, + /// child: Container( + /// padding: const EdgeInsets.all(8.0), + /// color: const Color(0xFFE8581C), + /// child: const Text('Bad Idea Bears'), + /// ), + /// ) + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [ScaleTransition], which animates changes in scale smoothly over a given + /// duration. + Transform.scale({ + super.key, + double? scale, + double? scaleX, + double? scaleY, + this.origin, + this.alignment = Alignment.center, + this.transformHitTests = true, + this.filterQuality, + super.child, + }) : assert(!(scale == null && scaleX == null && scaleY == null), "At least one of 'scale', 'scaleX' and 'scaleY' is required to be non-null"), + assert(scale == null || (scaleX == null && scaleY == null), "If 'scale' is non-null then 'scaleX' and 'scaleY' must be left null"), + transform = Matrix4.diagonal3Values(scale ?? scaleX ?? 1.0, scale ?? scaleY ?? 1.0, 1.0); + + /// Creates a widget that mirrors its child about the widget's center point. + /// + /// If `flipX` is true, the child widget will be flipped horizontally. Defaults to false. + /// + /// If `flipY` is true, the child widget will be flipped vertically. Defaults to false. + /// + /// If both are true, the child widget will be flipped both vertically and horizontally, equivalent to a 180 degree rotation. + /// + /// {@tool snippet} + /// + /// This example flips the text horizontally. + /// + /// ```dart + /// Transform.flip( + /// flipX: true, + /// child: const Text('Horizontal Flip'), + /// ) + /// ``` + /// {@end-tool} + Transform.flip({ + super.key, + bool flipX = false, + bool flipY = false, + this.origin, + this.transformHitTests = true, + this.filterQuality, + super.child, + }) : alignment = Alignment.center, + transform = Matrix4.diagonal3Values(flipX ? -1.0 : 1.0, flipY ? -1.0 : 1.0, 1.0); + + // Computes a rotation matrix for an angle in radians, attempting to keep rotations + // at integral values for angles of 0, π/2, π, 3π/2. + static Matrix4 _computeRotation(double radians) { + assert(radians.isFinite, 'Cannot compute the rotation matrix for a non-finite angle: $radians'); + if (radians == 0.0) { + return Matrix4.identity(); + } + final double sin = math.sin(radians); + if (sin == 1.0) { + return _createZRotation(1.0, 0.0); + } + if (sin == -1.0) { + return _createZRotation(-1.0, 0.0); + } + final double cos = math.cos(radians); + if (cos == -1.0) { + return _createZRotation(0.0, -1.0); + } + return _createZRotation(sin, cos); + } + + static Matrix4 _createZRotation(double sin, double cos) { + final Matrix4 result = Matrix4.zero(); + result.storage[0] = cos; + result.storage[1] = sin; + result.storage[4] = -sin; + result.storage[5] = cos; + result.storage[10] = 1.0; + result.storage[15] = 1.0; + return result; + } + + /// The matrix to transform the child by during painting. + final Matrix4 transform; + + /// The origin of the coordinate system (relative to the upper left corner of + /// this render object) in which to apply the matrix. + /// + /// Setting an origin is equivalent to conjugating the transform matrix by a + /// translation. This property is provided just for convenience. + final Offset? origin; + + /// The alignment of the origin, relative to the size of the box. + /// + /// This is equivalent to setting an origin based on the size of the box. + /// If it is specified at the same time as the [origin], both are applied. + /// + /// An [AlignmentDirectional.centerStart] value is the same as an [Alignment] + /// whose [Alignment.x] value is `-1.0` if [Directionality.of] returns + /// [TextDirection.ltr], and `1.0` if [Directionality.of] returns + /// [TextDirection.rtl]. Similarly [AlignmentDirectional.centerEnd] is the + /// same as an [Alignment] whose [Alignment.x] value is `1.0` if + /// [Directionality.of] returns [TextDirection.ltr], and `-1.0` if + /// [Directionality.of] returns [TextDirection.rtl]. + final AlignmentGeometry? alignment; + + /// Whether to apply the transformation when performing hit tests. + final bool transformHitTests; + + /// The filter quality with which to apply the transform as a bitmap operation. + /// + /// {@template flutter.widgets.Transform.optional.FilterQuality} + /// The transform will be applied by re-rendering the child if [filterQuality] is null, + /// otherwise it controls the quality of an [ImageFilter.matrix] applied to a bitmap + /// rendering of the child. + /// {@endtemplate} + final FilterQuality? filterQuality; + + @override + RenderTransform createRenderObject(BuildContext context) { + return RenderTransform( + transform: transform, + origin: origin, + alignment: alignment, + textDirection: Directionality.maybeOf(context), + transformHitTests: transformHitTests, + filterQuality: filterQuality, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderTransform renderObject) { + renderObject + ..transform = transform + ..origin = origin + ..alignment = alignment + ..textDirection = Directionality.maybeOf(context) + ..transformHitTests = transformHitTests + ..filterQuality = filterQuality; + } +} + +/// A widget that can be targeted by a [CompositedTransformFollower]. +/// +/// When this widget is composited during the compositing phase (which comes +/// after the paint phase, as described in [WidgetsBinding.drawFrame]), it +/// updates the [link] object so that any [CompositedTransformFollower] widgets +/// that are subsequently composited in the same frame and were given the same +/// [LayerLink] can position themselves at the same screen location. +/// +/// A single [CompositedTransformTarget] can be followed by multiple +/// [CompositedTransformFollower] widgets. +/// +/// The [CompositedTransformTarget] must come earlier in the paint order than +/// any linked [CompositedTransformFollower]s. +/// +/// See also: +/// +/// * [CompositedTransformFollower], the widget that can target this one. +/// * [LeaderLayer], the layer that implements this widget's logic. +class CompositedTransformTarget extends SingleChildRenderObjectWidget { + /// Creates a composited transform target widget. + /// + /// The [link] property must not be currently used by any other + /// [CompositedTransformTarget] object that is in the tree. + const CompositedTransformTarget({ + super.key, + required this.link, + super.child, + }); + + /// The link object that connects this [CompositedTransformTarget] with one or + /// more [CompositedTransformFollower]s. + /// + /// The link must not be associated with another [CompositedTransformTarget] + /// that is also being painted. + final LayerLink link; + + @override + RenderLeaderLayer createRenderObject(BuildContext context) { + return RenderLeaderLayer( + link: link, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderLeaderLayer renderObject) { + renderObject.link = link; + } +} + +/// A widget that follows a [CompositedTransformTarget]. +/// +/// When this widget is composited during the compositing phase (which comes +/// after the paint phase, as described in [WidgetsBinding.drawFrame]), it +/// applies a transformation that brings [targetAnchor] of the linked +/// [CompositedTransformTarget] and [followerAnchor] of this widget together. +/// The two anchor points will have the same global coordinates, unless [offset] +/// is not [Offset.zero], in which case [followerAnchor] will be offset by +/// [offset] in the linked [CompositedTransformTarget]'s coordinate space. +/// +/// The [LayerLink] object used as the [link] must be the same object as that +/// provided to the matching [CompositedTransformTarget]. +/// +/// The [CompositedTransformTarget] must come earlier in the paint order than +/// this [CompositedTransformFollower]. +/// +/// Hit testing on descendants of this widget will only work if the target +/// position is within the box that this widget's parent considers to be +/// hittable. If the parent covers the screen, this is trivially achievable, so +/// this widget is usually used as the root of an [OverlayEntry] in an app-wide +/// [Overlay] (e.g. as created by the [MaterialApp] widget's [Navigator]). +/// +/// See also: +/// +/// * [CompositedTransformTarget], the widget that this widget can target. +/// * [FollowerLayer], the layer that implements this widget's logic. +/// * [Transform], which applies an arbitrary transform to a child. +class CompositedTransformFollower extends SingleChildRenderObjectWidget { + /// Creates a composited transform target widget. + /// + /// If the [link] property was also provided to a [CompositedTransformTarget], + /// that widget must come earlier in the paint order. + /// + /// The [showWhenUnlinked] and [offset] properties must also not be null. + const CompositedTransformFollower({ + super.key, + required this.link, + this.showWhenUnlinked = true, + this.offset = Offset.zero, + this.targetAnchor = Alignment.topLeft, + this.followerAnchor = Alignment.topLeft, + super.child, + }); + + /// The link object that connects this [CompositedTransformFollower] with a + /// [CompositedTransformTarget]. + final LayerLink link; + + /// Whether to show the widget's contents when there is no corresponding + /// [CompositedTransformTarget] with the same [link]. + /// + /// When the widget is linked, the child is positioned such that it has the + /// same global position as the linked [CompositedTransformTarget]. + /// + /// When the widget is not linked, then: if [showWhenUnlinked] is true, the + /// child is visible and not repositioned; if it is false, then child is + /// hidden. + final bool showWhenUnlinked; + + /// The anchor point on the linked [CompositedTransformTarget] that + /// [followerAnchor] will line up with. + /// + /// {@template flutter.widgets.CompositedTransformFollower.targetAnchor} + /// For example, when [targetAnchor] and [followerAnchor] are both + /// [Alignment.topLeft], this widget will be top left aligned with the linked + /// [CompositedTransformTarget]. When [targetAnchor] is + /// [Alignment.bottomLeft] and [followerAnchor] is [Alignment.topLeft], this + /// widget will be left aligned with the linked [CompositedTransformTarget], + /// and its top edge will line up with the [CompositedTransformTarget]'s + /// bottom edge. + /// {@endtemplate} + /// + /// Defaults to [Alignment.topLeft]. + final Alignment targetAnchor; + + /// The anchor point on this widget that will line up with [targetAnchor] on + /// the linked [CompositedTransformTarget]. + /// + /// {@macro flutter.widgets.CompositedTransformFollower.targetAnchor} + /// + /// Defaults to [Alignment.topLeft]. + final Alignment followerAnchor; + + /// The additional offset to apply to the [targetAnchor] of the linked + /// [CompositedTransformTarget] to obtain this widget's [followerAnchor] + /// position. + final Offset offset; + + @override + RenderFollowerLayer createRenderObject(BuildContext context) { + return RenderFollowerLayer( + link: link, + showWhenUnlinked: showWhenUnlinked, + offset: offset, + leaderAnchor: targetAnchor, + followerAnchor: followerAnchor, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderFollowerLayer renderObject) { + renderObject + ..link = link + ..showWhenUnlinked = showWhenUnlinked + ..offset = offset + ..leaderAnchor = targetAnchor + ..followerAnchor = followerAnchor; + } +} + +/// Scales and positions its child within itself according to [fit]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=T4Uehk3_wlY} +/// +/// {@tool dartpad} +/// In this example, the [Placeholder] is stretched to fill the entire +/// [Container]. Try changing the fit types to see the effect on the layout of +/// the [Placeholder]. +/// +/// ** See code in examples/api/lib/widgets/basic/fitted_box.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Transform], which applies an arbitrary transform to its child widget at +/// paint time. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class FittedBox extends SingleChildRenderObjectWidget { + /// Creates a widget that scales and positions its child within itself according to [fit]. + const FittedBox({ + super.key, + this.fit = BoxFit.contain, + this.alignment = Alignment.center, + this.clipBehavior = Clip.none, + super.child, + }); + + /// How to inscribe the child into the space allocated during layout. + final BoxFit fit; + + /// How to align the child within its parent's bounds. + /// + /// An alignment of (-1.0, -1.0) aligns the child to the top-left corner of its + /// parent's bounds. An alignment of (1.0, 0.0) aligns the child to the middle + /// of the right edge of its parent's bounds. + /// + /// Defaults to [Alignment.center]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + @override + RenderFittedBox createRenderObject(BuildContext context) { + return RenderFittedBox( + fit: fit, + alignment: alignment, + textDirection: Directionality.maybeOf(context), + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderFittedBox renderObject) { + renderObject + ..fit = fit + ..alignment = alignment + ..textDirection = Directionality.maybeOf(context) + ..clipBehavior = clipBehavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<BoxFit>('fit', fit)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + } +} + +/// Applies a translation transformation before painting its child. +/// +/// The translation is expressed as a [Offset] scaled to the child's size. For +/// example, an [Offset] with a `dx` of 0.25 will result in a horizontal +/// translation of one quarter the width of the child. +/// +/// Hit tests will only be detected inside the bounds of the +/// [FractionalTranslation], even if the contents are offset such that +/// they overflow. +/// +/// See also: +/// +/// * [Transform], which applies an arbitrary transform to its child widget at +/// paint time. +/// * [Transform.translate], which applies an absolute offset translation +/// transformation instead of an offset scaled to the child. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class FractionalTranslation extends SingleChildRenderObjectWidget { + /// Creates a widget that translates its child's painting. + const FractionalTranslation({ + super.key, + required this.translation, + this.transformHitTests = true, + super.child, + }); + + /// The translation to apply to the child, scaled to the child's size. + /// + /// For example, an [Offset] with a `dx` of 0.25 will result in a horizontal + /// translation of one quarter the width of the child. + final Offset translation; + + /// Whether to apply the translation when performing hit tests. + final bool transformHitTests; + + @override + RenderFractionalTranslation createRenderObject(BuildContext context) { + return RenderFractionalTranslation( + translation: translation, + transformHitTests: transformHitTests, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderFractionalTranslation renderObject) { + renderObject + ..translation = translation + ..transformHitTests = transformHitTests; + } +} + +/// A widget that rotates its child by a integral number of quarter turns. +/// +/// Unlike [Transform], which applies a transform just prior to painting, +/// this object applies its rotation prior to layout, which means the entire +/// rotated box consumes only as much space as required by the rotated child. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=BFE6_UglLfQ} +/// +/// {@tool snippet} +/// +/// This snippet rotates the child (some [Text]) so that it renders from bottom +/// to top, like an axis label on a graph: +/// +/// ```dart +/// const RotatedBox( +/// quarterTurns: 3, +/// child: Text('Hello World!'), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Transform], which is a paint effect that allows you to apply an +/// arbitrary transform to a child. +/// * [Transform.rotate], which applies a rotation paint effect. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class RotatedBox extends SingleChildRenderObjectWidget { + /// A widget that rotates its child. + const RotatedBox({ + super.key, + required this.quarterTurns, + super.child, + }); + + /// The number of clockwise quarter turns the child should be rotated. + final int quarterTurns; + + @override + RenderRotatedBox createRenderObject(BuildContext context) => RenderRotatedBox(quarterTurns: quarterTurns); + + @override + void updateRenderObject(BuildContext context, RenderRotatedBox renderObject) { + renderObject.quarterTurns = quarterTurns; + } +} + +/// A widget that insets its child by the given padding. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=oD5RtLhhubg} +/// +/// When passing layout constraints to its child, padding shrinks the +/// constraints by the given padding, causing the child to layout at a smaller +/// size. Padding then sizes itself to its child's size, inflated by the +/// padding, effectively creating empty space around the child. +/// +/// {@tool snippet} +/// +/// This snippet creates "Hello World!" [Text] inside a [Card] that is indented +/// by sixteen pixels in each direction. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/padding.png) +/// +/// ```dart +/// const Card( +/// child: Padding( +/// padding: EdgeInsets.all(16.0), +/// child: Text('Hello World!'), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Design discussion +/// +/// ### Why use a [Padding] widget rather than a [Container] with a [Container.padding] property? +/// +/// There isn't really any difference between the two. If you supply a +/// [Container.padding] argument, [Container] builds a [Padding] widget +/// for you. +/// +/// [Container] doesn't implement its properties directly. Instead, [Container] +/// combines a number of simpler widgets together into a convenient package. For +/// example, the [Container.padding] property causes the container to build a +/// [Padding] widget and the [Container.decoration] property causes the +/// container to build a [DecoratedBox] widget. If you find [Container] +/// convenient, feel free to use it. If not, feel free to build these simpler +/// widgets in whatever combination meets your needs. +/// +/// In fact, the majority of widgets in Flutter are combinations of other +/// simpler widgets. Composition, rather than inheritance, is the primary +/// mechanism for building up widgets. +/// +/// See also: +/// +/// * [EdgeInsets], the class that is used to describe the padding dimensions. +/// * [AnimatedPadding], which animates changes in [padding] over a given +/// duration. +/// * [SliverPadding], the sliver equivalent of this widget. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Padding extends SingleChildRenderObjectWidget { + /// Creates a widget that insets its child. + const Padding({ + super.key, + required this.padding, + super.child, + }); + + /// The amount of space by which to inset the child. + final EdgeInsetsGeometry padding; + + @override + RenderPadding createRenderObject(BuildContext context) { + return RenderPadding( + padding: padding, + textDirection: Directionality.maybeOf(context), + ); + } + + @override + void updateRenderObject(BuildContext context, RenderPadding renderObject) { + renderObject + ..padding = padding + ..textDirection = Directionality.maybeOf(context); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding)); + } +} + +/// A widget that aligns its child within itself and optionally sizes itself +/// based on the child's size. +/// +/// For example, to align a box at the bottom right, you would pass this box a +/// tight constraint that is bigger than the child's natural size, +/// with an alignment of [Alignment.bottomRight]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=g2E7yl3MwMk} +/// +/// This widget will be as big as possible if its dimensions are constrained and +/// [widthFactor] and [heightFactor] are null. If a dimension is unconstrained +/// and the corresponding size factor is null then the widget will match its +/// child's size in that dimension. If a size factor is non-null then the +/// corresponding dimension of this widget will be the product of the child's +/// dimension and the size factor. For example if widthFactor is 2.0 then +/// the width of this widget will always be twice its child's width. +/// +/// {@tool snippet} +/// The [Align] widget in this example uses one of the defined constants from +/// [Alignment], [Alignment.topRight]. This places the [FlutterLogo] in the top +/// right corner of the parent blue [Container]. +/// +/// ![A blue square container with the Flutter logo in the top right corner.](https://flutter.github.io/assets-for-api-docs/assets/widgets/align_constant.png) +/// +/// ```dart +/// Center( +/// child: Container( +/// height: 120.0, +/// width: 120.0, +/// color: Colors.blue[50], +/// child: const Align( +/// alignment: Alignment.topRight, +/// child: FlutterLogo( +/// size: 60, +/// ), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ## How it works +/// +/// The [alignment] property describes a point in the `child`'s coordinate system +/// and a different point in the coordinate system of this widget. The [Align] +/// widget positions the `child` such that both points are lined up on top of +/// each other. +/// +/// {@tool snippet} +/// The [Alignment] used in the following example defines two points: +/// +/// * (0.2 * width of [FlutterLogo]/2 + width of [FlutterLogo]/2, 0.6 * height +/// of [FlutterLogo]/2 + height of [FlutterLogo]/2) = (36.0, 48.0) in the +/// coordinate system of the [FlutterLogo]. +/// * (0.2 * width of [Align]/2 + width of [Align]/2, 0.6 * height +/// of [Align]/2 + height of [Align]/2) = (72.0, 96.0) in the +/// coordinate system of the [Align] widget (blue area). +/// +/// The [Align] widget positions the [FlutterLogo] such that the two points are on +/// top of each other. In this example, the top left of the [FlutterLogo] will +/// be placed at (72.0, 96.0) - (36.0, 48.0) = (36.0, 48.0) from the top left of +/// the [Align] widget. +/// +/// ![A blue square container with the Flutter logo positioned according to the +/// Alignment specified above. A point is marked at the center of the container +/// for the origin of the Alignment coordinate system.](https://flutter.github.io/assets-for-api-docs/assets/widgets/align_alignment.png) +/// +/// ```dart +/// Center( +/// child: Container( +/// height: 120.0, +/// width: 120.0, +/// color: Colors.blue[50], +/// child: const Align( +/// alignment: Alignment(0.2, 0.6), +/// child: FlutterLogo( +/// size: 60, +/// ), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// The [FractionalOffset] used in the following example defines two points: +/// +/// * (0.2 * width of [FlutterLogo], 0.6 * height of [FlutterLogo]) = (12.0, 36.0) +/// in the coordinate system of the [FlutterLogo]. +/// * (0.2 * width of [Align], 0.6 * height of [Align]) = (24.0, 72.0) in the +/// coordinate system of the [Align] widget (blue area). +/// +/// The [Align] widget positions the [FlutterLogo] such that the two points are on +/// top of each other. In this example, the top left of the [FlutterLogo] will +/// be placed at (24.0, 72.0) - (12.0, 36.0) = (12.0, 36.0) from the top left of +/// the [Align] widget. +/// +/// The [FractionalOffset] class uses a coordinate system with an origin in the top-left +/// corner of the [Container] in difference to the center-oriented system used in +/// the example above with [Alignment]. +/// +/// ![A blue square container with the Flutter logo positioned according to the +/// FractionalOffset specified above. A point is marked at the top left corner +/// of the container for the origin of the FractionalOffset coordinate system.](https://flutter.github.io/assets-for-api-docs/assets/widgets/align_fractional_offset.png) +/// +/// ```dart +/// Center( +/// child: Container( +/// height: 120.0, +/// width: 120.0, +/// color: Colors.blue[50], +/// child: const Align( +/// alignment: FractionalOffset(0.2, 0.6), +/// child: FlutterLogo( +/// size: 60, +/// ), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedAlign], which animates changes in [alignment] smoothly over a +/// given duration. +/// * [CustomSingleChildLayout], which uses a delegate to control the layout of +/// a single child. +/// * [Center], which is the same as [Align] but with the [alignment] always +/// set to [Alignment.center]. +/// * [FractionallySizedBox], which sizes its child based on a fraction of its +/// own size and positions the child according to an [Alignment] value. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Align extends SingleChildRenderObjectWidget { + /// Creates an alignment widget. + /// + /// The alignment defaults to [Alignment.center]. + const Align({ + super.key, + this.alignment = Alignment.center, + this.widthFactor, + this.heightFactor, + super.child, + }) : assert(widthFactor == null || widthFactor >= 0.0), + assert(heightFactor == null || heightFactor >= 0.0); + + /// How to align the child. + /// + /// The x and y values of the [Alignment] control the horizontal and vertical + /// alignment, respectively. An x value of -1.0 means that the left edge of + /// the child is aligned with the left edge of the parent whereas an x value + /// of 1.0 means that the right edge of the child is aligned with the right + /// edge of the parent. Other values interpolate (and extrapolate) linearly. + /// For example, a value of 0.0 means that the center of the child is aligned + /// with the center of the parent. + /// + /// See also: + /// + /// * [Alignment], which has more details and some convenience constants for + /// common positions. + /// * [AlignmentDirectional], which has a horizontal coordinate orientation + /// that depends on the [TextDirection]. + final AlignmentGeometry alignment; + + /// If non-null, sets its width to the child's width multiplied by this factor. + /// + /// Can be both greater and less than 1.0 but must be non-negative. + final double? widthFactor; + + /// If non-null, sets its height to the child's height multiplied by this factor. + /// + /// Can be both greater and less than 1.0 but must be non-negative. + final double? heightFactor; + + @override + RenderPositionedBox createRenderObject(BuildContext context) { + return RenderPositionedBox( + alignment: alignment, + widthFactor: widthFactor, + heightFactor: heightFactor, + textDirection: Directionality.maybeOf(context), + ); + } + + @override + void updateRenderObject(BuildContext context, RenderPositionedBox renderObject) { + renderObject + ..alignment = alignment + ..widthFactor = widthFactor + ..heightFactor = heightFactor + ..textDirection = Directionality.maybeOf(context); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(DoubleProperty('widthFactor', widthFactor, defaultValue: null)); + properties.add(DoubleProperty('heightFactor', heightFactor, defaultValue: null)); + } +} + +/// A widget that centers its child within itself. +/// +/// This widget will be as big as possible if its dimensions are constrained and +/// [widthFactor] and [heightFactor] are null. If a dimension is unconstrained +/// and the corresponding size factor is null then the widget will match its +/// child's size in that dimension. If a size factor is non-null then the +/// corresponding dimension of this widget will be the product of the child's +/// dimension and the size factor. For example if widthFactor is 2.0 then +/// the width of this widget will always be twice its child's width. +/// +/// See also: +/// +/// * [Align], which lets you arbitrarily position a child within itself, +/// rather than just centering it. +/// * [Row], a widget that displays its children in a horizontal array. +/// * [Column], a widget that displays its children in a vertical array. +/// * [Container], a convenience widget that combines common painting, +/// positioning, and sizing widgets. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Center extends Align { + /// Creates a widget that centers its child. + const Center({ super.key, super.widthFactor, super.heightFactor, super.child }); +} + +/// A widget that defers the layout of its single child to a delegate. +/// +/// The delegate can determine the layout constraints for the child and can +/// decide where to position the child. The delegate can also determine the size +/// of the parent, but the size of the parent cannot depend on the size of the +/// child. +/// +/// See also: +/// +/// * [SingleChildLayoutDelegate], which controls the layout of the child. +/// * [Align], which sizes itself based on its child's size and positions +/// the child according to an [Alignment] value. +/// * [FractionallySizedBox], which sizes its child based on a fraction of its own +/// size and positions the child according to an [Alignment] value. +/// * [CustomMultiChildLayout], which uses a delegate to position multiple +/// children. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class CustomSingleChildLayout extends SingleChildRenderObjectWidget { + /// Creates a custom single child layout. + const CustomSingleChildLayout({ + super.key, + required this.delegate, + super.child, + }); + + /// The delegate that controls the layout of the child. + final SingleChildLayoutDelegate delegate; + + @override + RenderCustomSingleChildLayoutBox createRenderObject(BuildContext context) { + return RenderCustomSingleChildLayoutBox(delegate: delegate); + } + + @override + void updateRenderObject(BuildContext context, RenderCustomSingleChildLayoutBox renderObject) { + renderObject.delegate = delegate; + } +} + +/// Metadata for identifying children in a [CustomMultiChildLayout]. +/// +/// The [MultiChildLayoutDelegate.hasChild], +/// [MultiChildLayoutDelegate.layoutChild], and +/// [MultiChildLayoutDelegate.positionChild] methods use these identifiers. +class LayoutId extends ParentDataWidget<MultiChildLayoutParentData> { + /// Marks a child with a layout identifier. + LayoutId({ + Key? key, + required this.id, + required super.child, + }) : super(key: key ?? ValueKey<Object>(id)); + + /// An object representing the identity of this child. + /// + /// The [id] needs to be unique among the children that the + /// [CustomMultiChildLayout] manages. + final Object id; + + @override + void applyParentData(RenderObject renderObject) { + assert(renderObject.parentData is MultiChildLayoutParentData); + final MultiChildLayoutParentData parentData = renderObject.parentData! as MultiChildLayoutParentData; + if (parentData.id != id) { + parentData.id = id; + final RenderObject? targetParent = renderObject.parent; + if (targetParent is RenderObject) { + targetParent.markNeedsLayout(); + } + } + } + + @override + Type get debugTypicalAncestorWidgetClass => CustomMultiChildLayout; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Object>('id', id)); + } +} + +/// A widget that uses a delegate to size and position multiple children. +/// +/// The delegate can determine the layout constraints for each child and can +/// decide where to position each child. The delegate can also determine the +/// size of the parent, but the size of the parent cannot depend on the sizes of +/// the children. +/// +/// [CustomMultiChildLayout] is appropriate when there are complex relationships +/// between the size and positioning of multiple widgets. To control the +/// layout of a single child, [CustomSingleChildLayout] is more appropriate. For +/// simple cases, such as aligning a widget to one or another edge, the [Stack] +/// widget is more appropriate. +/// +/// Each child must be wrapped in a [LayoutId] widget to identify the widget for +/// the delegate. +/// +/// {@tool dartpad} +/// This example shows a [CustomMultiChildLayout] widget being used to lay out +/// colored blocks from start to finish in a cascade that has some overlap. +/// +/// It responds to changes in [Directionality] by re-laying out its children. +/// +/// ** See code in examples/api/lib/widgets/basic/custom_multi_child_layout.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [MultiChildLayoutDelegate], for details about how to control the layout of +/// the children. +/// * [CustomSingleChildLayout], which uses a delegate to control the layout of +/// a single child. +/// * [Stack], which arranges children relative to the edges of the container. +/// * [Flow], which provides paint-time control of its children using transform +/// matrices. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class CustomMultiChildLayout extends MultiChildRenderObjectWidget { + /// Creates a custom multi-child layout. + const CustomMultiChildLayout({ + super.key, + required this.delegate, + super.children, + }); + + /// The delegate that controls the layout of the children. + final MultiChildLayoutDelegate delegate; + + @override + RenderCustomMultiChildLayoutBox createRenderObject(BuildContext context) { + return RenderCustomMultiChildLayoutBox(delegate: delegate); + } + + @override + void updateRenderObject(BuildContext context, RenderCustomMultiChildLayoutBox renderObject) { + renderObject.delegate = delegate; + } +} + +/// A box with a specified size. +/// +/// If given a child, this widget forces it to have a specific width and/or height. +/// These values will be ignored if this widget's parent does not permit them. +/// For example, this happens if the parent is the screen (forces the child to +/// be the same size as the parent), or another [SizedBox] (forces its child to +/// have a specific width and/or height). This can be remedied by wrapping the +/// child [SizedBox] in a widget that does permit it to be any size up to the +/// size of the parent, such as [Center] or [Align]. +/// +/// If either the width or height is null, this widget will try to size itself to +/// match the child's size in that dimension. If the child's size depends on the +/// size of its parent, the height and width must be provided. +/// +/// If not given a child, [SizedBox] will try to size itself as close to the +/// specified height and width as possible given the parent's constraints. If +/// [height] or [width] is null or unspecified, it will be treated as zero. +/// +/// The [SizedBox.expand] constructor can be used to make a [SizedBox] that +/// sizes itself to fit the parent. It is equivalent to setting [width] and +/// [height] to [double.infinity]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=EHPu_DzRfqA} +/// +/// {@tool snippet} +/// +/// This snippet makes the child widget (a [Card] with some [Text]) have the +/// exact size 200x300, parental constraints permitting: +/// +/// ```dart +/// const SizedBox( +/// width: 200.0, +/// height: 300.0, +/// child: Card(child: Text('Hello World!')), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [ConstrainedBox], a more generic version of this class that takes +/// arbitrary [BoxConstraints] instead of an explicit width and height. +/// * [UnconstrainedBox], a container that tries to let its child draw without +/// constraints. +/// * [FractionallySizedBox], a widget that sizes its child to a fraction of +/// the total available space. +/// * [AspectRatio], a widget that attempts to fit within the parent's +/// constraints while also sizing its child to match a given aspect ratio. +/// * [FittedBox], which sizes and positions its child widget to fit the parent +/// according to a given [BoxFit] discipline. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +/// * [Understanding constraints](https://flutter.dev/docs/development/ui/layout/constraints), +/// an in-depth article about layout in Flutter. +class SizedBox extends SingleChildRenderObjectWidget { + /// Creates a fixed size box. The [width] and [height] parameters can be null + /// to indicate that the size of the box should not be constrained in + /// the corresponding dimension. + const SizedBox({ super.key, this.width, this.height, super.child }); + + /// Creates a box that will become as large as its parent allows. + const SizedBox.expand({ super.key, super.child }) + : width = double.infinity, + height = double.infinity; + + /// Creates a box that will become as small as its parent allows. + const SizedBox.shrink({ super.key, super.child }) + : width = 0.0, + height = 0.0; + + /// Creates a box with the specified size. + SizedBox.fromSize({ super.key, super.child, Size? size }) + : width = size?.width, + height = size?.height; + + /// Creates a box whose [width] and [height] are equal. + const SizedBox.square({super.key, super.child, double? dimension}) + : width = dimension, + height = dimension; + + /// If non-null, requires the child to have exactly this width. + final double? width; + + /// If non-null, requires the child to have exactly this height. + final double? height; + + @override + RenderConstrainedBox createRenderObject(BuildContext context) { + return RenderConstrainedBox( + additionalConstraints: _additionalConstraints, + ); + } + + BoxConstraints get _additionalConstraints { + return BoxConstraints.tightFor(width: width, height: height); + } + + @override + void updateRenderObject(BuildContext context, RenderConstrainedBox renderObject) { + renderObject.additionalConstraints = _additionalConstraints; + } + + @override + String toStringShort() { + final String type; + if (width == double.infinity && height == double.infinity) { + type = '${objectRuntimeType(this, 'SizedBox')}.expand'; + } else if (width == 0.0 && height == 0.0) { + type = '${objectRuntimeType(this, 'SizedBox')}.shrink'; + } else { + type = objectRuntimeType(this, 'SizedBox'); + } + return key == null ? type : '$type-$key'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final DiagnosticLevel level; + if ((width == double.infinity && height == double.infinity) || + (width == 0.0 && height == 0.0)) { + level = DiagnosticLevel.hidden; + } else { + level = DiagnosticLevel.info; + } + properties.add(DoubleProperty('width', width, defaultValue: null, level: level)); + properties.add(DoubleProperty('height', height, defaultValue: null, level: level)); + } +} + +/// A widget that imposes additional constraints on its child. +/// +/// For example, if you wanted [child] to have a minimum height of 50.0 logical +/// pixels, you could use `const BoxConstraints(minHeight: 50.0)` as the +/// [constraints]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=o2KveVr7adg} +/// +/// {@tool snippet} +/// +/// This snippet makes the child widget (a [Card] with some [Text]) fill the +/// parent, by applying [BoxConstraints.expand] constraints: +/// +/// ```dart +/// ConstrainedBox( +/// constraints: const BoxConstraints.expand(), +/// child: const Card(child: Text('Hello World!')), +/// ) +/// ``` +/// {@end-tool} +/// +/// The same behavior can be obtained using the [SizedBox.expand] widget. +/// +/// See also: +/// +/// * [BoxConstraints], the class that describes constraints. +/// * [UnconstrainedBox], a container that tries to let its child draw without +/// constraints. +/// * [SizedBox], which lets you specify tight constraints by explicitly +/// specifying the height or width. +/// * [FractionallySizedBox], which sizes its child based on a fraction of its +/// own size and positions the child according to an [Alignment] value. +/// * [AspectRatio], a widget that attempts to fit within the parent's +/// constraints while also sizing its child to match a given aspect ratio. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class ConstrainedBox extends SingleChildRenderObjectWidget { + /// Creates a widget that imposes additional constraints on its child. + ConstrainedBox({ + super.key, + required this.constraints, + super.child, + }) : assert(constraints.debugAssertIsValid()); + + /// The additional constraints to impose on the child. + final BoxConstraints constraints; + + @override + RenderConstrainedBox createRenderObject(BuildContext context) { + return RenderConstrainedBox(additionalConstraints: constraints); + } + + @override + void updateRenderObject(BuildContext context, RenderConstrainedBox renderObject) { + renderObject.additionalConstraints = constraints; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<BoxConstraints>('constraints', constraints, showName: false)); + } +} + +/// A container widget that applies an arbitrary transform to its constraints, +/// and sizes its child using the resulting [BoxConstraints], optionally +/// clipping, or treating the overflow as an error. +/// +/// This container sizes its child using a [BoxConstraints] created by applying +/// [constraintsTransform] to its own constraints. This container will then +/// attempt to adopt the same size, within the limits of its own constraints. If +/// it ends up with a different size, it will align the child based on +/// [alignment]. If the container cannot expand enough to accommodate the entire +/// child, the child will be clipped if [clipBehavior] is not [Clip.none]. +/// +/// In debug mode, if [clipBehavior] is [Clip.none] and the child overflows the +/// container, a warning will be printed on the console, and black and yellow +/// striped areas will appear where the overflow occurs. +/// +/// When [child] is null, this widget becomes as small as possible and never +/// overflows. +/// +/// This widget can be used to ensure some of [child]'s natural dimensions are +/// honored, and get an early warning otherwise during development. For +/// instance, if [child] requires a minimum height to fully display its content, +/// [constraintsTransform] can be set to [maxHeightUnconstrained], so that if +/// the parent [RenderObject] fails to provide enough vertical space, a warning +/// will be displayed in debug mode, while still allowing [child] to grow +/// vertically: +/// +/// {@tool snippet} +/// In the following snippet, the [Card] is guaranteed to be at least as tall as +/// its "natural" height. Unlike [UnconstrainedBox], it will become taller if +/// its "natural" height is smaller than 40 px. If the [Container] isn't high +/// enough to show the full content of the [Card], in debug mode a warning will +/// be given. +/// +/// ```dart +/// Container( +/// constraints: const BoxConstraints(minHeight: 40, maxHeight: 100), +/// alignment: Alignment.center, +/// child: const ConstraintsTransformBox( +/// constraintsTransform: ConstraintsTransformBox.maxHeightUnconstrained, +/// child: Card(child: Text('Hello World!')), +/// ) +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [ConstrainedBox], which renders a box which imposes constraints +/// on its child. +/// * [OverflowBox], a widget that imposes additional constraints on its child, +/// and allows the child to overflow itself. +/// * [UnconstrainedBox] which allows its children to render themselves +/// unconstrained and expands to fit them. +class ConstraintsTransformBox extends SingleChildRenderObjectWidget { + /// Creates a widget that uses a function to transform the constraints it + /// passes to its child. If the child overflows the parent's constraints, a + /// warning will be given in debug mode. + /// + /// The `debugTransformType` argument adds a debug label to this widget. + /// + /// The `alignment`, `clipBehavior` and `constraintsTransform` arguments must + /// not be null. + const ConstraintsTransformBox({ + super.key, + super.child, + this.textDirection, + this.alignment = Alignment.center, + required this.constraintsTransform, + this.clipBehavior = Clip.none, + String debugTransformType = '', + }) : _debugTransformLabel = debugTransformType; + + /// A [BoxConstraintsTransform] that always returns its argument as-is (i.e., + /// it is an identity function). + /// + /// The [ConstraintsTransformBox] becomes a proxy widget that has no effect on + /// layout if [constraintsTransform] is set to this. + static BoxConstraints unmodified(BoxConstraints constraints) => constraints; + + /// A [BoxConstraintsTransform] that always returns a [BoxConstraints] that + /// imposes no constraints on either dimension (i.e. `const BoxConstraints()`). + /// + /// Setting [constraintsTransform] to this allows [child] to render at its + /// "natural" size (equivalent to an [UnconstrainedBox] with `constrainedAxis` + /// set to null). + static BoxConstraints unconstrained(BoxConstraints constraints) => const BoxConstraints(); + + /// A [BoxConstraintsTransform] that removes the width constraints from the + /// input. + /// + /// Setting [constraintsTransform] to this allows [child] to render at its + /// "natural" width (equivalent to an [UnconstrainedBox] with + /// `constrainedAxis` set to [Axis.horizontal]). + static BoxConstraints widthUnconstrained(BoxConstraints constraints) => constraints.heightConstraints(); + + /// A [BoxConstraintsTransform] that removes the height constraints from the + /// input. + /// + /// Setting [constraintsTransform] to this allows [child] to render at its + /// "natural" height (equivalent to an [UnconstrainedBox] with + /// `constrainedAxis` set to [Axis.vertical]). + static BoxConstraints heightUnconstrained(BoxConstraints constraints) => constraints.widthConstraints(); + + /// A [BoxConstraintsTransform] that removes the `maxHeight` constraint from + /// the input. + /// + /// Setting [constraintsTransform] to this allows [child] to render at its + /// "natural" height or the `minHeight` of the incoming [BoxConstraints], + /// whichever is larger. + static BoxConstraints maxHeightUnconstrained(BoxConstraints constraints) => constraints.copyWith(maxHeight: double.infinity); + + /// A [BoxConstraintsTransform] that removes the `maxWidth` constraint from + /// the input. + /// + /// Setting [constraintsTransform] to this allows [child] to render at its + /// "natural" width or the `minWidth` of the incoming [BoxConstraints], + /// whichever is larger. + static BoxConstraints maxWidthUnconstrained(BoxConstraints constraints) => constraints.copyWith(maxWidth: double.infinity); + + /// A [BoxConstraintsTransform] that removes both the `maxWidth` and the + /// `maxHeight` constraints from the input. + /// + /// Setting [constraintsTransform] to this allows [child] to render at least + /// its "natural" size, and grow along an axis if the incoming + /// [BoxConstraints] has a larger minimum constraint on that axis. + static BoxConstraints maxUnconstrained(BoxConstraints constraints) => constraints.copyWith(maxWidth: double.infinity, maxHeight: double.infinity); + + static final Map<BoxConstraintsTransform, String> _debugKnownTransforms = <BoxConstraintsTransform, String>{ + unmodified: 'unmodified', + unconstrained: 'unconstrained', + widthUnconstrained: 'width constraints removed', + heightUnconstrained: 'height constraints removed', + maxWidthUnconstrained: 'maxWidth constraint removed', + maxHeightUnconstrained: 'maxHeight constraint removed', + maxUnconstrained: 'maxWidth & maxHeight constraints removed', + }; + + /// The text direction to use when interpreting the [alignment] if it is an + /// [AlignmentDirectional]. + /// + /// Defaults to null, in which case [Directionality.maybeOf] is used to determine + /// the text direction. + final TextDirection? textDirection; + + /// The alignment to use when laying out the child, if it has a different size + /// than this widget. + /// + /// If this is an [AlignmentDirectional], then [textDirection] must not be + /// null. + /// + /// See also: + /// + /// * [Alignment] for non-[Directionality]-aware alignments. + /// * [AlignmentDirectional] for [Directionality]-aware alignments. + final AlignmentGeometry alignment; + + /// {@template flutter.widgets.constraintsTransform} + /// The function used to transform the incoming [BoxConstraints], to size + /// [child]. + /// + /// The function must return a [BoxConstraints] that is + /// [BoxConstraints.isNormalized]. + /// + /// See [ConstraintsTransformBox] for predefined common + /// [BoxConstraintsTransform]s. + /// {@endtemplate} + final BoxConstraintsTransform constraintsTransform; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// {@template flutter.widgets.ConstraintsTransformBox.clipBehavior} + /// In debug mode, if [clipBehavior] is [Clip.none], and the child overflows + /// its constraints, a warning will be printed on the console, and black and + /// yellow striped areas will appear where the overflow occurs. For other + /// values of [clipBehavior], the contents are clipped accordingly. + /// {@endtemplate} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + final String _debugTransformLabel; + + @override + RenderConstraintsTransformBox createRenderObject(BuildContext context) { + return RenderConstraintsTransformBox( + textDirection: textDirection ?? Directionality.maybeOf(context), + alignment: alignment, + constraintsTransform: constraintsTransform, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, covariant RenderConstraintsTransformBox renderObject) { + renderObject + ..textDirection = textDirection ?? Directionality.maybeOf(context) + ..constraintsTransform = constraintsTransform + ..alignment = alignment + ..clipBehavior = clipBehavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + + final String? debugTransformLabel = _debugTransformLabel.isNotEmpty + ? _debugTransformLabel + : _debugKnownTransforms[constraintsTransform]; + + if (debugTransformLabel != null) { + properties.add(DiagnosticsProperty<String>('constraints transform', debugTransformLabel)); + } + } +} + +/// A widget that imposes no constraints on its child, allowing it to render +/// at its "natural" size. +/// +/// This allows a child to render at the size it would render if it were alone +/// on an infinite canvas with no constraints. This container will then attempt +/// to adopt the same size, within the limits of its own constraints. If it ends +/// up with a different size, it will align the child based on [alignment]. +/// If the box cannot expand enough to accommodate the entire child, the +/// child will be clipped. +/// +/// In debug mode, if the child overflows the container, a warning will be +/// printed on the console, and black and yellow striped areas will appear where +/// the overflow occurs. +/// +/// See also: +/// +/// * [ConstrainedBox], for a box which imposes constraints on its child. +/// * [Align], which loosens the constraints given to the child rather than +/// removing them entirely. +/// * [Container], a convenience widget that combines common painting, +/// positioning, and sizing widgets. +/// * [OverflowBox], a widget that imposes different constraints on its child +/// than it gets from its parent, possibly allowing the child to overflow +/// the parent. +/// * [ConstraintsTransformBox], a widget that sizes its child using a +/// transformed [BoxConstraints], and shows a warning if the child overflows +/// in debug mode. +class UnconstrainedBox extends StatelessWidget { + /// Creates a widget that imposes no constraints on its child, allowing it to + /// render at its "natural" size. If the child overflows the parents + /// constraints, a warning will be given in debug mode. + const UnconstrainedBox({ + super.key, + this.child, + this.textDirection, + this.alignment = Alignment.center, + this.constrainedAxis, + this.clipBehavior = Clip.none, + }); + + /// The text direction to use when interpreting the [alignment] if it is an + /// [AlignmentDirectional]. + final TextDirection? textDirection; + + /// The alignment to use when laying out the child. + /// + /// If this is an [AlignmentDirectional], then [textDirection] must not be + /// null. + /// + /// See also: + /// + /// * [Alignment] for non-[Directionality]-aware alignments. + /// * [AlignmentDirectional] for [Directionality]-aware alignments. + final AlignmentGeometry alignment; + + /// The axis to retain constraints on, if any. + /// + /// If not set, or set to null (the default), neither axis will retain its + /// constraints. If set to [Axis.vertical], then vertical constraints will + /// be retained, and if set to [Axis.horizontal], then horizontal constraints + /// will be retained. + final Axis? constrainedAxis; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + BoxConstraintsTransform _axisToTransform(Axis? constrainedAxis) { + if (constrainedAxis != null) { + switch (constrainedAxis) { + case Axis.horizontal: + return ConstraintsTransformBox.heightUnconstrained; + case Axis.vertical: + return ConstraintsTransformBox.widthUnconstrained; + } + } else { + return ConstraintsTransformBox.unconstrained; + } + } + + @override + Widget build(BuildContext context) { + return ConstraintsTransformBox( + textDirection: textDirection, + alignment: alignment, + clipBehavior: clipBehavior, + constraintsTransform: _axisToTransform(constrainedAxis), + child: child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(EnumProperty<Axis>('constrainedAxis', constrainedAxis, defaultValue: null)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + } +} + +/// A widget that sizes its child to a fraction of the total available space. +/// For more details about the layout algorithm, see +/// [RenderFractionallySizedOverflowBox]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=PEsY654EGZ0} +/// +/// {@tool dartpad} +/// This sample shows a [FractionallySizedBox] whose one child is 50% of +/// the box's size per the width and height factor parameters, and centered +/// within that box by the alignment parameter. +/// +/// ** See code in examples/api/lib/widgets/basic/fractionally_sized_box.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Align], which sizes itself based on its child's size and positions +/// the child according to an [Alignment] value. +/// * [OverflowBox], a widget that imposes different constraints on its child +/// than it gets from its parent, possibly allowing the child to overflow the +/// parent. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class FractionallySizedBox extends SingleChildRenderObjectWidget { + /// Creates a widget that sizes its child to a fraction of the total available space. + /// + /// If non-null, the [widthFactor] and [heightFactor] arguments must be + /// non-negative. + const FractionallySizedBox({ + super.key, + this.alignment = Alignment.center, + this.widthFactor, + this.heightFactor, + super.child, + }) : assert(widthFactor == null || widthFactor >= 0.0), + assert(heightFactor == null || heightFactor >= 0.0); + + /// {@template flutter.widgets.basic.fractionallySizedBox.widthFactor} + /// If non-null, the fraction of the incoming width given to the child. + /// + /// If non-null, the child is given a tight width constraint that is the max + /// incoming width constraint multiplied by this factor. + /// + /// If null, the incoming width constraints are passed to the child + /// unmodified. + /// {@endtemplate} + final double? widthFactor; + + /// {@template flutter.widgets.basic.fractionallySizedBox.heightFactor} + /// If non-null, the fraction of the incoming height given to the child. + /// + /// If non-null, the child is given a tight height constraint that is the max + /// incoming height constraint multiplied by this factor. + /// + /// If null, the incoming height constraints are passed to the child + /// unmodified. + /// {@endtemplate} + final double? heightFactor; + + /// {@template flutter.widgets.basic.fractionallySizedBox.alignment} + /// How to align the child. + /// + /// The x and y values of the alignment control the horizontal and vertical + /// alignment, respectively. An x value of -1.0 means that the left edge of + /// the child is aligned with the left edge of the parent whereas an x value + /// of 1.0 means that the right edge of the child is aligned with the right + /// edge of the parent. Other values interpolate (and extrapolate) linearly. + /// For example, a value of 0.0 means that the center of the child is aligned + /// with the center of the parent. + /// + /// Defaults to [Alignment.center]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + /// {@endtemplate} + final AlignmentGeometry alignment; + + @override + RenderFractionallySizedOverflowBox createRenderObject(BuildContext context) { + return RenderFractionallySizedOverflowBox( + alignment: alignment, + widthFactor: widthFactor, + heightFactor: heightFactor, + textDirection: Directionality.maybeOf(context), + ); + } + + @override + void updateRenderObject(BuildContext context, RenderFractionallySizedOverflowBox renderObject) { + renderObject + ..alignment = alignment + ..widthFactor = widthFactor + ..heightFactor = heightFactor + ..textDirection = Directionality.maybeOf(context); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(DoubleProperty('widthFactor', widthFactor, defaultValue: null)); + properties.add(DoubleProperty('heightFactor', heightFactor, defaultValue: null)); + } +} + +/// A box that limits its size only when it's unconstrained. +/// +/// If this widget's maximum width is unconstrained then its child's width is +/// limited to [maxWidth]. Similarly, if this widget's maximum height is +/// unconstrained then its child's height is limited to [maxHeight]. +/// +/// This has the effect of giving the child a natural dimension in unbounded +/// environments. For example, by providing a [maxHeight] to a widget that +/// normally tries to be as big as possible, the widget will normally size +/// itself to fit its parent, but when placed in a vertical list, it will take +/// on the given height. +/// +/// This is useful when composing widgets that normally try to match their +/// parents' size, so that they behave reasonably in lists (which are +/// unbounded). +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=uVki2CIzBTs} +/// +/// See also: +/// +/// * [ConstrainedBox], which applies its constraints in all cases, not just +/// when the incoming constraints are unbounded. +/// * [SizedBox], which lets you specify tight constraints by explicitly +/// specifying the height or width. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class LimitedBox extends SingleChildRenderObjectWidget { + /// Creates a box that limits its size only when it's unconstrained. + /// + /// The [maxWidth] and [maxHeight] arguments must not be negative. + const LimitedBox({ + super.key, + this.maxWidth = double.infinity, + this.maxHeight = double.infinity, + super.child, + }) : assert(maxWidth >= 0.0), + assert(maxHeight >= 0.0); + + /// The maximum width limit to apply in the absence of a + /// [BoxConstraints.maxWidth] constraint. + final double maxWidth; + + /// The maximum height limit to apply in the absence of a + /// [BoxConstraints.maxHeight] constraint. + final double maxHeight; + + @override + RenderLimitedBox createRenderObject(BuildContext context) { + return RenderLimitedBox( + maxWidth: maxWidth, + maxHeight: maxHeight, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderLimitedBox renderObject) { + renderObject + ..maxWidth = maxWidth + ..maxHeight = maxHeight; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('maxWidth', maxWidth, defaultValue: double.infinity)); + properties.add(DoubleProperty('maxHeight', maxHeight, defaultValue: double.infinity)); + } +} + +/// A widget that imposes different constraints on its child than it gets +/// from its parent, possibly allowing the child to overflow the parent. +/// +/// {@tool dartpad} +/// This example shows how an [OverflowBox] is used, and what its effect is. +/// +/// ** See code in examples/api/lib/widgets/basic/overflowbox.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [RenderConstrainedOverflowBox] for details about how [OverflowBox] is +/// rendered. +/// * [SizedOverflowBox], a widget that is a specific size but passes its +/// original constraints through to its child, which may then overflow. +/// * [ConstrainedBox], a widget that imposes additional constraints on its +/// child. +/// * [UnconstrainedBox], a container that tries to let its child draw without +/// constraints. +/// * [SizedBox], a box with a specified size. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class OverflowBox extends SingleChildRenderObjectWidget { + /// Creates a widget that lets its child overflow itself. + const OverflowBox({ + super.key, + this.alignment = Alignment.center, + this.minWidth, + this.maxWidth, + this.minHeight, + this.maxHeight, + this.fit = OverflowBoxFit.max, + super.child, + }); + + /// How to align the child. + /// + /// The x and y values of the alignment control the horizontal and vertical + /// alignment, respectively. An x value of -1.0 means that the left edge of + /// the child is aligned with the left edge of the parent whereas an x value + /// of 1.0 means that the right edge of the child is aligned with the right + /// edge of the parent. Other values interpolate (and extrapolate) linearly. + /// For example, a value of 0.0 means that the center of the child is aligned + /// with the center of the parent. + /// + /// Defaults to [Alignment.center]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// The minimum width constraint to give the child. Set this to null (the + /// default) to use the constraint from the parent instead. + final double? minWidth; + + /// The maximum width constraint to give the child. Set this to null (the + /// default) to use the constraint from the parent instead. + final double? maxWidth; + + /// The minimum height constraint to give the child. Set this to null (the + /// default) to use the constraint from the parent instead. + final double? minHeight; + + /// The maximum height constraint to give the child. Set this to null (the + /// default) to use the constraint from the parent instead. + final double? maxHeight; + + /// The way to size the render object. + /// + /// This only affects scenario when the child does not indeed overflow. + /// If set to [OverflowBoxFit.deferToChild], the render object will size itself to + /// match the size of its child within the constraints of its parent or be + /// as small as the parent allows if no child is set. If set to + /// [OverflowBoxFit.max] (the default), the render object will size itself + /// to be as large as the parent allows. + final OverflowBoxFit fit; + + @override + RenderConstrainedOverflowBox createRenderObject(BuildContext context) { + return RenderConstrainedOverflowBox( + alignment: alignment, + minWidth: minWidth, + maxWidth: maxWidth, + minHeight: minHeight, + maxHeight: maxHeight, + fit: fit, + textDirection: Directionality.maybeOf(context), + ); + } + + @override + void updateRenderObject(BuildContext context, RenderConstrainedOverflowBox renderObject) { + renderObject + ..alignment = alignment + ..minWidth = minWidth + ..maxWidth = maxWidth + ..minHeight = minHeight + ..maxHeight = maxHeight + ..fit = fit + ..textDirection = Directionality.maybeOf(context); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(DoubleProperty('minWidth', minWidth, defaultValue: null)); + properties.add(DoubleProperty('maxWidth', maxWidth, defaultValue: null)); + properties.add(DoubleProperty('minHeight', minHeight, defaultValue: null)); + properties.add(DoubleProperty('maxHeight', maxHeight, defaultValue: null)); + properties.add(EnumProperty<OverflowBoxFit>('fit', fit)); + } +} + +/// A widget that is a specific size but passes its original constraints +/// through to its child, which may then overflow. +/// +/// See also: +/// +/// * [OverflowBox], A widget that imposes different constraints on its child +/// than it gets from its parent, possibly allowing the child to overflow the +/// parent. +/// * [ConstrainedBox], a widget that imposes additional constraints on its +/// child. +/// * [UnconstrainedBox], a container that tries to let its child draw without +/// constraints. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class SizedOverflowBox extends SingleChildRenderObjectWidget { + /// Creates a widget of a given size that lets its child overflow. + const SizedOverflowBox({ + super.key, + required this.size, + this.alignment = Alignment.center, + super.child, + }); + + /// How to align the child. + /// + /// The x and y values of the alignment control the horizontal and vertical + /// alignment, respectively. An x value of -1.0 means that the left edge of + /// the child is aligned with the left edge of the parent whereas an x value + /// of 1.0 means that the right edge of the child is aligned with the right + /// edge of the parent. Other values interpolate (and extrapolate) linearly. + /// For example, a value of 0.0 means that the center of the child is aligned + /// with the center of the parent. + /// + /// Defaults to [Alignment.center]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// The size this widget should attempt to be. + final Size size; + + @override + RenderSizedOverflowBox createRenderObject(BuildContext context) { + return RenderSizedOverflowBox( + alignment: alignment, + requestedSize: size, + textDirection: Directionality.of(context), + ); + } + + @override + void updateRenderObject(BuildContext context, RenderSizedOverflowBox renderObject) { + renderObject + ..alignment = alignment + ..requestedSize = size + ..textDirection = Directionality.of(context); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(DiagnosticsProperty<Size>('size', size, defaultValue: null)); + } +} + +/// A widget that lays the child out as if it was in the tree, but without +/// painting anything, without making the child available for hit testing, and +/// without taking any room in the parent. +/// +/// Offstage children are still active: they can receive focus and have keyboard +/// input directed to them. +/// +/// Animations continue to run in offstage children, and therefore use battery +/// and CPU time, regardless of whether the animations end up being visible. +/// +/// [Offstage] can be used to measure the dimensions of a widget without +/// bringing it on screen (yet). To hide a widget from view while it is not +/// needed, prefer removing the widget from the tree entirely rather than +/// keeping it alive in an [Offstage] subtree. +/// +/// {@tool dartpad} +/// This example shows a [FlutterLogo] widget when the `_offstage` member field +/// is false, and hides it without any room in the parent when it is true. When +/// offstage, this app displays a button to get the logo size, which will be +/// displayed in a [SnackBar]. +/// +/// ** See code in examples/api/lib/widgets/basic/offstage.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Visibility], which can hide a child more efficiently (albeit less +/// subtly). +/// * [TickerMode], which can be used to disable animations in a subtree. +/// * [SliverOffstage], the sliver version of this widget. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Offstage extends SingleChildRenderObjectWidget { + /// Creates a widget that visually hides its child. + const Offstage({ super.key, this.offstage = true, super.child }); + + /// Whether the child is hidden from the rest of the tree. + /// + /// If true, the child is laid out as if it was in the tree, but without + /// painting anything, without making the child available for hit testing, and + /// without taking any room in the parent. + /// + /// Offstage children are still active: they can receive focus and have keyboard + /// input directed to them. + /// + /// Animations continue to run in offstage children, and therefore use battery + /// and CPU time, regardless of whether the animations end up being visible. + /// + /// If false, the child is included in the tree as normal. + final bool offstage; + + @override + RenderOffstage createRenderObject(BuildContext context) => RenderOffstage(offstage: offstage); + + @override + void updateRenderObject(BuildContext context, RenderOffstage renderObject) { + renderObject.offstage = offstage; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('offstage', offstage)); + } + + @override + SingleChildRenderObjectElement createElement() => _OffstageElement(this); +} + +class _OffstageElement extends SingleChildRenderObjectElement { + _OffstageElement(Offstage super.widget); + + @override + void debugVisitOnstageChildren(ElementVisitor visitor) { + if (!(widget as Offstage).offstage) { + super.debugVisitOnstageChildren(visitor); + } + } +} + +/// A widget that attempts to size the child to a specific aspect ratio. +/// +/// The aspect ratio is expressed as a ratio of width to height. For example, a +/// 16:9 width:height aspect ratio would have a value of 16.0/9.0. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=XcnP3_mO_Ms} +/// +/// The [AspectRatio] widget uses a finite iterative process to compute the +/// appropriate constraints for the child, and then lays the child out a single +/// time with those constraints. This iterative process is efficient and does +/// not require multiple layout passes. +/// +/// The widget first tries the largest width permitted by the layout +/// constraints, and determines the height of the widget by applying the given +/// aspect ratio to the width, expressed as a ratio of width to height. +/// +/// If the maximum width is infinite, the initial width is determined +/// by applying the aspect ratio to the maximum height instead. +/// +/// The widget then examines if the computed dimensions are compatible with the +/// parent's constraints; if not, the dimensions are recomputed a second time, +/// taking those constraints into account. +/// +/// If the widget does not find a feasible size after consulting each +/// constraint, the widget will eventually select a size for the child that +/// meets the layout constraints but fails to meet the aspect ratio constraints. +/// +/// {@tool dartpad} +/// This examples shows how [AspectRatio] sets the width when its parent's width +/// constraint is infinite. Since the parent's allowed height is a fixed value, +/// the actual width is determined via the given [aspectRatio]. +/// +/// In this example, the height is fixed at 100.0 and the aspect ratio is set to +/// 16 / 9, making the width 100.0 / 9 * 16. +/// +/// ** See code in examples/api/lib/widgets/basic/aspect_ratio.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This second example uses an aspect ratio of 2.0, and layout constraints that +/// require the width to be between 0.0 and 100.0, and the height to be between +/// 0.0 and 100.0. The widget selects a width of 100.0 (the biggest allowed) and +/// a height of 50.0 (to match the aspect ratio). +/// +/// ** See code in examples/api/lib/widgets/basic/aspect_ratio.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This third example is similar to the second, but with the aspect ratio set +/// to 0.5. The widget still selects a width of 100.0 (the biggest allowed), and +/// attempts to use a height of 200.0. Unfortunately, that violates the +/// constraints because the child can be at most 100.0 pixels tall. The widget +/// will then take that value and apply the aspect ratio again to obtain a width +/// of 50.0. That width is permitted by the constraints and the child receives a +/// width of 50.0 and a height of 100.0. If the width were not permitted, the +/// widget would continue iterating through the constraints. +/// +/// ** See code in examples/api/lib/widgets/basic/aspect_ratio.2.dart ** +/// {@end-tool} +/// +/// ## Setting the aspect ratio in unconstrained situations +/// +/// When using a widget such as [FittedBox], the constraints are unbounded. This +/// results in [AspectRatio] being unable to find a suitable set of constraints +/// to apply. In that situation, consider explicitly setting a size using +/// [SizedBox] instead of setting the aspect ratio using [AspectRatio]. The size +/// is then scaled appropriately by the [FittedBox]. +/// +/// See also: +/// +/// * [Align], a widget that aligns its child within itself and optionally +/// sizes itself based on the child's size. +/// * [ConstrainedBox], a widget that imposes additional constraints on its +/// child. +/// * [UnconstrainedBox], a container that tries to let its child draw without +/// constraints. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class AspectRatio extends SingleChildRenderObjectWidget { + /// Creates a widget with a specific aspect ratio. + /// + /// The [aspectRatio] argument must be a finite number greater than zero. + const AspectRatio({ + super.key, + required this.aspectRatio, + super.child, + }) : assert(aspectRatio > 0.0); + + /// The aspect ratio to attempt to use. + /// + /// The aspect ratio is expressed as a ratio of width to height. For example, + /// a 16:9 width:height aspect ratio would have a value of 16.0/9.0. + final double aspectRatio; + + @override + RenderAspectRatio createRenderObject(BuildContext context) => RenderAspectRatio(aspectRatio: aspectRatio); + + @override + void updateRenderObject(BuildContext context, RenderAspectRatio renderObject) { + renderObject.aspectRatio = aspectRatio; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('aspectRatio', aspectRatio)); + } +} + +/// A widget that sizes its child to the child's maximum intrinsic width. +/// +/// This class is useful, for example, when unlimited width is available and +/// you would like a child that would otherwise attempt to expand infinitely to +/// instead size itself to a more reasonable width. +/// +/// The constraints that this widget passes to its child will adhere to the +/// parent's constraints, so if the constraints are not large enough to satisfy +/// the child's maximum intrinsic width, then the child will get less width +/// than it otherwise would. Likewise, if the minimum width constraint is +/// larger than the child's maximum intrinsic width, the child will be given +/// more width than it otherwise would. +/// +/// If [stepWidth] is non-null, the child's width will be snapped to a multiple +/// of the [stepWidth]. Similarly, if [stepHeight] is non-null, the child's +/// height will be snapped to a multiple of the [stepHeight]. +/// +/// This class is relatively expensive, because it adds a speculative layout +/// pass before the final layout phase. Avoid using it where possible. In the +/// worst case, this widget can result in a layout that is O(N²) in the depth of +/// the tree. +/// +/// See also: +/// +/// * [Align], a widget that aligns its child within itself. This can be used +/// to loosen the constraints passed to the [RenderIntrinsicWidth], +/// allowing the [RenderIntrinsicWidth]'s child to be smaller than that of +/// its parent. +/// * [Row], which when used with [CrossAxisAlignment.stretch] can be used +/// to loosen just the width constraints that are passed to the +/// [RenderIntrinsicWidth], allowing the [RenderIntrinsicWidth]'s child's +/// width to be smaller than that of its parent. +/// * [The catalog of layout widgets](https://flutter.dev/widgets/layout/). +class IntrinsicWidth extends SingleChildRenderObjectWidget { + /// Creates a widget that sizes its child to the child's intrinsic width. + /// + /// This class is relatively expensive. Avoid using it where possible. + const IntrinsicWidth({ super.key, this.stepWidth, this.stepHeight, super.child }) + : assert(stepWidth == null || stepWidth >= 0.0), + assert(stepHeight == null || stepHeight >= 0.0); + + /// If non-null, force the child's width to be a multiple of this value. + /// + /// If null or 0.0 the child's width will be the same as its maximum + /// intrinsic width. + /// + /// This value must not be negative. + /// + /// See also: + /// + /// * [RenderBox.getMaxIntrinsicWidth], which defines a widget's max + /// intrinsic width in general. + final double? stepWidth; + + /// If non-null, force the child's height to be a multiple of this value. + /// + /// If null or 0.0 the child's height will not be constrained. + /// + /// This value must not be negative. + final double? stepHeight; + + double? get _stepWidth => stepWidth == 0.0 ? null : stepWidth; + double? get _stepHeight => stepHeight == 0.0 ? null : stepHeight; + + @override + RenderIntrinsicWidth createRenderObject(BuildContext context) { + return RenderIntrinsicWidth(stepWidth: _stepWidth, stepHeight: _stepHeight); + } + + @override + void updateRenderObject(BuildContext context, RenderIntrinsicWidth renderObject) { + renderObject + ..stepWidth = _stepWidth + ..stepHeight = _stepHeight; + } +} + +/// A widget that sizes its child to the child's intrinsic height. +/// +/// This class is useful, for example, when unlimited height is available and +/// you would like a child that would otherwise attempt to expand infinitely to +/// instead size itself to a more reasonable height. +/// +/// The constraints that this widget passes to its child will adhere to the +/// parent's constraints, so if the constraints are not large enough to satisfy +/// the child's maximum intrinsic height, then the child will get less height +/// than it otherwise would. Likewise, if the minimum height constraint is +/// larger than the child's maximum intrinsic height, the child will be given +/// more height than it otherwise would. +/// +/// This class is relatively expensive, because it adds a speculative layout +/// pass before the final layout phase. Avoid using it where possible. In the +/// worst case, this widget can result in a layout that is O(N²) in the depth of +/// the tree. +/// +/// See also: +/// +/// * [Align], a widget that aligns its child within itself. This can be used +/// to loosen the constraints passed to the [RenderIntrinsicHeight], +/// allowing the [RenderIntrinsicHeight]'s child to be smaller than that of +/// its parent. +/// * [Column], which when used with [CrossAxisAlignment.stretch] can be used +/// to loosen just the height constraints that are passed to the +/// [RenderIntrinsicHeight], allowing the [RenderIntrinsicHeight]'s child's +/// height to be smaller than that of its parent. +/// * [The catalog of layout widgets](https://flutter.dev/widgets/layout/). +class IntrinsicHeight extends SingleChildRenderObjectWidget { + /// Creates a widget that sizes its child to the child's intrinsic height. + /// + /// This class is relatively expensive. Avoid using it where possible. + const IntrinsicHeight({ super.key, super.child }); + + @override + RenderIntrinsicHeight createRenderObject(BuildContext context) => RenderIntrinsicHeight(); +} + +/// A widget that positions its child according to the child's baseline. +/// +/// This widget shifts the child down such that the child's baseline (or the +/// bottom of the child, if the child has no baseline) is [baseline] +/// logical pixels below the top of this box, then sizes this box to +/// contain the child. If [baseline] is less than the distance from +/// the top of the child to the baseline of the child, then the child +/// is top-aligned instead. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=8ZaFk0yvNlI} +/// +/// See also: +/// +/// * [Align], a widget that aligns its child within itself and optionally +/// sizes itself based on the child's size. +/// * [Center], a widget that centers its child within itself. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Baseline extends SingleChildRenderObjectWidget { + /// Creates a widget that positions its child according to the child's baseline. + const Baseline({ + super.key, + required this.baseline, + required this.baselineType, + super.child, + }); + + /// The number of logical pixels from the top of this box at which to position + /// the child's baseline. + final double baseline; + + /// The type of baseline to use for positioning the child. + final TextBaseline baselineType; + + @override + RenderBaseline createRenderObject(BuildContext context) { + return RenderBaseline(baseline: baseline, baselineType: baselineType); + } + + @override + void updateRenderObject(BuildContext context, RenderBaseline renderObject) { + renderObject + ..baseline = baseline + ..baselineType = baselineType; + } +} + +/// A widget that causes the parent to ignore the [child] for the purposes +/// of baseline alignment. +/// +/// See also: +/// +/// * [Baseline], a widget that positions a child relative to a baseline. +class IgnoreBaseline extends SingleChildRenderObjectWidget { + /// Creates a widget that ignores the child for baseline alignment purposes. + const IgnoreBaseline({ + super.key, + super.child, + }); + + @override + RenderIgnoreBaseline createRenderObject(BuildContext context) { + return RenderIgnoreBaseline(); + } +} + + +// SLIVERS + +/// A sliver that contains a single box widget. +/// +/// Slivers are special-purpose widgets that can be combined using a +/// [CustomScrollView] to create custom scroll effects. A [SliverToBoxAdapter] +/// is a basic sliver that creates a bridge back to one of the usual box-based +/// widgets. +/// +/// _To learn more about slivers, see [CustomScrollView.slivers]._ +/// +/// Rather than using multiple [SliverToBoxAdapter] widgets to display multiple +/// box widgets in a [CustomScrollView], consider using [SliverList], +/// [SliverFixedExtentList], [SliverPrototypeExtentList], or [SliverGrid], +/// which are more efficient because they instantiate only those children that +/// are actually visible through the scroll view's viewport. +/// +/// See also: +/// +/// * [CustomScrollView], which displays a scrollable list of slivers. +/// * [SliverList], which displays multiple box widgets in a linear array. +/// * [SliverFixedExtentList], which displays multiple box widgets with the +/// same main-axis extent in a linear array. +/// * [SliverPrototypeExtentList], which displays multiple box widgets with the +/// same main-axis extent as a prototype item, in a linear array. +/// * [SliverGrid], which displays multiple box widgets in arbitrary positions. +class SliverToBoxAdapter extends SingleChildRenderObjectWidget { + /// Creates a sliver that contains a single box widget. + const SliverToBoxAdapter({ + super.key, + super.child, + }); + + @override + RenderSliverToBoxAdapter createRenderObject(BuildContext context) => RenderSliverToBoxAdapter(); +} + +/// A sliver that applies padding on each side of another sliver. +/// +/// Slivers are special-purpose widgets that can be combined using a +/// [CustomScrollView] to create custom scroll effects. A [SliverPadding] +/// is a basic sliver that insets another sliver by applying padding on each +/// side. +/// +/// {@macro flutter.rendering.RenderSliverEdgeInsetsPadding} +/// +/// See also: +/// +/// * [CustomScrollView], which displays a scrollable list of slivers. +/// * [Padding], the box version of this widget. +class SliverPadding extends SingleChildRenderObjectWidget { + /// Creates a sliver that applies padding on each side of another sliver. + const SliverPadding({ + super.key, + required this.padding, + Widget? sliver, + }) : super(child: sliver); + + /// The amount of space by which to inset the child sliver. + final EdgeInsetsGeometry padding; + + @override + RenderSliverPadding createRenderObject(BuildContext context) { + return RenderSliverPadding( + padding: padding, + textDirection: Directionality.of(context), + ); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverPadding renderObject) { + renderObject + ..padding = padding + ..textDirection = Directionality.of(context); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding)); + } +} + + +// LAYOUT NODES + +/// Returns the [AxisDirection] in the given [Axis] in the current +/// [Directionality] (or the reverse if `reverse` is true). +/// +/// If `axis` is [Axis.vertical], this function returns [AxisDirection.down] +/// unless `reverse` is true, in which case this function returns +/// [AxisDirection.up]. +/// +/// If `axis` is [Axis.horizontal], this function checks the current +/// [Directionality]. If the current [Directionality] is right-to-left, then +/// this function returns [AxisDirection.left] (unless `reverse` is true, in +/// which case it returns [AxisDirection.right]). Similarly, if the current +/// [Directionality] is left-to-right, then this function returns +/// [AxisDirection.right] (unless `reverse` is true, in which case it returns +/// [AxisDirection.left]). +/// +/// This function is used by a number of scrolling widgets (e.g., [ListView], +/// [GridView], [PageView], and [SingleChildScrollView]) as well as [ListBody] +/// to translate their [Axis] and `reverse` properties into a concrete +/// [AxisDirection]. +AxisDirection getAxisDirectionFromAxisReverseAndDirectionality( + BuildContext context, + Axis axis, + bool reverse, +) { + switch (axis) { + case Axis.horizontal: + assert(debugCheckHasDirectionality(context)); + final TextDirection textDirection = Directionality.of(context); + final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection); + return reverse ? flipAxisDirection(axisDirection) : axisDirection; + case Axis.vertical: + return reverse ? AxisDirection.up : AxisDirection.down; + } +} + +/// A widget that arranges its children sequentially along a given axis, forcing +/// them to the dimension of the parent in the other axis. +/// +/// This widget is rarely used directly. Instead, consider using [ListView], +/// which combines a similar layout algorithm with scrolling behavior, or +/// [Column], which gives you more flexible control over the layout of a +/// vertical set of boxes. +/// +/// See also: +/// +/// * [RenderListBody], which implements this layout algorithm and the +/// documentation for which describes some of its subtleties. +/// * [SingleChildScrollView], which is sometimes used with [ListBody] to +/// make the contents scrollable. +/// * [Column] and [Row], which implement a more elaborate version of +/// this layout algorithm (at the cost of being slightly less efficient). +/// * [ListView], which implements an efficient scrolling version of this +/// layout algorithm. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class ListBody extends MultiChildRenderObjectWidget { + /// Creates a layout widget that arranges its children sequentially along a + /// given axis. + /// + /// By default, the [mainAxis] is [Axis.vertical]. + const ListBody({ + super.key, + this.mainAxis = Axis.vertical, + this.reverse = false, + super.children, + }); + + /// The direction to use as the main axis. + final Axis mainAxis; + + /// Whether the list body positions children in the reading direction. + /// + /// For example, if the reading direction is left-to-right and + /// [mainAxis] is [Axis.horizontal], then the list body positions children + /// from left to right when [reverse] is false and from right to left when + /// [reverse] is true. + /// + /// Similarly, if [mainAxis] is [Axis.vertical], then the list body positions + /// from top to bottom when [reverse] is false and from bottom to top when + /// [reverse] is true. + /// + /// Defaults to false. + final bool reverse; + + AxisDirection _getDirection(BuildContext context) { + return getAxisDirectionFromAxisReverseAndDirectionality(context, mainAxis, reverse); + } + + @override + RenderListBody createRenderObject(BuildContext context) { + return RenderListBody(axisDirection: _getDirection(context)); + } + + @override + void updateRenderObject(BuildContext context, RenderListBody renderObject) { + renderObject.axisDirection = _getDirection(context); + } +} + +/// A widget that positions its children relative to the edges of its box. +/// +/// This class is useful if you want to overlap several children in a simple +/// way, for example having some text and an image, overlaid with a gradient and +/// a button attached to the bottom. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=liEGSeD3Zt8} +/// +/// Each child of a [Stack] widget is either _positioned_ or _non-positioned_. +/// Positioned children are those wrapped in a [Positioned] widget that has at +/// least one non-null property. The stack sizes itself to contain all the +/// non-positioned children, which are positioned according to [alignment] +/// (which defaults to the top-left corner in left-to-right environments and the +/// top-right corner in right-to-left environments). The positioned children are +/// then placed relative to the stack according to their top, right, bottom, and +/// left properties. +/// +/// The stack paints its children in order with the first child being at the +/// bottom. If you want to change the order in which the children paint, you +/// can rebuild the stack with the children in the new order. If you reorder +/// the children in this way, consider giving the children non-null keys. +/// These keys will cause the framework to move the underlying objects for +/// the children to their new locations rather than recreate them at their +/// new location. +/// +/// For more details about the stack layout algorithm, see [RenderStack]. +/// +/// If you want to lay a number of children out in a particular pattern, or if +/// you want to make a custom layout manager, you probably want to use +/// [CustomMultiChildLayout] instead. In particular, when using a [Stack] you +/// can't position children relative to their size or the stack's own size. +/// +/// {@tool snippet} +/// +/// Using a [Stack] you can position widgets over one another. +/// +/// ![The sample creates a blue box that overlaps a larger green box, which itself overlaps an even larger red box.](https://flutter.github.io/assets-for-api-docs/assets/widgets/stack.png) +/// +/// ```dart +/// Stack( +/// children: <Widget>[ +/// Container( +/// width: 100, +/// height: 100, +/// color: Colors.red, +/// ), +/// Container( +/// width: 90, +/// height: 90, +/// color: Colors.green, +/// ), +/// Container( +/// width: 80, +/// height: 80, +/// color: Colors.blue, +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// +/// This example shows how [Stack] can be used to enhance text visibility +/// by adding gradient backdrops. +/// +/// ![The gradient fades from transparent to dark grey at the bottom, with white text on top of the darker portion.](https://flutter.github.io/assets-for-api-docs/assets/widgets/stack_with_gradient.png) +/// +/// ```dart +/// SizedBox( +/// width: 250, +/// height: 250, +/// child: Stack( +/// children: <Widget>[ +/// Container( +/// width: 250, +/// height: 250, +/// color: Colors.white, +/// ), +/// Container( +/// padding: const EdgeInsets.all(5.0), +/// alignment: Alignment.bottomCenter, +/// decoration: BoxDecoration( +/// gradient: LinearGradient( +/// begin: Alignment.topCenter, +/// end: Alignment.bottomCenter, +/// colors: <Color>[ +/// Colors.black.withAlpha(0), +/// Colors.black12, +/// Colors.black45 +/// ], +/// ), +/// ), +/// child: const Text( +/// 'Foreground Text', +/// style: TextStyle(color: Colors.white, fontSize: 20.0), +/// ), +/// ), +/// ], +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Align], which sizes itself based on its child's size and positions +/// the child according to an [Alignment] value. +/// * [CustomSingleChildLayout], which uses a delegate to control the layout of +/// a single child. +/// * [CustomMultiChildLayout], which uses a delegate to position multiple +/// children. +/// * [Flow], which provides paint-time control of its children using transform +/// matrices. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Stack extends MultiChildRenderObjectWidget { + /// Creates a stack layout widget. + /// + /// By default, the non-positioned children of the stack are aligned by their + /// top left corners. + const Stack({ + super.key, + this.alignment = AlignmentDirectional.topStart, + this.textDirection, + this.fit = StackFit.loose, + this.clipBehavior = Clip.hardEdge, + super.children, + }); + + /// How to align the non-positioned and partially-positioned children in the + /// stack. + /// + /// The non-positioned children are placed relative to each other such that + /// the points determined by [alignment] are co-located. For example, if the + /// [alignment] is [Alignment.topLeft], then the top left corner of + /// each non-positioned child will be located at the same global coordinate. + /// + /// Partially-positioned children, those that do not specify an alignment in a + /// particular axis (e.g. that have neither `top` nor `bottom` set), use the + /// alignment to determine how they should be positioned in that + /// under-specified axis. + /// + /// Defaults to [AlignmentDirectional.topStart]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// The text direction with which to resolve [alignment]. + /// + /// Defaults to the ambient [Directionality]. + final TextDirection? textDirection; + + /// How to size the non-positioned children in the stack. + /// + /// The constraints passed into the [Stack] from its parent are either + /// loosened ([StackFit.loose]) or tightened to their biggest size + /// ([StackFit.expand]). + final StackFit fit; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Stacks only clip children whose _geometry_ overflows the stack. A child + /// that paints outside its bounds (e.g. a box with a shadow) will not be + /// clipped, regardless of the value of this property. Similarly, a child that + /// itself has a descendant that overflows the stack will not be clipped, as + /// only the geometry of the stack's direct children are considered. + /// [Transform] is an example of a widget that can cause its children to paint + /// outside its geometry. + /// + /// To clip children whose geometry does not overflow the stack, consider + /// using a [ClipRect] widget. + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + bool _debugCheckHasDirectionality(BuildContext context) { + if (alignment is AlignmentDirectional && textDirection == null) { + assert(debugCheckHasDirectionality( + context, + why: "to resolve the 'alignment' argument", + hint: alignment == AlignmentDirectional.topStart ? "The default value for 'alignment' is AlignmentDirectional.topStart, which requires a text direction." : null, + alternative: "Instead of providing a Directionality widget, another solution would be passing a non-directional 'alignment', or an explicit 'textDirection', to the $runtimeType.", + )); + } + return true; + } + + @override + RenderStack createRenderObject(BuildContext context) { + assert(_debugCheckHasDirectionality(context)); + return RenderStack( + alignment: alignment, + textDirection: textDirection ?? Directionality.maybeOf(context), + fit: fit, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderStack renderObject) { + assert(_debugCheckHasDirectionality(context)); + renderObject + ..alignment = alignment + ..textDirection = textDirection ?? Directionality.maybeOf(context) + ..fit = fit + ..clipBehavior = clipBehavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(EnumProperty<StackFit>('fit', fit)); + properties.add(EnumProperty<Clip>('clipBehavior', clipBehavior, defaultValue: Clip.hardEdge)); + } +} + +/// A [Stack] that shows a single child from a list of children. +/// +/// The displayed child is the one with the given [index]. The stack is +/// always as big as the largest child. +/// +/// If value is null, then nothing is displayed. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=_O0PPD1Xfbk} +/// +/// {@tool dartpad} +/// This example shows a [IndexedStack] widget being used to lay out one card +/// at a time from a series of cards, each keeping their respective states. +/// +/// ** See code in examples/api/lib/widgets/basic/indexed_stack.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Stack], for more details about stacks. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class IndexedStack extends StatelessWidget { + /// Creates a [Stack] widget that paints a single child. + const IndexedStack({ + super.key, + this.alignment = AlignmentDirectional.topStart, + this.textDirection, + this.clipBehavior = Clip.hardEdge, + this.sizing = StackFit.loose, + this.index = 0, + this.children = const <Widget>[], + }); + + /// How to align the non-positioned and partially-positioned children in the + /// stack. + /// + /// Defaults to [AlignmentDirectional.topStart]. + /// + /// See [Stack.alignment] for more information. + final AlignmentGeometry alignment; + + /// The text direction with which to resolve [alignment]. + /// + /// Defaults to the ambient [Directionality]. + final TextDirection? textDirection; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// How to size the non-positioned children in the stack. + /// + /// Defaults to [StackFit.loose]. + /// + /// See [Stack.fit] for more information. + final StackFit sizing; + + /// The index of the child to show. + /// + /// If this is null, none of the children will be shown. + final int? index; + + /// The child widgets of the stack. + /// + /// Only the child at index [index] will be shown. + /// + /// See [Stack.children] for more information. + final List<Widget> children; + + @override + Widget build(BuildContext context) { + final List<Widget> wrappedChildren = List<Widget>.generate(children.length, (int i) { + return Visibility.maintain( + visible: i == index, + child: children[i], + ); + }); + return _RawIndexedStack( + alignment: alignment, + textDirection: textDirection, + clipBehavior: clipBehavior, + sizing: sizing, + index: index, + children: wrappedChildren, + ); + } +} + +/// The render object widget that backs [IndexedStack]. +class _RawIndexedStack extends Stack { + /// Creates a [Stack] widget that paints a single child. + const _RawIndexedStack({ + super.alignment, + super.textDirection, + super.clipBehavior, + StackFit sizing = StackFit.loose, + this.index = 0, + super.children, + }) : super(fit: sizing); + + /// The index of the child to show. + final int? index; + + @override + RenderIndexedStack createRenderObject(BuildContext context) { + assert(_debugCheckHasDirectionality(context)); + return RenderIndexedStack( + index: index, + fit: fit, + clipBehavior: clipBehavior, + alignment: alignment, + textDirection: textDirection ?? Directionality.maybeOf(context), + ); + } + + @override + void updateRenderObject(BuildContext context, RenderIndexedStack renderObject) { + assert(_debugCheckHasDirectionality(context)); + renderObject + ..index = index + ..fit = fit + ..clipBehavior = clipBehavior + ..alignment = alignment + ..textDirection = textDirection ?? Directionality.maybeOf(context); + } + + @override + MultiChildRenderObjectElement createElement() { + return _IndexedStackElement(this); + } +} + +class _IndexedStackElement extends MultiChildRenderObjectElement { + _IndexedStackElement(_RawIndexedStack super.widget); + + @override + _RawIndexedStack get widget => super.widget as _RawIndexedStack; + + @override + void debugVisitOnstageChildren(ElementVisitor visitor) { + final int? index = widget.index; + // If the index is null, no child is onstage. Otherwise, only the child at + // the selected index is. + if (index != null && children.isNotEmpty) { + visitor(children.elementAt(index)); + } + } +} + +/// A widget that controls where a child of a [Stack] is positioned. +/// +/// A [Positioned] widget must be a descendant of a [Stack], and the path from +/// the [Positioned] widget to its enclosing [Stack] must contain only +/// [StatelessWidget]s or [StatefulWidget]s (not other kinds of widgets, like +/// [RenderObjectWidget]s). +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=EgtPleVwxBQ} +/// +/// If a widget is wrapped in a [Positioned], then it is a _positioned_ widget +/// in its [Stack]. If the [top] property is non-null, the top edge of this child +/// will be positioned [top] layout units from the top of the stack widget. The +/// [right], [bottom], and [left] properties work analogously. +/// +/// If both the [top] and [bottom] properties are non-null, then the child will +/// be forced to have exactly the height required to satisfy both constraints. +/// Similarly, setting the [right] and [left] properties to non-null values will +/// force the child to have a particular width. Alternatively the [width] and +/// [height] properties can be used to give the dimensions, with one +/// corresponding position property (e.g. [top] and [height]). +/// +/// If all three values on a particular axis are null, then the +/// [Stack.alignment] property is used to position the child. +/// +/// If all six values are null, the child is a non-positioned child. The [Stack] +/// uses only the non-positioned children to size itself. +/// +/// See also: +/// +/// * [AnimatedPositioned], which automatically transitions the child's +/// position over a given duration whenever the given position changes. +/// * [PositionedTransition], which takes a provided [Animation] to transition +/// changes in the child's position over a given duration. +/// * [PositionedDirectional], which adapts to the ambient [Directionality]. +class Positioned extends ParentDataWidget<StackParentData> { + /// Creates a widget that controls where a child of a [Stack] is positioned. + /// + /// Only two out of the three horizontal values ([left], [right], + /// [width]), and only two out of the three vertical values ([top], + /// [bottom], [height]), can be set. In each case, at least one of + /// the three must be null. + /// + /// See also: + /// + /// * [Positioned.directional], which specifies the widget's horizontal + /// position using `start` and `end` rather than `left` and `right`. + /// * [PositionedDirectional], which is similar to [Positioned.directional] + /// but adapts to the ambient [Directionality]. + const Positioned({ + super.key, + this.left, + this.top, + this.right, + this.bottom, + this.width, + this.height, + required super.child, + }) : assert(left == null || right == null || width == null), + assert(top == null || bottom == null || height == null); + + /// Creates a Positioned object with the values from the given [Rect]. + /// + /// This sets the [left], [top], [width], and [height] properties + /// from the given [Rect]. The [right] and [bottom] properties are + /// set to null. + Positioned.fromRect({ + super.key, + required Rect rect, + required super.child, + }) : left = rect.left, + top = rect.top, + width = rect.width, + height = rect.height, + right = null, + bottom = null; + + /// Creates a Positioned object with the values from the given [RelativeRect]. + /// + /// This sets the [left], [top], [right], and [bottom] properties from the + /// given [RelativeRect]. The [height] and [width] properties are set to null. + Positioned.fromRelativeRect({ + super.key, + required RelativeRect rect, + required super.child, + }) : left = rect.left, + top = rect.top, + right = rect.right, + bottom = rect.bottom, + width = null, + height = null; + + /// Creates a Positioned object with [left], [top], [right], and [bottom] set + /// to 0.0 unless a value for them is passed. + const Positioned.fill({ + super.key, + this.left = 0.0, + this.top = 0.0, + this.right = 0.0, + this.bottom = 0.0, + required super.child, + }) : width = null, + height = null; + + /// Creates a widget that controls where a child of a [Stack] is positioned. + /// + /// Only two out of the three horizontal values (`start`, `end`, + /// [width]), and only two out of the three vertical values ([top], + /// [bottom], [height]), can be set. In each case, at least one of + /// the three must be null. + /// + /// If `textDirection` is [TextDirection.rtl], then the `start` argument is + /// used for the [right] property and the `end` argument is used for the + /// [left] property. Otherwise, if `textDirection` is [TextDirection.ltr], + /// then the `start` argument is used for the [left] property and the `end` + /// argument is used for the [right] property. + /// + /// See also: + /// + /// * [PositionedDirectional], which adapts to the ambient [Directionality]. + factory Positioned.directional({ + Key? key, + required TextDirection textDirection, + double? start, + double? top, + double? end, + double? bottom, + double? width, + double? height, + required Widget child, + }) { + double? left; + double? right; + switch (textDirection) { + case TextDirection.rtl: + left = end; + right = start; + case TextDirection.ltr: + left = start; + right = end; + } + return Positioned( + key: key, + left: left, + top: top, + right: right, + bottom: bottom, + width: width, + height: height, + child: child, + ); + } + + /// The distance that the child's left edge is inset from the left of the stack. + /// + /// Only two out of the three horizontal values ([left], [right], [width]) can be + /// set. The third must be null. + /// + /// If all three are null, the [Stack.alignment] is used to position the child + /// horizontally. + final double? left; + + /// The distance that the child's top edge is inset from the top of the stack. + /// + /// Only two out of the three vertical values ([top], [bottom], [height]) can be + /// set. The third must be null. + /// + /// If all three are null, the [Stack.alignment] is used to position the child + /// vertically. + final double? top; + + /// The distance that the child's right edge is inset from the right of the stack. + /// + /// Only two out of the three horizontal values ([left], [right], [width]) can be + /// set. The third must be null. + /// + /// If all three are null, the [Stack.alignment] is used to position the child + /// horizontally. + final double? right; + + /// The distance that the child's bottom edge is inset from the bottom of the stack. + /// + /// Only two out of the three vertical values ([top], [bottom], [height]) can be + /// set. The third must be null. + /// + /// If all three are null, the [Stack.alignment] is used to position the child + /// vertically. + final double? bottom; + + /// The child's width. + /// + /// Only two out of the three horizontal values ([left], [right], [width]) can be + /// set. The third must be null. + /// + /// If all three are null, the [Stack.alignment] is used to position the child + /// horizontally. + final double? width; + + /// The child's height. + /// + /// Only two out of the three vertical values ([top], [bottom], [height]) can be + /// set. The third must be null. + /// + /// If all three are null, the [Stack.alignment] is used to position the child + /// vertically. + final double? height; + + @override + void applyParentData(RenderObject renderObject) { + assert(renderObject.parentData is StackParentData); + final StackParentData parentData = renderObject.parentData! as StackParentData; + bool needsLayout = false; + + if (parentData.left != left) { + parentData.left = left; + needsLayout = true; + } + + if (parentData.top != top) { + parentData.top = top; + needsLayout = true; + } + + if (parentData.right != right) { + parentData.right = right; + needsLayout = true; + } + + if (parentData.bottom != bottom) { + parentData.bottom = bottom; + needsLayout = true; + } + + if (parentData.width != width) { + parentData.width = width; + needsLayout = true; + } + + if (parentData.height != height) { + parentData.height = height; + needsLayout = true; + } + + if (needsLayout) { + final RenderObject? targetParent = renderObject.parent; + if (targetParent is RenderObject) { + targetParent.markNeedsLayout(); + } + } + } + + @override + Type get debugTypicalAncestorWidgetClass => Stack; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('left', left, defaultValue: null)); + properties.add(DoubleProperty('top', top, defaultValue: null)); + properties.add(DoubleProperty('right', right, defaultValue: null)); + properties.add(DoubleProperty('bottom', bottom, defaultValue: null)); + properties.add(DoubleProperty('width', width, defaultValue: null)); + properties.add(DoubleProperty('height', height, defaultValue: null)); + } +} + +/// A widget that controls where a child of a [Stack] is positioned without +/// committing to a specific [TextDirection]. +/// +/// The ambient [Directionality] is used to determine whether [start] is to the +/// left or to the right. +/// +/// A [PositionedDirectional] widget must be a descendant of a [Stack], and the +/// path from the [PositionedDirectional] widget to its enclosing [Stack] must +/// contain only [StatelessWidget]s or [StatefulWidget]s (not other kinds of +/// widgets, like [RenderObjectWidget]s). +/// +/// If a widget is wrapped in a [PositionedDirectional], then it is a +/// _positioned_ widget in its [Stack]. If the [top] property is non-null, the +/// top edge of this child/ will be positioned [top] layout units from the top +/// of the stack widget. The [start], [bottom], and [end] properties work +/// analogously. +/// +/// If both the [top] and [bottom] properties are non-null, then the child will +/// be forced to have exactly the height required to satisfy both constraints. +/// Similarly, setting the [start] and [end] properties to non-null values will +/// force the child to have a particular width. Alternatively the [width] and +/// [height] properties can be used to give the dimensions, with one +/// corresponding position property (e.g. [top] and [height]). +/// +/// See also: +/// +/// * [Positioned], which specifies the widget's position visually. +/// * [Positioned.directional], which also specifies the widget's horizontal +/// position using [start] and [end] but has an explicit [TextDirection]. +/// * [AnimatedPositionedDirectional], which automatically transitions +/// the child's position over a given duration whenever the given position +/// changes. +class PositionedDirectional extends StatelessWidget { + /// Creates a widget that controls where a child of a [Stack] is positioned. + /// + /// Only two out of the three horizontal values (`start`, `end`, + /// [width]), and only two out of the three vertical values ([top], + /// [bottom], [height]), can be set. In each case, at least one of + /// the three must be null. + /// + /// See also: + /// + /// * [Positioned.directional], which also specifies the widget's horizontal + /// position using [start] and [end] but has an explicit [TextDirection]. + const PositionedDirectional({ + super.key, + this.start, + this.top, + this.end, + this.bottom, + this.width, + this.height, + required this.child, + }); + + /// The distance that the child's leading edge is inset from the leading edge + /// of the stack. + /// + /// Only two out of the three horizontal values ([start], [end], [width]) can be + /// set. The third must be null. + final double? start; + + /// The distance that the child's top edge is inset from the top of the stack. + /// + /// Only two out of the three vertical values ([top], [bottom], [height]) can be + /// set. The third must be null. + final double? top; + + /// The distance that the child's trailing edge is inset from the trailing + /// edge of the stack. + /// + /// Only two out of the three horizontal values ([start], [end], [width]) can be + /// set. The third must be null. + final double? end; + + /// The distance that the child's bottom edge is inset from the bottom of the stack. + /// + /// Only two out of the three vertical values ([top], [bottom], [height]) can be + /// set. The third must be null. + final double? bottom; + + /// The child's width. + /// + /// Only two out of the three horizontal values ([start], [end], [width]) can be + /// set. The third must be null. + final double? width; + + /// The child's height. + /// + /// Only two out of the three vertical values ([top], [bottom], [height]) can be + /// set. The third must be null. + final double? height; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + return Positioned.directional( + textDirection: Directionality.of(context), + start: start, + top: top, + end: end, + bottom: bottom, + width: width, + height: height, + child: child, + ); + } +} + +/// A widget that displays its children in a one-dimensional array. +/// +/// The [Flex] widget allows you to control the axis along which the children are +/// placed (horizontal or vertical). This is referred to as the _main axis_. If +/// you know the main axis in advance, then consider using a [Row] (if it's +/// horizontal) or [Column] (if it's vertical) instead, because that will be less +/// verbose. +/// +/// To cause a child to expand to fill the available space in the [direction] +/// of this widget's main axis, wrap the child in an [Expanded] widget. +/// +/// The [Flex] widget does not scroll (and in general it is considered an error +/// to have more children in a [Flex] than will fit in the available room). If +/// you have some widgets and want them to be able to scroll if there is +/// insufficient room, consider using a [ListView]. +/// +/// The [Flex] widget does not allow its children to wrap across multiple +/// horizontal or vertical runs. For a widget that allows its children to wrap, +/// consider using the [Wrap] widget instead of [Flex]. +/// +/// If you only have one child, then rather than using [Flex], [Row], or +/// [Column], consider using [Align] or [Center] to position the child. +/// +/// ## Layout algorithm +/// +/// _This section describes how a [Flex] is rendered by the framework._ +/// _See [BoxConstraints] for an introduction to box layout models._ +/// +/// Layout for a [Flex] proceeds in six steps: +/// +/// 1. Layout each child with a null or zero flex factor (e.g., those that are +/// not [Expanded]) with unbounded main axis constraints and the incoming +/// cross axis constraints. If the [crossAxisAlignment] is +/// [CrossAxisAlignment.stretch], instead use tight cross axis constraints +/// that match the incoming max extent in the cross axis. +/// 2. Divide the remaining main axis space among the children with non-zero +/// flex factors (e.g., those that are [Expanded]) according to their flex +/// factor. For example, a child with a flex factor of 2.0 will receive twice +/// the amount of main axis space as a child with a flex factor of 1.0. +/// 3. Layout each of the remaining children with the same cross axis +/// constraints as in step 1, but instead of using unbounded main axis +/// constraints, use max axis constraints based on the amount of space +/// allocated in step 2. Children with [Flexible.fit] properties that are +/// [FlexFit.tight] are given tight constraints (i.e., forced to fill the +/// allocated space), and children with [Flexible.fit] properties that are +/// [FlexFit.loose] are given loose constraints (i.e., not forced to fill the +/// allocated space). +/// 4. The cross axis extent of the [Flex] is the maximum cross axis extent of +/// the children (which will always satisfy the incoming constraints). +/// 5. The main axis extent of the [Flex] is determined by the [mainAxisSize] +/// property. If the [mainAxisSize] property is [MainAxisSize.max], then the +/// main axis extent of the [Flex] is the max extent of the incoming main +/// axis constraints. If the [mainAxisSize] property is [MainAxisSize.min], +/// then the main axis extent of the [Flex] is the sum of the main axis +/// extents of the children (subject to the incoming constraints). +/// 6. Determine the position for each child according to the +/// [mainAxisAlignment] and the [crossAxisAlignment]. For example, if the +/// [mainAxisAlignment] is [MainAxisAlignment.spaceBetween], any main axis +/// space that has not been allocated to children is divided evenly and +/// placed between the children. +/// +/// See also: +/// +/// * [Row], for a version of this widget that is always horizontal. +/// * [Column], for a version of this widget that is always vertical. +/// * [Expanded], to indicate children that should take all the remaining room. +/// * [Flexible], to indicate children that should share the remaining room. +/// * [Spacer], a widget that takes up space proportional to its flex value. +/// that may be sized smaller (leaving some remaining room unused). +/// * [Wrap], for a widget that allows its children to wrap over multiple _runs_. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Flex extends MultiChildRenderObjectWidget { + /// Creates a flex layout. + /// + /// The [direction] is required. + /// + /// If [crossAxisAlignment] is [CrossAxisAlignment.baseline], then + /// [textBaseline] must not be null. + /// + /// The [textDirection] argument defaults to the ambient [Directionality], if + /// any. If there is no ambient directionality, and a text direction is going + /// to be necessary to decide which direction to lay the children in or to + /// disambiguate `start` or `end` values for the main or cross axis + /// directions, the [textDirection] must not be null. + const Flex({ + super.key, + required this.direction, + this.mainAxisAlignment = MainAxisAlignment.start, + this.mainAxisSize = MainAxisSize.max, + this.crossAxisAlignment = CrossAxisAlignment.center, + this.textDirection, + this.verticalDirection = VerticalDirection.down, + this.textBaseline, // NO DEFAULT: we don't know what the text's baseline should be + this.clipBehavior = Clip.none, + super.children, + }) : assert(!identical(crossAxisAlignment, CrossAxisAlignment.baseline) || textBaseline != null, 'textBaseline is required if you specify the crossAxisAlignment with CrossAxisAlignment.baseline'); + // Cannot use == in the assert above instead of identical because of https://github.com/dart-lang/language/issues/1811. + + /// The direction to use as the main axis. + /// + /// If you know the axis in advance, then consider using a [Row] (if it's + /// horizontal) or [Column] (if it's vertical) instead of a [Flex], since that + /// will be less verbose. (For [Row] and [Column] this property is fixed to + /// the appropriate axis.) + final Axis direction; + + /// How the children should be placed along the main axis. + /// + /// For example, [MainAxisAlignment.start], the default, places the children + /// at the start (i.e., the left for a [Row] or the top for a [Column]) of the + /// main axis. + final MainAxisAlignment mainAxisAlignment; + + /// How much space should be occupied in the main axis. + /// + /// After allocating space to children, there might be some remaining free + /// space. This value controls whether to maximize or minimize the amount of + /// free space, subject to the incoming layout constraints. + /// + /// If some children have a non-zero flex factors (and none have a fit of + /// [FlexFit.loose]), they will expand to consume all the available space and + /// there will be no remaining free space to maximize or minimize, making this + /// value irrelevant to the final layout. + final MainAxisSize mainAxisSize; + + /// How the children should be placed along the cross axis. + /// + /// For example, [CrossAxisAlignment.center], the default, centers the + /// children in the cross axis (e.g., horizontally for a [Column]). + final CrossAxisAlignment crossAxisAlignment; + + /// Determines the order to lay children out horizontally and how to interpret + /// `start` and `end` in the horizontal direction. + /// + /// Defaults to the ambient [Directionality]. + /// + /// If [textDirection] is [TextDirection.rtl], then the direction in which + /// text flows starts from right to left. Otherwise, if [textDirection] is + /// [TextDirection.ltr], then the direction in which text flows starts from + /// left to right. + /// + /// If the [direction] is [Axis.horizontal], this controls the order in which + /// the children are positioned (left-to-right or right-to-left), and the + /// meaning of the [mainAxisAlignment] property's [MainAxisAlignment.start] and + /// [MainAxisAlignment.end] values. + /// + /// If the [direction] is [Axis.horizontal], and either the + /// [mainAxisAlignment] is either [MainAxisAlignment.start] or + /// [MainAxisAlignment.end], or there's more than one child, then the + /// [textDirection] (or the ambient [Directionality]) must not be null. + /// + /// If the [direction] is [Axis.vertical], this controls the meaning of the + /// [crossAxisAlignment] property's [CrossAxisAlignment.start] and + /// [CrossAxisAlignment.end] values. + /// + /// If the [direction] is [Axis.vertical], and the [crossAxisAlignment] is + /// either [CrossAxisAlignment.start] or [CrossAxisAlignment.end], then the + /// [textDirection] (or the ambient [Directionality]) must not be null. + final TextDirection? textDirection; + + /// Determines the order to lay children out vertically and how to interpret + /// `start` and `end` in the vertical direction. + /// + /// Defaults to [VerticalDirection.down]. + /// + /// If the [direction] is [Axis.vertical], this controls which order children + /// are painted in (down or up), the meaning of the [mainAxisAlignment] + /// property's [MainAxisAlignment.start] and [MainAxisAlignment.end] values. + /// + /// If the [direction] is [Axis.vertical], and either the [mainAxisAlignment] + /// is either [MainAxisAlignment.start] or [MainAxisAlignment.end], or there's + /// more than one child, then the [verticalDirection] must not be null. + /// + /// If the [direction] is [Axis.horizontal], this controls the meaning of the + /// [crossAxisAlignment] property's [CrossAxisAlignment.start] and + /// [CrossAxisAlignment.end] values. + /// + /// If the [direction] is [Axis.horizontal], and the [crossAxisAlignment] is + /// either [CrossAxisAlignment.start] or [CrossAxisAlignment.end], then the + /// [verticalDirection] must not be null. + final VerticalDirection verticalDirection; + + /// If aligning items according to their baseline, which baseline to use. + /// + /// This must be set if using baseline alignment. There is no default because there is no + /// way for the framework to know the correct baseline _a priori_. + final TextBaseline? textBaseline; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + bool get _needTextDirection { + switch (direction) { + case Axis.horizontal: + return true; // because it affects the layout order. + case Axis.vertical: + return crossAxisAlignment == CrossAxisAlignment.start + || crossAxisAlignment == CrossAxisAlignment.end; + } + } + + /// The value to pass to [RenderFlex.textDirection]. + /// + /// This value is derived from the [textDirection] property and the ambient + /// [Directionality]. The value is null if there is no need to specify the + /// text direction. In practice there's always a need to specify the direction + /// except for vertical flexes (e.g. [Column]s) whose [crossAxisAlignment] is + /// not dependent on the text direction (not `start` or `end`). In particular, + /// a [Row] always needs a text direction because the text direction controls + /// its layout order. (For [Column]s, the layout order is controlled by + /// [verticalDirection], which is always specified as it does not depend on an + /// inherited widget and defaults to [VerticalDirection.down].) + /// + /// This method exists so that subclasses of [Flex] that create their own + /// render objects that are derived from [RenderFlex] can do so and still use + /// the logic for providing a text direction only when it is necessary. + @protected + TextDirection? getEffectiveTextDirection(BuildContext context) { + return textDirection ?? (_needTextDirection ? Directionality.maybeOf(context) : null); + } + + @override + RenderFlex createRenderObject(BuildContext context) { + return RenderFlex( + direction: direction, + mainAxisAlignment: mainAxisAlignment, + mainAxisSize: mainAxisSize, + crossAxisAlignment: crossAxisAlignment, + textDirection: getEffectiveTextDirection(context), + verticalDirection: verticalDirection, + textBaseline: textBaseline, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, covariant RenderFlex renderObject) { + renderObject + ..direction = direction + ..mainAxisAlignment = mainAxisAlignment + ..mainAxisSize = mainAxisSize + ..crossAxisAlignment = crossAxisAlignment + ..textDirection = getEffectiveTextDirection(context) + ..verticalDirection = verticalDirection + ..textBaseline = textBaseline + ..clipBehavior = clipBehavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<Axis>('direction', direction)); + properties.add(EnumProperty<MainAxisAlignment>('mainAxisAlignment', mainAxisAlignment)); + properties.add(EnumProperty<MainAxisSize>('mainAxisSize', mainAxisSize, defaultValue: MainAxisSize.max)); + properties.add(EnumProperty<CrossAxisAlignment>('crossAxisAlignment', crossAxisAlignment)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(EnumProperty<VerticalDirection>('verticalDirection', verticalDirection, defaultValue: VerticalDirection.down)); + properties.add(EnumProperty<TextBaseline>('textBaseline', textBaseline, defaultValue: null)); + } +} + +/// A widget that displays its children in a horizontal array. +/// +/// To cause a child to expand to fill the available horizontal space, wrap the +/// child in an [Expanded] widget. +/// +/// The [Row] widget does not scroll (and in general it is considered an error +/// to have more children in a [Row] than will fit in the available room). If +/// you have a line of widgets and want them to be able to scroll if there is +/// insufficient room, consider using a [ListView]. +/// +/// For a vertical variant, see [Column]. +/// +/// If you only have one child, then consider using [Align] or [Center] to +/// position the child. +/// +/// {@tool snippet} +/// +/// This example divides the available space into three (horizontally), and +/// places text centered in the first two cells and the Flutter logo centered in +/// the third: +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/row.png) +/// +/// ```dart +/// const Row( +/// children: <Widget>[ +/// Expanded( +/// child: Text('Deliver features faster', textAlign: TextAlign.center), +/// ), +/// Expanded( +/// child: Text('Craft beautiful UIs', textAlign: TextAlign.center), +/// ), +/// Expanded( +/// child: FittedBox( +/// child: FlutterLogo(), +/// ), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Troubleshooting +/// +/// ### Why does my row have a yellow and black warning stripe? +/// +/// If the non-flexible contents of the row (those that are not wrapped in +/// [Expanded] or [Flexible] widgets) are together wider than the row itself, +/// then the row is said to have overflowed. When a row overflows, the row does +/// not have any remaining space to share between its [Expanded] and [Flexible] +/// children. The row reports this by drawing a yellow and black striped +/// warning box on the edge that is overflowing. If there is room on the outside +/// of the row, the amount of overflow is printed in red lettering. +/// +/// #### Story time +/// +/// Suppose, for instance, that you had this code: +/// +/// ```dart +/// const Row( +/// children: <Widget>[ +/// FlutterLogo(), +/// Text("Flutter's hot reload helps you quickly and easily experiment, build UIs, add features, and fix bug faster. Experience sub-second reload times, without losing state, on emulators, simulators, and hardware for iOS and Android."), +/// Icon(Icons.sentiment_very_satisfied), +/// ], +/// ) +/// ``` +/// +/// The row first asks its first child, the [FlutterLogo], to lay out, at +/// whatever size the logo would like. The logo is friendly and happily decides +/// to be 24 pixels to a side. This leaves lots of room for the next child. The +/// row then asks that next child, the text, to lay out, at whatever size it +/// thinks is best. +/// +/// At this point, the text, not knowing how wide is too wide, says "Ok, I will +/// be thiiiiiiiiiiiiiiiiiiiis wide.", and goes well beyond the space that the +/// row has available, not wrapping. The row responds, "That's not fair, now I +/// have no more room available for my other children!", and gets angry and +/// sprouts a yellow and black strip. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/row_error.png) +/// +/// The fix is to wrap the second child in an [Expanded] widget, which tells the +/// row that the child should be given the remaining room: +/// +/// ```dart +/// const Row( +/// children: <Widget>[ +/// FlutterLogo(), +/// Expanded( +/// child: Text("Flutter's hot reload helps you quickly and easily experiment, build UIs, add features, and fix bug faster. Experience sub-second reload times, without losing state, on emulators, simulators, and hardware for iOS and Android."), +/// ), +/// Icon(Icons.sentiment_very_satisfied), +/// ], +/// ) +/// ``` +/// +/// Now, the row first asks the logo to lay out, and then asks the _icon_ to lay +/// out. The [Icon], like the logo, is happy to take on a reasonable size (also +/// 24 pixels, not coincidentally, since both [FlutterLogo] and [Icon] honor the +/// ambient [IconTheme]). This leaves some room left over, and now the row tells +/// the text exactly how wide to be: the exact width of the remaining space. The +/// text, now happy to comply to a reasonable request, wraps the text within +/// that width, and you end up with a paragraph split over several lines. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/row_fixed.png) +/// +/// The [textDirection] property controls the direction that children are rendered in. +/// [TextDirection.ltr] is the default [textDirection] of [Row] children, so the first +/// child is rendered at the `start` of the [Row], to the left, with subsequent children +/// following to the right. If you want to order children in the opposite +/// direction (right to left), then [textDirection] can be set to +/// [TextDirection.rtl]. This is shown in the example below +/// +/// ```dart +/// const Row( +/// textDirection: TextDirection.rtl, +/// children: <Widget>[ +/// FlutterLogo(), +/// Expanded( +/// child: Text("Flutter's hot reload helps you quickly and easily experiment, build UIs, add features, and fix bug faster. Experience sub-second reload times, without losing state, on emulators, simulators, and hardware for iOS and Android."), +/// ), +/// Icon(Icons.sentiment_very_satisfied), +/// ], +/// ) +/// ``` +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/row_textDirection.png) +/// +/// ## Layout algorithm +/// +/// _This section describes how a [Row] is rendered by the framework._ +/// _See [BoxConstraints] for an introduction to box layout models._ +/// +/// Layout for a [Row] proceeds in six steps: +/// +/// 1. Layout each child with a null or zero flex factor (e.g., those that are +/// not [Expanded]) with unbounded horizontal constraints and the incoming +/// vertical constraints. If the [crossAxisAlignment] is +/// [CrossAxisAlignment.stretch], instead use tight vertical constraints that +/// match the incoming max height. +/// 2. Divide the remaining horizontal space among the children with non-zero +/// flex factors (e.g., those that are [Expanded]) according to their flex +/// factor. For example, a child with a flex factor of 2.0 will receive twice +/// the amount of horizontal space as a child with a flex factor of 1.0. +/// 3. Layout each of the remaining children with the same vertical constraints +/// as in step 1, but instead of using unbounded horizontal constraints, use +/// horizontal constraints based on the amount of space allocated in step 2. +/// Children with [Flexible.fit] properties that are [FlexFit.tight] are +/// given tight constraints (i.e., forced to fill the allocated space), and +/// children with [Flexible.fit] properties that are [FlexFit.loose] are +/// given loose constraints (i.e., not forced to fill the allocated space). +/// 4. The height of the [Row] is the maximum height of the children (which will +/// always satisfy the incoming vertical constraints). +/// 5. The width of the [Row] is determined by the [mainAxisSize] property. If +/// the [mainAxisSize] property is [MainAxisSize.max], then the width of the +/// [Row] is the max width of the incoming constraints. If the [mainAxisSize] +/// property is [MainAxisSize.min], then the width of the [Row] is the sum +/// of widths of the children (subject to the incoming constraints). +/// 6. Determine the position for each child according to the +/// [mainAxisAlignment] and the [crossAxisAlignment]. For example, if the +/// [mainAxisAlignment] is [MainAxisAlignment.spaceBetween], any horizontal +/// space that has not been allocated to children is divided evenly and +/// placed between the children. +/// +/// See also: +/// +/// * [Column], for a vertical equivalent. +/// * [Flex], if you don't know in advance if you want a horizontal or vertical +/// arrangement. +/// * [Expanded], to indicate children that should take all the remaining room. +/// * [Flexible], to indicate children that should share the remaining room but +/// that may by sized smaller (leaving some remaining room unused). +/// * [Spacer], a widget that takes up space proportional to its flex value. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Row extends Flex { + /// Creates a horizontal array of children. + /// + /// If [crossAxisAlignment] is [CrossAxisAlignment.baseline], then + /// [textBaseline] must not be null. + /// + /// The [textDirection] argument defaults to the ambient [Directionality], if + /// any. If there is no ambient directionality, and a text direction is going + /// to be necessary to determine the layout order (which is always the case + /// unless the row has no children or only one child) or to disambiguate + /// `start` or `end` values for the [mainAxisAlignment], the [textDirection] + /// must not be null. + const Row({ + super.key, + super.mainAxisAlignment, + super.mainAxisSize, + super.crossAxisAlignment, + super.textDirection, + super.verticalDirection, + super.textBaseline, // NO DEFAULT: we don't know what the text's baseline should be + super.children, + }) : super( + direction: Axis.horizontal, + ); +} + +/// A widget that displays its children in a vertical array. +/// +/// To cause a child to expand to fill the available vertical space, wrap the +/// child in an [Expanded] widget. +/// +/// The [Column] widget does not scroll (and in general it is considered an error +/// to have more children in a [Column] than will fit in the available room). If +/// you have a line of widgets and want them to be able to scroll if there is +/// insufficient room, consider using a [ListView]. +/// +/// For a horizontal variant, see [Row]. +/// +/// If you only have one child, then consider using [Align] or [Center] to +/// position the child. +/// +/// {@tool snippet} +/// +/// This example uses a [Column] to arrange three widgets vertically, the last +/// being made to fill all the remaining space. +/// +/// ![Using the Column in this way creates two short lines of text with a large Flutter underneath.](https://flutter.github.io/assets-for-api-docs/assets/widgets/column.png) +/// +/// ```dart +/// const Column( +/// children: <Widget>[ +/// Text('Deliver features faster'), +/// Text('Craft beautiful UIs'), +/// Expanded( +/// child: FittedBox( +/// child: FlutterLogo(), +/// ), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// In the sample above, the text and the logo are centered on each line. In the +/// following example, the [crossAxisAlignment] is set to +/// [CrossAxisAlignment.start], so that the children are left-aligned. The +/// [mainAxisSize] is set to [MainAxisSize.min], so that the column shrinks to +/// fit the children. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/column_properties.png) +/// +/// ```dart +/// Column( +/// crossAxisAlignment: CrossAxisAlignment.start, +/// mainAxisSize: MainAxisSize.min, +/// children: <Widget>[ +/// const Text('We move under cover and we move as one'), +/// const Text('Through the night, we have one shot to live another day'), +/// const Text('We cannot let a stray gunshot give us away'), +/// const Text('We will fight up close, seize the moment and stay in it'), +/// const Text('It’s either that or meet the business end of a bayonet'), +/// const Text('The code word is ‘Rochambeau,’ dig me?'), +/// Text('Rochambeau!', style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 2.0)), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Troubleshooting +/// +/// ### When the incoming vertical constraints are unbounded +/// +/// When a [Column] has one or more [Expanded] or [Flexible] children, and is +/// placed in another [Column], or in a [ListView], or in some other context +/// that does not provide a maximum height constraint for the [Column], you will +/// get an exception at runtime saying that there are children with non-zero +/// flex but the vertical constraints are unbounded. +/// +/// The problem, as described in the details that accompany that exception, is +/// that using [Flexible] or [Expanded] means that the remaining space after +/// laying out all the other children must be shared equally, but if the +/// incoming vertical constraints are unbounded, there is infinite remaining +/// space. +/// +/// The key to solving this problem is usually to determine why the [Column] is +/// receiving unbounded vertical constraints. +/// +/// One common reason for this to happen is that the [Column] has been placed in +/// another [Column] (without using [Expanded] or [Flexible] around the inner +/// nested [Column]). When a [Column] lays out its non-flex children (those that +/// have neither [Expanded] or [Flexible] around them), it gives them unbounded +/// constraints so that they can determine their own dimensions (passing +/// unbounded constraints usually signals to the child that it should +/// shrink-wrap its contents). The solution in this case is typically to just +/// wrap the inner column in an [Expanded] to indicate that it should take the +/// remaining space of the outer column, rather than being allowed to take any +/// amount of room it desires. +/// +/// Another reason for this message to be displayed is nesting a [Column] inside +/// a [ListView] or other vertical scrollable. In that scenario, there really is +/// infinite vertical space (the whole point of a vertical scrolling list is to +/// allow infinite space vertically). In such scenarios, it is usually worth +/// examining why the inner [Column] should have an [Expanded] or [Flexible] +/// child: what size should the inner children really be? The solution in this +/// case is typically to remove the [Expanded] or [Flexible] widgets from around +/// the inner children. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=jckqXR5CrPI} +/// +/// For more discussion about constraints, see [BoxConstraints]. +/// +/// ### The yellow and black striped banner +/// +/// When the contents of a [Column] exceed the amount of space available, the +/// [Column] overflows, and the contents are clipped. In debug mode, a yellow +/// and black striped bar is rendered at the overflowing edge to indicate the +/// problem, and a message is printed below the [Column] saying how much +/// overflow was detected. +/// +/// The usual solution is to use a [ListView] rather than a [Column], to enable +/// the contents to scroll when vertical space is limited. +/// +/// ## Layout algorithm +/// +/// _This section describes how a [Column] is rendered by the framework._ +/// _See [BoxConstraints] for an introduction to box layout models._ +/// +/// Layout for a [Column] proceeds in six steps: +/// +/// 1. Layout each child with a null or zero flex factor (e.g., those that are +/// not [Expanded]) with unbounded vertical constraints and the incoming +/// horizontal constraints. If the [crossAxisAlignment] is +/// [CrossAxisAlignment.stretch], instead use tight horizontal constraints +/// that match the incoming max width. +/// 2. Divide the remaining vertical space among the children with non-zero +/// flex factors (e.g., those that are [Expanded]) according to their flex +/// factor. For example, a child with a flex factor of 2.0 will receive twice +/// the amount of vertical space as a child with a flex factor of 1.0. +/// 3. Layout each of the remaining children with the same horizontal +/// constraints as in step 1, but instead of using unbounded vertical +/// constraints, use vertical constraints based on the amount of space +/// allocated in step 2. Children with [Flexible.fit] properties that are +/// [FlexFit.tight] are given tight constraints (i.e., forced to fill the +/// allocated space), and children with [Flexible.fit] properties that are +/// [FlexFit.loose] are given loose constraints (i.e., not forced to fill the +/// allocated space). +/// 4. The width of the [Column] is the maximum width of the children (which +/// will always satisfy the incoming horizontal constraints). +/// 5. The height of the [Column] is determined by the [mainAxisSize] property. +/// If the [mainAxisSize] property is [MainAxisSize.max], then the height of +/// the [Column] is the max height of the incoming constraints. If the +/// [mainAxisSize] property is [MainAxisSize.min], then the height of the +/// [Column] is the sum of heights of the children (subject to the incoming +/// constraints). +/// 6. Determine the position for each child according to the +/// [mainAxisAlignment] and the [crossAxisAlignment]. For example, if the +/// [mainAxisAlignment] is [MainAxisAlignment.spaceBetween], any vertical +/// space that has not been allocated to children is divided evenly and +/// placed between the children. +/// +/// See also: +/// +/// * [Row], for a horizontal equivalent. +/// * [Flex], if you don't know in advance if you want a horizontal or vertical +/// arrangement. +/// * [Expanded], to indicate children that should take all the remaining room. +/// * [Flexible], to indicate children that should share the remaining room but +/// that may size smaller (leaving some remaining room unused). +/// * [SingleChildScrollView], whose documentation discusses some ways to +/// use a [Column] inside a scrolling container. +/// * [Spacer], a widget that takes up space proportional to its flex value. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Column extends Flex { + /// Creates a vertical array of children. + /// + /// If [crossAxisAlignment] is [CrossAxisAlignment.baseline], then + /// [textBaseline] must not be null. + /// + /// The [textDirection] argument defaults to the ambient [Directionality], if + /// any. If there is no ambient directionality, and a text direction is going + /// to be necessary to disambiguate `start` or `end` values for the + /// [crossAxisAlignment], the [textDirection] must not be null. + const Column({ + super.key, + super.mainAxisAlignment, + super.mainAxisSize, + super.crossAxisAlignment, + super.textDirection, + super.verticalDirection, + super.textBaseline, + super.children, + }) : super( + direction: Axis.vertical, + ); +} + +/// A widget that controls how a child of a [Row], [Column], or [Flex] flexes. +/// +/// Using a [Flexible] widget gives a child of a [Row], [Column], or [Flex] +/// the flexibility to expand to fill the available space in the main axis +/// (e.g., horizontally for a [Row] or vertically for a [Column]), but, unlike +/// [Expanded], [Flexible] does not require the child to fill the available +/// space. +/// +/// A [Flexible] widget must be a descendant of a [Row], [Column], or [Flex], +/// and the path from the [Flexible] widget to its enclosing [Row], [Column], or +/// [Flex] must contain only [StatelessWidget]s or [StatefulWidget]s (not other +/// kinds of widgets, like [RenderObjectWidget]s). +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=CI7x0mAZiY0} +/// +/// See also: +/// +/// * [Expanded], which forces the child to expand to fill the available space. +/// * [Spacer], a widget that takes up space proportional to its flex value. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Flexible extends ParentDataWidget<FlexParentData> { + /// Creates a widget that controls how a child of a [Row], [Column], or [Flex] + /// flexes. + const Flexible({ + super.key, + this.flex = 1, + this.fit = FlexFit.loose, + required super.child, + }); + + /// The flex factor to use for this child. + /// + /// If null or zero, the child is inflexible and determines its own size. If + /// non-zero, the amount of space the child's can occupy in the main axis is + /// determined by dividing the free space (after placing the inflexible + /// children) according to the flex factors of the flexible children. + final int flex; + + /// How a flexible child is inscribed into the available space. + /// + /// If [flex] is non-zero, the [fit] determines whether the child fills the + /// space the parent makes available during layout. If the fit is + /// [FlexFit.tight], the child is required to fill the available space. If the + /// fit is [FlexFit.loose], the child can be at most as large as the available + /// space (but is allowed to be smaller). + final FlexFit fit; + + @override + void applyParentData(RenderObject renderObject) { + assert(renderObject.parentData is FlexParentData); + final FlexParentData parentData = renderObject.parentData! as FlexParentData; + bool needsLayout = false; + + if (parentData.flex != flex) { + parentData.flex = flex; + needsLayout = true; + } + + if (parentData.fit != fit) { + parentData.fit = fit; + needsLayout = true; + } + + if (needsLayout) { + final RenderObject? targetParent = renderObject.parent; + if (targetParent is RenderObject) { + targetParent.markNeedsLayout(); + } + } + } + + @override + Type get debugTypicalAncestorWidgetClass => Flex; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('flex', flex)); + } +} + +/// A widget that expands a child of a [Row], [Column], or [Flex] +/// so that the child fills the available space. +/// +/// Using an [Expanded] widget makes a child of a [Row], [Column], or [Flex] +/// expand to fill the available space along the main axis (e.g., horizontally for +/// a [Row] or vertically for a [Column]). If multiple children are expanded, +/// the available space is divided among them according to the [flex] factor. +/// +/// An [Expanded] widget must be a descendant of a [Row], [Column], or [Flex], +/// and the path from the [Expanded] widget to its enclosing [Row], [Column], or +/// [Flex] must contain only [StatelessWidget]s or [StatefulWidget]s (not other +/// kinds of widgets, like [RenderObjectWidget]s). +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=_rnZaagadyo} +/// +/// {@tool dartpad} +/// This example shows how to use an [Expanded] widget in a [Column] so that +/// its middle child, a [Container] here, expands to fill the space. +/// +/// ![This results in two thin blue boxes with a larger amber box in between.](https://flutter.github.io/assets-for-api-docs/assets/widgets/expanded_column.png) +/// +/// ** See code in examples/api/lib/widgets/basic/expanded.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to use an [Expanded] widget in a [Row] with multiple +/// children expanded, utilizing the [flex] factor to prioritize available space. +/// +/// ![This results in a wide amber box, followed by a thin blue box, with a medium width amber box at the end.](https://flutter.github.io/assets-for-api-docs/assets/widgets/expanded_row.png) +/// +/// ** See code in examples/api/lib/widgets/basic/expanded.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Flexible], which does not force the child to fill the available space. +/// * [Spacer], a widget that takes up space proportional to its flex value. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Expanded extends Flexible { + /// Creates a widget that expands a child of a [Row], [Column], or [Flex] + /// so that the child fills the available space along the flex widget's + /// main axis. + const Expanded({ + super.key, + super.flex, + required super.child, + }) : super(fit: FlexFit.tight); +} + +/// A widget that displays its children in multiple horizontal or vertical runs. +/// +/// A [Wrap] lays out each child and attempts to place the child adjacent to the +/// previous child in the main axis, given by [direction], leaving [spacing] +/// space in between. If there is not enough space to fit the child, [Wrap] +/// creates a new _run_ adjacent to the existing children in the cross axis. +/// +/// After all the children have been allocated to runs, the children within the +/// runs are positioned according to the [alignment] in the main axis and +/// according to the [crossAxisAlignment] in the cross axis. +/// +/// The runs themselves are then positioned in the cross axis according to the +/// [runSpacing] and [runAlignment]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=z5iw2SeFx2M} +/// +/// {@tool snippet} +/// +/// This example renders some [Chip]s representing four contacts in a [Wrap] so +/// that they flow across lines as necessary. +/// +/// ```dart +/// Wrap( +/// spacing: 8.0, // gap between adjacent chips +/// runSpacing: 4.0, // gap between lines +/// children: <Widget>[ +/// Chip( +/// avatar: CircleAvatar(backgroundColor: Colors.blue.shade900, child: const Text('AH')), +/// label: const Text('Hamilton'), +/// ), +/// Chip( +/// avatar: CircleAvatar(backgroundColor: Colors.blue.shade900, child: const Text('ML')), +/// label: const Text('Lafayette'), +/// ), +/// Chip( +/// avatar: CircleAvatar(backgroundColor: Colors.blue.shade900, child: const Text('HM')), +/// label: const Text('Mulligan'), +/// ), +/// Chip( +/// avatar: CircleAvatar(backgroundColor: Colors.blue.shade900, child: const Text('JL')), +/// label: const Text('Laurens'), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Row], which places children in one line, and gives control over their +/// alignment and spacing. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Wrap extends MultiChildRenderObjectWidget { + /// Creates a wrap layout. + /// + /// By default, the wrap layout is horizontal and both the children and the + /// runs are aligned to the start. + /// + /// The [textDirection] argument defaults to the ambient [Directionality], if + /// any. If there is no ambient directionality, and a text direction is going + /// to be necessary to decide which direction to lay the children in or to + /// disambiguate `start` or `end` values for the main or cross axis + /// directions, the [textDirection] must not be null. + const Wrap({ + super.key, + this.direction = Axis.horizontal, + this.alignment = WrapAlignment.start, + this.spacing = 0.0, + this.runAlignment = WrapAlignment.start, + this.runSpacing = 0.0, + this.crossAxisAlignment = WrapCrossAlignment.start, + this.textDirection, + this.verticalDirection = VerticalDirection.down, + this.clipBehavior = Clip.none, + super.children, + }); + + /// The direction to use as the main axis. + /// + /// For example, if [direction] is [Axis.horizontal], the default, the + /// children are placed adjacent to one another in a horizontal run until the + /// available horizontal space is consumed, at which point a subsequent + /// children are placed in a new run vertically adjacent to the previous run. + final Axis direction; + + /// How the children within a run should be placed in the main axis. + /// + /// For example, if [alignment] is [WrapAlignment.center], the children in + /// each run are grouped together in the center of their run in the main axis. + /// + /// Defaults to [WrapAlignment.start]. + /// + /// See also: + /// + /// * [runAlignment], which controls how the runs are placed relative to each + /// other in the cross axis. + /// * [crossAxisAlignment], which controls how the children within each run + /// are placed relative to each other in the cross axis. + final WrapAlignment alignment; + + /// How much space to place between children in a run in the main axis. + /// + /// For example, if [spacing] is 10.0, the children will be spaced at least + /// 10.0 logical pixels apart in the main axis. + /// + /// If there is additional free space in a run (e.g., because the wrap has a + /// minimum size that is not filled or because some runs are longer than + /// others), the additional free space will be allocated according to the + /// [alignment]. + /// + /// Defaults to 0.0. + final double spacing; + + /// How the runs themselves should be placed in the cross axis. + /// + /// For example, if [runAlignment] is [WrapAlignment.center], the runs are + /// grouped together in the center of the overall [Wrap] in the cross axis. + /// + /// Defaults to [WrapAlignment.start]. + /// + /// See also: + /// + /// * [alignment], which controls how the children within each run are placed + /// relative to each other in the main axis. + /// * [crossAxisAlignment], which controls how the children within each run + /// are placed relative to each other in the cross axis. + final WrapAlignment runAlignment; + + /// How much space to place between the runs themselves in the cross axis. + /// + /// For example, if [runSpacing] is 10.0, the runs will be spaced at least + /// 10.0 logical pixels apart in the cross axis. + /// + /// If there is additional free space in the overall [Wrap] (e.g., because + /// the wrap has a minimum size that is not filled), the additional free space + /// will be allocated according to the [runAlignment]. + /// + /// Defaults to 0.0. + final double runSpacing; + + /// How the children within a run should be aligned relative to each other in + /// the cross axis. + /// + /// For example, if this is set to [WrapCrossAlignment.end], and the + /// [direction] is [Axis.horizontal], then the children within each + /// run will have their bottom edges aligned to the bottom edge of the run. + /// + /// Defaults to [WrapCrossAlignment.start]. + /// + /// See also: + /// + /// * [alignment], which controls how the children within each run are placed + /// relative to each other in the main axis. + /// * [runAlignment], which controls how the runs are placed relative to each + /// other in the cross axis. + final WrapCrossAlignment crossAxisAlignment; + + /// Determines the order to lay children out horizontally and how to interpret + /// `start` and `end` in the horizontal direction. + /// + /// Defaults to the ambient [Directionality]. + /// + /// If the [direction] is [Axis.horizontal], this controls order in which the + /// children are positioned (left-to-right or right-to-left), and the meaning + /// of the [alignment] property's [WrapAlignment.start] and + /// [WrapAlignment.end] values. + /// + /// If the [direction] is [Axis.horizontal], and either the + /// [alignment] is either [WrapAlignment.start] or [WrapAlignment.end], or + /// there's more than one child, then the [textDirection] (or the ambient + /// [Directionality]) must not be null. + /// + /// If the [direction] is [Axis.vertical], this controls the order in which + /// runs are positioned, the meaning of the [runAlignment] property's + /// [WrapAlignment.start] and [WrapAlignment.end] values, as well as the + /// [crossAxisAlignment] property's [WrapCrossAlignment.start] and + /// [WrapCrossAlignment.end] values. + /// + /// If the [direction] is [Axis.vertical], and either the + /// [runAlignment] is either [WrapAlignment.start] or [WrapAlignment.end], the + /// [crossAxisAlignment] is either [WrapCrossAlignment.start] or + /// [WrapCrossAlignment.end], or there's more than one child, then the + /// [textDirection] (or the ambient [Directionality]) must not be null. + final TextDirection? textDirection; + + /// Determines the order to lay children out vertically and how to interpret + /// `start` and `end` in the vertical direction. + /// + /// If the [direction] is [Axis.vertical], this controls which order children + /// are painted in (down or up), the meaning of the [alignment] property's + /// [WrapAlignment.start] and [WrapAlignment.end] values. + /// + /// If the [direction] is [Axis.vertical], and either the [alignment] + /// is either [WrapAlignment.start] or [WrapAlignment.end], or there's + /// more than one child, then the [verticalDirection] must not be null. + /// + /// If the [direction] is [Axis.horizontal], this controls the order in which + /// runs are positioned, the meaning of the [runAlignment] property's + /// [WrapAlignment.start] and [WrapAlignment.end] values, as well as the + /// [crossAxisAlignment] property's [WrapCrossAlignment.start] and + /// [WrapCrossAlignment.end] values. + /// + /// If the [direction] is [Axis.horizontal], and either the + /// [runAlignment] is either [WrapAlignment.start] or [WrapAlignment.end], the + /// [crossAxisAlignment] is either [WrapCrossAlignment.start] or + /// [WrapCrossAlignment.end], or there's more than one child, then the + /// [verticalDirection] must not be null. + final VerticalDirection verticalDirection; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + @override + RenderWrap createRenderObject(BuildContext context) { + return RenderWrap( + direction: direction, + alignment: alignment, + spacing: spacing, + runAlignment: runAlignment, + runSpacing: runSpacing, + crossAxisAlignment: crossAxisAlignment, + textDirection: textDirection ?? Directionality.maybeOf(context), + verticalDirection: verticalDirection, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderWrap renderObject) { + renderObject + ..direction = direction + ..alignment = alignment + ..spacing = spacing + ..runAlignment = runAlignment + ..runSpacing = runSpacing + ..crossAxisAlignment = crossAxisAlignment + ..textDirection = textDirection ?? Directionality.maybeOf(context) + ..verticalDirection = verticalDirection + ..clipBehavior = clipBehavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<Axis>('direction', direction)); + properties.add(EnumProperty<WrapAlignment>('alignment', alignment)); + properties.add(DoubleProperty('spacing', spacing)); + properties.add(EnumProperty<WrapAlignment>('runAlignment', runAlignment)); + properties.add(DoubleProperty('runSpacing', runSpacing)); + properties.add(EnumProperty<WrapCrossAlignment>('crossAxisAlignment', crossAxisAlignment)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(EnumProperty<VerticalDirection>('verticalDirection', verticalDirection, defaultValue: VerticalDirection.down)); + } +} + +/// A widget that sizes and positions children efficiently, according to the +/// logic in a [FlowDelegate]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=NG6pvXpnIso} +/// +/// Flow layouts are optimized for repositioning children using transformation +/// matrices. +/// +/// The flow container is sized independently from the children by the +/// [FlowDelegate.getSize] function of the delegate. The children are then sized +/// independently given the constraints from the +/// [FlowDelegate.getConstraintsForChild] function. +/// +/// Rather than positioning the children during layout, the children are +/// positioned using transformation matrices during the paint phase using the +/// matrices from the [FlowDelegate.paintChildren] function. The children can be +/// repositioned efficiently by only _repainting_ the flow, which happens +/// without the children being laid out again (contrast this with a [Stack], +/// which does the sizing and positioning together during layout). +/// +/// The most efficient way to trigger a repaint of the flow is to supply an +/// animation to the constructor of the [FlowDelegate]. The flow will listen to +/// this animation and repaint whenever the animation ticks, avoiding both the +/// build and layout phases of the pipeline. +/// +/// {@tool dartpad} +/// This example uses the [Flow] widget to create a menu that opens and closes +/// as it is interacted with, shown above. The color of the button in the menu +/// changes to indicate which one has been selected. +/// +/// ** See code in examples/api/lib/widgets/basic/flow.0.dart ** +/// {@end-tool} +/// +/// ## Hit testing and hidden [Flow] widgets +/// +/// The [Flow] widget recomputes its children's positions (as used by hit +/// testing) during the _paint_ phase rather than during the _layout_ phase. +/// +/// Widgets like [Opacity] avoid painting their children when those children +/// would be invisible due to their opacity being zero. +/// +/// Unfortunately, this means that hiding a [Flow] widget using an [Opacity] +/// widget will cause bugs when the user attempts to interact with the hidden +/// region, for example, by tapping it or clicking it. +/// +/// Such bugs will manifest either as out-of-date geometry (taps going to +/// different widgets than might be expected by the currently-specified +/// [FlowDelegate]s), or exceptions (e.g. if the last time the [Flow] was +/// painted, a different set of children was specified). +/// +/// To avoid this, when hiding a [Flow] widget with an [Opacity] widget (or +/// [AnimatedOpacity] or similar), it is wise to also disable hit testing on the +/// widget by using [IgnorePointer]. This is generally good advice anyway as +/// hit-testing invisible widgets is often confusing for the user. +/// +/// See also: +/// +/// * [Wrap], which provides the layout model that some other frameworks call +/// "flow", and is otherwise unrelated to [Flow]. +/// * [Stack], which arranges children relative to the edges of the container. +/// * [CustomSingleChildLayout], which uses a delegate to control the layout of +/// a single child. +/// * [CustomMultiChildLayout], which uses a delegate to position multiple +/// children. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Flow extends MultiChildRenderObjectWidget { + /// Creates a flow layout. + /// + /// Wraps each of the given children in a [RepaintBoundary] to avoid + /// repainting the children when the flow repaints. + Flow({ + super.key, + required this.delegate, + List<Widget> children = const <Widget>[], + this.clipBehavior = Clip.hardEdge, + }) : super(children: RepaintBoundary.wrapAll(children)); + // https://github.com/dart-lang/sdk/issues/29277 + + /// Creates a flow layout. + /// + /// Does not wrap the given children in repaint boundaries, unlike the default + /// constructor. Useful when the child is trivial to paint or already contains + /// a repaint boundary. + const Flow.unwrapped({ + super.key, + required this.delegate, + super.children, + this.clipBehavior = Clip.hardEdge, + }); + + /// The delegate that controls the transformation matrices of the children. + final FlowDelegate delegate; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + @override + RenderFlow createRenderObject(BuildContext context) => RenderFlow(delegate: delegate, clipBehavior: clipBehavior); + + @override + void updateRenderObject(BuildContext context, RenderFlow renderObject) { + renderObject.delegate = delegate; + renderObject.clipBehavior = clipBehavior; + } +} + +/// A paragraph of rich text. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=rykDVh-QFfw} +/// +/// The [RichText] widget displays text that uses multiple different styles. The +/// text to display is described using a tree of [TextSpan] objects, each of +/// which has an associated style that is used for that subtree. The text might +/// break across multiple lines or might all be displayed on the same line +/// depending on the layout constraints. +/// +/// Text displayed in a [RichText] widget must be explicitly styled. When +/// picking which style to use, consider using [DefaultTextStyle.of] the current +/// [BuildContext] to provide defaults. For more details on how to style text in +/// a [RichText] widget, see the documentation for [TextStyle]. +/// +/// Consider using the [Text] widget to integrate with the [DefaultTextStyle] +/// automatically. When all the text uses the same style, the default constructor +/// is less verbose. The [Text.rich] constructor allows you to style multiple +/// spans with the default text style while still allowing specified styles per +/// span. +/// +/// {@tool snippet} +/// +/// This sample demonstrates how to mix and match text with different text +/// styles using the [RichText] Widget. It displays the text "Hello bold world," +/// emphasizing the word "bold" using a bold font weight. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/rich_text.png) +/// +/// ```dart +/// RichText( +/// text: TextSpan( +/// text: 'Hello ', +/// style: DefaultTextStyle.of(context).style, +/// children: const <TextSpan>[ +/// TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)), +/// TextSpan(text: ' world!'), +/// ], +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Selections +/// +/// To make this [RichText] Selectable, the [RichText] needs to be in the +/// subtree of a [SelectionArea] or [SelectableRegion] and a +/// [SelectionRegistrar] needs to be assigned to the +/// [RichText.selectionRegistrar]. One can use +/// [SelectionContainer.maybeOf] to get the [SelectionRegistrar] from a +/// context. This enables users to select the text in [RichText]s with mice or +/// touch events. +/// +/// The [selectionColor] also needs to be set if the selection is enabled to +/// draw the selection highlights. +/// +/// {@tool snippet} +/// +/// This sample demonstrates how to assign a [SelectionRegistrar] for RichTexts +/// in the SelectionArea subtree. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/rich_text.png) +/// +/// ```dart +/// RichText( +/// text: const TextSpan(text: 'Hello'), +/// selectionRegistrar: SelectionContainer.maybeOf(context), +/// selectionColor: const Color(0xAF6694e8), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [TextStyle], which discusses how to style text. +/// * [TextSpan], which is used to describe the text in a paragraph. +/// * [Text], which automatically applies the ambient styles described by a +/// [DefaultTextStyle] to a single string. +/// * [Text.rich], a const text widget that provides similar functionality +/// as [RichText]. [Text.rich] will inherit [TextStyle] from [DefaultTextStyle]. +/// * [SelectableRegion], which provides an overview of the selection system. +class RichText extends MultiChildRenderObjectWidget { + /// Creates a paragraph of rich text. + /// + /// The [maxLines] property may be null (and indeed defaults to null), but if + /// it is not null, it must be greater than zero. + /// + /// The [textDirection], if null, defaults to the ambient [Directionality], + /// which in that case must not be null. + RichText({ + super.key, + required this.text, + this.textAlign = TextAlign.start, + this.textDirection, + this.softWrap = true, + this.overflow = TextOverflow.clip, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double textScaleFactor = 1.0, + TextScaler textScaler = TextScaler.noScaling, + this.maxLines, + this.locale, + this.strutStyle, + this.textWidthBasis = TextWidthBasis.parent, + this.textHeightBehavior, + this.selectionRegistrar, + this.selectionColor, + }) : assert(maxLines == null || maxLines > 0), + assert(selectionRegistrar == null || selectionColor != null), + assert(textScaleFactor == 1.0 || identical(textScaler, TextScaler.noScaling), 'Use textScaler instead.'), + textScaler = _effectiveTextScalerFrom(textScaler, textScaleFactor), + super(children: WidgetSpan.extractFromInlineSpan(text, _effectiveTextScalerFrom(textScaler, textScaleFactor))); + + static TextScaler _effectiveTextScalerFrom(TextScaler textScaler, double textScaleFactor) { + return switch ((textScaler, textScaleFactor)) { + (final TextScaler scaler, 1.0) => scaler, + (TextScaler.noScaling, final double textScaleFactor) => TextScaler.linear(textScaleFactor), + (final TextScaler scaler, _) => scaler, + }; + } + + /// The text to display in this widget. + final InlineSpan text; + + /// How the text should be aligned horizontally. + final TextAlign textAlign; + + /// The directionality of the text. + /// + /// This decides how [textAlign] values like [TextAlign.start] and + /// [TextAlign.end] are interpreted. + /// + /// This is also used to disambiguate how to render bidirectional text. For + /// example, if the [text] is an English phrase followed by a Hebrew phrase, + /// in a [TextDirection.ltr] context the English phrase will be on the left + /// and the Hebrew phrase to its right, while in a [TextDirection.rtl] + /// context, the English phrase will be on the right and the Hebrew phrase on + /// its left. + /// + /// Defaults to the ambient [Directionality], if any. If there is no ambient + /// [Directionality], then this must not be null. + final TextDirection? textDirection; + + /// Whether the text should break at soft line breaks. + /// + /// If false, the glyphs in the text will be positioned as if there was unlimited horizontal space. + final bool softWrap; + + /// How visual overflow should be handled. + final TextOverflow overflow; + + /// Deprecated. Will be removed in a future version of Flutter. Use + /// [textScaler] instead. + /// + /// The number of font pixels for each logical pixel. + /// + /// For example, if the text scale factor is 1.5, text will be 50% larger than + /// the specified font size. + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double get textScaleFactor => textScaler.textScaleFactor; + + /// {@macro flutter.painting.textPainter.textScaler} + final TextScaler textScaler; + + /// An optional maximum number of lines for the text to span, wrapping if necessary. + /// If the text exceeds the given number of lines, it will be truncated according + /// to [overflow]. + /// + /// If this is 1, text will not wrap. Otherwise, text will be wrapped at the + /// edge of the box. + final int? maxLines; + + /// Used to select a font when the same Unicode character can + /// be rendered differently, depending on the locale. + /// + /// It's rarely necessary to set this property. By default its value + /// is inherited from the enclosing app with `Localizations.localeOf(context)`. + /// + /// See [RenderParagraph.locale] for more information. + final Locale? locale; + + /// {@macro flutter.painting.textPainter.strutStyle} + final StrutStyle? strutStyle; + + /// {@macro flutter.painting.textPainter.textWidthBasis} + final TextWidthBasis textWidthBasis; + + /// {@macro dart.ui.textHeightBehavior} + final ui.TextHeightBehavior? textHeightBehavior; + + /// The [SelectionRegistrar] this rich text is subscribed to. + /// + /// If this is set, [selectionColor] must be non-null. + final SelectionRegistrar? selectionRegistrar; + + /// The color to use when painting the selection. + /// + /// This is ignored if [selectionRegistrar] is null. + /// + /// See the section on selections in the [RichText] top-level API + /// documentation for more details on enabling selection in [RichText] + /// widgets. + final Color? selectionColor; + + @override + RenderParagraph createRenderObject(BuildContext context) { + assert(textDirection != null || debugCheckHasDirectionality(context)); + return RenderParagraph(text, + textAlign: textAlign, + textDirection: textDirection ?? Directionality.of(context), + softWrap: softWrap, + overflow: overflow, + textScaler: textScaler, + maxLines: maxLines, + strutStyle: strutStyle, + textWidthBasis: textWidthBasis, + textHeightBehavior: textHeightBehavior, + locale: locale ?? Localizations.maybeLocaleOf(context), + registrar: selectionRegistrar, + selectionColor: selectionColor, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderParagraph renderObject) { + assert(textDirection != null || debugCheckHasDirectionality(context)); + renderObject + ..text = text + ..textAlign = textAlign + ..textDirection = textDirection ?? Directionality.of(context) + ..softWrap = softWrap + ..overflow = overflow + ..textScaler = textScaler + ..maxLines = maxLines + ..strutStyle = strutStyle + ..textWidthBasis = textWidthBasis + ..textHeightBehavior = textHeightBehavior + ..locale = locale ?? Localizations.maybeLocaleOf(context) + ..registrar = selectionRegistrar + ..selectionColor = selectionColor; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<TextAlign>('textAlign', textAlign, defaultValue: TextAlign.start)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(FlagProperty('softWrap', value: softWrap, ifTrue: 'wrapping at box width', ifFalse: 'no wrapping except at line break characters', showName: true)); + properties.add(EnumProperty<TextOverflow>('overflow', overflow, defaultValue: TextOverflow.clip)); + properties.add(DiagnosticsProperty<TextScaler>('textScaler', textScaler, defaultValue: TextScaler.noScaling)); + properties.add(IntProperty('maxLines', maxLines, ifNull: 'unlimited')); + properties.add(EnumProperty<TextWidthBasis>('textWidthBasis', textWidthBasis, defaultValue: TextWidthBasis.parent)); + properties.add(StringProperty('text', text.toPlainText())); + properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null)); + properties.add(DiagnosticsProperty<StrutStyle>('strutStyle', strutStyle, defaultValue: null)); + properties.add(DiagnosticsProperty<TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null)); + } +} + +/// A widget that displays a [dart:ui.Image] directly. +/// +/// The image is painted using [paintImage], which describes the meanings of the +/// various fields on this class in more detail. +/// +/// The [image] is not disposed of by this widget. Creators of the widget are +/// expected to call [Image.dispose] on the [image] once the [RawImage] is no +/// longer buildable. +/// +/// This widget is rarely used directly. Instead, consider using [Image]. +class RawImage extends LeafRenderObjectWidget { + /// Creates a widget that displays an image. + /// + /// The [scale], [alignment], [repeat], [matchTextDirection] and [filterQuality] arguments must + /// not be null. + const RawImage({ + super.key, + this.image, + this.debugImageLabel, + this.width, + this.height, + this.scale = 1.0, + this.color, + this.opacity, + this.colorBlendMode, + this.fit, + this.alignment = Alignment.center, + this.repeat = ImageRepeat.noRepeat, + this.centerSlice, + this.matchTextDirection = false, + this.invertColors = false, + this.filterQuality = FilterQuality.low, + this.isAntiAlias = false, + }); + + /// The image to display. + /// + /// Since a [RawImage] is stateless, it does not ever dispose this image. + /// Creators of a [RawImage] are expected to call [Image.dispose] on this + /// image handle when the [RawImage] will no longer be needed. + final ui.Image? image; + + /// A string identifying the source of the image. + final String? debugImageLabel; + + /// If non-null, require the image to have this width. + /// + /// If null, the image will pick a size that best preserves its intrinsic + /// aspect ratio. + final double? width; + + /// If non-null, require the image to have this height. + /// + /// If null, the image will pick a size that best preserves its intrinsic + /// aspect ratio. + final double? height; + + /// Specifies the image's scale. + /// + /// Used when determining the best display size for the image. + final double scale; + + /// If non-null, this color is blended with each image pixel using [colorBlendMode]. + final Color? color; + + /// If non-null, the value from the [Animation] is multiplied with the opacity + /// of each image pixel before painting onto the canvas. + /// + /// This is more efficient than using [FadeTransition] to change the opacity + /// of an image. + final Animation<double>? opacity; + + /// Used to set the filterQuality of the image. + /// + /// Defaults to [FilterQuality.low] to scale the image, which corresponds to + /// bilinear interpolation. + final FilterQuality filterQuality; + + /// Used to combine [color] with this image. + /// + /// The default is [BlendMode.srcIn]. In terms of the blend mode, [color] is + /// the source and this image is the destination. + /// + /// See also: + /// + /// * [BlendMode], which includes an illustration of the effect of each blend mode. + final BlendMode? colorBlendMode; + + /// How to inscribe the image into the space allocated during layout. + /// + /// The default varies based on the other fields. See the discussion at + /// [paintImage]. + final BoxFit? fit; + + /// How to align the image within its bounds. + /// + /// The alignment aligns the given position in the image to the given position + /// in the layout bounds. For example, an [Alignment] alignment of (-1.0, + /// -1.0) aligns the image to the top-left corner of its layout bounds, while a + /// [Alignment] alignment of (1.0, 1.0) aligns the bottom right of the + /// image with the bottom right corner of its layout bounds. Similarly, an + /// alignment of (0.0, 1.0) aligns the bottom middle of the image with the + /// middle of the bottom edge of its layout bounds. + /// + /// To display a subpart of an image, consider using a [CustomPainter] and + /// [Canvas.drawImageRect]. + /// + /// If the [alignment] is [TextDirection]-dependent (i.e. if it is a + /// [AlignmentDirectional]), then an ambient [Directionality] widget + /// must be in scope. + /// + /// Defaults to [Alignment.center]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// How to paint any portions of the layout bounds not covered by the image. + final ImageRepeat repeat; + + /// The center slice for a nine-patch image. + /// + /// The region of the image inside the center slice will be stretched both + /// horizontally and vertically to fit the image into its destination. The + /// region of the image above and below the center slice will be stretched + /// only horizontally and the region of the image to the left and right of + /// the center slice will be stretched only vertically. + final Rect? centerSlice; + + /// Whether to paint the image in the direction of the [TextDirection]. + /// + /// If this is true, then in [TextDirection.ltr] contexts, the image will be + /// drawn with its origin in the top left (the "normal" painting direction for + /// images); and in [TextDirection.rtl] contexts, the image will be drawn with + /// a scaling factor of -1 in the horizontal direction so that the origin is + /// in the top right. + /// + /// This is occasionally used with images in right-to-left environments, for + /// images that were designed for left-to-right locales. Be careful, when + /// using this, to not flip images with integral shadows, text, or other + /// effects that will look incorrect when flipped. + /// + /// If this is true, there must be an ambient [Directionality] widget in + /// scope. + final bool matchTextDirection; + + /// Whether the colors of the image are inverted when drawn. + /// + /// Inverting the colors of an image applies a new color filter to the paint. + /// If there is another specified color filter, the invert will be applied + /// after it. This is primarily used for implementing smart invert on iOS. + /// + /// See also: + /// + /// * [Paint.invertColors], for the dart:ui implementation. + final bool invertColors; + + /// Whether to paint the image with anti-aliasing. + /// + /// Anti-aliasing alleviates the sawtooth artifact when the image is rotated. + final bool isAntiAlias; + + @override + RenderImage createRenderObject(BuildContext context) { + assert((!matchTextDirection && alignment is Alignment) || debugCheckHasDirectionality(context)); + assert( + image?.debugGetOpenHandleStackTraces()?.isNotEmpty ?? true, + 'Creator of a RawImage disposed of the image when the RawImage still ' + 'needed it.', + ); + return RenderImage( + image: image?.clone(), + debugImageLabel: debugImageLabel, + width: width, + height: height, + scale: scale, + color: color, + opacity: opacity, + colorBlendMode: colorBlendMode, + fit: fit, + alignment: alignment, + repeat: repeat, + centerSlice: centerSlice, + matchTextDirection: matchTextDirection, + textDirection: matchTextDirection || alignment is! Alignment ? Directionality.of(context) : null, + invertColors: invertColors, + isAntiAlias: isAntiAlias, + filterQuality: filterQuality, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderImage renderObject) { + assert( + image?.debugGetOpenHandleStackTraces()?.isNotEmpty ?? true, + 'Creator of a RawImage disposed of the image when the RawImage still ' + 'needed it.', + ); + renderObject + ..image = image?.clone() + ..debugImageLabel = debugImageLabel + ..width = width + ..height = height + ..scale = scale + ..color = color + ..opacity = opacity + ..colorBlendMode = colorBlendMode + ..fit = fit + ..alignment = alignment + ..repeat = repeat + ..centerSlice = centerSlice + ..matchTextDirection = matchTextDirection + ..textDirection = matchTextDirection || alignment is! Alignment ? Directionality.of(context) : null + ..invertColors = invertColors + ..isAntiAlias = isAntiAlias + ..filterQuality = filterQuality; + } + + @override + void didUnmountRenderObject(RenderImage renderObject) { + // Have the render object dispose its image handle. + renderObject.image = null; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ui.Image>('image', image)); + properties.add(DoubleProperty('width', width, defaultValue: null)); + properties.add(DoubleProperty('height', height, defaultValue: null)); + properties.add(DoubleProperty('scale', scale, defaultValue: 1.0)); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(DiagnosticsProperty<Animation<double>?>('opacity', opacity, defaultValue: null)); + properties.add(EnumProperty<BlendMode>('colorBlendMode', colorBlendMode, defaultValue: null)); + properties.add(EnumProperty<BoxFit>('fit', fit, defaultValue: null)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: null)); + properties.add(EnumProperty<ImageRepeat>('repeat', repeat, defaultValue: ImageRepeat.noRepeat)); + properties.add(DiagnosticsProperty<Rect>('centerSlice', centerSlice, defaultValue: null)); + properties.add(FlagProperty('matchTextDirection', value: matchTextDirection, ifTrue: 'match text direction')); + properties.add(DiagnosticsProperty<bool>('invertColors', invertColors)); + properties.add(EnumProperty<FilterQuality>('filterQuality', filterQuality)); + } +} + +/// A widget that determines the default asset bundle for its descendants. +/// +/// For example, used by [Image] to determine which bundle to use for +/// [AssetImage]s if no bundle is specified explicitly. +/// +/// {@tool snippet} +/// +/// This can be used in tests to override what the current asset bundle is, thus +/// allowing specific resources to be injected into the widget under test. +/// +/// For example, a test could create a test asset bundle like this: +/// +/// ```dart +/// class TestAssetBundle extends CachingAssetBundle { +/// @override +/// Future<ByteData> load(String key) async { +/// if (key == 'resources/test') { +/// return ByteData.sublistView(utf8.encode('Hello World!')); +/// } +/// return ByteData(0); +/// } +/// } +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// ...then wrap the widget under test with a [DefaultAssetBundle] using this +/// bundle implementation: +/// +/// ```dart +/// // continuing from previous example... +/// await tester.pumpWidget( +/// MaterialApp( +/// home: DefaultAssetBundle( +/// bundle: TestAssetBundle(), +/// child: const TestWidget(), +/// ), +/// ), +/// ); +/// ``` +/// {@end-tool} +/// +/// Assuming that `TestWidget` uses [DefaultAssetBundle.of] to obtain its +/// [AssetBundle], it will now see the `TestAssetBundle`'s "Hello World!" data +/// when requesting the "resources/test" asset. +/// +/// See also: +/// +/// * [AssetBundle], the interface for asset bundles. +/// * [rootBundle], the default asset bundle. +class DefaultAssetBundle extends InheritedWidget { + /// Creates a widget that determines the default asset bundle for its descendants. + const DefaultAssetBundle({ + super.key, + required this.bundle, + required super.child, + }); + + /// The bundle to use as a default. + final AssetBundle bundle; + + /// The bundle from the closest instance of this class that encloses + /// the given context. + /// + /// If there is no [DefaultAssetBundle] ancestor widget in the tree + /// at the given context, then this will return the [rootBundle]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// AssetBundle bundle = DefaultAssetBundle.of(context); + /// ``` + static AssetBundle of(BuildContext context) { + final DefaultAssetBundle? result = context.dependOnInheritedWidgetOfExactType<DefaultAssetBundle>(); + return result?.bundle ?? rootBundle; + } + + @override + bool updateShouldNotify(DefaultAssetBundle oldWidget) => bundle != oldWidget.bundle; +} + +/// An adapter for placing a specific [RenderBox] in the widget tree. +/// +/// A given render object can be placed at most once in the widget tree. This +/// widget enforces that restriction by keying itself using a [GlobalObjectKey] +/// for the given render object. +/// +/// This widget will call [RenderObject.dispose] on the [renderBox] when it is +/// unmounted. After that point, the [renderBox] will be unusable. If any +/// children have been added to the [renderBox], they must be disposed in the +/// [onUnmount] callback. +class WidgetToRenderBoxAdapter extends LeafRenderObjectWidget { + /// Creates an adapter for placing a specific [RenderBox] in the widget tree. + WidgetToRenderBoxAdapter({ + required this.renderBox, + this.onBuild, + this.onUnmount, + }) : super(key: GlobalObjectKey(renderBox)); + + /// The render box to place in the widget tree. + /// + /// This widget takes ownership of the render object. When it is unmounted, + /// it also calls [RenderObject.dispose]. + final RenderBox renderBox; + + /// Called when it is safe to update the render box and its descendants. If + /// you update the RenderObject subtree under this widget outside of + /// invocations of this callback, features like hit-testing will fail as the + /// tree will be dirty. + final VoidCallback? onBuild; + + /// Called when it is safe to dispose of children that were manually added to + /// the [renderBox]. + /// + /// Do not dispose the [renderBox] itself, as it will be disposed by the + /// framework automatically. However, during that process the framework will + /// check that all children of the [renderBox] have also been disposed. + /// Typically, child [RenderObject]s are disposed by corresponding [Element]s + /// when they are unmounted. However, child render objects that were manually + /// added do not have corresponding [Element]s to manage their lifecycle, and + /// need to be manually disposed here. + /// + /// See also: + /// + /// * [RenderObjectElement.unmount], which invokes this callback before + /// disposing of its render object. + /// * [RenderObject.dispose], which instructs a render object to release + /// any resources it may be holding. + final VoidCallback? onUnmount; + + @override + RenderBox createRenderObject(BuildContext context) => renderBox; + + @override + void updateRenderObject(BuildContext context, RenderBox renderObject) { + onBuild?.call(); + } + + @override + void didUnmountRenderObject(RenderObject renderObject) { + assert(renderObject == renderBox); + onUnmount?.call(); + } +} + + +// EVENT HANDLING + +/// A widget that calls callbacks in response to common pointer events. +/// +/// It listens to events that can construct gestures, such as when the +/// pointer is pressed, moved, then released or canceled. +/// +/// It does not listen to events that are exclusive to mouse, such as when the +/// mouse enters, exits or hovers a region without pressing any buttons. For +/// these events, use [MouseRegion]. +/// +/// Rather than listening for raw pointer events, consider listening for +/// higher-level gestures using [GestureDetector]. +/// +/// ## Layout behavior +/// +/// _See [BoxConstraints] for an introduction to box layout models._ +/// +/// If it has a child, this widget defers to the child for sizing behavior. If +/// it does not have a child, it grows to fit the parent instead. +/// +/// {@tool dartpad} +/// This example makes a [Container] react to being touched, showing a count of +/// the number of pointer downs and ups. +/// +/// ** See code in examples/api/lib/widgets/basic/listener.0.dart ** +/// {@end-tool} +class Listener extends SingleChildRenderObjectWidget { + /// Creates a widget that forwards point events to callbacks. + /// + /// The [behavior] argument defaults to [HitTestBehavior.deferToChild]. + const Listener({ + super.key, + this.onPointerDown, + this.onPointerMove, + this.onPointerUp, + this.onPointerHover, + this.onPointerCancel, + this.onPointerPanZoomStart, + this.onPointerPanZoomUpdate, + this.onPointerPanZoomEnd, + this.onPointerSignal, + this.behavior = HitTestBehavior.deferToChild, + super.child, + }); + + /// Called when a pointer comes into contact with the screen (for touch + /// pointers), or has its button pressed (for mouse pointers) at this widget's + /// location. + final PointerDownEventListener? onPointerDown; + + /// Called when a pointer that triggered an [onPointerDown] changes position. + final PointerMoveEventListener? onPointerMove; + + /// Called when a pointer that triggered an [onPointerDown] is no longer in + /// contact with the screen. + final PointerUpEventListener? onPointerUp; + + /// Called when a pointer that has not triggered an [onPointerDown] changes + /// position. + /// + /// This is only fired for pointers which report their location when not down + /// (e.g. mouse pointers, but not most touch pointers). + final PointerHoverEventListener? onPointerHover; + + /// Called when the input from a pointer that triggered an [onPointerDown] is + /// no longer directed towards this receiver. + final PointerCancelEventListener? onPointerCancel; + + /// Called when a pan/zoom begins such as from a trackpad gesture. + final PointerPanZoomStartEventListener? onPointerPanZoomStart; + + /// Called when a pan/zoom is updated. + final PointerPanZoomUpdateEventListener? onPointerPanZoomUpdate; + + /// Called when a pan/zoom finishes. + final PointerPanZoomEndEventListener? onPointerPanZoomEnd; + + /// Called when a pointer signal occurs over this object. + /// + /// See also: + /// + /// * [PointerSignalEvent], which goes into more detail on pointer signal + /// events. + final PointerSignalEventListener? onPointerSignal; + + /// How to behave during hit testing. + final HitTestBehavior behavior; + + @override + RenderPointerListener createRenderObject(BuildContext context) { + return RenderPointerListener( + onPointerDown: onPointerDown, + onPointerMove: onPointerMove, + onPointerUp: onPointerUp, + onPointerHover: onPointerHover, + onPointerCancel: onPointerCancel, + onPointerPanZoomStart: onPointerPanZoomStart, + onPointerPanZoomUpdate: onPointerPanZoomUpdate, + onPointerPanZoomEnd: onPointerPanZoomEnd, + onPointerSignal: onPointerSignal, + behavior: behavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderPointerListener renderObject) { + renderObject + ..onPointerDown = onPointerDown + ..onPointerMove = onPointerMove + ..onPointerUp = onPointerUp + ..onPointerHover = onPointerHover + ..onPointerCancel = onPointerCancel + ..onPointerPanZoomStart = onPointerPanZoomStart + ..onPointerPanZoomUpdate = onPointerPanZoomUpdate + ..onPointerPanZoomEnd = onPointerPanZoomEnd + ..onPointerSignal = onPointerSignal + ..behavior = behavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final List<String> listeners = <String>[ + if (onPointerDown != null) 'down', + if (onPointerMove != null) 'move', + if (onPointerUp != null) 'up', + if (onPointerHover != null) 'hover', + if (onPointerCancel != null) 'cancel', + if (onPointerPanZoomStart != null) 'panZoomStart', + if (onPointerPanZoomUpdate != null) 'panZoomUpdate', + if (onPointerPanZoomEnd != null) 'panZoomEnd', + if (onPointerSignal != null) 'signal', + ]; + properties.add(IterableProperty<String>('listeners', listeners, ifEmpty: '<none>')); + properties.add(EnumProperty<HitTestBehavior>('behavior', behavior)); + } +} + +/// A widget that tracks the movement of mice. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=1oF3pI5umck} +/// +/// [MouseRegion] is used +/// when it is needed to compare the list of objects that a mouse pointer is +/// hovering over between this frame and the last frame. This means entering +/// events, exiting events, and mouse cursors. +/// +/// To listen to general pointer events, use [Listener], or more preferably, +/// [GestureDetector]. +/// +/// ## Layout behavior +/// +/// _See [BoxConstraints] for an introduction to box layout models._ +/// +/// If it has a child, this widget defers to the child for sizing behavior. If +/// it does not have a child, it grows to fit the parent instead. +/// +/// {@tool dartpad} +/// This example makes a [Container] react to being entered by a mouse +/// pointer, showing a count of the number of entries and exits. +/// +/// ** See code in examples/api/lib/widgets/basic/mouse_region.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Listener], a similar widget that tracks pointer events when the pointer +/// has buttons pressed. +class MouseRegion extends SingleChildRenderObjectWidget { + /// Creates a widget that forwards mouse events to callbacks. + /// + /// By default, all callbacks are empty, [cursor] is [MouseCursor.defer], and + /// [opaque] is true. + const MouseRegion({ + super.key, + this.onEnter, + this.onExit, + this.onHover, + this.cursor = MouseCursor.defer, + this.opaque = true, + this.hitTestBehavior, + super.child, + }); + + /// Triggered when a mouse pointer has entered this widget. + /// + /// This callback is triggered when the pointer, with or without buttons + /// pressed, has started to be contained by the region of this widget. More + /// specifically, the callback is triggered by the following cases: + /// + /// * This widget has appeared under a pointer. + /// * This widget has moved to under a pointer. + /// * A new pointer has been added to somewhere within this widget. + /// * An existing pointer has moved into this widget. + /// + /// This callback is not always matched by an [onExit]. If the [MouseRegion] + /// is unmounted while being hovered by a pointer, the [onExit] of the widget + /// callback will never called. For more details, see [onExit]. + /// + /// {@template flutter.widgets.MouseRegion.onEnter.triggerTime} + /// The time that this callback is triggered is always between frames: either + /// during the post-frame callbacks, or during the callback of a pointer + /// event. + /// {@endtemplate} + /// + /// See also: + /// + /// * [onExit], which is triggered when a mouse pointer exits the region. + /// * [MouseTrackerAnnotation.onEnter], which is how this callback is + /// internally implemented. + final PointerEnterEventListener? onEnter; + + /// Triggered when a pointer moves into a position within this widget without + /// buttons pressed. + /// + /// Usually this is only fired for pointers which report their location when + /// not down (e.g. mouse pointers). Certain devices also fire this event on + /// single taps in accessibility mode. + /// + /// This callback is not triggered by the movement of the widget. + /// + /// The time that this callback is triggered is during the callback of a + /// pointer event, which is always between frames. + /// + /// See also: + /// + /// * [Listener.onPointerHover], which does the same job. Prefer using + /// [Listener.onPointerHover], since hover events are similar to other regular + /// events. + final PointerHoverEventListener? onHover; + + /// Triggered when a mouse pointer has exited this widget when the widget is + /// still mounted. + /// + /// This callback is triggered when the pointer, with or without buttons + /// pressed, has stopped being contained by the region of this widget, except + /// when the exit is caused by the disappearance of this widget. More + /// specifically, this callback is triggered by the following cases: + /// + /// * A pointer that is hovering this widget has moved away. + /// * A pointer that is hovering this widget has been removed. + /// * This widget, which is being hovered by a pointer, has moved away. + /// + /// And is __not__ triggered by the following case: + /// + /// * This widget, which is being hovered by a pointer, has disappeared. + /// + /// This means that a [MouseRegion.onExit] might not be matched by a + /// [MouseRegion.onEnter]. + /// + /// This restriction aims to prevent a common misuse: if [State.setState] is + /// called during [MouseRegion.onExit] without checking whether the widget is + /// still mounted, an exception will occur. This is because the callback is + /// triggered during the post-frame phase, at which point the widget has been + /// unmounted. Since [State.setState] is exclusive to widgets, the restriction + /// is specific to [MouseRegion], and does not apply to its lower-level + /// counterparts, [RenderMouseRegion] and [MouseTrackerAnnotation]. + /// + /// There are a few ways to mitigate this restriction: + /// + /// * If the hover state is completely contained within a widget that + /// unconditionally creates this [MouseRegion], then this will not be a + /// concern, since after the [MouseRegion] is unmounted the state is no + /// longer used. + /// * Otherwise, the outer widget very likely has access to the variable that + /// controls whether this [MouseRegion] is present. If so, call [onExit] at + /// the event that turns the condition from true to false. + /// * In cases where the solutions above won't work, you can always + /// override [State.dispose] and call [onExit], or create your own widget + /// using [RenderMouseRegion]. + /// + /// {@tool dartpad} + /// The following example shows a blue rectangular that turns yellow when + /// hovered. Since the hover state is completely contained within a widget + /// that unconditionally creates the `MouseRegion`, you can ignore the + /// aforementioned restriction. + /// + /// ** See code in examples/api/lib/widgets/basic/mouse_region.on_exit.0.dart ** + /// {@end-tool} + /// + /// {@tool dartpad} + /// The following example shows a widget that hides its content one second + /// after being hovered, and also exposes the enter and exit callbacks. + /// Because the widget conditionally creates the `MouseRegion`, and leaks the + /// hover state, it needs to take the restriction into consideration. In this + /// case, since it has access to the event that triggers the disappearance of + /// the `MouseRegion`, it triggers the exit callback during that event + /// as well. + /// + /// ** See code in examples/api/lib/widgets/basic/mouse_region.on_exit.1.dart ** + /// {@end-tool} + /// + /// {@macro flutter.widgets.MouseRegion.onEnter.triggerTime} + /// + /// See also: + /// + /// * [onEnter], which is triggered when a mouse pointer enters the region. + /// * [RenderMouseRegion] and [MouseTrackerAnnotation.onExit], which are how + /// this callback is internally implemented, but without the restriction. + final PointerExitEventListener? onExit; + + /// The mouse cursor for mouse pointers that are hovering over the region. + /// + /// When a mouse enters the region, its cursor will be changed to the [cursor]. + /// When the mouse leaves the region, the cursor will be decided by the region + /// found at the new location. + /// + /// The [cursor] defaults to [MouseCursor.defer], deferring the choice of + /// cursor to the next region behind it in hit-test order. + final MouseCursor cursor; + + /// Whether this widget should prevent other [MouseRegion]s visually behind it + /// from detecting the pointer. + /// + /// This changes the list of regions that a pointer hovers, thus affecting how + /// their [onHover], [onEnter], [onExit], and [cursor] behave. + /// + /// If [opaque] is true, this widget will absorb the mouse pointer and + /// prevent this widget's siblings (or any other widgets that are not + /// ancestors or descendants of this widget) from detecting the mouse + /// pointer even when the pointer is within their areas. + /// + /// If [opaque] is false, this object will not affect how [MouseRegion]s + /// behind it behave, which will detect the mouse pointer as long as the + /// pointer is within their areas. + /// + /// This defaults to true. + final bool opaque; + + /// How to behave during hit testing. + /// + /// This defaults to [HitTestBehavior.opaque] if null. + final HitTestBehavior? hitTestBehavior; + + @override + RenderMouseRegion createRenderObject(BuildContext context) { + return RenderMouseRegion( + onEnter: onEnter, + onHover: onHover, + onExit: onExit, + cursor: cursor, + opaque: opaque, + hitTestBehavior: hitTestBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderMouseRegion renderObject) { + renderObject + ..onEnter = onEnter + ..onHover = onHover + ..onExit = onExit + ..cursor = cursor + ..opaque = opaque + ..hitTestBehavior = hitTestBehavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final List<String> listeners = <String>[]; + if (onEnter != null) { + listeners.add('enter'); + } + if (onExit != null) { + listeners.add('exit'); + } + if (onHover != null) { + listeners.add('hover'); + } + properties.add(IterableProperty<String>('listeners', listeners, ifEmpty: '<none>')); + properties.add(DiagnosticsProperty<MouseCursor>('cursor', cursor, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('opaque', opaque, defaultValue: true)); + } +} + +/// A widget that creates a separate display list for its child. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=cVAGLDuc2xE} +/// +/// This widget creates a separate display list for its child, which +/// can improve performance if the subtree repaints at different times than +/// the surrounding parts of the tree. +/// +/// This is useful since [RenderObject.paint] may be triggered even if its +/// associated [Widget] instances did not change or rebuild. A [RenderObject] +/// will repaint whenever any [RenderObject] that shares the same [Layer] is +/// marked as being dirty and needing paint (see [RenderObject.markNeedsPaint]), +/// such as when an ancestor scrolls or when an ancestor or descendant animates. +/// +/// Containing [RenderObject.paint] to parts of the render subtree that are +/// actually visually changing using [RepaintBoundary] explicitly or implicitly +/// is therefore critical to minimizing redundant work and improving the app's +/// performance. +/// +/// When a [RenderObject] is flagged as needing to paint via +/// [RenderObject.markNeedsPaint], the nearest ancestor [RenderObject] with +/// [RenderObject.isRepaintBoundary], up to possibly the root of the application, +/// is requested to repaint. That nearest ancestor's [RenderObject.paint] method +/// will cause _all_ of its descendant [RenderObject]s to repaint in the same +/// layer. +/// +/// [RepaintBoundary] is therefore used, both while propagating the +/// `markNeedsPaint` flag up the render tree and while traversing down the +/// render tree via [PaintingContext.paintChild], to strategically contain +/// repaints to the render subtree that visually changed for performance. This +/// is done because the [RepaintBoundary] widget creates a [RenderObject] that +/// always has a [Layer], decoupling ancestor render objects from the descendant +/// render objects. +/// +/// [RepaintBoundary] has the further side-effect of possibly hinting to the +/// engine that it should further optimize animation performance if the render +/// subtree behind the [RepaintBoundary] is sufficiently complex and is static +/// while the surrounding tree changes frequently. In those cases, the engine +/// may choose to pay a one time cost of rasterizing and caching the pixel +/// values of the subtree for faster future GPU re-rendering speed. +/// +/// Several framework widgets insert [RepaintBoundary] widgets to mark natural +/// separation points in applications. For instance, contents in Material Design +/// drawers typically don't change while the drawer opens and closes, so +/// repaints are automatically contained to regions inside or outside the drawer +/// when using the [Drawer] widget during transitions. +/// +/// See also: +/// +/// * [debugRepaintRainbowEnabled], a debugging flag to help visually monitor +/// render tree repaints in a running app. +/// * [debugProfilePaintsEnabled], a debugging flag to show render tree +/// repaints in the observatory's timeline view. +class RepaintBoundary extends SingleChildRenderObjectWidget { + /// Creates a widget that isolates repaints. + const RepaintBoundary({ super.key, super.child }); + + /// Wraps the given child in a [RepaintBoundary]. + /// + /// The key for the [RepaintBoundary] is derived either from the child's key + /// (if the child has a non-null key) or from the given `childIndex`. + factory RepaintBoundary.wrap(Widget child, int childIndex) { + final Key key = child.key != null ? ValueKey<Key>(child.key!) : ValueKey<int>(childIndex); + return RepaintBoundary(key: key, child: child); + } + + /// Wraps each of the given children in [RepaintBoundary]s. + /// + /// The key for each [RepaintBoundary] is derived either from the wrapped + /// child's key (if the wrapped child has a non-null key) or from the wrapped + /// child's index in the list. + static List<RepaintBoundary> wrapAll(List<Widget> widgets) => <RepaintBoundary>[ + for (int i = 0; i < widgets.length; ++i) RepaintBoundary.wrap(widgets[i], i), + ]; + + @override + RenderRepaintBoundary createRenderObject(BuildContext context) => RenderRepaintBoundary(); +} + +/// A widget that is invisible during hit testing. +/// +/// When [ignoring] is true, this widget (and its subtree) is invisible +/// to hit testing. It still consumes space during layout and paints its child +/// as usual. It just cannot be the target of located events, because it returns +/// false from [RenderBox.hitTest]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=qV9pqHWxYgI} +/// +/// {@tool dartpad} +/// The following sample has an [IgnorePointer] widget wrapping the `Column` +/// which contains a button. +/// When [ignoring] is set to `true` anything inside the `Column` can +/// not be tapped. When [ignoring] is set to `false` anything +/// inside the `Column` can be tapped. +/// +/// ** See code in examples/api/lib/widgets/basic/ignore_pointer.0.dart ** +/// {@end-tool} +/// +/// ## Semantics +/// +/// Using this class may also affect how the semantics subtree underneath is +/// collected. +/// +/// {@template flutter.widgets.IgnorePointer.semantics} +/// If [ignoring] is true, pointer-related [SemanticsAction]s are removed from +/// the semantics subtree. Otherwise, the subtree remains untouched. +/// {@endtemplate} +/// +/// {@template flutter.widgets.IgnorePointer.ignoringSemantics} +/// The usages of [ignoringSemantics] are deprecated and not recommended. This +/// property was introduced to workaround the semantics behavior of the +/// [IgnorePointer] and its friends before v3.8.0-12.0.pre. +/// +/// Before that version, entire semantics subtree is dropped if [ignoring] is +/// true. Developers can only use [ignoringSemantics] to preserver the semantics +/// subtrees. +/// +/// After that version, with [ignoring] set to true, it only prevents semantics +/// user actions in the semantics subtree but leaves the other +/// [SemanticsProperties] intact. Therefore, the [ignoringSemantics] is no +/// longer needed. +/// +/// If [ignoringSemantics] is true, the semantics subtree is dropped. Therefore, +/// the subtree will be invisible to assistive technologies. +/// +/// If [ignoringSemantics] is false, the semantics subtree is collected as +/// usual. +/// {@endtemplate} +/// +/// See also: +/// +/// * [AbsorbPointer], which also prevents its children from receiving pointer +/// events but is itself visible to hit testing. +/// * [SliverIgnorePointer], the sliver version of this widget. +class IgnorePointer extends SingleChildRenderObjectWidget { + /// Creates a widget that is invisible to hit testing. + const IgnorePointer({ + super.key, + this.ignoring = true, + @Deprecated( + 'Use ExcludeSemantics or create a custom ignore pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + this.ignoringSemantics, + super.child, + }); + + /// Whether this widget is ignored during hit testing. + /// + /// Regardless of whether this widget is ignored during hit testing, it will + /// still consume space during layout and be visible during painting. + /// + /// {@macro flutter.widgets.IgnorePointer.semantics} + /// + /// Defaults to true. + final bool ignoring; + + /// Whether the semantics of this widget is ignored when compiling the + /// semantics subtree. + /// + /// {@macro flutter.widgets.IgnorePointer.ignoringSemantics} + /// + /// See [SemanticsNode] for additional information about the semantics tree. + @Deprecated( + 'Use ExcludeSemantics or create a custom ignore pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + final bool? ignoringSemantics; + + @override + RenderIgnorePointer createRenderObject(BuildContext context) { + return RenderIgnorePointer( + ignoring: ignoring, + ignoringSemantics: ignoringSemantics, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderIgnorePointer renderObject) { + renderObject + ..ignoring = ignoring + ..ignoringSemantics = ignoringSemantics; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('ignoring', ignoring)); + properties.add(DiagnosticsProperty<bool>('ignoringSemantics', ignoringSemantics, defaultValue: null)); + } +} + +/// A widget that absorbs pointers during hit testing. +/// +/// When [absorbing] is true, this widget prevents its subtree from receiving +/// pointer events by terminating hit testing at itself. It still consumes space +/// during layout and paints its child as usual. It just prevents its children +/// from being the target of located events, because it returns true from +/// [RenderBox.hitTest]. +/// +/// When [ignoringSemantics] is true, the subtree will be invisible to +/// the semantics layer (and thus e.g. accessibility tools). +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=65HoWqBboI8} +/// +/// {@tool dartpad} +/// The following sample has an [AbsorbPointer] widget wrapping the button on +/// top of the stack, which absorbs pointer events, preventing its child button +/// __and__ the button below it in the stack from receiving the pointer events. +/// +/// ** See code in examples/api/lib/widgets/basic/absorb_pointer.0.dart ** +/// {@end-tool} +/// +/// ## Semantics +/// +/// Using this class may also affect how the semantics subtree underneath is +/// collected. +/// +/// {@template flutter.widgets.AbsorbPointer.semantics} +/// If [absorbing] is true, pointer-related [SemanticsAction]s are removed from +/// the semantics subtree. Otherwise, the subtree remains untouched. +/// {@endtemplate} +/// +/// {@template flutter.widgets.AbsorbPointer.ignoringSemantics} +/// The usages of [ignoringSemantics] are deprecated and not recommended. This +/// property was introduced to workaround the semantics behavior of the +/// [IgnorePointer] and its friends before v3.8.0-12.0.pre. +/// +/// Before that version, entire semantics subtree is dropped if [absorbing] is +/// true. Developers can only use [ignoringSemantics] to preserver the semantics +/// subtrees. +/// +/// After that version, with [absorbing] set to true, it only prevents semantics +/// user actions in the semantics subtree but leaves the other +/// [SemanticsProperties] intact. Therefore, the [ignoringSemantics] is no +/// longer needed. +/// +/// If [ignoringSemantics] is true, the semantics subtree is dropped. Therefore, +/// the subtree will be invisible to assistive technologies. +/// +/// If [ignoringSemantics] is false, the semantics subtree is collected as +/// usual. +/// {@endtemplate} +/// +/// See also: +/// +/// * [IgnorePointer], which also prevents its children from receiving pointer +/// events but is itself invisible to hit testing. +class AbsorbPointer extends SingleChildRenderObjectWidget { + /// Creates a widget that absorbs pointers during hit testing. + const AbsorbPointer({ + super.key, + this.absorbing = true, + @Deprecated( + 'Use ExcludeSemantics or create a custom absorb pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + this.ignoringSemantics, + super.child, + }); + + /// Whether this widget absorbs pointers during hit testing. + /// + /// Regardless of whether this render object absorbs pointers during hit + /// testing, it will still consume space during layout and be visible during + /// painting. + /// + /// {@macro flutter.widgets.AbsorbPointer.semantics} + /// + /// Defaults to true. + final bool absorbing; + + /// Whether the semantics of this render object is ignored when compiling the + /// semantics tree. + /// + /// {@macro flutter.widgets.AbsorbPointer.ignoringSemantics} + /// + /// See [SemanticsNode] for additional information about the semantics tree. + @Deprecated( + 'Use ExcludeSemantics or create a custom absorb pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + final bool? ignoringSemantics; + + @override + RenderAbsorbPointer createRenderObject(BuildContext context) { + return RenderAbsorbPointer( + absorbing: absorbing, + ignoringSemantics: ignoringSemantics, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderAbsorbPointer renderObject) { + renderObject + ..absorbing = absorbing + ..ignoringSemantics = ignoringSemantics; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('absorbing', absorbing)); + properties.add(DiagnosticsProperty<bool>('ignoringSemantics', ignoringSemantics, defaultValue: null)); + } +} + +/// Holds opaque meta data in the render tree. +/// +/// Useful for decorating the render tree with information that will be consumed +/// later. For example, you could store information in the render tree that will +/// be used when the user interacts with the render tree but has no visual +/// impact prior to the interaction. +class MetaData extends SingleChildRenderObjectWidget { + /// Creates a widget that hold opaque meta data. + /// + /// The [behavior] argument defaults to [HitTestBehavior.deferToChild]. + const MetaData({ + super.key, + this.metaData, + this.behavior = HitTestBehavior.deferToChild, + super.child, + }); + + /// Opaque meta data ignored by the render tree. + final dynamic metaData; + + /// How to behave during hit testing. + final HitTestBehavior behavior; + + @override + RenderMetaData createRenderObject(BuildContext context) { + return RenderMetaData( + metaData: metaData, + behavior: behavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderMetaData renderObject) { + renderObject + ..metaData = metaData + ..behavior = behavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<HitTestBehavior>('behavior', behavior)); + properties.add(DiagnosticsProperty<dynamic>('metaData', metaData)); + } +} + + +// UTILITY NODES + +/// A widget that annotates the widget tree with a description of the meaning of +/// the widgets. +/// +/// Used by assistive technologies, search engines, and other semantic analysis +/// software to determine the meaning of the application. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=NvtMt_DtFrQ} +/// +/// See also: +/// +/// * [SemanticsProperties], which contains a complete documentation for each +/// of the constructor parameters that belongs to semantics properties. +/// * [MergeSemantics], which marks a subtree as being a single node for +/// accessibility purposes. +/// * [ExcludeSemantics], which excludes a subtree from the semantics tree +/// (which might be useful if it is, e.g., totally decorative and not +/// important to the user). +/// * [RenderObject.describeSemanticsConfiguration], the rendering library API +/// through which the [Semantics] widget is actually implemented. +/// * [SemanticsNode], the object used by the rendering library to represent +/// semantics in the semantics tree. +/// * [SemanticsDebugger], an overlay to help visualize the semantics tree. Can +/// be enabled using [WidgetsApp.showSemanticsDebugger], +/// [MaterialApp.showSemanticsDebugger], or [CupertinoApp.showSemanticsDebugger]. +@immutable +class Semantics extends SingleChildRenderObjectWidget { + /// Creates a semantic annotation. + /// + /// To create a `const` instance of [Semantics], use the + /// [Semantics.fromProperties] constructor. + /// + /// See also: + /// + /// * [SemanticsProperties], which contains a complete documentation for each + /// of the constructor parameters that belongs to semantics properties. + /// * [SemanticsSortKey] for a class that determines accessibility traversal + /// order. + Semantics({ + Key? key, + Widget? child, + bool container = false, + bool explicitChildNodes = false, + bool excludeSemantics = false, + bool blockUserActions = false, + bool? enabled, + bool? checked, + bool? mixed, + bool? selected, + bool? toggled, + bool? button, + bool? slider, + bool? keyboardKey, + bool? link, + bool? header, + bool? textField, + bool? readOnly, + bool? focusable, + bool? focused, + bool? inMutuallyExclusiveGroup, + bool? obscured, + bool? multiline, + bool? scopesRoute, + bool? namesRoute, + bool? hidden, + bool? image, + bool? liveRegion, + bool? expanded, + int? maxValueLength, + int? currentValueLength, + String? identifier, + String? label, + AttributedString? attributedLabel, + String? value, + AttributedString? attributedValue, + String? increasedValue, + AttributedString? attributedIncreasedValue, + String? decreasedValue, + AttributedString? attributedDecreasedValue, + String? hint, + AttributedString? attributedHint, + String? tooltip, + String? onTapHint, + String? onLongPressHint, + TextDirection? textDirection, + SemanticsSortKey? sortKey, + SemanticsTag? tagForChildren, + VoidCallback? onTap, + VoidCallback? onLongPress, + VoidCallback? onScrollLeft, + VoidCallback? onScrollRight, + VoidCallback? onScrollUp, + VoidCallback? onScrollDown, + VoidCallback? onIncrease, + VoidCallback? onDecrease, + VoidCallback? onCopy, + VoidCallback? onCut, + VoidCallback? onPaste, + VoidCallback? onDismiss, + MoveCursorHandler? onMoveCursorForwardByCharacter, + MoveCursorHandler? onMoveCursorBackwardByCharacter, + SetSelectionHandler? onSetSelection, + SetTextHandler? onSetText, + VoidCallback? onDidGainAccessibilityFocus, + VoidCallback? onDidLoseAccessibilityFocus, + Map<CustomSemanticsAction, VoidCallback>? customSemanticsActions, + }) : this.fromProperties( + key: key, + child: child, + container: container, + explicitChildNodes: explicitChildNodes, + excludeSemantics: excludeSemantics, + blockUserActions: blockUserActions, + properties: SemanticsProperties( + enabled: enabled, + checked: checked, + mixed: mixed, + expanded: expanded, + toggled: toggled, + selected: selected, + button: button, + slider: slider, + keyboardKey: keyboardKey, + link: link, + header: header, + textField: textField, + readOnly: readOnly, + focusable: focusable, + focused: focused, + inMutuallyExclusiveGroup: inMutuallyExclusiveGroup, + obscured: obscured, + multiline: multiline, + scopesRoute: scopesRoute, + namesRoute: namesRoute, + hidden: hidden, + image: image, + liveRegion: liveRegion, + maxValueLength: maxValueLength, + currentValueLength: currentValueLength, + identifier: identifier, + label: label, + attributedLabel: attributedLabel, + value: value, + attributedValue: attributedValue, + increasedValue: increasedValue, + attributedIncreasedValue: attributedIncreasedValue, + decreasedValue: decreasedValue, + attributedDecreasedValue: attributedDecreasedValue, + hint: hint, + attributedHint: attributedHint, + tooltip: tooltip, + textDirection: textDirection, + sortKey: sortKey, + tagForChildren: tagForChildren, + onTap: onTap, + onLongPress: onLongPress, + onScrollLeft: onScrollLeft, + onScrollRight: onScrollRight, + onScrollUp: onScrollUp, + onScrollDown: onScrollDown, + onIncrease: onIncrease, + onDecrease: onDecrease, + onCopy: onCopy, + onCut: onCut, + onPaste: onPaste, + onMoveCursorForwardByCharacter: onMoveCursorForwardByCharacter, + onMoveCursorBackwardByCharacter: onMoveCursorBackwardByCharacter, + onDidGainAccessibilityFocus: onDidGainAccessibilityFocus, + onDidLoseAccessibilityFocus: onDidLoseAccessibilityFocus, + onDismiss: onDismiss, + onSetSelection: onSetSelection, + onSetText: onSetText, + customSemanticsActions: customSemanticsActions, + hintOverrides: onTapHint != null || onLongPressHint != null ? + SemanticsHintOverrides( + onTapHint: onTapHint, + onLongPressHint: onLongPressHint, + ) : null, + ), + ); + + /// Creates a semantic annotation using [SemanticsProperties]. + const Semantics.fromProperties({ + super.key, + super.child, + this.container = false, + this.explicitChildNodes = false, + this.excludeSemantics = false, + this.blockUserActions = false, + required this.properties, + }); + + /// Contains properties used by assistive technologies to make the application + /// more accessible. + final SemanticsProperties properties; + + /// If [container] is true, this widget will introduce a new + /// node in the semantics tree. Otherwise, the semantics will be + /// merged with the semantics of any ancestors (if the ancestor allows that). + /// + /// Whether descendants of this widget can add their semantic information to the + /// [SemanticsNode] introduced by this configuration is controlled by + /// [explicitChildNodes]. + final bool container; + + /// Whether descendants of this widget are allowed to add semantic information + /// to the [SemanticsNode] annotated by this widget. + /// + /// When set to false descendants are allowed to annotate [SemanticsNode]s of + /// their parent with the semantic information they want to contribute to the + /// semantic tree. + /// When set to true the only way for descendants to contribute semantic + /// information to the semantic tree is to introduce new explicit + /// [SemanticsNode]s to the tree. + /// + /// If the semantics properties of this node include + /// [SemanticsProperties.scopesRoute] set to true, then [explicitChildNodes] + /// must be true also. + /// + /// This setting is often used in combination with [SemanticsConfiguration.isSemanticBoundary] + /// to create semantic boundaries that are either writable or not for children. + final bool explicitChildNodes; + + /// Whether to replace all child semantics with this node. + /// + /// Defaults to false. + /// + /// When this flag is set to true, all child semantics nodes are ignored. + /// This can be used as a convenience for cases where a child is wrapped in + /// an [ExcludeSemantics] widget and then another [Semantics] widget. + final bool excludeSemantics; + + /// Whether to block user interactions for the rendering subtree. + /// + /// Setting this to true will prevent users from interacting with The + /// rendering object configured by this widget and its subtree through + /// pointer-related [SemanticsAction]s in assistive technologies. + /// + /// The [SemanticsNode] created from this widget is still focusable by + /// assistive technologies. Only pointer-related [SemanticsAction]s, such as + /// [SemanticsAction.tap] or its friends, are blocked. + /// + /// If this widget is merged into a parent semantics node, only the + /// [SemanticsAction]s of this widget and the widgets in the subtree are + /// blocked. + /// + /// For example: + /// ```dart + /// void _myTap() { } + /// void _myLongPress() { } + /// + /// Widget build(BuildContext context) { + /// return Semantics( + /// onTap: _myTap, + /// child: Semantics( + /// blockUserActions: true, + /// onLongPress: _myLongPress, + /// child: const Text('label'), + /// ), + /// ); + /// } + /// ``` + /// + /// The result semantics node will still have `_myTap`, but the `_myLongPress` + /// will be blocked. + final bool blockUserActions; + + @override + RenderSemanticsAnnotations createRenderObject(BuildContext context) { + return RenderSemanticsAnnotations( + container: container, + explicitChildNodes: explicitChildNodes, + excludeSemantics: excludeSemantics, + blockUserActions: blockUserActions, + properties: properties, + textDirection: _getTextDirection(context), + ); + } + + TextDirection? _getTextDirection(BuildContext context) { + if (properties.textDirection != null) { + return properties.textDirection; + } + + final bool containsText = properties.attributedLabel != null || + properties.label != null || + properties.value != null || + properties.hint != null || + properties.tooltip != null; + + if (!containsText) { + return null; + } + + return Directionality.maybeOf(context); + } + + @override + void updateRenderObject(BuildContext context, RenderSemanticsAnnotations renderObject) { + renderObject + ..container = container + ..explicitChildNodes = explicitChildNodes + ..excludeSemantics = excludeSemantics + ..blockUserActions = blockUserActions + ..properties = properties + ..textDirection = _getTextDirection(context); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('container', container)); + properties.add(DiagnosticsProperty<SemanticsProperties>('properties', this.properties)); + this.properties.debugFillProperties(properties); + } +} + +/// A widget that merges the semantics of its descendants. +/// +/// Causes all the semantics of the subtree rooted at this node to be +/// merged into one node in the semantics tree. For example, if you +/// have a widget with a Text node next to a checkbox widget, this +/// could be used to merge the label from the Text node with the +/// "checked" semantic state of the checkbox into a single node that +/// had both the label and the checked state. Otherwise, the label +/// would be presented as a separate feature than the checkbox, and +/// the user would not be able to be sure that they were related. +/// +/// {@tool snippet} +/// This snippet shows how to use [MergeSemantics] to merge the semantics of +/// a [Checkbox] and [Text] widget. +/// +/// ```dart +/// MergeSemantics( +/// child: Row( +/// children: <Widget>[ +/// Checkbox( +/// value: true, +/// onChanged: (bool? value) {}, +/// ), +/// const Text('Settings'), +/// ], +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// Be aware that if two nodes in the subtree have conflicting +/// semantics, the result may be nonsensical. For example, a subtree +/// with a checked checkbox and an unchecked checkbox will be +/// presented as checked. All the labels will be merged into a single +/// string (with newlines separating each label from the other). If +/// multiple nodes in the merged subtree can handle semantic gestures, +/// the first one in tree order will be the one to receive the +/// callbacks. +class MergeSemantics extends SingleChildRenderObjectWidget { + /// Creates a widget that merges the semantics of its descendants. + const MergeSemantics({ super.key, super.child }); + + @override + RenderMergeSemantics createRenderObject(BuildContext context) => RenderMergeSemantics(); +} + +/// A widget that drops the semantics of all widget that were painted before it +/// in the same semantic container. +/// +/// This is useful to hide widgets from accessibility tools that are painted +/// behind a certain widget, e.g. an alert should usually disallow interaction +/// with any widget located "behind" the alert (even when they are still +/// partially visible). Similarly, an open [Drawer] blocks interactions with +/// any widget outside the drawer. +/// +/// See also: +/// +/// * [ExcludeSemantics] which drops all semantics of its descendants. +class BlockSemantics extends SingleChildRenderObjectWidget { + /// Creates a widget that excludes the semantics of all widgets painted before + /// it in the same semantic container. + const BlockSemantics({ super.key, this.blocking = true, super.child }); + + /// Whether this widget is blocking semantics of all widget that were painted + /// before it in the same semantic container. + final bool blocking; + + @override + RenderBlockSemantics createRenderObject(BuildContext context) => RenderBlockSemantics(blocking: blocking); + + @override + void updateRenderObject(BuildContext context, RenderBlockSemantics renderObject) { + renderObject.blocking = blocking; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('blocking', blocking)); + } +} + +/// A widget that drops all the semantics of its descendants. +/// +/// When [excluding] is true, this widget (and its subtree) is excluded from +/// the semantics tree. +/// +/// This can be used to hide descendant widgets that would otherwise be +/// reported but that would only be confusing. For example, the +/// material library's [Chip] widget hides the avatar since it is +/// redundant with the chip label. +/// +/// See also: +/// +/// * [BlockSemantics] which drops semantics of widgets earlier in the tree. +class ExcludeSemantics extends SingleChildRenderObjectWidget { + /// Creates a widget that drops all the semantics of its descendants. + const ExcludeSemantics({ + super.key, + this.excluding = true, + super.child, + }); + + /// Whether this widget is excluded in the semantics tree. + final bool excluding; + + @override + RenderExcludeSemantics createRenderObject(BuildContext context) => RenderExcludeSemantics(excluding: excluding); + + @override + void updateRenderObject(BuildContext context, RenderExcludeSemantics renderObject) { + renderObject.excluding = excluding; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('excluding', excluding)); + } +} + +/// A widget that annotates the child semantics with an index. +/// +/// Semantic indexes are used by TalkBack/Voiceover to make announcements about +/// the current scroll state. Certain widgets like the [ListView] will +/// automatically provide a child index for building semantics. A user may wish +/// to manually provide semantic indexes if not all child of the scrollable +/// contribute semantics. +/// +/// {@tool snippet} +/// +/// The example below handles spacers in a scrollable that don't contribute +/// semantics. The automatic indexes would give the spaces a semantic index, +/// causing scroll announcements to erroneously state that there are four items +/// visible. +/// +/// ```dart +/// ListView( +/// addSemanticIndexes: false, +/// semanticChildCount: 2, +/// children: const <Widget>[ +/// IndexedSemantics(index: 0, child: Text('First')), +/// Spacer(), +/// IndexedSemantics(index: 1, child: Text('Second')), +/// Spacer(), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [CustomScrollView], for an explanation of index semantics. +class IndexedSemantics extends SingleChildRenderObjectWidget { + /// Creates a widget that annotated the first child semantics node with an index. + const IndexedSemantics({ + super.key, + required this.index, + super.child, + }); + + /// The index used to annotate the first child semantics node. + final int index; + + @override + RenderIndexedSemantics createRenderObject(BuildContext context) => RenderIndexedSemantics(index: index); + + @override + void updateRenderObject(BuildContext context, RenderIndexedSemantics renderObject) { + renderObject.index = index; + } + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<int>('index', index)); + } +} + +/// A widget that builds its child. +/// +/// Useful for attaching a key to an existing widget. +class KeyedSubtree extends StatelessWidget { + /// Creates a widget that builds its child. + const KeyedSubtree({ + super.key, + required this.child, + }); + + /// Creates a KeyedSubtree for child with a key that's based on the child's existing key or childIndex. + factory KeyedSubtree.wrap(Widget child, int childIndex) { + final Key key = child.key != null ? ValueKey<Key>(child.key!) : ValueKey<int>(childIndex); + return KeyedSubtree(key: key, child: child); + } + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// Wrap each item in a KeyedSubtree whose key is based on the item's existing key or + /// the sum of its list index and `baseIndex`. + static List<Widget> ensureUniqueKeysForList(List<Widget> items, { int baseIndex = 0 }) { + if (items.isEmpty) { + return items; + } + + final List<Widget> itemsWithUniqueKeys = <Widget>[]; + int itemIndex = baseIndex; + for (final Widget item in items) { + itemsWithUniqueKeys.add(KeyedSubtree.wrap(item, itemIndex)); + itemIndex += 1; + } + + assert(!debugItemsHaveDuplicateKeys(itemsWithUniqueKeys)); + return itemsWithUniqueKeys; + } + + @override + Widget build(BuildContext context) => child; +} + +/// A stateless utility widget whose [build] method uses its +/// [builder] callback to create the widget's child. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=xXNOkIuSYuA} +/// +/// This widget is an inline alternative to defining a [StatelessWidget] +/// subclass. For example, instead of defining a widget as follows: +/// +/// ```dart +/// class Foo extends StatelessWidget { +/// const Foo({super.key}); +/// @override +/// Widget build(BuildContext context) => const Text('foo'); +/// } +/// ``` +/// +/// ...and using it in the usual way: +/// +/// ```dart +/// // continuing from previous example... +/// const Center(child: Foo()) +/// ``` +/// +/// ...one could instead define and use it in a single step, without +/// defining a new widget class: +/// +/// ```dart +/// Center( +/// child: Builder( +/// builder: (BuildContext context) => const Text('foo'), +/// ), +/// ) +/// ``` +/// +/// The difference between either of the previous examples and +/// creating a child directly without an intervening widget, is the +/// extra [BuildContext] element that the additional widget adds. This +/// is particularly noticeable when the tree contains an inherited +/// widget that is referred to by a method like [Scaffold.of], +/// which visits the child widget's BuildContext ancestors. +/// +/// In the following example the button's `onPressed` callback is unable +/// to find the enclosing [ScaffoldState] with [Scaffold.of]: +/// +/// ```dart +/// Widget build(BuildContext context) { +/// return Scaffold( +/// body: Center( +/// child: TextButton( +/// onPressed: () { +/// // Fails because Scaffold.of() doesn't find anything +/// // above this widget's context. +/// print(Scaffold.of(context).hasAppBar); +/// }, +/// child: const Text('hasAppBar'), +/// ) +/// ), +/// ); +/// } +/// ``` +/// +/// A [Builder] widget introduces an additional [BuildContext] element +/// and so the [Scaffold.of] method succeeds. +/// +/// ```dart +/// Widget build(BuildContext context) { +/// return Scaffold( +/// body: Builder( +/// builder: (BuildContext context) { +/// return Center( +/// child: TextButton( +/// onPressed: () { +/// print(Scaffold.of(context).hasAppBar); +/// }, +/// child: const Text('hasAppBar'), +/// ), +/// ); +/// }, +/// ), +/// ); +/// } +/// ``` +/// +/// See also: +/// +/// * [StatefulBuilder], A stateful utility widget whose [build] method uses its +/// [builder] callback to create the widget's child. +class Builder extends StatelessWidget { + /// Creates a widget that delegates its build to a callback. + const Builder({ + super.key, + required this.builder, + }); + + /// Called to obtain the child widget. + /// + /// This function is called whenever this widget is included in its parent's + /// build and the old widget (if any) that it synchronizes with has a distinct + /// object identity. Typically the parent's build method will construct + /// a new tree of widgets and so a new Builder child will not be [identical] + /// to the corresponding old one. + final WidgetBuilder builder; + + @override + Widget build(BuildContext context) => builder(context); +} + +/// Signature for the builder callback used by [StatefulBuilder]. +/// +/// Call `setState` to schedule the [StatefulBuilder] to rebuild. +typedef StatefulWidgetBuilder = Widget Function(BuildContext context, StateSetter setState); + +/// A platonic widget that both has state and calls a closure to obtain its child widget. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=syvT63CosNE} +/// +/// The [StateSetter] function passed to the [builder] is used to invoke a +/// rebuild instead of a typical [State]'s [State.setState]. +/// +/// Since the [builder] is re-invoked when the [StateSetter] is called, any +/// variables that represents state should be kept outside the [builder] function. +/// +/// {@tool snippet} +/// +/// This example shows using an inline StatefulBuilder that rebuilds and that +/// also has state. +/// +/// ```dart +/// await showDialog<void>( +/// context: context, +/// builder: (BuildContext context) { +/// int? selectedRadio = 0; +/// return AlertDialog( +/// content: StatefulBuilder( +/// builder: (BuildContext context, StateSetter setState) { +/// return Column( +/// mainAxisSize: MainAxisSize.min, +/// children: List<Widget>.generate(4, (int index) { +/// return Radio<int>( +/// value: index, +/// groupValue: selectedRadio, +/// onChanged: (int? value) { +/// setState(() => selectedRadio = value); +/// }, +/// ); +/// }), +/// ); +/// }, +/// ), +/// ); +/// }, +/// ); +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Builder], the platonic stateless widget. +class StatefulBuilder extends StatefulWidget { + /// Creates a widget that both has state and delegates its build to a callback. + const StatefulBuilder({ + super.key, + required this.builder, + }); + + /// Called to obtain the child widget. + /// + /// This function is called whenever this widget is included in its parent's + /// build and the old widget (if any) that it synchronizes with has a distinct + /// object identity. Typically the parent's build method will construct + /// a new tree of widgets and so a new Builder child will not be [identical] + /// to the corresponding old one. + final StatefulWidgetBuilder builder; + + @override + State<StatefulBuilder> createState() => _StatefulBuilderState(); +} + +class _StatefulBuilderState extends State<StatefulBuilder> { + @override + Widget build(BuildContext context) => widget.builder(context, setState); +} + +/// A widget that paints its area with a specified [Color] and then draws its +/// child on top of that color. +class ColoredBox extends SingleChildRenderObjectWidget { + /// Creates a widget that paints its area with the specified [Color]. + const ColoredBox({ required this.color, super.child, super.key }); + + /// The color to paint the background area with. + final Color color; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderColoredBox(color: color); + } + + @override + void updateRenderObject(BuildContext context, RenderObject renderObject) { + (renderObject as _RenderColoredBox).color = color; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Color>('color', color)); + } +} + +class _RenderColoredBox extends RenderProxyBoxWithHitTestBehavior { + _RenderColoredBox({ required Color color }) + : _color = color, + super(behavior: HitTestBehavior.opaque); + + /// The fill color for this render object. + Color get color => _color; + Color _color; + set color(Color value) { + if (value == _color) { + return; + } + _color = value; + markNeedsPaint(); + } + + @override + void paint(PaintingContext context, Offset offset) { + // It's tempting to want to optimize out this `drawRect()` call if the + // color is transparent (alpha==0), but doing so would be incorrect. See + // https://github.com/flutter/flutter/pull/72526#issuecomment-749185938 for + // a good description of why. + if (size > Size.zero) { + context.canvas.drawRect(offset & size, Paint()..color = color); + } + if (child != null) { + context.paintChild(child!, offset); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/binding.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/binding.dart new file mode 100644 index 0000000000000000000000000000000000000000..44a6b3189eae8d7fa9fb60ed1373bdffb51e32ee --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/binding.dart @@ -0,0 +1,1411 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:developer' as developer; +import 'dart:ui' show AccessibilityFeatures, AppExitResponse, AppLifecycleState, FrameTiming, Locale, PlatformDispatcher, TimingsCallback; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'app.dart'; +import 'debug.dart'; +import 'focus_manager.dart'; +import 'framework.dart'; +import 'platform_menu_bar.dart'; +import 'router.dart'; +import 'service_extensions.dart'; +import 'view.dart'; +import 'widget_inspector.dart'; + +export 'dart:ui' show AppLifecycleState, Locale; + +/// Interface for classes that register with the Widgets layer binding. +/// +/// This can be used by any class, not just widgets. It provides an interface +/// which is used by [WidgetsBinding.addObserver] and +/// [WidgetsBinding.removeObserver] to notify objects of changes in the +/// environment, such as changes to the device metrics or accessibility +/// settings. It is used to implement features such as [MediaQuery]. +/// +/// This class can be extended directly, or mixed in, to get default behaviors +/// for all of the handlers. Alternatively it can be used with the +/// `implements` keyword, in which case all the handlers must be implemented +/// (and the analyzer will list those that have been omitted). +/// +/// To start receiving notifications, call `WidgetsBinding.instance.addObserver` +/// with a reference to the object implementing the [WidgetsBindingObserver] +/// interface. To avoid memory leaks, call +/// `WidgetsBinding.instance.removeObserver` to unregister the object when it +/// reaches the end of its lifecycle. +/// +/// {@tool dartpad} +/// This sample shows how to implement parts of the [State] and +/// [WidgetsBindingObserver] protocols necessary to react to application +/// lifecycle messages. See [didChangeAppLifecycleState]. +/// +/// To respond to other notifications, replace the [didChangeAppLifecycleState] +/// method in this example with other methods from this class. +/// +/// ** See code in examples/api/lib/widgets/binding/widget_binding_observer.0.dart ** +/// {@end-tool} +abstract mixin class WidgetsBindingObserver { + /// Called when the system tells the app to pop the current route, such as + /// after a system back button press or back gesture. + /// + /// Observers are notified in registration order until one returns + /// true. If none return true, the application quits. + /// + /// Observers are expected to return true if they were able to + /// handle the notification, for example by closing an active dialog + /// box, and false otherwise. The [WidgetsApp] widget uses this + /// mechanism to notify the [Navigator] widget that it should pop + /// its current route if possible. + /// + /// This method exposes the `popRoute` notification from + /// [SystemChannels.navigation]. + /// + /// {@macro flutter.widgets.AndroidPredictiveBack} + Future<bool> didPopRoute() => Future<bool>.value(false); + + /// Called when the host tells the application to push a new route onto the + /// navigator. + /// + /// Observers are expected to return true if they were able to + /// handle the notification. Observers are notified in registration + /// order until one returns true. + /// + /// This method exposes the `pushRoute` notification from + /// [SystemChannels.navigation]. + @Deprecated( + 'Use didPushRouteInformation instead. ' + 'This feature was deprecated after v3.8.0-14.0.pre.' + ) + Future<bool> didPushRoute(String route) => Future<bool>.value(false); + + /// Called when the host tells the application to push a new + /// [RouteInformation] and a restoration state onto the router. + /// + /// Observers are expected to return true if they were able to + /// handle the notification. Observers are notified in registration + /// order until one returns true. + /// + /// This method exposes the `pushRouteInformation` notification from + /// [SystemChannels.navigation]. + /// + /// The default implementation is to call the [didPushRoute] directly with the + /// string constructed from [RouteInformation.uri]'s path and query parameters. + // TODO(chunhtai): remove the default implementation once `didPushRoute` is + // removed. + Future<bool> didPushRouteInformation(RouteInformation routeInformation) { + final Uri uri = routeInformation.uri; + return didPushRoute( + Uri.decodeComponent( + Uri( + path: uri.path.isEmpty ? '/' : uri.path, + queryParameters: uri.queryParametersAll.isEmpty ? null : uri.queryParametersAll, + fragment: uri.fragment.isEmpty ? null : uri.fragment, + ).toString(), + ), + ); + } + + /// Called when the application's dimensions change. For example, + /// when a phone is rotated. + /// + /// This method exposes notifications from + /// [dart:ui.PlatformDispatcher.onMetricsChanged]. + /// + /// {@tool snippet} + /// + /// This [StatefulWidget] implements the parts of the [State] and + /// [WidgetsBindingObserver] protocols necessary to react when the device is + /// rotated (or otherwise changes dimensions). + /// + /// ```dart + /// class MetricsReactor extends StatefulWidget { + /// const MetricsReactor({ super.key }); + /// + /// @override + /// State<MetricsReactor> createState() => _MetricsReactorState(); + /// } + /// + /// class _MetricsReactorState extends State<MetricsReactor> with WidgetsBindingObserver { + /// late Size _lastSize; + /// + /// @override + /// void initState() { + /// super.initState(); + /// WidgetsBinding.instance.addObserver(this); + /// } + /// + /// @override + /// void didChangeDependencies() { + /// super.didChangeDependencies(); + /// // [View.of] exposes the view from `WidgetsBinding.instance.platformDispatcher.views` + /// // into which this widget is drawn. + /// _lastSize = View.of(context).physicalSize; + /// } + /// + /// @override + /// void dispose() { + /// WidgetsBinding.instance.removeObserver(this); + /// super.dispose(); + /// } + /// + /// @override + /// void didChangeMetrics() { + /// setState(() { _lastSize = View.of(context).physicalSize; }); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// return Text('Current size: $_lastSize'); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// In general, this is unnecessary as the layout system takes care of + /// automatically recomputing the application geometry when the application + /// size changes. + /// + /// See also: + /// + /// * [MediaQuery.sizeOf], which provides a similar service with less + /// boilerplate. + void didChangeMetrics() { } + + /// Called when the platform's text scale factor changes. + /// + /// This typically happens as the result of the user changing system + /// preferences, and it should affect all of the text sizes in the + /// application. + /// + /// This method exposes notifications from + /// [dart:ui.PlatformDispatcher.onTextScaleFactorChanged]. + /// + /// {@tool snippet} + /// + /// ```dart + /// class TextScaleFactorReactor extends StatefulWidget { + /// const TextScaleFactorReactor({ super.key }); + /// + /// @override + /// State<TextScaleFactorReactor> createState() => _TextScaleFactorReactorState(); + /// } + /// + /// class _TextScaleFactorReactorState extends State<TextScaleFactorReactor> with WidgetsBindingObserver { + /// @override + /// void initState() { + /// super.initState(); + /// WidgetsBinding.instance.addObserver(this); + /// } + /// + /// @override + /// void dispose() { + /// WidgetsBinding.instance.removeObserver(this); + /// super.dispose(); + /// } + /// + /// late double _lastTextScaleFactor; + /// + /// @override + /// void didChangeTextScaleFactor() { + /// setState(() { _lastTextScaleFactor = WidgetsBinding.instance.platformDispatcher.textScaleFactor; }); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// return Text('Current scale factor: $_lastTextScaleFactor'); + /// } + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [MediaQuery.textScaleFactorOf], which provides a similar service with less + /// boilerplate. + void didChangeTextScaleFactor() { } + + /// Called when the platform brightness changes. + /// + /// This method exposes notifications from + /// [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged]. + /// + /// See also: + /// + /// * [MediaQuery.platformBrightnessOf], which provides a similar service with + /// less boilerplate. + void didChangePlatformBrightness() { } + + /// Called when the system tells the app that the user's locale has + /// changed. For example, if the user changes the system language + /// settings. + /// + /// This method exposes notifications from + /// [dart:ui.PlatformDispatcher.onLocaleChanged]. + void didChangeLocales(List<Locale>? locales) { } + + /// Called when the system puts the app in the background or returns + /// the app to the foreground. + /// + /// An example of implementing this method is provided in the class-level + /// documentation for the [WidgetsBindingObserver] class. + /// + /// This method exposes notifications from [SystemChannels.lifecycle]. + /// + /// See also: + /// + /// * [AppLifecycleListener], an alternative API for responding to + /// application lifecycle changes. + void didChangeAppLifecycleState(AppLifecycleState state) { } + + /// Called when a request is received from the system to exit the application. + /// + /// If any observer responds with [AppExitResponse.cancel], it will cancel the + /// exit. All observers will be asked before exiting. + /// + /// {@macro flutter.services.binding.ServicesBinding.requestAppExit} + /// + /// See also: + /// + /// * [ServicesBinding.exitApplication] for a function to call that will request + /// that the application exits. + Future<AppExitResponse> didRequestAppExit() async { + return AppExitResponse.exit; + } + + /// Called when the system is running low on memory. + /// + /// This method exposes the `memoryPressure` notification from + /// [SystemChannels.system]. + void didHaveMemoryPressure() { } + + /// Called when the system changes the set of currently active accessibility + /// features. + /// + /// This method exposes notifications from + /// [dart:ui.PlatformDispatcher.onAccessibilityFeaturesChanged]. + void didChangeAccessibilityFeatures() { } +} + +/// The glue between the widgets layer and the Flutter engine. +/// +/// The [WidgetsBinding] manages a single [Element] tree rooted at [rootElement]. +/// Calling [runApp] (which indirectly calls [attachRootWidget]) bootstraps that +/// element tree. +/// +/// ## Relationship to render trees +/// +/// Multiple render trees may be associated with the element tree. Those are +/// managed by the underlying [RendererBinding]. +/// +/// The element tree is segmented into two types of zones: rendering zones and +/// non-rendering zones. +/// +/// A rendering zone is a part of the element tree that is backed by a render +/// tree and it describes the pixels that are drawn on screen. For elements in +/// this zone, [Element.renderObject] never returns null because the elements +/// are all associated with [RenderObject]s. Almost all widgets can be placed in +/// a rendering zone; notable exceptions are the [View] widget, [ViewCollection] +/// widget, and [RootWidget]. +/// +/// A non-rendering zone is a part of the element tree that is not backed by a +/// render tree. For elements in this zone, [Element.renderObject] returns null +/// because the elements are not associated with any [RenderObject]s. Only +/// widgets that do not produce a [RenderObject] can be used in this zone +/// because there is no render tree to attach the render object to. In other +/// words, [RenderObjectWidget]s cannot be used in this zone. Typically, one +/// would find [InheritedWidget]s, [View]s, and [ViewCollection]s in this zone +/// to inject data across rendering zones into the tree and to organize the +/// rendering zones (and by extension their associated render trees) into a +/// unified element tree. +/// +/// The root of the element tree at [rootElement] starts a non-rendering zone. +/// Within a non-rendering zone, the [View] widget is used to start a rendering +/// zone by bootstrapping a render tree. Within a rendering zone, the +/// [ViewAnchor] can be used to start a new non-rendering zone. +/// +// TODO(goderbauer): Include an example graph showcasing the different zones. +/// +/// To figure out if an element is in a rendering zone it may walk up the tree +/// calling [Element.debugExpectsRenderObjectForSlot] on its ancestors. If it +/// reaches an element that returns false, it is in a non-rendering zone. If it +/// reaches a [RenderObjectElement] ancestor it is in a rendering zone. +mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureBinding, RendererBinding, SemanticsBinding { + @override + void initInstances() { + super.initInstances(); + _instance = this; + + assert(() { + _debugAddStackFilters(); + return true; + }()); + + // Initialization of [_buildOwner] has to be done after + // [super.initInstances] is called, as it requires [ServicesBinding] to + // properly setup the [defaultBinaryMessenger] instance. + _buildOwner = BuildOwner(); + buildOwner!.onBuildScheduled = _handleBuildScheduled; + platformDispatcher.onLocaleChanged = handleLocaleChanged; + SystemChannels.navigation.setMethodCallHandler(_handleNavigationInvocation); + assert(() { + FlutterErrorDetails.propertiesTransformers.add(debugTransformDebugCreator); + return true; + }()); + platformMenuDelegate = DefaultPlatformMenuDelegate(); + } + + /// The current [WidgetsBinding], if one has been created. + /// + /// Provides access to the features exposed by this mixin. The binding must + /// be initialized before using this getter; this is typically done by calling + /// [runApp] or [WidgetsFlutterBinding.ensureInitialized]. + static WidgetsBinding get instance => BindingBase.checkInstance(_instance); + static WidgetsBinding? _instance; + + void _debugAddStackFilters() { + const PartialStackFrame elementInflateWidget = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'Element', method: 'inflateWidget'); + const PartialStackFrame elementUpdateChild = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'Element', method: 'updateChild'); + const PartialStackFrame elementRebuild = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'Element', method: 'rebuild'); + const PartialStackFrame componentElementPerformRebuild = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'ComponentElement', method: 'performRebuild'); + const PartialStackFrame componentElementFirstBuild = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'ComponentElement', method: '_firstBuild'); + const PartialStackFrame componentElementMount = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'ComponentElement', method: 'mount'); + const PartialStackFrame statefulElementFirstBuild = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'StatefulElement', method: '_firstBuild'); + const PartialStackFrame singleChildMount = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'SingleChildRenderObjectElement', method: 'mount'); + const PartialStackFrame statefulElementRebuild = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'StatefulElement', method: 'performRebuild'); + + const String replacementString = '... Normal element mounting'; + + // ComponentElement variations + FlutterError.addDefaultStackFilter(const RepetitiveStackFrameFilter( + frames: <PartialStackFrame>[ + elementInflateWidget, + elementUpdateChild, + componentElementPerformRebuild, + elementRebuild, + componentElementFirstBuild, + componentElementMount, + ], + replacement: replacementString, + )); + FlutterError.addDefaultStackFilter(const RepetitiveStackFrameFilter( + frames: <PartialStackFrame>[ + elementUpdateChild, + componentElementPerformRebuild, + elementRebuild, + componentElementFirstBuild, + componentElementMount, + ], + replacement: replacementString, + )); + + // StatefulElement variations + FlutterError.addDefaultStackFilter(const RepetitiveStackFrameFilter( + frames: <PartialStackFrame>[ + elementInflateWidget, + elementUpdateChild, + componentElementPerformRebuild, + statefulElementRebuild, + elementRebuild, + componentElementFirstBuild, + statefulElementFirstBuild, + componentElementMount, + ], + replacement: replacementString, + )); + FlutterError.addDefaultStackFilter(const RepetitiveStackFrameFilter( + frames: <PartialStackFrame>[ + elementUpdateChild, + componentElementPerformRebuild, + statefulElementRebuild, + elementRebuild, + componentElementFirstBuild, + statefulElementFirstBuild, + componentElementMount, + ], + replacement: replacementString, + )); + + // SingleChildRenderObjectElement variations + FlutterError.addDefaultStackFilter(const RepetitiveStackFrameFilter( + frames: <PartialStackFrame>[ + elementInflateWidget, + elementUpdateChild, + singleChildMount, + ], + replacement: replacementString, + )); + FlutterError.addDefaultStackFilter(const RepetitiveStackFrameFilter( + frames: <PartialStackFrame>[ + elementUpdateChild, + singleChildMount, + ], + replacement: replacementString, + )); + } + + @override + void initServiceExtensions() { + super.initServiceExtensions(); + + if (!kReleaseMode) { + registerServiceExtension( + name: WidgetsServiceExtensions.debugDumpApp.name, + callback: (Map<String, String> parameters) async { + final String data = _debugDumpAppString(); + return <String, Object>{ + 'data': data, + }; + }, + ); + + registerServiceExtension( + name: WidgetsServiceExtensions.debugDumpFocusTree.name, + callback: (Map<String, String> parameters) async { + final String data = focusManager.toStringDeep(); + return <String, Object>{ + 'data': data, + }; + }, + ); + + if (!kIsWeb) { + registerBoolServiceExtension( + name: WidgetsServiceExtensions.showPerformanceOverlay.name, + getter: () => + Future<bool>.value(WidgetsApp.showPerformanceOverlayOverride), + setter: (bool value) { + if (WidgetsApp.showPerformanceOverlayOverride == value) { + return Future<void>.value(); + } + WidgetsApp.showPerformanceOverlayOverride = value; + return _forceRebuild(); + }, + ); + } + + registerServiceExtension( + name: WidgetsServiceExtensions.didSendFirstFrameEvent.name, + callback: (_) async { + return <String, dynamic>{ + // This is defined to return a STRING, not a boolean. + // Devtools, the Intellij plugin, and the flutter tool all depend + // on it returning a string and not a boolean. + 'enabled': _needToReportFirstFrame ? 'false' : 'true', + }; + }, + ); + + registerServiceExtension( + name: WidgetsServiceExtensions.didSendFirstFrameRasterizedEvent.name, + callback: (_) async { + return <String, dynamic>{ + // This is defined to return a STRING, not a boolean. + // Devtools, the Intellij plugin, and the flutter tool all depend + // on it returning a string and not a boolean. + 'enabled': firstFrameRasterized ? 'true' : 'false', + }; + }, + ); + + // Expose the ability to send Widget rebuilds as [Timeline] events. + registerBoolServiceExtension( + name: WidgetsServiceExtensions.profileWidgetBuilds.name, + getter: () async => debugProfileBuildsEnabled, + setter: (bool value) async { + debugProfileBuildsEnabled = value; + } + ); + registerBoolServiceExtension( + name: WidgetsServiceExtensions.profileUserWidgetBuilds.name, + getter: () async => debugProfileBuildsEnabledUserWidgets, + setter: (bool value) async { + debugProfileBuildsEnabledUserWidgets = value; + } + ); + } + + assert(() { + registerBoolServiceExtension( + name: WidgetsServiceExtensions.debugAllowBanner.name, + getter: () => Future<bool>.value(WidgetsApp.debugAllowBannerOverride), + setter: (bool value) { + if (WidgetsApp.debugAllowBannerOverride == value) { + return Future<void>.value(); + } + WidgetsApp.debugAllowBannerOverride = value; + return _forceRebuild(); + }, + ); + + WidgetInspectorService.instance.initServiceExtensions(registerServiceExtension); + + return true; + }()); + } + + Future<void> _forceRebuild() { + if (rootElement != null) { + buildOwner!.reassemble(rootElement!); + return endOfFrame; + } + return Future<void>.value(); + } + + /// The [BuildOwner] in charge of executing the build pipeline for the + /// widget tree rooted at this binding. + BuildOwner? get buildOwner => _buildOwner; + // Initialization of [_buildOwner] has to be done within the [initInstances] + // method, as it requires [ServicesBinding] to properly setup the + // [defaultBinaryMessenger] instance. + BuildOwner? _buildOwner; + + /// The object in charge of the focus tree. + /// + /// Rarely used directly. Instead, consider using [FocusScope.of] to obtain + /// the [FocusScopeNode] for a given [BuildContext]. + /// + /// See [FocusManager] for more details. + FocusManager get focusManager => _buildOwner!.focusManager; + + /// A delegate that communicates with a platform plugin for serializing and + /// managing platform-rendered menu bars created by [PlatformMenuBar]. + /// + /// This is set by default to a [DefaultPlatformMenuDelegate] instance in + /// [initInstances]. + late PlatformMenuDelegate platformMenuDelegate; + + final List<WidgetsBindingObserver> _observers = <WidgetsBindingObserver>[]; + + /// Registers the given object as a binding observer. Binding + /// observers are notified when various application events occur, + /// for example when the system locale changes. Generally, one + /// widget in the widget tree registers itself as a binding + /// observer, and converts the system state into inherited widgets. + /// + /// For example, the [WidgetsApp] widget registers as a binding + /// observer and passes the screen size to a [MediaQuery] widget + /// each time it is built, which enables other widgets to use the + /// [MediaQuery.sizeOf] static method and (implicitly) the + /// [InheritedWidget] mechanism to be notified whenever the screen + /// size changes (e.g. whenever the screen rotates). + /// + /// See also: + /// + /// * [removeObserver], to release the resources reserved by this method. + /// * [WidgetsBindingObserver], which has an example of using this method. + void addObserver(WidgetsBindingObserver observer) => _observers.add(observer); + + /// Unregisters the given observer. This should be used sparingly as + /// it is relatively expensive (O(N) in the number of registered + /// observers). + /// + /// See also: + /// + /// * [addObserver], for the method that adds observers in the first place. + /// * [WidgetsBindingObserver], which has an example of using this method. + bool removeObserver(WidgetsBindingObserver observer) => _observers.remove(observer); + + @override + Future<AppExitResponse> handleRequestAppExit() async { + bool didCancel = false; + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + if ((await observer.didRequestAppExit()) == AppExitResponse.cancel) { + didCancel = true; + // Don't early return. For the case where someone is just using the + // observer to know when exit happens, we want to call all the + // observers, even if we already know we're going to cancel. + } + } + return didCancel ? AppExitResponse.cancel : AppExitResponse.exit; + } + + @override + void handleMetricsChanged() { + super.handleMetricsChanged(); + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + observer.didChangeMetrics(); + } + } + + @override + void handleTextScaleFactorChanged() { + super.handleTextScaleFactorChanged(); + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + observer.didChangeTextScaleFactor(); + } + } + + @override + void handlePlatformBrightnessChanged() { + super.handlePlatformBrightnessChanged(); + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + observer.didChangePlatformBrightness(); + } + } + + @override + void handleAccessibilityFeaturesChanged() { + super.handleAccessibilityFeaturesChanged(); + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + observer.didChangeAccessibilityFeatures(); + } + } + + /// Called when the system locale changes. + /// + /// Calls [dispatchLocalesChanged] to notify the binding observers. + /// + /// See [dart:ui.PlatformDispatcher.onLocaleChanged]. + @protected + @mustCallSuper + @visibleForTesting + void handleLocaleChanged() { + dispatchLocalesChanged(platformDispatcher.locales); + } + + /// Notify all the observers that the locale has changed (using + /// [WidgetsBindingObserver.didChangeLocales]), giving them the + /// `locales` argument. + /// + /// This is called by [handleLocaleChanged] when the + /// [PlatformDispatcher.onLocaleChanged] notification is received. + @protected + @mustCallSuper + void dispatchLocalesChanged(List<Locale>? locales) { + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + observer.didChangeLocales(locales); + } + } + + /// Notify all the observers that the active set of [AccessibilityFeatures] + /// has changed (using [WidgetsBindingObserver.didChangeAccessibilityFeatures]), + /// giving them the `features` argument. + /// + /// This is called by [handleAccessibilityFeaturesChanged] when the + /// [PlatformDispatcher.onAccessibilityFeaturesChanged] notification is received. + @protected + @mustCallSuper + void dispatchAccessibilityFeaturesChanged() { + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + observer.didChangeAccessibilityFeatures(); + } + } + + /// Called when the system pops the current route. + /// + /// This first notifies the binding observers (using + /// [WidgetsBindingObserver.didPopRoute]), in registration order, until one + /// returns true, meaning that it was able to handle the request (e.g. by + /// closing a dialog box). If none return true, then the application is shut + /// down by calling [SystemNavigator.pop]. + /// + /// [WidgetsApp] uses this in conjunction with a [Navigator] to + /// cause the back button to close dialog boxes, return from modal + /// pages, and so forth. + /// + /// This method exposes the `popRoute` notification from + /// [SystemChannels.navigation]. + /// + /// {@template flutter.widgets.AndroidPredictiveBack} + /// ## Handling backs ahead of time + /// + /// Not all system backs will result in a call to this method. Some are + /// handled entirely by the system without informing the Flutter framework. + /// + /// Android API 33+ introduced a feature called predictive back, which allows + /// the user to peek behind the current app or route during a back gesture and + /// then decide to cancel or commit the back. Flutter enables or disables this + /// feature ahead of time, before a back gesture occurs, and back gestures + /// that trigger predictive back are handled entirely by the system and do not + /// trigger this method here in the framework. + /// + /// By default, the framework communicates when it would like to handle system + /// back gestures using [SystemNavigator.setFrameworkHandlesBack] in + /// [WidgetsApp]. This is done automatically based on the status of the + /// [Navigator] stack and the state of any [PopScope] widgets present. + /// Developers can manually set this by calling the method directly or by + /// using [NavigationNotification]. + /// {@endtemplate} + @protected + @visibleForTesting + Future<void> handlePopRoute() async { + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + if (await observer.didPopRoute()) { + return; + } + } + SystemNavigator.pop(); + } + + /// Called when the host tells the app to push a new route onto the + /// navigator. + /// + /// This notifies the binding observers (using + /// [WidgetsBindingObserver.didPushRoute]), in registration order, until one + /// returns true, meaning that it was able to handle the request (e.g. by + /// opening a dialog box). If none return true, then nothing happens. + /// + /// This method exposes the `pushRoute` notification from + /// [SystemChannels.navigation]. + @protected + @mustCallSuper + @visibleForTesting + Future<void> handlePushRoute(String route) async { + final RouteInformation routeInformation = RouteInformation(uri: Uri.parse(route)); + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + if (await observer.didPushRouteInformation(routeInformation)) { + return; + } + } + } + + Future<void> _handlePushRouteInformation(Map<dynamic, dynamic> routeArguments) async { + final RouteInformation routeInformation = RouteInformation( + uri: Uri.parse(routeArguments['location'] as String), + state: routeArguments['state'] as Object?, + ); + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + if (await observer.didPushRouteInformation(routeInformation)) { + return; + } + } + } + + Future<dynamic> _handleNavigationInvocation(MethodCall methodCall) { + switch (methodCall.method) { + case 'popRoute': + return handlePopRoute(); + case 'pushRoute': + return handlePushRoute(methodCall.arguments as String); + case 'pushRouteInformation': + return _handlePushRouteInformation(methodCall.arguments as Map<dynamic, dynamic>); + } + return Future<dynamic>.value(); + } + + @override + void handleAppLifecycleStateChanged(AppLifecycleState state) { + super.handleAppLifecycleStateChanged(state); + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + observer.didChangeAppLifecycleState(state); + } + } + + @override + void handleMemoryPressure() { + super.handleMemoryPressure(); + for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) { + observer.didHaveMemoryPressure(); + } + } + + bool _needToReportFirstFrame = true; + + final Completer<void> _firstFrameCompleter = Completer<void>(); + + /// Whether the Flutter engine has rasterized the first frame. + /// + /// Usually, the time that a frame is rasterized is very close to the time that + /// it gets presented on the display. Specifically, rasterization is the last + /// expensive phase of a frame that's still in Flutter's control. + /// + /// See also: + /// + /// * [waitUntilFirstFrameRasterized], the future when [firstFrameRasterized] + /// becomes true. + bool get firstFrameRasterized => _firstFrameCompleter.isCompleted; + + /// A future that completes when the Flutter engine has rasterized the first + /// frame. + /// + /// Usually, the time that a frame is rasterized is very close to the time that + /// it gets presented on the display. Specifically, rasterization is the last + /// expensive phase of a frame that's still in Flutter's control. + /// + /// See also: + /// + /// * [firstFrameRasterized], whether this future has completed or not. + Future<void> get waitUntilFirstFrameRasterized => _firstFrameCompleter.future; + + /// Whether the first frame has finished building. + /// + /// This value can also be obtained over the VM service protocol as + /// `ext.flutter.didSendFirstFrameEvent`. + /// + /// See also: + /// + /// * [firstFrameRasterized], whether the first frame has finished rendering. + bool get debugDidSendFirstFrameEvent => !_needToReportFirstFrame; + + void _handleBuildScheduled() { + // If we're in the process of building dirty elements, then changes + // should not trigger a new frame. + assert(() { + if (debugBuildingDirtyElements) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Build scheduled during frame.'), + ErrorDescription( + 'While the widget tree was being built, laid out, and painted, ' + 'a new frame was scheduled to rebuild the widget tree.', + ), + ErrorHint( + 'This might be because setState() was called from a layout or ' + 'paint callback. ' + 'If a change is needed to the widget tree, it should be applied ' + 'as the tree is being built. Scheduling a change for the subsequent ' + 'frame instead results in an interface that lags behind by one frame. ' + 'If this was done to make your build dependent on a size measured at ' + 'layout time, consider using a LayoutBuilder, CustomSingleChildLayout, ' + 'or CustomMultiChildLayout. If, on the other hand, the one frame delay ' + 'is the desired effect, for example because this is an ' + 'animation, consider scheduling the frame in a post-frame callback ' + 'using SchedulerBinding.addPostFrameCallback or ' + 'using an AnimationController to trigger the animation.', + ), + ]); + } + return true; + }()); + ensureVisualUpdate(); + } + + /// Whether we are currently in a frame. This is used to verify + /// that frames are not scheduled redundantly. + /// + /// This is public so that test frameworks can change it. + /// + /// This flag is not used in release builds. + @protected + bool debugBuildingDirtyElements = false; + + /// Pump the build and rendering pipeline to generate a frame. + /// + /// This method is called by [handleDrawFrame], which itself is called + /// automatically by the engine when it is time to lay out and paint a + /// frame. + /// + /// Each frame consists of the following phases: + /// + /// 1. The animation phase: The [handleBeginFrame] method, which is registered + /// with [PlatformDispatcher.onBeginFrame], invokes all the transient frame + /// callbacks registered with [scheduleFrameCallback], in registration order. + /// This includes all the [Ticker] instances that are driving + /// [AnimationController] objects, which means all of the active [Animation] + /// objects tick at this point. + /// + /// 2. Microtasks: After [handleBeginFrame] returns, any microtasks that got + /// scheduled by transient frame callbacks get to run. This typically includes + /// callbacks for futures from [Ticker]s and [AnimationController]s that + /// completed this frame. + /// + /// After [handleBeginFrame], [handleDrawFrame], which is registered with + /// [PlatformDispatcher.onDrawFrame], is called, which invokes all the + /// persistent frame callbacks, of which the most notable is this method, + /// [drawFrame], which proceeds as follows: + /// + /// 3. The build phase: All the dirty [Element]s in the widget tree are + /// rebuilt (see [State.build]). See [State.setState] for further details on + /// marking a widget dirty for building. See [BuildOwner] for more information + /// on this step. + /// + /// 4. The layout phase: All the dirty [RenderObject]s in the system are laid + /// out (see [RenderObject.performLayout]). See [RenderObject.markNeedsLayout] + /// for further details on marking an object dirty for layout. + /// + /// 5. The compositing bits phase: The compositing bits on any dirty + /// [RenderObject] objects are updated. See + /// [RenderObject.markNeedsCompositingBitsUpdate]. + /// + /// 6. The paint phase: All the dirty [RenderObject]s in the system are + /// repainted (see [RenderObject.paint]). This generates the [Layer] tree. See + /// [RenderObject.markNeedsPaint] for further details on marking an object + /// dirty for paint. + /// + /// 7. The compositing phase: The layer tree is turned into a [Scene] and + /// sent to the GPU. + /// + /// 8. The semantics phase: All the dirty [RenderObject]s in the system have + /// their semantics updated (see [RenderObject.assembleSemanticsNode]). This + /// generates the [SemanticsNode] tree. See + /// [RenderObject.markNeedsSemanticsUpdate] for further details on marking an + /// object dirty for semantics. + /// + /// For more details on steps 4-8, see [PipelineOwner]. + /// + /// 9. The finalization phase in the widgets layer: The widgets tree is + /// finalized. This causes [State.dispose] to be invoked on any objects that + /// were removed from the widgets tree this frame. See + /// [BuildOwner.finalizeTree] for more details. + /// + /// 10. The finalization phase in the scheduler layer: After [drawFrame] + /// returns, [handleDrawFrame] then invokes post-frame callbacks (registered + /// with [addPostFrameCallback]). + // + // When editing the above, also update rendering/binding.dart's copy. + @override + void drawFrame() { + assert(!debugBuildingDirtyElements); + assert(() { + debugBuildingDirtyElements = true; + return true; + }()); + + TimingsCallback? firstFrameCallback; + if (_needToReportFirstFrame) { + assert(!_firstFrameCompleter.isCompleted); + + firstFrameCallback = (List<FrameTiming> timings) { + assert(sendFramesToEngine); + if (!kReleaseMode) { + // Change the current user tag back to the default tag. At this point, + // the user tag should be set to "AppStartUp" (originally set in the + // engine), so we need to change it back to the default tag to mark + // the end of app start up for CPU profiles. + developer.UserTag.defaultTag.makeCurrent(); + developer.Timeline.instantSync('Rasterized first useful frame'); + developer.postEvent('Flutter.FirstFrame', <String, dynamic>{}); + } + SchedulerBinding.instance.removeTimingsCallback(firstFrameCallback!); + firstFrameCallback = null; + _firstFrameCompleter.complete(); + }; + // Callback is only invoked when FlutterView.render is called. When + // sendFramesToEngine is set to false during the frame, it will not be + // called and we need to remove the callback (see below). + SchedulerBinding.instance.addTimingsCallback(firstFrameCallback!); + } + + try { + if (rootElement != null) { + buildOwner!.buildScope(rootElement!); + } + super.drawFrame(); + buildOwner!.finalizeTree(); + } finally { + assert(() { + debugBuildingDirtyElements = false; + return true; + }()); + } + if (!kReleaseMode) { + if (_needToReportFirstFrame && sendFramesToEngine) { + developer.Timeline.instantSync('Widgets built first useful frame'); + } + } + _needToReportFirstFrame = false; + if (firstFrameCallback != null && !sendFramesToEngine) { + // This frame is deferred and not the first frame sent to the engine that + // should be reported. + _needToReportFirstFrame = true; + SchedulerBinding.instance.removeTimingsCallback(firstFrameCallback!); + } + } + + /// The [Element] that is at the root of the element tree hierarchy. + /// + /// This is initialized the first time [runApp] is called. + Element? get rootElement => _rootElement; + Element? _rootElement; + + /// Deprecated. Will be removed in a future version of Flutter. + /// + /// Use [rootElement] instead. + @Deprecated( + 'Use rootElement instead. ' + 'This feature was deprecated after v3.9.0-16.0.pre.' + ) + Element? get renderViewElement => rootElement; + + bool _readyToProduceFrames = false; + + @override + bool get framesEnabled => super.framesEnabled && _readyToProduceFrames; + + /// Used by [runApp] to wrap the provided `rootWidget` in the default [View]. + /// + /// The [View] determines into what [FlutterView] the app is rendered into. + /// This is currently [PlatformDispatcher.implicitView] from [platformDispatcher]. + /// + /// The `rootWidget` widget provided to this method must not already be + /// wrapped in a [View]. + Widget wrapWithDefaultView(Widget rootWidget) { + return View( + view: platformDispatcher.implicitView!, + deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner: pipelineOwner, + deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView: renderView, + child: rootWidget, + ); + } + + /// Schedules a [Timer] for attaching the root widget. + /// + /// This is called by [runApp] to configure the widget tree. Consider using + /// [attachRootWidget] if you want to build the widget tree synchronously. + @protected + void scheduleAttachRootWidget(Widget rootWidget) { + Timer.run(() { + attachRootWidget(rootWidget); + }); + } + + /// Takes a widget and attaches it to the [rootElement], creating it if + /// necessary. + /// + /// This is called by [runApp] to configure the widget tree. + /// + /// See also: + /// + /// * [RenderObjectToWidgetAdapter.attachToRenderTree], which inflates a + /// widget and attaches it to the render tree. + void attachRootWidget(Widget rootWidget) { + attachToBuildOwner(RootWidget( + debugShortDescription: '[root]', + child: rootWidget, + )); + } + + /// Called by [attachRootWidget] to attach the provided [RootWidget] to the + /// [buildOwner]. + /// + /// This creates the [rootElement], if necessary, or re-uses an existing one. + /// + /// This method is rarely called directly, but it can be useful in tests to + /// restore the element tree to a previous version by providing the + /// [RootWidget] of that version (see [WidgetTester.restartAndRestore] for an + /// exemplary use case). + void attachToBuildOwner(RootWidget widget) { + final bool isBootstrapFrame = rootElement == null; + _readyToProduceFrames = true; + _rootElement = widget.attach(buildOwner!, rootElement as RootElement?); + if (isBootstrapFrame) { + SchedulerBinding.instance.ensureVisualUpdate(); + } + } + + /// Whether the [rootElement] has been initialized. + /// + /// This will be false until [runApp] is called (or [WidgetTester.pumpWidget] + /// is called in the context of a [TestWidgetsFlutterBinding]). + bool get isRootWidgetAttached => _rootElement != null; + + @override + Future<void> performReassemble() { + assert(() { + WidgetInspectorService.instance.performReassemble(); + return true; + }()); + + if (rootElement != null) { + buildOwner!.reassemble(rootElement!); + } + return super.performReassemble(); + } + + /// Computes the locale the current platform would resolve to. + /// + /// This method is meant to be used as part of a + /// [WidgetsApp.localeListResolutionCallback]. Since this method may return + /// null, a Flutter/dart algorithm should still be provided as a fallback in + /// case a native resolved locale cannot be determined or if the native + /// resolved locale is undesirable. + /// + /// This method may return a null [Locale] if the platform does not support + /// native locale resolution, or if the resolution failed. + /// + /// The first `supportedLocale` is treated as the default locale and will be returned + /// if no better match is found. + /// + /// Android and iOS are currently supported. + /// + /// On Android, the algorithm described in + /// https://developer.android.com/guide/topics/resources/multilingual-support + /// is used to determine the resolved locale. Depending on the android version + /// of the device, either the modern (>= API 24) or legacy (< API 24) algorithm + /// will be used. + /// + /// On iOS, the result of `preferredLocalizationsFromArray` method of `NSBundle` + /// is returned. See: + /// https://developer.apple.com/documentation/foundation/nsbundle/1417249-preferredlocalizationsfromarray?language=objc + /// for details on the used method. + /// + /// iOS treats script code as necessary for a match, so a user preferred locale of + /// `zh_Hans_CN` will not resolve to a supported locale of `zh_CN`. + /// + /// Since implementation may vary by platform and has potential to be heavy, + /// it is recommended to cache the results of this method if the value is + /// used multiple times. + /// + /// Second-best (and n-best) matching locales should be obtained by calling this + /// method again with the matched locale of the first call omitted from + /// `supportedLocales`. + Locale? computePlatformResolvedLocale(List<Locale> supportedLocales) { + return platformDispatcher.computePlatformResolvedLocale(supportedLocales); + } +} + +/// Inflate the given widget and attach it to the screen. +/// +/// The widget is given constraints during layout that force it to fill the +/// entire screen. If you wish to align your widget to one side of the screen +/// (e.g., the top), consider using the [Align] widget. If you wish to center +/// your widget, you can also use the [Center] widget. +/// +/// Calling [runApp] again will detach the previous root widget from the screen +/// and attach the given widget in its place. The new widget tree is compared +/// against the previous widget tree and any differences are applied to the +/// underlying render tree, similar to what happens when a [StatefulWidget] +/// rebuilds after calling [State.setState]. +/// +/// Initializes the binding using [WidgetsFlutterBinding] if necessary. +/// +/// ## Application shutdown +/// +/// This widget tree is not torn down when the application shuts down, because +/// there is no way to predict when that will happen. For example, a user could +/// physically remove power from their device, or the application could crash +/// unexpectedly, or the malware on the device could forcibly terminate the +/// process. +/// +/// Applications are responsible for ensuring that they are well-behaved +/// even in the face of a rapid unscheduled termination. +/// +/// To artificially cause the entire widget tree to be disposed, consider +/// calling [runApp] with a widget such as [SizedBox.shrink]. +/// +/// To listen for platform shutdown messages (and other lifecycle changes), +/// consider the [AppLifecycleListener] API. +/// +/// ## Dismissing Flutter UI via platform native methods +/// +/// {@template flutter.widgets.runApp.dismissal} +/// An application may have both Flutter and non-Flutter UI in it. If the +/// application calls non-Flutter methods to remove Flutter based UI such as +/// platform native API to manipulate the platform native navigation stack, +/// the framework does not know if the developer intends to eagerly free +/// resources or not. The widget tree remains mounted and ready to render +/// as soon as it is displayed again. +/// +/// To release resources more eagerly, establish a [platform channel](https://flutter.dev/platform-channels/) +/// and use it to call [runApp] with a widget such as [SizedBox.shrink] when +/// the framework should dispose of the active widget tree. +/// {@endtemplate} +/// +/// See also: +/// +/// * [WidgetsBinding.attachRootWidget], which creates the root widget for the +/// widget hierarchy. +/// * [RenderObjectToWidgetAdapter.attachToRenderTree], which creates the root +/// element for the element hierarchy. +/// * [WidgetsBinding.handleBeginFrame], which pumps the widget pipeline to +/// ensure the widget, element, and render trees are all built. +void runApp(Widget app) { + final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized(); + assert(binding.debugCheckZone('runApp')); + binding + ..scheduleAttachRootWidget(binding.wrapWithDefaultView(app)) + ..scheduleWarmUpFrame(); +} + +String _debugDumpAppString() { + const String mode = kDebugMode ? 'DEBUG MODE' : kReleaseMode ? 'RELEASE MODE' : 'PROFILE MODE'; + final StringBuffer buffer = StringBuffer(); + buffer.writeln('${WidgetsBinding.instance.runtimeType} - $mode'); + if (WidgetsBinding.instance.rootElement != null) { + buffer.writeln(WidgetsBinding.instance.rootElement!.toStringDeep()); + } else { + buffer.writeln('<no tree currently mounted>'); + } + return buffer.toString(); +} + +/// Print a string representation of the currently running app. +void debugDumpApp() { + debugPrint(_debugDumpAppString()); +} + +/// A widget for the root of the widget tree. +/// +/// Exposes an [attach] method to attach the widget tree to a [BuildOwner]. That +/// method also bootstraps the element tree. +/// +/// Used by [WidgetsBinding.attachRootWidget] (which is indirectly called by +/// [runApp]) to bootstrap applications. +class RootWidget extends Widget { + /// Creates a [RootWidget]. + const RootWidget({ + super.key, + this.child, + this.debugShortDescription, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// A short description of this widget used by debugging aids. + final String? debugShortDescription; + + @override + RootElement createElement() => RootElement(this); + + /// Inflate this widget and attaches it to the provided [BuildOwner]. + /// + /// If `element` is null, this function will create a new element. Otherwise, + /// the given element will have an update scheduled to switch to this widget. + /// + /// Used by [WidgetsBinding.attachToBuildOwner] (which is indirectly called by + /// [runApp]) to bootstrap applications. + RootElement attach(BuildOwner owner, [ RootElement? element ]) { + if (element == null) { + owner.lockState(() { + element = createElement(); + assert(element != null); + element!.assignOwner(owner); + }); + owner.buildScope(element!, () { + element!.mount(/* parent */ null, /* slot */ null); + }); + } else { + element._newWidget = this; + element.markNeedsBuild(); + } + return element!; + } + + @override + String toStringShort() => debugShortDescription ?? super.toStringShort(); +} + +/// The root of the element tree. +/// +/// This element class is the instantiation of a [RootWidget]. It can be used +/// only as the root of an [Element] tree (it cannot be mounted into another +/// [Element]; its parent must be null). +/// +/// In typical usage, it will be instantiated for a [RootWidget] by calling +/// [RootWidget.attach]. In this usage, it is normally instantiated by the +/// bootstrapping logic in the [WidgetsFlutterBinding] singleton created by +/// [runApp]. +class RootElement extends Element with RootElementMixin { + /// Creates a [RootElement] for the provided [RootWidget]. + RootElement(RootWidget super.widget); + + Element? _child; + + @override + void visitChildren(ElementVisitor visitor) { + if (_child != null) { + visitor(_child!); + } + } + + @override + void forgetChild(Element child) { + assert(child == _child); + _child = null; + super.forgetChild(child); + } + + @override + void mount(Element? parent, Object? newSlot) { + assert(parent == null); // We are the root! + super.mount(parent, newSlot); + _rebuild(); + assert(_child != null); + super.performRebuild(); // clears the "dirty" flag + } + + @override + void update(RootWidget newWidget) { + super.update(newWidget); + assert(widget == newWidget); + _rebuild(); + } + + // When we are assigned a new widget, we store it here + // until we are ready to update to it. + RootWidget? _newWidget; + + @override + void performRebuild() { + if (_newWidget != null) { + // _newWidget can be null if, for instance, we were rebuilt + // due to a reassemble. + final RootWidget newWidget = _newWidget!; + _newWidget = null; + update(newWidget); + } + super.performRebuild(); + assert(_newWidget == null); + } + + void _rebuild() { + try { + _child = updateChild(_child, (widget as RootWidget).child, /* slot */ null); + } catch (exception, stack) { + final FlutterErrorDetails details = FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets library', + context: ErrorDescription('attaching to the render tree'), + ); + FlutterError.reportError(details); + // No error widget possible here since it wouldn't have a view to render into. + _child = null; + } + + } + + @override + bool get debugDoingBuild => false; // This element doesn't have a build phase. + + @override + // There is no ancestor RenderObjectElement that the render object could be attached to. + bool debugExpectsRenderObjectForSlot(Object? slot) => false; +} + +/// A concrete binding for applications based on the Widgets framework. +/// +/// This is the glue that binds the framework to the Flutter engine. +/// +/// When using the widgets framework, this binding, or one that +/// implements the same interfaces, must be used. The following +/// mixins are used to implement this binding: +/// +/// * [GestureBinding], which implements the basics of hit testing. +/// * [SchedulerBinding], which introduces the concepts of frames. +/// * [ServicesBinding], which provides access to the plugin subsystem. +/// * [PaintingBinding], which enables decoding images. +/// * [SemanticsBinding], which supports accessibility. +/// * [RendererBinding], which handles the render tree. +/// * [WidgetsBinding], which handles the widget tree. +class WidgetsFlutterBinding extends BindingBase with GestureBinding, SchedulerBinding, ServicesBinding, PaintingBinding, SemanticsBinding, RendererBinding, WidgetsBinding { + /// Returns an instance of the binding that implements + /// [WidgetsBinding]. If no binding has yet been initialized, the + /// [WidgetsFlutterBinding] class is used to create and initialize + /// one. + /// + /// You only need to call this method if you need the binding to be + /// initialized before calling [runApp]. + /// + /// In the `flutter_test` framework, [testWidgets] initializes the + /// binding instance to a [TestWidgetsFlutterBinding], not a + /// [WidgetsFlutterBinding]. See + /// [TestWidgetsFlutterBinding.ensureInitialized]. + static WidgetsBinding ensureInitialized() { + if (WidgetsBinding._instance == null) { + WidgetsFlutterBinding(); + } + return WidgetsBinding.instance; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/bottom_navigation_bar_item.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/bottom_navigation_bar_item.dart new file mode 100644 index 0000000000000000000000000000000000000000..30bb768cf4bd02bacb32e1b4cc834c8ed421918d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/bottom_navigation_bar_item.dart @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show Color; + +import 'framework.dart'; + +/// An interactive button within either material's [BottomNavigationBar] +/// or the iOS themed [CupertinoTabBar] with an icon and title. +/// +/// This class is rarely used in isolation. It is typically embedded in one of +/// the bottom navigation widgets above. +/// +/// See also: +/// +/// * [BottomNavigationBar] +/// * <https://material.io/design/components/bottom-navigation.html> +/// * [CupertinoTabBar] +/// * <https://developer.apple.com/ios/human-interface-guidelines/bars/tab-bars> +class BottomNavigationBarItem { + /// Creates an item that is used with [BottomNavigationBar.items]. + /// + /// The argument [icon] should not be null and the argument [label] should not be null when used in a Material Design's [BottomNavigationBar]. + const BottomNavigationBarItem({ + this.key, + required this.icon, + this.label, + Widget? activeIcon, + this.backgroundColor, + this.tooltip, + }) : activeIcon = activeIcon ?? icon; + + /// A key to be passed through to the resultant widget. + /// + /// This allows the identification of different [BottomNavigationBarItem]s through their keys. + /// + /// When changing the number of bar items in response to a bar item being tapped, giving + /// each item a key will allow the inkwell / splash animation to be correctly positioned. + final Key? key; + + /// The icon of the item. + /// + /// Typically the icon is an [Icon] or an [ImageIcon] widget. If another type + /// of widget is provided then it should configure itself to match the current + /// [IconTheme] size and color. + /// + /// If [activeIcon] is provided, this will only be displayed when the item is + /// not selected. + /// + /// To make the bottom navigation bar more accessible, consider choosing an + /// icon with a stroked and filled version, such as [Icons.cloud] and + /// [Icons.cloud_queue]. [icon] should be set to the stroked version and + /// [activeIcon] to the filled version. + /// + /// If a particular icon doesn't have a stroked or filled version, then don't + /// pair unrelated icons. Instead, make sure to use a + /// [BottomNavigationBarType.shifting]. + final Widget icon; + + /// An alternative icon displayed when this bottom navigation item is + /// selected. + /// + /// If this icon is not provided, the bottom navigation bar will display + /// [icon] in either state. + /// + /// See also: + /// + /// * [BottomNavigationBarItem.icon], for a description of how to pair icons. + final Widget activeIcon; + + /// The text label for this [BottomNavigationBarItem]. + /// + /// This will be used to create a [Text] widget to put in the bottom navigation bar. + final String? label; + + /// The color of the background radial animation for material [BottomNavigationBar]. + /// + /// If the navigation bar's type is [BottomNavigationBarType.shifting], then + /// the entire bar is flooded with the [backgroundColor] when this item is + /// tapped. This will override [BottomNavigationBar.backgroundColor]. + /// + /// Not used for [CupertinoTabBar]. Control the invariant bar color directly + /// via [CupertinoTabBar.backgroundColor]. + /// + /// See also: + /// + /// * [Icon.color] and [ImageIcon.color] to control the foreground color of + /// the icons themselves. + final Color? backgroundColor; + + /// The text to display in the [Tooltip] for this [BottomNavigationBarItem]. + /// + /// A [Tooltip] will only appear on this item if [tooltip] is set to a non-empty string. + /// + /// Defaults to null, in which case the tooltip is not shown. + final String? tooltip; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/color_filter.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/color_filter.dart new file mode 100644 index 0000000000000000000000000000000000000000..bd01095792d54a6c3c55e80c4af4b4e2c5f354f2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/color_filter.dart @@ -0,0 +1,78 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; + +/// Applies a [ColorFilter] to its child. +/// +/// This widget applies a function independently to each pixel of [child]'s +/// content, according to the [ColorFilter] specified. +/// Use the [ColorFilter.mode] constructor to apply a [Color] using a [BlendMode]. +/// Use the [BackdropFilter] widget instead, if the [ColorFilter] +/// needs to be applied onto the content beneath [child]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=F7Cll22Dno8} +/// +/// {@tool dartpad} +/// These two images have two [ColorFilter]s applied with different [BlendMode]s, +/// one with red color and [BlendMode.modulate] another with a grey color and [BlendMode.saturation]. +/// +/// ** See code in examples/api/lib/widgets/color_filter/color_filtered.0.dart ** +///{@end-tool} +/// +/// See also: +/// +/// * [BlendMode], describes how to blend a source image with the destination image. +/// * [ColorFilter], which describes a function that modify a color to a different color. + +@immutable +class ColorFiltered extends SingleChildRenderObjectWidget { + /// Creates a widget that applies a [ColorFilter] to its child. + const ColorFiltered({required this.colorFilter, super.child, super.key}); + + /// The color filter to apply to the child of this widget. + final ColorFilter colorFilter; + + @override + RenderObject createRenderObject(BuildContext context) => _ColorFilterRenderObject(colorFilter); + + @override + void updateRenderObject(BuildContext context, RenderObject renderObject) { + (renderObject as _ColorFilterRenderObject).colorFilter = colorFilter; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ColorFilter>('colorFilter', colorFilter)); + } +} + +class _ColorFilterRenderObject extends RenderProxyBox { + _ColorFilterRenderObject(this._colorFilter); + + ColorFilter get colorFilter => _colorFilter; + ColorFilter _colorFilter; + set colorFilter(ColorFilter value) { + if (value != _colorFilter) { + _colorFilter = value; + markNeedsPaint(); + } + } + + @override + bool get alwaysNeedsCompositing => child != null; + + @override + void paint(PaintingContext context, Offset offset) { + layer = context.pushColorFilter(offset, colorFilter, super.paint, oldLayer: layer as ColorFilterLayer?); + assert(() { + layer!.debugCreator = debugCreator; + return true; + }()); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/constants.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/constants.dart new file mode 100644 index 0000000000000000000000000000000000000000..49ad4961833bde42e8d324a52927916a663d7ca1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/constants.dart @@ -0,0 +1,16 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// The minimum dimension of any interactive region according to the Material +/// guidelines. +/// +/// This is used to avoid small regions that are hard for the user to interact +/// with. It applies to both dimensions of a region, so a square of size +/// kMinInteractiveDimension x kMinInteractiveDimension is the smallest +/// acceptable region that should respond to gestures. +/// +/// See also: +/// +/// * [kMinInteractiveDimensionCupertino] +const double kMinInteractiveDimension = 48.0; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/container.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/container.dart new file mode 100644 index 0000000000000000000000000000000000000000..f6967ce1d0745c12f4dc3aeb9b0844873be57761 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/container.dart @@ -0,0 +1,478 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'image.dart'; + +// Examples can assume: +// late BuildContext context; + +/// A widget that paints a [Decoration] either before or after its child paints. +/// +/// [Container] insets its child by the widths of the borders; this widget does +/// not. +/// +/// Commonly used with [BoxDecoration]. +/// +/// The [child] is not clipped. To clip a child to the shape of a particular +/// [ShapeDecoration], consider using a [ClipPath] widget. +/// +/// {@tool snippet} +/// +/// This sample shows a radial gradient that draws a moon on a night sky: +/// +/// ```dart +/// const DecoratedBox( +/// decoration: BoxDecoration( +/// gradient: RadialGradient( +/// center: Alignment(-0.5, -0.6), +/// radius: 0.15, +/// colors: <Color>[ +/// Color(0xFFEEEEEE), +/// Color(0xFF111133), +/// ], +/// stops: <double>[0.9, 1.0], +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Ink], which paints a [Decoration] on a [Material], allowing +/// [InkResponse] and [InkWell] splashes to paint over them. +/// * [DecoratedBoxTransition], the version of this class that animates on the +/// [decoration] property. +/// * [Decoration], which you can extend to provide other effects with +/// [DecoratedBox]. +/// * [CustomPaint], another way to draw custom effects from the widget layer. +/// * [DecoratedSliver], which applies a [Decoration] to a sliver. +class DecoratedBox extends SingleChildRenderObjectWidget { + /// Creates a widget that paints a [Decoration]. + /// + /// By default the decoration paints behind the child. + const DecoratedBox({ + super.key, + required this.decoration, + this.position = DecorationPosition.background, + super.child, + }); + + /// What decoration to paint. + /// + /// Commonly a [BoxDecoration]. + final Decoration decoration; + + /// Whether to paint the box decoration behind or in front of the child. + final DecorationPosition position; + + @override + RenderDecoratedBox createRenderObject(BuildContext context) { + return RenderDecoratedBox( + decoration: decoration, + position: position, + configuration: createLocalImageConfiguration(context), + ); + } + + @override + void updateRenderObject(BuildContext context, RenderDecoratedBox renderObject) { + renderObject + ..decoration = decoration + ..configuration = createLocalImageConfiguration(context) + ..position = position; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final String label; + switch (position) { + case DecorationPosition.background: + label = 'bg'; + case DecorationPosition.foreground: + label = 'fg'; + } + properties.add(EnumProperty<DecorationPosition>('position', position, level: DiagnosticLevel.hidden)); + properties.add(DiagnosticsProperty<Decoration>(label, decoration)); + } +} + +/// A convenience widget that combines common painting, positioning, and sizing +/// widgets. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=c1xLMaTUWCY} +/// +/// A container first surrounds the child with [padding] (inflated by any +/// borders present in the [decoration]) and then applies additional +/// [constraints] to the padded extent (incorporating the `width` and `height` +/// as constraints, if either is non-null). The container is then surrounded by +/// additional empty space described from the [margin]. +/// +/// During painting, the container first applies the given [transform], then +/// paints the [decoration] to fill the padded extent, then it paints the child, +/// and finally paints the [foregroundDecoration], also filling the padded +/// extent. +/// +/// Containers with no children try to be as big as possible unless the incoming +/// constraints are unbounded, in which case they try to be as small as +/// possible. Containers with children size themselves to their children. The +/// `width`, `height`, and [constraints] arguments to the constructor override +/// this. +/// +/// By default, containers return false for all hit tests. If the [color] +/// property is specified, the hit testing is handled by [ColoredBox], which +/// always returns true. If the [decoration] or [foregroundDecoration] properties +/// are specified, hit testing is handled by [Decoration.hitTest]. +/// +/// ## Layout behavior +/// +/// _See [BoxConstraints] for an introduction to box layout models._ +/// +/// Since [Container] combines a number of other widgets each with their own +/// layout behavior, [Container]'s layout behavior is somewhat complicated. +/// +/// Summary: [Container] tries, in order: to honor [alignment], to size itself +/// to the [child], to honor the `width`, `height`, and [constraints], to expand +/// to fit the parent, to be as small as possible. +/// +/// More specifically: +/// +/// If the widget has no child, no `height`, no `width`, no [constraints], +/// and the parent provides unbounded constraints, then [Container] tries to +/// size as small as possible. +/// +/// If the widget has no child and no [alignment], but a `height`, `width`, or +/// [constraints] are provided, then the [Container] tries to be as small as +/// possible given the combination of those constraints and the parent's +/// constraints. +/// +/// If the widget has no child, no `height`, no `width`, no [constraints], and +/// no [alignment], but the parent provides bounded constraints, then +/// [Container] expands to fit the constraints provided by the parent. +/// +/// If the widget has an [alignment], and the parent provides unbounded +/// constraints, then the [Container] tries to size itself around the child. +/// +/// If the widget has an [alignment], and the parent provides bounded +/// constraints, then the [Container] tries to expand to fit the parent, and +/// then positions the child within itself as per the [alignment]. +/// +/// Otherwise, the widget has a [child] but no `height`, no `width`, no +/// [constraints], and no [alignment], and the [Container] passes the +/// constraints from the parent to the child and sizes itself to match the +/// child. +/// +/// The [margin] and [padding] properties also affect the layout, as described +/// in the documentation for those properties. (Their effects merely augment the +/// rules described above.) The [decoration] can implicitly increase the +/// [padding] (e.g. borders in a [BoxDecoration] contribute to the [padding]); +/// see [Decoration.padding]. +/// +/// ## Example +/// +/// {@tool snippet} +/// This example shows a 48x48 amber square (placed inside a [Center] widget in +/// case the parent widget has its own opinions regarding the size that the +/// [Container] should take), with a margin so that it stays away from +/// neighboring widgets: +/// +/// ![An amber colored container with the dimensions of 48 square pixels.](https://flutter.github.io/assets-for-api-docs/assets/widgets/container_a.png) +/// +/// ```dart +/// Center( +/// child: Container( +/// margin: const EdgeInsets.all(10.0), +/// color: Colors.amber[600], +/// width: 48.0, +/// height: 48.0, +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// +/// This example shows how to use many of the features of [Container] at once. +/// The [constraints] are set to fit the font size plus ample headroom +/// vertically, while expanding horizontally to fit the parent. The [padding] is +/// used to make sure there is space between the contents and the text. The +/// [color] makes the box blue. The [alignment] causes the [child] to be +/// centered in the box. Finally, the [transform] applies a slight rotation to the +/// entire contraption to complete the effect. +/// +/// ![A blue rectangular container with 'Hello World' in the center, rotated +/// slightly in the z axis.](https://flutter.github.io/assets-for-api-docs/assets/widgets/container_b.png) +/// +/// ```dart +/// Container( +/// constraints: BoxConstraints.expand( +/// height: Theme.of(context).textTheme.headlineMedium!.fontSize! * 1.1 + 200.0, +/// ), +/// padding: const EdgeInsets.all(8.0), +/// color: Colors.blue[600], +/// alignment: Alignment.center, +/// transform: Matrix4.rotationZ(0.1), +/// child: Text('Hello World', +/// style: Theme.of(context) +/// .textTheme +/// .headlineMedium! +/// .copyWith(color: Colors.white)), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedContainer], a variant that smoothly animates the properties when +/// they change. +/// * [Border], which has a sample which uses [Container] heavily. +/// * [Ink], which paints a [Decoration] on a [Material], allowing +/// [InkResponse] and [InkWell] splashes to paint over them. +/// * Cookbook: [Animate the properties of a container](https://flutter.dev/docs/cookbook/animation/animated-container) +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Container extends StatelessWidget { + /// Creates a widget that combines common painting, positioning, and sizing widgets. + /// + /// The `height` and `width` values include the padding. + /// + /// The `color` and `decoration` arguments cannot both be supplied, since + /// it would potentially result in the decoration drawing over the background + /// color. To supply a decoration with a color, use `decoration: + /// BoxDecoration(color: color)`. + Container({ + super.key, + this.alignment, + this.padding, + this.color, + this.decoration, + this.foregroundDecoration, + double? width, + double? height, + BoxConstraints? constraints, + this.margin, + this.transform, + this.transformAlignment, + this.child, + this.clipBehavior = Clip.none, + }) : assert(margin == null || margin.isNonNegative), + assert(padding == null || padding.isNonNegative), + assert(decoration == null || decoration.debugAssertIsValid()), + assert(constraints == null || constraints.debugAssertIsValid()), + assert(decoration != null || clipBehavior == Clip.none), + assert(color == null || decoration == null, + 'Cannot provide both a color and a decoration\n' + 'To provide both, use "decoration: BoxDecoration(color: color)".', + ), + constraints = + (width != null || height != null) + ? constraints?.tighten(width: width, height: height) + ?? BoxConstraints.tightFor(width: width, height: height) + : constraints; + + /// The [child] contained by the container. + /// + /// If null, and if the [constraints] are unbounded or also null, the + /// container will expand to fill all available space in its parent, unless + /// the parent provides unbounded constraints, in which case the container + /// will attempt to be as small as possible. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// Align the [child] within the container. + /// + /// If non-null, the container will expand to fill its parent and position its + /// child within itself according to the given value. If the incoming + /// constraints are unbounded, then the child will be shrink-wrapped instead. + /// + /// Ignored if [child] is null. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry? alignment; + + /// Empty space to inscribe inside the [decoration]. The [child], if any, is + /// placed inside this padding. + /// + /// This padding is in addition to any padding inherent in the [decoration]; + /// see [Decoration.padding]. + final EdgeInsetsGeometry? padding; + + /// The color to paint behind the [child]. + /// + /// This property should be preferred when the background is a simple color. + /// For other cases, such as gradients or images, use the [decoration] + /// property. + /// + /// If the [decoration] is used, this property must be null. A background + /// color may still be painted by the [decoration] even if this property is + /// null. + final Color? color; + + /// The decoration to paint behind the [child]. + /// + /// Use the [color] property to specify a simple solid color. + /// + /// The [child] is not clipped to the decoration. To clip a child to the shape + /// of a particular [ShapeDecoration], consider using a [ClipPath] widget. + final Decoration? decoration; + + /// The decoration to paint in front of the [child]. + final Decoration? foregroundDecoration; + + /// Additional constraints to apply to the child. + /// + /// The constructor `width` and `height` arguments are combined with the + /// `constraints` argument to set this property. + /// + /// The [padding] goes inside the constraints. + final BoxConstraints? constraints; + + /// Empty space to surround the [decoration] and [child]. + final EdgeInsetsGeometry? margin; + + /// The transformation matrix to apply before painting the container. + final Matrix4? transform; + + /// The alignment of the origin, relative to the size of the container, if [transform] is specified. + /// + /// When [transform] is null, the value of this property is ignored. + /// + /// See also: + /// + /// * [Transform.alignment], which is set by this property. + final AlignmentGeometry? transformAlignment; + + /// The clip behavior when [Container.decoration] is not null. + /// + /// Defaults to [Clip.none]. Must be [Clip.none] if [decoration] is null. + /// + /// If a clip is to be applied, the [Decoration.getClipPath] method + /// for the provided decoration must return a clip path. (This is not + /// supported by all decorations; the default implementation of that + /// method throws an [UnsupportedError].) + final Clip clipBehavior; + + EdgeInsetsGeometry? get _paddingIncludingDecoration { + if (decoration == null) { + return padding; + } + final EdgeInsetsGeometry decorationPadding = decoration!.padding; + if (padding == null) { + return decorationPadding; + } + return padding!.add(decorationPadding); + } + + @override + Widget build(BuildContext context) { + Widget? current = child; + + if (child == null && (constraints == null || !constraints!.isTight)) { + current = LimitedBox( + maxWidth: 0.0, + maxHeight: 0.0, + child: ConstrainedBox(constraints: const BoxConstraints.expand()), + ); + } else if (alignment != null) { + current = Align(alignment: alignment!, child: current); + } + + final EdgeInsetsGeometry? effectivePadding = _paddingIncludingDecoration; + if (effectivePadding != null) { + current = Padding(padding: effectivePadding, child: current); + } + + if (color != null) { + current = ColoredBox(color: color!, child: current); + } + + if (clipBehavior != Clip.none) { + assert(decoration != null); + current = ClipPath( + clipper: _DecorationClipper( + textDirection: Directionality.maybeOf(context), + decoration: decoration!, + ), + clipBehavior: clipBehavior, + child: current, + ); + } + + if (decoration != null) { + current = DecoratedBox(decoration: decoration!, child: current); + } + + if (foregroundDecoration != null) { + current = DecoratedBox( + decoration: foregroundDecoration!, + position: DecorationPosition.foreground, + child: current, + ); + } + + if (constraints != null) { + current = ConstrainedBox(constraints: constraints!, child: current); + } + + if (margin != null) { + current = Padding(padding: margin!, child: current); + } + + if (transform != null) { + current = Transform(transform: transform!, alignment: transformAlignment, child: current); + } + + return current!; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, showName: false, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior, defaultValue: Clip.none)); + if (color != null) { + properties.add(DiagnosticsProperty<Color>('bg', color)); + } else { + properties.add(DiagnosticsProperty<Decoration>('bg', decoration, defaultValue: null)); + } + properties.add(DiagnosticsProperty<Decoration>('fg', foregroundDecoration, defaultValue: null)); + properties.add(DiagnosticsProperty<BoxConstraints>('constraints', constraints, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('margin', margin, defaultValue: null)); + properties.add(ObjectFlagProperty<Matrix4>.has('transform', transform)); + } +} + +/// A clipper that uses [Decoration.getClipPath] to clip. +class _DecorationClipper extends CustomClipper<Path> { + _DecorationClipper({ + TextDirection? textDirection, + required this.decoration, + }) : textDirection = textDirection ?? TextDirection.ltr; + + final TextDirection textDirection; + final Decoration decoration; + + @override + Path getClip(Size size) { + return decoration.getClipPath(Offset.zero & size, textDirection); + } + + @override + bool shouldReclip(_DecorationClipper oldClipper) { + return oldClipper.decoration != decoration + || oldClipper.textDirection != textDirection; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/context_menu_button_item.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/context_menu_button_item.dart new file mode 100644 index 0000000000000000000000000000000000000000..896cbab9d20ec912c59aba999d10d05a9bd37e9f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/context_menu_button_item.dart @@ -0,0 +1,108 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'framework.dart'; + +/// The buttons that can appear in a context menu by default. +/// +/// See also: +/// +/// * [ContextMenuButtonItem], which uses this enum to describe a button in a +/// context menu. +enum ContextMenuButtonType { + /// A button that cuts the current text selection. + cut, + + /// A button that copies the current text selection. + copy, + + /// A button that pastes the clipboard contents into the focused text field. + paste, + + /// A button that selects all the contents of the focused text field. + selectAll, + + /// A button that deletes the current text selection. + delete, + + /// A button that looks up the current text selection. + lookUp, + + /// A button that launches a web search for the current text selection. + searchWeb, + + /// A button that displays the share screen for the current text selection. + share, + + /// A button for starting Live Text input. + /// + /// See also: + /// * [LiveText], where the availability of Live Text input can be obtained. + /// * [LiveTextInputStatusNotifier], where the status of Live Text can be listened to. + liveTextInput, + + /// Anything other than the default button types. + custom, +} + +/// The type and callback for a context menu button. +/// +/// See also: +/// +/// * [AdaptiveTextSelectionToolbar], which can take a list of +/// ContextMenuButtonItems and create a platform-specific context menu with +/// the indicated buttons. +@immutable +class ContextMenuButtonItem { + /// Creates a const instance of [ContextMenuButtonItem]. + const ContextMenuButtonItem({ + required this.onPressed, + this.type = ContextMenuButtonType.custom, + this.label, + }); + + /// The callback to be called when the button is pressed. + final VoidCallback? onPressed; + + /// The type of button this represents. + final ContextMenuButtonType type; + + /// The label to display on the button. + /// + /// If a [type] other than [ContextMenuButtonType.custom] is given + /// and a label is not provided, then the default label for that type for the + /// platform will be looked up. + final String? label; + + /// Creates a new [ContextMenuButtonItem] with the provided parameters + /// overridden. + ContextMenuButtonItem copyWith({ + VoidCallback? onPressed, + ContextMenuButtonType? type, + String? label, + }) { + return ContextMenuButtonItem( + onPressed: onPressed ?? this.onPressed, + type: type ?? this.type, + label: label ?? this.label, + ); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ContextMenuButtonItem + && other.label == label + && other.onPressed == onPressed + && other.type == type; + } + + @override + int get hashCode => Object.hash(label, onPressed, type); + + @override + String toString() => 'ContextMenuButtonItem $type, $label'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/context_menu_controller.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/context_menu_controller.dart new file mode 100644 index 0000000000000000000000000000000000000000..6e29a2b0ad9bfd63de3064cb2849225f3e5814b2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/context_menu_controller.dart @@ -0,0 +1,130 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'framework.dart'; +import 'inherited_theme.dart'; +import 'navigator.dart'; +import 'overlay.dart'; + +/// Builds and manages a context menu at a given location. +/// +/// There can only ever be one context menu shown at a given time in the entire +/// app. Calling [show] on one instance of this class will hide any other +/// shown instances. +/// +/// {@tool dartpad} +/// This example shows how to use a GestureDetector to show a context menu +/// anywhere in a widget subtree that receives a right click or long press. +/// +/// ** See code in examples/api/lib/material/context_menu/context_menu_controller.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [BrowserContextMenu], which allows the browser's context menu on web to +/// be disabled and Flutter-rendered context menus to appear. +class ContextMenuController { + /// Creates a context menu that can be shown with [show]. + ContextMenuController({ + this.onRemove, + }); + + /// Called when this menu is removed. + final VoidCallback? onRemove; + + /// The currently shown instance, if any. + static ContextMenuController? _shownInstance; + + // The OverlayEntry is static because only one context menu can be displayed + // at one time. + static OverlayEntry? _menuOverlayEntry; + + /// Shows the given context menu. + /// + /// Since there can only be one shown context menu at a time, calling this + /// will also remove any other context menu that is visible. + void show({ + required BuildContext context, + required WidgetBuilder contextMenuBuilder, + Widget? debugRequiredFor, + }) { + removeAny(); + final OverlayState overlayState = Overlay.of( + context, + rootOverlay: true, + debugRequiredFor: debugRequiredFor, + ); + final CapturedThemes capturedThemes = InheritedTheme.capture( + from: context, + to: Navigator.maybeOf(context)?.context, + ); + + _menuOverlayEntry = OverlayEntry( + builder: (BuildContext context) { + return capturedThemes.wrap(contextMenuBuilder(context)); + }, + ); + overlayState.insert(_menuOverlayEntry!); + _shownInstance = this; + } + + /// Remove the currently shown context menu from the UI. + /// + /// Does nothing if no context menu is currently shown. + /// + /// If a menu is removed, and that menu provided an [onRemove] callback when + /// it was created, then that callback will be called. + /// + /// See also: + /// + /// * [remove], which removes only the current instance. + static void removeAny() { + _menuOverlayEntry?.remove(); + _menuOverlayEntry?.dispose(); + _menuOverlayEntry = null; + if (_shownInstance != null) { + _shownInstance!.onRemove?.call(); + _shownInstance = null; + } + } + + /// True if and only if this menu is currently being shown. + bool get isShown => _shownInstance == this; + + /// Cause the underlying [OverlayEntry] to rebuild during the next pipeline + /// flush. + /// + /// It's necessary to call this function if the output of [contextMenuBuilder] + /// has changed. + /// + /// Errors if the context menu is not currently shown. + /// + /// See also: + /// + /// * [OverlayEntry.markNeedsBuild] + void markNeedsBuild() { + assert(isShown); + _menuOverlayEntry?.markNeedsBuild(); + } + + /// Remove this menu from the UI. + /// + /// Does nothing if this instance is not currently shown. In other words, if + /// another context menu is currently shown, that menu will not be removed. + /// + /// This method should only be called once. The instance cannot be shown again + /// after removing. Create a new instance. + /// + /// If an [onRemove] method was given to this instance, it will be called. + /// + /// See also: + /// + /// * [removeAny], which removes any shown instance of the context menu. + void remove() { + if (!isShown) { + return; + } + removeAny(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/debug.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/debug.dart new file mode 100644 index 0000000000000000000000000000000000000000..535ee42145732889dd219795afafe5c24c4c022b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/debug.dart @@ -0,0 +1,516 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:developer' show Timeline; // to disambiguate reference in dartdocs below + +import 'package:flutter/foundation.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'localizations.dart'; +import 'lookup_boundary.dart'; +import 'media_query.dart'; +import 'overlay.dart'; +import 'table.dart'; + +// Examples can assume: +// late BuildContext context; +// List<Widget> children = <Widget>[]; +// List<Widget> items = <Widget>[]; + +// Any changes to this file should be reflected in the debugAssertAllWidgetVarsUnset() +// function below. + +/// Log the dirty widgets that are built each frame. +/// +/// Combined with [debugPrintBuildScope] or [debugPrintBeginFrameBanner], this +/// allows you to distinguish builds triggered by the initial mounting of a +/// widget tree (e.g. in a call to [runApp]) from the regular builds triggered +/// by the pipeline. +/// +/// Combined with [debugPrintScheduleBuildForStacks], this lets you watch a +/// widget's dirty/clean lifecycle. +/// +/// To get similar information but showing it on the timeline available from +/// Flutter DevTools rather than getting it in the console (where it can be +/// overwhelming), consider [debugProfileBuildsEnabled]. +/// +/// See also: +/// +/// * [WidgetsBinding.drawFrame], which pumps the build and rendering pipeline +/// to generate a frame. +bool debugPrintRebuildDirtyWidgets = false; + +/// Signature for [debugOnRebuildDirtyWidget] implementations. +typedef RebuildDirtyWidgetCallback = void Function(Element e, bool builtOnce); + +/// Callback invoked for every dirty widget built each frame. +/// +/// This callback is only invoked in debug builds. +/// +/// See also: +/// +/// * [debugPrintRebuildDirtyWidgets], which does something similar but logs +/// to the console instead of invoking a callback. +/// * [debugOnProfilePaint], which does something similar for [RenderObject] +/// painting. +/// * [WidgetInspectorService], which uses the [debugOnRebuildDirtyWidget] +/// callback to generate aggregate profile statistics describing which widget +/// rebuilds occurred when the +/// `ext.flutter.inspector.trackRebuildDirtyWidgets` service extension is +/// enabled. +RebuildDirtyWidgetCallback? debugOnRebuildDirtyWidget; + +/// Log all calls to [BuildOwner.buildScope]. +/// +/// Combined with [debugPrintScheduleBuildForStacks], this allows you to track +/// when a [State.setState] call gets serviced. +/// +/// Combined with [debugPrintRebuildDirtyWidgets] or +/// [debugPrintBeginFrameBanner], this allows you to distinguish builds +/// triggered by the initial mounting of a widget tree (e.g. in a call to +/// [runApp]) from the regular builds triggered by the pipeline. +/// +/// See also: +/// +/// * [WidgetsBinding.drawFrame], which pumps the build and rendering pipeline +/// to generate a frame. +bool debugPrintBuildScope = false; + +/// Log the call stacks that mark widgets as needing to be rebuilt. +/// +/// This is called whenever [BuildOwner.scheduleBuildFor] adds an element to the +/// dirty list. Typically this is as a result of [Element.markNeedsBuild] being +/// called, which itself is usually a result of [State.setState] being called. +/// +/// To see when a widget is rebuilt, see [debugPrintRebuildDirtyWidgets]. +/// +/// To see when the dirty list is flushed, see [debugPrintBuildScope]. +/// +/// To see when a frame is scheduled, see [debugPrintScheduleFrameStacks]. +bool debugPrintScheduleBuildForStacks = false; + +/// Log when widgets with global keys are deactivated and log when they are +/// reactivated (retaken). +/// +/// This can help track down framework bugs relating to the [GlobalKey] logic. +bool debugPrintGlobalKeyedWidgetLifecycle = false; + +/// Adds [Timeline] events for every Widget built. +/// +/// The timing information this flag exposes is not representative of the actual +/// cost of building, because the overhead of adding timeline events is +/// significant relative to the time each object takes to build. However, it can +/// expose unexpected widget behavior in the timeline. +/// +/// In debug builds, additional information is included in the trace (such as +/// the properties of widgets being built). Collecting this data is +/// expensive and further makes these traces non-representative of actual +/// performance. This data is omitted in profile builds. +/// +/// For more information about performance debugging in Flutter, see +/// <https://flutter.dev/docs/perf/rendering>. +/// +/// See also: +/// +/// * [debugPrintRebuildDirtyWidgets], which does something similar but +/// reporting the builds to the console. +/// * [debugProfileLayoutsEnabled], which does something similar for layout, +/// and [debugPrintLayouts], its console equivalent. +/// * [debugProfilePaintsEnabled], which does something similar for painting. +/// * [debugProfileBuildsEnabledUserWidgets], which adds events for user-created +/// [Widget] build times and incurs less overhead. +/// * [debugEnhanceBuildTimelineArguments], which enhances the trace with +/// debugging information related to [Widget] builds. +bool debugProfileBuildsEnabled = false; + +/// Adds [Timeline] events for every user-created [Widget] built. +/// +/// A user-created [Widget] is any [Widget] that is constructed in the root +/// library. Often [Widget]s contain child [Widget]s that are constructed in +/// libraries (for example, a [TextButton] having a [RichText] child). Timeline +/// events for those children will be omitted with this flag. This works for any +/// [Widget] not just ones declared in the root library. +/// +/// See also: +/// +/// * [debugProfileBuildsEnabled], which functions similarly but shows events +/// for every widget and has a higher overhead cost. +/// * [debugEnhanceBuildTimelineArguments], which enhances the trace with +/// debugging information related to [Widget] builds. +bool debugProfileBuildsEnabledUserWidgets = false; + +/// Adds debugging information to [Timeline] events related to [Widget] builds. +/// +/// This flag will only add [Timeline] event arguments for debug builds. +/// Additional arguments will be added for the "BUILD" [Timeline] event and for +/// all [Widget] build [Timeline] events, which are the [Timeline] events that +/// are added when either of [debugProfileBuildsEnabled] and +/// [debugProfileBuildsEnabledUserWidgets] are true. The debugging information +/// that will be added in trace arguments includes stats around [Widget] dirty +/// states and [Widget] diagnostic information (i.e. [Widget] properties). +/// +/// See also: +/// +/// * [debugProfileBuildsEnabled], which adds [Timeline] events for every +/// [Widget] built. +/// * [debugProfileBuildsEnabledUserWidgets], which adds [Timeline] events for +/// every user-created [Widget] built. +/// * [debugEnhanceLayoutTimelineArguments], which does something similar for +/// events related to [RenderObject] layouts. +/// * [debugEnhancePaintTimelineArguments], which does something similar for +/// events related to [RenderObject] paints. +bool debugEnhanceBuildTimelineArguments = false; + +/// Show banners for deprecated widgets. +bool debugHighlightDeprecatedWidgets = false; + +Key? _firstNonUniqueKey(Iterable<Widget> widgets) { + final Set<Key> keySet = HashSet<Key>(); + for (final Widget widget in widgets) { + if (widget.key == null) { + continue; + } + if (!keySet.add(widget.key!)) { + return widget.key; + } + } + return null; +} + +/// Asserts if the given child list contains any duplicate non-null keys. +/// +/// To invoke this function, use the following pattern: +/// +/// ```dart +/// class MyWidget extends StatelessWidget { +/// MyWidget({ super.key, required this.children }) { +/// assert(!debugChildrenHaveDuplicateKeys(this, children)); +/// } +/// +/// final List<Widget> children; +/// +/// // ... +/// } +/// ``` +/// +/// If specified, the `message` overrides the default message. +/// +/// For a version of this function that can be used in contexts where +/// the list of items does not have a particular parent, see +/// [debugItemsHaveDuplicateKeys]. +/// +/// Does nothing if asserts are disabled. Always returns false. +bool debugChildrenHaveDuplicateKeys(Widget parent, Iterable<Widget> children, { String? message }) { + assert(() { + final Key? nonUniqueKey = _firstNonUniqueKey(children); + if (nonUniqueKey != null) { + throw FlutterError( + "${message ?? 'Duplicate keys found.\n' + 'If multiple keyed widgets exist as children of another widget, they must have unique keys.'}" + '\n$parent has multiple children with key $nonUniqueKey.', + ); + } + return true; + }()); + return false; +} + +/// Asserts if the given list of items contains any duplicate non-null keys. +/// +/// To invoke this function, use the following pattern: +/// +/// ```dart +/// assert(!debugItemsHaveDuplicateKeys(items)); +/// ``` +/// +/// For a version of this function specifically intended for parents +/// checking their children lists, see [debugChildrenHaveDuplicateKeys]. +/// +/// Does nothing if asserts are disabled. Always returns false. +bool debugItemsHaveDuplicateKeys(Iterable<Widget> items) { + assert(() { + final Key? nonUniqueKey = _firstNonUniqueKey(items); + if (nonUniqueKey != null) { + throw FlutterError('Duplicate key found: $nonUniqueKey.'); + } + return true; + }()); + return false; +} + +/// Asserts that the given context has a [Table] ancestor. +/// +/// Used by [TableRowInkWell] to make sure that it is only used in an appropriate context. +/// +/// To invoke this function, use the following pattern, typically in the +/// relevant Widget's build method: +/// +/// ```dart +/// assert(debugCheckHasTable(context)); +/// ``` +/// +/// Always place this before any early returns, so that the invariant is checked +/// in all cases. This prevents bugs from hiding until a particular codepath is +/// hit. +/// +/// This method can be expensive (it walks the element tree). +/// +/// Does nothing if asserts are disabled. Always returns true. +bool debugCheckHasTable(BuildContext context) { + assert(() { + if (context.widget is! Table && context.findAncestorWidgetOfExactType<Table>() == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('No Table widget found.'), + ErrorDescription('${context.widget.runtimeType} widgets require a Table widget ancestor.'), + context.describeWidget('The specific widget that could not find a Table ancestor was'), + context.describeOwnershipChain('The ownership chain for the affected widget is'), + ]); + } + return true; + }()); + return true; +} + +/// Asserts that the given context has a [MediaQuery] ancestor. +/// +/// Used by various widgets to make sure that they are only used in an +/// appropriate context. +/// +/// To invoke this function, use the following pattern, typically in the +/// relevant Widget's build method: +/// +/// ```dart +/// assert(debugCheckHasMediaQuery(context)); +/// ``` +/// +/// Always place this before any early returns, so that the invariant is checked +/// in all cases. This prevents bugs from hiding until a particular codepath is +/// hit. +/// +/// Does nothing if asserts are disabled. Always returns true. +bool debugCheckHasMediaQuery(BuildContext context) { + assert(() { + if (context.widget is! MediaQuery && context.getElementForInheritedWidgetOfExactType<MediaQuery>() == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('No MediaQuery widget ancestor found.'), + ErrorDescription('${context.widget.runtimeType} widgets require a MediaQuery widget ancestor.'), + context.describeWidget('The specific widget that could not find a MediaQuery ancestor was'), + context.describeOwnershipChain('The ownership chain for the affected widget is'), + ErrorHint( + 'No MediaQuery ancestor could be found starting from the context ' + 'that was passed to MediaQuery.of(). This can happen because the ' + 'context used is not a descendant of a View widget, which introduces ' + 'a MediaQuery.' + ), + ]); + } + return true; + }()); + return true; +} + +/// Asserts that the given context has a [Directionality] ancestor. +/// +/// Used by various widgets to make sure that they are only used in an +/// appropriate context. +/// +/// To invoke this function, use the following pattern, typically in the +/// relevant Widget's build method: +/// +/// ```dart +/// assert(debugCheckHasDirectionality(context)); +/// ``` +/// +/// To improve the error messages you can add some extra color using the +/// named arguments. +/// +/// * why: explain why the direction is needed, for example "to resolve +/// the 'alignment' argument". Should be an adverb phrase describing why. +/// * hint: explain why this might be happening, for example "The default +/// value of the 'alignment' argument of the $runtimeType widget is an +/// AlignmentDirectional value.". Should be a fully punctuated sentence. +/// * alternative: provide additional advice specific to the situation, +/// especially an alternative to providing a Directionality ancestor. +/// For example, "Alternatively, consider specifying the 'textDirection' +/// argument.". Should be a fully punctuated sentence. +/// +/// Each one can be null, in which case it is skipped (this is the default). +/// If they are non-null, they are included in the order above, interspersed +/// with the more generic advice regarding [Directionality]. +/// +/// Always place this before any early returns, so that the invariant is checked +/// in all cases. This prevents bugs from hiding until a particular codepath is +/// hit. +/// +/// Does nothing if asserts are disabled. Always returns true. +bool debugCheckHasDirectionality(BuildContext context, { String? why, String? hint, String? alternative }) { + assert(() { + if (context.widget is! Directionality && context.getElementForInheritedWidgetOfExactType<Directionality>() == null) { + why = why == null ? '' : ' $why'; + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('No Directionality widget found.'), + ErrorDescription('${context.widget.runtimeType} widgets require a Directionality widget ancestor$why.\n'), + if (hint != null) + ErrorHint(hint), + context.describeWidget('The specific widget that could not find a Directionality ancestor was'), + context.describeOwnershipChain('The ownership chain for the affected widget is'), + ErrorHint( + 'Typically, the Directionality widget is introduced by the MaterialApp ' + 'or WidgetsApp widget at the top of your application widget tree. It ' + 'determines the ambient reading direction and is used, for example, to ' + 'determine how to lay out text, how to interpret "start" and "end" ' + 'values, and to resolve EdgeInsetsDirectional, ' + 'AlignmentDirectional, and other *Directional objects.', + ), + if (alternative != null) + ErrorHint(alternative), + ]); + } + return true; + }()); + return true; +} + +/// Asserts that the `built` widget is not null. +/// +/// Used when the given `widget` calls a builder function to check that the +/// function returned a non-null value, as typically required. +/// +/// Does nothing when asserts are disabled. +void debugWidgetBuilderValue(Widget widget, Widget? built) { + assert(() { + if (built == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('A build function returned null.'), + DiagnosticsProperty<Widget>('The offending widget is', widget, style: DiagnosticsTreeStyle.errorProperty), + ErrorDescription('Build functions must never return null.'), + ErrorHint( + 'To return an empty space that causes the building widget to fill available room, return "Container()". ' + 'To return an empty space that takes as little room as possible, return "Container(width: 0.0, height: 0.0)".', + ), + ]); + } + if (widget == built) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('A build function returned context.widget.'), + DiagnosticsProperty<Widget>('The offending widget is', widget, style: DiagnosticsTreeStyle.errorProperty), + ErrorDescription( + 'Build functions must never return their BuildContext parameter\'s widget or a child that contains "context.widget". ' + 'Doing so introduces a loop in the widget tree that can cause the app to crash.', + ), + ]); + } + return true; + }()); +} + +/// Asserts that the given context has a [Localizations] ancestor that contains +/// a [WidgetsLocalizations] delegate. +/// +/// To call this function, use the following pattern, typically in the +/// relevant Widget's build method: +/// +/// ```dart +/// assert(debugCheckHasWidgetsLocalizations(context)); +/// ``` +/// +/// Always place this before any early returns, so that the invariant is checked +/// in all cases. This prevents bugs from hiding until a particular codepath is +/// hit. +/// +/// Does nothing if asserts are disabled. Always returns true. +bool debugCheckHasWidgetsLocalizations(BuildContext context) { + assert(() { + if (Localizations.of<WidgetsLocalizations>(context, WidgetsLocalizations) == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('No WidgetsLocalizations found.'), + ErrorDescription( + '${context.widget.runtimeType} widgets require WidgetsLocalizations ' + 'to be provided by a Localizations widget ancestor.', + ), + ErrorDescription( + 'The widgets library uses Localizations to generate messages, ' + 'labels, and abbreviations.', + ), + ErrorHint( + 'To introduce a WidgetsLocalizations, either use a ' + 'WidgetsApp at the root of your application to include them ' + 'automatically, or add a Localization widget with a ' + 'WidgetsLocalizations delegate.', + ), + ...context.describeMissingAncestor(expectedAncestorType: WidgetsLocalizations), + ]); + } + return true; + }()); + return true; +} + +/// Asserts that the given context has an [Overlay] ancestor. +/// +/// To call this function, use the following pattern, typically in the +/// relevant Widget's build method: +/// +/// ```dart +/// assert(debugCheckHasOverlay(context)); +/// ``` +/// +/// Always place this before any early returns, so that the invariant is checked +/// in all cases. This prevents bugs from hiding until a particular codepath is +/// hit. +/// +/// This method can be expensive (it walks the element tree). +/// +/// Does nothing if asserts are disabled. Always returns true. +bool debugCheckHasOverlay(BuildContext context) { + assert(() { + if (LookupBoundary.findAncestorWidgetOfExactType<Overlay>(context) == null) { + final bool hiddenByBoundary = LookupBoundary.debugIsHidingAncestorWidgetOfExactType<Overlay>(context); + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('No Overlay widget found${hiddenByBoundary ? ' within the closest LookupBoundary' : ''}.'), + if (hiddenByBoundary) + ErrorDescription( + 'There is an ancestor Overlay widget, but it is hidden by a LookupBoundary.' + ), + ErrorDescription( + '${context.widget.runtimeType} widgets require an Overlay ' + 'widget ancestor within the closest LookupBoundary.\n' + 'An overlay lets widgets float on top of other widget children.', + ), + ErrorHint( + 'To introduce an Overlay widget, you can either directly ' + 'include one, or use a widget that contains an Overlay itself, ' + 'such as a Navigator, WidgetApp, MaterialApp, or CupertinoApp.', + ), + ...context.describeMissingAncestor(expectedAncestorType: Overlay), + ]); + } + return true; + }()); + return true; +} + +/// Returns true if none of the widget library debug variables have been changed. +/// +/// This function is used by the test framework to ensure that debug variables +/// haven't been inadvertently changed. +/// +/// See [the widgets library](widgets/widgets-library.html) for a complete list. +bool debugAssertAllWidgetVarsUnset(String reason) { + assert(() { + if (debugPrintRebuildDirtyWidgets || + debugPrintBuildScope || + debugPrintScheduleBuildForStacks || + debugPrintGlobalKeyedWidgetLifecycle || + debugProfileBuildsEnabled || + debugHighlightDeprecatedWidgets || + debugProfileBuildsEnabledUserWidgets) { + throw FlutterError(reason); + } + return true; + }()); + return true; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/decorated_sliver.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/decorated_sliver.dart new file mode 100644 index 0000000000000000000000000000000000000000..3cc1b83e87c678663b1428a429f9884b9c9b3e34 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/decorated_sliver.dart @@ -0,0 +1,89 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'image.dart'; + +/// A sliver widget that paints a [Decoration] either before or after its child +/// paints. +/// +/// Unlike [DecoratedBox], this widget expects its child to be a sliver, and +/// must be placed in a widget that expects a sliver. +/// +/// If the child sliver has infinite [SliverGeometry.scrollExtent], then we only +/// draw the decoration down to the bottom [SliverGeometry.cacheExtent], and +/// it is necessary to ensure that the bottom border does not creep +/// above the top of the bottom cache. This can happen if the bottom has a +/// border radius larger than the extent of the cache area. +/// +/// Commonly used with [BoxDecoration]. +/// +/// The [child] is not clipped. To clip a child to the shape of a particular +/// [ShapeDecoration], consider using a [ClipPath] widget. +/// +/// {@tool dartpad} +/// This sample shows a radial gradient that draws a moon on a night sky: +/// +/// ** See code in examples/api/lib/widgets/sliver/decorated_sliver.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [DecoratedBox], the version of this class that works with RenderBox widgets. +/// * [Decoration], which you can extend to provide other effects with +/// [DecoratedSliver]. +/// * [CustomPaint], another way to draw custom effects from the widget layer. +class DecoratedSliver extends SingleChildRenderObjectWidget { + /// Creates a widget that paints a [Decoration]. + /// + /// By default the decoration paints behind the child. + const DecoratedSliver({ + super.key, + required this.decoration, + this.position = DecorationPosition.background, + Widget? sliver, + }) : super(child: sliver); + + /// What decoration to paint. + /// + /// Commonly a [BoxDecoration]. + final Decoration decoration; + + /// Whether to paint the box decoration behind or in front of the child. + final DecorationPosition position; + + @override + RenderDecoratedSliver createRenderObject(BuildContext context) { + return RenderDecoratedSliver( + decoration: decoration, + position: position, + configuration: createLocalImageConfiguration(context), + ); + } + + @override + void updateRenderObject(BuildContext context, RenderDecoratedSliver renderObject) { + renderObject + ..decoration = decoration + ..position = position + ..configuration = createLocalImageConfiguration(context); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + final String label; + switch (position) { + case DecorationPosition.background: + label = 'bg'; + case DecorationPosition.foreground: + label = 'fg'; + } + properties.add(EnumProperty<DecorationPosition>('position', position, level: DiagnosticLevel.hidden)); + properties.add(DiagnosticsProperty<Decoration>(label, decoration)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/default_selection_style.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/default_selection_style.dart new file mode 100644 index 0000000000000000000000000000000000000000..207f6cfa7aafaf37d95a8b1d4da344fe93e2dcee --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/default_selection_style.dart @@ -0,0 +1,136 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'basic.dart'; +import 'framework.dart'; +import 'inherited_theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// The selection style to apply to descendant [EditableText] widgets which +/// don't have an explicit style. +/// +/// {@macro flutter.cupertino.CupertinoApp.defaultSelectionStyle} +/// +/// {@macro flutter.material.MaterialApp.defaultSelectionStyle} +/// +/// See also: +/// * [TextSelectionTheme]: which also creates a [DefaultSelectionStyle] for +/// the subtree. +class DefaultSelectionStyle extends InheritedTheme { + /// Creates a default selection style widget that specifies the selection + /// properties for all widgets below it in the widget tree. + const DefaultSelectionStyle({ + super.key, + this.cursorColor, + this.selectionColor, + this.mouseCursor, + required super.child, + }); + + /// A const-constructable default selection style that provides fallback + /// values (null). + /// + /// Returned from [of] when the given [BuildContext] doesn't have an enclosing + /// default selection style. + /// + /// This constructor creates a [DefaultTextStyle] with an invalid [child], + /// which means the constructed value cannot be incorporated into the tree. + const DefaultSelectionStyle.fallback({ super.key }) + : cursorColor = null, + selectionColor = null, + mouseCursor = null, + super(child: const _NullWidget()); + + /// Creates a default selection style that overrides the selection styles in + /// scope at this point in the widget tree. + /// + /// Any Arguments that are not null replace the corresponding properties on the + /// default selection style for the [BuildContext] where the widget is inserted. + static Widget merge({ + Key? key, + Color? cursorColor, + Color? selectionColor, + MouseCursor? mouseCursor, + required Widget child, + }) { + return Builder( + builder: (BuildContext context) { + final DefaultSelectionStyle parent = DefaultSelectionStyle.of(context); + return DefaultSelectionStyle( + key: key, + cursorColor: cursorColor ?? parent.cursorColor, + selectionColor: selectionColor ?? parent.selectionColor, + mouseCursor: mouseCursor ?? parent.mouseCursor, + child: child, + ); + }, + ); + } + + /// The default cursor and selection color (semi-transparent grey). + /// + /// This is the color that the [Text] widget uses when the specified selection + /// color is null. + static const Color defaultColor = Color(0x80808080); + + /// The color of the text field's cursor. + /// + /// The cursor indicates the current location of the text insertion point in + /// the field. + final Color? cursorColor; + + /// The background color of selected text. + final Color? selectionColor; + + /// The [MouseCursor] for mouse pointers hovering over selectable Text widgets. + /// + /// If this property is null, [SystemMouseCursors.text] will be used. + final MouseCursor? mouseCursor; + + /// The closest instance of this class that encloses the given context. + /// + /// If no such instance exists, returns an instance created by + /// [DefaultSelectionStyle.fallback], which contains fallback values. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// DefaultSelectionStyle style = DefaultSelectionStyle.of(context); + /// ``` + static DefaultSelectionStyle of(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<DefaultSelectionStyle>() ?? const DefaultSelectionStyle.fallback(); + } + + @override + Widget wrap(BuildContext context, Widget child) { + return DefaultSelectionStyle( + cursorColor: cursorColor, + selectionColor: selectionColor, + mouseCursor: mouseCursor, + child: child + ); + } + + @override + bool updateShouldNotify(DefaultSelectionStyle oldWidget) { + return cursorColor != oldWidget.cursorColor || + selectionColor != oldWidget.selectionColor || + mouseCursor != oldWidget.mouseCursor; + } +} + +class _NullWidget extends StatelessWidget { + const _NullWidget(); + + @override + Widget build(BuildContext context) { + throw FlutterError( + 'A DefaultSelectionStyle constructed with DefaultSelectionStyle.fallback cannot be incorporated into the widget tree, ' + 'it is meant only to provide a fallback value returned by DefaultSelectionStyle.of() ' + 'when no enclosing default selection style is present in a BuildContext.', + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/default_text_editing_shortcuts.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/default_text_editing_shortcuts.dart new file mode 100644 index 0000000000000000000000000000000000000000..111f5cf1863843e72e8c4233786c8455ef461d02 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/default_text_editing_shortcuts.dart @@ -0,0 +1,596 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; +import 'package:flutter/services.dart'; + +import 'actions.dart'; +import 'focus_traversal.dart'; +import 'framework.dart'; +import 'scrollable_helpers.dart'; +import 'shortcuts.dart'; +import 'text_editing_intents.dart'; + +/// A widget with the shortcuts used for the default text editing behavior. +/// +/// This default behavior can be overridden by placing a [Shortcuts] widget +/// lower in the widget tree than this. See the [Action] class for an example +/// of remapping an [Intent] to a custom [Action]. +/// +/// The [Shortcuts] widget usually takes precedence over system keybindings. +/// Proceed with caution if the shortcut you wish to override is also used by +/// the system. For example, overriding [LogicalKeyboardKey.backspace] could +/// cause CJK input methods to discard more text than they should when the +/// backspace key is pressed during text composition on iOS. +/// +/// {@tool snippet} +/// +/// This example shows how to use an additional [Shortcuts] widget to override +/// some default text editing keyboard shortcuts to have new behavior. Instead +/// of moving the cursor, alt + up/down will change the focused widget. +/// +/// ```dart +/// @override +/// Widget build(BuildContext context) { +/// // If using WidgetsApp or its descendants MaterialApp or CupertinoApp, +/// // then DefaultTextEditingShortcuts is already being inserted into the +/// // widget tree. +/// return const DefaultTextEditingShortcuts( +/// child: Center( +/// child: Shortcuts( +/// shortcuts: <ShortcutActivator, Intent>{ +/// SingleActivator(LogicalKeyboardKey.arrowDown, alt: true): NextFocusIntent(), +/// SingleActivator(LogicalKeyboardKey.arrowUp, alt: true): PreviousFocusIntent(), +/// }, +/// child: Column( +/// children: <Widget>[ +/// TextField( +/// decoration: InputDecoration( +/// hintText: 'alt + down moves to the next field.', +/// ), +/// ), +/// TextField( +/// decoration: InputDecoration( +/// hintText: 'And alt + up moves to the previous.', +/// ), +/// ), +/// ], +/// ), +/// ), +/// ), +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// +/// This example shows how to use an additional [Shortcuts] widget to override +/// default text editing shortcuts to have completely custom behavior defined by +/// a custom Intent and Action. Here, the up/down arrow keys increment/decrement +/// a counter instead of moving the cursor. +/// +/// ```dart +/// class IncrementCounterIntent extends Intent {} +/// class DecrementCounterIntent extends Intent {} +/// +/// class MyWidget extends StatefulWidget { +/// const MyWidget({ super.key }); +/// +/// @override +/// MyWidgetState createState() => MyWidgetState(); +/// } +/// +/// class MyWidgetState extends State<MyWidget> { +/// +/// int _counter = 0; +/// +/// @override +/// Widget build(BuildContext context) { +/// // If using WidgetsApp or its descendants MaterialApp or CupertinoApp, +/// // then DefaultTextEditingShortcuts is already being inserted into the +/// // widget tree. +/// return DefaultTextEditingShortcuts( +/// child: Center( +/// child: Column( +/// mainAxisAlignment: MainAxisAlignment.center, +/// children: <Widget>[ +/// const Text( +/// 'You have pushed the button this many times:', +/// ), +/// Text( +/// '$_counter', +/// style: Theme.of(context).textTheme.headlineMedium, +/// ), +/// Shortcuts( +/// shortcuts: <ShortcutActivator, Intent>{ +/// const SingleActivator(LogicalKeyboardKey.arrowUp): IncrementCounterIntent(), +/// const SingleActivator(LogicalKeyboardKey.arrowDown): DecrementCounterIntent(), +/// }, +/// child: Actions( +/// actions: <Type, Action<Intent>>{ +/// IncrementCounterIntent: CallbackAction<IncrementCounterIntent>( +/// onInvoke: (IncrementCounterIntent intent) { +/// setState(() { +/// _counter++; +/// }); +/// return null; +/// }, +/// ), +/// DecrementCounterIntent: CallbackAction<DecrementCounterIntent>( +/// onInvoke: (DecrementCounterIntent intent) { +/// setState(() { +/// _counter--; +/// }); +/// return null; +/// }, +/// ), +/// }, +/// child: const TextField( +/// maxLines: 2, +/// decoration: InputDecoration( +/// hintText: 'Up/down increment/decrement here.', +/// ), +/// ), +/// ), +/// ), +/// const TextField( +/// maxLines: 2, +/// decoration: InputDecoration( +/// hintText: 'Up/down behave normally here.', +/// ), +/// ), +/// ], +/// ), +/// ), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [WidgetsApp], which creates a DefaultTextEditingShortcuts. +class DefaultTextEditingShortcuts extends StatelessWidget { + /// Creates a [DefaultTextEditingShortcuts] widget that provides the default text editing + /// shortcuts on the current platform. + const DefaultTextEditingShortcuts({ + super.key, + required this.child, + }); + + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + // These shortcuts are shared between all platforms except Apple platforms, + // because they use different modifier keys as the line/word modifier. + static final Map<ShortcutActivator, Intent> _commonShortcuts = <ShortcutActivator, Intent>{ + // Delete Shortcuts. + for (final bool pressShift in const <bool>[true, false]) + ...<SingleActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.backspace, shift: pressShift): const DeleteCharacterIntent(forward: false), + SingleActivator(LogicalKeyboardKey.backspace, control: true, shift: pressShift): const DeleteToNextWordBoundaryIntent(forward: false), + SingleActivator(LogicalKeyboardKey.backspace, alt: true, shift: pressShift): const DeleteToLineBreakIntent(forward: false), + SingleActivator(LogicalKeyboardKey.delete, shift: pressShift): const DeleteCharacterIntent(forward: true), + SingleActivator(LogicalKeyboardKey.delete, control: true, shift: pressShift): const DeleteToNextWordBoundaryIntent(forward: true), + SingleActivator(LogicalKeyboardKey.delete, alt: true, shift: pressShift): const DeleteToLineBreakIntent(forward: true), + }, + + // Arrow: Move selection. + const SingleActivator(LogicalKeyboardKey.arrowLeft): const ExtendSelectionByCharacterIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowRight): const ExtendSelectionByCharacterIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowUp): const ExtendSelectionVerticallyToAdjacentLineIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowDown): const ExtendSelectionVerticallyToAdjacentLineIntent(forward: true, collapseSelection: true), + + // Shift + Arrow: Extend selection. + const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true): const ExtendSelectionByCharacterIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true): const ExtendSelectionByCharacterIntent(forward: true, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowUp, shift: true): const ExtendSelectionVerticallyToAdjacentLineIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowDown, shift: true): const ExtendSelectionVerticallyToAdjacentLineIntent(forward: true, collapseSelection: false), + + const SingleActivator(LogicalKeyboardKey.arrowLeft, alt: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowRight, alt: true): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowUp, alt: true): const ExtendSelectionToDocumentBoundaryIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowDown, alt: true): const ExtendSelectionToDocumentBoundaryIntent(forward: true, collapseSelection: true), + + const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, alt: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, alt: true): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowUp, shift: true, alt: true): const ExtendSelectionToDocumentBoundaryIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowDown, shift: true, alt: true): const ExtendSelectionToDocumentBoundaryIntent(forward: true, collapseSelection: false), + + const SingleActivator(LogicalKeyboardKey.arrowLeft, control: true): const ExtendSelectionToNextWordBoundaryIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowRight, control: true): const ExtendSelectionToNextWordBoundaryIntent(forward: true, collapseSelection: true), + + const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, control: true): const ExtendSelectionToNextWordBoundaryIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, control: true): const ExtendSelectionToNextWordBoundaryIntent(forward: true, collapseSelection: false), + + const SingleActivator(LogicalKeyboardKey.arrowUp, shift: true, control: true): const ExtendSelectionToNextParagraphBoundaryIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowDown, shift: true, control: true): const ExtendSelectionToNextParagraphBoundaryIntent(forward: true, collapseSelection: false), + + // Page Up / Down: Move selection by page. + const SingleActivator(LogicalKeyboardKey.pageUp): const ExtendSelectionVerticallyToAdjacentPageIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.pageDown): const ExtendSelectionVerticallyToAdjacentPageIntent(forward: true, collapseSelection: true), + + // Shift + Page Up / Down: Extend selection by page. + const SingleActivator(LogicalKeyboardKey.pageUp, shift: true): const ExtendSelectionVerticallyToAdjacentPageIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.pageDown, shift: true): const ExtendSelectionVerticallyToAdjacentPageIntent(forward: true, collapseSelection: false), + + const SingleActivator(LogicalKeyboardKey.keyX, control: true): const CopySelectionTextIntent.cut(SelectionChangedCause.keyboard), + const SingleActivator(LogicalKeyboardKey.keyC, control: true): CopySelectionTextIntent.copy, + const SingleActivator(LogicalKeyboardKey.keyV, control: true): const PasteTextIntent(SelectionChangedCause.keyboard), + const SingleActivator(LogicalKeyboardKey.keyA, control: true): const SelectAllTextIntent(SelectionChangedCause.keyboard), + const SingleActivator(LogicalKeyboardKey.keyZ, control: true): const UndoTextIntent(SelectionChangedCause.keyboard), + const SingleActivator(LogicalKeyboardKey.keyZ, shift: true, control: true): const RedoTextIntent(SelectionChangedCause.keyboard), + // These keys should go to the IME when a field is focused, not to other + // Shortcuts. + const SingleActivator(LogicalKeyboardKey.space): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.enter): const DoNothingAndStopPropagationTextIntent(), + }; + + // The following key combinations have no effect on text editing on this + // platform: + // * End + // * Home + // * Meta + X + // * Meta + C + // * Meta + V + // * Meta + A + // * Meta + shift? + Z + // * Meta + shift? + arrow down + // * Meta + shift? + arrow left + // * Meta + shift? + arrow right + // * Meta + shift? + arrow up + // * Shift + end + // * Shift + home + // * Meta + shift? + delete + // * Meta + shift? + backspace + static final Map<ShortcutActivator, Intent> _androidShortcuts = _commonShortcuts; + + static final Map<ShortcutActivator, Intent> _fuchsiaShortcuts = _androidShortcuts; + + static final Map<ShortcutActivator, Intent> _linuxShortcuts = <ShortcutActivator, Intent>{ + ..._commonShortcuts, + const SingleActivator(LogicalKeyboardKey.home): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.end): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.home, shift: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.end, shift: true): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: false), + // The following key combinations have no effect on text editing on this + // platform: + // * Control + shift? + end + // * Control + shift? + home + // * Meta + X + // * Meta + C + // * Meta + V + // * Meta + A + // * Meta + shift? + Z + // * Meta + shift? + arrow down + // * Meta + shift? + arrow left + // * Meta + shift? + arrow right + // * Meta + shift? + arrow up + // * Meta + shift? + delete + // * Meta + shift? + backspace + }; + + // macOS document shortcuts: https://support.apple.com/en-us/HT201236. + // The macOS shortcuts uses different word/line modifiers than most other + // platforms. + static final Map<ShortcutActivator, Intent> _macShortcuts = <ShortcutActivator, Intent>{ + for (final bool pressShift in const <bool>[true, false]) + ...<SingleActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.backspace, shift: pressShift): const DeleteCharacterIntent(forward: false), + SingleActivator(LogicalKeyboardKey.backspace, alt: true, shift: pressShift): const DeleteToNextWordBoundaryIntent(forward: false), + SingleActivator(LogicalKeyboardKey.backspace, meta: true, shift: pressShift): const DeleteToLineBreakIntent(forward: false), + SingleActivator(LogicalKeyboardKey.delete, shift: pressShift): const DeleteCharacterIntent(forward: true), + SingleActivator(LogicalKeyboardKey.delete, alt: true, shift: pressShift): const DeleteToNextWordBoundaryIntent(forward: true), + SingleActivator(LogicalKeyboardKey.delete, meta: true, shift: pressShift): const DeleteToLineBreakIntent(forward: true), + }, + + const SingleActivator(LogicalKeyboardKey.arrowLeft): const ExtendSelectionByCharacterIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowRight): const ExtendSelectionByCharacterIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowUp): const ExtendSelectionVerticallyToAdjacentLineIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowDown): const ExtendSelectionVerticallyToAdjacentLineIntent(forward: true, collapseSelection: true), + + // Shift + Arrow: Extend selection. + const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true): const ExtendSelectionByCharacterIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true): const ExtendSelectionByCharacterIntent(forward: true, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowUp, shift: true): const ExtendSelectionVerticallyToAdjacentLineIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.arrowDown, shift: true): const ExtendSelectionVerticallyToAdjacentLineIntent(forward: true, collapseSelection: false), + + const SingleActivator(LogicalKeyboardKey.arrowLeft, alt: true): const ExtendSelectionToNextWordBoundaryIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowRight, alt: true): const ExtendSelectionToNextWordBoundaryIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowUp, alt: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowDown, alt: true): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: true), + + const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, alt: true): const ExtendSelectionToNextWordBoundaryOrCaretLocationIntent(forward: false), + const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, alt: true): const ExtendSelectionToNextWordBoundaryOrCaretLocationIntent(forward: true), + const SingleActivator(LogicalKeyboardKey.arrowUp, shift: true, alt: true): const ExtendSelectionToNextParagraphBoundaryOrCaretLocationIntent(forward: false), + const SingleActivator(LogicalKeyboardKey.arrowDown, shift: true, alt: true): const ExtendSelectionToNextParagraphBoundaryOrCaretLocationIntent(forward: true), + + const SingleActivator(LogicalKeyboardKey.arrowLeft, meta: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowRight, meta: true): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowUp, meta: true): const ExtendSelectionToDocumentBoundaryIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.arrowDown, meta: true): const ExtendSelectionToDocumentBoundaryIntent(forward: true, collapseSelection: true), + + const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, meta: true): const ExpandSelectionToLineBreakIntent(forward: false), + const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, meta: true): const ExpandSelectionToLineBreakIntent(forward: true), + const SingleActivator(LogicalKeyboardKey.arrowUp, shift: true, meta: true): const ExpandSelectionToDocumentBoundaryIntent(forward: false), + const SingleActivator(LogicalKeyboardKey.arrowDown, shift: true, meta: true): const ExpandSelectionToDocumentBoundaryIntent(forward: true), + + const SingleActivator(LogicalKeyboardKey.keyT, control: true): const TransposeCharactersIntent(), + + const SingleActivator(LogicalKeyboardKey.home): const ScrollToDocumentBoundaryIntent(forward: false), + const SingleActivator(LogicalKeyboardKey.end): const ScrollToDocumentBoundaryIntent(forward: true), + const SingleActivator(LogicalKeyboardKey.home, shift: true): const ExpandSelectionToDocumentBoundaryIntent(forward: false), + const SingleActivator(LogicalKeyboardKey.end, shift: true): const ExpandSelectionToDocumentBoundaryIntent(forward: true), + + const SingleActivator(LogicalKeyboardKey.pageUp): const ScrollIntent(direction: AxisDirection.up, type: ScrollIncrementType.page), + const SingleActivator(LogicalKeyboardKey.pageDown): const ScrollIntent(direction: AxisDirection.down, type: ScrollIncrementType.page), + const SingleActivator(LogicalKeyboardKey.pageUp, shift: true): const ExtendSelectionVerticallyToAdjacentPageIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.pageDown, shift: true): const ExtendSelectionVerticallyToAdjacentPageIntent(forward: true, collapseSelection: false), + + const SingleActivator(LogicalKeyboardKey.keyX, meta: true): const CopySelectionTextIntent.cut(SelectionChangedCause.keyboard), + const SingleActivator(LogicalKeyboardKey.keyC, meta: true): CopySelectionTextIntent.copy, + const SingleActivator(LogicalKeyboardKey.keyV, meta: true): const PasteTextIntent(SelectionChangedCause.keyboard), + const SingleActivator(LogicalKeyboardKey.keyA, meta: true): const SelectAllTextIntent(SelectionChangedCause.keyboard), + const SingleActivator(LogicalKeyboardKey.keyZ, meta: true): const UndoTextIntent(SelectionChangedCause.keyboard), + const SingleActivator(LogicalKeyboardKey.keyZ, shift: true, meta: true): const RedoTextIntent(SelectionChangedCause.keyboard), + const SingleActivator(LogicalKeyboardKey.keyE, control: true): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.keyA, control: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.keyF, control: true): const ExtendSelectionByCharacterIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.keyB, control: true): const ExtendSelectionByCharacterIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.keyN, control: true): const ExtendSelectionVerticallyToAdjacentLineIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.keyP, control: true): const ExtendSelectionVerticallyToAdjacentLineIntent(forward: false, collapseSelection: true), + // These keys should go to the IME when a field is focused, not to other + // Shortcuts. + const SingleActivator(LogicalKeyboardKey.space): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.enter): const DoNothingAndStopPropagationTextIntent(), + // The following key combinations have no effect on text editing on this + // platform: + // * End + // * Home + // * Control + shift? + end + // * Control + shift? + home + // * Control + shift? + Z + }; + + // There is no complete documentation of iOS shortcuts: use macOS ones. + static final Map<ShortcutActivator, Intent> _iOSShortcuts = _macShortcuts; + + // The following key combinations have no effect on text editing on this + // platform: + // * Meta + X + // * Meta + C + // * Meta + V + // * Meta + A + // * Meta + shift? + arrow down + // * Meta + shift? + arrow left + // * Meta + shift? + arrow right + // * Meta + shift? + arrow up + // * Meta + delete + // * Meta + backspace + static final Map<ShortcutActivator, Intent> _windowsShortcuts = <ShortcutActivator, Intent>{ + ..._commonShortcuts, + const SingleActivator(LogicalKeyboardKey.pageUp): const ExtendSelectionVerticallyToAdjacentPageIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.pageDown): const ExtendSelectionVerticallyToAdjacentPageIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.home): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: true, continuesAtWrap: true), + const SingleActivator(LogicalKeyboardKey.end): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: true, continuesAtWrap: true), + const SingleActivator(LogicalKeyboardKey.home, shift: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: false, continuesAtWrap: true), + const SingleActivator(LogicalKeyboardKey.end, shift: true): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: false, continuesAtWrap: true), + const SingleActivator(LogicalKeyboardKey.home, control: true): const ExtendSelectionToDocumentBoundaryIntent(forward: false, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.end, control: true): const ExtendSelectionToDocumentBoundaryIntent(forward: true, collapseSelection: true), + const SingleActivator(LogicalKeyboardKey.home, shift: true, control: true): const ExtendSelectionToDocumentBoundaryIntent(forward: false, collapseSelection: false), + const SingleActivator(LogicalKeyboardKey.end, shift: true, control: true): const ExtendSelectionToDocumentBoundaryIntent(forward: true, collapseSelection: false), + }; + + // Web handles its text selection natively and doesn't use any of these + // shortcuts in Flutter. + static final Map<ShortcutActivator, Intent> _webDisablingTextShortcuts = <ShortcutActivator, Intent>{ + for (final bool pressShift in const <bool>[true, false]) + ...<SingleActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.backspace, shift: pressShift): const DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.delete, shift: pressShift): const DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.backspace, alt: true, shift: pressShift): const DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.delete, alt: true, shift: pressShift): const DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.backspace, control: true, shift: pressShift): const DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.delete, control: true, shift: pressShift): const DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.backspace, meta: true, shift: pressShift): const DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.delete, meta: true, shift: pressShift): const DoNothingAndStopPropagationTextIntent(), + }, + ..._commonDisablingTextShortcuts, + const SingleActivator(LogicalKeyboardKey.keyX, control: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.keyX, meta: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.keyC, control: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.keyC, meta: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.keyV, control: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.keyV, meta: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.keyA, control: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.keyA, meta: true): const DoNothingAndStopPropagationTextIntent(), + }; + + static const Map<ShortcutActivator, Intent> _commonDisablingTextShortcuts = <ShortcutActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.arrowDown, alt: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowLeft, alt: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowRight, alt: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowUp, alt: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowDown, meta: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowLeft, meta: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowRight, meta: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowUp, meta: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowDown): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowLeft): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowRight): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowUp): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowLeft, control: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowRight, control: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, control: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, control: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.space): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.enter): DoNothingAndStopPropagationTextIntent(), + }; + + static final Map<ShortcutActivator, Intent> _macDisablingTextShortcuts = <ShortcutActivator, Intent>{ + ..._commonDisablingTextShortcuts, + ..._iOSDisablingTextShortcuts, + const SingleActivator(LogicalKeyboardKey.escape): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.tab): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.tab, shift: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.arrowDown, shift: true, alt: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.arrowUp, shift: true, alt: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, alt: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, alt: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, meta: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, meta: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.pageUp): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.pageDown): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.end): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.home): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.pageUp, shift: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.pageDown, shift: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.end, shift: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.home, shift: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.end, control: true): const DoNothingAndStopPropagationTextIntent(), + const SingleActivator(LogicalKeyboardKey.home, control: true): const DoNothingAndStopPropagationTextIntent(), + }; + + // Hand backspace/delete events that do not depend on text layout (delete + // character and delete to the next word) back to the IME to allow it to + // update composing text properly. + static const Map<ShortcutActivator, Intent> _iOSDisablingTextShortcuts = <ShortcutActivator, Intent>{ + SingleActivator(LogicalKeyboardKey.backspace): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.backspace, shift: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.delete): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.delete, shift: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.backspace, alt: true, shift: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.backspace, alt: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.delete, alt: true, shift: true): DoNothingAndStopPropagationTextIntent(), + SingleActivator(LogicalKeyboardKey.delete, alt: true): DoNothingAndStopPropagationTextIntent(), + }; + + static Map<ShortcutActivator, Intent> get _shortcuts { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + return _androidShortcuts; + case TargetPlatform.fuchsia: + return _fuchsiaShortcuts; + case TargetPlatform.iOS: + return _iOSShortcuts; + case TargetPlatform.linux: + return _linuxShortcuts; + case TargetPlatform.macOS: + return _macShortcuts; + case TargetPlatform.windows: + return _windowsShortcuts; + } + } + + Map<ShortcutActivator, Intent>? _getDisablingShortcut() { + if (kIsWeb) { + return _webDisablingTextShortcuts; + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return null; + case TargetPlatform.iOS: + return _iOSDisablingTextShortcuts; + case TargetPlatform.macOS: + return _macDisablingTextShortcuts; + } + } + + @override + Widget build(BuildContext context) { + Widget result = child; + final Map<ShortcutActivator, Intent>? disablingShortcut = _getDisablingShortcut(); + if (disablingShortcut != null) { + // These shortcuts make sure of the following: + // + // 1. Shortcuts fired when an EditableText is focused are ignored and + // forwarded to the platform by the EditableText's Actions, because it + // maps DoNothingAndStopPropagationTextIntent to DoNothingAction. + // 2. Shortcuts fired when no EditableText is focused will still trigger + // _shortcuts assuming DoNothingAndStopPropagationTextIntent is + // unhandled elsewhere. + result = Shortcuts( + debugLabel: '<Web Disabling Text Editing Shortcuts>', + shortcuts: disablingShortcut, + child: result + ); + } + return Shortcuts( + debugLabel: '<Default Text Editing Shortcuts>', + shortcuts: _shortcuts, + child: result + ); + } +} + +/// Maps the selector from NSStandardKeyBindingResponding to the Intent if the +/// selector is recognized. +Intent? intentForMacOSSelector(String selectorName) { + const Map<String, Intent> selectorToIntent = <String, Intent>{ + 'deleteBackward:': DeleteCharacterIntent(forward: false), + 'deleteWordBackward:': DeleteToNextWordBoundaryIntent(forward: false), + 'deleteToBeginningOfLine:': DeleteToLineBreakIntent(forward: false), + 'deleteForward:': DeleteCharacterIntent(forward: true), + 'deleteWordForward:': DeleteToNextWordBoundaryIntent(forward: true), + 'deleteToEndOfLine:': DeleteToLineBreakIntent(forward: true), + + 'moveLeft:': ExtendSelectionByCharacterIntent(forward: false, collapseSelection: true), + 'moveRight:': ExtendSelectionByCharacterIntent(forward: true, collapseSelection: true), + 'moveForward:': ExtendSelectionByCharacterIntent(forward: true, collapseSelection: true), + 'moveBackward:': ExtendSelectionByCharacterIntent(forward: false, collapseSelection: true), + + 'moveUp:': ExtendSelectionVerticallyToAdjacentLineIntent(forward: false, collapseSelection: true), + 'moveDown:': ExtendSelectionVerticallyToAdjacentLineIntent(forward: true, collapseSelection: true), + + 'moveLeftAndModifySelection:': ExtendSelectionByCharacterIntent(forward: false, collapseSelection: false), + 'moveRightAndModifySelection:': ExtendSelectionByCharacterIntent(forward: true, collapseSelection: false), + 'moveUpAndModifySelection:': ExtendSelectionVerticallyToAdjacentLineIntent(forward: false, collapseSelection: false), + 'moveDownAndModifySelection:': ExtendSelectionVerticallyToAdjacentLineIntent(forward: true, collapseSelection: false), + + 'moveWordLeft:': ExtendSelectionToNextWordBoundaryIntent(forward: false, collapseSelection: true), + 'moveWordRight:': ExtendSelectionToNextWordBoundaryIntent(forward: true, collapseSelection: true), + 'moveToBeginningOfParagraph:': ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: true), + 'moveToEndOfParagraph:': ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: true), + + 'moveWordLeftAndModifySelection:': ExtendSelectionToNextWordBoundaryOrCaretLocationIntent(forward: false), + 'moveWordRightAndModifySelection:': ExtendSelectionToNextWordBoundaryOrCaretLocationIntent(forward: true), + 'moveParagraphBackwardAndModifySelection:': ExtendSelectionToNextParagraphBoundaryOrCaretLocationIntent(forward: false), + 'moveParagraphForwardAndModifySelection:': ExtendSelectionToNextParagraphBoundaryOrCaretLocationIntent(forward: true), + + 'moveToLeftEndOfLine:': ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: true), + 'moveToRightEndOfLine:': ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: true), + 'moveToBeginningOfDocument:': ExtendSelectionToDocumentBoundaryIntent(forward: false, collapseSelection: true), + 'moveToEndOfDocument:': ExtendSelectionToDocumentBoundaryIntent(forward: true, collapseSelection: true), + + 'moveToLeftEndOfLineAndModifySelection:': ExpandSelectionToLineBreakIntent(forward: false), + 'moveToRightEndOfLineAndModifySelection:': ExpandSelectionToLineBreakIntent(forward: true), + 'moveToBeginningOfDocumentAndModifySelection:': ExpandSelectionToDocumentBoundaryIntent(forward: false), + 'moveToEndOfDocumentAndModifySelection:': ExpandSelectionToDocumentBoundaryIntent(forward: true), + + 'transpose:': TransposeCharactersIntent(), + + 'scrollToBeginningOfDocument:': ScrollToDocumentBoundaryIntent(forward: false), + 'scrollToEndOfDocument:': ScrollToDocumentBoundaryIntent(forward: true), + + 'scrollPageUp:': ScrollIntent(direction: AxisDirection.up, type: ScrollIncrementType.page), + 'scrollPageDown:': ScrollIntent(direction: AxisDirection.down, type: ScrollIncrementType.page), + 'pageUpAndModifySelection:': ExtendSelectionVerticallyToAdjacentPageIntent(forward: false, collapseSelection: false), + 'pageDownAndModifySelection:': ExtendSelectionVerticallyToAdjacentPageIntent(forward: true, collapseSelection: false), + + // Escape key when there's no IME selection popup. + 'cancelOperation:': DismissIntent(), + // Tab when there's no IME selection. + 'insertTab:': NextFocusIntent(), + 'insertBacktab:': PreviousFocusIntent(), + }; + return selectorToIntent[selectorName]; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/desktop_text_selection_toolbar_layout_delegate.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/desktop_text_selection_toolbar_layout_delegate.dart new file mode 100644 index 0000000000000000000000000000000000000000..706c28f4536cfe1ff07d6e352bc5892d2fc27cf9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/desktop_text_selection_toolbar_layout_delegate.dart @@ -0,0 +1,50 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +/// Positions the toolbar at [anchor] if it fits, otherwise moves it so that it +/// just fits fully on-screen. +/// +/// See also: +/// +/// * [desktopTextSelectionControls], which uses this to position +/// itself. +/// * [cupertinoDesktopTextSelectionControls], which uses this to position +/// itself. +/// * [TextSelectionToolbarLayoutDelegate], which does a similar layout for +/// the mobile text selection toolbars. +class DesktopTextSelectionToolbarLayoutDelegate extends SingleChildLayoutDelegate { + /// Creates an instance of TextSelectionToolbarLayoutDelegate. + DesktopTextSelectionToolbarLayoutDelegate({ + required this.anchor, + }); + + /// The point at which to render the menu, if possible. + /// + /// Should be provided in local coordinates. + final Offset anchor; + + @override + BoxConstraints getConstraintsForChild(BoxConstraints constraints) { + return constraints.loosen(); + } + + @override + Offset getPositionForChild(Size size, Size childSize) { + final Offset overhang = Offset( + anchor.dx + childSize.width - size.width, + anchor.dy + childSize.height - size.height, + ); + return Offset( + overhang.dx > 0.0 ? anchor.dx - overhang.dx : anchor.dx, + overhang.dy > 0.0 ? anchor.dy - overhang.dy : anchor.dy, + ); + } + + @override + bool shouldRelayout(DesktopTextSelectionToolbarLayoutDelegate oldDelegate) { + return anchor != oldDelegate.anchor; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/dismissible.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/dismissible.dart new file mode 100644 index 0000000000000000000000000000000000000000..0fe4bdfcd51c7ebdc778ec1d1868f2430c6fbf9f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/dismissible.dart @@ -0,0 +1,691 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/gestures.dart'; + +import 'automatic_keep_alive.dart'; +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'ticker_provider.dart'; +import 'transitions.dart'; + +const Curve _kResizeTimeCurve = Interval(0.4, 1.0, curve: Curves.ease); +const double _kMinFlingVelocity = 700.0; +const double _kMinFlingVelocityDelta = 400.0; +const double _kFlingVelocityScale = 1.0 / 300.0; +const double _kDismissThreshold = 0.4; + +/// Signature used by [Dismissible] to indicate that it has been dismissed in +/// the given `direction`. +/// +/// Used by [Dismissible.onDismissed]. +typedef DismissDirectionCallback = void Function(DismissDirection direction); + +/// Signature used by [Dismissible] to give the application an opportunity to +/// confirm or veto a dismiss gesture. +/// +/// Used by [Dismissible.confirmDismiss]. +typedef ConfirmDismissCallback = Future<bool?> Function(DismissDirection direction); + +/// Signature used by [Dismissible] to indicate that the dismissible has been dragged. +/// +/// Used by [Dismissible.onUpdate]. +typedef DismissUpdateCallback = void Function(DismissUpdateDetails details); + +/// The direction in which a [Dismissible] can be dismissed. +enum DismissDirection { + /// The [Dismissible] can be dismissed by dragging either up or down. + vertical, + + /// The [Dismissible] can be dismissed by dragging either left or right. + horizontal, + + /// The [Dismissible] can be dismissed by dragging in the reverse of the + /// reading direction (e.g., from right to left in left-to-right languages). + endToStart, + + /// The [Dismissible] can be dismissed by dragging in the reading direction + /// (e.g., from left to right in left-to-right languages). + startToEnd, + + /// The [Dismissible] can be dismissed by dragging up only. + up, + + /// The [Dismissible] can be dismissed by dragging down only. + down, + + /// The [Dismissible] cannot be dismissed by dragging. + none +} + +/// A widget that can be dismissed by dragging in the indicated [direction]. +/// +/// Dragging or flinging this widget in the [DismissDirection] causes the child +/// to slide out of view. Following the slide animation, if [resizeDuration] is +/// non-null, the Dismissible widget animates its height (or width, whichever is +/// perpendicular to the dismiss direction) to zero over the [resizeDuration]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=iEMgjrfuc58} +/// +/// {@tool dartpad} +/// This sample shows how you can use the [Dismissible] widget to +/// remove list items using swipe gestures. Swipe any of the list +/// tiles to the left or right to dismiss them from the [ListView]. +/// +/// ** See code in examples/api/lib/widgets/dismissible/dismissible.0.dart ** +/// {@end-tool} +/// +/// Backgrounds can be used to implement the "leave-behind" idiom. If a background +/// is specified it is stacked behind the Dismissible's child and is exposed when +/// the child moves. +/// +/// The widget calls the [onDismissed] callback either after its size has +/// collapsed to zero (if [resizeDuration] is non-null) or immediately after +/// the slide animation (if [resizeDuration] is null). If the Dismissible is a +/// list item, it must have a key that distinguishes it from the other items and +/// its [onDismissed] callback must remove the item from the list. +class Dismissible extends StatefulWidget { + /// Creates a widget that can be dismissed. + /// + /// The [key] argument is required because [Dismissible]s are commonly used in + /// lists and removed from the list when dismissed. Without keys, the default + /// behavior is to sync widgets based on their index in the list, which means + /// the item after the dismissed item would be synced with the state of the + /// dismissed item. Using keys causes the widgets to sync according to their + /// keys and avoids this pitfall. + const Dismissible({ + required Key key, + required this.child, + this.background, + this.secondaryBackground, + this.confirmDismiss, + this.onResize, + this.onUpdate, + this.onDismissed, + this.direction = DismissDirection.horizontal, + this.resizeDuration = const Duration(milliseconds: 300), + this.dismissThresholds = const <DismissDirection, double>{}, + this.movementDuration = const Duration(milliseconds: 200), + this.crossAxisEndOffset = 0.0, + this.dragStartBehavior = DragStartBehavior.start, + this.behavior = HitTestBehavior.opaque, + }) : assert(secondaryBackground == null || background != null), + super(key: key); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// A widget that is stacked behind the child. If secondaryBackground is also + /// specified then this widget only appears when the child has been dragged + /// down or to the right. + final Widget? background; + + /// A widget that is stacked behind the child and is exposed when the child + /// has been dragged up or to the left. It may only be specified when background + /// has also been specified. + final Widget? secondaryBackground; + + /// Gives the app an opportunity to confirm or veto a pending dismissal. + /// + /// The widget cannot be dragged again until the returned future resolves. + /// + /// If the returned Future<bool> completes true, then this widget will be + /// dismissed, otherwise it will be moved back to its original location. + /// + /// If the returned Future<bool?> completes to false or null the [onResize] + /// and [onDismissed] callbacks will not run. + final ConfirmDismissCallback? confirmDismiss; + + /// Called when the widget changes size (i.e., when contracting before being dismissed). + final VoidCallback? onResize; + + /// Called when the widget has been dismissed, after finishing resizing. + final DismissDirectionCallback? onDismissed; + + /// The direction in which the widget can be dismissed. + final DismissDirection direction; + + /// The amount of time the widget will spend contracting before [onDismissed] is called. + /// + /// If null, the widget will not contract and [onDismissed] will be called + /// immediately after the widget is dismissed. + final Duration? resizeDuration; + + /// The offset threshold the item has to be dragged in order to be considered + /// dismissed. + /// + /// Represented as a fraction, e.g. if it is 0.4 (the default), then the item + /// has to be dragged at least 40% towards one direction to be considered + /// dismissed. Clients can define different thresholds for each dismiss + /// direction. + /// + /// Flinging is treated as being equivalent to dragging almost to 1.0, so + /// flinging can dismiss an item past any threshold less than 1.0. + /// + /// Setting a threshold of 1.0 (or greater) prevents a drag in the given + /// [DismissDirection] even if it would be allowed by the [direction] + /// property. + /// + /// See also: + /// + /// * [direction], which controls the directions in which the items can + /// be dismissed. + final Map<DismissDirection, double> dismissThresholds; + + /// Defines the duration for card to dismiss or to come back to original position if not dismissed. + final Duration movementDuration; + + /// Defines the end offset across the main axis after the card is dismissed. + /// + /// If non-zero value is given then widget moves in cross direction depending on whether + /// it is positive or negative. + final double crossAxisEndOffset; + + /// Determines the way that drag start behavior is handled. + /// + /// If set to [DragStartBehavior.start], the drag gesture used to dismiss a + /// dismissible will begin at the position where the drag gesture won the arena. + /// If set to [DragStartBehavior.down] it will begin at the position where + /// a down event is first detected. + /// + /// In general, setting this to [DragStartBehavior.start] will make drag + /// animation smoother and setting it to [DragStartBehavior.down] will make + /// drag behavior feel slightly more reactive. + /// + /// By default, the drag start behavior is [DragStartBehavior.start]. + /// + /// See also: + /// + /// * [DragGestureRecognizer.dragStartBehavior], which gives an example for the different behaviors. + final DragStartBehavior dragStartBehavior; + + /// How to behave during hit tests. + /// + /// This defaults to [HitTestBehavior.opaque]. + final HitTestBehavior behavior; + + /// Called when the dismissible widget has been dragged. + /// + /// If [onUpdate] is not null, then it will be invoked for every pointer event + /// to dispatch the latest state of the drag. For example, this callback + /// can be used to for example change the color of the background widget + /// depending on whether the dismiss threshold is currently reached. + final DismissUpdateCallback? onUpdate; + + @override + State<Dismissible> createState() => _DismissibleState(); +} + +/// Details for [DismissUpdateCallback]. +/// +/// See also: +/// +/// * [Dismissible.onUpdate], which receives this information. +class DismissUpdateDetails { + /// Create a new instance of [DismissUpdateDetails]. + DismissUpdateDetails({ + this.direction = DismissDirection.horizontal, + this.reached = false, + this.previousReached = false, + this.progress = 0.0, + }); + + /// The direction that the dismissible is being dragged. + final DismissDirection direction; + + /// Whether the dismiss threshold is currently reached. + final bool reached; + + /// Whether the dismiss threshold was reached the last time this callback was invoked. + /// + /// This can be used in conjunction with [DismissUpdateDetails.reached] to catch the moment + /// that the [Dismissible] is dragged across the threshold. + final bool previousReached; + + /// The offset ratio of the dismissible in its parent container. + /// + /// A value of 0.0 represents the normal position and 1.0 means the child is + /// completely outside its parent. + /// + /// This can be used to synchronize other elements to what the dismissible is doing on screen, + /// e.g. using this value to set the opacity thereby fading dismissible as it's dragged offscreen. + final double progress; +} + +class _DismissibleClipper extends CustomClipper<Rect> { + _DismissibleClipper({ + required this.axis, + required this.moveAnimation, + }) : super(reclip: moveAnimation); + + final Axis axis; + final Animation<Offset> moveAnimation; + + @override + Rect getClip(Size size) { + switch (axis) { + case Axis.horizontal: + final double offset = moveAnimation.value.dx * size.width; + if (offset < 0) { + return Rect.fromLTRB(size.width + offset, 0.0, size.width, size.height); + } + return Rect.fromLTRB(0.0, 0.0, offset, size.height); + case Axis.vertical: + final double offset = moveAnimation.value.dy * size.height; + if (offset < 0) { + return Rect.fromLTRB(0.0, size.height + offset, size.width, size.height); + } + return Rect.fromLTRB(0.0, 0.0, size.width, offset); + } + } + + @override + Rect getApproximateClipRect(Size size) => getClip(size); + + @override + bool shouldReclip(_DismissibleClipper oldClipper) { + return oldClipper.axis != axis + || oldClipper.moveAnimation.value != moveAnimation.value; + } +} + +enum _FlingGestureKind { none, forward, reverse } + +class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { + @override + void initState() { + super.initState(); + _moveController = AnimationController(duration: widget.movementDuration, vsync: this) + ..addStatusListener(_handleDismissStatusChanged) + ..addListener(_handleDismissUpdateValueChanged); + _updateMoveAnimation(); + } + + AnimationController? _moveController; + late Animation<Offset> _moveAnimation; + + AnimationController? _resizeController; + Animation<double>? _resizeAnimation; + + double _dragExtent = 0.0; + bool _confirming = false; + bool _dragUnderway = false; + Size? _sizePriorToCollapse; + bool _dismissThresholdReached = false; + + final GlobalKey _contentKey = GlobalKey(); + + @override + bool get wantKeepAlive => (_moveController?.isAnimating ?? false) || (_resizeController?.isAnimating ?? false); + + @override + void dispose() { + _moveController!.dispose(); + _resizeController?.dispose(); + super.dispose(); + } + + bool get _directionIsXAxis { + return widget.direction == DismissDirection.horizontal + || widget.direction == DismissDirection.endToStart + || widget.direction == DismissDirection.startToEnd; + } + + DismissDirection _extentToDirection(double extent) { + if (extent == 0.0) { + return DismissDirection.none; + } + if (_directionIsXAxis) { + switch (Directionality.of(context)) { + case TextDirection.rtl: + return extent < 0 ? DismissDirection.startToEnd : DismissDirection.endToStart; + case TextDirection.ltr: + return extent > 0 ? DismissDirection.startToEnd : DismissDirection.endToStart; + } + } + return extent > 0 ? DismissDirection.down : DismissDirection.up; + } + + DismissDirection get _dismissDirection => _extentToDirection(_dragExtent); + + bool get _isActive { + return _dragUnderway || _moveController!.isAnimating; + } + + double get _overallDragAxisExtent { + final Size size = context.size!; + return _directionIsXAxis ? size.width : size.height; + } + + void _handleDragStart(DragStartDetails details) { + if (_confirming) { + return; + } + _dragUnderway = true; + if (_moveController!.isAnimating) { + _dragExtent = _moveController!.value * _overallDragAxisExtent * _dragExtent.sign; + _moveController!.stop(); + } else { + _dragExtent = 0.0; + _moveController!.value = 0.0; + } + setState(() { + _updateMoveAnimation(); + }); + } + + void _handleDragUpdate(DragUpdateDetails details) { + if (!_isActive || _moveController!.isAnimating) { + return; + } + + final double delta = details.primaryDelta!; + final double oldDragExtent = _dragExtent; + switch (widget.direction) { + case DismissDirection.horizontal: + case DismissDirection.vertical: + _dragExtent += delta; + + case DismissDirection.up: + if (_dragExtent + delta < 0) { + _dragExtent += delta; + } + + case DismissDirection.down: + if (_dragExtent + delta > 0) { + _dragExtent += delta; + } + + case DismissDirection.endToStart: + switch (Directionality.of(context)) { + case TextDirection.rtl: + if (_dragExtent + delta > 0) { + _dragExtent += delta; + } + case TextDirection.ltr: + if (_dragExtent + delta < 0) { + _dragExtent += delta; + } + } + + case DismissDirection.startToEnd: + switch (Directionality.of(context)) { + case TextDirection.rtl: + if (_dragExtent + delta < 0) { + _dragExtent += delta; + } + case TextDirection.ltr: + if (_dragExtent + delta > 0) { + _dragExtent += delta; + } + } + + case DismissDirection.none: + _dragExtent = 0; + } + if (oldDragExtent.sign != _dragExtent.sign) { + setState(() { + _updateMoveAnimation(); + }); + } + if (!_moveController!.isAnimating) { + _moveController!.value = _dragExtent.abs() / _overallDragAxisExtent; + } + } + + void _handleDismissUpdateValueChanged() { + if (widget.onUpdate != null) { + final bool oldDismissThresholdReached = _dismissThresholdReached; + _dismissThresholdReached = _moveController!.value > (widget.dismissThresholds[_dismissDirection] ?? _kDismissThreshold); + final DismissUpdateDetails details = DismissUpdateDetails( + direction: _dismissDirection, + reached: _dismissThresholdReached, + previousReached: oldDismissThresholdReached, + progress: _moveController!.value, + ); + widget.onUpdate!(details); + } + } + + void _updateMoveAnimation() { + final double end = _dragExtent.sign; + _moveAnimation = _moveController!.drive( + Tween<Offset>( + begin: Offset.zero, + end: _directionIsXAxis + ? Offset(end, widget.crossAxisEndOffset) + : Offset(widget.crossAxisEndOffset, end), + ), + ); + } + + _FlingGestureKind _describeFlingGesture(Velocity velocity) { + if (_dragExtent == 0.0) { + // If it was a fling, then it was a fling that was let loose at the exact + // middle of the range (i.e. when there's no displacement). In that case, + // we assume that the user meant to fling it back to the center, as + // opposed to having wanted to drag it out one way, then fling it past the + // center and into and out the other side. + return _FlingGestureKind.none; + } + final double vx = velocity.pixelsPerSecond.dx; + final double vy = velocity.pixelsPerSecond.dy; + DismissDirection flingDirection; + // Verify that the fling is in the generally right direction and fast enough. + if (_directionIsXAxis) { + if (vx.abs() - vy.abs() < _kMinFlingVelocityDelta || vx.abs() < _kMinFlingVelocity) { + return _FlingGestureKind.none; + } + assert(vx != 0.0); + flingDirection = _extentToDirection(vx); + } else { + if (vy.abs() - vx.abs() < _kMinFlingVelocityDelta || vy.abs() < _kMinFlingVelocity) { + return _FlingGestureKind.none; + } + assert(vy != 0.0); + flingDirection = _extentToDirection(vy); + } + if (flingDirection == _dismissDirection) { + return _FlingGestureKind.forward; + } + return _FlingGestureKind.reverse; + } + + void _handleDragEnd(DragEndDetails details) { + if (!_isActive || _moveController!.isAnimating) { + return; + } + _dragUnderway = false; + if (_moveController!.isCompleted) { + _handleMoveCompleted(); + return; + } + final double flingVelocity = _directionIsXAxis ? details.velocity.pixelsPerSecond.dx : details.velocity.pixelsPerSecond.dy; + switch (_describeFlingGesture(details.velocity)) { + case _FlingGestureKind.forward: + assert(_dragExtent != 0.0); + assert(!_moveController!.isDismissed); + if ((widget.dismissThresholds[_dismissDirection] ?? _kDismissThreshold) >= 1.0) { + _moveController!.reverse(); + break; + } + _dragExtent = flingVelocity.sign; + _moveController!.fling(velocity: flingVelocity.abs() * _kFlingVelocityScale); + case _FlingGestureKind.reverse: + assert(_dragExtent != 0.0); + assert(!_moveController!.isDismissed); + _dragExtent = flingVelocity.sign; + _moveController!.fling(velocity: -flingVelocity.abs() * _kFlingVelocityScale); + case _FlingGestureKind.none: + if (!_moveController!.isDismissed) { // we already know it's not completed, we check that above + if (_moveController!.value > (widget.dismissThresholds[_dismissDirection] ?? _kDismissThreshold)) { + _moveController!.forward(); + } else { + _moveController!.reverse(); + } + } + } + } + + Future<void> _handleDismissStatusChanged(AnimationStatus status) async { + if (status == AnimationStatus.completed && !_dragUnderway) { + await _handleMoveCompleted(); + } + if (mounted) { + updateKeepAlive(); + } + } + + Future<void> _handleMoveCompleted() async { + if ((widget.dismissThresholds[_dismissDirection] ?? _kDismissThreshold) >= 1.0) { + _moveController!.reverse(); + return; + } + final bool result = await _confirmStartResizeAnimation(); + if (mounted) { + if (result) { + _startResizeAnimation(); + } else { + _moveController!.reverse(); + } + } + } + + Future<bool> _confirmStartResizeAnimation() async { + if (widget.confirmDismiss != null) { + _confirming = true; + final DismissDirection direction = _dismissDirection; + try { + return await widget.confirmDismiss!(direction) ?? false; + } finally { + _confirming = false; + } + } + return true; + } + + void _startResizeAnimation() { + assert(_moveController!.isCompleted); + assert(_resizeController == null); + assert(_sizePriorToCollapse == null); + if (widget.resizeDuration == null) { + if (widget.onDismissed != null) { + final DismissDirection direction = _dismissDirection; + widget.onDismissed!(direction); + } + } else { + _resizeController = AnimationController(duration: widget.resizeDuration, vsync: this) + ..addListener(_handleResizeProgressChanged) + ..addStatusListener((AnimationStatus status) => updateKeepAlive()); + _resizeController!.forward(); + setState(() { + _sizePriorToCollapse = context.size; + _resizeAnimation = _resizeController!.drive( + CurveTween( + curve: _kResizeTimeCurve, + ), + ).drive( + Tween<double>( + begin: 1.0, + end: 0.0, + ), + ); + }); + } + } + + void _handleResizeProgressChanged() { + if (_resizeController!.isCompleted) { + widget.onDismissed?.call(_dismissDirection); + } else { + widget.onResize?.call(); + } + } + + @override + Widget build(BuildContext context) { + super.build(context); // See AutomaticKeepAliveClientMixin. + + assert(!_directionIsXAxis || debugCheckHasDirectionality(context)); + + Widget? background = widget.background; + if (widget.secondaryBackground != null) { + final DismissDirection direction = _dismissDirection; + if (direction == DismissDirection.endToStart || direction == DismissDirection.up) { + background = widget.secondaryBackground; + } + } + + if (_resizeAnimation != null) { + // we've been dragged aside, and are now resizing. + assert(() { + if (_resizeAnimation!.status != AnimationStatus.forward) { + assert(_resizeAnimation!.status == AnimationStatus.completed); + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('A dismissed Dismissible widget is still part of the tree.'), + ErrorHint( + 'Make sure to implement the onDismissed handler and to immediately remove the Dismissible ' + 'widget from the application once that handler has fired.', + ), + ]); + } + return true; + }()); + + return SizeTransition( + sizeFactor: _resizeAnimation!, + axis: _directionIsXAxis ? Axis.vertical : Axis.horizontal, + child: SizedBox( + width: _sizePriorToCollapse!.width, + height: _sizePriorToCollapse!.height, + child: background, + ), + ); + } + + Widget content = SlideTransition( + position: _moveAnimation, + child: KeyedSubtree(key: _contentKey, child: widget.child), + ); + + if (background != null) { + content = Stack(children: <Widget>[ + if (!_moveAnimation.isDismissed) + Positioned.fill( + child: ClipRect( + clipper: _DismissibleClipper( + axis: _directionIsXAxis ? Axis.horizontal : Axis.vertical, + moveAnimation: _moveAnimation, + ), + child: background, + ), + ), + content, + ]); + } + + // If the DismissDirection is none, we do not add drag gestures because the content + // cannot be dragged. + if (widget.direction == DismissDirection.none) { + return content; + } + + // We are not resizing but we may be being dragging in widget.direction. + return GestureDetector( + onHorizontalDragStart: _directionIsXAxis ? _handleDragStart : null, + onHorizontalDragUpdate: _directionIsXAxis ? _handleDragUpdate : null, + onHorizontalDragEnd: _directionIsXAxis ? _handleDragEnd : null, + onVerticalDragStart: _directionIsXAxis ? null : _handleDragStart, + onVerticalDragUpdate: _directionIsXAxis ? null : _handleDragUpdate, + onVerticalDragEnd: _directionIsXAxis ? null : _handleDragEnd, + behavior: widget.behavior, + dragStartBehavior: widget.dragStartBehavior, + child: content, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/display_feature_sub_screen.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/display_feature_sub_screen.dart new file mode 100644 index 0000000000000000000000000000000000000000..c502a269f0c15b4c7bdcebbd138faf03b4c6e986 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/display_feature_sub_screen.dart @@ -0,0 +1,259 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' show DisplayFeature, DisplayFeatureState; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'media_query.dart'; + +/// Positions [child] such that it avoids overlapping any [DisplayFeature] that +/// splits the screen into sub-screens. +/// +/// A [DisplayFeature] splits the screen into sub-screens when both these +/// conditions are met: +/// +/// * it obstructs the screen, meaning the area it occupies is not 0 or the +/// `state` is [DisplayFeatureState.postureHalfOpened]. +/// * it is at least as tall as the screen, producing a left and right +/// sub-screen or it is at least as wide as the screen, producing a top and +/// bottom sub-screen +/// +/// After determining the sub-screens, the closest one to [anchorPoint] is used +/// to render the content. +/// +/// If no [anchorPoint] is provided, then [Directionality] is used: +/// +/// * for [TextDirection.ltr], [anchorPoint] is `Offset.zero`, which will +/// cause the content to appear in the top-left sub-screen. +/// * for [TextDirection.rtl], [anchorPoint] is `Offset(double.maxFinite, 0)`, +/// which will cause the content to appear in the top-right sub-screen. +/// +/// If no [anchorPoint] is provided, and there is no [Directionality] ancestor +/// widget in the tree, then the widget asserts during build in debug mode. +/// +/// Similarly to [SafeArea], this widget assumes there is no added padding +/// between it and the first [MediaQuery] ancestor. The [child] is wrapped in a +/// new [MediaQuery] instance containing the [DisplayFeature]s that exist in the +/// selected sub-screen, with coordinates relative to the sub-screen. Padding is +/// also adjusted to zero out any sides that were avoided by this widget. +/// +/// See also: +/// +/// * [showDialog], which is a way to display a [DialogRoute]. +/// * [showCupertinoDialog], which displays an iOS-style dialog. +class DisplayFeatureSubScreen extends StatelessWidget { + /// Creates a widget that positions its child so that it avoids display + /// features. + const DisplayFeatureSubScreen({ + super.key, + this.anchorPoint, + required this.child, + }); + + /// {@template flutter.widgets.DisplayFeatureSubScreen.anchorPoint} + /// The anchor point used to pick the closest sub-screen. + /// + /// If the anchor point sits inside one of these sub-screens, then that + /// sub-screen is picked. If not, then the sub-screen with the closest edge to + /// the point is used. + /// + /// [Offset.zero] is the top-left corner of the available screen space. For a + /// vertically split dual-screen device, this is the top-left corner of the + /// left screen. + /// + /// When this is null, [Directionality] is used: + /// + /// * for [TextDirection.ltr], [anchorPoint] is [Offset.zero], which will + /// cause the top-left sub-screen to be picked. + /// * for [TextDirection.rtl], [anchorPoint] is + /// `Offset(double.maxFinite, 0)`, which will cause the top-right + /// sub-screen to be picked. + /// {@endtemplate} + final Offset? anchorPoint; + + /// The widget below this widget in the tree. + /// + /// The padding on the [MediaQuery] for the [child] will be suitably adjusted + /// to zero out any sides that were avoided by this widget. The [MediaQuery] + /// for the [child] will no longer contain any display features that split the + /// screen into sub-screens. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + assert(anchorPoint != null || debugCheckHasDirectionality( + context, + why: 'to determine which sub-screen DisplayFeatureSubScreen uses', + alternative: "Alternatively, consider specifying the 'anchorPoint' argument on the DisplayFeatureSubScreen.", + )); + final MediaQueryData mediaQuery = MediaQuery.of(context); + final Size parentSize = mediaQuery.size; + final Rect wantedBounds = Offset.zero & parentSize; + final Offset resolvedAnchorPoint = _capOffset(anchorPoint ?? _fallbackAnchorPoint(context), parentSize); + final Iterable<Rect> subScreens = subScreensInBounds(wantedBounds, avoidBounds(mediaQuery)); + final Rect closestSubScreen = _closestToAnchorPoint(subScreens, resolvedAnchorPoint); + + return Padding( + padding: EdgeInsets.only( + left: closestSubScreen.left, + top: closestSubScreen.top, + right: parentSize.width - closestSubScreen.right, + bottom: parentSize.height - closestSubScreen.bottom, + ), + child: MediaQuery( + data: mediaQuery.removeDisplayFeatures(closestSubScreen), + child: child, + ), + ); + } + + static Offset _fallbackAnchorPoint(BuildContext context) { + final TextDirection textDirection = Directionality.of(context); + switch (textDirection) { + case TextDirection.rtl: + return const Offset(double.maxFinite, 0); + case TextDirection.ltr: + return Offset.zero; + } + } + + /// Returns the areas of the screen that are obstructed by display features. + /// + /// A [DisplayFeature] obstructs the screen when the area it occupies is + /// not 0 or the `state` is [DisplayFeatureState.postureHalfOpened]. + static Iterable<Rect> avoidBounds(MediaQueryData mediaQuery) { + return mediaQuery.displayFeatures + .where((DisplayFeature d) => d.bounds.shortestSide > 0 || + d.state == DisplayFeatureState.postureHalfOpened) + .map((DisplayFeature d) => d.bounds); + } + + /// Returns the closest sub-screen to the [anchorPoint]. + static Rect _closestToAnchorPoint(Iterable<Rect> subScreens, Offset anchorPoint) { + Rect closestScreen = subScreens.first; + double closestDistance = _distanceFromPointToRect(anchorPoint, closestScreen); + for (final Rect screen in subScreens) { + final double subScreenDistance = _distanceFromPointToRect(anchorPoint, screen); + if (subScreenDistance < closestDistance) { + closestScreen = screen; + closestDistance = subScreenDistance; + } + } + return closestScreen; + } + + static double _distanceFromPointToRect(Offset point, Rect rect) { + // Cases for point position relative to rect: + // 1 2 3 + // 4 [R] 5 + // 6 7 8 + if (point.dx < rect.left) { + if (point.dy < rect.top) { + // Case 1 + return (point - rect.topLeft).distance; + } else if (point.dy > rect.bottom) { + // Case 6 + return (point - rect.bottomLeft).distance; + } else { + // Case 4 + return rect.left - point.dx; + } + } else if (point.dx > rect.right) { + if (point.dy < rect.top) { + // Case 3 + return (point - rect.topRight).distance; + } else if (point.dy > rect.bottom) { + // Case 8 + return (point - rect.bottomRight).distance; + } else { + // Case 5 + return point.dx - rect.right; + } + } else { + if (point.dy < rect.top) { + // Case 2 + return rect.top - point.dy; + } else if (point.dy > rect.bottom) { + // Case 7 + return point.dy - rect.bottom; + } else { + // Case R + return 0; + } + } + } + + /// Returns sub-screens resulted by dividing [wantedBounds] along items of + /// [avoidBounds] that are at least as tall or as wide. + static Iterable<Rect> subScreensInBounds(Rect wantedBounds, Iterable<Rect> avoidBounds) { + Iterable<Rect> subScreens = <Rect>[wantedBounds]; + for (final Rect bounds in avoidBounds) { + final List<Rect> newSubScreens = <Rect>[]; + for (final Rect screen in subScreens) { + if (screen.top >= bounds.top && screen.bottom <= bounds.bottom) { + // Display feature splits the screen vertically + if (screen.left < bounds.left) { + // There is a smaller sub-screen, left of the display feature + newSubScreens.add(Rect.fromLTWH( + screen.left, + screen.top, + bounds.left - screen.left, + screen.height, + )); + } + if (screen.right > bounds.right) { + // There is a smaller sub-screen, right of the display feature + newSubScreens.add(Rect.fromLTWH( + bounds.right, + screen.top, + screen.right - bounds.right, + screen.height, + )); + } + } else if (screen.left >= bounds.left && screen.right <= bounds.right) { + // Display feature splits the sub-screen horizontally + if (screen.top < bounds.top) { + // There is a smaller sub-screen, above the display feature + newSubScreens.add(Rect.fromLTWH( + screen.left, + screen.top, + screen.width, + bounds.top - screen.top, + )); + } + if (screen.bottom > bounds.bottom) { + // There is a smaller sub-screen, below the display feature + newSubScreens.add(Rect.fromLTWH( + screen.left, + bounds.bottom, + screen.width, + screen.bottom - bounds.bottom, + )); + } + } else { + newSubScreens.add(screen); + } + } + subScreens = newSubScreens; + } + return subScreens; + } + + static Offset _capOffset(Offset offset, Size maximum) { + if (offset.dx >= 0 && offset.dx <= maximum.width + && offset.dy >=0 && offset.dy <= maximum.height) { + return offset; + } else { + return Offset( + math.min(math.max(0, offset.dx), maximum.width), + math.min(math.max(0, offset.dy), maximum.height), + ); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/disposable_build_context.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/disposable_build_context.dart new file mode 100644 index 0000000000000000000000000000000000000000..64ff92dc98d0750793fdbd42d12d59fa5cfccbcc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/disposable_build_context.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'framework.dart'; + +/// Provides non-leaking access to a [BuildContext]. +/// +/// A [BuildContext] is only valid if it is pointing to an active [Element]. +/// Once the [Element] is unmounted, the [BuildContext] should not be accessed +/// further. This class makes it possible for a [StatefulWidget] to share its +/// build context safely with other objects. +/// +/// Creators of this object must guarantee the following: +/// +/// 1. They create this object at or after [State.initState] but before +/// [State.dispose]. In particular, do not attempt to create this from the +/// constructor of a state. +/// 2. They call [dispose] from [State.dispose]. +/// +/// This object will not hold on to the [State] after disposal. +@optionalTypeArgs +class DisposableBuildContext<T extends State> { + /// Creates an object that provides access to a [BuildContext] without leaking + /// a [State]. + /// + /// Creators must call [dispose] when the [State] is disposed. + /// + /// [State.mounted] must be true. + DisposableBuildContext(T this._state) + : assert(_state.mounted, 'A DisposableBuildContext was given a BuildContext for an Element that is not mounted.') { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/widgets.dart', + className: '$DisposableBuildContext', + object: this, + ); + } + } + + T? _state; + + /// Provides safe access to the build context. + /// + /// If [dispose] has been called, will return null. + /// + /// Otherwise, asserts the [_state] is still mounted and returns its context. + BuildContext? get context { + assert(_debugValidate()); + if (_state == null) { + return null; + } + return _state!.context; + } + + /// Called from asserts or tests to determine whether this object is in a + /// valid state. + /// + /// Always returns true, but will assert if [dispose] has not been called + /// but the state this is tracking is unmounted. + bool _debugValidate() { + assert( + _state == null || _state!.mounted, + 'A DisposableBuildContext tried to access the BuildContext of a disposed ' + 'State object. This can happen when the creator of this ' + 'DisposableBuildContext fails to call dispose when it is disposed.', + ); + return true; + } + + + /// Marks the [BuildContext] as disposed. + /// + /// Creators of this object must call [dispose] when their [Element] is + /// unmounted, i.e. when [State.dispose] is called. + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _state = null; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/drag_target.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/drag_target.dart new file mode 100644 index 0000000000000000000000000000000000000000..c68b8665c973f0bfd7a80034632a2a40bf97a00b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/drag_target.dart @@ -0,0 +1,982 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show kIsWeb; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; + +import 'basic.dart'; +import 'binding.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'media_query.dart'; +import 'overlay.dart'; +import 'view.dart'; + +/// Signature for determining whether the given data will be accepted by a [DragTarget]. +/// +/// Used by [DragTarget.onWillAccept]. +typedef DragTargetWillAccept<T> = bool Function(T? data); + +/// Signature for determining whether the given data will be accepted by a [DragTarget], +/// based on provided information. +/// +/// Used by [DragTarget.onWillAcceptWithDetails]. +typedef DragTargetWillAcceptWithDetails<T> = bool Function(DragTargetDetails<T> details); + +/// Signature for causing a [DragTarget] to accept the given data. +/// +/// Used by [DragTarget.onAccept]. +typedef DragTargetAccept<T> = void Function(T data); + +/// Signature for determining information about the acceptance by a [DragTarget]. +/// +/// Used by [DragTarget.onAcceptWithDetails]. +typedef DragTargetAcceptWithDetails<T> = void Function(DragTargetDetails<T> details); + +/// Signature for building children of a [DragTarget]. +/// +/// The `candidateData` argument contains the list of drag data that is hovering +/// over this [DragTarget] and that has passed [DragTarget.onWillAccept]. The +/// `rejectedData` argument contains the list of drag data that is hovering over +/// this [DragTarget] and that will not be accepted by the [DragTarget]. +/// +/// Used by [DragTarget.builder]. +typedef DragTargetBuilder<T> = Widget Function(BuildContext context, List<T?> candidateData, List<dynamic> rejectedData); + +/// Signature for when a [Draggable] is dragged across the screen. +/// +/// Used by [Draggable.onDragUpdate]. +typedef DragUpdateCallback = void Function(DragUpdateDetails details); + +/// Signature for when a [Draggable] is dropped without being accepted by a [DragTarget]. +/// +/// Used by [Draggable.onDraggableCanceled]. +typedef DraggableCanceledCallback = void Function(Velocity velocity, Offset offset); + +/// Signature for when the draggable is dropped. +/// +/// The velocity and offset at which the pointer was moving when the draggable +/// was dropped is available in the [DraggableDetails]. Also included in the +/// `details` is whether the draggable's [DragTarget] accepted it. +/// +/// Used by [Draggable.onDragEnd]. +typedef DragEndCallback = void Function(DraggableDetails details); + +/// Signature for when a [Draggable] leaves a [DragTarget]. +/// +/// Used by [DragTarget.onLeave]. +typedef DragTargetLeave<T> = void Function(T? data); + +/// Signature for when a [Draggable] moves within a [DragTarget]. +/// +/// Used by [DragTarget.onMove]. +typedef DragTargetMove<T> = void Function(DragTargetDetails<T> details); + +/// Signature for the strategy that determines the drag start point of a [Draggable]. +/// +/// Used by [Draggable.dragAnchorStrategy]. +/// +/// There are two built-in strategies: +/// +/// * [childDragAnchorStrategy], which displays the feedback anchored at the +/// position of the original child. +/// +/// * [pointerDragAnchorStrategy], which displays the feedback anchored at the +/// position of the touch that started the drag. +typedef DragAnchorStrategy = Offset Function(Draggable<Object> draggable, BuildContext context, Offset position); + +/// Display the feedback anchored at the position of the original child. +/// +/// If feedback is identical to the child, then this means the feedback will +/// exactly overlap the original child when the drag starts. +/// +/// This is the default [DragAnchorStrategy]. +/// +/// See also: +/// +/// * [DragAnchorStrategy], the typedef that this function implements. +/// * [Draggable.dragAnchorStrategy], for which this is a built-in value. +Offset childDragAnchorStrategy(Draggable<Object> draggable, BuildContext context, Offset position) { + final RenderBox renderObject = context.findRenderObject()! as RenderBox; + return renderObject.globalToLocal(position); +} + +/// Display the feedback anchored at the position of the touch that started +/// the drag. +/// +/// If feedback is identical to the child, then this means the top left of the +/// feedback will be under the finger when the drag starts. This will likely not +/// exactly overlap the original child, e.g. if the child is big and the touch +/// was not centered. This mode is useful when the feedback is transformed so as +/// to move the feedback to the left by half its width, and up by half its width +/// plus the height of the finger, since then it appears as if putting the +/// finger down makes the touch feedback appear above the finger. (It feels +/// weird for it to appear offset from the original child if it's anchored to +/// the child and not the finger.) +/// +/// See also: +/// +/// * [DragAnchorStrategy], the typedef that this function implements. +/// * [Draggable.dragAnchorStrategy], for which this is a built-in value. +Offset pointerDragAnchorStrategy(Draggable<Object> draggable, BuildContext context, Offset position) { + return Offset.zero; +} + +/// A widget that can be dragged from to a [DragTarget]. +/// +/// When a draggable widget recognizes the start of a drag gesture, it displays +/// a [feedback] widget that tracks the user's finger across the screen. If the +/// user lifts their finger while on top of a [DragTarget], that target is given +/// the opportunity to accept the [data] carried by the draggable. +/// +/// The [ignoringFeedbackPointer] defaults to true, which means that +/// the [feedback] widget ignores the pointer during hit testing. Similarly, +/// [ignoringFeedbackSemantics] defaults to true, and the [feedback] also ignores +/// semantics when building the semantics tree. +/// +/// On multitouch devices, multiple drags can occur simultaneously because there +/// can be multiple pointers in contact with the device at once. To limit the +/// number of simultaneous drags, use the [maxSimultaneousDrags] property. The +/// default is to allow an unlimited number of simultaneous drags. +/// +/// This widget displays [child] when zero drags are under way. If +/// [childWhenDragging] is non-null, this widget instead displays +/// [childWhenDragging] when one or more drags are underway. Otherwise, this +/// widget always displays [child]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=q4x2G_9-Mu0} +/// +/// {@tool dartpad} +/// The following example has a [Draggable] widget along with a [DragTarget] +/// in a row demonstrating an incremented `acceptedData` integer value when +/// you drag the element to the target. +/// +/// ** See code in examples/api/lib/widgets/drag_target/draggable.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [DragTarget] +/// * [LongPressDraggable] +class Draggable<T extends Object> extends StatefulWidget { + /// Creates a widget that can be dragged to a [DragTarget]. + /// + /// If [maxSimultaneousDrags] is non-null, it must be non-negative. + const Draggable({ + super.key, + required this.child, + required this.feedback, + this.data, + this.axis, + this.childWhenDragging, + this.feedbackOffset = Offset.zero, + this.dragAnchorStrategy = childDragAnchorStrategy, + this.affinity, + this.maxSimultaneousDrags, + this.onDragStarted, + this.onDragUpdate, + this.onDraggableCanceled, + this.onDragEnd, + this.onDragCompleted, + this.ignoringFeedbackSemantics = true, + this.ignoringFeedbackPointer = true, + this.rootOverlay = false, + this.hitTestBehavior = HitTestBehavior.deferToChild, + this.allowedButtonsFilter, + }) : assert(maxSimultaneousDrags == null || maxSimultaneousDrags >= 0); + + /// The data that will be dropped by this draggable. + final T? data; + + /// The [Axis] to restrict this draggable's movement, if specified. + /// + /// When axis is set to [Axis.horizontal], this widget can only be dragged + /// horizontally. Behavior is similar for [Axis.vertical]. + /// + /// Defaults to allowing drag on both [Axis.horizontal] and [Axis.vertical]. + /// + /// When null, allows drag on both [Axis.horizontal] and [Axis.vertical]. + /// + /// For the direction of gestures this widget competes with to start a drag + /// event, see [Draggable.affinity]. + final Axis? axis; + + /// The widget below this widget in the tree. + /// + /// This widget displays [child] when zero drags are under way. If + /// [childWhenDragging] is non-null, this widget instead displays + /// [childWhenDragging] when one or more drags are underway. Otherwise, this + /// widget always displays [child]. + /// + /// The [feedback] widget is shown under the pointer when a drag is under way. + /// + /// To limit the number of simultaneous drags on multitouch devices, see + /// [maxSimultaneousDrags]. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The widget to display instead of [child] when one or more drags are under way. + /// + /// If this is null, then this widget will always display [child] (and so the + /// drag source representation will not change while a drag is under + /// way). + /// + /// The [feedback] widget is shown under the pointer when a drag is under way. + /// + /// To limit the number of simultaneous drags on multitouch devices, see + /// [maxSimultaneousDrags]. + final Widget? childWhenDragging; + + /// The widget to show under the pointer when a drag is under way. + /// + /// See [child] and [childWhenDragging] for information about what is shown + /// at the location of the [Draggable] itself when a drag is under way. + final Widget feedback; + + /// The feedbackOffset can be used to set the hit test target point for the + /// purposes of finding a drag target. It is especially useful if the feedback + /// is transformed compared to the child. + final Offset feedbackOffset; + + /// A strategy that is used by this draggable to get the anchor offset when it + /// is dragged. + /// + /// The anchor offset refers to the distance between the users' fingers and + /// the [feedback] widget when this draggable is dragged. + /// + /// This property's value is a function that implements [DragAnchorStrategy]. + /// There are two built-in functions that can be used: + /// + /// * [childDragAnchorStrategy], which displays the feedback anchored at the + /// position of the original child. + /// + /// * [pointerDragAnchorStrategy], which displays the feedback anchored at the + /// position of the touch that started the drag. + /// + /// Defaults to [childDragAnchorStrategy]. + final DragAnchorStrategy dragAnchorStrategy; + + /// Whether the semantics of the [feedback] widget is ignored when building + /// the semantics tree. + /// + /// This value should be set to false when the [feedback] widget is intended + /// to be the same object as the [child]. Placing a [GlobalKey] on this + /// widget will ensure semantic focus is kept on the element as it moves in + /// and out of the feedback position. + /// + /// Defaults to true. + final bool ignoringFeedbackSemantics; + + /// Whether the [feedback] widget is ignored during hit testing. + /// + /// Regardless of whether this widget is ignored during hit testing, it will + /// still consume space during layout and be visible during painting. + /// + /// Defaults to true. + final bool ignoringFeedbackPointer; + + /// Controls how this widget competes with other gestures to initiate a drag. + /// + /// If affinity is null, this widget initiates a drag as soon as it recognizes + /// a tap down gesture, regardless of any directionality. If affinity is + /// horizontal (or vertical), then this widget will compete with other + /// horizontal (or vertical, respectively) gestures. + /// + /// For example, if this widget is placed in a vertically scrolling region and + /// has horizontal affinity, pointer motion in the vertical direction will + /// result in a scroll and pointer motion in the horizontal direction will + /// result in a drag. Conversely, if the widget has a null or vertical + /// affinity, pointer motion in any direction will result in a drag rather + /// than in a scroll because the draggable widget, being the more specific + /// widget, will out-compete the [Scrollable] for vertical gestures. + /// + /// For the directions this widget can be dragged in after the drag event + /// starts, see [Draggable.axis]. + final Axis? affinity; + + /// How many simultaneous drags to support. + /// + /// When null, no limit is applied. Set this to 1 if you want to only allow + /// the drag source to have one item dragged at a time. Set this to 0 if you + /// want to prevent the draggable from actually being dragged. + /// + /// If you set this property to 1, consider supplying an "empty" widget for + /// [childWhenDragging] to create the illusion of actually moving [child]. + final int? maxSimultaneousDrags; + + /// Called when the draggable starts being dragged. + final VoidCallback? onDragStarted; + + /// Called when the draggable is dragged. + /// + /// This function will only be called while this widget is still mounted to + /// the tree (i.e. [State.mounted] is true), and if this widget has actually moved. + final DragUpdateCallback? onDragUpdate; + + /// Called when the draggable is dropped without being accepted by a [DragTarget]. + /// + /// This function might be called after this widget has been removed from the + /// tree. For example, if a drag was in progress when this widget was removed + /// from the tree and the drag ended up being canceled, this callback will + /// still be called. For this reason, implementations of this callback might + /// need to check [State.mounted] to check whether the state receiving the + /// callback is still in the tree. + final DraggableCanceledCallback? onDraggableCanceled; + + /// Called when the draggable is dropped and accepted by a [DragTarget]. + /// + /// This function might be called after this widget has been removed from the + /// tree. For example, if a drag was in progress when this widget was removed + /// from the tree and the drag ended up completing, this callback will + /// still be called. For this reason, implementations of this callback might + /// need to check [State.mounted] to check whether the state receiving the + /// callback is still in the tree. + final VoidCallback? onDragCompleted; + + /// Called when the draggable is dropped. + /// + /// The velocity and offset at which the pointer was moving when it was + /// dropped is available in the [DraggableDetails]. Also included in the + /// `details` is whether the draggable's [DragTarget] accepted it. + /// + /// This function will only be called while this widget is still mounted to + /// the tree (i.e. [State.mounted] is true). + final DragEndCallback? onDragEnd; + + /// Whether the feedback widget will be put on the root [Overlay]. + /// + /// When false, the feedback widget will be put on the closest [Overlay]. When + /// true, the [feedback] widget will be put on the farthest (aka root) + /// [Overlay]. + /// + /// Defaults to false. + final bool rootOverlay; + + /// How to behave during hit test. + /// + /// Defaults to [HitTestBehavior.deferToChild]. + final HitTestBehavior hitTestBehavior; + + /// {@macro flutter.gestures.multidrag._allowedButtonsFilter} + final AllowedButtonsFilter? allowedButtonsFilter; + + /// Creates a gesture recognizer that recognizes the start of the drag. + /// + /// Subclasses can override this function to customize when they start + /// recognizing a drag. + @protected + MultiDragGestureRecognizer createRecognizer(GestureMultiDragStartCallback onStart) { + switch (affinity) { + case Axis.horizontal: + return HorizontalMultiDragGestureRecognizer(allowedButtonsFilter: allowedButtonsFilter)..onStart = onStart; + case Axis.vertical: + return VerticalMultiDragGestureRecognizer(allowedButtonsFilter: allowedButtonsFilter)..onStart = onStart; + case null: + return ImmediateMultiDragGestureRecognizer(allowedButtonsFilter: allowedButtonsFilter)..onStart = onStart; + } + } + + @override + State<Draggable<T>> createState() => _DraggableState<T>(); +} + +/// Makes its child draggable starting from long press. +/// +/// See also: +/// +/// * [Draggable], similar to the [LongPressDraggable] widget but happens immediately. +/// * [DragTarget], a widget that receives data when a [Draggable] widget is dropped. +class LongPressDraggable<T extends Object> extends Draggable<T> { + /// Creates a widget that can be dragged starting from long press. + /// + /// If [maxSimultaneousDrags] is non-null, it must be non-negative. + const LongPressDraggable({ + super.key, + required super.child, + required super.feedback, + super.data, + super.axis, + super.childWhenDragging, + super.feedbackOffset, + super.dragAnchorStrategy, + super.maxSimultaneousDrags, + super.onDragStarted, + super.onDragUpdate, + super.onDraggableCanceled, + super.onDragEnd, + super.onDragCompleted, + this.hapticFeedbackOnStart = true, + super.ignoringFeedbackSemantics, + super.ignoringFeedbackPointer, + this.delay = kLongPressTimeout, + super.allowedButtonsFilter, + }); + + /// Whether haptic feedback should be triggered on drag start. + final bool hapticFeedbackOnStart; + + /// The duration that a user has to press down before a long press is registered. + /// + /// Defaults to [kLongPressTimeout]. + final Duration delay; + + @override + DelayedMultiDragGestureRecognizer createRecognizer(GestureMultiDragStartCallback onStart) { + return DelayedMultiDragGestureRecognizer(delay: delay, allowedButtonsFilter: allowedButtonsFilter) + ..onStart = (Offset position) { + final Drag? result = onStart(position); + if (result != null && hapticFeedbackOnStart) { + HapticFeedback.selectionClick(); + } + return result; + }; + } +} + +class _DraggableState<T extends Object> extends State<Draggable<T>> { + @override + void initState() { + super.initState(); + _recognizer = widget.createRecognizer(_startDrag); + } + + @override + void dispose() { + _disposeRecognizerIfInactive(); + super.dispose(); + } + + @override + void didChangeDependencies() { + _recognizer!.gestureSettings = MediaQuery.maybeGestureSettingsOf(context); + super.didChangeDependencies(); + } + + // This gesture recognizer has an unusual lifetime. We want to support the use + // case of removing the Draggable from the tree in the middle of a drag. That + // means we need to keep this recognizer alive after this state object has + // been disposed because it's the one listening to the pointer events that are + // driving the drag. + // + // We achieve that by keeping count of the number of active drags and only + // disposing the gesture recognizer after (a) this state object has been + // disposed and (b) there are no more active drags. + GestureRecognizer? _recognizer; + int _activeCount = 0; + + void _disposeRecognizerIfInactive() { + if (_activeCount > 0) { + return; + } + _recognizer!.dispose(); + _recognizer = null; + } + + void _routePointer(PointerDownEvent event) { + if (widget.maxSimultaneousDrags != null && _activeCount >= widget.maxSimultaneousDrags!) { + return; + } + _recognizer!.addPointer(event); + } + + _DragAvatar<T>? _startDrag(Offset position) { + if (widget.maxSimultaneousDrags != null && _activeCount >= widget.maxSimultaneousDrags!) { + return null; + } + final Offset dragStartPoint; + dragStartPoint = widget.dragAnchorStrategy(widget, context, position); + setState(() { + _activeCount += 1; + }); + final _DragAvatar<T> avatar = _DragAvatar<T>( + overlayState: Overlay.of(context, debugRequiredFor: widget, rootOverlay: widget.rootOverlay), + data: widget.data, + axis: widget.axis, + initialPosition: position, + dragStartPoint: dragStartPoint, + feedback: widget.feedback, + feedbackOffset: widget.feedbackOffset, + ignoringFeedbackSemantics: widget.ignoringFeedbackSemantics, + ignoringFeedbackPointer: widget.ignoringFeedbackPointer, + viewId: View.of(context).viewId, + onDragUpdate: (DragUpdateDetails details) { + if (mounted && widget.onDragUpdate != null) { + widget.onDragUpdate!(details); + } + }, + onDragEnd: (Velocity velocity, Offset offset, bool wasAccepted) { + if (mounted) { + setState(() { + _activeCount -= 1; + }); + } else { + _activeCount -= 1; + _disposeRecognizerIfInactive(); + } + if (mounted && widget.onDragEnd != null) { + widget.onDragEnd!(DraggableDetails( + wasAccepted: wasAccepted, + velocity: velocity, + offset: offset, + )); + } + if (wasAccepted && widget.onDragCompleted != null) { + widget.onDragCompleted!(); + } + if (!wasAccepted && widget.onDraggableCanceled != null) { + widget.onDraggableCanceled!(velocity, offset); + } + }, + ); + widget.onDragStarted?.call(); + return avatar; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasOverlay(context)); + final bool canDrag = widget.maxSimultaneousDrags == null || + _activeCount < widget.maxSimultaneousDrags!; + final bool showChild = _activeCount == 0 || widget.childWhenDragging == null; + return Listener( + behavior: widget.hitTestBehavior, + onPointerDown: canDrag ? _routePointer : null, + child: showChild ? widget.child : widget.childWhenDragging, + ); + } +} + +/// Represents the details when a specific pointer event occurred on +/// the [Draggable]. +/// +/// This includes the [Velocity] at which the pointer was moving and [Offset] +/// when the draggable event occurred, and whether its [DragTarget] accepted it. +/// +/// Also, this is the details object for callbacks that use [DragEndCallback]. +class DraggableDetails { + /// Creates details for a [DraggableDetails]. + /// + /// If [wasAccepted] is not specified, it will default to `false`. + /// + /// The [velocity] or [offset] arguments must not be `null`. + DraggableDetails({ + this.wasAccepted = false, + required this.velocity, + required this.offset, + }); + + /// Determines whether the [DragTarget] accepted this draggable. + final bool wasAccepted; + + /// The velocity at which the pointer was moving when the specific pointer + /// event occurred on the draggable. + final Velocity velocity; + + /// The global position when the specific pointer event occurred on + /// the draggable. + final Offset offset; +} + +/// Represents the details when a pointer event occurred on the [DragTarget]. +class DragTargetDetails<T> { + /// Creates details for a [DragTarget] callback. + DragTargetDetails({required this.data, required this.offset}); + + /// The data that was dropped onto this [DragTarget]. + final T data; + + /// The global position when the specific pointer event occurred on + /// the draggable. + final Offset offset; +} + +/// A widget that receives data when a [Draggable] widget is dropped. +/// +/// When a draggable is dragged on top of a drag target, the drag target is +/// asked whether it will accept the data the draggable is carrying. If the user +/// does drop the draggable on top of the drag target (and the drag target has +/// indicated that it will accept the draggable's data), then the drag target is +/// asked to accept the draggable's data. +/// +/// See also: +/// +/// * [Draggable] +/// * [LongPressDraggable] +class DragTarget<T extends Object> extends StatefulWidget { + /// Creates a widget that receives drags. + const DragTarget({ + super.key, + required this.builder, + @Deprecated( + 'Use onWillAcceptWithDetails instead. ' + 'This callback is similar to onWillAcceptWithDetails but does not provide drag details. ' + 'This feature was deprecated after v3.14.0-0.2.pre.' + ) + this.onWillAccept, + this.onWillAcceptWithDetails, + @Deprecated( + 'Use onAcceptWithDetails instead. ' + 'This callback is similar to onAcceptWithDetails but does not provide drag details. ' + 'This feature was deprecated after v3.14.0-0.2.pre.' + ) + this.onAccept, + this.onAcceptWithDetails, + this.onLeave, + this.onMove, + this.hitTestBehavior = HitTestBehavior.translucent, + }) : assert(onWillAccept == null || onWillAcceptWithDetails == null, "Don't pass both onWillAccept and onWillAcceptWithDetails."); + + /// Called to build the contents of this widget. + /// + /// The builder can build different widgets depending on what is being dragged + /// into this drag target. + final DragTargetBuilder<T> builder; + + /// Called to determine whether this widget is interested in receiving a given + /// piece of data being dragged over this drag target. + /// + /// Called when a piece of data enters the target. This will be followed by + /// either [onAccept] and [onAcceptWithDetails], if the data is dropped, or + /// [onLeave], if the drag leaves the target. + /// + /// Equivalent to [onWillAcceptWithDetails], but only includes the data. + /// + /// Must not be provided if [onWillAcceptWithDetails] is provided. + @Deprecated( + 'Use onWillAcceptWithDetails instead. ' + 'This callback is similar to onWillAcceptWithDetails but does not provide drag details. ' + 'This feature was deprecated after v3.14.0-0.2.pre.' + ) + final DragTargetWillAccept<T>? onWillAccept; + + /// Called to determine whether this widget is interested in receiving a given + /// piece of data being dragged over this drag target. + /// + /// Called when a piece of data enters the target. This will be followed by + /// either [onAccept] and [onAcceptWithDetails], if the data is dropped, or + /// [onLeave], if the drag leaves the target. + /// + /// Equivalent to [onWillAccept], but with information, including the data, + /// in a [DragTargetDetails]. + /// + /// Must not be provided if [onWillAccept] is provided. + final DragTargetWillAcceptWithDetails<T>? onWillAcceptWithDetails; + + /// Called when an acceptable piece of data was dropped over this drag target. + /// It will not be called if `data` is `null`. + /// + /// Equivalent to [onAcceptWithDetails], but only includes the data. + @Deprecated( + 'Use onAcceptWithDetails instead. ' + 'This callback is similar to onAcceptWithDetails but does not provide drag details. ' + 'This feature was deprecated after v3.14.0-0.2.pre.' + ) + final DragTargetAccept<T>? onAccept; + + /// Called when an acceptable piece of data was dropped over this drag target. + /// It will not be called if `data` is `null`. + /// + /// Equivalent to [onAccept], but with information, including the data, in a + /// [DragTargetDetails]. + final DragTargetAcceptWithDetails<T>? onAcceptWithDetails; + + /// Called when a given piece of data being dragged over this target leaves + /// the target. + final DragTargetLeave<T>? onLeave; + + /// Called when a [Draggable] moves within this [DragTarget]. It will not be + /// called if `data` is `null`. + /// + /// This includes entering and leaving the target. + final DragTargetMove<T>? onMove; + + /// How to behave during hit testing. + /// + /// Defaults to [HitTestBehavior.translucent]. + final HitTestBehavior hitTestBehavior; + + @override + State<DragTarget<T>> createState() => _DragTargetState<T>(); +} + +List<T?> _mapAvatarsToData<T extends Object>(List<_DragAvatar<Object>> avatars) { + return avatars.map<T?>((_DragAvatar<Object> avatar) => avatar.data as T?).toList(); +} + +class _DragTargetState<T extends Object> extends State<DragTarget<T>> { + final List<_DragAvatar<Object>> _candidateAvatars = <_DragAvatar<Object>>[]; + final List<_DragAvatar<Object>> _rejectedAvatars = <_DragAvatar<Object>>[]; + + // On non-web platforms, checks if data Object is equal to type[T] or subtype of [T]. + // On web, it does the same, but requires a check for ints and doubles + // because dart doubles and ints are backed by the same kind of object on web. + // JavaScript does not support integers. + bool isExpectedDataType(Object? data, Type type) { + if (kIsWeb && ((type == int && T == double) || (type == double && T == int))) { + return false; + } + return data is T?; + } + + bool didEnter(_DragAvatar<Object> avatar) { + assert(!_candidateAvatars.contains(avatar)); + assert(!_rejectedAvatars.contains(avatar)); + final bool resolvedWillAccept = (widget.onWillAccept == null && + widget.onWillAcceptWithDetails == null) || + (widget.onWillAccept != null && + widget.onWillAccept!(avatar.data as T?)) || + (widget.onWillAcceptWithDetails != null && + avatar.data != null && + widget.onWillAcceptWithDetails!(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!))); + if (resolvedWillAccept) { + setState(() { + _candidateAvatars.add(avatar); + }); + return true; + } else { + setState(() { + _rejectedAvatars.add(avatar); + }); + return false; + } + } + + void didLeave(_DragAvatar<Object> avatar) { + assert(_candidateAvatars.contains(avatar) || _rejectedAvatars.contains(avatar)); + if (!mounted) { + return; + } + setState(() { + _candidateAvatars.remove(avatar); + _rejectedAvatars.remove(avatar); + }); + widget.onLeave?.call(avatar.data as T?); + } + + void didDrop(_DragAvatar<Object> avatar) { + assert(_candidateAvatars.contains(avatar)); + if (!mounted) { + return; + } + setState(() { + _candidateAvatars.remove(avatar); + }); + if (avatar.data != null) { + widget.onAccept?.call(avatar.data! as T); + widget.onAcceptWithDetails?.call(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!)); + } + } + + void didMove(_DragAvatar<Object> avatar) { + if (!mounted || avatar.data == null) { + return; + } + widget.onMove?.call(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!)); + } + + @override + Widget build(BuildContext context) { + return MetaData( + metaData: this, + behavior: widget.hitTestBehavior, + child: widget.builder(context, _mapAvatarsToData<T>(_candidateAvatars), _mapAvatarsToData<Object>(_rejectedAvatars)), + ); + } +} + +enum _DragEndKind { dropped, canceled } +typedef _OnDragEnd = void Function(Velocity velocity, Offset offset, bool wasAccepted); + +// The lifetime of this object is a little dubious right now. Specifically, it +// lives as long as the pointer is down. Arguably it should self-immolate if the +// overlay goes away. _DraggableState has some delicate logic to continue +// needing this object pointer events even after it has been disposed. +class _DragAvatar<T extends Object> extends Drag { + _DragAvatar({ + required this.overlayState, + this.data, + this.axis, + required Offset initialPosition, + this.dragStartPoint = Offset.zero, + this.feedback, + this.feedbackOffset = Offset.zero, + this.onDragUpdate, + this.onDragEnd, + required this.ignoringFeedbackSemantics, + required this.ignoringFeedbackPointer, + required this.viewId, + }) : _position = initialPosition { + _entry = OverlayEntry(builder: _build); + overlayState.insert(_entry!); + updateDrag(initialPosition); + } + + final T? data; + final Axis? axis; + final Offset dragStartPoint; + final Widget? feedback; + final Offset feedbackOffset; + final DragUpdateCallback? onDragUpdate; + final _OnDragEnd? onDragEnd; + final OverlayState overlayState; + final bool ignoringFeedbackSemantics; + final bool ignoringFeedbackPointer; + final int viewId; + + _DragTargetState<Object>? _activeTarget; + final List<_DragTargetState<Object>> _enteredTargets = <_DragTargetState<Object>>[]; + Offset _position; + Offset? _lastOffset; + OverlayEntry? _entry; + + @override + void update(DragUpdateDetails details) { + final Offset oldPosition = _position; + _position += _restrictAxis(details.delta); + updateDrag(_position); + if (onDragUpdate != null && _position != oldPosition) { + onDragUpdate!(details); + } + } + + @override + void end(DragEndDetails details) { + finishDrag(_DragEndKind.dropped, _restrictVelocityAxis(details.velocity)); + } + + + @override + void cancel() { + finishDrag(_DragEndKind.canceled); + } + + void updateDrag(Offset globalPosition) { + _lastOffset = globalPosition - dragStartPoint; + _entry!.markNeedsBuild(); + final HitTestResult result = HitTestResult(); + WidgetsBinding.instance.hitTestInView(result, globalPosition + feedbackOffset, viewId); + + final List<_DragTargetState<Object>> targets = _getDragTargets(result.path).toList(); + + bool listsMatch = false; + if (targets.length >= _enteredTargets.length && _enteredTargets.isNotEmpty) { + listsMatch = true; + final Iterator<_DragTargetState<Object>> iterator = targets.iterator; + for (int i = 0; i < _enteredTargets.length; i += 1) { + iterator.moveNext(); + if (iterator.current != _enteredTargets[i]) { + listsMatch = false; + break; + } + } + } + + // If everything's the same, report moves, and bail early. + if (listsMatch) { + for (final _DragTargetState<Object> target in _enteredTargets) { + target.didMove(this); + } + return; + } + + // Leave old targets. + _leaveAllEntered(); + + // Enter new targets. + final _DragTargetState<Object>? newTarget = targets.cast<_DragTargetState<Object>?>().firstWhere( + (_DragTargetState<Object>? target) { + if (target == null) { + return false; + } + _enteredTargets.add(target); + return target.didEnter(this); + }, + orElse: () => null, + ); + + // Report moves to the targets. + for (final _DragTargetState<Object> target in _enteredTargets) { + target.didMove(this); + } + + _activeTarget = newTarget; + } + + Iterable<_DragTargetState<Object>> _getDragTargets(Iterable<HitTestEntry> path) { + // Look for the RenderBoxes that corresponds to the hit target (the hit target + // widgets build RenderMetaData boxes for us for this purpose). + final List<_DragTargetState<Object>> targets = <_DragTargetState<Object>>[]; + for (final HitTestEntry entry in path) { + final HitTestTarget target = entry.target; + if (target is RenderMetaData) { + final dynamic metaData = target.metaData; + if (metaData is _DragTargetState && metaData.isExpectedDataType(data, T)) { + targets.add(metaData); + } + } + } + return targets; + } + + void _leaveAllEntered() { + for (int i = 0; i < _enteredTargets.length; i += 1) { + _enteredTargets[i].didLeave(this); + } + _enteredTargets.clear(); + } + + void finishDrag(_DragEndKind endKind, [ Velocity? velocity ]) { + bool wasAccepted = false; + if (endKind == _DragEndKind.dropped && _activeTarget != null) { + _activeTarget!.didDrop(this); + wasAccepted = true; + _enteredTargets.remove(_activeTarget); + } + _leaveAllEntered(); + _activeTarget = null; + _entry!.remove(); + _entry!.dispose(); + _entry = null; + // TODO(ianh): consider passing _entry as well so the client can perform an animation. + onDragEnd?.call(velocity ?? Velocity.zero, _lastOffset!, wasAccepted); + } + + Widget _build(BuildContext context) { + final RenderBox box = overlayState.context.findRenderObject()! as RenderBox; + final Offset overlayTopLeft = box.localToGlobal(Offset.zero); + return Positioned( + left: _lastOffset!.dx - overlayTopLeft.dx, + top: _lastOffset!.dy - overlayTopLeft.dy, + child: ExcludeSemantics( + excluding: ignoringFeedbackSemantics, + child: IgnorePointer( + ignoring: ignoringFeedbackPointer, + child: feedback, + ), + ), + ); + } + + Velocity _restrictVelocityAxis(Velocity velocity) { + if (axis == null) { + return velocity; + } + return Velocity( + pixelsPerSecond: _restrictAxis(velocity.pixelsPerSecond), + ); + } + + Offset _restrictAxis(Offset offset) { + if (axis == null) { + return offset; + } + if (axis == Axis.horizontal) { + return Offset(offset.dx, 0.0); + } + return Offset(0.0, offset.dy); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart new file mode 100644 index 0000000000000000000000000000000000000000..b4543d2346e8ceb2c5da974020d1f28dc94a7552 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart @@ -0,0 +1,1187 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; + +import 'basic.dart'; +import 'binding.dart'; +import 'framework.dart'; +import 'inherited_notifier.dart'; +import 'layout_builder.dart'; +import 'notification_listener.dart'; +import 'scroll_activity.dart'; +import 'scroll_context.dart'; +import 'scroll_controller.dart'; +import 'scroll_notification.dart'; +import 'scroll_physics.dart'; +import 'scroll_position.dart'; +import 'scroll_position_with_single_context.dart'; +import 'scroll_simulation.dart'; +import 'value_listenable_builder.dart'; + +/// The signature of a method that provides a [BuildContext] and +/// [ScrollController] for building a widget that may overflow the draggable +/// [Axis] of the containing [DraggableScrollableSheet]. +/// +/// Users should apply the [scrollController] to a [ScrollView] subclass, such +/// as a [SingleChildScrollView], [ListView] or [GridView], to have the whole +/// sheet be draggable. +typedef ScrollableWidgetBuilder = Widget Function( + BuildContext context, + ScrollController scrollController, +); + +/// Controls a [DraggableScrollableSheet]. +/// +/// Draggable scrollable controllers are typically stored as member variables in +/// [State] objects and are reused in each [State.build]. Controllers can only +/// be used to control one sheet at a time. A controller can be reused with a +/// new sheet if the previous sheet has been disposed. +/// +/// The controller's methods cannot be used until after the controller has been +/// passed into a [DraggableScrollableSheet] and the sheet has run initState. +/// +/// A [DraggableScrollableController] is a [Listenable]. It notifies its +/// listeners whenever an attached sheet changes sizes. It does not notify its +/// listeners when a sheet is first attached or when an attached sheet's +/// parameters change without affecting the sheet's current size. It does not +/// fire when [pixels] changes without [size] changing. For example, if the +/// constraints provided to an attached sheet change. +class DraggableScrollableController extends ChangeNotifier { + /// Creates a controller for [DraggableScrollableSheet]. + DraggableScrollableController() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + _DraggableScrollableSheetScrollController? _attachedController; + final Set<AnimationController> _animationControllers = <AnimationController>{}; + + /// Get the current size (as a fraction of the parent height) of the attached sheet. + double get size { + _assertAttached(); + return _attachedController!.extent.currentSize; + } + + /// Get the current pixel height of the attached sheet. + double get pixels { + _assertAttached(); + return _attachedController!.extent.currentPixels; + } + + /// Convert a sheet's size (fractional value of parent container height) to pixels. + double sizeToPixels(double size) { + _assertAttached(); + return _attachedController!.extent.sizeToPixels(size); + } + + /// Returns Whether any [DraggableScrollableController] objects have attached themselves to the + /// [DraggableScrollableSheet]. + /// + /// If this is false, then members that interact with the [ScrollPosition], + /// such as [sizeToPixels], [size], [animateTo], and [jumpTo], must not be + /// called. + bool get isAttached => _attachedController != null && _attachedController!.hasClients; + + /// Convert a sheet's pixel height to size (fractional value of parent container height). + double pixelsToSize(double pixels) { + _assertAttached(); + return _attachedController!.extent.pixelsToSize(pixels); + } + + /// Animates the attached sheet from its current size to the given [size], a + /// fractional value of the parent container's height. + /// + /// Any active sheet animation is canceled. If the sheet's internal scrollable + /// is currently animating (e.g. responding to a user fling), that animation is + /// canceled as well. + /// + /// An animation will be interrupted whenever the user attempts to scroll + /// manually, whenever another activity is started, or when the sheet hits its + /// max or min size (e.g. if you animate to 1 but the max size is .8, the + /// animation will stop playing when it reaches .8). + /// + /// The duration must not be zero. To jump to a particular value without an + /// animation, use [jumpTo]. + /// + /// The sheet will not snap after calling [animateTo] even if [DraggableScrollableSheet.snap] + /// is true. Snapping only occurs after user drags. + /// + /// When calling [animateTo] in widget tests, `await`ing the returned + /// [Future] may cause the test to hang and timeout. Instead, use + /// [WidgetTester.pumpAndSettle]. + Future<void> animateTo( + double size, { + required Duration duration, + required Curve curve, + }) async { + _assertAttached(); + assert(size >= 0 && size <= 1); + assert(duration != Duration.zero); + final AnimationController animationController = AnimationController.unbounded( + vsync: _attachedController!.position.context.vsync, + value: _attachedController!.extent.currentSize, + ); + _animationControllers.add(animationController); + _attachedController!.position.goIdle(); + // This disables any snapping until the next user interaction with the sheet. + _attachedController!.extent.hasDragged = false; + _attachedController!.extent.hasChanged = true; + _attachedController!.extent.startActivity(onCanceled: () { + // Don't stop the controller if it's already finished and may have been disposed. + if (animationController.isAnimating) { + animationController.stop(); + } + }); + animationController.addListener(() { + _attachedController!.extent.updateSize( + animationController.value, + _attachedController!.position.context.notificationContext!, + ); + }); + await animationController.animateTo( + clampDouble(size, _attachedController!.extent.minSize, _attachedController!.extent.maxSize), + duration: duration, + curve: curve, + ); + } + + /// Jumps the attached sheet from its current size to the given [size], a + /// fractional value of the parent container's height. + /// + /// If [size] is outside of a the attached sheet's min or max child size, + /// [jumpTo] will jump the sheet to the nearest valid size instead. + /// + /// Any active sheet animation is canceled. If the sheet's inner scrollable + /// is currently animating (e.g. responding to a user fling), that animation is + /// canceled as well. + /// + /// The sheet will not snap after calling [jumpTo] even if [DraggableScrollableSheet.snap] + /// is true. Snapping only occurs after user drags. + void jumpTo(double size) { + _assertAttached(); + assert(size >= 0 && size <= 1); + // Call start activity to interrupt any other playing activities. + _attachedController!.extent.startActivity(onCanceled: () {}); + _attachedController!.position.goIdle(); + _attachedController!.extent.hasDragged = false; + _attachedController!.extent.hasChanged = true; + _attachedController!.extent.updateSize(size, _attachedController!.position.context.notificationContext!); + } + + /// Reset the attached sheet to its initial size (see: [DraggableScrollableSheet.initialChildSize]). + void reset() { + _assertAttached(); + _attachedController!.reset(); + } + + void _assertAttached() { + assert( + isAttached, + 'DraggableScrollableController is not attached to a sheet. A DraggableScrollableController ' + 'must be used in a DraggableScrollableSheet before any of its methods are called.', + ); + } + + void _attach(_DraggableScrollableSheetScrollController scrollController) { + assert(_attachedController == null, 'Draggable scrollable controller is already attached to a sheet.'); + _attachedController = scrollController; + _attachedController!.extent._currentSize.addListener(notifyListeners); + _attachedController!.onPositionDetached = _disposeAnimationControllers; + } + + void _onExtentReplaced(_DraggableSheetExtent previousExtent) { + // When the extent has been replaced, the old extent is already disposed and + // the controller will point to a new extent. We have to add our listener to + // the new extent. + _attachedController!.extent._currentSize.addListener(notifyListeners); + if (previousExtent.currentSize != _attachedController!.extent.currentSize) { + // The listener won't fire for a change in size between two extent + // objects so we have to fire it manually here. + notifyListeners(); + } + } + + void _detach({bool disposeExtent = false}) { + if (disposeExtent) { + _attachedController?.extent.dispose(); + } else { + _attachedController?.extent._currentSize.removeListener(notifyListeners); + } + _disposeAnimationControllers(); + _attachedController = null; + } + + void _disposeAnimationControllers() { + for (final AnimationController animationController in _animationControllers) { + animationController.dispose(); + } + _animationControllers.clear(); + } +} + +/// A container for a [Scrollable] that responds to drag gestures by resizing +/// the scrollable until a limit is reached, and then scrolling. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=Hgw819mL_78} +/// +/// This widget can be dragged along the vertical axis between its +/// [minChildSize], which defaults to `0.25` and [maxChildSize], which defaults +/// to `1.0`. These sizes are percentages of the height of the parent container. +/// +/// The widget coordinates resizing and scrolling of the widget returned by +/// builder as the user drags along the horizontal axis. +/// +/// The widget will initially be displayed at its initialChildSize which +/// defaults to `0.5`, meaning half the height of its parent. Dragging will work +/// between the range of minChildSize and maxChildSize (as percentages of the +/// parent container's height) as long as the builder creates a widget which +/// uses the provided [ScrollController]. If the widget created by the +/// [ScrollableWidgetBuilder] does not use the provided [ScrollController], the +/// sheet will remain at the initialChildSize. +/// +/// By default, the widget will stay at whatever size the user drags it to. To +/// make the widget snap to specific sizes whenever they lift their finger +/// during a drag, set [snap] to `true`. The sheet will snap between +/// [minChildSize] and [maxChildSize]. Use [snapSizes] to add more sizes for +/// the sheet to snap between. +/// +/// The snapping effect is only applied on user drags. Programmatically +/// manipulating the sheet size via [DraggableScrollableController.animateTo] or +/// [DraggableScrollableController.jumpTo] will ignore [snap] and [snapSizes]. +/// +/// By default, the widget will expand its non-occupied area to fill available +/// space in the parent. If this is not desired, e.g. because the parent wants +/// to position sheet based on the space it is taking, the [expand] property +/// may be set to false. +/// +/// {@tool dartpad} +/// +/// This is a sample widget which shows a [ListView] that has 25 [ListTile]s. +/// It starts out as taking up half the body of the [Scaffold], and can be +/// dragged up to the full height of the scaffold or down to 25% of the height +/// of the scaffold. Upon reaching full height, the list contents will be +/// scrolled up or down, until they reach the top of the list again and the user +/// drags the sheet back down. +/// +/// On desktop and web running on desktop platforms, dragging to scroll with a mouse is disabled by default +/// to align with the natural behavior found in other desktop applications. +/// +/// This behavior is dictated by the [ScrollBehavior], and can be changed by adding +/// [PointerDeviceKind.mouse] to [ScrollBehavior.dragDevices]. +/// For more info on this, please refer to https://docs.flutter.dev/release/breaking-changes/default-scroll-behavior-drag +/// +/// Alternatively, this example illustrates how to add a drag handle for desktop applications. +/// +/// ** See code in examples/api/lib/widgets/draggable_scrollable_sheet/draggable_scrollable_sheet.0.dart ** +/// {@end-tool} +class DraggableScrollableSheet extends StatefulWidget { + /// Creates a widget that can be dragged and scrolled in a single gesture. + const DraggableScrollableSheet({ + super.key, + this.initialChildSize = 0.5, + this.minChildSize = 0.25, + this.maxChildSize = 1.0, + this.expand = true, + this.snap = false, + this.snapSizes, + this.snapAnimationDuration, + this.controller, + this.shouldCloseOnMinExtent = true, + required this.builder, + }) : assert(minChildSize >= 0.0), + assert(maxChildSize <= 1.0), + assert(minChildSize <= initialChildSize), + assert(initialChildSize <= maxChildSize), + assert(snapAnimationDuration == null || snapAnimationDuration > Duration.zero); + + /// The initial fractional value of the parent container's height to use when + /// displaying the widget. + /// + /// Rebuilding the sheet with a new [initialChildSize] will only move + /// the sheet to the new value if the sheet has not yet been dragged since it + /// was first built or since the last call to [DraggableScrollableActuator.reset]. + /// + /// The default value is `0.5`. + final double initialChildSize; + + /// The minimum fractional value of the parent container's height to use when + /// displaying the widget. + /// + /// The default value is `0.25`. + final double minChildSize; + + /// The maximum fractional value of the parent container's height to use when + /// displaying the widget. + /// + /// The default value is `1.0`. + final double maxChildSize; + + /// Whether the widget should expand to fill the available space in its parent + /// or not. + /// + /// In most cases, this should be true. However, in the case of a parent + /// widget that will position this one based on its desired size (such as a + /// [Center]), this should be set to false. + /// + /// The default value is true. + final bool expand; + + /// Whether the widget should snap between [snapSizes] when the user lifts + /// their finger during a drag. + /// + /// If the user's finger was still moving when they lifted it, the widget will + /// snap to the next snap size (see [snapSizes]) in the direction of the drag. + /// If their finger was still, the widget will snap to the nearest snap size. + /// + /// Snapping is not applied when the sheet is programmatically moved by + /// calling [DraggableScrollableController.animateTo] or [DraggableScrollableController.jumpTo]. + /// + /// Rebuilding the sheet with snap newly enabled will immediately trigger a + /// snap unless the sheet has not yet been dragged away from + /// [initialChildSize] since first being built or since the last call to + /// [DraggableScrollableActuator.reset]. + final bool snap; + + /// A list of target sizes that the widget should snap to. + /// + /// Snap sizes are fractional values of the parent container's height. They + /// must be listed in increasing order and be between [minChildSize] and + /// [maxChildSize]. + /// + /// The [minChildSize] and [maxChildSize] are implicitly included in snap + /// sizes and do not need to be specified here. For example, `snapSizes = [.5]` + /// will result in a sheet that snaps between [minChildSize], `.5`, and + /// [maxChildSize]. + /// + /// Any modifications to the [snapSizes] list will not take effect until the + /// `build` function containing this widget is run again. + /// + /// Rebuilding with a modified or new list will trigger a snap unless the + /// sheet has not yet been dragged away from [initialChildSize] since first + /// being built or since the last call to [DraggableScrollableActuator.reset]. + final List<double>? snapSizes; + + /// Defines a duration for the snap animations. + /// + /// If it's not set, then the animation duration is the distance to the snap + /// target divided by the velocity of the widget. + final Duration? snapAnimationDuration; + + /// A controller that can be used to programmatically control this sheet. + final DraggableScrollableController? controller; + + /// Whether the sheet, when dragged (or flung) to its minimum size, should + /// cause its parent sheet to close. + /// + /// Set on emitted [DraggableScrollableNotification]s. It is up to parent + /// classes to properly read and handle this value. + final bool shouldCloseOnMinExtent; + + /// The builder that creates a child to display in this widget, which will + /// use the provided [ScrollController] to enable dragging and scrolling + /// of the contents. + final ScrollableWidgetBuilder builder; + + @override + State<DraggableScrollableSheet> createState() => _DraggableScrollableSheetState(); +} + +/// A [Notification] related to the extent, which is the size, and scroll +/// offset, which is the position of the child list, of the +/// [DraggableScrollableSheet]. +/// +/// [DraggableScrollableSheet] widgets notify their ancestors when the size of +/// the sheet changes. When the extent of the sheet changes via a drag, +/// this notification bubbles up through the tree, which means a given +/// [NotificationListener] will receive notifications for all descendant +/// [DraggableScrollableSheet] widgets. To focus on notifications from the +/// nearest [DraggableScrollableSheet] descendant, check that the [depth] +/// property of the notification is zero. +/// +/// When an extent notification is received by a [NotificationListener], the +/// listener will already have completed build and layout, and it is therefore +/// too late for that widget to call [State.setState]. Any attempt to adjust the +/// build or layout based on an extent notification would result in a layout +/// that lagged one frame behind, which is a poor user experience. Extent +/// notifications are used primarily to drive animations. The [Scaffold] widget +/// listens for extent notifications and responds by driving animations for the +/// [FloatingActionButton] as the bottom sheet scrolls up. +class DraggableScrollableNotification extends Notification with ViewportNotificationMixin { + /// Creates a notification that the extent of a [DraggableScrollableSheet] has + /// changed. + /// + /// All parameters are required. The [minExtent] must be >= 0. The [maxExtent] + /// must be <= 1.0. The [extent] must be between [minExtent] and [maxExtent]. + DraggableScrollableNotification({ + required this.extent, + required this.minExtent, + required this.maxExtent, + required this.initialExtent, + required this.context, + this.shouldCloseOnMinExtent = true, + }) : assert(0.0 <= minExtent), + assert(maxExtent <= 1.0), + assert(minExtent <= extent), + assert(minExtent <= initialExtent), + assert(extent <= maxExtent), + assert(initialExtent <= maxExtent); + + /// The current value of the extent, between [minExtent] and [maxExtent]. + final double extent; + + /// The minimum value of [extent], which is >= 0. + final double minExtent; + + /// The maximum value of [extent]. + final double maxExtent; + + /// The initially requested value for [extent]. + final double initialExtent; + + /// The build context of the widget that fired this notification. + /// + /// This can be used to find the sheet's render objects to determine the size + /// of the viewport, for instance. A listener can only assume this context + /// is live when it first gets the notification. + final BuildContext context; + + /// Whether the widget that fired this notification, when dragged (or flung) + /// to minExtent, should cause its parent sheet to close. + /// + /// It is up to parent classes to properly read and handle this value. + final bool shouldCloseOnMinExtent; + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + description.add('minExtent: $minExtent, extent: $extent, maxExtent: $maxExtent, initialExtent: $initialExtent'); + } +} + +/// Manages state between [_DraggableScrollableSheetState], +/// [_DraggableScrollableSheetScrollController], and +/// [_DraggableScrollableSheetScrollPosition]. +/// +/// The State knows the pixels available along the axis the widget wants to +/// scroll, but expects to get a fraction of those pixels to render the sheet. +/// +/// The ScrollPosition knows the number of pixels a user wants to move the sheet. +/// +/// The [currentSize] will never be null. +/// The [availablePixels] will never be null, but may be `double.infinity`. +class _DraggableSheetExtent { + _DraggableSheetExtent({ + required this.minSize, + required this.maxSize, + required this.snap, + required this.snapSizes, + required this.initialSize, + this.snapAnimationDuration, + ValueNotifier<double>? currentSize, + bool? hasDragged, + bool? hasChanged, + this.shouldCloseOnMinExtent = true, + }) : assert(minSize >= 0), + assert(maxSize <= 1), + assert(minSize <= initialSize), + assert(initialSize <= maxSize), + _currentSize = currentSize ?? ValueNotifier<double>(initialSize), + availablePixels = double.infinity, + hasDragged = hasDragged ?? false, + hasChanged = hasChanged ?? false; + + VoidCallback? _cancelActivity; + + final double minSize; + final double maxSize; + final bool snap; + final List<double> snapSizes; + final Duration? snapAnimationDuration; + final double initialSize; + final bool shouldCloseOnMinExtent; + final ValueNotifier<double> _currentSize; + double availablePixels; + + // Used to disable snapping until the user has dragged on the sheet. + bool hasDragged; + + // Used to determine if the sheet should move to a new initial size when it + // changes. + // We need both `hasChanged` and `hasDragged` to achieve the following + // behavior: + // 1. The sheet should only snap following user drags (as opposed to + // programmatic sheet changes). See docs for `animateTo` and `jumpTo`. + // 2. The sheet should move to a new initial child size on rebuild iff the + // sheet has not changed, either by drag or programmatic control. See + // docs for `initialChildSize`. + bool hasChanged; + + bool get isAtMin => minSize >= _currentSize.value; + bool get isAtMax => maxSize <= _currentSize.value; + + double get currentSize => _currentSize.value; + double get currentPixels => sizeToPixels(_currentSize.value); + + List<double> get pixelSnapSizes => snapSizes.map(sizeToPixels).toList(); + + /// Start an activity that affects the sheet and register a cancel call back + /// that will be called if another activity starts. + /// + /// The `onCanceled` callback will get called even if the subsequent activity + /// started after this one finished, so `onCanceled` must be safe to call at + /// any time. + void startActivity({required VoidCallback onCanceled}) { + _cancelActivity?.call(); + _cancelActivity = onCanceled; + } + + /// The scroll position gets inputs in terms of pixels, but the size is + /// expected to be expressed as a number between 0..1. + /// + /// This should only be called to respond to a user drag. To update the + /// size in response to a programmatic call, use [updateSize] directly. + void addPixelDelta(double delta, BuildContext context) { + // Stop any playing sheet animations. + _cancelActivity?.call(); + _cancelActivity = null; + // The user has interacted with the sheet, set `hasDragged` to true so that + // we'll snap if applicable. + hasDragged = true; + hasChanged = true; + if (availablePixels == 0) { + return; + } + updateSize(currentSize + pixelsToSize(delta), context); + } + + /// Set the size to the new value. [newSize] should be a number between + /// [minSize] and [maxSize]. + /// + /// This can be triggered by a programmatic (e.g. controller triggered) change + /// or a user drag. + void updateSize(double newSize, BuildContext context) { + final double clampedSize = clampDouble(newSize, minSize, maxSize); + if (_currentSize.value == clampedSize) { + return; + } + _currentSize.value = clampedSize; + DraggableScrollableNotification( + minExtent: minSize, + maxExtent: maxSize, + extent: currentSize, + initialExtent: initialSize, + context: context, + shouldCloseOnMinExtent: shouldCloseOnMinExtent, + ).dispatch(context); + } + + double pixelsToSize(double pixels) { + return pixels / availablePixels * maxSize; + } + + double sizeToPixels(double size) { + return size / maxSize * availablePixels; + } + + void dispose() { + _currentSize.dispose(); + } + + _DraggableSheetExtent copyWith({ + required double minSize, + required double maxSize, + required bool snap, + required List<double> snapSizes, + required double initialSize, + Duration? snapAnimationDuration, + bool shouldCloseOnMinExtent = true, + }) { + return _DraggableSheetExtent( + minSize: minSize, + maxSize: maxSize, + snap: snap, + snapSizes: snapSizes, + snapAnimationDuration: snapAnimationDuration, + initialSize: initialSize, + // Set the current size to the possibly updated initial size if the sheet + // hasn't changed yet. + currentSize: ValueNotifier<double>(hasChanged + ? clampDouble(_currentSize.value, minSize, maxSize) + : initialSize), + hasDragged: hasDragged, + hasChanged: hasChanged, + shouldCloseOnMinExtent: shouldCloseOnMinExtent, + ); + } +} + +class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> { + late _DraggableScrollableSheetScrollController _scrollController; + late _DraggableSheetExtent _extent; + + @override + void initState() { + super.initState(); + _extent = _DraggableSheetExtent( + minSize: widget.minChildSize, + maxSize: widget.maxChildSize, + snap: widget.snap, + snapSizes: _impliedSnapSizes(), + snapAnimationDuration: widget.snapAnimationDuration, + initialSize: widget.initialChildSize, + shouldCloseOnMinExtent: widget.shouldCloseOnMinExtent, + ); + _scrollController = _DraggableScrollableSheetScrollController(extent: _extent); + widget.controller?._attach(_scrollController); + } + + List<double> _impliedSnapSizes() { + for (int index = 0; index < (widget.snapSizes?.length ?? 0); index += 1) { + final double snapSize = widget.snapSizes![index]; + assert(snapSize >= widget.minChildSize && snapSize <= widget.maxChildSize, + '${_snapSizeErrorMessage(index)}\nSnap sizes must be between `minChildSize` and `maxChildSize`. '); + assert(index == 0 || snapSize > widget.snapSizes![index - 1], + '${_snapSizeErrorMessage(index)}\nSnap sizes must be in ascending order. '); + } + // Ensure the snap sizes start and end with the min and max child sizes. + if (widget.snapSizes == null || widget.snapSizes!.isEmpty) { + return <double>[ + widget.minChildSize, + widget.maxChildSize, + ]; + } + return <double>[ + if (widget.snapSizes!.first != widget.minChildSize) widget.minChildSize, + ...widget.snapSizes!, + if (widget.snapSizes!.last != widget.maxChildSize) widget.maxChildSize, + ]; + } + + @override + void didUpdateWidget(covariant DraggableScrollableSheet oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.controller != oldWidget.controller) { + oldWidget.controller?._detach(); + widget.controller?._attach(_scrollController); + } + _replaceExtent(oldWidget); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (_InheritedResetNotifier.shouldReset(context)) { + _scrollController.reset(); + } + } + + @override + Widget build(BuildContext context) { + return ValueListenableBuilder<double>( + valueListenable: _extent._currentSize, + builder: (BuildContext context, double currentSize, Widget? child) => LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + _extent.availablePixels = widget.maxChildSize * constraints.biggest.height; + final Widget sheet = FractionallySizedBox( + heightFactor: currentSize, + alignment: Alignment.bottomCenter, + child: child, + ); + return widget.expand ? SizedBox.expand(child: sheet) : sheet; + }, + ), + child: widget.builder(context, _scrollController), + ); + } + + @override + void dispose() { + if (widget.controller == null) { + _extent.dispose(); + } else { + widget.controller!._detach(disposeExtent: true); + } + _scrollController.dispose(); + super.dispose(); + } + + void _replaceExtent(covariant DraggableScrollableSheet oldWidget) { + final _DraggableSheetExtent previousExtent = _extent; + _extent = previousExtent.copyWith( + minSize: widget.minChildSize, + maxSize: widget.maxChildSize, + snap: widget.snap, + snapSizes: _impliedSnapSizes(), + snapAnimationDuration: widget.snapAnimationDuration, + initialSize: widget.initialChildSize, + ); + // Modify the existing scroll controller instead of replacing it so that + // developers listening to the controller do not have to rebuild their listeners. + _scrollController.extent = _extent; + // If an external facing controller was provided, let it know that the + // extent has been replaced. + widget.controller?._onExtentReplaced(previousExtent); + previousExtent.dispose(); + if (widget.snap + && (widget.snap != oldWidget.snap || widget.snapSizes != oldWidget.snapSizes) + && _scrollController.hasClients + ) { + // Trigger a snap in case snap or snapSizes has changed and there is a + // scroll position currently attached. We put this in a post frame + // callback so that `build` can update `_extent.availablePixels` before + // this runs-we can't use the previous extent's available pixels as it may + // have changed when the widget was updated. + WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) { + for (int index = 0; index < _scrollController.positions.length; index++) { + final _DraggableScrollableSheetScrollPosition position = + _scrollController.positions.elementAt(index) as _DraggableScrollableSheetScrollPosition; + position.goBallistic(0); + } + }, debugLabel: 'DraggableScrollableSheet.snap'); + } + } + + String _snapSizeErrorMessage(int invalidIndex) { + final List<String> snapSizesWithIndicator = widget.snapSizes!.asMap().keys.map( + (int index) { + final String snapSizeString = widget.snapSizes![index].toString(); + if (index == invalidIndex) { + return '>>> $snapSizeString <<<'; + } + return snapSizeString; + }, + ).toList(); + return "Invalid snapSize '${widget.snapSizes![invalidIndex]}' at index $invalidIndex of:\n" + ' $snapSizesWithIndicator'; + } +} + +/// A [ScrollController] suitable for use in a [ScrollableWidgetBuilder] created +/// by a [DraggableScrollableSheet]. +/// +/// If a [DraggableScrollableSheet] contains content that is exceeds the height +/// of its container, this controller will allow the sheet to both be dragged to +/// fill the container and then scroll the child content. +/// +/// See also: +/// +/// * [_DraggableScrollableSheetScrollPosition], which manages the positioning logic for +/// this controller. +/// * [PrimaryScrollController], which can be used to establish a +/// [_DraggableScrollableSheetScrollController] as the primary controller for +/// descendants. +class _DraggableScrollableSheetScrollController extends ScrollController { + _DraggableScrollableSheetScrollController({ + required this.extent, + }); + + _DraggableSheetExtent extent; + VoidCallback? onPositionDetached; + + @override + _DraggableScrollableSheetScrollPosition createScrollPosition( + ScrollPhysics physics, + ScrollContext context, + ScrollPosition? oldPosition, + ) { + return _DraggableScrollableSheetScrollPosition( + physics: physics.applyTo(const AlwaysScrollableScrollPhysics()), + context: context, + oldPosition: oldPosition, + getExtent: () => extent, + ); + } + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + description.add('extent: $extent'); + } + + @override + _DraggableScrollableSheetScrollPosition get position => + super.position as _DraggableScrollableSheetScrollPosition; + + void reset() { + extent._cancelActivity?.call(); + extent.hasDragged = false; + extent.hasChanged = false; + // jumpTo can result in trying to replace semantics during build. + // Just animate really fast. + // Avoid doing it at all if the offset is already 0.0. + if (offset != 0.0) { + animateTo( + 0.0, + duration: const Duration(milliseconds: 1), + curve: Curves.linear, + ); + } + extent.updateSize(extent.initialSize, position.context.notificationContext!); + } + + @override + void detach(ScrollPosition position) { + onPositionDetached?.call(); + super.detach(position); + } +} + +/// A scroll position that manages scroll activities for +/// [_DraggableScrollableSheetScrollController]. +/// +/// This class is a concrete subclass of [ScrollPosition] logic that handles a +/// single [ScrollContext], such as a [Scrollable]. An instance of this class +/// manages [ScrollActivity] instances, which changes the +/// [_DraggableSheetExtent.currentSize] or visible content offset in the +/// [Scrollable]'s [Viewport] +/// +/// See also: +/// +/// * [_DraggableScrollableSheetScrollController], which uses this as its [ScrollPosition]. +class _DraggableScrollableSheetScrollPosition extends ScrollPositionWithSingleContext { + _DraggableScrollableSheetScrollPosition({ + required super.physics, + required super.context, + super.oldPosition, + required this.getExtent, + }); + + VoidCallback? _dragCancelCallback; + final _DraggableSheetExtent Function() getExtent; + final Set<AnimationController> _ballisticControllers = <AnimationController>{}; + bool get listShouldScroll => pixels > 0.0; + + _DraggableSheetExtent get extent => getExtent(); + + @override + void absorb(ScrollPosition other) { + super.absorb(other); + assert(_dragCancelCallback == null); + + if (other is! _DraggableScrollableSheetScrollPosition) { + return; + } + + if (other._dragCancelCallback != null) { + _dragCancelCallback = other._dragCancelCallback; + other._dragCancelCallback = null; + } + } + + @override + void beginActivity(ScrollActivity? newActivity) { + // Cancel the running ballistic simulations + for (final AnimationController ballisticController in _ballisticControllers) { + ballisticController.stop(); + } + super.beginActivity(newActivity); + } + + @override + void applyUserOffset(double delta) { + if (!listShouldScroll && + (!(extent.isAtMin || extent.isAtMax) || + (extent.isAtMin && delta < 0) || + (extent.isAtMax && delta > 0))) { + extent.addPixelDelta(-delta, context.notificationContext!); + } else { + super.applyUserOffset(delta); + } + } + + bool get _isAtSnapSize { + return extent.snapSizes.any( + (double snapSize) { + return (extent.currentSize - snapSize).abs() <= extent.pixelsToSize(physics.toleranceFor(this).distance); + }, + ); + } + bool get _shouldSnap => extent.snap && extent.hasDragged && !_isAtSnapSize; + + @override + void dispose() { + for (final AnimationController ballisticController in _ballisticControllers) { + ballisticController.dispose(); + } + _ballisticControllers.clear(); + super.dispose(); + } + + @override + void goBallistic(double velocity) { + if ((velocity == 0.0 && !_shouldSnap) || + (velocity < 0.0 && listShouldScroll) || + (velocity > 0.0 && extent.isAtMax)) { + super.goBallistic(velocity); + return; + } + // Scrollable expects that we will dispose of its current _dragCancelCallback + _dragCancelCallback?.call(); + _dragCancelCallback = null; + + late final Simulation simulation; + if (extent.snap) { + // Snap is enabled, simulate snapping instead of clamping scroll. + simulation = _SnappingSimulation( + position: extent.currentPixels, + initialVelocity: velocity, + pixelSnapSize: extent.pixelSnapSizes, + snapAnimationDuration: extent.snapAnimationDuration, + tolerance: physics.toleranceFor(this), + ); + } else { + // The iOS bouncing simulation just isn't right here - once we delegate + // the ballistic back to the ScrollView, it will use the right simulation. + simulation = ClampingScrollSimulation( + // Run the simulation in terms of pixels, not extent. + position: extent.currentPixels, + velocity: velocity, + tolerance: physics.toleranceFor(this), + ); + } + + final AnimationController ballisticController = AnimationController.unbounded( + debugLabel: objectRuntimeType(this, '_DraggableScrollableSheetPosition'), + vsync: context.vsync, + ); + _ballisticControllers.add(ballisticController); + + double lastPosition = extent.currentPixels; + void tick() { + final double delta = ballisticController.value - lastPosition; + lastPosition = ballisticController.value; + extent.addPixelDelta(delta, context.notificationContext!); + if ((velocity > 0 && extent.isAtMax) || (velocity < 0 && extent.isAtMin)) { + // Make sure we pass along enough velocity to keep scrolling - otherwise + // we just "bounce" off the top making it look like the list doesn't + // have more to scroll. + velocity = ballisticController.velocity + (physics.toleranceFor(this).velocity * ballisticController.velocity.sign); + super.goBallistic(velocity); + ballisticController.stop(); + } else if (ballisticController.isCompleted) { + super.goBallistic(0); + } + } + + ballisticController + ..addListener(tick) + ..animateWith(simulation).whenCompleteOrCancel( + () { + if (_ballisticControllers.contains(ballisticController)) { + _ballisticControllers.remove(ballisticController); + ballisticController.dispose(); + } + }, + ); + } + + @override + Drag drag(DragStartDetails details, VoidCallback dragCancelCallback) { + // Save this so we can call it later if we have to [goBallistic] on our own. + _dragCancelCallback = dragCancelCallback; + return super.drag(details, dragCancelCallback); + } +} + +/// A widget that can notify a descendent [DraggableScrollableSheet] that it +/// should reset its position to the initial state. +/// +/// The [Scaffold] uses this widget to notify a persistent bottom sheet that +/// the user has tapped back if the sheet has started to cover more of the body +/// than when at its initial position. This is important for users of assistive +/// technology, where dragging may be difficult to communicate. +/// +/// This is just a wrapper on top of [DraggableScrollableController]. It is +/// primarily useful for controlling a sheet in a part of the widget tree that +/// the current code does not control (e.g. library code trying to affect a sheet +/// in library users' code). Generally, it's easier to control the sheet +/// directly by creating a controller and passing the controller to the sheet in +/// its constructor (see [DraggableScrollableSheet.controller]). +class DraggableScrollableActuator extends StatefulWidget { + /// Creates a widget that can notify descendent [DraggableScrollableSheet]s + /// to reset to their initial position. + /// + /// The [child] parameter is required. + const DraggableScrollableActuator({ + super.key, + required this.child, + }); + + /// This child's [DraggableScrollableSheet] descendant will be reset when the + /// [reset] method is applied to a context that includes it. + final Widget child; + + + /// Notifies any descendant [DraggableScrollableSheet] that it should reset + /// to its initial position. + /// + /// Returns `true` if a [DraggableScrollableActuator] is available and + /// some [DraggableScrollableSheet] is listening for updates, `false` + /// otherwise. + static bool reset(BuildContext context) { + final _InheritedResetNotifier? notifier = context.dependOnInheritedWidgetOfExactType<_InheritedResetNotifier>(); + if (notifier == null) { + return false; + } + return notifier._sendReset(); + } + + @override + State<DraggableScrollableActuator> createState() => _DraggableScrollableActuatorState(); +} + +class _DraggableScrollableActuatorState extends State<DraggableScrollableActuator> { + final _ResetNotifier _notifier = _ResetNotifier(); + + @override + Widget build(BuildContext context) { + return _InheritedResetNotifier(notifier: _notifier, child: widget.child); + } + + @override + void dispose() { + _notifier.dispose(); + super.dispose(); + } +} + +/// A [ChangeNotifier] to use with [InheritedResetNotifier] to notify +/// descendants that they should reset to initial state. +class _ResetNotifier extends ChangeNotifier { + _ResetNotifier() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + /// Whether someone called [sendReset] or not. + /// + /// This flag should be reset after checking it. + bool _wasCalled = false; + + /// Fires a reset notification to descendants. + /// + /// Returns false if there are no listeners. + bool sendReset() { + if (!hasListeners) { + return false; + } + _wasCalled = true; + notifyListeners(); + return true; + } +} + +class _InheritedResetNotifier extends InheritedNotifier<_ResetNotifier> { + /// Creates an [InheritedNotifier] that the [DraggableScrollableSheet] will + /// listen to for an indication that it should reset itself back to [DraggableScrollableSheet.initialChildSize]. + const _InheritedResetNotifier({ + required super.child, + required _ResetNotifier super.notifier, + }); + + bool _sendReset() => notifier!.sendReset(); + + /// Specifies whether the [DraggableScrollableSheet] should reset to its + /// initial position. + /// + /// Returns true if the notifier requested a reset, false otherwise. + static bool shouldReset(BuildContext context) { + final InheritedWidget? widget = context.dependOnInheritedWidgetOfExactType<_InheritedResetNotifier>(); + if (widget == null) { + return false; + } + assert(widget is _InheritedResetNotifier); + final _InheritedResetNotifier inheritedNotifier = widget as _InheritedResetNotifier; + final bool wasCalled = inheritedNotifier.notifier!._wasCalled; + inheritedNotifier.notifier!._wasCalled = false; + return wasCalled; + } +} + +class _SnappingSimulation extends Simulation { + _SnappingSimulation({ + required this.position, + required double initialVelocity, + required List<double> pixelSnapSize, + Duration? snapAnimationDuration, + super.tolerance, + }) { + _pixelSnapSize = _getSnapSize(initialVelocity, pixelSnapSize); + + if (snapAnimationDuration != null && snapAnimationDuration.inMilliseconds > 0) { + velocity = (_pixelSnapSize - position) * 1000 / snapAnimationDuration.inMilliseconds; + } + // Check the direction of the target instead of the sign of the velocity because + // we may snap in the opposite direction of velocity if velocity is very low. + else if (_pixelSnapSize < position) { + velocity = math.min(-minimumSpeed, initialVelocity); + } else { + velocity = math.max(minimumSpeed, initialVelocity); + } + } + + final double position; + late final double velocity; + + // A minimum speed to snap at. Used to ensure that the snapping animation + // does not play too slowly. + static const double minimumSpeed = 1600.0; + + late final double _pixelSnapSize; + + @override + double dx(double time) { + if (isDone(time)) { + return 0; + } + return velocity; + } + + @override + bool isDone(double time) { + return x(time) == _pixelSnapSize; + } + + @override + double x(double time) { + final double newPosition = position + velocity * time; + if ((velocity >= 0 && newPosition > _pixelSnapSize) || + (velocity < 0 && newPosition < _pixelSnapSize)) { + // We're passed the snap size, return it instead. + return _pixelSnapSize; + } + return newPosition; + } + + // Find the two closest snap sizes to the position. If the velocity is + // non-zero, select the size in the velocity's direction. Otherwise, + // the nearest snap size. + double _getSnapSize(double initialVelocity, List<double> pixelSnapSizes) { + final int indexOfNextSize = pixelSnapSizes + .indexWhere((double size) => size >= position); + if (indexOfNextSize == 0) { + return pixelSnapSizes.first; + } + final double nextSize = pixelSnapSizes[indexOfNextSize]; + final double previousSize = pixelSnapSizes[indexOfNextSize - 1]; + if (initialVelocity.abs() <= tolerance.velocity) { + // If velocity is zero, snap to the nearest snap size with the minimum velocity. + if (position - previousSize < nextSize - position) { + return previousSize; + } else { + return nextSize; + } + } + // Snap forward or backward depending on current velocity. + if (initialVelocity < 0.0) { + return pixelSnapSizes[indexOfNextSize - 1]; + } + return pixelSnapSizes[indexOfNextSize]; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/dual_transition_builder.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/dual_transition_builder.dart new file mode 100644 index 0000000000000000000000000000000000000000..5f1a1868e4a5560f5791c7ff411711fbf88b894b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/dual_transition_builder.dart @@ -0,0 +1,188 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'basic.dart'; +import 'framework.dart'; + +/// Builder callback used by [DualTransitionBuilder]. +/// +/// The builder is expected to return a transition powered by the provided +/// `animation` and wrapping the provided `child`. +/// +/// The `animation` provided to the builder always runs forward from 0.0 to 1.0. +typedef AnimatedTransitionBuilder = Widget Function( + BuildContext context, + Animation<double> animation, + Widget? child, +); + +/// A transition builder that animates its [child] based on the +/// [AnimationStatus] of the provided [animation]. +/// +/// This widget can be used to specify different enter and exit transitions for +/// a [child]. +/// +/// While the [animation] runs forward, the [child] is animated according to +/// [forwardBuilder] and while the [animation] is running in reverse, it is +/// animated according to [reverseBuilder]. +/// +/// Using this builder allows the widget tree to maintain its shape by nesting +/// the enter and exit transitions. This ensures that no state information of +/// any descendant widget is lost when the transition starts or completes. +class DualTransitionBuilder extends StatefulWidget { + /// Creates a [DualTransitionBuilder]. + const DualTransitionBuilder({ + super.key, + required this.animation, + required this.forwardBuilder, + required this.reverseBuilder, + this.child, + }); + + /// The animation that drives the [child]'s transition. + /// + /// When this animation runs forward, the [child] transitions as specified by + /// [forwardBuilder]. When it runs in reverse, the child transitions according + /// to [reverseBuilder]. + final Animation<double> animation; + + /// A builder for the transition that makes [child] appear on screen. + /// + /// The [child] should be fully visible when the provided `animation` reaches + /// 1.0. + /// + /// The `animation` provided to this builder is running forward from 0.0 to + /// 1.0 when [animation] runs _forward_. When [animation] runs in reverse, + /// the given `animation` is set to [kAlwaysCompleteAnimation]. + /// + /// See also: + /// + /// * [reverseBuilder], which builds the transition for making the [child] + /// disappear from the screen. + final AnimatedTransitionBuilder forwardBuilder; + + /// A builder for a transition that makes [child] disappear from the screen. + /// + /// The [child] should be fully invisible when the provided `animation` + /// reaches 1.0. + /// + /// The `animation` provided to this builder is running forward from 0.0 to + /// 1.0 when [animation] runs in _reverse_. When [animation] runs forward, + /// the given `animation` is set to [kAlwaysDismissedAnimation]. + /// + /// See also: + /// + /// * [forwardBuilder], which builds the transition for making the [child] + /// appear on screen. + final AnimatedTransitionBuilder reverseBuilder; + + /// The widget below this [DualTransitionBuilder] in the tree. + /// + /// This child widget will be wrapped by the transitions built by + /// [forwardBuilder] and [reverseBuilder]. + final Widget? child; + + @override + State<DualTransitionBuilder> createState() => _DualTransitionBuilderState(); +} + +class _DualTransitionBuilderState extends State<DualTransitionBuilder> { + late AnimationStatus _effectiveAnimationStatus; + final ProxyAnimation _forwardAnimation = ProxyAnimation(); + final ProxyAnimation _reverseAnimation = ProxyAnimation(); + + @override + void initState() { + super.initState(); + _effectiveAnimationStatus = widget.animation.status; + widget.animation.addStatusListener(_animationListener); + _updateAnimations(); + } + + void _animationListener(AnimationStatus animationStatus) { + final AnimationStatus oldEffective = _effectiveAnimationStatus; + _effectiveAnimationStatus = _calculateEffectiveAnimationStatus( + lastEffective: _effectiveAnimationStatus, + current: animationStatus, + ); + if (oldEffective != _effectiveAnimationStatus) { + _updateAnimations(); + } + } + + @override + void didUpdateWidget(DualTransitionBuilder oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.animation != widget.animation) { + oldWidget.animation.removeStatusListener(_animationListener); + widget.animation.addStatusListener(_animationListener); + _animationListener(widget.animation.status); + } + } + + // When a transition is interrupted midway we just want to play the ongoing + // animation in reverse. Switching to the actual reverse transition would + // yield a disjoint experience since the forward and reverse transitions are + // very different. + AnimationStatus _calculateEffectiveAnimationStatus({ + required AnimationStatus lastEffective, + required AnimationStatus current, + }) { + switch (current) { + case AnimationStatus.dismissed: + case AnimationStatus.completed: + return current; + case AnimationStatus.forward: + switch (lastEffective) { + case AnimationStatus.dismissed: + case AnimationStatus.completed: + case AnimationStatus.forward: + return current; + case AnimationStatus.reverse: + return lastEffective; + } + case AnimationStatus.reverse: + switch (lastEffective) { + case AnimationStatus.dismissed: + case AnimationStatus.completed: + case AnimationStatus.reverse: + return current; + case AnimationStatus.forward: + return lastEffective; + } + } + } + + void _updateAnimations() { + switch (_effectiveAnimationStatus) { + case AnimationStatus.dismissed: + case AnimationStatus.forward: + _forwardAnimation.parent = widget.animation; + _reverseAnimation.parent = kAlwaysDismissedAnimation; + case AnimationStatus.reverse: + case AnimationStatus.completed: + _forwardAnimation.parent = kAlwaysCompleteAnimation; + _reverseAnimation.parent = ReverseAnimation(widget.animation); + } + } + + @override + void dispose() { + widget.animation.removeStatusListener(_animationListener); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return widget.forwardBuilder( + context, + _forwardAnimation, + widget.reverseBuilder( + context, + _reverseAnimation, + widget.child, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/editable_text.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/editable_text.dart new file mode 100644 index 0000000000000000000000000000000000000000..8f6611370a214a3e4f8e0320e3a7e7b177ded2ac --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/editable_text.dart @@ -0,0 +1,5754 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; +import 'dart:ui' as ui hide TextStyle; + +import 'package:characters/characters.dart' show CharacterRange, StringCharacters; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart' show DragStartBehavior; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'actions.dart'; +import 'autofill.dart'; +import 'automatic_keep_alive.dart'; +import 'basic.dart'; +import 'binding.dart'; +import 'constants.dart'; +import 'context_menu_button_item.dart'; +import 'debug.dart'; +import 'default_selection_style.dart'; +import 'default_text_editing_shortcuts.dart'; +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'focus_traversal.dart'; +import 'framework.dart'; +import 'localizations.dart'; +import 'magnifier.dart'; +import 'media_query.dart'; +import 'scroll_configuration.dart'; +import 'scroll_controller.dart'; +import 'scroll_physics.dart'; +import 'scroll_position.dart'; +import 'scrollable.dart'; +import 'scrollable_helpers.dart'; +import 'shortcuts.dart'; +import 'spell_check.dart'; +import 'tap_region.dart'; +import 'text.dart'; +import 'text_editing_intents.dart'; +import 'text_selection.dart'; +import 'text_selection_toolbar_anchors.dart'; +import 'ticker_provider.dart'; +import 'undo_history.dart'; +import 'view.dart'; +import 'widget_span.dart'; + +export 'package:flutter/services.dart' show KeyboardInsertedContent, SelectionChangedCause, SmartDashesType, SmartQuotesType, TextEditingValue, TextInputType, TextSelection; + +// Examples can assume: +// late BuildContext context; +// late WidgetTester tester; + +/// Signature for the callback that reports when the user changes the selection +/// (including the cursor location). +typedef SelectionChangedCallback = void Function(TextSelection selection, SelectionChangedCause? cause); + +/// Signature for the callback that reports the app private command results. +typedef AppPrivateCommandCallback = void Function(String action, Map<String, dynamic> data); + +/// Signature for a widget builder that builds a context menu for the given +/// [EditableTextState]. +/// +/// See also: +/// +/// * [SelectableRegionContextMenuBuilder], which performs the same role for +/// [SelectableRegion]. +typedef EditableTextContextMenuBuilder = Widget Function( + BuildContext context, + EditableTextState editableTextState, +); + +// Signature for a function that determines the target location of the given +// [TextPosition] after applying the given [TextBoundary]. +typedef _ApplyTextBoundary = TextPosition Function(TextPosition, bool, TextBoundary); + +// The time it takes for the cursor to fade from fully opaque to fully +// transparent and vice versa. A full cursor blink, from transparent to opaque +// to transparent, is twice this duration. +const Duration _kCursorBlinkHalfPeriod = Duration(milliseconds: 500); + +// Number of cursor ticks during which the most recently entered character +// is shown in an obscured text field. +const int _kObscureShowLatestCharCursorTicks = 3; + +/// The default mime types to be used when allowedMimeTypes is not provided. +/// +/// The default value supports inserting images of any supported format. +const List<String> kDefaultContentInsertionMimeTypes = <String>[ + 'image/png', + 'image/bmp', + 'image/jpg', + 'image/tiff', + 'image/gif', + 'image/jpeg', + 'image/webp' +]; + +class _CompositionCallback extends SingleChildRenderObjectWidget { + const _CompositionCallback({ required this.compositeCallback, required this.enabled, super.child }); + final CompositionCallback compositeCallback; + final bool enabled; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderCompositionCallback(compositeCallback, enabled); + } + @override + void updateRenderObject(BuildContext context, _RenderCompositionCallback renderObject) { + super.updateRenderObject(context, renderObject); + // _EditableTextState always uses the same callback. + assert(renderObject.compositeCallback == compositeCallback); + renderObject.enabled = enabled; + } +} + +class _RenderCompositionCallback extends RenderProxyBox { + _RenderCompositionCallback(this.compositeCallback, this._enabled); + + final CompositionCallback compositeCallback; + VoidCallback? _cancelCallback; + + bool get enabled => _enabled; + bool _enabled = false; + set enabled(bool newValue) { + _enabled = newValue; + if (!newValue) { + _cancelCallback?.call(); + _cancelCallback = null; + } else if (_cancelCallback == null) { + markNeedsPaint(); + } + } + + @override + void paint(PaintingContext context, ui.Offset offset) { + if (enabled) { + _cancelCallback ??= context.addCompositionCallback(compositeCallback); + } + super.paint(context, offset); + } +} + +/// A controller for an editable text field. +/// +/// Whenever the user modifies a text field with an associated +/// [TextEditingController], the text field updates [value] and the controller +/// notifies its listeners. Listeners can then read the [text] and [selection] +/// properties to learn what the user has typed or how the selection has been +/// updated. +/// +/// Similarly, if you modify the [text] or [selection] properties, the text +/// field will be notified and will update itself appropriately. +/// +/// A [TextEditingController] can also be used to provide an initial value for a +/// text field. If you build a text field with a controller that already has +/// [text], the text field will use that text as its initial value. +/// +/// The [value] (as well as [text] and [selection]) of this controller can be +/// updated from within a listener added to this controller. Be aware of +/// infinite loops since the listener will also be notified of the changes made +/// from within itself. Modifying the composing region from within a listener +/// can also have a bad interaction with some input methods. Gboard, for +/// example, will try to restore the composing region of the text if it was +/// modified programmatically, creating an infinite loop of communications +/// between the framework and the input method. Consider using +/// [TextInputFormatter]s instead for as-you-type text modification. +/// +/// If both the [text] or [selection] properties need to be changed, set the +/// controller's [value] instead. +/// +/// Remember to [dispose] of the [TextEditingController] when it is no longer +/// needed. This will ensure we discard any resources used by the object. +/// {@tool dartpad} +/// This example creates a [TextField] with a [TextEditingController] whose +/// change listener forces the entered text to be lower case and keeps the +/// cursor at the end of the input. +/// +/// ** See code in examples/api/lib/widgets/editable_text/text_editing_controller.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [TextField], which is a Material Design text field that can be controlled +/// with a [TextEditingController]. +/// * [EditableText], which is a raw region of editable text that can be +/// controlled with a [TextEditingController]. +/// * Learn how to use a [TextEditingController] in one of our [cookbook recipes](https://flutter.dev/docs/cookbook/forms/text-field-changes#2-use-a-texteditingcontroller). +class TextEditingController extends ValueNotifier<TextEditingValue> { + /// Creates a controller for an editable text field. + /// + /// This constructor treats a null [text] argument as if it were the empty + /// string. + TextEditingController({ String? text }) + : super(text == null ? TextEditingValue.empty : TextEditingValue(text: text)); + + /// Creates a controller for an editable text field from an initial [TextEditingValue]. + /// + /// This constructor treats a null [value] argument as if it were + /// [TextEditingValue.empty]. + TextEditingController.fromValue(TextEditingValue? value) + : assert( + value == null || !value.composing.isValid || value.isComposingRangeValid, + 'New TextEditingValue $value has an invalid non-empty composing range ' + '${value.composing}. It is recommended to use a valid composing range, ' + 'even for readonly text fields.', + ), + super(value ?? TextEditingValue.empty); + + /// The current string the user is editing. + String get text => value.text; + /// Setting this will notify all the listeners of this [TextEditingController] + /// that they need to update (it calls [notifyListeners]). For this reason, + /// this value should only be set between frames, e.g. in response to user + /// actions, not during the build, layout, or paint phases. + /// + /// This property can be set from a listener added to this + /// [TextEditingController]; however, one should not also set [selection] + /// in a separate statement. To change both the [text] and the [selection] + /// change the controller's [value]. + set text(String newText) { + value = value.copyWith( + text: newText, + selection: const TextSelection.collapsed(offset: -1), + composing: TextRange.empty, + ); + } + + @override + set value(TextEditingValue newValue) { + assert( + !newValue.composing.isValid || newValue.isComposingRangeValid, + 'New TextEditingValue $newValue has an invalid non-empty composing range ' + '${newValue.composing}. It is recommended to use a valid composing range, ' + 'even for readonly text fields.', + ); + super.value = newValue; + } + + /// Builds [TextSpan] from current editing value. + /// + /// By default makes text in composing range appear as underlined. Descendants + /// can override this method to customize appearance of text. + TextSpan buildTextSpan({required BuildContext context, TextStyle? style , required bool withComposing}) { + assert(!value.composing.isValid || !withComposing || value.isComposingRangeValid); + // If the composing range is out of range for the current text, ignore it to + // preserve the tree integrity, otherwise in release mode a RangeError will + // be thrown and this EditableText will be built with a broken subtree. + final bool composingRegionOutOfRange = !value.isComposingRangeValid || !withComposing; + + if (composingRegionOutOfRange) { + return TextSpan(style: style, text: text); + } + + final TextStyle composingStyle = style?.merge(const TextStyle(decoration: TextDecoration.underline)) + ?? const TextStyle(decoration: TextDecoration.underline); + return TextSpan( + style: style, + children: <TextSpan>[ + TextSpan(text: value.composing.textBefore(value.text)), + TextSpan( + style: composingStyle, + text: value.composing.textInside(value.text), + ), + TextSpan(text: value.composing.textAfter(value.text)), + ], + ); + } + + /// The currently selected [text]. + /// + /// If the selection is collapsed, then this property gives the offset of the + /// cursor within the text. + TextSelection get selection => value.selection; + /// Setting this will notify all the listeners of this [TextEditingController] + /// that they need to update (it calls [notifyListeners]). For this reason, + /// this value should only be set between frames, e.g. in response to user + /// actions, not during the build, layout, or paint phases. + /// + /// This property can be set from a listener added to this + /// [TextEditingController]; however, one should not also set [text] + /// in a separate statement. To change both the [text] and the [selection] + /// change the controller's [value]. + /// + /// If the new selection is of non-zero length, or is outside the composing + /// range, the composing range is cleared. + set selection(TextSelection newSelection) { + if (!isSelectionWithinTextBounds(newSelection)) { + throw FlutterError('invalid text selection: $newSelection'); + } + final TextRange newComposing = + newSelection.isCollapsed && _isSelectionWithinComposingRange(newSelection) + ? value.composing + : TextRange.empty; + value = value.copyWith(selection: newSelection, composing: newComposing); + } + + /// Set the [value] to empty. + /// + /// After calling this function, [text] will be the empty string and the + /// selection will be collapsed at zero offset. + /// + /// Calling this will notify all the listeners of this [TextEditingController] + /// that they need to update (it calls [notifyListeners]). For this reason, + /// this method should only be called between frames, e.g. in response to user + /// actions, not during the build, layout, or paint phases. + void clear() { + value = const TextEditingValue(selection: TextSelection.collapsed(offset: 0)); + } + + /// Set the composing region to an empty range. + /// + /// The composing region is the range of text that is still being composed. + /// Calling this function indicates that the user is done composing that + /// region. + /// + /// Calling this will notify all the listeners of this [TextEditingController] + /// that they need to update (it calls [notifyListeners]). For this reason, + /// this method should only be called between frames, e.g. in response to user + /// actions, not during the build, layout, or paint phases. + void clearComposing() { + value = value.copyWith(composing: TextRange.empty); + } + + /// Check that the [selection] is inside of the bounds of [text]. + bool isSelectionWithinTextBounds(TextSelection selection) { + return selection.start <= text.length && selection.end <= text.length; + } + + /// Check that the [selection] is inside of the composing range. + bool _isSelectionWithinComposingRange(TextSelection selection) { + return selection.start >= value.composing.start && selection.end <= value.composing.end; + } +} + +/// Toolbar configuration for [EditableText]. +/// +/// Toolbar is a context menu that will show up when user right click or long +/// press the [EditableText]. It includes several options: cut, copy, paste, +/// and select all. +/// +/// [EditableText] and its derived widgets have their own default [ToolbarOptions]. +/// Create a custom [ToolbarOptions] if you want explicit control over the toolbar +/// option. +@Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', +) +class ToolbarOptions { + /// Create a toolbar configuration with given options. + /// + /// All options default to false if they are not explicitly set. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + const ToolbarOptions({ + this.copy = false, + this.cut = false, + this.paste = false, + this.selectAll = false, + }); + + /// An instance of [ToolbarOptions] with no options enabled. + static const ToolbarOptions empty = ToolbarOptions(); + + /// Whether to show copy option in toolbar. + /// + /// Defaults to false. + final bool copy; + + /// Whether to show cut option in toolbar. + /// + /// If [EditableText.readOnly] is set to true, cut will be disabled regardless. + /// + /// Defaults to false. + final bool cut; + + /// Whether to show paste option in toolbar. + /// + /// If [EditableText.readOnly] is set to true, paste will be disabled regardless. + /// + /// Defaults to false. + final bool paste; + + /// Whether to show select all option in toolbar. + /// + /// Defaults to false. + final bool selectAll; +} + +/// Configures the ability to insert media content through the soft keyboard. +/// +/// The configuration provides a handler for any rich content inserted through +/// the system input method, and also provides the ability to limit the mime +/// types of the inserted content. +/// +/// See also: +/// +/// * [EditableText.contentInsertionConfiguration] +class ContentInsertionConfiguration { + /// Creates a content insertion configuration with the specified options. + /// + /// A handler for inserted content, in the form of [onContentInserted], must + /// be supplied. + /// + /// The allowable mime types of inserted content may also + /// be provided via [allowedMimeTypes], which cannot be an empty list. + ContentInsertionConfiguration({ + required this.onContentInserted, + this.allowedMimeTypes = kDefaultContentInsertionMimeTypes, + }) : assert(allowedMimeTypes.isNotEmpty); + + /// Called when a user inserts content through the virtual / on-screen keyboard, + /// currently only used on Android. + /// + /// [KeyboardInsertedContent] holds the data representing the inserted content. + /// + /// {@tool dartpad} + /// + /// This example shows how to access the data for inserted content in your + /// `TextField`. + /// + /// ** See code in examples/api/lib/widgets/editable_text/editable_text.on_content_inserted.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * <https://developer.android.com/guide/topics/text/image-keyboard> + final ValueChanged<KeyboardInsertedContent> onContentInserted; + + /// {@template flutter.widgets.contentInsertionConfiguration.allowedMimeTypes} + /// Used when a user inserts image-based content through the device keyboard, + /// currently only used on Android. + /// + /// The passed list of strings will determine which MIME types are allowed to + /// be inserted via the device keyboard. + /// + /// The default mime types are given by [kDefaultContentInsertionMimeTypes]. + /// These are all the mime types that are able to be handled and inserted + /// from keyboards. + /// + /// This field cannot be an empty list. + /// + /// {@tool dartpad} + /// This example shows how to limit image insertion to specific file types. + /// + /// ** See code in examples/api/lib/widgets/editable_text/editable_text.on_content_inserted.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * <https://developer.android.com/guide/topics/text/image-keyboard> + /// {@endtemplate} + final List<String> allowedMimeTypes; +} + +// A time-value pair that represents a key frame in an animation. +class _KeyFrame { + const _KeyFrame(this.time, this.value); + // Values extracted from iOS 15.4 UIKit. + static const List<_KeyFrame> iOSBlinkingCaretKeyFrames = <_KeyFrame>[ + _KeyFrame(0, 1), // 0 + _KeyFrame(0.5, 1), // 1 + _KeyFrame(0.5375, 0.75), // 2 + _KeyFrame(0.575, 0.5), // 3 + _KeyFrame(0.6125, 0.25), // 4 + _KeyFrame(0.65, 0), // 5 + _KeyFrame(0.85, 0), // 6 + _KeyFrame(0.8875, 0.25), // 7 + _KeyFrame(0.925, 0.5), // 8 + _KeyFrame(0.9625, 0.75), // 9 + _KeyFrame(1, 1), // 10 + ]; + + // The timing, in seconds, of the specified animation `value`. + final double time; + final double value; +} + +class _DiscreteKeyFrameSimulation extends Simulation { + _DiscreteKeyFrameSimulation.iOSBlinkingCaret() : this._(_KeyFrame.iOSBlinkingCaretKeyFrames, 1); + _DiscreteKeyFrameSimulation._(this._keyFrames, this.maxDuration) + : assert(_keyFrames.isNotEmpty), + assert(_keyFrames.last.time <= maxDuration), + assert(() { + for (int i = 0; i < _keyFrames.length -1; i += 1) { + if (_keyFrames[i].time > _keyFrames[i + 1].time) { + return false; + } + } + return true; + }(), 'The key frame sequence must be sorted by time.'); + + final double maxDuration; + + final List<_KeyFrame> _keyFrames; + + @override + double dx(double time) => 0; + + @override + bool isDone(double time) => time >= maxDuration; + + // The index of the KeyFrame corresponds to the most recent input `time`. + int _lastKeyFrameIndex = 0; + + @override + double x(double time) { + final int length = _keyFrames.length; + + // Perform a linear search in the sorted key frame list, starting from the + // last key frame found, since the input `time` usually monotonically + // increases by a small amount. + int searchIndex; + final int endIndex; + if (_keyFrames[_lastKeyFrameIndex].time > time) { + // The simulation may have restarted. Search within the index range + // [0, _lastKeyFrameIndex). + searchIndex = 0; + endIndex = _lastKeyFrameIndex; + } else { + searchIndex = _lastKeyFrameIndex; + endIndex = length; + } + + // Find the target key frame. Don't have to check (endIndex - 1): if + // (endIndex - 2) doesn't work we'll have to pick (endIndex - 1) anyways. + while (searchIndex < endIndex - 1) { + assert(_keyFrames[searchIndex].time <= time); + final _KeyFrame next = _keyFrames[searchIndex + 1]; + if (time < next.time) { + break; + } + searchIndex += 1; + } + + _lastKeyFrameIndex = searchIndex; + return _keyFrames[_lastKeyFrameIndex].value; + } +} + +/// A basic text input field. +/// +/// This widget interacts with the [TextInput] service to let the user edit the +/// text it contains. It also provides scrolling, selection, and cursor +/// movement. +/// +/// The [EditableText] widget is a low-level widget that is intended as a +/// building block for custom widget sets. For a complete user experience, +/// consider using a [TextField] or [CupertinoTextField]. +/// +/// ## Handling User Input +/// +/// Currently the user may change the text this widget contains via keyboard or +/// the text selection menu. When the user inserted or deleted text, you will be +/// notified of the change and get a chance to modify the new text value: +/// +/// * The [inputFormatters] will be first applied to the user input. +/// +/// * The [controller]'s [TextEditingController.value] will be updated with the +/// formatted result, and the [controller]'s listeners will be notified. +/// +/// * The [onChanged] callback, if specified, will be called last. +/// +/// ## Input Actions +/// +/// A [TextInputAction] can be provided to customize the appearance of the +/// action button on the soft keyboard for Android and iOS. The default action +/// is [TextInputAction.done]. +/// +/// Many [TextInputAction]s are common between Android and iOS. However, if a +/// [textInputAction] is provided that is not supported by the current +/// platform in debug mode, an error will be thrown when the corresponding +/// EditableText receives focus. For example, providing iOS's "emergencyCall" +/// action when running on an Android device will result in an error when in +/// debug mode. In release mode, incompatible [TextInputAction]s are replaced +/// either with "unspecified" on Android, or "default" on iOS. Appropriate +/// [textInputAction]s can be chosen by checking the current platform and then +/// selecting the appropriate action. +/// +/// {@template flutter.widgets.EditableText.lifeCycle} +/// ## Lifecycle +/// +/// Upon completion of editing, like pressing the "done" button on the keyboard, +/// two actions take place: +/// +/// 1st: Editing is finalized. The default behavior of this step includes +/// an invocation of [onChanged]. That default behavior can be overridden. +/// See [onEditingComplete] for details. +/// +/// 2nd: [onSubmitted] is invoked with the user's input value. +/// +/// [onSubmitted] can be used to manually move focus to another input widget +/// when a user finishes with the currently focused input widget. +/// +/// When the widget has focus, it will prevent itself from disposing via +/// [AutomaticKeepAliveClientMixin.wantKeepAlive] in order to avoid losing the +/// selection. Removing the focus will allow it to be disposed. +/// {@endtemplate} +/// +/// Rather than using this widget directly, consider using [TextField], which +/// is a full-featured, material-design text input field with placeholder text, +/// labels, and [Form] integration. +/// +/// ## Text Editing [Intent]s and Their Default [Action]s +/// +/// This widget provides default [Action]s for handling common text editing +/// [Intent]s such as deleting, copying and pasting in the text field. These +/// [Action]s can be directly invoked using [Actions.invoke] or the +/// [Actions.maybeInvoke] method. The default text editing keyboard [Shortcuts] +/// also use these [Intent]s and [Action]s to perform the text editing +/// operations they are bound to. +/// +/// The default handling of a specific [Intent] can be overridden by placing an +/// [Actions] widget above this widget. See the [Action] class and the +/// [Action.overridable] constructor for more information on how a pre-defined +/// overridable [Action] can be overridden. +/// +/// ### Intents for Deleting Text and Their Default Behavior +/// +/// | **Intent Class** | **Default Behavior when there's selected text** | **Default Behavior when there is a [caret](https://en.wikipedia.org/wiki/Caret_navigation) (The selection is [TextSelection.collapsed])** | +/// | :------------------------------- | :--------------------------------------------------- | :----------------------------------------------------------------------- | +/// | [DeleteCharacterIntent] | Deletes the selected text | Deletes the user-perceived character before or after the caret location. | +/// | [DeleteToNextWordBoundaryIntent] | Deletes the selected text and the word before/after the selection's [TextSelection.extent] position | Deletes from the caret location to the previous or the next word boundary | +/// | [DeleteToLineBreakIntent] | Deletes the selected text, and deletes to the start/end of the line from the selection's [TextSelection.extent] position | Deletes from the caret location to the logical start or end of the current line | +/// +/// ### Intents for Moving the [Caret](https://en.wikipedia.org/wiki/Caret_navigation) +/// +/// | **Intent Class** | **Default Behavior when there's selected text** | **Default Behavior when there is a caret ([TextSelection.collapsed])** | +/// | :----------------------------------------------------------------------------------- | :--------------------------------------------------------------- | :---------------------------------------------------------------------- | +/// | [ExtendSelectionByCharacterIntent](`collapseSelection: true`) | Collapses the selection to the logical start/end of the selection | Moves the caret past the user-perceived character before or after the current caret location. | +/// | [ExtendSelectionToNextWordBoundaryIntent](`collapseSelection: true`) | Collapses the selection to the word boundary before/after the selection's [TextSelection.extent] position | Moves the caret to the previous/next word boundary. | +/// | [ExtendSelectionToNextWordBoundaryOrCaretLocationIntent](`collapseSelection: true`) | Collapses the selection to the word boundary before/after the selection's [TextSelection.extent] position, or [TextSelection.base], whichever is closest in the given direction | Moves the caret to the previous/next word boundary. | +/// | [ExtendSelectionToLineBreakIntent](`collapseSelection: true`) | Collapses the selection to the start/end of the line at the selection's [TextSelection.extent] position | Moves the caret to the start/end of the current line .| +/// | [ExtendSelectionVerticallyToAdjacentLineIntent](`collapseSelection: true`) | Collapses the selection to the position closest to the selection's [TextSelection.extent], on the previous/next adjacent line | Moves the caret to the closest position on the previous/next adjacent line. | +/// | [ExtendSelectionVerticallyToAdjacentPageIntent](`collapseSelection: true`) | Collapses the selection to the position closest to the selection's [TextSelection.extent], on the previous/next adjacent page | Moves the caret to the closest position on the previous/next adjacent page. | +/// | [ExtendSelectionToDocumentBoundaryIntent](`collapseSelection: true`) | Collapses the selection to the start/end of the document | Moves the caret to the start/end of the document. | +/// +/// #### Intents for Extending the Selection +/// +/// | **Intent Class** | **Default Behavior when there's selected text** | **Default Behavior when there is a caret ([TextSelection.collapsed])** | +/// | :----------------------------------------------------------------------------------- | :--------------------------------------------------------------- | :---------------------------------------------------------------------- | +/// | [ExtendSelectionByCharacterIntent](`collapseSelection: false`) | Moves the selection's [TextSelection.extent] past the user-perceived character before/after it | +/// | [ExtendSelectionToNextWordBoundaryIntent](`collapseSelection: false`) | Moves the selection's [TextSelection.extent] to the previous/next word boundary | +/// | [ExtendSelectionToNextWordBoundaryOrCaretLocationIntent](`collapseSelection: false`) | Moves the selection's [TextSelection.extent] to the previous/next word boundary, or [TextSelection.base] whichever is closest in the given direction | Moves the selection's [TextSelection.extent] to the previous/next word boundary. | +/// | [ExtendSelectionToLineBreakIntent](`collapseSelection: false`) | Moves the selection's [TextSelection.extent] to the start/end of the line | +/// | [ExtendSelectionVerticallyToAdjacentLineIntent](`collapseSelection: false`) | Moves the selection's [TextSelection.extent] to the closest position on the previous/next adjacent line | +/// | [ExtendSelectionVerticallyToAdjacentPageIntent](`collapseSelection: false`) | Moves the selection's [TextSelection.extent] to the closest position on the previous/next adjacent page | +/// | [ExtendSelectionToDocumentBoundaryIntent](`collapseSelection: false`) | Moves the selection's [TextSelection.extent] to the start/end of the document | +/// | [SelectAllTextIntent] | Selects the entire document | +/// +/// ### Other Intents +/// +/// | **Intent Class** | **Default Behavior** | +/// | :-------------------------------------- | :--------------------------------------------------- | +/// | [DoNothingAndStopPropagationTextIntent] | Does nothing in the input field, and prevents the key event from further propagating in the widget tree. | +/// | [ReplaceTextIntent] | Replaces the current [TextEditingValue] in the input field's [TextEditingController], and triggers all related user callbacks and [TextInputFormatter]s. | +/// | [UpdateSelectionIntent] | Updates the current selection in the input field's [TextEditingController], and triggers the [onSelectionChanged] callback. | +/// | [CopySelectionTextIntent] | Copies or cuts the selected text into the clipboard | +/// | [PasteTextIntent] | Inserts the current text in the clipboard after the caret location, or replaces the selected text if the selection is not collapsed. | +/// +/// ## Gesture Events Handling +/// +/// When [rendererIgnoresPointer] is false (the default), this widget provides +/// rudimentary, platform-agnostic gesture handling for user actions such as +/// tapping, long-pressing, and scrolling. +/// +/// To provide more complete gesture handling, including double-click to select +/// a word, drag selection, and platform-specific handling of gestures such as +/// long presses, consider setting [rendererIgnoresPointer] to true and using +/// [TextSelectionGestureDetectorBuilder]. +/// +/// {@template flutter.widgets.editableText.showCaretOnScreen} +/// ## Keep the caret visible when focused +/// +/// When focused, this widget will make attempts to keep the text area and its +/// caret (even when [showCursor] is `false`) visible, on these occasions: +/// +/// * When the user focuses this text field and it is not [readOnly]. +/// * When the user changes the selection of the text field, or changes the +/// text when the text field is not [readOnly]. +/// * When the virtual keyboard pops up. +/// {@endtemplate} +/// +/// {@template flutter.widgets.editableText.accessibility} +/// ## Troubleshooting Common Accessibility Issues +/// +/// ### Customizing User Input Accessibility Announcements +/// +/// To customize user input accessibility announcements triggered by text +/// changes, use [SemanticsService.announce] to make the desired +/// accessibility announcement. +/// +/// On iOS, the on-screen keyboard may announce the most recent input +/// incorrectly when a [TextInputFormatter] inserts a thousands separator to +/// a currency value text field. The following example demonstrates how to +/// suppress the default accessibility announcements by always announcing +/// the content of the text field as a US currency value (the `\$` inserts +/// a dollar sign, the `$newText` interpolates the `newText` variable): +/// +/// ```dart +/// onChanged: (String newText) { +/// if (newText.isNotEmpty) { +/// SemanticsService.announce('\$$newText', Directionality.of(context)); +/// } +/// } +/// ``` +/// +/// {@endtemplate} +/// +/// See also: +/// +/// * [TextField], which is a full-featured, material-design text input field +/// with placeholder text, labels, and [Form] integration. +class EditableText extends StatefulWidget { + /// Creates a basic text input control. + /// + /// The [maxLines] property can be set to null to remove the restriction on + /// the number of lines. By default, it is one, meaning this is a single-line + /// text field. [maxLines] must be null or greater than zero. + /// + /// If [keyboardType] is not set or is null, its value will be inferred from + /// [autofillHints], if [autofillHints] is not empty. Otherwise it defaults to + /// [TextInputType.text] if [maxLines] is exactly one, and + /// [TextInputType.multiline] if [maxLines] is null or greater than one. + /// + /// The text cursor is not shown if [showCursor] is false or if [showCursor] + /// is null (the default) and [readOnly] is true. + EditableText({ + super.key, + required this.controller, + required this.focusNode, + this.readOnly = false, + this.obscuringCharacter = '•', + this.obscureText = false, + this.autocorrect = true, + SmartDashesType? smartDashesType, + SmartQuotesType? smartQuotesType, + this.enableSuggestions = true, + required this.style, + StrutStyle? strutStyle, + required this.cursorColor, + required this.backgroundCursorColor, + this.textAlign = TextAlign.start, + this.textDirection, + this.locale, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + this.textScaleFactor, + this.textScaler, + this.maxLines = 1, + this.minLines, + this.expands = false, + this.forceLine = true, + this.textHeightBehavior, + this.textWidthBasis = TextWidthBasis.parent, + this.autofocus = false, + bool? showCursor, + this.showSelectionHandles = false, + this.selectionColor, + this.selectionControls, + TextInputType? keyboardType, + this.textInputAction, + this.textCapitalization = TextCapitalization.none, + this.onChanged, + this.onEditingComplete, + this.onSubmitted, + this.onAppPrivateCommand, + this.onSelectionChanged, + this.onSelectionHandleTapped, + this.onTapOutside, + List<TextInputFormatter>? inputFormatters, + this.mouseCursor, + this.rendererIgnoresPointer = false, + this.cursorWidth = 2.0, + this.cursorHeight, + this.cursorRadius, + this.cursorOpacityAnimates = false, + this.cursorOffset, + this.paintCursorAboveText = false, + this.selectionHeightStyle = ui.BoxHeightStyle.tight, + this.selectionWidthStyle = ui.BoxWidthStyle.tight, + this.scrollPadding = const EdgeInsets.all(20.0), + this.keyboardAppearance = Brightness.light, + this.dragStartBehavior = DragStartBehavior.start, + bool? enableInteractiveSelection, + this.scrollController, + this.scrollPhysics, + this.autocorrectionTextRectColor, + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + ToolbarOptions? toolbarOptions, + this.autofillHints = const <String>[], + this.autofillClient, + this.clipBehavior = Clip.hardEdge, + this.restorationId, + this.scrollBehavior, + this.scribbleEnabled = true, + this.enableIMEPersonalizedLearning = true, + this.contentInsertionConfiguration, + this.contextMenuBuilder, + this.spellCheckConfiguration, + this.magnifierConfiguration = TextMagnifierConfiguration.disabled, + this.undoController, + }) : assert(obscuringCharacter.length == 1), + smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), + smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), + assert(minLines == null || minLines > 0), + assert( + (maxLines == null) || (minLines == null) || (maxLines >= minLines), + "minLines can't be greater than maxLines", + ), + assert( + !expands || (maxLines == null && minLines == null), + 'minLines and maxLines must be null when expands is true.', + ), + assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'), + enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText), + toolbarOptions = selectionControls is TextSelectionHandleControls && toolbarOptions == null ? ToolbarOptions.empty : toolbarOptions ?? + (obscureText + ? (readOnly + // No point in even offering "Select All" in a read-only obscured + // field. + ? ToolbarOptions.empty + // Writable, but obscured. + : const ToolbarOptions( + selectAll: true, + paste: true, + )) + : (readOnly + // Read-only, not obscured. + ? const ToolbarOptions( + selectAll: true, + copy: true, + ) + // Writable, not obscured. + : const ToolbarOptions( + copy: true, + cut: true, + selectAll: true, + paste: true, + ))), + assert( + spellCheckConfiguration == null || + spellCheckConfiguration == const SpellCheckConfiguration.disabled() || + spellCheckConfiguration.misspelledTextStyle != null, + 'spellCheckConfiguration must specify a misspelledTextStyle if spell check behavior is desired', + ), + _strutStyle = strutStyle, + keyboardType = keyboardType ?? _inferKeyboardType(autofillHints: autofillHints, maxLines: maxLines), + inputFormatters = maxLines == 1 + ? <TextInputFormatter>[ + FilteringTextInputFormatter.singleLineFormatter, + ...inputFormatters ?? const Iterable<TextInputFormatter>.empty(), + ] + : inputFormatters, + showCursor = showCursor ?? !readOnly; + + /// Controls the text being edited. + final TextEditingController controller; + + /// Controls whether this widget has keyboard focus. + final FocusNode focusNode; + + /// {@template flutter.widgets.editableText.obscuringCharacter} + /// Character used for obscuring text if [obscureText] is true. + /// + /// Must be only a single character. + /// + /// Defaults to the character U+2022 BULLET (•). + /// {@endtemplate} + final String obscuringCharacter; + + /// {@template flutter.widgets.editableText.obscureText} + /// Whether to hide the text being edited (e.g., for passwords). + /// + /// When this is set to true, all the characters in the text field are + /// replaced by [obscuringCharacter], and the text in the field cannot be + /// copied with copy or cut. If [readOnly] is also true, then the text cannot + /// be selected. + /// + /// Defaults to false. + /// {@endtemplate} + final bool obscureText; + + /// {@macro dart.ui.textHeightBehavior} + final TextHeightBehavior? textHeightBehavior; + + /// {@macro flutter.painting.textPainter.textWidthBasis} + final TextWidthBasis textWidthBasis; + + /// {@template flutter.widgets.editableText.readOnly} + /// Whether the text can be changed. + /// + /// When this is set to true, the text cannot be modified + /// by any shortcut or keyboard operation. The text is still selectable. + /// + /// Defaults to false. + /// {@endtemplate} + final bool readOnly; + + /// Whether the text will take the full width regardless of the text width. + /// + /// When this is set to false, the width will be based on text width, which + /// will also be affected by [textWidthBasis]. + /// + /// Defaults to true. + /// + /// See also: + /// + /// * [textWidthBasis], which controls the calculation of text width. + final bool forceLine; + + /// Configuration of toolbar options. + /// + /// By default, all options are enabled. If [readOnly] is true, paste and cut + /// will be disabled regardless. If [obscureText] is true, cut and copy will + /// be disabled regardless. If [readOnly] and [obscureText] are both true, + /// select all will also be disabled. + final ToolbarOptions toolbarOptions; + + /// Whether to show selection handles. + /// + /// When a selection is active, there will be two handles at each side of + /// boundary, or one handle if the selection is collapsed. The handles can be + /// dragged to adjust the selection. + /// + /// See also: + /// + /// * [showCursor], which controls the visibility of the cursor. + final bool showSelectionHandles; + + /// {@template flutter.widgets.editableText.showCursor} + /// Whether to show cursor. + /// + /// The cursor refers to the blinking caret when the [EditableText] is focused. + /// {@endtemplate} + /// + /// See also: + /// + /// * [showSelectionHandles], which controls the visibility of the selection handles. + final bool showCursor; + + /// {@template flutter.widgets.editableText.autocorrect} + /// Whether to enable autocorrection. + /// + /// Defaults to true. + /// {@endtemplate} + final bool autocorrect; + + /// {@macro flutter.services.TextInputConfiguration.smartDashesType} + final SmartDashesType smartDashesType; + + /// {@macro flutter.services.TextInputConfiguration.smartQuotesType} + final SmartQuotesType smartQuotesType; + + /// {@macro flutter.services.TextInputConfiguration.enableSuggestions} + final bool enableSuggestions; + + /// The text style to use for the editable text. + final TextStyle style; + + /// Controls the undo state of the current editable text. + /// + /// If null, this widget will create its own [UndoHistoryController]. + final UndoHistoryController? undoController; + + /// {@template flutter.widgets.editableText.strutStyle} + /// The strut style used for the vertical layout. + /// + /// [StrutStyle] is used to establish a predictable vertical layout. + /// Since fonts may vary depending on user input and due to font + /// fallback, [StrutStyle.forceStrutHeight] is enabled by default + /// to lock all lines to the height of the base [TextStyle], provided by + /// [style]. This ensures the typed text fits within the allotted space. + /// + /// If null, the strut used will inherit values from the [style] and will + /// have [StrutStyle.forceStrutHeight] set to true. When no [style] is + /// passed, the theme's [TextStyle] will be used to generate [strutStyle] + /// instead. + /// + /// To disable strut-based vertical alignment and allow dynamic vertical + /// layout based on the glyphs typed, use [StrutStyle.disabled]. + /// + /// Flutter's strut is based on [typesetting strut](https://en.wikipedia.org/wiki/Strut_(typesetting)) + /// and CSS's [line-height](https://www.w3.org/TR/CSS2/visudet.html#line-height). + /// {@endtemplate} + /// + /// Within editable text and text fields, [StrutStyle] will not use its standalone + /// default values, and will instead inherit omitted/null properties from the + /// [TextStyle] instead. See [StrutStyle.inheritFromTextStyle]. + StrutStyle get strutStyle { + if (_strutStyle == null) { + return StrutStyle.fromTextStyle(style, forceStrutHeight: true); + } + return _strutStyle.inheritFromTextStyle(style); + } + final StrutStyle? _strutStyle; + + /// {@template flutter.widgets.editableText.textAlign} + /// How the text should be aligned horizontally. + /// + /// Defaults to [TextAlign.start]. + /// {@endtemplate} + final TextAlign textAlign; + + /// {@template flutter.widgets.editableText.textDirection} + /// The directionality of the text. + /// + /// This decides how [textAlign] values like [TextAlign.start] and + /// [TextAlign.end] are interpreted. + /// + /// This is also used to disambiguate how to render bidirectional text. For + /// example, if the text is an English phrase followed by a Hebrew phrase, + /// in a [TextDirection.ltr] context the English phrase will be on the left + /// and the Hebrew phrase to its right, while in a [TextDirection.rtl] + /// context, the English phrase will be on the right and the Hebrew phrase on + /// its left. + /// + /// Defaults to the ambient [Directionality], if any. + /// {@endtemplate} + final TextDirection? textDirection; + + /// {@template flutter.widgets.editableText.textCapitalization} + /// Configures how the platform keyboard will select an uppercase or + /// lowercase keyboard. + /// + /// Only supports text keyboards, other keyboard types will ignore this + /// configuration. Capitalization is locale-aware. + /// + /// Defaults to [TextCapitalization.none]. + /// + /// See also: + /// + /// * [TextCapitalization], for a description of each capitalization behavior. + /// + /// {@endtemplate} + final TextCapitalization textCapitalization; + + /// Used to select a font when the same Unicode character can + /// be rendered differently, depending on the locale. + /// + /// It's rarely necessary to set this property. By default its value + /// is inherited from the enclosing app with `Localizations.localeOf(context)`. + /// + /// See [RenderEditable.locale] for more information. + final Locale? locale; + + /// {@template flutter.widgets.editableText.textScaleFactor} + /// Deprecated. Will be removed in a future version of Flutter. Use + /// [textScaler] instead. + /// + /// The number of font pixels for each logical pixel. + /// + /// For example, if the text scale factor is 1.5, text will be 50% larger than + /// the specified font size. + /// + /// Defaults to the [MediaQueryData.textScaleFactor] obtained from the ambient + /// [MediaQuery], or 1.0 if there is no [MediaQuery] in scope. + /// {@endtemplate} + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + final double? textScaleFactor; + + /// {@macro flutter.painting.textPainter.textScaler} + final TextScaler? textScaler; + + /// The color to use when painting the cursor. + final Color cursorColor; + + /// The color to use when painting the autocorrection Rect. + /// + /// For [CupertinoTextField]s, the value is set to the ambient + /// [CupertinoThemeData.primaryColor] with 20% opacity. For [TextField]s, the + /// value is null on non-iOS platforms and the same color used in [CupertinoTextField] + /// on iOS. + /// + /// Currently the autocorrection Rect only appears on iOS. + /// + /// Defaults to null, which disables autocorrection Rect painting. + final Color? autocorrectionTextRectColor; + + /// The color to use when painting the background cursor aligned with the text + /// while rendering the floating cursor. + /// + /// Typically this would be set to [CupertinoColors.inactiveGray]. + final Color backgroundCursorColor; + + /// {@template flutter.widgets.editableText.maxLines} + /// The maximum number of lines to show at one time, wrapping if necessary. + /// + /// This affects the height of the field itself and does not limit the number + /// of lines that can be entered into the field. + /// + /// If this is 1 (the default), the text will not wrap, but will scroll + /// horizontally instead. + /// + /// If this is null, there is no limit to the number of lines, and the text + /// container will start with enough vertical space for one line and + /// automatically grow to accommodate additional lines as they are entered, up + /// to the height of its constraints. + /// + /// If this is not null, the value must be greater than zero, and it will lock + /// the input to the given number of lines and take up enough horizontal space + /// to accommodate that number of lines. Setting [minLines] as well allows the + /// input to grow and shrink between the indicated range. + /// + /// The full set of behaviors possible with [minLines] and [maxLines] are as + /// follows. These examples apply equally to [TextField], [TextFormField], + /// [CupertinoTextField], and [EditableText]. + /// + /// Input that occupies a single line and scrolls horizontally as needed. + /// ```dart + /// const TextField() + /// ``` + /// + /// Input whose height grows from one line up to as many lines as needed for + /// the text that was entered. If a height limit is imposed by its parent, it + /// will scroll vertically when its height reaches that limit. + /// ```dart + /// const TextField(maxLines: null) + /// ``` + /// + /// The input's height is large enough for the given number of lines. If + /// additional lines are entered the input scrolls vertically. + /// ```dart + /// const TextField(maxLines: 2) + /// ``` + /// + /// Input whose height grows with content between a min and max. An infinite + /// max is possible with `maxLines: null`. + /// ```dart + /// const TextField(minLines: 2, maxLines: 4) + /// ``` + /// + /// See also: + /// + /// * [minLines], which sets the minimum number of lines visible. + /// {@endtemplate} + /// * [expands], which determines whether the field should fill the height of + /// its parent. + final int? maxLines; + + /// {@template flutter.widgets.editableText.minLines} + /// The minimum number of lines to occupy when the content spans fewer lines. + /// + /// This affects the height of the field itself and does not limit the number + /// of lines that can be entered into the field. + /// + /// If this is null (default), text container starts with enough vertical space + /// for one line and grows to accommodate additional lines as they are entered. + /// + /// This can be used in combination with [maxLines] for a varying set of behaviors. + /// + /// If the value is set, it must be greater than zero. If the value is greater + /// than 1, [maxLines] should also be set to either null or greater than + /// this value. + /// + /// When [maxLines] is set as well, the height will grow between the indicated + /// range of lines. When [maxLines] is null, it will grow as high as needed, + /// starting from [minLines]. + /// + /// A few examples of behaviors possible with [minLines] and [maxLines] are as follows. + /// These apply equally to [TextField], [TextFormField], [CupertinoTextField], + /// and [EditableText]. + /// + /// Input that always occupies at least 2 lines and has an infinite max. + /// Expands vertically as needed. + /// ```dart + /// TextField(minLines: 2) + /// ``` + /// + /// Input whose height starts from 2 lines and grows up to 4 lines at which + /// point the height limit is reached. If additional lines are entered it will + /// scroll vertically. + /// ```dart + /// const TextField(minLines:2, maxLines: 4) + /// ``` + /// + /// Defaults to null. + /// + /// See also: + /// + /// * [maxLines], which sets the maximum number of lines visible, and has + /// several examples of how minLines and maxLines interact to produce + /// various behaviors. + /// {@endtemplate} + /// * [expands], which determines whether the field should fill the height of + /// its parent. + final int? minLines; + + /// {@template flutter.widgets.editableText.expands} + /// Whether this widget's height will be sized to fill its parent. + /// + /// If set to true and wrapped in a parent widget like [Expanded] or + /// [SizedBox], the input will expand to fill the parent. + /// + /// [maxLines] and [minLines] must both be null when this is set to true, + /// otherwise an error is thrown. + /// + /// Defaults to false. + /// + /// See the examples in [maxLines] for the complete picture of how [maxLines], + /// [minLines], and [expands] interact to produce various behaviors. + /// + /// Input that matches the height of its parent: + /// ```dart + /// const Expanded( + /// child: TextField(maxLines: null, expands: true), + /// ) + /// ``` + /// {@endtemplate} + final bool expands; + + /// {@template flutter.widgets.editableText.autofocus} + /// Whether this text field should focus itself if nothing else is already + /// focused. + /// + /// If true, the keyboard will open as soon as this text field obtains focus. + /// Otherwise, the keyboard is only shown after the user taps the text field. + /// + /// Defaults to false. + /// {@endtemplate} + // See https://github.com/flutter/flutter/issues/7035 for the rationale for this + // keyboard behavior. + final bool autofocus; + + /// The color to use when painting the selection. + /// + /// If this property is null, this widget gets the selection color from the + /// [DefaultSelectionStyle]. + /// + /// For [CupertinoTextField]s, the value is set to the ambient + /// [CupertinoThemeData.primaryColor] with 20% opacity. For [TextField]s, the + /// value is set to the ambient [TextSelectionThemeData.selectionColor]. + final Color? selectionColor; + + /// {@template flutter.widgets.editableText.selectionControls} + /// Optional delegate for building the text selection handles. + /// + /// Historically, this field also controlled the toolbar. This is now handled + /// by [contextMenuBuilder] instead. However, for backwards compatibility, when + /// [selectionControls] is set to an object that does not mix in + /// [TextSelectionHandleControls], [contextMenuBuilder] is ignored and the + /// [TextSelectionControls.buildToolbar] method is used instead. + /// {@endtemplate} + /// + /// See also: + /// + /// * [CupertinoTextField], which wraps an [EditableText] and which shows the + /// selection toolbar upon user events that are appropriate on the iOS + /// platform. + /// * [TextField], a Material Design themed wrapper of [EditableText], which + /// shows the selection toolbar upon appropriate user events based on the + /// user's platform set in [ThemeData.platform]. + final TextSelectionControls? selectionControls; + + /// {@template flutter.widgets.editableText.keyboardType} + /// The type of keyboard to use for editing the text. + /// + /// Defaults to [TextInputType.text] if [maxLines] is one and + /// [TextInputType.multiline] otherwise. + /// {@endtemplate} + final TextInputType keyboardType; + + /// The type of action button to use with the soft keyboard. + final TextInputAction? textInputAction; + + /// {@template flutter.widgets.editableText.onChanged} + /// Called when the user initiates a change to the TextField's + /// value: when they have inserted or deleted text. + /// + /// This callback doesn't run when the TextField's text is changed + /// programmatically, via the TextField's [controller]. Typically it + /// isn't necessary to be notified of such changes, since they're + /// initiated by the app itself. + /// + /// To be notified of all changes to the TextField's text, cursor, + /// and selection, one can add a listener to its [controller] with + /// [TextEditingController.addListener]. + /// + /// [onChanged] is called before [onSubmitted] when user indicates completion + /// of editing, such as when pressing the "done" button on the keyboard. That + /// default behavior can be overridden. See [onEditingComplete] for details. + /// + /// {@tool dartpad} + /// This example shows how onChanged could be used to check the TextField's + /// current value each time the user inserts or deletes a character. + /// + /// ** See code in examples/api/lib/widgets/editable_text/editable_text.on_changed.0.dart ** + /// {@end-tool} + /// {@endtemplate} + /// + /// ## Handling emojis and other complex characters + /// {@template flutter.widgets.EditableText.onChanged} + /// It's important to always use + /// [characters](https://pub.dev/packages/characters) when dealing with user + /// input text that may contain complex characters. This will ensure that + /// extended grapheme clusters and surrogate pairs are treated as single + /// characters, as they appear to the user. + /// + /// For example, when finding the length of some user input, use + /// `string.characters.length`. Do NOT use `string.length` or even + /// `string.runes.length`. For the complex character "👨‍👩‍👦", this + /// appears to the user as a single character, and `string.characters.length` + /// intuitively returns 1. On the other hand, `string.length` returns 8, and + /// `string.runes.length` returns 5! + /// {@endtemplate} + /// + /// See also: + /// + /// * [inputFormatters], which are called before [onChanged] + /// runs and can validate and change ("format") the input value. + /// * [onEditingComplete], [onSubmitted], [onSelectionChanged]: + /// which are more specialized input change notifications. + /// * [TextEditingController], which implements the [Listenable] interface + /// and notifies its listeners on [TextEditingValue] changes. + final ValueChanged<String>? onChanged; + + /// {@template flutter.widgets.editableText.onEditingComplete} + /// Called when the user submits editable content (e.g., user presses the "done" + /// button on the keyboard). + /// + /// The default implementation of [onEditingComplete] executes 2 different + /// behaviors based on the situation: + /// + /// - When a completion action is pressed, such as "done", "go", "send", or + /// "search", the user's content is submitted to the [controller] and then + /// focus is given up. + /// + /// - When a non-completion action is pressed, such as "next" or "previous", + /// the user's content is submitted to the [controller], but focus is not + /// given up because developers may want to immediately move focus to + /// another input widget within [onSubmitted]. + /// + /// Providing [onEditingComplete] prevents the aforementioned default behavior. + /// {@endtemplate} + final VoidCallback? onEditingComplete; + + /// {@template flutter.widgets.editableText.onSubmitted} + /// Called when the user indicates that they are done editing the text in the + /// field. + /// + /// By default, [onSubmitted] is called after [onChanged] when the user + /// has finalized editing; or, if the default behavior has been overridden, + /// after [onEditingComplete]. See [onEditingComplete] for details. + /// + /// ## Testing + /// The following is the recommended way to trigger [onSubmitted] in a test: + /// + /// ```dart + /// await tester.testTextInput.receiveAction(TextInputAction.done); + /// ``` + /// + /// Sending a `LogicalKeyboardKey.enter` via `tester.sendKeyEvent` will not + /// trigger [onSubmitted]. This is because on a real device, the engine + /// translates the enter key to a done action, but `tester.sendKeyEvent` sends + /// the key to the framework only. + /// {@endtemplate} + final ValueChanged<String>? onSubmitted; + + /// {@template flutter.widgets.editableText.onAppPrivateCommand} + /// This is used to receive a private command from the input method. + /// + /// Called when the result of [TextInputClient.performPrivateCommand] is + /// received. + /// + /// This can be used to provide domain-specific features that are only known + /// between certain input methods and their clients. + /// + /// See also: + /// * [performPrivateCommand](https://developer.android.com/reference/android/view/inputmethod/InputConnection#performPrivateCommand\(java.lang.String,%20android.os.Bundle\)), + /// which is the Android documentation for performPrivateCommand, used to + /// send a command from the input method. + /// * [sendAppPrivateCommand](https://developer.android.com/reference/android/view/inputmethod/InputMethodManager#sendAppPrivateCommand), + /// which is the Android documentation for sendAppPrivateCommand, used to + /// send a command to the input method. + /// {@endtemplate} + final AppPrivateCommandCallback? onAppPrivateCommand; + + /// {@template flutter.widgets.editableText.onSelectionChanged} + /// Called when the user changes the selection of text (including the cursor + /// location). + /// {@endtemplate} + final SelectionChangedCallback? onSelectionChanged; + + /// {@macro flutter.widgets.SelectionOverlay.onSelectionHandleTapped} + final VoidCallback? onSelectionHandleTapped; + + /// {@template flutter.widgets.editableText.onTapOutside} + /// Called for each tap that occurs outside of the[TextFieldTapRegion] group + /// when the text field is focused. + /// + /// If this is null, [FocusNode.unfocus] will be called on the [focusNode] for + /// this text field when a [PointerDownEvent] is received on another part of + /// the UI. However, it will not unfocus as a result of mobile application + /// touch events (which does not include mouse clicks), to conform with the + /// platform conventions. To change this behavior, a callback may be set here + /// that operates differently from the default. + /// + /// When adding additional controls to a text field (for example, a spinner, a + /// button that copies the selected text, or modifies formatting), it is + /// helpful if tapping on that control doesn't unfocus the text field. In + /// order for an external widget to be considered as part of the text field + /// for the purposes of tapping "outside" of the field, wrap the control in a + /// [TextFieldTapRegion]. + /// + /// The [PointerDownEvent] passed to the function is the event that caused the + /// notification. It is possible that the event may occur outside of the + /// immediate bounding box defined by the text field, although it will be + /// within the bounding box of a [TextFieldTapRegion] member. + /// {@endtemplate} + /// + /// {@tool dartpad} + /// This example shows how to use a `TextFieldTapRegion` to wrap a set of + /// "spinner" buttons that increment and decrement a value in the [TextField] + /// without causing the text field to lose keyboard focus. + /// + /// This example includes a generic `SpinnerField<T>` class that you can copy + /// into your own project and customize. + /// + /// ** See code in examples/api/lib/widgets/tap_region/text_field_tap_region.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [TapRegion] for how the region group is determined. + final TapRegionCallback? onTapOutside; + + /// {@template flutter.widgets.editableText.inputFormatters} + /// Optional input validation and formatting overrides. + /// + /// Formatters are run in the provided order when the user changes the text + /// this widget contains. When this parameter changes, the new formatters will + /// not be applied until the next time the user inserts or deletes text. + /// Similar to the [onChanged] callback, formatters don't run when the text is + /// changed programmatically via [controller]. + /// + /// See also: + /// + /// * [TextEditingController], which implements the [Listenable] interface + /// and notifies its listeners on [TextEditingValue] changes. + /// {@endtemplate} + final List<TextInputFormatter>? inputFormatters; + + /// The cursor for a mouse pointer when it enters or is hovering over the + /// widget. + /// + /// If this property is null, [SystemMouseCursors.text] will be used. + /// + /// The [mouseCursor] is the only property of [EditableText] that controls the + /// appearance of the mouse pointer. All other properties related to "cursor" + /// stands for the text cursor, which is usually a blinking vertical line at + /// the editing position. + final MouseCursor? mouseCursor; + + /// Whether the caller will provide gesture handling (true), or if the + /// [EditableText] is expected to handle basic gestures (false). + /// + /// When this is false, the [EditableText] (or more specifically, the + /// [RenderEditable]) enables some rudimentary gestures (tap to position the + /// cursor, long-press to select all, and some scrolling behavior). + /// + /// These behaviors are sufficient for debugging purposes but are inadequate + /// for user-facing applications. To enable platform-specific behaviors, use a + /// [TextSelectionGestureDetectorBuilder] to wrap the [EditableText], and set + /// [rendererIgnoresPointer] to true. + /// + /// When [rendererIgnoresPointer] is true true, the [RenderEditable] created + /// by this widget will not handle pointer events. + /// + /// This property is false by default. + /// + /// See also: + /// + /// * [RenderEditable.ignorePointer], which implements this feature. + /// * [TextSelectionGestureDetectorBuilder], which implements platform-specific + /// gestures and behaviors. + final bool rendererIgnoresPointer; + + /// {@template flutter.widgets.editableText.cursorWidth} + /// How thick the cursor will be. + /// + /// Defaults to 2.0. + /// + /// The cursor will draw under the text. The cursor width will extend + /// to the right of the boundary between characters for left-to-right text + /// and to the left for right-to-left text. This corresponds to extending + /// downstream relative to the selected position. Negative values may be used + /// to reverse this behavior. + /// {@endtemplate} + final double cursorWidth; + + /// {@template flutter.widgets.editableText.cursorHeight} + /// How tall the cursor will be. + /// + /// If this property is null, [RenderEditable.preferredLineHeight] will be used. + /// {@endtemplate} + final double? cursorHeight; + + /// {@template flutter.widgets.editableText.cursorRadius} + /// How rounded the corners of the cursor should be. + /// + /// By default, the cursor has no radius. + /// {@endtemplate} + final Radius? cursorRadius; + + /// {@template flutter.widgets.editableText.cursorOpacityAnimates} + /// Whether the cursor will animate from fully transparent to fully opaque + /// during each cursor blink. + /// + /// By default, the cursor opacity will animate on iOS platforms and will not + /// animate on Android platforms. + /// {@endtemplate} + final bool cursorOpacityAnimates; + + ///{@macro flutter.rendering.RenderEditable.cursorOffset} + final Offset? cursorOffset; + + ///{@macro flutter.rendering.RenderEditable.paintCursorAboveText} + final bool paintCursorAboveText; + + /// Controls how tall the selection highlight boxes are computed to be. + /// + /// See [ui.BoxHeightStyle] for details on available styles. + final ui.BoxHeightStyle selectionHeightStyle; + + /// Controls how wide the selection highlight boxes are computed to be. + /// + /// See [ui.BoxWidthStyle] for details on available styles. + final ui.BoxWidthStyle selectionWidthStyle; + + /// The appearance of the keyboard. + /// + /// This setting is only honored on iOS devices. + /// + /// Defaults to [Brightness.light]. + final Brightness keyboardAppearance; + + /// {@template flutter.widgets.editableText.scrollPadding} + /// Configures padding to edges surrounding a [Scrollable] when the Textfield scrolls into view. + /// + /// When this widget receives focus and is not completely visible (for example scrolled partially + /// off the screen or overlapped by the keyboard) + /// then it will attempt to make itself visible by scrolling a surrounding [Scrollable], if one is present. + /// This value controls how far from the edges of a [Scrollable] the TextField will be positioned after the scroll. + /// + /// Defaults to EdgeInsets.all(20.0). + /// {@endtemplate} + final EdgeInsets scrollPadding; + + /// {@template flutter.widgets.editableText.enableInteractiveSelection} + /// Whether to enable user interface affordances for changing the + /// text selection. + /// + /// For example, setting this to true will enable features such as + /// long-pressing the TextField to select text and show the + /// cut/copy/paste menu, and tapping to move the text caret. + /// + /// When this is false, the text selection cannot be adjusted by + /// the user, text cannot be copied, and the user cannot paste into + /// the text field from the clipboard. + /// + /// Defaults to true. + /// {@endtemplate} + final bool enableInteractiveSelection; + + /// Setting this property to true makes the cursor stop blinking or fading + /// on and off once the cursor appears on focus. This property is useful for + /// testing purposes. + /// + /// It does not affect the necessity to focus the EditableText for the cursor + /// to appear in the first place. + /// + /// Defaults to false, resulting in a typical blinking cursor. + static bool debugDeterministicCursor = false; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@template flutter.widgets.editableText.scrollController} + /// The [ScrollController] to use when vertically scrolling the input. + /// + /// If null, it will instantiate a new ScrollController. + /// + /// See [Scrollable.controller]. + /// {@endtemplate} + final ScrollController? scrollController; + + /// {@template flutter.widgets.editableText.scrollPhysics} + /// The [ScrollPhysics] to use when vertically scrolling the input. + /// + /// If not specified, it will behave according to the current platform. + /// + /// See [Scrollable.physics]. + /// {@endtemplate} + /// + /// If an explicit [ScrollBehavior] is provided to [scrollBehavior], the + /// [ScrollPhysics] provided by that behavior will take precedence after + /// [scrollPhysics]. + final ScrollPhysics? scrollPhysics; + + /// {@template flutter.widgets.editableText.scribbleEnabled} + /// Whether iOS 14 Scribble features are enabled for this widget. + /// + /// Only available on iPads. + /// + /// Defaults to true. + /// {@endtemplate} + final bool scribbleEnabled; + + /// {@template flutter.widgets.editableText.selectionEnabled} + /// Same as [enableInteractiveSelection]. + /// + /// This getter exists primarily for consistency with + /// [RenderEditable.selectionEnabled]. + /// {@endtemplate} + bool get selectionEnabled => enableInteractiveSelection; + + /// {@template flutter.widgets.editableText.autofillHints} + /// A list of strings that helps the autofill service identify the type of this + /// text input. + /// + /// When set to null, this text input will not send its autofill information + /// to the platform, preventing it from participating in autofills triggered + /// by a different [AutofillClient], even if they're in the same + /// [AutofillScope]. Additionally, on Android and web, setting this to null + /// will disable autofill for this text field. + /// + /// The minimum platform SDK version that supports Autofill is API level 26 + /// for Android, and iOS 10.0 for iOS. + /// + /// Defaults to an empty list. + /// + /// ### Setting up iOS autofill: + /// + /// To provide the best user experience and ensure your app fully supports + /// password autofill on iOS, follow these steps: + /// + /// * Set up your iOS app's + /// [associated domains](https://developer.apple.com/documentation/safariservices/supporting_associated_domains_in_your_app). + /// * Some autofill hints only work with specific [keyboardType]s. For example, + /// [AutofillHints.name] requires [TextInputType.name] and [AutofillHints.email] + /// works only with [TextInputType.emailAddress]. Make sure the input field has a + /// compatible [keyboardType]. Empirically, [TextInputType.name] works well + /// with many autofill hints that are predefined on iOS. + /// + /// ### Troubleshooting Autofill + /// + /// Autofill service providers rely heavily on [autofillHints]. Make sure the + /// entries in [autofillHints] are supported by the autofill service currently + /// in use (the name of the service can typically be found in your mobile + /// device's system settings). + /// + /// #### Autofill UI refuses to show up when I tap on the text field + /// + /// Check the device's system settings and make sure autofill is turned on, + /// and there are available credentials stored in the autofill service. + /// + /// * iOS password autofill: Go to Settings -> Password, turn on "Autofill + /// Passwords", and add new passwords for testing by pressing the top right + /// "+" button. Use an arbitrary "website" if you don't have associated + /// domains set up for your app. As long as there's at least one password + /// stored, you should be able to see a key-shaped icon in the quick type + /// bar on the software keyboard, when a password related field is focused. + /// + /// * iOS contact information autofill: iOS seems to pull contact info from + /// the Apple ID currently associated with the device. Go to Settings -> + /// Apple ID (usually the first entry, or "Sign in to your iPhone" if you + /// haven't set up one on the device), and fill out the relevant fields. If + /// you wish to test more contact info types, try adding them in Contacts -> + /// My Card. + /// + /// * Android autofill: Go to Settings -> System -> Languages & input -> + /// Autofill service. Enable the autofill service of your choice, and make + /// sure there are available credentials associated with your app. + /// + /// #### I called `TextInput.finishAutofillContext` but the autofill save + /// prompt isn't showing + /// + /// * iOS: iOS may not show a prompt or any other visual indication when it + /// saves user password. Go to Settings -> Password and check if your new + /// password is saved. Neither saving password nor auto-generating strong + /// password works without properly setting up associated domains in your + /// app. To set up associated domains, follow the instructions in + /// <https://developer.apple.com/documentation/safariservices/supporting_associated_domains_in_your_app>. + /// + /// {@endtemplate} + /// {@macro flutter.services.AutofillConfiguration.autofillHints} + final Iterable<String>? autofillHints; + + /// The [AutofillClient] that controls this input field's autofill behavior. + /// + /// When null, this widget's [EditableTextState] will be used as the + /// [AutofillClient]. This property may override [autofillHints]. + final AutofillClient? autofillClient; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// Restoration ID to save and restore the scroll offset of the + /// [EditableText]. + /// + /// If a restoration id is provided, the [EditableText] will persist its + /// current scroll offset and restore it during state restoration. + /// + /// The scroll offset is persisted in a [RestorationBucket] claimed from + /// the surrounding [RestorationScope] using the provided restoration ID. + /// + /// Persisting and restoring the content of the [EditableText] is the + /// responsibility of the owner of the [controller], who may use a + /// [RestorableTextEditingController] for that purpose. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + final String? restorationId; + + /// {@template flutter.widgets.shadow.scrollBehavior} + /// A [ScrollBehavior] that will be applied to this widget individually. + /// + /// Defaults to null, wherein the inherited [ScrollBehavior] is copied and + /// modified to alter the viewport decoration, like [Scrollbar]s. + /// {@endtemplate} + /// + /// [ScrollBehavior]s also provide [ScrollPhysics]. If an explicit + /// [ScrollPhysics] is provided in [scrollPhysics], it will take precedence, + /// followed by [scrollBehavior], and then the inherited ancestor + /// [ScrollBehavior]. + /// + /// The [ScrollBehavior] of the inherited [ScrollConfiguration] will be + /// modified by default to only apply a [Scrollbar] if [maxLines] is greater + /// than 1. + final ScrollBehavior? scrollBehavior; + + /// {@macro flutter.services.TextInputConfiguration.enableIMEPersonalizedLearning} + final bool enableIMEPersonalizedLearning; + + /// {@template flutter.widgets.editableText.contentInsertionConfiguration} + /// Configuration of handler for media content inserted via the system input + /// method. + /// + /// Defaults to null in which case media content insertion will be disabled, + /// and the system will display a message informing the user that the text field + /// does not support inserting media content. + /// + /// Set [ContentInsertionConfiguration.onContentInserted] to provide a handler. + /// Additionally, set [ContentInsertionConfiguration.allowedMimeTypes] + /// to limit the allowable mime types for inserted content. + /// + /// {@tool dartpad} + /// + /// This example shows how to access the data for inserted content in your + /// `TextField`. + /// + /// ** See code in examples/api/lib/widgets/editable_text/editable_text.on_content_inserted.0.dart ** + /// {@end-tool} + /// + /// If [contentInsertionConfiguration] is not provided, by default + /// an empty list of mime types will be sent to the Flutter Engine. + /// A handler function must be provided in order to customize the allowable + /// mime types for inserted content. + /// + /// If rich content is inserted without a handler, the system will display + /// a message informing the user that the current text input does not support + /// inserting rich content. + /// {@endtemplate} + final ContentInsertionConfiguration? contentInsertionConfiguration; + + /// {@template flutter.widgets.EditableText.contextMenuBuilder} + /// Builds the text selection toolbar when requested by the user. + /// + /// `primaryAnchor` is the desired anchor position for the context menu, while + /// `secondaryAnchor` is the fallback location if the menu doesn't fit. + /// + /// `buttonItems` represents the buttons that would be built by default for + /// this widget. + /// + /// For backwards compatibility, when [selectionControls] is set to an object + /// that does not mix in [TextSelectionHandleControls], [contextMenuBuilder] + /// is ignored and the [TextSelectionControls.buildToolbar] method is used + /// instead. + /// + /// {@tool dartpad} + /// This example shows how to customize the menu, in this case by keeping the + /// default buttons for the platform but modifying their appearance. + /// + /// ** See code in examples/api/lib/material/context_menu/editable_text_toolbar_builder.0.dart ** + /// {@end-tool} + /// + /// {@tool dartpad} + /// This example shows how to show a custom button only when an email address + /// is currently selected. + /// + /// ** See code in examples/api/lib/material/context_menu/editable_text_toolbar_builder.1.dart ** + /// {@end-tool} + /// + /// See also: + /// * [AdaptiveTextSelectionToolbar], which builds the default text selection + /// toolbar for the current platform, but allows customization of the + /// buttons. + /// * [AdaptiveTextSelectionToolbar.getAdaptiveButtons], which builds the + /// button Widgets for the current platform given + /// [ContextMenuButtonItem]s. + /// * [BrowserContextMenu], which allows the browser's context menu on web + /// to be disabled and Flutter-rendered context menus to appear. + /// {@endtemplate} + /// + /// If not provided, no context menu will be shown. + final EditableTextContextMenuBuilder? contextMenuBuilder; + + /// {@template flutter.widgets.EditableText.spellCheckConfiguration} + /// Configuration that details how spell check should be performed. + /// + /// Specifies the [SpellCheckService] used to spell check text input and the + /// [TextStyle] used to style text with misspelled words. + /// + /// If the [SpellCheckService] is left null, spell check is disabled by + /// default unless the [DefaultSpellCheckService] is supported, in which case + /// it is used. It is currently supported only on Android and iOS. + /// + /// If this configuration is left null, then spell check is disabled by default. + /// {@endtemplate} + final SpellCheckConfiguration? spellCheckConfiguration; + + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.intro} + /// + /// {@macro flutter.widgets.magnifier.intro} + /// + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.details} + final TextMagnifierConfiguration magnifierConfiguration; + + bool get _userSelectionEnabled => enableInteractiveSelection && (!readOnly || !obscureText); + + /// Returns the [ContextMenuButtonItem]s representing the buttons in this + /// platform's default selection menu for an editable field. + /// + /// For example, [EditableText] uses this to generate the default buttons for + /// its context menu. + /// + /// See also: + /// + /// * [EditableTextState.contextMenuButtonItems], which gives the + /// [ContextMenuButtonItem]s for a specific EditableText. + /// * [SelectableRegion.getSelectableButtonItems], which performs a similar + /// role but for content that is selectable but not editable. + /// * [AdaptiveTextSelectionToolbar], which builds the toolbar itself, and can + /// take a list of [ContextMenuButtonItem]s with + /// [AdaptiveTextSelectionToolbar.buttonItems]. + /// * [AdaptiveTextSelectionToolbar.getAdaptiveButtons], which builds the button + /// Widgets for the current platform given [ContextMenuButtonItem]s. + static List<ContextMenuButtonItem> getEditableButtonItems({ + required final ClipboardStatus? clipboardStatus, + required final VoidCallback? onCopy, + required final VoidCallback? onCut, + required final VoidCallback? onPaste, + required final VoidCallback? onSelectAll, + required final VoidCallback? onLookUp, + required final VoidCallback? onSearchWeb, + required final VoidCallback? onShare, + required final VoidCallback? onLiveTextInput, + }) { + final List<ContextMenuButtonItem> resultButtonItem = <ContextMenuButtonItem>[]; + + // Configure button items with clipboard. + if (onPaste == null || clipboardStatus != ClipboardStatus.unknown) { + // If the paste button is enabled, don't render anything until the state + // of the clipboard is known, since it's used to determine if paste is + // shown. + + // On Android, the share button is before the select all button. + final bool showShareBeforeSelectAll = defaultTargetPlatform == TargetPlatform.android; + + resultButtonItem.addAll(<ContextMenuButtonItem>[ + if (onCut != null) + ContextMenuButtonItem( + onPressed: onCut, + type: ContextMenuButtonType.cut, + ), + if (onCopy != null) + ContextMenuButtonItem( + onPressed: onCopy, + type: ContextMenuButtonType.copy, + ), + if (onPaste != null) + ContextMenuButtonItem( + onPressed: onPaste, + type: ContextMenuButtonType.paste, + ), + if (onShare != null && showShareBeforeSelectAll) + ContextMenuButtonItem( + onPressed: onShare, + type: ContextMenuButtonType.share, + ), + if (onSelectAll != null) + ContextMenuButtonItem( + onPressed: onSelectAll, + type: ContextMenuButtonType.selectAll, + ), + if (onLookUp != null) + ContextMenuButtonItem( + onPressed: onLookUp, + type: ContextMenuButtonType.lookUp, + ), + if (onSearchWeb != null) + ContextMenuButtonItem( + onPressed: onSearchWeb, + type: ContextMenuButtonType.searchWeb, + ), + if (onShare != null && !showShareBeforeSelectAll) + ContextMenuButtonItem( + onPressed: onShare, + type: ContextMenuButtonType.share, + ), + ]); + } + + // Config button items with Live Text. + if (onLiveTextInput != null) { + resultButtonItem.add(ContextMenuButtonItem( + onPressed: onLiveTextInput, + type: ContextMenuButtonType.liveTextInput, + )); + } + + return resultButtonItem; + } + + // Infer the keyboard type of an `EditableText` if it's not specified. + static TextInputType _inferKeyboardType({ + required Iterable<String>? autofillHints, + required int? maxLines, + }) { + if (autofillHints == null || autofillHints.isEmpty) { + return maxLines == 1 ? TextInputType.text : TextInputType.multiline; + } + + final String effectiveHint = autofillHints.first; + + // On iOS oftentimes specifying a text content type is not enough to qualify + // the input field for autofill. The keyboard type also needs to be compatible + // with the content type. To get autofill to work by default on EditableText, + // the keyboard type inference on iOS is done differently from other platforms. + // + // The entries with "autofill not working" comments are the iOS text content + // types that should work with the specified keyboard type but won't trigger + // (even within a native app). Tested on iOS 13.5. + if (!kIsWeb) { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + const Map<String, TextInputType> iOSKeyboardType = <String, TextInputType> { + AutofillHints.addressCity : TextInputType.name, + AutofillHints.addressCityAndState : TextInputType.name, // Autofill not working. + AutofillHints.addressState : TextInputType.name, + AutofillHints.countryName : TextInputType.name, + AutofillHints.creditCardNumber : TextInputType.number, // Couldn't test. + AutofillHints.email : TextInputType.emailAddress, + AutofillHints.familyName : TextInputType.name, + AutofillHints.fullStreetAddress : TextInputType.name, + AutofillHints.givenName : TextInputType.name, + AutofillHints.jobTitle : TextInputType.name, // Autofill not working. + AutofillHints.location : TextInputType.name, // Autofill not working. + AutofillHints.middleName : TextInputType.name, // Autofill not working. + AutofillHints.name : TextInputType.name, + AutofillHints.namePrefix : TextInputType.name, // Autofill not working. + AutofillHints.nameSuffix : TextInputType.name, // Autofill not working. + AutofillHints.newPassword : TextInputType.text, + AutofillHints.newUsername : TextInputType.text, + AutofillHints.nickname : TextInputType.name, // Autofill not working. + AutofillHints.oneTimeCode : TextInputType.number, + AutofillHints.organizationName : TextInputType.text, // Autofill not working. + AutofillHints.password : TextInputType.text, + AutofillHints.postalCode : TextInputType.name, + AutofillHints.streetAddressLine1 : TextInputType.name, + AutofillHints.streetAddressLine2 : TextInputType.name, // Autofill not working. + AutofillHints.sublocality : TextInputType.name, // Autofill not working. + AutofillHints.telephoneNumber : TextInputType.name, + AutofillHints.url : TextInputType.url, // Autofill not working. + AutofillHints.username : TextInputType.text, + }; + + final TextInputType? keyboardType = iOSKeyboardType[effectiveHint]; + if (keyboardType != null) { + return keyboardType; + } + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + break; + } + } + + if (maxLines != 1) { + return TextInputType.multiline; + } + + const Map<String, TextInputType> inferKeyboardType = <String, TextInputType> { + AutofillHints.addressCity : TextInputType.streetAddress, + AutofillHints.addressCityAndState : TextInputType.streetAddress, + AutofillHints.addressState : TextInputType.streetAddress, + AutofillHints.birthday : TextInputType.datetime, + AutofillHints.birthdayDay : TextInputType.datetime, + AutofillHints.birthdayMonth : TextInputType.datetime, + AutofillHints.birthdayYear : TextInputType.datetime, + AutofillHints.countryCode : TextInputType.number, + AutofillHints.countryName : TextInputType.text, + AutofillHints.creditCardExpirationDate : TextInputType.datetime, + AutofillHints.creditCardExpirationDay : TextInputType.datetime, + AutofillHints.creditCardExpirationMonth : TextInputType.datetime, + AutofillHints.creditCardExpirationYear : TextInputType.datetime, + AutofillHints.creditCardFamilyName : TextInputType.name, + AutofillHints.creditCardGivenName : TextInputType.name, + AutofillHints.creditCardMiddleName : TextInputType.name, + AutofillHints.creditCardName : TextInputType.name, + AutofillHints.creditCardNumber : TextInputType.number, + AutofillHints.creditCardSecurityCode : TextInputType.number, + AutofillHints.creditCardType : TextInputType.text, + AutofillHints.email : TextInputType.emailAddress, + AutofillHints.familyName : TextInputType.name, + AutofillHints.fullStreetAddress : TextInputType.streetAddress, + AutofillHints.gender : TextInputType.text, + AutofillHints.givenName : TextInputType.name, + AutofillHints.impp : TextInputType.url, + AutofillHints.jobTitle : TextInputType.text, + AutofillHints.language : TextInputType.text, + AutofillHints.location : TextInputType.streetAddress, + AutofillHints.middleInitial : TextInputType.name, + AutofillHints.middleName : TextInputType.name, + AutofillHints.name : TextInputType.name, + AutofillHints.namePrefix : TextInputType.name, + AutofillHints.nameSuffix : TextInputType.name, + AutofillHints.newPassword : TextInputType.text, + AutofillHints.newUsername : TextInputType.text, + AutofillHints.nickname : TextInputType.text, + AutofillHints.oneTimeCode : TextInputType.text, + AutofillHints.organizationName : TextInputType.text, + AutofillHints.password : TextInputType.text, + AutofillHints.photo : TextInputType.text, + AutofillHints.postalAddress : TextInputType.streetAddress, + AutofillHints.postalAddressExtended : TextInputType.streetAddress, + AutofillHints.postalAddressExtendedPostalCode : TextInputType.number, + AutofillHints.postalCode : TextInputType.number, + AutofillHints.streetAddressLevel1 : TextInputType.streetAddress, + AutofillHints.streetAddressLevel2 : TextInputType.streetAddress, + AutofillHints.streetAddressLevel3 : TextInputType.streetAddress, + AutofillHints.streetAddressLevel4 : TextInputType.streetAddress, + AutofillHints.streetAddressLine1 : TextInputType.streetAddress, + AutofillHints.streetAddressLine2 : TextInputType.streetAddress, + AutofillHints.streetAddressLine3 : TextInputType.streetAddress, + AutofillHints.sublocality : TextInputType.streetAddress, + AutofillHints.telephoneNumber : TextInputType.phone, + AutofillHints.telephoneNumberAreaCode : TextInputType.phone, + AutofillHints.telephoneNumberCountryCode : TextInputType.phone, + AutofillHints.telephoneNumberDevice : TextInputType.phone, + AutofillHints.telephoneNumberExtension : TextInputType.phone, + AutofillHints.telephoneNumberLocal : TextInputType.phone, + AutofillHints.telephoneNumberLocalPrefix : TextInputType.phone, + AutofillHints.telephoneNumberLocalSuffix : TextInputType.phone, + AutofillHints.telephoneNumberNational : TextInputType.phone, + AutofillHints.transactionAmount : TextInputType.numberWithOptions(decimal: true), + AutofillHints.transactionCurrency : TextInputType.text, + AutofillHints.url : TextInputType.url, + AutofillHints.username : TextInputType.text, + }; + + return inferKeyboardType[effectiveHint] ?? TextInputType.text; + } + + @override + EditableTextState createState() => EditableTextState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<TextEditingController>('controller', controller)); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode)); + properties.add(DiagnosticsProperty<bool>('obscureText', obscureText, defaultValue: false)); + properties.add(DiagnosticsProperty<bool>('readOnly', readOnly, defaultValue: false)); + properties.add(DiagnosticsProperty<bool>('autocorrect', autocorrect, defaultValue: true)); + properties.add(EnumProperty<SmartDashesType>('smartDashesType', smartDashesType, defaultValue: obscureText ? SmartDashesType.disabled : SmartDashesType.enabled)); + properties.add(EnumProperty<SmartQuotesType>('smartQuotesType', smartQuotesType, defaultValue: obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled)); + properties.add(DiagnosticsProperty<bool>('enableSuggestions', enableSuggestions, defaultValue: true)); + style.debugFillProperties(properties); + properties.add(EnumProperty<TextAlign>('textAlign', textAlign, defaultValue: null)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null)); + properties.add(DiagnosticsProperty<TextScaler>('textScaler', textScaler, defaultValue: null)); + properties.add(IntProperty('maxLines', maxLines, defaultValue: 1)); + properties.add(IntProperty('minLines', minLines, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false)); + properties.add(DiagnosticsProperty<bool>('autofocus', autofocus, defaultValue: false)); + properties.add(DiagnosticsProperty<TextInputType>('keyboardType', keyboardType, defaultValue: null)); + properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null)); + properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null)); + properties.add(DiagnosticsProperty<Iterable<String>>('autofillHints', autofillHints, defaultValue: null)); + properties.add(DiagnosticsProperty<TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('scribbleEnabled', scribbleEnabled, defaultValue: true)); + properties.add(DiagnosticsProperty<bool>('enableIMEPersonalizedLearning', enableIMEPersonalizedLearning, defaultValue: true)); + properties.add(DiagnosticsProperty<bool>('enableInteractiveSelection', enableInteractiveSelection, defaultValue: true)); + properties.add(DiagnosticsProperty<UndoHistoryController>('undoController', undoController, defaultValue: null)); + properties.add(DiagnosticsProperty<SpellCheckConfiguration>('spellCheckConfiguration', spellCheckConfiguration, defaultValue: null)); + properties.add(DiagnosticsProperty<List<String>>('contentCommitMimeTypes', contentInsertionConfiguration?.allowedMimeTypes ?? const <String>[], defaultValue: contentInsertionConfiguration == null ? const <String>[] : kDefaultContentInsertionMimeTypes)); + } +} + +/// State for a [EditableText]. +class EditableTextState extends State<EditableText> with AutomaticKeepAliveClientMixin<EditableText>, WidgetsBindingObserver, TickerProviderStateMixin<EditableText>, TextSelectionDelegate, TextInputClient implements AutofillClient { + Timer? _cursorTimer; + AnimationController get _cursorBlinkOpacityController { + return _backingCursorBlinkOpacityController ??= AnimationController( + vsync: this, + )..addListener(_onCursorColorTick); + } + AnimationController? _backingCursorBlinkOpacityController; + late final Simulation _iosBlinkCursorSimulation = _DiscreteKeyFrameSimulation.iOSBlinkingCaret(); + + final ValueNotifier<bool> _cursorVisibilityNotifier = ValueNotifier<bool>(true); + final GlobalKey _editableKey = GlobalKey(); + + /// Detects whether the clipboard can paste. + final ClipboardStatusNotifier clipboardStatus = kIsWeb + // Web browsers will show a permission dialog when Clipboard.hasStrings is + // called. In an EditableText, this will happen before the paste button is + // clicked, often before the context menu is even shown. To avoid this + // poor user experience, always show the paste button on web. + ? _WebClipboardStatusNotifier() + : ClipboardStatusNotifier(); + + /// Detects whether the Live Text input is enabled. + /// + /// See also: + /// * [LiveText], where the availability of Live Text input can be obtained. + final LiveTextInputStatusNotifier? _liveTextInputStatus = + kIsWeb ? null : LiveTextInputStatusNotifier(); + + TextInputConnection? _textInputConnection; + bool get _hasInputConnection => _textInputConnection?.attached ?? false; + + TextSelectionOverlay? _selectionOverlay; + + final GlobalKey _scrollableKey = GlobalKey(); + ScrollController? _internalScrollController; + ScrollController get _scrollController => widget.scrollController ?? (_internalScrollController ??= ScrollController()); + + final LayerLink _toolbarLayerLink = LayerLink(); + final LayerLink _startHandleLayerLink = LayerLink(); + final LayerLink _endHandleLayerLink = LayerLink(); + + bool _didAutoFocus = false; + + AutofillGroupState? _currentAutofillScope; + @override + AutofillScope? get currentAutofillScope => _currentAutofillScope; + + AutofillClient get _effectiveAutofillClient => widget.autofillClient ?? this; + + late SpellCheckConfiguration _spellCheckConfiguration; + late TextStyle _style; + + /// Configuration that determines how spell check will be performed. + /// + /// If possible, this configuration will contain a default for the + /// [SpellCheckService] if it is not otherwise specified. + /// + /// See also: + /// * [DefaultSpellCheckService], the spell check service used by default. + @visibleForTesting + SpellCheckConfiguration get spellCheckConfiguration => _spellCheckConfiguration; + + /// Whether or not spell check is enabled. + /// + /// Spell check is enabled when a [SpellCheckConfiguration] has been specified + /// for the widget. + bool get spellCheckEnabled => _spellCheckConfiguration.spellCheckEnabled; + + /// The most up-to-date spell check results for text input. + /// + /// These results will be updated via calls to spell check through a + /// [SpellCheckService] and used by this widget to build the [TextSpan] tree + /// for text input and menus for replacement suggestions of misspelled words. + SpellCheckResults? spellCheckResults; + + bool get _spellCheckResultsReceived => spellCheckEnabled && spellCheckResults != null && spellCheckResults!.suggestionSpans.isNotEmpty; + + /// The text processing service used to retrieve the native text processing actions. + final ProcessTextService _processTextService = DefaultProcessTextService(); + + /// The list of native text processing actions provided by the engine. + final List<ProcessTextAction> _processTextActions = <ProcessTextAction>[]; + + /// Whether to create an input connection with the platform for text editing + /// or not. + /// + /// Read-only input fields do not need a connection with the platform since + /// there's no need for text editing capabilities (e.g. virtual keyboard). + /// + /// On the web, we always need a connection because we want some browser + /// functionalities to continue to work on read-only input fields like: + /// + /// - Relevant context menu. + /// - cmd/ctrl+c shortcut to copy. + /// - cmd/ctrl+a to select all. + /// - Changing the selection using a physical keyboard. + bool get _shouldCreateInputConnection => kIsWeb || !widget.readOnly; + + // The time it takes for the floating cursor to snap to the text aligned + // cursor position after the user has finished placing it. + static const Duration _floatingCursorResetTime = Duration(milliseconds: 125); + + AnimationController? _floatingCursorResetController; + + Orientation? _lastOrientation; + + @override + bool get wantKeepAlive => widget.focusNode.hasFocus; + + Color get _cursorColor { + final double effectiveOpacity = math.min(widget.cursorColor.alpha / 255.0, _cursorBlinkOpacityController.value); + return widget.cursorColor.withOpacity(effectiveOpacity); + } + + @override + bool get cutEnabled { + if (widget.selectionControls is! TextSelectionHandleControls) { + return widget.toolbarOptions.cut && !widget.readOnly && !widget.obscureText; + } + return !widget.readOnly + && !widget.obscureText + && !textEditingValue.selection.isCollapsed; + } + + @override + bool get copyEnabled { + if (widget.selectionControls is! TextSelectionHandleControls) { + return widget.toolbarOptions.copy && !widget.obscureText; + } + return !widget.obscureText + && !textEditingValue.selection.isCollapsed; + } + + @override + bool get pasteEnabled { + if (widget.selectionControls is! TextSelectionHandleControls) { + return widget.toolbarOptions.paste && !widget.readOnly; + } + return !widget.readOnly + && (clipboardStatus.value == ClipboardStatus.pasteable); + } + + @override + bool get selectAllEnabled { + if (widget.selectionControls is! TextSelectionHandleControls) { + return widget.toolbarOptions.selectAll && (!widget.readOnly || !widget.obscureText) && widget.enableInteractiveSelection; + } + + if (!widget.enableInteractiveSelection + || (widget.readOnly + && widget.obscureText)) { + return false; + } + + switch (defaultTargetPlatform) { + case TargetPlatform.macOS: + return false; + case TargetPlatform.iOS: + return textEditingValue.text.isNotEmpty + && textEditingValue.selection.isCollapsed; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return textEditingValue.text.isNotEmpty + && !(textEditingValue.selection.start == 0 + && textEditingValue.selection.end == textEditingValue.text.length); + } + } + + @override + bool get lookUpEnabled { + if (defaultTargetPlatform != TargetPlatform.iOS) { + return false; + } + return !widget.obscureText + && !textEditingValue.selection.isCollapsed + && textEditingValue.selection.textInside(textEditingValue.text).trim() != ''; + } + + @override + bool get searchWebEnabled { + if (defaultTargetPlatform != TargetPlatform.iOS) { + return false; + } + + return !widget.obscureText + && !textEditingValue.selection.isCollapsed + && textEditingValue.selection.textInside(textEditingValue.text).trim() != ''; + } + + @override + bool get shareEnabled { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + return !widget.obscureText + && !textEditingValue.selection.isCollapsed + && textEditingValue.selection.textInside(textEditingValue.text).trim() != ''; + case TargetPlatform.macOS: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return false; + } + } + + @override + bool get liveTextInputEnabled { + return _liveTextInputStatus?.value == LiveTextInputStatus.enabled && + !widget.obscureText && + !widget.readOnly && + textEditingValue.selection.isCollapsed; + } + + void _onChangedClipboardStatus() { + setState(() { + // Inform the widget that the value of clipboardStatus has changed. + }); + } + + void _onChangedLiveTextInputStatus() { + setState(() { + // Inform the widget that the value of liveTextInputStatus has changed. + }); + } + + TextEditingValue get _textEditingValueforTextLayoutMetrics { + final Widget? editableWidget =_editableKey.currentContext?.widget; + if (editableWidget is! _Editable) { + throw StateError('_Editable must be mounted.'); + } + return editableWidget.value; + } + + /// Copy current selection to [Clipboard]. + @override + void copySelection(SelectionChangedCause cause) { + final TextSelection selection = textEditingValue.selection; + if (selection.isCollapsed || widget.obscureText) { + return; + } + final String text = textEditingValue.text; + Clipboard.setData(ClipboardData(text: selection.textInside(text))); + if (cause == SelectionChangedCause.toolbar) { + bringIntoView(textEditingValue.selection.extent); + hideToolbar(false); + + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + break; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + // Collapse the selection and hide the toolbar and handles. + userUpdateTextEditingValue( + TextEditingValue( + text: textEditingValue.text, + selection: TextSelection.collapsed(offset: textEditingValue.selection.end), + ), + SelectionChangedCause.toolbar, + ); + } + } + clipboardStatus.update(); + } + + /// Cut current selection to [Clipboard]. + @override + void cutSelection(SelectionChangedCause cause) { + if (widget.readOnly || widget.obscureText) { + return; + } + final TextSelection selection = textEditingValue.selection; + final String text = textEditingValue.text; + if (selection.isCollapsed) { + return; + } + Clipboard.setData(ClipboardData(text: selection.textInside(text))); + _replaceText(ReplaceTextIntent(textEditingValue, '', selection, cause)); + if (cause == SelectionChangedCause.toolbar) { + // Schedule a call to bringIntoView() after renderEditable updates. + SchedulerBinding.instance.addPostFrameCallback((_) { + if (mounted) { + bringIntoView(textEditingValue.selection.extent); + } + }, debugLabel: 'EditableText.bringSelectionIntoView'); + hideToolbar(); + } + clipboardStatus.update(); + } + + bool get _allowPaste { + return !widget.readOnly && textEditingValue.selection.isValid; + } + + /// Paste text from [Clipboard]. + @override + Future<void> pasteText(SelectionChangedCause cause) async { + if (!_allowPaste) { + return; + } + // Snapshot the input before using `await`. + // See https://github.com/flutter/flutter/issues/11427 + final ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain); + if (data == null) { + return; + } + _pasteText(cause, data.text!); + } + + void _pasteText(SelectionChangedCause cause, String text) { + if (!_allowPaste) { + return; + } + + // After the paste, the cursor should be collapsed and located after the + // pasted content. + final TextSelection selection = textEditingValue.selection; + final int lastSelectionIndex = math.max(selection.baseOffset, selection.extentOffset); + final TextEditingValue collapsedTextEditingValue = textEditingValue.copyWith( + selection: TextSelection.collapsed(offset: lastSelectionIndex), + ); + + userUpdateTextEditingValue( + collapsedTextEditingValue.replaced(selection, text), + cause, + ); + if (cause == SelectionChangedCause.toolbar) { + // Schedule a call to bringIntoView() after renderEditable updates. + SchedulerBinding.instance.addPostFrameCallback((_) { + if (mounted) { + bringIntoView(textEditingValue.selection.extent); + } + }, debugLabel: 'EditableText.bringSelectionIntoView'); + hideToolbar(); + } + } + + /// Select the entire text value. + @override + void selectAll(SelectionChangedCause cause) { + if (widget.readOnly && widget.obscureText) { + // If we can't modify it, and we can't copy it, there's no point in + // selecting it. + return; + } + userUpdateTextEditingValue( + textEditingValue.copyWith( + selection: TextSelection(baseOffset: 0, extentOffset: textEditingValue.text.length), + ), + cause, + ); + + if (cause == SelectionChangedCause.toolbar) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + case TargetPlatform.fuchsia: + break; + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + hideToolbar(); + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + bringIntoView(textEditingValue.selection.extent); + case TargetPlatform.macOS: + case TargetPlatform.iOS: + break; + } + } + } + + /// Look up the current selection, + /// as in the "Look Up" edit menu button on iOS. + /// + /// Currently this is only implemented for iOS. + /// + /// Throws an error if the selection is empty or collapsed. + Future<void> lookUpSelection(SelectionChangedCause cause) async { + assert(!widget.obscureText); + + final String text = textEditingValue.selection.textInside(textEditingValue.text); + if (widget.obscureText || text.isEmpty) { + return; + } + await SystemChannels.platform.invokeMethod( + 'LookUp.invoke', + text, + ); + } + + /// Launch a web search on the current selection, + /// as in the "Search Web" edit menu button on iOS. + /// + /// Currently this is only implemented for iOS. + /// + /// When 'obscureText' is true or the selection is empty, + /// this function will not do anything + Future<void> searchWebForSelection(SelectionChangedCause cause) async { + assert(!widget.obscureText); + if (widget.obscureText) { + return; + } + + final String text = textEditingValue.selection.textInside(textEditingValue.text); + if (text.isNotEmpty) { + await SystemChannels.platform.invokeMethod( + 'SearchWeb.invoke', + text, + ); + } + } + + /// Launch the share interface for the current selection, + /// as in the "Share..." edit menu button on iOS. + /// + /// Currently this is only implemented for iOS and Android. + /// + /// When 'obscureText' is true or the selection is empty, + /// this function will not do anything + Future<void> shareSelection(SelectionChangedCause cause) async { + assert(!widget.obscureText); + if (widget.obscureText) { + return; + } + + final String text = textEditingValue.selection.textInside(textEditingValue.text); + if (text.isNotEmpty) { + await SystemChannels.platform.invokeMethod( + 'Share.invoke', + text, + ); + } + } + + void _startLiveTextInput(SelectionChangedCause cause) { + if (!liveTextInputEnabled) { + return; + } + if (_hasInputConnection) { + LiveText.startLiveTextInput(); + } + if (cause == SelectionChangedCause.toolbar) { + hideToolbar(); + } + } + + /// Finds specified [SuggestionSpan] that matches the provided index using + /// binary search. + /// + /// See also: + /// + /// * [SpellCheckSuggestionsToolbar], the Material style spell check + /// suggestions toolbar that uses this method to render the correct + /// suggestions in the toolbar for a misspelled word. + SuggestionSpan? findSuggestionSpanAtCursorIndex(int cursorIndex) { + if (!_spellCheckResultsReceived + || spellCheckResults!.suggestionSpans.last.range.end < cursorIndex) { + // No spell check results have been received or the cursor index is out + // of range that suggestionSpans covers. + return null; + } + + final List<SuggestionSpan> suggestionSpans = spellCheckResults!.suggestionSpans; + int leftIndex = 0; + int rightIndex = suggestionSpans.length - 1; + int midIndex = 0; + + while (leftIndex <= rightIndex) { + midIndex = ((leftIndex + rightIndex) / 2).floor(); + final int currentSpanStart = suggestionSpans[midIndex].range.start; + final int currentSpanEnd = suggestionSpans[midIndex].range.end; + + if (cursorIndex <= currentSpanEnd && cursorIndex >= currentSpanStart) { + return suggestionSpans[midIndex]; + } + else if (cursorIndex <= currentSpanStart) { + rightIndex = midIndex - 1; + } + else { + leftIndex = midIndex + 1; + } + } + return null; + } + + /// Infers the [SpellCheckConfiguration] used to perform spell check. + /// + /// If spell check is enabled, this will try to infer a value for + /// the [SpellCheckService] if left unspecified. + static SpellCheckConfiguration _inferSpellCheckConfiguration(SpellCheckConfiguration? configuration) { + final SpellCheckService? spellCheckService = configuration?.spellCheckService; + final bool spellCheckAutomaticallyDisabled = configuration == null || configuration == const SpellCheckConfiguration.disabled(); + final bool spellCheckServiceIsConfigured = spellCheckService != null || spellCheckService == null && WidgetsBinding.instance.platformDispatcher.nativeSpellCheckServiceDefined; + if (spellCheckAutomaticallyDisabled || !spellCheckServiceIsConfigured) { + // Only enable spell check if a non-disabled configuration is provided + // and if that configuration does not specify a spell check service, + // a native spell checker must be supported. + assert(() { + if (!spellCheckAutomaticallyDisabled && !spellCheckServiceIsConfigured) { + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError( + 'Spell check was enabled with spellCheckConfiguration, but the ' + 'current platform does not have a supported spell check ' + 'service, and none was provided. Consider disabling spell ' + 'check for this platform or passing a SpellCheckConfiguration ' + 'with a specified spell check service.', + ), + library: 'widget library', + stack: StackTrace.current, + ), + ); + } + return true; + }()); + return const SpellCheckConfiguration.disabled(); + } + + return configuration.copyWith(spellCheckService: spellCheckService ?? DefaultSpellCheckService()); + } + + /// Returns the [ContextMenuButtonItem]s for the given [ToolbarOptions]. + @Deprecated( + 'Use `contextMenuBuilder` instead of `toolbarOptions`. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + List<ContextMenuButtonItem>? buttonItemsForToolbarOptions([TargetPlatform? targetPlatform]) { + final ToolbarOptions toolbarOptions = widget.toolbarOptions; + if (toolbarOptions == ToolbarOptions.empty) { + return null; + } + return <ContextMenuButtonItem>[ + if (toolbarOptions.cut && cutEnabled) + ContextMenuButtonItem( + onPressed: () { + cutSelection(SelectionChangedCause.toolbar); + }, + type: ContextMenuButtonType.cut, + ), + if (toolbarOptions.copy && copyEnabled) + ContextMenuButtonItem( + onPressed: () { + copySelection(SelectionChangedCause.toolbar); + }, + type: ContextMenuButtonType.copy, + ), + if (toolbarOptions.paste && pasteEnabled) + ContextMenuButtonItem( + onPressed: () { + pasteText(SelectionChangedCause.toolbar); + }, + type: ContextMenuButtonType.paste, + ), + if (toolbarOptions.selectAll && selectAllEnabled) + ContextMenuButtonItem( + onPressed: () { + selectAll(SelectionChangedCause.toolbar); + }, + type: ContextMenuButtonType.selectAll, + ), + ]; + } + + /// Gets the line heights at the start and end of the selection for the given + /// [EditableTextState]. + _GlyphHeights _getGlyphHeights() { + final TextSelection selection = textEditingValue.selection; + + // Only calculate handle rects if the text in the previous frame + // is the same as the text in the current frame. This is done because + // widget.renderObject contains the renderEditable from the previous frame. + // If the text changed between the current and previous frames then + // widget.renderObject.getRectForComposingRange might fail. In cases where + // the current frame is different from the previous we fall back to + // renderObject.preferredLineHeight. + final InlineSpan span = renderEditable.text!; + final String prevText = span.toPlainText(); + final String currText = textEditingValue.text; + if (prevText != currText || !selection.isValid || selection.isCollapsed) { + return _GlyphHeights( + start: renderEditable.preferredLineHeight, + end: renderEditable.preferredLineHeight, + ); + } + + final String selectedGraphemes = selection.textInside(currText); + final int firstSelectedGraphemeExtent = selectedGraphemes.characters.first.length; + final Rect? startCharacterRect = renderEditable.getRectForComposingRange(TextRange( + start: selection.start, + end: selection.start + firstSelectedGraphemeExtent, + )); + final int lastSelectedGraphemeExtent = selectedGraphemes.characters.last.length; + final Rect? endCharacterRect = renderEditable.getRectForComposingRange(TextRange( + start: selection.end - lastSelectedGraphemeExtent, + end: selection.end, + )); + return _GlyphHeights( + start: startCharacterRect?.height ?? renderEditable.preferredLineHeight, + end: endCharacterRect?.height ?? renderEditable.preferredLineHeight, + ); + } + + /// {@template flutter.widgets.EditableText.getAnchors} + /// Returns the anchor points for the default context menu. + /// {@endtemplate} + /// + /// See also: + /// + /// * [contextMenuButtonItems], which provides the [ContextMenuButtonItem]s + /// for the default context menu buttons. + TextSelectionToolbarAnchors get contextMenuAnchors { + if (renderEditable.lastSecondaryTapDownPosition != null) { + return TextSelectionToolbarAnchors( + primaryAnchor: renderEditable.lastSecondaryTapDownPosition!, + ); + } + + final _GlyphHeights glyphHeights = _getGlyphHeights(); + final TextSelection selection = textEditingValue.selection; + final List<TextSelectionPoint> points = + renderEditable.getEndpointsForSelection(selection); + return TextSelectionToolbarAnchors.fromSelection( + renderBox: renderEditable, + startGlyphHeight: glyphHeights.start, + endGlyphHeight: glyphHeights.end, + selectionEndpoints: points, + ); + } + + /// Returns the [ContextMenuButtonItem]s representing the buttons in this + /// platform's default selection menu for [EditableText]. + /// + /// See also: + /// + /// * [EditableText.getEditableButtonItems], which performs a similar role, + /// but for any editable field, not just specifically EditableText. + /// * [SelectableRegionState.contextMenuButtonItems], which performs a similar + /// role but for content that is selectable but not editable. + /// * [contextMenuAnchors], which provides the anchor points for the default + /// context menu. + /// * [AdaptiveTextSelectionToolbar], which builds the toolbar itself, and can + /// take a list of [ContextMenuButtonItem]s with + /// [AdaptiveTextSelectionToolbar.buttonItems]. + /// * [AdaptiveTextSelectionToolbar.getAdaptiveButtons], which builds the + /// button Widgets for the current platform given [ContextMenuButtonItem]s. + List<ContextMenuButtonItem> get contextMenuButtonItems { + return buttonItemsForToolbarOptions() ?? EditableText.getEditableButtonItems( + clipboardStatus: clipboardStatus.value, + onCopy: copyEnabled + ? () => copySelection(SelectionChangedCause.toolbar) + : null, + onCut: cutEnabled + ? () => cutSelection(SelectionChangedCause.toolbar) + : null, + onPaste: pasteEnabled + ? () => pasteText(SelectionChangedCause.toolbar) + : null, + onSelectAll: selectAllEnabled + ? () => selectAll(SelectionChangedCause.toolbar) + : null, + onLookUp: lookUpEnabled + ? () => lookUpSelection(SelectionChangedCause.toolbar) + : null, + onSearchWeb: searchWebEnabled + ? () => searchWebForSelection(SelectionChangedCause.toolbar) + : null, + onShare: shareEnabled + ? () => shareSelection(SelectionChangedCause.toolbar) + : null, + onLiveTextInput: liveTextInputEnabled + ? () => _startLiveTextInput(SelectionChangedCause.toolbar) + : null, + )..addAll(_textProcessingActionButtonItems); + } + + List<ContextMenuButtonItem> get _textProcessingActionButtonItems { + final List<ContextMenuButtonItem> buttonItems = <ContextMenuButtonItem>[]; + final TextSelection selection = textEditingValue.selection; + if (widget.obscureText || !selection.isValid || selection.isCollapsed) { + return buttonItems; + } + + for (final ProcessTextAction action in _processTextActions) { + buttonItems.add(ContextMenuButtonItem( + label: action.label, + onPressed: () async { + final String selectedText = selection.textInside(textEditingValue.text); + if (selectedText.isNotEmpty) { + final String? processedText = await _processTextService.processTextAction(action.id, selectedText, widget.readOnly); + // If an activity does not return a modified version, just hide the toolbar. + // Otherwise use the result to replace the selected text. + if (processedText != null && _allowPaste) { + _pasteText(SelectionChangedCause.toolbar, processedText); + } else { + hideToolbar(); + } + } + }, + )); + } + return buttonItems; + } + + // State lifecycle: + + @override + void initState() { + super.initState(); + _liveTextInputStatus?.addListener(_onChangedLiveTextInputStatus); + clipboardStatus.addListener(_onChangedClipboardStatus); + widget.controller.addListener(_didChangeTextEditingValue); + widget.focusNode.addListener(_handleFocusChanged); + _scrollController.addListener(_onEditableScroll); + _cursorVisibilityNotifier.value = widget.showCursor; + _spellCheckConfiguration = _inferSpellCheckConfiguration(widget.spellCheckConfiguration); + _initProcessTextActions(); + } + + /// Query the engine to initialize the list of text processing actions to show + /// in the text selection toolbar. + Future<void> _initProcessTextActions() async { + _processTextActions.clear(); + _processTextActions.addAll(await _processTextService.queryTextActions()); + } + + // Whether `TickerMode.of(context)` is true and animations (like blinking the + // cursor) are supposed to run. + bool _tickersEnabled = true; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + _style = MediaQuery.boldTextOf(context) + ? widget.style.merge(const TextStyle(fontWeight: FontWeight.bold)) + : widget.style; + + final AutofillGroupState? newAutofillGroup = AutofillGroup.maybeOf(context); + if (currentAutofillScope != newAutofillGroup) { + _currentAutofillScope?.unregister(autofillId); + _currentAutofillScope = newAutofillGroup; + _currentAutofillScope?.register(_effectiveAutofillClient); + } + + if (!_didAutoFocus && widget.autofocus) { + _didAutoFocus = true; + SchedulerBinding.instance.addPostFrameCallback((_) { + if (mounted && renderEditable.hasSize) { + _flagInternalFocus(); + FocusScope.of(context).autofocus(widget.focusNode); + } + }, debugLabel: 'EditableText.autofocus'); + } + + // Restart or stop the blinking cursor when TickerMode changes. + final bool newTickerEnabled = TickerMode.of(context); + if (_tickersEnabled != newTickerEnabled) { + _tickersEnabled = newTickerEnabled; + if (_showBlinkingCursor) { + _startCursorBlink(); + } else if (!_tickersEnabled && _cursorTimer != null) { + _stopCursorBlink(); + } + } + + if (defaultTargetPlatform != TargetPlatform.iOS && defaultTargetPlatform != TargetPlatform.android) { + return; + } + + // Hide the text selection toolbar on mobile when orientation changes. + final Orientation orientation = MediaQuery.orientationOf(context); + if (_lastOrientation == null) { + _lastOrientation = orientation; + return; + } + if (orientation != _lastOrientation) { + _lastOrientation = orientation; + if (defaultTargetPlatform == TargetPlatform.iOS) { + hideToolbar(false); + } + if (defaultTargetPlatform == TargetPlatform.android) { + hideToolbar(); + } + } + } + + @override + void didUpdateWidget(EditableText oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.controller != oldWidget.controller) { + oldWidget.controller.removeListener(_didChangeTextEditingValue); + widget.controller.addListener(_didChangeTextEditingValue); + _updateRemoteEditingValueIfNeeded(); + } + if (widget.controller.selection != oldWidget.controller.selection) { + _selectionOverlay?.update(_value); + } + _selectionOverlay?.handlesVisible = widget.showSelectionHandles; + + if (widget.autofillClient != oldWidget.autofillClient) { + _currentAutofillScope?.unregister(oldWidget.autofillClient?.autofillId ?? autofillId); + _currentAutofillScope?.register(_effectiveAutofillClient); + } + + if (widget.focusNode != oldWidget.focusNode) { + oldWidget.focusNode.removeListener(_handleFocusChanged); + widget.focusNode.addListener(_handleFocusChanged); + updateKeepAlive(); + } + + if (widget.scrollController != oldWidget.scrollController) { + (oldWidget.scrollController ?? _internalScrollController)?.removeListener(_onEditableScroll); + _scrollController.addListener(_onEditableScroll); + } + + if (!_shouldCreateInputConnection) { + _closeInputConnectionIfNeeded(); + } else if (oldWidget.readOnly && _hasFocus) { + // _openInputConnection must be called after layout information is available. + // See https://github.com/flutter/flutter/issues/126312 + SchedulerBinding.instance.addPostFrameCallback((Duration _) { + _openInputConnection(); + }, debugLabel: 'EditableText.openInputConnection'); + } + + if (kIsWeb && _hasInputConnection) { + if (oldWidget.readOnly != widget.readOnly) { + _textInputConnection!.updateConfig(_effectiveAutofillClient.textInputConfiguration); + } + } + + if (_hasInputConnection) { + if (oldWidget.obscureText != widget.obscureText) { + _textInputConnection!.updateConfig(_effectiveAutofillClient.textInputConfiguration); + } + } + + if (widget.style != oldWidget.style) { + // The _textInputConnection will pick up the new style when it attaches in + // _openInputConnection. + _style = MediaQuery.boldTextOf(context) + ? widget.style.merge(const TextStyle(fontWeight: FontWeight.bold)) + : widget.style; + if (_hasInputConnection) { + _textInputConnection!.setStyle( + fontFamily: _style.fontFamily, + fontSize: _style.fontSize, + fontWeight: _style.fontWeight, + textDirection: _textDirection, + textAlign: widget.textAlign, + ); + } + } + + if (widget.showCursor != oldWidget.showCursor) { + _startOrStopCursorTimerIfNeeded(); + } + final bool canPaste = widget.selectionControls is TextSelectionHandleControls + ? pasteEnabled + : widget.selectionControls?.canPaste(this) ?? false; + if (widget.selectionEnabled && pasteEnabled && canPaste) { + clipboardStatus.update(); + } + } + + @override + void dispose() { + _internalScrollController?.dispose(); + _currentAutofillScope?.unregister(autofillId); + widget.controller.removeListener(_didChangeTextEditingValue); + _floatingCursorResetController?.dispose(); + _floatingCursorResetController = null; + _closeInputConnectionIfNeeded(); + assert(!_hasInputConnection); + _cursorTimer?.cancel(); + _cursorTimer = null; + _backingCursorBlinkOpacityController?.dispose(); + _backingCursorBlinkOpacityController = null; + _selectionOverlay?.dispose(); + _selectionOverlay = null; + widget.focusNode.removeListener(_handleFocusChanged); + WidgetsBinding.instance.removeObserver(this); + _liveTextInputStatus?.removeListener(_onChangedLiveTextInputStatus); + _liveTextInputStatus?.dispose(); + clipboardStatus.removeListener(_onChangedClipboardStatus); + clipboardStatus.dispose(); + _cursorVisibilityNotifier.dispose(); + FocusManager.instance.removeListener(_unflagInternalFocus); + super.dispose(); + assert(_batchEditDepth <= 0, 'unfinished batch edits: $_batchEditDepth'); + } + + // TextInputClient implementation: + + /// The last known [TextEditingValue] of the platform text input plugin. + /// + /// This value is updated when the platform text input plugin sends a new + /// update via [updateEditingValue], or when [EditableText] calls + /// [TextInputConnection.setEditingState] to overwrite the platform text input + /// plugin's [TextEditingValue]. + /// + /// Used in [_updateRemoteEditingValueIfNeeded] to determine whether the + /// remote value is outdated and needs updating. + TextEditingValue? _lastKnownRemoteTextEditingValue; + + @override + TextEditingValue get currentTextEditingValue => _value; + + @override + void updateEditingValue(TextEditingValue value) { + // This method handles text editing state updates from the platform text + // input plugin. The [EditableText] may not have the focus or an open input + // connection, as autofill can update a disconnected [EditableText]. + + // Since we still have to support keyboard select, this is the best place + // to disable text updating. + if (!_shouldCreateInputConnection) { + return; + } + + if (_checkNeedsAdjustAffinity(value)) { + value = value.copyWith(selection: value.selection.copyWith(affinity: _value.selection.affinity)); + } + + if (widget.readOnly) { + // In the read-only case, we only care about selection changes, and reject + // everything else. + value = _value.copyWith(selection: value.selection); + } + _lastKnownRemoteTextEditingValue = value; + + if (value == _value) { + // This is possible, for example, when the numeric keyboard is input, + // the engine will notify twice for the same value. + // Track at https://github.com/flutter/flutter/issues/65811 + return; + } + + if (value.text == _value.text && value.composing == _value.composing) { + // `selection` is the only change. + SelectionChangedCause cause; + if (_textInputConnection?.scribbleInProgress ?? false) { + cause = SelectionChangedCause.scribble; + } else if (_pointOffsetOrigin != null) { + // For floating cursor selection when force pressing the space bar. + cause = SelectionChangedCause.forcePress; + } else { + cause = SelectionChangedCause.keyboard; + } + _handleSelectionChanged(value.selection, cause); + } else { + if (value.text != _value.text) { + // Hide the toolbar if the text was changed, but only hide the toolbar + // overlay; the selection handle's visibility will be handled + // by `_handleSelectionChanged`. https://github.com/flutter/flutter/issues/108673 + hideToolbar(false); + } + _currentPromptRectRange = null; + + final bool revealObscuredInput = _hasInputConnection + && widget.obscureText + && WidgetsBinding.instance.platformDispatcher.brieflyShowPassword + && value.text.length == _value.text.length + 1; + + _obscureShowCharTicksPending = revealObscuredInput ? _kObscureShowLatestCharCursorTicks : 0; + _obscureLatestCharIndex = revealObscuredInput ? _value.selection.baseOffset : null; + _formatAndSetValue(value, SelectionChangedCause.keyboard); + } + + if (_showBlinkingCursor && _cursorTimer != null) { + // To keep the cursor from blinking while typing, restart the timer here. + _stopCursorBlink(resetCharTicks: false); + _startCursorBlink(); + } + + // Wherever the value is changed by the user, schedule a showCaretOnScreen + // to make sure the user can see the changes they just made. Programmatic + // changes to `textEditingValue` do not trigger the behavior even if the + // text field is focused. + _scheduleShowCaretOnScreen(withAnimation: true); + } + + bool _checkNeedsAdjustAffinity(TextEditingValue value) { + // Trust the engine affinity if the text changes or selection changes. + return value.text == _value.text && + value.selection.isCollapsed == _value.selection.isCollapsed && + value.selection.start == _value.selection.start && + value.selection.affinity != _value.selection.affinity; + } + + @override + void performAction(TextInputAction action) { + switch (action) { + case TextInputAction.newline: + // If this is a multiline EditableText, do nothing for a "newline" + // action; The newline is already inserted. Otherwise, finalize + // editing. + if (!_isMultiline) { + _finalizeEditing(action, shouldUnfocus: true); + } + case TextInputAction.done: + case TextInputAction.go: + case TextInputAction.next: + case TextInputAction.previous: + case TextInputAction.search: + case TextInputAction.send: + _finalizeEditing(action, shouldUnfocus: true); + case TextInputAction.continueAction: + case TextInputAction.emergencyCall: + case TextInputAction.join: + case TextInputAction.none: + case TextInputAction.route: + case TextInputAction.unspecified: + // Finalize editing, but don't give up focus because this keyboard + // action does not imply the user is done inputting information. + _finalizeEditing(action, shouldUnfocus: false); + } + } + + @override + void performPrivateCommand(String action, Map<String, dynamic> data) { + widget.onAppPrivateCommand?.call(action, data); + } + + @override + void insertContent(KeyboardInsertedContent content) { + assert(widget.contentInsertionConfiguration?.allowedMimeTypes.contains(content.mimeType) ?? false); + widget.contentInsertionConfiguration?.onContentInserted.call(content); + } + + // The original position of the caret on FloatingCursorDragState.start. + Offset? _startCaretCenter; + + // The most recent text position as determined by the location of the floating + // cursor. + TextPosition? _lastTextPosition; + + // The offset of the floating cursor as determined from the start call. + Offset? _pointOffsetOrigin; + + // The most recent position of the floating cursor. + Offset? _lastBoundedOffset; + + // Because the center of the cursor is preferredLineHeight / 2 below the touch + // origin, but the touch origin is used to determine which line the cursor is + // on, we need this offset to correctly render and move the cursor. + Offset get _floatingCursorOffset => Offset(0, renderEditable.preferredLineHeight / 2); + + @override + void updateFloatingCursor(RawFloatingCursorPoint point) { + _floatingCursorResetController ??= AnimationController( + vsync: this, + )..addListener(_onFloatingCursorResetTick); + switch (point.state) { + case FloatingCursorDragState.Start: + if (_floatingCursorResetController!.isAnimating) { + _floatingCursorResetController!.stop(); + _onFloatingCursorResetTick(); + } + // Stop cursor blinking and making it visible. + _stopCursorBlink(resetCharTicks: false); + _cursorBlinkOpacityController.value = 1.0; + // We want to send in points that are centered around a (0,0) origin, so + // we cache the position. + _pointOffsetOrigin = point.offset; + + final Offset startCaretCenter; + final TextPosition currentTextPosition; + final bool shouldResetOrigin; + // Only non-null when starting a floating cursor via long press. + if (point.startLocation != null) { + shouldResetOrigin = false; + (startCaretCenter, currentTextPosition) = point.startLocation!; + } else { + shouldResetOrigin = true; + currentTextPosition = TextPosition(offset: renderEditable.selection!.baseOffset, affinity: renderEditable.selection!.affinity); + startCaretCenter = renderEditable.getLocalRectForCaret(currentTextPosition).center; + } + + _startCaretCenter = startCaretCenter; + _lastBoundedOffset = renderEditable.calculateBoundedFloatingCursorOffset(_startCaretCenter! - _floatingCursorOffset, shouldResetOrigin: shouldResetOrigin); + _lastTextPosition = currentTextPosition; + renderEditable.setFloatingCursor(point.state, _lastBoundedOffset!, _lastTextPosition!); + case FloatingCursorDragState.Update: + final Offset centeredPoint = point.offset! - _pointOffsetOrigin!; + final Offset rawCursorOffset = _startCaretCenter! + centeredPoint - _floatingCursorOffset; + + _lastBoundedOffset = renderEditable.calculateBoundedFloatingCursorOffset(rawCursorOffset); + _lastTextPosition = renderEditable.getPositionForPoint(renderEditable.localToGlobal(_lastBoundedOffset! + _floatingCursorOffset)); + renderEditable.setFloatingCursor(point.state, _lastBoundedOffset!, _lastTextPosition!); + case FloatingCursorDragState.End: + // Resume cursor blinking. + _startCursorBlink(); + // We skip animation if no update has happened. + if (_lastTextPosition != null && _lastBoundedOffset != null) { + _floatingCursorResetController!.value = 0.0; + _floatingCursorResetController!.animateTo(1.0, duration: _floatingCursorResetTime, curve: Curves.decelerate); + } + } + } + + void _onFloatingCursorResetTick() { + final Offset finalPosition = renderEditable.getLocalRectForCaret(_lastTextPosition!).centerLeft - _floatingCursorOffset; + if (_floatingCursorResetController!.isCompleted) { + renderEditable.setFloatingCursor(FloatingCursorDragState.End, finalPosition, _lastTextPosition!); + // During a floating cursor's move gesture (1 finger), a cursor is + // animated only visually, without actually updating the selection. + // Only after move gesture is complete, this function will be called + // to actually update the selection to the new cursor location with + // zero selection length. + + // However, During a floating cursor's selection gesture (2 fingers), the + // selection is constantly updated by the engine throughout the gesture. + // Thus when the gesture is complete, we should not update the selection + // to the cursor location with zero selection length, because that would + // overwrite the selection made by floating cursor selection. + + // Here we use `isCollapsed` to distinguish between floating cursor's + // move gesture (1 finger) vs selection gesture (2 fingers), as + // the engine does not provide information other than notifying a + // new selection during with selection gesture (2 fingers). + if (renderEditable.selection!.isCollapsed) { + // The cause is technically the force cursor, but the cause is listed as tap as the desired functionality is the same. + _handleSelectionChanged(TextSelection.fromPosition(_lastTextPosition!), SelectionChangedCause.forcePress); + } + _startCaretCenter = null; + _lastTextPosition = null; + _pointOffsetOrigin = null; + _lastBoundedOffset = null; + } else { + final double lerpValue = _floatingCursorResetController!.value; + final double lerpX = ui.lerpDouble(_lastBoundedOffset!.dx, finalPosition.dx, lerpValue)!; + final double lerpY = ui.lerpDouble(_lastBoundedOffset!.dy, finalPosition.dy, lerpValue)!; + + renderEditable.setFloatingCursor(FloatingCursorDragState.Update, Offset(lerpX, lerpY), _lastTextPosition!, resetLerpValue: lerpValue); + } + } + + @pragma('vm:notify-debugger-on-exception') + void _finalizeEditing(TextInputAction action, {required bool shouldUnfocus}) { + // Take any actions necessary now that the user has completed editing. + if (widget.onEditingComplete != null) { + try { + widget.onEditingComplete!(); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets', + context: ErrorDescription('while calling onEditingComplete for $action'), + )); + } + } else { + // Default behavior if the developer did not provide an + // onEditingComplete callback: Finalize editing and remove focus, or move + // it to the next/previous field, depending on the action. + widget.controller.clearComposing(); + if (shouldUnfocus) { + switch (action) { + case TextInputAction.none: + case TextInputAction.unspecified: + case TextInputAction.done: + case TextInputAction.go: + case TextInputAction.search: + case TextInputAction.send: + case TextInputAction.continueAction: + case TextInputAction.join: + case TextInputAction.route: + case TextInputAction.emergencyCall: + case TextInputAction.newline: + widget.focusNode.unfocus(); + case TextInputAction.next: + widget.focusNode.nextFocus(); + case TextInputAction.previous: + widget.focusNode.previousFocus(); + } + } + } + + final ValueChanged<String>? onSubmitted = widget.onSubmitted; + if (onSubmitted == null) { + return; + } + + // Invoke optional callback with the user's submitted content. + try { + onSubmitted(_value.text); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets', + context: ErrorDescription('while calling onSubmitted for $action'), + )); + } + + // If `shouldUnfocus` is true, the text field should no longer be focused + // after the microtask queue is drained. But in case the developer cancelled + // the focus change in the `onSubmitted` callback by focusing this input + // field again, reset the soft keyboard. + // See https://github.com/flutter/flutter/issues/84240. + // + // `_restartConnectionIfNeeded` creates a new TextInputConnection to replace + // the current one. This on iOS switches to a new input view and on Android + // restarts the input method, and in both cases the soft keyboard will be + // reset. + if (shouldUnfocus) { + _scheduleRestartConnection(); + } + } + + int _batchEditDepth = 0; + + /// Begins a new batch edit, within which new updates made to the text editing + /// value will not be sent to the platform text input plugin. + /// + /// Batch edits nest. When the outermost batch edit finishes, [endBatchEdit] + /// will attempt to send [currentTextEditingValue] to the text input plugin if + /// it detected a change. + void beginBatchEdit() { + _batchEditDepth += 1; + } + + /// Ends the current batch edit started by the last call to [beginBatchEdit], + /// and send [currentTextEditingValue] to the text input plugin if needed. + /// + /// Throws an error in debug mode if this [EditableText] is not in a batch + /// edit. + void endBatchEdit() { + _batchEditDepth -= 1; + assert( + _batchEditDepth >= 0, + 'Unbalanced call to endBatchEdit: beginBatchEdit must be called first.', + ); + _updateRemoteEditingValueIfNeeded(); + } + + void _updateRemoteEditingValueIfNeeded() { + if (_batchEditDepth > 0 || !_hasInputConnection) { + return; + } + final TextEditingValue localValue = _value; + if (localValue == _lastKnownRemoteTextEditingValue) { + return; + } + _textInputConnection!.setEditingState(localValue); + _lastKnownRemoteTextEditingValue = localValue; + } + + TextEditingValue get _value => widget.controller.value; + set _value(TextEditingValue value) { + widget.controller.value = value; + } + + bool get _hasFocus => widget.focusNode.hasFocus; + bool get _isMultiline => widget.maxLines != 1; + + // Finds the closest scroll offset to the current scroll offset that fully + // reveals the given caret rect. If the given rect's main axis extent is too + // large to be fully revealed in `renderEditable`, it will be centered along + // the main axis. + // + // If this is a multiline EditableText (which means the Editable can only + // scroll vertically), the given rect's height will first be extended to match + // `renderEditable.preferredLineHeight`, before the target scroll offset is + // calculated. + RevealedOffset _getOffsetToRevealCaret(Rect rect) { + if (!_scrollController.position.allowImplicitScrolling) { + return RevealedOffset(offset: _scrollController.offset, rect: rect); + } + + final Size editableSize = renderEditable.size; + final double additionalOffset; + final Offset unitOffset; + + if (!_isMultiline) { + additionalOffset = rect.width >= editableSize.width + // Center `rect` if it's oversized. + ? editableSize.width / 2 - rect.center.dx + // Valid additional offsets range from (rect.right - size.width) + // to (rect.left). Pick the closest one if out of range. + : clampDouble(0.0, rect.right - editableSize.width, rect.left); + unitOffset = const Offset(1, 0); + } else { + // The caret is vertically centered within the line. Expand the caret's + // height so that it spans the line because we're going to ensure that the + // entire expanded caret is scrolled into view. + final Rect expandedRect = Rect.fromCenter( + center: rect.center, + width: rect.width, + height: math.max(rect.height, renderEditable.preferredLineHeight), + ); + + additionalOffset = expandedRect.height >= editableSize.height + ? editableSize.height / 2 - expandedRect.center.dy + : clampDouble(0.0, expandedRect.bottom - editableSize.height, expandedRect.top); + unitOffset = const Offset(0, 1); + } + + // No overscrolling when encountering tall fonts/scripts that extend past + // the ascent. + final double targetOffset = clampDouble( + additionalOffset + _scrollController.offset, + _scrollController.position.minScrollExtent, + _scrollController.position.maxScrollExtent, + ); + + final double offsetDelta = _scrollController.offset - targetOffset; + return RevealedOffset(rect: rect.shift(unitOffset * offsetDelta), offset: targetOffset); + } + + /// Whether to send the autofill information to the autofill service. True by + /// default. + bool get _needsAutofill => _effectiveAutofillClient.textInputConfiguration.autofillConfiguration.enabled; + + // Must be called after layout. + // See https://github.com/flutter/flutter/issues/126312 + void _openInputConnection() { + if (!_shouldCreateInputConnection) { + return; + } + if (!_hasInputConnection) { + final TextEditingValue localValue = _value; + + // When _needsAutofill == true && currentAutofillScope == null, autofill + // is allowed but saving the user input from the text field is + // discouraged. + // + // In case the autofillScope changes from a non-null value to null, or + // _needsAutofill changes to false from true, the platform needs to be + // notified to exclude this field from the autofill context. So we need to + // provide the autofillId. + _textInputConnection = _needsAutofill && currentAutofillScope != null + ? currentAutofillScope!.attach(this, _effectiveAutofillClient.textInputConfiguration) + : TextInput.attach(this, _effectiveAutofillClient.textInputConfiguration); + _updateSizeAndTransform(); + _schedulePeriodicPostFrameCallbacks(); + _textInputConnection! + ..setStyle( + fontFamily: _style.fontFamily, + fontSize: _style.fontSize, + fontWeight: _style.fontWeight, + textDirection: _textDirection, + textAlign: widget.textAlign, + ) + ..setEditingState(localValue) + ..show(); + if (_needsAutofill) { + // Request autofill AFTER the size and the transform have been sent to + // the platform text input plugin. + _textInputConnection!.requestAutofill(); + } + _lastKnownRemoteTextEditingValue = localValue; + } else { + _textInputConnection!.show(); + } + } + + void _closeInputConnectionIfNeeded() { + if (_hasInputConnection) { + _textInputConnection!.close(); + _textInputConnection = null; + _lastKnownRemoteTextEditingValue = null; + _scribbleCacheKey = null; + removeTextPlaceholder(); + } + } + + void _openOrCloseInputConnectionIfNeeded() { + if (_hasFocus && widget.focusNode.consumeKeyboardToken()) { + _openInputConnection(); + } else if (!_hasFocus) { + _closeInputConnectionIfNeeded(); + widget.controller.clearComposing(); + } + } + + bool _restartConnectionScheduled = false; + void _scheduleRestartConnection() { + if (_restartConnectionScheduled) { + return; + } + _restartConnectionScheduled = true; + scheduleMicrotask(_restartConnectionIfNeeded); + } + // Discards the current [TextInputConnection] and establishes a new one. + // + // This method is rarely needed. This is currently used to reset the input + // type when the "submit" text input action is triggered and the developer + // puts the focus back to this input field.. + void _restartConnectionIfNeeded() { + _restartConnectionScheduled = false; + if (!_hasInputConnection || !_shouldCreateInputConnection) { + return; + } + _textInputConnection!.close(); + _textInputConnection = null; + _lastKnownRemoteTextEditingValue = null; + + final AutofillScope? currentAutofillScope = _needsAutofill ? this.currentAutofillScope : null; + final TextInputConnection newConnection = currentAutofillScope?.attach(this, textInputConfiguration) + ?? TextInput.attach(this, _effectiveAutofillClient.textInputConfiguration); + _textInputConnection = newConnection; + + newConnection + ..show() + ..setStyle( + fontFamily: _style.fontFamily, + fontSize: _style.fontSize, + fontWeight: _style.fontWeight, + textDirection: _textDirection, + textAlign: widget.textAlign, + ) + ..setEditingState(_value); + _lastKnownRemoteTextEditingValue = _value; + } + + + @override + void didChangeInputControl(TextInputControl? oldControl, TextInputControl? newControl) { + if (_hasFocus && _hasInputConnection) { + oldControl?.hide(); + newControl?.show(); + } + } + + @override + void connectionClosed() { + if (_hasInputConnection) { + _textInputConnection!.connectionClosedReceived(); + _textInputConnection = null; + _lastKnownRemoteTextEditingValue = null; + widget.focusNode.unfocus(); + } + } + + // Indicates that a call to _handleFocusChanged originated within + // EditableText, allowing it to distinguish between internal and external + // focus changes. + bool _nextFocusChangeIsInternal = false; + + // Sets _nextFocusChangeIsInternal to true only until any subsequent focus + // change happens. + void _flagInternalFocus() { + _nextFocusChangeIsInternal = true; + FocusManager.instance.addListener(_unflagInternalFocus); + } + + void _unflagInternalFocus() { + _nextFocusChangeIsInternal = false; + FocusManager.instance.removeListener(_unflagInternalFocus); + } + + /// Express interest in interacting with the keyboard. + /// + /// If this control is already attached to the keyboard, this function will + /// request that the keyboard become visible. Otherwise, this function will + /// ask the focus system that it become focused. If successful in acquiring + /// focus, the control will then attach to the keyboard and request that the + /// keyboard become visible. + void requestKeyboard() { + if (_hasFocus) { + _openInputConnection(); + } else { + _flagInternalFocus(); + widget.focusNode.requestFocus(); // This eventually calls _openInputConnection also, see _handleFocusChanged. + } + } + + void _updateOrDisposeSelectionOverlayIfNeeded() { + if (_selectionOverlay != null) { + if (_hasFocus) { + _selectionOverlay!.update(_value); + } else { + _selectionOverlay!.dispose(); + _selectionOverlay = null; + } + } + } + + void _onEditableScroll() { + _selectionOverlay?.updateForScroll(); + _scribbleCacheKey = null; + } + + TextSelectionOverlay _createSelectionOverlay() { + final EditableTextContextMenuBuilder? contextMenuBuilder = widget.contextMenuBuilder; + final TextSelectionOverlay selectionOverlay = TextSelectionOverlay( + clipboardStatus: clipboardStatus, + context: context, + value: _value, + debugRequiredFor: widget, + toolbarLayerLink: _toolbarLayerLink, + startHandleLayerLink: _startHandleLayerLink, + endHandleLayerLink: _endHandleLayerLink, + renderObject: renderEditable, + selectionControls: widget.selectionControls, + selectionDelegate: this, + dragStartBehavior: widget.dragStartBehavior, + onSelectionHandleTapped: widget.onSelectionHandleTapped, + contextMenuBuilder: contextMenuBuilder == null + ? null + : (BuildContext context) { + return contextMenuBuilder( + context, + this, + ); + }, + magnifierConfiguration: widget.magnifierConfiguration, + ); + + return selectionOverlay; + } + + @pragma('vm:notify-debugger-on-exception') + void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) { + // We return early if the selection is not valid. This can happen when the + // text of [EditableText] is updated at the same time as the selection is + // changed by a gesture event. + if (!widget.controller.isSelectionWithinTextBounds(selection)) { + return; + } + + widget.controller.selection = selection; + + // This will show the keyboard for all selection changes on the + // EditableText except for those triggered by a keyboard input. + // Typically EditableText shouldn't take user keyboard input if + // it's not focused already. If the EditableText is being + // autofilled it shouldn't request focus. + switch (cause) { + case null: + case SelectionChangedCause.doubleTap: + case SelectionChangedCause.drag: + case SelectionChangedCause.forcePress: + case SelectionChangedCause.longPress: + case SelectionChangedCause.scribble: + case SelectionChangedCause.tap: + case SelectionChangedCause.toolbar: + requestKeyboard(); + case SelectionChangedCause.keyboard: + if (_hasFocus) { + requestKeyboard(); + } + } + if (widget.selectionControls == null && widget.contextMenuBuilder == null) { + _selectionOverlay?.dispose(); + _selectionOverlay = null; + } else { + if (_selectionOverlay == null) { + _selectionOverlay = _createSelectionOverlay(); + } else { + _selectionOverlay!.update(_value); + } + _selectionOverlay!.handlesVisible = widget.showSelectionHandles; + _selectionOverlay!.showHandles(); + } + // TODO(chunhtai): we should make sure selection actually changed before + // we call the onSelectionChanged. + // https://github.com/flutter/flutter/issues/76349. + try { + widget.onSelectionChanged?.call(selection, cause); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets', + context: ErrorDescription('while calling onSelectionChanged for $cause'), + )); + } + + // To keep the cursor from blinking while it moves, restart the timer here. + if (_showBlinkingCursor && _cursorTimer != null) { + _stopCursorBlink(resetCharTicks: false); + _startCursorBlink(); + } + } + + // Animation configuration for scrolling the caret back on screen. + static const Duration _caretAnimationDuration = Duration(milliseconds: 100); + static const Curve _caretAnimationCurve = Curves.fastOutSlowIn; + + bool _showCaretOnScreenScheduled = false; + + void _scheduleShowCaretOnScreen({required bool withAnimation}) { + if (_showCaretOnScreenScheduled) { + return; + } + _showCaretOnScreenScheduled = true; + SchedulerBinding.instance.addPostFrameCallback((Duration _) { + _showCaretOnScreenScheduled = false; + // Since we are in a post frame callback, check currentContext in case + // RenderEditable has been disposed (in which case it will be null). + final RenderEditable? renderEditable = + _editableKey.currentContext?.findRenderObject() as RenderEditable?; + if (renderEditable == null + || !(renderEditable.selection?.isValid ?? false) + || !_scrollController.hasClients) { + return; + } + + final double lineHeight = renderEditable.preferredLineHeight; + + // Enlarge the target rect by scrollPadding to ensure that caret is not + // positioned directly at the edge after scrolling. + double bottomSpacing = widget.scrollPadding.bottom; + if (_selectionOverlay?.selectionControls != null) { + final double handleHeight = _selectionOverlay!.selectionControls! + .getHandleSize(lineHeight).height; + final double interactiveHandleHeight = math.max( + handleHeight, + kMinInteractiveDimension, + ); + final Offset anchor = _selectionOverlay!.selectionControls! + .getHandleAnchor( + TextSelectionHandleType.collapsed, + lineHeight, + ); + final double handleCenter = handleHeight / 2 - anchor.dy; + bottomSpacing = math.max( + handleCenter + interactiveHandleHeight / 2, + bottomSpacing, + ); + } + + final EdgeInsets caretPadding = widget.scrollPadding + .copyWith(bottom: bottomSpacing); + + final Rect caretRect = renderEditable.getLocalRectForCaret(renderEditable.selection!.extent); + final RevealedOffset targetOffset = _getOffsetToRevealCaret(caretRect); + + final Rect rectToReveal; + final TextSelection selection = textEditingValue.selection; + if (selection.isCollapsed) { + rectToReveal = targetOffset.rect; + } else { + final List<TextBox> selectionBoxes = renderEditable.getBoxesForSelection(selection); + // selectionBoxes may be empty if, for example, the selection does not + // encompass a full character, like if it only contained part of an + // extended grapheme cluster. + if (selectionBoxes.isEmpty) { + rectToReveal = targetOffset.rect; + } else { + rectToReveal = selection.baseOffset < selection.extentOffset ? + selectionBoxes.last.toRect() : selectionBoxes.first.toRect(); + } + } + + if (withAnimation) { + _scrollController.animateTo( + targetOffset.offset, + duration: _caretAnimationDuration, + curve: _caretAnimationCurve, + ); + renderEditable.showOnScreen( + rect: caretPadding.inflateRect(rectToReveal), + duration: _caretAnimationDuration, + curve: _caretAnimationCurve, + ); + } else { + _scrollController.jumpTo(targetOffset.offset); + renderEditable.showOnScreen( + rect: caretPadding.inflateRect(rectToReveal), + ); + } + }, debugLabel: 'EditableText.showCaret'); + } + + late double _lastBottomViewInset; + + @override + void didChangeMetrics() { + if (!mounted) { + return; + } + final ui.FlutterView view = View.of(context); + if (_lastBottomViewInset != view.viewInsets.bottom) { + SchedulerBinding.instance.addPostFrameCallback((Duration _) { + _selectionOverlay?.updateForScroll(); + }, debugLabel: 'EditableText.updateForScroll'); + if (_lastBottomViewInset < view.viewInsets.bottom) { + // Because the metrics change signal from engine will come here every frame + // (on both iOS and Android). So we don't need to show caret with animation. + _scheduleShowCaretOnScreen(withAnimation: false); + } + } + _lastBottomViewInset = view.viewInsets.bottom; + } + + Future<void> _performSpellCheck(final String text) async { + try { + final Locale? localeForSpellChecking = widget.locale ?? Localizations.maybeLocaleOf(context); + + assert( + localeForSpellChecking != null, + 'Locale must be specified in widget or Localization widget must be in scope', + ); + + final List<SuggestionSpan>? suggestions = await + _spellCheckConfiguration + .spellCheckService! + .fetchSpellCheckSuggestions(localeForSpellChecking!, text); + + if (suggestions == null) { + // The request to fetch spell check suggestions was canceled due to ongoing request. + return; + } + + spellCheckResults = SpellCheckResults(text, suggestions); + renderEditable.text = buildTextSpan(); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets', + context: ErrorDescription('while performing spell check'), + )); + } + } + + @pragma('vm:notify-debugger-on-exception') + void _formatAndSetValue(TextEditingValue value, SelectionChangedCause? cause, {bool userInteraction = false}) { + final TextEditingValue oldValue = _value; + final bool textChanged = oldValue.text != value.text; + final bool textCommitted = !oldValue.composing.isCollapsed && value.composing.isCollapsed; + final bool selectionChanged = oldValue.selection != value.selection; + + if (textChanged || textCommitted) { + // Only apply input formatters if the text has changed (including uncommitted + // text in the composing region), or when the user committed the composing + // text. + // Gboard is very persistent in restoring the composing region. Applying + // input formatters on composing-region-only changes (except clearing the + // current composing region) is very infinite-loop-prone: the formatters + // will keep trying to modify the composing region while Gboard will keep + // trying to restore the original composing region. + try { + value = widget.inputFormatters?.fold<TextEditingValue>( + value, + (TextEditingValue newValue, TextInputFormatter formatter) => formatter.formatEditUpdate(_value, newValue), + ) ?? value; + + if (spellCheckEnabled && value.text.isNotEmpty && _value.text != value.text) { + _performSpellCheck(value.text); + } + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets', + context: ErrorDescription('while applying input formatters'), + )); + } + } + + final TextSelection oldTextSelection = textEditingValue.selection; + + // Put all optional user callback invocations in a batch edit to prevent + // sending multiple `TextInput.updateEditingValue` messages. + beginBatchEdit(); + _value = value; + // Changes made by the keyboard can sometimes be "out of band" for listening + // components, so always send those events, even if we didn't think it + // changed. Also, the user long pressing should always send a selection change + // as well. + if (selectionChanged || + (userInteraction && + (cause == SelectionChangedCause.longPress || + cause == SelectionChangedCause.keyboard))) { + _handleSelectionChanged(_value.selection, cause); + _bringIntoViewBySelectionState(oldTextSelection, value.selection, cause); + } + final String currentText = _value.text; + if (oldValue.text != currentText) { + try { + widget.onChanged?.call(currentText); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets', + context: ErrorDescription('while calling onChanged'), + )); + } + } + endBatchEdit(); + } + + void _bringIntoViewBySelectionState(TextSelection oldSelection, TextSelection newSelection, SelectionChangedCause? cause) { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + if (cause == SelectionChangedCause.longPress || + cause == SelectionChangedCause.drag) { + bringIntoView(newSelection.extent); + } + case TargetPlatform.linux: + case TargetPlatform.windows: + case TargetPlatform.fuchsia: + case TargetPlatform.android: + if (cause == SelectionChangedCause.drag) { + if (oldSelection.baseOffset != newSelection.baseOffset) { + bringIntoView(newSelection.base); + } else if (oldSelection.extentOffset != newSelection.extentOffset) { + bringIntoView(newSelection.extent); + } + } + } + } + + void _onCursorColorTick() { + final double effectiveOpacity = math.min(widget.cursorColor.alpha / 255.0, _cursorBlinkOpacityController.value); + renderEditable.cursorColor = widget.cursorColor.withOpacity(effectiveOpacity); + _cursorVisibilityNotifier.value = widget.showCursor && (EditableText.debugDeterministicCursor || _cursorBlinkOpacityController.value > 0); + } + + bool get _showBlinkingCursor => _hasFocus && _value.selection.isCollapsed && widget.showCursor && _tickersEnabled; + + /// Whether the blinking cursor is actually visible at this precise moment + /// (it's hidden half the time, since it blinks). + @visibleForTesting + bool get cursorCurrentlyVisible => _cursorBlinkOpacityController.value > 0; + + /// The cursor blink interval (the amount of time the cursor is in the "on" + /// state or the "off" state). A complete cursor blink period is twice this + /// value (half on, half off). + @visibleForTesting + Duration get cursorBlinkInterval => _kCursorBlinkHalfPeriod; + + /// The current status of the text selection handles. + @visibleForTesting + TextSelectionOverlay? get selectionOverlay => _selectionOverlay; + + int _obscureShowCharTicksPending = 0; + int? _obscureLatestCharIndex; + + void _startCursorBlink() { + assert(!(_cursorTimer?.isActive ?? false) || !(_backingCursorBlinkOpacityController?.isAnimating ?? false)); + if (!widget.showCursor) { + return; + } + if (!_tickersEnabled) { + return; + } + _cursorTimer?.cancel(); + _cursorBlinkOpacityController.value = 1.0; + if (EditableText.debugDeterministicCursor) { + return; + } + if (widget.cursorOpacityAnimates) { + _cursorBlinkOpacityController.animateWith(_iosBlinkCursorSimulation).whenComplete(_onCursorTick); + } else { + _cursorTimer = Timer.periodic(_kCursorBlinkHalfPeriod, (Timer timer) { _onCursorTick(); }); + } + } + + void _onCursorTick() { + if (_obscureShowCharTicksPending > 0) { + _obscureShowCharTicksPending = WidgetsBinding.instance.platformDispatcher.brieflyShowPassword + ? _obscureShowCharTicksPending - 1 + : 0; + if (_obscureShowCharTicksPending == 0) { + setState(() { }); + } + } + + if (widget.cursorOpacityAnimates) { + _cursorTimer?.cancel(); + // Schedule this as an async task to avoid blocking tester.pumpAndSettle + // indefinitely. + _cursorTimer = Timer(Duration.zero, () => _cursorBlinkOpacityController.animateWith(_iosBlinkCursorSimulation).whenComplete(_onCursorTick)); + } else { + if (!(_cursorTimer?.isActive ?? false) && _tickersEnabled) { + _cursorTimer = Timer.periodic(_kCursorBlinkHalfPeriod, (Timer timer) { _onCursorTick(); }); + } + _cursorBlinkOpacityController.value = _cursorBlinkOpacityController.value == 0 ? 1 : 0; + } + } + + void _stopCursorBlink({ bool resetCharTicks = true }) { + _cursorBlinkOpacityController.value = 0.0; + _cursorTimer?.cancel(); + _cursorTimer = null; + if (resetCharTicks) { + _obscureShowCharTicksPending = 0; + } + } + + void _startOrStopCursorTimerIfNeeded() { + if (!_showBlinkingCursor) { + _stopCursorBlink(); + } else if (_cursorTimer == null) { + _startCursorBlink(); + } + } + + void _didChangeTextEditingValue() { + if (_hasFocus && !_value.selection.isValid) { + // If this field is focused and the selection is invalid, place the cursor at + // the end. Does not rely on _handleFocusChanged because it makes selection + // handles visible on Android. + // Unregister as a listener to the text controller while making the change. + widget.controller.removeListener(_didChangeTextEditingValue); + widget.controller.selection = _adjustedSelectionWhenFocused()!; + widget.controller.addListener(_didChangeTextEditingValue); + } + _updateRemoteEditingValueIfNeeded(); + _startOrStopCursorTimerIfNeeded(); + _updateOrDisposeSelectionOverlayIfNeeded(); + // TODO(abarth): Teach RenderEditable about ValueNotifier<TextEditingValue> + // to avoid this setState(). + setState(() { /* We use widget.controller.value in build(). */ }); + _verticalSelectionUpdateAction.stopCurrentVerticalRunIfSelectionChanges(); + } + + void _handleFocusChanged() { + _openOrCloseInputConnectionIfNeeded(); + _startOrStopCursorTimerIfNeeded(); + _updateOrDisposeSelectionOverlayIfNeeded(); + if (_hasFocus) { + // Listen for changing viewInsets, which indicates keyboard showing up. + WidgetsBinding.instance.addObserver(this); + _lastBottomViewInset = View.of(context).viewInsets.bottom; + if (!widget.readOnly) { + _scheduleShowCaretOnScreen(withAnimation: true); + } + final TextSelection? updatedSelection = _adjustedSelectionWhenFocused(); + if (updatedSelection != null) { + _handleSelectionChanged(updatedSelection, null); + } + } else { + WidgetsBinding.instance.removeObserver(this); + setState(() { _currentPromptRectRange = null; }); + } + updateKeepAlive(); + } + + TextSelection? _adjustedSelectionWhenFocused() { + TextSelection? selection; + final bool shouldSelectAll = widget.selectionEnabled && kIsWeb + && !_isMultiline && !_nextFocusChangeIsInternal; + if (shouldSelectAll) { + // On native web, single line <input> tags select all when receiving + // focus. + selection = TextSelection( + baseOffset: 0, + extentOffset: _value.text.length, + ); + } else if (!_value.selection.isValid) { + // Place cursor at the end if the selection is invalid when we receive focus. + selection = TextSelection.collapsed(offset: _value.text.length); + } + return selection; + } + + void _compositeCallback(Layer layer) { + // The callback can be invoked when the layer is detached. + // The input connection can be closed by the platform in which case this + // widget doesn't rebuild. + if (!renderEditable.attached || !_hasInputConnection) { + return; + } + assert(mounted); + assert((context as Element).debugIsActive); + _updateSizeAndTransform(); + } + + // Must be called after layout. + // See https://github.com/flutter/flutter/issues/126312 + void _updateSizeAndTransform() { + final Size size = renderEditable.size; + final Matrix4 transform = renderEditable.getTransformTo(null); + _textInputConnection!.setEditableSizeAndTransform(size, transform); + } + + void _schedulePeriodicPostFrameCallbacks([Duration? duration]) { + if (!_hasInputConnection) { + return; + } + _updateSelectionRects(); + _updateComposingRectIfNeeded(); + _updateCaretRectIfNeeded(); + SchedulerBinding.instance.addPostFrameCallback( + _schedulePeriodicPostFrameCallbacks, + debugLabel: 'EditableText.postFrameCallbacks' + ); + } + _ScribbleCacheKey? _scribbleCacheKey; + + void _updateSelectionRects({bool force = false}) { + if (!widget.scribbleEnabled || defaultTargetPlatform != TargetPlatform.iOS) { + return; + } + + final ScrollDirection scrollDirection = _scrollController.position.userScrollDirection; + if (scrollDirection != ScrollDirection.idle) { + return; + } + + final InlineSpan inlineSpan = renderEditable.text!; + final TextScaler effectiveTextScaler = switch ((widget.textScaler, widget.textScaleFactor)) { + (final TextScaler textScaler, _) => textScaler, + (null, final double textScaleFactor) => TextScaler.linear(textScaleFactor), + (null, null) => MediaQuery.textScalerOf(context), + }; + + final _ScribbleCacheKey newCacheKey = _ScribbleCacheKey( + inlineSpan: inlineSpan, + textAlign: widget.textAlign, + textDirection: _textDirection, + textScaler: effectiveTextScaler, + textHeightBehavior: widget.textHeightBehavior ?? DefaultTextHeightBehavior.maybeOf(context), + locale: widget.locale, + structStyle: widget.strutStyle, + placeholder: _placeholderLocation, + size: renderEditable.size, + ); + + final RenderComparison comparison = force + ? RenderComparison.layout + : _scribbleCacheKey?.compare(newCacheKey) ?? RenderComparison.layout; + if (comparison.index < RenderComparison.layout.index) { + return; + } + _scribbleCacheKey = newCacheKey; + + final List<SelectionRect> rects = <SelectionRect>[]; + int graphemeStart = 0; + // Can't use _value.text here: the controller value could change between + // frames. + final String plainText = inlineSpan.toPlainText(includeSemanticsLabels: false); + final CharacterRange characterRange = CharacterRange(plainText); + while (characterRange.moveNext()) { + final int graphemeEnd = graphemeStart + characterRange.current.length; + final List<TextBox> boxes = renderEditable.getBoxesForSelection( + TextSelection(baseOffset: graphemeStart, extentOffset: graphemeEnd), + ); + + final TextBox? box = boxes.isEmpty ? null : boxes.first; + if (box != null) { + final Rect paintBounds = renderEditable.paintBounds; + // Stop early when characters are already below the bottom edge of the + // RenderEditable, regardless of its clipBehavior. + if (paintBounds.bottom <= box.top) { + break; + } + // Include any TextBox which intersects with the RenderEditable. + if (paintBounds.left <= box.right && + box.left <= paintBounds.right && + paintBounds.top <= box.bottom) { + // At least some part of the letter is visible within the text field. + rects.add(SelectionRect(position: graphemeStart, bounds: box.toRect(), direction: box.direction)); + } + } + graphemeStart = graphemeEnd; + } + _textInputConnection!.setSelectionRects(rects); + } + + // Sends the current composing rect to the embedder's text input plugin. + // + // In cases where the composing rect hasn't been updated in the embedder due + // to the lag of asynchronous messages over the channel, the position of the + // current caret rect is used instead. + // + // See: [_updateCaretRectIfNeeded] + void _updateComposingRectIfNeeded() { + final TextRange composingRange = _value.composing; + assert(mounted); + Rect? composingRect = renderEditable.getRectForComposingRange(composingRange); + // Send the caret location instead if there's no marked text yet. + if (composingRect == null) { + assert(!composingRange.isValid || composingRange.isCollapsed); + final int offset = composingRange.isValid ? composingRange.start : 0; + composingRect = renderEditable.getLocalRectForCaret(TextPosition(offset: offset)); + } + _textInputConnection!.setComposingRect(composingRect); + } + + // Sends the current caret rect to the embedder's text input plugin. + // + // The position of the caret rect is updated periodically such that if the + // user initiates composing input, the current cursor rect can be used for + // the first character until the composing rect can be sent. + // + // On selection changes, the start of the selection is used. This ensures + // that regardless of the direction the selection was created, the cursor is + // set to the position where next text input occurs. This position is used to + // position the IME's candidate selection menu. + // + // See: [_updateComposingRectIfNeeded] + void _updateCaretRectIfNeeded() { + final TextSelection? selection = renderEditable.selection; + if (selection == null || !selection.isValid) { + return; + } + final TextPosition currentTextPosition = TextPosition(offset: selection.start); + final Rect caretRect = renderEditable.getLocalRectForCaret(currentTextPosition); + _textInputConnection!.setCaretRect(caretRect); + } + + TextDirection get _textDirection => widget.textDirection ?? Directionality.of(context); + + /// The renderer for this widget's descendant. + /// + /// This property is typically used to notify the renderer of input gestures + /// when [RenderEditable.ignorePointer] is true. + late final RenderEditable renderEditable = _editableKey.currentContext!.findRenderObject()! as RenderEditable; + + @override + TextEditingValue get textEditingValue => _value; + + double get _devicePixelRatio => MediaQuery.devicePixelRatioOf(context); + + @override + void userUpdateTextEditingValue(TextEditingValue value, SelectionChangedCause? cause) { + // Compare the current TextEditingValue with the pre-format new + // TextEditingValue value, in case the formatter would reject the change. + final bool shouldShowCaret = widget.readOnly + ? _value.selection != value.selection + : _value != value; + if (shouldShowCaret) { + _scheduleShowCaretOnScreen(withAnimation: true); + } + + // Even if the value doesn't change, it may be necessary to focus and build + // the selection overlay. For example, this happens when right clicking an + // unfocused field that previously had a selection in the same spot. + if (value == textEditingValue) { + if (!widget.focusNode.hasFocus) { + _flagInternalFocus(); + widget.focusNode.requestFocus(); + _selectionOverlay = _createSelectionOverlay(); + } + return; + } + + _formatAndSetValue(value, cause, userInteraction: true); + } + + @override + void bringIntoView(TextPosition position) { + final Rect localRect = renderEditable.getLocalRectForCaret(position); + final RevealedOffset targetOffset = _getOffsetToRevealCaret(localRect); + + _scrollController.jumpTo(targetOffset.offset); + renderEditable.showOnScreen(rect: targetOffset.rect); + } + + /// Shows the selection toolbar at the location of the current cursor. + /// + /// Returns `false` if a toolbar couldn't be shown, such as when the toolbar + /// is already shown, or when no text selection currently exists. + @override + bool showToolbar() { + // Web is using native dom elements to enable clipboard functionality of the + // context menu: copy, paste, select, cut. It might also provide additional + // functionality depending on the browser (such as translate). Due to this, + // we should not show a Flutter toolbar for the editable text elements + // unless the browser's context menu is explicitly disabled. + if (kIsWeb && BrowserContextMenu.enabled) { + return false; + } + + if (_selectionOverlay == null) { + return false; + } + _liveTextInputStatus?.update(); + clipboardStatus.update(); + _selectionOverlay!.showToolbar(); + return true; + } + + @override + void hideToolbar([bool hideHandles = true]) { + if (hideHandles) { + // Hide the handles and the toolbar. + _selectionOverlay?.hide(); + } else if (_selectionOverlay?.toolbarIsVisible ?? false) { + // Hide only the toolbar but not the handles. + _selectionOverlay?.hideToolbar(); + } + } + + /// Toggles the visibility of the toolbar. + void toggleToolbar([bool hideHandles = true]) { + final TextSelectionOverlay selectionOverlay = _selectionOverlay ??= _createSelectionOverlay(); + + if (selectionOverlay.toolbarIsVisible) { + hideToolbar(hideHandles); + } else { + showToolbar(); + } + } + + /// Shows toolbar with spell check suggestions of misspelled words that are + /// available for click-and-replace. + bool showSpellCheckSuggestionsToolbar() { + // Spell check suggestions toolbars are intended to be shown on non-web + // platforms. Additionally, the Cupertino style toolbar can't be drawn on + // the web with the HTML renderer due to + // https://github.com/flutter/flutter/issues/123560. + final bool platformNotSupported = kIsWeb && BrowserContextMenu.enabled; + if (!spellCheckEnabled + || platformNotSupported + || widget.readOnly + || _selectionOverlay == null + || !_spellCheckResultsReceived + || findSuggestionSpanAtCursorIndex(textEditingValue.selection.extentOffset) == null) { + // Only attempt to show the spell check suggestions toolbar if there + // is a toolbar specified and spell check suggestions available to show. + return false; + } + + assert( + _spellCheckConfiguration.spellCheckSuggestionsToolbarBuilder != null, + 'spellCheckSuggestionsToolbarBuilder must be defined in ' + 'SpellCheckConfiguration to show a toolbar with spell check ' + 'suggestions', + ); + + _selectionOverlay! + .showSpellCheckSuggestionsToolbar( + (BuildContext context) { + return _spellCheckConfiguration + .spellCheckSuggestionsToolbarBuilder!( + context, + this, + ); + }, + ); + return true; + } + + /// Shows the magnifier at the position given by `positionToShow`, + /// if there is no magnifier visible. + /// + /// Updates the magnifier to the position given by `positionToShow`, + /// if there is a magnifier visible. + /// + /// Does nothing if a magnifier couldn't be shown, such as when the selection + /// overlay does not currently exist. + void showMagnifier(Offset positionToShow) { + if (_selectionOverlay == null) { + return; + } + + if (_selectionOverlay!.magnifierIsVisible) { + _selectionOverlay!.updateMagnifier(positionToShow); + } else { + _selectionOverlay!.showMagnifier(positionToShow); + } + } + + /// Hides the magnifier if it is visible. + void hideMagnifier() { + if (_selectionOverlay == null) { + return; + } + + if (_selectionOverlay!.magnifierIsVisible) { + _selectionOverlay!.hideMagnifier(); + } + } + + // Tracks the location a [_ScribblePlaceholder] should be rendered in the + // text. + // + // A value of -1 indicates there should be no placeholder, otherwise the + // value should be between 0 and the length of the text, inclusive. + int _placeholderLocation = -1; + + @override + void insertTextPlaceholder(Size size) { + if (!widget.scribbleEnabled) { + return; + } + + if (!widget.controller.selection.isValid) { + return; + } + + setState(() { + _placeholderLocation = _value.text.length - widget.controller.selection.end; + }); + } + + @override + void removeTextPlaceholder() { + if (!widget.scribbleEnabled || _placeholderLocation == -1) { + return; + } + + setState(() { + _placeholderLocation = -1; + }); + } + + @override + void performSelector(String selectorName) { + final Intent? intent = intentForMacOSSelector(selectorName); + + if (intent != null) { + final BuildContext? primaryContext = primaryFocus?.context; + if (primaryContext != null) { + Actions.invoke(primaryContext, intent); + } + } + } + + @override + String get autofillId => 'EditableText-$hashCode'; + + @override + TextInputConfiguration get textInputConfiguration { + final List<String>? autofillHints = widget.autofillHints?.toList(growable: false); + final AutofillConfiguration autofillConfiguration = autofillHints != null + ? AutofillConfiguration( + uniqueIdentifier: autofillId, + autofillHints: autofillHints, + currentEditingValue: currentTextEditingValue, + ) + : AutofillConfiguration.disabled; + + return TextInputConfiguration( + inputType: widget.keyboardType, + readOnly: widget.readOnly, + obscureText: widget.obscureText, + autocorrect: widget.autocorrect, + smartDashesType: widget.smartDashesType, + smartQuotesType: widget.smartQuotesType, + enableSuggestions: widget.enableSuggestions, + enableInteractiveSelection: widget._userSelectionEnabled, + inputAction: widget.textInputAction ?? (widget.keyboardType == TextInputType.multiline + ? TextInputAction.newline + : TextInputAction.done + ), + textCapitalization: widget.textCapitalization, + keyboardAppearance: widget.keyboardAppearance, + autofillConfiguration: autofillConfiguration, + enableIMEPersonalizedLearning: widget.enableIMEPersonalizedLearning, + allowedMimeTypes: widget.contentInsertionConfiguration == null + ? const <String>[] + : widget.contentInsertionConfiguration!.allowedMimeTypes, + ); + } + + @override + void autofill(TextEditingValue value) => updateEditingValue(value); + + // null if no promptRect should be shown. + TextRange? _currentPromptRectRange; + + @override + void showAutocorrectionPromptRect(int start, int end) { + setState(() { + _currentPromptRectRange = TextRange(start: start, end: end); + }); + } + + VoidCallback? _semanticsOnCopy(TextSelectionControls? controls) { + return widget.selectionEnabled + && _hasFocus + && (widget.selectionControls is TextSelectionHandleControls + ? copyEnabled + : copyEnabled && (widget.selectionControls?.canCopy(this) ?? false)) + ? () { + controls?.handleCopy(this); + copySelection(SelectionChangedCause.toolbar); + } + : null; + } + + VoidCallback? _semanticsOnCut(TextSelectionControls? controls) { + return widget.selectionEnabled + && _hasFocus + && (widget.selectionControls is TextSelectionHandleControls + ? cutEnabled + : cutEnabled && (widget.selectionControls?.canCut(this) ?? false)) + ? () { + controls?.handleCut(this); + cutSelection(SelectionChangedCause.toolbar); + } + : null; + } + + VoidCallback? _semanticsOnPaste(TextSelectionControls? controls) { + return widget.selectionEnabled + && _hasFocus + && (widget.selectionControls is TextSelectionHandleControls + ? pasteEnabled + : pasteEnabled && (widget.selectionControls?.canPaste(this) ?? false)) + && (clipboardStatus.value == ClipboardStatus.pasteable) + ? () { + controls?.handlePaste(this); + pasteText(SelectionChangedCause.toolbar); + } + : null; + } + + // Returns the closest boundary location to `extent` but not including `extent` + // itself (unless already at the start/end of the text), in the direction + // specified by `forward`. + TextPosition _moveBeyondTextBoundary(TextPosition extent, bool forward, TextBoundary textBoundary) { + assert(extent.offset >= 0); + final int newOffset = forward + ? textBoundary.getTrailingTextBoundaryAt(extent.offset) ?? _value.text.length + // if x is a boundary defined by `textBoundary`, most textBoundaries (except + // LineBreaker) guarantees `x == textBoundary.getLeadingTextBoundaryAt(x)`. + // Use x - 1 here to make sure we don't get stuck at the fixed point x. + : textBoundary.getLeadingTextBoundaryAt(extent.offset - 1) ?? 0; + return TextPosition(offset: newOffset); + } + + // Returns the closest boundary location to `extent`, including `extent` + // itself, in the direction specified by `forward`. + // + // This method returns a fixed point of itself: applying `_toTextBoundary` + // again on the returned TextPosition gives the same TextPosition. It's used + // exclusively for handling line boundaries, since performing "move to line + // start" more than once usually doesn't move you to the previous line. + TextPosition _moveToTextBoundary(TextPosition extent, bool forward, TextBoundary textBoundary) { + assert(extent.offset >= 0); + final int caretOffset; + switch (extent.affinity) { + case TextAffinity.upstream: + if (extent.offset < 1 && !forward) { + assert (extent.offset == 0); + return const TextPosition(offset: 0); + } + // When the text affinity is upstream, the caret is associated with the + // grapheme before the code unit at `extent.offset`. + // TODO(LongCatIsLooong): don't assume extent.offset is at a grapheme + // boundary, and do this instead: + // final int graphemeStart = CharacterRange.at(string, extent.offset).stringBeforeLength - 1; + caretOffset = math.max(0, extent.offset - 1); + case TextAffinity.downstream: + caretOffset = extent.offset; + } + // The line boundary range does not include some control characters + // (most notably, Line Feed), in which case there's + // `x ∉ getTextBoundaryAt(x)`. In case `caretOffset` points to one such + // control character, we define that these control characters themselves are + // still part of the previous line, but also exclude them from the + // line boundary range since they're non-printing. IOW, no additional + // processing needed since the LineBoundary class does exactly that. + return forward + ? TextPosition(offset: textBoundary.getTrailingTextBoundaryAt(caretOffset) ?? _value.text.length, affinity: TextAffinity.upstream) + : TextPosition(offset: textBoundary.getLeadingTextBoundaryAt(caretOffset) ?? 0); + } + + // --------------------------- Text Editing Actions --------------------------- + + TextBoundary _characterBoundary() => widget.obscureText ? _CodePointBoundary(_value.text) : CharacterBoundary(_value.text); + TextBoundary _nextWordBoundary() => widget.obscureText ? _documentBoundary() : renderEditable.wordBoundaries.moveByWordBoundary; + TextBoundary _linebreak() => widget.obscureText ? _documentBoundary() : LineBoundary(renderEditable); + TextBoundary _paragraphBoundary() => ParagraphBoundary(_value.text); + TextBoundary _documentBoundary() => DocumentBoundary(_value.text); + + Action<T> _makeOverridable<T extends Intent>(Action<T> defaultAction) { + return Action<T>.overridable(context: context, defaultAction: defaultAction); + } + + /// Transpose the characters immediately before and after the current + /// collapsed selection. + /// + /// When the cursor is at the end of the text, transposes the last two + /// characters, if they exist. + /// + /// When the cursor is at the start of the text, does nothing. + void _transposeCharacters(TransposeCharactersIntent intent) { + if (_value.text.characters.length <= 1 + || !_value.selection.isCollapsed + || _value.selection.baseOffset == 0) { + return; + } + + final String text = _value.text; + final TextSelection selection = _value.selection; + final bool atEnd = selection.baseOffset == text.length; + final CharacterRange transposing = CharacterRange.at(text, selection.baseOffset); + if (atEnd) { + transposing.moveBack(2); + } else { + transposing..moveBack()..expandNext(); + } + assert(transposing.currentCharacters.length == 2); + + userUpdateTextEditingValue( + TextEditingValue( + text: transposing.stringBefore + + transposing.currentCharacters.last + + transposing.currentCharacters.first + + transposing.stringAfter, + selection: TextSelection.collapsed( + offset: transposing.stringBeforeLength + transposing.current.length, + ), + ), + SelectionChangedCause.keyboard, + ); + } + late final Action<TransposeCharactersIntent> _transposeCharactersAction = CallbackAction<TransposeCharactersIntent>(onInvoke: _transposeCharacters); + + void _replaceText(ReplaceTextIntent intent) { + final TextEditingValue oldValue = _value; + final TextEditingValue newValue = intent.currentTextEditingValue.replaced( + intent.replacementRange, + intent.replacementText, + ); + userUpdateTextEditingValue(newValue, intent.cause); + + // If there's no change in text and selection (e.g. when selecting and + // pasting identical text), the widget won't be rebuilt on value update. + // Handle this by calling _didChangeTextEditingValue() so caret and scroll + // updates can happen. + if (newValue == oldValue) { + _didChangeTextEditingValue(); + } + } + late final Action<ReplaceTextIntent> _replaceTextAction = CallbackAction<ReplaceTextIntent>(onInvoke: _replaceText); + + // Scrolls either to the beginning or end of the document depending on the + // intent's `forward` parameter. + void _scrollToDocumentBoundary(ScrollToDocumentBoundaryIntent intent) { + if (intent.forward) { + bringIntoView(TextPosition(offset: _value.text.length)); + } else { + bringIntoView(const TextPosition(offset: 0)); + } + } + + /// Handles [ScrollIntent] by scrolling the [Scrollable] inside of + /// [EditableText]. + void _scroll(ScrollIntent intent) { + if (intent.type != ScrollIncrementType.page) { + return; + } + + final ScrollPosition position = _scrollController.position; + if (widget.maxLines == 1) { + _scrollController.jumpTo(position.maxScrollExtent); + return; + } + + // If the field isn't scrollable, do nothing. For example, when the lines of + // text is less than maxLines, the field has nothing to scroll. + if (position.maxScrollExtent == 0.0 && position.minScrollExtent == 0.0) { + return; + } + + final ScrollableState? state = _scrollableKey.currentState as ScrollableState?; + final double increment = ScrollAction.getDirectionalIncrement(state!, intent); + final double destination = clampDouble( + position.pixels + increment, + position.minScrollExtent, + position.maxScrollExtent, + ); + if (destination == position.pixels) { + return; + } + _scrollController.jumpTo(destination); + } + + /// Extend the selection down by page if the `forward` parameter is true, or + /// up by page otherwise. + void _extendSelectionByPage(ExtendSelectionByPageIntent intent) { + if (widget.maxLines == 1) { + return; + } + + final TextSelection nextSelection; + final Rect extentRect = renderEditable.getLocalRectForCaret( + _value.selection.extent, + ); + final ScrollableState? state = _scrollableKey.currentState as ScrollableState?; + final double increment = ScrollAction.getDirectionalIncrement( + state!, + ScrollIntent( + direction: intent.forward ? AxisDirection.down : AxisDirection.up, + type: ScrollIncrementType.page, + ), + ); + final ScrollPosition position = _scrollController.position; + if (intent.forward) { + if (_value.selection.extentOffset >= _value.text.length) { + return; + } + final Offset nextExtentOffset = + Offset(extentRect.left, extentRect.top + increment); + final double height = position.maxScrollExtent + renderEditable.size.height; + final TextPosition nextExtent = nextExtentOffset.dy + position.pixels >= height + ? TextPosition(offset: _value.text.length) + : renderEditable.getPositionForPoint( + renderEditable.localToGlobal(nextExtentOffset), + ); + nextSelection = _value.selection.copyWith( + extentOffset: nextExtent.offset, + ); + } else { + if (_value.selection.extentOffset <= 0) { + return; + } + final Offset nextExtentOffset = + Offset(extentRect.left, extentRect.top + increment); + final TextPosition nextExtent = nextExtentOffset.dy + position.pixels <= 0 + ? const TextPosition(offset: 0) + : renderEditable.getPositionForPoint( + renderEditable.localToGlobal(nextExtentOffset), + ); + nextSelection = _value.selection.copyWith( + extentOffset: nextExtent.offset, + ); + } + + bringIntoView(nextSelection.extent); + userUpdateTextEditingValue( + _value.copyWith(selection: nextSelection), + SelectionChangedCause.keyboard, + ); + } + + void _updateSelection(UpdateSelectionIntent intent) { + assert( + intent.newSelection.start <= intent.currentTextEditingValue.text.length, + 'invalid selection: ${intent.newSelection}: it must not exceed the current text length ${intent.currentTextEditingValue.text.length}', + ); + assert( + intent.newSelection.end <= intent.currentTextEditingValue.text.length, + 'invalid selection: ${intent.newSelection}: it must not exceed the current text length ${intent.currentTextEditingValue.text.length}', + ); + + bringIntoView(intent.newSelection.extent); + userUpdateTextEditingValue( + intent.currentTextEditingValue.copyWith(selection: intent.newSelection), + intent.cause, + ); + } + late final Action<UpdateSelectionIntent> _updateSelectionAction = CallbackAction<UpdateSelectionIntent>(onInvoke: _updateSelection); + + late final _UpdateTextSelectionVerticallyAction<DirectionalCaretMovementIntent> _verticalSelectionUpdateAction = + _UpdateTextSelectionVerticallyAction<DirectionalCaretMovementIntent>(this); + + Object? _hideToolbarIfVisible(DismissIntent intent) { + if (_selectionOverlay?.toolbarIsVisible ?? false) { + hideToolbar(false); + return null; + } + return Actions.invoke(context, intent); + } + + + /// The default behavior used if [onTapOutside] is null. + /// + /// The `event` argument is the [PointerDownEvent] that caused the notification. + void _defaultOnTapOutside(PointerDownEvent event) { + /// The focus dropping behavior is only present on desktop platforms + /// and mobile browsers. + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + case TargetPlatform.fuchsia: + // On mobile platforms, we don't unfocus on touch events unless they're + // in the web browser, but we do unfocus for all other kinds of events. + switch (event.kind) { + case ui.PointerDeviceKind.touch: + if (kIsWeb) { + widget.focusNode.unfocus(); + } + case ui.PointerDeviceKind.mouse: + case ui.PointerDeviceKind.stylus: + case ui.PointerDeviceKind.invertedStylus: + case ui.PointerDeviceKind.unknown: + widget.focusNode.unfocus(); + case ui.PointerDeviceKind.trackpad: + throw UnimplementedError('Unexpected pointer down event for trackpad'); + } + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + widget.focusNode.unfocus(); + } + } + + late final Map<Type, Action<Intent>> _actions = <Type, Action<Intent>>{ + DoNothingAndStopPropagationTextIntent: DoNothingAction(consumesKey: false), + ReplaceTextIntent: _replaceTextAction, + UpdateSelectionIntent: _updateSelectionAction, + DirectionalFocusIntent: DirectionalFocusAction.forTextField(), + DismissIntent: CallbackAction<DismissIntent>(onInvoke: _hideToolbarIfVisible), + + // Delete + DeleteCharacterIntent: _makeOverridable(_DeleteTextAction<DeleteCharacterIntent>(this, _characterBoundary, _moveBeyondTextBoundary)), + DeleteToNextWordBoundaryIntent: _makeOverridable(_DeleteTextAction<DeleteToNextWordBoundaryIntent>(this, _nextWordBoundary, _moveBeyondTextBoundary)), + DeleteToLineBreakIntent: _makeOverridable(_DeleteTextAction<DeleteToLineBreakIntent>(this, _linebreak, _moveToTextBoundary)), + + // Extend/Move Selection + ExtendSelectionByCharacterIntent: _makeOverridable(_UpdateTextSelectionAction<ExtendSelectionByCharacterIntent>(this, _characterBoundary, _moveBeyondTextBoundary, ignoreNonCollapsedSelection: false)), + ExtendSelectionByPageIntent: _makeOverridable(CallbackAction<ExtendSelectionByPageIntent>(onInvoke: _extendSelectionByPage)), + ExtendSelectionToNextWordBoundaryIntent: _makeOverridable(_UpdateTextSelectionAction<ExtendSelectionToNextWordBoundaryIntent>(this, _nextWordBoundary, _moveBeyondTextBoundary, ignoreNonCollapsedSelection: true)), + ExtendSelectionToNextParagraphBoundaryIntent : _makeOverridable(_UpdateTextSelectionAction<ExtendSelectionToNextParagraphBoundaryIntent>(this, _paragraphBoundary, _moveBeyondTextBoundary, ignoreNonCollapsedSelection: true)), + ExtendSelectionToLineBreakIntent: _makeOverridable(_UpdateTextSelectionAction<ExtendSelectionToLineBreakIntent>(this, _linebreak, _moveToTextBoundary, ignoreNonCollapsedSelection: true)), + ExtendSelectionVerticallyToAdjacentLineIntent: _makeOverridable(_verticalSelectionUpdateAction), + ExtendSelectionVerticallyToAdjacentPageIntent: _makeOverridable(_verticalSelectionUpdateAction), + ExtendSelectionToNextParagraphBoundaryOrCaretLocationIntent: _makeOverridable(_UpdateTextSelectionAction<ExtendSelectionToNextParagraphBoundaryOrCaretLocationIntent>(this, _paragraphBoundary, _moveBeyondTextBoundary, ignoreNonCollapsedSelection: true)), + ExtendSelectionToDocumentBoundaryIntent: _makeOverridable(_UpdateTextSelectionAction<ExtendSelectionToDocumentBoundaryIntent>(this, _documentBoundary, _moveBeyondTextBoundary, ignoreNonCollapsedSelection: true)), + ExtendSelectionToNextWordBoundaryOrCaretLocationIntent: _makeOverridable(_UpdateTextSelectionAction<ExtendSelectionToNextWordBoundaryOrCaretLocationIntent>(this, _nextWordBoundary, _moveBeyondTextBoundary, ignoreNonCollapsedSelection: true)), + ScrollToDocumentBoundaryIntent: _makeOverridable(CallbackAction<ScrollToDocumentBoundaryIntent>(onInvoke: _scrollToDocumentBoundary)), + ScrollIntent: CallbackAction<ScrollIntent>(onInvoke: _scroll), + + // Expand Selection + ExpandSelectionToLineBreakIntent: _makeOverridable(_UpdateTextSelectionAction<ExpandSelectionToLineBreakIntent>(this, _linebreak, _moveToTextBoundary, ignoreNonCollapsedSelection: true, isExpand: true)), + ExpandSelectionToDocumentBoundaryIntent: _makeOverridable(_UpdateTextSelectionAction<ExpandSelectionToDocumentBoundaryIntent>(this, _documentBoundary, _moveToTextBoundary, ignoreNonCollapsedSelection: true, isExpand: true, extentAtIndex: true)), + + // Copy Paste + SelectAllTextIntent: _makeOverridable(_SelectAllAction(this)), + CopySelectionTextIntent: _makeOverridable(_CopySelectionAction(this)), + PasteTextIntent: _makeOverridable(CallbackAction<PasteTextIntent>(onInvoke: (PasteTextIntent intent) => pasteText(intent.cause))), + + TransposeCharactersIntent: _makeOverridable(_transposeCharactersAction), + }; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + super.build(context); // See AutomaticKeepAliveClientMixin. + + final TextSelectionControls? controls = widget.selectionControls; + final TextScaler effectiveTextScaler = switch ((widget.textScaler, widget.textScaleFactor)) { + (final TextScaler textScaler, _) => textScaler, + (null, final double textScaleFactor) => TextScaler.linear(textScaleFactor), + (null, null) => MediaQuery.textScalerOf(context), + }; + + return _CompositionCallback( + compositeCallback: _compositeCallback, + enabled: _hasInputConnection, + child: TextFieldTapRegion( + onTapOutside: _hasFocus ? widget.onTapOutside ?? _defaultOnTapOutside : null, + debugLabel: kReleaseMode ? null : 'EditableText', + child: MouseRegion( + cursor: widget.mouseCursor ?? SystemMouseCursors.text, + child: Actions( + actions: _actions, + child: UndoHistory<TextEditingValue>( + value: widget.controller, + onTriggered: (TextEditingValue value) { + userUpdateTextEditingValue(value, SelectionChangedCause.keyboard); + }, + shouldChangeUndoStack: (TextEditingValue? oldValue, TextEditingValue newValue) { + if (!newValue.selection.isValid) { + return false; + } + + if (oldValue == null) { + return true; + } + + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + // Composing text is not counted in history coalescing. + if (!widget.controller.value.composing.isCollapsed) { + return false; + } + case TargetPlatform.android: + // Gboard on Android puts non-CJK words in composing regions. Coalesce + // composing text in order to allow the saving of partial words in that + // case. + break; + } + + return oldValue.text != newValue.text || oldValue.composing != newValue.composing; + }, + undoStackModifier: (TextEditingValue value) { + // On Android we should discard the composing region when pushing + // a new entry to the undo stack. This prevents the TextInputPlugin + // from restarting the input on every undo/redo when the composing + // region is changed by the framework. + return defaultTargetPlatform == TargetPlatform.android ? value.copyWith(composing: TextRange.empty) : value; + }, + focusNode: widget.focusNode, + controller: widget.undoController, + child: Focus( + focusNode: widget.focusNode, + includeSemantics: false, + debugLabel: kReleaseMode ? null : 'EditableText', + child: Scrollable( + key: _scrollableKey, + excludeFromSemantics: true, + axisDirection: _isMultiline ? AxisDirection.down : AxisDirection.right, + controller: _scrollController, + physics: widget.scrollPhysics, + dragStartBehavior: widget.dragStartBehavior, + restorationId: widget.restorationId, + // If a ScrollBehavior is not provided, only apply scrollbars when + // multiline. The overscroll indicator should not be applied in + // either case, glowing or stretching. + scrollBehavior: widget.scrollBehavior ?? ScrollConfiguration.of(context).copyWith( + scrollbars: _isMultiline, + overscroll: false, + ), + viewportBuilder: (BuildContext context, ViewportOffset offset) { + return CompositedTransformTarget( + link: _toolbarLayerLink, + child: Semantics( + onCopy: _semanticsOnCopy(controls), + onCut: _semanticsOnCut(controls), + onPaste: _semanticsOnPaste(controls), + child: _ScribbleFocusable( + focusNode: widget.focusNode, + editableKey: _editableKey, + enabled: widget.scribbleEnabled, + updateSelectionRects: () { + _openInputConnection(); + _updateSelectionRects(force: true); + }, + child: _Editable( + key: _editableKey, + startHandleLayerLink: _startHandleLayerLink, + endHandleLayerLink: _endHandleLayerLink, + inlineSpan: buildTextSpan(), + value: _value, + cursorColor: _cursorColor, + backgroundCursorColor: widget.backgroundCursorColor, + showCursor: _cursorVisibilityNotifier, + forceLine: widget.forceLine, + readOnly: widget.readOnly, + hasFocus: _hasFocus, + maxLines: widget.maxLines, + minLines: widget.minLines, + expands: widget.expands, + strutStyle: widget.strutStyle, + selectionColor: _selectionOverlay?.spellCheckToolbarIsVisible ?? false + ? _spellCheckConfiguration.misspelledSelectionColor ?? widget.selectionColor + : widget.selectionColor, + textScaler: effectiveTextScaler, + textAlign: widget.textAlign, + textDirection: _textDirection, + locale: widget.locale, + textHeightBehavior: widget.textHeightBehavior ?? DefaultTextHeightBehavior.maybeOf(context), + textWidthBasis: widget.textWidthBasis, + obscuringCharacter: widget.obscuringCharacter, + obscureText: widget.obscureText, + offset: offset, + rendererIgnoresPointer: widget.rendererIgnoresPointer, + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: widget.cursorRadius, + cursorOffset: widget.cursorOffset ?? Offset.zero, + selectionHeightStyle: widget.selectionHeightStyle, + selectionWidthStyle: widget.selectionWidthStyle, + paintCursorAboveText: widget.paintCursorAboveText, + enableInteractiveSelection: widget._userSelectionEnabled, + textSelectionDelegate: this, + devicePixelRatio: _devicePixelRatio, + promptRectRange: _currentPromptRectRange, + promptRectColor: widget.autocorrectionTextRectColor, + clipBehavior: widget.clipBehavior, + ), + ), + ), + ); + }, + ), + ), + ), + ), + ), + ), + ); + } + + /// Builds [TextSpan] from current editing value. + /// + /// By default makes text in composing range appear as underlined. + /// Descendants can override this method to customize appearance of text. + TextSpan buildTextSpan() { + + if (widget.obscureText) { + String text = _value.text; + text = widget.obscuringCharacter * text.length; + // Reveal the latest character in an obscured field only on mobile. + // Newer versions of iOS (iOS 15+) no longer reveal the most recently + // entered character. + const Set<TargetPlatform> mobilePlatforms = <TargetPlatform> { + TargetPlatform.android, TargetPlatform.fuchsia, + }; + final bool brieflyShowPassword = WidgetsBinding.instance.platformDispatcher.brieflyShowPassword + && mobilePlatforms.contains(defaultTargetPlatform); + if (brieflyShowPassword) { + final int? o = _obscureShowCharTicksPending > 0 ? _obscureLatestCharIndex : null; + if (o != null && o >= 0 && o < text.length) { + text = text.replaceRange(o, o + 1, _value.text.substring(o, o + 1)); + } + } + return TextSpan(style: _style, text: text); + } + if (_placeholderLocation >= 0 && _placeholderLocation <= _value.text.length) { + final List<_ScribblePlaceholder> placeholders = <_ScribblePlaceholder>[]; + final int placeholderLocation = _value.text.length - _placeholderLocation; + if (_isMultiline) { + // The zero size placeholder here allows the line to break and keep the caret on the first line. + placeholders.add(const _ScribblePlaceholder(child: SizedBox.shrink(), size: Size.zero)); + placeholders.add(_ScribblePlaceholder(child: const SizedBox.shrink(), size: Size(renderEditable.size.width, 0.0))); + } else { + placeholders.add(const _ScribblePlaceholder(child: SizedBox.shrink(), size: Size(100.0, 0.0))); + } + return TextSpan(style: _style, children: <InlineSpan>[ + TextSpan(text: _value.text.substring(0, placeholderLocation)), + ...placeholders, + TextSpan(text: _value.text.substring(placeholderLocation)), + ], + ); + } + final bool withComposing = !widget.readOnly && _hasFocus; + if (_spellCheckResultsReceived) { + // If the composing range is out of range for the current text, ignore it to + // preserve the tree integrity, otherwise in release mode a RangeError will + // be thrown and this EditableText will be built with a broken subtree. + assert(!_value.composing.isValid || !withComposing || _value.isComposingRangeValid); + + final bool composingRegionOutOfRange = !_value.isComposingRangeValid || !withComposing; + + return buildTextSpanWithSpellCheckSuggestions( + _value, + composingRegionOutOfRange, + _style, + _spellCheckConfiguration.misspelledTextStyle!, + spellCheckResults!, + ); + } + + // Read only mode should not paint text composing. + return widget.controller.buildTextSpan( + context: context, + style: _style, + withComposing: withComposing, + ); + } +} + +class _Editable extends MultiChildRenderObjectWidget { + _Editable({ + super.key, + required this.inlineSpan, + required this.value, + required this.startHandleLayerLink, + required this.endHandleLayerLink, + this.cursorColor, + this.backgroundCursorColor, + required this.showCursor, + required this.forceLine, + required this.readOnly, + this.textHeightBehavior, + required this.textWidthBasis, + required this.hasFocus, + required this.maxLines, + this.minLines, + required this.expands, + this.strutStyle, + this.selectionColor, + required this.textScaler, + required this.textAlign, + required this.textDirection, + this.locale, + required this.obscuringCharacter, + required this.obscureText, + required this.offset, + this.rendererIgnoresPointer = false, + required this.cursorWidth, + this.cursorHeight, + this.cursorRadius, + required this.cursorOffset, + required this.paintCursorAboveText, + this.selectionHeightStyle = ui.BoxHeightStyle.tight, + this.selectionWidthStyle = ui.BoxWidthStyle.tight, + this.enableInteractiveSelection = true, + required this.textSelectionDelegate, + required this.devicePixelRatio, + this.promptRectRange, + this.promptRectColor, + required this.clipBehavior, + }) : super(children: WidgetSpan.extractFromInlineSpan(inlineSpan, textScaler)); + + final InlineSpan inlineSpan; + final TextEditingValue value; + final Color? cursorColor; + final LayerLink startHandleLayerLink; + final LayerLink endHandleLayerLink; + final Color? backgroundCursorColor; + final ValueNotifier<bool> showCursor; + final bool forceLine; + final bool readOnly; + final bool hasFocus; + final int? maxLines; + final int? minLines; + final bool expands; + final StrutStyle? strutStyle; + final Color? selectionColor; + final TextScaler textScaler; + final TextAlign textAlign; + final TextDirection textDirection; + final Locale? locale; + final String obscuringCharacter; + final bool obscureText; + final TextHeightBehavior? textHeightBehavior; + final TextWidthBasis textWidthBasis; + final ViewportOffset offset; + final bool rendererIgnoresPointer; + final double cursorWidth; + final double? cursorHeight; + final Radius? cursorRadius; + final Offset cursorOffset; + final bool paintCursorAboveText; + final ui.BoxHeightStyle selectionHeightStyle; + final ui.BoxWidthStyle selectionWidthStyle; + final bool enableInteractiveSelection; + final TextSelectionDelegate textSelectionDelegate; + final double devicePixelRatio; + final TextRange? promptRectRange; + final Color? promptRectColor; + final Clip clipBehavior; + + @override + RenderEditable createRenderObject(BuildContext context) { + return RenderEditable( + text: inlineSpan, + cursorColor: cursorColor, + startHandleLayerLink: startHandleLayerLink, + endHandleLayerLink: endHandleLayerLink, + backgroundCursorColor: backgroundCursorColor, + showCursor: showCursor, + forceLine: forceLine, + readOnly: readOnly, + hasFocus: hasFocus, + maxLines: maxLines, + minLines: minLines, + expands: expands, + strutStyle: strutStyle, + selectionColor: selectionColor, + textScaler: textScaler, + textAlign: textAlign, + textDirection: textDirection, + locale: locale ?? Localizations.maybeLocaleOf(context), + selection: value.selection, + offset: offset, + ignorePointer: rendererIgnoresPointer, + obscuringCharacter: obscuringCharacter, + obscureText: obscureText, + textHeightBehavior: textHeightBehavior, + textWidthBasis: textWidthBasis, + cursorWidth: cursorWidth, + cursorHeight: cursorHeight, + cursorRadius: cursorRadius, + cursorOffset: cursorOffset, + paintCursorAboveText: paintCursorAboveText, + selectionHeightStyle: selectionHeightStyle, + selectionWidthStyle: selectionWidthStyle, + enableInteractiveSelection: enableInteractiveSelection, + textSelectionDelegate: textSelectionDelegate, + devicePixelRatio: devicePixelRatio, + promptRectRange: promptRectRange, + promptRectColor: promptRectColor, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderEditable renderObject) { + renderObject + ..text = inlineSpan + ..cursorColor = cursorColor + ..startHandleLayerLink = startHandleLayerLink + ..endHandleLayerLink = endHandleLayerLink + ..backgroundCursorColor = backgroundCursorColor + ..showCursor = showCursor + ..forceLine = forceLine + ..readOnly = readOnly + ..hasFocus = hasFocus + ..maxLines = maxLines + ..minLines = minLines + ..expands = expands + ..strutStyle = strutStyle + ..selectionColor = selectionColor + ..textScaler = textScaler + ..textAlign = textAlign + ..textDirection = textDirection + ..locale = locale ?? Localizations.maybeLocaleOf(context) + ..selection = value.selection + ..offset = offset + ..ignorePointer = rendererIgnoresPointer + ..textHeightBehavior = textHeightBehavior + ..textWidthBasis = textWidthBasis + ..obscuringCharacter = obscuringCharacter + ..obscureText = obscureText + ..cursorWidth = cursorWidth + ..cursorHeight = cursorHeight + ..cursorRadius = cursorRadius + ..cursorOffset = cursorOffset + ..selectionHeightStyle = selectionHeightStyle + ..selectionWidthStyle = selectionWidthStyle + ..enableInteractiveSelection = enableInteractiveSelection + ..textSelectionDelegate = textSelectionDelegate + ..devicePixelRatio = devicePixelRatio + ..paintCursorAboveText = paintCursorAboveText + ..promptRectColor = promptRectColor + ..clipBehavior = clipBehavior + ..setPromptRectRange(promptRectRange); + } +} + +@immutable +class _ScribbleCacheKey { + const _ScribbleCacheKey({ + required this.inlineSpan, + required this.textAlign, + required this.textDirection, + required this.textScaler, + required this.textHeightBehavior, + required this.locale, + required this.structStyle, + required this.placeholder, + required this.size, + }); + + final TextAlign textAlign; + final TextDirection textDirection; + final TextScaler textScaler; + final TextHeightBehavior? textHeightBehavior; + final Locale? locale; + final StrutStyle structStyle; + final int placeholder; + final Size size; + final InlineSpan inlineSpan; + + RenderComparison compare(_ScribbleCacheKey other) { + if (identical(other, this)) { + return RenderComparison.identical; + } + final bool needsLayout = textAlign != other.textAlign + || textDirection != other.textDirection + || textScaler != other.textScaler + || (textHeightBehavior ?? const TextHeightBehavior()) != (other.textHeightBehavior ?? const TextHeightBehavior()) + || locale != other.locale + || structStyle != other.structStyle + || placeholder != other.placeholder + || size != other.size; + return needsLayout ? RenderComparison.layout : inlineSpan.compareTo(other.inlineSpan); + } +} + +class _ScribbleFocusable extends StatefulWidget { + const _ScribbleFocusable({ + required this.child, + required this.focusNode, + required this.editableKey, + required this.updateSelectionRects, + required this.enabled, + }); + + final Widget child; + final FocusNode focusNode; + final GlobalKey editableKey; + final VoidCallback updateSelectionRects; + final bool enabled; + + @override + _ScribbleFocusableState createState() => _ScribbleFocusableState(); +} + +class _ScribbleFocusableState extends State<_ScribbleFocusable> implements ScribbleClient { + _ScribbleFocusableState(): _elementIdentifier = (_nextElementIdentifier++).toString(); + + @override + void initState() { + super.initState(); + if (widget.enabled) { + TextInput.registerScribbleElement(elementIdentifier, this); + } + } + + @override + void didUpdateWidget(_ScribbleFocusable oldWidget) { + super.didUpdateWidget(oldWidget); + if (!oldWidget.enabled && widget.enabled) { + TextInput.registerScribbleElement(elementIdentifier, this); + } + + if (oldWidget.enabled && !widget.enabled) { + TextInput.unregisterScribbleElement(elementIdentifier); + } + } + + @override + void dispose() { + TextInput.unregisterScribbleElement(elementIdentifier); + super.dispose(); + } + + RenderEditable? get renderEditable => widget.editableKey.currentContext?.findRenderObject() as RenderEditable?; + + static int _nextElementIdentifier = 1; + final String _elementIdentifier; + + @override + String get elementIdentifier => _elementIdentifier; + + @override + void onScribbleFocus(Offset offset) { + widget.focusNode.requestFocus(); + renderEditable?.selectPositionAt(from: offset, cause: SelectionChangedCause.scribble); + widget.updateSelectionRects(); + } + + @override + bool isInScribbleRect(Rect rect) { + final Rect calculatedBounds = bounds; + if (renderEditable?.readOnly ?? false) { + return false; + } + if (calculatedBounds == Rect.zero) { + return false; + } + if (!calculatedBounds.overlaps(rect)) { + return false; + } + final Rect intersection = calculatedBounds.intersect(rect); + final HitTestResult result = HitTestResult(); + WidgetsBinding.instance.hitTestInView(result, intersection.center, View.of(context).viewId); + return result.path.any((HitTestEntry entry) => entry.target == renderEditable); + } + + @override + Rect get bounds { + final RenderBox? box = context.findRenderObject() as RenderBox?; + if (box == null || !mounted || !box.attached) { + return Rect.zero; + } + final Matrix4 transform = box.getTransformTo(null); + return MatrixUtils.transformRect(transform, Rect.fromLTWH(0, 0, box.size.width, box.size.height)); + } + + @override + Widget build(BuildContext context) { + return widget.child; + } +} + +class _ScribblePlaceholder extends WidgetSpan { + const _ScribblePlaceholder({ + required super.child, + required this.size, + }); + + /// The size of the span, used in place of adding a placeholder size to the [TextPainter]. + final Size size; + + @override + void build(ui.ParagraphBuilder builder, { + TextScaler textScaler = TextScaler.noScaling, + List<PlaceholderDimensions>? dimensions, + }) { + assert(debugAssertIsValid()); + final bool hasStyle = style != null; + if (hasStyle) { + builder.pushStyle(style!.getTextStyle(textScaler: textScaler)); + } + builder.addPlaceholder( + size.width * textScaler.textScaleFactor, + size.height * textScaler.textScaleFactor, + alignment, + ); + if (hasStyle) { + builder.pop(); + } + } +} + +/// A text boundary that uses code points as logical boundaries. +/// +/// A code point represents a single character. This may be smaller than what is +/// represented by a user-perceived character, or grapheme. For example, a +/// single grapheme (in this case a Unicode extended grapheme cluster) like +/// "👨‍👩‍👦" consists of five code points: the man emoji, a zero +/// width joiner, the woman emoji, another zero width joiner, and the boy emoji. +/// The [String] has a length of eight because each emoji consists of two code +/// units. +/// +/// Code units are the units by which Dart's String class is measured, which is +/// encoded in UTF-16. +/// +/// See also: +/// +/// * [String.runes], which deals with code points like this class. +/// * [String.characters], which deals with graphemes. +/// * [CharacterBoundary], which is a [TextBoundary] like this class, but whose +/// boundaries are graphemes instead of code points. +class _CodePointBoundary extends TextBoundary { + const _CodePointBoundary(this._text); + + final String _text; + + // Returns true if the given position falls in the center of a surrogate pair. + bool _breaksSurrogatePair(int position) { + assert(position > 0 && position < _text.length && _text.length > 1); + return TextPainter.isHighSurrogate(_text.codeUnitAt(position - 1)) + && TextPainter.isLowSurrogate(_text.codeUnitAt(position)); + } + + @override + int? getLeadingTextBoundaryAt(int position) { + if (_text.isEmpty || position < 0) { + return null; + } + if (position == 0) { + return 0; + } + if (position >= _text.length) { + return _text.length; + } + if (_text.length <= 1) { + return position; + } + + return _breaksSurrogatePair(position) + ? position - 1 + : position; + } + + @override + int? getTrailingTextBoundaryAt(int position) { + if (_text.isEmpty || position >= _text.length) { + return null; + } + if (position < 0) { + return 0; + } + if (position == _text.length - 1) { + return _text.length; + } + if (_text.length <= 1) { + return position; + } + + return _breaksSurrogatePair(position + 1) + ? position + 2 + : position + 1; + } +} + +// ------------------------------- Text Actions ------------------------------- +class _DeleteTextAction<T extends DirectionalTextEditingIntent> extends ContextAction<T> { + _DeleteTextAction(this.state, this.getTextBoundary, this._applyTextBoundary); + + final EditableTextState state; + final TextBoundary Function() getTextBoundary; + final _ApplyTextBoundary _applyTextBoundary; + + @override + Object? invoke(T intent, [BuildContext? context]) { + final TextSelection selection = state._value.selection; + if (!selection.isValid) { + return null; + } + assert(selection.isValid); + // Expands the selection to ensure the range covers full graphemes. + final TextBoundary atomicBoundary = state._characterBoundary(); + if (!selection.isCollapsed) { + // Expands the selection to ensure the range covers full graphemes. + final TextRange range = TextRange( + start: atomicBoundary.getLeadingTextBoundaryAt(selection.start) ?? state._value.text.length, + end: atomicBoundary.getTrailingTextBoundaryAt(selection.end - 1) ?? 0, + ); + return Actions.invoke( + context!, + ReplaceTextIntent(state._value, '', range, SelectionChangedCause.keyboard), + ); + } + + final int target = _applyTextBoundary(selection.base, intent.forward, getTextBoundary()).offset; + + final TextRange rangeToDelete = TextSelection( + baseOffset: intent.forward + ? atomicBoundary.getLeadingTextBoundaryAt(selection.baseOffset) ?? state._value.text.length + : atomicBoundary.getTrailingTextBoundaryAt(selection.baseOffset - 1) ?? 0, + extentOffset: target, + ); + return Actions.invoke( + context!, + ReplaceTextIntent(state._value, '', rangeToDelete, SelectionChangedCause.keyboard), + ); + } + + @override + bool get isActionEnabled => !state.widget.readOnly && state._value.selection.isValid; +} + +class _UpdateTextSelectionAction<T extends DirectionalCaretMovementIntent> extends ContextAction<T> { + _UpdateTextSelectionAction( + this.state, + this.getTextBoundary, + this.applyTextBoundary, { + required this.ignoreNonCollapsedSelection, + this.isExpand = false, + this.extentAtIndex = false, + }); + + final EditableTextState state; + final bool ignoreNonCollapsedSelection; + final bool isExpand; + final bool extentAtIndex; + final TextBoundary Function() getTextBoundary; + final _ApplyTextBoundary applyTextBoundary; + + static const int NEWLINE_CODE_UNIT = 10; + + // Returns true iff the given position is at a wordwrap boundary in the + // upstream position. + bool _isAtWordwrapUpstream(TextPosition position) { + final TextPosition end = TextPosition( + offset: state.renderEditable.getLineAtOffset(position).end, + affinity: TextAffinity.upstream, + ); + return end == position && end.offset != state.textEditingValue.text.length + && state.textEditingValue.text.codeUnitAt(position.offset) != NEWLINE_CODE_UNIT; + } + + // Returns true if the given position at a wordwrap boundary in the + // downstream position. + bool _isAtWordwrapDownstream(TextPosition position) { + final TextPosition start = TextPosition( + offset: state.renderEditable.getLineAtOffset(position).start, + ); + return start == position && start.offset != 0 + && state.textEditingValue.text.codeUnitAt(position.offset - 1) != NEWLINE_CODE_UNIT; + } + + @override + Object? invoke(T intent, [BuildContext? context]) { + final TextSelection selection = state._value.selection; + assert(selection.isValid); + + final bool collapseSelection = intent.collapseSelection || !state.widget.selectionEnabled; + if (!selection.isCollapsed && !ignoreNonCollapsedSelection && collapseSelection) { + return Actions.invoke(context!, UpdateSelectionIntent( + state._value, + TextSelection.collapsed(offset: intent.forward ? selection.end : selection.start), + SelectionChangedCause.keyboard, + )); + } + + TextPosition extent = selection.extent; + // If continuesAtWrap is true extent and is at the relevant wordwrap, then + // move it just to the other side of the wordwrap. + if (intent.continuesAtWrap) { + if (intent.forward && _isAtWordwrapUpstream(extent)) { + extent = TextPosition( + offset: extent.offset, + ); + } else if (!intent.forward && _isAtWordwrapDownstream(extent)) { + extent = TextPosition( + offset: extent.offset, + affinity: TextAffinity.upstream, + ); + } + } + + final bool shouldTargetBase = isExpand && (intent.forward ? selection.baseOffset > selection.extentOffset : selection.baseOffset < selection.extentOffset); + final TextPosition newExtent = applyTextBoundary(shouldTargetBase ? selection.base : extent, intent.forward, getTextBoundary()); + final TextSelection newSelection = collapseSelection || (!isExpand && newExtent.offset == selection.baseOffset) + ? TextSelection.fromPosition(newExtent) + : isExpand ? selection.expandTo(newExtent, extentAtIndex || selection.isCollapsed) : selection.extendTo(newExtent); + + final bool shouldCollapseToBase = intent.collapseAtReversal + && (selection.baseOffset - selection.extentOffset) * (selection.baseOffset - newSelection.extentOffset) < 0; + final TextSelection newRange = shouldCollapseToBase ? TextSelection.fromPosition(selection.base) : newSelection; + return Actions.invoke(context!, UpdateSelectionIntent(state._value, newRange, SelectionChangedCause.keyboard)); + } + + @override + bool get isActionEnabled => state._value.selection.isValid; +} + +class _UpdateTextSelectionVerticallyAction<T extends DirectionalCaretMovementIntent> extends ContextAction<T> { + _UpdateTextSelectionVerticallyAction(this.state); + + final EditableTextState state; + + VerticalCaretMovementRun? _verticalMovementRun; + TextSelection? _runSelection; + + void stopCurrentVerticalRunIfSelectionChanges() { + final TextSelection? runSelection = _runSelection; + if (runSelection == null) { + assert(_verticalMovementRun == null); + return; + } + _runSelection = state._value.selection; + final TextSelection currentSelection = state.widget.controller.selection; + final bool continueCurrentRun = currentSelection.isValid && currentSelection.isCollapsed + && currentSelection.baseOffset == runSelection.baseOffset + && currentSelection.extentOffset == runSelection.extentOffset; + if (!continueCurrentRun) { + _verticalMovementRun = null; + _runSelection = null; + } + } + + @override + void invoke(T intent, [BuildContext? context]) { + assert(state._value.selection.isValid); + + final bool collapseSelection = intent.collapseSelection || !state.widget.selectionEnabled; + final TextEditingValue value = state._textEditingValueforTextLayoutMetrics; + if (!value.selection.isValid) { + return; + } + + if (_verticalMovementRun?.isValid == false) { + _verticalMovementRun = null; + _runSelection = null; + } + + final VerticalCaretMovementRun currentRun = _verticalMovementRun + ?? state.renderEditable.startVerticalCaretMovement(state.renderEditable.selection!.extent); + + final bool shouldMove = intent is ExtendSelectionVerticallyToAdjacentPageIntent + ? currentRun.moveByOffset((intent.forward ? 1.0 : -1.0) * state.renderEditable.size.height) + : intent.forward ? currentRun.moveNext() : currentRun.movePrevious(); + final TextPosition newExtent = shouldMove + ? currentRun.current + : intent.forward ? TextPosition(offset: value.text.length) : const TextPosition(offset: 0); + final TextSelection newSelection = collapseSelection + ? TextSelection.fromPosition(newExtent) + : value.selection.extendTo(newExtent); + + Actions.invoke( + context!, + UpdateSelectionIntent(value, newSelection, SelectionChangedCause.keyboard), + ); + if (state._value.selection == newSelection) { + _verticalMovementRun = currentRun; + _runSelection = newSelection; + } + } + + @override + bool get isActionEnabled => state._value.selection.isValid; +} + +class _SelectAllAction extends ContextAction<SelectAllTextIntent> { + _SelectAllAction(this.state); + + final EditableTextState state; + + @override + Object? invoke(SelectAllTextIntent intent, [BuildContext? context]) { + return Actions.invoke( + context!, + UpdateSelectionIntent( + state._value, + TextSelection(baseOffset: 0, extentOffset: state._value.text.length), + intent.cause, + ), + ); + } + + @override + bool get isActionEnabled => state.widget.selectionEnabled; +} + +class _CopySelectionAction extends ContextAction<CopySelectionTextIntent> { + _CopySelectionAction(this.state); + + final EditableTextState state; + + @override + void invoke(CopySelectionTextIntent intent, [BuildContext? context]) { + if (intent.collapseSelection) { + state.cutSelection(intent.cause); + } else { + state.copySelection(intent.cause); + } + } + + @override + bool get isActionEnabled => state._value.selection.isValid && !state._value.selection.isCollapsed; +} + +/// The start and end glyph heights of some range of text. +@immutable +class _GlyphHeights { + const _GlyphHeights({ + required this.start, + required this.end, + }); + + /// The glyph height of the first line. + final double start; + + /// The glyph height of the last line. + final double end; +} + +/// A [ClipboardStatusNotifier] whose [value] is hardcoded to +/// [ClipboardStatus.pasteable]. +/// +/// Useful to avoid showing a permission dialog on web, which happens when +/// [Clipboard.hasStrings] is called. +class _WebClipboardStatusNotifier extends ClipboardStatusNotifier { + @override + ClipboardStatus value = ClipboardStatus.pasteable; + + @override + Future<void> update() { + return Future<void>.value(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/fade_in_image.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/fade_in_image.dart new file mode 100644 index 0000000000000000000000000000000000000000..1837eae0c4f86d52ec22be1ecf85abca23d020a0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/fade_in_image.dart @@ -0,0 +1,604 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'image.dart'; +import 'implicit_animations.dart'; + +// Examples can assume: +// late Uint8List bytes; + +/// An image that shows a [placeholder] image while the target [image] is +/// loading, then fades in the new image when it loads. +/// +/// Use this class to display long-loading images, such as [NetworkImage.new], +/// so that the image appears on screen with a graceful animation rather than +/// abruptly popping onto the screen. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=pK738Pg9cxc} +/// +/// If the [image] emits an [ImageInfo] synchronously, such as when the image +/// has been loaded and cached, the [image] is displayed immediately, and the +/// [placeholder] is never displayed. +/// +/// The [fadeOutDuration] and [fadeOutCurve] properties control the fade-out +/// animation of the [placeholder]. +/// +/// The [fadeInDuration] and [fadeInCurve] properties control the fade-in +/// animation of the target [image]. +/// +/// Prefer a [placeholder] that's already cached so that it is displayed +/// immediately. This prevents it from popping onto the screen. +/// +/// When [image] changes, it is resolved to a new [ImageStream]. If the new +/// [ImageStream.key] is different, this widget subscribes to the new stream and +/// replaces the displayed image with images emitted by the new stream. +/// +/// When [placeholder] changes and the [image] has not yet emitted an +/// [ImageInfo], then [placeholder] is resolved to a new [ImageStream]. If the +/// new [ImageStream.key] is different, this widget subscribes to the new stream +/// and replaces the displayed image to images emitted by the new stream. +/// +/// When either [placeholder] or [image] changes, this widget continues showing +/// the previously loaded image (if any) until the new image provider provides a +/// different image. This is known as "gapless playback" (see also +/// [Image.gaplessPlayback]). +/// +/// {@tool snippet} +/// +/// ```dart +/// FadeInImage( +/// // here `bytes` is a Uint8List containing the bytes for the in-memory image +/// placeholder: MemoryImage(bytes), +/// image: const NetworkImage('https://backend.example.com/image.png'), +/// ) +/// ``` +/// {@end-tool} +class FadeInImage extends StatefulWidget { + /// Creates a widget that displays a [placeholder] while an [image] is loading, + /// then fades-out the placeholder and fades-in the image. + /// + /// The [placeholder] and [image] may be composed in a [ResizeImage] to provide + /// a custom decode/cache size. + /// + /// The [placeholder] and [image] may have their own BoxFit settings via [fit] + /// and [placeholderFit]. + /// + /// The [placeholder] and [image] may have their own FilterQuality settings via [filterQuality] + /// and [placeholderFilterQuality]. + /// + /// If [excludeFromSemantics] is true, then [imageSemanticLabel] will be ignored. + const FadeInImage({ + super.key, + required this.placeholder, + this.placeholderErrorBuilder, + required this.image, + this.imageErrorBuilder, + this.excludeFromSemantics = false, + this.imageSemanticLabel, + this.fadeOutDuration = const Duration(milliseconds: 300), + this.fadeOutCurve = Curves.easeOut, + this.fadeInDuration = const Duration(milliseconds: 700), + this.fadeInCurve = Curves.easeIn, + this.color, + this.colorBlendMode, + this.placeholderColor, + this.placeholderColorBlendMode, + this.width, + this.height, + this.fit, + this.placeholderFit, + this.filterQuality = FilterQuality.low, + this.placeholderFilterQuality, + this.alignment = Alignment.center, + this.repeat = ImageRepeat.noRepeat, + this.matchTextDirection = false, + }); + + /// Creates a widget that uses a placeholder image stored in memory while + /// loading the final image from the network. + /// + /// The `placeholder` argument contains the bytes of the in-memory image. + /// + /// The `image` argument is the URL of the final image. + /// + /// The `placeholderScale` and `imageScale` arguments are passed to their + /// respective [ImageProvider]s (see also [ImageInfo.scale]). + /// + /// If [placeholderCacheWidth], [placeholderCacheHeight], [imageCacheWidth], + /// or [imageCacheHeight] are provided, it indicates to the + /// engine that the respective image should be decoded at the specified size. + /// The image will be rendered to the constraints of the layout or [width] + /// and [height] regardless of these parameters. These parameters are primarily + /// intended to reduce the memory usage of [ImageCache]. + /// + /// The [placeholder], [image], [placeholderScale], [imageScale], + /// [fadeOutDuration], [fadeOutCurve], [fadeInDuration], [fadeInCurve], + /// [alignment], [repeat], and [matchTextDirection] arguments must not be + /// null. + /// + /// See also: + /// + /// * [Image.memory], which has more details about loading images from + /// memory. + /// * [Image.network], which has more details about loading images from + /// the network. + FadeInImage.memoryNetwork({ + super.key, + required Uint8List placeholder, + this.placeholderErrorBuilder, + required String image, + this.imageErrorBuilder, + double placeholderScale = 1.0, + double imageScale = 1.0, + this.excludeFromSemantics = false, + this.imageSemanticLabel, + this.fadeOutDuration = const Duration(milliseconds: 300), + this.fadeOutCurve = Curves.easeOut, + this.fadeInDuration = const Duration(milliseconds: 700), + this.fadeInCurve = Curves.easeIn, + this.width, + this.height, + this.fit, + this.color, + this.colorBlendMode, + this.placeholderColor, + this.placeholderColorBlendMode, + this.placeholderFit, + this.filterQuality = FilterQuality.low, + this.placeholderFilterQuality, + this.alignment = Alignment.center, + this.repeat = ImageRepeat.noRepeat, + this.matchTextDirection = false, + int? placeholderCacheWidth, + int? placeholderCacheHeight, + int? imageCacheWidth, + int? imageCacheHeight, + }) : placeholder = ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight, MemoryImage(placeholder, scale: placeholderScale)), + image = ResizeImage.resizeIfNeeded(imageCacheWidth, imageCacheHeight, NetworkImage(image, scale: imageScale)); + + /// Creates a widget that uses a placeholder image stored in an asset bundle + /// while loading the final image from the network. + /// + /// The `placeholder` argument is the key of the image in the asset bundle. + /// + /// The `image` argument is the URL of the final image. + /// + /// The `placeholderScale` and `imageScale` arguments are passed to their + /// respective [ImageProvider]s (see also [ImageInfo.scale]). + /// + /// If `placeholderScale` is omitted or is null, pixel-density-aware asset + /// resolution will be attempted for the [placeholder] image. Otherwise, the + /// exact asset specified will be used. + /// + /// If [placeholderCacheWidth], [placeholderCacheHeight], [imageCacheWidth], + /// or [imageCacheHeight] are provided, it indicates to the + /// engine that the respective image should be decoded at the specified size. + /// The image will be rendered to the constraints of the layout or [width] + /// and [height] regardless of these parameters. These parameters are primarily + /// intended to reduce the memory usage of [ImageCache]. + /// + /// See also: + /// + /// * [Image.asset], which has more details about loading images from + /// asset bundles. + /// * [Image.network], which has more details about loading images from + /// the network. + FadeInImage.assetNetwork({ + super.key, + required String placeholder, + this.placeholderErrorBuilder, + required String image, + this.imageErrorBuilder, + AssetBundle? bundle, + double? placeholderScale, + double imageScale = 1.0, + this.excludeFromSemantics = false, + this.imageSemanticLabel, + this.fadeOutDuration = const Duration(milliseconds: 300), + this.fadeOutCurve = Curves.easeOut, + this.fadeInDuration = const Duration(milliseconds: 700), + this.fadeInCurve = Curves.easeIn, + this.width, + this.height, + this.fit, + this.color, + this.colorBlendMode, + this.placeholderColor, + this.placeholderColorBlendMode, + this.placeholderFit, + this.filterQuality = FilterQuality.low, + this.placeholderFilterQuality, + this.alignment = Alignment.center, + this.repeat = ImageRepeat.noRepeat, + this.matchTextDirection = false, + int? placeholderCacheWidth, + int? placeholderCacheHeight, + int? imageCacheWidth, + int? imageCacheHeight, + }) : placeholder = placeholderScale != null + ? ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight, ExactAssetImage(placeholder, bundle: bundle, scale: placeholderScale)) + : ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight, AssetImage(placeholder, bundle: bundle)), + image = ResizeImage.resizeIfNeeded(imageCacheWidth, imageCacheHeight, NetworkImage(image, scale: imageScale)); + + /// Image displayed while the target [image] is loading. + final ImageProvider placeholder; + + /// A builder function that is called if an error occurs during placeholder + /// image loading. + /// + /// If this builder is not provided, any exceptions will be reported to + /// [FlutterError.onError]. If it is provided, the caller should either handle + /// the exception by providing a replacement widget, or rethrow the exception. + final ImageErrorWidgetBuilder? placeholderErrorBuilder; + + /// The target image that is displayed once it has loaded. + final ImageProvider image; + + /// A builder function that is called if an error occurs during image loading. + /// + /// If this builder is not provided, any exceptions will be reported to + /// [FlutterError.onError]. If it is provided, the caller should either handle + /// the exception by providing a replacement widget, or rethrow the exception. + final ImageErrorWidgetBuilder? imageErrorBuilder; + + /// The duration of the fade-out animation for the [placeholder]. + final Duration fadeOutDuration; + + /// The curve of the fade-out animation for the [placeholder]. + final Curve fadeOutCurve; + + /// The duration of the fade-in animation for the [image]. + final Duration fadeInDuration; + + /// The curve of the fade-in animation for the [image]. + final Curve fadeInCurve; + + /// If non-null, require the image to have this width. + /// + /// If null, the image will pick a size that best preserves its intrinsic + /// aspect ratio. This may result in a sudden change if the size of the + /// placeholder image does not match that of the target image. The size is + /// also affected by the scale factor. + final double? width; + + /// If non-null, this color is blended with each image pixel using [colorBlendMode]. + /// + /// Color applies to the [image]. + /// + /// See Also: + /// + /// * [placeholderColor], the color which applies to the [placeholder]. + final Color? color; + + /// Used to combine [color] with this [image]. + /// + /// The default is [BlendMode.srcIn]. In terms of the blend mode, [color] is + /// the source and this image is the destination. + /// + /// See also: + /// + /// * [BlendMode], which includes an illustration of the effect of each blend mode. + /// * [placeholderColorBlendMode], the color blend mode which applies to the [placeholder]. + final BlendMode? colorBlendMode; + + /// If non-null, this color is blended with each placeholder image pixel using [placeholderColorBlendMode]. + /// + /// Color applies to the [placeholder]. + /// + /// See Also: + /// + /// * [color], the color which applies to the [image]. + final Color? placeholderColor; + + /// Used to combine [placeholderColor] with the [placeholder] image. + /// + /// The default is [BlendMode.srcIn]. In terms of the blend mode, [placeholderColor] is + /// the source and this placeholder is the destination. + /// + /// See also: + /// + /// * [BlendMode], which includes an illustration of the effect of each blend mode. + /// * [colorBlendMode], the color blend mode which applies to the [image]. + final BlendMode? placeholderColorBlendMode; + + /// If non-null, require the image to have this height. + /// + /// If null, the image will pick a size that best preserves its intrinsic + /// aspect ratio. This may result in a sudden change if the size of the + /// placeholder image does not match that of the target image. The size is + /// also affected by the scale factor. + final double? height; + + /// How to inscribe the image into the space allocated during layout. + /// + /// The default varies based on the other fields. See the discussion at + /// [paintImage]. + final BoxFit? fit; + + /// How to inscribe the placeholder image into the space allocated during layout. + /// + /// If not value set, it will fallback to [fit]. + final BoxFit? placeholderFit; + + /// The rendering quality of the image. + /// + /// {@macro flutter.widgets.image.filterQuality} + final FilterQuality filterQuality; + + /// The rendering quality of the placeholder image. + /// + /// {@macro flutter.widgets.image.filterQuality} + final FilterQuality? placeholderFilterQuality; + + /// How to align the image within its bounds. + /// + /// The alignment aligns the given position in the image to the given position + /// in the layout bounds. For example, an [Alignment] alignment of (-1.0, + /// -1.0) aligns the image to the top-left corner of its layout bounds, while an + /// [Alignment] alignment of (1.0, 1.0) aligns the bottom right of the + /// image with the bottom right corner of its layout bounds. Similarly, an + /// alignment of (0.0, 1.0) aligns the bottom middle of the image with the + /// middle of the bottom edge of its layout bounds. + /// + /// If the [alignment] is [TextDirection]-dependent (i.e. if it is a + /// [AlignmentDirectional]), then an ambient [Directionality] widget + /// must be in scope. + /// + /// Defaults to [Alignment.center]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// How to paint any portions of the layout bounds not covered by the image. + final ImageRepeat repeat; + + /// Whether to paint the image in the direction of the [TextDirection]. + /// + /// If this is true, then in [TextDirection.ltr] contexts, the image will be + /// drawn with its origin in the top left (the "normal" painting direction for + /// images); and in [TextDirection.rtl] contexts, the image will be drawn with + /// a scaling factor of -1 in the horizontal direction so that the origin is + /// in the top right. + /// + /// This is occasionally used with images in right-to-left environments, for + /// images that were designed for left-to-right locales. Be careful, when + /// using this, to not flip images with integral shadows, text, or other + /// effects that will look incorrect when flipped. + /// + /// If this is true, there must be an ambient [Directionality] widget in + /// scope. + final bool matchTextDirection; + + /// Whether to exclude this image from semantics. + /// + /// This is useful for images which do not contribute meaningful information + /// to an application. + final bool excludeFromSemantics; + + /// A semantic description of the [image]. + /// + /// Used to provide a description of the [image] to TalkBack on Android, and + /// VoiceOver on iOS. + /// + /// This description will be used both while the [placeholder] is shown and + /// once the image has loaded. + final String? imageSemanticLabel; + + @override + State<FadeInImage> createState() => _FadeInImageState(); +} + +class _FadeInImageState extends State<FadeInImage> { + static const Animation<double> _kOpaqueAnimation = AlwaysStoppedAnimation<double>(1.0); + bool targetLoaded = false; + + // These ProxyAnimations are changed to the fade in animation by + // [_AnimatedFadeOutFadeInState]. Otherwise these animations are reset to + // their defaults by [_resetAnimations]. + final ProxyAnimation _imageAnimation = ProxyAnimation(_kOpaqueAnimation); + final ProxyAnimation _placeholderAnimation = ProxyAnimation(_kOpaqueAnimation); + + Image _image({ + required ImageProvider image, + ImageErrorWidgetBuilder? errorBuilder, + ImageFrameBuilder? frameBuilder, + BoxFit? fit, + Color? color, + BlendMode? colorBlendMode, + required FilterQuality filterQuality, + required Animation<double> opacity, + }) { + return Image( + image: image, + errorBuilder: errorBuilder, + frameBuilder: frameBuilder, + opacity: opacity, + width: widget.width, + height: widget.height, + fit: fit, + color: color, + colorBlendMode: colorBlendMode, + filterQuality: filterQuality, + alignment: widget.alignment, + repeat: widget.repeat, + matchTextDirection: widget.matchTextDirection, + gaplessPlayback: true, + excludeFromSemantics: true, + ); + } + + @override + Widget build(BuildContext context) { + Widget result = _image( + image: widget.image, + errorBuilder: widget.imageErrorBuilder, + opacity: _imageAnimation, + fit: widget.fit, + color: widget.color, + colorBlendMode: widget.colorBlendMode, + filterQuality: widget.filterQuality, + frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) { + if (wasSynchronouslyLoaded || frame != null) { + targetLoaded = true; + } + return _AnimatedFadeOutFadeIn( + target: child, + targetProxyAnimation: _imageAnimation, + placeholder: _image( + image: widget.placeholder, + errorBuilder: widget.placeholderErrorBuilder, + opacity: _placeholderAnimation, + color: widget.placeholderColor, + colorBlendMode: widget.placeholderColorBlendMode, + fit: widget.placeholderFit ?? widget.fit, + filterQuality: widget.placeholderFilterQuality ?? widget.filterQuality, + ), + placeholderProxyAnimation: _placeholderAnimation, + isTargetLoaded: targetLoaded, + wasSynchronouslyLoaded: wasSynchronouslyLoaded, + fadeInDuration: widget.fadeInDuration, + fadeOutDuration: widget.fadeOutDuration, + fadeInCurve: widget.fadeInCurve, + fadeOutCurve: widget.fadeOutCurve, + ); + }, + ); + + if (!widget.excludeFromSemantics) { + result = Semantics( + container: widget.imageSemanticLabel != null, + image: true, + label: widget.imageSemanticLabel ?? '', + child: result, + ); + } + + return result; + } +} + +class _AnimatedFadeOutFadeIn extends ImplicitlyAnimatedWidget { + const _AnimatedFadeOutFadeIn({ + required this.target, + required this.targetProxyAnimation, + required this.placeholder, + required this.placeholderProxyAnimation, + required this.isTargetLoaded, + required this.fadeOutDuration, + required this.fadeOutCurve, + required this.fadeInDuration, + required this.fadeInCurve, + required this.wasSynchronouslyLoaded, + }) : assert(!wasSynchronouslyLoaded || isTargetLoaded), + super(duration: fadeInDuration + fadeOutDuration); + + final Widget target; + final ProxyAnimation targetProxyAnimation; + final Widget placeholder; + final ProxyAnimation placeholderProxyAnimation; + final bool isTargetLoaded; + final Duration fadeInDuration; + final Duration fadeOutDuration; + final Curve fadeInCurve; + final Curve fadeOutCurve; + final bool wasSynchronouslyLoaded; + + @override + _AnimatedFadeOutFadeInState createState() => _AnimatedFadeOutFadeInState(); +} + +class _AnimatedFadeOutFadeInState extends ImplicitlyAnimatedWidgetState<_AnimatedFadeOutFadeIn> { + Tween<double>? _targetOpacity; + Tween<double>? _placeholderOpacity; + Animation<double>? _targetOpacityAnimation; + Animation<double>? _placeholderOpacityAnimation; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _targetOpacity = visitor( + _targetOpacity, + widget.isTargetLoaded ? 1.0 : 0.0, + (dynamic value) => Tween<double>(begin: value as double), + ) as Tween<double>?; + _placeholderOpacity = visitor( + _placeholderOpacity, + widget.isTargetLoaded ? 0.0 : 1.0, + (dynamic value) => Tween<double>(begin: value as double), + ) as Tween<double>?; + } + + @override + void didUpdateTweens() { + if (widget.wasSynchronouslyLoaded) { + // Opacity animations should not be reset if image was synchronously loaded. + return; + } + + _placeholderOpacityAnimation = animation.drive(TweenSequence<double>(<TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: _placeholderOpacity!.chain(CurveTween(curve: widget.fadeOutCurve)), + weight: widget.fadeOutDuration.inMilliseconds.toDouble(), + ), + TweenSequenceItem<double>( + tween: ConstantTween<double>(0), + weight: widget.fadeInDuration.inMilliseconds.toDouble(), + ), + ]))..addStatusListener((AnimationStatus status) { + if (_placeholderOpacityAnimation!.isCompleted) { + // Need to rebuild to remove placeholder now that it is invisible. + setState(() {}); + } + }); + + _targetOpacityAnimation = animation.drive(TweenSequence<double>(<TweenSequenceItem<double>>[ + TweenSequenceItem<double>( + tween: ConstantTween<double>(0), + weight: widget.fadeOutDuration.inMilliseconds.toDouble(), + ), + TweenSequenceItem<double>( + tween: _targetOpacity!.chain(CurveTween(curve: widget.fadeInCurve)), + weight: widget.fadeInDuration.inMilliseconds.toDouble(), + ), + ])); + + widget.targetProxyAnimation.parent = _targetOpacityAnimation; + widget.placeholderProxyAnimation.parent = _placeholderOpacityAnimation; + } + + @override + Widget build(BuildContext context) { + if (widget.wasSynchronouslyLoaded || + (_placeholderOpacityAnimation?.isCompleted ?? true)) { + return widget.target; + } + + return Stack( + fit: StackFit.passthrough, + alignment: AlignmentDirectional.center, + // Text direction is irrelevant here since we're using center alignment, + // but it allows the Stack to avoid a call to Directionality.of() + textDirection: TextDirection.ltr, + children: <Widget>[ + widget.target, + widget.placeholder, + ], + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Animation<double>>('targetOpacity', _targetOpacityAnimation)); + properties.add(DiagnosticsProperty<Animation<double>>('placeholderOpacity', _placeholderOpacityAnimation)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/feedback.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/feedback.dart new file mode 100644 index 0000000000000000000000000000000000000000..f0817ab75df6864f2e4a65d4a0ecbbfa762a490f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/feedback.dart @@ -0,0 +1,175 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/semantics.dart'; +import 'package:flutter/services.dart'; + +import 'framework.dart'; +import 'gesture_detector.dart'; + +/// Provides platform-specific acoustic and/or haptic feedback for certain +/// actions. +/// +/// For example, to play the Android-typically click sound when a button is +/// tapped, call [forTap]. For the Android-specific vibration when long pressing +/// an element, call [forLongPress]. Alternatively, you can also wrap your +/// [GestureDetector.onTap] or [GestureDetector.onLongPress] callback in +/// [wrapForTap] or [wrapForLongPress] to achieve the same (see example code +/// below). +/// +/// All methods in this class are usually called from within a +/// [StatelessWidget.build] method or from a [State]'s methods as you have to +/// provide a [BuildContext]. +/// +/// {@tool snippet} +/// +/// To trigger platform-specific feedback before executing the actual callback: +/// +/// ```dart +/// class WidgetWithWrappedHandler extends StatelessWidget { +/// const WidgetWithWrappedHandler({super.key}); +/// +/// @override +/// Widget build(BuildContext context) { +/// return GestureDetector( +/// onTap: Feedback.wrapForTap(_onTapHandler, context), +/// onLongPress: Feedback.wrapForLongPress(_onLongPressHandler, context), +/// child: const Text('X'), +/// ); +/// } +/// +/// void _onTapHandler() { +/// // Respond to tap. +/// } +/// +/// void _onLongPressHandler() { +/// // Respond to long press. +/// } +/// } +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// Alternatively, you can also call [forTap] or [forLongPress] directly within +/// your tap or long press handler: +/// +/// ```dart +/// class WidgetWithExplicitCall extends StatelessWidget { +/// const WidgetWithExplicitCall({super.key}); +/// +/// @override +/// Widget build(BuildContext context) { +/// return GestureDetector( +/// onTap: () { +/// // Do some work (e.g. check if the tap is valid) +/// Feedback.forTap(context); +/// // Do more work (e.g. respond to the tap) +/// }, +/// onLongPress: () { +/// // Do some work (e.g. check if the long press is valid) +/// Feedback.forLongPress(context); +/// // Do more work (e.g. respond to the long press) +/// }, +/// child: const Text('X'), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +abstract final class Feedback { + /// Provides platform-specific feedback for a tap. + /// + /// On Android the click system sound is played. On iOS this is a no-op. + /// + /// See also: + /// + /// * [wrapForTap] to trigger platform-specific feedback before executing a + /// [GestureTapCallback]. + static Future<void> forTap(BuildContext context) async { + context.findRenderObject()!.sendSemanticsEvent(const TapSemanticEvent()); + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + return SystemSound.play(SystemSoundType.click); + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return Future<void>.value(); + } + } + + /// Wraps a [GestureTapCallback] to provide platform specific feedback for a + /// tap before the provided callback is executed. + /// + /// On Android the platform-typical click system sound is played. On iOS this + /// is a no-op as that platform usually doesn't provide feedback for a tap. + /// + /// See also: + /// + /// * [forTap] to just trigger the platform-specific feedback without wrapping + /// a [GestureTapCallback]. + static GestureTapCallback? wrapForTap(GestureTapCallback? callback, BuildContext context) { + if (callback == null) { + return null; + } + return () { + forTap(context); + callback(); + }; + } + + /// Provides platform-specific feedback for a long press. + /// + /// On Android the platform-typical vibration is triggered. On iOS a + /// heavy-impact haptic feedback is triggered alongside the click system + /// sound, which was observed to be the default behavior on a physical iPhone + /// 15 Pro running iOS version 17.5. + /// + /// See also: + /// + /// * [wrapForLongPress] to trigger platform-specific feedback before + /// executing a [GestureLongPressCallback]. + static Future<void> forLongPress(BuildContext context) { + context.findRenderObject()!.sendSemanticsEvent(const LongPressSemanticsEvent()); + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + return HapticFeedback.vibrate(); + case TargetPlatform.iOS: + return Future.wait(<Future<void>>[ + SystemSound.play(SystemSoundType.click), + HapticFeedback.heavyImpact() + ]); + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return Future<void>.value(); + } + } + + /// Wraps a [GestureLongPressCallback] to provide platform specific feedback + /// for a long press before the provided callback is executed. + /// + /// On Android the platform-typical vibration is triggered. On iOS a + /// heavy-impact haptic feedback is triggered alongside the click system + /// sound, which was observed to be the default behavior on a physical iPhone + /// 15 Pro running iOS version 17.5. + /// + /// See also: + /// + /// * [forLongPress] to just trigger the platform-specific feedback without + /// wrapping a [GestureLongPressCallback]. + static GestureLongPressCallback? wrapForLongPress(GestureLongPressCallback? callback, BuildContext context) { + if (callback == null) { + return null; + } + return () { + Feedback.forLongPress(context); + callback(); + }; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/focus_manager.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/focus_manager.dart new file mode 100644 index 0000000000000000000000000000000000000000..c6b72ddc83e3e84d4b306e66dd83b82fb8785ae3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/focus_manager.dart @@ -0,0 +1,2136 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/painting.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'binding.dart'; +import 'focus_scope.dart'; +import 'focus_traversal.dart'; +import 'framework.dart'; + +/// Setting to true will cause extensive logging to occur when focus changes occur. +/// +/// Can be used to debug focus issues: each time the focus changes, the focus +/// tree will be printed and requests for focus and other focus operations will +/// be logged. +bool debugFocusChanges = false; + +// When using _focusDebug, always call it like so: +// +// assert(_focusDebug(() => 'Blah $foo')); +// +// It needs to be inside the assert in order to be removed in release mode, and +// it needs to use a closure to generate the string in order to avoid string +// interpolation when debugFocusChanges is false. +// +// It will throw a StateError if you try to call it when the app is in release +// mode. +bool _focusDebug( + String Function() messageFunc, [ + Iterable<Object> Function()? detailsFunc, +]) { + if (kReleaseMode) { + throw StateError( + '_focusDebug was called in Release mode. It should always be wrapped in ' + 'an assert. Always call _focusDebug like so:\n' + r" assert(_focusDebug(() => 'Blah $foo'));" + ); + } + if (!debugFocusChanges) { + return true; + } + debugPrint('FOCUS: ${messageFunc()}'); + final Iterable<Object> details = detailsFunc?.call() ?? const <Object>[]; + if (details.isNotEmpty) { + for (final Object detail in details) { + debugPrint(' $detail'); + } + } + // Return true so that it can be used inside of an assert. + return true; +} + +/// An enum that describes how to handle a key event handled by a +/// [FocusOnKeyCallback] or [FocusOnKeyEventCallback]. +enum KeyEventResult { + /// The key event has been handled, and the event should not be propagated to + /// other key event handlers. + handled, + /// The key event has not been handled, and the event should continue to be + /// propagated to other key event handlers, even non-Flutter ones. + ignored, + /// The key event has not been handled, but the key event should not be + /// propagated to other key event handlers. + /// + /// It will be returned to the platform embedding to be propagated to text + /// fields and non-Flutter key event handlers on the platform. + skipRemainingHandlers, +} + +/// Combine the results returned by multiple [FocusOnKeyCallback]s or +/// [FocusOnKeyEventCallback]s. +/// +/// If any callback returns [KeyEventResult.handled], the node considers the +/// message handled; otherwise, if any callback returns +/// [KeyEventResult.skipRemainingHandlers], the node skips the remaining +/// handlers without preventing the platform to handle; otherwise the node is +/// ignored. +KeyEventResult combineKeyEventResults(Iterable<KeyEventResult> results) { + bool hasSkipRemainingHandlers = false; + for (final KeyEventResult result in results) { + switch (result) { + case KeyEventResult.handled: + return KeyEventResult.handled; + case KeyEventResult.skipRemainingHandlers: + hasSkipRemainingHandlers = true; + case KeyEventResult.ignored: + break; + } + } + return hasSkipRemainingHandlers ? + KeyEventResult.skipRemainingHandlers : + KeyEventResult.ignored; +} + +/// Signature of a callback used by [Focus.onKey] and [FocusScope.onKey] +/// to receive key events. +/// +/// This kind of callback is deprecated and will be removed at a future date. +/// Use [FocusOnKeyEventCallback] and associated APIs instead. +/// +/// The [node] is the node that received the event. +/// +/// Returns a [KeyEventResult] that describes how, and whether, the key event +/// was handled. +@Deprecated( + 'Use FocusOnKeyEventCallback instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +typedef FocusOnKeyCallback = KeyEventResult Function(FocusNode node, RawKeyEvent event); + +/// Signature of a callback used by [Focus.onKeyEvent] and [FocusScope.onKeyEvent] +/// to receive key events. +/// +/// The [node] is the node that received the event. +/// +/// Returns a [KeyEventResult] that describes how, and whether, the key event +/// was handled. +typedef FocusOnKeyEventCallback = KeyEventResult Function(FocusNode node, KeyEvent event); + +/// Signature of a callback used by [FocusManager.addEarlyKeyEventHandler] and +/// [FocusManager.addLateKeyEventHandler]. +/// +/// The `event` parameter is a [KeyEvent] that is being sent to the callback to +/// be handled. +/// +/// The [KeyEventResult] return value indicates whether or not the event will +/// continue to be propagated. If the value returned is [KeyEventResult.handled] +/// or [KeyEventResult.skipRemainingHandlers], then the event will not continue +/// to be propagated. +typedef OnKeyEventCallback = KeyEventResult Function(KeyEvent event); + +// Represents a pending autofocus request. +@immutable +class _Autofocus { + const _Autofocus({ required this.scope, required this.autofocusNode }); + + final FocusScopeNode scope; + final FocusNode autofocusNode; + + // Applies the autofocus request, if the node is still attached to the + // original scope and the scope has no focused child. + // + // The widget tree is responsible for calling reparent/detach on attached + // nodes to keep their parent/manager information up-to-date, so here we can + // safely check if the scope/node involved in each autofocus request is + // still attached, and discard the ones which are no longer attached to the + // original manager. + void applyIfValid(FocusManager manager) { + final bool shouldApply = (scope.parent != null || identical(scope, manager.rootScope)) + && identical(scope._manager, manager) + && scope.focusedChild == null + && autofocusNode.ancestors.contains(scope); + if (shouldApply) { + assert(_focusDebug(() => 'Applying autofocus: $autofocusNode')); + autofocusNode._doRequestFocus(findFirstFocus: true); + } else { + assert(_focusDebug(() => 'Autofocus request discarded for node: $autofocusNode.')); + } + } +} + +/// An attachment point for a [FocusNode]. +/// +/// Using a [FocusAttachment] is rarely needed, unless building something +/// akin to the [Focus] or [FocusScope] widgets from scratch. +/// +/// Once created, a [FocusNode] must be attached to the widget tree by its +/// _host_ [StatefulWidget] via a [FocusAttachment] object. [FocusAttachment]s +/// are owned by the [StatefulWidget] that hosts a [FocusNode] or +/// [FocusScopeNode]. There can be multiple [FocusAttachment]s for each +/// [FocusNode], but the node will only ever be attached to one of them at a +/// time. +/// +/// This attachment is created by calling [FocusNode.attach], usually from the +/// host widget's [State.initState] method. If the widget is updated to have a +/// different focus node, then the new node needs to be attached in +/// [State.didUpdateWidget], after calling [detach] on the previous +/// [FocusAttachment]. Once detached, the attachment is defunct and will no +/// longer make changes to the [FocusNode] through [reparent]. +/// +/// Without these attachment points, it would be possible for a focus node to +/// simultaneously be attached to more than one part of the widget tree during +/// the build stage. +class FocusAttachment { + /// A private constructor, because [FocusAttachment]s are only to be created + /// by [FocusNode.attach]. + FocusAttachment._(this._node); + + // The focus node that this attachment manages an attachment for. The node may + // not yet have a parent, or may have been detached from this attachment, so + // don't count on this node being in a usable state. + final FocusNode _node; + + /// Returns true if the associated node is attached to this attachment. + /// + /// It is possible to be attached to the widget tree, but not be placed in + /// the focus tree (i.e. to not have a parent yet in the focus tree). + bool get isAttached => _node._attachment == this; + + /// Detaches the [FocusNode] this attachment point is associated with from the + /// focus tree, and disconnects it from this attachment point. + /// + /// Calling [FocusNode.dispose] will also automatically detach the node. + void detach() { + assert(_focusDebug(() => 'Detaching node:', () => <Object>[_node, 'With enclosing scope ${_node.enclosingScope}'])); + if (isAttached) { + if (_node.hasPrimaryFocus || (_node._manager != null && _node._manager!._markedForFocus == _node)) { + _node.unfocus(disposition: UnfocusDisposition.previouslyFocusedChild); + } + // This node is no longer in the tree, so shouldn't send notifications anymore. + _node._manager?._markDetached(_node); + _node._parent?._removeChild(_node); + _node._attachment = null; + assert(!_node.hasPrimaryFocus); + assert(_node._manager?._markedForFocus != _node); + } + assert(!isAttached); + } + + /// Ensures that the [FocusNode] attached at this attachment point has the + /// proper parent node, changing it if necessary. + /// + /// If given, ensures that the given [parent] node is the parent of the node + /// that is attached at this attachment point, changing it if necessary. + /// However, it is usually not necessary to supply an explicit parent, since + /// [reparent] will use [Focus.of] to determine the correct parent node for + /// the context given in [FocusNode.attach]. + /// + /// If [isAttached] is false, then calling this method does nothing. + /// + /// Should be called whenever the associated widget is rebuilt in order to + /// maintain the focus hierarchy. + /// + /// A [StatefulWidget] that hosts a [FocusNode] should call this method on the + /// node it hosts during its [State.build] or [State.didChangeDependencies] + /// methods in case the widget is moved from one location in the tree to + /// another location that has a different [FocusScope] or context. + /// + /// The optional [parent] argument must be supplied when not using [Focus] and + /// [FocusScope] widgets to build the focus tree, or if there is a need to + /// supply the parent explicitly (which are both uncommon). + void reparent({FocusNode? parent}) { + if (isAttached) { + assert(_node.context != null); + parent ??= Focus.maybeOf(_node.context!, scopeOk: true); + parent ??= _node.context!.owner!.focusManager.rootScope; + parent._reparent(_node); + } + } +} + +/// Describe what should happen after [FocusNode.unfocus] is called. +/// +/// See also: +/// +/// * [FocusNode.unfocus], which takes this as its `disposition` parameter. +enum UnfocusDisposition { + /// Focus the nearest focusable enclosing scope of this node, but do not + /// descend to locate the leaf [FocusScopeNode.focusedChild] the way + /// [previouslyFocusedChild] does. + /// + /// Focusing the scope in this way clears the [FocusScopeNode.focusedChild] + /// history for the enclosing scope when it receives focus. Because of this, + /// calling a traversal method like [FocusNode.nextFocus] after unfocusing + /// will cause the [FocusTraversalPolicy] to pick the node it thinks should be + /// first in the scope. + /// + /// This is the default disposition for [FocusNode.unfocus]. + scope, + + /// Focus the previously focused child of the nearest focusable enclosing + /// scope of this node. + /// + /// If there is no previously focused child, then this is equivalent to + /// using the [scope] disposition. + /// + /// Unfocusing with this disposition will cause [FocusNode.unfocus] to walk up + /// the tree to the nearest focusable enclosing scope, then start to walk down + /// the tree, looking for a focused child at its + /// [FocusScopeNode.focusedChild]. + /// + /// If the [FocusScopeNode.focusedChild] is a scope, then look for its + /// [FocusScopeNode.focusedChild], and so on, finding the leaf + /// [FocusScopeNode.focusedChild] that is not a scope, or, failing that, a + /// leaf scope that has no focused child. + previouslyFocusedChild, +} + +/// An object that can be used by a stateful widget to obtain the keyboard focus +/// and to handle keyboard events. +/// +/// _Please see the [Focus] and [FocusScope] widgets, which are utility widgets +/// that manage their own [FocusNode]s and [FocusScopeNode]s, respectively. If +/// they aren't appropriate, [FocusNode]s can be managed directly, but doing this +/// is rare._ +/// +/// [FocusNode]s are persistent objects that form a _focus tree_ that is a +/// representation of the widgets in the hierarchy that are interested in focus. +/// A focus node might need to be created if it is passed in from an ancestor of +/// a [Focus] widget to control the focus of the children from the ancestor, or +/// a widget might need to host one if the widget subsystem is not being used, +/// or if the [Focus] and [FocusScope] widgets provide insufficient control. +/// +/// [FocusNode]s are organized into _scopes_ (see [FocusScopeNode]), which form +/// sub-trees of nodes that restrict traversal to a group of nodes. Within a +/// scope, the most recent nodes to have focus are remembered, and if a node is +/// focused and then unfocused, the previous node receives focus again. +/// +/// The focus node hierarchy can be traversed using the [parent], [children], +/// [ancestors] and [descendants] accessors. +/// +/// [FocusNode]s are [ChangeNotifier]s, so a listener can be registered to +/// receive a notification when the focus changes. Listeners will also be +/// notified when [skipTraversal], [canRequestFocus], [descendantsAreFocusable], +/// and [descendantsAreTraversable] properties are updated. If the [Focus] and +/// [FocusScope] widgets are being used to manage the nodes, consider +/// establishing an [InheritedWidget] dependency on them by calling [Focus.of] +/// or [FocusScope.of] instead. [FocusNode.hasFocus] can also be used to +/// establish a similar dependency, especially if all that is needed is to +/// determine whether or not the widget is focused at build time. +/// +/// To see the focus tree in the debug console, call [debugDumpFocusTree]. To +/// get the focus tree as a string, call [debugDescribeFocusTree]. +/// +/// {@template flutter.widgets.FocusNode.lifecycle} +/// ## Lifecycle +/// +/// There are several actors involved in the lifecycle of a +/// [FocusNode]/[FocusScopeNode]. They are created and disposed by their +/// _owner_, attached, detached, and re-parented using a [FocusAttachment] by +/// their _host_ (which must be owned by the [State] of a [StatefulWidget]), and +/// they are managed by the [FocusManager]. Different parts of the [FocusNode] +/// API are intended for these different actors. +/// +/// [FocusNode]s (and hence [FocusScopeNode]s) are persistent objects that form +/// part of a _focus tree_ that is a sparse representation of the widgets in the +/// hierarchy that are interested in receiving keyboard events. They must be +/// managed like other persistent state, which is typically done by a +/// [StatefulWidget] that owns the node. A stateful widget that owns a focus +/// scope node must call [dispose] from its [State.dispose] method. +/// +/// Once created, a [FocusNode] must be attached to the widget tree via a +/// [FocusAttachment] object. This attachment is created by calling [attach], +/// usually from the [State.initState] method. If the hosting widget is updated +/// to have a different focus node, then the updated node needs to be attached +/// in [State.didUpdateWidget], after calling [FocusAttachment.detach] on the +/// previous [FocusAttachment]. +/// +/// Because [FocusNode]s form a sparse representation of the widget tree, they +/// must be updated whenever the widget tree is rebuilt. This is done by calling +/// [FocusAttachment.reparent], usually from the [State.build] or +/// [State.didChangeDependencies] methods of the widget that represents the +/// focused region, so that the [BuildContext] assigned to the [FocusScopeNode] +/// can be tracked (the context is used to obtain the [RenderObject], from which +/// the geometry of focused regions can be determined). +/// +/// Creating a [FocusNode] each time [State.build] is invoked will cause the +/// focus to be lost each time the widget is built, which is usually not desired +/// behavior (call [unfocus] if losing focus is desired). +/// +/// If, as is common, the hosting [StatefulWidget] is also the owner of the +/// focus node, then it will also call [dispose] from its [State.dispose] (in +/// which case the [FocusAttachment.detach] may be skipped, since dispose will +/// automatically detach). If another object owns the focus node, then it must +/// call [dispose] when the node is done being used. +/// {@endtemplate} +/// +/// {@template flutter.widgets.FocusNode.keyEvents} +/// ## Key Event Propagation +/// +/// The [FocusManager] receives key events from [HardwareKeyboard] and will pass +/// them to the focused nodes. It starts with the node with the primary focus, +/// and will call the [onKeyEvent] callback for that node. If the callback +/// returns [KeyEventResult.ignored], indicating that it did not handle the +/// event, the [FocusManager] will move to the parent of that node and call its +/// [onKeyEvent]. If that [onKeyEvent] returns [KeyEventResult.handled], then it +/// will stop propagating the event. If it reaches the root [FocusScopeNode], +/// [FocusManager.rootScope], the event is discarded. +/// {@endtemplate} +/// +/// ## Focus Traversal +/// +/// The term _traversal_, sometimes called _tab traversal_, refers to moving the +/// focus from one widget to the next in a particular order (also sometimes +/// referred to as the _tab order_, since the TAB key is often bound to the +/// action to move to the next widget). +/// +/// To give focus to the logical _next_ or _previous_ widget in the UI, call the +/// [nextFocus] or [previousFocus] methods. To give the focus to a widget in a +/// particular direction, call the [focusInDirection] method. +/// +/// The policy for what the _next_ or _previous_ widget is, or the widget in a +/// particular direction, is determined by the [FocusTraversalPolicy] in force. +/// +/// The ambient policy is determined by looking up the widget hierarchy for a +/// [FocusTraversalGroup] widget, and obtaining the focus traversal policy from +/// it. Different focus nodes can inherit difference policies, so part of the +/// app can go in a predefined order (using [OrderedTraversalPolicy]), and part +/// can go in reading order (using [ReadingOrderTraversalPolicy]), depending +/// upon the use case. +/// +/// Predefined policies include [WidgetOrderTraversalPolicy], +/// [ReadingOrderTraversalPolicy], [OrderedTraversalPolicy], and +/// [DirectionalFocusTraversalPolicyMixin], but custom policies can be built +/// based upon these policies. See [FocusTraversalPolicy] for more information. +/// +/// {@tool dartpad} +/// This example shows how a FocusNode should be managed if not using the +/// [Focus] or [FocusScope] widgets. See the [Focus] widget for a similar +/// example using [Focus] and [FocusScope] widgets. +/// +/// ** See code in examples/api/lib/widgets/focus_manager/focus_node.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Focus], a widget that manages a [FocusNode] and provides access to focus +/// information and actions to its descendant widgets. +/// * [FocusTraversalGroup], a widget used to group together and configure the +/// focus traversal policy for a widget subtree. +/// * [FocusManager], a singleton that manages the primary focus and distributes +/// key events to focused nodes. +/// * [FocusTraversalPolicy], a class used to determine how to move the focus to +/// other nodes. +class FocusNode with DiagnosticableTreeMixin, ChangeNotifier { + /// Creates a focus node. + /// + /// The [debugLabel] is ignored on release builds. + /// + /// To receive key events that focuses on this node, pass a listener to + /// `onKeyEvent`. + FocusNode({ + String? debugLabel, + @Deprecated( + 'Use onKeyEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + this.onKey, + this.onKeyEvent, + bool skipTraversal = false, + bool canRequestFocus = true, + bool descendantsAreFocusable = true, + bool descendantsAreTraversable = true, + }) : _skipTraversal = skipTraversal, + _canRequestFocus = canRequestFocus, + _descendantsAreFocusable = descendantsAreFocusable, + _descendantsAreTraversable = descendantsAreTraversable { + // Set it via the setter so that it does nothing on release builds. + this.debugLabel = debugLabel; + + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + /// If true, tells the focus traversal policy to skip over this node for + /// purposes of the traversal algorithm. + /// + /// This may be used to place nodes in the focus tree that may be focused, but + /// not traversed, allowing them to receive key events as part of the focus + /// chain, but not be traversed to via focus traversal. + /// + /// This is different from [canRequestFocus] because it only implies that the + /// node can't be reached via traversal, not that it can't be focused. It may + /// still be focused explicitly. + bool get skipTraversal { + if (_skipTraversal) { + return true; + } + for (final FocusNode ancestor in ancestors) { + if (!ancestor.descendantsAreTraversable) { + return true; + } + } + return false; + } + bool _skipTraversal; + set skipTraversal(bool value) { + if (value != _skipTraversal) { + _skipTraversal = value; + _manager?._markPropertiesChanged(this); + } + } + + /// If true, this focus node may request the primary focus. + /// + /// Defaults to true. Set to false if you want this node to do nothing when + /// [requestFocus] is called on it. + /// + /// If set to false on a [FocusScopeNode], will cause all of the children of + /// the scope node to not be focusable. + /// + /// If set to false on a [FocusNode], it will not affect the focusability of + /// children of the node. + /// + /// The [hasFocus] member can still return true if this node is the ancestor + /// of a node with primary focus. + /// + /// This is different than [skipTraversal] because [skipTraversal] still + /// allows the node to be focused, just not traversed to via the + /// [FocusTraversalPolicy]. + /// + /// Setting [canRequestFocus] to false implies that the node will also be + /// skipped for traversal purposes. + /// + /// See also: + /// + /// * [FocusTraversalGroup], a widget used to group together and configure the + /// focus traversal policy for a widget subtree. + /// * [FocusTraversalPolicy], a class that can be extended to describe a + /// traversal policy. + bool get canRequestFocus { + if (!_canRequestFocus) { + return false; + } + final FocusScopeNode? scope = enclosingScope; + if (scope != null && !scope.canRequestFocus) { + return false; + } + for (final FocusNode ancestor in ancestors) { + if (!ancestor.descendantsAreFocusable) { + return false; + } + } + return true; + } + + bool _canRequestFocus; + @mustCallSuper + set canRequestFocus(bool value) { + if (value != _canRequestFocus) { + // Have to set this first before unfocusing, since it checks this to cull + // unfocusable, previously-focused children. + _canRequestFocus = value; + if (hasFocus && !value) { + unfocus(disposition: UnfocusDisposition.previouslyFocusedChild); + } + _manager?._markPropertiesChanged(this); + } + } + + /// If false, will disable focus for all of this node's descendants. + /// + /// Defaults to true. Does not affect focusability of this node: for that, + /// use [canRequestFocus]. + /// + /// If any descendants are focused when this is set to false, they will be + /// unfocused. When [descendantsAreFocusable] is set to true again, they will + /// not be refocused, although they will be able to accept focus again. + /// + /// Does not affect the value of [canRequestFocus] on the descendants. + /// + /// If a descendant node loses focus when this value is changed, the focus + /// will move to the scope enclosing this node. + /// + /// See also: + /// + /// * [ExcludeFocus], a widget that uses this property to conditionally + /// exclude focus for a subtree. + /// * [descendantsAreTraversable], which makes this widget's descendants + /// untraversable. + /// * [ExcludeFocusTraversal], a widget that conditionally excludes focus + /// traversal for a subtree. + /// * [Focus], a widget that exposes this setting as a parameter. + /// * [FocusTraversalGroup], a widget used to group together and configure + /// the focus traversal policy for a widget subtree that also has a + /// `descendantsAreFocusable` parameter that prevents its children from + /// being focused. + bool get descendantsAreFocusable => _descendantsAreFocusable; + bool _descendantsAreFocusable; + @mustCallSuper + set descendantsAreFocusable(bool value) { + if (value == _descendantsAreFocusable) { + return; + } + // Set _descendantsAreFocusable before unfocusing, so the scope won't try + // and focus any of the children here again if it is false. + _descendantsAreFocusable = value; + if (!value && hasFocus) { + unfocus(disposition: UnfocusDisposition.previouslyFocusedChild); + } + _manager?._markPropertiesChanged(this); + } + + /// If false, tells the focus traversal policy to skip over for all of this + /// node's descendants for purposes of the traversal algorithm. + /// + /// Defaults to true. Does not affect the focus traversal of this node: for + /// that, use [skipTraversal]. + /// + /// Does not affect the value of [FocusNode.skipTraversal] on the + /// descendants. Does not affect focusability of the descendants. + /// + /// See also: + /// + /// * [ExcludeFocusTraversal], a widget that uses this property to conditionally + /// exclude focus traversal for a subtree. + /// * [descendantsAreFocusable], which makes this widget's descendants + /// unfocusable. + /// * [ExcludeFocus], a widget that conditionally excludes focus for a subtree. + /// * [FocusTraversalGroup], a widget used to group together and configure + /// the focus traversal policy for a widget subtree that also has an + /// `descendantsAreFocusable` parameter that prevents its children from + /// being focused. + bool get descendantsAreTraversable => _descendantsAreTraversable; + bool _descendantsAreTraversable; + @mustCallSuper + set descendantsAreTraversable(bool value) { + if (value != _descendantsAreTraversable) { + _descendantsAreTraversable = value; + _manager?._markPropertiesChanged(this); + } + } + + /// The context that was supplied to [attach]. + /// + /// This is typically the context for the widget that is being focused, as it + /// is used to determine the bounds of the widget. + BuildContext? get context => _context; + BuildContext? _context; + + /// Called if this focus node receives a key event while focused (i.e. when + /// [hasFocus] returns true). + /// + /// This property is deprecated and will be removed at a future date. Use + /// [onKeyEvent] instead. + /// + /// This is a legacy API based on [RawKeyEvent] and will be deprecated in the + /// future. Prefer [onKeyEvent] instead. + /// + /// {@macro flutter.widgets.FocusNode.keyEvents} + @Deprecated( + 'Use onKeyEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + FocusOnKeyCallback? onKey; + + /// Called if this focus node receives a key event while focused (i.e. when + /// [hasFocus] returns true). + /// + /// {@macro flutter.widgets.FocusNode.keyEvents} + FocusOnKeyEventCallback? onKeyEvent; + + FocusManager? _manager; + List<FocusNode>? _ancestors; + List<FocusNode>? _descendants; + bool _hasKeyboardToken = false; + + /// Returns the parent node for this object. + /// + /// All nodes except for the root [FocusScopeNode] ([FocusManager.rootScope]) + /// will be given a parent when they are added to the focus tree, which is + /// done using [FocusAttachment.reparent]. + FocusNode? get parent => _parent; + FocusNode? _parent; + + /// An iterator over the children of this node. + Iterable<FocusNode> get children => _children; + final List<FocusNode> _children = <FocusNode>[]; + + /// An iterator over the children that are allowed to be traversed by the + /// [FocusTraversalPolicy]. + /// + /// Returns the list of focusable, traversable children of this node, + /// regardless of those settings on this focus node. Will return an empty + /// iterable if [descendantsAreFocusable] is false. + /// + /// See also + /// + /// * [traversalDescendants], which traverses all of the node's descendants, + /// not just the immediate children. + Iterable<FocusNode> get traversalChildren { + if (!descendantsAreFocusable) { + return const Iterable<FocusNode>.empty(); + } + return children.where( + (FocusNode node) => !node.skipTraversal && node.canRequestFocus, + ); + } + + /// A debug label that is used for diagnostic output. + /// + /// Will always return null in release builds. + String? get debugLabel => _debugLabel; + String? _debugLabel; + set debugLabel(String? value) { + assert(() { + // Only set the value in debug builds. + _debugLabel = value; + return true; + }()); + } + + FocusAttachment? _attachment; + + /// An [Iterable] over the hierarchy of children below this one, in + /// depth-first order. + Iterable<FocusNode> get descendants { + if (_descendants == null) { + final List<FocusNode> result = <FocusNode>[]; + for (final FocusNode child in _children) { + result.addAll(child.descendants); + result.add(child); + } + _descendants = result; + } + return _descendants!; + } + + /// Returns all descendants which do not have the [skipTraversal] and do have + /// the [canRequestFocus] flag set. + Iterable<FocusNode> get traversalDescendants { + if (!descendantsAreFocusable) { + return const Iterable<FocusNode>.empty(); + } + return descendants.where((FocusNode node) => !node.skipTraversal && node.canRequestFocus); + } + + /// An [Iterable] over the ancestors of this node. + /// + /// Iterates the ancestors of this node starting at the parent and iterating + /// over successively more remote ancestors of this node, ending at the root + /// [FocusScopeNode] ([FocusManager.rootScope]). + Iterable<FocusNode> get ancestors { + if (_ancestors == null) { + final List<FocusNode> result = <FocusNode>[]; + FocusNode? parent = _parent; + while (parent != null) { + result.add(parent); + parent = parent._parent; + } + _ancestors = result; + } + return _ancestors!; + } + + /// Whether this node has input focus. + /// + /// A [FocusNode] has focus when it is an ancestor of a node that returns true + /// from [hasPrimaryFocus], or it has the primary focus itself. + /// + /// The [hasFocus] accessor is different from [hasPrimaryFocus] in that + /// [hasFocus] is true if the node is anywhere in the focus chain, but for + /// [hasPrimaryFocus] the node must to be at the end of the chain to return + /// true. + /// + /// A node that returns true for [hasFocus] will receive key events if none of + /// its focused descendants returned true from their [onKey] handler. + /// + /// This object is a [ChangeNotifier], and notifies its [Listenable] listeners + /// (registered via [addListener]) whenever this value changes. + /// + /// See also: + /// + /// * [Focus.isAt], which is a static method that will return the focus + /// state of the nearest ancestor [Focus] widget's focus node. + bool get hasFocus => hasPrimaryFocus || (_manager?.primaryFocus?.ancestors.contains(this) ?? false); + + /// Returns true if this node currently has the application-wide input focus. + /// + /// A [FocusNode] has the primary focus when the node is focused in its + /// nearest ancestor [FocusScopeNode] and [hasFocus] is true for all its + /// ancestor nodes, but none of its descendants. + /// + /// This is different from [hasFocus] in that [hasFocus] is true if the node + /// is anywhere in the focus chain, but here the node has to be at the end of + /// the chain to return true. + /// + /// A node that returns true for [hasPrimaryFocus] will be the first node to + /// receive key events through its [onKey] handler. + /// + /// This object notifies its listeners whenever this value changes. + bool get hasPrimaryFocus => _manager?.primaryFocus == this; + + /// Returns the [FocusHighlightMode] that is currently in effect for this node. + FocusHighlightMode get highlightMode => FocusManager.instance.highlightMode; + + /// Returns the nearest enclosing scope node above this node, including + /// this node, if it's a scope. + /// + /// Returns null if no scope is found. + /// + /// Use [enclosingScope] to look for scopes above this node. + FocusScopeNode? get nearestScope => enclosingScope; + + /// Returns the nearest enclosing scope node above this node, or null if the + /// node has not yet be added to the focus tree. + /// + /// If this node is itself a scope, this will only return ancestors of this + /// scope. + /// + /// Use [nearestScope] to start at this node instead of above it. + FocusScopeNode? get enclosingScope { + for (final FocusNode node in ancestors) { + if (node is FocusScopeNode) { + return node; + } + } + return null; + } + + /// Returns the size of the attached widget's [RenderObject], in logical + /// units. + /// + /// Size is the size of the transformed widget in global coordinates. + Size get size => rect.size; + + /// Returns the global offset to the upper left corner of the attached + /// widget's [RenderObject], in logical units. + /// + /// Offset is the offset of the transformed widget in global coordinates. + Offset get offset { + assert( + context != null, + "Tried to get the offset of a focus node that didn't have its context set yet.\n" + 'The context needs to be set before trying to evaluate traversal policies. ' + 'Setting the context is typically done with the attach method.', + ); + final RenderObject object = context!.findRenderObject()!; + return MatrixUtils.transformPoint(object.getTransformTo(null), object.semanticBounds.topLeft); + } + + /// Returns the global rectangle of the attached widget's [RenderObject], in + /// logical units. + /// + /// Rect is the rectangle of the transformed widget in global coordinates. + Rect get rect { + assert( + context != null, + "Tried to get the bounds of a focus node that didn't have its context set yet.\n" + 'The context needs to be set before trying to evaluate traversal policies. ' + 'Setting the context is typically done with the attach method.', + ); + final RenderObject object = context!.findRenderObject()!; + final Offset topLeft = MatrixUtils.transformPoint(object.getTransformTo(null), object.semanticBounds.topLeft); + final Offset bottomRight = MatrixUtils.transformPoint(object.getTransformTo(null), object.semanticBounds.bottomRight); + return Rect.fromLTRB(topLeft.dx, topLeft.dy, bottomRight.dx, bottomRight.dy); + } + + /// Removes the focus on this node by moving the primary focus to another node. + /// + /// This method removes focus from a node that has the primary focus, cancels + /// any outstanding requests to focus it, while setting the primary focus to + /// another node according to the `disposition`. + /// + /// It is safe to call regardless of whether this node has ever requested + /// focus or not. If this node doesn't have focus or primary focus, nothing + /// happens. + /// + /// The `disposition` argument determines which node will receive primary + /// focus after this one loses it. + /// + /// If `disposition` is set to [UnfocusDisposition.scope] (the default), then + /// the previously focused node history of the enclosing scope will be + /// cleared, and the primary focus will be moved to the nearest enclosing + /// scope ancestor that is enabled for focus, ignoring the + /// [FocusScopeNode.focusedChild] for that scope. + /// + /// If `disposition` is set to [UnfocusDisposition.previouslyFocusedChild], + /// then this node will be removed from the previously focused list in the + /// [enclosingScope], and the focus will be moved to the previously focused + /// node of the [enclosingScope], which (if it is a scope itself), will find + /// its focused child, etc., until a leaf focus node is found. If there is no + /// previously focused child, then the scope itself will receive focus, as if + /// [UnfocusDisposition.scope] were specified. + /// + /// If you want this node to lose focus and the focus to move to the next or + /// previous node in the enclosing [FocusTraversalGroup], call [nextFocus] or + /// [previousFocus] instead of calling [unfocus]. + /// + /// {@tool dartpad} + /// This example shows the difference between the different [UnfocusDisposition] + /// values for [unfocus]. + /// + /// Try setting focus on the four text fields by selecting them, and then + /// select "UNFOCUS" to see what happens when the current + /// [FocusManager.primaryFocus] is unfocused. + /// + /// Try pressing the TAB key after unfocusing to see what the next widget + /// chosen is. + /// + /// ** See code in examples/api/lib/widgets/focus_manager/focus_node.unfocus.0.dart ** + /// {@end-tool} + void unfocus({ + UnfocusDisposition disposition = UnfocusDisposition.scope, + }) { + if (!hasFocus && (_manager == null || _manager!._markedForFocus != this)) { + return; + } + FocusScopeNode? scope = enclosingScope; + if (scope == null) { + // If the scope is null, then this is either the root node, or a node that + // is not yet in the tree, neither of which do anything when unfocused. + return; + } + switch (disposition) { + case UnfocusDisposition.scope: + // If it can't request focus, then don't modify its focused children. + if (scope.canRequestFocus) { + // Clearing the focused children here prevents re-focusing the node + // that we just unfocused if we immediately hit "next" after + // unfocusing, and also prevents choosing to refocus the next-to-last + // focused child if unfocus is called more than once. + scope._focusedChildren.clear(); + } + + while (!scope!.canRequestFocus) { + scope = scope.enclosingScope ?? _manager?.rootScope; + } + scope._doRequestFocus(findFirstFocus: false); + case UnfocusDisposition.previouslyFocusedChild: + // Select the most recent focused child from the nearest focusable scope + // and focus that. If there isn't one, focus the scope itself. + if (scope.canRequestFocus) { + scope._focusedChildren.remove(this); + } + while (!scope!.canRequestFocus) { + scope.enclosingScope?._focusedChildren.remove(scope); + scope = scope.enclosingScope ?? _manager?.rootScope; + } + scope._doRequestFocus(findFirstFocus: true); + } + assert(_focusDebug(() => 'Unfocused node:', () => <Object>['primary focus was $this', 'next focus will be ${_manager?._markedForFocus}'])); + } + + /// Removes the keyboard token from this focus node if it has one. + /// + /// This mechanism helps distinguish between an input control gaining focus by + /// default and gaining focus as a result of an explicit user action. + /// + /// When a focus node requests the focus (either via + /// [FocusScopeNode.requestFocus] or [FocusScopeNode.autofocus]), the focus + /// node receives a keyboard token if it does not already have one. Later, + /// when the focus node becomes focused, the widget that manages the + /// [TextInputConnection] should show the keyboard (i.e. call + /// [TextInputConnection.show]) only if it successfully consumes the keyboard + /// token from the focus node. + /// + /// Returns true if this method successfully consumes the keyboard token. + bool consumeKeyboardToken() { + if (!_hasKeyboardToken) { + return false; + } + _hasKeyboardToken = false; + return true; + } + + // Marks the node as being the next to be focused, meaning that it will become + // the primary focus and notify listeners of a focus change the next time + // focus is resolved by the manager. If something else calls _markNextFocus + // before then, then that node will become the next focus instead of the + // previous one. + void _markNextFocus(FocusNode newFocus) { + if (_manager != null) { + // If we have a manager, then let it handle the focus change. + _manager!._markNextFocus(this); + return; + } + // If we don't have a manager, then change the focus locally. + newFocus._setAsFocusedChildForScope(); + newFocus._notify(); + if (newFocus != this) { + _notify(); + } + } + + // Removes the given FocusNode and its children as a child of this node. + @mustCallSuper + void _removeChild(FocusNode node, {bool removeScopeFocus = true}) { + assert(_children.contains(node), "Tried to remove a node that wasn't a child."); + assert(node._parent == this); + assert(node._manager == _manager); + + if (removeScopeFocus) { + final FocusScopeNode? nodeScope = node.enclosingScope; + if (nodeScope != null) { + nodeScope._focusedChildren.remove(node); + node.descendants.where((FocusNode descendant) { + return descendant.enclosingScope == nodeScope; + }).forEach(nodeScope._focusedChildren.remove); + } + } + + node._parent = null; + _children.remove(node); + for (final FocusNode ancestor in ancestors) { + ancestor._descendants = null; + } + _descendants = null; + assert(_manager == null || !_manager!.rootScope.descendants.contains(node)); + } + + void _updateManager(FocusManager? manager) { + _manager = manager; + for (final FocusNode descendant in descendants) { + descendant._manager = manager; + descendant._ancestors = null; + } + } + + // Used by FocusAttachment.reparent to perform the actual parenting operation. + @mustCallSuper + void _reparent(FocusNode child) { + assert(child != this, 'Tried to make a child into a parent of itself.'); + if (child._parent == this) { + assert(_children.contains(child), "Found a node that says it's a child, but doesn't appear in the child list."); + // The child is already a child of this parent. + return; + } + assert(_manager == null || child != _manager!.rootScope, "Reparenting the root node isn't allowed."); + assert(!ancestors.contains(child), 'The supplied child is already an ancestor of this node. Loops are not allowed.'); + final FocusScopeNode? oldScope = child.enclosingScope; + final bool hadFocus = child.hasFocus; + child._parent?._removeChild(child, removeScopeFocus: oldScope != nearestScope); + _children.add(child); + child._parent = this; + child._ancestors = null; + child._updateManager(_manager); + for (final FocusNode ancestor in child.ancestors) { + ancestor._descendants = null; + } + if (hadFocus) { + // Update the focus chain for the current focus without changing it. + _manager?.primaryFocus?._setAsFocusedChildForScope(); + } + if (oldScope != null && child.context != null && child.enclosingScope != oldScope) { + FocusTraversalGroup.maybeOf(child.context!)?.changedScope(node: child, oldScope: oldScope); + } + if (child._requestFocusWhenReparented) { + child._doRequestFocus(findFirstFocus: true); + child._requestFocusWhenReparented = false; + } + } + + /// Called by the _host_ [StatefulWidget] to attach a [FocusNode] to the + /// widget tree. + /// + /// In order to attach a [FocusNode] to the widget tree, call [attach], + /// typically from the [StatefulWidget]'s [State.initState] method. + /// + /// If the focus node in the host widget is swapped out, the new node will + /// need to be attached. [FocusAttachment.detach] should be called on the old + /// node, and then [attach] called on the new node. This typically happens in + /// the [State.didUpdateWidget] method. + /// + /// To receive key events that focuses on this node, pass a listener to + /// `onKeyEvent`. + @mustCallSuper + FocusAttachment attach( + BuildContext? context, { + FocusOnKeyEventCallback? onKeyEvent, + @Deprecated( + 'Use onKeyEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + FocusOnKeyCallback? onKey, + }) { + _context = context; + this.onKey = onKey ?? this.onKey; + this.onKeyEvent = onKeyEvent ?? this.onKeyEvent; + _attachment = FocusAttachment._(this); + return _attachment!; + } + + @override + void dispose() { + // Detaching will also unfocus and clean up the manager's data structures. + _attachment?.detach(); + super.dispose(); + } + + @mustCallSuper + void _notify() { + if (_parent == null) { + // no longer part of the tree, so don't notify. + return; + } + if (hasPrimaryFocus) { + _setAsFocusedChildForScope(); + } + notifyListeners(); + } + + /// Requests the primary focus for this node, or for a supplied [node], which + /// will also give focus to its [ancestors]. + /// + /// If called without a node, request focus for this node. If the node hasn't + /// been added to the focus tree yet, then defer the focus request until it + /// is, allowing newly created widgets to request focus as soon as they are + /// added. + /// + /// If the given [node] is not yet a part of the focus tree, then this method + /// will add the [node] as a child of this node before requesting focus. + /// + /// If the given [node] is a [FocusScopeNode] and that focus scope node has a + /// non-null [FocusScopeNode.focusedChild], then request the focus for the + /// focused child. This process is recursive and continues until it encounters + /// either a focus scope node with a null focused child or an ordinary + /// (non-scope) [FocusNode] is found. + /// + /// The node is notified that it has received the primary focus in a + /// microtask, so notification may lag the request by up to one frame. + void requestFocus([FocusNode? node]) { + if (node != null) { + if (node._parent == null) { + _reparent(node); + } + assert(node.ancestors.contains(this), 'Focus was requested for a node that is not a descendant of the scope from which it was requested.'); + node._doRequestFocus(findFirstFocus: true); + return; + } + _doRequestFocus(findFirstFocus: true); + } + + // This is overridden in FocusScopeNode. + void _doRequestFocus({required bool findFirstFocus}) { + if (!canRequestFocus) { + assert(_focusDebug(() => 'Node NOT requesting focus because canRequestFocus is false: $this')); + return; + } + // If the node isn't part of the tree, then we just defer the focus request + // until the next time it is reparented, so that it's possible to focus + // newly added widgets. + if (_parent == null) { + _requestFocusWhenReparented = true; + return; + } + _setAsFocusedChildForScope(); + if (hasPrimaryFocus && (_manager!._markedForFocus == null || _manager!._markedForFocus == this)) { + return; + } + _hasKeyboardToken = true; + assert(_focusDebug(() => 'Node requesting focus: $this')); + _markNextFocus(this); + } + + // If set to true, the node will request focus on this node the next time + // this node is reparented in the focus tree. + // + // Once requestFocus has been called at the next reparenting, this value + // will be reset to false. + // + // This will only force a call to requestFocus for the node once the next time + // the node is reparented. After that, _requestFocusWhenReparented would need + // to be set to true again to have it be focused again on the next + // reparenting. + // + // This is used when requestFocus is called and there is no parent yet. + bool _requestFocusWhenReparented = false; + + /// Sets this node as the [FocusScopeNode.focusedChild] of the enclosing + /// scope. + /// + /// Sets this node as the focused child for the enclosing scope, and that + /// scope as the focused child for the scope above it, etc., until it reaches + /// the root node. It doesn't change the primary focus, it just changes what + /// node would be focused if the enclosing scope receives focus, and keeps + /// track of previously focused children in that scope, so that if the focused + /// child in that scope is removed, the previous focus returns. + void _setAsFocusedChildForScope() { + FocusNode scopeFocus = this; + for (final FocusScopeNode ancestor in ancestors.whereType<FocusScopeNode>()) { + assert(scopeFocus != ancestor, 'Somehow made a loop by setting focusedChild to its scope.'); + assert(_focusDebug(() => 'Setting $scopeFocus as focused child for scope:', () => <Object>[ancestor])); + // Remove it anywhere in the focused child history. + ancestor._focusedChildren.remove(scopeFocus); + // Add it to the end of the list, which is also the top of the queue: The + // end of the list represents the currently focused child. + ancestor._focusedChildren.add(scopeFocus); + scopeFocus = ancestor; + } + } + + /// Request to move the focus to the next focus node, by calling the + /// [FocusTraversalPolicy.next] method. + /// + /// Returns true if it successfully found a node and requested focus. + bool nextFocus() => FocusTraversalGroup.of(context!).next(this); + + /// Request to move the focus to the previous focus node, by calling the + /// [FocusTraversalPolicy.previous] method. + /// + /// Returns true if it successfully found a node and requested focus. + bool previousFocus() => FocusTraversalGroup.of(context!).previous(this); + + /// Request to move the focus to the nearest focus node in the given + /// direction, by calling the [FocusTraversalPolicy.inDirection] method. + /// + /// Returns true if it successfully found a node and requested focus. + bool focusInDirection(TraversalDirection direction) => FocusTraversalGroup.of(context!).inDirection(this, direction); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<BuildContext>('context', context, defaultValue: null)); + properties.add(FlagProperty('descendantsAreFocusable', value: descendantsAreFocusable, ifFalse: 'DESCENDANTS UNFOCUSABLE', defaultValue: true)); + properties.add(FlagProperty('descendantsAreTraversable', value: descendantsAreTraversable, ifFalse: 'DESCENDANTS UNTRAVERSABLE', defaultValue: true)); + properties.add(FlagProperty('canRequestFocus', value: canRequestFocus, ifFalse: 'NOT FOCUSABLE', defaultValue: true)); + properties.add(FlagProperty('hasFocus', value: hasFocus && !hasPrimaryFocus, ifTrue: 'IN FOCUS PATH', defaultValue: false)); + properties.add(FlagProperty('hasPrimaryFocus', value: hasPrimaryFocus, ifTrue: 'PRIMARY FOCUS', defaultValue: false)); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + int count = 1; + return _children.map<DiagnosticsNode>((FocusNode child) { + return child.toDiagnosticsNode(name: 'Child ${count++}'); + }).toList(); + } + + @override + String toStringShort() { + final bool hasDebugLabel = debugLabel != null && debugLabel!.isNotEmpty; + final String extraData = '${hasDebugLabel ? debugLabel : ''}' + '${hasFocus && hasDebugLabel ? ' ' : ''}' + '${hasFocus && !hasPrimaryFocus ? '[IN FOCUS PATH]' : ''}' + '${hasPrimaryFocus ? '[PRIMARY FOCUS]' : ''}'; + return '${describeIdentity(this)}${extraData.isNotEmpty ? '($extraData)' : ''}'; + } +} + +/// A subclass of [FocusNode] that acts as a scope for its descendants, +/// maintaining information about which descendant is currently or was last +/// focused. +/// +/// _Please see the [FocusScope] and [Focus] widgets, which are utility widgets +/// that manage their own [FocusScopeNode]s and [FocusNode]s, respectively. If +/// they aren't appropriate, [FocusScopeNode]s can be managed directly._ +/// +/// [FocusScopeNode] organizes [FocusNode]s into _scopes_. Scopes form sub-trees +/// of nodes that can be traversed as a group. Within a scope, the most recent +/// nodes to have focus are remembered, and if a node is focused and then +/// removed, the original node receives focus again. +/// +/// From a [FocusScopeNode], calling [setFirstFocus], sets the given focus scope +/// as the [focusedChild] of this node, adopting if it isn't already part of the +/// focus tree. +/// +/// {@macro flutter.widgets.FocusNode.lifecycle} +/// {@macro flutter.widgets.FocusNode.keyEvents} +/// +/// See also: +/// +/// * [Focus], a widget that manages a [FocusNode] and provides access to focus +/// information and actions to its descendant widgets. +/// * [FocusManager], a singleton that manages the primary focus and +/// distributes key events to focused nodes. +class FocusScopeNode extends FocusNode { + /// Creates a [FocusScopeNode]. + /// + /// All parameters are optional. + FocusScopeNode({ + super.debugLabel, + super.onKeyEvent, + @Deprecated( + 'Use onKeyEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + super.onKey, + super.skipTraversal, + super.canRequestFocus, + this.traversalEdgeBehavior = TraversalEdgeBehavior.closedLoop, + }) : super( + descendantsAreFocusable: true, + ); + + @override + FocusScopeNode get nearestScope => this; + + /// Controls the transfer of focus beyond the first and the last items of a + /// [FocusScopeNode]. + /// + /// Changing this field value has no immediate effect on the UI. Instead, next time + /// focus traversal takes place [FocusTraversalPolicy] will read this value + /// and apply the new behavior. + TraversalEdgeBehavior traversalEdgeBehavior; + + /// Returns true if this scope is the focused child of its parent scope. + bool get isFirstFocus => enclosingScope!.focusedChild == this; + + /// Returns the child of this node that should receive focus if this scope + /// node receives focus. + /// + /// If [hasFocus] is true, then this points to the child of this node that is + /// currently focused. + /// + /// Returns null if there is no currently focused child. + FocusNode? get focusedChild { + assert(_focusedChildren.isEmpty || _focusedChildren.last.enclosingScope == this, 'Focused child does not have the same idea of its enclosing scope as the scope does.'); + return _focusedChildren.isNotEmpty ? _focusedChildren.last : null; + } + + // A stack of the children that have been set as the focusedChild, most recent + // last (which is the top of the stack). + final List<FocusNode> _focusedChildren = <FocusNode>[]; + + /// An iterator over the children that are allowed to be traversed by the + /// [FocusTraversalPolicy]. + /// + /// Will return an empty iterable if this scope node is not focusable, or if + /// [descendantsAreFocusable] is false. + /// + /// See also: + /// + /// * [traversalDescendants], which traverses all of the node's descendants, + /// not just the immediate children. + @override + Iterable<FocusNode> get traversalChildren { + if (!canRequestFocus) { + return const Iterable<FocusNode>.empty(); + } + return super.traversalChildren; + } + + /// Returns all descendants which do not have the [skipTraversal] and do have + /// the [canRequestFocus] flag set. + /// + /// Will return an empty iterable if this scope node is not focusable, or if + /// [descendantsAreFocusable] is false. + @override + Iterable<FocusNode> get traversalDescendants { + if (!canRequestFocus) { + return const Iterable<FocusNode>.empty(); + } + return super.traversalDescendants; + } + + /// Make the given [scope] the active child scope for this scope. + /// + /// If the given [scope] is not yet a part of the focus tree, then add it to + /// the tree as a child of this scope. If it is already part of the focus + /// tree, the given scope must be a descendant of this scope. + void setFirstFocus(FocusScopeNode scope) { + assert(scope != this, 'Unexpected self-reference in setFirstFocus.'); + assert(_focusDebug(() => 'Setting scope as first focus in $this to node:', () => <Object>[scope])); + if (scope._parent == null) { + _reparent(scope); + } + assert(scope.ancestors.contains(this), '$FocusScopeNode $scope must be a child of $this to set it as first focus.'); + if (hasFocus) { + scope._doRequestFocus(findFirstFocus: true); + } else { + scope._setAsFocusedChildForScope(); + } + } + + /// If this scope lacks a focus, request that the given node become the focus. + /// + /// If the given node is not yet part of the focus tree, then add it as a + /// child of this node. + /// + /// Useful for widgets that wish to grab the focus if no other widget already + /// has the focus. + /// + /// The node is notified that it has received the primary focus in a + /// microtask, so notification may lag the request by up to one frame. + void autofocus(FocusNode node) { + // Attach the node to the tree first, so in _applyFocusChange if the node + // is detached we don't add it back to the tree. + if (node._parent == null) { + _reparent(node); + } + + assert(_manager != null); + assert(_focusDebug(() => 'Autofocus scheduled for $node: scope $this')); + _manager?._pendingAutofocuses.add(_Autofocus(scope: this, autofocusNode: node)); + _manager?._markNeedsUpdate(); + } + + @override + void _doRequestFocus({required bool findFirstFocus}) { + + // It is possible that a previously focused child is no longer focusable. + while (this.focusedChild != null && !this.focusedChild!.canRequestFocus) { + _focusedChildren.removeLast(); + } + + final FocusNode? focusedChild = this.focusedChild; + // If findFirstFocus is false, then the request is to make this scope the + // focus instead of looking for the ultimate first focus for this scope and + // its descendants. + if (!findFirstFocus || focusedChild == null) { + if (canRequestFocus) { + _setAsFocusedChildForScope(); + _markNextFocus(this); + } + return; + } + + focusedChild._doRequestFocus(findFirstFocus: true); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + if (_focusedChildren.isEmpty) { + return; + } + final List<String> childList = _focusedChildren.reversed.map<String>((FocusNode child) { + return child.toStringShort(); + }).toList(); + properties.add(IterableProperty<String>('focusedChildren', childList, defaultValue: const Iterable<String>.empty())); + properties.add(DiagnosticsProperty<TraversalEdgeBehavior>('traversalEdgeBehavior', traversalEdgeBehavior, defaultValue: TraversalEdgeBehavior.closedLoop)); + } +} + +/// An enum to describe which kind of focus highlight behavior to use when +/// displaying focus information. +enum FocusHighlightMode { + /// Touch interfaces will not show the focus highlight except for controls + /// which bring up the soft keyboard. + /// + /// If a device that uses a traditional mouse and keyboard has a touch screen + /// attached, it can also enter `touch` mode if the user is using the touch + /// screen. + touch, + + /// Traditional interfaces (keyboard and mouse) will show the currently + /// focused control via a focus highlight of some sort. + /// + /// If a touch device (like a mobile phone) has a keyboard and/or mouse + /// attached, it also can enter `traditional` mode if the user is using these + /// input devices. + traditional, +} + +/// An enum to describe how the current value of [FocusManager.highlightMode] is +/// determined. The strategy is set on [FocusManager.highlightStrategy]. +enum FocusHighlightStrategy { + /// Automatic switches between the various highlight modes based on the last + /// kind of input that was received. This is the default. + automatic, + + /// [FocusManager.highlightMode] always returns [FocusHighlightMode.touch]. + alwaysTouch, + + /// [FocusManager.highlightMode] always returns [FocusHighlightMode.traditional]. + alwaysTraditional, +} + +/// Manages the focus tree. +/// +/// The focus tree is a separate, sparser, tree from the widget tree that +/// maintains the hierarchical relationship between focusable widgets in the +/// widget tree. +/// +/// The focus manager is responsible for tracking which [FocusNode] has the +/// primary input focus (the [primaryFocus]), holding the [FocusScopeNode] that +/// is the root of the focus tree (the [rootScope]), and what the current +/// [highlightMode] is. It also distributes [KeyEvent]s to the nodes in the +/// focus tree. +/// +/// The singleton [FocusManager] instance is held by the [WidgetsBinding] as +/// [WidgetsBinding.focusManager], and can be conveniently accessed using the +/// [FocusManager.instance] static accessor. +/// +/// To find the [FocusNode] for a given [BuildContext], use [Focus.of]. To find +/// the [FocusScopeNode] for a given [BuildContext], use [FocusScope.of]. +/// +/// If you would like notification whenever the [primaryFocus] changes, register +/// a listener with [addListener]. When you no longer want to receive these +/// events, as when your object is about to be disposed, you must unregister +/// with [removeListener] to avoid memory leaks. Removing listeners is typically +/// done in [State.dispose] on stateful widgets. +/// +/// The [highlightMode] describes how focus highlights should be displayed on +/// components in the UI. The [highlightMode] changes are notified separately +/// via [addHighlightModeListener] and removed with +/// [removeHighlightModeListener]. The highlight mode changes when the user +/// switches from a mouse to a touch interface, or vice versa. +/// +/// The widgets that are used to manage focus in the widget tree are: +/// +/// * [Focus], a widget that manages a [FocusNode] in the focus tree so that +/// the focus tree reflects changes in the widget hierarchy. +/// * [FocusScope], a widget that manages a [FocusScopeNode] in the focus tree, +/// creating a new scope for restricting focus to a set of focus nodes. +/// * [FocusTraversalGroup], a widget that groups together nodes that should be +/// traversed using an order described by a given [FocusTraversalPolicy]. +/// +/// See also: +/// +/// * [FocusNode], which is a node in the focus tree that can receive focus. +/// * [FocusScopeNode], which is a node in the focus tree used to collect +/// subtrees into groups and restrict focus to them. +/// * The [primaryFocus] global accessor, for convenient access from anywhere +/// to the current focus manager state. +class FocusManager with DiagnosticableTreeMixin, ChangeNotifier { + /// Creates an object that manages the focus tree. + /// + /// This constructor is rarely called directly. To access the [FocusManager], + /// consider using the [FocusManager.instance] accessor instead (which gets it + /// from the [WidgetsBinding] singleton). + /// + /// This newly constructed focus manager does not have the necessary event + /// handlers registered to allow it to manage focus. To register those event + /// handlers, callers must call [registerGlobalHandlers]. See the + /// documentation in that method for caveats to watch out for. + FocusManager() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + rootScope._manager = this; + } + + /// Registers global input event handlers that are needed to manage focus. + /// + /// This calls the [HardwareKeyboard.addHandler] on the shared instance of + /// [HardwareKeyboard] and adds a route to the global entry in the gesture + /// routing table. As such, only one [FocusManager] instance should register + /// its global handlers. + /// + /// When this focus manager is no longer needed, calling [dispose] on it will + /// unregister these handlers. + void registerGlobalHandlers() => _highlightManager.registerGlobalHandlers(); + + @override + void dispose() { + _highlightManager.dispose(); + rootScope.dispose(); + super.dispose(); + } + + /// Provides convenient access to the current [FocusManager] singleton from + /// the [WidgetsBinding] instance. + static FocusManager get instance => WidgetsBinding.instance.focusManager; + + final _HighlightModeManager _highlightManager = _HighlightModeManager(); + + /// Sets the strategy by which [highlightMode] is determined. + /// + /// If set to [FocusHighlightStrategy.automatic], then the highlight mode will + /// change depending upon the interaction mode used last. For instance, if the + /// last interaction was a touch interaction, then [highlightMode] will return + /// [FocusHighlightMode.touch], and focus highlights will only appear on + /// widgets that bring up a soft keyboard. If the last interaction was a + /// non-touch interaction (hardware keyboard press, mouse click, etc.), then + /// [highlightMode] will return [FocusHighlightMode.traditional], and focus + /// highlights will appear on all widgets. + /// + /// If set to [FocusHighlightStrategy.alwaysTouch] or + /// [FocusHighlightStrategy.alwaysTraditional], then [highlightMode] will + /// always return [FocusHighlightMode.touch] or + /// [FocusHighlightMode.traditional], respectively, regardless of the last UI + /// interaction type. + /// + /// The initial value of [highlightMode] depends upon the value of + /// [defaultTargetPlatform] and [MouseTracker.mouseIsConnected] of + /// [RendererBinding.mouseTracker], making a guess about which interaction is + /// most appropriate for the initial interaction mode. + /// + /// Defaults to [FocusHighlightStrategy.automatic]. + FocusHighlightStrategy get highlightStrategy => _highlightManager.strategy; + set highlightStrategy(FocusHighlightStrategy value) { + if (_highlightManager.strategy == value) { + return; + } + _highlightManager.strategy = value; + } + + /// Indicates the current interaction mode for focus highlights. + /// + /// The value returned depends upon the [highlightStrategy] used, and possibly + /// (depending on the value of [highlightStrategy]) the most recent + /// interaction mode that they user used. + /// + /// If [highlightMode] returns [FocusHighlightMode.touch], then widgets should + /// not draw their focus highlight unless they perform text entry. + /// + /// If [highlightMode] returns [FocusHighlightMode.traditional], then widgets should + /// draw their focus highlight whenever they are focused. + // Don't want to set _highlightMode here, since it's possible for the target + // platform to change (especially in tests). + FocusHighlightMode get highlightMode => _highlightManager.highlightMode; + + /// Register a closure to be called when the [FocusManager] notifies its listeners + /// that the value of [highlightMode] has changed. + void addHighlightModeListener(ValueChanged<FocusHighlightMode> listener) => _highlightManager.addListener(listener); + + /// Remove a previously registered closure from the list of closures that the + /// [FocusManager] notifies. + void removeHighlightModeListener(ValueChanged<FocusHighlightMode> listener) => _highlightManager.removeListener(listener); + + /// {@template flutter.widgets.focus_manager.FocusManager.addEarlyKeyEventHandler} + /// Adds a key event handler to a set of handlers that are called before any + /// key event handlers in the focus tree are called. + /// + /// All of the handlers in the set will be called for every key event the + /// [FocusManager] receives. If any one of the handlers returns + /// [KeyEventResult.handled] or [KeyEventResult.skipRemainingHandlers], then + /// none of the handlers in the focus tree will be called. + /// + /// If handlers are added while the existing callbacks are being invoked, they + /// will not be called until the next key event occurs. + /// + /// See also: + /// + /// * [removeEarlyKeyEventHandler], which removes handlers added by this + /// function. + /// * [addLateKeyEventHandler], which is a similar mechanism for adding + /// handlers that are invoked after the focus tree has had a chance to + /// handle an event. + /// {@endtemplate} + void addEarlyKeyEventHandler(OnKeyEventCallback handler) { + _highlightManager.addEarlyKeyEventHandler(handler); + } + + /// {@template flutter.widgets.focus_manager.FocusManager.removeEarlyKeyEventHandler} + /// Removes a key handler added by calling [addEarlyKeyEventHandler]. + /// + /// If handlers are removed while the existing callbacks are being invoked, + /// they will continue to be called until the next key event is received. + /// + /// See also: + /// + /// * [addEarlyKeyEventHandler], which adds the handlers removed by this + /// function. + /// {@endtemplate} + void removeEarlyKeyEventHandler(OnKeyEventCallback handler) { + _highlightManager.removeEarlyKeyEventHandler(handler); + } + + /// {@template flutter.widgets.focus_manager.FocusManager.addLateKeyEventHandler} + /// Adds a key event handler to a set of handlers that are called if none of + /// the key event handlers in the focus tree handle the event. + /// + /// If the event reaches the root of the focus tree without being handled, + /// then all of the handlers in the set will be called. If any of them returns + /// [KeyEventResult.handled] or [KeyEventResult.skipRemainingHandlers], then + /// event propagation to the platform will be stopped. + /// + /// If handlers are added while the existing callbacks are being invoked, they + /// will not be called until the next key event is not handled by the focus + /// tree. + /// + /// See also: + /// + /// * [removeLateKeyEventHandler], which removes handlers added by this + /// function. + /// * [addEarlyKeyEventHandler], which is a similar mechanism for adding + /// handlers that are invoked before the focus tree has had a chance to + /// handle an event. + /// {@endtemplate} + void addLateKeyEventHandler(OnKeyEventCallback handler) { + _highlightManager.addLateKeyEventHandler(handler); + } + + /// {@template flutter.widgets.focus_manager.FocusManager.removeLateKeyEventHandler} + /// Removes a key handler added by calling [addLateKeyEventHandler]. + /// + /// If handlers are removed while the existing callbacks are being invoked, + /// they will continue to be called until the next key event is received. + /// + /// See also: + /// + /// * [addLateKeyEventHandler], which adds the handlers removed by this + /// function. + /// {@endtemplate} + void removeLateKeyEventHandler(OnKeyEventCallback handler) { + _highlightManager.removeLateKeyEventHandler(handler); + } + + /// The root [FocusScopeNode] in the focus tree. + /// + /// This field is rarely used directly. To find the nearest [FocusScopeNode] + /// for a given [FocusNode], call [FocusNode.nearestScope]. + final FocusScopeNode rootScope = FocusScopeNode(debugLabel: 'Root Focus Scope'); + + /// The node that currently has the primary focus. + FocusNode? get primaryFocus => _primaryFocus; + FocusNode? _primaryFocus; + + // The set of nodes that need to notify their listeners of changes at the next + // update. + final Set<FocusNode> _dirtyNodes = <FocusNode>{}; + + // The node that has requested to have the primary focus, but hasn't been + // given it yet. + FocusNode? _markedForFocus; + + void _markDetached(FocusNode node) { + // The node has been removed from the tree, so it no longer needs to be + // notified of changes. + assert(_focusDebug(() => 'Node was detached: $node')); + if (_primaryFocus == node) { + _primaryFocus = null; + } + _dirtyNodes.remove(node); + } + + void _markPropertiesChanged(FocusNode node) { + _markNeedsUpdate(); + assert(_focusDebug(() => 'Properties changed for node $node.')); + _dirtyNodes.add(node); + } + + void _markNextFocus(FocusNode node) { + if (_primaryFocus == node) { + // The caller asked for the current focus to be the next focus, so just + // pretend that didn't happen. + _markedForFocus = null; + } else { + _markedForFocus = node; + _markNeedsUpdate(); + } + } + + // The list of autofocus requests made since the last _applyFocusChange call. + final List<_Autofocus> _pendingAutofocuses = <_Autofocus>[]; + + // True indicates that there is an update pending. + bool _haveScheduledUpdate = false; + + // Request that an update be scheduled, optionally requesting focus for the + // given newFocus node. + void _markNeedsUpdate() { + assert(_focusDebug(() => 'Scheduling update, current focus is $_primaryFocus, next focus will be $_markedForFocus')); + if (_haveScheduledUpdate) { + return; + } + _haveScheduledUpdate = true; + scheduleMicrotask(applyFocusChangesIfNeeded); + } + + /// Applies any pending focus changes and notifies listeners that the focus + /// has changed. + /// + /// Must not be called during the build phase. This method is meant to be + /// called in a post-frame callback or microtask when the pending focus + /// changes need to be resolved before something else occurs. + /// + /// It can't be called during the build phase because not all listeners are + /// safe to be called with an update during a build. + /// + /// Typically, this is called automatically by the [FocusManager], but + /// sometimes it is necessary to ensure that no focus changes are pending + /// before executing an action. For example, the [MenuAnchor] class uses this + /// to make sure that the previous focus has been restored before executing a + /// menu callback when a menu item is selected. + /// + /// It is safe to call this if no focus changes are pending. + void applyFocusChangesIfNeeded() { + assert( + SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks, + 'applyFocusChangesIfNeeded() should not be called during the build phase.' + ); + + _haveScheduledUpdate = false; + final FocusNode? previousFocus = _primaryFocus; + + for (final _Autofocus autofocus in _pendingAutofocuses) { + autofocus.applyIfValid(this); + } + _pendingAutofocuses.clear(); + + if (_primaryFocus == null && _markedForFocus == null) { + // If we don't have any current focus, and nobody has asked to focus yet, + // then revert to the root scope. + _markedForFocus = rootScope; + } + assert(_focusDebug(() => 'Refreshing focus state. Next focus will be $_markedForFocus')); + // A node has requested to be the next focus, and isn't already the primary + // focus. + if (_markedForFocus != null && _markedForFocus != _primaryFocus) { + final Set<FocusNode> previousPath = previousFocus?.ancestors.toSet() ?? <FocusNode>{}; + final Set<FocusNode> nextPath = _markedForFocus!.ancestors.toSet(); + // Notify nodes that are newly focused. + _dirtyNodes.addAll(nextPath.difference(previousPath)); + // Notify nodes that are no longer focused + _dirtyNodes.addAll(previousPath.difference(nextPath)); + + _primaryFocus = _markedForFocus; + _markedForFocus = null; + } + assert(_markedForFocus == null); + if (previousFocus != _primaryFocus) { + assert(_focusDebug(() => 'Updating focus from $previousFocus to $_primaryFocus')); + if (previousFocus != null) { + _dirtyNodes.add(previousFocus); + } + if (_primaryFocus != null) { + _dirtyNodes.add(_primaryFocus!); + } + } + for (final FocusNode node in _dirtyNodes) { + node._notify(); + } + assert(_focusDebug(() => 'Notified ${_dirtyNodes.length} dirty nodes:', () => _dirtyNodes)); + _dirtyNodes.clear(); + if (previousFocus != _primaryFocus) { + notifyListeners(); + } + assert(() { + if (debugFocusChanges) { + debugDumpFocusTree(); + } + return true; + }()); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return <DiagnosticsNode>[ + rootScope.toDiagnosticsNode(name: 'rootScope'), + ]; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + properties.add(FlagProperty('haveScheduledUpdate', value: _haveScheduledUpdate, ifTrue: 'UPDATE SCHEDULED')); + properties.add(DiagnosticsProperty<FocusNode>('primaryFocus', primaryFocus, defaultValue: null)); + properties.add(DiagnosticsProperty<FocusNode>('nextFocus', _markedForFocus, defaultValue: null)); + final Element? element = primaryFocus?.context as Element?; + if (element != null) { + properties.add(DiagnosticsProperty<String>('primaryFocusCreator', element.debugGetCreatorChain(20))); + } + } +} + +// A class to detect and manage the highlight mode transitions. An instance of +// this is owned by the FocusManager. +// +// This doesn't extend ChangeNotifier because the callback passes the updated +// value, and ChangeNotifier requires using VoidCallback. +class _HighlightModeManager { + // If set, indicates if the last interaction detected was touch or not. If + // null, no interactions have occurred yet. + bool? _lastInteractionWasTouch; + + FocusHighlightMode get highlightMode => _highlightMode ?? _defaultModeForPlatform; + FocusHighlightMode? _highlightMode; + + FocusHighlightStrategy get strategy => _strategy; + FocusHighlightStrategy _strategy = FocusHighlightStrategy.automatic; + set strategy(FocusHighlightStrategy value) { + if (_strategy == value) { + return; + } + _strategy = value; + updateMode(); + } + + /// {@macro flutter.widgets.focus_manager.FocusManager.addEarlyKeyEventHandler} + void addEarlyKeyEventHandler(OnKeyEventCallback callback) => _earlyKeyEventHandlers.add(callback); + + /// {@macro flutter.widgets.focus_manager.FocusManager.removeEarlyKeyEventHandler} + void removeEarlyKeyEventHandler(OnKeyEventCallback callback) => _earlyKeyEventHandlers.remove(callback); + + // The list of callbacks for early key handling. + final HashedObserverList<OnKeyEventCallback> _earlyKeyEventHandlers = HashedObserverList<OnKeyEventCallback>(); + + /// {@macro flutter.widgets.focus_manager.FocusManager.addLateKeyEventHandler} + void addLateKeyEventHandler(OnKeyEventCallback callback) => _lateKeyEventHandlers.add(callback); + + /// {@macro flutter.widgets.focus_manager.FocusManager.removeLateKeyEventHandler} + void removeLateKeyEventHandler(OnKeyEventCallback callback) => _lateKeyEventHandlers.remove(callback); + + // The list of callbacks for late key handling. + final HashedObserverList<OnKeyEventCallback> _lateKeyEventHandlers = HashedObserverList<OnKeyEventCallback>(); + + /// Register a closure to be called when the [FocusManager] notifies its + /// listeners that the value of [highlightMode] has changed. + void addListener(ValueChanged<FocusHighlightMode> listener) => _listeners.add(listener); + + /// Remove a previously registered closure from the list of closures that the + /// [FocusManager] notifies. + void removeListener(ValueChanged<FocusHighlightMode> listener) => _listeners.remove(listener); + + // The list of listeners for [highlightMode] state changes. + HashedObserverList<ValueChanged<FocusHighlightMode>> _listeners = HashedObserverList<ValueChanged<FocusHighlightMode>>(); + + void registerGlobalHandlers() { + assert(ServicesBinding.instance.keyEventManager.keyMessageHandler == null); + // TODO(gspencergoog): Remove this when the RawKeyEvent system is + // deprecated, and replace it with registering a handler on the + // HardwareKeyboard. + ServicesBinding.instance.keyEventManager.keyMessageHandler = handleKeyMessage; + GestureBinding.instance.pointerRouter.addGlobalRoute(handlePointerEvent); + } + + @mustCallSuper + void dispose() { + if (ServicesBinding.instance.keyEventManager.keyMessageHandler == handleKeyMessage) { + GestureBinding.instance.pointerRouter.removeGlobalRoute(handlePointerEvent); + ServicesBinding.instance.keyEventManager.keyMessageHandler = null; + } + _listeners = HashedObserverList<ValueChanged<FocusHighlightMode>>(); + } + + @pragma('vm:notify-debugger-on-exception') + void notifyListeners() { + if (_listeners.isEmpty) { + return; + } + final List<ValueChanged<FocusHighlightMode>> localListeners = List<ValueChanged<FocusHighlightMode>>.of(_listeners); + for (final ValueChanged<FocusHighlightMode> listener in localListeners) { + try { + if (_listeners.contains(listener)) { + listener(highlightMode); + } + } catch (exception, stack) { + InformationCollector? collector; + assert(() { + collector = () => <DiagnosticsNode>[ + DiagnosticsProperty<_HighlightModeManager>( + 'The $runtimeType sending notification was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]; + return true; + }()); + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets library', + context: ErrorDescription('while dispatching notifications for $runtimeType'), + informationCollector: collector, + )); + } + } + } + + void handlePointerEvent(PointerEvent event) { + final FocusHighlightMode expectedMode; + switch (event.kind) { + case PointerDeviceKind.touch: + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + _lastInteractionWasTouch = true; + expectedMode = FocusHighlightMode.touch; + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + case PointerDeviceKind.unknown: + _lastInteractionWasTouch = false; + expectedMode = FocusHighlightMode.traditional; + } + if (expectedMode != highlightMode) { + updateMode(); + } + } + + bool handleKeyMessage(KeyMessage message) { + // Update highlightMode first, since things responding to the keys might + // look at the highlight mode, and it should be accurate. + _lastInteractionWasTouch = false; + updateMode(); + + assert(_focusDebug(() => 'Received key event $message')); + if (FocusManager.instance.primaryFocus == null) { + assert(_focusDebug(() => 'No primary focus for key event, ignored: $message')); + return false; + } + + bool handled = false; + // Check to see if any of the early handlers handle the key. If so, then + // return early. + if (_earlyKeyEventHandlers.isNotEmpty) { + final List<KeyEventResult> results = <KeyEventResult>[]; + // Copy the list before iteration to prevent problems if the list gets + // modified during iteration. + final List<OnKeyEventCallback> iterationList = _earlyKeyEventHandlers.toList(); + for (final OnKeyEventCallback callback in iterationList) { + for (final KeyEvent event in message.events) { + results.add(callback(event)); + } + } + final KeyEventResult result = combineKeyEventResults(results); + switch (result) { + case KeyEventResult.ignored: + break; + case KeyEventResult.handled: + assert(_focusDebug(() => 'Key event $message handled by early key event callback.')); + handled = true; + case KeyEventResult.skipRemainingHandlers: + assert(_focusDebug(() => 'Key event $message propagation stopped by early key event callback.')); + handled = false; + } + } + if (handled) { + return true; + } + + // Walk the current focus from the leaf to the root, calling each node's + // onKeyEvent on the way up, and if one responds that they handled it or + // want to stop propagation, stop. + for (final FocusNode node in <FocusNode>[ + FocusManager.instance.primaryFocus!, + ...FocusManager.instance.primaryFocus!.ancestors, + ]) { + final List<KeyEventResult> results = <KeyEventResult>[]; + if (node.onKeyEvent != null) { + for (final KeyEvent event in message.events) { + results.add(node.onKeyEvent!(node, event)); + } + } + if (node.onKey != null && message.rawEvent != null) { + results.add(node.onKey!(node, message.rawEvent!)); + } + final KeyEventResult result = combineKeyEventResults(results); + switch (result) { + case KeyEventResult.ignored: + continue; + case KeyEventResult.handled: + assert(_focusDebug(() => 'Node $node handled key event $message.')); + handled = true; + case KeyEventResult.skipRemainingHandlers: + assert(_focusDebug(() => 'Node $node stopped key event propagation: $message.')); + handled = false; + } + // Only KeyEventResult.ignored will continue the for loop. All other + // options will stop the event propagation. + assert(result != KeyEventResult.ignored); + break; + } + + // Check to see if any late key event handlers want to handle the event. + if (!handled && _lateKeyEventHandlers.isNotEmpty) { + final List<KeyEventResult> results = <KeyEventResult>[]; + // Copy the list before iteration to prevent problems if the list gets + // modified during iteration. + final List<OnKeyEventCallback> iterationList = _lateKeyEventHandlers.toList(); + for (final OnKeyEventCallback callback in iterationList) { + for (final KeyEvent event in message.events) { + results.add(callback(event)); + } + } + final KeyEventResult result = combineKeyEventResults(results); + switch (result) { + case KeyEventResult.ignored: + break; + case KeyEventResult.handled: + assert(_focusDebug(() => 'Key event $message handled by late key event callback.')); + handled = true; + case KeyEventResult.skipRemainingHandlers: + assert(_focusDebug(() => 'Key event $message propagation stopped by late key event callback.')); + handled = false; + } + } + if (!handled) { + assert(_focusDebug(() => 'Key event not handled by focus system: $message.')); + } + return handled; + } + + // Update function to be called whenever the state relating to highlightMode + // changes. + void updateMode() { + final FocusHighlightMode newMode; + switch (strategy) { + case FocusHighlightStrategy.automatic: + if (_lastInteractionWasTouch == null) { + // If we don't have any information about the last interaction yet, + // then just rely on the default value for the platform, which will be + // determined based on the target platform if _highlightMode is not + // set. + return; + } + if (_lastInteractionWasTouch!) { + newMode = FocusHighlightMode.touch; + } else { + newMode = FocusHighlightMode.traditional; + } + case FocusHighlightStrategy.alwaysTouch: + newMode = FocusHighlightMode.touch; + case FocusHighlightStrategy.alwaysTraditional: + newMode = FocusHighlightMode.traditional; + } + // We can't just compare newMode with _highlightMode here, since + // _highlightMode could be null, so we want to compare with the return value + // for the getter, since that's what clients will be looking at. + final FocusHighlightMode oldMode = highlightMode; + _highlightMode = newMode; + if (highlightMode != oldMode) { + notifyListeners(); + } + } + + static FocusHighlightMode get _defaultModeForPlatform { + // Assume that if we're on one of the mobile platforms, and there's no mouse + // connected, that the initial interaction will be touch-based, and that + // it's traditional mouse and keyboard on all other platforms. + // + // This only affects the initial value: the ongoing value is updated to a + // known correct value as soon as any pointer/keyboard events are received. + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + if (WidgetsBinding.instance.mouseTracker.mouseIsConnected) { + return FocusHighlightMode.traditional; + } + return FocusHighlightMode.touch; + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return FocusHighlightMode.traditional; + } + } +} + +/// Provides convenient access to the current [FocusManager.primaryFocus] from +/// the [WidgetsBinding] instance. +FocusNode? get primaryFocus => WidgetsBinding.instance.focusManager.primaryFocus; + +/// Returns a text representation of the current focus tree, along with the +/// current attributes on each node. +/// +/// Will return an empty string in release builds. +String debugDescribeFocusTree() { + String? result; + assert(() { + result = FocusManager.instance.toStringDeep(); + return true; + }()); + return result ?? ''; +} + +/// Prints a text representation of the current focus tree, along with the +/// current attributes on each node. +/// +/// Will do nothing in release builds. +void debugDumpFocusTree() { + assert(() { + debugPrint(debugDescribeFocusTree()); + return true; + }()); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/focus_scope.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/focus_scope.dart new file mode 100644 index 0000000000000000000000000000000000000000..0b8a19563e730f8db05494848e5c5147a903f2df --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/focus_scope.dart @@ -0,0 +1,914 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic.dart'; +import 'focus_manager.dart'; +import 'framework.dart'; +import 'inherited_notifier.dart'; + +/// A widget that manages a [FocusNode] to allow keyboard focus to be given +/// to this widget and its descendants. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=JCDfh5bs1xc} +/// +/// When the focus is gained or lost, [onFocusChange] is called. +/// +/// For keyboard events, [onKey] and [onKeyEvent] are called if +/// [FocusNode.hasFocus] is true for this widget's [focusNode], unless a focused +/// descendant's [onKey] or [onKeyEvent] callback returned +/// [KeyEventResult.handled] when called. +/// +/// This widget does not provide any visual indication that the focus has +/// changed. Any desired visual changes should be made when [onFocusChange] is +/// called. +/// +/// To access the [FocusNode] of the nearest ancestor [Focus] widget and +/// establish a relationship that will rebuild the widget when the focus +/// changes, use the [Focus.of] and [FocusScope.of] static methods. +/// +/// To access the focused state of the nearest [Focus] widget, use +/// [FocusNode.hasFocus] from a build method, which also establishes a +/// relationship between the calling widget and the [Focus] widget that will +/// rebuild the calling widget when the focus changes. +/// +/// Managing a [FocusNode] means managing its lifecycle, listening for changes +/// in focus, and re-parenting it when needed to keep the focus hierarchy in +/// sync with the widget hierarchy. This widget does all of those things for +/// you. See [FocusNode] for more information about the details of what node +/// management entails if you are not using a [Focus] widget and you need to do +/// it yourself. +/// +/// If the [Focus] default constructor is used, then this widget will manage any +/// given [focusNode] by overwriting the appropriate values of the [focusNode] +/// with the values of [FocusNode.onKey], [FocusNode.onKeyEvent], +/// [FocusNode.skipTraversal], [FocusNode.canRequestFocus], and +/// [FocusNode.descendantsAreFocusable] whenever the [Focus] widget is updated. +/// +/// If the [Focus.withExternalFocusNode] is used instead, then the values +/// returned by [onKey], [onKeyEvent], [skipTraversal], [canRequestFocus], and +/// [descendantsAreFocusable] will be the values in the external focus node, and +/// the external focus node's values will not be overwritten when the widget is +/// updated. +/// +/// To collect a sub-tree of nodes into an exclusive group that restricts focus +/// traversal to the group, use a [FocusScope]. To collect a sub-tree of nodes +/// into a group that has a specific order to its traversal but allows the +/// traversal to escape the group, use a [FocusTraversalGroup]. +/// +/// To move the focus, use methods on [FocusNode] by getting the [FocusNode] +/// through the [of] method. For instance, to move the focus to the next node in +/// the focus traversal order, call `Focus.of(context).nextFocus()`. To unfocus +/// a widget, call `Focus.of(context).unfocus()`. +/// +/// {@tool dartpad} +/// This example shows how to manage focus using the [Focus] and [FocusScope] +/// widgets. See [FocusNode] for a similar example that doesn't use [Focus] or +/// [FocusScope]. +/// +/// ** See code in examples/api/lib/widgets/focus_scope/focus.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to wrap another widget in a [Focus] widget to make it +/// focusable. It wraps a [Container], and changes the container's color when it +/// is set as the [FocusManager.primaryFocus]. +/// +/// If you also want to handle mouse hover and/or keyboard actions on a widget, +/// consider using a [FocusableActionDetector], which combines several different +/// widgets to provide those capabilities. +/// +/// ** See code in examples/api/lib/widgets/focus_scope/focus.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows how to focus a newly-created widget immediately after it +/// is created. +/// +/// The focus node will not actually be given the focus until after the frame in +/// which it has requested focus is drawn, so it is OK to call +/// [FocusNode.requestFocus] on a node which is not yet in the focus tree. +/// +/// ** See code in examples/api/lib/widgets/focus_scope/focus.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [FocusNode], which represents a node in the focus hierarchy and +/// [FocusNode]'s API documentation includes a detailed explanation of its role +/// in the overall focus system. +/// * [FocusScope], a widget that manages a group of focusable widgets using a +/// [FocusScopeNode]. +/// * [FocusScopeNode], a node that collects focus nodes into a group for +/// traversal. +/// * [FocusManager], a singleton that manages the primary focus and +/// distributes key events to focused nodes. +/// * [FocusTraversalPolicy], an object used to determine how to move the focus +/// to other nodes. +/// * [FocusTraversalGroup], a widget that groups together and imposes a +/// traversal policy on the [Focus] nodes below it in the widget hierarchy. +class Focus extends StatefulWidget { + /// Creates a widget that manages a [FocusNode]. + const Focus({ + super.key, + required this.child, + this.focusNode, + this.parentNode, + this.autofocus = false, + this.onFocusChange, + FocusOnKeyEventCallback? onKeyEvent, + @Deprecated( + 'Use onKeyEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + FocusOnKeyCallback? onKey, + bool? canRequestFocus, + bool? skipTraversal, + bool? descendantsAreFocusable, + bool? descendantsAreTraversable, + this.includeSemantics = true, + String? debugLabel, + }) : _onKeyEvent = onKeyEvent, + _onKey = onKey, + _canRequestFocus = canRequestFocus, + _skipTraversal = skipTraversal, + _descendantsAreFocusable = descendantsAreFocusable, + _descendantsAreTraversable = descendantsAreTraversable, + _debugLabel = debugLabel; + + /// Creates a Focus widget that uses the given [focusNode] as the source of + /// truth for attributes on the node, rather than the attributes of this widget. + const factory Focus.withExternalFocusNode({ + Key? key, + required Widget child, + required FocusNode focusNode, + FocusNode? parentNode, + bool autofocus, + ValueChanged<bool>? onFocusChange, + bool includeSemantics, + }) = _FocusWithExternalFocusNode; + + // Indicates whether the widget's focusNode attributes should have priority + // when then widget is updated. + bool get _usingExternalFocus => false; + + /// The optional parent node to use when reparenting the [focusNode] for this + /// [Focus] widget. + /// + /// If [parentNode] is null, then [Focus.maybeOf] is used to find the parent + /// in the widget tree, which is typically what is desired, since it is easier + /// to reason about the focus tree if it mirrors the shape of the widget tree. + /// + /// Set this property if the focus tree needs to have a different shape than + /// the widget tree. This is typically in cases where a dialog is in an + /// [Overlay] (or another part of the widget tree), and focus should + /// behave as if the widgets in the overlay are descendants of the given + /// [parentNode] for purposes of focus. + /// + /// Defaults to null. + final FocusNode? parentNode; + + /// The child widget of this [Focus]. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// {@template flutter.widgets.Focus.focusNode} + /// An optional focus node to use as the focus node for this widget. + /// + /// If one is not supplied, then one will be automatically allocated, owned, + /// and managed by this widget. The widget will be focusable even if a + /// [focusNode] is not supplied. If supplied, the given [focusNode] will be + /// _hosted_ by this widget, but not owned. See [FocusNode] for more + /// information on what being hosted and/or owned implies. + /// + /// Supplying a focus node is sometimes useful if an ancestor to this widget + /// wants to control when this widget has the focus. The owner will be + /// responsible for calling [FocusNode.dispose] on the focus node when it is + /// done with it, but this widget will attach/detach and reparent the node + /// when needed. + /// {@endtemplate} + /// + /// A non-null [focusNode] must be supplied if using the + /// [Focus.withExternalFocusNode] constructor. + final FocusNode? focusNode; + + /// {@template flutter.widgets.Focus.autofocus} + /// True if this widget will be selected as the initial focus when no other + /// node in its scope is currently focused. + /// + /// Ideally, there is only one widget with autofocus set in each [FocusScope]. + /// If there is more than one widget with autofocus set, then the first one + /// added to the tree will get focus. + /// + /// Defaults to false. + /// {@endtemplate} + final bool autofocus; + + /// Handler called when the focus changes. + /// + /// Called with true if this widget's node gains focus, and false if it loses + /// focus. + final ValueChanged<bool>? onFocusChange; + + /// A handler for keys that are pressed when this object or one of its + /// children has focus. + /// + /// Key events are first given to the [FocusNode] that has primary focus, and + /// if its [onKeyEvent] method returns [KeyEventResult.ignored], then they are + /// given to each ancestor node up the focus hierarchy in turn. If an event + /// reaches the root of the hierarchy, it is discarded. + /// + /// This is not the way to get text input in the manner of a text field: it + /// leaves out support for input method editors, and doesn't support soft + /// keyboards in general. For text input, consider [TextField], + /// [EditableText], or [CupertinoTextField] instead, which do support these + /// things. + FocusOnKeyEventCallback? get onKeyEvent => _onKeyEvent ?? focusNode?.onKeyEvent; + final FocusOnKeyEventCallback? _onKeyEvent; + + /// A handler for keys that are pressed when this object or one of its + /// children has focus. + /// + /// This property is deprecated and will be removed. Use [onKeyEvent] instead. + /// + /// Key events are first given to the [FocusNode] that has primary focus, and + /// if its [onKey] method return false, then they are given to each ancestor + /// node up the focus hierarchy in turn. If an event reaches the root of the + /// hierarchy, it is discarded. + /// + /// This is not the way to get text input in the manner of a text field: it + /// leaves out support for input method editors, and doesn't support soft + /// keyboards in general. For text input, consider [TextField], + /// [EditableText], or [CupertinoTextField] instead, which do support these + /// things. + @Deprecated( + 'Use onKeyEvent instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + FocusOnKeyCallback? get onKey => _onKey ?? focusNode?.onKey; + final FocusOnKeyCallback? _onKey; + + /// {@template flutter.widgets.Focus.canRequestFocus} + /// If true, this widget may request the primary focus. + /// + /// Defaults to true. Set to false if you want the [FocusNode] this widget + /// manages to do nothing when [FocusNode.requestFocus] is called on it. Does + /// not affect the children of this node, and [FocusNode.hasFocus] can still + /// return true if this node is the ancestor of the primary focus. + /// + /// This is different than [Focus.skipTraversal] because [Focus.skipTraversal] + /// still allows the widget to be focused, just not traversed to. + /// + /// Setting [FocusNode.canRequestFocus] to false implies that the widget will + /// also be skipped for traversal purposes. + /// + /// See also: + /// + /// * [FocusTraversalGroup], a widget that sets the traversal policy for its + /// descendants. + /// * [FocusTraversalPolicy], a class that can be extended to describe a + /// traversal policy. + /// {@endtemplate} + bool get canRequestFocus => _canRequestFocus ?? focusNode?.canRequestFocus ?? true; + final bool? _canRequestFocus; + + /// Sets the [FocusNode.skipTraversal] flag on the focus node so that it won't + /// be visited by the [FocusTraversalPolicy]. + /// + /// This is sometimes useful if a [Focus] widget should receive key events as + /// part of the focus chain, but shouldn't be accessible via focus traversal. + /// + /// This is different from [FocusNode.canRequestFocus] because it only implies + /// that the widget can't be reached via traversal, not that it can't be + /// focused. It may still be focused explicitly. + bool get skipTraversal => _skipTraversal ?? focusNode?.skipTraversal ?? false; + final bool? _skipTraversal; + + /// {@template flutter.widgets.Focus.descendantsAreFocusable} + /// If false, will make this widget's descendants unfocusable. + /// + /// Defaults to true. Does not affect focusability of this node (just its + /// descendants): for that, use [FocusNode.canRequestFocus]. + /// + /// If any descendants are focused when this is set to false, they will be + /// unfocused. When [descendantsAreFocusable] is set to true again, they will + /// not be refocused, although they will be able to accept focus again. + /// + /// Does not affect the value of [FocusNode.canRequestFocus] on the + /// descendants. + /// + /// If a descendant node loses focus when this value is changed, the focus + /// will move to the scope enclosing this node. + /// + /// See also: + /// + /// * [ExcludeFocus], a widget that uses this property to conditionally + /// exclude focus for a subtree. + /// * [descendantsAreTraversable], which makes this widget's descendants + /// untraversable. + /// * [ExcludeFocusTraversal], a widget that conditionally excludes focus + /// traversal for a subtree. + /// * [FocusTraversalGroup], a widget used to group together and configure the + /// focus traversal policy for a widget subtree that has a + /// `descendantsAreFocusable` parameter to conditionally block focus for a + /// subtree. + /// {@endtemplate} + bool get descendantsAreFocusable => _descendantsAreFocusable ?? focusNode?.descendantsAreFocusable ?? true; + final bool? _descendantsAreFocusable; + + /// {@template flutter.widgets.Focus.descendantsAreTraversable} + /// If false, will make this widget's descendants untraversable. + /// + /// Defaults to true. Does not affect traversability of this node (just its + /// descendants): for that, use [FocusNode.skipTraversal]. + /// + /// Does not affect the value of [FocusNode.skipTraversal] on the + /// descendants. Does not affect focusability of the descendants. + /// + /// See also: + /// + /// * [ExcludeFocusTraversal], a widget that uses this property to + /// conditionally exclude focus traversal for a subtree. + /// * [descendantsAreFocusable], which makes this widget's descendants + /// unfocusable. + /// * [ExcludeFocus], a widget that conditionally excludes focus for a subtree. + /// * [FocusTraversalGroup], a widget used to group together and configure the + /// focus traversal policy for a widget subtree that has a + /// `descendantsAreFocusable` parameter to conditionally block focus for a + /// subtree. + /// {@endtemplate} + bool get descendantsAreTraversable => _descendantsAreTraversable ?? focusNode?.descendantsAreTraversable ?? true; + final bool? _descendantsAreTraversable; + + /// {@template flutter.widgets.Focus.includeSemantics} + /// Include semantics information in this widget. + /// + /// If true, this widget will include a [Semantics] node that indicates the + /// [SemanticsProperties.focusable] and [SemanticsProperties.focused] + /// properties. + /// + /// It is not typical to set this to false, as that can affect the semantics + /// information available to accessibility systems. + /// + /// Defaults to true. + /// {@endtemplate} + final bool includeSemantics; + + /// A debug label for this widget. + /// + /// Not used for anything except to be printed in the diagnostic output from + /// [toString] or [toStringDeep]. + /// + /// To get a string with the entire tree, call [debugDescribeFocusTree]. To + /// print it to the console call [debugDumpFocusTree]. + /// + /// Defaults to null. + String? get debugLabel => _debugLabel ?? focusNode?.debugLabel; + final String? _debugLabel; + + /// Returns the [focusNode] of the [Focus] that most tightly encloses the + /// given [BuildContext]. + /// + /// If no [Focus] node is found before reaching the nearest [FocusScope] + /// widget, or there is no [Focus] widget in the context, then this method + /// will throw an exception. + /// + /// {@macro flutter.widgets.focus_scope.Focus.maybeOf} + /// + /// See also: + /// + /// * [maybeOf], which is similar to this function, but will return null + /// instead of throwing if it doesn't find a [Focus] node. + static FocusNode of(BuildContext context, { bool scopeOk = false, bool createDependency = true }) { + final FocusNode? node = Focus.maybeOf(context, scopeOk: scopeOk, createDependency: createDependency); + assert(() { + if (node == null) { + throw FlutterError( + 'Focus.of() was called with a context that does not contain a Focus widget.\n' + 'No Focus widget ancestor could be found starting from the context that was passed to ' + 'Focus.of(). This can happen because you are using a widget that looks for a Focus ' + 'ancestor, and do not have a Focus widget descendant in the nearest FocusScope.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + assert(() { + if (!scopeOk && node is FocusScopeNode) { + throw FlutterError( + 'Focus.of() was called with a context that does not contain a Focus between the given ' + 'context and the nearest FocusScope widget.\n' + 'No Focus ancestor could be found starting from the context that was passed to ' + 'Focus.of() to the point where it found the nearest FocusScope widget. This can happen ' + 'because you are using a widget that looks for a Focus ancestor, and do not have a ' + 'Focus widget ancestor in the current FocusScope.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return node!; + } + + /// Returns the [focusNode] of the [Focus] that most tightly encloses the + /// given [BuildContext]. + /// + /// If no [Focus] node is found before reaching the nearest [FocusScope] + /// widget, or there is no [Focus] widget in scope, then this method will + /// return null. + /// + /// {@template flutter.widgets.focus_scope.Focus.maybeOf} + /// If `createDependency` is true (which is the default), calling this + /// function creates a dependency that will rebuild the given context when the + /// focus node gains or loses focus. + /// {@endtemplate} + /// + /// See also: + /// + /// * [of], which is similar to this function, but will throw an exception if + /// it doesn't find a [Focus] node, instead of returning null. + static FocusNode? maybeOf(BuildContext context, { bool scopeOk = false, bool createDependency = true }) { + final _FocusInheritedScope? scope; + if (createDependency) { + scope = context.dependOnInheritedWidgetOfExactType<_FocusInheritedScope>(); + } else { + scope = context.getInheritedWidgetOfExactType<_FocusInheritedScope>(); + } + final FocusNode? node = scope?.notifier; + if (node == null) { + return null; + } + if (!scopeOk && node is FocusScopeNode) { + return null; + } + return node; + } + + /// Returns true if the nearest enclosing [Focus] widget's node is focused. + /// + /// A convenience method to allow build methods to write: + /// `Focus.isAt(context)` to get whether or not the nearest [Focus] above them + /// in the widget hierarchy currently has the input focus. + /// + /// Returns false if no [Focus] widget is found before reaching the nearest + /// [FocusScope], or if the root of the focus tree is reached without finding + /// a [Focus] widget. + /// + /// Calling this function creates a dependency that will rebuild the given + /// context when the focus changes. + static bool isAt(BuildContext context) => Focus.maybeOf(context)?.hasFocus ?? false; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('debugLabel', debugLabel, defaultValue: null)); + properties.add(FlagProperty('autofocus', value: autofocus, ifTrue: 'AUTOFOCUS', defaultValue: false)); + properties.add(FlagProperty('canRequestFocus', value: canRequestFocus, ifFalse: 'NOT FOCUSABLE', defaultValue: false)); + properties.add(FlagProperty('descendantsAreFocusable', value: descendantsAreFocusable, ifFalse: 'DESCENDANTS UNFOCUSABLE', defaultValue: true)); + properties.add(FlagProperty('descendantsAreTraversable', value: descendantsAreTraversable, ifFalse: 'DESCENDANTS UNTRAVERSABLE', defaultValue: true)); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null)); + } + + @override + State<Focus> createState() => _FocusState(); +} + +// Implements the behavior differences when the Focus.withExternalFocusNode +// constructor is used. +class _FocusWithExternalFocusNode extends Focus { + const _FocusWithExternalFocusNode({ + super.key, + required super.child, + required FocusNode super.focusNode, + super.parentNode, + super.autofocus, + super.onFocusChange, + super.includeSemantics, + }); + + @override + bool get _usingExternalFocus => true; + @override + FocusOnKeyEventCallback? get onKeyEvent => focusNode!.onKeyEvent; + @override + FocusOnKeyCallback? get onKey => focusNode!.onKey; + @override + bool get canRequestFocus => focusNode!.canRequestFocus; + @override + bool get skipTraversal => focusNode!.skipTraversal; + @override + bool get descendantsAreFocusable => focusNode!.descendantsAreFocusable; + @override + bool? get _descendantsAreTraversable => focusNode!.descendantsAreTraversable; + @override + String? get debugLabel => focusNode!.debugLabel; +} + +class _FocusState extends State<Focus> { + FocusNode? _internalNode; + FocusNode get focusNode => widget.focusNode ?? _internalNode!; + late bool _hadPrimaryFocus; + late bool _couldRequestFocus; + late bool _descendantsWereFocusable; + late bool _descendantsWereTraversable; + bool _didAutofocus = false; + FocusAttachment? _focusAttachment; + + @override + void initState() { + super.initState(); + _initNode(); + } + + void _initNode() { + if (widget.focusNode == null) { + // Only create a new node if the widget doesn't have one. + // This calls a function instead of just allocating in place because + // _createNode is overridden in _FocusScopeState. + _internalNode ??= _createNode(); + } + focusNode.descendantsAreFocusable = widget.descendantsAreFocusable; + focusNode.descendantsAreTraversable = widget.descendantsAreTraversable; + focusNode.skipTraversal = widget.skipTraversal; + if (widget._canRequestFocus != null) { + focusNode.canRequestFocus = widget._canRequestFocus!; + } + _couldRequestFocus = focusNode.canRequestFocus; + _descendantsWereFocusable = focusNode.descendantsAreFocusable; + _descendantsWereTraversable = focusNode.descendantsAreTraversable; + _hadPrimaryFocus = focusNode.hasPrimaryFocus; + _focusAttachment = focusNode.attach(context, onKeyEvent: widget.onKeyEvent, onKey: widget.onKey); + + // Add listener even if the _internalNode existed before, since it should + // not be listening now if we're re-using a previous one because it should + // have already removed its listener. + focusNode.addListener(_handleFocusChanged); + } + + FocusNode _createNode() { + return FocusNode( + debugLabel: widget.debugLabel, + canRequestFocus: widget.canRequestFocus, + descendantsAreFocusable: widget.descendantsAreFocusable, + descendantsAreTraversable: widget.descendantsAreTraversable, + skipTraversal: widget.skipTraversal, + ); + } + + @override + void dispose() { + // Regardless of the node owner, we need to remove it from the tree and stop + // listening to it. + focusNode.removeListener(_handleFocusChanged); + _focusAttachment!.detach(); + + // Don't manage the lifetime of external nodes given to the widget, just the + // internal node. + _internalNode?.dispose(); + super.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _focusAttachment?.reparent(); + _handleAutofocus(); + } + + void _handleAutofocus() { + if (!_didAutofocus && widget.autofocus) { + FocusScope.of(context).autofocus(focusNode); + _didAutofocus = true; + } + } + + @override + void deactivate() { + super.deactivate(); + // The focus node's location in the tree is no longer valid here. But + // we can't unfocus or remove the node from the tree because if the widget + // is moved to a different part of the tree (via global key) it should + // retain its focus state. That's why we temporarily park it on the root + // focus node (via reparent) until it either gets moved to a different part + // of the tree (via didChangeDependencies) or until it is disposed. + _focusAttachment?.reparent(); + _didAutofocus = false; + } + + @override + void didUpdateWidget(Focus oldWidget) { + super.didUpdateWidget(oldWidget); + assert(() { + // Only update the debug label in debug builds. + if (oldWidget.focusNode == widget.focusNode && + !widget._usingExternalFocus && + oldWidget.debugLabel != widget.debugLabel) { + focusNode.debugLabel = widget.debugLabel; + } + return true; + }()); + + if (oldWidget.focusNode == widget.focusNode) { + if (!widget._usingExternalFocus) { + if (widget.onKey != focusNode.onKey) { + focusNode.onKey = widget.onKey; + } + if (widget.onKeyEvent != focusNode.onKeyEvent) { + focusNode.onKeyEvent = widget.onKeyEvent; + } + focusNode.skipTraversal = widget.skipTraversal; + if (widget._canRequestFocus != null) { + focusNode.canRequestFocus = widget._canRequestFocus!; + } + focusNode.descendantsAreFocusable = widget.descendantsAreFocusable; + focusNode.descendantsAreTraversable = widget.descendantsAreTraversable; + } + } else { + _focusAttachment!.detach(); + oldWidget.focusNode?.removeListener(_handleFocusChanged); + _initNode(); + } + + if (oldWidget.autofocus != widget.autofocus) { + _handleAutofocus(); + } + } + + void _handleFocusChanged() { + final bool hasPrimaryFocus = focusNode.hasPrimaryFocus; + final bool canRequestFocus = focusNode.canRequestFocus; + final bool descendantsAreFocusable = focusNode.descendantsAreFocusable; + final bool descendantsAreTraversable = focusNode.descendantsAreTraversable; + widget.onFocusChange?.call(focusNode.hasFocus); + // Check the cached states that matter here, and call setState if they have + // changed. + if (_hadPrimaryFocus != hasPrimaryFocus) { + setState(() { + _hadPrimaryFocus = hasPrimaryFocus; + }); + } + if (_couldRequestFocus != canRequestFocus) { + setState(() { + _couldRequestFocus = canRequestFocus; + }); + } + if (_descendantsWereFocusable != descendantsAreFocusable) { + setState(() { + _descendantsWereFocusable = descendantsAreFocusable; + }); + } + if (_descendantsWereTraversable != descendantsAreTraversable) { + setState(() { + _descendantsWereTraversable = descendantsAreTraversable; + }); + } + } + + @override + Widget build(BuildContext context) { + _focusAttachment!.reparent(parent: widget.parentNode); + Widget child = widget.child; + if (widget.includeSemantics) { + child = Semantics( + focusable: _couldRequestFocus, + focused: _hadPrimaryFocus, + child: widget.child, + ); + } + return _FocusInheritedScope( + node: focusNode, + child: child, + ); + } +} + +/// A [FocusScope] is similar to a [Focus], but also serves as a scope for its +/// descendants, restricting focus traversal to the scoped controls. +/// +/// For example a new [FocusScope] is created automatically when a route is +/// pushed, keeping the focus traversal from moving to a control in a previous +/// route. +/// +/// If you just want to group widgets together in a group so that they are +/// traversed in a particular order, but the focus can still leave the group, +/// use a [FocusTraversalGroup]. +/// +/// Like [Focus], [FocusScope] provides an [onFocusChange] as a way to be +/// notified when the focus is given to or removed from this widget. +/// +/// The [onKey] argument allows specification of a key event handler that is +/// invoked when this node or one of its children has focus. Keys are handed to +/// the primary focused widget first, and then they propagate through the +/// ancestors of that node, stopping if one of them returns +/// [KeyEventResult.handled] from [onKey], indicating that it has handled the +/// event. +/// +/// Managing a [FocusScopeNode] means managing its lifecycle, listening for +/// changes in focus, and re-parenting it when needed to keep the focus +/// hierarchy in sync with the widget hierarchy. This widget does all of those +/// things for you. See [FocusScopeNode] for more information about the details +/// of what node management entails if you are not using a [FocusScope] widget +/// and you need to do it yourself. +/// +/// [FocusScopeNode]s remember the last [FocusNode] that was focused within +/// their descendants, and can move that focus to the next/previous node, or a +/// node in a particular direction when the [FocusNode.nextFocus], +/// [FocusNode.previousFocus], or [FocusNode.focusInDirection] are called on a +/// [FocusNode] or [FocusScopeNode]. +/// +/// To move the focus, use methods on [FocusNode] by getting the [FocusNode] +/// through the [of] method. For instance, to move the focus to the next node in +/// the focus traversal order, call `Focus.of(context).nextFocus()`. To unfocus +/// a widget, call `Focus.of(context).unfocus()`. +/// +/// {@tool dartpad} +/// This example demonstrates using a [FocusScope] to restrict focus to a particular +/// portion of the app. In this case, restricting focus to the visible part of a +/// Stack. +/// +/// ** See code in examples/api/lib/widgets/focus_scope/focus_scope.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [FocusScopeNode], which represents a scope node in the focus hierarchy. +/// * [FocusNode], which represents a node in the focus hierarchy and has an +/// explanation of the focus system. +/// * [Focus], a widget that manages a [FocusNode] and allows easy access to +/// managing focus without having to manage the node. +/// * [FocusManager], a singleton that manages the focus and distributes key +/// events to focused nodes. +/// * [FocusTraversalPolicy], an object used to determine how to move the focus +/// to other nodes. +/// * [FocusTraversalGroup], a widget used to configure the focus traversal +/// policy for a widget subtree. +class FocusScope extends Focus { + /// Creates a widget that manages a [FocusScopeNode]. + const FocusScope({ + super.key, + FocusScopeNode? node, + super.parentNode, + required super.child, + super.autofocus, + super.onFocusChange, + super.canRequestFocus, + super.skipTraversal, + super.onKeyEvent, + super.onKey, + super.debugLabel, + }) : super( + focusNode: node, + ); + + /// Creates a FocusScope widget that uses the given [focusScopeNode] as the + /// source of truth for attributes on the node, rather than the attributes of + /// this widget. + const factory FocusScope.withExternalFocusNode({ + Key? key, + required Widget child, + required FocusScopeNode focusScopeNode, + FocusNode? parentNode, + bool autofocus, + ValueChanged<bool>? onFocusChange, + }) = _FocusScopeWithExternalFocusNode; + + /// Returns the [FocusNode.nearestScope] of the [Focus] or [FocusScope] that + /// most tightly encloses the given [context]. + /// + /// If this node doesn't have a [Focus] or [FocusScope] widget ancestor, then + /// the [FocusManager.rootScope] is returned. + /// + /// {@macro flutter.widgets.focus_scope.Focus.maybeOf} + static FocusScopeNode of(BuildContext context, { bool createDependency = true }) { + return Focus.maybeOf(context, scopeOk: true, createDependency: createDependency)?.nearestScope + ?? context.owner!.focusManager.rootScope; + } + + @override + State<Focus> createState() => _FocusScopeState(); +} + +// Implements the behavior differences when the FocusScope.withExternalFocusNode +// constructor is used. +class _FocusScopeWithExternalFocusNode extends FocusScope { + const _FocusScopeWithExternalFocusNode({ + super.key, + required super.child, + required FocusScopeNode focusScopeNode, + super.parentNode, + super.autofocus, + super.onFocusChange, + }) : super( + node: focusScopeNode, + ); + + @override + bool get _usingExternalFocus => true; + @override + FocusOnKeyEventCallback? get onKeyEvent => focusNode!.onKeyEvent; + @override + FocusOnKeyCallback? get onKey => focusNode!.onKey; + @override + bool get canRequestFocus => focusNode!.canRequestFocus; + @override + bool get skipTraversal => focusNode!.skipTraversal; + @override + bool get descendantsAreFocusable => focusNode!.descendantsAreFocusable; + @override + bool get descendantsAreTraversable => focusNode!.descendantsAreTraversable; + @override + String? get debugLabel => focusNode!.debugLabel; +} + +class _FocusScopeState extends _FocusState { + @override + FocusScopeNode _createNode() { + return FocusScopeNode( + debugLabel: widget.debugLabel, + canRequestFocus: widget.canRequestFocus, + skipTraversal: widget.skipTraversal, + ); + } + + @override + Widget build(BuildContext context) { + _focusAttachment!.reparent(parent: widget.parentNode); + return Semantics( + explicitChildNodes: true, + child: _FocusInheritedScope( + node: focusNode, + child: widget.child, + ), + ); + } +} + +// The InheritedWidget for Focus and FocusScope. +class _FocusInheritedScope extends InheritedNotifier<FocusNode> { + const _FocusInheritedScope({ + required FocusNode node, + required super.child, + }) : super(notifier: node); +} + +/// A widget that controls whether or not the descendants of this widget are +/// focusable. +/// +/// Does not affect the value of [Focus.canRequestFocus] on the descendants. +/// +/// See also: +/// +/// * [Focus], a widget for adding and managing a [FocusNode] in the widget tree. +/// * [FocusTraversalGroup], a widget that groups widgets for focus traversal, +/// and can also be used in the same way as this widget by setting its +/// `descendantsAreFocusable` attribute. +class ExcludeFocus extends StatelessWidget { + /// Const constructor for [ExcludeFocus] widget. + const ExcludeFocus({ + super.key, + this.excluding = true, + required this.child, + }); + + /// If true, will make this widget's descendants unfocusable. + /// + /// Defaults to true. + /// + /// If any descendants are focused when this is set to true, they will be + /// unfocused. When [excluding] is set to false again, they will not be + /// refocused, although they will be able to accept focus again. + /// + /// Does not affect the value of [FocusNode.canRequestFocus] on the + /// descendants. + /// + /// See also: + /// + /// * [Focus.descendantsAreFocusable], the attribute of a [Focus] widget that + /// controls this same property for focus widgets. + /// * [FocusTraversalGroup], a widget used to group together and configure the + /// focus traversal policy for a widget subtree that has a + /// `descendantsAreFocusable` parameter to conditionally block focus for a + /// subtree. + final bool excluding; + + /// The child widget of this [ExcludeFocus]. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + return Focus( + canRequestFocus: false, + skipTraversal: true, + includeSemantics: false, + descendantsAreFocusable: !excluding, + child: child, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/focus_traversal.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/focus_traversal.dart new file mode 100644 index 0000000000000000000000000000000000000000..53455c7397ad7622aaa7b54dd1575e34dc462db1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/focus_traversal.dart @@ -0,0 +1,2158 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'actions.dart'; +import 'basic.dart'; +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; +import 'scroll_position.dart'; +import 'scrollable.dart'; + +// Examples can assume: +// late BuildContext context; +// FocusNode focusNode = FocusNode(); + +// BuildContext/Element doesn't have a parent accessor, but it can be simulated +// with visitAncestorElements. _getAncestor is needed because +// context.getElementForInheritedWidgetOfExactType will return itself if it +// happens to be of the correct type. _getAncestor should be O(count), since we +// always return false at a specific ancestor. By default it returns the parent, +// which is O(1). +BuildContext? _getAncestor(BuildContext context, {int count = 1}) { + BuildContext? target; + context.visitAncestorElements((Element ancestor) { + count--; + if (count == 0) { + target = ancestor; + return false; + } + return true; + }); + return target; +} + +/// Signature for the callback that's called when a traversal policy +/// requests focus. +typedef TraversalRequestFocusCallback = void Function( + FocusNode node, { + ScrollPositionAlignmentPolicy? alignmentPolicy, + double? alignment, + Duration? duration, + Curve? curve, +}); + +// A class to temporarily hold information about FocusTraversalGroups when +// sorting their contents. +class _FocusTraversalGroupInfo { + _FocusTraversalGroupInfo( + _FocusTraversalGroupNode? group, { + FocusTraversalPolicy? defaultPolicy, + List<FocusNode>? members, + }) : groupNode = group, + policy = group?.policy ?? defaultPolicy ?? ReadingOrderTraversalPolicy(), + members = members ?? <FocusNode>[]; + + final FocusNode? groupNode; + final FocusTraversalPolicy policy; + final List<FocusNode> members; +} + +/// A direction along either the horizontal or vertical axes. +/// +/// This is used by the [DirectionalFocusTraversalPolicyMixin], and +/// [FocusNode.focusInDirection] to indicate which direction to look in for the +/// next focus. +enum TraversalDirection { + /// Indicates a direction above the currently focused widget. + up, + + /// Indicates a direction to the right of the currently focused widget. + /// + /// This direction is unaffected by the [Directionality] of the current + /// context. + right, + + /// Indicates a direction below the currently focused widget. + down, + + /// Indicates a direction to the left of the currently focused widget. + /// + /// This direction is unaffected by the [Directionality] of the current + /// context. + left, +} + +/// Controls the transfer of focus beyond the first and the last items of a +/// [FocusScopeNode]. +/// +/// This enumeration only controls the traversal behavior performed by +/// [FocusTraversalPolicy]. Other methods of focus transfer, such as direct +/// calls to [FocusNode.requestFocus] and [FocusNode.unfocus], are not affected +/// by this enumeration. +/// +/// See also: +/// +/// * [FocusTraversalPolicy], which implements the logic behind this enum. +/// * [FocusScopeNode], which is configured by this enum. +enum TraversalEdgeBehavior { + /// Keeps the focus among the items of the focus scope. + /// + /// Requesting the next focus after the last focusable item will transfer the + /// focus to the first item, and requesting focus previous to the first item + /// will transfer the focus to the last item, thus forming a closed loop of + /// focusable items. + closedLoop, + + /// Allows the focus to leave the [FlutterView]. + /// + /// Requesting next focus after the last focusable item or previous to the + /// first item will unfocus any focused nodes. If the focus traversal action + /// was initiated by the embedder (e.g. the Flutter Engine) the embedder + /// receives a result indicating that the focus is no longer within the + /// current [FlutterView]. For example, [NextFocusAction] invoked via keyboard + /// (typically the TAB key) would receive [KeyEventResult.skipRemainingHandlers] + /// allowing the embedder handle the shortcut. On the web, typically the + /// control is transferred to the browser, allowing the user to reach the + /// address bar, escape an `iframe`, or focus on HTML elements other than + /// those managed by Flutter. + leaveFlutterView, + + /// Allows focus to traverse up to parent scope. + /// + /// When reaching the edge of the current scope, requesting the next focus + /// will look up to the parent scope of the current scope and focus the focus + /// node next to the current scope. + /// + /// If there is no parent scope above the current scope, fallback to + /// [closedLoop] behavior. + parentScope, +} + +/// Determines how focusable widgets are traversed within a [FocusTraversalGroup]. +/// +/// The focus traversal policy is what determines which widget is "next", +/// "previous", or in a direction from the widget associated with the currently +/// focused [FocusNode] (usually a [Focus] widget). +/// +/// One of the pre-defined subclasses may be used, or define a custom policy to +/// create a unique focus order. +/// +/// When defining your own, your subclass should implement [sortDescendants] to +/// provide the order in which you would like the descendants to be traversed. +/// +/// See also: +/// +/// * [FocusNode], for a description of the focus system. +/// * [FocusTraversalGroup], a widget that groups together and imposes a +/// traversal policy on the [Focus] nodes below it in the widget hierarchy. +/// * [FocusNode], which is affected by the traversal policy. +/// * [WidgetOrderTraversalPolicy], a policy that relies on the widget +/// creation order to describe the order of traversal. +/// * [ReadingOrderTraversalPolicy], a policy that describes the order as the +/// natural "reading order" for the current [Directionality]. +/// * [OrderedTraversalPolicy], a policy that describes the order +/// explicitly using [FocusTraversalOrder] widgets. +/// * [DirectionalFocusTraversalPolicyMixin] a mixin class that implements +/// focus traversal in a direction. +@immutable +abstract class FocusTraversalPolicy with Diagnosticable { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + /// + /// {@template flutter.widgets.FocusTraversalPolicy.requestFocusCallback} + /// The `requestFocusCallback` can be used to override the default behavior + /// of the focus requests. If `requestFocusCallback` + /// is null, it defaults to [FocusTraversalPolicy.defaultTraversalRequestFocusCallback]. + /// {@endtemplate} + const FocusTraversalPolicy({ + TraversalRequestFocusCallback? requestFocusCallback + }) : requestFocusCallback = requestFocusCallback ?? defaultTraversalRequestFocusCallback; + + /// The callback used to move the focus from one focus node to another when + /// traversing them using a keyboard. By default it requests focus on the next + /// node and ensures the node is visible if it's in a scrollable. + final TraversalRequestFocusCallback requestFocusCallback; + + /// The default value for [requestFocusCallback]. + /// Requests focus from `node` and ensures the node is visible + /// by calling [Scrollable.ensureVisible]. + static void defaultTraversalRequestFocusCallback( + FocusNode node, { + ScrollPositionAlignmentPolicy? alignmentPolicy, + double? alignment, + Duration? duration, + Curve? curve, + }) { + node.requestFocus(); + Scrollable.ensureVisible( + node.context!, + alignment: alignment ?? 1, + alignmentPolicy: alignmentPolicy ?? ScrollPositionAlignmentPolicy.explicit, + duration: duration ?? Duration.zero, + curve: curve ?? Curves.ease, + ); + } + + /// Request focus on a focus node as a result of a tab traversal. + /// + /// If the `node` is a [FocusScopeNode], this method will recursively find + /// the next focus from its descendants until it find a regular [FocusNode]. + /// + /// Returns true if this method focused a new focus node. + bool _requestTabTraversalFocus( + FocusNode node, { + ScrollPositionAlignmentPolicy? alignmentPolicy, + double? alignment, + Duration? duration, + Curve? curve, + required bool forward, + }) { + if (node is FocusScopeNode) { + if (node.focusedChild != null) { + // Can't stop here as the `focusedChild` may be a focus scope node + // without a first focus. The first focus will be picked in the + // next iteration. + return _requestTabTraversalFocus( + node.focusedChild!, + alignmentPolicy: alignmentPolicy, + alignment: alignment, + duration: duration, + curve: curve, + forward: forward, + ); + } + final List<FocusNode> sortedChildren = _sortAllDescendants(node, node); + if (sortedChildren.isNotEmpty) { + _requestTabTraversalFocus( + forward ? sortedChildren.first : sortedChildren.last, + alignmentPolicy: alignmentPolicy, + alignment: alignment, + duration: duration, + curve: curve, + forward: forward, + ); + // Regardless if _requestTabTraversalFocus return true or false, a first + // focus has been picked. + return true; + } + } + final bool nodeHadPrimaryFocus = node.hasPrimaryFocus; + requestFocusCallback( + node, + alignmentPolicy: alignmentPolicy, + alignment: alignment, + duration: duration, + curve: curve, + ); + return !nodeHadPrimaryFocus; + } + + /// Returns the node that should receive focus if focus is traversing + /// forwards, and there is no current focus. + /// + /// The node returned is the node that should receive focus if focus is + /// traversing forwards (i.e. with [next]), and there is no current focus in + /// the nearest [FocusScopeNode] that `currentNode` belongs to. + /// + /// If `ignoreCurrentFocus` is false or not given, this function returns the + /// [FocusScopeNode.focusedChild], if set, on the nearest scope of the + /// `currentNode`, otherwise, returns the first node from [sortDescendants], + /// or the given `currentNode` if there are no descendants. + /// + /// If `ignoreCurrentFocus` is true, then the algorithm returns the first node + /// from [sortDescendants], or the given `currentNode` if there are no + /// descendants. + /// + /// See also: + /// + /// * [next], the function that is called to move the focus to the next node. + /// * [DirectionalFocusTraversalPolicyMixin.findFirstFocusInDirection], a + /// function that finds the first focusable widget in a particular + /// direction. + FocusNode? findFirstFocus(FocusNode currentNode, {bool ignoreCurrentFocus = false}) { + return _findInitialFocus(currentNode, ignoreCurrentFocus: ignoreCurrentFocus); + } + + /// Returns the node that should receive focus if focus is traversing + /// backwards, and there is no current focus. + /// + /// The node returned is the one that should receive focus if focus is + /// traversing backwards (i.e. with [previous]), and there is no current focus + /// in the nearest [FocusScopeNode] that `currentNode` belongs to. + /// + /// If `ignoreCurrentFocus` is false or not given, this function returns the + /// [FocusScopeNode.focusedChild], if set, on the nearest scope of the + /// `currentNode`, otherwise, returns the last node from [sortDescendants], + /// or the given `currentNode` if there are no descendants. + /// + /// If `ignoreCurrentFocus` is true, then the algorithm returns the last node + /// from [sortDescendants], or the given `currentNode` if there are no + /// descendants. + /// + /// See also: + /// + /// * [previous], the function that is called to move the focus to the previous node. + /// * [DirectionalFocusTraversalPolicyMixin.findFirstFocusInDirection], a + /// function that finds the first focusable widget in a particular direction. + FocusNode findLastFocus(FocusNode currentNode, {bool ignoreCurrentFocus = false}) { + return _findInitialFocus(currentNode, fromEnd: true, ignoreCurrentFocus: ignoreCurrentFocus); + } + + FocusNode _findInitialFocus(FocusNode currentNode, {bool fromEnd = false, bool ignoreCurrentFocus = false}) { + final FocusScopeNode scope = currentNode.nearestScope!; + FocusNode? candidate = scope.focusedChild; + if (ignoreCurrentFocus || candidate == null && scope.descendants.isNotEmpty) { + final Iterable<FocusNode> sorted = _sortAllDescendants(scope, currentNode).where((FocusNode node) => _canRequestTraversalFocus(node)); + if (sorted.isEmpty) { + candidate = null; + } else { + candidate = fromEnd ? sorted.last : sorted.first; + } + } + + // If we still didn't find any candidate, use the current node as a + // fallback. + candidate ??= currentNode; + return candidate; + } + + /// Returns the first node in the given `direction` that should receive focus + /// if there is no current focus in the scope to which the `currentNode` + /// belongs. + /// + /// This is typically used by [inDirection] to determine which node to focus + /// if it is called when no node is currently focused. + FocusNode? findFirstFocusInDirection(FocusNode currentNode, TraversalDirection direction); + + /// Clears the data associated with the given [FocusScopeNode] for this object. + /// + /// This is used to indicate that the focus policy has changed its mode, and + /// so any cached policy data should be invalidated. For example, changing the + /// direction in which focus is moving, or changing from directional to + /// next/previous navigation modes. + /// + /// The default implementation does nothing. + @mustCallSuper + void invalidateScopeData(FocusScopeNode node) {} + + /// This is called whenever the given [node] is re-parented into a new scope, + /// so that the policy has a chance to update or invalidate any cached data + /// that it maintains per scope about the node. + /// + /// The [oldScope] is the previous scope that this node belonged to, if any. + /// + /// The default implementation does nothing. + @mustCallSuper + void changedScope({FocusNode? node, FocusScopeNode? oldScope}) {} + + /// Focuses the next widget in the focus scope that contains the given + /// [currentNode]. + /// + /// This should determine what the next node to receive focus should be by + /// inspecting the node tree, and then calling [FocusNode.requestFocus] on + /// the node that has been selected. + /// + /// Returns true if it successfully found a node and requested focus. + bool next(FocusNode currentNode) => _moveFocus(currentNode, forward: true); + + /// Focuses the previous widget in the focus scope that contains the given + /// [currentNode]. + /// + /// This should determine what the previous node to receive focus should be by + /// inspecting the node tree, and then calling [FocusNode.requestFocus] on + /// the node that has been selected. + /// + /// Returns true if it successfully found a node and requested focus. + bool previous(FocusNode currentNode) => _moveFocus(currentNode, forward: false); + + /// Focuses the next widget in the given [direction] in the focus scope that + /// contains the given [currentNode]. + /// + /// This should determine what the next node to receive focus in the given + /// [direction] should be by inspecting the node tree, and then calling + /// [FocusNode.requestFocus] on the node that has been selected. + /// + /// Returns true if it successfully found a node and requested focus. + bool inDirection(FocusNode currentNode, TraversalDirection direction); + + /// Sorts the given `descendants` into focus order. + /// + /// Subclasses should override this to implement a different sort for [next] + /// and [previous] to use in their ordering. If the returned iterable omits a + /// node that is a descendant of the given scope, then the user will be unable + /// to use next/previous keyboard traversal to reach that node. + /// + /// The node used to initiate the traversal (the one passed to [next] or + /// [previous]) is passed as `currentNode`. + /// + /// Having the current node in the list is what allows the algorithm to + /// determine which nodes are adjacent to the current node. If the + /// `currentNode` is removed from the list, then the focus will be unchanged + /// when [next] or [previous] are called, and they will return false. + /// + /// This is not used for directional focus ([inDirection]), only for + /// determining the focus order for [next] and [previous]. + /// + /// When implementing an override for this function, be sure to use + /// [mergeSort] instead of Dart's default list sorting algorithm when sorting + /// items, since the default algorithm is not stable (items deemed to be equal + /// can appear in arbitrary order, and change positions between sorts), whereas + /// [mergeSort] is stable. + @protected + Iterable<FocusNode> sortDescendants(Iterable<FocusNode> descendants, FocusNode currentNode); + + static bool _canRequestTraversalFocus(FocusNode node) { + return node.canRequestFocus && !node.skipTraversal; + } + + static Iterable<FocusNode> _getDescendantsWithoutExpandingScope(FocusNode node) { + final List<FocusNode> result = <FocusNode>[]; + for (final FocusNode child in node.children) { + result.add(child); + if (child is! FocusScopeNode) { + result.addAll(_getDescendantsWithoutExpandingScope(child)); + } + } + return result; + } + + static Map<FocusNode?, _FocusTraversalGroupInfo> _findGroups(FocusScopeNode scope, _FocusTraversalGroupNode? scopeGroupNode, FocusNode currentNode) { + final FocusTraversalPolicy defaultPolicy = scopeGroupNode?.policy ?? ReadingOrderTraversalPolicy(); + final Map<FocusNode?, _FocusTraversalGroupInfo> groups = <FocusNode?, _FocusTraversalGroupInfo>{}; + for (final FocusNode node in _getDescendantsWithoutExpandingScope(scope)) { + final _FocusTraversalGroupNode? groupNode = FocusTraversalGroup._getGroupNode(node); + // Group nodes need to be added to their parent's node, or to the "null" + // node if no parent is found. This creates the hierarchy of group nodes + // and makes it so the entire group is sorted along with the other members + // of the parent group. + if (node == groupNode) { + // To find the parent of the group node, we need to skip over the parent + // of the Focus node added in _FocusTraversalGroupState.build, and start + // looking with that node's parent, since _getGroupNode will return the + // node it was called on if it matches the type. + final _FocusTraversalGroupNode? parentGroup = FocusTraversalGroup._getGroupNode(groupNode!.parent!); + groups[parentGroup] ??= _FocusTraversalGroupInfo(parentGroup, members: <FocusNode>[], defaultPolicy: defaultPolicy); + assert(!groups[parentGroup]!.members.contains(node)); + groups[parentGroup]!.members.add(groupNode); + continue; + } + // Skip non-focusable and non-traversable nodes in the same way that + // FocusScopeNode.traversalDescendants would. + // + // Current focused node needs to be in the group so that the caller can + // find the next traversable node from the current focused node. + if (node == currentNode || (node.canRequestFocus && !node.skipTraversal)) { + groups[groupNode] ??= _FocusTraversalGroupInfo(groupNode, members: <FocusNode>[], defaultPolicy: defaultPolicy); + assert(!groups[groupNode]!.members.contains(node)); + groups[groupNode]!.members.add(node); + } + } + return groups; + } + + // Sort all descendants, taking into account the FocusTraversalGroup + // that they are each in, and filtering out non-traversable/focusable nodes. + static List<FocusNode> _sortAllDescendants(FocusScopeNode scope, FocusNode currentNode) { + final _FocusTraversalGroupNode? scopeGroupNode = FocusTraversalGroup._getGroupNode(scope); + // Build the sorting data structure, separating descendants into groups. + final Map<FocusNode?, _FocusTraversalGroupInfo> groups = _findGroups(scope, scopeGroupNode, currentNode); + + // Sort the member lists using the individual policy sorts. + for (final FocusNode? key in groups.keys) { + final List<FocusNode> sortedMembers = groups[key]!.policy.sortDescendants(groups[key]!.members, currentNode).toList(); + groups[key]!.members.clear(); + groups[key]!.members.addAll(sortedMembers); + } + + // Traverse the group tree, adding the children of members in the order they + // appear in the member lists. + final List<FocusNode> sortedDescendants = <FocusNode>[]; + void visitGroups(_FocusTraversalGroupInfo info) { + for (final FocusNode node in info.members) { + if (groups.containsKey(node)) { + // This is a policy group focus node. Replace it with the members of + // the corresponding policy group. + visitGroups(groups[node]!); + } else { + sortedDescendants.add(node); + } + } + } + + // Visit the children of the scope, if any. + if (groups.isNotEmpty && groups.containsKey(scopeGroupNode)) { + visitGroups(groups[scopeGroupNode]!); + } + + // Remove the FocusTraversalGroup nodes themselves, which aren't focusable. + // They were left in above because they were needed to find their members + // during sorting. + sortedDescendants.removeWhere((FocusNode node) { + return node != currentNode && !_canRequestTraversalFocus(node); + }); + + // Sanity check to make sure that the algorithm above doesn't diverge from + // the one in FocusScopeNode.traversalDescendants in terms of which nodes it + // finds. + assert((){ + final Set<FocusNode> difference = sortedDescendants.toSet().difference(scope.traversalDescendants.toSet()); + if (!_canRequestTraversalFocus(currentNode)) { + // The scope.traversalDescendants will not contain currentNode if it + // skips traversal or not focusable. + assert( + difference.isEmpty || (difference.length == 1 && difference.contains(currentNode)), + 'Difference between sorted descendants and FocusScopeNode.traversalDescendants contains ' + 'something other than the current skipped node. This is the difference: $difference', + ); + return true; + } + assert( + difference.isEmpty, + 'Sorted descendants contains different nodes than FocusScopeNode.traversalDescendants would. ' + 'These are the different nodes: $difference', + ); + return true; + }()); + return sortedDescendants; + } + + /// Moves the focus to the next node in the FocusScopeNode nearest to the + /// currentNode argument, either in a forward or reverse direction, depending + /// on the value of the forward argument. + /// + /// This function is called by the next and previous members to move to the + /// next or previous node, respectively. + /// + /// Uses [findFirstFocus]/[findLastFocus] to find the first/last node if there is + /// no [FocusScopeNode.focusedChild] set. If there is a focused child for the + /// scope, then it calls sortDescendants to get a sorted list of descendants, + /// and then finds the node after the current first focus of the scope if + /// forward is true, and the node before it if forward is false. + /// + /// Returns true if a node requested focus. + @protected + bool _moveFocus(FocusNode currentNode, {required bool forward}) { + final FocusScopeNode nearestScope = currentNode.nearestScope!; + invalidateScopeData(nearestScope); + FocusNode? focusedChild = nearestScope.focusedChild; + if (focusedChild == null) { + final FocusNode? firstFocus = forward ? findFirstFocus(currentNode) : findLastFocus(currentNode); + if (firstFocus != null) { + return _requestTabTraversalFocus( + firstFocus, + alignmentPolicy: forward ? ScrollPositionAlignmentPolicy.keepVisibleAtEnd : ScrollPositionAlignmentPolicy.keepVisibleAtStart, + forward: forward, + ); + } + } + focusedChild ??= nearestScope; + final List<FocusNode> sortedNodes = _sortAllDescendants(nearestScope, focusedChild); + assert(sortedNodes.contains(focusedChild)); + + if (forward && focusedChild == sortedNodes.last) { + switch (nearestScope.traversalEdgeBehavior) { + case TraversalEdgeBehavior.leaveFlutterView: + focusedChild.unfocus(); + return false; + case TraversalEdgeBehavior.parentScope: + final FocusScopeNode? parentScope = nearestScope.enclosingScope; + if (parentScope != null && parentScope != FocusManager.instance.rootScope) { + focusedChild.unfocus(); + parentScope.nextFocus(); + // Verify the focus really has changed. + return focusedChild.enclosingScope?.focusedChild != focusedChild; + } + // No valid parent scope. Fallback to closed loop behavior. + return _requestTabTraversalFocus( + sortedNodes.first, + alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd, + forward: forward, + ); + case TraversalEdgeBehavior.closedLoop: + return _requestTabTraversalFocus( + sortedNodes.first, + alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd, + forward: forward, + ); + } + } + if (!forward && focusedChild == sortedNodes.first) { + switch (nearestScope.traversalEdgeBehavior) { + case TraversalEdgeBehavior.leaveFlutterView: + focusedChild.unfocus(); + return false; + case TraversalEdgeBehavior.parentScope: + final FocusScopeNode? parentScope = nearestScope.enclosingScope; + if (parentScope != null && parentScope != FocusManager.instance.rootScope) { + focusedChild.unfocus(); + parentScope.previousFocus(); + // Verify the focus really has changed. + return focusedChild.enclosingScope?.focusedChild != focusedChild; + } + // No valid parent scope. Fallback to closed loop behavior. + return _requestTabTraversalFocus( + sortedNodes.last, + alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtStart, + forward: forward, + ); + case TraversalEdgeBehavior.closedLoop: + return _requestTabTraversalFocus( + sortedNodes.last, + alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtStart, + forward: forward, + ); + } + } + + final Iterable<FocusNode> maybeFlipped = forward ? sortedNodes : sortedNodes.reversed; + FocusNode? previousNode; + for (final FocusNode node in maybeFlipped) { + if (previousNode == focusedChild) { + return _requestTabTraversalFocus( + node, + alignmentPolicy: forward ? ScrollPositionAlignmentPolicy.keepVisibleAtEnd : ScrollPositionAlignmentPolicy.keepVisibleAtStart, + forward: forward, + ); + } + previousNode = node; + } + return false; + } +} + +// A policy data object for use by the DirectionalFocusTraversalPolicyMixin so +// it can keep track of the traversal history. +class _DirectionalPolicyDataEntry { + const _DirectionalPolicyDataEntry({required this.direction, required this.node}); + + final TraversalDirection direction; + final FocusNode node; +} + +class _DirectionalPolicyData { + const _DirectionalPolicyData({required this.history}); + + /// A queue of entries that describe the path taken to the current node. + final List<_DirectionalPolicyDataEntry> history; +} + +/// A mixin class that provides an implementation for finding a node in a +/// particular direction. +/// +/// This can be mixed in to other [FocusTraversalPolicy] implementations that +/// only want to implement new next/previous policies. +/// +/// Since hysteresis in the navigation order is undesirable, this implementation +/// maintains a stack of previous locations that have been visited on the policy +/// data for the affected [FocusScopeNode]. If the previous direction was the +/// opposite of the current direction, then the this policy will request focus +/// on the previously focused node. Change to another direction other than the +/// current one or its opposite will clear the stack. +/// +/// For instance, if the focus moves down, down, down, and then up, up, up, it +/// will follow the same path through the widgets in both directions. However, +/// if it moves down, down, down, left, right, and then up, up, up, it may not +/// follow the same path on the way up as it did on the way down, since changing +/// the axis of motion resets the history. +/// +/// This class implements an algorithm that considers an infinite band extending +/// along the direction of movement, the width or height (depending on +/// direction) of the currently focused widget, and finds the closest widget in +/// that band along the direction of movement. If nothing is found in that band, +/// then it picks the widget with an edge closest to the band in the +/// perpendicular direction. If two out-of-band widgets are the same distance +/// from the band, then it picks the one closest along the direction of +/// movement. +/// +/// The goal of this algorithm is to pick a widget that (to the user) doesn't +/// appear to traverse along the wrong axis, as it might if it only sorted +/// widgets by distance along one axis, but also jumps to the next logical +/// widget in a direction without skipping over widgets. +/// +/// See also: +/// +/// * [FocusNode], for a description of the focus system. +/// * [FocusTraversalGroup], a widget that groups together and imposes a +/// traversal policy on the [Focus] nodes below it in the widget hierarchy. +/// * [WidgetOrderTraversalPolicy], a policy that relies on the widget creation +/// order to describe the order of traversal. +/// * [ReadingOrderTraversalPolicy], a policy that describes the order as the +/// natural "reading order" for the current [Directionality]. +/// * [OrderedTraversalPolicy], a policy that describes the order explicitly +/// using [FocusTraversalOrder] widgets. +mixin DirectionalFocusTraversalPolicyMixin on FocusTraversalPolicy { + final Map<FocusScopeNode, _DirectionalPolicyData> _policyData = <FocusScopeNode, _DirectionalPolicyData>{}; + + @override + void invalidateScopeData(FocusScopeNode node) { + super.invalidateScopeData(node); + _policyData.remove(node); + } + + @override + void changedScope({FocusNode? node, FocusScopeNode? oldScope}) { + super.changedScope(node: node, oldScope: oldScope); + if (oldScope != null) { + _policyData[oldScope]?.history.removeWhere((_DirectionalPolicyDataEntry entry) { + return entry.node == node; + }); + } + } + + @override + FocusNode? findFirstFocusInDirection(FocusNode currentNode, TraversalDirection direction) { + switch (direction) { + case TraversalDirection.up: + // Find the bottom-most node so we can go up from there. + return _sortAndFindInitial(currentNode, vertical: true, first: false); + case TraversalDirection.down: + // Find the top-most node so we can go down from there. + return _sortAndFindInitial(currentNode, vertical: true, first: true); + case TraversalDirection.left: + // Find the right-most node so we can go left from there. + return _sortAndFindInitial(currentNode, vertical: false, first: false); + case TraversalDirection.right: + // Find the left-most node so we can go right from there. + return _sortAndFindInitial(currentNode, vertical: false, first: true); + } + } + + FocusNode? _sortAndFindInitial(FocusNode currentNode, {required bool vertical, required bool first}) { + final Iterable<FocusNode> nodes = currentNode.nearestScope!.traversalDescendants; + final List<FocusNode> sorted = nodes.toList(); + mergeSort<FocusNode>(sorted, compare: (FocusNode a, FocusNode b) { + if (vertical) { + if (first) { + return a.rect.top.compareTo(b.rect.top); + } else { + return b.rect.bottom.compareTo(a.rect.bottom); + } + } else { + if (first) { + return a.rect.left.compareTo(b.rect.left); + } else { + return b.rect.right.compareTo(a.rect.right); + } + } + }); + + if (sorted.isNotEmpty) { + return sorted.first; + } + + return null; + } + + static int _verticalCompare(Offset target, Offset a, Offset b) { + return (a.dy - target.dy).abs().compareTo((b.dy - target.dy).abs()); + } + + static int _horizontalCompare(Offset target, Offset a, Offset b) { + return (a.dx - target.dx).abs().compareTo((b.dx - target.dx).abs()); + } + + // Sort the ones that are closest to target vertically first, and if two are + // the same vertical distance, pick the one that is closest horizontally. + static Iterable<FocusNode> _sortByDistancePreferVertical(Offset target, Iterable<FocusNode> nodes) { + final List<FocusNode> sorted = nodes.toList(); + mergeSort<FocusNode>(sorted, compare: (FocusNode nodeA, FocusNode nodeB) { + final Offset a = nodeA.rect.center; + final Offset b = nodeB.rect.center; + final int vertical = _verticalCompare(target, a, b); + if (vertical == 0) { + return _horizontalCompare(target, a, b); + } + return vertical; + }); + return sorted; + } + + // Sort the ones that are closest horizontally first, and if two are the same + // horizontal distance, pick the one that is closest vertically. + static Iterable<FocusNode> _sortByDistancePreferHorizontal(Offset target, Iterable<FocusNode> nodes) { + final List<FocusNode> sorted = nodes.toList(); + mergeSort<FocusNode>(sorted, compare: (FocusNode nodeA, FocusNode nodeB) { + final Offset a = nodeA.rect.center; + final Offset b = nodeB.rect.center; + final int horizontal = _horizontalCompare(target, a, b); + if (horizontal == 0) { + return _verticalCompare(target, a, b); + } + return horizontal; + }); + return sorted; + } + + static int _verticalCompareClosestEdge(Offset target, Rect a, Rect b) { + // Find which edge is closest to the target for each. + final double aCoord = (a.top - target.dy).abs() < (a.bottom - target.dy).abs() ? a.top : a.bottom; + final double bCoord = (b.top - target.dy).abs() < (b.bottom - target.dy).abs() ? b.top : b.bottom; + return (aCoord - target.dy).abs().compareTo((bCoord - target.dy).abs()); + } + + static int _horizontalCompareClosestEdge(Offset target, Rect a, Rect b) { + // Find which edge is closest to the target for each. + final double aCoord = (a.left - target.dx).abs() < (a.right - target.dx).abs() ? a.left : a.right; + final double bCoord = (b.left - target.dx).abs() < (b.right - target.dx).abs() ? b.left : b.right; + return (aCoord - target.dx).abs().compareTo((bCoord - target.dx).abs()); + } + + // Sort the ones that have edges that are closest horizontally first, and if + // two are the same horizontal distance, pick the one that is closest + // vertically. + static Iterable<FocusNode> _sortClosestEdgesByDistancePreferHorizontal(Offset target, Iterable<FocusNode> nodes) { + final List<FocusNode> sorted = nodes.toList(); + mergeSort<FocusNode>(sorted, compare: (FocusNode nodeA, FocusNode nodeB) { + final int horizontal = _horizontalCompareClosestEdge(target, nodeA.rect, nodeB.rect); + if (horizontal == 0) { + // If they're the same distance horizontally, pick the closest one + // vertically. + return _verticalCompare(target, nodeA.rect.center, nodeB.rect.center); + } + return horizontal; + }); + return sorted; + } + + // Sort the ones that have edges that are closest vertically first, and if + // two are the same vertical distance, pick the one that is closest + // horizontally. + static Iterable<FocusNode> _sortClosestEdgesByDistancePreferVertical(Offset target, Iterable<FocusNode> nodes) { + final List<FocusNode> sorted = nodes.toList(); + mergeSort<FocusNode>(sorted, compare: (FocusNode nodeA, FocusNode nodeB) { + final int vertical = _verticalCompareClosestEdge(target, nodeA.rect, nodeB.rect); + if (vertical == 0) { + // If they're the same distance vertically, pick the closest one + // horizontally. + return _horizontalCompare(target, nodeA.rect.center, nodeB.rect.center); + } + return vertical; + }); + return sorted; + } + + // Sorts nodes from left to right horizontally, and removes nodes that are + // either to the right of the left side of the target node if we're going + // left, or to the left of the right side of the target node if we're going + // right. + // + // This doesn't need to take into account directionality because it is + // typically intending to actually go left or right, not in a reading + // direction. + Iterable<FocusNode> _sortAndFilterHorizontally( + TraversalDirection direction, + Rect target, + Iterable<FocusNode> nodes, + ) { + assert(direction == TraversalDirection.left || direction == TraversalDirection.right); + final Iterable<FocusNode> filtered; + switch (direction) { + case TraversalDirection.left: + filtered = nodes.where((FocusNode node) => node.rect != target && node.rect.center.dx <= target.left); + case TraversalDirection.right: + filtered = nodes.where((FocusNode node) => node.rect != target && node.rect.center.dx >= target.right); + case TraversalDirection.up: + case TraversalDirection.down: + throw ArgumentError('Invalid direction $direction'); + } + final List<FocusNode> sorted = filtered.toList(); + // Sort all nodes from left to right. + mergeSort<FocusNode>(sorted, compare: (FocusNode a, FocusNode b) => a.rect.center.dx.compareTo(b.rect.center.dx)); + return sorted; + } + + // Sorts nodes from top to bottom vertically, and removes nodes that are + // either below the top of the target node if we're going up, or above the + // bottom of the target node if we're going down. + Iterable<FocusNode> _sortAndFilterVertically( + TraversalDirection direction, + Rect target, + Iterable<FocusNode> nodes, + ) { + assert(direction == TraversalDirection.up || direction == TraversalDirection.down); + final Iterable<FocusNode> filtered; + switch (direction) { + case TraversalDirection.up: + filtered = nodes.where((FocusNode node) => node.rect != target && node.rect.center.dy <= target.top); + case TraversalDirection.down: + filtered = nodes.where((FocusNode node) => node.rect != target && node.rect.center.dy >= target.bottom); + case TraversalDirection.left: + case TraversalDirection.right: + throw ArgumentError('Invalid direction $direction'); + } + final List<FocusNode> sorted = filtered.toList(); + mergeSort<FocusNode>(sorted, compare: (FocusNode a, FocusNode b) => a.rect.center.dy.compareTo(b.rect.center.dy)); + return sorted; + } + + // Updates the policy data to keep the previously visited node so that we can + // avoid hysteresis when we change directions in navigation. + // + // Returns true if focus was requested on a previous node. + bool _popPolicyDataIfNeeded(TraversalDirection direction, FocusScopeNode nearestScope, FocusNode focusedChild) { + final _DirectionalPolicyData? policyData = _policyData[nearestScope]; + if (policyData != null && policyData.history.isNotEmpty && policyData.history.first.direction != direction) { + if (policyData.history.last.node.parent == null) { + // If a node has been removed from the tree, then we should stop + // referencing it and reset the scope data so that we don't try and + // request focus on it. This can happen in slivers where the rendered + // node has been unmounted. This has the side effect that hysteresis + // might not be avoided when items that go off screen get unmounted. + invalidateScopeData(nearestScope); + return false; + } + + // Returns true if successfully popped the history. + bool popOrInvalidate(TraversalDirection direction) { + final FocusNode lastNode = policyData.history.removeLast().node; + if (Scrollable.maybeOf(lastNode.context!) != Scrollable.maybeOf(primaryFocus!.context!)) { + invalidateScopeData(nearestScope); + return false; + } + final ScrollPositionAlignmentPolicy alignmentPolicy; + switch (direction) { + case TraversalDirection.up: + case TraversalDirection.left: + alignmentPolicy = ScrollPositionAlignmentPolicy.keepVisibleAtStart; + case TraversalDirection.right: + case TraversalDirection.down: + alignmentPolicy = ScrollPositionAlignmentPolicy.keepVisibleAtEnd; + } + requestFocusCallback( + lastNode, + alignmentPolicy: alignmentPolicy, + ); + return true; + } + + switch (direction) { + case TraversalDirection.down: + case TraversalDirection.up: + switch (policyData.history.first.direction) { + case TraversalDirection.left: + case TraversalDirection.right: + // Reset the policy data if we change directions. + invalidateScopeData(nearestScope); + case TraversalDirection.up: + case TraversalDirection.down: + if (popOrInvalidate(direction)) { + return true; + } + } + case TraversalDirection.left: + case TraversalDirection.right: + switch (policyData.history.first.direction) { + case TraversalDirection.left: + case TraversalDirection.right: + if (popOrInvalidate(direction)) { + return true; + } + case TraversalDirection.up: + case TraversalDirection.down: + // Reset the policy data if we change directions. + invalidateScopeData(nearestScope); + } + } + } + if (policyData != null && policyData.history.isEmpty) { + invalidateScopeData(nearestScope); + } + return false; + } + + void _pushPolicyData(TraversalDirection direction, FocusScopeNode nearestScope, FocusNode focusedChild) { + final _DirectionalPolicyData? policyData = _policyData[nearestScope]; + final _DirectionalPolicyDataEntry newEntry = _DirectionalPolicyDataEntry(node: focusedChild, direction: direction); + if (policyData != null) { + policyData.history.add(newEntry); + } else { + _policyData[nearestScope] = _DirectionalPolicyData(history: <_DirectionalPolicyDataEntry>[newEntry]); + } + } + + /// Focuses the next widget in the given [direction] in the [FocusScope] that + /// contains the [currentNode]. + /// + /// This determines what the next node to receive focus in the given + /// [direction] will be by inspecting the node tree, and then calling + /// [FocusNode.requestFocus] on it. + /// + /// Returns true if it successfully found a node and requested focus. + /// + /// Maintains a stack of previous locations that have been visited on the + /// policy data for the affected [FocusScopeNode]. If the previous direction + /// was the opposite of the current direction, then the this policy will + /// request focus on the previously focused node. Change to another direction + /// other than the current one or its opposite will clear the stack. + /// + /// If this function returns true when called by a subclass, then the subclass + /// should return true and not request focus from any node. + @mustCallSuper + @override + bool inDirection(FocusNode currentNode, TraversalDirection direction) { + final FocusScopeNode nearestScope = currentNode.nearestScope!; + final FocusNode? focusedChild = nearestScope.focusedChild; + if (focusedChild == null) { + final FocusNode firstFocus = findFirstFocusInDirection(currentNode, direction) ?? currentNode; + switch (direction) { + case TraversalDirection.up: + case TraversalDirection.left: + requestFocusCallback( + firstFocus, + alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtStart, + ); + case TraversalDirection.right: + case TraversalDirection.down: + requestFocusCallback( + firstFocus, + alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd, + ); + } + return true; + } + if (_popPolicyDataIfNeeded(direction, nearestScope, focusedChild)) { + return true; + } + FocusNode? found; + final ScrollableState? focusedScrollable = Scrollable.maybeOf(focusedChild.context!); + switch (direction) { + case TraversalDirection.down: + case TraversalDirection.up: + Iterable<FocusNode> eligibleNodes = _sortAndFilterVertically(direction, focusedChild.rect, nearestScope.traversalDescendants); + if (eligibleNodes.isEmpty) { + break; + } + if (focusedScrollable != null && !focusedScrollable.position.atEdge) { + final Iterable<FocusNode> filteredEligibleNodes = eligibleNodes.where((FocusNode node) => Scrollable.maybeOf(node.context!) == focusedScrollable); + if (filteredEligibleNodes.isNotEmpty) { + eligibleNodes = filteredEligibleNodes; + } + } + if (direction == TraversalDirection.up) { + eligibleNodes = eligibleNodes.toList().reversed; + } + // Find any nodes that intersect the band of the focused child. + final Rect band = Rect.fromLTRB(focusedChild.rect.left, -double.infinity, focusedChild.rect.right, double.infinity); + final Iterable<FocusNode> inBand = eligibleNodes.where((FocusNode node) => !node.rect.intersect(band).isEmpty); + if (inBand.isNotEmpty) { + found = _sortByDistancePreferVertical(focusedChild.rect.center, inBand).first; + break; + } + // Only out-of-band targets are eligible, so pick the one that is + // closest to the center line horizontally, and if any are the same + // distance horizontally, pick the closest one of those vertically. + found = _sortClosestEdgesByDistancePreferHorizontal(focusedChild.rect.center, eligibleNodes).first; + case TraversalDirection.right: + case TraversalDirection.left: + Iterable<FocusNode> eligibleNodes = _sortAndFilterHorizontally(direction, focusedChild.rect, nearestScope.traversalDescendants); + if (eligibleNodes.isEmpty) { + break; + } + if (focusedScrollable != null && !focusedScrollable.position.atEdge) { + final Iterable<FocusNode> filteredEligibleNodes = eligibleNodes.where((FocusNode node) => Scrollable.maybeOf(node.context!) == focusedScrollable); + if (filteredEligibleNodes.isNotEmpty) { + eligibleNodes = filteredEligibleNodes; + } + } + if (direction == TraversalDirection.left) { + eligibleNodes = eligibleNodes.toList().reversed; + } + // Find any nodes that intersect the band of the focused child. + final Rect band = Rect.fromLTRB(-double.infinity, focusedChild.rect.top, double.infinity, focusedChild.rect.bottom); + final Iterable<FocusNode> inBand = eligibleNodes.where((FocusNode node) => !node.rect.intersect(band).isEmpty); + if (inBand.isNotEmpty) { + found = _sortByDistancePreferHorizontal(focusedChild.rect.center, inBand).first; + break; + } + // Only out-of-band targets are eligible, so pick the one that is + // closest to the center line vertically, and if any are the same + // distance vertically, pick the closest one of those horizontally. + found = _sortClosestEdgesByDistancePreferVertical(focusedChild.rect.center, eligibleNodes).first; + } + if (found != null) { + _pushPolicyData(direction, nearestScope, focusedChild); + switch (direction) { + case TraversalDirection.up: + case TraversalDirection.left: + requestFocusCallback( + found, + alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtStart, + ); + case TraversalDirection.down: + case TraversalDirection.right: + requestFocusCallback( + found, + alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd, + ); + } + return true; + } + return false; + } +} + +/// A [FocusTraversalPolicy] that traverses the focus order in widget hierarchy +/// order. +/// +/// This policy is used when the order desired is the order in which widgets are +/// created in the widget hierarchy. +/// +/// See also: +/// +/// * [FocusNode], for a description of the focus system. +/// * [FocusTraversalGroup], a widget that groups together and imposes a +/// traversal policy on the [Focus] nodes below it in the widget hierarchy. +/// * [ReadingOrderTraversalPolicy], a policy that describes the order as the +/// natural "reading order" for the current [Directionality]. +/// * [DirectionalFocusTraversalPolicyMixin] a mixin class that implements +/// focus traversal in a direction. +/// * [OrderedTraversalPolicy], a policy that describes the order +/// explicitly using [FocusTraversalOrder] widgets. +class WidgetOrderTraversalPolicy extends FocusTraversalPolicy with DirectionalFocusTraversalPolicyMixin { + /// Constructs a traversal policy that orders widgets for keyboard traversal + /// based on the widget hierarchy order. + /// + /// {@macro flutter.widgets.FocusTraversalPolicy.requestFocusCallback} + WidgetOrderTraversalPolicy({super.requestFocusCallback}); + @override + Iterable<FocusNode> sortDescendants(Iterable<FocusNode> descendants, FocusNode currentNode) => descendants; +} + +// This class exists mainly for efficiency reasons: the rect is copied out of +// the node, because it will be accessed many times in the reading order +// algorithm, and the FocusNode.rect accessor does coordinate transformation. If +// not for this optimization, it could just be removed, and the node used +// directly. +// +// It's also a convenient place to put some utility functions having to do with +// the sort data. +class _ReadingOrderSortData with Diagnosticable { + _ReadingOrderSortData(this.node) + : rect = node.rect, + directionality = _findDirectionality(node.context!); + + final TextDirection? directionality; + final Rect rect; + final FocusNode node; + + // Find the directionality in force for a build context without creating a + // dependency. + static TextDirection? _findDirectionality(BuildContext context) { + return context.getInheritedWidgetOfExactType<Directionality>()?.textDirection; + } + + /// Finds the common Directional ancestor of an entire list of groups. + static TextDirection? commonDirectionalityOf(List<_ReadingOrderSortData> list) { + final Iterable<Set<Directionality>> allAncestors = list.map<Set<Directionality>>((_ReadingOrderSortData member) => member.directionalAncestors.toSet()); + Set<Directionality>? common; + for (final Set<Directionality> ancestorSet in allAncestors) { + common ??= ancestorSet; + common = common.intersection(ancestorSet); + } + if (common!.isEmpty) { + // If there is no common ancestor, then arbitrarily pick the + // directionality of the first group, which is the equivalent of the + // "first strongly typed" item in a bidirectional algorithm. + return list.first.directionality; + } + // Find the closest common ancestor. The memberAncestors list contains the + // ancestors for all members, but the first member's ancestry was + // added in order from nearest to furthest, so we can still use that + // to determine the closest one. + return list.first.directionalAncestors.firstWhere(common.contains).textDirection; + } + + static void sortWithDirectionality(List<_ReadingOrderSortData> list, TextDirection directionality) { + mergeSort<_ReadingOrderSortData>(list, compare: (_ReadingOrderSortData a, _ReadingOrderSortData b) { + switch (directionality) { + case TextDirection.ltr: + return a.rect.left.compareTo(b.rect.left); + case TextDirection.rtl: + return b.rect.right.compareTo(a.rect.right); + } + }); + } + + /// Returns the list of Directionality ancestors, in order from nearest to + /// furthest. + Iterable<Directionality> get directionalAncestors { + List<Directionality> getDirectionalityAncestors(BuildContext context) { + final List<Directionality> result = <Directionality>[]; + InheritedElement? directionalityElement = context.getElementForInheritedWidgetOfExactType<Directionality>(); + while (directionalityElement != null) { + result.add(directionalityElement.widget as Directionality); + directionalityElement = _getAncestor(directionalityElement)?.getElementForInheritedWidgetOfExactType<Directionality>(); + } + return result; + } + + _directionalAncestors ??= getDirectionalityAncestors(node.context!); + return _directionalAncestors!; + } + + List<Directionality>? _directionalAncestors; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<TextDirection>('directionality', directionality)); + properties.add(StringProperty('name', node.debugLabel, defaultValue: null)); + properties.add(DiagnosticsProperty<Rect>('rect', rect)); + } +} + +// A class for containing group data while sorting in reading order while taking +// into account the ambient directionality. +class _ReadingOrderDirectionalGroupData with Diagnosticable { + _ReadingOrderDirectionalGroupData(this.members); + + final List<_ReadingOrderSortData> members; + + TextDirection? get directionality => members.first.directionality; + + Rect? _rect; + Rect get rect { + if (_rect == null) { + for (final Rect rect in members.map<Rect>((_ReadingOrderSortData data) => data.rect)) { + _rect ??= rect; + _rect = _rect!.expandToInclude(rect); + } + } + return _rect!; + } + + List<Directionality> get memberAncestors { + if (_memberAncestors == null) { + _memberAncestors = <Directionality>[]; + for (final _ReadingOrderSortData member in members) { + _memberAncestors!.addAll(member.directionalAncestors); + } + } + return _memberAncestors!; + } + + List<Directionality>? _memberAncestors; + + static void sortWithDirectionality(List<_ReadingOrderDirectionalGroupData> list, TextDirection directionality) { + mergeSort<_ReadingOrderDirectionalGroupData>(list, compare: (_ReadingOrderDirectionalGroupData a, _ReadingOrderDirectionalGroupData b) { + switch (directionality) { + case TextDirection.ltr: + return a.rect.left.compareTo(b.rect.left); + case TextDirection.rtl: + return b.rect.right.compareTo(a.rect.right); + } + }); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<TextDirection>('directionality', directionality)); + properties.add(DiagnosticsProperty<Rect>('rect', rect)); + properties.add(IterableProperty<String>('members', members.map<String>((_ReadingOrderSortData member) { + return '"${member.node.debugLabel}"(${member.rect})'; + }))); + } +} + +/// Traverses the focus order in "reading order". +/// +/// By default, reading order traversal goes in the reading direction, and then +/// down, using this algorithm: +/// +/// 1. Find the node rectangle that has the highest `top` on the screen. +/// 2. Find any other nodes that intersect the infinite horizontal band defined +/// by the highest rectangle's top and bottom edges. +/// 3. Pick the closest to the beginning of the reading order from among the +/// nodes discovered above. +/// +/// It uses the ambient [Directionality] in the context for the enclosing +/// [FocusTraversalGroup] to determine which direction is "reading order". +/// +/// See also: +/// +/// * [FocusNode], for a description of the focus system. +/// * [FocusTraversalGroup], a widget that groups together and imposes a +/// traversal policy on the [Focus] nodes below it in the widget hierarchy. +/// * [WidgetOrderTraversalPolicy], a policy that relies on the widget +/// creation order to describe the order of traversal. +/// * [DirectionalFocusTraversalPolicyMixin] a mixin class that implements +/// focus traversal in a direction. +/// * [OrderedTraversalPolicy], a policy that describes the order +/// explicitly using [FocusTraversalOrder] widgets. +class ReadingOrderTraversalPolicy extends FocusTraversalPolicy with DirectionalFocusTraversalPolicyMixin { + /// Constructs a traversal policy that orders the widgets in "reading order". + /// + /// {@macro flutter.widgets.FocusTraversalPolicy.requestFocusCallback} + ReadingOrderTraversalPolicy({super.requestFocusCallback}); + + // Collects the given candidates into groups by directionality. The candidates + // have already been sorted as if they all had the directionality of the + // nearest Directionality ancestor. + List<_ReadingOrderDirectionalGroupData> _collectDirectionalityGroups(Iterable<_ReadingOrderSortData> candidates) { + TextDirection? currentDirection = candidates.first.directionality; + List<_ReadingOrderSortData> currentGroup = <_ReadingOrderSortData>[]; + final List<_ReadingOrderDirectionalGroupData> result = <_ReadingOrderDirectionalGroupData>[]; + // Split candidates into runs of the same directionality. + for (final _ReadingOrderSortData candidate in candidates) { + if (candidate.directionality == currentDirection) { + currentGroup.add(candidate); + continue; + } + currentDirection = candidate.directionality; + result.add(_ReadingOrderDirectionalGroupData(currentGroup)); + currentGroup = <_ReadingOrderSortData>[candidate]; + } + if (currentGroup.isNotEmpty) { + result.add(_ReadingOrderDirectionalGroupData(currentGroup)); + } + // Sort each group separately. Each group has the same directionality. + for (final _ReadingOrderDirectionalGroupData bandGroup in result) { + if (bandGroup.members.length == 1) { + continue; // No need to sort one node. + } + _ReadingOrderSortData.sortWithDirectionality(bandGroup.members, bandGroup.directionality!); + } + return result; + } + + _ReadingOrderSortData _pickNext(List<_ReadingOrderSortData> candidates) { + // Find the topmost node by sorting on the top of the rectangles. + mergeSort<_ReadingOrderSortData>(candidates, compare: (_ReadingOrderSortData a, _ReadingOrderSortData b) => a.rect.top.compareTo(b.rect.top)); + final _ReadingOrderSortData topmost = candidates.first; + + // Find the candidates that are in the same horizontal band as the current one. + List<_ReadingOrderSortData> inBand(_ReadingOrderSortData current, Iterable<_ReadingOrderSortData> candidates) { + final Rect band = Rect.fromLTRB(double.negativeInfinity, current.rect.top, double.infinity, current.rect.bottom); + return candidates.where((_ReadingOrderSortData item) { + return !item.rect.intersect(band).isEmpty; + }).toList(); + } + + final List<_ReadingOrderSortData> inBandOfTop = inBand(topmost, candidates); + // It has to have at least topmost in it if the topmost is not degenerate. + assert(topmost.rect.isEmpty || inBandOfTop.isNotEmpty); + + // The topmost rect is in a band by itself, so just return that one. + if (inBandOfTop.length <= 1) { + return topmost; + } + + // Now that we know there are others in the same band as the topmost, then pick + // the one at the beginning, depending on the text direction in force. + + // Find out the directionality of the nearest common Directionality + // ancestor for all nodes. This provides a base directionality to use for + // the ordering of the groups. + final TextDirection? nearestCommonDirectionality = _ReadingOrderSortData.commonDirectionalityOf(inBandOfTop); + + // Do an initial common-directionality-based sort to get consistent geometric + // ordering for grouping into directionality groups. It has to use the + // common directionality to be able to group into sane groups for the + // given directionality, since rectangles can overlap and give different + // results for different directionalities. + _ReadingOrderSortData.sortWithDirectionality(inBandOfTop, nearestCommonDirectionality!); + + // Collect the top band into internally sorted groups with shared directionality. + final List<_ReadingOrderDirectionalGroupData> bandGroups = _collectDirectionalityGroups(inBandOfTop); + if (bandGroups.length == 1) { + // There's only one directionality group, so just send back the first + // one in that group, since it's already sorted. + return bandGroups.first.members.first; + } + + // Sort the groups based on the common directionality and bounding boxes. + _ReadingOrderDirectionalGroupData.sortWithDirectionality(bandGroups, nearestCommonDirectionality); + return bandGroups.first.members.first; + } + + // Sorts the list of nodes based on their geometry into the desired reading + // order based on the directionality of the context for each node. + @override + Iterable<FocusNode> sortDescendants(Iterable<FocusNode> descendants, FocusNode currentNode) { + if (descendants.length <= 1) { + return descendants; + } + + final List<_ReadingOrderSortData> data = <_ReadingOrderSortData>[ + for (final FocusNode node in descendants) _ReadingOrderSortData(node), + ]; + + final List<FocusNode> sortedList = <FocusNode>[]; + final List<_ReadingOrderSortData> unplaced = data; + + // Pick the initial widget as the one that is at the beginning of the band + // of the topmost, or the topmost, if there are no others in its band. + _ReadingOrderSortData current = _pickNext(unplaced); + sortedList.add(current.node); + unplaced.remove(current); + + // Go through each node, picking the next one after eliminating the previous + // one, since removing the previously picked node will expose a new band in + // which to choose candidates. + while (unplaced.isNotEmpty) { + final _ReadingOrderSortData next = _pickNext(unplaced); + current = next; + sortedList.add(current.node); + unplaced.remove(current); + } + return sortedList; + } +} + +/// Base class for all sort orders for [OrderedTraversalPolicy] traversal. +/// +/// {@template flutter.widgets.FocusOrder.comparable} +/// Only orders of the same type are comparable. If a set of widgets in the same +/// [FocusTraversalGroup] contains orders that are not comparable with each +/// other, it will assert, since the ordering between such keys is undefined. To +/// avoid collisions, use a [FocusTraversalGroup] to group similarly ordered +/// widgets together. +/// +/// When overriding, [FocusOrder.doCompare] must be overridden instead of +/// [FocusOrder.compareTo], which calls [FocusOrder.doCompare] to do the actual +/// comparison. +/// {@endtemplate} +/// +/// See also: +/// +/// * [FocusTraversalGroup], a widget that groups together and imposes a +/// traversal policy on the [Focus] nodes below it in the widget hierarchy. +/// * [FocusTraversalOrder], a widget that assigns an order to a widget subtree +/// for the [OrderedTraversalPolicy] to use. +/// * [NumericFocusOrder], for a focus order that describes its order with a +/// `double`. +/// * [LexicalFocusOrder], a focus order that assigns a string-based lexical +/// traversal order to a [FocusTraversalOrder] widget. +@immutable +abstract class FocusOrder with Diagnosticable implements Comparable<FocusOrder> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const FocusOrder(); + + /// Compares this object to another [Comparable]. + /// + /// When overriding [FocusOrder], implement [doCompare] instead of this + /// function to do the actual comparison. + /// + /// Returns a value like a [Comparator] when comparing `this` to [other]. + /// That is, it returns a negative integer if `this` is ordered before [other], + /// a positive integer if `this` is ordered after [other], + /// and zero if `this` and [other] are ordered together. + /// + /// The [other] argument must be a value that is comparable to this object. + @override + @nonVirtual + int compareTo(FocusOrder other) { + assert( + runtimeType == other.runtimeType, + "The sorting algorithm must not compare incomparable keys, since they don't " + 'know how to order themselves relative to each other. Comparing $this with $other', + ); + return doCompare(other); + } + + /// The subclass implementation called by [compareTo] to compare orders. + /// + /// The argument is guaranteed to be of the same [runtimeType] as this object. + /// + /// The method should return a negative number if this object comes earlier in + /// the sort order than the `other` argument; and a positive number if it + /// comes later in the sort order than `other`. Returning zero causes the + /// system to fall back to the secondary sort order defined by + /// [OrderedTraversalPolicy.secondary] + @protected + int doCompare(covariant FocusOrder other); +} + +/// Can be given to a [FocusTraversalOrder] widget to assign a numerical order +/// to a widget subtree that is using a [OrderedTraversalPolicy] to define the +/// order in which widgets should be traversed with the keyboard. +/// +/// {@macro flutter.widgets.FocusOrder.comparable} +/// +/// See also: +/// +/// * [FocusTraversalOrder], a widget that assigns an order to a widget subtree +/// for the [OrderedTraversalPolicy] to use. +class NumericFocusOrder extends FocusOrder { + /// Creates an object that describes a focus traversal order numerically. + const NumericFocusOrder(this.order); + + /// The numerical order to assign to the widget subtree using + /// [FocusTraversalOrder]. + /// + /// Determines the placement of this widget in a sequence of widgets that defines + /// the order in which this node is traversed by the focus policy. + /// + /// Lower values will be traversed first. + final double order; + + @override + int doCompare(NumericFocusOrder other) => order.compareTo(other.order); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('order', order)); + } +} + +/// Can be given to a [FocusTraversalOrder] widget to use a String to assign a +/// lexical order to a widget subtree that is using a +/// [OrderedTraversalPolicy] to define the order in which widgets should be +/// traversed with the keyboard. +/// +/// This sorts strings using Dart's default string comparison, which is not +/// locale-specific. +/// +/// {@macro flutter.widgets.FocusOrder.comparable} +/// +/// See also: +/// +/// * [FocusTraversalOrder], a widget that assigns an order to a widget subtree +/// for the [OrderedTraversalPolicy] to use. +class LexicalFocusOrder extends FocusOrder { + /// Creates an object that describes a focus traversal order lexically. + const LexicalFocusOrder(this.order); + + /// The String that defines the lexical order to assign to the widget subtree + /// using [FocusTraversalOrder]. + /// + /// Determines the placement of this widget in a sequence of widgets that defines + /// the order in which this node is traversed by the focus policy. + /// + /// Lower lexical values will be traversed first (e.g. 'a' comes before 'z'). + final String order; + + @override + int doCompare(LexicalFocusOrder other) => order.compareTo(other.order); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('order', order)); + } +} + +// Used to help sort the focus nodes in an OrderedFocusTraversalPolicy. +class _OrderedFocusInfo { + const _OrderedFocusInfo({required this.node, required this.order}); + + final FocusNode node; + final FocusOrder order; +} + +/// A [FocusTraversalPolicy] that orders nodes by an explicit order that resides +/// in the nearest [FocusTraversalOrder] widget ancestor. +/// +/// {@macro flutter.widgets.FocusOrder.comparable} +/// +/// {@tool dartpad} +/// This sample shows how to assign a traversal order to a widget. In the +/// example, the focus order goes from bottom right (the "One" button) to top +/// left (the "Six" button). +/// +/// ** See code in examples/api/lib/widgets/focus_traversal/ordered_traversal_policy.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [FocusTraversalGroup], a widget that groups together and imposes a +/// traversal policy on the [Focus] nodes below it in the widget hierarchy. +/// * [WidgetOrderTraversalPolicy], a policy that relies on the widget +/// creation order to describe the order of traversal. +/// * [ReadingOrderTraversalPolicy], a policy that describes the order as the +/// natural "reading order" for the current [Directionality]. +/// * [NumericFocusOrder], a focus order that assigns a numeric traversal order +/// to a [FocusTraversalOrder] widget. +/// * [LexicalFocusOrder], a focus order that assigns a string-based lexical +/// traversal order to a [FocusTraversalOrder] widget. +/// * [FocusOrder], an abstract base class for all types of focus traversal +/// orderings. +class OrderedTraversalPolicy extends FocusTraversalPolicy with DirectionalFocusTraversalPolicyMixin { + /// Constructs a traversal policy that orders widgets for keyboard traversal + /// based on an explicit order. + /// + /// If [secondary] is null, it will default to [ReadingOrderTraversalPolicy]. + OrderedTraversalPolicy({this.secondary, super.requestFocusCallback}); + + /// This is the policy that is used when a node doesn't have an order + /// assigned, or when multiple nodes have orders which are identical. + /// + /// If not set, this defaults to [ReadingOrderTraversalPolicy]. + /// + /// This policy determines the secondary sorting order of nodes which evaluate + /// as having an identical order (including those with no order specified). + /// + /// Nodes with no order specified will be sorted after nodes with an explicit + /// order. + final FocusTraversalPolicy? secondary; + + @override + Iterable<FocusNode> sortDescendants(Iterable<FocusNode> descendants, FocusNode currentNode) { + final FocusTraversalPolicy secondaryPolicy = secondary ?? ReadingOrderTraversalPolicy(); + final Iterable<FocusNode> sortedDescendants = secondaryPolicy.sortDescendants(descendants, currentNode); + final List<FocusNode> unordered = <FocusNode>[]; + final List<_OrderedFocusInfo> ordered = <_OrderedFocusInfo>[]; + for (final FocusNode node in sortedDescendants) { + final FocusOrder? order = FocusTraversalOrder.maybeOf(node.context!); + if (order != null) { + ordered.add(_OrderedFocusInfo(node: node, order: order)); + } else { + unordered.add(node); + } + } + mergeSort<_OrderedFocusInfo>(ordered, compare: (_OrderedFocusInfo a, _OrderedFocusInfo b) { + assert( + a.order.runtimeType == b.order.runtimeType, + 'When sorting nodes for determining focus order, the order (${a.order}) of ' + "node ${a.node}, isn't the same type as the order (${b.order}) of ${b.node}. " + "Incompatible order types can't be compared. Use a FocusTraversalGroup to group " + 'similar orders together.', + ); + return a.order.compareTo(b.order); + }); + return ordered.map<FocusNode>((_OrderedFocusInfo info) => info.node).followedBy(unordered); + } +} + +/// An inherited widget that describes the order in which its child subtree +/// should be traversed. +/// +/// {@macro flutter.widgets.FocusOrder.comparable} +/// +/// The order for a widget is determined by the [FocusOrder] returned by +/// [FocusTraversalOrder.of] for a particular context. +class FocusTraversalOrder extends InheritedWidget { + /// Creates an inherited widget used to describe the focus order of + /// the [child] subtree. + const FocusTraversalOrder({super.key, required this.order, required super.child}); + + /// The order for the widget descendants of this [FocusTraversalOrder]. + final FocusOrder order; + + /// Finds the [FocusOrder] in the nearest ancestor [FocusTraversalOrder] widget. + /// + /// It does not create a rebuild dependency because changing the traversal + /// order doesn't change the widget tree, so nothing needs to be rebuilt as a + /// result of an order change. + /// + /// If no [FocusTraversalOrder] ancestor exists, or the order is null, this + /// will assert in debug mode, and throw an exception in release mode. + static FocusOrder of(BuildContext context) { + final FocusTraversalOrder? marker = context.getInheritedWidgetOfExactType<FocusTraversalOrder>(); + assert(() { + if (marker == null) { + throw FlutterError( + 'FocusTraversalOrder.of() was called with a context that ' + 'does not contain a FocusTraversalOrder widget. No TraversalOrder widget ' + 'ancestor could be found starting from the context that was passed to ' + 'FocusTraversalOrder.of().\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return marker!.order; + } + + /// Finds the [FocusOrder] in the nearest ancestor [FocusTraversalOrder] widget. + /// + /// It does not create a rebuild dependency because changing the traversal + /// order doesn't change the widget tree, so nothing needs to be rebuilt as a + /// result of an order change. + /// + /// If no [FocusTraversalOrder] ancestor exists, or the order is null, returns null. + static FocusOrder? maybeOf(BuildContext context) { + final FocusTraversalOrder? marker = context.getInheritedWidgetOfExactType<FocusTraversalOrder>(); + return marker?.order; + } + + // Since the order of traversal doesn't affect display of anything, we don't + // need to force a rebuild of anything that depends upon it. + @override + bool updateShouldNotify(InheritedWidget oldWidget) => false; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<FocusOrder>('order', order)); + } +} + +/// A widget that describes the inherited focus policy for focus traversal for +/// its descendants, grouping them into a separate traversal group. +/// +/// A traversal group is treated as one entity when sorted by the traversal +/// algorithm, so it can be used to segregate different parts of the widget tree +/// that need to be sorted using different algorithms and/or sort orders when +/// using an [OrderedTraversalPolicy]. +/// +/// Within the group, it will use the given [policy] to order the elements. The +/// group itself will be ordered using the parent group's policy. +/// +/// By default, traverses in reading order using [ReadingOrderTraversalPolicy]. +/// +/// To prevent the members of the group from being focused, set the +/// [descendantsAreFocusable] attribute to false. +/// +/// {@tool dartpad} +/// This sample shows three rows of buttons, each grouped by a +/// [FocusTraversalGroup], each with different traversal order policies. Use tab +/// traversal to see the order they are traversed in. The first row follows a +/// numerical order, the second follows a lexical order (ordered to traverse +/// right to left), and the third ignores the numerical order assigned to it and +/// traverses in widget order. +/// +/// ** See code in examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [FocusNode], for a description of the focus system. +/// * [WidgetOrderTraversalPolicy], a policy that relies on the widget +/// creation order to describe the order of traversal. +/// * [ReadingOrderTraversalPolicy], a policy that describes the order as the +/// natural "reading order" for the current [Directionality]. +/// * [DirectionalFocusTraversalPolicyMixin] a mixin class that implements +/// focus traversal in a direction. +class FocusTraversalGroup extends StatefulWidget { + /// Creates a [FocusTraversalGroup] object. + FocusTraversalGroup({ + super.key, + FocusTraversalPolicy? policy, + this.descendantsAreFocusable = true, + this.descendantsAreTraversable = true, + required this.child, + }) : policy = policy ?? ReadingOrderTraversalPolicy(); + + /// The policy used to move the focus from one focus node to another when + /// traversing them using a keyboard. + /// + /// If not specified, traverses in reading order using + /// [ReadingOrderTraversalPolicy]. + /// + /// See also: + /// + /// * [FocusTraversalPolicy] for the API used to impose traversal order + /// policy. + /// * [WidgetOrderTraversalPolicy] for a traversal policy that traverses + /// nodes in the order they are added to the widget tree. + /// * [ReadingOrderTraversalPolicy] for a traversal policy that traverses + /// nodes in the reading order defined in the widget tree, and then top to + /// bottom. + final FocusTraversalPolicy policy; + + /// {@macro flutter.widgets.Focus.descendantsAreFocusable} + final bool descendantsAreFocusable; + + /// {@macro flutter.widgets.Focus.descendantsAreTraversable} + final bool descendantsAreTraversable; + + /// The child widget of this [FocusTraversalGroup]. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// Returns the [FocusTraversalPolicy] that applies to the nearest ancestor of + /// the given [FocusNode]. + /// + /// Will return null if no [FocusTraversalPolicy] ancestor applies to the + /// given [FocusNode]. + /// + /// The [FocusTraversalPolicy] is set by introducing a [FocusTraversalGroup] + /// into the widget tree, which will associate a policy with the focus tree + /// under the nearest ancestor [Focus] widget. + /// + /// This function differs from [maybeOf] in that it takes a [FocusNode] and + /// only traverses the focus tree to determine the policy in effect. Unlike + /// this function, the [maybeOf] function takes a [BuildContext] and first + /// walks up the widget tree to find the nearest ancestor [Focus] or + /// [FocusScope] widget, and then calls this function with the focus node + /// associated with that widget to determine the policy in effect. + static FocusTraversalPolicy? maybeOfNode(FocusNode node) { + return _getGroupNode(node)?.policy; + } + + static _FocusTraversalGroupNode? _getGroupNode(FocusNode node) { + while (node.parent != null) { + if (node.context == null) { + return null; + } + if (node is _FocusTraversalGroupNode) { + return node; + } + node = node.parent!; + } + return null; + } + + /// Returns the [FocusTraversalPolicy] that applies to the [FocusNode] of the + /// nearest ancestor [Focus] widget, given a [BuildContext]. + /// + /// Will throw a [FlutterError] in debug mode, and throw a null check + /// exception in release mode, if no [Focus] ancestor is found, or if no + /// [FocusTraversalPolicy] applies to the associated [FocusNode]. + /// + /// {@template flutter.widgets.focus_traversal.FocusTraversalGroup.of} + /// This function looks up the nearest ancestor [Focus] (or [FocusScope]) + /// widget, and uses its [FocusNode] (or [FocusScopeNode]) to walk up the + /// focus tree to find the applicable [FocusTraversalPolicy] for that node. + /// + /// Calling this function does not create a rebuild dependency because + /// changing the traversal order doesn't change the widget tree, so nothing + /// needs to be rebuilt as a result of an order change. + /// + /// The [FocusTraversalPolicy] is set by introducing a [FocusTraversalGroup] + /// into the widget tree, which will associate a policy with the focus tree + /// under the nearest ancestor [Focus] widget. + /// {@endtemplate} + /// + /// See also: + /// + /// * [maybeOf] for a similar function that will return null if no + /// [FocusTraversalGroup] ancestor is found. + /// * [maybeOfNode] for a function that will look for a policy using a given + /// [FocusNode], and return null if no policy applies. + static FocusTraversalPolicy of(BuildContext context) { + final FocusTraversalPolicy? policy = maybeOf(context); + assert(() { + if (policy == null) { + throw FlutterError( + 'Unable to find a Focus or FocusScope widget in the given context, or the FocusNode ' + 'from with the widget that was found is not associated with a FocusTraversalPolicy.\n' + 'FocusTraversalGroup.of() was called with a context that does not contain a ' + 'Focus or FocusScope widget, or there was no FocusTraversalPolicy in effect.\n' + 'This can happen if there is not a FocusTraversalGroup that defines the policy, ' + 'or if the context comes from a widget that is above the WidgetsApp, MaterialApp, ' + 'or CupertinoApp widget (those widgets introduce an implicit default policy) \n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return policy!; + } + + /// Returns the [FocusTraversalPolicy] that applies to the [FocusNode] of the + /// nearest ancestor [Focus] widget, or null, given a [BuildContext]. + /// + /// Will return null if it doesn't find an ancestor [Focus] or [FocusScope] + /// widget, or doesn't find a [FocusTraversalPolicy] that applies to the node. + /// + /// {@macro flutter.widgets.focus_traversal.FocusTraversalGroup.of} + /// + /// See also: + /// + /// * [maybeOfNode] for a similar function that will look for a policy using a + /// given [FocusNode]. + /// * [of] for a similar function that will throw if no [FocusTraversalPolicy] + /// applies. + static FocusTraversalPolicy? maybeOf(BuildContext context) { + final FocusNode? node = Focus.maybeOf(context, scopeOk: true, createDependency: false); + if (node == null) { + return null; + } + return FocusTraversalGroup.maybeOfNode(node); + } + + @override + State<FocusTraversalGroup> createState() => _FocusTraversalGroupState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<FocusTraversalPolicy>('policy', policy)); + } +} + +// A special focus node subclass that only FocusTraversalGroup uses so that it +// can be used to cache the policy in the focus tree, and so that the traversal +// code can find groups in the focus tree. +class _FocusTraversalGroupNode extends FocusNode { + _FocusTraversalGroupNode({ + super.debugLabel, + required this.policy, + }) { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + FocusTraversalPolicy policy; +} + +class _FocusTraversalGroupState extends State<FocusTraversalGroup> { + // The internal focus node used to collect the children of this node into a + // group, and to provide a context for the traversal algorithm to sort the + // group with. It's a special subclass of FocusNode just so that it can be + // identified when walking the focus tree during traversal, and hold the + // current policy. + late final _FocusTraversalGroupNode focusNode = _FocusTraversalGroupNode( + debugLabel: 'FocusTraversalGroup', + policy: widget.policy, + ); + + @override + void dispose() { + focusNode.dispose(); + super.dispose(); + } + + @override + void didUpdateWidget (FocusTraversalGroup oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.policy != widget.policy) { + focusNode.policy = widget.policy; + } + } + + @override + Widget build(BuildContext context) { + return Focus( + focusNode: focusNode, + canRequestFocus: false, + skipTraversal: true, + includeSemantics: false, + descendantsAreFocusable: widget.descendantsAreFocusable, + descendantsAreTraversable: widget.descendantsAreTraversable, + child: widget.child, + ); + } +} + +/// An intent for use with the [RequestFocusAction], which supplies the +/// [FocusNode] that should be focused. +class RequestFocusIntent extends Intent { + /// Creates an intent used with [RequestFocusAction]. + /// + /// {@macro flutter.widgets.FocusTraversalPolicy.requestFocusCallback} + const RequestFocusIntent(this.focusNode, { + TraversalRequestFocusCallback? requestFocusCallback + }) : requestFocusCallback = requestFocusCallback ?? FocusTraversalPolicy.defaultTraversalRequestFocusCallback; + + /// The callback used to move the focus to the node [focusNode]. + /// By default it requests focus on the node and ensures the node is visible + /// if it's in a scrollable. + final TraversalRequestFocusCallback requestFocusCallback; + + /// The [FocusNode] that is to be focused. + final FocusNode focusNode; +} + +/// An [Action] that requests the focus on the node it is given in its +/// [RequestFocusIntent]. +/// +/// This action can be used to request focus for a particular node, by calling +/// [Action.invoke] like so: +/// +/// ```dart +/// Actions.invoke(context, RequestFocusIntent(focusNode)); +/// ``` +/// +/// Where the `focusNode` is the node for which the focus will be requested. +/// +/// The difference between requesting focus in this way versus calling +/// [FocusNode.requestFocus] directly is that it will use the [Action] +/// registered in the nearest [Actions] widget associated with +/// [RequestFocusIntent] to make the request, rather than just requesting focus +/// directly. This allows the action to have additional side effects, like +/// logging, or undo and redo functionality. +/// +/// This [RequestFocusAction] class is the default action associated with the +/// [RequestFocusIntent] in the [WidgetsApp]. It requests focus. You +/// can redefine the associated action with your own [Actions] widget. +/// +/// See [FocusTraversalPolicy] for more information about focus traversal. +class RequestFocusAction extends Action<RequestFocusIntent> { + + @override + void invoke(RequestFocusIntent intent) { + intent.requestFocusCallback(intent.focusNode); + } +} + +/// An [Intent] bound to [NextFocusAction], which moves the focus to the next +/// focusable node in the focus traversal order. +/// +/// See [FocusTraversalPolicy] for more information about focus traversal. +class NextFocusIntent extends Intent { + /// Creates an intent that is used with [NextFocusAction]. + const NextFocusIntent(); +} + +/// An [Action] that moves the focus to the next focusable node in the focus +/// order. +/// +/// This action is the default action registered for the [NextFocusIntent], and +/// by default is bound to the [LogicalKeyboardKey.tab] key in the [WidgetsApp]. +/// +/// See [FocusTraversalPolicy] for more information about focus traversal. +class NextFocusAction extends Action<NextFocusIntent> { + /// Attempts to pass the focus to the next widget. + /// + /// Returns true if a widget was focused as a result of invoking this action. + /// + /// Returns false when the traversal reached the end and the engine must pass + /// focus to platform UI. + @override + bool invoke(NextFocusIntent intent) { + return primaryFocus!.nextFocus(); + } + + @override + KeyEventResult toKeyEventResult(NextFocusIntent intent, bool invokeResult) { + return invokeResult ? KeyEventResult.handled : KeyEventResult.skipRemainingHandlers; + } +} + +/// An [Intent] bound to [PreviousFocusAction], which moves the focus to the +/// previous focusable node in the focus traversal order. +/// +/// See [FocusTraversalPolicy] for more information about focus traversal. +class PreviousFocusIntent extends Intent { + /// Creates an intent that is used with [PreviousFocusAction]. + const PreviousFocusIntent(); +} + +/// An [Action] that moves the focus to the previous focusable node in the focus +/// order. +/// +/// This action is the default action registered for the [PreviousFocusIntent], +/// and by default is bound to a combination of the [LogicalKeyboardKey.tab] key +/// and the [LogicalKeyboardKey.shift] key in the [WidgetsApp]. +/// +/// See [FocusTraversalPolicy] for more information about focus traversal. +class PreviousFocusAction extends Action<PreviousFocusIntent> { + /// Attempts to pass the focus to the previous widget. + /// + /// Returns true if a widget was focused as a result of invoking this action. + /// + /// Returns false when the traversal reached the beginning and the engine must + /// pass focus to platform UI. + @override + bool invoke(PreviousFocusIntent intent) { + return primaryFocus!.previousFocus(); + } + + @override + KeyEventResult toKeyEventResult(PreviousFocusIntent intent, bool invokeResult) { + return invokeResult ? KeyEventResult.handled : KeyEventResult.skipRemainingHandlers; + } +} + +/// An [Intent] that represents moving to the next focusable node in the given +/// [direction]. +/// +/// This is the [Intent] bound by default to the [LogicalKeyboardKey.arrowUp], +/// [LogicalKeyboardKey.arrowDown], [LogicalKeyboardKey.arrowLeft], and +/// [LogicalKeyboardKey.arrowRight] keys in the [WidgetsApp], with the +/// appropriate associated directions. +/// +/// See [FocusTraversalPolicy] for more information about focus traversal. +class DirectionalFocusIntent extends Intent { + /// Creates an intent used to move the focus in the given [direction]. + const DirectionalFocusIntent(this.direction, {this.ignoreTextFields = true}); + + /// The direction in which to look for the next focusable node when the + /// associated [DirectionalFocusAction] is invoked. + final TraversalDirection direction; + + /// If true, then directional focus actions that occur within a text field + /// will not happen when the focus node which received the key is a text + /// field. + /// + /// Defaults to true. + final bool ignoreTextFields; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<TraversalDirection>('direction', direction)); + } +} + +/// An [Action] that moves the focus to the focusable node in the direction +/// configured by the associated [DirectionalFocusIntent.direction]. +/// +/// This is the [Action] associated with [DirectionalFocusIntent] and bound by +/// default to the [LogicalKeyboardKey.arrowUp], [LogicalKeyboardKey.arrowDown], +/// [LogicalKeyboardKey.arrowLeft], and [LogicalKeyboardKey.arrowRight] keys in +/// the [WidgetsApp], with the appropriate associated directions. +class DirectionalFocusAction extends Action<DirectionalFocusIntent> { + /// Creates a [DirectionalFocusAction]. + DirectionalFocusAction() : _isForTextField = false; + + /// Creates a [DirectionalFocusAction] that ignores [DirectionalFocusIntent]s + /// whose `ignoreTextFields` field is true. + DirectionalFocusAction.forTextField() : _isForTextField = true; + + // Whether this action is defined in a text field. + final bool _isForTextField; + @override + void invoke(DirectionalFocusIntent intent) { + if (!intent.ignoreTextFields || !_isForTextField) { + primaryFocus!.focusInDirection(intent.direction); + } + } +} + +/// A widget that controls whether or not the descendants of this widget are +/// traversable. +/// +/// Does not affect the value of [FocusNode.skipTraversal] of the descendants. +/// +/// See also: +/// +/// * [Focus], a widget for adding and managing a [FocusNode] in the widget tree. +/// * [ExcludeFocus], a widget that excludes its descendants from focusability. +/// * [FocusTraversalGroup], a widget that groups widgets for focus traversal, +/// and can also be used in the same way as this widget by setting its +/// `descendantsAreFocusable` attribute. +class ExcludeFocusTraversal extends StatelessWidget { + /// Const constructor for [ExcludeFocusTraversal] widget. + const ExcludeFocusTraversal({ + super.key, + this.excluding = true, + required this.child, + }); + + /// If true, will make this widget's descendants untraversable. + /// + /// Defaults to true. + /// + /// Does not affect the value of [FocusNode.skipTraversal] on the descendants. + /// + /// See also: + /// + /// * [Focus.descendantsAreTraversable], the attribute of a [Focus] widget that + /// controls this same property for focus widgets. + /// * [FocusTraversalGroup], a widget used to group together and configure the + /// focus traversal policy for a widget subtree that has a + /// `descendantsAreFocusable` parameter to conditionally block focus for a + /// subtree. + final bool excluding; + + /// The child widget of this [ExcludeFocusTraversal]. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + return Focus( + canRequestFocus: false, + skipTraversal: true, + includeSemantics: false, + descendantsAreTraversable: !excluding, + child: child, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/form.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/form.dart new file mode 100644 index 0000000000000000000000000000000000000000..cb8b5d9c6e8b02cb342107549a6954bad7dfb481 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/form.dart @@ -0,0 +1,611 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'navigator.dart'; +import 'pop_scope.dart'; +import 'restoration.dart'; +import 'restoration_properties.dart'; +import 'routes.dart'; +import 'will_pop_scope.dart'; + +// Duration for delay before announcement in IOS so that the announcement won't be interrupted. +const Duration _kIOSAnnouncementDelayDuration = Duration(seconds: 1); + +// Examples can assume: +// late BuildContext context; + +/// An optional container for grouping together multiple form field widgets +/// (e.g. [TextField] widgets). +/// +/// Each individual form field should be wrapped in a [FormField] widget, with +/// the [Form] widget as a common ancestor of all of those. Call methods on +/// [FormState] to save, reset, or validate each [FormField] that is a +/// descendant of this [Form]. To obtain the [FormState], you may use [Form.of] +/// with a context whose ancestor is the [Form], or pass a [GlobalKey] to the +/// [Form] constructor and call [GlobalKey.currentState]. +/// +/// {@tool dartpad} +/// This example shows a [Form] with one [TextFormField] to enter an email +/// address and an [ElevatedButton] to submit the form. A [GlobalKey] is used here +/// to identify the [Form] and validate input. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/form.png) +/// +/// ** See code in examples/api/lib/widgets/form/form.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [GlobalKey], a key that is unique across the entire app. +/// * [FormField], a single form field widget that maintains the current state. +/// * [TextFormField], a convenience widget that wraps a [TextField] widget in a [FormField]. +class Form extends StatefulWidget { + /// Creates a container for form fields. + const Form({ + super.key, + required this.child, + this.canPop, + this.onPopInvoked, + @Deprecated( + 'Use canPop and/or onPopInvoked instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', + ) + this.onWillPop, + this.onChanged, + AutovalidateMode? autovalidateMode, + }) : autovalidateMode = autovalidateMode ?? AutovalidateMode.disabled, + assert((onPopInvoked == null && canPop == null) || onWillPop == null, 'onWillPop is deprecated; use canPop and/or onPopInvoked.'); + + /// Returns the [FormState] of the closest [Form] widget which encloses the + /// given context, or null if none is found. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// FormState? form = Form.maybeOf(context); + /// form?.save(); + /// ``` + /// + /// Calling this method will create a dependency on the closest [Form] in the + /// [context], if there is one. + /// + /// See also: + /// + /// * [Form.of], which is similar to this method, but asserts if no [Form] + /// ancestor is found. + static FormState? maybeOf(BuildContext context) { + final _FormScope? scope = context.dependOnInheritedWidgetOfExactType<_FormScope>(); + return scope?._formState; + } + + /// Returns the [FormState] of the closest [Form] widget which encloses the + /// given context. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// FormState form = Form.of(context); + /// form.save(); + /// ``` + /// + /// If no [Form] ancestor is found, this will assert in debug mode, and throw + /// an exception in release mode. + /// + /// Calling this method will create a dependency on the closest [Form] in the + /// [context]. + /// + /// See also: + /// + /// * [Form.maybeOf], which is similar to this method, but returns null if no + /// [Form] ancestor is found. + static FormState of(BuildContext context) { + final FormState? formState = maybeOf(context); + assert(() { + if (formState == null) { + throw FlutterError( + 'Form.of() was called with a context that does not contain a Form widget.\n' + 'No Form widget ancestor could be found starting from the context that ' + 'was passed to Form.of(). This can happen because you are using a widget ' + 'that looks for a Form ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return formState!; + } + + /// The widget below this widget in the tree. + /// + /// This is the root of the widget hierarchy that contains this form. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// Enables the form to veto attempts by the user to dismiss the [ModalRoute] + /// that contains the form. + /// + /// If the callback returns a Future that resolves to false, the form's route + /// will not be popped. + /// + /// See also: + /// + /// * [WillPopScope], another widget that provides a way to intercept the + /// back button. + @Deprecated( + 'Use canPop and/or onPopInvoked instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', + ) + final WillPopCallback? onWillPop; + + /// {@macro flutter.widgets.PopScope.canPop} + /// + /// {@tool dartpad} + /// This sample demonstrates how to use this parameter to show a confirmation + /// dialog when a navigation pop would cause form data to be lost. + /// + /// ** See code in examples/api/lib/widgets/form/form.1.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [onPopInvoked], which also comes from [PopScope] and is often used in + /// conjunction with this parameter. + /// * [PopScope.canPop], which is what [Form] delegates to internally. + final bool? canPop; + + /// {@macro flutter.widgets.navigator.onPopInvoked} + /// + /// {@tool dartpad} + /// This sample demonstrates how to use this parameter to show a confirmation + /// dialog when a navigation pop would cause form data to be lost. + /// + /// ** See code in examples/api/lib/widgets/form/form.1.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [canPop], which also comes from [PopScope] and is often used in + /// conjunction with this parameter. + /// * [PopScope.onPopInvoked], which is what [Form] delegates to internally. + final PopInvokedCallback? onPopInvoked; + + /// Called when one of the form fields changes. + /// + /// In addition to this callback being invoked, all the form fields themselves + /// will rebuild. + final VoidCallback? onChanged; + + /// Used to enable/disable form fields auto validation and update their error + /// text. + /// + /// {@macro flutter.widgets.FormField.autovalidateMode} + final AutovalidateMode autovalidateMode; + + @override + FormState createState() => FormState(); +} + +/// State associated with a [Form] widget. +/// +/// A [FormState] object can be used to [save], [reset], and [validate] every +/// [FormField] that is a descendant of the associated [Form]. +/// +/// Typically obtained via [Form.of]. +class FormState extends State<Form> { + int _generation = 0; + bool _hasInteractedByUser = false; + final Set<FormFieldState<dynamic>> _fields = <FormFieldState<dynamic>>{}; + + // Called when a form field has changed. This will cause all form fields + // to rebuild, useful if form fields have interdependencies. + void _fieldDidChange() { + widget.onChanged?.call(); + + _hasInteractedByUser = _fields + .any((FormFieldState<dynamic> field) => field._hasInteractedByUser.value); + _forceRebuild(); + } + + void _forceRebuild() { + setState(() { + ++_generation; + }); + } + + void _register(FormFieldState<dynamic> field) { + _fields.add(field); + } + + void _unregister(FormFieldState<dynamic> field) { + _fields.remove(field); + } + + @override + Widget build(BuildContext context) { + switch (widget.autovalidateMode) { + case AutovalidateMode.always: + _validate(); + case AutovalidateMode.onUserInteraction: + if (_hasInteractedByUser) { + _validate(); + } + case AutovalidateMode.disabled: + break; + } + + if (widget.canPop != null || widget.onPopInvoked != null) { + return PopScope( + canPop: widget.canPop ?? true, + onPopInvoked: widget.onPopInvoked, + child: _FormScope( + formState: this, + generation: _generation, + child: widget.child, + ), + ); + } + + return WillPopScope( + onWillPop: widget.onWillPop, + child: _FormScope( + formState: this, + generation: _generation, + child: widget.child, + ), + ); + } + + /// Saves every [FormField] that is a descendant of this [Form]. + void save() { + for (final FormFieldState<dynamic> field in _fields) { + field.save(); + } + } + + /// Resets every [FormField] that is a descendant of this [Form] back to its + /// [FormField.initialValue]. + /// + /// The [Form.onChanged] callback will be called. + /// + /// If the form's [Form.autovalidateMode] property is [AutovalidateMode.always], + /// the fields will all be revalidated after being reset. + void reset() { + for (final FormFieldState<dynamic> field in _fields) { + field.reset(); + } + _hasInteractedByUser = false; + _fieldDidChange(); + } + + /// Validates every [FormField] that is a descendant of this [Form], and + /// returns true if there are no errors. + /// + /// The form will rebuild to report the results. + bool validate() { + _hasInteractedByUser = true; + _forceRebuild(); + return _validate(); + } + + bool _validate() { + bool hasError = false; + String errorMessage = ''; + for (final FormFieldState<dynamic> field in _fields) { + hasError = !field.validate() || hasError; + errorMessage += field.errorText ?? ''; + } + + if (errorMessage.isNotEmpty) { + final TextDirection directionality = Directionality.of(context); + if (defaultTargetPlatform == TargetPlatform.iOS) { + unawaited(Future<void>(() async { + await Future<void>.delayed(_kIOSAnnouncementDelayDuration); + SemanticsService.announce(errorMessage, directionality, assertiveness: Assertiveness.assertive); + })); + } else { + SemanticsService.announce(errorMessage, directionality, assertiveness: Assertiveness.assertive); + } + } + return !hasError; + } +} + +class _FormScope extends InheritedWidget { + const _FormScope({ + required super.child, + required FormState formState, + required int generation, + }) : _formState = formState, + _generation = generation; + + final FormState _formState; + + /// Incremented every time a form field has changed. This lets us know when + /// to rebuild the form. + final int _generation; + + /// The [Form] associated with this widget. + Form get form => _formState.widget; + + @override + bool updateShouldNotify(_FormScope old) => _generation != old._generation; +} + +/// Signature for validating a form field. +/// +/// Returns an error string to display if the input is invalid, or null +/// otherwise. +/// +/// Used by [FormField.validator]. +typedef FormFieldValidator<T> = String? Function(T? value); + +/// Signature for being notified when a form field changes value. +/// +/// Used by [FormField.onSaved]. +typedef FormFieldSetter<T> = void Function(T? newValue); + +/// Signature for building the widget representing the form field. +/// +/// Used by [FormField.builder]. +typedef FormFieldBuilder<T> = Widget Function(FormFieldState<T> field); + +/// A single form field. +/// +/// This widget maintains the current state of the form field, so that updates +/// and validation errors are visually reflected in the UI. +/// +/// When used inside a [Form], you can use methods on [FormState] to query or +/// manipulate the form data as a whole. For example, calling [FormState.save] +/// will invoke each [FormField]'s [onSaved] callback in turn. +/// +/// Use a [GlobalKey] with [FormField] if you want to retrieve its current +/// state, for example if you want one form field to depend on another. +/// +/// A [Form] ancestor is not required. The [Form] allows one to +/// save, reset, or validate multiple fields at once. To use without a [Form], +/// pass a [GlobalKey] to the constructor and use [GlobalKey.currentState] to +/// save or reset the form field. +/// +/// See also: +/// +/// * [Form], which is the widget that aggregates the form fields. +/// * [TextField], which is a commonly used form field for entering text. +class FormField<T> extends StatefulWidget { + /// Creates a single form field. + const FormField({ + super.key, + required this.builder, + this.onSaved, + this.validator, + this.initialValue, + this.enabled = true, + AutovalidateMode? autovalidateMode, + this.restorationId, + }) : autovalidateMode = autovalidateMode ?? AutovalidateMode.disabled; + + /// An optional method to call with the final value when the form is saved via + /// [FormState.save]. + final FormFieldSetter<T>? onSaved; + + /// An optional method that validates an input. Returns an error string to + /// display if the input is invalid, or null otherwise. + /// + /// The returned value is exposed by the [FormFieldState.errorText] property. + /// The [TextFormField] uses this to override the [InputDecoration.errorText] + /// value. + /// + /// Alternating between error and normal state can cause the height of the + /// [TextFormField] to change if no other subtext decoration is set on the + /// field. To create a field whose height is fixed regardless of whether or + /// not an error is displayed, either wrap the [TextFormField] in a fixed + /// height parent like [SizedBox], or set the [InputDecoration.helperText] + /// parameter to a space. + final FormFieldValidator<T>? validator; + + /// Function that returns the widget representing this form field. It is + /// passed the form field state as input, containing the current value and + /// validation state of this field. + final FormFieldBuilder<T> builder; + + /// An optional value to initialize the form field to, or null otherwise. + final T? initialValue; + + /// Whether the form is able to receive user input. + /// + /// Defaults to true. If [autovalidateMode] is not [AutovalidateMode.disabled], + /// the field will be auto validated. Likewise, if this field is false, the widget + /// will not be validated regardless of [autovalidateMode]. + final bool enabled; + + /// Used to enable/disable this form field auto validation and update its + /// error text. + /// + /// {@template flutter.widgets.FormField.autovalidateMode} + /// If [AutovalidateMode.onUserInteraction], this FormField will only + /// auto-validate after its content changes. If [AutovalidateMode.always], it + /// will auto-validate even without user interaction. If + /// [AutovalidateMode.disabled], auto-validation will be disabled. + /// + /// Defaults to [AutovalidateMode.disabled]. + /// {@endtemplate} + final AutovalidateMode autovalidateMode; + + /// Restoration ID to save and restore the state of the form field. + /// + /// Setting the restoration ID to a non-null value results in whether or not + /// the form field validation persists. + /// + /// The state of this widget is persisted in a [RestorationBucket] claimed + /// from the surrounding [RestorationScope] using the provided restoration ID. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + final String? restorationId; + + @override + FormFieldState<T> createState() => FormFieldState<T>(); +} + +/// The current state of a [FormField]. Passed to the [FormFieldBuilder] method +/// for use in constructing the form field's widget. +class FormFieldState<T> extends State<FormField<T>> with RestorationMixin { + late T? _value = widget.initialValue; + final RestorableStringN _errorText = RestorableStringN(null); + final RestorableBool _hasInteractedByUser = RestorableBool(false); + + /// The current value of the form field. + T? get value => _value; + + /// The current validation error returned by the [FormField.validator] + /// callback, or null if no errors have been triggered. This only updates when + /// [validate] is called. + String? get errorText => _errorText.value; + + /// True if this field has any validation errors. + bool get hasError => _errorText.value != null; + + /// Returns true if the user has modified the value of this field. + /// + /// This only updates to true once [didChange] has been called and resets to + /// false when [reset] is called. + bool get hasInteractedByUser => _hasInteractedByUser.value; + + /// True if the current value is valid. + /// + /// This will not set [errorText] or [hasError] and it will not update + /// error display. + /// + /// See also: + /// + /// * [validate], which may update [errorText] and [hasError]. + bool get isValid => widget.validator?.call(_value) == null; + + /// Calls the [FormField]'s onSaved method with the current value. + void save() { + widget.onSaved?.call(value); + } + + /// Resets the field to its initial value. + void reset() { + setState(() { + _value = widget.initialValue; + _hasInteractedByUser.value = false; + _errorText.value = null; + }); + Form.maybeOf(context)?._fieldDidChange(); + } + + /// Calls [FormField.validator] to set the [errorText]. Returns true if there + /// were no errors. + /// + /// See also: + /// + /// * [isValid], which passively gets the validity without setting + /// [errorText] or [hasError]. + bool validate() { + setState(() { + _validate(); + }); + return !hasError; + } + + void _validate() { + if (widget.validator != null) { + _errorText.value = widget.validator!(_value); + } else { + _errorText.value = null; + } + } + + /// Updates this field's state to the new value. Useful for responding to + /// child widget changes, e.g. [Slider]'s [Slider.onChanged] argument. + /// + /// Triggers the [Form.onChanged] callback and, if [Form.autovalidateMode] is + /// [AutovalidateMode.always] or [AutovalidateMode.onUserInteraction], + /// revalidates all the fields of the form. + void didChange(T? value) { + setState(() { + _value = value; + _hasInteractedByUser.value = true; + }); + Form.maybeOf(context)?._fieldDidChange(); + } + + /// Sets the value associated with this form field. + /// + /// This method should only be called by subclasses that need to update + /// the form field value due to state changes identified during the widget + /// build phase, when calling `setState` is prohibited. In all other cases, + /// the value should be set by a call to [didChange], which ensures that + /// `setState` is called. + @protected + // ignore: use_setters_to_change_properties, (API predates enforcing the lint) + void setValue(T? value) { + _value = value; + } + + @override + String? get restorationId => widget.restorationId; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_errorText, 'error_text'); + registerForRestoration(_hasInteractedByUser, 'has_interacted_by_user'); + } + + @override + void deactivate() { + Form.maybeOf(context)?._unregister(this); + super.deactivate(); + } + + @override + void dispose() { + _errorText.dispose(); + _hasInteractedByUser.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + if (widget.enabled) { + switch (widget.autovalidateMode) { + case AutovalidateMode.always: + _validate(); + case AutovalidateMode.onUserInteraction: + if (_hasInteractedByUser.value) { + _validate(); + } + case AutovalidateMode.disabled: + break; + } + } + Form.maybeOf(context)?._register(this); + return widget.builder(this); + } +} + +/// Used to configure the auto validation of [FormField] and [Form] widgets. +enum AutovalidateMode { + /// No auto validation will occur. + disabled, + + /// Used to auto-validate [Form] and [FormField] even without user interaction. + always, + + /// Used to auto-validate [Form] and [FormField] only after each user + /// interaction. + onUserInteraction, +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/framework.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/framework.dart new file mode 100644 index 0000000000000000000000000000000000000000..2e2c711310f16e8dfcada7fe682120bc446f6ebd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/framework.dart @@ -0,0 +1,7071 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:collection'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'binding.dart'; +import 'debug.dart'; +import 'focus_manager.dart'; +import 'inherited_model.dart'; +import 'notification_listener.dart'; +import 'widget_inspector.dart'; + +export 'package:flutter/foundation.dart' show + factory, + immutable, + mustCallSuper, + optionalTypeArgs, + protected, + required, + visibleForTesting; +export 'package:flutter/foundation.dart' show ErrorDescription, ErrorHint, ErrorSummary, FlutterError, debugPrint, debugPrintStack; +export 'package:flutter/foundation.dart' show ValueChanged, ValueGetter, ValueSetter, VoidCallback; +export 'package:flutter/foundation.dart' show DiagnosticLevel, DiagnosticsNode; +export 'package:flutter/foundation.dart' show Key, LocalKey, ValueKey; +export 'package:flutter/rendering.dart' show RenderBox, RenderObject, debugDumpLayerTree, debugDumpRenderTree; + +// Examples can assume: +// late BuildContext context; +// void setState(VoidCallback fn) { } +// abstract class RenderFrogJar extends RenderObject { } +// abstract class FrogJar extends RenderObjectWidget { const FrogJar({super.key}); } +// abstract class FrogJarParentData extends ParentData { late Size size; } +// abstract class SomeWidget extends StatefulWidget { const SomeWidget({super.key}); } +// typedef ChildWidget = Placeholder; +// class _SomeWidgetState extends State<SomeWidget> { @override Widget build(BuildContext context) => widget; } +// abstract class RenderFoo extends RenderObject { } +// abstract class Foo extends RenderObjectWidget { const Foo({super.key}); } +// abstract class StatefulWidgetX { const StatefulWidgetX({this.key}); final Key? key; Widget build(BuildContext context, State state); } +// class SpecialWidget extends StatelessWidget { const SpecialWidget({ super.key, this.handler }); final VoidCallback? handler; @override Widget build(BuildContext context) => this; } +// late Object? _myState, newValue; +// int _counter = 0; +// Future<Directory> getApplicationDocumentsDirectory() async => Directory(''); +// late AnimationController animation; + +// An annotation used by test_analysis package to verify patterns are followed +// that allow for tree-shaking of both fields and their initializers. This +// annotation has no impact on code by itself, but indicates the following pattern +// should be followed for a given field: +// +// ```dart +// class Foo { +// final bar = kDebugMode ? Object() : null; +// } +// ``` +class _DebugOnly { + const _DebugOnly(); +} + +const _DebugOnly _debugOnly = _DebugOnly(); + +// KEYS + +/// A key that takes its identity from the object used as its value. +/// +/// Used to tie the identity of a widget to the identity of an object used to +/// generate that widget. +/// +/// See also: +/// +/// * [Key], the base class for all keys. +/// * The discussion at [Widget.key] for more information about how widgets use +/// keys. +class ObjectKey extends LocalKey { + /// Creates a key that uses [identical] on [value] for its [operator==]. + const ObjectKey(this.value); + + /// The object whose identity is used by this key's [operator==]. + final Object? value; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is ObjectKey + && identical(other.value, value); + } + + @override + int get hashCode => Object.hash(runtimeType, identityHashCode(value)); + + @override + String toString() { + if (runtimeType == ObjectKey) { + return '[${describeIdentity(value)}]'; + } + return '[${objectRuntimeType(this, 'ObjectKey')} ${describeIdentity(value)}]'; + } +} + +/// A key that is unique across the entire app. +/// +/// Global keys uniquely identify elements. Global keys provide access to other +/// objects that are associated with those elements, such as [BuildContext]. +/// For [StatefulWidget]s, global keys also provide access to [State]. +/// +/// Widgets that have global keys reparent their subtrees when they are moved +/// from one location in the tree to another location in the tree. In order to +/// reparent its subtree, a widget must arrive at its new location in the tree +/// in the same animation frame in which it was removed from its old location in +/// the tree. +/// +/// Reparenting an [Element] using a global key is relatively expensive, as +/// this operation will trigger a call to [State.deactivate] on the associated +/// [State] and all of its descendants; then force all widgets that depends +/// on an [InheritedWidget] to rebuild. +/// +/// If you don't need any of the features listed above, consider using a [Key], +/// [ValueKey], [ObjectKey], or [UniqueKey] instead. +/// +/// You cannot simultaneously include two widgets in the tree with the same +/// global key. Attempting to do so will assert at runtime. +/// +/// ## Pitfalls +/// +/// GlobalKeys should not be re-created on every build. They should usually be +/// long-lived objects owned by a [State] object, for example. +/// +/// Creating a new GlobalKey on every build will throw away the state of the +/// subtree associated with the old key and create a new fresh subtree for the +/// new key. Besides harming performance, this can also cause unexpected +/// behavior in widgets in the subtree. For example, a [GestureDetector] in the +/// subtree will be unable to track ongoing gestures since it will be recreated +/// on each build. +/// +/// Instead, a good practice is to let a State object own the GlobalKey, and +/// instantiate it outside the build method, such as in [State.initState]. +/// +/// See also: +/// +/// * The discussion at [Widget.key] for more information about how widgets use +/// keys. +@optionalTypeArgs +abstract class GlobalKey<T extends State<StatefulWidget>> extends Key { + /// Creates a [LabeledGlobalKey], which is a [GlobalKey] with a label used for + /// debugging. + /// + /// The label is purely for debugging and not used for comparing the identity + /// of the key. + factory GlobalKey({ String? debugLabel }) => LabeledGlobalKey<T>(debugLabel); + + /// Creates a global key without a label. + /// + /// Used by subclasses because the factory constructor shadows the implicit + /// constructor. + const GlobalKey.constructor() : super.empty(); + + Element? get _currentElement => WidgetsBinding.instance.buildOwner!._globalKeyRegistry[this]; + + /// The build context in which the widget with this key builds. + /// + /// The current context is null if there is no widget in the tree that matches + /// this global key. + BuildContext? get currentContext => _currentElement; + + /// The widget in the tree that currently has this global key. + /// + /// The current widget is null if there is no widget in the tree that matches + /// this global key. + Widget? get currentWidget => _currentElement?.widget; + + /// The [State] for the widget in the tree that currently has this global key. + /// + /// The current state is null if (1) there is no widget in the tree that + /// matches this global key, (2) that widget is not a [StatefulWidget], or the + /// associated [State] object is not a subtype of `T`. + T? get currentState { + final Element? element = _currentElement; + if (element is StatefulElement) { + final StatefulElement statefulElement = element; + final State state = statefulElement.state; + if (state is T) { + return state; + } + } + return null; + } +} + +/// A global key with a debugging label. +/// +/// The debug label is useful for documentation and for debugging. The label +/// does not affect the key's identity. +@optionalTypeArgs +class LabeledGlobalKey<T extends State<StatefulWidget>> extends GlobalKey<T> { + /// Creates a global key with a debugging label. + /// + /// The label does not affect the key's identity. + // ignore: prefer_const_constructors_in_immutables , never use const for this class + LabeledGlobalKey(this._debugLabel) : super.constructor(); + + final String? _debugLabel; + + @override + String toString() { + final String label = _debugLabel != null ? ' $_debugLabel' : ''; + if (runtimeType == LabeledGlobalKey) { + return '[GlobalKey#${shortHash(this)}$label]'; + } + return '[${describeIdentity(this)}$label]'; + } +} + +/// A global key that takes its identity from the object used as its value. +/// +/// Used to tie the identity of a widget to the identity of an object used to +/// generate that widget. +/// +/// Any [GlobalObjectKey] created for the same object will match. +/// +/// If the object is not private, then it is possible that collisions will occur +/// where independent widgets will reuse the same object as their +/// [GlobalObjectKey] value in a different part of the tree, leading to a global +/// key conflict. To avoid this problem, create a private [GlobalObjectKey] +/// subclass, as in: +/// +/// ```dart +/// class _MyKey extends GlobalObjectKey { +/// const _MyKey(super.value); +/// } +/// ``` +/// +/// Since the [runtimeType] of the key is part of its identity, this will +/// prevent clashes with other [GlobalObjectKey]s even if they have the same +/// value. +@optionalTypeArgs +class GlobalObjectKey<T extends State<StatefulWidget>> extends GlobalKey<T> { + /// Creates a global key that uses [identical] on [value] for its [operator==]. + const GlobalObjectKey(this.value) : super.constructor(); + + /// The object whose identity is used by this key's [operator==]. + final Object value; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is GlobalObjectKey<T> + && identical(other.value, value); + } + + @override + int get hashCode => identityHashCode(value); + + @override + String toString() { + String selfType = objectRuntimeType(this, 'GlobalObjectKey'); + // The runtimeType string of a GlobalObjectKey() returns 'GlobalObjectKey<State<StatefulWidget>>' + // because GlobalObjectKey is instantiated to its bounds. To avoid cluttering the output + // we remove the suffix. + const String suffix = '<State<StatefulWidget>>'; + if (selfType.endsWith(suffix)) { + selfType = selfType.substring(0, selfType.length - suffix.length); + } + return '[$selfType ${describeIdentity(value)}]'; + } +} + +/// Describes the configuration for an [Element]. +/// +/// Widgets are the central class hierarchy in the Flutter framework. A widget +/// is an immutable description of part of a user interface. Widgets can be +/// inflated into elements, which manage the underlying render tree. +/// +/// Widgets themselves have no mutable state (all their fields must be final). +/// If you wish to associate mutable state with a widget, consider using a +/// [StatefulWidget], which creates a [State] object (via +/// [StatefulWidget.createState]) whenever it is inflated into an element and +/// incorporated into the tree. +/// +/// A given widget can be included in the tree zero or more times. In particular +/// a given widget can be placed in the tree multiple times. Each time a widget +/// is placed in the tree, it is inflated into an [Element], which means a +/// widget that is incorporated into the tree multiple times will be inflated +/// multiple times. +/// +/// The [key] property controls how one widget replaces another widget in the +/// tree. If the [runtimeType] and [key] properties of the two widgets are +/// [operator==], respectively, then the new widget replaces the old widget by +/// updating the underlying element (i.e., by calling [Element.update] with the +/// new widget). Otherwise, the old element is removed from the tree, the new +/// widget is inflated into an element, and the new element is inserted into the +/// tree. +/// +/// See also: +/// +/// * [StatefulWidget] and [State], for widgets that can build differently +/// several times over their lifetime. +/// * [InheritedWidget], for widgets that introduce ambient state that can +/// be read by descendant widgets. +/// * [StatelessWidget], for widgets that always build the same way given a +/// particular configuration and ambient state. +@immutable +abstract class Widget extends DiagnosticableTree { + /// Initializes [key] for subclasses. + const Widget({ this.key }); + + /// Controls how one widget replaces another widget in the tree. + /// + /// If the [runtimeType] and [key] properties of the two widgets are + /// [operator==], respectively, then the new widget replaces the old widget by + /// updating the underlying element (i.e., by calling [Element.update] with the + /// new widget). Otherwise, the old element is removed from the tree, the new + /// widget is inflated into an element, and the new element is inserted into the + /// tree. + /// + /// In addition, using a [GlobalKey] as the widget's [key] allows the element + /// to be moved around the tree (changing parent) without losing state. When a + /// new widget is found (its key and type do not match a previous widget in + /// the same location), but there was a widget with that same global key + /// elsewhere in the tree in the previous frame, then that widget's element is + /// moved to the new location. + /// + /// Generally, a widget that is the only child of another widget does not need + /// an explicit key. + /// + /// See also: + /// + /// * The discussions at [Key] and [GlobalKey]. + final Key? key; + + /// Inflates this configuration to a concrete instance. + /// + /// A given widget can be included in the tree zero or more times. In particular + /// a given widget can be placed in the tree multiple times. Each time a widget + /// is placed in the tree, it is inflated into an [Element], which means a + /// widget that is incorporated into the tree multiple times will be inflated + /// multiple times. + @protected + @factory + Element createElement(); + + /// A short, textual description of this widget. + @override + String toStringShort() { + final String type = objectRuntimeType(this, 'Widget'); + return key == null ? type : '$type-$key'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.defaultDiagnosticsTreeStyle = DiagnosticsTreeStyle.dense; + } + + @override + @nonVirtual + bool operator ==(Object other) => super == other; + + @override + @nonVirtual + int get hashCode => super.hashCode; + + /// Whether the `newWidget` can be used to update an [Element] that currently + /// has the `oldWidget` as its configuration. + /// + /// An element that uses a given widget as its configuration can be updated to + /// use another widget as its configuration if, and only if, the two widgets + /// have [runtimeType] and [key] properties that are [operator==]. + /// + /// If the widgets have no key (their key is null), then they are considered a + /// match if they have the same type, even if their children are completely + /// different. + static bool canUpdate(Widget oldWidget, Widget newWidget) { + return oldWidget.runtimeType == newWidget.runtimeType + && oldWidget.key == newWidget.key; + } + + // Return a numeric encoding of the specific `Widget` concrete subtype. + // This is used in `Element.updateChild` to determine if a hot reload modified the + // superclass of a mounted element's configuration. The encoding of each `Widget` + // must match the corresponding `Element` encoding in `Element._debugConcreteSubtype`. + static int _debugConcreteSubtype(Widget widget) { + return widget is StatefulWidget ? 1 : + widget is StatelessWidget ? 2 : + 0; + } +} + +/// A widget that does not require mutable state. +/// +/// A stateless widget is a widget that describes part of the user interface by +/// building a constellation of other widgets that describe the user interface +/// more concretely. The building process continues recursively until the +/// description of the user interface is fully concrete (e.g., consists +/// entirely of [RenderObjectWidget]s, which describe concrete [RenderObject]s). +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=wE7khGHVkYY} +/// +/// Stateless widget are useful when the part of the user interface you are +/// describing does not depend on anything other than the configuration +/// information in the object itself and the [BuildContext] in which the widget +/// is inflated. For compositions that can change dynamically, e.g. due to +/// having an internal clock-driven state, or depending on some system state, +/// consider using [StatefulWidget]. +/// +/// ## Performance considerations +/// +/// The [build] method of a stateless widget is typically only called in three +/// situations: the first time the widget is inserted in the tree, when the +/// widget's parent changes its configuration (see [Element.rebuild]), and when +/// an [InheritedWidget] it depends on changes. +/// +/// If a widget's parent will regularly change the widget's configuration, or if +/// it depends on inherited widgets that frequently change, then it is important +/// to optimize the performance of the [build] method to maintain a fluid +/// rendering performance. +/// +/// There are several techniques one can use to minimize the impact of +/// rebuilding a stateless widget: +/// +/// * Minimize the number of nodes transitively created by the build method and +/// any widgets it creates. For example, instead of an elaborate arrangement +/// of [Row]s, [Column]s, [Padding]s, and [SizedBox]es to position a single +/// child in a particularly fancy manner, consider using just an [Align] or a +/// [CustomSingleChildLayout]. Instead of an intricate layering of multiple +/// [Container]s and with [Decoration]s to draw just the right graphical +/// effect, consider a single [CustomPaint] widget. +/// +/// * Use `const` widgets where possible, and provide a `const` constructor for +/// the widget so that users of the widget can also do so. +/// +/// * Consider refactoring the stateless widget into a stateful widget so that +/// it can use some of the techniques described at [StatefulWidget], such as +/// caching common parts of subtrees and using [GlobalKey]s when changing the +/// tree structure. +/// +/// * If the widget is likely to get rebuilt frequently due to the use of +/// [InheritedWidget]s, consider refactoring the stateless widget into +/// multiple widgets, with the parts of the tree that change being pushed to +/// the leaves. For example instead of building a tree with four widgets, the +/// inner-most widget depending on the [Theme], consider factoring out the +/// part of the build function that builds the inner-most widget into its own +/// widget, so that only the inner-most widget needs to be rebuilt when the +/// theme changes. +/// {@template flutter.flutter.widgets.framework.prefer_const_over_helper} +/// * When trying to create a reusable piece of UI, prefer using a widget +/// rather than a helper method. For example, if there was a function used to +/// build a widget, a [State.setState] call would require Flutter to entirely +/// rebuild the returned wrapping widget. If a [Widget] was used instead, +/// Flutter would be able to efficiently re-render only those parts that +/// really need to be updated. Even better, if the created widget is `const`, +/// Flutter would short-circuit most of the rebuild work. +/// {@endtemplate} +/// +/// This video gives more explanations on why `const` constructors are important +/// and why a [Widget] is better than a helper method. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=IOyq-eTRhvo} +/// +/// {@tool snippet} +/// +/// The following is a skeleton of a stateless widget subclass called `GreenFrog`. +/// +/// Normally, widgets have more constructor arguments, each of which corresponds +/// to a `final` property. +/// +/// ```dart +/// class GreenFrog extends StatelessWidget { +/// const GreenFrog({ super.key }); +/// +/// @override +/// Widget build(BuildContext context) { +/// return Container(color: const Color(0xFF2DBD3A)); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// +/// This next example shows the more generic widget `Frog` which can be given +/// a color and a child: +/// +/// ```dart +/// class Frog extends StatelessWidget { +/// const Frog({ +/// super.key, +/// this.color = const Color(0xFF2DBD3A), +/// this.child, +/// }); +/// +/// final Color color; +/// final Widget? child; +/// +/// @override +/// Widget build(BuildContext context) { +/// return ColoredBox(color: color, child: child); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// By convention, widget constructors only use named arguments. Also by +/// convention, the first argument is [key], and the last argument is `child`, +/// `children`, or the equivalent. +/// +/// See also: +/// +/// * [StatefulWidget] and [State], for widgets that can build differently +/// several times over their lifetime. +/// * [InheritedWidget], for widgets that introduce ambient state that can +/// be read by descendant widgets. +abstract class StatelessWidget extends Widget { + /// Initializes [key] for subclasses. + const StatelessWidget({ super.key }); + + /// Creates a [StatelessElement] to manage this widget's location in the tree. + /// + /// It is uncommon for subclasses to override this method. + @override + StatelessElement createElement() => StatelessElement(this); + + /// Describes the part of the user interface represented by this widget. + /// + /// The framework calls this method when this widget is inserted into the tree + /// in a given [BuildContext] and when the dependencies of this widget change + /// (e.g., an [InheritedWidget] referenced by this widget changes). This + /// method can potentially be called in every frame and should not have any side + /// effects beyond building a widget. + /// + /// The framework replaces the subtree below this widget with the widget + /// returned by this method, either by updating the existing subtree or by + /// removing the subtree and inflating a new subtree, depending on whether the + /// widget returned by this method can update the root of the existing + /// subtree, as determined by calling [Widget.canUpdate]. + /// + /// Typically implementations return a newly created constellation of widgets + /// that are configured with information from this widget's constructor and + /// from the given [BuildContext]. + /// + /// The given [BuildContext] contains information about the location in the + /// tree at which this widget is being built. For example, the context + /// provides the set of inherited widgets for this location in the tree. A + /// given widget might be built with multiple different [BuildContext] + /// arguments over time if the widget is moved around the tree or if the + /// widget is inserted into the tree in multiple places at once. + /// + /// The implementation of this method must only depend on: + /// + /// * the fields of the widget, which themselves must not change over time, + /// and + /// * any ambient state obtained from the `context` using + /// [BuildContext.dependOnInheritedWidgetOfExactType]. + /// + /// If a widget's [build] method is to depend on anything else, use a + /// [StatefulWidget] instead. + /// + /// See also: + /// + /// * [StatelessWidget], which contains the discussion on performance considerations. + @protected + Widget build(BuildContext context); +} + +/// A widget that has mutable state. +/// +/// State is information that (1) can be read synchronously when the widget is +/// built and (2) might change during the lifetime of the widget. It is the +/// responsibility of the widget implementer to ensure that the [State] is +/// promptly notified when such state changes, using [State.setState]. +/// +/// A stateful widget is a widget that describes part of the user interface by +/// building a constellation of other widgets that describe the user interface +/// more concretely. The building process continues recursively until the +/// description of the user interface is fully concrete (e.g., consists +/// entirely of [RenderObjectWidget]s, which describe concrete [RenderObject]s). +/// +/// Stateful widgets are useful when the part of the user interface you are +/// describing can change dynamically, e.g. due to having an internal +/// clock-driven state, or depending on some system state. For compositions that +/// depend only on the configuration information in the object itself and the +/// [BuildContext] in which the widget is inflated, consider using +/// [StatelessWidget]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=AqCMFXEmf3w} +/// +/// [StatefulWidget] instances themselves are immutable and store their mutable +/// state either in separate [State] objects that are created by the +/// [createState] method, or in objects to which that [State] subscribes, for +/// example [Stream] or [ChangeNotifier] objects, to which references are stored +/// in final fields on the [StatefulWidget] itself. +/// +/// The framework calls [createState] whenever it inflates a +/// [StatefulWidget], which means that multiple [State] objects might be +/// associated with the same [StatefulWidget] if that widget has been inserted +/// into the tree in multiple places. Similarly, if a [StatefulWidget] is +/// removed from the tree and later inserted in to the tree again, the framework +/// will call [createState] again to create a fresh [State] object, simplifying +/// the lifecycle of [State] objects. +/// +/// A [StatefulWidget] keeps the same [State] object when moving from one +/// location in the tree to another if its creator used a [GlobalKey] for its +/// [key]. Because a widget with a [GlobalKey] can be used in at most one +/// location in the tree, a widget that uses a [GlobalKey] has at most one +/// associated element. The framework takes advantage of this property when +/// moving a widget with a global key from one location in the tree to another +/// by grafting the (unique) subtree associated with that widget from the old +/// location to the new location (instead of recreating the subtree at the new +/// location). The [State] objects associated with [StatefulWidget] are grafted +/// along with the rest of the subtree, which means the [State] object is reused +/// (instead of being recreated) in the new location. However, in order to be +/// eligible for grafting, the widget must be inserted into the new location in +/// the same animation frame in which it was removed from the old location. +/// +/// ## Performance considerations +/// +/// There are two primary categories of [StatefulWidget]s. +/// +/// The first is one which allocates resources in [State.initState] and disposes +/// of them in [State.dispose], but which does not depend on [InheritedWidget]s +/// or call [State.setState]. Such widgets are commonly used at the root of an +/// application or page, and communicate with subwidgets via [ChangeNotifier]s, +/// [Stream]s, or other such objects. Stateful widgets following such a pattern +/// are relatively cheap (in terms of CPU and GPU cycles), because they are +/// built once then never update. They can, therefore, have somewhat complicated +/// and deep build methods. +/// +/// The second category is widgets that use [State.setState] or depend on +/// [InheritedWidget]s. These will typically rebuild many times during the +/// application's lifetime, and it is therefore important to minimize the impact +/// of rebuilding such a widget. (They may also use [State.initState] or +/// [State.didChangeDependencies] and allocate resources, but the important part +/// is that they rebuild.) +/// +/// There are several techniques one can use to minimize the impact of +/// rebuilding a stateful widget: +/// +/// * Push the state to the leaves. For example, if your page has a ticking +/// clock, rather than putting the state at the top of the page and +/// rebuilding the entire page each time the clock ticks, create a dedicated +/// clock widget that only updates itself. +/// +/// * Minimize the number of nodes transitively created by the build method and +/// any widgets it creates. Ideally, a stateful widget would only create a +/// single widget, and that widget would be a [RenderObjectWidget]. +/// (Obviously this isn't always practical, but the closer a widget gets to +/// this ideal, the more efficient it will be.) +/// +/// * If a subtree does not change, cache the widget that represents that +/// subtree and re-use it each time it can be used. To do this, assign +/// a widget to a `final` state variable and re-use it in the build method. It +/// is massively more efficient for a widget to be re-used than for a new (but +/// identically-configured) widget to be created. Another caching strategy +/// consists in extracting the mutable part of the widget into a [StatefulWidget] +/// which accepts a child parameter. +/// +/// * Use `const` widgets where possible. (This is equivalent to caching a +/// widget and re-using it.) +/// +/// * Avoid changing the depth of any created subtrees or changing the type of +/// any widgets in the subtree. For example, rather than returning either the +/// child or the child wrapped in an [IgnorePointer], always wrap the child +/// widget in an [IgnorePointer] and control the [IgnorePointer.ignoring] +/// property. This is because changing the depth of the subtree requires +/// rebuilding, laying out, and painting the entire subtree, whereas just +/// changing the property will require the least possible change to the +/// render tree (in the case of [IgnorePointer], for example, no layout or +/// repaint is necessary at all). +/// +/// * If the depth must be changed for some reason, consider wrapping the +/// common parts of the subtrees in widgets that have a [GlobalKey] that +/// remains consistent for the life of the stateful widget. (The +/// [KeyedSubtree] widget may be useful for this purpose if no other widget +/// can conveniently be assigned the key.) +/// +/// {@macro flutter.flutter.widgets.framework.prefer_const_over_helper} +/// +/// This video gives more explanations on why `const` constructors are important +/// and why a [Widget] is better than a helper method. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=IOyq-eTRhvo} +/// +/// For more details on the mechanics of rebuilding a widget, see +/// the discussion at [Element.rebuild]. +/// +/// {@tool snippet} +/// +/// This is a skeleton of a stateful widget subclass called `YellowBird`. +/// +/// In this example, the [State] has no actual state. State is normally +/// represented as private member fields. Also, normally widgets have more +/// constructor arguments, each of which corresponds to a `final` property. +/// +/// ```dart +/// class YellowBird extends StatefulWidget { +/// const YellowBird({ super.key }); +/// +/// @override +/// State<YellowBird> createState() => _YellowBirdState(); +/// } +/// +/// class _YellowBirdState extends State<YellowBird> { +/// @override +/// Widget build(BuildContext context) { +/// return Container(color: const Color(0xFFFFE306)); +/// } +/// } +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// This example shows the more generic widget `Bird` which can be given a +/// color and a child, and which has some internal state with a method that +/// can be called to mutate it: +/// +/// ```dart +/// class Bird extends StatefulWidget { +/// const Bird({ +/// super.key, +/// this.color = const Color(0xFFFFE306), +/// this.child, +/// }); +/// +/// final Color color; +/// final Widget? child; +/// +/// @override +/// State<Bird> createState() => _BirdState(); +/// } +/// +/// class _BirdState extends State<Bird> { +/// double _size = 1.0; +/// +/// void grow() { +/// setState(() { _size += 0.1; }); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return Container( +/// color: widget.color, +/// transform: Matrix4.diagonal3Values(_size, _size, 1.0), +/// child: widget.child, +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// By convention, widget constructors only use named arguments. Also by +/// convention, the first argument is [key], and the last argument is `child`, +/// `children`, or the equivalent. +/// +/// See also: +/// +/// * [State], where the logic behind a [StatefulWidget] is hosted. +/// * [StatelessWidget], for widgets that always build the same way given a +/// particular configuration and ambient state. +/// * [InheritedWidget], for widgets that introduce ambient state that can +/// be read by descendant widgets. +abstract class StatefulWidget extends Widget { + /// Initializes [key] for subclasses. + const StatefulWidget({ super.key }); + + /// Creates a [StatefulElement] to manage this widget's location in the tree. + /// + /// It is uncommon for subclasses to override this method. + @override + StatefulElement createElement() => StatefulElement(this); + + /// Creates the mutable state for this widget at a given location in the tree. + /// + /// Subclasses should override this method to return a newly created + /// instance of their associated [State] subclass: + /// + /// ```dart + /// @override + /// State<SomeWidget> createState() => _SomeWidgetState(); + /// ``` + /// + /// The framework can call this method multiple times over the lifetime of + /// a [StatefulWidget]. For example, if the widget is inserted into the tree + /// in multiple locations, the framework will create a separate [State] object + /// for each location. Similarly, if the widget is removed from the tree and + /// later inserted into the tree again, the framework will call [createState] + /// again to create a fresh [State] object, simplifying the lifecycle of + /// [State] objects. + @protected + @factory + State createState(); +} + +/// Tracks the lifecycle of [State] objects when asserts are enabled. +enum _StateLifecycle { + /// The [State] object has been created. [State.initState] is called at this + /// time. + created, + + /// The [State.initState] method has been called but the [State] object is + /// not yet ready to build. [State.didChangeDependencies] is called at this time. + initialized, + + /// The [State] object is ready to build and [State.dispose] has not yet been + /// called. + ready, + + /// The [State.dispose] method has been called and the [State] object is + /// no longer able to build. + defunct, +} + +/// The signature of [State.setState] functions. +typedef StateSetter = void Function(VoidCallback fn); + +const String _flutterWidgetsLibrary = 'package:flutter/widgets.dart'; + +/// The logic and internal state for a [StatefulWidget]. +/// +/// State is information that (1) can be read synchronously when the widget is +/// built and (2) might change during the lifetime of the widget. It is the +/// responsibility of the widget implementer to ensure that the [State] is +/// promptly notified when such state changes, using [State.setState]. +/// +/// [State] objects are created by the framework by calling the +/// [StatefulWidget.createState] method when inflating a [StatefulWidget] to +/// insert it into the tree. Because a given [StatefulWidget] instance can be +/// inflated multiple times (e.g., the widget is incorporated into the tree in +/// multiple places at once), there might be more than one [State] object +/// associated with a given [StatefulWidget] instance. Similarly, if a +/// [StatefulWidget] is removed from the tree and later inserted in to the tree +/// again, the framework will call [StatefulWidget.createState] again to create +/// a fresh [State] object, simplifying the lifecycle of [State] objects. +/// +/// [State] objects have the following lifecycle: +/// +/// * The framework creates a [State] object by calling +/// [StatefulWidget.createState]. +/// * The newly created [State] object is associated with a [BuildContext]. +/// This association is permanent: the [State] object will never change its +/// [BuildContext]. However, the [BuildContext] itself can be moved around +/// the tree along with its subtree. At this point, the [State] object is +/// considered [mounted]. +/// * The framework calls [initState]. Subclasses of [State] should override +/// [initState] to perform one-time initialization that depends on the +/// [BuildContext] or the widget, which are available as the [context] and +/// [widget] properties, respectively, when the [initState] method is +/// called. +/// * The framework calls [didChangeDependencies]. Subclasses of [State] should +/// override [didChangeDependencies] to perform initialization involving +/// [InheritedWidget]s. If [BuildContext.dependOnInheritedWidgetOfExactType] is +/// called, the [didChangeDependencies] method will be called again if the +/// inherited widgets subsequently change or if the widget moves in the tree. +/// * At this point, the [State] object is fully initialized and the framework +/// might call its [build] method any number of times to obtain a +/// description of the user interface for this subtree. [State] objects can +/// spontaneously request to rebuild their subtree by calling their +/// [setState] method, which indicates that some of their internal state +/// has changed in a way that might impact the user interface in this +/// subtree. +/// * During this time, a parent widget might rebuild and request that this +/// location in the tree update to display a new widget with the same +/// [runtimeType] and [Widget.key]. When this happens, the framework will +/// update the [widget] property to refer to the new widget and then call the +/// [didUpdateWidget] method with the previous widget as an argument. [State] +/// objects should override [didUpdateWidget] to respond to changes in their +/// associated widget (e.g., to start implicit animations). The framework +/// always calls [build] after calling [didUpdateWidget], which means any +/// calls to [setState] in [didUpdateWidget] are redundant. (See also the +/// discussion at [Element.rebuild].) +/// * During development, if a hot reload occurs (whether initiated from the +/// command line `flutter` tool by pressing `r`, or from an IDE), the +/// [reassemble] method is called. This provides an opportunity to +/// reinitialize any data that was prepared in the [initState] method. +/// * If the subtree containing the [State] object is removed from the tree +/// (e.g., because the parent built a widget with a different [runtimeType] +/// or [Widget.key]), the framework calls the [deactivate] method. Subclasses +/// should override this method to clean up any links between this object +/// and other elements in the tree (e.g. if you have provided an ancestor +/// with a pointer to a descendant's [RenderObject]). +/// * At this point, the framework might reinsert this subtree into another +/// part of the tree. If that happens, the framework will ensure that it +/// calls [build] to give the [State] object a chance to adapt to its new +/// location in the tree. If the framework does reinsert this subtree, it +/// will do so before the end of the animation frame in which the subtree was +/// removed from the tree. For this reason, [State] objects can defer +/// releasing most resources until the framework calls their [dispose] +/// method. +/// * If the framework does not reinsert this subtree by the end of the current +/// animation frame, the framework will call [dispose], which indicates that +/// this [State] object will never build again. Subclasses should override +/// this method to release any resources retained by this object (e.g., +/// stop any active animations). +/// * After the framework calls [dispose], the [State] object is considered +/// unmounted and the [mounted] property is false. It is an error to call +/// [setState] at this point. This stage of the lifecycle is terminal: there +/// is no way to remount a [State] object that has been disposed. +/// +/// See also: +/// +/// * [StatefulWidget], where the current configuration of a [State] is hosted, +/// and whose documentation has sample code for [State]. +/// * [StatelessWidget], for widgets that always build the same way given a +/// particular configuration and ambient state. +/// * [InheritedWidget], for widgets that introduce ambient state that can +/// be read by descendant widgets. +/// * [Widget], for an overview of widgets in general. +@optionalTypeArgs +abstract class State<T extends StatefulWidget> with Diagnosticable { + /// The current configuration. + /// + /// A [State] object's configuration is the corresponding [StatefulWidget] + /// instance. This property is initialized by the framework before calling + /// [initState]. If the parent updates this location in the tree to a new + /// widget with the same [runtimeType] and [Widget.key] as the current + /// configuration, the framework will update this property to refer to the new + /// widget and then call [didUpdateWidget], passing the old configuration as + /// an argument. + T get widget => _widget!; + T? _widget; + + /// The current stage in the lifecycle for this state object. + /// + /// This field is used by the framework when asserts are enabled to verify + /// that [State] objects move through their lifecycle in an orderly fashion. + _StateLifecycle _debugLifecycleState = _StateLifecycle.created; + + /// Verifies that the [State] that was created is one that expects to be + /// created for that particular [Widget]. + bool _debugTypesAreRight(Widget widget) => widget is T; + + /// The location in the tree where this widget builds. + /// + /// The framework associates [State] objects with a [BuildContext] after + /// creating them with [StatefulWidget.createState] and before calling + /// [initState]. The association is permanent: the [State] object will never + /// change its [BuildContext]. However, the [BuildContext] itself can be moved + /// around the tree. + /// + /// After calling [dispose], the framework severs the [State] object's + /// connection with the [BuildContext]. + BuildContext get context { + assert(() { + if (_element == null) { + throw FlutterError( + 'This widget has been unmounted, so the State no longer has a context (and should be considered defunct). \n' + 'Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.', + ); + } + return true; + }()); + return _element!; + } + StatefulElement? _element; + + /// Whether this [State] object is currently in a tree. + /// + /// After creating a [State] object and before calling [initState], the + /// framework "mounts" the [State] object by associating it with a + /// [BuildContext]. The [State] object remains mounted until the framework + /// calls [dispose], after which time the framework will never ask the [State] + /// object to [build] again. + /// + /// It is an error to call [setState] unless [mounted] is true. + bool get mounted => _element != null; + + /// Called when this object is inserted into the tree. + /// + /// The framework will call this method exactly once for each [State] object + /// it creates. + /// + /// Override this method to perform initialization that depends on the + /// location at which this object was inserted into the tree (i.e., [context]) + /// or on the widget used to configure this object (i.e., [widget]). + /// + /// {@template flutter.widgets.State.initState} + /// If a [State]'s [build] method depends on an object that can itself + /// change state, for example a [ChangeNotifier] or [Stream], or some + /// other object to which one can subscribe to receive notifications, then + /// be sure to subscribe and unsubscribe properly in [initState], + /// [didUpdateWidget], and [dispose]: + /// + /// * In [initState], subscribe to the object. + /// * In [didUpdateWidget] unsubscribe from the old object and subscribe + /// to the new one if the updated widget configuration requires + /// replacing the object. + /// * In [dispose], unsubscribe from the object. + /// + /// {@endtemplate} + /// + /// You should not use [BuildContext.dependOnInheritedWidgetOfExactType] from this + /// method. However, [didChangeDependencies] will be called immediately + /// following this method, and [BuildContext.dependOnInheritedWidgetOfExactType] can + /// be used there. + /// + /// Implementations of this method should start with a call to the inherited + /// method, as in `super.initState()`. + @protected + @mustCallSuper + void initState() { + assert(_debugLifecycleState == _StateLifecycle.created); + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: _flutterWidgetsLibrary, + className: '$State', + object: this, + ); + } + } + + /// Called whenever the widget configuration changes. + /// + /// If the parent widget rebuilds and requests that this location in the tree + /// update to display a new widget with the same [runtimeType] and + /// [Widget.key], the framework will update the [widget] property of this + /// [State] object to refer to the new widget and then call this method + /// with the previous widget as an argument. + /// + /// Override this method to respond when the [widget] changes (e.g., to start + /// implicit animations). + /// + /// The framework always calls [build] after calling [didUpdateWidget], which + /// means any calls to [setState] in [didUpdateWidget] are redundant. + /// + /// {@macro flutter.widgets.State.initState} + /// + /// Implementations of this method should start with a call to the inherited + /// method, as in `super.didUpdateWidget(oldWidget)`. + /// + /// _See the discussion at [Element.rebuild] for more information on when this + /// method is called._ + @mustCallSuper + @protected + void didUpdateWidget(covariant T oldWidget) { } + + /// {@macro flutter.widgets.Element.reassemble} + /// + /// In addition to this method being invoked, it is guaranteed that the + /// [build] method will be invoked when a reassemble is signaled. Most + /// widgets therefore do not need to do anything in the [reassemble] method. + /// + /// See also: + /// + /// * [Element.reassemble] + /// * [BindingBase.reassembleApplication] + /// * [Image], which uses this to reload images. + @protected + @mustCallSuper + void reassemble() { } + + /// Notify the framework that the internal state of this object has changed. + /// + /// Whenever you change the internal state of a [State] object, make the + /// change in a function that you pass to [setState]: + /// + /// ```dart + /// setState(() { _myState = newValue; }); + /// ``` + /// + /// The provided callback is immediately called synchronously. It must not + /// return a future (the callback cannot be `async`), since then it would be + /// unclear when the state was actually being set. + /// + /// Calling [setState] notifies the framework that the internal state of this + /// object has changed in a way that might impact the user interface in this + /// subtree, which causes the framework to schedule a [build] for this [State] + /// object. + /// + /// If you just change the state directly without calling [setState], the + /// framework might not schedule a [build] and the user interface for this + /// subtree might not be updated to reflect the new state. + /// + /// Generally it is recommended that the [setState] method only be used to + /// wrap the actual changes to the state, not any computation that might be + /// associated with the change. For example, here a value used by the [build] + /// function is incremented, and then the change is written to disk, but only + /// the increment is wrapped in the [setState]: + /// + /// ```dart + /// Future<void> _incrementCounter() async { + /// setState(() { + /// _counter++; + /// }); + /// Directory directory = await getApplicationDocumentsDirectory(); // from path_provider package + /// final String dirName = directory.path; + /// await File('$dirName/counter.txt').writeAsString('$_counter'); + /// } + /// ``` + /// + /// Sometimes, the changed state is in some other object not owned by the + /// widget [State], but the widget nonetheless needs to be updated to react to + /// the new state. This is especially common with [Listenable]s, such as + /// [AnimationController]s. + /// + /// In such cases, it is good practice to leave a comment in the callback + /// passed to [setState] that explains what state changed: + /// + /// ```dart + /// void _update() { + /// setState(() { /* The animation changed. */ }); + /// } + /// //... + /// animation.addListener(_update); + /// ``` + /// + /// It is an error to call this method after the framework calls [dispose]. + /// You can determine whether it is legal to call this method by checking + /// whether the [mounted] property is true. That said, it is better practice + /// to cancel whatever work might trigger the [setState] rather than merely + /// checking for [mounted] before calling [setState], as otherwise CPU cycles + /// will be wasted. + /// + /// ## Design discussion + /// + /// The original version of this API was a method called `markNeedsBuild`, for + /// consistency with [RenderObject.markNeedsLayout], + /// [RenderObject.markNeedsPaint], _et al_. + /// + /// However, early user testing of the Flutter framework revealed that people + /// would call `markNeedsBuild()` much more often than necessary. Essentially, + /// people used it like a good luck charm, any time they weren't sure if they + /// needed to call it, they would call it, just in case. + /// + /// Naturally, this led to performance issues in applications. + /// + /// When the API was changed to take a callback instead, this practice was + /// greatly reduced. One hypothesis is that prompting developers to actually + /// update their state in a callback caused developers to think more carefully + /// about what exactly was being updated, and thus improved their understanding + /// of the appropriate times to call the method. + /// + /// In practice, the [setState] method's implementation is trivial: it calls + /// the provided callback synchronously, then calls [Element.markNeedsBuild]. + /// + /// ## Performance considerations + /// + /// There is minimal _direct_ overhead to calling this function, and as it is + /// expected to be called at most once per frame, the overhead is irrelevant + /// anyway. Nonetheless, it is best to avoid calling this function redundantly + /// (e.g. in a tight loop), as it does involve creating a closure and calling + /// it. The method is idempotent, there is no benefit to calling it more than + /// once per [State] per frame. + /// + /// The _indirect_ cost of causing this function, however, is high: it causes + /// the widget to rebuild, possibly triggering rebuilds for the entire subtree + /// rooted at this widget, and further triggering a relayout and repaint of + /// the entire corresponding [RenderObject] subtree. + /// + /// For this reason, this method should only be called when the [build] method + /// will, as a result of whatever state change was detected, change its result + /// meaningfully. + /// + /// See also: + /// + /// * [StatefulWidget], the API documentation for which has a section on + /// performance considerations that are relevant here. + @protected + void setState(VoidCallback fn) { + assert(() { + if (_debugLifecycleState == _StateLifecycle.defunct) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('setState() called after dispose(): $this'), + ErrorDescription( + 'This error happens if you call setState() on a State object for a widget that ' + 'no longer appears in the widget tree (e.g., whose parent widget no longer ' + 'includes the widget in its build). This error can occur when code calls ' + 'setState() from a timer or an animation callback.', + ), + ErrorHint( + 'The preferred solution is ' + 'to cancel the timer or stop listening to the animation in the dispose() ' + 'callback. Another solution is to check the "mounted" property of this ' + 'object before calling setState() to ensure the object is still in the ' + 'tree.', + ), + ErrorHint( + 'This error might indicate a memory leak if setState() is being called ' + 'because another object is retaining a reference to this State object ' + 'after it has been removed from the tree. To avoid memory leaks, ' + 'consider breaking the reference to this object during dispose().', + ), + ]); + } + if (_debugLifecycleState == _StateLifecycle.created && !mounted) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('setState() called in constructor: $this'), + ErrorHint( + 'This happens when you call setState() on a State object for a widget that ' + "hasn't been inserted into the widget tree yet. It is not necessary to call " + 'setState() in the constructor, since the state is already assumed to be dirty ' + 'when it is initially created.', + ), + ]); + } + return true; + }()); + final Object? result = fn() as dynamic; + assert(() { + if (result is Future) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('setState() callback argument returned a Future.'), + ErrorDescription( + 'The setState() method on $this was called with a closure or method that ' + 'returned a Future. Maybe it is marked as "async".', + ), + ErrorHint( + 'Instead of performing asynchronous work inside a call to setState(), first ' + 'execute the work (without updating the widget state), and then synchronously ' + 'update the state inside a call to setState().', + ), + ]); + } + // We ignore other types of return values so that you can do things like: + // setState(() => x = 3); + return true; + }()); + _element!.markNeedsBuild(); + } + + /// Called when this object is removed from the tree. + /// + /// The framework calls this method whenever it removes this [State] object + /// from the tree. In some cases, the framework will reinsert the [State] + /// object into another part of the tree (e.g., if the subtree containing this + /// [State] object is grafted from one location in the tree to another due to + /// the use of a [GlobalKey]). If that happens, the framework will call + /// [activate] to give the [State] object a chance to reacquire any resources + /// that it released in [deactivate]. It will then also call [build] to give + /// the [State] object a chance to adapt to its new location in the tree. If + /// the framework does reinsert this subtree, it will do so before the end of + /// the animation frame in which the subtree was removed from the tree. For + /// this reason, [State] objects can defer releasing most resources until the + /// framework calls their [dispose] method. + /// + /// Subclasses should override this method to clean up any links between + /// this object and other elements in the tree (e.g. if you have provided an + /// ancestor with a pointer to a descendant's [RenderObject]). + /// + /// Implementations of this method should end with a call to the inherited + /// method, as in `super.deactivate()`. + /// + /// See also: + /// + /// * [dispose], which is called after [deactivate] if the widget is removed + /// from the tree permanently. + @protected + @mustCallSuper + void deactivate() { } + + /// Called when this object is reinserted into the tree after having been + /// removed via [deactivate]. + /// + /// In most cases, after a [State] object has been deactivated, it is _not_ + /// reinserted into the tree, and its [dispose] method will be called to + /// signal that it is ready to be garbage collected. + /// + /// In some cases, however, after a [State] object has been deactivated, the + /// framework will reinsert it into another part of the tree (e.g., if the + /// subtree containing this [State] object is grafted from one location in + /// the tree to another due to the use of a [GlobalKey]). If that happens, + /// the framework will call [activate] to give the [State] object a chance to + /// reacquire any resources that it released in [deactivate]. It will then + /// also call [build] to give the object a chance to adapt to its new + /// location in the tree. If the framework does reinsert this subtree, it + /// will do so before the end of the animation frame in which the subtree was + /// removed from the tree. For this reason, [State] objects can defer + /// releasing most resources until the framework calls their [dispose] method. + /// + /// The framework does not call this method the first time a [State] object + /// is inserted into the tree. Instead, the framework calls [initState] in + /// that situation. + /// + /// Implementations of this method should start with a call to the inherited + /// method, as in `super.activate()`. + /// + /// See also: + /// + /// * [Element.activate], the corresponding method when an element + /// transitions from the "inactive" to the "active" lifecycle state. + @protected + @mustCallSuper + void activate() { } + + /// Called when this object is removed from the tree permanently. + /// + /// The framework calls this method when this [State] object will never + /// build again. After the framework calls [dispose], the [State] object is + /// considered unmounted and the [mounted] property is false. It is an error + /// to call [setState] at this point. This stage of the lifecycle is terminal: + /// there is no way to remount a [State] object that has been disposed. + /// + /// Subclasses should override this method to release any resources retained + /// by this object (e.g., stop any active animations). + /// + /// {@macro flutter.widgets.State.initState} + /// + /// Implementations of this method should end with a call to the inherited + /// method, as in `super.dispose()`. + /// + /// ## Caveats + /// + /// This method is _not_ invoked at times where a developer might otherwise + /// expect it, such as application shutdown or dismissal via platform + /// native methods. + /// + /// ### Application shutdown + /// + /// There is no way to predict when application shutdown will happen. For + /// example, a user's battery could catch fire, or the user could drop the + /// device into a swimming pool, or the operating system could unilaterally + /// terminate the application process due to memory pressure. + /// + /// Applications are responsible for ensuring that they are well-behaved + /// even in the face of a rapid unscheduled termination. + /// + /// To artificially cause the entire widget tree to be disposed, consider + /// calling [runApp] with a widget such as [SizedBox.shrink]. + /// + /// To listen for platform shutdown messages (and other lifecycle changes), + /// consider the [AppLifecycleListener] API. + /// + /// ### Dismissing Flutter UI via platform native methods + /// + /// {@macro flutter.widgets.runApp.dismissal} + /// + /// See also: + /// + /// * [deactivate], which is called prior to [dispose]. + @protected + @mustCallSuper + void dispose() { + assert(_debugLifecycleState == _StateLifecycle.ready); + assert(() { + _debugLifecycleState = _StateLifecycle.defunct; + return true; + }()); + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + } + + /// Describes the part of the user interface represented by this widget. + /// + /// The framework calls this method in a number of different situations. For + /// example: + /// + /// * After calling [initState]. + /// * After calling [didUpdateWidget]. + /// * After receiving a call to [setState]. + /// * After a dependency of this [State] object changes (e.g., an + /// [InheritedWidget] referenced by the previous [build] changes). + /// * After calling [deactivate] and then reinserting the [State] object into + /// the tree at another location. + /// + /// This method can potentially be called in every frame and should not have + /// any side effects beyond building a widget. + /// + /// The framework replaces the subtree below this widget with the widget + /// returned by this method, either by updating the existing subtree or by + /// removing the subtree and inflating a new subtree, depending on whether the + /// widget returned by this method can update the root of the existing + /// subtree, as determined by calling [Widget.canUpdate]. + /// + /// Typically implementations return a newly created constellation of widgets + /// that are configured with information from this widget's constructor, the + /// given [BuildContext], and the internal state of this [State] object. + /// + /// The given [BuildContext] contains information about the location in the + /// tree at which this widget is being built. For example, the context + /// provides the set of inherited widgets for this location in the tree. The + /// [BuildContext] argument is always the same as the [context] property of + /// this [State] object and will remain the same for the lifetime of this + /// object. The [BuildContext] argument is provided redundantly here so that + /// this method matches the signature for a [WidgetBuilder]. + /// + /// ## Design discussion + /// + /// ### Why is the [build] method on [State], and not [StatefulWidget]? + /// + /// Putting a `Widget build(BuildContext context)` method on [State] rather + /// than putting a `Widget build(BuildContext context, State state)` method + /// on [StatefulWidget] gives developers more flexibility when subclassing + /// [StatefulWidget]. + /// + /// For example, [AnimatedWidget] is a subclass of [StatefulWidget] that + /// introduces an abstract `Widget build(BuildContext context)` method for its + /// subclasses to implement. If [StatefulWidget] already had a [build] method + /// that took a [State] argument, [AnimatedWidget] would be forced to provide + /// its [State] object to subclasses even though its [State] object is an + /// internal implementation detail of [AnimatedWidget]. + /// + /// Conceptually, [StatelessWidget] could also be implemented as a subclass of + /// [StatefulWidget] in a similar manner. If the [build] method were on + /// [StatefulWidget] rather than [State], that would not be possible anymore. + /// + /// Putting the [build] function on [State] rather than [StatefulWidget] also + /// helps avoid a category of bugs related to closures implicitly capturing + /// `this`. If you defined a closure in a [build] function on a + /// [StatefulWidget], that closure would implicitly capture `this`, which is + /// the current widget instance, and would have the (immutable) fields of that + /// instance in scope: + /// + /// ```dart + /// // (this is not valid Flutter code) + /// class MyButton extends StatefulWidgetX { + /// MyButton({super.key, required this.color}); + /// + /// final Color color; + /// + /// @override + /// Widget build(BuildContext context, State state) { + /// return SpecialWidget( + /// handler: () { print('color: $color'); }, + /// ); + /// } + /// } + /// ``` + /// + /// For example, suppose the parent builds `MyButton` with `color` being blue, + /// the `$color` in the print function refers to blue, as expected. Now, + /// suppose the parent rebuilds `MyButton` with green. The closure created by + /// the first build still implicitly refers to the original widget and the + /// `$color` still prints blue even through the widget has been updated to + /// green; should that closure outlive its widget, it would print outdated + /// information. + /// + /// In contrast, with the [build] function on the [State] object, closures + /// created during [build] implicitly capture the [State] instance instead of + /// the widget instance: + /// + /// ```dart + /// class MyButton extends StatefulWidget { + /// const MyButton({super.key, this.color = Colors.teal}); + /// + /// final Color color; + /// // ... + /// } + /// + /// class MyButtonState extends State<MyButton> { + /// // ... + /// @override + /// Widget build(BuildContext context) { + /// return SpecialWidget( + /// handler: () { print('color: ${widget.color}'); }, + /// ); + /// } + /// } + /// ``` + /// + /// Now when the parent rebuilds `MyButton` with green, the closure created by + /// the first build still refers to [State] object, which is preserved across + /// rebuilds, but the framework has updated that [State] object's [widget] + /// property to refer to the new `MyButton` instance and `${widget.color}` + /// prints green, as expected. + /// + /// See also: + /// + /// * [StatefulWidget], which contains the discussion on performance considerations. + @protected + Widget build(BuildContext context); + + /// Called when a dependency of this [State] object changes. + /// + /// For example, if the previous call to [build] referenced an + /// [InheritedWidget] that later changed, the framework would call this + /// method to notify this object about the change. + /// + /// This method is also called immediately after [initState]. It is safe to + /// call [BuildContext.dependOnInheritedWidgetOfExactType] from this method. + /// + /// Subclasses rarely override this method because the framework always + /// calls [build] after a dependency changes. Some subclasses do override + /// this method because they need to do some expensive work (e.g., network + /// fetches) when their dependencies change, and that work would be too + /// expensive to do for every build. + @protected + @mustCallSuper + void didChangeDependencies() { } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + assert(() { + properties.add(EnumProperty<_StateLifecycle>('lifecycle state', _debugLifecycleState, defaultValue: _StateLifecycle.ready)); + return true; + }()); + properties.add(ObjectFlagProperty<T>('_widget', _widget, ifNull: 'no widget')); + properties.add(ObjectFlagProperty<StatefulElement>('_element', _element, ifNull: 'not mounted')); + } +} + +/// A widget that has a child widget provided to it, instead of building a new +/// widget. +/// +/// Useful as a base class for other widgets, such as [InheritedWidget] and +/// [ParentDataWidget]. +/// +/// See also: +/// +/// * [InheritedWidget], for widgets that introduce ambient state that can +/// be read by descendant widgets. +/// * [ParentDataWidget], for widgets that populate the +/// [RenderObject.parentData] slot of their child's [RenderObject] to +/// configure the parent widget's layout. +/// * [StatefulWidget] and [State], for widgets that can build differently +/// several times over their lifetime. +/// * [StatelessWidget], for widgets that always build the same way given a +/// particular configuration and ambient state. +/// * [Widget], for an overview of widgets in general. +abstract class ProxyWidget extends Widget { + /// Creates a widget that has exactly one child widget. + const ProxyWidget({ super.key, required this.child }); + + /// The widget below this widget in the tree. + /// + /// {@template flutter.widgets.ProxyWidget.child} + /// This widget can only have one child. To lay out multiple children, let this + /// widget's child be a widget such as [Row], [Column], or [Stack], which have a + /// `children` property, and then provide the children to that widget. + /// {@endtemplate} + final Widget child; +} + +/// Base class for widgets that hook [ParentData] information to children of +/// [RenderObjectWidget]s. +/// +/// This can be used to provide per-child configuration for +/// [RenderObjectWidget]s with more than one child. For example, [Stack] uses +/// the [Positioned] parent data widget to position each child. +/// +/// A [ParentDataWidget] is specific to a particular kind of [ParentData]. That +/// class is `T`, the [ParentData] type argument. +/// +/// {@tool snippet} +/// +/// This example shows how you would build a [ParentDataWidget] to configure a +/// `FrogJar` widget's children by specifying a [Size] for each one. +/// +/// ```dart +/// class FrogSize extends ParentDataWidget<FrogJarParentData> { +/// const FrogSize({ +/// super.key, +/// required this.size, +/// required super.child, +/// }); +/// +/// final Size size; +/// +/// @override +/// void applyParentData(RenderObject renderObject) { +/// final FrogJarParentData parentData = renderObject.parentData! as FrogJarParentData; +/// if (parentData.size != size) { +/// parentData.size = size; +/// final RenderFrogJar targetParent = renderObject.parent! as RenderFrogJar; +/// targetParent.markNeedsLayout(); +/// } +/// } +/// +/// @override +/// Type get debugTypicalAncestorWidgetClass => FrogJar; +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [RenderObject], the superclass for layout algorithms. +/// * [RenderObject.parentData], the slot that this class configures. +/// * [ParentData], the superclass of the data that will be placed in +/// [RenderObject.parentData] slots. The `T` type parameter for +/// [ParentDataWidget] is a [ParentData]. +/// * [RenderObjectWidget], the class for widgets that wrap [RenderObject]s. +/// * [StatefulWidget] and [State], for widgets that can build differently +/// several times over their lifetime. +abstract class ParentDataWidget<T extends ParentData> extends ProxyWidget { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const ParentDataWidget({ super.key, required super.child }); + + @override + ParentDataElement<T> createElement() => ParentDataElement<T>(this); + + /// Checks if this widget can apply its parent data to the provided + /// `renderObject`. + /// + /// The [RenderObject.parentData] of the provided `renderObject` is + /// typically set up by an ancestor [RenderObjectWidget] of the type returned + /// by [debugTypicalAncestorWidgetClass]. + /// + /// This is called just before [applyParentData] is invoked with the same + /// [RenderObject] provided to that method. + bool debugIsValidRenderObject(RenderObject renderObject) { + assert(T != dynamic); + assert(T != ParentData); + return renderObject.parentData is T; + } + + /// Describes the [RenderObjectWidget] that is typically used to set up the + /// [ParentData] that [applyParentData] will write to. + /// + /// This is only used in error messages to tell users what widget typically + /// wraps this [ParentDataWidget] through + /// [debugTypicalAncestorWidgetDescription]. + /// + /// ## Implementations + /// + /// The returned Type should describe a subclass of `RenderObjectWidget`. If + /// more than one Type is supported, use + /// [debugTypicalAncestorWidgetDescription], which typically inserts this + /// value but can be overridden to describe more than one Type. + /// + /// ```dart + /// @override + /// Type get debugTypicalAncestorWidgetClass => FrogJar; + /// ``` + /// + /// If the "typical" parent is generic (`Foo<T>`), consider specifying either + /// a typical type argument (e.g. `Foo<int>` if `int` is typically how the + /// type is specialized), or specifying the upper bound (e.g. `Foo<Object?>`). + Type get debugTypicalAncestorWidgetClass; + + /// Describes the [RenderObjectWidget] that is typically used to set up the + /// [ParentData] that [applyParentData] will write to. + /// + /// This is only used in error messages to tell users what widget typically + /// wraps this [ParentDataWidget]. + /// + /// Returns [debugTypicalAncestorWidgetClass] by default as a String. This can + /// be overridden to describe more than one Type of valid parent. + String get debugTypicalAncestorWidgetDescription => '$debugTypicalAncestorWidgetClass'; + + Iterable<DiagnosticsNode> _debugDescribeIncorrectParentDataType({ + required ParentData? parentData, + RenderObjectWidget? parentDataCreator, + DiagnosticsNode? ownershipChain, + }) { + assert(T != dynamic); + assert(T != ParentData); + + final String description = 'The ParentDataWidget $this wants to apply ParentData of type $T to a RenderObject'; + return <DiagnosticsNode>[ + if (parentData == null) + ErrorDescription( + '$description, which has not been set up to receive any ParentData.', + ) + else + ErrorDescription( + '$description, which has been set up to accept ParentData of incompatible type ${parentData.runtimeType}.', + ), + ErrorHint( + 'Usually, this means that the $runtimeType widget has the wrong ancestor RenderObjectWidget. ' + 'Typically, $runtimeType widgets are placed directly inside $debugTypicalAncestorWidgetDescription widgets.', + ), + if (parentDataCreator != null) + ErrorHint( + 'The offending $runtimeType is currently placed inside a ${parentDataCreator.runtimeType} widget.', + ), + if (ownershipChain != null) + ErrorDescription( + 'The ownership chain for the RenderObject that received the incompatible parent data was:\n $ownershipChain', + ), + ]; + } + + /// Write the data from this widget into the given render object's parent data. + /// + /// The framework calls this function whenever it detects that the + /// [RenderObject] associated with the [child] has outdated + /// [RenderObject.parentData]. For example, if the render object was recently + /// inserted into the render tree, the render object's parent data might not + /// match the data in this widget. + /// + /// Subclasses are expected to override this function to copy data from their + /// fields into the [RenderObject.parentData] field of the given render + /// object. The render object's parent is guaranteed to have been created by a + /// widget of type `T`, which usually means that this function can assume that + /// the render object's parent data object inherits from a particular class. + /// + /// If this function modifies data that can change the parent's layout or + /// painting, this function is responsible for calling + /// [RenderObject.markNeedsLayout] or [RenderObject.markNeedsPaint] on the + /// parent, as appropriate. + @protected + void applyParentData(RenderObject renderObject); + + /// Whether the [ParentDataElement.applyWidgetOutOfTurn] method is allowed + /// with this widget. + /// + /// This should only return true if this widget represents a [ParentData] + /// configuration that will have no impact on the layout or paint phase. + /// + /// See also: + /// + /// * [ParentDataElement.applyWidgetOutOfTurn], which verifies this in debug + /// mode. + @protected + bool debugCanApplyOutOfTurn() => false; +} + +/// Base class for widgets that efficiently propagate information down the tree. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=og-vJqLzg2c} +/// +/// To obtain the nearest instance of a particular type of inherited widget from +/// a build context, use [BuildContext.dependOnInheritedWidgetOfExactType]. +/// +/// Inherited widgets, when referenced in this way, will cause the consumer to +/// rebuild when the inherited widget itself changes state. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=Zbm3hjPjQMk} +/// +/// {@tool snippet} +/// +/// The following is a skeleton of an inherited widget called `FrogColor`: +/// +/// ```dart +/// class FrogColor extends InheritedWidget { +/// const FrogColor({ +/// super.key, +/// required this.color, +/// required super.child, +/// }); +/// +/// final Color color; +/// +/// static FrogColor? maybeOf(BuildContext context) { +/// return context.dependOnInheritedWidgetOfExactType<FrogColor>(); +/// } +/// +/// static FrogColor of(BuildContext context) { +/// final FrogColor? result = maybeOf(context); +/// assert(result != null, 'No FrogColor found in context'); +/// return result!; +/// } +/// +/// @override +/// bool updateShouldNotify(FrogColor oldWidget) => color != oldWidget.color; +/// } +/// ``` +/// {@end-tool} +/// +/// ## Implementing the `of` and `maybeOf` methods +/// +/// The convention is to provide two static methods, `of` and `maybeOf`, on the +/// [InheritedWidget] which call +/// [BuildContext.dependOnInheritedWidgetOfExactType]. This allows the class to +/// define its own fallback logic in case there isn't a widget in scope. +/// +/// The `of` method typically returns a non-nullable instance and asserts if the +/// [InheritedWidget] isn't found, and the `maybeOf` method returns a nullable +/// instance, and returns null if the [InheritedWidget] isn't found. The `of` +/// method is typically implemented by calling `maybeOf` internally. +/// +/// Sometimes, the `of` and `maybeOf` methods return some data rather than the +/// inherited widget itself; for example, in this case it could have returned a +/// [Color] instead of the `FrogColor` widget. +/// +/// Occasionally, the inherited widget is an implementation detail of another +/// class, and is therefore private. The `of` and `maybeOf` methods in that case +/// are typically implemented on the public class instead. For example, [Theme] +/// is implemented as a [StatelessWidget] that builds a private inherited +/// widget; [Theme.of] looks for that private inherited widget using +/// [BuildContext.dependOnInheritedWidgetOfExactType] and then returns the +/// [ThemeData] inside it. +/// +/// ## Calling the `of` or `maybeOf` methods +/// +/// When using the `of` or `maybeOf` methods, the `context` must be a descendant +/// of the [InheritedWidget], meaning it must be "below" the [InheritedWidget] +/// in the tree. +/// +/// {@tool snippet} +/// +/// In this example, the `context` used is the one from the [Builder], which is +/// a child of the `FrogColor` widget, so this works. +/// +/// ```dart +/// // continuing from previous example... +/// class MyPage extends StatelessWidget { +/// const MyPage({super.key}); +/// +/// @override +/// Widget build(BuildContext context) { +/// return Scaffold( +/// body: FrogColor( +/// color: Colors.green, +/// child: Builder( +/// builder: (BuildContext innerContext) { +/// return Text( +/// 'Hello Frog', +/// style: TextStyle(color: FrogColor.of(innerContext).color), +/// ); +/// }, +/// ), +/// ), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// +/// In this example, the `context` used is the one from the `MyOtherPage` +/// widget, which is a parent of the `FrogColor` widget, so this does not work, +/// and will assert when `FrogColor.of` is called. +/// +/// ```dart +/// // continuing from previous example... +/// +/// class MyOtherPage extends StatelessWidget { +/// const MyOtherPage({super.key}); +/// +/// @override +/// Widget build(BuildContext context) { +/// return Scaffold( +/// body: FrogColor( +/// color: Colors.green, +/// child: Text( +/// 'Hello Frog', +/// style: TextStyle(color: FrogColor.of(context).color), +/// ), +/// ), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} {@youtube 560 315 https://www.youtube.com/watch?v=1t-8rBCGBYw} +/// +/// See also: +/// +/// * [StatefulWidget] and [State], for widgets that can build differently +/// several times over their lifetime. +/// * [StatelessWidget], for widgets that always build the same way given a +/// particular configuration and ambient state. +/// * [Widget], for an overview of widgets in general. +/// * [InheritedNotifier], an inherited widget whose value can be a +/// [Listenable], and which will notify dependents whenever the value sends +/// notifications. +/// * [InheritedModel], an inherited widget that allows clients to subscribe to +/// changes for subparts of the value. +abstract class InheritedWidget extends ProxyWidget { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const InheritedWidget({ super.key, required super.child }); + + @override + InheritedElement createElement() => InheritedElement(this); + + /// Whether the framework should notify widgets that inherit from this widget. + /// + /// When this widget is rebuilt, sometimes we need to rebuild the widgets that + /// inherit from this widget but sometimes we do not. For example, if the data + /// held by this widget is the same as the data held by `oldWidget`, then we + /// do not need to rebuild the widgets that inherited the data held by + /// `oldWidget`. + /// + /// The framework distinguishes these cases by calling this function with the + /// widget that previously occupied this location in the tree as an argument. + /// The given widget is guaranteed to have the same [runtimeType] as this + /// object. + @protected + bool updateShouldNotify(covariant InheritedWidget oldWidget); +} + +/// [RenderObjectWidget]s provide the configuration for [RenderObjectElement]s, +/// which wrap [RenderObject]s, which provide the actual rendering of the +/// application. +/// +/// Usually, rather than subclassing [RenderObjectWidget] directly, render +/// object widgets subclass one of: +/// +/// * [LeafRenderObjectWidget], if the widget has no children. +/// * [SingleChildRenderObjectElement], if the widget has exactly one child. +/// * [MultiChildRenderObjectWidget], if the widget takes a list of children. +/// * [SlottedMultiChildRenderObjectWidget], if the widget organizes its +/// children in different named slots. +/// +/// Subclasses must implement [createRenderObject] and [updateRenderObject]. +abstract class RenderObjectWidget extends Widget { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const RenderObjectWidget({ super.key }); + + /// RenderObjectWidgets always inflate to a [RenderObjectElement] subclass. + @override + @factory + RenderObjectElement createElement(); + + /// Creates an instance of the [RenderObject] class that this + /// [RenderObjectWidget] represents, using the configuration described by this + /// [RenderObjectWidget]. + /// + /// This method should not do anything with the children of the render object. + /// That should instead be handled by the method that overrides + /// [RenderObjectElement.mount] in the object rendered by this object's + /// [createElement] method. See, for example, + /// [SingleChildRenderObjectElement.mount]. + @protected + @factory + RenderObject createRenderObject(BuildContext context); + + /// Copies the configuration described by this [RenderObjectWidget] to the + /// given [RenderObject], which will be of the same type as returned by this + /// object's [createRenderObject]. + /// + /// This method should not do anything to update the children of the render + /// object. That should instead be handled by the method that overrides + /// [RenderObjectElement.update] in the object rendered by this object's + /// [createElement] method. See, for example, + /// [SingleChildRenderObjectElement.update]. + @protected + void updateRenderObject(BuildContext context, covariant RenderObject renderObject) { } + + /// A render object previously associated with this widget has been removed + /// from the tree. The given [RenderObject] will be of the same type as + /// returned by this object's [createRenderObject]. + @protected + void didUnmountRenderObject(covariant RenderObject renderObject) { } +} + +/// A superclass for [RenderObjectWidget]s that configure [RenderObject] subclasses +/// that have no children. +/// +/// Subclasses must implement [createRenderObject] and [updateRenderObject]. +abstract class LeafRenderObjectWidget extends RenderObjectWidget { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const LeafRenderObjectWidget({ super.key }); + + @override + LeafRenderObjectElement createElement() => LeafRenderObjectElement(this); +} + +/// A superclass for [RenderObjectWidget]s that configure [RenderObject] subclasses +/// that have a single child slot. +/// +/// The render object assigned to this widget should make use of +/// [RenderObjectWithChildMixin] to implement a single-child model. The mixin +/// exposes a [RenderObjectWithChildMixin.child] property that allows retrieving +/// the render object belonging to the [child] widget. +/// +/// Subclasses must implement [createRenderObject] and [updateRenderObject]. +abstract class SingleChildRenderObjectWidget extends RenderObjectWidget { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const SingleChildRenderObjectWidget({ super.key, this.child }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + @override + SingleChildRenderObjectElement createElement() => SingleChildRenderObjectElement(this); +} + +/// A superclass for [RenderObjectWidget]s that configure [RenderObject] subclasses +/// that have a single list of children. (This superclass only provides the +/// storage for that child list, it doesn't actually provide the updating +/// logic.) +/// +/// Subclasses must use a [RenderObject] that mixes in +/// [ContainerRenderObjectMixin], which provides the necessary functionality to +/// visit the children of the container render object (the render object +/// belonging to the [children] widgets). Typically, subclasses will use a +/// [RenderBox] that mixes in both [ContainerRenderObjectMixin] and +/// [RenderBoxContainerDefaultsMixin]. +/// +/// Subclasses must implement [createRenderObject] and [updateRenderObject]. +/// +/// See also: +/// +/// * [Stack], which uses [MultiChildRenderObjectWidget]. +/// * [RenderStack], for an example implementation of the associated render +/// object. +/// * [SlottedMultiChildRenderObjectWidget], which configures a +/// [RenderObject] that instead of having a single list of children organizes +/// its children in named slots. +abstract class MultiChildRenderObjectWidget extends RenderObjectWidget { + /// Initializes fields for subclasses. + const MultiChildRenderObjectWidget({ super.key, this.children = const <Widget>[] }); + + /// The widgets below this widget in the tree. + /// + /// If this list is going to be mutated, it is usually wise to put a [Key] on + /// each of the child widgets, so that the framework can match old + /// configurations to new configurations and maintain the underlying render + /// objects. + /// + /// Also, a [Widget] in Flutter is immutable, so directly modifying the + /// [children] such as `someMultiChildRenderObjectWidget.children.add(...)` or + /// as the example code below will result in incorrect behaviors. Whenever the + /// children list is modified, a new list object should be provided. + /// + /// ```dart + /// // This code is incorrect. + /// class SomeWidgetState extends State<SomeWidget> { + /// final List<Widget> _children = <Widget>[]; + /// + /// void someHandler() { + /// setState(() { + /// _children.add(const ChildWidget()); + /// }); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// // Reusing `List<Widget> _children` here is problematic. + /// return Row(children: _children); + /// } + /// } + /// ``` + /// + /// The following code corrects the problem mentioned above. + /// + /// ```dart + /// class SomeWidgetState extends State<SomeWidget> { + /// final List<Widget> _children = <Widget>[]; + /// + /// void someHandler() { + /// setState(() { + /// // The key here allows Flutter to reuse the underlying render + /// // objects even if the children list is recreated. + /// _children.add(ChildWidget(key: UniqueKey())); + /// }); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// // Always create a new list of children as a Widget is immutable. + /// return Row(children: _children.toList()); + /// } + /// } + /// ``` + final List<Widget> children; + + @override + MultiChildRenderObjectElement createElement() => MultiChildRenderObjectElement(this); +} + + +// ELEMENTS + +enum _ElementLifecycle { + initial, + active, + inactive, + defunct, +} + +class _InactiveElements { + bool _locked = false; + final Set<Element> _elements = HashSet<Element>(); + + void _unmount(Element element) { + assert(element._lifecycleState == _ElementLifecycle.inactive); + assert(() { + if (debugPrintGlobalKeyedWidgetLifecycle) { + if (element.widget.key is GlobalKey) { + debugPrint('Discarding $element from inactive elements list.'); + } + } + return true; + }()); + element.visitChildren((Element child) { + assert(child._parent == element); + _unmount(child); + }); + element.unmount(); + assert(element._lifecycleState == _ElementLifecycle.defunct); + } + + void _unmountAll() { + _locked = true; + final List<Element> elements = _elements.toList()..sort(Element._sort); + _elements.clear(); + try { + elements.reversed.forEach(_unmount); + } finally { + assert(_elements.isEmpty); + _locked = false; + } + } + + static void _deactivateRecursively(Element element) { + assert(element._lifecycleState == _ElementLifecycle.active); + element.deactivate(); + assert(element._lifecycleState == _ElementLifecycle.inactive); + element.visitChildren(_deactivateRecursively); + assert(() { + element.debugDeactivated(); + return true; + }()); + } + + void add(Element element) { + assert(!_locked); + assert(!_elements.contains(element)); + assert(element._parent == null); + if (element._lifecycleState == _ElementLifecycle.active) { + _deactivateRecursively(element); + } + _elements.add(element); + } + + void remove(Element element) { + assert(!_locked); + assert(_elements.contains(element)); + assert(element._parent == null); + _elements.remove(element); + assert(element._lifecycleState != _ElementLifecycle.active); + } + + bool debugContains(Element element) { + late bool result; + assert(() { + result = _elements.contains(element); + return true; + }()); + return result; + } +} + +/// Signature for the callback to [BuildContext.visitChildElements]. +/// +/// The argument is the child being visited. +/// +/// It is safe to call `element.visitChildElements` reentrantly within +/// this callback. +typedef ElementVisitor = void Function(Element element); + +/// Signature for the callback to [BuildContext.visitAncestorElements]. +/// +/// The argument is the ancestor being visited. +/// +/// Return false to stop the walk. +typedef ConditionalElementVisitor = bool Function(Element element); + +/// A handle to the location of a widget in the widget tree. +/// +/// This class presents a set of methods that can be used from +/// [StatelessWidget.build] methods and from methods on [State] objects. +/// +/// [BuildContext] objects are passed to [WidgetBuilder] functions (such as +/// [StatelessWidget.build]), and are available from the [State.context] member. +/// Some static functions (e.g. [showDialog], [Theme.of], and so forth) also +/// take build contexts so that they can act on behalf of the calling widget, or +/// obtain data specifically for the given context. +/// +/// Each widget has its own [BuildContext], which becomes the parent of the +/// widget returned by the [StatelessWidget.build] or [State.build] function. +/// (And similarly, the parent of any children for [RenderObjectWidget]s.) +/// +/// In particular, this means that within a build method, the build context of +/// the widget of the build method is not the same as the build context of the +/// widgets returned by that build method. This can lead to some tricky cases. +/// For example, [Theme.of(context)] looks for the nearest enclosing [Theme] of +/// the given build context. If a build method for a widget Q includes a [Theme] +/// within its returned widget tree, and attempts to use [Theme.of] passing its +/// own context, the build method for Q will not find that [Theme] object. It +/// will instead find whatever [Theme] was an ancestor to the widget Q. If the +/// build context for a subpart of the returned tree is needed, a [Builder] +/// widget can be used: the build context passed to the [Builder.builder] +/// callback will be that of the [Builder] itself. +/// +/// For example, in the following snippet, the [ScaffoldState.showBottomSheet] +/// method is called on the [Scaffold] widget that the build method itself +/// creates. If a [Builder] had not been used, and instead the `context` +/// argument of the build method itself had been used, no [Scaffold] would have +/// been found, and the [Scaffold.of] function would have returned null. +/// +/// ```dart +/// @override +/// Widget build(BuildContext context) { +/// // here, Scaffold.of(context) returns null +/// return Scaffold( +/// appBar: AppBar(title: const Text('Demo')), +/// body: Builder( +/// builder: (BuildContext context) { +/// return TextButton( +/// child: const Text('BUTTON'), +/// onPressed: () { +/// Scaffold.of(context).showBottomSheet( +/// (BuildContext context) { +/// return Container( +/// alignment: Alignment.center, +/// height: 200, +/// color: Colors.amber, +/// child: Center( +/// child: Column( +/// mainAxisSize: MainAxisSize.min, +/// children: <Widget>[ +/// const Text('BottomSheet'), +/// ElevatedButton( +/// child: const Text('Close BottomSheet'), +/// onPressed: () { +/// Navigator.pop(context); +/// }, +/// ) +/// ], +/// ), +/// ), +/// ); +/// }, +/// ); +/// }, +/// ); +/// }, +/// ) +/// ); +/// } +/// ``` +/// +/// The [BuildContext] for a particular widget can change location over time as +/// the widget is moved around the tree. Because of this, values returned from +/// the methods on this class should not be cached beyond the execution of a +/// single synchronous function. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=rIaaH87z1-g} +/// +/// Avoid storing instances of [BuildContext]s because they may become invalid +/// if the widget they are associated with is unmounted from the widget tree. +/// {@template flutter.widgets.BuildContext.asynchronous_gap} +/// If a [BuildContext] is used across an asynchronous gap (i.e. after performing +/// an asynchronous operation), consider checking [mounted] to determine whether +/// the context is still valid before interacting with it: +/// +/// ```dart +/// @override +/// Widget build(BuildContext context) { +/// return OutlinedButton( +/// onPressed: () async { +/// await Future<void>.delayed(const Duration(seconds: 1)); +/// if (context.mounted) { +/// Navigator.of(context).pop(); +/// } +/// }, +/// child: const Text('Delayed pop'), +/// ); +/// } +/// ``` +/// {@endtemplate} +/// +/// [BuildContext] objects are actually [Element] objects. The [BuildContext] +/// interface is used to discourage direct manipulation of [Element] objects. +abstract class BuildContext { + /// The current configuration of the [Element] that is this [BuildContext]. + Widget get widget; + + /// The [BuildOwner] for this context. The [BuildOwner] is in charge of + /// managing the rendering pipeline for this context. + BuildOwner? get owner; + + /// Whether the [Widget] this context is associated with is currently + /// mounted in the widget tree. + /// + /// Accessing the properties of the [BuildContext] or calling any methods on + /// it is only valid while mounted is true. If mounted is false, assertions + /// will trigger. + /// + /// Once unmounted, a given [BuildContext] will never become mounted again. + /// + /// {@macro flutter.widgets.BuildContext.asynchronous_gap} + bool get mounted; + + /// Whether the [widget] is currently updating the widget or render tree. + /// + /// For [StatefulWidget]s and [StatelessWidget]s this flag is true while + /// their respective build methods are executing. + /// [RenderObjectWidget]s set this to true while creating or configuring their + /// associated [RenderObject]s. + /// Other [Widget] types may set this to true for conceptually similar phases + /// of their lifecycle. + /// + /// When this is true, it is safe for [widget] to establish a dependency to an + /// [InheritedWidget] by calling [dependOnInheritedElement] or + /// [dependOnInheritedWidgetOfExactType]. + /// + /// Accessing this flag in release mode is not valid. + bool get debugDoingBuild; + + /// The current [RenderObject] for the widget. If the widget is a + /// [RenderObjectWidget], this is the render object that the widget created + /// for itself. Otherwise, it is the render object of the first descendant + /// [RenderObjectWidget]. + /// + /// This method will only return a valid result after the build phase is + /// complete. It is therefore not valid to call this from a build method. + /// It should only be called from interaction event handlers (e.g. + /// gesture callbacks) or layout or paint callbacks. It is also not valid to + /// call if [State.mounted] returns false. + /// + /// If the render object is a [RenderBox], which is the common case, then the + /// size of the render object can be obtained from the [size] getter. This is + /// only valid after the layout phase, and should therefore only be examined + /// from paint callbacks or interaction event handlers (e.g. gesture + /// callbacks). + /// + /// For details on the different phases of a frame, see the discussion at + /// [WidgetsBinding.drawFrame]. + /// + /// Calling this method is theoretically relatively expensive (O(N) in the + /// depth of the tree), but in practice is usually cheap because the tree + /// usually has many render objects and therefore the distance to the nearest + /// render object is usually short. + RenderObject? findRenderObject(); + + /// The size of the [RenderBox] returned by [findRenderObject]. + /// + /// This getter will only return a valid result after the layout phase is + /// complete. It is therefore not valid to call this from a build method. + /// It should only be called from paint callbacks or interaction event + /// handlers (e.g. gesture callbacks). + /// + /// For details on the different phases of a frame, see the discussion at + /// [WidgetsBinding.drawFrame]. + /// + /// This getter will only return a valid result if [findRenderObject] actually + /// returns a [RenderBox]. If [findRenderObject] returns a render object that + /// is not a subtype of [RenderBox] (e.g., [RenderView]), this getter will + /// throw an exception in debug mode and will return null in release mode. + /// + /// Calling this getter is theoretically relatively expensive (O(N) in the + /// depth of the tree), but in practice is usually cheap because the tree + /// usually has many render objects and therefore the distance to the nearest + /// render object is usually short. + Size? get size; + + /// Registers this build context with [ancestor] such that when + /// [ancestor]'s widget changes this build context is rebuilt. + /// + /// Returns `ancestor.widget`. + /// + /// This method is rarely called directly. Most applications should use + /// [dependOnInheritedWidgetOfExactType], which calls this method after finding + /// the appropriate [InheritedElement] ancestor. + /// + /// All of the qualifications about when [dependOnInheritedWidgetOfExactType] can + /// be called apply to this method as well. + InheritedWidget dependOnInheritedElement(InheritedElement ancestor, { Object? aspect }); + + /// Returns the nearest widget of the given type `T` and creates a dependency + /// on it, or null if no appropriate widget is found. + /// + /// The widget found will be a concrete [InheritedWidget] subclass, and + /// calling [dependOnInheritedWidgetOfExactType] registers this build context + /// with the returned widget. When that widget changes (or a new widget of + /// that type is introduced, or the widget goes away), this build context is + /// rebuilt so that it can obtain new values from that widget. + /// + /// {@template flutter.widgets.BuildContext.dependOnInheritedWidgetOfExactType} + /// This is typically called implicitly from `of()` static methods, e.g. + /// [Theme.of]. + /// + /// This method should not be called from widget constructors or from + /// [State.initState] methods, because those methods would not get called + /// again if the inherited value were to change. To ensure that the widget + /// correctly updates itself when the inherited value changes, only call this + /// (directly or indirectly) from build methods, layout and paint callbacks, + /// or from [State.didChangeDependencies] (which is called immediately after + /// [State.initState]). + /// + /// This method should not be called from [State.dispose] because the element + /// tree is no longer stable at that time. To refer to an ancestor from that + /// method, save a reference to the ancestor in [State.didChangeDependencies]. + /// It is safe to use this method from [State.deactivate], which is called + /// whenever the widget is removed from the tree. + /// + /// It is also possible to call this method from interaction event handlers + /// (e.g. gesture callbacks) or timers, to obtain a value once, as long as + /// that value is not cached and/or reused later. + /// + /// Calling this method is O(1) with a small constant factor, but will lead to + /// the widget being rebuilt more often. + /// + /// Once a widget registers a dependency on a particular type by calling this + /// method, it will be rebuilt, and [State.didChangeDependencies] will be + /// called, whenever changes occur relating to that widget until the next time + /// the widget or one of its ancestors is moved (for example, because an + /// ancestor is added or removed). + /// + /// The [aspect] parameter is only used when `T` is an + /// [InheritedWidget] subclasses that supports partial updates, like + /// [InheritedModel]. It specifies what "aspect" of the inherited + /// widget this context depends on. + /// {@endtemplate} + T? dependOnInheritedWidgetOfExactType<T extends InheritedWidget>({ Object? aspect }); + + /// Returns the nearest widget of the given [InheritedWidget] subclass `T` or + /// null if an appropriate ancestor is not found. + /// + /// This method does not introduce a dependency the way that the more typical + /// [dependOnInheritedWidgetOfExactType] does, so this context will not be + /// rebuilt if the [InheritedWidget] changes. This function is meant for those + /// uncommon use cases where a dependency is undesirable. + /// + /// This method should not be called from [State.dispose] because the element + /// tree is no longer stable at that time. To refer to an ancestor from that + /// method, save a reference to the ancestor in [State.didChangeDependencies]. + /// It is safe to use this method from [State.deactivate], which is called + /// whenever the widget is removed from the tree. + /// + /// It is also possible to call this method from interaction event handlers + /// (e.g. gesture callbacks) or timers, to obtain a value once, as long as + /// that value is not cached and/or reused later. + /// + /// Calling this method is O(1) with a small constant factor. + T? getInheritedWidgetOfExactType<T extends InheritedWidget>(); + + /// Obtains the element corresponding to the nearest widget of the given type `T`, + /// which must be the type of a concrete [InheritedWidget] subclass. + /// + /// Returns null if no such element is found. + /// + /// {@template flutter.widgets.BuildContext.getElementForInheritedWidgetOfExactType} + /// Calling this method is O(1) with a small constant factor. + /// + /// This method does not establish a relationship with the target in the way + /// that [dependOnInheritedWidgetOfExactType] does. + /// + /// This method should not be called from [State.dispose] because the element + /// tree is no longer stable at that time. To refer to an ancestor from that + /// method, save a reference to the ancestor by calling + /// [dependOnInheritedWidgetOfExactType] in [State.didChangeDependencies]. It is + /// safe to use this method from [State.deactivate], which is called whenever + /// the widget is removed from the tree. + /// {@endtemplate} + InheritedElement? getElementForInheritedWidgetOfExactType<T extends InheritedWidget>(); + + /// Returns the nearest ancestor widget of the given type `T`, which must be the + /// type of a concrete [Widget] subclass. + /// + /// {@template flutter.widgets.BuildContext.findAncestorWidgetOfExactType} + /// In general, [dependOnInheritedWidgetOfExactType] is more useful, since + /// inherited widgets will trigger consumers to rebuild when they change. This + /// method is appropriate when used in interaction event handlers (e.g. + /// gesture callbacks) or for performing one-off tasks such as asserting that + /// you have or don't have a widget of a specific type as an ancestor. The + /// return value of a Widget's build method should not depend on the value + /// returned by this method, because the build context will not rebuild if the + /// return value of this method changes. This could lead to a situation where + /// data used in the build method changes, but the widget is not rebuilt. + /// + /// Calling this method is relatively expensive (O(N) in the depth of the + /// tree). Only call this method if the distance from this widget to the + /// desired ancestor is known to be small and bounded. + /// + /// This method should not be called from [State.deactivate] or [State.dispose] + /// because the widget tree is no longer stable at that time. To refer to + /// an ancestor from one of those methods, save a reference to the ancestor + /// by calling [findAncestorWidgetOfExactType] in [State.didChangeDependencies]. + /// + /// Returns null if a widget of the requested type does not appear in the + /// ancestors of this context. + /// {@endtemplate} + T? findAncestorWidgetOfExactType<T extends Widget>(); + + /// Returns the [State] object of the nearest ancestor [StatefulWidget] widget + /// that is an instance of the given type `T`. + /// + /// {@template flutter.widgets.BuildContext.findAncestorStateOfType} + /// This should not be used from build methods, because the build context will + /// not be rebuilt if the value that would be returned by this method changes. + /// In general, [dependOnInheritedWidgetOfExactType] is more appropriate for such + /// cases. This method is useful for changing the state of an ancestor widget in + /// a one-off manner, for example, to cause an ancestor scrolling list to + /// scroll this build context's widget into view, or to move the focus in + /// response to user interaction. + /// + /// In general, though, consider using a callback that triggers a stateful + /// change in the ancestor rather than using the imperative style implied by + /// this method. This will usually lead to more maintainable and reusable code + /// since it decouples widgets from each other. + /// + /// Calling this method is relatively expensive (O(N) in the depth of the + /// tree). Only call this method if the distance from this widget to the + /// desired ancestor is known to be small and bounded. + /// + /// This method should not be called from [State.deactivate] or [State.dispose] + /// because the widget tree is no longer stable at that time. To refer to + /// an ancestor from one of those methods, save a reference to the ancestor + /// by calling [findAncestorStateOfType] in [State.didChangeDependencies]. + /// {@endtemplate} + /// + /// {@tool snippet} + /// + /// ```dart + /// ScrollableState? scrollable = context.findAncestorStateOfType<ScrollableState>(); + /// ``` + /// {@end-tool} + T? findAncestorStateOfType<T extends State>(); + + /// Returns the [State] object of the furthest ancestor [StatefulWidget] widget + /// that is an instance of the given type `T`. + /// + /// {@template flutter.widgets.BuildContext.findRootAncestorStateOfType} + /// Functions the same way as [findAncestorStateOfType] but keeps visiting subsequent + /// ancestors until there are none of the type instance of `T` remaining. + /// Then returns the last one found. + /// + /// This operation is O(N) as well though N is the entire widget tree rather than + /// a subtree. + /// {@endtemplate} + T? findRootAncestorStateOfType<T extends State>(); + + /// Returns the [RenderObject] object of the nearest ancestor [RenderObjectWidget] widget + /// that is an instance of the given type `T`. + /// + /// {@template flutter.widgets.BuildContext.findAncestorRenderObjectOfType} + /// This should not be used from build methods, because the build context will + /// not be rebuilt if the value that would be returned by this method changes. + /// In general, [dependOnInheritedWidgetOfExactType] is more appropriate for such + /// cases. This method is useful only in esoteric cases where a widget needs + /// to cause an ancestor to change its layout or paint behavior. For example, + /// it is used by [Material] so that [InkWell] widgets can trigger the ink + /// splash on the [Material]'s actual render object. + /// + /// Calling this method is relatively expensive (O(N) in the depth of the + /// tree). Only call this method if the distance from this widget to the + /// desired ancestor is known to be small and bounded. + /// + /// This method should not be called from [State.deactivate] or [State.dispose] + /// because the widget tree is no longer stable at that time. To refer to + /// an ancestor from one of those methods, save a reference to the ancestor + /// by calling [findAncestorRenderObjectOfType] in [State.didChangeDependencies]. + /// {@endtemplate} + T? findAncestorRenderObjectOfType<T extends RenderObject>(); + + /// Walks the ancestor chain, starting with the parent of this build context's + /// widget, invoking the argument for each ancestor. + /// + /// {@template flutter.widgets.BuildContext.visitAncestorElements} + /// The callback is given a reference to the ancestor widget's corresponding + /// [Element] object. The walk stops when it reaches the root widget or when + /// the callback returns false. The callback must not return null. + /// + /// This is useful for inspecting the widget tree. + /// + /// Calling this method is relatively expensive (O(N) in the depth of the tree). + /// + /// This method should not be called from [State.deactivate] or [State.dispose] + /// because the element tree is no longer stable at that time. To refer to + /// an ancestor from one of those methods, save a reference to the ancestor + /// by calling [visitAncestorElements] in [State.didChangeDependencies]. + /// {@endtemplate} + void visitAncestorElements(ConditionalElementVisitor visitor); + + /// Walks the children of this widget. + /// + /// {@template flutter.widgets.BuildContext.visitChildElements} + /// This is useful for applying changes to children after they are built + /// without waiting for the next frame, especially if the children are known, + /// and especially if there is exactly one child (as is always the case for + /// [StatefulWidget]s or [StatelessWidget]s). + /// + /// Calling this method is very cheap for build contexts that correspond to + /// [StatefulWidget]s or [StatelessWidget]s (O(1), since there's only one + /// child). + /// + /// Calling this method is potentially expensive for build contexts that + /// correspond to [RenderObjectWidget]s (O(N) in the number of children). + /// + /// Calling this method recursively is extremely expensive (O(N) in the number + /// of descendants), and should be avoided if possible. Generally it is + /// significantly cheaper to use an [InheritedWidget] and have the descendants + /// pull data down, than it is to use [visitChildElements] recursively to push + /// data down to them. + /// {@endtemplate} + void visitChildElements(ElementVisitor visitor); + + /// Start bubbling this notification at the given build context. + /// + /// The notification will be delivered to any [NotificationListener] widgets + /// with the appropriate type parameters that are ancestors of the given + /// [BuildContext]. + void dispatchNotification(Notification notification); + + /// Returns a description of the [Element] associated with the current build context. + /// + /// The `name` is typically something like "The element being rebuilt was". + /// + /// See also: + /// + /// * [Element.describeElements], which can be used to describe a list of elements. + DiagnosticsNode describeElement(String name, {DiagnosticsTreeStyle style = DiagnosticsTreeStyle.errorProperty}); + + /// Returns a description of the [Widget] associated with the current build context. + /// + /// The `name` is typically something like "The widget being rebuilt was". + DiagnosticsNode describeWidget(String name, {DiagnosticsTreeStyle style = DiagnosticsTreeStyle.errorProperty}); + + /// Adds a description of a specific type of widget missing from the current + /// build context's ancestry tree. + /// + /// You can find an example of using this method in [debugCheckHasMaterial]. + List<DiagnosticsNode> describeMissingAncestor({ required Type expectedAncestorType }); + + /// Adds a description of the ownership chain from a specific [Element] + /// to the error report. + /// + /// The ownership chain is useful for debugging the source of an element. + DiagnosticsNode describeOwnershipChain(String name); +} + +/// Manager class for the widgets framework. +/// +/// This class tracks which widgets need rebuilding, and handles other tasks +/// that apply to widget trees as a whole, such as managing the inactive element +/// list for the tree and triggering the "reassemble" command when necessary +/// during hot reload when debugging. +/// +/// The main build owner is typically owned by the [WidgetsBinding], and is +/// driven from the operating system along with the rest of the +/// build/layout/paint pipeline. +/// +/// Additional build owners can be built to manage off-screen widget trees. +/// +/// To assign a build owner to a tree, use the +/// [RootElementMixin.assignOwner] method on the root element of the +/// widget tree. +/// +/// {@tool dartpad} +/// This example shows how to build an off-screen widget tree used to measure +/// the layout size of the rendered tree. For some use cases, the simpler +/// [Offstage] widget may be a better alternative to this approach. +/// +/// ** See code in examples/api/lib/widgets/framework/build_owner.0.dart ** +/// {@end-tool} +class BuildOwner { + /// Creates an object that manages widgets. + /// + /// If the `focusManager` argument is not specified or is null, this will + /// construct a new [FocusManager] and register its global input handlers + /// via [FocusManager.registerGlobalHandlers], which will modify static + /// state. Callers wishing to avoid altering this state can explicitly pass + /// a focus manager here. + BuildOwner({ this.onBuildScheduled, FocusManager? focusManager }) : + focusManager = focusManager ?? (FocusManager()..registerGlobalHandlers()); + + /// Called on each build pass when the first buildable element is marked + /// dirty. + VoidCallback? onBuildScheduled; + + final _InactiveElements _inactiveElements = _InactiveElements(); + + final List<Element> _dirtyElements = <Element>[]; + bool _scheduledFlushDirtyElements = false; + + /// Whether [_dirtyElements] need to be sorted again as a result of more + /// elements becoming dirty during the build. + /// + /// This is necessary to preserve the sort order defined by [Element._sort]. + /// + /// This field is set to null when [buildScope] is not actively rebuilding + /// the widget tree. + bool? _dirtyElementsNeedsResorting; + + /// Whether [buildScope] is actively rebuilding the widget tree. + /// + /// [scheduleBuildFor] should only be called when this value is true. + bool get _debugIsInBuildScope => _dirtyElementsNeedsResorting != null; + + /// The object in charge of the focus tree. + /// + /// Rarely used directly. Instead, consider using [FocusScope.of] to obtain + /// the [FocusScopeNode] for a given [BuildContext]. + /// + /// See [FocusManager] for more details. + /// + /// This field will default to a [FocusManager] that has registered its + /// global input handlers via [FocusManager.registerGlobalHandlers]. Callers + /// wishing to avoid registering those handlers (and modifying the associated + /// static state) can explicitly pass a focus manager to the [BuildOwner.new] + /// constructor. + FocusManager focusManager; + + /// Adds an element to the dirty elements list so that it will be rebuilt + /// when [WidgetsBinding.drawFrame] calls [buildScope]. + void scheduleBuildFor(Element element) { + assert(element.owner == this); + assert(() { + if (debugPrintScheduleBuildForStacks) { + debugPrintStack(label: 'scheduleBuildFor() called for $element${_dirtyElements.contains(element) ? " (ALREADY IN LIST)" : ""}'); + } + if (!element.dirty) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('scheduleBuildFor() called for a widget that is not marked as dirty.'), + element.describeElement('The method was called for the following element'), + ErrorDescription( + 'This element is not current marked as dirty. Make sure to set the dirty flag before ' + 'calling scheduleBuildFor().', + ), + ErrorHint( + 'If you did not attempt to call scheduleBuildFor() yourself, then this probably ' + 'indicates a bug in the widgets framework. Please report it:\n' + ' https://github.com/flutter/flutter/issues/new?template=2_bug.yml', + ), + ]); + } + return true; + }()); + if (element._inDirtyList) { + assert(() { + if (debugPrintScheduleBuildForStacks) { + debugPrintStack(label: 'BuildOwner.scheduleBuildFor() called; _dirtyElementsNeedsResorting was $_dirtyElementsNeedsResorting (now true); dirty list is: $_dirtyElements'); + } + if (!_debugIsInBuildScope) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('BuildOwner.scheduleBuildFor() called inappropriately.'), + ErrorHint( + 'The BuildOwner.scheduleBuildFor() method should only be called while the ' + 'buildScope() method is actively rebuilding the widget tree.', + ), + ]); + } + return true; + }()); + _dirtyElementsNeedsResorting = true; + return; + } + if (!_scheduledFlushDirtyElements && onBuildScheduled != null) { + _scheduledFlushDirtyElements = true; + onBuildScheduled!(); + } + _dirtyElements.add(element); + element._inDirtyList = true; + assert(() { + if (debugPrintScheduleBuildForStacks) { + debugPrint('...dirty list is now: $_dirtyElements'); + } + return true; + }()); + } + + int _debugStateLockLevel = 0; + bool get _debugStateLocked => _debugStateLockLevel > 0; + + /// Whether this widget tree is in the build phase. + /// + /// Only valid when asserts are enabled. + bool get debugBuilding => _debugBuilding; + bool _debugBuilding = false; + Element? _debugCurrentBuildTarget; + + /// Establishes a scope in which calls to [State.setState] are forbidden, and + /// calls the given `callback`. + /// + /// This mechanism is used to ensure that, for instance, [State.dispose] does + /// not call [State.setState]. + void lockState(VoidCallback callback) { + assert(_debugStateLockLevel >= 0); + assert(() { + _debugStateLockLevel += 1; + return true; + }()); + try { + callback(); + } finally { + assert(() { + _debugStateLockLevel -= 1; + return true; + }()); + } + assert(_debugStateLockLevel >= 0); + } + + /// Establishes a scope for updating the widget tree, and calls the given + /// `callback`, if any. Then, builds all the elements that were marked as + /// dirty using [scheduleBuildFor], in depth order. + /// + /// This mechanism prevents build methods from transitively requiring other + /// build methods to run, potentially causing infinite loops. + /// + /// The dirty list is processed after `callback` returns, building all the + /// elements that were marked as dirty using [scheduleBuildFor], in depth + /// order. If elements are marked as dirty while this method is running, they + /// must be deeper than the `context` node, and deeper than any + /// previously-built node in this pass. + /// + /// To flush the current dirty list without performing any other work, this + /// function can be called with no callback. This is what the framework does + /// each frame, in [WidgetsBinding.drawFrame]. + /// + /// Only one [buildScope] can be active at a time. + /// + /// A [buildScope] implies a [lockState] scope as well. + /// + /// To print a console message every time this method is called, set + /// [debugPrintBuildScope] to true. This is useful when debugging problems + /// involving widgets not getting marked dirty, or getting marked dirty too + /// often. + @pragma('vm:notify-debugger-on-exception') + void buildScope(Element context, [ VoidCallback? callback ]) { + if (callback == null && _dirtyElements.isEmpty) { + return; + } + assert(_debugStateLockLevel >= 0); + assert(!_debugBuilding); + assert(() { + if (debugPrintBuildScope) { + debugPrint('buildScope called with context $context; dirty list is: $_dirtyElements'); + } + _debugStateLockLevel += 1; + _debugBuilding = true; + return true; + }()); + if (!kReleaseMode) { + Map<String, String>? debugTimelineArguments; + assert(() { + if (debugEnhanceBuildTimelineArguments) { + debugTimelineArguments = <String, String>{ + 'dirty count': '${_dirtyElements.length}', + 'dirty list': '$_dirtyElements', + 'lock level': '$_debugStateLockLevel', + 'scope context': '$context', + }; + } + return true; + }()); + FlutterTimeline.startSync( + 'BUILD', + arguments: debugTimelineArguments + ); + } + try { + _scheduledFlushDirtyElements = true; + if (callback != null) { + assert(_debugStateLocked); + Element? debugPreviousBuildTarget; + assert(() { + debugPreviousBuildTarget = _debugCurrentBuildTarget; + _debugCurrentBuildTarget = context; + return true; + }()); + _dirtyElementsNeedsResorting = false; + try { + callback(); + } finally { + assert(() { + assert(_debugCurrentBuildTarget == context); + _debugCurrentBuildTarget = debugPreviousBuildTarget; + _debugElementWasRebuilt(context); + return true; + }()); + } + } + _dirtyElements.sort(Element._sort); + _dirtyElementsNeedsResorting = false; + int dirtyCount = _dirtyElements.length; + int index = 0; + while (index < dirtyCount) { + final Element element = _dirtyElements[index]; + assert(element._inDirtyList); + assert(() { + if (element._lifecycleState == _ElementLifecycle.active && !element._debugIsInScope(context)) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Tried to build dirty widget in the wrong build scope.'), + ErrorDescription( + 'A widget which was marked as dirty and is still active was scheduled to be built, ' + 'but the current build scope unexpectedly does not contain that widget.', + ), + ErrorHint( + 'Sometimes this is detected when an element is removed from the widget tree, but the ' + 'element somehow did not get marked as inactive. In that case, it might be caused by ' + 'an ancestor element failing to implement visitChildren correctly, thus preventing ' + 'some or all of its descendants from being correctly deactivated.', + ), + DiagnosticsProperty<Element>( + 'The root of the build scope was', + context, + style: DiagnosticsTreeStyle.errorProperty, + ), + DiagnosticsProperty<Element>( + 'The offending element (which does not appear to be a descendant of the root of the build scope) was', + element, + style: DiagnosticsTreeStyle.errorProperty, + ), + ]); + } + return true; + }()); + final bool isTimelineTracked = !kReleaseMode && _isProfileBuildsEnabledFor(element.widget); + if (isTimelineTracked) { + Map<String, String>? debugTimelineArguments; + assert(() { + if (kDebugMode && debugEnhanceBuildTimelineArguments) { + debugTimelineArguments = element.widget.toDiagnosticsNode().toTimelineArguments(); + } + return true; + }()); + FlutterTimeline.startSync( + '${element.widget.runtimeType}', + arguments: debugTimelineArguments, + ); + } + try { + element.rebuild(); + } catch (e, stack) { + _reportException( + ErrorDescription('while rebuilding dirty elements'), + e, + stack, + informationCollector: () => <DiagnosticsNode>[ + if (kDebugMode && index < _dirtyElements.length) + DiagnosticsDebugCreator(DebugCreator(element)), + if (index < _dirtyElements.length) + element.describeElement('The element being rebuilt at the time was index $index of $dirtyCount') + else + ErrorHint('The element being rebuilt at the time was index $index of $dirtyCount, but _dirtyElements only had ${_dirtyElements.length} entries. This suggests some confusion in the framework internals.'), + ], + ); + } + if (isTimelineTracked) { + FlutterTimeline.finishSync(); + } + index += 1; + if (dirtyCount < _dirtyElements.length || _dirtyElementsNeedsResorting!) { + _dirtyElements.sort(Element._sort); + _dirtyElementsNeedsResorting = false; + dirtyCount = _dirtyElements.length; + while (index > 0 && _dirtyElements[index - 1].dirty) { + // It is possible for previously dirty but inactive widgets to move right in the list. + // We therefore have to move the index left in the list to account for this. + // We don't know how many could have moved. However, we do know that the only possible + // change to the list is that nodes that were previously to the left of the index have + // now moved to be to the right of the right-most cleaned node, and we do know that + // all the clean nodes were to the left of the index. So we move the index left + // until just after the right-most clean node. + index -= 1; + } + } + } + assert(() { + if (_dirtyElements.any((Element element) => element._lifecycleState == _ElementLifecycle.active && element.dirty)) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('buildScope missed some dirty elements.'), + ErrorHint('This probably indicates that the dirty list should have been resorted but was not.'), + Element.describeElements('The list of dirty elements at the end of the buildScope call was', _dirtyElements), + ]); + } + return true; + }()); + } finally { + for (final Element element in _dirtyElements) { + assert(element._inDirtyList); + element._inDirtyList = false; + } + _dirtyElements.clear(); + _scheduledFlushDirtyElements = false; + _dirtyElementsNeedsResorting = null; + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + assert(_debugBuilding); + assert(() { + _debugBuilding = false; + _debugStateLockLevel -= 1; + if (debugPrintBuildScope) { + debugPrint('buildScope finished'); + } + return true; + }()); + } + assert(_debugStateLockLevel >= 0); + } + + Map<Element, Set<GlobalKey>>? _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans; + + void _debugTrackElementThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans(Element node, GlobalKey key) { + _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans ??= HashMap<Element, Set<GlobalKey>>(); + final Set<GlobalKey> keys = _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans! + .putIfAbsent(node, () => HashSet<GlobalKey>()); + keys.add(key); + } + + void _debugElementWasRebuilt(Element node) { + _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans?.remove(node); + } + + final Map<GlobalKey, Element> _globalKeyRegistry = <GlobalKey, Element>{}; + + // In Profile/Release mode this field is initialized to `null`. The Dart compiler can + // eliminate unused fields, but not their initializers. + @_debugOnly + final Set<Element>? _debugIllFatedElements = kDebugMode ? HashSet<Element>() : null; + + // This map keeps track which child reserves the global key with the parent. + // Parent, child -> global key. + // This provides us a way to remove old reservation while parent rebuilds the + // child in the same slot. + // + // In Profile/Release mode this field is initialized to `null`. The Dart compiler can + // eliminate unused fields, but not their initializers. + @_debugOnly + final Map<Element, Map<Element, GlobalKey>>? _debugGlobalKeyReservations = kDebugMode ? <Element, Map<Element, GlobalKey>>{} : null; + + /// The number of [GlobalKey] instances that are currently associated with + /// [Element]s that have been built by this build owner. + int get globalKeyCount => _globalKeyRegistry.length; + + void _debugRemoveGlobalKeyReservationFor(Element parent, Element child) { + assert(() { + _debugGlobalKeyReservations?[parent]?.remove(child); + return true; + }()); + } + + void _registerGlobalKey(GlobalKey key, Element element) { + assert(() { + if (_globalKeyRegistry.containsKey(key)) { + final Element oldElement = _globalKeyRegistry[key]!; + assert(element.widget.runtimeType != oldElement.widget.runtimeType); + _debugIllFatedElements?.add(oldElement); + } + return true; + }()); + _globalKeyRegistry[key] = element; + } + + void _unregisterGlobalKey(GlobalKey key, Element element) { + assert(() { + if (_globalKeyRegistry.containsKey(key) && _globalKeyRegistry[key] != element) { + final Element oldElement = _globalKeyRegistry[key]!; + assert(element.widget.runtimeType != oldElement.widget.runtimeType); + } + return true; + }()); + if (_globalKeyRegistry[key] == element) { + _globalKeyRegistry.remove(key); + } + } + + void _debugReserveGlobalKeyFor(Element parent, Element child, GlobalKey key) { + assert(() { + _debugGlobalKeyReservations?[parent] ??= <Element, GlobalKey>{}; + _debugGlobalKeyReservations?[parent]![child] = key; + return true; + }()); + } + + void _debugVerifyGlobalKeyReservation() { + assert(() { + final Map<GlobalKey, Element> keyToParent = <GlobalKey, Element>{}; + _debugGlobalKeyReservations?.forEach((Element parent, Map<Element, GlobalKey> childToKey) { + // We ignore parent that are unmounted or detached. + if (parent._lifecycleState == _ElementLifecycle.defunct || parent.renderObject?.attached == false) { + return; + } + childToKey.forEach((Element child, GlobalKey key) { + // If parent = null, the node is deactivated by its parent and is + // not re-attached to other part of the tree. We should ignore this + // node. + if (child._parent == null) { + return; + } + // It is possible the same key registers to the same parent twice + // with different children. That is illegal, but it is not in the + // scope of this check. Such error will be detected in + // _debugVerifyIllFatedPopulation or + // _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans. + if (keyToParent.containsKey(key) && keyToParent[key] != parent) { + // We have duplication reservations for the same global key. + final Element older = keyToParent[key]!; + final Element newer = parent; + final FlutterError error; + if (older.toString() != newer.toString()) { + error = FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Multiple widgets used the same GlobalKey.'), + ErrorDescription( + 'The key $key was used by multiple widgets. The parents of those widgets were:\n' + '- $older\n' + '- $newer\n' + 'A GlobalKey can only be specified on one widget at a time in the widget tree.', + ), + ]); + } else { + error = FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Multiple widgets used the same GlobalKey.'), + ErrorDescription( + 'The key $key was used by multiple widgets. The parents of those widgets were ' + 'different widgets that both had the following description:\n' + ' $parent\n' + 'A GlobalKey can only be specified on one widget at a time in the widget tree.', + ), + ]); + } + // Fix the tree by removing the duplicated child from one of its + // parents to resolve the duplicated key issue. This allows us to + // tear down the tree during testing without producing additional + // misleading exceptions. + if (child._parent != older) { + older.visitChildren((Element currentChild) { + if (currentChild == child) { + older.forgetChild(child); + } + }); + } + if (child._parent != newer) { + newer.visitChildren((Element currentChild) { + if (currentChild == child) { + newer.forgetChild(child); + } + }); + } + throw error; + } else { + keyToParent[key] = parent; + } + }); + }); + _debugGlobalKeyReservations?.clear(); + return true; + }()); + } + + void _debugVerifyIllFatedPopulation() { + assert(() { + Map<GlobalKey, Set<Element>>? duplicates; + for (final Element element in _debugIllFatedElements ?? const <Element>{}) { + if (element._lifecycleState != _ElementLifecycle.defunct) { + assert(element.widget.key != null); + final GlobalKey key = element.widget.key! as GlobalKey; + assert(_globalKeyRegistry.containsKey(key)); + duplicates ??= <GlobalKey, Set<Element>>{}; + // Uses ordered set to produce consistent error message. + final Set<Element> elements = duplicates.putIfAbsent(key, () => <Element>{}); + elements.add(element); + elements.add(_globalKeyRegistry[key]!); + } + } + _debugIllFatedElements?.clear(); + if (duplicates != null) { + final List<DiagnosticsNode> information = <DiagnosticsNode>[]; + information.add(ErrorSummary('Multiple widgets used the same GlobalKey.')); + for (final GlobalKey key in duplicates.keys) { + final Set<Element> elements = duplicates[key]!; + // TODO(jacobr): this will omit the '- ' before each widget name and + // use the more standard whitespace style instead. Please let me know + // if the '- ' style is a feature we want to maintain and we can add + // another tree style that supports it. I also see '* ' in some places + // so it would be nice to unify and normalize. + information.add(Element.describeElements('The key $key was used by ${elements.length} widgets', elements)); + } + information.add(ErrorDescription('A GlobalKey can only be specified on one widget at a time in the widget tree.')); + throw FlutterError.fromParts(information); + } + return true; + }()); + } + + /// Complete the element build pass by unmounting any elements that are no + /// longer active. + /// + /// This is called by [WidgetsBinding.drawFrame]. + /// + /// In debug mode, this also runs some sanity checks, for example checking for + /// duplicate global keys. + /// + /// After the current call stack unwinds, a microtask that notifies listeners + /// about changes to global keys will run. + @pragma('vm:notify-debugger-on-exception') + void finalizeTree() { + if (!kReleaseMode) { + FlutterTimeline.startSync('FINALIZE TREE'); + } + try { + lockState(_inactiveElements._unmountAll); // this unregisters the GlobalKeys + assert(() { + try { + _debugVerifyGlobalKeyReservation(); + _debugVerifyIllFatedPopulation(); + if (_debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans != null && + _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans!.isNotEmpty) { + final Set<GlobalKey> keys = HashSet<GlobalKey>(); + for (final Element element in _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans!.keys) { + if (element._lifecycleState != _ElementLifecycle.defunct) { + keys.addAll(_debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans![element]!); + } + } + if (keys.isNotEmpty) { + final Map<String, int> keyStringCount = HashMap<String, int>(); + for (final String key in keys.map<String>((GlobalKey key) => key.toString())) { + if (keyStringCount.containsKey(key)) { + keyStringCount.update(key, (int value) => value + 1); + } else { + keyStringCount[key] = 1; + } + } + final List<String> keyLabels = <String>[]; + keyStringCount.forEach((String key, int count) { + if (count == 1) { + keyLabels.add(key); + } else { + keyLabels.add('$key ($count different affected keys had this toString representation)'); + } + }); + final Iterable<Element> elements = _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans!.keys; + final Map<String, int> elementStringCount = HashMap<String, int>(); + for (final String element in elements.map<String>((Element element) => element.toString())) { + if (elementStringCount.containsKey(element)) { + elementStringCount.update(element, (int value) => value + 1); + } else { + elementStringCount[element] = 1; + } + } + final List<String> elementLabels = <String>[]; + elementStringCount.forEach((String element, int count) { + if (count == 1) { + elementLabels.add(element); + } else { + elementLabels.add('$element ($count different affected elements had this toString representation)'); + } + }); + assert(keyLabels.isNotEmpty); + final String the = keys.length == 1 ? ' the' : ''; + final String s = keys.length == 1 ? '' : 's'; + final String were = keys.length == 1 ? 'was' : 'were'; + final String their = keys.length == 1 ? 'its' : 'their'; + final String respective = elementLabels.length == 1 ? '' : ' respective'; + final String those = keys.length == 1 ? 'that' : 'those'; + final String s2 = elementLabels.length == 1 ? '' : 's'; + final String those2 = elementLabels.length == 1 ? 'that' : 'those'; + final String they = elementLabels.length == 1 ? 'it' : 'they'; + final String think = elementLabels.length == 1 ? 'thinks' : 'think'; + final String are = elementLabels.length == 1 ? 'is' : 'are'; + // TODO(jacobr): make this error more structured to better expose which widgets had problems. + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Duplicate GlobalKey$s detected in widget tree.'), + // TODO(jacobr): refactor this code so the elements are clickable + // in GUI debug tools. + ErrorDescription( + 'The following GlobalKey$s $were specified multiple times in the widget tree. This will lead to ' + 'parts of the widget tree being truncated unexpectedly, because the second time a key is seen, ' + 'the previous instance is moved to the new location. The key$s $were:\n' + '- ${keyLabels.join("\n ")}\n' + 'This was determined by noticing that after$the widget$s with the above global key$s $were moved ' + 'out of $their$respective previous parent$s2, $those2 previous parent$s2 never updated during this frame, meaning ' + 'that $they either did not update at all or updated before the widget$s $were moved, in either case ' + 'implying that $they still $think that $they should have a child with $those global key$s.\n' + 'The specific parent$s2 that did not update after having one or more children forcibly removed ' + 'due to GlobalKey reparenting $are:\n' + '- ${elementLabels.join("\n ")}' + '\nA GlobalKey can only be specified on one widget at a time in the widget tree.', + ), + ]); + } + } + } finally { + _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans?.clear(); + } + return true; + }()); + } catch (e, stack) { + // Catching the exception directly to avoid activating the ErrorWidget. + // Since the tree is in a broken state, adding the ErrorWidget would + // cause more exceptions. + _reportException(ErrorSummary('while finalizing the widget tree'), e, stack); + } finally { + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + } + } + + /// Cause the entire subtree rooted at the given [Element] to be entirely + /// rebuilt. This is used by development tools when the application code has + /// changed and is being hot-reloaded, to cause the widget tree to pick up any + /// changed implementations. + /// + /// This is expensive and should not be called except during development. + void reassemble(Element root) { + if (!kReleaseMode) { + FlutterTimeline.startSync('Preparing Hot Reload (widgets)'); + } + try { + assert(root._parent == null); + assert(root.owner == this); + root.reassemble(); + } finally { + if (!kReleaseMode) { + FlutterTimeline.finishSync(); + } + } + } +} + +/// Mixin this class to allow receiving [Notification] objects dispatched by +/// child elements. +/// +/// See also: +/// * [NotificationListener], for a widget that allows consuming notifications. +mixin NotifiableElementMixin on Element { + /// Called when a notification of the appropriate type arrives at this + /// location in the tree. + /// + /// Return true to cancel the notification bubbling. Return false to + /// allow the notification to continue to be dispatched to further ancestors. + bool onNotification(Notification notification); + + @override + void attachNotificationTree() { + _notificationTree = _NotificationNode(_parent?._notificationTree, this); + } +} + +class _NotificationNode { + _NotificationNode(this.parent, this.current); + + NotifiableElementMixin? current; + _NotificationNode? parent; + + void dispatchNotification(Notification notification) { + if (current?.onNotification(notification) ?? true) { + return; + } + parent?.dispatchNotification(notification); + } +} + +bool _isProfileBuildsEnabledFor(Widget widget) { + return debugProfileBuildsEnabled || + (debugProfileBuildsEnabledUserWidgets && + debugIsWidgetLocalCreation(widget)); +} + +/// An instantiation of a [Widget] at a particular location in the tree. +/// +/// Widgets describe how to configure a subtree but the same widget can be used +/// to configure multiple subtrees simultaneously because widgets are immutable. +/// An [Element] represents the use of a widget to configure a specific location +/// in the tree. Over time, the widget associated with a given element can +/// change, for example, if the parent widget rebuilds and creates a new widget +/// for this location. +/// +/// Elements form a tree. Most elements have a unique child, but some widgets +/// (e.g., subclasses of [RenderObjectElement]) can have multiple children. +/// +/// Elements have the following lifecycle: +/// +/// * The framework creates an element by calling [Widget.createElement] on the +/// widget that will be used as the element's initial configuration. +/// * The framework calls [mount] to add the newly created element to the tree +/// at a given slot in a given parent. The [mount] method is responsible for +/// inflating any child widgets and calling [attachRenderObject] as +/// necessary to attach any associated render objects to the render tree. +/// * At this point, the element is considered "active" and might appear on +/// screen. +/// * At some point, the parent might decide to change the widget used to +/// configure this element, for example because the parent rebuilt with new +/// state. When this happens, the framework will call [update] with the new +/// widget. The new widget will always have the same [runtimeType] and key as +/// old widget. If the parent wishes to change the [runtimeType] or key of +/// the widget at this location in the tree, it can do so by unmounting this +/// element and inflating the new widget at this location. +/// * At some point, an ancestor might decide to remove this element (or an +/// intermediate ancestor) from the tree, which the ancestor does by calling +/// [deactivateChild] on itself. Deactivating the intermediate ancestor will +/// remove that element's render object from the render tree and add this +/// element to the [owner]'s list of inactive elements, causing the framework +/// to call [deactivate] on this element. +/// * At this point, the element is considered "inactive" and will not appear +/// on screen. An element can remain in the inactive state only until +/// the end of the current animation frame. At the end of the animation +/// frame, any elements that are still inactive will be unmounted. +/// * If the element gets reincorporated into the tree (e.g., because it or one +/// of its ancestors has a global key that is reused), the framework will +/// remove the element from the [owner]'s list of inactive elements, call +/// [activate] on the element, and reattach the element's render object to +/// the render tree. (At this point, the element is again considered "active" +/// and might appear on screen.) +/// * If the element does not get reincorporated into the tree by the end of +/// the current animation frame, the framework will call [unmount] on the +/// element. +/// * At this point, the element is considered "defunct" and will not be +/// incorporated into the tree in the future. +abstract class Element extends DiagnosticableTree implements BuildContext { + /// Creates an element that uses the given widget as its configuration. + /// + /// Typically called by an override of [Widget.createElement]. + Element(Widget widget) + : _widget = widget { + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: _flutterWidgetsLibrary, + className: '$Element', + object: this, + ); + } + } + + Element? _parent; + _NotificationNode? _notificationTree; + + /// Compare two widgets for equality. + /// + /// When a widget is rebuilt with another that compares equal according + /// to `operator ==`, it is assumed that the update is redundant and the + /// work to update that branch of the tree is skipped. + /// + /// It is generally discouraged to override `operator ==` on any widget that + /// has children, since a correct implementation would have to defer to the + /// children's equality operator also, and that is an O(N²) operation: each + /// child would need to itself walk all its children, each step of the tree. + /// + /// It is sometimes reasonable for a leaf widget (one with no children) to + /// implement this method, if rebuilding the widget is known to be much more + /// expensive than checking the widgets' parameters for equality and if the + /// widget is expected to often be rebuilt with identical parameters. + /// + /// In general, however, it is more efficient to cache the widgets used + /// in a build method if it is known that they will not change. + @nonVirtual + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes, hash_and_equals + bool operator ==(Object other) => identical(this, other); + + /// Information set by parent to define where this child fits in its parent's + /// child list. + /// + /// A child widget's slot is determined when the parent's [updateChild] method + /// is called to inflate the child widget. See [RenderObjectElement] for more + /// details on slots. + Object? get slot => _slot; + Object? _slot; + + /// An integer that is guaranteed to be greater than the parent's, if any. + /// The element at the root of the tree must have a depth greater than 0. + int get depth { + assert(() { + if (_lifecycleState == _ElementLifecycle.initial) { + throw FlutterError('Depth is only available when element has been mounted.'); + } + return true; + }()); + return _depth; + } + late int _depth; + + /// Returns result < 0 when [a] < [b], result == 0 when [a] == [b], result > 0 + /// when [a] > [b]. + static int _sort(Element a, Element b) { + final int diff = a.depth - b.depth; + // If depths are not equal, return the difference. + if (diff != 0) { + return diff; + } + // If the `dirty` values are not equal, sort with non-dirty elements being + // less than dirty elements. + final bool isBDirty = b.dirty; + if (a.dirty != isBDirty) { + return isBDirty ? -1 : 1; + } + // Otherwise, `depth`s and `dirty`s are equal. + return 0; + } + + // Return a numeric encoding of the specific `Element` concrete subtype. + // This is used in `Element.updateChild` to determine if a hot reload modified the + // superclass of a mounted element's configuration. The encoding of each `Element` + // must match the corresponding `Widget` encoding in `Widget._debugConcreteSubtype`. + static int _debugConcreteSubtype(Element element) { + return element is StatefulElement ? 1 : + element is StatelessElement ? 2 : + 0; + } + + /// The configuration for this element. + /// + /// Avoid overriding this field on [Element] subtypes to provide a more + /// specific widget type (i.e. [StatelessElement] and [StatelessWidget]). + /// Instead, cast at any call sites where the more specific type is required. + /// This avoids significant cast overhead on the getter which is accessed + /// throughout the framework internals during the build phase - and for which + /// the more specific type information is not used. + @override + Widget get widget => _widget!; + Widget? _widget; + + @override + bool get mounted => _widget != null; + + /// Returns true if the Element is defunct. + /// + /// This getter always returns false in profile and release builds. + /// See the lifecycle documentation for [Element] for additional information. + bool get debugIsDefunct { + bool isDefunct = false; + assert(() { + isDefunct = _lifecycleState == _ElementLifecycle.defunct; + return true; + }()); + return isDefunct; + } + + /// Returns true if the Element is active. + /// + /// This getter always returns false in profile and release builds. + /// See the lifecycle documentation for [Element] for additional information. + bool get debugIsActive { + bool isActive = false; + assert(() { + isActive = _lifecycleState == _ElementLifecycle.active; + return true; + }()); + return isActive; + } + + /// The object that manages the lifecycle of this element. + @override + BuildOwner? get owner => _owner; + BuildOwner? _owner; + + /// {@template flutter.widgets.Element.reassemble} + /// Called whenever the application is reassembled during debugging, for + /// example during hot reload. + /// + /// This method should rerun any initialization logic that depends on global + /// state, for example, image loading from asset bundles (since the asset + /// bundle may have changed). + /// + /// This function will only be called during development. In release builds, + /// the `ext.flutter.reassemble` hook is not available, and so this code will + /// never execute. + /// + /// Implementers should not rely on any ordering for hot reload source update, + /// reassemble, and build methods after a hot reload has been initiated. It is + /// possible that a [Timer] (e.g. an [Animation]) or a debugging session + /// attached to the isolate could trigger a build with reloaded code _before_ + /// reassemble is called. Code that expects preconditions to be set by + /// reassemble after a hot reload must be resilient to being called out of + /// order, e.g. by fizzling instead of throwing. That said, once reassemble is + /// called, build will be called after it at least once. + /// {@endtemplate} + /// + /// See also: + /// + /// * [State.reassemble] + /// * [BindingBase.reassembleApplication] + /// * [Image], which uses this to reload images. + @mustCallSuper + @protected + void reassemble() { + markNeedsBuild(); + visitChildren((Element child) { + child.reassemble(); + }); + } + + bool _debugIsInScope(Element target) { + Element? current = this; + while (current != null) { + if (target == current) { + return true; + } + current = current._parent; + } + return false; + } + + /// The render object at (or below) this location in the tree. + /// + /// If this object is a [RenderObjectElement], the render object is the one at + /// this location in the tree. Otherwise, this getter will walk down the tree + /// until it finds a [RenderObjectElement]. + /// + /// Some locations in the tree are not backed by a render object. In those + /// cases, this getter returns null. This can happen, if the element is + /// located outside of a [View] since only the element subtree rooted in a + /// view has a render tree associated with it. + RenderObject? get renderObject { + Element? current = this; + while (current != null) { + if (current._lifecycleState == _ElementLifecycle.defunct) { + break; + } else if (current is RenderObjectElement) { + return current.renderObject; + } else { + current = current.renderObjectAttachingChild; + } + } + return null; + } + + /// Returns the child of this [Element] that will insert a [RenderObject] into + /// an ancestor of this Element to construct the render tree. + /// + /// Returns null if this Element doesn't have any children who need to attach + /// a [RenderObject] to an ancestor of this [Element]. A [RenderObjectElement] + /// will therefore return null because its children insert their + /// [RenderObject]s into the [RenderObjectElement] itself and not into an + /// ancestor of the [RenderObjectElement]. + /// + /// Furthermore, this may return null for [Element]s that hoist their own + /// independent render tree and do not extend the ancestor render tree. + @protected + Element? get renderObjectAttachingChild { + Element? next; + visitChildren((Element child) { + assert(next == null); // This verifies that there's only one child. + next = child; + }); + return next; + } + + @override + List<DiagnosticsNode> describeMissingAncestor({ required Type expectedAncestorType }) { + final List<DiagnosticsNode> information = <DiagnosticsNode>[]; + final List<Element> ancestors = <Element>[]; + visitAncestorElements((Element element) { + ancestors.add(element); + return true; + }); + + information.add(DiagnosticsProperty<Element>( + 'The specific widget that could not find a $expectedAncestorType ancestor was', + this, + style: DiagnosticsTreeStyle.errorProperty, + )); + + if (ancestors.isNotEmpty) { + information.add(describeElements('The ancestors of this widget were', ancestors)); + } else { + information.add(ErrorDescription( + 'This widget is the root of the tree, so it has no ' + 'ancestors, let alone a "$expectedAncestorType" ancestor.', + )); + } + return information; + } + + /// Returns a list of [Element]s from the current build context to the error report. + static DiagnosticsNode describeElements(String name, Iterable<Element> elements) { + return DiagnosticsBlock( + name: name, + children: elements.map<DiagnosticsNode>((Element element) => DiagnosticsProperty<Element>('', element)).toList(), + allowTruncate: true, + ); + } + + @override + DiagnosticsNode describeElement(String name, {DiagnosticsTreeStyle style = DiagnosticsTreeStyle.errorProperty}) { + return DiagnosticsProperty<Element>(name, this, style: style); + } + + @override + DiagnosticsNode describeWidget(String name, {DiagnosticsTreeStyle style = DiagnosticsTreeStyle.errorProperty}) { + return DiagnosticsProperty<Element>(name, this, style: style); + } + + @override + DiagnosticsNode describeOwnershipChain(String name) { + // TODO(jacobr): make this structured so clients can support clicks on + // individual entries. For example, is this an iterable with arrows as + // separators? + return StringProperty(name, debugGetCreatorChain(10)); + } + + // This is used to verify that Element objects move through life in an + // orderly fashion. + _ElementLifecycle _lifecycleState = _ElementLifecycle.initial; + + /// Calls the argument for each child. Must be overridden by subclasses that + /// support having children. + /// + /// There is no guaranteed order in which the children will be visited, though + /// it should be consistent over time. + /// + /// Calling this during build is dangerous: the child list might still be + /// being updated at that point, so the children might not be constructed yet, + /// or might be old children that are going to be replaced. This method should + /// only be called if it is provable that the children are available. + void visitChildren(ElementVisitor visitor) { } + + /// Calls the argument for each child considered onstage. + /// + /// Classes like [Offstage] and [Overlay] override this method to hide their + /// children. + /// + /// Being onstage affects the element's discoverability during testing when + /// you use Flutter's [Finder] objects. For example, when you instruct the + /// test framework to tap on a widget, by default the finder will look for + /// onstage elements and ignore the offstage ones. + /// + /// The default implementation defers to [visitChildren] and therefore treats + /// the element as onstage. + /// + /// See also: + /// + /// * [Offstage] widget that hides its children. + /// * [Finder] that skips offstage widgets by default. + /// * [RenderObject.visitChildrenForSemantics], in contrast to this method, + /// designed specifically for excluding parts of the UI from the semantics + /// tree. + void debugVisitOnstageChildren(ElementVisitor visitor) => visitChildren(visitor); + + /// Wrapper around [visitChildren] for [BuildContext]. + @override + void visitChildElements(ElementVisitor visitor) { + assert(() { + if (owner == null || !owner!._debugStateLocked) { + return true; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('visitChildElements() called during build.'), + ErrorDescription( + "The BuildContext.visitChildElements() method can't be called during " + 'build because the child list is still being updated at that point, ' + 'so the children might not be constructed yet, or might be old children ' + 'that are going to be replaced.', + ), + ]); + }()); + visitChildren(visitor); + } + + /// Update the given child with the given new configuration. + /// + /// This method is the core of the widgets system. It is called each time we + /// are to add, update, or remove a child based on an updated configuration. + /// + /// The `newSlot` argument specifies the new value for this element's [slot]. + /// + /// If the `child` is null, and the `newWidget` is not null, then we have a new + /// child for which we need to create an [Element], configured with `newWidget`. + /// + /// If the `newWidget` is null, and the `child` is not null, then we need to + /// remove it because it no longer has a configuration. + /// + /// If neither are null, then we need to update the `child`'s configuration to + /// be the new configuration given by `newWidget`. If `newWidget` can be given + /// to the existing child (as determined by [Widget.canUpdate]), then it is so + /// given. Otherwise, the old child needs to be disposed and a new child + /// created for the new configuration. + /// + /// If both are null, then we don't have a child and won't have a child, so we + /// do nothing. + /// + /// The [updateChild] method returns the new child, if it had to create one, + /// or the child that was passed in, if it just had to update the child, or + /// null, if it removed the child and did not replace it. + /// + /// The following table summarizes the above: + /// + /// | | **newWidget == null** | **newWidget != null** | + /// | :-----------------: | :--------------------- | :---------------------- | + /// | **child == null** | Returns null. | Returns new [Element]. | + /// | **child != null** | Old child is removed, returns null. | Old child updated if possible, returns child or new [Element]. | + /// + /// The `newSlot` argument is used only if `newWidget` is not null. If `child` + /// is null (or if the old child cannot be updated), then the `newSlot` is + /// given to the new [Element] that is created for the child, via + /// [inflateWidget]. If `child` is not null (and the old child _can_ be + /// updated), then the `newSlot` is given to [updateSlotForChild] to update + /// its slot, in case it has moved around since it was last built. + /// + /// See the [RenderObjectElement] documentation for more information on slots. + @protected + @pragma('vm:prefer-inline') + Element? updateChild(Element? child, Widget? newWidget, Object? newSlot) { + if (newWidget == null) { + if (child != null) { + deactivateChild(child); + } + return null; + } + + final Element newChild; + if (child != null) { + bool hasSameSuperclass = true; + // When the type of a widget is changed between Stateful and Stateless via + // hot reload, the element tree will end up in a partially invalid state. + // That is, if the widget was a StatefulWidget and is now a StatelessWidget, + // then the element tree currently contains a StatefulElement that is incorrectly + // referencing a StatelessWidget (and likewise with StatelessElement). + // + // To avoid crashing due to type errors, we need to gently guide the invalid + // element out of the tree. To do so, we ensure that the `hasSameSuperclass` condition + // returns false which prevents us from trying to update the existing element + // incorrectly. + // + // For the case where the widget becomes Stateful, we also need to avoid + // accessing `StatelessElement.widget` as the cast on the getter will + // cause a type error to be thrown. Here we avoid that by short-circuiting + // the `Widget.canUpdate` check once `hasSameSuperclass` is false. + assert(() { + final int oldElementClass = Element._debugConcreteSubtype(child); + final int newWidgetClass = Widget._debugConcreteSubtype(newWidget); + hasSameSuperclass = oldElementClass == newWidgetClass; + return true; + }()); + if (hasSameSuperclass && child.widget == newWidget) { + // We don't insert a timeline event here, because otherwise it's + // confusing that widgets that "don't update" (because they didn't + // change) get "charged" on the timeline. + if (child.slot != newSlot) { + updateSlotForChild(child, newSlot); + } + newChild = child; + } else if (hasSameSuperclass && Widget.canUpdate(child.widget, newWidget)) { + if (child.slot != newSlot) { + updateSlotForChild(child, newSlot); + } + final bool isTimelineTracked = !kReleaseMode && _isProfileBuildsEnabledFor(newWidget); + if (isTimelineTracked) { + Map<String, String>? debugTimelineArguments; + assert(() { + if (kDebugMode && debugEnhanceBuildTimelineArguments) { + debugTimelineArguments = newWidget.toDiagnosticsNode().toTimelineArguments(); + } + return true; + }()); + FlutterTimeline.startSync( + '${newWidget.runtimeType}', + arguments: debugTimelineArguments, + ); + } + child.update(newWidget); + if (isTimelineTracked) { + FlutterTimeline.finishSync(); + } + assert(child.widget == newWidget); + assert(() { + child.owner!._debugElementWasRebuilt(child); + return true; + }()); + newChild = child; + } else { + deactivateChild(child); + assert(child._parent == null); + // The [debugProfileBuildsEnabled] code for this branch is inside + // [inflateWidget], since some [Element]s call [inflateWidget] directly + // instead of going through [updateChild]. + newChild = inflateWidget(newWidget, newSlot); + } + } else { + // The [debugProfileBuildsEnabled] code for this branch is inside + // [inflateWidget], since some [Element]s call [inflateWidget] directly + // instead of going through [updateChild]. + newChild = inflateWidget(newWidget, newSlot); + } + + assert(() { + if (child != null) { + _debugRemoveGlobalKeyReservation(child); + } + final Key? key = newWidget.key; + if (key is GlobalKey) { + assert(owner != null); + owner!._debugReserveGlobalKeyFor(this, newChild, key); + } + return true; + }()); + + return newChild; + } + + /// Updates the children of this element to use new widgets. + /// + /// Attempts to update the given old children list using the given new + /// widgets, removing obsolete elements and introducing new ones as necessary, + /// and then returns the new child list. + /// + /// During this function the `oldChildren` list must not be modified. If the + /// caller wishes to remove elements from `oldChildren` reentrantly while + /// this function is on the stack, the caller can supply a `forgottenChildren` + /// argument, which can be modified while this function is on the stack. + /// Whenever this function reads from `oldChildren`, this function first + /// checks whether the child is in `forgottenChildren`. If it is, the function + /// acts as if the child was not in `oldChildren`. + /// + /// This function is a convenience wrapper around [updateChild], which updates + /// each individual child. If `slots` is non-null, the value for the `newSlot` + /// argument of [updateChild] is retrieved from that list using the index that + /// the currently processed `child` corresponds to in the `newWidgets` list + /// (`newWidgets` and `slots` must have the same length). If `slots` is null, + /// an [IndexedSlot<Element>] is used as the value for the `newSlot` argument. + /// In that case, [IndexedSlot.index] is set to the index that the currently + /// processed `child` corresponds to in the `newWidgets` list and + /// [IndexedSlot.value] is set to the [Element] of the previous widget in that + /// list (or null if it is the first child). + /// + /// When the [slot] value of an [Element] changes, its + /// associated [renderObject] needs to move to a new position in the child + /// list of its parents. If that [RenderObject] organizes its children in a + /// linked list (as is done by the [ContainerRenderObjectMixin]) this can + /// be implemented by re-inserting the child [RenderObject] into the + /// list after the [RenderObject] associated with the [Element] provided as + /// [IndexedSlot.value] in the [slot] object. + /// + /// Using the previous sibling as a [slot] is not enough, though, because + /// child [RenderObject]s are only moved around when the [slot] of their + /// associated [RenderObjectElement]s is updated. When the order of child + /// [Element]s is changed, some elements in the list may move to a new index + /// but still have the same previous sibling. For example, when + /// `[e1, e2, e3, e4]` is changed to `[e1, e3, e4, e2]` the element e4 + /// continues to have e3 as a previous sibling even though its index in the list + /// has changed and its [RenderObject] needs to move to come before e2's + /// [RenderObject]. In order to trigger this move, a new [slot] value needs to + /// be assigned to its [Element] whenever its index in its + /// parent's child list changes. Using an [IndexedSlot<Element>] achieves + /// exactly that and also ensures that the underlying parent [RenderObject] + /// knows where a child needs to move to in a linked list by providing its new + /// previous sibling. + @protected + List<Element> updateChildren(List<Element> oldChildren, List<Widget> newWidgets, { Set<Element>? forgottenChildren, List<Object?>? slots }) { + assert(slots == null || newWidgets.length == slots.length); + + Element? replaceWithNullIfForgotten(Element child) { + return forgottenChildren != null && forgottenChildren.contains(child) ? null : child; + } + + Object? slotFor(int newChildIndex, Element? previousChild) { + return slots != null + ? slots[newChildIndex] + : IndexedSlot<Element?>(newChildIndex, previousChild); + } + + // This attempts to diff the new child list (newWidgets) with + // the old child list (oldChildren), and produce a new list of elements to + // be the new list of child elements of this element. The called of this + // method is expected to update this render object accordingly. + + // The cases it tries to optimize for are: + // - the old list is empty + // - the lists are identical + // - there is an insertion or removal of one or more widgets in + // only one place in the list + // If a widget with a key is in both lists, it will be synced. + // Widgets without keys might be synced but there is no guarantee. + + // The general approach is to sync the entire new list backwards, as follows: + // 1. Walk the lists from the top, syncing nodes, until you no longer have + // matching nodes. + // 2. Walk the lists from the bottom, without syncing nodes, until you no + // longer have matching nodes. We'll sync these nodes at the end. We + // don't sync them now because we want to sync all the nodes in order + // from beginning to end. + // At this point we narrowed the old and new lists to the point + // where the nodes no longer match. + // 3. Walk the narrowed part of the old list to get the list of + // keys and sync null with non-keyed items. + // 4. Walk the narrowed part of the new list forwards: + // * Sync non-keyed items with null + // * Sync keyed items with the source if it exists, else with null. + // 5. Walk the bottom of the list again, syncing the nodes. + // 6. Sync null with any items in the list of keys that are still + // mounted. + + int newChildrenTop = 0; + int oldChildrenTop = 0; + int newChildrenBottom = newWidgets.length - 1; + int oldChildrenBottom = oldChildren.length - 1; + + final List<Element> newChildren = List<Element>.filled(newWidgets.length, _NullElement.instance); + + Element? previousChild; + + // Update the top of the list. + while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) { + final Element? oldChild = replaceWithNullIfForgotten(oldChildren[oldChildrenTop]); + final Widget newWidget = newWidgets[newChildrenTop]; + assert(oldChild == null || oldChild._lifecycleState == _ElementLifecycle.active); + if (oldChild == null || !Widget.canUpdate(oldChild.widget, newWidget)) { + break; + } + final Element newChild = updateChild(oldChild, newWidget, slotFor(newChildrenTop, previousChild))!; + assert(newChild._lifecycleState == _ElementLifecycle.active); + newChildren[newChildrenTop] = newChild; + previousChild = newChild; + newChildrenTop += 1; + oldChildrenTop += 1; + } + + // Scan the bottom of the list. + while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) { + final Element? oldChild = replaceWithNullIfForgotten(oldChildren[oldChildrenBottom]); + final Widget newWidget = newWidgets[newChildrenBottom]; + assert(oldChild == null || oldChild._lifecycleState == _ElementLifecycle.active); + if (oldChild == null || !Widget.canUpdate(oldChild.widget, newWidget)) { + break; + } + oldChildrenBottom -= 1; + newChildrenBottom -= 1; + } + + // Scan the old children in the middle of the list. + final bool haveOldChildren = oldChildrenTop <= oldChildrenBottom; + Map<Key, Element>? oldKeyedChildren; + if (haveOldChildren) { + oldKeyedChildren = <Key, Element>{}; + while (oldChildrenTop <= oldChildrenBottom) { + final Element? oldChild = replaceWithNullIfForgotten(oldChildren[oldChildrenTop]); + assert(oldChild == null || oldChild._lifecycleState == _ElementLifecycle.active); + if (oldChild != null) { + if (oldChild.widget.key != null) { + oldKeyedChildren[oldChild.widget.key!] = oldChild; + } else { + deactivateChild(oldChild); + } + } + oldChildrenTop += 1; + } + } + + // Update the middle of the list. + while (newChildrenTop <= newChildrenBottom) { + Element? oldChild; + final Widget newWidget = newWidgets[newChildrenTop]; + if (haveOldChildren) { + final Key? key = newWidget.key; + if (key != null) { + oldChild = oldKeyedChildren![key]; + if (oldChild != null) { + if (Widget.canUpdate(oldChild.widget, newWidget)) { + // we found a match! + // remove it from oldKeyedChildren so we don't unsync it later + oldKeyedChildren.remove(key); + } else { + // Not a match, let's pretend we didn't see it for now. + oldChild = null; + } + } + } + } + assert(oldChild == null || Widget.canUpdate(oldChild.widget, newWidget)); + final Element newChild = updateChild(oldChild, newWidget, slotFor(newChildrenTop, previousChild))!; + assert(newChild._lifecycleState == _ElementLifecycle.active); + assert(oldChild == newChild || oldChild == null || oldChild._lifecycleState != _ElementLifecycle.active); + newChildren[newChildrenTop] = newChild; + previousChild = newChild; + newChildrenTop += 1; + } + + // We've scanned the whole list. + assert(oldChildrenTop == oldChildrenBottom + 1); + assert(newChildrenTop == newChildrenBottom + 1); + assert(newWidgets.length - newChildrenTop == oldChildren.length - oldChildrenTop); + newChildrenBottom = newWidgets.length - 1; + oldChildrenBottom = oldChildren.length - 1; + + // Update the bottom of the list. + while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) { + final Element oldChild = oldChildren[oldChildrenTop]; + assert(replaceWithNullIfForgotten(oldChild) != null); + assert(oldChild._lifecycleState == _ElementLifecycle.active); + final Widget newWidget = newWidgets[newChildrenTop]; + assert(Widget.canUpdate(oldChild.widget, newWidget)); + final Element newChild = updateChild(oldChild, newWidget, slotFor(newChildrenTop, previousChild))!; + assert(newChild._lifecycleState == _ElementLifecycle.active); + assert(oldChild == newChild || oldChild._lifecycleState != _ElementLifecycle.active); + newChildren[newChildrenTop] = newChild; + previousChild = newChild; + newChildrenTop += 1; + oldChildrenTop += 1; + } + + // Clean up any of the remaining middle nodes from the old list. + if (haveOldChildren && oldKeyedChildren!.isNotEmpty) { + for (final Element oldChild in oldKeyedChildren.values) { + if (forgottenChildren == null || !forgottenChildren.contains(oldChild)) { + deactivateChild(oldChild); + } + } + } + assert(newChildren.every((Element element) => element is! _NullElement)); + return newChildren; + } + + /// Add this element to the tree in the given slot of the given parent. + /// + /// The framework calls this function when a newly created element is added to + /// the tree for the first time. Use this method to initialize state that + /// depends on having a parent. State that is independent of the parent can + /// more easily be initialized in the constructor. + /// + /// This method transitions the element from the "initial" lifecycle state to + /// the "active" lifecycle state. + /// + /// Subclasses that override this method are likely to want to also override + /// [update], [visitChildren], [RenderObjectElement.insertRenderObjectChild], + /// [RenderObjectElement.moveRenderObjectChild], and + /// [RenderObjectElement.removeRenderObjectChild]. + /// + /// Implementations of this method should start with a call to the inherited + /// method, as in `super.mount(parent, newSlot)`. + @mustCallSuper + void mount(Element? parent, Object? newSlot) { + assert(_lifecycleState == _ElementLifecycle.initial); + assert(_parent == null); + assert(parent == null || parent._lifecycleState == _ElementLifecycle.active); + assert(slot == null); + _parent = parent; + _slot = newSlot; + _lifecycleState = _ElementLifecycle.active; + _depth = _parent != null ? _parent!.depth + 1 : 1; + if (parent != null) { + // Only assign ownership if the parent is non-null. If parent is null + // (the root node), the owner should have already been assigned. + // See RootRenderObjectElement.assignOwner(). + _owner = parent.owner; + } + assert(owner != null); + final Key? key = widget.key; + if (key is GlobalKey) { + owner!._registerGlobalKey(key, this); + } + _updateInheritance(); + attachNotificationTree(); + } + + void _debugRemoveGlobalKeyReservation(Element child) { + assert(owner != null); + owner!._debugRemoveGlobalKeyReservationFor(this, child); + } + + /// Change the widget used to configure this element. + /// + /// The framework calls this function when the parent wishes to use a + /// different widget to configure this element. The new widget is guaranteed + /// to have the same [runtimeType] as the old widget. + /// + /// This function is called only during the "active" lifecycle state. + @mustCallSuper + void update(covariant Widget newWidget) { + // This code is hot when hot reloading, so we try to + // only call _AssertionError._evaluateAssertion once. + assert( + _lifecycleState == _ElementLifecycle.active + && newWidget != widget + && Widget.canUpdate(widget, newWidget), + ); + // This Element was told to update and we can now release all the global key + // reservations of forgotten children. We cannot do this earlier because the + // forgotten children still represent global key duplications if the element + // never updates (the forgotten children are not removed from the tree + // until the call to update happens) + assert(() { + _debugForgottenChildrenWithGlobalKey?.forEach(_debugRemoveGlobalKeyReservation); + _debugForgottenChildrenWithGlobalKey?.clear(); + return true; + }()); + _widget = newWidget; + } + + /// Change the slot that the given child occupies in its parent. + /// + /// Called by [MultiChildRenderObjectElement], and other [RenderObjectElement] + /// subclasses that have multiple children, when child moves from one position + /// to another in this element's child list. + @protected + void updateSlotForChild(Element child, Object? newSlot) { + assert(_lifecycleState == _ElementLifecycle.active); + assert(child._parent == this); + void visit(Element element) { + element.updateSlot(newSlot); + final Element? descendant = element.renderObjectAttachingChild; + if (descendant != null) { + visit(descendant); + } + } + visit(child); + } + + /// Called by [updateSlotForChild] when the framework needs to change the slot + /// that this [Element] occupies in its ancestor. + @protected + @mustCallSuper + void updateSlot(Object? newSlot) { + assert(_lifecycleState == _ElementLifecycle.active); + assert(_parent != null); + assert(_parent!._lifecycleState == _ElementLifecycle.active); + _slot = newSlot; + } + + void _updateDepth(int parentDepth) { + final int expectedDepth = parentDepth + 1; + if (_depth < expectedDepth) { + _depth = expectedDepth; + visitChildren((Element child) { + child._updateDepth(expectedDepth); + }); + } + } + + /// Remove [renderObject] from the render tree. + /// + /// The default implementation of this function calls + /// [detachRenderObject] recursively on each child. The + /// [RenderObjectElement.detachRenderObject] override does the actual work of + /// removing [renderObject] from the render tree. + /// + /// This is called by [deactivateChild]. + void detachRenderObject() { + visitChildren((Element child) { + child.detachRenderObject(); + }); + _slot = null; + } + + /// Add [renderObject] to the render tree at the location specified by `newSlot`. + /// + /// The default implementation of this function calls + /// [attachRenderObject] recursively on each child. The + /// [RenderObjectElement.attachRenderObject] override does the actual work of + /// adding [renderObject] to the render tree. + /// + /// The `newSlot` argument specifies the new value for this element's [slot]. + void attachRenderObject(Object? newSlot) { + assert(slot == null); + visitChildren((Element child) { + child.attachRenderObject(newSlot); + }); + _slot = newSlot; + } + + Element? _retakeInactiveElement(GlobalKey key, Widget newWidget) { + // The "inactivity" of the element being retaken here may be forward-looking: if + // we are taking an element with a GlobalKey from an element that currently has + // it as a child, then we know that element will soon no longer have that + // element as a child. The only way that assumption could be false is if the + // global key is being duplicated, and we'll try to track that using the + // _debugTrackElementThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans call below. + final Element? element = key._currentElement; + if (element == null) { + return null; + } + if (!Widget.canUpdate(element.widget, newWidget)) { + return null; + } + assert(() { + if (debugPrintGlobalKeyedWidgetLifecycle) { + debugPrint('Attempting to take $element from ${element._parent ?? "inactive elements list"} to put in $this.'); + } + return true; + }()); + final Element? parent = element._parent; + if (parent != null) { + assert(() { + if (parent == this) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary("A GlobalKey was used multiple times inside one widget's child list."), + DiagnosticsProperty<GlobalKey>('The offending GlobalKey was', key), + parent.describeElement('The parent of the widgets with that key was'), + element.describeElement('The first child to get instantiated with that key became'), + DiagnosticsProperty<Widget>('The second child that was to be instantiated with that key was', widget, style: DiagnosticsTreeStyle.errorProperty), + ErrorDescription('A GlobalKey can only be specified on one widget at a time in the widget tree.'), + ]); + } + parent.owner!._debugTrackElementThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans( + parent, + key, + ); + return true; + }()); + parent.forgetChild(element); + parent.deactivateChild(element); + } + assert(element._parent == null); + owner!._inactiveElements.remove(element); + return element; + } + + /// Create an element for the given widget and add it as a child of this + /// element in the given slot. + /// + /// This method is typically called by [updateChild] but can be called + /// directly by subclasses that need finer-grained control over creating + /// elements. + /// + /// If the given widget has a global key and an element already exists that + /// has a widget with that global key, this function will reuse that element + /// (potentially grafting it from another location in the tree or reactivating + /// it from the list of inactive elements) rather than creating a new element. + /// + /// The `newSlot` argument specifies the new value for this element's [slot]. + /// + /// The element returned by this function will already have been mounted and + /// will be in the "active" lifecycle state. + @protected + @pragma('vm:prefer-inline') + Element inflateWidget(Widget newWidget, Object? newSlot) { + final bool isTimelineTracked = !kReleaseMode && _isProfileBuildsEnabledFor(newWidget); + if (isTimelineTracked) { + Map<String, String>? debugTimelineArguments; + assert(() { + if (kDebugMode && debugEnhanceBuildTimelineArguments) { + debugTimelineArguments = newWidget.toDiagnosticsNode().toTimelineArguments(); + } + return true; + }()); + FlutterTimeline.startSync( + '${newWidget.runtimeType}', + arguments: debugTimelineArguments, + ); + } + + try { + final Key? key = newWidget.key; + if (key is GlobalKey) { + final Element? newChild = _retakeInactiveElement(key, newWidget); + if (newChild != null) { + assert(newChild._parent == null); + assert(() { + _debugCheckForCycles(newChild); + return true; + }()); + try { + newChild._activateWithParent(this, newSlot); + } catch (_) { + // Attempt to do some clean-up if activation fails to leave tree in a reasonable state. + try { + deactivateChild(newChild); + } catch (_) { + // Clean-up failed. Only surface original exception. + } + rethrow; + } + final Element? updatedChild = updateChild(newChild, newWidget, newSlot); + assert(newChild == updatedChild); + return updatedChild!; + } + } + final Element newChild = newWidget.createElement(); + assert(() { + _debugCheckForCycles(newChild); + return true; + }()); + newChild.mount(this, newSlot); + assert(newChild._lifecycleState == _ElementLifecycle.active); + + return newChild; + } finally { + if (isTimelineTracked) { + FlutterTimeline.finishSync(); + } + } + } + + void _debugCheckForCycles(Element newChild) { + assert(newChild._parent == null); + assert(() { + Element node = this; + while (node._parent != null) { + node = node._parent!; + } + assert(node != newChild); // indicates we are about to create a cycle + return true; + }()); + } + + /// Move the given element to the list of inactive elements and detach its + /// render object from the render tree. + /// + /// This method stops the given element from being a child of this element by + /// detaching its render object from the render tree and moving the element to + /// the list of inactive elements. + /// + /// This method (indirectly) calls [deactivate] on the child. + /// + /// The caller is responsible for removing the child from its child model. + /// Typically [deactivateChild] is called by the element itself while it is + /// updating its child model; however, during [GlobalKey] reparenting, the new + /// parent proactively calls the old parent's [deactivateChild], first using + /// [forgetChild] to cause the old parent to update its child model. + @protected + void deactivateChild(Element child) { + assert(child._parent == this); + child._parent = null; + child.detachRenderObject(); + owner!._inactiveElements.add(child); // this eventually calls child.deactivate() + assert(() { + if (debugPrintGlobalKeyedWidgetLifecycle) { + if (child.widget.key is GlobalKey) { + debugPrint('Deactivated $child (keyed child of $this)'); + } + } + return true; + }()); + } + + // The children that have been forgotten by forgetChild. This will be used in + // [update] to remove the global key reservations of forgotten children. + // + // In Profile/Release mode this field is initialized to `null`. The Dart compiler can + // eliminate unused fields, but not their initializers. + @_debugOnly + final Set<Element>? _debugForgottenChildrenWithGlobalKey = kDebugMode ? HashSet<Element>() : null; + + /// Remove the given child from the element's child list, in preparation for + /// the child being reused elsewhere in the element tree. + /// + /// This updates the child model such that, e.g., [visitChildren] does not + /// walk that child anymore. + /// + /// The element will still have a valid parent when this is called, and the + /// child's [Element.slot] value will be valid in the context of that parent. + /// After this is called, [deactivateChild] is called to sever the link to + /// this object. + /// + /// The [update] is responsible for updating or creating the new child that + /// will replace this [child]. + @protected + @mustCallSuper + void forgetChild(Element child) { + // This method is called on the old parent when the given child (with a + // global key) is given a new parent. We cannot remove the global key + // reservation directly in this method because the forgotten child is not + // removed from the tree until this Element is updated in [update]. If + // [update] is never called, the forgotten child still represents a global + // key duplication that we need to catch. + assert(() { + if (child.widget.key is GlobalKey) { + _debugForgottenChildrenWithGlobalKey?.add(child); + } + return true; + }()); + } + + void _activateWithParent(Element parent, Object? newSlot) { + assert(_lifecycleState == _ElementLifecycle.inactive); + _parent = parent; + assert(() { + if (debugPrintGlobalKeyedWidgetLifecycle) { + debugPrint('Reactivating $this (now child of $_parent).'); + } + return true; + }()); + _updateDepth(_parent!.depth); + _activateRecursively(this); + attachRenderObject(newSlot); + assert(_lifecycleState == _ElementLifecycle.active); + } + + static void _activateRecursively(Element element) { + assert(element._lifecycleState == _ElementLifecycle.inactive); + element.activate(); + assert(element._lifecycleState == _ElementLifecycle.active); + element.visitChildren(_activateRecursively); + } + + /// Transition from the "inactive" to the "active" lifecycle state. + /// + /// The framework calls this method when a previously deactivated element has + /// been reincorporated into the tree. The framework does not call this method + /// the first time an element becomes active (i.e., from the "initial" + /// lifecycle state). Instead, the framework calls [mount] in that situation. + /// + /// See the lifecycle documentation for [Element] for additional information. + /// + /// Implementations of this method should start with a call to the inherited + /// method, as in `super.activate()`. + @mustCallSuper + void activate() { + assert(_lifecycleState == _ElementLifecycle.inactive); + assert(owner != null); + final bool hadDependencies = (_dependencies != null && _dependencies!.isNotEmpty) || _hadUnsatisfiedDependencies; + _lifecycleState = _ElementLifecycle.active; + // We unregistered our dependencies in deactivate, but never cleared the list. + // Since we're going to be reused, let's clear our list now. + _dependencies?.clear(); + _hadUnsatisfiedDependencies = false; + _updateInheritance(); + attachNotificationTree(); + if (_dirty) { + owner!.scheduleBuildFor(this); + } + if (hadDependencies) { + didChangeDependencies(); + } + } + + /// Transition from the "active" to the "inactive" lifecycle state. + /// + /// The framework calls this method when a previously active element is moved + /// to the list of inactive elements. While in the inactive state, the element + /// will not appear on screen. The element can remain in the inactive state + /// only until the end of the current animation frame. At the end of the + /// animation frame, if the element has not be reactivated, the framework will + /// unmount the element. + /// + /// This is (indirectly) called by [deactivateChild]. + /// + /// See the lifecycle documentation for [Element] for additional information. + /// + /// Implementations of this method should end with a call to the inherited + /// method, as in `super.deactivate()`. + @mustCallSuper + void deactivate() { + assert(_lifecycleState == _ElementLifecycle.active); + assert(_widget != null); // Use the private property to avoid a CastError during hot reload. + if (_dependencies != null && _dependencies!.isNotEmpty) { + for (final InheritedElement dependency in _dependencies!) { + dependency.removeDependent(this); + } + // For expediency, we don't actually clear the list here, even though it's + // no longer representative of what we are registered with. If we never + // get re-used, it doesn't matter. If we do, then we'll clear the list in + // activate(). The benefit of this is that it allows Element's activate() + // implementation to decide whether to rebuild based on whether we had + // dependencies here. + } + _inheritedElements = null; + _lifecycleState = _ElementLifecycle.inactive; + } + + /// Called, in debug mode, after children have been deactivated (see [deactivate]). + /// + /// This method is not called in release builds. + @mustCallSuper + void debugDeactivated() { + assert(_lifecycleState == _ElementLifecycle.inactive); + } + + /// Transition from the "inactive" to the "defunct" lifecycle state. + /// + /// Called when the framework determines that an inactive element will never + /// be reactivated. At the end of each animation frame, the framework calls + /// [unmount] on any remaining inactive elements, preventing inactive elements + /// from remaining inactive for longer than a single animation frame. + /// + /// After this function is called, the element will not be incorporated into + /// the tree again. + /// + /// Any resources this element holds should be released at this point. For + /// example, [RenderObjectElement.unmount] calls [RenderObject.dispose] and + /// nulls out its reference to the render object. + /// + /// See the lifecycle documentation for [Element] for additional information. + /// + /// Implementations of this method should end with a call to the inherited + /// method, as in `super.unmount()`. + @mustCallSuper + void unmount() { + assert(_lifecycleState == _ElementLifecycle.inactive); + assert(_widget != null); // Use the private property to avoid a CastError during hot reload. + assert(owner != null); + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + // Use the private property to avoid a CastError during hot reload. + final Key? key = _widget?.key; + if (key is GlobalKey) { + owner!._unregisterGlobalKey(key, this); + } + // Release resources to reduce the severity of memory leaks caused by + // defunct, but accidentally retained Elements. + _widget = null; + _dependencies = null; + _lifecycleState = _ElementLifecycle.defunct; + } + + /// Whether the child in the provided `slot` (or one of its descendants) must + /// insert a [RenderObject] into its ancestor [RenderObjectElement] by calling + /// [RenderObjectElement.insertRenderObjectChild] on it. + /// + /// This method is used to define non-rendering zones in the element tree (see + /// [WidgetsBinding] for an explanation of rendering and non-rendering zones): + /// + /// Most branches of the [Element] tree are expected to eventually insert a + /// [RenderObject] into their [RenderObjectElement] ancestor to construct the + /// render tree. However, there is a notable exception: an [Element] may + /// expect that the occupant of a certain child slot creates a new independent + /// render tree and therefore is not allowed to insert a render object into + /// the existing render tree. Those elements must return false from this + /// method for the slot in question to signal to the child in that slot that + /// it must not call [RenderObjectElement.insertRenderObjectChild] on its + /// ancestor. + /// + /// As an example, the element backing the [ViewAnchor] returns false from + /// this method for the [ViewAnchor.view] slot to enforce that it is occupied + /// by e.g. a [View] widget, which will ultimately bootstrap a separate + /// render tree for that view. Another example is the [ViewCollection] widget, + /// which returns false for all its slots for the same reason. + /// + /// Overriding this method is not common, as elements behaving in the way + /// described above are rare. + bool debugExpectsRenderObjectForSlot(Object? slot) => true; + + @override + RenderObject? findRenderObject() { + assert(() { + if (_lifecycleState != _ElementLifecycle.active) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Cannot get renderObject of inactive element.'), + ErrorDescription( + 'In order for an element to have a valid renderObject, it must be ' + 'active, which means it is part of the tree.\n' + 'Instead, this element is in the $_lifecycleState state.\n' + 'If you called this method from a State object, consider guarding ' + 'it with State.mounted.', + ), + describeElement('The findRenderObject() method was called for the following element'), + ]); + } + return true; + }()); + return renderObject; + } + + @override + Size? get size { + assert(() { + if (_lifecycleState != _ElementLifecycle.active) { + // TODO(jacobr): is this a good separation into contract and violation? + // I have added a line of white space. + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Cannot get size of inactive element.'), + ErrorDescription( + 'In order for an element to have a valid size, the element must be ' + 'active, which means it is part of the tree.\n' + 'Instead, this element is in the $_lifecycleState state.', + ), + describeElement('The size getter was called for the following element'), + ]); + } + if (owner!._debugBuilding) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Cannot get size during build.'), + ErrorDescription( + 'The size of this render object has not yet been determined because ' + 'the framework is still in the process of building widgets, which ' + 'means the render tree for this frame has not yet been determined. ' + 'The size getter should only be called from paint callbacks or ' + 'interaction event handlers (e.g. gesture callbacks).', + ), + ErrorSpacer(), + ErrorHint( + 'If you need some sizing information during build to decide which ' + 'widgets to build, consider using a LayoutBuilder widget, which can ' + 'tell you the layout constraints at a given location in the tree. See ' + '<https://api.flutter.dev/flutter/widgets/LayoutBuilder-class.html> ' + 'for more details.', + ), + ErrorSpacer(), + describeElement('The size getter was called for the following element'), + ]); + } + return true; + }()); + final RenderObject? renderObject = findRenderObject(); + assert(() { + if (renderObject == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Cannot get size without a render object.'), + ErrorHint( + 'In order for an element to have a valid size, the element must have ' + 'an associated render object. This element does not have an associated ' + 'render object, which typically means that the size getter was called ' + 'too early in the pipeline (e.g., during the build phase) before the ' + 'framework has created the render tree.', + ), + describeElement('The size getter was called for the following element'), + ]); + } + if (renderObject is RenderSliver) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Cannot get size from a RenderSliver.'), + ErrorHint( + 'The render object associated with this element is a ' + '${renderObject.runtimeType}, which is a subtype of RenderSliver. ' + 'Slivers do not have a size per se. They have a more elaborate ' + 'geometry description, which can be accessed by calling ' + 'findRenderObject and then using the "geometry" getter on the ' + 'resulting object.', + ), + describeElement('The size getter was called for the following element'), + renderObject.describeForError('The associated render sliver was'), + ]); + } + if (renderObject is! RenderBox) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Cannot get size from a render object that is not a RenderBox.'), + ErrorHint( + 'Instead of being a subtype of RenderBox, the render object associated ' + 'with this element is a ${renderObject.runtimeType}. If this type of ' + 'render object does have a size, consider calling findRenderObject ' + 'and extracting its size manually.', + ), + describeElement('The size getter was called for the following element'), + renderObject.describeForError('The associated render object was'), + ]); + } + final RenderBox box = renderObject; + if (!box.hasSize) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Cannot get size from a render object that has not been through layout.'), + ErrorHint( + 'The size of this render object has not yet been determined because ' + 'this render object has not yet been through layout, which typically ' + 'means that the size getter was called too early in the pipeline ' + '(e.g., during the build phase) before the framework has determined ' + 'the size and position of the render objects during layout.', + ), + describeElement('The size getter was called for the following element'), + box.describeForError('The render object from which the size was to be obtained was'), + ]); + } + if (box.debugNeedsLayout) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Cannot get size from a render object that has been marked dirty for layout.'), + ErrorHint( + 'The size of this render object is ambiguous because this render object has ' + 'been modified since it was last laid out, which typically means that the size ' + 'getter was called too early in the pipeline (e.g., during the build phase) ' + 'before the framework has determined the size and position of the render ' + 'objects during layout.', + ), + describeElement('The size getter was called for the following element'), + box.describeForError('The render object from which the size was to be obtained was'), + ErrorHint( + 'Consider using debugPrintMarkNeedsLayoutStacks to determine why the render ' + 'object in question is dirty, if you did not expect this.', + ), + ]); + } + return true; + }()); + if (renderObject is RenderBox) { + return renderObject.size; + } + return null; + } + + PersistentHashMap<Type, InheritedElement>? _inheritedElements; + Set<InheritedElement>? _dependencies; + bool _hadUnsatisfiedDependencies = false; + + bool _debugCheckStateIsActiveForAncestorLookup() { + assert(() { + if (_lifecycleState != _ElementLifecycle.active) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary("Looking up a deactivated widget's ancestor is unsafe."), + ErrorDescription( + "At this point the state of the widget's element tree is no longer " + 'stable.', + ), + ErrorHint( + "To safely refer to a widget's ancestor in its dispose() method, " + 'save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() ' + "in the widget's didChangeDependencies() method.", + ), + ]); + } + return true; + }()); + return true; + } + + /// Returns `true` if [dependOnInheritedElement] was previously called with [ancestor]. + @protected + bool doesDependOnInheritedElement(InheritedElement ancestor) => + _dependencies != null && _dependencies!.contains(ancestor); + + @override + InheritedWidget dependOnInheritedElement(InheritedElement ancestor, { Object? aspect }) { + _dependencies ??= HashSet<InheritedElement>(); + _dependencies!.add(ancestor); + ancestor.updateDependencies(this, aspect); + return ancestor.widget as InheritedWidget; + } + + @override + T? dependOnInheritedWidgetOfExactType<T extends InheritedWidget>({Object? aspect}) { + assert(_debugCheckStateIsActiveForAncestorLookup()); + final InheritedElement? ancestor = _inheritedElements == null ? null : _inheritedElements![T]; + if (ancestor != null) { + return dependOnInheritedElement(ancestor, aspect: aspect) as T; + } + _hadUnsatisfiedDependencies = true; + return null; + } + + @override + T? getInheritedWidgetOfExactType<T extends InheritedWidget>() { + return getElementForInheritedWidgetOfExactType<T>()?.widget as T?; + } + + @override + InheritedElement? getElementForInheritedWidgetOfExactType<T extends InheritedWidget>() { + assert(_debugCheckStateIsActiveForAncestorLookup()); + final InheritedElement? ancestor = _inheritedElements == null ? null : _inheritedElements![T]; + return ancestor; + } + + /// Called in [Element.mount] and [Element.activate] to register this element in + /// the notification tree. + /// + /// This method is only exposed so that [NotifiableElementMixin] can be implemented. + /// Subclasses of [Element] that wish to respond to notifications should mix that + /// in instead. + /// + /// See also: + /// * [NotificationListener], a widget that allows listening to notifications. + @protected + void attachNotificationTree() { + _notificationTree = _parent?._notificationTree; + } + + void _updateInheritance() { + assert(_lifecycleState == _ElementLifecycle.active); + _inheritedElements = _parent?._inheritedElements; + } + + @override + T? findAncestorWidgetOfExactType<T extends Widget>() { + assert(_debugCheckStateIsActiveForAncestorLookup()); + Element? ancestor = _parent; + while (ancestor != null && ancestor.widget.runtimeType != T) { + ancestor = ancestor._parent; + } + return ancestor?.widget as T?; + } + + @override + T? findAncestorStateOfType<T extends State<StatefulWidget>>() { + assert(_debugCheckStateIsActiveForAncestorLookup()); + Element? ancestor = _parent; + while (ancestor != null) { + if (ancestor is StatefulElement && ancestor.state is T) { + break; + } + ancestor = ancestor._parent; + } + final StatefulElement? statefulAncestor = ancestor as StatefulElement?; + return statefulAncestor?.state as T?; + } + + @override + T? findRootAncestorStateOfType<T extends State<StatefulWidget>>() { + assert(_debugCheckStateIsActiveForAncestorLookup()); + Element? ancestor = _parent; + StatefulElement? statefulAncestor; + while (ancestor != null) { + if (ancestor is StatefulElement && ancestor.state is T) { + statefulAncestor = ancestor; + } + ancestor = ancestor._parent; + } + return statefulAncestor?.state as T?; + } + + @override + T? findAncestorRenderObjectOfType<T extends RenderObject>() { + assert(_debugCheckStateIsActiveForAncestorLookup()); + Element? ancestor = _parent; + while (ancestor != null) { + if (ancestor is RenderObjectElement && ancestor.renderObject is T) { + return ancestor.renderObject as T; + } + ancestor = ancestor._parent; + } + return null; + } + + @override + void visitAncestorElements(ConditionalElementVisitor visitor) { + assert(_debugCheckStateIsActiveForAncestorLookup()); + Element? ancestor = _parent; + while (ancestor != null && visitor(ancestor)) { + ancestor = ancestor._parent; + } + } + + /// Called when a dependency of this element changes. + /// + /// The [dependOnInheritedWidgetOfExactType] registers this element as depending on + /// inherited information of the given type. When the information of that type + /// changes at this location in the tree (e.g., because the [InheritedElement] + /// updated to a new [InheritedWidget] and + /// [InheritedWidget.updateShouldNotify] returned true), the framework calls + /// this function to notify this element of the change. + @mustCallSuper + void didChangeDependencies() { + assert(_lifecycleState == _ElementLifecycle.active); // otherwise markNeedsBuild is a no-op + assert(_debugCheckOwnerBuildTargetExists('didChangeDependencies')); + markNeedsBuild(); + } + + bool _debugCheckOwnerBuildTargetExists(String methodName) { + assert(() { + if (owner!._debugCurrentBuildTarget == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + '$methodName for ${widget.runtimeType} was called at an ' + 'inappropriate time.', + ), + ErrorDescription('It may only be called while the widgets are being built.'), + ErrorHint( + 'A possible cause of this error is when $methodName is called during ' + 'one of:\n' + ' * network I/O event\n' + ' * file I/O event\n' + ' * timer\n' + ' * microtask (caused by Future.then, async/await, scheduleMicrotask)', + ), + ]); + } + return true; + }()); + return true; + } + + /// Returns a description of what caused this element to be created. + /// + /// Useful for debugging the source of an element. + String debugGetCreatorChain(int limit) { + final List<String> chain = <String>[]; + Element? node = this; + while (chain.length < limit && node != null) { + chain.add(node.toStringShort()); + node = node._parent; + } + if (node != null) { + chain.add('\u22EF'); + } + return chain.join(' \u2190 '); + } + + /// Returns the parent chain from this element back to the root of the tree. + /// + /// Useful for debug display of a tree of Elements with only nodes in the path + /// from the root to this Element expanded. + List<Element> debugGetDiagnosticChain() { + final List<Element> chain = <Element>[this]; + Element? node = _parent; + while (node != null) { + chain.add(node); + node = node._parent; + } + return chain; + } + + @override + void dispatchNotification(Notification notification) { + _notificationTree?.dispatchNotification(notification); + } + + /// A short, textual description of this element. + @override + String toStringShort() => _widget?.toStringShort() ?? '${describeIdentity(this)}(DEFUNCT)'; + + @override + DiagnosticsNode toDiagnosticsNode({ String? name, DiagnosticsTreeStyle? style }) { + return _ElementDiagnosticableTreeNode( + name: name, + value: this, + style: style, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.defaultDiagnosticsTreeStyle= DiagnosticsTreeStyle.dense; + if (_lifecycleState != _ElementLifecycle.initial) { + properties.add(ObjectFlagProperty<int>('depth', depth, ifNull: 'no depth')); + } + properties.add(ObjectFlagProperty<Widget>('widget', _widget, ifNull: 'no widget')); + properties.add(DiagnosticsProperty<Key>('key', _widget?.key, showName: false, defaultValue: null, level: DiagnosticLevel.hidden)); + _widget?.debugFillProperties(properties); + properties.add(FlagProperty('dirty', value: dirty, ifTrue: 'dirty')); + final Set<InheritedElement>? deps = _dependencies; + if (deps != null && deps.isNotEmpty) { + final List<InheritedElement> sortedDependencies = deps.toList() + ..sort((InheritedElement a, InheritedElement b) => + a.toStringShort().compareTo(b.toStringShort())); + final List<DiagnosticsNode> diagnosticsDependencies = sortedDependencies + .map((InheritedElement element) => element.widget.toDiagnosticsNode(style: DiagnosticsTreeStyle.sparse)) + .toList(); + properties.add(DiagnosticsProperty<Set<InheritedElement>>('dependencies', deps, description: diagnosticsDependencies.toString())); + } + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<DiagnosticsNode> children = <DiagnosticsNode>[]; + visitChildren((Element child) { + children.add(child.toDiagnosticsNode()); + }); + return children; + } + + /// Returns true if the element has been marked as needing rebuilding. + /// + /// The flag is true when the element is first created and after + /// [markNeedsBuild] has been called. The flag is reset to false in the + /// [performRebuild] implementation. + bool get dirty => _dirty; + bool _dirty = true; + + // Whether this is in owner._dirtyElements. This is used to know whether we + // should be adding the element back into the list when it's reactivated. + bool _inDirtyList = false; + + // Whether we've already built or not. Set in [rebuild]. + bool _debugBuiltOnce = false; + + /// Marks the element as dirty and adds it to the global list of widgets to + /// rebuild in the next frame. + /// + /// Since it is inefficient to build an element twice in one frame, + /// applications and widgets should be structured so as to only mark + /// widgets dirty during event handlers before the frame begins, not during + /// the build itself. + void markNeedsBuild() { + assert(_lifecycleState != _ElementLifecycle.defunct); + if (_lifecycleState != _ElementLifecycle.active) { + return; + } + assert(owner != null); + assert(_lifecycleState == _ElementLifecycle.active); + assert(() { + if (owner!._debugBuilding) { + assert(owner!._debugCurrentBuildTarget != null); + assert(owner!._debugStateLocked); + if (_debugIsInScope(owner!._debugCurrentBuildTarget!)) { + return true; + } + final List<DiagnosticsNode> information = <DiagnosticsNode>[ + ErrorSummary('setState() or markNeedsBuild() called during build.'), + ErrorDescription( + 'This ${widget.runtimeType} widget cannot be marked as needing to build because the framework ' + 'is already in the process of building widgets. A widget can be marked as ' + 'needing to be built during the build phase only if one of its ancestors ' + 'is currently building. This exception is allowed because the framework ' + 'builds parent widgets before children, which means a dirty descendant ' + 'will always be built. Otherwise, the framework might not visit this ' + 'widget during this build phase.', + ), + describeElement('The widget on which setState() or markNeedsBuild() was called was'), + ]; + if (owner!._debugCurrentBuildTarget != null) { + information.add(owner!._debugCurrentBuildTarget!.describeWidget('The widget which was currently being built when the offending call was made was')); + } + throw FlutterError.fromParts(information); + } else if (owner!._debugStateLocked) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('setState() or markNeedsBuild() called when widget tree was locked.'), + ErrorDescription( + 'This ${widget.runtimeType} widget cannot be marked as needing to build ' + 'because the framework is locked.', + ), + describeElement('The widget on which setState() or markNeedsBuild() was called was'), + ]); + } + return true; + }()); + if (dirty) { + return; + } + _dirty = true; + owner!.scheduleBuildFor(this); + } + + /// Cause the widget to update itself. In debug builds, also verify various + /// invariants. + /// + /// Called by the [BuildOwner] when [BuildOwner.scheduleBuildFor] has been + /// called to mark this element dirty, by [mount] when the element is first + /// built, and by [update] when the widget has changed. + /// + /// The method will only rebuild if [dirty] is true. To rebuild regardless + /// of the [dirty] flag, set `force` to true. Forcing a rebuild is convenient + /// from [update], during which [dirty] is false. + /// + /// ## When rebuilds happen + /// + /// ### Terminology + /// + /// [Widget]s represent the configuration of [Element]s. Each [Element] has a + /// widget, specified in [Element.widget]. The term "widget" is often used + /// when strictly speaking "element" would be more correct. + /// + /// While an [Element] has a current [Widget], over time, that widget may be + /// replaced by others. For example, the element backing a [ColoredBox] may + /// first have as its widget a [ColoredBox] whose [ColoredBox.color] is blue, + /// then later be given a new [ColoredBox] whose color is green. + /// + /// At any particular time, multiple [Element]s in the same tree may have the + /// same [Widget]. For example, the same [ColoredBox] with the green color may + /// be used in multiple places in the widget tree at the same time, each being + /// backed by a different [Element]. + /// + /// ### Marking an element dirty + /// + /// An [Element] can be marked dirty between frames. This can happen for various + /// reasons, including the following: + /// + /// * The [State] of a [StatefulWidget] can cause its [Element] to be marked + /// dirty by calling the [State.setState] method. + /// + /// * When an [InheritedWidget] changes, descendants that have previously + /// subscribed to it will be marked dirty. + /// + /// * During a hot reload, every element is marked dirty (using [Element.reassemble]). + /// + /// ### Rebuilding + /// + /// Dirty elements are rebuilt during the next frame. Precisely how this is + /// done depends on the kind of element. A [StatelessElement] rebuilds by + /// using its widget's [StatelessWidget.build] method. A [StatefulElement] + /// rebuilds by using its widget's state's [State.build] method. A + /// [RenderObjectElement] rebuilds by updating its [RenderObject]. + /// + /// In many cases, the end result of rebuilding is a single child widget + /// or (for [MultiChildRenderObjectElement]s) a list of children widgets. + /// + /// These child widgets are used to update the [widget] property of the + /// element's child (or children) elements. The new [Widget] is considered to + /// correspond to an existing [Element] if it has the same [Type] and [Key]. + /// (In the case of [MultiChildRenderObjectElement]s, some effort is put into + /// tracking widgets even when they change order; see + /// [RenderObjectElement.updateChildren].) + /// + /// If there was no corresponding previous child, this results in a new + /// [Element] being created (using [Widget.createElement]); that element is + /// then itself built, recursively. + /// + /// If there was a child previously but the build did not provide a + /// corresponding child to update it, then the old child is discarded (or, in + /// cases involving [GlobalKey] reparenting, reused elsewhere in the element + /// tree). + /// + /// The most common case, however, is that there was a corresponding previous + /// child. This is handled by asking the child [Element] to update itself + /// using the new child [Widget]. In the case of [StatefulElement]s, this + /// is what triggers [State.didUpdateWidget]. + /// + /// ### Not rebuilding + /// + /// Before an [Element] is told to update itself with a new [Widget], the old + /// and new objects are compared using `operator ==`. + /// + /// In general, this is equivalent to doing a comparison using [identical] to + /// see if the two objects are in fact the exact same instance. If they are, + /// and if the element is not already marked dirty for other reasons, then the + /// element skips updating itself as it can determine with certainty that + /// there would be no value in updating itself or its descendants. + /// + /// It is strongly advised to avoid overriding `operator ==` on [Widget] + /// objects. While doing so seems like it could improve performance, in + /// practice, for non-leaf widgets, it results in O(N²) behavior. This is + /// because by necessity the comparison would have to include comparing child + /// widgets, and if those child widgets also implement `operator ==`, it + /// ultimately results in a complete walk of the widget tree... which is then + /// repeated at each level of the tree. In practice, just rebuilding is + /// cheaper. (Additionally, if _any_ subclass of [Widget] used in an + /// application implements `operator ==`, then the compiler cannot inline the + /// comparison anywhere, because it has to treat the call as virtual just in + /// case the instance happens to be one that has an overridden operator.) + /// + /// Instead, the best way to avoid unnecessary rebuilds is to cache the + /// widgets that are returned from [State.build], so that each frame the same + /// widgets are used until such time as they change. Several mechanisms exist + /// to encourage this: `const` widgets, for example, are a form of automatic + /// caching (if a widget is constructed using the `const` keyword, the same + /// instance is returned each time it is constructed with the same arguments). + /// + /// Another example is the [AnimatedBuilder.child] property, which allows the + /// non-animating parts of a subtree to remain static even as the + /// [AnimatedBuilder.builder] callback recreates the other components. + @pragma('vm:prefer-inline') + void rebuild({bool force = false}) { + assert(_lifecycleState != _ElementLifecycle.initial); + if (_lifecycleState != _ElementLifecycle.active || (!_dirty && !force)) { + return; + } + assert(() { + debugOnRebuildDirtyWidget?.call(this, _debugBuiltOnce); + if (debugPrintRebuildDirtyWidgets) { + if (!_debugBuiltOnce) { + debugPrint('Building $this'); + _debugBuiltOnce = true; + } else { + debugPrint('Rebuilding $this'); + } + } + return true; + }()); + assert(_lifecycleState == _ElementLifecycle.active); + assert(owner!._debugStateLocked); + Element? debugPreviousBuildTarget; + assert(() { + debugPreviousBuildTarget = owner!._debugCurrentBuildTarget; + owner!._debugCurrentBuildTarget = this; + return true; + }()); + try { + performRebuild(); + } finally { + assert(() { + owner!._debugElementWasRebuilt(this); + assert(owner!._debugCurrentBuildTarget == this); + owner!._debugCurrentBuildTarget = debugPreviousBuildTarget; + return true; + }()); + } + assert(!_dirty); + } + + /// Cause the widget to update itself. + /// + /// Called by [rebuild] after the appropriate checks have been made. + /// + /// The base implementation only clears the [dirty] flag. + @protected + @mustCallSuper + void performRebuild() { + _dirty = false; + } +} + +class _ElementDiagnosticableTreeNode extends DiagnosticableTreeNode { + _ElementDiagnosticableTreeNode({ + super.name, + required Element super.value, + required super.style, + this.stateful = false, + }); + + final bool stateful; + + @override + Map<String, Object?> toJsonMap(DiagnosticsSerializationDelegate delegate) { + final Map<String, Object?> json = super.toJsonMap(delegate); + final Element element = value as Element; + if (!element.debugIsDefunct) { + json['widgetRuntimeType'] = element.widget.runtimeType.toString(); + } + json['stateful'] = stateful; + return json; + } +} + +/// Signature for the constructor that is called when an error occurs while +/// building a widget. +/// +/// The argument provides information regarding the cause of the error. +/// +/// See also: +/// +/// * [ErrorWidget.builder], which can be set to override the default +/// [ErrorWidget] builder. +/// * [FlutterError.reportError], which is typically called with the same +/// [FlutterErrorDetails] object immediately prior to [ErrorWidget.builder] +/// being called. +typedef ErrorWidgetBuilder = Widget Function(FlutterErrorDetails details); + +/// A widget that renders an exception's message. +/// +/// This widget is used when a build method fails, to help with determining +/// where the problem lies. Exceptions are also logged to the console, which you +/// can read using `flutter logs`. The console will also include additional +/// information such as the stack trace for the exception. +/// +/// It is possible to override this widget. +/// +/// {@tool dartpad} +/// This example shows how to override the standard error widget builder in release +/// mode, but use the standard one in debug mode. +/// +/// The error occurs when you click the "Error Prone" button. +/// +/// ** See code in examples/api/lib/widgets/framework/error_widget.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [FlutterError.onError], which can be set to a method that exits the +/// application if that is preferable to showing an error message. +/// * <https://flutter.dev/docs/testing/errors>, more information about error +/// handling in Flutter. +class ErrorWidget extends LeafRenderObjectWidget { + /// Creates a widget that displays the given exception. + /// + /// The message will be the stringification of the given exception, unless + /// computing that value itself throws an exception, in which case it will + /// be the string "Error". + /// + /// If this object is inspected from an IDE or the devtools, and the original + /// exception is a [FlutterError] object, the original exception itself will + /// be shown in the inspection output. + ErrorWidget(Object exception) + : message = _stringify(exception), + _flutterError = exception is FlutterError ? exception : null, + super(key: UniqueKey()); + + /// Creates a widget that displays the given error message. + /// + /// An explicit [FlutterError] can be provided to be reported to inspection + /// tools. It need not match the message. + ErrorWidget.withDetails({ this.message = '', FlutterError? error }) + : _flutterError = error, + super(key: UniqueKey()); + + /// The configurable factory for [ErrorWidget]. + /// + /// When an error occurs while building a widget, the broken widget is + /// replaced by the widget returned by this function. By default, an + /// [ErrorWidget] is returned. + /// + /// The system is typically in an unstable state when this function is called. + /// An exception has just been thrown in the middle of build (and possibly + /// layout), so surrounding widgets and render objects may be in a rather + /// fragile state. The framework itself (especially the [BuildOwner]) may also + /// be confused, and additional exceptions are quite likely to be thrown. + /// + /// Because of this, it is highly recommended that the widget returned from + /// this function perform the least amount of work possible. A + /// [LeafRenderObjectWidget] is the best choice, especially one that + /// corresponds to a [RenderBox] that can handle the most absurd of incoming + /// constraints. The default constructor maps to a [RenderErrorBox]. + /// + /// The default behavior is to show the exception's message in debug mode, + /// and to show nothing but a gray background in release builds. + /// + /// See also: + /// + /// * [FlutterError.onError], which is typically called with the same + /// [FlutterErrorDetails] object immediately prior to this callback being + /// invoked, and which can also be configured to control how errors are + /// reported. + /// * <https://flutter.dev/docs/testing/errors>, more information about error + /// handling in Flutter. + static ErrorWidgetBuilder builder = _defaultErrorWidgetBuilder; + + static Widget _defaultErrorWidgetBuilder(FlutterErrorDetails details) { + String message = ''; + assert(() { + message = '${_stringify(details.exception)}\nSee also: https://flutter.dev/docs/testing/errors'; + return true; + }()); + final Object exception = details.exception; + return ErrorWidget.withDetails(message: message, error: exception is FlutterError ? exception : null); + } + + static String _stringify(Object? exception) { + try { + return exception.toString(); + } catch (error) { + // If we get here, it means things have really gone off the rails, and we're better + // off just returning a simple string and letting the developer find out what the + // root cause of all their problems are by looking at the console logs. + } + return 'Error'; + } + + /// The message to display. + final String message; + final FlutterError? _flutterError; + + @override + RenderBox createRenderObject(BuildContext context) => RenderErrorBox(message); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + if (_flutterError == null) { + properties.add(StringProperty('message', message, quoted: false)); + } else { + properties.add(_flutterError.toDiagnosticsNode(style: DiagnosticsTreeStyle.whitespace)); + } + } +} + +/// Signature for a function that creates a widget, e.g. [StatelessWidget.build] +/// or [State.build]. +/// +/// Used by [Builder.builder], [OverlayEntry.builder], etc. +/// +/// See also: +/// +/// * [IndexedWidgetBuilder], which is similar but also takes an index. +/// * [TransitionBuilder], which is similar but also takes a child. +/// * [ValueWidgetBuilder], which is similar but takes a value and a child. +typedef WidgetBuilder = Widget Function(BuildContext context); + +/// Signature for a function that creates a widget for a given index, e.g., in a +/// list. +/// +/// Used by [ListView.builder] and other APIs that use lazily-generated widgets. +/// +/// See also: +/// +/// * [WidgetBuilder], which is similar but only takes a [BuildContext]. +/// * [TransitionBuilder], which is similar but also takes a child. +/// * [NullableIndexedWidgetBuilder], which is similar but may return null. +typedef IndexedWidgetBuilder = Widget Function(BuildContext context, int index); + +/// Signature for a function that creates a widget for a given index, e.g., in a +/// list, but may return null. +/// +/// Used by [SliverChildBuilderDelegate.builder] and other APIs that +/// use lazily-generated widgets where the child count is not known +/// ahead of time. +/// +/// Unlike most builders, this callback can return null, indicating the index +/// is out of range. Whether and when this is valid depends on the semantics +/// of the builder. For example, [SliverChildBuilderDelegate.builder] returns +/// null when the index is out of range, where the range is defined by the +/// [SliverChildBuilderDelegate.childCount]; so in that case the `index` +/// parameter's value may determine whether returning null is valid or not. +/// +/// See also: +/// +/// * [WidgetBuilder], which is similar but only takes a [BuildContext]. +/// * [TransitionBuilder], which is similar but also takes a child. +/// * [IndexedWidgetBuilder], which is similar but not nullable. +typedef NullableIndexedWidgetBuilder = Widget? Function(BuildContext context, int index); + +/// A builder that builds a widget given a child. +/// +/// The child should typically be part of the returned widget tree. +/// +/// Used by [AnimatedBuilder.builder], [ListenableBuilder.builder], +/// [WidgetsApp.builder], and [MaterialApp.builder]. +/// +/// See also: +/// +/// * [WidgetBuilder], which is similar but only takes a [BuildContext]. +/// * [IndexedWidgetBuilder], which is similar but also takes an index. +/// * [ValueWidgetBuilder], which is similar but takes a value and a child. +typedef TransitionBuilder = Widget Function(BuildContext context, Widget? child); + +/// An [Element] that composes other [Element]s. +/// +/// Rather than creating a [RenderObject] directly, a [ComponentElement] creates +/// [RenderObject]s indirectly by creating other [Element]s. +/// +/// Contrast with [RenderObjectElement]. +abstract class ComponentElement extends Element { + /// Creates an element that uses the given widget as its configuration. + ComponentElement(super.widget); + + Element? _child; + + bool _debugDoingBuild = false; + @override + bool get debugDoingBuild => _debugDoingBuild; + + @override + Element? get renderObjectAttachingChild => _child; + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + assert(_child == null); + assert(_lifecycleState == _ElementLifecycle.active); + _firstBuild(); + assert(_child != null); + } + + void _firstBuild() { + // StatefulElement overrides this to also call state.didChangeDependencies. + rebuild(); // This eventually calls performRebuild. + } + + /// Calls the [StatelessWidget.build] method of the [StatelessWidget] object + /// (for stateless widgets) or the [State.build] method of the [State] object + /// (for stateful widgets) and then updates the widget tree. + /// + /// Called automatically during [mount] to generate the first build, and by + /// [rebuild] when the element needs updating. + @override + @pragma('vm:notify-debugger-on-exception') + void performRebuild() { + Widget? built; + try { + assert(() { + _debugDoingBuild = true; + return true; + }()); + built = build(); + assert(() { + _debugDoingBuild = false; + return true; + }()); + debugWidgetBuilderValue(widget, built); + } catch (e, stack) { + _debugDoingBuild = false; + built = ErrorWidget.builder( + _reportException( + ErrorDescription('building $this'), + e, + stack, + informationCollector: () => <DiagnosticsNode>[ + if (kDebugMode) + DiagnosticsDebugCreator(DebugCreator(this)), + ], + ), + ); + } finally { + // We delay marking the element as clean until after calling build() so + // that attempts to markNeedsBuild() during build() will be ignored. + super.performRebuild(); // clears the "dirty" flag + } + try { + _child = updateChild(_child, built, slot); + assert(_child != null); + } catch (e, stack) { + built = ErrorWidget.builder( + _reportException( + ErrorDescription('building $this'), + e, + stack, + informationCollector: () => <DiagnosticsNode>[ + if (kDebugMode) + DiagnosticsDebugCreator(DebugCreator(this)), + ], + ), + ); + _child = updateChild(null, built, slot); + } + } + + /// Subclasses should override this function to actually call the appropriate + /// `build` function (e.g., [StatelessWidget.build] or [State.build]) for + /// their widget. + @protected + Widget build(); + + @override + void visitChildren(ElementVisitor visitor) { + if (_child != null) { + visitor(_child!); + } + } + + @override + void forgetChild(Element child) { + assert(child == _child); + _child = null; + super.forgetChild(child); + } +} + +/// An [Element] that uses a [StatelessWidget] as its configuration. +class StatelessElement extends ComponentElement { + /// Creates an element that uses the given widget as its configuration. + StatelessElement(StatelessWidget super.widget); + + @override + Widget build() => (widget as StatelessWidget).build(this); + + @override + void update(StatelessWidget newWidget) { + super.update(newWidget); + assert(widget == newWidget); + rebuild(force: true); + } +} + +/// An [Element] that uses a [StatefulWidget] as its configuration. +class StatefulElement extends ComponentElement { + /// Creates an element that uses the given widget as its configuration. + StatefulElement(StatefulWidget widget) + : _state = widget.createState(), + super(widget) { + assert(() { + if (!state._debugTypesAreRight(widget)) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('StatefulWidget.createState must return a subtype of State<${widget.runtimeType}>'), + ErrorDescription( + 'The createState function for ${widget.runtimeType} returned a state ' + 'of type ${state.runtimeType}, which is not a subtype of ' + 'State<${widget.runtimeType}>, violating the contract for createState.', + ), + ]); + } + return true; + }()); + assert(state._element == null); + state._element = this; + assert( + state._widget == null, + 'The createState function for $widget returned an old or invalid state ' + 'instance: ${state._widget}, which is not null, violating the contract ' + 'for createState.', + ); + state._widget = widget; + assert(state._debugLifecycleState == _StateLifecycle.created); + } + + @override + Widget build() => state.build(this); + + /// The [State] instance associated with this location in the tree. + /// + /// There is a one-to-one relationship between [State] objects and the + /// [StatefulElement] objects that hold them. The [State] objects are created + /// by [StatefulElement] in [mount]. + State<StatefulWidget> get state => _state!; + State<StatefulWidget>? _state; + + @override + void reassemble() { + state.reassemble(); + super.reassemble(); + } + + @override + void _firstBuild() { + assert(state._debugLifecycleState == _StateLifecycle.created); + final Object? debugCheckForReturnedFuture = state.initState() as dynamic; + assert(() { + if (debugCheckForReturnedFuture is Future) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('${state.runtimeType}.initState() returned a Future.'), + ErrorDescription('State.initState() must be a void method without an `async` keyword.'), + ErrorHint( + 'Rather than awaiting on asynchronous work directly inside of initState, ' + 'call a separate method to do this work without awaiting it.', + ), + ]); + } + return true; + }()); + assert(() { + state._debugLifecycleState = _StateLifecycle.initialized; + return true; + }()); + state.didChangeDependencies(); + assert(() { + state._debugLifecycleState = _StateLifecycle.ready; + return true; + }()); + super._firstBuild(); + } + + @override + void performRebuild() { + if (_didChangeDependencies) { + state.didChangeDependencies(); + _didChangeDependencies = false; + } + super.performRebuild(); + } + + @override + void update(StatefulWidget newWidget) { + super.update(newWidget); + assert(widget == newWidget); + final StatefulWidget oldWidget = state._widget!; + state._widget = widget as StatefulWidget; + final Object? debugCheckForReturnedFuture = state.didUpdateWidget(oldWidget) as dynamic; + assert(() { + if (debugCheckForReturnedFuture is Future) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('${state.runtimeType}.didUpdateWidget() returned a Future.'), + ErrorDescription( 'State.didUpdateWidget() must be a void method without an `async` keyword.'), + ErrorHint( + 'Rather than awaiting on asynchronous work directly inside of didUpdateWidget, ' + 'call a separate method to do this work without awaiting it.', + ), + ]); + } + return true; + }()); + rebuild(force: true); + } + + @override + void activate() { + super.activate(); + state.activate(); + // Since the State could have observed the deactivate() and thus disposed of + // resources allocated in the build method, we have to rebuild the widget + // so that its State can reallocate its resources. + assert(_lifecycleState == _ElementLifecycle.active); // otherwise markNeedsBuild is a no-op + markNeedsBuild(); + } + + @override + void deactivate() { + state.deactivate(); + super.deactivate(); + } + + @override + void unmount() { + super.unmount(); + state.dispose(); + assert(() { + if (state._debugLifecycleState == _StateLifecycle.defunct) { + return true; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('${state.runtimeType}.dispose failed to call super.dispose.'), + ErrorDescription( + 'dispose() implementations must always call their superclass dispose() method, to ensure ' + 'that all the resources used by the widget are fully released.', + ), + ]); + }()); + state._element = null; + // Release resources to reduce the severity of memory leaks caused by + // defunct, but accidentally retained Elements. + _state = null; + } + + @override + InheritedWidget dependOnInheritedElement(Element ancestor, { Object? aspect }) { + assert(() { + final Type targetType = ancestor.widget.runtimeType; + if (state._debugLifecycleState == _StateLifecycle.created) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('dependOnInheritedWidgetOfExactType<$targetType>() or dependOnInheritedElement() was called before ${state.runtimeType}.initState() completed.'), + ErrorDescription( + 'When an inherited widget changes, for example if the value of Theme.of() changes, ' + "its dependent widgets are rebuilt. If the dependent widget's reference to " + 'the inherited widget is in a constructor or an initState() method, ' + 'then the rebuilt dependent widget will not reflect the changes in the ' + 'inherited widget.', + ), + ErrorHint( + 'Typically references to inherited widgets should occur in widget build() methods. Alternatively, ' + 'initialization based on inherited widgets can be placed in the didChangeDependencies method, which ' + 'is called after initState and whenever the dependencies change thereafter.', + ), + ]); + } + if (state._debugLifecycleState == _StateLifecycle.defunct) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('dependOnInheritedWidgetOfExactType<$targetType>() or dependOnInheritedElement() was called after dispose(): $this'), + ErrorDescription( + 'This error happens if you call dependOnInheritedWidgetOfExactType() on the ' + 'BuildContext for a widget that no longer appears in the widget tree ' + '(e.g., whose parent widget no longer includes the widget in its ' + 'build). This error can occur when code calls ' + 'dependOnInheritedWidgetOfExactType() from a timer or an animation callback.', + ), + ErrorHint( + 'The preferred solution is to cancel the timer or stop listening to the ' + 'animation in the dispose() callback. Another solution is to check the ' + '"mounted" property of this object before calling ' + 'dependOnInheritedWidgetOfExactType() to ensure the object is still in the ' + 'tree.', + ), + ErrorHint( + 'This error might indicate a memory leak if ' + 'dependOnInheritedWidgetOfExactType() is being called because another object ' + 'is retaining a reference to this State object after it has been ' + 'removed from the tree. To avoid memory leaks, consider breaking the ' + 'reference to this object during dispose().', + ), + ]); + } + return true; + }()); + return super.dependOnInheritedElement(ancestor as InheritedElement, aspect: aspect); + } + + /// This controls whether we should call [State.didChangeDependencies] from + /// the start of [build], to avoid calls when the [State] will not get built. + /// This can happen when the widget has dropped out of the tree, but depends + /// on an [InheritedWidget] that is still in the tree. + /// + /// It is set initially to false, since [_firstBuild] makes the initial call + /// on the [state]. When it is true, [build] will call + /// `state.didChangeDependencies` and then sets it to false. Subsequent calls + /// to [didChangeDependencies] set it to true. + bool _didChangeDependencies = false; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _didChangeDependencies = true; + } + + @override + DiagnosticsNode toDiagnosticsNode({ String? name, DiagnosticsTreeStyle? style }) { + return _ElementDiagnosticableTreeNode( + name: name, + value: this, + style: style, + stateful: true, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<State<StatefulWidget>>('state', _state, defaultValue: null)); + } +} + +/// An [Element] that uses a [ProxyWidget] as its configuration. +abstract class ProxyElement extends ComponentElement { + /// Initializes fields for subclasses. + ProxyElement(ProxyWidget super.widget); + + @override + Widget build() => (widget as ProxyWidget).child; + + @override + void update(ProxyWidget newWidget) { + final ProxyWidget oldWidget = widget as ProxyWidget; + assert(widget != newWidget); + super.update(newWidget); + assert(widget == newWidget); + updated(oldWidget); + rebuild(force: true); + } + + /// Called during build when the [widget] has changed. + /// + /// By default, calls [notifyClients]. Subclasses may override this method to + /// avoid calling [notifyClients] unnecessarily (e.g. if the old and new + /// widgets are equivalent). + @protected + void updated(covariant ProxyWidget oldWidget) { + notifyClients(oldWidget); + } + + /// Notify other objects that the widget associated with this element has + /// changed. + /// + /// Called during [update] (via [updated]) after changing the widget + /// associated with this element but before rebuilding this element. + @protected + void notifyClients(covariant ProxyWidget oldWidget); +} + +/// An [Element] that uses a [ParentDataWidget] as its configuration. +class ParentDataElement<T extends ParentData> extends ProxyElement { + /// Creates an element that uses the given widget as its configuration. + ParentDataElement(ParentDataWidget<T> super.widget); + + /// Returns the [Type] of [ParentData] that this element has been configured + /// for. + /// + /// This is only available in debug mode. It will throw in profile and + /// release modes. + Type get debugParentDataType { + Type? type; + assert(() { + type = T; + return true; + }()); + if (type != null) { + return type!; + } + throw UnsupportedError('debugParentDataType is only supported in debug builds'); + } + + void _applyParentData(ParentDataWidget<T> widget) { + void applyParentDataToChild(Element child) { + if (child is RenderObjectElement) { + child._updateParentData(widget); + } else { + child.visitChildren(applyParentDataToChild); + } + } + visitChildren(applyParentDataToChild); + } + + /// Calls [ParentDataWidget.applyParentData] on the given widget, passing it + /// the [RenderObject] whose parent data this element is ultimately + /// responsible for. + /// + /// This allows a render object's [RenderObject.parentData] to be modified + /// without triggering a build. This is generally ill-advised, but makes sense + /// in situations such as the following: + /// + /// * Build and layout are currently under way, but the [ParentData] in question + /// does not affect layout, and the value to be applied could not be + /// determined before build and layout (e.g. it depends on the layout of a + /// descendant). + /// + /// * Paint is currently under way, but the [ParentData] in question does not + /// affect layout or paint, and the value to be applied could not be + /// determined before paint (e.g. it depends on the compositing phase). + /// + /// In either case, the next build is expected to cause this element to be + /// configured with the given new widget (or a widget with equivalent data). + /// + /// Only [ParentDataWidget]s that return true for + /// [ParentDataWidget.debugCanApplyOutOfTurn] can be applied this way. + /// + /// The new widget must have the same child as the current widget. + /// + /// An example of when this is used is the [AutomaticKeepAlive] widget. If it + /// receives a notification during the build of one of its descendants saying + /// that its child must be kept alive, it will apply a [KeepAlive] widget out + /// of turn. This is safe, because by definition the child is already alive, + /// and therefore this will not change the behavior of the parent this frame. + /// It is more efficient than requesting an additional frame just for the + /// purpose of updating the [KeepAlive] widget. + void applyWidgetOutOfTurn(ParentDataWidget<T> newWidget) { + assert(newWidget.debugCanApplyOutOfTurn()); + assert(newWidget.child == (widget as ParentDataWidget<T>).child); + _applyParentData(newWidget); + } + + @override + void notifyClients(ParentDataWidget<T> oldWidget) { + _applyParentData(widget as ParentDataWidget<T>); + } +} + +/// An [Element] that uses an [InheritedWidget] as its configuration. +class InheritedElement extends ProxyElement { + /// Creates an element that uses the given widget as its configuration. + InheritedElement(InheritedWidget super.widget); + + final Map<Element, Object?> _dependents = HashMap<Element, Object?>(); + + @override + void _updateInheritance() { + assert(_lifecycleState == _ElementLifecycle.active); + final PersistentHashMap<Type, InheritedElement> incomingWidgets = + _parent?._inheritedElements ?? const PersistentHashMap<Type, InheritedElement>.empty(); + _inheritedElements = incomingWidgets.put(widget.runtimeType, this); + } + + @override + void debugDeactivated() { + assert(() { + assert(_dependents.isEmpty); + return true; + }()); + super.debugDeactivated(); + } + + /// Returns the dependencies value recorded for [dependent] + /// with [setDependencies]. + /// + /// Each dependent element is mapped to a single object value + /// which represents how the element depends on this + /// [InheritedElement]. This value is null by default and by default + /// dependent elements are rebuilt unconditionally. + /// + /// Subclasses can manage these values with [updateDependencies] + /// so that they can selectively rebuild dependents in + /// [notifyDependent]. + /// + /// This method is typically only called in overrides of [updateDependencies]. + /// + /// See also: + /// + /// * [updateDependencies], which is called each time a dependency is + /// created with [dependOnInheritedWidgetOfExactType]. + /// * [setDependencies], which sets dependencies value for a dependent + /// element. + /// * [notifyDependent], which can be overridden to use a dependent's + /// dependencies value to decide if the dependent needs to be rebuilt. + /// * [InheritedModel], which is an example of a class that uses this method + /// to manage dependency values. + @protected + Object? getDependencies(Element dependent) { + return _dependents[dependent]; + } + + /// Sets the value returned by [getDependencies] value for [dependent]. + /// + /// Each dependent element is mapped to a single object value + /// which represents how the element depends on this + /// [InheritedElement]. The [updateDependencies] method sets this value to + /// null by default so that dependent elements are rebuilt unconditionally. + /// + /// Subclasses can manage these values with [updateDependencies] + /// so that they can selectively rebuild dependents in [notifyDependent]. + /// + /// This method is typically only called in overrides of [updateDependencies]. + /// + /// See also: + /// + /// * [updateDependencies], which is called each time a dependency is + /// created with [dependOnInheritedWidgetOfExactType]. + /// * [getDependencies], which returns the current value for a dependent + /// element. + /// * [notifyDependent], which can be overridden to use a dependent's + /// [getDependencies] value to decide if the dependent needs to be rebuilt. + /// * [InheritedModel], which is an example of a class that uses this method + /// to manage dependency values. + @protected + void setDependencies(Element dependent, Object? value) { + _dependents[dependent] = value; + } + + /// Called by [dependOnInheritedWidgetOfExactType] when a new [dependent] is added. + /// + /// Each dependent element can be mapped to a single object value with + /// [setDependencies]. This method can lookup the existing dependencies with + /// [getDependencies]. + /// + /// By default this method sets the inherited dependencies for [dependent] + /// to null. This only serves to record an unconditional dependency on + /// [dependent]. + /// + /// Subclasses can manage their own dependencies values so that they + /// can selectively rebuild dependents in [notifyDependent]. + /// + /// See also: + /// + /// * [getDependencies], which returns the current value for a dependent + /// element. + /// * [setDependencies], which sets the value for a dependent element. + /// * [notifyDependent], which can be overridden to use a dependent's + /// dependencies value to decide if the dependent needs to be rebuilt. + /// * [InheritedModel], which is an example of a class that uses this method + /// to manage dependency values. + @protected + void updateDependencies(Element dependent, Object? aspect) { + setDependencies(dependent, null); + } + + /// Called by [notifyClients] for each dependent. + /// + /// Calls `dependent.didChangeDependencies()` by default. + /// + /// Subclasses can override this method to selectively call + /// [didChangeDependencies] based on the value of [getDependencies]. + /// + /// See also: + /// + /// * [updateDependencies], which is called each time a dependency is + /// created with [dependOnInheritedWidgetOfExactType]. + /// * [getDependencies], which returns the current value for a dependent + /// element. + /// * [setDependencies], which sets the value for a dependent element. + /// * [InheritedModel], which is an example of a class that uses this method + /// to manage dependency values. + @protected + void notifyDependent(covariant InheritedWidget oldWidget, Element dependent) { + dependent.didChangeDependencies(); + } + + /// Called by [Element.deactivate] to remove the provided `dependent` [Element] from this [InheritedElement]. + /// + /// After the dependent is removed, [Element.didChangeDependencies] will no + /// longer be called on it when this [InheritedElement] notifies its dependents. + /// + /// Subclasses can override this method to release any resources retained for + /// a given [dependent]. + @protected + @mustCallSuper + void removeDependent(Element dependent) { + _dependents.remove(dependent); + } + + /// Calls [Element.didChangeDependencies] of all dependent elements, if + /// [InheritedWidget.updateShouldNotify] returns true. + /// + /// Called by [update], immediately prior to [build]. + /// + /// Calls [notifyClients] to actually trigger the notifications. + @override + void updated(InheritedWidget oldWidget) { + if ((widget as InheritedWidget).updateShouldNotify(oldWidget)) { + super.updated(oldWidget); + } + } + + /// Notifies all dependent elements that this inherited widget has changed, by + /// calling [Element.didChangeDependencies]. + /// + /// This method must only be called during the build phase. Usually this + /// method is called automatically when an inherited widget is rebuilt, e.g. + /// as a result of calling [State.setState] above the inherited widget. + /// + /// See also: + /// + /// * [InheritedNotifier], a subclass of [InheritedWidget] that also calls + /// this method when its [Listenable] sends a notification. + @override + void notifyClients(InheritedWidget oldWidget) { + assert(_debugCheckOwnerBuildTargetExists('notifyClients')); + for (final Element dependent in _dependents.keys) { + assert(() { + // check that it really is our descendant + Element? ancestor = dependent._parent; + while (ancestor != this && ancestor != null) { + ancestor = ancestor._parent; + } + return ancestor == this; + }()); + // check that it really depends on us + assert(dependent._dependencies!.contains(this)); + notifyDependent(oldWidget, dependent); + } + } +} + +/// An [Element] that uses a [RenderObjectWidget] as its configuration. +/// +/// [RenderObjectElement] objects have an associated [RenderObject] widget in +/// the render tree, which handles concrete operations like laying out, +/// painting, and hit testing. +/// +/// Contrast with [ComponentElement]. +/// +/// For details on the lifecycle of an element, see the discussion at [Element]. +/// +/// ## Writing a RenderObjectElement subclass +/// +/// There are three common child models used by most [RenderObject]s: +/// +/// * Leaf render objects, with no children: The [LeafRenderObjectElement] class +/// handles this case. +/// +/// * A single child: The [SingleChildRenderObjectElement] class handles this +/// case. +/// +/// * A linked list of children: The [MultiChildRenderObjectElement] class +/// handles this case. +/// +/// Sometimes, however, a render object's child model is more complicated. Maybe +/// it has a two-dimensional array of children. Maybe it constructs children on +/// demand. Maybe it features multiple lists. In such situations, the +/// corresponding [Element] for the [Widget] that configures that [RenderObject] +/// will be a new subclass of [RenderObjectElement]. +/// +/// Such a subclass is responsible for managing children, specifically the +/// [Element] children of this object, and the [RenderObject] children of its +/// corresponding [RenderObject]. +/// +/// ### Specializing the getters +/// +/// [RenderObjectElement] objects spend much of their time acting as +/// intermediaries between their [widget] and their [renderObject]. It is +/// generally recommended against specializing the [widget] getter and +/// instead casting at the various call sites to avoid adding overhead +/// outside of this particular implementation. +/// +/// ```dart +/// class FooElement extends RenderObjectElement { +/// FooElement(super.widget); +/// +/// // Specializing the renderObject getter is fine because +/// // it is not performance sensitive. +/// @override +/// RenderFoo get renderObject => super.renderObject as RenderFoo; +/// +/// void _foo() { +/// // For the widget getter, though, we prefer to cast locally +/// // since that results in better overall performance where the +/// // casting isn't needed: +/// final Foo foo = widget as Foo; +/// // ... +/// } +/// +/// // ... +/// } +/// ``` +/// +/// ### Slots +/// +/// Each child [Element] corresponds to a [RenderObject] which should be +/// attached to this element's render object as a child. +/// +/// However, the immediate children of the element may not be the ones that +/// eventually produce the actual [RenderObject] that they correspond to. For +/// example, a [StatelessElement] (the element of a [StatelessWidget]) +/// corresponds to whatever [RenderObject] its child (the element returned by +/// its [StatelessWidget.build] method) corresponds to. +/// +/// Each child is therefore assigned a _[slot]_ token. This is an identifier whose +/// meaning is private to this [RenderObjectElement] node. When the descendant +/// that finally produces the [RenderObject] is ready to attach it to this +/// node's render object, it passes that slot token back to this node, and that +/// allows this node to cheaply identify where to put the child render object +/// relative to the others in the parent render object. +/// +/// A child's [slot] is determined when the parent calls [updateChild] to +/// inflate the child (see the next section). It can be updated by calling +/// [updateSlotForChild]. +/// +/// ### Updating children +/// +/// Early in the lifecycle of an element, the framework calls the [mount] +/// method. This method should call [updateChild] for each child, passing in +/// the widget for that child, and the slot for that child, thus obtaining a +/// list of child [Element]s. +/// +/// Subsequently, the framework will call the [update] method. In this method, +/// the [RenderObjectElement] should call [updateChild] for each child, passing +/// in the [Element] that was obtained during [mount] or the last time [update] +/// was run (whichever happened most recently), the new [Widget], and the slot. +/// This provides the object with a new list of [Element] objects. +/// +/// Where possible, the [update] method should attempt to map the elements from +/// the last pass to the widgets in the new pass. For example, if one of the +/// elements from the last pass was configured with a particular [Key], and one +/// of the widgets in this new pass has that same key, they should be paired up, +/// and the old element should be updated with the widget (and the slot +/// corresponding to the new widget's new position, also). The [updateChildren] +/// method may be useful in this regard. +/// +/// [updateChild] should be called for children in their logical order. The +/// order can matter; for example, if two of the children use [PageStorage]'s +/// `writeState` feature in their build method (and neither has a [Widget.key]), +/// then the state written by the first will be overwritten by the second. +/// +/// #### Dynamically determining the children during the build phase +/// +/// The child widgets need not necessarily come from this element's widget +/// verbatim. They could be generated dynamically from a callback, or generated +/// in other more creative ways. +/// +/// #### Dynamically determining the children during layout +/// +/// If the widgets are to be generated at layout time, then generating them in +/// the [mount] and [update] methods won't work: layout of this element's render +/// object hasn't started yet at that point. Instead, the [update] method can +/// mark the render object as needing layout (see +/// [RenderObject.markNeedsLayout]), and then the render object's +/// [RenderObject.performLayout] method can call back to the element to have it +/// generate the widgets and call [updateChild] accordingly. +/// +/// For a render object to call an element during layout, it must use +/// [RenderObject.invokeLayoutCallback]. For an element to call [updateChild] +/// outside of its [update] method, it must use [BuildOwner.buildScope]. +/// +/// The framework provides many more checks in normal operation than it does +/// when doing a build during layout. For this reason, creating widgets with +/// layout-time build semantics should be done with great care. +/// +/// #### Handling errors when building +/// +/// If an element calls a builder function to obtain widgets for its children, +/// it may find that the build throws an exception. Such exceptions should be +/// caught and reported using [FlutterError.reportError]. If a child is needed +/// but a builder has failed in this way, an instance of [ErrorWidget] can be +/// used instead. +/// +/// ### Detaching children +/// +/// It is possible, when using [GlobalKey]s, for a child to be proactively +/// removed by another element before this element has been updated. +/// (Specifically, this happens when the subtree rooted at a widget with a +/// particular [GlobalKey] is being moved from this element to an element +/// processed earlier in the build phase.) When this happens, this element's +/// [forgetChild] method will be called with a reference to the affected child +/// element. +/// +/// The [forgetChild] method of a [RenderObjectElement] subclass must remove the +/// child element from its child list, so that when it next [update]s its +/// children, the removed child is not considered. +/// +/// For performance reasons, if there are many elements, it may be quicker to +/// track which elements were forgotten by storing them in a [Set], rather than +/// proactively mutating the local record of the child list and the identities +/// of all the slots. For example, see the implementation of +/// [MultiChildRenderObjectElement]. +/// +/// ### Maintaining the render object tree +/// +/// Once a descendant produces a render object, it will call +/// [insertRenderObjectChild]. If the descendant's slot changes identity, it +/// will call [moveRenderObjectChild]. If a descendant goes away, it will call +/// [removeRenderObjectChild]. +/// +/// These three methods should update the render tree accordingly, attaching, +/// moving, and detaching the given child render object from this element's own +/// render object respectively. +/// +/// ### Walking the children +/// +/// If a [RenderObjectElement] object has any children [Element]s, it must +/// expose them in its implementation of the [visitChildren] method. This method +/// is used by many of the framework's internal mechanisms, and so should be +/// fast. It is also used by the test framework and [debugDumpApp]. +abstract class RenderObjectElement extends Element { + /// Creates an element that uses the given widget as its configuration. + RenderObjectElement(RenderObjectWidget super.widget); + + /// The underlying [RenderObject] for this element. + /// + /// If this element has been [unmount]ed, this getter will throw. + @override + RenderObject get renderObject { + assert(_renderObject != null, '$runtimeType unmounted'); + return _renderObject!; + } + RenderObject? _renderObject; + + @override + Element? get renderObjectAttachingChild => null; + + bool _debugDoingBuild = false; + @override + bool get debugDoingBuild => _debugDoingBuild; + + RenderObjectElement? _ancestorRenderObjectElement; + + RenderObjectElement? _findAncestorRenderObjectElement() { + Element? ancestor = _parent; + while (ancestor != null && ancestor is! RenderObjectElement) { + // In debug mode we check whether the ancestor accepts RenderObjects to + // produce a better error message in attachRenderObject. In release mode, + // we assume only correct trees are built (i.e. + // debugExpectsRenderObjectForSlot always returns true) and don't check + // explicitly. + assert(() { + if (!ancestor!.debugExpectsRenderObjectForSlot(slot)) { + ancestor = null; + } + return true; + }()); + ancestor = ancestor?._parent; + } + assert(() { + if (ancestor?.debugExpectsRenderObjectForSlot(slot) == false) { + ancestor = null; + } + return true; + }()); + return ancestor as RenderObjectElement?; + } + + void _debugCheckCompetingAncestors( + List<ParentDataElement<ParentData>> result, + Set<Type> debugAncestorTypes, + Set<Type> debugParentDataTypes, + List<Type> debugAncestorCulprits, + ) { + assert(() { + // Check that no other ParentDataWidgets of the same + // type want to provide parent data. + if (debugAncestorTypes.length != result.length || debugParentDataTypes.length != result.length) { + // This can only occur if the Sets of ancestors and parent data types was + // provided a dupe and did not add it. + assert(debugAncestorTypes.length < result.length || debugParentDataTypes.length < result.length); + try { + // We explicitly throw here (even though we immediately redirect the + // exception elsewhere) so that debuggers will notice it when they + // have "break on exception" enabled. + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Incorrect use of ParentDataWidget.'), + ErrorDescription( + 'Competing ParentDataWidgets are providing parent data to the ' + 'same RenderObject:' + ), + for (final ParentDataElement<ParentData> ancestor in result.where((ParentDataElement<ParentData> ancestor) { + return debugAncestorCulprits.contains(ancestor.runtimeType); + })) + ErrorDescription( + '- ${ancestor.widget}, which writes ParentData of type ' + '${ancestor.debugParentDataType}, (typically placed directly ' + 'inside a ' + '${(ancestor.widget as ParentDataWidget<ParentData>).debugTypicalAncestorWidgetClass} ' + 'widget)' + ), + ErrorDescription( + 'A RenderObject can receive parent data from multiple ' + 'ParentDataWidgets, but the Type of ParentData must be unique to ' + 'prevent one overwriting another.' + ), + ErrorHint( + 'Usually, this indicates that one or more of the offending ' + "ParentDataWidgets listed above isn't placed inside a dedicated " + "compatible ancestor widget that it isn't sharing with another " + 'ParentDataWidget of the same type.' + ), + ErrorHint( + 'Otherwise, separating aspects of ParentData to prevent ' + 'conflicts can be done using mixins, mixing them all in on the ' + 'full ParentData Object, such as KeepAlive does with ' + 'KeepAliveParentDataMixin.' + ), + ErrorDescription( + 'The ownership chain for the RenderObject that received the ' + 'parent data was:\n ${debugGetCreatorChain(10)}' + ), + ]); + } on FlutterError catch (error) { + _reportException( + ErrorSummary('while looking for parent data.'), + error, + error.stackTrace, + ); + } + } + return true; + }()); + } + + List<ParentDataElement<ParentData>> _findAncestorParentDataElements() { + Element? ancestor = _parent; + final List<ParentDataElement<ParentData>> result = <ParentDataElement<ParentData>>[]; + final Set<Type> debugAncestorTypes = <Type>{}; + final Set<Type> debugParentDataTypes = <Type>{}; + final List<Type> debugAncestorCulprits = <Type>[]; + + // More than one ParentDataWidget can contribute ParentData, but there are + // some constraints. + // 1. ParentData can only be written by unique ParentDataWidget types. + // For example, two KeepAlive ParentDataWidgets trying to write to the + // same child is not allowed. + // 2. Each contributing ParentDataWidget must contribute to a unique + // ParentData type, less ParentData be overwritten. + // For example, there cannot be two ParentDataWidgets that both write + // ParentData of type KeepAliveParentDataMixin, if the first check was + // subverted by a subclassing of the KeepAlive ParentDataWidget. + // 3. The ParentData itself must be compatible with all ParentDataWidgets + // writing to it. + // For example, TwoDimensionalViewportParentData uses the + // KeepAliveParentDataMixin, so it could be compatible with both + // KeepAlive, and another ParentDataWidget with ParentData type + // TwoDimensionalViewportParentData or a subclass thereof. + // The first and second cases are verified here. The third is verified in + // debugIsValidRenderObject. + + while (ancestor != null && ancestor is! RenderObjectElement) { + if (ancestor is ParentDataElement<ParentData>) { + assert((ParentDataElement<ParentData> ancestor) { + if (!debugAncestorTypes.add(ancestor.runtimeType) || !debugParentDataTypes.add(ancestor.debugParentDataType)) { + debugAncestorCulprits.add(ancestor.runtimeType); + } + return true; + }(ancestor)); + result.add(ancestor); + } + ancestor = ancestor._parent; + } + assert(() { + if (result.isEmpty || ancestor == null) { + return true; + } + // Validate points 1 and 2 from above. + _debugCheckCompetingAncestors( + result, + debugAncestorTypes, + debugParentDataTypes, + debugAncestorCulprits, + ); + return true; + }()); + return result; + } + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + assert(() { + _debugDoingBuild = true; + return true; + }()); + _renderObject = (widget as RenderObjectWidget).createRenderObject(this); + assert(!_renderObject!.debugDisposed!); + assert(() { + _debugDoingBuild = false; + return true; + }()); + assert(() { + _debugUpdateRenderObjectOwner(); + return true; + }()); + assert(slot == newSlot); + attachRenderObject(newSlot); + super.performRebuild(); // clears the "dirty" flag + } + + @override + void update(covariant RenderObjectWidget newWidget) { + super.update(newWidget); + assert(widget == newWidget); + assert(() { + _debugUpdateRenderObjectOwner(); + return true; + }()); + _performRebuild(); // calls widget.updateRenderObject() + } + + void _debugUpdateRenderObjectOwner() { + assert(() { + renderObject.debugCreator = DebugCreator(this); + return true; + }()); + } + + @override + void performRebuild() { // ignore: must_call_super, _performRebuild calls super. + _performRebuild(); // calls widget.updateRenderObject() + } + + @pragma('vm:prefer-inline') + void _performRebuild() { + assert(() { + _debugDoingBuild = true; + return true; + }()); + (widget as RenderObjectWidget).updateRenderObject(this, renderObject); + assert(() { + _debugDoingBuild = false; + return true; + }()); + super.performRebuild(); // clears the "dirty" flag + } + + @override + void deactivate() { + super.deactivate(); + assert( + !renderObject.attached, + 'A RenderObject was still attached when attempting to deactivate its ' + 'RenderObjectElement: $renderObject', + ); + } + + @override + void unmount() { + assert( + !renderObject.debugDisposed!, + 'A RenderObject was disposed prior to its owning element being unmounted: ' + '$renderObject', + ); + final RenderObjectWidget oldWidget = widget as RenderObjectWidget; + super.unmount(); + assert( + !renderObject.attached, + 'A RenderObject was still attached when attempting to unmount its ' + 'RenderObjectElement: $renderObject', + ); + oldWidget.didUnmountRenderObject(renderObject); + _renderObject!.dispose(); + _renderObject = null; + } + + void _updateParentData(ParentDataWidget<ParentData> parentDataWidget) { + bool applyParentData = true; + assert(() { + try { + if (!parentDataWidget.debugIsValidRenderObject(renderObject)) { + applyParentData = false; + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Incorrect use of ParentDataWidget.'), + ...parentDataWidget._debugDescribeIncorrectParentDataType( + parentData: renderObject.parentData, + parentDataCreator: _ancestorRenderObjectElement!.widget as RenderObjectWidget, + ownershipChain: ErrorDescription(debugGetCreatorChain(10)), + ), + ]); + } + } on FlutterError catch (e) { + // We catch the exception directly to avoid activating the ErrorWidget, + // while still allowing debuggers to break on exception. Since the tree + // is in a broken state, adding the ErrorWidget would likely cause more + // exceptions, which is not good for the debugging experience. + _reportException(ErrorSummary('while applying parent data.'), e, e.stackTrace); + } + return true; + }()); + if (applyParentData) { + parentDataWidget.applyParentData(renderObject); + } + } + + @override + void updateSlot(Object? newSlot) { + final Object? oldSlot = slot; + assert(oldSlot != newSlot); + super.updateSlot(newSlot); + assert(slot == newSlot); + assert(_ancestorRenderObjectElement == _findAncestorRenderObjectElement()); + _ancestorRenderObjectElement?.moveRenderObjectChild(renderObject, oldSlot, slot); + } + + @override + void attachRenderObject(Object? newSlot) { + assert(_ancestorRenderObjectElement == null); + _slot = newSlot; + _ancestorRenderObjectElement = _findAncestorRenderObjectElement(); + assert(() { + if (_ancestorRenderObjectElement == null) { + FlutterError.reportError(FlutterErrorDetails(exception: FlutterError.fromParts( + <DiagnosticsNode>[ + ErrorSummary( + 'The render object for ${toStringShort()} cannot find ancestor render object to attach to.', + ), + ErrorDescription( + 'The ownership chain for the RenderObject in question was:\n ${debugGetCreatorChain(10)}', + ), + ErrorHint( + 'Try wrapping your widget in a View widget or any other widget that is backed by ' + 'a $RenderTreeRootElement to serve as the root of the render tree.', + ), + ] + ))); + } + return true; + }()); + _ancestorRenderObjectElement?.insertRenderObjectChild(renderObject, newSlot); + final List<ParentDataElement<ParentData>> parentDataElements = _findAncestorParentDataElements(); + for (final ParentDataElement<ParentData> parentDataElement in parentDataElements) { + _updateParentData(parentDataElement.widget as ParentDataWidget<ParentData>); + } + } + + @override + void detachRenderObject() { + if (_ancestorRenderObjectElement != null) { + _ancestorRenderObjectElement!.removeRenderObjectChild(renderObject, slot); + _ancestorRenderObjectElement = null; + } + _slot = null; + } + + /// Insert the given child into [renderObject] at the given slot. + /// + /// {@template flutter.widgets.RenderObjectElement.insertRenderObjectChild} + /// The semantics of `slot` are determined by this element. For example, if + /// this element has a single child, the slot should always be null. If this + /// element has a list of children, the previous sibling element wrapped in an + /// [IndexedSlot] is a convenient value for the slot. + /// {@endtemplate} + @protected + void insertRenderObjectChild(covariant RenderObject child, covariant Object? slot); + + /// Move the given child from the given old slot to the given new slot. + /// + /// The given child is guaranteed to have [renderObject] as its parent. + /// + /// {@macro flutter.widgets.RenderObjectElement.insertRenderObjectChild} + /// + /// This method is only ever called if [updateChild] can end up being called + /// with an existing [Element] child and a `slot` that differs from the slot + /// that element was previously given. [MultiChildRenderObjectElement] does this, + /// for example. [SingleChildRenderObjectElement] does not (since the `slot` is + /// always null). An [Element] that has a specific set of slots with each child + /// always having the same slot (and where children in different slots are never + /// compared against each other for the purposes of updating one slot with the + /// element from another slot) would never call this. + @protected + void moveRenderObjectChild(covariant RenderObject child, covariant Object? oldSlot, covariant Object? newSlot); + + /// Remove the given child from [renderObject]. + /// + /// The given child is guaranteed to have been inserted at the given `slot` + /// and have [renderObject] as its parent. + @protected + void removeRenderObjectChild(covariant RenderObject child, covariant Object? slot); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<RenderObject>('renderObject', _renderObject, defaultValue: null)); + } +} + +/// Deprecated. Unused in the framework and will be removed in a future version +/// of Flutter. +/// +/// Classes that extend this class can extend [RenderObjectElement] and mixin +/// [RootElementMixin] instead. +@Deprecated( + 'Use RootElementMixin instead. ' + 'This feature was deprecated after v3.9.0-16.0.pre.' +) +abstract class RootRenderObjectElement extends RenderObjectElement with RootElementMixin { + /// Initializes fields for subclasses. + @Deprecated( + 'Use RootElementMixin instead. ' + 'This feature was deprecated after v3.9.0-16.0.pre.' + ) + RootRenderObjectElement(super.widget); +} + +/// Mixin for the element at the root of the tree. +/// +/// Only root elements may have their owner set explicitly. All other +/// elements inherit their owner from their parent. +mixin RootElementMixin on Element { + /// Set the owner of the element. The owner will be propagated to all the + /// descendants of this element. + /// + /// The owner manages the dirty elements list. + /// + /// The [WidgetsBinding] introduces the primary owner, + /// [WidgetsBinding.buildOwner], and assigns it to the widget tree in the call + /// to [runApp]. The binding is responsible for driving the build pipeline by + /// calling the build owner's [BuildOwner.buildScope] method. See + /// [WidgetsBinding.drawFrame]. + // ignore: use_setters_to_change_properties, (API predates enforcing the lint) + void assignOwner(BuildOwner owner) { + _owner = owner; + } + + @override + void mount(Element? parent, Object? newSlot) { + // Root elements should never have parents. + assert(parent == null); + assert(newSlot == null); + super.mount(parent, newSlot); + } +} + +/// An [Element] that uses a [LeafRenderObjectWidget] as its configuration. +class LeafRenderObjectElement extends RenderObjectElement { + /// Creates an element that uses the given widget as its configuration. + LeafRenderObjectElement(LeafRenderObjectWidget super.widget); + + @override + void forgetChild(Element child) { + assert(false); + super.forgetChild(child); + } + + @override + void insertRenderObjectChild(RenderObject child, Object? slot) { + assert(false); + } + + @override + void moveRenderObjectChild(RenderObject child, Object? oldSlot, Object? newSlot) { + assert(false); + } + + @override + void removeRenderObjectChild(RenderObject child, Object? slot) { + assert(false); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return widget.debugDescribeChildren(); + } +} + +/// An [Element] that uses a [SingleChildRenderObjectWidget] as its configuration. +/// +/// The child is optional. +/// +/// This element subclass can be used for [RenderObjectWidget]s whose +/// [RenderObject]s use the [RenderObjectWithChildMixin] mixin. Such widgets are +/// expected to inherit from [SingleChildRenderObjectWidget]. +class SingleChildRenderObjectElement extends RenderObjectElement { + /// Creates an element that uses the given widget as its configuration. + SingleChildRenderObjectElement(SingleChildRenderObjectWidget super.widget); + + Element? _child; + + @override + void visitChildren(ElementVisitor visitor) { + if (_child != null) { + visitor(_child!); + } + } + + @override + void forgetChild(Element child) { + assert(child == _child); + _child = null; + super.forgetChild(child); + } + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + _child = updateChild(_child, (widget as SingleChildRenderObjectWidget).child, null); + } + + @override + void update(SingleChildRenderObjectWidget newWidget) { + super.update(newWidget); + assert(widget == newWidget); + _child = updateChild(_child, (widget as SingleChildRenderObjectWidget).child, null); + } + + @override + void insertRenderObjectChild(RenderObject child, Object? slot) { + final RenderObjectWithChildMixin<RenderObject> renderObject = this.renderObject as RenderObjectWithChildMixin<RenderObject>; + assert(slot == null); + assert(renderObject.debugValidateChild(child)); + renderObject.child = child; + assert(renderObject == this.renderObject); + } + + @override + void moveRenderObjectChild(RenderObject child, Object? oldSlot, Object? newSlot) { + assert(false); + } + + @override + void removeRenderObjectChild(RenderObject child, Object? slot) { + final RenderObjectWithChildMixin<RenderObject> renderObject = this.renderObject as RenderObjectWithChildMixin<RenderObject>; + assert(slot == null); + assert(renderObject.child == child); + renderObject.child = null; + assert(renderObject == this.renderObject); + } +} + +/// An [Element] that uses a [MultiChildRenderObjectWidget] as its configuration. +/// +/// This element subclass can be used for [RenderObjectWidget]s whose +/// [RenderObject]s use the [ContainerRenderObjectMixin] mixin with a parent data +/// type that implements [ContainerParentDataMixin<RenderObject>]. Such widgets +/// are expected to inherit from [MultiChildRenderObjectWidget]. +/// +/// See also: +/// +/// * [IndexedSlot], which is used as [Element.slot]s for the children of a +/// [MultiChildRenderObjectElement]. +/// * [RenderObjectElement.updateChildren], which discusses why [IndexedSlot] +/// is used for the slots of the children. +class MultiChildRenderObjectElement extends RenderObjectElement { + /// Creates an element that uses the given widget as its configuration. + MultiChildRenderObjectElement(MultiChildRenderObjectWidget super.widget) + : assert(!debugChildrenHaveDuplicateKeys(widget, widget.children)); + + @override + ContainerRenderObjectMixin<RenderObject, ContainerParentDataMixin<RenderObject>> get renderObject { + return super.renderObject as ContainerRenderObjectMixin<RenderObject, ContainerParentDataMixin<RenderObject>>; + } + + /// The current list of children of this element. + /// + /// This list is filtered to hide elements that have been forgotten (using + /// [forgetChild]). + @protected + @visibleForTesting + Iterable<Element> get children => _children.where((Element child) => !_forgottenChildren.contains(child)); + + late List<Element> _children; + // We keep a set of forgotten children to avoid O(n^2) work walking _children + // repeatedly to remove children. + final Set<Element> _forgottenChildren = HashSet<Element>(); + + @override + void insertRenderObjectChild(RenderObject child, IndexedSlot<Element?> slot) { + final ContainerRenderObjectMixin<RenderObject, ContainerParentDataMixin<RenderObject>> renderObject = this.renderObject; + assert(renderObject.debugValidateChild(child)); + renderObject.insert(child, after: slot.value?.renderObject); + assert(renderObject == this.renderObject); + } + + @override + void moveRenderObjectChild(RenderObject child, IndexedSlot<Element?> oldSlot, IndexedSlot<Element?> newSlot) { + final ContainerRenderObjectMixin<RenderObject, ContainerParentDataMixin<RenderObject>> renderObject = this.renderObject; + assert(child.parent == renderObject); + renderObject.move(child, after: newSlot.value?.renderObject); + assert(renderObject == this.renderObject); + } + + @override + void removeRenderObjectChild(RenderObject child, Object? slot) { + final ContainerRenderObjectMixin<RenderObject, ContainerParentDataMixin<RenderObject>> renderObject = this.renderObject; + assert(child.parent == renderObject); + renderObject.remove(child); + assert(renderObject == this.renderObject); + } + + @override + void visitChildren(ElementVisitor visitor) { + for (final Element child in _children) { + if (!_forgottenChildren.contains(child)) { + visitor(child); + } + } + } + + @override + void forgetChild(Element child) { + assert(_children.contains(child)); + assert(!_forgottenChildren.contains(child)); + _forgottenChildren.add(child); + super.forgetChild(child); + } + + bool _debugCheckHasAssociatedRenderObject(Element newChild) { + assert(() { + if (newChild.renderObject == null) { + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The children of `MultiChildRenderObjectElement` must each has an associated render object.'), + ErrorHint( + 'This typically means that the `${newChild.widget}` or its children\n' + 'are not a subtype of `RenderObjectWidget`.', + ), + newChild.describeElement('The following element does not have an associated render object'), + DiagnosticsDebugCreator(DebugCreator(newChild)), + ]), + ), + ); + } + return true; + }()); + return true; + } + + @override + Element inflateWidget(Widget newWidget, Object? newSlot) { + final Element newChild = super.inflateWidget(newWidget, newSlot); + assert(_debugCheckHasAssociatedRenderObject(newChild)); + return newChild; + } + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + final MultiChildRenderObjectWidget multiChildRenderObjectWidget = widget as MultiChildRenderObjectWidget; + final List<Element> children = List<Element>.filled(multiChildRenderObjectWidget.children.length, _NullElement.instance); + Element? previousChild; + for (int i = 0; i < children.length; i += 1) { + final Element newChild = inflateWidget(multiChildRenderObjectWidget.children[i], IndexedSlot<Element?>(i, previousChild)); + children[i] = newChild; + previousChild = newChild; + } + _children = children; + } + + @override + void update(MultiChildRenderObjectWidget newWidget) { + super.update(newWidget); + final MultiChildRenderObjectWidget multiChildRenderObjectWidget = widget as MultiChildRenderObjectWidget; + assert(widget == newWidget); + assert(!debugChildrenHaveDuplicateKeys(widget, multiChildRenderObjectWidget.children)); + _children = updateChildren(_children, multiChildRenderObjectWidget.children, forgottenChildren: _forgottenChildren); + _forgottenChildren.clear(); + } +} + +/// A [RenderObjectElement] used to manage the root of a render tree. +/// +/// Unlike any other render object element this element does not attempt to +/// attach its [renderObject] to the closest ancestor [RenderObjectElement]. +/// Instead, subclasses must override [attachRenderObject] and +/// [detachRenderObject] to attach/detach the [renderObject] to whatever +/// instance manages the render tree (e.g. by assigning it to +/// [PipelineOwner.rootNode]). +abstract class RenderTreeRootElement extends RenderObjectElement { + /// Creates an element that uses the given widget as its configuration. + RenderTreeRootElement(super.widget); + + @override + @mustCallSuper + void attachRenderObject(Object? newSlot) { + _slot = newSlot; + assert(_debugCheckMustNotAttachRenderObjectToAncestor()); + } + + @override + @mustCallSuper + void detachRenderObject() { + _slot = null; + } + + @override + void updateSlot(Object? newSlot) { + super.updateSlot(newSlot); + assert(_debugCheckMustNotAttachRenderObjectToAncestor()); + } + + bool _debugCheckMustNotAttachRenderObjectToAncestor() { + if (!kDebugMode) { + return true; + } + if (_findAncestorRenderObjectElement() != null) { + throw FlutterError.fromParts( + <DiagnosticsNode>[ + ErrorSummary( + 'The RenderObject for ${toStringShort()} cannot maintain an independent render tree at its current location.', + ), + ErrorDescription( + 'The ownership chain for the RenderObject in question was:\n ${debugGetCreatorChain(10)}', + ), + ErrorDescription( + 'This RenderObject is the root of an independent render tree and it cannot ' + 'attach itself to an ancestor in an existing tree. The ancestor RenderObject, ' + 'however, expects that a child will be attached.', + ), + ErrorHint( + 'Try moving the subtree that contains the ${toStringShort()} widget into the ' + 'view property of a ViewAnchor widget or to the root of the widget tree, where ' + 'it is not expected to attach its RenderObject to a parent.', + ), + ], + ); + } + return true; + } +} + +/// A wrapper class for the [Element] that is the creator of a [RenderObject]. +/// +/// Setting a [DebugCreator] as [RenderObject.debugCreator] will lead to better +/// error messages. +class DebugCreator { + /// Create a [DebugCreator] instance with input [Element]. + DebugCreator(this.element); + + /// The creator of the [RenderObject]. + final Element element; + + @override + String toString() => element.debugGetCreatorChain(12); +} + +FlutterErrorDetails _reportException( + DiagnosticsNode context, + Object exception, + StackTrace? stack, { + InformationCollector? informationCollector, +}) { + final FlutterErrorDetails details = FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets library', + context: context, + informationCollector: informationCollector, + ); + FlutterError.reportError(details); + return details; +} + +/// A value for [Element.slot] used for children of +/// [MultiChildRenderObjectElement]s. +/// +/// A slot for a [MultiChildRenderObjectElement] consists of an [index] +/// identifying where the child occupying this slot is located in the +/// [MultiChildRenderObjectElement]'s child list and an arbitrary [value] that +/// can further define where the child occupying this slot fits in its +/// parent's child list. +/// +/// See also: +/// +/// * [RenderObjectElement.updateChildren], which discusses why this class is +/// used as slot values for the children of a [MultiChildRenderObjectElement]. +@immutable +class IndexedSlot<T extends Element?> { + /// Creates an [IndexedSlot] with the provided [index] and slot [value]. + const IndexedSlot(this.index, this.value); + + /// Information to define where the child occupying this slot fits in its + /// parent's child list. + final T value; + + /// The index of this slot in the parent's child list. + final int index; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is IndexedSlot + && index == other.index + && value == other.value; + } + + @override + int get hashCode => Object.hash(index, value); +} + +/// Used as a placeholder in [List<Element>] objects when the actual +/// elements are not yet determined. +class _NullElement extends Element { + _NullElement() : super(const _NullWidget()); + + static _NullElement instance = _NullElement(); + + @override + bool get debugDoingBuild => throw UnimplementedError(); +} + +class _NullWidget extends Widget { + const _NullWidget(); + + @override + Element createElement() => throw UnimplementedError(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/gesture_detector.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/gesture_detector.dart new file mode 100644 index 0000000000000000000000000000000000000000..43c7caa7646831fda225c38e84746b453ffc5c32 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/gesture_detector.dart @@ -0,0 +1,1736 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'media_query.dart'; + +export 'package:flutter/gestures.dart' show + DragDownDetails, + DragEndDetails, + DragStartDetails, + DragUpdateDetails, + ForcePressDetails, + GestureDragCancelCallback, + GestureDragDownCallback, + GestureDragEndCallback, + GestureDragStartCallback, + GestureDragUpdateCallback, + GestureForcePressEndCallback, + GestureForcePressPeakCallback, + GestureForcePressStartCallback, + GestureForcePressUpdateCallback, + GestureLongPressCallback, + GestureLongPressEndCallback, + GestureLongPressMoveUpdateCallback, + GestureLongPressStartCallback, + GestureLongPressUpCallback, + GestureScaleEndCallback, + GestureScaleStartCallback, + GestureScaleUpdateCallback, + GestureTapCallback, + GestureTapCancelCallback, + GestureTapDownCallback, + GestureTapUpCallback, + LongPressEndDetails, + LongPressMoveUpdateDetails, + LongPressStartDetails, + ScaleEndDetails, + ScaleStartDetails, + ScaleUpdateDetails, + TapDownDetails, + TapUpDetails, + Velocity; +export 'package:flutter/rendering.dart' show RenderSemanticsGestureHandler; + +// Examples can assume: +// late bool _lights; +// void setState(VoidCallback fn) { } +// late String _last; +// late Color _color; + +/// Factory for creating gesture recognizers. +/// +/// `T` is the type of gesture recognizer this class manages. +/// +/// Used by [RawGestureDetector.gestures]. +@optionalTypeArgs +abstract class GestureRecognizerFactory<T extends GestureRecognizer> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const GestureRecognizerFactory(); + + /// Must return an instance of T. + T constructor(); + + /// Must configure the given instance (which will have been created by + /// `constructor`). + /// + /// This normally means setting the callbacks. + void initializer(T instance); + + bool _debugAssertTypeMatches(Type type) { + assert(type == T, 'GestureRecognizerFactory of type $T was used where type $type was specified.'); + return true; + } +} + +/// Signature for closures that implement [GestureRecognizerFactory.constructor]. +typedef GestureRecognizerFactoryConstructor<T extends GestureRecognizer> = T Function(); + +/// Signature for closures that implement [GestureRecognizerFactory.initializer]. +typedef GestureRecognizerFactoryInitializer<T extends GestureRecognizer> = void Function(T instance); + +/// Factory for creating gesture recognizers that delegates to callbacks. +/// +/// Used by [RawGestureDetector.gestures]. +class GestureRecognizerFactoryWithHandlers<T extends GestureRecognizer> extends GestureRecognizerFactory<T> { + /// Creates a gesture recognizer factory with the given callbacks. + const GestureRecognizerFactoryWithHandlers(this._constructor, this._initializer); + + final GestureRecognizerFactoryConstructor<T> _constructor; + + final GestureRecognizerFactoryInitializer<T> _initializer; + + @override + T constructor() => _constructor(); + + @override + void initializer(T instance) => _initializer(instance); +} + +/// A widget that detects gestures. +/// +/// Attempts to recognize gestures that correspond to its non-null callbacks. +/// +/// If this widget has a child, it defers to that child for its sizing behavior. +/// If it does not have a child, it grows to fit the parent instead. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=WhVXkCFPmK4} +/// +/// By default a GestureDetector with an invisible child ignores touches; +/// this behavior can be controlled with [behavior]. +/// +/// GestureDetector also listens for accessibility events and maps +/// them to the callbacks. To ignore accessibility events, set +/// [excludeFromSemantics] to true. +/// +/// See <http://flutter.dev/gestures/> for additional information. +/// +/// Material design applications typically react to touches with ink splash +/// effects. The [InkWell] class implements this effect and can be used in place +/// of a [GestureDetector] for handling taps. +/// +/// {@tool dartpad} +/// This example contains a black light bulb wrapped in a [GestureDetector]. It +/// turns the light bulb yellow when the "TURN LIGHT ON" button is tapped by +/// setting the `_lights` field, and off again when "TURN LIGHT OFF" is tapped. +/// +/// ** See code in examples/api/lib/widgets/gesture_detector/gesture_detector.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example uses a [Container] that wraps a [GestureDetector] widget which +/// detects a tap. +/// +/// Since the [GestureDetector] does not have a child, it takes on the size of its +/// parent, making the entire area of the surrounding [Container] clickable. When +/// tapped, the [Container] turns yellow by setting the `_color` field. When +/// tapped again, it goes back to white. +/// +/// ** See code in examples/api/lib/widgets/gesture_detector/gesture_detector.1.dart ** +/// {@end-tool} +/// +/// ### Troubleshooting +/// +/// Why isn't my parent [GestureDetector.onTap] method called? +/// +/// Given a parent [GestureDetector] with an onTap callback, and a child +/// GestureDetector that also defines an onTap callback, when the inner +/// GestureDetector is tapped, both GestureDetectors send a [GestureRecognizer] +/// into the gesture arena. This is because the pointer coordinates are within the +/// bounds of both GestureDetectors. The child GestureDetector wins in this +/// scenario because it was the first to enter the arena, resolving as first come, +/// first served. The child onTap is called, and the parent's is not as the gesture has +/// been consumed. +/// For more information on gesture disambiguation see: +/// [Gesture disambiguation](https://docs.flutter.dev/development/ui/advanced/gestures#gesture-disambiguation). +/// +/// Setting [GestureDetector.behavior] to [HitTestBehavior.opaque] +/// or [HitTestBehavior.translucent] has no impact on parent-child relationships: +/// both GestureDetectors send a GestureRecognizer into the gesture arena, only one wins. +/// +/// Some callbacks (e.g. onTapDown) can fire before a recognizer wins the arena, +/// and others (e.g. onTapCancel) fire even when it loses the arena. Therefore, +/// the parent detector in the example above may call some of its callbacks even +/// though it loses in the arena. +/// +/// {@tool dartpad} +/// This example uses a [GestureDetector] that wraps a green [Container] and a second +/// GestureDetector that wraps a yellow Container. The second GestureDetector is +/// a child of the green Container. +/// Both GestureDetectors define an onTap callback. When the callback is called it +/// adds a red border to the corresponding Container. +/// +/// When the green Container is tapped, it's parent GestureDetector enters +/// the gesture arena. It wins because there is no competing GestureDetector and +/// the green Container shows a red border. +/// When the yellow Container is tapped, it's parent GestureDetector enters +/// the gesture arena. The GestureDetector that wraps the green Container also +/// enters the gesture arena (the pointer events coordinates are inside both +/// GestureDetectors bounds). The GestureDetector that wraps the yellow Container +/// wins because it was the first detector to enter the arena. +/// +/// This example sets [debugPrintGestureArenaDiagnostics] to true. +/// This flag prints useful information about gesture arenas. +/// +/// Changing the [GestureDetector.behavior] property to [HitTestBehavior.translucent] +/// or [HitTestBehavior.opaque] has no impact: both GestureDetectors send a [GestureRecognizer] +/// into the gesture arena, only one wins. +/// +/// ** See code in examples/api/lib/widgets/gesture_detector/gesture_detector.2.dart ** +/// {@end-tool} +/// +/// ## Debugging +/// +/// To see how large the hit test box of a [GestureDetector] is for debugging +/// purposes, set [debugPaintPointersEnabled] to true. +/// +/// See also: +/// +/// * [Listener], a widget for listening to lower-level raw pointer events. +/// * [MouseRegion], a widget that tracks the movement of mice, even when no +/// button is pressed. +/// * [RawGestureDetector], a widget that is used to detect custom gestures. +class GestureDetector extends StatelessWidget { + /// Creates a widget that detects gestures. + /// + /// Pan and scale callbacks cannot be used simultaneously because scale is a + /// superset of pan. Use the scale callbacks instead. + /// + /// Horizontal and vertical drag callbacks cannot be used simultaneously + /// because a combination of a horizontal and vertical drag is a pan. + /// Use the pan callbacks instead. + /// + /// {@youtube 560 315 https://www.youtube.com/watch?v=WhVXkCFPmK4} + /// + /// By default, gesture detectors contribute semantic information to the tree + /// that is used by assistive technology. + GestureDetector({ + super.key, + this.child, + this.onTapDown, + this.onTapUp, + this.onTap, + this.onTapCancel, + this.onSecondaryTap, + this.onSecondaryTapDown, + this.onSecondaryTapUp, + this.onSecondaryTapCancel, + this.onTertiaryTapDown, + this.onTertiaryTapUp, + this.onTertiaryTapCancel, + this.onDoubleTapDown, + this.onDoubleTap, + this.onDoubleTapCancel, + this.onLongPressDown, + this.onLongPressCancel, + this.onLongPress, + this.onLongPressStart, + this.onLongPressMoveUpdate, + this.onLongPressUp, + this.onLongPressEnd, + this.onSecondaryLongPressDown, + this.onSecondaryLongPressCancel, + this.onSecondaryLongPress, + this.onSecondaryLongPressStart, + this.onSecondaryLongPressMoveUpdate, + this.onSecondaryLongPressUp, + this.onSecondaryLongPressEnd, + this.onTertiaryLongPressDown, + this.onTertiaryLongPressCancel, + this.onTertiaryLongPress, + this.onTertiaryLongPressStart, + this.onTertiaryLongPressMoveUpdate, + this.onTertiaryLongPressUp, + this.onTertiaryLongPressEnd, + this.onVerticalDragDown, + this.onVerticalDragStart, + this.onVerticalDragUpdate, + this.onVerticalDragEnd, + this.onVerticalDragCancel, + this.onHorizontalDragDown, + this.onHorizontalDragStart, + this.onHorizontalDragUpdate, + this.onHorizontalDragEnd, + this.onHorizontalDragCancel, + this.onForcePressStart, + this.onForcePressPeak, + this.onForcePressUpdate, + this.onForcePressEnd, + this.onPanDown, + this.onPanStart, + this.onPanUpdate, + this.onPanEnd, + this.onPanCancel, + this.onScaleStart, + this.onScaleUpdate, + this.onScaleEnd, + this.behavior, + this.excludeFromSemantics = false, + this.dragStartBehavior = DragStartBehavior.start, + this.trackpadScrollCausesScale = false, + this.trackpadScrollToScaleFactor = kDefaultTrackpadScrollToScaleFactor, + this.supportedDevices, + }) : assert(() { + final bool haveVerticalDrag = onVerticalDragStart != null || onVerticalDragUpdate != null || onVerticalDragEnd != null; + final bool haveHorizontalDrag = onHorizontalDragStart != null || onHorizontalDragUpdate != null || onHorizontalDragEnd != null; + final bool havePan = onPanStart != null || onPanUpdate != null || onPanEnd != null; + final bool haveScale = onScaleStart != null || onScaleUpdate != null || onScaleEnd != null; + if (havePan || haveScale) { + if (havePan && haveScale) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Incorrect GestureDetector arguments.'), + ErrorDescription( + 'Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan.', + ), + ErrorHint('Just use the scale gesture recognizer.'), + ]); + } + final String recognizer = havePan ? 'pan' : 'scale'; + if (haveVerticalDrag && haveHorizontalDrag) { + throw FlutterError( + 'Incorrect GestureDetector arguments.\n' + 'Simultaneously having a vertical drag gesture recognizer, a horizontal drag gesture recognizer, and a $recognizer gesture recognizer ' + 'will result in the $recognizer gesture recognizer being ignored, since the other two will catch all drags.', + ); + } + } + return true; + }()); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// A pointer that might cause a tap with a primary button has contacted the + /// screen at a particular location. + /// + /// This is called after a short timeout, even if the winning gesture has not + /// yet been selected. If the tap gesture wins, [onTapUp] will be called, + /// otherwise [onTapCancel] will be called. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureTapDownCallback? onTapDown; + + /// A pointer that will trigger a tap with a primary button has stopped + /// contacting the screen at a particular location. + /// + /// This triggers immediately before [onTap] in the case of the tap gesture + /// winning. If the tap gesture did not win, [onTapCancel] is called instead. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureTapUpCallback? onTapUp; + + /// A tap with a primary button has occurred. + /// + /// This triggers when the tap gesture wins. If the tap gesture did not win, + /// [onTapCancel] is called instead. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [onTapUp], which is called at the same time but includes details + /// regarding the pointer position. + final GestureTapCallback? onTap; + + /// The pointer that previously triggered [onTapDown] will not end up causing + /// a tap. + /// + /// This is called after [onTapDown], and instead of [onTapUp] and [onTap], if + /// the tap gesture did not win. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureTapCancelCallback? onTapCancel; + + /// A tap with a secondary button has occurred. + /// + /// This triggers when the tap gesture wins. If the tap gesture did not win, + /// [onSecondaryTapCancel] is called instead. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [onSecondaryTapUp], which is called at the same time but includes details + /// regarding the pointer position. + final GestureTapCallback? onSecondaryTap; + + /// A pointer that might cause a tap with a secondary button has contacted the + /// screen at a particular location. + /// + /// This is called after a short timeout, even if the winning gesture has not + /// yet been selected. If the tap gesture wins, [onSecondaryTapUp] will be + /// called, otherwise [onSecondaryTapCancel] will be called. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + final GestureTapDownCallback? onSecondaryTapDown; + + /// A pointer that will trigger a tap with a secondary button has stopped + /// contacting the screen at a particular location. + /// + /// This triggers in the case of the tap gesture winning. If the tap gesture + /// did not win, [onSecondaryTapCancel] is called instead. + /// + /// See also: + /// + /// * [onSecondaryTap], a handler triggered right after this one that doesn't + /// pass any details about the tap. + /// * [kSecondaryButton], the button this callback responds to. + final GestureTapUpCallback? onSecondaryTapUp; + + /// The pointer that previously triggered [onSecondaryTapDown] will not end up + /// causing a tap. + /// + /// This is called after [onSecondaryTapDown], and instead of + /// [onSecondaryTapUp], if the tap gesture did not win. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + final GestureTapCancelCallback? onSecondaryTapCancel; + + /// A pointer that might cause a tap with a tertiary button has contacted the + /// screen at a particular location. + /// + /// This is called after a short timeout, even if the winning gesture has not + /// yet been selected. If the tap gesture wins, [onTertiaryTapUp] will be + /// called, otherwise [onTertiaryTapCancel] will be called. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + final GestureTapDownCallback? onTertiaryTapDown; + + /// A pointer that will trigger a tap with a tertiary button has stopped + /// contacting the screen at a particular location. + /// + /// This triggers in the case of the tap gesture winning. If the tap gesture + /// did not win, [onTertiaryTapCancel] is called instead. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + final GestureTapUpCallback? onTertiaryTapUp; + + /// The pointer that previously triggered [onTertiaryTapDown] will not end up + /// causing a tap. + /// + /// This is called after [onTertiaryTapDown], and instead of + /// [onTertiaryTapUp], if the tap gesture did not win. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + final GestureTapCancelCallback? onTertiaryTapCancel; + + /// A pointer that might cause a double tap has contacted the screen at a + /// particular location. + /// + /// Triggered immediately after the down event of the second tap. + /// + /// If the user completes the double tap and the gesture wins, [onDoubleTap] + /// will be called after this callback. Otherwise, [onDoubleTapCancel] will + /// be called after this callback. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureTapDownCallback? onDoubleTapDown; + + /// The user has tapped the screen with a primary button at the same location + /// twice in quick succession. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureTapCallback? onDoubleTap; + + /// The pointer that previously triggered [onDoubleTapDown] will not end up + /// causing a double tap. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureTapCancelCallback? onDoubleTapCancel; + + /// The pointer has contacted the screen with a primary button, which might + /// be the start of a long-press. + /// + /// This triggers after the pointer down event. + /// + /// If the user completes the long-press, and this gesture wins, + /// [onLongPressStart] will be called after this callback. Otherwise, + /// [onLongPressCancel] will be called after this callback. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [onSecondaryLongPressDown], a similar callback but for a secondary button. + /// * [onTertiaryLongPressDown], a similar callback but for a tertiary button. + /// * [LongPressGestureRecognizer.onLongPressDown], which exposes this + /// callback at the gesture layer. + final GestureLongPressDownCallback? onLongPressDown; + + /// A pointer that previously triggered [onLongPressDown] will not end up + /// causing a long-press. + /// + /// This triggers once the gesture loses if [onLongPressDown] has previously + /// been triggered. + /// + /// If the user completed the long-press, and the gesture won, then + /// [onLongPressStart] and [onLongPress] are called instead. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onLongPressCancel], which exposes this + /// callback at the gesture layer. + final GestureLongPressCancelCallback? onLongPressCancel; + + /// Called when a long press gesture with a primary button has been recognized. + /// + /// Triggered when a pointer has remained in contact with the screen at the + /// same location for a long period of time. + /// + /// This is equivalent to (and is called immediately after) [onLongPressStart]. + /// The only difference between the two is that this callback does not + /// contain details of the position at which the pointer initially contacted + /// the screen. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onLongPress], which exposes this + /// callback at the gesture layer. + final GestureLongPressCallback? onLongPress; + + /// Called when a long press gesture with a primary button has been recognized. + /// + /// Triggered when a pointer has remained in contact with the screen at the + /// same location for a long period of time. + /// + /// This is equivalent to (and is called immediately before) [onLongPress]. + /// The only difference between the two is that this callback contains + /// details of the position at which the pointer initially contacted the + /// screen, whereas [onLongPress] does not. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onLongPressStart], which exposes this + /// callback at the gesture layer. + final GestureLongPressStartCallback? onLongPressStart; + + /// A pointer has been drag-moved after a long-press with a primary button. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onLongPressMoveUpdate], which exposes this + /// callback at the gesture layer. + final GestureLongPressMoveUpdateCallback? onLongPressMoveUpdate; + + /// A pointer that has triggered a long-press with a primary button has + /// stopped contacting the screen. + /// + /// This is equivalent to (and is called immediately after) [onLongPressEnd]. + /// The only difference between the two is that this callback does not + /// contain details of the state of the pointer when it stopped contacting + /// the screen. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onLongPressUp], which exposes this + /// callback at the gesture layer. + final GestureLongPressUpCallback? onLongPressUp; + + /// A pointer that has triggered a long-press with a primary button has + /// stopped contacting the screen. + /// + /// This is equivalent to (and is called immediately before) [onLongPressUp]. + /// The only difference between the two is that this callback contains + /// details of the state of the pointer when it stopped contacting the + /// screen, whereas [onLongPressUp] does not. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onLongPressEnd], which exposes this + /// callback at the gesture layer. + final GestureLongPressEndCallback? onLongPressEnd; + + /// The pointer has contacted the screen with a secondary button, which might + /// be the start of a long-press. + /// + /// This triggers after the pointer down event. + /// + /// If the user completes the long-press, and this gesture wins, + /// [onSecondaryLongPressStart] will be called after this callback. Otherwise, + /// [onSecondaryLongPressCancel] will be called after this callback. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [onLongPressDown], a similar callback but for a secondary button. + /// * [onTertiaryLongPressDown], a similar callback but for a tertiary button. + /// * [LongPressGestureRecognizer.onSecondaryLongPressDown], which exposes + /// this callback at the gesture layer. + final GestureLongPressDownCallback? onSecondaryLongPressDown; + + /// A pointer that previously triggered [onSecondaryLongPressDown] will not + /// end up causing a long-press. + /// + /// This triggers once the gesture loses if [onSecondaryLongPressDown] has + /// previously been triggered. + /// + /// If the user completed the long-press, and the gesture won, then + /// [onSecondaryLongPressStart] and [onSecondaryLongPress] are called instead. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onSecondaryLongPressCancel], which exposes + /// this callback at the gesture layer. + final GestureLongPressCancelCallback? onSecondaryLongPressCancel; + + /// Called when a long press gesture with a secondary button has been + /// recognized. + /// + /// Triggered when a pointer has remained in contact with the screen at the + /// same location for a long period of time. + /// + /// This is equivalent to (and is called immediately after) + /// [onSecondaryLongPressStart]. The only difference between the two is that + /// this callback does not contain details of the position at which the + /// pointer initially contacted the screen. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onSecondaryLongPress], which exposes + /// this callback at the gesture layer. + final GestureLongPressCallback? onSecondaryLongPress; + + /// Called when a long press gesture with a secondary button has been + /// recognized. + /// + /// Triggered when a pointer has remained in contact with the screen at the + /// same location for a long period of time. + /// + /// This is equivalent to (and is called immediately before) + /// [onSecondaryLongPress]. The only difference between the two is that this + /// callback contains details of the position at which the pointer initially + /// contacted the screen, whereas [onSecondaryLongPress] does not. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onSecondaryLongPressStart], which exposes + /// this callback at the gesture layer. + final GestureLongPressStartCallback? onSecondaryLongPressStart; + + /// A pointer has been drag-moved after a long press with a secondary button. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onSecondaryLongPressMoveUpdate], which exposes + /// this callback at the gesture layer. + final GestureLongPressMoveUpdateCallback? onSecondaryLongPressMoveUpdate; + + /// A pointer that has triggered a long-press with a secondary button has + /// stopped contacting the screen. + /// + /// This is equivalent to (and is called immediately after) + /// [onSecondaryLongPressEnd]. The only difference between the two is that + /// this callback does not contain details of the state of the pointer when + /// it stopped contacting the screen. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onSecondaryLongPressUp], which exposes + /// this callback at the gesture layer. + final GestureLongPressUpCallback? onSecondaryLongPressUp; + + /// A pointer that has triggered a long-press with a secondary button has + /// stopped contacting the screen. + /// + /// This is equivalent to (and is called immediately before) + /// [onSecondaryLongPressUp]. The only difference between the two is that + /// this callback contains details of the state of the pointer when it + /// stopped contacting the screen, whereas [onSecondaryLongPressUp] does not. + /// + /// See also: + /// + /// * [kSecondaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onSecondaryLongPressEnd], which exposes + /// this callback at the gesture layer. + final GestureLongPressEndCallback? onSecondaryLongPressEnd; + + /// The pointer has contacted the screen with a tertiary button, which might + /// be the start of a long-press. + /// + /// This triggers after the pointer down event. + /// + /// If the user completes the long-press, and this gesture wins, + /// [onTertiaryLongPressStart] will be called after this callback. Otherwise, + /// [onTertiaryLongPressCancel] will be called after this callback. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [onLongPressDown], a similar callback but for a primary button. + /// * [onSecondaryLongPressDown], a similar callback but for a secondary button. + /// * [LongPressGestureRecognizer.onTertiaryLongPressDown], which exposes + /// this callback at the gesture layer. + final GestureLongPressDownCallback? onTertiaryLongPressDown; + + /// A pointer that previously triggered [onTertiaryLongPressDown] will not + /// end up causing a long-press. + /// + /// This triggers once the gesture loses if [onTertiaryLongPressDown] has + /// previously been triggered. + /// + /// If the user completed the long-press, and the gesture won, then + /// [onTertiaryLongPressStart] and [onTertiaryLongPress] are called instead. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onTertiaryLongPressCancel], which exposes + /// this callback at the gesture layer. + final GestureLongPressCancelCallback? onTertiaryLongPressCancel; + + /// Called when a long press gesture with a tertiary button has been + /// recognized. + /// + /// Triggered when a pointer has remained in contact with the screen at the + /// same location for a long period of time. + /// + /// This is equivalent to (and is called immediately after) + /// [onTertiaryLongPressStart]. The only difference between the two is that + /// this callback does not contain details of the position at which the + /// pointer initially contacted the screen. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onTertiaryLongPress], which exposes + /// this callback at the gesture layer. + final GestureLongPressCallback? onTertiaryLongPress; + + /// Called when a long press gesture with a tertiary button has been + /// recognized. + /// + /// Triggered when a pointer has remained in contact with the screen at the + /// same location for a long period of time. + /// + /// This is equivalent to (and is called immediately before) + /// [onTertiaryLongPress]. The only difference between the two is that this + /// callback contains details of the position at which the pointer initially + /// contacted the screen, whereas [onTertiaryLongPress] does not. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onTertiaryLongPressStart], which exposes + /// this callback at the gesture layer. + final GestureLongPressStartCallback? onTertiaryLongPressStart; + + /// A pointer has been drag-moved after a long press with a tertiary button. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onTertiaryLongPressMoveUpdate], which exposes + /// this callback at the gesture layer. + final GestureLongPressMoveUpdateCallback? onTertiaryLongPressMoveUpdate; + + /// A pointer that has triggered a long-press with a tertiary button has + /// stopped contacting the screen. + /// + /// This is equivalent to (and is called immediately after) + /// [onTertiaryLongPressEnd]. The only difference between the two is that + /// this callback does not contain details of the state of the pointer when + /// it stopped contacting the screen. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onTertiaryLongPressUp], which exposes + /// this callback at the gesture layer. + final GestureLongPressUpCallback? onTertiaryLongPressUp; + + /// A pointer that has triggered a long-press with a tertiary button has + /// stopped contacting the screen. + /// + /// This is equivalent to (and is called immediately before) + /// [onTertiaryLongPressUp]. The only difference between the two is that + /// this callback contains details of the state of the pointer when it + /// stopped contacting the screen, whereas [onTertiaryLongPressUp] does not. + /// + /// See also: + /// + /// * [kTertiaryButton], the button this callback responds to. + /// * [LongPressGestureRecognizer.onTertiaryLongPressEnd], which exposes + /// this callback at the gesture layer. + final GestureLongPressEndCallback? onTertiaryLongPressEnd; + + /// A pointer has contacted the screen with a primary button and might begin + /// to move vertically. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragDownCallback? onVerticalDragDown; + + /// A pointer has contacted the screen with a primary button and has begun to + /// move vertically. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragStartCallback? onVerticalDragStart; + + /// A pointer that is in contact with the screen with a primary button and + /// moving vertically has moved in the vertical direction. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragUpdateCallback? onVerticalDragUpdate; + + /// A pointer that was previously in contact with the screen with a primary + /// button and moving vertically is no longer in contact with the screen and + /// was moving at a specific velocity when it stopped contacting the screen. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragEndCallback? onVerticalDragEnd; + + /// The pointer that previously triggered [onVerticalDragDown] did not + /// complete. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragCancelCallback? onVerticalDragCancel; + + /// A pointer has contacted the screen with a primary button and might begin + /// to move horizontally. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragDownCallback? onHorizontalDragDown; + + /// A pointer has contacted the screen with a primary button and has begun to + /// move horizontally. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragStartCallback? onHorizontalDragStart; + + /// A pointer that is in contact with the screen with a primary button and + /// moving horizontally has moved in the horizontal direction. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragUpdateCallback? onHorizontalDragUpdate; + + /// A pointer that was previously in contact with the screen with a primary + /// button and moving horizontally is no longer in contact with the screen and + /// was moving at a specific velocity when it stopped contacting the screen. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragEndCallback? onHorizontalDragEnd; + + /// The pointer that previously triggered [onHorizontalDragDown] did not + /// complete. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragCancelCallback? onHorizontalDragCancel; + + /// A pointer has contacted the screen with a primary button and might begin + /// to move. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragDownCallback? onPanDown; + + /// A pointer has contacted the screen with a primary button and has begun to + /// move. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragStartCallback? onPanStart; + + /// A pointer that is in contact with the screen with a primary button and + /// moving has moved again. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragUpdateCallback? onPanUpdate; + + /// A pointer that was previously in contact with the screen with a primary + /// button and moving is no longer in contact with the screen and was moving + /// at a specific velocity when it stopped contacting the screen. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragEndCallback? onPanEnd; + + /// The pointer that previously triggered [onPanDown] did not complete. + /// + /// See also: + /// + /// * [kPrimaryButton], the button this callback responds to. + final GestureDragCancelCallback? onPanCancel; + + /// The pointers in contact with the screen have established a focal point and + /// initial scale of 1.0. + final GestureScaleStartCallback? onScaleStart; + + /// The pointers in contact with the screen have indicated a new focal point + /// and/or scale. + final GestureScaleUpdateCallback? onScaleUpdate; + + /// The pointers are no longer in contact with the screen. + final GestureScaleEndCallback? onScaleEnd; + + /// The pointer is in contact with the screen and has pressed with sufficient + /// force to initiate a force press. The amount of force is at least + /// [ForcePressGestureRecognizer.startPressure]. + /// + /// This callback will only be fired on devices with pressure + /// detecting screens. + final GestureForcePressStartCallback? onForcePressStart; + + /// The pointer is in contact with the screen and has pressed with the maximum + /// force. The amount of force is at least + /// [ForcePressGestureRecognizer.peakPressure]. + /// + /// This callback will only be fired on devices with pressure + /// detecting screens. + final GestureForcePressPeakCallback? onForcePressPeak; + + /// A pointer is in contact with the screen, has previously passed the + /// [ForcePressGestureRecognizer.startPressure] and is either moving on the + /// plane of the screen, pressing the screen with varying forces or both + /// simultaneously. + /// + /// This callback will only be fired on devices with pressure + /// detecting screens. + final GestureForcePressUpdateCallback? onForcePressUpdate; + + /// The pointer tracked by [onForcePressStart] is no longer in contact with the screen. + /// + /// This callback will only be fired on devices with pressure + /// detecting screens. + final GestureForcePressEndCallback? onForcePressEnd; + + /// How this gesture detector should behave during hit testing when deciding + /// how the hit test propagates to children and whether to consider targets + /// behind this one. + /// + /// This defaults to [HitTestBehavior.deferToChild] if [child] is not null and + /// [HitTestBehavior.translucent] if child is null. + /// + /// See [HitTestBehavior] for the allowed values and their meanings. + final HitTestBehavior? behavior; + + /// Whether to exclude these gestures from the semantics tree. For + /// example, the long-press gesture for showing a tooltip is + /// excluded because the tooltip itself is included in the semantics + /// tree directly and so having a gesture to show it would result in + /// duplication of information. + final bool excludeFromSemantics; + + /// Determines the way that drag start behavior is handled. + /// + /// If set to [DragStartBehavior.start], gesture drag behavior will + /// begin at the position where the drag gesture won the arena. If set to + /// [DragStartBehavior.down] it will begin at the position where a down event + /// is first detected. + /// + /// In general, setting this to [DragStartBehavior.start] will make drag + /// animation smoother and setting it to [DragStartBehavior.down] will make + /// drag behavior feel slightly more reactive. + /// + /// By default, the drag start behavior is [DragStartBehavior.start]. + /// + /// Only the [DragGestureRecognizer.onStart] callbacks for the + /// [VerticalDragGestureRecognizer], [HorizontalDragGestureRecognizer] and + /// [PanGestureRecognizer] are affected by this setting. + /// + /// See also: + /// + /// * [DragGestureRecognizer.dragStartBehavior], which gives an example for the different behaviors. + final DragStartBehavior dragStartBehavior; + + /// The kind of devices that are allowed to be recognized. + /// + /// If set to null, events from all device types will be recognized. Defaults to null. + final Set<PointerDeviceKind>? supportedDevices; + + /// {@macro flutter.gestures.scale.trackpadScrollCausesScale} + final bool trackpadScrollCausesScale; + + /// {@macro flutter.gestures.scale.trackpadScrollToScaleFactor} + final Offset trackpadScrollToScaleFactor; + + @override + Widget build(BuildContext context) { + final Map<Type, GestureRecognizerFactory> gestures = <Type, GestureRecognizerFactory>{}; + final DeviceGestureSettings? gestureSettings = MediaQuery.maybeGestureSettingsOf(context); + + if (onTapDown != null || + onTapUp != null || + onTap != null || + onTapCancel != null || + onSecondaryTap != null || + onSecondaryTapDown != null || + onSecondaryTapUp != null || + onSecondaryTapCancel != null|| + onTertiaryTapDown != null || + onTertiaryTapUp != null || + onTertiaryTapCancel != null + ) { + gestures[TapGestureRecognizer] = GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>( + () => TapGestureRecognizer(debugOwner: this, supportedDevices: supportedDevices), + (TapGestureRecognizer instance) { + instance + ..onTapDown = onTapDown + ..onTapUp = onTapUp + ..onTap = onTap + ..onTapCancel = onTapCancel + ..onSecondaryTap = onSecondaryTap + ..onSecondaryTapDown = onSecondaryTapDown + ..onSecondaryTapUp = onSecondaryTapUp + ..onSecondaryTapCancel = onSecondaryTapCancel + ..onTertiaryTapDown = onTertiaryTapDown + ..onTertiaryTapUp = onTertiaryTapUp + ..onTertiaryTapCancel = onTertiaryTapCancel + ..gestureSettings = gestureSettings + ..supportedDevices = supportedDevices; + }, + ); + } + + if (onDoubleTap != null || + onDoubleTapDown != null || + onDoubleTapCancel != null) { + gestures[DoubleTapGestureRecognizer] = GestureRecognizerFactoryWithHandlers<DoubleTapGestureRecognizer>( + () => DoubleTapGestureRecognizer(debugOwner: this, supportedDevices: supportedDevices), + (DoubleTapGestureRecognizer instance) { + instance + ..onDoubleTapDown = onDoubleTapDown + ..onDoubleTap = onDoubleTap + ..onDoubleTapCancel = onDoubleTapCancel + ..gestureSettings = gestureSettings + ..supportedDevices = supportedDevices; + }, + ); + } + + if (onLongPressDown != null || + onLongPressCancel != null || + onLongPress != null || + onLongPressStart != null || + onLongPressMoveUpdate != null || + onLongPressUp != null || + onLongPressEnd != null || + onSecondaryLongPressDown != null || + onSecondaryLongPressCancel != null || + onSecondaryLongPress != null || + onSecondaryLongPressStart != null || + onSecondaryLongPressMoveUpdate != null || + onSecondaryLongPressUp != null || + onSecondaryLongPressEnd != null || + onTertiaryLongPressDown != null || + onTertiaryLongPressCancel != null || + onTertiaryLongPress != null || + onTertiaryLongPressStart != null || + onTertiaryLongPressMoveUpdate != null || + onTertiaryLongPressUp != null || + onTertiaryLongPressEnd != null) { + gestures[LongPressGestureRecognizer] = GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>( + () => LongPressGestureRecognizer(debugOwner: this, supportedDevices: supportedDevices), + (LongPressGestureRecognizer instance) { + instance + ..onLongPressDown = onLongPressDown + ..onLongPressCancel = onLongPressCancel + ..onLongPress = onLongPress + ..onLongPressStart = onLongPressStart + ..onLongPressMoveUpdate = onLongPressMoveUpdate + ..onLongPressUp = onLongPressUp + ..onLongPressEnd = onLongPressEnd + ..onSecondaryLongPressDown = onSecondaryLongPressDown + ..onSecondaryLongPressCancel = onSecondaryLongPressCancel + ..onSecondaryLongPress = onSecondaryLongPress + ..onSecondaryLongPressStart = onSecondaryLongPressStart + ..onSecondaryLongPressMoveUpdate = onSecondaryLongPressMoveUpdate + ..onSecondaryLongPressUp = onSecondaryLongPressUp + ..onSecondaryLongPressEnd = onSecondaryLongPressEnd + ..onTertiaryLongPressDown = onTertiaryLongPressDown + ..onTertiaryLongPressCancel = onTertiaryLongPressCancel + ..onTertiaryLongPress = onTertiaryLongPress + ..onTertiaryLongPressStart = onTertiaryLongPressStart + ..onTertiaryLongPressMoveUpdate = onTertiaryLongPressMoveUpdate + ..onTertiaryLongPressUp = onTertiaryLongPressUp + ..onTertiaryLongPressEnd = onTertiaryLongPressEnd + ..gestureSettings = gestureSettings + ..supportedDevices = supportedDevices; + }, + ); + } + + if (onVerticalDragDown != null || + onVerticalDragStart != null || + onVerticalDragUpdate != null || + onVerticalDragEnd != null || + onVerticalDragCancel != null) { + gestures[VerticalDragGestureRecognizer] = GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>( + () => VerticalDragGestureRecognizer(debugOwner: this, supportedDevices: supportedDevices), + (VerticalDragGestureRecognizer instance) { + instance + ..onDown = onVerticalDragDown + ..onStart = onVerticalDragStart + ..onUpdate = onVerticalDragUpdate + ..onEnd = onVerticalDragEnd + ..onCancel = onVerticalDragCancel + ..dragStartBehavior = dragStartBehavior + ..gestureSettings = gestureSettings + ..supportedDevices = supportedDevices; + }, + ); + } + + if (onHorizontalDragDown != null || + onHorizontalDragStart != null || + onHorizontalDragUpdate != null || + onHorizontalDragEnd != null || + onHorizontalDragCancel != null) { + gestures[HorizontalDragGestureRecognizer] = GestureRecognizerFactoryWithHandlers<HorizontalDragGestureRecognizer>( + () => HorizontalDragGestureRecognizer(debugOwner: this, supportedDevices: supportedDevices), + (HorizontalDragGestureRecognizer instance) { + instance + ..onDown = onHorizontalDragDown + ..onStart = onHorizontalDragStart + ..onUpdate = onHorizontalDragUpdate + ..onEnd = onHorizontalDragEnd + ..onCancel = onHorizontalDragCancel + ..dragStartBehavior = dragStartBehavior + ..gestureSettings = gestureSettings + ..supportedDevices = supportedDevices; + }, + ); + } + + if (onPanDown != null || + onPanStart != null || + onPanUpdate != null || + onPanEnd != null || + onPanCancel != null) { + gestures[PanGestureRecognizer] = GestureRecognizerFactoryWithHandlers<PanGestureRecognizer>( + () => PanGestureRecognizer(debugOwner: this, supportedDevices: supportedDevices), + (PanGestureRecognizer instance) { + instance + ..onDown = onPanDown + ..onStart = onPanStart + ..onUpdate = onPanUpdate + ..onEnd = onPanEnd + ..onCancel = onPanCancel + ..dragStartBehavior = dragStartBehavior + ..gestureSettings = gestureSettings + ..supportedDevices = supportedDevices; + }, + ); + } + + if (onScaleStart != null || onScaleUpdate != null || onScaleEnd != null) { + gestures[ScaleGestureRecognizer] = GestureRecognizerFactoryWithHandlers<ScaleGestureRecognizer>( + () => ScaleGestureRecognizer(debugOwner: this, supportedDevices: supportedDevices), + (ScaleGestureRecognizer instance) { + instance + ..onStart = onScaleStart + ..onUpdate = onScaleUpdate + ..onEnd = onScaleEnd + ..dragStartBehavior = dragStartBehavior + ..gestureSettings = gestureSettings + ..trackpadScrollCausesScale = trackpadScrollCausesScale + ..trackpadScrollToScaleFactor = trackpadScrollToScaleFactor + ..supportedDevices = supportedDevices; + }, + ); + } + + if (onForcePressStart != null || + onForcePressPeak != null || + onForcePressUpdate != null || + onForcePressEnd != null) { + gestures[ForcePressGestureRecognizer] = GestureRecognizerFactoryWithHandlers<ForcePressGestureRecognizer>( + () => ForcePressGestureRecognizer(debugOwner: this, supportedDevices: supportedDevices), + (ForcePressGestureRecognizer instance) { + instance + ..onStart = onForcePressStart + ..onPeak = onForcePressPeak + ..onUpdate = onForcePressUpdate + ..onEnd = onForcePressEnd + ..gestureSettings = gestureSettings + ..supportedDevices = supportedDevices; + }, + ); + } + + return RawGestureDetector( + gestures: gestures, + behavior: behavior, + excludeFromSemantics: excludeFromSemantics, + child: child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<DragStartBehavior>('startBehavior', dragStartBehavior)); + } +} + +/// A widget that detects gestures described by the given gesture +/// factories. +/// +/// For common gestures, use a [GestureDetector]. +/// [RawGestureDetector] is useful primarily when developing your +/// own gesture recognizers. +/// +/// Configuring the gesture recognizers requires a carefully constructed map, as +/// described in [gestures] and as shown in the example below. +/// +/// {@tool snippet} +/// +/// This example shows how to hook up a [TapGestureRecognizer]. It assumes that +/// the code is being used inside a [State] object with a `_last` field that is +/// then displayed as the child of the gesture detector. +/// +/// ```dart +/// RawGestureDetector( +/// gestures: <Type, GestureRecognizerFactory>{ +/// TapGestureRecognizer: GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>( +/// () => TapGestureRecognizer(), +/// (TapGestureRecognizer instance) { +/// instance +/// ..onTapDown = (TapDownDetails details) { setState(() { _last = 'down'; }); } +/// ..onTapUp = (TapUpDetails details) { setState(() { _last = 'up'; }); } +/// ..onTap = () { setState(() { _last = 'tap'; }); } +/// ..onTapCancel = () { setState(() { _last = 'cancel'; }); }; +/// }, +/// ), +/// }, +/// child: Container(width: 300.0, height: 300.0, color: Colors.yellow, child: Text(_last)), +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [GestureDetector], a less flexible but much simpler widget that does the same thing. +/// * [Listener], a widget that reports raw pointer events. +/// * [GestureRecognizer], the class that you extend to create a custom gesture recognizer. +class RawGestureDetector extends StatefulWidget { + /// Creates a widget that detects gestures. + /// + /// Gesture detectors can contribute semantic information to the tree that is + /// used by assistive technology. The behavior can be configured by + /// [semantics], or disabled with [excludeFromSemantics]. + const RawGestureDetector({ + super.key, + this.child, + this.gestures = const <Type, GestureRecognizerFactory>{}, + this.behavior, + this.excludeFromSemantics = false, + this.semantics, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The gestures that this widget will attempt to recognize. + /// + /// This should be a map from [GestureRecognizer] subclasses to + /// [GestureRecognizerFactory] subclasses specialized with the same type. + /// + /// This value can be late-bound at layout time using + /// [RawGestureDetectorState.replaceGestureRecognizers]. + final Map<Type, GestureRecognizerFactory> gestures; + + /// How this gesture detector should behave during hit testing. + /// + /// This defaults to [HitTestBehavior.deferToChild] if [child] is not null and + /// [HitTestBehavior.translucent] if child is null. + final HitTestBehavior? behavior; + + /// Whether to exclude these gestures from the semantics tree. For + /// example, the long-press gesture for showing a tooltip is + /// excluded because the tooltip itself is included in the semantics + /// tree directly and so having a gesture to show it would result in + /// duplication of information. + final bool excludeFromSemantics; + + /// Describes the semantics notations that should be added to the underlying + /// render object [RenderSemanticsGestureHandler]. + /// + /// It has no effect if [excludeFromSemantics] is true. + /// + /// When [semantics] is null, [RawGestureDetector] will fall back to a + /// default delegate which checks if the detector owns certain gesture + /// recognizers and calls their callbacks if they exist: + /// + /// * During a semantic tap, it calls [TapGestureRecognizer]'s + /// `onTapDown`, `onTapUp`, and `onTap`. + /// * During a semantic long press, it calls [LongPressGestureRecognizer]'s + /// `onLongPressDown`, `onLongPressStart`, `onLongPress`, `onLongPressEnd` + /// and `onLongPressUp`. + /// * During a semantic horizontal drag, it calls [HorizontalDragGestureRecognizer]'s + /// `onDown`, `onStart`, `onUpdate` and `onEnd`, then + /// [PanGestureRecognizer]'s `onDown`, `onStart`, `onUpdate` and `onEnd`. + /// * During a semantic vertical drag, it calls [VerticalDragGestureRecognizer]'s + /// `onDown`, `onStart`, `onUpdate` and `onEnd`, then + /// [PanGestureRecognizer]'s `onDown`, `onStart`, `onUpdate` and `onEnd`. + /// + /// {@tool snippet} + /// This custom gesture detector listens to force presses, while also allows + /// the same callback to be triggered by semantic long presses. + /// + /// ```dart + /// class ForcePressGestureDetectorWithSemantics extends StatelessWidget { + /// const ForcePressGestureDetectorWithSemantics({ + /// super.key, + /// required this.child, + /// required this.onForcePress, + /// }); + /// + /// final Widget child; + /// final VoidCallback onForcePress; + /// + /// @override + /// Widget build(BuildContext context) { + /// return RawGestureDetector( + /// gestures: <Type, GestureRecognizerFactory>{ + /// ForcePressGestureRecognizer: GestureRecognizerFactoryWithHandlers<ForcePressGestureRecognizer>( + /// () => ForcePressGestureRecognizer(debugOwner: this), + /// (ForcePressGestureRecognizer instance) { + /// instance.onStart = (_) => onForcePress(); + /// } + /// ), + /// }, + /// behavior: HitTestBehavior.opaque, + /// semantics: _LongPressSemanticsDelegate(onForcePress), + /// child: child, + /// ); + /// } + /// } + /// + /// class _LongPressSemanticsDelegate extends SemanticsGestureDelegate { + /// _LongPressSemanticsDelegate(this.onLongPress); + /// + /// VoidCallback onLongPress; + /// + /// @override + /// void assignSemantics(RenderSemanticsGestureHandler renderObject) { + /// renderObject.onLongPress = onLongPress; + /// } + /// } + /// ``` + /// {@end-tool} + final SemanticsGestureDelegate? semantics; + + @override + RawGestureDetectorState createState() => RawGestureDetectorState(); +} + +/// State for a [RawGestureDetector]. +class RawGestureDetectorState extends State<RawGestureDetector> { + Map<Type, GestureRecognizer>? _recognizers = const <Type, GestureRecognizer>{}; + SemanticsGestureDelegate? _semantics; + + @override + void initState() { + super.initState(); + _semantics = widget.semantics ?? _DefaultSemanticsGestureDelegate(this); + _syncAll(widget.gestures); + } + + @override + void didUpdateWidget(RawGestureDetector oldWidget) { + super.didUpdateWidget(oldWidget); + if (!(oldWidget.semantics == null && widget.semantics == null)) { + _semantics = widget.semantics ?? _DefaultSemanticsGestureDelegate(this); + } + _syncAll(widget.gestures); + } + + /// This method can be called after the build phase, during the + /// layout of the nearest descendant [RenderObjectWidget] of the + /// gesture detector, to update the list of active gesture + /// recognizers. + /// + /// The typical use case is [Scrollable]s, which put their viewport + /// in their gesture detector, and then need to know the dimensions + /// of the viewport and the viewport's child to determine whether + /// the gesture detector should be enabled. + /// + /// The argument should follow the same conventions as + /// [RawGestureDetector.gestures]. It acts like a temporary replacement for + /// that value until the next build. + void replaceGestureRecognizers(Map<Type, GestureRecognizerFactory> gestures) { + assert(() { + if (!context.findRenderObject()!.owner!.debugDoingLayout) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Unexpected call to replaceGestureRecognizers() method of RawGestureDetectorState.'), + ErrorDescription('The replaceGestureRecognizers() method can only be called during the layout phase.'), + ErrorHint( + 'To set the gesture recognizers at other times, trigger a new build using setState() ' + 'and provide the new gesture recognizers as constructor arguments to the corresponding ' + 'RawGestureDetector or GestureDetector object.', + ), + ]); + } + return true; + }()); + _syncAll(gestures); + if (!widget.excludeFromSemantics) { + final RenderSemanticsGestureHandler semanticsGestureHandler = context.findRenderObject()! as RenderSemanticsGestureHandler; + _updateSemanticsForRenderObject(semanticsGestureHandler); + } + } + + /// This method can be called to filter the list of available semantic actions, + /// after the render object was created. + /// + /// The actual filtering is happening in the next frame and a frame will be + /// scheduled if non is pending. + /// + /// This is used by [Scrollable] to configure system accessibility tools so + /// that they know in which direction a particular list can be scrolled. + /// + /// If this is never called, then the actions are not filtered. If the list of + /// actions to filter changes, it must be called again. + void replaceSemanticsActions(Set<SemanticsAction> actions) { + if (widget.excludeFromSemantics) { + return; + } + + final RenderSemanticsGestureHandler? semanticsGestureHandler = context.findRenderObject() as RenderSemanticsGestureHandler?; + assert(() { + if (semanticsGestureHandler == null) { + throw FlutterError( + 'Unexpected call to replaceSemanticsActions() method of RawGestureDetectorState.\n' + 'The replaceSemanticsActions() method can only be called after the RenderSemanticsGestureHandler has been created.', + ); + } + return true; + }()); + + semanticsGestureHandler!.validActions = actions; // will call _markNeedsSemanticsUpdate(), if required. + } + + @override + void dispose() { + for (final GestureRecognizer recognizer in _recognizers!.values) { + recognizer.dispose(); + } + _recognizers = null; + super.dispose(); + } + + void _syncAll(Map<Type, GestureRecognizerFactory> gestures) { + assert(_recognizers != null); + final Map<Type, GestureRecognizer> oldRecognizers = _recognizers!; + _recognizers = <Type, GestureRecognizer>{}; + for (final Type type in gestures.keys) { + assert(gestures[type] != null); + assert(gestures[type]!._debugAssertTypeMatches(type)); + assert(!_recognizers!.containsKey(type)); + _recognizers![type] = oldRecognizers[type] ?? gestures[type]!.constructor(); + assert(_recognizers![type].runtimeType == type, 'GestureRecognizerFactory of type $type created a GestureRecognizer of type ${_recognizers![type].runtimeType}. The GestureRecognizerFactory must be specialized with the type of the class that it returns from its constructor method.'); + gestures[type]!.initializer(_recognizers![type]!); + } + for (final Type type in oldRecognizers.keys) { + if (!_recognizers!.containsKey(type)) { + oldRecognizers[type]!.dispose(); + } + } + } + + void _handlePointerDown(PointerDownEvent event) { + assert(_recognizers != null); + for (final GestureRecognizer recognizer in _recognizers!.values) { + recognizer.addPointer(event); + } + } + + void _handlePointerPanZoomStart(PointerPanZoomStartEvent event) { + assert(_recognizers != null); + for (final GestureRecognizer recognizer in _recognizers!.values) { + recognizer.addPointerPanZoom(event); + } + } + + HitTestBehavior get _defaultBehavior { + return widget.child == null ? HitTestBehavior.translucent : HitTestBehavior.deferToChild; + } + + void _updateSemanticsForRenderObject(RenderSemanticsGestureHandler renderObject) { + assert(!widget.excludeFromSemantics); + assert(_semantics != null); + _semantics!.assignSemantics(renderObject); + } + + @override + Widget build(BuildContext context) { + Widget result = Listener( + onPointerDown: _handlePointerDown, + onPointerPanZoomStart: _handlePointerPanZoomStart, + behavior: widget.behavior ?? _defaultBehavior, + child: widget.child, + ); + if (!widget.excludeFromSemantics) { + result = _GestureSemantics( + behavior: widget.behavior ?? _defaultBehavior, + assignSemantics: _updateSemanticsForRenderObject, + child: result, + ); + } + return result; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + if (_recognizers == null) { + properties.add(DiagnosticsNode.message('DISPOSED')); + } else { + final List<String> gestures = _recognizers!.values.map<String>((GestureRecognizer recognizer) => recognizer.debugDescription).toList(); + properties.add(IterableProperty<String>('gestures', gestures, ifEmpty: '<none>')); + properties.add(IterableProperty<GestureRecognizer>('recognizers', _recognizers!.values, level: DiagnosticLevel.fine)); + properties.add(DiagnosticsProperty<bool>('excludeFromSemantics', widget.excludeFromSemantics, defaultValue: false)); + if (!widget.excludeFromSemantics) { + properties.add(DiagnosticsProperty<SemanticsGestureDelegate>('semantics', widget.semantics, defaultValue: null)); + } + } + properties.add(EnumProperty<HitTestBehavior>('behavior', widget.behavior, defaultValue: null)); + } +} + +typedef _AssignSemantics = void Function(RenderSemanticsGestureHandler); + +class _GestureSemantics extends SingleChildRenderObjectWidget { + const _GestureSemantics({ + super.child, + required this.behavior, + required this.assignSemantics, + }); + + final HitTestBehavior behavior; + final _AssignSemantics assignSemantics; + + @override + RenderSemanticsGestureHandler createRenderObject(BuildContext context) { + final RenderSemanticsGestureHandler renderObject = RenderSemanticsGestureHandler() + ..behavior = behavior; + assignSemantics(renderObject); + return renderObject; + } + + @override + void updateRenderObject(BuildContext context, RenderSemanticsGestureHandler renderObject) { + renderObject.behavior = behavior; + assignSemantics(renderObject); + } +} + +/// A base class that describes what semantics notations a [RawGestureDetector] +/// should add to the render object [RenderSemanticsGestureHandler]. +/// +/// It is used to allow custom [GestureDetector]s to add semantics notations. +abstract class SemanticsGestureDelegate { + /// Create a delegate of gesture semantics. + const SemanticsGestureDelegate(); + + /// Assigns semantics notations to the [RenderSemanticsGestureHandler] render + /// object of the gesture detector. + /// + /// This method is called when the widget is created, updated, or during + /// [RawGestureDetectorState.replaceGestureRecognizers]. + void assignSemantics(RenderSemanticsGestureHandler renderObject); + + @override + String toString() => '${objectRuntimeType(this, 'SemanticsGestureDelegate')}()'; +} + +// The default semantics delegate of [RawGestureDetector]. Its behavior is +// described in [RawGestureDetector.semantics]. +// +// For readers who come here to learn how to write custom semantics delegates: +// this is not a proper sample code. It has access to the detector state as well +// as its private properties, which are inaccessible normally. It is designed +// this way in order to work independently in a [RawGestureRecognizer] to +// preserve existing behavior. +// +// Instead, a normal delegate will store callbacks as properties, and use them +// in `assignSemantics`. +class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate { + _DefaultSemanticsGestureDelegate(this.detectorState); + + final RawGestureDetectorState detectorState; + + @override + void assignSemantics(RenderSemanticsGestureHandler renderObject) { + assert(!detectorState.widget.excludeFromSemantics); + final Map<Type, GestureRecognizer> recognizers = detectorState._recognizers!; + renderObject + ..onTap = _getTapHandler(recognizers) + ..onLongPress = _getLongPressHandler(recognizers) + ..onHorizontalDragUpdate = _getHorizontalDragUpdateHandler(recognizers) + ..onVerticalDragUpdate = _getVerticalDragUpdateHandler(recognizers); + } + + GestureTapCallback? _getTapHandler(Map<Type, GestureRecognizer> recognizers) { + final TapGestureRecognizer? tap = recognizers[TapGestureRecognizer] as TapGestureRecognizer?; + if (tap == null) { + return null; + } + + return () { + tap.onTapDown?.call(TapDownDetails()); + tap.onTapUp?.call(TapUpDetails(kind: PointerDeviceKind.unknown)); + tap.onTap?.call(); + }; + } + + GestureLongPressCallback? _getLongPressHandler(Map<Type, GestureRecognizer> recognizers) { + final LongPressGestureRecognizer? longPress = recognizers[LongPressGestureRecognizer] as LongPressGestureRecognizer?; + if (longPress == null) { + return null; + } + + return () { + longPress.onLongPressDown?.call(const LongPressDownDetails()); + longPress.onLongPressStart?.call(const LongPressStartDetails()); + longPress.onLongPress?.call(); + longPress.onLongPressEnd?.call(const LongPressEndDetails()); + longPress.onLongPressUp?.call(); + }; + } + + GestureDragUpdateCallback? _getHorizontalDragUpdateHandler(Map<Type, GestureRecognizer> recognizers) { + final HorizontalDragGestureRecognizer? horizontal = recognizers[HorizontalDragGestureRecognizer] as HorizontalDragGestureRecognizer?; + final PanGestureRecognizer? pan = recognizers[PanGestureRecognizer] as PanGestureRecognizer?; + + final GestureDragUpdateCallback? horizontalHandler = horizontal == null ? + null : + (DragUpdateDetails details) { + horizontal.onDown?.call(DragDownDetails()); + horizontal.onStart?.call(DragStartDetails()); + horizontal.onUpdate?.call(details); + horizontal.onEnd?.call(DragEndDetails(primaryVelocity: 0.0)); + }; + + final GestureDragUpdateCallback? panHandler = pan == null ? + null : + (DragUpdateDetails details) { + pan.onDown?.call(DragDownDetails()); + pan.onStart?.call(DragStartDetails()); + pan.onUpdate?.call(details); + pan.onEnd?.call(DragEndDetails()); + }; + + if (horizontalHandler == null && panHandler == null) { + return null; + } + return (DragUpdateDetails details) { + if (horizontalHandler != null) { + horizontalHandler(details); + } + if (panHandler != null) { + panHandler(details); + } + }; + } + + GestureDragUpdateCallback? _getVerticalDragUpdateHandler(Map<Type, GestureRecognizer> recognizers) { + final VerticalDragGestureRecognizer? vertical = recognizers[VerticalDragGestureRecognizer] as VerticalDragGestureRecognizer?; + final PanGestureRecognizer? pan = recognizers[PanGestureRecognizer] as PanGestureRecognizer?; + + final GestureDragUpdateCallback? verticalHandler = vertical == null ? + null : + (DragUpdateDetails details) { + vertical.onDown?.call(DragDownDetails()); + vertical.onStart?.call(DragStartDetails()); + vertical.onUpdate?.call(details); + vertical.onEnd?.call(DragEndDetails(primaryVelocity: 0.0)); + }; + + final GestureDragUpdateCallback? panHandler = pan == null ? + null : + (DragUpdateDetails details) { + pan.onDown?.call(DragDownDetails()); + pan.onStart?.call(DragStartDetails()); + pan.onUpdate?.call(details); + pan.onEnd?.call(DragEndDetails()); + }; + + if (verticalHandler == null && panHandler == null) { + return null; + } + return (DragUpdateDetails details) { + if (verticalHandler != null) { + verticalHandler(details); + } + if (panHandler != null) { + panHandler(details); + } + }; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/grid_paper.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/grid_paper.dart new file mode 100644 index 0000000000000000000000000000000000000000..04073bed054bd4866d948b44b233750da744679c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/grid_paper.dart @@ -0,0 +1,117 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'basic.dart'; +import 'framework.dart'; + +class _GridPaperPainter extends CustomPainter { + const _GridPaperPainter({ + required this.color, + required this.interval, + required this.divisions, + required this.subdivisions, + }); + + final Color color; + final double interval; + final int divisions; + final int subdivisions; + + @override + void paint(Canvas canvas, Size size) { + final Paint linePaint = Paint() + ..color = color; + final double allDivisions = (divisions * subdivisions).toDouble(); + for (double x = 0.0; x <= size.width; x += interval / allDivisions) { + linePaint.strokeWidth = (x % interval == 0.0) ? 1.0 : (x % (interval / subdivisions) == 0.0) ? 0.5 : 0.25; + canvas.drawLine(Offset(x, 0.0), Offset(x, size.height), linePaint); + } + for (double y = 0.0; y <= size.height; y += interval / allDivisions) { + linePaint.strokeWidth = (y % interval == 0.0) ? 1.0 : (y % (interval / subdivisions) == 0.0) ? 0.5 : 0.25; + canvas.drawLine(Offset(0.0, y), Offset(size.width, y), linePaint); + } + } + + @override + bool shouldRepaint(_GridPaperPainter oldPainter) { + return oldPainter.color != color + || oldPainter.interval != interval + || oldPainter.divisions != divisions + || oldPainter.subdivisions != subdivisions; + } + + @override + bool hitTest(Offset position) => false; +} + +/// A widget that draws a rectilinear grid of lines one pixel wide. +/// +/// Useful with a [Stack] for visualizing your layout along a grid. +/// +/// The grid's origin (where the first primary horizontal line and the first +/// primary vertical line intersect) is at the top left of the widget. +/// +/// The grid is drawn over the [child] widget. +class GridPaper extends StatelessWidget { + /// Creates a widget that draws a rectilinear grid of 1-pixel-wide lines. + const GridPaper({ + super.key, + this.color = const Color(0x7FC3E8F3), + this.interval = 100.0, + this.divisions = 2, + this.subdivisions = 5, + this.child, + }) : assert(divisions > 0, 'The "divisions" property must be greater than zero. If there were no divisions, the grid paper would not paint anything.'), + assert(subdivisions > 0, 'The "subdivisions" property must be greater than zero. If there were no subdivisions, the grid paper would not paint anything.'); + + /// The color to draw the lines in the grid. + /// + /// Defaults to a light blue commonly seen on traditional grid paper. + final Color color; + + /// The distance between the primary lines in the grid, in logical pixels. + /// + /// Each primary line is one logical pixel wide. + final double interval; + + /// The number of major divisions within each primary grid cell. + /// + /// This is the number of major divisions per [interval], including the + /// primary grid's line. + /// + /// The lines after the first are half a logical pixel wide. + /// + /// If this is set to 2 (the default), then for each [interval] there will be + /// a 1-pixel line on the left, a half-pixel line in the middle, and a 1-pixel + /// line on the right (the latter being the 1-pixel line on the left of the + /// next [interval]). + final int divisions; + + /// The number of minor divisions within each major division, including the + /// major division itself. + /// + /// If [subdivisions] is 5 (the default), it means that there will be four + /// lines between each major ([divisions]) line. + /// + /// The subdivision lines after the first are a quarter of a logical pixel wide. + final int subdivisions; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + @override + Widget build(BuildContext context) { + return CustomPaint( + foregroundPainter: _GridPaperPainter( + color: color, + interval: interval, + divisions: divisions, + subdivisions: subdivisions, + ), + child: child, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/heroes.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/heroes.dart new file mode 100644 index 0000000000000000000000000000000000000000..aca86e3dfd01422842e6177137ac304608b3a31e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/heroes.dart @@ -0,0 +1,1104 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'basic.dart'; +import 'binding.dart'; +import 'framework.dart'; +import 'implicit_animations.dart'; +import 'media_query.dart'; +import 'navigator.dart'; +import 'overlay.dart'; +import 'pages.dart'; +import 'routes.dart'; +import 'ticker_provider.dart' show TickerMode; +import 'transitions.dart'; + +/// Signature for a function that takes two [Rect] instances and returns a +/// [RectTween] that transitions between them. +/// +/// This is typically used with a [HeroController] to provide an animation for +/// [Hero] positions that looks nicer than a linear movement. For example, see +/// [MaterialRectArcTween]. +typedef CreateRectTween = Tween<Rect?> Function(Rect? begin, Rect? end); + +/// Signature for a function that builds a [Hero] placeholder widget given a +/// child and a [Size]. +/// +/// The child can optionally be part of the returned widget tree. The returned +/// widget should typically be constrained to [heroSize], if it doesn't do so +/// implicitly. +/// +/// See also: +/// +/// * [TransitionBuilder], which is similar but only takes a [BuildContext] +/// and a child widget. +typedef HeroPlaceholderBuilder = Widget Function( + BuildContext context, + Size heroSize, + Widget child, +); + +/// A function that lets [Hero]es self supply a [Widget] that is shown during the +/// hero's flight from one route to another instead of default (which is to +/// show the destination route's instance of the Hero). +typedef HeroFlightShuttleBuilder = Widget Function( + BuildContext flightContext, + Animation<double> animation, + HeroFlightDirection flightDirection, + BuildContext fromHeroContext, + BuildContext toHeroContext, +); + +typedef _OnFlightEnded = void Function(_HeroFlight flight); + +/// Direction of the hero's flight based on the navigation operation. +enum HeroFlightDirection { + /// A flight triggered by a route push. + /// + /// The animation goes from 0 to 1. + /// + /// If no custom [HeroFlightShuttleBuilder] is supplied, the top route's + /// [Hero] child is shown in flight. + push, + + /// A flight triggered by a route pop. + /// + /// The animation goes from 1 to 0. + /// + /// If no custom [HeroFlightShuttleBuilder] is supplied, the bottom route's + /// [Hero] child is shown in flight. + pop, +} + +/// A widget that marks its child as being a candidate for +/// [hero animations](https://flutter.dev/docs/development/ui/animations/hero-animations). +/// +/// When a [PageRoute] is pushed or popped with the [Navigator], the entire +/// screen's content is replaced. An old route disappears and a new route +/// appears. If there's a common visual feature on both routes then it can +/// be helpful for orienting the user for the feature to physically move from +/// one page to the other during the routes' transition. Such an animation +/// is called a *hero animation*. The hero widgets "fly" in the Navigator's +/// overlay during the transition and while they're in-flight they're, by +/// default, not shown in their original locations in the old and new routes. +/// +/// To label a widget as such a feature, wrap it in a [Hero] widget. When +/// navigation happens, the [Hero] widgets on each route are identified +/// by the [HeroController]. For each pair of [Hero] widgets that have the +/// same tag, a hero animation is triggered. +/// +/// If a [Hero] is already in flight when navigation occurs, its +/// flight animation will be redirected to its new destination. The +/// widget shown in-flight during the transition is, by default, the +/// destination route's [Hero]'s child. +/// +/// For a Hero animation to trigger, the Hero has to exist on the very first +/// frame of the new page's animation. +/// +/// Routes must not contain more than one [Hero] for each [tag]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=Be9UH1kXFDw} +/// +/// {@tool dartpad} +/// This sample shows a [Hero] used within a [ListTile]. +/// +/// Tapping on the Hero-wrapped rectangle triggers a hero +/// animation as a new [MaterialPageRoute] is pushed. Both the size +/// and location of the rectangle animates. +/// +/// Both widgets use the same [Hero.tag]. +/// +/// The Hero widget uses the matching tags to identify and execute this +/// animation. +/// +/// ** See code in examples/api/lib/widgets/heroes/hero.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows [Hero] flight animations using default tween +/// and custom rect tween. +/// +/// ** See code in examples/api/lib/widgets/heroes/hero.1.dart ** +/// {@end-tool} +/// +/// ## Discussion +/// +/// Heroes and the [Navigator]'s [Overlay] [Stack] must be axis-aligned for +/// all this to work. The top left and bottom right coordinates of each animated +/// Hero will be converted to global coordinates and then from there converted +/// to that [Stack]'s coordinate space, and the entire Hero subtree will, for +/// the duration of the animation, be lifted out of its original place, and +/// positioned on that stack. If the [Hero] isn't axis aligned, this is going to +/// fail in a rather ugly fashion. Don't rotate your heroes! +/// +/// To make the animations look good, it's critical that the widget tree for the +/// hero in both locations be essentially identical. The widget of the *target* +/// is, by default, used to do the transition: when going from route A to route +/// B, route B's hero's widget is placed over route A's hero's widget. Additionally, +/// if the [Hero] subtree changes appearance based on an [InheritedWidget] (such +/// as [MediaQuery] or [Theme]), then the hero animation may have discontinuity +/// at the start or the end of the animation because route A and route B provides +/// different such [InheritedWidget]s. Consider providing a custom [flightShuttleBuilder] +/// to ensure smooth transitions. The default [flightShuttleBuilder] interpolates +/// [MediaQuery]'s paddings. If your [Hero] widget uses custom [InheritedWidget]s +/// and displays a discontinuity in the animation, try to provide custom in-flight +/// transition using [flightShuttleBuilder]. +/// +/// By default, both route A and route B's heroes are hidden while the +/// transitioning widget is animating in-flight above the 2 routes. +/// [placeholderBuilder] can be used to show a custom widget in their place +/// instead once the transition has taken flight. +/// +/// During the transition, the transition widget is animated to route B's hero's +/// position, and then the widget is inserted into route B. When going back from +/// B to A, route A's hero's widget is, by default, placed over where route B's +/// hero's widget was, and then the animation goes the other way. +/// +/// ### Nested Navigators +/// +/// If either or both routes contain nested [Navigator]s, only [Hero]es +/// contained in the top-most routes (as defined by [Route.isCurrent]) *of those +/// nested [Navigator]s* are considered for animation. Just like in the +/// non-nested case the top-most routes containing these [Hero]es in the nested +/// [Navigator]s have to be [PageRoute]s. +/// +/// ## Parts of a Hero Transition +/// +/// ![Diagrams with parts of the Hero transition.](https://flutter.github.io/assets-for-api-docs/assets/interaction/heroes.png) +class Hero extends StatefulWidget { + /// Create a hero. + /// + /// The [child] parameter and all of the its descendants must not be [Hero]es. + const Hero({ + super.key, + required this.tag, + this.createRectTween, + this.flightShuttleBuilder, + this.placeholderBuilder, + this.transitionOnUserGestures = false, + required this.child, + }); + + /// The identifier for this particular hero. If the tag of this hero matches + /// the tag of a hero on a [PageRoute] that we're navigating to or from, then + /// a hero animation will be triggered. + final Object tag; + + /// Defines how the destination hero's bounds change as it flies from the starting + /// route to the destination route. + /// + /// A hero flight begins with the destination hero's [child] aligned with the + /// starting hero's child. The [Tween<Rect>] returned by this callback is used + /// to compute the hero's bounds as the flight animation's value goes from 0.0 + /// to 1.0. + /// + /// If this property is null, the default, then the value of + /// [HeroController.createRectTween] is used. The [HeroController] created by + /// [MaterialApp] creates a [MaterialRectArcTween]. + final CreateRectTween? createRectTween; + + /// The widget subtree that will "fly" from one route to another during a + /// [Navigator] push or pop transition. + /// + /// The appearance of this subtree should be similar to the appearance of + /// the subtrees of any other heroes in the application with the same [tag]. + /// Changes in scale and aspect ratio work well in hero animations, changes + /// in layout or composition do not. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// Optional override to supply a widget that's shown during the hero's flight. + /// + /// This in-flight widget can depend on the route transition's animation as + /// well as the incoming and outgoing routes' [Hero] descendants' widgets and + /// layout. + /// + /// When both the source and destination [Hero]es provide a [flightShuttleBuilder], + /// the destination's [flightShuttleBuilder] takes precedence. + /// + /// If none is provided, the destination route's Hero child is shown in-flight + /// by default. + /// + /// ## Limitations + /// + /// If a widget built by [flightShuttleBuilder] takes part in a [Navigator] + /// push transition, that widget or its descendants must not have any + /// [GlobalKey] that is used in the source Hero's descendant widgets. That is + /// because both subtrees will be included in the widget tree during the Hero + /// flight animation, and [GlobalKey]s must be unique across the entire widget + /// tree. + /// + /// If the said [GlobalKey] is essential to your application, consider providing + /// a custom [placeholderBuilder] for the source Hero, to avoid the [GlobalKey] + /// collision, such as a builder that builds an empty [SizedBox], keeping the + /// Hero [child]'s original size. + final HeroFlightShuttleBuilder? flightShuttleBuilder; + + /// Placeholder widget left in place as the Hero's [child] once the flight takes + /// off. + /// + /// By default the placeholder widget is an empty [SizedBox] keeping the Hero + /// child's original size, unless this Hero is a source Hero of a [Navigator] + /// push transition, in which case [child] will be a descendant of the placeholder + /// and will be kept [Offstage] during the Hero's flight. + final HeroPlaceholderBuilder? placeholderBuilder; + + /// Whether to perform the hero transition if the [PageRoute] transition was + /// triggered by a user gesture, such as a back swipe on iOS. + /// + /// If [Hero]es with the same [tag] on both the from and the to routes have + /// [transitionOnUserGestures] set to true, a back swipe gesture will + /// trigger the same hero animation as a programmatically triggered push or + /// pop. + /// + /// The route being popped to or the bottom route must also have + /// [PageRoute.maintainState] set to true for a gesture triggered hero + /// transition to work. + /// + /// Defaults to false. + final bool transitionOnUserGestures; + + // Returns a map of all of the heroes in `context` indexed by hero tag that + // should be considered for animation when `navigator` transitions from one + // PageRoute to another. + static Map<Object, _HeroState> _allHeroesFor( + BuildContext context, + bool isUserGestureTransition, + NavigatorState navigator, + ) { + final Map<Object, _HeroState> result = <Object, _HeroState>{}; + + void inviteHero(StatefulElement hero, Object tag) { + assert(() { + if (result.containsKey(tag)) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('There are multiple heroes that share the same tag within a subtree.'), + ErrorDescription( + 'Within each subtree for which heroes are to be animated (i.e. a PageRoute subtree), ' + 'each Hero must have a unique non-null tag.\n' + 'In this case, multiple heroes had the following tag: $tag', + ), + DiagnosticsProperty<StatefulElement>('Here is the subtree for one of the offending heroes', hero, linePrefix: '# ', style: DiagnosticsTreeStyle.dense), + ]); + } + return true; + }()); + final Hero heroWidget = hero.widget as Hero; + final _HeroState heroState = hero.state as _HeroState; + if (!isUserGestureTransition || heroWidget.transitionOnUserGestures) { + result[tag] = heroState; + } else { + // If transition is not allowed, we need to make sure hero is not hidden. + // A hero can be hidden previously due to hero transition. + heroState.endFlight(); + } + } + + void visitor(Element element) { + final Widget widget = element.widget; + if (widget is Hero) { + final StatefulElement hero = element as StatefulElement; + final Object tag = widget.tag; + if (Navigator.of(hero) == navigator) { + inviteHero(hero, tag); + } else { + // The nearest navigator to the Hero is not the Navigator that is + // currently transitioning from one route to another. This means + // the Hero is inside a nested Navigator and should only be + // considered for animation if it is part of the top-most route in + // that nested Navigator and if that route is also a PageRoute. + final ModalRoute<Object?>? heroRoute = ModalRoute.of(hero); + if (heroRoute != null && heroRoute is PageRoute && heroRoute.isCurrent) { + inviteHero(hero, tag); + } + } + } else if (widget is HeroMode && !widget.enabled) { + return; + } + element.visitChildren(visitor); + } + + context.visitChildElements(visitor); + return result; + } + + @override + State<Hero> createState() => _HeroState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Object>('tag', tag)); + } +} + +/// The [Hero] widget displays different content based on whether it is in an +/// animated transition ("flight"), from/to another [Hero] with the same tag: +/// * When [startFlight] is called, the real content of this [Hero] will be +/// replaced by a "placeholder" widget. +/// * When the flight ends, the "toHero"'s [endFlight] method must be called +/// by the hero controller, so the real content of that [Hero] becomes +/// visible again when the animation completes. +class _HeroState extends State<Hero> { + final GlobalKey _key = GlobalKey(); + Size? _placeholderSize; + // Whether the placeholder widget should wrap the hero's child widget as its + // own child, when `_placeholderSize` is non-null (i.e. the hero is currently + // in its flight animation). See `startFlight`. + bool _shouldIncludeChild = true; + + // The `shouldIncludeChildInPlaceholder` flag dictates if the child widget of + // this hero should be included in the placeholder widget as a descendant. + // + // When a new hero flight animation takes place, a placeholder widget + // needs to be built to replace the original hero widget. When + // `shouldIncludeChildInPlaceholder` is set to true and `widget.placeholderBuilder` + // is null, the placeholder widget will include the original hero's child + // widget as a descendant, allowing the original element tree to be preserved. + // + // It is typically set to true for the *from* hero in a push transition, + // and false otherwise. + void startFlight({ bool shouldIncludedChildInPlaceholder = false }) { + _shouldIncludeChild = shouldIncludedChildInPlaceholder; + assert(mounted); + final RenderBox box = context.findRenderObject()! as RenderBox; + assert(box.hasSize); + setState(() { + _placeholderSize = box.size; + }); + } + + // When `keepPlaceholder` is true, the placeholder will continue to be shown + // after the flight ends. Otherwise the child of the Hero will become visible + // and its TickerMode will be re-enabled. + // + // This method can be safely called even when this [Hero] is currently not in + // a flight. + void endFlight({ bool keepPlaceholder = false }) { + if (keepPlaceholder || _placeholderSize == null) { + return; + } + + _placeholderSize = null; + if (mounted) { + // Tell the widget to rebuild if it's mounted. _placeholderSize has already + // been updated. + setState(() {}); + } + } + + @override + Widget build(BuildContext context) { + assert( + context.findAncestorWidgetOfExactType<Hero>() == null, + 'A Hero widget cannot be the descendant of another Hero widget.', + ); + + final bool showPlaceholder = _placeholderSize != null; + + if (showPlaceholder && widget.placeholderBuilder != null) { + return widget.placeholderBuilder!(context, _placeholderSize!, widget.child); + } + + if (showPlaceholder && !_shouldIncludeChild) { + return SizedBox( + width: _placeholderSize!.width, + height: _placeholderSize!.height, + ); + } + + return SizedBox( + width: _placeholderSize?.width, + height: _placeholderSize?.height, + child: Offstage( + offstage: showPlaceholder, + child: TickerMode( + enabled: !showPlaceholder, + child: KeyedSubtree(key: _key, child: widget.child), + ), + ), + ); + } +} + +// Everything known about a hero flight that's to be started or diverted. +@immutable +class _HeroFlightManifest { + _HeroFlightManifest({ + required this.type, + required this.overlay, + required this.navigatorSize, + required this.fromRoute, + required this.toRoute, + required this.fromHero, + required this.toHero, + required this.createRectTween, + required this.shuttleBuilder, + required this.isUserGestureTransition, + required this.isDiverted, + }) : assert(fromHero.widget.tag == toHero.widget.tag); + + final HeroFlightDirection type; + final OverlayState overlay; + final Size navigatorSize; + final PageRoute<dynamic> fromRoute; + final PageRoute<dynamic> toRoute; + final _HeroState fromHero; + final _HeroState toHero; + final CreateRectTween? createRectTween; + final HeroFlightShuttleBuilder shuttleBuilder; + final bool isUserGestureTransition; + final bool isDiverted; + + Object get tag => fromHero.widget.tag; + + Animation<double> get animation { + return CurvedAnimation( + parent: (type == HeroFlightDirection.push) ? toRoute.animation! : fromRoute.animation!, + curve: Curves.fastOutSlowIn, + reverseCurve: isDiverted ? null : Curves.fastOutSlowIn.flipped, + ); + } + + Tween<Rect?> createHeroRectTween({ required Rect? begin, required Rect? end }) { + final CreateRectTween? createRectTween = toHero.widget.createRectTween ?? this.createRectTween; + return createRectTween?.call(begin, end) ?? RectTween(begin: begin, end: end); + } + + // The bounding box for `context`'s render object, in `ancestorContext`'s + // render object's coordinate space. + static Rect _boundingBoxFor(BuildContext context, BuildContext? ancestorContext) { + assert(ancestorContext != null); + final RenderBox box = context.findRenderObject()! as RenderBox; + assert(box.hasSize && box.size.isFinite); + return MatrixUtils.transformRect( + box.getTransformTo(ancestorContext?.findRenderObject()), + Offset.zero & box.size, + ); + } + + /// The bounding box of [fromHero], in [fromRoute]'s coordinate space. + /// + /// This property should only be accessed in [_HeroFlight.start]. + late final Rect fromHeroLocation = _boundingBoxFor(fromHero.context, fromRoute.subtreeContext); + + /// The bounding box of [toHero], in [toRoute]'s coordinate space. + /// + /// This property should only be accessed in [_HeroFlight.start] or + /// [_HeroFlight.divert]. + late final Rect toHeroLocation = _boundingBoxFor(toHero.context, toRoute.subtreeContext); + + /// Whether this [_HeroFlightManifest] is valid and can be used to start or + /// divert a [_HeroFlight]. + /// + /// When starting or diverting a [_HeroFlight] with a brand new + /// [_HeroFlightManifest], this flag must be checked to ensure the [RectTween] + /// the [_HeroFlightManifest] produces does not contain coordinates that have + /// [double.infinity] or [double.nan]. + late final bool isValid = toHeroLocation.isFinite && (isDiverted || fromHeroLocation.isFinite); + + @override + String toString() { + return '_HeroFlightManifest($type tag: $tag from route: ${fromRoute.settings} ' + 'to route: ${toRoute.settings} with hero: $fromHero to $toHero)${isValid ? '' : ', INVALID'}'; + } +} + +// Builds the in-flight hero widget. +class _HeroFlight { + _HeroFlight(this.onFlightEnded) { + _proxyAnimation = ProxyAnimation()..addStatusListener(_handleAnimationUpdate); + } + + final _OnFlightEnded onFlightEnded; + + late Tween<Rect?> heroRectTween; + Widget? shuttle; + + Animation<double> _heroOpacity = kAlwaysCompleteAnimation; + late ProxyAnimation _proxyAnimation; + // The manifest will be available once `start` is called, throughout the + // flight's lifecycle. + late _HeroFlightManifest manifest; + OverlayEntry? overlayEntry; + bool _aborted = false; + + static final Animatable<double> _reverseTween = Tween<double>(begin: 1.0, end: 0.0); + + // The OverlayEntry WidgetBuilder callback for the hero's overlay. + Widget _buildOverlay(BuildContext context) { + shuttle ??= manifest.shuttleBuilder( + context, + manifest.animation, + manifest.type, + manifest.fromHero.context, + manifest.toHero.context, + ); + assert(shuttle != null); + + return AnimatedBuilder( + animation: _proxyAnimation, + child: shuttle, + builder: (BuildContext context, Widget? child) { + final Rect rect = heroRectTween.evaluate(_proxyAnimation)!; + final RelativeRect offsets = RelativeRect.fromSize(rect, manifest.navigatorSize); + return Positioned( + top: offsets.top, + right: offsets.right, + bottom: offsets.bottom, + left: offsets.left, + child: IgnorePointer( + child: FadeTransition( + opacity: _heroOpacity, + child: child, + ), + ), + ); + }, + ); + } + + void _performAnimationUpdate(AnimationStatus status) { + if (status == AnimationStatus.completed || status == AnimationStatus.dismissed) { + _proxyAnimation.parent = null; + + assert(overlayEntry != null); + overlayEntry!.remove(); + overlayEntry!.dispose(); + overlayEntry = null; + // We want to keep the hero underneath the current page hidden. If + // [AnimationStatus.completed], toHero will be the one on top and we keep + // fromHero hidden. If [AnimationStatus.dismissed], the animation is + // triggered but canceled before it finishes. In this case, we keep toHero + // hidden instead. + manifest.fromHero.endFlight(keepPlaceholder: status == AnimationStatus.completed); + manifest.toHero.endFlight(keepPlaceholder: status == AnimationStatus.dismissed); + onFlightEnded(this); + _proxyAnimation.removeListener(onTick); + } + } + + bool _scheduledPerformAnimationUpdate = false; + void _handleAnimationUpdate(AnimationStatus status) { + // The animation will not finish until the user lifts their finger, so we + // should suppress the status update if the gesture is in progress, and + // delay it until the finger is lifted. + if (manifest.fromRoute.navigator?.userGestureInProgress != true) { + _performAnimationUpdate(status); + return; + } + + if (_scheduledPerformAnimationUpdate) { + return; + } + + // The `navigator` must be non-null here, or the first if clause above would + // have returned from this method. + final NavigatorState navigator = manifest.fromRoute.navigator!; + + void delayedPerformAnimationUpdate() { + assert(!navigator.userGestureInProgress); + assert(_scheduledPerformAnimationUpdate); + _scheduledPerformAnimationUpdate = false; + navigator.userGestureInProgressNotifier.removeListener(delayedPerformAnimationUpdate); + _performAnimationUpdate(_proxyAnimation.status); + } + assert(navigator.userGestureInProgress); + _scheduledPerformAnimationUpdate = true; + navigator.userGestureInProgressNotifier.addListener(delayedPerformAnimationUpdate); + } + + /// Releases resources. + @mustCallSuper + void dispose() { + if (overlayEntry != null) { + overlayEntry!.remove(); + overlayEntry!.dispose(); + overlayEntry = null; + _proxyAnimation.parent = null; + _proxyAnimation.removeListener(onTick); + _proxyAnimation.removeStatusListener(_handleAnimationUpdate); + } + } + + void onTick() { + final RenderBox? toHeroBox = (!_aborted && manifest.toHero.mounted) + ? manifest.toHero.context.findRenderObject() as RenderBox? + : null; + // Try to find the new origin of the toHero, if the flight isn't aborted. + final Offset? toHeroOrigin = toHeroBox != null && toHeroBox.attached && toHeroBox.hasSize + ? toHeroBox.localToGlobal(Offset.zero, ancestor: manifest.toRoute.subtreeContext?.findRenderObject() as RenderBox?) + : null; + + if (toHeroOrigin != null && toHeroOrigin.isFinite) { + // If the new origin of toHero is available and also paintable, try to + // update heroRectTween with it. + if (toHeroOrigin != heroRectTween.end!.topLeft) { + final Rect heroRectEnd = toHeroOrigin & heroRectTween.end!.size; + heroRectTween = manifest.createHeroRectTween(begin: heroRectTween.begin, end: heroRectEnd); + } + } else if (_heroOpacity.isCompleted) { + // The toHero no longer exists or it's no longer the flight's destination. + // Continue flying while fading out. + _heroOpacity = _proxyAnimation.drive( + _reverseTween.chain(CurveTween(curve: Interval(_proxyAnimation.value, 1.0))), + ); + } + // Update _aborted for the next animation tick. + _aborted = toHeroOrigin == null || !toHeroOrigin.isFinite; + } + + // The simple case: we're either starting a push or a pop animation. + void start(_HeroFlightManifest initialManifest) { + assert(!_aborted); + assert(() { + final Animation<double> initial = initialManifest.animation; + final HeroFlightDirection type = initialManifest.type; + switch (type) { + case HeroFlightDirection.pop: + return initial.value == 1.0 && initialManifest.isUserGestureTransition + // During user gesture transitions, the animation controller isn't + // driving the reverse transition, but should still be in a previously + // completed stage with the initial value at 1.0. + ? initial.status == AnimationStatus.completed + : initial.status == AnimationStatus.reverse; + case HeroFlightDirection.push: + return initial.value == 0.0 && initial.status == AnimationStatus.forward; + } + }()); + + manifest = initialManifest; + + final bool shouldIncludeChildInPlaceholder; + switch (manifest.type) { + case HeroFlightDirection.pop: + _proxyAnimation.parent = ReverseAnimation(manifest.animation); + shouldIncludeChildInPlaceholder = false; + case HeroFlightDirection.push: + _proxyAnimation.parent = manifest.animation; + shouldIncludeChildInPlaceholder = true; + } + + heroRectTween = manifest.createHeroRectTween(begin: manifest.fromHeroLocation, end: manifest.toHeroLocation); + manifest.fromHero.startFlight(shouldIncludedChildInPlaceholder: shouldIncludeChildInPlaceholder); + manifest.toHero.startFlight(); + manifest.overlay.insert(overlayEntry = OverlayEntry(builder: _buildOverlay)); + _proxyAnimation.addListener(onTick); + } + + // While this flight's hero was in transition a push or a pop occurred for + // routes with the same hero. Redirect the in-flight hero to the new toRoute. + void divert(_HeroFlightManifest newManifest) { + assert(manifest.tag == newManifest.tag); + if (manifest.type == HeroFlightDirection.push && newManifest.type == HeroFlightDirection.pop) { + // A push flight was interrupted by a pop. + assert(newManifest.animation.status == AnimationStatus.reverse); + assert(manifest.fromHero == newManifest.toHero); + assert(manifest.toHero == newManifest.fromHero); + assert(manifest.fromRoute == newManifest.toRoute); + assert(manifest.toRoute == newManifest.fromRoute); + + // The same heroRect tween is used in reverse, rather than creating + // a new heroRect with _doCreateRectTween(heroRect.end, heroRect.begin). + // That's because tweens like MaterialRectArcTween may create a different + // path for swapped begin and end parameters. We want the pop flight + // path to be the same (in reverse) as the push flight path. + _proxyAnimation.parent = ReverseAnimation(newManifest.animation); + heroRectTween = ReverseTween<Rect?>(heroRectTween); + } else if (manifest.type == HeroFlightDirection.pop && newManifest.type == HeroFlightDirection.push) { + // A pop flight was interrupted by a push. + assert(newManifest.animation.status == AnimationStatus.forward); + assert(manifest.toHero == newManifest.fromHero); + assert(manifest.toRoute == newManifest.fromRoute); + + _proxyAnimation.parent = newManifest.animation.drive( + Tween<double>( + begin: manifest.animation.value, + end: 1.0, + ), + ); + if (manifest.fromHero != newManifest.toHero) { + manifest.fromHero.endFlight(keepPlaceholder: true); + newManifest.toHero.startFlight(); + heroRectTween = manifest.createHeroRectTween(begin: heroRectTween.end, end: newManifest.toHeroLocation); + } else { + // TODO(hansmuller): Use ReverseTween here per github.com/flutter/flutter/pull/12203. + heroRectTween = manifest.createHeroRectTween(begin: heroRectTween.end, end: heroRectTween.begin); + } + } else { + // A push or a pop flight is heading to a new route, i.e. + // manifest.type == _HeroFlightType.push && newManifest.type == _HeroFlightType.push || + // manifest.type == _HeroFlightType.pop && newManifest.type == _HeroFlightType.pop + assert(manifest.fromHero != newManifest.fromHero); + assert(manifest.toHero != newManifest.toHero); + + heroRectTween = manifest.createHeroRectTween( + begin: heroRectTween.evaluate(_proxyAnimation), + end: newManifest.toHeroLocation, + ); + shuttle = null; + + if (newManifest.type == HeroFlightDirection.pop) { + _proxyAnimation.parent = ReverseAnimation(newManifest.animation); + } else { + _proxyAnimation.parent = newManifest.animation; + } + + manifest.fromHero.endFlight(keepPlaceholder: true); + manifest.toHero.endFlight(keepPlaceholder: true); + + // Let the heroes in each of the routes rebuild with their placeholders. + newManifest.fromHero.startFlight(shouldIncludedChildInPlaceholder: newManifest.type == HeroFlightDirection.push); + newManifest.toHero.startFlight(); + + // Let the transition overlay on top of the routes also rebuild since + // we cleared the old shuttle. + overlayEntry!.markNeedsBuild(); + } + + manifest = newManifest; + } + + void abort() { + _aborted = true; + } + + @override + String toString() { + final RouteSettings from = manifest.fromRoute.settings; + final RouteSettings to = manifest.toRoute.settings; + final Object tag = manifest.tag; + return 'HeroFlight(for: $tag, from: $from, to: $to ${_proxyAnimation.parent})'; + } +} + +/// A [Navigator] observer that manages [Hero] transitions. +/// +/// An instance of [HeroController] should be used in [Navigator.observers]. +/// This is done automatically by [MaterialApp]. +class HeroController extends NavigatorObserver { + /// Creates a hero controller with the given [RectTween] constructor if any. + /// + /// The [createRectTween] argument is optional. If null, the controller uses a + /// linear [Tween<Rect>]. + HeroController({ this.createRectTween }) { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/widgets.dart', + className: '$HeroController', + object: this, + ); + } + } + + /// Used to create [RectTween]s that interpolate the position of heroes in flight. + /// + /// If null, the controller uses a linear [RectTween]. + final CreateRectTween? createRectTween; + + // All of the heroes that are currently in the overlay and in motion. + // Indexed by the hero tag. + final Map<Object, _HeroFlight> _flights = <Object, _HeroFlight>{}; + + @override + void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) { + assert(navigator != null); + _maybeStartHeroTransition(previousRoute, route, HeroFlightDirection.push, false); + } + + @override + void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) { + assert(navigator != null); + // Don't trigger another flight when a pop is committed as a user gesture + // back swipe is snapped. + if (!navigator!.userGestureInProgress) { + _maybeStartHeroTransition(route, previousRoute, HeroFlightDirection.pop, false); + } + } + + @override + void didReplace({ Route<dynamic>? newRoute, Route<dynamic>? oldRoute }) { + assert(navigator != null); + if (newRoute?.isCurrent ?? false) { + // Only run hero animations if the top-most route got replaced. + _maybeStartHeroTransition(oldRoute, newRoute, HeroFlightDirection.push, false); + } + } + + @override + void didStartUserGesture(Route<dynamic> route, Route<dynamic>? previousRoute) { + assert(navigator != null); + _maybeStartHeroTransition(route, previousRoute, HeroFlightDirection.pop, true); + } + + @override + void didStopUserGesture() { + if (navigator!.userGestureInProgress) { + return; + } + + // When the user gesture ends, if the user horizontal drag gesture initiated + // the flight (i.e. the back swipe) didn't move towards the pop direction at + // all, the animation will not play and thus the status update callback + // _handleAnimationUpdate will never be called when the gesture finishes. In + // this case the initiated flight needs to be manually invalidated. + bool isInvalidFlight(_HeroFlight flight) { + return flight.manifest.isUserGestureTransition + && flight.manifest.type == HeroFlightDirection.pop + && flight._proxyAnimation.isDismissed; + } + + final List<_HeroFlight> invalidFlights = _flights.values + .where(isInvalidFlight) + .toList(growable: false); + + // Treat these invalidated flights as dismissed. Calling _handleAnimationUpdate + // will also remove the flight from _flights. + for (final _HeroFlight flight in invalidFlights) { + flight._handleAnimationUpdate(AnimationStatus.dismissed); + } + } + + // If we're transitioning between different page routes, start a hero transition + // after the toRoute has been laid out with its animation's value at 1.0. + void _maybeStartHeroTransition( + Route<dynamic>? fromRoute, + Route<dynamic>? toRoute, + HeroFlightDirection flightType, + bool isUserGestureTransition, + ) { + if (toRoute == fromRoute || + toRoute is! PageRoute<dynamic> || + fromRoute is! PageRoute<dynamic>) { + return; + } + + final PageRoute<dynamic> from = fromRoute; + final PageRoute<dynamic> to = toRoute; + + // A user gesture may have already completed the pop, or we might be the initial route + switch (flightType) { + case HeroFlightDirection.pop: + if (from.animation!.value == 0.0) { + return; + } + case HeroFlightDirection.push: + if (to.animation!.value == 1.0) { + return; + } + } + + // For pop transitions driven by a user gesture: if the "to" page has + // maintainState = true, then the hero's final dimensions can be measured + // immediately because their page's layout is still valid. + if (isUserGestureTransition && flightType == HeroFlightDirection.pop && to.maintainState) { + _startHeroTransition(from, to, flightType, isUserGestureTransition); + } else { + // Otherwise, delay measuring until the end of the next frame to allow + // the 'to' route to build and layout. + + // Putting a route offstage changes its animation value to 1.0. Once this + // frame completes, we'll know where the heroes in the `to` route are + // going to end up, and the `to` route will go back onstage. + to.offstage = to.animation!.value == 0.0; + + WidgetsBinding.instance.addPostFrameCallback((Duration value) { + if (from.navigator == null || to.navigator == null) { + return; + } + _startHeroTransition(from, to, flightType, isUserGestureTransition); + }, debugLabel: 'HeroController.startTransition'); + } + } + + // Find the matching pairs of heroes in from and to and either start or a new + // hero flight, or divert an existing one. + void _startHeroTransition( + PageRoute<dynamic> from, + PageRoute<dynamic> to, + HeroFlightDirection flightType, + bool isUserGestureTransition, + ) { + // If the `to` route was offstage, then we're implicitly restoring its + // animation value back to what it was before it was "moved" offstage. + to.offstage = false; + + final NavigatorState? navigator = this.navigator; + final OverlayState? overlay = navigator?.overlay; + // If the navigator or the overlay was removed before this end-of-frame + // callback was called, then don't actually start a transition, and we don't + // have to worry about any Hero widget we might have hidden in a previous + // flight, or ongoing flights. + if (navigator == null || overlay == null) { + return; + } + + final RenderObject? navigatorRenderObject = navigator.context.findRenderObject(); + + if (navigatorRenderObject is! RenderBox) { + assert(false, 'Navigator $navigator has an invalid RenderObject type ${navigatorRenderObject.runtimeType}.'); + return; + } + assert(navigatorRenderObject.hasSize); + + // At this point, the toHeroes may have been built and laid out for the first time. + // + // If `fromSubtreeContext` is null, call endFlight on all toHeroes, for good measure. + // If `toSubtreeContext` is null abort existingFlights. + final BuildContext? fromSubtreeContext = from.subtreeContext; + final Map<Object, _HeroState> fromHeroes = fromSubtreeContext != null + ? Hero._allHeroesFor(fromSubtreeContext, isUserGestureTransition, navigator) + : const <Object, _HeroState>{}; + final BuildContext? toSubtreeContext = to.subtreeContext; + final Map<Object, _HeroState> toHeroes = toSubtreeContext != null + ? Hero._allHeroesFor(toSubtreeContext, isUserGestureTransition, navigator) + : const <Object, _HeroState>{}; + + for (final MapEntry<Object, _HeroState> fromHeroEntry in fromHeroes.entries) { + final Object tag = fromHeroEntry.key; + final _HeroState fromHero = fromHeroEntry.value; + final _HeroState? toHero = toHeroes[tag]; + final _HeroFlight? existingFlight = _flights[tag]; + final _HeroFlightManifest? manifest = toHero == null + ? null + : _HeroFlightManifest( + type: flightType, + overlay: overlay, + navigatorSize: navigatorRenderObject.size, + fromRoute: from, + toRoute: to, + fromHero: fromHero, + toHero: toHero, + createRectTween: createRectTween, + shuttleBuilder: toHero.widget.flightShuttleBuilder + ?? fromHero.widget.flightShuttleBuilder + ?? _defaultHeroFlightShuttleBuilder, + isUserGestureTransition: isUserGestureTransition, + isDiverted: existingFlight != null, + ); + + // Only proceed with a valid manifest. Otherwise abort the existing + // flight, and call endFlight when this for loop finishes. + if (manifest != null && manifest.isValid) { + toHeroes.remove(tag); + if (existingFlight != null) { + existingFlight.divert(manifest); + } else { + _flights[tag] = _HeroFlight(_handleFlightEnded)..start(manifest); + } + } else { + existingFlight?.abort(); + } + } + + // The remaining entries in toHeroes are those failed to participate in a + // new flight (for not having a valid manifest). + // + // This can happen in a route pop transition when a fromHero is no longer + // mounted, or kept alive by the [KeepAlive] mechanism but no longer visible. + // TODO(LongCatIsLooong): resume aborted flights: https://github.com/flutter/flutter/issues/72947 + for (final _HeroState toHero in toHeroes.values) { + toHero.endFlight(); + } + } + + void _handleFlightEnded(_HeroFlight flight) { + _flights.remove(flight.manifest.tag); + } + + Widget _defaultHeroFlightShuttleBuilder( + BuildContext flightContext, + Animation<double> animation, + HeroFlightDirection flightDirection, + BuildContext fromHeroContext, + BuildContext toHeroContext, + ) { + final Hero toHero = toHeroContext.widget as Hero; + + final MediaQueryData? toMediaQueryData = MediaQuery.maybeOf(toHeroContext); + final MediaQueryData? fromMediaQueryData = MediaQuery.maybeOf(fromHeroContext); + + if (toMediaQueryData == null || fromMediaQueryData == null) { + return toHero.child; + } + + final EdgeInsets fromHeroPadding = fromMediaQueryData.padding; + final EdgeInsets toHeroPadding = toMediaQueryData.padding; + + return AnimatedBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + return MediaQuery( + data: toMediaQueryData.copyWith( + padding: (flightDirection == HeroFlightDirection.push) + ? EdgeInsetsTween( + begin: fromHeroPadding, + end: toHeroPadding, + ).evaluate(animation) + : EdgeInsetsTween( + begin: toHeroPadding, + end: fromHeroPadding, + ).evaluate(animation), + ), + child: toHero.child); + }, + ); + } + + /// Releases resources. + @mustCallSuper + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + + for (final _HeroFlight flight in _flights.values) { + flight.dispose(); + } + } +} + +/// Enables or disables [Hero]es in the widget subtree. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=AaIASk2u1C0} +/// +/// When [enabled] is false, all [Hero] widgets in this subtree will not be +/// involved in hero animations. +/// +/// When [enabled] is true (the default), [Hero] widgets may be involved in +/// hero animations, as usual. +class HeroMode extends StatelessWidget { + /// Creates a widget that enables or disables [Hero]es. + const HeroMode({ + super.key, + required this.child, + this.enabled = true, + }); + + /// The subtree to place inside the [HeroMode]. + final Widget child; + + /// Whether or not [Hero]es are enabled in this subtree. + /// + /// If this property is false, the [Hero]es in this subtree will not animate + /// on route changes. Otherwise, they will animate as usual. + /// + /// Defaults to true. + final bool enabled; + + @override + Widget build(BuildContext context) => child; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('mode', value: enabled, ifTrue: 'enabled', ifFalse: 'disabled', showName: true)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon.dart new file mode 100644 index 0000000000000000000000000000000000000000..b6944fb5e99cebfb467693111f6c9e2edae3ef21 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon.dart @@ -0,0 +1,351 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'icon_data.dart'; +import 'icon_theme.dart'; +import 'icon_theme_data.dart'; +import 'media_query.dart'; + +/// A graphical icon widget drawn with a glyph from a font described in +/// an [IconData] such as material's predefined [IconData]s in [Icons]. +/// +/// Icons are not interactive. For an interactive icon, consider material's +/// [IconButton]. +/// +/// There must be an ambient [Directionality] widget when using [Icon]. +/// Typically this is introduced automatically by the [WidgetsApp] or +/// [MaterialApp]. +/// +/// This widget assumes that the rendered icon is squared. Non-squared icons may +/// render incorrectly. +/// +/// {@tool snippet} +/// +/// This example shows how to create a [Row] of [Icon]s in different colors and +/// sizes. The first [Icon] uses a [semanticLabel] to announce in accessibility +/// modes like TalkBack and VoiceOver. +/// +/// ![The following code snippet would generate a row of icons consisting of a pink heart, a green musical note, and a blue umbrella, each progressively bigger than the last.](https://flutter.github.io/assets-for-api-docs/assets/widgets/icon.png) +/// +/// ```dart +/// const Row( +/// mainAxisAlignment: MainAxisAlignment.spaceAround, +/// children: <Widget>[ +/// Icon( +/// Icons.favorite, +/// color: Colors.pink, +/// size: 24.0, +/// semanticLabel: 'Text to announce in accessibility modes', +/// ), +/// Icon( +/// Icons.audiotrack, +/// color: Colors.green, +/// size: 30.0, +/// ), +/// Icon( +/// Icons.beach_access, +/// color: Colors.blue, +/// size: 36.0, +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [IconButton], for interactive icons. +/// * [Icons], for the list of available Material Icons for use with this class. +/// * [IconTheme], which provides ambient configuration for icons. +/// * [ImageIcon], for showing icons from [AssetImage]s or other [ImageProvider]s. +class Icon extends StatelessWidget { + /// Creates an icon. + const Icon( + this.icon, { + super.key, + this.size, + this.fill, + this.weight, + this.grade, + this.opticalSize, + this.color, + this.shadows, + this.semanticLabel, + this.textDirection, + this.applyTextScaling, + }) : assert(fill == null || (0.0 <= fill && fill <= 1.0)), + assert(weight == null || (0.0 < weight)), + assert(opticalSize == null || (0.0 < opticalSize)); + + /// The icon to display. The available icons are described in [Icons]. + /// + /// The icon can be null, in which case the widget will render as an empty + /// space of the specified [size]. + final IconData? icon; + + /// The size of the icon in logical pixels. + /// + /// Icons occupy a square with width and height equal to size. + /// + /// Defaults to the nearest [IconTheme]'s [IconThemeData.size]. + /// + /// If this [Icon] is being placed inside an [IconButton], then use + /// [IconButton.iconSize] instead, so that the [IconButton] can make the splash + /// area the appropriate size as well. The [IconButton] uses an [IconTheme] to + /// pass down the size to the [Icon]. + final double? size; + + /// The fill for drawing the icon. + /// + /// Requires the underlying icon font to support the `FILL` [FontVariation] + /// axis, otherwise has no effect. Variable font filenames often indicate + /// the supported axes. Must be between 0.0 (unfilled) and 1.0 (filled), + /// inclusive. + /// + /// Can be used to convey a state transition for animation or interaction. + /// + /// Defaults to nearest [IconTheme]'s [IconThemeData.fill]. + /// + /// See also: + /// * [weight], for controlling stroke weight. + /// * [grade], for controlling stroke weight in a more granular way. + /// * [opticalSize], for controlling optical size. + final double? fill; + + /// The stroke weight for drawing the icon. + /// + /// Requires the underlying icon font to support the `wght` [FontVariation] + /// axis, otherwise has no effect. Variable font filenames often indicate + /// the supported axes. Must be greater than 0. + /// + /// Defaults to nearest [IconTheme]'s [IconThemeData.weight]. + /// + /// See also: + /// * [fill], for controlling fill. + /// * [grade], for controlling stroke weight in a more granular way. + /// * [opticalSize], for controlling optical size. + /// * https://fonts.google.com/knowledge/glossary/weight_axis + final double? weight; + + /// The grade (granular stroke weight) for drawing the icon. + /// + /// Requires the underlying icon font to support the `GRAD` [FontVariation] + /// axis, otherwise has no effect. Variable font filenames often indicate + /// the supported axes. Can be negative. + /// + /// Grade and [weight] both affect a symbol's stroke weight (thickness), but + /// grade has a smaller impact on the size of the symbol. + /// + /// Grade is also available in some text fonts. One can match grade levels + /// between text and symbols for a harmonious visual effect. For example, if + /// the text font has a -25 grade value, the symbols can match it with a + /// suitable value, say -25. + /// + /// Defaults to nearest [IconTheme]'s [IconThemeData.grade]. + /// + /// See also: + /// * [fill], for controlling fill. + /// * [weight], for controlling stroke weight in a less granular way. + /// * [opticalSize], for controlling optical size. + /// * https://fonts.google.com/knowledge/glossary/grade_axis + final double? grade; + + /// The optical size for drawing the icon. + /// + /// Requires the underlying icon font to support the `opsz` [FontVariation] + /// axis, otherwise has no effect. Variable font filenames often indicate + /// the supported axes. Must be greater than 0. + /// + /// For an icon to look the same at different sizes, the stroke weight + /// (thickness) must change as the icon size scales. Optical size offers a way + /// to automatically adjust the stroke weight as icon size changes. + /// + /// Defaults to nearest [IconTheme]'s [IconThemeData.opticalSize]. + /// + /// See also: + /// * [fill], for controlling fill. + /// * [weight], for controlling stroke weight. + /// * [grade], for controlling stroke weight in a more granular way. + /// * https://fonts.google.com/knowledge/glossary/optical_size_axis + final double? opticalSize; + + /// The color to use when drawing the icon. + /// + /// Defaults to the nearest [IconTheme]'s [IconThemeData.color]. + /// + /// The color (whether specified explicitly here or obtained from the + /// [IconTheme]) will be further adjusted by the nearest [IconTheme]'s + /// [IconThemeData.opacity]. + /// + /// {@tool snippet} + /// Typically, a Material Design color will be used, as follows: + /// + /// ```dart + /// Icon( + /// Icons.widgets, + /// color: Colors.blue.shade400, + /// ) + /// ``` + /// {@end-tool} + final Color? color; + + /// A list of [Shadow]s that will be painted underneath the icon. + /// + /// Multiple shadows are supported to replicate lighting from multiple light + /// sources. + /// + /// Shadows must be in the same order for [Icon] to be considered as + /// equivalent as order produces differing transparency. + /// + /// Defaults to the nearest [IconTheme]'s [IconThemeData.shadows]. + final List<Shadow>? shadows; + + /// Semantic label for the icon. + /// + /// Announced in accessibility modes (e.g TalkBack/VoiceOver). + /// This label does not show in the UI. + /// + /// * [SemanticsProperties.label], which is set to [semanticLabel] in the + /// underlying [Semantics] widget. + final String? semanticLabel; + + /// The text direction to use for rendering the icon. + /// + /// If this is null, the ambient [Directionality] is used instead. + /// + /// Some icons follow the reading direction. For example, "back" buttons point + /// left in left-to-right environments and right in right-to-left + /// environments. Such icons have their [IconData.matchTextDirection] field + /// set to true, and the [Icon] widget uses the [textDirection] to determine + /// the orientation in which to draw the icon. + /// + /// This property has no effect if the [icon]'s [IconData.matchTextDirection] + /// field is false, but for consistency a text direction value must always be + /// specified, either directly using this property or using [Directionality]. + final TextDirection? textDirection; + + /// Whether to scale the size of this widget using the ambient [MediaQuery]'s [TextScaler]. + /// + /// This is specially useful when you have an icon associated with a text, as + /// scaling the text without scaling the icon would result in a confusing + /// interface. + /// + /// Defaults to the nearest [IconTheme]'s + /// [IconThemeData.applyTextScaling]. + final bool? applyTextScaling; + + @override + Widget build(BuildContext context) { + assert(this.textDirection != null || debugCheckHasDirectionality(context)); + final TextDirection textDirection = this.textDirection ?? Directionality.of(context); + + final IconThemeData iconTheme = IconTheme.of(context); + + final bool applyTextScaling = this.applyTextScaling ?? iconTheme.applyTextScaling ?? false; + + final double tentativeIconSize = size ?? iconTheme.size ?? kDefaultFontSize; + + final double iconSize = applyTextScaling ? MediaQuery.textScalerOf(context).scale(tentativeIconSize) : tentativeIconSize; + + final double? iconFill = fill ?? iconTheme.fill; + + final double? iconWeight = weight ?? iconTheme.weight; + + final double? iconGrade = grade ?? iconTheme.grade; + + final double? iconOpticalSize = opticalSize ?? iconTheme.opticalSize; + + final List<Shadow>? iconShadows = shadows ?? iconTheme.shadows; + + final IconData? icon = this.icon; + if (icon == null) { + return Semantics( + label: semanticLabel, + child: SizedBox(width: iconSize, height: iconSize), + ); + } + + final double iconOpacity = iconTheme.opacity ?? 1.0; + Color iconColor = color ?? iconTheme.color!; + if (iconOpacity != 1.0) { + iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity); + } + + final TextStyle fontStyle = TextStyle( + fontVariations: <FontVariation>[ + if (iconFill != null) FontVariation('FILL', iconFill), + if (iconWeight != null) FontVariation('wght', iconWeight), + if (iconGrade != null) FontVariation('GRAD', iconGrade), + if (iconOpticalSize != null) FontVariation('opsz', iconOpticalSize), + ], + inherit: false, + color: iconColor, + fontSize: iconSize, + fontFamily: icon.fontFamily, + package: icon.fontPackage, + fontFamilyFallback: icon.fontFamilyFallback, + shadows: iconShadows, + height: 1.0, // Makes sure the font's body is vertically centered within the iconSize x iconSize square. + leadingDistribution: TextLeadingDistribution.even, + ); + + Widget iconWidget = RichText( + overflow: TextOverflow.visible, // Never clip. + textDirection: textDirection, // Since we already fetched it for the assert... + text: TextSpan( + text: String.fromCharCode(icon.codePoint), + style: fontStyle, + ), + ); + + if (icon.matchTextDirection) { + switch (textDirection) { + case TextDirection.rtl: + iconWidget = Transform( + transform: Matrix4.identity()..scale(-1.0, 1.0, 1.0), + alignment: Alignment.center, + transformHitTests: false, + child: iconWidget, + ); + case TextDirection.ltr: + break; + } + } + + return Semantics( + label: semanticLabel, + child: ExcludeSemantics( + child: SizedBox( + width: iconSize, + height: iconSize, + child: Center( + child: iconWidget, + ), + ), + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IconDataProperty('icon', icon, ifNull: '<empty>', showName: false)); + properties.add(DoubleProperty('size', size, defaultValue: null)); + properties.add(DoubleProperty('fill', fill, defaultValue: null)); + properties.add(DoubleProperty('weight', weight, defaultValue: null)); + properties.add(DoubleProperty('grade', grade, defaultValue: null)); + properties.add(DoubleProperty('opticalSize', opticalSize, defaultValue: null)); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(IterableProperty<Shadow>('shadows', shadows, defaultValue: null)); + properties.add(StringProperty('semanticLabel', semanticLabel, defaultValue: null)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('applyTextScaling', applyTextScaling, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon_data.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon_data.dart new file mode 100644 index 0000000000000000000000000000000000000000..865d5d10801cd5db9fec917c69732c326596bd1c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon_data.dart @@ -0,0 +1,140 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +/// A description of an icon fulfilled by a font glyph. +/// +/// See [Icons] for a number of predefined icons available for material +/// design applications. +/// +/// In release builds, the Flutter tool will tree shake out of bundled fonts +/// the code points (or instances of [IconData]) which are not referenced from +/// Dart app code. See the [staticIconProvider] annotation for more details. +@immutable +class IconData { + /// Creates icon data. + /// + /// Rarely used directly. Instead, consider using one of the predefined icons + /// like the [Icons] collection. + /// + /// The [fontPackage] argument must be non-null when using a font family that + /// is included in a package. This is used when selecting the font. + /// + /// Instantiating non-const instances of this class in your app will + /// mean the app cannot be built in release mode with icon tree-shaking (it + /// need to be explicitly opted out at build time). See [staticIconProvider] + /// for more context. + const IconData( + this.codePoint, { + this.fontFamily, + this.fontPackage, + this.matchTextDirection = false, + this.fontFamilyFallback, + }); + + /// The Unicode code point at which this icon is stored in the icon font. + final int codePoint; + + /// The font family from which the glyph for the [codePoint] will be selected. + final String? fontFamily; + + /// The name of the package from which the font family is included. + /// + /// The name is used by the [Icon] widget when configuring the [TextStyle] so + /// that the given [fontFamily] is obtained from the appropriate asset. + /// + /// See also: + /// + /// * [TextStyle], which describes how to use fonts from other packages. + final String? fontPackage; + + /// Whether this icon should be automatically mirrored in right-to-left + /// environments. + /// + /// The [Icon] widget respects this value by mirroring the icon when the + /// [Directionality] is [TextDirection.rtl]. + final bool matchTextDirection; + + /// The ordered list of font families to fall back on when a glyph cannot be found in a higher priority font family. + /// + /// For more details, refer to the documentation of [TextStyle] + final List<String>? fontFamilyFallback; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is IconData + && other.codePoint == codePoint + && other.fontFamily == fontFamily + && other.fontPackage == fontPackage + && other.matchTextDirection == matchTextDirection + && listEquals(other.fontFamilyFallback, fontFamilyFallback); + } + + @override + int get hashCode { + return Object.hash( + codePoint, + fontFamily, + fontPackage, + matchTextDirection, + Object.hashAll(fontFamilyFallback ?? const <String?>[]), + ); + } + + @override + String toString() => 'IconData(U+${codePoint.toRadixString(16).toUpperCase().padLeft(5, '0')})'; +} + +/// [DiagnosticsProperty] that has an [IconData] as value. +class IconDataProperty extends DiagnosticsProperty<IconData> { + /// Create a diagnostics property for [IconData]. + IconDataProperty( + String super.name, + super.value, { + super.ifNull, + super.showName, + super.style, + super.level, + }); + + @override + Map<String, Object?> toJsonMap(DiagnosticsSerializationDelegate delegate) { + final Map<String, Object?> json = super.toJsonMap(delegate); + if (value != null) { + json['valueProperties'] = <String, Object>{ + 'codePoint': value!.codePoint, + }; + } + return json; + } +} + +class _StaticIconProvider { + const _StaticIconProvider(); +} + +/// Annotation for classes that only provide static const [IconData] instances. +/// +/// This is a hint to the font tree shaker to ignore the constant instances +/// of [IconData] appearing in the declaration of this class when tree-shaking +/// unused code points from the bundled font. +/// +/// Classes with this annotation must have only "static const" members. The +/// presence of any non-const [IconData] instances will preclude apps +/// importing the declaration into their application from being able to use +/// icon tree-shaking during release builds, resulting in larger font assets. +/// +/// ```dart +/// @staticIconProvider +/// abstract final class MyCustomIcons { +/// static const String fontFamily = 'MyCustomIcons'; +/// static const IconData happyFace = IconData(1, fontFamily: fontFamily); +/// static const IconData sadFace = IconData(2, fontFamily: fontFamily); +/// } +/// ``` +const Object staticIconProvider = _StaticIconProvider(); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..1a8a17ef4a60bef79d7c959307ad850a78beef72 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon_theme.dart @@ -0,0 +1,101 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'icon_theme_data.dart'; +import 'inherited_theme.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Controls the default properties of icons in a widget subtree. +/// +/// The icon theme is honored by [Icon] and [ImageIcon] widgets. +class IconTheme extends InheritedTheme { + /// Creates an icon theme that controls properties of descendant widgets. + const IconTheme({ + super.key, + required this.data, + required super.child, + }); + + /// Creates an icon theme that controls the properties of + /// descendant widgets, and merges in the current icon theme, if any. + static Widget merge({ + Key? key, + required IconThemeData data, + required Widget child, + }) { + return Builder( + builder: (BuildContext context) { + return IconTheme( + key: key, + data: _getInheritedIconThemeData(context).merge(data), + child: child, + ); + }, + ); + } + + /// The set of properties to use for icons in this subtree. + final IconThemeData data; + + /// The data from the closest instance of this class that encloses the given + /// context, if any. + /// + /// If there is no ambient icon theme, defaults to [IconThemeData.fallback]. + /// The returned [IconThemeData] is concrete (all values are non-null; see + /// [IconThemeData.isConcrete]). Any properties on the ambient icon theme that + /// are null get defaulted to the values specified on + /// [IconThemeData.fallback]. + /// + /// The [Theme] widget from the `material` library introduces an [IconTheme] + /// widget set to the [ThemeData.iconTheme], so in a Material Design + /// application, this will typically default to the icon theme from the + /// ambient [Theme]. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// IconThemeData theme = IconTheme.of(context); + /// ``` + static IconThemeData of(BuildContext context) { + final IconThemeData iconThemeData = _getInheritedIconThemeData(context).resolve(context); + return iconThemeData.isConcrete + ? iconThemeData + : iconThemeData.copyWith( + size: iconThemeData.size ?? const IconThemeData.fallback().size, + fill: iconThemeData.fill ?? const IconThemeData.fallback().fill, + weight: iconThemeData.weight ?? const IconThemeData.fallback().weight, + grade: iconThemeData.grade ?? const IconThemeData.fallback().grade, + opticalSize: iconThemeData.opticalSize ?? const IconThemeData.fallback().opticalSize, + color: iconThemeData.color ?? const IconThemeData.fallback().color, + opacity: iconThemeData.opacity ?? const IconThemeData.fallback().opacity, + shadows: iconThemeData.shadows ?? const IconThemeData.fallback().shadows, + applyTextScaling: iconThemeData.applyTextScaling ?? const IconThemeData.fallback().applyTextScaling, + ); + } + + static IconThemeData _getInheritedIconThemeData(BuildContext context) { + final IconTheme? iconTheme = context.dependOnInheritedWidgetOfExactType<IconTheme>(); + return iconTheme?.data ?? const IconThemeData.fallback(); + } + + @override + bool updateShouldNotify(IconTheme oldWidget) => data != oldWidget.data; + + @override + Widget wrap(BuildContext context, Widget child) { + return IconTheme(data: data, child: child); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + data.debugFillProperties(properties); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon_theme_data.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon_theme_data.dart new file mode 100644 index 0000000000000000000000000000000000000000..ee71b24a83bcb2488493b18ebb526ab5f17cc966 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/icon_theme_data.dart @@ -0,0 +1,238 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show lerpDouble; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; + +import 'framework.dart' show BuildContext; + +/// Defines the size, font variations, color, opacity, and shadows of icons. +/// +/// Used by [IconTheme] to control those properties in a widget subtree. +/// +/// To obtain the current icon theme, use [IconTheme.of]. To convert an icon +/// theme to a version with all the fields filled in, use +/// [IconThemeData.fallback]. +@immutable +class IconThemeData with Diagnosticable { + /// Creates an icon theme data. + /// + /// The opacity applies to both explicit and default icon colors. The value + /// is clamped between 0.0 and 1.0. + const IconThemeData({ + this.size, + this.fill, + this.weight, + this.grade, + this.opticalSize, + this.color, + double? opacity, + this.shadows, + this.applyTextScaling, + }) : _opacity = opacity, + assert(fill == null || (0.0 <= fill && fill <= 1.0)), + assert(weight == null || (0.0 < weight)), + assert(opticalSize == null || (0.0 < opticalSize)); + + /// Creates an icon theme with some reasonable default values. + /// + /// The [size] is 24.0, [fill] is 0.0, [weight] is 400.0, [grade] is 0.0, + /// opticalSize is 48.0, [color] is black, and [opacity] is 1.0. + const IconThemeData.fallback() + : size = 24.0, + fill = 0.0, + weight = 400.0, + grade = 0.0, + opticalSize = 48.0, + color = const Color(0xFF000000), + _opacity = 1.0, + shadows = null, + applyTextScaling = false; + + /// Creates a copy of this icon theme but with the given fields replaced with + /// the new values. + IconThemeData copyWith({ + double? size, + double? fill, + double? weight, + double? grade, + double? opticalSize, + Color? color, + double? opacity, + List<Shadow>? shadows, + bool? applyTextScaling, + }) { + return IconThemeData( + size: size ?? this.size, + fill: fill ?? this.fill, + weight: weight ?? this.weight, + grade: grade ?? this.grade, + opticalSize: opticalSize ?? this.opticalSize, + color: color ?? this.color, + opacity: opacity ?? this.opacity, + shadows: shadows ?? this.shadows, + applyTextScaling: applyTextScaling ?? this.applyTextScaling, + ); + } + + /// Returns a new icon theme that matches this icon theme but with some values + /// replaced by the non-null parameters of the given icon theme. If the given + /// icon theme is null, returns this icon theme. + IconThemeData merge(IconThemeData? other) { + if (other == null) { + return this; + } + return copyWith( + size: other.size, + fill: other.fill, + weight: other.weight, + grade: other.grade, + opticalSize: other.opticalSize, + color: other.color, + opacity: other.opacity, + shadows: other.shadows, + applyTextScaling: other.applyTextScaling, + ); + } + + /// Called by [IconTheme.of] to convert this instance to an [IconThemeData] + /// that fits the given [BuildContext]. + /// + /// This method gives the ambient [IconThemeData] a chance to update itself, + /// after it's been retrieved by [IconTheme.of], and before being returned as + /// the final result. For instance, [CupertinoIconThemeData] overrides this method + /// to resolve [color], in case [color] is a [CupertinoDynamicColor] and needs + /// to be resolved against the given [BuildContext] before it can be used as a + /// regular [Color]. + /// + /// The default implementation returns this [IconThemeData] as-is. + /// + /// See also: + /// + /// * [CupertinoIconThemeData.resolve] an implementation that resolves + /// the color of [CupertinoIconThemeData] before returning. + IconThemeData resolve(BuildContext context) => this; + + /// Whether all the properties (except shadows) of this object are non-null. + bool get isConcrete => size != null + && fill != null + && weight != null + && grade != null + && opticalSize != null + && color != null + && opacity != null + && applyTextScaling != null; + + /// The default for [Icon.size]. + /// + /// Falls back to 24.0. + final double? size; + + /// The default for [Icon.fill]. + /// + /// Falls back to 0.0. + final double? fill; + + /// The default for [Icon.weight]. + /// + /// Falls back to 400.0. + final double? weight; + + /// The default for [Icon.grade]. + /// + /// Falls back to 0.0. + final double? grade; + + /// The default for [Icon.opticalSize]. + /// + /// Falls back to 48.0. + final double? opticalSize; + + /// The default for [Icon.color]. + /// + /// In material apps, if there is a [Theme] without any [IconTheme]s + /// specified, icon colors default to white if [ThemeData.brightness] is dark + /// and black if [ThemeData.brightness] is light. + /// + /// Otherwise, falls back to black. + final Color? color; + + /// An opacity to apply to both explicit and default icon colors. + /// + /// Falls back to 1.0. + double? get opacity => _opacity == null ? null : clampDouble(_opacity, 0.0, 1.0); + final double? _opacity; + + /// The default for [Icon.shadows]. + final List<Shadow>? shadows; + + /// The default for [Icon.applyTextScaling]. + final bool? applyTextScaling; + + /// Linearly interpolate between two icon theme data objects. + /// + /// {@macro dart.ui.shadow.lerp} + static IconThemeData lerp(IconThemeData? a, IconThemeData? b, double t) { + if (identical(a, b) && a != null) { + return a; + } + return IconThemeData( + size: ui.lerpDouble(a?.size, b?.size, t), + fill: ui.lerpDouble(a?.fill, b?.fill, t), + weight: ui.lerpDouble(a?.weight, b?.weight, t), + grade: ui.lerpDouble(a?.grade, b?.grade, t), + opticalSize: ui.lerpDouble(a?.opticalSize, b?.opticalSize, t), + color: Color.lerp(a?.color, b?.color, t), + opacity: ui.lerpDouble(a?.opacity, b?.opacity, t), + shadows: Shadow.lerpList(a?.shadows, b?.shadows, t), + applyTextScaling: t < 0.5 ? a?.applyTextScaling : b?.applyTextScaling, + ); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is IconThemeData + && other.size == size + && other.fill == fill + && other.weight == weight + && other.grade == grade + && other.opticalSize == opticalSize + && other.color == color + && other.opacity == opacity + && listEquals(other.shadows, shadows) + && other.applyTextScaling == applyTextScaling; + } + + @override + int get hashCode => Object.hash( + size, + fill, + weight, + grade, + opticalSize, + color, + opacity, + shadows == null ? null : Object.hashAll(shadows!), + applyTextScaling, + ); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('size', size, defaultValue: null)); + properties.add(DoubleProperty('fill', fill, defaultValue: null)); + properties.add(DoubleProperty('weight', weight, defaultValue: null)); + properties.add(DoubleProperty('grade', grade, defaultValue: null)); + properties.add(DoubleProperty('opticalSize', opticalSize, defaultValue: null)); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(DoubleProperty('opacity', opacity, defaultValue: null)); + properties.add(IterableProperty<Shadow>('shadows', shadows, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('applyTextScaling', applyTextScaling, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/image.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/image.dart new file mode 100644 index 0000000000000000000000000000000000000000..c3180508df3c1bfadbe1040b8678e6a42954b720 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/image.dart @@ -0,0 +1,1325 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:io' show File; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/semantics.dart'; + +import 'basic.dart'; +import 'binding.dart'; +import 'disposable_build_context.dart'; +import 'framework.dart'; +import 'localizations.dart'; +import 'media_query.dart'; +import 'placeholder.dart'; +import 'scroll_aware_image_provider.dart'; +import 'text.dart'; +import 'ticker_provider.dart'; + +export 'package:flutter/painting.dart' show + AssetImage, + ExactAssetImage, + FileImage, + FilterQuality, + ImageConfiguration, + ImageInfo, + ImageProvider, + ImageStream, + MemoryImage, + NetworkImage; + +// Examples can assume: +// late Widget image; +// late ImageProvider _image; + +/// Creates an [ImageConfiguration] based on the given [BuildContext] (and +/// optionally size). +/// +/// This is the object that must be passed to [BoxPainter.paint] and to +/// [ImageProvider.resolve]. +/// +/// If this is not called from a build method, then it should be reinvoked +/// whenever the dependencies change, e.g. by calling it from +/// [State.didChangeDependencies], so that any changes in the environment are +/// picked up (e.g. if the device pixel ratio changes). +/// +/// See also: +/// +/// * [ImageProvider], which has an example showing how this might be used. +ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size? size }) { + return ImageConfiguration( + bundle: DefaultAssetBundle.of(context), + devicePixelRatio: MediaQuery.maybeDevicePixelRatioOf(context) ?? 1.0, + locale: Localizations.maybeLocaleOf(context), + textDirection: Directionality.maybeOf(context), + size: size, + platform: defaultTargetPlatform, + ); +} + +/// Prefetches an image into the image cache. +/// +/// Returns a [Future] that will complete when the first image yielded by the +/// [ImageProvider] is available or failed to load. +/// +/// If the image is later used by an [Image] or [BoxDecoration] or [FadeInImage], +/// it will probably be loaded faster. The consumer of the image does not need +/// to use the same [ImageProvider] instance. The [ImageCache] will find the image +/// as long as both images share the same key, and the image is held by the +/// cache. +/// +/// The cache may refuse to hold the image if it is disabled, the image is too +/// large, or some other criteria implemented by a custom [ImageCache] +/// implementation. +/// +/// The [ImageCache] holds a reference to all images passed to +/// [ImageCache.putIfAbsent] as long as their [ImageStreamCompleter] has at +/// least one listener. This method will wait until the end of the frame after +/// its future completes before releasing its own listener. This gives callers a +/// chance to listen to the stream if necessary. A caller can determine if the +/// image ended up in the cache by calling [ImageProvider.obtainCacheStatus]. If +/// it is only held as [ImageCacheStatus.live], and the caller wishes to keep +/// the resolved image in memory, the caller should immediately call +/// `provider.resolve` and add a listener to the returned [ImageStream]. The +/// image will remain pinned in memory at least until the caller removes its +/// listener from the stream, even if it would not otherwise fit into the cache. +/// +/// Callers should be cautious about pinning large images or a large number of +/// images in memory, as this can result in running out of memory and being +/// killed by the operating system. The lower the available physical memory, the +/// more susceptible callers will be to running into OOM issues. These issues +/// manifest as immediate process death, sometimes with no other error messages. +/// +/// The [BuildContext] and [Size] are used to select an image configuration +/// (see [createLocalImageConfiguration]). +/// +/// The returned future will not complete with error, even if precaching +/// failed. The `onError` argument can be used to manually handle errors while +/// pre-caching. +/// +/// See also: +/// +/// * [ImageCache], which holds images that may be reused. +Future<void> precacheImage( + ImageProvider provider, + BuildContext context, { + Size? size, + ImageErrorListener? onError, +}) { + final ImageConfiguration config = createLocalImageConfiguration(context, size: size); + final Completer<void> completer = Completer<void>(); + final ImageStream stream = provider.resolve(config); + ImageStreamListener? listener; + listener = ImageStreamListener( + (ImageInfo? image, bool sync) { + if (!completer.isCompleted) { + completer.complete(); + } + // Give callers until at least the end of the frame to subscribe to the + // image stream. + // See ImageCache._liveImages + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + stream.removeListener(listener!); + }, debugLabel: 'precacheImage.removeListener'); + }, + onError: (Object exception, StackTrace? stackTrace) { + if (!completer.isCompleted) { + completer.complete(); + } + stream.removeListener(listener!); + if (onError != null) { + onError(exception, stackTrace); + } else { + FlutterError.reportError(FlutterErrorDetails( + context: ErrorDescription('image failed to precache'), + library: 'image resource service', + exception: exception, + stack: stackTrace, + silent: true, + )); + } + }, + ); + stream.addListener(listener); + return completer.future; +} + +/// Signature used by [Image.frameBuilder] to control the widget that will be +/// used when an [Image] is built. +/// +/// The `child` argument contains the default image widget and is guaranteed to +/// be non-null. Typically, this builder will wrap the `child` widget in some +/// way and return the wrapped widget. If this builder returns `child` directly, +/// it will yield the same result as if [Image.frameBuilder] was null. +/// +/// The `frame` argument specifies the index of the current image frame being +/// rendered. It will be null before the first image frame is ready, and zero +/// for the first image frame. For single-frame images, it will never be greater +/// than zero. For multi-frame images (such as animated GIFs), it will increase +/// by one every time a new image frame is shown (including when the image +/// animates in a loop). +/// +/// The `wasSynchronouslyLoaded` argument specifies whether the image was +/// available synchronously (on the same +/// [rendering pipeline frame](rendering/RendererBinding/drawFrame.html) as the +/// `Image` widget itself was created) and thus able to be painted immediately. +/// If this is false, then there was one or more rendering pipeline frames where +/// the image wasn't yet available to be painted. For multi-frame images (such +/// as animated GIFs), the value of this argument will be the same for all image +/// frames. In other words, if the first image frame was available immediately, +/// then this argument will be true for all image frames. +/// +/// This builder must not return null. +/// +/// See also: +/// +/// * [Image.frameBuilder], which makes use of this signature in the [Image] +/// widget. +typedef ImageFrameBuilder = Widget Function( + BuildContext context, + Widget child, + int? frame, + bool wasSynchronouslyLoaded, +); + +/// Signature used by [Image.loadingBuilder] to build a representation of the +/// image's loading progress. +/// +/// This is useful for images that are incrementally loaded (e.g. over a local +/// file system or a network), and the application wishes to give the user an +/// indication of when the image will be displayed. +/// +/// The `child` argument contains the default image widget and is guaranteed to +/// be non-null. Typically, this builder will wrap the `child` widget in some +/// way and return the wrapped widget. If this builder returns `child` directly, +/// it will yield the same result as if [Image.loadingBuilder] was null. +/// +/// The `loadingProgress` argument contains the current progress towards loading +/// the image. This argument will be non-null while the image is loading, but it +/// will be null in the following cases: +/// +/// * When the widget is first rendered before any bytes have been loaded. +/// * When an image has been fully loaded and is available to be painted. +/// +/// If callers are implementing custom [ImageProvider] and [ImageStream] +/// instances (which is very rare), it's possible to produce image streams that +/// continue to fire image chunk events after an image frame has been loaded. +/// In such cases, the `child` parameter will represent the current +/// fully-loaded image frame. +/// +/// This builder must not return null. +/// +/// See also: +/// +/// * [Image.loadingBuilder], which makes use of this signature in the [Image] +/// widget. +/// * [ImageChunkListener], a lower-level signature for listening to raw +/// [ImageChunkEvent]s. +typedef ImageLoadingBuilder = Widget Function( + BuildContext context, + Widget child, + ImageChunkEvent? loadingProgress, +); + +/// Signature used by [Image.errorBuilder] to create a replacement widget to +/// render instead of the image. +typedef ImageErrorWidgetBuilder = Widget Function( + BuildContext context, + Object error, + StackTrace? stackTrace, +); + +/// A widget that displays an image. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=7oIAs-0G4mw} +/// +/// Several constructors are provided for the various ways that an image can be +/// specified: +/// +/// * [Image.new], for obtaining an image from an [ImageProvider]. +/// * [Image.asset], for obtaining an image from an [AssetBundle] +/// using a key. +/// * [Image.network], for obtaining an image from a URL. +/// * [Image.file], for obtaining an image from a [File]. +/// * [Image.memory], for obtaining an image from a [Uint8List]. +/// +/// The following image formats are supported: {@macro dart.ui.imageFormats} +/// +/// To automatically perform pixel-density-aware asset resolution, specify the +/// image using an [AssetImage] and make sure that a [MaterialApp], [WidgetsApp], +/// or [MediaQuery] widget exists above the [Image] widget in the widget tree. +/// +/// The image is painted using [paintImage], which describes the meanings of the +/// various fields on this class in more detail. +/// +/// {@tool snippet} +/// The default constructor can be used with any [ImageProvider], such as a +/// [NetworkImage], to display an image from the internet. +/// +/// ![An image of an owl displayed by the image widget](https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg) +/// +/// ```dart +/// const Image( +/// image: NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg'), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// The [Image] Widget also provides several constructors to display different +/// types of images for convenience. In this example, use the [Image.network] +/// constructor to display an image from the internet. +/// +/// ![An image of an owl displayed by the image widget using the shortcut constructor](https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg) +/// +/// ```dart +/// Image.network('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg') +/// ``` +/// {@end-tool} +/// +/// ## Memory usage +/// +/// The image is stored in memory in uncompressed form (so that it can be +/// rendered). Large images will use a lot of memory: a 4K image (3840×2160) +/// will use over 30MB of RAM (assuming 32 bits per pixel). +/// +/// This problem is exacerbated by the images being cached in the [ImageCache], +/// so large images can use memory for even longer than they are displayed. +/// +/// The [Image.asset], [Image.network], [Image.file], and [Image.memory] +/// constructors allow a custom decode size to be specified through `cacheWidth` +/// and `cacheHeight` parameters. The engine will then decode and store the +/// image at the specified size, instead of the image's natural size. +/// +/// This can significantly reduce the memory usage. For example, a 4K image that +/// will be rendered at only 384×216 pixels (one-tenth the horizontal and +/// vertical dimensions) would only use 330KB if those dimensions are specified +/// using the `cacheWidth` and `cacheHeight` parameters, a 100-fold reduction in +/// memory usage. +/// +/// ### Web considerations +/// +/// In the case where a network image is used on the Web platform, the +/// `cacheWidth` and `cacheHeight` parameters are only supported when the +/// application is running with the CanvasKit renderer. When the application is +/// using the HTML renderer, the web engine delegates image decoding of network +/// images to the Web, which does not support custom decode sizes. +/// +/// ## Custom image providers +/// +/// {@tool dartpad} +/// In this example, a variant of [NetworkImage] is created that passes all the +/// [ImageConfiguration] information (locale, platform, size, etc) to the server +/// using query arguments in the image URL. +/// +/// ** See code in examples/api/lib/painting/image_provider/image_provider.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Icon], which shows an image from a font. +/// * [Ink.image], which is the preferred way to show an image in a +/// material application (especially if the image is in a [Material] and will +/// have an [InkWell] on top of it). +/// * [Image](dart-ui/Image-class.html), the class in the [dart:ui] library. +/// * Cookbook: [Display images from the internet](https://flutter.dev/docs/cookbook/images/network-image) +/// * Cookbook: [Work with cached images](https://flutter.dev/docs/cookbook/images/cached-images) +/// * Cookbook: [Fade in images with a placeholder](https://flutter.dev/docs/cookbook/images/fading-in-images) +class Image extends StatefulWidget { + /// Creates a widget that displays an image. + /// + /// To show an image from the network or from an asset bundle, consider using + /// [Image.network] and [Image.asset] respectively. + /// + /// Either the [width] and [height] arguments should be specified, or the + /// widget should be placed in a context that sets tight layout constraints. + /// Otherwise, the image dimensions will change as the image is loaded, which + /// will result in ugly layout changes. + /// + /// {@template flutter.widgets.image.filterQualityParameter} + /// Use [filterQuality] to specify the rendering quality of the image. + /// {@endtemplate} + /// + /// If [excludeFromSemantics] is true, then [semanticLabel] will be ignored. + const Image({ + super.key, + required this.image, + this.frameBuilder, + this.loadingBuilder, + this.errorBuilder, + this.semanticLabel, + this.excludeFromSemantics = false, + this.width, + this.height, + this.color, + this.opacity, + this.colorBlendMode, + this.fit, + this.alignment = Alignment.center, + this.repeat = ImageRepeat.noRepeat, + this.centerSlice, + this.matchTextDirection = false, + this.gaplessPlayback = false, + this.isAntiAlias = false, + this.filterQuality = FilterQuality.low, + }); + + /// Creates a widget that displays an [ImageStream] obtained from the network. + /// + /// Either the [width] and [height] arguments should be specified, or the + /// widget should be placed in a context that sets tight layout constraints. + /// Otherwise, the image dimensions will change as the image is loaded, which + /// will result in ugly layout changes. + /// + /// All network images are cached regardless of HTTP headers. + /// + /// An optional [headers] argument can be used to send custom HTTP headers + /// with the image request. + /// + /// {@macro flutter.widgets.image.filterQualityParameter} + /// + /// If [excludeFromSemantics] is true, then [semanticLabel] will be ignored. + /// + /// If `cacheWidth` or `cacheHeight` are provided, they indicate to the + /// engine that the image should be decoded at the specified size. The image + /// will be rendered to the constraints of the layout or [width] and [height] + /// regardless of these parameters. These parameters are primarily intended + /// to reduce the memory usage of [ImageCache]. + /// + /// In the case where the network image is on the Web platform, the [cacheWidth] + /// and [cacheHeight] parameters are ignored as the web engine delegates + /// image decoding to the web which does not support custom decode sizes. + Image.network( + String src, { + super.key, + double scale = 1.0, + this.frameBuilder, + this.loadingBuilder, + this.errorBuilder, + this.semanticLabel, + this.excludeFromSemantics = false, + this.width, + this.height, + this.color, + this.opacity, + this.colorBlendMode, + this.fit, + this.alignment = Alignment.center, + this.repeat = ImageRepeat.noRepeat, + this.centerSlice, + this.matchTextDirection = false, + this.gaplessPlayback = false, + this.filterQuality = FilterQuality.low, + this.isAntiAlias = false, + Map<String, String>? headers, + int? cacheWidth, + int? cacheHeight, + }) : image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, NetworkImage(src, scale: scale, headers: headers)), + assert(cacheWidth == null || cacheWidth > 0), + assert(cacheHeight == null || cacheHeight > 0); + + /// Creates a widget that displays an [ImageStream] obtained from a [File]. + /// + /// Either the [width] and [height] arguments should be specified, or the + /// widget should be placed in a context that sets tight layout constraints. + /// Otherwise, the image dimensions will change as the image is loaded, which + /// will result in ugly layout changes. + /// + /// On Android, this may require the + /// `android.permission.READ_EXTERNAL_STORAGE` permission. + /// + /// {@macro flutter.widgets.image.filterQualityParameter} + /// + /// If [excludeFromSemantics] is true, then [semanticLabel] will be ignored. + /// + /// If `cacheWidth` or `cacheHeight` are provided, they indicate to the + /// engine that the image must be decoded at the specified size. The image + /// will be rendered to the constraints of the layout or [width] and [height] + /// regardless of these parameters. These parameters are primarily intended + /// to reduce the memory usage of [ImageCache]. + /// + /// Loading an image from a file creates an in memory copy of the file, + /// which is retained in the [ImageCache]. The underlying file is not + /// monitored for changes. If it does change, the application should evict + /// the entry from the [ImageCache]. + /// + /// See also: + /// + /// * [FileImage] provider for evicting the underlying file easily. + Image.file( + File file, { + super.key, + double scale = 1.0, + this.frameBuilder, + this.errorBuilder, + this.semanticLabel, + this.excludeFromSemantics = false, + this.width, + this.height, + this.color, + this.opacity, + this.colorBlendMode, + this.fit, + this.alignment = Alignment.center, + this.repeat = ImageRepeat.noRepeat, + this.centerSlice, + this.matchTextDirection = false, + this.gaplessPlayback = false, + this.isAntiAlias = false, + this.filterQuality = FilterQuality.low, + int? cacheWidth, + int? cacheHeight, + }) : + // FileImage is not supported on Flutter Web therefore neither this method. + assert( + !kIsWeb, + 'Image.file is not supported on Flutter Web. ' + 'Consider using either Image.asset or Image.network instead.', + ), + image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, FileImage(file, scale: scale)), + loadingBuilder = null, + assert(cacheWidth == null || cacheWidth > 0), + assert(cacheHeight == null || cacheHeight > 0); + + // TODO(ianh): Implement the following (see ../services/image_resolution.dart): + // + // * If [width] and [height] are both specified, and [scale] is not, then + // size-aware asset resolution will be attempted also, with the given + // dimensions interpreted as logical pixels. + // + // * If the images have platform, locale, or directionality variants, the + // current platform, locale, and directionality are taken into account + // during asset resolution as well. + /// Creates a widget that displays an [ImageStream] obtained from an asset + /// bundle. The key for the image is given by the `name` argument. + /// + /// The `package` argument must be non-null when displaying an image from a + /// package and null otherwise. See the `Assets in packages` section for + /// details. + /// + /// If the `bundle` argument is omitted or null, then the + /// [DefaultAssetBundle] will be used. + /// + /// By default, the pixel-density-aware asset resolution will be attempted. In + /// addition: + /// + /// * If the `scale` argument is provided and is not null, then the exact + /// asset specified will be used. To display an image variant with a specific + /// density, the exact path must be provided (e.g. `images/2x/cat.png`). + /// + /// If [excludeFromSemantics] is true, then [semanticLabel] will be ignored. + /// + /// If `cacheWidth` or `cacheHeight` are provided, they indicate to the + /// engine that the image must be decoded at the specified size. The image + /// will be rendered to the constraints of the layout or [width] and [height] + /// regardless of these parameters. These parameters are primarily intended + /// to reduce the memory usage of [ImageCache]. + /// + /// Either the [width] and [height] arguments should be specified, or the + /// widget should be placed in a context that sets tight layout constraints. + /// Otherwise, the image dimensions will change as the image is loaded, which + /// will result in ugly layout changes. + /// + /// {@macro flutter.widgets.image.filterQualityParameter} + /// + /// {@tool snippet} + /// + /// Suppose that the project's `pubspec.yaml` file contains the following: + /// + /// ```yaml + /// flutter: + /// assets: + /// - images/cat.png + /// - images/2x/cat.png + /// - images/3.5x/cat.png + /// ``` + /// {@end-tool} + /// + /// On a screen with a device pixel ratio of 2.0, the following widget would + /// render the `images/2x/cat.png` file: + /// + /// ```dart + /// Image.asset('images/cat.png') + /// ``` + /// + /// This corresponds to the file that is in the project's `images/2x/` + /// directory with the name `cat.png` (the paths are relative to the + /// `pubspec.yaml` file). + /// + /// On a device with a 4.0 device pixel ratio, the `images/3.5x/cat.png` asset + /// would be used. On a device with a 1.0 device pixel ratio, the + /// `images/cat.png` resource would be used. + /// + /// The `images/cat.png` image can be omitted from disk (though it must still + /// be present in the manifest). If it is omitted, then on a device with a 1.0 + /// device pixel ratio, the `images/2x/cat.png` image would be used instead. + /// + /// + /// ## Assets in packages + /// + /// To create the widget with an asset from a package, the [package] argument + /// must be provided. For instance, suppose a package called `my_icons` has + /// `icons/heart.png` . + /// + /// {@tool snippet} + /// Then to display the image, use: + /// + /// ```dart + /// Image.asset('icons/heart.png', package: 'my_icons') + /// ``` + /// {@end-tool} + /// + /// Assets used by the package itself should also be displayed using the + /// [package] argument as above. + /// + /// If the desired asset is specified in the `pubspec.yaml` of the package, it + /// is bundled automatically with the app. In particular, assets used by the + /// package itself must be specified in its `pubspec.yaml`. + /// + /// A package can also choose to have assets in its 'lib/' folder that are not + /// specified in its `pubspec.yaml`. In this case for those images to be + /// bundled, the app has to specify which ones to include. For instance a + /// package named `fancy_backgrounds` could have: + /// + /// lib/backgrounds/background1.png + /// lib/backgrounds/background2.png + /// lib/backgrounds/background3.png + /// + /// To include, say the first image, the `pubspec.yaml` of the app should + /// specify it in the assets section: + /// + /// ```yaml + /// assets: + /// - packages/fancy_backgrounds/backgrounds/background1.png + /// ``` + /// + /// The `lib/` is implied, so it should not be included in the asset path. + /// + /// + /// See also: + /// + /// * [AssetImage], which is used to implement the behavior when the scale is + /// omitted. + /// * [ExactAssetImage], which is used to implement the behavior when the + /// scale is present. + /// * <https://flutter.dev/assets-and-images/>, an introduction to assets in + /// Flutter. + Image.asset( + String name, { + super.key, + AssetBundle? bundle, + this.frameBuilder, + this.errorBuilder, + this.semanticLabel, + this.excludeFromSemantics = false, + double? scale, + this.width, + this.height, + this.color, + this.opacity, + this.colorBlendMode, + this.fit, + this.alignment = Alignment.center, + this.repeat = ImageRepeat.noRepeat, + this.centerSlice, + this.matchTextDirection = false, + this.gaplessPlayback = false, + this.isAntiAlias = false, + String? package, + this.filterQuality = FilterQuality.low, + int? cacheWidth, + int? cacheHeight, + }) : image = ResizeImage.resizeIfNeeded( + cacheWidth, + cacheHeight, + scale != null + ? ExactAssetImage(name, bundle: bundle, scale: scale, package: package) + : AssetImage(name, bundle: bundle, package: package), + ), + loadingBuilder = null, + assert(cacheWidth == null || cacheWidth > 0), + assert(cacheHeight == null || cacheHeight > 0); + + /// Creates a widget that displays an [ImageStream] obtained from a [Uint8List]. + /// + /// The `bytes` argument specifies encoded image bytes, which can be encoded + /// in any of the following supported image formats: + /// {@macro dart.ui.imageFormats} + /// + /// The `scale` argument specifies the linear scale factor for drawing this + /// image at its intended size and applies to both the width and the height. + /// {@macro flutter.painting.imageInfo.scale} + /// + /// This only accepts compressed image formats (e.g. PNG). Uncompressed + /// formats like rawRgba (the default format of [dart:ui.Image.toByteData]) + /// will lead to exceptions. + /// + /// Either the [width] and [height] arguments should be specified, or the + /// widget should be placed in a context that sets tight layout constraints. + /// Otherwise, the image dimensions will change as the image is loaded, which + /// will result in ugly layout changes. + /// + /// {@macro flutter.widgets.image.filterQualityParameter} + /// + /// If [excludeFromSemantics] is true, then [semanticLabel] will be ignored. + /// + /// If `cacheWidth` or `cacheHeight` are provided, they indicate to the + /// engine that the image must be decoded at the specified size. The image + /// will be rendered to the constraints of the layout or [width] and [height] + /// regardless of these parameters. These parameters are primarily intended + /// to reduce the memory usage of [ImageCache]. + Image.memory( + Uint8List bytes, { + super.key, + double scale = 1.0, + this.frameBuilder, + this.errorBuilder, + this.semanticLabel, + this.excludeFromSemantics = false, + this.width, + this.height, + this.color, + this.opacity, + this.colorBlendMode, + this.fit, + this.alignment = Alignment.center, + this.repeat = ImageRepeat.noRepeat, + this.centerSlice, + this.matchTextDirection = false, + this.gaplessPlayback = false, + this.isAntiAlias = false, + this.filterQuality = FilterQuality.low, + int? cacheWidth, + int? cacheHeight, + }) : image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, MemoryImage(bytes, scale: scale)), + loadingBuilder = null, + assert(cacheWidth == null || cacheWidth > 0), + assert(cacheHeight == null || cacheHeight > 0); + + /// The image to display. + final ImageProvider image; + + /// A builder function responsible for creating the widget that represents + /// this image. + /// + /// If this is null, this widget will display an image that is painted as + /// soon as the first image frame is available (and will appear to "pop" in + /// if it becomes available asynchronously). Callers might use this builder to + /// add effects to the image (such as fading the image in when it becomes + /// available) or to display a placeholder widget while the image is loading. + /// + /// To have finer-grained control over the way that an image's loading + /// progress is communicated to the user, see [loadingBuilder]. + /// + /// ## Chaining with [loadingBuilder] + /// + /// If a [loadingBuilder] has _also_ been specified for an image, the two + /// builders will be chained together: the _result_ of this builder will + /// be passed as the `child` argument to the [loadingBuilder]. For example, + /// consider the following builders used in conjunction: + /// + /// {@template flutter.widgets.Image.frameBuilder.chainedBuildersExample} + /// ```dart + /// Image( + /// image: _image, + /// frameBuilder: (BuildContext context, Widget child, int? frame, bool? wasSynchronouslyLoaded) { + /// return Padding( + /// padding: const EdgeInsets.all(8.0), + /// child: child, + /// ); + /// }, + /// loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) { + /// return Center(child: child); + /// }, + /// ) + /// ``` + /// + /// In this example, the widget hierarchy will contain the following: + /// + /// ```dart + /// Center( + /// child: Padding( + /// padding: const EdgeInsets.all(8.0), + /// child: image, + /// ), + /// ), + /// ``` + /// {@endtemplate} + /// + /// {@tool dartpad} + /// The following sample demonstrates how to use this builder to implement an + /// image that fades in once it's been loaded. + /// + /// This sample contains a limited subset of the functionality that the + /// [FadeInImage] widget provides out of the box. + /// + /// ** See code in examples/api/lib/widgets/image/image.frame_builder.0.dart ** + /// {@end-tool} + final ImageFrameBuilder? frameBuilder; + + /// A builder that specifies the widget to display to the user while an image + /// is still loading. + /// + /// If this is null, and the image is loaded incrementally (e.g. over a + /// network), the user will receive no indication of the progress as the + /// bytes of the image are loaded. + /// + /// For more information on how to interpret the arguments that are passed to + /// this builder, see the documentation on [ImageLoadingBuilder]. + /// + /// ## Performance implications + /// + /// If a [loadingBuilder] is specified for an image, the [Image] widget is + /// likely to be rebuilt on every + /// [rendering pipeline frame](rendering/RendererBinding/drawFrame.html) until + /// the image has loaded. This is useful for cases such as displaying a loading + /// progress indicator, but for simpler cases such as displaying a placeholder + /// widget that doesn't depend on the loading progress (e.g. static "loading" + /// text), [frameBuilder] will likely work and not incur as much cost. + /// + /// ## Chaining with [frameBuilder] + /// + /// If a [frameBuilder] has _also_ been specified for an image, the two + /// builders will be chained together: the `child` argument to this + /// builder will contain the _result_ of the [frameBuilder]. For example, + /// consider the following builders used in conjunction: + /// + /// {@macro flutter.widgets.Image.frameBuilder.chainedBuildersExample} + /// + /// {@tool dartpad} + /// The following sample uses [loadingBuilder] to show a + /// [CircularProgressIndicator] while an image loads over the network. + /// + /// ** See code in examples/api/lib/widgets/image/image.loading_builder.0.dart ** + /// {@end-tool} + /// + /// Run against a real-world image on a slow network, the previous example + /// renders the following loading progress indicator while the image loads + /// before rendering the completed image. + /// + /// {@animation 400 400 https://flutter.github.io/assets-for-api-docs/assets/widgets/loading_progress_image.mp4} + final ImageLoadingBuilder? loadingBuilder; + + /// A builder function that is called if an error occurs during image loading. + /// + /// If this builder is not provided, any exceptions will be reported to + /// [FlutterError.onError]. If it is provided, the caller should either handle + /// the exception by providing a replacement widget, or rethrow the exception. + /// + /// {@tool dartpad} + /// The following sample uses [errorBuilder] to show a '😢' in place of the + /// image that fails to load, and prints the error to the console. + /// + /// ** See code in examples/api/lib/widgets/image/image.error_builder.0.dart ** + /// {@end-tool} + final ImageErrorWidgetBuilder? errorBuilder; + + /// If non-null, require the image to have this width (in logical pixels). + /// + /// If null, the image will pick a size that best preserves its intrinsic + /// aspect ratio. + /// + /// It is strongly recommended that either both the [width] and the [height] + /// be specified, or that the widget be placed in a context that sets tight + /// layout constraints, so that the image does not change size as it loads. + /// Consider using [fit] to adapt the image's rendering to fit the given width + /// and height if the exact image dimensions are not known in advance. + final double? width; + + /// If non-null, require the image to have this height (in logical pixels). + /// + /// If null, the image will pick a size that best preserves its intrinsic + /// aspect ratio. + /// + /// It is strongly recommended that either both the [width] and the [height] + /// be specified, or that the widget be placed in a context that sets tight + /// layout constraints, so that the image does not change size as it loads. + /// Consider using [fit] to adapt the image's rendering to fit the given width + /// and height if the exact image dimensions are not known in advance. + final double? height; + + /// If non-null, this color is blended with each image pixel using [colorBlendMode]. + final Color? color; + + /// If non-null, the value from the [Animation] is multiplied with the opacity + /// of each image pixel before painting onto the canvas. + /// + /// This is more efficient than using [FadeTransition] to change the opacity + /// of an image, since this avoids creating a new composited layer. Composited + /// layers may double memory usage as the image is painted onto an offscreen + /// render target. + /// + /// See also: + /// + /// * [AlwaysStoppedAnimation], which allows you to create an [Animation] + /// from a single opacity value. + final Animation<double>? opacity; + + /// The rendering quality of the image. + /// + /// {@template flutter.widgets.image.filterQuality} + /// If the image is of a high quality and its pixels are perfectly aligned + /// with the physical screen pixels, extra quality enhancement may not be + /// necessary. If so, then [FilterQuality.none] would be the most efficient. + /// + /// If the pixels are not perfectly aligned with the screen pixels, or if the + /// image itself is of a low quality, [FilterQuality.none] may produce + /// undesirable artifacts. Consider using other [FilterQuality] values to + /// improve the rendered image quality in this case. Pixels may be misaligned + /// with the screen pixels as a result of transforms or scaling. + /// + /// See also: + /// + /// * [FilterQuality], the enum containing all possible filter quality + /// options. + /// {@endtemplate} + final FilterQuality filterQuality; + + /// Used to combine [color] with this image. + /// + /// The default is [BlendMode.srcIn]. In terms of the blend mode, [color] is + /// the source and this image is the destination. + /// + /// See also: + /// + /// * [BlendMode], which includes an illustration of the effect of each blend mode. + final BlendMode? colorBlendMode; + + /// How to inscribe the image into the space allocated during layout. + /// + /// The default varies based on the other fields. See the discussion at + /// [paintImage]. + final BoxFit? fit; + + /// How to align the image within its bounds. + /// + /// The alignment aligns the given position in the image to the given position + /// in the layout bounds. For example, an [Alignment] alignment of (-1.0, + /// -1.0) aligns the image to the top-left corner of its layout bounds, while an + /// [Alignment] alignment of (1.0, 1.0) aligns the bottom right of the + /// image with the bottom right corner of its layout bounds. Similarly, an + /// alignment of (0.0, 1.0) aligns the bottom middle of the image with the + /// middle of the bottom edge of its layout bounds. + /// + /// To display a subpart of an image, consider using a [CustomPainter] and + /// [Canvas.drawImageRect]. + /// + /// If the [alignment] is [TextDirection]-dependent (i.e. if it is a + /// [AlignmentDirectional]), then an ambient [Directionality] widget + /// must be in scope. + /// + /// Defaults to [Alignment.center]. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry alignment; + + /// How to paint any portions of the layout bounds not covered by the image. + final ImageRepeat repeat; + + /// The center slice for a nine-patch image. + /// + /// The region of the image inside the center slice will be stretched both + /// horizontally and vertically to fit the image into its destination. The + /// region of the image above and below the center slice will be stretched + /// only horizontally and the region of the image to the left and right of + /// the center slice will be stretched only vertically. + final Rect? centerSlice; + + /// Whether to paint the image in the direction of the [TextDirection]. + /// + /// If this is true, then in [TextDirection.ltr] contexts, the image will be + /// drawn with its origin in the top left (the "normal" painting direction for + /// images); and in [TextDirection.rtl] contexts, the image will be drawn with + /// a scaling factor of -1 in the horizontal direction so that the origin is + /// in the top right. + /// + /// This is occasionally used with images in right-to-left environments, for + /// images that were designed for left-to-right locales. Be careful, when + /// using this, to not flip images with integral shadows, text, or other + /// effects that will look incorrect when flipped. + /// + /// If this is true, there must be an ambient [Directionality] widget in + /// scope. + final bool matchTextDirection; + + /// Whether to continue showing the old image (true), or briefly show nothing + /// (false), when the image provider changes. The default value is false. + /// + /// ## Design discussion + /// + /// ### Why is the default value of [gaplessPlayback] false? + /// + /// Having the default value of [gaplessPlayback] be false helps prevent + /// situations where stale or misleading information might be presented. + /// Consider the following case: + /// + /// We have constructed a 'Person' widget that displays an avatar [Image] of + /// the currently loaded person along with their name. We could request for a + /// new person to be loaded into the widget at any time. Suppose we have a + /// person currently loaded and the widget loads a new person. What happens + /// if the [Image] fails to load? + /// + /// * Option A ([gaplessPlayback] = false): The new person's name is coupled + /// with a blank image. + /// + /// * Option B ([gaplessPlayback] = true): The widget displays the avatar of + /// the previous person and the name of the newly loaded person. + /// + /// This is why the default value is false. Most of the time, when you change + /// the image provider you're not just changing the image, you're removing the + /// old widget and adding a new one and not expecting them to have any + /// relationship. With [gaplessPlayback] on you might accidentally break this + /// expectation and re-use the old widget. + final bool gaplessPlayback; + + /// A Semantic description of the image. + /// + /// Used to provide a description of the image to TalkBack on Android, and + /// VoiceOver on iOS. + final String? semanticLabel; + + /// Whether to exclude this image from semantics. + /// + /// Useful for images which do not contribute meaningful information to an + /// application. + final bool excludeFromSemantics; + + /// Whether to paint the image with anti-aliasing. + /// + /// Anti-aliasing alleviates the sawtooth artifact when the image is rotated. + final bool isAntiAlias; + + @override + State<Image> createState() => _ImageState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ImageProvider>('image', image)); + properties.add(DiagnosticsProperty<Function>('frameBuilder', frameBuilder)); + properties.add(DiagnosticsProperty<Function>('loadingBuilder', loadingBuilder)); + properties.add(DoubleProperty('width', width, defaultValue: null)); + properties.add(DoubleProperty('height', height, defaultValue: null)); + properties.add(ColorProperty('color', color, defaultValue: null)); + properties.add(DiagnosticsProperty<Animation<double>?>('opacity', opacity, defaultValue: null)); + properties.add(EnumProperty<BlendMode>('colorBlendMode', colorBlendMode, defaultValue: null)); + properties.add(EnumProperty<BoxFit>('fit', fit, defaultValue: null)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: null)); + properties.add(EnumProperty<ImageRepeat>('repeat', repeat, defaultValue: ImageRepeat.noRepeat)); + properties.add(DiagnosticsProperty<Rect>('centerSlice', centerSlice, defaultValue: null)); + properties.add(FlagProperty('matchTextDirection', value: matchTextDirection, ifTrue: 'match text direction')); + properties.add(StringProperty('semanticLabel', semanticLabel, defaultValue: null)); + properties.add(DiagnosticsProperty<bool>('this.excludeFromSemantics', excludeFromSemantics)); + properties.add(EnumProperty<FilterQuality>('filterQuality', filterQuality)); + } +} + +class _ImageState extends State<Image> with WidgetsBindingObserver { + ImageStream? _imageStream; + ImageInfo? _imageInfo; + ImageChunkEvent? _loadingProgress; + bool _isListeningToStream = false; + late bool _invertColors; + int? _frameNumber; + bool _wasSynchronouslyLoaded = false; + late DisposableBuildContext<State<Image>> _scrollAwareContext; + Object? _lastException; + StackTrace? _lastStack; + ImageStreamCompleterHandle? _completerHandle; + + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addObserver(this); + _scrollAwareContext = DisposableBuildContext<State<Image>>(this); + } + + @override + void dispose() { + assert(_imageStream != null); + WidgetsBinding.instance.removeObserver(this); + _stopListeningToStream(); + _completerHandle?.dispose(); + _scrollAwareContext.dispose(); + _replaceImage(info: null); + super.dispose(); + } + + @override + void didChangeDependencies() { + _updateInvertColors(); + _resolveImage(); + + if (TickerMode.of(context)) { + _listenToStream(); + } else { + _stopListeningToStream(keepStreamAlive: true); + } + + super.didChangeDependencies(); + } + + @override + void didUpdateWidget(Image oldWidget) { + super.didUpdateWidget(oldWidget); + if (_isListeningToStream && + (widget.loadingBuilder == null) != (oldWidget.loadingBuilder == null)) { + final ImageStreamListener oldListener = _getListener(); + _imageStream!.addListener(_getListener(recreateListener: true)); + _imageStream!.removeListener(oldListener); + } + if (widget.image != oldWidget.image) { + _resolveImage(); + } + } + + @override + void didChangeAccessibilityFeatures() { + super.didChangeAccessibilityFeatures(); + setState(() { + _updateInvertColors(); + }); + } + + @override + void reassemble() { + _resolveImage(); // in case the image cache was flushed + super.reassemble(); + } + + void _updateInvertColors() { + _invertColors = MediaQuery.maybeInvertColorsOf(context) + ?? SemanticsBinding.instance.accessibilityFeatures.invertColors; + } + + void _resolveImage() { + final ScrollAwareImageProvider provider = ScrollAwareImageProvider<Object>( + context: _scrollAwareContext, + imageProvider: widget.image, + ); + final ImageStream newStream = + provider.resolve(createLocalImageConfiguration( + context, + size: widget.width != null && widget.height != null ? Size(widget.width!, widget.height!) : null, + )); + _updateSourceStream(newStream); + } + + ImageStreamListener? _imageStreamListener; + ImageStreamListener _getListener({bool recreateListener = false}) { + if (_imageStreamListener == null || recreateListener) { + _lastException = null; + _lastStack = null; + _imageStreamListener = ImageStreamListener( + _handleImageFrame, + onChunk: widget.loadingBuilder == null ? null : _handleImageChunk, + onError: widget.errorBuilder != null || kDebugMode + ? (Object error, StackTrace? stackTrace) { + setState(() { + _lastException = error; + _lastStack = stackTrace; + }); + assert(() { + if (widget.errorBuilder == null) { + // ignore: only_throw_errors, since we're just proxying the error. + throw error; // Ensures the error message is printed to the console. + } + return true; + }()); + } + : null, + ); + } + return _imageStreamListener!; + } + + void _handleImageFrame(ImageInfo imageInfo, bool synchronousCall) { + setState(() { + _replaceImage(info: imageInfo); + _loadingProgress = null; + _lastException = null; + _lastStack = null; + _frameNumber = _frameNumber == null ? 0 : _frameNumber! + 1; + _wasSynchronouslyLoaded = _wasSynchronouslyLoaded | synchronousCall; + }); + } + + void _handleImageChunk(ImageChunkEvent event) { + assert(widget.loadingBuilder != null); + setState(() { + _loadingProgress = event; + _lastException = null; + _lastStack = null; + }); + } + + void _replaceImage({required ImageInfo? info}) { + final ImageInfo? oldImageInfo = _imageInfo; + SchedulerBinding.instance.addPostFrameCallback( + (_) => oldImageInfo?.dispose(), + debugLabel: 'Image.disposeOldInfo' + ); + _imageInfo = info; + } + + // Updates _imageStream to newStream, and moves the stream listener + // registration from the old stream to the new stream (if a listener was + // registered). + void _updateSourceStream(ImageStream newStream) { + if (_imageStream?.key == newStream.key) { + return; + } + + if (_isListeningToStream) { + _imageStream!.removeListener(_getListener()); + } + + if (!widget.gaplessPlayback) { + setState(() { _replaceImage(info: null); }); + } + + setState(() { + _loadingProgress = null; + _frameNumber = null; + _wasSynchronouslyLoaded = false; + }); + + _imageStream = newStream; + if (_isListeningToStream) { + _imageStream!.addListener(_getListener()); + } + } + + void _listenToStream() { + if (_isListeningToStream) { + return; + } + + _imageStream!.addListener(_getListener()); + _completerHandle?.dispose(); + _completerHandle = null; + + _isListeningToStream = true; + } + + /// Stops listening to the image stream, if this state object has attached a + /// listener. + /// + /// If the listener from this state is the last listener on the stream, the + /// stream will be disposed. To keep the stream alive, set `keepStreamAlive` + /// to true, which create [ImageStreamCompleterHandle] to keep the completer + /// alive and is compatible with the [TickerMode] being off. + void _stopListeningToStream({bool keepStreamAlive = false}) { + if (!_isListeningToStream) { + return; + } + + if (keepStreamAlive && _completerHandle == null && _imageStream?.completer != null) { + _completerHandle = _imageStream!.completer!.keepAlive(); + } + + _imageStream!.removeListener(_getListener()); + _isListeningToStream = false; + } + + Widget _debugBuildErrorWidget(BuildContext context, Object error) { + return Stack( + alignment: Alignment.center, + children: <Widget>[ + const Positioned.fill( + child: Placeholder( + color: Color(0xCF8D021F), + ), + ), + Padding( + padding: const EdgeInsets.all(4.0), + child: FittedBox( + child: Text( + '$error', + textAlign: TextAlign.center, + textDirection: TextDirection.ltr, + style: const TextStyle( + shadows: <Shadow>[ + Shadow(blurRadius: 1.0), + ], + ), + ), + ), + ), + ], + ); + } + + @override + Widget build(BuildContext context) { + if (_lastException != null) { + if (widget.errorBuilder != null) { + return widget.errorBuilder!(context, _lastException!, _lastStack); + } + if (kDebugMode) { + return _debugBuildErrorWidget(context, _lastException!); + } + } + + Widget result = RawImage( + // Do not clone the image, because RawImage is a stateless wrapper. + // The image will be disposed by this state object when it is not needed + // anymore, such as when it is unmounted or when the image stream pushes + // a new image. + image: _imageInfo?.image, + debugImageLabel: _imageInfo?.debugLabel, + width: widget.width, + height: widget.height, + scale: _imageInfo?.scale ?? 1.0, + color: widget.color, + opacity: widget.opacity, + colorBlendMode: widget.colorBlendMode, + fit: widget.fit, + alignment: widget.alignment, + repeat: widget.repeat, + centerSlice: widget.centerSlice, + matchTextDirection: widget.matchTextDirection, + invertColors: _invertColors, + isAntiAlias: widget.isAntiAlias, + filterQuality: widget.filterQuality, + ); + + if (!widget.excludeFromSemantics) { + result = Semantics( + container: widget.semanticLabel != null, + image: true, + label: widget.semanticLabel ?? '', + child: result, + ); + } + + if (widget.frameBuilder != null) { + result = widget.frameBuilder!(context, result, _frameNumber, _wasSynchronouslyLoaded); + } + + if (widget.loadingBuilder != null) { + result = widget.loadingBuilder!(context, result, _loadingProgress); + } + + return result; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DiagnosticsProperty<ImageStream>('stream', _imageStream)); + description.add(DiagnosticsProperty<ImageInfo>('pixels', _imageInfo)); + description.add(DiagnosticsProperty<ImageChunkEvent>('loadingProgress', _loadingProgress)); + description.add(DiagnosticsProperty<int>('frameNumber', _frameNumber)); + description.add(DiagnosticsProperty<bool>('wasSynchronouslyLoaded', _wasSynchronouslyLoaded)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/image_filter.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/image_filter.dart new file mode 100644 index 0000000000000000000000000000000000000000..ada948a6ae47c200f06f7aaa09199e8b579b968e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/image_filter.dart @@ -0,0 +1,109 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; + +/// Applies an [ImageFilter] to its child. +/// +/// An image filter will always apply its filter operation to the child widget, +/// even if said filter is conceptually a "no-op", such as an ImageFilter.blur +/// with a radius of 0 or an ImageFilter.matrix with an identity matrix. Setting +/// [ImageFiltered.enabled] to `false` is a more efficient manner of disabling +/// an image filter. +/// +/// The framework does not attempt to optimize out "no-op" filters because it +/// cannot tell the difference between an intentional no-op and a filter that is +/// only incidentally a no-op. Consider an ImageFilter.matrix that is animated +/// and happens to pass through the identity matrix. If the framework identified it +/// as a no-op it would drop and then recreate the layer during the animation which +/// would be more expensive than keeping it around. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=7Lftorq4i2o} +/// +/// See also: +/// +/// * [BackdropFilter], which applies an [ImageFilter] to everything +/// beneath its child. +/// * [ColorFiltered], which applies a [ColorFilter] to its child. +@immutable +class ImageFiltered extends SingleChildRenderObjectWidget { + /// Creates a widget that applies an [ImageFilter] to its child. + const ImageFiltered({ + super.key, + required this.imageFilter, + super.child, + this.enabled = true, + }); + + /// The image filter to apply to the child of this widget. + final ImageFilter imageFilter; + + /// Whether or not to apply the image filter operation to the child of this + /// widget. + /// + /// Prefer setting enabled to `false` instead of creating a "no-op" filter + /// type for performance reasons. + final bool enabled; + + @override + RenderObject createRenderObject(BuildContext context) => _ImageFilterRenderObject(imageFilter, enabled); + + @override + void updateRenderObject(BuildContext context, RenderObject renderObject) { + (renderObject as _ImageFilterRenderObject) + ..enabled = enabled + ..imageFilter = imageFilter; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ImageFilter>('imageFilter', imageFilter)); + } +} + +class _ImageFilterRenderObject extends RenderProxyBox { + _ImageFilterRenderObject(this._imageFilter, this._enabled); + + bool get enabled => _enabled; + bool _enabled; + set enabled(bool value) { + if (enabled == value) { + return; + } + final bool wasRepaintBoundary = isRepaintBoundary; + _enabled = value; + if (isRepaintBoundary != wasRepaintBoundary) { + markNeedsCompositingBitsUpdate(); + } + markNeedsPaint(); + } + + ImageFilter get imageFilter => _imageFilter; + ImageFilter _imageFilter; + set imageFilter(ImageFilter value) { + if (value != _imageFilter) { + _imageFilter = value; + markNeedsCompositedLayerUpdate(); + } + } + + @override + bool get alwaysNeedsCompositing => child != null && enabled; + + @override + bool get isRepaintBoundary => alwaysNeedsCompositing; + + @override + OffsetLayer updateCompositedLayer({required covariant ImageFilterLayer? oldLayer}) { + final ImageFilterLayer layer = oldLayer ?? ImageFilterLayer(); + layer.imageFilter = imageFilter; + return layer; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/image_icon.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/image_icon.dart new file mode 100644 index 0000000000000000000000000000000000000000..af19497f18f1c97c2d9ee038a0305e3fc71d3604 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/image_icon.dart @@ -0,0 +1,106 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'icon.dart'; +import 'icon_theme.dart'; +import 'icon_theme_data.dart'; +import 'image.dart'; + +/// An icon that comes from an [ImageProvider], e.g. an [AssetImage]. +/// +/// See also: +/// +/// * [IconButton], for interactive icons. +/// * [IconTheme], which provides ambient configuration for icons. +/// * [Icon], for icons based on glyphs from fonts instead of images. +/// * [Icons], the library of Material Icons. +class ImageIcon extends StatelessWidget { + /// Creates an image icon. + /// + /// The [size] and [color] default to the value given by the current [IconTheme]. + const ImageIcon( + this.image, { + super.key, + this.size, + this.color, + this.semanticLabel, + }); + + /// The image to display as the icon. + /// + /// The icon can be null, in which case the widget will render as an empty + /// space of the specified [size]. + final ImageProvider? image; + + /// The size of the icon in logical pixels. + /// + /// Icons occupy a square with width and height equal to size. + /// + /// Defaults to the current [IconTheme] size, if any. If there is no + /// [IconTheme], or it does not specify an explicit size, then it defaults to + /// 24.0. + final double? size; + + /// The color to use when drawing the icon. + /// + /// Defaults to the current [IconTheme] color, if any. If there is + /// no [IconTheme], then it defaults to not recolorizing the image. + /// + /// The image will be additionally adjusted by the opacity of the current + /// [IconTheme], if any. + final Color? color; + + /// Semantic label for the icon. + /// + /// Announced in accessibility modes (e.g TalkBack/VoiceOver). + /// This label does not show in the UI. + /// + /// * [SemanticsProperties.label], which is set to [semanticLabel] in the + /// underlying [Semantics] widget. + final String? semanticLabel; + + @override + Widget build(BuildContext context) { + final IconThemeData iconTheme = IconTheme.of(context); + final double? iconSize = size ?? iconTheme.size; + + if (image == null) { + return Semantics( + label: semanticLabel, + child: SizedBox(width: iconSize, height: iconSize), + ); + } + + final double? iconOpacity = iconTheme.opacity; + Color iconColor = color ?? iconTheme.color!; + + if (iconOpacity != null && iconOpacity != 1.0) { + iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity); + } + + return Semantics( + label: semanticLabel, + child: Image( + image: image!, + width: iconSize, + height: iconSize, + color: iconColor, + fit: BoxFit.scaleDown, + excludeFromSemantics: true, + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ImageProvider>('image', image, ifNull: '<empty>', showName: false)); + properties.add(DoubleProperty('size', size, defaultValue: null)); + properties.add(ColorProperty('color', color, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/implicit_animations.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/implicit_animations.dart new file mode 100644 index 0000000000000000000000000000000000000000..20fec44e0b792628b1645d87c38d22efda517e47 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -0,0 +1,2196 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show TextHeightBehavior; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'basic.dart'; +import 'container.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'text.dart'; +import 'ticker_provider.dart'; +import 'transitions.dart'; + +// Examples can assume: +// class MyWidget extends ImplicitlyAnimatedWidget { +// const MyWidget({super.key, this.targetColor = Colors.black}) : super(duration: const Duration(seconds: 1)); +// final Color targetColor; +// @override +// ImplicitlyAnimatedWidgetState<MyWidget> createState() => throw UnimplementedError(); // ignore: no_logic_in_create_state +// } +// void setState(VoidCallback fn) { } + +/// An interpolation between two [BoxConstraints]. +/// +/// This class specializes the interpolation of [Tween<BoxConstraints>] to use +/// [BoxConstraints.lerp]. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class BoxConstraintsTween extends Tween<BoxConstraints> { + /// Creates a [BoxConstraints] tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as a tight constraint of zero size. + BoxConstraintsTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + BoxConstraints lerp(double t) => BoxConstraints.lerp(begin, end, t)!; +} + +/// An interpolation between two [Decoration]s. +/// +/// This class specializes the interpolation of [Tween<BoxConstraints>] to use +/// [Decoration.lerp]. +/// +/// For [ShapeDecoration]s which know how to [ShapeDecoration.lerpTo] or +/// [ShapeDecoration.lerpFrom] each other, this will produce a smooth +/// interpolation between decorations. +/// +/// See also: +/// +/// * [Tween] for a discussion on how to use interpolation objects. +/// * [ShapeDecoration], [RoundedRectangleBorder], [CircleBorder], and +/// [StadiumBorder] for examples of shape borders that can be smoothly +/// interpolated. +/// * [BoxBorder] for a border that can only be smoothly interpolated between other +/// [BoxBorder]s. +class DecorationTween extends Tween<Decoration> { + /// Creates a decoration tween. + /// + /// The [begin] and [end] properties may be null. If both are null, then the + /// result is always null. If [end] is not null, then its lerping logic is + /// used (via [Decoration.lerpTo]). Otherwise, [begin]'s lerping logic is used + /// (via [Decoration.lerpFrom]). + DecorationTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + Decoration lerp(double t) => Decoration.lerp(begin, end, t)!; +} + +/// An interpolation between two [EdgeInsets]s. +/// +/// This class specializes the interpolation of [Tween<EdgeInsets>] to use +/// [EdgeInsets.lerp]. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +/// +/// See also: +/// +/// * [EdgeInsetsGeometryTween], which interpolates between two +/// [EdgeInsetsGeometry] objects. +class EdgeInsetsTween extends Tween<EdgeInsets> { + /// Creates an [EdgeInsets] tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as an [EdgeInsets] with no inset. + EdgeInsetsTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + EdgeInsets lerp(double t) => EdgeInsets.lerp(begin, end, t)!; +} + +/// An interpolation between two [EdgeInsetsGeometry]s. +/// +/// This class specializes the interpolation of [Tween<EdgeInsetsGeometry>] to +/// use [EdgeInsetsGeometry.lerp]. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +/// +/// See also: +/// +/// * [EdgeInsetsTween], which interpolates between two [EdgeInsets] objects. +class EdgeInsetsGeometryTween extends Tween<EdgeInsetsGeometry> { + /// Creates an [EdgeInsetsGeometry] tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as an [EdgeInsetsGeometry] with no inset. + EdgeInsetsGeometryTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + EdgeInsetsGeometry lerp(double t) => EdgeInsetsGeometry.lerp(begin, end, t)!; +} + +/// An interpolation between two [BorderRadius]s. +/// +/// This class specializes the interpolation of [Tween<BorderRadius>] to use +/// [BorderRadius.lerp]. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class BorderRadiusTween extends Tween<BorderRadius?> { + /// Creates a [BorderRadius] tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as a right angle (no radius). + BorderRadiusTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + BorderRadius? lerp(double t) => BorderRadius.lerp(begin, end, t); +} + +/// An interpolation between two [Border]s. +/// +/// This class specializes the interpolation of [Tween<Border>] to use +/// [Border.lerp]. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class BorderTween extends Tween<Border?> { + /// Creates a [Border] tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as having no border. + BorderTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + Border? lerp(double t) => Border.lerp(begin, end, t); +} + +/// An interpolation between two [Matrix4]s. +/// +/// This class specializes the interpolation of [Tween<Matrix4>] to be +/// appropriate for transformation matrices. +/// +/// Currently this class works only for translations. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class Matrix4Tween extends Tween<Matrix4> { + /// Creates a [Matrix4] tween. + /// + /// The [begin] and [end] properties must be non-null before the tween is + /// first used, but the arguments can be null if the values are going to be + /// filled in later. + Matrix4Tween({ super.begin, super.end }); + + @override + Matrix4 lerp(double t) { + assert(begin != null); + assert(end != null); + final Vector3 beginTranslation = Vector3.zero(); + final Vector3 endTranslation = Vector3.zero(); + final Quaternion beginRotation = Quaternion.identity(); + final Quaternion endRotation = Quaternion.identity(); + final Vector3 beginScale = Vector3.zero(); + final Vector3 endScale = Vector3.zero(); + begin!.decompose(beginTranslation, beginRotation, beginScale); + end!.decompose(endTranslation, endRotation, endScale); + final Vector3 lerpTranslation = + beginTranslation * (1.0 - t) + endTranslation * t; + // TODO(alangardner): Implement lerp for constant rotation + final Quaternion lerpRotation = + (beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized(); + final Vector3 lerpScale = beginScale * (1.0 - t) + endScale * t; + return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale); + } +} + +/// An interpolation between two [TextStyle]s. +/// +/// This class specializes the interpolation of [Tween<TextStyle>] to use +/// [TextStyle.lerp]. +/// +/// This will not work well if the styles don't set the same fields. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class TextStyleTween extends Tween<TextStyle> { + /// Creates a text style tween. + /// + /// The [begin] and [end] properties must be non-null before the tween is + /// first used, but the arguments can be null if the values are going to be + /// filled in later. + TextStyleTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + TextStyle lerp(double t) => TextStyle.lerp(begin, end, t)!; +} + +/// An abstract class for building widgets that animate changes to their +/// properties. +/// +/// Widgets of this type will not animate when they are first added to the +/// widget tree. Rather, when they are rebuilt with different values, they will +/// respond to those _changes_ by animating the changes over a specified +/// [duration]. +/// +/// Which properties are animated is left up to the subclass. Subclasses' [State]s +/// must extend [ImplicitlyAnimatedWidgetState] and provide a way to visit the +/// relevant fields to animate. +/// +/// ## Relationship to [AnimatedWidget]s +/// +/// [ImplicitlyAnimatedWidget]s (and their subclasses) automatically animate +/// changes in their properties whenever they change. For this, +/// they create and manage their own internal [AnimationController]s to power +/// the animation. While these widgets are simple to use and don't require you +/// to manually manage the lifecycle of an [AnimationController], they +/// are also somewhat limited: Besides the target value for the animated +/// property, developers can only choose a [duration] and [curve] for the +/// animation. If you require more control over the animation (e.g. you want +/// to stop it somewhere in the middle), consider using an +/// [AnimatedWidget] or one of its subclasses. These widgets take an [Animation] +/// as an argument to power the animation. This gives the developer full control +/// over the animation at the cost of requiring you to manually manage the +/// underlying [AnimationController]. +/// +/// ## Common implicitly animated widgets +/// +/// A number of implicitly animated widgets ship with the framework. They are +/// usually named `AnimatedFoo`, where `Foo` is the name of the non-animated +/// version of that widget. Commonly used implicitly animated widgets include: +/// +/// * [TweenAnimationBuilder], which animates any property expressed by +/// a [Tween] to a specified target value. +/// * [AnimatedAlign], which is an implicitly animated version of [Align]. +/// * [AnimatedContainer], which is an implicitly animated version of +/// [Container]. +/// * [AnimatedDefaultTextStyle], which is an implicitly animated version of +/// [DefaultTextStyle]. +/// * [AnimatedScale], which is an implicitly animated version of [Transform.scale]. +/// * [AnimatedRotation], which is an implicitly animated version of [Transform.rotate]. +/// * [AnimatedSlide], which implicitly animates the position of a widget relative to its normal position. +/// * [AnimatedOpacity], which is an implicitly animated version of [Opacity]. +/// * [AnimatedPadding], which is an implicitly animated version of [Padding]. +/// * [AnimatedPhysicalModel], which is an implicitly animated version of +/// [PhysicalModel]. +/// * [AnimatedPositioned], which is an implicitly animated version of +/// [Positioned]. +/// * [AnimatedPositionedDirectional], which is an implicitly animated version +/// of [PositionedDirectional]. +/// * [AnimatedTheme], which is an implicitly animated version of [Theme]. +/// * [AnimatedCrossFade], which cross-fades between two given children and +/// animates itself between their sizes. +/// * [AnimatedSize], which automatically transitions its size over a given +/// duration. +/// * [AnimatedSwitcher], which fades from one widget to another. +abstract class ImplicitlyAnimatedWidget extends StatefulWidget { + /// Initializes fields for subclasses. + const ImplicitlyAnimatedWidget({ + super.key, + this.curve = Curves.linear, + required this.duration, + this.onEnd, + }); + + /// The curve to apply when animating the parameters of this container. + final Curve curve; + + /// The duration over which to animate the parameters of this container. + final Duration duration; + + /// Called every time an animation completes. + /// + /// This can be useful to trigger additional actions (e.g. another animation) + /// at the end of the current animation. + final VoidCallback? onEnd; + + @override + ImplicitlyAnimatedWidgetState<ImplicitlyAnimatedWidget> createState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('duration', duration.inMilliseconds, unit: 'ms')); + } +} + +/// Signature for a [Tween] factory. +/// +/// This is the type of one of the arguments of [TweenVisitor], the signature +/// used by [AnimatedWidgetBaseState.forEachTween]. +/// +/// Instances of this function are expected to take a value and return a tween +/// beginning at that value. +typedef TweenConstructor<T extends Object> = Tween<T> Function(T targetValue); + +/// Signature for callbacks passed to [ImplicitlyAnimatedWidgetState.forEachTween]. +/// +/// {@template flutter.widgets.TweenVisitor.arguments} +/// The `tween` argument should contain the current tween value. This will +/// initially be null when the state is first initialized. +/// +/// The `targetValue` argument should contain the value toward which the state +/// is animating. For instance, if the state is animating its widget's +/// opacity value, then this argument should contain the widget's current +/// opacity value. +/// +/// The `constructor` argument should contain a function that takes a value +/// (the widget's value being animated) and returns a tween beginning at that +/// value. +/// +/// {@endtemplate} +/// +/// `forEachTween()` is expected to update its tween value to the return value +/// of this visitor. +/// +/// The `<T>` parameter specifies the type of value that's being animated. +typedef TweenVisitor<T extends Object> = Tween<T>? Function(Tween<T>? tween, T targetValue, TweenConstructor<T> constructor); + +/// A base class for the `State` of widgets with implicit animations. +/// +/// [ImplicitlyAnimatedWidgetState] requires that subclasses respond to the +/// animation themselves. If you would like `setState()` to be called +/// automatically as the animation changes, use [AnimatedWidgetBaseState]. +/// +/// Properties that subclasses choose to animate are represented by [Tween] +/// instances. Subclasses must implement the [forEachTween] method to allow +/// [ImplicitlyAnimatedWidgetState] to iterate through the widget's fields and +/// animate them. +abstract class ImplicitlyAnimatedWidgetState<T extends ImplicitlyAnimatedWidget> extends State<T> with SingleTickerProviderStateMixin<T> { + /// The animation controller driving this widget's implicit animations. + @protected + AnimationController get controller => _controller; + late final AnimationController _controller = AnimationController( + duration: widget.duration, + debugLabel: kDebugMode ? widget.toStringShort() : null, + vsync: this, + ); + + /// The animation driving this widget's implicit animations. + Animation<double> get animation => _animation; + late CurvedAnimation _animation = _createCurve(); + + @override + void initState() { + super.initState(); + _controller.addStatusListener((AnimationStatus status) { + switch (status) { + case AnimationStatus.completed: + widget.onEnd?.call(); + case AnimationStatus.dismissed: + case AnimationStatus.forward: + case AnimationStatus.reverse: + } + }); + _constructTweens(); + didUpdateTweens(); + } + + @override + void didUpdateWidget(T oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.curve != oldWidget.curve) { + _animation.dispose(); + _animation = _createCurve(); + } + _controller.duration = widget.duration; + if (_constructTweens()) { + forEachTween((Tween<dynamic>? tween, dynamic targetValue, TweenConstructor<dynamic> constructor) { + _updateTween(tween, targetValue); + return tween; + }); + _controller + ..value = 0.0 + ..forward(); + didUpdateTweens(); + } + } + + CurvedAnimation _createCurve() { + return CurvedAnimation(parent: _controller, curve: widget.curve); + } + + @override + void dispose() { + _animation.dispose(); + _controller.dispose(); + super.dispose(); + } + + bool _shouldAnimateTween(Tween<dynamic> tween, dynamic targetValue) { + return targetValue != (tween.end ?? tween.begin); + } + + void _updateTween(Tween<dynamic>? tween, dynamic targetValue) { + if (tween == null) { + return; + } + tween + ..begin = tween.evaluate(_animation) + ..end = targetValue; + } + + bool _constructTweens() { + bool shouldStartAnimation = false; + forEachTween((Tween<dynamic>? tween, dynamic targetValue, TweenConstructor<dynamic> constructor) { + if (targetValue != null) { + tween ??= constructor(targetValue); + if (_shouldAnimateTween(tween, targetValue)) { + shouldStartAnimation = true; + } else { + tween.end ??= tween.begin; + } + } else { + tween = null; + } + return tween; + }); + return shouldStartAnimation; + } + + /// Visits each tween controlled by this state with the specified `visitor` + /// function. + /// + /// ### Subclass responsibility + /// + /// Properties to be animated are represented by [Tween] member variables in + /// the state. For each such tween, [forEachTween] implementations are + /// expected to call `visitor` with the appropriate arguments and store the + /// result back into the member variable. The arguments to `visitor` are as + /// follows: + /// + /// {@macro flutter.widgets.TweenVisitor.arguments} + /// + /// ### When this method will be called + /// + /// [forEachTween] is initially called during [initState]. It is expected that + /// the visitor's `tween` argument will be set to null, causing the visitor to + /// call its `constructor` argument to construct the tween for the first time. + /// The resulting tween will have its `begin` value set to the target value + /// and will have its `end` value set to null. The animation will not be + /// started. + /// + /// When this state's [widget] is updated (thus triggering the + /// [didUpdateWidget] method to be called), [forEachTween] will be called + /// again to check if the target value has changed. If the target value has + /// changed, signaling that the [animation] should start, then the visitor + /// will update the tween's `start` and `end` values accordingly, and the + /// animation will be started. + /// + /// ### Other member variables + /// + /// Subclasses that contain properties based on tweens created by + /// [forEachTween] should override [didUpdateTweens] to update those + /// properties. Dependent properties should not be updated within + /// [forEachTween]. + /// + /// {@tool snippet} + /// + /// This sample implements an implicitly animated widget's `State`. + /// The widget animates between colors whenever `widget.targetColor` + /// changes. + /// + /// ```dart + /// class MyWidgetState extends AnimatedWidgetBaseState<MyWidget> { + /// ColorTween? _colorTween; + /// + /// @override + /// Widget build(BuildContext context) { + /// return Text( + /// 'Hello World', + /// // Computes the value of the text color at any given time. + /// style: TextStyle(color: _colorTween?.evaluate(animation)), + /// ); + /// } + /// + /// @override + /// void forEachTween(TweenVisitor<dynamic> visitor) { + /// // Update the tween using the provided visitor function. + /// _colorTween = visitor( + /// // The latest tween value. Can be `null`. + /// _colorTween, + /// // The color value toward which we are animating. + /// widget.targetColor, + /// // A function that takes a color value and returns a tween + /// // beginning at that value. + /// (dynamic value) => ColorTween(begin: value as Color?), + /// ) as ColorTween?; + /// + /// // We could have more tweens than one by using the visitor + /// // multiple times. + /// } + /// } + /// ``` + /// {@end-tool} + @protected + void forEachTween(TweenVisitor<dynamic> visitor); + + /// Optional hook for subclasses that runs after all tweens have been updated + /// via [forEachTween]. + /// + /// Any properties that depend upon tweens created by [forEachTween] should be + /// updated within [didUpdateTweens], not within [forEachTween]. + /// + /// This method will be called both: + /// + /// 1. After the tweens are _initially_ constructed (by + /// the `constructor` argument to the [TweenVisitor] that's passed to + /// [forEachTween]). In this case, the tweens are likely to contain only + /// a [Tween.begin] value and not a [Tween.end]. + /// + /// 2. When the state's [widget] is updated, and one or more of the tweens + /// visited by [forEachTween] specifies a target value that's different + /// than the widget's current value, thus signaling that the [animation] + /// should run. In this case, the [Tween.begin] value for each tween will + /// an evaluation of the tween against the current [animation], and the + /// [Tween.end] value for each tween will be the target value. + @protected + void didUpdateTweens() { } +} + +/// A base class for widgets with implicit animations that need to rebuild their +/// widget tree as the animation runs. +/// +/// This class calls [build] each frame that the animation ticks. For a +/// variant that does not rebuild each frame, consider subclassing +/// [ImplicitlyAnimatedWidgetState] directly. +/// +/// Subclasses must implement the [forEachTween] method to allow +/// [AnimatedWidgetBaseState] to iterate through the subclasses' widget's fields +/// and animate them. +abstract class AnimatedWidgetBaseState<T extends ImplicitlyAnimatedWidget> extends ImplicitlyAnimatedWidgetState<T> { + @override + void initState() { + super.initState(); + controller.addListener(_handleAnimationChanged); + } + + void _handleAnimationChanged() { + setState(() { /* The animation ticked. Rebuild with new animation value */ }); + } +} + +/// Animated version of [Container] that gradually changes its values over a period of time. +/// +/// The [AnimatedContainer] will automatically animate between the old and +/// new values of properties when they change using the provided curve and +/// duration. Properties that are null are not animated. Its child and +/// descendants are not animated. +/// +/// This class is useful for generating simple implicit transitions between +/// different parameters to [Container] with its internal [AnimationController]. +/// For more complex animations, you'll likely want to use a subclass of +/// [AnimatedWidget] such as the [DecoratedBoxTransition] or use your own +/// [AnimationController]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=yI-8QHpGIP4} +/// +/// {@tool dartpad} +/// The following example (depicted above) transitions an AnimatedContainer +/// between two states. It adjusts the `height`, `width`, `color`, and +/// [alignment] properties when tapped. +/// +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_container.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedPadding], which is a subset of this widget that only +/// supports animating the [padding]. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +/// * [AnimatedPositioned], which, as a child of a [Stack], automatically +/// transitions its child's position over a given duration whenever the given +/// position changes. +/// * [AnimatedAlign], which automatically transitions its child's +/// position over a given duration whenever the given [AnimatedAlign.alignment] changes. +/// * [AnimatedSwitcher], which switches out a child for a new one with a customizable transition. +/// * [AnimatedCrossFade], which fades between two children and interpolates their sizes. +class AnimatedContainer extends ImplicitlyAnimatedWidget { + /// Creates a container that animates its parameters implicitly. + AnimatedContainer({ + super.key, + this.alignment, + this.padding, + Color? color, + Decoration? decoration, + this.foregroundDecoration, + double? width, + double? height, + BoxConstraints? constraints, + this.margin, + this.transform, + this.transformAlignment, + this.child, + this.clipBehavior = Clip.none, + super.curve, + required super.duration, + super.onEnd, + }) : assert(margin == null || margin.isNonNegative), + assert(padding == null || padding.isNonNegative), + assert(decoration == null || decoration.debugAssertIsValid()), + assert(constraints == null || constraints.debugAssertIsValid()), + assert(color == null || decoration == null, + 'Cannot provide both a color and a decoration\n' + 'The color argument is just a shorthand for "decoration: BoxDecoration(color: color)".', + ), + decoration = decoration ?? (color != null ? BoxDecoration(color: color) : null), + constraints = + (width != null || height != null) + ? constraints?.tighten(width: width, height: height) + ?? BoxConstraints.tightFor(width: width, height: height) + : constraints; + + /// The [child] contained by the container. + /// + /// If null, and if the [constraints] are unbounded or also null, the + /// container will expand to fill all available space in its parent, unless + /// the parent provides unbounded constraints, in which case the container + /// will attempt to be as small as possible. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// Align the [child] within the container. + /// + /// If non-null, the container will expand to fill its parent and position its + /// child within itself according to the given value. If the incoming + /// constraints are unbounded, then the child will be shrink-wrapped instead. + /// + /// Ignored if [child] is null. + /// + /// See also: + /// + /// * [Alignment], a class with convenient constants typically used to + /// specify an [AlignmentGeometry]. + /// * [AlignmentDirectional], like [Alignment] for specifying alignments + /// relative to text direction. + final AlignmentGeometry? alignment; + + /// Empty space to inscribe inside the [decoration]. The [child], if any, is + /// placed inside this padding. + final EdgeInsetsGeometry? padding; + + /// The decoration to paint behind the [child]. + /// + /// A shorthand for specifying just a solid color is available in the + /// constructor: set the `color` argument instead of the `decoration` + /// argument. + final Decoration? decoration; + + /// The decoration to paint in front of the child. + final Decoration? foregroundDecoration; + + /// Additional constraints to apply to the child. + /// + /// The constructor `width` and `height` arguments are combined with the + /// `constraints` argument to set this property. + /// + /// The [padding] goes inside the constraints. + final BoxConstraints? constraints; + + /// Empty space to surround the [decoration] and [child]. + final EdgeInsetsGeometry? margin; + + /// The transformation matrix to apply before painting the container. + final Matrix4? transform; + + /// The alignment of the origin, relative to the size of the container, if [transform] is specified. + /// + /// When [transform] is null, the value of this property is ignored. + /// + /// See also: + /// + /// * [Transform.alignment], which is set by this property. + final AlignmentGeometry? transformAlignment; + + /// The clip behavior when [AnimatedContainer.decoration] is not null. + /// + /// Defaults to [Clip.none]. Must be [Clip.none] if [decoration] is null. + /// + /// Unlike other properties of [AnimatedContainer], changes to this property + /// apply immediately and have no animation. + /// + /// If a clip is to be applied, the [Decoration.getClipPath] method + /// for the provided decoration must return a clip path. (This is not + /// supported by all decorations; the default implementation of that + /// method throws an [UnsupportedError].) + final Clip clipBehavior; + + @override + AnimatedWidgetBaseState<AnimatedContainer> createState() => _AnimatedContainerState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, showName: false, defaultValue: null)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + properties.add(DiagnosticsProperty<Decoration>('bg', decoration, defaultValue: null)); + properties.add(DiagnosticsProperty<Decoration>('fg', foregroundDecoration, defaultValue: null)); + properties.add(DiagnosticsProperty<BoxConstraints>('constraints', constraints, defaultValue: null, showName: false)); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('margin', margin, defaultValue: null)); + properties.add(ObjectFlagProperty<Matrix4>.has('transform', transform)); + properties.add(DiagnosticsProperty<AlignmentGeometry>('transformAlignment', transformAlignment, defaultValue: null)); + properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior)); + } +} + +class _AnimatedContainerState extends AnimatedWidgetBaseState<AnimatedContainer> { + AlignmentGeometryTween? _alignment; + EdgeInsetsGeometryTween? _padding; + DecorationTween? _decoration; + DecorationTween? _foregroundDecoration; + BoxConstraintsTween? _constraints; + EdgeInsetsGeometryTween? _margin; + Matrix4Tween? _transform; + AlignmentGeometryTween? _transformAlignment; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _alignment = visitor(_alignment, widget.alignment, (dynamic value) => AlignmentGeometryTween(begin: value as AlignmentGeometry)) as AlignmentGeometryTween?; + _padding = visitor(_padding, widget.padding, (dynamic value) => EdgeInsetsGeometryTween(begin: value as EdgeInsetsGeometry)) as EdgeInsetsGeometryTween?; + _decoration = visitor(_decoration, widget.decoration, (dynamic value) => DecorationTween(begin: value as Decoration)) as DecorationTween?; + _foregroundDecoration = visitor(_foregroundDecoration, widget.foregroundDecoration, (dynamic value) => DecorationTween(begin: value as Decoration)) as DecorationTween?; + _constraints = visitor(_constraints, widget.constraints, (dynamic value) => BoxConstraintsTween(begin: value as BoxConstraints)) as BoxConstraintsTween?; + _margin = visitor(_margin, widget.margin, (dynamic value) => EdgeInsetsGeometryTween(begin: value as EdgeInsetsGeometry)) as EdgeInsetsGeometryTween?; + _transform = visitor(_transform, widget.transform, (dynamic value) => Matrix4Tween(begin: value as Matrix4)) as Matrix4Tween?; + _transformAlignment = visitor(_transformAlignment, widget.transformAlignment, (dynamic value) => AlignmentGeometryTween(begin: value as AlignmentGeometry)) as AlignmentGeometryTween?; + } + + @override + Widget build(BuildContext context) { + final Animation<double> animation = this.animation; + return Container( + alignment: _alignment?.evaluate(animation), + padding: _padding?.evaluate(animation), + decoration: _decoration?.evaluate(animation), + foregroundDecoration: _foregroundDecoration?.evaluate(animation), + constraints: _constraints?.evaluate(animation), + margin: _margin?.evaluate(animation), + transform: _transform?.evaluate(animation), + transformAlignment: _transformAlignment?.evaluate(animation), + clipBehavior: widget.clipBehavior, + child: widget.child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DiagnosticsProperty<AlignmentGeometryTween>('alignment', _alignment, showName: false, defaultValue: null)); + description.add(DiagnosticsProperty<EdgeInsetsGeometryTween>('padding', _padding, defaultValue: null)); + description.add(DiagnosticsProperty<DecorationTween>('bg', _decoration, defaultValue: null)); + description.add(DiagnosticsProperty<DecorationTween>('fg', _foregroundDecoration, defaultValue: null)); + description.add(DiagnosticsProperty<BoxConstraintsTween>('constraints', _constraints, showName: false, defaultValue: null)); + description.add(DiagnosticsProperty<EdgeInsetsGeometryTween>('margin', _margin, defaultValue: null)); + description.add(ObjectFlagProperty<Matrix4Tween>.has('transform', _transform)); + description.add(DiagnosticsProperty<AlignmentGeometryTween>('transformAlignment', _transformAlignment, defaultValue: null)); + } +} + +/// Animated version of [Padding] which automatically transitions the +/// indentation over a given duration whenever the given inset changes. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=PY2m0fhGNz4} +/// +/// Here's an illustration of what using this widget looks like, using a [curve] +/// of [Curves.fastOutSlowIn]. +/// {@animation 250 266 https://flutter.github.io/assets-for-api-docs/assets/widgets/animated_padding.mp4} +/// +/// {@tool dartpad} +/// The following code implements the [AnimatedPadding] widget, using a [curve] of +/// [Curves.easeInOut]. +/// +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_padding.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedContainer], which can transition more values at once. +/// * [AnimatedAlign], which automatically transitions its child's +/// position over a given duration whenever the given +/// [AnimatedAlign.alignment] changes. +class AnimatedPadding extends ImplicitlyAnimatedWidget { + /// Creates a widget that insets its child by a value that animates + /// implicitly. + AnimatedPadding({ + super.key, + required this.padding, + this.child, + super.curve, + required super.duration, + super.onEnd, + }) : assert(padding.isNonNegative); + + /// The amount of space by which to inset the child. + final EdgeInsetsGeometry padding; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + @override + AnimatedWidgetBaseState<AnimatedPadding> createState() => _AnimatedPaddingState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding)); + } +} + +class _AnimatedPaddingState extends AnimatedWidgetBaseState<AnimatedPadding> { + EdgeInsetsGeometryTween? _padding; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _padding = visitor(_padding, widget.padding, (dynamic value) => EdgeInsetsGeometryTween(begin: value as EdgeInsetsGeometry)) as EdgeInsetsGeometryTween?; + } + + @override + Widget build(BuildContext context) { + return Padding( + padding: _padding! + .evaluate(animation) + .clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity), + child: widget.child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DiagnosticsProperty<EdgeInsetsGeometryTween>('padding', _padding, defaultValue: null)); + } +} + +/// Animated version of [Align] which automatically transitions the child's +/// position over a given duration whenever the given [alignment] changes. +/// +/// Here's an illustration of what this can look like, using a [curve] of +/// [Curves.fastOutSlowIn]. +/// {@animation 250 266 https://flutter.github.io/assets-for-api-docs/assets/widgets/animated_align.mp4} +/// +/// For the animation, you can choose a [curve] as well as a [duration] and the +/// widget will automatically animate to the new target [alignment]. If you require +/// more control over the animation (e.g. if you want to stop it mid-animation), +/// consider using an [AlignTransition] instead, which takes a provided +/// [Animation] as argument. While that allows you to fine-tune the animation, +/// it also requires more development overhead as you have to manually manage +/// the lifecycle of the underlying [AnimationController]. +/// +/// {@tool dartpad} +/// The following code implements the [AnimatedAlign] widget, using a [curve] of +/// [Curves.fastOutSlowIn]. +/// +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_align.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedContainer], which can transition more values at once. +/// * [AnimatedPadding], which can animate the padding instead of the +/// alignment. +/// * [AnimatedSlide], which can animate the translation of child by a given offset relative to its size. +/// * [AnimatedPositioned], which, as a child of a [Stack], automatically +/// transitions its child's position over a given duration whenever the given +/// position changes. +class AnimatedAlign extends ImplicitlyAnimatedWidget { + /// Creates a widget that positions its child by an alignment that animates + /// implicitly. + const AnimatedAlign({ + super.key, + required this.alignment, + this.child, + this.heightFactor, + this.widthFactor, + super.curve, + required super.duration, + super.onEnd, + }) : assert(widthFactor == null || widthFactor >= 0.0), + assert(heightFactor == null || heightFactor >= 0.0); + + /// How to align the child. + /// + /// The x and y values of the [Alignment] control the horizontal and vertical + /// alignment, respectively. An x value of -1.0 means that the left edge of + /// the child is aligned with the left edge of the parent whereas an x value + /// of 1.0 means that the right edge of the child is aligned with the right + /// edge of the parent. Other values interpolate (and extrapolate) linearly. + /// For example, a value of 0.0 means that the center of the child is aligned + /// with the center of the parent. + /// + /// See also: + /// + /// * [Alignment], which has more details and some convenience constants for + /// common positions. + /// * [AlignmentDirectional], which has a horizontal coordinate orientation + /// that depends on the [TextDirection]. + final AlignmentGeometry alignment; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// If non-null, sets its height to the child's height multiplied by this factor. + /// + /// Must be greater than or equal to 0.0, defaults to null. + final double? heightFactor; + + /// If non-null, sets its width to the child's width multiplied by this factor. + /// + /// Must be greater than or equal to 0.0, defaults to null. + final double? widthFactor; + + @override + AnimatedWidgetBaseState<AnimatedAlign> createState() => _AnimatedAlignState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + } +} + +class _AnimatedAlignState extends AnimatedWidgetBaseState<AnimatedAlign> { + AlignmentGeometryTween? _alignment; + Tween<double>? _heightFactorTween; + Tween<double>? _widthFactorTween; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _alignment = visitor(_alignment, widget.alignment, (dynamic value) => AlignmentGeometryTween(begin: value as AlignmentGeometry)) as AlignmentGeometryTween?; + if (widget.heightFactor != null) { + _heightFactorTween = visitor(_heightFactorTween, widget.heightFactor, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + } + if (widget.widthFactor != null) { + _widthFactorTween = visitor(_widthFactorTween, widget.widthFactor, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + } + } + + @override + Widget build(BuildContext context) { + return Align( + alignment: _alignment!.evaluate(animation)!, + heightFactor: _heightFactorTween?.evaluate(animation), + widthFactor: _widthFactorTween?.evaluate(animation), + child: widget.child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DiagnosticsProperty<AlignmentGeometryTween>('alignment', _alignment, defaultValue: null)); + description.add(DiagnosticsProperty<Tween<double>>('widthFactor', _widthFactorTween, defaultValue: null)); + description.add(DiagnosticsProperty<Tween<double>>('heightFactor', _heightFactorTween, defaultValue: null)); + } +} + +/// Animated version of [Positioned] which automatically transitions the child's +/// position over a given duration whenever the given position changes. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=hC3s2YdtWt8} +/// +/// Only works if it's the child of a [Stack]. +/// +/// This widget is a good choice if the _size_ of the child would end up +/// changing as a result of this animation. If the size is intended to remain +/// the same, with only the _position_ changing over time, then consider +/// [SlideTransition] instead. [SlideTransition] only triggers a repaint each +/// frame of the animation, whereas [AnimatedPositioned] will trigger a relayout +/// as well. +/// +/// Here's an illustration of what using this widget looks like, using a [curve] +/// of [Curves.fastOutSlowIn]. +/// {@animation 250 266 https://flutter.github.io/assets-for-api-docs/assets/widgets/animated_positioned.mp4} +/// +/// For the animation, you can choose a [curve] as well as a [duration] and the +/// widget will automatically animate to the new target position. If you require +/// more control over the animation (e.g. if you want to stop it mid-animation), +/// consider using a [PositionedTransition] instead, which takes a provided +/// [Animation] as an argument. While that allows you to fine-tune the animation, +/// it also requires more development overhead as you have to manually manage +/// the lifecycle of the underlying [AnimationController]. +/// +/// {@tool dartpad} +/// The following example transitions an AnimatedPositioned +/// between two states. It adjusts the `height`, `width`, and +/// [Positioned] properties when tapped. +/// +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_positioned.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedPositionedDirectional], which adapts to the ambient +/// [Directionality] (the same as this widget, but for animating +/// [PositionedDirectional]). +class AnimatedPositioned extends ImplicitlyAnimatedWidget { + /// Creates a widget that animates its position implicitly. + /// + /// Only two out of the three horizontal values ([left], [right], + /// [width]), and only two out of the three vertical values ([top], + /// [bottom], [height]), can be set. In each case, at least one of + /// the three must be null. + const AnimatedPositioned({ + super.key, + required this.child, + this.left, + this.top, + this.right, + this.bottom, + this.width, + this.height, + super.curve, + required super.duration, + super.onEnd, + }) : assert(left == null || right == null || width == null), + assert(top == null || bottom == null || height == null); + + /// Creates a widget that animates the rectangle it occupies implicitly. + AnimatedPositioned.fromRect({ + super.key, + required this.child, + required Rect rect, + super.curve, + required super.duration, + super.onEnd, + }) : left = rect.left, + top = rect.top, + width = rect.width, + height = rect.height, + right = null, + bottom = null; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The offset of the child's left edge from the left of the stack. + final double? left; + + /// The offset of the child's top edge from the top of the stack. + final double? top; + + /// The offset of the child's right edge from the right of the stack. + final double? right; + + /// The offset of the child's bottom edge from the bottom of the stack. + final double? bottom; + + /// The child's width. + /// + /// Only two out of the three horizontal values ([left], [right], [width]) can + /// be set. The third must be null. + final double? width; + + /// The child's height. + /// + /// Only two out of the three vertical values ([top], [bottom], [height]) can + /// be set. The third must be null. + final double? height; + + @override + AnimatedWidgetBaseState<AnimatedPositioned> createState() => _AnimatedPositionedState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('left', left, defaultValue: null)); + properties.add(DoubleProperty('top', top, defaultValue: null)); + properties.add(DoubleProperty('right', right, defaultValue: null)); + properties.add(DoubleProperty('bottom', bottom, defaultValue: null)); + properties.add(DoubleProperty('width', width, defaultValue: null)); + properties.add(DoubleProperty('height', height, defaultValue: null)); + } +} + +class _AnimatedPositionedState extends AnimatedWidgetBaseState<AnimatedPositioned> { + Tween<double>? _left; + Tween<double>? _top; + Tween<double>? _right; + Tween<double>? _bottom; + Tween<double>? _width; + Tween<double>? _height; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _left = visitor(_left, widget.left, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _top = visitor(_top, widget.top, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _right = visitor(_right, widget.right, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _bottom = visitor(_bottom, widget.bottom, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _width = visitor(_width, widget.width, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _height = visitor(_height, widget.height, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + } + + @override + Widget build(BuildContext context) { + return Positioned( + left: _left?.evaluate(animation), + top: _top?.evaluate(animation), + right: _right?.evaluate(animation), + bottom: _bottom?.evaluate(animation), + width: _width?.evaluate(animation), + height: _height?.evaluate(animation), + child: widget.child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(ObjectFlagProperty<Tween<double>>.has('left', _left)); + description.add(ObjectFlagProperty<Tween<double>>.has('top', _top)); + description.add(ObjectFlagProperty<Tween<double>>.has('right', _right)); + description.add(ObjectFlagProperty<Tween<double>>.has('bottom', _bottom)); + description.add(ObjectFlagProperty<Tween<double>>.has('width', _width)); + description.add(ObjectFlagProperty<Tween<double>>.has('height', _height)); + } +} + +/// Animated version of [PositionedDirectional] which automatically transitions +/// the child's position over a given duration whenever the given position +/// changes. +/// +/// The ambient [Directionality] is used to determine whether [start] is to the +/// left or to the right. +/// +/// Only works if it's the child of a [Stack]. +/// +/// This widget is a good choice if the _size_ of the child would end up +/// changing as a result of this animation. If the size is intended to remain +/// the same, with only the _position_ changing over time, then consider +/// [SlideTransition] instead. [SlideTransition] only triggers a repaint each +/// frame of the animation, whereas [AnimatedPositionedDirectional] will trigger +/// a relayout as well. ([SlideTransition] is also text-direction-aware.) +/// +/// Here's an illustration of what using this widget looks like, using a [curve] +/// of [Curves.fastOutSlowIn]. +/// {@animation 250 266 https://flutter.github.io/assets-for-api-docs/assets/widgets/animated_positioned_directional.mp4} +/// +/// See also: +/// +/// * [AnimatedPositioned], which specifies the widget's position visually (the +/// same as this widget, but for animating [Positioned]). +class AnimatedPositionedDirectional extends ImplicitlyAnimatedWidget { + /// Creates a widget that animates its position implicitly. + /// + /// Only two out of the three horizontal values ([start], [end], [width]), and + /// only two out of the three vertical values ([top], [bottom], [height]), can + /// be set. In each case, at least one of the three must be null. + const AnimatedPositionedDirectional({ + super.key, + required this.child, + this.start, + this.top, + this.end, + this.bottom, + this.width, + this.height, + super.curve, + required super.duration, + super.onEnd, + }) : assert(start == null || end == null || width == null), + assert(top == null || bottom == null || height == null); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The offset of the child's start edge from the start of the stack. + final double? start; + + /// The offset of the child's top edge from the top of the stack. + final double? top; + + /// The offset of the child's end edge from the end of the stack. + final double? end; + + /// The offset of the child's bottom edge from the bottom of the stack. + final double? bottom; + + /// The child's width. + /// + /// Only two out of the three horizontal values ([start], [end], [width]) can + /// be set. The third must be null. + final double? width; + + /// The child's height. + /// + /// Only two out of the three vertical values ([top], [bottom], [height]) can + /// be set. The third must be null. + final double? height; + + @override + AnimatedWidgetBaseState<AnimatedPositionedDirectional> createState() => _AnimatedPositionedDirectionalState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('start', start, defaultValue: null)); + properties.add(DoubleProperty('top', top, defaultValue: null)); + properties.add(DoubleProperty('end', end, defaultValue: null)); + properties.add(DoubleProperty('bottom', bottom, defaultValue: null)); + properties.add(DoubleProperty('width', width, defaultValue: null)); + properties.add(DoubleProperty('height', height, defaultValue: null)); + } +} + +class _AnimatedPositionedDirectionalState extends AnimatedWidgetBaseState<AnimatedPositionedDirectional> { + Tween<double>? _start; + Tween<double>? _top; + Tween<double>? _end; + Tween<double>? _bottom; + Tween<double>? _width; + Tween<double>? _height; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _start = visitor(_start, widget.start, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _top = visitor(_top, widget.top, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _end = visitor(_end, widget.end, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _bottom = visitor(_bottom, widget.bottom, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _width = visitor(_width, widget.width, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _height = visitor(_height, widget.height, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + return Positioned.directional( + textDirection: Directionality.of(context), + start: _start?.evaluate(animation), + top: _top?.evaluate(animation), + end: _end?.evaluate(animation), + bottom: _bottom?.evaluate(animation), + width: _width?.evaluate(animation), + height: _height?.evaluate(animation), + child: widget.child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(ObjectFlagProperty<Tween<double>>.has('start', _start)); + description.add(ObjectFlagProperty<Tween<double>>.has('top', _top)); + description.add(ObjectFlagProperty<Tween<double>>.has('end', _end)); + description.add(ObjectFlagProperty<Tween<double>>.has('bottom', _bottom)); + description.add(ObjectFlagProperty<Tween<double>>.has('width', _width)); + description.add(ObjectFlagProperty<Tween<double>>.has('height', _height)); + } +} + +/// Animated version of [Transform.scale] which automatically transitions the child's +/// scale over a given duration whenever the given scale changes. +/// +/// {@tool snippet} +/// +/// This code defines a widget that uses [AnimatedScale] to change the size +/// of [FlutterLogo] gradually to a new scale whenever the button is pressed. +/// +/// ```dart +/// class LogoScale extends StatefulWidget { +/// const LogoScale({super.key}); +/// +/// @override +/// State<LogoScale> createState() => LogoScaleState(); +/// } +/// +/// class LogoScaleState extends State<LogoScale> { +/// double scale = 1.0; +/// +/// void _changeScale() { +/// setState(() => scale = scale == 1.0 ? 3.0 : 1.0); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return Column( +/// mainAxisAlignment: MainAxisAlignment.center, +/// children: <Widget>[ +/// ElevatedButton( +/// onPressed: _changeScale, +/// child: const Text('Scale Logo'), +/// ), +/// Padding( +/// padding: const EdgeInsets.all(50), +/// child: AnimatedScale( +/// scale: scale, +/// duration: const Duration(seconds: 2), +/// child: const FlutterLogo(), +/// ), +/// ), +/// ], +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedRotation], for animating the rotation of a child. +/// * [AnimatedSize], for animating the resize of a child based on changes +/// in layout. +/// * [AnimatedSlide], for animating the translation of a child by a given offset relative to its size. +/// * [ScaleTransition], an explicitly animated version of this widget, where +/// an [Animation] is provided by the caller instead of being built in. +class AnimatedScale extends ImplicitlyAnimatedWidget { + /// Creates a widget that animates its scale implicitly. + const AnimatedScale({ + super.key, + this.child, + required this.scale, + this.alignment = Alignment.center, + this.filterQuality, + super.curve, + required super.duration, + super.onEnd, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The target scale. + final double scale; + + /// The alignment of the origin of the coordinate system in which the scale + /// takes place, relative to the size of the box. + /// + /// For example, to set the origin of the scale to bottom middle, you can use + /// an alignment of (0.0, 1.0). + final Alignment alignment; + + /// The filter quality with which to apply the transform as a bitmap operation. + /// + /// {@macro flutter.widgets.Transform.optional.FilterQuality} + final FilterQuality? filterQuality; + + @override + ImplicitlyAnimatedWidgetState<AnimatedScale> createState() => _AnimatedScaleState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('scale', scale)); + properties.add(DiagnosticsProperty<Alignment>('alignment', alignment, defaultValue: Alignment.center)); + properties.add(EnumProperty<FilterQuality>('filterQuality', filterQuality, defaultValue: null)); + } +} + +class _AnimatedScaleState extends ImplicitlyAnimatedWidgetState<AnimatedScale> { + Tween<double>? _scale; + late Animation<double> _scaleAnimation; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _scale = visitor(_scale, widget.scale, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + } + + @override + void didUpdateTweens() { + _scaleAnimation = animation.drive(_scale!); + } + + @override + Widget build(BuildContext context) { + return ScaleTransition( + scale: _scaleAnimation, + alignment: widget.alignment, + filterQuality: widget.filterQuality, + child: widget.child, + ); + } +} + +/// Animated version of [Transform.rotate] which automatically transitions the child's +/// rotation over a given duration whenever the given rotation changes. +/// +/// {@tool snippet} +/// +/// This code defines a widget that uses [AnimatedRotation] to rotate a [FlutterLogo] +/// gradually by an eighth of a turn (45 degrees) with each press of the button. +/// +/// ```dart +/// class LogoRotate extends StatefulWidget { +/// const LogoRotate({super.key}); +/// +/// @override +/// State<LogoRotate> createState() => LogoRotateState(); +/// } +/// +/// class LogoRotateState extends State<LogoRotate> { +/// double turns = 0.0; +/// +/// void _changeRotation() { +/// setState(() => turns += 1.0 / 8.0); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return Column( +/// mainAxisAlignment: MainAxisAlignment.center, +/// children: <Widget>[ +/// ElevatedButton( +/// onPressed: _changeRotation, +/// child: const Text('Rotate Logo'), +/// ), +/// Padding( +/// padding: const EdgeInsets.all(50), +/// child: AnimatedRotation( +/// turns: turns, +/// duration: const Duration(seconds: 1), +/// child: const FlutterLogo(), +/// ), +/// ), +/// ], +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedScale], for animating the scale of a child. +/// * [RotationTransition], an explicitly animated version of this widget, where +/// an [Animation] is provided by the caller instead of being built in. +class AnimatedRotation extends ImplicitlyAnimatedWidget { + /// Creates a widget that animates its rotation implicitly. + const AnimatedRotation({ + super.key, + this.child, + required this.turns, + this.alignment = Alignment.center, + this.filterQuality, + super.curve, + required super.duration, + super.onEnd, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The animation that controls the rotation of the child. + /// + /// If the current value of the turns animation is v, the child will be + /// rotated v * 2 * pi radians before being painted. + final double turns; + + /// The alignment of the origin of the coordinate system in which the rotation + /// takes place, relative to the size of the box. + /// + /// For example, to set the origin of the rotation to bottom middle, you can use + /// an alignment of (0.0, 1.0). + final Alignment alignment; + + /// The filter quality with which to apply the transform as a bitmap operation. + /// + /// {@macro flutter.widgets.Transform.optional.FilterQuality} + final FilterQuality? filterQuality; + + @override + ImplicitlyAnimatedWidgetState<AnimatedRotation> createState() => _AnimatedRotationState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('turns', turns)); + properties.add(DiagnosticsProperty<Alignment>('alignment', alignment, defaultValue: Alignment.center)); + properties.add(EnumProperty<FilterQuality>('filterQuality', filterQuality, defaultValue: null)); + } +} + +class _AnimatedRotationState extends ImplicitlyAnimatedWidgetState<AnimatedRotation> { + Tween<double>? _turns; + late Animation<double> _turnsAnimation; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _turns = visitor(_turns, widget.turns, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + } + + @override + void didUpdateTweens() { + _turnsAnimation = animation.drive(_turns!); + } + + @override + Widget build(BuildContext context) { + return RotationTransition( + turns: _turnsAnimation, + alignment: widget.alignment, + filterQuality: widget.filterQuality, + child: widget.child, + ); + } +} + +/// Widget which automatically transitions the child's +/// offset relative to its normal position whenever the given offset changes. +/// +/// The translation is expressed as an [Offset] scaled to the child's size. For +/// example, an [Offset] with a `dx` of 0.25 will result in a horizontal +/// translation of one quarter the width of the child. +/// +/// {@tool dartpad} +/// This code defines a widget that uses [AnimatedSlide] to translate a [FlutterLogo] +/// up or down and right or left by dragging the X and Y axis sliders. +/// +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_slide.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedPositioned], which, as a child of a [Stack], automatically +/// transitions its child's position over a given duration whenever the given +/// position changes. +/// * [AnimatedAlign], which automatically transitions its child's +/// position over a given duration whenever the given [AnimatedAlign.alignment] changes. +class AnimatedSlide extends ImplicitlyAnimatedWidget { + /// Creates a widget that animates its offset translation implicitly. + const AnimatedSlide({ + super.key, + this.child, + required this.offset, + super.curve, + required super.duration, + super.onEnd, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The target offset. + /// The child will be translated horizontally by `width * dx` and vertically by `height * dy` + final Offset offset; + + @override + ImplicitlyAnimatedWidgetState<AnimatedSlide> createState() => _AnimatedSlideState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Offset>('offset', offset)); + } +} + +class _AnimatedSlideState extends ImplicitlyAnimatedWidgetState<AnimatedSlide> { + Tween<Offset>? _offset; + late Animation<Offset> _offsetAnimation; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _offset = visitor(_offset, widget.offset, (dynamic value) => Tween<Offset>(begin: value as Offset)) as Tween<Offset>?; + } + + @override + void didUpdateTweens() { + _offsetAnimation = animation.drive(_offset!); + } + + @override + Widget build(BuildContext context) { + return SlideTransition( + position: _offsetAnimation, + child: widget.child, + ); + } +} + +/// Animated version of [Opacity] which automatically transitions the child's +/// opacity over a given duration whenever the given opacity changes. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=QZAvjqOqiLY} +/// +/// Animating an opacity is relatively expensive because it requires painting +/// the child into an intermediate buffer. +/// +/// Here's an illustration of what using this widget looks like, using a [curve] +/// of [Curves.fastOutSlowIn]. +/// {@animation 250 266 https://flutter.github.io/assets-for-api-docs/assets/widgets/animated_opacity.mp4} +/// +/// {@tool snippet} +/// +/// ```dart +/// class LogoFade extends StatefulWidget { +/// const LogoFade({super.key}); +/// +/// @override +/// State<LogoFade> createState() => LogoFadeState(); +/// } +/// +/// class LogoFadeState extends State<LogoFade> { +/// double opacityLevel = 1.0; +/// +/// void _changeOpacity() { +/// setState(() => opacityLevel = opacityLevel == 0 ? 1.0 : 0.0); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return Column( +/// mainAxisAlignment: MainAxisAlignment.center, +/// children: <Widget>[ +/// AnimatedOpacity( +/// opacity: opacityLevel, +/// duration: const Duration(seconds: 3), +/// child: const FlutterLogo(), +/// ), +/// ElevatedButton( +/// onPressed: _changeOpacity, +/// child: const Text('Fade Logo'), +/// ), +/// ], +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// ## Hit testing +/// +/// Setting the [opacity] to zero does not prevent hit testing from being +/// applied to the descendants of the [AnimatedOpacity] widget. This can be +/// confusing for the user, who may not see anything, and may believe the area +/// of the interface where the [AnimatedOpacity] is hiding a widget to be +/// non-interactive. +/// +/// With certain widgets, such as [Flow], that compute their positions only when +/// they are painted, this can actually lead to bugs (from unexpected geometry +/// to exceptions), because those widgets are not painted by the [AnimatedOpacity] +/// widget at all when the [opacity] animation reaches zero. +/// +/// To avoid such problems, it is generally a good idea to use an +/// [IgnorePointer] widget when setting the [opacity] to zero. This prevents +/// interactions with any children in the subtree when the [child] is animating +/// away. +/// +/// See also: +/// +/// * [AnimatedCrossFade], for fading between two children. +/// * [AnimatedSwitcher], for fading between many children in sequence. +/// * [FadeTransition], an explicitly animated version of this widget, where +/// an [Animation] is provided by the caller instead of being built in. +/// * [SliverAnimatedOpacity], for automatically transitioning a _sliver's_ +/// opacity over a given duration whenever the given opacity changes. +class AnimatedOpacity extends ImplicitlyAnimatedWidget { + /// Creates a widget that animates its opacity implicitly. + /// + /// The [opacity] argument must be between zero and one, inclusive. + const AnimatedOpacity({ + super.key, + this.child, + required this.opacity, + super.curve, + required super.duration, + super.onEnd, + this.alwaysIncludeSemantics = false, + }) : assert(opacity >= 0.0 && opacity <= 1.0); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The target opacity. + /// + /// An opacity of 1.0 is fully opaque. An opacity of 0.0 is fully transparent + /// (i.e., invisible). + final double opacity; + + /// Whether the semantic information of the children is always included. + /// + /// Defaults to false. + /// + /// When true, regardless of the opacity settings the child semantic + /// information is exposed as if the widget were fully visible. This is + /// useful in cases where labels may be hidden during animations that + /// would otherwise contribute relevant semantics. + final bool alwaysIncludeSemantics; + + @override + ImplicitlyAnimatedWidgetState<AnimatedOpacity> createState() => _AnimatedOpacityState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('opacity', opacity)); + } +} + +class _AnimatedOpacityState extends ImplicitlyAnimatedWidgetState<AnimatedOpacity> { + Tween<double>? _opacity; + late Animation<double> _opacityAnimation; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _opacity = visitor(_opacity, widget.opacity, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + } + + @override + void didUpdateTweens() { + _opacityAnimation = animation.drive(_opacity!); + } + + @override + Widget build(BuildContext context) { + return FadeTransition( + opacity: _opacityAnimation, + alwaysIncludeSemantics: widget.alwaysIncludeSemantics, + child: widget.child, + ); + } +} + +/// Animated version of [SliverOpacity] which automatically transitions the +/// sliver child's opacity over a given duration whenever the given opacity +/// changes. +/// +/// Animating an opacity is relatively expensive because it requires painting +/// the sliver child into an intermediate buffer. +/// +/// Here's an illustration of what using this widget looks like, using a [curve] +/// of [Curves.fastOutSlowIn]. +/// +/// {@tool dartpad} +/// Creates a [CustomScrollView] with a [SliverFixedExtentList] and a +/// [FloatingActionButton]. Pressing the button animates the lists' opacity. +/// +/// ** See code in examples/api/lib/widgets/implicit_animations/sliver_animated_opacity.0.dart ** +/// {@end-tool} +/// +/// ## Hit testing +/// +/// Setting the [opacity] to zero does not prevent hit testing from being +/// applied to the descendants of the [SliverAnimatedOpacity] widget. This can +/// be confusing for the user, who may not see anything, and may believe the +/// area of the interface where the [SliverAnimatedOpacity] is hiding a widget +/// to be non-interactive. +/// +/// With certain widgets, such as [Flow], that compute their positions only when +/// they are painted, this can actually lead to bugs (from unexpected geometry +/// to exceptions), because those widgets are not painted by the +/// [SliverAnimatedOpacity] widget at all when the [opacity] animation reaches +/// zero. +/// +/// To avoid such problems, it is generally a good idea to use a +/// [SliverIgnorePointer] widget when setting the [opacity] to zero. This +/// prevents interactions with any children in the subtree when the [sliver] is +/// animating away. +/// +/// See also: +/// +/// * [SliverFadeTransition], an explicitly animated version of this widget, where +/// an [Animation] is provided by the caller instead of being built in. +/// * [AnimatedOpacity], for automatically transitioning a box child's +/// opacity over a given duration whenever the given opacity changes. +class SliverAnimatedOpacity extends ImplicitlyAnimatedWidget { + /// Creates a widget that animates its opacity implicitly. + /// + /// The [opacity] argument must be between zero and one, inclusive. + const SliverAnimatedOpacity({ + super.key, + this.sliver, + required this.opacity, + super.curve, + required super.duration, + super.onEnd, + this.alwaysIncludeSemantics = false, + }) : assert(opacity >= 0.0 && opacity <= 1.0); + + /// The sliver below this widget in the tree. + final Widget? sliver; + + /// The target opacity. + /// + /// An opacity of 1.0 is fully opaque. An opacity of 0.0 is fully transparent + /// (i.e., invisible). + final double opacity; + + /// Whether the semantic information of the children is always included. + /// + /// Defaults to false. + /// + /// When true, regardless of the opacity settings the sliver child's semantic + /// information is exposed as if the widget were fully visible. This is + /// useful in cases where labels may be hidden during animations that + /// would otherwise contribute relevant semantics. + final bool alwaysIncludeSemantics; + + @override + ImplicitlyAnimatedWidgetState<SliverAnimatedOpacity> createState() => _SliverAnimatedOpacityState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('opacity', opacity)); + } +} + +class _SliverAnimatedOpacityState extends ImplicitlyAnimatedWidgetState<SliverAnimatedOpacity> { + Tween<double>? _opacity; + late Animation<double> _opacityAnimation; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _opacity = visitor(_opacity, widget.opacity, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + } + + @override + void didUpdateTweens() { + _opacityAnimation = animation.drive(_opacity!); + } + + @override + Widget build(BuildContext context) { + return SliverFadeTransition( + opacity: _opacityAnimation, + sliver: widget.sliver, + alwaysIncludeSemantics: widget.alwaysIncludeSemantics, + ); + } +} + +/// Animated version of [DefaultTextStyle] which automatically transitions the +/// default text style (the text style to apply to descendant [Text] widgets +/// without explicit style) over a given duration whenever the given style +/// changes. +/// +/// The [textAlign], [softWrap], [overflow], [maxLines], [textWidthBasis] +/// and [textHeightBehavior] properties are not animated and take effect +/// immediately when changed. +/// +/// Here's an illustration of what using this widget looks like, using a [curve] +/// of [Curves.elasticInOut]. +/// {@animation 250 266 https://flutter.github.io/assets-for-api-docs/assets/widgets/animated_default_text_style.mp4} +/// +/// For the animation, you can choose a [curve] as well as a [duration] and the +/// widget will automatically animate to the new default text style. If you require +/// more control over the animation (e.g. if you want to stop it mid-animation), +/// consider using a [DefaultTextStyleTransition] instead, which takes a provided +/// [Animation] as argument. While that allows you to fine-tune the animation, +/// it also requires more development overhead as you have to manually manage +/// the lifecycle of the underlying [AnimationController]. +class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget { + /// Creates a widget that animates the default text style implicitly. + const AnimatedDefaultTextStyle({ + super.key, + required this.child, + required this.style, + this.textAlign, + this.softWrap = true, + this.overflow = TextOverflow.clip, + this.maxLines, + this.textWidthBasis = TextWidthBasis.parent, + this.textHeightBehavior, + super.curve, + required super.duration, + super.onEnd, + }) : assert(maxLines == null || maxLines > 0); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The target text style. + /// + /// When this property is changed, the style will be animated over [duration] time. + final TextStyle style; + + /// How the text should be aligned horizontally. + /// + /// This property takes effect immediately when changed, it is not animated. + final TextAlign? textAlign; + + /// Whether the text should break at soft line breaks. + /// + /// This property takes effect immediately when changed, it is not animated. + /// + /// See [DefaultTextStyle.softWrap] for more details. + final bool softWrap; + + /// How visual overflow should be handled. + /// + /// This property takes effect immediately when changed, it is not animated. + final TextOverflow overflow; + + /// An optional maximum number of lines for the text to span, wrapping if necessary. + /// + /// This property takes effect immediately when changed, it is not animated. + /// + /// See [DefaultTextStyle.maxLines] for more details. + final int? maxLines; + + /// The strategy to use when calculating the width of the Text. + /// + /// See [TextWidthBasis] for possible values and their implications. + final TextWidthBasis textWidthBasis; + + /// {@macro dart.ui.textHeightBehavior} + final ui.TextHeightBehavior? textHeightBehavior; + + @override + AnimatedWidgetBaseState<AnimatedDefaultTextStyle> createState() => _AnimatedDefaultTextStyleState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + style.debugFillProperties(properties); + properties.add(EnumProperty<TextAlign>('textAlign', textAlign, defaultValue: null)); + properties.add(FlagProperty('softWrap', value: softWrap, ifTrue: 'wrapping at box width', ifFalse: 'no wrapping except at line break characters', showName: true)); + properties.add(EnumProperty<TextOverflow>('overflow', overflow, defaultValue: null)); + properties.add(IntProperty('maxLines', maxLines, defaultValue: null)); + properties.add(EnumProperty<TextWidthBasis>('textWidthBasis', textWidthBasis, defaultValue: TextWidthBasis.parent)); + properties.add(DiagnosticsProperty<ui.TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null)); + } +} + +class _AnimatedDefaultTextStyleState extends AnimatedWidgetBaseState<AnimatedDefaultTextStyle> { + TextStyleTween? _style; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _style = visitor(_style, widget.style, (dynamic value) => TextStyleTween(begin: value as TextStyle)) as TextStyleTween?; + } + + @override + Widget build(BuildContext context) { + return DefaultTextStyle( + style: _style!.evaluate(animation), + textAlign: widget.textAlign, + softWrap: widget.softWrap, + overflow: widget.overflow, + maxLines: widget.maxLines, + textWidthBasis: widget.textWidthBasis, + textHeightBehavior: widget.textHeightBehavior, + child: widget.child, + ); + } +} + +/// Animated version of [PhysicalModel]. +/// +/// The [borderRadius] and [elevation] are animated. +/// +/// The [color] is animated if the [animateColor] property is set; otherwise, +/// the color changes immediately at the start of the animation for the other +/// two properties. This allows the color to be animated independently (e.g. +/// because it is being driven by an [AnimatedTheme]). +/// +/// The [shape] is not animated. +/// +/// Here's an illustration of what using this widget looks like, using a [curve] +/// of [Curves.fastOutSlowIn]. +/// {@animation 250 266 https://flutter.github.io/assets-for-api-docs/assets/widgets/animated_physical_model.mp4} +class AnimatedPhysicalModel extends ImplicitlyAnimatedWidget { + /// Creates a widget that animates the properties of a [PhysicalModel]. + /// + /// The [elevation] must be non-negative. + /// + /// Animating [color] is optional and is controlled by the [animateColor] flag. + /// + /// Animating [shadowColor] is optional and is controlled by the [animateShadowColor] flag. + const AnimatedPhysicalModel({ + super.key, + required this.child, + required this.shape, + this.clipBehavior = Clip.none, + this.borderRadius = BorderRadius.zero, + required this.elevation, + required this.color, + this.animateColor = true, + required this.shadowColor, + this.animateShadowColor = true, + super.curve, + required super.duration, + super.onEnd, + }) : assert(elevation >= 0.0); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The type of shape. + /// + /// This property is not animated. + final BoxShape shape; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + /// The target border radius of the rounded corners for a rectangle shape. + final BorderRadius borderRadius; + + /// The target z-coordinate relative to the parent at which to place this + /// physical object. + /// + /// The value will always be non-negative. + final double elevation; + + /// The target background color. + final Color color; + + /// Whether the color should be animated. + final bool animateColor; + + /// The target shadow color. + final Color shadowColor; + + /// Whether the shadow color should be animated. + final bool animateShadowColor; + + @override + AnimatedWidgetBaseState<AnimatedPhysicalModel> createState() => _AnimatedPhysicalModelState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<BoxShape>('shape', shape)); + properties.add(DiagnosticsProperty<BorderRadius>('borderRadius', borderRadius)); + properties.add(DoubleProperty('elevation', elevation)); + properties.add(ColorProperty('color', color)); + properties.add(DiagnosticsProperty<bool>('animateColor', animateColor)); + properties.add(ColorProperty('shadowColor', shadowColor)); + properties.add(DiagnosticsProperty<bool>('animateShadowColor', animateShadowColor)); + } +} + +class _AnimatedPhysicalModelState extends AnimatedWidgetBaseState<AnimatedPhysicalModel> { + BorderRadiusTween? _borderRadius; + Tween<double>? _elevation; + ColorTween? _color; + ColorTween? _shadowColor; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _borderRadius = visitor(_borderRadius, widget.borderRadius, (dynamic value) => BorderRadiusTween(begin: value as BorderRadius)) as BorderRadiusTween?; + _elevation = visitor(_elevation, widget.elevation, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + _color = visitor(_color, widget.color, (dynamic value) => ColorTween(begin: value as Color)) as ColorTween?; + _shadowColor = visitor(_shadowColor, widget.shadowColor, (dynamic value) => ColorTween(begin: value as Color)) as ColorTween?; + } + + @override + Widget build(BuildContext context) { + return PhysicalModel( + shape: widget.shape, + clipBehavior: widget.clipBehavior, + borderRadius: _borderRadius!.evaluate(animation), + elevation: _elevation!.evaluate(animation), + color: widget.animateColor ? _color!.evaluate(animation)! : widget.color, + shadowColor: widget.animateShadowColor + ? _shadowColor!.evaluate(animation)! + : widget.shadowColor, + child: widget.child, + ); + } +} + +/// Animated version of [FractionallySizedBox] which automatically transitions the +/// child's size over a given duration whenever the given [widthFactor] or +/// [heightFactor] changes, as well as the position whenever the given [alignment] +/// changes. +/// +/// For the animation, you can choose a [curve] as well as a [duration] and the +/// widget will automatically animate to the new target [widthFactor] or +/// [heightFactor]. +/// +/// {@tool dartpad} +/// The following example transitions an [AnimatedFractionallySizedBox] +/// between two states. It adjusts the [heightFactor], [widthFactor], and +/// [alignment] properties when tapped, using a [curve] of [Curves.fastOutSlowIn] +/// +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_fractionally_sized_box.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedAlign], which is an implicitly animated version of [Align]. +/// * [AnimatedContainer], which can transition more values at once. +/// * [AnimatedSlide], which can animate the translation of child by a given offset relative to its size. +/// * [AnimatedPositioned], which, as a child of a [Stack], automatically +/// transitions its child's position over a given duration whenever the given +/// position changes. +class AnimatedFractionallySizedBox extends ImplicitlyAnimatedWidget { + /// Creates a widget that sizes its child to a fraction of the total available + /// space that animates implicitly, and positions its child by an alignment + /// that animates implicitly. + /// + /// If non-null, the [widthFactor] and [heightFactor] arguments must be + /// non-negative. + const AnimatedFractionallySizedBox({ + super.key, + this.alignment = Alignment.center, + this.child, + this.heightFactor, + this.widthFactor, + super.curve, + required super.duration, + super.onEnd, + }) : assert(widthFactor == null || widthFactor >= 0.0), + assert(heightFactor == null || heightFactor >= 0.0); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// {@macro flutter.widgets.basic.fractionallySizedBox.heightFactor} + final double? heightFactor; + + /// {@macro flutter.widgets.basic.fractionallySizedBox.widthFactor} + final double? widthFactor; + + /// {@macro flutter.widgets.basic.fractionallySizedBox.alignment} + final AlignmentGeometry alignment; + + @override + AnimatedWidgetBaseState<AnimatedFractionallySizedBox> createState() => _AnimatedFractionallySizedBoxState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment)); + properties.add(DiagnosticsProperty<double>('widthFactor', widthFactor)); + properties.add(DiagnosticsProperty<double>('heightFactor', heightFactor)); + } +} + +class _AnimatedFractionallySizedBoxState extends AnimatedWidgetBaseState<AnimatedFractionallySizedBox> { + AlignmentGeometryTween? _alignment; + Tween<double>? _heightFactorTween; + Tween<double>? _widthFactorTween; + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + _alignment = visitor(_alignment, widget.alignment, (dynamic value) => AlignmentGeometryTween(begin: value as AlignmentGeometry)) as AlignmentGeometryTween?; + if (widget.heightFactor != null) { + _heightFactorTween = visitor(_heightFactorTween, widget.heightFactor, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + } + if (widget.widthFactor != null) { + _widthFactorTween = visitor(_widthFactorTween, widget.widthFactor, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?; + } + } + + @override + Widget build(BuildContext context) { + return FractionallySizedBox( + alignment: _alignment!.evaluate(animation)!, + heightFactor: _heightFactorTween?.evaluate(animation), + widthFactor: _widthFactorTween?.evaluate(animation), + child: widget.child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(DiagnosticsProperty<AlignmentGeometryTween>('alignment', _alignment, defaultValue: null)); + description.add(DiagnosticsProperty<Tween<double>>('widthFactor', _widthFactorTween, defaultValue: null)); + description.add(DiagnosticsProperty<Tween<double>>('heightFactor', _heightFactorTween, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/inherited_model.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/inherited_model.dart new file mode 100644 index 0000000000000000000000000000000000000000..688992546c23895d47c626ab0d8b7be7f4e65345 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/inherited_model.dart @@ -0,0 +1,239 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; + +import 'framework.dart'; + +/// An [InheritedWidget] that's intended to be used as the base class for models +/// whose dependents may only depend on one part or "aspect" of the overall +/// model. +/// +/// An inherited widget's dependents are unconditionally rebuilt when the +/// inherited widget changes per [InheritedWidget.updateShouldNotify]. This +/// widget is similar except that dependents aren't rebuilt unconditionally. +/// +/// Widgets that depend on an [InheritedModel] qualify their dependence with a +/// value that indicates what "aspect" of the model they depend on. When the +/// model is rebuilt, dependents will also be rebuilt, but only if there was a +/// change in the model that corresponds to the aspect they provided. +/// +/// The type parameter `T` is the type of the model aspect objects. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ml5uefGgkaA} +/// +/// Widgets create a dependency on an [InheritedModel] with a static method: +/// [InheritedModel.inheritFrom]. This method's `context` parameter defines the +/// subtree that will be rebuilt when the model changes. Typically the +/// `inheritFrom` method is called from a model-specific static `maybeOf` or +/// `of` methods, a convention that is present in many Flutter framework classes +/// which look things up. For example: +/// +/// ```dart +/// class MyModel extends InheritedModel<String> { +/// const MyModel({super.key, required super.child}); +/// +/// // ... +/// static MyModel? maybeOf(BuildContext context, [String? aspect]) { +/// return InheritedModel.inheritFrom<MyModel>(context, aspect: aspect); +/// } +/// +/// // ... +/// static MyModel of(BuildContext context, [String? aspect]) { +/// final MyModel? result = maybeOf(context, aspect); +/// assert(result != null, 'Unable to find an instance of MyModel...'); +/// return result!; +/// } +/// } +/// ``` +/// +/// Calling `MyModel.of(context, 'foo')` or `MyModel.maybeOf(context, +/// 'foo')` means that `context` should only be rebuilt when the `foo` aspect of +/// `MyModel` changes. If the `aspect` is null, then the model supports all +/// aspects. +/// +/// {@tool snippet} +/// When the inherited model is rebuilt the [updateShouldNotify] and +/// [updateShouldNotifyDependent] methods are used to decide what should be +/// rebuilt. If [updateShouldNotify] returns true, then the inherited model's +/// [updateShouldNotifyDependent] method is tested for each dependent and the +/// set of aspect objects it depends on. The [updateShouldNotifyDependent] +/// method must compare the set of aspect dependencies with the changes in the +/// model itself. For example: +/// +/// ```dart +/// class ABModel extends InheritedModel<String> { +/// const ABModel({ +/// super.key, +/// this.a, +/// this.b, +/// required super.child, +/// }); +/// +/// final int? a; +/// final int? b; +/// +/// @override +/// bool updateShouldNotify(ABModel oldWidget) { +/// return a != oldWidget.a || b != oldWidget.b; +/// } +/// +/// @override +/// bool updateShouldNotifyDependent(ABModel oldWidget, Set<String> dependencies) { +/// return (a != oldWidget.a && dependencies.contains('a')) +/// || (b != oldWidget.b && dependencies.contains('b')); +/// } +/// +/// // ... +/// } +/// ``` +/// {@end-tool} +/// +/// In the previous example the dependencies checked by +/// [updateShouldNotifyDependent] are just the aspect strings passed to +/// `dependOnInheritedWidgetOfExactType`. They're represented as a [Set] because +/// one Widget can depend on more than one aspect of the model. If a widget +/// depends on the model but doesn't specify an aspect, then changes in the +/// model will cause the widget to be rebuilt unconditionally. +/// +/// {@tool dartpad} +/// This example shows how to implement [InheritedModel] to rebuild a widget +/// based on a qualified dependence. When tapped on the "Resize Logo" button +/// only the logo widget is rebuilt while the background widget remains +/// unaffected. +/// +/// ** See code in examples/api/lib/widgets/inherited_model/inherited_model.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [InheritedWidget], an inherited widget that only notifies dependents when +/// its value is different. +/// * [InheritedNotifier], an inherited widget whose value can be a +/// [Listenable], and which will notify dependents whenever the value sends +/// notifications. +abstract class InheritedModel<T> extends InheritedWidget { + /// Creates an inherited widget that supports dependencies qualified by + /// "aspects", i.e. a descendant widget can indicate that it should + /// only be rebuilt if a specific aspect of the model changes. + const InheritedModel({ super.key, required super.child }); + + @override + InheritedModelElement<T> createElement() => InheritedModelElement<T>(this); + + /// Return true if the changes between this model and [oldWidget] match any + /// of the [dependencies]. + @protected + bool updateShouldNotifyDependent(covariant InheritedModel<T> oldWidget, Set<T> dependencies); + + /// Returns true if this model supports the given [aspect]. + /// + /// Returns true by default: this model supports all aspects. + /// + /// Subclasses may override this method to indicate that they do not support + /// all model aspects. This is typically done when a model can be used + /// to "shadow" some aspects of an ancestor. + @protected + bool isSupportedAspect(Object aspect) => true; + + // The [result] will be a list of all of context's type T ancestors concluding + // with the one that supports the specified model [aspect]. + static void _findModels<T extends InheritedModel<Object>>(BuildContext context, Object aspect, List<InheritedElement> results) { + final InheritedElement? model = context.getElementForInheritedWidgetOfExactType<T>(); + if (model == null) { + return; + } + + results.add(model); + + assert(model.widget is T); + final T modelWidget = model.widget as T; + if (modelWidget.isSupportedAspect(aspect)) { + return; + } + + Element? modelParent; + model.visitAncestorElements((Element ancestor) { + modelParent = ancestor; + return false; + }); + if (modelParent == null) { + return; + } + + _findModels<T>(modelParent!, aspect, results); + } + + /// Makes [context] dependent on the specified [aspect] of an [InheritedModel] + /// of type T. + /// + /// When the given [aspect] of the model changes, the [context] will be + /// rebuilt. The [updateShouldNotifyDependent] method must determine if a + /// change in the model widget corresponds to an [aspect] value. + /// + /// The dependencies created by this method target all [InheritedModel] ancestors + /// of type T up to and including the first one for which [isSupportedAspect] + /// returns true. + /// + /// If [aspect] is null this method is the same as + /// `context.dependOnInheritedWidgetOfExactType<T>()`. + /// + /// If no ancestor of type T exists, null is returned. + static T? inheritFrom<T extends InheritedModel<Object>>(BuildContext context, { Object? aspect }) { + if (aspect == null) { + return context.dependOnInheritedWidgetOfExactType<T>(); + } + + // Create a dependency on all of the type T ancestor models up until + // a model is found for which isSupportedAspect(aspect) is true. + final List<InheritedElement> models = <InheritedElement>[]; + _findModels<T>(context, aspect, models); + if (models.isEmpty) { + return null; + } + + final InheritedElement lastModel = models.last; + for (final InheritedElement model in models) { + final T value = context.dependOnInheritedElement(model, aspect: aspect) as T; + if (model == lastModel) { + return value; + } + } + + assert(false); + return null; + } +} + +/// An [Element] that uses a [InheritedModel] as its configuration. +class InheritedModelElement<T> extends InheritedElement { + /// Creates an element that uses the given widget as its configuration. + InheritedModelElement(InheritedModel<T> super.widget); + + @override + void updateDependencies(Element dependent, Object? aspect) { + final Set<T>? dependencies = getDependencies(dependent) as Set<T>?; + if (dependencies != null && dependencies.isEmpty) { + return; + } + + if (aspect == null) { + setDependencies(dependent, HashSet<T>()); + } else { + assert(aspect is T); + setDependencies(dependent, (dependencies ?? HashSet<T>())..add(aspect as T)); + } + } + + @override + void notifyDependent(InheritedModel<T> oldWidget, Element dependent) { + final Set<T>? dependencies = getDependencies(dependent) as Set<T>?; + if (dependencies == null) { + return; + } + if (dependencies.isEmpty || (widget as InheritedModel<T>).updateShouldNotifyDependent(oldWidget, dependencies)) { + dependent.didChangeDependencies(); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/inherited_notifier.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/inherited_notifier.dart new file mode 100644 index 0000000000000000000000000000000000000000..a3f09cd983255598acccfead62d4e7a1327b2513 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/inherited_notifier.dart @@ -0,0 +1,132 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'framework.dart'; + +/// An inherited widget for a [Listenable] [notifier], which updates its +/// dependencies when the [notifier] is triggered. +/// +/// This is a variant of [InheritedWidget], specialized for subclasses of +/// [Listenable], such as [ChangeNotifier] or [ValueNotifier]. +/// +/// Dependents are notified whenever the [notifier] sends notifications, or +/// whenever the identity of the [notifier] changes. +/// +/// Multiple notifications are coalesced, so that dependents only rebuild once +/// even if the [notifier] fires multiple times between two frames. +/// +/// Typically this class is subclassed with a class that provides an `of` static +/// method that calls [BuildContext.dependOnInheritedWidgetOfExactType] with that +/// class. +/// +/// The [updateShouldNotify] method may also be overridden, to change the logic +/// in the cases where [notifier] itself is changed. The [updateShouldNotify] +/// method is called with the old [notifier] in the case of the [notifier] being +/// changed. When it returns true, the dependents are marked as needing to be +/// rebuilt this frame. +/// +/// {@tool dartpad} +/// This example shows three spinning squares that use the value of the notifier +/// on an ancestor [InheritedNotifier] (`SpinModel`) to give them their +/// rotation. The [InheritedNotifier] doesn't need to know about the children, +/// and the `notifier` argument doesn't need to be an animation controller, it +/// can be anything that implements [Listenable] (like a [ChangeNotifier]). +/// +/// The `SpinModel` class could just as easily listen to another object (say, a +/// separate object that keeps the value of an input or data model value) that +/// is a [Listenable], and get the value from that. The descendants also don't +/// need to have an instance of the [InheritedNotifier] in order to use it, they +/// just need to know that there is one in their ancestry. This can help with +/// decoupling widgets from their models. +/// +/// ** See code in examples/api/lib/widgets/inherited_notifier/inherited_notifier.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Animation], an implementation of [Listenable] that ticks each frame to +/// update a value. +/// * [ViewportOffset] or its subclass [ScrollPosition], implementations of +/// [Listenable] that trigger when a view is scrolled. +/// * [InheritedWidget], an inherited widget that only notifies dependents +/// when its value is different. +/// * [InheritedModel], an inherited widget that allows clients to subscribe +/// to changes for subparts of the value. +abstract class InheritedNotifier<T extends Listenable> extends InheritedWidget { + /// Create an inherited widget that updates its dependents when [notifier] + /// sends notifications. + const InheritedNotifier({ + super.key, + this.notifier, + required super.child, + }); + + /// The [Listenable] object to which to listen. + /// + /// Whenever this object sends change notifications, the dependents of this + /// widget are triggered. + /// + /// By default, whenever the [notifier] is changed (including when changing to + /// or from null), if the old notifier is not equal to the new notifier (as + /// determined by the `==` operator), notifications are sent. This behavior + /// can be overridden by overriding [updateShouldNotify]. + /// + /// While the [notifier] is null, no notifications are sent, since the null + /// object cannot itself send notifications. + final T? notifier; + + @override + bool updateShouldNotify(InheritedNotifier<T> oldWidget) { + return oldWidget.notifier != notifier; + } + + @override + InheritedElement createElement() => _InheritedNotifierElement<T>(this); +} + +class _InheritedNotifierElement<T extends Listenable> extends InheritedElement { + _InheritedNotifierElement(InheritedNotifier<T> widget) : super(widget) { + widget.notifier?.addListener(_handleUpdate); + } + + bool _dirty = false; + + @override + void update(InheritedNotifier<T> newWidget) { + final T? oldNotifier = (widget as InheritedNotifier<T>).notifier; + final T? newNotifier = newWidget.notifier; + if (oldNotifier != newNotifier) { + oldNotifier?.removeListener(_handleUpdate); + newNotifier?.addListener(_handleUpdate); + } + super.update(newWidget); + } + + @override + Widget build() { + if (_dirty) { + notifyClients(widget as InheritedNotifier<T>); + } + return super.build(); + } + + void _handleUpdate() { + _dirty = true; + markNeedsBuild(); + } + + @override + void notifyClients(InheritedNotifier<T> oldWidget) { + super.notifyClients(oldWidget); + _dirty = false; + } + + @override + void unmount() { + (widget as InheritedNotifier<T>).notifier?.removeListener(_handleUpdate); + super.unmount(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/inherited_theme.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/inherited_theme.dart new file mode 100644 index 0000000000000000000000000000000000000000..673a94f0cb63186a06e8a0393b2d1d6d4466bb6e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/inherited_theme.dart @@ -0,0 +1,161 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'framework.dart'; + +// Examples can assume: +// TooltipThemeData data = const TooltipThemeData(); + +/// An [InheritedWidget] that defines visual properties like colors +/// and text styles, which the [child]'s subtree depends on. +/// +/// The [wrap] method is used by [captureAll] and [CapturedThemes.wrap] to +/// construct a widget that will wrap a child in all of the inherited themes +/// which are present in a specified part of the widget tree. +/// +/// A widget that's shown in a different context from the one it's built in, +/// like the contents of a new route or an overlay, will be able to see the +/// ancestor inherited themes of the context it was built in. +/// +/// {@tool dartpad} +/// This example demonstrates how `InheritedTheme.capture()` can be used +/// to wrap the contents of a new route with the inherited themes that +/// are present when the route was built - but are not present when route +/// is actually shown. +/// +/// If the same code is run without `InheritedTheme.capture(), the +/// new route's Text widget will inherit the "something must be wrong" +/// fallback text style, rather than the default text style defined in MyApp. +/// +/// ** See code in examples/api/lib/widgets/inherited_theme/inherited_theme.0.dart ** +/// {@end-tool} +abstract class InheritedTheme extends InheritedWidget { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + + const InheritedTheme({ + super.key, + required super.child, + }); + + /// Return a copy of this inherited theme with the specified [child]. + /// + /// This implementation for [TooltipTheme] is typical: + /// + /// ```dart + /// Widget wrap(BuildContext context, Widget child) { + /// return TooltipTheme(data: data, child: child); + /// } + /// ``` + Widget wrap(BuildContext context, Widget child); + + /// Returns a widget that will [wrap] `child` in all of the inherited themes + /// which are present between `context` and the specified `to` + /// [BuildContext]. + /// + /// The `to` context must be an ancestor of `context`. If `to` is not + /// specified, all inherited themes up to the root of the widget tree are + /// captured. + /// + /// After calling this method, the themes present between `context` and `to` + /// are frozen for the provided `child`. If the themes (or their theme data) + /// change in the original subtree, those changes will not be visible to + /// the wrapped `child` - unless this method is called again to re-wrap the + /// child. + static Widget captureAll(BuildContext context, Widget child, {BuildContext? to}) { + + return capture(from: context, to: to).wrap(child); + } + + /// Returns a [CapturedThemes] object that includes all the [InheritedTheme]s + /// between the given `from` and `to` [BuildContext]s. + /// + /// The `to` context must be an ancestor of the `from` context. If `to` is + /// null, all ancestor inherited themes of `from` up to the root of the + /// widget tree are captured. + /// + /// After calling this method, the themes present between `from` and `to` are + /// frozen in the returned [CapturedThemes] object. If the themes (or their + /// theme data) change in the original subtree, those changes will not be + /// applied to the themes captured in the [CapturedThemes] object - unless + /// this method is called again to re-capture the updated themes. + /// + /// To wrap a [Widget] in the captured themes, call [CapturedThemes.wrap]. + /// + /// This method can be expensive if there are many widgets between `from` and + /// `to` (it walks the element tree between those nodes). + static CapturedThemes capture({ required BuildContext from, required BuildContext? to }) { + + if (from == to) { + // Nothing to capture. + return CapturedThemes._(const <InheritedTheme>[]); + } + + final List<InheritedTheme> themes = <InheritedTheme>[]; + final Set<Type> themeTypes = <Type>{}; + late bool debugDidFindAncestor; + assert(() { + debugDidFindAncestor = to == null; + return true; + }()); + from.visitAncestorElements((Element ancestor) { + if (ancestor == to) { + assert(() { + debugDidFindAncestor = true; + return true; + }()); + return false; + } + if (ancestor is InheritedElement && ancestor.widget is InheritedTheme) { + final InheritedTheme theme = ancestor.widget as InheritedTheme; + final Type themeType = theme.runtimeType; + // Only remember the first theme of any type. This assumes + // that inherited themes completely shadow ancestors of the + // same type. + if (!themeTypes.contains(themeType)) { + themeTypes.add(themeType); + themes.add(theme); + } + } + return true; + }); + + assert(debugDidFindAncestor, 'The provided `to` context must be an ancestor of the `from` context.'); + return CapturedThemes._(themes); + } +} + +/// Stores a list of captured [InheritedTheme]s that can be wrapped around a +/// child [Widget]. +/// +/// Used as return type by [InheritedTheme.capture]. +class CapturedThemes { + CapturedThemes._(this._themes); + + final List<InheritedTheme> _themes; + + /// Wraps a `child` [Widget] in the [InheritedTheme]s captured in this object. + Widget wrap(Widget child) { + return _CaptureAll(themes: _themes, child: child); + } +} + +class _CaptureAll extends StatelessWidget { + const _CaptureAll({ + required this.themes, + required this.child, + }); + + final List<InheritedTheme> themes; + final Widget child; + + @override + Widget build(BuildContext context) { + Widget wrappedChild = child; + for (final InheritedTheme theme in themes) { + wrappedChild = theme.wrap(context, wrappedChild); + } + return wrappedChild; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/interactive_viewer.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/interactive_viewer.dart new file mode 100644 index 0000000000000000000000000000000000000000..9ed589af7bb529f126d2257966409c5571d82dfa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/interactive_viewer.dart @@ -0,0 +1,1485 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/gestures.dart'; +import 'package:flutter/physics.dart'; +import 'package:vector_math/vector_math_64.dart' show Matrix4, Quad, Vector3; + +import 'basic.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'layout_builder.dart'; +import 'ticker_provider.dart'; + +// Examples can assume: +// late BuildContext context; +// late Offset? _childWasTappedAt; +// late TransformationController _transformationController; +// Widget child = const Placeholder(); + +/// A signature for widget builders that take a [Quad] of the current viewport. +/// +/// See also: +/// +/// * [InteractiveViewer.builder], whose builder is of this type. +/// * [WidgetBuilder], which is similar, but takes no viewport. +typedef InteractiveViewerWidgetBuilder = Widget Function(BuildContext context, Quad viewport); + +/// A widget that enables pan and zoom interactions with its child. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=zrn7V3bMJvg} +/// +/// The user can transform the child by dragging to pan or pinching to zoom. +/// +/// By default, InteractiveViewer clips its child using [Clip.hardEdge]. +/// To prevent this behavior, consider setting [clipBehavior] to [Clip.none]. +/// When [clipBehavior] is [Clip.none], InteractiveViewer may draw outside of +/// its original area of the screen, such as when a child is zoomed in and +/// increases in size. However, it will not receive gestures outside of its original area. +/// To prevent dead areas where InteractiveViewer does not receive gestures, +/// don't set [clipBehavior] or be sure that the InteractiveViewer widget is the +/// size of the area that should be interactive. +/// +/// See also: +/// * The [Flutter Gallery's transformations demo](https://github.com/flutter/gallery/blob/master/lib/demos/reference/transformations_demo.dart), +/// which includes the use of InteractiveViewer. +/// * The [flutter-go demo](https://github.com/justinmc/flutter-go), which includes robust positioning of an InteractiveViewer child +/// that works for all screen sizes and child sizes. +/// * The [Lazy Flutter Performance Session](https://www.youtube.com/watch?v=qax_nOpgz7E), which includes the use of an InteractiveViewer to +/// performantly view subsets of a large set of widgets using the builder constructor. +/// +/// {@tool dartpad} +/// This example shows a simple Container that can be panned and zoomed. +/// +/// ** See code in examples/api/lib/widgets/interactive_viewer/interactive_viewer.0.dart ** +/// {@end-tool} +@immutable +class InteractiveViewer extends StatefulWidget { + /// Create an InteractiveViewer. + InteractiveViewer({ + super.key, + this.clipBehavior = Clip.hardEdge, + @Deprecated( + 'Use panAxis instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + this.alignPanAxis = false, + this.panAxis = PanAxis.free, + this.boundaryMargin = EdgeInsets.zero, + this.constrained = true, + // These default scale values were eyeballed as reasonable limits for common + // use cases. + this.maxScale = 2.5, + this.minScale = 0.8, + this.interactionEndFrictionCoefficient = _kDrag, + this.onInteractionEnd, + this.onInteractionStart, + this.onInteractionUpdate, + this.panEnabled = true, + this.scaleEnabled = true, + this.scaleFactor = kDefaultMouseScrollToScaleFactor, + this.transformationController, + this.alignment, + this.trackpadScrollCausesScale = false, + required Widget this.child, + }) : assert(minScale > 0), + assert(interactionEndFrictionCoefficient > 0), + assert(minScale.isFinite), + assert(maxScale > 0), + assert(!maxScale.isNaN), + assert(maxScale >= minScale), + // boundaryMargin must be either fully infinite or fully finite, but not + // a mix of both. + assert( + (boundaryMargin.horizontal.isInfinite + && boundaryMargin.vertical.isInfinite) || (boundaryMargin.top.isFinite + && boundaryMargin.right.isFinite && boundaryMargin.bottom.isFinite + && boundaryMargin.left.isFinite), + ), + builder = null; + + /// Creates an InteractiveViewer for a child that is created on demand. + /// + /// Can be used to render a child that changes in response to the current + /// transformation. + /// + /// See the [builder] attribute docs for an example of using it to optimize a + /// large child. + InteractiveViewer.builder({ + super.key, + this.clipBehavior = Clip.hardEdge, + @Deprecated( + 'Use panAxis instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + this.alignPanAxis = false, + this.panAxis = PanAxis.free, + this.boundaryMargin = EdgeInsets.zero, + // These default scale values were eyeballed as reasonable limits for common + // use cases. + this.maxScale = 2.5, + this.minScale = 0.8, + this.interactionEndFrictionCoefficient = _kDrag, + this.onInteractionEnd, + this.onInteractionStart, + this.onInteractionUpdate, + this.panEnabled = true, + this.scaleEnabled = true, + this.scaleFactor = 200.0, + this.transformationController, + this.alignment, + this.trackpadScrollCausesScale = false, + required InteractiveViewerWidgetBuilder this.builder, + }) : assert(minScale > 0), + assert(interactionEndFrictionCoefficient > 0), + assert(minScale.isFinite), + assert(maxScale > 0), + assert(!maxScale.isNaN), + assert(maxScale >= minScale), + // boundaryMargin must be either fully infinite or fully finite, but not + // a mix of both. + assert( + (boundaryMargin.horizontal.isInfinite && boundaryMargin.vertical.isInfinite) || + (boundaryMargin.top.isFinite && + boundaryMargin.right.isFinite && + boundaryMargin.bottom.isFinite && + boundaryMargin.left.isFinite), + ), + constrained = false, + child = null; + + /// The alignment of the child's origin, relative to the size of the box. + final Alignment? alignment; + + /// If set to [Clip.none], the child may extend beyond the size of the InteractiveViewer, + /// but it will not receive gestures in these areas. + /// Be sure that the InteractiveViewer is the desired size when using [Clip.none]. + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// This property is deprecated, please use [panAxis] instead. + /// + /// If true, panning is only allowed in the direction of the horizontal axis + /// or the vertical axis. + /// + /// In other words, when this is true, diagonal panning is not allowed. A + /// single gesture begun along one axis cannot also cause panning along the + /// other axis without stopping and beginning a new gesture. This is a common + /// pattern in tables where data is displayed in columns and rows. + /// + /// See also: + /// * [constrained], which has an example of creating a table that uses + /// alignPanAxis. + @Deprecated( + 'Use panAxis instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + final bool alignPanAxis; + + /// When set to [PanAxis.aligned], panning is only allowed in the horizontal + /// axis or the vertical axis, diagonal panning is not allowed. + /// + /// When set to [PanAxis.vertical] or [PanAxis.horizontal] panning is only + /// allowed in the specified axis. For example, if set to [PanAxis.vertical], + /// panning will only be allowed in the vertical axis. And if set to [PanAxis.horizontal], + /// panning will only be allowed in the horizontal axis. + /// + /// When set to [PanAxis.free] panning is allowed in all directions. + /// + /// Defaults to [PanAxis.free]. + final PanAxis panAxis; + + /// A margin for the visible boundaries of the child. + /// + /// Any transformation that results in the viewport being able to view outside + /// of the boundaries will be stopped at the boundary. The boundaries do not + /// rotate with the rest of the scene, so they are always aligned with the + /// viewport. + /// + /// To produce no boundaries at all, pass infinite [EdgeInsets], such as + /// `EdgeInsets.all(double.infinity)`. + /// + /// No edge can be NaN. + /// + /// Defaults to [EdgeInsets.zero], which results in boundaries that are the + /// exact same size and position as the [child]. + final EdgeInsets boundaryMargin; + + /// Builds the child of this widget. + /// + /// Passed with the [InteractiveViewer.builder] constructor. Otherwise, the + /// [child] parameter must be passed directly, and this is null. + /// + /// {@tool dartpad} + /// This example shows how to use builder to create a [Table] whose cell + /// contents are only built when they are visible. Built and remove cells are + /// logged in the console for illustration. + /// + /// ** See code in examples/api/lib/widgets/interactive_viewer/interactive_viewer.builder.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [ListView.builder], which follows a similar pattern. + final InteractiveViewerWidgetBuilder? builder; + + /// The child [Widget] that is transformed by InteractiveViewer. + /// + /// If the [InteractiveViewer.builder] constructor is used, then this will be + /// null, otherwise it is required. + final Widget? child; + + /// Whether the normal size constraints at this point in the widget tree are + /// applied to the child. + /// + /// If set to false, then the child will be given infinite constraints. This + /// is often useful when a child should be bigger than the InteractiveViewer. + /// + /// For example, for a child which is bigger than the viewport but can be + /// panned to reveal parts that were initially offscreen, [constrained] must + /// be set to false to allow it to size itself properly. If [constrained] is + /// true and the child can only size itself to the viewport, then areas + /// initially outside of the viewport will not be able to receive user + /// interaction events. If experiencing regions of the child that are not + /// receptive to user gestures, make sure [constrained] is false and the child + /// is sized properly. + /// + /// Defaults to true. + /// + /// {@tool dartpad} + /// This example shows how to create a pannable table. Because the table is + /// larger than the entire screen, setting [constrained] to false is necessary + /// to allow it to be drawn to its full size. The parts of the table that + /// exceed the screen size can then be panned into view. + /// + /// ** See code in examples/api/lib/widgets/interactive_viewer/interactive_viewer.constrained.0.dart ** + /// {@end-tool} + final bool constrained; + + /// If false, the user will be prevented from panning. + /// + /// Defaults to true. + /// + /// See also: + /// + /// * [scaleEnabled], which is similar but for scale. + final bool panEnabled; + + /// If false, the user will be prevented from scaling. + /// + /// Defaults to true. + /// + /// See also: + /// + /// * [panEnabled], which is similar but for panning. + final bool scaleEnabled; + + /// {@macro flutter.gestures.scale.trackpadScrollCausesScale} + final bool trackpadScrollCausesScale; + + /// Determines the amount of scale to be performed per pointer scroll. + /// + /// Defaults to [kDefaultMouseScrollToScaleFactor]. + /// + /// Increasing this value above the default causes scaling to feel slower, + /// while decreasing it causes scaling to feel faster. + /// + /// The amount of scale is calculated as the exponential function of the + /// [PointerScrollEvent.scrollDelta] to [scaleFactor] ratio. In the Flutter + /// engine, the mousewheel [PointerScrollEvent.scrollDelta] is hardcoded to 20 + /// per scroll, while a trackpad scroll can be any amount. + /// + /// Affects only pointer device scrolling, not pinch to zoom. + final double scaleFactor; + + /// The maximum allowed scale. + /// + /// The scale will be clamped between this and [minScale] inclusively. + /// + /// Defaults to 2.5. + /// + /// Must be greater than zero and greater than [minScale]. + final double maxScale; + + /// The minimum allowed scale. + /// + /// The scale will be clamped between this and [maxScale] inclusively. + /// + /// Scale is also affected by [boundaryMargin]. If the scale would result in + /// viewing beyond the boundary, then it will not be allowed. By default, + /// boundaryMargin is EdgeInsets.zero, so scaling below 1.0 will not be + /// allowed in most cases without first increasing the boundaryMargin. + /// + /// Defaults to 0.8. + /// + /// Must be a finite number greater than zero and less than [maxScale]. + final double minScale; + + /// Changes the deceleration behavior after a gesture. + /// + /// Defaults to 0.0000135. + /// + /// Must be a finite number greater than zero. + final double interactionEndFrictionCoefficient; + + /// Called when the user ends a pan or scale gesture on the widget. + /// + /// At the time this is called, the [TransformationController] will have + /// already been updated to reflect the change caused by the interaction, + /// though a pan may cause an inertia animation after this is called as well. + /// + /// {@template flutter.widgets.InteractiveViewer.onInteractionEnd} + /// Will be called even if the interaction is disabled with [panEnabled] or + /// [scaleEnabled] for both touch gestures and mouse interactions. + /// + /// A [GestureDetector] wrapping the InteractiveViewer will not respond to + /// [GestureDetector.onScaleStart], [GestureDetector.onScaleUpdate], and + /// [GestureDetector.onScaleEnd]. Use [onInteractionStart], + /// [onInteractionUpdate], and [onInteractionEnd] to respond to those + /// gestures. + /// {@endtemplate} + /// + /// See also: + /// + /// * [onInteractionStart], which handles the start of the same interaction. + /// * [onInteractionUpdate], which handles an update to the same interaction. + final GestureScaleEndCallback? onInteractionEnd; + + /// Called when the user begins a pan or scale gesture on the widget. + /// + /// At the time this is called, the [TransformationController] will not have + /// changed due to this interaction. + /// + /// {@macro flutter.widgets.InteractiveViewer.onInteractionEnd} + /// + /// The coordinates provided in the details' `focalPoint` and + /// `localFocalPoint` are normal Flutter event coordinates, not + /// InteractiveViewer scene coordinates. See + /// [TransformationController.toScene] for how to convert these coordinates to + /// scene coordinates relative to the child. + /// + /// See also: + /// + /// * [onInteractionUpdate], which handles an update to the same interaction. + /// * [onInteractionEnd], which handles the end of the same interaction. + final GestureScaleStartCallback? onInteractionStart; + + /// Called when the user updates a pan or scale gesture on the widget. + /// + /// At the time this is called, the [TransformationController] will have + /// already been updated to reflect the change caused by the interaction, if + /// the interaction caused the matrix to change. + /// + /// {@macro flutter.widgets.InteractiveViewer.onInteractionEnd} + /// + /// The coordinates provided in the details' `focalPoint` and + /// `localFocalPoint` are normal Flutter event coordinates, not + /// InteractiveViewer scene coordinates. See + /// [TransformationController.toScene] for how to convert these coordinates to + /// scene coordinates relative to the child. + /// + /// See also: + /// + /// * [onInteractionStart], which handles the start of the same interaction. + /// * [onInteractionEnd], which handles the end of the same interaction. + final GestureScaleUpdateCallback? onInteractionUpdate; + + /// A [TransformationController] for the transformation performed on the + /// child. + /// + /// Whenever the child is transformed, the [Matrix4] value is updated and all + /// listeners are notified. If the value is set, InteractiveViewer will update + /// to respect the new value. + /// + /// {@tool dartpad} + /// This example shows how transformationController can be used to animate the + /// transformation back to its starting position. + /// + /// ** See code in examples/api/lib/widgets/interactive_viewer/interactive_viewer.transformation_controller.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [ValueNotifier], the parent class of TransformationController. + /// * [TextEditingController] for an example of another similar pattern. + final TransformationController? transformationController; + + // Used as the coefficient of friction in the inertial translation animation. + // This value was eyeballed to give a feel similar to Google Photos. + static const double _kDrag = 0.0000135; + + /// Returns the closest point to the given point on the given line segment. + @visibleForTesting + static Vector3 getNearestPointOnLine(Vector3 point, Vector3 l1, Vector3 l2) { + final double lengthSquared = math.pow(l2.x - l1.x, 2.0).toDouble() + + math.pow(l2.y - l1.y, 2.0).toDouble(); + + // In this case, l1 == l2. + if (lengthSquared == 0) { + return l1; + } + + // Calculate how far down the line segment the closest point is and return + // the point. + final Vector3 l1P = point - l1; + final Vector3 l1L2 = l2 - l1; + final double fraction = clampDouble(l1P.dot(l1L2) / lengthSquared, 0.0, 1.0); + return l1 + l1L2 * fraction; + } + + /// Given a quad, return its axis aligned bounding box. + @visibleForTesting + static Quad getAxisAlignedBoundingBox(Quad quad) { + final double minX = math.min( + quad.point0.x, + math.min( + quad.point1.x, + math.min( + quad.point2.x, + quad.point3.x, + ), + ), + ); + final double minY = math.min( + quad.point0.y, + math.min( + quad.point1.y, + math.min( + quad.point2.y, + quad.point3.y, + ), + ), + ); + final double maxX = math.max( + quad.point0.x, + math.max( + quad.point1.x, + math.max( + quad.point2.x, + quad.point3.x, + ), + ), + ); + final double maxY = math.max( + quad.point0.y, + math.max( + quad.point1.y, + math.max( + quad.point2.y, + quad.point3.y, + ), + ), + ); + return Quad.points( + Vector3(minX, minY, 0), + Vector3(maxX, minY, 0), + Vector3(maxX, maxY, 0), + Vector3(minX, maxY, 0), + ); + } + + /// Returns true iff the point is inside the rectangle given by the Quad, + /// inclusively. + /// Algorithm from https://math.stackexchange.com/a/190373. + @visibleForTesting + static bool pointIsInside(Vector3 point, Quad quad) { + final Vector3 aM = point - quad.point0; + final Vector3 aB = quad.point1 - quad.point0; + final Vector3 aD = quad.point3 - quad.point0; + + final double aMAB = aM.dot(aB); + final double aBAB = aB.dot(aB); + final double aMAD = aM.dot(aD); + final double aDAD = aD.dot(aD); + + return 0 <= aMAB && aMAB <= aBAB && 0 <= aMAD && aMAD <= aDAD; + } + + /// Get the point inside (inclusively) the given Quad that is nearest to the + /// given Vector3. + @visibleForTesting + static Vector3 getNearestPointInside(Vector3 point, Quad quad) { + // If the point is inside the axis aligned bounding box, then it's ok where + // it is. + if (pointIsInside(point, quad)) { + return point; + } + + // Otherwise, return the nearest point on the quad. + final List<Vector3> closestPoints = <Vector3>[ + InteractiveViewer.getNearestPointOnLine(point, quad.point0, quad.point1), + InteractiveViewer.getNearestPointOnLine(point, quad.point1, quad.point2), + InteractiveViewer.getNearestPointOnLine(point, quad.point2, quad.point3), + InteractiveViewer.getNearestPointOnLine(point, quad.point3, quad.point0), + ]; + double minDistance = double.infinity; + late Vector3 closestOverall; + for (final Vector3 closePoint in closestPoints) { + final double distance = math.sqrt( + math.pow(point.x - closePoint.x, 2) + math.pow(point.y - closePoint.y, 2), + ); + if (distance < minDistance) { + minDistance = distance; + closestOverall = closePoint; + } + } + return closestOverall; + } + + @override + State<InteractiveViewer> createState() => _InteractiveViewerState(); +} + +class _InteractiveViewerState extends State<InteractiveViewer> with TickerProviderStateMixin { + TransformationController? _transformationController; + + final GlobalKey _childKey = GlobalKey(); + final GlobalKey _parentKey = GlobalKey(); + Animation<Offset>? _animation; + Animation<double>? _scaleAnimation; + late Offset _scaleAnimationFocalPoint; + late AnimationController _controller; + late AnimationController _scaleController; + Axis? _currentAxis; // Used with panAxis. + Offset? _referenceFocalPoint; // Point where the current gesture began. + double? _scaleStart; // Scale value at start of scaling gesture. + double? _rotationStart = 0.0; // Rotation at start of rotation gesture. + double _currentRotation = 0.0; // Rotation of _transformationController.value. + _GestureType? _gestureType; + + // TODO(justinmc): Add rotateEnabled parameter to the widget and remove this + // hardcoded value when the rotation feature is implemented. + // https://github.com/flutter/flutter/issues/57698 + final bool _rotateEnabled = false; + + // The _boundaryRect is calculated by adding the boundaryMargin to the size of + // the child. + Rect get _boundaryRect { + assert(_childKey.currentContext != null); + assert(!widget.boundaryMargin.left.isNaN); + assert(!widget.boundaryMargin.right.isNaN); + assert(!widget.boundaryMargin.top.isNaN); + assert(!widget.boundaryMargin.bottom.isNaN); + + final RenderBox childRenderBox = _childKey.currentContext!.findRenderObject()! as RenderBox; + final Size childSize = childRenderBox.size; + final Rect boundaryRect = widget.boundaryMargin.inflateRect(Offset.zero & childSize); + assert( + !boundaryRect.isEmpty, + "InteractiveViewer's child must have nonzero dimensions.", + ); + // Boundaries that are partially infinite are not allowed because Matrix4's + // rotation and translation methods don't handle infinites well. + assert( + boundaryRect.isFinite || + (boundaryRect.left.isInfinite + && boundaryRect.top.isInfinite + && boundaryRect.right.isInfinite + && boundaryRect.bottom.isInfinite), + 'boundaryRect must either be infinite in all directions or finite in all directions.', + ); + return boundaryRect; + } + + // The Rect representing the child's parent. + Rect get _viewport { + assert(_parentKey.currentContext != null); + final RenderBox parentRenderBox = _parentKey.currentContext!.findRenderObject()! as RenderBox; + return Offset.zero & parentRenderBox.size; + } + + // Return a new matrix representing the given matrix after applying the given + // translation. + Matrix4 _matrixTranslate(Matrix4 matrix, Offset translation) { + if (translation == Offset.zero) { + return matrix.clone(); + } + + late final Offset alignedTranslation; + + if (_currentAxis != null) { + switch (widget.panAxis){ + case PanAxis.horizontal: + alignedTranslation = _alignAxis(translation, Axis.horizontal); + case PanAxis.vertical: + alignedTranslation = _alignAxis(translation, Axis.vertical); + case PanAxis.aligned: + alignedTranslation = _alignAxis(translation, _currentAxis!); + case PanAxis.free: + alignedTranslation = translation; + } + } else { + alignedTranslation = translation; + } + + final Matrix4 nextMatrix = matrix.clone()..translate( + alignedTranslation.dx, + alignedTranslation.dy, + ); + + // Transform the viewport to determine where its four corners will be after + // the child has been transformed. + final Quad nextViewport = _transformViewport(nextMatrix, _viewport); + + // If the boundaries are infinite, then no need to check if the translation + // fits within them. + if (_boundaryRect.isInfinite) { + return nextMatrix; + } + + // Expand the boundaries with rotation. This prevents the problem where a + // mismatch in orientation between the viewport and boundaries effectively + // limits translation. With this approach, all points that are visible with + // no rotation are visible after rotation. + final Quad boundariesAabbQuad = _getAxisAlignedBoundingBoxWithRotation( + _boundaryRect, + _currentRotation, + ); + + // If the given translation fits completely within the boundaries, allow it. + final Offset offendingDistance = _exceedsBy(boundariesAabbQuad, nextViewport); + if (offendingDistance == Offset.zero) { + return nextMatrix; + } + + // Desired translation goes out of bounds, so translate to the nearest + // in-bounds point instead. + final Offset nextTotalTranslation = _getMatrixTranslation(nextMatrix); + final double currentScale = matrix.getMaxScaleOnAxis(); + final Offset correctedTotalTranslation = Offset( + nextTotalTranslation.dx - offendingDistance.dx * currentScale, + nextTotalTranslation.dy - offendingDistance.dy * currentScale, + ); + // TODO(justinmc): This needs some work to handle rotation properly. The + // idea is that the boundaries are axis aligned (boundariesAabbQuad), but + // calculating the translation to put the viewport inside that Quad is more + // complicated than this when rotated. + // https://github.com/flutter/flutter/issues/57698 + final Matrix4 correctedMatrix = matrix.clone()..setTranslation(Vector3( + correctedTotalTranslation.dx, + correctedTotalTranslation.dy, + 0.0, + )); + + // Double check that the corrected translation fits. + final Quad correctedViewport = _transformViewport(correctedMatrix, _viewport); + final Offset offendingCorrectedDistance = _exceedsBy(boundariesAabbQuad, correctedViewport); + if (offendingCorrectedDistance == Offset.zero) { + return correctedMatrix; + } + + // If the corrected translation doesn't fit in either direction, don't allow + // any translation at all. This happens when the viewport is larger than the + // entire boundary. + if (offendingCorrectedDistance.dx != 0.0 && offendingCorrectedDistance.dy != 0.0) { + return matrix.clone(); + } + + // Otherwise, allow translation in only the direction that fits. This + // happens when the viewport is larger than the boundary in one direction. + final Offset unidirectionalCorrectedTotalTranslation = Offset( + offendingCorrectedDistance.dx == 0.0 ? correctedTotalTranslation.dx : 0.0, + offendingCorrectedDistance.dy == 0.0 ? correctedTotalTranslation.dy : 0.0, + ); + return matrix.clone()..setTranslation(Vector3( + unidirectionalCorrectedTotalTranslation.dx, + unidirectionalCorrectedTotalTranslation.dy, + 0.0, + )); + } + + // Return a new matrix representing the given matrix after applying the given + // scale. + Matrix4 _matrixScale(Matrix4 matrix, double scale) { + if (scale == 1.0) { + return matrix.clone(); + } + assert(scale != 0.0); + + // Don't allow a scale that results in an overall scale beyond min/max + // scale. + final double currentScale = _transformationController!.value.getMaxScaleOnAxis(); + final double totalScale = math.max( + currentScale * scale, + // Ensure that the scale cannot make the child so big that it can't fit + // inside the boundaries (in either direction). + math.max( + _viewport.width / _boundaryRect.width, + _viewport.height / _boundaryRect.height, + ), + ); + final double clampedTotalScale = clampDouble(totalScale, + widget.minScale, + widget.maxScale, + ); + final double clampedScale = clampedTotalScale / currentScale; + return matrix.clone()..scale(clampedScale); + } + + // Return a new matrix representing the given matrix after applying the given + // rotation. + Matrix4 _matrixRotate(Matrix4 matrix, double rotation, Offset focalPoint) { + if (rotation == 0) { + return matrix.clone(); + } + final Offset focalPointScene = _transformationController!.toScene( + focalPoint, + ); + return matrix + .clone() + ..translate(focalPointScene.dx, focalPointScene.dy) + ..rotateZ(-rotation) + ..translate(-focalPointScene.dx, -focalPointScene.dy); + } + + // Returns true iff the given _GestureType is enabled. + bool _gestureIsSupported(_GestureType? gestureType) { + switch (gestureType) { + case _GestureType.rotate: + return _rotateEnabled; + + case _GestureType.scale: + return widget.scaleEnabled; + + case _GestureType.pan: + case null: + return widget.panEnabled; + } + } + + // Decide which type of gesture this is by comparing the amount of scale + // and rotation in the gesture, if any. Scale starts at 1 and rotation + // starts at 0. Pan will have no scale and no rotation because it uses only one + // finger. + _GestureType _getGestureType(ScaleUpdateDetails details) { + final double scale = !widget.scaleEnabled ? 1.0 : details.scale; + final double rotation = !_rotateEnabled ? 0.0 : details.rotation; + if ((scale - 1).abs() > rotation.abs()) { + return _GestureType.scale; + } else if (rotation != 0.0) { + return _GestureType.rotate; + } else { + return _GestureType.pan; + } + } + + // Handle the start of a gesture. All of pan, scale, and rotate are handled + // with GestureDetector's scale gesture. + void _onScaleStart(ScaleStartDetails details) { + widget.onInteractionStart?.call(details); + + if (_controller.isAnimating) { + _controller.stop(); + _controller.reset(); + _animation?.removeListener(_onAnimate); + _animation = null; + } + if (_scaleController.isAnimating) { + _scaleController.stop(); + _scaleController.reset(); + _scaleAnimation?.removeListener(_onScaleAnimate); + _scaleAnimation = null; + } + + _gestureType = null; + _currentAxis = null; + _scaleStart = _transformationController!.value.getMaxScaleOnAxis(); + _referenceFocalPoint = _transformationController!.toScene( + details.localFocalPoint, + ); + _rotationStart = _currentRotation; + } + + // Handle an update to an ongoing gesture. All of pan, scale, and rotate are + // handled with GestureDetector's scale gesture. + void _onScaleUpdate(ScaleUpdateDetails details) { + final double scale = _transformationController!.value.getMaxScaleOnAxis(); + _scaleAnimationFocalPoint = details.localFocalPoint; + final Offset focalPointScene = _transformationController!.toScene( + details.localFocalPoint, + ); + + if (_gestureType == _GestureType.pan) { + // When a gesture first starts, it sometimes has no change in scale and + // rotation despite being a two-finger gesture. Here the gesture is + // allowed to be reinterpreted as its correct type after originally + // being marked as a pan. + _gestureType = _getGestureType(details); + } else { + _gestureType ??= _getGestureType(details); + } + if (!_gestureIsSupported(_gestureType)) { + widget.onInteractionUpdate?.call(details); + return; + } + + switch (_gestureType!) { + case _GestureType.scale: + assert(_scaleStart != null); + // details.scale gives us the amount to change the scale as of the + // start of this gesture, so calculate the amount to scale as of the + // previous call to _onScaleUpdate. + final double desiredScale = _scaleStart! * details.scale; + final double scaleChange = desiredScale / scale; + _transformationController!.value = _matrixScale( + _transformationController!.value, + scaleChange, + ); + + // While scaling, translate such that the user's two fingers stay on + // the same places in the scene. That means that the focal point of + // the scale should be on the same place in the scene before and after + // the scale. + final Offset focalPointSceneScaled = _transformationController!.toScene( + details.localFocalPoint, + ); + _transformationController!.value = _matrixTranslate( + _transformationController!.value, + focalPointSceneScaled - _referenceFocalPoint!, + ); + + // details.localFocalPoint should now be at the same location as the + // original _referenceFocalPoint point. If it's not, that's because + // the translate came in contact with a boundary. In that case, update + // _referenceFocalPoint so subsequent updates happen in relation to + // the new effective focal point. + final Offset focalPointSceneCheck = _transformationController!.toScene( + details.localFocalPoint, + ); + if (_round(_referenceFocalPoint!) != _round(focalPointSceneCheck)) { + _referenceFocalPoint = focalPointSceneCheck; + } + + case _GestureType.rotate: + if (details.rotation == 0.0) { + widget.onInteractionUpdate?.call(details); + return; + } + final double desiredRotation = _rotationStart! + details.rotation; + _transformationController!.value = _matrixRotate( + _transformationController!.value, + _currentRotation - desiredRotation, + details.localFocalPoint, + ); + _currentRotation = desiredRotation; + + case _GestureType.pan: + assert(_referenceFocalPoint != null); + // details may have a change in scale here when scaleEnabled is false. + // In an effort to keep the behavior similar whether or not scaleEnabled + // is true, these gestures are thrown away. + if (details.scale != 1.0) { + widget.onInteractionUpdate?.call(details); + return; + } + _currentAxis ??= _getPanAxis(_referenceFocalPoint!, focalPointScene); + // Translate so that the same point in the scene is underneath the + // focal point before and after the movement. + final Offset translationChange = focalPointScene - _referenceFocalPoint!; + _transformationController!.value = _matrixTranslate( + _transformationController!.value, + translationChange, + ); + _referenceFocalPoint = _transformationController!.toScene( + details.localFocalPoint, + ); + } + widget.onInteractionUpdate?.call(details); + } + + // Handle the end of a gesture of _GestureType. All of pan, scale, and rotate + // are handled with GestureDetector's scale gesture. + void _onScaleEnd(ScaleEndDetails details) { + widget.onInteractionEnd?.call(details); + _scaleStart = null; + _rotationStart = null; + _referenceFocalPoint = null; + + _animation?.removeListener(_onAnimate); + _scaleAnimation?.removeListener(_onScaleAnimate); + _controller.reset(); + _scaleController.reset(); + + if (!_gestureIsSupported(_gestureType)) { + _currentAxis = null; + return; + } + + if (_gestureType == _GestureType.pan) { + if (details.velocity.pixelsPerSecond.distance < kMinFlingVelocity) { + _currentAxis = null; + return; + } + final Vector3 translationVector = _transformationController!.value.getTranslation(); + final Offset translation = Offset(translationVector.x, translationVector.y); + final FrictionSimulation frictionSimulationX = FrictionSimulation( + widget.interactionEndFrictionCoefficient, + translation.dx, + details.velocity.pixelsPerSecond.dx, + ); + final FrictionSimulation frictionSimulationY = FrictionSimulation( + widget.interactionEndFrictionCoefficient, + translation.dy, + details.velocity.pixelsPerSecond.dy, + ); + final double tFinal = _getFinalTime( + details.velocity.pixelsPerSecond.distance, + widget.interactionEndFrictionCoefficient, + ); + _animation = Tween<Offset>( + begin: translation, + end: Offset(frictionSimulationX.finalX, frictionSimulationY.finalX), + ).animate(CurvedAnimation( + parent: _controller, + curve: Curves.decelerate, + )); + _controller.duration = Duration(milliseconds: (tFinal * 1000).round()); + _animation!.addListener(_onAnimate); + _controller.forward(); + } else if (_gestureType == _GestureType.scale) { + if (details.scaleVelocity.abs() < 0.1) { + _currentAxis = null; + return; + } + final double scale = _transformationController!.value.getMaxScaleOnAxis(); + final FrictionSimulation frictionSimulation = FrictionSimulation( + widget.interactionEndFrictionCoefficient * widget.scaleFactor, + scale, + details.scaleVelocity / 10 + ); + final double tFinal = _getFinalTime(details.scaleVelocity.abs(), widget.interactionEndFrictionCoefficient, effectivelyMotionless: 0.1); + _scaleAnimation = Tween<double>( + begin: scale, + end: frictionSimulation.x(tFinal) + ).animate(CurvedAnimation( + parent: _scaleController, + curve: Curves.decelerate + )); + _scaleController.duration = Duration(milliseconds: (tFinal * 1000).round()); + _scaleAnimation!.addListener(_onScaleAnimate); + _scaleController.forward(); + } + } + + // Handle mousewheel and web trackpad scroll events. + void _receivedPointerSignal(PointerSignalEvent event) { + final double scaleChange; + if (event is PointerScrollEvent) { + if (event.kind == PointerDeviceKind.trackpad && !widget.trackpadScrollCausesScale) { + // Trackpad scroll, so treat it as a pan. + widget.onInteractionStart?.call( + ScaleStartDetails( + focalPoint: event.position, + localFocalPoint: event.localPosition, + ), + ); + + final Offset localDelta = PointerEvent.transformDeltaViaPositions( + untransformedEndPosition: event.position + event.scrollDelta, + untransformedDelta: event.scrollDelta, + transform: event.transform, + ); + + if (!_gestureIsSupported(_GestureType.pan)) { + widget.onInteractionUpdate?.call(ScaleUpdateDetails( + focalPoint: event.position - event.scrollDelta, + localFocalPoint: event.localPosition - event.scrollDelta, + focalPointDelta: -localDelta, + )); + widget.onInteractionEnd?.call(ScaleEndDetails()); + return; + } + + final Offset focalPointScene = _transformationController!.toScene( + event.localPosition, + ); + + final Offset newFocalPointScene = _transformationController!.toScene( + event.localPosition - localDelta, + ); + + _transformationController!.value = _matrixTranslate( + _transformationController!.value, + newFocalPointScene - focalPointScene + ); + + widget.onInteractionUpdate?.call(ScaleUpdateDetails( + focalPoint: event.position - event.scrollDelta, + localFocalPoint: event.localPosition - localDelta, + focalPointDelta: -localDelta + )); + widget.onInteractionEnd?.call(ScaleEndDetails()); + return; + } + // Ignore left and right mouse wheel scroll. + if (event.scrollDelta.dy == 0.0) { + return; + } + scaleChange = math.exp(-event.scrollDelta.dy / widget.scaleFactor); + } + else if (event is PointerScaleEvent) { + scaleChange = event.scale; + } + else { + return; + } + widget.onInteractionStart?.call( + ScaleStartDetails( + focalPoint: event.position, + localFocalPoint: event.localPosition, + ), + ); + + if (!_gestureIsSupported(_GestureType.scale)) { + widget.onInteractionUpdate?.call(ScaleUpdateDetails( + focalPoint: event.position, + localFocalPoint: event.localPosition, + scale: scaleChange, + )); + widget.onInteractionEnd?.call(ScaleEndDetails()); + return; + } + + final Offset focalPointScene = _transformationController!.toScene( + event.localPosition, + ); + + _transformationController!.value = _matrixScale( + _transformationController!.value, + scaleChange, + ); + + // After scaling, translate such that the event's position is at the + // same scene point before and after the scale. + final Offset focalPointSceneScaled = _transformationController!.toScene( + event.localPosition, + ); + _transformationController!.value = _matrixTranslate( + _transformationController!.value, + focalPointSceneScaled - focalPointScene, + ); + + widget.onInteractionUpdate?.call(ScaleUpdateDetails( + focalPoint: event.position, + localFocalPoint: event.localPosition, + scale: scaleChange, + )); + widget.onInteractionEnd?.call(ScaleEndDetails()); + } + + // Handle inertia drag animation. + void _onAnimate() { + if (!_controller.isAnimating) { + _currentAxis = null; + _animation?.removeListener(_onAnimate); + _animation = null; + _controller.reset(); + return; + } + // Translate such that the resulting translation is _animation.value. + final Vector3 translationVector = _transformationController!.value.getTranslation(); + final Offset translation = Offset(translationVector.x, translationVector.y); + final Offset translationScene = _transformationController!.toScene( + translation, + ); + final Offset animationScene = _transformationController!.toScene( + _animation!.value, + ); + final Offset translationChangeScene = animationScene - translationScene; + _transformationController!.value = _matrixTranslate( + _transformationController!.value, + translationChangeScene, + ); + } + + // Handle inertia scale animation. + void _onScaleAnimate() { + if (!_scaleController.isAnimating) { + _currentAxis = null; + _scaleAnimation?.removeListener(_onScaleAnimate); + _scaleAnimation = null; + _scaleController.reset(); + return; + } + final double desiredScale = _scaleAnimation!.value; + final double scaleChange = desiredScale / _transformationController!.value.getMaxScaleOnAxis(); + final Offset referenceFocalPoint = _transformationController!.toScene( + _scaleAnimationFocalPoint, + ); + _transformationController!.value = _matrixScale( + _transformationController!.value, + scaleChange, + ); + + // While scaling, translate such that the user's two fingers stay on + // the same places in the scene. That means that the focal point of + // the scale should be on the same place in the scene before and after + // the scale. + final Offset focalPointSceneScaled = _transformationController!.toScene( + _scaleAnimationFocalPoint, + ); + _transformationController!.value = _matrixTranslate( + _transformationController!.value, + focalPointSceneScaled - referenceFocalPoint, + ); + } + + void _onTransformationControllerChange() { + // A change to the TransformationController's value is a change to the + // state. + setState(() {}); + } + + @override + void initState() { + super.initState(); + + _transformationController = widget.transformationController + ?? TransformationController(); + _transformationController!.addListener(_onTransformationControllerChange); + _controller = AnimationController( + vsync: this, + ); + _scaleController = AnimationController( + vsync: this + ); + } + + @override + void didUpdateWidget(InteractiveViewer oldWidget) { + super.didUpdateWidget(oldWidget); + // Handle all cases of needing to dispose and initialize + // transformationControllers. + if (oldWidget.transformationController == null) { + if (widget.transformationController != null) { + _transformationController!.removeListener(_onTransformationControllerChange); + _transformationController!.dispose(); + _transformationController = widget.transformationController; + _transformationController!.addListener(_onTransformationControllerChange); + } + } else { + if (widget.transformationController == null) { + _transformationController!.removeListener(_onTransformationControllerChange); + _transformationController = TransformationController(); + _transformationController!.addListener(_onTransformationControllerChange); + } else if (widget.transformationController != oldWidget.transformationController) { + _transformationController!.removeListener(_onTransformationControllerChange); + _transformationController = widget.transformationController; + _transformationController!.addListener(_onTransformationControllerChange); + } + } + } + + @override + void dispose() { + _controller.dispose(); + _scaleController.dispose(); + _transformationController!.removeListener(_onTransformationControllerChange); + if (widget.transformationController == null) { + _transformationController!.dispose(); + } + super.dispose(); + } + + @override + Widget build(BuildContext context) { + Widget child; + if (widget.child != null) { + child = _InteractiveViewerBuilt( + childKey: _childKey, + clipBehavior: widget.clipBehavior, + constrained: widget.constrained, + matrix: _transformationController!.value, + alignment: widget.alignment, + child: widget.child!, + ); + } else { + // When using InteractiveViewer.builder, then constrained is false and the + // viewport is the size of the constraints. + assert(widget.builder != null); + assert(!widget.constrained); + child = LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + final Matrix4 matrix = _transformationController!.value; + return _InteractiveViewerBuilt( + childKey: _childKey, + clipBehavior: widget.clipBehavior, + constrained: widget.constrained, + alignment: widget.alignment, + matrix: matrix, + child: widget.builder!( + context, + _transformViewport(matrix, Offset.zero & constraints.biggest), + ), + ); + }, + ); + } + + return Listener( + key: _parentKey, + onPointerSignal: _receivedPointerSignal, + child: GestureDetector( + behavior: HitTestBehavior.opaque, // Necessary when panning off screen. + onScaleEnd: _onScaleEnd, + onScaleStart: _onScaleStart, + onScaleUpdate: _onScaleUpdate, + trackpadScrollCausesScale: widget.trackpadScrollCausesScale, + trackpadScrollToScaleFactor: Offset(0, -1/widget.scaleFactor), + child: child, + ), + ); + } +} + +// This widget allows us to easily swap in and out the LayoutBuilder in +// InteractiveViewer's depending on if it's using a builder or a child. +class _InteractiveViewerBuilt extends StatelessWidget { + const _InteractiveViewerBuilt({ + required this.child, + required this.childKey, + required this.clipBehavior, + required this.constrained, + required this.matrix, + required this.alignment, + }); + + final Widget child; + final GlobalKey childKey; + final Clip clipBehavior; + final bool constrained; + final Matrix4 matrix; + final Alignment? alignment; + + @override + Widget build(BuildContext context) { + Widget child = Transform( + transform: matrix, + alignment: alignment, + child: KeyedSubtree( + key: childKey, + child: this.child, + ), + ); + + if (!constrained) { + child = OverflowBox( + alignment: Alignment.topLeft, + minWidth: 0.0, + minHeight: 0.0, + maxWidth: double.infinity, + maxHeight: double.infinity, + child: child, + ); + } + + return ClipRect( + clipBehavior: clipBehavior, + child: child, + ); + } +} + +/// A thin wrapper on [ValueNotifier] whose value is a [Matrix4] representing a +/// transformation. +/// +/// The [value] defaults to the identity matrix, which corresponds to no +/// transformation. +/// +/// See also: +/// +/// * [InteractiveViewer.transformationController] for detailed documentation +/// on how to use TransformationController with [InteractiveViewer]. +class TransformationController extends ValueNotifier<Matrix4> { + /// Create an instance of [TransformationController]. + /// + /// The [value] defaults to the identity matrix, which corresponds to no + /// transformation. + TransformationController([Matrix4? value]) : super(value ?? Matrix4.identity()); + + /// Return the scene point at the given viewport point. + /// + /// A viewport point is relative to the parent while a scene point is relative + /// to the child, regardless of transformation. Calling toScene with a + /// viewport point essentially returns the scene coordinate that lies + /// underneath the viewport point given the transform. + /// + /// The viewport transforms as the inverse of the child (i.e. moving the child + /// left is equivalent to moving the viewport right). + /// + /// This method is often useful when determining where an event on the parent + /// occurs on the child. This example shows how to determine where a tap on + /// the parent occurred on the child. + /// + /// ```dart + /// @override + /// Widget build(BuildContext context) { + /// return GestureDetector( + /// onTapUp: (TapUpDetails details) { + /// _childWasTappedAt = _transformationController.toScene( + /// details.localPosition, + /// ); + /// }, + /// child: InteractiveViewer( + /// transformationController: _transformationController, + /// child: child, + /// ), + /// ); + /// } + /// ``` + Offset toScene(Offset viewportPoint) { + // On viewportPoint, perform the inverse transformation of the scene to get + // where the point would be in the scene before the transformation. + final Matrix4 inverseMatrix = Matrix4.inverted(value); + final Vector3 untransformed = inverseMatrix.transform3(Vector3( + viewportPoint.dx, + viewportPoint.dy, + 0, + )); + return Offset(untransformed.x, untransformed.y); + } +} + +// A classification of relevant user gestures. Each contiguous user gesture is +// represented by exactly one _GestureType. +enum _GestureType { + pan, + scale, + rotate, +} + +// Given a velocity and drag, calculate the time at which motion will come to +// a stop, within the margin of effectivelyMotionless. +double _getFinalTime(double velocity, double drag, {double effectivelyMotionless = 10}) { + return math.log(effectivelyMotionless / velocity) / math.log(drag / 100); +} + +// Return the translation from the given Matrix4 as an Offset. +Offset _getMatrixTranslation(Matrix4 matrix) { + final Vector3 nextTranslation = matrix.getTranslation(); + return Offset(nextTranslation.x, nextTranslation.y); +} + +// Transform the four corners of the viewport by the inverse of the given +// matrix. This gives the viewport after the child has been transformed by the +// given matrix. The viewport transforms as the inverse of the child (i.e. +// moving the child left is equivalent to moving the viewport right). +Quad _transformViewport(Matrix4 matrix, Rect viewport) { + final Matrix4 inverseMatrix = matrix.clone()..invert(); + return Quad.points( + inverseMatrix.transform3(Vector3( + viewport.topLeft.dx, + viewport.topLeft.dy, + 0.0, + )), + inverseMatrix.transform3(Vector3( + viewport.topRight.dx, + viewport.topRight.dy, + 0.0, + )), + inverseMatrix.transform3(Vector3( + viewport.bottomRight.dx, + viewport.bottomRight.dy, + 0.0, + )), + inverseMatrix.transform3(Vector3( + viewport.bottomLeft.dx, + viewport.bottomLeft.dy, + 0.0, + )), + ); +} + +// Find the axis aligned bounding box for the rect rotated about its center by +// the given amount. +Quad _getAxisAlignedBoundingBoxWithRotation(Rect rect, double rotation) { + final Matrix4 rotationMatrix = Matrix4.identity() + ..translate(rect.size.width / 2, rect.size.height / 2) + ..rotateZ(rotation) + ..translate(-rect.size.width / 2, -rect.size.height / 2); + final Quad boundariesRotated = Quad.points( + rotationMatrix.transform3(Vector3(rect.left, rect.top, 0.0)), + rotationMatrix.transform3(Vector3(rect.right, rect.top, 0.0)), + rotationMatrix.transform3(Vector3(rect.right, rect.bottom, 0.0)), + rotationMatrix.transform3(Vector3(rect.left, rect.bottom, 0.0)), + ); + return InteractiveViewer.getAxisAlignedBoundingBox(boundariesRotated); +} + +// Return the amount that viewport lies outside of boundary. If the viewport +// is completely contained within the boundary (inclusively), then returns +// Offset.zero. +Offset _exceedsBy(Quad boundary, Quad viewport) { + final List<Vector3> viewportPoints = <Vector3>[ + viewport.point0, viewport.point1, viewport.point2, viewport.point3, + ]; + Offset largestExcess = Offset.zero; + for (final Vector3 point in viewportPoints) { + final Vector3 pointInside = InteractiveViewer.getNearestPointInside(point, boundary); + final Offset excess = Offset( + pointInside.x - point.x, + pointInside.y - point.y, + ); + if (excess.dx.abs() > largestExcess.dx.abs()) { + largestExcess = Offset(excess.dx, largestExcess.dy); + } + if (excess.dy.abs() > largestExcess.dy.abs()) { + largestExcess = Offset(largestExcess.dx, excess.dy); + } + } + + return _round(largestExcess); +} + +// Round the output values. This works around a precision problem where +// values that should have been zero were given as within 10^-10 of zero. +Offset _round(Offset offset) { + return Offset( + double.parse(offset.dx.toStringAsFixed(9)), + double.parse(offset.dy.toStringAsFixed(9)), + ); +} + +// Align the given offset to the given axis by allowing movement only in the +// axis direction. +Offset _alignAxis(Offset offset, Axis axis) { + switch (axis) { + case Axis.horizontal: + return Offset(offset.dx, 0.0); + case Axis.vertical: + return Offset(0.0, offset.dy); + } +} + +// Given two points, return the axis where the distance between the points is +// greatest. If they are equal, return null. +Axis? _getPanAxis(Offset point1, Offset point2) { + if (point1 == point2) { + return null; + } + final double x = point2.dx - point1.dx; + final double y = point2.dy - point1.dy; + return x.abs() > y.abs() ? Axis.horizontal : Axis.vertical; +} + +/// This enum is used to specify the behavior of the [InteractiveViewer] when +/// the user drags the viewport. +enum PanAxis{ + /// The user can only pan the viewport along the horizontal axis. + horizontal, + + /// The user can only pan the viewport along the vertical axis. + vertical, + + /// The user can pan the viewport along the horizontal and vertical axes + /// but not diagonally. + aligned, + + /// The user can pan the viewport freely in any direction. + free, +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/keyboard_listener.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/keyboard_listener.dart new file mode 100644 index 0000000000000000000000000000000000000000..8c3a2ea6571a53f44de21364a0a5b63b71c600ae --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/keyboard_listener.dart @@ -0,0 +1,81 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; + +export 'package:flutter/services.dart' show KeyEvent; + +/// A widget that calls a callback whenever the user presses or releases a key +/// on a keyboard. +/// +/// A [KeyboardListener] is useful for listening to key events and +/// hardware buttons that are represented as keys. Typically used by games and +/// other apps that use keyboards for purposes other than text entry. +/// +/// For text entry, consider using a [EditableText], which integrates with +/// on-screen keyboards and input method editors (IMEs). +/// +/// See also: +/// +/// * [EditableText], which should be used instead of this widget for text +/// entry. +class KeyboardListener extends StatelessWidget { + /// Creates a widget that receives keyboard events. + /// + /// For text entry, consider using a [EditableText], which integrates with + /// on-screen keyboards and input method editors (IMEs). + /// + /// The `key` is an identifier for widgets, and is unrelated to keyboards. + /// See [Widget.key]. + const KeyboardListener({ + super.key, + required this.focusNode, + this.autofocus = false, + this.includeSemantics = true, + this.onKeyEvent, + required this.child, + }); + + /// Controls whether this widget has keyboard focus. + final FocusNode focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@macro flutter.widgets.Focus.includeSemantics} + final bool includeSemantics; + + /// Called whenever this widget receives a keyboard event. + final ValueChanged<KeyEvent>? onKeyEvent; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + return Focus( + focusNode: focusNode, + autofocus: autofocus, + includeSemantics: includeSemantics, + onKeyEvent: (FocusNode node, KeyEvent event) { + onKeyEvent?.call(event); + return KeyEventResult.ignored; + }, + child: child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/layout_builder.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/layout_builder.dart new file mode 100644 index 0000000000000000000000000000000000000000..df503e720c6a61af38eea8142e25ca4253be689c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/layout_builder.dart @@ -0,0 +1,391 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'debug.dart'; +import 'framework.dart'; + +/// The signature of the [LayoutBuilder] builder function. +typedef LayoutWidgetBuilder = Widget Function(BuildContext context, BoxConstraints constraints); + +/// An abstract superclass for widgets that defer their building until layout. +/// +/// Similar to the [Builder] widget except that the framework calls the [builder] +/// function at layout time and provides the constraints that this widget should +/// adhere to. This is useful when the parent constrains the child's size and layout, +/// and doesn't depend on the child's intrinsic size. +/// +/// {@template flutter.widgets.ConstrainedLayoutBuilder} +/// The [builder] function is called in the following situations: +/// +/// * The first time the widget is laid out. +/// * When the parent widget passes different layout constraints. +/// * When the parent widget updates this widget. +/// * When the dependencies that the [builder] function subscribes to change. +/// +/// The [builder] function is _not_ called during layout if the parent passes +/// the same constraints repeatedly. +/// {@endtemplate} +/// +/// Subclasses must return a [RenderObject] that mixes in +/// [RenderConstrainedLayoutBuilder]. +abstract class ConstrainedLayoutBuilder<ConstraintType extends Constraints> extends RenderObjectWidget { + /// Creates a widget that defers its building until layout. + const ConstrainedLayoutBuilder({ + super.key, + required this.builder, + }); + + @override + RenderObjectElement createElement() => _LayoutBuilderElement<ConstraintType>(this); + + /// Called at layout time to construct the widget tree. + /// + /// The builder must not return null. + final Widget Function(BuildContext context, ConstraintType constraints) builder; + + /// Whether [builder] needs to be called again even if the layout constraints + /// are the same. + /// + /// When this widget's configuration is updated, the [builder] callback most + /// likely needs to be called to build this widget's child. However, + /// subclasses may provide ways in which the widget can be updated without + /// needing to rebuild the child. Such subclasses can use this method to tell + /// the framework when the child widget should be rebuilt. + /// + /// When this method is called by the framework, the newly configured widget + /// is asked if it requires a rebuild, and it is passed the old widget as a + /// parameter. + /// + /// See also: + /// + /// * [State.setState] and [State.didUpdateWidget], which talk about widget + /// configuration changes and how they're triggered. + /// * [Element.update], the method that actually updates the widget's + /// configuration. + @protected + bool updateShouldRebuild(covariant ConstrainedLayoutBuilder<ConstraintType> oldWidget) => true; + + // updateRenderObject is redundant with the logic in the LayoutBuilderElement below. +} + +class _LayoutBuilderElement<ConstraintType extends Constraints> extends RenderObjectElement { + _LayoutBuilderElement(ConstrainedLayoutBuilder<ConstraintType> super.widget); + + @override + RenderConstrainedLayoutBuilder<ConstraintType, RenderObject> get renderObject => super.renderObject as RenderConstrainedLayoutBuilder<ConstraintType, RenderObject>; + + Element? _child; + + @override + void visitChildren(ElementVisitor visitor) { + if (_child != null) { + visitor(_child!); + } + } + + @override + void forgetChild(Element child) { + assert(child == _child); + _child = null; + super.forgetChild(child); + } + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); // Creates the renderObject. + renderObject.updateCallback(_layout); + } + + @override + void update(ConstrainedLayoutBuilder<ConstraintType> newWidget) { + assert(widget != newWidget); + final ConstrainedLayoutBuilder<ConstraintType> oldWidget = widget as ConstrainedLayoutBuilder<ConstraintType>; + super.update(newWidget); + assert(widget == newWidget); + + renderObject.updateCallback(_layout); + if (newWidget.updateShouldRebuild(oldWidget)) { + renderObject.markNeedsBuild(); + } + } + + @override + void performRebuild() { + // This gets called if markNeedsBuild() is called on us. + // That might happen if, e.g., our builder uses Inherited widgets. + + // Force the callback to be called, even if the layout constraints are the + // same. This is because that callback may depend on the updated widget + // configuration, or an inherited widget. + renderObject.markNeedsBuild(); + super.performRebuild(); // Calls widget.updateRenderObject (a no-op in this case). + } + + @override + void unmount() { + renderObject.updateCallback(null); + super.unmount(); + } + + void _layout(ConstraintType constraints) { + @pragma('vm:notify-debugger-on-exception') + void layoutCallback() { + Widget built; + try { + built = (widget as ConstrainedLayoutBuilder<ConstraintType>).builder(this, constraints); + debugWidgetBuilderValue(widget, built); + } catch (e, stack) { + built = ErrorWidget.builder( + _reportException( + ErrorDescription('building $widget'), + e, + stack, + informationCollector: () => <DiagnosticsNode>[ + if (kDebugMode) + DiagnosticsDebugCreator(DebugCreator(this)), + ], + ), + ); + } + try { + _child = updateChild(_child, built, null); + assert(_child != null); + } catch (e, stack) { + built = ErrorWidget.builder( + _reportException( + ErrorDescription('building $widget'), + e, + stack, + informationCollector: () => <DiagnosticsNode>[ + if (kDebugMode) + DiagnosticsDebugCreator(DebugCreator(this)), + ], + ), + ); + _child = updateChild(null, built, slot); + } + } + + owner!.buildScope(this, layoutCallback); + } + + @override + void insertRenderObjectChild(RenderObject child, Object? slot) { + final RenderObjectWithChildMixin<RenderObject> renderObject = this.renderObject; + assert(slot == null); + assert(renderObject.debugValidateChild(child)); + renderObject.child = child; + assert(renderObject == this.renderObject); + } + + @override + void moveRenderObjectChild(RenderObject child, Object? oldSlot, Object? newSlot) { + assert(false); + } + + @override + void removeRenderObjectChild(RenderObject child, Object? slot) { + final RenderConstrainedLayoutBuilder<ConstraintType, RenderObject> renderObject = this.renderObject; + assert(renderObject.child == child); + renderObject.child = null; + assert(renderObject == this.renderObject); + } +} + +/// Generic mixin for [RenderObject]s created by [ConstrainedLayoutBuilder]. +/// +/// Provides a callback that should be called at layout time, typically in +/// [RenderObject.performLayout]. +mixin RenderConstrainedLayoutBuilder<ConstraintType extends Constraints, ChildType extends RenderObject> on RenderObjectWithChildMixin<ChildType> { + LayoutCallback<ConstraintType>? _callback; + /// Change the layout callback. + void updateCallback(LayoutCallback<ConstraintType>? value) { + if (value == _callback) { + return; + } + _callback = value; + markNeedsLayout(); + } + + bool _needsBuild = true; + + /// Marks this layout builder as needing to rebuild. + /// + /// The layout build rebuilds automatically when layout constraints change. + /// However, we must also rebuild when the widget updates, e.g. after + /// [State.setState], or [State.didChangeDependencies], even when the layout + /// constraints remain unchanged. + /// + /// See also: + /// + /// * [ConstrainedLayoutBuilder.builder], which is called during the rebuild. + void markNeedsBuild() { + // Do not call the callback directly. It must be called during the layout + // phase, when parent constraints are available. Calling `markNeedsLayout` + // will cause it to be called at the right time. + _needsBuild = true; + markNeedsLayout(); + } + + // The constraints that were passed to this class last time it was laid out. + // These constraints are compared to the new constraints to determine whether + // [ConstrainedLayoutBuilder.builder] needs to be called. + Constraints? _previousConstraints; + + /// Invoke the callback supplied via [updateCallback]. + /// + /// Typically this results in [ConstrainedLayoutBuilder.builder] being called + /// during layout. + void rebuildIfNecessary() { + assert(_callback != null); + if (_needsBuild || constraints != _previousConstraints) { + _previousConstraints = constraints; + _needsBuild = false; + invokeLayoutCallback(_callback!); + } + } +} + +/// Builds a widget tree that can depend on the parent widget's size. +/// +/// Similar to the [Builder] widget except that the framework calls the [builder] +/// function at layout time and provides the parent widget's constraints. This +/// is useful when the parent constrains the child's size and doesn't depend on +/// the child's intrinsic size. The [LayoutBuilder]'s final size will match its +/// child's size. +/// +/// {@macro flutter.widgets.ConstrainedLayoutBuilder} +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=IYDVcriKjsw} +/// +/// If the child should be smaller than the parent, consider wrapping the child +/// in an [Align] widget. If the child might want to be bigger, consider +/// wrapping it in a [SingleChildScrollView] or [OverflowBox]. +/// +/// {@tool dartpad} +/// This example uses a [LayoutBuilder] to build a different widget depending on the available width. Resize the +/// DartPad window to see [LayoutBuilder] in action! +/// +/// ** See code in examples/api/lib/widgets/layout_builder/layout_builder.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverLayoutBuilder], the sliver counterpart of this widget. +/// * [Builder], which calls a `builder` function at build time. +/// * [StatefulBuilder], which passes its `builder` function a `setState` callback. +/// * [CustomSingleChildLayout], which positions its child during layout. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class LayoutBuilder extends ConstrainedLayoutBuilder<BoxConstraints> { + /// Creates a widget that defers its building until layout. + const LayoutBuilder({ + super.key, + required super.builder, + }); + + @override + RenderObject createRenderObject(BuildContext context) => _RenderLayoutBuilder(); +} + +class _RenderLayoutBuilder extends RenderBox with RenderObjectWithChildMixin<RenderBox>, RenderConstrainedLayoutBuilder<BoxConstraints, RenderBox> { + @override + double computeMinIntrinsicWidth(double height) { + assert(_debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + assert(_debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + assert(_debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + assert(_debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + assert(debugCannotComputeDryLayout(reason: + 'Calculating the dry layout would require running the layout callback ' + 'speculatively, which might mutate the live render object tree.', + )); + return Size.zero; + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + rebuildIfNecessary(); + if (child != null) { + child!.layout(constraints, parentUsesSize: true); + size = constraints.constrain(child!.size); + } else { + size = constraints.biggest; + } + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + if (child != null) { + return child!.getDistanceToActualBaseline(baseline); + } + return super.computeDistanceToActualBaseline(baseline); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + return child?.hitTest(result, position: position) ?? false; + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + context.paintChild(child!, offset); + } + } + + bool _debugThrowIfNotCheckingIntrinsics() { + assert(() { + if (!RenderObject.debugCheckingIntrinsics) { + throw FlutterError( + 'LayoutBuilder does not support returning intrinsic dimensions.\n' + 'Calculating the intrinsic dimensions would require running the layout ' + 'callback speculatively, which might mutate the live render object tree.', + ); + } + return true; + }()); + + return true; + } +} + +FlutterErrorDetails _reportException( + DiagnosticsNode context, + Object exception, + StackTrace stack, { + InformationCollector? informationCollector, +}) { + final FlutterErrorDetails details = FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets library', + context: context, + informationCollector: informationCollector, + ); + FlutterError.reportError(details); + return details; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..ba52e9b2bd4c0215d0ea42f3e414ddad73b2e46f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart @@ -0,0 +1,1059 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:math' as math; + +import 'package:flutter/physics.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'notification_listener.dart'; +import 'scroll_configuration.dart'; +import 'scroll_context.dart'; +import 'scroll_controller.dart'; +import 'scroll_metrics.dart'; +import 'scroll_notification.dart'; +import 'scroll_physics.dart'; +import 'scroll_position.dart'; +import 'scroll_position_with_single_context.dart'; +import 'scrollable.dart'; + +/// A delegate that supplies children for [ListWheelScrollView]. +/// +/// [ListWheelScrollView] lazily constructs its children during layout to avoid +/// creating more children than are visible through the [Viewport]. This +/// delegate is responsible for providing children to [ListWheelScrollView] +/// during that stage. +/// +/// See also: +/// +/// * [ListWheelChildListDelegate], a delegate that supplies children using an +/// explicit list. +/// * [ListWheelChildLoopingListDelegate], a delegate that supplies infinite +/// children by looping an explicit list. +/// * [ListWheelChildBuilderDelegate], a delegate that supplies children using +/// a builder callback. +abstract class ListWheelChildDelegate { + /// Return the child at the given index. If the child at the given + /// index does not exist, return null. + Widget? build(BuildContext context, int index); + + /// Returns an estimate of the number of children this delegate will build. + int? get estimatedChildCount; + + /// Returns the true index for a child built at a given index. Defaults to + /// the given index, however if the delegate is [ListWheelChildLoopingListDelegate], + /// this value is the index of the true element that the delegate is looping to. + /// + /// + /// Example: [ListWheelChildLoopingListDelegate] is built by looping a list of + /// length 8. Then, trueIndexOf(10) = 2 and trueIndexOf(-5) = 3. + int trueIndexOf(int index) => index; + + /// Called to check whether this and the old delegate are actually 'different', + /// so that the caller can decide to rebuild or not. + bool shouldRebuild(covariant ListWheelChildDelegate oldDelegate); +} + +/// A delegate that supplies children for [ListWheelScrollView] using an +/// explicit list. +/// +/// [ListWheelScrollView] lazily constructs its children to avoid creating more +/// children than are visible through the [Viewport]. This delegate provides +/// children using an explicit list, which is convenient but reduces the benefit +/// of building children lazily. +/// +/// In general building all the widgets in advance is not efficient. It is +/// better to create a delegate that builds them on demand using +/// [ListWheelChildBuilderDelegate] or by subclassing [ListWheelChildDelegate] +/// directly. +/// +/// This class is provided for the cases where either the list of children is +/// known well in advance (ideally the children are themselves compile-time +/// constants, for example), and therefore will not be built each time the +/// delegate itself is created, or the list is small, such that it's likely +/// always visible (and thus there is nothing to be gained by building it on +/// demand). For example, the body of a dialog box might fit both of these +/// conditions. +class ListWheelChildListDelegate extends ListWheelChildDelegate { + /// Constructs the delegate from a concrete list of children. + ListWheelChildListDelegate({required this.children}); + + /// The list containing all children that can be supplied. + final List<Widget> children; + + @override + int get estimatedChildCount => children.length; + + @override + Widget? build(BuildContext context, int index) { + if (index < 0 || index >= children.length) { + return null; + } + return IndexedSemantics(index: index, child: children[index]); + } + + @override + bool shouldRebuild(covariant ListWheelChildListDelegate oldDelegate) { + return children != oldDelegate.children; + } +} + +/// A delegate that supplies infinite children for [ListWheelScrollView] by +/// looping an explicit list. +/// +/// [ListWheelScrollView] lazily constructs its children to avoid creating more +/// children than are visible through the [Viewport]. This delegate provides +/// children using an explicit list, which is convenient but reduces the benefit +/// of building children lazily. +/// +/// In general building all the widgets in advance is not efficient. It is +/// better to create a delegate that builds them on demand using +/// [ListWheelChildBuilderDelegate] or by subclassing [ListWheelChildDelegate] +/// directly. +/// +/// This class is provided for the cases where either the list of children is +/// known well in advance (ideally the children are themselves compile-time +/// constants, for example), and therefore will not be built each time the +/// delegate itself is created, or the list is small, such that it's likely +/// always visible (and thus there is nothing to be gained by building it on +/// demand). For example, the body of a dialog box might fit both of these +/// conditions. +class ListWheelChildLoopingListDelegate extends ListWheelChildDelegate { + /// Constructs the delegate from a concrete list of children. + ListWheelChildLoopingListDelegate({required this.children}); + + /// The list containing all children that can be supplied. + final List<Widget> children; + + @override + int? get estimatedChildCount => null; + + @override + int trueIndexOf(int index) => index % children.length; + + @override + Widget? build(BuildContext context, int index) { + if (children.isEmpty) { + return null; + } + return IndexedSemantics(index: index, child: children[index % children.length]); + } + + @override + bool shouldRebuild(covariant ListWheelChildLoopingListDelegate oldDelegate) { + return children != oldDelegate.children; + } +} + +/// A delegate that supplies children for [ListWheelScrollView] using a builder +/// callback. +/// +/// [ListWheelScrollView] lazily constructs its children to avoid creating more +/// children than are visible through the [Viewport]. This delegate provides +/// children using an [IndexedWidgetBuilder] callback, so that the children do +/// not have to be built until they are displayed. +class ListWheelChildBuilderDelegate extends ListWheelChildDelegate { + /// Constructs the delegate from a builder callback. + ListWheelChildBuilderDelegate({ + required this.builder, + this.childCount, + }); + + /// Called lazily to build children. + final NullableIndexedWidgetBuilder builder; + + /// {@template flutter.widgets.ListWheelChildBuilderDelegate.childCount} + /// If non-null, [childCount] is the maximum number of children that can be + /// provided, and children are available from 0 to [childCount] - 1. + /// + /// If null, then the lower and upper limit are not known. However the [builder] + /// must provide children for a contiguous segment. If the builder returns null + /// at some index, the segment terminates there. + /// {@endtemplate} + final int? childCount; + + @override + int? get estimatedChildCount => childCount; + + @override + Widget? build(BuildContext context, int index) { + if (childCount == null) { + final Widget? child = builder(context, index); + return child == null ? null : IndexedSemantics(index: index, child: child); + } + if (index < 0 || index >= childCount!) { + return null; + } + return IndexedSemantics(index: index, child: builder(context, index)); + } + + @override + bool shouldRebuild(covariant ListWheelChildBuilderDelegate oldDelegate) { + return builder != oldDelegate.builder || childCount != oldDelegate.childCount; + } +} + +/// A controller for scroll views whose items have the same size. +/// +/// Similar to a standard [ScrollController] but with the added convenience +/// mechanisms to read and go to item indices rather than a raw pixel scroll +/// offset. +/// +/// See also: +/// +/// * [ListWheelScrollView], a scrollable view widget with fixed size items +/// that this widget controls. +/// * [FixedExtentMetrics], the `metrics` property exposed by +/// [ScrollNotification] from [ListWheelScrollView] which can be used +/// to listen to the current item index on a push basis rather than polling +/// the [FixedExtentScrollController]. +class FixedExtentScrollController extends ScrollController { + /// Creates a scroll controller for scrollables whose items have the same size. + /// + /// [initialItem] defaults to zero. + FixedExtentScrollController({ + this.initialItem = 0, + super.onAttach, + super.onDetach, + }); + + /// The page to show when first creating the scroll view. + /// + /// Defaults to zero. + final int initialItem; + + /// The currently selected item index that's closest to the center of the viewport. + /// + /// There are circumstances that this [FixedExtentScrollController] can't know + /// the current item. Reading [selectedItem] will throw an [AssertionError] in + /// the following cases: + /// + /// 1. No scroll view is currently using this [FixedExtentScrollController]. + /// 2. More than one scroll views using the same [FixedExtentScrollController]. + /// + /// The [hasClients] property can be used to check if a scroll view is + /// attached prior to accessing [selectedItem]. + int get selectedItem { + assert( + positions.isNotEmpty, + 'FixedExtentScrollController.selectedItem cannot be accessed before a ' + 'scroll view is built with it.', + ); + assert( + positions.length == 1, + 'The selectedItem property cannot be read when multiple scroll views are ' + 'attached to the same FixedExtentScrollController.', + ); + final _FixedExtentScrollPosition position = this.position as _FixedExtentScrollPosition; + return position.itemIndex; + } + + /// Animates the controlled scroll view to the given item index. + /// + /// The animation lasts for the given duration and follows the given curve. + /// The returned [Future] resolves when the animation completes. + Future<void> animateToItem( + int itemIndex, { + required Duration duration, + required Curve curve, + }) async { + if (!hasClients) { + return; + } + + await Future.wait<void>(<Future<void>>[ + for (final _FixedExtentScrollPosition position in positions.cast<_FixedExtentScrollPosition>()) + position.animateTo( + itemIndex * position.itemExtent, + duration: duration, + curve: curve, + ), + ]); + } + + /// Changes which item index is centered in the controlled scroll view. + /// + /// Jumps the item index position from its current value to the given value, + /// without animation, and without checking if the new value is in range. + void jumpToItem(int itemIndex) { + for (final _FixedExtentScrollPosition position in positions.cast<_FixedExtentScrollPosition>()) { + position.jumpTo(itemIndex * position.itemExtent); + } + } + + @override + ScrollPosition createScrollPosition(ScrollPhysics physics, ScrollContext context, ScrollPosition? oldPosition) { + return _FixedExtentScrollPosition( + physics: physics, + context: context, + initialItem: initialItem, + oldPosition: oldPosition, + ); + } +} + +/// Metrics for a [ScrollPosition] to a scroll view with fixed item sizes. +/// +/// The metrics are available on [ScrollNotification]s generated from a scroll +/// views such as [ListWheelScrollView]s with a [FixedExtentScrollController] +/// and exposes the current [itemIndex] and the scroll view's extents. +/// +/// `FixedExtent` refers to the fact that the scrollable items have the same +/// size. This is distinct from `Fixed` in the parent class name's +/// [FixedScrollMetrics] which refers to its immutability. +class FixedExtentMetrics extends FixedScrollMetrics { + /// Creates an immutable snapshot of values associated with a + /// [ListWheelScrollView]. + FixedExtentMetrics({ + required super.minScrollExtent, + required super.maxScrollExtent, + required super.pixels, + required super.viewportDimension, + required super.axisDirection, + required this.itemIndex, + required super.devicePixelRatio, + }); + + @override + FixedExtentMetrics copyWith({ + double? minScrollExtent, + double? maxScrollExtent, + double? pixels, + double? viewportDimension, + AxisDirection? axisDirection, + int? itemIndex, + double? devicePixelRatio, + }) { + return FixedExtentMetrics( + minScrollExtent: minScrollExtent ?? (hasContentDimensions ? this.minScrollExtent : null), + maxScrollExtent: maxScrollExtent ?? (hasContentDimensions ? this.maxScrollExtent : null), + pixels: pixels ?? (hasPixels ? this.pixels : null), + viewportDimension: viewportDimension ?? (hasViewportDimension ? this.viewportDimension : null), + axisDirection: axisDirection ?? this.axisDirection, + itemIndex: itemIndex ?? this.itemIndex, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + ); + } + + /// The scroll view's currently selected item index. + final int itemIndex; +} + +int _getItemFromOffset({ + required double offset, + required double itemExtent, + required double minScrollExtent, + required double maxScrollExtent, +}) { + return (_clipOffsetToScrollableRange(offset, minScrollExtent, maxScrollExtent) / itemExtent).round(); +} + +double _clipOffsetToScrollableRange( + double offset, + double minScrollExtent, + double maxScrollExtent, +) { + return math.min(math.max(offset, minScrollExtent), maxScrollExtent); +} + +/// A [ScrollPositionWithSingleContext] that can only be created based on +/// [_FixedExtentScrollable] and can access its `itemExtent` to derive [itemIndex]. +class _FixedExtentScrollPosition extends ScrollPositionWithSingleContext implements FixedExtentMetrics { + _FixedExtentScrollPosition({ + required super.physics, + required super.context, + required int initialItem, + super.oldPosition, + }) : assert( + context is _FixedExtentScrollableState, + 'FixedExtentScrollController can only be used with ListWheelScrollViews', + ), + super( + initialPixels: _getItemExtentFromScrollContext(context) * initialItem, + ); + + static double _getItemExtentFromScrollContext(ScrollContext context) { + final _FixedExtentScrollableState scrollable = context as _FixedExtentScrollableState; + return scrollable.itemExtent; + } + + double get itemExtent => _getItemExtentFromScrollContext(context); + + @override + int get itemIndex { + return _getItemFromOffset( + offset: pixels, + itemExtent: itemExtent, + minScrollExtent: minScrollExtent, + maxScrollExtent: maxScrollExtent, + ); + } + + @override + FixedExtentMetrics copyWith({ + double? minScrollExtent, + double? maxScrollExtent, + double? pixels, + double? viewportDimension, + AxisDirection? axisDirection, + int? itemIndex, + double? devicePixelRatio, + }) { + return FixedExtentMetrics( + minScrollExtent: minScrollExtent ?? (hasContentDimensions ? this.minScrollExtent : null), + maxScrollExtent: maxScrollExtent ?? (hasContentDimensions ? this.maxScrollExtent : null), + pixels: pixels ?? (hasPixels ? this.pixels : null), + viewportDimension: viewportDimension ?? (hasViewportDimension ? this.viewportDimension : null), + axisDirection: axisDirection ?? this.axisDirection, + itemIndex: itemIndex ?? this.itemIndex, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + ); + } +} + +/// A [Scrollable] which must be given its viewport children's item extent +/// size so it can pass it on ultimately to the [FixedExtentScrollController]. +class _FixedExtentScrollable extends Scrollable { + const _FixedExtentScrollable({ + super.controller, + super.physics, + required this.itemExtent, + required super.viewportBuilder, + super.restorationId, + super.scrollBehavior, + }); + + final double itemExtent; + + @override + _FixedExtentScrollableState createState() => _FixedExtentScrollableState(); +} + +/// This [ScrollContext] is used by [_FixedExtentScrollPosition] to read the +/// prescribed [itemExtent]. +class _FixedExtentScrollableState extends ScrollableState { + double get itemExtent { + // Downcast because only _FixedExtentScrollable can make _FixedExtentScrollableState. + final _FixedExtentScrollable actualWidget = widget as _FixedExtentScrollable; + return actualWidget.itemExtent; + } +} + +/// A snapping physics that always lands directly on items instead of anywhere +/// within the scroll extent. +/// +/// Behaves similarly to a slot machine wheel except the ballistics simulation +/// never overshoots and rolls back within a single item if it's to settle on +/// that item. +/// +/// Must be used with a scrollable that uses a [FixedExtentScrollController]. +/// +/// Defers back to the parent beyond the scroll extents. +class FixedExtentScrollPhysics extends ScrollPhysics { + /// Creates a scroll physics that always lands on items. + const FixedExtentScrollPhysics({ super.parent }); + + @override + FixedExtentScrollPhysics applyTo(ScrollPhysics? ancestor) { + return FixedExtentScrollPhysics(parent: buildParent(ancestor)); + } + + @override + Simulation? createBallisticSimulation(ScrollMetrics position, double velocity) { + assert( + position is _FixedExtentScrollPosition, + 'FixedExtentScrollPhysics can only be used with Scrollables that uses ' + 'the FixedExtentScrollController', + ); + + final _FixedExtentScrollPosition metrics = position as _FixedExtentScrollPosition; + + // Scenario 1: + // If we're out of range and not headed back in range, defer to the parent + // ballistics, which should put us back in range at the scrollable's boundary. + if ((velocity <= 0.0 && metrics.pixels <= metrics.minScrollExtent) || + (velocity >= 0.0 && metrics.pixels >= metrics.maxScrollExtent)) { + return super.createBallisticSimulation(metrics, velocity); + } + + // Create a test simulation to see where it would have ballistically fallen + // naturally without settling onto items. + final Simulation? testFrictionSimulation = + super.createBallisticSimulation(metrics, velocity); + + // Scenario 2: + // If it was going to end up past the scroll extent, defer back to the + // parent physics' ballistics again which should put us on the scrollable's + // boundary. + if (testFrictionSimulation != null + && (testFrictionSimulation.x(double.infinity) == metrics.minScrollExtent + || testFrictionSimulation.x(double.infinity) == metrics.maxScrollExtent)) { + return super.createBallisticSimulation(metrics, velocity); + } + + // From the natural final position, find the nearest item it should have + // settled to. + final int settlingItemIndex = _getItemFromOffset( + offset: testFrictionSimulation?.x(double.infinity) ?? metrics.pixels, + itemExtent: metrics.itemExtent, + minScrollExtent: metrics.minScrollExtent, + maxScrollExtent: metrics.maxScrollExtent, + ); + + final double settlingPixels = settlingItemIndex * metrics.itemExtent; + + // Scenario 3: + // If there's no velocity and we're already at where we intend to land, + // do nothing. + if (velocity.abs() < toleranceFor(position).velocity + && (settlingPixels - metrics.pixels).abs() < toleranceFor(position).distance) { + return null; + } + + // Scenario 4: + // If we're going to end back at the same item because initial velocity + // is too low to break past it, use a spring simulation to get back. + if (settlingItemIndex == metrics.itemIndex) { + return SpringSimulation( + spring, + metrics.pixels, + settlingPixels, + velocity, + tolerance: toleranceFor(position), + ); + } + + // Scenario 5: + // Create a new friction simulation except the drag will be tweaked to land + // exactly on the item closest to the natural stopping point. + return FrictionSimulation.through( + metrics.pixels, + settlingPixels, + velocity, + toleranceFor(position).velocity * velocity.sign, + ); + } +} + +/// A box in which children on a wheel can be scrolled. +/// +/// This widget is similar to a [ListView] but with the restriction that all +/// children must be the same size along the scrolling axis. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=dUhmWAz4C7Y} +/// +/// When the list is at the zero scroll offset, the first child is aligned with +/// the middle of the viewport. When the list is at the final scroll offset, +/// the last child is aligned with the middle of the viewport. +/// +/// The children are rendered as if rotating on a wheel instead of scrolling on +/// a plane. +class ListWheelScrollView extends StatefulWidget { + /// Constructs a list in which children are scrolled a wheel. Its children + /// are passed to a delegate and lazily built during layout. + ListWheelScrollView({ + super.key, + this.controller, + this.physics, + this.diameterRatio = RenderListWheelViewport.defaultDiameterRatio, + this.perspective = RenderListWheelViewport.defaultPerspective, + this.offAxisFraction = 0.0, + this.useMagnifier = false, + this.magnification = 1.0, + this.overAndUnderCenterOpacity = 1.0, + required this.itemExtent, + this.squeeze = 1.0, + this.onSelectedItemChanged, + this.renderChildrenOutsideViewport = false, + this.clipBehavior = Clip.hardEdge, + this.restorationId, + this.scrollBehavior, + required List<Widget> children, + }) : assert(diameterRatio > 0.0, RenderListWheelViewport.diameterRatioZeroMessage), + assert(perspective > 0), + assert(perspective <= 0.01, RenderListWheelViewport.perspectiveTooHighMessage), + assert(magnification > 0), + assert(overAndUnderCenterOpacity >= 0 && overAndUnderCenterOpacity <= 1), + assert(itemExtent > 0), + assert(squeeze > 0), + assert( + !renderChildrenOutsideViewport || clipBehavior == Clip.none, + RenderListWheelViewport.clipBehaviorAndRenderChildrenOutsideViewportConflict, + ), + childDelegate = ListWheelChildListDelegate(children: children); + + /// Constructs a list in which children are scrolled a wheel. Its children + /// are managed by a delegate and are lazily built during layout. + const ListWheelScrollView.useDelegate({ + super.key, + this.controller, + this.physics, + this.diameterRatio = RenderListWheelViewport.defaultDiameterRatio, + this.perspective = RenderListWheelViewport.defaultPerspective, + this.offAxisFraction = 0.0, + this.useMagnifier = false, + this.magnification = 1.0, + this.overAndUnderCenterOpacity = 1.0, + required this.itemExtent, + this.squeeze = 1.0, + this.onSelectedItemChanged, + this.renderChildrenOutsideViewport = false, + this.clipBehavior = Clip.hardEdge, + this.restorationId, + this.scrollBehavior, + required this.childDelegate, + }) : assert(diameterRatio > 0.0, RenderListWheelViewport.diameterRatioZeroMessage), + assert(perspective > 0), + assert(perspective <= 0.01, RenderListWheelViewport.perspectiveTooHighMessage), + assert(magnification > 0), + assert(overAndUnderCenterOpacity >= 0 && overAndUnderCenterOpacity <= 1), + assert(itemExtent > 0), + assert(squeeze > 0), + assert( + !renderChildrenOutsideViewport || clipBehavior == Clip.none, + RenderListWheelViewport.clipBehaviorAndRenderChildrenOutsideViewportConflict, + ); + + /// Typically a [FixedExtentScrollController] used to control the current item. + /// + /// A [FixedExtentScrollController] can be used to read the currently + /// selected/centered child item and can be used to change the current item. + /// + /// If none is provided, a new [FixedExtentScrollController] is implicitly + /// created. + /// + /// If a [ScrollController] is used instead of [FixedExtentScrollController], + /// [ScrollNotification.metrics] will no longer provide [FixedExtentMetrics] + /// to indicate the current item index and [onSelectedItemChanged] will not + /// work. + /// + /// To read the current selected item only when the value changes, use + /// [onSelectedItemChanged]. + final ScrollController? controller; + + /// How the scroll view should respond to user input. + /// + /// For example, determines how the scroll view continues to animate after the + /// user stops dragging the scroll view. + /// + /// If an explicit [ScrollBehavior] is provided to [scrollBehavior], the + /// [ScrollPhysics] provided by that behavior will take precedence after + /// [physics]. + /// + /// Defaults to matching platform conventions. + final ScrollPhysics? physics; + + /// {@macro flutter.rendering.RenderListWheelViewport.diameterRatio} + final double diameterRatio; + + /// {@macro flutter.rendering.RenderListWheelViewport.perspective} + final double perspective; + + /// {@macro flutter.rendering.RenderListWheelViewport.offAxisFraction} + final double offAxisFraction; + + /// {@macro flutter.rendering.RenderListWheelViewport.useMagnifier} + final bool useMagnifier; + + /// {@macro flutter.rendering.RenderListWheelViewport.magnification} + final double magnification; + + /// {@macro flutter.rendering.RenderListWheelViewport.overAndUnderCenterOpacity} + final double overAndUnderCenterOpacity; + + /// Size of each child in the main axis. + /// + /// Must be positive. + final double itemExtent; + + /// {@macro flutter.rendering.RenderListWheelViewport.squeeze} + /// + /// Defaults to 1. + final double squeeze; + + /// On optional listener that's called when the centered item changes. + final ValueChanged<int>? onSelectedItemChanged; + + /// {@macro flutter.rendering.RenderListWheelViewport.renderChildrenOutsideViewport} + final bool renderChildrenOutsideViewport; + + /// A delegate that helps lazily instantiating child. + final ListWheelChildDelegate childDelegate; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// {@macro flutter.widgets.scrollable.restorationId} + final String? restorationId; + + /// {@macro flutter.widgets.shadow.scrollBehavior} + /// + /// [ScrollBehavior]s also provide [ScrollPhysics]. If an explicit + /// [ScrollPhysics] is provided in [physics], it will take precedence, + /// followed by [scrollBehavior], and then the inherited ancestor + /// [ScrollBehavior]. + /// + /// The [ScrollBehavior] of the inherited [ScrollConfiguration] will be + /// modified by default to not apply a [Scrollbar]. + final ScrollBehavior? scrollBehavior; + + @override + State<ListWheelScrollView> createState() => _ListWheelScrollViewState(); +} + +class _ListWheelScrollViewState extends State<ListWheelScrollView> { + int _lastReportedItemIndex = 0; + ScrollController? _backupController; + + ScrollController get _effectiveController => + widget.controller ?? (_backupController ??= FixedExtentScrollController()); + + @override + void initState() { + super.initState(); + if (widget.controller is FixedExtentScrollController) { + final FixedExtentScrollController controller = widget.controller! as FixedExtentScrollController; + _lastReportedItemIndex = controller.initialItem; + } + } + + @override + void dispose() { + _backupController?.dispose(); + super.dispose(); + } + + bool _handleScrollNotification(ScrollNotification notification) { + if (notification.depth == 0 + && widget.onSelectedItemChanged != null + && notification is ScrollUpdateNotification + && notification.metrics is FixedExtentMetrics) { + final FixedExtentMetrics metrics = notification.metrics as FixedExtentMetrics; + final int currentItemIndex = metrics.itemIndex; + if (currentItemIndex != _lastReportedItemIndex) { + _lastReportedItemIndex = currentItemIndex; + final int trueIndex = widget.childDelegate.trueIndexOf(currentItemIndex); + widget.onSelectedItemChanged!(trueIndex); + } + } + return false; + } + + @override + Widget build(BuildContext context) { + return NotificationListener<ScrollNotification>( + onNotification: _handleScrollNotification, + child: _FixedExtentScrollable( + controller: _effectiveController, + physics: widget.physics, + itemExtent: widget.itemExtent, + restorationId: widget.restorationId, + scrollBehavior: widget.scrollBehavior ?? ScrollConfiguration.of(context).copyWith(scrollbars: false), + viewportBuilder: (BuildContext context, ViewportOffset offset) { + return ListWheelViewport( + diameterRatio: widget.diameterRatio, + perspective: widget.perspective, + offAxisFraction: widget.offAxisFraction, + useMagnifier: widget.useMagnifier, + magnification: widget.magnification, + overAndUnderCenterOpacity: widget.overAndUnderCenterOpacity, + itemExtent: widget.itemExtent, + squeeze: widget.squeeze, + renderChildrenOutsideViewport: widget.renderChildrenOutsideViewport, + offset: offset, + childDelegate: widget.childDelegate, + clipBehavior: widget.clipBehavior, + ); + }, + ), + ); + } +} + +/// Element that supports building children lazily for [ListWheelViewport]. +class ListWheelElement extends RenderObjectElement implements ListWheelChildManager { + /// Creates an element that lazily builds children for the given widget. + ListWheelElement(ListWheelViewport super.widget); + + @override + RenderListWheelViewport get renderObject => super.renderObject as RenderListWheelViewport; + + // We inflate widgets at two different times: + // 1. When we ourselves are told to rebuild (see performRebuild). + // 2. When our render object needs a new child (see createChild). + // In both cases, we cache the results of calling into our delegate to get the + // widget, so that if we do case 2 later, we don't call the builder again. + // Any time we do case 1, though, we reset the cache. + + /// A cache of widgets so that we don't have to rebuild every time. + final Map<int, Widget?> _childWidgets = HashMap<int, Widget?>(); + + /// The map containing all active child elements. SplayTreeMap is used so that + /// we have all elements ordered and iterable by their keys. + final SplayTreeMap<int, Element> _childElements = SplayTreeMap<int, Element>(); + + @override + void update(ListWheelViewport newWidget) { + final ListWheelViewport oldWidget = widget as ListWheelViewport; + super.update(newWidget); + final ListWheelChildDelegate newDelegate = newWidget.childDelegate; + final ListWheelChildDelegate oldDelegate = oldWidget.childDelegate; + if (newDelegate != oldDelegate && + (newDelegate.runtimeType != oldDelegate.runtimeType || newDelegate.shouldRebuild(oldDelegate))) { + performRebuild(); + renderObject.markNeedsLayout(); + } + } + + @override + int? get childCount => (widget as ListWheelViewport).childDelegate.estimatedChildCount; + + @override + void performRebuild() { + _childWidgets.clear(); + super.performRebuild(); + if (_childElements.isEmpty) { + return; + } + + final int firstIndex = _childElements.firstKey()!; + final int lastIndex = _childElements.lastKey()!; + + for (int index = firstIndex; index <= lastIndex; ++index) { + final Element? newChild = updateChild(_childElements[index], retrieveWidget(index), index); + if (newChild != null) { + _childElements[index] = newChild; + } else { + _childElements.remove(index); + } + } + } + + /// Asks the underlying delegate for a widget at the given index. + /// + /// Normally the builder is only called once for each index and the result + /// will be cached. However when the element is rebuilt, the cache will be + /// cleared. + Widget? retrieveWidget(int index) { + return _childWidgets.putIfAbsent(index, () => (widget as ListWheelViewport).childDelegate.build(this, index)); + } + + @override + bool childExistsAt(int index) => retrieveWidget(index) != null; + + @override + void createChild(int index, { required RenderBox? after }) { + owner!.buildScope(this, () { + final bool insertFirst = after == null; + assert(insertFirst || _childElements[index - 1] != null); + final Element? newChild = + updateChild(_childElements[index], retrieveWidget(index), index); + if (newChild != null) { + _childElements[index] = newChild; + } else { + _childElements.remove(index); + } + }); + } + + @override + void removeChild(RenderBox child) { + final int index = renderObject.indexOf(child); + owner!.buildScope(this, () { + assert(_childElements.containsKey(index)); + final Element? result = updateChild(_childElements[index], null, index); + assert(result == null); + _childElements.remove(index); + assert(!_childElements.containsKey(index)); + }); + } + + @override + Element? updateChild(Element? child, Widget? newWidget, Object? newSlot) { + final ListWheelParentData? oldParentData = child?.renderObject?.parentData as ListWheelParentData?; + final Element? newChild = super.updateChild(child, newWidget, newSlot); + final ListWheelParentData? newParentData = newChild?.renderObject?.parentData as ListWheelParentData?; + if (newParentData != null) { + newParentData.index = newSlot! as int; + if (oldParentData != null) { + newParentData.offset = oldParentData.offset; + } + } + + return newChild; + } + + @override + void insertRenderObjectChild(RenderObject child, int slot) { + final RenderListWheelViewport renderObject = this.renderObject; + assert(renderObject.debugValidateChild(child)); + renderObject.insert(child as RenderBox, after: _childElements[slot - 1]?.renderObject as RenderBox?); + assert(renderObject == this.renderObject); + } + + @override + void moveRenderObjectChild(RenderObject child, int oldSlot, int newSlot) { + const String moveChildRenderObjectErrorMessage = + 'Currently we maintain the list in contiguous increasing order, so ' + 'moving children around is not allowed.'; + assert(false, moveChildRenderObjectErrorMessage); + } + + @override + void removeRenderObjectChild(RenderObject child, int slot) { + assert(child.parent == renderObject); + renderObject.remove(child as RenderBox); + } + + @override + void visitChildren(ElementVisitor visitor) { + _childElements.forEach((int key, Element child) { + visitor(child); + }); + } + + @override + void forgetChild(Element child) { + _childElements.remove(child.slot); + super.forgetChild(child); + } + +} + +/// A viewport showing a subset of children on a wheel. +/// +/// Typically used with [ListWheelScrollView], this viewport is similar to +/// [Viewport] in that it shows a subset of children in a scrollable based +/// on the scrolling offset and the children's dimensions. But uses +/// [RenderListWheelViewport] to display the children on a wheel. +/// +/// See also: +/// +/// * [ListWheelScrollView], widget that combines this viewport with a scrollable. +/// * [RenderListWheelViewport], the render object that renders the children +/// on a wheel. +class ListWheelViewport extends RenderObjectWidget { + /// Creates a viewport where children are rendered onto a wheel. + /// + /// The [diameterRatio] argument defaults to 2. + /// + /// The [perspective] argument defaults to 0.003. + /// + /// The [itemExtent] argument in pixels must be provided and must be positive. + /// + /// The [clipBehavior] argument defaults to [Clip.hardEdge]. + /// + /// The [renderChildrenOutsideViewport] argument defaults to false and must + /// not be null. + /// + /// The [offset] argument must be provided. + const ListWheelViewport({ + super.key, + this.diameterRatio = RenderListWheelViewport.defaultDiameterRatio, + this.perspective = RenderListWheelViewport.defaultPerspective, + this.offAxisFraction = 0.0, + this.useMagnifier = false, + this.magnification = 1.0, + this.overAndUnderCenterOpacity = 1.0, + required this.itemExtent, + this.squeeze = 1.0, + this.renderChildrenOutsideViewport = false, + required this.offset, + required this.childDelegate, + this.clipBehavior = Clip.hardEdge, + }) : assert(diameterRatio > 0, RenderListWheelViewport.diameterRatioZeroMessage), + assert(perspective > 0), + assert(perspective <= 0.01, RenderListWheelViewport.perspectiveTooHighMessage), + assert(overAndUnderCenterOpacity >= 0 && overAndUnderCenterOpacity <= 1), + assert(itemExtent > 0), + assert(squeeze > 0), + assert( + !renderChildrenOutsideViewport || clipBehavior == Clip.none, + RenderListWheelViewport.clipBehaviorAndRenderChildrenOutsideViewportConflict, + ); + + /// {@macro flutter.rendering.RenderListWheelViewport.diameterRatio} + final double diameterRatio; + + /// {@macro flutter.rendering.RenderListWheelViewport.perspective} + final double perspective; + + /// {@macro flutter.rendering.RenderListWheelViewport.offAxisFraction} + final double offAxisFraction; + + /// {@macro flutter.rendering.RenderListWheelViewport.useMagnifier} + final bool useMagnifier; + + /// {@macro flutter.rendering.RenderListWheelViewport.magnification} + final double magnification; + + /// {@macro flutter.rendering.RenderListWheelViewport.overAndUnderCenterOpacity} + final double overAndUnderCenterOpacity; + + /// {@macro flutter.rendering.RenderListWheelViewport.itemExtent} + final double itemExtent; + + /// {@macro flutter.rendering.RenderListWheelViewport.squeeze} + /// + /// Defaults to 1. + final double squeeze; + + /// {@macro flutter.rendering.RenderListWheelViewport.renderChildrenOutsideViewport} + final bool renderChildrenOutsideViewport; + + /// [ViewportOffset] object describing the content that should be visible + /// in the viewport. + final ViewportOffset offset; + + /// A delegate that lazily instantiates children. + final ListWheelChildDelegate childDelegate; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + @override + ListWheelElement createElement() => ListWheelElement(this); + + @override + RenderListWheelViewport createRenderObject(BuildContext context) { + final ListWheelElement childManager = context as ListWheelElement; + return RenderListWheelViewport( + childManager: childManager, + offset: offset, + diameterRatio: diameterRatio, + perspective: perspective, + offAxisFraction: offAxisFraction, + useMagnifier: useMagnifier, + magnification: magnification, + overAndUnderCenterOpacity: overAndUnderCenterOpacity, + itemExtent: itemExtent, + squeeze: squeeze, + renderChildrenOutsideViewport: renderChildrenOutsideViewport, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderListWheelViewport renderObject) { + renderObject + ..offset = offset + ..diameterRatio = diameterRatio + ..perspective = perspective + ..offAxisFraction = offAxisFraction + ..useMagnifier = useMagnifier + ..magnification = magnification + ..overAndUnderCenterOpacity = overAndUnderCenterOpacity + ..itemExtent = itemExtent + ..squeeze = squeeze + ..renderChildrenOutsideViewport = renderChildrenOutsideViewport + ..clipBehavior = clipBehavior; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/localizations.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/localizations.dart new file mode 100644 index 0000000000000000000000000000000000000000..499e21bdf96f9fd04097d83a68bbc8e3bb818f6a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/localizations.dart @@ -0,0 +1,645 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; + +// Examples can assume: +// class Intl { Intl._(); static String message(String s, { String? name, String? locale }) => ''; } +// Future<void> initializeMessages(String locale) => Future<void>.value(); +// late BuildContext context; +// class Foo { } +// const Widget myWidget = Placeholder(); + +// Used by loadAll() to record LocalizationsDelegate.load() futures we're +// waiting for. +class _Pending { + _Pending(this.delegate, this.futureValue); + final LocalizationsDelegate<dynamic> delegate; + final Future<dynamic> futureValue; +} + +// A utility function used by Localizations to generate one future +// that completes when all of the LocalizationsDelegate.load() futures +// complete. The returned map is indexed by each delegate's type. +// +// The input future values must have distinct types. +// +// The returned Future<Map> will resolve when all of the input map's +// future values have resolved. If all of the input map's values are +// SynchronousFutures then a SynchronousFuture will be returned +// immediately. +// +// This is more complicated than just applying Future.wait to input +// because some of the input.values may be SynchronousFutures. We don't want +// to Future.wait for the synchronous futures. +Future<Map<Type, dynamic>> _loadAll(Locale locale, Iterable<LocalizationsDelegate<dynamic>> allDelegates) { + final Map<Type, dynamic> output = <Type, dynamic>{}; + List<_Pending>? pendingList; + + // Only load the first delegate for each delegate type that supports + // locale.languageCode. + final Set<Type> types = <Type>{}; + final List<LocalizationsDelegate<dynamic>> delegates = <LocalizationsDelegate<dynamic>>[]; + for (final LocalizationsDelegate<dynamic> delegate in allDelegates) { + if (!types.contains(delegate.type) && delegate.isSupported(locale)) { + types.add(delegate.type); + delegates.add(delegate); + } + } + + for (final LocalizationsDelegate<dynamic> delegate in delegates) { + final Future<dynamic> inputValue = delegate.load(locale); + dynamic completedValue; + final Future<dynamic> futureValue = inputValue.then<dynamic>((dynamic value) { + return completedValue = value; + }); + if (completedValue != null) { // inputValue was a SynchronousFuture + final Type type = delegate.type; + assert(!output.containsKey(type)); + output[type] = completedValue; + } else { + pendingList ??= <_Pending>[]; + pendingList.add(_Pending(delegate, futureValue)); + } + } + + // All of the delegate.load() values were synchronous futures, we're done. + if (pendingList == null) { + return SynchronousFuture<Map<Type, dynamic>>(output); + } + + // Some of delegate.load() values were asynchronous futures. Wait for them. + return Future.wait<dynamic>(pendingList.map<Future<dynamic>>((_Pending p) => p.futureValue)) + .then<Map<Type, dynamic>>((List<dynamic> values) { + assert(values.length == pendingList!.length); + for (int i = 0; i < values.length; i += 1) { + final Type type = pendingList![i].delegate.type; + assert(!output.containsKey(type)); + output[type] = values[i]; + } + return output; + }); +} + +/// A factory for a set of localized resources of type `T`, to be loaded by a +/// [Localizations] widget. +/// +/// Typical applications have one [Localizations] widget which is created by the +/// [WidgetsApp] and configured with the app's `localizationsDelegates` +/// parameter (a list of delegates). The delegate's [type] is used to identify +/// the object created by an individual delegate's [load] method. +/// +/// An example of a class used as the value of `T` here would be +/// [MaterialLocalizations]. +abstract class LocalizationsDelegate<T> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const LocalizationsDelegate(); + + /// Whether resources for the given locale can be loaded by this delegate. + /// + /// Return true if the instance of `T` loaded by this delegate's [load] + /// method supports the given `locale`'s language. + bool isSupported(Locale locale); + + /// Start loading the resources for `locale`. The returned future completes + /// when the resources have finished loading. + /// + /// It's assumed that this method will return an object that contains a + /// collection of related string resources (typically defined with one method + /// per resource). The object will be retrieved with [Localizations.of]. + Future<T> load(Locale locale); + + /// Returns true if the resources for this delegate should be loaded + /// again by calling the [load] method. + /// + /// This method is called whenever its [Localizations] widget is + /// rebuilt. If it returns true then dependent widgets will be rebuilt + /// after [load] has completed. + bool shouldReload(covariant LocalizationsDelegate<T> old); + + /// The type of the object returned by the [load] method, T by default. + /// + /// This type is used to retrieve the object "loaded" by this + /// [LocalizationsDelegate] from the [Localizations] inherited widget. + /// For example the object loaded by `LocalizationsDelegate<Foo>` would + /// be retrieved with: + /// + /// ```dart + /// Foo foo = Localizations.of<Foo>(context, Foo)!; + /// ``` + /// + /// It's rarely necessary to override this getter. + Type get type => T; + + @override + String toString() => '${objectRuntimeType(this, 'LocalizationsDelegate')}[$type]'; +} + +/// Interface for localized resource values for the lowest levels of the Flutter +/// framework. +/// +/// This class also maps locales to a specific [Directionality] using the +/// [textDirection] property. +/// +/// See also: +/// +/// * [DefaultWidgetsLocalizations], which implements this interface and +/// supports a variety of locales. +abstract class WidgetsLocalizations { + /// The reading direction for text in this locale. + TextDirection get textDirection; + + /// The semantics label used for [SliverReorderableList] to reorder an item in the + /// list to the start of the list. + String get reorderItemToStart; + + /// The semantics label used for [SliverReorderableList] to reorder an item in the + /// list to the end of the list. + String get reorderItemToEnd; + + /// The semantics label used for [SliverReorderableList] to reorder an item in the + /// list one space up the list. + String get reorderItemUp; + + /// The semantics label used for [SliverReorderableList] to reorder an item in the + /// list one space down the list. + String get reorderItemDown; + + /// The semantics label used for [SliverReorderableList] to reorder an item in the + /// list one space left in the list. + String get reorderItemLeft; + + /// The semantics label used for [SliverReorderableList] to reorder an item in the + /// list one space right in the list. + String get reorderItemRight; + + /// The `WidgetsLocalizations` from the closest [Localizations] instance + /// that encloses the given context. + /// + /// This method is just a convenient shorthand for: + /// `Localizations.of<WidgetsLocalizations>(context, WidgetsLocalizations)!`. + /// + /// References to the localized resources defined by this class are typically + /// written in terms of this method. For example: + /// + /// ```dart + /// textDirection: WidgetsLocalizations.of(context).textDirection, + /// ``` + static WidgetsLocalizations of(BuildContext context) { + assert(debugCheckHasWidgetsLocalizations(context)); + return Localizations.of<WidgetsLocalizations>(context, WidgetsLocalizations)!; + } +} + +class _WidgetsLocalizationsDelegate extends LocalizationsDelegate<WidgetsLocalizations> { + const _WidgetsLocalizationsDelegate(); + + // This is convenient simplification. It would be more correct test if the locale's + // text-direction is LTR. + @override + bool isSupported(Locale locale) => true; + + @override + Future<WidgetsLocalizations> load(Locale locale) => DefaultWidgetsLocalizations.load(locale); + + @override + bool shouldReload(_WidgetsLocalizationsDelegate old) => false; + + @override + String toString() => 'DefaultWidgetsLocalizations.delegate(en_US)'; +} + +/// US English localizations for the widgets library. +/// +/// See also: +/// +/// * [GlobalWidgetsLocalizations], which provides widgets localizations for +/// many languages. +/// * [WidgetsApp.localizationsDelegates], which automatically includes +/// [DefaultWidgetsLocalizations.delegate] by default. +class DefaultWidgetsLocalizations implements WidgetsLocalizations { + /// Construct an object that defines the localized values for the widgets + /// library for US English (only). + /// + /// [LocalizationsDelegate] implementations typically call the static [load] + const DefaultWidgetsLocalizations(); + + @override + String get reorderItemUp => 'Move up'; + + @override + String get reorderItemDown => 'Move down'; + + @override + String get reorderItemLeft => 'Move left'; + + @override + String get reorderItemRight => 'Move right'; + + @override + String get reorderItemToEnd => 'Move to the end'; + + @override + String get reorderItemToStart => 'Move to the start'; + + @override + TextDirection get textDirection => TextDirection.ltr; + + /// Creates an object that provides US English resource values for the + /// lowest levels of the widgets library. + /// + /// The [locale] parameter is ignored. + /// + /// This method is typically used to create a [LocalizationsDelegate]. + /// The [WidgetsApp] does so by default. + static Future<WidgetsLocalizations> load(Locale locale) { + return SynchronousFuture<WidgetsLocalizations>(const DefaultWidgetsLocalizations()); + } + + /// A [LocalizationsDelegate] that uses [DefaultWidgetsLocalizations.load] + /// to create an instance of this class. + /// + /// [WidgetsApp] automatically adds this value to [WidgetsApp.localizationsDelegates]. + static const LocalizationsDelegate<WidgetsLocalizations> delegate = _WidgetsLocalizationsDelegate(); +} + +class _LocalizationsScope extends InheritedWidget { + const _LocalizationsScope({ + super.key, + required this.locale, + required this.localizationsState, + required this.typeToResources, + required super.child, + }); + + final Locale locale; + final _LocalizationsState localizationsState; + final Map<Type, dynamic> typeToResources; + + @override + bool updateShouldNotify(_LocalizationsScope old) { + return typeToResources != old.typeToResources; + } +} + +/// Defines the [Locale] for its `child` and the localized resources that the +/// child depends on. +/// +/// ## Defining localized resources +/// +/// {@tool snippet} +/// +/// This following class is defined in terms of the +/// [Dart `intl` package](https://github.com/dart-lang/intl). Using the `intl` +/// package isn't required. +/// +/// ```dart +/// class MyLocalizations { +/// MyLocalizations(this.locale); +/// +/// final Locale locale; +/// +/// static Future<MyLocalizations> load(Locale locale) { +/// return initializeMessages(locale.toString()) +/// .then((void _) { +/// return MyLocalizations(locale); +/// }); +/// } +/// +/// static MyLocalizations of(BuildContext context) { +/// return Localizations.of<MyLocalizations>(context, MyLocalizations)!; +/// } +/// +/// String title() => Intl.message('<title>', name: 'title', locale: locale.toString()); +/// // ... more Intl.message() methods like title() +/// } +/// ``` +/// {@end-tool} +/// A class based on the `intl` package imports a generated message catalog that provides +/// the `initializeMessages()` function and the per-locale backing store for `Intl.message()`. +/// The message catalog is produced by an `intl` tool that analyzes the source code for +/// classes that contain `Intl.message()` calls. In this case that would just be the +/// `MyLocalizations` class. +/// +/// One could choose another approach for loading localized resources and looking them up while +/// still conforming to the structure of this example. +/// +/// ## Loading localized resources +/// +/// Localized resources are loaded by the list of [LocalizationsDelegate] +/// `delegates`. Each delegate is essentially a factory for a collection +/// of localized resources. There are multiple delegates because there are +/// multiple sources for localizations within an app. +/// +/// Delegates are typically simple subclasses of [LocalizationsDelegate] that +/// override [LocalizationsDelegate.load]. For example a delegate for the +/// `MyLocalizations` class defined above would be: +/// +/// ```dart +/// // continuing from previous example... +/// class _MyDelegate extends LocalizationsDelegate<MyLocalizations> { +/// @override +/// Future<MyLocalizations> load(Locale locale) => MyLocalizations.load(locale); +/// +/// @override +/// bool isSupported(Locale locale) { +/// // in a real implementation this would only return true for +/// // locales that are definitely supported. +/// return true; +/// } +/// +/// @override +/// bool shouldReload(_MyDelegate old) => false; +/// } +/// ``` +/// +/// Each delegate can be viewed as a factory for objects that encapsulate a set +/// of localized resources. These objects are retrieved with +/// by runtime type with [Localizations.of]. +/// +/// The [WidgetsApp] class creates a [Localizations] widget so most apps +/// will not need to create one. The widget app's [Localizations] delegates can +/// be initialized with [WidgetsApp.localizationsDelegates]. The [MaterialApp] +/// class also provides a `localizationsDelegates` parameter that's just +/// passed along to the [WidgetsApp]. +/// +/// ## Obtaining localized resources for use in user interfaces +/// +/// Apps should retrieve collections of localized resources with +/// `Localizations.of<MyLocalizations>(context, MyLocalizations)`, +/// where MyLocalizations is an app specific class defines one function per +/// resource. This is conventionally done by a static `.of` method on the +/// custom localized resource class (`MyLocalizations` in the example above). +/// +/// For example, using the `MyLocalizations` class defined above, one would +/// lookup a localized title string like this: +/// +/// ```dart +/// // continuing from previous example... +/// MyLocalizations.of(context).title() +/// ``` +/// +/// If [Localizations] were to be rebuilt with a new `locale` then +/// the widget subtree that corresponds to [BuildContext] `context` would +/// be rebuilt after the corresponding resources had been loaded. +/// +/// This class is effectively an [InheritedWidget]. If it's rebuilt with +/// a new `locale` or a different list of delegates or any of its +/// delegates' [LocalizationsDelegate.shouldReload()] methods returns true, +/// then widgets that have created a dependency by calling +/// `Localizations.of(context)` will be rebuilt after the resources +/// for the new locale have been loaded. +/// +/// The [Localizations] widget also instantiates [Directionality] in order to +/// support the appropriate [Directionality.textDirection] of the localized +/// resources. +class Localizations extends StatefulWidget { + /// Create a widget from which localizations (like translated strings) can be obtained. + Localizations({ + super.key, + required this.locale, + required this.delegates, + this.child, + }) : assert(delegates.any((LocalizationsDelegate<dynamic> delegate) => delegate is LocalizationsDelegate<WidgetsLocalizations>)); + + /// Overrides the inherited [Locale] or [LocalizationsDelegate]s for `child`. + /// + /// This factory constructor is used for the (usually rare) situation where part + /// of an app should be localized for a different locale than the one defined + /// for the device, or if its localizations should come from a different list + /// of [LocalizationsDelegate]s than the list defined by + /// [WidgetsApp.localizationsDelegates]. + /// + /// For example you could specify that `myWidget` was only to be localized for + /// the US English locale: + /// + /// ```dart + /// Widget build(BuildContext context) { + /// return Localizations.override( + /// context: context, + /// locale: const Locale('en', 'US'), + /// child: myWidget, + /// ); + /// } + /// ``` + /// + /// The `locale` and `delegates` parameters default to the [Localizations.locale] + /// and [Localizations.delegates] values from the nearest [Localizations] ancestor. + /// + /// To override the [Localizations.locale] or [Localizations.delegates] for an + /// entire app, specify [WidgetsApp.locale] or [WidgetsApp.localizationsDelegates] + /// (or specify the same parameters for [MaterialApp]). + factory Localizations.override({ + Key? key, + required BuildContext context, + Locale? locale, + List<LocalizationsDelegate<dynamic>>? delegates, + Widget? child, + }) { + final List<LocalizationsDelegate<dynamic>> mergedDelegates = Localizations._delegatesOf(context); + if (delegates != null) { + mergedDelegates.insertAll(0, delegates); + } + return Localizations( + key: key, + locale: locale ?? Localizations.localeOf(context), + delegates: mergedDelegates, + child: child, + ); + } + + /// The resources returned by [Localizations.of] will be specific to this locale. + final Locale locale; + + /// This list collectively defines the localized resources objects that can + /// be retrieved with [Localizations.of]. + final List<LocalizationsDelegate<dynamic>> delegates; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The locale of the Localizations widget for the widget tree that + /// corresponds to [BuildContext] `context`. + /// + /// If no [Localizations] widget is in scope then the [Localizations.localeOf] + /// method will throw an exception. + static Locale localeOf(BuildContext context) { + final _LocalizationsScope? scope = context.dependOnInheritedWidgetOfExactType<_LocalizationsScope>(); + assert(() { + if (scope == null) { + throw FlutterError( + 'Requested the Locale of a context that does not include a Localizations ancestor.\n' + 'To request the Locale, the context used to retrieve the Localizations widget must ' + 'be that of a widget that is a descendant of a Localizations widget.', + ); + } + if (scope.localizationsState.locale == null) { + throw FlutterError( + 'Localizations.localeOf found a Localizations widget that had a unexpected null locale.\n', + ); + } + return true; + }()); + return scope!.localizationsState.locale!; + } + + /// The locale of the Localizations widget for the widget tree that + /// corresponds to [BuildContext] `context`. + /// + /// If no [Localizations] widget is in scope then this function will return + /// null. + static Locale? maybeLocaleOf(BuildContext context) { + final _LocalizationsScope? scope = context.dependOnInheritedWidgetOfExactType<_LocalizationsScope>(); + return scope?.localizationsState.locale; + } + + // There doesn't appear to be a need to make this public. See the + // Localizations.override factory constructor. + static List<LocalizationsDelegate<dynamic>> _delegatesOf(BuildContext context) { + final _LocalizationsScope? scope = context.dependOnInheritedWidgetOfExactType<_LocalizationsScope>(); + assert(scope != null, 'a Localizations ancestor was not found'); + return List<LocalizationsDelegate<dynamic>>.of(scope!.localizationsState.widget.delegates); + } + + /// Returns the localized resources object of the given `type` for the widget + /// tree that corresponds to the given `context`. + /// + /// Returns null if no resources object of the given `type` exists within + /// the given `context`. + /// + /// This method is typically used by a static factory method on the `type` + /// class. For example Flutter's MaterialLocalizations class looks up Material + /// resources with a method defined like this: + /// + /// ```dart + /// static MaterialLocalizations of(BuildContext context) { + /// return Localizations.of<MaterialLocalizations>(context, MaterialLocalizations)!; + /// } + /// ``` + static T? of<T>(BuildContext context, Type type) { + final _LocalizationsScope? scope = context.dependOnInheritedWidgetOfExactType<_LocalizationsScope>(); + return scope?.localizationsState.resourcesFor<T?>(type); + } + + @override + State<Localizations> createState() => _LocalizationsState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Locale>('locale', locale)); + properties.add(IterableProperty<LocalizationsDelegate<dynamic>>('delegates', delegates)); + } +} + +class _LocalizationsState extends State<Localizations> { + final GlobalKey _localizedResourcesScopeKey = GlobalKey(); + Map<Type, dynamic> _typeToResources = <Type, dynamic>{}; + + Locale? get locale => _locale; + Locale? _locale; + + @override + void initState() { + super.initState(); + load(widget.locale); + } + + bool _anyDelegatesShouldReload(Localizations old) { + if (widget.delegates.length != old.delegates.length) { + return true; + } + final List<LocalizationsDelegate<dynamic>> delegates = widget.delegates.toList(); + final List<LocalizationsDelegate<dynamic>> oldDelegates = old.delegates.toList(); + for (int i = 0; i < delegates.length; i += 1) { + final LocalizationsDelegate<dynamic> delegate = delegates[i]; + final LocalizationsDelegate<dynamic> oldDelegate = oldDelegates[i]; + if (delegate.runtimeType != oldDelegate.runtimeType || delegate.shouldReload(oldDelegate)) { + return true; + } + } + return false; + } + + @override + void didUpdateWidget(Localizations old) { + super.didUpdateWidget(old); + if (widget.locale != old.locale || (_anyDelegatesShouldReload(old))) { + load(widget.locale); + } + } + + void load(Locale locale) { + final Iterable<LocalizationsDelegate<dynamic>> delegates = widget.delegates; + if (delegates.isEmpty) { + _locale = locale; + return; + } + + Map<Type, dynamic>? typeToResources; + final Future<Map<Type, dynamic>> typeToResourcesFuture = _loadAll(locale, delegates) + .then<Map<Type, dynamic>>((Map<Type, dynamic> value) { + return typeToResources = value; + }); + + if (typeToResources != null) { + // All of the delegates' resources loaded synchronously. + _typeToResources = typeToResources!; + _locale = locale; + } else { + // - Don't rebuild the dependent widgets until the resources for the new locale + // have finished loading. Until then the old locale will continue to be used. + // - If we're running at app startup time then defer reporting the first + // "useful" frame until after the async load has completed. + RendererBinding.instance.deferFirstFrame(); + typeToResourcesFuture.then<void>((Map<Type, dynamic> value) { + if (mounted) { + setState(() { + _typeToResources = value; + _locale = locale; + }); + } + RendererBinding.instance.allowFirstFrame(); + }); + } + } + + T resourcesFor<T>(Type type) { + final T resources = _typeToResources[type] as T; + return resources; + } + + TextDirection get _textDirection { + final WidgetsLocalizations resources = _typeToResources[WidgetsLocalizations] as WidgetsLocalizations; + return resources.textDirection; + } + + @override + Widget build(BuildContext context) { + if (_locale == null) { + return const SizedBox.shrink(); + } + return Semantics( + textDirection: _textDirection, + child: _LocalizationsScope( + key: _localizedResourcesScopeKey, + locale: _locale!, + localizationsState: this, + typeToResources: _typeToResources, + child: Directionality( + textDirection: _textDirection, + child: widget.child!, + ), + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/lookup_boundary.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/lookup_boundary.dart new file mode 100644 index 0000000000000000000000000000000000000000..40ebaeaf669287ef5dd8b21e0ea62c1a9c8a2c1e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/lookup_boundary.dart @@ -0,0 +1,325 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'framework.dart'; + +// Examples can assume: +// class MyWidget extends StatelessWidget { const MyWidget({super.key, required this.child}); final Widget child; @override Widget build(BuildContext context) => child; } + +/// A lookup boundary controls what entities are visible to descendants of the +/// boundary via the static lookup methods provided by the boundary. +/// +/// The static lookup methods of the boundary mirror the lookup methods by the +/// same name exposed on [BuildContext] and they can be used as direct +/// replacements. Unlike the methods on [BuildContext], these methods do not +/// find any ancestor entities of the closest [LookupBoundary] surrounding the +/// provided [BuildContext]. The root of the tree is an implicit lookup boundary. +/// +/// {@tool snippet} +/// In the example below, the [LookupBoundary.findAncestorWidgetOfExactType] +/// call returns null because the [LookupBoundary] "hides" `MyWidget` from the +/// [BuildContext] that was queried. +/// +/// ```dart +/// MyWidget( +/// child: LookupBoundary( +/// child: Builder( +/// builder: (BuildContext context) { +/// MyWidget? widget = LookupBoundary.findAncestorWidgetOfExactType<MyWidget>(context); +/// return Text('$widget'); // "null" +/// }, +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// A [LookupBoundary] only affects the behavior of the static lookup methods +/// defined on the boundary. It does not affect the behavior of the lookup +/// methods defined on [BuildContext]. +/// +/// A [LookupBoundary] is rarely instantiated directly. They are inserted at +/// locations of the widget tree where the render tree diverges from the element +/// tree, which is rather uncommon. Such anomalies are created by +/// [RenderObjectElement]s that don't attach their [RenderObject] to the closest +/// ancestor [RenderObjectElement], e.g. because they bootstrap a separate +/// stand-alone render tree. +// TODO(goderbauer): Reference the View widget here once available. +/// This behavior breaks the assumption some widgets have about the structure of +/// the render tree: These widgets may try to reach out to an ancestor widget, +/// assuming that their associated [RenderObject]s are also ancestors, which due +/// to the anomaly may not be the case. At the point where the divergence in the +/// two trees is introduced, a [LookupBoundary] can be used to hide that ancestor +/// from the querying widget. +/// +/// As an example, [Material.of] relies on lookup boundaries to hide the +/// [Material] widget from certain descendant button widget. Buttons reach out +/// to their [Material] ancestor to draw ink splashes on its associated render +/// object. This only produces the desired effect if the button render object +/// is a descendant of the [Material] render object. If the element tree and +/// the render tree are not in sync due to anomalies described above, this may +/// not be the case. To avoid incorrect visuals, the [Material] relies on +/// lookup boundaries to hide itself from descendants in subtrees with such +/// anomalies. Those subtrees are expected to introduce their own [Material] +/// widget that buttons there can utilize without crossing a lookup boundary. +class LookupBoundary extends InheritedWidget { + /// Creates a [LookupBoundary]. + /// + /// A none-null [child] widget must be provided. + const LookupBoundary({super.key, required super.child}); + + /// Obtains the nearest widget of the given type `T` within the current + /// [LookupBoundary] of `context`, which must be the type of a concrete + /// [InheritedWidget] subclass, and registers the provided build `context` + /// with that widget such that when that widget changes (or a new widget of + /// that type is introduced, or the widget goes away), the build context is + /// rebuilt so that it can obtain new values from that widget. + /// + /// This method behaves exactly like + /// [BuildContext.dependOnInheritedWidgetOfExactType], except it only + /// considers [InheritedWidget]s of the specified type `T` between the + /// provided [BuildContext] and its closest [LookupBoundary] ancestor. + /// [InheritedWidget]s past that [LookupBoundary] are invisible to this + /// method. The root of the tree is treated as an implicit lookup boundary. + /// + /// {@macro flutter.widgets.BuildContext.dependOnInheritedWidgetOfExactType} + static T? dependOnInheritedWidgetOfExactType<T extends InheritedWidget>(BuildContext context, { Object? aspect }) { + // The following call makes sure that context depends on something so + // Element.didChangeDependencies is called when context moves in the tree + // even when requested dependency remains unfulfilled (i.e. null is + // returned). + context.dependOnInheritedWidgetOfExactType<LookupBoundary>(); + final InheritedElement? candidate = getElementForInheritedWidgetOfExactType<T>(context); + if (candidate == null) { + return null; + } + context.dependOnInheritedElement(candidate, aspect: aspect); + return candidate.widget as T; + } + + /// Obtains the element corresponding to the nearest widget of the given type + /// `T` within the current [LookupBoundary] of `context`. + /// + /// `T` must be the type of a concrete [InheritedWidget] subclass. Returns + /// null if no such element is found. + /// + /// This method behaves exactly like + /// [BuildContext.getElementForInheritedWidgetOfExactType], except it only + /// considers [InheritedWidget]s of the specified type `T` between the + /// provided [BuildContext] and its closest [LookupBoundary] ancestor. + /// [InheritedWidget]s past that [LookupBoundary] are invisible to this + /// method. The root of the tree is treated as an implicit lookup boundary. + /// + /// {@macro flutter.widgets.BuildContext.getElementForInheritedWidgetOfExactType} + static InheritedElement? getElementForInheritedWidgetOfExactType<T extends InheritedWidget>(BuildContext context) { + final InheritedElement? candidate = context.getElementForInheritedWidgetOfExactType<T>(); + if (candidate == null) { + return null; + } + final Element? boundary = context.getElementForInheritedWidgetOfExactType<LookupBoundary>(); + if (boundary != null && boundary.depth > candidate.depth) { + return null; + } + return candidate; + } + + /// Returns the nearest ancestor widget of the given type `T` within the + /// current [LookupBoundary] of `context`. + /// + /// `T` must be the type of a concrete [Widget] subclass. + /// + /// This method behaves exactly like + /// [BuildContext.findAncestorWidgetOfExactType], except it only considers + /// [Widget]s of the specified type `T` between the provided [BuildContext] + /// and its closest [LookupBoundary] ancestor. [Widget]s past that + /// [LookupBoundary] are invisible to this method. The root of the tree is + /// treated as an implicit lookup boundary. + /// + /// {@macro flutter.widgets.BuildContext.findAncestorWidgetOfExactType} + static T? findAncestorWidgetOfExactType<T extends Widget>(BuildContext context) { + Element? target; + context.visitAncestorElements((Element ancestor) { + if (ancestor.widget.runtimeType == T) { + target = ancestor; + return false; + } + return ancestor.widget.runtimeType != LookupBoundary; + }); + return target?.widget as T?; + } + + /// Returns the [State] object of the nearest ancestor [StatefulWidget] widget + /// within the current [LookupBoundary] of `context` that is an instance of + /// the given type `T`. + /// + /// This method behaves exactly like + /// [BuildContext.findAncestorWidgetOfExactType], except it only considers + /// [State] objects of the specified type `T` between the provided + /// [BuildContext] and its closest [LookupBoundary] ancestor. [State] objects + /// past that [LookupBoundary] are invisible to this method. The root of the + /// tree is treated as an implicit lookup boundary. + /// + /// {@macro flutter.widgets.BuildContext.findAncestorStateOfType} + static T? findAncestorStateOfType<T extends State>(BuildContext context) { + StatefulElement? target; + context.visitAncestorElements((Element ancestor) { + if (ancestor is StatefulElement && ancestor.state is T) { + target = ancestor; + return false; + } + return ancestor.widget.runtimeType != LookupBoundary; + }); + return target?.state as T?; + } + + /// Returns the [State] object of the furthest ancestor [StatefulWidget] + /// widget within the current [LookupBoundary] of `context` that is an + /// instance of the given type `T`. + /// + /// This method behaves exactly like + /// [BuildContext.findRootAncestorStateOfType], except it considers the + /// closest [LookupBoundary] ancestor of `context` to be the root. [State] + /// objects past that [LookupBoundary] are invisible to this method. The root + /// of the tree is treated as an implicit lookup boundary. + /// + /// {@macro flutter.widgets.BuildContext.findRootAncestorStateOfType} + static T? findRootAncestorStateOfType<T extends State>(BuildContext context) { + StatefulElement? target; + context.visitAncestorElements((Element ancestor) { + if (ancestor is StatefulElement && ancestor.state is T) { + target = ancestor; + } + return ancestor.widget.runtimeType != LookupBoundary; + }); + return target?.state as T?; + } + + /// Returns the [RenderObject] object of the nearest ancestor + /// [RenderObjectWidget] widget within the current [LookupBoundary] of + /// `context` that is an instance of the given type `T`. + /// + /// This method behaves exactly like + /// [BuildContext.findAncestorRenderObjectOfType], except it only considers + /// [RenderObject]s of the specified type `T` between the provided + /// [BuildContext] and its closest [LookupBoundary] ancestor. [RenderObject]s + /// past that [LookupBoundary] are invisible to this method. The root of the + /// tree is treated as an implicit lookup boundary. + /// + /// {@macro flutter.widgets.BuildContext.findAncestorRenderObjectOfType} + static T? findAncestorRenderObjectOfType<T extends RenderObject>(BuildContext context) { + Element? target; + context.visitAncestorElements((Element ancestor) { + if (ancestor is RenderObjectElement && ancestor.renderObject is T) { + target = ancestor; + return false; + } + return ancestor.widget.runtimeType != LookupBoundary; + }); + return target?.renderObject as T?; + } + + /// Walks the ancestor chain, starting with the parent of the build context's + /// widget, invoking the argument for each ancestor until a [LookupBoundary] + /// or the root is reached. + /// + /// This method behaves exactly like [BuildContext.visitAncestorElements], + /// except it only walks the tree up to the closest [LookupBoundary] ancestor + /// of the provided context. The root of the tree is treated as an implicit + /// lookup boundary. + /// + /// {@macro flutter.widgets.BuildContext.visitAncestorElements} + static void visitAncestorElements(BuildContext context, ConditionalElementVisitor visitor) { + context.visitAncestorElements((Element ancestor) { + return visitor(ancestor) && ancestor.widget.runtimeType != LookupBoundary; + }); + } + + /// Walks the non-[LookupBoundary] child [Element]s of the provided + /// `context`. + /// + /// This method behaves exactly like [BuildContext.visitChildElements], + /// except it only visits children that are not a [LookupBoundary]. + /// + /// {@macro flutter.widgets.BuildContext.visitChildElements} + static void visitChildElements(BuildContext context, ElementVisitor visitor) { + context.visitChildElements((Element child) { + if (child.widget.runtimeType != LookupBoundary) { + visitor(child); + } + }); + } + + /// Returns true if a [LookupBoundary] is hiding the nearest + /// [Widget] of the specified type `T` from the provided [BuildContext]. + /// + /// This method throws when asserts are disabled. + static bool debugIsHidingAncestorWidgetOfExactType<T extends Widget>(BuildContext context) { + bool? result; + assert(() { + bool hiddenByBoundary = false; + bool ancestorFound = false; + context.visitAncestorElements((Element ancestor) { + if (ancestor.widget.runtimeType == T) { + ancestorFound = true; + return false; + } + hiddenByBoundary = hiddenByBoundary || ancestor.widget.runtimeType == LookupBoundary; + return true; + }); + result = ancestorFound & hiddenByBoundary; + return true; + } ()); + return result!; + } + + /// Returns true if a [LookupBoundary] is hiding the nearest [StatefulWidget] + /// with a [State] of the specified type `T` from the provided [BuildContext]. + /// + /// This method throws when asserts are disabled. + static bool debugIsHidingAncestorStateOfType<T extends State>(BuildContext context) { + bool? result; + assert(() { + bool hiddenByBoundary = false; + bool ancestorFound = false; + context.visitAncestorElements((Element ancestor) { + if (ancestor is StatefulElement && ancestor.state is T) { + ancestorFound = true; + return false; + } + hiddenByBoundary = hiddenByBoundary || ancestor.widget.runtimeType == LookupBoundary; + return true; + }); + result = ancestorFound & hiddenByBoundary; + return true; + } ()); + return result!; + } + + /// Returns true if a [LookupBoundary] is hiding the nearest + /// [RenderObjectWidget] with a [RenderObject] of the specified type `T` + /// from the provided [BuildContext]. + /// + /// This method throws when asserts are disabled. + static bool debugIsHidingAncestorRenderObjectOfType<T extends RenderObject>(BuildContext context) { + bool? result; + assert(() { + bool hiddenByBoundary = false; + bool ancestorFound = false; + context.visitAncestorElements((Element ancestor) { + if (ancestor is RenderObjectElement && ancestor.renderObject is T) { + ancestorFound = true; + return false; + } + hiddenByBoundary = hiddenByBoundary || ancestor.widget.runtimeType == LookupBoundary; + return true; + }); + result = ancestorFound & hiddenByBoundary; + return true; + } ()); + return result!; + } + + @override + bool updateShouldNotify(covariant InheritedWidget oldWidget) => false; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/magnifier.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/magnifier.dart new file mode 100644 index 0000000000000000000000000000000000000000..ea598e90a903a397a2f8c26b88ee0d68043e0fa9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/magnifier.dart @@ -0,0 +1,659 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; +import 'dart:ui'; + +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'container.dart'; +import 'framework.dart'; +import 'inherited_theme.dart'; +import 'navigator.dart'; +import 'overlay.dart'; + +/// {@template flutter.widgets.magnifier.MagnifierBuilder} +/// Signature for a builder that builds a [Widget] with a [MagnifierController]. +/// +/// Consuming [MagnifierController] or [ValueNotifier]<[MagnifierInfo]> is not +/// required, although if a Widget intends to have entry or exit animations, it should take +/// [MagnifierController] and provide it an [AnimationController], so that [MagnifierController] +/// can wait before removing it from the overlay. +/// {@endtemplate} +/// +/// See also: +/// +/// - [MagnifierInfo], the data class that updates the +/// magnifier. +typedef MagnifierBuilder = Widget? Function( + BuildContext context, + MagnifierController controller, + ValueNotifier<MagnifierInfo> magnifierInfo, +); + +/// A data class that contains the geometry information of text layouts +/// and selection gestures, used to position magnifiers. +@immutable +class MagnifierInfo { + /// Constructs a [MagnifierInfo] from provided geometry values. + const MagnifierInfo({ + required this.globalGesturePosition, + required this.caretRect, + required this.fieldBounds, + required this.currentLineBoundaries, + }); + + /// Const [MagnifierInfo] with all values set to 0. + static const MagnifierInfo empty = MagnifierInfo( + globalGesturePosition: Offset.zero, + caretRect: Rect.zero, + currentLineBoundaries: Rect.zero, + fieldBounds: Rect.zero, + ); + + /// The offset of the gesture position that the magnifier should be shown at. + final Offset globalGesturePosition; + + /// The rect of the current line the magnifier should be shown at, + /// without taking into account any padding of the field; only the position + /// of the first and last character. + final Rect currentLineBoundaries; + + /// The rect of the handle that the magnifier should follow. + final Rect caretRect; + + /// The bounds of the entire text field that the magnifier is bound to. + final Rect fieldBounds; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is MagnifierInfo + && other.globalGesturePosition == globalGesturePosition + && other.caretRect == caretRect + && other.currentLineBoundaries == currentLineBoundaries + && other.fieldBounds == fieldBounds; + } + + @override + int get hashCode => Object.hash( + globalGesturePosition, + caretRect, + fieldBounds, + currentLineBoundaries, + ); +} + +/// {@template flutter.widgets.magnifier.TextMagnifierConfiguration.intro} +/// A configuration object for a magnifier. +/// {@endtemplate} +/// +/// {@macro flutter.widgets.magnifier.intro} +/// +/// {@template flutter.widgets.magnifier.TextMagnifierConfiguration.details} +/// In general, most features of the magnifier can be configured through +/// [MagnifierBuilder]. [TextMagnifierConfiguration] is used to configure +/// the magnifier's behavior through the [SelectionOverlay]. +/// {@endtemplate} +class TextMagnifierConfiguration { + /// Constructs a [TextMagnifierConfiguration] from parts. + /// + /// If [magnifierBuilder] is null, a default [MagnifierBuilder] will be used + /// that never builds a magnifier. + const TextMagnifierConfiguration({ + MagnifierBuilder? magnifierBuilder, + this.shouldDisplayHandlesInMagnifier = true + }) : _magnifierBuilder = magnifierBuilder; + + /// The passed in [MagnifierBuilder]. + /// + /// This is nullable because [disabled] needs to be static const, + /// so that it can be used as a default parameter. If left null, + /// the [magnifierBuilder] getter will be a function that always returns + /// null. + final MagnifierBuilder? _magnifierBuilder; + + /// {@macro flutter.widgets.magnifier.MagnifierBuilder} + MagnifierBuilder get magnifierBuilder => _magnifierBuilder ?? (_, __, ___) => null; + + /// Determines whether a magnifier should show the text editing handles or not. + final bool shouldDisplayHandlesInMagnifier; + + /// A constant for a [TextMagnifierConfiguration] that is disabled. + /// + /// In particular, this [TextMagnifierConfiguration] is considered disabled + /// because it never builds anything, regardless of platform. + static const TextMagnifierConfiguration disabled = TextMagnifierConfiguration(); +} + +/// [MagnifierController]'s main benefit over holding a raw [OverlayEntry] is that +/// [MagnifierController] will handle logic around waiting for a magnifier to animate in or out. +/// +/// If a magnifier chooses to have an entry / exit animation, it should provide the animation +/// controller to [MagnifierController.animationController]. [MagnifierController] will then drive +/// the [AnimationController] and wait for it to be complete before removing it from the +/// [Overlay]. +/// +/// To check the status of the magnifier, see [MagnifierController.shown]. +// TODO(antholeole): This whole paradigm can be removed once portals +// lands - then the magnifier can be controlled though a widget in the tree. +// https://github.com/flutter/flutter/pull/105335 +class MagnifierController { + /// If there is no in / out animation for the magnifier, [animationController] should be left + /// null. + MagnifierController({this.animationController}) { + animationController?.value = 0; + } + + /// The controller that will be driven in / out when show / hide is triggered, + /// respectively. + AnimationController? animationController; + + /// The magnifier's [OverlayEntry], if currently in the overlay. + /// + /// This is public in case other overlay entries need to be positioned + /// above or below this [overlayEntry]. Anything in the paint order after + /// the [RawMagnifier] will not be displayed in the magnifier; this means that if it + /// is desired for an overlay entry to be displayed in the magnifier, + /// it _must_ be positioned below the magnifier. + /// + /// {@tool snippet} + /// ```dart + /// void magnifierShowExample(BuildContext context) { + /// final MagnifierController myMagnifierController = MagnifierController(); + /// + /// // Placed below the magnifier, so it will show. + /// Overlay.of(context).insert(OverlayEntry( + /// builder: (BuildContext context) => const Text('I WILL display in the magnifier'))); + /// + /// // Will display in the magnifier, since this entry was passed to show. + /// final OverlayEntry displayInMagnifier = OverlayEntry( + /// builder: (BuildContext context) => + /// const Text('I WILL display in the magnifier')); + /// + /// Overlay.of(context) + /// .insert(displayInMagnifier); + /// myMagnifierController.show( + /// context: context, + /// below: displayInMagnifier, + /// builder: (BuildContext context) => const RawMagnifier( + /// size: Size(100, 100), + /// )); + /// + /// // By default, new entries will be placed over the top entry. + /// Overlay.of(context).insert(OverlayEntry( + /// builder: (BuildContext context) => const Text('I WILL NOT display in the magnifier'))); + /// + /// Overlay.of(context).insert( + /// below: + /// myMagnifierController.overlayEntry, // Explicitly placed below the magnifier. + /// OverlayEntry( + /// builder: (BuildContext context) => const Text('I WILL display in the magnifier'))); + /// } + /// ``` + /// {@end-tool} + /// + /// A null check on [overlayEntry] will not suffice to check if a magnifier is in the + /// overlay or not; instead, you should check [shown]. This is because it is possible, + /// such as in cases where [hide] was called with `removeFromOverlay` false, that the magnifier + /// is not shown, but the entry is not null. + OverlayEntry? get overlayEntry => _overlayEntry; + OverlayEntry? _overlayEntry; + + /// If the magnifier is shown or not. + /// + /// [shown] is: + /// - false when nothing is in the overlay. + /// - false when [animationController] is [AnimationStatus.dismissed]. + /// - false when [animationController] is animating out. + /// and true in all other circumstances. + bool get shown { + if (overlayEntry == null) { + return false; + } + + if (animationController != null) { + return animationController!.status == AnimationStatus.completed || + animationController!.status == AnimationStatus.forward; + } + + return true; + } + + /// Shows the [RawMagnifier] that this controller controls. + /// + /// Returns a future that completes when the magnifier is fully shown, i.e. done + /// with its entry animation. + /// + /// To control what overlays are shown in the magnifier, utilize [below]. See + /// [overlayEntry] for more details on how to utilize [below]. + /// + /// If the magnifier already exists (i.e. [overlayEntry] != null), then [show] will + /// override the old overlay and not play an exit animation. Consider awaiting [hide] + /// first, to guarantee + Future<void> show({ + required BuildContext context, + required WidgetBuilder builder, + Widget? debugRequiredFor, + OverlayEntry? below, + }) async { + _overlayEntry?.remove(); + _overlayEntry?.dispose(); + + final OverlayState overlayState = Overlay.of( + context, + rootOverlay: true, + debugRequiredFor: debugRequiredFor, + ); + + final CapturedThemes capturedThemes = InheritedTheme.capture( + from: context, + to: Navigator.maybeOf(context)?.context, + ); + + _overlayEntry = OverlayEntry( + builder: (BuildContext context) => capturedThemes.wrap(builder(context)), + ); + overlayState.insert(overlayEntry!, below: below); + + if (animationController != null) { + await animationController?.forward(); + } + } + + /// Schedules a hide of the magnifier. + /// + /// If this [MagnifierController] has an [AnimationController], + /// then [hide] reverses the animation controller and waits + /// for the animation to complete. Then, if [removeFromOverlay] + /// is true, remove the magnifier from the overlay. + /// + /// In general, `removeFromOverlay` should be true, unless + /// the magnifier needs to preserve states between shows / hides. + /// + /// See also: + /// + /// * [removeFromOverlay] which removes the [OverlayEntry] from the [Overlay] + /// synchronously. + Future<void> hide({bool removeFromOverlay = true}) async { + if (overlayEntry == null) { + return; + } + + if (animationController != null) { + await animationController?.reverse(); + } + + if (removeFromOverlay) { + this.removeFromOverlay(); + } + } + + /// Remove the [OverlayEntry] from the [Overlay]. + /// + /// This method removes the [OverlayEntry] synchronously, + /// regardless of exit animation: this leads to abrupt removals + /// of [OverlayEntry]s with animations. + /// + /// To allow the [OverlayEntry] to play its exit animation, consider calling + /// [hide] instead, with `removeFromOverlay` set to true, and optionally await + /// the returned Future. + @visibleForTesting + void removeFromOverlay() { + _overlayEntry?.remove(); + _overlayEntry?.dispose(); + _overlayEntry = null; + } + + /// A utility for calculating a new [Rect] from [rect] such that + /// [rect] is fully constrained within [bounds]. + /// + /// Any point in the output rect is guaranteed to also be a point contained in [bounds]. + /// + /// It is a runtime error for [rect].width to be greater than [bounds].width, + /// and it is also an error for [rect].height to be greater than [bounds].height. + /// + /// This algorithm translates [rect] the shortest distance such that it is entirely within + /// [bounds]. + /// + /// If [rect] is already within [bounds], no shift will be applied to [rect] and + /// [rect] will be returned as-is. + /// + /// It is perfectly valid for the output rect to have a point along the edge of the + /// [bounds]. If the desired output rect requires that no edges are parallel to edges + /// of [bounds], see [Rect.deflate] by 1 on [bounds] to achieve this effect. + static Rect shiftWithinBounds({ + required Rect rect, + required Rect bounds, + }) { + assert(rect.width <= bounds.width, + 'attempted to shift $rect within $bounds, but the rect has a greater width.'); + assert(rect.height <= bounds.height, + 'attempted to shift $rect within $bounds, but the rect has a greater height.'); + + Offset rectShift = Offset.zero; + if (rect.left < bounds.left) { + rectShift += Offset(bounds.left - rect.left, 0); + } else if (rect.right > bounds.right) { + rectShift += Offset(bounds.right - rect.right, 0); + } + + if (rect.top < bounds.top) { + rectShift += Offset(0, bounds.top - rect.top); + } else if (rect.bottom > bounds.bottom) { + rectShift += Offset(0, bounds.bottom - rect.bottom); + } + + return rect.shift(rectShift); + } +} + +/// A decoration for a [RawMagnifier]. +/// +/// [MagnifierDecoration] does not expose [ShapeDecoration.color], [ShapeDecoration.image], +/// or [ShapeDecoration.gradient], since they will be covered by the [RawMagnifier]'s lens. +/// +/// Also takes an [opacity] (see https://github.com/flutter/engine/pull/34435). +class MagnifierDecoration extends ShapeDecoration { + /// Constructs a [MagnifierDecoration]. + /// + /// By default, [MagnifierDecoration] is a rectangular magnifier with no shadows, and + /// fully opaque. + const MagnifierDecoration({ + this.opacity = 1, + super.shadows, + super.shape = const RoundedRectangleBorder(), + }); + + /// The magnifier's opacity. + final double opacity; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return super == other && other is MagnifierDecoration && other.opacity == opacity; + } + + @override + int get hashCode => Object.hash(super.hashCode, opacity); +} + +/// A common base class for magnifiers. +/// +/// {@tool dartpad} +/// This sample demonstrates what a magnifier is, and how it can be used. +/// +/// ** See code in examples/api/lib/widgets/magnifier/magnifier.0.dart ** +/// {@end-tool} +/// +/// {@template flutter.widgets.magnifier.intro} +/// This magnifying glass is useful for scenarios on mobile devices where +/// the user's finger may be covering part of the screen where a granular +/// action is being performed, such as navigating a small cursor with a drag +/// gesture, on an image or text. +/// {@endtemplate} +/// +/// A magnifier can be conveniently managed by [MagnifierController], which handles +/// showing and hiding the magnifier, with an optional entry / exit animation. +/// +/// See: +/// * [MagnifierController], a controller to handle magnifiers in an overlay. +class RawMagnifier extends StatelessWidget { + /// Constructs a [RawMagnifier]. + /// + /// {@template flutter.widgets.magnifier.RawMagnifier.invisibility_warning} + /// By default, this magnifier uses the default [MagnifierDecoration], + /// the focal point is directly under the magnifier, and there is no magnification: + /// This means that a default magnifier will be entirely invisible to the naked eye, + /// since it is painting exactly what is under it, exactly where it was painted + /// originally. + /// {@endtemplate} + const RawMagnifier({ + super.key, + this.child, + this.decoration = const MagnifierDecoration(), + this.focalPointOffset = Offset.zero, + this.magnificationScale = 1, + required this.size, + }) : assert(magnificationScale != 0, + 'Magnification scale of 0 results in undefined behavior.'); + + /// An optional widget to position inside the len of the [RawMagnifier]. + /// + /// This is positioned over the [RawMagnifier] - it may be useful for tinting the + /// [RawMagnifier], or drawing a crosshair like UI. + final Widget? child; + + /// This magnifier's decoration. + /// + /// {@macro flutter.widgets.magnifier.RawMagnifier.invisibility_warning} + final MagnifierDecoration decoration; + + + /// The offset of the magnifier from [RawMagnifier]'s center. + /// + /// {@template flutter.widgets.magnifier.offset} + /// For example, if [RawMagnifier] is globally positioned at Offset(100, 100), + /// and [focalPointOffset] is Offset(-20, -20), then [RawMagnifier] will see + /// the content at global offset (80, 80). + /// + /// If left as [Offset.zero], the [RawMagnifier] will show the content that + /// is directly below it. + /// {@endtemplate} + final Offset focalPointOffset; + + /// How "zoomed in" the magnification subject is in the lens. + final double magnificationScale; + + /// The size of the magnifier. + /// + /// This does not include added border; it only includes + /// the size of the magnifier. + final Size size; + + @override + Widget build(BuildContext context) { + return Stack( + clipBehavior: Clip.none, + alignment: Alignment.center, + children: <Widget>[ + ClipPath.shape( + shape: decoration.shape, + child: Opacity( + opacity: decoration.opacity, + child: _Magnifier( + shape: decoration.shape, + focalPointOffset: focalPointOffset, + magnificationScale: magnificationScale, + child: SizedBox.fromSize( + size: size, + child: child, + ), + ), + ), + ), + // Because `BackdropFilter` will filter any widgets before it, we should + // apply the style after (i.e. in a younger sibling) to avoid the magnifier + // from seeing its own styling. + Opacity( + opacity: decoration.opacity, + child: _MagnifierStyle( + decoration, + size: size, + ), + ) + ], + ); + } +} + +class _MagnifierStyle extends StatelessWidget { + const _MagnifierStyle(this.decoration, {required this.size}); + + final MagnifierDecoration decoration; + final Size size; + + @override + Widget build(BuildContext context) { + double largestShadow = 0; + for (final BoxShadow shadow in decoration.shadows ?? <BoxShadow>[]) { + largestShadow = math.max( + largestShadow, + (shadow.blurRadius + shadow.spreadRadius) + + math.max(shadow.offset.dy.abs(), shadow.offset.dx.abs())); + } + + return ClipPath( + clipBehavior: Clip.hardEdge, + clipper: _DonutClip( + shape: decoration.shape, + spreadRadius: largestShadow, + ), + child: DecoratedBox( + decoration: decoration, + child: SizedBox.fromSize( + size: size, + ), + ), + ); + } +} + +/// A `clipPath` that looks like a donut if you were to fill its area. +/// +/// This is necessary because the shadow must be added after the magnifier is drawn, +/// so that the shadow does not end up in the magnifier. Without this clip, the magnifier would be +/// entirely covered by the shadow. +/// +/// The negative space of the donut is clipped out (the donut hole, outside the donut). +/// The donut hole is cut out exactly like the shape of the magnifier. +class _DonutClip extends CustomClipper<Path> { + _DonutClip({required this.shape, required this.spreadRadius}); + + final double spreadRadius; + final ShapeBorder shape; + + @override + Path getClip(Size size) { + final Path path = Path(); + final Rect rect = Offset.zero & size; + + path.fillType = PathFillType.evenOdd; + path.addPath(shape.getOuterPath(rect.inflate(spreadRadius)), Offset.zero); + path.addPath(shape.getInnerPath(rect), Offset.zero); + return path; + } + + @override + bool shouldReclip(_DonutClip oldClipper) => oldClipper.shape != shape; +} + +class _Magnifier extends SingleChildRenderObjectWidget { + const _Magnifier({ + super.child, + required this.shape, + this.magnificationScale = 1, + this.focalPointOffset = Offset.zero, + }); + + // The Offset that the center of the _Magnifier points to, relative + // to the center of the magnifier. + final Offset focalPointOffset; + + // The enlarge multiplier of the magnification. + // + // If equal to 1.0, the content in the magnifier is true to its real size. + // If greater than 1.0, the content appears bigger in the magnifier. + final double magnificationScale; + + // Shape of the magnifier. + final ShapeBorder shape; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderMagnification(focalPointOffset, magnificationScale, shape); + } + + @override + void updateRenderObject( + BuildContext context, _RenderMagnification renderObject) { + renderObject + ..focalPointOffset = focalPointOffset + ..shape = shape + ..magnificationScale = magnificationScale; + } +} + +class _RenderMagnification extends RenderProxyBox { + _RenderMagnification( + this._focalPointOffset, + this._magnificationScale, + this._shape, { + RenderBox? child, + }) : super(child); + + Offset get focalPointOffset => _focalPointOffset; + Offset _focalPointOffset; + set focalPointOffset(Offset value) { + if (_focalPointOffset == value) { + return; + } + _focalPointOffset = value; + markNeedsPaint(); + } + + double get magnificationScale => _magnificationScale; + double _magnificationScale; + set magnificationScale(double value) { + if (_magnificationScale == value) { + return; + } + _magnificationScale = value; + markNeedsPaint(); + } + + ShapeBorder get shape => _shape; + ShapeBorder _shape; + set shape(ShapeBorder value) { + if (_shape == value) { + return; + } + _shape = value; + markNeedsPaint(); + } + + @override + bool get alwaysNeedsCompositing => true; + + @override + BackdropFilterLayer? get layer => super.layer as BackdropFilterLayer?; + + @override + void paint(PaintingContext context, Offset offset) { + final Offset thisCenter = Alignment.center.alongSize(size) + offset; + final Matrix4 matrix = Matrix4.identity() + ..translate( + magnificationScale * ((focalPointOffset.dx * -1) - thisCenter.dx) + thisCenter.dx, + magnificationScale * ((focalPointOffset.dy * -1) - thisCenter.dy) + thisCenter.dy) + ..scale(magnificationScale); + final ImageFilter filter = ImageFilter.matrix(matrix.storage, filterQuality: FilterQuality.high); + + if (layer == null) { + layer = BackdropFilterLayer( + filter: filter, + ); + } else { + layer!.filter = filter; + } + + context.pushLayer(layer!, super.paint, offset); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/media_query.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/media_query.dart new file mode 100644 index 0000000000000000000000000000000000000000..b9b4468f321534c59c23624e4fd94a5c3dc4091f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/media_query.dart @@ -0,0 +1,1928 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; + +import 'basic.dart'; +import 'binding.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'inherited_model.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Whether in portrait or landscape. +enum Orientation { + /// Taller than wide. + portrait, + + /// Wider than tall. + landscape +} + +/// Specifies a part of MediaQueryData to depend on. +/// +/// [MediaQuery] contains a large number of related properties. Widgets frequently +/// depend on only a few of these attributes. For example, a widget that needs to +/// rebuild when the [MediaQueryData.textScaler] changes does not need to be +/// notified when the [MediaQueryData.size] changes. Specifying an aspect avoids +/// unnecessary rebuilds. +enum _MediaQueryAspect { + /// Specifies the aspect corresponding to [MediaQueryData.size]. + size, + /// Specifies the aspect corresponding to [MediaQueryData.orientation]. + orientation, + /// Specifies the aspect corresponding to [MediaQueryData.devicePixelRatio]. + devicePixelRatio, + /// Specifies the aspect corresponding to [MediaQueryData.textScaleFactor]. + textScaleFactor, + /// Specifies the aspect corresponding to [MediaQueryData.textScaler]. + textScaler, + /// Specifies the aspect corresponding to [MediaQueryData.platformBrightness]. + platformBrightness, + /// Specifies the aspect corresponding to [MediaQueryData.padding]. + padding, + /// Specifies the aspect corresponding to [MediaQueryData.viewInsets]. + viewInsets, + /// Specifies the aspect corresponding to [MediaQueryData.systemGestureInsets]. + systemGestureInsets, + /// Specifies the aspect corresponding to [MediaQueryData.viewPadding]. + viewPadding, + /// Specifies the aspect corresponding to [MediaQueryData.alwaysUse24HourFormat]. + alwaysUse24HourFormat, + /// Specifies the aspect corresponding to [MediaQueryData.accessibleNavigation]. + accessibleNavigation, + /// Specifies the aspect corresponding to [MediaQueryData.invertColors]. + invertColors, + /// Specifies the aspect corresponding to [MediaQueryData.highContrast]. + highContrast, + /// Specifies the aspect corresponding to [MediaQueryData.onOffSwitchLabels]. + onOffSwitchLabels, + /// Specifies the aspect corresponding to [MediaQueryData.disableAnimations]. + disableAnimations, + /// Specifies the aspect corresponding to [MediaQueryData.boldText]. + boldText, + /// Specifies the aspect corresponding to [MediaQueryData.navigationMode]. + navigationMode, + /// Specifies the aspect corresponding to [MediaQueryData.gestureSettings]. + gestureSettings, + /// Specifies the aspect corresponding to [MediaQueryData.displayFeatures]. + displayFeatures, +} + +/// Information about a piece of media (e.g., a window). +/// +/// For example, the [MediaQueryData.size] property contains the width and +/// height of the current window. +/// +/// To obtain individual attributes in a [MediaQueryData], prefer to use the +/// attribute-specific functions of [MediaQuery] over obtaining the entire +/// [MediaQueryData] and accessing its members. +/// {@macro flutter.widgets.media_query.MediaQuery.useSpecific} +/// +/// To obtain the entire current [MediaQueryData] for a given [BuildContext], +/// use the [MediaQuery.of] function. This can be useful if you are going to use +/// [copyWith] to replace the [MediaQueryData] with one with an updated +/// property. +/// +/// ## Insets and Padding +/// +/// ![A diagram of padding, viewInsets, and viewPadding in correlation with each +/// other](https://flutter.github.io/assets-for-api-docs/assets/widgets/media_query.png) +/// +/// This diagram illustrates how [padding] relates to [viewPadding] and +/// [viewInsets], shown here in its simplest configuration, as the difference +/// between the two. In cases when the viewInsets exceed the viewPadding, like +/// when a software keyboard is shown below, padding goes to zero rather than a +/// negative value. Therefore, padding is calculated by taking +/// `max(0.0, viewPadding - viewInsets)`. +/// +/// {@animation 300 300 https://flutter.github.io/assets-for-api-docs/assets/widgets/window_padding.mp4} +/// +/// In this diagram, the black areas represent system UI that the app cannot +/// draw over. The red area represents view padding that the application may not +/// be able to detect gestures in and may not want to draw in. The grey area +/// represents the system keyboard, which can cover over the bottom view padding +/// when visible. +/// +/// MediaQueryData includes three [EdgeInsets] values: +/// [padding], [viewPadding], and [viewInsets]. These values reflect the +/// configuration of the device and are used and optionally consumed by widgets +/// that position content within these insets. The padding value defines areas +/// that might not be completely visible, like the display "notch" on the iPhone +/// X. The viewInsets value defines areas that aren't visible at all, typically +/// because they're obscured by the device's keyboard. Similar to viewInsets, +/// viewPadding does not differentiate padding in areas that may be obscured. +/// For example, by using the viewPadding property, padding would defer to the +/// iPhone "safe area" regardless of whether a keyboard is showing. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ceCo8U0XHqw} +/// +/// The viewInsets and viewPadding are independent values, they're +/// measured from the edges of the MediaQuery widget's bounds. Together they +/// inform the [padding] property. The bounds of the top level MediaQuery +/// created by [WidgetsApp] are the same as the window that contains the app. +/// +/// Widgets whose layouts consume space defined by [viewInsets], [viewPadding], +/// or [padding] should enclose their children in secondary MediaQuery +/// widgets that reduce those properties by the same amount. +/// The [removePadding], [removeViewPadding], and [removeViewInsets] methods are +/// useful for this. +/// +/// See also: +/// +/// * [Scaffold], [SafeArea], [CupertinoTabScaffold], and +/// [CupertinoPageScaffold], all of which are informed by [padding], +/// [viewPadding], and [viewInsets]. +@immutable +class MediaQueryData { + /// Creates data for a media query with explicit values. + /// + /// In a typical application, calling this constructor directly is rarely + /// needed. Consider using [MediaQueryData.fromView] to create data based on a + /// [dart:ui.FlutterView], or [MediaQueryData.copyWith] to create a new copy + /// of [MediaQueryData] with updated properties from a base [MediaQueryData]. + const MediaQueryData({ + this.size = Size.zero, + this.devicePixelRatio = 1.0, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double textScaleFactor = 1.0, + TextScaler textScaler = _kUnspecifiedTextScaler, + this.platformBrightness = Brightness.light, + this.padding = EdgeInsets.zero, + this.viewInsets = EdgeInsets.zero, + this.systemGestureInsets = EdgeInsets.zero, + this.viewPadding = EdgeInsets.zero, + this.alwaysUse24HourFormat = false, + this.accessibleNavigation = false, + this.invertColors = false, + this.highContrast = false, + this.onOffSwitchLabels = false, + this.disableAnimations = false, + this.boldText = false, + this.navigationMode = NavigationMode.traditional, + this.gestureSettings = const DeviceGestureSettings(touchSlop: kTouchSlop), + this.displayFeatures = const <ui.DisplayFeature>[], + }) : _textScaleFactor = textScaleFactor, + _textScaler = textScaler, + assert( + identical(textScaler, _kUnspecifiedTextScaler) || textScaleFactor == 1.0, + 'textScaleFactor is deprecated and cannot be specified when textScaler is specified.', + ); + + /// Deprecated. Use [MediaQueryData.fromView] instead. + /// + /// This constructor was operating on a single window assumption. In + /// preparation for Flutter's upcoming multi-window support, it has been + /// deprecated. + @Deprecated( + 'Use MediaQueryData.fromView instead. ' + 'This constructor was deprecated in preparation for the upcoming multi-window support. ' + 'This feature was deprecated after v3.7.0-32.0.pre.' + ) + factory MediaQueryData.fromWindow(ui.FlutterView window) => MediaQueryData.fromView(window); + + /// Creates data for a [MediaQuery] based on the given `view`. + /// + /// If provided, the `platformData` is used to fill in the platform-specific + /// aspects of the newly created [MediaQueryData]. If `platformData` is null, + /// the `view`'s [PlatformDispatcher] is consulted to construct the + /// platform-specific data. + /// + /// Data which is exposed directly on the [FlutterView] is considered + /// view-specific. Data which is only exposed via the + /// [FlutterView.platformDispatcher] property is considered platform-specific. + /// + /// Callers of this method should ensure that they also register for + /// notifications so that the [MediaQueryData] can be updated when any data + /// used to construct it changes. Notifications to consider are: + /// + /// * [WidgetsBindingObserver.didChangeMetrics] or + /// [dart:ui.PlatformDispatcher.onMetricsChanged], + /// * [WidgetsBindingObserver.didChangeAccessibilityFeatures] or + /// [dart:ui.PlatformDispatcher.onAccessibilityFeaturesChanged], + /// * [WidgetsBindingObserver.didChangeTextScaleFactor] or + /// [dart:ui.PlatformDispatcher.onTextScaleFactorChanged], + /// * [WidgetsBindingObserver.didChangePlatformBrightness] or + /// [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged]. + /// + /// The last three notifications are only relevant if no `platformData` is + /// provided. If `platformData` is provided, callers should ensure to call + /// this method again when it changes to keep the constructed [MediaQueryData] + /// updated. + /// + /// In general, [MediaQuery.of], and its associated "...Of" methods, are the + /// appropriate way to obtain [MediaQueryData] from a widget. This `fromView` + /// constructor is primarily for use in the implementation of the framework + /// itself. + /// + /// See also: + /// + /// * [MediaQuery.fromView], which constructs [MediaQueryData] from a provided + /// [FlutterView], makes it available to descendant widgets, and sets up + /// the appropriate notification listeners to keep the data updated. + MediaQueryData.fromView(ui.FlutterView view, {MediaQueryData? platformData}) + : size = view.physicalSize / view.devicePixelRatio, + devicePixelRatio = view.devicePixelRatio, + _textScaleFactor = 1.0, // _textScaler is the source of truth. + _textScaler = _textScalerFromView(view, platformData), + platformBrightness = platformData?.platformBrightness ?? view.platformDispatcher.platformBrightness, + padding = EdgeInsets.fromViewPadding(view.padding, view.devicePixelRatio), + viewPadding = EdgeInsets.fromViewPadding(view.viewPadding, view.devicePixelRatio), + viewInsets = EdgeInsets.fromViewPadding(view.viewInsets, view.devicePixelRatio), + systemGestureInsets = EdgeInsets.fromViewPadding(view.systemGestureInsets, view.devicePixelRatio), + accessibleNavigation = platformData?.accessibleNavigation ?? view.platformDispatcher.accessibilityFeatures.accessibleNavigation, + invertColors = platformData?.invertColors ?? view.platformDispatcher.accessibilityFeatures.invertColors, + disableAnimations = platformData?.disableAnimations ?? view.platformDispatcher.accessibilityFeatures.disableAnimations, + boldText = platformData?.boldText ?? view.platformDispatcher.accessibilityFeatures.boldText, + highContrast = platformData?.highContrast ?? view.platformDispatcher.accessibilityFeatures.highContrast, + onOffSwitchLabels = platformData?.onOffSwitchLabels ?? view.platformDispatcher.accessibilityFeatures.onOffSwitchLabels, + alwaysUse24HourFormat = platformData?.alwaysUse24HourFormat ?? view.platformDispatcher.alwaysUse24HourFormat, + navigationMode = platformData?.navigationMode ?? NavigationMode.traditional, + gestureSettings = DeviceGestureSettings.fromView(view), + displayFeatures = view.displayFeatures; + + static TextScaler _textScalerFromView(ui.FlutterView view, MediaQueryData? platformData) { + final double scaleFactor = platformData?.textScaleFactor ?? view.platformDispatcher.textScaleFactor; + return scaleFactor == 1.0 ? TextScaler.noScaling : TextScaler.linear(scaleFactor); + } + + /// The size of the media in logical pixels (e.g, the size of the screen). + /// + /// Logical pixels are roughly the same visual size across devices. Physical + /// pixels are the size of the actual hardware pixels on the device. The + /// number of physical pixels per logical pixel is described by the + /// [devicePixelRatio]. + /// + /// Prefer using [MediaQuery.sizeOf] over [MediaQuery.of]`.size` to get the + /// size, since the former will only notify of changes in [size], while the + /// latter will notify for all [MediaQueryData] changes. + /// + /// For widgets drawn in an [Overlay], do not assume that the size of the + /// [Overlay] is the size of the [MediaQuery]'s size. Nested overlays can have + /// different sizes. + /// + /// ## Troubleshooting + /// + /// It is considered bad practice to cache and later use the size returned by + /// `MediaQuery.sizeOf(context)`. It will make the application non-responsive + /// and might lead to unexpected behaviors. + /// + /// For instance, during startup, especially in release mode, the first + /// returned size might be [Size.zero]. The size will be updated when the + /// native platform reports the actual resolution. Using [MediaQuery.sizeOf] + /// will ensure that when the size changes, any widgets depending on the size + /// are automatically rebuilt. + /// + /// See the article on [Creating responsive and adaptive + /// apps](https://docs.flutter.dev/development/ui/layout/adaptive-responsive) + /// for an introduction. + /// + /// See also: + /// + /// * [FlutterView.physicalSize], which returns the size of the view in physical pixels. + /// * [FlutterView.display], which returns reports display information like size, and refresh rate. + /// * [MediaQuery.sizeOf], a method to find and depend on the size defined for + /// a [BuildContext]. + final Size size; + + /// The number of device pixels for each logical pixel. This number might not + /// be a power of two. Indeed, it might not even be an integer. For example, + /// the Nexus 6 has a device pixel ratio of 3.5. + final double devicePixelRatio; + + /// Deprecated. Will be removed in a future version of Flutter. Use + /// [textScaler] instead. + /// + /// The number of font pixels for each logical pixel. + /// + /// For example, if the text scale factor is 1.5, text will be 50% larger than + /// the specified font size. + /// + /// See also: + /// + /// * [MediaQuery.textScaleFactorOf], a method to find and depend on the + /// textScaleFactor defined for a [BuildContext]. + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double get textScaleFactor => textScaler.textScaleFactor; + // TODO(LongCatIsLooong): remove this after textScaleFactor is removed. To + // maintain backward compatibility and also keep the const constructor this + // has to be kept as a private field. + // https://github.com/flutter/flutter/issues/128825 + final double _textScaleFactor; + + /// The font scaling strategy to use for laying out textual contents. + /// + /// If this [MediaQueryData] is created by the [MediaQueryData.fromView] + /// constructor, this property reflects the platform's preferred text scaling + /// strategy, and may change as the user changes the scaling factor in the + /// operating system's accessibility settings. + /// + /// See also: + /// + /// * [MediaQuery.textScalerOf], a method to find and depend on the + /// [textScaler] defined for a [BuildContext]. + /// * [TextPainter], a class that lays out and paints text. + TextScaler get textScaler { + // The constructor was called with an explicitly specified textScaler value, + // we assume the caller is migrated and ignore _textScaleFactor. + if (!identical(_kUnspecifiedTextScaler, _textScaler)) { + return _textScaler; + } + return _textScaleFactor == 1.0 + // textScaleFactor and textScaler from the constructor are consistent. + ? TextScaler.noScaling + // The constructor was called with an explicitly specified textScaleFactor, + // we assume the caller is unmigrated and ignore _textScaler. + : TextScaler.linear(_textScaleFactor); + } + final TextScaler _textScaler; + + /// The current brightness mode of the host platform. + /// + /// For example, starting in Android Pie, battery saver mode asks all apps to + /// render in a "dark mode". + /// + /// Not all platforms necessarily support a concept of brightness mode. Those + /// platforms will report [Brightness.light] in this property. + /// + /// See also: + /// + /// * [MediaQuery.platformBrightnessOf], a method to find and depend on the + /// platformBrightness defined for a [BuildContext]. + final Brightness platformBrightness; + + /// The parts of the display that are completely obscured by system UI, + /// typically by the device's keyboard. + /// + /// When a mobile device's keyboard is visible `viewInsets.bottom` + /// corresponds to the top of the keyboard. + /// + /// This value is independent of the [padding] and [viewPadding]. viewPadding + /// is measured from the edges of the [MediaQuery] widget's bounds. Padding is + /// calculated based on the viewPadding and viewInsets. The bounds of the top + /// level MediaQuery created by [WidgetsApp] are the same as the window + /// (often the mobile device screen) that contains the app. + /// + /// {@youtube 560 315 https://www.youtube.com/watch?v=ceCo8U0XHqw} + /// + /// See also: + /// + /// * [FlutterView], which provides some additional detail about this property + /// and how it relates to [padding] and [viewPadding]. + final EdgeInsets viewInsets; + + /// The parts of the display that are partially obscured by system UI, + /// typically by the hardware display "notches" or the system status bar. + /// + /// If you consumed this padding (e.g. by building a widget that envelops or + /// accounts for this padding in its layout in such a way that children are + /// no longer exposed to this padding), you should remove this padding + /// for subsequent descendants in the widget tree by inserting a new + /// [MediaQuery] widget using the [MediaQuery.removePadding] factory. + /// + /// Padding is derived from the values of [viewInsets] and [viewPadding]. + /// + /// {@youtube 560 315 https://www.youtube.com/watch?v=ceCo8U0XHqw} + /// + /// See also: + /// + /// * [FlutterView], which provides some additional detail about this + /// property and how it relates to [viewInsets] and [viewPadding]. + /// * [SafeArea], a widget that consumes this padding with a [Padding] widget + /// and automatically removes it from the [MediaQuery] for its child. + final EdgeInsets padding; + + /// The parts of the display that are partially obscured by system UI, + /// typically by the hardware display "notches" or the system status bar. + /// + /// This value remains the same regardless of whether the system is reporting + /// other obstructions in the same physical area of the screen. For example, a + /// software keyboard on the bottom of the screen that may cover and consume + /// the same area that requires bottom padding will not affect this value. + /// + /// This value is independent of the [padding] and [viewInsets]: their values + /// are measured from the edges of the [MediaQuery] widget's bounds. The + /// bounds of the top level MediaQuery created by [WidgetsApp] are the + /// same as the window that contains the app. On mobile devices, this will + /// typically be the full screen. + /// + /// {@youtube 560 315 https://www.youtube.com/watch?v=ceCo8U0XHqw} + /// + /// See also: + /// + /// * [FlutterView], which provides some additional detail about this + /// property and how it relates to [padding] and [viewInsets]. + final EdgeInsets viewPadding; + + /// The areas along the edges of the display where the system consumes + /// certain input events and blocks delivery of those events to the app. + /// + /// Starting with Android Q, simple swipe gestures that start within the + /// [systemGestureInsets] areas are used by the system for page navigation + /// and may not be delivered to the app. Taps and swipe gestures that begin + /// with a long-press are delivered to the app, but simple press-drag-release + /// swipe gestures which begin within the area defined by [systemGestureInsets] + /// may not be. + /// + /// Apps should avoid locating gesture detectors within the system gesture + /// insets area. Apps should feel free to put visual elements within + /// this area. + /// + /// This property is currently only expected to be set to a non-default value + /// on Android starting with version Q. + /// + /// {@tool dartpad} + /// For apps that might be deployed on Android Q devices with full gesture + /// navigation enabled, use [systemGestureInsets] with [Padding] + /// to avoid having the left and right edges of the [Slider] from appearing + /// within the area reserved for system gesture navigation. + /// + /// By default, [Slider]s expand to fill the available width. So, we pad the + /// left and right sides. + /// + /// ** See code in examples/api/lib/widgets/media_query/media_query_data.system_gesture_insets.0.dart ** + /// {@end-tool} + final EdgeInsets systemGestureInsets; + + /// Whether to use 24-hour format when formatting time. + /// + /// The behavior of this flag is different across platforms: + /// + /// - On Android this flag is reported directly from the user settings called + /// "Use 24-hour format". It applies to any locale used by the application, + /// whether it is the system-wide locale, or the custom locale set by the + /// application. + /// - On iOS this flag is set to true when the user setting called "24-Hour + /// Time" is set or the system-wide locale's default uses 24-hour + /// formatting. + final bool alwaysUse24HourFormat; + + /// Whether the user is using an accessibility service like TalkBack or + /// VoiceOver to interact with the application. + /// + /// When this setting is true, features such as timeouts should be disabled or + /// have minimum durations increased. + /// + /// See also: + /// + /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting originates. + final bool accessibleNavigation; + + /// Whether the device is inverting the colors of the platform. + /// + /// This flag is currently only updated on iOS devices. + /// + /// See also: + /// + /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting + /// originates. + final bool invertColors; + + /// Whether the user requested a high contrast between foreground and background + /// content on iOS, via Settings -> Accessibility -> Increase Contrast. + /// + /// This flag is currently only updated on iOS devices that are running iOS 13 + /// or above. + final bool highContrast; + + /// Whether the user requested to show on/off labels inside switches on iOS, + /// via Settings -> Accessibility -> Display & Text Size -> On/Off Labels. + /// + /// See also: + /// + /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting + /// originates. + final bool onOffSwitchLabels; + + /// Whether the platform is requesting that animations be disabled or reduced + /// as much as possible. + /// + /// See also: + /// + /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting + /// originates. + final bool disableAnimations; + + /// Whether the platform is requesting that text be drawn with a bold font + /// weight. + /// + /// See also: + /// + /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting + /// originates. + final bool boldText; + + /// Describes the navigation mode requested by the platform. + /// + /// Some user interfaces are better navigated using a directional pad (DPAD) + /// or arrow keys, and for those interfaces, some widgets need to handle these + /// directional events differently. In order to know when to do that, these + /// widgets will look for the navigation mode in effect for their context. + /// + /// For instance, in a television interface, [NavigationMode.directional] + /// should be set, so that directional navigation is used to navigate away + /// from a text field using the DPAD. In contrast, on a regular desktop + /// application with the [navigationMode] set to [NavigationMode.traditional], + /// the arrow keys are used to move the cursor instead of navigating away. + /// + /// The [NavigationMode] values indicate the type of navigation to be used in + /// a widget subtree for those widgets sensitive to it. + final NavigationMode navigationMode; + + /// The gesture settings for the view this media query is derived from. + /// + /// This contains platform specific configuration for gesture behavior, + /// such as touch slop. These settings should be favored for configuring + /// gesture behavior over the framework constants. + final DeviceGestureSettings gestureSettings; + + /// {@macro dart.ui.ViewConfiguration.displayFeatures} + /// + /// See also: + /// + /// * [dart:ui.DisplayFeatureType], which lists the different types of + /// display features and explains the differences between them. + /// * [dart:ui.DisplayFeatureState], which lists the possible states for + /// folding features ([dart:ui.DisplayFeatureType.fold] and + /// [dart:ui.DisplayFeatureType.hinge]). + final List<ui.DisplayFeature> displayFeatures; + + /// The orientation of the media (e.g., whether the device is in landscape or + /// portrait mode). + Orientation get orientation { + return size.width > size.height ? Orientation.landscape : Orientation.portrait; + } + + /// Creates a copy of this media query data but with the given fields replaced + /// with the new values. + /// + /// The `textScaler` parameter and `textScaleFactor` parameter must not be + /// both specified. + MediaQueryData copyWith({ + Size? size, + double? devicePixelRatio, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + double? textScaleFactor, + TextScaler? textScaler, + Brightness? platformBrightness, + EdgeInsets? padding, + EdgeInsets? viewPadding, + EdgeInsets? viewInsets, + EdgeInsets? systemGestureInsets, + bool? alwaysUse24HourFormat, + bool? highContrast, + bool? onOffSwitchLabels, + bool? disableAnimations, + bool? invertColors, + bool? accessibleNavigation, + bool? boldText, + NavigationMode? navigationMode, + DeviceGestureSettings? gestureSettings, + List<ui.DisplayFeature>? displayFeatures, + }) { + assert(textScaleFactor == null || textScaler == null); + if (textScaleFactor != null) { + textScaler ??= TextScaler.linear(textScaleFactor); + } + return MediaQueryData( + size: size ?? this.size, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + textScaler: textScaler ?? this.textScaler, + platformBrightness: platformBrightness ?? this.platformBrightness, + padding: padding ?? this.padding, + viewPadding: viewPadding ?? this.viewPadding, + viewInsets: viewInsets ?? this.viewInsets, + systemGestureInsets: systemGestureInsets ?? this.systemGestureInsets, + alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat, + invertColors: invertColors ?? this.invertColors, + highContrast: highContrast ?? this.highContrast, + onOffSwitchLabels: onOffSwitchLabels ?? this.onOffSwitchLabels, + disableAnimations: disableAnimations ?? this.disableAnimations, + accessibleNavigation: accessibleNavigation ?? this.accessibleNavigation, + boldText: boldText ?? this.boldText, + navigationMode: navigationMode ?? this.navigationMode, + gestureSettings: gestureSettings ?? this.gestureSettings, + displayFeatures: displayFeatures ?? this.displayFeatures, + ); + } + + /// Creates a copy of this media query data but with the given [padding]s + /// replaced with zero. + /// + /// If all four of the `removeLeft`, `removeTop`, `removeRight`, and + /// `removeBottom` arguments are false (the default), then this + /// [MediaQueryData] is returned unmodified. + /// + /// See also: + /// + /// * [MediaQuery.removePadding], which uses this method to remove [padding] + /// from the ambient [MediaQuery]. + /// * [SafeArea], which both removes the padding from the [MediaQuery] and + /// adds a [Padding] widget. + /// * [removeViewInsets], the same thing but for [viewInsets]. + /// * [removeViewPadding], the same thing but for [viewPadding]. + MediaQueryData removePadding({ + bool removeLeft = false, + bool removeTop = false, + bool removeRight = false, + bool removeBottom = false, + }) { + if (!(removeLeft || removeTop || removeRight || removeBottom)) { + return this; + } + return copyWith( + padding: padding.copyWith( + left: removeLeft ? 0.0 : null, + top: removeTop ? 0.0 : null, + right: removeRight ? 0.0 : null, + bottom: removeBottom ? 0.0 : null, + ), + viewPadding: viewPadding.copyWith( + left: removeLeft ? math.max(0.0, viewPadding.left - padding.left) : null, + top: removeTop ? math.max(0.0, viewPadding.top - padding.top) : null, + right: removeRight ? math.max(0.0, viewPadding.right - padding.right) : null, + bottom: removeBottom ? math.max(0.0, viewPadding.bottom - padding.bottom) : null, + ), + ); + } + + /// Creates a copy of this media query data but with the given [viewInsets] + /// replaced with zero. + /// + /// If all four of the `removeLeft`, `removeTop`, `removeRight`, and + /// `removeBottom` arguments are false (the default), then this + /// [MediaQueryData] is returned unmodified. + /// + /// See also: + /// + /// * [MediaQuery.removeViewInsets], which uses this method to remove + /// [viewInsets] from the ambient [MediaQuery]. + /// * [removePadding], the same thing but for [padding]. + /// * [removeViewPadding], the same thing but for [viewPadding]. + MediaQueryData removeViewInsets({ + bool removeLeft = false, + bool removeTop = false, + bool removeRight = false, + bool removeBottom = false, + }) { + if (!(removeLeft || removeTop || removeRight || removeBottom)) { + return this; + } + return copyWith( + viewPadding: viewPadding.copyWith( + left: removeLeft ? math.max(0.0, viewPadding.left - viewInsets.left) : null, + top: removeTop ? math.max(0.0, viewPadding.top - viewInsets.top) : null, + right: removeRight ? math.max(0.0, viewPadding.right - viewInsets.right) : null, + bottom: removeBottom ? math.max(0.0, viewPadding.bottom - viewInsets.bottom) : null, + ), + viewInsets: viewInsets.copyWith( + left: removeLeft ? 0.0 : null, + top: removeTop ? 0.0 : null, + right: removeRight ? 0.0 : null, + bottom: removeBottom ? 0.0 : null, + ), + ); + } + + /// Creates a copy of this media query data but with the given [viewPadding] + /// replaced with zero. + /// + /// If all four of the `removeLeft`, `removeTop`, `removeRight`, and + /// `removeBottom` arguments are false (the default), then this + /// [MediaQueryData] is returned unmodified. + /// + /// See also: + /// + /// * [MediaQuery.removeViewPadding], which uses this method to remove + /// [viewPadding] from the ambient [MediaQuery]. + /// * [removePadding], the same thing but for [padding]. + /// * [removeViewInsets], the same thing but for [viewInsets]. + MediaQueryData removeViewPadding({ + bool removeLeft = false, + bool removeTop = false, + bool removeRight = false, + bool removeBottom = false, + }) { + if (!(removeLeft || removeTop || removeRight || removeBottom)) { + return this; + } + return copyWith( + padding: padding.copyWith( + left: removeLeft ? 0.0 : null, + top: removeTop ? 0.0 : null, + right: removeRight ? 0.0 : null, + bottom: removeBottom ? 0.0 : null, + ), + viewPadding: viewPadding.copyWith( + left: removeLeft ? 0.0 : null, + top: removeTop ? 0.0 : null, + right: removeRight ? 0.0 : null, + bottom: removeBottom ? 0.0 : null, + ), + ); + } + + /// Creates a copy of this media query data by removing [displayFeatures] that + /// are completely outside the given sub-screen and adjusting the [padding], + /// [viewInsets] and [viewPadding] to be zero on the sides that are not + /// included in the sub-screen. + /// + /// Returns unmodified [MediaQueryData] if the sub-screen coincides with the + /// available screen space. + /// + /// Asserts in debug mode, if the given sub-screen is outside the available + /// screen space. + /// + /// See also: + /// + /// * [DisplayFeatureSubScreen], which removes the display features that + /// split the screen, from the [MediaQuery] and adds a [Padding] widget to + /// position the child to match the selected sub-screen. + MediaQueryData removeDisplayFeatures(Rect subScreen) { + assert(subScreen.left >= 0.0 && subScreen.top >= 0.0 && + subScreen.right <= size.width && subScreen.bottom <= size.height, + "'subScreen' argument cannot be outside the bounds of the screen"); + if (subScreen.size == size && subScreen.topLeft == Offset.zero) { + return this; + } + final double rightInset = size.width - subScreen.right; + final double bottomInset = size.height - subScreen.bottom; + return copyWith( + padding: EdgeInsets.only( + left: math.max(0.0, padding.left - subScreen.left), + top: math.max(0.0, padding.top - subScreen.top), + right: math.max(0.0, padding.right - rightInset), + bottom: math.max(0.0, padding.bottom - bottomInset), + ), + viewPadding: EdgeInsets.only( + left: math.max(0.0, viewPadding.left - subScreen.left), + top: math.max(0.0, viewPadding.top - subScreen.top), + right: math.max(0.0, viewPadding.right - rightInset), + bottom: math.max(0.0, viewPadding.bottom - bottomInset), + ), + viewInsets: EdgeInsets.only( + left: math.max(0.0, viewInsets.left - subScreen.left), + top: math.max(0.0, viewInsets.top - subScreen.top), + right: math.max(0.0, viewInsets.right - rightInset), + bottom: math.max(0.0, viewInsets.bottom - bottomInset), + ), + displayFeatures: displayFeatures.where( + (ui.DisplayFeature displayFeature) => subScreen.overlaps(displayFeature.bounds) + ).toList(), + ); + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is MediaQueryData + && other.size == size + && other.devicePixelRatio == devicePixelRatio + && other.textScaleFactor == textScaleFactor + && other.platformBrightness == platformBrightness + && other.padding == padding + && other.viewPadding == viewPadding + && other.viewInsets == viewInsets + && other.systemGestureInsets == systemGestureInsets + && other.alwaysUse24HourFormat == alwaysUse24HourFormat + && other.highContrast == highContrast + && other.onOffSwitchLabels == onOffSwitchLabels + && other.disableAnimations == disableAnimations + && other.invertColors == invertColors + && other.accessibleNavigation == accessibleNavigation + && other.boldText == boldText + && other.navigationMode == navigationMode + && other.gestureSettings == gestureSettings + && listEquals(other.displayFeatures, displayFeatures); + } + + @override + int get hashCode => Object.hash( + size, + devicePixelRatio, + textScaleFactor, + platformBrightness, + padding, + viewPadding, + viewInsets, + alwaysUse24HourFormat, + highContrast, + onOffSwitchLabels, + disableAnimations, + invertColors, + accessibleNavigation, + boldText, + navigationMode, + gestureSettings, + Object.hashAll(displayFeatures), + ); + + @override + String toString() { + final List<String> properties = <String>[ + 'size: $size', + 'devicePixelRatio: ${devicePixelRatio.toStringAsFixed(1)}', + 'textScaler: $textScaler', + 'platformBrightness: $platformBrightness', + 'padding: $padding', + 'viewPadding: $viewPadding', + 'viewInsets: $viewInsets', + 'systemGestureInsets: $systemGestureInsets', + 'alwaysUse24HourFormat: $alwaysUse24HourFormat', + 'accessibleNavigation: $accessibleNavigation', + 'highContrast: $highContrast', + 'onOffSwitchLabels: $onOffSwitchLabels', + 'disableAnimations: $disableAnimations', + 'invertColors: $invertColors', + 'boldText: $boldText', + 'navigationMode: ${navigationMode.name}', + 'gestureSettings: $gestureSettings', + 'displayFeatures: $displayFeatures', + ]; + return '${objectRuntimeType(this, 'MediaQueryData')}(${properties.join(', ')})'; + } +} + +/// Establishes a subtree in which media queries resolve to the given data. +/// +/// For example, to learn the size of the current view (e.g., +/// the [FlutterView] containing your app), you can use [MediaQuery.sizeOf]: +/// `MediaQuery.sizeOf(context)`. +/// +/// Querying the current media using specific methods (for example, +/// [MediaQuery.sizeOf] or [MediaQuery.paddingOf]) will cause your widget to +/// rebuild automatically whenever that specific property changes. +/// +/// {@template flutter.widgets.media_query.MediaQuery.useSpecific} +/// Querying using [MediaQuery.of] will cause your widget to rebuild +/// automatically whenever _any_ field of the [MediaQueryData] changes (e.g., if +/// the user rotates their device). Therefore, unless you are concerned with the +/// entire [MediaQueryData] object changing, prefer using the specific methods +/// (for example: [MediaQuery.sizeOf] and [MediaQuery.paddingOf]), as it will +/// rebuild more efficiently. +/// +/// If no [MediaQuery] is in scope then [MediaQuery.of] and the "...Of" methods +/// similar to [MediaQuery.sizeOf] will throw an exception. Alternatively, the +/// "maybe-" variant methods (such as [MediaQuery.maybeOf] and +/// [MediaQuery.maybeSizeOf]) can be used, which return null, instead of +/// throwing, when no [MediaQuery] is in scope. +/// {@endtemplate} +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=A3WrA4zAaPw} +/// +/// See also: +/// +/// * [WidgetsApp] and [MaterialApp], which introduce a [MediaQuery] and keep +/// it up to date with the current screen metrics as they change. +/// * [MediaQueryData], the data structure that represents the metrics. +class MediaQuery extends InheritedModel<_MediaQueryAspect> { + /// Creates a widget that provides [MediaQueryData] to its descendants. + const MediaQuery({ + super.key, + required this.data, + required super.child, + }); + + /// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery] + /// from the given context, but removes the specified padding. + /// + /// This should be inserted into the widget tree when the [MediaQuery] padding + /// is consumed by a widget in such a way that the padding is no longer + /// exposed to the widget's descendants or siblings. + /// + /// The [context] argument must have a [MediaQuery] in scope. + /// + /// If all four of the `removeLeft`, `removeTop`, `removeRight`, and + /// `removeBottom` arguments are false (the default), then the returned + /// [MediaQuery] reuses the ambient [MediaQueryData] unmodified, which is not + /// particularly useful. + /// + /// See also: + /// + /// * [SafeArea], which both removes the padding from the [MediaQuery] and + /// adds a [Padding] widget. + /// * [MediaQueryData.padding], the affected property of the + /// [MediaQueryData]. + /// * [removeViewInsets], the same thing but for [MediaQueryData.viewInsets]. + /// * [removeViewPadding], the same thing but for + /// [MediaQueryData.viewPadding]. + factory MediaQuery.removePadding({ + Key? key, + required BuildContext context, + bool removeLeft = false, + bool removeTop = false, + bool removeRight = false, + bool removeBottom = false, + required Widget child, + }) { + return MediaQuery( + key: key, + data: MediaQuery.of(context).removePadding( + removeLeft: removeLeft, + removeTop: removeTop, + removeRight: removeRight, + removeBottom: removeBottom, + ), + child: child, + ); + } + + /// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery] + /// from the given context, but removes the specified view insets. + /// + /// This should be inserted into the widget tree when the [MediaQuery] view + /// insets are consumed by a widget in such a way that the view insets are no + /// longer exposed to the widget's descendants or siblings. + /// + /// The [context] argument must have a [MediaQuery] in scope. + /// + /// If all four of the `removeLeft`, `removeTop`, `removeRight`, and + /// `removeBottom` arguments are false (the default), then the returned + /// [MediaQuery] reuses the ambient [MediaQueryData] unmodified, which is not + /// particularly useful. + /// + /// See also: + /// + /// * [MediaQueryData.viewInsets], the affected property of the + /// [MediaQueryData]. + /// * [removePadding], the same thing but for [MediaQueryData.padding]. + /// * [removeViewPadding], the same thing but for + /// [MediaQueryData.viewPadding]. + factory MediaQuery.removeViewInsets({ + Key? key, + required BuildContext context, + bool removeLeft = false, + bool removeTop = false, + bool removeRight = false, + bool removeBottom = false, + required Widget child, + }) { + return MediaQuery( + key: key, + data: MediaQuery.of(context).removeViewInsets( + removeLeft: removeLeft, + removeTop: removeTop, + removeRight: removeRight, + removeBottom: removeBottom, + ), + child: child, + ); + } + + /// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery] + /// from the given context, but removes the specified view padding. + /// + /// This should be inserted into the widget tree when the [MediaQuery] view + /// padding is consumed by a widget in such a way that the view padding is no + /// longer exposed to the widget's descendants or siblings. + /// + /// The [context] argument must have a [MediaQuery] in scope. + /// + /// If all four of the `removeLeft`, `removeTop`, `removeRight`, and + /// `removeBottom` arguments are false (the default), then the returned + /// [MediaQuery] reuses the ambient [MediaQueryData] unmodified, which is not + /// particularly useful. + /// + /// See also: + /// + /// * [MediaQueryData.viewPadding], the affected property of the + /// [MediaQueryData]. + /// * [removePadding], the same thing but for [MediaQueryData.padding]. + /// * [removeViewInsets], the same thing but for [MediaQueryData.viewInsets]. + factory MediaQuery.removeViewPadding({ + Key? key, + required BuildContext context, + bool removeLeft = false, + bool removeTop = false, + bool removeRight = false, + bool removeBottom = false, + required Widget child, + }) { + return MediaQuery( + key: key, + data: MediaQuery.of(context).removeViewPadding( + removeLeft: removeLeft, + removeTop: removeTop, + removeRight: removeRight, + removeBottom: removeBottom, + ), + child: child, + ); + } + + /// Deprecated. Use [MediaQuery.fromView] instead. + /// + /// This constructor was operating on a single window assumption. In + /// preparation for Flutter's upcoming multi-window support, it has been + /// deprecated. + /// + /// Replaced by [MediaQuery.fromView], which requires specifying the + /// [FlutterView] the [MediaQuery] is constructed for. The [FlutterView] can, + /// for example, be obtained from the context via [View.of] or from + /// [PlatformDispatcher.views]. + @Deprecated( + 'Use MediaQuery.fromView instead. ' + 'This constructor was deprecated in preparation for the upcoming multi-window support. ' + 'This feature was deprecated after v3.7.0-32.0.pre.' + ) + static Widget fromWindow({ + Key? key, + required Widget child, + }) { + return _MediaQueryFromView( + key: key, + view: WidgetsBinding.instance.window, + ignoreParentData: true, + child: child, + ); + } + + /// Wraps the [child] in a [MediaQuery] which is built using data from the + /// provided [view]. + /// + /// The [MediaQuery] is constructed using the platform-specific data of the + /// surrounding [MediaQuery] and the view-specific data of the provided + /// [view]. If no surrounding [MediaQuery] exists, the platform-specific data + /// is generated from the [PlatformDispatcher] associated with the provided + /// [view]. Any information that's exposed via the [PlatformDispatcher] is + /// considered platform-specific. Data exposed directly on the [FlutterView] + /// (excluding its [FlutterView.platformDispatcher] property) is considered + /// view-specific. + /// + /// The injected [MediaQuery] automatically updates when any of the data used + /// to construct it changes. + static Widget fromView({ + Key? key, + required FlutterView view, + required Widget child, + }) { + return _MediaQueryFromView( + key: key, + view: view, + child: child, + ); + } + + /// Wraps the `child` in a [MediaQuery] with its [MediaQueryData.textScaler] + /// set to [TextScaler.noScaling]. + /// + /// The returned widget must be inserted in a widget tree below an existing + /// [MediaQuery] widget. + /// + /// This can be used to prevent, for example, icon fonts from scaling as the + /// user adjusts the platform's text scaling value. + static Widget withNoTextScaling({ + Key? key, + required Widget child, + }) { + return Builder( + key: key, + builder: (BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + return MediaQuery( + data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling), + child: child, + ); + }, + ); + } + + /// Wraps the `child` in a [MediaQuery] and applies [TextScaler.clamp] on the + /// current [MediaQueryData.textScaler]. + /// + /// The returned widget must be inserted in a widget tree below an existing + /// [MediaQuery] widget. + /// + /// This is a convenience function to restrict the range of the scaled text + /// size to `[minScaleFactor * fontSize, maxScaleFactor * fontSize]` (to + /// prevent excessive text scaling that would break the UI, for example). When + /// `minScaleFactor` equals `maxScaleFactor`, the scaler becomes + /// `TextScaler.linear(minScaleFactor)`. + static Widget withClampedTextScaling({ + Key? key, + double minScaleFactor = 0.0, + double maxScaleFactor = double.infinity, + required Widget child, + }) { + assert(maxScaleFactor >= minScaleFactor); + assert(!maxScaleFactor.isNaN); + assert(minScaleFactor.isFinite); + assert(minScaleFactor >= 0); + + return Builder(builder: (BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final MediaQueryData data = MediaQuery.of(context); + return MediaQuery( + data: data.copyWith( + textScaler: data.textScaler.clamp(minScaleFactor: minScaleFactor, maxScaleFactor: maxScaleFactor), + ), + child: child, + ); + }); + } + + /// Contains information about the current media. + /// + /// For example, the [MediaQueryData.size] property contains the width and + /// height of the current window. + final MediaQueryData data; + + /// The data from the closest instance of this class that encloses the given + /// context. + /// + /// You can use this function to query the entire set of data held in the + /// current [MediaQueryData] object. When any of that information changes, + /// your widget will be scheduled to be rebuilt, keeping your widget + /// up-to-date. + /// + /// Since it is typical that the widget only requires a subset of properties + /// of the [MediaQueryData] object, prefer using the more specific methods + /// (for example: [MediaQuery.sizeOf] and [MediaQuery.paddingOf]), as those + /// methods will not cause a widget to rebuild when unrelated properties are + /// updated. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// MediaQueryData media = MediaQuery.of(context); + /// ``` + /// + /// If there is no [MediaQuery] in scope, this method will throw a [TypeError] + /// exception in release builds, and throw a descriptive [FlutterError] in + /// debug builds. + /// + /// See also: + /// + /// * [maybeOf], which doesn't throw or assert if it doesn't find a + /// [MediaQuery] ancestor. It returns null instead. + /// * [sizeOf] and other specific methods for retrieving and depending on + /// changes of a specific value. + static MediaQueryData of(BuildContext context) { + return _of(context); + } + + static MediaQueryData _of(BuildContext context, [_MediaQueryAspect? aspect]) { + assert(debugCheckHasMediaQuery(context)); + return InheritedModel.inheritFrom<MediaQuery>(context, aspect: aspect)!.data; + } + + /// The data from the closest instance of this class that encloses the given + /// context, if any. + /// + /// Use this function if you want to allow situations where no [MediaQuery] is + /// in scope. Prefer using [MediaQuery.of] in situations where a media query + /// is always expected to exist. + /// + /// If there is no [MediaQuery] in scope, then this function will return null. + /// + /// You can use this function to query the entire set of data held in the + /// current [MediaQueryData] object. When any of that information changes, + /// your widget will be scheduled to be rebuilt, keeping your widget + /// up-to-date. + /// + /// Since it is typical that the widget only requires a subset of properties + /// of the [MediaQueryData] object, prefer using the more specific methods + /// (for example: [MediaQuery.maybeSizeOf] and [MediaQuery.maybePaddingOf]), + /// as those methods will not cause a widget to rebuild when unrelated + /// properties are updated. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// MediaQueryData? mediaQuery = MediaQuery.maybeOf(context); + /// if (mediaQuery == null) { + /// // Do something else instead. + /// } + /// ``` + /// + /// See also: + /// + /// * [of], which will throw if it doesn't find a [MediaQuery] ancestor, + /// instead of returning null. + /// * [maybeSizeOf] and other specific methods for retrieving and depending on + /// changes of a specific value. + static MediaQueryData? maybeOf(BuildContext context) { + return _maybeOf(context); + } + + static MediaQueryData? _maybeOf(BuildContext context, [_MediaQueryAspect? aspect]) { + return InheritedModel.inheritFrom<MediaQuery>(context, aspect: aspect)?.data; + } + + /// Returns [MediaQueryData.size] from the nearest [MediaQuery] ancestor or + /// throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.size] property of the ancestor [MediaQuery] changes. + /// + /// {@template flutter.widgets.media_query.MediaQuery.dontUseOf} + /// Prefer using this function over getting the attribute directly from the + /// [MediaQueryData] returned from [of], because using this function will only + /// rebuild the `context` when this specific attribute changes, not when _any_ + /// attribute changes. + /// {@endtemplate} + static Size sizeOf(BuildContext context) => _of(context, _MediaQueryAspect.size).size; + + /// Returns [MediaQueryData.size] from the nearest [MediaQuery] ancestor or + /// null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.size] property of the ancestor [MediaQuery] changes. + /// + /// {@template flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + /// Prefer using this function over getting the attribute directly from the + /// [MediaQueryData] returned from [maybeOf], because using this function will + /// only rebuild the `context` when this specific attribute changes, not when + /// _any_ attribute changes. + /// {@endtemplate} + static Size? maybeSizeOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.size)?.size; + + /// Returns [MediaQueryData.orientation] for the nearest [MediaQuery] ancestor or + /// throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.orientation] property of the ancestor [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static Orientation orientationOf(BuildContext context) => _of(context, _MediaQueryAspect.orientation).orientation; + + /// Returns [MediaQueryData.orientation] for the nearest [MediaQuery] ancestor or + /// null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.orientation] property of the ancestor [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static Orientation? maybeOrientationOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.orientation)?.orientation; + + /// Returns [MediaQueryData.devicePixelRatio] for the nearest [MediaQuery] ancestor or + /// throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.devicePixelRatio] property of the ancestor [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static double devicePixelRatioOf(BuildContext context) => _of(context, _MediaQueryAspect.devicePixelRatio).devicePixelRatio; + + /// Returns [MediaQueryData.devicePixelRatio] for the nearest [MediaQuery] ancestor or + /// null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.devicePixelRatio] property of the ancestor [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static double? maybeDevicePixelRatioOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.devicePixelRatio)?.devicePixelRatio; + + /// Deprecated. Will be removed in a future version of Flutter. Use + /// [maybeTextScalerOf] instead. + /// + /// Returns [MediaQueryData.textScaleFactor] for the nearest [MediaQuery] ancestor or + /// 1.0, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.textScaleFactor] property of the ancestor [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + @Deprecated( + 'Use textScalerOf instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + static double textScaleFactorOf(BuildContext context) => maybeTextScaleFactorOf(context) ?? 1.0; + + /// Deprecated. Will be removed in a future version of Flutter. Use + /// [maybeTextScalerOf] instead. + /// + /// Returns [MediaQueryData.textScaleFactor] for the nearest [MediaQuery] ancestor or + /// null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.textScaleFactor] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + @Deprecated( + 'Use maybeTextScalerOf instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + static double? maybeTextScaleFactorOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.textScaleFactor)?.textScaleFactor; + + /// Returns the [MediaQueryData.textScaler] for the nearest [MediaQuery] + /// ancestor or [TextScaler.noScaling] if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.textScaler] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static TextScaler textScalerOf(BuildContext context) => maybeTextScalerOf(context) ?? TextScaler.noScaling; + + /// Returns the [MediaQueryData.textScaler] for the nearest [MediaQuery] + /// ancestor or null if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.textScaler] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static TextScaler? maybeTextScalerOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.textScaler)?.textScaler; + + /// Returns [MediaQueryData.platformBrightness] for the nearest [MediaQuery] + /// ancestor or [Brightness.light], if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.platformBrightness] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static Brightness platformBrightnessOf(BuildContext context) => maybePlatformBrightnessOf(context) ?? Brightness.light; + + /// Returns [MediaQueryData.platformBrightness] for the nearest [MediaQuery] + /// ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.platformBrightness] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static Brightness? maybePlatformBrightnessOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.platformBrightness)?.platformBrightness; + + /// Returns [MediaQueryData.padding] for the nearest [MediaQuery] ancestor or + /// throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.padding] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static EdgeInsets paddingOf(BuildContext context) => _of(context, _MediaQueryAspect.padding).padding; + + /// Returns [MediaQueryData.padding] for the nearest [MediaQuery] ancestor + /// or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.padding] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static EdgeInsets? maybePaddingOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.padding)?.padding; + + /// Returns [MediaQueryData.viewInsets] for the nearest [MediaQuery] ancestor + /// or throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.viewInsets] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static EdgeInsets viewInsetsOf(BuildContext context) => _of(context, _MediaQueryAspect.viewInsets).viewInsets; + + /// Returns [MediaQueryData.viewInsets] for the nearest [MediaQuery] ancestor + /// or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.viewInsets] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static EdgeInsets? maybeViewInsetsOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.viewInsets)?.viewInsets; + + /// Returns [MediaQueryData.systemGestureInsets] for the nearest [MediaQuery] + /// ancestor or throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.systemGestureInsets] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static EdgeInsets systemGestureInsetsOf(BuildContext context) => _of(context, _MediaQueryAspect.systemGestureInsets).systemGestureInsets; + + /// Returns [MediaQueryData.systemGestureInsets] for the nearest [MediaQuery] + /// ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.systemGestureInsets] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static EdgeInsets? maybeSystemGestureInsetsOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.systemGestureInsets)?.systemGestureInsets; + + /// Returns [MediaQueryData.viewPadding] for the nearest [MediaQuery] ancestor + /// or throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.viewPadding] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static EdgeInsets viewPaddingOf(BuildContext context) => _of(context, _MediaQueryAspect.viewPadding).viewPadding; + + /// Returns [MediaQueryData.viewPadding] for the nearest [MediaQuery] ancestor + /// or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.viewPadding] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static EdgeInsets? maybeViewPaddingOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.viewPadding)?.viewPadding; + + /// Returns [MediaQueryData.alwaysUse24HourFormat] for the nearest + /// [MediaQuery] ancestor or throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.alwaysUse24HourFormat] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static bool alwaysUse24HourFormatOf(BuildContext context) => _of(context, _MediaQueryAspect.alwaysUse24HourFormat).alwaysUse24HourFormat; + + /// Returns [MediaQueryData.alwaysUse24HourFormat] for the nearest + /// [MediaQuery] ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.alwaysUse24HourFormat] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static bool? maybeAlwaysUse24HourFormatOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.alwaysUse24HourFormat)?.alwaysUse24HourFormat; + + /// Returns [MediaQueryData.accessibleNavigation] for the nearest [MediaQuery] + /// ancestor or throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.accessibleNavigation] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static bool accessibleNavigationOf(BuildContext context) => _of(context, _MediaQueryAspect.accessibleNavigation).accessibleNavigation; + + /// Returns [MediaQueryData.accessibleNavigation] for the nearest [MediaQuery] + /// ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.accessibleNavigation] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static bool? maybeAccessibleNavigationOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.accessibleNavigation)?.accessibleNavigation; + + /// Returns [MediaQueryData.invertColors] for the nearest [MediaQuery] + /// ancestor or throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.invertColors] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static bool invertColorsOf(BuildContext context) => _of(context, _MediaQueryAspect.invertColors).invertColors; + + /// Returns [MediaQueryData.invertColors] for the nearest [MediaQuery] + /// ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.invertColors] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static bool? maybeInvertColorsOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.invertColors)?.invertColors; + + /// Returns [MediaQueryData.highContrast] for the nearest [MediaQuery] + /// ancestor or false, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.highContrast] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static bool highContrastOf(BuildContext context) => maybeHighContrastOf(context) ?? false; + + /// Returns [MediaQueryData.highContrast] for the nearest [MediaQuery] + /// ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.highContrast] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static bool? maybeHighContrastOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.highContrast)?.highContrast; + + /// Returns [MediaQueryData.onOffSwitchLabels] for the nearest [MediaQuery] + /// ancestor or false, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.onOffSwitchLabels] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static bool onOffSwitchLabelsOf(BuildContext context) => maybeOnOffSwitchLabelsOf(context) ?? false; + + /// Returns [MediaQueryData.onOffSwitchLabels] for the nearest [MediaQuery] + /// ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.onOffSwitchLabels] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static bool? maybeOnOffSwitchLabelsOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.onOffSwitchLabels)?.onOffSwitchLabels; + + /// Returns [MediaQueryData.disableAnimations] for the nearest [MediaQuery] + /// ancestor or false, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.disableAnimations] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static bool disableAnimationsOf(BuildContext context) => _of(context, _MediaQueryAspect.disableAnimations).disableAnimations; + + /// Returns [MediaQueryData.disableAnimations] for the nearest [MediaQuery] + /// ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.disableAnimations] property of the ancestor + /// [MediaQuery] changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static bool? maybeDisableAnimationsOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.disableAnimations)?.disableAnimations; + + /// Returns the [MediaQueryData.boldText] accessibility setting for the + /// nearest [MediaQuery] ancestor or false, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.boldText] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static bool boldTextOf(BuildContext context) => maybeBoldTextOf(context) ?? false; + + /// Returns the [MediaQueryData.boldText] accessibility setting for the + /// nearest [MediaQuery] ancestor or false, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.boldText] property of the ancestor [MediaQuery] + /// changes. + /// + /// Deprecated in favor of [boldTextOf]. + @Deprecated( + 'Migrate to boldTextOf. ' + 'This feature was deprecated after v3.5.0-9.0.pre.' + ) + static bool boldTextOverride(BuildContext context) => boldTextOf(context); + + /// Returns the [MediaQueryData.boldText] accessibility setting for the + /// nearest [MediaQuery] ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.boldText] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static bool? maybeBoldTextOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.boldText)?.boldText; + + /// Returns [MediaQueryData.navigationMode] for the nearest [MediaQuery] + /// ancestor or throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.navigationMode] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static NavigationMode navigationModeOf(BuildContext context) => _of(context, _MediaQueryAspect.navigationMode).navigationMode; + + /// Returns [MediaQueryData.navigationMode] for the nearest [MediaQuery] + /// ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.navigationMode] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static NavigationMode? maybeNavigationModeOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.navigationMode)?.navigationMode; + + /// Returns [MediaQueryData.gestureSettings] for the nearest [MediaQuery] + /// ancestor or throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.gestureSettings] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static DeviceGestureSettings gestureSettingsOf(BuildContext context) => _of(context, _MediaQueryAspect.gestureSettings).gestureSettings; + + /// Returns [MediaQueryData.gestureSettings] for the nearest [MediaQuery] + /// ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.gestureSettings] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static DeviceGestureSettings? maybeGestureSettingsOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.gestureSettings)?.gestureSettings; + + /// Returns [MediaQueryData.displayFeatures] for the nearest [MediaQuery] + /// ancestor or throws an exception, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.displayFeatures] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseOf} + static List<ui.DisplayFeature> displayFeaturesOf(BuildContext context) => _of(context, _MediaQueryAspect.displayFeatures).displayFeatures; + + /// Returns [MediaQueryData.displayFeatures] for the nearest [MediaQuery] + /// ancestor or null, if no such ancestor exists. + /// + /// Use of this method will cause the given [context] to rebuild any time that + /// the [MediaQueryData.displayFeatures] property of the ancestor [MediaQuery] + /// changes. + /// + /// {@macro flutter.widgets.media_query.MediaQuery.dontUseMaybeOf} + static List<ui.DisplayFeature>? maybeDisplayFeaturesOf(BuildContext context) => _maybeOf(context, _MediaQueryAspect.displayFeatures)?.displayFeatures; + + @override + bool updateShouldNotify(MediaQuery oldWidget) => data != oldWidget.data; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<MediaQueryData>('data', data, showName: false)); + } + + @override + bool updateShouldNotifyDependent(MediaQuery oldWidget, Set<Object> dependencies) { + for (final Object dependency in dependencies) { + if (dependency is _MediaQueryAspect) { + switch (dependency) { + case _MediaQueryAspect.size: + if (data.size != oldWidget.data.size) { + return true; + } + case _MediaQueryAspect.orientation: + if (data.orientation != oldWidget.data.orientation) { + return true; + } + case _MediaQueryAspect.devicePixelRatio: + if (data.devicePixelRatio != oldWidget.data.devicePixelRatio) { + return true; + } + case _MediaQueryAspect.textScaleFactor: + if (data.textScaleFactor != oldWidget.data.textScaleFactor) { + return true; + } + case _MediaQueryAspect.textScaler: + if (data.textScaler != oldWidget.data.textScaler) { + return true; + } + case _MediaQueryAspect.platformBrightness: + if (data.platformBrightness != oldWidget.data.platformBrightness) { + return true; + } + case _MediaQueryAspect.padding: + if (data.padding != oldWidget.data.padding) { + return true; + } + case _MediaQueryAspect.viewInsets: + if (data.viewInsets != oldWidget.data.viewInsets) { + return true; + } + case _MediaQueryAspect.systemGestureInsets: + if (data.systemGestureInsets != oldWidget.data.systemGestureInsets) { + return true; + } + case _MediaQueryAspect.viewPadding: + if (data.viewPadding != oldWidget.data.viewPadding) { + return true; + } + case _MediaQueryAspect.alwaysUse24HourFormat: + if (data.alwaysUse24HourFormat != oldWidget.data.alwaysUse24HourFormat) { + return true; + } + case _MediaQueryAspect.accessibleNavigation: + if (data.accessibleNavigation != oldWidget.data.accessibleNavigation) { + return true; + } + case _MediaQueryAspect.invertColors: + if (data.invertColors != oldWidget.data.invertColors) { + return true; + } + case _MediaQueryAspect.highContrast: + if (data.highContrast != oldWidget.data.highContrast) { + return true; + } + case _MediaQueryAspect.onOffSwitchLabels: + if (data.onOffSwitchLabels != oldWidget.data.onOffSwitchLabels) { + return true; + } + case _MediaQueryAspect.disableAnimations: + if (data.disableAnimations != oldWidget.data.disableAnimations) { + return true; + } + case _MediaQueryAspect.boldText: + if (data.boldText != oldWidget.data.boldText) { + return true; + } + case _MediaQueryAspect.navigationMode: + if (data.navigationMode != oldWidget.data.navigationMode) { + return true; + } + case _MediaQueryAspect.gestureSettings: + if (data.gestureSettings != oldWidget.data.gestureSettings) { + return true; + } + case _MediaQueryAspect.displayFeatures: + if (data.displayFeatures != oldWidget.data.displayFeatures) { + return true; + } + } + } + } + return false; + } +} + +/// Describes the navigation mode to be set by a [MediaQuery] widget. +/// +/// The different modes indicate the type of navigation to be used in a widget +/// subtree for those widgets sensitive to it. +/// +/// Use `MediaQuery.navigationModeOf(context)` to determine the navigation mode +/// in effect for the given context. Use a [MediaQuery] widget to set the +/// navigation mode for its descendant widgets. +enum NavigationMode { + /// This indicates a traditional keyboard-and-mouse navigation modality. + /// + /// This navigation mode is where the arrow keys can be used for secondary + /// modification operations, like moving sliders or cursors, and disabled + /// controls will lose focus and not be traversable. + traditional, + + /// This indicates a directional-based navigation mode. + /// + /// This navigation mode indicates that arrow keys should be reserved for + /// navigation operations, and secondary modifications operations, like moving + /// sliders or cursors, will use alternative bindings or be disabled. + /// + /// Some behaviors are also affected by this mode. For instance, disabled + /// controls will retain focus when disabled, and will be able to receive + /// focus (although they remain disabled) when traversed. + directional, +} + +class _MediaQueryFromView extends StatefulWidget { + const _MediaQueryFromView({ + super.key, + required this.view, + this.ignoreParentData = false, + required this.child, + }); + + final FlutterView view; + final bool ignoreParentData; + final Widget child; + + @override + State<_MediaQueryFromView> createState() => _MediaQueryFromViewState(); +} + +class _MediaQueryFromViewState extends State<_MediaQueryFromView> with WidgetsBindingObserver { + MediaQueryData? _parentData; + MediaQueryData? _data; + + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addObserver(this); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _updateParentData(); + _updateData(); + assert(_data != null); + } + + @override + void didUpdateWidget(_MediaQueryFromView oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.ignoreParentData != oldWidget.ignoreParentData) { + _updateParentData(); + } + if (_data == null || oldWidget.view != widget.view) { + _updateData(); + } + assert(_data != null); + } + + void _updateParentData() { + _parentData = widget.ignoreParentData ? null : MediaQuery.maybeOf(context); + _data = null; // _updateData must be called again after changing parent data. + } + + void _updateData() { + final MediaQueryData newData = MediaQueryData.fromView(widget.view, platformData: _parentData); + if (newData != _data) { + setState(() { + _data = newData; + }); + } + } + + @override + void didChangeAccessibilityFeatures() { + // If we have a parent, it dictates our accessibility features. If we don't + // have a parent, we get our accessibility features straight from the + // PlatformDispatcher and need to update our data in response to the + // PlatformDispatcher changing its accessibility features setting. + if (_parentData == null) { + _updateData(); + } + } + + @override + void didChangeMetrics() { + _updateData(); + } + + @override + void didChangeTextScaleFactor() { + // If we have a parent, it dictates our text scale factor. If we don't have + // a parent, we get our text scale factor from the PlatformDispatcher and + // need to update our data in response to the PlatformDispatcher changing + // its text scale factor setting. + if (_parentData == null) { + _updateData(); + } + } + + @override + void didChangePlatformBrightness() { + // If we have a parent, it dictates our platform brightness. If we don't + // have a parent, we get our platform brightness from the PlatformDispatcher + // and need to update our data in response to the PlatformDispatcher + // changing its platform brightness setting. + if (_parentData == null) { + _updateData(); + } + } + + @override + void dispose() { + WidgetsBinding.instance.removeObserver(this); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + MediaQueryData effectiveData = _data!; + // If we get our platformBrightness from the PlatformDispatcher (i.e. we have no parentData) replace it + // with the debugBrightnessOverride in non-release mode. + if (!kReleaseMode && _parentData == null && effectiveData.platformBrightness != debugBrightnessOverride) { + effectiveData = effectiveData.copyWith(platformBrightness: debugBrightnessOverride); + } + return MediaQuery( + data: effectiveData, + child: widget.child, + ); + } +} + +const TextScaler _kUnspecifiedTextScaler = _UnspecifiedTextScaler(); +// TODO(LongCatIsLooong): Remove once `MediaQueryData.textScaleFactor` is +// removed: https://github.com/flutter/flutter/issues/128825. +class _UnspecifiedTextScaler implements TextScaler { + const _UnspecifiedTextScaler(); + + @override + TextScaler clamp({double minScaleFactor = 0, double maxScaleFactor = double.infinity}) => throw UnimplementedError(); + + @override + double scale(double fontSize) => throw UnimplementedError(); + + @override + double get textScaleFactor => throw UnimplementedError(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/modal_barrier.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/modal_barrier.dart new file mode 100644 index 0000000000000000000000000000000000000000..f2a247a7d3b582b7104fe7a8744ab19034131a2e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/modal_barrier.dart @@ -0,0 +1,454 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'navigator.dart'; +import 'transitions.dart'; + +/// A widget that modifies the size of the [SemanticsNode.rect] created by its +/// child widget. +/// +/// It clips the focus in potentially four directions based on the +/// specified [EdgeInsets]. +/// +/// The size of the accessibility focus is adjusted based on value changes +/// inside the given [ValueNotifier]. +/// +/// See also: +/// +/// * [ModalBarrier], which utilizes this widget to adjust the barrier focus +/// size based on the size of the content layer rendered on top of it. +class _SemanticsClipper extends SingleChildRenderObjectWidget{ + /// creates a [SemanticsClipper] that updates the size of the + /// [SemanticsNode.rect] of its child based on the value inside the provided + /// [ValueNotifier], or a default value of [EdgeInsets.zero]. + const _SemanticsClipper({ + super.child, + required this.clipDetailsNotifier, + }); + + /// The [ValueNotifier] whose value determines how the child's + /// [SemanticsNode.rect] should be clipped in four directions. + final ValueNotifier<EdgeInsets> clipDetailsNotifier; + + @override + _RenderSemanticsClipper createRenderObject(BuildContext context) { + return _RenderSemanticsClipper(clipDetailsNotifier: clipDetailsNotifier,); + } + + @override + void updateRenderObject(BuildContext context, _RenderSemanticsClipper renderObject) { + renderObject.clipDetailsNotifier = clipDetailsNotifier; + } +} +/// Updates the [SemanticsNode.rect] of its child based on the value inside +/// provided [ValueNotifier]. +class _RenderSemanticsClipper extends RenderProxyBox { + /// Creates a [RenderProxyBox] that Updates the [SemanticsNode.rect] of its child + /// based on the value inside provided [ValueNotifier]. + _RenderSemanticsClipper({ + required ValueNotifier<EdgeInsets> clipDetailsNotifier, + RenderBox? child, + }) : _clipDetailsNotifier = clipDetailsNotifier, + super(child); + + ValueNotifier<EdgeInsets> _clipDetailsNotifier; + + /// The getter and setter retrieves / updates the [ValueNotifier] associated + /// with this clipper. + ValueNotifier<EdgeInsets> get clipDetailsNotifier => _clipDetailsNotifier; + set clipDetailsNotifier (ValueNotifier<EdgeInsets> newNotifier) { + if (_clipDetailsNotifier == newNotifier) { + return; + } + if (attached) { + _clipDetailsNotifier.removeListener(markNeedsSemanticsUpdate); + } + _clipDetailsNotifier = newNotifier; + _clipDetailsNotifier.addListener(markNeedsSemanticsUpdate); + markNeedsSemanticsUpdate(); + } + + @override + Rect get semanticBounds { + final EdgeInsets clipDetails = _clipDetailsNotifier.value; + final Rect originalRect = super.semanticBounds; + final Rect clippedRect = Rect.fromLTRB( + originalRect.left + clipDetails.left, + originalRect.top + clipDetails.top, + originalRect.right - clipDetails.right, + originalRect.bottom - clipDetails.bottom, + ); + return clippedRect; + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + clipDetailsNotifier.addListener(markNeedsSemanticsUpdate); + } + + @override + void detach() { + clipDetailsNotifier.removeListener(markNeedsSemanticsUpdate); + super.detach(); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.isSemanticBoundary = true; + } +} + +/// A widget that prevents the user from interacting with widgets behind itself. +/// +/// The modal barrier is the scrim that is rendered behind each route, which +/// generally prevents the user from interacting with the route below the +/// current route, and normally partially obscures such routes. +/// +/// For example, when a dialog is on the screen, the page below the dialog is +/// usually darkened by the modal barrier. +/// +/// See also: +/// +/// * [ModalRoute], which indirectly uses this widget. +/// * [AnimatedModalBarrier], which is similar but takes an animated [color] +/// instead of a single color value. +class ModalBarrier extends StatelessWidget { + /// Creates a widget that blocks user interaction. + const ModalBarrier({ + super.key, + this.color, + this.dismissible = true, + this.onDismiss, + this.semanticsLabel, + this.barrierSemanticsDismissible = true, + this.clipDetailsNotifier, + this.semanticsOnTapHint, + }); + + /// If non-null, fill the barrier with this color. + /// + /// See also: + /// + /// * [ModalRoute.barrierColor], which controls this property for the + /// [ModalBarrier] built by [ModalRoute] pages. + final Color? color; + + /// Specifies if the barrier will be dismissed when the user taps on it. + /// + /// If true, and [onDismiss] is non-null, [onDismiss] will be called, + /// otherwise the current route will be popped from the ambient [Navigator]. + /// + /// If false, tapping on the barrier will do nothing. + /// + /// See also: + /// + /// * [ModalRoute.barrierDismissible], which controls this property for the + /// [ModalBarrier] built by [ModalRoute] pages. + final bool dismissible; + + /// {@template flutter.widgets.ModalBarrier.onDismiss} + /// Called when the barrier is being dismissed. + /// + /// If non-null [onDismiss] will be called in place of popping the current + /// route. It is up to the callback to handle dismissing the barrier. + /// + /// If null, the ambient [Navigator]'s current route will be popped. + /// + /// This field is ignored if [dismissible] is false. + /// {@endtemplate} + final VoidCallback? onDismiss; + + /// Whether the modal barrier semantics are included in the semantics tree. + /// + /// See also: + /// + /// * [ModalRoute.semanticsDismissible], which controls this property for + /// the [ModalBarrier] built by [ModalRoute] pages. + final bool? barrierSemanticsDismissible; + + /// Semantics label used for the barrier if it is [dismissible]. + /// + /// The semantics label is read out by accessibility tools (e.g. TalkBack + /// on Android and VoiceOver on iOS) when the barrier is focused. + /// + /// See also: + /// + /// * [ModalRoute.barrierLabel], which controls this property for the + /// [ModalBarrier] built by [ModalRoute] pages. + final String? semanticsLabel; + + /// {@template flutter.widgets.ModalBarrier.clipDetailsNotifier} + /// Contains a value of type [EdgeInsets] that specifies how the + /// [SemanticsNode.rect] of the widget should be clipped. + /// + /// See also: + /// + /// * [_SemanticsClipper], which utilizes the value inside to update the + /// [SemanticsNode.rect] for its child. + /// {@endtemplate} + final ValueNotifier<EdgeInsets>? clipDetailsNotifier; + + /// {@macro flutter.material.ModalBottomSheetRoute.barrierOnTapHint} + final String? semanticsOnTapHint; + + @override + Widget build(BuildContext context) { + assert(!dismissible || semanticsLabel == null || debugCheckHasDirectionality(context)); + final bool platformSupportsDismissingBarrier; + switch (defaultTargetPlatform) { + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + platformSupportsDismissingBarrier = false; + case TargetPlatform.android: + case TargetPlatform.iOS: + case TargetPlatform.macOS: + platformSupportsDismissingBarrier = true; + } + final bool semanticsDismissible = dismissible && platformSupportsDismissingBarrier; + final bool modalBarrierSemanticsDismissible = barrierSemanticsDismissible ?? semanticsDismissible; + + void handleDismiss() { + if (dismissible) { + if (onDismiss != null) { + onDismiss!(); + } else { + Navigator.maybePop(context); + } + } else { + SystemSound.play(SystemSoundType.alert); + } + } + + Widget barrier = Semantics( + onTapHint: semanticsOnTapHint, + onTap: semanticsDismissible && semanticsLabel != null ? handleDismiss : null, + onDismiss: semanticsDismissible && semanticsLabel != null ? handleDismiss : null, + label: semanticsDismissible ? semanticsLabel : null, + textDirection: semanticsDismissible && semanticsLabel != null ? Directionality.of(context) : null, + child: MouseRegion( + cursor: SystemMouseCursors.basic, + child: ConstrainedBox( + constraints: const BoxConstraints.expand(), + child: color == null ? null : ColoredBox( + color: color!, + ), + ), + ), + ); + + // Developers can set [dismissible: true] and [barrierSemanticsDismissible: true] + // to allow assistive technology users to dismiss a modal BottomSheet by + // tapping on the Scrim focus. + // On iOS, some modal barriers are not dismissible in accessibility mode. + final bool excluding = !semanticsDismissible || !modalBarrierSemanticsDismissible; + + if (!excluding && clipDetailsNotifier != null) { + barrier = _SemanticsClipper( + clipDetailsNotifier: clipDetailsNotifier!, + child: barrier, + ); + } + + return BlockSemantics( + child: ExcludeSemantics( + excluding: excluding, + child: _ModalBarrierGestureDetector( + onDismiss: handleDismiss, + child: barrier, + ), + ), + ); + } +} + +/// A widget that prevents the user from interacting with widgets behind itself, +/// and can be configured with an animated color value. +/// +/// The modal barrier is the scrim that is rendered behind each route, which +/// generally prevents the user from interacting with the route below the +/// current route, and normally partially obscures such routes. +/// +/// For example, when a dialog is on the screen, the page below the dialog is +/// usually darkened by the modal barrier. +/// +/// This widget is similar to [ModalBarrier] except that it takes an animated +/// [color] instead of a single color. +/// +/// See also: +/// +/// * [ModalRoute], which uses this widget. +class AnimatedModalBarrier extends AnimatedWidget { + /// Creates a widget that blocks user interaction. + const AnimatedModalBarrier({ + super.key, + required Animation<Color?> color, + this.dismissible = true, + this.semanticsLabel, + this.barrierSemanticsDismissible, + this.onDismiss, + this.clipDetailsNotifier, + this.semanticsOnTapHint, + }) : super(listenable: color); + + /// If non-null, fill the barrier with this color. + /// + /// See also: + /// + /// * [ModalRoute.barrierColor], which controls this property for the + /// [AnimatedModalBarrier] built by [ModalRoute] pages. + Animation<Color?> get color => listenable as Animation<Color?>; + + /// Whether touching the barrier will pop the current route off the [Navigator]. + /// + /// See also: + /// + /// * [ModalRoute.barrierDismissible], which controls this property for the + /// [AnimatedModalBarrier] built by [ModalRoute] pages. + final bool dismissible; + + /// Semantics label used for the barrier if it is [dismissible]. + /// + /// The semantics label is read out by accessibility tools (e.g. TalkBack + /// on Android and VoiceOver on iOS) when the barrier is focused. + /// See also: + /// + /// * [ModalRoute.barrierLabel], which controls this property for the + /// [ModalBarrier] built by [ModalRoute] pages. + final String? semanticsLabel; + + /// Whether the modal barrier semantics are included in the semantics tree. + /// + /// See also: + /// + /// * [ModalRoute.semanticsDismissible], which controls this property for + /// the [ModalBarrier] built by [ModalRoute] pages. + final bool? barrierSemanticsDismissible; + + /// {@macro flutter.widgets.ModalBarrier.onDismiss} + final VoidCallback? onDismiss; + + /// {@macro flutter.widgets.ModalBarrier.clipDetailsNotifier} + final ValueNotifier<EdgeInsets>? clipDetailsNotifier; + + /// This hint text instructs users what they are able to do when they tap on + /// the [ModalBarrier] + /// + /// E.g. If the hint text is 'close bottom sheet", it will be announced as + /// "Double tap to close bottom sheet". + /// + /// If this value is null, the default onTapHint will be applied, resulting + /// in the announcement of 'Double tap to activate'. + final String? semanticsOnTapHint; + + @override + Widget build(BuildContext context) { + return ModalBarrier( + color: color.value, + dismissible: dismissible, + semanticsLabel: semanticsLabel, + barrierSemanticsDismissible: barrierSemanticsDismissible, + onDismiss: onDismiss, + clipDetailsNotifier: clipDetailsNotifier, + semanticsOnTapHint: semanticsOnTapHint, + ); + } +} + +// Recognizes tap down by any pointer button. +// +// It is similar to [TapGestureRecognizer.onTapDown], but accepts any single +// button, which means the gesture also takes parts in gesture arenas. +class _AnyTapGestureRecognizer extends BaseTapGestureRecognizer { + _AnyTapGestureRecognizer(); + + VoidCallback? onAnyTapUp; + + @protected + @override + bool isPointerAllowed(PointerDownEvent event) { + if (onAnyTapUp == null) { + return false; + } + return super.isPointerAllowed(event); + } + + @protected + @override + void handleTapDown({PointerDownEvent? down}) { + // Do nothing. + } + + @protected + @override + void handleTapUp({PointerDownEvent? down, PointerUpEvent? up}) { + if (onAnyTapUp != null) { + invokeCallback('onAnyTapUp', onAnyTapUp!); + } + } + + @protected + @override + void handleTapCancel({PointerDownEvent? down, PointerCancelEvent? cancel, String? reason}) { + // Do nothing. + } + + @override + String get debugDescription => 'any tap'; +} + +class _AnyTapGestureRecognizerFactory extends GestureRecognizerFactory<_AnyTapGestureRecognizer> { + const _AnyTapGestureRecognizerFactory({this.onAnyTapUp}); + + final VoidCallback? onAnyTapUp; + + @override + _AnyTapGestureRecognizer constructor() => _AnyTapGestureRecognizer(); + + @override + void initializer(_AnyTapGestureRecognizer instance) { + instance.onAnyTapUp = onAnyTapUp; + } +} + +// A GestureDetector used by ModalBarrier. It only has one callback, +// [onAnyTapDown], which recognizes tap down unconditionally. +class _ModalBarrierGestureDetector extends StatelessWidget { + const _ModalBarrierGestureDetector({ + required this.child, + required this.onDismiss, + }); + + /// The widget below this widget in the tree. + /// See [RawGestureDetector.child]. + final Widget child; + + /// Immediately called when an event that should dismiss the modal barrier + /// has happened. + final VoidCallback onDismiss; + + @override + Widget build(BuildContext context) { + final Map<Type, GestureRecognizerFactory> gestures = <Type, GestureRecognizerFactory>{ + _AnyTapGestureRecognizer: _AnyTapGestureRecognizerFactory(onAnyTapUp: onDismiss), + }; + + return RawGestureDetector( + gestures: gestures, + behavior: HitTestBehavior.opaque, + child: child, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/navigation_toolbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/navigation_toolbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..8e196c285960cda0aa8f0de8f66b73767383dcc8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/navigation_toolbar.dart @@ -0,0 +1,174 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; + +/// [NavigationToolbar] is a layout helper to position 3 widgets or groups of +/// widgets along a horizontal axis that's sensible for an application's +/// navigation bar such as in Material Design and in iOS. +/// +/// The [leading] and [trailing] widgets occupy the edges of the widget with +/// reasonable size constraints while the [middle] widget occupies the remaining +/// space in either a center aligned or start aligned fashion. +/// +/// Either directly use the themed app bars such as the Material [AppBar] or +/// the iOS [CupertinoNavigationBar] or wrap this widget with more theming +/// specifications for your own custom app bar. +class NavigationToolbar extends StatelessWidget { + + /// Creates a widget that lays out its children in a manner suitable for a + /// toolbar. + const NavigationToolbar({ + super.key, + this.leading, + this.middle, + this.trailing, + this.centerMiddle = true, + this.middleSpacing = kMiddleSpacing, + }); + + /// The default spacing around the [middle] widget in dp. + static const double kMiddleSpacing = 16.0; + + /// Widget to place at the start of the horizontal toolbar. + final Widget? leading; + + /// Widget to place in the middle of the horizontal toolbar, occupying + /// as much remaining space as possible. + final Widget? middle; + + /// Widget to place at the end of the horizontal toolbar. + final Widget? trailing; + + /// Whether to align the [middle] widget to the center of this widget or + /// next to the [leading] widget when false. + final bool centerMiddle; + + /// The spacing around the [middle] widget on horizontal axis. + /// + /// Defaults to [kMiddleSpacing]. + final double middleSpacing; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + final TextDirection textDirection = Directionality.of(context); + return CustomMultiChildLayout( + delegate: _ToolbarLayout( + centerMiddle: centerMiddle, + middleSpacing: middleSpacing, + textDirection: textDirection, + ), + children: <Widget>[ + if (leading != null) LayoutId(id: _ToolbarSlot.leading, child: leading!), + if (middle != null) LayoutId(id: _ToolbarSlot.middle, child: middle!), + if (trailing != null) LayoutId(id: _ToolbarSlot.trailing, child: trailing!), + ], + ); + } +} + +enum _ToolbarSlot { + leading, + middle, + trailing, +} + +class _ToolbarLayout extends MultiChildLayoutDelegate { + _ToolbarLayout({ + required this.centerMiddle, + required this.middleSpacing, + required this.textDirection, + }); + + // If false the middle widget should be start-justified within the space + // between the leading and trailing widgets. + // If true the middle widget is centered within the toolbar (not within the horizontal + // space between the leading and trailing widgets). + final bool centerMiddle; + + /// The spacing around middle widget on horizontal axis. + final double middleSpacing; + + final TextDirection textDirection; + + @override + void performLayout(Size size) { + double leadingWidth = 0.0; + double trailingWidth = 0.0; + + if (hasChild(_ToolbarSlot.leading)) { + final BoxConstraints constraints = BoxConstraints( + maxWidth: size.width, + minHeight: size.height, // The height should be exactly the height of the bar. + maxHeight: size.height, + ); + leadingWidth = layoutChild(_ToolbarSlot.leading, constraints).width; + final double leadingX; + switch (textDirection) { + case TextDirection.rtl: + leadingX = size.width - leadingWidth; + case TextDirection.ltr: + leadingX = 0.0; + } + positionChild(_ToolbarSlot.leading, Offset(leadingX, 0.0)); + } + + if (hasChild(_ToolbarSlot.trailing)) { + final BoxConstraints constraints = BoxConstraints.loose(size); + final Size trailingSize = layoutChild(_ToolbarSlot.trailing, constraints); + final double trailingX; + switch (textDirection) { + case TextDirection.rtl: + trailingX = 0.0; + case TextDirection.ltr: + trailingX = size.width - trailingSize.width; + } + final double trailingY = (size.height - trailingSize.height) / 2.0; + trailingWidth = trailingSize.width; + positionChild(_ToolbarSlot.trailing, Offset(trailingX, trailingY)); + } + + if (hasChild(_ToolbarSlot.middle)) { + final double maxWidth = math.max(size.width - leadingWidth - trailingWidth - middleSpacing * 2.0, 0.0); + final BoxConstraints constraints = BoxConstraints.loose(size).copyWith(maxWidth: maxWidth); + final Size middleSize = layoutChild(_ToolbarSlot.middle, constraints); + + final double middleStartMargin = leadingWidth + middleSpacing; + double middleStart = middleStartMargin; + final double middleY = (size.height - middleSize.height) / 2.0; + // If the centered middle will not fit between the leading and trailing + // widgets, then align its left or right edge with the adjacent boundary. + if (centerMiddle) { + middleStart = (size.width - middleSize.width) / 2.0; + if (middleStart + middleSize.width > size.width - trailingWidth) { + middleStart = size.width - trailingWidth - middleSize.width - middleSpacing; + } else if (middleStart < middleStartMargin) { + middleStart = middleStartMargin; + } + } + + final double middleX; + switch (textDirection) { + case TextDirection.rtl: + middleX = size.width - middleSize.width - middleStart; + case TextDirection.ltr: + middleX = middleStart; + } + + positionChild(_ToolbarSlot.middle, Offset(middleX, middleY)); + } + } + + @override + bool shouldRelayout(_ToolbarLayout oldDelegate) { + return oldDelegate.centerMiddle != centerMiddle + || oldDelegate.middleSpacing != middleSpacing + || oldDelegate.textDirection != textDirection; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/navigator.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/navigator.dart new file mode 100644 index 0000000000000000000000000000000000000000..a781e6e3f53101ce8ac36595e2a3d8c4f2ae0d59 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/navigator.dart @@ -0,0 +1,6079 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:collection'; +import 'dart:convert'; +import 'dart:developer' as developer; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'basic.dart'; +import 'binding.dart'; +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'focus_traversal.dart'; +import 'framework.dart'; +import 'heroes.dart'; +import 'notification_listener.dart'; +import 'overlay.dart'; +import 'restoration.dart'; +import 'restoration_properties.dart'; +import 'routes.dart'; +import 'ticker_provider.dart'; + +// Duration for delay before refocusing in android so that the focus won't be interrupted. +const Duration _kAndroidRefocusingDelayDuration = Duration(milliseconds: 300); + +// Examples can assume: +// typedef MyAppHome = Placeholder; +// typedef MyHomePage = Placeholder; +// typedef MyPage = ListTile; // any const widget with a Widget "title" constructor argument would do +// late NavigatorState navigator; +// late BuildContext context; + +/// Creates a route for the given route settings. +/// +/// Used by [Navigator.onGenerateRoute]. +/// +/// See also: +/// +/// * [Navigator], which is where all the [Route]s end up. +typedef RouteFactory = Route<dynamic>? Function(RouteSettings settings); + +/// Creates a series of one or more routes. +/// +/// Used by [Navigator.onGenerateInitialRoutes]. +typedef RouteListFactory = List<Route<dynamic>> Function(NavigatorState navigator, String initialRoute); + +/// Creates a [Route] that is to be added to a [Navigator]. +/// +/// The route can be configured with the provided `arguments`. The provided +/// `context` is the `BuildContext` of the [Navigator] to which the route is +/// added. +/// +/// Used by the restorable methods of the [Navigator] that add anonymous routes +/// (e.g. [NavigatorState.restorablePush]). For this use case, the +/// [RestorableRouteBuilder] must be static function annotated with +/// `@pragma('vm:entry-point')`. The [Navigator] will call it again during +/// state restoration to re-create the route. +typedef RestorableRouteBuilder<T> = Route<T> Function(BuildContext context, Object? arguments); + +/// Signature for the [Navigator.popUntil] predicate argument. +typedef RoutePredicate = bool Function(Route<dynamic> route); + +/// Signature for a callback that verifies that it's OK to call [Navigator.pop]. +/// +/// Used by [Form.onWillPop], [ModalRoute.addScopedWillPopCallback], +/// [ModalRoute.removeScopedWillPopCallback], and [WillPopScope]. +@Deprecated( + 'Use PopInvokedCallback instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', +) +typedef WillPopCallback = Future<bool> Function(); + +/// Signature for the [Navigator.onPopPage] callback. +/// +/// This callback must call [Route.didPop] on the specified route and must +/// properly update the pages list the next time it is passed into +/// [Navigator.pages] so that it no longer includes the corresponding [Page]. +/// (Otherwise, the page will be interpreted as a new page to show when the +/// [Navigator.pages] list is next updated.) +typedef PopPageCallback = bool Function(Route<dynamic> route, dynamic result); + +/// Indicates whether the current route should be popped. +/// +/// Used as the return value for [Route.willPop]. +/// +/// See also: +/// +/// * [WillPopScope], a widget that hooks into the route's [Route.willPop] +/// mechanism. +enum RoutePopDisposition { + /// Pop the route. + /// + /// If [Route.willPop] or [Route.popDisposition] return [pop] then the back + /// button will actually pop the current route. + pop, + + /// Do not pop the route. + /// + /// If [Route.willPop] or [Route.popDisposition] return [doNotPop] then the + /// back button will be ignored. + doNotPop, + + /// Delegate this to the next level of navigation. + /// + /// If [Route.willPop] or [Route.popDisposition] return [bubble] then the back + /// button will be handled by the [SystemNavigator], which will usually close + /// the application. + bubble, +} + +/// An abstraction for an entry managed by a [Navigator]. +/// +/// This class defines an abstract interface between the navigator and the +/// "routes" that are pushed on and popped off the navigator. Most routes have +/// visual affordances, which they place in the navigators [Overlay] using one +/// or more [OverlayEntry] objects. +/// +/// See [Navigator] for more explanation of how to use a [Route] with +/// navigation, including code examples. +/// +/// See [MaterialPageRoute] for a route that replaces the entire screen with a +/// platform-adaptive transition. +/// +/// A route can belong to a page if the [settings] are a subclass of [Page]. A +/// page-based route, as opposed to a pageless route, is created from +/// [Page.createRoute] during [Navigator.pages] updates. The page associated +/// with this route may change during the lifetime of the route. If the +/// [Navigator] updates the page of this route, it calls [changedInternalState] +/// to notify the route that the page has been updated. +/// +/// The type argument `T` is the route's return type, as used by +/// [currentResult], [popped], and [didPop]. The type `void` may be used if the +/// route does not return a value. +abstract class Route<T> { + /// Initialize the [Route]. + /// + /// If the [settings] are not provided, an empty [RouteSettings] object is + /// used instead. + Route({ RouteSettings? settings }) : _settings = settings ?? const RouteSettings() { + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/widgets.dart', + className: '$Route<$T>', + object: this, + ); + } + } + + /// The navigator that the route is in, if any. + NavigatorState? get navigator => _navigator; + NavigatorState? _navigator; + + /// The settings for this route. + /// + /// See [RouteSettings] for details. + /// + /// The settings can change during the route's lifetime. If the settings + /// change, the route's overlays will be marked dirty (see + /// [changedInternalState]). + /// + /// If the route is created from a [Page] in the [Navigator.pages] list, then + /// this will be a [Page] subclass, and it will be updated each time its + /// corresponding [Page] in the [Navigator.pages] has changed. Once the + /// [Route] is removed from the history, this value stops updating (and + /// remains with its last value). + RouteSettings get settings => _settings; + RouteSettings _settings; + + /// The restoration scope ID to be used for the [RestorationScope] surrounding + /// this route. + /// + /// The restoration scope ID is null if restoration is currently disabled + /// for this route. + /// + /// If the restoration scope ID changes (e.g. because restoration is enabled + /// or disabled) during the life of the route, the [ValueListenable] notifies + /// its listeners. As an example, the ID changes to null while the route is + /// transitioning off screen, which triggers a notification on this field. At + /// that point, the route is considered as no longer present for restoration + /// purposes and its state will not be restored. + ValueListenable<String?> get restorationScopeId => _restorationScopeId; + final ValueNotifier<String?> _restorationScopeId = ValueNotifier<String?>(null); + + void _updateSettings(RouteSettings newSettings) { + if (_settings != newSettings) { + _settings = newSettings; + changedInternalState(); + } + } + + // ignore: use_setters_to_change_properties, (setters can't be private) + void _updateRestorationId(String? restorationId) { + _restorationScopeId.value = restorationId; + } + + /// The overlay entries of this route. + /// + /// These are typically populated by [install]. The [Navigator] is in charge + /// of adding them to and removing them from the [Overlay]. + /// + /// There must be at least one entry in this list after [install] has been + /// invoked. + /// + /// The [Navigator] will take care of keeping the entries together if the + /// route is moved in the history. + List<OverlayEntry> get overlayEntries => const <OverlayEntry>[]; + + /// Called when the route is inserted into the navigator. + /// + /// Uses this to populate [overlayEntries]. There must be at least one entry in + /// this list after [install] has been invoked. The [Navigator] will be in charge + /// to add them to the [Overlay] or remove them from it by calling + /// [OverlayEntry.remove]. + @protected + @mustCallSuper + void install() { } + + /// Called after [install] when the route is pushed onto the navigator. + /// + /// The returned value resolves when the push transition is complete. + /// + /// The [didAdd] method will be called instead of [didPush] when the route + /// immediately appears on screen without any push transition. + /// + /// The [didChangeNext] and [didChangePrevious] methods are typically called + /// immediately after this method is called. + @protected + @mustCallSuper + TickerFuture didPush() { + return TickerFuture.complete()..then<void>((void _) { + if (navigator?.widget.requestFocus ?? false) { + navigator!.focusNode.enclosingScope?.requestFocus(); + } + }); + } + + /// Called after [install] when the route is added to the navigator. + /// + /// This method is called instead of [didPush] when the route immediately + /// appears on screen without any push transition. + /// + /// The [didChangeNext] and [didChangePrevious] methods are typically called + /// immediately after this method is called. + @protected + @mustCallSuper + void didAdd() { + if (navigator?.widget.requestFocus ?? false) { + // This TickerFuture serves two purposes. First, we want to make sure that + // animations triggered by other operations will finish before focusing + // the navigator. Second, navigator.focusNode might acquire more focused + // children in Route.install asynchronously. This TickerFuture will wait + // for it to finish first. + // + // The later case can be found when subclasses manage their own focus scopes. + // For example, ModalRoute creates a focus scope in its overlay entries. The + // focused child can only be attached to navigator after initState which + // will be guarded by the asynchronous gap. + TickerFuture.complete().then<void>((void _) { + // The route can be disposed before the ticker future completes. This can + // happen when the navigator is under a TabView that warps from one tab to + // another, non-adjacent tab, with an animation. The TabView reorders its + // children before and after the warping completes, and that causes its + // children to be built and disposed within the same frame. If one of its + // children contains a navigator, the routes in that navigator are also + // added and disposed within that frame. + // + // Since the reference to the navigator will be set to null after it is + // disposed, we have to do a null-safe operation in case that happens + // within the same frame when it is added. + navigator?.focusNode.enclosingScope?.requestFocus(); + }); + } + } + + /// Called after [install] when the route replaced another in the navigator. + /// + /// The [didChangeNext] and [didChangePrevious] methods are typically called + /// immediately after this method is called. + @protected + @mustCallSuper + void didReplace(Route<dynamic>? oldRoute) { } + + /// Returns whether calling [Navigator.maybePop] when this [Route] is current + /// ([isCurrent]) should do anything. + /// + /// [Navigator.maybePop] is usually used instead of [Navigator.pop] to handle + /// the system back button. + /// + /// By default, if a [Route] is the first route in the history (i.e., if + /// [isFirst]), it reports that pops should be bubbled + /// ([RoutePopDisposition.bubble]). This behavior prevents the user from + /// popping the first route off the history and being stranded at a blank + /// screen; instead, the larger scope is popped (e.g. the application quits, + /// so that the user returns to the previous application). + /// + /// In other cases, the default behavior is to accept the pop + /// ([RoutePopDisposition.pop]). + /// + /// The third possible value is [RoutePopDisposition.doNotPop], which causes + /// the pop request to be ignored entirely. + /// + /// See also: + /// + /// * [Form], which provides a [Form.onWillPop] callback that uses this + /// mechanism. + /// * [WillPopScope], another widget that provides a way to intercept the + /// back button. + @Deprecated( + 'Use popDisposition instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', + ) + Future<RoutePopDisposition> willPop() async { + return isFirst ? RoutePopDisposition.bubble : RoutePopDisposition.pop; + } + + /// Returns whether calling [Navigator.maybePop] when this [Route] is current + /// ([isCurrent]) should do anything. + /// + /// [Navigator.maybePop] is usually used instead of [Navigator.pop] to handle + /// the system back button, when it hasn't been disabled via + /// [SystemNavigator.setFrameworkHandlesBack]. + /// + /// By default, if a [Route] is the first route in the history (i.e., if + /// [isFirst]), it reports that pops should be bubbled + /// ([RoutePopDisposition.bubble]). This behavior prevents the user from + /// popping the first route off the history and being stranded at a blank + /// screen; instead, the larger scope is popped (e.g. the application quits, + /// so that the user returns to the previous application). + /// + /// In other cases, the default behavior is to accept the pop + /// ([RoutePopDisposition.pop]). + /// + /// The third possible value is [RoutePopDisposition.doNotPop], which causes + /// the pop request to be ignored entirely. + /// + /// See also: + /// + /// * [Form], which provides a [Form.canPop] boolean that is similar. + /// * [PopScope], a widget that provides a way to intercept the back button. + RoutePopDisposition get popDisposition { + return isFirst ? RoutePopDisposition.bubble : RoutePopDisposition.pop; + } + + /// {@template flutter.widgets.navigator.onPopInvoked} + /// Called after a route pop was handled. + /// + /// Even when the pop is canceled, for example by a [PopScope] widget, this + /// will still be called. The `didPop` parameter indicates whether or not the + /// back navigation actually happened successfully. + /// {@endtemplate} + void onPopInvoked(bool didPop) {} + + /// Whether calling [didPop] would return false. + bool get willHandlePopInternally => false; + + /// When this route is popped (see [Navigator.pop]) if the result isn't + /// specified or if it's null, this value will be used instead. + /// + /// This fallback is implemented by [didComplete]. This value is used if the + /// argument to that method is null. + T? get currentResult => null; + + /// A future that completes when this route is popped off the navigator. + /// + /// The future completes with the value given to [Navigator.pop], if any, or + /// else the value of [currentResult]. See [didComplete] for more discussion + /// on this topic. + Future<T?> get popped => _popCompleter.future; + final Completer<T?> _popCompleter = Completer<T?>(); + + final Completer<T?> _disposeCompleter = Completer<T?>(); + + /// A request was made to pop this route. If the route can handle it + /// internally (e.g. because it has its own stack of internal state) then + /// return false, otherwise return true (by returning the value of calling + /// `super.didPop`). Returning false will prevent the default behavior of + /// [NavigatorState.pop]. + /// + /// When this function returns true, the navigator removes this route from + /// the history but does not yet call [dispose]. Instead, it is the route's + /// responsibility to call [NavigatorState.finalizeRoute], which will in turn + /// call [dispose] on the route. This sequence lets the route perform an + /// exit animation (or some other visual effect) after being popped but prior + /// to being disposed. + /// + /// This method should call [didComplete] to resolve the [popped] future (and + /// this is all that the default implementation does); routes should not wait + /// for their exit animation to complete before doing so. + /// + /// See [popped], [didComplete], and [currentResult] for a discussion of the + /// `result` argument. + @mustCallSuper + bool didPop(T? result) { + didComplete(result); + return true; + } + + /// The route was popped or is otherwise being removed somewhat gracefully. + /// + /// This is called by [didPop] and in response to + /// [NavigatorState.pushReplacement]. If [didPop] was not called, then the + /// [NavigatorState.finalizeRoute] method must be called immediately, and no exit + /// animation will run. + /// + /// The [popped] future is completed by this method. The `result` argument + /// specifies the value that this future is completed with, unless it is null, + /// in which case [currentResult] is used instead. + /// + /// This should be called before the pop animation, if any, takes place, + /// though in some cases the animation may be driven by the user before the + /// route is committed to being popped; this can in particular happen with the + /// iOS-style back gesture. See [NavigatorState.didStartUserGesture]. + @protected + @mustCallSuper + void didComplete(T? result) { + _popCompleter.complete(result ?? currentResult); + } + + /// The given route, which was above this one, has been popped off the + /// navigator. + /// + /// This route is now the current route ([isCurrent] is now true), and there + /// is no next route. + @protected + @mustCallSuper + void didPopNext(Route<dynamic> nextRoute) { } + + /// This route's next route has changed to the given new route. + /// + /// This is called on a route whenever the next route changes for any reason, + /// so long as it is in the history, including when a route is first added to + /// a [Navigator] (e.g. by [Navigator.push]), except for cases when + /// [didPopNext] would be called. + /// + /// The `nextRoute` argument will be null if there's no new next route (i.e. + /// if [isCurrent] is true). + @protected + @mustCallSuper + void didChangeNext(Route<dynamic>? nextRoute) { } + + /// This route's previous route has changed to the given new route. + /// + /// This is called on a route whenever the previous route changes for any + /// reason, so long as it is in the history, except for immediately after the + /// route itself has been pushed (in which case [didPush] or [didReplace] will + /// be called instead). + /// + /// The `previousRoute` argument will be null if there's no previous route + /// (i.e. if [isFirst] is true). + @protected + @mustCallSuper + void didChangePrevious(Route<dynamic>? previousRoute) { } + + /// Called whenever the internal state of the route has changed. + /// + /// This should be called whenever [willHandlePopInternally], [didPop], + /// [ModalRoute.offstage], or other internal state of the route changes value. + /// It is used by [ModalRoute], for example, to report the new information via + /// its inherited widget to any children of the route. + /// + /// See also: + /// + /// * [changedExternalState], which is called when the [Navigator] has + /// updated in some manner that might affect the routes. + @protected + @mustCallSuper + void changedInternalState() { } + + /// Called whenever the [Navigator] has updated in some manner that might + /// affect routes, to indicate that the route may wish to rebuild as well. + /// + /// This is called by the [Navigator] whenever the + /// [NavigatorState]'s [State.widget] changes (as in [State.didUpdateWidget]), + /// for example because the [MaterialApp] has been rebuilt. This + /// ensures that routes that directly refer to the state of the + /// widget that built the [MaterialApp] will be notified when that + /// widget rebuilds, since it would otherwise be difficult to notify + /// the routes that state they depend on may have changed. + /// + /// It is also called whenever the [Navigator]'s dependencies change + /// (as in [State.didChangeDependencies]). This allows routes to use the + /// [Navigator]'s context ([NavigatorState.context]), for example in + /// [ModalRoute.barrierColor], and update accordingly. + /// + /// The [ModalRoute] subclass overrides this to force the barrier + /// overlay to rebuild. + /// + /// See also: + /// + /// * [changedInternalState], the equivalent but for changes to the internal + /// state of the route. + @protected + @mustCallSuper + void changedExternalState() { } + + /// Discards any resources used by the object. + /// + /// This method should not remove its [overlayEntries] from the [Overlay]. The + /// object's owner is in charge of doing that. + /// + /// After this is called, the object is not in a usable state and should be + /// discarded. + /// + /// This method should only be called by the object's owner; typically the + /// [Navigator] owns a route and so will call this method when the route is + /// removed, after which the route is no longer referenced by the navigator. + @mustCallSuper + @protected + void dispose() { + _navigator = null; + _restorationScopeId.dispose(); + _disposeCompleter.complete(); + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + } + + /// Whether this route is the top-most route on the navigator. + /// + /// If this is true, then [isActive] is also true. + bool get isCurrent { + if (_navigator == null) { + return false; + } + final _RouteEntry? currentRouteEntry = _navigator!._lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate); + if (currentRouteEntry == null) { + return false; + } + return currentRouteEntry.route == this; + } + + /// Whether this route is the bottom-most active route on the navigator. + /// + /// If [isFirst] and [isCurrent] are both true then this is the only route on + /// the navigator (and [isActive] will also be true). + bool get isFirst { + if (_navigator == null) { + return false; + } + final _RouteEntry? currentRouteEntry = _navigator!._firstRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate); + if (currentRouteEntry == null) { + return false; + } + return currentRouteEntry.route == this; + } + + /// Whether there is at least one active route underneath this route. + @protected + bool get hasActiveRouteBelow { + if (_navigator == null) { + return false; + } + for (final _RouteEntry entry in _navigator!._history) { + if (entry.route == this) { + return false; + } + if (_RouteEntry.isPresentPredicate(entry)) { + return true; + } + } + return false; + } + + /// Whether this route is on the navigator. + /// + /// If the route is not only active, but also the current route (the top-most + /// route), then [isCurrent] will also be true. If it is the first route (the + /// bottom-most route), then [isFirst] will also be true. + /// + /// If a higher route is entirely opaque, then the route will be active but not + /// rendered. It is even possible for the route to be active but for the stateful + /// widgets within the route to not be instantiated. See [ModalRoute.maintainState]. + bool get isActive { + if (_navigator == null) { + return false; + } + return _navigator!._firstRouteEntryWhereOrNull(_RouteEntry.isRoutePredicate(this))?.isPresent ?? false; + } +} + +/// Data that might be useful in constructing a [Route]. +@immutable +class RouteSettings { + /// Creates data used to construct routes. + const RouteSettings({ + this.name, + this.arguments, + }); + + /// The name of the route (e.g., "/settings"). + /// + /// If null, the route is anonymous. + final String? name; + + /// The arguments passed to this route. + /// + /// May be used when building the route, e.g. in [Navigator.onGenerateRoute]. + final Object? arguments; + + @override + String toString() => '${objectRuntimeType(this, 'RouteSettings')}(${name == null ? 'none' : '"$name"'}, $arguments)'; +} + +/// Describes the configuration of a [Route]. +/// +/// The type argument `T` is the corresponding [Route]'s return type, as +/// used by [Route.currentResult], [Route.popped], and [Route.didPop]. +/// +/// See also: +/// +/// * [Navigator.pages], which accepts a list of [Page]s and updates its routes +/// history. +abstract class Page<T> extends RouteSettings { + /// Creates a page and initializes [key] for subclasses. + const Page({ + this.key, + super.name, + super.arguments, + this.restorationId, + }); + + /// The key associated with this page. + /// + /// This key will be used for comparing pages in [canUpdate]. + final LocalKey? key; + + /// Restoration ID to save and restore the state of the [Route] configured by + /// this page. + /// + /// If no restoration ID is provided, the [Route] will not restore its state. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + final String? restorationId; + + /// Whether this page can be updated with the [other] page. + /// + /// Two pages are consider updatable if they have same the [runtimeType] and + /// [key]. + bool canUpdate(Page<dynamic> other) { + return other.runtimeType == runtimeType && + other.key == key; + } + + /// Creates the [Route] that corresponds to this page. + /// + /// The created [Route] must have its [Route.settings] property set to this [Page]. + @factory + Route<T> createRoute(BuildContext context); + + @override + String toString() => '${objectRuntimeType(this, 'Page')}("$name", $key, $arguments)'; +} + +/// An interface for observing the behavior of a [Navigator]. +class NavigatorObserver { + /// The navigator that the observer is observing, if any. + NavigatorState? get navigator => _navigators[this]; + + // Expando mapping instances of NavigatorObserver to their associated + // NavigatorState (or `null`, if there is no associated NavigatorState). The + // reason we don't use a private instance field of type + // `NavigatorState?` is because as part of implementing + // https://github.com/dart-lang/language/issues/2020, it will soon become a + // runtime error to invoke a private member that is mocked in another + // library. By using an expando rather than an instance field, we ensure + // that a mocked NavigatorObserver can still properly keep track of its + // associated NavigatorState. + static final Expando<NavigatorState> _navigators = Expando<NavigatorState>(); + + /// The [Navigator] pushed `route`. + /// + /// The route immediately below that one, and thus the previously active + /// route, is `previousRoute`. + void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) { } + + /// The [Navigator] popped `route`. + /// + /// The route immediately below that one, and thus the newly active + /// route, is `previousRoute`. + void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) { } + + /// The [Navigator] removed `route`. + /// + /// If only one route is being removed, then the route immediately below + /// that one, if any, is `previousRoute`. + /// + /// If multiple routes are being removed, then the route below the + /// bottommost route being removed, if any, is `previousRoute`, and this + /// method will be called once for each removed route, from the topmost route + /// to the bottommost route. + void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) { } + + /// The [Navigator] replaced `oldRoute` with `newRoute`. + void didReplace({ Route<dynamic>? newRoute, Route<dynamic>? oldRoute }) { } + + /// The [Navigator]'s routes are being moved by a user gesture. + /// + /// For example, this is called when an iOS back gesture starts, and is used + /// to disabled hero animations during such interactions. + void didStartUserGesture(Route<dynamic> route, Route<dynamic>? previousRoute) { } + + /// User gesture is no longer controlling the [Navigator]. + /// + /// Paired with an earlier call to [didStartUserGesture]. + void didStopUserGesture() { } +} + +/// An inherited widget to host a hero controller. +/// +/// The hosted hero controller will be picked up by the navigator in the +/// [child] subtree. Once a navigator picks up this controller, the navigator +/// will bar any navigator below its subtree from receiving this controller. +/// +/// The hero controller inside the [HeroControllerScope] can only subscribe to +/// one navigator at a time. An assertion will be thrown if the hero controller +/// subscribes to more than one navigators. This can happen when there are +/// multiple navigators under the same [HeroControllerScope] in parallel. +class HeroControllerScope extends InheritedWidget { + /// Creates a widget to host the input [controller]. + const HeroControllerScope({ + super.key, + required HeroController this.controller, + required super.child, + }); + + /// Creates a widget to prevent the subtree from receiving the hero controller + /// above. + const HeroControllerScope.none({ + super.key, + required super.child, + }) : controller = null; + + /// The hero controller that is hosted inside this widget. + final HeroController? controller; + + /// Retrieves the [HeroController] from the closest [HeroControllerScope] + /// ancestor, or null if none exists. + /// + /// Calling this method will create a dependency on the closest + /// [HeroControllerScope] in the [context], if there is one. + /// + /// See also: + /// + /// * [HeroControllerScope.of], which is similar to this method, but asserts + /// if no [HeroControllerScope] ancestor is found. + static HeroController? maybeOf(BuildContext context) { + final HeroControllerScope? host = context.dependOnInheritedWidgetOfExactType<HeroControllerScope>(); + return host?.controller; + } + + /// Retrieves the [HeroController] from the closest [HeroControllerScope] + /// ancestor. + /// + /// If no ancestor is found, this method will assert in debug mode, and throw + /// an exception in release mode. + /// + /// Calling this method will create a dependency on the closest + /// [HeroControllerScope] in the [context]. + /// + /// See also: + /// + /// * [HeroControllerScope.maybeOf], which is similar to this method, but + /// returns null if no [HeroControllerScope] ancestor is found. + static HeroController of(BuildContext context) { + final HeroController? controller = maybeOf(context); + assert(() { + if (controller == null) { + throw FlutterError( + 'HeroControllerScope.of() was called with a context that does not contain a ' + 'HeroControllerScope widget.\n' + 'No HeroControllerScope widget ancestor could be found starting from the ' + 'context that was passed to HeroControllerScope.of(). This can happen ' + 'because you are using a widget that looks for a HeroControllerScope ' + 'ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return controller!; + } + + @override + bool updateShouldNotify(HeroControllerScope oldWidget) { + return oldWidget.controller != controller; + } +} + +/// A [Route] wrapper interface that can be staged for [TransitionDelegate] to +/// decide how its underlying [Route] should transition on or off screen. +abstract class RouteTransitionRecord { + /// Retrieves the wrapped [Route]. + Route<dynamic> get route; + + /// Whether this route is waiting for the decision on how to enter the screen. + /// + /// If this property is true, this route requires an explicit decision on how + /// to transition into the screen. Such a decision should be made in the + /// [TransitionDelegate.resolve]. + bool get isWaitingForEnteringDecision; + + /// Whether this route is waiting for the decision on how to exit the screen. + /// + /// If this property is true, this route requires an explicit decision on how + /// to transition off the screen. Such a decision should be made in the + /// [TransitionDelegate.resolve]. + bool get isWaitingForExitingDecision; + + /// Marks the [route] to be pushed with transition. + /// + /// During [TransitionDelegate.resolve], this can be called on an entering + /// route (where [RouteTransitionRecord.isWaitingForEnteringDecision] is true) in indicate that the + /// route should be pushed onto the [Navigator] with an animated transition. + void markForPush(); + + /// Marks the [route] to be added without transition. + /// + /// During [TransitionDelegate.resolve], this can be called on an entering + /// route (where [RouteTransitionRecord.isWaitingForEnteringDecision] is true) in indicate that the + /// route should be added onto the [Navigator] without an animated transition. + void markForAdd(); + + /// Marks the [route] to be popped with transition. + /// + /// During [TransitionDelegate.resolve], this can be called on an exiting + /// route to indicate that the route should be popped off the [Navigator] with + /// an animated transition. + void markForPop([dynamic result]); + + /// Marks the [route] to be completed without transition. + /// + /// During [TransitionDelegate.resolve], this can be called on an exiting + /// route to indicate that the route should be completed with the provided + /// result and removed from the [Navigator] without an animated transition. + void markForComplete([dynamic result]); + + /// Marks the [route] to be removed without transition. + /// + /// During [TransitionDelegate.resolve], this can be called on an exiting + /// route to indicate that the route should be removed from the [Navigator] + /// without completing and without an animated transition. + void markForRemove(); +} + +/// The delegate that decides how pages added and removed from [Navigator.pages] +/// transition in or out of the screen. +/// +/// This abstract class implements the API to be called by [Navigator] when it +/// requires explicit decisions on how the routes transition on or off the screen. +/// +/// To make route transition decisions, subclass must implement [resolve]. +/// +/// {@tool snippet} +/// The following example demonstrates how to implement a subclass that always +/// removes or adds routes without animated transitions and puts the removed +/// routes at the top of the list. +/// +/// ```dart +/// class NoAnimationTransitionDelegate extends TransitionDelegate<void> { +/// @override +/// Iterable<RouteTransitionRecord> resolve({ +/// required List<RouteTransitionRecord> newPageRouteHistory, +/// required Map<RouteTransitionRecord?, RouteTransitionRecord> locationToExitingPageRoute, +/// required Map<RouteTransitionRecord?, List<RouteTransitionRecord>> pageRouteToPagelessRoutes, +/// }) { +/// final List<RouteTransitionRecord> results = <RouteTransitionRecord>[]; +/// +/// for (final RouteTransitionRecord pageRoute in newPageRouteHistory) { +/// if (pageRoute.isWaitingForEnteringDecision) { +/// pageRoute.markForAdd(); +/// } +/// results.add(pageRoute); +/// +/// } +/// for (final RouteTransitionRecord exitingPageRoute in locationToExitingPageRoute.values) { +/// if (exitingPageRoute.isWaitingForExitingDecision) { +/// exitingPageRoute.markForRemove(); +/// final List<RouteTransitionRecord>? pagelessRoutes = pageRouteToPagelessRoutes[exitingPageRoute]; +/// if (pagelessRoutes != null) { +/// for (final RouteTransitionRecord pagelessRoute in pagelessRoutes) { +/// pagelessRoute.markForRemove(); +/// } +/// } +/// } +/// results.add(exitingPageRoute); +/// +/// } +/// return results; +/// } +/// } +/// +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Navigator.transitionDelegate], which uses this class to make route +/// transition decisions. +/// * [DefaultTransitionDelegate], which implements the default way to decide +/// how routes transition in or out of the screen. +abstract class TransitionDelegate<T> { + /// Creates a delegate and enables subclass to create a constant class. + const TransitionDelegate(); + + Iterable<RouteTransitionRecord> _transition({ + required List<RouteTransitionRecord> newPageRouteHistory, + required Map<RouteTransitionRecord?, RouteTransitionRecord> locationToExitingPageRoute, + required Map<RouteTransitionRecord?, List<RouteTransitionRecord>> pageRouteToPagelessRoutes, + }) { + final Iterable<RouteTransitionRecord> results = resolve( + newPageRouteHistory: newPageRouteHistory, + locationToExitingPageRoute: locationToExitingPageRoute, + pageRouteToPagelessRoutes: pageRouteToPagelessRoutes, + ); + // Verifies the integrity after the decisions have been made. + // + // Here are the rules: + // - All the entering routes in newPageRouteHistory must either be pushed or + // added. + // - All the exiting routes in locationToExitingPageRoute must either be + // popped, completed or removed. + // - All the pageless routes that belong to exiting routes must either be + // popped, completed or removed. + // - All the entering routes in the result must preserve the same order as + // the entering routes in newPageRouteHistory, and the result must contain + // all exiting routes. + // ex: + // + // newPageRouteHistory = [A, B, C] + // + // locationToExitingPageRoute = {A -> D, C -> E} + // + // results = [A, B ,C ,D ,E] is valid + // results = [D, A, B ,C ,E] is also valid because exiting route can be + // inserted in any place + // + // results = [B, A, C ,D ,E] is invalid because B must be after A. + // results = [A, B, C ,E] is invalid because results must include D. + assert(() { + final List<RouteTransitionRecord> resultsToVerify = results.toList(growable: false); + final Set<RouteTransitionRecord> exitingPageRoutes = locationToExitingPageRoute.values.toSet(); + // Firstly, verifies all exiting routes have been marked. + for (final RouteTransitionRecord exitingPageRoute in exitingPageRoutes) { + assert(!exitingPageRoute.isWaitingForExitingDecision); + if (pageRouteToPagelessRoutes.containsKey(exitingPageRoute)) { + for (final RouteTransitionRecord pagelessRoute in pageRouteToPagelessRoutes[exitingPageRoute]!) { + assert(!pagelessRoute.isWaitingForExitingDecision); + } + } + } + // Secondly, verifies the order of results matches the newPageRouteHistory + // and contains all the exiting routes. + int indexOfNextRouteInNewHistory = 0; + + for (final _RouteEntry routeEntry in resultsToVerify.cast<_RouteEntry>()) { + assert(!routeEntry.isWaitingForEnteringDecision && !routeEntry.isWaitingForExitingDecision); + if ( + indexOfNextRouteInNewHistory >= newPageRouteHistory.length || + routeEntry != newPageRouteHistory[indexOfNextRouteInNewHistory] + ) { + assert(exitingPageRoutes.contains(routeEntry)); + exitingPageRoutes.remove(routeEntry); + } else { + indexOfNextRouteInNewHistory += 1; + } + } + + assert( + indexOfNextRouteInNewHistory == newPageRouteHistory.length && + exitingPageRoutes.isEmpty, + 'The merged result from the $runtimeType.resolve does not include all ' + 'required routes. Do you remember to merge all exiting routes?', + ); + return true; + }()); + + return results; + } + + /// A method that will be called by the [Navigator] to decide how routes + /// transition in or out of the screen when [Navigator.pages] is updated. + /// + /// The `newPageRouteHistory` list contains all page-based routes in the order + /// that will be on the [Navigator]'s history stack after this update + /// completes. If a route in `newPageRouteHistory` has its + /// [RouteTransitionRecord.isWaitingForEnteringDecision] set to true, this + /// route requires explicit decision on how it should transition onto the + /// Navigator. To make a decision, call [RouteTransitionRecord.markForPush] or + /// [RouteTransitionRecord.markForAdd]. + /// + /// The `locationToExitingPageRoute` contains the pages-based routes that + /// are removed from the routes history after page update. This map records + /// page-based routes to be removed with the location of the route in the + /// original route history before the update. The keys are the locations + /// represented by the page-based routes that are directly below the removed + /// routes, and the value are the page-based routes to be removed. The + /// location is null if the route to be removed is the bottom most route. If + /// a route in `locationToExitingPageRoute` has its + /// [RouteTransitionRecord.isWaitingForExitingDecision] set to true, this + /// route requires explicit decision on how it should transition off the + /// Navigator. To make a decision for a removed route, call + /// [RouteTransitionRecord.markForPop], + /// [RouteTransitionRecord.markForComplete] or + /// [RouteTransitionRecord.markForRemove]. It is possible that decisions are + /// not required for routes in the `locationToExitingPageRoute`. This can + /// happen if the routes have already been popped in earlier page updates and + /// are still waiting for popping animations to finish. In such case, those + /// routes are still included in the `locationToExitingPageRoute` with their + /// [RouteTransitionRecord.isWaitingForExitingDecision] set to false and no + /// decisions are required. + /// + /// The `pageRouteToPagelessRoutes` records the page-based routes and their + /// associated pageless routes. If a page-based route is waiting for exiting + /// decision, its associated pageless routes also require explicit decisions + /// on how to transition off the screen. + /// + /// Once all the decisions have been made, this method must merge the removed + /// routes (whether or not they require decisions) and the + /// `newPageRouteHistory` and return the merged result. The order in the + /// result will be the order the [Navigator] uses for updating the route + /// history. The return list must preserve the same order of routes in + /// `newPageRouteHistory`. The removed routes, however, can be inserted into + /// the return list freely as long as all of them are included. + /// + /// For example, consider the following case. + /// + /// `newPageRouteHistory = [A, B, C]` + /// + /// `locationToExitingPageRoute = {A -> D, C -> E}` + /// + /// The following outputs are valid. + /// + /// `result = [A, B ,C ,D ,E]` is valid. + /// `result = [D, A, B ,C ,E]` is also valid because exiting route can be + /// inserted in any place. + /// + /// The following outputs are invalid. + /// + /// `result = [B, A, C ,D ,E]` is invalid because B must be after A. + /// `result = [A, B, C ,E]` is invalid because results must include D. + /// + /// See also: + /// + /// * [RouteTransitionRecord.markForPush], which makes route enter the screen + /// with an animated transition. + /// * [RouteTransitionRecord.markForAdd], which makes route enter the screen + /// without an animated transition. + /// * [RouteTransitionRecord.markForPop], which makes route exit the screen + /// with an animated transition. + /// * [RouteTransitionRecord.markForRemove], which does not complete the + /// route and makes it exit the screen without an animated transition. + /// * [RouteTransitionRecord.markForComplete], which completes the route and + /// makes it exit the screen without an animated transition. + /// * [DefaultTransitionDelegate.resolve], which implements the default way + /// to decide how routes transition in or out of the screen. + Iterable<RouteTransitionRecord> resolve({ + required List<RouteTransitionRecord> newPageRouteHistory, + required Map<RouteTransitionRecord?, RouteTransitionRecord> locationToExitingPageRoute, + required Map<RouteTransitionRecord?, List<RouteTransitionRecord>> pageRouteToPagelessRoutes, + }); +} + +/// The default implementation of [TransitionDelegate] that the [Navigator] will +/// use if its [Navigator.transitionDelegate] is not specified. +/// +/// This transition delegate follows two rules. Firstly, all the entering routes +/// are placed on top of the exiting routes if they are at the same location. +/// Secondly, the top most route will always transition with an animated transition. +/// All the other routes below will either be completed with +/// [Route.currentResult] or added without an animated transition. +class DefaultTransitionDelegate<T> extends TransitionDelegate<T> { + /// Creates a default transition delegate. + const DefaultTransitionDelegate() : super(); + + @override + Iterable<RouteTransitionRecord> resolve({ + required List<RouteTransitionRecord> newPageRouteHistory, + required Map<RouteTransitionRecord?, RouteTransitionRecord> locationToExitingPageRoute, + required Map<RouteTransitionRecord?, List<RouteTransitionRecord>> pageRouteToPagelessRoutes, + }) { + final List<RouteTransitionRecord> results = <RouteTransitionRecord>[]; + // This method will handle the exiting route and its corresponding pageless + // route at this location. It will also recursively check if there is any + // other exiting routes above it and handle them accordingly. + void handleExitingRoute(RouteTransitionRecord? location, bool isLast) { + final RouteTransitionRecord? exitingPageRoute = locationToExitingPageRoute[location]; + if (exitingPageRoute == null) { + return; + } + if (exitingPageRoute.isWaitingForExitingDecision) { + final bool hasPagelessRoute = pageRouteToPagelessRoutes.containsKey(exitingPageRoute); + final bool isLastExitingPageRoute = isLast && !locationToExitingPageRoute.containsKey(exitingPageRoute); + if (isLastExitingPageRoute && !hasPagelessRoute) { + exitingPageRoute.markForPop(exitingPageRoute.route.currentResult); + } else { + exitingPageRoute.markForComplete(exitingPageRoute.route.currentResult); + } + if (hasPagelessRoute) { + final List<RouteTransitionRecord> pagelessRoutes = pageRouteToPagelessRoutes[exitingPageRoute]!; + for (final RouteTransitionRecord pagelessRoute in pagelessRoutes) { + // It is possible that a pageless route that belongs to an exiting + // page-based route does not require exiting decision. This can + // happen if the page list is updated right after a Navigator.pop. + if (pagelessRoute.isWaitingForExitingDecision) { + if (isLastExitingPageRoute && pagelessRoute == pagelessRoutes.last) { + pagelessRoute.markForPop(pagelessRoute.route.currentResult); + } else { + pagelessRoute.markForComplete(pagelessRoute.route.currentResult); + } + } + } + } + } + results.add(exitingPageRoute); + + // It is possible there is another exiting route above this exitingPageRoute. + handleExitingRoute(exitingPageRoute, isLast); + } + + // Handles exiting route in the beginning of list. + handleExitingRoute(null, newPageRouteHistory.isEmpty); + + for (final RouteTransitionRecord pageRoute in newPageRouteHistory) { + final bool isLastIteration = newPageRouteHistory.last == pageRoute; + if (pageRoute.isWaitingForEnteringDecision) { + if (!locationToExitingPageRoute.containsKey(pageRoute) && isLastIteration) { + pageRoute.markForPush(); + } else { + pageRoute.markForAdd(); + } + } + results.add(pageRoute); + handleExitingRoute(pageRoute, isLastIteration); + } + return results; + } +} + +/// The default value of [Navigator.routeTraversalEdgeBehavior]. +/// +/// {@macro flutter.widgets.navigator.routeTraversalEdgeBehavior} +const TraversalEdgeBehavior kDefaultRouteTraversalEdgeBehavior = TraversalEdgeBehavior.parentScope; + +/// A widget that manages a set of child widgets with a stack discipline. +/// +/// Many apps have a navigator near the top of their widget hierarchy in order +/// to display their logical history using an [Overlay] with the most recently +/// visited pages visually on top of the older pages. Using this pattern lets +/// the navigator visually transition from one page to another by moving the widgets +/// around in the overlay. Similarly, the navigator can be used to show a dialog +/// by positioning the dialog widget above the current page. +/// +/// ## Using the Pages API +/// +/// The [Navigator] will convert its [Navigator.pages] into a stack of [Route]s +/// if it is provided. A change in [Navigator.pages] will trigger an update to +/// the stack of [Route]s. The [Navigator] will update its routes to match the +/// new configuration of its [Navigator.pages]. To use this API, one can create +/// a [Page] subclass and defines a list of [Page]s for [Navigator.pages]. A +/// [Navigator.onPopPage] callback is also required to properly clean up the +/// input pages in case of a pop. +/// +/// By Default, the [Navigator] will use [DefaultTransitionDelegate] to decide +/// how routes transition in or out of the screen. To customize it, define a +/// [TransitionDelegate] subclass and provide it to the +/// [Navigator.transitionDelegate]. +/// +/// For more information on using the pages API, see the [Router] widget. +/// +/// ## Using the Navigator API +/// +/// Mobile apps typically reveal their contents via full-screen elements +/// called "screens" or "pages". In Flutter these elements are called +/// routes and they're managed by a [Navigator] widget. The navigator +/// manages a stack of [Route] objects and provides two ways for managing +/// the stack, the declarative API [Navigator.pages] or imperative API +/// [Navigator.push] and [Navigator.pop]. +/// +/// When your user interface fits this paradigm of a stack, where the user +/// should be able to _navigate_ back to an earlier element in the stack, +/// the use of routes and the Navigator is appropriate. On certain platforms, +/// such as Android, the system UI will provide a back button (outside the +/// bounds of your application) that will allow the user to navigate back +/// to earlier routes in your application's stack. On platforms that don't +/// have this build-in navigation mechanism, the use of an [AppBar] (typically +/// used in the [Scaffold.appBar] property) can automatically add a back +/// button for user navigation. +/// +/// ### Displaying a full-screen route +/// +/// Although you can create a navigator directly, it's most common to use the +/// navigator created by the `Router` which itself is created and configured by +/// a [WidgetsApp] or a [MaterialApp] widget. You can refer to that navigator +/// with [Navigator.of]. +/// +/// A [MaterialApp] is the simplest way to set things up. The [MaterialApp]'s +/// home becomes the route at the bottom of the [Navigator]'s stack. It is what +/// you see when the app is launched. +/// +/// ```dart +/// void main() { +/// runApp(const MaterialApp(home: MyAppHome())); +/// } +/// ``` +/// +/// To push a new route on the stack you can create an instance of +/// [MaterialPageRoute] with a builder function that creates whatever you +/// want to appear on the screen. For example: +/// +/// ```dart +/// Navigator.push(context, MaterialPageRoute<void>( +/// builder: (BuildContext context) { +/// return Scaffold( +/// appBar: AppBar(title: const Text('My Page')), +/// body: Center( +/// child: TextButton( +/// child: const Text('POP'), +/// onPressed: () { +/// Navigator.pop(context); +/// }, +/// ), +/// ), +/// ); +/// }, +/// )); +/// ``` +/// +/// The route defines its widget with a builder function instead of a +/// child widget because it will be built and rebuilt in different +/// contexts depending on when it's pushed and popped. +/// +/// As you can see, the new route can be popped, revealing the app's home +/// page, with the Navigator's pop method: +/// +/// ```dart +/// Navigator.pop(context); +/// ``` +/// +/// It usually isn't necessary to provide a widget that pops the Navigator +/// in a route with a [Scaffold] because the Scaffold automatically adds a +/// 'back' button to its AppBar. Pressing the back button causes +/// [Navigator.pop] to be called. On Android, pressing the system back +/// button does the same thing. +/// +/// ### Using named navigator routes +/// +/// Mobile apps often manage a large number of routes and it's often +/// easiest to refer to them by name. Route names, by convention, +/// use a path-like structure (for example, '/a/b/c'). +/// The app's home page route is named '/' by default. +/// +/// The [MaterialApp] can be created +/// with a [Map<String, WidgetBuilder>] which maps from a route's name to +/// a builder function that will create it. The [MaterialApp] uses this +/// map to create a value for its navigator's [onGenerateRoute] callback. +/// +/// ```dart +/// void main() { +/// runApp(MaterialApp( +/// home: const MyAppHome(), // becomes the route named '/' +/// routes: <String, WidgetBuilder> { +/// '/a': (BuildContext context) => const MyPage(title: Text('page A')), +/// '/b': (BuildContext context) => const MyPage(title: Text('page B')), +/// '/c': (BuildContext context) => const MyPage(title: Text('page C')), +/// }, +/// )); +/// } +/// ``` +/// +/// To show a route by name: +/// +/// ```dart +/// Navigator.pushNamed(context, '/b'); +/// ``` +/// +/// ### Routes can return a value +/// +/// When a route is pushed to ask the user for a value, the value can be +/// returned via the [pop] method's result parameter. +/// +/// Methods that push a route return a [Future]. The Future resolves when the +/// route is popped and the [Future]'s value is the [pop] method's `result` +/// parameter. +/// +/// For example if we wanted to ask the user to press 'OK' to confirm an +/// operation we could `await` the result of [Navigator.push]: +/// +/// ```dart +/// bool? value = await Navigator.push(context, MaterialPageRoute<bool>( +/// builder: (BuildContext context) { +/// return Center( +/// child: GestureDetector( +/// child: const Text('OK'), +/// onTap: () { Navigator.pop(context, true); } +/// ), +/// ); +/// } +/// )); +/// ``` +/// +/// If the user presses 'OK' then value will be true. If the user backs +/// out of the route, for example by pressing the Scaffold's back button, +/// the value will be null. +/// +/// When a route is used to return a value, the route's type parameter must +/// match the type of [pop]'s result. That's why we've used +/// `MaterialPageRoute<bool>` instead of `MaterialPageRoute<void>` or just +/// `MaterialPageRoute`. (If you prefer to not specify the types, though, that's +/// fine too.) +/// +/// ### Popup routes +/// +/// Routes don't have to obscure the entire screen. [PopupRoute]s cover the +/// screen with a [ModalRoute.barrierColor] that can be only partially opaque to +/// allow the current screen to show through. Popup routes are "modal" because +/// they block input to the widgets below. +/// +/// There are functions which create and show popup routes. For +/// example: [showDialog], [showMenu], and [showModalBottomSheet]. These +/// functions return their pushed route's Future as described above. +/// Callers can await the returned value to take an action when the +/// route is popped, or to discover the route's value. +/// +/// There are also widgets which create popup routes, like [PopupMenuButton] and +/// [DropdownButton]. These widgets create internal subclasses of PopupRoute +/// and use the Navigator's push and pop methods to show and dismiss them. +/// +/// ### Custom routes +/// +/// You can create your own subclass of one of the widget library route classes +/// like [PopupRoute], [ModalRoute], or [PageRoute], to control the animated +/// transition employed to show the route, the color and behavior of the route's +/// modal barrier, and other aspects of the route. +/// +/// The [PageRouteBuilder] class makes it possible to define a custom route +/// in terms of callbacks. Here's an example that rotates and fades its child +/// when the route appears or disappears. This route does not obscure the entire +/// screen because it specifies `opaque: false`, just as a popup route does. +/// +/// ```dart +/// Navigator.push(context, PageRouteBuilder<void>( +/// opaque: false, +/// pageBuilder: (BuildContext context, _, __) { +/// return const Center(child: Text('My PageRoute')); +/// }, +/// transitionsBuilder: (___, Animation<double> animation, ____, Widget child) { +/// return FadeTransition( +/// opacity: animation, +/// child: RotationTransition( +/// turns: Tween<double>(begin: 0.5, end: 1.0).animate(animation), +/// child: child, +/// ), +/// ); +/// } +/// )); +/// ``` +/// +/// The page route is built in two parts, the "page" and the +/// "transitions". The page becomes a descendant of the child passed to +/// the `transitionsBuilder` function. Typically the page is only built once, +/// because it doesn't depend on its animation parameters (elided with `_` +/// and `__` in this example). The transition is built on every frame +/// for its duration. +/// +/// (In this example, `void` is used as the return type for the route, because +/// it does not return a value.) +/// +/// ### Nesting Navigators +/// +/// An app can use more than one [Navigator]. Nesting one [Navigator] below +/// another [Navigator] can be used to create an "inner journey" such as tabbed +/// navigation, user registration, store checkout, or other independent journeys +/// that represent a subsection of your overall application. +/// +/// #### Example +/// +/// It is standard practice for iOS apps to use tabbed navigation where each +/// tab maintains its own navigation history. Therefore, each tab has its own +/// [Navigator], creating a kind of "parallel navigation." +/// +/// In addition to the parallel navigation of the tabs, it is still possible to +/// launch full-screen pages that completely cover the tabs. For example: an +/// on-boarding flow, or an alert dialog. Therefore, there must exist a "root" +/// [Navigator] that sits above the tab navigation. As a result, each of the +/// tab's [Navigator]s are actually nested [Navigator]s sitting below a single +/// root [Navigator]. +/// +/// In practice, the nested [Navigator]s for tabbed navigation sit in the +/// [WidgetsApp] and [CupertinoTabView] widgets and do not need to be explicitly +/// created or managed. +/// +/// {@tool sample} +/// The following example demonstrates how a nested [Navigator] can be used to +/// present a standalone user registration journey. +/// +/// Even though this example uses two [Navigator]s to demonstrate nested +/// [Navigator]s, a similar result is possible using only a single [Navigator]. +/// +/// Run this example with `flutter run --route=/signup` to start it with +/// the signup flow instead of on the home page. +/// +/// ** See code in examples/api/lib/widgets/navigator/navigator.0.dart ** +/// {@end-tool} +/// +/// [Navigator.of] operates on the nearest ancestor [Navigator] from the given +/// [BuildContext]. Be sure to provide a [BuildContext] below the intended +/// [Navigator], especially in large `build` methods where nested [Navigator]s +/// are created. The [Builder] widget can be used to access a [BuildContext] at +/// a desired location in the widget subtree. +/// +/// ### Finding the enclosing route +/// +/// In the common case of a modal route, the enclosing route can be obtained +/// from inside a build method using [ModalRoute.of]. To determine if the +/// enclosing route is the active route (e.g. so that controls can be dimmed +/// when the route is not active), the [Route.isCurrent] property can be checked +/// on the returned route. +/// +/// ## State Restoration +/// +/// If provided with a [restorationScopeId] and when surrounded by a valid +/// [RestorationScope] the [Navigator] will restore its state by recreating +/// the current history stack of [Route]s during state restoration and by +/// restoring the internal state of those [Route]s. However, not all [Route]s +/// on the stack can be restored: +/// +/// * [Page]-based routes restore their state if [Page.restorationId] is +/// provided. +/// * [Route]s added with the classic imperative API ([push], [pushNamed], and +/// friends) can never restore their state. +/// * A [Route] added with the restorable imperative API ([restorablePush], +/// [restorablePushNamed], and all other imperative methods with "restorable" +/// in their name) restores its state if all routes below it up to and +/// including the first [Page]-based route below it are restored. If there +/// is no [Page]-based route below it, it only restores its state if all +/// routes below it restore theirs. +/// +/// If a [Route] is deemed restorable, the [Navigator] will set its +/// [Route.restorationScopeId] to a non-null value. Routes can use that ID to +/// store and restore their own state. As an example, the [ModalRoute] will +/// use this ID to create a [RestorationScope] for its content widgets. +class Navigator extends StatefulWidget { + /// Creates a widget that maintains a stack-based history of child widgets. + /// + /// If the [pages] is not empty, the [onPopPage] must not be null. + const Navigator({ + super.key, + this.pages = const <Page<dynamic>>[], + this.onPopPage, + this.initialRoute, + this.onGenerateInitialRoutes = Navigator.defaultGenerateInitialRoutes, + this.onGenerateRoute, + this.onUnknownRoute, + this.transitionDelegate = const DefaultTransitionDelegate<dynamic>(), + this.reportsRouteUpdateToEngine = false, + this.clipBehavior = Clip.hardEdge, + this.observers = const <NavigatorObserver>[], + this.requestFocus = true, + this.restorationScopeId, + this.routeTraversalEdgeBehavior = kDefaultRouteTraversalEdgeBehavior, + }); + + /// The list of pages with which to populate the history. + /// + /// Pages are turned into routes using [Page.createRoute] in a manner + /// analogous to how [Widget]s are turned into [Element]s (and [State]s or + /// [RenderObject]s) using [Widget.createElement] (and + /// [StatefulWidget.createState] or [RenderObjectWidget.createRenderObject]). + /// + /// When this list is updated, the new list is compared to the previous + /// list and the set of routes is updated accordingly. + /// + /// Some [Route]s do not correspond to [Page] objects, namely, those that are + /// added to the history using the [Navigator] API ([push] and friends). A + /// [Route] that does not correspond to a [Page] object is called a pageless + /// route and is tied to the [Route] that _does_ correspond to a [Page] object + /// that is below it in the history. + /// + /// Pages that are added or removed may be animated as controlled by the + /// [transitionDelegate]. If a page is removed that had other pageless routes + /// pushed on top of it using [push] and friends, those pageless routes are + /// also removed with or without animation as determined by the + /// [transitionDelegate]. + /// + /// To use this API, an [onPopPage] callback must also be provided to properly + /// clean up this list if a page has been popped. + /// + /// If [initialRoute] is non-null when the widget is first created, then + /// [onGenerateInitialRoutes] is used to generate routes that are above those + /// corresponding to [pages] in the initial history. + final List<Page<dynamic>> pages; + + /// Called when [pop] is invoked but the current [Route] corresponds to a + /// [Page] found in the [pages] list. + /// + /// The `result` argument is the value with which the route is to complete + /// (e.g. the value returned from a dialog). + /// + /// This callback is responsible for calling [Route.didPop] and returning + /// whether this pop is successful. + /// + /// The [Navigator] widget should be rebuilt with a [pages] list that does not + /// contain the [Page] for the given [Route]. The next time the [pages] list + /// is updated, if the [Page] corresponding to this [Route] is still present, + /// it will be interpreted as a new route to display. + final PopPageCallback? onPopPage; + + /// The delegate used for deciding how routes transition in or off the screen + /// during the [pages] updates. + /// + /// Defaults to [DefaultTransitionDelegate]. + final TransitionDelegate<dynamic> transitionDelegate; + + /// The name of the first route to show. + /// + /// Defaults to [Navigator.defaultRouteName]. + /// + /// The value is interpreted according to [onGenerateInitialRoutes], which + /// defaults to [defaultGenerateInitialRoutes]. + /// + /// Changing the [initialRoute] will have no effect, as it only controls the + /// _initial_ route. To change the route while the application is running, use + /// the static functions on this class, such as [push] or [replace]. + final String? initialRoute; + + /// Called to generate a route for a given [RouteSettings]. + final RouteFactory? onGenerateRoute; + + /// Called when [onGenerateRoute] fails to generate a route. + /// + /// This callback is typically used for error handling. For example, this + /// callback might always generate a "not found" page that describes the route + /// that wasn't found. + /// + /// Unknown routes can arise either from errors in the app or from external + /// requests to push routes, such as from Android intents. + final RouteFactory? onUnknownRoute; + + /// A list of observers for this navigator. + final List<NavigatorObserver> observers; + + /// Restoration ID to save and restore the state of the navigator, including + /// its history. + /// + /// {@template flutter.widgets.navigator.restorationScopeId} + /// If a restoration ID is provided, the navigator will persist its internal + /// state (including the route history as well as the restorable state of the + /// routes) and restore it during state restoration. + /// + /// If no restoration ID is provided, the route history stack will not be + /// restored and state restoration is disabled for the individual routes as + /// well. + /// + /// The state is persisted in a [RestorationBucket] claimed from + /// the surrounding [RestorationScope] using the provided restoration ID. + /// Within that bucket, the [Navigator] also creates a new [RestorationScope] + /// for its children (the [Route]s). + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + /// * [RestorationMixin], which contains a runnable code sample showcasing + /// state restoration in Flutter. + /// * [Navigator], which explains under the heading "state restoration" + /// how and under what conditions the navigator restores its state. + /// * [Navigator.restorablePush], which includes an example showcasing how + /// to push a restorable route unto the navigator. + /// {@endtemplate} + final String? restorationScopeId; + + /// Controls the transfer of focus beyond the first and the last items of a + /// focus scope that defines focus traversal of widgets within a route. + /// + /// {@template flutter.widgets.navigator.routeTraversalEdgeBehavior} + /// The focus inside routes installed in the top of the app affects how + /// the app behaves with respect to the platform content surrounding it. + /// For example, on the web, an app is at a minimum surrounded by browser UI, + /// such as the address bar, browser tabs, and more. The user should be able + /// to reach browser UI using normal focus shortcuts. Similarly, if the app + /// is embedded within an `<iframe>` or inside a custom element, it should + /// be able to participate in the overall focus traversal, including elements + /// not rendered by Flutter. + /// {@endtemplate} + final TraversalEdgeBehavior routeTraversalEdgeBehavior; + + /// The name for the default route of the application. + /// + /// See also: + /// + /// * [dart:ui.PlatformDispatcher.defaultRouteName], which reflects the route that the + /// application was started with. + static const String defaultRouteName = '/'; + + /// Called when the widget is created to generate the initial list of [Route] + /// objects if [initialRoute] is not null. + /// + /// Defaults to [defaultGenerateInitialRoutes]. + /// + /// The [NavigatorState] and [initialRoute] will be passed to the callback. + /// The callback must return a list of [Route] objects with which the history + /// will be primed. + /// + /// When parsing the initialRoute, if there's any chance that the it may + /// contain complex characters, it's best to use the + /// [characters](https://pub.dev/packages/characters) API. This will ensure + /// that extended grapheme clusters and surrogate pairs are treated as single + /// characters by the code, the same way that they appear to the user. For + /// example, the string "👨‍👩‍👦" appears to the user as a single + /// character and `string.characters.length` intuitively returns 1. On the + /// other hand, `string.length` returns 8, and `string.runes.length` returns + /// 5! + final RouteListFactory onGenerateInitialRoutes; + + /// Whether this navigator should report route update message back to the + /// engine when the top-most route changes. + /// + /// If the property is set to true, this navigator automatically sends the + /// route update message to the engine when it detects top-most route changes. + /// The messages are used by the web engine to update the browser URL bar. + /// + /// If the property is set to true when the [Navigator] is first created, + /// single-entry history mode is requested using + /// [SystemNavigator.selectSingleEntryHistory]. This means this property + /// should not be used at the same time as [PlatformRouteInformationProvider] + /// is used with a [Router] (including when used with [MaterialApp.router], + /// for example). + /// + /// If there are multiple navigators in the widget tree, at most one of them + /// can set this property to true (typically, the top-most one created from + /// the [WidgetsApp]). Otherwise, the web engine may receive multiple route + /// update messages from different navigators and fail to update the URL + /// bar. + /// + /// Defaults to false. + final bool reportsRouteUpdateToEngine; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// In cases where clipping is not desired, consider setting this property to + /// [Clip.none]. + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// Whether or not the navigator and it's new topmost route should request focus + /// when the new route is pushed onto the navigator. + /// + /// Defaults to true. + final bool requestFocus; + + /// Push a named route onto the navigator that most tightly encloses the given + /// context. + /// + /// {@template flutter.widgets.navigator.pushNamed} + /// The route name will be passed to the [Navigator.onGenerateRoute] + /// callback. The returned route will be pushed into the navigator. + /// + /// The new route and the previous route (if any) are notified (see + /// [Route.didPush] and [Route.didChangeNext]). If the [Navigator] has any + /// [Navigator.observers], they will be notified as well (see + /// [NavigatorObserver.didPush]). + /// + /// Ongoing gestures within the current route are canceled when a new route is + /// pushed. + /// + /// The `T` type argument is the type of the return value of the route. + /// + /// To use [pushNamed], an [Navigator.onGenerateRoute] callback must be + /// provided, + /// {@endtemplate} + /// + /// {@template flutter.widgets.navigator.pushNamed.returnValue} + /// Returns a [Future] that completes to the `result` value passed to [pop] + /// when the pushed route is popped off the navigator. + /// {@endtemplate} + /// + /// {@template flutter.widgets.Navigator.pushNamed} + /// The provided `arguments` are passed to the pushed route via + /// [RouteSettings.arguments]. Any object can be passed as `arguments` (e.g. a + /// [String], [int], or an instance of a custom `MyRouteArguments` class). + /// Often, a [Map] is used to pass key-value pairs. + /// + /// The `arguments` may be used in [Navigator.onGenerateRoute] or + /// [Navigator.onUnknownRoute] to construct the route. + /// {@endtemplate} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _didPushButton() { + /// Navigator.pushNamed(context, '/settings'); + /// } + /// ``` + /// {@end-tool} + /// + /// {@tool snippet} + /// + /// The following example shows how to pass additional `arguments` to the + /// route: + /// + /// ```dart + /// void _showBerlinWeather() { + /// Navigator.pushNamed( + /// context, + /// '/weather', + /// arguments: <String, String>{ + /// 'city': 'Berlin', + /// 'country': 'Germany', + /// }, + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// {@tool snippet} + /// + /// The following example shows how to pass a custom Object to the route: + /// + /// ```dart + /// class WeatherRouteArguments { + /// WeatherRouteArguments({ required this.city, required this.country }); + /// final String city; + /// final String country; + /// + /// bool get isGermanCapital { + /// return country == 'Germany' && city == 'Berlin'; + /// } + /// } + /// + /// void _showWeather() { + /// Navigator.pushNamed( + /// context, + /// '/weather', + /// arguments: WeatherRouteArguments(city: 'Berlin', country: 'Germany'), + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePushNamed], which pushes a route that can be restored + /// during state restoration. + @optionalTypeArgs + static Future<T?> pushNamed<T extends Object?>( + BuildContext context, + String routeName, { + Object? arguments, + }) { + return Navigator.of(context).pushNamed<T>(routeName, arguments: arguments); + } + + /// Push a named route onto the navigator that most tightly encloses the given + /// context. + /// + /// {@template flutter.widgets.navigator.restorablePushNamed} + /// Unlike [Route]s pushed via [pushNamed], [Route]s pushed with this method + /// are restored during state restoration according to the rules outlined + /// in the "State Restoration" section of [Navigator]. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushNamed} + /// + /// {@template flutter.widgets.Navigator.restorablePushNamed.arguments} + /// The provided `arguments` are passed to the pushed route via + /// [RouteSettings.arguments]. Any object that is serializable via the + /// [StandardMessageCodec] can be passed as `arguments`. Often, a Map is used + /// to pass key-value pairs. + /// + /// The arguments may be used in [Navigator.onGenerateRoute] or + /// [Navigator.onUnknownRoute] to construct the route. + /// {@endtemplate} + /// + /// {@template flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// The method returns an opaque ID for the pushed route that can be used by + /// the [RestorableRouteFuture] to gain access to the actual [Route] object + /// added to the navigator and its return value. You can ignore the return + /// value of this method, if you do not care about the route object or the + /// route's return value. + /// {@endtemplate} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _showParisWeather() { + /// Navigator.restorablePushNamed( + /// context, + /// '/weather', + /// arguments: <String, String>{ + /// 'city': 'Paris', + /// 'country': 'France', + /// }, + /// ); + /// } + /// ``` + /// {@end-tool} + @optionalTypeArgs + static String restorablePushNamed<T extends Object?>( + BuildContext context, + String routeName, { + Object? arguments, + }) { + return Navigator.of(context).restorablePushNamed<T>(routeName, arguments: arguments); + } + + /// Replace the current route of the navigator that most tightly encloses the + /// given context by pushing the route named [routeName] and then disposing + /// the previous route once the new route has finished animating in. + /// + /// {@template flutter.widgets.navigator.pushReplacementNamed} + /// If non-null, `result` will be used as the result of the route that is + /// removed; the future that had been returned from pushing that old route + /// will complete with `result`. Routes such as dialogs or popup menus + /// typically use this mechanism to return the value selected by the user to + /// the widget that created their route. The type of `result`, if provided, + /// must match the type argument of the class of the old route (`TO`). + /// + /// The route name will be passed to the [Navigator.onGenerateRoute] + /// callback. The returned route will be pushed into the navigator. + /// + /// The new route and the route below the removed route are notified (see + /// [Route.didPush] and [Route.didChangeNext]). If the [Navigator] has any + /// [Navigator.observers], they will be notified as well (see + /// [NavigatorObserver.didReplace]). The removed route is notified once the + /// new route has finished animating (see [Route.didComplete]). The removed + /// route's exit animation is not run (see [popAndPushNamed] for a variant + /// that does animated the removed route). + /// + /// Ongoing gestures within the current route are canceled when a new route is + /// pushed. + /// + /// The `T` type argument is the type of the return value of the new route, + /// and `TO` is the type of the return value of the old route. + /// + /// To use [pushReplacementNamed], a [Navigator.onGenerateRoute] callback must + /// be provided. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@macro flutter.widgets.Navigator.pushNamed} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _switchToBrightness() { + /// Navigator.pushReplacementNamed(context, '/settings/brightness'); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePushReplacementNamed], which pushes a replacement route that + /// can be restored during state restoration. + @optionalTypeArgs + static Future<T?> pushReplacementNamed<T extends Object?, TO extends Object?>( + BuildContext context, + String routeName, { + TO? result, + Object? arguments, + }) { + return Navigator.of(context).pushReplacementNamed<T, TO>(routeName, arguments: arguments, result: result); + } + + /// Replace the current route of the navigator that most tightly encloses the + /// given context by pushing the route named [routeName] and then disposing + /// the previous route once the new route has finished animating in. + /// + /// {@template flutter.widgets.navigator.restorablePushReplacementNamed} + /// Unlike [Route]s pushed via [pushReplacementNamed], [Route]s pushed with + /// this method are restored during state restoration according to the rules + /// outlined in the "State Restoration" section of [Navigator]. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushReplacementNamed} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.arguments} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _switchToAudioVolume() { + /// Navigator.restorablePushReplacementNamed(context, '/settings/volume'); + /// } + /// ``` + /// {@end-tool} + @optionalTypeArgs + static String restorablePushReplacementNamed<T extends Object?, TO extends Object?>( + BuildContext context, + String routeName, { + TO? result, + Object? arguments, + }) { + return Navigator.of(context).restorablePushReplacementNamed<T, TO>(routeName, arguments: arguments, result: result); + } + + /// Pop the current route off the navigator that most tightly encloses the + /// given context and push a named route in its place. + /// + /// {@template flutter.widgets.navigator.popAndPushNamed} + /// The popping of the previous route is handled as per [pop]. + /// + /// The new route's name will be passed to the [Navigator.onGenerateRoute] + /// callback. The returned route will be pushed into the navigator. + /// + /// The new route, the old route, and the route below the old route (if any) + /// are all notified (see [Route.didPop], [Route.didComplete], + /// [Route.didPopNext], [Route.didPush], and [Route.didChangeNext]). If the + /// [Navigator] has any [Navigator.observers], they will be notified as well + /// (see [NavigatorObserver.didPop] and [NavigatorObserver.didPush]). The + /// animations for the pop and the push are performed simultaneously, so the + /// route below may be briefly visible even if both the old route and the new + /// route are opaque (see [TransitionRoute.opaque]). + /// + /// Ongoing gestures within the current route are canceled when a new route is + /// pushed. + /// + /// The `T` type argument is the type of the return value of the new route, + /// and `TO` is the return value type of the old route. + /// + /// To use [popAndPushNamed], a [Navigator.onGenerateRoute] callback must be provided. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@macro flutter.widgets.Navigator.pushNamed} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _selectAccessibility() { + /// Navigator.popAndPushNamed(context, '/settings/accessibility'); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePopAndPushNamed], which pushes a new route that can be + /// restored during state restoration. + @optionalTypeArgs + static Future<T?> popAndPushNamed<T extends Object?, TO extends Object?>( + BuildContext context, + String routeName, { + TO? result, + Object? arguments, + }) { + return Navigator.of(context).popAndPushNamed<T, TO>(routeName, arguments: arguments, result: result); + } + + /// Pop the current route off the navigator that most tightly encloses the + /// given context and push a named route in its place. + /// + /// {@template flutter.widgets.navigator.restorablePopAndPushNamed} + /// Unlike [Route]s pushed via [popAndPushNamed], [Route]s pushed with + /// this method are restored during state restoration according to the rules + /// outlined in the "State Restoration" section of [Navigator]. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.popAndPushNamed} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.arguments} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _selectNetwork() { + /// Navigator.restorablePopAndPushNamed(context, '/settings/network'); + /// } + /// ``` + /// {@end-tool} + @optionalTypeArgs + static String restorablePopAndPushNamed<T extends Object?, TO extends Object?>( + BuildContext context, + String routeName, { + TO? result, + Object? arguments, + }) { + return Navigator.of(context).restorablePopAndPushNamed<T, TO>(routeName, arguments: arguments, result: result); + } + + /// Push the route with the given name onto the navigator that most tightly + /// encloses the given context, and then remove all the previous routes until + /// the `predicate` returns true. + /// + /// {@template flutter.widgets.navigator.pushNamedAndRemoveUntil} + /// The predicate may be applied to the same route more than once if + /// [Route.willHandlePopInternally] is true. + /// + /// To remove routes until a route with a certain name, use the + /// [RoutePredicate] returned from [ModalRoute.withName]. + /// + /// To remove all the routes below the pushed route, use a [RoutePredicate] + /// that always returns false (e.g. `(Route<dynamic> route) => false`). + /// + /// The removed routes are removed without being completed, so this method + /// does not take a return value argument. + /// + /// The new route's name (`routeName`) will be passed to the + /// [Navigator.onGenerateRoute] callback. The returned route will be pushed + /// into the navigator. + /// + /// The new route and the route below the bottommost removed route (which + /// becomes the route below the new route) are notified (see [Route.didPush] + /// and [Route.didChangeNext]). If the [Navigator] has any + /// [Navigator.observers], they will be notified as well (see + /// [NavigatorObserver.didPush] and [NavigatorObserver.didRemove]). The + /// removed routes are disposed, without being notified, once the new route + /// has finished animating. The futures that had been returned from pushing + /// those routes will not complete. + /// + /// Ongoing gestures within the current route are canceled when a new route is + /// pushed. + /// + /// The `T` type argument is the type of the return value of the new route. + /// + /// To use [pushNamedAndRemoveUntil], an [Navigator.onGenerateRoute] callback + /// must be provided. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@macro flutter.widgets.Navigator.pushNamed} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _resetToCalendar() { + /// Navigator.pushNamedAndRemoveUntil(context, '/calendar', ModalRoute.withName('/')); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePushNamedAndRemoveUntil], which pushes a new route that can + /// be restored during state restoration. + @optionalTypeArgs + static Future<T?> pushNamedAndRemoveUntil<T extends Object?>( + BuildContext context, + String newRouteName, + RoutePredicate predicate, { + Object? arguments, + }) { + return Navigator.of(context).pushNamedAndRemoveUntil<T>(newRouteName, predicate, arguments: arguments); + } + + /// Push the route with the given name onto the navigator that most tightly + /// encloses the given context, and then remove all the previous routes until + /// the `predicate` returns true. + /// + /// {@template flutter.widgets.navigator.restorablePushNamedAndRemoveUntil} + /// Unlike [Route]s pushed via [pushNamedAndRemoveUntil], [Route]s pushed with + /// this method are restored during state restoration according to the rules + /// outlined in the "State Restoration" section of [Navigator]. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushNamedAndRemoveUntil} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.arguments} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _resetToOverview() { + /// Navigator.restorablePushNamedAndRemoveUntil(context, '/overview', ModalRoute.withName('/')); + /// } + /// ``` + /// {@end-tool} + @optionalTypeArgs + static String restorablePushNamedAndRemoveUntil<T extends Object?>( + BuildContext context, + String newRouteName, + RoutePredicate predicate, { + Object? arguments, + }) { + return Navigator.of(context).restorablePushNamedAndRemoveUntil<T>(newRouteName, predicate, arguments: arguments); + } + + /// Push the given route onto the navigator that most tightly encloses the + /// given context. + /// + /// {@template flutter.widgets.navigator.push} + /// The new route and the previous route (if any) are notified (see + /// [Route.didPush] and [Route.didChangeNext]). If the [Navigator] has any + /// [Navigator.observers], they will be notified as well (see + /// [NavigatorObserver.didPush]). + /// + /// Ongoing gestures within the current route are canceled when a new route is + /// pushed. + /// + /// The `T` type argument is the type of the return value of the route. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _openMyPage() { + /// Navigator.push<void>( + /// context, + /// MaterialPageRoute<void>( + /// builder: (BuildContext context) => const MyPage(), + /// ), + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePush], which pushes a route that can be restored during + /// state restoration. + @optionalTypeArgs + static Future<T?> push<T extends Object?>(BuildContext context, Route<T> route) { + return Navigator.of(context).push(route); + } + + /// Push a new route onto the navigator that most tightly encloses the + /// given context. + /// + /// {@template flutter.widgets.navigator.restorablePush} + /// Unlike [Route]s pushed via [push], [Route]s pushed with this method are + /// restored during state restoration according to the rules outlined in the + /// "State Restoration" section of [Navigator]. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.push} + /// + /// {@template flutter.widgets.Navigator.restorablePush} + /// The method takes a [RestorableRouteBuilder] as argument, which must be a + /// _static_ function annotated with `@pragma('vm:entry-point')`. It must + /// instantiate and return a new [Route] object that will be added to the + /// navigator. The provided `arguments` object is passed to the + /// `routeBuilder`. The navigator calls the static `routeBuilder` function + /// again during state restoration to re-create the route object. + /// + /// Any object that is serializable via the [StandardMessageCodec] can be + /// passed as `arguments`. Often, a Map is used to pass key-value pairs. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool dartpad} + /// Typical usage is as follows: + /// + /// ** See code in examples/api/lib/widgets/navigator/navigator.restorable_push.0.dart ** + /// {@end-tool} + @optionalTypeArgs + static String restorablePush<T extends Object?>(BuildContext context, RestorableRouteBuilder<T> routeBuilder, {Object? arguments}) { + return Navigator.of(context).restorablePush(routeBuilder, arguments: arguments); + } + + /// Replace the current route of the navigator that most tightly encloses the + /// given context by pushing the given route and then disposing the previous + /// route once the new route has finished animating in. + /// + /// {@template flutter.widgets.navigator.pushReplacement} + /// If non-null, `result` will be used as the result of the route that is + /// removed; the future that had been returned from pushing that old route will + /// complete with `result`. Routes such as dialogs or popup menus typically + /// use this mechanism to return the value selected by the user to the widget + /// that created their route. The type of `result`, if provided, must match + /// the type argument of the class of the old route (`TO`). + /// + /// The new route and the route below the removed route are notified (see + /// [Route.didPush] and [Route.didChangeNext]). If the [Navigator] has any + /// [Navigator.observers], they will be notified as well (see + /// [NavigatorObserver.didReplace]). The removed route is notified once the + /// new route has finished animating (see [Route.didComplete]). + /// + /// Ongoing gestures within the current route are canceled when a new route is + /// pushed. + /// + /// The `T` type argument is the type of the return value of the new route, + /// and `TO` is the type of the return value of the old route. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _completeLogin() { + /// Navigator.pushReplacement<void, void>( + /// context, + /// MaterialPageRoute<void>( + /// builder: (BuildContext context) => const MyHomePage(), + /// ), + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePushReplacement], which pushes a replacement route that can + /// be restored during state restoration. + @optionalTypeArgs + static Future<T?> pushReplacement<T extends Object?, TO extends Object?>(BuildContext context, Route<T> newRoute, { TO? result }) { + return Navigator.of(context).pushReplacement<T, TO>(newRoute, result: result); + } + + /// Replace the current route of the navigator that most tightly encloses the + /// given context by pushing a new route and then disposing the previous + /// route once the new route has finished animating in. + /// + /// {@template flutter.widgets.navigator.restorablePushReplacement} + /// Unlike [Route]s pushed via [pushReplacement], [Route]s pushed with this + /// method are restored during state restoration according to the rules + /// outlined in the "State Restoration" section of [Navigator]. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushReplacement} + /// + /// {@macro flutter.widgets.Navigator.restorablePush} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool dartpad} + /// Typical usage is as follows: + /// + /// ** See code in examples/api/lib/widgets/navigator/navigator.restorable_push_replacement.0.dart ** + /// {@end-tool} + @optionalTypeArgs + static String restorablePushReplacement<T extends Object?, TO extends Object?>(BuildContext context, RestorableRouteBuilder<T> routeBuilder, { TO? result, Object? arguments }) { + return Navigator.of(context).restorablePushReplacement<T, TO>(routeBuilder, result: result, arguments: arguments); + } + + /// Push the given route onto the navigator that most tightly encloses the + /// given context, and then remove all the previous routes until the + /// `predicate` returns true. + /// + /// {@template flutter.widgets.navigator.pushAndRemoveUntil} + /// The predicate may be applied to the same route more than once if + /// [Route.willHandlePopInternally] is true. + /// + /// To remove routes until a route with a certain name, use the + /// [RoutePredicate] returned from [ModalRoute.withName]. + /// + /// To remove all the routes below the pushed route, use a [RoutePredicate] + /// that always returns false (e.g. `(Route<dynamic> route) => false`). + /// + /// The removed routes are removed without being completed, so this method + /// does not take a return value argument. + /// + /// The newly pushed route and its preceding route are notified for + /// [Route.didPush]. After removal, the new route and its new preceding route, + /// (the route below the bottommost removed route) are notified through + /// [Route.didChangeNext]). If the [Navigator] has any [Navigator.observers], + /// they will be notified as well (see [NavigatorObserver.didPush] and + /// [NavigatorObserver.didRemove]). The removed routes are disposed of and + /// notified, once the new route has finished animating. The futures that had + /// been returned from pushing those routes will not complete. + /// + /// Ongoing gestures within the current route are canceled when a new route is + /// pushed. + /// + /// The `T` type argument is the type of the return value of the new route. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _finishAccountCreation() { + /// Navigator.pushAndRemoveUntil<void>( + /// context, + /// MaterialPageRoute<void>(builder: (BuildContext context) => const MyHomePage()), + /// ModalRoute.withName('/'), + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePushAndRemoveUntil], which pushes a route that can be + /// restored during state restoration. + @optionalTypeArgs + static Future<T?> pushAndRemoveUntil<T extends Object?>(BuildContext context, Route<T> newRoute, RoutePredicate predicate) { + return Navigator.of(context).pushAndRemoveUntil<T>(newRoute, predicate); + } + + /// Push a new route onto the navigator that most tightly encloses the + /// given context, and then remove all the previous routes until the + /// `predicate` returns true. + /// + /// {@template flutter.widgets.navigator.restorablePushAndRemoveUntil} + /// Unlike [Route]s pushed via [pushAndRemoveUntil], [Route]s pushed with this + /// method are restored during state restoration according to the rules + /// outlined in the "State Restoration" section of [Navigator]. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.pushAndRemoveUntil} + /// + /// {@macro flutter.widgets.Navigator.restorablePush} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool dartpad} + /// Typical usage is as follows: + /// + /// ** See code in examples/api/lib/widgets/navigator/navigator.restorable_push_and_remove_until.0.dart ** + /// {@end-tool} + @optionalTypeArgs + static String restorablePushAndRemoveUntil<T extends Object?>(BuildContext context, RestorableRouteBuilder<T> newRouteBuilder, RoutePredicate predicate, {Object? arguments}) { + return Navigator.of(context).restorablePushAndRemoveUntil<T>(newRouteBuilder, predicate, arguments: arguments); + } + + /// Replaces a route on the navigator that most tightly encloses the given + /// context with a new route. + /// + /// {@template flutter.widgets.navigator.replace} + /// The old route must not be currently visible, as this method skips the + /// animations and therefore the removal would be jarring if it was visible. + /// To replace the top-most route, consider [pushReplacement] instead, which + /// _does_ animate the new route, and delays removing the old route until the + /// new route has finished animating. + /// + /// The removed route is removed without being completed, so this method does + /// not take a return value argument. + /// + /// The new route, the route below the new route (if any), and the route above + /// the new route, are all notified (see [Route.didReplace], + /// [Route.didChangeNext], and [Route.didChangePrevious]). If the [Navigator] + /// has any [Navigator.observers], they will be notified as well (see + /// [NavigatorObserver.didReplace]). The removed route is disposed without + /// being notified. The future that had been returned from pushing that routes + /// will not complete. + /// + /// This can be useful in combination with [removeRouteBelow] when building a + /// non-linear user experience. + /// + /// The `T` type argument is the type of the return value of the new route. + /// {@endtemplate} + /// + /// See also: + /// + /// * [replaceRouteBelow], which is the same but identifies the route to be + /// removed by reference to the route above it, rather than directly. + /// * [restorableReplace], which adds a replacement route that can be + /// restored during state restoration. + @optionalTypeArgs + static void replace<T extends Object?>(BuildContext context, { required Route<dynamic> oldRoute, required Route<T> newRoute }) { + return Navigator.of(context).replace<T>(oldRoute: oldRoute, newRoute: newRoute); + } + + /// Replaces a route on the navigator that most tightly encloses the given + /// context with a new route. + /// + /// {@template flutter.widgets.navigator.restorableReplace} + /// Unlike [Route]s added via [replace], [Route]s added with this method are + /// restored during state restoration according to the rules outlined in the + /// "State Restoration" section of [Navigator]. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.replace} + /// + /// {@macro flutter.widgets.Navigator.restorablePush} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + @optionalTypeArgs + static String restorableReplace<T extends Object?>(BuildContext context, { required Route<dynamic> oldRoute, required RestorableRouteBuilder<T> newRouteBuilder, Object? arguments }) { + return Navigator.of(context).restorableReplace<T>(oldRoute: oldRoute, newRouteBuilder: newRouteBuilder, arguments: arguments); + } + + /// Replaces a route on the navigator that most tightly encloses the given + /// context with a new route. The route to be replaced is the one below the + /// given `anchorRoute`. + /// + /// {@template flutter.widgets.navigator.replaceRouteBelow} + /// The old route must not be current visible, as this method skips the + /// animations and therefore the removal would be jarring if it was visible. + /// To replace the top-most route, consider [pushReplacement] instead, which + /// _does_ animate the new route, and delays removing the old route until the + /// new route has finished animating. + /// + /// The removed route is removed without being completed, so this method does + /// not take a return value argument. + /// + /// The new route, the route below the new route (if any), and the route above + /// the new route, are all notified (see [Route.didReplace], + /// [Route.didChangeNext], and [Route.didChangePrevious]). If the [Navigator] + /// has any [Navigator.observers], they will be notified as well (see + /// [NavigatorObserver.didReplace]). The removed route is disposed without + /// being notified. The future that had been returned from pushing that routes + /// will not complete. + /// + /// The `T` type argument is the type of the return value of the new route. + /// {@endtemplate} + /// + /// See also: + /// + /// * [replace], which is the same but identifies the route to be removed + /// directly. + /// * [restorableReplaceRouteBelow], which adds a replacement route that can + /// be restored during state restoration. + @optionalTypeArgs + static void replaceRouteBelow<T extends Object?>(BuildContext context, { required Route<dynamic> anchorRoute, required Route<T> newRoute }) { + return Navigator.of(context).replaceRouteBelow<T>(anchorRoute: anchorRoute, newRoute: newRoute); + } + + /// Replaces a route on the navigator that most tightly encloses the given + /// context with a new route. The route to be replaced is the one below the + /// given `anchorRoute`. + /// + /// {@template flutter.widgets.navigator.restorableReplaceRouteBelow} + /// Unlike [Route]s added via [restorableReplaceRouteBelow], [Route]s added + /// with this method are restored during state restoration according to the + /// rules outlined in the "State Restoration" section of [Navigator]. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.navigator.replaceRouteBelow} + /// + /// {@macro flutter.widgets.Navigator.restorablePush} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + @optionalTypeArgs + static String restorableReplaceRouteBelow<T extends Object?>(BuildContext context, { required Route<dynamic> anchorRoute, required RestorableRouteBuilder<T> newRouteBuilder, Object? arguments }) { + return Navigator.of(context).restorableReplaceRouteBelow<T>(anchorRoute: anchorRoute, newRouteBuilder: newRouteBuilder, arguments: arguments); + } + + /// Whether the navigator that most tightly encloses the given context can be + /// popped. + /// + /// {@template flutter.widgets.navigator.canPop} + /// The initial route cannot be popped off the navigator, which implies that + /// this function returns true only if popping the navigator would not remove + /// the initial route. + /// + /// If there is no [Navigator] in scope, returns false. + /// + /// Does not consider anything that might externally prevent popping, such as + /// [PopEntry]. + /// {@endtemplate} + /// + /// See also: + /// + /// * [Route.isFirst], which returns true for routes for which [canPop] + /// returns false. + static bool canPop(BuildContext context) { + final NavigatorState? navigator = Navigator.maybeOf(context); + return navigator != null && navigator.canPop(); + } + + /// Consults the current route's [Route.popDisposition] getter or + /// [Route.willPop] method, and acts accordingly, potentially popping the + /// route as a result; returns whether the pop request should be considered + /// handled. + /// + /// {@template flutter.widgets.navigator.maybePop} + /// If the [RoutePopDisposition] is [RoutePopDisposition.pop], then the [pop] + /// method is called, and this method returns true, indicating that it handled + /// the pop request. + /// + /// If the [RoutePopDisposition] is [RoutePopDisposition.doNotPop], then this + /// method returns true, but does not do anything beyond that. + /// + /// If the [RoutePopDisposition] is [RoutePopDisposition.bubble], then this + /// method returns false, and the caller is responsible for sending the + /// request to the containing scope (e.g. by closing the application). + /// + /// This method is typically called for a user-initiated [pop]. For example on + /// Android it's called by the binding for the system's back button. + /// + /// The `T` type argument is the type of the return value of the current + /// route. (Typically this isn't known; consider specifying `dynamic` or + /// `Null`.) + /// {@endtemplate} + /// + /// See also: + /// + /// * [Form], which provides an `onWillPop` callback that enables the form + /// to veto a [pop] initiated by the app's back button. + /// * [ModalRoute], which provides a `scopedWillPopCallback` that can be used + /// to define the route's `willPop` method. + @optionalTypeArgs + static Future<bool> maybePop<T extends Object?>(BuildContext context, [ T? result ]) { + return Navigator.of(context).maybePop<T>(result); + } + + /// Pop the top-most route off the navigator that most tightly encloses the + /// given context. + /// + /// {@template flutter.widgets.navigator.pop} + /// The current route's [Route.didPop] method is called first. If that method + /// returns false, then the route remains in the [Navigator]'s history (the + /// route is expected to have popped some internal state; see e.g. + /// [LocalHistoryRoute]). Otherwise, the rest of this description applies. + /// + /// If non-null, `result` will be used as the result of the route that is + /// popped; the future that had been returned from pushing the popped route + /// will complete with `result`. Routes such as dialogs or popup menus + /// typically use this mechanism to return the value selected by the user to + /// the widget that created their route. The type of `result`, if provided, + /// must match the type argument of the class of the popped route (`T`). + /// + /// The popped route and the route below it are notified (see [Route.didPop], + /// [Route.didComplete], and [Route.didPopNext]). If the [Navigator] has any + /// [Navigator.observers], they will be notified as well (see + /// [NavigatorObserver.didPop]). + /// + /// The `T` type argument is the type of the return value of the popped route. + /// + /// The type of `result`, if provided, must match the type argument of the + /// class of the popped route (`T`). + /// {@endtemplate} + /// + /// {@tool snippet} + /// + /// Typical usage for closing a route is as follows: + /// + /// ```dart + /// void _close() { + /// Navigator.pop(context); + /// } + /// ``` + /// {@end-tool} + /// + /// A dialog box might be closed with a result: + /// + /// ```dart + /// void _accept() { + /// Navigator.pop(context, true); // dialog returns true + /// } + /// ``` + @optionalTypeArgs + static void pop<T extends Object?>(BuildContext context, [ T? result ]) { + Navigator.of(context).pop<T>(result); + } + + /// Calls [pop] repeatedly on the navigator that most tightly encloses the + /// given context until the predicate returns true. + /// + /// {@template flutter.widgets.navigator.popUntil} + /// The predicate may be applied to the same route more than once if + /// [Route.willHandlePopInternally] is true. + /// + /// To pop until a route with a certain name, use the [RoutePredicate] + /// returned from [ModalRoute.withName]. + /// + /// The routes are closed with null as their `return` value. + /// + /// See [pop] for more details of the semantics of popping a route. + /// {@endtemplate} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _logout() { + /// Navigator.popUntil(context, ModalRoute.withName('/login')); + /// } + /// ``` + /// {@end-tool} + static void popUntil(BuildContext context, RoutePredicate predicate) { + Navigator.of(context).popUntil(predicate); + } + + /// Immediately remove `route` from the navigator that most tightly encloses + /// the given context, and [Route.dispose] it. + /// + /// {@template flutter.widgets.navigator.removeRoute} + /// The removed route is removed without being completed, so this method does + /// not take a return value argument. No animations are run as a result of + /// this method call. + /// + /// The routes below and above the removed route are notified (see + /// [Route.didChangeNext] and [Route.didChangePrevious]). If the [Navigator] + /// has any [Navigator.observers], they will be notified as well (see + /// [NavigatorObserver.didRemove]). The removed route is disposed without + /// being notified. The future that had been returned from pushing that routes + /// will not complete. + /// + /// The given `route` must be in the history; this method will throw an + /// exception if it is not. + /// + /// Ongoing gestures within the current route are canceled. + /// {@endtemplate} + /// + /// This method is used, for example, to instantly dismiss dropdown menus that + /// are up when the screen's orientation changes. + static void removeRoute(BuildContext context, Route<dynamic> route) { + return Navigator.of(context).removeRoute(route); + } + + /// Immediately remove a route from the navigator that most tightly encloses + /// the given context, and [Route.dispose] it. The route to be removed is the + /// one below the given `anchorRoute`. + /// + /// {@template flutter.widgets.navigator.removeRouteBelow} + /// The removed route is removed without being completed, so this method does + /// not take a return value argument. No animations are run as a result of + /// this method call. + /// + /// The routes below and above the removed route are notified (see + /// [Route.didChangeNext] and [Route.didChangePrevious]). If the [Navigator] + /// has any [Navigator.observers], they will be notified as well (see + /// [NavigatorObserver.didRemove]). The removed route is disposed without + /// being notified. The future that had been returned from pushing that routes + /// will not complete. + /// + /// The given `anchorRoute` must be in the history and must have a route below + /// it; this method will throw an exception if it is not or does not. + /// + /// Ongoing gestures within the current route are canceled. + /// {@endtemplate} + static void removeRouteBelow(BuildContext context, Route<dynamic> anchorRoute) { + return Navigator.of(context).removeRouteBelow(anchorRoute); + } + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// Navigator.of(context) + /// ..pop() + /// ..pop() + /// ..pushNamed('/settings'); + /// ``` + /// + /// If `rootNavigator` is set to true, the state from the furthest instance of + /// this class is given instead. Useful for pushing contents above all + /// subsequent instances of [Navigator]. + /// + /// If there is no [Navigator] in the give `context`, this function will throw + /// a [FlutterError] in debug mode, and an exception in release mode. + /// + /// This method can be expensive (it walks the element tree). + static NavigatorState of( + BuildContext context, { + bool rootNavigator = false, + }) { + // Handles the case where the input context is a navigator element. + NavigatorState? navigator; + if (context is StatefulElement && context.state is NavigatorState) { + navigator = context.state as NavigatorState; + } + if (rootNavigator) { + navigator = context.findRootAncestorStateOfType<NavigatorState>() ?? navigator; + } else { + navigator = navigator ?? context.findAncestorStateOfType<NavigatorState>(); + } + + assert(() { + if (navigator == null) { + throw FlutterError( + 'Navigator operation requested with a context that does not include a Navigator.\n' + 'The context used to push or pop routes from the Navigator must be that of a ' + 'widget that is a descendant of a Navigator widget.', + ); + } + return true; + }()); + return navigator!; + } + + /// The state from the closest instance of this class that encloses the given + /// context, if any. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// NavigatorState? navigatorState = Navigator.maybeOf(context); + /// if (navigatorState != null) { + /// navigatorState + /// ..pop() + /// ..pop() + /// ..pushNamed('/settings'); + /// } + /// ``` + /// + /// If `rootNavigator` is set to true, the state from the furthest instance of + /// this class is given instead. Useful for pushing contents above all + /// subsequent instances of [Navigator]. + /// + /// Will return null if there is no ancestor [Navigator] in the `context`. + /// + /// This method can be expensive (it walks the element tree). + static NavigatorState? maybeOf( + BuildContext context, { + bool rootNavigator = false, + }) { + // Handles the case where the input context is a navigator element. + NavigatorState? navigator; + if (context is StatefulElement && context.state is NavigatorState) { + navigator = context.state as NavigatorState; + } + if (rootNavigator) { + navigator = context.findRootAncestorStateOfType<NavigatorState>() ?? navigator; + } else { + navigator = navigator ?? context.findAncestorStateOfType<NavigatorState>(); + } + return navigator; + } + + /// Turn a route name into a set of [Route] objects. + /// + /// This is the default value of [onGenerateInitialRoutes], which is used if + /// [initialRoute] is not null. + /// + /// If this string starts with a `/` character and has multiple `/` characters + /// in it, then the string is split on those characters and substrings from + /// the start of the string up to each such character are, in turn, used as + /// routes to push. + /// + /// For example, if the route `/stocks/HOOLI` was used as the [initialRoute], + /// then the [Navigator] would push the following routes on startup: `/`, + /// `/stocks`, `/stocks/HOOLI`. This enables deep linking while allowing the + /// application to maintain a predictable route history. + static List<Route<dynamic>> defaultGenerateInitialRoutes(NavigatorState navigator, String initialRouteName) { + final List<Route<dynamic>?> result = <Route<dynamic>?>[]; + if (initialRouteName.startsWith('/') && initialRouteName.length > 1) { + initialRouteName = initialRouteName.substring(1); // strip leading '/' + assert(Navigator.defaultRouteName == '/'); + List<String>? debugRouteNames; + assert(() { + debugRouteNames = <String>[ Navigator.defaultRouteName ]; + return true; + }()); + result.add(navigator._routeNamed<dynamic>(Navigator.defaultRouteName, arguments: null, allowNull: true)); + final List<String> routeParts = initialRouteName.split('/'); + if (initialRouteName.isNotEmpty) { + String routeName = ''; + for (final String part in routeParts) { + routeName += '/$part'; + assert(() { + debugRouteNames!.add(routeName); + return true; + }()); + result.add(navigator._routeNamed<dynamic>(routeName, arguments: null, allowNull: true)); + } + } + if (result.last == null) { + assert(() { + FlutterError.reportError( + FlutterErrorDetails( + exception: + 'Could not navigate to initial route.\n' + 'The requested route name was: "/$initialRouteName"\n' + 'There was no corresponding route in the app, and therefore the initial route specified will be ' + 'ignored and "${Navigator.defaultRouteName}" will be used instead.', + ), + ); + return true; + }()); + for (final Route<dynamic>? route in result) { + route?.dispose(); + } + result.clear(); + } + } else if (initialRouteName != Navigator.defaultRouteName) { + // If initialRouteName wasn't '/', then we try to get it with allowNull:true, so that if that fails, + // we fall back to '/' (without allowNull:true, see below). + result.add(navigator._routeNamed<dynamic>(initialRouteName, arguments: null, allowNull: true)); + } + // Null route might be a result of gap in initialRouteName + // + // For example, routes = ['A', 'A/B/C'], and initialRouteName = 'A/B/C' + // This should result in result = ['A', null,'A/B/C'] where 'A/B' produces + // the null. In this case, we want to filter out the null and return + // result = ['A', 'A/B/C']. + result.removeWhere((Route<dynamic>? route) => route == null); + if (result.isEmpty) { + result.add(navigator._routeNamed<dynamic>(Navigator.defaultRouteName, arguments: null)); + } + return result.cast<Route<dynamic>>(); + } + + @override + NavigatorState createState() => NavigatorState(); +} + +// The _RouteLifecycle state machine (only goes down): +// +// [creation of a _RouteEntry] +// | +// + +// |\ +// | \ +// | staging +// | / +// |/ +// +-+----------+--+-------+ +// / | | | +// / | | | +// / | | | +// / | | | +// / | | | +// pushReplace push* add* replace* +// \ | | | +// \ | | / +// +--pushing# adding / +// \ / / +// \ / / +// idle--+-----+ +// / \ +// / +------+ +// / | | +// / | complete* +// | | / +// pop* remove* +// / \ +// / removing# +// popping# | +// | | +// [finalizeRoute] | +// \ | +// dispose* +// | +// disposing +// | +// disposed +// | +// | +// [_RouteEntry garbage collected] +// (terminal state) +// +// * These states are transient; as soon as _flushHistoryUpdates is run the +// route entry will exit that state. +// # These states await futures or other events, then transition automatically. +enum _RouteLifecycle { + staging, // we will wait for transition delegate to decide what to do with this route. + // + // routes that are present: + // + add, // we'll want to run install, didAdd, etc; a route created by onGenerateInitialRoutes or by the initial widget.pages + adding, // we'll waiting for the future from didPush of top-most route to complete + // routes that are ready for transition. + push, // we'll want to run install, didPush, etc; a route added via push() and friends + pushReplace, // we'll want to run install, didPush, etc; a route added via pushReplace() and friends + pushing, // we're waiting for the future from didPush to complete + replace, // we'll want to run install, didReplace, etc; a route added via replace() and friends + idle, // route is being harmless + // + // routes that are not present: + // + // routes that should be included in route announcement and should still listen to transition changes. + pop, // we'll want to call didPop + complete, // we'll want to call didComplete, + remove, // we'll want to run didReplace/didRemove etc + // routes should not be included in route announcement but should still listen to transition changes. + popping, // we're waiting for the route to call finalizeRoute to switch to dispose + removing, // we are waiting for subsequent routes to be done animating, then will switch to dispose + // routes that are completely removed from the navigator and overlay. + dispose, // we will dispose the route momentarily + disposing, // The entry is waiting for its widget subtree to be disposed + // first. It is stored in _entryWaitingForSubTreeDisposal while + // awaiting that. + disposed, // we have disposed the route +} + +typedef _RouteEntryPredicate = bool Function(_RouteEntry entry); + +class _NotAnnounced extends Route<void> { + // A placeholder for the lastAnnouncedPreviousRoute, the + // lastAnnouncedPoppedNextRoute, and the lastAnnouncedNextRoute before any + // change has been announced. +} + +class _RouteEntry extends RouteTransitionRecord { + _RouteEntry( + this.route, { + required _RouteLifecycle initialState, + required this.pageBased, + this.restorationInformation, + }) : assert(!pageBased || route.settings is Page), + assert( + initialState == _RouteLifecycle.staging || + initialState == _RouteLifecycle.add || + initialState == _RouteLifecycle.push || + initialState == _RouteLifecycle.pushReplace || + initialState == _RouteLifecycle.replace, + ), + currentState = initialState { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/widgets.dart', + className: '$_RouteEntry', + object: this, + ); + } + } + + @override + final Route<dynamic> route; + final _RestorationInformation? restorationInformation; + final bool pageBased; + + /// The limit this route entry will attempt to pop in the case of route being + /// remove as a result of a page update. + static const int kDebugPopAttemptLimit = 100; + + static final Route<dynamic> notAnnounced = _NotAnnounced(); + + _RouteLifecycle currentState; + Route<dynamic>? lastAnnouncedPreviousRoute = notAnnounced; // last argument to Route.didChangePrevious + WeakReference<Route<dynamic>> lastAnnouncedPoppedNextRoute = WeakReference<Route<dynamic>>(notAnnounced); // last argument to Route.didPopNext + Route<dynamic>? lastAnnouncedNextRoute = notAnnounced; // last argument to Route.didChangeNext + int? lastFocusNode; // The last focused semantic node for the route entry. + + /// Restoration ID to be used for the encapsulating route when restoration is + /// enabled for it or null if restoration cannot be enabled for it. + String? get restorationId { + // User-provided restoration ids of Pages are prefixed with 'p+'. Generated + // ids for pageless routes are prefixed with 'r+' to avoid clashes. + if (pageBased) { + final Page<Object?> page = route.settings as Page<Object?>; + return page.restorationId != null ? 'p+${page.restorationId}' : null; + } + if (restorationInformation != null) { + return 'r+${restorationInformation!.restorationScopeId}'; + } + return null; + } + + bool canUpdateFrom(Page<dynamic> page) { + if (!willBePresent) { + return false; + } + if (!pageBased) { + return false; + } + final Page<dynamic> routePage = route.settings as Page<dynamic>; + return page.canUpdate(routePage); + } + + void handleAdd({ required NavigatorState navigator, required Route<dynamic>? previousPresent }) { + assert(currentState == _RouteLifecycle.add); + assert(navigator._debugLocked); + assert(route._navigator == null); + route._navigator = navigator; + route.install(); + assert(route.overlayEntries.isNotEmpty); + currentState = _RouteLifecycle.adding; + navigator._observedRouteAdditions.add( + _NavigatorPushObservation(route, previousPresent), + ); + } + + void handlePush({ required NavigatorState navigator, required bool isNewFirst, required Route<dynamic>? previous, required Route<dynamic>? previousPresent }) { + assert(currentState == _RouteLifecycle.push || currentState == _RouteLifecycle.pushReplace || currentState == _RouteLifecycle.replace); + assert(navigator._debugLocked); + assert( + route._navigator == null, + 'The pushed route has already been used. When pushing a route, a new ' + 'Route object must be provided.', + ); + final _RouteLifecycle previousState = currentState; + route._navigator = navigator; + route.install(); + assert(route.overlayEntries.isNotEmpty); + if (currentState == _RouteLifecycle.push || currentState == _RouteLifecycle.pushReplace) { + final TickerFuture routeFuture = route.didPush(); + currentState = _RouteLifecycle.pushing; + routeFuture.whenCompleteOrCancel(() { + if (currentState == _RouteLifecycle.pushing) { + currentState = _RouteLifecycle.idle; + assert(!navigator._debugLocked); + assert(() { navigator._debugLocked = true; return true; }()); + navigator._flushHistoryUpdates(); + assert(() { navigator._debugLocked = false; return true; }()); + } + }); + } else { + assert(currentState == _RouteLifecycle.replace); + route.didReplace(previous); + currentState = _RouteLifecycle.idle; + } + if (isNewFirst) { + route.didChangeNext(null); + } + + if (previousState == _RouteLifecycle.replace || previousState == _RouteLifecycle.pushReplace) { + navigator._observedRouteAdditions.add( + _NavigatorReplaceObservation(route, previousPresent), + ); + } else { + assert(previousState == _RouteLifecycle.push); + navigator._observedRouteAdditions.add( + _NavigatorPushObservation(route, previousPresent), + ); + } + } + + void handleDidPopNext(Route<dynamic> poppedRoute) { + route.didPopNext(poppedRoute); + lastAnnouncedPoppedNextRoute = WeakReference<Route<dynamic>>(poppedRoute); + if (lastFocusNode != null) { + // Move focus back to the last focused node. + poppedRoute._disposeCompleter.future.then((dynamic result) async { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + // In the Android platform, we have to wait for the system refocus to complete before + // sending the refocus message. Otherwise, the refocus message will be ignored. + // TODO(hangyujin): update this logic if Android provide a better way to do so. + final int? reFocusNode = lastFocusNode; + await Future<void>.delayed(_kAndroidRefocusingDelayDuration); + SystemChannels.accessibility.send(const FocusSemanticEvent().toMap(nodeId: reFocusNode)); + case TargetPlatform.iOS: + SystemChannels.accessibility.send(const FocusSemanticEvent().toMap(nodeId: lastFocusNode)); + case _: + break ; + } + }); + } + } + + /// Process the to-be-popped route. + /// + /// A route can be marked for pop by transition delegate or Navigator.pop, + /// this method actually pops the route by calling Route.didPop. + /// + /// Returns true if the route is popped; otherwise, returns false if the route + /// refuses to be popped. + bool handlePop({ required NavigatorState navigator, required Route<dynamic>? previousPresent }) { + assert(navigator._debugLocked); + assert(route._navigator == navigator); + currentState = _RouteLifecycle.popping; + if (route._popCompleter.isCompleted) { + // This is a page-based route popped through the Navigator.pop. The + // didPop should have been called. No further action is needed. + assert(pageBased); + assert(pendingResult == null); + return true; + } + if (!route.didPop(pendingResult)) { + currentState = _RouteLifecycle.idle; + return false; + } + pendingResult = null; + return true; + } + + void handleComplete() { + route.didComplete(pendingResult); + pendingResult = null; + assert(route._popCompleter.isCompleted); // implies didComplete was called + currentState = _RouteLifecycle.remove; + } + + void handleRemoval({ required NavigatorState navigator, required Route<dynamic>? previousPresent }) { + assert(navigator._debugLocked); + assert(route._navigator == navigator); + currentState = _RouteLifecycle.removing; + if (_reportRemovalToObserver) { + navigator._observedRouteDeletions.add( + _NavigatorRemoveObservation(route, previousPresent), + ); + } + } + + void didAdd({ required NavigatorState navigator, required bool isNewFirst}) { + route.didAdd(); + currentState = _RouteLifecycle.idle; + if (isNewFirst) { + route.didChangeNext(null); + } + } + + Object? pendingResult; + + void pop<T>(T? result) { + assert(isPresent); + pendingResult = result; + currentState = _RouteLifecycle.pop; + route.onPopInvoked(true); + } + + bool _reportRemovalToObserver = true; + + // Route is removed without being completed. + void remove({ bool isReplaced = false }) { + assert( + !pageBased || isWaitingForExitingDecision, + 'A page-based route cannot be completed using imperative api, provide a ' + 'new list without the corresponding Page to Navigator.pages instead. ', + ); + if (currentState.index >= _RouteLifecycle.remove.index) { + return; + } + assert(isPresent); + _reportRemovalToObserver = !isReplaced; + currentState = _RouteLifecycle.remove; + } + + // Route completes with `result` and is removed. + void complete<T>(T result, { bool isReplaced = false }) { + assert( + !pageBased || isWaitingForExitingDecision, + 'A page-based route cannot be completed using imperative api, provide a ' + 'new list without the corresponding Page to Navigator.pages instead. ', + ); + if (currentState.index >= _RouteLifecycle.remove.index) { + return; + } + assert(isPresent); + _reportRemovalToObserver = !isReplaced; + pendingResult = result; + currentState = _RouteLifecycle.complete; + } + + void finalize() { + assert(currentState.index < _RouteLifecycle.dispose.index); + currentState = _RouteLifecycle.dispose; + } + + /// Disposes this route entry and its [route] immediately. + /// + /// This method does not wait for the widget subtree of the [route] to unmount + /// before disposing. + void forcedDispose() { + assert(currentState.index < _RouteLifecycle.disposed.index); + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + currentState = _RouteLifecycle.disposed; + route.dispose(); + } + + /// Disposes this route entry and its [route]. + /// + /// This method waits for the widget subtree of the [route] to unmount before + /// disposing. If subtree is already unmounted, this method calls + /// [forcedDispose] immediately. + /// + /// Use [forcedDispose] if the [route] need to be disposed immediately. + void dispose() { + assert(currentState.index < _RouteLifecycle.disposing.index); + currentState = _RouteLifecycle.disposing; + + // If the overlay entries are still mounted, widgets in the route's subtree + // may still reference resources from the route and we delay disposal of + // the route until the overlay entries are no longer mounted. + // Since the overlay entry is the root of the route's subtree it will only + // get unmounted after every other widget in the subtree has been unmounted. + + final Iterable<OverlayEntry> mountedEntries = route.overlayEntries.where((OverlayEntry e) => e.mounted); + + if (mountedEntries.isEmpty) { + forcedDispose(); + return; + } + + int mounted = mountedEntries.length; + assert(mounted > 0); + final NavigatorState navigator = route._navigator!; + navigator._entryWaitingForSubTreeDisposal.add(this); + for (final OverlayEntry entry in mountedEntries) { + late VoidCallback listener; + listener = () { + assert(mounted > 0); + assert(!entry.mounted); + mounted--; + entry.removeListener(listener); + if (mounted == 0) { + assert(route.overlayEntries.every((OverlayEntry e) => !e.mounted)); + // This is a listener callback of one of the overlayEntries in this + // route. Disposing the route also disposes its overlayEntries and + // violates the rule that a change notifier can't be disposed during + // its notifying callback. + // + // Use a microtask to ensure the overlayEntries have finished + // notifying their listeners before disposing. + return scheduleMicrotask(() { + if (!navigator._entryWaitingForSubTreeDisposal.remove(this)) { + // This route must have been destroyed as a result of navigator + // force dispose. + assert(route._navigator == null && !navigator.mounted); + return; + } + assert(currentState == _RouteLifecycle.disposing); + forcedDispose(); + }); + } + }; + entry.addListener(listener); + } + } + + bool get willBePresent { + return currentState.index <= _RouteLifecycle.idle.index && + currentState.index >= _RouteLifecycle.add.index; + } + + bool get isPresent { + return currentState.index <= _RouteLifecycle.remove.index && + currentState.index >= _RouteLifecycle.add.index; + } + + bool get isPresentForRestoration => currentState.index <= _RouteLifecycle.idle.index; + + bool get suitableForAnnouncement { + return currentState.index <= _RouteLifecycle.removing.index && + currentState.index >= _RouteLifecycle.push.index; + } + + bool get suitableForTransitionAnimation { + return currentState.index <= _RouteLifecycle.remove.index && + currentState.index >= _RouteLifecycle.push.index; + } + + bool shouldAnnounceChangeToNext(Route<dynamic>? nextRoute) { + assert(nextRoute != lastAnnouncedNextRoute); + // Do not announce if `next` changes from a just popped route to null. We + // already announced this change by calling didPopNext. + return !( + nextRoute == null && + lastAnnouncedPoppedNextRoute.target == lastAnnouncedNextRoute + ); + } + + static bool isPresentPredicate(_RouteEntry entry) => entry.isPresent; + static bool suitableForTransitionAnimationPredicate(_RouteEntry entry) => entry.suitableForTransitionAnimation; + static bool willBePresentPredicate(_RouteEntry entry) => entry.willBePresent; + + static _RouteEntryPredicate isRoutePredicate(Route<dynamic> route) { + return (_RouteEntry entry) => entry.route == route; + } + + @override + bool get isWaitingForEnteringDecision => currentState == _RouteLifecycle.staging; + + @override + bool get isWaitingForExitingDecision => _isWaitingForExitingDecision; + bool _isWaitingForExitingDecision = false; + + void markNeedsExitingDecision() => _isWaitingForExitingDecision = true; + + @override + void markForPush() { + assert( + isWaitingForEnteringDecision && !isWaitingForExitingDecision, + 'This route cannot be marked for push. Either a decision has already been ' + 'made or it does not require an explicit decision on how to transition in.', + ); + currentState = _RouteLifecycle.push; + } + + @override + void markForAdd() { + assert( + isWaitingForEnteringDecision && !isWaitingForExitingDecision, + 'This route cannot be marked for add. Either a decision has already been ' + 'made or it does not require an explicit decision on how to transition in.', + ); + currentState = _RouteLifecycle.add; + } + + @override + void markForPop([dynamic result]) { + assert( + !isWaitingForEnteringDecision && isWaitingForExitingDecision && isPresent, + 'This route cannot be marked for pop. Either a decision has already been ' + 'made or it does not require an explicit decision on how to transition out.', + ); + // Remove state that prevents a pop, e.g. LocalHistoryEntry[s]. + int attempt = 0; + while (route.willHandlePopInternally) { + assert( + () { + attempt += 1; + return attempt < kDebugPopAttemptLimit; + }(), + 'Attempted to pop $route $kDebugPopAttemptLimit times, but still failed', + ); + final bool popResult = route.didPop(result); + assert(!popResult); + + } + pop<dynamic>(result); + _isWaitingForExitingDecision = false; + } + + @override + void markForComplete([dynamic result]) { + assert( + !isWaitingForEnteringDecision && isWaitingForExitingDecision && isPresent, + 'This route cannot be marked for complete. Either a decision has already ' + 'been made or it does not require an explicit decision on how to transition ' + 'out.', + ); + complete<dynamic>(result); + _isWaitingForExitingDecision = false; + } + + @override + void markForRemove() { + assert( + !isWaitingForEnteringDecision && isWaitingForExitingDecision && isPresent, + 'This route cannot be marked for remove. Either a decision has already ' + 'been made or it does not require an explicit decision on how to transition ' + 'out.', + ); + remove(); + _isWaitingForExitingDecision = false; + } + + bool get restorationEnabled => route.restorationScopeId.value != null; + set restorationEnabled(bool value) { + assert(!value || restorationId != null); + route._updateRestorationId(value ? restorationId : null); + } +} + +abstract class _NavigatorObservation { + _NavigatorObservation( + this.primaryRoute, + this.secondaryRoute, + ); + final Route<dynamic> primaryRoute; + final Route<dynamic>? secondaryRoute; + + void notify(NavigatorObserver observer); +} + +class _NavigatorPushObservation extends _NavigatorObservation { + _NavigatorPushObservation( + super.primaryRoute, + super.secondaryRoute, + ); + + @override + void notify(NavigatorObserver observer) { + observer.didPush(primaryRoute, secondaryRoute); + } +} + +class _NavigatorPopObservation extends _NavigatorObservation { + _NavigatorPopObservation( + super.primaryRoute, + super.secondaryRoute, + ); + + @override + void notify(NavigatorObserver observer) { + observer.didPop(primaryRoute, secondaryRoute); + } +} + +class _NavigatorRemoveObservation extends _NavigatorObservation { + _NavigatorRemoveObservation( + super.primaryRoute, + super.secondaryRoute, + ); + + @override + void notify(NavigatorObserver observer) { + observer.didRemove(primaryRoute, secondaryRoute); + } +} + +class _NavigatorReplaceObservation extends _NavigatorObservation { + _NavigatorReplaceObservation( + super.primaryRoute, + super.secondaryRoute, + ); + + @override + void notify(NavigatorObserver observer) { + observer.didReplace(newRoute: primaryRoute, oldRoute: secondaryRoute); + } +} + +typedef _IndexWhereCallback = bool Function(_RouteEntry element); + +/// A collection of _RouteEntries representing a navigation history. +/// +/// Acts as a ChangeNotifier and notifies after its List of _RouteEntries is +/// mutated. +class _History extends Iterable<_RouteEntry> with ChangeNotifier { + /// Creates an instance of [_History]. + _History() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + final List<_RouteEntry> _value = <_RouteEntry>[]; + + int indexWhere(_IndexWhereCallback test, [int start = 0]) { + return _value.indexWhere(test, start); + } + + void add(_RouteEntry element) { + _value.add(element); + notifyListeners(); + } + + void addAll(Iterable<_RouteEntry> elements) { + _value.addAll(elements); + if (elements.isNotEmpty) { + notifyListeners(); + } + } + + void clear() { + final bool valueWasEmpty = _value.isEmpty; + _value.clear(); + if (!valueWasEmpty) { + notifyListeners(); + } + } + + void insert(int index, _RouteEntry element) { + _value.insert(index, element); + notifyListeners(); + } + + _RouteEntry removeAt(int index) { + final _RouteEntry entry = _value.removeAt(index); + notifyListeners(); + return entry; + } + + _RouteEntry removeLast() { + final _RouteEntry entry = _value.removeLast(); + notifyListeners(); + return entry; + } + + _RouteEntry operator [](int index) { + return _value[index]; + } + + @override + Iterator<_RouteEntry> get iterator { + return _value.iterator; + } + + @override + String toString() { + return _value.toString(); + } +} + +/// The state for a [Navigator] widget. +/// +/// A reference to this class can be obtained by calling [Navigator.of]. +class NavigatorState extends State<Navigator> with TickerProviderStateMixin, RestorationMixin { + late GlobalKey<OverlayState> _overlayKey; + final _History _history = _History(); + + /// A set for entries that are waiting to dispose until their subtrees are + /// disposed. + /// + /// These entries are not considered to be in the _history and will usually + /// remove themselves from this set once they can dispose. + /// + /// The navigator keep track of these entries so that, in case the navigator + /// itself is disposed, it can dispose these entries immediately. + final Set<_RouteEntry> _entryWaitingForSubTreeDisposal = <_RouteEntry>{}; + final _HistoryProperty _serializableHistory = _HistoryProperty(); + final Queue<_NavigatorObservation> _observedRouteAdditions = Queue<_NavigatorObservation>(); + final Queue<_NavigatorObservation> _observedRouteDeletions = Queue<_NavigatorObservation>(); + + /// The [FocusNode] for the [Focus] that encloses the routes. + final FocusNode focusNode = FocusNode(debugLabel: 'Navigator'); + + bool _debugLocked = false; // used to prevent re-entrant calls to push, pop, and friends + + HeroController? _heroControllerFromScope; + + late List<NavigatorObserver> _effectiveObservers; + + bool get _usingPagesAPI => widget.pages != const <Page<dynamic>>[]; + + void _handleHistoryChanged() { + final bool navigatorCanPop = canPop(); + late final bool routeBlocksPop; + if (!navigatorCanPop) { + final _RouteEntry? lastEntry = _lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate); + routeBlocksPop = lastEntry != null + && lastEntry.route.popDisposition == RoutePopDisposition.doNotPop; + } else { + routeBlocksPop = false; + } + final NavigationNotification notification = NavigationNotification( + canHandlePop: navigatorCanPop || routeBlocksPop, + ); + // Avoid dispatching a notification in the middle of a build. + switch (SchedulerBinding.instance.schedulerPhase) { + case SchedulerPhase.postFrameCallbacks: + notification.dispatch(context); + case SchedulerPhase.idle: + case SchedulerPhase.midFrameMicrotasks: + case SchedulerPhase.persistentCallbacks: + case SchedulerPhase.transientCallbacks: + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + if (!mounted) { + return; + } + notification.dispatch(context); + }, debugLabel: 'Navigator.dispatchNotification'); + } + } + + @override + void initState() { + super.initState(); + assert(() { + if (_usingPagesAPI) { + if (widget.pages.isEmpty) { + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError( + 'The Navigator.pages must not be empty to use the ' + 'Navigator.pages API', + ), + library: 'widget library', + stack: StackTrace.current, + ), + ); + } else if (widget.onPopPage == null) { + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError( + 'The Navigator.onPopPage must be provided to use the ' + 'Navigator.pages API', + ), + library: 'widget library', + stack: StackTrace.current, + ), + ); + } + } + return true; + }()); + for (final NavigatorObserver observer in widget.observers) { + assert(observer.navigator == null); + NavigatorObserver._navigators[observer] = this; + } + _effectiveObservers = widget.observers; + + // We have to manually extract the inherited widget in initState because + // the current context is not fully initialized. + final HeroControllerScope? heroControllerScope = context + .getElementForInheritedWidgetOfExactType<HeroControllerScope>() + ?.widget as HeroControllerScope?; + _updateHeroController(heroControllerScope?.controller); + + if (widget.reportsRouteUpdateToEngine) { + SystemNavigator.selectSingleEntryHistory(); + } + + ServicesBinding.instance.accessibilityFocus.addListener(_recordLastFocus); + _history.addListener(_handleHistoryChanged); + } + + // Record the last focused node in route entry. + void _recordLastFocus(){ + final _RouteEntry? entry = _history.where(_RouteEntry.isPresentPredicate).lastOrNull; + entry?.lastFocusNode = ServicesBinding.instance.accessibilityFocus.value; + } + + // Use [_nextPagelessRestorationScopeId] to get the next id. + final RestorableNum<int> _rawNextPagelessRestorationScopeId = RestorableNum<int>(0); + + int get _nextPagelessRestorationScopeId => _rawNextPagelessRestorationScopeId.value++; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_rawNextPagelessRestorationScopeId, 'id'); + registerForRestoration(_serializableHistory, 'history'); + + // Delete everything in the old history and clear the overlay. + _forcedDisposeAllRouteEntries(); + assert(_history.isEmpty); + _overlayKey = GlobalKey<OverlayState>(); + + // Populate the new history from restoration data. + _history.addAll(_serializableHistory.restoreEntriesForPage(null, this)); + for (final Page<dynamic> page in widget.pages) { + final _RouteEntry entry = _RouteEntry( + page.createRoute(context), + pageBased: true, + initialState: _RouteLifecycle.add, + ); + assert( + entry.route.settings == page, + 'The settings getter of a page-based Route must return a Page object. ' + 'Please set the settings to the Page in the Page.createRoute method.', + ); + _history.add(entry); + _history.addAll(_serializableHistory.restoreEntriesForPage(entry, this)); + } + + // If there was nothing to restore, we need to process the initial route. + if (!_serializableHistory.hasData) { + String? initialRoute = widget.initialRoute; + if (widget.pages.isEmpty) { + initialRoute = initialRoute ?? Navigator.defaultRouteName; + } + if (initialRoute != null) { + _history.addAll( + widget.onGenerateInitialRoutes( + this, + widget.initialRoute ?? Navigator.defaultRouteName, + ).map((Route<dynamic> route) => _RouteEntry( + route, + pageBased: false, + initialState: _RouteLifecycle.add, + restorationInformation: route.settings.name != null + ? _RestorationInformation.named( + name: route.settings.name!, + arguments: null, + restorationScopeId: _nextPagelessRestorationScopeId, + ) + : null, + ), + ), + ); + } + } + + assert( + _history.isNotEmpty, + 'All routes returned by onGenerateInitialRoutes are not restorable. ' + 'Please make sure that all routes returned by onGenerateInitialRoutes ' + 'have their RouteSettings defined with names that are defined in the ' + "app's routes table.", + ); + assert(!_debugLocked); + assert(() { _debugLocked = true; return true; }()); + _flushHistoryUpdates(); + assert(() { _debugLocked = false; return true; }()); + } + + @override + void didToggleBucket(RestorationBucket? oldBucket) { + super.didToggleBucket(oldBucket); + if (bucket != null) { + _serializableHistory.update(_history); + } else { + _serializableHistory.clear(); + } + } + @override + String? get restorationId => widget.restorationScopeId; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _updateHeroController(HeroControllerScope.maybeOf(context)); + for (final _RouteEntry entry in _history) { + entry.route.changedExternalState(); + } + } + + /// Dispose all lingering router entries immediately. + void _forcedDisposeAllRouteEntries() { + _entryWaitingForSubTreeDisposal.removeWhere((_RouteEntry entry) { + entry.forcedDispose(); + return true; + }); + while (_history.isNotEmpty) { + _disposeRouteEntry(_history.removeLast(), graceful: false); + } + } + + static void _disposeRouteEntry(_RouteEntry entry, {required bool graceful}) { + for (final OverlayEntry overlayEntry in entry.route.overlayEntries) { + overlayEntry.remove(); + } + if (graceful) { + entry.dispose(); + } else { + entry.forcedDispose(); + } + } + + void _updateHeroController(HeroController? newHeroController) { + if (_heroControllerFromScope != newHeroController) { + if (newHeroController != null) { + // Makes sure the same hero controller is not shared between two navigators. + assert(() { + // It is possible that the hero controller subscribes to an existing + // navigator. We are fine as long as that navigator gives up the hero + // controller at the end of the build. + if (newHeroController.navigator != null) { + final NavigatorState previousOwner = newHeroController.navigator!; + ServicesBinding.instance.addPostFrameCallback((Duration timestamp) { + // We only check if this navigator still owns the hero controller. + if (_heroControllerFromScope == newHeroController) { + final bool hasHeroControllerOwnerShip = _heroControllerFromScope!.navigator == this; + if (!hasHeroControllerOwnerShip || + previousOwner._heroControllerFromScope == newHeroController) { + final NavigatorState otherOwner = hasHeroControllerOwnerShip + ? previousOwner + : _heroControllerFromScope!.navigator!; + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError( + 'A HeroController can not be shared by multiple Navigators. ' + 'The Navigators that share the same HeroController are:\n' + '- $this\n' + '- $otherOwner\n' + 'Please create a HeroControllerScope for each Navigator or ' + 'use a HeroControllerScope.none to prevent subtree from ' + 'receiving a HeroController.', + ), + library: 'widget library', + stack: StackTrace.current, + ), + ); + } + } + }, debugLabel: 'Navigator.checkHeroControllerOwnership'); + } + return true; + }()); + NavigatorObserver._navigators[newHeroController] = this; + } + // Only unsubscribe the hero controller when it is currently subscribe to + // this navigator. + if (_heroControllerFromScope?.navigator == this) { + NavigatorObserver._navigators[_heroControllerFromScope!] = null; + } + _heroControllerFromScope = newHeroController; + _updateEffectiveObservers(); + } + } + + void _updateEffectiveObservers() { + if (_heroControllerFromScope != null) { + _effectiveObservers = widget.observers + <NavigatorObserver>[_heroControllerFromScope!]; + } else { + _effectiveObservers = widget.observers; + } + } + + @override + void didUpdateWidget(Navigator oldWidget) { + super.didUpdateWidget(oldWidget); + assert(() { + if (_usingPagesAPI) { + // This navigator uses page API. + if (widget.pages.isEmpty) { + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError( + 'The Navigator.pages must not be empty to use the ' + 'Navigator.pages API', + ), + library: 'widget library', + stack: StackTrace.current, + ), + ); + } else if (widget.onPopPage == null) { + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError( + 'The Navigator.onPopPage must be provided to use the ' + 'Navigator.pages API', + ), + library: 'widget library', + stack: StackTrace.current, + ), + ); + } + } + return true; + }()); + if (oldWidget.observers != widget.observers) { + for (final NavigatorObserver observer in oldWidget.observers) { + NavigatorObserver._navigators[observer] = null; + } + for (final NavigatorObserver observer in widget.observers) { + assert(observer.navigator == null); + NavigatorObserver._navigators[observer] = this; + } + _updateEffectiveObservers(); + } + if (oldWidget.pages != widget.pages && !restorePending) { + assert(() { + if (widget.pages.isEmpty) { + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError( + 'The Navigator.pages must not be empty to use the ' + 'Navigator.pages API', + ), + library: 'widget library', + stack: StackTrace.current, + ), + ); + } + return true; + }()); + _updatePages(); + } + + for (final _RouteEntry entry in _history) { + entry.route.changedExternalState(); + } + } + + void _debugCheckDuplicatedPageKeys() { + assert(() { + final Set<Key> keyReservation = <Key>{}; + for (final Page<dynamic> page in widget.pages) { + final LocalKey? key = page.key; + if (key != null) { + assert(!keyReservation.contains(key)); + keyReservation.add(key); + } + } + return true; + }()); + } + + @override + void deactivate() { + for (final NavigatorObserver observer in _effectiveObservers) { + NavigatorObserver._navigators[observer] = null; + } + super.deactivate(); + } + + @override + void activate() { + super.activate(); + for (final NavigatorObserver observer in _effectiveObservers) { + assert(observer.navigator == null); + NavigatorObserver._navigators[observer] = this; + } + } + + @override + void dispose() { + assert(!_debugLocked); + assert(() { + _debugLocked = true; + return true; + }()); + assert(() { + for (final NavigatorObserver observer in _effectiveObservers) { + assert(observer.navigator != this); + } + return true; + }()); + _updateHeroController(null); + focusNode.dispose(); + _forcedDisposeAllRouteEntries(); + _rawNextPagelessRestorationScopeId.dispose(); + _serializableHistory.dispose(); + userGestureInProgressNotifier.dispose(); + ServicesBinding.instance.accessibilityFocus.removeListener(_recordLastFocus); + _history.removeListener(_handleHistoryChanged); + _history.dispose(); + super.dispose(); + // don't unlock, so that the object becomes unusable + assert(_debugLocked); + } + + /// The overlay this navigator uses for its visual presentation. + OverlayState? get overlay => _overlayKey.currentState; + + Iterable<OverlayEntry> get _allRouteOverlayEntries { + return <OverlayEntry>[ + for (final _RouteEntry entry in _history) + ...entry.route.overlayEntries, + ]; + } + + String? _lastAnnouncedRouteName; + + bool _debugUpdatingPage = false; + void _updatePages() { + assert(() { + assert(!_debugUpdatingPage); + _debugCheckDuplicatedPageKeys(); + _debugUpdatingPage = true; + return true; + }()); + + // This attempts to diff the new pages list (widget.pages) with + // the old _RouteEntry(s) list (_history), and produces a new list of + // _RouteEntry(s) to be the new list of _history. This method roughly + // follows the same outline of RenderObjectElement.updateChildren. + // + // The cases it tries to optimize for are: + // - the old list is empty + // - All the pages in the new list can match the page-based routes in the old + // list, and their orders are the same. + // - there is an insertion or removal of one or more page-based route in + // only one place in the list + // If a page-based route with a key is in both lists, it will be synced. + // Page-based routes without keys might be synced but there is no guarantee. + + // The general approach is to sync the entire new list backwards, as follows: + // 1. Walk the lists from the bottom, syncing nodes, and record pageless routes, + // until you no longer have matching nodes. + // 2. Walk the lists from the top, without syncing nodes, until you no + // longer have matching nodes. We'll sync these nodes at the end. We + // don't sync them now because we want to sync all the nodes in order + // from beginning to end. + // At this point we narrowed the old and new lists to the point + // where the nodes no longer match. + // 3. Walk the narrowed part of the old list to get the list of + // keys. + // 4. Walk the narrowed part of the new list forwards: + // * Create a new _RouteEntry for non-keyed items and record them for + // transitionDelegate. + // * Sync keyed items with the source if it exists. + // 5. Walk the narrowed part of the old list again to records the + // _RouteEntry(s), as well as pageless routes, needed to be removed for + // transitionDelegate. + // 5. Walk the top of the list again, syncing the nodes and recording + // pageless routes. + // 6. Use transitionDelegate for explicit decisions on how _RouteEntry(s) + // transition in or off the screens. + // 7. Fill pageless routes back into the new history. + + bool needsExplicitDecision = false; + int newPagesBottom = 0; + int oldEntriesBottom = 0; + int newPagesTop = widget.pages.length - 1; + int oldEntriesTop = _history.length - 1; + + final List<_RouteEntry> newHistory = <_RouteEntry>[]; + final Map<_RouteEntry?, List<_RouteEntry>> pageRouteToPagelessRoutes = <_RouteEntry?, List<_RouteEntry>>{}; + + // Updates the bottom of the list. + _RouteEntry? previousOldPageRouteEntry; + while (oldEntriesBottom <= oldEntriesTop) { + final _RouteEntry oldEntry = _history[oldEntriesBottom]; + assert(oldEntry.currentState != _RouteLifecycle.disposed); + // Records pageless route. The bottom most pageless routes will be + // stored in key = null. + if (!oldEntry.pageBased) { + final List<_RouteEntry> pagelessRoutes = pageRouteToPagelessRoutes.putIfAbsent( + previousOldPageRouteEntry, + () => <_RouteEntry>[], + ); + pagelessRoutes.add(oldEntry); + oldEntriesBottom += 1; + continue; + } + if (newPagesBottom > newPagesTop) { + break; + } + final Page<dynamic> newPage = widget.pages[newPagesBottom]; + if (!oldEntry.canUpdateFrom(newPage)) { + break; + } + previousOldPageRouteEntry = oldEntry; + oldEntry.route._updateSettings(newPage); + newHistory.add(oldEntry); + newPagesBottom += 1; + oldEntriesBottom += 1; + } + + final List<_RouteEntry> unattachedPagelessRoutes=<_RouteEntry>[]; + // Scans the top of the list until we found a page-based route that cannot be + // updated. + while ((oldEntriesBottom <= oldEntriesTop) && (newPagesBottom <= newPagesTop)) { + final _RouteEntry oldEntry = _history[oldEntriesTop]; + assert(oldEntry.currentState != _RouteLifecycle.disposed); + if (!oldEntry.pageBased) { + unattachedPagelessRoutes.add(oldEntry); + oldEntriesTop -= 1; + continue; + } + final Page<dynamic> newPage = widget.pages[newPagesTop]; + if (!oldEntry.canUpdateFrom(newPage)) { + break; + } + + // We found the page for all the consecutive pageless routes below. Attach these + // pageless routes to the page. + if (unattachedPagelessRoutes.isNotEmpty) { + pageRouteToPagelessRoutes.putIfAbsent( + oldEntry, + () => List<_RouteEntry>.from(unattachedPagelessRoutes), + ); + unattachedPagelessRoutes.clear(); + } + + oldEntriesTop -= 1; + newPagesTop -= 1; + } + // Reverts the pageless routes that cannot be updated. + oldEntriesTop += unattachedPagelessRoutes.length; + + // Scans middle of the old entries and records the page key to old entry map. + int oldEntriesBottomToScan = oldEntriesBottom; + final Map<LocalKey, _RouteEntry> pageKeyToOldEntry = <LocalKey, _RouteEntry>{}; + // This set contains entries that are transitioning out but are still in + // the route stack. + final Set<_RouteEntry> phantomEntries = <_RouteEntry>{}; + while (oldEntriesBottomToScan <= oldEntriesTop) { + final _RouteEntry oldEntry = _history[oldEntriesBottomToScan]; + oldEntriesBottomToScan += 1; + assert( + oldEntry.currentState != _RouteLifecycle.disposed, + ); + // Pageless routes will be recorded when we update the middle of the old + // list. + if (!oldEntry.pageBased) { + continue; + } + + final Page<dynamic> page = oldEntry.route.settings as Page<dynamic>; + if (page.key == null) { + continue; + } + + if (!oldEntry.willBePresent) { + phantomEntries.add(oldEntry); + continue; + } + assert(!pageKeyToOldEntry.containsKey(page.key)); + pageKeyToOldEntry[page.key!] = oldEntry; + } + + // Updates the middle of the list. + while (newPagesBottom <= newPagesTop) { + final Page<dynamic> nextPage = widget.pages[newPagesBottom]; + newPagesBottom += 1; + if ( + nextPage.key == null || + !pageKeyToOldEntry.containsKey(nextPage.key) || + !pageKeyToOldEntry[nextPage.key]!.canUpdateFrom(nextPage) + ) { + // There is no matching key in the old history, we need to create a new + // route and wait for the transition delegate to decide how to add + // it into the history. + final _RouteEntry newEntry = _RouteEntry( + nextPage.createRoute(context), + pageBased: true, + initialState: _RouteLifecycle.staging, + ); + needsExplicitDecision = true; + assert( + newEntry.route.settings == nextPage, + 'The settings getter of a page-based Route must return a Page object. ' + 'Please set the settings to the Page in the Page.createRoute method.', + ); + newHistory.add(newEntry); + } else { + // Removes the key from pageKeyToOldEntry to indicate it is taken. + final _RouteEntry matchingEntry = pageKeyToOldEntry.remove(nextPage.key)!; + assert(matchingEntry.canUpdateFrom(nextPage)); + matchingEntry.route._updateSettings(nextPage); + newHistory.add(matchingEntry); + } + } + + // Any remaining old routes that do not have a match will need to be removed. + final Map<RouteTransitionRecord?, RouteTransitionRecord> locationToExitingPageRoute = <RouteTransitionRecord?, RouteTransitionRecord>{}; + while (oldEntriesBottom <= oldEntriesTop) { + final _RouteEntry potentialEntryToRemove = _history[oldEntriesBottom]; + oldEntriesBottom += 1; + + if (!potentialEntryToRemove.pageBased) { + assert(previousOldPageRouteEntry != null); + final List<_RouteEntry> pagelessRoutes = pageRouteToPagelessRoutes + .putIfAbsent( + previousOldPageRouteEntry, + () => <_RouteEntry>[], + ); + pagelessRoutes.add(potentialEntryToRemove); + if (previousOldPageRouteEntry!.isWaitingForExitingDecision && potentialEntryToRemove.willBePresent) { + potentialEntryToRemove.markNeedsExitingDecision(); + } + continue; + } + + final Page<dynamic> potentialPageToRemove = potentialEntryToRemove.route.settings as Page<dynamic>; + // Marks for transition delegate to remove if this old page does not have + // a key, was not taken during updating the middle of new page, or is + // already transitioning out. + if (potentialPageToRemove.key == null || + pageKeyToOldEntry.containsKey(potentialPageToRemove.key) || + phantomEntries.contains(potentialEntryToRemove)) { + locationToExitingPageRoute[previousOldPageRouteEntry] = potentialEntryToRemove; + // We only need a decision if it has not already been popped. + if (potentialEntryToRemove.willBePresent) { + potentialEntryToRemove.markNeedsExitingDecision(); + } + } + previousOldPageRouteEntry = potentialEntryToRemove; + } + + // We've scanned the whole list. + assert(oldEntriesBottom == oldEntriesTop + 1); + assert(newPagesBottom == newPagesTop + 1); + newPagesTop = widget.pages.length - 1; + oldEntriesTop = _history.length - 1; + // Verifies we either reach the bottom or the oldEntriesBottom must be updatable + // by newPagesBottom. + assert(() { + if (oldEntriesBottom <= oldEntriesTop) { + return newPagesBottom <= newPagesTop && + _history[oldEntriesBottom].pageBased && + _history[oldEntriesBottom].canUpdateFrom(widget.pages[newPagesBottom]); + } else { + return newPagesBottom > newPagesTop; + } + }()); + + // Updates the top of the list. + while ((oldEntriesBottom <= oldEntriesTop) && (newPagesBottom <= newPagesTop)) { + final _RouteEntry oldEntry = _history[oldEntriesBottom]; + assert(oldEntry.currentState != _RouteLifecycle.disposed); + if (!oldEntry.pageBased) { + assert(previousOldPageRouteEntry != null); + final List<_RouteEntry> pagelessRoutes = pageRouteToPagelessRoutes + .putIfAbsent( + previousOldPageRouteEntry, + () => <_RouteEntry>[], + ); + pagelessRoutes.add(oldEntry); + continue; + } + previousOldPageRouteEntry = oldEntry; + final Page<dynamic> newPage = widget.pages[newPagesBottom]; + assert(oldEntry.canUpdateFrom(newPage)); + oldEntry.route._updateSettings(newPage); + newHistory.add(oldEntry); + oldEntriesBottom += 1; + newPagesBottom += 1; + } + + // Finally, uses transition delegate to make explicit decision if needed. + needsExplicitDecision = needsExplicitDecision || locationToExitingPageRoute.isNotEmpty; + Iterable<_RouteEntry> results = newHistory; + if (needsExplicitDecision) { + results = widget.transitionDelegate._transition( + newPageRouteHistory: newHistory, + locationToExitingPageRoute: locationToExitingPageRoute, + pageRouteToPagelessRoutes: pageRouteToPagelessRoutes, + ).cast<_RouteEntry>(); + } + _history.clear(); + // Adds the leading pageless routes if there is any. + if (pageRouteToPagelessRoutes.containsKey(null)) { + _history.addAll(pageRouteToPagelessRoutes[null]!); + } + for (final _RouteEntry result in results) { + _history.add(result); + if (pageRouteToPagelessRoutes.containsKey(result)) { + _history.addAll(pageRouteToPagelessRoutes[result]!); + } + } + assert(() {_debugUpdatingPage = false; return true;}()); + assert(() { _debugLocked = true; return true; }()); + _flushHistoryUpdates(); + assert(() { _debugLocked = false; return true; }()); + } + + bool _flushingHistory = false; + + void _flushHistoryUpdates({bool rearrangeOverlay = true}) { + assert(_debugLocked && !_debugUpdatingPage); + _flushingHistory = true; + // Clean up the list, sending updates to the routes that changed. Notably, + // we don't send the didChangePrevious/didChangeNext updates to those that + // did not change at this point, because we're not yet sure exactly what the + // routes will be at the end of the day (some might get disposed). + int index = _history.length - 1; + _RouteEntry? next; + _RouteEntry? entry = _history[index]; + _RouteEntry? previous = index > 0 ? _history[index - 1] : null; + bool canRemoveOrAdd = false; // Whether there is a fully opaque route on top to silently remove or add route underneath. + Route<dynamic>? poppedRoute; // The route that should trigger didPopNext on the top active route. + bool seenTopActiveRoute = false; // Whether we've seen the route that would get didPopNext. + final List<_RouteEntry> toBeDisposed = <_RouteEntry>[]; + while (index >= 0) { + switch (entry!.currentState) { + case _RouteLifecycle.add: + assert(rearrangeOverlay); + entry.handleAdd( + navigator: this, + previousPresent: _getRouteBefore(index - 1, _RouteEntry.isPresentPredicate)?.route, + ); + assert(entry.currentState == _RouteLifecycle.adding); + continue; + case _RouteLifecycle.adding: + if (canRemoveOrAdd || next == null) { + entry.didAdd( + navigator: this, + isNewFirst: next == null, + ); + assert(entry.currentState == _RouteLifecycle.idle); + continue; + } + case _RouteLifecycle.push: + case _RouteLifecycle.pushReplace: + case _RouteLifecycle.replace: + assert(rearrangeOverlay); + entry.handlePush( + navigator: this, + previous: previous?.route, + previousPresent: _getRouteBefore(index - 1, _RouteEntry.isPresentPredicate)?.route, + isNewFirst: next == null, + ); + assert(entry.currentState != _RouteLifecycle.push); + assert(entry.currentState != _RouteLifecycle.pushReplace); + assert(entry.currentState != _RouteLifecycle.replace); + if (entry.currentState == _RouteLifecycle.idle) { + continue; + } + case _RouteLifecycle.pushing: // Will exit this state when animation completes. + if (!seenTopActiveRoute && poppedRoute != null) { + entry.handleDidPopNext(poppedRoute); + } + seenTopActiveRoute = true; + case _RouteLifecycle.idle: + if (!seenTopActiveRoute && poppedRoute != null) { + entry.handleDidPopNext(poppedRoute); + } + seenTopActiveRoute = true; + // This route is idle, so we are allowed to remove subsequent (earlier) + // routes that are waiting to be removed silently: + canRemoveOrAdd = true; + case _RouteLifecycle.pop: + if (!entry.handlePop( + navigator: this, + previousPresent: _getRouteBefore(index, _RouteEntry.willBePresentPredicate)?.route)){ + assert(entry.currentState == _RouteLifecycle.idle); + continue; + } + if (!seenTopActiveRoute) { + if (poppedRoute != null) { + entry.handleDidPopNext(poppedRoute); + } + poppedRoute = entry.route; + } + _observedRouteDeletions.add( + _NavigatorPopObservation(entry.route, _getRouteBefore(index, _RouteEntry.willBePresentPredicate)?.route), + ); + if (entry.currentState == _RouteLifecycle.dispose) { + // The pop finished synchronously. This can happen if transition + // duration is zero. + continue; + } + assert(entry.currentState == _RouteLifecycle.popping); + canRemoveOrAdd = true; + case _RouteLifecycle.popping: + // Will exit this state when animation completes. + break; + case _RouteLifecycle.complete: + entry.handleComplete(); + assert(entry.currentState == _RouteLifecycle.remove); + continue; + case _RouteLifecycle.remove: + if (!seenTopActiveRoute) { + if (poppedRoute != null) { + entry.route.didPopNext(poppedRoute); + } + poppedRoute = null; + } + entry.handleRemoval( + navigator: this, + previousPresent: _getRouteBefore(index, _RouteEntry.willBePresentPredicate)?.route, + ); + assert(entry.currentState == _RouteLifecycle.removing); + continue; + case _RouteLifecycle.removing: + if (!canRemoveOrAdd && next != null) { + // We aren't allowed to remove this route yet. + break; + } + entry.currentState = _RouteLifecycle.dispose; + continue; + case _RouteLifecycle.dispose: + // Delay disposal until didChangeNext/didChangePrevious have been sent. + toBeDisposed.add(_history.removeAt(index)); + entry = next; + case _RouteLifecycle.disposing: + case _RouteLifecycle.disposed: + case _RouteLifecycle.staging: + assert(false); + } + index -= 1; + next = entry; + entry = previous; + previous = index > 0 ? _history[index - 1] : null; + } + // Informs navigator observers about route changes. + _flushObserverNotifications(); + + // Now that the list is clean, send the didChangeNext/didChangePrevious + // notifications. + _flushRouteAnnouncement(); + + // Announce route name changes. + if (widget.reportsRouteUpdateToEngine) { + final _RouteEntry? lastEntry = _lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate); + final String? routeName = lastEntry?.route.settings.name; + if (routeName != null && routeName != _lastAnnouncedRouteName) { + SystemNavigator.routeInformationUpdated(uri: Uri.parse(routeName)); + _lastAnnouncedRouteName = routeName; + } + } + + // Lastly, removes the overlay entries of all marked entries and disposes + // them. + for (final _RouteEntry entry in toBeDisposed) { + _disposeRouteEntry(entry, graceful: true); + } + if (rearrangeOverlay) { + overlay?.rearrange(_allRouteOverlayEntries); + } + if (bucket != null) { + _serializableHistory.update(_history); + } + _flushingHistory = false; + } + + void _flushObserverNotifications() { + if (_effectiveObservers.isEmpty) { + _observedRouteDeletions.clear(); + _observedRouteAdditions.clear(); + return; + } + while (_observedRouteAdditions.isNotEmpty) { + final _NavigatorObservation observation = _observedRouteAdditions.removeLast(); + _effectiveObservers.forEach(observation.notify); + } + + while (_observedRouteDeletions.isNotEmpty) { + final _NavigatorObservation observation = _observedRouteDeletions.removeFirst(); + _effectiveObservers.forEach(observation.notify); + } + } + + void _flushRouteAnnouncement() { + int index = _history.length - 1; + while (index >= 0) { + final _RouteEntry entry = _history[index]; + if (!entry.suitableForAnnouncement) { + index -= 1; + continue; + } + final _RouteEntry? next = _getRouteAfter(index + 1, _RouteEntry.suitableForTransitionAnimationPredicate); + + if (next?.route != entry.lastAnnouncedNextRoute) { + if (entry.shouldAnnounceChangeToNext(next?.route)) { + entry.route.didChangeNext(next?.route); + } + entry.lastAnnouncedNextRoute = next?.route; + } + final _RouteEntry? previous = _getRouteBefore(index - 1, _RouteEntry.suitableForTransitionAnimationPredicate); + if (previous?.route != entry.lastAnnouncedPreviousRoute) { + entry.route.didChangePrevious(previous?.route); + entry.lastAnnouncedPreviousRoute = previous?.route; + } + index -= 1; + } + } + + _RouteEntry? _getRouteBefore(int index, _RouteEntryPredicate predicate) { + index = _getIndexBefore(index, predicate); + return index >= 0 ? _history[index] : null; + } + + int _getIndexBefore(int index, _RouteEntryPredicate predicate) { + while (index >= 0 && !predicate(_history[index])) { + index -= 1; + } + return index; + } + + _RouteEntry? _getRouteAfter(int index, _RouteEntryPredicate predicate) { + while (index < _history.length && !predicate(_history[index])) { + index += 1; + } + return index < _history.length ? _history[index] : null; + } + + Route<T?>? _routeNamed<T>(String name, { required Object? arguments, bool allowNull = false }) { + assert(!_debugLocked); + if (allowNull && widget.onGenerateRoute == null) { + return null; + } + assert(() { + if (widget.onGenerateRoute == null) { + throw FlutterError( + 'Navigator.onGenerateRoute was null, but the route named "$name" was referenced.\n' + 'To use the Navigator API with named routes (pushNamed, pushReplacementNamed, or ' + 'pushNamedAndRemoveUntil), the Navigator must be provided with an ' + 'onGenerateRoute handler.\n' + 'The Navigator was:\n' + ' $this', + ); + } + return true; + }()); + final RouteSettings settings = RouteSettings( + name: name, + arguments: arguments, + ); + Route<T?>? route = widget.onGenerateRoute!(settings) as Route<T?>?; + if (route == null && !allowNull) { + assert(() { + if (widget.onUnknownRoute == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Navigator.onGenerateRoute returned null when requested to build route "$name".'), + ErrorDescription( + 'The onGenerateRoute callback must never return null, unless an onUnknownRoute ' + 'callback is provided as well.', + ), + DiagnosticsProperty<NavigatorState>('The Navigator was', this, style: DiagnosticsTreeStyle.errorProperty), + ]); + } + return true; + }()); + route = widget.onUnknownRoute!(settings) as Route<T?>?; + assert(() { + if (route == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Navigator.onUnknownRoute returned null when requested to build route "$name".'), + ErrorDescription('The onUnknownRoute callback must never return null.'), + DiagnosticsProperty<NavigatorState>('The Navigator was', this, style: DiagnosticsTreeStyle.errorProperty), + ]); + } + return true; + }()); + } + assert(route != null || allowNull); + return route; + } + + /// Push a named route onto the navigator. + /// + /// {@macro flutter.widgets.navigator.pushNamed} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@macro flutter.widgets.Navigator.pushNamed} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _aaronBurrSir() { + /// navigator.pushNamed('/nyc/1776'); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePushNamed], which pushes a route that can be restored + /// during state restoration. + @optionalTypeArgs + Future<T?> pushNamed<T extends Object?>( + String routeName, { + Object? arguments, + }) { + return push<T?>(_routeNamed<T>(routeName, arguments: arguments)!); + } + + /// Push a named route onto the navigator. + /// + /// {@macro flutter.widgets.navigator.restorablePushNamed} + /// + /// {@macro flutter.widgets.navigator.pushNamed} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.arguments} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _openDetails() { + /// navigator.restorablePushNamed('/nyc/1776'); + /// } + /// ``` + /// {@end-tool} + @optionalTypeArgs + String restorablePushNamed<T extends Object?>( + String routeName, { + Object? arguments, + }) { + assert(debugIsSerializableForRestoration(arguments), 'The arguments object must be serializable via the StandardMessageCodec.'); + final _RouteEntry entry = _RestorationInformation.named( + name: routeName, + arguments: arguments, + restorationScopeId: _nextPagelessRestorationScopeId, + ).toRouteEntry(this, initialState: _RouteLifecycle.push); + _pushEntry(entry); + return entry.restorationId!; + } + + /// Replace the current route of the navigator by pushing the route named + /// [routeName] and then disposing the previous route once the new route has + /// finished animating in. + /// + /// {@macro flutter.widgets.navigator.pushReplacementNamed} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@macro flutter.widgets.Navigator.pushNamed} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _startBike() { + /// navigator.pushReplacementNamed('/jouett/1781'); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePushReplacementNamed], which pushes a replacement route that + /// can be restored during state restoration. + @optionalTypeArgs + Future<T?> pushReplacementNamed<T extends Object?, TO extends Object?>( + String routeName, { + TO? result, + Object? arguments, + }) { + return pushReplacement<T?, TO>(_routeNamed<T>(routeName, arguments: arguments)!, result: result); + } + + /// Replace the current route of the navigator by pushing the route named + /// [routeName] and then disposing the previous route once the new route has + /// finished animating in. + /// + /// {@macro flutter.widgets.navigator.restorablePushReplacementNamed} + /// + /// {@macro flutter.widgets.navigator.pushReplacementNamed} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.arguments} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _startCar() { + /// navigator.restorablePushReplacementNamed('/jouett/1781'); + /// } + /// ``` + /// {@end-tool} + @optionalTypeArgs + String restorablePushReplacementNamed<T extends Object?, TO extends Object?>( + String routeName, { + TO? result, + Object? arguments, + }) { + assert(debugIsSerializableForRestoration(arguments), 'The arguments object must be serializable via the StandardMessageCodec.'); + final _RouteEntry entry = _RestorationInformation.named( + name: routeName, + arguments: arguments, + restorationScopeId: _nextPagelessRestorationScopeId, + ).toRouteEntry(this, initialState: _RouteLifecycle.pushReplace); + _pushReplacementEntry(entry, result); + return entry.restorationId!; + } + + /// Pop the current route off the navigator and push a named route in its + /// place. + /// + /// {@macro flutter.widgets.navigator.popAndPushNamed} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@macro flutter.widgets.Navigator.pushNamed} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _begin() { + /// navigator.popAndPushNamed('/nyc/1776'); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePopAndPushNamed], which pushes a new route that can be + /// restored during state restoration. + @optionalTypeArgs + Future<T?> popAndPushNamed<T extends Object?, TO extends Object?>( + String routeName, { + TO? result, + Object? arguments, + }) { + pop<TO>(result); + return pushNamed<T>(routeName, arguments: arguments); + } + + /// Pop the current route off the navigator and push a named route in its + /// place. + /// + /// {@macro flutter.widgets.navigator.restorablePopAndPushNamed} + /// + /// {@macro flutter.widgets.navigator.popAndPushNamed} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.arguments} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _end() { + /// navigator.restorablePopAndPushNamed('/nyc/1776'); + /// } + /// ``` + /// {@end-tool} + @optionalTypeArgs + String restorablePopAndPushNamed<T extends Object?, TO extends Object?>( + String routeName, { + TO? result, + Object? arguments, + }) { + pop<TO>(result); + return restorablePushNamed(routeName, arguments: arguments); + } + + /// Push the route with the given name onto the navigator, and then remove all + /// the previous routes until the `predicate` returns true. + /// + /// {@macro flutter.widgets.navigator.pushNamedAndRemoveUntil} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@macro flutter.widgets.Navigator.pushNamed} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _handleOpenCalendar() { + /// navigator.pushNamedAndRemoveUntil('/calendar', ModalRoute.withName('/')); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePushNamedAndRemoveUntil], which pushes a new route that can + /// be restored during state restoration. + @optionalTypeArgs + Future<T?> pushNamedAndRemoveUntil<T extends Object?>( + String newRouteName, + RoutePredicate predicate, { + Object? arguments, + }) { + return pushAndRemoveUntil<T?>(_routeNamed<T>(newRouteName, arguments: arguments)!, predicate); + } + + /// Push the route with the given name onto the navigator, and then remove all + /// the previous routes until the `predicate` returns true. + /// + /// {@macro flutter.widgets.navigator.restorablePushNamedAndRemoveUntil} + /// + /// {@macro flutter.widgets.navigator.pushNamedAndRemoveUntil} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.arguments} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _openCalendar() { + /// navigator.restorablePushNamedAndRemoveUntil('/calendar', ModalRoute.withName('/')); + /// } + /// ``` + /// {@end-tool} + @optionalTypeArgs + String restorablePushNamedAndRemoveUntil<T extends Object?>( + String newRouteName, + RoutePredicate predicate, { + Object? arguments, + }) { + assert(debugIsSerializableForRestoration(arguments), 'The arguments object must be serializable via the StandardMessageCodec.'); + final _RouteEntry entry = _RestorationInformation.named( + name: newRouteName, + arguments: arguments, + restorationScopeId: _nextPagelessRestorationScopeId, + ).toRouteEntry(this, initialState: _RouteLifecycle.push); + _pushEntryAndRemoveUntil(entry, predicate); + return entry.restorationId!; + } + + /// Push the given route onto the navigator. + /// + /// {@macro flutter.widgets.navigator.push} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _openPage() { + /// navigator.push<void>( + /// MaterialPageRoute<void>( + /// builder: (BuildContext context) => const MyPage(), + /// ), + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePush], which pushes a route that can be restored during + /// state restoration. + @optionalTypeArgs + Future<T?> push<T extends Object?>(Route<T> route) { + _pushEntry(_RouteEntry(route, pageBased: false, initialState: _RouteLifecycle.push)); + return route.popped; + } + + bool _debugIsStaticCallback(Function callback) { + bool result = false; + assert(() { + // TODO(goderbauer): remove the kIsWeb check when https://github.com/flutter/flutter/issues/33615 is resolved. + result = kIsWeb || ui.PluginUtilities.getCallbackHandle(callback) != null; + return true; + }()); + return result; + } + + /// Push a new route onto the navigator. + /// + /// {@macro flutter.widgets.navigator.restorablePush} + /// + /// {@macro flutter.widgets.navigator.push} + /// + /// {@macro flutter.widgets.Navigator.restorablePush} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool dartpad} + /// Typical usage is as follows: + /// + /// ** See code in examples/api/lib/widgets/navigator/navigator_state.restorable_push.0.dart ** + /// {@end-tool} + @optionalTypeArgs + String restorablePush<T extends Object?>(RestorableRouteBuilder<T> routeBuilder, {Object? arguments}) { + assert(_debugIsStaticCallback(routeBuilder), 'The provided routeBuilder must be a static function.'); + assert(debugIsSerializableForRestoration(arguments), 'The arguments object must be serializable via the StandardMessageCodec.'); + final _RouteEntry entry = _RestorationInformation.anonymous( + routeBuilder: routeBuilder, + arguments: arguments, + restorationScopeId: _nextPagelessRestorationScopeId, + ).toRouteEntry(this, initialState: _RouteLifecycle.push); + _pushEntry(entry); + return entry.restorationId!; + } + + void _pushEntry(_RouteEntry entry) { + assert(!_debugLocked); + assert(() { + _debugLocked = true; + return true; + }()); + assert(entry.route._navigator == null); + assert(entry.currentState == _RouteLifecycle.push); + _history.add(entry); + _flushHistoryUpdates(); + assert(() { + _debugLocked = false; + return true; + }()); + _afterNavigation(entry.route); + } + + void _afterNavigation(Route<dynamic>? route) { + if (!kReleaseMode) { + // Among other uses, performance tools use this event to ensure that perf + // stats reflect the time interval since the last navigation event + // occurred, ensuring that stats only reflect the current page. + + Map<String, dynamic>? routeJsonable; + if (route != null) { + routeJsonable = <String, dynamic>{}; + + final String description; + if (route is TransitionRoute<dynamic>) { + final TransitionRoute<dynamic> transitionRoute = route; + description = transitionRoute.debugLabel; + } else { + description = '$route'; + } + routeJsonable['description'] = description; + + final RouteSettings settings = route.settings; + final Map<String, dynamic> settingsJsonable = <String, dynamic> { + 'name': settings.name, + }; + if (settings.arguments != null) { + settingsJsonable['arguments'] = jsonEncode( + settings.arguments, + toEncodable: (Object? object) => '$object', + ); + } + routeJsonable['settings'] = settingsJsonable; + } + + developer.postEvent('Flutter.Navigation', <String, dynamic>{ + 'route': routeJsonable, + }); + } + _cancelActivePointers(); + } + + /// Replace the current route of the navigator by pushing the given route and + /// then disposing the previous route once the new route has finished + /// animating in. + /// + /// {@macro flutter.widgets.navigator.pushReplacement} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _doOpenPage() { + /// navigator.pushReplacement<void, void>( + /// MaterialPageRoute<void>( + /// builder: (BuildContext context) => const MyHomePage(), + /// ), + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [restorablePushReplacement], which pushes a replacement route that can + /// be restored during state restoration. + @optionalTypeArgs + Future<T?> pushReplacement<T extends Object?, TO extends Object?>(Route<T> newRoute, { TO? result }) { + assert(newRoute._navigator == null); + _pushReplacementEntry(_RouteEntry(newRoute, pageBased: false, initialState: _RouteLifecycle.pushReplace), result); + return newRoute.popped; + } + + /// Replace the current route of the navigator by pushing a new route and + /// then disposing the previous route once the new route has finished + /// animating in. + /// + /// {@macro flutter.widgets.navigator.restorablePushReplacement} + /// + /// {@macro flutter.widgets.navigator.pushReplacement} + /// + /// {@macro flutter.widgets.Navigator.restorablePush} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool dartpad} + /// Typical usage is as follows: + /// + /// ** See code in examples/api/lib/widgets/navigator/navigator_state.restorable_push_replacement.0.dart ** + /// {@end-tool} + @optionalTypeArgs + String restorablePushReplacement<T extends Object?, TO extends Object?>(RestorableRouteBuilder<T> routeBuilder, { TO? result, Object? arguments }) { + assert(_debugIsStaticCallback(routeBuilder), 'The provided routeBuilder must be a static function.'); + assert(debugIsSerializableForRestoration(arguments), 'The arguments object must be serializable via the StandardMessageCodec.'); + final _RouteEntry entry = _RestorationInformation.anonymous( + routeBuilder: routeBuilder, + arguments: arguments, + restorationScopeId: _nextPagelessRestorationScopeId, + ).toRouteEntry(this, initialState: _RouteLifecycle.pushReplace); + _pushReplacementEntry(entry, result); + return entry.restorationId!; + } + + void _pushReplacementEntry<TO extends Object?>(_RouteEntry entry, TO? result) { + assert(!_debugLocked); + assert(() { + _debugLocked = true; + return true; + }()); + assert(entry.route._navigator == null); + assert(_history.isNotEmpty); + assert(_history.any(_RouteEntry.isPresentPredicate), 'Navigator has no active routes to replace.'); + assert(entry.currentState == _RouteLifecycle.pushReplace); + _history.lastWhere(_RouteEntry.isPresentPredicate).complete(result, isReplaced: true); + _history.add(entry); + _flushHistoryUpdates(); + assert(() { + _debugLocked = false; + return true; + }()); + _afterNavigation(entry.route); + } + + /// Push the given route onto the navigator, and then remove all the previous + /// routes until the `predicate` returns true. + /// + /// {@macro flutter.widgets.navigator.pushAndRemoveUntil} + /// + /// {@macro flutter.widgets.navigator.pushNamed.returnValue} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _resetAndOpenPage() { + /// navigator.pushAndRemoveUntil<void>( + /// MaterialPageRoute<void>(builder: (BuildContext context) => const MyHomePage()), + /// ModalRoute.withName('/'), + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// + /// See also: + /// + /// * [restorablePushAndRemoveUntil], which pushes a route that can be + /// restored during state restoration. + @optionalTypeArgs + Future<T?> pushAndRemoveUntil<T extends Object?>(Route<T> newRoute, RoutePredicate predicate) { + assert(newRoute._navigator == null); + assert(newRoute.overlayEntries.isEmpty); + _pushEntryAndRemoveUntil(_RouteEntry(newRoute, pageBased: false, initialState: _RouteLifecycle.push), predicate); + return newRoute.popped; + } + + /// Push a new route onto the navigator, and then remove all the previous + /// routes until the `predicate` returns true. + /// + /// {@macro flutter.widgets.navigator.restorablePushAndRemoveUntil} + /// + /// {@macro flutter.widgets.navigator.pushAndRemoveUntil} + /// + /// {@macro flutter.widgets.Navigator.restorablePush} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + /// + /// {@tool dartpad} + /// Typical usage is as follows: + /// + /// ** See code in examples/api/lib/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart ** + /// {@end-tool} + @optionalTypeArgs + String restorablePushAndRemoveUntil<T extends Object?>(RestorableRouteBuilder<T> newRouteBuilder, RoutePredicate predicate, {Object? arguments}) { + assert(_debugIsStaticCallback(newRouteBuilder), 'The provided routeBuilder must be a static function.'); + assert(debugIsSerializableForRestoration(arguments), 'The arguments object must be serializable via the StandardMessageCodec.'); + final _RouteEntry entry = _RestorationInformation.anonymous( + routeBuilder: newRouteBuilder, + arguments: arguments, + restorationScopeId: _nextPagelessRestorationScopeId, + ).toRouteEntry(this, initialState: _RouteLifecycle.push); + _pushEntryAndRemoveUntil(entry, predicate); + return entry.restorationId!; + } + + void _pushEntryAndRemoveUntil(_RouteEntry entry, RoutePredicate predicate) { + assert(!_debugLocked); + assert(() { + _debugLocked = true; + return true; + }()); + assert(entry.route._navigator == null); + assert(entry.route.overlayEntries.isEmpty); + assert(entry.currentState == _RouteLifecycle.push); + int index = _history.length - 1; + _history.add(entry); + while (index >= 0 && !predicate(_history[index].route)) { + if (_history[index].isPresent) { + _history[index].remove(); + } + index -= 1; + } + _flushHistoryUpdates(); + + assert(() { + _debugLocked = false; + return true; + }()); + _afterNavigation(entry.route); + } + + /// Replaces a route on the navigator with a new route. + /// + /// {@macro flutter.widgets.navigator.replace} + /// + /// See also: + /// + /// * [replaceRouteBelow], which is the same but identifies the route to be + /// removed by reference to the route above it, rather than directly. + /// * [restorableReplace], which adds a replacement route that can be + /// restored during state restoration. + @optionalTypeArgs + void replace<T extends Object?>({ required Route<dynamic> oldRoute, required Route<T> newRoute }) { + assert(!_debugLocked); + assert(oldRoute._navigator == this); + _replaceEntry(_RouteEntry(newRoute, pageBased: false, initialState: _RouteLifecycle.replace), oldRoute); + } + + /// Replaces a route on the navigator with a new route. + /// + /// {@macro flutter.widgets.navigator.restorableReplace} + /// + /// {@macro flutter.widgets.navigator.replace} + /// + /// {@macro flutter.widgets.Navigator.restorablePush} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + @optionalTypeArgs + String restorableReplace<T extends Object?>({ required Route<dynamic> oldRoute, required RestorableRouteBuilder<T> newRouteBuilder, Object? arguments }) { + assert(oldRoute._navigator == this); + assert(_debugIsStaticCallback(newRouteBuilder), 'The provided routeBuilder must be a static function.'); + assert(debugIsSerializableForRestoration(arguments), 'The arguments object must be serializable via the StandardMessageCodec.'); + final _RouteEntry entry = _RestorationInformation.anonymous( + routeBuilder: newRouteBuilder, + arguments: arguments, + restorationScopeId: _nextPagelessRestorationScopeId, + ).toRouteEntry(this, initialState: _RouteLifecycle.replace); + _replaceEntry(entry, oldRoute); + return entry.restorationId!; + } + + void _replaceEntry(_RouteEntry entry, Route<dynamic> oldRoute) { + assert(!_debugLocked); + if (oldRoute == entry.route) { + return; + } + assert(() { + _debugLocked = true; + return true; + }()); + assert(entry.currentState == _RouteLifecycle.replace); + assert(entry.route._navigator == null); + final int index = _history.indexWhere(_RouteEntry.isRoutePredicate(oldRoute)); + assert(index >= 0, 'This Navigator does not contain the specified oldRoute.'); + assert(_history[index].isPresent, 'The specified oldRoute has already been removed from the Navigator.'); + final bool wasCurrent = oldRoute.isCurrent; + _history.insert(index + 1, entry); + _history[index].remove(isReplaced: true); + _flushHistoryUpdates(); + assert(() { + _debugLocked = false; + return true; + }()); + if (wasCurrent) { + _afterNavigation(entry.route); + } + } + + /// Replaces a route on the navigator with a new route. The route to be + /// replaced is the one below the given `anchorRoute`. + /// + /// {@macro flutter.widgets.navigator.replaceRouteBelow} + /// + /// See also: + /// + /// * [replace], which is the same but identifies the route to be removed + /// directly. + /// * [restorableReplaceRouteBelow], which adds a replacement route that can + /// be restored during state restoration. + @optionalTypeArgs + void replaceRouteBelow<T extends Object?>({ required Route<dynamic> anchorRoute, required Route<T> newRoute }) { + assert(newRoute._navigator == null); + assert(anchorRoute._navigator == this); + _replaceEntryBelow(_RouteEntry(newRoute, pageBased: false, initialState: _RouteLifecycle.replace), anchorRoute); + } + + /// Replaces a route on the navigator with a new route. The route to be + /// replaced is the one below the given `anchorRoute`. + /// + /// {@macro flutter.widgets.navigator.restorableReplaceRouteBelow} + /// + /// {@macro flutter.widgets.navigator.replaceRouteBelow} + /// + /// {@macro flutter.widgets.Navigator.restorablePush} + /// + /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} + @optionalTypeArgs + String restorableReplaceRouteBelow<T extends Object?>({ required Route<dynamic> anchorRoute, required RestorableRouteBuilder<T> newRouteBuilder, Object? arguments }) { + assert(anchorRoute._navigator == this); + assert(_debugIsStaticCallback(newRouteBuilder), 'The provided routeBuilder must be a static function.'); + assert(debugIsSerializableForRestoration(arguments), 'The arguments object must be serializable via the StandardMessageCodec.'); + final _RouteEntry entry = _RestorationInformation.anonymous( + routeBuilder: newRouteBuilder, + arguments: arguments, + restorationScopeId: _nextPagelessRestorationScopeId, + ).toRouteEntry(this, initialState: _RouteLifecycle.replace); + _replaceEntryBelow(entry, anchorRoute); + return entry.restorationId!; + } + + void _replaceEntryBelow(_RouteEntry entry, Route<dynamic> anchorRoute) { + assert(!_debugLocked); + assert(() { _debugLocked = true; return true; }()); + final int anchorIndex = _history.indexWhere(_RouteEntry.isRoutePredicate(anchorRoute)); + assert(anchorIndex >= 0, 'This Navigator does not contain the specified anchorRoute.'); + assert(_history[anchorIndex].isPresent, 'The specified anchorRoute has already been removed from the Navigator.'); + int index = anchorIndex - 1; + while (index >= 0) { + if (_history[index].isPresent) { + break; + } + index -= 1; + } + assert(index >= 0, 'There are no routes below the specified anchorRoute.'); + _history.insert(index + 1, entry); + _history[index].remove(isReplaced: true); + _flushHistoryUpdates(); + assert(() { _debugLocked = false; return true; }()); + } + + /// Whether the navigator can be popped. + /// + /// {@macro flutter.widgets.navigator.canPop} + /// + /// See also: + /// + /// * [Route.isFirst], which returns true for routes for which [canPop] + /// returns false. + bool canPop() { + final Iterator<_RouteEntry> iterator = _history.where(_RouteEntry.isPresentPredicate).iterator; + if (!iterator.moveNext()) { + // We have no active routes, so we can't pop. + return false; + } + if (iterator.current.route.willHandlePopInternally) { + // The first route can handle pops itself, so we can pop. + return true; + } + if (!iterator.moveNext()) { + // There's only one route, so we can't pop. + return false; + } + return true; // there's at least two routes, so we can pop + } + + /// Consults the current route's [Route.popDisposition] method, and acts + /// accordingly, potentially popping the route as a result; returns whether + /// the pop request should be considered handled. + /// + /// {@macro flutter.widgets.navigator.maybePop} + /// + /// See also: + /// + /// * [Form], which provides a [Form.canPop] boolean that enables the + /// form to prevent any [pop]s initiated by the app's back button. + /// * [ModalRoute], which provides a `scopedOnPopCallback` that can be used + /// to define the route's `willPop` method. + @optionalTypeArgs + Future<bool> maybePop<T extends Object?>([ T? result ]) async { + final _RouteEntry? lastEntry = _lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate); + if (lastEntry == null) { + return false; + } + assert(lastEntry.route._navigator == this); + + // TODO(justinmc): When the deprecated willPop method is removed, delete + // this code and use only popDisposition, below. + final RoutePopDisposition willPopDisposition = await lastEntry.route.willPop(); + if (!mounted) { + // Forget about this pop, we were disposed in the meantime. + return true; + } + if (willPopDisposition == RoutePopDisposition.doNotPop) { + return true; + } + final _RouteEntry? newLastEntry = _lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate); + if (lastEntry != newLastEntry) { + // Forget about this pop, something happened to our history in the meantime. + return true; + } + + switch (lastEntry.route.popDisposition) { + case RoutePopDisposition.bubble: + return false; + case RoutePopDisposition.pop: + pop(result); + return true; + case RoutePopDisposition.doNotPop: + lastEntry.route.onPopInvoked(false); + return true; + } + } + + /// Pop the top-most route off the navigator. + /// + /// {@macro flutter.widgets.navigator.pop} + /// + /// {@tool snippet} + /// + /// Typical usage for closing a route is as follows: + /// + /// ```dart + /// void _handleClose() { + /// navigator.pop(); + /// } + /// ``` + /// {@end-tool} + /// {@tool snippet} + /// + /// A dialog box might be closed with a result: + /// + /// ```dart + /// void _handleAccept() { + /// navigator.pop(true); // dialog returns true + /// } + /// ``` + /// {@end-tool} + @optionalTypeArgs + void pop<T extends Object?>([ T? result ]) { + assert(!_debugLocked); + assert(() { + _debugLocked = true; + return true; + }()); + final _RouteEntry entry = _history.lastWhere(_RouteEntry.isPresentPredicate); + if (entry.pageBased) { + if (widget.onPopPage!(entry.route, result) && entry.currentState == _RouteLifecycle.idle) { + // The entry may have been disposed if the pop finishes synchronously. + assert(entry.route._popCompleter.isCompleted); + entry.currentState = _RouteLifecycle.pop; + } + } else { + entry.pop<T>(result); + assert (entry.currentState == _RouteLifecycle.pop); + } + if (entry.currentState == _RouteLifecycle.pop) { + _flushHistoryUpdates(rearrangeOverlay: false); + } + assert(entry.currentState == _RouteLifecycle.idle || entry.route._popCompleter.isCompleted); + assert(() { + _debugLocked = false; + return true; + }()); + _afterNavigation(entry.route); + } + + /// Calls [pop] repeatedly until the predicate returns true. + /// + /// {@macro flutter.widgets.navigator.popUntil} + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// void _doLogout() { + /// navigator.popUntil(ModalRoute.withName('/login')); + /// } + /// ``` + /// {@end-tool} + void popUntil(RoutePredicate predicate) { + _RouteEntry? candidate = _lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate); + while (candidate != null) { + if (predicate(candidate.route)) { + return; + } + pop(); + candidate = _lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate); + } + } + + /// Immediately remove `route` from the navigator, and [Route.dispose] it. + /// + /// {@macro flutter.widgets.navigator.removeRoute} + void removeRoute(Route<dynamic> route) { + assert(!_debugLocked); + assert(() { + _debugLocked = true; + return true; + }()); + assert(route._navigator == this); + final bool wasCurrent = route.isCurrent; + final _RouteEntry entry = _history.firstWhere(_RouteEntry.isRoutePredicate(route)); + entry.remove(); + _flushHistoryUpdates(rearrangeOverlay: false); + assert(() { + _debugLocked = false; + return true; + }()); + if (wasCurrent) { + _afterNavigation( + _lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate)?.route, + ); + } + } + + /// Immediately remove a route from the navigator, and [Route.dispose] it. The + /// route to be removed is the one below the given `anchorRoute`. + /// + /// {@macro flutter.widgets.navigator.removeRouteBelow} + void removeRouteBelow(Route<dynamic> anchorRoute) { + assert(!_debugLocked); + assert(() { + _debugLocked = true; + return true; + }()); + assert(anchorRoute._navigator == this); + final int anchorIndex = _history.indexWhere(_RouteEntry.isRoutePredicate(anchorRoute)); + assert(anchorIndex >= 0, 'This Navigator does not contain the specified anchorRoute.'); + assert(_history[anchorIndex].isPresent, 'The specified anchorRoute has already been removed from the Navigator.'); + int index = anchorIndex - 1; + while (index >= 0) { + if (_history[index].isPresent) { + break; + } + index -= 1; + } + assert(index >= 0, 'There are no routes below the specified anchorRoute.'); + _history[index].remove(); + _flushHistoryUpdates(rearrangeOverlay: false); + assert(() { + _debugLocked = false; + return true; + }()); + } + + /// Complete the lifecycle for a route that has been popped off the navigator. + /// + /// When the navigator pops a route, the navigator retains a reference to the + /// route in order to call [Route.dispose] if the navigator itself is removed + /// from the tree. When the route is finished with any exit animation, the + /// route should call this function to complete its lifecycle (e.g., to + /// receive a call to [Route.dispose]). + /// + /// The given `route` must have already received a call to [Route.didPop]. + /// This function may be called directly from [Route.didPop] if [Route.didPop] + /// will return true. + void finalizeRoute(Route<dynamic> route) { + // FinalizeRoute may have been called while we were already locked as a + // responds to route.didPop(). Make sure to leave in the state we were in + // before the call. + bool? wasDebugLocked; + assert(() { wasDebugLocked = _debugLocked; _debugLocked = true; return true; }()); + assert(_history.where(_RouteEntry.isRoutePredicate(route)).length == 1); + final int index = _history.indexWhere(_RouteEntry.isRoutePredicate(route)); + final _RouteEntry entry = _history[index]; + // For page-based route with zero transition, the finalizeRoute can be + // called on any life cycle above pop. + if (entry.pageBased && entry.currentState.index < _RouteLifecycle.pop.index) { + _observedRouteDeletions.add(_NavigatorPopObservation(route, _getRouteBefore(index - 1, _RouteEntry.willBePresentPredicate)?.route)); + } else { + assert(entry.currentState == _RouteLifecycle.popping); + } + entry.finalize(); + // finalizeRoute can be called during _flushHistoryUpdates if a pop + // finishes synchronously. + if (!_flushingHistory) { + _flushHistoryUpdates(rearrangeOverlay: false); + } + + assert(() { _debugLocked = wasDebugLocked!; return true; }()); + } + + @optionalTypeArgs + Route<T>? _getRouteById<T>(String id) { + return _firstRouteEntryWhereOrNull((_RouteEntry entry) => entry.restorationId == id)?.route as Route<T>?; + } + + int get _userGesturesInProgress => _userGesturesInProgressCount; + int _userGesturesInProgressCount = 0; + set _userGesturesInProgress(int value) { + _userGesturesInProgressCount = value; + userGestureInProgressNotifier.value = _userGesturesInProgress > 0; + } + + /// Whether a route is currently being manipulated by the user, e.g. + /// as during an iOS back gesture. + /// + /// See also: + /// + /// * [userGestureInProgressNotifier], which notifies its listeners if + /// the value of [userGestureInProgress] changes. + bool get userGestureInProgress => userGestureInProgressNotifier.value; + + /// Notifies its listeners if the value of [userGestureInProgress] changes. + final ValueNotifier<bool> userGestureInProgressNotifier = ValueNotifier<bool>(false); + + /// The navigator is being controlled by a user gesture. + /// + /// For example, called when the user beings an iOS back gesture. + /// + /// When the gesture finishes, call [didStopUserGesture]. + void didStartUserGesture() { + _userGesturesInProgress += 1; + if (_userGesturesInProgress == 1) { + final int routeIndex = _getIndexBefore( + _history.length - 1, + _RouteEntry.willBePresentPredicate, + ); + final Route<dynamic> route = _history[routeIndex].route; + Route<dynamic>? previousRoute; + if (!route.willHandlePopInternally && routeIndex > 0) { + previousRoute = _getRouteBefore( + routeIndex - 1, + _RouteEntry.willBePresentPredicate, + )!.route; + } + for (final NavigatorObserver observer in _effectiveObservers) { + observer.didStartUserGesture(route, previousRoute); + } + } + } + + /// A user gesture completed. + /// + /// Notifies the navigator that a gesture regarding which the navigator was + /// previously notified with [didStartUserGesture] has completed. + void didStopUserGesture() { + assert(_userGesturesInProgress > 0); + _userGesturesInProgress -= 1; + if (_userGesturesInProgress == 0) { + for (final NavigatorObserver observer in _effectiveObservers) { + observer.didStopUserGesture(); + } + } + } + + final Set<int> _activePointers = <int>{}; + + void _handlePointerDown(PointerDownEvent event) { + _activePointers.add(event.pointer); + } + + void _handlePointerUpOrCancel(PointerEvent event) { + _activePointers.remove(event.pointer); + } + + void _cancelActivePointers() { + // TODO(abarth): This mechanism is far from perfect. See https://github.com/flutter/flutter/issues/4770 + if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.idle) { + // If we're between frames (SchedulerPhase.idle) then absorb any + // subsequent pointers from this frame. The absorbing flag will be + // reset in the next frame, see build(). + final RenderAbsorbPointer? absorber = _overlayKey.currentContext?.findAncestorRenderObjectOfType<RenderAbsorbPointer>(); + setState(() { + absorber?.absorbing = true; + // We do this in setState so that we'll reset the absorbing value back + // to false on the next frame. + }); + } + _activePointers.toList().forEach(WidgetsBinding.instance.cancelPointer); + } + + /// Gets first route entry satisfying the predicate, or null if not found. + _RouteEntry? _firstRouteEntryWhereOrNull(_RouteEntryPredicate test) { + for (final _RouteEntry element in _history) { + if (test(element)) { + return element; + } + } + return null; + } + + /// Gets last route entry satisfying the predicate, or null if not found. + _RouteEntry? _lastRouteEntryWhereOrNull(_RouteEntryPredicate test) { + _RouteEntry? result; + for (final _RouteEntry element in _history) { + if (test(element)) { + result = element; + } + } + return result; + } + + @override + Widget build(BuildContext context) { + assert(!_debugLocked); + assert(_history.isNotEmpty); + + // Hides the HeroControllerScope for the widget subtree so that the other + // nested navigator underneath will not pick up the hero controller above + // this level. + return HeroControllerScope.none( + child: NotificationListener<NavigationNotification>( + onNotification: (NavigationNotification notification) { + // If the state of this Navigator does not change whether or not the + // whole framework can pop, propagate the Notification as-is. + if (notification.canHandlePop || !canPop()) { + return false; + } + // Otherwise, dispatch a new Notification with the correct canPop and + // stop the propagation of the old Notification. + const NavigationNotification nextNotification = NavigationNotification( + canHandlePop: true, + ); + nextNotification.dispatch(context); + return true; + }, + child: Listener( + onPointerDown: _handlePointerDown, + onPointerUp: _handlePointerUpOrCancel, + onPointerCancel: _handlePointerUpOrCancel, + child: AbsorbPointer( + absorbing: false, // it's mutated directly by _cancelActivePointers above + child: FocusTraversalGroup( + policy: FocusTraversalGroup.maybeOf(context), + child: Focus( + focusNode: focusNode, + autofocus: true, + skipTraversal: true, + includeSemantics: false, + child: UnmanagedRestorationScope( + bucket: bucket, + child: Overlay( + key: _overlayKey, + clipBehavior: widget.clipBehavior, + initialEntries: overlay == null ? _allRouteOverlayEntries.toList(growable: false) : const <OverlayEntry>[], + ), + ), + ), + ), + ), + ), + ), + ); + } +} + +enum _RouteRestorationType { + named, + anonymous, +} + +abstract class _RestorationInformation { + _RestorationInformation(this.type); + factory _RestorationInformation.named({ + required String name, + required Object? arguments, + required int restorationScopeId, + }) = _NamedRestorationInformation; + factory _RestorationInformation.anonymous({ + required RestorableRouteBuilder<Object?> routeBuilder, + required Object? arguments, + required int restorationScopeId, + }) = _AnonymousRestorationInformation; + + factory _RestorationInformation.fromSerializableData(Object data) { + final List<Object?> casted = data as List<Object?>; + assert(casted.isNotEmpty); + final _RouteRestorationType type = _RouteRestorationType.values[casted[0]! as int]; + switch (type) { + case _RouteRestorationType.named: + return _NamedRestorationInformation.fromSerializableData(casted.sublist(1)); + case _RouteRestorationType.anonymous: + return _AnonymousRestorationInformation.fromSerializableData(casted.sublist(1)); + } + } + + final _RouteRestorationType type; + int get restorationScopeId; + Object? _serializableData; + + bool get isRestorable => true; + + Object getSerializableData() { + _serializableData ??= computeSerializableData(); + return _serializableData!; + } + + @mustCallSuper + List<Object> computeSerializableData() { + return <Object>[type.index]; + } + + @protected + Route<dynamic> createRoute(NavigatorState navigator); + + _RouteEntry toRouteEntry(NavigatorState navigator, {_RouteLifecycle initialState = _RouteLifecycle.add}) { + final Route<Object?> route = createRoute(navigator); + return _RouteEntry( + route, + pageBased: false, + initialState: initialState, + restorationInformation: this, + ); + } +} + +class _NamedRestorationInformation extends _RestorationInformation { + _NamedRestorationInformation({ + required this.name, + required this.arguments, + required this.restorationScopeId, + }) : super(_RouteRestorationType.named); + + factory _NamedRestorationInformation.fromSerializableData(List<Object?> data) { + assert(data.length >= 2); + return _NamedRestorationInformation( + restorationScopeId: data[0]! as int, + name: data[1]! as String, + arguments: data.length > 2 ? data[2] : null, + ); + } + + @override + List<Object> computeSerializableData() { + return super.computeSerializableData()..addAll(<Object>[ + restorationScopeId, + name, + if (arguments != null) + arguments!, + ]); + } + + @override + final int restorationScopeId; + final String name; + final Object? arguments; + + @override + Route<dynamic> createRoute(NavigatorState navigator) { + final Route<dynamic> route = navigator._routeNamed<dynamic>(name, arguments: arguments)!; + return route; + } +} + +class _AnonymousRestorationInformation extends _RestorationInformation { + _AnonymousRestorationInformation({ + required this.routeBuilder, + required this.arguments, + required this.restorationScopeId, + }) : super(_RouteRestorationType.anonymous); + + factory _AnonymousRestorationInformation.fromSerializableData(List<Object?> data) { + assert(data.length > 1); + final RestorableRouteBuilder<Object?> routeBuilder = ui.PluginUtilities.getCallbackFromHandle(ui.CallbackHandle.fromRawHandle(data[1]! as int))! as RestorableRouteBuilder; + return _AnonymousRestorationInformation( + restorationScopeId: data[0]! as int, + routeBuilder: routeBuilder, + arguments: data.length > 2 ? data[2] : null, + ); + } + + @override + // TODO(goderbauer): remove the kIsWeb check when https://github.com/flutter/flutter/issues/33615 is resolved. + bool get isRestorable => !kIsWeb; + + @override + List<Object> computeSerializableData() { + assert(isRestorable); + final ui.CallbackHandle? handle = ui.PluginUtilities.getCallbackHandle(routeBuilder); + assert(handle != null); + return super.computeSerializableData()..addAll(<Object>[ + restorationScopeId, + handle!.toRawHandle(), + if (arguments != null) + arguments!, + ]); + } + + @override + final int restorationScopeId; + final RestorableRouteBuilder<Object?> routeBuilder; + final Object? arguments; + + @override + Route<dynamic> createRoute(NavigatorState navigator) { + final Route<dynamic> result = routeBuilder(navigator.context, arguments); + return result; + } +} + +class _HistoryProperty extends RestorableProperty<Map<String?, List<Object>>?> { + // Routes not associated with a page are stored under key 'null'. + Map<String?, List<Object>>? _pageToPagelessRoutes; + + // Updating. + + void update(_History history) { + assert(isRegistered); + final bool wasUninitialized = _pageToPagelessRoutes == null; + bool needsSerialization = wasUninitialized; + _pageToPagelessRoutes ??= <String, List<Object>>{}; + _RouteEntry? currentPage; + List<Object> newRoutesForCurrentPage = <Object>[]; + List<Object> oldRoutesForCurrentPage = _pageToPagelessRoutes![null] ?? const <Object>[]; + bool restorationEnabled = true; + + final Map<String?, List<Object>> newMap = <String?, List<Object>>{}; + final Set<String?> removedPages = _pageToPagelessRoutes!.keys.toSet(); + + for (final _RouteEntry entry in history) { + if (!entry.isPresentForRestoration) { + entry.restorationEnabled = false; + continue; + } + + assert(entry.isPresentForRestoration); + if (entry.pageBased) { + needsSerialization = needsSerialization || newRoutesForCurrentPage.length != oldRoutesForCurrentPage.length; + _finalizeEntry(newRoutesForCurrentPage, currentPage, newMap, removedPages); + currentPage = entry; + restorationEnabled = entry.restorationId != null; + entry.restorationEnabled = restorationEnabled; + if (restorationEnabled) { + assert(entry.restorationId != null); + newRoutesForCurrentPage = <Object>[]; + oldRoutesForCurrentPage = _pageToPagelessRoutes![entry.restorationId] ?? const <Object>[]; + } else { + newRoutesForCurrentPage = const <Object>[]; + oldRoutesForCurrentPage = const <Object>[]; + } + continue; + } + + assert(!entry.pageBased); + restorationEnabled = restorationEnabled && (entry.restorationInformation?.isRestorable ?? false); + entry.restorationEnabled = restorationEnabled; + if (restorationEnabled) { + assert(entry.restorationId != null); + assert(currentPage == null || currentPage.restorationId != null); + assert(entry.restorationInformation != null); + final Object serializedData = entry.restorationInformation!.getSerializableData(); + needsSerialization = needsSerialization + || oldRoutesForCurrentPage.length <= newRoutesForCurrentPage.length + || oldRoutesForCurrentPage[newRoutesForCurrentPage.length] != serializedData; + newRoutesForCurrentPage.add(serializedData); + } + } + needsSerialization = needsSerialization || newRoutesForCurrentPage.length != oldRoutesForCurrentPage.length; + _finalizeEntry(newRoutesForCurrentPage, currentPage, newMap, removedPages); + + needsSerialization = needsSerialization || removedPages.isNotEmpty; + + assert(wasUninitialized || _debugMapsEqual(_pageToPagelessRoutes!, newMap) != needsSerialization); + + if (needsSerialization) { + _pageToPagelessRoutes = newMap; + notifyListeners(); + } + } + + void _finalizeEntry( + List<Object> routes, + _RouteEntry? page, + Map<String?, List<Object>> pageToRoutes, + Set<String?> pagesToRemove, + ) { + assert(page == null || page.pageBased); + assert(!pageToRoutes.containsKey(page?.restorationId)); + if (routes.isNotEmpty) { + assert(page == null || page.restorationId != null); + final String? restorationId = page?.restorationId; + pageToRoutes[restorationId] = routes; + pagesToRemove.remove(restorationId); + } + } + + bool _debugMapsEqual(Map<String?, List<Object>> a, Map<String?, List<Object>> b) { + if (!setEquals(a.keys.toSet(), b.keys.toSet())) { + return false; + } + for (final String? key in a.keys) { + if (!listEquals(a[key], b[key])) { + return false; + } + } + return true; + } + + void clear() { + assert(isRegistered); + if (_pageToPagelessRoutes == null) { + return; + } + _pageToPagelessRoutes = null; + notifyListeners(); + } + + // Restoration. + + bool get hasData => _pageToPagelessRoutes != null; + + List<_RouteEntry> restoreEntriesForPage(_RouteEntry? page, NavigatorState navigator) { + assert(isRegistered); + assert(page == null || page.pageBased); + final List<_RouteEntry> result = <_RouteEntry>[]; + if (_pageToPagelessRoutes == null || (page != null && page.restorationId == null)) { + return result; + } + final List<Object>? serializedData = _pageToPagelessRoutes![page?.restorationId]; + if (serializedData == null) { + return result; + } + for (final Object data in serializedData) { + result.add(_RestorationInformation.fromSerializableData(data).toRouteEntry(navigator)); + } + return result; + } + + // RestorableProperty overrides. + + @override + Map<String?, List<Object>>? createDefaultValue() { + return null; + } + + @override + Map<String?, List<Object>>? fromPrimitives(Object? data) { + final Map<dynamic, dynamic> casted = data! as Map<dynamic, dynamic>; + return casted.map<String?, List<Object>>((dynamic key, dynamic value) => MapEntry<String?, List<Object>>( + key as String?, + List<Object>.from(value as List<dynamic>), + )); + } + + @override + void initWithValue(Map<String?, List<Object>>? value) { + _pageToPagelessRoutes = value; + } + + @override + Object? toPrimitives() { + return _pageToPagelessRoutes; + } + + @override + bool get enabled => hasData; +} + +/// A callback that given a [BuildContext] finds a [NavigatorState]. +/// +/// Used by [RestorableRouteFuture.navigatorFinder] to determine the navigator +/// to which a new route should be added. +typedef NavigatorFinderCallback = NavigatorState Function(BuildContext context); + +/// A callback that given some `arguments` and a `navigator` adds a new +/// restorable route to that `navigator` and returns the opaque ID of that +/// new route. +/// +/// Usually, this callback calls one of the imperative methods on the Navigator +/// that have "restorable" in the name and returns their return value. +/// +/// Used by [RestorableRouteFuture.onPresent]. +typedef RoutePresentationCallback = String Function(NavigatorState navigator, Object? arguments); + +/// A callback to handle the result of a completed [Route]. +/// +/// The return value of the route (which can be null for e.g. void routes) is +/// passed to the callback. +/// +/// Used by [RestorableRouteFuture.onComplete]. +typedef RouteCompletionCallback<T> = void Function(T result); + +/// Gives access to a [Route] object and its return value that was added to a +/// navigator via one of its "restorable" API methods. +/// +/// When a [State] object wants access to the return value of a [Route] object +/// it has pushed onto the [Navigator], a [RestorableRouteFuture] ensures that +/// it will also have access to that value after state restoration. +/// +/// To show a new route on the navigator defined by the [navigatorFinder], call +/// [present], which will invoke the [onPresent] callback. The [onPresent] +/// callback must add a new route to the navigator provided to it using one +/// of the "restorable" API methods. When the newly added route completes, the +/// [onComplete] callback executes. It is given the return value of the route, +/// which may be null. +/// +/// While the route added via [present] is shown on the navigator, it can be +/// accessed via the [route] getter. +/// +/// If the property is restored to a state in which [present] had been called on +/// it, but the route has not completed yet, the [RestorableRouteFuture] will +/// obtain the restored route object from the navigator again and call +/// [onComplete] once it completes. +/// +/// The [RestorableRouteFuture] can only keep track of one active [route]. +/// When [present] has been called to add a route, it may only be called again +/// after the previously added route has completed. +/// +/// {@tool dartpad} +/// This example uses a [RestorableRouteFuture] in the `_MyHomeState` to push a +/// new `MyCounter` route and to retrieve its return value. +/// +/// ** See code in examples/api/lib/widgets/navigator/restorable_route_future.0.dart ** +/// {@end-tool} +class RestorableRouteFuture<T> extends RestorableProperty<String?> { + /// Creates a [RestorableRouteFuture]. + RestorableRouteFuture({ + this.navigatorFinder = _defaultNavigatorFinder, + required this.onPresent, + this.onComplete, + }); + + /// A callback that given the [BuildContext] of the [State] object to which + /// this property is registered returns the [NavigatorState] of the navigator + /// to which the route instantiated in [onPresent] is added. + final NavigatorFinderCallback navigatorFinder; + + /// A callback that add a new [Route] to the provided navigator. + /// + /// The callback must use one of the API methods on the [NavigatorState] that + /// have "restorable" in their name (e.g. [NavigatorState.restorablePush], + /// [NavigatorState.restorablePushNamed], etc.) and return the opaque ID + /// returned by those methods. + /// + /// This callback is invoked when [present] is called with the `arguments` + /// Object that was passed to that method and the [NavigatorState] obtained + /// from [navigatorFinder]. + final RoutePresentationCallback onPresent; + + /// A callback that is invoked when the [Route] added via [onPresent] + /// completes. + /// + /// The return value of that route is passed to this method. + final RouteCompletionCallback<T>? onComplete; + + /// Shows the route created by [onPresent] and invoke [onComplete] when it + /// completes. + /// + /// The `arguments` object is passed to [onPresent] and can be used to + /// customize the route. It must be serializable via the + /// [StandardMessageCodec]. Often, a [Map] is used to pass key-value pairs. + void present([Object? arguments]) { + assert(!isPresent); + assert(isRegistered); + final String routeId = onPresent(_navigator, arguments); + _hookOntoRouteFuture(routeId); + notifyListeners(); + } + + /// Whether the [Route] created by [present] is currently shown. + /// + /// Returns true after [present] has been called until the [Route] completes. + bool get isPresent => route != null; + + /// The route that [present] added to the Navigator. + /// + /// Returns null when currently no route is shown + Route<T>? get route => _route; + Route<T>? _route; + + @override + String? createDefaultValue() => null; + + @override + void initWithValue(String? value) { + if (value != null) { + _hookOntoRouteFuture(value); + } + } + + @override + Object? toPrimitives() { + assert(route != null); + assert(enabled); + return route?.restorationScopeId.value; + } + + @override + String fromPrimitives(Object? data) { + assert(data != null); + return data! as String; + } + + bool _disposed = false; + + @override + void dispose() { + super.dispose(); + _route?.restorationScopeId.removeListener(notifyListeners); + _disposed = true; + } + + @override + bool get enabled => route?.restorationScopeId.value != null; + + NavigatorState get _navigator { + final NavigatorState navigator = navigatorFinder(state.context); + return navigator; + } + + void _hookOntoRouteFuture(String id) { + _route = _navigator._getRouteById<T>(id); + assert(_route != null); + route!.restorationScopeId.addListener(notifyListeners); + route!.popped.then((dynamic result) { + if (_disposed) { + return; + } + _route?.restorationScopeId.removeListener(notifyListeners); + _route = null; + notifyListeners(); + onComplete?.call(result as T); + }); + } + + static NavigatorState _defaultNavigatorFinder(BuildContext context) => Navigator.of(context); +} + +/// A notification that a change in navigation has taken place. +/// +/// Specifically, this notification indicates that at least one of the following +/// has occurred: +/// +/// * That route stack of a [Navigator] has changed in any way. +/// * The ability to pop has changed, such as controlled by [PopScope]. +class NavigationNotification extends Notification { + /// Creates a notification that some change in navigation has happened. + const NavigationNotification({ + required this.canHandlePop, + }); + + /// Indicates that the originator of this [Notification] is capable of + /// handling a navigation pop. + final bool canHandlePop; + + @override + String toString() { + return 'NavigationNotification canHandlePop: $canHandlePop'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/navigator_pop_handler.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/navigator_pop_handler.dart new file mode 100644 index 0000000000000000000000000000000000000000..203a85beded186327c0708b6789e2f8565c636ab --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/navigator_pop_handler.dart @@ -0,0 +1,110 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'framework.dart'; +import 'navigator.dart'; +import 'notification_listener.dart'; +import 'pop_scope.dart'; + +/// Enables the handling of system back gestures. +/// +/// Typically wraps a nested [Navigator] widget and allows it to handle system +/// back gestures in the [onPop] callback. +/// +/// {@tool dartpad} +/// This sample demonstrates how to use this widget to properly handle system +/// back gestures when using nested [Navigator]s. +/// +/// ** See code in examples/api/lib/widgets/navigator_pop_handler/navigator_pop_handler.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample demonstrates how to use this widget to properly handle system +/// back gestures with a bottom navigation bar whose tabs each have their own +/// nested [Navigator]s. +/// +/// ** See code in examples/api/lib/widgets/navigator_pop_handler/navigator_pop_handler.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [PopScope], which allows toggling the ability of a [Navigator] to +/// handle pops. +/// * [NavigationNotification], which indicates whether a [Navigator] in a +/// subtree can handle pops. +class NavigatorPopHandler extends StatefulWidget { + /// Creates an instance of [NavigatorPopHandler]. + const NavigatorPopHandler({ + super.key, + this.onPop, + this.enabled = true, + required this.child, + }); + + /// The widget to place below this in the widget tree. + /// + /// Typically this is a [Navigator] that will handle the pop when [onPop] is + /// called. + final Widget child; + + /// Whether this widget's ability to handle system back gestures is enabled or + /// disabled. + /// + /// When false, there will be no effect on system back gestures. If provided, + /// [onPop] will still be called. + /// + /// This can be used, for example, when the nested [Navigator] is no longer + /// active but remains in the widget tree, such as in an inactive tab. + /// + /// Defaults to true. + final bool enabled; + + /// Called when a handleable pop event happens. + /// + /// For example, a pop is handleable when a [Navigator] in [child] has + /// multiple routes on its stack. It's not handleable when it has only a + /// single route, and so [onPop] will not be called. + /// + /// Typically this is used to pop the [Navigator] in [child]. See the sample + /// code on [NavigatorPopHandler] for a full example of this. + final VoidCallback? onPop; + + @override + State<NavigatorPopHandler> createState() => _NavigatorPopHandlerState(); +} + +class _NavigatorPopHandlerState extends State<NavigatorPopHandler> { + bool _canPop = true; + + @override + Widget build(BuildContext context) { + // When the widget subtree indicates it can handle a pop, disable popping + // here, so that it can be manually handled in canPop. + return PopScope( + canPop: !widget.enabled || _canPop, + onPopInvoked: (bool didPop) { + if (didPop) { + return; + } + widget.onPop?.call(); + }, + // Listen to changes in the navigation stack in the widget subtree. + child: NotificationListener<NavigationNotification>( + onNotification: (NavigationNotification notification) { + // If this subtree cannot handle pop, then set canPop to true so + // that our PopScope will allow the Navigator higher in the tree to + // handle the pop instead. + final bool nextCanPop = !notification.canHandlePop; + if (nextCanPop != _canPop) { + setState(() { + _canPop = nextCanPop; + }); + } + return false; + }, + child: widget.child, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/nested_scroll_view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/nested_scroll_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..f2226888b49b9fe67748a81b8729738d73248307 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/nested_scroll_view.dart @@ -0,0 +1,2106 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'primary_scroll_controller.dart'; +import 'scroll_activity.dart'; +import 'scroll_configuration.dart'; +import 'scroll_context.dart'; +import 'scroll_controller.dart'; +import 'scroll_metrics.dart'; +import 'scroll_physics.dart'; +import 'scroll_position.dart'; +import 'scroll_view.dart'; +import 'sliver_fill.dart'; +import 'viewport.dart'; + +/// Signature used by [NestedScrollView] for building its header. +/// +/// The `innerBoxIsScrolled` argument is typically used to control the +/// [SliverAppBar.forceElevated] property to ensure that the app bar shows a +/// shadow, since it would otherwise not necessarily be aware that it had +/// content ostensibly below it. +typedef NestedScrollViewHeaderSliversBuilder = List<Widget> Function(BuildContext context, bool innerBoxIsScrolled); + +/// A scrolling view inside of which can be nested other scrolling views, with +/// their scroll positions being intrinsically linked. +/// +/// The most common use case for this widget is a scrollable view with a +/// flexible [SliverAppBar] containing a [TabBar] in the header (built by +/// [headerSliverBuilder], and with a [TabBarView] in the [body], such that the +/// scrollable view's contents vary based on which tab is visible. +/// +/// ## Motivation +/// +/// In a normal [ScrollView], there is one set of slivers (the components of the +/// scrolling view). If one of those slivers hosted a [TabBarView] which scrolls +/// in the opposite direction (e.g. allowing the user to swipe horizontally +/// between the pages represented by the tabs, while the list scrolls +/// vertically), then any list inside that [TabBarView] would not interact with +/// the outer [ScrollView]. For example, flinging the inner list to scroll to +/// the top would not cause a collapsed [SliverAppBar] in the outer [ScrollView] +/// to expand. +/// +/// [NestedScrollView] solves this problem by providing custom +/// [ScrollController]s for the outer [ScrollView] and the inner [ScrollView]s +/// (those inside the [TabBarView], hooking them together so that they appear, +/// to the user, as one coherent scroll view. +/// +/// {@tool dartpad} +/// This example shows a [NestedScrollView] whose header is the combination of a +/// [TabBar] in a [SliverAppBar] and whose body is a [TabBarView]. It uses a +/// [SliverOverlapAbsorber]/[SliverOverlapInjector] pair to make the inner lists +/// align correctly, and it uses [SafeArea] to avoid any horizontal disturbances +/// (e.g. the "notch" on iOS when the phone is horizontal). In addition, +/// [PageStorageKey]s are used to remember the scroll position of each tab's +/// list. +/// +/// ** See code in examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.0.dart ** +/// {@end-tool} +/// +/// ## [SliverAppBar]s with [NestedScrollView]s +/// +/// Using a [SliverAppBar] in the outer scroll view, or [headerSliverBuilder], +/// of a [NestedScrollView] may require special configurations in order to work +/// as it would if the outer and inner were one single scroll view, like a +/// [CustomScrollView]. +/// +/// ### Pinned [SliverAppBar]s +/// +/// A pinned [SliverAppBar] works in a [NestedScrollView] exactly as it would in +/// another scroll view, like [CustomScrollView]. When using +/// [SliverAppBar.pinned], the app bar remains visible at the top of the scroll +/// view. The app bar can still expand and contract as the user scrolls, but it +/// will remain visible rather than being scrolled out of view. +/// +/// This works naturally in a [NestedScrollView], as the pinned [SliverAppBar] +/// is not expected to move in or out of the visible portion of the viewport. +/// As the inner or outer [Scrollable]s are moved, the app bar persists as +/// expected. +/// +/// If the app bar is floating, pinned, and using an expanded height, follow the +/// floating convention laid out below. +/// +/// ### Floating [SliverAppBar]s +/// +/// When placed in the outer scrollable, or the [headerSliverBuilder], +/// a [SliverAppBar] that floats, using [SliverAppBar.floating] will not be +/// triggered to float over the inner scroll view, or [body], automatically. +/// +/// This is because a floating app bar uses the scroll offset of its own +/// [Scrollable] to dictate the floating action. Being two separate inner and +/// outer [Scrollable]s, a [SliverAppBar] in the outer header is not aware of +/// changes in the scroll offset of the inner body. +/// +/// In order to float the outer, use [NestedScrollView.floatHeaderSlivers]. When +/// set to true, the nested scrolling coordinator will prioritize floating in +/// the header slivers before applying the remaining drag to the body. +/// +/// Furthermore, the `floatHeaderSlivers` flag should also be used when using an +/// app bar that is floating, pinned, and has an expanded height. In this +/// configuration, the flexible space of the app bar will open and collapse, +/// while the primary portion of the app bar remains pinned. +/// +/// {@tool dartpad} +/// This simple example shows a [NestedScrollView] whose header contains a +/// floating [SliverAppBar]. By using the [floatHeaderSlivers] property, the +/// floating behavior is coordinated between the outer and inner [Scrollable]s, +/// so it behaves as it would in a single scrollable. +/// +/// ** See code in examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.1.dart ** +/// {@end-tool} +/// +/// ### Snapping [SliverAppBar]s +/// +/// Floating [SliverAppBar]s also have the option to perform a snapping animation. +/// If [SliverAppBar.snap] is true, then a scroll that exposes the floating app +/// bar will trigger an animation that slides the entire app bar into view. +/// Similarly if a scroll dismisses the app bar, the animation will slide the +/// app bar completely out of view. +/// +/// It is possible with a [NestedScrollView] to perform just the snapping +/// animation without floating the app bar in and out. By not using the +/// [NestedScrollView.floatHeaderSlivers], the app bar will snap in and out +/// without floating. +/// +/// The [SliverAppBar.snap] animation should be used in conjunction with the +/// [SliverOverlapAbsorber] and [SliverOverlapInjector] widgets when +/// implemented in a [NestedScrollView]. These widgets take any overlapping +/// behavior of the [SliverAppBar] in the header and redirect it to the +/// [SliverOverlapInjector] in the body. If it is missing, then it is possible +/// for the nested "inner" scroll view below to end up under the [SliverAppBar] +/// even when the inner scroll view thinks it has not been scrolled. +/// +/// {@tool dartpad} +/// This simple example shows a [NestedScrollView] whose header contains a +/// snapping, floating [SliverAppBar]. _Without_ setting any additional flags, +/// e.g [NestedScrollView.floatHeaderSlivers], the [SliverAppBar] will animate +/// in and out without floating. The [SliverOverlapAbsorber] and +/// [SliverOverlapInjector] maintain the proper alignment between the two +/// separate scroll views. +/// +/// ** See code in examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.2.dart ** +/// {@end-tool} +/// +/// ### Snapping and Floating [SliverAppBar]s +/// +// See https://github.com/flutter/flutter/issues/59189 +/// Currently, [NestedScrollView] does not support simultaneously floating and +/// snapping the outer scrollable, e.g. when using [SliverAppBar.floating] & +/// [SliverAppBar.snap] at the same time. +/// +/// ### Stretching [SliverAppBar]s +/// +// See https://github.com/flutter/flutter/issues/54059 +/// Currently, [NestedScrollView] does not support stretching the outer +/// scrollable, e.g. when using [SliverAppBar.stretch]. +/// +/// See also: +/// +/// * [SliverAppBar], for examples on different configurations like floating, +/// pinned and snap behaviors. +/// * [SliverOverlapAbsorber], a sliver that wraps another, forcing its layout +/// extent to be treated as overlap. +/// * [SliverOverlapInjector], a sliver that has a sliver geometry based on +/// the values stored in a [SliverOverlapAbsorberHandle]. +class NestedScrollView extends StatefulWidget { + /// Creates a nested scroll view. + /// + /// The [reverse], [headerSliverBuilder], and [body] arguments must not be + /// null. + const NestedScrollView({ + super.key, + this.controller, + this.scrollDirection = Axis.vertical, + this.reverse = false, + this.physics, + required this.headerSliverBuilder, + required this.body, + this.dragStartBehavior = DragStartBehavior.start, + this.floatHeaderSlivers = false, + this.clipBehavior = Clip.hardEdge, + this.restorationId, + this.scrollBehavior, + }); + + /// An object that can be used to control the position to which the outer + /// scroll view is scrolled. + final ScrollController? controller; + + /// {@macro flutter.widgets.scroll_view.scrollDirection} + /// + /// This property only applies to the [Axis] of the outer scroll view, + /// composed of the slivers returned from [headerSliverBuilder]. Since the + /// inner scroll view is not directly configured by the [NestedScrollView], + /// for the axes to match, configure the scroll view of the [body] the same + /// way if they are expected to scroll in the same orientation. This allows + /// for flexible configurations of the NestedScrollView. + final Axis scrollDirection; + + /// Whether the scroll view scrolls in the reading direction. + /// + /// For example, if the reading direction is left-to-right and + /// [scrollDirection] is [Axis.horizontal], then the scroll view scrolls from + /// left to right when [reverse] is false and from right to left when + /// [reverse] is true. + /// + /// Similarly, if [scrollDirection] is [Axis.vertical], then the scroll view + /// scrolls from top to bottom when [reverse] is false and from bottom to top + /// when [reverse] is true. + /// + /// This property only applies to the outer scroll view, composed of the + /// slivers returned from [headerSliverBuilder]. Since the inner scroll view + /// is not directly configured by the [NestedScrollView]. For both to scroll + /// in reverse, configure the scroll view of the [body] the same way if they + /// are expected to match. This allows for flexible configurations of the + /// NestedScrollView. + /// + /// Defaults to false. + final bool reverse; + + /// How the scroll view should respond to user input. + /// + /// For example, determines how the scroll view continues to animate after the + /// user stops dragging the scroll view (providing a custom implementation of + /// [ScrollPhysics.createBallisticSimulation] allows this particular aspect of + /// the physics to be overridden). + /// + /// If an explicit [ScrollBehavior] is provided to [scrollBehavior], the + /// [ScrollPhysics] provided by that behavior will take precedence after + /// [physics]. + /// + /// Defaults to matching platform conventions. + /// + /// The [ScrollPhysics.applyBoundaryConditions] implementation of the provided + /// object should not allow scrolling outside the scroll extent range + /// described by the [ScrollMetrics.minScrollExtent] and + /// [ScrollMetrics.maxScrollExtent] properties passed to that method. If that + /// invariant is not maintained, the nested scroll view may respond to user + /// scrolling erratically. + /// + /// This property only applies to the outer scroll view, composed of the + /// slivers returned from [headerSliverBuilder]. Since the inner scroll view + /// is not directly configured by the [NestedScrollView]. For both to scroll + /// with the same [ScrollPhysics], configure the scroll view of the [body] + /// the same way if they are expected to match, or use a [ScrollBehavior] as + /// an ancestor so both the inner and outer scroll views inherit the same + /// [ScrollPhysics]. This allows for flexible configurations of the + /// NestedScrollView. + /// + /// The [ScrollPhysics] also determine whether or not the [NestedScrollView] + /// can accept input from the user to change the scroll offset. For example, + /// [NeverScrollableScrollPhysics] typically will not allow the user to drag a + /// scroll view, but in this case, if one of the two scroll views can be + /// dragged, then dragging will be allowed. Configuring both scroll views with + /// [NeverScrollableScrollPhysics] will disallow dragging in this case. + final ScrollPhysics? physics; + + /// A builder for any widgets that are to precede the inner scroll views (as + /// given by [body]). + /// + /// Typically this is used to create a [SliverAppBar] with a [TabBar]. + final NestedScrollViewHeaderSliversBuilder headerSliverBuilder; + + /// The widget to show inside the [NestedScrollView]. + /// + /// Typically this will be [TabBarView]. + /// + /// The [body] is built in a context that provides a [PrimaryScrollController] + /// that interacts with the [NestedScrollView]'s scroll controller. Any + /// [ListView] or other [Scrollable]-based widget inside the [body] that is + /// intended to scroll with the [NestedScrollView] should therefore not be + /// given an explicit [ScrollController], instead allowing it to default to + /// the [PrimaryScrollController] provided by the [NestedScrollView]. + final Widget body; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// Whether or not the [NestedScrollView]'s coordinator should prioritize the + /// outer scrollable over the inner when scrolling back. + /// + /// This is useful for an outer scrollable containing a [SliverAppBar] that + /// is expected to float. + final bool floatHeaderSlivers; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// {@macro flutter.widgets.scrollable.restorationId} + final String? restorationId; + + /// {@macro flutter.widgets.shadow.scrollBehavior} + /// + /// [ScrollBehavior]s also provide [ScrollPhysics]. If an explicit + /// [ScrollPhysics] is provided in [physics], it will take precedence, + /// followed by [scrollBehavior], and then the inherited ancestor + /// [ScrollBehavior]. + /// + /// The [ScrollBehavior] of the inherited [ScrollConfiguration] will be + /// modified by default to not apply a [Scrollbar]. This is because the + /// NestedScrollView cannot assume the configuration of the outer and inner + /// [Scrollable] widgets, particularly whether to treat them as one scrollable, + /// or separate and desirous of unique behaviors. + final ScrollBehavior? scrollBehavior; + + /// Returns the [SliverOverlapAbsorberHandle] of the nearest ancestor + /// [NestedScrollView]. + /// + /// This is necessary to configure the [SliverOverlapAbsorber] and + /// [SliverOverlapInjector] widgets. + /// + /// For sample code showing how to use this method, see the [NestedScrollView] + /// documentation. + static SliverOverlapAbsorberHandle sliverOverlapAbsorberHandleFor(BuildContext context) { + final _InheritedNestedScrollView? target = context.dependOnInheritedWidgetOfExactType<_InheritedNestedScrollView>(); + assert( + target != null, + 'NestedScrollView.sliverOverlapAbsorberHandleFor must be called with a context that contains a NestedScrollView.', + ); + return target!.state._absorberHandle; + } + + List<Widget> _buildSlivers(BuildContext context, ScrollController innerController, bool bodyIsScrolled) { + return <Widget>[ + ...headerSliverBuilder(context, bodyIsScrolled), + SliverFillRemaining( + // The inner (body) scroll view must use this scroll controller so that + // the independent scroll positions can be kept in sync. + child: PrimaryScrollController( + // The inner scroll view should always inherit this + // PrimaryScrollController, on every platform. + automaticallyInheritForPlatforms: TargetPlatform.values.toSet(), + // `PrimaryScrollController.scrollDirection` is not set, and so it is + // restricted to the default Axis.vertical. + // Ideally the inner and outer views would have the same + // scroll direction, and so we could assume + // `NestedScrollView.scrollDirection` for the PrimaryScrollController, + // but use cases already exist where the axes are mismatched. + // https://github.com/flutter/flutter/issues/102001 + controller: innerController, + child: body, + ), + ), + ]; + } + + @override + NestedScrollViewState createState() => NestedScrollViewState(); +} + +/// The [State] for a [NestedScrollView]. +/// +/// The [ScrollController]s, [innerController] and [outerController], of the +/// [NestedScrollView]'s children may be accessed through its state. This is +/// useful for obtaining respective scroll positions in the [NestedScrollView]. +/// +/// If you want to access the inner or outer scroll controller of a +/// [NestedScrollView], you can get its [NestedScrollViewState] by supplying a +/// `GlobalKey<NestedScrollViewState>` to the [NestedScrollView.key] parameter). +/// +/// {@tool dartpad} +/// [NestedScrollViewState] can be obtained using a [GlobalKey]. +/// Using the following setup, you can access the inner scroll controller +/// using `globalKey.currentState.innerController`. +/// +/// ** See code in examples/api/lib/widgets/nested_scroll_view/nested_scroll_view_state.0.dart ** +/// {@end-tool} +class NestedScrollViewState extends State<NestedScrollView> { + final SliverOverlapAbsorberHandle _absorberHandle = SliverOverlapAbsorberHandle(); + + /// The [ScrollController] provided to the [ScrollView] in + /// [NestedScrollView.body]. + /// + /// Manipulating the [ScrollPosition] of this controller pushes the outer + /// header sliver(s) up and out of view. The position of the [outerController] + /// will be set to [ScrollPosition.maxScrollExtent], unless you use + /// [ScrollPosition.setPixels]. + /// + /// See also: + /// + /// * [outerController], which exposes the [ScrollController] used by the + /// sliver(s) contained in [NestedScrollView.headerSliverBuilder]. + ScrollController get innerController => _coordinator!._innerController; + + /// The [ScrollController] provided to the [ScrollView] in + /// [NestedScrollView.headerSliverBuilder]. + /// + /// This is equivalent to [NestedScrollView.controller], if provided. + /// + /// Manipulating the [ScrollPosition] of this controller pushes the inner body + /// sliver(s) down. The position of the [innerController] will be set to + /// [ScrollPosition.minScrollExtent], unless you use + /// [ScrollPosition.setPixels]. Visually, the inner body will be scrolled to + /// its beginning. + /// + /// See also: + /// + /// * [innerController], which exposes the [ScrollController] used by the + /// [ScrollView] contained in [NestedScrollView.body]. + ScrollController get outerController => _coordinator!._outerController; + + _NestedScrollCoordinator? _coordinator; + + @override + void initState() { + super.initState(); + _coordinator = _NestedScrollCoordinator( + this, + widget.controller, + _handleHasScrolledBodyChanged, + widget.floatHeaderSlivers, + ); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _coordinator!.setParent(widget.controller); + } + + @override + void didUpdateWidget(NestedScrollView oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.controller != widget.controller) { + _coordinator!.setParent(widget.controller); + } + } + + @override + void dispose() { + _coordinator!.dispose(); + _coordinator = null; + _absorberHandle.dispose(); + super.dispose(); + } + + bool? _lastHasScrolledBody; + + void _handleHasScrolledBodyChanged() { + if (!mounted) { + return; + } + final bool newHasScrolledBody = _coordinator!.hasScrolledBody; + if (_lastHasScrolledBody != newHasScrolledBody) { + setState(() { + // _coordinator.hasScrolledBody changed (we use it in the build method) + // (We record _lastHasScrolledBody in the build() method, rather than in + // this setState call, because the build() method may be called more + // often than just from here, and we want to only call setState when the + // new value is different than the last built value.) + }); + } + } + + @override + Widget build(BuildContext context) { + final ScrollPhysics scrollPhysics = widget.physics?.applyTo(const ClampingScrollPhysics()) + ?? widget.scrollBehavior?.getScrollPhysics(context).applyTo(const ClampingScrollPhysics()) + ?? const ClampingScrollPhysics(); + + return _InheritedNestedScrollView( + state: this, + child: Builder( + builder: (BuildContext context) { + _lastHasScrolledBody = _coordinator!.hasScrolledBody; + return _NestedScrollViewCustomScrollView( + dragStartBehavior: widget.dragStartBehavior, + scrollDirection: widget.scrollDirection, + reverse: widget.reverse, + physics: scrollPhysics, + scrollBehavior: widget.scrollBehavior ?? ScrollConfiguration.of(context).copyWith(scrollbars: false), + controller: _coordinator!._outerController, + slivers: widget._buildSlivers( + context, + _coordinator!._innerController, + _lastHasScrolledBody!, + ), + handle: _absorberHandle, + clipBehavior: widget.clipBehavior, + restorationId: widget.restorationId, + ); + }, + ), + ); + } +} + +class _NestedScrollViewCustomScrollView extends CustomScrollView { + const _NestedScrollViewCustomScrollView({ + required super.scrollDirection, + required super.reverse, + required ScrollPhysics super.physics, + required ScrollBehavior super.scrollBehavior, + required ScrollController super.controller, + required super.slivers, + required this.handle, + required super.clipBehavior, + super.dragStartBehavior, + super.restorationId, + }); + + final SliverOverlapAbsorberHandle handle; + + @override + Widget buildViewport( + BuildContext context, + ViewportOffset offset, + AxisDirection axisDirection, + List<Widget> slivers, + ) { + assert(!shrinkWrap); + return NestedScrollViewViewport( + axisDirection: axisDirection, + offset: offset, + slivers: slivers, + handle: handle, + clipBehavior: clipBehavior, + ); + } +} + +class _InheritedNestedScrollView extends InheritedWidget { + const _InheritedNestedScrollView({ + required this.state, + required super.child, + }); + + final NestedScrollViewState state; + + @override + bool updateShouldNotify(_InheritedNestedScrollView old) => state != old.state; +} + +class _NestedScrollMetrics extends FixedScrollMetrics { + _NestedScrollMetrics({ + required super.minScrollExtent, + required super.maxScrollExtent, + required super.pixels, + required super.viewportDimension, + required super.axisDirection, + required super.devicePixelRatio, + required this.minRange, + required this.maxRange, + required this.correctionOffset, + }); + + @override + _NestedScrollMetrics copyWith({ + double? minScrollExtent, + double? maxScrollExtent, + double? pixels, + double? viewportDimension, + AxisDirection? axisDirection, + double? devicePixelRatio, + double? minRange, + double? maxRange, + double? correctionOffset, + }) { + return _NestedScrollMetrics( + minScrollExtent: minScrollExtent ?? (hasContentDimensions ? this.minScrollExtent : null), + maxScrollExtent: maxScrollExtent ?? (hasContentDimensions ? this.maxScrollExtent : null), + pixels: pixels ?? (hasPixels ? this.pixels : null), + viewportDimension: viewportDimension ?? (hasViewportDimension ? this.viewportDimension : null), + axisDirection: axisDirection ?? this.axisDirection, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + minRange: minRange ?? this.minRange, + maxRange: maxRange ?? this.maxRange, + correctionOffset: correctionOffset ?? this.correctionOffset, + ); + } + + final double minRange; + + final double maxRange; + + final double correctionOffset; +} + +typedef _NestedScrollActivityGetter = ScrollActivity Function(_NestedScrollPosition position); + +class _NestedScrollCoordinator implements ScrollActivityDelegate, ScrollHoldController { + _NestedScrollCoordinator( + this._state, + this._parent, + this._onHasScrolledBodyChanged, + this._floatHeaderSlivers, + ) { + final double initialScrollOffset = _parent?.initialScrollOffset ?? 0.0; + _outerController = _NestedScrollController( + this, + initialScrollOffset: initialScrollOffset, + debugLabel: 'outer', + ); + _innerController = _NestedScrollController( + this, + debugLabel: 'inner', + ); + } + + final NestedScrollViewState _state; + ScrollController? _parent; + final VoidCallback _onHasScrolledBodyChanged; + final bool _floatHeaderSlivers; + + late _NestedScrollController _outerController; + late _NestedScrollController _innerController; + + _NestedScrollPosition? get _outerPosition { + if (!_outerController.hasClients) { + return null; + } + return _outerController.nestedPositions.single; + } + + Iterable<_NestedScrollPosition> get _innerPositions { + return _innerController.nestedPositions; + } + + bool get canScrollBody { + final _NestedScrollPosition? outer = _outerPosition; + if (outer == null) { + return true; + } + return outer.haveDimensions && outer.extentAfter == 0.0; + } + + bool get hasScrolledBody { + for (final _NestedScrollPosition position in _innerPositions) { + if (!position.hasContentDimensions || !position.hasPixels) { + // It's possible that NestedScrollView built twice before layout phase + // in the same frame. This can happen when the FocusManager schedules a microTask + // that marks NestedScrollView dirty during the warm up frame. + // https://github.com/flutter/flutter/pull/75308 + continue; + } else if (position.pixels > position.minScrollExtent) { + return true; + } + } + return false; + } + + void updateShadow() { _onHasScrolledBodyChanged(); } + + ScrollDirection get userScrollDirection => _userScrollDirection; + ScrollDirection _userScrollDirection = ScrollDirection.idle; + + void updateUserScrollDirection(ScrollDirection value) { + if (userScrollDirection == value) { + return; + } + _userScrollDirection = value; + _outerPosition!.didUpdateScrollDirection(value); + for (final _NestedScrollPosition position in _innerPositions) { + position.didUpdateScrollDirection(value); + } + } + + ScrollDragController? _currentDrag; + + void beginActivity(ScrollActivity newOuterActivity, _NestedScrollActivityGetter innerActivityGetter) { + _outerPosition!.beginActivity(newOuterActivity); + bool scrolling = newOuterActivity.isScrolling; + for (final _NestedScrollPosition position in _innerPositions) { + final ScrollActivity newInnerActivity = innerActivityGetter(position); + position.beginActivity(newInnerActivity); + scrolling = scrolling && newInnerActivity.isScrolling; + } + _currentDrag?.dispose(); + _currentDrag = null; + if (!scrolling) { + updateUserScrollDirection(ScrollDirection.idle); + } + } + + @override + AxisDirection get axisDirection => _outerPosition!.axisDirection; + + static IdleScrollActivity _createIdleScrollActivity(_NestedScrollPosition position) { + return IdleScrollActivity(position); + } + + @override + void goIdle() { + beginActivity( + _createIdleScrollActivity(_outerPosition!), + _createIdleScrollActivity, + ); + } + + @override + void goBallistic(double velocity) { + beginActivity( + createOuterBallisticScrollActivity(velocity), + (_NestedScrollPosition position) { + return createInnerBallisticScrollActivity( + position, + velocity, + ); + }, + ); + } + + ScrollActivity createOuterBallisticScrollActivity(double velocity) { + // This function creates a ballistic scroll for the outer scrollable. + // + // It assumes that the outer scrollable can't be overscrolled, and sets up a + // ballistic scroll over the combined space of the innerPositions and the + // outerPosition. + + // First we must pick a representative inner position that we will care + // about. This is somewhat arbitrary. Ideally we'd pick the one that is "in + // the center" but there isn't currently a good way to do that so we + // arbitrarily pick the one that is the furthest away from the infinity we + // are heading towards. + _NestedScrollPosition? innerPosition; + if (velocity != 0.0) { + for (final _NestedScrollPosition position in _innerPositions) { + if (innerPosition != null) { + if (velocity > 0.0) { + if (innerPosition.pixels < position.pixels) { + continue; + } + } else { + assert(velocity < 0.0); + if (innerPosition.pixels > position.pixels) { + continue; + } + } + } + innerPosition = position; + } + } + + if (innerPosition == null) { + // It's either just us or a velocity=0 situation. + return _outerPosition!.createBallisticScrollActivity( + _outerPosition!.physics.createBallisticSimulation( + _outerPosition!, + velocity, + ), + mode: _NestedBallisticScrollActivityMode.independent, + ); + } + + final _NestedScrollMetrics metrics = _getMetrics(innerPosition, velocity); + + return _outerPosition!.createBallisticScrollActivity( + _outerPosition!.physics.createBallisticSimulation(metrics, velocity), + mode: _NestedBallisticScrollActivityMode.outer, + metrics: metrics, + ); + } + + @protected + ScrollActivity createInnerBallisticScrollActivity(_NestedScrollPosition position, double velocity) { + return position.createBallisticScrollActivity( + position.physics.createBallisticSimulation( + _getMetrics(position, velocity), + velocity, + ), + mode: _NestedBallisticScrollActivityMode.inner, + ); + } + + _NestedScrollMetrics _getMetrics(_NestedScrollPosition innerPosition, double velocity) { + double pixels, minRange, maxRange, correctionOffset; + double extra = 0.0; + if (innerPosition.pixels == innerPosition.minScrollExtent) { + pixels = clampDouble(_outerPosition!.pixels, + _outerPosition!.minScrollExtent, + _outerPosition!.maxScrollExtent, + ); // TODO(ianh): gracefully handle out-of-range outer positions + minRange = _outerPosition!.minScrollExtent; + maxRange = _outerPosition!.maxScrollExtent; + assert(minRange <= maxRange); + correctionOffset = 0.0; + } else { + assert(innerPosition.pixels != innerPosition.minScrollExtent); + if (innerPosition.pixels < innerPosition.minScrollExtent) { + pixels = innerPosition.pixels - innerPosition.minScrollExtent + _outerPosition!.minScrollExtent; + } else { + assert(innerPosition.pixels > innerPosition.minScrollExtent); + pixels = innerPosition.pixels - innerPosition.minScrollExtent + _outerPosition!.maxScrollExtent; + } + if ((velocity > 0.0) && (innerPosition.pixels > innerPosition.minScrollExtent)) { + // This handles going forward (fling up) and inner list is scrolled past + // zero. We want to grab the extra pixels immediately to shrink. + extra = _outerPosition!.maxScrollExtent - _outerPosition!.pixels; + assert(extra >= 0.0); + minRange = pixels; + maxRange = pixels + extra; + assert(minRange <= maxRange); + correctionOffset = _outerPosition!.pixels - pixels; + } else if ((velocity < 0.0) && (innerPosition.pixels < innerPosition.minScrollExtent)) { + // This handles going backward (fling down) and inner list is + // underscrolled. We want to grab the extra pixels immediately to grow. + extra = _outerPosition!.pixels - _outerPosition!.minScrollExtent; + assert(extra >= 0.0); + minRange = pixels - extra; + maxRange = pixels; + assert(minRange <= maxRange); + correctionOffset = _outerPosition!.pixels - pixels; + } else { + // This handles going forward (fling up) and inner list is + // underscrolled, OR, going backward (fling down) and inner list is + // scrolled past zero. We want to skip the pixels we don't need to grow + // or shrink over. + if (velocity > 0.0) { + // shrinking + extra = _outerPosition!.minScrollExtent - _outerPosition!.pixels; + } else if (velocity < 0.0) { + // growing + extra = _outerPosition!.pixels - (_outerPosition!.maxScrollExtent - _outerPosition!.minScrollExtent); + } + assert(extra <= 0.0); + minRange = _outerPosition!.minScrollExtent; + maxRange = _outerPosition!.maxScrollExtent + extra; + assert(minRange <= maxRange); + correctionOffset = 0.0; + } + } + return _NestedScrollMetrics( + minScrollExtent: _outerPosition!.minScrollExtent, + maxScrollExtent: _outerPosition!.maxScrollExtent + innerPosition.maxScrollExtent - innerPosition.minScrollExtent + extra, + pixels: pixels, + viewportDimension: _outerPosition!.viewportDimension, + axisDirection: _outerPosition!.axisDirection, + minRange: minRange, + maxRange: maxRange, + correctionOffset: correctionOffset, + devicePixelRatio: _outerPosition!.devicePixelRatio, + ); + } + + double unnestOffset(double value, _NestedScrollPosition source) { + if (source == _outerPosition) { + return clampDouble(value, + _outerPosition!.minScrollExtent, + _outerPosition!.maxScrollExtent, + ); + } + if (value < source.minScrollExtent) { + return value - source.minScrollExtent + _outerPosition!.minScrollExtent; + } + return value - source.minScrollExtent + _outerPosition!.maxScrollExtent; + } + + double nestOffset(double value, _NestedScrollPosition target) { + if (target == _outerPosition) { + return clampDouble(value, + _outerPosition!.minScrollExtent, + _outerPosition!.maxScrollExtent, + ); + } + if (value < _outerPosition!.minScrollExtent) { + return value - _outerPosition!.minScrollExtent + target.minScrollExtent; + } + if (value > _outerPosition!.maxScrollExtent) { + return value - _outerPosition!.maxScrollExtent + target.minScrollExtent; + } + return target.minScrollExtent; + } + + void updateCanDrag() { + if (!_outerPosition!.haveDimensions) { + return; + } + bool innerCanDrag = false; + for (final _NestedScrollPosition position in _innerPositions) { + if (!position.haveDimensions) { + return; + } + innerCanDrag = innerCanDrag + // This refers to the physics of the actual inner scroll position, not + // the whole NestedScrollView, since it is possible to have different + // ScrollPhysics for the inner and outer positions. + || position.physics.shouldAcceptUserOffset(position); + } + _outerPosition!.updateCanDrag(innerCanDrag); + } + + Future<void> animateTo( + double to, { + required Duration duration, + required Curve curve, + }) async { + final DrivenScrollActivity outerActivity = _outerPosition!.createDrivenScrollActivity( + nestOffset(to, _outerPosition!), + duration, + curve, + ); + final List<Future<void>> resultFutures = <Future<void>>[outerActivity.done]; + beginActivity( + outerActivity, + (_NestedScrollPosition position) { + final DrivenScrollActivity innerActivity = position.createDrivenScrollActivity( + nestOffset(to, position), + duration, + curve, + ); + resultFutures.add(innerActivity.done); + return innerActivity; + }, + ); + await Future.wait<void>(resultFutures); + } + + void jumpTo(double to) { + goIdle(); + _outerPosition!.localJumpTo(nestOffset(to, _outerPosition!)); + for (final _NestedScrollPosition position in _innerPositions) { + position.localJumpTo(nestOffset(to, position)); + } + goBallistic(0.0); + } + + void pointerScroll(double delta) { + // If an update is made to pointer scrolling here, consider if the same + // (or similar) change should be made in + // ScrollPositionWithSingleContext.pointerScroll. + if (delta == 0.0) { + goBallistic(0.0); + return; + } + + goIdle(); + updateUserScrollDirection( + delta < 0.0 ? ScrollDirection.forward : ScrollDirection.reverse, + ); + + // Handle notifications. Even if only one position actually receives + // the delta, the NestedScrollView's intention is to treat multiple + // ScrollPositions as one. + _outerPosition!.isScrollingNotifier.value = true; + _outerPosition!.didStartScroll(); + for (final _NestedScrollPosition position in _innerPositions) { + position.isScrollingNotifier.value = true; + position.didStartScroll(); + } + + if (_innerPositions.isEmpty) { + // Does not enter overscroll. + _outerPosition!.applyClampedPointerSignalUpdate(delta); + } else if (delta > 0.0) { + // Dragging "up" - delta is positive + // Prioritize getting rid of any inner overscroll, and then the outer + // view, so that the app bar will scroll out of the way asap. + double outerDelta = delta; + for (final _NestedScrollPosition position in _innerPositions) { + if (position.pixels < 0.0) { // This inner position is in overscroll. + final double potentialOuterDelta = position.applyClampedPointerSignalUpdate(delta); + // In case there are multiple positions in varying states of + // overscroll, the first to 'reach' the outer view above takes + // precedence. + outerDelta = math.max(outerDelta, potentialOuterDelta); + } + } + if (outerDelta != 0.0) { + final double innerDelta = _outerPosition!.applyClampedPointerSignalUpdate( + outerDelta, + ); + if (innerDelta != 0.0) { + for (final _NestedScrollPosition position in _innerPositions) { + position.applyClampedPointerSignalUpdate(innerDelta); + } + } + } + } else { + // Dragging "down" - delta is negative + double innerDelta = delta; + // Apply delta to the outer header first if it is configured to float. + if (_floatHeaderSlivers) { + innerDelta = _outerPosition!.applyClampedPointerSignalUpdate(delta); + } + + if (innerDelta != 0.0) { + // Apply the innerDelta, if we have not floated in the outer scrollable, + // any leftover delta after this will be passed on to the outer + // scrollable by the outerDelta. + double outerDelta = 0.0; // it will go negative if it changes + for (final _NestedScrollPosition position in _innerPositions) { + final double overscroll = position.applyClampedPointerSignalUpdate(innerDelta); + outerDelta = math.min(outerDelta, overscroll); + } + if (outerDelta != 0.0) { + _outerPosition!.applyClampedPointerSignalUpdate(outerDelta); + } + } + } + + _outerPosition!.didEndScroll(); + for (final _NestedScrollPosition position in _innerPositions) { + position.didEndScroll(); + } + goBallistic(0.0); + } + + @override + double setPixels(double newPixels) { + assert(false); + return 0.0; + } + + ScrollHoldController hold(VoidCallback holdCancelCallback) { + beginActivity( + HoldScrollActivity( + delegate: _outerPosition!, + onHoldCanceled: holdCancelCallback, + ), + (_NestedScrollPosition position) => HoldScrollActivity(delegate: position), + ); + return this; + } + + @override + void cancel() { + goBallistic(0.0); + } + + Drag drag(DragStartDetails details, VoidCallback dragCancelCallback) { + final ScrollDragController drag = ScrollDragController( + delegate: this, + details: details, + onDragCanceled: dragCancelCallback, + ); + beginActivity( + DragScrollActivity(_outerPosition!, drag), + (_NestedScrollPosition position) => DragScrollActivity(position, drag), + ); + assert(_currentDrag == null); + _currentDrag = drag; + return drag; + } + + @override + void applyUserOffset(double delta) { + updateUserScrollDirection( + delta > 0.0 ? ScrollDirection.forward : ScrollDirection.reverse, + ); + assert(delta != 0.0); + if (_innerPositions.isEmpty) { + _outerPosition!.applyFullDragUpdate(delta); + } else if (delta < 0.0) { + // Dragging "up" + // Prioritize getting rid of any inner overscroll, and then the outer + // view, so that the app bar will scroll out of the way asap. + double outerDelta = delta; + for (final _NestedScrollPosition position in _innerPositions) { + if (position.pixels < 0.0) { // This inner position is in overscroll. + final double potentialOuterDelta = position.applyClampedDragUpdate(delta); + // In case there are multiple positions in varying states of + // overscroll, the first to 'reach' the outer view above takes + // precedence. + outerDelta = math.max(outerDelta, potentialOuterDelta); + } + } + if (outerDelta != 0.0) { + final double innerDelta = _outerPosition!.applyClampedDragUpdate( + outerDelta, + ); + if (innerDelta != 0.0) { + for (final _NestedScrollPosition position in _innerPositions) { + position.applyFullDragUpdate(innerDelta); + } + } + } + } else { + // Dragging "down" - delta is positive + double innerDelta = delta; + // Apply delta to the outer header first if it is configured to float. + if (_floatHeaderSlivers) { + innerDelta = _outerPosition!.applyClampedDragUpdate(delta); + } + + if (innerDelta != 0.0) { + // Apply the innerDelta, if we have not floated in the outer scrollable, + // any leftover delta after this will be passed on to the outer + // scrollable by the outerDelta. + double outerDelta = 0.0; // it will go positive if it changes + final List<double> overscrolls = <double>[]; + final List<_NestedScrollPosition> innerPositions = _innerPositions.toList(); + for (final _NestedScrollPosition position in innerPositions) { + final double overscroll = position.applyClampedDragUpdate(innerDelta); + outerDelta = math.max(outerDelta, overscroll); + overscrolls.add(overscroll); + } + if (outerDelta != 0.0) { + outerDelta -= _outerPosition!.applyClampedDragUpdate(outerDelta); + } + + // Now deal with any overscroll + for (int i = 0; i < innerPositions.length; ++i) { + final double remainingDelta = overscrolls[i] - outerDelta; + if (remainingDelta > 0.0) { + innerPositions[i].applyFullDragUpdate(remainingDelta); + } + } + } + } + } + + void setParent(ScrollController? value) { + _parent = value; + updateParent(); + } + + void updateParent() { + _outerPosition?.setParent( + _parent ?? PrimaryScrollController.maybeOf(_state.context), + ); + } + + @mustCallSuper + void dispose() { + _currentDrag?.dispose(); + _currentDrag = null; + _outerController.dispose(); + _innerController.dispose(); + } + + @override + String toString() => '${objectRuntimeType(this, '_NestedScrollCoordinator')}(outer=$_outerController; inner=$_innerController)'; +} + +class _NestedScrollController extends ScrollController { + _NestedScrollController( + this.coordinator, { + super.initialScrollOffset, + super.debugLabel, + }); + + final _NestedScrollCoordinator coordinator; + + @override + ScrollPosition createScrollPosition( + ScrollPhysics physics, + ScrollContext context, + ScrollPosition? oldPosition, + ) { + return _NestedScrollPosition( + coordinator: coordinator, + physics: physics, + context: context, + initialPixels: initialScrollOffset, + oldPosition: oldPosition, + debugLabel: debugLabel, + ); + } + + @override + void attach(ScrollPosition position) { + assert(position is _NestedScrollPosition); + super.attach(position); + coordinator.updateParent(); + coordinator.updateCanDrag(); + position.addListener(_scheduleUpdateShadow); + _scheduleUpdateShadow(); + } + + @override + void detach(ScrollPosition position) { + assert(position is _NestedScrollPosition); + (position as _NestedScrollPosition).setParent(null); + position.removeListener(_scheduleUpdateShadow); + super.detach(position); + _scheduleUpdateShadow(); + } + + void _scheduleUpdateShadow() { + // We do this asynchronously for attach() so that the new position has had + // time to be initialized, and we do it asynchronously for detach() and from + // the position change notifications because those happen synchronously + // during a frame, at a time where it's too late to call setState. Since the + // result is usually animated, the lag incurred is no big deal. + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + coordinator.updateShadow(); + }, debugLabel: 'NestedScrollController.updateShadow'); + } + + Iterable<_NestedScrollPosition> get nestedPositions { + // TODO(vegorov): use instance method version of castFrom when it is available. + return Iterable.castFrom<ScrollPosition, _NestedScrollPosition>(positions); + } +} + +// The _NestedScrollPosition is used by both the inner and outer viewports of a +// NestedScrollView. It tracks the offset to use for those viewports, and knows +// about the _NestedScrollCoordinator, so that when activities are triggered on +// this class, they can defer, or be influenced by, the coordinator. +class _NestedScrollPosition extends ScrollPosition implements ScrollActivityDelegate { + _NestedScrollPosition({ + required super.physics, + required super.context, + double initialPixels = 0.0, + super.oldPosition, + super.debugLabel, + required this.coordinator, + }) { + if (!hasPixels) { + correctPixels(initialPixels); + } + if (activity == null) { + goIdle(); + } + assert(activity != null); + saveScrollOffset(); // in case we didn't restore but could, so that we don't restore it later + } + + final _NestedScrollCoordinator coordinator; + + TickerProvider get vsync => context.vsync; + + ScrollController? _parent; + + void setParent(ScrollController? value) { + _parent?.detach(this); + _parent = value; + _parent?.attach(this); + } + + @override + AxisDirection get axisDirection => context.axisDirection; + + @override + void absorb(ScrollPosition other) { + super.absorb(other); + activity!.updateDelegate(this); + } + + @override + void restoreScrollOffset() { + if (coordinator.canScrollBody) { + super.restoreScrollOffset(); + } + } + + // Returns the amount of delta that was not used. + // + // Positive delta means going down (exposing stuff above), negative delta + // going up (exposing stuff below). + double applyClampedDragUpdate(double delta) { + assert(delta != 0.0); + // If we are going towards the maxScrollExtent (negative scroll offset), + // then the furthest we can be in the minScrollExtent direction is negative + // infinity. For example, if we are already overscrolled, then scrolling to + // reduce the overscroll should not disallow the overscroll. + // + // If we are going towards the minScrollExtent (positive scroll offset), + // then the furthest we can be in the minScrollExtent direction is wherever + // we are now, if we are already overscrolled (in which case pixels is less + // than the minScrollExtent), or the minScrollExtent if we are not. + // + // In other words, we cannot, via applyClampedDragUpdate, _enter_ an + // overscroll situation. + // + // An overscroll situation might be nonetheless entered via several means. + // One is if the physics allow it, via applyFullDragUpdate (see below). An + // overscroll situation can also be forced, e.g. if the scroll position is + // artificially set using the scroll controller. + final double min = delta < 0.0 + ? -double.infinity + : math.min(minScrollExtent, pixels); + // The logic for max is equivalent but on the other side. + final double max = delta > 0.0 + ? double.infinity + // If pixels < 0.0, then we are currently in overscroll. The max should be + // 0.0, representing the end of the overscrolled portion. + : pixels < 0.0 ? 0.0 : math.max(maxScrollExtent, pixels); + final double oldPixels = pixels; + final double newPixels = clampDouble(pixels - delta, min, max); + final double clampedDelta = newPixels - pixels; + if (clampedDelta == 0.0) { + return delta; + } + final double overscroll = physics.applyBoundaryConditions(this, newPixels); + final double actualNewPixels = newPixels - overscroll; + final double offset = actualNewPixels - oldPixels; + if (offset != 0.0) { + forcePixels(actualNewPixels); + didUpdateScrollPositionBy(offset); + } + return delta + offset; + } + + // Returns the overscroll. + double applyFullDragUpdate(double delta) { + assert(delta != 0.0); + final double oldPixels = pixels; + // Apply friction: + final double newPixels = pixels - physics.applyPhysicsToUserOffset( + this, + delta, + ); + if (oldPixels == newPixels) { + // Delta must have been so small we dropped it during floating point addition. + return 0.0; + } + // Check for overscroll: + final double overscroll = physics.applyBoundaryConditions(this, newPixels); + final double actualNewPixels = newPixels - overscroll; + if (actualNewPixels != oldPixels) { + forcePixels(actualNewPixels); + didUpdateScrollPositionBy(actualNewPixels - oldPixels); + } + if (overscroll != 0.0) { + didOverscrollBy(overscroll); + return overscroll; + } + return 0.0; + } + + + // Returns the amount of delta that was not used. + // + // Negative delta represents a forward ScrollDirection, while the positive + // would be a reverse ScrollDirection. + // + // The method doesn't take into account the effects of [ScrollPhysics]. + double applyClampedPointerSignalUpdate(double delta) { + assert(delta != 0.0); + + final double min = delta > 0.0 + ? -double.infinity + : math.min(minScrollExtent, pixels); + // The logic for max is equivalent but on the other side. + final double max = delta < 0.0 + ? double.infinity + : math.max(maxScrollExtent, pixels); + final double newPixels = clampDouble(pixels + delta, min, max); + final double clampedDelta = newPixels - pixels; + if (clampedDelta == 0.0) { + return delta; + } + forcePixels(newPixels); + didUpdateScrollPositionBy(clampedDelta); + return delta - clampedDelta; + } + + @override + ScrollDirection get userScrollDirection => coordinator.userScrollDirection; + + DrivenScrollActivity createDrivenScrollActivity(double to, Duration duration, Curve curve) { + return DrivenScrollActivity( + this, + from: pixels, + to: to, + duration: duration, + curve: curve, + vsync: vsync, + ); + } + + @override + double applyUserOffset(double delta) { + assert(false); + return 0.0; + } + + // This is called by activities when they finish their work. + @override + void goIdle() { + beginActivity(IdleScrollActivity(this)); + coordinator.updateUserScrollDirection(ScrollDirection.idle); + } + + // This is called by activities when they finish their work and want to go + // ballistic. + @override + void goBallistic(double velocity) { + Simulation? simulation; + if (velocity != 0.0 || outOfRange) { + simulation = physics.createBallisticSimulation(this, velocity); + } + beginActivity(createBallisticScrollActivity( + simulation, + mode: _NestedBallisticScrollActivityMode.independent, + )); + } + + ScrollActivity createBallisticScrollActivity( + Simulation? simulation, { + required _NestedBallisticScrollActivityMode mode, + _NestedScrollMetrics? metrics, + }) { + if (simulation == null) { + return IdleScrollActivity(this); + } + switch (mode) { + case _NestedBallisticScrollActivityMode.outer: + assert(metrics != null); + if (metrics!.minRange == metrics.maxRange) { + return IdleScrollActivity(this); + } + return _NestedOuterBallisticScrollActivity( + coordinator, + this, + metrics, + simulation, + context.vsync, + activity?.shouldIgnorePointer ?? true, + ); + case _NestedBallisticScrollActivityMode.inner: + return _NestedInnerBallisticScrollActivity( + coordinator, + this, + simulation, + context.vsync, + activity?.shouldIgnorePointer ?? true, + ); + case _NestedBallisticScrollActivityMode.independent: + return BallisticScrollActivity(this, simulation, context.vsync, activity?.shouldIgnorePointer ?? true); + } + } + + @override + Future<void> animateTo( + double to, { + required Duration duration, + required Curve curve, + }) { + return coordinator.animateTo( + coordinator.unnestOffset(to, this), + duration: duration, + curve: curve, + ); + } + + @override + void jumpTo(double value) { + return coordinator.jumpTo(coordinator.unnestOffset(value, this)); + } + + @override + void pointerScroll(double delta) { + return coordinator.pointerScroll(delta); + } + + + @override + void jumpToWithoutSettling(double value) { + assert(false); + } + + void localJumpTo(double value) { + if (pixels != value) { + final double oldPixels = pixels; + forcePixels(value); + didStartScroll(); + didUpdateScrollPositionBy(pixels - oldPixels); + didEndScroll(); + } + } + + @override + void applyNewDimensions() { + super.applyNewDimensions(); + coordinator.updateCanDrag(); + } + + void updateCanDrag(bool innerCanDrag) { + // This is only called for the outer position + assert(coordinator._outerPosition == this); + context.setCanDrag( + // This refers to the physics of the actual outer scroll position, not + // the whole NestedScrollView, since it is possible to have different + // ScrollPhysics for the inner and outer positions. + physics.shouldAcceptUserOffset(this) + || innerCanDrag, + ); + } + + @override + ScrollHoldController hold(VoidCallback holdCancelCallback) { + return coordinator.hold(holdCancelCallback); + } + + @override + Drag drag(DragStartDetails details, VoidCallback dragCancelCallback) { + return coordinator.drag(details, dragCancelCallback); + } +} + +enum _NestedBallisticScrollActivityMode { outer, inner, independent } + +class _NestedInnerBallisticScrollActivity extends BallisticScrollActivity { + _NestedInnerBallisticScrollActivity( + this.coordinator, + _NestedScrollPosition position, + Simulation simulation, + TickerProvider vsync, + bool shouldIgnorePointer, + ) : super(position, simulation, vsync, shouldIgnorePointer); + + final _NestedScrollCoordinator coordinator; + + @override + _NestedScrollPosition get delegate => super.delegate as _NestedScrollPosition; + + @override + void resetActivity() { + delegate.beginActivity(coordinator.createInnerBallisticScrollActivity( + delegate, + velocity, + )); + } + + @override + void applyNewDimensions() { + delegate.beginActivity(coordinator.createInnerBallisticScrollActivity( + delegate, + velocity, + )); + } + + @override + bool applyMoveTo(double value) { + return super.applyMoveTo(coordinator.nestOffset(value, delegate)); + } +} + +class _NestedOuterBallisticScrollActivity extends BallisticScrollActivity { + _NestedOuterBallisticScrollActivity( + this.coordinator, + _NestedScrollPosition position, + this.metrics, + Simulation simulation, + TickerProvider vsync, + bool shouldIgnorePointer, + ) : assert(metrics.minRange != metrics.maxRange), + assert(metrics.maxRange > metrics.minRange), + super(position, simulation, vsync, shouldIgnorePointer); + + final _NestedScrollCoordinator coordinator; + final _NestedScrollMetrics metrics; + + @override + _NestedScrollPosition get delegate => super.delegate as _NestedScrollPosition; + + @override + void resetActivity() { + delegate.beginActivity( + coordinator.createOuterBallisticScrollActivity(velocity), + ); + } + + @override + void applyNewDimensions() { + delegate.beginActivity( + coordinator.createOuterBallisticScrollActivity(velocity), + ); + } + + @override + bool applyMoveTo(double value) { + bool done = false; + if (velocity > 0.0) { + if (value < metrics.minRange) { + return true; + } + if (value > metrics.maxRange) { + value = metrics.maxRange; + done = true; + } + } else if (velocity < 0.0) { + if (value > metrics.maxRange) { + return true; + } + if (value < metrics.minRange) { + value = metrics.minRange; + done = true; + } + } else { + value = clampDouble(value, metrics.minRange, metrics.maxRange); + done = true; + } + final bool result = super.applyMoveTo(value + metrics.correctionOffset); + assert(result); // since we tried to pass an in-range value, it shouldn't ever overflow + return !done; + } + + @override + String toString() { + return '${objectRuntimeType(this, '_NestedOuterBallisticScrollActivity')}(${metrics.minRange} .. ${metrics.maxRange}; correcting by ${metrics.correctionOffset})'; + } +} + +/// Handle to provide to a [SliverOverlapAbsorber], a [SliverOverlapInjector], +/// and an [NestedScrollViewViewport], to shift overlap in a [NestedScrollView]. +/// +/// A particular [SliverOverlapAbsorberHandle] can only be assigned to a single +/// [SliverOverlapAbsorber] at a time. It can also be (and normally is) assigned +/// to one or more [SliverOverlapInjector]s, which must be later descendants of +/// the same [NestedScrollViewViewport] as the [SliverOverlapAbsorber]. The +/// [SliverOverlapAbsorber] must be a direct descendant of the +/// [NestedScrollViewViewport], taking part in the same sliver layout. (The +/// [SliverOverlapInjector] can be a descendant that takes part in a nested +/// scroll view's sliver layout.) +/// +/// Whenever the [NestedScrollViewViewport] is marked dirty for layout, it will +/// cause its assigned [SliverOverlapAbsorberHandle] to fire notifications. It +/// is the responsibility of the [SliverOverlapInjector]s (and any other +/// clients) to mark themselves dirty when this happens, in case the geometry +/// subsequently changes during layout. +/// +/// See also: +/// +/// * [NestedScrollView], which uses a [NestedScrollViewViewport] and a +/// [SliverOverlapAbsorber] to align its children, and which shows sample +/// usage for this class. +class SliverOverlapAbsorberHandle extends ChangeNotifier { + /// Creates a [SliverOverlapAbsorberHandle]. + SliverOverlapAbsorberHandle() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + // Incremented when a RenderSliverOverlapAbsorber takes ownership of this + // object, decremented when it releases it. This allows us to find cases where + // the same handle is being passed to two render objects. + int _writers = 0; + + /// The current amount of overlap being absorbed by the + /// [SliverOverlapAbsorber]. + /// + /// This corresponds to the [SliverGeometry.layoutExtent] of the child of the + /// [SliverOverlapAbsorber]. + /// + /// This is updated during the layout of the [SliverOverlapAbsorber]. It + /// should not change at any other time. No notifications are sent when it + /// changes; clients (e.g. [SliverOverlapInjector]s) are responsible for + /// marking themselves dirty whenever this object sends notifications, which + /// happens any time the [SliverOverlapAbsorber] might subsequently change the + /// value during that layout. + double? get layoutExtent => _layoutExtent; + double? _layoutExtent; + + /// The total scroll extent of the gap being absorbed by the + /// [SliverOverlapAbsorber]. + /// + /// This corresponds to the [SliverGeometry.scrollExtent] of the child of the + /// [SliverOverlapAbsorber]. + /// + /// This is updated during the layout of the [SliverOverlapAbsorber]. It + /// should not change at any other time. No notifications are sent when it + /// changes; clients (e.g. [SliverOverlapInjector]s) are responsible for + /// marking themselves dirty whenever this object sends notifications, which + /// happens any time the [SliverOverlapAbsorber] might subsequently change the + /// value during that layout. + double? get scrollExtent => _scrollExtent; + double? _scrollExtent; + + void _setExtents(double? layoutValue, double? scrollValue) { + assert( + _writers == 1, + 'Multiple RenderSliverOverlapAbsorbers have been provided the same SliverOverlapAbsorberHandle.', + ); + _layoutExtent = layoutValue; + _scrollExtent = scrollValue; + } + + void _markNeedsLayout() => notifyListeners(); + + @override + String toString() { + String? extra; + switch (_writers) { + case 0: + extra = ', orphan'; + case 1: + // normal case + break; + default: + extra = ', $_writers WRITERS ASSIGNED'; + break; + } + return '${objectRuntimeType(this, 'SliverOverlapAbsorberHandle')}($layoutExtent$extra)'; + } +} + +/// A sliver that wraps another, forcing its layout extent to be treated as +/// overlap. +/// +/// The difference between the overlap requested by the child `sliver` and the +/// overlap reported by this widget, called the _absorbed overlap_, is reported +/// to the [SliverOverlapAbsorberHandle], which is typically passed to a +/// [SliverOverlapInjector]. +/// +/// See also: +/// +/// * [NestedScrollView], whose documentation has sample code showing how to +/// use this widget. +class SliverOverlapAbsorber extends SingleChildRenderObjectWidget { + /// Creates a sliver that absorbs overlap and reports it to a + /// [SliverOverlapAbsorberHandle]. + const SliverOverlapAbsorber({ + super.key, + required this.handle, + Widget? sliver, + }) : super(child: sliver); + + /// The object in which the absorbed overlap is recorded. + /// + /// A particular [SliverOverlapAbsorberHandle] can only be assigned to a + /// single [SliverOverlapAbsorber] at a time. + final SliverOverlapAbsorberHandle handle; + + @override + RenderSliverOverlapAbsorber createRenderObject(BuildContext context) { + return RenderSliverOverlapAbsorber( + handle: handle, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverOverlapAbsorber renderObject) { + renderObject.handle = handle; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<SliverOverlapAbsorberHandle>('handle', handle)); + } +} + +/// A sliver that wraps another, forcing its layout extent to be treated as +/// overlap. +/// +/// The difference between the overlap requested by the child `sliver` and the +/// overlap reported by this widget, called the _absorbed overlap_, is reported +/// to the [SliverOverlapAbsorberHandle], which is typically passed to a +/// [RenderSliverOverlapInjector]. +class RenderSliverOverlapAbsorber extends RenderSliver with RenderObjectWithChildMixin<RenderSliver> { + /// Create a sliver that absorbs overlap and reports it to a + /// [SliverOverlapAbsorberHandle]. + /// + /// The [sliver] must be a [RenderSliver]. + RenderSliverOverlapAbsorber({ + required SliverOverlapAbsorberHandle handle, + RenderSliver? sliver, + }) : _handle = handle { + child = sliver; + } + + /// The object in which the absorbed overlap is recorded. + /// + /// A particular [SliverOverlapAbsorberHandle] can only be assigned to a + /// single [RenderSliverOverlapAbsorber] at a time. + SliverOverlapAbsorberHandle get handle => _handle; + SliverOverlapAbsorberHandle _handle; + set handle(SliverOverlapAbsorberHandle value) { + if (handle == value) { + return; + } + if (attached) { + handle._writers -= 1; + value._writers += 1; + value._setExtents(handle.layoutExtent, handle.scrollExtent); + } + _handle = value; + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + handle._writers += 1; + } + + @override + void detach() { + handle._writers -= 1; + super.detach(); + } + + @override + void performLayout() { + assert( + handle._writers == 1, + 'A SliverOverlapAbsorberHandle cannot be passed to multiple RenderSliverOverlapAbsorber objects at the same time.', + ); + if (child == null) { + geometry = SliverGeometry.zero; + return; + } + child!.layout(constraints, parentUsesSize: true); + final SliverGeometry childLayoutGeometry = child!.geometry!; + geometry = childLayoutGeometry.copyWith( + scrollExtent: childLayoutGeometry.scrollExtent - childLayoutGeometry.maxScrollObstructionExtent, + layoutExtent: math.max(0, childLayoutGeometry.paintExtent - childLayoutGeometry.maxScrollObstructionExtent), + ); + handle._setExtents( + childLayoutGeometry.maxScrollObstructionExtent, + childLayoutGeometry.maxScrollObstructionExtent, + ); + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + // child is always at our origin + } + + @override + bool hitTestChildren(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }) { + if (child != null) { + return child!.hitTest( + result, + mainAxisPosition: mainAxisPosition, + crossAxisPosition: crossAxisPosition, + ); + } + return false; + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + context.paintChild(child!, offset); + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<SliverOverlapAbsorberHandle>('handle', handle)); + } +} + +/// A sliver that has a sliver geometry based on the values stored in a +/// [SliverOverlapAbsorberHandle]. +/// +/// The [SliverOverlapAbsorber] must be an earlier descendant of a common +/// ancestor [Viewport], so that it will always be laid out before the +/// [SliverOverlapInjector] during a particular frame. +/// +/// See also: +/// +/// * [NestedScrollView], which uses a [SliverOverlapAbsorber] to align its +/// children, and which shows sample usage for this class. +class SliverOverlapInjector extends SingleChildRenderObjectWidget { + /// Creates a sliver that is as tall as the value of the given [handle]'s + /// layout extent. + const SliverOverlapInjector({ + super.key, + required this.handle, + Widget? sliver, + }) : super(child: sliver); + + /// The handle to the [SliverOverlapAbsorber] that is feeding this injector. + /// + /// This should be a handle owned by a [SliverOverlapAbsorber] and a + /// [NestedScrollViewViewport]. + final SliverOverlapAbsorberHandle handle; + + @override + RenderSliverOverlapInjector createRenderObject(BuildContext context) { + return RenderSliverOverlapInjector( + handle: handle, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverOverlapInjector renderObject) { + renderObject.handle = handle; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<SliverOverlapAbsorberHandle>('handle', handle)); + } +} + +/// A sliver that has a sliver geometry based on the values stored in a +/// [SliverOverlapAbsorberHandle]. +/// +/// The [RenderSliverOverlapAbsorber] must be an earlier descendant of a common +/// ancestor [RenderViewport] (probably a [RenderNestedScrollViewViewport]), so +/// that it will always be laid out before the [RenderSliverOverlapInjector] +/// during a particular frame. +class RenderSliverOverlapInjector extends RenderSliver { + /// Creates a sliver that is as tall as the value of the given [handle]'s extent. + RenderSliverOverlapInjector({ + required SliverOverlapAbsorberHandle handle, + }) : _handle = handle; + + double? _currentLayoutExtent; + double? _currentMaxExtent; + + /// The object that specifies how wide to make the gap injected by this render + /// object. + /// + /// This should be a handle owned by a [RenderSliverOverlapAbsorber] and a + /// [RenderNestedScrollViewViewport]. + SliverOverlapAbsorberHandle get handle => _handle; + SliverOverlapAbsorberHandle _handle; + set handle(SliverOverlapAbsorberHandle value) { + if (handle == value) { + return; + } + if (attached) { + handle.removeListener(markNeedsLayout); + } + _handle = value; + if (attached) { + handle.addListener(markNeedsLayout); + if (handle.layoutExtent != _currentLayoutExtent || + handle.scrollExtent != _currentMaxExtent) { + markNeedsLayout(); + } + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + handle.addListener(markNeedsLayout); + if (handle.layoutExtent != _currentLayoutExtent || + handle.scrollExtent != _currentMaxExtent) { + markNeedsLayout(); + } + } + + @override + void detach() { + handle.removeListener(markNeedsLayout); + super.detach(); + } + + @override + void performLayout() { + _currentLayoutExtent = handle.layoutExtent; + _currentMaxExtent = handle.layoutExtent; + assert( + _currentLayoutExtent != null && _currentMaxExtent != null, + 'SliverOverlapInjector has found no absorbed extent to inject.\n ' + 'The SliverOverlapAbsorber must be an earlier descendant of a common ' + 'ancestor Viewport, so that it will always be laid out before the ' + 'SliverOverlapInjector during a particular frame.\n ' + 'The SliverOverlapAbsorber is typically contained in the list of slivers ' + 'provided by NestedScrollView.headerSliverBuilder.\n' + ); + final double clampedLayoutExtent = math.min( + _currentLayoutExtent! - constraints.scrollOffset, + constraints.remainingPaintExtent, + ); + geometry = SliverGeometry( + scrollExtent: _currentLayoutExtent!, + paintExtent: math.max(0.0, clampedLayoutExtent), + maxPaintExtent: _currentMaxExtent!, + ); + } + + @override + void debugPaint(PaintingContext context, Offset offset) { + assert(() { + if (debugPaintSizeEnabled) { + final Paint paint = Paint() + ..color = const Color(0xFFCC9933) + ..strokeWidth = 3.0 + ..style = PaintingStyle.stroke; + Offset start, end, delta; + switch (constraints.axis) { + case Axis.vertical: + final double x = offset.dx + constraints.crossAxisExtent / 2.0; + start = Offset(x, offset.dy); + end = Offset(x, offset.dy + geometry!.paintExtent); + delta = Offset(constraints.crossAxisExtent / 5.0, 0.0); + case Axis.horizontal: + final double y = offset.dy + constraints.crossAxisExtent / 2.0; + start = Offset(offset.dx, y); + end = Offset(offset.dy + geometry!.paintExtent, y); + delta = Offset(0.0, constraints.crossAxisExtent / 5.0); + } + for (int index = -2; index <= 2; index += 1) { + paintZigZag( + context.canvas, + paint, + start - delta * index.toDouble(), + end - delta * index.toDouble(), + 10, + 10.0, + ); + } + } + return true; + }()); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<SliverOverlapAbsorberHandle>('handle', handle)); + } +} + +/// The [Viewport] variant used by [NestedScrollView]. +/// +/// This viewport takes a [SliverOverlapAbsorberHandle] and notifies it any time +/// the viewport needs to recompute its layout (e.g. when it is scrolled). +class NestedScrollViewViewport extends Viewport { + /// Creates a variant of [Viewport] that has a [SliverOverlapAbsorberHandle]. + NestedScrollViewViewport({ + super.key, + super.axisDirection, + super.crossAxisDirection, + super.anchor, + required super.offset, + super.center, + super.slivers, + required this.handle, + super.clipBehavior, + }); + + /// The handle to the [SliverOverlapAbsorber] that is feeding this injector. + final SliverOverlapAbsorberHandle handle; + + @override + RenderNestedScrollViewViewport createRenderObject(BuildContext context) { + return RenderNestedScrollViewViewport( + axisDirection: axisDirection, + crossAxisDirection: crossAxisDirection ?? Viewport.getDefaultCrossAxisDirection( + context, + axisDirection, + ), + anchor: anchor, + offset: offset, + handle: handle, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderNestedScrollViewViewport renderObject) { + renderObject + ..axisDirection = axisDirection + ..crossAxisDirection = crossAxisDirection ?? Viewport.getDefaultCrossAxisDirection( + context, + axisDirection, + ) + ..anchor = anchor + ..offset = offset + ..handle = handle + ..clipBehavior = clipBehavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<SliverOverlapAbsorberHandle>('handle', handle)); + } +} + +/// The [RenderViewport] variant used by [NestedScrollView]. +/// +/// This viewport takes a [SliverOverlapAbsorberHandle] and notifies it any time +/// the viewport needs to recompute its layout (e.g. when it is scrolled). +class RenderNestedScrollViewViewport extends RenderViewport { + /// Create a variant of [RenderViewport] that has a + /// [SliverOverlapAbsorberHandle]. + RenderNestedScrollViewViewport({ + super.axisDirection, + required super.crossAxisDirection, + required super.offset, + super.anchor, + super.children, + super.center, + required SliverOverlapAbsorberHandle handle, + super.clipBehavior, + }) : _handle = handle; + + /// The object to notify when [markNeedsLayout] is called. + SliverOverlapAbsorberHandle get handle => _handle; + SliverOverlapAbsorberHandle _handle; + /// Setting this will trigger notifications on the new object. + set handle(SliverOverlapAbsorberHandle value) { + if (handle == value) { + return; + } + _handle = value; + handle._markNeedsLayout(); + } + + @override + void markNeedsLayout() { + handle._markNeedsLayout(); + super.markNeedsLayout(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<SliverOverlapAbsorberHandle>('handle', handle)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/notification_listener.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/notification_listener.dart new file mode 100644 index 0000000000000000000000000000000000000000..0665bc0153a575e5b0d249c9decee5b770616db5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/notification_listener.dart @@ -0,0 +1,172 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'framework.dart'; + +/// Signature for [Notification] listeners. +/// +/// Return true to cancel the notification bubbling. Return false to allow the +/// notification to continue to be dispatched to further ancestors. +/// +/// [NotificationListener] is useful when listening scroll events +/// in [ListView],[NestedScrollView],[GridView] or any Scrolling widgets. +/// Used by [NotificationListener.onNotification]. +typedef NotificationListenerCallback<T extends Notification> = bool Function(T notification); + +/// A notification that can bubble up the widget tree. +/// +/// You can determine the type of a notification using the `is` operator to +/// check the [runtimeType] of the notification. +/// +/// To listen for notifications in a subtree, use a [NotificationListener]. +/// +/// To send a notification, call [dispatch] on the notification you wish to +/// send. The notification will be delivered to any [NotificationListener] +/// widgets with the appropriate type parameters that are ancestors of the given +/// [BuildContext]. +/// +/// {@tool dartpad} +/// This example shows a [NotificationListener] widget +/// that listens for [ScrollNotification] notifications. When a scroll +/// event occurs in the [NestedScrollView], +/// this widget is notified. The events could be either a +/// [ScrollStartNotification]or[ScrollEndNotification]. +/// +/// ** See code in examples/api/lib/widgets/notification_listener/notification.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ScrollNotification] which describes the notification lifecycle. +/// * [ScrollStartNotification] which returns the start position of scrolling. +/// * [ScrollEndNotification] which returns the end position of scrolling. +/// * [NestedScrollView] which creates a nested scroll view. +/// +abstract class Notification { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const Notification(); + + /// Start bubbling this notification at the given build context. + /// + /// The notification will be delivered to any [NotificationListener] widgets + /// with the appropriate type parameters that are ancestors of the given + /// [BuildContext]. If the [BuildContext] is null, the notification is not + /// dispatched. + void dispatch(BuildContext? target) { + target?.dispatchNotification(this); + } + + @override + String toString() { + final List<String> description = <String>[]; + debugFillDescription(description); + return '${objectRuntimeType(this, 'Notification')}(${description.join(", ")})'; + } + + /// Add additional information to the given description for use by [toString]. + /// + /// This method makes it easier for subclasses to coordinate to provide a + /// high-quality [toString] implementation. The [toString] implementation on + /// the [Notification] base class calls [debugFillDescription] to collect + /// useful information from subclasses to incorporate into its return value. + /// + /// Implementations of this method should start with a call to the inherited + /// method, as in `super.debugFillDescription(description)`. + @protected + @mustCallSuper + void debugFillDescription(List<String> description) { } +} + +/// A widget that listens for [Notification]s bubbling up the tree. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=cAnFbFoGM50} +/// +/// Notifications will trigger the [onNotification] callback only if their +/// [runtimeType] is a subtype of `T`. +/// +/// To dispatch notifications, use the [Notification.dispatch] method. +class NotificationListener<T extends Notification> extends ProxyWidget { + /// Creates a widget that listens for notifications. + const NotificationListener({ + super.key, + required super.child, + this.onNotification, + }); + + /// Called when a notification of the appropriate type arrives at this + /// location in the tree. + /// + /// Return true to cancel the notification bubbling. Return false to + /// allow the notification to continue to be dispatched to further ancestors. + /// + /// Notifications vary in terms of when they are dispatched. There are two + /// main possibilities: dispatch between frames, and dispatch during layout. + /// + /// For notifications that dispatch during layout, such as those that inherit + /// from [LayoutChangedNotification], it is too late to call [State.setState] + /// in response to the notification (as layout is currently happening in a + /// descendant, by definition, since notifications bubble up the tree). For + /// widgets that depend on layout, consider a [LayoutBuilder] instead. + final NotificationListenerCallback<T>? onNotification; + + @override + Element createElement() { + return _NotificationElement<T>(this); + } +} + +/// An element used to host [NotificationListener] elements. +class _NotificationElement<T extends Notification> extends ProxyElement with NotifiableElementMixin { + _NotificationElement(NotificationListener<T> super.widget); + + @override + bool onNotification(Notification notification) { + final NotificationListener<T> listener = widget as NotificationListener<T>; + if (listener.onNotification != null && notification is T) { + return listener.onNotification!(notification); + } + return false; + } + + @override + void notifyClients(covariant ProxyWidget oldWidget) { + // Notification tree does not need to notify clients. + } +} + +/// Indicates that the layout of one of the descendants of the object receiving +/// this notification has changed in some way, and that therefore any +/// assumptions about that layout are no longer valid. +/// +/// Useful if, for instance, you're trying to align multiple descendants. +/// +/// To listen for notifications in a subtree, use a +/// [NotificationListener<LayoutChangedNotification>]. +/// +/// To send a notification, call [dispatch] on the notification you wish to +/// send. The notification will be delivered to any [NotificationListener] +/// widgets with the appropriate type parameters that are ancestors of the given +/// [BuildContext]. +/// +/// In the widgets library, only the [SizeChangedLayoutNotifier] class and +/// [Scrollable] classes dispatch this notification (specifically, they dispatch +/// [SizeChangedLayoutNotification]s and [ScrollNotification]s respectively). +/// Transitions, in particular, do not. Changing one's layout in one's build +/// function does not cause this notification to be dispatched automatically. If +/// an ancestor expects to be notified for any layout change, make sure you +/// either only use widgets that never change layout, or that notify their +/// ancestors when appropriate, or alternatively, dispatch the notifications +/// yourself when appropriate. +/// +/// Also, since this notification is sent when the layout is changed, it is only +/// useful for paint effects that depend on the layout. If you were to use this +/// notification to change the build, for instance, you would always be one +/// frame behind, which would look really ugly and laggy. +class LayoutChangedNotification extends Notification { + /// Create a new [LayoutChangedNotification]. + const LayoutChangedNotification(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/orientation_builder.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/orientation_builder.dart new file mode 100644 index 0000000000000000000000000000000000000000..3ef6face3daf88767c3cb71ea92308bb6c43e6d2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/orientation_builder.dart @@ -0,0 +1,54 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'basic.dart'; +import 'framework.dart'; +import 'layout_builder.dart'; +import 'media_query.dart'; + +/// Signature for a function that builds a widget given an [Orientation]. +/// +/// Used by [OrientationBuilder.builder]. +typedef OrientationWidgetBuilder = Widget Function(BuildContext context, Orientation orientation); + +/// Builds a widget tree that can depend on the parent widget's orientation +/// (distinct from the device orientation). +/// +/// See also: +/// +/// * [LayoutBuilder], which exposes the complete constraints, not just the +/// orientation. +/// * [CustomSingleChildLayout], which positions its child during layout. +/// * [CustomMultiChildLayout], with which you can define the precise layout +/// of a list of children during the layout phase. +/// * [MediaQueryData.orientation], which exposes whether the device is in +/// landscape or portrait mode. +class OrientationBuilder extends StatelessWidget { + /// Creates an orientation builder. + const OrientationBuilder({ + super.key, + required this.builder, + }); + + /// Builds the widgets below this widget given this widget's orientation. + /// + /// A widget's orientation is a factor of its width relative to its + /// height. For example, a [Column] widget will have a landscape orientation + /// if its width exceeds its height, even though it displays its children in + /// a vertical array. + final OrientationWidgetBuilder builder; + + Widget _buildWithConstraints(BuildContext context, BoxConstraints constraints) { + // If the constraints are fully unbounded (i.e., maxWidth and maxHeight are + // both infinite), we prefer Orientation.portrait because its more common to + // scroll vertically then horizontally. + final Orientation orientation = constraints.maxWidth > constraints.maxHeight ? Orientation.landscape : Orientation.portrait; + return builder(context, orientation); + } + + @override + Widget build(BuildContext context) { + return LayoutBuilder(builder: _buildWithConstraints); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/overflow_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/overflow_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..75291df635af65a3eff480938e200a513b01bd4a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/overflow_bar.dart @@ -0,0 +1,572 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; + +/// Defines the horizontal alignment of [OverflowBar] children +/// when they're laid out in an overflow column. +/// +/// This value must be interpreted relative to the ambient +/// [TextDirection]. +enum OverflowBarAlignment { + /// Each child is left-aligned for [TextDirection.ltr], + /// right-aligned for [TextDirection.rtl]. + start, + + /// Each child is right-aligned for [TextDirection.ltr], + /// left-aligned for [TextDirection.rtl]. + end, + + /// Each child is horizontally centered. + center, +} + +/// A widget that lays out its [children] in a row unless they +/// "overflow" the available horizontal space, in which case it lays +/// them out in a column instead. +/// +/// This widget's width will expand to contain its children and the +/// specified [spacing] until it overflows. The overflow column will +/// consume all of the available width. The [overflowAlignment] +/// defines how each child will be aligned within the overflow column +/// and the [overflowSpacing] defines the gap between each child. +/// +/// The order that the children appear in the horizontal layout +/// is defined by the [textDirection], just like the [Row] widget. +/// If the layout overflows, then children's order within their +/// column is specified by [overflowDirection] instead. +/// +/// {@tool dartpad} +/// This example defines a simple approximation of a dialog +/// layout, where the layout of the dialog's action buttons are +/// defined by an [OverflowBar]. The content is wrapped in a +/// [SingleChildScrollView], so that if overflow occurs, the +/// action buttons will still be accessible by scrolling, +/// no matter how much vertical space is available. +/// +/// ** See code in examples/api/lib/widgets/overflow_bar/overflow_bar.0.dart ** +/// {@end-tool} +class OverflowBar extends MultiChildRenderObjectWidget { + /// Constructs an OverflowBar. + const OverflowBar({ + super.key, + this.spacing = 0.0, + this.alignment, + this.overflowSpacing = 0.0, + this.overflowAlignment = OverflowBarAlignment.start, + this.overflowDirection = VerticalDirection.down, + this.textDirection, + this.clipBehavior = Clip.none, + super.children, + }); + + /// The width of the gap between [children] for the default + /// horizontal layout. + /// + /// If the horizontal layout overflows, then [overflowSpacing] is + /// used instead. + /// + /// Defaults to 0.0. + final double spacing; + + /// Defines the [children]'s horizontal layout according to the same + /// rules as for [Row.mainAxisAlignment]. + /// + /// If this property is non-null, and the [children], separated by + /// [spacing], fit within the available width, then the overflow + /// bar will be as wide as possible. If the children do not fit + /// within the available width, then this property is ignored and + /// [overflowAlignment] applies instead. + /// + /// If this property is null (the default) then the overflow bar + /// will be no wider than needed to layout the [children] separated + /// by [spacing], modulo the incoming constraints. + /// + /// If [alignment] is one of [MainAxisAlignment.spaceAround], + /// [MainAxisAlignment.spaceBetween], or + /// [MainAxisAlignment.spaceEvenly], then the [spacing] parameter is + /// only used to see if the horizontal layout will overflow. + /// + /// Defaults to null. + /// + /// See also: + /// + /// * [overflowAlignment], the horizontal alignment of the [children] within + /// the vertical "overflow" layout. + /// + final MainAxisAlignment? alignment; + + /// The height of the gap between [children] in the vertical + /// "overflow" layout. + /// + /// This parameter is only used if the horizontal layout overflows, i.e. + /// if there isn't enough horizontal room for the [children] and [spacing]. + /// + /// Defaults to 0.0. + /// + /// See also: + /// + /// * [spacing], The width of the gap between each pair of children + /// for the default horizontal layout. + final double overflowSpacing; + + /// The horizontal alignment of the [children] within the vertical + /// "overflow" layout. + /// + /// This parameter is only used if the horizontal layout overflows, i.e. + /// if there isn't enough horizontal room for the [children] and [spacing]. + /// In that case the overflow bar will expand to fill the available + /// width and it will layout its [children] in a column. The + /// horizontal alignment of each child within that column is + /// defined by this parameter and the [textDirection]. If the + /// [textDirection] is [TextDirection.ltr] then each child will be + /// aligned with the left edge of the available space for + /// [OverflowBarAlignment.start], with the right edge of the + /// available space for [OverflowBarAlignment.end]. Similarly, if the + /// [textDirection] is [TextDirection.rtl] then each child will + /// be aligned with the right edge of the available space for + /// [OverflowBarAlignment.start], and with the left edge of the + /// available space for [OverflowBarAlignment.end]. For + /// [OverflowBarAlignment.center] each child is horizontally + /// centered within the available space. + /// + /// Defaults to [OverflowBarAlignment.start]. + /// + /// See also: + /// + /// * [alignment], which defines the [children]'s horizontal layout + /// (according to the same rules as for [Row.mainAxisAlignment]) when + /// the children, separated by [spacing], fit within the available space. + /// * [overflowDirection], which defines the order that the + /// [OverflowBar]'s children appear in, if the horizontal layout + /// overflows. + final OverflowBarAlignment overflowAlignment; + + /// Defines the order that the [children] appear in, if + /// the horizontal layout overflows. + /// + /// This parameter is only used if the horizontal layout overflows, i.e. + /// if there isn't enough horizontal room for the [children] and [spacing]. + /// + /// If the children do not fit into a single row, then they + /// are arranged in a column. The first child is at the top of the + /// column if this property is set to [VerticalDirection.down], since it + /// "starts" at the top and "ends" at the bottom. On the other hand, + /// the first child will be at the bottom of the column if this + /// property is set to [VerticalDirection.up], since it "starts" at the + /// bottom and "ends" at the top. + /// + /// Defaults to [VerticalDirection.down]. + /// + /// See also: + /// + /// * [overflowAlignment], which defines the horizontal alignment + /// of the children within the vertical "overflow" layout. + final VerticalDirection overflowDirection; + + /// Determines the order that the [children] appear in for the default + /// horizontal layout, and the interpretation of + /// [OverflowBarAlignment.start] and [OverflowBarAlignment.end] for + /// the vertical overflow layout. + /// + /// For the default horizontal layout, if [textDirection] is + /// [TextDirection.rtl] then the last child is laid out first. If + /// [textDirection] is [TextDirection.ltr] then the first child is + /// laid out first. + /// + /// If this parameter is null, then the value of + /// `Directionality.of(context)` is used. + /// + /// See also: + /// + /// * [overflowDirection], which defines the order that the + /// [OverflowBar]'s children appear in, if the horizontal layout + /// overflows. + /// * [Directionality], which defines the ambient directionality of + /// text and text-direction-sensitive render objects. + final TextDirection? textDirection; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + final Clip clipBehavior; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderOverflowBar( + spacing: spacing, + alignment: alignment, + overflowSpacing: overflowSpacing, + overflowAlignment: overflowAlignment, + overflowDirection: overflowDirection, + textDirection: textDirection ?? Directionality.of(context), + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderObject renderObject) { + (renderObject as _RenderOverflowBar) + ..spacing = spacing + ..alignment = alignment + ..overflowSpacing = overflowSpacing + ..overflowAlignment = overflowAlignment + ..overflowDirection = overflowDirection + ..textDirection = textDirection ?? Directionality.of(context) + ..clipBehavior = clipBehavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('spacing', spacing, defaultValue: 0)); + properties.add(EnumProperty<MainAxisAlignment>('alignment', alignment, defaultValue: null)); + properties.add(DoubleProperty('overflowSpacing', overflowSpacing, defaultValue: 0)); + properties.add(EnumProperty<OverflowBarAlignment>('overflowAlignment', overflowAlignment, defaultValue: OverflowBarAlignment.start)); + properties.add(EnumProperty<VerticalDirection>('overflowDirection', overflowDirection, defaultValue: VerticalDirection.down)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + } +} + +class _OverflowBarParentData extends ContainerBoxParentData<RenderBox> { } + +class _RenderOverflowBar extends RenderBox + with ContainerRenderObjectMixin<RenderBox, _OverflowBarParentData>, + RenderBoxContainerDefaultsMixin<RenderBox, _OverflowBarParentData> { + _RenderOverflowBar({ + List<RenderBox>? children, + double spacing = 0.0, + MainAxisAlignment? alignment, + double overflowSpacing = 0.0, + OverflowBarAlignment overflowAlignment = OverflowBarAlignment.start, + VerticalDirection overflowDirection = VerticalDirection.down, + required TextDirection textDirection, + Clip clipBehavior = Clip.none, + }) : _spacing = spacing, + _alignment = alignment, + _overflowSpacing = overflowSpacing, + _overflowAlignment = overflowAlignment, + _overflowDirection = overflowDirection, + _textDirection = textDirection, + _clipBehavior = clipBehavior { + addAll(children); + } + + double get spacing => _spacing; + double _spacing; + set spacing (double value) { + if (_spacing == value) { + return; + } + _spacing = value; + markNeedsLayout(); + } + + MainAxisAlignment? get alignment => _alignment; + MainAxisAlignment? _alignment; + set alignment (MainAxisAlignment? value) { + if (_alignment == value) { + return; + } + _alignment = value; + markNeedsLayout(); + } + + double get overflowSpacing => _overflowSpacing; + double _overflowSpacing; + set overflowSpacing (double value) { + if (_overflowSpacing == value) { + return; + } + _overflowSpacing = value; + markNeedsLayout(); + } + + OverflowBarAlignment get overflowAlignment => _overflowAlignment; + OverflowBarAlignment _overflowAlignment; + set overflowAlignment (OverflowBarAlignment value) { + if (_overflowAlignment == value) { + return; + } + _overflowAlignment = value; + markNeedsLayout(); + } + + VerticalDirection get overflowDirection => _overflowDirection; + VerticalDirection _overflowDirection; + set overflowDirection (VerticalDirection value) { + if (_overflowDirection == value) { + return; + } + _overflowDirection = value; + markNeedsLayout(); + } + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + markNeedsLayout(); + } + + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.none; + set clipBehavior(Clip value) { + if (value == _clipBehavior) { + return; + } + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! _OverflowBarParentData) { + child.parentData = _OverflowBarParentData(); + } + } + + @override + double computeMinIntrinsicHeight(double width) { + RenderBox? child = firstChild; + if (child == null) { + return 0; + } + double barWidth = 0.0; + while (child != null) { + barWidth += child.getMinIntrinsicWidth(double.infinity); + child = childAfter(child); + } + barWidth += spacing * (childCount - 1); + + double height = 0.0; + if (barWidth > width) { + child = firstChild; + while (child != null) { + height += child.getMinIntrinsicHeight(width); + child = childAfter(child); + } + return height + overflowSpacing * (childCount - 1); + } else { + child = firstChild; + while (child != null) { + height = math.max(height, child.getMinIntrinsicHeight(width)); + child = childAfter(child); + } + return height; + } + } + + @override + double computeMaxIntrinsicHeight(double width) { + RenderBox? child = firstChild; + if (child == null) { + return 0; + } + double barWidth = 0.0; + while (child != null) { + barWidth += child.getMinIntrinsicWidth(double.infinity); + child = childAfter(child); + } + barWidth += spacing * (childCount - 1); + + double height = 0.0; + if (barWidth > width) { + child = firstChild; + while (child != null) { + height += child.getMaxIntrinsicHeight(width); + child = childAfter(child); + } + return height + overflowSpacing * (childCount - 1); + } else { + child = firstChild; + while (child != null) { + height = math.max(height, child.getMaxIntrinsicHeight(width)); + child = childAfter(child); + } + return height; + } + } + + @override + double computeMinIntrinsicWidth(double height) { + RenderBox? child = firstChild; + if (child == null) { + return 0; + } + double width = 0.0; + while (child != null) { + width += child.getMinIntrinsicWidth(double.infinity); + child = childAfter(child); + } + return width + spacing * (childCount - 1); + } + + @override + double computeMaxIntrinsicWidth(double height) { + RenderBox? child = firstChild; + if (child == null) { + return 0; + } + double width = 0.0; + while (child != null) { + width += child.getMaxIntrinsicWidth(double.infinity); + child = childAfter(child); + } + return width + spacing * (childCount - 1); + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + return defaultComputeDistanceToHighestActualBaseline(baseline); + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + RenderBox? child = firstChild; + if (child == null) { + return constraints.smallest; + } + final BoxConstraints childConstraints = constraints.loosen(); + double childrenWidth = 0.0; + double maxChildHeight = 0.0; + double y = 0.0; + while (child != null) { + final Size childSize = child.getDryLayout(childConstraints); + childrenWidth += childSize.width; + maxChildHeight = math.max(maxChildHeight, childSize.height); + y += childSize.height + overflowSpacing; + child = childAfter(child); + } + final double actualWidth = childrenWidth + spacing * (childCount - 1); + if (actualWidth > constraints.maxWidth) { + return constraints.constrain(Size(constraints.maxWidth, y - overflowSpacing)); + } else { + final double overallWidth = alignment == null ? actualWidth : constraints.maxWidth; + return constraints.constrain(Size(overallWidth, maxChildHeight)); + } + } + + @override + void performLayout() { + RenderBox? child = firstChild; + if (child == null) { + size = constraints.smallest; + return; + } + + final BoxConstraints childConstraints = constraints.loosen(); + double childrenWidth = 0; + double maxChildHeight = 0; + double maxChildWidth = 0; + + while (child != null) { + child.layout(childConstraints, parentUsesSize: true); + childrenWidth += child.size.width; + maxChildHeight = math.max(maxChildHeight, child.size.height); + maxChildWidth = math.max(maxChildWidth, child.size.width); + child = childAfter(child); + } + + final bool rtl = textDirection == TextDirection.rtl; + final double actualWidth = childrenWidth + spacing * (childCount - 1); + + if (actualWidth > constraints.maxWidth) { + // Overflow vertical layout + child = overflowDirection == VerticalDirection.down ? firstChild : lastChild; + RenderBox? nextChild() => overflowDirection == VerticalDirection.down ? childAfter(child!) : childBefore(child!); + double y = 0; + while (child != null) { + final _OverflowBarParentData childParentData = child.parentData! as _OverflowBarParentData; + double x = 0; + switch (overflowAlignment) { + case OverflowBarAlignment.start: + x = rtl ? constraints.maxWidth - child.size.width : 0; + case OverflowBarAlignment.center: + x = (constraints.maxWidth - child.size.width) / 2; + case OverflowBarAlignment.end: + x = rtl ? 0 : constraints.maxWidth - child.size.width; + } + childParentData.offset = Offset(x, y); + y += child.size.height + overflowSpacing; + child = nextChild(); + } + size = constraints.constrain(Size(constraints.maxWidth, y - overflowSpacing)); + } else { + // Default horizontal layout + child = firstChild; + final double firstChildWidth = child!.size.width; + final double overallWidth = alignment == null ? actualWidth : constraints.maxWidth; + size = constraints.constrain(Size(overallWidth, maxChildHeight)); + + late double x; // initial value: origin of the first child + double layoutSpacing = spacing; // space between children + switch (alignment) { + case null: + x = rtl ? size.width - firstChildWidth : 0; + case MainAxisAlignment.start: + x = rtl ? size.width - firstChildWidth : 0; + case MainAxisAlignment.center: + final double halfRemainingWidth = (size.width - actualWidth) / 2; + x = rtl ? size.width - halfRemainingWidth - firstChildWidth : halfRemainingWidth; + case MainAxisAlignment.end: + x = rtl ? actualWidth - firstChildWidth : size.width - actualWidth; + case MainAxisAlignment.spaceBetween: + layoutSpacing = (size.width - childrenWidth) / (childCount - 1); + x = rtl ? size.width - firstChildWidth : 0; + case MainAxisAlignment.spaceAround: + layoutSpacing = childCount > 0 ? (size.width - childrenWidth) / childCount : 0; + x = rtl ? size.width - layoutSpacing / 2 - firstChildWidth : layoutSpacing / 2; + case MainAxisAlignment.spaceEvenly: + layoutSpacing = (size.width - childrenWidth) / (childCount + 1); + x = rtl ? size.width - layoutSpacing - firstChildWidth : layoutSpacing; + } + + while (child != null) { + final _OverflowBarParentData childParentData = child.parentData! as _OverflowBarParentData; + childParentData.offset = Offset(x, (maxChildHeight - child.size.height) / 2); + // x is the horizontal origin of child. To advance x to the next child's + // origin for LTR: add the width of the current child. To advance x to + // the origin of the next child for RTL: subtract the width of the next + // child (if there is one). + if (!rtl) { + x += child.size.width + layoutSpacing; + } + child = childAfter(child); + if (rtl && child != null) { + x -= child.size.width + layoutSpacing; + } + } + } + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + return defaultHitTestChildren(result, position: position); + } + + @override + void paint(PaintingContext context, Offset offset) { + defaultPaint(context, offset); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('spacing', spacing, defaultValue: 0)); + properties.add(DoubleProperty('overflowSpacing', overflowSpacing, defaultValue: 0)); + properties.add(EnumProperty<OverflowBarAlignment>('overflowAlignment', overflowAlignment, defaultValue: OverflowBarAlignment.start)); + properties.add(EnumProperty<VerticalDirection>('overflowDirection', overflowDirection, defaultValue: VerticalDirection.down)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/overlay.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/overlay.dart new file mode 100644 index 0000000000000000000000000000000000000000..1f178f4484b065669e6295697e0d76fdb1410cfd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/overlay.dart @@ -0,0 +1,2371 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'lookup_boundary.dart'; +import 'ticker_provider.dart'; + +const String _flutterWidgetsLibrary = 'package:flutter/widgets.dart'; + +// Examples can assume: +// late BuildContext context; + +// * OverlayEntry Implementation + +/// A place in an [Overlay] that can contain a widget. +/// +/// Overlay entries are inserted into an [Overlay] using the +/// [OverlayState.insert] or [OverlayState.insertAll] functions. To find the +/// closest enclosing overlay for a given [BuildContext], use the [Overlay.of] +/// function. +/// +/// An overlay entry can be in at most one overlay at a time. To remove an entry +/// from its overlay, call the [remove] function on the overlay entry. +/// +/// Because an [Overlay] uses a [Stack] layout, overlay entries can use +/// [Positioned] and [AnimatedPositioned] to position themselves within the +/// overlay. +/// +/// For example, [Draggable] uses an [OverlayEntry] to show the drag avatar that +/// follows the user's finger across the screen after the drag begins. Using the +/// overlay to display the drag avatar lets the avatar float over the other +/// widgets in the app. As the user's finger moves, draggable calls +/// [markNeedsBuild] on the overlay entry to cause it to rebuild. In its build, +/// the entry includes a [Positioned] with its top and left property set to +/// position the drag avatar near the user's finger. When the drag is over, +/// [Draggable] removes the entry from the overlay to remove the drag avatar +/// from view. +/// +/// By default, if there is an entirely [opaque] entry over this one, then this +/// one will not be included in the widget tree (in particular, stateful widgets +/// within the overlay entry will not be instantiated). To ensure that your +/// overlay entry is still built even if it is not visible, set [maintainState] +/// to true. This is more expensive, so should be done with care. In particular, +/// if widgets in an overlay entry with [maintainState] set to true repeatedly +/// call [State.setState], the user's battery will be drained unnecessarily. +/// +/// [OverlayEntry] is a [Listenable] that notifies when the widget built by +/// [builder] is mounted or unmounted, whose exact state can be queried by +/// [mounted]. After the owner of the [OverlayEntry] calls [remove] and then +/// [dispose], the widget may not be immediately removed from the widget tree. +/// As a result listeners of the [OverlayEntry] can get notified for one last +/// time after the [dispose] call, when the widget is eventually unmounted. +/// +/// {@macro flutter.widgets.overlayPortalVsOverlayEntry} +/// +/// See also: +/// +/// * [OverlayPortal], an alternative API for inserting widgets into an +/// [Overlay] using a builder callback. +/// * [Overlay], a stack of entries that can be managed independently. +/// * [OverlayState], the current state of an Overlay. +/// * [WidgetsApp], a convenience widget that wraps a number of widgets that +/// are commonly required for an application. +/// * [MaterialApp], a convenience widget that wraps a number of widgets that +/// are commonly required for Material Design applications. +class OverlayEntry implements Listenable { + /// Creates an overlay entry. + /// + /// To insert the entry into an [Overlay], first find the overlay using + /// [Overlay.of] and then call [OverlayState.insert]. To remove the entry, + /// call [remove] on the overlay entry itself. + OverlayEntry({ + required this.builder, + bool opaque = false, + bool maintainState = false, + this.canSizeOverlay = false, + }) : _opaque = opaque, + _maintainState = maintainState { + if (kFlutterMemoryAllocationsEnabled) { + _maybeDispatchObjectCreation(); + } + } + + /// This entry will include the widget built by this builder in the overlay at + /// the entry's position. + /// + /// To cause this builder to be called again, call [markNeedsBuild] on this + /// overlay entry. + final WidgetBuilder builder; + + /// Whether this entry occludes the entire overlay. + /// + /// If an entry claims to be opaque, then, for efficiency, the overlay will + /// skip building entries below that entry unless they have [maintainState] + /// set. + bool get opaque => _opaque; + bool _opaque; + set opaque(bool value) { + assert(!_disposedByOwner); + if (_opaque == value) { + return; + } + _opaque = value; + _overlay?._didChangeEntryOpacity(); + } + + /// Whether this entry must be included in the tree even if there is a fully + /// [opaque] entry above it. + /// + /// By default, if there is an entirely [opaque] entry over this one, then this + /// one will not be included in the widget tree (in particular, stateful widgets + /// within the overlay entry will not be instantiated). To ensure that your + /// overlay entry is still built even if it is not visible, set [maintainState] + /// to true. This is more expensive, so should be done with care. In particular, + /// if widgets in an overlay entry with [maintainState] set to true repeatedly + /// call [State.setState], the user's battery will be drained unnecessarily. + /// + /// This is used by the [Navigator] and [Route] objects to ensure that routes + /// are kept around even when in the background, so that [Future]s promised + /// from subsequent routes will be handled properly when they complete. + bool get maintainState => _maintainState; + bool _maintainState; + set maintainState(bool value) { + assert(!_disposedByOwner); + if (_maintainState == value) { + return; + } + _maintainState = value; + assert(_overlay != null); + _overlay!._didChangeEntryOpacity(); + } + + /// Whether the content of this [OverlayEntry] can be used to size the + /// [Overlay]. + /// + /// In most situations the overlay sizes itself based on its incoming + /// constraints to be as large as possible. However, if that would result in + /// an infinite size, it has to rely on one of its children to size itself. In + /// this situation, the overlay will consult the topmost non-[Positioned] + /// overlay entry that has this property set to true, lay it out with the + /// incoming [BoxConstraints] of the overlay, and force all other + /// non-[Positioned] overlay entries to have the same size. The [Positioned] + /// entries are laid out as usual based on the calculated size of the overlay. + /// + /// Overlay entries that set this to true must be able to handle unconstrained + /// [BoxConstraints]. + /// + /// Setting this to true has no effect if the overlay entry uses a [Positioned] + /// widget to position itself in the overlay. + final bool canSizeOverlay; + + /// Whether the [OverlayEntry] is currently mounted in the widget tree. + /// + /// The [OverlayEntry] notifies its listeners when this value changes. + bool get mounted => _overlayEntryStateNotifier?.value != null; + + /// The currently mounted `_OverlayEntryWidgetState` built using this [OverlayEntry]. + ValueNotifier<_OverlayEntryWidgetState?>? _overlayEntryStateNotifier = ValueNotifier<_OverlayEntryWidgetState?>(null); + + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + /// Dispatches event of object creation to [FlutterMemoryAllocations.instance]. + void _maybeDispatchObjectCreation() { + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: _flutterWidgetsLibrary, + className: '$OverlayEntry', + object: this, + ); + } + } + + @override + void addListener(VoidCallback listener) { + assert(!_disposedByOwner); + _overlayEntryStateNotifier?.addListener(listener); + } + + @override + void removeListener(VoidCallback listener) { + _overlayEntryStateNotifier?.removeListener(listener); + } + + OverlayState? _overlay; + final GlobalKey<_OverlayEntryWidgetState> _key = GlobalKey<_OverlayEntryWidgetState>(); + + /// Remove this entry from the overlay. + /// + /// This should only be called once. + /// + /// This method removes this overlay entry from the overlay immediately. The + /// UI will be updated in the same frame if this method is called before the + /// overlay rebuild in this frame; otherwise, the UI will be updated in the + /// next frame. This means that it is safe to call during builds, but also + /// that if you do call this after the overlay rebuild, the UI will not update + /// until the next frame (i.e. many milliseconds later). + void remove() { + assert(_overlay != null); + assert(!_disposedByOwner); + final OverlayState overlay = _overlay!; + _overlay = null; + if (!overlay.mounted) { + return; + } + + overlay._entries.remove(this); + if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks) { + SchedulerBinding.instance.addPostFrameCallback((Duration duration) { + overlay._markDirty(); + }, debugLabel: 'OverlayEntry.markDirty'); + } else { + overlay._markDirty(); + } + } + + /// Cause this entry to rebuild during the next pipeline flush. + /// + /// You need to call this function if the output of [builder] has changed. + void markNeedsBuild() { + assert(!_disposedByOwner); + _key.currentState?._markNeedsBuild(); + } + + void _didUnmount() { + assert(!mounted); + if (_disposedByOwner) { + _overlayEntryStateNotifier?.dispose(); + _overlayEntryStateNotifier = null; + } + } + + bool _disposedByOwner = false; + + /// Discards any resources used by this [OverlayEntry]. + /// + /// This method must be called after [remove] if the [OverlayEntry] is + /// inserted into an [Overlay]. + /// + /// After this is called, the object is not in a usable state and should be + /// discarded (calls to [addListener] will throw after the object is disposed). + /// However, the listeners registered may not be immediately released until + /// the widget built using this [OverlayEntry] is unmounted from the widget + /// tree. + /// + /// This method should only be called by the object's owner. + void dispose() { + assert(!_disposedByOwner); + assert(_overlay == null, 'An OverlayEntry must first be removed from the Overlay before dispose is called.'); + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _disposedByOwner = true; + if (!mounted) { + // If we're still mounted when disposed, then this will be disposed in + // _didUnmount, to allow notifications to occur until the entry is + // unmounted. + _overlayEntryStateNotifier?.dispose(); + _overlayEntryStateNotifier = null; + } + } + + @override + String toString() => '${describeIdentity(this)}(opaque: $opaque; maintainState: $maintainState)${_disposedByOwner ? "(DISPOSED)" : ""}'; +} + +class _OverlayEntryWidget extends StatefulWidget { + const _OverlayEntryWidget({ + required Key key, + required this.entry, + required this.overlayState, + this.tickerEnabled = true, + }) : super(key: key); + + final OverlayEntry entry; + final OverlayState overlayState; + final bool tickerEnabled; + + @override + _OverlayEntryWidgetState createState() => _OverlayEntryWidgetState(); +} + +class _OverlayEntryWidgetState extends State<_OverlayEntryWidget> { + late _RenderTheater _theater; + + // Manages the stack of theater children whose paint order are sorted by their + // _zOrderIndex. The children added by OverlayPortal are added to this linked + // list, and they will be shown _above_ the OverlayEntry tied to this widget. + // The children with larger zOrderIndex values (i.e. those called `show` + // recently) will be painted last. + // + // This linked list is lazily created in `_add`, and the entries are added/removed + // via `_add`/`_remove`, called by OverlayPortals lower in the tree. `_add` or + // `_remove` does not cause this widget to rebuild, the linked list will be + // read by _RenderTheater as part of its render child model. This would ideally + // be in a RenderObject but there may not be RenderObjects between + // _RenderTheater and the render subtree OverlayEntry builds. + LinkedList<_OverlayEntryLocation>? _sortedTheaterSiblings; + + // Worst-case O(N), N being the number of children added to the top spot in + // the same frame. This can be a bit expensive when there's a lot of global + // key reparenting in the same frame but N is usually a small number. + void _add(_OverlayEntryLocation child) { + assert(mounted); + final LinkedList<_OverlayEntryLocation> children = _sortedTheaterSiblings ??= LinkedList<_OverlayEntryLocation>(); + assert(!children.contains(child)); + _OverlayEntryLocation? insertPosition = children.isEmpty ? null : children.last; + while (insertPosition != null && insertPosition._zOrderIndex > child._zOrderIndex) { + insertPosition = insertPosition.previous; + } + if (insertPosition == null) { + children.addFirst(child); + } else { + insertPosition.insertAfter(child); + } + assert(children.contains(child)); + } + + void _remove(_OverlayEntryLocation child) { + assert(_sortedTheaterSiblings != null); + final bool wasInCollection = _sortedTheaterSiblings?.remove(child) ?? false; + assert(wasInCollection); + } + + // Returns an Iterable that traverse the children in the child model in paint + // order (from farthest to the user to the closest to the user). + // + // The iterator should be safe to use even when the child model is being + // mutated. The reason for that is it's allowed to add/remove/move deferred + // children to a _RenderTheater during performLayout, but the affected + // children don't have to be laid out in the same performLayout call. + late final Iterable<RenderBox> _paintOrderIterable = _createChildIterable(reversed: false); + // An Iterable that traverse the children in the child model in + // hit-test order (from closest to the user to the farthest to the user). + late final Iterable<RenderBox> _hitTestOrderIterable = _createChildIterable(reversed: true); + + // The following uses sync* because hit-testing is lazy, and LinkedList as a + // Iterable doesn't support concurrent modification. + Iterable<RenderBox> _createChildIterable({ required bool reversed }) sync* { + final LinkedList<_OverlayEntryLocation>? children = _sortedTheaterSiblings; + if (children == null || children.isEmpty) { + return; + } + _OverlayEntryLocation? candidate = reversed ? children.last : children.first; + while (candidate != null) { + final RenderBox? renderBox = candidate._overlayChildRenderBox; + candidate = reversed ? candidate.previous : candidate.next; + if (renderBox != null) { + yield renderBox; + } + } + } + + @override + void initState() { + super.initState(); + widget.entry._overlayEntryStateNotifier!.value = this; + _theater = context.findAncestorRenderObjectOfType<_RenderTheater>()!; + assert(_sortedTheaterSiblings == null); + } + + @override + void didUpdateWidget(_OverlayEntryWidget oldWidget) { + super.didUpdateWidget(oldWidget); + // OverlayState's build method always returns a RenderObjectWidget _Theater, + // so it's safe to assume that state equality implies render object equality. + assert(oldWidget.entry == widget.entry); + if (oldWidget.overlayState != widget.overlayState) { + final _RenderTheater newTheater = context.findAncestorRenderObjectOfType<_RenderTheater>()!; + assert(_theater != newTheater); + _theater = newTheater; + } + } + + @override + void dispose() { + widget.entry._overlayEntryStateNotifier?.value = null; + widget.entry._didUnmount(); + _sortedTheaterSiblings = null; + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return TickerMode( + enabled: widget.tickerEnabled, + child: _RenderTheaterMarker( + theater: _theater, + overlayEntryWidgetState: this, + child: widget.entry.builder(context), + ), + ); + } + + void _markNeedsBuild() { + setState(() { /* the state that changed is in the builder */ }); + } +} + +/// A stack of entries that can be managed independently. +/// +/// Overlays let independent child widgets "float" visual elements on top of +/// other widgets by inserting them into the overlay's stack. The overlay lets +/// each of these widgets manage their participation in the overlay using +/// [OverlayEntry] objects. +/// +/// Although you can create an [Overlay] directly, it's most common to use the +/// overlay created by the [Navigator] in a [WidgetsApp], [CupertinoApp] or a +/// [MaterialApp]. The navigator uses its overlay to manage the visual +/// appearance of its routes. +/// +/// The [Overlay] widget uses a custom stack implementation, which is very +/// similar to the [Stack] widget. The main use case of [Overlay] is related to +/// navigation and being able to insert widgets on top of the pages in an app. +/// For layout purposes unrelated to navigation, consider using [Stack] instead. +/// +/// An [Overlay] widget requires a [Directionality] widget to be in scope, so +/// that it can resolve direction-sensitive coordinates of any +/// [Positioned.directional] children. +/// +/// For widgets drawn in an [OverlayEntry], do not assume that the size of the +/// [Overlay] is the size returned by [MediaQuery.sizeOf]. Nested overlays can +/// have different sizes. +/// +/// {@tool dartpad} +/// This example shows how to use the [Overlay] to highlight the [NavigationBar] +/// destination. +/// +/// ** See code in examples/api/lib/widgets/overlay/overlay.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [OverlayEntry], the class that is used for describing the overlay entries. +/// * [OverlayState], which is used to insert the entries into the overlay. +/// * [WidgetsApp], which inserts an [Overlay] widget indirectly via its [Navigator]. +/// * [MaterialApp], which inserts an [Overlay] widget indirectly via its [Navigator]. +/// * [CupertinoApp], which inserts an [Overlay] widget indirectly via its [Navigator]. +/// * [Stack], which allows directly displaying a stack of widgets. +class Overlay extends StatefulWidget { + /// Creates an overlay. + /// + /// The initial entries will be inserted into the overlay when its associated + /// [OverlayState] is initialized. + /// + /// Rather than creating an overlay, consider using the overlay that is + /// created by the [Navigator] in a [WidgetsApp], [CupertinoApp], or a + /// [MaterialApp] for the application. + const Overlay({ + super.key, + this.initialEntries = const <OverlayEntry>[], + this.clipBehavior = Clip.hardEdge, + }); + + /// Wrap the provided `child` in an [Overlay] to allow other visual elements + /// (packed in [OverlayEntry]s) to float on top of the child. + /// + /// This is a convenience method over the regular [Overlay] constructor: It + /// creates an [Overlay] and puts the provided `child` in an [OverlayEntry] + /// at the bottom of that newly created Overlay. + static Widget wrap({ + Key? key, + Clip clipBehavior = Clip.hardEdge, + required Widget child, + }) { + return _WrappingOverlay(key: key, clipBehavior: clipBehavior, child: child); + } + + /// The entries to include in the overlay initially. + /// + /// These entries are only used when the [OverlayState] is initialized. If you + /// are providing a new [Overlay] description for an overlay that's already in + /// the tree, then the new entries are ignored. + /// + /// To add entries to an [Overlay] that is already in the tree, use + /// [Overlay.of] to obtain the [OverlayState] (or assign a [GlobalKey] to the + /// [Overlay] widget and obtain the [OverlayState] via + /// [GlobalKey.currentState]), and then use [OverlayState.insert] or + /// [OverlayState.insertAll]. + /// + /// To remove an entry from an [Overlay], use [OverlayEntry.remove]. + final List<OverlayEntry> initialEntries; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// The [OverlayState] from the closest instance of [Overlay] that encloses + /// the given context within the closest [LookupBoundary], and, in debug mode, + /// will throw if one is not found. + /// + /// In debug mode, if the `debugRequiredFor` argument is provided and an + /// overlay isn't found, then this function will throw an exception containing + /// the runtime type of the given widget in the error message. The exception + /// attempts to explain that the calling [Widget] (the one given by the + /// `debugRequiredFor` argument) needs an [Overlay] to be present to function. + /// If `debugRequiredFor` is not supplied, then the error message is more + /// generic. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// OverlayState overlay = Overlay.of(context); + /// ``` + /// + /// If `rootOverlay` is set to true, the state from the furthest instance of + /// this class is given instead. Useful for installing overlay entries above + /// all subsequent instances of [Overlay]. + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [Overlay.maybeOf] for a similar function that returns null if an + /// [Overlay] is not found. + static OverlayState of( + BuildContext context, { + bool rootOverlay = false, + Widget? debugRequiredFor, + }) { + final OverlayState? result = maybeOf(context, rootOverlay: rootOverlay); + assert(() { + if (result == null) { + final bool hiddenByBoundary = LookupBoundary.debugIsHidingAncestorStateOfType<OverlayState>(context); + final List<DiagnosticsNode> information = <DiagnosticsNode>[ + ErrorSummary('No Overlay widget found${hiddenByBoundary ? ' within the closest LookupBoundary' : ''}.'), + if (hiddenByBoundary) + ErrorDescription( + 'There is an ancestor Overlay widget, but it is hidden by a LookupBoundary.' + ), + ErrorDescription('${debugRequiredFor?.runtimeType ?? 'Some'} widgets require an Overlay widget ancestor for correct operation.'), + ErrorHint('The most common way to add an Overlay to an application is to include a MaterialApp, CupertinoApp or Navigator widget in the runApp() call.'), + if (debugRequiredFor != null) DiagnosticsProperty<Widget>('The specific widget that failed to find an overlay was', debugRequiredFor, style: DiagnosticsTreeStyle.errorProperty), + if (context.widget != debugRequiredFor) + context.describeElement('The context from which that widget was searching for an overlay was'), + ]; + + throw FlutterError.fromParts(information); + } + return true; + }()); + return result!; + } + + /// The [OverlayState] from the closest instance of [Overlay] that encloses + /// the given context within the closest [LookupBoundary], if any. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// OverlayState? overlay = Overlay.maybeOf(context); + /// ``` + /// + /// If `rootOverlay` is set to true, the state from the furthest instance of + /// this class is given instead. Useful for installing overlay entries above + /// all subsequent instances of [Overlay]. + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [Overlay.of] for a similar function that returns a non-nullable result + /// and throws if an [Overlay] is not found. + + static OverlayState? maybeOf( + BuildContext context, { + bool rootOverlay = false, + }) { + return rootOverlay + ? LookupBoundary.findRootAncestorStateOfType<OverlayState>(context) + : LookupBoundary.findAncestorStateOfType<OverlayState>(context); + } + + @override + OverlayState createState() => OverlayState(); +} + +/// The current state of an [Overlay]. +/// +/// Used to insert [OverlayEntry]s into the overlay using the [insert] and +/// [insertAll] functions. +class OverlayState extends State<Overlay> with TickerProviderStateMixin { + final List<OverlayEntry> _entries = <OverlayEntry>[]; + + @override + void initState() { + super.initState(); + insertAll(widget.initialEntries); + } + + int _insertionIndex(OverlayEntry? below, OverlayEntry? above) { + assert(above == null || below == null); + if (below != null) { + return _entries.indexOf(below); + } + if (above != null) { + return _entries.indexOf(above) + 1; + } + return _entries.length; + } + + bool _debugCanInsertEntry(OverlayEntry entry) { + final List<DiagnosticsNode> operandsInformation = <DiagnosticsNode>[ + DiagnosticsProperty<OverlayEntry>('The OverlayEntry was', entry, style: DiagnosticsTreeStyle.errorProperty), + DiagnosticsProperty<OverlayState>( + 'The Overlay the OverlayEntry was trying to insert to was', this, style: DiagnosticsTreeStyle.errorProperty, + ), + ]; + + if (!mounted) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Attempted to insert an OverlayEntry to an already disposed Overlay.'), + ...operandsInformation, + ]); + } + + final OverlayState? currentOverlay = entry._overlay; + final bool alreadyContainsEntry = _entries.contains(entry); + + if (alreadyContainsEntry) { + final bool inconsistentOverlayState = !identical(currentOverlay, this); + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The specified entry is already present in the target Overlay.'), + ...operandsInformation, + if (inconsistentOverlayState) ErrorHint('This could be an error in the Flutter framework.') + else ErrorHint( + 'Consider calling remove on the OverlayEntry before inserting it to a different Overlay, ' + 'or switching to the OverlayPortal API to avoid manual OverlayEntry management.' + ), + if (inconsistentOverlayState) DiagnosticsProperty<OverlayState>( + "The OverlayEntry's current Overlay was", currentOverlay, style: DiagnosticsTreeStyle.errorProperty, + ), + ]); + } + + if (currentOverlay == null) { + return true; + } + + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The specified entry is already present in a different Overlay.'), + ...operandsInformation, + DiagnosticsProperty<OverlayState>("The OverlayEntry's current Overlay was", currentOverlay, style: DiagnosticsTreeStyle.errorProperty,), + ErrorHint( + 'Consider calling remove on the OverlayEntry before inserting it to a different Overlay, ' + 'or switching to the OverlayPortal API to avoid manual OverlayEntry management.' + ) + ]); + } + + /// Insert the given entry into the overlay. + /// + /// If `below` is non-null, the entry is inserted just below `below`. + /// If `above` is non-null, the entry is inserted just above `above`. + /// Otherwise, the entry is inserted on top. + /// + /// It is an error to specify both `above` and `below`. + void insert(OverlayEntry entry, { OverlayEntry? below, OverlayEntry? above }) { + assert(_debugVerifyInsertPosition(above, below)); + assert(_debugCanInsertEntry(entry)); + entry._overlay = this; + setState(() { + _entries.insert(_insertionIndex(below, above), entry); + }); + } + + /// Insert all the entries in the given iterable. + /// + /// If `below` is non-null, the entries are inserted just below `below`. + /// If `above` is non-null, the entries are inserted just above `above`. + /// Otherwise, the entries are inserted on top. + /// + /// It is an error to specify both `above` and `below`. + void insertAll(Iterable<OverlayEntry> entries, { OverlayEntry? below, OverlayEntry? above }) { + assert(_debugVerifyInsertPosition(above, below)); + assert(entries.every(_debugCanInsertEntry)); + if (entries.isEmpty) { + return; + } + for (final OverlayEntry entry in entries) { + assert(entry._overlay == null); + entry._overlay = this; + } + setState(() { + _entries.insertAll(_insertionIndex(below, above), entries); + }); + } + + bool _debugVerifyInsertPosition(OverlayEntry? above, OverlayEntry? below, { Iterable<OverlayEntry>? newEntries }) { + assert( + above == null || below == null, + 'Only one of `above` and `below` may be specified.', + ); + assert( + above == null || (above._overlay == this && _entries.contains(above) && (newEntries?.contains(above) ?? true)), + 'The provided entry used for `above` must be present in the Overlay${newEntries != null ? ' and in the `newEntriesList`' : ''}.', + ); + assert( + below == null || (below._overlay == this && _entries.contains(below) && (newEntries?.contains(below) ?? true)), + 'The provided entry used for `below` must be present in the Overlay${newEntries != null ? ' and in the `newEntriesList`' : ''}.', + ); + return true; + } + + /// Remove all the entries listed in the given iterable, then reinsert them + /// into the overlay in the given order. + /// + /// Entries mention in `newEntries` but absent from the overlay are inserted + /// as if with [insertAll]. + /// + /// Entries not mentioned in `newEntries` but present in the overlay are + /// positioned as a group in the resulting list relative to the entries that + /// were moved, as specified by one of `below` or `above`, which, if + /// specified, must be one of the entries in `newEntries`: + /// + /// If `below` is non-null, the group is positioned just below `below`. + /// If `above` is non-null, the group is positioned just above `above`. + /// Otherwise, the group is left on top, with all the rearranged entries + /// below. + /// + /// It is an error to specify both `above` and `below`. + void rearrange(Iterable<OverlayEntry> newEntries, { OverlayEntry? below, OverlayEntry? above }) { + final List<OverlayEntry> newEntriesList = newEntries is List<OverlayEntry> ? newEntries : newEntries.toList(growable: false); + assert(_debugVerifyInsertPosition(above, below, newEntries: newEntriesList)); + assert( + newEntriesList.every((OverlayEntry entry) => entry._overlay == null || entry._overlay == this), + 'One or more of the specified entries are already present in another Overlay.', + ); + assert( + newEntriesList.every((OverlayEntry entry) => _entries.indexOf(entry) == _entries.lastIndexOf(entry)), + 'One or more of the specified entries are specified multiple times.', + ); + if (newEntriesList.isEmpty) { + return; + } + if (listEquals(_entries, newEntriesList)) { + return; + } + final LinkedHashSet<OverlayEntry> old = LinkedHashSet<OverlayEntry>.of(_entries); + for (final OverlayEntry entry in newEntriesList) { + entry._overlay ??= this; + } + setState(() { + _entries.clear(); + _entries.addAll(newEntriesList); + old.removeAll(newEntriesList); + _entries.insertAll(_insertionIndex(below, above), old); + }); + } + + void _markDirty() { + if (mounted) { + setState(() {}); + } + } + + /// (DEBUG ONLY) Check whether a given entry is visible (i.e., not behind an + /// opaque entry). + /// + /// This is an O(N) algorithm, and should not be necessary except for debug + /// asserts. To avoid people depending on it, this function is implemented + /// only in debug mode, and always returns false in release mode. + bool debugIsVisible(OverlayEntry entry) { + bool result = false; + assert(_entries.contains(entry)); + assert(() { + for (int i = _entries.length - 1; i > 0; i -= 1) { + final OverlayEntry candidate = _entries[i]; + if (candidate == entry) { + result = true; + break; + } + if (candidate.opaque) { + break; + } + } + return true; + }()); + return result; + } + + void _didChangeEntryOpacity() { + setState(() { + // We use the opacity of the entry in our build function, which means we + // our state has changed. + }); + } + + @override + Widget build(BuildContext context) { + // This list is filled backwards and then reversed below before + // it is added to the tree. + final List<_OverlayEntryWidget> children = <_OverlayEntryWidget>[]; + bool onstage = true; + int onstageCount = 0; + for (final OverlayEntry entry in _entries.reversed) { + if (onstage) { + onstageCount += 1; + children.add(_OverlayEntryWidget( + key: entry._key, + overlayState: this, + entry: entry, + )); + if (entry.opaque) { + onstage = false; + } + } else if (entry.maintainState) { + children.add(_OverlayEntryWidget( + key: entry._key, + overlayState: this, + entry: entry, + tickerEnabled: false, + )); + } + } + return _Theater( + skipCount: children.length - onstageCount, + clipBehavior: widget.clipBehavior, + children: children.reversed.toList(growable: false), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + // TODO(jacobr): use IterableProperty instead as that would + // provide a slightly more consistent string summary of the List. + properties.add(DiagnosticsProperty<List<OverlayEntry>>('entries', _entries)); + } +} + +class _WrappingOverlay extends StatefulWidget { + const _WrappingOverlay({super.key, this.clipBehavior = Clip.hardEdge, required this.child}); + + final Clip clipBehavior; + final Widget child; + + @override + State<_WrappingOverlay> createState() => _WrappingOverlayState(); +} + +class _WrappingOverlayState extends State<_WrappingOverlay> { + late final OverlayEntry _entry = OverlayEntry( + canSizeOverlay: true, + opaque: true, + builder: (BuildContext context) { + return widget.child; + } + ); + + @override + void didUpdateWidget(_WrappingOverlay oldWidget) { + super.didUpdateWidget(oldWidget); + _entry.markNeedsBuild(); + } + + @override + Widget build(BuildContext context) { + return Overlay( + clipBehavior: widget.clipBehavior, + initialEntries: <OverlayEntry>[_entry], + ); + } +} + +/// Special version of a [Stack], that doesn't layout and render the first +/// [skipCount] children. +/// +/// The first [skipCount] children are considered "offstage". +class _Theater extends MultiChildRenderObjectWidget { + const _Theater({ + this.skipCount = 0, + this.clipBehavior = Clip.hardEdge, + required List<_OverlayEntryWidget> super.children, + }) : assert(skipCount >= 0), + assert(children.length >= skipCount); + + final int skipCount; + + final Clip clipBehavior; + + @override + _TheaterElement createElement() => _TheaterElement(this); + + @override + _RenderTheater createRenderObject(BuildContext context) { + return _RenderTheater( + skipCount: skipCount, + textDirection: Directionality.of(context), + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderTheater renderObject) { + renderObject + ..skipCount = skipCount + ..textDirection = Directionality.of(context) + ..clipBehavior = clipBehavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('skipCount', skipCount)); + } +} + +class _TheaterElement extends MultiChildRenderObjectElement { + _TheaterElement(_Theater super.widget); + + @override + _RenderTheater get renderObject => super.renderObject as _RenderTheater; + + @override + void insertRenderObjectChild(RenderBox child, IndexedSlot<Element?> slot) { + super.insertRenderObjectChild(child, slot); + final _TheaterParentData parentData = child.parentData! as _TheaterParentData; + parentData.overlayEntry = ((widget as _Theater).children[slot.index] as _OverlayEntryWidget).entry; + assert(parentData.overlayEntry != null); + } + + @override + void moveRenderObjectChild(RenderBox child, IndexedSlot<Element?> oldSlot, IndexedSlot<Element?> newSlot) { + super.moveRenderObjectChild(child, oldSlot, newSlot); + assert(() { + final _TheaterParentData parentData = child.parentData! as _TheaterParentData; + return parentData.overlayEntry == ((widget as _Theater).children[newSlot.index] as _OverlayEntryWidget).entry; + }()); + } + + @override + void debugVisitOnstageChildren(ElementVisitor visitor) { + final _Theater theater = widget as _Theater; + assert(children.length >= theater.skipCount); + children.skip(theater.skipCount).forEach(visitor); + } +} + +// A `RenderBox` that sizes itself to its parent's size, implements the stack +// layout algorithm and renders its children in the given `theater`. +mixin _RenderTheaterMixin on RenderBox { + _RenderTheater get theater; + + Iterable<RenderBox> _childrenInPaintOrder(); + Iterable<RenderBox> _childrenInHitTestOrder(); + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! StackParentData) { + child.parentData = StackParentData(); + } + } + + void layoutChild(RenderBox child, BoxConstraints nonPositionedChildConstraints) { + final StackParentData childParentData = child.parentData! as StackParentData; + final Alignment alignment = theater._resolvedAlignment; + if (!childParentData.isPositioned) { + child.layout(nonPositionedChildConstraints, parentUsesSize: true); + childParentData.offset = Offset.zero; + } else { + assert(child is! _RenderDeferredLayoutBox, 'all _RenderDeferredLayoutBoxes must be non-positioned children.'); + RenderStack.layoutPositionedChild(child, childParentData, size, alignment); + } + assert(child.parentData == childParentData); + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + final Iterator<RenderBox> iterator = _childrenInHitTestOrder().iterator; + bool isHit = false; + while (!isHit && iterator.moveNext()) { + final RenderBox child = iterator.current; + final StackParentData childParentData = child.parentData! as StackParentData; + final RenderBox localChild = child; + bool childHitTest(BoxHitTestResult result, Offset position) => localChild.hitTest(result, position: position); + isHit = result.addWithPaintOffset(offset: childParentData.offset, position: position, hitTest: childHitTest); + } + return isHit; + } + + @override + void paint(PaintingContext context, Offset offset) { + for (final RenderBox child in _childrenInPaintOrder()) { + final StackParentData childParentData = child.parentData! as StackParentData; + context.paintChild(child, childParentData.offset + offset); + } + } +} + +class _TheaterParentData extends StackParentData { + // The OverlayEntry that directly created this child. This field is null for + // children that are created by an OverlayPortal. + OverlayEntry? overlayEntry; + + /// A [OverlayPortal] makes its overlay child a render child of an ancestor + /// [Overlay]. Currently, to make sure the overlay child is painted after its + /// [OverlayPortal], and before the next [OverlayEntry] (which could be + /// something that should obstruct the overlay child, such as a [ModalRoute]) + /// in the host [Overlay], the paint order of each overlay child is managed by + /// the [OverlayEntry] that hosts its [OverlayPortal]. + /// + /// The following methods are exposed to allow easy access to the overlay + /// children's render objects whose order is managed by [overlayEntry], in the + /// right order. + + // _overlayStateMounted is set to null in _OverlayEntryWidgetState's dispose + // method. This property is only accessed during layout, paint and hit-test so + // the `value!` should be safe. + Iterator<RenderBox>? get paintOrderIterator => overlayEntry?._overlayEntryStateNotifier?.value!._paintOrderIterable.iterator; + Iterator<RenderBox>? get hitTestOrderIterator => overlayEntry?._overlayEntryStateNotifier?.value!._hitTestOrderIterable.iterator; + + // A convenience method for traversing `paintOrderIterator` with a + // [RenderObjectVisitor]. + void visitOverlayPortalChildrenOnOverlayEntry(RenderObjectVisitor visitor) => overlayEntry?._overlayEntryStateNotifier?.value!._paintOrderIterable.forEach(visitor); +} + +class _RenderTheater extends RenderBox with ContainerRenderObjectMixin<RenderBox, StackParentData>, _RenderTheaterMixin { + _RenderTheater({ + List<RenderBox>? children, + required TextDirection textDirection, + int skipCount = 0, + Clip clipBehavior = Clip.hardEdge, + }) : assert(skipCount >= 0), + _textDirection = textDirection, + _skipCount = skipCount, + _clipBehavior = clipBehavior { + addAll(children); + } + + @override + _RenderTheater get theater => this; + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! _TheaterParentData) { + child.parentData = _TheaterParentData(); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + RenderBox? child = firstChild; + while (child != null) { + final _TheaterParentData childParentData = child.parentData! as _TheaterParentData; + final Iterator<RenderBox>? iterator = childParentData.paintOrderIterator; + if (iterator != null) { + while (iterator.moveNext()) { + iterator.current.attach(owner); + } + } + child = childParentData.nextSibling; + } + } + + static void _detachChild(RenderObject child) => child.detach(); + + @override + void detach() { + super.detach(); + RenderBox? child = firstChild; + while (child != null) { + final _TheaterParentData childParentData = child.parentData! as _TheaterParentData; + childParentData.visitOverlayPortalChildrenOnOverlayEntry(_detachChild); + child = childParentData.nextSibling; + } + } + + @override + void redepthChildren() => visitChildren(redepthChild); + + Alignment? _alignmentCache; + Alignment get _resolvedAlignment => _alignmentCache ??= AlignmentDirectional.topStart.resolve(textDirection); + + void _markNeedResolution() { + _alignmentCache = null; + markNeedsLayout(); + } + + TextDirection get textDirection => _textDirection; + TextDirection _textDirection; + set textDirection(TextDirection value) { + if (_textDirection == value) { + return; + } + _textDirection = value; + _markNeedResolution(); + } + + int get skipCount => _skipCount; + int _skipCount; + set skipCount(int value) { + if (_skipCount != value) { + _skipCount = value; + markNeedsLayout(); + } + } + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.hardEdge; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + // Adding/removing deferred child does not affect the layout of other children, + // or that of the Overlay, so there's no need to invalidate the layout of the + // Overlay. + // + // When _skipMarkNeedsLayout is true, markNeedsLayout does not do anything. + bool _skipMarkNeedsLayout = false; + void _addDeferredChild(_RenderDeferredLayoutBox child) { + assert(!_skipMarkNeedsLayout); + _skipMarkNeedsLayout = true; + adoptChild(child); + // The Overlay still needs repainting when a deferred child is added. Usually + // `markNeedsLayout` implies `markNeedsPaint`, but here `markNeedsLayout` is + // skipped when the `_skipMarkNeedsLayout` flag is set. + markNeedsPaint(); + _skipMarkNeedsLayout = false; + + // After adding `child` to the render tree, we want to make sure it will be + // laid out in the same frame. This is done by calling markNeedsLayout on the + // layout surrgate. This ensures `child` is reachable via tree walk (see + // _RenderLayoutSurrogateProxyBox.performLayout). + child._layoutSurrogate.markNeedsLayout(); + } + + void _removeDeferredChild(_RenderDeferredLayoutBox child) { + assert(!_skipMarkNeedsLayout); + _skipMarkNeedsLayout = true; + dropChild(child); + // The Overlay still needs repainting when a deferred child is dropped. See + // the comment in `_addDeferredChild`. + markNeedsPaint(); + _skipMarkNeedsLayout = false; + } + + @override + void markNeedsLayout() { + if (!_skipMarkNeedsLayout) { + super.markNeedsLayout(); + } + } + + RenderBox? get _firstOnstageChild { + if (skipCount == super.childCount) { + return null; + } + RenderBox? child = super.firstChild; + for (int toSkip = skipCount; toSkip > 0; toSkip--) { + final StackParentData childParentData = child!.parentData! as StackParentData; + child = childParentData.nextSibling; + assert(child != null); + } + return child; + } + + RenderBox? get _lastOnstageChild => skipCount == super.childCount ? null : lastChild; + + @override + double computeMinIntrinsicWidth(double height) { + return RenderStack.getIntrinsicDimension(_firstOnstageChild, (RenderBox child) => child.getMinIntrinsicWidth(height)); + } + + @override + double computeMaxIntrinsicWidth(double height) { + return RenderStack.getIntrinsicDimension(_firstOnstageChild, (RenderBox child) => child.getMaxIntrinsicWidth(height)); + } + + @override + double computeMinIntrinsicHeight(double width) { + return RenderStack.getIntrinsicDimension(_firstOnstageChild, (RenderBox child) => child.getMinIntrinsicHeight(width)); + } + + @override + double computeMaxIntrinsicHeight(double width) { + return RenderStack.getIntrinsicDimension(_firstOnstageChild, (RenderBox child) => child.getMaxIntrinsicHeight(width)); + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + assert(!debugNeedsLayout); + double? result; + RenderBox? child = _firstOnstageChild; + while (child != null) { + assert(!child.debugNeedsLayout); + final StackParentData childParentData = child.parentData! as StackParentData; + double? candidate = child.getDistanceToActualBaseline(baseline); + if (candidate != null) { + candidate += childParentData.offset.dy; + if (result != null) { + result = math.min(result, candidate); + } else { + result = candidate; + } + } + child = childParentData.nextSibling; + } + return result; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + if (constraints.biggest.isFinite) { + return constraints.biggest; + } + return _findSizeDeterminingChild().getDryLayout(constraints); + } + + @override + // The following uses sync* because concurrent modifications should be allowed + // during layout. + Iterable<RenderBox> _childrenInPaintOrder() sync* { + RenderBox? child = _firstOnstageChild; + while (child != null) { + yield child; + final _TheaterParentData childParentData = child.parentData! as _TheaterParentData; + final Iterator<RenderBox>? innerIterator = childParentData.paintOrderIterator; + if (innerIterator != null) { + while (innerIterator.moveNext()) { + yield innerIterator.current; + } + } + child = childParentData.nextSibling; + } + } + + @override + // The following uses sync* because hit testing should be lazy. + Iterable<RenderBox> _childrenInHitTestOrder() sync* { + RenderBox? child = _lastOnstageChild; + int childLeft = childCount - skipCount; + while (child != null) { + final _TheaterParentData childParentData = child.parentData! as _TheaterParentData; + final Iterator<RenderBox>? innerIterator = childParentData.hitTestOrderIterator; + if (innerIterator != null) { + while (innerIterator.moveNext()) { + yield innerIterator.current; + } + } + yield child; + childLeft -= 1; + child = childLeft <= 0 ? null : childParentData.previousSibling; + } + } + + @override + bool get sizedByParent => false; + + @override + void performLayout() { + RenderBox? sizeDeterminingChild; + if (constraints.biggest.isFinite) { + size = constraints.biggest; + } else { + sizeDeterminingChild = _findSizeDeterminingChild(); + layoutChild(sizeDeterminingChild, constraints); + size = sizeDeterminingChild.size; + } + + // Equivalent to BoxConstraints used by RenderStack for StackFit.expand. + final BoxConstraints nonPositionedChildConstraints = BoxConstraints.tight(size); + for (final RenderBox child in _childrenInPaintOrder()) { + if (child != sizeDeterminingChild) { + layoutChild(child, nonPositionedChildConstraints); + } + } + } + + RenderBox _findSizeDeterminingChild() { + RenderBox? child = _lastOnstageChild; + while (child != null) { + final _TheaterParentData childParentData = child.parentData! as _TheaterParentData; + if ((childParentData.overlayEntry?.canSizeOverlay ?? false) && !childParentData.isPositioned) { + return child; + } + child = childParentData.previousSibling; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Overlay was given infinite constraints and cannot be sized by a suitable child.'), + ErrorDescription( + 'The constraints given to the overlay ($constraints) would result in an illegal ' + 'infinite size (${constraints.biggest}). To avoid that, the Overlay tried to size ' + 'itself to one of its children, but no suitable non-positioned child that belongs to an ' + 'OverlayEntry with canSizeOverlay set to true could be found.', + ), + ErrorHint( + 'Try wrapping the Overlay in a SizedBox to give it a finite size or ' + 'use an OverlayEntry with canSizeOverlay set to true.', + ), + ]); + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void paint(PaintingContext context, Offset offset) { + if (clipBehavior != Clip.none) { + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + super.paint, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + } else { + _clipRectLayer.layer = null; + super.paint(context, offset); + } + } + + @override + void dispose() { + _clipRectLayer.layer = null; + super.dispose(); + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + RenderBox? child = firstChild; + while (child != null) { + visitor(child); + final _TheaterParentData childParentData = child.parentData! as _TheaterParentData; + childParentData.visitOverlayPortalChildrenOnOverlayEntry(visitor); + child = childParentData.nextSibling; + } + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + RenderBox? child = _firstOnstageChild; + while (child != null) { + visitor(child); + final _TheaterParentData childParentData = child.parentData! as _TheaterParentData; + child = childParentData.nextSibling; + } + } + + @override + Rect? describeApproximatePaintClip(RenderObject child) { + switch (clipBehavior) { + case Clip.none: + return null; + case Clip.hardEdge: + case Clip.antiAlias: + case Clip.antiAliasWithSaveLayer: + return Offset.zero & size; + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('skipCount', skipCount)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection)); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<DiagnosticsNode> offstageChildren = <DiagnosticsNode>[]; + final List<DiagnosticsNode> onstageChildren = <DiagnosticsNode>[]; + + int count = 1; + bool onstage = false; + RenderBox? child = firstChild; + final RenderBox? firstOnstageChild = _firstOnstageChild; + while (child != null) { + final _TheaterParentData childParentData = child.parentData! as _TheaterParentData; + if (child == firstOnstageChild) { + onstage = true; + count = 1; + } + + if (onstage) { + onstageChildren.add( + child.toDiagnosticsNode( + name: 'onstage $count', + ), + ); + } else { + offstageChildren.add( + child.toDiagnosticsNode( + name: 'offstage $count', + style: DiagnosticsTreeStyle.offstage, + ), + ); + } + + int subcount = 1; + childParentData.visitOverlayPortalChildrenOnOverlayEntry((RenderObject renderObject) { + final RenderBox child = renderObject as RenderBox; + if (onstage) { + onstageChildren.add( + child.toDiagnosticsNode( + name: 'onstage $count - $subcount', + ), + ); + } else { + offstageChildren.add( + child.toDiagnosticsNode( + name: 'offstage $count - $subcount', + style: DiagnosticsTreeStyle.offstage, + ), + ); + } + subcount += 1; + }); + + child = childParentData.nextSibling; + count += 1; + } + + return <DiagnosticsNode>[ + ...onstageChildren, + if (offstageChildren.isNotEmpty) + ...offstageChildren + else + DiagnosticsNode.message( + 'no offstage children', + style: DiagnosticsTreeStyle.offstage, + ), + ]; + } +} + + +// * OverlayPortal Implementation +// OverlayPortal is inspired by the +// [flutter_portal](https://pub.dev/packages/flutter_portal) package. +// +// ** RenderObject hierarchy +// The widget works by inserting its overlay child's render subtree directly +// under [Overlay]'s render object (_RenderTheater). +// https://user-images.githubusercontent.com/31859944/171971838-62ed3975-4b5d-4733-a9c9-f79e263b8fcc.jpg +// +// To ensure the overlay child render subtree does not do layout twice, the +// subtree must only perform layout after both its _RenderTheater and the +// [OverlayPortal]'s render object (_RenderLayoutSurrogateProxyBox) have +// finished layout. This is handled by _RenderDeferredLayoutBox. +// +// ** Z-Index of an overlay child +// [_OverlayEntryLocation] is a (currently private) interface that allows an +// [OverlayPortal] to insert its overlay child into a specific [Overlay], as +// well as specifying the paint order between the overlay child and other +// children of the _RenderTheater. +// +// Since [OverlayPortal] is only allowed to target ancestor [Overlay]s +// (_RenderTheater must finish doing layout before _RenderDeferredLayoutBox), +// the _RenderTheater should typically be acquired using an [InheritedWidget] +// (currently, _RenderTheaterMarker) in case the [OverlayPortal] gets +// reparented. + +/// A class to show, hide and bring to top an [OverlayPortal]'s overlay child +/// in the target [Overlay]. +/// +/// A [OverlayPortalController] can only be given to at most one [OverlayPortal] +/// at a time. When an [OverlayPortalController] is moved from one +/// [OverlayPortal] to another, its [isShowing] state does not carry over. +/// +/// [OverlayPortalController.show] and [OverlayPortalController.hide] can be +/// called even before the controller is assigned to any [OverlayPortal], but +/// they typically should not be called while the widget tree is being rebuilt. +class OverlayPortalController { + /// Creates an [OverlayPortalController], optionally with a String identifier + /// `debugLabel`. + OverlayPortalController({ String? debugLabel }) : _debugLabel = debugLabel; + + _OverlayPortalState? _attachTarget; + + // A separate _zOrderIndex to allow `show()` or `hide()` to be called when the + // controller is not yet attached. Once this controller is attached, + // _attachTarget._zOrderIndex will be used as the source of truth, and this + // variable will be set to null. + int? _zOrderIndex; + final String? _debugLabel; + + static int _wallTime = kIsWeb + ? -9007199254740992 // -2^53 + : -1 << 63; + + // Returns a unique and monotonically increasing timestamp that represents + // now. + // + // The value this method returns increments after each call. + int _now() { + final int now = _wallTime += 1; + assert(_zOrderIndex == null || _zOrderIndex! < now); + assert(_attachTarget?._zOrderIndex == null || _attachTarget!._zOrderIndex! < now); + return now; + } + + /// Show the overlay child of the [OverlayPortal] this controller is attached + /// to, at the top of the target [Overlay]. + /// + /// When there are more than one [OverlayPortal]s that target the same + /// [Overlay], the overlay child of the last [OverlayPortal] to have called + /// [show] appears at the top level, unobstructed. + /// + /// If [isShowing] is already true, calling this method brings the overlay + /// child it controls to the top. + /// + /// This method should typically not be called while the widget tree is being + /// rebuilt. + void show() { + final _OverlayPortalState? state = _attachTarget; + if (state != null) { + state.show(_now()); + } else { + _zOrderIndex = _now(); + } + } + + /// Hide the [OverlayPortal]'s overlay child. + /// + /// Once hidden, the overlay child will be removed from the widget tree the + /// next time the widget tree rebuilds, and stateful widgets in the overlay + /// child may lose states as a result. + /// + /// This method should typically not be called while the widget tree is being + /// rebuilt. + void hide() { + final _OverlayPortalState? state = _attachTarget; + if (state != null) { + state.hide(); + } else { + assert(_zOrderIndex != null); + _zOrderIndex = null; + } + } + + /// Whether the associated [OverlayPortal] should build and show its overlay + /// child, using its `overlayChildBuilder`. + bool get isShowing { + final _OverlayPortalState? state = _attachTarget; + return state != null + ? state._zOrderIndex != null + : _zOrderIndex != null; + } + + /// Convenience method for toggling the current [isShowing] status. + /// + /// This method should typically not be called while the widget tree is being + /// rebuilt. + void toggle() => isShowing ? hide() : show(); + + @override + String toString() { + final String? debugLabel = _debugLabel; + final String label = debugLabel == null ? '' : '($debugLabel)'; + final String isDetached = _attachTarget != null ? '' : ' DETACHED'; + return '${objectRuntimeType(this, 'OverlayPortalController')}$label$isDetached'; + } +} + +/// A widget that renders its overlay child on an [Overlay]. +/// +/// The overlay child is initially hidden until [OverlayPortalController.show] +/// is called on the associated [controller]. The [OverlayPortal] uses +/// [overlayChildBuilder] to build its overlay child and renders it on the +/// specified [Overlay] as if it was inserted using an [OverlayEntry], while it +/// can depend on the same set of [InheritedWidget]s (such as [Theme]) that this +/// widget can depend on. +/// +/// This widget requires an [Overlay] ancestor in the widget tree when its +/// overlay child is showing. The overlay child is rendered by the [Overlay] +/// ancestor, not by the widget itself. This allows the overlay child to float +/// above other widgets, independent of its position in the widget tree. +/// +/// When [OverlayPortalController.hide] is called, the widget built using +/// [overlayChildBuilder] will be removed from the widget tree the next time the +/// widget rebuilds. Stateful descendants in the overlay child subtree may lose +/// states as a result. +/// +/// {@tool dartpad} +/// This example uses an [OverlayPortal] to build a tooltip that becomes visible +/// when the user taps on the [child] widget. There's a [DefaultTextStyle] above +/// the [OverlayPortal] controlling the [TextStyle] of both the [child] widget +/// and the widget [overlayChildBuilder] builds, which isn't otherwise doable if +/// the tooltip was added as an [OverlayEntry]. +/// +/// ** See code in examples/api/lib/widgets/overlay/overlay_portal.0.dart ** +/// {@end-tool} +/// +/// ### Paint Order +/// +/// In an [Overlay], an overlay child is painted after the [OverlayEntry] +/// associated with its [OverlayPortal] (that is, the [OverlayEntry] closest to +/// the [OverlayPortal] in the widget tree, which usually represents the +/// enclosing [Route]), and before the next [OverlayEntry]. +/// +/// When an [OverlayEntry] has multiple associated [OverlayPortal]s, the paint +/// order between their overlay children is the order in which +/// [OverlayPortalController.show] was called. The last [OverlayPortal] to have +/// called `show` gets to paint its overlay child in the foreground. +/// +/// ### Semantics +/// +/// The semantics subtree generated by the overlay child is considered attached +/// to [OverlayPortal] instead of the target [Overlay]. An [OverlayPortal]'s +/// semantics subtree can be dropped from the semantics tree due to invisibility +/// while the overlay child is still visible (for example, when the +/// [OverlayPortal] is completely invisible in a [ListView] but kept alive by +/// a [KeepAlive] widget). When this happens the semantics subtree generated by +/// the overlay child is also dropped, even if the overlay child is still visible +/// on screen. +/// +/// {@template flutter.widgets.overlayPortalVsOverlayEntry} +/// ### Differences between [OverlayPortal] and [OverlayEntry] +/// +/// The main difference between [OverlayEntry] and [OverlayPortal] is that +/// [OverlayEntry] builds its widget subtree as a child of the target [Overlay], +/// while [OverlayPortal] uses [OverlayPortal.overlayChildBuilder] to build a +/// child widget of itself. This allows [OverlayPortal]'s overlay child to depend +/// on the same set of [InheritedWidget]s as [OverlayPortal], and it's also +/// guaranteed that the overlay child will not outlive its [OverlayPortal]. +/// +/// On the other hand, [OverlayPortal]'s implementation is more complex. For +/// instance, it does a bit more work than a regular widget during global key +/// reparenting. If the content to be shown on the [Overlay] doesn't benefit +/// from being a part of [OverlayPortal]'s subtree, consider using an +/// [OverlayEntry] instead. +/// {@endtemplate} +/// +/// See also: +/// +/// * [OverlayEntry], an alternative API for inserting widgets into an +/// [Overlay]. +/// * [Positioned], which can be used to size and position the overlay child in +/// relation to the target [Overlay]'s boundaries. +/// * [CompositedTransformFollower], which can be used to position the overlay +/// child in relation to the linked [CompositedTransformTarget] widget. +class OverlayPortal extends StatefulWidget { + /// Creates an [OverlayPortal] that renders the widget [overlayChildBuilder] + /// builds on the closest [Overlay] when [OverlayPortalController.show] is + /// called. + const OverlayPortal({ + super.key, + required this.controller, + required this.overlayChildBuilder, + this.child, + }) : _targetRootOverlay = false; + + /// Creates an [OverlayPortal] that renders the widget [overlayChildBuilder] + /// builds on the root [Overlay] when [OverlayPortalController.show] is + /// called. + const OverlayPortal.targetsRootOverlay({ + super.key, + required this.controller, + required this.overlayChildBuilder, + this.child, + }) : _targetRootOverlay = true; + + /// The controller to show, hide and bring to top the overlay child. + final OverlayPortalController controller; + + /// A [WidgetBuilder] used to build a widget below this widget in the tree, + /// that renders on the closest [Overlay]. + /// + /// The said widget will only be built and shown in the closest [Overlay] once + /// [OverlayPortalController.show] is called on the associated [controller]. + /// It will be painted in front of the [OverlayEntry] closest to this widget + /// in the widget tree (which is usually the enclosing [Route]). + /// + /// The built overlay child widget is inserted below this widget in the widget + /// tree, allowing it to depend on [InheritedWidget]s above it, and be + /// notified when the [InheritedWidget]s change. + /// + /// Unlike [child], the built overlay child can visually extend outside the + /// bounds of this widget without being clipped, and receive hit-test events + /// outside of this widget's bounds, as long as it does not extend outside of + /// the [Overlay] on which it is rendered. + final WidgetBuilder overlayChildBuilder; + + /// A widget below this widget in the tree. + final Widget? child; + + final bool _targetRootOverlay; + + @override + State<OverlayPortal> createState() => _OverlayPortalState(); +} + +class _OverlayPortalState extends State<OverlayPortal> { + int? _zOrderIndex; + // The location of the overlay child within the overlay. This object will be + // used as the slot of the overlay child widget. + // + // The developer must call `show` to reveal the overlay so we can get a unique + // timestamp of the user interaction for determining the z-index of the + // overlay child in the overlay. + // + // Avoid invalidating the cache if possible, since the framework uses `==` to + // compare slots, and _OverlayEntryLocation can't override that operator since + // it's mutable. Changing slots can be relatively slow. + bool _childModelMayHaveChanged = true; + _OverlayEntryLocation? _locationCache; + static bool _isTheSameLocation(_OverlayEntryLocation locationCache, _RenderTheaterMarker marker) { + return locationCache._childModel == marker.overlayEntryWidgetState + && locationCache._theater == marker.theater; + } + + _OverlayEntryLocation _getLocation(int zOrderIndex, bool targetRootOverlay) { + final _OverlayEntryLocation? cachedLocation = _locationCache; + late final _RenderTheaterMarker marker = _RenderTheaterMarker.of(context, targetRootOverlay: targetRootOverlay); + final bool isCacheValid = cachedLocation != null + && (!_childModelMayHaveChanged || _isTheSameLocation(cachedLocation, marker)); + _childModelMayHaveChanged = false; + if (isCacheValid) { + assert(cachedLocation._zOrderIndex == zOrderIndex); + assert(cachedLocation._debugIsLocationValid()); + return cachedLocation; + } + // Otherwise invalidate the cache and create a new location. + cachedLocation?._debugMarkLocationInvalid(); + final _OverlayEntryLocation newLocation = _OverlayEntryLocation(zOrderIndex, marker.overlayEntryWidgetState, marker.theater); + assert(newLocation._zOrderIndex == zOrderIndex); + return _locationCache = newLocation; + } + + @override + void initState() { + super.initState(); + _setupController(widget.controller); + } + + void _setupController(OverlayPortalController controller) { + assert( + controller._attachTarget == null || controller._attachTarget == this, + 'Failed to attach $controller to $this. It is already attached to ${controller._attachTarget}.' + ); + final int? controllerZOrderIndex = controller._zOrderIndex; + final int? zOrderIndex = _zOrderIndex; + if (zOrderIndex == null || (controllerZOrderIndex != null && controllerZOrderIndex > zOrderIndex)) { + _zOrderIndex = controllerZOrderIndex; + } + controller._zOrderIndex = null; + controller._attachTarget = this; + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _childModelMayHaveChanged = true; + } + + @override + void didUpdateWidget(OverlayPortal oldWidget) { + super.didUpdateWidget(oldWidget); + _childModelMayHaveChanged = _childModelMayHaveChanged || oldWidget._targetRootOverlay != widget._targetRootOverlay; + if (oldWidget.controller != widget.controller) { + oldWidget.controller._attachTarget = null; + _setupController(widget.controller); + } + } + + @override + void dispose() { + assert(widget.controller._attachTarget == this); + widget.controller._attachTarget = null; + _locationCache?._debugMarkLocationInvalid(); + _locationCache = null; + super.dispose(); + } + + void show(int zOrderIndex) { + assert( + SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks, + '${widget.controller.runtimeType}.show() should not be called during build.' + ); + setState(() { _zOrderIndex = zOrderIndex; }); + _locationCache?._debugMarkLocationInvalid(); + _locationCache = null; + } + + void hide() { + assert(SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks); + setState(() { _zOrderIndex = null; }); + _locationCache?._debugMarkLocationInvalid(); + _locationCache = null; + } + + @override + Widget build(BuildContext context) { + final int? zOrderIndex = _zOrderIndex; + if (zOrderIndex == null) { + return _OverlayPortal( + overlayLocation: null, + overlayChild: null, + child: widget.child, + ); + } + return _OverlayPortal( + overlayLocation: _getLocation(zOrderIndex, widget._targetRootOverlay), + overlayChild: _DeferredLayout(child: Builder(builder: widget.overlayChildBuilder)), + child: widget.child, + ); + } +} + +/// A location in an [Overlay]. +/// +/// An [_OverlayEntryLocation] determines the [Overlay] the associated +/// [OverlayPortal] should put its overlay child onto, as well as the overlay +/// child's paint order in relation to other contents painted on the [Overlay]. +// +// An _OverlayEntryLocation is a cursor pointing to a location in a particular +// Overlay's child model, and provides methods to insert/remove/move a +// _RenderDeferredLayoutBox to/from its target _theater. +// +// The occupant (a `RenderBox`) will be painted above the associated +// [OverlayEntry], but below the [OverlayEntry] above that [OverlayEntry]. +// +// Additionally, `_activate` and `_deactivate` are called when the overlay +// child's `_OverlayPortalElement` activates/deactivates (for instance, during +// global key reparenting). +// `_OverlayPortalElement` removes its overlay child's render object from the +// target `_RenderTheater` when it deactivates and puts it back on `activated`. +// These 2 methods can be used to "hide" a child in the child model without +// removing it, when the child is expensive/difficult to re-insert at the +// correct location on `activated`. +// +// ### Equality +// +// An `_OverlayEntryLocation` will be used as an Element's slot. These 3 parts +// uniquely identify a place in an overlay's child model: +// - _theater +// - _childModel (the OverlayEntry) +// - _zOrderIndex +// +// Since it can't implement operator== (it's mutable), the same `_OverlayEntryLocation` +// instance must not be used to represent more than one locations. +final class _OverlayEntryLocation extends LinkedListEntry<_OverlayEntryLocation> { + _OverlayEntryLocation(this._zOrderIndex, this._childModel, this._theater); + + final int _zOrderIndex; + final _OverlayEntryWidgetState _childModel; + final _RenderTheater _theater; + + _RenderDeferredLayoutBox? _overlayChildRenderBox; + void _addToChildModel(_RenderDeferredLayoutBox child) { + assert(_overlayChildRenderBox == null, 'Failed to add $child. This location ($this) is already occupied by $_overlayChildRenderBox.'); + _overlayChildRenderBox = child; + _childModel._add(this); + _theater.markNeedsPaint(); + _theater.markNeedsCompositingBitsUpdate(); + _theater.markNeedsSemanticsUpdate(); + } + void _removeFromChildModel(_RenderDeferredLayoutBox child) { + assert(child == _overlayChildRenderBox); + _overlayChildRenderBox = null; + assert(_childModel._sortedTheaterSiblings?.contains(this) ?? false); + _childModel._remove(this); + _theater.markNeedsPaint(); + _theater.markNeedsCompositingBitsUpdate(); + _theater.markNeedsSemanticsUpdate(); + } + + void _addChild(_RenderDeferredLayoutBox child) { + assert(_debugIsLocationValid()); + _addToChildModel(child); + _theater._addDeferredChild(child); + assert(child.parent == _theater); + } + + void _removeChild(_RenderDeferredLayoutBox child) { + // This call is allowed even when this location is disposed. + _removeFromChildModel(child); + _theater._removeDeferredChild(child); + assert(child.parent == null); + } + + void _moveChild(_RenderDeferredLayoutBox child, _OverlayEntryLocation fromLocation) { + assert(fromLocation != this); + assert(_debugIsLocationValid()); + final _RenderTheater fromTheater = fromLocation._theater; + final _OverlayEntryWidgetState fromModel = fromLocation._childModel; + + if (fromTheater != _theater) { + fromTheater._removeDeferredChild(child); + _theater._addDeferredChild(child); + } + + if (fromModel != _childModel || fromLocation._zOrderIndex != _zOrderIndex) { + fromLocation._removeFromChildModel(child); + _addToChildModel(child); + } + } + + void _activate(_RenderDeferredLayoutBox child) { + // This call is allowed even when this location is invalidated. + // See _OverlayPortalElement.activate. + assert(_overlayChildRenderBox == null, '$_overlayChildRenderBox'); + _theater._addDeferredChild(child); + _overlayChildRenderBox = child; + } + + void _deactivate(_RenderDeferredLayoutBox child) { + // This call is allowed even when this location is invalidated. + _theater._removeDeferredChild(child); + _overlayChildRenderBox = null; + } + + // Throws a StateError if this location is already invalidated and shouldn't + // be used as an OverlayPortal slot. Must be used in asserts. + // + // Generally, `assert(_debugIsLocationValid())` should be used to prevent + // invalid accesses to an invalid `_OverlayEntryLocation` object. Exceptions + // to this rule are _removeChild, _deactive, which will be called when the + // OverlayPortal is being removed from the widget tree and may use the + // location information to perform cleanup tasks. + // + // Another exception is the _activate method which is called by + // _OverlayPortalElement.activate. See the comment in _OverlayPortalElement.activate. + bool _debugIsLocationValid() { + if (_debugMarkLocationInvalidStackTrace == null) { + return true; + } + throw StateError('$this is already disposed. Stack trace: $_debugMarkLocationInvalidStackTrace'); + } + + // The StackTrace of the first _debugMarkLocationInvalid call. It's only for + // debugging purposes and the StackTrace will only be captured in debug builds. + // + // The effect of this method is not reversible. Once marked invalid, this + // object can't be marked as valid again. + StackTrace? _debugMarkLocationInvalidStackTrace; + @mustCallSuper + void _debugMarkLocationInvalid() { + assert(_debugIsLocationValid()); + assert(() { + _debugMarkLocationInvalidStackTrace = StackTrace.current; + return true; + }()); + } + + @override + String toString() => '${objectRuntimeType(this, '_OverlayEntryLocation')}[${shortHash(this)}] ${_debugMarkLocationInvalidStackTrace != null ? "(INVALID)":""}'; +} + +class _RenderTheaterMarker extends InheritedWidget { + const _RenderTheaterMarker({ + required this.theater, + required this.overlayEntryWidgetState, + required super.child, + }); + + final _RenderTheater theater; + final _OverlayEntryWidgetState overlayEntryWidgetState; + + @override + bool updateShouldNotify(_RenderTheaterMarker oldWidget) { + return oldWidget.theater != theater + || oldWidget.overlayEntryWidgetState != overlayEntryWidgetState; + } + + static _RenderTheaterMarker of(BuildContext context, { bool targetRootOverlay = false }) { + final _RenderTheaterMarker? marker; + if (targetRootOverlay) { + final InheritedElement? ancestor = _rootRenderTheaterMarkerOf(context.getElementForInheritedWidgetOfExactType<_RenderTheaterMarker>()); + assert(ancestor == null || ancestor.widget is _RenderTheaterMarker); + marker = ancestor != null ? context.dependOnInheritedElement(ancestor) as _RenderTheaterMarker? : null; + } else { + marker = context.dependOnInheritedWidgetOfExactType<_RenderTheaterMarker>(); + } + if (marker != null) { + return marker; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('No Overlay widget found.'), + ErrorDescription( + '${context.widget.runtimeType} widgets require an Overlay widget ancestor.\n' + 'An overlay lets widgets float on top of other widget children.', + ), + ErrorHint( + 'To introduce an Overlay widget, you can either directly ' + 'include one, or use a widget that contains an Overlay itself, ' + 'such as a Navigator, WidgetApp, MaterialApp, or CupertinoApp.', + ), + ...context.describeMissingAncestor(expectedAncestorType: Overlay), + ]); + } + + static InheritedElement? _rootRenderTheaterMarkerOf(InheritedElement? theaterMarkerElement) { + assert(theaterMarkerElement == null || theaterMarkerElement.widget is _RenderTheaterMarker); + if (theaterMarkerElement == null) { + return null; + } + InheritedElement? ancestor; + theaterMarkerElement.visitAncestorElements((Element element) { + ancestor = element.getElementForInheritedWidgetOfExactType<_RenderTheaterMarker>(); + return false; + }); + return ancestor == null ? theaterMarkerElement : _rootRenderTheaterMarkerOf(ancestor); + } +} + +class _OverlayPortal extends RenderObjectWidget { + /// Creates a widget that renders the given [overlayChild] in the [Overlay] + /// specified by `overlayLocation`. + /// + /// The `overlayLocation` parameter must not be null when [overlayChild] is not + /// null. + _OverlayPortal({ + required this.overlayLocation, + required this.overlayChild, + required this.child, + }) : assert(overlayChild == null || overlayLocation != null), + assert(overlayLocation == null || overlayLocation._debugIsLocationValid()); + + final Widget? overlayChild; + + /// A widget below this widget in the tree. + final Widget? child; + + final _OverlayEntryLocation? overlayLocation; + + @override + RenderObjectElement createElement() => _OverlayPortalElement(this); + + @override + RenderObject createRenderObject(BuildContext context) => _RenderLayoutSurrogateProxyBox(); +} + +class _OverlayPortalElement extends RenderObjectElement { + _OverlayPortalElement(_OverlayPortal super.widget); + + @override + _RenderLayoutSurrogateProxyBox get renderObject => super.renderObject as _RenderLayoutSurrogateProxyBox; + + Element? _overlayChild; + Element? _child; + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + final _OverlayPortal widget = this.widget as _OverlayPortal; + _child = updateChild(_child, widget.child, null); + _overlayChild = updateChild(_overlayChild, widget.overlayChild, widget.overlayLocation); + } + + @override + void update(_OverlayPortal newWidget) { + super.update(newWidget); + _child = updateChild(_child, newWidget.child, null); + _overlayChild = updateChild(_overlayChild, newWidget.overlayChild, newWidget.overlayLocation); + } + + @override + void forgetChild(Element child) { + // The _overlayChild Element does not have a key because the _DeferredLayout + // widget does not take a Key, so only the regular _child can be taken + // during global key reparenting. + assert(child == _child); + _child = null; + super.forgetChild(child); + } + + @override + void visitChildren(ElementVisitor visitor) { + final Element? child = _child; + final Element? overlayChild = _overlayChild; + if (child != null) { + visitor(child); + } + if (overlayChild != null) { + visitor(overlayChild); + } + } + + @override + void activate() { + super.activate(); + final Element? overlayChild = _overlayChild; + if (overlayChild != null) { + final _RenderDeferredLayoutBox? box = overlayChild.renderObject as _RenderDeferredLayoutBox?; + if (box != null) { + assert(!box.attached); + assert(renderObject._deferredLayoutChild == box); + // updateChild has not been called at this point so the RenderTheater in + // the overlay location could be detached. Adding children to a detached + // RenderObject is still allowed however this isn't the most efficient. + (overlayChild.slot! as _OverlayEntryLocation)._activate(box); + } + } + } + + @override + void deactivate() { + final Element? overlayChild = _overlayChild; + // Instead of just detaching the render objects, removing them from the + // render subtree entirely. This is a workaround for the + // !renderObject.attached assert in the `super.deactive()` method. + if (overlayChild != null) { + final _RenderDeferredLayoutBox? box = overlayChild.renderObject as _RenderDeferredLayoutBox?; + if (box != null) { + (overlayChild.slot! as _OverlayEntryLocation)._deactivate(box); + } + } + super.deactivate(); + } + + @override + void insertRenderObjectChild(RenderBox child, _OverlayEntryLocation? slot) { + assert(child.parent == null, "$child's parent is not null: ${child.parent}"); + if (slot != null) { + renderObject._deferredLayoutChild = child as _RenderDeferredLayoutBox; + slot._addChild(child); + } else { + renderObject.child = child; + } + } + + // The [_DeferredLayout] widget does not have a key so there will be no + // reparenting between _overlayChild and _child, thus the non-null-typed slots. + @override + void moveRenderObjectChild(_RenderDeferredLayoutBox child, _OverlayEntryLocation oldSlot, _OverlayEntryLocation newSlot) { + assert(newSlot._debugIsLocationValid()); + newSlot._moveChild(child, oldSlot); + } + + @override + void removeRenderObjectChild(RenderBox child, _OverlayEntryLocation? slot) { + if (slot == null) { + renderObject.child = null; + return; + } + assert(renderObject._deferredLayoutChild == child); + slot._removeChild(child as _RenderDeferredLayoutBox); + renderObject._deferredLayoutChild = null; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Element>('child', _child, defaultValue: null)); + properties.add(DiagnosticsProperty<Element>('overlayChild', _overlayChild, defaultValue: null)); + properties.add(DiagnosticsProperty<Object>('overlayLocation', _overlayChild?.slot, defaultValue: null)); + } +} + +class _DeferredLayout extends SingleChildRenderObjectWidget { + const _DeferredLayout({ + // This widget must not be given a key: we currently do not support + // reparenting between the overlayChild and child. + required Widget child, + }) : super(child: child); + + _RenderLayoutSurrogateProxyBox getLayoutParent(BuildContext context) { + return context.findAncestorRenderObjectOfType<_RenderLayoutSurrogateProxyBox>()!; + } + + @override + _RenderDeferredLayoutBox createRenderObject(BuildContext context) { + final _RenderLayoutSurrogateProxyBox parent = getLayoutParent(context); + final _RenderDeferredLayoutBox renderObject = _RenderDeferredLayoutBox(parent); + parent._deferredLayoutChild = renderObject; + return renderObject; + } + + @override + void updateRenderObject(BuildContext context, _RenderDeferredLayoutBox renderObject) { + assert(renderObject._layoutSurrogate == getLayoutParent(context)); + assert(getLayoutParent(context)._deferredLayoutChild == renderObject); + } +} + +// A `RenderProxyBox` that defers its layout until its `_layoutSurrogate` (which +// is not necessarily an ancestor of this RenderBox, but shares at least one +// `_RenderTheater` ancestor with this RenderBox) is laid out. +// +// This `RenderObject` must be a child of a `_RenderTheater`. It guarantees that: +// +// 1. It's a relayout boundary, and `markParentNeedsLayout` is overridden such +// that it never dirties its `_RenderTheater`. +// +// 2. Its `layout` implementation is overridden such that `performLayout` does +// not do anything when its called from `layout`, preventing the parent +// `_RenderTheater` from laying out this subtree prematurely (but this +// `RenderObject` may still be resized). Instead, `markNeedsLayout` will be +// called from within `layout` to schedule a layout update for this relayout +// boundary when needed. +// +// 3. When invoked from `PipelineOwner.flushLayout`, or +// `_layoutSurrogate.performLayout`, this `RenderObject` behaves like an +// `Overlay` that has only one entry. +final class _RenderDeferredLayoutBox extends RenderProxyBox with _RenderTheaterMixin, LinkedListEntry<_RenderDeferredLayoutBox> { + _RenderDeferredLayoutBox(this._layoutSurrogate); + + StackParentData get stackParentData => parentData! as StackParentData; + final _RenderLayoutSurrogateProxyBox _layoutSurrogate; + + @override + Iterable<RenderBox> _childrenInPaintOrder() { + final RenderBox? child = this.child; + return child == null + ? const Iterable<RenderBox>.empty() + : Iterable<RenderBox>.generate(1, (int i) => child); + } + @override + Iterable<RenderBox> _childrenInHitTestOrder() => _childrenInPaintOrder(); + + @override + _RenderTheater get theater { + final RenderObject? parent = this.parent; + return parent is _RenderTheater + ? parent + : throw FlutterError('$parent of $this is not a _RenderTheater'); + } + + @override + void redepthChildren() { + _layoutSurrogate.redepthChild(this); + super.redepthChildren(); + } + + bool _callingMarkParentNeedsLayout = false; + @override + void markParentNeedsLayout() { + // No re-entrant calls. + if (_callingMarkParentNeedsLayout) { + return; + } + _callingMarkParentNeedsLayout = true; + markNeedsLayout(); + _layoutSurrogate.markNeedsLayout(); + _callingMarkParentNeedsLayout = false; + } + + @override + bool get sizedByParent => true; + + bool _needsLayout = true; + @override + void markNeedsLayout() { + _needsLayout = true; + super.markNeedsLayout(); + } + + @override + RenderObject? get debugLayoutParent => _layoutSurrogate; + + void layoutByLayoutSurrogate() { + assert(!_theaterDoingThisLayout); + final _RenderTheater? theater = parent as _RenderTheater?; + if (theater == null || !attached) { + assert(false, '$this is not attached to parent'); + return; + } + super.layout(BoxConstraints.tight(theater.constraints.biggest)); + } + + bool _theaterDoingThisLayout = false; + @override + void layout(Constraints constraints, { bool parentUsesSize = false }) { + assert(_needsLayout == debugNeedsLayout); + // Only _RenderTheater calls this implementation. + assert(parent != null); + final bool scheduleDeferredLayout = _needsLayout || this.constraints != constraints; + assert(!_theaterDoingThisLayout); + _theaterDoingThisLayout = true; + super.layout(constraints, parentUsesSize: parentUsesSize); + assert(_theaterDoingThisLayout); + _theaterDoingThisLayout = false; + _needsLayout = false; + assert(!debugNeedsLayout); + if (scheduleDeferredLayout) { + final _RenderTheater parent = this.parent! as _RenderTheater; + // Invoking markNeedsLayout as a layout callback allows this node to be + // merged back to the `PipelineOwner`'s dirty list in the right order, if + // it's not already dirty. Otherwise this may cause some dirty descendants + // to performLayout a second time. + parent.invokeLayoutCallback((BoxConstraints constraints) { markNeedsLayout(); }); + } + } + + @override + void performResize() { + size = constraints.biggest; + } + + bool _debugMutationsLocked = false; + @override + void performLayout() { + assert(!_debugMutationsLocked); + if (_theaterDoingThisLayout) { + _needsLayout = false; + return; + } + assert(() { + _debugMutationsLocked = true; + return true; + }()); + // This method is directly being invoked from `PipelineOwner.flushLayout`, + // or from `_layoutSurrogate`'s performLayout. + assert(parent != null); + final RenderBox? child = this.child; + if (child == null) { + _needsLayout = false; + return; + } + assert(constraints.isTight); + layoutChild(child, constraints); + assert(() { + _debugMutationsLocked = false; + return true; + }()); + _needsLayout = false; + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + final BoxParentData childParentData = child.parentData! as BoxParentData; + final Offset offset = childParentData.offset; + transform.translate(offset.dx, offset.dy); + } +} + +// A RenderProxyBox that makes sure its `deferredLayoutChild` has a greater +// depth than itself. +class _RenderLayoutSurrogateProxyBox extends RenderProxyBox { + _RenderDeferredLayoutBox? _deferredLayoutChild; + + @override + void redepthChildren() { + super.redepthChildren(); + final _RenderDeferredLayoutBox? child = _deferredLayoutChild; + // If child is not attached, this method will be invoked by child's real + // parent when it's attached. + if (child != null && child.attached) { + assert(child.attached); + redepthChild(child); + } + } + + @override + void performLayout() { + super.performLayout(); + // Try to layout `_deferredLayoutChild` here now that its configuration + // and constraints are up-to-date. Additionally, during the very first + // layout, this makes sure that _deferredLayoutChild is reachable via tree + // walk. + _deferredLayoutChild?.layoutByLayoutSurrogate(); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + super.visitChildrenForSemantics(visitor); + final _RenderDeferredLayoutBox? deferredChild = _deferredLayoutChild; + if (deferredChild != null) { + visitor(deferredChild); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/overscroll_indicator.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/overscroll_indicator.dart new file mode 100644 index 0000000000000000000000000000000000000000..ef198d769be64459b4f731dc54e8e1e4828ec737 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/overscroll_indicator.dart @@ -0,0 +1,993 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async' show Timer; +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/physics.dart' show Tolerance, nearEqual; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'media_query.dart'; +import 'notification_listener.dart'; +import 'scroll_notification.dart'; +import 'ticker_provider.dart'; +import 'transitions.dart'; + +/// A visual indication that a scroll view has overscrolled. +/// +/// A [GlowingOverscrollIndicator] listens for [ScrollNotification]s in order +/// to control the overscroll indication. These notifications are typically +/// generated by a [ScrollView], such as a [ListView] or a [GridView]. +/// +/// [GlowingOverscrollIndicator] generates [OverscrollIndicatorNotification] +/// before showing an overscroll indication. To prevent the indicator from +/// showing the indication, call +/// [OverscrollIndicatorNotification.disallowIndicator] on the notification. +/// +/// Created automatically by [ScrollBehavior.buildOverscrollIndicator] on platforms +/// (e.g., Android) that commonly use this type of overscroll indication. +/// +/// In a [MaterialApp], the edge glow color is the overall theme's +/// [ColorScheme.secondary] color. +/// +/// ## Customizing the Glow Position for Advanced Scroll Views +/// +/// When building a [CustomScrollView] with a [GlowingOverscrollIndicator], the +/// indicator will apply to the entire scrollable area, regardless of what +/// slivers the CustomScrollView contains. +/// +/// For example, if your CustomScrollView contains a SliverAppBar in the first +/// position, the GlowingOverscrollIndicator will overlay the SliverAppBar. To +/// manipulate the position of the GlowingOverscrollIndicator in this case, +/// you can either make use of a [NotificationListener] and provide a +/// [OverscrollIndicatorNotification.paintOffset] to the +/// notification, or use a [NestedScrollView]. +/// +/// {@tool dartpad} +/// This example demonstrates how to use a [NotificationListener] to manipulate +/// the placement of a [GlowingOverscrollIndicator] when building a +/// [CustomScrollView]. Drag the scrollable to see the bounds of the overscroll +/// indicator. +/// +/// ** See code in examples/api/lib/widgets/overscroll_indicator/glowing_overscroll_indicator.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example demonstrates how to use a [NestedScrollView] to manipulate the +/// placement of a [GlowingOverscrollIndicator] when building a +/// [CustomScrollView]. Drag the scrollable to see the bounds of the overscroll +/// indicator. +/// +/// ** See code in examples/api/lib/widgets/overscroll_indicator/glowing_overscroll_indicator.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [OverscrollIndicatorNotification], which can be used to manipulate the +/// glow position or prevent the glow from being painted at all. +/// * [NotificationListener], to listen for the +/// [OverscrollIndicatorNotification]. +/// * [StretchingOverscrollIndicator], a Material Design overscroll indicator. +class GlowingOverscrollIndicator extends StatefulWidget { + /// Creates a visual indication that a scroll view has overscrolled. + /// + /// In order for this widget to display an overscroll indication, the [child] + /// widget must contain a widget that generates a [ScrollNotification], such + /// as a [ListView] or a [GridView]. + const GlowingOverscrollIndicator({ + super.key, + this.showLeading = true, + this.showTrailing = true, + required this.axisDirection, + required this.color, + this.notificationPredicate = defaultScrollNotificationPredicate, + this.child, + }); + + /// Whether to show the overscroll glow on the side with negative scroll + /// offsets. + /// + /// For a vertical downwards viewport, this is the top side. + /// + /// Defaults to true. + /// + /// See [showTrailing] for the corresponding control on the other side of the + /// viewport. + final bool showLeading; + + /// Whether to show the overscroll glow on the side with positive scroll + /// offsets. + /// + /// For a vertical downwards viewport, this is the bottom side. + /// + /// Defaults to true. + /// + /// See [showLeading] for the corresponding control on the other side of the + /// viewport. + final bool showTrailing; + + /// {@template flutter.overscroll.axisDirection} + /// The direction of positive scroll offsets in the [Scrollable] whose + /// overscrolls are to be visualized. + /// {@endtemplate} + final AxisDirection axisDirection; + + /// {@template flutter.overscroll.axis} + /// The axis along which scrolling occurs in the [Scrollable] whose + /// overscrolls are to be visualized. + /// {@endtemplate} + Axis get axis => axisDirectionToAxis(axisDirection); + + /// The color of the glow. The alpha channel is ignored. + final Color color; + + /// {@template flutter.overscroll.notificationPredicate} + /// A check that specifies whether a [ScrollNotification] should be + /// handled by this widget. + /// + /// By default, checks whether `notification.depth == 0`. Set it to something + /// else for more complicated layouts, such as nested [ScrollView]s. + /// {@endtemplate} + final ScrollNotificationPredicate notificationPredicate; + + /// The widget below this widget in the tree. + /// + /// The overscroll indicator will paint on top of this child. This child (and its + /// subtree) should include a source of [ScrollNotification] notifications. + /// + /// Typically a [GlowingOverscrollIndicator] is created by a + /// [ScrollBehavior.buildOverscrollIndicator] method, in which case + /// the child is usually the one provided as an argument to that method. + final Widget? child; + + @override + State<GlowingOverscrollIndicator> createState() => _GlowingOverscrollIndicatorState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<AxisDirection>('axisDirection', axisDirection)); + final String showDescription; + if (showLeading && showTrailing) { + showDescription = 'both sides'; + } else if (showLeading) { + showDescription = 'leading side only'; + } else if (showTrailing) { + showDescription = 'trailing side only'; + } else { + showDescription = 'neither side (!)'; + } + properties.add(MessageProperty('show', showDescription)); + properties.add(ColorProperty('color', color, showName: false)); + } +} + +class _GlowingOverscrollIndicatorState extends State<GlowingOverscrollIndicator> with TickerProviderStateMixin { + _GlowController? _leadingController; + _GlowController? _trailingController; + Listenable? _leadingAndTrailingListener; + + @override + void initState() { + super.initState(); + _leadingController = _GlowController(vsync: this, color: widget.color, axis: widget.axis); + _trailingController = _GlowController(vsync: this, color: widget.color, axis: widget.axis); + _leadingAndTrailingListener = Listenable.merge(<Listenable>[_leadingController!, _trailingController!]); + } + + @override + void didUpdateWidget(GlowingOverscrollIndicator oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.color != widget.color || oldWidget.axis != widget.axis) { + _leadingController!.color = widget.color; + _leadingController!.axis = widget.axis; + _trailingController!.color = widget.color; + _trailingController!.axis = widget.axis; + } + } + + Type? _lastNotificationType; + final Map<bool, bool> _accepted = <bool, bool>{false: true, true: true}; + + bool _handleScrollNotification(ScrollNotification notification) { + if (!widget.notificationPredicate(notification)) { + return false; + } + if (notification.metrics.axis != widget.axis) { + // This widget is explicitly configured to one axis. If a notification + // from a different axis bubbles up, do nothing. + return false; + } + + // Update the paint offset with the current scroll position. This makes + // sure that the glow effect correctly scrolls in line with the current + // scroll, e.g. when scrolling in the opposite direction again to hide + // the glow. Otherwise, the glow would always stay in a fixed position, + // even if the top of the content already scrolled away. + // For example (CustomScrollView with sliver before center), the scroll + // extent is [-200.0, 300.0], scroll in the opposite direction with 10.0 pixels + // before glow disappears, so the current pixels is -190.0, + // in this case, we should move the glow up 10.0 pixels and should not + // overflow the scrollable widget's edge. https://github.com/flutter/flutter/issues/64149. + _leadingController!._paintOffsetScrollPixels = + -math.min(notification.metrics.pixels - notification.metrics.minScrollExtent, _leadingController!._paintOffset); + _trailingController!._paintOffsetScrollPixels = + -math.min(notification.metrics.maxScrollExtent - notification.metrics.pixels, _trailingController!._paintOffset); + + if (notification is OverscrollNotification) { + _GlowController? controller; + if (notification.overscroll < 0.0) { + controller = _leadingController; + } else if (notification.overscroll > 0.0) { + controller = _trailingController; + } else { + assert(false); + } + final bool isLeading = controller == _leadingController; + if (_lastNotificationType is! OverscrollNotification) { + final OverscrollIndicatorNotification confirmationNotification = OverscrollIndicatorNotification(leading: isLeading); + confirmationNotification.dispatch(context); + _accepted[isLeading] = confirmationNotification.accepted; + if (_accepted[isLeading]!) { + controller!._paintOffset = confirmationNotification.paintOffset; + } + } + assert(controller != null); + if (_accepted[isLeading]!) { + if (notification.velocity != 0.0) { + assert(notification.dragDetails == null); + controller!.absorbImpact(notification.velocity.abs()); + } else { + assert(notification.overscroll != 0.0); + if (notification.dragDetails != null) { + final RenderBox renderer = notification.context!.findRenderObject()! as RenderBox; + assert(renderer.hasSize); + final Size size = renderer.size; + final Offset position = renderer.globalToLocal(notification.dragDetails!.globalPosition); + switch (notification.metrics.axis) { + case Axis.horizontal: + controller!.pull(notification.overscroll.abs(), size.width, clampDouble(position.dy, 0.0, size.height), size.height); + case Axis.vertical: + controller!.pull(notification.overscroll.abs(), size.height, clampDouble(position.dx, 0.0, size.width), size.width); + } + } + } + } + } else if ((notification is ScrollEndNotification && notification.dragDetails != null) || + (notification is ScrollUpdateNotification && notification.dragDetails != null)) { + _leadingController!.scrollEnd(); + _trailingController!.scrollEnd(); + } + _lastNotificationType = notification.runtimeType; + return false; + } + + @override + void dispose() { + _leadingController!.dispose(); + _trailingController!.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return NotificationListener<ScrollNotification>( + onNotification: _handleScrollNotification, + child: RepaintBoundary( + child: CustomPaint( + foregroundPainter: _GlowingOverscrollIndicatorPainter( + leadingController: widget.showLeading ? _leadingController : null, + trailingController: widget.showTrailing ? _trailingController : null, + axisDirection: widget.axisDirection, + repaint: _leadingAndTrailingListener, + ), + child: RepaintBoundary( + child: widget.child, + ), + ), + ), + ); + } +} + +// The Glow logic is a port of the logic in the following file: +// https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/EdgeEffect.java +// as of December 2016. + +enum _GlowState { idle, absorb, pull, recede } + +class _GlowController extends ChangeNotifier { + _GlowController({ + required TickerProvider vsync, + required Color color, + required Axis axis, + }) : _color = color, + _axis = axis { + _glowController = AnimationController(vsync: vsync) + ..addStatusListener(_changePhase); + final Animation<double> decelerator = CurvedAnimation( + parent: _glowController, + curve: Curves.decelerate, + )..addListener(notifyListeners); + _glowOpacity = decelerator.drive(_glowOpacityTween); + _glowSize = decelerator.drive(_glowSizeTween); + _displacementTicker = vsync.createTicker(_tickDisplacement); + } + + // animation of the main axis direction + _GlowState _state = _GlowState.idle; + late final AnimationController _glowController; + Timer? _pullRecedeTimer; + double _paintOffset = 0.0; + double _paintOffsetScrollPixels = 0.0; + + // animation values + final Tween<double> _glowOpacityTween = Tween<double>(begin: 0.0, end: 0.0); + late final Animation<double> _glowOpacity; + final Tween<double> _glowSizeTween = Tween<double>(begin: 0.0, end: 0.0); + late final Animation<double> _glowSize; + + // animation of the cross axis position + late final Ticker _displacementTicker; + Duration? _displacementTickerLastElapsed; + double _displacementTarget = 0.5; + double _displacement = 0.5; + + // tracking the pull distance + double _pullDistance = 0.0; + + Color get color => _color; + Color _color; + set color(Color value) { + if (color == value) { + return; + } + _color = value; + notifyListeners(); + } + + Axis get axis => _axis; + Axis _axis; + set axis(Axis value) { + if (axis == value) { + return; + } + _axis = value; + notifyListeners(); + } + + static const Duration _recedeTime = Duration(milliseconds: 600); + static const Duration _pullTime = Duration(milliseconds: 167); + static const Duration _pullHoldTime = Duration(milliseconds: 167); + static const Duration _pullDecayTime = Duration(milliseconds: 2000); + static final Duration _crossAxisHalfTime = Duration(microseconds: (Duration.microsecondsPerSecond / 60.0).round()); + + static const double _maxOpacity = 0.5; + static const double _pullOpacityGlowFactor = 0.8; + static const double _velocityGlowFactor = 0.00006; + static const double _sqrt3 = 1.73205080757; // const math.sqrt(3) + static const double _widthToHeightFactor = (3.0 / 4.0) * (2.0 - _sqrt3); + + // absorbed velocities are clamped to the range _minVelocity.._maxVelocity + static const double _minVelocity = 100.0; // logical pixels per second + static const double _maxVelocity = 10000.0; // logical pixels per second + + @override + void dispose() { + _glowController.dispose(); + _displacementTicker.dispose(); + _pullRecedeTimer?.cancel(); + super.dispose(); + } + + /// Handle a scroll slamming into the edge at a particular velocity. + /// + /// The velocity must be positive. + void absorbImpact(double velocity) { + assert(velocity >= 0.0); + _pullRecedeTimer?.cancel(); + _pullRecedeTimer = null; + velocity = clampDouble(velocity, _minVelocity, _maxVelocity); + _glowOpacityTween.begin = _state == _GlowState.idle ? 0.3 : _glowOpacity.value; + _glowOpacityTween.end = clampDouble(velocity * _velocityGlowFactor, _glowOpacityTween.begin!, _maxOpacity); + _glowSizeTween.begin = _glowSize.value; + _glowSizeTween.end = math.min(0.025 + 7.5e-7 * velocity * velocity, 1.0); + _glowController.duration = Duration(milliseconds: (0.15 + velocity * 0.02).round()); + _glowController.forward(from: 0.0); + _displacement = 0.5; + _state = _GlowState.absorb; + } + + /// Handle a user-driven overscroll. + /// + /// The `overscroll` argument should be the scroll distance in logical pixels, + /// the `extent` argument should be the total dimension of the viewport in the + /// main axis in logical pixels, the `crossAxisOffset` argument should be the + /// distance from the leading (left or top) edge of the cross axis of the + /// viewport, and the `crossExtent` should be the size of the cross axis. For + /// example, a pull of 50 pixels up the middle of a 200 pixel high and 100 + /// pixel wide vertical viewport should result in a call of `pull(50.0, 200.0, + /// 50.0, 100.0)`. The `overscroll` value should be positive regardless of the + /// direction. + void pull(double overscroll, double extent, double crossAxisOffset, double crossExtent) { + _pullRecedeTimer?.cancel(); + _pullDistance += overscroll / 200.0; // This factor is magic. Not clear why we need it to match Android. + _glowOpacityTween.begin = _glowOpacity.value; + _glowOpacityTween.end = math.min(_glowOpacity.value + overscroll / extent * _pullOpacityGlowFactor, _maxOpacity); + final double height = math.min(extent, crossExtent * _widthToHeightFactor); + _glowSizeTween.begin = _glowSize.value; + _glowSizeTween.end = math.max(1.0 - 1.0 / (0.7 * math.sqrt(_pullDistance * height)), _glowSize.value); + _displacementTarget = crossAxisOffset / crossExtent; + if (_displacementTarget != _displacement) { + if (!_displacementTicker.isTicking) { + assert(_displacementTickerLastElapsed == null); + _displacementTicker.start(); + } + } else { + _displacementTicker.stop(); + _displacementTickerLastElapsed = null; + } + _glowController.duration = _pullTime; + if (_state != _GlowState.pull) { + _glowController.forward(from: 0.0); + _state = _GlowState.pull; + } else { + if (!_glowController.isAnimating) { + assert(_glowController.value == 1.0); + notifyListeners(); + } + } + _pullRecedeTimer = Timer(_pullHoldTime, () => _recede(_pullDecayTime)); + } + + void scrollEnd() { + if (_state == _GlowState.pull) { + _recede(_recedeTime); + } + } + + void _changePhase(AnimationStatus status) { + if (status != AnimationStatus.completed) { + return; + } + switch (_state) { + case _GlowState.absorb: + _recede(_recedeTime); + case _GlowState.recede: + _state = _GlowState.idle; + _pullDistance = 0.0; + case _GlowState.pull: + case _GlowState.idle: + break; + } + } + + void _recede(Duration duration) { + if (_state == _GlowState.recede || _state == _GlowState.idle) { + return; + } + _pullRecedeTimer?.cancel(); + _pullRecedeTimer = null; + _glowOpacityTween.begin = _glowOpacity.value; + _glowOpacityTween.end = 0.0; + _glowSizeTween.begin = _glowSize.value; + _glowSizeTween.end = 0.0; + _glowController.duration = duration; + _glowController.forward(from: 0.0); + _state = _GlowState.recede; + } + + void _tickDisplacement(Duration elapsed) { + if (_displacementTickerLastElapsed != null) { + final double t = (elapsed.inMicroseconds - _displacementTickerLastElapsed!.inMicroseconds).toDouble(); + _displacement = _displacementTarget - (_displacementTarget - _displacement) * math.pow(2.0, -t / _crossAxisHalfTime.inMicroseconds); + notifyListeners(); + } + if (nearEqual(_displacementTarget, _displacement, Tolerance.defaultTolerance.distance)) { + _displacementTicker.stop(); + _displacementTickerLastElapsed = null; + } else { + _displacementTickerLastElapsed = elapsed; + } + } + + void paint(Canvas canvas, Size size) { + if (_glowOpacity.value == 0.0) { + return; + } + final double baseGlowScale = size.width > size.height ? size.height / size.width : 1.0; + final double radius = size.width * 3.0 / 2.0; + final double height = math.min(size.height, size.width * _widthToHeightFactor); + final double scaleY = _glowSize.value * baseGlowScale; + final Rect rect = Rect.fromLTWH(0.0, 0.0, size.width, height); + final Offset center = Offset((size.width / 2.0) * (0.5 + _displacement), height - radius); + final Paint paint = Paint()..color = color.withOpacity(_glowOpacity.value); + canvas.save(); + canvas.translate(0.0, _paintOffset + _paintOffsetScrollPixels); + canvas.scale(1.0, scaleY); + canvas.clipRect(rect); + canvas.drawCircle(center, radius, paint); + canvas.restore(); + } + + @override + String toString() { + return '_GlowController(color: $color, axis: ${axis.name})'; + } +} + +class _GlowingOverscrollIndicatorPainter extends CustomPainter { + _GlowingOverscrollIndicatorPainter({ + this.leadingController, + this.trailingController, + required this.axisDirection, + super.repaint, + }); + + /// The controller for the overscroll glow on the side with negative scroll offsets. + /// + /// For a vertical downwards viewport, this is the top side. + final _GlowController? leadingController; + + /// The controller for the overscroll glow on the side with positive scroll offsets. + /// + /// For a vertical downwards viewport, this is the bottom side. + final _GlowController? trailingController; + + /// The direction of the viewport. + final AxisDirection axisDirection; + + static const double piOver2 = math.pi / 2.0; + + void _paintSide(Canvas canvas, Size size, _GlowController? controller, AxisDirection axisDirection, GrowthDirection growthDirection) { + if (controller == null) { + return; + } + switch (applyGrowthDirectionToAxisDirection(axisDirection, growthDirection)) { + case AxisDirection.up: + controller.paint(canvas, size); + case AxisDirection.down: + canvas.save(); + canvas.translate(0.0, size.height); + canvas.scale(1.0, -1.0); + controller.paint(canvas, size); + canvas.restore(); + case AxisDirection.left: + canvas.save(); + canvas.rotate(piOver2); + canvas.scale(1.0, -1.0); + controller.paint(canvas, Size(size.height, size.width)); + canvas.restore(); + case AxisDirection.right: + canvas.save(); + canvas.translate(size.width, 0.0); + canvas.rotate(piOver2); + controller.paint(canvas, Size(size.height, size.width)); + canvas.restore(); + } + } + + @override + void paint(Canvas canvas, Size size) { + _paintSide(canvas, size, leadingController, axisDirection, GrowthDirection.reverse); + _paintSide(canvas, size, trailingController, axisDirection, GrowthDirection.forward); + } + + @override + bool shouldRepaint(_GlowingOverscrollIndicatorPainter oldDelegate) { + return oldDelegate.leadingController != leadingController + || oldDelegate.trailingController != trailingController; + } + + @override + String toString() { + return '_GlowingOverscrollIndicatorPainter($leadingController, $trailingController)'; + } +} + +enum _StretchDirection { + /// The [trailing] direction indicates that the content will be stretched toward + /// the trailing edge. + trailing, + /// The [leading] direction indicates that the content will be stretched toward + /// the leading edge. + leading, +} + +/// A Material Design visual indication that a scroll view has overscrolled. +/// +/// A [StretchingOverscrollIndicator] listens for [ScrollNotification]s in order +/// to stretch the content of the [Scrollable]. These notifications are typically +/// generated by a [ScrollView], such as a [ListView] or a [GridView]. +/// +/// When triggered, the [StretchingOverscrollIndicator] generates an +/// [OverscrollIndicatorNotification] before showing an overscroll indication. +/// To prevent the indicator from showing the indication, call +/// [OverscrollIndicatorNotification.disallowIndicator] on the notification. +/// +/// Created by [MaterialScrollBehavior.buildOverscrollIndicator] on platforms +/// (e.g., Android) that commonly use this type of overscroll indication when +/// [ThemeData.useMaterial3] is true. Otherwise, when [ThemeData.useMaterial3] +/// is false, a [GlowingOverscrollIndicator] is used instead.= +/// +/// See also: +/// +/// * [OverscrollIndicatorNotification], which can be used to prevent the +/// stretch effect from being applied at all. +/// * [NotificationListener], to listen for the +/// [OverscrollIndicatorNotification]. +/// * [GlowingOverscrollIndicator], the default overscroll indicator for +/// [TargetPlatform.android] and [TargetPlatform.fuchsia]. +class StretchingOverscrollIndicator extends StatefulWidget { + /// Creates a visual indication that a scroll view has overscrolled by + /// applying a stretch transformation to the content. + /// + /// In order for this widget to display an overscroll indication, the [child] + /// widget must contain a widget that generates a [ScrollNotification], such + /// as a [ListView] or a [GridView]. + const StretchingOverscrollIndicator({ + super.key, + required this.axisDirection, + this.notificationPredicate = defaultScrollNotificationPredicate, + this.clipBehavior = Clip.hardEdge, + this.child, + }); + + /// {@macro flutter.overscroll.axisDirection} + final AxisDirection axisDirection; + + /// {@macro flutter.overscroll.axis} + Axis get axis => axisDirectionToAxis(axisDirection); + + /// {@macro flutter.overscroll.notificationPredicate} + final ScrollNotificationPredicate notificationPredicate; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// The widget below this widget in the tree. + /// + /// The overscroll indicator will apply a stretch effect to this child. This + /// child (and its subtree) should include a source of [ScrollNotification] + /// notifications. + final Widget? child; + + @override + State<StretchingOverscrollIndicator> createState() => _StretchingOverscrollIndicatorState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<AxisDirection>('axisDirection', axisDirection)); + } +} + +class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndicator> with TickerProviderStateMixin { + late final _StretchController _stretchController = _StretchController(vsync: this); + ScrollNotification? _lastNotification; + OverscrollNotification? _lastOverscrollNotification; + + double _totalOverscroll = 0.0; + + bool _accepted = true; + + bool _handleScrollNotification(ScrollNotification notification) { + if (!widget.notificationPredicate(notification)) { + return false; + } + if (notification.metrics.axis != widget.axis) { + // This widget is explicitly configured to one axis. If a notification + // from a different axis bubbles up, do nothing. + return false; + } + + if (notification is OverscrollNotification) { + _lastOverscrollNotification = notification; + if (_lastNotification.runtimeType is! OverscrollNotification) { + final OverscrollIndicatorNotification confirmationNotification = OverscrollIndicatorNotification(leading: notification.overscroll < 0.0); + confirmationNotification.dispatch(context); + _accepted = confirmationNotification.accepted; + } + + if (_accepted) { + _totalOverscroll += notification.overscroll; + + if (notification.velocity != 0.0) { + assert(notification.dragDetails == null); + _stretchController.absorbImpact(notification.velocity.abs(), _totalOverscroll); + } else { + assert(notification.overscroll != 0.0); + if (notification.dragDetails != null) { + // We clamp the overscroll amount relative to the length of the viewport, + // which is the furthest distance a single pointer could pull on the + // screen. This is because more than one pointer will multiply the + // amount of overscroll - https://github.com/flutter/flutter/issues/11884 + + final double viewportDimension = notification.metrics.viewportDimension; + final double distanceForPull = _totalOverscroll.abs() / viewportDimension; + final double clampedOverscroll = clampDouble(distanceForPull, 0, 1.0); + _stretchController.pull(clampedOverscroll, _totalOverscroll); + } + } + } + } else if (notification is ScrollEndNotification || notification is ScrollUpdateNotification) { + // Since the overscrolling ended, we reset the total overscroll amount. + _totalOverscroll = 0; + _stretchController.scrollEnd(); + } + _lastNotification = notification; + return false; + } + + AlignmentGeometry _getAlignmentForAxisDirection(_StretchDirection stretchDirection) { + // Accounts for reversed scrollables by checking the AxisDirection + switch (widget.axisDirection) { + case AxisDirection.up: + return stretchDirection == _StretchDirection.trailing + ? AlignmentDirectional.topCenter + : AlignmentDirectional.bottomCenter; + case AxisDirection.right: + return stretchDirection == _StretchDirection.trailing + ? Alignment.centerRight + : Alignment.centerLeft; + case AxisDirection.down: + return stretchDirection == _StretchDirection.trailing + ? AlignmentDirectional.bottomCenter + : AlignmentDirectional.topCenter; + case AxisDirection.left: + return stretchDirection == _StretchDirection.trailing + ? Alignment.centerLeft + : Alignment.centerRight; + } + } + + @override + void dispose() { + _stretchController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final Size size = MediaQuery.sizeOf(context); + double mainAxisSize; + return NotificationListener<ScrollNotification>( + onNotification: _handleScrollNotification, + child: AnimatedBuilder( + animation: _stretchController, + builder: (BuildContext context, Widget? child) { + final double stretch = _stretchController.value; + double x = 1.0; + double y = 1.0; + + switch (widget.axis) { + case Axis.horizontal: + x += stretch; + mainAxisSize = size.width; + case Axis.vertical: + y += stretch; + mainAxisSize = size.height; + } + + final AlignmentGeometry alignment = _getAlignmentForAxisDirection( + _stretchController.stretchDirection, + ); + + final double viewportDimension = _lastOverscrollNotification?.metrics.viewportDimension ?? mainAxisSize; + final Widget transform = Transform( + alignment: alignment, + transform: Matrix4.diagonal3Values(x, y, 1.0), + filterQuality: stretch == 0 ? null : FilterQuality.low, + child: widget.child, + ); + + // Only clip if the viewport dimension is smaller than that of the + // screen size in the main axis. If the viewport takes up the whole + // screen, overflow from transforming the viewport is irrelevant. + return ClipRect( + clipBehavior: stretch != 0.0 && viewportDimension != mainAxisSize + ? widget.clipBehavior + : Clip.none, + child: transform, + ); + }, + ), + ); + } +} + +enum _StretchState { + idle, + absorb, + pull, + recede, +} + +class _StretchController extends ChangeNotifier { + _StretchController({ required TickerProvider vsync }) { + _stretchController = AnimationController(vsync: vsync) + ..addStatusListener(_changePhase); + final Animation<double> decelerator = CurvedAnimation( + parent: _stretchController, + curve: Curves.decelerate, + )..addListener(notifyListeners); + _stretchSize = decelerator.drive(_stretchSizeTween); + } + + late final AnimationController _stretchController; + late final Animation<double> _stretchSize; + final Tween<double> _stretchSizeTween = Tween<double>(begin: 0.0, end: 0.0); + _StretchState _state = _StretchState.idle; + + double get pullDistance => _pullDistance; + double _pullDistance = 0.0; + + _StretchDirection get stretchDirection => _stretchDirection; + _StretchDirection _stretchDirection = _StretchDirection.trailing; + + // Constants from Android. + static const double _exponentialScalar = math.e / 0.33; + static const double _stretchIntensity = 0.016; + static const double _flingFriction = 1.01; + static const Duration _stretchDuration = Duration(milliseconds: 400); + + double get value => _stretchSize.value; + + /// Handle a fling to the edge of the viewport at a particular velocity. + /// + /// The velocity must be positive. + void absorbImpact(double velocity, double totalOverscroll) { + assert(velocity >= 0.0); + velocity = clampDouble(velocity, 1, 10000); + _stretchSizeTween.begin = _stretchSize.value; + _stretchSizeTween.end = math.min(_stretchIntensity + (_flingFriction / velocity), 1.0); + _stretchController.duration = Duration(milliseconds: (velocity * 0.02).round()); + _stretchController.forward(from: 0.0); + _state = _StretchState.absorb; + _stretchDirection = totalOverscroll > 0 ? _StretchDirection.trailing : _StretchDirection.leading; + } + + /// Handle a user-driven overscroll. + /// + /// The `normalizedOverscroll` argument should be the absolute value of the + /// scroll distance in logical pixels, divided by the extent of the viewport + /// in the main axis. + void pull(double normalizedOverscroll, double totalOverscroll) { + assert(normalizedOverscroll >= 0.0); + + final _StretchDirection newStretchDirection = totalOverscroll > 0 ? _StretchDirection.trailing : _StretchDirection.leading; + if (_stretchDirection != newStretchDirection && _state == _StretchState.recede) { + // When the stretch direction changes while we are in the recede state, we need to ignore the change. + // If we don't, the stretch will instantly jump to the new direction with the recede animation still playing, which causes + // a unwanted visual abnormality (https://github.com/flutter/flutter/pull/116548#issuecomment-1414872567). + // By ignoring the directional change until the recede state is finished, we can avoid this. + return; + } + + _stretchDirection = newStretchDirection; + _pullDistance = normalizedOverscroll; + _stretchSizeTween.begin = _stretchSize.value; + final double linearIntensity =_stretchIntensity * _pullDistance; + final double exponentialIntensity = _stretchIntensity * (1 - math.exp(-_pullDistance * _exponentialScalar)); + _stretchSizeTween.end = linearIntensity + exponentialIntensity; + _stretchController.duration = _stretchDuration; + if (_state != _StretchState.pull) { + _stretchController.forward(from: 0.0); + _state = _StretchState.pull; + } else { + if (!_stretchController.isAnimating) { + assert(_stretchController.value == 1.0); + notifyListeners(); + } + } + } + + void scrollEnd() { + if (_state == _StretchState.pull) { + _recede(_stretchDuration); + } + } + + void _changePhase(AnimationStatus status) { + if (status != AnimationStatus.completed) { + return; + } + switch (_state) { + case _StretchState.absorb: + _recede(_stretchDuration); + case _StretchState.recede: + _state = _StretchState.idle; + _pullDistance = 0.0; + case _StretchState.pull: + case _StretchState.idle: + break; + } + } + + void _recede(Duration duration) { + if (_state == _StretchState.recede || _state == _StretchState.idle) { + return; + } + _stretchSizeTween.begin = _stretchSize.value; + _stretchSizeTween.end = 0.0; + _stretchController.duration = duration; + _stretchController.forward(from: 0.0); + _state = _StretchState.recede; + } + + @override + void dispose() { + _stretchController.dispose(); + super.dispose(); + } + + @override + String toString() => '_StretchController()'; +} + +/// A notification that either a [GlowingOverscrollIndicator] or a +/// [StretchingOverscrollIndicator] will start showing an overscroll indication. +/// +/// To prevent the indicator from showing the indication, call +/// [disallowIndicator] on the notification. +/// +/// See also: +/// +/// * [GlowingOverscrollIndicator], which generates this type of notification +/// by painting an indicator over the child content. +/// * [StretchingOverscrollIndicator], which generates this type of +/// notification by applying a stretch transformation to the child content. +class OverscrollIndicatorNotification extends Notification with ViewportNotificationMixin { + /// Creates a notification that an [GlowingOverscrollIndicator] or a + /// [StretchingOverscrollIndicator] will start showing an overscroll indication. + OverscrollIndicatorNotification({ + required this.leading, + }); + + /// Whether the indication will be shown on the leading edge of the scroll + /// view. + final bool leading; + + /// Controls at which offset a [GlowingOverscrollIndicator] draws. + /// + /// A positive offset will move the glow away from its edge, + /// i.e. for a vertical, [leading] indicator, a [paintOffset] of 100.0 will + /// draw the indicator 100.0 pixels from the top of the edge. + /// For a vertical indicator with [leading] set to `false`, a [paintOffset] + /// of 100.0 will draw the indicator 100.0 pixels from the bottom instead. + /// + /// A negative [paintOffset] is generally not useful, since the glow will be + /// clipped. + /// + /// This has no effect on a [StretchingOverscrollIndicator]. + double paintOffset = 0.0; + + @protected + @visibleForTesting + /// Whether the current overscroll event will allow for the indicator to be + /// shown. + /// + /// Calling [disallowIndicator] sets this to false, preventing the over scroll + /// indicator from showing. + /// + /// Defaults to true. + bool accepted = true; + + /// Call this method if the overscroll indicator should be prevented. + void disallowIndicator() { + accepted = false; + } + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + description.add('side: ${leading ? "leading edge" : "trailing edge"}'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/page_storage.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/page_storage.dart new file mode 100644 index 0000000000000000000000000000000000000000..808274172c6815562ca0672229ca6f5af810733f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/page_storage.dart @@ -0,0 +1,238 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'framework.dart'; + +// Examples can assume: +// late BuildContext context; + +/// A [Key] that can be used to persist the widget state in storage after the +/// destruction and will be restored when recreated. +/// +/// Each key with its value plus the ancestor chain of other [PageStorageKey]s +/// need to be unique within the widget's closest ancestor [PageStorage]. To +/// make it possible for a saved value to be found when a widget is recreated, +/// the key's value must not be objects whose identity will change each time the +/// widget is created. +/// +/// See also: +/// +/// * [PageStorage], which manages the data storage for widgets using +/// [PageStorageKey]s. +class PageStorageKey<T> extends ValueKey<T> { + /// Creates a [ValueKey] that defines where [PageStorage] values will be saved. + const PageStorageKey(super.value); +} + +@immutable +class _StorageEntryIdentifier { + const _StorageEntryIdentifier(this.keys); + + final List<PageStorageKey<dynamic>> keys; + + bool get isNotEmpty => keys.isNotEmpty; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _StorageEntryIdentifier + && listEquals<PageStorageKey<dynamic>>(other.keys, keys); + } + + @override + int get hashCode => Object.hashAll(keys); + + @override + String toString() { + return 'StorageEntryIdentifier(${keys.join(":")})'; + } +} + +/// A storage bucket associated with a page in an app. +/// +/// Useful for storing per-page state that persists across navigations from one +/// page to another. +class PageStorageBucket { + static bool _maybeAddKey(BuildContext context, List<PageStorageKey<dynamic>> keys) { + final Widget widget = context.widget; + final Key? key = widget.key; + if (key is PageStorageKey) { + keys.add(key); + } + return widget is! PageStorage; + } + + List<PageStorageKey<dynamic>> _allKeys(BuildContext context) { + final List<PageStorageKey<dynamic>> keys = <PageStorageKey<dynamic>>[]; + if (_maybeAddKey(context, keys)) { + context.visitAncestorElements((Element element) { + return _maybeAddKey(element, keys); + }); + } + return keys; + } + + _StorageEntryIdentifier _computeIdentifier(BuildContext context) { + return _StorageEntryIdentifier(_allKeys(context)); + } + + Map<Object, dynamic>? _storage; + + /// Write the given data into this page storage bucket using the + /// specified identifier or an identifier computed from the given context. + /// The computed identifier is based on the [PageStorageKey]s + /// found in the path from context to the [PageStorage] widget that + /// owns this page storage bucket. + /// + /// If an explicit identifier is not provided and no [PageStorageKey]s + /// are found, then the `data` is not saved. + void writeState(BuildContext context, dynamic data, { Object? identifier }) { + _storage ??= <Object, dynamic>{}; + if (identifier != null) { + _storage![identifier] = data; + } else { + final _StorageEntryIdentifier contextIdentifier = _computeIdentifier(context); + if (contextIdentifier.isNotEmpty) { + _storage![contextIdentifier] = data; + } + } + } + + /// Read given data from into this page storage bucket using the specified + /// identifier or an identifier computed from the given context. + /// The computed identifier is based on the [PageStorageKey]s + /// found in the path from context to the [PageStorage] widget that + /// owns this page storage bucket. + /// + /// If an explicit identifier is not provided and no [PageStorageKey]s + /// are found, then null is returned. + dynamic readState(BuildContext context, { Object? identifier }) { + if (_storage == null) { + return null; + } + if (identifier != null) { + return _storage![identifier]; + } + final _StorageEntryIdentifier contextIdentifier = _computeIdentifier(context); + return contextIdentifier.isNotEmpty ? _storage![contextIdentifier] : null; + } +} + +/// Establish a subtree in which widgets can opt into persisting states after +/// being destroyed. +/// +/// [PageStorage] is used to save and restore values that can outlive the widget. +/// For example, when multiple pages are grouped in tabs, when a page is +/// switched out, its widget is destroyed and its state is lost. By adding a +/// [PageStorage] at the root and adding a [PageStorageKey] to each page, some of the +/// page's state (e.g. the scroll position of a [Scrollable] widget) will be stored +/// automatically in its closest ancestor [PageStorage], and restored when it's +/// switched back. +/// +/// Usually you don't need to explicitly use a [PageStorage], since it's already +/// included in routes. +/// +/// [PageStorageKey] is used by [Scrollable] if [ScrollController.keepScrollOffset] +/// is enabled to save their [ScrollPosition]s. When more than one scrollable +/// ([ListView], [SingleChildScrollView], [TextField], etc.) appears within the +/// widget's closest ancestor [PageStorage] (such as within the same route), to +/// save all of their positions independently, one must give each of them unique +/// [PageStorageKey]s, or set the `keepScrollOffset` property of some such +/// widgets to false to prevent saving. +/// +/// {@tool dartpad} +/// This sample shows how to explicitly use a [PageStorage] to +/// store the states of its children pages. Each page includes a scrollable +/// list, whose position is preserved when switching between the tabs thanks to +/// the help of [PageStorageKey]. +/// +/// ** See code in examples/api/lib/widgets/page_storage/page_storage.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ModalRoute], which includes this class. +class PageStorage extends StatelessWidget { + /// Creates a widget that provides a storage bucket for its descendants. + const PageStorage({ + super.key, + required this.bucket, + required this.child, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The page storage bucket to use for this subtree. + final PageStorageBucket bucket; + + /// The [PageStorageBucket] from the closest instance of a [PageStorage] + /// widget that encloses the given context. + /// + /// Returns null if none exists. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// PageStorageBucket? bucket = PageStorage.of(context); + /// ``` + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [PageStorage.of], which is similar to this method, but + /// asserts if no [PageStorage] ancestor is found. + static PageStorageBucket? maybeOf(BuildContext context) { + final PageStorage? widget = context.findAncestorWidgetOfExactType<PageStorage>(); + return widget?.bucket; + } + + /// The [PageStorageBucket] from the closest instance of a [PageStorage] + /// widget that encloses the given context. + /// + /// If no ancestor is found, this method will assert in debug mode, and throw + /// an exception in release mode. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// PageStorageBucket bucket = PageStorage.of(context); + /// ``` + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [PageStorage.maybeOf], which is similar to this method, but + /// returns null if no [PageStorage] ancestor is found. + static PageStorageBucket of(BuildContext context) { + final PageStorageBucket? bucket = maybeOf(context); + assert(() { + if (bucket == null) { + throw FlutterError( + 'PageStorage.of() was called with a context that does not contain a ' + 'PageStorage widget.\n' + 'No PageStorage widget ancestor could be found starting from the ' + 'context that was passed to PageStorage.of(). This can happen ' + 'because you are using a widget that looks for a PageStorage ' + 'ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return bucket!; + } + + @override + Widget build(BuildContext context) => child; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/page_view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/page_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..33a139e87e427469c05116ae9f34859b40f11099 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/page_view.dart @@ -0,0 +1,932 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart' show clampDouble, precisionErrorTolerance; +import 'package:flutter/gestures.dart' show DragStartBehavior; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'notification_listener.dart'; +import 'page_storage.dart'; +import 'scroll_configuration.dart'; +import 'scroll_context.dart'; +import 'scroll_controller.dart'; +import 'scroll_delegate.dart'; +import 'scroll_metrics.dart'; +import 'scroll_notification.dart'; +import 'scroll_physics.dart'; +import 'scroll_position.dart'; +import 'scroll_position_with_single_context.dart'; +import 'scroll_view.dart'; +import 'scrollable.dart'; +import 'sliver_fill.dart'; +import 'viewport.dart'; + +/// A controller for [PageView]. +/// +/// A page controller lets you manipulate which page is visible in a [PageView]. +/// In addition to being able to control the pixel offset of the content inside +/// the [PageView], a [PageController] also lets you control the offset in terms +/// of pages, which are increments of the viewport size. +/// +/// See also: +/// +/// * [PageView], which is the widget this object controls. +/// +/// {@tool snippet} +/// +/// This widget introduces a [MaterialApp], [Scaffold] and [PageView] with two pages +/// using the default constructor. Both pages contain an [ElevatedButton] allowing you +/// to animate the [PageView] using a [PageController]. +/// +/// ```dart +/// class MyPageView extends StatefulWidget { +/// const MyPageView({super.key}); +/// +/// @override +/// State<MyPageView> createState() => _MyPageViewState(); +/// } +/// +/// class _MyPageViewState extends State<MyPageView> { +/// final PageController _pageController = PageController(); +/// +/// @override +/// void dispose() { +/// _pageController.dispose(); +/// super.dispose(); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return MaterialApp( +/// home: Scaffold( +/// body: PageView( +/// controller: _pageController, +/// children: <Widget>[ +/// ColoredBox( +/// color: Colors.red, +/// child: Center( +/// child: ElevatedButton( +/// onPressed: () { +/// if (_pageController.hasClients) { +/// _pageController.animateToPage( +/// 1, +/// duration: const Duration(milliseconds: 400), +/// curve: Curves.easeInOut, +/// ); +/// } +/// }, +/// child: const Text('Next'), +/// ), +/// ), +/// ), +/// ColoredBox( +/// color: Colors.blue, +/// child: Center( +/// child: ElevatedButton( +/// onPressed: () { +/// if (_pageController.hasClients) { +/// _pageController.animateToPage( +/// 0, +/// duration: const Duration(milliseconds: 400), +/// curve: Curves.easeInOut, +/// ); +/// } +/// }, +/// child: const Text('Previous'), +/// ), +/// ), +/// ), +/// ], +/// ), +/// ), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +class PageController extends ScrollController { + /// Creates a page controller. + PageController({ + this.initialPage = 0, + this.keepPage = true, + this.viewportFraction = 1.0, + super.onAttach, + super.onDetach, + }) : assert(viewportFraction > 0.0); + + /// The page to show when first creating the [PageView]. + final int initialPage; + + /// Save the current [page] with [PageStorage] and restore it if + /// this controller's scrollable is recreated. + /// + /// If this property is set to false, the current [page] is never saved + /// and [initialPage] is always used to initialize the scroll offset. + /// If true (the default), the initial page is used the first time the + /// controller's scrollable is created, since there's isn't a page to + /// restore yet. Subsequently the saved page is restored and + /// [initialPage] is ignored. + /// + /// See also: + /// + /// * [PageStorageKey], which should be used when more than one + /// scrollable appears in the same route, to distinguish the [PageStorage] + /// locations used to save scroll offsets. + final bool keepPage; + + /// {@template flutter.widgets.pageview.viewportFraction} + /// The fraction of the viewport that each page should occupy. + /// + /// Defaults to 1.0, which means each page fills the viewport in the scrolling + /// direction. + /// {@endtemplate} + final double viewportFraction; + + /// The current page displayed in the controlled [PageView]. + /// + /// There are circumstances that this [PageController] can't know the current + /// page. Reading [page] will throw an [AssertionError] in the following cases: + /// + /// 1. No [PageView] is currently using this [PageController]. Once a + /// [PageView] starts using this [PageController], the new [page] + /// position will be derived: + /// + /// * First, based on the attached [PageView]'s [BuildContext] and the + /// position saved at that context's [PageStorage] if [keepPage] is true. + /// * Second, from the [PageController]'s [initialPage]. + /// + /// 2. More than one [PageView] using the same [PageController]. + /// + /// The [hasClients] property can be used to check if a [PageView] is attached + /// prior to accessing [page]. + double? get page { + assert( + positions.isNotEmpty, + 'PageController.page cannot be accessed before a PageView is built with it.', + ); + assert( + positions.length == 1, + 'The page property cannot be read when multiple PageViews are attached to ' + 'the same PageController.', + ); + final _PagePosition position = this.position as _PagePosition; + return position.page; + } + + /// Animates the controlled [PageView] from the current page to the given page. + /// + /// The animation lasts for the given duration and follows the given curve. + /// The returned [Future] resolves when the animation completes. + Future<void> animateToPage( + int page, { + required Duration duration, + required Curve curve, + }) { + final _PagePosition position = this.position as _PagePosition; + if (position._cachedPage != null) { + position._cachedPage = page.toDouble(); + return Future<void>.value(); + } + + return position.animateTo( + position.getPixelsFromPage(page.toDouble()), + duration: duration, + curve: curve, + ); + } + + /// Changes which page is displayed in the controlled [PageView]. + /// + /// Jumps the page position from its current value to the given value, + /// without animation, and without checking if the new value is in range. + void jumpToPage(int page) { + final _PagePosition position = this.position as _PagePosition; + if (position._cachedPage != null) { + position._cachedPage = page.toDouble(); + return; + } + + position.jumpTo(position.getPixelsFromPage(page.toDouble())); + } + + /// Animates the controlled [PageView] to the next page. + /// + /// The animation lasts for the given duration and follows the given curve. + /// The returned [Future] resolves when the animation completes. + Future<void> nextPage({ required Duration duration, required Curve curve }) { + return animateToPage(page!.round() + 1, duration: duration, curve: curve); + } + + /// Animates the controlled [PageView] to the previous page. + /// + /// The animation lasts for the given duration and follows the given curve. + /// The returned [Future] resolves when the animation completes. + Future<void> previousPage({ required Duration duration, required Curve curve }) { + return animateToPage(page!.round() - 1, duration: duration, curve: curve); + } + + @override + ScrollPosition createScrollPosition(ScrollPhysics physics, ScrollContext context, ScrollPosition? oldPosition) { + return _PagePosition( + physics: physics, + context: context, + initialPage: initialPage, + keepPage: keepPage, + viewportFraction: viewportFraction, + oldPosition: oldPosition, + ); + } + + @override + void attach(ScrollPosition position) { + super.attach(position); + final _PagePosition pagePosition = position as _PagePosition; + pagePosition.viewportFraction = viewportFraction; + } +} + +/// Metrics for a [PageView]. +/// +/// The metrics are available on [ScrollNotification]s generated from +/// [PageView]s. +class PageMetrics extends FixedScrollMetrics { + /// Creates an immutable snapshot of values associated with a [PageView]. + PageMetrics({ + required super.minScrollExtent, + required super.maxScrollExtent, + required super.pixels, + required super.viewportDimension, + required super.axisDirection, + required this.viewportFraction, + required super.devicePixelRatio, + }); + + @override + PageMetrics copyWith({ + double? minScrollExtent, + double? maxScrollExtent, + double? pixels, + double? viewportDimension, + AxisDirection? axisDirection, + double? viewportFraction, + double? devicePixelRatio, + }) { + return PageMetrics( + minScrollExtent: minScrollExtent ?? (hasContentDimensions ? this.minScrollExtent : null), + maxScrollExtent: maxScrollExtent ?? (hasContentDimensions ? this.maxScrollExtent : null), + pixels: pixels ?? (hasPixels ? this.pixels : null), + viewportDimension: viewportDimension ?? (hasViewportDimension ? this.viewportDimension : null), + axisDirection: axisDirection ?? this.axisDirection, + viewportFraction: viewportFraction ?? this.viewportFraction, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + ); + } + + /// The current page displayed in the [PageView]. + double? get page { + return math.max(0.0, clampDouble(pixels, minScrollExtent, maxScrollExtent)) / + math.max(1.0, viewportDimension * viewportFraction); + } + + /// The fraction of the viewport that each page occupies. + /// + /// Used to compute [page] from the current [pixels]. + final double viewportFraction; +} + +class _PagePosition extends ScrollPositionWithSingleContext implements PageMetrics { + _PagePosition({ + required super.physics, + required super.context, + this.initialPage = 0, + bool keepPage = true, + double viewportFraction = 1.0, + super.oldPosition, + }) : assert(viewportFraction > 0.0), + _viewportFraction = viewportFraction, + _pageToUseOnStartup = initialPage.toDouble(), + super( + initialPixels: null, + keepScrollOffset: keepPage, + ); + + final int initialPage; + double _pageToUseOnStartup; + // When the viewport has a zero-size, the `page` can not + // be retrieved by `getPageFromPixels`, so we need to cache the page + // for use when resizing the viewport to non-zero next time. + double? _cachedPage; + + @override + Future<void> ensureVisible( + RenderObject object, { + double alignment = 0.0, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit, + RenderObject? targetRenderObject, + }) { + // Since the _PagePosition is intended to cover the available space within + // its viewport, stop trying to move the target render object to the center + // - otherwise, could end up changing which page is visible and moving the + // targetRenderObject out of the viewport. + return super.ensureVisible( + object, + alignment: alignment, + duration: duration, + curve: curve, + alignmentPolicy: alignmentPolicy, + ); + } + + @override + double get viewportFraction => _viewportFraction; + double _viewportFraction; + set viewportFraction(double value) { + if (_viewportFraction == value) { + return; + } + final double? oldPage = page; + _viewportFraction = value; + if (oldPage != null) { + forcePixels(getPixelsFromPage(oldPage)); + } + } + + // The amount of offset that will be added to [minScrollExtent] and subtracted + // from [maxScrollExtent], such that every page will properly snap to the center + // of the viewport when viewportFraction is greater than 1. + // + // The value is 0 if viewportFraction is less than or equal to 1, larger than 0 + // otherwise. + double get _initialPageOffset => math.max(0, viewportDimension * (viewportFraction - 1) / 2); + + double getPageFromPixels(double pixels, double viewportDimension) { + assert(viewportDimension > 0.0); + final double actual = math.max(0.0, pixels - _initialPageOffset) / (viewportDimension * viewportFraction); + final double round = actual.roundToDouble(); + if ((actual - round).abs() < precisionErrorTolerance) { + return round; + } + return actual; + } + + double getPixelsFromPage(double page) { + return page * viewportDimension * viewportFraction + _initialPageOffset; + } + + @override + double? get page { + assert( + !hasPixels || hasContentDimensions, + 'Page value is only available after content dimensions are established.', + ); + return !hasPixels || !hasContentDimensions + ? null + : _cachedPage ?? getPageFromPixels(clampDouble(pixels, minScrollExtent, maxScrollExtent), viewportDimension); + } + + @override + void saveScrollOffset() { + PageStorage.maybeOf(context.storageContext)?.writeState(context.storageContext, _cachedPage ?? getPageFromPixels(pixels, viewportDimension)); + } + + @override + void restoreScrollOffset() { + if (!hasPixels) { + final double? value = PageStorage.maybeOf(context.storageContext)?.readState(context.storageContext) as double?; + if (value != null) { + _pageToUseOnStartup = value; + } + } + } + + @override + void saveOffset() { + context.saveOffset(_cachedPage ?? getPageFromPixels(pixels, viewportDimension)); + } + + @override + void restoreOffset(double offset, {bool initialRestore = false}) { + if (initialRestore) { + _pageToUseOnStartup = offset; + } else { + jumpTo(getPixelsFromPage(offset)); + } + } + + @override + bool applyViewportDimension(double viewportDimension) { + final double? oldViewportDimensions = hasViewportDimension ? this.viewportDimension : null; + if (viewportDimension == oldViewportDimensions) { + return true; + } + final bool result = super.applyViewportDimension(viewportDimension); + final double? oldPixels = hasPixels ? pixels : null; + double page; + if (oldPixels == null) { + page = _pageToUseOnStartup; + } else if (oldViewportDimensions == 0.0) { + // If resize from zero, we should use the _cachedPage to recover the state. + page = _cachedPage!; + } else { + page = getPageFromPixels(oldPixels, oldViewportDimensions!); + } + final double newPixels = getPixelsFromPage(page); + + // If the viewportDimension is zero, cache the page + // in case the viewport is resized to be non-zero. + _cachedPage = (viewportDimension == 0.0) ? page : null; + + if (newPixels != oldPixels) { + correctPixels(newPixels); + return false; + } + return result; + } + + @override + void absorb(ScrollPosition other) { + super.absorb(other); + assert(_cachedPage == null); + + if (other is! _PagePosition) { + return; + } + + if (other._cachedPage != null) { + _cachedPage = other._cachedPage; + } + } + + @override + bool applyContentDimensions(double minScrollExtent, double maxScrollExtent) { + final double newMinScrollExtent = minScrollExtent + _initialPageOffset; + return super.applyContentDimensions( + newMinScrollExtent, + math.max(newMinScrollExtent, maxScrollExtent - _initialPageOffset), + ); + } + + @override + PageMetrics copyWith({ + double? minScrollExtent, + double? maxScrollExtent, + double? pixels, + double? viewportDimension, + AxisDirection? axisDirection, + double? viewportFraction, + double? devicePixelRatio, + }) { + return PageMetrics( + minScrollExtent: minScrollExtent ?? (hasContentDimensions ? this.minScrollExtent : null), + maxScrollExtent: maxScrollExtent ?? (hasContentDimensions ? this.maxScrollExtent : null), + pixels: pixels ?? (hasPixels ? this.pixels : null), + viewportDimension: viewportDimension ?? (hasViewportDimension ? this.viewportDimension : null), + axisDirection: axisDirection ?? this.axisDirection, + viewportFraction: viewportFraction ?? this.viewportFraction, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + ); + } +} + +class _ForceImplicitScrollPhysics extends ScrollPhysics { + const _ForceImplicitScrollPhysics({ + required this.allowImplicitScrolling, + super.parent, + }); + + @override + _ForceImplicitScrollPhysics applyTo(ScrollPhysics? ancestor) { + return _ForceImplicitScrollPhysics( + allowImplicitScrolling: allowImplicitScrolling, + parent: buildParent(ancestor), + ); + } + + @override + final bool allowImplicitScrolling; +} + +/// Scroll physics used by a [PageView]. +/// +/// These physics cause the page view to snap to page boundaries. +/// +/// See also: +/// +/// * [ScrollPhysics], the base class which defines the API for scrolling +/// physics. +/// * [PageView.physics], which can override the physics used by a page view. +class PageScrollPhysics extends ScrollPhysics { + /// Creates physics for a [PageView]. + const PageScrollPhysics({ super.parent }); + + @override + PageScrollPhysics applyTo(ScrollPhysics? ancestor) { + return PageScrollPhysics(parent: buildParent(ancestor)); + } + + double _getPage(ScrollMetrics position) { + if (position is _PagePosition) { + return position.page!; + } + return position.pixels / position.viewportDimension; + } + + double _getPixels(ScrollMetrics position, double page) { + if (position is _PagePosition) { + return position.getPixelsFromPage(page); + } + return page * position.viewportDimension; + } + + double _getTargetPixels(ScrollMetrics position, Tolerance tolerance, double velocity) { + double page = _getPage(position); + if (velocity < -tolerance.velocity) { + page -= 0.5; + } else if (velocity > tolerance.velocity) { + page += 0.5; + } + return _getPixels(position, page.roundToDouble()); + } + + @override + Simulation? createBallisticSimulation(ScrollMetrics position, double velocity) { + // If we're out of range and not headed back in range, defer to the parent + // ballistics, which should put us back in range at a page boundary. + if ((velocity <= 0.0 && position.pixels <= position.minScrollExtent) || + (velocity >= 0.0 && position.pixels >= position.maxScrollExtent)) { + return super.createBallisticSimulation(position, velocity); + } + final Tolerance tolerance = toleranceFor(position); + final double target = _getTargetPixels(position, tolerance, velocity); + if (target != position.pixels) { + return ScrollSpringSimulation(spring, position.pixels, target, velocity, tolerance: tolerance); + } + return null; + } + + @override + bool get allowImplicitScrolling => false; +} + +// Having this global (mutable) page controller is a bit of a hack. We need it +// to plumb in the factory for _PagePosition, but it will end up accumulating +// a large list of scroll positions. As long as you don't try to actually +// control the scroll positions, everything should be fine. +final PageController _defaultPageController = PageController(); +const PageScrollPhysics _kPagePhysics = PageScrollPhysics(); + +/// A scrollable list that works page by page. +/// +/// Each child of a page view is forced to be the same size as the viewport. +/// +/// You can use a [PageController] to control which page is visible in the view. +/// In addition to being able to control the pixel offset of the content inside +/// the [PageView], a [PageController] also lets you control the offset in terms +/// of pages, which are increments of the viewport size. +/// +/// The [PageController] can also be used to control the +/// [PageController.initialPage], which determines which page is shown when the +/// [PageView] is first constructed, and the [PageController.viewportFraction], +/// which determines the size of the pages as a fraction of the viewport size. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=J1gE9xvph-A} +/// +/// {@tool dartpad} +/// Here is an example of [PageView]. It creates a centered [Text] in each of the three pages +/// which scroll horizontally. +/// +/// ** See code in examples/api/lib/widgets/page_view/page_view.0.dart ** +/// {@end-tool} +/// +/// ## Persisting the scroll position during a session +/// +/// Scroll views attempt to persist their scroll position using [PageStorage]. +/// For a [PageView], this can be disabled by setting [PageController.keepPage] +/// to false on the [controller]. If it is enabled, using a [PageStorageKey] for +/// the [key] of this widget is recommended to help disambiguate different +/// scroll views from each other. +/// +/// See also: +/// +/// * [PageController], which controls which page is visible in the view. +/// * [SingleChildScrollView], when you need to make a single child scrollable. +/// * [ListView], for a scrollable list of boxes. +/// * [GridView], for a scrollable grid of boxes. +/// * [ScrollNotification] and [NotificationListener], which can be used to watch +/// the scroll position without using a [ScrollController]. +class PageView extends StatefulWidget { + /// Creates a scrollable list that works page by page from an explicit [List] + /// of widgets. + /// + /// This constructor is appropriate for page views with a small number of + /// children because constructing the [List] requires doing work for every + /// child that could possibly be displayed in the page view, instead of just + /// those children that are actually visible. + /// + /// Like other widgets in the framework, this widget expects that + /// the [children] list will not be mutated after it has been passed in here. + /// See the documentation at [SliverChildListDelegate.children] for more details. + /// + /// {@template flutter.widgets.PageView.allowImplicitScrolling} + /// If [allowImplicitScrolling] is true, the [PageView] will participate in + /// accessibility scrolling more like a [ListView], where implicit scroll + /// actions will move to the next page rather than into the contents of the + /// [PageView]. + /// {@endtemplate} + PageView({ + super.key, + this.scrollDirection = Axis.horizontal, + this.reverse = false, + PageController? controller, + this.physics, + this.pageSnapping = true, + this.onPageChanged, + List<Widget> children = const <Widget>[], + this.dragStartBehavior = DragStartBehavior.start, + this.allowImplicitScrolling = false, + this.restorationId, + this.clipBehavior = Clip.hardEdge, + this.scrollBehavior, + this.padEnds = true, + }) : controller = controller ?? _defaultPageController, + childrenDelegate = SliverChildListDelegate(children); + + /// Creates a scrollable list that works page by page using widgets that are + /// created on demand. + /// + /// This constructor is appropriate for page views with a large (or infinite) + /// number of children because the builder is called only for those children + /// that are actually visible. + /// + /// Providing a non-null [itemCount] lets the [PageView] compute the maximum + /// scroll extent. + /// + /// [itemBuilder] will be called only with indices greater than or equal to + /// zero and less than [itemCount]. + /// + /// {@macro flutter.widgets.ListView.builder.itemBuilder} + /// + /// {@template flutter.widgets.PageView.findChildIndexCallback} + /// The [findChildIndexCallback] corresponds to the + /// [SliverChildBuilderDelegate.findChildIndexCallback] property. If null, + /// a child widget may not map to its existing [RenderObject] when the order + /// of children returned from the children builder changes. + /// This may result in state-loss. This callback needs to be implemented if + /// the order of the children may change at a later time. + /// {@endtemplate} + /// + /// {@macro flutter.widgets.PageView.allowImplicitScrolling} + PageView.builder({ + super.key, + this.scrollDirection = Axis.horizontal, + this.reverse = false, + PageController? controller, + this.physics, + this.pageSnapping = true, + this.onPageChanged, + required NullableIndexedWidgetBuilder itemBuilder, + ChildIndexGetter? findChildIndexCallback, + int? itemCount, + this.dragStartBehavior = DragStartBehavior.start, + this.allowImplicitScrolling = false, + this.restorationId, + this.clipBehavior = Clip.hardEdge, + this.scrollBehavior, + this.padEnds = true, + }) : controller = controller ?? _defaultPageController, + childrenDelegate = SliverChildBuilderDelegate( + itemBuilder, + findChildIndexCallback: findChildIndexCallback, + childCount: itemCount, + ); + + /// Creates a scrollable list that works page by page with a custom child + /// model. + /// + /// {@tool dartpad} + /// This example shows a [PageView] that uses a custom [SliverChildBuilderDelegate] to support child + /// reordering. + /// + /// ** See code in examples/api/lib/widgets/page_view/page_view.1.dart ** + /// {@end-tool} + /// + /// {@macro flutter.widgets.PageView.allowImplicitScrolling} + PageView.custom({ + super.key, + this.scrollDirection = Axis.horizontal, + this.reverse = false, + PageController? controller, + this.physics, + this.pageSnapping = true, + this.onPageChanged, + required this.childrenDelegate, + this.dragStartBehavior = DragStartBehavior.start, + this.allowImplicitScrolling = false, + this.restorationId, + this.clipBehavior = Clip.hardEdge, + this.scrollBehavior, + this.padEnds = true, + }) : controller = controller ?? _defaultPageController; + + /// Controls whether the widget's pages will respond to + /// [RenderObject.showOnScreen], which will allow for implicit accessibility + /// scrolling. + /// + /// With this flag set to false, when accessibility focus reaches the end of + /// the current page and the user attempts to move it to the next element, the + /// focus will traverse to the next widget outside of the page view. + /// + /// With this flag set to true, when accessibility focus reaches the end of + /// the current page and user attempts to move it to the next element, focus + /// will traverse to the next page in the page view. + final bool allowImplicitScrolling; + + /// {@macro flutter.widgets.scrollable.restorationId} + final String? restorationId; + + /// The [Axis] along which the scroll view's offset increases with each page. + /// + /// For the direction in which active scrolling may be occurring, see + /// [ScrollDirection]. + /// + /// Defaults to [Axis.horizontal]. + final Axis scrollDirection; + + /// Whether the page view scrolls in the reading direction. + /// + /// For example, if the reading direction is left-to-right and + /// [scrollDirection] is [Axis.horizontal], then the page view scrolls from + /// left to right when [reverse] is false and from right to left when + /// [reverse] is true. + /// + /// Similarly, if [scrollDirection] is [Axis.vertical], then the page view + /// scrolls from top to bottom when [reverse] is false and from bottom to top + /// when [reverse] is true. + /// + /// Defaults to false. + final bool reverse; + + /// An object that can be used to control the position to which this page + /// view is scrolled. + final PageController controller; + + /// How the page view should respond to user input. + /// + /// For example, determines how the page view continues to animate after the + /// user stops dragging the page view. + /// + /// The physics are modified to snap to page boundaries using + /// [PageScrollPhysics] prior to being used. + /// + /// If an explicit [ScrollBehavior] is provided to [scrollBehavior], the + /// [ScrollPhysics] provided by that behavior will take precedence after + /// [physics]. + /// + /// Defaults to matching platform conventions. + final ScrollPhysics? physics; + + /// Set to false to disable page snapping, useful for custom scroll behavior. + /// + /// If the [padEnds] is false and [PageController.viewportFraction] < 1.0, + /// the page will snap to the beginning of the viewport; otherwise, the page + /// will snap to the center of the viewport. + final bool pageSnapping; + + /// Called whenever the page in the center of the viewport changes. + final ValueChanged<int>? onPageChanged; + + /// A delegate that provides the children for the [PageView]. + /// + /// The [PageView.custom] constructor lets you specify this delegate + /// explicitly. The [PageView] and [PageView.builder] constructors create a + /// [childrenDelegate] that wraps the given [List] and [IndexedWidgetBuilder], + /// respectively. + final SliverChildDelegate childrenDelegate; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// {@macro flutter.widgets.shadow.scrollBehavior} + /// + /// [ScrollBehavior]s also provide [ScrollPhysics]. If an explicit + /// [ScrollPhysics] is provided in [physics], it will take precedence, + /// followed by [scrollBehavior], and then the inherited ancestor + /// [ScrollBehavior]. + /// + /// The [ScrollBehavior] of the inherited [ScrollConfiguration] will be + /// modified by default to not apply a [Scrollbar]. + final ScrollBehavior? scrollBehavior; + + /// Whether to add padding to both ends of the list. + /// + /// If this is set to true and [PageController.viewportFraction] < 1.0, padding will be added + /// such that the first and last child slivers will be in the center of + /// the viewport when scrolled all the way to the start or end, respectively. + /// + /// If [PageController.viewportFraction] >= 1.0, this property has no effect. + /// + /// This property defaults to true. + final bool padEnds; + + @override + State<PageView> createState() => _PageViewState(); +} + +class _PageViewState extends State<PageView> { + int _lastReportedPage = 0; + + @override + void initState() { + super.initState(); + _lastReportedPage = widget.controller.initialPage; + } + + AxisDirection _getDirection(BuildContext context) { + switch (widget.scrollDirection) { + case Axis.horizontal: + assert(debugCheckHasDirectionality(context)); + final TextDirection textDirection = Directionality.of(context); + final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection); + return widget.reverse ? flipAxisDirection(axisDirection) : axisDirection; + case Axis.vertical: + return widget.reverse ? AxisDirection.up : AxisDirection.down; + } + } + + @override + Widget build(BuildContext context) { + final AxisDirection axisDirection = _getDirection(context); + final ScrollPhysics physics = _ForceImplicitScrollPhysics( + allowImplicitScrolling: widget.allowImplicitScrolling, + ).applyTo( + widget.pageSnapping + ? _kPagePhysics.applyTo(widget.physics ?? widget.scrollBehavior?.getScrollPhysics(context)) + : widget.physics ?? widget.scrollBehavior?.getScrollPhysics(context), + ); + + return NotificationListener<ScrollNotification>( + onNotification: (ScrollNotification notification) { + if (notification.depth == 0 && widget.onPageChanged != null && notification is ScrollUpdateNotification) { + final PageMetrics metrics = notification.metrics as PageMetrics; + final int currentPage = metrics.page!.round(); + if (currentPage != _lastReportedPage) { + _lastReportedPage = currentPage; + widget.onPageChanged!(currentPage); + } + } + return false; + }, + child: Scrollable( + dragStartBehavior: widget.dragStartBehavior, + axisDirection: axisDirection, + controller: widget.controller, + physics: physics, + restorationId: widget.restorationId, + scrollBehavior: widget.scrollBehavior ?? ScrollConfiguration.of(context).copyWith(scrollbars: false), + viewportBuilder: (BuildContext context, ViewportOffset position) { + return Viewport( + // TODO(dnfield): we should provide a way to set cacheExtent + // independent of implicit scrolling: + // https://github.com/flutter/flutter/issues/45632 + cacheExtent: widget.allowImplicitScrolling ? 1.0 : 0.0, + cacheExtentStyle: CacheExtentStyle.viewport, + axisDirection: axisDirection, + offset: position, + clipBehavior: widget.clipBehavior, + slivers: <Widget>[ + SliverFillViewport( + viewportFraction: widget.controller.viewportFraction, + delegate: widget.childrenDelegate, + padEnds: widget.padEnds, + ), + ], + ); + }, + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(EnumProperty<Axis>('scrollDirection', widget.scrollDirection)); + description.add(FlagProperty('reverse', value: widget.reverse, ifTrue: 'reversed')); + description.add(DiagnosticsProperty<PageController>('controller', widget.controller, showName: false)); + description.add(DiagnosticsProperty<ScrollPhysics>('physics', widget.physics, showName: false)); + description.add(FlagProperty('pageSnapping', value: widget.pageSnapping, ifFalse: 'snapping disabled')); + description.add(FlagProperty('allowImplicitScrolling', value: widget.allowImplicitScrolling, ifTrue: 'allow implicit scrolling')); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/pages.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/pages.dart new file mode 100644 index 0000000000000000000000000000000000000000..2399efba7388ddd5a3619d86fa3a8ec47366e610 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/pages.dart @@ -0,0 +1,134 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'basic.dart'; +import 'framework.dart'; +import 'routes.dart'; + +/// A modal route that replaces the entire screen. +/// +/// The [PageRouteBuilder] subclass provides a way to create a [PageRoute] using +/// callbacks rather than by defining a new class via subclassing. +/// +/// If `barrierDismissible` is true, then pressing the escape key on the keyboard +/// will cause the current route to be popped with null as the value. +/// +/// See also: +/// +/// * [Route], which documents the meaning of the `T` generic type argument. +abstract class PageRoute<T> extends ModalRoute<T> { + /// Creates a modal route that replaces the entire screen. + PageRoute({ + super.settings, + this.fullscreenDialog = false, + this.allowSnapshotting = true, + bool barrierDismissible = false, + }) : _barrierDismissible = barrierDismissible; + + /// {@template flutter.widgets.PageRoute.fullscreenDialog} + /// Whether this page route is a full-screen dialog. + /// + /// In Material and Cupertino, being fullscreen has the effects of making + /// the app bars have a close button instead of a back button. On + /// iOS, dialogs transitions animate differently and are also not closeable + /// with the back swipe gesture. + /// {@endtemplate} + final bool fullscreenDialog; + + @override + final bool allowSnapshotting; + + @override + bool get opaque => true; + + @override + bool get barrierDismissible => _barrierDismissible; + final bool _barrierDismissible; + + @override + bool canTransitionTo(TransitionRoute<dynamic> nextRoute) => nextRoute is PageRoute; + + @override + bool canTransitionFrom(TransitionRoute<dynamic> previousRoute) => previousRoute is PageRoute; +} + +Widget _defaultTransitionsBuilder(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) { + return child; +} + +/// A utility class for defining one-off page routes in terms of callbacks. +/// +/// Callers must define the [pageBuilder] function which creates the route's +/// primary contents. To add transitions define the [transitionsBuilder] function. +/// +/// The `T` generic type argument corresponds to the type argument of the +/// created [Route] objects. +/// +/// See also: +/// +/// * [Route], which documents the meaning of the `T` generic type argument. +class PageRouteBuilder<T> extends PageRoute<T> { + /// Creates a route that delegates to builder callbacks. + PageRouteBuilder({ + super.settings, + required this.pageBuilder, + this.transitionsBuilder = _defaultTransitionsBuilder, + this.transitionDuration = const Duration(milliseconds: 300), + this.reverseTransitionDuration = const Duration(milliseconds: 300), + this.opaque = true, + this.barrierDismissible = false, + this.barrierColor, + this.barrierLabel, + this.maintainState = true, + super.fullscreenDialog, + super.allowSnapshotting = true, + }); + + /// {@template flutter.widgets.pageRouteBuilder.pageBuilder} + /// Used build the route's primary contents. + /// + /// See [ModalRoute.buildPage] for complete definition of the parameters. + /// {@endtemplate} + final RoutePageBuilder pageBuilder; + + /// {@template flutter.widgets.pageRouteBuilder.transitionsBuilder} + /// Used to build the route's transitions. + /// + /// See [ModalRoute.buildTransitions] for complete definition of the parameters. + /// {@endtemplate} + /// + /// The default transition is a jump cut (i.e. no animation). + final RouteTransitionsBuilder transitionsBuilder; + + @override + final Duration transitionDuration; + + @override + final Duration reverseTransitionDuration; + + @override + final bool opaque; + + @override + final bool barrierDismissible; + + @override + final Color? barrierColor; + + @override + final String? barrierLabel; + + @override + final bool maintainState; + + @override + Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { + return pageBuilder(context, animation, secondaryAnimation); + } + + @override + Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) { + return transitionsBuilder(context, animation, secondaryAnimation, child); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/performance_overlay.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/performance_overlay.dart new file mode 100644 index 0000000000000000000000000000000000000000..8fe58a6d5f0213afc5217665ba18e52d665a0fff --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/performance_overlay.dart @@ -0,0 +1,122 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; + +/// Displays performance statistics. +/// +/// The overlay shows two time series. The first shows how much time was +/// required on this thread to produce each frame. The second shows how much +/// time was required on the raster thread (formerly known as the GPU thread) +/// to produce each frame. Ideally, both these values would be less than +/// the total frame budget for the hardware on which the app is running. +/// For example, if the hardware has a screen that updates at 60 Hz, each +/// thread should ideally spend less than 16ms producing each frame. +/// This ideal condition is indicated by a green vertical line for each thread. +/// Otherwise, the performance overlay shows a red vertical line. +/// +/// The simplest way to show the performance overlay is to set +/// [MaterialApp.showPerformanceOverlay] or [WidgetsApp.showPerformanceOverlay] +/// to true. +class PerformanceOverlay extends LeafRenderObjectWidget { + // TODO(abarth): We should have a page on the web site with a screenshot and + // an explanation of all the various readouts. + + /// Create a performance overlay that only displays specific statistics. The + /// mask is created by shifting 1 by the index of the specific + /// [PerformanceOverlayOption] to enable. + const PerformanceOverlay({ + super.key, + this.optionsMask = 0, + this.rasterizerThreshold = 0, + this.checkerboardRasterCacheImages = false, + this.checkerboardOffscreenLayers = false, + }); + + /// Create a performance overlay that displays all available statistics. + PerformanceOverlay.allEnabled({ + super.key, + this.rasterizerThreshold = 0, + this.checkerboardRasterCacheImages = false, + this.checkerboardOffscreenLayers = false, + }) : optionsMask = + 1 << PerformanceOverlayOption.displayRasterizerStatistics.index | + 1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index | + 1 << PerformanceOverlayOption.displayEngineStatistics.index | + 1 << PerformanceOverlayOption.visualizeEngineStatistics.index; + + /// The mask is created by shifting 1 by the index of the specific + /// [PerformanceOverlayOption] to enable. + final int optionsMask; + + /// The rasterizer threshold is an integer specifying the number of frame + /// intervals that the rasterizer must miss before it decides that the frame + /// is suitable for capturing an SkPicture trace for further analysis. + /// + /// For example, if you want a trace of all pictures that could not be + /// rendered by the rasterizer within the frame boundary (and hence caused + /// jank), specify 1. Specifying 2 will trace all pictures that took more + /// than 2 frame intervals to render. Adjust this value to only capture + /// the particularly expensive pictures while skipping the others. Specifying + /// 0 disables all capture. + /// + /// Captured traces are placed on your device in the application documents + /// directory in this form "trace_<collection_time>.skp". These can + /// be viewed in the Skia debugger. + /// + /// Notes: + /// The rasterizer only takes into account the time it took to render + /// the already constructed picture. This include the Skia calls (which is + /// also why an SkPicture trace is generated) but not any of the time spent in + /// dart to construct that picture. To profile that part of your code, use + /// the instrumentation available in observatory. + /// + /// To decide what threshold interval to use, count the number of horizontal + /// lines displayed in the performance overlay for the rasterizer (not the + /// engine). That should give an idea of how often frames are skipped (and by + /// how many frame intervals). + final int rasterizerThreshold; + + /// Whether the raster cache should checkerboard cached entries. + /// + /// The compositor can sometimes decide to cache certain portions of the + /// widget hierarchy. Such portions typically don't change often from frame to + /// frame and are expensive to render. This can speed up overall rendering. However, + /// there is certain upfront cost to constructing these cache entries. And, if + /// the cache entries are not used very often, this cost may not be worth the + /// speedup in rendering of subsequent frames. If the developer wants to be certain + /// that populating the raster cache is not causing stutters, this option can be + /// set. Depending on the observations made, hints can be provided to the compositor + /// that aid it in making better decisions about caching. + final bool checkerboardRasterCacheImages; + + /// Whether the compositor should checkerboard layers that are rendered to offscreen + /// bitmaps. This can be useful for debugging rendering performance. + /// + /// Render target switches are caused by using opacity layers (via a [FadeTransition] or + /// [Opacity] widget), clips, shader mask layers, etc. Selecting a new render target + /// and merging it with the rest of the scene has a performance cost. This can sometimes + /// be avoided by using equivalent widgets that do not require these layers (for example, + /// replacing an [Opacity] widget with an [widgets.Image] using a [BlendMode]). + final bool checkerboardOffscreenLayers; + + @override + RenderPerformanceOverlay createRenderObject(BuildContext context) => RenderPerformanceOverlay( + optionsMask: optionsMask, + rasterizerThreshold: rasterizerThreshold, + checkerboardRasterCacheImages: checkerboardRasterCacheImages, + checkerboardOffscreenLayers: checkerboardOffscreenLayers, + ); + + @override + void updateRenderObject(BuildContext context, RenderPerformanceOverlay renderObject) { + renderObject + ..optionsMask = optionsMask + ..rasterizerThreshold = rasterizerThreshold + ..checkerboardRasterCacheImages = checkerboardRasterCacheImages + ..checkerboardOffscreenLayers = checkerboardOffscreenLayers; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/pinned_header_sliver.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/pinned_header_sliver.dart new file mode 100644 index 0000000000000000000000000000000000000000..61f337eee813c48d3054285427a0c88363c1728a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/pinned_header_sliver.dart @@ -0,0 +1,83 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; + +/// A sliver that keeps its Widget child at the top of the a [CustomScrollView]. +/// +/// This sliver is preferable to the general purpose [SliverPersistentHeader] +/// for its relatively narrow use case because there's no need to create a +/// [SliverPersistentHeaderDelegate] or to predict the header's size. +/// +/// {@tool dartpad} +/// This example demonstrates that the sliver's size can change. Pressing the +/// floating action button replaces the one line of header text with two lines. +/// +/// ** See code in examples/api/lib/widgets/sliver/pinned_header_sliver.0.dart ** +/// {@end-tool} +/// +/// +/// See also: +/// +/// * [SliverResizingHeader] - which similarly pins the header at the top +/// of the [CustomScrollView] but reacts to scrolling by resizing the header +/// between its minimum and maximum extent limits. +/// * [SliverPersistentHeader] - a general purpose header that can be +/// configured as a pinned, resizing, or floating header. +class PinnedHeaderSliver extends SingleChildRenderObjectWidget { + /// Creates a sliver whose [Widget] child appears at the top of a + /// [CustomScrollView]. + const PinnedHeaderSliver({ + super.key, + super.child, + }); + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderPinnedHeaderSliver(); + } +} + +class _RenderPinnedHeaderSliver extends RenderSliverSingleBoxAdapter { + _RenderPinnedHeaderSliver(); + + double get childExtent { + if (child == null) { + return 0.0; + } + assert(child!.hasSize); + return switch (constraints.axis) { + Axis.vertical => child!.size.height, + Axis.horizontal => child!.size.width, + }; + } + + @override + double childMainAxisPosition(covariant RenderObject child) => 0; + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + child?.layout(constraints.asBoxConstraints(), parentUsesSize: true); + + final double layoutExtent = clampDouble(childExtent - constraints.scrollOffset, 0, constraints.remainingPaintExtent); + final double paintExtent = math.min(childExtent, constraints.remainingPaintExtent - constraints.overlap); + geometry = SliverGeometry( + scrollExtent: childExtent, + paintOrigin: constraints.overlap, + paintExtent: paintExtent, + layoutExtent: layoutExtent, + maxPaintExtent: childExtent, + maxScrollObstructionExtent: childExtent, + cacheExtent: calculateCacheOffset(constraints, from: 0.0, to: childExtent), + hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity. + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/placeholder.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/placeholder.dart new file mode 100644 index 0000000000000000000000000000000000000000..9be0303421f379a78878f59e8c7609dd45d672ce --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/placeholder.dart @@ -0,0 +1,116 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'basic.dart'; +import 'framework.dart'; + +class _PlaceholderPainter extends CustomPainter { + const _PlaceholderPainter({ + required this.color, + required this.strokeWidth, + }); + + final Color color; + final double strokeWidth; + + @override + void paint(Canvas canvas, Size size) { + final Paint paint = Paint() + ..color = color + ..style = PaintingStyle.stroke + ..strokeWidth = strokeWidth; + final Rect rect = Offset.zero & size; + final Path path = Path() + ..addRect(rect) + ..addPolygon(<Offset>[rect.topRight, rect.bottomLeft], false) + ..addPolygon(<Offset>[rect.topLeft, rect.bottomRight], false); + canvas.drawPath(path, paint); + } + + @override + bool shouldRepaint(_PlaceholderPainter oldPainter) { + return oldPainter.color != color + || oldPainter.strokeWidth != strokeWidth; + } + + @override + bool hitTest(Offset position) => false; +} + +/// A widget that draws a box that represents where other widgets will one day +/// be added. +/// +/// This widget is useful during development to indicate that the interface is +/// not yet complete. +/// +/// By default, the placeholder is sized to fit its container. If the +/// placeholder is in an unbounded space, it will size itself according to the +/// given [fallbackWidth] and [fallbackHeight]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=LPe56fezmoo} +class Placeholder extends StatelessWidget { + /// Creates a widget which draws a box. + const Placeholder({ + super.key, + this.color = const Color(0xFF455A64), // Blue Grey 700 + this.strokeWidth = 2.0, + this.fallbackWidth = 400.0, + this.fallbackHeight = 400.0, + this.child + }); + + /// The color to draw the placeholder box. + final Color color; + + /// The width of the lines in the placeholder box. + final double strokeWidth; + + /// The width to use when the placeholder is in a situation with an unbounded + /// width. + /// + /// See also: + /// + /// * [fallbackHeight], the same but vertically. + final double fallbackWidth; + + /// The height to use when the placeholder is in a situation with an unbounded + /// height. + /// + /// See also: + /// + /// * [fallbackWidth], the same but horizontally. + final double fallbackHeight; + + /// The [child] contained by the placeholder box. + /// + /// Defaults to null. + final Widget? child; + @override + Widget build(BuildContext context) { + return LimitedBox( + maxWidth: fallbackWidth, + maxHeight: fallbackHeight, + child: CustomPaint( + size: Size.infinite, + painter: _PlaceholderPainter( + color: color, + strokeWidth: strokeWidth, + ), + child: child, + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(ColorProperty('color', color, defaultValue: const Color(0xFF455A64))); + properties.add(DoubleProperty('strokeWidth', strokeWidth, defaultValue: 2.0)); + properties.add(DoubleProperty('fallbackWidth', fallbackWidth, defaultValue: 400.0)); + properties.add(DoubleProperty('fallbackHeight', fallbackHeight, defaultValue: 400.0)); + properties.add(DiagnosticsProperty<Widget>('child', child, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/platform_menu_bar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/platform_menu_bar.dart new file mode 100644 index 0000000000000000000000000000000000000000..687894d37805c3c5c7fa26260d6fa96eaa7bfc4c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/platform_menu_bar.dart @@ -0,0 +1,1034 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'actions.dart'; +import 'basic.dart'; +import 'binding.dart'; +import 'focus_manager.dart'; +import 'framework.dart'; +import 'shortcuts.dart'; + +// "flutter/menu" Method channel methods. +const String _kMenuSetMethod = 'Menu.setMenus'; +const String _kMenuSelectedCallbackMethod = 'Menu.selectedCallback'; +const String _kMenuItemOpenedMethod = 'Menu.opened'; +const String _kMenuItemClosedMethod = 'Menu.closed'; + +// Keys for channel communication map. +const String _kIdKey = 'id'; +const String _kLabelKey = 'label'; +const String _kEnabledKey = 'enabled'; +const String _kChildrenKey = 'children'; +const String _kIsDividerKey = 'isDivider'; +const String _kPlatformDefaultMenuKey = 'platformProvidedMenu'; +const String _kShortcutCharacter = 'shortcutCharacter'; +const String _kShortcutTrigger = 'shortcutTrigger'; +const String _kShortcutModifiers = 'shortcutModifiers'; + +/// A class used by [MenuSerializableShortcut] to describe the shortcut for +/// serialization to send to the platform for rendering a [PlatformMenuBar]. +/// +/// See also: +/// +/// * [PlatformMenuBar], a widget that defines a menu bar for the platform to +/// render natively. +/// * [MenuSerializableShortcut], a mixin allowing a [ShortcutActivator] to +/// provide data for serialization of the shortcut for sending to the +/// platform. +class ShortcutSerialization { + /// Creates a [ShortcutSerialization] representing a single character. + /// + /// This is used by a [CharacterActivator] to serialize itself. + ShortcutSerialization.character(String character, { + bool alt = false, + bool control = false, + bool meta = false, + }) : assert(character.length == 1), + _character = character, + _trigger = null, + _alt = alt, + _control = control, + _meta = meta, + _shift = null, + _internal = <String, Object?>{ + _kShortcutCharacter: character, + _kShortcutModifiers: (control ? _shortcutModifierControl : 0) | + (alt ? _shortcutModifierAlt : 0) | + (meta ? _shortcutModifierMeta : 0), + }; + + /// Creates a [ShortcutSerialization] representing a specific + /// [LogicalKeyboardKey] and modifiers. + /// + /// This is used by a [SingleActivator] to serialize itself. + ShortcutSerialization.modifier( + LogicalKeyboardKey trigger, { + bool alt = false, + bool control = false, + bool meta = false, + bool shift = false, + }) : assert(trigger != LogicalKeyboardKey.alt && + trigger != LogicalKeyboardKey.altLeft && + trigger != LogicalKeyboardKey.altRight && + trigger != LogicalKeyboardKey.control && + trigger != LogicalKeyboardKey.controlLeft && + trigger != LogicalKeyboardKey.controlRight && + trigger != LogicalKeyboardKey.meta && + trigger != LogicalKeyboardKey.metaLeft && + trigger != LogicalKeyboardKey.metaRight && + trigger != LogicalKeyboardKey.shift && + trigger != LogicalKeyboardKey.shiftLeft && + trigger != LogicalKeyboardKey.shiftRight, + 'Specifying a modifier key as a trigger is not allowed. ' + 'Use provided boolean parameters instead.'), + _trigger = trigger, + _character = null, + _alt = alt, + _control = control, + _meta = meta, + _shift = shift, + _internal = <String, Object?>{ + _kShortcutTrigger: trigger.keyId, + _kShortcutModifiers: (alt ? _shortcutModifierAlt : 0) | + (control ? _shortcutModifierControl : 0) | + (meta ? _shortcutModifierMeta : 0) | + (shift ? _shortcutModifierShift : 0), + }; + + final Map<String, Object?> _internal; + + /// The keyboard key that triggers this shortcut, if any. + LogicalKeyboardKey? get trigger => _trigger; + final LogicalKeyboardKey? _trigger; + + /// The character that triggers this shortcut, if any. + String? get character => _character; + final String? _character; + + /// If this shortcut has a [trigger], this indicates whether or not the + /// alt modifier needs to be down or not. + bool? get alt => _alt; + final bool? _alt; + + /// If this shortcut has a [trigger], this indicates whether or not the + /// control modifier needs to be down or not. + bool? get control => _control; + final bool? _control; + + /// If this shortcut has a [trigger], this indicates whether or not the meta + /// (also known as the Windows or Command key) modifier needs to be down or + /// not. + bool? get meta => _meta; + final bool? _meta; + + /// If this shortcut has a [trigger], this indicates whether or not the + /// shift modifier needs to be down or not. + bool? get shift => _shift; + final bool? _shift; + + /// The bit mask for the [LogicalKeyboardKey.alt] key (or it's left/right + /// equivalents) being down. + static const int _shortcutModifierAlt = 1 << 2; + + /// The bit mask for the [LogicalKeyboardKey.control] key (or it's left/right + /// equivalents) being down. + static const int _shortcutModifierControl = 1 << 3; + + /// The bit mask for the [LogicalKeyboardKey.meta] key (or it's left/right + /// equivalents) being down. + static const int _shortcutModifierMeta = 1 << 0; + + /// The bit mask for the [LogicalKeyboardKey.shift] key (or it's left/right + /// equivalents) being down. + static const int _shortcutModifierShift = 1 << 1; + + /// Converts the internal representation to the format needed for a + /// [PlatformMenuItem] to include it in its serialized form for sending to the + /// platform. + Map<String, Object?> toChannelRepresentation() => _internal; +} + +/// A mixin allowing a [ShortcutActivator] to provide data for serialization of +/// the shortcut when sending to the platform. +/// +/// This is meant for those who have written their own [ShortcutActivator] +/// subclass, and would like to have it work for menus in a [PlatformMenuBar] as +/// well. +/// +/// Keep in mind that there are limits to the capabilities of the platform APIs, +/// and not all kinds of [ShortcutActivator]s will work with them. +/// +/// See also: +/// +/// * [SingleActivator], a [ShortcutActivator] which implements this mixin. +/// * [CharacterActivator], another [ShortcutActivator] which implements this mixin. +mixin MenuSerializableShortcut implements ShortcutActivator { + /// Implement this in a [ShortcutActivator] subclass to allow it to be + /// serialized for use in a [PlatformMenuBar]. + ShortcutSerialization serializeForMenu(); +} + +/// An abstract delegate class that can be used to set +/// [WidgetsBinding.platformMenuDelegate] to provide for managing platform +/// menus. +/// +/// This can be subclassed to provide a different menu plugin than the default +/// system-provided plugin for managing [PlatformMenuBar] menus. +/// +/// The [setMenus] method allows for setting of the menu hierarchy when the +/// [PlatformMenuBar] menu hierarchy changes. +/// +/// This delegate doesn't handle the results of clicking on a menu item, which +/// is left to the implementor of subclasses of [PlatformMenuDelegate] to +/// handle for their implementation. +/// +/// This delegate typically knows how to serialize a [PlatformMenu] +/// hierarchy, send it over a channel, and register for calls from the channel +/// when a menu is invoked or a submenu is opened or closed. +/// +/// See [DefaultPlatformMenuDelegate] for an example of implementing one of +/// these. +/// +/// See also: +/// +/// * [PlatformMenuBar], the widget that adds a platform menu bar to an +/// application, and uses [setMenus] to send the menus to the platform. +/// * [PlatformMenu], the class that describes a menu item with children +/// that appear in a cascading menu. +/// * [PlatformMenuItem], the class that describes the leaves of a menu +/// hierarchy. +abstract class PlatformMenuDelegate { + /// A const constructor so that subclasses can have const constructors. + const PlatformMenuDelegate(); + + /// Sets the entire menu hierarchy for a platform-rendered menu bar. + /// + /// The `topLevelMenus` argument is the list of menus that appear in the menu + /// bar, which themselves can have children. + /// + /// To update the menu hierarchy or menu item state, call [setMenus] with the + /// modified hierarchy, and it will overwrite the previous menu state. + /// + /// See also: + /// + /// * [PlatformMenuBar], the widget that adds a platform menu bar to an + /// application. + /// * [PlatformMenu], the class that describes a menu item with children + /// that appear in a cascading menu. + /// * [PlatformMenuItem], the class that describes the leaves of a menu + /// hierarchy. + void setMenus(List<PlatformMenuItem> topLevelMenus); + + /// Clears any existing platform-rendered menus and leaves the application + /// with no menus. + /// + /// It is not necessary to call this before updating the menu with [setMenus]. + void clearMenus(); + + /// This is called by [PlatformMenuBar] when it is initialized, to be sure that + /// only one is active at a time. + /// + /// The [debugLockDelegate] function should be called before the first call to + /// [setMenus]. + /// + /// If the lock is successfully acquired, [debugLockDelegate] will return + /// true. + /// + /// If your implementation of a [PlatformMenuDelegate] can have only limited + /// active instances, enforce it when you override this function. + /// + /// See also: + /// + /// * [debugUnlockDelegate], where the delegate is unlocked. + bool debugLockDelegate(BuildContext context); + + /// This is called by [PlatformMenuBar] when it is disposed, so that another + /// one can take over. + /// + /// If the [debugUnlockDelegate] successfully unlocks the delegate, it will + /// return true. + /// + /// See also: + /// + /// * [debugLockDelegate], where the delegate is locked. + bool debugUnlockDelegate(BuildContext context); +} + +/// The signature for a function that generates unique menu item IDs for +/// serialization of a [PlatformMenuItem]. +typedef MenuItemSerializableIdGenerator = int Function(PlatformMenuItem item); + +/// The platform menu delegate that handles the built-in macOS platform menu +/// generation using the 'flutter/menu' channel. +/// +/// An instance of this class is set on [WidgetsBinding.platformMenuDelegate] by +/// default when the [WidgetsBinding] is initialized. +/// +/// See also: +/// +/// * [PlatformMenuBar], the widget that adds a platform menu bar to an +/// application. +/// * [PlatformMenu], the class that describes a menu item with children +/// that appear in a cascading menu. +/// * [PlatformMenuItem], the class that describes the leaves of a menu +/// hierarchy. +class DefaultPlatformMenuDelegate extends PlatformMenuDelegate { + /// Creates a const [DefaultPlatformMenuDelegate]. + /// + /// The optional [channel] argument defines the channel used to communicate + /// with the platform. It defaults to [SystemChannels.menu] if not supplied. + DefaultPlatformMenuDelegate({MethodChannel? channel}) + : channel = channel ?? SystemChannels.menu, + _idMap = <int, PlatformMenuItem>{} { + this.channel.setMethodCallHandler(_methodCallHandler); + } + + // Map of distributed IDs to menu items. + final Map<int, PlatformMenuItem> _idMap; + // An ever increasing value used to dole out IDs. + int _serial = 0; + // The context used to "lock" this delegate to a specific instance of + // PlatformMenuBar to make sure there is only one. + BuildContext? _lockedContext; + + @override + void clearMenus() => setMenus(<PlatformMenuItem>[]); + + @override + void setMenus(List<PlatformMenuItem> topLevelMenus) { + _idMap.clear(); + final List<Map<String, Object?>> representation = <Map<String, Object?>>[]; + if (topLevelMenus.isNotEmpty) { + for (final PlatformMenuItem childItem in topLevelMenus) { + representation.addAll(childItem.toChannelRepresentation(this, getId: _getId)); + } + } + // Currently there's only ever one window, but the channel's format allows + // more than one window's menu hierarchy to be defined. + final Map<String, Object?> windowMenu = <String, Object?>{ + '0': representation, + }; + channel.invokeMethod<void>(_kMenuSetMethod, windowMenu); + } + + /// Defines the channel that the [DefaultPlatformMenuDelegate] uses to + /// communicate with the platform. + /// + /// Defaults to [SystemChannels.menu]. + final MethodChannel channel; + + /// Get the next serialization ID. + /// + /// This is called by each DefaultPlatformMenuDelegateSerializer when + /// serializing a new object so that it has a unique ID. + int _getId(PlatformMenuItem item) { + _serial += 1; + _idMap[_serial] = item; + return _serial; + } + + @override + bool debugLockDelegate(BuildContext context) { + assert(() { + // It's OK to lock if the lock isn't set, but not OK if a different + // context is locking it. + if (_lockedContext != null && _lockedContext != context) { + return false; + } + _lockedContext = context; + return true; + }()); + return true; + } + + @override + bool debugUnlockDelegate(BuildContext context) { + assert(() { + // It's OK to unlock if the lock isn't set, but not OK if a different + // context is unlocking it. + if (_lockedContext != null && _lockedContext != context) { + return false; + } + _lockedContext = null; + return true; + }()); + return true; + } + + // Handles the method calls from the plugin to forward to selection and + // open/close callbacks. + Future<void> _methodCallHandler(MethodCall call) async { + final int id = call.arguments as int; + assert( + _idMap.containsKey(id), + 'Received a menu ${call.method} for a menu item with an ID that was not recognized: $id', + ); + if (!_idMap.containsKey(id)) { + return; + } + final PlatformMenuItem item = _idMap[id]!; + if (call.method == _kMenuSelectedCallbackMethod) { + assert(item.onSelected == null || item.onSelectedIntent == null, + 'Only one of PlatformMenuItem.onSelected or PlatformMenuItem.onSelectedIntent may be specified'); + item.onSelected?.call(); + if (item.onSelectedIntent != null) { + Actions.maybeInvoke(FocusManager.instance.primaryFocus!.context!, item.onSelectedIntent!); + } + } else if (call.method == _kMenuItemOpenedMethod) { + item.onOpen?.call(); + } else if (call.method == _kMenuItemClosedMethod) { + item.onClose?.call(); + } + } +} + +/// A menu bar that uses the platform's native APIs to construct and render a +/// menu described by a [PlatformMenu]/[PlatformMenuItem] hierarchy. +/// +/// This widget is especially useful on macOS, where a system menu is a required +/// part of every application. Flutter only includes support for macOS out of +/// the box, but support for other platforms may be provided via plugins that +/// set [WidgetsBinding.platformMenuDelegate] in their initialization. +/// +/// The [menus] member contains [PlatformMenuItem]s, which configure the +/// properties of the menus on the platform menu bar. +/// +/// As far as Flutter is concerned, this widget has no visual representation, +/// and intercepts no events: it just returns the [child] from its build +/// function. This is because all of the rendering, shortcuts, and event +/// handling for the menu is handled by the plugin on the host platform. It is +/// only part of the widget tree to provide a convenient refresh mechanism for +/// the menu data. +/// +/// There can only be one [PlatformMenuBar] at a time using the same +/// [PlatformMenuDelegate]. It will assert if more than one is detected. +/// +/// When calling [toStringDeep] on this widget, it will give a tree of +/// [PlatformMenuItem]s, not a tree of widgets. +/// +/// {@tool sample} This example shows a [PlatformMenuBar] that contains a single +/// top level menu, containing three items for "About", a toggleable menu item +/// for showing a message, a cascading submenu with message choices, and "Quit". +/// +/// **This example will only work on macOS.** +/// +/// ** See code in examples/api/lib/material/platform_menu_bar/platform_menu_bar.0.dart ** +/// {@end-tool} +/// +/// The menus could just as effectively be managed without using the widget tree +/// by using the following code, but mixing this usage with [PlatformMenuBar] is +/// not recommended, since it will overwrite the menu configuration when it is +/// rebuilt: +/// +/// ```dart +/// List<PlatformMenuItem> menus = <PlatformMenuItem>[ /* Define menus... */ ]; +/// WidgetsBinding.instance.platformMenuDelegate.setMenus(menus); +/// ``` +class PlatformMenuBar extends StatefulWidget with DiagnosticableTreeMixin { + /// Creates a const [PlatformMenuBar]. + /// + /// The [child] and [menus] attributes are required. + const PlatformMenuBar({ + super.key, + required this.menus, + this.child, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// The list of menu items that are the top level children of the + /// [PlatformMenuBar]. + /// + /// The [menus] member contains [PlatformMenuItem]s. They will not be part of + /// the widget tree, since they are not widgets. They are provided to + /// configure the properties of the menus on the platform menu bar. + /// + /// Also, a Widget in Flutter is immutable, so directly modifying the + /// [menus] with `List` APIs such as + /// `somePlatformMenuBarWidget.menus.add(...)` will result in incorrect + /// behaviors. Whenever the menus list is modified, a new list object + /// should be provided. + final List<PlatformMenuItem> menus; + + @override + State<PlatformMenuBar> createState() => _PlatformMenuBarState(); + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return menus.map<DiagnosticsNode>((PlatformMenuItem child) => child.toDiagnosticsNode()).toList(); + } +} + +class _PlatformMenuBarState extends State<PlatformMenuBar> { + List<PlatformMenuItem> descendants = <PlatformMenuItem>[]; + + @override + void initState() { + super.initState(); + assert( + WidgetsBinding.instance.platformMenuDelegate.debugLockDelegate(context), + 'More than one active $PlatformMenuBar detected. Only one active ' + 'platform-rendered menu bar is allowed at a time.'); + WidgetsBinding.instance.platformMenuDelegate.clearMenus(); + _updateMenu(); + } + + @override + void dispose() { + assert(WidgetsBinding.instance.platformMenuDelegate.debugUnlockDelegate(context), + 'tried to unlock the $DefaultPlatformMenuDelegate more than once with context $context.'); + WidgetsBinding.instance.platformMenuDelegate.clearMenus(); + super.dispose(); + } + + @override + void didUpdateWidget(PlatformMenuBar oldWidget) { + super.didUpdateWidget(oldWidget); + final List<PlatformMenuItem> newDescendants = <PlatformMenuItem>[ + for (final PlatformMenuItem item in widget.menus) ...<PlatformMenuItem>[ + item, + ...item.descendants, + ], + ]; + if (!listEquals(newDescendants, descendants)) { + descendants = newDescendants; + _updateMenu(); + } + } + + // Updates the data structures for the menu and send them to the platform + // plugin. + void _updateMenu() { + WidgetsBinding.instance.platformMenuDelegate.setMenus(widget.menus); + } + + @override + Widget build(BuildContext context) { + // PlatformMenuBar is really about managing the platform menu bar, and + // doesn't do any rendering or event handling in Flutter. + return widget.child ?? const SizedBox(); + } +} + +/// A class for representing menu items that have child submenus. +/// +/// See also: +/// +/// * [PlatformMenuItem], a class representing a leaf menu item in a +/// [PlatformMenuBar]. +class PlatformMenu extends PlatformMenuItem with DiagnosticableTreeMixin { + /// Creates a const [PlatformMenu]. + /// + /// The [label] and [menus] fields are required. + const PlatformMenu({ + required super.label, + this.onOpen, + this.onClose, + required this.menus, + }); + + @override + final VoidCallback? onOpen; + + @override + final VoidCallback? onClose; + + /// The menu items in the submenu opened by this menu item. + /// + /// If this is an empty list, this [PlatformMenu] will be disabled. + final List<PlatformMenuItem> menus; + + /// Returns all descendant [PlatformMenuItem]s of this item. + @override + List<PlatformMenuItem> get descendants => getDescendants(this); + + /// Returns all descendants of the given item. + /// + /// This API is supplied so that implementers of [PlatformMenu] can share + /// this implementation. + static List<PlatformMenuItem> getDescendants(PlatformMenu item) { + return <PlatformMenuItem>[ + for (final PlatformMenuItem child in item.menus) ...<PlatformMenuItem>[ + child, + ...child.descendants, + ], + ]; + } + + @override + Iterable<Map<String, Object?>> toChannelRepresentation( + PlatformMenuDelegate delegate, { + required MenuItemSerializableIdGenerator getId, + }) { + return <Map<String, Object?>>[serialize(this, delegate, getId)]; + } + + /// Converts the supplied object to the correct channel representation for the + /// 'flutter/menu' channel. + /// + /// This API is supplied so that implementers of [PlatformMenu] can share + /// this implementation. + static Map<String, Object?> serialize( + PlatformMenu item, + PlatformMenuDelegate delegate, + MenuItemSerializableIdGenerator getId, + ) { + final List<Map<String, Object?>> result = <Map<String, Object?>>[]; + for (final PlatformMenuItem childItem in item.menus) { + result.addAll(childItem.toChannelRepresentation( + delegate, + getId: getId, + )); + } + // To avoid doing type checking for groups, just filter out when there are + // multiple sequential dividers, or when they are first or last, since + // groups may be interleaved with non-groups, and non-groups may also add + // dividers. + Map<String, Object?>? previousItem; + result.removeWhere((Map<String, Object?> item) { + if (previousItem == null && item[_kIsDividerKey] == true) { + // Strip any leading dividers. + return true; + } + if (previousItem != null && previousItem![_kIsDividerKey] == true && item[_kIsDividerKey] == true) { + // Strip any duplicate dividers. + return true; + } + previousItem = item; + return false; + }); + if (result.isNotEmpty && result.last[_kIsDividerKey] == true) { + result.removeLast(); + } + return <String, Object?>{ + _kIdKey: getId(item), + _kLabelKey: item.label, + _kEnabledKey: item.menus.isNotEmpty, + _kChildrenKey: result, + }; + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + return menus.map<DiagnosticsNode>((PlatformMenuItem child) => child.toDiagnosticsNode()).toList(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('label', label)); + properties.add(FlagProperty('enabled', value: menus.isNotEmpty, ifFalse: 'DISABLED')); + } +} + +/// A class that groups other menu items into sections delineated by dividers. +/// +/// Visual dividers will be added before and after this group if other menu +/// items appear in the [PlatformMenu], and the leading one omitted if it is +/// first and the trailing one omitted if it is last in the menu. +class PlatformMenuItemGroup extends PlatformMenuItem { + /// Creates a const [PlatformMenuItemGroup]. + /// + /// The [members] field is required. + const PlatformMenuItemGroup({required this.members}) : super(label: ''); + + /// The [PlatformMenuItem]s that are members of this menu item group. + /// + /// An assertion will be thrown if there isn't at least one member of the group. + @override + final List<PlatformMenuItem> members; + + @override + Iterable<Map<String, Object?>> toChannelRepresentation( + PlatformMenuDelegate delegate, { + required MenuItemSerializableIdGenerator getId, + }) { + assert(members.isNotEmpty, 'There must be at least one member in a PlatformMenuItemGroup'); + return serialize(this, delegate, getId: getId); + } + + /// Converts the supplied object to the correct channel representation for the + /// 'flutter/menu' channel. + /// + /// This API is supplied so that implementers of [PlatformMenuItemGroup] can share + /// this implementation. + static Iterable<Map<String, Object?>> serialize( + PlatformMenuItem group, + PlatformMenuDelegate delegate, { + required MenuItemSerializableIdGenerator getId, + }) { + final List<Map<String, Object?>> result = <Map<String, Object?>>[]; + result.add(<String, Object?>{ + _kIdKey: getId(group), + _kIsDividerKey: true, + }); + for (final PlatformMenuItem item in group.members) { + result.addAll(item.toChannelRepresentation( + delegate, + getId: getId, + )); + } + result.add(<String, Object?>{ + _kIdKey: getId(group), + _kIsDividerKey: true, + }); + return result; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IterableProperty<PlatformMenuItem>('members', members)); + } +} + +/// A class for [PlatformMenuItem]s that do not have submenus (as a [PlatformMenu] +/// would), but can be selected. +/// +/// These [PlatformMenuItem]s are the leaves of the menu item tree, and [onSelected] +/// will be called when they are selected by clicking on them, or via an +/// optional keyboard [shortcut]. +/// +/// See also: +/// +/// * [PlatformMenu], a menu item that opens a submenu. +class PlatformMenuItem with Diagnosticable { + /// Creates a const [PlatformMenuItem]. + /// + /// The [label] attribute is required. + const PlatformMenuItem({ + required this.label, + this.shortcut, + this.onSelected, + this.onSelectedIntent, + }) : assert(onSelected == null || onSelectedIntent == null, 'Only one of onSelected or onSelectedIntent may be specified'); + + /// The required label used for rendering the menu item. + final String label; + + /// The optional shortcut that selects this [PlatformMenuItem]. + /// + /// This shortcut is only enabled when [onSelected] is set. + final MenuSerializableShortcut? shortcut; + + /// An optional callback that is called when this [PlatformMenuItem] is + /// selected. + /// + /// At most one of [onSelected] and [onSelectedIntent] may be set. If neither + /// field is set, this menu item will be disabled. + final VoidCallback? onSelected; + + /// Returns a callback, if any, to be invoked if the platform menu receives a + /// "Menu.opened" method call from the platform for this item. + /// + /// Only items that have submenus will have this callback invoked. + /// + /// The default implementation returns null. + VoidCallback? get onOpen => null; + + /// Returns a callback, if any, to be invoked if the platform menu receives a + /// "Menu.closed" method call from the platform for this item. + /// + /// Only items that have submenus will have this callback invoked. + /// + /// The default implementation returns null. + VoidCallback? get onClose => null; + + /// An optional intent that is invoked when this [PlatformMenuItem] is + /// selected. + /// + /// At most one of [onSelected] and [onSelectedIntent] may be set. If neither + /// field is set, this menu item will be disabled. + final Intent? onSelectedIntent; + + /// Returns all descendant [PlatformMenuItem]s of this item. + /// + /// Returns an empty list if this type of menu item doesn't have + /// descendants. + List<PlatformMenuItem> get descendants => const <PlatformMenuItem>[]; + + /// Returns the list of group members if this menu item is a "grouping" menu + /// item, such as [PlatformMenuItemGroup]. + /// + /// Defaults to an empty list. + List<PlatformMenuItem> get members => const <PlatformMenuItem>[]; + + /// Converts the representation of this item into a map suitable for sending + /// over the default "flutter/menu" channel used by [DefaultPlatformMenuDelegate]. + /// + /// The `delegate` is the [PlatformMenuDelegate] that is requesting the + /// serialization. + /// + /// The `getId` parameter is a [MenuItemSerializableIdGenerator] function that + /// generates a unique ID for each menu item, which is to be returned in the + /// "id" field of the menu item data. + Iterable<Map<String, Object?>> toChannelRepresentation( + PlatformMenuDelegate delegate, { + required MenuItemSerializableIdGenerator getId, + }) { + return <Map<String, Object?>>[PlatformMenuItem.serialize(this, delegate, getId)]; + } + + /// Converts the given [PlatformMenuItem] into a data structure accepted by + /// the 'flutter/menu' method channel method 'Menu.SetMenu'. + /// + /// This API is supplied so that implementers of [PlatformMenuItem] can share + /// this implementation. + static Map<String, Object?> serialize( + PlatformMenuItem item, + PlatformMenuDelegate delegate, + MenuItemSerializableIdGenerator getId, + ) { + final MenuSerializableShortcut? shortcut = item.shortcut; + return <String, Object?>{ + _kIdKey: getId(item), + _kLabelKey: item.label, + _kEnabledKey: item.onSelected != null || item.onSelectedIntent != null, + if (shortcut != null)...shortcut.serializeForMenu().toChannelRepresentation(), + }; + } + + @override + String toStringShort() => '${describeIdentity(this)}($label)'; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('label', label)); + properties.add(DiagnosticsProperty<MenuSerializableShortcut?>('shortcut', shortcut, defaultValue: null)); + properties.add(FlagProperty('enabled', value: onSelected != null, ifFalse: 'DISABLED')); + } +} + +/// A class that represents a menu item that is provided by the platform. +/// +/// This is used to add things like the "About" and "Quit" menu items to a +/// platform menu. +/// +/// The [type] enum determines which type of platform defined menu will be +/// added. +/// +/// This is most useful on a macOS platform where there are many different types +/// of platform provided menu items in the standard menu setup. +/// +/// In order to know if a [PlatformProvidedMenuItem] is available on a +/// particular platform, call [PlatformProvidedMenuItem.hasMenu]. +/// +/// If the platform does not support the given [type], then the menu item will +/// throw an [ArgumentError] when it is sent to the platform. +/// +/// See also: +/// +/// * [PlatformMenuBar] which takes these items for inclusion in a +/// platform-rendered menu bar. +class PlatformProvidedMenuItem extends PlatformMenuItem { + /// Creates a const [PlatformProvidedMenuItem] of the appropriate type. Throws if the + /// platform doesn't support the given default menu type. + /// + /// The [type] argument is required. + const PlatformProvidedMenuItem({ + required this.type, + this.enabled = true, + }) : super(label: ''); // The label is ignored for platform provided menus. + + /// The type of default menu this is. + /// + /// See [PlatformProvidedMenuItemType] for the different types available. Not + /// all of the types will be available on every platform. Use [hasMenu] to + /// determine if the current platform has a given default menu item. + /// + /// If the platform does not support the given [type], then the menu item will + /// throw an [ArgumentError] in debug mode. + final PlatformProvidedMenuItemType type; + + /// True if this [PlatformProvidedMenuItem] should be enabled or not. + final bool enabled; + + /// Checks to see if the given default menu type is supported on this + /// platform. + static bool hasMenu(PlatformProvidedMenuItemType menu) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return false; + case TargetPlatform.macOS: + return const <PlatformProvidedMenuItemType>{ + PlatformProvidedMenuItemType.about, + PlatformProvidedMenuItemType.quit, + PlatformProvidedMenuItemType.servicesSubmenu, + PlatformProvidedMenuItemType.hide, + PlatformProvidedMenuItemType.hideOtherApplications, + PlatformProvidedMenuItemType.showAllApplications, + PlatformProvidedMenuItemType.startSpeaking, + PlatformProvidedMenuItemType.stopSpeaking, + PlatformProvidedMenuItemType.toggleFullScreen, + PlatformProvidedMenuItemType.minimizeWindow, + PlatformProvidedMenuItemType.zoomWindow, + PlatformProvidedMenuItemType.arrangeWindowsInFront, + }.contains(menu); + } + } + + @override + Iterable<Map<String, Object?>> toChannelRepresentation( + PlatformMenuDelegate delegate, { + required MenuItemSerializableIdGenerator getId, + }) { + assert(() { + if (!hasMenu(type)) { + throw ArgumentError( + 'Platform ${defaultTargetPlatform.name} has no platform provided menu for ' + '$type. Call PlatformProvidedMenuItem.hasMenu to determine this before ' + 'instantiating one.', + ); + } + return true; + }()); + + return <Map<String, Object?>>[ + <String, Object?>{ + _kIdKey: getId(this), + _kEnabledKey: enabled, + _kPlatformDefaultMenuKey: type.index, + }, + ]; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('enabled', value: enabled, ifFalse: 'DISABLED')); + } +} + +/// The list of possible platform provided, prebuilt menus for use in a +/// [PlatformMenuBar]. +/// +/// These are menus that the platform typically provides that cannot be +/// reproduced in Flutter without calling platform functions, but are standard +/// on the platform. +/// +/// Examples include things like the "Quit" or "Services" menu items on macOS. +/// Not all platforms support all menu item types. Use +/// [PlatformProvidedMenuItem.hasMenu] to know if a particular type is supported +/// on a the current platform. +/// +/// Add these to your [PlatformMenuBar] using the [PlatformProvidedMenuItem] +/// class. +/// +/// You can tell if the platform provides the given menu using the +/// [PlatformProvidedMenuItem.hasMenu] method. +// Must be kept in sync with the plugin code's enum of the same name. +enum PlatformProvidedMenuItemType { + /// The system provided "About" menu item. + /// + /// On macOS, this is the `orderFrontStandardAboutPanel` default menu. + about, + + /// The system provided "Quit" menu item. + /// + /// On macOS, this is the `terminate` default menu. + /// + /// This menu item will exit the application when activated. + quit, + + /// The system provided "Services" submenu. + /// + /// This submenu provides a list of system provided application services. + /// + /// This default menu is only supported on macOS. + servicesSubmenu, + + /// The system provided "Hide" menu item. + /// + /// This menu item hides the application window. + /// + /// On macOS, this is the `hide` default menu. + /// + /// This default menu is only supported on macOS. + hide, + + /// The system provided "Hide Others" menu item. + /// + /// This menu item hides other application windows. + /// + /// On macOS, this is the `hideOtherApplications` default menu. + /// + /// This default menu is only supported on macOS. + hideOtherApplications, + + /// The system provided "Show All" menu item. + /// + /// This menu item shows all hidden application windows. + /// + /// On macOS, this is the `unhideAllApplications` default menu. + /// + /// This default menu is only supported on macOS. + showAllApplications, + + /// The system provided "Start Dictation..." menu item. + /// + /// This menu item tells the system to start the screen reader. + /// + /// On macOS, this is the `startSpeaking` default menu. + /// + /// This default menu is currently only supported on macOS. + startSpeaking, + + /// The system provided "Stop Dictation..." menu item. + /// + /// This menu item tells the system to stop the screen reader. + /// + /// On macOS, this is the `stopSpeaking` default menu. + /// + /// This default menu is currently only supported on macOS. + stopSpeaking, + + /// The system provided "Enter Full Screen" menu item. + /// + /// This menu item tells the system to toggle full screen mode for the window. + /// + /// On macOS, this is the `toggleFullScreen` default menu. + /// + /// This default menu is currently only supported on macOS. + toggleFullScreen, + + /// The system provided "Minimize" menu item. + /// + /// This menu item tells the system to minimize the window. + /// + /// On macOS, this is the `performMiniaturize` default menu. + /// + /// This default menu is currently only supported on macOS. + minimizeWindow, + + /// The system provided "Zoom" menu item. + /// + /// This menu item tells the system to expand the window size. + /// + /// On macOS, this is the `performZoom` default menu. + /// + /// This default menu is currently only supported on macOS. + zoomWindow, + + /// The system provided "Bring To Front" menu item. + /// + /// This menu item tells the system to stack the window above other windows. + /// + /// On macOS, this is the `arrangeInFront` default menu. + /// + /// This default menu is currently only supported on macOS. + arrangeWindowsInFront, +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/platform_selectable_region_context_menu.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/platform_selectable_region_context_menu.dart new file mode 100644 index 0000000000000000000000000000000000000000..2bd7e7cca847f12bbf8b3e772f45a33da6d6a335 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/platform_selectable_region_context_menu.dart @@ -0,0 +1,6 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export '_platform_selectable_region_context_menu_io.dart' +if (dart.library.js_util) '_platform_selectable_region_context_menu_web.dart'; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/platform_view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/platform_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..2ae217ebc9d3650b667e622d79729025bb6183ca --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/platform_view.dart @@ -0,0 +1,1314 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import '_html_element_view_io.dart' if (dart.library.js_util) '_html_element_view_web.dart'; +import 'basic.dart'; +import 'debug.dart'; +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; + +// Examples can assume: +// PlatformViewController createFooWebView(PlatformViewCreationParams params) { return (null as dynamic) as PlatformViewController; } +// Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers = <Factory<OneSequenceGestureRecognizer>>{}; +// late PlatformViewController _controller; + +/// Embeds an Android view in the Widget hierarchy. +/// +/// Requires Android API level 23 or greater. +/// +/// Embedding Android views is an expensive operation and should be avoided when a Flutter +/// equivalent is possible. +/// +/// The embedded Android view is painted just like any other Flutter widget and transformations +/// apply to it as well. +/// +/// {@template flutter.widgets.AndroidView.layout} +/// The widget fills all available space, the parent of this object must provide bounded layout +/// constraints. +/// {@endtemplate} +/// +/// {@template flutter.widgets.AndroidView.gestures} +/// The widget participates in Flutter's gesture arenas, and dispatches touch events to the +/// platform view iff it won the arena. Specific gestures that should be dispatched to the platform +/// view can be specified in the `gestureRecognizers` constructor parameter. If +/// the set of gesture recognizers is empty, a gesture will be dispatched to the platform +/// view iff it was not claimed by any other gesture recognizer. +/// {@endtemplate} +/// +/// The Android view object is created using a [PlatformViewFactory](/javadoc/io/flutter/plugin/platform/PlatformViewFactory.html). +/// Plugins can register platform view factories with [PlatformViewRegistry#registerViewFactory](/javadoc/io/flutter/plugin/platform/PlatformViewRegistry.html#registerViewFactory-java.lang.String-io.flutter.plugin.platform.PlatformViewFactory-). +/// +/// Registration is typically done in the plugin's registerWith method, e.g: +/// +/// ```java +/// public static void registerWith(Registrar registrar) { +/// registrar.platformViewRegistry().registerViewFactory("webview", WebViewFactory(registrar.messenger())); +/// } +/// ``` +/// +/// {@template flutter.widgets.AndroidView.lifetime} +/// The platform view's lifetime is the same as the lifetime of the [State] object for this widget. +/// When the [State] is disposed the platform view (and auxiliary resources) are lazily +/// released (some resources are immediately released and some by platform garbage collector). +/// A stateful widget's state is disposed when the widget is removed from the tree or when it is +/// moved within the tree. If the stateful widget has a key and it's only moved relative to its siblings, +/// or it has a [GlobalKey] and it's moved within the tree, it will not be disposed. +/// {@endtemplate} +class AndroidView extends StatefulWidget { + /// Creates a widget that embeds an Android view. + /// + /// {@template flutter.widgets.AndroidView.constructorArgs} + /// If `creationParams` is not null then `creationParamsCodec` must not be null. + /// {@endtemplate} + const AndroidView({ + super.key, + required this.viewType, + this.onPlatformViewCreated, + this.hitTestBehavior = PlatformViewHitTestBehavior.opaque, + this.layoutDirection, + this.gestureRecognizers, + this.creationParams, + this.creationParamsCodec, + this.clipBehavior = Clip.hardEdge, + }) : assert(creationParams == null || creationParamsCodec != null); + + /// The unique identifier for Android view type to be embedded by this widget. + /// + /// A [PlatformViewFactory](/javadoc/io/flutter/plugin/platform/PlatformViewFactory.html) + /// for this type must have been registered. + /// + /// See also: + /// + /// * [AndroidView] for an example of registering a platform view factory. + final String viewType; + + /// {@template flutter.widgets.AndroidView.onPlatformViewCreated} + /// Callback to invoke after the platform view has been created. + /// + /// May be null. + /// {@endtemplate} + final PlatformViewCreatedCallback? onPlatformViewCreated; + + /// {@template flutter.widgets.AndroidView.hitTestBehavior} + /// How this widget should behave during hit testing. + /// + /// This defaults to [PlatformViewHitTestBehavior.opaque]. + /// {@endtemplate} + final PlatformViewHitTestBehavior hitTestBehavior; + + /// {@template flutter.widgets.AndroidView.layoutDirection} + /// The text direction to use for the embedded view. + /// + /// If this is null, the ambient [Directionality] is used instead. + /// {@endtemplate} + final TextDirection? layoutDirection; + + /// Which gestures should be forwarded to the Android view. + /// + /// {@template flutter.widgets.AndroidView.gestureRecognizers.descHead} + /// The gesture recognizers built by factories in this set participate in the gesture arena for + /// each pointer that was put down on the widget. If any of these recognizers win the + /// gesture arena, the entire pointer event sequence starting from the pointer down event + /// will be dispatched to the platform view. + /// + /// When null, an empty set of gesture recognizer factories is used, in which case a pointer event sequence + /// will only be dispatched to the platform view if no other member of the arena claimed it. + /// {@endtemplate} + /// + /// For example, with the following setup vertical drags will not be dispatched to the Android + /// view as the vertical drag gesture is claimed by the parent [GestureDetector]. + /// + /// ```dart + /// GestureDetector( + /// onVerticalDragStart: (DragStartDetails d) {}, + /// child: const AndroidView( + /// viewType: 'webview', + /// ), + /// ) + /// ``` + /// + /// To get the [AndroidView] to claim the vertical drag gestures we can pass a vertical drag + /// gesture recognizer factory in [gestureRecognizers] e.g: + /// + /// ```dart + /// GestureDetector( + /// onVerticalDragStart: (DragStartDetails details) {}, + /// child: SizedBox( + /// width: 200.0, + /// height: 100.0, + /// child: AndroidView( + /// viewType: 'webview', + /// gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{ + /// Factory<OneSequenceGestureRecognizer>( + /// () => EagerGestureRecognizer(), + /// ), + /// }, + /// ), + /// ), + /// ) + /// ``` + /// + /// {@template flutter.widgets.AndroidView.gestureRecognizers.descFoot} + /// A platform view can be configured to consume all pointers that were put + /// down in its bounds by passing a factory for an [EagerGestureRecognizer] in + /// [gestureRecognizers]. [EagerGestureRecognizer] is a special gesture + /// recognizer that immediately claims the gesture after a pointer down event. + /// + /// The [gestureRecognizers] property must not contain more than one factory + /// with the same [Factory.type]. + /// + /// Changing [gestureRecognizers] results in rejection of any active gesture + /// arenas (if the platform view is actively participating in an arena). + /// {@endtemplate} + // We use OneSequenceGestureRecognizers as they support gesture arena teams. + // TODO(amirh): get a list of GestureRecognizers here. + // https://github.com/flutter/flutter/issues/20953 + final Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers; + + /// Passed as the args argument of [PlatformViewFactory#create](/javadoc/io/flutter/plugin/platform/PlatformViewFactory.html#create-android.content.Context-int-java.lang.Object-) + /// + /// This can be used by plugins to pass constructor parameters to the embedded Android view. + final dynamic creationParams; + + /// The codec used to encode `creationParams` before sending it to the + /// platform side. It should match the codec passed to the constructor of [PlatformViewFactory](/javadoc/io/flutter/plugin/platform/PlatformViewFactory.html#PlatformViewFactory-io.flutter.plugin.common.MessageCodec-). + /// + /// This is typically one of: [StandardMessageCodec], [JSONMessageCodec], [StringCodec], or [BinaryCodec]. + /// + /// This must not be null if [creationParams] is not null. + final MessageCodec<dynamic>? creationParamsCodec; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + @override + State<AndroidView> createState() => _AndroidViewState(); +} + +/// Common superclass for iOS and macOS platform views. +/// +/// Platform views are used to embed native views in the widget hierarchy, with +/// support for transforms, clips, and opacity similar to any other Flutter widget. +abstract class _DarwinView extends StatefulWidget { + /// Creates a widget that embeds a platform view. + /// + /// {@macro flutter.widgets.AndroidView.constructorArgs} + const _DarwinView({ + super.key, + required this.viewType, + this.onPlatformViewCreated, + this.hitTestBehavior = PlatformViewHitTestBehavior.opaque, + this.layoutDirection, + this.creationParams, + this.creationParamsCodec, + this.gestureRecognizers, + }) : assert(creationParams == null || creationParamsCodec != null); + + // TODO(amirh): reference the iOS API doc once available. + /// The unique identifier for iOS view type to be embedded by this widget. + /// + /// A PlatformViewFactory for this type must have been registered. + final String viewType; + + /// {@macro flutter.widgets.AndroidView.onPlatformViewCreated} + final PlatformViewCreatedCallback? onPlatformViewCreated; + + /// {@macro flutter.widgets.AndroidView.hitTestBehavior} + final PlatformViewHitTestBehavior hitTestBehavior; + + /// {@macro flutter.widgets.AndroidView.layoutDirection} + final TextDirection? layoutDirection; + + /// Passed as the `arguments` argument of [-\[FlutterPlatformViewFactory createWithFrame:viewIdentifier:arguments:\]](/ios-embedder/protocol_flutter_platform_view_factory-p.html#a4e3c4390cd6ebd982390635e9bca4edc) + /// + /// This can be used by plugins to pass constructor parameters to the embedded iOS view. + final dynamic creationParams; + + /// The codec used to encode `creationParams` before sending it to the + /// platform side. It should match the codec returned by [-\[FlutterPlatformViewFactory createArgsCodec:\]](/ios-embedder/protocol_flutter_platform_view_factory-p.html#a32c3c067cb45a83dfa720c74a0d5c93c) + /// + /// This is typically one of: [StandardMessageCodec], [JSONMessageCodec], [StringCodec], or [BinaryCodec]. + /// + /// This must not be null if [creationParams] is not null. + final MessageCodec<dynamic>? creationParamsCodec; + + /// Which gestures should be forwarded to the UIKit view. + /// + /// {@macro flutter.widgets.AndroidView.gestureRecognizers.descHead} + /// + /// For example, with the following setup vertical drags will not be dispatched to the UIKit + /// view as the vertical drag gesture is claimed by the parent [GestureDetector]. + /// + /// ```dart + /// GestureDetector( + /// onVerticalDragStart: (DragStartDetails details) {}, + /// child: const UiKitView( + /// viewType: 'webview', + /// ), + /// ) + /// ``` + /// + /// To get the [UiKitView] to claim the vertical drag gestures we can pass a vertical drag + /// gesture recognizer factory in [gestureRecognizers] e.g: + /// + /// ```dart + /// GestureDetector( + /// onVerticalDragStart: (DragStartDetails details) {}, + /// child: SizedBox( + /// width: 200.0, + /// height: 100.0, + /// child: UiKitView( + /// viewType: 'webview', + /// gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{ + /// Factory<OneSequenceGestureRecognizer>( + /// () => EagerGestureRecognizer(), + /// ), + /// }, + /// ), + /// ), + /// ) + /// ``` + /// + /// {@macro flutter.widgets.AndroidView.gestureRecognizers.descFoot} + // We use OneSequenceGestureRecognizers as they support gesture arena teams. + // TODO(amirh): get a list of GestureRecognizers here. + // https://github.com/flutter/flutter/issues/20953 + final Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers; +} + +// TODO(amirh): describe the embedding mechanism. +// TODO(ychris): remove the documentation for conic path not supported once https://github.com/flutter/flutter/issues/35062 is resolved. +/// Embeds an iOS view in the Widget hierarchy. +/// +/// Embedding iOS views is an expensive operation and should be avoided when a Flutter +/// equivalent is possible. +/// +/// {@macro flutter.widgets.AndroidView.layout} +/// +/// {@macro flutter.widgets.AndroidView.gestures} +/// +/// {@macro flutter.widgets.AndroidView.lifetime} +/// +/// Construction of UIViews is done asynchronously, before the UIView is ready this widget paints +/// nothing while maintaining the same layout constraints. +/// +/// Clipping operations on a UiKitView can result slow performance. +/// If a conic path clipping is applied to a UIKitView, +/// a quad path is used to approximate the clip due to limitation of Quartz. +class UiKitView extends _DarwinView { + /// Creates a widget that embeds an iOS view. + /// + /// {@macro flutter.widgets.AndroidView.constructorArgs} + const UiKitView({ + super.key, + required super.viewType, + super.onPlatformViewCreated, + super.hitTestBehavior = PlatformViewHitTestBehavior.opaque, + super.layoutDirection, + super.creationParams, + super.creationParamsCodec, + super.gestureRecognizers, + }) : assert(creationParams == null || creationParamsCodec != null); + + @override + State<UiKitView> createState() => _UiKitViewState(); +} + +/// Widget that contains a macOS AppKit view. +/// +/// Embedding macOS views is an expensive operation and should be avoided where +/// a Flutter equivalent is possible. +/// +/// The platform view's lifetime is the same as the lifetime of the [State] +/// object for this widget. When the [State] is disposed the platform view (and +/// auxiliary resources) are lazily released (some resources are immediately +/// released and some by platform garbage collector). A stateful widget's state +/// is disposed when the widget is removed from the tree or when it is moved +/// within the tree. If the stateful widget has a key and it's only moved +/// relative to its siblings, or it has a [GlobalKey] and it's moved within the +/// tree, it will not be disposed. +/// +/// Construction of AppKitViews is done asynchronously, before the underlying +/// NSView is ready this widget paints nothing while maintaining the same +/// layout constraints. +class AppKitView extends _DarwinView { + /// Creates a widget that embeds a macOS AppKit NSView. + const AppKitView({ + super.key, + required super.viewType, + super.onPlatformViewCreated, + super.hitTestBehavior = PlatformViewHitTestBehavior.opaque, + super.layoutDirection, + super.creationParams, + super.creationParamsCodec, + super.gestureRecognizers, + }); + + @override + State<AppKitView> createState() => _AppKitViewState(); +} + +/// Callback signature for when the platform view's DOM element was created. +/// +/// [element] is the DOM element that was created. +/// +/// Also see [HtmlElementView.fromTagName] that uses this callback +/// signature. +typedef ElementCreatedCallback = void Function(Object element); + +/// Embeds an HTML element in the Widget hierarchy in Flutter Web. +/// +/// *NOTE*: This only works in Flutter Web. To embed web content on other +/// platforms, consider using the `flutter_webview` plugin. +/// +/// Embedding HTML is an expensive operation and should be avoided when a +/// Flutter equivalent is possible. +/// +/// The embedded HTML is painted just like any other Flutter widget and +/// transformations apply to it as well. This widget should only be used in +/// Flutter Web. +/// +/// {@macro flutter.widgets.AndroidView.layout} +/// +/// Due to security restrictions with cross-origin `<iframe>` elements, Flutter +/// cannot dispatch pointer events to an HTML view. If an `<iframe>` is the +/// target of an event, the window containing the `<iframe>` is not notified +/// of the event. In particular, this means that any pointer events which land +/// on an `<iframe>` will not be seen by Flutter, and so the HTML view cannot +/// participate in gesture detection with other widgets. +/// +/// The way we enable accessibility on Flutter for web is to have a full-page +/// button which waits for a double tap. Placing this full-page button in front +/// of the scene would cause platform views not to receive pointer events. The +/// tradeoff is that by placing the scene in front of the semantics placeholder +/// will cause platform views to block pointer events from reaching the +/// placeholder. This means that in order to enable accessibility, you must +/// double tap the app *outside of a platform view*. As a consequence, a +/// full-screen platform view will make it impossible to enable accessibility. +/// Make sure that your HTML views are sized no larger than necessary, or you +/// may cause difficulty for users trying to enable accessibility. +/// +/// {@macro flutter.widgets.AndroidView.lifetime} +class HtmlElementView extends StatelessWidget { + /// Creates a platform view for Flutter Web. + /// + /// `viewType` identifies the type of platform view to create. + const HtmlElementView({ + super.key, + required this.viewType, + this.onPlatformViewCreated, + this.creationParams, + }); + + /// Creates a platform view that creates a DOM element specified by [tagName]. + /// + /// [isVisible] indicates whether the view is visible to the user or not. + /// Setting this to false allows the rendering pipeline to perform extra + /// optimizations knowing that the view will not result in any pixels painted + /// on the screen. + /// + /// [onElementCreated] is called when the DOM element is created. It can be + /// used by the app to customize the element by adding attributes and styles. + factory HtmlElementView.fromTagName({ + Key? key, + required String tagName, + bool isVisible = true, + ElementCreatedCallback? onElementCreated, + }) => + HtmlElementViewImpl.createFromTagName( + key: key, + tagName: tagName, + isVisible: isVisible, + onElementCreated: onElementCreated, + ); + + /// The unique identifier for the HTML view type to be embedded by this widget. + /// + /// A PlatformViewFactory for this type must have been registered. + final String viewType; + + /// Callback to invoke after the platform view has been created. + /// + /// May be null. + final PlatformViewCreatedCallback? onPlatformViewCreated; + + /// Passed as the 2nd argument (i.e. `params`) of the registered view factory. + final Object? creationParams; + + @override + Widget build(BuildContext context) => buildImpl(context); +} + +class _AndroidViewState extends State<AndroidView> { + int? _id; + late AndroidViewController _controller; + TextDirection? _layoutDirection; + bool _initialized = false; + FocusNode? _focusNode; + + static final Set<Factory<OneSequenceGestureRecognizer>> _emptyRecognizersSet = + <Factory<OneSequenceGestureRecognizer>>{}; + + @override + Widget build(BuildContext context) { + return Focus( + focusNode: _focusNode, + onFocusChange: _onFocusChange, + child: _AndroidPlatformView( + controller: _controller, + hitTestBehavior: widget.hitTestBehavior, + gestureRecognizers: widget.gestureRecognizers ?? _emptyRecognizersSet, + clipBehavior: widget.clipBehavior, + ), + ); + } + + void _initializeOnce() { + if (_initialized) { + return; + } + _initialized = true; + _createNewAndroidView(); + _focusNode = FocusNode(debugLabel: 'AndroidView(id: $_id)'); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final TextDirection newLayoutDirection = _findLayoutDirection(); + final bool didChangeLayoutDirection = _layoutDirection != newLayoutDirection; + _layoutDirection = newLayoutDirection; + + _initializeOnce(); + if (didChangeLayoutDirection) { + // The native view will update asynchronously, in the meantime we don't want + // to block the framework. (so this is intentionally not awaiting). + _controller.setLayoutDirection(_layoutDirection!); + } + } + + @override + void didUpdateWidget(AndroidView oldWidget) { + super.didUpdateWidget(oldWidget); + + final TextDirection newLayoutDirection = _findLayoutDirection(); + final bool didChangeLayoutDirection = _layoutDirection != newLayoutDirection; + _layoutDirection = newLayoutDirection; + + if (widget.viewType != oldWidget.viewType) { + _controller.disposePostFrame(); + _createNewAndroidView(); + return; + } + + if (didChangeLayoutDirection) { + _controller.setLayoutDirection(_layoutDirection!); + } + } + + TextDirection _findLayoutDirection() { + assert(widget.layoutDirection != null || debugCheckHasDirectionality(context)); + return widget.layoutDirection ?? Directionality.of(context); + } + + @override + void dispose() { + _controller.dispose(); + _focusNode?.dispose(); + _focusNode = null; + super.dispose(); + } + + void _createNewAndroidView() { + _id = platformViewsRegistry.getNextPlatformViewId(); + _controller = PlatformViewsService.initAndroidView( + id: _id!, + viewType: widget.viewType, + layoutDirection: _layoutDirection!, + creationParams: widget.creationParams, + creationParamsCodec: widget.creationParamsCodec, + onFocus: () { + _focusNode!.requestFocus(); + }, + ); + if (widget.onPlatformViewCreated != null) { + _controller.addOnPlatformViewCreatedListener(widget.onPlatformViewCreated!); + } + } + + void _onFocusChange(bool isFocused) { + if (!_controller.isCreated) { + return; + } + if (!isFocused) { + _controller.clearFocus().catchError((dynamic e) { + if (e is MissingPluginException) { + // We land the framework part of Android platform views keyboard + // support before the engine part. There will be a commit range where + // clearFocus isn't implemented in the engine. When that happens we + // just swallow the error here. Once the engine part is rolled to the + // framework I'll remove this. + // TODO(amirh): remove this once the engine's clearFocus is rolled. + return; + } + }); + return; + } + SystemChannels.textInput.invokeMethod<void>( + 'TextInput.setPlatformViewClient', + <String, dynamic>{'platformViewId': _id}, + ).catchError((dynamic e) { + if (e is MissingPluginException) { + // We land the framework part of Android platform views keyboard + // support before the engine part. There will be a commit range where + // setPlatformViewClient isn't implemented in the engine. When that + // happens we just swallow the error here. Once the engine part is + // rolled to the framework I'll remove this. + // TODO(amirh): remove this once the engine's clearFocus is rolled. + return; + } + }); + } +} + +abstract class _DarwinViewState<PlatformViewT extends _DarwinView, ControllerT extends DarwinPlatformViewController, RenderT extends RenderDarwinPlatformView<ControllerT>, ViewT extends _DarwinPlatformView<ControllerT, RenderT>> extends State<PlatformViewT> { + ControllerT? _controller; + TextDirection? _layoutDirection; + bool _initialized = false; + + @visibleForTesting + FocusNode? focusNode; + + static final Set<Factory<OneSequenceGestureRecognizer>> _emptyRecognizersSet = + <Factory<OneSequenceGestureRecognizer>>{}; + + @override + Widget build(BuildContext context) { + final ControllerT? controller = _controller; + if (controller == null) { + return const SizedBox.expand(); + } + return Focus( + focusNode: focusNode, + onFocusChange: (bool isFocused) => _onFocusChange(isFocused, controller), + child: childPlatformView() + ); + } + + ViewT childPlatformView(); + + void _initializeOnce() { + if (_initialized) { + return; + } + _initialized = true; + _createNewUiKitView(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final TextDirection newLayoutDirection = _findLayoutDirection(); + final bool didChangeLayoutDirection = _layoutDirection != newLayoutDirection; + _layoutDirection = newLayoutDirection; + + _initializeOnce(); + if (didChangeLayoutDirection) { + // The native view will update asynchronously, in the meantime we don't want + // to block the framework. (so this is intentionally not awaiting). + _controller?.setLayoutDirection(_layoutDirection!); + } + } + + @override + void didUpdateWidget(PlatformViewT oldWidget) { + super.didUpdateWidget(oldWidget); + + final TextDirection newLayoutDirection = _findLayoutDirection(); + final bool didChangeLayoutDirection = _layoutDirection != newLayoutDirection; + _layoutDirection = newLayoutDirection; + + if (widget.viewType != oldWidget.viewType) { + _controller?.dispose(); + _controller = null; + focusNode?.dispose(); + focusNode = null; + _createNewUiKitView(); + return; + } + + if (didChangeLayoutDirection) { + _controller?.setLayoutDirection(_layoutDirection!); + } + } + + TextDirection _findLayoutDirection() { + assert(widget.layoutDirection != null || debugCheckHasDirectionality(context)); + return widget.layoutDirection ?? Directionality.of(context); + } + + @override + void dispose() { + _controller?.dispose(); + _controller = null; + focusNode?.dispose(); + focusNode = null; + super.dispose(); + } + + Future<void> _createNewUiKitView() async { + final int id = platformViewsRegistry.getNextPlatformViewId(); + final ControllerT controller = await createNewViewController( + id + ); + if (!mounted) { + controller.dispose(); + return; + } + widget.onPlatformViewCreated?.call(id); + setState(() { + _controller = controller; + focusNode = FocusNode(debugLabel: 'UiKitView(id: $id)'); + }); + } + + Future<ControllerT> createNewViewController(int id); + + void _onFocusChange(bool isFocused, ControllerT controller) { + if (!isFocused) { + // Unlike Android, we do not need to send "clearFocus" channel message + // to the engine, because focusing on another view will automatically + // cancel the focus on the previously focused platform view. + return; + } + SystemChannels.textInput.invokeMethod<void>( + 'TextInput.setPlatformViewClient', + <String, dynamic>{'platformViewId': controller.id}, + ); + } +} + +class _UiKitViewState extends _DarwinViewState<UiKitView, UiKitViewController, RenderUiKitView, _UiKitPlatformView> { + @override + Future<UiKitViewController> createNewViewController(int id) async { + return PlatformViewsService.initUiKitView( + id: id, + viewType: widget.viewType, + layoutDirection: _layoutDirection!, + creationParams: widget.creationParams, + creationParamsCodec: widget.creationParamsCodec, + onFocus: () { + focusNode?.requestFocus(); + } + ); + } + + @override + _UiKitPlatformView childPlatformView() { + return _UiKitPlatformView( + controller: _controller!, + hitTestBehavior: widget.hitTestBehavior, + gestureRecognizers: widget.gestureRecognizers ?? _DarwinViewState._emptyRecognizersSet, + ); + } +} + +class _AppKitViewState extends _DarwinViewState<AppKitView, AppKitViewController, RenderAppKitView, _AppKitPlatformView> { + @override + Future<AppKitViewController> createNewViewController(int id) async { + return PlatformViewsService.initAppKitView( + id: id, + viewType: widget.viewType, + layoutDirection: _layoutDirection!, + creationParams: widget.creationParams, + creationParamsCodec: widget.creationParamsCodec, + onFocus: () { + focusNode?.requestFocus(); + } + ); + } + + @override + _AppKitPlatformView childPlatformView() { + return _AppKitPlatformView( + controller: _controller!, + hitTestBehavior: widget.hitTestBehavior, + gestureRecognizers: widget.gestureRecognizers ?? _DarwinViewState._emptyRecognizersSet, + ); + } +} + +class _AndroidPlatformView extends LeafRenderObjectWidget { + const _AndroidPlatformView({ + required this.controller, + required this.hitTestBehavior, + required this.gestureRecognizers, + this.clipBehavior = Clip.hardEdge, + }); + + final AndroidViewController controller; + final PlatformViewHitTestBehavior hitTestBehavior; + final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers; + final Clip clipBehavior; + + @override + RenderObject createRenderObject(BuildContext context) => + RenderAndroidView( + viewController: controller, + hitTestBehavior: hitTestBehavior, + gestureRecognizers: gestureRecognizers, + clipBehavior: clipBehavior, + ); + + @override + void updateRenderObject(BuildContext context, RenderAndroidView renderObject) { + renderObject.controller = controller; + renderObject.hitTestBehavior = hitTestBehavior; + renderObject.updateGestureRecognizers(gestureRecognizers); + renderObject.clipBehavior = clipBehavior; + } +} + +abstract class _DarwinPlatformView<TController extends DarwinPlatformViewController, TRender extends RenderDarwinPlatformView<TController>> extends LeafRenderObjectWidget { + const _DarwinPlatformView({ + required this.controller, + required this.hitTestBehavior, + required this.gestureRecognizers, + }); + + final TController controller; + final PlatformViewHitTestBehavior hitTestBehavior; + final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers; + + @override + @mustCallSuper + void updateRenderObject(BuildContext context, TRender renderObject) { + renderObject + ..viewController = controller + ..hitTestBehavior = hitTestBehavior + ..updateGestureRecognizers(gestureRecognizers); + } +} + +class _UiKitPlatformView extends _DarwinPlatformView<UiKitViewController, RenderUiKitView> { + const _UiKitPlatformView({required super.controller, required super.hitTestBehavior, required super.gestureRecognizers}); + + @override + RenderObject createRenderObject(BuildContext context) { + return RenderUiKitView( + viewController: controller, + hitTestBehavior: hitTestBehavior, + gestureRecognizers: gestureRecognizers, + ); + } +} + +class _AppKitPlatformView extends _DarwinPlatformView<AppKitViewController, RenderAppKitView> { + const _AppKitPlatformView({required super.controller, required super.hitTestBehavior, required super.gestureRecognizers}); + + @override + RenderObject createRenderObject(BuildContext context) { + return RenderAppKitView( + viewController: controller, + hitTestBehavior: hitTestBehavior, + gestureRecognizers: gestureRecognizers, + ); + } +} + +/// The parameters used to create a [PlatformViewController]. +/// +/// See also: +/// +/// * [CreatePlatformViewCallback] which uses this object to create a [PlatformViewController]. +class PlatformViewCreationParams { + + const PlatformViewCreationParams._({ + required this.id, + required this.viewType, + required this.onPlatformViewCreated, + required this.onFocusChanged, + }); + + /// The unique identifier for the new platform view. + /// + /// [PlatformViewController.viewId] should match this id. + final int id; + + /// The unique identifier for the type of platform view to be embedded. + /// + /// This viewType is used to tell the platform which type of view to + /// associate with the [id]. + final String viewType; + + /// Callback invoked after the platform view has been created. + final PlatformViewCreatedCallback onPlatformViewCreated; + + /// Callback invoked when the platform view's focus is changed on the platform side. + /// + /// The value is true when the platform view gains focus and false when it loses focus. + final ValueChanged<bool> onFocusChanged; +} + +/// A factory for a surface presenting a platform view as part of the widget hierarchy. +/// +/// The returned widget should present the platform view associated with `controller`. +/// +/// See also: +/// +/// * [PlatformViewSurface], a common widget for presenting platform views. +typedef PlatformViewSurfaceFactory = Widget Function(BuildContext context, PlatformViewController controller); + +/// Constructs a [PlatformViewController]. +/// +/// The [PlatformViewController.viewId] field of the created controller must match the value of the +/// params [PlatformViewCreationParams.id] field. +/// +/// See also: +/// +/// * [PlatformViewLink], which links a platform view with the Flutter framework. +typedef CreatePlatformViewCallback = PlatformViewController Function(PlatformViewCreationParams params); + +/// Links a platform view with the Flutter framework. +/// +/// Provides common functionality for embedding a platform view (e.g an android.view.View on Android) +/// with the Flutter framework. +/// +/// {@macro flutter.widgets.AndroidView.lifetime} +/// +/// To implement a new platform view widget, return this widget in the `build` method. +/// For example: +/// +/// ```dart +/// class FooPlatformView extends StatelessWidget { +/// const FooPlatformView({super.key}); +/// @override +/// Widget build(BuildContext context) { +/// return PlatformViewLink( +/// viewType: 'webview', +/// onCreatePlatformView: createFooWebView, +/// surfaceFactory: (BuildContext context, PlatformViewController controller) { +/// return PlatformViewSurface( +/// gestureRecognizers: gestureRecognizers, +/// controller: controller, +/// hitTestBehavior: PlatformViewHitTestBehavior.opaque, +/// ); +/// }, +/// ); +/// } +/// } +/// ``` +/// +/// The `surfaceFactory` and the `onCreatePlatformView` are only called when the +/// state of this widget is initialized, or when the `viewType` changes. +class PlatformViewLink extends StatefulWidget { + /// Construct a [PlatformViewLink] widget. + /// + /// See also: + /// + /// * [PlatformViewSurface] for details on the widget returned by `surfaceFactory`. + /// * [PlatformViewCreationParams] for how each parameter can be used when implementing `createPlatformView`. + const PlatformViewLink({ + super.key, + required PlatformViewSurfaceFactory surfaceFactory, + required CreatePlatformViewCallback onCreatePlatformView, + required this.viewType, + }) : _surfaceFactory = surfaceFactory, + _onCreatePlatformView = onCreatePlatformView; + + + final PlatformViewSurfaceFactory _surfaceFactory; + final CreatePlatformViewCallback _onCreatePlatformView; + + /// The unique identifier for the view type to be embedded. + /// + /// Typically, this viewType has already been registered on the platform side. + final String viewType; + + @override + State<StatefulWidget> createState() => _PlatformViewLinkState(); +} + +class _PlatformViewLinkState extends State<PlatformViewLink> { + int? _id; + PlatformViewController? _controller; + bool _platformViewCreated = false; + Widget? _surface; + FocusNode? _focusNode; + + @override + Widget build(BuildContext context) { + final PlatformViewController? controller = _controller; + if (controller == null) { + return const SizedBox.expand(); + } + if (!_platformViewCreated) { + // Depending on the implementation, the first non-empty size can be used + // to size the platform view. + return _PlatformViewPlaceHolder(onLayout: (Size size, Offset position) { + if (controller.awaitingCreation && !size.isEmpty) { + controller.create(size: size, position: position); + } + }); + } + _surface ??= widget._surfaceFactory(context, controller); + return Focus( + focusNode: _focusNode, + onFocusChange: _handleFrameworkFocusChanged, + child: _surface!, + ); + } + + @override + void initState() { + _focusNode = FocusNode(debugLabel: 'PlatformView(id: $_id)'); + _initialize(); + super.initState(); + } + + @override + void didUpdateWidget(PlatformViewLink oldWidget) { + super.didUpdateWidget(oldWidget); + + if (widget.viewType != oldWidget.viewType) { + _controller?.disposePostFrame(); + // The _surface has to be recreated as its controller is disposed. + // Setting _surface to null will trigger its creation in build(). + _surface = null; + _initialize(); + } + } + + void _initialize() { + _id = platformViewsRegistry.getNextPlatformViewId(); + _controller = widget._onCreatePlatformView( + PlatformViewCreationParams._( + id: _id!, + viewType: widget.viewType, + onPlatformViewCreated: _onPlatformViewCreated, + onFocusChanged: _handlePlatformFocusChanged, + ), + ); + } + + void _onPlatformViewCreated(int id) { + if (mounted) { + setState(() { + _platformViewCreated = true; + }); + } + } + + void _handleFrameworkFocusChanged(bool isFocused) { + if (!isFocused) { + _controller?.clearFocus(); + } + SystemChannels.textInput.invokeMethod<void>( + 'TextInput.setPlatformViewClient', + <String, dynamic>{'platformViewId': _id}, + ); + } + + void _handlePlatformFocusChanged(bool isFocused) { + if (isFocused) { + _focusNode!.requestFocus(); + } + } + + @override + void dispose() { + _controller?.dispose(); + _controller = null; + _focusNode?.dispose(); + _focusNode = null; + super.dispose(); + } +} + +/// Integrates a platform view with Flutter's compositor, touch, and semantics subsystems. +/// +/// The compositor integration is done by adding a [PlatformViewLayer] to the layer tree. [PlatformViewSurface] +/// isn't supported on all platforms (e.g on Android platform views can be composited by using a [TextureLayer] or +/// [AndroidViewSurface]). +/// Custom Flutter embedders can support [PlatformViewLayer]s by implementing a SystemCompositor. +/// +/// The widget fills all available space, the parent of this object must provide bounded layout +/// constraints. +/// +/// If the associated platform view is not created the [PlatformViewSurface] does not paint any contents. +/// +/// See also: +/// +/// * [AndroidView] which embeds an Android platform view in the widget hierarchy using a [TextureLayer]. +/// * [UiKitView] which embeds an iOS platform view in the widget hierarchy. +// TODO(amirh): Link to the embedder's system compositor documentation once available. +class PlatformViewSurface extends LeafRenderObjectWidget { + + /// Construct a [PlatformViewSurface]. + const PlatformViewSurface({ + super.key, + required this.controller, + required this.hitTestBehavior, + required this.gestureRecognizers, + }); + + /// The controller for the platform view integrated by this [PlatformViewSurface]. + /// + /// [PlatformViewController] is used for dispatching touch events to the platform view. + /// [PlatformViewController.viewId] identifies the platform view whose contents are painted by this widget. + final PlatformViewController controller; + + /// Which gestures should be forwarded to the PlatformView. + /// + /// {@macro flutter.widgets.AndroidView.gestureRecognizers.descHead} + /// + /// For example, with the following setup vertical drags will not be dispatched to the platform view + /// as the vertical drag gesture is claimed by the parent [GestureDetector]. + /// + /// ```dart + /// GestureDetector( + /// onVerticalDragStart: (DragStartDetails details) { }, + /// child: PlatformViewSurface( + /// gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{}, + /// controller: _controller, + /// hitTestBehavior: PlatformViewHitTestBehavior.opaque, + /// ), + /// ) + /// ``` + /// + /// To get the [PlatformViewSurface] to claim the vertical drag gestures we can pass a vertical drag + /// gesture recognizer factory in [gestureRecognizers] e.g: + /// + /// ```dart + /// GestureDetector( + /// onVerticalDragStart: (DragStartDetails details) { }, + /// child: SizedBox( + /// width: 200.0, + /// height: 100.0, + /// child: PlatformViewSurface( + /// gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{ + /// Factory<OneSequenceGestureRecognizer>( + /// () => EagerGestureRecognizer(), + /// ), + /// }, + /// controller: _controller, + /// hitTestBehavior: PlatformViewHitTestBehavior.opaque, + /// ), + /// ), + /// ) + /// ``` + /// + /// {@macro flutter.widgets.AndroidView.gestureRecognizers.descFoot} + // We use OneSequenceGestureRecognizers as they support gesture arena teams. + // TODO(amirh): get a list of GestureRecognizers here. + // https://github.com/flutter/flutter/issues/20953 + final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers; + + /// {@macro flutter.widgets.AndroidView.hitTestBehavior} + final PlatformViewHitTestBehavior hitTestBehavior; + + @override + RenderObject createRenderObject(BuildContext context) { + return PlatformViewRenderBox(controller: controller, gestureRecognizers: gestureRecognizers, hitTestBehavior: hitTestBehavior); + } + + @override + void updateRenderObject(BuildContext context, PlatformViewRenderBox renderObject) { + renderObject + ..controller = controller + ..hitTestBehavior = hitTestBehavior + ..updateGestureRecognizers(gestureRecognizers); + } +} + +/// Integrates an Android view with Flutter's compositor, touch, and semantics subsystems. +/// +/// The compositor integration is done by adding a [TextureLayer] to the layer tree. +/// +/// The parent of this object must provide bounded layout constraints. +/// +/// If the associated platform view is not created, the [AndroidViewSurface] does not paint any contents. +/// +/// When possible, you may want to use [AndroidView] directly, since it requires less boilerplate code +/// than [AndroidViewSurface], and there's no difference in performance, or other trade-off(s). +/// +/// See also: +/// +/// * [AndroidView] which embeds an Android platform view in the widget hierarchy. +/// * [UiKitView] which embeds an iOS platform view in the widget hierarchy. +class AndroidViewSurface extends StatefulWidget { + /// Construct an `AndroidPlatformViewSurface`. + const AndroidViewSurface({ + super.key, + required this.controller, + required this.hitTestBehavior, + required this.gestureRecognizers, + }); + + /// The controller for the platform view integrated by this [AndroidViewSurface]. + /// + /// See [PlatformViewSurface.controller] for details. + final AndroidViewController controller; + + /// Which gestures should be forwarded to the PlatformView. + /// + /// See [PlatformViewSurface.gestureRecognizers] for details. + final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers; + + /// {@macro flutter.widgets.AndroidView.hitTestBehavior} + final PlatformViewHitTestBehavior hitTestBehavior; + + @override + State<StatefulWidget> createState() { + return _AndroidViewSurfaceState(); + } +} + +class _AndroidViewSurfaceState extends State<AndroidViewSurface> { + @override + void initState() { + super.initState(); + if (!widget.controller.isCreated) { + // Schedule a rebuild once creation is complete and the final display + // type is known. + widget.controller.addOnPlatformViewCreatedListener(_onPlatformViewCreated); + } + } + + @override + void dispose() { + widget.controller.removeOnPlatformViewCreatedListener(_onPlatformViewCreated); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + if (widget.controller.requiresViewComposition) { + return _PlatformLayerBasedAndroidViewSurface( + controller: widget.controller, + hitTestBehavior: widget.hitTestBehavior, + gestureRecognizers: widget.gestureRecognizers, + ); + } else { + return _TextureBasedAndroidViewSurface( + controller: widget.controller, + hitTestBehavior: widget.hitTestBehavior, + gestureRecognizers: widget.gestureRecognizers, + ); + } + } + + void _onPlatformViewCreated(int _) { + // Trigger a re-build based on the current controller state. + setState(() {}); + } +} + +// Displays an Android platform view via GL texture. +class _TextureBasedAndroidViewSurface extends PlatformViewSurface { + const _TextureBasedAndroidViewSurface({ + required AndroidViewController super.controller, + required super.hitTestBehavior, + required super.gestureRecognizers, + }); + + @override + RenderObject createRenderObject(BuildContext context) { + final AndroidViewController viewController = controller as AndroidViewController; + // Use GL texture based composition. + // App should use GL texture unless they require to embed a SurfaceView. + final RenderAndroidView renderBox = RenderAndroidView( + viewController: viewController, + gestureRecognizers: gestureRecognizers, + hitTestBehavior: hitTestBehavior, + ); + viewController.pointTransformer = + (Offset position) => renderBox.globalToLocal(position); + return renderBox; + } +} + +class _PlatformLayerBasedAndroidViewSurface extends PlatformViewSurface { + const _PlatformLayerBasedAndroidViewSurface({ + required AndroidViewController super.controller, + required super.hitTestBehavior, + required super.gestureRecognizers, + }); + + @override + RenderObject createRenderObject(BuildContext context) { + final AndroidViewController viewController = controller as AndroidViewController; + final PlatformViewRenderBox renderBox = + super.createRenderObject(context) as PlatformViewRenderBox; + viewController.pointTransformer = + (Offset position) => renderBox.globalToLocal(position); + return renderBox; + } +} + +/// A callback used to notify the size of the platform view placeholder. +/// This size is the initial size of the platform view. +typedef _OnLayoutCallback = void Function(Size size, Offset position); + +/// A [RenderBox] that notifies its size to the owner after a layout. +class _PlatformViewPlaceholderBox extends RenderConstrainedBox { + _PlatformViewPlaceholderBox({ + required this.onLayout, + }) : super(additionalConstraints: const BoxConstraints.tightFor( + width: double.infinity, + height: double.infinity, + )); + + _OnLayoutCallback onLayout; + + @override + void performLayout() { + super.performLayout(); + // A call to `localToGlobal` requires waiting for a frame to render first. + SchedulerBinding.instance.addPostFrameCallback((_) { + onLayout(size, localToGlobal(Offset.zero)); + }, debugLabel: 'PlatformViewPlaceholderBox.onLayout'); + } +} + +/// When a platform view is in the widget hierarchy, this widget is used to capture +/// the size of the platform view after the first layout. +/// This placeholder is basically a [SizedBox.expand] with a [onLayout] callback to +/// notify the size of the render object to its parent. +class _PlatformViewPlaceHolder extends SingleChildRenderObjectWidget { + const _PlatformViewPlaceHolder({ + required this.onLayout, + }); + + final _OnLayoutCallback onLayout; + + @override + _PlatformViewPlaceholderBox createRenderObject(BuildContext context) { + return _PlatformViewPlaceholderBox(onLayout: onLayout); + } + + @override + void updateRenderObject(BuildContext context, _PlatformViewPlaceholderBox renderObject) { + renderObject.onLayout = onLayout; + } +} + +extension on PlatformViewController { + /// Disposes the controller in a post-frame callback, to allow other widgets to + /// remove their listeners before the controller is disposed. + void disposePostFrame() { + SchedulerBinding.instance.addPostFrameCallback((_) { + dispose(); + }, debugLabel: 'PlatformViewController.dispose'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/pop_scope.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/pop_scope.dart new file mode 100644 index 0000000000000000000000000000000000000000..b47d83fcdbbd0fad6268d47c5cdb3019e1119238 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/pop_scope.dart @@ -0,0 +1,137 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'framework.dart'; +import 'navigator.dart'; +import 'routes.dart'; + +/// Manages system back gestures. +/// +/// The [canPop] parameter can be used to disable system back gestures. Defaults +/// to true, meaning that back gestures happen as usual. +/// +/// The [onPopInvoked] parameter reports when system back gestures occur, +/// regardless of whether or not they were successful. +/// +/// If [canPop] is false, then a system back gesture will not pop the route off +/// of the enclosing [Navigator]. [onPopInvoked] will still be called, and +/// `didPop` will be `false`. +/// +/// If [canPop] is true, then a system back gesture will cause the enclosing +/// [Navigator] to receive a pop as usual. [onPopInvoked] will be called with +/// `didPop` as `true`, unless the pop failed for reasons unrelated to +/// [PopScope], in which case it will be `false`. +/// +/// {@tool dartpad} +/// This sample demonstrates how to use this widget to handle nested navigation +/// in a bottom navigation bar. +/// +/// ** See code in examples/api/lib/widgets/pop_scope/pop_scope.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [NavigatorPopHandler], which is a less verbose way to handle system back +/// gestures in simple cases of nested [Navigator]s. +/// * [Form.canPop] and [Form.onPopInvoked], which can be used to handle system +/// back gestures in the case of a form with unsaved data. +/// * [ModalRoute.registerPopEntry] and [ModalRoute.unregisterPopEntry], +/// which this widget uses to integrate with Flutter's navigation system. +class PopScope extends StatefulWidget { + /// Creates a widget that registers a callback to veto attempts by the user to + /// dismiss the enclosing [ModalRoute]. + const PopScope({ + super.key, + required this.child, + this.canPop = true, + this.onPopInvoked, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// {@template flutter.widgets.PopScope.onPopInvoked} + /// Called after a route pop was handled. + /// {@endtemplate} + /// + /// It's not possible to prevent the pop from happening at the time that this + /// method is called; the pop has already happened. Use [canPop] to + /// disable pops in advance. + /// + /// This will still be called even when the pop is canceled. A pop is canceled + /// when the relevant [Route.popDisposition] returns false, such as when + /// [canPop] is set to false on a [PopScope]. The `didPop` parameter + /// indicates whether or not the back navigation actually happened + /// successfully. + /// + /// See also: + /// + /// * [Route.onPopInvoked], which is similar. + final PopInvokedCallback? onPopInvoked; + + /// {@template flutter.widgets.PopScope.canPop} + /// When false, blocks the current route from being popped. + /// + /// This includes the root route, where upon popping, the Flutter app would + /// exit. + /// + /// If multiple [PopScope] widgets appear in a route's widget subtree, then + /// each and every `canPop` must be `true` in order for the route to be + /// able to pop. + /// + /// [Android's predictive back](https://developer.android.com/guide/navigation/predictive-back-gesture) + /// feature will not animate when this boolean is false. + /// {@endtemplate} + final bool canPop; + + @override + State<PopScope> createState() => _PopScopeState(); +} + +class _PopScopeState extends State<PopScope> implements PopEntry { + ModalRoute<dynamic>? _route; + + @override + PopInvokedCallback? get onPopInvoked => widget.onPopInvoked; + + @override + late final ValueNotifier<bool> canPopNotifier; + + @override + void initState() { + super.initState(); + canPopNotifier = ValueNotifier<bool>(widget.canPop); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final ModalRoute<dynamic>? nextRoute = ModalRoute.of(context); + if (nextRoute != _route) { + _route?.unregisterPopEntry(this); + _route = nextRoute; + _route?.registerPopEntry(this); + } + } + + @override + void didUpdateWidget(PopScope oldWidget) { + super.didUpdateWidget(oldWidget); + canPopNotifier.value = widget.canPop; + } + + @override + void dispose() { + _route?.unregisterPopEntry(this); + canPopNotifier.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => widget.child; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/preferred_size.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/preferred_size.dart new file mode 100644 index 0000000000000000000000000000000000000000..2c6f876a51eb9ad0757dfa627a862ee125def407 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/preferred_size.dart @@ -0,0 +1,81 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; + +/// An interface for widgets that can return the size this widget would prefer +/// if it were otherwise unconstrained. +/// +/// There are a few cases, notably [AppBar] and [TabBar], where it would be +/// undesirable for the widget to constrain its own size but where the widget +/// needs to expose a preferred or "default" size. For example a primary +/// [Scaffold] sets its app bar height to the app bar's preferred height +/// plus the height of the system status bar. +/// +/// Widgets that need to know the preferred size of their child can require +/// that their child implement this interface by using this class rather +/// than [Widget] as the type of their `child` property. +/// +/// Use [PreferredSize] to give a preferred size to an arbitrary widget. +abstract class PreferredSizeWidget implements Widget { + /// The size this widget would prefer if it were otherwise unconstrained. + /// + /// In many cases it's only necessary to define one preferred dimension. + /// For example the [Scaffold] only depends on its app bar's preferred + /// height. In that case implementations of this method can just return + /// `Size.fromHeight(myAppBarHeight)`. + Size get preferredSize; +} + +/// A widget with a preferred size. +/// +/// This widget does not impose any constraints on its child, and it doesn't +/// affect the child's layout in any way. It just advertises a preferred size +/// which can be used by the parent. +/// +/// Parents like [Scaffold] use [PreferredSizeWidget] to require that their +/// children implement that interface. To give a preferred size to an arbitrary +/// widget so that it can be used in a `child` property of that type, this +/// widget, [PreferredSize], can be used. +/// +/// Widgets like [AppBar] implement a [PreferredSizeWidget], so that this +/// [PreferredSize] widget is not necessary for them. +/// +/// {@tool dartpad} +/// This sample shows a custom widget, similar to an [AppBar], which uses a +/// [PreferredSize] widget, with its height set to 80 logical pixels. +/// Changing the [PreferredSize] can be used to change the height +/// of the custom app bar. +/// +/// ** See code in examples/api/lib/widgets/preferred_size/preferred_size.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AppBar.bottom] and [Scaffold.appBar], which require preferred size widgets. +/// * [PreferredSizeWidget], the interface which this widget implements to expose +/// its preferred size. +/// * [AppBar] and [TabBar], which implement PreferredSizeWidget. +class PreferredSize extends StatelessWidget implements PreferredSizeWidget { + /// Creates a widget that has a preferred size that the parent can query. + const PreferredSize({ + super.key, + required this.preferredSize, + required this.child, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + final Size preferredSize; + + @override + Widget build(BuildContext context) => child; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/primary_scroll_controller.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/primary_scroll_controller.dart new file mode 100644 index 0000000000000000000000000000000000000000..dea998277de273e5c311ade958f4cd2b6a4d2bb6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/primary_scroll_controller.dart @@ -0,0 +1,187 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; + +import 'framework.dart'; +import 'scroll_configuration.dart'; +import 'scroll_controller.dart'; + +const Set<TargetPlatform> _kMobilePlatforms = <TargetPlatform>{ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.fuchsia, +}; + +/// Associates a [ScrollController] with a subtree. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=33_0ABjFJUU} +/// +/// When a [ScrollView] has [ScrollView.primary] set to true, the [ScrollView] +/// uses [of] to inherit the [PrimaryScrollController] associated with its +/// subtree. +/// +/// A ScrollView that doesn't have a controller or the primary flag set will +/// inherit the PrimaryScrollController, if [shouldInherit] allows it. By +/// default [shouldInherit] is true for mobile platforms when the ScrollView has +/// a scroll direction of [Axis.vertical]. This automatic inheritance can be +/// configured with [automaticallyInheritForPlatforms] and [scrollDirection]. +/// +/// Inheriting this ScrollController can provide default behavior for scroll +/// views in a subtree. For example, the [Scaffold] uses this mechanism to +/// implement the scroll-to-top gesture on iOS. +/// +/// Another default behavior handled by the PrimaryScrollController is default +/// [ScrollAction]s. If a ScrollAction is not handled by an otherwise focused +/// part of the application, the ScrollAction will be evaluated using the scroll +/// view associated with a PrimaryScrollController, for example, when executing +/// [Shortcuts] key events like page up and down. +/// +/// See also: +/// * [ScrollAction], an [Action] that scrolls the [Scrollable] that encloses +/// the current [primaryFocus] or is attached to the PrimaryScrollController. +/// * [Shortcuts], a widget that establishes a [ShortcutManager] to be used +/// by its descendants when invoking an [Action] via a keyboard key +/// combination that maps to an [Intent]. +class PrimaryScrollController extends InheritedWidget { + /// Creates a widget that associates a [ScrollController] with a subtree. + const PrimaryScrollController({ + super.key, + required ScrollController this.controller, + this.automaticallyInheritForPlatforms = _kMobilePlatforms, + this.scrollDirection = Axis.vertical, + required super.child, + }); + + /// Creates a subtree without an associated [ScrollController]. + const PrimaryScrollController.none({ + super.key, + required super.child, + }) : automaticallyInheritForPlatforms = const <TargetPlatform>{}, + scrollDirection = null, + controller = null; + + /// The [ScrollController] associated with the subtree. + /// + /// See also: + /// + /// * [ScrollView.controller], which discusses the purpose of specifying a + /// scroll controller. + final ScrollController? controller; + + /// The [Axis] this controller is configured for [ScrollView]s to + /// automatically inherit. + /// + /// Used in conjunction with [automaticallyInheritForPlatforms]. If the + /// current [TargetPlatform] is not included in + /// [automaticallyInheritForPlatforms], this is ignored. + /// + /// When null, no [ScrollView] in any Axis will automatically inherit this + /// controller. This is dissimilar to [PrimaryScrollController.none]. When a + /// PrimaryScrollController is inherited, ScrollView will insert + /// PrimaryScrollController.none into the tree to prevent further descendant + /// ScrollViews from inheriting the current PrimaryScrollController. + /// + /// For the direction in which active scrolling may be occurring, see + /// [ScrollDirection]. + /// + /// Defaults to [Axis.vertical]. + final Axis? scrollDirection; + + /// The [TargetPlatform]s this controller is configured for [ScrollView]s to + /// automatically inherit. + /// + /// Used in conjunction with [scrollDirection]. If the [Axis] provided to + /// [shouldInherit] is not [scrollDirection], this is ignored. + /// + /// When empty, no ScrollView in any Axis will automatically inherit this + /// controller. Defaults to [TargetPlatformVariant.mobile]. + final Set<TargetPlatform> automaticallyInheritForPlatforms; + + /// Returns true if this PrimaryScrollController is configured to be + /// automatically inherited for the current [TargetPlatform] and the given + /// [Axis]. + /// + /// This method is typically not called directly. [ScrollView] will call this + /// method if it has not been provided a [ScrollController] and + /// [ScrollView.primary] is unset. + /// + /// If a ScrollController has already been provided to + /// [ScrollView.controller], or [ScrollView.primary] is set, this is method is + /// not called by ScrollView as it will have determined whether or not to + /// inherit the PrimaryScrollController. + static bool shouldInherit(BuildContext context, Axis scrollDirection) { + final PrimaryScrollController? result = context.findAncestorWidgetOfExactType<PrimaryScrollController>(); + if (result == null) { + return false; + } + + final TargetPlatform platform = ScrollConfiguration.of(context).getPlatform(context); + if (result.automaticallyInheritForPlatforms.contains(platform)) { + return result.scrollDirection == scrollDirection; + } + return false; + } + + /// Returns the [ScrollController] most closely associated with the given + /// context. + /// + /// Returns null if there is no [ScrollController] associated with the given + /// context. + /// + /// Calling this method will create a dependency on the closest + /// [PrimaryScrollController] in the [context], if there is one. + /// + /// See also: + /// + /// * [PrimaryScrollController.maybeOf], which is similar to this method, but + /// asserts if no [PrimaryScrollController] ancestor is found. + static ScrollController? maybeOf(BuildContext context) { + final PrimaryScrollController? result = context.dependOnInheritedWidgetOfExactType<PrimaryScrollController>(); + return result?.controller; + } + + /// Returns the [ScrollController] most closely associated with the given + /// context. + /// + /// If no ancestor is found, this method will assert in debug mode, and throw + /// an exception in release mode. + /// + /// Calling this method will create a dependency on the closest + /// [PrimaryScrollController] in the [context]. + /// + /// See also: + /// + /// * [PrimaryScrollController.maybeOf], which is similar to this method, but + /// returns null if no [PrimaryScrollController] ancestor is found. + static ScrollController of(BuildContext context) { + final ScrollController? controller = maybeOf(context); + assert(() { + if (controller == null) { + throw FlutterError( + 'PrimaryScrollController.of() was called with a context that does not contain a ' + 'PrimaryScrollController widget.\n' + 'No PrimaryScrollController widget ancestor could be found starting from the ' + 'context that was passed to PrimaryScrollController.of(). This can happen ' + 'because you are using a widget that looks for a PrimaryScrollController ' + 'ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return controller!; + } + + @override + bool updateShouldNotify(PrimaryScrollController oldWidget) => controller != oldWidget.controller; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ScrollController>('controller', controller, ifNull: 'no controller', showName: false)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/raw_keyboard_listener.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/raw_keyboard_listener.dart new file mode 100644 index 0000000000000000000000000000000000000000..203f836749d2f16edb30a229b1ce6aa101cdffde --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/raw_keyboard_listener.dart @@ -0,0 +1,144 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; + +export 'package:flutter/services.dart' show RawKeyEvent; + +/// A widget that calls a callback whenever the user presses or releases a key +/// on a keyboard. +/// +/// The [RawKeyboardListener] is deprecated and will be removed. Use +/// [KeyboardListener] instead. +/// +/// A [RawKeyboardListener] is useful for listening to raw key events and +/// hardware buttons that are represented as keys. Typically used by games and +/// other apps that use keyboards for purposes other than text entry. +/// +/// For text entry, consider using a [EditableText], which integrates with +/// on-screen keyboards and input method editors (IMEs). +/// +/// See also: +/// +/// * [EditableText], which should be used instead of this widget for text +/// entry. +/// * [KeyboardListener], a similar widget based on the newer [HardwareKeyboard] +/// API. +@Deprecated( + 'Use KeyboardListener instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', +) +class RawKeyboardListener extends StatefulWidget { + /// Creates a widget that receives raw keyboard events. + /// + /// For text entry, consider using a [EditableText], which integrates with + /// on-screen keyboards and input method editors (IMEs). + @Deprecated( + 'Use KeyboardListener instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + const RawKeyboardListener({ + super.key, + required this.focusNode, + this.autofocus = false, + this.includeSemantics = true, + this.onKey, + required this.child, + }); + + /// Controls whether this widget has keyboard focus. + final FocusNode focusNode; + + /// {@macro flutter.widgets.Focus.autofocus} + final bool autofocus; + + /// {@macro flutter.widgets.Focus.includeSemantics} + final bool includeSemantics; + + /// Called whenever this widget receives a raw keyboard event. + final ValueChanged<RawKeyEvent>? onKey; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + State<RawKeyboardListener> createState() => _RawKeyboardListenerState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode)); + } +} + +class _RawKeyboardListenerState extends State<RawKeyboardListener> { + @override + void initState() { + super.initState(); + widget.focusNode.addListener(_handleFocusChanged); + } + + @override + void didUpdateWidget(RawKeyboardListener oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.focusNode != oldWidget.focusNode) { + oldWidget.focusNode.removeListener(_handleFocusChanged); + widget.focusNode.addListener(_handleFocusChanged); + } + } + + @override + void dispose() { + widget.focusNode.removeListener(_handleFocusChanged); + _detachKeyboardIfAttached(); + super.dispose(); + } + + void _handleFocusChanged() { + if (widget.focusNode.hasFocus) { + _attachKeyboardIfDetached(); + } else { + _detachKeyboardIfAttached(); + } + } + + bool _listening = false; + + void _attachKeyboardIfDetached() { + if (_listening) { + return; + } + RawKeyboard.instance.addListener(_handleRawKeyEvent); + _listening = true; + } + + void _detachKeyboardIfAttached() { + if (!_listening) { + return; + } + RawKeyboard.instance.removeListener(_handleRawKeyEvent); + _listening = false; + } + + void _handleRawKeyEvent(RawKeyEvent event) { + widget.onKey?.call(event); + } + + @override + Widget build(BuildContext context) { + return Focus( + focusNode: widget.focusNode, + autofocus: widget.autofocus, + includeSemantics: widget.includeSemantics, + child: widget.child, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/reorderable_list.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/reorderable_list.dart new file mode 100644 index 0000000000000000000000000000000000000000..239bd18eaf1e9fc8624a4ad2ed2aeedc136ac429 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/reorderable_list.dart @@ -0,0 +1,1552 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'inherited_theme.dart'; +import 'localizations.dart'; +import 'media_query.dart'; +import 'overlay.dart'; +import 'scroll_controller.dart'; +import 'scroll_delegate.dart'; +import 'scroll_physics.dart'; +import 'scroll_view.dart'; +import 'scrollable.dart'; +import 'scrollable_helpers.dart'; +import 'sliver.dart'; +import 'sliver_prototype_extent_list.dart'; +import 'sliver_varied_extent_list.dart'; +import 'ticker_provider.dart'; +import 'transitions.dart'; + +// Examples can assume: +// class MyDataObject {} + +/// A callback used by [ReorderableList] to report that a list item has moved +/// to a new position in the list. +/// +/// Implementations should remove the corresponding list item at [oldIndex] +/// and reinsert it at [newIndex]. +/// +/// If [oldIndex] is before [newIndex], removing the item at [oldIndex] from the +/// list will reduce the list's length by one. Implementations will need to +/// account for this when inserting before [newIndex]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=3fB1mxOsqJE} +/// +/// {@tool snippet} +/// +/// ```dart +/// final List<MyDataObject> backingList = <MyDataObject>[/* ... */]; +/// +/// void handleReorder(int oldIndex, int newIndex) { +/// if (oldIndex < newIndex) { +/// // removing the item at oldIndex will shorten the list by 1. +/// newIndex -= 1; +/// } +/// final MyDataObject element = backingList.removeAt(oldIndex); +/// backingList.insert(newIndex, element); +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [ReorderableList], a widget list that allows the user to reorder +/// its items. +/// * [SliverReorderableList], a sliver list that allows the user to reorder +/// its items. +/// * [ReorderableListView], a Material Design list that allows the user to +/// reorder its items. +typedef ReorderCallback = void Function(int oldIndex, int newIndex); + +/// Signature for the builder callback used to decorate the dragging item in +/// [ReorderableList] and [SliverReorderableList]. +/// +/// The [child] will be the item that is being dragged, and [index] is the +/// position of the item in the list. +/// +/// The [animation] will be driven forward from 0.0 to 1.0 while the item is +/// being picked up during a drag operation, and reversed from 1.0 to 0.0 when +/// the item is dropped. This can be used to animate properties of the proxy +/// like an elevation or border. +/// +/// The returned value will typically be the [child] wrapped in other widgets. +typedef ReorderItemProxyDecorator = Widget Function(Widget child, int index, Animation<double> animation); + +/// A scrolling container that allows the user to interactively reorder the +/// list items. +/// +/// This widget is similar to one created by [ListView.builder], and uses +/// an [IndexedWidgetBuilder] to create each item. +/// +/// It is up to the application to wrap each child (or an internal part of the +/// child such as a drag handle) with a drag listener that will recognize +/// the start of an item drag and then start the reorder by calling +/// [ReorderableListState.startItemDragReorder]. This is most easily achieved +/// by wrapping each child in a [ReorderableDragStartListener] or a +/// [ReorderableDelayedDragStartListener]. These will take care of recognizing +/// the start of a drag gesture and call the list state's +/// [ReorderableListState.startItemDragReorder] method. +/// +/// This widget's [ReorderableListState] can be used to manually start an item +/// reorder, or cancel a current drag. To refer to the +/// [ReorderableListState] either provide a [GlobalKey] or use the static +/// [ReorderableList.of] method from an item's build method. +/// +/// See also: +/// +/// * [SliverReorderableList], a sliver list that allows the user to reorder +/// its items. +/// * [ReorderableListView], a Material Design list that allows the user to +/// reorder its items. +class ReorderableList extends StatefulWidget { + /// Creates a scrolling container that allows the user to interactively + /// reorder the list items. + /// + /// The [itemCount] must be greater than or equal to zero. + const ReorderableList({ + super.key, + required this.itemBuilder, + required this.itemCount, + required this.onReorder, + this.onReorderStart, + this.onReorderEnd, + this.itemExtent, + this.itemExtentBuilder, + this.prototypeItem, + this.proxyDecorator, + this.padding, + this.scrollDirection = Axis.vertical, + this.reverse = false, + this.controller, + this.primary, + this.physics, + this.shrinkWrap = false, + this.anchor = 0.0, + this.cacheExtent, + this.dragStartBehavior = DragStartBehavior.start, + this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, + this.restorationId, + this.clipBehavior = Clip.hardEdge, + this.autoScrollerVelocityScalar, + }) : assert(itemCount >= 0), + assert( + (itemExtent == null && prototypeItem == null) || + (itemExtent == null && itemExtentBuilder == null) || + (prototypeItem == null && itemExtentBuilder == null), + 'You can only pass one of itemExtent, prototypeItem and itemExtentBuilder.', + ); + + /// {@template flutter.widgets.reorderable_list.itemBuilder} + /// Called, as needed, to build list item widgets. + /// + /// List items are only built when they're scrolled into view. + /// + /// The [IndexedWidgetBuilder] index parameter indicates the item's + /// position in the list. The value of the index parameter will be between + /// zero and one less than [itemCount]. All items in the list must have a + /// unique [Key], and should have some kind of listener to start the drag + /// (usually a [ReorderableDragStartListener] or + /// [ReorderableDelayedDragStartListener]). + /// {@endtemplate} + final IndexedWidgetBuilder itemBuilder; + + /// {@template flutter.widgets.reorderable_list.itemCount} + /// The number of items in the list. + /// + /// It must be a non-negative integer. When zero, nothing is displayed and + /// the widget occupies no space. + /// {@endtemplate} + final int itemCount; + + /// {@template flutter.widgets.reorderable_list.onReorder} + /// A callback used by the list to report that a list item has been dragged + /// to a new location in the list and the application should update the order + /// of the items. + /// {@endtemplate} + final ReorderCallback onReorder; + + /// {@template flutter.widgets.reorderable_list.onReorderStart} + /// A callback that is called when an item drag has started. + /// + /// The index parameter of the callback is the index of the selected item. + /// + /// See also: + /// + /// * [onReorderEnd], which is a called when the dragged item is dropped. + /// * [onReorder], which reports that a list item has been dragged to a new + /// location. + /// {@endtemplate} + final void Function(int index)? onReorderStart; + + /// {@template flutter.widgets.reorderable_list.onReorderEnd} + /// A callback that is called when the dragged item is dropped. + /// + /// The index parameter of the callback is the index where the item is + /// dropped. Unlike [onReorder], this is called even when the list item is + /// dropped in the same location. + /// + /// See also: + /// + /// * [onReorderStart], which is a called when an item drag has started. + /// * [onReorder], which reports that a list item has been dragged to a new + /// location. + /// {@endtemplate} + final void Function(int index)? onReorderEnd; + + /// {@template flutter.widgets.reorderable_list.proxyDecorator} + /// A callback that allows the app to add an animated decoration around + /// an item when it is being dragged. + /// {@endtemplate} + final ReorderItemProxyDecorator? proxyDecorator; + + /// {@template flutter.widgets.reorderable_list.padding} + /// The amount of space by which to inset the list contents. + /// + /// It defaults to `EdgeInsets.all(0)`. + /// {@endtemplate} + final EdgeInsetsGeometry? padding; + + /// {@macro flutter.widgets.scroll_view.scrollDirection} + final Axis scrollDirection; + + /// {@macro flutter.widgets.scroll_view.reverse} + final bool reverse; + + /// {@macro flutter.widgets.scroll_view.controller} + final ScrollController? controller; + + /// {@macro flutter.widgets.scroll_view.primary} + final bool? primary; + + /// {@macro flutter.widgets.scroll_view.physics} + final ScrollPhysics? physics; + + /// {@macro flutter.widgets.scroll_view.shrinkWrap} + final bool shrinkWrap; + + /// {@macro flutter.widgets.scroll_view.anchor} + final double anchor; + + /// {@macro flutter.rendering.RenderViewportBase.cacheExtent} + final double? cacheExtent; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@macro flutter.widgets.scroll_view.keyboardDismissBehavior} + /// + /// The default is [ScrollViewKeyboardDismissBehavior.manual] + final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior; + + /// {@macro flutter.widgets.scrollable.restorationId} + final String? restorationId; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// {@macro flutter.widgets.list_view.itemExtent} + final double? itemExtent; + + /// {@macro flutter.widgets.list_view.itemExtentBuilder} + final ItemExtentBuilder? itemExtentBuilder; + + /// {@macro flutter.widgets.list_view.prototypeItem} + final Widget? prototypeItem; + + /// {@macro flutter.widgets.EdgeDraggingAutoScroller.velocityScalar} + /// + /// {@macro flutter.widgets.SliverReorderableList.autoScrollerVelocityScalar.default} + final double? autoScrollerVelocityScalar; + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [ReorderableList] item widgets that + /// insert or remove items in response to user input. + /// + /// If no [ReorderableList] surrounds the given context, then this function + /// will assert in debug mode and throw an exception in release mode. + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [maybeOf], a similar function that will return null if no + /// [ReorderableList] ancestor is found. + static ReorderableListState of(BuildContext context) { + final ReorderableListState? result = context.findAncestorStateOfType<ReorderableListState>(); + assert(() { + if (result == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('ReorderableList.of() called with a context that does not contain a ReorderableList.'), + ErrorDescription( + 'No ReorderableList ancestor could be found starting from the context that was passed to ReorderableList.of().', + ), + ErrorHint( + 'This can happen when the context provided is from the same StatefulWidget that ' + 'built the ReorderableList. Please see the ReorderableList documentation for examples ' + 'of how to refer to an ReorderableListState object:\n' + ' https://api.flutter.dev/flutter/widgets/ReorderableListState-class.html', + ), + context.describeElement('The context used was'), + ]); + } + return true; + }()); + return result!; + } + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [ReorderableList] item widgets that insert + /// or remove items in response to user input. + /// + /// If no [ReorderableList] surrounds the context given, then this function will + /// return null. + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [of], a similar function that will throw if no [ReorderableList] ancestor + /// is found. + static ReorderableListState? maybeOf(BuildContext context) { + return context.findAncestorStateOfType<ReorderableListState>(); + } + + @override + ReorderableListState createState() => ReorderableListState(); +} + +/// The state for a list that allows the user to interactively reorder +/// the list items. +/// +/// An app that needs to start a new item drag or cancel an existing one +/// can refer to the [ReorderableList]'s state with a global key: +/// +/// ```dart +/// GlobalKey<ReorderableListState> listKey = GlobalKey<ReorderableListState>(); +/// // ... +/// Widget build(BuildContext context) { +/// return ReorderableList( +/// key: listKey, +/// itemBuilder: (BuildContext context, int index) => const SizedBox(height: 10.0), +/// itemCount: 5, +/// onReorder: (int oldIndex, int newIndex) { +/// // ... +/// }, +/// ); +/// } +/// // ... +/// listKey.currentState!.cancelReorder(); +/// ``` +class ReorderableListState extends State<ReorderableList> { + final GlobalKey<SliverReorderableListState> _sliverReorderableListKey = GlobalKey(); + + /// Initiate the dragging of the item at [index] that was started with + /// the pointer down [event]. + /// + /// The given [recognizer] will be used to recognize and start the drag + /// item tracking and lead to either an item reorder, or a canceled drag. + /// The list will take ownership of the returned recognizer and will dispose + /// it when it is no longer needed. + /// + /// Most applications will not use this directly, but will wrap the item + /// (or part of the item, like a drag handle) in either a + /// [ReorderableDragStartListener] or [ReorderableDelayedDragStartListener] + /// which call this for the application. + void startItemDragReorder({ + required int index, + required PointerDownEvent event, + required MultiDragGestureRecognizer recognizer, + }) { + _sliverReorderableListKey.currentState!.startItemDragReorder(index: index, event: event, recognizer: recognizer); + } + + /// Cancel any item drag in progress. + /// + /// This should be called before any major changes to the item list + /// occur so that any item drags will not get confused by + /// changes to the underlying list. + /// + /// If no drag is active, this will do nothing. + void cancelReorder() { + _sliverReorderableListKey.currentState!.cancelReorder(); + } + + @override + Widget build(BuildContext context) { + return CustomScrollView( + scrollDirection: widget.scrollDirection, + reverse: widget.reverse, + controller: widget.controller, + primary: widget.primary, + physics: widget.physics, + shrinkWrap: widget.shrinkWrap, + anchor: widget.anchor, + cacheExtent: widget.cacheExtent, + dragStartBehavior: widget.dragStartBehavior, + keyboardDismissBehavior: widget.keyboardDismissBehavior, + restorationId: widget.restorationId, + clipBehavior: widget.clipBehavior, + slivers: <Widget>[ + SliverPadding( + padding: widget.padding ?? EdgeInsets.zero, + sliver: SliverReorderableList( + key: _sliverReorderableListKey, + itemExtent: widget.itemExtent, + prototypeItem: widget.prototypeItem, + itemBuilder: widget.itemBuilder, + itemCount: widget.itemCount, + onReorder: widget.onReorder, + onReorderStart: widget.onReorderStart, + onReorderEnd: widget.onReorderEnd, + proxyDecorator: widget.proxyDecorator, + autoScrollerVelocityScalar: widget.autoScrollerVelocityScalar, + ), + ), + ], + ); + } +} + +/// A sliver list that allows the user to interactively reorder the list items. +/// +/// It is up to the application to wrap each child (or an internal part of the +/// child) with a drag listener that will recognize the start of an item drag +/// and then start the reorder by calling +/// [SliverReorderableListState.startItemDragReorder]. This is most easily +/// achieved by wrapping each child in a [ReorderableDragStartListener] or +/// a [ReorderableDelayedDragStartListener]. These will take care of +/// recognizing the start of a drag gesture and call the list state's start +/// item drag method. +/// +/// This widget's [SliverReorderableListState] can be used to manually start an item +/// reorder, or cancel a current drag that's already underway. To refer to the +/// [SliverReorderableListState] either provide a [GlobalKey] or use the static +/// [SliverReorderableList.of] method from an item's build method. +/// +/// See also: +/// +/// * [ReorderableList], a regular widget list that allows the user to reorder +/// its items. +/// * [ReorderableListView], a Material Design list that allows the user to +/// reorder its items. +class SliverReorderableList extends StatefulWidget { + /// Creates a sliver list that allows the user to interactively reorder its + /// items. + /// + /// The [itemCount] must be greater than or equal to zero. + const SliverReorderableList({ + super.key, + required this.itemBuilder, + this.findChildIndexCallback, + required this.itemCount, + required this.onReorder, + this.onReorderStart, + this.onReorderEnd, + this.itemExtent, + this.itemExtentBuilder, + this.prototypeItem, + this.proxyDecorator, + double? autoScrollerVelocityScalar, + }) : autoScrollerVelocityScalar = autoScrollerVelocityScalar ?? _kDefaultAutoScrollVelocityScalar, + assert(itemCount >= 0), + assert( + (itemExtent == null && prototypeItem == null) || + (itemExtent == null && itemExtentBuilder == null) || + (prototypeItem == null && itemExtentBuilder == null), + 'You can only pass one of itemExtent, prototypeItem and itemExtentBuilder.', + ); + + // An eyeballed value for a smooth scrolling experience. + static const double _kDefaultAutoScrollVelocityScalar = 50; + + /// {@macro flutter.widgets.reorderable_list.itemBuilder} + final IndexedWidgetBuilder itemBuilder; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.findChildIndexCallback} + final ChildIndexGetter? findChildIndexCallback; + + /// {@macro flutter.widgets.reorderable_list.itemCount} + final int itemCount; + + /// {@macro flutter.widgets.reorderable_list.onReorder} + final ReorderCallback onReorder; + + /// {@macro flutter.widgets.reorderable_list.onReorderStart} + final void Function(int)? onReorderStart; + + /// {@macro flutter.widgets.reorderable_list.onReorderEnd} + final void Function(int)? onReorderEnd; + + /// {@macro flutter.widgets.reorderable_list.proxyDecorator} + final ReorderItemProxyDecorator? proxyDecorator; + + /// {@macro flutter.widgets.list_view.itemExtent} + final double? itemExtent; + + /// {@macro flutter.widgets.list_view.itemExtentBuilder} + final ItemExtentBuilder? itemExtentBuilder; + + /// {@macro flutter.widgets.list_view.prototypeItem} + final Widget? prototypeItem; + + /// {@macro flutter.widgets.EdgeDraggingAutoScroller.velocityScalar} + /// + /// {@template flutter.widgets.SliverReorderableList.autoScrollerVelocityScalar.default} + /// Defaults to 50 if not set or set to null. + /// {@endtemplate} + final double autoScrollerVelocityScalar; + + @override + SliverReorderableListState createState() => SliverReorderableListState(); + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [SliverReorderableList] item widgets to + /// start or cancel an item drag operation. + /// + /// If no [SliverReorderableList] surrounds the context given, this function + /// will assert in debug mode and throw an exception in release mode. + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [maybeOf], a similar function that will return null if no + /// [SliverReorderableList] ancestor is found. + static SliverReorderableListState of(BuildContext context) { + final SliverReorderableListState? result = context.findAncestorStateOfType<SliverReorderableListState>(); + assert(() { + if (result == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'SliverReorderableList.of() called with a context that does not contain a SliverReorderableList.', + ), + ErrorDescription( + 'No SliverReorderableList ancestor could be found starting from the context that was passed to SliverReorderableList.of().', + ), + ErrorHint( + 'This can happen when the context provided is from the same StatefulWidget that ' + 'built the SliverReorderableList. Please see the SliverReorderableList documentation for examples ' + 'of how to refer to an SliverReorderableList object:\n' + ' https://api.flutter.dev/flutter/widgets/SliverReorderableListState-class.html', + ), + context.describeElement('The context used was'), + ]); + } + return true; + }()); + return result!; + } + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// This method is typically used by [SliverReorderableList] item widgets that + /// insert or remove items in response to user input. + /// + /// If no [SliverReorderableList] surrounds the context given, this function + /// will return null. + /// + /// This method can be expensive (it walks the element tree). + /// + /// See also: + /// + /// * [of], a similar function that will throw if no [SliverReorderableList] + /// ancestor is found. + static SliverReorderableListState? maybeOf(BuildContext context) { + return context.findAncestorStateOfType<SliverReorderableListState>(); + } +} + +/// The state for a sliver list that allows the user to interactively reorder +/// the list items. +/// +/// An app that needs to start a new item drag or cancel an existing one +/// can refer to the [SliverReorderableList]'s state with a global key: +/// +/// ```dart +/// // (e.g. in a stateful widget) +/// GlobalKey<SliverReorderableListState> listKey = GlobalKey<SliverReorderableListState>(); +/// +/// // ... +/// +/// @override +/// Widget build(BuildContext context) { +/// return SliverReorderableList( +/// key: listKey, +/// itemBuilder: (BuildContext context, int index) => const SizedBox(height: 10.0), +/// itemCount: 5, +/// onReorder: (int oldIndex, int newIndex) { +/// // ... +/// }, +/// ); +/// } +/// +/// // ... +/// +/// void _stop() { +/// listKey.currentState!.cancelReorder(); +/// } +/// ``` +/// +/// [ReorderableDragStartListener] and [ReorderableDelayedDragStartListener] +/// refer to their [SliverReorderableList] with the static +/// [SliverReorderableList.of] method. +class SliverReorderableListState extends State<SliverReorderableList> with TickerProviderStateMixin { + // Map of index -> child state used manage where the dragging item will need + // to be inserted. + final Map<int, _ReorderableItemState> _items = <int, _ReorderableItemState>{}; + + OverlayEntry? _overlayEntry; + int? _dragIndex; + _DragInfo? _dragInfo; + int? _insertIndex; + Offset? _finalDropPosition; + MultiDragGestureRecognizer? _recognizer; + int? _recognizerPointer; + // To implement the gap for the dragged item, we replace the dragged item + // with a zero sized box, and then translate all of the later items down + // by the size of the dragged item. This allows us to keep the order of the + // list, while still being able to animate the gap between the items. However + // for the first frame of the drag, the item has not yet been replaced, so + // the calculation for the gap is off by the size of the gap. This flag is + // used to determine if the transition to the zero sized box has completed, + // so the gap calculation can compensate for it. + bool _dragStartTransitionComplete = false; + + EdgeDraggingAutoScroller? _autoScroller; + + late ScrollableState _scrollable; + Axis get _scrollDirection => axisDirectionToAxis(_scrollable.axisDirection); + bool get _reverse => + _scrollable.axisDirection == AxisDirection.up || + _scrollable.axisDirection == AxisDirection.left; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _scrollable = Scrollable.of(context); + if (_autoScroller?.scrollable != _scrollable) { + _autoScroller?.stopAutoScroll(); + _autoScroller = EdgeDraggingAutoScroller( + _scrollable, + onScrollViewScrolled: _handleScrollableAutoScrolled, + velocityScalar: widget.autoScrollerVelocityScalar, + ); + } + } + + @override + void didUpdateWidget(covariant SliverReorderableList oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.itemCount != oldWidget.itemCount) { + cancelReorder(); + } + + if (widget.autoScrollerVelocityScalar != oldWidget.autoScrollerVelocityScalar) { + _autoScroller?.stopAutoScroll(); + _autoScroller = EdgeDraggingAutoScroller( + _scrollable, + onScrollViewScrolled: _handleScrollableAutoScrolled, + velocityScalar: widget.autoScrollerVelocityScalar, + ); + } + } + + @override + void dispose() { + _dragReset(); + _recognizer?.dispose(); + super.dispose(); + } + + /// Initiate the dragging of the item at [index] that was started with + /// the pointer down [event]. + /// + /// The given [recognizer] will be used to recognize and start the drag + /// item tracking and lead to either an item reorder, or a canceled drag. + /// + /// Most applications will not use this directly, but will wrap the item + /// (or part of the item, like a drag handle) in either a + /// [ReorderableDragStartListener] or [ReorderableDelayedDragStartListener] + /// which call this method when they detect the gesture that triggers a drag + /// start. + void startItemDragReorder({ + required int index, + required PointerDownEvent event, + required MultiDragGestureRecognizer recognizer, + }) { + assert(0 <= index && index < widget.itemCount); + setState(() { + if (_dragInfo != null) { + cancelReorder(); + } else if (_recognizer != null && _recognizerPointer != event.pointer) { + _recognizer!.dispose(); + _recognizer = null; + _recognizerPointer = null; + } + + if (_items.containsKey(index)) { + _dragIndex = index; + _recognizer = recognizer + ..onStart = _dragStart + ..addPointer(event); + _recognizerPointer = event.pointer; + } else { + // TODO(darrenaustin): Can we handle this better, maybe scroll to the item? + throw Exception('Attempting to start a drag on a non-visible item'); + } + }); + } + + /// Cancel any item drag in progress. + /// + /// This should be called before any major changes to the item list + /// occur so that any item drags will not get confused by + /// changes to the underlying list. + /// + /// If a drag operation is in progress, this will immediately reset + /// the list to back to its pre-drag state. + /// + /// If no drag is active, this will do nothing. + void cancelReorder() { + setState(() { + _dragReset(); + }); + } + + void _registerItem(_ReorderableItemState item) { + if (_dragInfo != null && _items[item.index] != item) { + item.updateForGap(_dragInfo!.index, _dragInfo!.itemExtent, false, _reverse); + } + _items[item.index] = item; + if (item.index == _dragInfo?.index) { + item.dragging = true; + item.rebuild(); + } + } + + void _unregisterItem(int index, _ReorderableItemState item) { + final _ReorderableItemState? currentItem = _items[index]; + if (currentItem == item) { + _items.remove(index); + } + } + + Drag? _dragStart(Offset position) { + assert(_dragInfo == null); + final _ReorderableItemState item = _items[_dragIndex!]!; + item.dragging = true; + widget.onReorderStart?.call(_dragIndex!); + item.rebuild(); + _dragStartTransitionComplete = false; + SchedulerBinding.instance.addPostFrameCallback((Duration duration) { + _dragStartTransitionComplete = true; + }, debugLabel: 'SliverReorderableList.completeDragStartTransition'); + + _insertIndex = item.index; + _dragInfo = _DragInfo( + item: item, + initialPosition: position, + scrollDirection: _scrollDirection, + onUpdate: _dragUpdate, + onCancel: _dragCancel, + onEnd: _dragEnd, + onDropCompleted: _dropCompleted, + proxyDecorator: widget.proxyDecorator, + tickerProvider: this, + ); + _dragInfo!.startDrag(); + + final OverlayState overlay = Overlay.of(context, debugRequiredFor: widget); + assert(_overlayEntry == null); + _overlayEntry = OverlayEntry(builder: _dragInfo!.createProxy); + overlay.insert(_overlayEntry!); + + for (final _ReorderableItemState childItem in _items.values) { + if (childItem == item || !childItem.mounted) { + continue; + } + childItem.updateForGap(_insertIndex!, _dragInfo!.itemExtent, false, _reverse); + } + return _dragInfo; + } + + void _dragUpdate(_DragInfo item, Offset position, Offset delta) { + setState(() { + _overlayEntry?.markNeedsBuild(); + _dragUpdateItems(); + _autoScroller?.startAutoScrollIfNecessary(_dragTargetRect); + }); + } + + void _dragCancel(_DragInfo item) { + setState(() { + _dragReset(); + }); + } + + void _dragEnd(_DragInfo item) { + setState(() { + if (_insertIndex == item.index) { + // Although it's at its original position, the original position has been replaced by a zero-size box + // So when reversed, it should offset its own extent + _finalDropPosition = _reverse ? _itemOffsetAt(_insertIndex!) - _extentOffset(item.itemExtent, _scrollDirection) : _itemOffsetAt(_insertIndex!); + } else if (_reverse) { + if (_insertIndex! >= _items.length) { + // Drop at the starting position of the last element and offset its own extent + _finalDropPosition = _itemOffsetAt(_items.length - 1) - _extentOffset(item.itemExtent, _scrollDirection); + } else { + // Drop at the end of the current element occupying the insert position + _finalDropPosition = _itemOffsetAt(_insertIndex!) + _extentOffset(_itemExtentAt(_insertIndex!), _scrollDirection); + } + } else { + if (_insertIndex! == 0) { + // Drop at the starting position of the first element and offset its own extent + _finalDropPosition = _itemOffsetAt(0) - _extentOffset(item.itemExtent, _scrollDirection); + } else { + // Drop at the end of the previous element occupying the insert position + final int atIndex = _insertIndex! - 1; + _finalDropPosition = _itemOffsetAt(atIndex) + _extentOffset(_itemExtentAt(atIndex), _scrollDirection); + } + } + }); + widget.onReorderEnd?.call(_insertIndex!); + } + + void _dropCompleted() { + final int fromIndex = _dragIndex!; + final int toIndex = _insertIndex!; + if (fromIndex != toIndex) { + widget.onReorder.call(fromIndex, toIndex); + } + setState(() { + _dragReset(); + }); + } + + void _dragReset() { + if (_dragInfo != null) { + if (_dragIndex != null && _items.containsKey(_dragIndex)) { + final _ReorderableItemState dragItem = _items[_dragIndex!]!; + dragItem._dragging = false; + dragItem.rebuild(); + _dragIndex = null; + } + _dragInfo?.dispose(); + _dragInfo = null; + _autoScroller?.stopAutoScroll(); + _resetItemGap(); + _recognizer?.dispose(); + _recognizer = null; + _overlayEntry?.remove(); + _overlayEntry?.dispose(); + _overlayEntry = null; + _finalDropPosition = null; + } + } + + void _resetItemGap() { + for (final _ReorderableItemState item in _items.values) { + item.resetGap(); + } + } + + void _handleScrollableAutoScrolled() { + if (_dragInfo == null) { + return; + } + _dragUpdateItems(); + // Continue scrolling if the drag is still in progress. + _autoScroller?.startAutoScrollIfNecessary(_dragTargetRect); + } + + void _dragUpdateItems() { + assert(_dragInfo != null); + final double gapExtent = _dragInfo!.itemExtent; + final double proxyItemStart = _offsetExtent(_dragInfo!.dragPosition - _dragInfo!.dragOffset, _scrollDirection); + final double proxyItemEnd = proxyItemStart + gapExtent; + + // Find the new index for inserting the item being dragged. + int newIndex = _insertIndex!; + for (final _ReorderableItemState item in _items.values) { + if (item.index == _dragIndex! || !item.mounted) { + continue; + } + + Rect geometry = item.targetGeometry(); + if (!_dragStartTransitionComplete && _dragIndex! <= item.index) { + // Transition is not complete, so each item after the dragged item is still + // in its normal location and not moved up for the zero sized box that will + // replace the dragged item. + final Offset transitionOffset = _extentOffset(_reverse ? -gapExtent : gapExtent, _scrollDirection); + geometry = (geometry.topLeft - transitionOffset) & geometry.size; + } + final double itemStart = _scrollDirection == Axis.vertical ? geometry.top : geometry.left; + final double itemExtent = _scrollDirection == Axis.vertical ? geometry.height : geometry.width; + final double itemEnd = itemStart + itemExtent; + final double itemMiddle = itemStart + itemExtent / 2; + + if (_reverse) { + if (itemEnd >= proxyItemEnd && proxyItemEnd >= itemMiddle) { + // The start of the proxy is in the beginning half of the item, so + // we should swap the item with the gap and we are done looking for + // the new index. + newIndex = item.index; + break; + + } else if (itemMiddle >= proxyItemStart && proxyItemStart >= itemStart) { + // The end of the proxy is in the ending half of the item, so + // we should swap the item with the gap and we are done looking for + // the new index. + newIndex = item.index + 1; + break; + + } else if (itemStart > proxyItemEnd && newIndex < (item.index + 1)) { + newIndex = item.index + 1; + } else if (proxyItemStart > itemEnd && newIndex > item.index) { + newIndex = item.index; + } + } else { + if (itemStart <= proxyItemStart && proxyItemStart <= itemMiddle) { + // The start of the proxy is in the beginning half of the item, so + // we should swap the item with the gap and we are done looking for + // the new index. + newIndex = item.index; + break; + + } else if (itemMiddle <= proxyItemEnd && proxyItemEnd <= itemEnd) { + // The end of the proxy is in the ending half of the item, so + // we should swap the item with the gap and we are done looking for + // the new index. + newIndex = item.index + 1; + break; + + } else if (itemEnd < proxyItemStart && newIndex < (item.index + 1)) { + newIndex = item.index + 1; + } else if (proxyItemEnd < itemStart && newIndex > item.index) { + newIndex = item.index; + } + } + } + + if (newIndex != _insertIndex) { + _insertIndex = newIndex; + for (final _ReorderableItemState item in _items.values) { + if (item.index == _dragIndex! || !item.mounted) { + continue; + } + item.updateForGap(newIndex, gapExtent, true, _reverse); + } + } + } + + Rect get _dragTargetRect { + final Offset origin = _dragInfo!.dragPosition - _dragInfo!.dragOffset; + return Rect.fromLTWH(origin.dx, origin.dy, _dragInfo!.itemSize.width, _dragInfo!.itemSize.height); + } + + Offset _itemOffsetAt(int index) { + return _items[index]!.targetGeometry().topLeft; + } + + double _itemExtentAt(int index) { + return _sizeExtent(_items[index]!.targetGeometry().size, _scrollDirection); + } + + Widget _itemBuilder(BuildContext context, int index) { + if (_dragInfo != null && index >= widget.itemCount) { + switch (_scrollDirection) { + case Axis.horizontal: + return SizedBox(width: _dragInfo!.itemExtent); + case Axis.vertical: + return SizedBox(height: _dragInfo!.itemExtent); + } + } + final Widget child = widget.itemBuilder(context, index); + assert(child.key != null, 'All list items must have a key'); + final OverlayState overlay = Overlay.of(context, debugRequiredFor: widget); + return _ReorderableItem( + key: _ReorderableItemGlobalKey(child.key!, index, this), + index: index, + capturedThemes: InheritedTheme.capture(from: context, to: overlay.context), + child: _wrapWithSemantics(child, index), + ); + } + + Widget _wrapWithSemantics(Widget child, int index) { + void reorder(int startIndex, int endIndex) { + if (startIndex != endIndex) { + widget.onReorder(startIndex, endIndex); + } + } + + // First, determine which semantics actions apply. + final Map<CustomSemanticsAction, VoidCallback> semanticsActions = <CustomSemanticsAction, VoidCallback>{}; + + // Create the appropriate semantics actions. + void moveToStart() => reorder(index, 0); + void moveToEnd() => reorder(index, widget.itemCount); + void moveBefore() => reorder(index, index - 1); + // To move after, go to index+2 because it is moved to the space + // before index+2, which is after the space at index+1. + void moveAfter() => reorder(index, index + 2); + + final WidgetsLocalizations localizations = WidgetsLocalizations.of(context); + final bool isHorizontal = _scrollDirection == Axis.horizontal; + // If the item can move to before its current position in the list. + if (index > 0) { + semanticsActions[CustomSemanticsAction(label: localizations.reorderItemToStart)] = moveToStart; + String reorderItemBefore = localizations.reorderItemUp; + if (isHorizontal) { + reorderItemBefore = Directionality.of(context) == TextDirection.ltr + ? localizations.reorderItemLeft + : localizations.reorderItemRight; + } + semanticsActions[CustomSemanticsAction(label: reorderItemBefore)] = moveBefore; + } + + // If the item can move to after its current position in the list. + if (index < widget.itemCount - 1) { + String reorderItemAfter = localizations.reorderItemDown; + if (isHorizontal) { + reorderItemAfter = Directionality.of(context) == TextDirection.ltr + ? localizations.reorderItemRight + : localizations.reorderItemLeft; + } + semanticsActions[CustomSemanticsAction(label: reorderItemAfter)] = moveAfter; + semanticsActions[CustomSemanticsAction(label: localizations.reorderItemToEnd)] = moveToEnd; + } + + // Pass toWrap with a GlobalKey into the item so that when it + // gets dragged, the accessibility framework can preserve the selected + // state of the dragging item. + // + // Also apply the relevant custom accessibility actions for moving the item + // up, down, to the start, and to the end of the list. + return Semantics( + container: true, + customSemanticsActions: semanticsActions, + child: child, + ); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasOverlay(context)); + final SliverChildBuilderDelegate childrenDelegate = SliverChildBuilderDelegate( + _itemBuilder, + // When dragging, the dragged item is still in the list but has been replaced + // by a zero height SizedBox, so that the gap can move around. To make the + // list extent stable we add a dummy entry to the end. + childCount: widget.itemCount + (_dragInfo != null ? 1 : 0), + findChildIndexCallback: widget.findChildIndexCallback, + ); + if (widget.itemExtent != null) { + return SliverFixedExtentList( + delegate: childrenDelegate, + itemExtent: widget.itemExtent!, + ); + } else if (widget.itemExtentBuilder != null) { + return SliverVariedExtentList( + delegate: childrenDelegate, + itemExtentBuilder: widget.itemExtentBuilder!, + ); + } else if (widget.prototypeItem != null) { + return SliverPrototypeExtentList( + delegate: childrenDelegate, + prototypeItem: widget.prototypeItem!, + ); + } + return SliverList(delegate: childrenDelegate); + } +} + +class _ReorderableItem extends StatefulWidget { + const _ReorderableItem({ + required Key key, + required this.index, + required this.child, + required this.capturedThemes, + }) : super(key: key); + + final int index; + final Widget child; + final CapturedThemes capturedThemes; + + @override + _ReorderableItemState createState() => _ReorderableItemState(); +} + +class _ReorderableItemState extends State<_ReorderableItem> { + late SliverReorderableListState _listState; + + Offset _startOffset = Offset.zero; + Offset _targetOffset = Offset.zero; + AnimationController? _offsetAnimation; + + Key get key => widget.key!; + int get index => widget.index; + + bool get dragging => _dragging; + set dragging(bool dragging) { + if (mounted) { + setState(() { + _dragging = dragging; + }); + } + } + bool _dragging = false; + + @override + void initState() { + _listState = SliverReorderableList.of(context); + _listState._registerItem(this); + super.initState(); + } + + @override + void dispose() { + _offsetAnimation?.dispose(); + _listState._unregisterItem(index, this); + super.dispose(); + } + + @override + void didUpdateWidget(covariant _ReorderableItem oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.index != widget.index) { + _listState._unregisterItem(oldWidget.index, this); + _listState._registerItem(this); + } + } + + @override + Widget build(BuildContext context) { + if (_dragging) { + return const SizedBox(); + } + _listState._registerItem(this); + return Transform( + transform: Matrix4.translationValues(offset.dx, offset.dy, 0.0), + child: widget.child, + ); + } + + @override + void deactivate() { + _listState._unregisterItem(index, this); + super.deactivate(); + } + + Offset get offset { + if (_offsetAnimation != null) { + final double animValue = Curves.easeInOut.transform(_offsetAnimation!.value); + return Offset.lerp(_startOffset, _targetOffset, animValue)!; + } + return _targetOffset; + } + + void updateForGap(int gapIndex, double gapExtent, bool animate, bool reverse) { + final Offset newTargetOffset = (gapIndex <= index) + ? _extentOffset(reverse ? -gapExtent : gapExtent, _listState._scrollDirection) + : Offset.zero; + if (newTargetOffset != _targetOffset) { + _targetOffset = newTargetOffset; + if (animate) { + if (_offsetAnimation == null) { + _offsetAnimation = AnimationController( + vsync: _listState, + duration: const Duration(milliseconds: 250), + ) + ..addListener(rebuild) + ..addStatusListener((AnimationStatus status) { + if (status == AnimationStatus.completed) { + _startOffset = _targetOffset; + _offsetAnimation!.dispose(); + _offsetAnimation = null; + } + }) + ..forward(); + } else { + _startOffset = offset; + _offsetAnimation!.forward(from: 0.0); + } + } else { + if (_offsetAnimation != null) { + _offsetAnimation!.dispose(); + _offsetAnimation = null; + } + _startOffset = _targetOffset; + } + rebuild(); + } + } + + void resetGap() { + if (_offsetAnimation != null) { + _offsetAnimation!.dispose(); + _offsetAnimation = null; + } + _startOffset = Offset.zero; + _targetOffset = Offset.zero; + rebuild(); + } + + Rect targetGeometry() { + final RenderBox itemRenderBox = context.findRenderObject()! as RenderBox; + final Offset itemPosition = itemRenderBox.localToGlobal(Offset.zero) + _targetOffset; + return itemPosition & itemRenderBox.size; + } + + void rebuild() { + if (mounted) { + setState(() {}); + } + } +} + +/// A wrapper widget that will recognize the start of a drag on the wrapped +/// widget by a [PointerDownEvent], and immediately initiate dragging the +/// wrapped item to a new location in a reorderable list. +/// +/// See also: +/// +/// * [ReorderableDelayedDragStartListener], a similar wrapper that will +/// only recognize the start after a long press event. +/// * [ReorderableList], a widget list that allows the user to reorder +/// its items. +/// * [SliverReorderableList], a sliver list that allows the user to reorder +/// its items. +/// * [ReorderableListView], a Material Design list that allows the user to +/// reorder its items. +class ReorderableDragStartListener extends StatelessWidget { + /// Creates a listener for a drag immediately following a pointer down + /// event over the given child widget. + /// + /// This is most commonly used to wrap part of a list item like a drag + /// handle. + const ReorderableDragStartListener({ + super.key, + required this.child, + required this.index, + this.enabled = true, + }); + + /// The widget for which the application would like to respond to a tap and + /// drag gesture by starting a reordering drag on a reorderable list. + final Widget child; + + /// The index of the associated item that will be dragged in the list. + final int index; + + /// Whether the [child] item can be dragged and moved in the list. + /// + /// If true, the item can be moved to another location in the list when the + /// user taps on the child. If false, tapping on the child will be ignored. + final bool enabled; + + @override + Widget build(BuildContext context) { + return Listener( + onPointerDown: enabled ? (PointerDownEvent event) => _startDragging(context, event) : null, + child: child, + ); + } + + /// Provides the gesture recognizer used to indicate the start of a reordering + /// drag operation. + /// + /// By default this returns an [ImmediateMultiDragGestureRecognizer] but + /// subclasses can use this to customize the drag start gesture. + @protected + MultiDragGestureRecognizer createRecognizer() { + return ImmediateMultiDragGestureRecognizer(debugOwner: this); + } + + void _startDragging(BuildContext context, PointerDownEvent event) { + final DeviceGestureSettings? gestureSettings = MediaQuery.maybeGestureSettingsOf(context); + final SliverReorderableListState? list = SliverReorderableList.maybeOf(context); + list?.startItemDragReorder( + index: index, + event: event, + recognizer: createRecognizer() + ..gestureSettings = gestureSettings, + ); + } +} + +/// A wrapper widget that will recognize the start of a drag operation by +/// looking for a long press event. Once it is recognized, it will start +/// a drag operation on the wrapped item in the reorderable list. +/// +/// See also: +/// +/// * [ReorderableDragStartListener], a similar wrapper that will +/// recognize the start of the drag immediately after a pointer down event. +/// * [ReorderableList], a widget list that allows the user to reorder +/// its items. +/// * [SliverReorderableList], a sliver list that allows the user to reorder +/// its items. +/// * [ReorderableListView], a Material Design list that allows the user to +/// reorder its items. +class ReorderableDelayedDragStartListener extends ReorderableDragStartListener { + /// Creates a listener for an drag following a long press event over the + /// given child widget. + /// + /// This is most commonly used to wrap an entire list item in a reorderable + /// list. + const ReorderableDelayedDragStartListener({ + super.key, + required super.child, + required super.index, + super.enabled, + }); + + @override + MultiDragGestureRecognizer createRecognizer() { + return DelayedMultiDragGestureRecognizer(debugOwner: this); + } +} + +typedef _DragItemUpdate = void Function(_DragInfo item, Offset position, Offset delta); +typedef _DragItemCallback = void Function(_DragInfo item); + +class _DragInfo extends Drag { + _DragInfo({ + required _ReorderableItemState item, + Offset initialPosition = Offset.zero, + this.scrollDirection = Axis.vertical, + this.onUpdate, + this.onEnd, + this.onCancel, + this.onDropCompleted, + this.proxyDecorator, + required this.tickerProvider, + }) { + final RenderBox itemRenderBox = item.context.findRenderObject()! as RenderBox; + listState = item._listState; + index = item.index; + child = item.widget.child; + capturedThemes = item.widget.capturedThemes; + dragPosition = initialPosition; + dragOffset = itemRenderBox.globalToLocal(initialPosition); + itemSize = item.context.size!; + itemExtent = _sizeExtent(itemSize, scrollDirection); + scrollable = Scrollable.of(item.context); + } + + final Axis scrollDirection; + final _DragItemUpdate? onUpdate; + final _DragItemCallback? onEnd; + final _DragItemCallback? onCancel; + final VoidCallback? onDropCompleted; + final ReorderItemProxyDecorator? proxyDecorator; + final TickerProvider tickerProvider; + + late SliverReorderableListState listState; + late int index; + late Widget child; + late Offset dragPosition; + late Offset dragOffset; + late Size itemSize; + late double itemExtent; + late CapturedThemes capturedThemes; + ScrollableState? scrollable; + AnimationController? _proxyAnimation; + + void dispose() { + _proxyAnimation?.dispose(); + } + + void startDrag() { + _proxyAnimation = AnimationController( + vsync: tickerProvider, + duration: const Duration(milliseconds: 250), + ) + ..addStatusListener((AnimationStatus status) { + if (status == AnimationStatus.dismissed) { + _dropCompleted(); + } + }) + ..forward(); + } + + @override + void update(DragUpdateDetails details) { + final Offset delta = _restrictAxis(details.delta, scrollDirection); + dragPosition += delta; + onUpdate?.call(this, dragPosition, details.delta); + } + + @override + void end(DragEndDetails details) { + _proxyAnimation!.reverse(); + onEnd?.call(this); + } + + @override + void cancel() { + _proxyAnimation?.dispose(); + _proxyAnimation = null; + onCancel?.call(this); + } + + void _dropCompleted() { + _proxyAnimation?.dispose(); + _proxyAnimation = null; + onDropCompleted?.call(); + } + + Widget createProxy(BuildContext context) { + return capturedThemes.wrap( + _DragItemProxy( + listState: listState, + index: index, + size: itemSize, + animation: _proxyAnimation!, + position: dragPosition - dragOffset - _overlayOrigin(context), + proxyDecorator: proxyDecorator, + child: child, + ), + ); + } +} + +Offset _overlayOrigin(BuildContext context) { + final OverlayState overlay = Overlay.of(context, debugRequiredFor: context.widget); + final RenderBox overlayBox = overlay.context.findRenderObject()! as RenderBox; + return overlayBox.localToGlobal(Offset.zero); +} + +class _DragItemProxy extends StatelessWidget { + const _DragItemProxy({ + required this.listState, + required this.index, + required this.child, + required this.position, + required this.size, + required this.animation, + required this.proxyDecorator, + }); + + final SliverReorderableListState listState; + final int index; + final Widget child; + final Offset position; + final Size size; + final AnimationController animation; + final ReorderItemProxyDecorator? proxyDecorator; + + @override + Widget build(BuildContext context) { + final Widget proxyChild = proxyDecorator?.call(child, index, animation.view) ?? child; + final Offset overlayOrigin = _overlayOrigin(context); + + return MediaQuery( + // Remove the top padding so that any nested list views in the item + // won't pick up the scaffold's padding in the overlay. + data: MediaQuery.of(context).removePadding(removeTop: true), + child: AnimatedBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + Offset effectivePosition = position; + final Offset? dropPosition = listState._finalDropPosition; + if (dropPosition != null) { + effectivePosition = Offset.lerp(dropPosition - overlayOrigin, effectivePosition, Curves.easeOut.transform(animation.value))!; + } + return Positioned( + left: effectivePosition.dx, + top: effectivePosition.dy, + child: SizedBox( + width: size.width, + height: size.height, + child: child, + ), + ); + }, + child: proxyChild, + ), + ); + } +} + +double _sizeExtent(Size size, Axis scrollDirection) { + switch (scrollDirection) { + case Axis.horizontal: + return size.width; + case Axis.vertical: + return size.height; + } +} + +double _offsetExtent(Offset offset, Axis scrollDirection) { + switch (scrollDirection) { + case Axis.horizontal: + return offset.dx; + case Axis.vertical: + return offset.dy; + } +} + +Offset _extentOffset(double extent, Axis scrollDirection) { + switch (scrollDirection) { + case Axis.horizontal: + return Offset(extent, 0.0); + case Axis.vertical: + return Offset(0.0, extent); + } +} + +Offset _restrictAxis(Offset offset, Axis scrollDirection) { + switch (scrollDirection) { + case Axis.horizontal: + return Offset(offset.dx, 0.0); + case Axis.vertical: + return Offset(0.0, offset.dy); + } +} + +// A global key that takes its identity from the object and uses a value of a +// particular type to identify itself. +// +// The difference with GlobalObjectKey is that it uses [==] instead of [identical] +// of the objects used to generate widgets. +@optionalTypeArgs +class _ReorderableItemGlobalKey extends GlobalObjectKey { + + const _ReorderableItemGlobalKey(this.subKey, this.index, this.state) : super(subKey); + + final Key subKey; + final int index; + final SliverReorderableListState state; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _ReorderableItemGlobalKey + && other.subKey == subKey + && other.index == index + && other.state == state; + } + + @override + int get hashCode => Object.hash(subKey, index, state); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/restoration.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/restoration.dart new file mode 100644 index 0000000000000000000000000000000000000000..7f532552c008a8c631bdfd9ceec3214ade0856d0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/restoration.dart @@ -0,0 +1,1020 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; + +import 'basic.dart'; +import 'framework.dart'; + +export 'package:flutter/services.dart' show RestorationBucket; + +/// Creates a new scope for restoration IDs used by descendant widgets to claim +/// [RestorationBucket]s. +/// +/// {@template flutter.widgets.RestorationScope} +/// A restoration scope inserts a [RestorationBucket] into the widget tree, +/// which descendant widgets can access via [RestorationScope.of]. It is +/// uncommon for descendants to directly store data in this bucket. Instead, +/// descendant widgets should consider storing their own restoration data in a +/// child bucket claimed with [RestorationBucket.claimChild] from the bucket +/// provided by this scope. +/// {@endtemplate} +/// +/// The bucket inserted into the widget tree by this scope has been claimed from +/// the surrounding [RestorationScope] using the provided [restorationId]. If +/// the [RestorationScope] is moved to a different part of the widget tree under +/// a different [RestorationScope], the bucket owned by this scope with all its +/// children and the data contained in them is moved to the new scope as well. +/// +/// This widget will not make a [RestorationBucket] available to descendants if +/// [restorationId] is null or when there is no surrounding restoration scope to +/// claim a bucket from. In this case, descendant widgets invoking +/// [RestorationScope.of] will receive null as a return value indicating that no +/// bucket is available for storing restoration data. This will turn off state +/// restoration for the widget subtree. +/// +/// See also: +/// +/// * [RootRestorationScope], which inserts the root bucket provided by +/// the [RestorationManager] into the widget tree and makes it accessible +/// for descendants via [RestorationScope.of]. +/// * [UnmanagedRestorationScope], which inserts a provided [RestorationBucket] +/// into the widget tree and makes it accessible for descendants via +/// [RestorationScope.of]. +/// * [RestorationMixin], which may be used in [State] objects to manage the +/// restoration data of a [StatefulWidget] instead of manually interacting +/// with [RestorationScope]s and [RestorationBucket]s. +/// * [RestorationManager], which describes the basic concepts of state +/// restoration in Flutter. +class RestorationScope extends StatefulWidget { + /// Creates a [RestorationScope]. + /// + /// Providing null as the [restorationId] turns off state restoration for + /// the [child] and its descendants. + const RestorationScope({ + super.key, + required this.restorationId, + required this.child, + }); + + /// Returns the [RestorationBucket] inserted into the widget tree by the + /// closest ancestor [RestorationScope] of `context`. + /// + /// {@template flutter.widgets.restoration.RestorationScope.bucket_warning} + /// To avoid accidentally overwriting data already stored in the bucket by its + /// owner, data should not be stored directly in the bucket returned by this + /// method. Instead, consider claiming a child bucket from the returned bucket + /// (via [RestorationBucket.claimChild]) and store the restoration data in + /// that child. + /// {@endtemplate} + /// + /// This method returns null if state restoration is turned off for this + /// subtree. + /// + /// Calling this method will create a dependency on the closest + /// [RestorationScope] in the [context], if there is one. + /// + /// See also: + /// + /// * [RestorationScope.maybeOf], which is similar to this method, but asserts + /// if no [RestorationScope] ancestor is found. + static RestorationBucket? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<UnmanagedRestorationScope>()?.bucket; + } + + /// Returns the [RestorationBucket] inserted into the widget tree by the + /// closest ancestor [RestorationScope] of `context`. + /// + /// {@macro flutter.widgets.restoration.RestorationScope.bucket_warning} + /// + /// This method will assert in debug mode and throw an exception in release + /// mode if state restoration is turned off for this subtree. + /// + /// Calling this method will create a dependency on the closest + /// [RestorationScope] in the [context]. + /// + /// See also: + /// + /// * [RestorationScope.maybeOf], which is similar to this method, but returns + /// null if no [RestorationScope] ancestor is found. + static RestorationBucket of(BuildContext context) { + final RestorationBucket? bucket = maybeOf(context); + assert(() { + if (bucket == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'RestorationScope.of() was called with a context that does not ' + 'contain a RestorationScope widget. ' + ), + ErrorDescription( + 'No RestorationScope widget ancestor could be found starting from ' + 'the context that was passed to RestorationScope.of(). This can ' + 'happen because you are using a widget that looks for a ' + 'RestorationScope ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context' + ), + ErrorHint( + 'State restoration must be enabled for a RestorationScope to exist. ' + 'This can be done by passing a restorationScopeId to MaterialApp, ' + 'CupertinoApp, or WidgetsApp at the root of the widget tree or by ' + 'wrapping the widget tree in a RootRestorationScope.' + ), + ], + ); + } + return true; + }()); + return bucket!; + } + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The restoration ID used by this widget to obtain a child bucket from the + /// surrounding [RestorationScope]. + /// + /// The child bucket obtained from the surrounding scope is made available to + /// descendant widgets via [RestorationScope.of]. + /// + /// If this is null, [RestorationScope.of] invoked by descendants will return + /// null which effectively turns off state restoration for this subtree. + final String? restorationId; + + @override + State<RestorationScope> createState() => _RestorationScopeState(); +} + +class _RestorationScopeState extends State<RestorationScope> with RestorationMixin { + @override + String? get restorationId => widget.restorationId; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + // Nothing to do. + // The bucket gets injected into the widget tree in the build method. + } + + @override + Widget build(BuildContext context) { + return UnmanagedRestorationScope( + bucket: bucket, // `bucket` is provided by the RestorationMixin. + child: widget.child, + ); + } +} + +/// Inserts a provided [RestorationBucket] into the widget tree and makes it +/// available to descendants via [RestorationScope.of]. +/// +/// {@macro flutter.widgets.RestorationScope} +/// +/// If [bucket] is null, no restoration bucket is made available to descendant +/// widgets ([RestorationScope.of] invoked from a descendant will return null). +/// This effectively turns off state restoration for the subtree because no +/// bucket for storing restoration data is made available. +/// +/// See also: +/// +/// * [RestorationScope], which inserts a bucket obtained from a surrounding +/// restoration scope into the widget tree and makes it accessible +/// for descendants via [RestorationScope.of]. +/// * [RootRestorationScope], which inserts the root bucket provided by +/// the [RestorationManager] into the widget tree and makes it accessible +/// for descendants via [RestorationScope.of]. +/// * [RestorationMixin], which may be used in [State] objects to manage the +/// restoration data of a [StatefulWidget] instead of manually interacting +/// with [RestorationScope]s and [RestorationBucket]s. +/// * [RestorationManager], which describes the basic concepts of state +/// restoration in Flutter. +class UnmanagedRestorationScope extends InheritedWidget { + /// Creates an [UnmanagedRestorationScope]. + /// + /// When [bucket] is null state restoration is turned off for the [child] and + /// its descendants. + const UnmanagedRestorationScope({ + super.key, + this.bucket, + required super.child, + }); + + /// The [RestorationBucket] that this widget will insert into the widget tree. + /// + /// Descendant widgets may obtain this bucket via [RestorationScope.of]. + final RestorationBucket? bucket; + + @override + bool updateShouldNotify(UnmanagedRestorationScope oldWidget) { + return oldWidget.bucket != bucket; + } +} + +/// Inserts a child bucket of [RestorationManager.rootBucket] into the widget +/// tree and makes it available to descendants via [RestorationScope.of]. +/// +/// This widget is usually used near the root of the widget tree to enable the +/// state restoration functionality for the application. For all other use +/// cases, consider using a regular [RestorationScope] instead. +/// +/// The root restoration bucket can only be retrieved asynchronously from the +/// [RestorationManager]. To ensure that the provided [child] has its +/// restoration data available the first time it builds, the +/// [RootRestorationScope] will build an empty [Container] instead of the actual +/// [child] until the root bucket is available. To hide the empty container from +/// the eyes of users, the [RootRestorationScope] also delays rendering the +/// first frame while the container is shown. On platforms that show a splash +/// screen on app launch the splash screen is kept up (hiding the empty +/// container) until the bucket is available and the [child] is ready to be +/// build. +/// +/// The exact behavior of this widget depends on its ancestors: When the +/// [RootRestorationScope] does not find an ancestor restoration bucket via +/// [RestorationScope.of] it will claim a child bucket from the root restoration +/// bucket ([RestorationManager.rootBucket]) using the provided [restorationId] +/// and inserts that bucket into the widget tree where descendants may access it +/// via [RestorationScope.of]. If the [RootRestorationScope] finds a non-null +/// ancestor restoration bucket via [RestorationScope.of] it will behave like a +/// regular [RestorationScope] instead: It will claim a child bucket from that +/// ancestor and insert that child into the widget tree. +/// +/// Unlike the [RestorationScope] widget, the [RootRestorationScope] will +/// guarantee that descendants have a bucket available for storing restoration +/// data as long as [restorationId] is not null and [RestorationManager] is +/// able to provide a root bucket. In other words, it will force-enable +/// state restoration for the subtree if [restorationId] is not null. +/// +/// If [restorationId] is null, no bucket is made available to descendants, +/// which effectively turns off state restoration for this subtree. +/// +/// See also: +/// +/// * [RestorationScope], which inserts a bucket obtained from a surrounding +/// restoration scope into the widget tree and makes it accessible +/// for descendants via [RestorationScope.of]. +/// * [UnmanagedRestorationScope], which inserts a provided [RestorationBucket] +/// into the widget tree and makes it accessible for descendants via +/// [RestorationScope.of]. +/// * [RestorationMixin], which may be used in [State] objects to manage the +/// restoration data of a [StatefulWidget] instead of manually interacting +/// with [RestorationScope]s and [RestorationBucket]s. +/// * [RestorationManager], which describes the basic concepts of state +/// restoration in Flutter. +class RootRestorationScope extends StatefulWidget { + /// Creates a [RootRestorationScope]. + /// + /// Providing null as the [restorationId] turns off state restoration for + /// the [child] and its descendants. + const RootRestorationScope({ + super.key, + required this.restorationId, + required this.child, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The restoration ID used to identify the child bucket that this widget + /// will insert into the tree. + /// + /// If this is null, no bucket is made available to descendants and state + /// restoration for the subtree is essentially turned off. + final String? restorationId; + + @override + State<RootRestorationScope> createState() => _RootRestorationScopeState(); +} + +class _RootRestorationScopeState extends State<RootRestorationScope> { + bool? _okToRenderBlankContainer; + bool _rootBucketValid = false; + RestorationBucket? _rootBucket; + RestorationBucket? _ancestorBucket; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _ancestorBucket = RestorationScope.maybeOf(context); + _loadRootBucketIfNecessary(); + _okToRenderBlankContainer ??= widget.restorationId != null && _needsRootBucketInserted; + } + + @override + void didUpdateWidget(RootRestorationScope oldWidget) { + super.didUpdateWidget(oldWidget); + _loadRootBucketIfNecessary(); + } + + bool get _needsRootBucketInserted => _ancestorBucket == null; + + bool get _isWaitingForRootBucket { + return widget.restorationId != null && _needsRootBucketInserted && !_rootBucketValid; + } + + bool _isLoadingRootBucket = false; + + void _loadRootBucketIfNecessary() { + if (_isWaitingForRootBucket && !_isLoadingRootBucket) { + _isLoadingRootBucket = true; + RendererBinding.instance.deferFirstFrame(); + ServicesBinding.instance.restorationManager.rootBucket.then((RestorationBucket? bucket) { + _isLoadingRootBucket = false; + if (mounted) { + ServicesBinding.instance.restorationManager.addListener(_replaceRootBucket); + setState(() { + _rootBucket = bucket; + _rootBucketValid = true; + _okToRenderBlankContainer = false; + }); + } + RendererBinding.instance.allowFirstFrame(); + }); + } + } + + void _replaceRootBucket() { + _rootBucketValid = false; + _rootBucket = null; + ServicesBinding.instance.restorationManager.removeListener(_replaceRootBucket); + _loadRootBucketIfNecessary(); + assert(!_isWaitingForRootBucket); // Ensure that load finished synchronously. + } + + @override + void dispose() { + if (_rootBucketValid) { + ServicesBinding.instance.restorationManager.removeListener(_replaceRootBucket); + } + super.dispose(); + } + + @override + Widget build(BuildContext context) { + if (_okToRenderBlankContainer! && _isWaitingForRootBucket) { + return const SizedBox.shrink(); + } + + return UnmanagedRestorationScope( + bucket: _ancestorBucket ?? _rootBucket, + child: RestorationScope( + restorationId: widget.restorationId, + child: widget.child, + ), + ); + } +} + +/// Manages an object of type `T`, whose value a [State] object wants to have +/// restored during state restoration. +/// +/// The property wraps an object of type `T`. It knows how to store its value in +/// the restoration data and it knows how to re-instantiate that object from the +/// information it previously stored in the restoration data. +/// +/// The knowledge of how to store the wrapped object in the restoration data is +/// encoded in the [toPrimitives] method and the knowledge of how to +/// re-instantiate the object from that data is encoded in the [fromPrimitives] +/// method. A call to [toPrimitives] must return a representation of the wrapped +/// object that can be serialized with the [StandardMessageCodec]. If any +/// collections (e.g. [List]s, [Map]s, etc.) are returned, they must not be +/// modified after they have been returned from [toPrimitives]. At a later point +/// in time (which may be after the application restarted), the data obtained +/// from [toPrimitives] may be handed back to the property's [fromPrimitives] +/// method to restore it to the previous state described by that data. +/// +/// A [RestorableProperty] needs to be registered to a [RestorationMixin] using +/// a restoration ID that is unique within the mixin. The [RestorationMixin] +/// provides and manages the [RestorationBucket], in which the data returned by +/// [toPrimitives] is stored. +/// +/// Whenever the value returned by [toPrimitives] (or the [enabled] getter) +/// changes, the [RestorableProperty] must call [notifyListeners]. This will +/// trigger the [RestorationMixin] to update the data it has stored for the +/// property in its [RestorationBucket] to the latest information returned by +/// [toPrimitives]. +/// +/// When the property is registered with the [RestorationMixin], the mixin +/// checks whether there is any restoration data available for the property. If +/// data is available, the mixin calls [fromPrimitives] on the property, which +/// must return an object that matches the object the property wrapped when the +/// provided restoration data was obtained from [toPrimitives]. If no +/// restoration data is available to restore the property's wrapped object from, +/// the mixin calls [createDefaultValue]. The value returned by either of those +/// methods is then handed to the property's [initWithValue] method. +/// +/// Usually, subclasses of [RestorableProperty] hold on to the value provided to +/// them in [initWithValue] and make it accessible to the [State] object that +/// owns the property. This [RestorableProperty] base class, however, has no +/// opinion about what to do with the value provided to [initWithValue]. +/// +/// The [RestorationMixin] may call [fromPrimitives]/[createDefaultValue] +/// followed by [initWithValue] multiple times throughout the life of a +/// [RestorableProperty]: Whenever new restoration data is made available to the +/// [RestorationMixin] the property is registered with, the cycle of calling +/// [fromPrimitives] (if the new restoration data contains information to +/// restore the property from) or [createDefaultValue] (if no information for +/// the property is available in the new restoration data) followed by a call to +/// [initWithValue] repeats. Whenever [initWithValue] is called, the property +/// should forget the old value it was wrapping and re-initialize itself with +/// the newly provided value. +/// +/// In a typical use case, a subclass of [RestorableProperty] is instantiated +/// either to initialize a member variable of a [State] object or within +/// [State.initState]. It is then registered to a [RestorationMixin] in +/// [RestorationMixin.restoreState] and later [dispose]ed in [State.dispose]. +/// For less common use cases (e.g. if the value stored in a +/// [RestorableProperty] is only needed while the [State] object is in a certain +/// state), a [RestorableProperty] may be registered with a [RestorationMixin] +/// any time after [RestorationMixin.restoreState] has been called for the first +/// time. A [RestorableProperty] may also be unregistered from a +/// [RestorationMixin] before the owning [State] object is disposed by calling +/// [RestorationMixin.unregisterFromRestoration]. This is uncommon, though, and +/// will delete the information that the property contributed from the +/// restoration data (meaning the value of the property will no longer be +/// restored during a future state restoration). +/// +/// See also: +/// +/// * [RestorableValue], which is a [RestorableProperty] that makes the wrapped +/// value accessible to the owning [State] object via a `value` +/// getter and setter. +/// * [RestorationMixin], to which a [RestorableProperty] must be registered. +/// * [RestorationManager], which describes how state restoration works in +/// Flutter. +abstract class RestorableProperty<T> extends ChangeNotifier { + /// Creates a [RestorableProperty]. + RestorableProperty(){ + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + /// Called by the [RestorationMixin] if no restoration data is available to + /// restore the value of the property from to obtain the default value for the + /// property. + /// + /// The method returns the default value that the property should wrap if no + /// restoration data is available. After this is called, [initWithValue] will + /// be called with this method's return value. + /// + /// The method may be called multiple times throughout the life of the + /// [RestorableProperty]. Whenever new restoration data has been provided to + /// the [RestorationMixin] the property is registered to, either this method + /// or [fromPrimitives] is called before [initWithValue] is invoked. + T createDefaultValue(); + + /// Called by the [RestorationMixin] to convert the `data` previously + /// retrieved from [toPrimitives] back into an object of type `T` that this + /// property should wrap. + /// + /// The object returned by this method is passed to [initWithValue] to restore + /// the value that this property is wrapping to the value described by the + /// provided `data`. + /// + /// The method may be called multiple times throughout the life of the + /// [RestorableProperty]. Whenever new restoration data has been provided to + /// the [RestorationMixin] the property is registered to, either this method + /// or [createDefaultValue] is called before [initWithValue] is invoked. + T fromPrimitives(Object? data); + + /// Called by the [RestorationMixin] with the `value` returned by either + /// [createDefaultValue] or [fromPrimitives] to set the value that this + /// property currently wraps. + /// + /// The [initWithValue] method may be called multiple times throughout the + /// life of the [RestorableProperty] whenever new restoration data has been + /// provided to the [RestorationMixin] the property is registered to. When + /// [initWithValue] is called, the property should forget its previous value + /// and re-initialize itself to the newly provided `value`. + void initWithValue(T value); + + /// Called by the [RestorationMixin] to retrieve the information that this + /// property wants to store in the restoration data. + /// + /// The returned object must be serializable with the [StandardMessageCodec] + /// and if it includes any collections, those should not be modified after + /// they have been returned by this method. + /// + /// The information returned by this method may be handed back to the property + /// in a call to [fromPrimitives] at a later point in time (possibly after the + /// application restarted) to restore the value that the property is currently + /// wrapping. + /// + /// When the value returned by this method changes, the property must call + /// [notifyListeners]. The [RestorationMixin] will invoke this method whenever + /// the property's listeners are notified. + Object? toPrimitives(); + + /// Whether the object currently returned by [toPrimitives] should be included + /// in the restoration state. + /// + /// When this returns false, no information is included in the restoration + /// data for this property and the property will be initialized to its default + /// value (obtained from [createDefaultValue]) the next time that restoration + /// data is used for state restoration. + /// + /// Whenever the value returned by this getter changes, [notifyListeners] must + /// be called. When the value changes from true to false, the information last + /// retrieved from [toPrimitives] is removed from the restoration data. When + /// it changes from false to true, [toPrimitives] is invoked to add the latest + /// restoration information provided by this property to the restoration data. + bool get enabled => true; + + bool _disposed = false; + + @override + void dispose() { + assert(ChangeNotifier.debugAssertNotDisposed(this)); // FYI, This uses ChangeNotifier's _debugDisposed, not _disposed. + _owner?._unregister(this); + super.dispose(); + _disposed = true; + } + + // ID under which the property has been registered with the RestorationMixin. + String? _restorationId; + RestorationMixin? _owner; + void _register(String restorationId, RestorationMixin owner) { + assert(ChangeNotifier.debugAssertNotDisposed(this)); + _restorationId = restorationId; + _owner = owner; + } + void _unregister() { + assert(ChangeNotifier.debugAssertNotDisposed(this)); + assert(_restorationId != null); + assert(_owner != null); + _restorationId = null; + _owner = null; + } + + /// The [State] object that this property is registered with. + /// + /// Must only be called when [isRegistered] is true. + @protected + State get state { + assert(isRegistered); + assert(ChangeNotifier.debugAssertNotDisposed(this)); + return _owner!; + } + + /// Whether this property is currently registered with a [RestorationMixin]. + @protected + bool get isRegistered { + assert(ChangeNotifier.debugAssertNotDisposed(this)); + return _restorationId != null; + } +} + +/// Manages the restoration data for a [State] object of a [StatefulWidget]. +/// +/// Restoration data can be serialized out and, at a later point in time, be +/// used to restore the stateful members in the [State] object to the same +/// values they had when the data was generated. +/// +/// This mixin organizes the restoration data of a [State] object in +/// [RestorableProperty]. All the information that the [State] object wants to +/// get restored during state restoration need to be saved in a subclass of +/// [RestorableProperty]. For example, to restore the count value in a counter +/// app, that value should be stored in a member variable of type +/// [RestorableInt] instead of a plain member variable of type [int]. +/// +/// The mixin ensures that the current values of the [RestorableProperty]s are +/// serialized as part of the restoration state. It is up to the [State] to +/// ensure that the data stored in the properties is always up to date. When the +/// widget is restored from previously generated restoration data, the values of +/// the [RestorableProperty]s are automatically restored to the values that had +/// when the restoration data was serialized out. +/// +/// Within a [State] that uses this mixin, [RestorableProperty]s are usually +/// instantiated to initialize member variables. Users of the mixin must +/// override [restoreState] and register their previously instantiated +/// [RestorableProperty]s in this method by calling [registerForRestoration]. +/// The mixin calls this method for the first time right after +/// [State.initState]. After registration, the values stored in the property +/// have either been restored to their previous value or - if no restoration +/// data for restoring is available - they are initialized with a +/// property-specific default value. At the end of a [State] object's life +/// cycle, all restorable properties must be disposed in [State.dispose]. +/// +/// In addition to being invoked right after [State.initState], [restoreState] +/// is invoked again when new restoration data has been provided to the mixin. +/// When this happens, the [State] object must re-register all properties with +/// [registerForRestoration] again to restore them to their previous values as +/// described by the new restoration data. All initialization logic that depends +/// on the current value of a restorable property should be included in the +/// [restoreState] method to ensure it re-executes when the properties are +/// restored to a different value during the life time of the [State] object. +/// +/// Internally, the mixin stores the restoration data from all registered +/// properties in a [RestorationBucket] claimed from the surrounding +/// [RestorationScope] using the [State]-provided [restorationId]. The +/// [restorationId] must be unique in the surrounding [RestorationScope]. State +/// restoration is disabled for the [State] object using this mixin if +/// [restorationId] is null or when there is no surrounding [RestorationScope]. +/// In that case, the values of the registered properties will not be restored +/// during state restoration. +/// +/// The [RestorationBucket] used to store the registered properties is available +/// via the [bucket] getter. Interacting directly with the bucket is uncommon, +/// but the [State] object may make this bucket available for its descendants to +/// claim child buckets from. For that, the [bucket] is injected into the widget +/// tree in [State.build] with the help of an [UnmanagedRestorationScope]. +/// +/// The [bucket] getter returns null if state restoration is turned off. If +/// state restoration is turned on or off during the lifetime of the widget +/// (e.g. because [restorationId] changes from null to non-null) the value +/// returned by the getter will also change from null to non-null or vice versa. +/// The mixin calls [didToggleBucket] on itself to notify the [State] object +/// about this change. Overriding this method is not necessary as long as the +/// [State] object does not directly interact with the [bucket]. +/// +/// Whenever the value returned by [restorationId] changes, +/// [didUpdateRestorationId] must be called (unless the change already triggers +/// a call to [didUpdateWidget]). +/// +/// {@tool dartpad} +/// This example demonstrates how to make a simple counter app restorable by +/// using the [RestorationMixin] and a [RestorableInt]. +/// +/// ** See code in examples/api/lib/widgets/restoration/restoration_mixin.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [RestorableProperty], which is the base class for all restoration +/// properties managed by this mixin. +/// * [RestorationManager], which describes how state restoration in Flutter +/// works. +/// * [RestorationScope], which creates a new namespace for restoration IDs +/// in the widget tree. +@optionalTypeArgs +mixin RestorationMixin<S extends StatefulWidget> on State<S> { + /// The restoration ID used for the [RestorationBucket] in which the mixin + /// will store the restoration data of all registered properties. + /// + /// The restoration ID is used to claim a child [RestorationScope] from the + /// surrounding [RestorationScope] (accessed via [RestorationScope.of]) and + /// the ID must be unique in that scope (otherwise an exception is triggered + /// in debug mode). + /// + /// State restoration for this mixin is turned off when this getter returns + /// null or when there is no surrounding [RestorationScope] available. When + /// state restoration is turned off, the values of the registered properties + /// cannot be restored. + /// + /// Whenever the value returned by this getter changes, + /// [didUpdateRestorationId] must be called unless the (unless the change + /// already triggered a call to [didUpdateWidget]). + /// + /// The restoration ID returned by this getter is often provided in the + /// constructor of the [StatefulWidget] that this [State] object is associated + /// with. + @protected + String? get restorationId; + + /// The [RestorationBucket] used for the restoration data of the + /// [RestorableProperty]s registered to this mixin. + /// + /// The bucket has been claimed from the surrounding [RestorationScope] using + /// [restorationId]. + /// + /// The getter returns null if state restoration is turned off. When state + /// restoration is turned on or off during the lifetime of this mixin (and + /// hence the return value of this getter switches between null and non-null) + /// [didToggleBucket] is called. + /// + /// Interacting directly with this bucket is uncommon. However, the bucket may + /// be injected into the widget tree in the [State]'s `build` method using an + /// [UnmanagedRestorationScope]. That allows descendants to claim child + /// buckets from this bucket for their own restoration needs. + RestorationBucket? get bucket => _bucket; + RestorationBucket? _bucket; + + /// Called to initialize or restore the [RestorableProperty]s used by the + /// [State] object. + /// + /// This method is always invoked at least once right after [State.initState] + /// to register the [RestorableProperty]s with the mixin even when state + /// restoration is turned off or no restoration data is available for this + /// [State] object. + /// + /// Typically, [registerForRestoration] is called from this method to register + /// all [RestorableProperty]s used by the [State] object with the mixin. The + /// registration will either restore the property's value to the value + /// described by the restoration data, if available, or, if no restoration + /// data is available - initialize it to a property-specific default value. + /// + /// The method is called again whenever new restoration data (in the form of a + /// new [bucket]) has been provided to the mixin. When that happens, the + /// [State] object must re-register all previously registered properties, + /// which will restore their values to the value described by the new + /// restoration data. + /// + /// Since the method may change the value of the registered properties when + /// new restoration state is provided, all initialization logic that depends + /// on a specific value of a [RestorableProperty] should be included in this + /// method. That way, that logic re-executes when the [RestorableProperty]s + /// have their values restored from newly provided restoration data. + /// + /// The first time the method is invoked, the provided `oldBucket` argument is + /// always null. In subsequent calls triggered by new restoration data in the + /// form of a new bucket, the argument given is the previous value of + /// [bucket]. + @mustCallSuper + @protected + void restoreState(RestorationBucket? oldBucket, bool initialRestore); + + /// Called when [bucket] switches between null and non-null values. + /// + /// [State] objects that wish to directly interact with the bucket may + /// override this method to store additional values in the bucket when one + /// becomes available or to save values stored in a bucket elsewhere when the + /// bucket goes away. This is uncommon and storing those values in + /// [RestorableProperty]s should be considered instead. + /// + /// The `oldBucket` is provided to the method when the [bucket] getter changes + /// from non-null to null. The `oldBucket` argument is null when the [bucket] + /// changes from null to non-null. + /// + /// See also: + /// + /// * [restoreState], which is called when the [bucket] changes from one + /// non-null value to another non-null value. + @mustCallSuper + @protected + void didToggleBucket(RestorationBucket? oldBucket) { + // When a bucket is replaced, must `restoreState` is called instead. + assert(_bucket?.isReplacing != true); + } + + // Maps properties to their listeners. + final Map<RestorableProperty<Object?>, VoidCallback> _properties = <RestorableProperty<Object?>, VoidCallback>{}; + + /// Registers a [RestorableProperty] for state restoration. + /// + /// The registration associates the provided `property` with the provided + /// `restorationId`. If restoration data is available for the provided + /// `restorationId`, the property's value is restored to the value described + /// by the restoration data. If no restoration data is available, the property + /// will be initialized to a property-specific default value. + /// + /// Each property within a [State] object must be registered under a unique + /// ID. Only registered properties will have their values restored during + /// state restoration. + /// + /// Typically, this method is called from within [restoreState] to register + /// all restorable properties of the owning [State] object. However, if a + /// given [RestorableProperty] is only needed when certain conditions are met + /// within the [State], [registerForRestoration] may also be called at any + /// time after [restoreState] has been invoked for the first time. + /// + /// A property that has been registered outside of [restoreState] must be + /// re-registered within [restoreState] the next time that method is called + /// unless it has been unregistered with [unregisterFromRestoration]. + @protected + void registerForRestoration(RestorableProperty<Object?> property, String restorationId) { + assert(property._restorationId == null || (_debugDoingRestore && property._restorationId == restorationId), + 'Property is already registered under ${property._restorationId}.', + ); + assert(_debugDoingRestore || !_properties.keys.map((RestorableProperty<Object?> r) => r._restorationId).contains(restorationId), + '"$restorationId" is already registered to another property.', + ); + final bool hasSerializedValue = bucket?.contains(restorationId) ?? false; + final Object? initialValue = hasSerializedValue + ? property.fromPrimitives(bucket!.read<Object>(restorationId)) + : property.createDefaultValue(); + + if (!property.isRegistered) { + property._register(restorationId, this); + void listener() { + if (bucket == null) { + return; + } + _updateProperty(property); + } + property.addListener(listener); + _properties[property] = listener; + } + + assert( + property._restorationId == restorationId && + property._owner == this && + _properties.containsKey(property), + ); + + property.initWithValue(initialValue); + if (!hasSerializedValue && property.enabled && bucket != null) { + _updateProperty(property); + } + + assert(() { + _debugPropertiesWaitingForReregistration?.remove(property); + return true; + }()); + } + + /// Unregisters a [RestorableProperty] from state restoration. + /// + /// The value of the `property` is removed from the restoration data and it + /// will not be restored if that data is used in a future state restoration. + /// + /// Calling this method is uncommon, but may be necessary if the data of a + /// [RestorableProperty] is only relevant when the [State] object is in a + /// certain state. When the data of a property is no longer necessary to + /// restore the internal state of a [State] object, it may be removed from the + /// restoration data by calling this method. + @protected + void unregisterFromRestoration(RestorableProperty<Object?> property) { + assert(property._owner == this); + _bucket?.remove<Object?>(property._restorationId!); + _unregister(property); + } + + /// Must be called when the value returned by [restorationId] changes. + /// + /// This method is automatically called from [didUpdateWidget]. Therefore, + /// manually invoking this method may be omitted when the change in + /// [restorationId] was caused by an updated widget. + @protected + void didUpdateRestorationId() { + // There's nothing to do if: + // - We don't have a parent to claim a bucket from. + // - Our current bucket already uses the provided restoration ID. + // - There's a restore pending, which means that didChangeDependencies + // will be called and we handle the rename there. + if (_currentParent == null || _bucket?.restorationId == restorationId || restorePending) { + return; + } + + final RestorationBucket? oldBucket = _bucket; + assert(!restorePending); + final bool didReplaceBucket = _updateBucketIfNecessary(parent: _currentParent, restorePending: false); + if (didReplaceBucket) { + assert(oldBucket != _bucket); + assert(_bucket == null || oldBucket == null); + oldBucket?.dispose(); + } + } + + @override + void didUpdateWidget(S oldWidget) { + super.didUpdateWidget(oldWidget); + didUpdateRestorationId(); + } + + /// Whether [restoreState] will be called at the beginning of the next build + /// phase. + /// + /// Returns true when new restoration data has been provided to the mixin, but + /// the registered [RestorableProperty]s have not been restored to their new + /// values (as described by the new restoration data) yet. The properties will + /// get the values restored when [restoreState] is invoked at the beginning of + /// the next build cycle. + /// + /// While this is true, [bucket] will also still return the old bucket with + /// the old restoration data. It will update to the new bucket with the new + /// data just before [restoreState] is invoked. + bool get restorePending { + if (_firstRestorePending) { + return true; + } + if (restorationId == null) { + return false; + } + final RestorationBucket? potentialNewParent = RestorationScope.maybeOf(context); + return potentialNewParent != _currentParent && (potentialNewParent?.isReplacing ?? false); + } + + List<RestorableProperty<Object?>>? _debugPropertiesWaitingForReregistration; + bool get _debugDoingRestore => _debugPropertiesWaitingForReregistration != null; + + bool _firstRestorePending = true; + RestorationBucket? _currentParent; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + final RestorationBucket? oldBucket = _bucket; + final bool needsRestore = restorePending; + _currentParent = RestorationScope.maybeOf(context); + + final bool didReplaceBucket = _updateBucketIfNecessary(parent: _currentParent, restorePending: needsRestore); + + if (needsRestore) { + _doRestore(oldBucket); + } + if (didReplaceBucket) { + assert(oldBucket != _bucket); + oldBucket?.dispose(); + } + } + + void _doRestore(RestorationBucket? oldBucket) { + assert(() { + _debugPropertiesWaitingForReregistration = _properties.keys.toList(); + return true; + }()); + + restoreState(oldBucket, _firstRestorePending); + _firstRestorePending = false; + + assert(() { + if (_debugPropertiesWaitingForReregistration!.isNotEmpty) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'Previously registered RestorableProperties must be re-registered in "restoreState".', + ), + ErrorDescription( + 'The RestorableProperties with the following IDs were not re-registered to $this when ' + '"restoreState" was called:', + ), + ..._debugPropertiesWaitingForReregistration!.map((RestorableProperty<Object?> property) => ErrorDescription( + ' * ${property._restorationId}', + )), + ]); + } + _debugPropertiesWaitingForReregistration = null; + return true; + }()); + } + + // Returns true if `bucket` has been replaced with a new bucket. It's the + // responsibility of the caller to dispose the old bucket when this returns true. + bool _updateBucketIfNecessary({ + required RestorationBucket? parent, + required bool restorePending, + }) { + if (restorationId == null || parent == null) { + final bool didReplace = _setNewBucketIfNecessary(newBucket: null, restorePending: restorePending); + assert(_bucket == null); + return didReplace; + } + assert(restorationId != null); + if (restorePending || _bucket == null) { + final RestorationBucket newBucket = parent.claimChild(restorationId!, debugOwner: this); + final bool didReplace = _setNewBucketIfNecessary(newBucket: newBucket, restorePending: restorePending); + assert(_bucket == newBucket); + return didReplace; + } + // We have an existing bucket, make sure it has the right parent and id. + assert(_bucket != null); + assert(!restorePending); + _bucket!.rename(restorationId!); + parent.adoptChild(_bucket!); + return false; + } + + // Returns true if `bucket` has been replaced with a new bucket. It's the + // responsibility of the caller to dispose the old bucket when this returns true. + bool _setNewBucketIfNecessary({required RestorationBucket? newBucket, required bool restorePending}) { + if (newBucket == _bucket) { + return false; + } + final RestorationBucket? oldBucket = _bucket; + _bucket = newBucket; + if (!restorePending) { + // Write the current property values into the new bucket to persist them. + if (_bucket != null) { + _properties.keys.forEach(_updateProperty); + } + didToggleBucket(oldBucket); + } + return true; + } + + void _updateProperty(RestorableProperty<Object?> property) { + if (property.enabled) { + _bucket?.write(property._restorationId!, property.toPrimitives()); + } else { + _bucket?.remove<Object>(property._restorationId!); + } + } + + void _unregister(RestorableProperty<Object?> property) { + final VoidCallback listener = _properties.remove(property)!; + assert(() { + _debugPropertiesWaitingForReregistration?.remove(property); + return true; + }()); + property.removeListener(listener); + property._unregister(); + } + + @override + void dispose() { + _properties.forEach((RestorableProperty<Object?> property, VoidCallback listener) { + if (!property._disposed) { + property.removeListener(listener); + } + }); + _bucket?.dispose(); + _bucket = null; + super.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/restoration_properties.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/restoration_properties.dart new file mode 100644 index 0000000000000000000000000000000000000000..fccd03ad1a712c32bff7ca666fb17cb762d9267f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/restoration_properties.dart @@ -0,0 +1,668 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'editable_text.dart'; +import 'restoration.dart'; + +/// A [RestorableProperty] that makes the wrapped value accessible to the owning +/// [State] object via the [value] getter and setter. +/// +/// Whenever a new [value] is set, [didUpdateValue] is called. Subclasses should +/// call [notifyListeners] from this method if the new value changes what +/// [toPrimitives] returns. +/// +/// ## Using a RestorableValue +/// +/// {@tool dartpad} +/// A [StatefulWidget] that has a restorable [int] property. +/// +/// ** See code in examples/api/lib/widgets/restoration_properties/restorable_value.0.dart ** +/// {@end-tool} +/// +/// ## Creating a subclass +/// +/// {@tool snippet} +/// This example shows how to create a new [RestorableValue] subclass, +/// in this case for the [Duration] class. +/// +/// ```dart +/// class RestorableDuration extends RestorableValue<Duration> { +/// @override +/// Duration createDefaultValue() => Duration.zero; +/// +/// @override +/// void didUpdateValue(Duration? oldValue) { +/// if (oldValue == null || oldValue.inMicroseconds != value.inMicroseconds) { +/// notifyListeners(); +/// } +/// } +/// +/// @override +/// Duration fromPrimitives(Object? data) { +/// if (data != null) { +/// return Duration(microseconds: data as int); +/// } +/// return Duration.zero; +/// } +/// +/// @override +/// Object toPrimitives() { +/// return value.inMicroseconds; +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [RestorableProperty], which is the super class of this class. +/// * [RestorationMixin], to which a [RestorableValue] needs to be registered +/// in order to work. +/// * [RestorationManager], which provides an overview of how state restoration +/// works in Flutter. +abstract class RestorableValue<T> extends RestorableProperty<T> { + /// The current value stored in this property. + /// + /// A representation of the current value is stored in the restoration data. + /// During state restoration, the property will restore the value to what it + /// was when the restoration data it is getting restored from was collected. + /// + /// The [value] can only be accessed after the property has been registered + /// with a [RestorationMixin] by calling + /// [RestorationMixin.registerForRestoration]. + T get value { + assert(isRegistered); + return _value as T; + } + T? _value; + set value(T newValue) { + assert(isRegistered); + if (newValue != _value) { + final T? oldValue = _value; + _value = newValue; + didUpdateValue(oldValue); + } + } + + @mustCallSuper + @override + void initWithValue(T value) { + _value = value; + } + + /// Called whenever a new value is assigned to [value]. + /// + /// The new value can be accessed via the regular [value] getter and the + /// previous value is provided as `oldValue`. + /// + /// Subclasses should call [notifyListeners] from this method, if the new + /// value changes what [toPrimitives] returns. + @protected + void didUpdateValue(T? oldValue); +} + +// _RestorablePrimitiveValueN and its subclasses allows for null values. +// See [_RestorablePrimitiveValue] for the non-nullable version of this class. +class _RestorablePrimitiveValueN<T extends Object?> extends RestorableValue<T> { + _RestorablePrimitiveValueN(this._defaultValue) + : assert(debugIsSerializableForRestoration(_defaultValue)), + super(); + + final T _defaultValue; + + @override + T createDefaultValue() => _defaultValue; + + @override + void didUpdateValue(T? oldValue) { + assert(debugIsSerializableForRestoration(value)); + notifyListeners(); + } + + @override + T fromPrimitives(Object? serialized) => serialized as T; + + @override + Object? toPrimitives() => value; +} + +// _RestorablePrimitiveValue and its subclasses are non-nullable. +// See [_RestorablePrimitiveValueN] for the nullable version of this class. +class _RestorablePrimitiveValue<T extends Object> extends _RestorablePrimitiveValueN<T> { + _RestorablePrimitiveValue(super.defaultValue) + : assert(debugIsSerializableForRestoration(defaultValue)); + + @override + set value(T value) { + super.value = value; + } + + @override + T fromPrimitives(Object? serialized) { + assert(serialized != null); + return super.fromPrimitives(serialized); + } + + @override + Object toPrimitives() { + return super.toPrimitives()!; + } +} + +/// A [RestorableProperty] that knows how to store and restore a [num]. +/// +/// {@template flutter.widgets.RestorableNum} +/// The current [value] of this property is stored in the restoration data. +/// During state restoration the property is restored to the value it had when +/// the restoration data it is getting restored from was collected. +/// +/// If no restoration data is available, [value] is initialized to the +/// `defaultValue` given in the constructor. +/// {@endtemplate} +/// +/// Instead of using the more generic [RestorableNum] directly, consider using +/// one of the more specific subclasses (e.g. [RestorableDouble] to store a +/// [double] and [RestorableInt] to store an [int]). +/// +/// See also: +/// +/// * [RestorableNumN] for the nullable version of this class. +class RestorableNum<T extends num> extends _RestorablePrimitiveValue<T> { + /// Creates a [RestorableNum]. + /// + /// {@template flutter.widgets.RestorableNum.constructor} + /// If no restoration data is available to restore the value in this property + /// from, the property will be initialized with the provided `defaultValue`. + /// {@endtemplate} + RestorableNum(super.defaultValue); +} + +/// A [RestorableProperty] that knows how to store and restore a [double]. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// See also: +/// +/// * [RestorableDoubleN] for the nullable version of this class. +class RestorableDouble extends RestorableNum<double> { + /// Creates a [RestorableDouble]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableDouble(super.defaultValue); +} + +/// A [RestorableProperty] that knows how to store and restore an [int]. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// See also: +/// +/// * [RestorableIntN] for the nullable version of this class. +class RestorableInt extends RestorableNum<int> { + /// Creates a [RestorableInt]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableInt(super.defaultValue); +} + +/// A [RestorableProperty] that knows how to store and restore a [String]. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// See also: +/// +/// * [RestorableStringN] for the nullable version of this class. +class RestorableString extends _RestorablePrimitiveValue<String> { + /// Creates a [RestorableString]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableString(super.defaultValue); +} + +/// A [RestorableProperty] that knows how to store and restore a [bool]. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// See also: +/// +/// * [RestorableBoolN] for the nullable version of this class. +class RestorableBool extends _RestorablePrimitiveValue<bool> { + /// Creates a [RestorableBool]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableBool(super.defaultValue); +} + +/// A [RestorableProperty] that knows how to store and restore a [bool] that is +/// nullable. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// See also: +/// +/// * [RestorableBool] for the non-nullable version of this class. +class RestorableBoolN extends _RestorablePrimitiveValueN<bool?> { + /// Creates a [RestorableBoolN]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableBoolN(super.defaultValue); +} + +/// A [RestorableProperty] that knows how to store and restore a [num] +/// that is nullable. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// Instead of using the more generic [RestorableNumN] directly, consider using +/// one of the more specific subclasses (e.g. [RestorableDoubleN] to store a +/// [double] and [RestorableIntN] to store an [int]). +/// +/// See also: +/// +/// * [RestorableNum] for the non-nullable version of this class. +class RestorableNumN<T extends num?> extends _RestorablePrimitiveValueN<T> { + /// Creates a [RestorableNumN]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableNumN(super.defaultValue); +} + +/// A [RestorableProperty] that knows how to store and restore a [double] +/// that is nullable. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// See also: +/// +/// * [RestorableDouble] for the non-nullable version of this class. +class RestorableDoubleN extends RestorableNumN<double?> { + /// Creates a [RestorableDoubleN]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableDoubleN(super.defaultValue); +} + +/// A [RestorableProperty] that knows how to store and restore an [int] +/// that is nullable. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// See also: +/// +/// * [RestorableInt] for the non-nullable version of this class. +class RestorableIntN extends RestorableNumN<int?> { + /// Creates a [RestorableIntN]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableIntN(super.defaultValue); +} + +/// A [RestorableProperty] that knows how to store and restore a [String] +/// that is nullable. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// See also: +/// +/// * [RestorableString] for the non-nullable version of this class. +class RestorableStringN extends _RestorablePrimitiveValueN<String?> { + /// Creates a [RestorableString]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableStringN(super.defaultValue); +} + +/// A [RestorableValue] that knows how to save and restore [DateTime]. +/// +/// {@macro flutter.widgets.RestorableNum}. +class RestorableDateTime extends RestorableValue<DateTime> { + /// Creates a [RestorableDateTime]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableDateTime(DateTime defaultValue) : _defaultValue = defaultValue; + + final DateTime _defaultValue; + + @override + DateTime createDefaultValue() => _defaultValue; + + @override + void didUpdateValue(DateTime? oldValue) { + assert(debugIsSerializableForRestoration(value.millisecondsSinceEpoch)); + notifyListeners(); + } + + @override + DateTime fromPrimitives(Object? data) => DateTime.fromMillisecondsSinceEpoch(data! as int); + + @override + Object? toPrimitives() => value.millisecondsSinceEpoch; +} + +/// A [RestorableValue] that knows how to save and restore [DateTime] that is +/// nullable. +/// +/// {@macro flutter.widgets.RestorableNum}. +class RestorableDateTimeN extends RestorableValue<DateTime?> { + /// Creates a [RestorableDateTime]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableDateTimeN(DateTime? defaultValue) : _defaultValue = defaultValue; + + final DateTime? _defaultValue; + + @override + DateTime? createDefaultValue() => _defaultValue; + + @override + void didUpdateValue(DateTime? oldValue) { + assert(debugIsSerializableForRestoration(value?.millisecondsSinceEpoch)); + notifyListeners(); + } + + @override + DateTime? fromPrimitives(Object? data) => data != null ? DateTime.fromMillisecondsSinceEpoch(data as int) : null; + + @override + Object? toPrimitives() => value?.millisecondsSinceEpoch; +} + +/// A base class for creating a [RestorableProperty] that stores and restores a +/// [Listenable]. +/// +/// This class may be used to implement a [RestorableProperty] for a +/// [Listenable], whose information it needs to store in the restoration data +/// change whenever the [Listenable] notifies its listeners. +/// +/// The [RestorationMixin] this property is registered with will call +/// [toPrimitives] whenever the wrapped [Listenable] notifies its listeners to +/// update the information that this property has stored in the restoration +/// data. +abstract class RestorableListenable<T extends Listenable> extends RestorableProperty<T> { + /// The [Listenable] stored in this property. + /// + /// A representation of the current value of the [Listenable] is stored in the + /// restoration data. During state restoration, the [Listenable] returned by + /// this getter will be restored to the state it had when the restoration data + /// the property is getting restored from was collected. + /// + /// The [value] can only be accessed after the property has been registered + /// with a [RestorationMixin] by calling + /// [RestorationMixin.registerForRestoration]. + T get value { + assert(isRegistered); + return _value!; + } + T? _value; + + @override + void initWithValue(T value) { + _value?.removeListener(notifyListeners); + _value = value; + _value!.addListener(notifyListeners); + } + + @override + void dispose() { + super.dispose(); + _value?.removeListener(notifyListeners); + } +} + +/// A base class for creating a [RestorableProperty] that stores and restores a +/// [ChangeNotifier]. +/// +/// This class may be used to implement a [RestorableProperty] for a +/// [ChangeNotifier], whose information it needs to store in the restoration +/// data change whenever the [ChangeNotifier] notifies its listeners. +/// +/// The [RestorationMixin] this property is registered with will call +/// [toPrimitives] whenever the wrapped [ChangeNotifier] notifies its listeners +/// to update the information that this property has stored in the restoration +/// data. +/// +/// Furthermore, the property will dispose the wrapped [ChangeNotifier] when +/// either the property itself is disposed or its value is replaced with another +/// [ChangeNotifier] instance. +abstract class RestorableChangeNotifier<T extends ChangeNotifier> extends RestorableListenable<T> { + @override + void initWithValue(T value) { + _disposeOldValue(); + super.initWithValue(value); + } + + @override + void dispose() { + _disposeOldValue(); + super.dispose(); + } + + void _disposeOldValue() { + if (_value != null) { + // Scheduling a microtask for dispose to give other entities a chance + // to remove their listeners first. + scheduleMicrotask(_value!.dispose); + } + } +} + +/// A [RestorableProperty] that knows how to store and restore a +/// [TextEditingController]. +/// +/// The [TextEditingController] is accessible via the [value] getter. During +/// state restoration, the property will restore [TextEditingController.text] to +/// the value it had when the restoration data it is getting restored from was +/// collected. +class RestorableTextEditingController extends RestorableChangeNotifier<TextEditingController> { + /// Creates a [RestorableTextEditingController]. + /// + /// This constructor treats a null `text` argument as if it were the empty + /// string. + factory RestorableTextEditingController({String? text}) => RestorableTextEditingController.fromValue( + text == null ? TextEditingValue.empty : TextEditingValue(text: text), + ); + + /// Creates a [RestorableTextEditingController] from an initial + /// [TextEditingValue]. + /// + /// This constructor treats a null `value` argument as if it were + /// [TextEditingValue.empty]. + RestorableTextEditingController.fromValue(TextEditingValue value) : _initialValue = value; + + final TextEditingValue _initialValue; + + @override + TextEditingController createDefaultValue() { + return TextEditingController.fromValue(_initialValue); + } + + @override + TextEditingController fromPrimitives(Object? data) { + return TextEditingController(text: data! as String); + } + + @override + Object toPrimitives() { + return value.text; + } +} + +/// A [RestorableProperty] that knows how to store and restore a nullable [Enum] +/// type. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// The values are serialized using the name of the enum, obtained using the +/// [EnumName.name] extension accessor. +/// +/// The represented value is accessible via the [value] getter. The set of +/// values in the enum are accessible via the [values] getter. Since +/// [RestorableEnumN] allows null, this set will include null. +/// +/// See also: +/// +/// * [RestorableEnum], a class similar to this one that knows how to store and +/// restore non-nullable [Enum] types. +class RestorableEnumN<T extends Enum> extends RestorableValue<T?> { + /// Creates a [RestorableEnumN]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableEnumN(T? defaultValue, { required Iterable<T> values }) + : assert(defaultValue == null || values.contains(defaultValue), + 'Default value $defaultValue not found in $T values: $values'), + _defaultValue = defaultValue, + values = values.toSet(); + + @override + T? createDefaultValue() => _defaultValue; + final T? _defaultValue; + + @override + set value(T? newValue) { + assert(newValue == null || values.contains(newValue), + 'Attempted to set an unknown enum value "$newValue" that is not null, or ' + 'in the valid set of enum values for the $T type: ' + '${values.map<String>((T value) => value.name).toSet()}'); + super.value = newValue; + } + + /// The set of non-null values that this [RestorableEnumN] may represent. + /// + /// This is a required field that supplies the enum values that are serialized + /// and restored. + /// + /// If a value is encountered that is not null or a value in this set, + /// [fromPrimitives] will assert when restoring. + /// + /// It is typically set to the `values` list of the enum type. + /// + /// In addition to this set, because [RestorableEnumN] allows nullable values, + /// null is also a valid value, even though it doesn't appear in this set. + /// + /// {@tool snippet} For example, to create a [RestorableEnumN] with an + /// [AxisDirection] enum value, with a default value of null, you would build + /// it like the code below: + /// + /// ```dart + /// RestorableEnumN<AxisDirection> axis = RestorableEnumN<AxisDirection>(null, values: AxisDirection.values); + /// ``` + /// {@end-tool} + Set<T> values; + + @override + void didUpdateValue(T? oldValue) { + notifyListeners(); + } + + @override + T? fromPrimitives(Object? data) { + if (data == null) { + return null; + } + if (data is String) { + for (final T allowed in values) { + if (allowed.name == data) { + return allowed; + } + } + assert(false, + 'Attempted to set an unknown enum value "$data" that is not null, or ' + 'in the valid set of enum values for the $T type: ' + '${values.map<String>((T value) => value.name).toSet()}'); + } + return _defaultValue; + } + + @override + Object? toPrimitives() => value?.name; +} + + +/// A [RestorableProperty] that knows how to store and restore an [Enum] +/// type. +/// +/// {@macro flutter.widgets.RestorableNum} +/// +/// The values are serialized using the name of the enum, obtained using the +/// [EnumName.name] extension accessor. +/// +/// The represented value is accessible via the [value] getter. +/// +/// See also: +/// +/// * [RestorableEnumN], a class similar to this one that knows how to store and +/// restore nullable [Enum] types. +class RestorableEnum<T extends Enum> extends RestorableValue<T> { + /// Creates a [RestorableEnum]. + /// + /// {@macro flutter.widgets.RestorableNum.constructor} + RestorableEnum(T defaultValue, { required Iterable<T> values }) + : assert(values.contains(defaultValue), + 'Default value $defaultValue not found in $T values: $values'), + _defaultValue = defaultValue, + values = values.toSet(); + + @override + T createDefaultValue() => _defaultValue; + final T _defaultValue; + + @override + set value(T newValue) { + assert(values.contains(newValue), + 'Attempted to set an unknown enum value "$newValue" that is not in the ' + 'valid set of enum values for the $T type: ' + '${values.map<String>((T value) => value.name).toSet()}'); + + super.value = newValue; + } + + /// The set of values that this [RestorableEnum] may represent. + /// + /// This is a required field that supplies the possible enum values that can + /// be serialized and restored. + /// + /// If a value is encountered that is not in this set, [fromPrimitives] will + /// assert when restoring. + /// + /// It is typically set to the `values` list of the enum type. + /// + /// {@tool snippet} For example, to create a [RestorableEnum] with an + /// [AxisDirection] enum value, with a default value of [AxisDirection.up], + /// you would build it like the code below: + /// + /// ```dart + /// RestorableEnum<AxisDirection> axis = RestorableEnum<AxisDirection>(AxisDirection.up, values: AxisDirection.values); + /// ``` + /// {@end-tool} + Set<T> values; + + @override + void didUpdateValue(T? oldValue) { + notifyListeners(); + } + + @override + T fromPrimitives(Object? data) { + if (data != null && data is String) { + for (final T allowed in values) { + if (allowed.name == data) { + return allowed; + } + } + assert(false, + 'Attempted to restore an unknown enum value "$data" that is not in the ' + 'valid set of enum values for the $T type: ' + '${values.map<String>((T value) => value.name).toSet()}'); + } + return _defaultValue; + } + + @override + Object toPrimitives() => value.name; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/router.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/router.dart new file mode 100644 index 0000000000000000000000000000000000000000..5541f92e7c1a6e6621f7086084923573bed06116 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/router.dart @@ -0,0 +1,1599 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:collection'; + +import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'basic.dart'; +import 'binding.dart'; +import 'framework.dart'; +import 'navigator.dart'; +import 'restoration.dart'; +import 'restoration_properties.dart'; + +/// A piece of routing information. +/// +/// The route information consists of a location string of the application and +/// a state object that configures the application in that location. +/// +/// This information flows two ways, from the [RouteInformationProvider] to the +/// [Router] or from the [Router] to [RouteInformationProvider]. +/// +/// In the former case, the [RouteInformationProvider] notifies the [Router] +/// widget when a new [RouteInformation] is available. The [Router] widget takes +/// these information and navigates accordingly. +/// +/// The latter case happens in web application where the [Router] reports route +/// changes back to the web engine. +/// +/// The current [RouteInformation] of an application is also used for state +/// restoration purposes. Before an application is killed, the [Router] converts +/// its current configurations into a [RouteInformation] object utilizing the +/// [RouteInformationProvider]. The [RouteInformation] object is then serialized +/// out and persisted. During state restoration, the object is deserialized and +/// passed back to the [RouteInformationProvider], which turns it into a +/// configuration for the [Router] again to restore its state from. +class RouteInformation { + /// Creates a route information object. + /// + /// Either `location` or `uri` must not be null. + const RouteInformation({ + @Deprecated( + 'Pass Uri.parse(location) to uri parameter instead. ' + 'This feature was deprecated after v3.8.0-3.0.pre.' + ) + String? location, + Uri? uri, + this.state, + }) : _location = location, + _uri = uri, + assert((location != null) != (uri != null)); + + /// The location of the application. + /// + /// The string is usually in the format of multiple string identifiers with + /// slashes in between. ex: `/`, `/path`, `/path/to/the/app`. + @Deprecated( + 'Use uri instead. ' + 'This feature was deprecated after v3.8.0-3.0.pre.' + ) + String get location { + if (_location != null) { + return _location; + } + return Uri.decodeComponent( + Uri( + path: uri.path.isEmpty ? '/' : uri.path, + queryParameters: uri.queryParametersAll.isEmpty ? null : uri.queryParametersAll, + fragment: uri.fragment.isEmpty ? null : uri.fragment, + ).toString(), + ); + } + final String? _location; + + /// The uri location of the application. + /// + /// The host and scheme will not be empty if this object is created from a + /// deep link request. They represents the website that redirect the deep + /// link. + /// + /// In web platform, the host and scheme are always empty. + Uri get uri { + if (_uri != null){ + return _uri; + } + return Uri.parse(_location!); + } + final Uri? _uri; + + /// The state of the application in the [uri]. + /// + /// The app can have different states even in the same location. For example, + /// the text inside a [TextField] or the scroll position in a [ScrollView]. + /// These widget states can be stored in the [state]. + /// + /// On the web, this information is stored in the browser history when the + /// [Router] reports this route information back to the web engine + /// through the [PlatformRouteInformationProvider]. The information + /// is then passed back, along with the [uri], when the user + /// clicks the back or forward buttons. + /// + /// This information is also serialized and persisted alongside the + /// [uri] for state restoration purposes. During state restoration, + /// the information is made available again to the [Router] so it can restore + /// its configuration to the previous state. + /// + /// The state must be serializable. + final Object? state; +} + +/// A convenient bundle to configure a [Router] widget. +/// +/// To configure a [Router] widget, one needs to provide several delegates, +/// [RouteInformationProvider], [RouteInformationParser], [RouterDelegate], +/// and [BackButtonDispatcher]. This abstract class provides way to bundle these +/// delegates into a single object to configure a [Router]. +/// +/// The [backButtonDispatcher], [routeInformationProvider], and +/// [routeInformationProvider] are optional. +/// +/// The [routeInformationProvider] and [routeInformationParser] must +/// both be provided or both not provided. +class RouterConfig<T> { + /// Creates a [RouterConfig]. + /// + /// The [backButtonDispatcher], [routeInformationProvider], and + /// [routeInformationParser] are optional. + /// + /// The [routeInformationProvider] and [routeInformationParser] must both be + /// provided or both not provided. + const RouterConfig({ + this.routeInformationProvider, + this.routeInformationParser, + required this.routerDelegate, + this.backButtonDispatcher, + }) : assert((routeInformationProvider == null) == (routeInformationParser == null)); + + /// The [RouteInformationProvider] that is used to configure the [Router]. + final RouteInformationProvider? routeInformationProvider; + + /// The [RouteInformationParser] that is used to configure the [Router]. + final RouteInformationParser<T>? routeInformationParser; + + /// The [RouterDelegate] that is used to configure the [Router]. + final RouterDelegate<T> routerDelegate; + + /// The [BackButtonDispatcher] that is used to configure the [Router]. + final BackButtonDispatcher? backButtonDispatcher; +} + +/// The dispatcher for opening and closing pages of an application. +/// +/// This widget listens for routing information from the operating system (e.g. +/// an initial route provided on app startup, a new route obtained when an +/// intent is received, or a notification that the user hit the system back +/// button), parses route information into data of type `T`, and then converts +/// that data into [Page] objects that it passes to a [Navigator]. +/// +/// Each part of this process can be overridden and configured as desired. +/// +/// The [routeInformationProvider] can be overridden to change how the name of +/// the route is obtained. The [RouteInformationProvider.value] is used as the +/// initial route when the [Router] is first created. Subsequent notifications +/// from the [RouteInformationProvider] to its listeners are treated as +/// notifications that the route information has changed. +/// +/// The [backButtonDispatcher] can be overridden to change how back button +/// notifications are received. This must be a [BackButtonDispatcher], which is +/// an object where callbacks can be registered, and which can be chained so +/// that back button presses are delegated to subsidiary routers. The callbacks +/// are invoked to indicate that the user is trying to close the current route +/// (by pressing the system back button); the [Router] ensures that when this +/// callback is invoked, the message is passed to the [routerDelegate] and its +/// result is provided back to the [backButtonDispatcher]. Some platforms don't +/// have back buttons (e.g. iOS and desktop platforms); on those platforms this +/// notification is never sent. Typically, the [backButtonDispatcher] for the +/// root router is an instance of [RootBackButtonDispatcher], which uses a +/// [WidgetsBindingObserver] to listen to the `popRoute` notifications from +/// [SystemChannels.navigation]. Nested [Router]s typically use a +/// [ChildBackButtonDispatcher], which must be provided the +/// [BackButtonDispatcher] of its ancestor [Router] (available via [Router.of]). +/// +/// The [routeInformationParser] can be overridden to change how names obtained +/// from the [routeInformationProvider] are interpreted. It must implement the +/// [RouteInformationParser] interface, specialized with the same type as the +/// [Router] itself. This type, `T`, represents the data type that the +/// [routeInformationParser] will generate. +/// +/// The [routerDelegate] can be overridden to change how the output of the +/// [routeInformationParser] is interpreted. It must implement the +/// [RouterDelegate] interface, also specialized with `T`; it takes as input +/// the data (of type `T`) from the [routeInformationParser], and is responsible +/// for providing a navigating widget to insert into the widget tree. The +/// [RouterDelegate] interface is also [Listenable]; notifications are taken +/// to mean that the [Router] needs to rebuild. +/// +/// ## Concerns regarding asynchrony +/// +/// Some of the APIs (notably those involving [RouteInformationParser] and +/// [RouterDelegate]) are asynchronous. +/// +/// When developing objects implementing these APIs, if the work can be done +/// entirely synchronously, then consider using [SynchronousFuture] for the +/// future returned from the relevant methods. This will allow the [Router] to +/// proceed in a completely synchronous way, which removes a number of +/// complications. +/// +/// Using asynchronous computation is entirely reasonable, however, and the API +/// is designed to support it. For example, maybe a set of images need to be +/// loaded before a route can be shown; waiting for those images to be loaded +/// before [RouterDelegate.setNewRoutePath] returns is a reasonable approach to +/// handle this case. +/// +/// If an asynchronous operation is ongoing when a new one is to be started, the +/// precise behavior will depend on the exact circumstances, as follows: +/// +/// If the active operation is a [routeInformationParser] parsing a new route information: +/// that operation's result, if it ever completes, will be discarded. +/// +/// If the active operation is a [routerDelegate] handling a pop request: +/// the previous pop is immediately completed with "false", claiming that the +/// previous pop was not handled (this may cause the application to close). +/// +/// If the active operation is a [routerDelegate] handling an initial route +/// or a pushed route, the result depends on the new operation. If the new +/// operation is a pop request, then the original operation's result, if it ever +/// completes, will be discarded. If the new operation is a push request, +/// however, the [routeInformationParser] will be requested to start the parsing, and +/// only if that finishes before the original [routerDelegate] request +/// completes will that original request's result be discarded. +/// +/// If the identity of the [Router] widget's delegates change while an +/// asynchronous operation is in progress, to keep matters simple, all active +/// asynchronous operations will have their results discarded. It is generally +/// considered unusual for these delegates to change during the lifetime of the +/// [Router]. +/// +/// If the [Router] itself is disposed while an asynchronous operation is in +/// progress, all active asynchronous operations will have their results +/// discarded also. +/// +/// No explicit signals are provided to the [routeInformationParser] or +/// [routerDelegate] to indicate when any of the above happens, so it is +/// strongly recommended that [RouteInformationParser] and [RouterDelegate] +/// implementations not perform extensive computation. +/// +/// ## Application architectural design +/// +/// An application can have zero, one, or many [Router] widgets, depending on +/// its needs. +/// +/// An application might have no [Router] widgets if it has only one "screen", +/// or if the facilities provided by [Navigator] are sufficient. This is common +/// for desktop applications, where subsidiary "screens" are represented using +/// different windows rather than changing the active interface. +/// +/// A particularly elaborate application might have multiple [Router] widgets, +/// in a tree configuration, with the first handling the entire route parsing +/// and making the result available for routers in the subtree. The routers in +/// the subtree do not participate in route information parsing but merely take the +/// result from the first router to build their sub routes. +/// +/// Most applications only need a single [Router]. +/// +/// ## URL updates for web applications +/// +/// In the web platform, keeping the URL in the browser's location bar up to +/// date with the application state ensures that the browser constructs its +/// history entry correctly, allowing its back and forward buttons to function +/// as the user expects. +/// +/// If an app state change leads to the [Router] rebuilding, the [Router] will +/// retrieve the new route information from the [routerDelegate]'s +/// [RouterDelegate.currentConfiguration] method and the +/// [routeInformationParser]'s [RouteInformationParser.restoreRouteInformation] +/// method. +/// +/// If the location in the new route information is different from the +/// current location, this is considered to be a navigation event, the +/// [PlatformRouteInformationProvider.routerReportsNewRouteInformation] method +/// calls [SystemNavigator.routeInformationUpdated] with `replace = false` to +/// notify the engine, and through that the browser, to create a history entry +/// with the new url. Otherwise, +/// [PlatformRouteInformationProvider.routerReportsNewRouteInformation] calls +/// [SystemNavigator.routeInformationUpdated] with `replace = true` to update +/// the current history entry with the latest [RouteInformation]. +/// +/// One can force the [Router] to report new route information as navigation +/// event to the [routeInformationProvider] (and thus the browser) even if the +/// [RouteInformation.uri] has not changed by calling the [Router.navigate] +/// method with a callback that performs the state change. This causes [Router] +/// to call the [RouteInformationProvider.routerReportsNewRouteInformation] with +/// [RouteInformationReportingType.navigate], and thus causes +/// [PlatformRouteInformationProvider] to push a new history entry regardlessly. +/// This allows one to support the browser's back and forward buttons without +/// changing the URL. For example, the scroll position of a scroll view may be +/// saved in the [RouteInformation.state]. Using [Router.navigate] to update the +/// scroll position causes the browser to create a new history entry with the +/// [RouteInformation.state] that stores this new scroll position. When the user +/// clicks the back button, the app will go back to the previous scroll position +/// without changing the URL in the location bar. +/// +/// One can also force the [Router] to ignore a navigation event by making +/// those changes during a callback passed to [Router.neglect]. The [Router] +/// calls the [RouteInformationProvider.routerReportsNewRouteInformation] with +/// [RouteInformationReportingType.neglect], and thus causes +/// [PlatformRouteInformationProvider] to replace the current history entry +/// regardlessly even if it detects location change. +/// +/// To opt out of URL updates entirely, pass null for [routeInformationProvider] +/// and [routeInformationParser]. This is not recommended in general, but may be +/// appropriate in the following cases: +/// +/// * The application does not target the web platform. +/// +/// * There are multiple router widgets in the application. Only one [Router] +/// widget should update the URL (typically the top-most one created by the +/// [WidgetsApp.router], [MaterialApp.router], or [CupertinoApp.router]). +/// +/// * The application does not need to implement in-app navigation using the +/// browser's back and forward buttons. +/// +/// In other cases, it is strongly recommended to implement the +/// [RouterDelegate.currentConfiguration] and +/// [RouteInformationParser.restoreRouteInformation] APIs to provide an optimal +/// user experience when running on the web platform. +/// +/// ## State Restoration +/// +/// The [Router] will restore the current configuration of the [routerDelegate] +/// during state restoration if it is configured with a [restorationScopeId] and +/// state restoration is enabled for the subtree. For that, the value of +/// [RouterDelegate.currentConfiguration] is serialized and persisted before the +/// app is killed by the operating system. After the app is restarted, the value +/// is deserialized and passed back to the [RouterDelegate] via a call to +/// [RouterDelegate.setRestoredRoutePath] (which by default just calls +/// [RouterDelegate.setNewRoutePath]). It is the responsibility of the +/// [RouterDelegate] to use the configuration information provided to restore +/// its internal state. +/// +/// To serialize [RouterDelegate.currentConfiguration] and to deserialize it +/// again, the [Router] calls [RouteInformationParser.restoreRouteInformation] +/// and [RouteInformationParser.parseRouteInformation], respectively. Therefore, +/// if a [restorationScopeId] is provided, a [routeInformationParser] must be +/// configured as well. +class Router<T> extends StatefulWidget { + /// Creates a router. + /// + /// The [routeInformationProvider] and [routeInformationParser] can be null if this + /// router does not depend on route information. A common example is a sub router + /// that builds its content completely based on the app state. + /// + /// The [routeInformationProvider] and [routeInformationParser] must + /// both be provided or not provided. + const Router({ + super.key, + this.routeInformationProvider, + this.routeInformationParser, + required this.routerDelegate, + this.backButtonDispatcher, + this.restorationScopeId, + }) : assert( + routeInformationProvider == null || routeInformationParser != null, + 'A routeInformationParser must be provided when a routeInformationProvider is specified.', + ); + + /// Creates a router with a [RouterConfig]. + /// + /// The [RouterConfig.routeInformationProvider] and + /// [RouterConfig.routeInformationParser] can be null if this router does not + /// depend on route information. A common example is a sub router that builds + /// its content completely based on the app state. + /// + /// If the [RouterConfig.routeInformationProvider] is not null, then + /// [RouterConfig.routeInformationParser] must also not be + /// null. + factory Router.withConfig({ + Key? key, + required RouterConfig<T> config, + String? restorationScopeId, + }) { + return Router<T>( + key: key, + routeInformationProvider: config.routeInformationProvider, + routeInformationParser: config.routeInformationParser, + routerDelegate: config.routerDelegate, + backButtonDispatcher: config.backButtonDispatcher, + restorationScopeId: restorationScopeId, + ); + } + + /// The route information provider for the router. + /// + /// The value at the time of first build will be used as the initial route. + /// The [Router] listens to this provider and rebuilds with new names when + /// it notifies. + /// + /// This can be null if this router does not rely on the route information + /// to build its content. In such case, the [routeInformationParser] must also + /// be null. + final RouteInformationProvider? routeInformationProvider; + + /// The route information parser for the router. + /// + /// When the [Router] gets a new route information from the [routeInformationProvider], + /// the [Router] uses this delegate to parse the route information and produce a + /// configuration. The configuration will be used by [routerDelegate] and + /// eventually rebuilds the [Router] widget. + /// + /// Since this delegate is the primary consumer of the [routeInformationProvider], + /// it must not be null if [routeInformationProvider] is not null. + final RouteInformationParser<T>? routeInformationParser; + + /// The router delegate for the router. + /// + /// This delegate consumes the configuration from [routeInformationParser] and + /// builds a navigating widget for the [Router]. + /// + /// It is also the primary respondent for the [backButtonDispatcher]. The + /// [Router] relies on [RouterDelegate.popRoute] to handle the back + /// button. + /// + /// If the [RouterDelegate.currentConfiguration] returns a non-null object, + /// this [Router] will opt for URL updates. + final RouterDelegate<T> routerDelegate; + + /// The back button dispatcher for the router. + /// + /// The two common alternatives are the [RootBackButtonDispatcher] for root + /// router, or the [ChildBackButtonDispatcher] for other routers. + final BackButtonDispatcher? backButtonDispatcher; + + /// Restoration ID to save and restore the state of the [Router]. + /// + /// If non-null, the [Router] will persist the [RouterDelegate]'s current + /// configuration (i.e. [RouterDelegate.currentConfiguration]). During state + /// restoration, the [Router] informs the [RouterDelegate] of the previous + /// configuration by calling [RouterDelegate.setRestoredRoutePath] (which by + /// default just calls [RouterDelegate.setNewRoutePath]). It is the + /// responsibility of the [RouterDelegate] to restore its internal state based + /// on the provided configuration. + /// + /// The router uses the [RouteInformationParser] to serialize and deserialize + /// [RouterDelegate.currentConfiguration]. Therefore, a + /// [routeInformationParser] must be provided when [restorationScopeId] is + /// non-null. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + final String? restorationScopeId; + + /// Retrieves the immediate [Router] ancestor from the given context. + /// + /// This method provides access to the delegates in the [Router]. For example, + /// this can be used to access the [backButtonDispatcher] of the parent router + /// when creating a [ChildBackButtonDispatcher] for a nested [Router]. + /// + /// If no [Router] ancestor exists for the given context, this will assert in + /// debug mode, and throw an exception in release mode. + /// + /// See also: + /// + /// * [maybeOf], which is a similar function, but it will return null instead + /// of throwing an exception if no [Router] ancestor exists. + static Router<T> of<T extends Object?>(BuildContext context) { + final _RouterScope? scope = context.dependOnInheritedWidgetOfExactType<_RouterScope>(); + assert(() { + if (scope == null) { + throw FlutterError( + 'Router operation requested with a context that does not include a Router.\n' + 'The context used to retrieve the Router must be that of a widget that ' + 'is a descendant of a Router widget.', + ); + } + return true; + }()); + return scope!.routerState.widget as Router<T>; + } + + /// Retrieves the immediate [Router] ancestor from the given context. + /// + /// This method provides access to the delegates in the [Router]. For example, + /// this can be used to access the [backButtonDispatcher] of the parent router + /// when creating a [ChildBackButtonDispatcher] for a nested [Router]. + /// + /// If no `Router` ancestor exists for the given context, this will return + /// null. + /// + /// See also: + /// + /// * [of], a similar method that returns a non-nullable value, and will + /// throw if no [Router] ancestor exists. + static Router<T>? maybeOf<T extends Object?>(BuildContext context) { + final _RouterScope? scope = context.dependOnInheritedWidgetOfExactType<_RouterScope>(); + return scope?.routerState.widget as Router<T>?; + } + + /// Forces the [Router] to run the [callback] and create a new history + /// entry in the browser. + /// + /// The web application relies on the [Router] to report new route information + /// in order to create browser history entry. The [Router] will only report + /// them if it detects the [RouteInformation.uri] changes. Use this + /// method if you want the [Router] to report the route information even if + /// the location does not change. This can be useful when you want to + /// support the browser backward and forward button without changing the URL. + /// + /// For example, you can store certain state such as the scroll position into + /// the [RouteInformation.state]. If you use this method to update the + /// scroll position multiple times with the same URL, the browser will create + /// a stack of new history entries with the same URL but different + /// [RouteInformation.state]s that store the new scroll positions. If the user + /// click the backward button in the browser, the browser will restore the + /// scroll positions saved in history entries without changing the URL. + /// + /// See also: + /// + /// * [Router]: see the "URL updates for web applications" section for more + /// information about route information reporting. + /// * [neglect]: which forces the [Router] to not create a new history entry + /// even if location does change. + static void navigate(BuildContext context, VoidCallback callback) { + final _RouterScope scope = context + .getElementForInheritedWidgetOfExactType<_RouterScope>()! + .widget as _RouterScope; + scope.routerState._setStateWithExplicitReportStatus(RouteInformationReportingType.navigate, callback); + } + + /// Forces the [Router] to run the [callback] without creating a new history + /// entry in the browser. + /// + /// The web application relies on the [Router] to report new route information + /// in order to create browser history entry. The [Router] will report them + /// automatically if it detects the [RouteInformation.uri] changes. + /// + /// Creating a new route history entry makes users feel they have visited a + /// new page, and the browser back button brings them back to previous history + /// entry. Use this method if you don't want the [Router] to create a new + /// route information even if it detects changes as a result of running the + /// [callback]. + /// + /// Using this method will still update the URL and state in current history + /// entry. + /// + /// See also: + /// + /// * [Router]: see the "URL updates for web applications" section for more + /// information about route information reporting. + /// * [navigate]: which forces the [Router] to create a new history entry + /// even if location does not change. + static void neglect(BuildContext context, VoidCallback callback) { + final _RouterScope scope = context + .getElementForInheritedWidgetOfExactType<_RouterScope>()! + .widget as _RouterScope; + scope.routerState._setStateWithExplicitReportStatus(RouteInformationReportingType.neglect, callback); + } + + @override + State<Router<T>> createState() => _RouterState<T>(); +} + +typedef _AsyncPassthrough<Q> = Future<Q> Function(Q); +typedef _RouteSetter<T> = Future<void> Function(T); + +/// The [Router]'s intention when it reports a new [RouteInformation] to the +/// [RouteInformationProvider]. +/// +/// See also: +/// +/// * [RouteInformationProvider.routerReportsNewRouteInformation]: which is +/// called by the router when it has a new route information to report. +enum RouteInformationReportingType { + /// Router does not have a specific intention. + /// + /// The router generates a new route information every time it detects route + /// information may have change due to a rebuild. This is the default type if + /// neither [Router.neglect] nor [Router.navigate] was used during the + /// rebuild. + none, + /// The accompanying [RouteInformation] were generated during a + /// [Router.neglect] call. + neglect, + /// The accompanying [RouteInformation] were generated during a + /// [Router.navigate] call. + navigate, +} + +class _RouterState<T> extends State<Router<T>> with RestorationMixin { + Object? _currentRouterTransaction; + RouteInformationReportingType? _currentIntentionToReport; + final _RestorableRouteInformation _routeInformation = _RestorableRouteInformation(); + late bool _routeParsePending; + + @override + String? get restorationId => widget.restorationScopeId; + + @override + void initState() { + super.initState(); + widget.routeInformationProvider?.addListener(_handleRouteInformationProviderNotification); + widget.backButtonDispatcher?.addCallback(_handleBackButtonDispatcherNotification); + widget.routerDelegate.addListener(_handleRouterDelegateNotification); + } + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_routeInformation, 'route'); + if (_routeInformation.value != null) { + assert(widget.routeInformationParser != null); + _processRouteInformation(_routeInformation.value!, () => widget.routerDelegate.setRestoredRoutePath); + } else if (widget.routeInformationProvider != null) { + _processRouteInformation(widget.routeInformationProvider!.value, () => widget.routerDelegate.setInitialRoutePath); + } + } + + bool _routeInformationReportingTaskScheduled = false; + + void _scheduleRouteInformationReportingTask() { + if (_routeInformationReportingTaskScheduled || widget.routeInformationProvider == null) { + return; + } + assert(_currentIntentionToReport != null); + _routeInformationReportingTaskScheduled = true; + SchedulerBinding.instance.addPostFrameCallback( + _reportRouteInformation, + debugLabel: 'Router.reportRouteInfo', + ); + } + + void _reportRouteInformation(Duration timestamp) { + if (!mounted) { + return; + } + + assert(_routeInformationReportingTaskScheduled); + _routeInformationReportingTaskScheduled = false; + + if (_routeInformation.value != null) { + final RouteInformation currentRouteInformation = _routeInformation.value!; + assert(_currentIntentionToReport != null); + widget.routeInformationProvider!.routerReportsNewRouteInformation(currentRouteInformation, type: _currentIntentionToReport!); + } + _currentIntentionToReport = RouteInformationReportingType.none; + } + + RouteInformation? _retrieveNewRouteInformation() { + final T? configuration = widget.routerDelegate.currentConfiguration; + if (configuration == null) { + return null; + } + return widget.routeInformationParser?.restoreRouteInformation(configuration); + } + + void _setStateWithExplicitReportStatus( + RouteInformationReportingType status, + VoidCallback fn, + ) { + assert(status.index >= RouteInformationReportingType.neglect.index); + assert(() { + if (_currentIntentionToReport != null && + _currentIntentionToReport != RouteInformationReportingType.none && + _currentIntentionToReport != status) { + FlutterError.reportError( + const FlutterErrorDetails( + exception: + 'Both Router.navigate and Router.neglect have been called in this ' + 'build cycle, and the Router cannot decide whether to report the ' + 'route information. Please make sure only one of them is called ' + 'within the same build cycle.', + ), + ); + } + return true; + }()); + _currentIntentionToReport = status; + _scheduleRouteInformationReportingTask(); + fn(); + } + + void _maybeNeedToReportRouteInformation() { + _routeInformation.value = _retrieveNewRouteInformation(); + _currentIntentionToReport ??= RouteInformationReportingType.none; + _scheduleRouteInformationReportingTask(); + } + + @override + void didChangeDependencies() { + _routeParsePending = true; + super.didChangeDependencies(); + // The super.didChangeDependencies may have parsed the route information. + // This can happen if the didChangeDependencies is triggered by state + // restoration or first build. + if (widget.routeInformationProvider != null && _routeParsePending) { + _processRouteInformation(widget.routeInformationProvider!.value, () => widget.routerDelegate.setNewRoutePath); + } + _routeParsePending = false; + _maybeNeedToReportRouteInformation(); + } + + @override + void didUpdateWidget(Router<T> oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.routeInformationProvider != oldWidget.routeInformationProvider || + widget.backButtonDispatcher != oldWidget.backButtonDispatcher || + widget.routeInformationParser != oldWidget.routeInformationParser || + widget.routerDelegate != oldWidget.routerDelegate) { + _currentRouterTransaction = Object(); + } + if (widget.routeInformationProvider != oldWidget.routeInformationProvider) { + oldWidget.routeInformationProvider?.removeListener(_handleRouteInformationProviderNotification); + widget.routeInformationProvider?.addListener(_handleRouteInformationProviderNotification); + if (oldWidget.routeInformationProvider?.value != widget.routeInformationProvider?.value) { + _handleRouteInformationProviderNotification(); + } + } + if (widget.backButtonDispatcher != oldWidget.backButtonDispatcher) { + oldWidget.backButtonDispatcher?.removeCallback(_handleBackButtonDispatcherNotification); + widget.backButtonDispatcher?.addCallback(_handleBackButtonDispatcherNotification); + } + if (widget.routerDelegate != oldWidget.routerDelegate) { + oldWidget.routerDelegate.removeListener(_handleRouterDelegateNotification); + widget.routerDelegate.addListener(_handleRouterDelegateNotification); + _maybeNeedToReportRouteInformation(); + } + } + + @override + void dispose() { + _routeInformation.dispose(); + widget.routeInformationProvider?.removeListener(_handleRouteInformationProviderNotification); + widget.backButtonDispatcher?.removeCallback(_handleBackButtonDispatcherNotification); + widget.routerDelegate.removeListener(_handleRouterDelegateNotification); + _currentRouterTransaction = null; + super.dispose(); + } + + void _processRouteInformation(RouteInformation information, ValueGetter<_RouteSetter<T>> delegateRouteSetter) { + assert(_routeParsePending); + _routeParsePending = false; + _currentRouterTransaction = Object(); + widget.routeInformationParser! + .parseRouteInformationWithDependencies(information, context) + .then<void>(_processParsedRouteInformation(_currentRouterTransaction, delegateRouteSetter)); + } + + _RouteSetter<T> _processParsedRouteInformation(Object? transaction, ValueGetter<_RouteSetter<T>> delegateRouteSetter) { + return (T data) async { + if (_currentRouterTransaction != transaction) { + return; + } + await delegateRouteSetter()(data); + if (_currentRouterTransaction == transaction) { + _rebuild(); + } + }; + } + + void _handleRouteInformationProviderNotification() { + _routeParsePending = true; + _processRouteInformation(widget.routeInformationProvider!.value, () => widget.routerDelegate.setNewRoutePath); + } + + Future<bool> _handleBackButtonDispatcherNotification() { + _currentRouterTransaction = Object(); + return widget.routerDelegate + .popRoute() + .then<bool>(_handleRoutePopped(_currentRouterTransaction)); + } + + _AsyncPassthrough<bool> _handleRoutePopped(Object? transaction) { + return (bool data) { + if (transaction != _currentRouterTransaction) { + // A rebuilt was trigger from a different source. Returns true to + // prevent bubbling. + return SynchronousFuture<bool>(true); + } + _rebuild(); + return SynchronousFuture<bool>(data); + }; + } + + Future<void> _rebuild([void value]) { + setState(() {/* routerDelegate is ready to rebuild */}); + _maybeNeedToReportRouteInformation(); + return SynchronousFuture<void>(value); + } + + void _handleRouterDelegateNotification() { + setState(() {/* routerDelegate wants to rebuild */}); + _maybeNeedToReportRouteInformation(); + } + + @override + Widget build(BuildContext context) { + return UnmanagedRestorationScope( + bucket: bucket, + child: _RouterScope( + routeInformationProvider: widget.routeInformationProvider, + backButtonDispatcher: widget.backButtonDispatcher, + routeInformationParser: widget.routeInformationParser, + routerDelegate: widget.routerDelegate, + routerState: this, + child: Builder( + // Use a Builder so that the build method below will have a + // BuildContext that contains the _RouterScope. This also prevents + // dependencies look ups in routerDelegate from rebuilding Router + // widget that may result in re-parsing the route information. + builder: widget.routerDelegate.build, + ), + ), + ); + } +} + +class _RouterScope extends InheritedWidget { + const _RouterScope({ + required this.routeInformationProvider, + required this.backButtonDispatcher, + required this.routeInformationParser, + required this.routerDelegate, + required this.routerState, + required super.child, + }) : assert(routeInformationProvider == null || routeInformationParser != null); + + final ValueListenable<RouteInformation?>? routeInformationProvider; + final BackButtonDispatcher? backButtonDispatcher; + final RouteInformationParser<Object?>? routeInformationParser; + final RouterDelegate<Object?> routerDelegate; + final _RouterState<Object?> routerState; + + @override + bool updateShouldNotify(_RouterScope oldWidget) { + return routeInformationProvider != oldWidget.routeInformationProvider || + backButtonDispatcher != oldWidget.backButtonDispatcher || + routeInformationParser != oldWidget.routeInformationParser || + routerDelegate != oldWidget.routerDelegate || + routerState != oldWidget.routerState; + } +} + +/// A class that can be extended or mixed in that invokes a single callback, +/// which then returns a value. +/// +/// While multiple callbacks can be registered, when a notification is +/// dispatched there must be only a single callback. The return values of +/// multiple callbacks are not aggregated. +/// +/// `T` is the return value expected from the callback. +/// +/// See also: +/// +/// * [Listenable] and its subclasses, which provide a similar mechanism for +/// one-way signaling. +class _CallbackHookProvider<T> { + final ObserverList<ValueGetter<T>> _callbacks = ObserverList<ValueGetter<T>>(); + + /// Whether a callback is currently registered. + @protected + bool get hasCallbacks => _callbacks.isNotEmpty; + + /// Register the callback to be called when the object changes. + /// + /// If other callbacks have already been registered, they must be removed + /// (with [removeCallback]) before the callback is next called. + void addCallback(ValueGetter<T> callback) => _callbacks.add(callback); + + /// Remove a previously registered callback. + /// + /// If the given callback is not registered, the call is ignored. + void removeCallback(ValueGetter<T> callback) => _callbacks.remove(callback); + + /// Calls the (single) registered callback and returns its result. + /// + /// If no callback is registered, or if the callback throws, returns + /// `defaultValue`. + /// + /// Call this method whenever the callback is to be invoked. If there is more + /// than one callback registered, this method will throw a [StateError]. + /// + /// Exceptions thrown by callbacks will be caught and reported using + /// [FlutterError.reportError]. + @protected + @pragma('vm:notify-debugger-on-exception') + T invokeCallback(T defaultValue) { + if (_callbacks.isEmpty) { + return defaultValue; + } + try { + return _callbacks.single(); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widget library', + context: ErrorDescription('while invoking the callback for $runtimeType'), + informationCollector: () => <DiagnosticsNode>[ + DiagnosticsProperty<_CallbackHookProvider<T>>( + 'The $runtimeType that invoked the callback was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + ], + )); + return defaultValue; + } + } +} + +/// Report to a [Router] when the user taps the back button on platforms that +/// support back buttons (such as Android). +/// +/// When [Router] widgets are nested, consider using a +/// [ChildBackButtonDispatcher], passing it the parent [BackButtonDispatcher], +/// so that the back button requests get dispatched to the appropriate [Router]. +/// To make this work properly, it's important that whenever a [Router] thinks +/// it should get the back button messages (e.g. after the user taps inside it), +/// it calls [takePriority] on its [BackButtonDispatcher] (or +/// [ChildBackButtonDispatcher]) instance. +/// +/// The class takes a single callback, which must return a [Future<bool>]. The +/// callback's semantics match [WidgetsBindingObserver.didPopRoute]'s, namely, +/// the callback should return a future that completes to true if it can handle +/// the pop request, and a future that completes to false otherwise. +abstract class BackButtonDispatcher extends _CallbackHookProvider<Future<bool>> { + late final LinkedHashSet<ChildBackButtonDispatcher> _children = + <ChildBackButtonDispatcher>{} as LinkedHashSet<ChildBackButtonDispatcher>; + + @override + bool get hasCallbacks => super.hasCallbacks || (_children.isNotEmpty); + + /// Handles a pop route request. + /// + /// This method prioritizes the children list in reverse order and calls + /// [ChildBackButtonDispatcher.notifiedByParent] on them. If any of them + /// handles the request (by returning a future with true), it exits this + /// method by returning this future. Otherwise, it keeps moving on to the next + /// child until a child handles the request. If none of the children handles + /// the request, this back button dispatcher will then try to handle the request + /// by itself. This back button dispatcher handles the request by notifying the + /// router which in turn calls the [RouterDelegate.popRoute] and returns its + /// result. + /// + /// To decide whether this back button dispatcher will handle the pop route + /// request, you can override the [RouterDelegate.popRoute] of the router + /// delegate you pass into the router with this back button dispatcher to + /// return a future of true or false. + @override + Future<bool> invokeCallback(Future<bool> defaultValue) { + if (_children.isNotEmpty) { + final List<ChildBackButtonDispatcher> children = _children.toList(); + int childIndex = children.length - 1; + + Future<bool> notifyNextChild(bool result) { + // If the previous child handles the callback, we return the result. + if (result) { + return SynchronousFuture<bool>(result); + } + // If the previous child did not handle the callback, we ask the next + // child to handle the it. + if (childIndex > 0) { + childIndex -= 1; + return children[childIndex] + .notifiedByParent(defaultValue) + .then<bool>(notifyNextChild); + } + // If none of the child handles the callback, the parent will then handle it. + return super.invokeCallback(defaultValue); + } + + return children[childIndex] + .notifiedByParent(defaultValue) + .then<bool>(notifyNextChild); + } + return super.invokeCallback(defaultValue); + } + + /// Creates a [ChildBackButtonDispatcher] that is a direct descendant of this + /// back button dispatcher. + /// + /// To participate in handling the pop route request, call the [takePriority] + /// on the [ChildBackButtonDispatcher] created from this method. + /// + /// When the pop route request is handled by this back button dispatcher, it + /// propagate the request to its direct descendants that have called the + /// [takePriority] method. If there are multiple candidates, the latest one + /// that called the [takePriority] wins the right to handle the request. If + /// the latest one does not handle the request (by returning a future of + /// false in [ChildBackButtonDispatcher.notifiedByParent]), the second latest + /// one will then have the right to handle the request. This dispatcher + /// continues finding the next candidate until there are no more candidates + /// and finally handles the request itself. + ChildBackButtonDispatcher createChildBackButtonDispatcher() { + return ChildBackButtonDispatcher(this); + } + + /// Make this [BackButtonDispatcher] take priority among its peers. + /// + /// This has no effect when a [BackButtonDispatcher] has no parents and no + /// children. If a [BackButtonDispatcher] does have parents or children, + /// however, it causes this object to be the one to dispatch the notification + /// when the parent would normally notify its callback. + /// + /// The [BackButtonDispatcher] must have a listener registered before it can + /// be told to take priority. + void takePriority() => _children.clear(); + + /// Mark the given child as taking priority over this object and the other + /// children. + /// + /// This causes [invokeCallback] to defer to the given child instead of + /// calling this object's callback. + /// + /// Children are stored in a list, so that if the current child is removed + /// using [forget], a previous child will return to take its place. When + /// [takePriority] is called, the list is cleared. + /// + /// Calling this again without first calling [forget] moves the child back to + /// the head of the list. + /// + /// The [BackButtonDispatcher] must have a listener registered before it can + /// be told to defer to a child. + void deferTo(ChildBackButtonDispatcher child) { + assert(hasCallbacks); + _children.remove(child); // child may or may not be in the set already + _children.add(child); + } + + /// Causes the given child to be removed from the list of children to which + /// this object might defer, as if [deferTo] had never been called for that + /// child. + /// + /// This should only be called once per child, even if [deferTo] was called + /// multiple times for that child. + /// + /// If no children are left in the list, this object will stop deferring to + /// its children. (This is not the same as calling [takePriority], since, if + /// this object itself is a [ChildBackButtonDispatcher], [takePriority] would + /// additionally attempt to claim priority from its parent, whereas removing + /// the last child does not.) + void forget(ChildBackButtonDispatcher child) => _children.remove(child); +} + +/// The default implementation of back button dispatcher for the root router. +/// +/// This dispatcher listens to platform pop route notifications. When the +/// platform wants to pop the current route, this dispatcher calls the +/// [BackButtonDispatcher.invokeCallback] method to handle the request. +class RootBackButtonDispatcher extends BackButtonDispatcher with WidgetsBindingObserver { + /// Create a root back button dispatcher. + RootBackButtonDispatcher(); + + @override + void addCallback(ValueGetter<Future<bool>> callback) { + if (!hasCallbacks) { + WidgetsBinding.instance.addObserver(this); + } + super.addCallback(callback); + } + + @override + void removeCallback(ValueGetter<Future<bool>> callback) { + super.removeCallback(callback); + if (!hasCallbacks) { + WidgetsBinding.instance.removeObserver(this); + } + } + + @override + Future<bool> didPopRoute() => invokeCallback(Future<bool>.value(false)); +} + +/// A variant of [BackButtonDispatcher] which listens to notifications from a +/// parent back button dispatcher, and can take priority from its parent for the +/// handling of such notifications. +/// +/// Useful when [Router]s are being nested within each other. +/// +/// Use [Router.of] to obtain a reference to the nearest ancestor [Router], from +/// which the [Router.backButtonDispatcher] can be found, and then used as the +/// [parent] of the [ChildBackButtonDispatcher]. +class ChildBackButtonDispatcher extends BackButtonDispatcher { + /// Creates a back button dispatcher that acts as the child of another. + ChildBackButtonDispatcher(this.parent); + + /// The back button dispatcher that this object will attempt to take priority + /// over when [takePriority] is called. + /// + /// The parent must have a listener registered before this child object can + /// have its [takePriority] or [deferTo] methods used. + final BackButtonDispatcher parent; + + /// The parent of this child back button dispatcher decide to let this + /// child to handle the invoke the callback request in + /// [BackButtonDispatcher.invokeCallback]. + /// + /// Return a boolean future with true if this child will handle the request; + /// otherwise, return a boolean future with false. + @protected + Future<bool> notifiedByParent(Future<bool> defaultValue) { + return invokeCallback(defaultValue); + } + + @override + void takePriority() { + parent.deferTo(this); + super.takePriority(); + } + + @override + void deferTo(ChildBackButtonDispatcher child) { + assert(hasCallbacks); + parent.deferTo(this); + super.deferTo(child); + } + + @override + void removeCallback(ValueGetter<Future<bool>> callback) { + super.removeCallback(callback); + if (!hasCallbacks) { + parent.forget(this); + } + } +} + +/// A convenience widget that registers a callback for when the back button is pressed. +/// +/// In order to use this widget, there must be an ancestor [Router] widget in the tree +/// that has a [RootBackButtonDispatcher]. e.g. The [Router] widget created by the +/// [MaterialApp.router] has a built-in [RootBackButtonDispatcher] by default. +/// +/// It only applies to platforms that accept back button clicks, such as Android. +/// +/// It can be useful for scenarios, in which you create a different state in your +/// screen but don't want to use a new page for that. +class BackButtonListener extends StatefulWidget { + /// Creates a BackButtonListener widget . + const BackButtonListener({ + super.key, + required this.child, + required this.onBackButtonPressed, + }); + + /// The widget below this widget in the tree. + final Widget child; + + /// The callback function that will be called when the back button is pressed. + /// + /// It must return a boolean future with true if this child will handle the request; + /// otherwise, return a boolean future with false. + final ValueGetter<Future<bool>> onBackButtonPressed; + + @override + State<BackButtonListener> createState() => _BackButtonListenerState(); +} + +class _BackButtonListenerState extends State<BackButtonListener> { + BackButtonDispatcher? dispatcher; + + @override + void didChangeDependencies() { + dispatcher?.removeCallback(widget.onBackButtonPressed); + + final BackButtonDispatcher? rootBackDispatcher = Router.of(context).backButtonDispatcher; + assert(rootBackDispatcher != null, 'The parent router must have a backButtonDispatcher to use this widget'); + + dispatcher = rootBackDispatcher!.createChildBackButtonDispatcher() + ..addCallback(widget.onBackButtonPressed) + ..takePriority(); + super.didChangeDependencies(); + } + + @override + void didUpdateWidget(covariant BackButtonListener oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.onBackButtonPressed != widget.onBackButtonPressed) { + dispatcher?.removeCallback(oldWidget.onBackButtonPressed); + dispatcher?.addCallback(widget.onBackButtonPressed); + dispatcher?.takePriority(); + } + } + + @override + void dispose() { + dispatcher?.removeCallback(widget.onBackButtonPressed); + super.dispose(); + } + + @override + Widget build(BuildContext context) => widget.child; +} + +/// A delegate that is used by the [Router] widget to parse a route information +/// into a configuration of type T. +/// +/// This delegate is used when the [Router] widget is first built with initial +/// route information from [Router.routeInformationProvider] and any subsequent +/// new route notifications from it. The [Router] widget calls the [parseRouteInformation] +/// with the route information from [Router.routeInformationProvider]. +/// +/// One of the [parseRouteInformation] or +/// [parseRouteInformationWithDependencies] must be implemented, otherwise a +/// runtime error will be thrown. +abstract class RouteInformationParser<T> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const RouteInformationParser(); + + /// {@template flutter.widgets.RouteInformationParser.parseRouteInformation} + /// Converts the given route information into parsed data to pass to a + /// [RouterDelegate]. + /// + /// The method should return a future which completes when the parsing is + /// complete. The parsing may be asynchronous if, e.g., the parser needs to + /// communicate with the OEM thread to obtain additional data about the route. + /// + /// Consider using a [SynchronousFuture] if the result can be computed + /// synchronously, so that the [Router] does not need to wait for the next + /// microtask to pass the data to the [RouterDelegate]. + /// {@endtemplate} + /// + /// One can implement [parseRouteInformationWithDependencies] instead if + /// the parsing depends on other dependencies from the [BuildContext]. + Future<T> parseRouteInformation(RouteInformation routeInformation) { + throw UnimplementedError( + 'One of the parseRouteInformation or ' + 'parseRouteInformationWithDependencies must be implemented' + ); + } + + /// {@macro flutter.widgets.RouteInformationParser.parseRouteInformation} + /// + /// The input [BuildContext] can be used for looking up [InheritedWidget]s + /// If one uses [BuildContext.dependOnInheritedWidgetOfExactType], a + /// dependency will be created. The [Router] will re-parse the + /// [RouteInformation] from its [RouteInformationProvider] if the dependency + /// notifies its listeners. + /// + /// One can also use [BuildContext.getElementForInheritedWidgetOfExactType] to + /// look up [InheritedWidget]s without creating dependencies. + Future<T> parseRouteInformationWithDependencies(RouteInformation routeInformation, BuildContext context) { + return parseRouteInformation(routeInformation); + } + + /// Restore the route information from the given configuration. + /// + /// This may return null, in which case the browser history will not be + /// updated and state restoration is disabled. See [Router]'s documentation + /// for details. + /// + /// The [parseRouteInformation] method must produce an equivalent + /// configuration when passed this method's return value. + RouteInformation? restoreRouteInformation(T configuration) => null; +} + +/// A delegate that is used by the [Router] widget to build and configure a +/// navigating widget. +/// +/// This delegate is the core piece of the [Router] widget. It responds to +/// push route and pop route intents from the engine and notifies the [Router] +/// to rebuild. It also acts as a builder for the [Router] widget and builds a +/// navigating widget, typically a [Navigator], when the [Router] widget +/// builds. +/// +/// When the engine pushes a new route, the route information is parsed by the +/// [RouteInformationParser] to produce a configuration of type T. The router +/// delegate receives the configuration through [setInitialRoutePath] or +/// [setNewRoutePath] to configure itself and builds the latest navigating +/// widget when asked ([build]). +/// +/// When implementing subclasses, consider defining a [Listenable] app state object to be +/// used for building the navigating widget. The router delegate would update +/// the app state accordingly and notify its own listeners when the app state has +/// changed and when it receive route related engine intents (e.g. +/// [setNewRoutePath], [setInitialRoutePath], or [popRoute]). +/// +/// All subclass must implement [setNewRoutePath], [popRoute], and [build]. +/// +/// ## State Restoration +/// +/// If the [Router] owning this delegate is configured for state restoration, it +/// will persist and restore the configuration of this [RouterDelegate] using +/// the following mechanism: Before the app is killed by the operating system, +/// the value of [currentConfiguration] is serialized out and persisted. After +/// the app has restarted, the value is deserialized and passed back to the +/// [RouterDelegate] via a call to [setRestoredRoutePath] (which by default just +/// calls [setNewRoutePath]). It is the responsibility of the [RouterDelegate] +/// to use the configuration information provided to restore its internal state. +/// +/// See also: +/// +/// * [RouteInformationParser], which is responsible for parsing the route +/// information to a configuration before passing in to router delegate. +/// * [Router], which is the widget that wires all the delegates together to +/// provide a fully functional routing solution. +abstract class RouterDelegate<T> extends Listenable { + /// Called by the [Router] at startup with the structure that the + /// [RouteInformationParser] obtained from parsing the initial route. + /// + /// This should configure the [RouterDelegate] so that when [build] is + /// invoked, it will create a widget tree that matches the initial route. + /// + /// By default, this method forwards the [configuration] to [setNewRoutePath]. + /// + /// Consider using a [SynchronousFuture] if the result can be computed + /// synchronously, so that the [Router] does not need to wait for the next + /// microtask to schedule a build. + /// + /// See also: + /// + /// * [setRestoredRoutePath], which is called instead of this method during + /// state restoration. + Future<void> setInitialRoutePath(T configuration) { + return setNewRoutePath(configuration); + } + + /// Called by the [Router] during state restoration. + /// + /// When the [Router] is configured for state restoration, it will persist + /// the value of [currentConfiguration] during state serialization. During + /// state restoration, the [Router] calls this method (instead of + /// [setInitialRoutePath]) to pass the previous configuration back to the + /// delegate. It is the responsibility of the delegate to restore its internal + /// state based on the provided configuration. + /// + /// By default, this method forwards the `configuration` to [setNewRoutePath]. + Future<void> setRestoredRoutePath(T configuration) { + return setNewRoutePath(configuration); + } + + /// Called by the [Router] when the [Router.routeInformationProvider] reports that a + /// new route has been pushed to the application by the operating system. + /// + /// Consider using a [SynchronousFuture] if the result can be computed + /// synchronously, so that the [Router] does not need to wait for the next + /// microtask to schedule a build. + Future<void> setNewRoutePath(T configuration); + + /// Called by the [Router] when the [Router.backButtonDispatcher] reports that + /// the operating system is requesting that the current route be popped. + /// + /// The method should return a boolean [Future] to indicate whether this + /// delegate handles the request. Returning false will cause the entire app + /// to be popped. + /// + /// Consider using a [SynchronousFuture] if the result can be computed + /// synchronously, so that the [Router] does not need to wait for the next + /// microtask to schedule a build. + Future<bool> popRoute(); + + /// Called by the [Router] when it detects a route information may have + /// changed as a result of rebuild. + /// + /// If this getter returns non-null, the [Router] will start to report new + /// route information back to the engine. In web applications, the new + /// route information is used for populating browser history in order to + /// support the forward and the backward buttons. + /// + /// When overriding this method, the configuration returned by this getter + /// must be able to construct the current app state and build the widget + /// with the same configuration in the [build] method if it is passed back + /// to the [setNewRoutePath]. Otherwise, the browser backward and forward + /// buttons will not work properly. + /// + /// By default, this getter returns null, which prevents the [Router] from + /// reporting the route information. To opt in, a subclass can override this + /// getter to return the current configuration. + /// + /// At most one [Router] can opt in to route information reporting. Typically, + /// only the top-most [Router] created by [WidgetsApp.router] should opt for + /// route information reporting. + /// + /// ## State Restoration + /// + /// This getter is also used by the [Router] to implement state restoration. + /// During state serialization, the [Router] will persist the current + /// configuration and during state restoration pass it back to the delegate + /// by calling [setRestoredRoutePath]. + T? get currentConfiguration => null; + + /// Called by the [Router] to obtain the widget tree that represents the + /// current state. + /// + /// This is called whenever the [Future]s returned by [setInitialRoutePath], + /// [setNewRoutePath], or [setRestoredRoutePath] complete as well as when this + /// notifies its clients (see the [Listenable] interface, which this interface + /// includes). In addition, it may be called at other times. It is important, + /// therefore, that the methods above do not update the state that the [build] + /// method uses before they complete their respective futures. + /// + /// Typically this method returns a suitably-configured [Navigator]. If you do + /// plan to create a navigator, consider using the + /// [PopNavigatorRouterDelegateMixin]. If state restoration is enabled for the + /// [Router] using this delegate, consider providing a non-null + /// [Navigator.restorationScopeId] to the [Navigator] returned by this method. + /// + /// This method must not return null. + /// + /// The `context` is the [Router]'s build context. + Widget build(BuildContext context); +} + +/// A route information provider that provides route information for the +/// [Router] widget +/// +/// This provider is responsible for handing the route information through [value] +/// getter and notifies listeners, typically the [Router] widget, when a new +/// route information is available. +/// +/// When the router opts for route information reporting (by overriding the +/// [RouterDelegate.currentConfiguration] to return non-null), override the +/// [routerReportsNewRouteInformation] method to process the route information. +/// +/// See also: +/// +/// * [PlatformRouteInformationProvider], which wires up the itself with the +/// [WidgetsBindingObserver.didPushRoute] to propagate platform push route +/// intent to the [Router] widget, as well as reports new route information +/// from the [Router] back to the engine by overriding the +/// [routerReportsNewRouteInformation]. +abstract class RouteInformationProvider extends ValueListenable<RouteInformation> { + /// A callback called when the [Router] widget reports new route information + /// + /// The subclasses can override this method to update theirs values or trigger + /// other side effects. For example, the [PlatformRouteInformationProvider] + /// overrides this method to report the route information back to the engine. + /// + /// The `routeInformation` is the new route information generated by the + /// Router rebuild, and it can be the same or different from the + /// [value]. + /// + /// The `type` denotes the [Router]'s intention when it reports this + /// `routeInformation`. It is useful when deciding how to update the internal + /// state of [RouteInformationProvider] subclass with the `routeInformation`. + /// For example, [PlatformRouteInformationProvider] uses this property to + /// decide whether to push or replace the browser history entry with the new + /// `routeInformation`. + /// + /// For more information on how [Router] determines a navigation event, see + /// the "URL updates for web applications" section in the [Router] + /// documentation. + void routerReportsNewRouteInformation(RouteInformation routeInformation, {RouteInformationReportingType type = RouteInformationReportingType.none}) {} +} + +/// The route information provider that propagates the platform route information changes. +/// +/// This provider also reports the new route information from the [Router] widget +/// back to engine using message channel method, the +/// [SystemNavigator.routeInformationUpdated]. +/// +/// Each time [SystemNavigator.routeInformationUpdated] is called, the +/// [SystemNavigator.selectMultiEntryHistory] method is also called. This +/// overrides the initialization behavior of +/// [Navigator.reportsRouteUpdateToEngine]. +class PlatformRouteInformationProvider extends RouteInformationProvider with WidgetsBindingObserver, ChangeNotifier { + /// Create a platform route information provider. + /// + /// Use the [initialRouteInformation] to set the default route information for this + /// provider. + PlatformRouteInformationProvider({ + required RouteInformation initialRouteInformation, + }) : _value = initialRouteInformation { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + static bool _equals(Uri a, Uri b) { + return a.path == b.path + && a.fragment == b.fragment + && const DeepCollectionEquality.unordered().equals(a.queryParametersAll, b.queryParametersAll); + } + + @override + void routerReportsNewRouteInformation(RouteInformation routeInformation, {RouteInformationReportingType type = RouteInformationReportingType.none}) { + final bool replace = + type == RouteInformationReportingType.neglect || + (type == RouteInformationReportingType.none && + _equals(_valueInEngine.uri, routeInformation.uri)); + SystemNavigator.selectMultiEntryHistory(); + SystemNavigator.routeInformationUpdated( + uri: routeInformation.uri, + state: routeInformation.state, + replace: replace, + ); + _value = routeInformation; + _valueInEngine = routeInformation; + } + + @override + RouteInformation get value => _value; + RouteInformation _value; + + RouteInformation _valueInEngine = RouteInformation(uri: Uri.parse(WidgetsBinding.instance.platformDispatcher.defaultRouteName)); + + void _platformReportsNewRouteInformation(RouteInformation routeInformation) { + if (_value == routeInformation) { + return; + } + _value = routeInformation; + _valueInEngine = routeInformation; + notifyListeners(); + } + + @override + void addListener(VoidCallback listener) { + if (!hasListeners) { + WidgetsBinding.instance.addObserver(this); + } + super.addListener(listener); + } + + @override + void removeListener(VoidCallback listener) { + super.removeListener(listener); + if (!hasListeners) { + WidgetsBinding.instance.removeObserver(this); + } + } + + @override + void dispose() { + // In practice, this will rarely be called. We assume that the listeners + // will be added and removed in a coherent fashion such that when the object + // is no longer being used, there's no listener, and so it will get garbage + // collected. + if (hasListeners) { + WidgetsBinding.instance.removeObserver(this); + } + super.dispose(); + } + + @override + Future<bool> didPushRouteInformation(RouteInformation routeInformation) async { + assert(hasListeners); + _platformReportsNewRouteInformation(routeInformation); + return true; + } +} + +/// A mixin that wires [RouterDelegate.popRoute] to the [Navigator] it builds. +/// +/// This mixin calls [Navigator.maybePop] when it receives an Android back +/// button intent through the [RouterDelegate.popRoute]. Using this mixin +/// guarantees that the back button still respects pageless routes in the +/// navigator. +/// +/// Only use this mixin if you plan to build a navigator in the +/// [RouterDelegate.build]. +mixin PopNavigatorRouterDelegateMixin<T> on RouterDelegate<T> { + /// The key used for retrieving the current navigator. + /// + /// When using this mixin, be sure to use this key to create the navigator. + GlobalKey<NavigatorState>? get navigatorKey; + + @override + Future<bool> popRoute() { + final NavigatorState? navigator = navigatorKey?.currentState; + if (navigator == null) { + return SynchronousFuture<bool>(false); + } + return navigator.maybePop(); + } +} + +class _RestorableRouteInformation extends RestorableValue<RouteInformation?> { + @override + RouteInformation? createDefaultValue() => null; + + @override + void didUpdateValue(RouteInformation? oldValue) { + notifyListeners(); + } + + @override + RouteInformation? fromPrimitives(Object? data) { + if (data == null) { + return null; + } + assert(data is List<Object?> && data.length == 2); + final List<Object?> castedData = data as List<Object?>; + final String? uri = castedData.first as String?; + if (uri == null) { + return null; + } + return RouteInformation(uri: Uri.parse(uri), state: castedData.last); + } + + @override + Object? toPrimitives() { + return value == null ? null : <Object?>[value!.uri.toString(), value!.state]; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/routes.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/routes.dart new file mode 100644 index 0000000000000000000000000000000000000000..8f00436dcf3dc7c1c57eb289c5fa239a69c4f3c9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/routes.dart @@ -0,0 +1,2322 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'actions.dart'; +import 'basic.dart'; +import 'display_feature_sub_screen.dart'; +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'focus_traversal.dart'; +import 'framework.dart'; +import 'modal_barrier.dart'; +import 'navigator.dart'; +import 'overlay.dart'; +import 'page_storage.dart'; +import 'primary_scroll_controller.dart'; +import 'restoration.dart'; +import 'scroll_controller.dart'; +import 'transitions.dart'; + +// Examples can assume: +// late NavigatorState navigator; +// late BuildContext context; +// Future<bool> askTheUserIfTheyAreSure() async { return true; } +// abstract class MyWidget extends StatefulWidget { const MyWidget({super.key}); } +// late dynamic _myState, newValue; +// late StateSetter setState; + +/// A route that displays widgets in the [Navigator]'s [Overlay]. +/// +/// See also: +/// +/// * [Route], which documents the meaning of the `T` generic type argument. +abstract class OverlayRoute<T> extends Route<T> { + /// Creates a route that knows how to interact with an [Overlay]. + OverlayRoute({ + super.settings, + }); + + /// Subclasses should override this getter to return the builders for the overlay. + @factory + Iterable<OverlayEntry> createOverlayEntries(); + + @override + List<OverlayEntry> get overlayEntries => _overlayEntries; + final List<OverlayEntry> _overlayEntries = <OverlayEntry>[]; + + @override + void install() { + assert(_overlayEntries.isEmpty); + _overlayEntries.addAll(createOverlayEntries()); + super.install(); + } + + /// Controls whether [didPop] calls [NavigatorState.finalizeRoute]. + /// + /// If true, this route removes its overlay entries during [didPop]. + /// Subclasses can override this getter if they want to delay finalization + /// (for example to animate the route's exit before removing it from the + /// overlay). + /// + /// Subclasses that return false from [finishedWhenPopped] are responsible for + /// calling [NavigatorState.finalizeRoute] themselves. + @protected + bool get finishedWhenPopped => true; + + @override + bool didPop(T? result) { + final bool returnValue = super.didPop(result); + assert(returnValue); + if (finishedWhenPopped) { + navigator!.finalizeRoute(this); + } + return returnValue; + } + + @override + void dispose() { + for (final OverlayEntry entry in _overlayEntries) { + entry.dispose(); + } + _overlayEntries.clear(); + super.dispose(); + } +} + +/// A route with entrance and exit transitions. +/// +/// See also: +/// +/// * [Route], which documents the meaning of the `T` generic type argument. +abstract class TransitionRoute<T> extends OverlayRoute<T> { + /// Creates a route that animates itself when it is pushed or popped. + TransitionRoute({ + super.settings, + }); + + /// This future completes only once the transition itself has finished, after + /// the overlay entries have been removed from the navigator's overlay. + /// + /// This future completes once the animation has been dismissed. That will be + /// after [popped], because [popped] typically completes before the animation + /// even starts, as soon as the route is popped. + Future<T?> get completed => _transitionCompleter.future; + final Completer<T?> _transitionCompleter = Completer<T?>(); + + /// Handle to the performance mode request. + /// + /// When the route is animating, the performance mode is requested. It is then + /// disposed when the animation ends. Requesting [DartPerformanceMode.latency] + /// indicates to the engine that the transition is latency sensitive and to delay + /// non-essential work while this handle is active. + PerformanceModeRequestHandle? _performanceModeRequestHandle; + + /// {@template flutter.widgets.TransitionRoute.transitionDuration} + /// The duration the transition going forwards. + /// + /// See also: + /// + /// * [reverseTransitionDuration], which controls the duration of the + /// transition when it is in reverse. + /// {@endtemplate} + Duration get transitionDuration; + + /// {@template flutter.widgets.TransitionRoute.reverseTransitionDuration} + /// The duration the transition going in reverse. + /// + /// By default, the reverse transition duration is set to the value of + /// the forwards [transitionDuration]. + /// {@endtemplate} + Duration get reverseTransitionDuration => transitionDuration; + + /// {@template flutter.widgets.TransitionRoute.opaque} + /// Whether the route obscures previous routes when the transition is complete. + /// + /// When an opaque route's entrance transition is complete, the routes behind + /// the opaque route will not be built to save resources. + /// {@endtemplate} + bool get opaque; + + /// {@template flutter.widgets.TransitionRoute.allowSnapshotting} + /// Whether the route transition will prefer to animate a snapshot of the + /// entering/exiting routes. + /// + /// When this value is true, certain route transitions (such as the Android + /// zoom page transition) will snapshot the entering and exiting routes. + /// These snapshots are then animated in place of the underlying widgets to + /// improve performance of the transition. + /// + /// Generally this means that animations that occur on the entering/exiting + /// route while the route animation plays may appear frozen - unless they + /// are a hero animation or something that is drawn in a separate overlay. + /// {@endtemplate} + bool get allowSnapshotting => true; + + // This ensures that if we got to the dismissed state while still current, + // we will still be disposed when we are eventually popped. + // + // This situation arises when dealing with the Cupertino dismiss gesture. + @override + bool get finishedWhenPopped => _controller!.status == AnimationStatus.dismissed && !_popFinalized; + + bool _popFinalized = false; + + /// The animation that drives the route's transition and the previous route's + /// forward transition. + Animation<double>? get animation => _animation; + Animation<double>? _animation; + + /// The animation controller that the route uses to drive the transitions. + /// + /// The animation itself is exposed by the [animation] property. + @protected + AnimationController? get controller => _controller; + AnimationController? _controller; + + /// The animation for the route being pushed on top of this route. This + /// animation lets this route coordinate with the entrance and exit transition + /// of route pushed on top of this route. + Animation<double>? get secondaryAnimation => _secondaryAnimation; + final ProxyAnimation _secondaryAnimation = ProxyAnimation(kAlwaysDismissedAnimation); + + /// Whether to takeover the [controller] created by [createAnimationController]. + /// + /// If true, this route will call [AnimationController.dispose] when the + /// controller is no longer needed. + /// If false, the controller should be disposed by whoever owned it. + /// + /// It defaults to `true`. + bool willDisposeAnimationController = true; + + /// Called to create the animation controller that will drive the transitions to + /// this route from the previous one, and back to the previous route from this + /// one. + /// + /// The returned controller will be disposed by [AnimationController.dispose] + /// if the [willDisposeAnimationController] is `true`. + AnimationController createAnimationController() { + assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.'); + final Duration duration = transitionDuration; + final Duration reverseDuration = reverseTransitionDuration; + assert(duration >= Duration.zero); + return AnimationController( + duration: duration, + reverseDuration: reverseDuration, + debugLabel: debugLabel, + vsync: navigator!, + ); + } + + /// Called to create the animation that exposes the current progress of + /// the transition controlled by the animation controller created by + /// [createAnimationController()]. + Animation<double> createAnimation() { + assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.'); + assert(_controller != null); + return _controller!.view; + } + + T? _result; + + void _handleStatusChanged(AnimationStatus status) { + switch (status) { + case AnimationStatus.completed: + if (overlayEntries.isNotEmpty) { + overlayEntries.first.opaque = opaque; + } + _performanceModeRequestHandle?.dispose(); + _performanceModeRequestHandle = null; + case AnimationStatus.forward: + case AnimationStatus.reverse: + if (overlayEntries.isNotEmpty) { + overlayEntries.first.opaque = false; + } + _performanceModeRequestHandle ??= + SchedulerBinding.instance + .requestPerformanceMode(ui.DartPerformanceMode.latency); + case AnimationStatus.dismissed: + // We might still be an active route if a subclass is controlling the + // transition and hits the dismissed status. For example, the iOS + // back gesture drives this animation to the dismissed status before + // removing the route and disposing it. + if (!isActive) { + navigator!.finalizeRoute(this); + _popFinalized = true; + _performanceModeRequestHandle?.dispose(); + _performanceModeRequestHandle = null; + } + } + } + + @override + void install() { + assert(!_transitionCompleter.isCompleted, 'Cannot install a $runtimeType after disposing it.'); + _controller = createAnimationController(); + assert(_controller != null, '$runtimeType.createAnimationController() returned null.'); + _animation = createAnimation() + ..addStatusListener(_handleStatusChanged); + assert(_animation != null, '$runtimeType.createAnimation() returned null.'); + super.install(); + if (_animation!.isCompleted && overlayEntries.isNotEmpty) { + overlayEntries.first.opaque = opaque; + } + } + + @override + TickerFuture didPush() { + assert(_controller != null, '$runtimeType.didPush called before calling install() or after calling dispose().'); + assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.'); + super.didPush(); + return _controller!.forward(); + } + + @override + void didAdd() { + assert(_controller != null, '$runtimeType.didPush called before calling install() or after calling dispose().'); + assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.'); + super.didAdd(); + _controller!.value = _controller!.upperBound; + } + + @override + void didReplace(Route<dynamic>? oldRoute) { + assert(_controller != null, '$runtimeType.didReplace called before calling install() or after calling dispose().'); + assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.'); + if (oldRoute is TransitionRoute) { + _controller!.value = oldRoute._controller!.value; + } + super.didReplace(oldRoute); + } + + @override + bool didPop(T? result) { + assert(_controller != null, '$runtimeType.didPop called before calling install() or after calling dispose().'); + assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.'); + _result = result; + _controller!.reverse(); + return super.didPop(result); + } + + @override + void didPopNext(Route<dynamic> nextRoute) { + assert(_controller != null, '$runtimeType.didPopNext called before calling install() or after calling dispose().'); + assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.'); + _updateSecondaryAnimation(nextRoute); + super.didPopNext(nextRoute); + } + + @override + void didChangeNext(Route<dynamic>? nextRoute) { + assert(_controller != null, '$runtimeType.didChangeNext called before calling install() or after calling dispose().'); + assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.'); + _updateSecondaryAnimation(nextRoute); + super.didChangeNext(nextRoute); + } + + // A callback method that disposes existing train hopping animation and + // removes its listener. + // + // This property is non-null if there is a train hopping in progress, and the + // caller must reset this property to null after it is called. + VoidCallback? _trainHoppingListenerRemover; + + void _updateSecondaryAnimation(Route<dynamic>? nextRoute) { + // There is an existing train hopping in progress. Unfortunately, we cannot + // dispose current train hopping animation until we replace it with a new + // animation. + final VoidCallback? previousTrainHoppingListenerRemover = _trainHoppingListenerRemover; + _trainHoppingListenerRemover = null; + + if (nextRoute is TransitionRoute<dynamic> && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) { + final Animation<double>? current = _secondaryAnimation.parent; + if (current != null) { + final Animation<double> currentTrain = (current is TrainHoppingAnimation ? current.currentTrain : current)!; + final Animation<double> nextTrain = nextRoute._animation!; + if ( + currentTrain.value == nextTrain.value || + nextTrain.status == AnimationStatus.completed || + nextTrain.status == AnimationStatus.dismissed + ) { + _setSecondaryAnimation(nextTrain, nextRoute.completed); + } else { + // Two trains animate at different values. We have to do train hopping. + // There are three possibilities of train hopping: + // 1. We hop on the nextTrain when two trains meet in the middle using + // TrainHoppingAnimation. + // 2. There is no chance to hop on nextTrain because two trains never + // cross each other. We have to directly set the animation to + // nextTrain once the nextTrain stops animating. + // 3. A new _updateSecondaryAnimation is called before train hopping + // finishes. We leave a listener remover for the next call to + // properly clean up the existing train hopping. + TrainHoppingAnimation? newAnimation; + void jumpOnAnimationEnd(AnimationStatus status) { + switch (status) { + case AnimationStatus.completed: + case AnimationStatus.dismissed: + // The nextTrain has stopped animating without train hopping. + // Directly sets the secondary animation and disposes the + // TrainHoppingAnimation. + _setSecondaryAnimation(nextTrain, nextRoute.completed); + if (_trainHoppingListenerRemover != null) { + _trainHoppingListenerRemover!(); + _trainHoppingListenerRemover = null; + } + case AnimationStatus.forward: + case AnimationStatus.reverse: + break; + } + } + _trainHoppingListenerRemover = () { + nextTrain.removeStatusListener(jumpOnAnimationEnd); + newAnimation?.dispose(); + }; + nextTrain.addStatusListener(jumpOnAnimationEnd); + newAnimation = TrainHoppingAnimation( + currentTrain, + nextTrain, + onSwitchedTrain: () { + assert(_secondaryAnimation.parent == newAnimation); + assert(newAnimation!.currentTrain == nextRoute._animation); + // We can hop on the nextTrain, so we don't need to listen to + // whether the nextTrain has stopped. + _setSecondaryAnimation(newAnimation!.currentTrain, nextRoute.completed); + if (_trainHoppingListenerRemover != null) { + _trainHoppingListenerRemover!(); + _trainHoppingListenerRemover = null; + } + }, + ); + _setSecondaryAnimation(newAnimation, nextRoute.completed); + } + } else { + _setSecondaryAnimation(nextRoute._animation, nextRoute.completed); + } + } else { + _setSecondaryAnimation(kAlwaysDismissedAnimation); + } + // Finally, we dispose any previous train hopping animation because it + // has been successfully updated at this point. + if (previousTrainHoppingListenerRemover != null) { + previousTrainHoppingListenerRemover(); + } + } + + void _setSecondaryAnimation(Animation<double>? animation, [Future<dynamic>? disposed]) { + _secondaryAnimation.parent = animation; + // Releases the reference to the next route's animation when that route + // is disposed. + disposed?.then((dynamic _) { + if (_secondaryAnimation.parent == animation) { + _secondaryAnimation.parent = kAlwaysDismissedAnimation; + if (animation is TrainHoppingAnimation) { + animation.dispose(); + } + } + }); + } + + /// Returns true if this route supports a transition animation that runs + /// when [nextRoute] is pushed on top of it or when [nextRoute] is popped + /// off of it. + /// + /// Subclasses can override this method to restrict the set of routes they + /// need to coordinate transitions with. + /// + /// If true, and `nextRoute.canTransitionFrom()` is true, then the + /// [ModalRoute.buildTransitions] `secondaryAnimation` will run from 0.0 - 1.0 + /// when [nextRoute] is pushed on top of this one. Similarly, if + /// the [nextRoute] is popped off of this route, the + /// `secondaryAnimation` will run from 1.0 - 0.0. + /// + /// If false, this route's [ModalRoute.buildTransitions] `secondaryAnimation` parameter + /// value will be [kAlwaysDismissedAnimation]. In other words, this route + /// will not animate when [nextRoute] is pushed on top of it or when + /// [nextRoute] is popped off of it. + /// + /// Returns true by default. + /// + /// See also: + /// + /// * [canTransitionFrom], which must be true for [nextRoute] for the + /// [ModalRoute.buildTransitions] `secondaryAnimation` to run. + bool canTransitionTo(TransitionRoute<dynamic> nextRoute) => true; + + /// Returns true if [previousRoute] should animate when this route + /// is pushed on top of it or when then this route is popped off of it. + /// + /// Subclasses can override this method to restrict the set of routes they + /// need to coordinate transitions with. + /// + /// If true, and `previousRoute.canTransitionTo()` is true, then the + /// previous route's [ModalRoute.buildTransitions] `secondaryAnimation` will + /// run from 0.0 - 1.0 when this route is pushed on top of + /// it. Similarly, if this route is popped off of [previousRoute] + /// the previous route's `secondaryAnimation` will run from 1.0 - 0.0. + /// + /// If false, then the previous route's [ModalRoute.buildTransitions] + /// `secondaryAnimation` value will be kAlwaysDismissedAnimation. In + /// other words [previousRoute] will not animate when this route is + /// pushed on top of it or when then this route is popped off of it. + /// + /// Returns true by default. + /// + /// See also: + /// + /// * [canTransitionTo], which must be true for [previousRoute] for its + /// [ModalRoute.buildTransitions] `secondaryAnimation` to run. + bool canTransitionFrom(TransitionRoute<dynamic> previousRoute) => true; + + @override + void dispose() { + assert(!_transitionCompleter.isCompleted, 'Cannot dispose a $runtimeType twice.'); + _animation?.removeStatusListener(_handleStatusChanged); + _performanceModeRequestHandle?.dispose(); + _performanceModeRequestHandle = null; + if (willDisposeAnimationController) { + _controller?.dispose(); + } + _transitionCompleter.complete(_result); + super.dispose(); + } + + /// A short description of this route useful for debugging. + String get debugLabel => objectRuntimeType(this, 'TransitionRoute'); + + @override + String toString() => '${objectRuntimeType(this, 'TransitionRoute')}(animation: $_controller)'; +} + +/// An entry in the history of a [LocalHistoryRoute]. +class LocalHistoryEntry { + /// Creates an entry in the history of a [LocalHistoryRoute]. + /// + /// The [impliesAppBarDismissal] defaults to true if not provided. + LocalHistoryEntry({ this.onRemove, this.impliesAppBarDismissal = true }); + + /// Called when this entry is removed from the history of its associated [LocalHistoryRoute]. + final VoidCallback? onRemove; + + LocalHistoryRoute<dynamic>? _owner; + + /// Whether an [AppBar] in the route this entry belongs to should + /// automatically add a back button or close button. + /// + /// Defaults to true. + final bool impliesAppBarDismissal; + + /// Remove this entry from the history of its associated [LocalHistoryRoute]. + void remove() { + _owner?.removeLocalHistoryEntry(this); + assert(_owner == null); + } + + void _notifyRemoved() { + onRemove?.call(); + } +} + +/// A mixin used by routes to handle back navigations internally by popping a list. +/// +/// When a [Navigator] is instructed to pop, the current route is given an +/// opportunity to handle the pop internally. A [LocalHistoryRoute] handles the +/// pop internally if its list of local history entries is non-empty. Rather +/// than being removed as the current route, the most recent [LocalHistoryEntry] +/// is removed from the list and its [LocalHistoryEntry.onRemove] is called. +/// +/// See also: +/// +/// * [Route], which documents the meaning of the `T` generic type argument. +mixin LocalHistoryRoute<T> on Route<T> { + List<LocalHistoryEntry>? _localHistory; + int _entriesImpliesAppBarDismissal = 0; + /// Adds a local history entry to this route. + /// + /// When asked to pop, if this route has any local history entries, this route + /// will handle the pop internally by removing the most recently added local + /// history entry. + /// + /// The given local history entry must not already be part of another local + /// history route. + /// + /// {@tool snippet} + /// + /// The following example is an app with 2 pages: `HomePage` and `SecondPage`. + /// The `HomePage` can navigate to the `SecondPage`. + /// + /// The `SecondPage` uses a [LocalHistoryEntry] to implement local navigation + /// within that page. Pressing 'show rectangle' displays a red rectangle and + /// adds a local history entry. At that point, pressing the '< back' button + /// pops the latest route, which is the local history entry, and the red + /// rectangle disappears. Pressing the '< back' button a second time + /// once again pops the latest route, which is the `SecondPage`, itself. + /// Therefore, the second press navigates back to the `HomePage`. + /// + /// ```dart + /// class App extends StatelessWidget { + /// const App({super.key}); + /// + /// @override + /// Widget build(BuildContext context) { + /// return MaterialApp( + /// initialRoute: '/', + /// routes: <String, WidgetBuilder>{ + /// '/': (BuildContext context) => const HomePage(), + /// '/second_page': (BuildContext context) => const SecondPage(), + /// }, + /// ); + /// } + /// } + /// + /// class HomePage extends StatefulWidget { + /// const HomePage({super.key}); + /// + /// @override + /// State<HomePage> createState() => _HomePageState(); + /// } + /// + /// class _HomePageState extends State<HomePage> { + /// @override + /// Widget build(BuildContext context) { + /// return Scaffold( + /// body: Center( + /// child: Column( + /// mainAxisSize: MainAxisSize.min, + /// children: <Widget>[ + /// const Text('HomePage'), + /// // Press this button to open the SecondPage. + /// ElevatedButton( + /// child: const Text('Second Page >'), + /// onPressed: () { + /// Navigator.pushNamed(context, '/second_page'); + /// }, + /// ), + /// ], + /// ), + /// ), + /// ); + /// } + /// } + /// + /// class SecondPage extends StatefulWidget { + /// const SecondPage({super.key}); + /// + /// @override + /// State<SecondPage> createState() => _SecondPageState(); + /// } + /// + /// class _SecondPageState extends State<SecondPage> { + /// + /// bool _showRectangle = false; + /// + /// Future<void> _navigateLocallyToShowRectangle() async { + /// // This local history entry essentially represents the display of the red + /// // rectangle. When this local history entry is removed, we hide the red + /// // rectangle. + /// setState(() => _showRectangle = true); + /// ModalRoute.of(context)?.addLocalHistoryEntry( + /// LocalHistoryEntry( + /// onRemove: () { + /// // Hide the red rectangle. + /// setState(() => _showRectangle = false); + /// } + /// ) + /// ); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// final Widget localNavContent = _showRectangle + /// ? Container( + /// width: 100.0, + /// height: 100.0, + /// color: Colors.red, + /// ) + /// : ElevatedButton( + /// onPressed: _navigateLocallyToShowRectangle, + /// child: const Text('Show Rectangle'), + /// ); + /// + /// return Scaffold( + /// body: Center( + /// child: Column( + /// mainAxisAlignment: MainAxisAlignment.center, + /// children: <Widget>[ + /// localNavContent, + /// ElevatedButton( + /// child: const Text('< Back'), + /// onPressed: () { + /// // Pop a route. If this is pressed while the red rectangle is + /// // visible then it will pop our local history entry, which + /// // will hide the red rectangle. Otherwise, the SecondPage will + /// // navigate back to the HomePage. + /// Navigator.of(context).pop(); + /// }, + /// ), + /// ], + /// ), + /// ), + /// ); + /// } + /// } + /// ``` + /// {@end-tool} + void addLocalHistoryEntry(LocalHistoryEntry entry) { + assert(entry._owner == null); + entry._owner = this; + _localHistory ??= <LocalHistoryEntry>[]; + final bool wasEmpty = _localHistory!.isEmpty; + _localHistory!.add(entry); + bool internalStateChanged = false; + if (entry.impliesAppBarDismissal) { + internalStateChanged = _entriesImpliesAppBarDismissal == 0; + _entriesImpliesAppBarDismissal += 1; + } + if (wasEmpty || internalStateChanged) { + changedInternalState(); + } + } + + /// Remove a local history entry from this route. + /// + /// The entry's [LocalHistoryEntry.onRemove] callback, if any, will be called + /// synchronously. + void removeLocalHistoryEntry(LocalHistoryEntry entry) { + assert(entry._owner == this); + assert(_localHistory!.contains(entry)); + bool internalStateChanged = false; + if (_localHistory!.remove(entry) && entry.impliesAppBarDismissal) { + _entriesImpliesAppBarDismissal -= 1; + internalStateChanged = _entriesImpliesAppBarDismissal == 0; + } + entry._owner = null; + entry._notifyRemoved(); + if (_localHistory!.isEmpty || internalStateChanged) { + assert(_entriesImpliesAppBarDismissal == 0); + if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks) { + // The local history might be removed as a result of disposing inactive + // elements during finalizeTree. The state is locked at this moment, and + // we can only notify state has changed in the next frame. + SchedulerBinding.instance.addPostFrameCallback((Duration duration) { + if (isActive) { + changedInternalState(); + } + }, debugLabel: 'LocalHistoryRoute.changedInternalState'); + } else { + changedInternalState(); + } + } + } + + @Deprecated( + 'Use popDisposition instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', + ) + @override + Future<RoutePopDisposition> willPop() async { + if (willHandlePopInternally) { + return RoutePopDisposition.pop; + } + return super.willPop(); + } + + @override + RoutePopDisposition get popDisposition { + if (willHandlePopInternally) { + return RoutePopDisposition.pop; + } + return super.popDisposition; + } + + @override + bool didPop(T? result) { + if (_localHistory != null && _localHistory!.isNotEmpty) { + final LocalHistoryEntry entry = _localHistory!.removeLast(); + assert(entry._owner == this); + entry._owner = null; + entry._notifyRemoved(); + bool internalStateChanged = false; + if (entry.impliesAppBarDismissal) { + _entriesImpliesAppBarDismissal -= 1; + internalStateChanged = _entriesImpliesAppBarDismissal == 0; + } + if (_localHistory!.isEmpty || internalStateChanged) { + changedInternalState(); + } + return false; + } + return super.didPop(result); + } + + @override + bool get willHandlePopInternally { + return _localHistory != null && _localHistory!.isNotEmpty; + } +} + +class _DismissModalAction extends DismissAction { + _DismissModalAction(this.context); + + final BuildContext context; + + @override + bool isEnabled(DismissIntent intent) { + final ModalRoute<dynamic> route = ModalRoute.of<dynamic>(context)!; + return route.barrierDismissible; + } + + @override + Object invoke(DismissIntent intent) { + return Navigator.of(context).maybePop(); + } +} + +class _ModalScopeStatus extends InheritedWidget { + const _ModalScopeStatus({ + required this.isCurrent, + required this.canPop, + required this.impliesAppBarDismissal, + required this.route, + required super.child, + }); + + final bool isCurrent; + final bool canPop; + final bool impliesAppBarDismissal; + final Route<dynamic> route; + + @override + bool updateShouldNotify(_ModalScopeStatus old) { + return isCurrent != old.isCurrent || + canPop != old.canPop || + impliesAppBarDismissal != old.impliesAppBarDismissal || + route != old.route; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add(FlagProperty('isCurrent', value: isCurrent, ifTrue: 'active', ifFalse: 'inactive')); + description.add(FlagProperty('canPop', value: canPop, ifTrue: 'can pop')); + description.add(FlagProperty('impliesAppBarDismissal', value: impliesAppBarDismissal, ifTrue: 'implies app bar dismissal')); + } +} + +class _ModalScope<T> extends StatefulWidget { + const _ModalScope({ + super.key, + required this.route, + }); + + final ModalRoute<T> route; + + @override + _ModalScopeState<T> createState() => _ModalScopeState<T>(); +} + +class _ModalScopeState<T> extends State<_ModalScope<T>> { + // We cache the result of calling the route's buildPage, and clear the cache + // whenever the dependencies change. This implements the contract described in + // the documentation for buildPage, namely that it gets called once, unless + // something like a ModalRoute.of() dependency triggers an update. + Widget? _page; + + // This is the combination of the two animations for the route. + late Listenable _listenable; + + /// The node this scope will use for its root [FocusScope] widget. + final FocusScopeNode focusScopeNode = FocusScopeNode( + debugLabel: '$_ModalScopeState Focus Scope', + ); + final ScrollController primaryScrollController = ScrollController(); + + @override + void initState() { + super.initState(); + final List<Listenable> animations = <Listenable>[ + if (widget.route.animation != null) widget.route.animation!, + if (widget.route.secondaryAnimation != null) widget.route.secondaryAnimation!, + ]; + _listenable = Listenable.merge(animations); + } + + @override + void didUpdateWidget(_ModalScope<T> oldWidget) { + super.didUpdateWidget(oldWidget); + assert(widget.route == oldWidget.route); + _updateFocusScopeNode(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _page = null; + _updateFocusScopeNode(); + } + + void _updateFocusScopeNode() { + final TraversalEdgeBehavior traversalEdgeBehavior; + final ModalRoute<T> route = widget.route; + if (route.traversalEdgeBehavior != null) { + traversalEdgeBehavior = route.traversalEdgeBehavior!; + } else { + traversalEdgeBehavior = route.navigator!.widget.routeTraversalEdgeBehavior; + } + focusScopeNode.traversalEdgeBehavior = traversalEdgeBehavior; + if (route.isCurrent && _shouldRequestFocus) { + route.navigator!.focusNode.enclosingScope?.setFirstFocus(focusScopeNode); + } + } + + void _forceRebuildPage() { + setState(() { + _page = null; + }); + } + + @override + void dispose() { + focusScopeNode.dispose(); + primaryScrollController.dispose(); + super.dispose(); + } + + bool get _shouldIgnoreFocusRequest { + return widget.route.animation?.status == AnimationStatus.reverse || + (widget.route.navigator?.userGestureInProgress ?? false); + } + + bool get _shouldRequestFocus { + return widget.route.navigator!.widget.requestFocus; + } + + // This should be called to wrap any changes to route.isCurrent, route.canPop, + // and route.offstage. + void _routeSetState(VoidCallback fn) { + if (widget.route.isCurrent && !_shouldIgnoreFocusRequest && _shouldRequestFocus) { + widget.route.navigator!.focusNode.enclosingScope?.setFirstFocus(focusScopeNode); + } + setState(fn); + } + + @override + Widget build(BuildContext context) { + return AnimatedBuilder( + animation: widget.route.restorationScopeId, + builder: (BuildContext context, Widget? child) { + assert(child != null); + return RestorationScope( + restorationId: widget.route.restorationScopeId.value, + child: child!, + ); + }, + child: _ModalScopeStatus( + route: widget.route, + isCurrent: widget.route.isCurrent, // _routeSetState is called if this updates + canPop: widget.route.canPop, // _routeSetState is called if this updates + impliesAppBarDismissal: widget.route.impliesAppBarDismissal, + child: Offstage( + offstage: widget.route.offstage, // _routeSetState is called if this updates + child: PageStorage( + bucket: widget.route._storageBucket, // immutable + child: Builder( + builder: (BuildContext context) { + return Actions( + actions: <Type, Action<Intent>>{ + DismissIntent: _DismissModalAction(context), + }, + child: PrimaryScrollController( + controller: primaryScrollController, + child: FocusScope( + node: focusScopeNode, // immutable + // Only top most route can participate in focus traversal. + skipTraversal: !widget.route.isCurrent, + child: RepaintBoundary( + child: AnimatedBuilder( + animation: _listenable, // immutable + builder: (BuildContext context, Widget? child) { + return widget.route.buildTransitions( + context, + widget.route.animation!, + widget.route.secondaryAnimation!, + // This additional AnimatedBuilder is include because if the + // value of the userGestureInProgressNotifier changes, it's + // only necessary to rebuild the IgnorePointer widget and set + // the focus node's ability to focus. + AnimatedBuilder( + animation: widget.route.navigator?.userGestureInProgressNotifier ?? ValueNotifier<bool>(false), + builder: (BuildContext context, Widget? child) { + final bool ignoreEvents = _shouldIgnoreFocusRequest; + focusScopeNode.canRequestFocus = !ignoreEvents; + return IgnorePointer( + ignoring: ignoreEvents, + child: child, + ); + }, + child: child, + ), + ); + }, + child: _page ??= RepaintBoundary( + key: widget.route._subtreeKey, // immutable + child: Builder( + builder: (BuildContext context) { + return widget.route.buildPage( + context, + widget.route.animation!, + widget.route.secondaryAnimation!, + ); + }, + ), + ), + ), + ), + ), + ), + ); + }, + ), + ), + ), + ), + ); + } +} + +/// A route that blocks interaction with previous routes. +/// +/// [ModalRoute]s cover the entire [Navigator]. They are not necessarily +/// [opaque], however; for example, a pop-up menu uses a [ModalRoute] but only +/// shows the menu in a small box overlapping the previous route. +/// +/// The `T` type argument is the return value of the route. If there is no +/// return value, consider using `void` as the return value. +/// +/// See also: +/// +/// * [Route], which further documents the meaning of the `T` generic type argument. +abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T> { + /// Creates a route that blocks interaction with previous routes. + ModalRoute({ + super.settings, + this.filter, + this.traversalEdgeBehavior, + }); + + /// The filter to add to the barrier. + /// + /// If given, this filter will be applied to the modal barrier using + /// [BackdropFilter]. This allows blur effects, for example. + final ui.ImageFilter? filter; + + /// Controls the transfer of focus beyond the first and the last items of a + /// [FocusScopeNode]. + /// + /// If set to null, [Navigator.routeTraversalEdgeBehavior] is used. + final TraversalEdgeBehavior? traversalEdgeBehavior; + + // The API for general users of this class + + /// Returns the modal route most closely associated with the given context. + /// + /// Returns null if the given context is not associated with a modal route. + /// + /// {@tool snippet} + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ModalRoute<int>? route = ModalRoute.of<int>(context); + /// ``` + /// {@end-tool} + /// + /// The given [BuildContext] will be rebuilt if the state of the route changes + /// while it is visible (specifically, if [isCurrent] or [canPop] change value). + @optionalTypeArgs + static ModalRoute<T>? of<T extends Object?>(BuildContext context) { + final _ModalScopeStatus? widget = context.dependOnInheritedWidgetOfExactType<_ModalScopeStatus>(); + return widget?.route as ModalRoute<T>?; + } + + /// Schedule a call to [buildTransitions]. + /// + /// Whenever you need to change internal state for a [ModalRoute] object, make + /// the change in a function that you pass to [setState], as in: + /// + /// ```dart + /// setState(() { _myState = newValue; }); + /// ``` + /// + /// If you just change the state directly without calling [setState], then the + /// route will not be scheduled for rebuilding, meaning that its rendering + /// will not be updated. + @protected + void setState(VoidCallback fn) { + if (_scopeKey.currentState != null) { + _scopeKey.currentState!._routeSetState(fn); + } else { + // The route isn't currently visible, so we don't have to call its setState + // method, but we do still need to call the fn callback, otherwise the state + // in the route won't be updated! + fn(); + } + } + + /// Returns a predicate that's true if the route has the specified name and if + /// popping the route will not yield the same route, i.e. if the route's + /// [willHandlePopInternally] property is false. + /// + /// This function is typically used with [Navigator.popUntil()]. + static RoutePredicate withName(String name) { + return (Route<dynamic> route) { + return !route.willHandlePopInternally + && route is ModalRoute + && route.settings.name == name; + }; + } + + // The API for subclasses to override - used by _ModalScope + + /// Override this method to build the primary content of this route. + /// + /// The arguments have the following meanings: + /// + /// * `context`: The context in which the route is being built. + /// * [animation]: The animation for this route's transition. When entering, + /// the animation runs forward from 0.0 to 1.0. When exiting, this animation + /// runs backwards from 1.0 to 0.0. + /// * [secondaryAnimation]: The animation for the route being pushed on top of + /// this route. This animation lets this route coordinate with the entrance + /// and exit transition of routes pushed on top of this route. + /// + /// This method is only called when the route is first built, and rarely + /// thereafter. In particular, it is not automatically called again when the + /// route's state changes unless it uses [ModalRoute.of]. For a builder that + /// is called every time the route's state changes, consider + /// [buildTransitions]. For widgets that change their behavior when the + /// route's state changes, consider [ModalRoute.of] to obtain a reference to + /// the route; this will cause the widget to be rebuilt each time the route + /// changes state. + /// + /// In general, [buildPage] should be used to build the page contents, and + /// [buildTransitions] for the widgets that change as the page is brought in + /// and out of view. Avoid using [buildTransitions] for content that never + /// changes; building such content once from [buildPage] is more efficient. + Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation); + + /// Override this method to wrap the [child] with one or more transition + /// widgets that define how the route arrives on and leaves the screen. + /// + /// By default, the child (which contains the widget returned by [buildPage]) + /// is not wrapped in any transition widgets. + /// + /// The [buildTransitions] method, in contrast to [buildPage], is called each + /// time the [Route]'s state changes while it is visible (e.g. if the value of + /// [canPop] changes on the active route). + /// + /// The [buildTransitions] method is typically used to define transitions + /// that animate the new topmost route's comings and goings. When the + /// [Navigator] pushes a route on the top of its stack, the new route's + /// primary [animation] runs from 0.0 to 1.0. When the Navigator pops the + /// topmost route, e.g. because the use pressed the back button, the + /// primary animation runs from 1.0 to 0.0. + /// + /// {@tool snippet} + /// The following example uses the primary animation to drive a + /// [SlideTransition] that translates the top of the new route vertically + /// from the bottom of the screen when it is pushed on the Navigator's + /// stack. When the route is popped the SlideTransition translates the + /// route from the top of the screen back to the bottom. + /// + /// We've used [PageRouteBuilder] to demonstrate the [buildTransitions] method + /// here. The body of an override of the [buildTransitions] method would be + /// defined in the same way. + /// + /// ```dart + /// PageRouteBuilder<void>( + /// pageBuilder: (BuildContext context, + /// Animation<double> animation, + /// Animation<double> secondaryAnimation, + /// ) { + /// return Scaffold( + /// appBar: AppBar(title: const Text('Hello')), + /// body: const Center( + /// child: Text('Hello World'), + /// ), + /// ); + /// }, + /// transitionsBuilder: ( + /// BuildContext context, + /// Animation<double> animation, + /// Animation<double> secondaryAnimation, + /// Widget child, + /// ) { + /// return SlideTransition( + /// position: Tween<Offset>( + /// begin: const Offset(0.0, 1.0), + /// end: Offset.zero, + /// ).animate(animation), + /// child: child, // child is the value returned by pageBuilder + /// ); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// When the [Navigator] pushes a route on the top of its stack, the + /// [secondaryAnimation] can be used to define how the route that was on + /// the top of the stack leaves the screen. Similarly when the topmost route + /// is popped, the secondaryAnimation can be used to define how the route + /// below it reappears on the screen. When the Navigator pushes a new route + /// on the top of its stack, the old topmost route's secondaryAnimation + /// runs from 0.0 to 1.0. When the Navigator pops the topmost route, the + /// secondaryAnimation for the route below it runs from 1.0 to 0.0. + /// + /// {@tool snippet} + /// The example below adds a transition that's driven by the + /// [secondaryAnimation]. When this route disappears because a new route has + /// been pushed on top of it, it translates in the opposite direction of + /// the new route. Likewise when the route is exposed because the topmost + /// route has been popped off. + /// + /// ```dart + /// PageRouteBuilder<void>( + /// pageBuilder: (BuildContext context, + /// Animation<double> animation, + /// Animation<double> secondaryAnimation, + /// ) { + /// return Scaffold( + /// appBar: AppBar(title: const Text('Hello')), + /// body: const Center( + /// child: Text('Hello World'), + /// ), + /// ); + /// }, + /// transitionsBuilder: ( + /// BuildContext context, + /// Animation<double> animation, + /// Animation<double> secondaryAnimation, + /// Widget child, + /// ) { + /// return SlideTransition( + /// position: Tween<Offset>( + /// begin: const Offset(0.0, 1.0), + /// end: Offset.zero, + /// ).animate(animation), + /// child: SlideTransition( + /// position: Tween<Offset>( + /// begin: Offset.zero, + /// end: const Offset(0.0, 1.0), + /// ).animate(secondaryAnimation), + /// child: child, + /// ), + /// ); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// In practice the `secondaryAnimation` is used pretty rarely. + /// + /// The arguments to this method are as follows: + /// + /// * `context`: The context in which the route is being built. + /// * [animation]: When the [Navigator] pushes a route on the top of its stack, + /// the new route's primary [animation] runs from 0.0 to 1.0. When the [Navigator] + /// pops the topmost route this animation runs from 1.0 to 0.0. + /// * [secondaryAnimation]: When the Navigator pushes a new route + /// on the top of its stack, the old topmost route's [secondaryAnimation] + /// runs from 0.0 to 1.0. When the [Navigator] pops the topmost route, the + /// [secondaryAnimation] for the route below it runs from 1.0 to 0.0. + /// * `child`, the page contents, as returned by [buildPage]. + /// + /// See also: + /// + /// * [buildPage], which is used to describe the actual contents of the page, + /// and whose result is passed to the `child` argument of this method. + Widget buildTransitions( + BuildContext context, + Animation<double> animation, + Animation<double> secondaryAnimation, + Widget child, + ) { + return child; + } + + @override + void install() { + super.install(); + _animationProxy = ProxyAnimation(super.animation); + _secondaryAnimationProxy = ProxyAnimation(super.secondaryAnimation); + } + + @override + TickerFuture didPush() { + if (_scopeKey.currentState != null && navigator!.widget.requestFocus) { + navigator!.focusNode.enclosingScope?.setFirstFocus(_scopeKey.currentState!.focusScopeNode); + } + return super.didPush(); + } + + @override + void didAdd() { + if (_scopeKey.currentState != null && navigator!.widget.requestFocus) { + navigator!.focusNode.enclosingScope?.setFirstFocus(_scopeKey.currentState!.focusScopeNode); + } + super.didAdd(); + } + + // The API for subclasses to override - used by this class + + /// {@template flutter.widgets.ModalRoute.barrierDismissible} + /// Whether you can dismiss this route by tapping the modal barrier. + /// + /// The modal barrier is the scrim that is rendered behind each route, which + /// generally prevents the user from interacting with the route below the + /// current route, and normally partially obscures such routes. + /// + /// For example, when a dialog is on the screen, the page below the dialog is + /// usually darkened by the modal barrier. + /// + /// If [barrierDismissible] is true, then tapping this barrier, pressing + /// the escape key on the keyboard, or calling route popping functions + /// such as [Navigator.pop] will cause the current route to be popped + /// with null as the value. + /// + /// If [barrierDismissible] is false, then tapping the barrier has no effect. + /// + /// If this getter would ever start returning a different value, + /// either [changedInternalState] or [changedExternalState] should + /// be invoked so that the change can take effect. + /// + /// It is safe to use `navigator.context` to look up inherited + /// widgets here, because the [Navigator] calls + /// [changedExternalState] whenever its dependencies change, and + /// [changedExternalState] causes the modal barrier to rebuild. + /// + /// See also: + /// + /// * [Navigator.pop], which is used to dismiss the route. + /// * [barrierColor], which controls the color of the scrim for this route. + /// * [ModalBarrier], the widget that implements this feature. + /// {@endtemplate} + bool get barrierDismissible; + + /// Whether the semantics of the modal barrier are included in the + /// semantics tree. + /// + /// The modal barrier is the scrim that is rendered behind each route, which + /// generally prevents the user from interacting with the route below the + /// current route, and normally partially obscures such routes. + /// + /// If [semanticsDismissible] is true, then modal barrier semantics are + /// included in the semantics tree. + /// + /// If [semanticsDismissible] is false, then modal barrier semantics are + /// excluded from the semantics tree and tapping on the modal barrier + /// has no effect. + /// + /// If this getter would ever start returning a different value, + /// either [changedInternalState] or [changedExternalState] should + /// be invoked so that the change can take effect. + /// + /// It is safe to use `navigator.context` to look up inherited + /// widgets here, because the [Navigator] calls + /// [changedExternalState] whenever its dependencies change, and + /// [changedExternalState] causes the modal barrier to rebuild. + bool get semanticsDismissible => true; + + /// {@template flutter.widgets.ModalRoute.barrierColor} + /// The color to use for the modal barrier. If this is null, the barrier will + /// be transparent. + /// + /// The modal barrier is the scrim that is rendered behind each route, which + /// generally prevents the user from interacting with the route below the + /// current route, and normally partially obscures such routes. + /// + /// For example, when a dialog is on the screen, the page below the dialog is + /// usually darkened by the modal barrier. + /// + /// The color is ignored, and the barrier made invisible, when + /// [ModalRoute.offstage] is true. + /// + /// While the route is animating into position, the color is animated from + /// transparent to the specified color. + /// {@endtemplate} + /// + /// If this getter would ever start returning a different color, one + /// of the [changedInternalState] or [changedExternalState] methods + /// should be invoked so that the change can take effect. + /// + /// It is safe to use `navigator.context` to look up inherited + /// widgets here, because the [Navigator] calls + /// [changedExternalState] whenever its dependencies change, and + /// [changedExternalState] causes the modal barrier to rebuild. + /// + /// {@tool snippet} + /// + /// For example, to make the barrier color use the theme's + /// background color, one could say: + /// + /// ```dart + /// Color get barrierColor => Theme.of(navigator.context).colorScheme.background; + /// ``` + /// + /// {@end-tool} + /// + /// See also: + /// + /// * [barrierDismissible], which controls the behavior of the barrier when + /// tapped. + /// * [ModalBarrier], the widget that implements this feature. + Color? get barrierColor; + + /// {@template flutter.widgets.ModalRoute.barrierLabel} + /// The semantic label used for a dismissible barrier. + /// + /// If the barrier is dismissible, this label will be read out if + /// accessibility tools (like VoiceOver on iOS) focus on the barrier. + /// + /// The modal barrier is the scrim that is rendered behind each route, which + /// generally prevents the user from interacting with the route below the + /// current route, and normally partially obscures such routes. + /// + /// For example, when a dialog is on the screen, the page below the dialog is + /// usually darkened by the modal barrier. + /// {@endtemplate} + /// + /// If this getter would ever start returning a different label, + /// either [changedInternalState] or [changedExternalState] should + /// be invoked so that the change can take effect. + /// + /// It is safe to use `navigator.context` to look up inherited + /// widgets here, because the [Navigator] calls + /// [changedExternalState] whenever its dependencies change, and + /// [changedExternalState] causes the modal barrier to rebuild. + /// + /// See also: + /// + /// * [barrierDismissible], which controls the behavior of the barrier when + /// tapped. + /// * [ModalBarrier], the widget that implements this feature. + String? get barrierLabel; + + /// The curve that is used for animating the modal barrier in and out. + /// + /// The modal barrier is the scrim that is rendered behind each route, which + /// generally prevents the user from interacting with the route below the + /// current route, and normally partially obscures such routes. + /// + /// For example, when a dialog is on the screen, the page below the dialog is + /// usually darkened by the modal barrier. + /// + /// While the route is animating into position, the color is animated from + /// transparent to the specified [barrierColor]. + /// + /// If this getter would ever start returning a different curve, + /// either [changedInternalState] or [changedExternalState] should + /// be invoked so that the change can take effect. + /// + /// It is safe to use `navigator.context` to look up inherited + /// widgets here, because the [Navigator] calls + /// [changedExternalState] whenever its dependencies change, and + /// [changedExternalState] causes the modal barrier to rebuild. + /// + /// It defaults to [Curves.ease]. + /// + /// See also: + /// + /// * [barrierColor], which determines the color that the modal transitions + /// to. + /// * [Curves] for a collection of common curves. + /// * [AnimatedModalBarrier], the widget that implements this feature. + Curve get barrierCurve => Curves.ease; + + /// {@template flutter.widgets.ModalRoute.maintainState} + /// Whether the route should remain in memory when it is inactive. + /// + /// If this is true, then the route is maintained, so that any futures it is + /// holding from the next route will properly resolve when the next route + /// pops. If this is not necessary, this can be set to false to allow the + /// framework to entirely discard the route's widget hierarchy when it is not + /// visible. + /// + /// Setting [maintainState] to false does not guarantee that the route will be + /// discarded. For instance, it will not be descarded if it is still visible + /// because the next above it is not opaque (e.g. it is a popup dialog). + /// {@endtemplate} + /// + /// If this getter would ever start returning a different value, the + /// [changedInternalState] should be invoked so that the change can take + /// effect. + /// + /// See also: + /// + /// * [OverlayEntry.maintainState], which is the underlying implementation + /// of this property. + bool get maintainState; + + + // The API for _ModalScope and HeroController + + /// Whether this route is currently offstage. + /// + /// On the first frame of a route's entrance transition, the route is built + /// [Offstage] using an animation progress of 1.0. The route is invisible and + /// non-interactive, but each widget has its final size and position. This + /// mechanism lets the [HeroController] determine the final local of any hero + /// widgets being animated as part of the transition. + /// + /// The modal barrier, if any, is not rendered if [offstage] is true (see + /// [barrierColor]). + /// + /// Whenever this changes value, [changedInternalState] is called. + bool get offstage => _offstage; + bool _offstage = false; + set offstage(bool value) { + if (_offstage == value) { + return; + } + setState(() { + _offstage = value; + }); + _animationProxy!.parent = _offstage ? kAlwaysCompleteAnimation : super.animation; + _secondaryAnimationProxy!.parent = _offstage ? kAlwaysDismissedAnimation : super.secondaryAnimation; + changedInternalState(); + } + + /// The build context for the subtree containing the primary content of this route. + BuildContext? get subtreeContext => _subtreeKey.currentContext; + + @override + Animation<double>? get animation => _animationProxy; + ProxyAnimation? _animationProxy; + + @override + Animation<double>? get secondaryAnimation => _secondaryAnimationProxy; + ProxyAnimation? _secondaryAnimationProxy; + + final List<WillPopCallback> _willPopCallbacks = <WillPopCallback>[]; + + final Set<PopEntry> _popEntries = <PopEntry>{}; + + /// Returns [RoutePopDisposition.doNotPop] if any of callbacks added with + /// [addScopedWillPopCallback] returns either false or null. If they all + /// return true, the base [Route.willPop]'s result will be returned. The + /// callbacks will be called in the order they were added, and will only be + /// called if all previous callbacks returned true. + /// + /// Typically this method is not overridden because applications usually + /// don't create modal routes directly, they use higher level primitives + /// like [showDialog]. The scoped [WillPopCallback] list makes it possible + /// for ModalRoute descendants to collectively define the value of [willPop]. + /// + /// See also: + /// + /// * [Form], which provides an `onWillPop` callback that uses this mechanism. + /// * [addScopedWillPopCallback], which adds a callback to the list this + /// method checks. + /// * [removeScopedWillPopCallback], which removes a callback from the list + /// this method checks. + @Deprecated( + 'Use popDisposition instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', + ) + @override + Future<RoutePopDisposition> willPop() async { + final _ModalScopeState<T>? scope = _scopeKey.currentState; + assert(scope != null); + for (final WillPopCallback callback in List<WillPopCallback>.of(_willPopCallbacks)) { + if (!await callback()) { + return RoutePopDisposition.doNotPop; + } + } + return super.willPop(); + } + + /// Returns [RoutePopDisposition.doNotPop] if any of the [PopEntry] instances + /// registered with [registerPopEntry] have [PopEntry.canPopNotifier] set to + /// false. + /// + /// Typically this method is not overridden because applications usually + /// don't create modal routes directly, they use higher level primitives + /// like [showDialog]. The scoped [PopEntry] list makes it possible for + /// ModalRoute descendants to collectively define the value of + /// [popDisposition]. + /// + /// See also: + /// + /// * [Form], which provides an `onPopInvoked` callback that is similar. + /// * [registerPopEntry], which adds a [PopEntry] to the list this method + /// checks. + /// * [unregisterPopEntry], which removes a [PopEntry] from the list this + /// method checks. + @override + RoutePopDisposition get popDisposition { + final bool canPop = _popEntries.every((PopEntry popEntry) { + return popEntry.canPopNotifier.value; + }); + + if (!canPop) { + return RoutePopDisposition.doNotPop; + } + return super.popDisposition; + } + + @override + void onPopInvoked(bool didPop) { + for (final PopEntry popEntry in _popEntries) { + popEntry.onPopInvoked?.call(didPop); + } + } + + /// Enables this route to veto attempts by the user to dismiss it. + /// + /// This callback runs asynchronously and it's possible that it will be called + /// after its route has been disposed. The callback should check [State.mounted] + /// before doing anything. + /// + /// A typical application of this callback would be to warn the user about + /// unsaved [Form] data if the user attempts to back out of the form. In that + /// case, use the [Form.onWillPop] property to register the callback. + /// + /// See also: + /// + /// * [WillPopScope], which manages the registration and unregistration + /// process automatically. + /// * [Form], which provides an `onWillPop` callback that uses this mechanism. + /// * [willPop], which runs the callbacks added with this method. + /// * [removeScopedWillPopCallback], which removes a callback from the list + /// that [willPop] checks. + @Deprecated( + 'Use registerPopEntry or PopScope instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', + ) + void addScopedWillPopCallback(WillPopCallback callback) { + assert(_scopeKey.currentState != null, 'Tried to add a willPop callback to a route that is not currently in the tree.'); + _willPopCallbacks.add(callback); + } + + /// Remove one of the callbacks run by [willPop]. + /// + /// See also: + /// + /// * [Form], which provides an `onWillPop` callback that uses this mechanism. + /// * [addScopedWillPopCallback], which adds callback to the list + /// checked by [willPop]. + @Deprecated( + 'Use unregisterPopEntry or PopScope instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', + ) + void removeScopedWillPopCallback(WillPopCallback callback) { + assert(_scopeKey.currentState != null, 'Tried to remove a willPop callback from a route that is not currently in the tree.'); + _willPopCallbacks.remove(callback); + } + + /// Registers the existence of a [PopEntry] in the route. + /// + /// [PopEntry] instances registered in this way will have their + /// [PopEntry.onPopInvoked] callbacks called when a route is popped or a pop + /// is attempted. They will also be able to block pop operations with + /// [PopEntry.canPopNotifier] through this route's [popDisposition] method. + /// + /// See also: + /// + /// * [unregisterPopEntry], which performs the opposite operation. + void registerPopEntry(PopEntry popEntry) { + _popEntries.add(popEntry); + popEntry.canPopNotifier.addListener(_handlePopEntryChange); + _handlePopEntryChange(); + } + + /// Unregisters a [PopEntry] in the route's widget subtree. + /// + /// See also: + /// + /// * [registerPopEntry], which performs the opposite operation. + void unregisterPopEntry(PopEntry popEntry) { + _popEntries.remove(popEntry); + popEntry.canPopNotifier.removeListener(_handlePopEntryChange); + _handlePopEntryChange(); + } + + void _handlePopEntryChange() { + if (!isCurrent) { + return; + } + final NavigationNotification notification = NavigationNotification( + // canPop indicates that the originator of the Notification can handle a + // pop. In the case of PopScope, it handles pops when canPop is + // false. Hence the seemingly backward logic here. + canHandlePop: popDisposition == RoutePopDisposition.doNotPop, + ); + // Avoid dispatching a notification in the middle of a build. + switch (SchedulerBinding.instance.schedulerPhase) { + case SchedulerPhase.postFrameCallbacks: + notification.dispatch(subtreeContext); + case SchedulerPhase.idle: + case SchedulerPhase.midFrameMicrotasks: + case SchedulerPhase.persistentCallbacks: + case SchedulerPhase.transientCallbacks: + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + if (!(subtreeContext?.mounted ?? false)) { + return; + } + notification.dispatch(subtreeContext); + }, debugLabel: 'ModalRoute.dispatchNotification'); + } + } + + /// True if one or more [WillPopCallback] callbacks exist. + /// + /// This method is used to disable the horizontal swipe pop gesture supported + /// by [MaterialPageRoute] for [TargetPlatform.iOS] and + /// [TargetPlatform.macOS]. If a pop might be vetoed, then the back gesture is + /// disabled. + /// + /// The [buildTransitions] method will not be called again if this changes, + /// since it can change during the build as descendants of the route add or + /// remove callbacks. + /// + /// See also: + /// + /// * [addScopedWillPopCallback], which adds a callback. + /// * [removeScopedWillPopCallback], which removes a callback. + /// * [willHandlePopInternally], which reports on another reason why + /// a pop might be vetoed. + @Deprecated( + 'Use popDisposition instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', + ) + @protected + bool get hasScopedWillPopCallback { + return _willPopCallbacks.isNotEmpty; + } + + @override + void didChangePrevious(Route<dynamic>? previousRoute) { + super.didChangePrevious(previousRoute); + changedInternalState(); + } + + @override + void didChangeNext(Route<dynamic>? nextRoute) { + super.didChangeNext(nextRoute); + changedInternalState(); + } + + @override + void didPopNext(Route<dynamic> nextRoute) { + super.didPopNext(nextRoute); + changedInternalState(); + } + + @override + void changedInternalState() { + super.changedInternalState(); + // No need to mark dirty if this method is called during build phase. + if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks) { + setState(() { /* internal state already changed */ }); + _modalBarrier.markNeedsBuild(); + } + _modalScope.maintainState = maintainState; + } + + @override + void changedExternalState() { + super.changedExternalState(); + _modalBarrier.markNeedsBuild(); + if (_scopeKey.currentState != null) { + _scopeKey.currentState!._forceRebuildPage(); + } + } + + /// Whether this route can be popped. + /// + /// A route can be popped if there is at least one active route below it, or + /// if [willHandlePopInternally] returns true. + /// + /// When this changes, if the route is visible, the route will + /// rebuild, and any widgets that used [ModalRoute.of] will be + /// notified. + bool get canPop => hasActiveRouteBelow || willHandlePopInternally; + + /// Whether an [AppBar] in the route should automatically add a back button or + /// close button. + /// + /// This getter returns true if there is at least one active route below it, + /// or there is at least one [LocalHistoryEntry] with [impliesAppBarDismissal] + /// set to true + bool get impliesAppBarDismissal => hasActiveRouteBelow || _entriesImpliesAppBarDismissal > 0; + + // Internals + + final GlobalKey<_ModalScopeState<T>> _scopeKey = GlobalKey<_ModalScopeState<T>>(); + final GlobalKey _subtreeKey = GlobalKey(); + final PageStorageBucket _storageBucket = PageStorageBucket(); + + // one of the builders + late OverlayEntry _modalBarrier; + Widget _buildModalBarrier(BuildContext context) { + Widget barrier = buildModalBarrier(); + if (filter != null) { + barrier = BackdropFilter( + filter: filter!, + child: barrier, + ); + } + barrier = IgnorePointer( + ignoring: animation!.status == AnimationStatus.reverse || // changedInternalState is called when animation.status updates + animation!.status == AnimationStatus.dismissed, // dismissed is possible when doing a manual pop gesture + child: barrier, + ); + if (semanticsDismissible && barrierDismissible) { + // To be sorted after the _modalScope. + barrier = Semantics( + sortKey: const OrdinalSortKey(1.0), + child: barrier, + ); + } + return barrier; + } + + /// Build the barrier for this [ModalRoute], subclasses can override + /// this method to create their own barrier with customized features such as + /// color or accessibility focus size. + /// + /// See also: + /// * [ModalBarrier], which is typically used to build a barrier. + /// * [ModalBottomSheetRoute], which overrides this method to build a + /// customized barrier. + Widget buildModalBarrier() { + Widget barrier; + if (barrierColor != null && barrierColor!.alpha != 0 && !offstage) { // changedInternalState is called if barrierColor or offstage updates + assert(barrierColor != barrierColor!.withOpacity(0.0)); + final Animation<Color?> color = animation!.drive( + ColorTween( + begin: barrierColor!.withOpacity(0.0), + end: barrierColor, // changedInternalState is called if barrierColor updates + ).chain(CurveTween(curve: barrierCurve)), // changedInternalState is called if barrierCurve updates + ); + barrier = AnimatedModalBarrier( + color: color, + dismissible: barrierDismissible, // changedInternalState is called if barrierDismissible updates + semanticsLabel: barrierLabel, // changedInternalState is called if barrierLabel updates + barrierSemanticsDismissible: semanticsDismissible, + ); + } else { + barrier = ModalBarrier( + dismissible: barrierDismissible, // changedInternalState is called if barrierDismissible updates + semanticsLabel: barrierLabel, // changedInternalState is called if barrierLabel updates + barrierSemanticsDismissible: semanticsDismissible, + ); + } + + return barrier; + } + + // We cache the part of the modal scope that doesn't change from frame to + // frame so that we minimize the amount of building that happens. + Widget? _modalScopeCache; + + // one of the builders + Widget _buildModalScope(BuildContext context) { + // To be sorted before the _modalBarrier. + return _modalScopeCache ??= Semantics( + sortKey: const OrdinalSortKey(0.0), + child: _ModalScope<T>( + key: _scopeKey, + route: this, + // _ModalScope calls buildTransitions() and buildChild(), defined above + ), + ); + } + + late OverlayEntry _modalScope; + + @override + Iterable<OverlayEntry> createOverlayEntries() { + return <OverlayEntry>[ + _modalBarrier = OverlayEntry(builder: _buildModalBarrier), + _modalScope = OverlayEntry(builder: _buildModalScope, maintainState: maintainState, canSizeOverlay: opaque), + ]; + } + + @override + String toString() => '${objectRuntimeType(this, 'ModalRoute')}($settings, animation: $_animation)'; +} + +/// A modal route that overlays a widget over the current route. +/// +/// {@macro flutter.widgets.ModalRoute.barrierDismissible} +/// +/// {@tool dartpad} +/// This example shows how to create a dialog box that is dismissible. +/// +/// ** See code in examples/api/lib/widgets/routes/popup_route.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ModalRoute], which is the base class for this class. +/// * [Navigator.pop], which is used to dismiss the route. +abstract class PopupRoute<T> extends ModalRoute<T> { + /// Initializes the [PopupRoute]. + PopupRoute({ + super.settings, + super.filter, + super.traversalEdgeBehavior, + }); + + @override + bool get opaque => false; + + @override + bool get maintainState => true; + + @override + bool get allowSnapshotting => false; +} + +/// A [Navigator] observer that notifies [RouteAware]s of changes to the +/// state of their [Route]. +/// +/// [RouteObserver] informs subscribers whenever a route of type `R` is pushed +/// on top of their own route of type `R` or popped from it. This is for example +/// useful to keep track of page transitions, e.g. a `RouteObserver<PageRoute>` +/// will inform subscribed [RouteAware]s whenever the user navigates away from +/// the current page route to another page route. +/// +/// To be informed about route changes of any type, consider instantiating a +/// `RouteObserver<Route>`. +/// +/// ## Type arguments +/// +/// When using more aggressive [lints](https://dart.dev/lints), +/// in particular lints such as `always_specify_types`, +/// the Dart analyzer will require that certain types +/// be given with their type arguments. Since the [Route] class and its +/// subclasses have a type argument, this includes the arguments passed to this +/// class. Consider using `dynamic` to specify the entire class of routes rather +/// than only specific subtypes. For example, to watch for all [ModalRoute] +/// variants, the `RouteObserver<ModalRoute<dynamic>>` type may be used. +/// +/// {@tool snippet} +/// +/// To make a [StatefulWidget] aware of its current [Route] state, implement +/// [RouteAware] in its [State] and subscribe it to a [RouteObserver]: +/// +/// ```dart +/// // Register the RouteObserver as a navigation observer. +/// final RouteObserver<ModalRoute<void>> routeObserver = RouteObserver<ModalRoute<void>>(); +/// +/// void main() { +/// runApp(MaterialApp( +/// home: Container(), +/// navigatorObservers: <RouteObserver<ModalRoute<void>>>[ routeObserver ], +/// )); +/// } +/// +/// class RouteAwareWidget extends StatefulWidget { +/// const RouteAwareWidget({super.key}); +/// +/// @override +/// State<RouteAwareWidget> createState() => RouteAwareWidgetState(); +/// } +/// +/// // Implement RouteAware in a widget's state and subscribe it to the RouteObserver. +/// class RouteAwareWidgetState extends State<RouteAwareWidget> with RouteAware { +/// +/// @override +/// void didChangeDependencies() { +/// super.didChangeDependencies(); +/// routeObserver.subscribe(this, ModalRoute.of(context)!); +/// } +/// +/// @override +/// void dispose() { +/// routeObserver.unsubscribe(this); +/// super.dispose(); +/// } +/// +/// @override +/// void didPush() { +/// // Route was pushed onto navigator and is now topmost route. +/// } +/// +/// @override +/// void didPopNext() { +/// // Covering route was popped off the navigator. +/// } +/// +/// @override +/// Widget build(BuildContext context) => Container(); +/// +/// } +/// ``` +/// {@end-tool} +class RouteObserver<R extends Route<dynamic>> extends NavigatorObserver { + final Map<R, Set<RouteAware>> _listeners = <R, Set<RouteAware>>{}; + + /// Whether this observer is managing changes for the specified route. + /// + /// If asserts are disabled, this method will throw an exception. + @visibleForTesting + bool debugObservingRoute(R route) { + late bool contained; + assert(() { + contained = _listeners.containsKey(route); + return true; + }()); + return contained; + } + + /// Subscribe [routeAware] to be informed about changes to [route]. + /// + /// Going forward, [routeAware] will be informed about qualifying changes + /// to [route], e.g. when [route] is covered by another route or when [route] + /// is popped off the [Navigator] stack. + void subscribe(RouteAware routeAware, R route) { + final Set<RouteAware> subscribers = _listeners.putIfAbsent(route, () => <RouteAware>{}); + if (subscribers.add(routeAware)) { + routeAware.didPush(); + } + } + + /// Unsubscribe [routeAware]. + /// + /// [routeAware] is no longer informed about changes to its route. If the given argument was + /// subscribed to multiple types, this will unregister it (once) from each type. + void unsubscribe(RouteAware routeAware) { + final List<R> routes = _listeners.keys.toList(); + for (final R route in routes) { + final Set<RouteAware>? subscribers = _listeners[route]; + if (subscribers != null) { + subscribers.remove(routeAware); + if (subscribers.isEmpty) { + _listeners.remove(route); + } + } + } + } + + @override + void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) { + if (route is R && previousRoute is R) { + final List<RouteAware>? previousSubscribers = _listeners[previousRoute]?.toList(); + + if (previousSubscribers != null) { + for (final RouteAware routeAware in previousSubscribers) { + routeAware.didPopNext(); + } + } + + final List<RouteAware>? subscribers = _listeners[route]?.toList(); + + if (subscribers != null) { + for (final RouteAware routeAware in subscribers) { + routeAware.didPop(); + } + } + } + } + + @override + void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) { + if (route is R && previousRoute is R) { + final Set<RouteAware>? previousSubscribers = _listeners[previousRoute]; + + if (previousSubscribers != null) { + for (final RouteAware routeAware in previousSubscribers) { + routeAware.didPushNext(); + } + } + } + } +} + +/// An interface for objects that are aware of their current [Route]. +/// +/// This is used with [RouteObserver] to make a widget aware of changes to the +/// [Navigator]'s session history. +abstract mixin class RouteAware { + /// Called when the top route has been popped off, and the current route + /// shows up. + void didPopNext() { } + + /// Called when the current route has been pushed. + void didPush() { } + + /// Called when the current route has been popped off. + void didPop() { } + + /// Called when a new route has been pushed, and the current route is no + /// longer visible. + void didPushNext() { } +} + +/// A general dialog route which allows for customization of the dialog popup. +/// +/// It is used internally by [showGeneralDialog] or can be directly pushed +/// onto the [Navigator] stack to enable state restoration. See +/// [showGeneralDialog] for a state restoration app example. +/// +/// This function takes a `pageBuilder`, which typically builds a dialog. +/// Content below the dialog is dimmed with a [ModalBarrier]. The widget +/// returned by the `builder` does not share a context with the location that +/// `showDialog` is originally called from. Use a [StatefulBuilder] or a +/// custom [StatefulWidget] if the dialog needs to update dynamically. +/// +/// The `barrierDismissible` argument is used to indicate whether tapping on the +/// barrier will dismiss the dialog. It is `true` by default and cannot be `null`. +/// +/// The `barrierColor` argument is used to specify the color of the modal +/// barrier that darkens everything below the dialog. If `null`, the default +/// color `Colors.black54` is used. +/// +/// The `settings` argument define the settings for this route. See +/// [RouteSettings] for details. +/// +/// {@template flutter.widgets.RawDialogRoute} +/// A [DisplayFeature] can split the screen into sub-screens. The closest one to +/// [anchorPoint] is used to render the content. +/// +/// If no [anchorPoint] is provided, then [Directionality] is used: +/// +/// * for [TextDirection.ltr], [anchorPoint] is `Offset.zero`, which will +/// cause the content to appear in the top-left sub-screen. +/// * for [TextDirection.rtl], [anchorPoint] is `Offset(double.maxFinite, 0)`, +/// which will cause the content to appear in the top-right sub-screen. +/// +/// If no [anchorPoint] is provided, and there is no [Directionality] ancestor +/// widget in the tree, then the widget asserts during build in debug mode. +/// {@endtemplate} +/// +/// See also: +/// +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +/// * [showGeneralDialog], which is a way to display a RawDialogRoute. +/// * [showDialog], which is a way to display a DialogRoute. +/// * [showCupertinoDialog], which displays an iOS-style dialog. +class RawDialogRoute<T> extends PopupRoute<T> { + /// A general dialog route which allows for customization of the dialog popup. + RawDialogRoute({ + required RoutePageBuilder pageBuilder, + bool barrierDismissible = true, + Color? barrierColor = const Color(0x80000000), + String? barrierLabel, + Duration transitionDuration = const Duration(milliseconds: 200), + RouteTransitionsBuilder? transitionBuilder, + super.settings, + this.anchorPoint, + super.traversalEdgeBehavior, + }) : _pageBuilder = pageBuilder, + _barrierDismissible = barrierDismissible, + _barrierLabel = barrierLabel, + _barrierColor = barrierColor, + _transitionDuration = transitionDuration, + _transitionBuilder = transitionBuilder; + + final RoutePageBuilder _pageBuilder; + + @override + bool get barrierDismissible => _barrierDismissible; + final bool _barrierDismissible; + + @override + String? get barrierLabel => _barrierLabel; + final String? _barrierLabel; + + @override + Color? get barrierColor => _barrierColor; + final Color? _barrierColor; + + @override + Duration get transitionDuration => _transitionDuration; + final Duration _transitionDuration; + + final RouteTransitionsBuilder? _transitionBuilder; + + /// {@macro flutter.widgets.DisplayFeatureSubScreen.anchorPoint} + final Offset? anchorPoint; + + @override + Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { + return Semantics( + scopesRoute: true, + explicitChildNodes: true, + child: DisplayFeatureSubScreen( + anchorPoint: anchorPoint, + child: _pageBuilder(context, animation, secondaryAnimation), + ), + ); + } + + @override + Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) { + if (_transitionBuilder == null) { + // Some default transition. + return FadeTransition( + opacity: CurvedAnimation( + parent: animation, + curve: Curves.linear, + ), + child: child, + ); + } + return _transitionBuilder(context, animation, secondaryAnimation, child); + } +} + +/// Displays a dialog above the current contents of the app. +/// +/// This function allows for customization of aspects of the dialog popup. +/// +/// This function takes a `pageBuilder` which is used to build the primary +/// content of the route (typically a dialog widget). Content below the dialog +/// is dimmed with a [ModalBarrier]. The widget returned by the `pageBuilder` +/// does not share a context with the location that [showGeneralDialog] is +/// originally called from. Use a [StatefulBuilder] or a custom +/// [StatefulWidget] if the dialog needs to update dynamically. +/// +/// The `context` argument is used to look up the [Navigator] for the +/// dialog. It is only used when the method is called. Its corresponding widget +/// can be safely removed from the tree before the dialog is closed. +/// +/// The `useRootNavigator` argument is used to determine whether to push the +/// dialog to the [Navigator] furthest from or nearest to the given `context`. +/// By default, `useRootNavigator` is `true` and the dialog route created by +/// this method is pushed to the root navigator. +/// +/// If the application has multiple [Navigator] objects, it may be necessary to +/// call `Navigator.of(context, rootNavigator: true).pop(result)` to close the +/// dialog rather than just `Navigator.pop(context, result)`. +/// +/// The `barrierDismissible` argument is used to determine whether this route +/// can be dismissed by tapping the modal barrier. This argument defaults +/// to false. If `barrierDismissible` is true, a non-null `barrierLabel` must be +/// provided. +/// +/// The `barrierLabel` argument is the semantic label used for a dismissible +/// barrier. This argument defaults to `null`. +/// +/// The `barrierColor` argument is the color used for the modal barrier. This +/// argument defaults to `Color(0x80000000)`. +/// +/// The `transitionDuration` argument is used to determine how long it takes +/// for the route to arrive on or leave off the screen. This argument defaults +/// to 200 milliseconds. +/// +/// The `transitionBuilder` argument is used to define how the route arrives on +/// and leaves off the screen. By default, the transition is a linear fade of +/// the page's contents. +/// +/// The `routeSettings` will be used in the construction of the dialog's route. +/// See [RouteSettings] for more details. +/// +/// {@macro flutter.widgets.RawDialogRoute} +/// +/// Returns a [Future] that resolves to the value (if any) that was passed to +/// [Navigator.pop] when the dialog was closed. +/// +/// ### State Restoration in Dialogs +/// +/// Using this method will not enable state restoration for the dialog. In order +/// to enable state restoration for a dialog, use [Navigator.restorablePush] +/// or [Navigator.restorablePushNamed] with [RawDialogRoute]. +/// +/// For more information about state restoration, see [RestorationManager]. +/// +/// {@tool sample} +/// This sample demonstrates how to create a restorable dialog. This is +/// accomplished by enabling state restoration by specifying +/// [WidgetsApp.restorationScopeId] and using [Navigator.restorablePush] to +/// push [RawDialogRoute] when the button is tapped. +/// +/// {@macro flutter.widgets.RestorationManager} +/// +/// ** See code in examples/api/lib/widgets/routes/show_general_dialog.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [DisplayFeatureSubScreen], which documents the specifics of how +/// [DisplayFeature]s can split the screen into sub-screens. +/// * [showDialog], which displays a Material-style dialog. +/// * [showCupertinoDialog], which displays an iOS-style dialog. +Future<T?> showGeneralDialog<T extends Object?>({ + required BuildContext context, + required RoutePageBuilder pageBuilder, + bool barrierDismissible = false, + String? barrierLabel, + Color barrierColor = const Color(0x80000000), + Duration transitionDuration = const Duration(milliseconds: 200), + RouteTransitionsBuilder? transitionBuilder, + bool useRootNavigator = true, + RouteSettings? routeSettings, + Offset? anchorPoint, +}) { + assert(!barrierDismissible || barrierLabel != null); + return Navigator.of(context, rootNavigator: useRootNavigator).push<T>(RawDialogRoute<T>( + pageBuilder: pageBuilder, + barrierDismissible: barrierDismissible, + barrierLabel: barrierLabel, + barrierColor: barrierColor, + transitionDuration: transitionDuration, + transitionBuilder: transitionBuilder, + settings: routeSettings, + anchorPoint: anchorPoint, + )); +} + +/// Signature for the function that builds a route's primary contents. +/// Used in [PageRouteBuilder] and [showGeneralDialog]. +/// +/// See [ModalRoute.buildPage] for complete definition of the parameters. +typedef RoutePageBuilder = Widget Function(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation); + +/// Signature for the function that builds a route's transitions. +/// Used in [PageRouteBuilder] and [showGeneralDialog]. +/// +/// See [ModalRoute.buildTransitions] for complete definition of the parameters. +typedef RouteTransitionsBuilder = Widget Function(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child); + +/// A callback type for informing that a navigation pop has been invoked, +/// whether or not it was handled successfully. +/// +/// Accepts a didPop boolean indicating whether or not back navigation +/// succeeded. +typedef PopInvokedCallback = void Function(bool didPop); + +/// Allows listening to and preventing pops. +/// +/// Can be registered in [ModalRoute] to listen to pops with [onPopInvoked] or +/// to enable/disable them with [canPopNotifier]. +/// +/// See also: +/// +/// * [PopScope], which provides similar functionality in a widget. +/// * [ModalRoute.registerPopEntry], which unregisters instances of this. +/// * [ModalRoute.unregisterPopEntry], which unregisters instances of this. +abstract class PopEntry { + /// {@macro flutter.widgets.PopScope.onPopInvoked} + PopInvokedCallback? get onPopInvoked; + + /// {@macro flutter.widgets.PopScope.canPop} + ValueListenable<bool> get canPopNotifier; + + @override + String toString() { + return 'PopEntry canPop: ${canPopNotifier.value}, onPopInvoked: $onPopInvoked'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/safe_area.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/safe_area.dart new file mode 100644 index 0000000000000000000000000000000000000000..93048ea3a7a10d83fcbd2249b100918f174f318f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/safe_area.dart @@ -0,0 +1,213 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'media_query.dart'; + +/// A widget that insets its child by sufficient padding to avoid intrusions by +/// the operating system. +/// +/// For example, this will indent the child by enough to avoid the status bar at +/// the top of the screen. +/// +/// It will also indent the child by the amount necessary to avoid The Notch on +/// the iPhone X, or other similar creative physical features of the display. +/// +/// When a [minimum] padding is specified, the greater of the minimum padding +/// or the safe area padding will be applied. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=lkF0TQJO0bA} +/// +/// See also: +/// +/// * [SliverSafeArea], for insetting slivers to avoid operating system +/// intrusions. +/// * [Padding], for insetting widgets in general. +/// * [MediaQuery], from which the window padding is obtained. +/// * [dart:ui.FlutterView.padding], which reports the padding from the operating +/// system. +class SafeArea extends StatelessWidget { + /// Creates a widget that avoids operating system interfaces. + /// + /// The [left], [top], [right], [bottom], and [minimum] arguments must not be + /// null. + const SafeArea({ + super.key, + this.left = true, + this.top = true, + this.right = true, + this.bottom = true, + this.minimum = EdgeInsets.zero, + this.maintainBottomViewPadding = false, + required this.child, + }); + + /// Whether to avoid system intrusions on the left. + final bool left; + + /// Whether to avoid system intrusions at the top of the screen, typically the + /// system status bar. + final bool top; + + /// Whether to avoid system intrusions on the right. + final bool right; + + /// Whether to avoid system intrusions on the bottom side of the screen. + final bool bottom; + + /// This minimum padding to apply. + /// + /// The greater of the minimum insets and the media padding will be applied. + final EdgeInsets minimum; + + /// Specifies whether the [SafeArea] should maintain the bottom + /// [MediaQueryData.viewPadding] instead of the bottom [MediaQueryData.padding], + /// defaults to false. + /// + /// For example, if there is an onscreen keyboard displayed above the + /// SafeArea, the padding can be maintained below the obstruction rather than + /// being consumed. This can be helpful in cases where your layout contains + /// flexible widgets, which could visibly move when opening a software + /// keyboard due to the change in the padding value. Setting this to true will + /// avoid the UI shift. + final bool maintainBottomViewPadding; + + /// The widget below this widget in the tree. + /// + /// The padding on the [MediaQuery] for the [child] will be suitably adjusted + /// to zero out any sides that were avoided by this widget. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + EdgeInsets padding = MediaQuery.paddingOf(context); + // Bottom padding has been consumed - i.e. by the keyboard + if (maintainBottomViewPadding) { + padding = padding.copyWith(bottom: MediaQuery.viewPaddingOf(context).bottom); + } + + return Padding( + padding: EdgeInsets.only( + left: math.max(left ? padding.left : 0.0, minimum.left), + top: math.max(top ? padding.top : 0.0, minimum.top), + right: math.max(right ? padding.right : 0.0, minimum.right), + bottom: math.max(bottom ? padding.bottom : 0.0, minimum.bottom), + ), + child: MediaQuery.removePadding( + context: context, + removeLeft: left, + removeTop: top, + removeRight: right, + removeBottom: bottom, + child: child, + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('left', value: left, ifTrue: 'avoid left padding')); + properties.add(FlagProperty('top', value: top, ifTrue: 'avoid top padding')); + properties.add(FlagProperty('right', value: right, ifTrue: 'avoid right padding')); + properties.add(FlagProperty('bottom', value: bottom, ifTrue: 'avoid bottom padding')); + } +} + +/// A sliver that insets another sliver by sufficient padding to avoid +/// intrusions by the operating system. +/// +/// For example, this will indent the sliver by enough to avoid the status bar +/// at the top of the screen. +/// +/// It will also indent the sliver by the amount necessary to avoid The Notch +/// on the iPhone X, or other similar creative physical features of the +/// display. +/// +/// When a [minimum] padding is specified, the greater of the minimum padding +/// or the safe area padding will be applied. +/// +/// See also: +/// +/// * [SafeArea], for insetting box widgets to avoid operating system intrusions. +/// * [SliverPadding], for insetting slivers in general. +/// * [MediaQuery], from which the window padding is obtained. +/// * [dart:ui.FlutterView.padding], which reports the padding from the operating +/// system. +class SliverSafeArea extends StatelessWidget { + /// Creates a sliver that avoids operating system interfaces. + const SliverSafeArea({ + super.key, + this.left = true, + this.top = true, + this.right = true, + this.bottom = true, + this.minimum = EdgeInsets.zero, + required this.sliver, + }); + + /// Whether to avoid system intrusions on the left. + final bool left; + + /// Whether to avoid system intrusions at the top of the screen, typically the + /// system status bar. + final bool top; + + /// Whether to avoid system intrusions on the right. + final bool right; + + /// Whether to avoid system intrusions on the bottom side of the screen. + final bool bottom; + + /// This minimum padding to apply. + /// + /// The greater of the minimum padding and the media padding is be applied. + final EdgeInsets minimum; + + /// The sliver below this sliver in the tree. + /// + /// The padding on the [MediaQuery] for the [sliver] will be suitably adjusted + /// to zero out any sides that were avoided by this sliver. + final Widget sliver; + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); + final EdgeInsets padding = MediaQuery.paddingOf(context); + return SliverPadding( + padding: EdgeInsets.only( + left: math.max(left ? padding.left : 0.0, minimum.left), + top: math.max(top ? padding.top : 0.0, minimum.top), + right: math.max(right ? padding.right : 0.0, minimum.right), + bottom: math.max(bottom ? padding.bottom : 0.0, minimum.bottom), + ), + sliver: MediaQuery.removePadding( + context: context, + removeLeft: left, + removeTop: top, + removeRight: right, + removeBottom: bottom, + child: sliver, + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('left', value: left, ifTrue: 'avoid left padding')); + properties.add(FlagProperty('top', value: top, ifTrue: 'avoid top padding')); + properties.add(FlagProperty('right', value: right, ifTrue: 'avoid right padding')); + properties.add(FlagProperty('bottom', value: bottom, ifTrue: 'avoid bottom padding')); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_activity.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_activity.dart new file mode 100644 index 0000000000000000000000000000000000000000..aa0f92958ed7384332a291550b336494dce0a1df --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_activity.dart @@ -0,0 +1,716 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'scroll_metrics.dart'; +import 'scroll_notification.dart'; + +/// A backend for a [ScrollActivity]. +/// +/// Used by subclasses of [ScrollActivity] to manipulate the scroll view that +/// they are acting upon. +/// +/// See also: +/// +/// * [ScrollActivity], which uses this class as its delegate. +/// * [ScrollPositionWithSingleContext], the main implementation of this interface. +abstract class ScrollActivityDelegate { + /// The direction in which the scroll view scrolls. + AxisDirection get axisDirection; + + /// Update the scroll position to the given pixel value. + /// + /// Returns the overscroll, if any. See [ScrollPosition.setPixels] for more + /// information. + double setPixels(double pixels); + + /// Updates the scroll position by the given amount. + /// + /// Appropriate for when the user is directly manipulating the scroll + /// position, for example by dragging the scroll view. Typically applies + /// [ScrollPhysics.applyPhysicsToUserOffset] and other transformations that + /// are appropriate for user-driving scrolling. + void applyUserOffset(double delta); + + /// Terminate the current activity and start an idle activity. + void goIdle(); + + /// Terminate the current activity and start a ballistic activity with the + /// given velocity. + void goBallistic(double velocity); +} + +/// Base class for scrolling activities like dragging and flinging. +/// +/// See also: +/// +/// * [ScrollPosition], which uses [ScrollActivity] objects to manage the +/// [ScrollPosition] of a [Scrollable]. +abstract class ScrollActivity { + /// Initializes [delegate] for subclasses. + ScrollActivity(this._delegate) { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/widgets.dart', + className: '$ScrollActivity', + object: this, + ); + } + } + + /// The delegate that this activity will use to actuate the scroll view. + ScrollActivityDelegate get delegate => _delegate; + ScrollActivityDelegate _delegate; + + bool _isDisposed = false; + + /// Updates the activity's link to the [ScrollActivityDelegate]. + /// + /// This should only be called when an activity is being moved from a defunct + /// (or about-to-be defunct) [ScrollActivityDelegate] object to a new one. + void updateDelegate(ScrollActivityDelegate value) { + assert(_delegate != value); + _delegate = value; + } + + /// Called by the [ScrollActivityDelegate] when it has changed type (for + /// example, when changing from an Android-style scroll position to an + /// iOS-style scroll position). If this activity can differ between the two + /// modes, then it should tell the position to restart that activity + /// appropriately. + /// + /// For example, [BallisticScrollActivity]'s implementation calls + /// [ScrollActivityDelegate.goBallistic]. + void resetActivity() { } + + /// Dispatch a [ScrollStartNotification] with the given metrics. + void dispatchScrollStartNotification(ScrollMetrics metrics, BuildContext? context) { + ScrollStartNotification(metrics: metrics, context: context).dispatch(context); + } + + /// Dispatch a [ScrollUpdateNotification] with the given metrics and scroll delta. + void dispatchScrollUpdateNotification(ScrollMetrics metrics, BuildContext context, double scrollDelta) { + ScrollUpdateNotification(metrics: metrics, context: context, scrollDelta: scrollDelta).dispatch(context); + } + + /// Dispatch an [OverscrollNotification] with the given metrics and overscroll. + void dispatchOverscrollNotification(ScrollMetrics metrics, BuildContext context, double overscroll) { + OverscrollNotification(metrics: metrics, context: context, overscroll: overscroll).dispatch(context); + } + + /// Dispatch a [ScrollEndNotification] with the given metrics and overscroll. + void dispatchScrollEndNotification(ScrollMetrics metrics, BuildContext context) { + ScrollEndNotification(metrics: metrics, context: context).dispatch(context); + } + + /// Called when the scroll view that is performing this activity changes its metrics. + void applyNewDimensions() { } + + /// Whether the scroll view should ignore pointer events while performing this + /// activity. + /// + /// See also: + /// + /// * [isScrolling], which describes whether the activity is considered + /// to represent user interaction or not. + bool get shouldIgnorePointer; + + /// Whether performing this activity constitutes scrolling. + /// + /// Used, for example, to determine whether the user scroll + /// direction (see [ScrollPosition.userScrollDirection]) is + /// [ScrollDirection.idle]. + /// + /// See also: + /// + /// * [shouldIgnorePointer], which controls whether pointer events + /// are allowed while the activity is live. + /// * [UserScrollNotification], which exposes this status. + bool get isScrolling; + + /// If applicable, the velocity at which the scroll offset is currently + /// independently changing (i.e. without external stimuli such as a dragging + /// gestures) in logical pixels per second for this activity. + double get velocity; + + /// Called when the scroll view stops performing this activity. + @mustCallSuper + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + + _isDisposed = true; + } + + @override + String toString() => describeIdentity(this); +} + +/// A scroll activity that does nothing. +/// +/// When a scroll view is not scrolling, it is performing the idle activity. +/// +/// If the [Scrollable] changes dimensions, this activity triggers a ballistic +/// activity to restore the view. +class IdleScrollActivity extends ScrollActivity { + /// Creates a scroll activity that does nothing. + IdleScrollActivity(super.delegate); + + @override + void applyNewDimensions() { + delegate.goBallistic(0.0); + } + + @override + bool get shouldIgnorePointer => false; + + @override + bool get isScrolling => false; + + @override + double get velocity => 0.0; +} + +/// Interface for holding a [Scrollable] stationary. +/// +/// An object that implements this interface is returned by +/// [ScrollPosition.hold]. It holds the scrollable stationary until an activity +/// is started or the [cancel] method is called. +abstract class ScrollHoldController { + /// Release the [Scrollable], potentially letting it go ballistic if + /// necessary. + void cancel(); +} + +/// A scroll activity that does nothing but can be released to resume +/// normal idle behavior. +/// +/// This is used while the user is touching the [Scrollable] but before the +/// touch has become a [Drag]. +/// +/// For the purposes of [ScrollNotification]s, this activity does not constitute +/// scrolling, and does not prevent the user from interacting with the contents +/// of the [Scrollable] (unlike when a drag has begun or there is a scroll +/// animation underway). +class HoldScrollActivity extends ScrollActivity implements ScrollHoldController { + /// Creates a scroll activity that does nothing. + HoldScrollActivity({ + required ScrollActivityDelegate delegate, + this.onHoldCanceled, + }) : super(delegate); + + /// Called when [dispose] is called. + final VoidCallback? onHoldCanceled; + + @override + bool get shouldIgnorePointer => false; + + @override + bool get isScrolling => false; + + @override + double get velocity => 0.0; + + @override + void cancel() { + delegate.goBallistic(0.0); + } + + @override + void dispose() { + onHoldCanceled?.call(); + super.dispose(); + } +} + +/// Scrolls a scroll view as the user drags their finger across the screen. +/// +/// See also: +/// +/// * [DragScrollActivity], which is the activity the scroll view performs +/// while a drag is underway. +class ScrollDragController implements Drag { + /// Creates an object that scrolls a scroll view as the user drags their + /// finger across the screen. + ScrollDragController({ + required ScrollActivityDelegate delegate, + required DragStartDetails details, + this.onDragCanceled, + this.carriedVelocity, + this.motionStartDistanceThreshold, + }) : assert( + motionStartDistanceThreshold == null || motionStartDistanceThreshold > 0.0, + 'motionStartDistanceThreshold must be a positive number or null', + ), + _delegate = delegate, + _lastDetails = details, + _retainMomentum = carriedVelocity != null && carriedVelocity != 0.0, + _lastNonStationaryTimestamp = details.sourceTimeStamp, + _kind = details.kind, + _offsetSinceLastStop = motionStartDistanceThreshold == null ? null : 0.0 { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/widgets.dart', + className: '$ScrollDragController', + object: this, + ); + } + } + + /// The object that will actuate the scroll view as the user drags. + ScrollActivityDelegate get delegate => _delegate; + ScrollActivityDelegate _delegate; + + /// Called when [dispose] is called. + final VoidCallback? onDragCanceled; + + /// Velocity that was present from a previous [ScrollActivity] when this drag + /// began. + final double? carriedVelocity; + + /// Amount of pixels in either direction the drag has to move by to start + /// scroll movement again after each time scrolling came to a stop. + final double? motionStartDistanceThreshold; + + Duration? _lastNonStationaryTimestamp; + bool _retainMomentum; + /// Null if already in motion or has no [motionStartDistanceThreshold]. + double? _offsetSinceLastStop; + + /// Maximum amount of time interval the drag can have consecutive stationary + /// pointer update events before losing the momentum carried from a previous + /// scroll activity. + static const Duration momentumRetainStationaryDurationThreshold = + Duration(milliseconds: 20); + + /// The minimum amount of velocity needed to apply the [carriedVelocity] at + /// the end of a drag. Expressed as a factor. For example with a + /// [carriedVelocity] of 2000, we will need a velocity of at least 1000 to + /// apply the [carriedVelocity] as well. If the velocity does not meet the + /// threshold, the [carriedVelocity] is lost. Decided by fair eyeballing + /// with the scroll_overlay platform test. + static const double momentumRetainVelocityThresholdFactor = 0.5; + + /// Maximum amount of time interval the drag can have consecutive stationary + /// pointer update events before needing to break the + /// [motionStartDistanceThreshold] to start motion again. + static const Duration motionStoppedDurationThreshold = + Duration(milliseconds: 50); + + /// The drag distance past which, a [motionStartDistanceThreshold] breaking + /// drag is considered a deliberate fling. + static const double _bigThresholdBreakDistance = 24.0; + + bool get _reversed => axisDirectionIsReversed(delegate.axisDirection); + + /// Updates the controller's link to the [ScrollActivityDelegate]. + /// + /// This should only be called when a controller is being moved from a defunct + /// (or about-to-be defunct) [ScrollActivityDelegate] object to a new one. + void updateDelegate(ScrollActivityDelegate value) { + assert(_delegate != value); + _delegate = value; + } + + /// Determines whether to lose the existing incoming velocity when starting + /// the drag. + void _maybeLoseMomentum(double offset, Duration? timestamp) { + if (_retainMomentum && + offset == 0.0 && + (timestamp == null || // If drag event has no timestamp, we lose momentum. + timestamp - _lastNonStationaryTimestamp! > momentumRetainStationaryDurationThreshold)) { + // If pointer is stationary for too long, we lose momentum. + _retainMomentum = false; + } + } + + /// If a motion start threshold exists, determine whether the threshold needs + /// to be broken to scroll. Also possibly apply an offset adjustment when + /// threshold is first broken. + /// + /// Returns `0.0` when stationary or within threshold. Returns `offset` + /// transparently when already in motion. + double _adjustForScrollStartThreshold(double offset, Duration? timestamp) { + if (timestamp == null) { + // If we can't track time, we can't apply thresholds. + // May be null for proxied drags like via accessibility. + return offset; + } + if (offset == 0.0) { + if (motionStartDistanceThreshold != null && + _offsetSinceLastStop == null && + timestamp - _lastNonStationaryTimestamp! > motionStoppedDurationThreshold) { + // Enforce a new threshold. + _offsetSinceLastStop = 0.0; + } + // Not moving can't break threshold. + return 0.0; + } else { + if (_offsetSinceLastStop == null) { + // Already in motion or no threshold behavior configured such as for + // Android. Allow transparent offset transmission. + return offset; + } else { + _offsetSinceLastStop = _offsetSinceLastStop! + offset; + if (_offsetSinceLastStop!.abs() > motionStartDistanceThreshold!) { + // Threshold broken. + _offsetSinceLastStop = null; + if (offset.abs() > _bigThresholdBreakDistance) { + // This is heuristically a very deliberate fling. Leave the motion + // unaffected. + return offset; + } else { + // This is a normal speed threshold break. + return math.min( + // Ease into the motion when the threshold is initially broken + // to avoid a visible jump. + motionStartDistanceThreshold! / 3.0, + offset.abs(), + ) * offset.sign; + } + } else { + return 0.0; + } + } + } + } + + @override + void update(DragUpdateDetails details) { + assert(details.primaryDelta != null); + _lastDetails = details; + double offset = details.primaryDelta!; + if (offset != 0.0) { + _lastNonStationaryTimestamp = details.sourceTimeStamp; + } + // By default, iOS platforms carries momentum and has a start threshold + // (configured in [BouncingScrollPhysics]). The 2 operations below are + // no-ops on Android. + _maybeLoseMomentum(offset, details.sourceTimeStamp); + offset = _adjustForScrollStartThreshold(offset, details.sourceTimeStamp); + if (offset == 0.0) { + return; + } + if (_reversed) { + offset = -offset; + } + delegate.applyUserOffset(offset); + } + + @override + void end(DragEndDetails details) { + assert(details.primaryVelocity != null); + // We negate the velocity here because if the touch is moving downwards, + // the scroll has to move upwards. It's the same reason that update() + // above negates the delta before applying it to the scroll offset. + double velocity = -details.primaryVelocity!; + if (_reversed) { + velocity = -velocity; + } + _lastDetails = details; + + if (_retainMomentum) { + // Build momentum only if dragging in the same direction. + final bool isFlingingInSameDirection = velocity.sign == carriedVelocity!.sign; + // Build momentum only if the velocity of the last drag was not + // substantially lower than the carried momentum. + final bool isVelocityNotSubstantiallyLessThanCarriedMomentum = + velocity.abs() > carriedVelocity!.abs() * momentumRetainVelocityThresholdFactor; + if (isFlingingInSameDirection && isVelocityNotSubstantiallyLessThanCarriedMomentum) { + velocity += carriedVelocity!; + } + } + delegate.goBallistic(velocity); + } + + @override + void cancel() { + delegate.goBallistic(0.0); + } + + /// Called by the delegate when it is no longer sending events to this object. + @mustCallSuper + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _lastDetails = null; + onDragCanceled?.call(); + } + + /// The type of input device driving the drag. + final PointerDeviceKind? _kind; + /// The most recently observed [DragStartDetails], [DragUpdateDetails], or + /// [DragEndDetails] object. + dynamic get lastDetails => _lastDetails; + dynamic _lastDetails; + + @override + String toString() => describeIdentity(this); +} + +/// The activity a scroll view performs when the user drags their finger +/// across the screen. +/// +/// See also: +/// +/// * [ScrollDragController], which listens to the [Drag] and actually scrolls +/// the scroll view. +class DragScrollActivity extends ScrollActivity { + /// Creates an activity for when the user drags their finger across the + /// screen. + DragScrollActivity( + super.delegate, + ScrollDragController controller, + ) : _controller = controller; + + ScrollDragController? _controller; + + @override + void dispatchScrollStartNotification(ScrollMetrics metrics, BuildContext? context) { + final dynamic lastDetails = _controller!.lastDetails; + assert(lastDetails is DragStartDetails); + ScrollStartNotification(metrics: metrics, context: context, dragDetails: lastDetails as DragStartDetails).dispatch(context); + } + + @override + void dispatchScrollUpdateNotification(ScrollMetrics metrics, BuildContext context, double scrollDelta) { + final dynamic lastDetails = _controller!.lastDetails; + assert(lastDetails is DragUpdateDetails); + ScrollUpdateNotification(metrics: metrics, context: context, scrollDelta: scrollDelta, dragDetails: lastDetails as DragUpdateDetails).dispatch(context); + } + + @override + void dispatchOverscrollNotification(ScrollMetrics metrics, BuildContext context, double overscroll) { + final dynamic lastDetails = _controller!.lastDetails; + assert(lastDetails is DragUpdateDetails); + OverscrollNotification(metrics: metrics, context: context, overscroll: overscroll, dragDetails: lastDetails as DragUpdateDetails).dispatch(context); + } + + @override + void dispatchScrollEndNotification(ScrollMetrics metrics, BuildContext context) { + // We might not have DragEndDetails yet if we're being called from beginActivity. + final dynamic lastDetails = _controller!.lastDetails; + ScrollEndNotification( + metrics: metrics, + context: context, + dragDetails: lastDetails is DragEndDetails ? lastDetails : null, + ).dispatch(context); + } + + @override + bool get shouldIgnorePointer => _controller?._kind != PointerDeviceKind.trackpad; + + @override + bool get isScrolling => true; + + // DragScrollActivity is not independently changing velocity yet + // until the drag is ended. + @override + double get velocity => 0.0; + + @override + void dispose() { + _controller = null; + super.dispose(); + } + + @override + String toString() { + return '${describeIdentity(this)}($_controller)'; + } +} + +/// An activity that animates a scroll view based on a physics [Simulation]. +/// +/// A [BallisticScrollActivity] is typically used when the user lifts their +/// finger off the screen to continue the scrolling gesture with the current velocity. +/// +/// [BallisticScrollActivity] is also used to restore a scroll view to a valid +/// scroll offset when the geometry of the scroll view changes. In these +/// situations, the [Simulation] typically starts with a zero velocity. +/// +/// See also: +/// +/// * [DrivenScrollActivity], which animates a scroll view based on a set of +/// animation parameters. +class BallisticScrollActivity extends ScrollActivity { + /// Creates an activity that animates a scroll view based on a [simulation]. + BallisticScrollActivity( + super.delegate, + Simulation simulation, + TickerProvider vsync, + this.shouldIgnorePointer, + ) { + _controller = AnimationController.unbounded( + debugLabel: kDebugMode ? objectRuntimeType(this, 'BallisticScrollActivity') : null, + vsync: vsync, + ) + ..addListener(_tick) + ..animateWith(simulation) + .whenComplete(_end); // won't trigger if we dispose _controller before it completes. + } + + late AnimationController _controller; + + @override + void resetActivity() { + delegate.goBallistic(velocity); + } + + @override + void applyNewDimensions() { + delegate.goBallistic(velocity); + } + + void _tick() { + if (!applyMoveTo(_controller.value)) { + delegate.goIdle(); + } + } + + /// Move the position to the given location. + /// + /// If the new position was fully applied, returns true. If there was any + /// overflow, returns false. + /// + /// The default implementation calls [ScrollActivityDelegate.setPixels] + /// and returns true if the overflow was zero. + @protected + bool applyMoveTo(double value) { + return delegate.setPixels(value).abs() < precisionErrorTolerance; + } + + void _end() { + // Check if the activity was disposed before going ballistic because _end might be called + // if _controller is disposed just after completion. + if (!_isDisposed) { + delegate.goBallistic(0.0); + } + } + + @override + void dispatchOverscrollNotification(ScrollMetrics metrics, BuildContext context, double overscroll) { + OverscrollNotification(metrics: metrics, context: context, overscroll: overscroll, velocity: velocity).dispatch(context); + } + + @override + final bool shouldIgnorePointer; + + @override + bool get isScrolling => true; + + @override + double get velocity => _controller.velocity; + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + String toString() { + return '${describeIdentity(this)}($_controller)'; + } +} + +/// An activity that animates a scroll view based on animation parameters. +/// +/// For example, a [DrivenScrollActivity] is used to implement +/// [ScrollController.animateTo]. +/// +/// See also: +/// +/// * [BallisticScrollActivity], which animates a scroll view based on a +/// physics [Simulation]. +class DrivenScrollActivity extends ScrollActivity { + /// Creates an activity that animates a scroll view based on animation + /// parameters. + DrivenScrollActivity( + super.delegate, { + required double from, + required double to, + required Duration duration, + required Curve curve, + required TickerProvider vsync, + }) : assert(duration > Duration.zero) { + _completer = Completer<void>(); + _controller = AnimationController.unbounded( + value: from, + debugLabel: objectRuntimeType(this, 'DrivenScrollActivity'), + vsync: vsync, + ) + ..addListener(_tick) + ..animateTo(to, duration: duration, curve: curve) + .whenComplete(_end); // won't trigger if we dispose _controller before it completes. + } + + late final Completer<void> _completer; + late final AnimationController _controller; + + /// A [Future] that completes when the activity stops. + /// + /// For example, this [Future] will complete if the animation reaches the end + /// or if the user interacts with the scroll view in way that causes the + /// animation to stop before it reaches the end. + Future<void> get done => _completer.future; + + void _tick() { + if (delegate.setPixels(_controller.value) != 0.0) { + delegate.goIdle(); + } + } + + void _end() { + // Check if the activity was disposed before going ballistic because _end might be called + // if _controller is disposed just after completion. + if (!_isDisposed) { + delegate.goBallistic(velocity); + } + } + + @override + void dispatchOverscrollNotification(ScrollMetrics metrics, BuildContext context, double overscroll) { + OverscrollNotification(metrics: metrics, context: context, overscroll: overscroll, velocity: velocity).dispatch(context); + } + + @override + bool get shouldIgnorePointer => true; + + @override + bool get isScrolling => true; + + @override + double get velocity => _controller.velocity; + + @override + void dispose() { + _completer.complete(); + _controller.dispose(); + super.dispose(); + } + + @override + String toString() { + return '${describeIdentity(this)}($_controller)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_aware_image_provider.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_aware_image_provider.dart new file mode 100644 index 0000000000000000000000000000000000000000..11d903e808f83705368fa4d7a78b572431215727 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_aware_image_provider.dart @@ -0,0 +1,115 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/painting.dart'; +import 'package:flutter/scheduler.dart'; + +import 'disposable_build_context.dart'; +import 'framework.dart'; +import 'scrollable.dart'; + +/// An [ImageProvider] that makes use of +/// [Scrollable.recommendDeferredLoadingForContext] to avoid loading images when +/// rapidly scrolling. +/// +/// This provider assumes that its wrapped [imageProvider] correctly uses the +/// [ImageCache], and does not attempt to re-acquire or decode images in the +/// cache. +/// +/// Calling [resolve] on this provider will cause it to obtain the image key +/// and then check the following: +/// +/// 1. If the returned [ImageStream] has been completed, end. This can happen +/// if the caller sets the completer on the stream. +/// 2. If the [ImageCache] has a completer for the key for this image, ask the +/// wrapped provider to resolve. +/// This can happen if the image was precached, or another [ImageProvider] +/// already resolved the same image. +/// 3. If the [context] has been disposed, end. This can happen if the caller +/// has been disposed and is no longer interested in resolving the image. +/// 4. If the widget is scrolling with high velocity at this point in time, +/// wait until the beginning of the next frame and go back to step 1. +/// 5. Delegate loading the image to the wrapped provider and finish. +/// +/// If the cycle ends at steps 1 or 3, the [ImageStream] will never be marked as +/// complete and listeners will not be notified. +/// +/// The [Image] widget wraps its incoming providers with this provider to avoid +/// overutilization of resources for images that would never appear on screen or +/// only be visible for a very brief period. +@optionalTypeArgs +class ScrollAwareImageProvider<T extends Object> extends ImageProvider<T> { + /// Creates a [ScrollAwareImageProvider]. + /// + /// The [context] object is the [BuildContext] of the [State] using this + /// provider. It is used to determine scrolling velocity during [resolve]. + /// + /// The [imageProvider] is used to create a key and load the image. It must + /// not be null, and is assumed to interact with the cache in the normal way + /// that [ImageProvider.resolveStreamForKey] does. + const ScrollAwareImageProvider({ + required this.context, + required this.imageProvider, + }); + + /// The context that may or may not be enclosed by a [Scrollable]. + /// + /// Once [DisposableBuildContext.dispose] is called on this context, + /// the provider will stop trying to resolve the image if it has not already + /// been resolved. + final DisposableBuildContext context; + + /// The wrapped image provider to delegate [obtainKey] and [loadImage] to. + final ImageProvider<T> imageProvider; + + @override + void resolveStreamForKey( + ImageConfiguration configuration, + ImageStream stream, + T key, + ImageErrorListener handleError, + ) { + // Something managed to complete the stream, or it's already in the image + // cache. Notify the wrapped provider and expect it to behave by not + // reloading the image since it's already resolved. + // Do this even if the context has gone out of the tree, since it will + // update LRU information about the cache. Even though we never showed the + // image, it was still touched more recently. + // Do this before checking scrolling, so that if the bytes are available we + // render them even though we're scrolling fast - there's no additional + // allocations to do for texture memory, it's already there. + if (stream.completer != null || PaintingBinding.instance.imageCache.containsKey(key)) { + imageProvider.resolveStreamForKey(configuration, stream, key, handleError); + return; + } + // The context has gone out of the tree - ignore it. + if (context.context == null) { + return; + } + // Something still wants this image, but check if the context is scrolling + // too fast before scheduling work that might never show on screen. + // Try to get to end of the frame callbacks of the next frame, and then + // check again. + if (Scrollable.recommendDeferredLoadingForContext(context.context!)) { + SchedulerBinding.instance.scheduleFrameCallback((_) { + scheduleMicrotask(() => resolveStreamForKey(configuration, stream, key, handleError)); + }); + return; + } + // We are in the tree, we're not scrolling too fast, the cache doesn't + // have our image, and no one has otherwise completed the stream. Go. + imageProvider.resolveStreamForKey(configuration, stream, key, handleError); + } + + @override + ImageStreamCompleter loadBuffer(T key, DecoderBufferCallback decode) => imageProvider.loadBuffer(key, decode); + + @override + ImageStreamCompleter loadImage(T key, ImageDecoderCallback decode) => imageProvider.loadImage(key, decode); + + @override + Future<T> obtainKey(ImageConfiguration configuration) => imageProvider.obtainKey(configuration); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_configuration.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_configuration.dart new file mode 100644 index 0000000000000000000000000000000000000000..599a2aa9173ff0bf248c2097d61187a82184b01c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_configuration.dart @@ -0,0 +1,386 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart' show LogicalKeyboardKey; + +import 'framework.dart'; +import 'overscroll_indicator.dart'; +import 'scroll_physics.dart'; +import 'scrollable.dart'; +import 'scrollable_helpers.dart'; +import 'scrollbar.dart'; + +const Color _kDefaultGlowColor = Color(0xFFFFFFFF); + +/// Device types that scrollables should accept drag gestures from by default. +const Set<PointerDeviceKind> _kTouchLikeDeviceTypes = <PointerDeviceKind>{ + PointerDeviceKind.touch, + PointerDeviceKind.stylus, + PointerDeviceKind.invertedStylus, + PointerDeviceKind.trackpad, + // The VoiceAccess sends pointer events with unknown type when scrolling + // scrollables. + PointerDeviceKind.unknown, +}; + +/// Types of overscroll indicators supported by [TargetPlatform.android]. +enum AndroidOverscrollIndicator { + /// Utilizes a [StretchingOverscrollIndicator], which transforms the contents + /// of a [ScrollView] when overscrolled. + stretch, + + /// Utilizes a [GlowingOverscrollIndicator], painting a glowing semi circle on + /// top of the [ScrollView] in response to overscrolling. + glow, +} + +/// Describes how [Scrollable] widgets should behave. +/// +/// {@template flutter.widgets.scrollBehavior} +/// Used by [ScrollConfiguration] to configure the [Scrollable] widgets in a +/// subtree. +/// +/// This class can be extended to further customize a [ScrollBehavior] for a +/// subtree. For example, overriding [ScrollBehavior.getScrollPhysics] sets the +/// default [ScrollPhysics] for [Scrollable]s that inherit this [ScrollConfiguration]. +/// Overriding [ScrollBehavior.buildOverscrollIndicator] can be used to add or change +/// the default [GlowingOverscrollIndicator] decoration, while +/// [ScrollBehavior.buildScrollbar] can be changed to modify the default [Scrollbar]. +/// +/// When looking to easily toggle the default decorations, you can use +/// [ScrollBehavior.copyWith] instead of creating your own [ScrollBehavior] class. +/// The `scrollbar` and `overscrollIndicator` flags can turn these decorations off. +/// {@endtemplate} +/// +/// See also: +/// +/// * [ScrollConfiguration], the inherited widget that controls how +/// [Scrollable] widgets behave in a subtree. +@immutable +class ScrollBehavior { + /// Creates a description of how [Scrollable] widgets should behave. + const ScrollBehavior(); + + /// Creates a copy of this ScrollBehavior, making it possible to + /// easily toggle `scrollbar` and `overscrollIndicator` effects. + /// + /// This is used by widgets like [PageView] and [ListWheelScrollView] to + /// override the current [ScrollBehavior] and manage how they are decorated. + /// Widgets such as these have the option to provide a [ScrollBehavior] on + /// the widget level, like [PageView.scrollBehavior], in order to change the + /// default. + ScrollBehavior copyWith({ + bool? scrollbars, + bool? overscroll, + Set<PointerDeviceKind>? dragDevices, + MultitouchDragStrategy? multitouchDragStrategy, + Set<LogicalKeyboardKey>? pointerAxisModifiers, + ScrollPhysics? physics, + TargetPlatform? platform, + }) { + return _WrappedScrollBehavior( + delegate: this, + scrollbars: scrollbars ?? true, + overscroll: overscroll ?? true, + dragDevices: dragDevices, + multitouchDragStrategy: multitouchDragStrategy, + pointerAxisModifiers: pointerAxisModifiers, + physics: physics, + platform: platform, + ); + } + + /// The platform whose scroll physics should be implemented. + /// + /// Defaults to the current platform. + TargetPlatform getPlatform(BuildContext context) => defaultTargetPlatform; + + /// The device kinds that the scrollable will accept drag gestures from. + /// + /// By default only [PointerDeviceKind.touch], [PointerDeviceKind.stylus], and + /// [PointerDeviceKind.invertedStylus] are configured to create drag gestures. + /// Enabling this for [PointerDeviceKind.mouse] will make it difficult or + /// impossible to select text in scrollable containers and is not recommended. + Set<PointerDeviceKind> get dragDevices => _kTouchLikeDeviceTypes; + + /// {@macro flutter.gestures.monodrag.DragGestureRecognizer.multitouchDragStrategy} + /// + /// By default, [MultitouchDragStrategy.latestPointer] is configured to + /// create drag gestures for all platforms. + MultitouchDragStrategy get multitouchDragStrategy => MultitouchDragStrategy.latestPointer; + + /// A set of [LogicalKeyboardKey]s that, when any or all are pressed in + /// combination with a [PointerDeviceKind.mouse] pointer scroll event, will + /// flip the axes of the scroll input. + /// + /// This will for example, result in the input of a vertical mouse wheel, to + /// move the [ScrollPosition] of a [ScrollView] with an [Axis.horizontal] + /// scroll direction. + /// + /// If other keys exclusive of this set are pressed during a scroll event, in + /// conjunction with keys from this set, the scroll input will still be + /// flipped. + /// + /// Defaults to [LogicalKeyboardKey.shiftLeft], + /// [LogicalKeyboardKey.shiftRight]. + Set<LogicalKeyboardKey> get pointerAxisModifiers => <LogicalKeyboardKey>{ + LogicalKeyboardKey.shiftLeft, + LogicalKeyboardKey.shiftRight, + }; + + /// Applies a [RawScrollbar] to the child widget on desktop platforms. + Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) { + // When modifying this function, consider modifying the implementation in + // the Material and Cupertino subclasses as well. + switch (getPlatform(context)) { + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + assert(details.controller != null); + return RawScrollbar( + controller: details.controller, + child: child, + ); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + return child; + } + } + + /// Applies a [GlowingOverscrollIndicator] to the child widget on + /// [TargetPlatform.android] and [TargetPlatform.fuchsia]. + Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) { + // When modifying this function, consider modifying the implementation in + // the Material and Cupertino subclasses as well. + switch (getPlatform(context)) { + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return child; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + return GlowingOverscrollIndicator( + axisDirection: details.direction, + color: _kDefaultGlowColor, + child: child, + ); + } + } + + /// Specifies the type of velocity tracker to use in the descendant + /// [Scrollable]s' drag gesture recognizers, for estimating the velocity of a + /// drag gesture. + /// + /// This can be used to, for example, apply different fling velocity + /// estimation methods on different platforms, in order to match the + /// platform's native behavior. + /// + /// Typically, the provided [GestureVelocityTrackerBuilder] should return a + /// fresh velocity tracker. If null is returned, [Scrollable] creates a new + /// [VelocityTracker] to track the newly added pointer that may develop into + /// a drag gesture. + /// + /// The default implementation provides a new + /// [IOSScrollViewFlingVelocityTracker] on iOS and macOS for each new pointer, + /// and a new [VelocityTracker] on other platforms for each new pointer. + GestureVelocityTrackerBuilder velocityTrackerBuilder(BuildContext context) { + switch (getPlatform(context)) { + case TargetPlatform.iOS: + return (PointerEvent event) => IOSScrollViewFlingVelocityTracker(event.kind); + case TargetPlatform.macOS: + return (PointerEvent event) => MacOSScrollViewFlingVelocityTracker(event.kind); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return (PointerEvent event) => VelocityTracker.withKind(event.kind); + } + } + + static const ScrollPhysics _bouncingPhysics = BouncingScrollPhysics(parent: RangeMaintainingScrollPhysics()); + static const ScrollPhysics _bouncingDesktopPhysics = BouncingScrollPhysics( + decelerationRate: ScrollDecelerationRate.fast, + parent: RangeMaintainingScrollPhysics() + ); + static const ScrollPhysics _clampingPhysics = ClampingScrollPhysics(parent: RangeMaintainingScrollPhysics()); + + /// The scroll physics to use for the platform given by [getPlatform]. + /// + /// Defaults to [RangeMaintainingScrollPhysics] mixed with + /// [BouncingScrollPhysics] on iOS and [ClampingScrollPhysics] on + /// Android. + ScrollPhysics getScrollPhysics(BuildContext context) { + // When modifying this function, consider modifying the implementation in + // the Material and Cupertino subclasses as well. + switch (getPlatform(context)) { + case TargetPlatform.iOS: + return _bouncingPhysics; + case TargetPlatform.macOS: + return _bouncingDesktopPhysics; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return _clampingPhysics; + } + } + + /// Called whenever a [ScrollConfiguration] is rebuilt with a new + /// [ScrollBehavior] of the same [runtimeType]. + /// + /// If the new instance represents different information than the old + /// instance, then the method should return true, otherwise it should return + /// false. + /// + /// If this method returns true, all the widgets that inherit from the + /// [ScrollConfiguration] will rebuild using the new [ScrollBehavior]. If this + /// method returns false, the rebuilds might be optimized away. + bool shouldNotify(covariant ScrollBehavior oldDelegate) => false; + + @override + String toString() => objectRuntimeType(this, 'ScrollBehavior'); +} + +class _WrappedScrollBehavior implements ScrollBehavior { + const _WrappedScrollBehavior({ + required this.delegate, + this.scrollbars = true, + this.overscroll = true, + Set<PointerDeviceKind>? dragDevices, + MultitouchDragStrategy? multitouchDragStrategy, + Set<LogicalKeyboardKey>? pointerAxisModifiers, + this.physics, + this.platform, + }) : _dragDevices = dragDevices, + _multitouchDragStrategy = multitouchDragStrategy, + _pointerAxisModifiers = pointerAxisModifiers; + + final ScrollBehavior delegate; + final bool scrollbars; + final bool overscroll; + final ScrollPhysics? physics; + final TargetPlatform? platform; + final Set<PointerDeviceKind>? _dragDevices; + final MultitouchDragStrategy? _multitouchDragStrategy; + final Set<LogicalKeyboardKey>? _pointerAxisModifiers; + + @override + Set<PointerDeviceKind> get dragDevices => _dragDevices ?? delegate.dragDevices; + + @override + MultitouchDragStrategy get multitouchDragStrategy => _multitouchDragStrategy ?? delegate.multitouchDragStrategy; + + @override + Set<LogicalKeyboardKey> get pointerAxisModifiers => _pointerAxisModifiers ?? delegate.pointerAxisModifiers; + + @override + Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) { + if (overscroll) { + return delegate.buildOverscrollIndicator(context, child, details); + } + return child; + } + + @override + Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) { + if (scrollbars) { + return delegate.buildScrollbar(context, child, details); + } + return child; + } + + @override + ScrollBehavior copyWith({ + bool? scrollbars, + bool? overscroll, + Set<PointerDeviceKind>? dragDevices, + MultitouchDragStrategy? multitouchDragStrategy, + Set<LogicalKeyboardKey>? pointerAxisModifiers, + ScrollPhysics? physics, + TargetPlatform? platform, + }) { + return delegate.copyWith( + scrollbars: scrollbars ?? this.scrollbars, + overscroll: overscroll ?? this.overscroll, + dragDevices: dragDevices ?? this.dragDevices, + multitouchDragStrategy: multitouchDragStrategy ?? this.multitouchDragStrategy, + pointerAxisModifiers: pointerAxisModifiers ?? this.pointerAxisModifiers, + physics: physics ?? this.physics, + platform: platform ?? this.platform, + ); + } + + @override + TargetPlatform getPlatform(BuildContext context) { + return platform ?? delegate.getPlatform(context); + } + + @override + ScrollPhysics getScrollPhysics(BuildContext context) { + return physics ?? delegate.getScrollPhysics(context); + } + + @override + bool shouldNotify(_WrappedScrollBehavior oldDelegate) { + return oldDelegate.delegate.runtimeType != delegate.runtimeType + || oldDelegate.scrollbars != scrollbars + || oldDelegate.overscroll != overscroll + || !setEquals<PointerDeviceKind>(oldDelegate.dragDevices, dragDevices) + || oldDelegate.multitouchDragStrategy != multitouchDragStrategy + || !setEquals<LogicalKeyboardKey>(oldDelegate.pointerAxisModifiers, pointerAxisModifiers) + || oldDelegate.physics != physics + || oldDelegate.platform != platform + || delegate.shouldNotify(oldDelegate.delegate); + } + + @override + GestureVelocityTrackerBuilder velocityTrackerBuilder(BuildContext context) { + return delegate.velocityTrackerBuilder(context); + } + + @override + String toString() => objectRuntimeType(this, '_WrappedScrollBehavior'); +} + +/// Controls how [Scrollable] widgets behave in a subtree. +/// +/// The scroll configuration determines the [ScrollPhysics] and viewport +/// decorations used by descendants of [child]. +class ScrollConfiguration extends InheritedWidget { + /// Creates a widget that controls how [Scrollable] widgets behave in a subtree. + const ScrollConfiguration({ + super.key, + required this.behavior, + required super.child, + }); + + /// How [Scrollable] widgets that are descendants of [child] should behave. + final ScrollBehavior behavior; + + /// The [ScrollBehavior] for [Scrollable] widgets in the given [BuildContext]. + /// + /// If no [ScrollConfiguration] widget is in scope of the given `context`, + /// a default [ScrollBehavior] instance is returned. + static ScrollBehavior of(BuildContext context) { + final ScrollConfiguration? configuration = context.dependOnInheritedWidgetOfExactType<ScrollConfiguration>(); + return configuration?.behavior ?? const ScrollBehavior(); + } + + @override + bool updateShouldNotify(ScrollConfiguration oldWidget) { + return behavior.runtimeType != oldWidget.behavior.runtimeType + || (behavior != oldWidget.behavior && behavior.shouldNotify(oldWidget.behavior)); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ScrollBehavior>('behavior', behavior)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_context.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_context.dart new file mode 100644 index 0000000000000000000000000000000000000000..19406f0c92eaa487d4346f40e5f3fd5c643733a6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_context.dart @@ -0,0 +1,75 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; + +import 'framework.dart'; +import 'ticker_provider.dart'; + +/// An interface that [Scrollable] widgets implement in order to use +/// [ScrollPosition]. +/// +/// See also: +/// +/// * [ScrollableState], which is the most common implementation of this +/// interface. +/// * [ScrollPosition], which uses this interface to communicate with the +/// scrollable widget. +abstract class ScrollContext { + /// The [BuildContext] that should be used when dispatching + /// [ScrollNotification]s. + /// + /// This context is typically different that the context of the scrollable + /// widget itself. For example, [Scrollable] uses a context outside the + /// [Viewport] but inside the widgets created by + /// [ScrollBehavior.buildOverscrollIndicator] and [ScrollBehavior.buildScrollbar]. + BuildContext? get notificationContext; + + /// The [BuildContext] that should be used when searching for a [PageStorage]. + /// + /// This context is typically the context of the scrollable widget itself. In + /// particular, it should involve any [GlobalKey]s that are dynamically + /// created as part of creating the scrolling widget, since those would be + /// different each time the widget is created. + // TODO(goderbauer): Deprecate this when state restoration supports all features of PageStorage. + BuildContext get storageContext; + + /// A [TickerProvider] to use when animating the scroll position. + TickerProvider get vsync; + + /// The direction in which the widget scrolls. + AxisDirection get axisDirection; + + /// The [FlutterView.devicePixelRatio] of the view that the [Scrollable] this + /// [ScrollContext] is associated with is drawn into. + double get devicePixelRatio; + + /// Whether the contents of the widget should ignore [PointerEvent] inputs. + /// + /// Setting this value to true prevents the use from interacting with the + /// contents of the widget with pointer events. The widget itself is still + /// interactive. + /// + /// For example, if the scroll position is being driven by an animation, it + /// might be appropriate to set this value to ignore pointer events to + /// prevent the user from accidentally interacting with the contents of the + /// widget as it animates. The user will still be able to touch the widget, + /// potentially stopping the animation. + void setIgnorePointer(bool value); + + /// Whether the user can drag the widget, for example to initiate a scroll. + void setCanDrag(bool value); + + /// Set the [SemanticsAction]s that should be expose to the semantics tree. + void setSemanticsActions(Set<SemanticsAction> actions); + + /// Called by the [ScrollPosition] whenever scrolling ends to persist the + /// provided scroll `offset` for state restoration purposes. + /// + /// The [ScrollContext] may pass the value back to a [ScrollPosition] by + /// calling [ScrollPosition.restoreOffset] at a later point in time or after + /// the application has restarted to restore the scroll offset. + void saveOffset(double offset); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_controller.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_controller.dart new file mode 100644 index 0000000000000000000000000000000000000000..d9a478328ce926e4d8581c7bdf47d96f50b5b873 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_controller.dart @@ -0,0 +1,438 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/animation.dart'; +import 'package:flutter/foundation.dart'; + +import 'scroll_context.dart'; +import 'scroll_physics.dart'; +import 'scroll_position.dart'; +import 'scroll_position_with_single_context.dart'; + +// Examples can assume: +// TrackingScrollController _trackingScrollController = TrackingScrollController(); + +/// Signature for when a [ScrollController] has added or removed a +/// [ScrollPosition]. +/// +/// Since a [ScrollPosition] is not created and attached to a controller until +/// the [Scrollable] is built, this can be used to respond to the position being +/// attached to a controller. +/// +/// By having access to the position directly, additional listeners can be +/// applied to aspects of the scroll position, like +/// [ScrollPosition.isScrollingNotifier]. +/// +/// Used by [ScrollController.onAttach] and [ScrollController.onDetach]. +typedef ScrollControllerCallback = void Function(ScrollPosition position); + +/// Controls a scrollable widget. +/// +/// Scroll controllers are typically stored as member variables in [State] +/// objects and are reused in each [State.build]. A single scroll controller can +/// be used to control multiple scrollable widgets, but some operations, such +/// as reading the scroll [offset], require the controller to be used with a +/// single scrollable widget. +/// +/// A scroll controller creates a [ScrollPosition] to manage the state specific +/// to an individual [Scrollable] widget. To use a custom [ScrollPosition], +/// subclass [ScrollController] and override [createScrollPosition]. +/// +/// {@macro flutter.widgets.scrollPosition.listening} +/// +/// Typically used with [ListView], [GridView], [CustomScrollView]. +/// +/// See also: +/// +/// * [ListView], [GridView], [CustomScrollView], which can be controlled by a +/// [ScrollController]. +/// * [Scrollable], which is the lower-level widget that creates and associates +/// [ScrollPosition] objects with [ScrollController] objects. +/// * [PageController], which is an analogous object for controlling a +/// [PageView]. +/// * [ScrollPosition], which manages the scroll offset for an individual +/// scrolling widget. +/// * [ScrollNotification] and [NotificationListener], which can be used to +/// listen to scrolling occur without using a [ScrollController]. +class ScrollController extends ChangeNotifier { + /// Creates a controller for a scrollable widget. + ScrollController({ + double initialScrollOffset = 0.0, + this.keepScrollOffset = true, + this.debugLabel, + this.onAttach, + this.onDetach, + }) : _initialScrollOffset = initialScrollOffset { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + /// The initial value to use for [offset]. + /// + /// New [ScrollPosition] objects that are created and attached to this + /// controller will have their offset initialized to this value + /// if [keepScrollOffset] is false or a scroll offset hasn't been saved yet. + /// + /// Defaults to 0.0. + double get initialScrollOffset => _initialScrollOffset; + final double _initialScrollOffset; + + /// Each time a scroll completes, save the current scroll [offset] with + /// [PageStorage] and restore it if this controller's scrollable is recreated. + /// + /// If this property is set to false, the scroll offset is never saved + /// and [initialScrollOffset] is always used to initialize the scroll + /// offset. If true (the default), the initial scroll offset is used the + /// first time the controller's scrollable is created, since there's no + /// scroll offset to restore yet. Subsequently the saved offset is + /// restored and [initialScrollOffset] is ignored. + /// + /// See also: + /// + /// * [PageStorageKey], which should be used when more than one + /// scrollable appears in the same route, to distinguish the [PageStorage] + /// locations used to save scroll offsets. + final bool keepScrollOffset; + + /// Called when a [ScrollPosition] is attached to the scroll controller. + /// + /// Since a scroll position is not attached until a [Scrollable] is actually + /// built, this can be used to respond to a new position being attached. + /// + /// At the time that a scroll position is attached, the [ScrollMetrics], such as + /// the [ScrollMetrics.maxScrollExtent], are not yet available. These are not + /// determined until the [Scrollable] has finished laying out its contents and + /// computing things like the full extent of that content. + /// [ScrollPosition.hasContentDimensions] can be used to know when the + /// metrics are available, or a [ScrollMetricsNotification] can be used, + /// discussed further below. + /// + /// {@tool dartpad} + /// This sample shows how to apply a listener to the + /// [ScrollPosition.isScrollingNotifier] using [ScrollController.onAttach]. + /// This is used to change the [AppBar]'s color when scrolling is occurring. + /// + /// ** See code in examples/api/lib/widgets/scroll_position/scroll_controller_on_attach.0.dart ** + /// {@end-tool} + final ScrollControllerCallback? onAttach; + + /// Called when a [ScrollPosition] is detached from the scroll controller. + /// + /// {@tool dartpad} + /// This sample shows how to apply a listener to the + /// [ScrollPosition.isScrollingNotifier] using [ScrollController.onAttach] + /// & [ScrollController.onDetach]. + /// This is used to change the [AppBar]'s color when scrolling is occurring. + /// + /// ** See code in examples/api/lib/widgets/scroll_position/scroll_controller_on_attach.0.dart ** + /// {@end-tool} + final ScrollControllerCallback? onDetach; + + /// A label that is used in the [toString] output. Intended to aid with + /// identifying scroll controller instances in debug output. + final String? debugLabel; + + /// The currently attached positions. + /// + /// This should not be mutated directly. [ScrollPosition] objects can be added + /// and removed using [attach] and [detach]. + Iterable<ScrollPosition> get positions => _positions; + final List<ScrollPosition> _positions = <ScrollPosition>[]; + + /// Whether any [ScrollPosition] objects have attached themselves to the + /// [ScrollController] using the [attach] method. + /// + /// If this is false, then members that interact with the [ScrollPosition], + /// such as [position], [offset], [animateTo], and [jumpTo], must not be + /// called. + bool get hasClients => _positions.isNotEmpty; + + /// Returns the attached [ScrollPosition], from which the actual scroll offset + /// of the [ScrollView] can be obtained. + /// + /// Calling this is only valid when only a single position is attached. + ScrollPosition get position { + assert(_positions.isNotEmpty, 'ScrollController not attached to any scroll views.'); + assert(_positions.length == 1, 'ScrollController attached to multiple scroll views.'); + return _positions.single; + } + + /// The current scroll offset of the scrollable widget. + /// + /// Requires the controller to be controlling exactly one scrollable widget. + double get offset => position.pixels; + + /// Animates the position from its current value to the given value. + /// + /// Any active animation is canceled. If the user is currently scrolling, that + /// action is canceled. + /// + /// The returned [Future] will complete when the animation ends, whether it + /// completed successfully or whether it was interrupted prematurely. + /// + /// An animation will be interrupted whenever the user attempts to scroll + /// manually, or whenever another activity is started, or whenever the + /// animation reaches the edge of the viewport and attempts to overscroll. (If + /// the [ScrollPosition] does not overscroll but instead allows scrolling + /// beyond the extents, then going beyond the extents will not interrupt the + /// animation.) + /// + /// The animation is indifferent to changes to the viewport or content + /// dimensions. + /// + /// Once the animation has completed, the scroll position will attempt to + /// begin a ballistic activity in case its value is not stable (for example, + /// if it is scrolled beyond the extents and in that situation the scroll + /// position would normally bounce back). + /// + /// The duration must not be zero. To jump to a particular value without an + /// animation, use [jumpTo]. + /// + /// When calling [animateTo] in widget tests, `await`ing the returned + /// [Future] may cause the test to hang and timeout. Instead, use + /// [WidgetTester.pumpAndSettle]. + Future<void> animateTo( + double offset, { + required Duration duration, + required Curve curve, + }) async { + assert(_positions.isNotEmpty, 'ScrollController not attached to any scroll views.'); + await Future.wait<void>(<Future<void>>[ + for (int i = 0; i < _positions.length; i += 1) _positions[i].animateTo(offset, duration: duration, curve: curve), + ]); + } + + /// Jumps the scroll position from its current value to the given value, + /// without animation, and without checking if the new value is in range. + /// + /// Any active animation is canceled. If the user is currently scrolling, that + /// action is canceled. + /// + /// If this method changes the scroll position, a sequence of start/update/end + /// scroll notifications will be dispatched. No overscroll notifications can + /// be generated by this method. + /// + /// Immediately after the jump, a ballistic activity is started, in case the + /// value was out of range. + void jumpTo(double value) { + assert(_positions.isNotEmpty, 'ScrollController not attached to any scroll views.'); + for (final ScrollPosition position in List<ScrollPosition>.of(_positions)) { + position.jumpTo(value); + } + } + + /// Register the given position with this controller. + /// + /// After this function returns, the [animateTo] and [jumpTo] methods on this + /// controller will manipulate the given position. + void attach(ScrollPosition position) { + assert(!_positions.contains(position)); + _positions.add(position); + position.addListener(notifyListeners); + if (onAttach != null) { + onAttach!(position); + } + } + + /// Unregister the given position with this controller. + /// + /// After this function returns, the [animateTo] and [jumpTo] methods on this + /// controller will not manipulate the given position. + void detach(ScrollPosition position) { + assert(_positions.contains(position)); + if (onDetach != null) { + onDetach!(position); + } + position.removeListener(notifyListeners); + _positions.remove(position); + } + + @override + void dispose() { + for (final ScrollPosition position in _positions) { + position.removeListener(notifyListeners); + } + super.dispose(); + } + + /// Creates a [ScrollPosition] for use by a [Scrollable] widget. + /// + /// Subclasses can override this function to customize the [ScrollPosition] + /// used by the scrollable widgets they control. For example, [PageController] + /// overrides this function to return a page-oriented scroll position + /// subclass that keeps the same page visible when the scrollable widget + /// resizes. + /// + /// By default, returns a [ScrollPositionWithSingleContext]. + /// + /// The arguments are generally passed to the [ScrollPosition] being created: + /// + /// * `physics`: An instance of [ScrollPhysics] that determines how the + /// [ScrollPosition] should react to user interactions, how it should + /// simulate scrolling when released or flung, etc. The value will not be + /// null. It typically comes from the [ScrollView] or other widget that + /// creates the [Scrollable], or, if none was provided, from the ambient + /// [ScrollConfiguration]. + /// * `context`: A [ScrollContext] used for communicating with the object + /// that is to own the [ScrollPosition] (typically, this is the + /// [Scrollable] itself). + /// * `oldPosition`: If this is not the first time a [ScrollPosition] has + /// been created for this [Scrollable], this will be the previous instance. + /// This is used when the environment has changed and the [Scrollable] + /// needs to recreate the [ScrollPosition] object. It is null the first + /// time the [ScrollPosition] is created. + ScrollPosition createScrollPosition( + ScrollPhysics physics, + ScrollContext context, + ScrollPosition? oldPosition, + ) { + return ScrollPositionWithSingleContext( + physics: physics, + context: context, + initialPixels: initialScrollOffset, + keepScrollOffset: keepScrollOffset, + oldPosition: oldPosition, + debugLabel: debugLabel, + ); + } + + @override + String toString() { + final List<String> description = <String>[]; + debugFillDescription(description); + return '${describeIdentity(this)}(${description.join(", ")})'; + } + + /// Add additional information to the given description for use by [toString]. + /// + /// This method makes it easier for subclasses to coordinate to provide a + /// high-quality [toString] implementation. The [toString] implementation on + /// the [ScrollController] base class calls [debugFillDescription] to collect + /// useful information from subclasses to incorporate into its return value. + /// + /// Implementations of this method should start with a call to the inherited + /// method, as in `super.debugFillDescription(description)`. + @mustCallSuper + void debugFillDescription(List<String> description) { + if (debugLabel != null) { + description.add(debugLabel!); + } + if (initialScrollOffset != 0.0) { + description.add('initialScrollOffset: ${initialScrollOffset.toStringAsFixed(1)}, '); + } + if (_positions.isEmpty) { + description.add('no clients'); + } else if (_positions.length == 1) { + // Don't actually list the client itself, since its toString may refer to us. + description.add('one client, offset ${offset.toStringAsFixed(1)}'); + } else { + description.add('${_positions.length} clients'); + } + } +} + +// Examples can assume: +// TrackingScrollController? _trackingScrollController; + +/// A [ScrollController] whose [initialScrollOffset] tracks its most recently +/// updated [ScrollPosition]. +/// +/// This class can be used to synchronize the scroll offset of two or more +/// lazily created scroll views that share a single [TrackingScrollController]. +/// It tracks the most recently updated scroll position and reports it as its +/// `initialScrollOffset`. +/// +/// {@tool snippet} +/// +/// In this example each [PageView] page contains a [ListView] and all three +/// [ListView]'s share a [TrackingScrollController]. The scroll offsets of all +/// three list views will track each other, to the extent that's possible given +/// the different list lengths. +/// +/// ```dart +/// PageView( +/// children: <Widget>[ +/// ListView( +/// controller: _trackingScrollController, +/// children: List<Widget>.generate(100, (int i) => Text('page 0 item $i')).toList(), +/// ), +/// ListView( +/// controller: _trackingScrollController, +/// children: List<Widget>.generate(200, (int i) => Text('page 1 item $i')).toList(), +/// ), +/// ListView( +/// controller: _trackingScrollController, +/// children: List<Widget>.generate(300, (int i) => Text('page 2 item $i')).toList(), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// In this example the `_trackingController` would have been created by the +/// stateful widget that built the widget tree. +class TrackingScrollController extends ScrollController { + /// Creates a scroll controller that continually updates its + /// [initialScrollOffset] to match the last scroll notification it received. + TrackingScrollController({ + super.initialScrollOffset, + super.keepScrollOffset, + super.debugLabel, + super.onAttach, + super.onDetach, + }); + + final Map<ScrollPosition, VoidCallback> _positionToListener = <ScrollPosition, VoidCallback>{}; + ScrollPosition? _lastUpdated; + double? _lastUpdatedOffset; + + /// The last [ScrollPosition] to change. Returns null if there aren't any + /// attached scroll positions, or there hasn't been any scrolling yet, or the + /// last [ScrollPosition] to change has since been removed. + ScrollPosition? get mostRecentlyUpdatedPosition => _lastUpdated; + + /// Returns the scroll offset of the [mostRecentlyUpdatedPosition] or, if that + /// is null, the initial scroll offset provided to the constructor. + /// + /// See also: + /// + /// * [ScrollController.initialScrollOffset], which this overrides. + @override + double get initialScrollOffset => _lastUpdatedOffset ?? super.initialScrollOffset; + + @override + void attach(ScrollPosition position) { + super.attach(position); + assert(!_positionToListener.containsKey(position)); + _positionToListener[position] = () { + _lastUpdated = position; + _lastUpdatedOffset = position.pixels; + }; + position.addListener(_positionToListener[position]!); + } + + @override + void detach(ScrollPosition position) { + super.detach(position); + assert(_positionToListener.containsKey(position)); + position.removeListener(_positionToListener[position]!); + _positionToListener.remove(position); + if (_lastUpdated == position) { + _lastUpdated = null; + } + if (_positionToListener.isEmpty) { + _lastUpdatedOffset = null; + } + } + + @override + void dispose() { + for (final ScrollPosition position in positions) { + assert(_positionToListener.containsKey(position)); + position.removeListener(_positionToListener[position]!); + } + super.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_delegate.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_delegate.dart new file mode 100644 index 0000000000000000000000000000000000000000..eb2ec00e409d7e3de12830befbdbedcbc9ef009b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_delegate.dart @@ -0,0 +1,1153 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'automatic_keep_alive.dart'; +import 'basic.dart'; +import 'framework.dart'; +import 'selection_container.dart'; +import 'two_dimensional_viewport.dart'; + +export 'package:flutter/rendering.dart' show + SliverGridDelegate, + SliverGridDelegateWithFixedCrossAxisCount, + SliverGridDelegateWithMaxCrossAxisExtent; + +// Examples can assume: +// late SliverGridDelegateWithMaxCrossAxisExtent _gridDelegate; +// abstract class SomeWidget extends StatefulWidget { const SomeWidget({super.key}); } +// typedef ChildWidget = Placeholder; + +/// A callback which produces a semantic index given a widget and the local index. +/// +/// Return a null value to prevent a widget from receiving an index. +/// +/// A semantic index is used to tag child semantic nodes for accessibility +/// announcements in scroll view. +/// +/// See also: +/// +/// * [CustomScrollView], for an explanation of scroll semantics. +/// * [SliverChildBuilderDelegate], for an explanation of how this is used to +/// generate indexes. +typedef SemanticIndexCallback = int? Function(Widget widget, int localIndex); + +int _kDefaultSemanticIndexCallback(Widget _, int localIndex) => localIndex; + +/// A delegate that supplies children for slivers. +/// +/// Many slivers lazily construct their box children to avoid creating more +/// children than are visible through the [Viewport]. Rather than receiving +/// their children as an explicit [List], they receive their children using a +/// [SliverChildDelegate]. +/// +/// It's uncommon to subclass [SliverChildDelegate]. Instead, consider using one +/// of the existing subclasses that provide adaptors to builder callbacks or +/// explicit child lists. +/// +/// {@template flutter.widgets.SliverChildDelegate.lifecycle} +/// ## Child elements' lifecycle +/// +/// ### Creation +/// +/// While laying out the list, visible children's elements, states and render +/// objects will be created lazily based on existing widgets (such as in the +/// case of [SliverChildListDelegate]) or lazily provided ones (such as in the +/// case of [SliverChildBuilderDelegate]). +/// +/// ### Destruction +/// +/// When a child is scrolled out of view, the associated element subtree, states +/// and render objects are destroyed. A new child at the same position in the +/// sliver will be lazily recreated along with new elements, states and render +/// objects when it is scrolled back. +/// +/// ### Destruction mitigation +/// +/// In order to preserve state as child elements are scrolled in and out of +/// view, the following options are possible: +/// +/// * Moving the ownership of non-trivial UI-state-driving business logic +/// out of the sliver child subtree. For instance, if a list contains posts +/// with their number of upvotes coming from a cached network response, store +/// the list of posts and upvote number in a data model outside the list. Let +/// the sliver child UI subtree be easily recreate-able from the +/// source-of-truth model object. Use [StatefulWidget]s in the child widget +/// subtree to store instantaneous UI state only. +/// +/// * Letting [KeepAlive] be the root widget of the sliver child widget subtree +/// that needs to be preserved. The [KeepAlive] widget marks the child +/// subtree's top render object child for keepalive. When the associated top +/// render object is scrolled out of view, the sliver keeps the child's +/// render object (and by extension, its associated elements and states) in a +/// cache list instead of destroying them. When scrolled back into view, the +/// render object is repainted as-is (if it wasn't marked dirty in the +/// interim). +/// +/// This only works if the [SliverChildDelegate] subclasses don't wrap the +/// child widget subtree with other widgets such as [AutomaticKeepAlive] and +/// [RepaintBoundary] via `addAutomaticKeepAlives` and +/// `addRepaintBoundaries`. +/// +/// * Using [AutomaticKeepAlive] widgets (inserted by default in +/// [SliverChildListDelegate] or [SliverChildListDelegate]). +/// [AutomaticKeepAlive] allows descendant widgets to control whether the +/// subtree is actually kept alive or not. This behavior is in contrast with +/// [KeepAlive], which will unconditionally keep the subtree alive. +/// +/// As an example, the [EditableText] widget signals its sliver child element +/// subtree to stay alive while its text field has input focus. If it doesn't +/// have focus and no other descendants signaled for keepalive via a +/// [KeepAliveNotification], the sliver child element subtree will be +/// destroyed when scrolled away. +/// +/// [AutomaticKeepAlive] descendants typically signal it to be kept alive by +/// using the [AutomaticKeepAliveClientMixin], then implementing the +/// [AutomaticKeepAliveClientMixin.wantKeepAlive] getter and calling +/// [AutomaticKeepAliveClientMixin.updateKeepAlive]. +/// +/// ## Using more than one delegate in a [Viewport] +/// +/// If multiple delegates are used in a single scroll view, the first child of +/// each delegate will always be laid out, even if it extends beyond the +/// currently viewable area. This is because at least one child is required in +/// order to [estimateMaxScrollOffset] for the whole scroll view, as it uses the +/// currently built children to estimate the remaining children's extent. +/// {@endtemplate} +/// +/// See also: +/// +/// * [SliverChildBuilderDelegate], which is a delegate that uses a builder +/// callback to construct the children. +/// * [SliverChildListDelegate], which is a delegate that has an explicit list +/// of children. +abstract class SliverChildDelegate { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const SliverChildDelegate(); + + /// Returns the child with the given index. + /// + /// Should return null if asked to build a widget with a greater + /// index than exists. If this returns null, [estimatedChildCount] + /// must subsequently return a precise non-null value (which is then + /// used to implement [RenderSliverBoxChildManager.childCount]). + /// + /// Subclasses typically override this function and wrap their children in + /// [AutomaticKeepAlive], [IndexedSemantics], and [RepaintBoundary] widgets. + /// + /// The values returned by this method are cached. To indicate that the + /// widgets have changed, a new delegate must be provided, and the new + /// delegate's [shouldRebuild] method must return true. + Widget? build(BuildContext context, int index); + + /// Returns an estimate of the number of children this delegate will build. + /// + /// Used to estimate the maximum scroll offset if [estimateMaxScrollOffset] + /// returns null. + /// + /// Return null if there are an unbounded number of children or if it would + /// be too difficult to estimate the number of children. + /// + /// This must return a precise number once [build] has returned null, as it + /// used to implement [RenderSliverBoxChildManager.childCount]. + int? get estimatedChildCount => null; + + /// Returns an estimate of the max scroll extent for all the children. + /// + /// Subclasses should override this function if they have additional + /// information about their max scroll extent. + /// + /// The default implementation returns null, which causes the caller to + /// extrapolate the max scroll offset from the given parameters. + double? estimateMaxScrollOffset( + int firstIndex, + int lastIndex, + double leadingScrollOffset, + double trailingScrollOffset, + ) => null; + + /// Called at the end of layout to indicate that layout is now complete. + /// + /// The `firstIndex` argument is the index of the first child that was + /// included in the current layout. The `lastIndex` argument is the index of + /// the last child that was included in the current layout. + /// + /// Useful for subclasses that which to track which children are included in + /// the underlying render tree. + void didFinishLayout(int firstIndex, int lastIndex) { } + + /// Called whenever a new instance of the child delegate class is + /// provided to the sliver. + /// + /// If the new instance represents different information than the old + /// instance, then the method should return true, otherwise it should return + /// false. + /// + /// If the method returns false, then the [build] call might be optimized + /// away. + bool shouldRebuild(covariant SliverChildDelegate oldDelegate); + + /// Find index of child element with associated key. + /// + /// This will be called during `performRebuild` in [SliverMultiBoxAdaptorElement] + /// to check if a child has moved to a different position. It should return the + /// index of the child element with associated key, null if not found. + /// + /// If not provided, a child widget may not map to its existing [RenderObject] + /// when the order of children returned from the children builder changes. + /// This may result in state-loss. + int? findIndexByKey(Key key) => null; + + @override + String toString() { + final List<String> description = <String>[]; + debugFillDescription(description); + return '${describeIdentity(this)}(${description.join(", ")})'; + } + + /// Add additional information to the given description for use by [toString]. + @protected + @mustCallSuper + void debugFillDescription(List<String> description) { + try { + final int? children = estimatedChildCount; + if (children != null) { + description.add('estimated child count: $children'); + } + } catch (e) { + // The exception is forwarded to widget inspector. + description.add('estimated child count: EXCEPTION (${e.runtimeType})'); + } + } +} + +class _SaltedValueKey extends ValueKey<Key> { + const _SaltedValueKey(super.value); +} + +/// Called to find the new index of a child based on its `key` in case of +/// reordering. +/// +/// If the child with the `key` is no longer present, null is returned. +/// +/// Used by [SliverChildBuilderDelegate.findChildIndexCallback]. +typedef ChildIndexGetter = int? Function(Key key); + +/// A delegate that supplies children for slivers using a builder callback. +/// +/// Many slivers lazily construct their box children to avoid creating more +/// children than are visible through the [Viewport]. This delegate provides +/// children using a [NullableIndexedWidgetBuilder] callback, so that the children do +/// not even have to be built until they are displayed. +/// +/// The widgets returned from the builder callback are automatically wrapped in +/// [AutomaticKeepAlive] widgets if [addAutomaticKeepAlives] is true (the +/// default) and in [RepaintBoundary] widgets if [addRepaintBoundaries] is true +/// (also the default). +/// +/// ## Accessibility +/// +/// The [CustomScrollView] requires that its semantic children are annotated +/// using [IndexedSemantics]. This is done by default in the delegate with +/// the `addSemanticIndexes` parameter set to true. +/// +/// If multiple delegates are used in a single scroll view, then the indexes +/// will not be correct by default. The `semanticIndexOffset` can be used to +/// offset the semantic indexes of each delegate so that the indexes are +/// monotonically increasing. For example, if a scroll view contains two +/// delegates where the first has 10 children contributing semantics, then the +/// second delegate should offset its children by 10. +/// +/// {@tool snippet} +/// +/// This sample code shows how to use `semanticIndexOffset` to handle multiple +/// delegates in a single scroll view. +/// +/// ```dart +/// CustomScrollView( +/// semanticChildCount: 4, +/// slivers: <Widget>[ +/// SliverGrid( +/// gridDelegate: _gridDelegate, +/// delegate: SliverChildBuilderDelegate( +/// (BuildContext context, int index) { +/// return const Text('...'); +/// }, +/// childCount: 2, +/// ), +/// ), +/// SliverGrid( +/// gridDelegate: _gridDelegate, +/// delegate: SliverChildBuilderDelegate( +/// (BuildContext context, int index) { +/// return const Text('...'); +/// }, +/// childCount: 2, +/// semanticIndexOffset: 2, +/// ), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// In certain cases, only a subset of child widgets should be annotated +/// with a semantic index. For example, in [ListView.separated()] the +/// separators do not have an index associated with them. This is done by +/// providing a `semanticIndexCallback` which returns null for separators +/// indexes and rounds the non-separator indexes down by half. +/// +/// {@tool snippet} +/// +/// This sample code shows how to use `semanticIndexCallback` to handle +/// annotating a subset of child nodes with a semantic index. There is +/// a [Spacer] widget at odd indexes which should not have a semantic +/// index. +/// +/// ```dart +/// CustomScrollView( +/// semanticChildCount: 5, +/// slivers: <Widget>[ +/// SliverGrid( +/// gridDelegate: _gridDelegate, +/// delegate: SliverChildBuilderDelegate( +/// (BuildContext context, int index) { +/// if (index.isEven) { +/// return const Text('...'); +/// } +/// return const Spacer(); +/// }, +/// semanticIndexCallback: (Widget widget, int localIndex) { +/// if (localIndex.isEven) { +/// return localIndex ~/ 2; +/// } +/// return null; +/// }, +/// childCount: 10, +/// ), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverChildListDelegate], which is a delegate that has an explicit list +/// of children. +/// * [IndexedSemantics], for an example of manually annotating child nodes +/// with semantic indexes. +class SliverChildBuilderDelegate extends SliverChildDelegate { + /// Creates a delegate that supplies children for slivers using the given + /// builder callback. + /// + /// The [builder], [addAutomaticKeepAlives], [addRepaintBoundaries], + /// [addSemanticIndexes], and [semanticIndexCallback] arguments must not be + /// null. + /// + /// If the order in which [builder] returns children ever changes, consider + /// providing a [findChildIndexCallback]. This allows the delegate to find the + /// new index for a child that was previously located at a different index to + /// attach the existing state to the [Widget] at its new location. + const SliverChildBuilderDelegate( + this.builder, { + this.findChildIndexCallback, + this.childCount, + this.addAutomaticKeepAlives = true, + this.addRepaintBoundaries = true, + this.addSemanticIndexes = true, + this.semanticIndexCallback = _kDefaultSemanticIndexCallback, + this.semanticIndexOffset = 0, + }); + + /// Called to build children for the sliver. + /// + /// Will be called only for indices greater than or equal to zero and less + /// than [childCount] (if [childCount] is non-null). + /// + /// Should return null if asked to build a widget with a greater index than + /// exists. + /// + /// May result in an infinite loop or run out of memory if [childCount] is null + /// and the [builder] always provides a zero-size widget (such as `Container()` + /// or `SizedBox.shrink()`). If possible, provide children with non-zero size, + /// return null from [builder], or set a [childCount]. + /// + /// The delegate wraps the children returned by this builder in + /// [RepaintBoundary] widgets. + final NullableIndexedWidgetBuilder builder; + + /// The total number of children this delegate can provide. + /// + /// If null, the number of children is determined by the least index for which + /// [builder] returns null. + /// + /// May result in an infinite loop or run out of memory if [childCount] is null + /// and the [builder] always provides a zero-size widget (such as `Container()` + /// or `SizedBox.shrink()`). If possible, provide children with non-zero size, + /// return null from [builder], or set a [childCount]. + final int? childCount; + + /// {@template flutter.widgets.SliverChildBuilderDelegate.addAutomaticKeepAlives} + /// Whether to wrap each child in an [AutomaticKeepAlive]. + /// + /// Typically, lazily laid out children are wrapped in [AutomaticKeepAlive] + /// widgets so that the children can use [KeepAliveNotification]s to preserve + /// their state when they would otherwise be garbage collected off-screen. + /// + /// This feature (and [addRepaintBoundaries]) must be disabled if the children + /// are going to manually maintain their [KeepAlive] state. It may also be + /// more efficient to disable this feature if it is known ahead of time that + /// none of the children will ever try to keep themselves alive. + /// + /// Defaults to true. + /// {@endtemplate} + final bool addAutomaticKeepAlives; + + /// {@template flutter.widgets.SliverChildBuilderDelegate.addRepaintBoundaries} + /// Whether to wrap each child in a [RepaintBoundary]. + /// + /// Typically, children in a scrolling container are wrapped in repaint + /// boundaries so that they do not need to be repainted as the list scrolls. + /// If the children are easy to repaint (e.g., solid color blocks or a short + /// snippet of text), it might be more efficient to not add a repaint boundary + /// and instead always repaint the children during scrolling. + /// + /// Defaults to true. + /// {@endtemplate} + final bool addRepaintBoundaries; + + /// {@template flutter.widgets.SliverChildBuilderDelegate.addSemanticIndexes} + /// Whether to wrap each child in an [IndexedSemantics]. + /// + /// Typically, children in a scrolling container must be annotated with a + /// semantic index in order to generate the correct accessibility + /// announcements. This should only be set to false if the indexes have + /// already been provided by an [IndexedSemantics] widget. + /// + /// Defaults to true. + /// + /// See also: + /// + /// * [IndexedSemantics], for an explanation of how to manually + /// provide semantic indexes. + /// {@endtemplate} + final bool addSemanticIndexes; + + /// {@template flutter.widgets.SliverChildBuilderDelegate.semanticIndexOffset} + /// An initial offset to add to the semantic indexes generated by this widget. + /// + /// Defaults to zero. + /// {@endtemplate} + final int semanticIndexOffset; + + /// {@template flutter.widgets.SliverChildBuilderDelegate.semanticIndexCallback} + /// A [SemanticIndexCallback] which is used when [addSemanticIndexes] is true. + /// + /// Defaults to providing an index for each widget. + /// {@endtemplate} + final SemanticIndexCallback semanticIndexCallback; + + /// {@template flutter.widgets.SliverChildBuilderDelegate.findChildIndexCallback} + /// Called to find the new index of a child based on its key in case of reordering. + /// + /// If not provided, a child widget may not map to its existing [RenderObject] + /// when the order of children returned from the children builder changes. + /// This may result in state-loss. + /// + /// This callback should take an input [Key], and it should return the + /// index of the child element with that associated key, or null if not found. + /// {@endtemplate} + final ChildIndexGetter? findChildIndexCallback; + + @override + int? findIndexByKey(Key key) { + if (findChildIndexCallback == null) { + return null; + } + final Key childKey; + if (key is _SaltedValueKey) { + final _SaltedValueKey saltedValueKey = key; + childKey = saltedValueKey.value; + } else { + childKey = key; + } + return findChildIndexCallback!(childKey); + } + + @override + @pragma('vm:notify-debugger-on-exception') + Widget? build(BuildContext context, int index) { + if (index < 0 || (childCount != null && index >= childCount!)) { + return null; + } + Widget? child; + try { + child = builder(context, index); + } catch (exception, stackTrace) { + child = _createErrorWidget(exception, stackTrace); + } + if (child == null) { + return null; + } + final Key? key = child.key != null ? _SaltedValueKey(child.key!) : null; + if (addRepaintBoundaries) { + child = RepaintBoundary(child: child); + } + if (addSemanticIndexes) { + final int? semanticIndex = semanticIndexCallback(child, index); + if (semanticIndex != null) { + child = IndexedSemantics(index: semanticIndex + semanticIndexOffset, child: child); + } + } + if (addAutomaticKeepAlives) { + child = AutomaticKeepAlive(child: _SelectionKeepAlive(child: child)); + } + return KeyedSubtree(key: key, child: child); + } + + @override + int? get estimatedChildCount => childCount; + + @override + bool shouldRebuild(covariant SliverChildBuilderDelegate oldDelegate) => true; +} + +/// A delegate that supplies children for slivers using an explicit list. +/// +/// Many slivers lazily construct their box children to avoid creating more +/// children than are visible through the [Viewport]. This delegate provides +/// children using an explicit list, which is convenient but reduces the benefit +/// of building children lazily. +/// +/// In general building all the widgets in advance is not efficient. It is +/// better to create a delegate that builds them on demand using +/// [SliverChildBuilderDelegate] or by subclassing [SliverChildDelegate] +/// directly. +/// +/// This class is provided for the cases where either the list of children is +/// known well in advance (ideally the children are themselves compile-time +/// constants, for example), and therefore will not be built each time the +/// delegate itself is created, or the list is small, such that it's likely +/// always visible (and thus there is nothing to be gained by building it on +/// demand). For example, the body of a dialog box might fit both of these +/// conditions. +/// +/// The widgets in the given [children] list are automatically wrapped in +/// [AutomaticKeepAlive] widgets if [addAutomaticKeepAlives] is true (the +/// default) and in [RepaintBoundary] widgets if [addRepaintBoundaries] is true +/// (also the default). +/// +/// ## Accessibility +/// +/// The [CustomScrollView] requires that its semantic children are annotated +/// using [IndexedSemantics]. This is done by default in the delegate with +/// the `addSemanticIndexes` parameter set to true. +/// +/// If multiple delegates are used in a single scroll view, then the indexes +/// will not be correct by default. The `semanticIndexOffset` can be used to +/// offset the semantic indexes of each delegate so that the indexes are +/// monotonically increasing. For example, if a scroll view contains two +/// delegates where the first has 10 children contributing semantics, then the +/// second delegate should offset its children by 10. +/// +/// In certain cases, only a subset of child widgets should be annotated +/// with a semantic index. For example, in [ListView.separated()] the +/// separators do not have an index associated with them. This is done by +/// providing a `semanticIndexCallback` which returns null for separators +/// indexes and rounds the non-separator indexes down by half. +/// +/// See [SliverChildBuilderDelegate] for sample code using +/// `semanticIndexOffset` and `semanticIndexCallback`. +/// +/// See also: +/// +/// * [SliverChildBuilderDelegate], which is a delegate that uses a builder +/// callback to construct the children. +class SliverChildListDelegate extends SliverChildDelegate { + /// Creates a delegate that supplies children for slivers using the given + /// list. + /// + /// The [children], [addAutomaticKeepAlives], [addRepaintBoundaries], + /// [addSemanticIndexes], and [semanticIndexCallback] arguments must not be + /// null. + /// + /// If the order of children never changes, consider using the constant + /// [SliverChildListDelegate.fixed] constructor. + SliverChildListDelegate( + this.children, { + this.addAutomaticKeepAlives = true, + this.addRepaintBoundaries = true, + this.addSemanticIndexes = true, + this.semanticIndexCallback = _kDefaultSemanticIndexCallback, + this.semanticIndexOffset = 0, + }) : _keyToIndex = <Key?, int>{null: 0}; + + /// Creates a constant version of the delegate that supplies children for + /// slivers using the given list. + /// + /// If the order of the children will change, consider using the regular + /// [SliverChildListDelegate] constructor. + /// + /// The [children], [addAutomaticKeepAlives], [addRepaintBoundaries], + /// [addSemanticIndexes], and [semanticIndexCallback] arguments must not be + /// null. + const SliverChildListDelegate.fixed( + this.children, { + this.addAutomaticKeepAlives = true, + this.addRepaintBoundaries = true, + this.addSemanticIndexes = true, + this.semanticIndexCallback = _kDefaultSemanticIndexCallback, + this.semanticIndexOffset = 0, + }) : _keyToIndex = null; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.addAutomaticKeepAlives} + final bool addAutomaticKeepAlives; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.addRepaintBoundaries} + final bool addRepaintBoundaries; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.addSemanticIndexes} + final bool addSemanticIndexes; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.semanticIndexOffset} + final int semanticIndexOffset; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.semanticIndexCallback} + final SemanticIndexCallback semanticIndexCallback; + + /// The widgets to display. + /// + /// If this list is going to be mutated, it is usually wise to put a [Key] on + /// each of the child widgets, so that the framework can match old + /// configurations to new configurations and maintain the underlying render + /// objects. + /// + /// Also, a [Widget] in Flutter is immutable, so directly modifying the + /// [children] such as `someWidget.children.add(...)` or + /// passing a reference of the original list value to the [children] parameter + /// will result in incorrect behaviors. Whenever the + /// children list is modified, a new list object must be provided. + /// + /// The following code corrects the problem mentioned above. + /// + /// ```dart + /// class SomeWidgetState extends State<SomeWidget> { + /// final List<Widget> _children = <Widget>[]; + /// + /// void someHandler() { + /// setState(() { + /// // The key here allows Flutter to reuse the underlying render + /// // objects even if the children list is recreated. + /// _children.add(ChildWidget(key: UniqueKey())); + /// }); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// // Always create a new list of children as a Widget is immutable. + /// return PageView(children: List<Widget>.of(_children)); + /// } + /// } + /// ``` + final List<Widget> children; + + /// A map to cache key to index lookup for children. + /// + /// _keyToIndex[null] is used as current index during the lazy loading process + /// in [_findChildIndex]. _keyToIndex should never be used for looking up null key. + final Map<Key?, int>? _keyToIndex; + + bool get _isConstantInstance => _keyToIndex == null; + + int? _findChildIndex(Key key) { + if (_isConstantInstance) { + return null; + } + // Lazily fill the [_keyToIndex]. + if (!_keyToIndex!.containsKey(key)) { + int index = _keyToIndex[null]!; + while (index < children.length) { + final Widget child = children[index]; + if (child.key != null) { + _keyToIndex[child.key] = index; + } + if (child.key == key) { + // Record current index for next function call. + _keyToIndex[null] = index + 1; + return index; + } + index += 1; + } + _keyToIndex[null] = index; + } else { + return _keyToIndex[key]; + } + return null; + } + + @override + int? findIndexByKey(Key key) { + final Key childKey; + if (key is _SaltedValueKey) { + final _SaltedValueKey saltedValueKey = key; + childKey = saltedValueKey.value; + } else { + childKey = key; + } + return _findChildIndex(childKey); + } + + @override + Widget? build(BuildContext context, int index) { + if (index < 0 || index >= children.length) { + return null; + } + Widget child = children[index]; + final Key? key = child.key != null? _SaltedValueKey(child.key!) : null; + if (addRepaintBoundaries) { + child = RepaintBoundary(child: child); + } + if (addSemanticIndexes) { + final int? semanticIndex = semanticIndexCallback(child, index); + if (semanticIndex != null) { + child = IndexedSemantics(index: semanticIndex + semanticIndexOffset, child: child); + } + } + if (addAutomaticKeepAlives) { + child = AutomaticKeepAlive(child: _SelectionKeepAlive(child: child)); + } + + return KeyedSubtree(key: key, child: child); + } + + @override + int? get estimatedChildCount => children.length; + + @override + bool shouldRebuild(covariant SliverChildListDelegate oldDelegate) { + return children != oldDelegate.children; + } +} + +class _SelectionKeepAlive extends StatefulWidget { + /// Creates a widget that listens to [KeepAliveNotification]s and maintains a + /// [KeepAlive] widget appropriately. + const _SelectionKeepAlive({ + required this.child, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + State<_SelectionKeepAlive> createState() => _SelectionKeepAliveState(); +} + +class _SelectionKeepAliveState extends State<_SelectionKeepAlive> with AutomaticKeepAliveClientMixin implements SelectionRegistrar { + Set<Selectable>? _selectablesWithSelections; + Map<Selectable, VoidCallback>? _selectableAttachments; + SelectionRegistrar? _registrar; + + @override + bool get wantKeepAlive => _wantKeepAlive; + bool _wantKeepAlive = false; + set wantKeepAlive(bool value) { + if (_wantKeepAlive != value) { + _wantKeepAlive = value; + updateKeepAlive(); + } + } + + VoidCallback listensTo(Selectable selectable) { + return () { + if (selectable.value.hasSelection) { + _updateSelectablesWithSelections(selectable, add: true); + } else { + _updateSelectablesWithSelections(selectable, add: false); + } + }; + } + + void _updateSelectablesWithSelections(Selectable selectable, {required bool add}) { + if (add) { + assert(selectable.value.hasSelection); + _selectablesWithSelections ??= <Selectable>{}; + _selectablesWithSelections!.add(selectable); + } else { + _selectablesWithSelections?.remove(selectable); + } + wantKeepAlive = _selectablesWithSelections?.isNotEmpty ?? false; + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final SelectionRegistrar? newRegistrar = SelectionContainer.maybeOf(context); + if (_registrar != newRegistrar) { + if (_registrar != null) { + _selectableAttachments?.keys.forEach(_registrar!.remove); + } + _registrar = newRegistrar; + if (_registrar != null) { + _selectableAttachments?.keys.forEach(_registrar!.add); + } + } + } + + @override + void add(Selectable selectable) { + final VoidCallback attachment = listensTo(selectable); + selectable.addListener(attachment); + _selectableAttachments ??= <Selectable, VoidCallback>{}; + _selectableAttachments![selectable] = attachment; + _registrar!.add(selectable); + if (selectable.value.hasSelection) { + _updateSelectablesWithSelections(selectable, add: true); + } + } + + @override + void remove(Selectable selectable) { + if (_selectableAttachments == null) { + return; + } + assert(_selectableAttachments!.containsKey(selectable)); + final VoidCallback attachment = _selectableAttachments!.remove(selectable)!; + selectable.removeListener(attachment); + _registrar!.remove(selectable); + _updateSelectablesWithSelections(selectable, add: false); + } + + @override + void dispose() { + if (_selectableAttachments != null) { + for (final Selectable selectable in _selectableAttachments!.keys) { + _registrar!.remove(selectable); + selectable.removeListener(_selectableAttachments![selectable]!); + } + _selectableAttachments = null; + } + _selectablesWithSelections = null; + super.dispose(); + } + + @override + Widget build(BuildContext context) { + super.build(context); + if (_registrar == null) { + return widget.child; + } + return SelectionRegistrarScope( + registrar: this, + child: widget.child, + ); + } +} + +// Return a Widget for the given Exception +Widget _createErrorWidget(Object exception, StackTrace stackTrace) { + final FlutterErrorDetails details = FlutterErrorDetails( + exception: exception, + stack: stackTrace, + library: 'widgets library', + context: ErrorDescription('building'), + ); + FlutterError.reportError(details); + return ErrorWidget.builder(details); +} + +/// A delegate that supplies children for scrolling in two dimensions. +/// +/// A [TwoDimensionalScrollView] lazily constructs its box children to avoid +/// creating more children than are visible through the +/// [TwoDimensionalViewport]. Rather than receiving children as an +/// explicit [List], it receives its children using a +/// [TwoDimensionalChildDelegate]. +/// +/// As a ChangeNotifier, this delegate allows subclasses to notify its listeners +/// (typically as a subclass of [RenderTwoDimensionalViewport]) to rebuild when +/// aspects of the delegate change. When values returned by getters or builders +/// on this delegate change, [notifyListeners] should be called. This signals to +/// the [RenderTwoDimensionalViewport] that the getters and builders need to be +/// re-queried to update the layout of children in the viewport. +/// +/// See also: +/// +/// * [TwoDimensionalChildBuilderDelegate], an concrete subclass of this that +/// lazily builds children on demand. +/// * [TwoDimensionalChildListDelegate], an concrete subclass of this that +/// uses a two dimensional array to layout children. +abstract class TwoDimensionalChildDelegate extends ChangeNotifier { + /// Returns the child with the given [ChildVicinity], which is described in + /// terms of x and y indices. + /// + /// Subclasses must implement this function and will typically wrap their + /// children in [RepaintBoundary] widgets. + /// + /// The values returned by this method are cached. To indicate that the + /// widgets have changed, a new delegate must be provided, and the new + /// delegate's [shouldRebuild] method must return true. Alternatively, + /// calling [notifyListeners] will allow the same delegate to be used. + Widget? build(BuildContext context, ChildVicinity vicinity); + + /// Called whenever a new instance of the child delegate class is + /// provided. + /// + /// If the new instance represents different information than the old + /// instance, then the method should return true, otherwise it should return + /// false. + /// + /// If the method returns false, then the [build] call might be optimized + /// away. + bool shouldRebuild(covariant TwoDimensionalChildDelegate oldDelegate); +} + +/// A delegate that supplies children for a [TwoDimensionalScrollView] using a +/// builder callback. +/// +/// The widgets returned from the builder callback are automatically wrapped in +/// [RepaintBoundary] widgets if [addRepaintBoundaries] is true +/// (also the default). +/// +/// See also: +/// +/// * [TwoDimensionalChildListDelegate], which is a similar delegate that has an +/// explicit two dimensional array of children. +/// * [SliverChildBuilderDelegate], which is a delegate that uses a builder +/// callback to construct the children in one dimension instead of two. +/// * [SliverChildListDelegate], which is a delegate that has an explicit list +/// of children in one dimension instead of two. +class TwoDimensionalChildBuilderDelegate extends TwoDimensionalChildDelegate { + /// Creates a delegate that supplies children for a [TwoDimensionalScrollView] + /// using the given builder callback. + TwoDimensionalChildBuilderDelegate({ + required this.builder, + int? maxXIndex, + int? maxYIndex, + this.addRepaintBoundaries = true, + this.addAutomaticKeepAlives = true, + }) : assert(maxYIndex == null || maxYIndex >= -1), + assert(maxXIndex == null || maxXIndex >= -1), + _maxYIndex = maxYIndex, + _maxXIndex = maxXIndex; + + /// Called to build children on demand. + /// + /// Implementors of [RenderTwoDimensionalViewport.layoutChildSequence] + /// call this builder to create the children of the viewport. For + /// [ChildVicinity] indices greater than [maxXIndex] or [maxYIndex], null will + /// be returned by the default [build] implementation. This default behavior + /// can be changed by overriding the build method. + /// + /// Must return null if asked to build a widget with a [ChildVicinity] that + /// does not exist. + /// + /// The delegate wraps the children returned by this builder in + /// [RepaintBoundary] widgets if [addRepaintBoundaries] is true. + final TwoDimensionalIndexedWidgetBuilder builder; + + /// The maximum [ChildVicinity.xIndex] for children in the x axis. + /// + /// {@template flutter.widgets.twoDimensionalChildBuilderDelegate.maxIndex} + /// For each [ChildVicinity], the child's relative location is described in + /// terms of x and y indices to facilitate a consistent visitor pattern for + /// all children in the viewport. + /// + /// This is fairly straightforward in the context of a table implementation, + /// where there is usually the same number of columns in every row and vice + /// versa, each aligned one after the other. + /// + /// When plotting children more abstractly in two dimensional space, there may + /// be more x indices for a given y index than another y index. An example of + /// this would be a scatter plot where there are more children at the top of + /// the graph than at the bottom. + /// + /// If null, subclasses of [RenderTwoDimensionalViewport] can continue call on + /// the [builder] until null has been returned for each known index of x and + /// y. In some cases, null may not be a terminating result, such as a table + /// with a merged cell spanning multiple indices. Refer to the + /// [TwoDimensionalViewport] subclass to learn how this value is applied in + /// the specific use case. + /// + /// If not null, the value must be greater than or equal to -1, where -1 + /// indicates there will be no children at all provided to the + /// [TwoDimensionalViewport]. + /// + /// If the value changes, the delegate will call [notifyListeners]. This + /// informs the [RenderTwoDimensionalViewport] that any cached information + /// from the delegate is invalid. + /// {@endtemplate} + /// + /// This value represents the greatest x index of all [ChildVicinity]s for the + /// two dimensional scroll view. + /// + /// See also: + /// + /// * [RenderTwoDimensionalViewport.buildOrObtainChildFor], the method that + /// leads to calling on the delegate to build a child of the given + /// [ChildVicinity]. + int? get maxXIndex => _maxXIndex; + int? _maxXIndex; + set maxXIndex(int? value) { + if (value == maxXIndex) { + return; + } + assert(value == null || value >= -1); + _maxXIndex = value; + notifyListeners(); + } + + /// The maximum [ChildVicinity.yIndex] for children in the y axis. + /// + /// {@macro flutter.widgets.twoDimensionalChildBuilderDelegate.maxIndex} + /// + /// This value represents the greatest y index of all [ChildVicinity]s for the + /// two dimensional scroll view. + /// + /// See also: + /// + /// * [RenderTwoDimensionalViewport.buildOrObtainChildFor], the method that + /// leads to calling on the delegate to build a child of the given + /// [ChildVicinity]. + int? get maxYIndex => _maxYIndex; + int? _maxYIndex; + set maxYIndex(int? value) { + if (maxYIndex == value) { + return; + } + assert(value == null || value >= -1); + _maxYIndex = value; + notifyListeners(); + } + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.addRepaintBoundaries} + final bool addRepaintBoundaries; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.addAutomaticKeepAlives} + final bool addAutomaticKeepAlives; + + @override + Widget? build(BuildContext context, ChildVicinity vicinity) { + // If we have exceeded explicit upper bounds, return null. + if (vicinity.xIndex < 0 || (maxXIndex != null && vicinity.xIndex > maxXIndex!)) { + return null; + } + if (vicinity.yIndex < 0 || (maxYIndex != null && vicinity.yIndex > maxYIndex!)) { + return null; + } + + Widget? child; + try { + child = builder(context, vicinity); + } catch (exception, stackTrace) { + child = _createErrorWidget(exception, stackTrace); + } + if (child == null) { + return null; + } + if (addRepaintBoundaries) { + child = RepaintBoundary(child: child); + } + if (addAutomaticKeepAlives) { + child = AutomaticKeepAlive(child: _SelectionKeepAlive(child: child)); + } + return child; + } + + @override + bool shouldRebuild(covariant TwoDimensionalChildDelegate oldDelegate) => true; +} + +/// A delegate that supplies children for a [TwoDimensionalViewport] using an +/// explicit two dimensional array. +/// +/// In general, building all the widgets in advance is not efficient. It is +/// better to create a delegate that builds them on demand using +/// [TwoDimensionalChildBuilderDelegate] or by subclassing +/// [TwoDimensionalChildDelegate] directly. +/// +/// This class is provided for the cases where either the list of children is +/// known well in advance (ideally the children are themselves compile-time +/// constants, for example), and therefore will not be built each time the +/// delegate itself is created, or the array is small, such that it's likely +/// always visible (and thus there is nothing to be gained by building it on +/// demand). +/// +/// The widgets in the given [children] list are automatically wrapped in +/// [RepaintBoundary] widgets if [addRepaintBoundaries] is true +/// (also the default). +/// +/// The [children] are accessed for each [ChildVicinity.yIndex] and +/// [ChildVicinity.xIndex] of the [TwoDimensionalViewport] as +/// `children[vicinity.yIndex][vicinity.xIndex]`. +/// +/// See also: +/// +/// * [TwoDimensionalChildBuilderDelegate], which is a delegate that uses a +/// builder callback to construct the children. +/// * [SliverChildBuilderDelegate], which is a delegate that uses a builder +/// callback to construct the children in one dimension instead of two. +/// * [SliverChildListDelegate], which is a delegate that has an explicit list +/// of children in one dimension instead of two. +class TwoDimensionalChildListDelegate extends TwoDimensionalChildDelegate { + /// Creates a delegate that supplies children for a [TwoDimensionalScrollView]. + /// + /// The [children] and [addRepaintBoundaries] must not be + /// null. + TwoDimensionalChildListDelegate({ + this.addRepaintBoundaries = true, + this.addAutomaticKeepAlives = true, + required this.children, + }); + + /// The widgets to display. + /// + /// Also, a [Widget] in Flutter is immutable, so directly modifying the + /// [children] such as `someWidget.children.add(...)` or + /// passing a reference of the original list value to the [children] parameter + /// will result in incorrect behaviors. Whenever the + /// children list is modified, a new list object must be provided. + /// + /// The [children] are accessed for each [ChildVicinity.yIndex] and + /// [ChildVicinity.xIndex] of the [TwoDimensionalViewport] as + /// `children[vicinity.yIndex][vicinity.xIndex]`. + final List<List<Widget>> children; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.addRepaintBoundaries} + final bool addRepaintBoundaries; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.addAutomaticKeepAlives} + final bool addAutomaticKeepAlives; + + @override + Widget? build(BuildContext context, ChildVicinity vicinity) { + // If we have exceeded explicit upper bounds, return null. + if (vicinity.yIndex < 0 || vicinity.yIndex >= children.length) { + return null; + } + if (vicinity.xIndex < 0 || vicinity.xIndex >= children[vicinity.yIndex].length) { + return null; + } + + Widget child = children[vicinity.yIndex][vicinity.xIndex]; + if (addRepaintBoundaries) { + child = RepaintBoundary(child: child); + } + if (addAutomaticKeepAlives) { + child = AutomaticKeepAlive(child: _SelectionKeepAlive(child: child)); + } + return child; + } + + @override + bool shouldRebuild(covariant TwoDimensionalChildListDelegate oldDelegate) { + return children != oldDelegate.children; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_metrics.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_metrics.dart new file mode 100644 index 0000000000000000000000000000000000000000..2448cf5d0eb9bae01e74c3ee08e224037b0d7abf --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_metrics.dart @@ -0,0 +1,210 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +/// A description of a [Scrollable]'s contents, useful for modeling the state +/// of its viewport. +/// +/// This class defines a current position, [pixels], and a range of values +/// considered "in bounds" for that position. The range has a minimum value at +/// [minScrollExtent] and a maximum value at [maxScrollExtent] (inclusive). The +/// viewport scrolls in the direction and axis described by [axisDirection] +/// and [axis]. +/// +/// The [outOfRange] getter will return true if [pixels] is outside this defined +/// range. The [atEdge] getter will return true if the [pixels] position equals +/// either the [minScrollExtent] or the [maxScrollExtent]. +/// +/// The dimensions of the viewport in the given [axis] are described by +/// [viewportDimension]. +/// +/// The above values are also exposed in terms of [extentBefore], +/// [extentInside], and [extentAfter], which may be more useful for use cases +/// such as scroll bars; for example, see [Scrollbar]. +/// +/// {@tool dartpad} +/// This sample shows how a [ScrollMetricsNotification] is dispatched when +/// the [ScrollMetrics] changed as a result of resizing the [Viewport]. +/// Press the floating action button to increase the scrollable window's size. +/// +/// ** See code in examples/api/lib/widgets/scroll_position/scroll_metrics_notification.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [FixedScrollMetrics], which is an immutable object that implements this +/// interface. +mixin ScrollMetrics { + /// Creates a [ScrollMetrics] that has the same properties as this object. + /// + /// This is useful if this object is mutable, but you want to get a snapshot + /// of the current state. + /// + /// The named arguments allow the values to be adjusted in the process. This + /// is useful to examine hypothetical situations, for example "would applying + /// this delta unmodified take the position [outOfRange]?". + ScrollMetrics copyWith({ + double? minScrollExtent, + double? maxScrollExtent, + double? pixels, + double? viewportDimension, + AxisDirection? axisDirection, + double? devicePixelRatio, + }) { + return FixedScrollMetrics( + minScrollExtent: minScrollExtent ?? (hasContentDimensions ? this.minScrollExtent : null), + maxScrollExtent: maxScrollExtent ?? (hasContentDimensions ? this.maxScrollExtent : null), + pixels: pixels ?? (hasPixels ? this.pixels : null), + viewportDimension: viewportDimension ?? (hasViewportDimension ? this.viewportDimension : null), + axisDirection: axisDirection ?? this.axisDirection, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + ); + } + + /// The minimum in-range value for [pixels]. + /// + /// The actual [pixels] value might be [outOfRange]. + /// + /// This value is typically less than or equal to + /// [maxScrollExtent]. It can be negative infinity, if the scroll is unbounded. + double get minScrollExtent; + + /// The maximum in-range value for [pixels]. + /// + /// The actual [pixels] value might be [outOfRange]. + /// + /// This value is typically greater than or equal to + /// [minScrollExtent]. It can be infinity, if the scroll is unbounded. + double get maxScrollExtent; + + /// Whether the [minScrollExtent] and the [maxScrollExtent] properties are available. + bool get hasContentDimensions; + + /// The current scroll position, in logical pixels along the [axisDirection]. + double get pixels; + + /// Whether the [pixels] property is available. + bool get hasPixels; + + /// The extent of the viewport along the [axisDirection]. + double get viewportDimension; + + /// Whether the [viewportDimension] property is available. + bool get hasViewportDimension; + + /// The direction in which the scroll view scrolls. + AxisDirection get axisDirection; + + /// The axis in which the scroll view scrolls. + Axis get axis => axisDirectionToAxis(axisDirection); + + /// Whether the [pixels] value is outside the [minScrollExtent] and + /// [maxScrollExtent]. + bool get outOfRange => pixels < minScrollExtent || pixels > maxScrollExtent; + + /// Whether the [pixels] value is exactly at the [minScrollExtent] or the + /// [maxScrollExtent]. + bool get atEdge => pixels == minScrollExtent || pixels == maxScrollExtent; + + /// The quantity of content conceptually "above" the viewport in the scrollable. + /// This is the content above the content described by [extentInside]. + double get extentBefore => math.max(pixels - minScrollExtent, 0.0); + + /// The quantity of content conceptually "inside" the viewport in the + /// scrollable (including empty space if the total amount of content is less + /// than the [viewportDimension]). + /// + /// The value is typically the extent of the viewport ([viewportDimension]) + /// when [outOfRange] is false. It can be less when overscrolling. + /// + /// The value is always non-negative, and less than or equal to [viewportDimension]. + double get extentInside { + assert(minScrollExtent <= maxScrollExtent); + return viewportDimension + // "above" overscroll value + - clampDouble(minScrollExtent - pixels, 0, viewportDimension) + // "below" overscroll value + - clampDouble(pixels - maxScrollExtent, 0, viewportDimension); + } + + /// The quantity of content conceptually "below" the viewport in the scrollable. + /// This is the content below the content described by [extentInside]. + double get extentAfter => math.max(maxScrollExtent - pixels, 0.0); + + /// The total quantity of content available. + /// + /// This is the sum of [extentBefore], [extentInside], and [extentAfter], modulo + /// any rounding errors. + double get extentTotal => maxScrollExtent - minScrollExtent + viewportDimension; + + /// The [FlutterView.devicePixelRatio] of the view that the [Scrollable] + /// associated with this metrics object is drawn into. + double get devicePixelRatio; +} + +/// An immutable snapshot of values associated with a [Scrollable] viewport. +/// +/// For details, see [ScrollMetrics], which defines this object's interfaces. +/// +/// {@tool dartpad} +/// This sample shows how a [ScrollMetricsNotification] is dispatched when +/// the [ScrollMetrics] changed as a result of resizing the [Viewport]. +/// Press the floating action button to increase the scrollable window's size. +/// +/// ** See code in examples/api/lib/widgets/scroll_position/scroll_metrics_notification.0.dart ** +/// {@end-tool} +class FixedScrollMetrics with ScrollMetrics { + /// Creates an immutable snapshot of values associated with a [Scrollable] viewport. + FixedScrollMetrics({ + required double? minScrollExtent, + required double? maxScrollExtent, + required double? pixels, + required double? viewportDimension, + required this.axisDirection, + required this.devicePixelRatio, + }) : _minScrollExtent = minScrollExtent, + _maxScrollExtent = maxScrollExtent, + _pixels = pixels, + _viewportDimension = viewportDimension; + + @override + double get minScrollExtent => _minScrollExtent!; + final double? _minScrollExtent; + + @override + double get maxScrollExtent => _maxScrollExtent!; + final double? _maxScrollExtent; + + @override + bool get hasContentDimensions => _minScrollExtent != null && _maxScrollExtent != null; + + @override + double get pixels => _pixels!; + final double? _pixels; + + @override + bool get hasPixels => _pixels != null; + + @override + double get viewportDimension => _viewportDimension!; + final double? _viewportDimension; + + @override + bool get hasViewportDimension => _viewportDimension != null; + + @override + final AxisDirection axisDirection; + + @override + final double devicePixelRatio; + + @override + String toString() { + return '${objectRuntimeType(this, 'FixedScrollMetrics')}(${extentBefore.toStringAsFixed(1)}..[${extentInside.toStringAsFixed(1)}]..${extentAfter.toStringAsFixed(1)})'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_notification.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_notification.dart new file mode 100644 index 0000000000000000000000000000000000000000..1108a99151d23608d3e2034f661014580e10177e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_notification.dart @@ -0,0 +1,346 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; +import 'notification_listener.dart'; +import 'scroll_metrics.dart'; + +/// Mixin for [Notification]s that track how many [RenderAbstractViewport] they +/// have bubbled through. +/// +/// This is used by [ScrollNotification] and [OverscrollIndicatorNotification]. +mixin ViewportNotificationMixin on Notification { + /// The number of viewports that this notification has bubbled through. + /// + /// Typically listeners only respond to notifications with a [depth] of zero. + /// + /// Specifically, this is the number of [Widget]s representing + /// [RenderAbstractViewport] render objects through which this notification + /// has bubbled. + int get depth => _depth; + int _depth = 0; + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + description.add('depth: $depth (${ depth == 0 ? "local" : "remote"})'); + } +} + +/// A mixin that allows [Element]s containing [Viewport] like widgets to correctly +/// modify the notification depth of a [ViewportNotificationMixin]. +/// +/// See also: +/// * [Viewport], which creates a custom [MultiChildRenderObjectElement] that mixes +/// this in. +mixin ViewportElementMixin on NotifiableElementMixin { + @override + bool onNotification(Notification notification) { + if (notification is ViewportNotificationMixin) { + notification._depth += 1; + } + return false; + } +} + +/// A [Notification] related to scrolling. +/// +/// [Scrollable] widgets notify their ancestors about scrolling-related changes. +/// The notifications have the following lifecycle: +/// +/// * A [ScrollStartNotification], which indicates that the widget has started +/// scrolling. +/// * Zero or more [ScrollUpdateNotification]s, which indicate that the widget +/// has changed its scroll position, mixed with zero or more +/// [OverscrollNotification]s, which indicate that the widget has not changed +/// its scroll position because the change would have caused its scroll +/// position to go outside its scroll bounds. +/// * Interspersed with the [ScrollUpdateNotification]s and +/// [OverscrollNotification]s are zero or more [UserScrollNotification]s, +/// which indicate that the user has changed the direction in which they are +/// scrolling. +/// * A [ScrollEndNotification], which indicates that the widget has stopped +/// scrolling. +/// * A [UserScrollNotification], with a [UserScrollNotification.direction] of +/// [ScrollDirection.idle]. +/// +/// Notifications bubble up through the tree, which means a given +/// [NotificationListener] will receive notifications for all descendant +/// [Scrollable] widgets. To focus on notifications from the nearest +/// [Scrollable] descendant, check that the [depth] property of the notification +/// is zero. +/// +/// When a scroll notification is received by a [NotificationListener], the +/// listener will have already completed build and layout, and it is therefore +/// too late for that widget to call [State.setState]. Any attempt to adjust the +/// build or layout based on a scroll notification would result in a layout that +/// lagged one frame behind, which is a poor user experience. Scroll +/// notifications are therefore primarily useful for paint effects (since paint +/// happens after layout). The [GlowingOverscrollIndicator] and [Scrollbar] +/// widgets are examples of paint effects that use scroll notifications. +/// +/// {@tool dartpad} +/// This sample shows the difference between using a [ScrollController] or a +/// [NotificationListener] of type [ScrollNotification] to listen to scrolling +/// activities. Toggling the [Radio] button switches between the two. +/// Using a [ScrollNotification] will provide details about the scrolling +/// activity, along with the metrics of the [ScrollPosition], but not the scroll +/// position object itself. By listening with a [ScrollController], the position +/// object is directly accessible. +/// Both of these types of notifications are only triggered by scrolling. +/// +/// ** See code in examples/api/lib/widgets/scroll_position/scroll_controller_notification.0.dart ** +/// {@end-tool} +/// +/// To drive layout based on the scroll position, consider listening to the +/// [ScrollPosition] directly (or indirectly via a [ScrollController]). This +/// will not notify when the [ScrollMetrics] of a given scroll position changes, +/// such as when the window is resized, changing the dimensions of the +/// [Viewport]. In order to listen to changes in scroll metrics, use a +/// [NotificationListener] of type [ScrollMetricsNotification]. +/// This type of notification differs from [ScrollNotification], as it is not +/// associated with the activity of scrolling, but rather the dimensions of +/// the scrollable area. +/// +/// {@tool dartpad} +/// This sample shows how a [ScrollMetricsNotification] is dispatched when +/// the `windowSize` is changed. Press the floating action button to increase +/// the scrollable window's size. +/// +/// ** See code in examples/api/lib/widgets/scroll_position/scroll_metrics_notification.0.dart ** +/// {@end-tool} +/// +abstract class ScrollNotification extends LayoutChangedNotification with ViewportNotificationMixin { + /// Initializes fields for subclasses. + ScrollNotification({ + required this.metrics, + required this.context, + }); + + /// A description of a [Scrollable]'s contents, useful for modeling the state + /// of its viewport. + final ScrollMetrics metrics; + + /// The build context of the widget that fired this notification. + /// + /// This can be used to find the scrollable's render objects to determine the + /// size of the viewport, for instance. + final BuildContext? context; + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + description.add('$metrics'); + } +} + +/// A notification that a [Scrollable] widget has started scrolling. +/// +/// See also: +/// +/// * [ScrollEndNotification], which indicates that scrolling has stopped. +/// * [ScrollNotification], which describes the notification lifecycle. +class ScrollStartNotification extends ScrollNotification { + /// Creates a notification that a [Scrollable] widget has started scrolling. + ScrollStartNotification({ + required super.metrics, + required super.context, + this.dragDetails, + }); + + /// If the [Scrollable] started scrolling because of a drag, the details about + /// that drag start. + /// + /// Otherwise, null. + final DragStartDetails? dragDetails; + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + if (dragDetails != null) { + description.add('$dragDetails'); + } + } +} + +/// A notification that a [Scrollable] widget has changed its scroll position. +/// +/// See also: +/// +/// * [OverscrollNotification], which indicates that a [Scrollable] widget +/// has not changed its scroll position because the change would have caused +/// its scroll position to go outside its scroll bounds. +/// * [ScrollNotification], which describes the notification lifecycle. +class ScrollUpdateNotification extends ScrollNotification { + /// Creates a notification that a [Scrollable] widget has changed its scroll + /// position. + ScrollUpdateNotification({ + required super.metrics, + required BuildContext super.context, + this.dragDetails, + this.scrollDelta, + int? depth, + }) { + if (depth != null) { + _depth = depth; + } + } + + /// If the [Scrollable] changed its scroll position because of a drag, the + /// details about that drag update. + /// + /// Otherwise, null. + final DragUpdateDetails? dragDetails; + + /// The distance by which the [Scrollable] was scrolled, in logical pixels. + final double? scrollDelta; + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + description.add('scrollDelta: $scrollDelta'); + if (dragDetails != null) { + description.add('$dragDetails'); + } + } +} + +/// A notification that a [Scrollable] widget has not changed its scroll position +/// because the change would have caused its scroll position to go outside of +/// its scroll bounds. +/// +/// See also: +/// +/// * [ScrollUpdateNotification], which indicates that a [Scrollable] widget +/// has changed its scroll position. +/// * [ScrollNotification], which describes the notification lifecycle. +class OverscrollNotification extends ScrollNotification { + /// Creates a notification that a [Scrollable] widget has changed its scroll + /// position outside of its scroll bounds. + OverscrollNotification({ + required super.metrics, + required BuildContext super.context, + this.dragDetails, + required this.overscroll, + this.velocity = 0.0, + }) : assert(overscroll.isFinite), + assert(overscroll != 0.0); + + /// If the [Scrollable] overscrolled because of a drag, the details about that + /// drag update. + /// + /// Otherwise, null. + final DragUpdateDetails? dragDetails; + + /// The number of logical pixels that the [Scrollable] avoided scrolling. + /// + /// This will be negative for overscroll on the "start" side and positive for + /// overscroll on the "end" side. + final double overscroll; + + /// The velocity at which the [ScrollPosition] was changing when this + /// overscroll happened. + /// + /// This will typically be 0.0 for touch-driven overscrolls, and positive + /// for overscrolls that happened from a [BallisticScrollActivity] or + /// [DrivenScrollActivity]. + final double velocity; + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + description.add('overscroll: ${overscroll.toStringAsFixed(1)}'); + description.add('velocity: ${velocity.toStringAsFixed(1)}'); + if (dragDetails != null) { + description.add('$dragDetails'); + } + } +} + +/// A notification that a [Scrollable] widget has stopped scrolling. +/// +/// See also: +/// +/// * [ScrollStartNotification], which indicates that scrolling has started. +/// * [ScrollNotification], which describes the notification lifecycle. +class ScrollEndNotification extends ScrollNotification { + /// Creates a notification that a [Scrollable] widget has stopped scrolling. + ScrollEndNotification({ + required super.metrics, + required BuildContext super.context, + this.dragDetails, + }); + + /// If the [Scrollable] stopped scrolling because of a drag, the details about + /// that drag end. + /// + /// Otherwise, null. + /// + /// If a drag ends with some residual velocity, a typical [ScrollPhysics] will + /// start a ballistic scroll, which delays the [ScrollEndNotification] until + /// the ballistic simulation completes, at which time [dragDetails] will + /// be null. If the residual velocity is too small to trigger ballistic + /// scrolling, then the [ScrollEndNotification] will be dispatched immediately + /// and [dragDetails] will be non-null. + final DragEndDetails? dragDetails; + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + if (dragDetails != null) { + description.add('$dragDetails'); + } + } +} + +/// A notification that the user has changed the [ScrollDirection] in which they +/// are scrolling, or have stopped scrolling. +/// +/// For the direction that the [ScrollView] is oriented to, and the direction +/// contents are being laid out in, see [AxisDirection] & [GrowthDirection]. +/// +/// {@macro flutter.rendering.ScrollDirection.sample} +/// +/// See also: +/// +/// * [ScrollNotification], which describes the notification lifecycle. +class UserScrollNotification extends ScrollNotification { + /// Creates a notification that the user has changed the direction in which + /// they are scrolling. + UserScrollNotification({ + required super.metrics, + required BuildContext super.context, + required this.direction, + }); + + /// The direction in which the user is scrolling. + /// + /// This does not represent the current [AxisDirection] or [GrowthDirection] + /// of the [Viewport], which respectively represent the direction that the + /// scroll offset is increasing in, and the direction that contents are being + /// laid out in. + /// + /// {@macro flutter.rendering.ScrollDirection.sample} + final ScrollDirection direction; + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + description.add('direction: $direction'); + } +} + +/// A predicate for [ScrollNotification], used to customize widgets that +/// listen to notifications from their children. +typedef ScrollNotificationPredicate = bool Function(ScrollNotification notification); + +/// A [ScrollNotificationPredicate] that checks whether +/// `notification.depth == 0`, which means that the notification did not bubble +/// through any intervening scrolling widgets. +bool defaultScrollNotificationPredicate(ScrollNotification notification) { + return notification.depth == 0; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_notification_observer.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_notification_observer.dart new file mode 100644 index 0000000000000000000000000000000000000000..f7112ec1494379cbf95f9d3f642320b3fbf2ec45 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_notification_observer.dart @@ -0,0 +1,245 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; + +import 'package:flutter/foundation.dart'; + +import 'framework.dart'; +import 'notification_listener.dart'; +import 'scroll_notification.dart'; +import 'scroll_position.dart'; + +// Examples can assume: +// void _listener(ScrollNotification notification) { } +// late BuildContext context; + +/// A [ScrollNotification] listener for [ScrollNotificationObserver]. +/// +/// [ScrollNotificationObserver] is similar to +/// [NotificationListener]. It supports a listener list instead of +/// just a single listener and its listeners run unconditionally, they +/// do not require a gating boolean return value. +typedef ScrollNotificationCallback = void Function(ScrollNotification notification); + +class _ScrollNotificationObserverScope extends InheritedWidget { + const _ScrollNotificationObserverScope({ + required super.child, + required ScrollNotificationObserverState scrollNotificationObserverState, + }) : _scrollNotificationObserverState = scrollNotificationObserverState; + + final ScrollNotificationObserverState _scrollNotificationObserverState; + + @override + bool updateShouldNotify(_ScrollNotificationObserverScope old) => _scrollNotificationObserverState != old._scrollNotificationObserverState; +} + +final class _ListenerEntry extends LinkedListEntry<_ListenerEntry> { + _ListenerEntry(this.listener); + final ScrollNotificationCallback listener; +} + +/// Notifies its listeners when a descendant scrolls. +/// +/// To add a listener to a [ScrollNotificationObserver] ancestor: +/// +/// ```dart +/// ScrollNotificationObserver.of(context).addListener(_listener); +/// ``` +/// +/// To remove the listener from a [ScrollNotificationObserver] ancestor: +/// +/// ```dart +/// ScrollNotificationObserver.of(context).removeListener(_listener); +/// ``` +/// +/// Stateful widgets that share an ancestor [ScrollNotificationObserver] typically +/// add a listener in [State.didChangeDependencies] (removing the old one +/// if necessary) and remove the listener in their [State.dispose] method. +/// +/// Any function with the [ScrollNotificationCallback] signature can act as a +/// listener: +/// +/// ```dart +/// // (e.g. in a stateful widget) +/// void _listener(ScrollNotification notification) { +/// // Do something, maybe setState() +/// } +/// ``` +/// +/// This widget is similar to [NotificationListener]. It supports a listener +/// list instead of just a single listener and its listeners run +/// unconditionally, they do not require a gating boolean return value. +/// +/// {@tool dartpad} +/// This sample shows a "Scroll to top" button that uses [ScrollNotificationObserver] +/// to listen for scroll notifications from [ListView]. The button is only visible +/// when the user has scrolled down. When pressed, the button animates the scroll +/// position of the [ListView] back to the top. +/// +/// ** See code in examples/api/lib/widgets/scroll_notification_observer/scroll_notification_observer.0.dart ** +/// {@end-tool} +class ScrollNotificationObserver extends StatefulWidget { + /// Create a [ScrollNotificationObserver]. + const ScrollNotificationObserver({ + super.key, + required this.child, + }); + + /// The subtree below this widget. + final Widget child; + + /// The closest instance of this class that encloses the given context. + /// + /// If there is no enclosing [ScrollNotificationObserver] widget, then null is + /// returned. + /// + /// Calling this method will create a dependency on the closest + /// [ScrollNotificationObserver] in the [context], if there is one. + /// + /// See also: + /// + /// * [ScrollNotificationObserver.of], which is similar to this method, but + /// asserts if no [ScrollNotificationObserver] ancestor is found. + static ScrollNotificationObserverState? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<_ScrollNotificationObserverScope>()?._scrollNotificationObserverState; + } + + /// The closest instance of this class that encloses the given context. + /// + /// If no ancestor is found, this method will assert in debug mode, and throw + /// an exception in release mode. + /// + /// Calling this method will create a dependency on the closest + /// [ScrollNotificationObserver] in the [context]. + /// + /// See also: + /// + /// * [ScrollNotificationObserver.maybeOf], which is similar to this method, + /// but returns null if no [ScrollNotificationObserver] ancestor is found. + static ScrollNotificationObserverState of(BuildContext context) { + final ScrollNotificationObserverState? observerState = maybeOf(context); + assert(() { + if (observerState == null) { + throw FlutterError( + 'ScrollNotificationObserver.of() was called with a context that does not contain a ' + 'ScrollNotificationObserver widget.\n' + 'No ScrollNotificationObserver widget ancestor could be found starting from the ' + 'context that was passed to ScrollNotificationObserver.of(). This can happen ' + 'because you are using a widget that looks for a ScrollNotificationObserver ' + 'ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return observerState!; + } + + @override + ScrollNotificationObserverState createState() => ScrollNotificationObserverState(); +} + +/// The listener list state for a [ScrollNotificationObserver] returned by +/// [ScrollNotificationObserver.of]. +/// +/// [ScrollNotificationObserver] is similar to +/// [NotificationListener]. It supports a listener list instead of +/// just a single listener and its listeners run unconditionally, they +/// do not require a gating boolean return value. +class ScrollNotificationObserverState extends State<ScrollNotificationObserver> { + LinkedList<_ListenerEntry>? _listeners = LinkedList<_ListenerEntry>(); + + bool _debugAssertNotDisposed() { + assert(() { + if (_listeners == null) { + throw FlutterError( + 'A $runtimeType was used after being disposed.\n' + 'Once you have called dispose() on a $runtimeType, it can no longer be used.', + ); + } + return true; + }()); + return true; + } + + /// Add a [ScrollNotificationCallback] that will be called each time + /// a descendant scrolls. + void addListener(ScrollNotificationCallback listener) { + assert(_debugAssertNotDisposed()); + _listeners!.add(_ListenerEntry(listener)); + } + + /// Remove the specified [ScrollNotificationCallback]. + void removeListener(ScrollNotificationCallback listener) { + assert(_debugAssertNotDisposed()); + for (final _ListenerEntry entry in _listeners!) { + if (entry.listener == listener) { + entry.unlink(); + return; + } + } + } + + void _notifyListeners(ScrollNotification notification) { + assert(_debugAssertNotDisposed()); + if (_listeners!.isEmpty) { + return; + } + + final List<_ListenerEntry> localListeners = List<_ListenerEntry>.of(_listeners!); + for (final _ListenerEntry entry in localListeners) { + try { + if (entry.list != null) { + entry.listener(notification); + } + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widget library', + context: ErrorDescription('while dispatching notifications for $runtimeType'), + informationCollector: () => <DiagnosticsNode>[ + DiagnosticsProperty<ScrollNotificationObserverState>( + 'The $runtimeType sending notification was', + this, + style: DiagnosticsTreeStyle.errorProperty, + ), + ], + )); + } + } + } + + @override + Widget build(BuildContext context) { + return NotificationListener<ScrollMetricsNotification>( + onNotification: (ScrollMetricsNotification notification) { + // A ScrollMetricsNotification allows listeners to be notified for an + // initial state, as well as if the content dimensions change without + // scrolling. + _notifyListeners(notification.asScrollUpdate()); + return false; + }, + child: NotificationListener<ScrollNotification>( + onNotification: (ScrollNotification notification) { + _notifyListeners(notification); + return false; + }, + child: _ScrollNotificationObserverScope( + scrollNotificationObserverState: this, + child: widget.child, + ), + ), + ); + } + + @override + void dispose() { + assert(_debugAssertNotDisposed()); + _listeners = null; + super.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_physics.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_physics.dart new file mode 100644 index 0000000000000000000000000000000000000000..ef8ca02b0a1433ddf8d4c8b0b369834ae1e43bca --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_physics.dart @@ -0,0 +1,976 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/painting.dart' show AxisDirection; +import 'package:flutter/physics.dart'; + +import 'binding.dart' show WidgetsBinding; +import 'framework.dart'; +import 'overscroll_indicator.dart'; +import 'scroll_metrics.dart'; +import 'scroll_simulation.dart'; +import 'view.dart'; + +export 'package:flutter/physics.dart' show ScrollSpringSimulation, Simulation, Tolerance; + +/// The rate at which scroll momentum will be decelerated. +enum ScrollDecelerationRate { + /// Standard deceleration, aligned with mobile software expectations. + normal, + /// Increased deceleration, aligned with desktop software expectations. + /// + /// Appropriate for use with input devices more precise than touch screens, + /// such as trackpads or mouse wheels. + fast +} + +// Examples can assume: +// class FooScrollPhysics extends ScrollPhysics { +// const FooScrollPhysics({ super.parent }); +// @override +// FooScrollPhysics applyTo(ScrollPhysics? ancestor) { +// return FooScrollPhysics(parent: buildParent(ancestor)); +// } +// } +// class BarScrollPhysics extends ScrollPhysics { +// const BarScrollPhysics({ super.parent }); +// } + +/// Determines the physics of a [Scrollable] widget. +/// +/// For example, determines how the [Scrollable] will behave when the user +/// reaches the maximum scroll extent or when the user stops scrolling. +/// +/// When starting a physics [Simulation], the current scroll position and +/// velocity are used as the initial conditions for the particle in the +/// simulation. The movement of the particle in the simulation is then used to +/// determine the scroll position for the widget. +/// +/// Instead of creating your own subclasses, [parent] can be used to combine +/// [ScrollPhysics] objects of different types to get the desired scroll physics. +/// For example: +/// +/// ```dart +/// const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()) +/// ``` +/// +/// You can also use `applyTo`, which is useful when you already have +/// an instance of [ScrollPhysics]: +/// +/// ```dart +/// ScrollPhysics physics = const BouncingScrollPhysics(); +/// // ... +/// final ScrollPhysics mergedPhysics = physics.applyTo(const AlwaysScrollableScrollPhysics()); +/// ``` +/// +/// When implementing a subclass, you must override [applyTo] so that it returns +/// an appropriate instance of your subclass. Otherwise, classes like +/// [Scrollable] that inform a [ScrollPosition] will combine them with +/// the default [ScrollPhysics] object instead of your custom subclass. +@immutable +class ScrollPhysics { + /// Creates an object with the default scroll physics. + const ScrollPhysics({ this.parent }); + + /// If non-null, determines the default behavior for each method. + /// + /// If a subclass of [ScrollPhysics] does not override a method, that subclass + /// will inherit an implementation from this base class that defers to + /// [parent]. This mechanism lets you assemble novel combinations of + /// [ScrollPhysics] subclasses at runtime. For example: + /// + /// ```dart + /// const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()) + /// ``` + /// + /// will result in a [ScrollPhysics] that has the combined behavior + /// of [BouncingScrollPhysics] and [AlwaysScrollableScrollPhysics]: + /// behaviors that are not specified in [BouncingScrollPhysics] + /// (e.g. [shouldAcceptUserOffset]) will defer to [AlwaysScrollableScrollPhysics]. + final ScrollPhysics? parent; + + /// If [parent] is null then return ancestor, otherwise recursively build a + /// ScrollPhysics that has [ancestor] as its parent. + /// + /// This method is typically used to define [applyTo] methods like: + /// + /// ```dart + /// class MyScrollPhysics extends ScrollPhysics { + /// const MyScrollPhysics({ super.parent }); + /// + /// @override + /// MyScrollPhysics applyTo(ScrollPhysics? ancestor) { + /// return MyScrollPhysics(parent: buildParent(ancestor)); + /// } + /// + /// // ... + /// } + /// ``` + @protected + ScrollPhysics? buildParent(ScrollPhysics? ancestor) => parent?.applyTo(ancestor) ?? ancestor; + + /// Combines this [ScrollPhysics] instance with the given physics. + /// + /// The returned object uses this instance's physics when it has an + /// opinion, and defers to the given `ancestor` object's physics + /// when it does not. + /// + /// If [parent] is null then this returns a [ScrollPhysics] with the + /// same [runtimeType], but where the [parent] has been replaced + /// with the [ancestor]. + /// + /// If this scroll physics object already has a parent, then this + /// method is applied recursively and ancestor will appear at the + /// end of the existing chain of parents. + /// + /// Calling this method with a null argument will copy the current + /// object. This is inefficient. + /// + /// {@tool snippet} + /// + /// In the following example, the [applyTo] method is used to combine the + /// scroll physics of two [ScrollPhysics] objects. The resulting [ScrollPhysics] + /// `x` has the same behavior as `y`. + /// + /// ```dart + /// final FooScrollPhysics x = const FooScrollPhysics().applyTo(const BarScrollPhysics()); + /// const FooScrollPhysics y = FooScrollPhysics(parent: BarScrollPhysics()); + /// ``` + /// {@end-tool} + /// + /// ## Implementing [applyTo] + /// + /// When creating a custom [ScrollPhysics] subclass, this method + /// must be implemented. If the physics class has no constructor + /// arguments, then implementing this method is merely a matter of + /// calling the constructor with a [parent] constructed using + /// [buildParent], as follows: + /// + /// ```dart + /// class MyScrollPhysics extends ScrollPhysics { + /// const MyScrollPhysics({ super.parent }); + /// + /// @override + /// MyScrollPhysics applyTo(ScrollPhysics? ancestor) { + /// return MyScrollPhysics(parent: buildParent(ancestor)); + /// } + /// + /// // ... + /// } + /// ``` + /// + /// If the physics class has constructor arguments, they must be passed to + /// the constructor here as well, so as to create a clone. + /// + /// See also: + /// + /// * [buildParent], a utility method that's often used to define [applyTo] + /// methods for [ScrollPhysics] subclasses. + ScrollPhysics applyTo(ScrollPhysics? ancestor) { + return ScrollPhysics(parent: buildParent(ancestor)); + } + + /// Used by [DragScrollActivity] and other user-driven activities to convert + /// an offset in logical pixels as provided by the [DragUpdateDetails] into a + /// delta to apply (subtract from the current position) using + /// [ScrollActivityDelegate.setPixels]. + /// + /// This is used by some [ScrollPosition] subclasses to apply friction during + /// overscroll situations. + /// + /// This method must not adjust parts of the offset that are entirely within + /// the bounds described by the given `position`. + /// + /// The given `position` is only valid during this method call. Do not keep a + /// reference to it to use later, as the values may update, may not update, or + /// may update to reflect an entirely unrelated scrollable. + double applyPhysicsToUserOffset(ScrollMetrics position, double offset) { + if (parent == null) { + return offset; + } + return parent!.applyPhysicsToUserOffset(position, offset); + } + + /// Whether the scrollable should let the user adjust the scroll offset, for + /// example by dragging. If [allowUserScrolling] is false, the scrollable + /// will never allow user input to change the scroll position. + /// + /// By default, the user can manipulate the scroll offset if, and only if, + /// there is actually content outside the viewport to reveal. + /// + /// The given `position` is only valid during this method call. Do not keep a + /// reference to it to use later, as the values may update, may not update, or + /// may update to reflect an entirely unrelated scrollable. + bool shouldAcceptUserOffset(ScrollMetrics position) { + if (!allowUserScrolling) { + return false; + } + + if (parent == null) { + return position.pixels != 0.0 || position.minScrollExtent != position.maxScrollExtent; + } + return parent!.shouldAcceptUserOffset(position); + } + + /// Provides a heuristic to determine if expensive frame-bound tasks should be + /// deferred. + /// + /// The `velocity` parameter may be positive, negative, or zero. + /// + /// The `context` parameter normally refers to the [BuildContext] of the widget + /// making the call, such as an [Image] widget in a [ListView]. + /// + /// This can be used to determine whether decoding or fetching complex data + /// for the currently visible part of the viewport should be delayed + /// to avoid doing work that will not have a chance to appear before a new + /// frame is rendered. + /// + /// For example, a list of images could use this logic to delay decoding + /// images until scrolling is slow enough to actually render the decoded + /// image to the screen. + /// + /// The default implementation is a heuristic that compares the current + /// scroll velocity in local logical pixels to the longest side of the window + /// in physical pixels. Implementers can change this heuristic by overriding + /// this method and providing their custom physics to the scrollable widget. + /// For example, an application that changes the local coordinate system with + /// a large perspective transform could provide a more or less aggressive + /// heuristic depending on whether the transform was increasing or decreasing + /// the overall scale between the global screen and local scrollable + /// coordinate systems. + /// + /// The default implementation is stateless, and provides a point-in-time + /// decision about how fast the scrollable is scrolling. It would always + /// return true for a scrollable that is animating back and forth at high + /// velocity in a loop. It is assumed that callers will handle such + /// a case, or that a custom stateful implementation would be written that + /// tracks the sign of the velocity on successive calls. + /// + /// Returning true from this method indicates that the current scroll velocity + /// is great enough that expensive operations impacting the UI should be + /// deferred. + bool recommendDeferredLoading(double velocity, ScrollMetrics metrics, BuildContext context) { + if (parent == null) { + final double maxPhysicalPixels = View.of(context).physicalSize.longestSide; + return velocity.abs() > maxPhysicalPixels; + } + return parent!.recommendDeferredLoading(velocity, metrics, context); + } + + /// Determines the overscroll by applying the boundary conditions. + /// + /// Called by [ScrollPosition.applyBoundaryConditions], which is called by + /// [ScrollPosition.setPixels] just before the [ScrollPosition.pixels] value + /// is updated, to determine how much of the offset is to be clamped off and + /// sent to [ScrollPosition.didOverscrollBy]. + /// + /// The `value` argument is guaranteed to not equal the [ScrollMetrics.pixels] + /// of the `position` argument when this is called. + /// + /// It is possible for this method to be called when the `position` describes + /// an already-out-of-bounds position. In that case, the boundary conditions + /// should usually only prevent a further increase in the extent to which the + /// position is out of bounds, allowing a decrease to be applied successfully, + /// so that (for instance) an animation can smoothly snap an out of bounds + /// position to the bounds. See [BallisticScrollActivity]. + /// + /// This method must not clamp parts of the offset that are entirely within + /// the bounds described by the given `position`. + /// + /// The given `position` is only valid during this method call. Do not keep a + /// reference to it to use later, as the values may update, may not update, or + /// may update to reflect an entirely unrelated scrollable. + /// + /// ## Examples + /// + /// [BouncingScrollPhysics] returns zero. In other words, it allows scrolling + /// past the boundary unhindered. + /// + /// [ClampingScrollPhysics] returns the amount by which the value is beyond + /// the position or the boundary, whichever is furthest from the content. In + /// other words, it disallows scrolling past the boundary, but allows + /// scrolling back from being overscrolled, if for some reason the position + /// ends up overscrolled. + double applyBoundaryConditions(ScrollMetrics position, double value) { + if (parent == null) { + return 0.0; + } + return parent!.applyBoundaryConditions(position, value); + } + + /// Describes what the scroll position should be given new viewport dimensions. + /// + /// This is called by [ScrollPosition.correctForNewDimensions]. + /// + /// The arguments consist of the scroll metrics as they stood in the previous + /// frame and the scroll metrics as they now stand after the last layout, + /// including the position and minimum and maximum scroll extents; a flag + /// indicating if the current [ScrollActivity] considers that the user is + /// actively scrolling (see [ScrollActivity.isScrolling]); and the current + /// velocity of the scroll position, if it is being driven by the scroll + /// activity (this is 0.0 during a user gesture) (see + /// [ScrollActivity.velocity]). + /// + /// The scroll metrics will be identical except for the + /// [ScrollMetrics.minScrollExtent] and [ScrollMetrics.maxScrollExtent]. They + /// are referred to as the `oldPosition` and `newPosition` (even though they + /// both technically have the same "position", in the form of + /// [ScrollMetrics.pixels]) because they are generated from the + /// [ScrollPosition] before and after updating the scroll extents. + /// + /// If the returned value does not exactly match the scroll offset given by + /// the `newPosition` argument (see [ScrollMetrics.pixels]), then the + /// [ScrollPosition] will call [ScrollPosition.correctPixels] to update the + /// new scroll position to the returned value, and layout will be re-run. This + /// is expensive. The new value is subject to further manipulation by + /// [applyBoundaryConditions]. + /// + /// If the returned value _does_ match the `newPosition.pixels` scroll offset + /// exactly, then [ScrollPosition.applyNewDimensions] will be called next. In + /// that case, [applyBoundaryConditions] is not applied to the return value. + /// + /// The given [ScrollMetrics] are only valid during this method call. Do not + /// keep references to them to use later, as the values may update, may not + /// update, or may update to reflect an entirely unrelated scrollable. + /// + /// The default implementation returns the [ScrollMetrics.pixels] of the + /// `newPosition`, which indicates that the current scroll offset is + /// acceptable. + /// + /// See also: + /// + /// * [RangeMaintainingScrollPhysics], which is enabled by default, and + /// which prevents unexpected changes to the content dimensions from + /// causing the scroll position to get any further out of bounds. + double adjustPositionForNewDimensions({ + required ScrollMetrics oldPosition, + required ScrollMetrics newPosition, + required bool isScrolling, + required double velocity, + }) { + if (parent == null) { + return newPosition.pixels; + } + return parent!.adjustPositionForNewDimensions(oldPosition: oldPosition, newPosition: newPosition, isScrolling: isScrolling, velocity: velocity); + } + + /// Returns a simulation for ballistic scrolling starting from the given + /// position with the given velocity. + /// + /// This is used by [ScrollPositionWithSingleContext] in the + /// [ScrollPositionWithSingleContext.goBallistic] method. If the result + /// is non-null, [ScrollPositionWithSingleContext] will begin a + /// [BallisticScrollActivity] with the returned value. Otherwise, it will + /// begin an idle activity instead. + /// + /// The given `position` is only valid during this method call. Do not keep a + /// reference to it to use later, as the values may update, may not update, or + /// may update to reflect an entirely unrelated scrollable. + /// + /// This method can potentially be called in every frame, even in the middle + /// of what the user perceives as a single ballistic scroll. For example, in + /// a [ListView] when previously off-screen items come into view and are laid + /// out, this method may be called with a new [ScrollMetrics.maxScrollExtent]. + /// The method implementation should ensure that when the same ballistic + /// scroll motion is still intended, these calls have no side effects on the + /// physics beyond continuing that motion. + /// + /// Generally this is ensured by having the [Simulation] conform to a physical + /// metaphor of a particle in ballistic flight, where the forces on the + /// particle depend only on its position, velocity, and environment, and not + /// on the current time or any internal state. This means that the + /// time-derivative of [Simulation.dx] should be possible to write + /// mathematically as a function purely of the values of [Simulation.x], + /// [Simulation.dx], and the parameters used to construct the [Simulation], + /// independent of the time. + // TODO(gnprice): Some scroll physics in the framework violate that invariant; fix them. + // An audit found three cases violating the invariant: + // https://github.com/flutter/flutter/issues/120338 + // https://github.com/flutter/flutter/issues/120340 + // https://github.com/flutter/flutter/issues/109675 + Simulation? createBallisticSimulation(ScrollMetrics position, double velocity) { + if (parent == null) { + return null; + } + return parent!.createBallisticSimulation(position, velocity); + } + + static final SpringDescription _kDefaultSpring = SpringDescription.withDampingRatio( + mass: 0.5, + stiffness: 100.0, + ratio: 1.1, + ); + + /// The spring to use for ballistic simulations. + SpringDescription get spring => parent?.spring ?? _kDefaultSpring; + + /// Deprecated. Call [toleranceFor] instead. + @Deprecated( + 'Call toleranceFor instead. ' + 'This feature was deprecated after v3.7.0-13.0.pre.', + ) + Tolerance get tolerance { + return toleranceFor(FixedScrollMetrics( + minScrollExtent: null, + maxScrollExtent: null, + pixels: null, + viewportDimension: null, + axisDirection: AxisDirection.down, + devicePixelRatio: WidgetsBinding.instance.window.devicePixelRatio, + )); + } + + /// The tolerance to use for ballistic simulations. + Tolerance toleranceFor(ScrollMetrics metrics) { + return parent?.toleranceFor(metrics) ?? Tolerance( + velocity: 1.0 / (0.050 * metrics.devicePixelRatio), // logical pixels per second + distance: 1.0 / metrics.devicePixelRatio, // logical pixels + ); + } + + /// The minimum distance an input pointer drag must have moved to be + /// considered a scroll fling gesture. + /// + /// This value is typically compared with the distance traveled along the + /// scrolling axis. + /// + /// See also: + /// + /// * [VelocityTracker.getVelocityEstimate], which computes the velocity + /// of a press-drag-release gesture. + double get minFlingDistance => parent?.minFlingDistance ?? kTouchSlop; + + /// The minimum velocity for an input pointer drag to be considered a + /// scroll fling. + /// + /// This value is typically compared with the magnitude of fling gesture's + /// velocity along the scrolling axis. + /// + /// See also: + /// + /// * [VelocityTracker.getVelocityEstimate], which computes the velocity + /// of a press-drag-release gesture. + double get minFlingVelocity => parent?.minFlingVelocity ?? kMinFlingVelocity; + + /// Scroll fling velocity magnitudes will be clamped to this value. + double get maxFlingVelocity => parent?.maxFlingVelocity ?? kMaxFlingVelocity; + + /// Returns the velocity carried on repeated flings. + /// + /// The function is applied to the existing scroll velocity when another + /// scroll drag is applied in the same direction. + /// + /// By default, physics for platforms other than iOS doesn't carry momentum. + double carriedMomentum(double existingVelocity) { + if (parent == null) { + return 0.0; + } + return parent!.carriedMomentum(existingVelocity); + } + + /// The minimum amount of pixel distance drags must move by to start motion + /// the first time or after each time the drag motion stopped. + /// + /// If null, no minimum threshold is enforced. + double? get dragStartDistanceMotionThreshold => parent?.dragStartDistanceMotionThreshold; + + /// Whether a viewport is allowed to change its scroll position implicitly in + /// response to a call to [RenderObject.showOnScreen]. + /// + /// [RenderObject.showOnScreen] is for example used to bring a text field + /// fully on screen after it has received focus. This property controls + /// whether the viewport associated with this object is allowed to change the + /// scroll position to fulfill such a request. + bool get allowImplicitScrolling => true; + + /// Whether a viewport is allowed to change the scroll position as the result of user input. + bool get allowUserScrolling => true; + + @override + String toString() { + if (parent == null) { + return objectRuntimeType(this, 'ScrollPhysics'); + } + return '${objectRuntimeType(this, 'ScrollPhysics')} -> $parent'; + } +} + +/// Scroll physics that attempt to keep the scroll position in range when the +/// contents change dimensions suddenly. +/// +/// This attempts to maintain the amount of overscroll or underscroll already present, +/// if the scroll position is already out of range _and_ the extents +/// have decreased, meaning that some content was removed. The reason for this +/// condition is that when new content is added, keeping the same overscroll +/// would mean that instead of showing it to the user, all of it is +/// being skipped by jumping right to the max extent. +/// +/// If the scroll activity is animating the scroll position, sudden changes to +/// the scroll dimensions are allowed to happen (so as to prevent animations +/// from jumping back and forth between in-range and out-of-range values). +/// +/// These physics should be combined with other scroll physics, e.g. +/// [BouncingScrollPhysics] or [ClampingScrollPhysics], to obtain a complete +/// description of typical scroll physics. See [applyTo]. +/// +/// ## Implementation details +/// +/// Specifically, these physics perform two adjustments. +/// +/// The first is to maintain overscroll when the position is out of range. +/// +/// The second is to enforce the boundary when the position is in range. +/// +/// If the current velocity is non-zero, neither adjustment is made. The +/// assumption is that there is an ongoing animation and therefore +/// further changing the scroll position would disrupt the experience. +/// +/// If the extents haven't changed, then the overscroll adjustment is +/// not made. The assumption is that if the position is overscrolled, +/// it is intentional, otherwise the position could not have reached +/// that position. (Consider [ClampingScrollPhysics] vs +/// [BouncingScrollPhysics] for example.) +/// +/// If the position itself changed since the last animation frame, +/// then the overscroll is not maintained. The assumption is similar +/// to the previous case: the position would not have been placed out +/// of range unless it was intentional. +/// +/// In addition, if the position changed and the boundaries were and +/// still are finite, then the boundary isn't enforced either, for +/// the same reason. However, if any of the boundaries were or are +/// now infinite, the boundary _is_ enforced, on the assumption that +/// infinite boundaries indicate a lazy-loading scroll view, which +/// cannot enforce boundaries while the full list has not loaded. +/// +/// If the range was out of range, then the boundary is not enforced +/// even if the range is not maintained. If the range is maintained, +/// then the distance between the old position and the old boundary is +/// applied to the new boundary to obtain the new position. +/// +/// If the range was in range, and the boundary is to be enforced, +/// then the new position is obtained by deferring to the other physics, +/// if any, and then clamped to the new range. +class RangeMaintainingScrollPhysics extends ScrollPhysics { + /// Creates scroll physics that maintain the scroll position in range. + const RangeMaintainingScrollPhysics({ super.parent }); + + @override + RangeMaintainingScrollPhysics applyTo(ScrollPhysics? ancestor) { + return RangeMaintainingScrollPhysics(parent: buildParent(ancestor)); + } + + @override + double adjustPositionForNewDimensions({ + required ScrollMetrics oldPosition, + required ScrollMetrics newPosition, + required bool isScrolling, + required double velocity, + }) { + bool maintainOverscroll = true; + bool enforceBoundary = true; + if (velocity != 0.0) { + // Don't try to adjust an animating position, the jumping around + // would be distracting. + maintainOverscroll = false; + enforceBoundary = false; + } + if ((oldPosition.minScrollExtent == newPosition.minScrollExtent) && + (oldPosition.maxScrollExtent == newPosition.maxScrollExtent)) { + // If the extents haven't changed then ignore overscroll. + maintainOverscroll = false; + } + if (oldPosition.pixels != newPosition.pixels) { + // If the position has been changed already, then it might have + // been adjusted to expect new overscroll, so don't try to + // maintain the relative overscroll. + maintainOverscroll = false; + if (oldPosition.minScrollExtent.isFinite && oldPosition.maxScrollExtent.isFinite && + newPosition.minScrollExtent.isFinite && newPosition.maxScrollExtent.isFinite) { + // In addition, if the position changed then we don't enforce the new + // boundary if both the new and previous boundaries are entirely finite. + // A common case where the position changes while one + // of the extents is infinite is a lazily-loaded list. (If the + // boundaries were finite, and the position changed, then we + // assume it was intentional.) + enforceBoundary = false; + } + } + if ((oldPosition.pixels < oldPosition.minScrollExtent) || + (oldPosition.pixels > oldPosition.maxScrollExtent)) { + // If the old position was out of range, then we should + // not try to keep the new position in range. + enforceBoundary = false; + } + if (maintainOverscroll) { + // Force the new position to be no more out of range than it was before, if: + // * it was overscrolled, and + // * the extents have decreased, meaning that some content was removed. The + // reason for this condition is that when new content is added, keeping + // the same overscroll would mean that instead of showing it to the user, + // all of it is being skipped by jumping right to the max extent. + if (oldPosition.pixels < oldPosition.minScrollExtent && + newPosition.minScrollExtent > oldPosition.minScrollExtent) { + final double oldDelta = oldPosition.minScrollExtent - oldPosition.pixels; + return newPosition.minScrollExtent - oldDelta; + } + if (oldPosition.pixels > oldPosition.maxScrollExtent && + newPosition.maxScrollExtent < oldPosition.maxScrollExtent) { + final double oldDelta = oldPosition.pixels - oldPosition.maxScrollExtent; + return newPosition.maxScrollExtent + oldDelta; + } + } + // If we're not forcing the overscroll, defer to other physics. + double result = super.adjustPositionForNewDimensions(oldPosition: oldPosition, newPosition: newPosition, isScrolling: isScrolling, velocity: velocity); + if (enforceBoundary) { + // ...but if they put us out of range then reinforce the boundary. + result = clampDouble(result, newPosition.minScrollExtent, newPosition.maxScrollExtent); + } + return result; + } +} + +/// Scroll physics for environments that allow the scroll offset to go beyond +/// the bounds of the content, but then bounce the content back to the edge of +/// those bounds. +/// +/// This is the behavior typically seen on iOS. +/// +/// [BouncingScrollPhysics] by itself will not create an overscroll effect if +/// the contents of the scroll view do not extend beyond the size of the +/// viewport. To create the overscroll and bounce effect regardless of the +/// length of your scroll view, combine with [AlwaysScrollableScrollPhysics]. +/// +/// {@tool snippet} +/// ```dart +/// const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()) +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [ScrollConfiguration], which uses this to provide the default +/// scroll behavior on iOS. +/// * [ClampingScrollPhysics], which is the analogous physics for Android's +/// clamping behavior. +/// * [ScrollPhysics], for more examples of combining [ScrollPhysics] objects +/// of different types to get the desired scroll physics. +class BouncingScrollPhysics extends ScrollPhysics { + /// Creates scroll physics that bounce back from the edge. + const BouncingScrollPhysics({ + this.decelerationRate = ScrollDecelerationRate.normal, + super.parent, + }); + + /// Used to determine parameters for friction simulations. + final ScrollDecelerationRate decelerationRate; + + @override + BouncingScrollPhysics applyTo(ScrollPhysics? ancestor) { + return BouncingScrollPhysics( + parent: buildParent(ancestor), + decelerationRate: decelerationRate + ); + } + + /// The multiple applied to overscroll to make it appear that scrolling past + /// the edge of the scrollable contents is harder than scrolling the list. + /// This is done by reducing the ratio of the scroll effect output vs the + /// scroll gesture input. + /// + /// This factor starts at 0.52 and progressively becomes harder to overscroll + /// as more of the area past the edge is dragged in (represented by an increasing + /// `overscrollFraction` which starts at 0 when there is no overscroll). + double frictionFactor(double overscrollFraction) { + switch (decelerationRate) { + case ScrollDecelerationRate.fast: + return 0.26 * math.pow(1 - overscrollFraction, 2); + case ScrollDecelerationRate.normal: + return 0.52 * math.pow(1 - overscrollFraction, 2); + } + } + + @override + double applyPhysicsToUserOffset(ScrollMetrics position, double offset) { + assert(offset != 0.0); + assert(position.minScrollExtent <= position.maxScrollExtent); + + if (!position.outOfRange) { + return offset; + } + + final double overscrollPastStart = math.max(position.minScrollExtent - position.pixels, 0.0); + final double overscrollPastEnd = math.max(position.pixels - position.maxScrollExtent, 0.0); + final double overscrollPast = math.max(overscrollPastStart, overscrollPastEnd); + final bool easing = (overscrollPastStart > 0.0 && offset < 0.0) + || (overscrollPastEnd > 0.0 && offset > 0.0); + + final double friction = easing + // Apply less resistance when easing the overscroll vs tensioning. + ? frictionFactor((overscrollPast - offset.abs()) / position.viewportDimension) + : frictionFactor(overscrollPast / position.viewportDimension); + final double direction = offset.sign; + + if (easing && decelerationRate == ScrollDecelerationRate.fast) { + return direction * offset.abs(); + } + return direction * _applyFriction(overscrollPast, offset.abs(), friction); + } + + static double _applyFriction(double extentOutside, double absDelta, double gamma) { + assert(absDelta > 0); + double total = 0.0; + if (extentOutside > 0) { + final double deltaToLimit = extentOutside / gamma; + if (absDelta < deltaToLimit) { + return absDelta * gamma; + } + total += extentOutside; + absDelta -= deltaToLimit; + } + return total + absDelta; + } + + @override + double applyBoundaryConditions(ScrollMetrics position, double value) => 0.0; + + @override + Simulation? createBallisticSimulation(ScrollMetrics position, double velocity) { + final Tolerance tolerance = toleranceFor(position); + if (velocity.abs() >= tolerance.velocity || position.outOfRange) { + double constantDeceleration; + switch (decelerationRate) { + case ScrollDecelerationRate.fast: + constantDeceleration = 1400; + case ScrollDecelerationRate.normal: + constantDeceleration = 0; + } + return BouncingScrollSimulation( + spring: spring, + position: position.pixels, + velocity: velocity, + leadingExtent: position.minScrollExtent, + trailingExtent: position.maxScrollExtent, + tolerance: tolerance, + constantDeceleration: constantDeceleration + ); + } + return null; + } + + // The ballistic simulation here decelerates more slowly than the one for + // ClampingScrollPhysics so we require a more deliberate input gesture + // to trigger a fling. + @override + double get minFlingVelocity => kMinFlingVelocity * 2.0; + + // Methodology: + // 1- Use https://github.com/flutter/platform_tests/tree/master/scroll_overlay to test with + // Flutter and platform scroll views superimposed. + // 3- If the scrollables stopped overlapping at any moment, adjust the desired + // output value of this function at that input speed. + // 4- Feed new input/output set into a power curve fitter. Change function + // and repeat from 2. + // 5- Repeat from 2 with medium and slow flings. + /// Momentum build-up function that mimics iOS's scroll speed increase with repeated flings. + /// + /// The velocity of the last fling is not an important factor. Existing speed + /// and (related) time since last fling are factors for the velocity transfer + /// calculations. + @override + double carriedMomentum(double existingVelocity) { + return existingVelocity.sign * + math.min(0.000816 * math.pow(existingVelocity.abs(), 1.967).toDouble(), 40000.0); + } + + // Eyeballed from observation to counter the effect of an unintended scroll + // from the natural motion of lifting the finger after a scroll. + @override + double get dragStartDistanceMotionThreshold => 3.5; + + @override + double get maxFlingVelocity { + switch (decelerationRate) { + case ScrollDecelerationRate.fast: + return kMaxFlingVelocity * 8.0; + case ScrollDecelerationRate.normal: + return super.maxFlingVelocity; + } + } + + @override + SpringDescription get spring { + switch (decelerationRate) { + case ScrollDecelerationRate.fast: + return SpringDescription.withDampingRatio( + mass: 0.3, + stiffness: 75.0, + ratio: 1.3, + ); + case ScrollDecelerationRate.normal: + return super.spring; + } + } +} + +/// Scroll physics for environments that prevent the scroll offset from reaching +/// beyond the bounds of the content. +/// +/// This is the behavior typically seen on Android. +/// +/// See also: +/// +/// * [ScrollConfiguration], which uses this to provide the default +/// scroll behavior on Android. +/// * [BouncingScrollPhysics], which is the analogous physics for iOS' bouncing +/// behavior. +/// * [GlowingOverscrollIndicator], which is used by [ScrollConfiguration] to +/// provide the glowing effect that is usually found with this clamping effect +/// on Android. When using a [MaterialApp], the [GlowingOverscrollIndicator]'s +/// glow color is specified to use the overall theme's +/// [ColorScheme.secondary] color. +class ClampingScrollPhysics extends ScrollPhysics { + /// Creates scroll physics that prevent the scroll offset from exceeding the + /// bounds of the content. + const ClampingScrollPhysics({ super.parent }); + + @override + ClampingScrollPhysics applyTo(ScrollPhysics? ancestor) { + return ClampingScrollPhysics(parent: buildParent(ancestor)); + } + + @override + double applyBoundaryConditions(ScrollMetrics position, double value) { + assert(() { + if (value == position.pixels) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$runtimeType.applyBoundaryConditions() was called redundantly.'), + ErrorDescription( + 'The proposed new position, $value, is exactly equal to the current position of the ' + 'given ${position.runtimeType}, ${position.pixels}.\n' + 'The applyBoundaryConditions method should only be called when the value is ' + 'going to actually change the pixels, otherwise it is redundant.', + ), + DiagnosticsProperty<ScrollPhysics>('The physics object in question was', this, style: DiagnosticsTreeStyle.errorProperty), + DiagnosticsProperty<ScrollMetrics>('The position object in question was', position, style: DiagnosticsTreeStyle.errorProperty), + ]); + } + return true; + }()); + if (value < position.pixels && position.pixels <= position.minScrollExtent) { + // Underscroll. + return value - position.pixels; + } + if (position.maxScrollExtent <= position.pixels && position.pixels < value) { + // Overscroll. + return value - position.pixels; + } + if (value < position.minScrollExtent && position.minScrollExtent < position.pixels) { + // Hit top edge. + return value - position.minScrollExtent; + } + if (position.pixels < position.maxScrollExtent && position.maxScrollExtent < value) { + // Hit bottom edge. + return value - position.maxScrollExtent; + } + return 0.0; + } + + @override + Simulation? createBallisticSimulation(ScrollMetrics position, double velocity) { + final Tolerance tolerance = toleranceFor(position); + if (position.outOfRange) { + double? end; + if (position.pixels > position.maxScrollExtent) { + end = position.maxScrollExtent; + } + if (position.pixels < position.minScrollExtent) { + end = position.minScrollExtent; + } + assert(end != null); + return ScrollSpringSimulation( + spring, + position.pixels, + end!, + math.min(0.0, velocity), + tolerance: tolerance, + ); + } + if (velocity.abs() < tolerance.velocity) { + return null; + } + if (velocity > 0.0 && position.pixels >= position.maxScrollExtent) { + return null; + } + if (velocity < 0.0 && position.pixels <= position.minScrollExtent) { + return null; + } + return ClampingScrollSimulation( + position: position.pixels, + velocity: velocity, + tolerance: tolerance, + ); + } +} + +/// Scroll physics that always lets the user scroll. +/// +/// This overrides the default behavior which is to disable scrolling +/// when there is no content to scroll. It does not override the +/// handling of overscrolling. +/// +/// On Android, overscrolls will be clamped by default and result in an +/// overscroll glow. On iOS, overscrolls will load a spring that will return the +/// scroll view to its normal range when released. +/// +/// See also: +/// +/// * [ScrollPhysics], which can be used instead of this class when the default +/// behavior is desired instead. +/// * [BouncingScrollPhysics], which provides the bouncing overscroll behavior +/// found on iOS. +/// * [ClampingScrollPhysics], which provides the clamping overscroll behavior +/// found on Android. +class AlwaysScrollableScrollPhysics extends ScrollPhysics { + /// Creates scroll physics that always lets the user scroll. + const AlwaysScrollableScrollPhysics({ super.parent }); + + @override + AlwaysScrollableScrollPhysics applyTo(ScrollPhysics? ancestor) { + return AlwaysScrollableScrollPhysics(parent: buildParent(ancestor)); + } + + @override + bool shouldAcceptUserOffset(ScrollMetrics position) => true; +} + +/// Scroll physics that does not allow the user to scroll. +/// +/// See also: +/// +/// * [ScrollPhysics], which can be used instead of this class when the default +/// behavior is desired instead. +/// * [BouncingScrollPhysics], which provides the bouncing overscroll behavior +/// found on iOS. +/// * [ClampingScrollPhysics], which provides the clamping overscroll behavior +/// found on Android. +class NeverScrollableScrollPhysics extends ScrollPhysics { + /// Creates scroll physics that does not let the user scroll. + const NeverScrollableScrollPhysics({ super.parent }); + + @override + NeverScrollableScrollPhysics applyTo(ScrollPhysics? ancestor) { + return NeverScrollableScrollPhysics(parent: buildParent(ancestor)); + } + + @override + bool get allowUserScrolling => false; + + @override + bool get allowImplicitScrolling => false; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_position.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_position.dart new file mode 100644 index 0000000000000000000000000000000000000000..2a03d15e0ebb4aaf8875037c7202de830ae988d1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_position.dart @@ -0,0 +1,1157 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/physics.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'notification_listener.dart'; +import 'page_storage.dart'; +import 'scroll_activity.dart'; +import 'scroll_context.dart'; +import 'scroll_metrics.dart'; +import 'scroll_notification.dart'; +import 'scroll_physics.dart'; + +export 'scroll_activity.dart' show ScrollHoldController; + +/// The policy to use when applying the `alignment` parameter of +/// [ScrollPosition.ensureVisible]. +enum ScrollPositionAlignmentPolicy { + /// Use the `alignment` property of [ScrollPosition.ensureVisible] to decide + /// where to align the visible object. + explicit, + + /// Find the bottom edge of the scroll container, and scroll the container, if + /// necessary, to show the bottom of the object. + /// + /// For example, find the bottom edge of the scroll container. If the bottom + /// edge of the item is below the bottom edge of the scroll container, scroll + /// the item so that the bottom of the item is just visible. If the entire + /// item is already visible, then do nothing. + keepVisibleAtEnd, + + /// Find the top edge of the scroll container, and scroll the container if + /// necessary to show the top of the object. + /// + /// For example, find the top edge of the scroll container. If the top edge of + /// the item is above the top edge of the scroll container, scroll the item so + /// that the top of the item is just visible. If the entire item is already + /// visible, then do nothing. + keepVisibleAtStart, +} + +/// Determines which portion of the content is visible in a scroll view. +/// +/// The [pixels] value determines the scroll offset that the scroll view uses to +/// select which part of its content to display. As the user scrolls the +/// viewport, this value changes, which changes the content that is displayed. +/// +/// The [ScrollPosition] applies [physics] to scrolling, and stores the +/// [minScrollExtent] and [maxScrollExtent]. +/// +/// Scrolling is controlled by the current [activity], which is set by +/// [beginActivity]. [ScrollPosition] itself does not start any activities. +/// Instead, concrete subclasses, such as [ScrollPositionWithSingleContext], +/// typically start activities in response to user input or instructions from a +/// [ScrollController]. +/// +/// This object is a [Listenable] that notifies its listeners when [pixels] +/// changes. +/// +/// {@template flutter.widgets.scrollPosition.listening} +/// ### Accessing Scrolling Information +/// +/// There are several ways to acquire information about scrolling and +/// scrollable widgets, but each provides different types of information about +/// the scrolling activity, the position, and the dimensions of the [Viewport]. +/// +/// A [ScrollController] is a [Listenable]. It notifies its listeners whenever +/// any of the attached [ScrollPosition]s notify _their_ listeners, such as when +/// scrolling occurs. This is very similar to using a [NotificationListener] of +/// type [ScrollNotification] to listen to changes in the scroll position, with +/// the difference being that a notification listener will provide information +/// about the scrolling activity. A notification listener can further listen to +/// specific subclasses of [ScrollNotification], like [UserScrollNotification]. +/// +/// {@tool dartpad} +/// This sample shows the difference between using a [ScrollController] or a +/// [NotificationListener] of type [ScrollNotification] to listen to scrolling +/// activities. Toggling the [Radio] button switches between the two. +/// Using a [ScrollNotification] will provide details about the scrolling +/// activity, along with the metrics of the [ScrollPosition], but not the scroll +/// position object itself. By listening with a [ScrollController], the position +/// object is directly accessible. +/// Both of these types of notifications are only triggered by scrolling. +/// +/// ** See code in examples/api/lib/widgets/scroll_position/scroll_controller_notification.0.dart ** +/// {@end-tool} +/// +/// [ScrollController] does not notify its listeners when the list of +/// [ScrollPosition]s attached to the scroll controller changes. To listen to +/// the attaching and detaching of scroll positions to the controller, use the +/// [ScrollController.onAttach] and [ScrollController.onDetach] methods. This is +/// also useful for adding a listener to the +/// [ScrollPosition.isScrollingNotifier] when the position is created during the +/// build method of the [Scrollable]. +/// +/// At the time that a scroll position is attached, the [ScrollMetrics], such as +/// the [ScrollMetrics.maxScrollExtent], are not yet available. These are not +/// determined until the [Scrollable] has finished laying out its contents and +/// computing things like the full extent of that content. +/// [ScrollPosition.hasContentDimensions] can be used to know when the +/// metrics are available, or a [ScrollMetricsNotification] can be used, +/// discussed further below. +/// +/// {@tool dartpad} +/// This sample shows how to apply a listener to the +/// [ScrollPosition.isScrollingNotifier] using [ScrollController.onAttach]. +/// This is used to change the [AppBar]'s color when scrolling is occurring. +/// +/// ** See code in examples/api/lib/widgets/scroll_position/scroll_controller_on_attach.0.dart ** +/// {@end-tool} +/// +/// #### From a different context +/// +/// When needing to access scrolling information from a context that is within +/// the scrolling widget itself, use [Scrollable.of] to access the +/// [ScrollableState] and the [ScrollableState.position]. This would be the same +/// [ScrollPosition] attached to a [ScrollController]. +/// +/// When needing to access scrolling information from a context that is not an +/// ancestor of the scrolling widget, use [ScrollNotificationObserver]. This is +/// used by [AppBar] to create the scrolled under effect. Since [Scaffold.appBar] +/// is a separate subtree from the [Scaffold.body], scroll notifications would +/// not bubble up to the app bar. Use +/// [ScrollNotificationObserverState.addListener] to listen to scroll +/// notifications happening outside of the current context. +/// +/// #### Dimension changes +/// +/// Lastly, listening to a [ScrollController] or a [ScrollPosition] will +/// _not_ notify when the [ScrollMetrics] of a given scroll position changes, +/// such as when the window is resized, changing the dimensions of the +/// [Viewport] and the previously mentioned extents of the scrollable. In order +/// to listen to changes in scroll metrics, use a [NotificationListener] of type +/// [ScrollMetricsNotification]. This type of notification differs from +/// [ScrollNotification], as it is not associated with the activity of +/// scrolling, but rather the dimensions of the scrollable area, such as the +/// window size. +/// +/// {@tool dartpad} +/// This sample shows how a [ScrollMetricsNotification] is dispatched when +/// the `windowSize` is changed. Press the floating action button to increase +/// the scrollable window's size. +/// +/// ** See code in examples/api/lib/widgets/scroll_position/scroll_metrics_notification.0.dart ** +/// {@end-tool} +/// {@endtemplate} +/// +/// ## Subclassing ScrollPosition +/// +/// Over time, a [Scrollable] might have many different [ScrollPosition] +/// objects. For example, if [Scrollable.physics] changes type, [Scrollable] +/// creates a new [ScrollPosition] with the new physics. To transfer state from +/// the old instance to the new instance, subclasses implement [absorb]. See +/// [absorb] for more details. +/// +/// Subclasses also need to call [didUpdateScrollDirection] whenever +/// [userScrollDirection] changes values. +/// +/// See also: +/// +/// * [Scrollable], which uses a [ScrollPosition] to determine which portion of +/// its content to display. +/// * [ScrollController], which can be used with [ListView], [GridView] and +/// other scrollable widgets to control a [ScrollPosition]. +/// * [ScrollPositionWithSingleContext], which is the most commonly used +/// concrete subclass of [ScrollPosition]. +/// * [ScrollNotification] and [NotificationListener], which can be used to watch +/// the scroll position without using a [ScrollController]. +abstract class ScrollPosition extends ViewportOffset with ScrollMetrics { + /// Creates an object that determines which portion of the content is visible + /// in a scroll view. + ScrollPosition({ + required this.physics, + required this.context, + this.keepScrollOffset = true, + ScrollPosition? oldPosition, + this.debugLabel, + }) { + if (oldPosition != null) { + absorb(oldPosition); + } + if (keepScrollOffset) { + restoreScrollOffset(); + } + } + + /// How the scroll position should respond to user input. + /// + /// For example, determines how the widget continues to animate after the + /// user stops dragging the scroll view. + final ScrollPhysics physics; + + /// Where the scrolling is taking place. + /// + /// Typically implemented by [ScrollableState]. + final ScrollContext context; + + /// Save the current scroll offset with [PageStorage] and restore it if + /// this scroll position's scrollable is recreated. + /// + /// See also: + /// + /// * [ScrollController.keepScrollOffset] and [PageController.keepPage], which + /// create scroll positions and initialize this property. + // TODO(goderbauer): Deprecate this when state restoration supports all features of PageStorage. + final bool keepScrollOffset; + + /// A label that is used in the [toString] output. + /// + /// Intended to aid with identifying animation controller instances in debug + /// output. + final String? debugLabel; + + @override + double get minScrollExtent => _minScrollExtent!; + double? _minScrollExtent; + + @override + double get maxScrollExtent => _maxScrollExtent!; + double? _maxScrollExtent; + + @override + bool get hasContentDimensions => _minScrollExtent != null && _maxScrollExtent != null; + + /// The additional velocity added for a [forcePixels] change in a single + /// frame. + /// + /// This value is used by [recommendDeferredLoading] in addition to the + /// [activity]'s [ScrollActivity.velocity] to ask the [physics] whether or + /// not to defer loading. It accounts for the fact that a [forcePixels] call + /// may involve a [ScrollActivity] with 0 velocity, but the scrollable is + /// still instantaneously moving from its current position to a potentially + /// very far position, and which is of interest to callers of + /// [recommendDeferredLoading]. + /// + /// For example, if a scrollable is currently at 5000 pixels, and we [jumpTo] + /// 0 to get back to the top of the list, we would have an implied velocity of + /// -5000 and an `activity.velocity` of 0. The jump may be going past a + /// number of resource intensive widgets which should avoid doing work if the + /// position jumps past them. + double _impliedVelocity = 0; + + @override + double get pixels => _pixels!; + double? _pixels; + + @override + bool get hasPixels => _pixels != null; + + @override + double get viewportDimension => _viewportDimension!; + double? _viewportDimension; + + @override + bool get hasViewportDimension => _viewportDimension != null; + + /// Whether [viewportDimension], [minScrollExtent], [maxScrollExtent], + /// [outOfRange], and [atEdge] are available. + /// + /// Set to true just before the first time [applyNewDimensions] is called. + bool get haveDimensions => _haveDimensions; + bool _haveDimensions = false; + + /// Take any current applicable state from the given [ScrollPosition]. + /// + /// This method is called by the constructor if it is given an `oldPosition`. + /// The `other` argument might not have the same [runtimeType] as this object. + /// + /// This method can be destructive to the other [ScrollPosition]. The other + /// object must be disposed immediately after this call (in the same call + /// stack, before microtask resolution, by whomever called this object's + /// constructor). + /// + /// If the old [ScrollPosition] object is a different [runtimeType] than this + /// one, the [ScrollActivity.resetActivity] method is invoked on the newly + /// adopted [ScrollActivity]. + /// + /// ## Overriding + /// + /// Overrides of this method must call `super.absorb` after setting any + /// metrics-related or activity-related state, since this method may restart + /// the activity and scroll activities tend to use those metrics when being + /// restarted. + /// + /// Overrides of this method might need to start an [IdleScrollActivity] if + /// they are unable to absorb the activity from the other [ScrollPosition]. + /// + /// Overrides of this method might also need to update the delegates of + /// absorbed scroll activities if they use themselves as a + /// [ScrollActivityDelegate]. + @protected + @mustCallSuper + void absorb(ScrollPosition other) { + assert(other.context == context); + assert(_pixels == null); + if (other.hasContentDimensions) { + _minScrollExtent = other.minScrollExtent; + _maxScrollExtent = other.maxScrollExtent; + } + if (other.hasPixels) { + _pixels = other.pixels; + } + if (other.hasViewportDimension) { + _viewportDimension = other.viewportDimension; + } + + assert(activity == null); + assert(other.activity != null); + _activity = other.activity; + other._activity = null; + if (other.runtimeType != runtimeType) { + activity!.resetActivity(); + } + context.setIgnorePointer(activity!.shouldIgnorePointer); + isScrollingNotifier.value = activity!.isScrolling; + } + + @override + double get devicePixelRatio => context.devicePixelRatio; + + /// Update the scroll position ([pixels]) to a given pixel value. + /// + /// This should only be called by the current [ScrollActivity], either during + /// the transient callback phase or in response to user input. + /// + /// Returns the overscroll, if any. If the return value is 0.0, that means + /// that [pixels] now returns the given `value`. If the return value is + /// positive, then [pixels] is less than the requested `value` by the given + /// amount (overscroll past the max extent), and if it is negative, it is + /// greater than the requested `value` by the given amount (underscroll past + /// the min extent). + /// + /// The amount of overscroll is computed by [applyBoundaryConditions]. + /// + /// The amount of the change that is applied is reported using [didUpdateScrollPositionBy]. + /// If there is any overscroll, it is reported using [didOverscrollBy]. + double setPixels(double newPixels) { + assert(hasPixels); + assert(SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks, "A scrollable's position should not change during the build, layout, and paint phases, otherwise the rendering will be confused."); + if (newPixels != pixels) { + final double overscroll = applyBoundaryConditions(newPixels); + assert(() { + final double delta = newPixels - pixels; + if (overscroll.abs() > delta.abs()) { + throw FlutterError( + '$runtimeType.applyBoundaryConditions returned invalid overscroll value.\n' + 'setPixels() was called to change the scroll offset from $pixels to $newPixels.\n' + 'That is a delta of $delta units.\n' + '$runtimeType.applyBoundaryConditions reported an overscroll of $overscroll units.', + ); + } + return true; + }()); + final double oldPixels = pixels; + _pixels = newPixels - overscroll; + if (_pixels != oldPixels) { + notifyListeners(); + didUpdateScrollPositionBy(pixels - oldPixels); + } + if (overscroll.abs() > precisionErrorTolerance) { + didOverscrollBy(overscroll); + return overscroll; + } + } + return 0.0; + } + + /// Change the value of [pixels] to the new value, without notifying any + /// customers. + /// + /// This is used to adjust the position while doing layout. In particular, + /// this is typically called as a response to [applyViewportDimension] or + /// [applyContentDimensions] (in both cases, if this method is called, those + /// methods should then return false to indicate that the position has been + /// adjusted). + /// + /// Calling this is rarely correct in other contexts. It will not immediately + /// cause the rendering to change, since it does not notify the widgets or + /// render objects that might be listening to this object: they will only + /// change when they next read the value, which could be arbitrarily later. It + /// is generally only appropriate in the very specific case of the value being + /// corrected during layout (since then the value is immediately read), in the + /// specific case of a [ScrollPosition] with a single viewport customer. + /// + /// To cause the position to jump or animate to a new value, consider [jumpTo] + /// or [animateTo], which will honor the normal conventions for changing the + /// scroll offset. + /// + /// To force the [pixels] to a particular value without honoring the normal + /// conventions for changing the scroll offset, consider [forcePixels]. (But + /// see the discussion there for why that might still be a bad idea.) + /// + /// See also: + /// + /// * [correctBy], which is a method of [ViewportOffset] used + /// by viewport render objects to correct the offset during layout + /// without notifying its listeners. + /// * [jumpTo], for making changes to position while not in the + /// middle of layout and applying the new position immediately. + /// * [animateTo], which is like [jumpTo] but animating to the + /// destination offset. + // ignore: use_setters_to_change_properties, (API is intended to discourage setting value) + void correctPixels(double value) { + _pixels = value; + } + + /// Apply a layout-time correction to the scroll offset. + /// + /// This method should change the [pixels] value by `correction`, but without + /// calling [notifyListeners]. It is called during layout by the + /// [RenderViewport], before [applyContentDimensions]. After this method is + /// called, the layout will be recomputed and that may result in this method + /// being called again, though this should be very rare. + /// + /// See also: + /// + /// * [jumpTo], for also changing the scroll position when not in layout. + /// [jumpTo] applies the change immediately and notifies its listeners. + /// * [correctPixels], which is used by the [ScrollPosition] itself to + /// set the offset initially during construction or after + /// [applyViewportDimension] or [applyContentDimensions] is called. + @override + void correctBy(double correction) { + assert( + hasPixels, + 'An initial pixels value must exist by calling correctPixels on the ScrollPosition', + ); + _pixels = _pixels! + correction; + _didChangeViewportDimensionOrReceiveCorrection = true; + } + + /// Change the value of [pixels] to the new value, and notify any customers, + /// but without honoring normal conventions for changing the scroll offset. + /// + /// This is used to implement [jumpTo]. It can also be used adjust the + /// position when the dimensions of the viewport change. It should only be + /// used when manually implementing the logic for honoring the relevant + /// conventions of the class. For example, [ScrollPositionWithSingleContext] + /// introduces [ScrollActivity] objects and uses [forcePixels] in conjunction + /// with adjusting the activity, e.g. by calling + /// [ScrollPositionWithSingleContext.goIdle], so that the activity does + /// not immediately set the value back. (Consider, for instance, a case where + /// one is using a [DrivenScrollActivity]. That object will ignore any calls + /// to [forcePixels], which would result in the rendering stuttering: changing + /// in response to [forcePixels], and then changing back to the next value + /// derived from the animation.) + /// + /// To cause the position to jump or animate to a new value, consider [jumpTo] + /// or [animateTo]. + /// + /// This should not be called during layout (e.g. when setting the initial + /// scroll offset). Consider [correctPixels] if you find you need to adjust + /// the position during layout. + @protected + void forcePixels(double value) { + assert(hasPixels); + _impliedVelocity = value - pixels; + _pixels = value; + notifyListeners(); + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + _impliedVelocity = 0; + }, debugLabel: 'ScrollPosition.resetVelocity'); + } + + /// Called whenever scrolling ends, to store the current scroll offset in a + /// storage mechanism with a lifetime that matches the app's lifetime. + /// + /// The stored value will be used by [restoreScrollOffset] when the + /// [ScrollPosition] is recreated, in the case of the [Scrollable] being + /// disposed then recreated in the same session. This might happen, for + /// instance, if a [ListView] is on one of the pages inside a [TabBarView], + /// and that page is displayed, then hidden, then displayed again. + /// + /// The default implementation writes the [pixels] using the nearest + /// [PageStorage] found from the [context]'s [ScrollContext.storageContext] + /// property. + // TODO(goderbauer): Deprecate this when state restoration supports all features of PageStorage. + @protected + void saveScrollOffset() { + PageStorage.maybeOf(context.storageContext)?.writeState(context.storageContext, pixels); + } + + /// Called whenever the [ScrollPosition] is created, to restore the scroll + /// offset if possible. + /// + /// The value is stored by [saveScrollOffset] when the scroll position + /// changes, so that it can be restored in the case of the [Scrollable] being + /// disposed then recreated in the same session. This might happen, for + /// instance, if a [ListView] is on one of the pages inside a [TabBarView], + /// and that page is displayed, then hidden, then displayed again. + /// + /// The default implementation reads the value from the nearest [PageStorage] + /// found from the [context]'s [ScrollContext.storageContext] property, and + /// sets it using [correctPixels], if [pixels] is still null. + /// + /// This method is called from the constructor, so layout has not yet + /// occurred, and the viewport dimensions aren't yet known when it is called. + // TODO(goderbauer): Deprecate this when state restoration supports all features of PageStorage. + @protected + void restoreScrollOffset() { + if (!hasPixels) { + final double? value = PageStorage.maybeOf(context.storageContext)?.readState(context.storageContext) as double?; + if (value != null) { + correctPixels(value); + } + } + } + + /// Called by [context] to restore the scroll offset to the provided value. + /// + /// The provided value has previously been provided to the [context] by + /// calling [ScrollContext.saveOffset], e.g. from [saveOffset]. + /// + /// This method may be called right after the scroll position is created + /// before layout has occurred. In that case, `initialRestore` is set to true + /// and the viewport dimensions will not be known yet. If the [context] + /// doesn't have any information to restore the scroll offset this method is + /// not called. + /// + /// The method may be called multiple times in the lifecycle of a + /// [ScrollPosition] to restore it to different scroll offsets. + void restoreOffset(double offset, {bool initialRestore = false}) { + if (initialRestore) { + correctPixels(offset); + } else { + jumpTo(offset); + } + } + + /// Called whenever scrolling ends, to persist the current scroll offset for + /// state restoration purposes. + /// + /// The default implementation stores the current value of [pixels] on the + /// [context] by calling [ScrollContext.saveOffset]. At a later point in time + /// or after the application restarts, the [context] may restore the scroll + /// position to the persisted offset by calling [restoreOffset]. + @protected + void saveOffset() { + assert(hasPixels); + context.saveOffset(pixels); + } + + /// Returns the overscroll by applying the boundary conditions. + /// + /// If the given value is in bounds, returns 0.0. Otherwise, returns the + /// amount of value that cannot be applied to [pixels] as a result of the + /// boundary conditions. If the [physics] allow out-of-bounds scrolling, this + /// method always returns 0.0. + /// + /// The default implementation defers to the [physics] object's + /// [ScrollPhysics.applyBoundaryConditions]. + @protected + double applyBoundaryConditions(double value) { + final double result = physics.applyBoundaryConditions(this, value); + assert(() { + final double delta = value - pixels; + if (result.abs() > delta.abs()) { + throw FlutterError( + '${physics.runtimeType}.applyBoundaryConditions returned invalid overscroll value.\n' + 'The method was called to consider a change from $pixels to $value, which is a ' + 'delta of ${delta.toStringAsFixed(1)} units. However, it returned an overscroll of ' + '${result.toStringAsFixed(1)} units, which has a greater magnitude than the delta. ' + 'The applyBoundaryConditions method is only supposed to reduce the possible range ' + 'of movement, not increase it.\n' + 'The scroll extents are $minScrollExtent .. $maxScrollExtent, and the ' + 'viewport dimension is $viewportDimension.', + ); + } + return true; + }()); + return result; + } + + bool _didChangeViewportDimensionOrReceiveCorrection = true; + + @override + bool applyViewportDimension(double viewportDimension) { + if (_viewportDimension != viewportDimension) { + _viewportDimension = viewportDimension; + _didChangeViewportDimensionOrReceiveCorrection = true; + // If this is called, you can rely on applyContentDimensions being called + // soon afterwards in the same layout phase. So we put all the logic that + // relies on both values being computed into applyContentDimensions. + } + return true; + } + + bool _pendingDimensions = false; + ScrollMetrics? _lastMetrics; + // True indicates that there is a ScrollMetrics update notification pending. + bool _haveScheduledUpdateNotification = false; + Axis? _lastAxis; + + bool _isMetricsChanged() { + assert(haveDimensions); + final ScrollMetrics currentMetrics = copyWith(); + + return _lastMetrics == null || + !(currentMetrics.extentBefore == _lastMetrics!.extentBefore && + currentMetrics.extentInside == _lastMetrics!.extentInside && + currentMetrics.extentAfter == _lastMetrics!.extentAfter && + currentMetrics.axisDirection == _lastMetrics!.axisDirection); + } + + @override + bool applyContentDimensions(double minScrollExtent, double maxScrollExtent) { + assert(haveDimensions == (_lastMetrics != null)); + if (!nearEqual(_minScrollExtent, minScrollExtent, Tolerance.defaultTolerance.distance) || + !nearEqual(_maxScrollExtent, maxScrollExtent, Tolerance.defaultTolerance.distance) || + _didChangeViewportDimensionOrReceiveCorrection || + _lastAxis != axis) { + assert(minScrollExtent <= maxScrollExtent); + _minScrollExtent = minScrollExtent; + _maxScrollExtent = maxScrollExtent; + _lastAxis = axis; + final ScrollMetrics? currentMetrics = haveDimensions ? copyWith() : null; + _didChangeViewportDimensionOrReceiveCorrection = false; + _pendingDimensions = true; + if (haveDimensions && !correctForNewDimensions(_lastMetrics!, currentMetrics!)) { + return false; + } + _haveDimensions = true; + } + assert(haveDimensions); + if (_pendingDimensions) { + applyNewDimensions(); + _pendingDimensions = false; + } + assert(!_didChangeViewportDimensionOrReceiveCorrection, 'Use correctForNewDimensions() (and return true) to change the scroll offset during applyContentDimensions().'); + + if (_isMetricsChanged()) { + // It is too late to send useful notifications, because the potential + // listeners have, by definition, already been built this frame. To make + // sure the notification is sent at all, we delay it until after the frame + // is complete. + if (!_haveScheduledUpdateNotification) { + scheduleMicrotask(didUpdateScrollMetrics); + _haveScheduledUpdateNotification = true; + } + _lastMetrics = copyWith(); + } + return true; + } + + /// Verifies that the new content and viewport dimensions are acceptable. + /// + /// Called by [applyContentDimensions] to determine its return value. + /// + /// Should return true if the current scroll offset is correct given + /// the new content and viewport dimensions. + /// + /// Otherwise, should call [correctPixels] to correct the scroll + /// offset given the new dimensions, and then return false. + /// + /// This is only called when [haveDimensions] is true. + /// + /// The default implementation defers to [ScrollPhysics.adjustPositionForNewDimensions]. + @protected + bool correctForNewDimensions(ScrollMetrics oldPosition, ScrollMetrics newPosition) { + final double newPixels = physics.adjustPositionForNewDimensions( + oldPosition: oldPosition, + newPosition: newPosition, + isScrolling: activity!.isScrolling, + velocity: activity!.velocity, + ); + if (newPixels != pixels) { + correctPixels(newPixels); + return false; + } + return true; + } + + /// Notifies the activity that the dimensions of the underlying viewport or + /// contents have changed. + /// + /// Called after [applyViewportDimension] or [applyContentDimensions] have + /// changed the [minScrollExtent], the [maxScrollExtent], or the + /// [viewportDimension]. When this method is called, it should be called + /// _after_ any corrections are applied to [pixels] using [correctPixels], not + /// before. + /// + /// The default implementation informs the [activity] of the new dimensions by + /// calling its [ScrollActivity.applyNewDimensions] method. + /// + /// See also: + /// + /// * [applyViewportDimension], which is called when new + /// viewport dimensions are established. + /// * [applyContentDimensions], which is called after new + /// viewport dimensions are established, and also if new content dimensions + /// are established, and which calls [ScrollPosition.applyNewDimensions]. + @protected + @mustCallSuper + void applyNewDimensions() { + assert(hasPixels); + assert(_pendingDimensions); + activity!.applyNewDimensions(); + _updateSemanticActions(); // will potentially request a semantics update. + } + + Set<SemanticsAction>? _semanticActions; + + /// Called whenever the scroll position or the dimensions of the scroll view + /// change to schedule an update of the available semantics actions. The + /// actual update will be performed in the next frame. If non is pending + /// a frame will be scheduled. + /// + /// For example: If the scroll view has been scrolled all the way to the top, + /// the action to scroll further up needs to be removed as the scroll view + /// cannot be scrolled in that direction anymore. + /// + /// This method is potentially called twice per frame (if scroll position and + /// scroll view dimensions both change) and therefore shouldn't do anything + /// expensive. + void _updateSemanticActions() { + final SemanticsAction forward; + final SemanticsAction backward; + switch (axisDirection) { + case AxisDirection.up: + forward = SemanticsAction.scrollDown; + backward = SemanticsAction.scrollUp; + case AxisDirection.right: + forward = SemanticsAction.scrollLeft; + backward = SemanticsAction.scrollRight; + case AxisDirection.down: + forward = SemanticsAction.scrollUp; + backward = SemanticsAction.scrollDown; + case AxisDirection.left: + forward = SemanticsAction.scrollRight; + backward = SemanticsAction.scrollLeft; + } + + final Set<SemanticsAction> actions = <SemanticsAction>{}; + if (pixels > minScrollExtent) { + actions.add(backward); + } + if (pixels < maxScrollExtent) { + actions.add(forward); + } + + if (setEquals<SemanticsAction>(actions, _semanticActions)) { + return; + } + + _semanticActions = actions; + context.setSemanticsActions(_semanticActions!); + } + + ScrollPositionAlignmentPolicy _maybeFlipAlignment(ScrollPositionAlignmentPolicy alignmentPolicy) { + return switch (alignmentPolicy) { + // Don't flip when explicit. + ScrollPositionAlignmentPolicy.explicit => alignmentPolicy, + ScrollPositionAlignmentPolicy.keepVisibleAtEnd => ScrollPositionAlignmentPolicy.keepVisibleAtStart, + ScrollPositionAlignmentPolicy.keepVisibleAtStart => ScrollPositionAlignmentPolicy.keepVisibleAtEnd, + }; + } + + ScrollPositionAlignmentPolicy _applyAxisDirectionToAlignmentPolicy(ScrollPositionAlignmentPolicy alignmentPolicy) { + return switch (axisDirection) { + // Start and end alignments must account for axis direction. + // When focus is requested for example, it knows the directionality of the + // keyboard keys initiating traversal, but not the direction of the + // Scrollable. + AxisDirection.up || AxisDirection.left => _maybeFlipAlignment(alignmentPolicy), + AxisDirection.down || AxisDirection.right => alignmentPolicy, + }; + } + + /// Animates the position such that the given object is as visible as possible + /// by just scrolling this position. + /// + /// The optional `targetRenderObject` parameter is used to determine which area + /// of that object should be as visible as possible. If `targetRenderObject` + /// is null, the entire [RenderObject] (as defined by its + /// [RenderObject.paintBounds]) will be as visible as possible. If + /// `targetRenderObject` is provided, it must be a descendant of the object. + /// + /// See also: + /// + /// * [ScrollPositionAlignmentPolicy] for the way in which `alignment` is + /// applied, and the way the given `object` is aligned. + Future<void> ensureVisible( + RenderObject object, { + double alignment = 0.0, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit, + RenderObject? targetRenderObject, + }) async { + assert(object.attached); + final RenderAbstractViewport? viewport = RenderAbstractViewport.maybeOf(object); + // If no viewport is found, return. + if (viewport == null) { + return; + } + + Rect? targetRect; + if (targetRenderObject != null && targetRenderObject != object) { + targetRect = MatrixUtils.transformRect( + targetRenderObject.getTransformTo(object), + object.paintBounds.intersect(targetRenderObject.paintBounds), + ); + } + + double target; + switch (_applyAxisDirectionToAlignmentPolicy(alignmentPolicy)) { + case ScrollPositionAlignmentPolicy.explicit: + target = viewport.getOffsetToReveal( + object, + alignment, + rect: targetRect, + axis: axis, + ).offset; + target = clampDouble(target, minScrollExtent, maxScrollExtent); + case ScrollPositionAlignmentPolicy.keepVisibleAtEnd: + target = viewport.getOffsetToReveal( + object, + 1.0, // Aligns to end + rect: targetRect, + axis: axis, + ).offset; + target = clampDouble(target, minScrollExtent, maxScrollExtent); + if (target < pixels) { + target = pixels; + } + case ScrollPositionAlignmentPolicy.keepVisibleAtStart: + target = viewport.getOffsetToReveal( + object, + 0.0, // Aligns to start + rect: targetRect, + axis: axis, + ).offset; + target = clampDouble(target, minScrollExtent, maxScrollExtent); + if (target > pixels) { + target = pixels; + } + } + + if (target == pixels) { + return; + } + + if (duration == Duration.zero) { + jumpTo(target); + return; + } + + return animateTo(target, duration: duration, curve: curve); + } + + /// This notifier's value is true if a scroll is underway and false if the scroll + /// position is idle. + /// + /// Listeners added by stateful widgets should be removed in the widget's + /// [State.dispose] method. + final ValueNotifier<bool> isScrollingNotifier = ValueNotifier<bool>(false); + + /// Animates the position from its current value to the given value. + /// + /// Any active animation is canceled. If the user is currently scrolling, that + /// action is canceled. + /// + /// The returned [Future] will complete when the animation ends, whether it + /// completed successfully or whether it was interrupted prematurely. + /// + /// An animation will be interrupted whenever the user attempts to scroll + /// manually, or whenever another activity is started, or whenever the + /// animation reaches the edge of the viewport and attempts to overscroll. (If + /// the [ScrollPosition] does not overscroll but instead allows scrolling + /// beyond the extents, then going beyond the extents will not interrupt the + /// animation.) + /// + /// The animation is indifferent to changes to the viewport or content + /// dimensions. + /// + /// Once the animation has completed, the scroll position will attempt to + /// begin a ballistic activity in case its value is not stable (for example, + /// if it is scrolled beyond the extents and in that situation the scroll + /// position would normally bounce back). + /// + /// The duration must not be zero. To jump to a particular value without an + /// animation, use [jumpTo]. + /// + /// The animation is typically handled by an [DrivenScrollActivity]. + @override + Future<void> animateTo( + double to, { + required Duration duration, + required Curve curve, + }); + + /// Jumps the scroll position from its current value to the given value, + /// without animation, and without checking if the new value is in range. + /// + /// Any active animation is canceled. If the user is currently scrolling, that + /// action is canceled. + /// + /// If this method changes the scroll position, a sequence of start/update/end + /// scroll notifications will be dispatched. No overscroll notifications can + /// be generated by this method. + @override + void jumpTo(double value); + + /// Changes the scrolling position based on a pointer signal from current + /// value to delta without animation and without checking if new value is in + /// range, taking min/max scroll extent into account. + /// + /// Any active animation is canceled. If the user is currently scrolling, that + /// action is canceled. + /// + /// This method dispatches the start/update/end sequence of scrolling + /// notifications. + /// + /// This method is very similar to [jumpTo], but [pointerScroll] will + /// update the [ScrollDirection]. + void pointerScroll(double delta); + + /// Calls [jumpTo] if duration is null or [Duration.zero], otherwise + /// [animateTo] is called. + /// + /// If [clamp] is true (the default) then [to] is adjusted to prevent over or + /// underscroll. + /// + /// If [animateTo] is called then [curve] defaults to [Curves.ease]. + @override + Future<void> moveTo( + double to, { + Duration? duration, + Curve? curve, + bool? clamp = true, + }) { + assert(clamp != null); + + if (clamp!) { + to = clampDouble(to, minScrollExtent, maxScrollExtent); + } + + return super.moveTo(to, duration: duration, curve: curve); + } + + @override + bool get allowImplicitScrolling => physics.allowImplicitScrolling; + + /// Deprecated. Use [jumpTo] or a custom [ScrollPosition] instead. + @Deprecated('This will lead to bugs.') // flutter_ignore: deprecation_syntax, https://github.com/flutter/flutter/issues/44609 + void jumpToWithoutSettling(double value); + + /// Stop the current activity and start a [HoldScrollActivity]. + ScrollHoldController hold(VoidCallback holdCancelCallback); + + /// Start a drag activity corresponding to the given [DragStartDetails]. + /// + /// The `onDragCanceled` argument will be invoked if the drag is ended + /// prematurely (e.g. from another activity taking over). See + /// [ScrollDragController.onDragCanceled] for details. + Drag drag(DragStartDetails details, VoidCallback dragCancelCallback); + + /// The currently operative [ScrollActivity]. + /// + /// If the scroll position is not performing any more specific activity, the + /// activity will be an [IdleScrollActivity]. To determine whether the scroll + /// position is idle, check the [isScrollingNotifier]. + /// + /// Call [beginActivity] to change the current activity. + @protected + @visibleForTesting + ScrollActivity? get activity => _activity; + ScrollActivity? _activity; + + /// Change the current [activity], disposing of the old one and + /// sending scroll notifications as necessary. + /// + /// If the argument is null, this method has no effect. This is convenient for + /// cases where the new activity is obtained from another method, and that + /// method might return null, since it means the caller does not have to + /// explicitly null-check the argument. + void beginActivity(ScrollActivity? newActivity) { + if (newActivity == null) { + return; + } + bool wasScrolling, oldIgnorePointer; + if (_activity != null) { + oldIgnorePointer = _activity!.shouldIgnorePointer; + wasScrolling = _activity!.isScrolling; + if (wasScrolling && !newActivity.isScrolling) { + // Notifies and then saves the scroll offset. + didEndScroll(); + } + _activity!.dispose(); + } else { + oldIgnorePointer = false; + wasScrolling = false; + } + _activity = newActivity; + if (oldIgnorePointer != activity!.shouldIgnorePointer) { + context.setIgnorePointer(activity!.shouldIgnorePointer); + } + isScrollingNotifier.value = activity!.isScrolling; + if (!wasScrolling && _activity!.isScrolling) { + didStartScroll(); + } + } + + + // NOTIFICATION DISPATCH + + /// Called by [beginActivity] to report when an activity has started. + void didStartScroll() { + activity!.dispatchScrollStartNotification(copyWith(), context.notificationContext); + } + + /// Called by [setPixels] to report a change to the [pixels] position. + void didUpdateScrollPositionBy(double delta) { + activity!.dispatchScrollUpdateNotification(copyWith(), context.notificationContext!, delta); + } + + /// Called by [beginActivity] to report when an activity has ended. + /// + /// This also saves the scroll offset using [saveScrollOffset]. + void didEndScroll() { + activity!.dispatchScrollEndNotification(copyWith(), context.notificationContext!); + saveOffset(); + if (keepScrollOffset) { + saveScrollOffset(); + } + } + + /// Called by [setPixels] to report overscroll when an attempt is made to + /// change the [pixels] position. Overscroll is the amount of change that was + /// not applied to the [pixels] value. + void didOverscrollBy(double value) { + assert(activity!.isScrolling); + activity!.dispatchOverscrollNotification(copyWith(), context.notificationContext!, value); + } + + /// Dispatches a notification that the [userScrollDirection] has changed. + /// + /// Subclasses should call this function when they change [userScrollDirection]. + void didUpdateScrollDirection(ScrollDirection direction) { + UserScrollNotification(metrics: copyWith(), context: context.notificationContext!, direction: direction).dispatch(context.notificationContext); + } + + /// Dispatches a notification that the [ScrollMetrics] have changed. + void didUpdateScrollMetrics() { + assert(SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks); + assert(_haveScheduledUpdateNotification); + _haveScheduledUpdateNotification = false; + if (context.notificationContext != null) { + ScrollMetricsNotification(metrics: copyWith(), context: context.notificationContext!).dispatch(context.notificationContext); + } + } + + /// Provides a heuristic to determine if expensive frame-bound tasks should be + /// deferred. + /// + /// The actual work of this is delegated to the [physics] via + /// [ScrollPhysics.recommendDeferredLoading] called with the current + /// [activity]'s [ScrollActivity.velocity]. + /// + /// Returning true from this method indicates that the [ScrollPhysics] + /// evaluate the current scroll velocity to be great enough that expensive + /// operations impacting the UI should be deferred. + bool recommendDeferredLoading(BuildContext context) { + assert(activity != null); + return physics.recommendDeferredLoading( + activity!.velocity + _impliedVelocity, + copyWith(), + context, + ); + } + + @override + void dispose() { + activity?.dispose(); // it will be null if it got absorbed by another ScrollPosition + _activity = null; + isScrollingNotifier.dispose(); + super.dispose(); + } + + @override + void notifyListeners() { + _updateSemanticActions(); // will potentially request a semantics update. + super.notifyListeners(); + } + + @override + void debugFillDescription(List<String> description) { + if (debugLabel != null) { + description.add(debugLabel!); + } + super.debugFillDescription(description); + description.add('range: ${_minScrollExtent?.toStringAsFixed(1)}..${_maxScrollExtent?.toStringAsFixed(1)}'); + description.add('viewport: ${_viewportDimension?.toStringAsFixed(1)}'); + } +} + +/// A notification that a scrollable widget's [ScrollMetrics] have changed. +/// +/// For example, when the content of a scrollable is altered, making it larger +/// or smaller, this notification will be dispatched. Similarly, if the size +/// of the window or parent changes, the scrollable can notify of these +/// changes in dimensions. +/// +/// The above behaviors usually do not trigger [ScrollNotification] events, +/// so this is useful for listening to [ScrollMetrics] changes that are not +/// caused by the user scrolling. +/// +/// {@tool dartpad} +/// This sample shows how a [ScrollMetricsNotification] is dispatched when +/// the `windowSize` is changed. Press the floating action button to increase +/// the scrollable window's size. +/// +/// ** See code in examples/api/lib/widgets/scroll_position/scroll_metrics_notification.0.dart ** +/// {@end-tool} +class ScrollMetricsNotification extends Notification with ViewportNotificationMixin { + /// Creates a notification that the scrollable widget's [ScrollMetrics] have + /// changed. + ScrollMetricsNotification({ + required this.metrics, + required this.context, + }); + + /// Description of a scrollable widget's [ScrollMetrics]. + final ScrollMetrics metrics; + + /// The build context of the widget that fired this notification. + /// + /// This can be used to find the scrollable widget's render objects to + /// determine the size of the viewport, for instance. + final BuildContext context; + + /// Convert this notification to a [ScrollNotification]. + /// + /// This allows it to be used with [ScrollNotificationPredicate]s. + ScrollUpdateNotification asScrollUpdate() { + return ScrollUpdateNotification( + metrics: metrics, + context: context, + depth: depth, + ); + } + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + description.add('$metrics'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_position_with_single_context.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_position_with_single_context.dart new file mode 100644 index 0000000000000000000000000000000000000000..a48b0cdb8b0ca6fc8bf3c2c5f53d617940cdba2c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_position_with_single_context.dart @@ -0,0 +1,298 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/physics.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'scroll_activity.dart'; +import 'scroll_context.dart'; +import 'scroll_notification.dart'; +import 'scroll_physics.dart'; +import 'scroll_position.dart'; + +/// A scroll position that manages scroll activities for a single +/// [ScrollContext]. +/// +/// This class is a concrete subclass of [ScrollPosition] logic that handles a +/// single [ScrollContext], such as a [Scrollable]. An instance of this class +/// manages [ScrollActivity] instances, which change what content is visible in +/// the [Scrollable]'s [Viewport]. +/// +/// {@macro flutter.widgets.scrollPosition.listening} +/// +/// See also: +/// +/// * [ScrollPosition], which defines the underlying model for a position +/// within a [Scrollable] but is agnostic as to how that position is +/// changed. +/// * [ScrollView] and its subclasses such as [ListView], which use +/// [ScrollPositionWithSingleContext] to manage their scroll position. +/// * [ScrollController], which can manipulate one or more [ScrollPosition]s, +/// and which uses [ScrollPositionWithSingleContext] as its default class for +/// scroll positions. +class ScrollPositionWithSingleContext extends ScrollPosition implements ScrollActivityDelegate { + /// Create a [ScrollPosition] object that manages its behavior using + /// [ScrollActivity] objects. + /// + /// The `initialPixels` argument can be null, but in that case it is + /// imperative that the value be set, using [correctPixels], as soon as + /// [applyNewDimensions] is invoked, before calling the inherited + /// implementation of that method. + /// + /// If [keepScrollOffset] is true (the default), the current scroll offset is + /// saved with [PageStorage] and restored it if this scroll position's scrollable + /// is recreated. + ScrollPositionWithSingleContext({ + required super.physics, + required super.context, + double? initialPixels = 0.0, + super.keepScrollOffset, + super.oldPosition, + super.debugLabel, + }) { + // If oldPosition is not null, the superclass will first call absorb(), + // which may set _pixels and _activity. + if (!hasPixels && initialPixels != null) { + correctPixels(initialPixels); + } + if (activity == null) { + goIdle(); + } + assert(activity != null); + } + + /// Velocity from a previous activity temporarily held by [hold] to potentially + /// transfer to a next activity. + double _heldPreviousVelocity = 0.0; + + @override + AxisDirection get axisDirection => context.axisDirection; + + @override + double setPixels(double newPixels) { + assert(activity!.isScrolling); + return super.setPixels(newPixels); + } + + @override + void absorb(ScrollPosition other) { + super.absorb(other); + if (other is! ScrollPositionWithSingleContext) { + goIdle(); + return; + } + activity!.updateDelegate(this); + _userScrollDirection = other._userScrollDirection; + assert(_currentDrag == null); + if (other._currentDrag != null) { + _currentDrag = other._currentDrag; + _currentDrag!.updateDelegate(this); + other._currentDrag = null; + } + } + + @override + void applyNewDimensions() { + super.applyNewDimensions(); + context.setCanDrag(physics.shouldAcceptUserOffset(this)); + } + + @override + void beginActivity(ScrollActivity? newActivity) { + _heldPreviousVelocity = 0.0; + if (newActivity == null) { + return; + } + assert(newActivity.delegate == this); + super.beginActivity(newActivity); + _currentDrag?.dispose(); + _currentDrag = null; + if (!activity!.isScrolling) { + updateUserScrollDirection(ScrollDirection.idle); + } + } + + @override + void applyUserOffset(double delta) { + updateUserScrollDirection(delta > 0.0 ? ScrollDirection.forward : ScrollDirection.reverse); + setPixels(pixels - physics.applyPhysicsToUserOffset(this, delta)); + } + + @override + void goIdle() { + beginActivity(IdleScrollActivity(this)); + } + + /// Start a physics-driven simulation that settles the [pixels] position, + /// starting at a particular velocity. + /// + /// This method defers to [ScrollPhysics.createBallisticSimulation], which + /// typically provides a bounce simulation when the current position is out of + /// bounds and a friction simulation when the position is in bounds but has a + /// non-zero velocity. + /// + /// The velocity should be in logical pixels per second. + @override + void goBallistic(double velocity) { + assert(hasPixels); + final Simulation? simulation = physics.createBallisticSimulation(this, velocity); + if (simulation != null) { + beginActivity(BallisticScrollActivity( + this, + simulation, + context.vsync, + activity?.shouldIgnorePointer ?? true, + )); + } else { + goIdle(); + } + } + + @override + ScrollDirection get userScrollDirection => _userScrollDirection; + ScrollDirection _userScrollDirection = ScrollDirection.idle; + + /// Set [userScrollDirection] to the given value. + /// + /// If this changes the value, then a [UserScrollNotification] is dispatched. + @protected + @visibleForTesting + void updateUserScrollDirection(ScrollDirection value) { + if (userScrollDirection == value) { + return; + } + _userScrollDirection = value; + didUpdateScrollDirection(value); + } + + @override + Future<void> animateTo( + double to, { + required Duration duration, + required Curve curve, + }) { + if (nearEqual(to, pixels, physics.toleranceFor(this).distance)) { + // Skip the animation, go straight to the position as we are already close. + jumpTo(to); + return Future<void>.value(); + } + + final DrivenScrollActivity activity = DrivenScrollActivity( + this, + from: pixels, + to: to, + duration: duration, + curve: curve, + vsync: context.vsync, + ); + beginActivity(activity); + return activity.done; + } + + @override + void jumpTo(double value) { + goIdle(); + if (pixels != value) { + final double oldPixels = pixels; + forcePixels(value); + didStartScroll(); + didUpdateScrollPositionBy(pixels - oldPixels); + didEndScroll(); + } + goBallistic(0.0); + } + + @override + void pointerScroll(double delta) { + // If an update is made to pointer scrolling here, consider if the same + // (or similar) change should be made in + // _NestedScrollCoordinator.pointerScroll. + if (delta == 0.0) { + goBallistic(0.0); + return; + } + + final double targetPixels = + math.min(math.max(pixels + delta, minScrollExtent), maxScrollExtent); + if (targetPixels != pixels) { + goIdle(); + updateUserScrollDirection( + -delta > 0.0 ? ScrollDirection.forward : ScrollDirection.reverse, + ); + final double oldPixels = pixels; + // Set the notifier before calling force pixels. + // This is set to false again after going ballistic below. + isScrollingNotifier.value = true; + forcePixels(targetPixels); + didStartScroll(); + didUpdateScrollPositionBy(pixels - oldPixels); + didEndScroll(); + goBallistic(0.0); + } + } + + + @Deprecated('This will lead to bugs.') // flutter_ignore: deprecation_syntax, https://github.com/flutter/flutter/issues/44609 + @override + void jumpToWithoutSettling(double value) { + goIdle(); + if (pixels != value) { + final double oldPixels = pixels; + forcePixels(value); + didStartScroll(); + didUpdateScrollPositionBy(pixels - oldPixels); + didEndScroll(); + } + } + + @override + ScrollHoldController hold(VoidCallback holdCancelCallback) { + final double previousVelocity = activity!.velocity; + final HoldScrollActivity holdActivity = HoldScrollActivity( + delegate: this, + onHoldCanceled: holdCancelCallback, + ); + beginActivity(holdActivity); + _heldPreviousVelocity = previousVelocity; + return holdActivity; + } + + ScrollDragController? _currentDrag; + + @override + Drag drag(DragStartDetails details, VoidCallback dragCancelCallback) { + final ScrollDragController drag = ScrollDragController( + delegate: this, + details: details, + onDragCanceled: dragCancelCallback, + carriedVelocity: physics.carriedMomentum(_heldPreviousVelocity), + motionStartDistanceThreshold: physics.dragStartDistanceMotionThreshold, + ); + beginActivity(DragScrollActivity(this, drag)); + assert(_currentDrag == null); + _currentDrag = drag; + return drag; + } + + @override + void dispose() { + _currentDrag?.dispose(); + _currentDrag = null; + super.dispose(); + } + + @override + void debugFillDescription(List<String> description) { + super.debugFillDescription(description); + description.add('${context.runtimeType}'); + description.add('$physics'); + description.add('$activity'); + description.add('$userScrollDirection'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_simulation.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_simulation.dart new file mode 100644 index 0000000000000000000000000000000000000000..61cc18bc769eaa86c65fd094e7c74ea35cb5c490 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_simulation.dart @@ -0,0 +1,255 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/physics.dart'; + +/// An implementation of scroll physics that matches iOS. +/// +/// See also: +/// +/// * [ClampingScrollSimulation], which implements Android scroll physics. +class BouncingScrollSimulation extends Simulation { + /// Creates a simulation group for scrolling on iOS, with the given + /// parameters. + /// + /// The position and velocity arguments must use the same units as will be + /// expected from the [x] and [dx] methods respectively (typically logical + /// pixels and logical pixels per second respectively). + /// + /// The leading and trailing extents must use the unit of length, the same + /// unit as used for the position argument and as expected from the [x] + /// method (typically logical pixels). + /// + /// The units used with the provided [SpringDescription] must similarly be + /// consistent with the other arguments. A default set of constants is used + /// for the `spring` description if it is omitted; these defaults assume + /// that the unit of length is the logical pixel. + BouncingScrollSimulation({ + required double position, + required double velocity, + required this.leadingExtent, + required this.trailingExtent, + required this.spring, + double constantDeceleration = 0, + super.tolerance, + }) : assert(leadingExtent <= trailingExtent) { + if (position < leadingExtent) { + _springSimulation = _underscrollSimulation(position, velocity); + _springTime = double.negativeInfinity; + } else if (position > trailingExtent) { + _springSimulation = _overscrollSimulation(position, velocity); + _springTime = double.negativeInfinity; + } else { + // Taken from UIScrollView.decelerationRate (.normal = 0.998) + // 0.998^1000 = ~0.135 + _frictionSimulation = FrictionSimulation(0.135, position, velocity, constantDeceleration: constantDeceleration); + final double finalX = _frictionSimulation.finalX; + if (velocity > 0.0 && finalX > trailingExtent) { + _springTime = _frictionSimulation.timeAtX(trailingExtent); + _springSimulation = _overscrollSimulation( + trailingExtent, + math.min(_frictionSimulation.dx(_springTime), maxSpringTransferVelocity), + ); + assert(_springTime.isFinite); + } else if (velocity < 0.0 && finalX < leadingExtent) { + _springTime = _frictionSimulation.timeAtX(leadingExtent); + _springSimulation = _underscrollSimulation( + leadingExtent, + math.min(_frictionSimulation.dx(_springTime), maxSpringTransferVelocity), + ); + assert(_springTime.isFinite); + } else { + _springTime = double.infinity; + } + } + } + + /// The maximum velocity that can be transferred from the inertia of a ballistic + /// scroll into overscroll. + static const double maxSpringTransferVelocity = 5000.0; + + /// When [x] falls below this value the simulation switches from an internal friction + /// model to a spring model which causes [x] to "spring" back to [leadingExtent]. + final double leadingExtent; + + /// When [x] exceeds this value the simulation switches from an internal friction + /// model to a spring model which causes [x] to "spring" back to [trailingExtent]. + final double trailingExtent; + + /// The spring used to return [x] to either [leadingExtent] or [trailingExtent]. + final SpringDescription spring; + + late FrictionSimulation _frictionSimulation; + late Simulation _springSimulation; + late double _springTime; + double _timeOffset = 0.0; + + Simulation _underscrollSimulation(double x, double dx) { + return ScrollSpringSimulation(spring, x, leadingExtent, dx); + } + + Simulation _overscrollSimulation(double x, double dx) { + return ScrollSpringSimulation(spring, x, trailingExtent, dx); + } + + Simulation _simulation(double time) { + final Simulation simulation; + if (time > _springTime) { + _timeOffset = _springTime.isFinite ? _springTime : 0.0; + simulation = _springSimulation; + } else { + _timeOffset = 0.0; + simulation = _frictionSimulation; + } + return simulation..tolerance = tolerance; + } + + @override + double x(double time) => _simulation(time).x(time - _timeOffset); + + @override + double dx(double time) => _simulation(time).dx(time - _timeOffset); + + @override + bool isDone(double time) => _simulation(time).isDone(time - _timeOffset); + + @override + String toString() { + return '${objectRuntimeType(this, 'BouncingScrollSimulation')}(leadingExtent: $leadingExtent, trailingExtent: $trailingExtent)'; + } +} + +/// An implementation of scroll physics that aligns with Android. +/// +/// For any value of [velocity], this travels the same total distance as the +/// Android scroll physics. +/// +/// This scroll physics has been adjusted relative to Android's in order to make +/// it ballistic, meaning that the deceleration at any moment is a function only +/// of the current velocity [dx] and does not depend on how long ago the +/// simulation was started. (This is required by Flutter's scrolling protocol, +/// where [ScrollActivityDelegate.goBallistic] may restart a scroll activity +/// using only its current velocity and the scroll position's own state.) +/// Compared to this scroll physics, Android's moves faster at the very +/// beginning, then slower, and it ends at the same place but a little later. +/// +/// Times are measured in seconds, and positions in logical pixels. +/// +/// See also: +/// +/// * [BouncingScrollSimulation], which implements iOS scroll physics. +// +// This class is based on OverScroller.java from Android: +// https://android.googlesource.com/platform/frameworks/base/+/android-13.0.0_r24/core/java/android/widget/OverScroller.java#738 +// and in particular class SplineOverScroller (at the end of the file), starting +// at method "fling". (A very similar algorithm is in Scroller.java in the same +// directory, but OverScroller is what's used by RecyclerView.) +// +// In the Android implementation, times are in milliseconds, positions are in +// physical pixels, but velocity is in physical pixels per whole second. +// +// The "See..." comments below refer to SplineOverScroller methods and values. +class ClampingScrollSimulation extends Simulation { + /// Creates a scroll physics simulation that aligns with Android scrolling. + ClampingScrollSimulation({ + required this.position, + required this.velocity, + this.friction = 0.015, + super.tolerance, + }) { + _duration = _flingDuration(); + _distance = _flingDistance(); + } + + /// The position of the particle at the beginning of the simulation, in + /// logical pixels. + final double position; + + /// The velocity at which the particle is traveling at the beginning of the + /// simulation, in logical pixels per second. + final double velocity; + + /// The amount of friction the particle experiences as it travels. + /// + /// The more friction the particle experiences, the sooner it stops and the + /// less far it travels. + /// + /// The default value causes the particle to travel the same total distance + /// as in the Android scroll physics. + // See mFlingFriction. + final double friction; + + /// The total time the simulation will run, in seconds. + late double _duration; + + /// The total, signed, distance the simulation will travel, in logical pixels. + late double _distance; + + // See DECELERATION_RATE. + static final double _kDecelerationRate = math.log(0.78) / math.log(0.9); + + // See INFLEXION. + static const double _kInflexion = 0.35; + + // See mPhysicalCoeff. This has a value of 0.84 times Earth gravity, + // expressed in units of logical pixels per second^2. + static const double _physicalCoeff = + 9.80665 // g, in meters per second^2 + * 39.37 // 1 meter / 1 inch + * 160.0 // 1 inch / 1 logical pixel + * 0.84; // "look and feel tuning" + + // See getSplineFlingDuration(). + double _flingDuration() { + // See getSplineDeceleration(). That function's value is + // math.log(velocity.abs() / referenceVelocity). + final double referenceVelocity = friction * _physicalCoeff / _kInflexion; + + // This is the value getSplineFlingDuration() would return, but in seconds. + final double androidDuration = + math.pow(velocity.abs() / referenceVelocity, + 1 / (_kDecelerationRate - 1.0)) as double; + + // We finish a bit sooner than Android, in order to travel the + // same total distance. + return _kDecelerationRate * _kInflexion * androidDuration; + } + + // See getSplineFlingDistance(). This returns the same value but with the + // sign of [velocity], and in logical pixels. + double _flingDistance() { + final double distance = velocity * _duration / _kDecelerationRate; + assert(() { + // This is the more complicated calculation that getSplineFlingDistance() + // actually performs, which boils down to the much simpler formula above. + final double referenceVelocity = friction * _physicalCoeff / _kInflexion; + final double logVelocity = math.log(velocity.abs() / referenceVelocity); + final double distanceAgain = + friction * _physicalCoeff + * math.exp(logVelocity * _kDecelerationRate / (_kDecelerationRate - 1.0)); + return (distance.abs() - distanceAgain).abs() < tolerance.distance; + }()); + return distance; + } + + @override + double x(double time) { + final double t = clampDouble(time / _duration, 0.0, 1.0); + return position + _distance * (1.0 - math.pow(1.0 - t, _kDecelerationRate)); + } + + @override + double dx(double time) { + final double t = clampDouble(time / _duration, 0.0, 1.0); + return velocity * math.pow(1.0 - t, _kDecelerationRate - 1.0); + } + + @override + bool isDone(double time) { + return time >= _duration; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..067c69877f2a61c4569c0f9c6fc47d8c99529474 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scroll_view.dart @@ -0,0 +1,2076 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; +import 'media_query.dart'; +import 'notification_listener.dart'; +import 'primary_scroll_controller.dart'; +import 'scroll_configuration.dart'; +import 'scroll_controller.dart'; +import 'scroll_delegate.dart'; +import 'scroll_notification.dart'; +import 'scroll_physics.dart'; +import 'scrollable.dart'; +import 'scrollable_helpers.dart'; +import 'sliver.dart'; +import 'sliver_prototype_extent_list.dart'; +import 'sliver_varied_extent_list.dart'; +import 'viewport.dart'; + +// Examples can assume: +// late int itemCount; + +/// A representation of how a [ScrollView] should dismiss the on-screen +/// keyboard. +enum ScrollViewKeyboardDismissBehavior { + /// `manual` means there is no automatic dismissal of the on-screen keyboard. + /// It is up to the client to dismiss the keyboard. + manual, + /// `onDrag` means that the [ScrollView] will dismiss an on-screen keyboard + /// when a drag begins. + onDrag, +} + +/// A widget that combines a [Scrollable] and a [Viewport] to create an +/// interactive scrolling pane of content in one dimension. +/// +/// Scrollable widgets consist of three pieces: +/// +/// 1. A [Scrollable] widget, which listens for various user gestures and +/// implements the interaction design for scrolling. +/// 2. A viewport widget, such as [Viewport] or [ShrinkWrappingViewport], which +/// implements the visual design for scrolling by displaying only a portion +/// of the widgets inside the scroll view. +/// 3. One or more slivers, which are widgets that can be composed to created +/// various scrolling effects, such as lists, grids, and expanding headers. +/// +/// [ScrollView] helps orchestrate these pieces by creating the [Scrollable] and +/// the viewport and deferring to its subclass to create the slivers. +/// +/// To learn more about slivers, see [CustomScrollView.slivers]. +/// +/// To control the initial scroll offset of the scroll view, provide a +/// [controller] with its [ScrollController.initialScrollOffset] property set. +/// +/// {@template flutter.widgets.ScrollView.PageStorage} +/// ## Persisting the scroll position during a session +/// +/// Scroll views attempt to persist their scroll position using [PageStorage]. +/// This can be disabled by setting [ScrollController.keepScrollOffset] to false +/// on the [controller]. If it is enabled, using a [PageStorageKey] for the +/// [key] of this widget is recommended to help disambiguate different scroll +/// views from each other. +/// {@endtemplate} +/// +/// See also: +/// +/// * [ListView], which is a commonly used [ScrollView] that displays a +/// scrolling, linear list of child widgets. +/// * [PageView], which is a scrolling list of child widgets that are each the +/// size of the viewport. +/// * [GridView], which is a [ScrollView] that displays a scrolling, 2D array +/// of child widgets. +/// * [CustomScrollView], which is a [ScrollView] that creates custom scroll +/// effects using slivers. +/// * [ScrollNotification] and [NotificationListener], which can be used to watch +/// the scroll position without using a [ScrollController]. +/// * [TwoDimensionalScrollView], which is a similar widget [ScrollView] that +/// scrolls in two dimensions. +abstract class ScrollView extends StatelessWidget { + /// Creates a widget that scrolls. + /// + /// The [ScrollView.primary] argument defaults to true for vertical + /// scroll views if no [controller] has been provided. The [controller] argument + /// must be null if [primary] is explicitly set to true. If [primary] is true, + /// the nearest [PrimaryScrollController] surrounding the widget is attached + /// to this scroll view. + /// + /// If the [shrinkWrap] argument is true, the [center] argument must be null. + /// + /// The [anchor] argument must be in the range zero to one, inclusive. + const ScrollView({ + super.key, + this.scrollDirection = Axis.vertical, + this.reverse = false, + this.controller, + this.primary, + ScrollPhysics? physics, + this.scrollBehavior, + this.shrinkWrap = false, + this.center, + this.anchor = 0.0, + this.cacheExtent, + this.semanticChildCount, + this.dragStartBehavior = DragStartBehavior.start, + this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, + this.restorationId, + this.clipBehavior = Clip.hardEdge, + }) : assert( + !(controller != null && (primary ?? false)), + 'Primary ScrollViews obtain their ScrollController via inheritance ' + 'from a PrimaryScrollController widget. You cannot both set primary to ' + 'true and pass an explicit controller.', + ), + assert(!shrinkWrap || center == null), + assert(anchor >= 0.0 && anchor <= 1.0), + assert(semanticChildCount == null || semanticChildCount >= 0), + physics = physics ?? ((primary ?? false) || (primary == null && controller == null && identical(scrollDirection, Axis.vertical)) ? const AlwaysScrollableScrollPhysics() : null); + + /// {@template flutter.widgets.scroll_view.scrollDirection} + /// The [Axis] along which the scroll view's offset increases. + /// + /// For the direction in which active scrolling may be occurring, see + /// [ScrollDirection]. + /// + /// Defaults to [Axis.vertical]. + /// {@endtemplate} + final Axis scrollDirection; + + /// {@template flutter.widgets.scroll_view.reverse} + /// Whether the scroll view scrolls in the reading direction. + /// + /// For example, if the reading direction is left-to-right and + /// [scrollDirection] is [Axis.horizontal], then the scroll view scrolls from + /// left to right when [reverse] is false and from right to left when + /// [reverse] is true. + /// + /// Similarly, if [scrollDirection] is [Axis.vertical], then the scroll view + /// scrolls from top to bottom when [reverse] is false and from bottom to top + /// when [reverse] is true. + /// + /// Defaults to false. + /// {@endtemplate} + final bool reverse; + + /// {@template flutter.widgets.scroll_view.controller} + /// An object that can be used to control the position to which this scroll + /// view is scrolled. + /// + /// Must be null if [primary] is true. + /// + /// A [ScrollController] serves several purposes. It can be used to control + /// the initial scroll position (see [ScrollController.initialScrollOffset]). + /// It can be used to control whether the scroll view should automatically + /// save and restore its scroll position in the [PageStorage] (see + /// [ScrollController.keepScrollOffset]). It can be used to read the current + /// scroll position (see [ScrollController.offset]), or change it (see + /// [ScrollController.animateTo]). + /// {@endtemplate} + final ScrollController? controller; + + /// {@template flutter.widgets.scroll_view.primary} + /// Whether this is the primary scroll view associated with the parent + /// [PrimaryScrollController]. + /// + /// When this is true, the scroll view is scrollable even if it does not have + /// sufficient content to actually scroll. Otherwise, by default the user can + /// only scroll the view if it has sufficient content. See [physics]. + /// + /// Also when true, the scroll view is used for default [ScrollAction]s. If a + /// ScrollAction is not handled by an otherwise focused part of the application, + /// the ScrollAction will be evaluated using this scroll view, for example, + /// when executing [Shortcuts] key events like page up and down. + /// + /// On iOS, this also identifies the scroll view that will scroll to top in + /// response to a tap in the status bar. + /// + /// Cannot be true while a [ScrollController] is provided to `controller`, + /// only one ScrollController can be associated with a ScrollView. + /// + /// Setting to false will explicitly prevent inheriting any + /// [PrimaryScrollController]. + /// + /// Defaults to null. When null, and a controller is not provided, + /// [PrimaryScrollController.shouldInherit] is used to decide automatic + /// inheritance. + /// + /// By default, the [PrimaryScrollController] that is injected by each + /// [ModalRoute] is configured to automatically be inherited on + /// [TargetPlatformVariant.mobile] for ScrollViews in the [Axis.vertical] + /// scroll direction. Adding another to your app will override the + /// PrimaryScrollController above it. + /// + /// The following video contains more information about scroll controllers, + /// the PrimaryScrollController widget, and their impact on your apps: + /// + /// {@youtube 560 315 https://www.youtube.com/watch?v=33_0ABjFJUU} + /// + /// {@endtemplate} + final bool? primary; + + /// {@template flutter.widgets.scroll_view.physics} + /// How the scroll view should respond to user input. + /// + /// For example, determines how the scroll view continues to animate after the + /// user stops dragging the scroll view. + /// + /// Defaults to matching platform conventions. Furthermore, if [primary] is + /// false, then the user cannot scroll if there is insufficient content to + /// scroll, while if [primary] is true, they can always attempt to scroll. + /// + /// To force the scroll view to always be scrollable even if there is + /// insufficient content, as if [primary] was true but without necessarily + /// setting it to true, provide an [AlwaysScrollableScrollPhysics] physics + /// object, as in: + /// + /// ```dart + /// physics: const AlwaysScrollableScrollPhysics(), + /// ``` + /// + /// To force the scroll view to use the default platform conventions and not + /// be scrollable if there is insufficient content, regardless of the value of + /// [primary], provide an explicit [ScrollPhysics] object, as in: + /// + /// ```dart + /// physics: const ScrollPhysics(), + /// ``` + /// + /// The physics can be changed dynamically (by providing a new object in a + /// subsequent build), but new physics will only take effect if the _class_ of + /// the provided object changes. Merely constructing a new instance with a + /// different configuration is insufficient to cause the physics to be + /// reapplied. (This is because the final object used is generated + /// dynamically, which can be relatively expensive, and it would be + /// inefficient to speculatively create this object each frame to see if the + /// physics should be updated.) + /// {@endtemplate} + /// + /// If an explicit [ScrollBehavior] is provided to [scrollBehavior], the + /// [ScrollPhysics] provided by that behavior will take precedence after + /// [physics]. + final ScrollPhysics? physics; + + /// {@macro flutter.widgets.shadow.scrollBehavior} + /// + /// [ScrollBehavior]s also provide [ScrollPhysics]. If an explicit + /// [ScrollPhysics] is provided in [physics], it will take precedence, + /// followed by [scrollBehavior], and then the inherited ancestor + /// [ScrollBehavior]. + final ScrollBehavior? scrollBehavior; + + /// {@template flutter.widgets.scroll_view.shrinkWrap} + /// Whether the extent of the scroll view in the [scrollDirection] should be + /// determined by the contents being viewed. + /// + /// If the scroll view does not shrink wrap, then the scroll view will expand + /// to the maximum allowed size in the [scrollDirection]. If the scroll view + /// has unbounded constraints in the [scrollDirection], then [shrinkWrap] must + /// be true. + /// + /// Shrink wrapping the content of the scroll view is significantly more + /// expensive than expanding to the maximum allowed size because the content + /// can expand and contract during scrolling, which means the size of the + /// scroll view needs to be recomputed whenever the scroll position changes. + /// + /// Defaults to false. + /// + /// {@youtube 560 315 https://www.youtube.com/watch?v=LUqDNnv_dh0} + /// {@endtemplate} + final bool shrinkWrap; + + /// The first child in the [GrowthDirection.forward] growth direction. + /// + /// Children after [center] will be placed in the [AxisDirection] determined + /// by [scrollDirection] and [reverse] relative to the [center]. Children + /// before [center] will be placed in the opposite of the axis direction + /// relative to the [center]. This makes the [center] the inflection point of + /// the growth direction. + /// + /// The [center] must be the key of one of the slivers built by [buildSlivers]. + /// + /// Of the built-in subclasses of [ScrollView], only [CustomScrollView] + /// supports [center]; for that class, the given key must be the key of one of + /// the slivers in the [CustomScrollView.slivers] list. + /// + /// Most scroll views by default are ordered [GrowthDirection.forward]. + /// Changing the default values of [ScrollView.anchor], + /// [ScrollView.center], or both, can configure a scroll view for + /// [GrowthDirection.reverse]. + /// + /// {@tool dartpad} + /// This sample shows a [CustomScrollView], with [Radio] buttons in the + /// [AppBar.bottom] that change the [AxisDirection] to illustrate different + /// configurations. The [CustomScrollView.anchor] and [CustomScrollView.center] + /// properties are also set to have the 0 scroll offset positioned in the middle + /// of the viewport, with [GrowthDirection.forward] and [GrowthDirection.reverse] + /// illustrated on either side. The sliver that shares the + /// [CustomScrollView.center] key is positioned at the [CustomScrollView.anchor]. + /// + /// ** See code in examples/api/lib/rendering/growth_direction/growth_direction.0.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [anchor], which controls where the [center] as aligned in the viewport. + final Key? center; + + /// {@template flutter.widgets.scroll_view.anchor} + /// The relative position of the zero scroll offset. + /// + /// For example, if [anchor] is 0.5 and the [AxisDirection] determined by + /// [scrollDirection] and [reverse] is [AxisDirection.down] or + /// [AxisDirection.up], then the zero scroll offset is vertically centered + /// within the viewport. If the [anchor] is 1.0, and the axis direction is + /// [AxisDirection.right], then the zero scroll offset is on the left edge of + /// the viewport. + /// + /// Most scroll views by default are ordered [GrowthDirection.forward]. + /// Changing the default values of [ScrollView.anchor], + /// [ScrollView.center], or both, can configure a scroll view for + /// [GrowthDirection.reverse]. + /// + /// {@tool dartpad} + /// This sample shows a [CustomScrollView], with [Radio] buttons in the + /// [AppBar.bottom] that change the [AxisDirection] to illustrate different + /// configurations. The [CustomScrollView.anchor] and [CustomScrollView.center] + /// properties are also set to have the 0 scroll offset positioned in the middle + /// of the viewport, with [GrowthDirection.forward] and [GrowthDirection.reverse] + /// illustrated on either side. The sliver that shares the + /// [CustomScrollView.center] key is positioned at the [CustomScrollView.anchor]. + /// + /// ** See code in examples/api/lib/rendering/growth_direction/growth_direction.0.dart ** + /// {@end-tool} + /// {@endtemplate} + final double anchor; + + /// {@macro flutter.rendering.RenderViewportBase.cacheExtent} + final double? cacheExtent; + + /// The number of children that will contribute semantic information. + /// + /// Some subtypes of [ScrollView] can infer this value automatically. For + /// example [ListView] will use the number of widgets in the child list, + /// while the [ListView.separated] constructor will use half that amount. + /// + /// For [CustomScrollView] and other types which do not receive a builder + /// or list of widgets, the child count must be explicitly provided. If the + /// number is unknown or unbounded this should be left unset or set to null. + /// + /// See also: + /// + /// * [SemanticsConfiguration.scrollChildCount], the corresponding semantics property. + final int? semanticChildCount; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@template flutter.widgets.scroll_view.keyboardDismissBehavior} + /// [ScrollViewKeyboardDismissBehavior] the defines how this [ScrollView] will + /// dismiss the keyboard automatically. + /// {@endtemplate} + final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior; + + /// {@macro flutter.widgets.scrollable.restorationId} + final String? restorationId; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// Returns the [AxisDirection] in which the scroll view scrolls. + /// + /// Combines the [scrollDirection] with the [reverse] boolean to obtain the + /// concrete [AxisDirection]. + /// + /// If the [scrollDirection] is [Axis.horizontal], the ambient + /// [Directionality] is also considered when selecting the concrete + /// [AxisDirection]. For example, if the ambient [Directionality] is + /// [TextDirection.rtl], then the non-reversed [AxisDirection] is + /// [AxisDirection.left] and the reversed [AxisDirection] is + /// [AxisDirection.right]. + @protected + AxisDirection getDirection(BuildContext context) { + return getAxisDirectionFromAxisReverseAndDirectionality(context, scrollDirection, reverse); + } + + /// Build the list of widgets to place inside the viewport. + /// + /// Subclasses should override this method to build the slivers for the inside + /// of the viewport. + /// + /// To learn more about slivers, see [CustomScrollView.slivers]. + @protected + List<Widget> buildSlivers(BuildContext context); + + /// Build the viewport. + /// + /// Subclasses may override this method to change how the viewport is built. + /// The default implementation uses a [ShrinkWrappingViewport] if [shrinkWrap] + /// is true, and a regular [Viewport] otherwise. + /// + /// The `offset` argument is the value obtained from + /// [Scrollable.viewportBuilder]. + /// + /// The `axisDirection` argument is the value obtained from [getDirection], + /// which by default uses [scrollDirection] and [reverse]. + /// + /// The `slivers` argument is the value obtained from [buildSlivers]. + @protected + Widget buildViewport( + BuildContext context, + ViewportOffset offset, + AxisDirection axisDirection, + List<Widget> slivers, + ) { + assert(() { + switch (axisDirection) { + case AxisDirection.up: + case AxisDirection.down: + return debugCheckHasDirectionality( + context, + why: 'to determine the cross-axis direction of the scroll view', + hint: 'Vertical scroll views create Viewport widgets that try to determine their cross axis direction ' + 'from the ambient Directionality.', + ); + case AxisDirection.left: + case AxisDirection.right: + return true; + } + }()); + if (shrinkWrap) { + return ShrinkWrappingViewport( + axisDirection: axisDirection, + offset: offset, + slivers: slivers, + clipBehavior: clipBehavior, + ); + } + return Viewport( + axisDirection: axisDirection, + offset: offset, + slivers: slivers, + cacheExtent: cacheExtent, + center: center, + anchor: anchor, + clipBehavior: clipBehavior, + ); + } + + @override + Widget build(BuildContext context) { + final List<Widget> slivers = buildSlivers(context); + final AxisDirection axisDirection = getDirection(context); + + final bool effectivePrimary = primary + ?? controller == null && PrimaryScrollController.shouldInherit(context, scrollDirection); + + final ScrollController? scrollController = effectivePrimary + ? PrimaryScrollController.maybeOf(context) + : controller; + + final Scrollable scrollable = Scrollable( + dragStartBehavior: dragStartBehavior, + axisDirection: axisDirection, + controller: scrollController, + physics: physics, + scrollBehavior: scrollBehavior, + semanticChildCount: semanticChildCount, + restorationId: restorationId, + viewportBuilder: (BuildContext context, ViewportOffset offset) { + return buildViewport(context, offset, axisDirection, slivers); + }, + clipBehavior: clipBehavior, + ); + + final Widget scrollableResult = effectivePrimary && scrollController != null + // Further descendant ScrollViews will not inherit the same PrimaryScrollController + ? PrimaryScrollController.none(child: scrollable) + : scrollable; + + if (keyboardDismissBehavior == ScrollViewKeyboardDismissBehavior.onDrag) { + return NotificationListener<ScrollUpdateNotification>( + child: scrollableResult, + onNotification: (ScrollUpdateNotification notification) { + final FocusScopeNode focusScope = FocusScope.of(context); + if (notification.dragDetails != null && focusScope.hasFocus) { + focusScope.unfocus(); + } + return false; + }, + ); + } else { + return scrollableResult; + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<Axis>('scrollDirection', scrollDirection)); + properties.add(FlagProperty('reverse', value: reverse, ifTrue: 'reversed', showName: true)); + properties.add(DiagnosticsProperty<ScrollController>('controller', controller, showName: false, defaultValue: null)); + properties.add(FlagProperty('primary', value: primary, ifTrue: 'using primary controller', showName: true)); + properties.add(DiagnosticsProperty<ScrollPhysics>('physics', physics, showName: false, defaultValue: null)); + properties.add(FlagProperty('shrinkWrap', value: shrinkWrap, ifTrue: 'shrink-wrapping', showName: true)); + } +} + +/// A [ScrollView] that creates custom scroll effects using [slivers]. +/// +/// A [CustomScrollView] lets you supply [slivers] directly to create various +/// scrolling effects, such as lists, grids, and expanding headers. For example, +/// to create a scroll view that contains an expanding app bar followed by a +/// list and a grid, use a list of three slivers: [SliverAppBar], [SliverList], +/// and [SliverGrid]. +/// +/// [Widget]s in these [slivers] must produce [RenderSliver] objects. +/// +/// To control the initial scroll offset of the scroll view, provide a +/// [controller] with its [ScrollController.initialScrollOffset] property set. +/// +/// {@animation 400 376 https://flutter.github.io/assets-for-api-docs/assets/widgets/custom_scroll_view.mp4} +/// +/// {@tool snippet} +/// +/// This sample code shows a scroll view that contains a flexible pinned app +/// bar, a grid, and an infinite list. +/// +/// ```dart +/// CustomScrollView( +/// slivers: <Widget>[ +/// const SliverAppBar( +/// pinned: true, +/// expandedHeight: 250.0, +/// flexibleSpace: FlexibleSpaceBar( +/// title: Text('Demo'), +/// ), +/// ), +/// SliverGrid( +/// gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( +/// maxCrossAxisExtent: 200.0, +/// mainAxisSpacing: 10.0, +/// crossAxisSpacing: 10.0, +/// childAspectRatio: 4.0, +/// ), +/// delegate: SliverChildBuilderDelegate( +/// (BuildContext context, int index) { +/// return Container( +/// alignment: Alignment.center, +/// color: Colors.teal[100 * (index % 9)], +/// child: Text('Grid Item $index'), +/// ); +/// }, +/// childCount: 20, +/// ), +/// ), +/// SliverFixedExtentList( +/// itemExtent: 50.0, +/// delegate: SliverChildBuilderDelegate( +/// (BuildContext context, int index) { +/// return Container( +/// alignment: Alignment.center, +/// color: Colors.lightBlue[100 * (index % 9)], +/// child: Text('List Item $index'), +/// ); +/// }, +/// ), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool dartpad} +/// By default, if items are inserted at the "top" of a scrolling container like +/// [ListView] or [CustomScrollView], the top item and all of the items below it +/// are scrolled downwards. In some applications, it's preferable to have the +/// top of the list just grow upwards, without changing the scroll position. +/// This example demonstrates how to do that with a [CustomScrollView] with +/// two [SliverList] children, and the [CustomScrollView.center] set to the key +/// of the bottom SliverList. The top one SliverList will grow upwards, and the +/// bottom SliverList will grow downwards. +/// +/// ** See code in examples/api/lib/widgets/scroll_view/custom_scroll_view.1.dart ** +/// {@end-tool} +/// +/// ## Accessibility +/// +/// A [CustomScrollView] can allow Talkback/VoiceOver to make announcements +/// to the user when the scroll state changes. For example, on Android an +/// announcement might be read as "showing items 1 to 10 of 23". To produce +/// this announcement, the scroll view needs three pieces of information: +/// +/// * The first visible child index. +/// * The total number of children. +/// * The total number of visible children. +/// +/// The last value can be computed exactly by the framework, however the first +/// two must be provided. Most of the higher-level scrollable widgets provide +/// this information automatically. For example, [ListView] provides each child +/// widget with a semantic index automatically and sets the semantic child +/// count to the length of the list. +/// +/// To determine visible indexes, the scroll view needs a way to associate the +/// generated semantics of each scrollable item with a semantic index. This can +/// be done by wrapping the child widgets in an [IndexedSemantics]. +/// +/// This semantic index is not necessarily the same as the index of the widget in +/// the scrollable, because some widgets may not contribute semantic +/// information. Consider a [ListView.separated]: every other widget is a +/// divider with no semantic information. In this case, only odd numbered +/// widgets have a semantic index (equal to the index ~/ 2). Furthermore, the +/// total number of children in this example would be half the number of +/// widgets. (The [ListView.separated] constructor handles this +/// automatically; this is only used here as an example.) +/// +/// The total number of visible children can be provided by the constructor +/// parameter `semanticChildCount`. This should always be the same as the +/// number of widgets wrapped in [IndexedSemantics]. +/// +/// {@macro flutter.widgets.ScrollView.PageStorage} +/// +/// See also: +/// +/// * [SliverList], which is a sliver that displays linear list of children. +/// * [SliverFixedExtentList], which is a more efficient sliver that displays +/// linear list of children that have the same extent along the scroll axis. +/// * [SliverGrid], which is a sliver that displays a 2D array of children. +/// * [SliverPadding], which is a sliver that adds blank space around another +/// sliver. +/// * [SliverAppBar], which is a sliver that displays a header that can expand +/// and float as the scroll view scrolls. +/// * [ScrollNotification] and [NotificationListener], which can be used to watch +/// the scroll position without using a [ScrollController]. +/// * [IndexedSemantics], which allows annotating child lists with an index +/// for scroll announcements. +class CustomScrollView extends ScrollView { + /// Creates a [ScrollView] that creates custom scroll effects using slivers. + /// + /// See the [ScrollView] constructor for more details on these arguments. + const CustomScrollView({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.scrollBehavior, + super.shrinkWrap, + super.center, + super.anchor, + super.cacheExtent, + this.slivers = const <Widget>[], + super.semanticChildCount, + super.dragStartBehavior, + super.keyboardDismissBehavior, + super.restorationId, + super.clipBehavior, + }); + + /// The slivers to place inside the viewport. + /// + /// ## What is a sliver? + /// + /// > _**sliver** (noun): a small, thin piece of something._ + /// + /// A _sliver_ is a widget backed by a [RenderSliver] subclass, i.e. one that + /// implements the constraint/geometry protocol that uses [SliverConstraints] + /// and [SliverGeometry]. + /// + /// This is as distinct from those widgets that are backed by [RenderBox] + /// subclasses, which use [BoxConstraints] and [Size] respectively, and are + /// known as box widgets. (Widgets like [Container], [Row], and [SizedBox] are + /// box widgets.) + /// + /// While boxes are much more straightforward (implementing a simple + /// two-dimensional Cartesian layout system), slivers are much more powerful, + /// and are optimized for one-axis scrolling environments. + /// + /// Slivers are hosted in viewports, also known as scroll views, most notably + /// [CustomScrollView]. + /// + /// ## Examples of slivers + /// + /// The Flutter framework has many built-in sliver widgets, and custom widgets + /// can be created in the same manner. By convention, sliver widgets always + /// start with the prefix `Sliver` and are always used in properties called + /// `sliver` or `slivers` (as opposed to `child` and `children` which are used + /// for box widgets). + /// + /// Examples of widgets unique to the sliver world include: + /// + /// * [SliverList], a lazily-loading list of variably-sized box widgets. + /// * [SliverFixedExtentList], a lazily-loading list of box widgets that are + /// all forced to the same height. + /// * [SliverPrototypeExtentList], a lazily-loading list of box widgets that + /// are all forced to the same height as a given prototype widget. + /// * [SliverGrid], a lazily-loading grid of box widgets. + /// * [SliverAnimatedList] and [SliverAnimatedGrid], animated variants of + /// [SliverList] and [SliverGrid]. + /// * [SliverFillRemaining], a widget that fills all remaining space in a + /// scroll view, and lays a box widget out inside that space. + /// * [SliverFillViewport], a widget that lays a list of boxes out, each + /// being sized to fit the whole viewport. + /// * [SliverPersistentHeader], a sliver that implements pinned and floating + /// headers, e.g. used to implement [SliverAppBar]. + /// * [SliverToBoxAdapter], a sliver that wraps a box widget. + /// + /// Examples of sliver variants of common box widgets include: + /// + /// * [SliverOpacity], [SliverAnimatedOpacity], and [SliverFadeTransition], + /// sliver versions of [Opacity], [AnimatedOpacity], and [FadeTransition]. + /// * [SliverIgnorePointer], a sliver version of [IgnorePointer]. + /// * [SliverLayoutBuilder], a sliver version of [LayoutBuilder]. + /// * [SliverOffstage], a sliver version of [Offstage]. + /// * [SliverPadding], a sliver version of [Padding]. + /// * [SliverReorderableList], a sliver version of [ReorderableList] + /// * [SliverSafeArea], a sliver version of [SafeArea]. + /// * [SliverVisibility], a sliver version of [Visibility]. + /// + /// ## Benefits of slivers over boxes + /// + /// The sliver protocol ([SliverConstraints] and [SliverGeometry]) enables + /// _scroll effects_, such as floating app bars, widgets that expand and + /// shrink during scroll, section headers that are pinned only while the + /// section's children are visible, etc. + /// + /// {@youtube 560 315 https://www.youtube.com/watch?v=Mz3kHQxBjGg} + /// + /// ## Mixing slivers and boxes + /// + /// In general, slivers always wrap box widgets to actually render anything + /// (for example, there is no sliver equivalent of [Text] or [Container]); + /// the sliver part of the equation is mostly about how these boxes should + /// be laid out in a viewport (i.e. when scrolling). + /// + /// Typically, the simplest way to combine boxes into a sliver environment is + /// to use a [SliverList] (maybe using a [ListView, which is a convenient + /// combination of a [CustomScrollView] and a [SliverList]). In rare cases, + /// e.g. if a single [Divider] widget is needed between two [SliverGrid]s, + /// a [SliverToBoxAdapter] can be used to wrap the box widgets. + /// + /// ## Performance considerations + /// + /// Because the purpose of scroll views is to, well, scroll, it is common + /// for scroll views to contain more contents than are rendered on the screen + /// at any particular time. + /// + /// To improve the performance of scroll views, the content can be rendered in + /// _lazy_ widgets, notably [SliverList] and [SliverGrid] (and their variants, + /// such as [SliverFixedExtentList] and [SliverAnimatedGrid]). These widgets + /// ensure that only the portion of their child lists that are actually + /// visible get built, laid out, and painted. + /// + /// The [ListView] and [GridView] widgets provide a convenient way to combine + /// a [CustomScrollView] and a [SliverList] or [SliverGrid] (respectively). + final List<Widget> slivers; + + @override + List<Widget> buildSlivers(BuildContext context) => slivers; +} + +/// A [ScrollView] that uses a single child layout model. +/// +/// {@template flutter.widgets.BoxScroll.scrollBehaviour} +/// [ScrollView]s are often decorated with [Scrollbar]s and overscroll indicators, +/// which are managed by the inherited [ScrollBehavior]. Placing a +/// [ScrollConfiguration] above a ScrollView can modify these behaviors for that +/// ScrollView, or can be managed app-wide by providing a ScrollBehavior to +/// [MaterialApp.scrollBehavior] or [CupertinoApp.scrollBehavior]. +/// {@endtemplate} +/// +/// See also: +/// +/// * [ListView], which is a [BoxScrollView] that uses a linear layout model. +/// * [GridView], which is a [BoxScrollView] that uses a 2D layout model. +/// * [CustomScrollView], which can combine multiple child layout models into a +/// single scroll view. +abstract class BoxScrollView extends ScrollView { + /// Creates a [ScrollView] uses a single child layout model. + /// + /// If the [primary] argument is true, the [controller] must be null. + const BoxScrollView({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.shrinkWrap, + this.padding, + super.cacheExtent, + super.semanticChildCount, + super.dragStartBehavior, + super.keyboardDismissBehavior, + super.restorationId, + super.clipBehavior, + }); + + /// The amount of space by which to inset the children. + final EdgeInsetsGeometry? padding; + + @override + List<Widget> buildSlivers(BuildContext context) { + Widget sliver = buildChildLayout(context); + EdgeInsetsGeometry? effectivePadding = padding; + if (padding == null) { + final MediaQueryData? mediaQuery = MediaQuery.maybeOf(context); + if (mediaQuery != null) { + // Automatically pad sliver with padding from MediaQuery. + final EdgeInsets mediaQueryHorizontalPadding = + mediaQuery.padding.copyWith(top: 0.0, bottom: 0.0); + final EdgeInsets mediaQueryVerticalPadding = + mediaQuery.padding.copyWith(left: 0.0, right: 0.0); + // Consume the main axis padding with SliverPadding. + effectivePadding = scrollDirection == Axis.vertical + ? mediaQueryVerticalPadding + : mediaQueryHorizontalPadding; + // Leave behind the cross axis padding. + sliver = MediaQuery( + data: mediaQuery.copyWith( + padding: scrollDirection == Axis.vertical + ? mediaQueryHorizontalPadding + : mediaQueryVerticalPadding, + ), + child: sliver, + ); + } + } + + if (effectivePadding != null) { + sliver = SliverPadding(padding: effectivePadding, sliver: sliver); + } + return <Widget>[ sliver ]; + } + + /// Subclasses should override this method to build the layout model. + @protected + Widget buildChildLayout(BuildContext context); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); + } +} + +/// A scrollable list of widgets arranged linearly. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=KJpkjHGiI5A} +/// +/// [ListView] is the most commonly used scrolling widget. It displays its +/// children one after another in the scroll direction. In the cross axis, the +/// children are required to fill the [ListView]. +/// +/// If non-null, the [itemExtent] forces the children to have the given extent +/// in the scroll direction. +/// +/// If non-null, the [prototypeItem] forces the children to have the same extent +/// as the given widget in the scroll direction. +/// +/// Specifying an [itemExtent] or an [prototypeItem] is more efficient than +/// letting the children determine their own extent because the scrolling +/// machinery can make use of the foreknowledge of the children's extent to save +/// work, for example when the scroll position changes drastically. +/// +/// You can't specify both [itemExtent] and [prototypeItem], only one or none of +/// them. +/// +/// There are four options for constructing a [ListView]: +/// +/// 1. The default constructor takes an explicit [List<Widget>] of children. This +/// constructor is appropriate for list views with a small number of +/// children because constructing the [List] requires doing work for every +/// child that could possibly be displayed in the list view instead of just +/// those children that are actually visible. +/// +/// 2. The [ListView.builder] constructor takes an [IndexedWidgetBuilder], which +/// builds the children on demand. This constructor is appropriate for list views +/// with a large (or infinite) number of children because the builder is called +/// only for those children that are actually visible. +/// +/// 3. The [ListView.separated] constructor takes two [IndexedWidgetBuilder]s: +/// `itemBuilder` builds child items on demand, and `separatorBuilder` +/// similarly builds separator children which appear in between the child items. +/// This constructor is appropriate for list views with a fixed number of children. +/// +/// 4. The [ListView.custom] constructor takes a [SliverChildDelegate], which provides +/// the ability to customize additional aspects of the child model. For example, +/// a [SliverChildDelegate] can control the algorithm used to estimate the +/// size of children that are not actually visible. +/// +/// To control the initial scroll offset of the scroll view, provide a +/// [controller] with its [ScrollController.initialScrollOffset] property set. +/// +/// By default, [ListView] will automatically pad the list's scrollable +/// extremities to avoid partial obstructions indicated by [MediaQuery]'s +/// padding. To avoid this behavior, override with a zero [padding] property. +/// +/// {@tool snippet} +/// This example uses the default constructor for [ListView] which takes an +/// explicit [List<Widget>] of children. This [ListView]'s children are made up +/// of [Container]s with [Text]. +/// +/// ![A ListView of 3 amber colored containers with sample text.](https://flutter.github.io/assets-for-api-docs/assets/widgets/list_view.png) +/// +/// ```dart +/// ListView( +/// padding: const EdgeInsets.all(8), +/// children: <Widget>[ +/// Container( +/// height: 50, +/// color: Colors.amber[600], +/// child: const Center(child: Text('Entry A')), +/// ), +/// Container( +/// height: 50, +/// color: Colors.amber[500], +/// child: const Center(child: Text('Entry B')), +/// ), +/// Container( +/// height: 50, +/// color: Colors.amber[100], +/// child: const Center(child: Text('Entry C')), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// This example mirrors the previous one, creating the same list using the +/// [ListView.builder] constructor. Using the [IndexedWidgetBuilder], children +/// are built lazily and can be infinite in number. +/// +/// ![A ListView of 3 amber colored containers with sample text.](https://flutter.github.io/assets-for-api-docs/assets/widgets/list_view_builder.png) +/// +/// ```dart +/// final List<String> entries = <String>['A', 'B', 'C']; +/// final List<int> colorCodes = <int>[600, 500, 100]; +/// +/// Widget build(BuildContext context) { +/// return ListView.builder( +/// padding: const EdgeInsets.all(8), +/// itemCount: entries.length, +/// itemBuilder: (BuildContext context, int index) { +/// return Container( +/// height: 50, +/// color: Colors.amber[colorCodes[index]], +/// child: Center(child: Text('Entry ${entries[index]}')), +/// ); +/// } +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// This example continues to build from our the previous ones, creating a +/// similar list using [ListView.separated]. Here, a [Divider] is used as a +/// separator. +/// +/// ![A ListView of 3 amber colored containers with sample text and a Divider +/// between each of them.](https://flutter.github.io/assets-for-api-docs/assets/widgets/list_view_separated.png) +/// +/// ```dart +/// final List<String> entries = <String>['A', 'B', 'C']; +/// final List<int> colorCodes = <int>[600, 500, 100]; +/// +/// Widget build(BuildContext context) { +/// return ListView.separated( +/// padding: const EdgeInsets.all(8), +/// itemCount: entries.length, +/// itemBuilder: (BuildContext context, int index) { +/// return Container( +/// height: 50, +/// color: Colors.amber[colorCodes[index]], +/// child: Center(child: Text('Entry ${entries[index]}')), +/// ); +/// }, +/// separatorBuilder: (BuildContext context, int index) => const Divider(), +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// ## Child elements' lifecycle +/// +/// ### Creation +/// +/// While laying out the list, visible children's elements, states and render +/// objects will be created lazily based on existing widgets (such as when using +/// the default constructor) or lazily provided ones (such as when using the +/// [ListView.builder] constructor). +/// +/// ### Destruction +/// +/// When a child is scrolled out of view, the associated element subtree, +/// states and render objects are destroyed. A new child at the same position +/// in the list will be lazily recreated along with new elements, states and +/// render objects when it is scrolled back. +/// +/// ### Destruction mitigation +/// +/// In order to preserve state as child elements are scrolled in and out of +/// view, the following options are possible: +/// +/// * Moving the ownership of non-trivial UI-state-driving business logic +/// out of the list child subtree. For instance, if a list contains posts +/// with their number of upvotes coming from a cached network response, store +/// the list of posts and upvote number in a data model outside the list. Let +/// the list child UI subtree be easily recreate-able from the +/// source-of-truth model object. Use [StatefulWidget]s in the child +/// widget subtree to store instantaneous UI state only. +/// +/// * Letting [KeepAlive] be the root widget of the list child widget subtree +/// that needs to be preserved. The [KeepAlive] widget marks the child +/// subtree's top render object child for keepalive. When the associated top +/// render object is scrolled out of view, the list keeps the child's render +/// object (and by extension, its associated elements and states) in a cache +/// list instead of destroying them. When scrolled back into view, the render +/// object is repainted as-is (if it wasn't marked dirty in the interim). +/// +/// This only works if `addAutomaticKeepAlives` and `addRepaintBoundaries` +/// are false since those parameters cause the [ListView] to wrap each child +/// widget subtree with other widgets. +/// +/// * Using [AutomaticKeepAlive] widgets (inserted by default when +/// `addAutomaticKeepAlives` is true). [AutomaticKeepAlive] allows descendant +/// widgets to control whether the subtree is actually kept alive or not. +/// This behavior is in contrast with [KeepAlive], which will unconditionally keep +/// the subtree alive. +/// +/// As an example, the [EditableText] widget signals its list child element +/// subtree to stay alive while its text field has input focus. If it doesn't +/// have focus and no other descendants signaled for keepalive via a +/// [KeepAliveNotification], the list child element subtree will be destroyed +/// when scrolled away. +/// +/// [AutomaticKeepAlive] descendants typically signal it to be kept alive +/// by using the [AutomaticKeepAliveClientMixin], then implementing the +/// [AutomaticKeepAliveClientMixin.wantKeepAlive] getter and calling +/// [AutomaticKeepAliveClientMixin.updateKeepAlive]. +/// +/// ## Transitioning to [CustomScrollView] +/// +/// A [ListView] is basically a [CustomScrollView] with a single [SliverList] in +/// its [CustomScrollView.slivers] property. +/// +/// If [ListView] is no longer sufficient, for example because the scroll view +/// is to have both a list and a grid, or because the list is to be combined +/// with a [SliverAppBar], etc, it is straight-forward to port code from using +/// [ListView] to using [CustomScrollView] directly. +/// +/// The [key], [scrollDirection], [reverse], [controller], [primary], [physics], +/// and [shrinkWrap] properties on [ListView] map directly to the identically +/// named properties on [CustomScrollView]. +/// +/// The [CustomScrollView.slivers] property should be a list containing either: +/// * a [SliverList] if both [itemExtent] and [prototypeItem] were null; +/// * a [SliverFixedExtentList] if [itemExtent] was not null; or +/// * a [SliverPrototypeExtentList] if [prototypeItem] was not null. +/// +/// The [childrenDelegate] property on [ListView] corresponds to the +/// [SliverList.delegate] (or [SliverFixedExtentList.delegate]) property. The +/// [ListView] constructor's `children` argument corresponds to the +/// [childrenDelegate] being a [SliverChildListDelegate] with that same +/// argument. The [ListView.builder] constructor's `itemBuilder` and +/// `itemCount` arguments correspond to the [childrenDelegate] being a +/// [SliverChildBuilderDelegate] with the equivalent arguments. +/// +/// The [padding] property corresponds to having a [SliverPadding] in the +/// [CustomScrollView.slivers] property instead of the list itself, and having +/// the [SliverList] instead be a child of the [SliverPadding]. +/// +/// [CustomScrollView]s don't automatically avoid obstructions from [MediaQuery] +/// like [ListView]s do. To reproduce the behavior, wrap the slivers in +/// [SliverSafeArea]s. +/// +/// Once code has been ported to use [CustomScrollView], other slivers, such as +/// [SliverGrid] or [SliverAppBar], can be put in the [CustomScrollView.slivers] +/// list. +/// +/// {@tool snippet} +/// +/// Here are two brief snippets showing a [ListView] and its equivalent using +/// [CustomScrollView]: +/// +/// ```dart +/// ListView( +/// padding: const EdgeInsets.all(20.0), +/// children: const <Widget>[ +/// Text("I'm dedicating every day to you"), +/// Text('Domestic life was never quite my style'), +/// Text('When you smile, you knock me out, I fall apart'), +/// Text('And I thought I was so smart'), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// {@tool snippet} +/// +/// ```dart +/// CustomScrollView( +/// slivers: <Widget>[ +/// SliverPadding( +/// padding: const EdgeInsets.all(20.0), +/// sliver: SliverList( +/// delegate: SliverChildListDelegate( +/// <Widget>[ +/// const Text("I'm dedicating every day to you"), +/// const Text('Domestic life was never quite my style'), +/// const Text('When you smile, you knock me out, I fall apart'), +/// const Text('And I thought I was so smart'), +/// ], +/// ), +/// ), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Special handling for an empty list +/// +/// A common design pattern is to have a custom UI for an empty list. The best +/// way to achieve this in Flutter is just conditionally replacing the +/// [ListView] at build time with whatever widgets you need to show for the +/// empty list state: +/// +/// {@tool snippet} +/// +/// Example of simple empty list interface: +/// +/// ```dart +/// Widget build(BuildContext context) { +/// return Scaffold( +/// appBar: AppBar(title: const Text('Empty List Test')), +/// body: itemCount > 0 +/// ? ListView.builder( +/// itemCount: itemCount, +/// itemBuilder: (BuildContext context, int index) { +/// return ListTile( +/// title: Text('Item ${index + 1}'), +/// ); +/// }, +/// ) +/// : const Center(child: Text('No items')), +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// ## Selection of list items +/// +/// [ListView] has no built-in notion of a selected item or items. For a small +/// example of how a caller might wire up basic item selection, see +/// [ListTile.selected]. +/// +/// {@tool dartpad} +/// This example shows a custom implementation of [ListTile] selection in a [ListView] or [GridView]. +/// Long press any [ListTile] to enable selection mode. +/// +/// ** See code in examples/api/lib/widgets/scroll_view/list_view.0.dart ** +/// {@end-tool} +/// +/// {@macro flutter.widgets.BoxScroll.scrollBehaviour} +/// +/// {@macro flutter.widgets.ScrollView.PageStorage} +/// +/// See also: +/// +/// * [SingleChildScrollView], which is a scrollable widget that has a single +/// child. +/// * [PageView], which is a scrolling list of child widgets that are each the +/// size of the viewport. +/// * [GridView], which is a scrollable, 2D array of widgets. +/// * [CustomScrollView], which is a scrollable widget that creates custom +/// scroll effects using slivers. +/// * [ListBody], which arranges its children in a similar manner, but without +/// scrolling. +/// * [ScrollNotification] and [NotificationListener], which can be used to watch +/// the scroll position without using a [ScrollController]. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +/// * Cookbook: [Use lists](https://flutter.dev/docs/cookbook/lists/basic-list) +/// * Cookbook: [Work with long lists](https://flutter.dev/docs/cookbook/lists/long-lists) +/// * Cookbook: [Create a horizontal list](https://flutter.dev/docs/cookbook/lists/horizontal-list) +/// * Cookbook: [Create lists with different types of items](https://flutter.dev/docs/cookbook/lists/mixed-list) +/// * Cookbook: [Implement swipe to dismiss](https://flutter.dev/docs/cookbook/gestures/dismissible) +class ListView extends BoxScrollView { + /// Creates a scrollable, linear array of widgets from an explicit [List]. + /// + /// This constructor is appropriate for list views with a small number of + /// children because constructing the [List] requires doing work for every + /// child that could possibly be displayed in the list view instead of just + /// those children that are actually visible. + /// + /// Like other widgets in the framework, this widget expects that + /// the [children] list will not be mutated after it has been passed in here. + /// See the documentation at [SliverChildListDelegate.children] for more details. + /// + /// It is usually more efficient to create children on demand using + /// [ListView.builder] because it will create the widget children lazily as necessary. + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildListDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildListDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildListDelegate.addSemanticIndexes] property. None + /// may be null. + ListView({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.shrinkWrap, + super.padding, + this.itemExtent, + this.itemExtentBuilder, + this.prototypeItem, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + super.cacheExtent, + List<Widget> children = const <Widget>[], + int? semanticChildCount, + super.dragStartBehavior, + super.keyboardDismissBehavior, + super.restorationId, + super.clipBehavior, + }) : assert( + (itemExtent == null && prototypeItem == null) || + (itemExtent == null && itemExtentBuilder == null) || + (prototypeItem == null && itemExtentBuilder == null), + 'You can only pass one of itemExtent, prototypeItem and itemExtentBuilder.', + ), + childrenDelegate = SliverChildListDelegate( + children, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + ), + super( + semanticChildCount: semanticChildCount ?? children.length, + ); + + /// Creates a scrollable, linear array of widgets that are created on demand. + /// + /// This constructor is appropriate for list views with a large (or infinite) + /// number of children because the builder is called only for those children + /// that are actually visible. + /// + /// Providing a non-null `itemCount` improves the ability of the [ListView] to + /// estimate the maximum scroll extent. + /// + /// The `itemBuilder` callback will be called only with indices greater than + /// or equal to zero and less than `itemCount`. + /// + /// {@template flutter.widgets.ListView.builder.itemBuilder} + /// It is legal for `itemBuilder` to return `null`. If it does, the scroll view + /// will stop calling `itemBuilder`, even if it has yet to reach `itemCount`. + /// By returning `null`, the [ScrollPosition.maxScrollExtent] will not be accurate + /// unless the user has reached the end of the [ScrollView]. This can also cause the + /// [Scrollbar] to grow as the user scrolls. + /// + /// For more accurate [ScrollMetrics], consider specifying `itemCount`. + /// {@endtemplate} + /// + /// The `itemBuilder` should always create the widget instances when called. + /// Avoid using a builder that returns a previously-constructed widget; if the + /// list view's children are created in advance, or all at once when the + /// [ListView] itself is created, it is more efficient to use the [ListView] + /// constructor. Even more efficient, however, is to create the instances on + /// demand using this constructor's `itemBuilder` callback. + /// + /// {@macro flutter.widgets.PageView.findChildIndexCallback} + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. None may be + /// null. + ListView.builder({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.shrinkWrap, + super.padding, + this.itemExtent, + this.itemExtentBuilder, + this.prototypeItem, + required NullableIndexedWidgetBuilder itemBuilder, + ChildIndexGetter? findChildIndexCallback, + int? itemCount, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + super.cacheExtent, + int? semanticChildCount, + super.dragStartBehavior, + super.keyboardDismissBehavior, + super.restorationId, + super.clipBehavior, + }) : assert(itemCount == null || itemCount >= 0), + assert(semanticChildCount == null || semanticChildCount <= itemCount!), + assert( + (itemExtent == null && prototypeItem == null) || + (itemExtent == null && itemExtentBuilder == null) || + (prototypeItem == null && itemExtentBuilder == null), + 'You can only pass one of itemExtent, prototypeItem and itemExtentBuilder.', + ), + childrenDelegate = SliverChildBuilderDelegate( + itemBuilder, + findChildIndexCallback: findChildIndexCallback, + childCount: itemCount, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + ), + super( + semanticChildCount: semanticChildCount ?? itemCount, + ); + + /// Creates a fixed-length scrollable linear array of list "items" separated + /// by list item "separators". + /// + /// This constructor is appropriate for list views with a large number of + /// item and separator children because the builders are only called for + /// the children that are actually visible. + /// + /// The `itemBuilder` callback will be called with indices greater than + /// or equal to zero and less than `itemCount`. + /// + /// Separators only appear between list items: separator 0 appears after item + /// 0 and the last separator appears before the last item. + /// + /// The `separatorBuilder` callback will be called with indices greater than + /// or equal to zero and less than `itemCount - 1`. + /// + /// The `itemBuilder` and `separatorBuilder` callbacks should always + /// actually create widget instances when called. Avoid using a builder that + /// returns a previously-constructed widget; if the list view's children are + /// created in advance, or all at once when the [ListView] itself is created, + /// it is more efficient to use the [ListView] constructor. + /// + /// {@macro flutter.widgets.ListView.builder.itemBuilder} + /// + /// {@macro flutter.widgets.PageView.findChildIndexCallback} + /// + /// {@tool snippet} + /// + /// This example shows how to create [ListView] whose [ListTile] list items + /// are separated by [Divider]s. + /// + /// ```dart + /// ListView.separated( + /// itemCount: 25, + /// separatorBuilder: (BuildContext context, int index) => const Divider(), + /// itemBuilder: (BuildContext context, int index) { + /// return ListTile( + /// title: Text('item $index'), + /// ); + /// }, + /// ) + /// ``` + /// {@end-tool} + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. None may be + /// null. + ListView.separated({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.shrinkWrap, + super.padding, + required NullableIndexedWidgetBuilder itemBuilder, + ChildIndexGetter? findChildIndexCallback, + required IndexedWidgetBuilder separatorBuilder, + required int itemCount, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + super.cacheExtent, + super.dragStartBehavior, + super.keyboardDismissBehavior, + super.restorationId, + super.clipBehavior, + }) : assert(itemCount >= 0), + itemExtent = null, + itemExtentBuilder = null, + prototypeItem = null, + childrenDelegate = SliverChildBuilderDelegate( + (BuildContext context, int index) { + final int itemIndex = index ~/ 2; + if (index.isEven) { + return itemBuilder(context, itemIndex); + } + return separatorBuilder(context, itemIndex); + }, + findChildIndexCallback: findChildIndexCallback, + childCount: _computeActualChildCount(itemCount), + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + semanticIndexCallback: (Widget widget, int index) { + return index.isEven ? index ~/ 2 : null; + }, + ), + super( + semanticChildCount: itemCount, + ); + + /// Creates a scrollable, linear array of widgets with a custom child model. + /// + /// For example, a custom child model can control the algorithm used to + /// estimate the size of children that are not actually visible. + /// + /// {@tool dartpad} + /// This example shows a [ListView] that uses a custom [SliverChildBuilderDelegate] to support child + /// reordering. + /// + /// ** See code in examples/api/lib/widgets/scroll_view/list_view.1.dart ** + /// {@end-tool} + const ListView.custom({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.shrinkWrap, + super.padding, + this.itemExtent, + this.prototypeItem, + this.itemExtentBuilder, + required this.childrenDelegate, + super.cacheExtent, + super.semanticChildCount, + super.dragStartBehavior, + super.keyboardDismissBehavior, + super.restorationId, + super.clipBehavior, + }) : assert( + (itemExtent == null && prototypeItem == null) || + (itemExtent == null && itemExtentBuilder == null) || + (prototypeItem == null && itemExtentBuilder == null), + 'You can only pass one of itemExtent, prototypeItem and itemExtentBuilder.', + ); + + /// {@template flutter.widgets.list_view.itemExtent} + /// If non-null, forces the children to have the given extent in the scroll + /// direction. + /// + /// Specifying an [itemExtent] is more efficient than letting the children + /// determine their own extent because the scrolling machinery can make use of + /// the foreknowledge of the children's extent to save work, for example when + /// the scroll position changes drastically. + /// + /// See also: + /// + /// * [SliverFixedExtentList], the sliver used internally when this property + /// is provided. It constrains its box children to have a specific given + /// extent along the main axis. + /// * The [prototypeItem] property, which allows forcing the children's + /// extent to be the same as the given widget. + /// * The [itemExtentBuilder] property, which allows forcing the children's + /// extent to be the value returned by the callback. + /// {@endtemplate} + final double? itemExtent; + + /// {@template flutter.widgets.list_view.itemExtentBuilder} + /// If non-null, forces the children to have the corresponding extent returned + /// by the builder. + /// + /// Specifying an [itemExtentBuilder] is more efficient than letting the children + /// determine their own extent because the scrolling machinery can make use of + /// the foreknowledge of the children's extent to save work, for example when + /// the scroll position changes drastically. + /// + /// This will be called multiple times during the layout phase of a frame to find + /// the items that should be loaded by the lazy loading process. + /// + /// Unlike [itemExtent] or [prototypeItem], this allows children to have + /// different extents. + /// + /// See also: + /// + /// * [SliverVariedExtentList], the sliver used internally when this property + /// is provided. It constrains its box children to have a specific given + /// extent along the main axis. + /// * The [itemExtent] property, which allows forcing the children's extent + /// to a given value. + /// * The [prototypeItem] property, which allows forcing the children's + /// extent to be the same as the given widget. + /// {@endtemplate} + final ItemExtentBuilder? itemExtentBuilder; + + /// {@template flutter.widgets.list_view.prototypeItem} + /// If non-null, forces the children to have the same extent as the given + /// widget in the scroll direction. + /// + /// Specifying an [prototypeItem] is more efficient than letting the children + /// determine their own extent because the scrolling machinery can make use of + /// the foreknowledge of the children's extent to save work, for example when + /// the scroll position changes drastically. + /// + /// See also: + /// + /// * [SliverPrototypeExtentList], the sliver used internally when this + /// property is provided. It constrains its box children to have the same + /// extent as a prototype item along the main axis. + /// * The [itemExtent] property, which allows forcing the children's extent + /// to a given value. + /// * The [itemExtentBuilder] property, which allows forcing the children's + /// extent to be the value returned by the callback. + /// {@endtemplate} + final Widget? prototypeItem; + + /// A delegate that provides the children for the [ListView]. + /// + /// The [ListView.custom] constructor lets you specify this delegate + /// explicitly. The [ListView] and [ListView.builder] constructors create a + /// [childrenDelegate] that wraps the given [List] and [IndexedWidgetBuilder], + /// respectively. + final SliverChildDelegate childrenDelegate; + + @override + Widget buildChildLayout(BuildContext context) { + if (itemExtent != null) { + return SliverFixedExtentList( + delegate: childrenDelegate, + itemExtent: itemExtent!, + ); + } else if (itemExtentBuilder != null) { + return SliverVariedExtentList( + delegate: childrenDelegate, + itemExtentBuilder: itemExtentBuilder!, + ); + } else if (prototypeItem != null) { + return SliverPrototypeExtentList( + delegate: childrenDelegate, + prototypeItem: prototypeItem!, + ); + } + return SliverList(delegate: childrenDelegate); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DoubleProperty('itemExtent', itemExtent, defaultValue: null)); + } + + // Helper method to compute the actual child count for the separated constructor. + static int _computeActualChildCount(int itemCount) { + return math.max(0, itemCount * 2 - 1); + } +} + +/// A scrollable, 2D array of widgets. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=bLOtZDTm4H8} +/// +/// The main axis direction of a grid is the direction in which it scrolls (the +/// [scrollDirection]). +/// +/// The most commonly used grid layouts are [GridView.count], which creates a +/// layout with a fixed number of tiles in the cross axis, and +/// [GridView.extent], which creates a layout with tiles that have a maximum +/// cross-axis extent. A custom [SliverGridDelegate] can produce an arbitrary 2D +/// arrangement of children, including arrangements that are unaligned or +/// overlapping. +/// +/// To create a grid with a large (or infinite) number of children, use the +/// [GridView.builder] constructor with either a +/// [SliverGridDelegateWithFixedCrossAxisCount] or a +/// [SliverGridDelegateWithMaxCrossAxisExtent] for the [gridDelegate]. +/// +/// To use a custom [SliverChildDelegate], use [GridView.custom]. +/// +/// To create a linear array of children, use a [ListView]. +/// +/// To control the initial scroll offset of the scroll view, provide a +/// [controller] with its [ScrollController.initialScrollOffset] property set. +/// +/// ## Transitioning to [CustomScrollView] +/// +/// A [GridView] is basically a [CustomScrollView] with a single [SliverGrid] in +/// its [CustomScrollView.slivers] property. +/// +/// If [GridView] is no longer sufficient, for example because the scroll view +/// is to have both a grid and a list, or because the grid is to be combined +/// with a [SliverAppBar], etc, it is straight-forward to port code from using +/// [GridView] to using [CustomScrollView] directly. +/// +/// The [key], [scrollDirection], [reverse], [controller], [primary], [physics], +/// and [shrinkWrap] properties on [GridView] map directly to the identically +/// named properties on [CustomScrollView]. +/// +/// The [CustomScrollView.slivers] property should be a list containing just a +/// [SliverGrid]. +/// +/// The [childrenDelegate] property on [GridView] corresponds to the +/// [SliverGrid.delegate] property, and the [gridDelegate] property on the +/// [GridView] corresponds to the [SliverGrid.gridDelegate] property. +/// +/// The [GridView], [GridView.count], and [GridView.extent] +/// constructors' `children` arguments correspond to the [childrenDelegate] +/// being a [SliverChildListDelegate] with that same argument. The +/// [GridView.builder] constructor's `itemBuilder` and `childCount` arguments +/// correspond to the [childrenDelegate] being a [SliverChildBuilderDelegate] +/// with the matching arguments. +/// +/// The [GridView.count] and [GridView.extent] constructors create +/// custom grid delegates, and have equivalently named constructors on +/// [SliverGrid] to ease the transition: [SliverGrid.count] and +/// [SliverGrid.extent] respectively. +/// +/// The [padding] property corresponds to having a [SliverPadding] in the +/// [CustomScrollView.slivers] property instead of the grid itself, and having +/// the [SliverGrid] instead be a child of the [SliverPadding]. +/// +/// Once code has been ported to use [CustomScrollView], other slivers, such as +/// [SliverList] or [SliverAppBar], can be put in the [CustomScrollView.slivers] +/// list. +/// +/// {@macro flutter.widgets.ScrollView.PageStorage} +/// +/// ## Examples +/// +/// {@tool snippet} +/// This example demonstrates how to create a [GridView] with two columns. The +/// children are spaced apart using the `crossAxisSpacing` and `mainAxisSpacing` +/// properties. +/// +/// ![The GridView displays six children with different background colors arranged in two columns](https://flutter.github.io/assets-for-api-docs/assets/widgets/grid_view.png) +/// +/// ```dart +/// GridView.count( +/// primary: false, +/// padding: const EdgeInsets.all(20), +/// crossAxisSpacing: 10, +/// mainAxisSpacing: 10, +/// crossAxisCount: 2, +/// children: <Widget>[ +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.teal[100], +/// child: const Text("He'd have you all unravel at the"), +/// ), +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.teal[200], +/// child: const Text('Heed not the rabble'), +/// ), +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.teal[300], +/// child: const Text('Sound of screams but the'), +/// ), +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.teal[400], +/// child: const Text('Who scream'), +/// ), +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.teal[500], +/// child: const Text('Revolution is coming...'), +/// ), +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.teal[600], +/// child: const Text('Revolution, they...'), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// This example shows how to create the same grid as the previous example +/// using a [CustomScrollView] and a [SliverGrid]. +/// +/// ![The CustomScrollView contains a SliverGrid that displays six children with different background colors arranged in two columns](https://flutter.github.io/assets-for-api-docs/assets/widgets/grid_view_custom_scroll.png) +/// +/// ```dart +/// CustomScrollView( +/// primary: false, +/// slivers: <Widget>[ +/// SliverPadding( +/// padding: const EdgeInsets.all(20), +/// sliver: SliverGrid.count( +/// crossAxisSpacing: 10, +/// mainAxisSpacing: 10, +/// crossAxisCount: 2, +/// children: <Widget>[ +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.green[100], +/// child: const Text("He'd have you all unravel at the"), +/// ), +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.green[200], +/// child: const Text('Heed not the rabble'), +/// ), +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.green[300], +/// child: const Text('Sound of screams but the'), +/// ), +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.green[400], +/// child: const Text('Who scream'), +/// ), +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.green[500], +/// child: const Text('Revolution is coming...'), +/// ), +/// Container( +/// padding: const EdgeInsets.all(8), +/// color: Colors.green[600], +/// child: const Text('Revolution, they...'), +/// ), +/// ], +/// ), +/// ), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows a custom implementation of selection in list and grid views. +/// Use the button in the top right (possibly hidden under the DEBUG banner) to toggle between +/// [ListView] and [GridView]. +/// Long press any [ListTile] or [GridTile] to enable selection mode. +/// +/// ** See code in examples/api/lib/widgets/scroll_view/list_view.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows a custom [SliverGridDelegate]. +/// +/// ** See code in examples/api/lib/widgets/scroll_view/grid_view.0.dart ** +/// {@end-tool} +/// +/// ## Troubleshooting +/// +/// ### Padding +/// +/// By default, [GridView] will automatically pad the limits of the +/// grid's scrollable to avoid partial obstructions indicated by +/// [MediaQuery]'s padding. To avoid this behavior, override with a +/// zero [padding] property. +/// +/// {@tool snippet} +/// The following example demonstrates how to override the default top padding +/// using [MediaQuery.removePadding]. +/// +/// ```dart +/// Widget myWidget(BuildContext context) { +/// return MediaQuery.removePadding( +/// context: context, +/// removeTop: true, +/// child: GridView.builder( +/// gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( +/// crossAxisCount: 3, +/// ), +/// itemCount: 300, +/// itemBuilder: (BuildContext context, int index) { +/// return Card( +/// color: Colors.amber, +/// child: Center(child: Text('$index')), +/// ); +/// } +/// ), +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [SingleChildScrollView], which is a scrollable widget that has a single +/// child. +/// * [ListView], which is scrollable, linear list of widgets. +/// * [PageView], which is a scrolling list of child widgets that are each the +/// size of the viewport. +/// * [CustomScrollView], which is a scrollable widget that creates custom +/// scroll effects using slivers. +/// * [SliverGridDelegateWithFixedCrossAxisCount], which creates a layout with +/// a fixed number of tiles in the cross axis. +/// * [SliverGridDelegateWithMaxCrossAxisExtent], which creates a layout with +/// tiles that have a maximum cross-axis extent. +/// * [ScrollNotification] and [NotificationListener], which can be used to watch +/// the scroll position without using a [ScrollController]. +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class GridView extends BoxScrollView { + /// Creates a scrollable, 2D array of widgets with a custom + /// [SliverGridDelegate]. + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildListDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildListDelegate.addRepaintBoundaries] property. Both must not be + /// null. + GridView({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.shrinkWrap, + super.padding, + required this.gridDelegate, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + super.cacheExtent, + List<Widget> children = const <Widget>[], + int? semanticChildCount, + super.dragStartBehavior, + super.clipBehavior, + super.keyboardDismissBehavior, + super.restorationId, + }) : childrenDelegate = SliverChildListDelegate( + children, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + ), + super( + semanticChildCount: semanticChildCount ?? children.length, + ); + + /// Creates a scrollable, 2D array of widgets that are created on demand. + /// + /// This constructor is appropriate for grid views with a large (or infinite) + /// number of children because the builder is called only for those children + /// that are actually visible. + /// + /// Providing a non-null `itemCount` improves the ability of the [GridView] to + /// estimate the maximum scroll extent. + /// + /// `itemBuilder` will be called only with indices greater than or equal to + /// zero and less than `itemCount`. + /// + /// {@macro flutter.widgets.ListView.builder.itemBuilder} + /// + /// {@macro flutter.widgets.PageView.findChildIndexCallback} + /// + /// The [gridDelegate] argument is required. + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. + GridView.builder({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.shrinkWrap, + super.padding, + required this.gridDelegate, + required NullableIndexedWidgetBuilder itemBuilder, + ChildIndexGetter? findChildIndexCallback, + int? itemCount, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + super.cacheExtent, + int? semanticChildCount, + super.dragStartBehavior, + super.keyboardDismissBehavior, + super.restorationId, + super.clipBehavior, + }) : childrenDelegate = SliverChildBuilderDelegate( + itemBuilder, + findChildIndexCallback: findChildIndexCallback, + childCount: itemCount, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + ), + super( + semanticChildCount: semanticChildCount ?? itemCount, + ); + + /// Creates a scrollable, 2D array of widgets with both a custom + /// [SliverGridDelegate] and a custom [SliverChildDelegate]. + /// + /// To use an [IndexedWidgetBuilder] callback to build children, either use + /// a [SliverChildBuilderDelegate] or use the [GridView.builder] constructor. + const GridView.custom({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.shrinkWrap, + super.padding, + required this.gridDelegate, + required this.childrenDelegate, + super.cacheExtent, + super.semanticChildCount, + super.dragStartBehavior, + super.keyboardDismissBehavior, + super.restorationId, + super.clipBehavior, + }); + + /// Creates a scrollable, 2D array of widgets with a fixed number of tiles in + /// the cross axis. + /// + /// Uses a [SliverGridDelegateWithFixedCrossAxisCount] as the [gridDelegate]. + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildListDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildListDelegate.addRepaintBoundaries] property. Both must not be + /// null. + /// + /// See also: + /// + /// * [SliverGrid.count], the equivalent constructor for [SliverGrid]. + GridView.count({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.shrinkWrap, + super.padding, + required int crossAxisCount, + double mainAxisSpacing = 0.0, + double crossAxisSpacing = 0.0, + double childAspectRatio = 1.0, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + super.cacheExtent, + List<Widget> children = const <Widget>[], + int? semanticChildCount, + super.dragStartBehavior, + super.keyboardDismissBehavior, + super.restorationId, + super.clipBehavior, + }) : gridDelegate = SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: crossAxisCount, + mainAxisSpacing: mainAxisSpacing, + crossAxisSpacing: crossAxisSpacing, + childAspectRatio: childAspectRatio, + ), + childrenDelegate = SliverChildListDelegate( + children, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + ), + super( + semanticChildCount: semanticChildCount ?? children.length, + ); + + /// Creates a scrollable, 2D array of widgets with tiles that each have a + /// maximum cross-axis extent. + /// + /// Uses a [SliverGridDelegateWithMaxCrossAxisExtent] as the [gridDelegate]. + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildListDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildListDelegate.addRepaintBoundaries] property. Both must not be + /// null. + /// + /// See also: + /// + /// * [SliverGrid.extent], the equivalent constructor for [SliverGrid]. + GridView.extent({ + super.key, + super.scrollDirection, + super.reverse, + super.controller, + super.primary, + super.physics, + super.shrinkWrap, + super.padding, + required double maxCrossAxisExtent, + double mainAxisSpacing = 0.0, + double crossAxisSpacing = 0.0, + double childAspectRatio = 1.0, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + super.cacheExtent, + List<Widget> children = const <Widget>[], + int? semanticChildCount, + super.dragStartBehavior, + super.keyboardDismissBehavior, + super.restorationId, + super.clipBehavior, + }) : gridDelegate = SliverGridDelegateWithMaxCrossAxisExtent( + maxCrossAxisExtent: maxCrossAxisExtent, + mainAxisSpacing: mainAxisSpacing, + crossAxisSpacing: crossAxisSpacing, + childAspectRatio: childAspectRatio, + ), + childrenDelegate = SliverChildListDelegate( + children, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + ), + super( + semanticChildCount: semanticChildCount ?? children.length, + ); + + /// A delegate that controls the layout of the children within the [GridView]. + /// + /// The [GridView], [GridView.builder], and [GridView.custom] constructors let you specify this + /// delegate explicitly. The other constructors create a [gridDelegate] + /// implicitly. + final SliverGridDelegate gridDelegate; + + /// A delegate that provides the children for the [GridView]. + /// + /// The [GridView.custom] constructor lets you specify this delegate + /// explicitly. The other constructors create a [childrenDelegate] that wraps + /// the given child list. + final SliverChildDelegate childrenDelegate; + + @override + Widget buildChildLayout(BuildContext context) { + return SliverGrid( + delegate: childrenDelegate, + gridDelegate: gridDelegate, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scrollable.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scrollable.dart new file mode 100644 index 0000000000000000000000000000000000000000..9b55e707166119853915a0fb4c9cd8570303fa51 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scrollable.dart @@ -0,0 +1,2427 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'media_query.dart'; +import 'notification_listener.dart'; +import 'restoration.dart'; +import 'restoration_properties.dart'; +import 'scroll_activity.dart'; +import 'scroll_configuration.dart'; +import 'scroll_context.dart'; +import 'scroll_controller.dart'; +import 'scroll_physics.dart'; +import 'scroll_position.dart'; +import 'scrollable_helpers.dart'; +import 'selectable_region.dart'; +import 'selection_container.dart'; +import 'ticker_provider.dart'; +import 'view.dart'; +import 'viewport.dart'; + +export 'package:flutter/physics.dart' show Tolerance; + +// Examples can assume: +// late BuildContext context; + +/// Signature used by [Scrollable] to build the viewport through which the +/// scrollable content is displayed. +typedef ViewportBuilder = Widget Function(BuildContext context, ViewportOffset position); + +/// Signature used by [TwoDimensionalScrollable] to build the viewport through +/// which the scrollable content is displayed. +typedef TwoDimensionalViewportBuilder = Widget Function(BuildContext context, ViewportOffset verticalPosition, ViewportOffset horizontalPosition); + +// The return type of _performEnsureVisible. +// +// The list of futures represents each pending ScrollPosition call to +// ensureVisible. The returned ScrollableState's context is used to find the +// next potential ancestor Scrollable. +typedef _EnsureVisibleResults = (List<Future<void>>, ScrollableState); + +/// A widget that manages scrolling in one dimension and informs the [Viewport] +/// through which the content is viewed. +/// +/// [Scrollable] implements the interaction model for a scrollable widget, +/// including gesture recognition, but does not have an opinion about how the +/// viewport, which actually displays the children, is constructed. +/// +/// It's rare to construct a [Scrollable] directly. Instead, consider [ListView] +/// or [GridView], which combine scrolling, viewporting, and a layout model. To +/// combine layout models (or to use a custom layout mode), consider using +/// [CustomScrollView]. +/// +/// The static [Scrollable.of] and [Scrollable.ensureVisible] functions are +/// often used to interact with the [Scrollable] widget inside a [ListView] or +/// a [GridView]. +/// +/// To further customize scrolling behavior with a [Scrollable]: +/// +/// 1. You can provide a [viewportBuilder] to customize the child model. For +/// example, [SingleChildScrollView] uses a viewport that displays a single +/// box child whereas [CustomScrollView] uses a [Viewport] or a +/// [ShrinkWrappingViewport], both of which display a list of slivers. +/// +/// 2. You can provide a custom [ScrollController] that creates a custom +/// [ScrollPosition] subclass. For example, [PageView] uses a +/// [PageController], which creates a page-oriented scroll position subclass +/// that keeps the same page visible when the [Scrollable] resizes. +/// +/// ## Persisting the scroll position during a session +/// +/// Scrollables attempt to persist their scroll position using [PageStorage]. +/// This can be disabled by setting [ScrollController.keepScrollOffset] to false +/// on the [controller]. If it is enabled, using a [PageStorageKey] for the +/// [key] of this widget (or one of its ancestors, e.g. a [ScrollView]) is +/// recommended to help disambiguate different [Scrollable]s from each other. +/// +/// See also: +/// +/// * [ListView], which is a commonly used [ScrollView] that displays a +/// scrolling, linear list of child widgets. +/// * [PageView], which is a scrolling list of child widgets that are each the +/// size of the viewport. +/// * [GridView], which is a [ScrollView] that displays a scrolling, 2D array +/// of child widgets. +/// * [CustomScrollView], which is a [ScrollView] that creates custom scroll +/// effects using slivers. +/// * [SingleChildScrollView], which is a scrollable widget that has a single +/// child. +/// * [ScrollNotification] and [NotificationListener], which can be used to watch +/// the scroll position without using a [ScrollController]. +class Scrollable extends StatefulWidget { + /// Creates a widget that scrolls. + const Scrollable({ + super.key, + this.axisDirection = AxisDirection.down, + this.controller, + this.physics, + required this.viewportBuilder, + this.incrementCalculator, + this.excludeFromSemantics = false, + this.semanticChildCount, + this.dragStartBehavior = DragStartBehavior.start, + this.restorationId, + this.scrollBehavior, + this.clipBehavior = Clip.hardEdge, + }) : assert(semanticChildCount == null || semanticChildCount >= 0); + + /// {@template flutter.widgets.Scrollable.axisDirection} + /// The direction in which this widget scrolls. + /// + /// For example, if the [Scrollable.axisDirection] is [AxisDirection.down], + /// increasing the scroll position will cause content below the bottom of the + /// viewport to become visible through the viewport. Similarly, if the + /// axisDirection is [AxisDirection.right], increasing the scroll position + /// will cause content beyond the right edge of the viewport to become visible + /// through the viewport. + /// + /// Defaults to [AxisDirection.down]. + /// {@endtemplate} + final AxisDirection axisDirection; + + /// {@template flutter.widgets.Scrollable.controller} + /// An object that can be used to control the position to which this widget is + /// scrolled. + /// + /// A [ScrollController] serves several purposes. It can be used to control + /// the initial scroll position (see [ScrollController.initialScrollOffset]). + /// It can be used to control whether the scroll view should automatically + /// save and restore its scroll position in the [PageStorage] (see + /// [ScrollController.keepScrollOffset]). It can be used to read the current + /// scroll position (see [ScrollController.offset]), or change it (see + /// [ScrollController.animateTo]). + /// + /// If null, a [ScrollController] will be created internally by [Scrollable] + /// in order to create and manage the [ScrollPosition]. + /// + /// See also: + /// + /// * [Scrollable.ensureVisible], which animates the scroll position to + /// reveal a given [BuildContext]. + /// {@endtemplate} + final ScrollController? controller; + + /// {@template flutter.widgets.Scrollable.physics} + /// How the widgets should respond to user input. + /// + /// For example, determines how the widget continues to animate after the + /// user stops dragging the scroll view. + /// + /// Defaults to matching platform conventions via the physics provided from + /// the ambient [ScrollConfiguration]. + /// + /// If an explicit [ScrollBehavior] is provided to + /// [Scrollable.scrollBehavior], the [ScrollPhysics] provided by that behavior + /// will take precedence after [Scrollable.physics]. + /// + /// The physics can be changed dynamically, but new physics will only take + /// effect if the _class_ of the provided object changes. Merely constructing + /// a new instance with a different configuration is insufficient to cause the + /// physics to be reapplied. (This is because the final object used is + /// generated dynamically, which can be relatively expensive, and it would be + /// inefficient to speculatively create this object each frame to see if the + /// physics should be updated.) + /// + /// See also: + /// + /// * [AlwaysScrollableScrollPhysics], which can be used to indicate that the + /// scrollable should react to scroll requests (and possible overscroll) + /// even if the scrollable's contents fit without scrolling being necessary. + /// {@endtemplate} + final ScrollPhysics? physics; + + /// Builds the viewport through which the scrollable content is displayed. + /// + /// A typical viewport uses the given [ViewportOffset] to determine which part + /// of its content is actually visible through the viewport. + /// + /// See also: + /// + /// * [Viewport], which is a viewport that displays a list of slivers. + /// * [ShrinkWrappingViewport], which is a viewport that displays a list of + /// slivers and sizes itself based on the size of the slivers. + final ViewportBuilder viewportBuilder; + + /// {@template flutter.widgets.Scrollable.incrementCalculator} + /// An optional function that will be called to calculate the distance to + /// scroll when the scrollable is asked to scroll via the keyboard using a + /// [ScrollAction]. + /// + /// If not supplied, the [Scrollable] will scroll a default amount when a + /// keyboard navigation key is pressed (e.g. pageUp/pageDown, control-upArrow, + /// etc.), or otherwise invoked by a [ScrollAction]. + /// + /// If [incrementCalculator] is null, the default for + /// [ScrollIncrementType.page] is 80% of the size of the scroll window, and + /// for [ScrollIncrementType.line], 50 logical pixels. + /// {@endtemplate} + final ScrollIncrementCalculator? incrementCalculator; + + /// {@template flutter.widgets.scrollable.excludeFromSemantics} + /// Whether the scroll actions introduced by this [Scrollable] are exposed + /// in the semantics tree. + /// + /// Text fields with an overflow are usually scrollable to make sure that the + /// user can get to the beginning/end of the entered text. However, these + /// scrolling actions are generally not exposed to the semantics layer. + /// {@endtemplate} + /// + /// See also: + /// + /// * [GestureDetector.excludeFromSemantics], which is used to accomplish the + /// exclusion. + final bool excludeFromSemantics; + + /// The number of children that will contribute semantic information. + /// + /// The value will be null if the number of children is unknown or unbounded. + /// + /// Some subtypes of [ScrollView] can infer this value automatically. For + /// example [ListView] will use the number of widgets in the child list, + /// while the [ListView.separated] constructor will use half that amount. + /// + /// For [CustomScrollView] and other types which do not receive a builder + /// or list of widgets, the child count must be explicitly provided. + /// + /// See also: + /// + /// * [CustomScrollView], for an explanation of scroll semantics. + /// * [SemanticsConfiguration.scrollChildCount], the corresponding semantics property. + final int? semanticChildCount; + + // TODO(jslavitz): Set the DragStartBehavior default to be start across all widgets. + /// {@template flutter.widgets.scrollable.dragStartBehavior} + /// Determines the way that drag start behavior is handled. + /// + /// If set to [DragStartBehavior.start], scrolling drag behavior will + /// begin at the position where the drag gesture won the arena. If set to + /// [DragStartBehavior.down] it will begin at the position where a down + /// event is first detected. + /// + /// In general, setting this to [DragStartBehavior.start] will make drag + /// animation smoother and setting it to [DragStartBehavior.down] will make + /// drag behavior feel slightly more reactive. + /// + /// By default, the drag start behavior is [DragStartBehavior.start]. + /// + /// See also: + /// + /// * [DragGestureRecognizer.dragStartBehavior], which gives an example for + /// the different behaviors. + /// + /// {@endtemplate} + final DragStartBehavior dragStartBehavior; + + /// {@template flutter.widgets.scrollable.restorationId} + /// Restoration ID to save and restore the scroll offset of the scrollable. + /// + /// If a restoration id is provided, the scrollable will persist its current + /// scroll offset and restore it during state restoration. + /// + /// The scroll offset is persisted in a [RestorationBucket] claimed from + /// the surrounding [RestorationScope] using the provided restoration ID. + /// + /// See also: + /// + /// * [RestorationManager], which explains how state restoration works in + /// Flutter. + /// {@endtemplate} + final String? restorationId; + + /// {@macro flutter.widgets.shadow.scrollBehavior} + /// + /// [ScrollBehavior]s also provide [ScrollPhysics]. If an explicit + /// [ScrollPhysics] is provided in [physics], it will take precedence, + /// followed by [scrollBehavior], and then the inherited ancestor + /// [ScrollBehavior]. + final ScrollBehavior? scrollBehavior; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + /// + /// This is passed to decorators in [ScrollableDetails], and does not directly affect + /// clipping of the [Scrollable]. This reflects the same [Clip] that is provided + /// to [ScrollView.clipBehavior] and is supplied to the [Viewport]. + final Clip clipBehavior; + + /// The axis along which the scroll view scrolls. + /// + /// Determined by the [axisDirection]. + Axis get axis => axisDirectionToAxis(axisDirection); + + @override + ScrollableState createState() => ScrollableState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<AxisDirection>('axisDirection', axisDirection)); + properties.add(DiagnosticsProperty<ScrollPhysics>('physics', physics)); + properties.add(StringProperty('restorationId', restorationId)); + } + + /// The state from the closest instance of this class that encloses the given + /// context, or null if none is found. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ScrollableState? scrollable = Scrollable.maybeOf(context); + /// ``` + /// + /// Calling this method will create a dependency on the [ScrollableState] + /// that is returned, if there is one. This is typically the closest + /// [Scrollable], but may be a more distant ancestor if [axis] is used to + /// target a specific [Scrollable]. + /// + /// Using the optional [Axis] is useful when Scrollables are nested and the + /// target [Scrollable] is not the closest instance. When [axis] is provided, + /// the nearest enclosing [ScrollableState] in that [Axis] is returned, or + /// null if there is none. + /// + /// This finds the nearest _ancestor_ [Scrollable] of the `context`. This + /// means that if the `context` is that of a [Scrollable], it will _not_ find + /// _that_ [Scrollable]. + /// + /// See also: + /// + /// * [Scrollable.of], which is similar to this method, but asserts + /// if no [Scrollable] ancestor is found. + static ScrollableState? maybeOf(BuildContext context, { Axis? axis }) { + // This is the context that will need to establish the dependency. + final BuildContext originalContext = context; + InheritedElement? element = context.getElementForInheritedWidgetOfExactType<_ScrollableScope>(); + while (element != null) { + final ScrollableState scrollable = (element.widget as _ScrollableScope).scrollable; + if (axis == null || axisDirectionToAxis(scrollable.axisDirection) == axis) { + // Establish the dependency on the correct context. + originalContext.dependOnInheritedElement(element); + return scrollable; + } + context = scrollable.context; + element = context.getElementForInheritedWidgetOfExactType<_ScrollableScope>(); + } + return null; + } + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// ScrollableState scrollable = Scrollable.of(context); + /// ``` + /// + /// Calling this method will create a dependency on the [ScrollableState] + /// that is returned, if there is one. This is typically the closest + /// [Scrollable], but may be a more distant ancestor if [axis] is used to + /// target a specific [Scrollable]. + /// + /// Using the optional [Axis] is useful when Scrollables are nested and the + /// target [Scrollable] is not the closest instance. When [axis] is provided, + /// the nearest enclosing [ScrollableState] in that [Axis] is returned. + /// + /// This finds the nearest _ancestor_ [Scrollable] of the `context`. This + /// means that if the `context` is that of a [Scrollable], it will _not_ find + /// _that_ [Scrollable]. + /// + /// If no [Scrollable] ancestor is found, then this method will assert in + /// debug mode, and throw an exception in release mode. + /// + /// See also: + /// + /// * [Scrollable.maybeOf], which is similar to this method, but returns null + /// if no [Scrollable] ancestor is found. + static ScrollableState of(BuildContext context, { Axis? axis }) { + final ScrollableState? scrollableState = maybeOf(context, axis: axis); + assert(() { + if (scrollableState == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'Scrollable.of() was called with a context that does not contain a ' + 'Scrollable widget.', + ), + ErrorDescription( + 'No Scrollable widget ancestor could be found ' + '${axis == null ? '' : 'for the provided Axis: $axis '}' + 'starting from the context that was passed to Scrollable.of(). This ' + 'can happen because you are using a widget that looks for a Scrollable ' + 'ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ), + if (axis != null) ErrorHint( + 'When specifying an axis, this method will only look for a Scrollable ' + 'that matches the given Axis.', + ), + ]); + } + return true; + }()); + return scrollableState!; + } + + /// Provides a heuristic to determine if expensive frame-bound tasks should be + /// deferred for the [context] at a specific point in time. + /// + /// Calling this method does _not_ create a dependency on any other widget. + /// This also means that the value returned is only good for the point in time + /// when it is called, and callers will not get updated if the value changes. + /// + /// The heuristic used is determined by the [physics] of this [Scrollable] + /// via [ScrollPhysics.recommendDeferredLoading]. That method is called with + /// the current [ScrollPosition.activity]'s [ScrollActivity.velocity]. + /// + /// The optional [Axis] allows targeting of a specific [Scrollable] of that + /// axis, useful when Scrollables are nested. When [axis] is provided, + /// [ScrollPosition.recommendDeferredLoading] is called for the nearest + /// [Scrollable] in that [Axis]. + /// + /// If there is no [Scrollable] in the widget tree above the [context], this + /// method returns false. + static bool recommendDeferredLoadingForContext(BuildContext context, { Axis? axis }) { + _ScrollableScope? widget = context.getInheritedWidgetOfExactType<_ScrollableScope>(); + while (widget != null) { + if (axis == null || axisDirectionToAxis(widget.scrollable.axisDirection) == axis) { + return widget.position.recommendDeferredLoading(context); + } + context = widget.scrollable.context; + widget = context.getInheritedWidgetOfExactType<_ScrollableScope>(); + } + return false; + } + + /// Scrolls the scrollables that enclose the given context so as to make the + /// given context visible. + /// + /// If the [Scrollable] of the provided [BuildContext] is a + /// [TwoDimensionalScrollable], both vertical and horizontal axes will ensure + /// the target is made visible. + static Future<void> ensureVisible( + BuildContext context, { + double alignment = 0.0, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit, + }) { + final List<Future<void>> futures = <Future<void>>[]; + + // The targetRenderObject is used to record the first target renderObject. + // If there are multiple scrollable widgets nested, the targetRenderObject + // is made to be as visible as possible to improve the user experience. If + // the targetRenderObject is already visible, then let the outer + // renderObject be as visible as possible. + // + // Also see https://github.com/flutter/flutter/issues/65100 + RenderObject? targetRenderObject; + ScrollableState? scrollable = Scrollable.maybeOf(context); + while (scrollable != null) { + final List<Future<void>> newFutures; + (newFutures, scrollable) = scrollable._performEnsureVisible( + context.findRenderObject()!, + alignment: alignment, + duration: duration, + curve: curve, + alignmentPolicy: alignmentPolicy, + targetRenderObject: targetRenderObject, + ); + futures.addAll(newFutures); + + targetRenderObject ??= context.findRenderObject(); + context = scrollable.context; + scrollable = Scrollable.maybeOf(context); + } + + if (futures.isEmpty || duration == Duration.zero) { + return Future<void>.value(); + } + if (futures.length == 1) { + return futures.single; + } + return Future.wait<void>(futures).then<void>((List<void> _) => null); + } +} + +// Enable Scrollable.of() to work as if ScrollableState was an inherited widget. +// ScrollableState.build() always rebuilds its _ScrollableScope. +class _ScrollableScope extends InheritedWidget { + const _ScrollableScope({ + required this.scrollable, + required this.position, + required super.child, + }); + + final ScrollableState scrollable; + final ScrollPosition position; + + @override + bool updateShouldNotify(_ScrollableScope old) { + return position != old.position; + } +} + +/// State object for a [Scrollable] widget. +/// +/// To manipulate a [Scrollable] widget's scroll position, use the object +/// obtained from the [position] property. +/// +/// To be informed of when a [Scrollable] widget is scrolling, use a +/// [NotificationListener] to listen for [ScrollNotification] notifications. +/// +/// This class is not intended to be subclassed. To specialize the behavior of a +/// [Scrollable], provide it with a [ScrollPhysics]. +class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, RestorationMixin + implements ScrollContext { + + // GETTERS + + /// The manager for this [Scrollable] widget's viewport position. + /// + /// To control what kind of [ScrollPosition] is created for a [Scrollable], + /// provide it with custom [ScrollController] that creates the appropriate + /// [ScrollPosition] in its [ScrollController.createScrollPosition] method. + ScrollPosition get position => _position!; + ScrollPosition? _position; + + /// The resolved [ScrollPhysics] of the [ScrollableState]. + ScrollPhysics? get resolvedPhysics => _physics; + ScrollPhysics? _physics; + + /// An [Offset] that represents the absolute distance from the origin, or 0, + /// of the [ScrollPosition] expressed in the associated [Axis]. + /// + /// Used by [EdgeDraggingAutoScroller] to progress the position forward when a + /// drag gesture reaches the edge of the [Viewport]. + Offset get deltaToScrollOrigin { + switch (axisDirection) { + case AxisDirection.down: + return Offset(0, position.pixels); + case AxisDirection.up: + return Offset(0, -position.pixels); + case AxisDirection.left: + return Offset(-position.pixels, 0); + case AxisDirection.right: + return Offset(position.pixels, 0); + } + } + + ScrollController get _effectiveScrollController => widget.controller ?? _fallbackScrollController!; + + @override + AxisDirection get axisDirection => widget.axisDirection; + + @override + TickerProvider get vsync => this; + + @override + double get devicePixelRatio => _devicePixelRatio; + late double _devicePixelRatio; + + @override + BuildContext? get notificationContext => _gestureDetectorKey.currentContext; + + @override + BuildContext get storageContext => context; + + @override + String? get restorationId => widget.restorationId; + final _RestorableScrollOffset _persistedScrollOffset = _RestorableScrollOffset(); + + late ScrollBehavior _configuration; + ScrollController? _fallbackScrollController; + DeviceGestureSettings? _mediaQueryGestureSettings; + + // Only call this from places that will definitely trigger a rebuild. + void _updatePosition() { + _configuration = widget.scrollBehavior ?? ScrollConfiguration.of(context); + _physics = _configuration.getScrollPhysics(context); + if (widget.physics != null) { + _physics = widget.physics!.applyTo(_physics); + } else if (widget.scrollBehavior != null) { + _physics = widget.scrollBehavior!.getScrollPhysics(context).applyTo(_physics); + } + final ScrollPosition? oldPosition = _position; + if (oldPosition != null) { + _effectiveScrollController.detach(oldPosition); + // It's important that we not dispose the old position until after the + // viewport has had a chance to unregister its listeners from the old + // position. So, schedule a microtask to do it. + scheduleMicrotask(oldPosition.dispose); + } + + _position = _effectiveScrollController.createScrollPosition(_physics!, this, oldPosition); + assert(_position != null); + _effectiveScrollController.attach(position); + } + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_persistedScrollOffset, 'offset'); + assert(_position != null); + if (_persistedScrollOffset.value != null) { + position.restoreOffset(_persistedScrollOffset.value!, initialRestore: initialRestore); + } + } + + @override + void saveOffset(double offset) { + assert(debugIsSerializableForRestoration(offset)); + _persistedScrollOffset.value = offset; + // [saveOffset] is called after a scrolling ends and it is usually not + // followed by a frame. Therefore, manually flush restoration data. + ServicesBinding.instance.restorationManager.flushData(); + } + + @override + void initState() { + if (widget.controller == null) { + _fallbackScrollController = ScrollController(); + } + super.initState(); + } + + @override + void didChangeDependencies() { + _mediaQueryGestureSettings = MediaQuery.maybeGestureSettingsOf(context); + _devicePixelRatio = MediaQuery.maybeDevicePixelRatioOf(context) ?? View.of(context).devicePixelRatio; + _updatePosition(); + super.didChangeDependencies(); + } + + bool _shouldUpdatePosition(Scrollable oldWidget) { + if ((widget.scrollBehavior == null) != (oldWidget.scrollBehavior == null)) { + return true; + } + if (widget.scrollBehavior != null && oldWidget.scrollBehavior != null && widget.scrollBehavior!.shouldNotify(oldWidget.scrollBehavior!)) { + return true; + } + ScrollPhysics? newPhysics = widget.physics ?? widget.scrollBehavior?.getScrollPhysics(context); + ScrollPhysics? oldPhysics = oldWidget.physics ?? oldWidget.scrollBehavior?.getScrollPhysics(context); + do { + if (newPhysics?.runtimeType != oldPhysics?.runtimeType) { + return true; + } + newPhysics = newPhysics?.parent; + oldPhysics = oldPhysics?.parent; + } while (newPhysics != null || oldPhysics != null); + + return widget.controller?.runtimeType != oldWidget.controller?.runtimeType; + } + + @override + void didUpdateWidget(Scrollable oldWidget) { + super.didUpdateWidget(oldWidget); + + if (widget.controller != oldWidget.controller) { + if (oldWidget.controller == null) { + // The old controller was null, meaning the fallback cannot be null. + // Dispose of the fallback. + assert(_fallbackScrollController != null); + assert(widget.controller != null); + _fallbackScrollController!.detach(position); + _fallbackScrollController!.dispose(); + _fallbackScrollController = null; + } else { + // The old controller was not null, detach. + oldWidget.controller?.detach(position); + if (widget.controller == null) { + // If the new controller is null, we need to set up the fallback + // ScrollController. + _fallbackScrollController = ScrollController(); + } + } + // Attach the updated effective scroll controller. + _effectiveScrollController.attach(position); + } + + if (_shouldUpdatePosition(oldWidget)) { + _updatePosition(); + } + } + + @override + void dispose() { + if (widget.controller != null) { + widget.controller!.detach(position); + } else { + _fallbackScrollController?.detach(position); + _fallbackScrollController?.dispose(); + } + + position.dispose(); + _persistedScrollOffset.dispose(); + super.dispose(); + } + + // SEMANTICS + + final GlobalKey _scrollSemanticsKey = GlobalKey(); + + @override + @protected + void setSemanticsActions(Set<SemanticsAction> actions) { + if (_gestureDetectorKey.currentState != null) { + _gestureDetectorKey.currentState!.replaceSemanticsActions(actions); + } + } + + // GESTURE RECOGNITION AND POINTER IGNORING + + final GlobalKey<RawGestureDetectorState> _gestureDetectorKey = GlobalKey<RawGestureDetectorState>(); + final GlobalKey _ignorePointerKey = GlobalKey(); + + // This field is set during layout, and then reused until the next time it is set. + Map<Type, GestureRecognizerFactory> _gestureRecognizers = const <Type, GestureRecognizerFactory>{}; + bool _shouldIgnorePointer = false; + + bool? _lastCanDrag; + Axis? _lastAxisDirection; + + @override + @protected + void setCanDrag(bool value) { + if (value == _lastCanDrag && (!value || widget.axis == _lastAxisDirection)) { + return; + } + if (!value) { + _gestureRecognizers = const <Type, GestureRecognizerFactory>{}; + // Cancel the active hold/drag (if any) because the gesture recognizers + // will soon be disposed by our RawGestureDetector, and we won't be + // receiving pointer up events to cancel the hold/drag. + _handleDragCancel(); + } else { + switch (widget.axis) { + case Axis.vertical: + _gestureRecognizers = <Type, GestureRecognizerFactory>{ + VerticalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>( + () => VerticalDragGestureRecognizer(supportedDevices: _configuration.dragDevices), + (VerticalDragGestureRecognizer instance) { + instance + ..onDown = _handleDragDown + ..onStart = _handleDragStart + ..onUpdate = _handleDragUpdate + ..onEnd = _handleDragEnd + ..onCancel = _handleDragCancel + ..minFlingDistance = _physics?.minFlingDistance + ..minFlingVelocity = _physics?.minFlingVelocity + ..maxFlingVelocity = _physics?.maxFlingVelocity + ..velocityTrackerBuilder = _configuration.velocityTrackerBuilder(context) + ..dragStartBehavior = widget.dragStartBehavior + ..multitouchDragStrategy = _configuration.multitouchDragStrategy + ..gestureSettings = _mediaQueryGestureSettings + ..supportedDevices = _configuration.dragDevices; + }, + ), + }; + case Axis.horizontal: + _gestureRecognizers = <Type, GestureRecognizerFactory>{ + HorizontalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<HorizontalDragGestureRecognizer>( + () => HorizontalDragGestureRecognizer(supportedDevices: _configuration.dragDevices), + (HorizontalDragGestureRecognizer instance) { + instance + ..onDown = _handleDragDown + ..onStart = _handleDragStart + ..onUpdate = _handleDragUpdate + ..onEnd = _handleDragEnd + ..onCancel = _handleDragCancel + ..minFlingDistance = _physics?.minFlingDistance + ..minFlingVelocity = _physics?.minFlingVelocity + ..maxFlingVelocity = _physics?.maxFlingVelocity + ..velocityTrackerBuilder = _configuration.velocityTrackerBuilder(context) + ..dragStartBehavior = widget.dragStartBehavior + ..multitouchDragStrategy = _configuration.multitouchDragStrategy + ..gestureSettings = _mediaQueryGestureSettings + ..supportedDevices = _configuration.dragDevices; + }, + ), + }; + } + } + _lastCanDrag = value; + _lastAxisDirection = widget.axis; + if (_gestureDetectorKey.currentState != null) { + _gestureDetectorKey.currentState!.replaceGestureRecognizers(_gestureRecognizers); + } + } + + @override + @protected + void setIgnorePointer(bool value) { + if (_shouldIgnorePointer == value) { + return; + } + _shouldIgnorePointer = value; + if (_ignorePointerKey.currentContext != null) { + final RenderIgnorePointer renderBox = _ignorePointerKey.currentContext!.findRenderObject()! as RenderIgnorePointer; + renderBox.ignoring = _shouldIgnorePointer; + } + } + + // TOUCH HANDLERS + + Drag? _drag; + ScrollHoldController? _hold; + + void _handleDragDown(DragDownDetails details) { + assert(_drag == null); + assert(_hold == null); + _hold = position.hold(_disposeHold); + } + + void _handleDragStart(DragStartDetails details) { + // It's possible for _hold to become null between _handleDragDown and + // _handleDragStart, for example if some user code calls jumpTo or otherwise + // triggers a new activity to begin. + assert(_drag == null); + _drag = position.drag(details, _disposeDrag); + assert(_drag != null); + assert(_hold == null); + } + + void _handleDragUpdate(DragUpdateDetails details) { + // _drag might be null if the drag activity ended and called _disposeDrag. + assert(_hold == null || _drag == null); + _drag?.update(details); + } + + void _handleDragEnd(DragEndDetails details) { + // _drag might be null if the drag activity ended and called _disposeDrag. + assert(_hold == null || _drag == null); + _drag?.end(details); + assert(_drag == null); + } + + void _handleDragCancel() { + if (_gestureDetectorKey.currentContext == null) { + // The cancel was caused by the GestureDetector getting disposed, which + // means we will get disposed momentarily as well and shouldn't do + // any work. + return; + } + // _hold might be null if the drag started. + // _drag might be null if the drag activity ended and called _disposeDrag. + assert(_hold == null || _drag == null); + _hold?.cancel(); + _drag?.cancel(); + assert(_hold == null); + assert(_drag == null); + } + + void _disposeHold() { + _hold = null; + } + + void _disposeDrag() { + _drag = null; + } + + // SCROLL WHEEL + + // Returns the offset that should result from applying [event] to the current + // position, taking min/max scroll extent into account. + double _targetScrollOffsetForPointerScroll(double delta) { + return math.min( + math.max(position.pixels + delta, position.minScrollExtent), + position.maxScrollExtent, + ); + } + + // Returns the delta that should result from applying [event] with axis, + // direction, and any modifiers specified by the ScrollBehavior taken into + // account. + double _pointerSignalEventDelta(PointerScrollEvent event) { + late double delta; + final Set<LogicalKeyboardKey> pressed = HardwareKeyboard.instance.logicalKeysPressed; + final bool flipAxes = pressed.any(_configuration.pointerAxisModifiers.contains) && + // Axes are only flipped for physical mouse wheel input. + // On some platforms, like web, trackpad input is handled through pointer + // signals, but should not be included in this axis modifying behavior. + // This is because on a trackpad, all directional axes are available to + // the user, while mouse scroll wheels typically are restricted to one + // axis. + event.kind == PointerDeviceKind.mouse; + + switch (widget.axis) { + case Axis.horizontal: + delta = flipAxes + ? event.scrollDelta.dy + : event.scrollDelta.dx; + case Axis.vertical: + delta = flipAxes + ? event.scrollDelta.dx + : event.scrollDelta.dy; + } + + if (axisDirectionIsReversed(widget.axisDirection)) { + delta *= -1; + } + return delta; + } + + void _receivedPointerSignal(PointerSignalEvent event) { + if (event is PointerScrollEvent && _position != null) { + if (_physics != null && !_physics!.shouldAcceptUserOffset(position)) { + return; + } + final double delta = _pointerSignalEventDelta(event); + final double targetScrollOffset = _targetScrollOffsetForPointerScroll(delta); + // Only express interest in the event if it would actually result in a scroll. + if (delta != 0.0 && targetScrollOffset != position.pixels) { + GestureBinding.instance.pointerSignalResolver.register(event, _handlePointerScroll); + } + } else if (event is PointerScrollInertiaCancelEvent) { + position.pointerScroll(0); + // Don't use the pointer signal resolver, all hit-tested scrollables should stop. + } + } + + void _handlePointerScroll(PointerEvent event) { + assert(event is PointerScrollEvent); + final double delta = _pointerSignalEventDelta(event as PointerScrollEvent); + final double targetScrollOffset = _targetScrollOffsetForPointerScroll(delta); + if (delta != 0.0 && targetScrollOffset != position.pixels) { + position.pointerScroll(delta); + } + } + + bool _handleScrollMetricsNotification(ScrollMetricsNotification notification) { + if (notification.depth == 0) { + final RenderObject? scrollSemanticsRenderObject = _scrollSemanticsKey.currentContext?.findRenderObject(); + if (scrollSemanticsRenderObject != null) { + scrollSemanticsRenderObject.markNeedsSemanticsUpdate(); + } + } + return false; + } + + Widget _buildChrome(BuildContext context, Widget child) { + final ScrollableDetails details = ScrollableDetails( + direction: widget.axisDirection, + controller: _effectiveScrollController, + decorationClipBehavior: widget.clipBehavior, + ); + + return _configuration.buildScrollbar( + context, + _configuration.buildOverscrollIndicator(context, child, details), + details, + ); + } + + // DESCRIPTION + + @override + Widget build(BuildContext context) { + assert(_position != null); + // _ScrollableScope must be placed above the BuildContext returned by notificationContext + // so that we can get this ScrollableState by doing the following: + // + // ScrollNotification notification; + // Scrollable.of(notification.context) + // + // Since notificationContext is pointing to _gestureDetectorKey.context, _ScrollableScope + // must be placed above the widget using it: RawGestureDetector + Widget result = _ScrollableScope( + scrollable: this, + position: position, + child: Listener( + onPointerSignal: _receivedPointerSignal, + child: RawGestureDetector( + key: _gestureDetectorKey, + gestures: _gestureRecognizers, + behavior: HitTestBehavior.opaque, + excludeFromSemantics: widget.excludeFromSemantics, + child: Semantics( + explicitChildNodes: !widget.excludeFromSemantics, + child: IgnorePointer( + key: _ignorePointerKey, + ignoring: _shouldIgnorePointer, + child: widget.viewportBuilder(context, position), + ), + ), + ), + ), + ); + + if (!widget.excludeFromSemantics) { + result = NotificationListener<ScrollMetricsNotification>( + onNotification: _handleScrollMetricsNotification, + child: _ScrollSemantics( + key: _scrollSemanticsKey, + position: position, + allowImplicitScrolling: _physics!.allowImplicitScrolling, + semanticChildCount: widget.semanticChildCount, + child: result, + ) + ); + } + + result = _buildChrome(context, result); + + // Selection is only enabled when there is a parent registrar. + final SelectionRegistrar? registrar = SelectionContainer.maybeOf(context); + if (registrar != null) { + result = _ScrollableSelectionHandler( + state: this, + position: position, + registrar: registrar, + child: result, + ); + } + + return result; + } + + // Returns the Future from calling ensureVisible for the ScrollPosition, as + // as well as this ScrollableState instance so its context can be used to + // check for other ancestor Scrollables in executing ensureVisible. + _EnsureVisibleResults _performEnsureVisible( + RenderObject object, { + double alignment = 0.0, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit, + RenderObject? targetRenderObject, + }) { + final Future<void> ensureVisibleFuture = position.ensureVisible( + object, + alignment: alignment, + duration: duration, + curve: curve, + alignmentPolicy: alignmentPolicy, + targetRenderObject: targetRenderObject, + ); + return (<Future<void>>[ ensureVisibleFuture ], this); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ScrollPosition>('position', _position)); + properties.add(DiagnosticsProperty<ScrollPhysics>('effective physics', _physics)); + } +} + +/// A widget to handle selection for a scrollable. +/// +/// This widget registers itself to the [registrar] and uses +/// [SelectionContainer] to collect selectables from its subtree. +class _ScrollableSelectionHandler extends StatefulWidget { + const _ScrollableSelectionHandler({ + required this.state, + required this.position, + required this.registrar, + required this.child, + }); + + final ScrollableState state; + final ScrollPosition position; + final Widget child; + final SelectionRegistrar registrar; + + @override + _ScrollableSelectionHandlerState createState() => _ScrollableSelectionHandlerState(); +} + +class _ScrollableSelectionHandlerState extends State<_ScrollableSelectionHandler> { + late _ScrollableSelectionContainerDelegate _selectionDelegate; + + @override + void initState() { + super.initState(); + _selectionDelegate = _ScrollableSelectionContainerDelegate( + state: widget.state, + position: widget.position, + ); + } + + @override + void didUpdateWidget(_ScrollableSelectionHandler oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.position != widget.position) { + _selectionDelegate.position = widget.position; + } + } + + @override + void dispose() { + _selectionDelegate.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return SelectionContainer( + registrar: widget.registrar, + delegate: _selectionDelegate, + child: widget.child, + ); + } +} + +/// This updater handles the case where the selectables change frequently, and +/// it optimizes toward scrolling updates. +/// +/// It keeps track of the drag start offset relative to scroll origin for every +/// selectable. The records are used to determine whether the selection is up to +/// date with the scroll position when it sends the drag update event to a +/// selectable. +class _ScrollableSelectionContainerDelegate extends MultiSelectableSelectionContainerDelegate { + _ScrollableSelectionContainerDelegate({ + required this.state, + required ScrollPosition position + }) : _position = position, + _autoScroller = EdgeDraggingAutoScroller(state, velocityScalar: _kDefaultSelectToScrollVelocityScalar) { + _position.addListener(_scheduleLayoutChange); + } + + // Pointer drag is a single point, it should not have a size. + static const double _kDefaultDragTargetSize = 0; + + // An eye-balled value for a smooth scrolling speed. + static const double _kDefaultSelectToScrollVelocityScalar = 30; + + final ScrollableState state; + final EdgeDraggingAutoScroller _autoScroller; + bool _scheduledLayoutChange = false; + Offset? _currentDragStartRelatedToOrigin; + Offset? _currentDragEndRelatedToOrigin; + + // The scrollable only auto scrolls if the selection starts in the scrollable. + bool _selectionStartsInScrollable = false; + + ScrollPosition get position => _position; + ScrollPosition _position; + set position(ScrollPosition other) { + if (other == _position) { + return; + } + _position.removeListener(_scheduleLayoutChange); + _position = other; + _position.addListener(_scheduleLayoutChange); + } + + // The layout will only be updated a frame later than position changes. + // Schedule PostFrameCallback to capture the accurate layout. + void _scheduleLayoutChange() { + if (_scheduledLayoutChange) { + return; + } + _scheduledLayoutChange = true; + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + if (!_scheduledLayoutChange) { + return; + } + _scheduledLayoutChange = false; + layoutDidChange(); + }, debugLabel: 'ScrollableSelectionContainer.layoutDidChange'); + } + + /// Stores the scroll offset when a scrollable receives the last + /// [SelectionEdgeUpdateEvent]. + /// + /// The stored scroll offset may be null if a scrollable never receives a + /// [SelectionEdgeUpdateEvent]. + /// + /// When a new [SelectionEdgeUpdateEvent] is dispatched to a selectable, this + /// updater checks the current scroll offset against the one stored in these + /// records. If the scroll offset is different, it synthesizes an opposite + /// [SelectionEdgeUpdateEvent] and dispatches the event before dispatching the + /// new event. + /// + /// For example, if a selectable receives an end [SelectionEdgeUpdateEvent] + /// and its scroll offset in the records is different from the current value, + /// it synthesizes a start [SelectionEdgeUpdateEvent] and dispatches it before + /// dispatching the original end [SelectionEdgeUpdateEvent]. + final Map<Selectable, double> _selectableStartEdgeUpdateRecords = <Selectable, double>{}; + final Map<Selectable, double> _selectableEndEdgeUpdateRecords = <Selectable, double>{}; + + @override + void didChangeSelectables() { + final Set<Selectable> selectableSet = selectables.toSet(); + _selectableStartEdgeUpdateRecords.removeWhere((Selectable key, double value) => !selectableSet.contains(key)); + _selectableEndEdgeUpdateRecords.removeWhere((Selectable key, double value) => !selectableSet.contains(key)); + super.didChangeSelectables(); + } + + @override + SelectionResult handleClearSelection(ClearSelectionEvent event) { + _selectableStartEdgeUpdateRecords.clear(); + _selectableEndEdgeUpdateRecords.clear(); + _currentDragStartRelatedToOrigin = null; + _currentDragEndRelatedToOrigin = null; + _selectionStartsInScrollable = false; + return super.handleClearSelection(event); + } + + @override + SelectionResult handleSelectionEdgeUpdate(SelectionEdgeUpdateEvent event) { + if (_currentDragEndRelatedToOrigin == null && _currentDragStartRelatedToOrigin == null) { + assert(!_selectionStartsInScrollable); + _selectionStartsInScrollable = _globalPositionInScrollable(event.globalPosition); + } + final Offset deltaToOrigin = _getDeltaToScrollOrigin(state); + if (event.type == SelectionEventType.endEdgeUpdate) { + _currentDragEndRelatedToOrigin = _inferPositionRelatedToOrigin(event.globalPosition); + final Offset endOffset = _currentDragEndRelatedToOrigin!.translate(-deltaToOrigin.dx, -deltaToOrigin.dy); + event = SelectionEdgeUpdateEvent.forEnd(globalPosition: endOffset, granularity: event.granularity); + } else { + _currentDragStartRelatedToOrigin = _inferPositionRelatedToOrigin(event.globalPosition); + final Offset startOffset = _currentDragStartRelatedToOrigin!.translate(-deltaToOrigin.dx, -deltaToOrigin.dy); + event = SelectionEdgeUpdateEvent.forStart(globalPosition: startOffset, granularity: event.granularity); + } + final SelectionResult result = super.handleSelectionEdgeUpdate(event); + + // Result may be pending if one of the selectable child is also a scrollable. + // In that case, the parent scrollable needs to wait for the child to finish + // scrolling. + if (result == SelectionResult.pending) { + _autoScroller.stopAutoScroll(); + return result; + } + if (_selectionStartsInScrollable) { + _autoScroller.startAutoScrollIfNecessary(_dragTargetFromEvent(event)); + if (_autoScroller.scrolling) { + return SelectionResult.pending; + } + } + return result; + } + + Offset _inferPositionRelatedToOrigin(Offset globalPosition) { + final RenderBox box = state.context.findRenderObject()! as RenderBox; + final Offset localPosition = box.globalToLocal(globalPosition); + if (!_selectionStartsInScrollable) { + // If the selection starts outside of the scrollable, selecting across the + // scrollable boundary will act as selecting the entire content in the + // scrollable. This logic move the offset to the 0.0 or infinity to cover + // the entire content if the input position is outside of the scrollable. + if (localPosition.dy < 0 || localPosition.dx < 0) { + return box.localToGlobal(Offset.zero); + } + if (localPosition.dy > box.size.height || localPosition.dx > box.size.width) { + return Offset.infinite; + } + } + final Offset deltaToOrigin = _getDeltaToScrollOrigin(state); + return box.localToGlobal(localPosition.translate(deltaToOrigin.dx, deltaToOrigin.dy)); + } + + /// Infers the [_currentDragStartRelatedToOrigin] and + /// [_currentDragEndRelatedToOrigin] from the geometry. + /// + /// This method is called after a select word and select all event where the + /// selection is triggered by none drag events. The + /// [_currentDragStartRelatedToOrigin] and [_currentDragEndRelatedToOrigin] + /// are essential to handle future [SelectionEdgeUpdateEvent]s. + void _updateDragLocationsFromGeometries({bool forceUpdateStart = true, bool forceUpdateEnd = true}) { + final Offset deltaToOrigin = _getDeltaToScrollOrigin(state); + final RenderBox box = state.context.findRenderObject()! as RenderBox; + final Matrix4 transform = box.getTransformTo(null); + if (currentSelectionStartIndex != -1 && (_currentDragStartRelatedToOrigin == null || forceUpdateStart)) { + final SelectionGeometry geometry = selectables[currentSelectionStartIndex].value; + assert(geometry.hasSelection); + final SelectionPoint start = geometry.startSelectionPoint!; + final Matrix4 childTransform = selectables[currentSelectionStartIndex].getTransformTo(box); + final Offset localDragStart = MatrixUtils.transformPoint( + childTransform, + start.localPosition + Offset(0, - start.lineHeight / 2), + ); + _currentDragStartRelatedToOrigin = MatrixUtils.transformPoint(transform, localDragStart + deltaToOrigin); + } + if (currentSelectionEndIndex != -1 && (_currentDragEndRelatedToOrigin == null || forceUpdateEnd)) { + final SelectionGeometry geometry = selectables[currentSelectionEndIndex].value; + assert(geometry.hasSelection); + final SelectionPoint end = geometry.endSelectionPoint!; + final Matrix4 childTransform = selectables[currentSelectionEndIndex].getTransformTo(box); + final Offset localDragEnd = MatrixUtils.transformPoint( + childTransform, + end.localPosition + Offset(0, - end.lineHeight / 2), + ); + _currentDragEndRelatedToOrigin = MatrixUtils.transformPoint(transform, localDragEnd + deltaToOrigin); + } + } + + @override + SelectionResult handleSelectAll(SelectAllSelectionEvent event) { + assert(!_selectionStartsInScrollable); + final SelectionResult result = super.handleSelectAll(event); + assert((currentSelectionStartIndex == -1) == (currentSelectionEndIndex == -1)); + if (currentSelectionStartIndex != -1) { + _updateDragLocationsFromGeometries(); + } + return result; + } + + @override + SelectionResult handleSelectWord(SelectWordSelectionEvent event) { + _selectionStartsInScrollable = _globalPositionInScrollable(event.globalPosition); + final SelectionResult result = super.handleSelectWord(event); + _updateDragLocationsFromGeometries(); + return result; + } + + @override + SelectionResult handleGranularlyExtendSelection(GranularlyExtendSelectionEvent event) { + final SelectionResult result = super.handleGranularlyExtendSelection(event); + // The selection geometry may not have the accurate offset for the edges + // that are outside of the viewport whose transform may not be valid. Only + // the edge this event is updating is sure to be accurate. + _updateDragLocationsFromGeometries( + forceUpdateStart: !event.isEnd, + forceUpdateEnd: event.isEnd, + ); + if (_selectionStartsInScrollable) { + _jumpToEdge(event.isEnd); + } + return result; + } + + @override + SelectionResult handleDirectionallyExtendSelection(DirectionallyExtendSelectionEvent event) { + final SelectionResult result = super.handleDirectionallyExtendSelection(event); + // The selection geometry may not have the accurate offset for the edges + // that are outside of the viewport whose transform may not be valid. Only + // the edge this event is updating is sure to be accurate. + _updateDragLocationsFromGeometries( + forceUpdateStart: !event.isEnd, + forceUpdateEnd: event.isEnd, + ); + if (_selectionStartsInScrollable) { + _jumpToEdge(event.isEnd); + } + return result; + } + + void _jumpToEdge(bool isExtent) { + final Selectable selectable; + final double? lineHeight; + final SelectionPoint? edge; + if (isExtent) { + selectable = selectables[currentSelectionEndIndex]; + edge = selectable.value.endSelectionPoint; + lineHeight = selectable.value.endSelectionPoint!.lineHeight; + } else { + selectable = selectables[currentSelectionStartIndex]; + edge = selectable.value.startSelectionPoint; + lineHeight = selectable.value.startSelectionPoint?.lineHeight; + } + if (lineHeight == null || edge == null) { + return; + } + final RenderBox scrollableBox = state.context.findRenderObject()! as RenderBox; + final Matrix4 transform = selectable.getTransformTo(scrollableBox); + final Offset edgeOffsetInScrollableCoordinates = MatrixUtils.transformPoint(transform, edge.localPosition); + final Rect scrollableRect = Rect.fromLTRB(0, 0, scrollableBox.size.width, scrollableBox.size.height); + switch (state.axisDirection) { + case AxisDirection.up: + final double edgeBottom = edgeOffsetInScrollableCoordinates.dy; + final double edgeTop = edgeOffsetInScrollableCoordinates.dy - lineHeight; + if (edgeBottom >= scrollableRect.bottom && edgeTop <= scrollableRect.top) { + return; + } + if (edgeBottom > scrollableRect.bottom) { + position.jumpTo(position.pixels + scrollableRect.bottom - edgeBottom); + return; + } + if (edgeTop < scrollableRect.top) { + position.jumpTo(position.pixels + scrollableRect.top - edgeTop); + } + return; + case AxisDirection.right: + final double edge = edgeOffsetInScrollableCoordinates.dx; + if (edge >= scrollableRect.right && edge <= scrollableRect.left) { + return; + } + if (edge > scrollableRect.right) { + position.jumpTo(position.pixels + edge - scrollableRect.right); + return; + } + if (edge < scrollableRect.left) { + position.jumpTo(position.pixels + edge - scrollableRect.left); + } + return; + case AxisDirection.down: + final double edgeBottom = edgeOffsetInScrollableCoordinates.dy; + final double edgeTop = edgeOffsetInScrollableCoordinates.dy - lineHeight; + if (edgeBottom >= scrollableRect.bottom && edgeTop <= scrollableRect.top) { + return; + } + if (edgeBottom > scrollableRect.bottom) { + position.jumpTo(position.pixels + edgeBottom - scrollableRect.bottom); + return; + } + if (edgeTop < scrollableRect.top) { + position.jumpTo(position.pixels + edgeTop - scrollableRect.top); + } + return; + case AxisDirection.left: + final double edge = edgeOffsetInScrollableCoordinates.dx; + if (edge >= scrollableRect.right && edge <= scrollableRect.left) { + return; + } + if (edge > scrollableRect.right) { + position.jumpTo(position.pixels + scrollableRect.right - edge); + return; + } + if (edge < scrollableRect.left) { + position.jumpTo(position.pixels + scrollableRect.left - edge); + } + return; + } + } + + bool _globalPositionInScrollable(Offset globalPosition) { + final RenderBox box = state.context.findRenderObject()! as RenderBox; + final Offset localPosition = box.globalToLocal(globalPosition); + final Rect rect = Rect.fromLTWH(0, 0, box.size.width, box.size.height); + return rect.contains(localPosition); + } + + Rect _dragTargetFromEvent(SelectionEdgeUpdateEvent event) { + return Rect.fromCenter(center: event.globalPosition, width: _kDefaultDragTargetSize, height: _kDefaultDragTargetSize); + } + + @override + SelectionResult dispatchSelectionEventToChild(Selectable selectable, SelectionEvent event) { + switch (event.type) { + case SelectionEventType.startEdgeUpdate: + _selectableStartEdgeUpdateRecords[selectable] = state.position.pixels; + ensureChildUpdated(selectable); + case SelectionEventType.endEdgeUpdate: + _selectableEndEdgeUpdateRecords[selectable] = state.position.pixels; + ensureChildUpdated(selectable); + case SelectionEventType.granularlyExtendSelection: + case SelectionEventType.directionallyExtendSelection: + ensureChildUpdated(selectable); + _selectableStartEdgeUpdateRecords[selectable] = state.position.pixels; + _selectableEndEdgeUpdateRecords[selectable] = state.position.pixels; + case SelectionEventType.clear: + _selectableEndEdgeUpdateRecords.remove(selectable); + _selectableStartEdgeUpdateRecords.remove(selectable); + case SelectionEventType.selectAll: + case SelectionEventType.selectWord: + _selectableEndEdgeUpdateRecords[selectable] = state.position.pixels; + _selectableStartEdgeUpdateRecords[selectable] = state.position.pixels; + } + return super.dispatchSelectionEventToChild(selectable, event); + } + + @override + void ensureChildUpdated(Selectable selectable) { + final double newRecord = state.position.pixels; + final double? previousStartRecord = _selectableStartEdgeUpdateRecords[selectable]; + if (_currentDragStartRelatedToOrigin != null && + (previousStartRecord == null || (newRecord - previousStartRecord).abs() > precisionErrorTolerance)) { + // Make sure the selectable has up to date events. + final Offset deltaToOrigin = _getDeltaToScrollOrigin(state); + final Offset startOffset = _currentDragStartRelatedToOrigin!.translate(-deltaToOrigin.dx, -deltaToOrigin.dy); + selectable.dispatchSelectionEvent(SelectionEdgeUpdateEvent.forStart(globalPosition: startOffset)); + // Make sure we track that we have synthesized a start event for this selectable, + // so we don't synthesize events unnecessarily. + _selectableStartEdgeUpdateRecords[selectable] = state.position.pixels; + } + final double? previousEndRecord = _selectableEndEdgeUpdateRecords[selectable]; + if (_currentDragEndRelatedToOrigin != null && + (previousEndRecord == null || (newRecord - previousEndRecord).abs() > precisionErrorTolerance)) { + // Make sure the selectable has up to date events. + final Offset deltaToOrigin = _getDeltaToScrollOrigin(state); + final Offset endOffset = _currentDragEndRelatedToOrigin!.translate(-deltaToOrigin.dx, -deltaToOrigin.dy); + selectable.dispatchSelectionEvent(SelectionEdgeUpdateEvent.forEnd(globalPosition: endOffset)); + // Make sure we track that we have synthesized an end event for this selectable, + // so we don't synthesize events unnecessarily. + _selectableEndEdgeUpdateRecords[selectable] = state.position.pixels; + } + } + + @override + void dispose() { + _selectableStartEdgeUpdateRecords.clear(); + _selectableEndEdgeUpdateRecords.clear(); + _scheduledLayoutChange = false; + _autoScroller.stopAutoScroll(); + super.dispose(); + } +} + +Offset _getDeltaToScrollOrigin(ScrollableState scrollableState) { + switch (scrollableState.axisDirection) { + case AxisDirection.down: + return Offset(0, scrollableState.position.pixels); + case AxisDirection.up: + return Offset(0, -scrollableState.position.pixels); + case AxisDirection.left: + return Offset(-scrollableState.position.pixels, 0); + case AxisDirection.right: + return Offset(scrollableState.position.pixels, 0); + } +} + +/// With [_ScrollSemantics] certain child [SemanticsNode]s can be +/// excluded from the scrollable area for semantics purposes. +/// +/// Nodes, that are to be excluded, have to be tagged with +/// [RenderViewport.excludeFromScrolling] and the [RenderAbstractViewport] in +/// use has to add the [RenderViewport.useTwoPaneSemantics] tag to its +/// [SemanticsConfiguration] by overriding +/// [RenderObject.describeSemanticsConfiguration]. +/// +/// If the tag [RenderViewport.useTwoPaneSemantics] is present on the viewport, +/// two semantics nodes will be used to represent the [Scrollable]: The outer +/// node will contain all children, that are excluded from scrolling. The inner +/// node, which is annotated with the scrolling actions, will house the +/// scrollable children. +class _ScrollSemantics extends SingleChildRenderObjectWidget { + const _ScrollSemantics({ + super.key, + required this.position, + required this.allowImplicitScrolling, + required this.semanticChildCount, + super.child, + }) : assert(semanticChildCount == null || semanticChildCount >= 0); + + final ScrollPosition position; + final bool allowImplicitScrolling; + final int? semanticChildCount; + + @override + _RenderScrollSemantics createRenderObject(BuildContext context) { + return _RenderScrollSemantics( + position: position, + allowImplicitScrolling: allowImplicitScrolling, + semanticChildCount: semanticChildCount, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderScrollSemantics renderObject) { + renderObject + ..allowImplicitScrolling = allowImplicitScrolling + ..position = position + ..semanticChildCount = semanticChildCount; + } +} + +class _RenderScrollSemantics extends RenderProxyBox { + _RenderScrollSemantics({ + required ScrollPosition position, + required bool allowImplicitScrolling, + required int? semanticChildCount, + RenderBox? child, + }) : _position = position, + _allowImplicitScrolling = allowImplicitScrolling, + _semanticChildCount = semanticChildCount, + super(child) { + position.addListener(markNeedsSemanticsUpdate); + } + + /// Whether this render object is excluded from the semantic tree. + ScrollPosition get position => _position; + ScrollPosition _position; + set position(ScrollPosition value) { + if (value == _position) { + return; + } + _position.removeListener(markNeedsSemanticsUpdate); + _position = value; + _position.addListener(markNeedsSemanticsUpdate); + markNeedsSemanticsUpdate(); + } + + /// Whether this node can be scrolled implicitly. + bool get allowImplicitScrolling => _allowImplicitScrolling; + bool _allowImplicitScrolling; + set allowImplicitScrolling(bool value) { + if (value == _allowImplicitScrolling) { + return; + } + _allowImplicitScrolling = value; + markNeedsSemanticsUpdate(); + } + + int? get semanticChildCount => _semanticChildCount; + int? _semanticChildCount; + set semanticChildCount(int? value) { + if (value == semanticChildCount) { + return; + } + _semanticChildCount = value; + markNeedsSemanticsUpdate(); + } + + @override + void describeSemanticsConfiguration(SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.isSemanticBoundary = true; + if (position.haveDimensions) { + config + ..hasImplicitScrolling = allowImplicitScrolling + ..scrollPosition = _position.pixels + ..scrollExtentMax = _position.maxScrollExtent + ..scrollExtentMin = _position.minScrollExtent + ..scrollChildCount = semanticChildCount; + } + } + + SemanticsNode? _innerNode; + + @override + void assembleSemanticsNode(SemanticsNode node, SemanticsConfiguration config, Iterable<SemanticsNode> children) { + if (children.isEmpty || !children.first.isTagged(RenderViewport.useTwoPaneSemantics)) { + _innerNode = null; + super.assembleSemanticsNode(node, config, children); + return; + } + + (_innerNode ??= SemanticsNode(showOnScreen: showOnScreen)).rect = node.rect; + + int? firstVisibleIndex; + final List<SemanticsNode> excluded = <SemanticsNode>[_innerNode!]; + final List<SemanticsNode> included = <SemanticsNode>[]; + for (final SemanticsNode child in children) { + assert(child.isTagged(RenderViewport.useTwoPaneSemantics)); + if (child.isTagged(RenderViewport.excludeFromScrolling)) { + excluded.add(child); + } else { + if (!child.hasFlag(SemanticsFlag.isHidden)) { + firstVisibleIndex ??= child.indexInParent; + } + included.add(child); + } + } + config.scrollIndex = firstVisibleIndex; + node.updateWith(config: null, childrenInInversePaintOrder: excluded); + _innerNode!.updateWith(config: config, childrenInInversePaintOrder: included); + } + + @override + void clearSemantics() { + super.clearSemantics(); + _innerNode = null; + } +} + +// Not using a RestorableDouble because we want to allow null values and override +// [enabled]. +class _RestorableScrollOffset extends RestorableValue<double?> { + @override + double? createDefaultValue() => null; + + @override + void didUpdateValue(double? oldValue) { + notifyListeners(); + } + + @override + double fromPrimitives(Object? data) { + return data! as double; + } + + @override + Object? toPrimitives() { + return value; + } + + @override + bool get enabled => value != null; +} + +// 2D SCROLLING + +/// Specifies how to configure the [DragGestureRecognizer]s of a +/// [TwoDimensionalScrollable]. +// TODO(Piinks): Add sample code, https://github.com/flutter/flutter/issues/126298 +enum DiagonalDragBehavior { + /// This behavior will not allow for any diagonal scrolling. + /// + /// Drag gestures in one direction or the other will lock the input axis until + /// the gesture is released. + none, + + /// This behavior will only allow diagonal scrolling on a weighted + /// scale per gesture event. + /// + /// This means that after initially evaluating the drag gesture, the weighted + /// evaluation (based on [kTouchSlop]) stands until the gesture is released. + weightedEvent, + + /// This behavior will only allow diagonal scrolling on a weighted + /// scale that is evaluated throughout a gesture event. + /// + /// This means that during each update to the drag gesture, the scrolling + /// axis will be allowed to scroll diagonally if it exceeds the + /// [kTouchSlop]. + weightedContinuous, + + /// This behavior allows free movement in any and all directions when + /// dragging. + free, +} + +/// A widget that manages scrolling in both the vertical and horizontal +/// dimensions and informs the [TwoDimensionalViewport] through which the +/// content is viewed. +/// +/// [TwoDimensionalScrollable] implements the interaction model for a scrollable +/// widget in both the vertical and horizontal axes, including gesture +/// recognition, but does not have an opinion about how the +/// [TwoDimensionalViewport], which actually displays the children, is +/// constructed. +/// +/// It's rare to construct a [TwoDimensionalScrollable] directly. Instead, +/// consider subclassing [TwoDimensionalScrollView], which combines scrolling, +/// viewporting, and a layout model in both dimensions. +/// +/// See also: +/// +/// * [TwoDimensionalScrollView], an abstract base class for displaying a +/// scrolling array of children in both directions. +/// * [TwoDimensionalViewport], which can be used to customize the child layout +/// model. +class TwoDimensionalScrollable extends StatefulWidget { + /// Creates a widget that scrolls in two dimensions. + /// + /// The [horizontalDetails], [verticalDetails], and [viewportBuilder] must not + /// be null. + const TwoDimensionalScrollable({ + super.key, + required this.horizontalDetails, + required this.verticalDetails, + required this.viewportBuilder, + this.incrementCalculator, + this.restorationId, + this.excludeFromSemantics = false, + this.diagonalDragBehavior = DiagonalDragBehavior.none, + this.dragStartBehavior = DragStartBehavior.start, + }); + + /// How scrolling gestures should lock to one axis, or allow free movement + /// in both axes. + final DiagonalDragBehavior diagonalDragBehavior; + + /// The configuration of the horizontal [Scrollable]. + /// + /// These [ScrollableDetails] can be used to set the [AxisDirection], + /// [ScrollController], [ScrollPhysics] and more for the horizontal axis. + final ScrollableDetails horizontalDetails; + + /// The configuration of the vertical [Scrollable]. + /// + /// These [ScrollableDetails] can be used to set the [AxisDirection], + /// [ScrollController], [ScrollPhysics] and more for the vertical axis. + final ScrollableDetails verticalDetails; + + /// Builds the viewport through which the scrollable content is displayed. + /// + /// A [TwoDimensionalViewport] uses two given [ViewportOffset]s to determine + /// which part of its content is actually visible through the viewport. + /// + /// See also: + /// + /// * [TwoDimensionalViewport], which is a viewport that displays a span of + /// widgets in both dimensions. + final TwoDimensionalViewportBuilder viewportBuilder; + + /// {@macro flutter.widgets.Scrollable.incrementCalculator} + /// + /// This value applies in both axes. + final ScrollIncrementCalculator? incrementCalculator; + + /// {@macro flutter.widgets.scrollable.restorationId} + /// + /// Internally, the [TwoDimensionalScrollable] will introduce a + /// [RestorationScope] that will be assigned this value. The two [Scrollable]s + /// within will then be given unique IDs within this scope. + final String? restorationId; + + /// {@macro flutter.widgets.scrollable.excludeFromSemantics} + /// + /// This value applies to both axes. + final bool excludeFromSemantics; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + /// + /// This value applies in both axes. + final DragStartBehavior dragStartBehavior; + + @override + State<TwoDimensionalScrollable> createState() => TwoDimensionalScrollableState(); + + /// The state from the closest instance of this class that encloses the given + /// context, or null if none is found. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// TwoDimensionalScrollableState? scrollable = TwoDimensionalScrollable.maybeOf(context); + /// ``` + /// + /// Calling this method will create a dependency on the closest + /// [TwoDimensionalScrollable] in the [context]. The internal [Scrollable]s + /// can be accessed through [TwoDimensionalScrollableState.verticalScrollable] + /// and [TwoDimensionalScrollableState.horizontalScrollable]. + /// + /// Alternatively, [Scrollable.maybeOf] can be used by providing the desired + /// [Axis] to the `axis` parameter. + /// + /// See also: + /// + /// * [TwoDimensionalScrollable.of], which is similar to this method, but + /// asserts if no [Scrollable] ancestor is found. + static TwoDimensionalScrollableState? maybeOf(BuildContext context) { + final _TwoDimensionalScrollableScope? widget = context.dependOnInheritedWidgetOfExactType<_TwoDimensionalScrollableScope>(); + return widget?.twoDimensionalScrollable; + } + + /// The state from the closest instance of this class that encloses the given + /// context. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// TwoDimensionalScrollableState scrollable = TwoDimensionalScrollable.of(context); + /// ``` + /// + /// Calling this method will create a dependency on the closest + /// [TwoDimensionalScrollable] in the [context]. The internal [Scrollable]s + /// can be accessed through [TwoDimensionalScrollableState.verticalScrollable] + /// and [TwoDimensionalScrollableState.horizontalScrollable]. + /// + /// If no [TwoDimensionalScrollable] ancestor is found, then this method will + /// assert in debug mode, and throw an exception in release mode. + /// + /// Alternatively, [Scrollable.of] can be used by providing the desired [Axis] + /// to the `axis` parameter. + /// + /// See also: + /// + /// * [TwoDimensionalScrollable.maybeOf], which is similar to this method, + /// but returns null if no [TwoDimensionalScrollable] ancestor is found. + static TwoDimensionalScrollableState of(BuildContext context) { + final TwoDimensionalScrollableState? scrollableState = maybeOf(context); + assert(() { + if (scrollableState == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'TwoDimensionalScrollable.of() was called with a context that does ' + 'not contain a TwoDimensionalScrollable widget.\n' + ), + ErrorDescription( + 'No TwoDimensionalScrollable widget ancestor could be found starting ' + 'from the context that was passed to TwoDimensionalScrollable.of(). ' + 'This can happen because you are using a widget that looks for a ' + 'TwoDimensionalScrollable ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ), + ]); + } + return true; + }()); + return scrollableState!; + } +} + +/// State object for a [TwoDimensionalScrollable] widget. +/// +/// To manipulate one of the internal [Scrollable] widget's scroll position, use +/// the object obtained from the [verticalScrollable] or [horizontalScrollable] +/// property. +/// +/// To be informed of when a [TwoDimensionalScrollable] widget is scrolling, +/// use a [NotificationListener] to listen for [ScrollNotification]s. +/// Both axes will have the same viewport depth since there is only one +/// viewport, and so should be differentiated by the [Axis] of the +/// [ScrollMetrics] provided by the notification. +class TwoDimensionalScrollableState extends State<TwoDimensionalScrollable> { + ScrollController? _verticalFallbackController; + ScrollController? _horizontalFallbackController; + final GlobalKey<ScrollableState> _verticalOuterScrollableKey = GlobalKey<ScrollableState>(); + final GlobalKey<ScrollableState> _horizontalInnerScrollableKey = GlobalKey<ScrollableState>(); + + /// The [ScrollableState] of the vertical axis. + /// + /// Accessible by calling [TwoDimensionalScrollable.of]. + /// + /// Alternatively, [Scrollable.of] can be used by providing [Axis.vertical] + /// to the `axis` parameter. + ScrollableState get verticalScrollable { + assert(_verticalOuterScrollableKey.currentState != null); + return _verticalOuterScrollableKey.currentState!; + } + + /// The [ScrollableState] of the horizontal axis. + /// + /// Accessible by calling [TwoDimensionalScrollable.of]. + /// + /// Alternatively, [Scrollable.of] can be used by providing [Axis.horizontal] + /// to the `axis` parameter. + ScrollableState get horizontalScrollable { + assert(_horizontalInnerScrollableKey.currentState != null); + return _horizontalInnerScrollableKey.currentState!; + } + + @override + void initState() { + if (widget.verticalDetails.controller == null) { + _verticalFallbackController = ScrollController(); + } + if (widget.horizontalDetails.controller == null) { + _horizontalFallbackController = ScrollController(); + } + super.initState(); + } + + @override + void didUpdateWidget(TwoDimensionalScrollable oldWidget) { + super.didUpdateWidget(oldWidget); + // Handle changes in the provided/fallback scroll controllers + + // Vertical + if (oldWidget.verticalDetails.controller != widget.verticalDetails.controller) { + if (oldWidget.verticalDetails.controller == null) { + // The old controller was null, meaning the fallback cannot be null. + // Dispose of the fallback. + assert(_verticalFallbackController != null); + assert(widget.verticalDetails.controller != null); + _verticalFallbackController!.dispose(); + _verticalFallbackController = null; + } else if (widget.verticalDetails.controller == null) { + // If the new controller is null, we need to set up the fallback + // ScrollController. + assert(_verticalFallbackController == null); + _verticalFallbackController = ScrollController(); + } + } + + // Horizontal + if (oldWidget.horizontalDetails.controller != widget.horizontalDetails.controller) { + if (oldWidget.horizontalDetails.controller == null) { + // The old controller was null, meaning the fallback cannot be null. + // Dispose of the fallback. + assert(_horizontalFallbackController != null); + assert(widget.horizontalDetails.controller != null); + _horizontalFallbackController!.dispose(); + _horizontalFallbackController = null; + } else if (widget.horizontalDetails.controller == null) { + // If the new controller is null, we need to set up the fallback + // ScrollController. + assert(_horizontalFallbackController == null); + _horizontalFallbackController = ScrollController(); + } + } + } + + @override + Widget build(BuildContext context) { + assert( + axisDirectionToAxis(widget.verticalDetails.direction) == Axis.vertical, + 'TwoDimensionalScrollable.verticalDetails are not Axis.vertical.' + ); + assert( + axisDirectionToAxis(widget.horizontalDetails.direction) == Axis.horizontal, + 'TwoDimensionalScrollable.horizontalDetails are not Axis.horizontal.' + ); + + final Widget result = RestorationScope( + restorationId: widget.restorationId, + child: _VerticalOuterDimension( + key: _verticalOuterScrollableKey, + // For gesture forwarding + horizontalKey: _horizontalInnerScrollableKey, + axisDirection: widget.verticalDetails.direction, + controller: widget.verticalDetails.controller + ?? _verticalFallbackController!, + physics: widget.verticalDetails.physics, + clipBehavior: widget.verticalDetails.clipBehavior + ?? widget.verticalDetails.decorationClipBehavior + ?? Clip.hardEdge, + incrementCalculator: widget.incrementCalculator, + excludeFromSemantics: widget.excludeFromSemantics, + restorationId: 'OuterVerticalTwoDimensionalScrollable', + dragStartBehavior: widget.dragStartBehavior, + diagonalDragBehavior: widget.diagonalDragBehavior, + viewportBuilder: (BuildContext context, ViewportOffset verticalOffset) { + return _HorizontalInnerDimension( + key: _horizontalInnerScrollableKey, + axisDirection: widget.horizontalDetails.direction, + controller: widget.horizontalDetails.controller + ?? _horizontalFallbackController!, + physics: widget.horizontalDetails.physics, + clipBehavior: widget.horizontalDetails.clipBehavior + ?? widget.horizontalDetails.decorationClipBehavior + ?? Clip.hardEdge, + incrementCalculator: widget.incrementCalculator, + excludeFromSemantics: widget.excludeFromSemantics, + restorationId: 'InnerHorizontalTwoDimensionalScrollable', + dragStartBehavior: widget.dragStartBehavior, + diagonalDragBehavior: widget.diagonalDragBehavior, + viewportBuilder: (BuildContext context, ViewportOffset horizontalOffset) { + return widget.viewportBuilder(context, verticalOffset, horizontalOffset); + }, + ); + } + ) + ); + + // TODO(Piinks): Build scrollbars for 2 dimensions instead of 1, + // https://github.com/flutter/flutter/issues/122348 + + return _TwoDimensionalScrollableScope( + twoDimensionalScrollable: this, + child: result, + ); + } + + @override + void dispose() { + _verticalFallbackController?.dispose(); + _horizontalFallbackController?.dispose(); + super.dispose(); + } +} + +// Enable TwoDimensionalScrollable.of() to work as if +// TwoDimensionalScrollableState was an inherited widget. +// TwoDimensionalScrollableState.build() always rebuilds its +// _TwoDimensionalScrollableScope. +class _TwoDimensionalScrollableScope extends InheritedWidget { + const _TwoDimensionalScrollableScope({ + required this.twoDimensionalScrollable, + required super.child, + }); + + final TwoDimensionalScrollableState twoDimensionalScrollable; + + @override + bool updateShouldNotify(_TwoDimensionalScrollableScope old) => false; +} + +// Vertical outer scrollable of 2D scrolling +class _VerticalOuterDimension extends Scrollable { + const _VerticalOuterDimension({ + super.key, + required this.horizontalKey, + required super.viewportBuilder, + required super.axisDirection, + super.controller, + super.physics, + super.clipBehavior, + super.incrementCalculator, + super.excludeFromSemantics, + super.dragStartBehavior, + super.restorationId, + this.diagonalDragBehavior = DiagonalDragBehavior.none, + }) : assert(axisDirection == AxisDirection.up || axisDirection == AxisDirection.down); + + final DiagonalDragBehavior diagonalDragBehavior; + final GlobalKey<ScrollableState> horizontalKey; + + @override + _VerticalOuterDimensionState createState() => _VerticalOuterDimensionState(); +} + +class _VerticalOuterDimensionState extends ScrollableState { + DiagonalDragBehavior get diagonalDragBehavior => (widget as _VerticalOuterDimension).diagonalDragBehavior; + ScrollableState get horizontalScrollable => (widget as _VerticalOuterDimension).horizontalKey.currentState!; + + Axis? lockedAxis; + Offset? lastDragOffset; + + // Implemented in the _HorizontalInnerDimension instead. + @override + _EnsureVisibleResults _performEnsureVisible( + RenderObject object, { + double alignment = 0.0, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit, + RenderObject? targetRenderObject, + }) { + assert( + false, + 'The _performEnsureVisible method was called for the vertical scrollable ' + 'of a TwoDimensionalScrollable. This should not happen as the horizontal ' + 'scrollable handles both axes.' + ); + return (<Future<void>>[], this); + } + + void _evaluateLockedAxis(Offset offset) { + assert(lastDragOffset != null); + final Offset offsetDelta = lastDragOffset! - offset; + final double axisDifferential = offsetDelta.dx.abs() - offsetDelta.dy.abs(); + if (axisDifferential.abs() >= kTouchSlop) { + // We have single axis winner. + lockedAxis = axisDifferential > 0.0 ? Axis.horizontal : Axis.vertical; + } else { + lockedAxis = null; + } + } + + @override + void _handleDragDown(DragDownDetails details) { + switch (diagonalDragBehavior) { + case DiagonalDragBehavior.none: + break; + case DiagonalDragBehavior.weightedEvent: + case DiagonalDragBehavior.weightedContinuous: + case DiagonalDragBehavior.free: + // Initiate hold. If one or the other wins the gesture, cancel the + // opposite axis. + horizontalScrollable._handleDragDown(details); + } + super._handleDragDown(details); + } + + @override + void _handleDragStart(DragStartDetails details) { + lastDragOffset = details.globalPosition; + switch (diagonalDragBehavior) { + case DiagonalDragBehavior.none: + break; + case DiagonalDragBehavior.free: + // Prepare to scroll both. + // vertical - will call super below after switch. + horizontalScrollable._handleDragStart(details); + case DiagonalDragBehavior.weightedEvent: + case DiagonalDragBehavior.weightedContinuous: + // See if one axis wins the drag. + _evaluateLockedAxis(details.globalPosition); + switch (lockedAxis) { + case null: + // Prepare to scroll both, null means no winner yet. + // vertical - will call super below after switch. + horizontalScrollable._handleDragStart(details); + case Axis.horizontal: + // Prepare to scroll horizontally. + horizontalScrollable._handleDragStart(details); + return; + case Axis.vertical: + // Prepare to scroll vertically - will call super below after switch. + } + } + super._handleDragStart(details); + } + + @override + void _handleDragUpdate(DragUpdateDetails details) { + final DragUpdateDetails verticalDragDetails = DragUpdateDetails( + sourceTimeStamp: details.sourceTimeStamp, + delta: Offset(0.0, details.delta.dy), + primaryDelta: details.delta.dy, + globalPosition: details.globalPosition, + localPosition: details.localPosition, + ); + final DragUpdateDetails horizontalDragDetails = DragUpdateDetails( + sourceTimeStamp: details.sourceTimeStamp, + delta: Offset(details.delta.dx, 0.0), + primaryDelta: details.delta.dx, + globalPosition: details.globalPosition, + localPosition: details.localPosition, + ); + + switch (diagonalDragBehavior) { + case DiagonalDragBehavior.none: + // Default gesture handling from super class. + super._handleDragUpdate(verticalDragDetails); + return; + case DiagonalDragBehavior.free: + // Scroll both axes + horizontalScrollable._handleDragUpdate(horizontalDragDetails); + super._handleDragUpdate(verticalDragDetails); + return; + case DiagonalDragBehavior.weightedContinuous: + // Re-evaluate locked axis for every update. + _evaluateLockedAxis(details.globalPosition); + lastDragOffset = details.globalPosition; + case DiagonalDragBehavior.weightedEvent: + // Lock axis only once per gesture. + if (lockedAxis == null && lastDragOffset != null) { + // A winner has not been declared yet. + // See if one axis has won the drag. + _evaluateLockedAxis(details.globalPosition); + } + } + switch (lockedAxis) { + case null: + // Scroll both - vertical after switch + horizontalScrollable._handleDragUpdate(horizontalDragDetails); + case Axis.horizontal: + // Scroll horizontally + horizontalScrollable._handleDragUpdate(horizontalDragDetails); + return; + case Axis.vertical: + // Scroll vertically - after switch + } + super._handleDragUpdate(verticalDragDetails); + } + + @override + void _handleDragEnd(DragEndDetails details) { + lastDragOffset = null; + lockedAxis = null; + final double dx = details.velocity.pixelsPerSecond.dx; + final double dy = details.velocity.pixelsPerSecond.dy; + final DragEndDetails verticalDragDetails = DragEndDetails( + velocity: Velocity(pixelsPerSecond: Offset(0.0, dy)), + primaryVelocity: dy, + ); + final DragEndDetails horizontalDragDetails = DragEndDetails( + velocity: Velocity(pixelsPerSecond: Offset(dx, 0.0)), + primaryVelocity: dx, + ); + + switch (diagonalDragBehavior) { + case DiagonalDragBehavior.none: + break; + case DiagonalDragBehavior.weightedEvent: + case DiagonalDragBehavior.weightedContinuous: + case DiagonalDragBehavior.free: + horizontalScrollable._handleDragEnd(horizontalDragDetails); + } + super._handleDragEnd(verticalDragDetails); + } + + @override + void _handleDragCancel() { + lastDragOffset = null; + lockedAxis = null; + switch (diagonalDragBehavior) { + case DiagonalDragBehavior.none: + break; + case DiagonalDragBehavior.weightedEvent: + case DiagonalDragBehavior.weightedContinuous: + case DiagonalDragBehavior.free: + horizontalScrollable._handleDragCancel(); + } + super._handleDragCancel(); + } + + @override + void setCanDrag(bool value) { + switch (diagonalDragBehavior) { + case DiagonalDragBehavior.none: + // If we aren't scrolling diagonally, the default drag gesture recognizer + // is used. + super.setCanDrag(value); + return; + case DiagonalDragBehavior.weightedEvent: + case DiagonalDragBehavior.weightedContinuous: + case DiagonalDragBehavior.free: + if (value) { + // Replaces the typical vertical/horizontal drag gesture recognizers + // with a pan gesture recognizer to allow bidirectional scrolling. + // Based on the diagonalDragBehavior, valid horizontal deltas are + // applied to this scrollable, while vertical deltas are routed to + // the vertical scrollable. + _gestureRecognizers = <Type, GestureRecognizerFactory>{ + PanGestureRecognizer: GestureRecognizerFactoryWithHandlers<PanGestureRecognizer>( + () => PanGestureRecognizer(supportedDevices: _configuration.dragDevices), + (PanGestureRecognizer instance) { + instance + ..onDown = _handleDragDown + ..onStart = _handleDragStart + ..onUpdate = _handleDragUpdate + ..onEnd = _handleDragEnd + ..onCancel = _handleDragCancel + ..minFlingDistance = _physics?.minFlingDistance + ..minFlingVelocity = _physics?.minFlingVelocity + ..maxFlingVelocity = _physics?.maxFlingVelocity + ..velocityTrackerBuilder = _configuration.velocityTrackerBuilder(context) + ..dragStartBehavior = widget.dragStartBehavior + ..gestureSettings = _mediaQueryGestureSettings; + }, + ), + }; + // Cancel the active hold/drag (if any) because the gesture recognizers + // will soon be disposed by our RawGestureDetector, and we won't be + // receiving pointer up events to cancel the hold/drag. + _handleDragCancel(); + _lastCanDrag = value; + _lastAxisDirection = widget.axis; + if (_gestureDetectorKey.currentState != null) { + _gestureDetectorKey.currentState!.replaceGestureRecognizers(_gestureRecognizers); + } + } + return; + } + } + + @override + Widget _buildChrome(BuildContext context, Widget child) { + final ScrollableDetails details = ScrollableDetails( + direction: widget.axisDirection, + controller: _effectiveScrollController, + clipBehavior: widget.clipBehavior, + ); + // Skip building a scrollbar here, the dual scrollbar is added in + // TwoDimensionalScrollableState. + return _configuration.buildOverscrollIndicator(context, child, details); + } +} + +// Horizontal inner scrollable of 2D scrolling +class _HorizontalInnerDimension extends Scrollable { + const _HorizontalInnerDimension({ + super.key, + required super.viewportBuilder, + required super.axisDirection, + super.controller, + super.physics, + super.clipBehavior, + super.incrementCalculator, + super.excludeFromSemantics, + super.dragStartBehavior, + super.restorationId, + this.diagonalDragBehavior = DiagonalDragBehavior.none, + }) : assert(axisDirection == AxisDirection.left || axisDirection == AxisDirection.right); + + final DiagonalDragBehavior diagonalDragBehavior; + + @override + _HorizontalInnerDimensionState createState() => _HorizontalInnerDimensionState(); +} + +class _HorizontalInnerDimensionState extends ScrollableState { + late ScrollableState verticalScrollable; + + DiagonalDragBehavior get diagonalDragBehavior => (widget as _HorizontalInnerDimension).diagonalDragBehavior; + + @override + void didChangeDependencies() { + verticalScrollable = Scrollable.of(context); + assert(axisDirectionToAxis(verticalScrollable.axisDirection) == Axis.vertical); + super.didChangeDependencies(); + } + + // Returns the Future from calling ensureVisible for the ScrollPosition, as + // as well as the vertical ScrollableState instance so its context can be + // used to check for other ancestor Scrollables in executing ensureVisible. + @override + _EnsureVisibleResults _performEnsureVisible( + RenderObject object, { + double alignment = 0.0, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit, + RenderObject? targetRenderObject, + }) { + final List<Future<void>> newFutures = <Future<void>>[]; + + newFutures.add(position.ensureVisible( + object, + alignment: alignment, + duration: duration, + curve: curve, + alignmentPolicy: alignmentPolicy, + )); + + newFutures.add(verticalScrollable.position.ensureVisible( + object, + alignment: alignment, + duration: duration, + curve: curve, + alignmentPolicy: alignmentPolicy, + )); + + return (newFutures, verticalScrollable); + } + + @override + void setCanDrag(bool value) { + switch (diagonalDragBehavior) { + case DiagonalDragBehavior.none: + // If we aren't scrolling diagonally, the default drag gesture + // recognizer is used. + super.setCanDrag(value); + return; + case DiagonalDragBehavior.weightedEvent: + case DiagonalDragBehavior.weightedContinuous: + case DiagonalDragBehavior.free: + if (value) { + // If a type of diagonal scrolling is enabled, a panning gesture + // recognizer will be created for the _InnerDimension. So in this + // case, the _OuterDimension does not require a gesture recognizer. + _gestureRecognizers = const <Type, GestureRecognizerFactory>{}; + // Cancel the active hold/drag (if any) because the gesture recognizers + // will soon be disposed by our RawGestureDetector, and we won't be + // receiving pointer up events to cancel the hold/drag. + _handleDragCancel(); + _lastCanDrag = value; + _lastAxisDirection = widget.axis; + if (_gestureDetectorKey.currentState != null) { + _gestureDetectorKey.currentState!.replaceGestureRecognizers(_gestureRecognizers); + } + } + return; + } + } + + @override + Widget _buildChrome(BuildContext context, Widget child) { + final ScrollableDetails details = ScrollableDetails( + direction: widget.axisDirection, + controller: _effectiveScrollController, + clipBehavior: widget.clipBehavior, + ); + // Skip building a scrollbar here, the dual scrollbar is added in + // TwoDimensionalScrollableState. + return _configuration.buildOverscrollIndicator(context, child, details); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scrollable_helpers.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scrollable_helpers.dart new file mode 100644 index 0000000000000000000000000000000000000000..1854cfc217513201c8e6a82c886a48315ac4a3d5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scrollable_helpers.dart @@ -0,0 +1,526 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'actions.dart'; +import 'basic.dart'; +import 'framework.dart'; +import 'primary_scroll_controller.dart'; +import 'scroll_configuration.dart'; +import 'scroll_controller.dart'; +import 'scroll_metrics.dart'; +import 'scroll_physics.dart'; +import 'scrollable.dart'; + +export 'package:flutter/physics.dart' show Tolerance; + +/// Describes the aspects of a Scrollable widget to inform inherited widgets +/// like [ScrollBehavior] for decorating or enumerate the properties of combined +/// Scrollables, such as [TwoDimensionalScrollable]. +/// +/// Decorations like [GlowingOverscrollIndicator]s and [Scrollbar]s require +/// information about the Scrollable in order to be initialized. +@immutable +class ScrollableDetails { + /// Creates a set of details describing the [Scrollable]. + const ScrollableDetails({ + required this.direction, + this.controller, + this.physics, + @Deprecated( + 'Migrate to decorationClipBehavior. ' + 'This property was deprecated so that its application is clearer. This clip ' + 'applies to decorators, and does not directly clip a scroll view. ' + 'This feature was deprecated after v3.9.0-1.0.pre.' + ) + Clip? clipBehavior, + Clip? decorationClipBehavior, + }) : decorationClipBehavior = clipBehavior ?? decorationClipBehavior; + + /// A constructor specific to a [Scrollable] with an [Axis.vertical]. + const ScrollableDetails.vertical({ + bool reverse = false, + this.controller, + this.physics, + this.decorationClipBehavior, + }) : direction = reverse ? AxisDirection.up : AxisDirection.down; + + /// A constructor specific to a [Scrollable] with an [Axis.horizontal]. + const ScrollableDetails.horizontal({ + bool reverse = false, + this.controller, + this.physics, + this.decorationClipBehavior, + }) : direction = reverse ? AxisDirection.left : AxisDirection.right; + + /// {@macro flutter.widgets.Scrollable.axisDirection} + final AxisDirection direction; + + /// {@macro flutter.widgets.Scrollable.controller} + final ScrollController? controller; + + /// {@macro flutter.widgets.Scrollable.physics} + final ScrollPhysics? physics; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// This can be used by [MaterialScrollBehavior] to clip a + /// [StretchingOverscrollIndicator]. + /// + /// This [Clip] does not affect the [Viewport.clipBehavior], but is rather + /// passed from the same value by [Scrollable] so that decorators like + /// [StretchingOverscrollIndicator] honor the same clip. + /// + /// Defaults to null. + final Clip? decorationClipBehavior; + + /// Deprecated getter for [decorationClipBehavior]. + @Deprecated( + 'Migrate to decorationClipBehavior. ' + 'This property was deprecated so that its application is clearer. This clip ' + 'applies to decorators, and does not directly clip a scroll view. ' + 'This feature was deprecated after v3.9.0-1.0.pre.' + ) + Clip? get clipBehavior => decorationClipBehavior; + + /// Copy the current [ScrollableDetails] with the given values replacing the + /// current values. + ScrollableDetails copyWith({ + AxisDirection? direction, + ScrollController? controller, + ScrollPhysics? physics, + Clip? decorationClipBehavior, + }) { + return ScrollableDetails( + direction: direction ?? this.direction, + controller: controller ?? this.controller, + physics: physics ?? this.physics, + decorationClipBehavior: decorationClipBehavior ?? this.decorationClipBehavior, + ); + } + + @override + String toString() { + final List<String> description = <String>[]; + description.add('axisDirection: $direction'); + + void addIfNonNull(String prefix, Object? value) { + if (value != null) { + description.add(prefix + value.toString()); + } + } + addIfNonNull('scroll controller: ', controller); + addIfNonNull('scroll physics: ', physics); + addIfNonNull('decorationClipBehavior: ', decorationClipBehavior); + return '${describeIdentity(this)}(${description.join(", ")})'; + } + + @override + int get hashCode => Object.hash( + direction, + controller, + physics, + decorationClipBehavior, + ); + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is ScrollableDetails + && other.direction == direction + && other.controller == controller + && other.physics == physics + && other.decorationClipBehavior == decorationClipBehavior; + } +} + +/// An auto scroller that scrolls the [scrollable] if a drag gesture drags close +/// to its edge. +/// +/// The scroll velocity is controlled by the [velocityScalar]: +/// +/// velocity = <distance of overscroll> * [velocityScalar]. +class EdgeDraggingAutoScroller { + /// Creates a auto scroller that scrolls the [scrollable]. + EdgeDraggingAutoScroller( + this.scrollable, { + this.onScrollViewScrolled, + required this.velocityScalar, + }); + + /// The [Scrollable] this auto scroller is scrolling. + final ScrollableState scrollable; + + /// Called when a scroll view is scrolled. + /// + /// The scroll view may be scrolled multiple times in a row until the drag + /// target no longer triggers the auto scroll. This callback will be called + /// in between each scroll. + final VoidCallback? onScrollViewScrolled; + + /// {@template flutter.widgets.EdgeDraggingAutoScroller.velocityScalar} + /// The velocity scalar per pixel over scroll. + /// + /// It represents how the velocity scale with the over scroll distance. The + /// auto-scroll velocity = <distance of overscroll> * velocityScalar. + /// {@endtemplate} + final double velocityScalar; + + late Rect _dragTargetRelatedToScrollOrigin; + + /// Whether the auto scroll is in progress. + bool get scrolling => _scrolling; + bool _scrolling = false; + + double _offsetExtent(Offset offset, Axis scrollDirection) { + switch (scrollDirection) { + case Axis.horizontal: + return offset.dx; + case Axis.vertical: + return offset.dy; + } + } + + double _sizeExtent(Size size, Axis scrollDirection) { + switch (scrollDirection) { + case Axis.horizontal: + return size.width; + case Axis.vertical: + return size.height; + } + } + + AxisDirection get _axisDirection => scrollable.axisDirection; + Axis get _scrollDirection => axisDirectionToAxis(_axisDirection); + + /// Starts the auto scroll if the [dragTarget] is close to the edge. + /// + /// The scroll starts to scroll the [scrollable] if the target rect is close + /// to the edge of the [scrollable]; otherwise, it remains stationary. + /// + /// If the scrollable is already scrolling, calling this method updates the + /// previous dragTarget to the new value and continues scrolling if necessary. + void startAutoScrollIfNecessary(Rect dragTarget) { + final Offset deltaToOrigin = scrollable.deltaToScrollOrigin; + _dragTargetRelatedToScrollOrigin = dragTarget.translate(deltaToOrigin.dx, deltaToOrigin.dy); + if (_scrolling) { + // The change will be picked up in the next scroll. + return; + } + assert(!_scrolling); + _scroll(); + } + + /// Stop any ongoing auto scrolling. + void stopAutoScroll() { + _scrolling = false; + } + + Future<void> _scroll() async { + final RenderBox scrollRenderBox = scrollable.context.findRenderObject()! as RenderBox; + final Rect globalRect = MatrixUtils.transformRect( + scrollRenderBox.getTransformTo(null), + Rect.fromLTWH(0, 0, scrollRenderBox.size.width, scrollRenderBox.size.height), + ); + assert( + globalRect.size.width >= _dragTargetRelatedToScrollOrigin.size.width && + globalRect.size.height >= _dragTargetRelatedToScrollOrigin.size.height, + 'Drag target size is larger than scrollable size, which may cause bouncing', + ); + _scrolling = true; + double? newOffset; + const double overDragMax = 20.0; + + final Offset deltaToOrigin = scrollable.deltaToScrollOrigin; + final Offset viewportOrigin = globalRect.topLeft.translate(deltaToOrigin.dx, deltaToOrigin.dy); + final double viewportStart = _offsetExtent(viewportOrigin, _scrollDirection); + final double viewportEnd = viewportStart + _sizeExtent(globalRect.size, _scrollDirection); + + final double proxyStart = _offsetExtent(_dragTargetRelatedToScrollOrigin.topLeft, _scrollDirection); + final double proxyEnd = _offsetExtent(_dragTargetRelatedToScrollOrigin.bottomRight, _scrollDirection); + switch (_axisDirection) { + case AxisDirection.up: + case AxisDirection.left: + if (proxyEnd > viewportEnd && scrollable.position.pixels > scrollable.position.minScrollExtent) { + final double overDrag = math.min(proxyEnd - viewportEnd, overDragMax); + newOffset = math.max(scrollable.position.minScrollExtent, scrollable.position.pixels - overDrag); + } else if (proxyStart < viewportStart && scrollable.position.pixels < scrollable.position.maxScrollExtent) { + final double overDrag = math.min(viewportStart - proxyStart, overDragMax); + newOffset = math.min(scrollable.position.maxScrollExtent, scrollable.position.pixels + overDrag); + } + case AxisDirection.right: + case AxisDirection.down: + if (proxyStart < viewportStart && scrollable.position.pixels > scrollable.position.minScrollExtent) { + final double overDrag = math.min(viewportStart - proxyStart, overDragMax); + newOffset = math.max(scrollable.position.minScrollExtent, scrollable.position.pixels - overDrag); + } else if (proxyEnd > viewportEnd && scrollable.position.pixels < scrollable.position.maxScrollExtent) { + final double overDrag = math.min(proxyEnd - viewportEnd, overDragMax); + newOffset = math.min(scrollable.position.maxScrollExtent, scrollable.position.pixels + overDrag); + } + } + + if (newOffset == null || (newOffset - scrollable.position.pixels).abs() < 1.0) { + // Drag should not trigger scroll. + _scrolling = false; + return; + } + final Duration duration = Duration(milliseconds: (1000 / velocityScalar).round()); + await scrollable.position.animateTo( + newOffset, + duration: duration, + curve: Curves.linear, + ); + if (onScrollViewScrolled != null) { + onScrollViewScrolled!(); + } + if (_scrolling) { + await _scroll(); + } + } +} + +/// A typedef for a function that can calculate the offset for a type of scroll +/// increment given a [ScrollIncrementDetails]. +/// +/// This function is used as the type for [Scrollable.incrementCalculator], +/// which is called from a [ScrollAction]. +typedef ScrollIncrementCalculator = double Function(ScrollIncrementDetails details); + +/// Describes the type of scroll increment that will be performed by a +/// [ScrollAction] on a [Scrollable]. +/// +/// This is used to configure a [ScrollIncrementDetails] object to pass to a +/// [ScrollIncrementCalculator] function on a [Scrollable]. +/// +/// {@template flutter.widgets.ScrollIncrementType.intent} +/// This indicates the *intent* of the scroll, not necessarily the size. Not all +/// scrollable areas will have the concept of a "line" or "page", but they can +/// respond to the different standard key bindings that cause scrolling, which +/// are bound to keys that people use to indicate a "line" scroll (e.g. +/// control-arrowDown keys) or a "page" scroll (e.g. pageDown key). It is +/// recommended that at least the relative magnitudes of the scrolls match +/// expectations. +/// {@endtemplate} +enum ScrollIncrementType { + /// Indicates that the [ScrollIncrementCalculator] should return the scroll + /// distance it should move when the user requests to scroll by a "line". + /// + /// The distance a "line" scrolls refers to what should happen when the key + /// binding for "scroll down/up by a line" is triggered. It's up to the + /// [ScrollIncrementCalculator] function to decide what that means for a + /// particular scrollable. + line, + + /// Indicates that the [ScrollIncrementCalculator] should return the scroll + /// distance it should move when the user requests to scroll by a "page". + /// + /// The distance a "page" scrolls refers to what should happen when the key + /// binding for "scroll down/up by a page" is triggered. It's up to the + /// [ScrollIncrementCalculator] function to decide what that means for a + /// particular scrollable. + page, +} + +/// A details object that describes the type of scroll increment being requested +/// of a [ScrollIncrementCalculator] function, as well as the current metrics +/// for the scrollable. +class ScrollIncrementDetails { + /// A const constructor for a [ScrollIncrementDetails]. + const ScrollIncrementDetails({ + required this.type, + required this.metrics, + }); + + /// The type of scroll this is (e.g. line, page, etc.). + /// + /// {@macro flutter.widgets.ScrollIncrementType.intent} + final ScrollIncrementType type; + + /// The current metrics of the scrollable that is being scrolled. + final ScrollMetrics metrics; +} + +/// An [Intent] that represents scrolling the nearest scrollable by an amount +/// appropriate for the [type] specified. +/// +/// The actual amount of the scroll is determined by the +/// [Scrollable.incrementCalculator], or by its defaults if that is not +/// specified. +class ScrollIntent extends Intent { + /// Creates a const [ScrollIntent] that requests scrolling in the given + /// [direction], with the given [type]. + const ScrollIntent({ + required this.direction, + this.type = ScrollIncrementType.line, + }); + + /// The direction in which to scroll the scrollable containing the focused + /// widget. + final AxisDirection direction; + + /// The type of scrolling that is intended. + final ScrollIncrementType type; +} + +/// An [Action] that scrolls the relevant [Scrollable] by the amount configured +/// in the [ScrollIntent] given to it. +/// +/// If a Scrollable cannot be found above the given [BuildContext], the +/// [PrimaryScrollController] will be considered for default handling of +/// [ScrollAction]s. +/// +/// If [Scrollable.incrementCalculator] is null for the scrollable, the default +/// for a [ScrollIntent.type] set to [ScrollIncrementType.page] is 80% of the +/// size of the scroll window, and for [ScrollIncrementType.line], 50 logical +/// pixels. +class ScrollAction extends ContextAction<ScrollIntent> { + @override + bool isEnabled(ScrollIntent intent, [BuildContext? context]) { + if (context == null) { + return false; + } + if (Scrollable.maybeOf(context) != null) { + return true; + } + final ScrollController? primaryScrollController = PrimaryScrollController.maybeOf(context); + return (primaryScrollController != null) && (primaryScrollController.hasClients); + } + + /// Returns the scroll increment for a single scroll request, for use when + /// scrolling using a hardware keyboard. + /// + /// Must not be called when the position is null, or when any of the position + /// metrics (pixels, viewportDimension, maxScrollExtent, minScrollExtent) are + /// null. The widget must have already been laid out so that the position + /// fields are valid. + static double _calculateScrollIncrement(ScrollableState state, { ScrollIncrementType type = ScrollIncrementType.line }) { + assert(state.position.hasPixels); + assert(state.resolvedPhysics == null || state.resolvedPhysics!.shouldAcceptUserOffset(state.position)); + if (state.widget.incrementCalculator != null) { + return state.widget.incrementCalculator!( + ScrollIncrementDetails( + type: type, + metrics: state.position, + ), + ); + } + switch (type) { + case ScrollIncrementType.line: + return 50.0; + case ScrollIncrementType.page: + return 0.8 * state.position.viewportDimension; + } + } + + /// Find out how much of an increment to move by, taking the different + /// directions into account. + static double getDirectionalIncrement(ScrollableState state, ScrollIntent intent) { + final double increment = _calculateScrollIncrement(state, type: intent.type); + switch (intent.direction) { + case AxisDirection.down: + switch (state.axisDirection) { + case AxisDirection.up: + return -increment; + case AxisDirection.down: + return increment; + case AxisDirection.right: + case AxisDirection.left: + return 0.0; + } + case AxisDirection.up: + switch (state.axisDirection) { + case AxisDirection.up: + return increment; + case AxisDirection.down: + return -increment; + case AxisDirection.right: + case AxisDirection.left: + return 0.0; + } + case AxisDirection.left: + switch (state.axisDirection) { + case AxisDirection.right: + return -increment; + case AxisDirection.left: + return increment; + case AxisDirection.up: + case AxisDirection.down: + return 0.0; + } + case AxisDirection.right: + switch (state.axisDirection) { + case AxisDirection.right: + return increment; + case AxisDirection.left: + return -increment; + case AxisDirection.up: + case AxisDirection.down: + return 0.0; + } + } + } + + @override + void invoke(ScrollIntent intent, [BuildContext? context]) { + assert(context != null, 'Cannot scroll without a context.'); + ScrollableState? state = Scrollable.maybeOf(context!); + if (state == null) { + final ScrollController primaryScrollController = PrimaryScrollController.of(context); + assert (() { + if (primaryScrollController.positions.length != 1) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'A ScrollAction was invoked with the PrimaryScrollController, but ' + 'more than one ScrollPosition is attached.', + ), + ErrorDescription( + 'Only one ScrollPosition can be manipulated by a ScrollAction at ' + 'a time.', + ), + ErrorHint( + 'The PrimaryScrollController can be inherited automatically by ' + 'descendant ScrollViews based on the TargetPlatform and scroll ' + 'direction. By default, the PrimaryScrollController is ' + 'automatically inherited on mobile platforms for vertical ' + 'ScrollViews. ScrollView.primary can also override this behavior.', + ), + ]); + } + return true; + }()); + + if (primaryScrollController.position.context.notificationContext == null + && Scrollable.maybeOf(primaryScrollController.position.context.notificationContext!) == null) { + return; + } + state = Scrollable.maybeOf(primaryScrollController.position.context.notificationContext!); + } + assert(state != null, '$ScrollAction was invoked on a context that has no scrollable parent'); + assert(state!.position.hasPixels, 'Scrollable must be laid out before it can be scrolled via a ScrollAction'); + + // Don't do anything if the user isn't allowed to scroll. + if (state!.resolvedPhysics != null && !state.resolvedPhysics!.shouldAcceptUserOffset(state.position)) { + return; + } + final double increment = getDirectionalIncrement(state, intent); + if (increment == 0.0) { + return; + } + state.position.moveTo( + state.position.pixels + increment, + duration: const Duration(milliseconds: 100), + curve: Curves.easeInOut, + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scrollbar.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scrollbar.dart new file mode 100644 index 0000000000000000000000000000000000000000..76891b95ff933a470d9ac9b5e43c9fe3a0dc3748 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/scrollbar.dart @@ -0,0 +1,2131 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'binding.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'media_query.dart'; +import 'notification_listener.dart'; +import 'primary_scroll_controller.dart'; +import 'scroll_configuration.dart'; +import 'scroll_controller.dart'; +import 'scroll_metrics.dart'; +import 'scroll_notification.dart'; +import 'scroll_position.dart'; +import 'scrollable.dart'; +import 'scrollable_helpers.dart'; +import 'ticker_provider.dart'; + +const double _kMinThumbExtent = 18.0; +const double _kMinInteractiveSize = 48.0; +const double _kScrollbarThickness = 6.0; +const Duration _kScrollbarFadeDuration = Duration(milliseconds: 300); +const Duration _kScrollbarTimeToFade = Duration(milliseconds: 600); + +/// An orientation along either the horizontal or vertical [Axis]. +enum ScrollbarOrientation { + /// Place towards the left of the screen. + left, + + /// Place towards the right of the screen. + right, + + /// Place on top of the screen. + top, + + /// Place on the bottom of the screen. + bottom, +} + +/// Paints a scrollbar's track and thumb. +/// +/// The size of the scrollbar along its scroll direction is typically +/// proportional to the percentage of content completely visible on screen, +/// as long as its size isn't less than [minLength] and it isn't overscrolling. +/// +/// Unlike [CustomPainter]s that subclasses [CustomPainter] and only repaint +/// when [shouldRepaint] returns true (which requires this [CustomPainter] to +/// be rebuilt), this painter has the added optimization of repainting and not +/// rebuilding when: +/// +/// * the scroll position changes; and +/// * when the scrollbar fades away. +/// +/// Calling [update] with the new [ScrollMetrics] will repaint the new scrollbar +/// position. +/// +/// Updating the value on the provided [fadeoutOpacityAnimation] will repaint +/// with the new opacity. +/// +/// You must call [dispose] on this [ScrollbarPainter] when it's no longer used. +/// +/// See also: +/// +/// * [Scrollbar] for a widget showing a scrollbar around a [Scrollable] in the +/// Material Design style. +/// * [CupertinoScrollbar] for a widget showing a scrollbar around a +/// [Scrollable] in the iOS style. +class ScrollbarPainter extends ChangeNotifier implements CustomPainter { + /// Creates a scrollbar with customizations given by construction arguments. + ScrollbarPainter({ + required Color color, + required this.fadeoutOpacityAnimation, + Color trackColor = const Color(0x00000000), + Color trackBorderColor = const Color(0x00000000), + TextDirection? textDirection, + double thickness = _kScrollbarThickness, + EdgeInsets padding = EdgeInsets.zero, + double mainAxisMargin = 0.0, + double crossAxisMargin = 0.0, + Radius? radius, + Radius? trackRadius, + OutlinedBorder? shape, + double minLength = _kMinThumbExtent, + double? minOverscrollLength, + ScrollbarOrientation? scrollbarOrientation, + bool ignorePointer = false, + }) : assert(radius == null || shape == null), + assert(minLength >= 0), + assert(minOverscrollLength == null || minOverscrollLength <= minLength), + assert(minOverscrollLength == null || minOverscrollLength >= 0), + assert(padding.isNonNegative), + _color = color, + _textDirection = textDirection, + _thickness = thickness, + _radius = radius, + _shape = shape, + _padding = padding, + _mainAxisMargin = mainAxisMargin, + _crossAxisMargin = crossAxisMargin, + _minLength = minLength, + _trackColor = trackColor, + _trackBorderColor = trackBorderColor, + _trackRadius = trackRadius, + _scrollbarOrientation = scrollbarOrientation, + _minOverscrollLength = minOverscrollLength ?? minLength, + _ignorePointer = ignorePointer { + fadeoutOpacityAnimation.addListener(notifyListeners); + } + + /// [Color] of the thumb. Mustn't be null. + Color get color => _color; + Color _color; + set color(Color value) { + if (color == value) { + return; + } + + _color = value; + notifyListeners(); + } + + /// [Color] of the track. Mustn't be null. + Color get trackColor => _trackColor; + Color _trackColor; + set trackColor(Color value) { + if (trackColor == value) { + return; + } + + _trackColor = value; + notifyListeners(); + } + + /// [Color] of the track border. Mustn't be null. + Color get trackBorderColor => _trackBorderColor; + Color _trackBorderColor; + set trackBorderColor(Color value) { + if (trackBorderColor == value) { + return; + } + + _trackBorderColor = value; + notifyListeners(); + } + + /// [Radius] of corners of the Scrollbar's track. + /// + /// Scrollbar's track will be rectangular if [trackRadius] is null. + Radius? get trackRadius => _trackRadius; + Radius? _trackRadius; + set trackRadius(Radius? value) { + if (trackRadius == value) { + return; + } + + _trackRadius = value; + notifyListeners(); + } + + /// [TextDirection] of the [BuildContext] which dictates the side of the + /// screen the scrollbar appears in (the trailing side). Must be set prior to + /// calling paint. + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { + assert(value != null); + if (textDirection == value) { + return; + } + + _textDirection = value; + notifyListeners(); + } + + /// Thickness of the scrollbar in its cross-axis in logical pixels. Mustn't be null. + double get thickness => _thickness; + double _thickness; + set thickness(double value) { + if (thickness == value) { + return; + } + + _thickness = value; + notifyListeners(); + } + + /// An opacity [Animation] that dictates the opacity of the thumb. + /// Changes in value of this [Listenable] will automatically trigger repaints. + /// Mustn't be null. + final Animation<double> fadeoutOpacityAnimation; + + /// Distance from the scrollbar thumb's start and end to the edge of the + /// viewport in logical pixels. It affects the amount of available paint area. + /// + /// The scrollbar track consumes this space. + /// + /// Mustn't be null and defaults to 0. + double get mainAxisMargin => _mainAxisMargin; + double _mainAxisMargin; + set mainAxisMargin(double value) { + if (mainAxisMargin == value) { + return; + } + + _mainAxisMargin = value; + notifyListeners(); + } + + /// Distance from the scrollbar thumb to the nearest cross axis edge + /// in logical pixels. + /// + /// The scrollbar track consumes this space. + /// + /// Defaults to zero. + double get crossAxisMargin => _crossAxisMargin; + double _crossAxisMargin; + set crossAxisMargin(double value) { + if (crossAxisMargin == value) { + return; + } + + _crossAxisMargin = value; + notifyListeners(); + } + + /// [Radius] of corners if the scrollbar should have rounded corners. + /// + /// Scrollbar will be rectangular if [radius] is null. + Radius? get radius => _radius; + Radius? _radius; + set radius(Radius? value) { + assert(shape == null || value == null); + if (radius == value) { + return; + } + + _radius = value; + notifyListeners(); + } + + /// The [OutlinedBorder] of the scrollbar's thumb. + /// + /// Only one of [radius] and [shape] may be specified. For a rounded rectangle, + /// it's simplest to just specify [radius]. By default, the scrollbar thumb's + /// shape is a simple rectangle. + /// + /// If [shape] is specified, the thumb will take the shape of the passed + /// [OutlinedBorder] and fill itself with [color] (or grey if it + /// is unspecified). + /// + OutlinedBorder? get shape => _shape; + OutlinedBorder? _shape; + set shape(OutlinedBorder? value){ + assert(radius == null || value == null); + if (shape == value) { + return; + } + + _shape = value; + notifyListeners(); + } + + /// The amount of space by which to inset the scrollbar's start and end, as + /// well as its side to the nearest edge, in logical pixels. + /// + /// This is typically set to the current [MediaQueryData.padding] to avoid + /// partial obstructions such as display notches. If you only want additional + /// margins around the scrollbar, see [mainAxisMargin]. + /// + /// Defaults to [EdgeInsets.zero]. Offsets from all four directions must be + /// greater than or equal to zero. + EdgeInsets get padding => _padding; + EdgeInsets _padding; + set padding(EdgeInsets value) { + if (padding == value) { + return; + } + + _padding = value; + notifyListeners(); + } + + /// The preferred smallest size the scrollbar thumb can shrink to when the total + /// scrollable extent is large, the current visible viewport is small, and the + /// viewport is not overscrolled. + /// + /// The size of the scrollbar may shrink to a smaller size than [minLength] to + /// fit in the available paint area. E.g., when [minLength] is + /// `double.infinity`, it will not be respected if + /// [ScrollMetrics.viewportDimension] and [mainAxisMargin] are finite. + /// + /// Mustn't be null and the value has to be greater or equal to + /// [minOverscrollLength], which in turn is >= 0. Defaults to 18.0. + double get minLength => _minLength; + double _minLength; + set minLength(double value) { + if (minLength == value) { + return; + } + + _minLength = value; + notifyListeners(); + } + + /// The preferred smallest size the scrollbar thumb can shrink to when viewport is + /// overscrolled. + /// + /// When overscrolling, the size of the scrollbar may shrink to a smaller size + /// than [minOverscrollLength] to fit in the available paint area. E.g., when + /// [minOverscrollLength] is `double.infinity`, it will not be respected if + /// the [ScrollMetrics.viewportDimension] and [mainAxisMargin] are finite. + /// + /// The value is less than or equal to [minLength] and greater than or equal to 0. + /// When null, it will default to the value of [minLength]. + double get minOverscrollLength => _minOverscrollLength; + double _minOverscrollLength; + set minOverscrollLength(double value) { + if (minOverscrollLength == value) { + return; + } + + _minOverscrollLength = value; + notifyListeners(); + } + + /// {@template flutter.widgets.Scrollbar.scrollbarOrientation} + /// Dictates the orientation of the scrollbar. + /// + /// [ScrollbarOrientation.top] places the scrollbar on top of the screen. + /// [ScrollbarOrientation.bottom] places the scrollbar on the bottom of the screen. + /// [ScrollbarOrientation.left] places the scrollbar on the left of the screen. + /// [ScrollbarOrientation.right] places the scrollbar on the right of the screen. + /// + /// [ScrollbarOrientation.top] and [ScrollbarOrientation.bottom] can only be + /// used with a vertical scroll. + /// [ScrollbarOrientation.left] and [ScrollbarOrientation.right] can only be + /// used with a horizontal scroll. + /// + /// For a vertical scroll the orientation defaults to + /// [ScrollbarOrientation.right] for [TextDirection.ltr] and + /// [ScrollbarOrientation.left] for [TextDirection.rtl]. + /// For a horizontal scroll the orientation defaults to [ScrollbarOrientation.bottom]. + /// {@endtemplate} + ScrollbarOrientation? get scrollbarOrientation => _scrollbarOrientation; + ScrollbarOrientation? _scrollbarOrientation; + set scrollbarOrientation(ScrollbarOrientation? value) { + if (scrollbarOrientation == value) { + return; + } + + _scrollbarOrientation = value; + notifyListeners(); + } + + /// Whether the painter will be ignored during hit testing. + bool get ignorePointer => _ignorePointer; + bool _ignorePointer; + set ignorePointer(bool value) { + if (ignorePointer == value) { + return; + } + + _ignorePointer = value; + notifyListeners(); + } + + // - Scrollbar Details + + Rect? _trackRect; + // The full painted length of the track + double get _trackExtent => _lastMetrics!.viewportDimension - _totalTrackMainAxisOffsets; + // The full length of the track that the thumb can travel + double get _traversableTrackExtent => _trackExtent - (2 * mainAxisMargin); + // Track Offsets + // The track is offset by only padding. + double get _totalTrackMainAxisOffsets => _isVertical ? padding.vertical : padding.horizontal; + double get _leadingTrackMainAxisOffset { + switch (_resolvedOrientation) { + case ScrollbarOrientation.left: + case ScrollbarOrientation.right: + return padding.top; + case ScrollbarOrientation.top: + case ScrollbarOrientation.bottom: + return padding.left; + } + } + + Rect? _thumbRect; + // The current scroll position + _leadingThumbMainAxisOffset + late double _thumbOffset; + // The fraction visible in relation to the traversable length of the track. + late double _thumbExtent; + // Thumb Offsets + // The thumb is offset by padding and margins. + double get _leadingThumbMainAxisOffset { + switch (_resolvedOrientation) { + case ScrollbarOrientation.left: + case ScrollbarOrientation.right: + return padding.top + mainAxisMargin; + case ScrollbarOrientation.top: + case ScrollbarOrientation.bottom: + return padding.left + mainAxisMargin; + } + } + void _setThumbExtent() { + // Thumb extent reflects fraction of content visible, as long as this + // isn't less than the absolute minimum size. + // _totalContentExtent >= viewportDimension, so (_totalContentExtent - _mainAxisPadding) > 0 + final double fractionVisible = clampDouble( + (_lastMetrics!.extentInside - _totalTrackMainAxisOffsets) + / (_totalContentExtent - _totalTrackMainAxisOffsets), + 0.0, + 1.0, + ); + + final double thumbExtent = math.max( + math.min(_traversableTrackExtent, minOverscrollLength), + _traversableTrackExtent * fractionVisible, + ); + + final double fractionOverscrolled = 1.0 - _lastMetrics!.extentInside / _lastMetrics!.viewportDimension; + final double safeMinLength = math.min(minLength, _traversableTrackExtent); + final double newMinLength = (_beforeExtent > 0 && _afterExtent > 0) + // Thumb extent is no smaller than minLength if scrolling normally. + ? safeMinLength + // User is overscrolling. Thumb extent can be less than minLength + // but no smaller than minOverscrollLength. We can't use the + // fractionVisible to produce intermediate values between minLength and + // minOverscrollLength when the user is transitioning from regular + // scrolling to overscrolling, so we instead use the percentage of the + // content that is still in the viewport to determine the size of the + // thumb. iOS behavior appears to have the thumb reach its minimum size + // with ~20% of overscroll. We map the percentage of minLength from + // [0.8, 1.0] to [0.0, 1.0], so 0% to 20% of overscroll will produce + // values for the thumb that range between minLength and the smallest + // possible value, minOverscrollLength. + : safeMinLength * (1.0 - clampDouble(fractionOverscrolled, 0.0, 0.2) / 0.2); + + // The `thumbExtent` should be no greater than `trackSize`, otherwise + // the scrollbar may scroll towards the wrong direction. + _thumbExtent = clampDouble(thumbExtent, newMinLength, _traversableTrackExtent); + } + + // - Scrollable Details + + ScrollMetrics? _lastMetrics; + bool get _lastMetricsAreScrollable => _lastMetrics!.minScrollExtent != _lastMetrics!.maxScrollExtent; + AxisDirection? _lastAxisDirection; + + bool get _isVertical => _lastAxisDirection == AxisDirection.down || _lastAxisDirection == AxisDirection.up; + bool get _isReversed => _lastAxisDirection == AxisDirection.up || _lastAxisDirection == AxisDirection.left; + // The amount of scroll distance before and after the current position. + double get _beforeExtent => _isReversed ? _lastMetrics!.extentAfter : _lastMetrics!.extentBefore; + double get _afterExtent => _isReversed ? _lastMetrics!.extentBefore : _lastMetrics!.extentAfter; + + // The total size of the scrollable content. + double get _totalContentExtent { + return _lastMetrics!.maxScrollExtent + - _lastMetrics!.minScrollExtent + + _lastMetrics!.viewportDimension; + } + + ScrollbarOrientation get _resolvedOrientation { + if (scrollbarOrientation == null) { + if (_isVertical) { + return textDirection == TextDirection.ltr + ? ScrollbarOrientation.right + : ScrollbarOrientation.left; + } + return ScrollbarOrientation.bottom; + } + return scrollbarOrientation!; + } + + void _debugAssertIsValidOrientation(ScrollbarOrientation orientation) { + assert( + () { + bool isVerticalOrientation(ScrollbarOrientation orientation) => + orientation == ScrollbarOrientation.left + || orientation == ScrollbarOrientation.right; + return (_isVertical && isVerticalOrientation(orientation)) + || (!_isVertical && !isVerticalOrientation(orientation)); + }(), + 'The given ScrollbarOrientation: $orientation is incompatible with the ' + 'current AxisDirection: $_lastAxisDirection.' + ); + } + + // - Updating + + /// Update with new [ScrollMetrics]. If the metrics change, the scrollbar will + /// show and redraw itself based on these new metrics. + /// + /// The scrollbar will remain on screen. + void update( + ScrollMetrics metrics, + AxisDirection axisDirection, + ) { + if (_lastMetrics != null && + _lastMetrics!.extentBefore == metrics.extentBefore && + _lastMetrics!.extentInside == metrics.extentInside && + _lastMetrics!.extentAfter == metrics.extentAfter && + _lastAxisDirection == axisDirection) { + return; + } + + final ScrollMetrics? oldMetrics = _lastMetrics; + _lastMetrics = metrics; + _lastAxisDirection = axisDirection; + + bool needPaint(ScrollMetrics? metrics) => metrics != null && metrics.maxScrollExtent > metrics.minScrollExtent; + if (!needPaint(oldMetrics) && !needPaint(metrics)) { + return; + } + notifyListeners(); + } + + /// Update and redraw with new scrollbar thickness and radius. + void updateThickness(double nextThickness, Radius nextRadius) { + thickness = nextThickness; + radius = nextRadius; + } + + // - Painting + + Paint get _paintThumb { + return Paint() + ..color = color.withOpacity(color.opacity * fadeoutOpacityAnimation.value); + } + + Paint _paintTrack({ bool isBorder = false }) { + if (isBorder) { + return Paint() + ..color = trackBorderColor.withOpacity(trackBorderColor.opacity * fadeoutOpacityAnimation.value) + ..style = PaintingStyle.stroke + ..strokeWidth = 1.0; + } + return Paint() + ..color = trackColor.withOpacity(trackColor.opacity * fadeoutOpacityAnimation.value); + } + + void _paintScrollbar(Canvas canvas, Size size) { + assert( + textDirection != null, + 'A TextDirection must be provided before a Scrollbar can be painted.', + ); + + final double x, y; + final Size thumbSize, trackSize; + final Offset trackOffset, borderStart, borderEnd; + _debugAssertIsValidOrientation(_resolvedOrientation); + switch (_resolvedOrientation) { + case ScrollbarOrientation.left: + thumbSize = Size(thickness, _thumbExtent); + trackSize = Size(thickness + 2 * crossAxisMargin, _trackExtent); + x = crossAxisMargin + padding.left; + y = _thumbOffset; + trackOffset = Offset(x - crossAxisMargin, _leadingTrackMainAxisOffset); + borderStart = trackOffset + Offset(trackSize.width, 0.0); + borderEnd = Offset(trackOffset.dx + trackSize.width, trackOffset.dy + _trackExtent); + case ScrollbarOrientation.right: + thumbSize = Size(thickness, _thumbExtent); + trackSize = Size(thickness + 2 * crossAxisMargin, _trackExtent); + x = size.width - thickness - crossAxisMargin - padding.right; + y = _thumbOffset; + trackOffset = Offset(x - crossAxisMargin, _leadingTrackMainAxisOffset); + borderStart = trackOffset; + borderEnd = Offset(trackOffset.dx, trackOffset.dy + _trackExtent); + case ScrollbarOrientation.top: + thumbSize = Size(_thumbExtent, thickness); + trackSize = Size(_trackExtent, thickness + 2 * crossAxisMargin); + x = _thumbOffset; + y = crossAxisMargin + padding.top; + trackOffset = Offset(_leadingTrackMainAxisOffset, y - crossAxisMargin); + borderStart = trackOffset + Offset(0.0, trackSize.height); + borderEnd = Offset(trackOffset.dx + _trackExtent, trackOffset.dy + trackSize.height); + case ScrollbarOrientation.bottom: + thumbSize = Size(_thumbExtent, thickness); + trackSize = Size(_trackExtent, thickness + 2 * crossAxisMargin); + x = _thumbOffset; + y = size.height - thickness - crossAxisMargin - padding.bottom; + trackOffset = Offset(_leadingTrackMainAxisOffset, y - crossAxisMargin); + borderStart = trackOffset; + borderEnd = Offset(trackOffset.dx + _trackExtent, trackOffset.dy); + } + + // Whether we paint or not, calculating these rects allows us to hit test + // when the scrollbar is transparent. + _trackRect = trackOffset & trackSize; + _thumbRect = Offset(x, y) & thumbSize; + + // Paint if the opacity dictates visibility + if (fadeoutOpacityAnimation.value != 0.0) { + // Track + if (trackRadius == null) { + canvas.drawRect(_trackRect!, _paintTrack()); + } else { + canvas.drawRRect(RRect.fromRectAndRadius(_trackRect!, trackRadius!), _paintTrack()); + } + // Track Border + canvas.drawLine(borderStart, borderEnd, _paintTrack(isBorder: true)); + if (radius != null) { + // Rounded rect thumb + canvas.drawRRect(RRect.fromRectAndRadius(_thumbRect!, radius!), _paintThumb); + return; + } + if (shape == null) { + // Square thumb + canvas.drawRect(_thumbRect!, _paintThumb); + return; + } + // Custom-shaped thumb + final Path outerPath = shape!.getOuterPath(_thumbRect!); + canvas.drawPath(outerPath, _paintThumb); + shape!.paint(canvas, _thumbRect!); + } + } + + @override + void paint(Canvas canvas, Size size) { + if (_lastAxisDirection == null + || _lastMetrics == null + || _lastMetrics!.maxScrollExtent <= _lastMetrics!.minScrollExtent) { + return; + } + // Skip painting if there's not enough space. + if (_traversableTrackExtent <= 0) { + return; + } + // Do not paint a scrollbar if the scroll view is infinitely long. + // TODO(Piinks): Special handling for infinite scroll views, + // https://github.com/flutter/flutter/issues/41434 + if (_lastMetrics!.maxScrollExtent.isInfinite) { + return; + } + + _setThumbExtent(); + final double thumbPositionOffset = _getScrollToTrack(_lastMetrics!, _thumbExtent); + _thumbOffset = thumbPositionOffset + _leadingThumbMainAxisOffset; + + return _paintScrollbar(canvas, size); + } + + // - Scroll Position Conversion + + /// Convert between a thumb track position and the corresponding scroll + /// position. + /// + /// The `thumbOffsetLocal` argument is a position in the thumb track. + double getTrackToScroll(double thumbOffsetLocal) { + final double scrollableExtent = _lastMetrics!.maxScrollExtent - _lastMetrics!.minScrollExtent; + final double thumbMovableExtent = _traversableTrackExtent - _thumbExtent; + + return scrollableExtent * thumbOffsetLocal / thumbMovableExtent; + } + + /// The thumb's corresponding scroll offset in the track. + double getThumbScrollOffset() { + final double scrollableExtent = _lastMetrics!.maxScrollExtent - _lastMetrics!.minScrollExtent; + + final double fractionPast = (scrollableExtent > 0) + ? clampDouble(_lastMetrics!.pixels / scrollableExtent, 0.0, 1.0) + : 0; + + return fractionPast * (_traversableTrackExtent - _thumbExtent); + } + + // Converts between a scroll position and the corresponding position in the + // thumb track. + double _getScrollToTrack(ScrollMetrics metrics, double thumbExtent) { + final double scrollableExtent = metrics.maxScrollExtent - metrics.minScrollExtent; + + final double fractionPast = (scrollableExtent > 0) + ? clampDouble((metrics.pixels - metrics.minScrollExtent) / scrollableExtent, 0.0, 1.0) + : 0; + + return (_isReversed ? 1 - fractionPast : fractionPast) * (_traversableTrackExtent - thumbExtent); + } + + // - Hit Testing + + @override + bool? hitTest(Offset? position) { + // There is nothing painted to hit. + if (_thumbRect == null) { + return null; + } + + // Interaction disabled. + if (ignorePointer + // The thumb is not able to be hit when transparent. + || fadeoutOpacityAnimation.value == 0.0 + // Not scrollable + || !_lastMetricsAreScrollable) { + return false; + } + + return _trackRect!.contains(position!); + } + + /// Same as hitTest, but includes some padding when the [PointerEvent] is + /// caused by [PointerDeviceKind.touch] to make sure that the region + /// isn't too small to be interacted with by the user. + /// + /// The hit test area for hovering with [PointerDeviceKind.mouse] over the + /// scrollbar also uses this extra padding. This is to make it easier to + /// interact with the scrollbar by presenting it to the mouse for interaction + /// based on proximity. When `forHover` is true, the larger hit test area will + /// be used. + bool hitTestInteractive(Offset position, PointerDeviceKind kind, { bool forHover = false }) { + if (_trackRect == null) { + // We have not computed the scrollbar position yet. + return false; + } + if (ignorePointer) { + return false; + } + + if (!_lastMetricsAreScrollable) { + return false; + } + + final Rect interactiveRect = _trackRect!; + final Rect paddedRect = interactiveRect.expandToInclude( + Rect.fromCircle(center: _thumbRect!.center, radius: _kMinInteractiveSize / 2), + ); + + // The scrollbar is not able to be hit when transparent - except when + // hovering with a mouse. This should bring the scrollbar into view so the + // mouse can interact with it. + if (fadeoutOpacityAnimation.value == 0.0) { + if (forHover && kind == PointerDeviceKind.mouse) { + return paddedRect.contains(position); + } + return false; + } + + switch (kind) { + case PointerDeviceKind.touch: + case PointerDeviceKind.trackpad: + return paddedRect.contains(position); + case PointerDeviceKind.mouse: + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.unknown: + return interactiveRect.contains(position); + } + } + + /// Same as hitTestInteractive, but excludes the track portion of the scrollbar. + /// Used to evaluate interactions with only the scrollbar thumb. + bool hitTestOnlyThumbInteractive(Offset position, PointerDeviceKind kind) { + if (_thumbRect == null) { + return false; + } + if (ignorePointer) { + return false; + } + // The thumb is not able to be hit when transparent. + if (fadeoutOpacityAnimation.value == 0.0) { + return false; + } + + if (!_lastMetricsAreScrollable) { + return false; + } + + switch (kind) { + case PointerDeviceKind.touch: + case PointerDeviceKind.trackpad: + final Rect touchThumbRect = _thumbRect!.expandToInclude( + Rect.fromCircle(center: _thumbRect!.center, radius: _kMinInteractiveSize / 2), + ); + return touchThumbRect.contains(position); + case PointerDeviceKind.mouse: + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.unknown: + return _thumbRect!.contains(position); + } + } + + @override + bool shouldRepaint(ScrollbarPainter oldDelegate) { + // Should repaint if any properties changed. + return color != oldDelegate.color + || trackColor != oldDelegate.trackColor + || trackBorderColor != oldDelegate.trackBorderColor + || textDirection != oldDelegate.textDirection + || thickness != oldDelegate.thickness + || fadeoutOpacityAnimation != oldDelegate.fadeoutOpacityAnimation + || mainAxisMargin != oldDelegate.mainAxisMargin + || crossAxisMargin != oldDelegate.crossAxisMargin + || radius != oldDelegate.radius + || trackRadius != oldDelegate.trackRadius + || shape != oldDelegate.shape + || padding != oldDelegate.padding + || minLength != oldDelegate.minLength + || minOverscrollLength != oldDelegate.minOverscrollLength + || scrollbarOrientation != oldDelegate.scrollbarOrientation + || ignorePointer != oldDelegate.ignorePointer; + } + + @override + bool shouldRebuildSemantics(CustomPainter oldDelegate) => false; + + @override + SemanticsBuilderCallback? get semanticsBuilder => null; + + @override + String toString() => describeIdentity(this); + + @override + void dispose() { + fadeoutOpacityAnimation.removeListener(notifyListeners); + super.dispose(); + } +} + +/// An extendable base class for building scrollbars that fade in and out. +/// +/// To add a scrollbar to a [ScrollView], like a [ListView] or a +/// [CustomScrollView], wrap the scroll view widget in a [RawScrollbar] widget. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=DbkIQSvwnZc} +/// +/// {@template flutter.widgets.Scrollbar} +/// A scrollbar thumb indicates which portion of a [ScrollView] is actually +/// visible. +/// +/// By default, the thumb will fade in and out as the child scroll view +/// scrolls. When [thumbVisibility] is true, the scrollbar thumb will remain +/// visible without the fade animation. This requires that the [ScrollController] +/// associated with the Scrollable widget is provided to [controller], or that +/// the [PrimaryScrollController] is being used by that Scrollable widget. +/// +/// If the scrollbar is wrapped around multiple [ScrollView]s, it only responds to +/// the nearest ScrollView and shows the corresponding scrollbar thumb by default. +/// The [notificationPredicate] allows the ability to customize which +/// [ScrollNotification]s the Scrollbar should listen to. +/// +/// If the child [ScrollView] is infinitely long, the [RawScrollbar] will not be +/// painted. In this case, the scrollbar cannot accurately represent the +/// relative location of the visible area, or calculate the accurate delta to +/// apply when dragging on the thumb or tapping on the track. +/// +/// ### Interaction +/// +/// Scrollbars are interactive and can use the [PrimaryScrollController] if +/// a [controller] is not set. Interactive Scrollbar thumbs can be dragged along +/// the main axis of the [ScrollView] to change the [ScrollPosition]. Tapping +/// along the track exclusive of the thumb will trigger a +/// [ScrollIncrementType.page] based on the relative position to the thumb. +/// +/// When using the [PrimaryScrollController], it must not be attached to more +/// than one [ScrollPosition]. [ScrollView]s that have not been provided a +/// [ScrollController] and have a [ScrollView.scrollDirection] of +/// [Axis.vertical] will automatically attach their ScrollPosition to the +/// PrimaryScrollController. Provide a unique ScrollController to each +/// [Scrollable] in this case to prevent having multiple ScrollPositions +/// attached to the PrimaryScrollController. +/// +/// {@tool dartpad} +/// This sample shows an app with two scrollables in the same route. Since by +/// default, there is one [PrimaryScrollController] per route, and they both have a +/// scroll direction of [Axis.vertical], they would both try to attach to that +/// controller on mobile platforms. The [Scrollbar] cannot support multiple +/// positions attached to the same controller, so one [ListView], and its +/// [Scrollbar] have been provided a unique [ScrollController]. Desktop +/// platforms do not automatically attach to the PrimaryScrollController, +/// requiring [ScrollView.primary] to be true instead in order to use the +/// PrimaryScrollController. +/// +/// Alternatively, a new PrimaryScrollController could be created above one of +/// the [ListView]s. +/// +/// ** See code in examples/api/lib/widgets/scrollbar/raw_scrollbar.0.dart ** +/// {@end-tool} +/// +/// ### Automatic Scrollbars on Desktop Platforms +/// +/// Scrollbars are added to most [Scrollable] widgets by default on +/// [TargetPlatformVariant.desktop] platforms. This is done through +/// [ScrollBehavior.buildScrollbar] as part of an app's +/// [ScrollConfiguration]. Scrollables that do not use the +/// [PrimaryScrollController] or have a [ScrollController] provided to them +/// will receive a unique ScrollController for use with the Scrollbar. In this +/// case, only one Scrollable can be using the PrimaryScrollController, unless +/// [interactive] is false. To prevent [Axis.vertical] Scrollables from using +/// the PrimaryScrollController, set [ScrollView.primary] to false. Scrollable +/// widgets that do not have automatically applied Scrollbars include +/// +/// * [EditableText] +/// * [ListWheelScrollView] +/// * [PageView] +/// * [NestedScrollView] +/// * [DropdownButton] +/// +/// Default Scrollbars can be disabled for the whole app by setting a +/// [ScrollBehavior] with `scrollbars` set to false. +/// +/// {@tool snippet} +/// ```dart +/// MaterialApp( +/// scrollBehavior: const MaterialScrollBehavior() +/// .copyWith(scrollbars: false), +/// home: Scaffold( +/// appBar: AppBar(title: const Text('Home')), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool dartpad} +/// This sample shows how to disable the default Scrollbar for a [Scrollable] +/// widget to avoid duplicate Scrollbars when running on desktop platforms. +/// +/// ** See code in examples/api/lib/widgets/scrollbar/raw_scrollbar.desktop.0.dart ** +/// {@end-tool} +/// {@endtemplate} +/// +/// {@tool dartpad} +/// This sample shows a [RawScrollbar] that executes a fade animation as +/// scrolling occurs. The RawScrollbar will fade into view as the user scrolls, +/// and fade out when scrolling stops. The [GridView] uses the +/// [PrimaryScrollController] since it has an [Axis.vertical] scroll direction +/// and has not been provided a [ScrollController]. +/// +/// ** See code in examples/api/lib/widgets/scrollbar/raw_scrollbar.1.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// When `thumbVisibility` is true, the scrollbar thumb will remain visible without +/// the fade animation. This requires that a [ScrollController] is provided to +/// `controller` for both the [RawScrollbar] and the [GridView]. +/// Alternatively, the [PrimaryScrollController] can be used automatically so long +/// as it is attached to the singular [ScrollPosition] associated with the GridView. +/// +/// ** See code in examples/api/lib/widgets/scrollbar/raw_scrollbar.2.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListView], which displays a linear, scrollable list of children. +/// * [GridView], which displays a 2 dimensional, scrollable array of children. +class RawScrollbar extends StatefulWidget { + /// Creates a basic raw scrollbar that wraps the given [child]. + /// + /// The [child], or a descendant of the [child], should be a source of + /// [ScrollNotification] notifications, typically a [Scrollable] widget. + const RawScrollbar({ + super.key, + required this.child, + this.controller, + this.thumbVisibility, + this.shape, + this.radius, + this.thickness, + this.thumbColor, + this.minThumbLength = _kMinThumbExtent, + this.minOverscrollLength, + this.trackVisibility, + this.trackRadius, + this.trackColor, + this.trackBorderColor, + this.fadeDuration = _kScrollbarFadeDuration, + this.timeToFade = _kScrollbarTimeToFade, + this.pressDuration = Duration.zero, + this.notificationPredicate = defaultScrollNotificationPredicate, + this.interactive, + this.scrollbarOrientation, + this.mainAxisMargin = 0.0, + this.crossAxisMargin = 0.0, + this.padding, + }) : assert( + !(thumbVisibility == false && (trackVisibility ?? false)), + 'A scrollbar track cannot be drawn without a scrollbar thumb.', + ), + assert(minThumbLength >= 0), + assert(minOverscrollLength == null || minOverscrollLength <= minThumbLength), + assert(minOverscrollLength == null || minOverscrollLength >= 0), + assert(radius == null || shape == null); + + /// {@template flutter.widgets.Scrollbar.child} + /// The widget below this widget in the tree. + /// + /// The scrollbar will be stacked on top of this child. This child (and its + /// subtree) should include a source of [ScrollNotification] notifications. + /// Typically a [Scrollbar] is created on desktop platforms by a + /// [ScrollBehavior.buildScrollbar] method, in which case the child is usually + /// the one provided as an argument to that method. + /// + /// Typically a [ListView] or [CustomScrollView]. + /// {@endtemplate} + final Widget child; + + /// {@template flutter.widgets.Scrollbar.controller} + /// The [ScrollController] used to implement Scrollbar dragging. + /// + /// If nothing is passed to controller, the default behavior is to automatically + /// enable scrollbar dragging on the nearest ScrollController using + /// [PrimaryScrollController.of]. + /// + /// If a ScrollController is passed, then dragging on the scrollbar thumb will + /// update the [ScrollPosition] attached to the controller. A stateful ancestor + /// of this widget needs to manage the ScrollController and either pass it to + /// a scrollable descendant or use a PrimaryScrollController to share it. + /// + /// {@tool snippet} + /// Here is an example of using the [controller] attribute to enable + /// scrollbar dragging for multiple independent ListViews: + /// + /// ```dart + /// // (e.g. in a stateful widget) + /// + /// final ScrollController controllerOne = ScrollController(); + /// final ScrollController controllerTwo = ScrollController(); + /// + /// @override + /// Widget build(BuildContext context) { + /// return Column( + /// children: <Widget>[ + /// SizedBox( + /// height: 200, + /// child: CupertinoScrollbar( + /// controller: controllerOne, + /// child: ListView.builder( + /// controller: controllerOne, + /// itemCount: 120, + /// itemBuilder: (BuildContext context, int index) => Text('item $index'), + /// ), + /// ), + /// ), + /// SizedBox( + /// height: 200, + /// child: CupertinoScrollbar( + /// controller: controllerTwo, + /// child: ListView.builder( + /// controller: controllerTwo, + /// itemCount: 120, + /// itemBuilder: (BuildContext context, int index) => Text('list 2 item $index'), + /// ), + /// ), + /// ), + /// ], + /// ); + /// } + /// ``` + /// {@end-tool} + /// {@endtemplate} + final ScrollController? controller; + + /// {@template flutter.widgets.Scrollbar.thumbVisibility} + /// Indicates that the scrollbar thumb should be visible, even when a scroll + /// is not underway. + /// + /// When false, the scrollbar will be shown during scrolling + /// and will fade out otherwise. + /// + /// When true, the scrollbar will always be visible and never fade out. This + /// requires that the Scrollbar can access the [ScrollController] of the + /// associated Scrollable widget. This can either be the provided [controller], + /// or the [PrimaryScrollController] of the current context. + /// + /// * When providing a controller, the same ScrollController must also be + /// provided to the associated Scrollable widget. + /// * The [PrimaryScrollController] is used by default for a [ScrollView] + /// that has not been provided a [ScrollController] and that has a + /// [ScrollView.scrollDirection] of [Axis.vertical]. This automatic + /// behavior does not apply to those with [Axis.horizontal]. To explicitly + /// use the PrimaryScrollController, set [ScrollView.primary] to true. + /// + /// Defaults to false when null. + /// + /// {@tool snippet} + /// + /// ```dart + /// // (e.g. in a stateful widget) + /// + /// final ScrollController controllerOne = ScrollController(); + /// final ScrollController controllerTwo = ScrollController(); + /// + /// @override + /// Widget build(BuildContext context) { + /// return Column( + /// children: <Widget>[ + /// SizedBox( + /// height: 200, + /// child: Scrollbar( + /// thumbVisibility: true, + /// controller: controllerOne, + /// child: ListView.builder( + /// controller: controllerOne, + /// itemCount: 120, + /// itemBuilder: (BuildContext context, int index) { + /// return Text('item $index'); + /// }, + /// ), + /// ), + /// ), + /// SizedBox( + /// height: 200, + /// child: CupertinoScrollbar( + /// thumbVisibility: true, + /// controller: controllerTwo, + /// child: SingleChildScrollView( + /// controller: controllerTwo, + /// child: const SizedBox( + /// height: 2000, + /// width: 500, + /// child: Placeholder(), + /// ), + /// ), + /// ), + /// ), + /// ], + /// ); + /// } + /// ``` + /// {@end-tool} + /// + /// See also: + /// + /// * [RawScrollbarState.showScrollbar], an overridable getter which uses + /// this value to override the default behavior. + /// * [ScrollView.primary], which indicates whether the ScrollView is the primary + /// scroll view associated with the parent [PrimaryScrollController]. + /// * [PrimaryScrollController], which associates a [ScrollController] with + /// a subtree. + /// {@endtemplate} + /// + /// Subclass [Scrollbar] can hide and show the scrollbar thumb in response to + /// [MaterialState]s by using [ScrollbarThemeData.thumbVisibility]. + final bool? thumbVisibility; + + /// The [OutlinedBorder] of the scrollbar's thumb. + /// + /// Only one of [radius] and [shape] may be specified. For a rounded rectangle, + /// it's simplest to just specify [radius]. By default, the scrollbar thumb's + /// shape is a simple rectangle. + /// + /// If [shape] is specified, the thumb will take the shape of the passed + /// [OutlinedBorder] and fill itself with [thumbColor] (or grey if it + /// is unspecified). + /// + /// {@tool dartpad} + /// This is an example of using a [StadiumBorder] for drawing the [shape] of the + /// thumb in a [RawScrollbar]. + /// + /// ** See code in examples/api/lib/widgets/scrollbar/raw_scrollbar.shape.0.dart ** + /// {@end-tool} + final OutlinedBorder? shape; + + /// The [Radius] of the scrollbar thumb's rounded rectangle corners. + /// + /// Scrollbar will be rectangular if [radius] is null, which is the default + /// behavior. + final Radius? radius; + + /// The thickness of the scrollbar in the cross axis of the scrollable. + /// + /// If null, will default to 6.0 pixels. + final double? thickness; + + /// The color of the scrollbar thumb. + /// + /// If null, defaults to Color(0x66BCBCBC). + final Color? thumbColor; + + /// The preferred smallest size the scrollbar thumb can shrink to when the total + /// scrollable extent is large, the current visible viewport is small, and the + /// viewport is not overscrolled. + /// + /// The size of the scrollbar's thumb may shrink to a smaller size than [minThumbLength] + /// to fit in the available paint area (e.g., when [minThumbLength] is greater + /// than [ScrollMetrics.viewportDimension] and [mainAxisMargin] combined). + /// + /// Mustn't be null and the value has to be greater or equal to + /// [minOverscrollLength], which in turn is >= 0. Defaults to 18.0. + final double minThumbLength; + + /// The preferred smallest size the scrollbar thumb can shrink to when viewport is + /// overscrolled. + /// + /// When overscrolling, the size of the scrollbar's thumb may shrink to a smaller size + /// than [minOverscrollLength] to fit in the available paint area (e.g., when + /// [minOverscrollLength] is greater than [ScrollMetrics.viewportDimension] and + /// [mainAxisMargin] combined). + /// + /// Overscrolling can be made possible by setting the `physics` property + /// of the `child` Widget to a `BouncingScrollPhysics`, which is a special + /// `ScrollPhysics` that allows overscrolling. + /// + /// The value is less than or equal to [minThumbLength] and greater than or equal to 0. + /// When null, it will default to the value of [minThumbLength]. + final double? minOverscrollLength; + + /// {@template flutter.widgets.Scrollbar.trackVisibility} + /// Indicates that the scrollbar track should be visible. + /// + /// When true, the scrollbar track will always be visible so long as the thumb + /// is visible. If the scrollbar thumb is not visible, the track will not be + /// visible either. + /// + /// Defaults to false when null. + /// {@endtemplate} + /// + /// Subclass [Scrollbar] can hide and show the scrollbar thumb in response to + /// [MaterialState]s by using [ScrollbarThemeData.trackVisibility]. + final bool? trackVisibility; + + /// The [Radius] of the scrollbar track's rounded rectangle corners. + /// + /// Scrollbar's track will be rectangular if [trackRadius] is null, which is + /// the default behavior. + final Radius? trackRadius; + + /// The color of the scrollbar track. + /// + /// The scrollbar track will only be visible when [trackVisibility] and + /// [thumbVisibility] are true. + /// + /// If null, defaults to Color(0x08000000). + final Color? trackColor; + + /// The color of the scrollbar track's border. + /// + /// The scrollbar track will only be visible when [trackVisibility] and + /// [thumbVisibility] are true. + /// + /// If null, defaults to Color(0x1a000000). + final Color? trackBorderColor; + + /// The [Duration] of the fade animation. + /// + /// Defaults to a [Duration] of 300 milliseconds. + final Duration fadeDuration; + + /// The [Duration] of time until the fade animation begins. + /// + /// Defaults to a [Duration] of 600 milliseconds. + final Duration timeToFade; + + /// The [Duration] of time that a LongPress will trigger the drag gesture of + /// the scrollbar thumb. + /// + /// Defaults to [Duration.zero]. + final Duration pressDuration; + + /// {@template flutter.widgets.Scrollbar.notificationPredicate} + /// A check that specifies whether a [ScrollNotification] should be + /// handled by this widget. + /// + /// By default, checks whether `notification.depth == 0`. That means if the + /// scrollbar is wrapped around multiple [ScrollView]s, it only responds to the + /// nearest scrollView and shows the corresponding scrollbar thumb. + /// {@endtemplate} + final ScrollNotificationPredicate notificationPredicate; + + /// {@template flutter.widgets.Scrollbar.interactive} + /// Whether the Scrollbar should be interactive and respond to dragging on the + /// thumb, or tapping in the track area. + /// + /// Does not apply to the [CupertinoScrollbar], which is always interactive to + /// match native behavior. On Android, the scrollbar is not interactive by + /// default. + /// + /// When false, the scrollbar will not respond to gesture or hover events, + /// and will allow to click through it. + /// + /// Defaults to true when null, unless on Android, which will default to false + /// when null. + /// + /// See also: + /// + /// * [RawScrollbarState.enableGestures], an overridable getter which uses + /// this value to override the default behavior. + /// {@endtemplate} + final bool? interactive; + + /// {@macro flutter.widgets.Scrollbar.scrollbarOrientation} + final ScrollbarOrientation? scrollbarOrientation; + + /// Distance from the scrollbar thumb's start or end to the nearest edge of + /// the viewport in logical pixels. It affects the amount of available + /// paint area. + /// + /// The scrollbar track consumes this space. + /// + /// Mustn't be null and defaults to 0. + final double mainAxisMargin; + + /// Distance from the scrollbar thumb's side to the nearest cross axis edge + /// in logical pixels. + /// + /// The scrollbar track consumes this space. + /// + /// Defaults to zero. + final double crossAxisMargin; + + /// The insets by which the scrollbar thumb and track should be padded. + /// + /// When null, the inherited [MediaQueryData.padding] is used. + /// + /// Defaults to null. + final EdgeInsets? padding; + + @override + RawScrollbarState<RawScrollbar> createState() => RawScrollbarState<RawScrollbar>(); +} + +/// The state for a [RawScrollbar] widget, also shared by the [Scrollbar] and +/// [CupertinoScrollbar] widgets. +/// +/// Controls the animation that fades a scrollbar's thumb in and out of view. +/// +/// Provides defaults gestures for dragging the scrollbar thumb and tapping on the +/// scrollbar track. +class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProviderStateMixin<T> { + Offset? _startDragScrollbarAxisOffset; + Offset? _lastDragUpdateOffset; + double? _startDragThumbOffset; + ScrollController? _cachedController; + Timer? _fadeoutTimer; + late AnimationController _fadeoutAnimationController; + late Animation<double> _fadeoutOpacityAnimation; + final GlobalKey _scrollbarPainterKey = GlobalKey(); + bool _hoverIsActive = false; + bool _thumbDragging = false; + + ScrollController? get _effectiveScrollController => widget.controller ?? PrimaryScrollController.maybeOf(context); + + /// Used to paint the scrollbar. + /// + /// Can be customized by subclasses to change scrollbar behavior by overriding + /// [updateScrollbarPainter]. + @protected + late final ScrollbarPainter scrollbarPainter; + + /// Overridable getter to indicate that the scrollbar should be visible, even + /// when a scroll is not underway. + /// + /// Subclasses can override this getter to make its value depend on an inherited + /// theme. + /// + /// Defaults to false when [RawScrollbar.thumbVisibility] is null. + @protected + bool get showScrollbar => widget.thumbVisibility ?? false; + + bool get _showTrack => showScrollbar && (widget.trackVisibility ?? false); + + /// Overridable getter to indicate is gestures should be enabled on the + /// scrollbar. + /// + /// When false, the scrollbar will not respond to gesture or hover events, + /// and will allow to click through it. + /// + /// Subclasses can override this getter to make its value depend on an inherited + /// theme. + /// + /// Defaults to true when [RawScrollbar.interactive] is null. + /// + /// See also: + /// + /// * [RawScrollbar.interactive], which overrides the default behavior. + @protected + bool get enableGestures => widget.interactive ?? true; + + @override + void initState() { + super.initState(); + _fadeoutAnimationController = AnimationController( + vsync: this, + duration: widget.fadeDuration, + )..addStatusListener(_validateInteractions); + _fadeoutOpacityAnimation = CurvedAnimation( + parent: _fadeoutAnimationController, + curve: Curves.fastOutSlowIn, + ); + scrollbarPainter = ScrollbarPainter( + color: widget.thumbColor ?? const Color(0x66BCBCBC), + fadeoutOpacityAnimation: _fadeoutOpacityAnimation, + thickness: widget.thickness ?? _kScrollbarThickness, + radius: widget.radius, + trackRadius: widget.trackRadius, + scrollbarOrientation: widget.scrollbarOrientation, + mainAxisMargin: widget.mainAxisMargin, + shape: widget.shape, + crossAxisMargin: widget.crossAxisMargin, + minLength: widget.minThumbLength, + minOverscrollLength: widget.minOverscrollLength ?? widget.minThumbLength, + ); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + assert(_debugScheduleCheckHasValidScrollPosition()); + } + + bool _debugScheduleCheckHasValidScrollPosition() { + if (!showScrollbar) { + return true; + } + WidgetsBinding.instance.addPostFrameCallback((Duration duration) { + assert(_debugCheckHasValidScrollPosition()); + }, debugLabel: 'RawScrollbar.checkScrollPosition'); + return true; + } + + void _validateInteractions(AnimationStatus status) { + if (status == AnimationStatus.dismissed) { + assert(_fadeoutOpacityAnimation.value == 0.0); + // We do not check for a valid scroll position if the scrollbar is not + // visible, because it cannot be interacted with. + } else if (_effectiveScrollController != null && enableGestures) { + // Interactive scrollbars need to be properly configured. If it is visible + // for interaction, ensure we are set up properly. + assert(_debugCheckHasValidScrollPosition()); + } + } + + bool _debugCheckHasValidScrollPosition() { + if (!mounted) { + return true; + } + final ScrollController? scrollController = _effectiveScrollController; + final bool tryPrimary = widget.controller == null; + final String controllerForError = tryPrimary + ? 'PrimaryScrollController' + : 'provided ScrollController'; + + String when = ''; + if (widget.thumbVisibility ?? false) { + when = 'Scrollbar.thumbVisibility is true'; + } else if (enableGestures) { + when = 'the scrollbar is interactive'; + } else { + when = 'using the Scrollbar'; + } + + assert( + scrollController != null, + 'A ScrollController is required when $when. ' + '${tryPrimary ? 'The Scrollbar was not provided a ScrollController, ' + 'and attempted to use the PrimaryScrollController, but none was found.' :''}', + ); + assert (() { + if (!scrollController!.hasClients) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + "The Scrollbar's ScrollController has no ScrollPosition attached.", + ), + ErrorDescription( + 'A Scrollbar cannot be painted without a ScrollPosition. ', + ), + ErrorHint( + 'The Scrollbar attempted to use the $controllerForError. This ' + 'ScrollController should be associated with the ScrollView that ' + 'the Scrollbar is being applied to.' + '${tryPrimary + ? 'When ScrollView.scrollDirection is Axis.vertical on mobile ' + 'platforms will automatically use the ' + 'PrimaryScrollController if the user has not provided a ' + 'ScrollController. To use the PrimaryScrollController ' + 'explicitly, set ScrollView.primary to true for the Scrollable ' + 'widget.' + : 'When providing your own ScrollController, ensure both the ' + 'Scrollbar and the Scrollable widget use the same one.' + }', + ), + ]); + } + return true; + }()); + assert (() { + try { + scrollController!.position; + } catch (error) { + if (scrollController == null || scrollController.positions.length <= 1) { + rethrow; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'The $controllerForError is currently attached to more than one ' + 'ScrollPosition.', + ), + ErrorDescription( + 'The Scrollbar requires a single ScrollPosition in order to be painted.', + ), + ErrorHint( + 'When $when, the associated ScrollController must only have one ' + 'ScrollPosition attached.' + '${tryPrimary + ? 'If a ScrollController has not been provided, the ' + 'PrimaryScrollController is used by default on mobile platforms ' + 'for ScrollViews with an Axis.vertical scroll direction. More ' + 'than one ScrollView may have tried to use the ' + 'PrimaryScrollController of the current context. ' + 'ScrollView.primary can override this behavior.' + : 'The provided ScrollController must be unique to one ' + 'ScrollView widget.' + }', + ), + ]); + } + return true; + }()); + return true; + } + + /// This method is responsible for configuring the [scrollbarPainter] + /// according to the [widget]'s properties and any inherited widgets the + /// painter depends on, like [Directionality] and [MediaQuery]. + /// + /// Subclasses can override to configure the [scrollbarPainter]. + @protected + void updateScrollbarPainter() { + scrollbarPainter + ..color = widget.thumbColor ?? const Color(0x66BCBCBC) + ..trackRadius = widget.trackRadius + ..trackColor = _showTrack + ? widget.trackColor ?? const Color(0x08000000) + : const Color(0x00000000) + ..trackBorderColor = _showTrack + ? widget.trackBorderColor ?? const Color(0x1a000000) + : const Color(0x00000000) + ..textDirection = Directionality.of(context) + ..thickness = widget.thickness ?? _kScrollbarThickness + ..radius = widget.radius + ..padding = widget.padding ?? MediaQuery.paddingOf(context) + ..scrollbarOrientation = widget.scrollbarOrientation + ..mainAxisMargin = widget.mainAxisMargin + ..shape = widget.shape + ..crossAxisMargin = widget.crossAxisMargin + ..minLength = widget.minThumbLength + ..minOverscrollLength = widget.minOverscrollLength ?? widget.minThumbLength + ..ignorePointer = !enableGestures; + } + + @override + void didUpdateWidget(T oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.thumbVisibility != oldWidget.thumbVisibility) { + if (widget.thumbVisibility ?? false) { + assert(_debugScheduleCheckHasValidScrollPosition()); + _fadeoutTimer?.cancel(); + _fadeoutAnimationController.animateTo(1.0); + } else { + _fadeoutAnimationController.reverse(); + } + } + } + + void _updateScrollPosition(Offset updatedOffset) { + assert(_cachedController != null); + assert(_startDragScrollbarAxisOffset != null); + assert(_lastDragUpdateOffset != null); + assert(_startDragThumbOffset != null); + + final ScrollPosition position = _cachedController!.position; + late double primaryDeltaFromDragStart; + late double primaryDeltaFromLastDragUpdate; + switch (position.axisDirection) { + case AxisDirection.up: + primaryDeltaFromDragStart = _startDragScrollbarAxisOffset!.dy - updatedOffset.dy; + primaryDeltaFromLastDragUpdate = _lastDragUpdateOffset!.dy - updatedOffset.dy; + case AxisDirection.right: + primaryDeltaFromDragStart = updatedOffset.dx -_startDragScrollbarAxisOffset!.dx; + primaryDeltaFromLastDragUpdate = updatedOffset.dx -_lastDragUpdateOffset!.dx; + case AxisDirection.down: + primaryDeltaFromDragStart = updatedOffset.dy -_startDragScrollbarAxisOffset!.dy; + primaryDeltaFromLastDragUpdate = updatedOffset.dy -_lastDragUpdateOffset!.dy; + case AxisDirection.left: + primaryDeltaFromDragStart = _startDragScrollbarAxisOffset!.dx - updatedOffset.dx; + primaryDeltaFromLastDragUpdate = _lastDragUpdateOffset!.dx - updatedOffset.dx; + } + + // Convert primaryDelta, the amount that the scrollbar moved since the last + // time when drag started or last updated, into the coordinate space of the scroll + // position, and jump to that position. + double scrollOffsetGlobal = scrollbarPainter.getTrackToScroll(primaryDeltaFromDragStart + _startDragThumbOffset!); + if (primaryDeltaFromDragStart > 0 && scrollOffsetGlobal < position.pixels + || primaryDeltaFromDragStart < 0 && scrollOffsetGlobal > position.pixels) { + // Adjust the position value if the scrolling direction conflicts with + // the dragging direction due to scroll metrics shrink. + scrollOffsetGlobal = position.pixels + scrollbarPainter.getTrackToScroll(primaryDeltaFromLastDragUpdate); + } + if (scrollOffsetGlobal != position.pixels) { + // Ensure we don't drag into overscroll if the physics do not allow it. + final double physicsAdjustment = position.physics.applyBoundaryConditions(position, scrollOffsetGlobal); + double newPosition = scrollOffsetGlobal - physicsAdjustment; + + // The physics may allow overscroll when actually *scrolling*, but + // dragging on the scrollbar does not always allow us to enter overscroll. + switch (ScrollConfiguration.of(context).getPlatform(context)) { + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + newPosition = clampDouble(newPosition, position.minScrollExtent, position.maxScrollExtent); + case TargetPlatform.iOS: + case TargetPlatform.android: + // We can only drag the scrollbar into overscroll on mobile + // platforms, and only then if the physics allow it. + break; + } + position.jumpTo(newPosition); + } + } + + void _maybeStartFadeoutTimer() { + if (!showScrollbar) { + _fadeoutTimer?.cancel(); + _fadeoutTimer = Timer(widget.timeToFade, () { + _fadeoutAnimationController.reverse(); + _fadeoutTimer = null; + }); + } + } + + /// Returns the [Axis] of the child scroll view, or null if the + /// current scroll controller does not have any attached positions. + @protected + Axis? getScrollbarDirection() { + assert(_cachedController != null); + if (_cachedController!.hasClients) { + return _cachedController!.position.axis; + } + return null; + } + + /// Handler called when a press on the scrollbar thumb has been recognized. + /// + /// Cancels the [Timer] associated with the fade animation of the scrollbar. + @protected + @mustCallSuper + void handleThumbPress() { + assert(_debugCheckHasValidScrollPosition()); + if (getScrollbarDirection() == null) { + return; + } + _fadeoutTimer?.cancel(); + } + + /// Handler called when a long press gesture has started. + /// + /// Begins the fade out animation and initializes dragging the scrollbar thumb. + @protected + @mustCallSuper + void handleThumbPressStart(Offset localPosition) { + assert(_debugCheckHasValidScrollPosition()); + _cachedController = _effectiveScrollController; + final Axis? direction = getScrollbarDirection(); + if (direction == null) { + return; + } + _fadeoutTimer?.cancel(); + _fadeoutAnimationController.forward(); + _startDragScrollbarAxisOffset = localPosition; + _lastDragUpdateOffset = localPosition; + _startDragThumbOffset = scrollbarPainter.getThumbScrollOffset(); + _thumbDragging = true; + } + + /// Handler called when a currently active long press gesture moves. + /// + /// Updates the position of the child scrollable. + @protected + @mustCallSuper + void handleThumbPressUpdate(Offset localPosition) { + assert(_debugCheckHasValidScrollPosition()); + if (_lastDragUpdateOffset == localPosition) { + return; + } + final ScrollPosition position = _cachedController!.position; + if (!position.physics.shouldAcceptUserOffset(position)) { + return; + } + final Axis? direction = getScrollbarDirection(); + if (direction == null) { + return; + } + _updateScrollPosition(localPosition); + _lastDragUpdateOffset = localPosition; + } + + /// Handler called when a long press has ended. + @protected + @mustCallSuper + void handleThumbPressEnd(Offset localPosition, Velocity velocity) { + assert(_debugCheckHasValidScrollPosition()); + _thumbDragging = false; + final Axis? direction = getScrollbarDirection(); + if (direction == null) { + return; + } + _maybeStartFadeoutTimer(); + _startDragScrollbarAxisOffset = null; + _lastDragUpdateOffset = null; + _startDragThumbOffset = null; + _cachedController = null; + } + + void _handleTrackTapDown(TapDownDetails details) { + // The Scrollbar should page towards the position of the tap on the track. + assert(_debugCheckHasValidScrollPosition()); + _cachedController = _effectiveScrollController; + + final ScrollPosition position = _cachedController!.position; + if (!position.physics.shouldAcceptUserOffset(position)) { + return; + } + + // Determines the scroll direction. + final AxisDirection scrollDirection; + + switch (position.axisDirection) { + case AxisDirection.up: + case AxisDirection.down: + if (details.localPosition.dy > scrollbarPainter._thumbOffset) { + scrollDirection = AxisDirection.down; + } else { + scrollDirection = AxisDirection.up; + } + case AxisDirection.left: + case AxisDirection.right: + if (details.localPosition.dx > scrollbarPainter._thumbOffset) { + scrollDirection = AxisDirection.right; + } else { + scrollDirection = AxisDirection.left; + } + } + + final ScrollableState? state = Scrollable.maybeOf(position.context.notificationContext!); + final ScrollIntent intent = ScrollIntent(direction: scrollDirection, type: ScrollIncrementType.page); + assert(state != null); + final double scrollIncrement = ScrollAction.getDirectionalIncrement(state!, intent); + + _cachedController!.position.moveTo( + _cachedController!.position.pixels + scrollIncrement, + duration: const Duration(milliseconds: 100), + curve: Curves.easeInOut, + ); + } + + // ScrollController takes precedence over ScrollNotification + bool _shouldUpdatePainter(Axis notificationAxis) { + final ScrollController? scrollController = _effectiveScrollController; + // Only update the painter of this scrollbar if the notification + // metrics do not conflict with the information we have from the scroll + // controller. + + // We do not have a scroll controller dictating axis. + if (scrollController == null) { + return true; + } + // Has more than one attached positions. + if (scrollController.positions.length > 1) { + return false; + } + + return + // The scroll controller is not attached to a position. + !scrollController.hasClients + // The notification matches the scroll controller's axis. + || scrollController.position.axis == notificationAxis; + } + + bool _handleScrollMetricsNotification(ScrollMetricsNotification notification) { + if (!widget.notificationPredicate(notification.asScrollUpdate())) { + return false; + } + + if (showScrollbar) { + if (_fadeoutAnimationController.status != AnimationStatus.forward && + _fadeoutAnimationController.status != AnimationStatus.completed) { + _fadeoutAnimationController.forward(); + } + } + + final ScrollMetrics metrics = notification.metrics; + if (_shouldUpdatePainter(metrics.axis)) { + scrollbarPainter.update(metrics, metrics.axisDirection); + } + return false; + } + + bool _handleScrollNotification(ScrollNotification notification) { + if (!widget.notificationPredicate(notification)) { + return false; + } + + final ScrollMetrics metrics = notification.metrics; + if (metrics.maxScrollExtent <= metrics.minScrollExtent) { + // Hide the bar when the Scrollable widget has no space to scroll. + if (_fadeoutAnimationController.status != AnimationStatus.dismissed && + _fadeoutAnimationController.status != AnimationStatus.reverse) { + _fadeoutAnimationController.reverse(); + } + + if (_shouldUpdatePainter(metrics.axis)) { + scrollbarPainter.update(metrics, metrics.axisDirection); + } + return false; + } + + if (notification is ScrollUpdateNotification || + notification is OverscrollNotification) { + // Any movements always makes the scrollbar start showing up. + if (_fadeoutAnimationController.status != AnimationStatus.forward && + _fadeoutAnimationController.status != AnimationStatus.completed) { + _fadeoutAnimationController.forward(); + } + + _fadeoutTimer?.cancel(); + + if (_shouldUpdatePainter(metrics.axis)) { + scrollbarPainter.update(metrics, metrics.axisDirection); + } + } else if (notification is ScrollEndNotification) { + if (_startDragScrollbarAxisOffset == null) { + _maybeStartFadeoutTimer(); + } + } + return false; + } + + Map<Type, GestureRecognizerFactory> get _gestures { + final Map<Type, GestureRecognizerFactory> gestures = <Type, GestureRecognizerFactory>{}; + if (_effectiveScrollController == null || !enableGestures) { + return gestures; + } + + gestures[_ThumbPressGestureRecognizer] = + GestureRecognizerFactoryWithHandlers<_ThumbPressGestureRecognizer>( + () => _ThumbPressGestureRecognizer( + debugOwner: this, + customPaintKey: _scrollbarPainterKey, + duration: widget.pressDuration, + ), + (_ThumbPressGestureRecognizer instance) { + instance.onLongPress = handleThumbPress; + instance.onLongPressStart = (LongPressStartDetails details) => handleThumbPressStart(details.localPosition); + instance.onLongPressMoveUpdate = (LongPressMoveUpdateDetails details) => handleThumbPressUpdate(details.localPosition); + instance.onLongPressEnd = (LongPressEndDetails details) => handleThumbPressEnd(details.localPosition, details.velocity); + }, + ); + + gestures[_TrackTapGestureRecognizer] = + GestureRecognizerFactoryWithHandlers<_TrackTapGestureRecognizer>( + () => _TrackTapGestureRecognizer( + debugOwner: this, + customPaintKey: _scrollbarPainterKey, + ), + (_TrackTapGestureRecognizer instance) { + instance.onTapDown = _handleTrackTapDown; + }, + ); + + return gestures; + } + /// Returns true if the provided [Offset] is located over the track of the + /// [RawScrollbar]. + /// + /// Excludes the [RawScrollbar] thumb. + @protected + bool isPointerOverTrack(Offset position, PointerDeviceKind kind) { + if (_scrollbarPainterKey.currentContext == null) { + return false; + } + final Offset localOffset = _getLocalOffset(_scrollbarPainterKey, position); + return scrollbarPainter.hitTestInteractive(localOffset, kind) + && !scrollbarPainter.hitTestOnlyThumbInteractive(localOffset, kind); + } + /// Returns true if the provided [Offset] is located over the thumb of the + /// [RawScrollbar]. + @protected + bool isPointerOverThumb(Offset position, PointerDeviceKind kind) { + if (_scrollbarPainterKey.currentContext == null) { + return false; + } + final Offset localOffset = _getLocalOffset(_scrollbarPainterKey, position); + return scrollbarPainter.hitTestOnlyThumbInteractive(localOffset, kind); + } + /// Returns true if the provided [Offset] is located over the track or thumb + /// of the [RawScrollbar]. + /// + /// The hit test area for mouse hovering over the scrollbar is larger than + /// regular hit testing. This is to make it easier to interact with the + /// scrollbar and present it to the mouse for interaction based on proximity. + /// When `forHover` is true, the larger hit test area will be used. + @protected + bool isPointerOverScrollbar(Offset position, PointerDeviceKind kind, { bool forHover = false }) { + if (_scrollbarPainterKey.currentContext == null) { + return false; + } + final Offset localOffset = _getLocalOffset(_scrollbarPainterKey, position); + return scrollbarPainter.hitTestInteractive(localOffset, kind, forHover: true); + } + + /// Cancels the fade out animation so the scrollbar will remain visible for + /// interaction. + /// + /// Can be overridden by subclasses to respond to a [PointerHoverEvent]. + /// + /// Helper methods [isPointerOverScrollbar], [isPointerOverThumb], and + /// [isPointerOverTrack] can be used to determine the location of the pointer + /// relative to the painter scrollbar elements. + @protected + @mustCallSuper + void handleHover(PointerHoverEvent event) { + // Check if the position of the pointer falls over the painted scrollbar + if (isPointerOverScrollbar(event.position, event.kind, forHover: true)) { + _hoverIsActive = true; + // Bring the scrollbar back into view if it has faded or started to fade + // away. + _fadeoutAnimationController.forward(); + _fadeoutTimer?.cancel(); + } else if (_hoverIsActive) { + // Pointer is not over painted scrollbar. + _hoverIsActive = false; + _maybeStartFadeoutTimer(); + } + } + + /// Initiates the fade out animation. + /// + /// Can be overridden by subclasses to respond to a [PointerExitEvent]. + @protected + @mustCallSuper + void handleHoverExit(PointerExitEvent event) { + _hoverIsActive = false; + _maybeStartFadeoutTimer(); + } + + // Returns the delta that should result from applying [event] with axis and + // direction taken into account. + double _pointerSignalEventDelta(PointerScrollEvent event) { + assert(_cachedController != null); + double delta = _cachedController!.position.axis == Axis.horizontal + ? event.scrollDelta.dx + : event.scrollDelta.dy; + + if (axisDirectionIsReversed(_cachedController!.position.axisDirection)) { + delta *= -1; + } + return delta; + } + + // Returns the offset that should result from applying [event] to the current + // position, taking min/max scroll extent into account. + double _targetScrollOffsetForPointerScroll(double delta) { + assert(_cachedController != null); + return math.min( + math.max(_cachedController!.position.pixels + delta, _cachedController!.position.minScrollExtent), + _cachedController!.position.maxScrollExtent, + ); + } + + void _handlePointerScroll(PointerEvent event) { + assert(event is PointerScrollEvent); + _cachedController = _effectiveScrollController; + final double delta = _pointerSignalEventDelta(event as PointerScrollEvent); + final double targetScrollOffset = _targetScrollOffsetForPointerScroll(delta); + if (delta != 0.0 && targetScrollOffset != _cachedController!.position.pixels) { + _cachedController!.position.pointerScroll(delta); + } + } + + void _receivedPointerSignal(PointerSignalEvent event) { + _cachedController = _effectiveScrollController; + // Only try to scroll if the bar absorb the hit test. + if ((scrollbarPainter.hitTest(event.localPosition) ?? false) && + _cachedController != null && + _cachedController!.hasClients && + (!_thumbDragging || kIsWeb)) { + final ScrollPosition position = _cachedController!.position; + if (event is PointerScrollEvent) { + if (!position.physics.shouldAcceptUserOffset(position)) { + return; + } + final double delta = _pointerSignalEventDelta(event); + final double targetScrollOffset = _targetScrollOffsetForPointerScroll(delta); + if (delta != 0.0 && targetScrollOffset != position.pixels) { + GestureBinding.instance.pointerSignalResolver.register(event, _handlePointerScroll); + } + } else if (event is PointerScrollInertiaCancelEvent) { + position.jumpTo(position.pixels); + // Don't use the pointer signal resolver, all hit-tested scrollables should stop. + } + } + } + + @override + void dispose() { + _fadeoutAnimationController.dispose(); + _fadeoutTimer?.cancel(); + scrollbarPainter.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + updateScrollbarPainter(); + + return NotificationListener<ScrollMetricsNotification>( + onNotification: _handleScrollMetricsNotification, + child: NotificationListener<ScrollNotification>( + onNotification: _handleScrollNotification, + child: RepaintBoundary( + child: Listener( + onPointerSignal: _receivedPointerSignal, + child: RawGestureDetector( + gestures: _gestures, + child: MouseRegion( + onExit: (PointerExitEvent event) { + switch (event.kind) { + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + if (enableGestures) { + handleHoverExit(event); + } + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.unknown: + case PointerDeviceKind.touch: + break; + } + }, + onHover: (PointerHoverEvent event) { + switch (event.kind) { + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + if (enableGestures) { + handleHover(event); + } + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.unknown: + case PointerDeviceKind.touch: + break; + } + }, + child: CustomPaint( + key: _scrollbarPainterKey, + foregroundPainter: scrollbarPainter, + child: RepaintBoundary(child: widget.child), + ), + ), + ), + ), + ), + ), + ); + } +} + +// A long press gesture detector that only responds to events on the scrollbar's +// thumb and ignores everything else. +class _ThumbPressGestureRecognizer extends LongPressGestureRecognizer { + _ThumbPressGestureRecognizer({ + required Object super.debugOwner, + required GlobalKey customPaintKey, + required super.duration, + }) : _customPaintKey = customPaintKey; + + final GlobalKey _customPaintKey; + + @override + bool isPointerAllowed(PointerDownEvent event) { + if (!_hitTestInteractive(_customPaintKey, event.position, event.kind)) { + return false; + } + return super.isPointerAllowed(event); + } + + bool _hitTestInteractive(GlobalKey customPaintKey, Offset offset, PointerDeviceKind kind) { + if (customPaintKey.currentContext == null) { + return false; + } + final CustomPaint customPaint = customPaintKey.currentContext!.widget as CustomPaint; + final ScrollbarPainter painter = customPaint.foregroundPainter! as ScrollbarPainter; + final Offset localOffset = _getLocalOffset(customPaintKey, offset); + return painter.hitTestOnlyThumbInteractive(localOffset, kind); + } +} + +// A tap gesture detector that only responds to events on the scrollbar's +// track and ignores everything else, including the thumb. +class _TrackTapGestureRecognizer extends TapGestureRecognizer { + _TrackTapGestureRecognizer({ + required super.debugOwner, + required GlobalKey customPaintKey, + }) : _customPaintKey = customPaintKey; + + final GlobalKey _customPaintKey; + + @override + bool isPointerAllowed(PointerDownEvent event) { + if (!_hitTestInteractive(_customPaintKey, event.position, event.kind)) { + return false; + } + return super.isPointerAllowed(event); + } + + bool _hitTestInteractive(GlobalKey customPaintKey, Offset offset, PointerDeviceKind kind) { + if (customPaintKey.currentContext == null) { + return false; + } + final CustomPaint customPaint = customPaintKey.currentContext!.widget as CustomPaint; + final ScrollbarPainter painter = customPaint.foregroundPainter! as ScrollbarPainter; + final Offset localOffset = _getLocalOffset(customPaintKey, offset); + // We only receive track taps that are not on the thumb. + return painter.hitTestInteractive(localOffset, kind) && !painter.hitTestOnlyThumbInteractive(localOffset, kind); + } +} + +Offset _getLocalOffset(GlobalKey scrollbarPainterKey, Offset position) { + final RenderBox renderBox = scrollbarPainterKey.currentContext!.findRenderObject()! as RenderBox; + return renderBox.globalToLocal(position); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/selectable_region.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/selectable_region.dart new file mode 100644 index 0000000000000000000000000000000000000000..8fbdb763a7767aa976be6ed6542c7c38d7e5ea1f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/selectable_region.dart @@ -0,0 +1,2519 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; +import 'package:vector_math/vector_math_64.dart'; + +import 'actions.dart'; +import 'basic.dart'; +import 'context_menu_button_item.dart'; +import 'debug.dart'; +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'magnifier.dart'; +import 'media_query.dart'; +import 'overlay.dart'; +import 'platform_selectable_region_context_menu.dart'; +import 'selection_container.dart'; +import 'text_editing_intents.dart'; +import 'text_selection.dart'; +import 'text_selection_toolbar_anchors.dart'; + +// Examples can assume: +// FocusNode _focusNode = FocusNode(); +// late GlobalKey key; + +const Set<PointerDeviceKind> _kLongPressSelectionDevices = <PointerDeviceKind>{ + PointerDeviceKind.touch, + PointerDeviceKind.stylus, + PointerDeviceKind.invertedStylus, +}; + +// In practice some selectables like widgetspan shift several pixels. So when +// the vertical position diff is within the threshold, compare the horizontal +// position to make the compareScreenOrder function more robust. +const double _kSelectableVerticalComparingThreshold = 3.0; + +/// A widget that introduces an area for user selections. +/// +/// Flutter widgets are not selectable by default. Wrapping a widget subtree +/// with a [SelectableRegion] widget enables selection within that subtree (for +/// example, [Text] widgets automatically look for selectable regions to enable +/// selection). The wrapped subtree can be selected by users using mouse or +/// touch gestures, e.g. users can select widgets by holding the mouse +/// left-click and dragging across widgets, or they can use long press gestures +/// to select words on touch devices. +/// +/// A [SelectableRegion] widget requires configuration; in particular specific +/// [selectionControls] must be provided. +/// +/// The [SelectionArea] widget from the [material] library configures a +/// [SelectableRegion] in a platform-specific manner (e.g. using a Material +/// toolbar on Android, a Cupertino toolbar on iOS), and it may therefore be +/// simpler to use that widget rather than using [SelectableRegion] directly. +/// +/// ## An overview of the selection system. +/// +/// Every [Selectable] under the [SelectableRegion] can be selected. They form a +/// selection tree structure to handle the selection. +/// +/// The [SelectableRegion] is a wrapper over [SelectionContainer]. It listens to +/// user gestures and sends corresponding [SelectionEvent]s to the +/// [SelectionContainer] it creates. +/// +/// A [SelectionContainer] is a single [Selectable] that handles +/// [SelectionEvent]s on behalf of child [Selectable]s in the subtree. It +/// creates a [SelectionRegistrarScope] with its [SelectionContainer.delegate] +/// to collect child [Selectable]s and sends the [SelectionEvent]s it receives +/// from the parent [SelectionRegistrar] to the appropriate child [Selectable]s. +/// It creates an abstraction for the parent [SelectionRegistrar] as if it is +/// interacting with a single [Selectable]. +/// +/// The [SelectionContainer] created by [SelectableRegion] is the root node of a +/// selection tree. Each non-leaf node in the tree is a [SelectionContainer], +/// and the leaf node is a leaf widget whose render object implements +/// [Selectable]. They are connected through [SelectionRegistrarScope]s created +/// by [SelectionContainer]s. +/// +/// Both [SelectionContainer]s and the leaf [Selectable]s need to register +/// themselves to the [SelectionRegistrar] from the +/// [SelectionContainer.maybeOf] if they want to participate in the +/// selection. +/// +/// An example selection tree will look like: +/// +/// {@tool snippet} +/// +/// ```dart +/// MaterialApp( +/// home: SelectableRegion( +/// selectionControls: materialTextSelectionControls, +/// focusNode: _focusNode, // initialized to FocusNode() +/// child: Scaffold( +/// appBar: AppBar(title: const Text('Flutter Code Sample')), +/// body: ListView( +/// children: const <Widget>[ +/// Text('Item 0', style: TextStyle(fontSize: 50.0)), +/// Text('Item 1', style: TextStyle(fontSize: 50.0)), +/// ], +/// ), +/// ), +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// +/// SelectionContainer +/// (SelectableRegion) +/// / \ +/// / \ +/// / \ +/// Selectable \ +/// ("Flutter Code Sample") \ +/// \ +/// SelectionContainer +/// (ListView) +/// / \ +/// / \ +/// / \ +/// Selectable Selectable +/// ("Item 0") ("Item 1") +/// +/// +/// ## Making a widget selectable +/// +/// Some leaf widgets, such as [Text], have all of the selection logic wired up +/// automatically and can be selected as long as they are under a +/// [SelectableRegion]. +/// +/// To make a custom selectable widget, its render object needs to mix in +/// [Selectable] and implement the required APIs to handle [SelectionEvent]s +/// as well as paint appropriate selection highlights. +/// +/// The render object also needs to register itself to a [SelectionRegistrar]. +/// For the most cases, one can use [SelectionRegistrant] to auto-register +/// itself with the register returned from [SelectionContainer.maybeOf] as +/// seen in the example below. +/// +/// {@tool dartpad} +/// This sample demonstrates how to create an adapter widget that makes any +/// child widget selectable. +/// +/// ** See code in examples/api/lib/material/selectable_region/selectable_region.0.dart ** +/// {@end-tool} +/// +/// ## Complex layout +/// +/// By default, the screen order is used as the selection order. If a group of +/// [Selectable]s needs to select differently, consider wrapping them with a +/// [SelectionContainer] to customize its selection behavior. +/// +/// {@tool dartpad} +/// This sample demonstrates how to create a [SelectionContainer] that only +/// allows selecting everything or nothing with no partial selection. +/// +/// ** See code in examples/api/lib/material/selection_container/selection_container.0.dart ** +/// {@end-tool} +/// +/// In the case where a group of widgets should be excluded from selection under +/// a [SelectableRegion], consider wrapping that group of widgets using +/// [SelectionContainer.disabled]. +/// +/// {@tool dartpad} +/// This sample demonstrates how to disable selection for a Text in a Column. +/// +/// ** See code in examples/api/lib/material/selection_container/selection_container_disabled.0.dart ** +/// {@end-tool} +/// +/// To create a separate selection system from its parent selection area, +/// wrap part of the subtree with another [SelectableRegion]. The selection of the +/// child selection area can not extend past its subtree, and the selection of +/// the parent selection area can not extend inside the child selection area. +/// +/// ## Tests +/// +/// In a test, a region can be selected either by faking drag events (e.g. using +/// [WidgetTester.dragFrom]) or by sending intents to a widget inside the region +/// that has been given a [GlobalKey], e.g.: +/// +/// ```dart +/// Actions.invoke(key.currentContext!, const SelectAllTextIntent(SelectionChangedCause.keyboard)); +/// ``` +/// +/// See also: +/// * [SelectionArea], which creates a [SelectableRegion] with +/// platform-adaptive selection controls. +/// * [SelectionHandler], which contains APIs to handle selection events from the +/// [SelectableRegion]. +/// * [Selectable], which provides API to participate in the selection system. +/// * [SelectionRegistrar], which [Selectable] needs to subscribe to receive +/// selection events. +/// * [SelectionContainer], which collects selectable widgets in the subtree +/// and provides api to dispatch selection event to the collected widget. +class SelectableRegion extends StatefulWidget { + /// Create a new [SelectableRegion] widget. + /// + /// The [selectionControls] are used for building the selection handles and + /// toolbar for mobile devices. + const SelectableRegion({ + super.key, + this.contextMenuBuilder, + required this.focusNode, + required this.selectionControls, + required this.child, + this.magnifierConfiguration = TextMagnifierConfiguration.disabled, + this.onSelectionChanged, + }); + + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.intro} + /// + /// {@macro flutter.widgets.magnifier.intro} + /// + /// By default, [SelectableRegion]'s [TextMagnifierConfiguration] is disabled. + /// + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.details} + final TextMagnifierConfiguration magnifierConfiguration; + + /// {@macro flutter.widgets.Focus.focusNode} + final FocusNode focusNode; + + /// The child widget this selection area applies to. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// {@macro flutter.widgets.EditableText.contextMenuBuilder} + final SelectableRegionContextMenuBuilder? contextMenuBuilder; + + /// The delegate to build the selection handles and toolbar for mobile + /// devices. + /// + /// The [emptyTextSelectionControls] global variable provides a default + /// [TextSelectionControls] implementation with no controls. + final TextSelectionControls selectionControls; + + /// Called when the selected content changes. + final ValueChanged<SelectedContent?>? onSelectionChanged; + + /// Returns the [ContextMenuButtonItem]s representing the buttons in this + /// platform's default selection menu. + /// + /// For example, [SelectableRegion] uses this to generate the default buttons + /// for its context menu. + /// + /// See also: + /// + /// * [SelectableRegionState.contextMenuButtonItems], which gives the + /// [ContextMenuButtonItem]s for a specific SelectableRegion. + /// * [EditableText.getEditableButtonItems], which performs a similar role but + /// for content that is both selectable and editable. + /// * [AdaptiveTextSelectionToolbar], which builds the toolbar itself, and can + /// take a list of [ContextMenuButtonItem]s with + /// [AdaptiveTextSelectionToolbar.buttonItems]. + /// * [AdaptiveTextSelectionToolbar.getAdaptiveButtons], which builds the button + /// Widgets for the current platform given [ContextMenuButtonItem]s. + static List<ContextMenuButtonItem> getSelectableButtonItems({ + required final SelectionGeometry selectionGeometry, + required final VoidCallback onCopy, + required final VoidCallback onSelectAll, + }) { + final bool canCopy = selectionGeometry.status == SelectionStatus.uncollapsed; + final bool canSelectAll = selectionGeometry.hasContent; + + // Determine which buttons will appear so that the order and total number is + // known. A button's position in the menu can slightly affect its + // appearance. + return <ContextMenuButtonItem>[ + if (canCopy) + ContextMenuButtonItem( + onPressed: onCopy, + type: ContextMenuButtonType.copy, + ), + if (canSelectAll) + ContextMenuButtonItem( + onPressed: onSelectAll, + type: ContextMenuButtonType.selectAll, + ), + ]; + } + + @override + State<StatefulWidget> createState() => SelectableRegionState(); +} + +/// State for a [SelectableRegion]. +class SelectableRegionState extends State<SelectableRegion> with TextSelectionDelegate implements SelectionRegistrar { + late final Map<Type, Action<Intent>> _actions = <Type, Action<Intent>>{ + SelectAllTextIntent: _makeOverridable(_SelectAllAction(this)), + CopySelectionTextIntent: _makeOverridable(_CopySelectionAction(this)), + ExtendSelectionToNextWordBoundaryOrCaretLocationIntent: _makeOverridable(_GranularlyExtendSelectionAction<ExtendSelectionToNextWordBoundaryOrCaretLocationIntent>(this, granularity: TextGranularity.word)), + ExpandSelectionToDocumentBoundaryIntent: _makeOverridable(_GranularlyExtendSelectionAction<ExpandSelectionToDocumentBoundaryIntent>(this, granularity: TextGranularity.document)), + ExpandSelectionToLineBreakIntent: _makeOverridable(_GranularlyExtendSelectionAction<ExpandSelectionToLineBreakIntent>(this, granularity: TextGranularity.line)), + ExtendSelectionByCharacterIntent: _makeOverridable(_GranularlyExtendCaretSelectionAction<ExtendSelectionByCharacterIntent>(this, granularity: TextGranularity.character)), + ExtendSelectionToNextWordBoundaryIntent: _makeOverridable(_GranularlyExtendCaretSelectionAction<ExtendSelectionToNextWordBoundaryIntent>(this, granularity: TextGranularity.word)), + ExtendSelectionToLineBreakIntent: _makeOverridable(_GranularlyExtendCaretSelectionAction<ExtendSelectionToLineBreakIntent>(this, granularity: TextGranularity.line)), + ExtendSelectionVerticallyToAdjacentLineIntent: _makeOverridable(_DirectionallyExtendCaretSelectionAction<ExtendSelectionVerticallyToAdjacentLineIntent>(this)), + ExtendSelectionToDocumentBoundaryIntent: _makeOverridable(_GranularlyExtendCaretSelectionAction<ExtendSelectionToDocumentBoundaryIntent>(this, granularity: TextGranularity.document)), + }; + + final Map<Type, GestureRecognizerFactory> _gestureRecognizers = <Type, GestureRecognizerFactory>{}; + SelectionOverlay? _selectionOverlay; + final LayerLink _startHandleLayerLink = LayerLink(); + final LayerLink _endHandleLayerLink = LayerLink(); + final LayerLink _toolbarLayerLink = LayerLink(); + final _SelectableRegionContainerDelegate _selectionDelegate = _SelectableRegionContainerDelegate(); + // there should only ever be one selectable, which is the SelectionContainer. + Selectable? _selectable; + + bool get _hasSelectionOverlayGeometry => _selectionDelegate.value.startSelectionPoint != null + || _selectionDelegate.value.endSelectionPoint != null; + + Orientation? _lastOrientation; + SelectedContent? _lastSelectedContent; + + /// {@macro flutter.rendering.RenderEditable.lastSecondaryTapDownPosition} + Offset? lastSecondaryTapDownPosition; + + /// The [SelectionOverlay] that is currently visible on the screen. + /// + /// Can be null if there is no visible [SelectionOverlay]. + @visibleForTesting + SelectionOverlay? get selectionOverlay => _selectionOverlay; + + @override + void initState() { + super.initState(); + widget.focusNode.addListener(_handleFocusChanged); + _initMouseGestureRecognizer(); + _initTouchGestureRecognizer(); + // Taps and right clicks. + _gestureRecognizers[TapGestureRecognizer] = GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>( + () => TapGestureRecognizer(debugOwner: this), + (TapGestureRecognizer instance) { + instance.onTapUp = (TapUpDetails details) { + if (defaultTargetPlatform == TargetPlatform.iOS && _positionIsOnActiveSelection(globalPosition: details.globalPosition)) { + // On iOS when the tap occurs on the previous selection, instead of + // moving the selection, the context menu will be toggled. + final bool toolbarIsVisible = _selectionOverlay?.toolbarIsVisible ?? false; + if (toolbarIsVisible) { + hideToolbar(false); + } else { + _showToolbar(location: details.globalPosition); + } + } else { + hideToolbar(); + _collapseSelectionAt(offset: details.globalPosition); + } + }; + instance.onSecondaryTapDown = _handleRightClickDown; + }, + ); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + break; + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return; + } + + // Hide the text selection toolbar on mobile when orientation changes. + final Orientation orientation = MediaQuery.orientationOf(context); + if (_lastOrientation == null) { + _lastOrientation = orientation; + return; + } + if (orientation != _lastOrientation) { + _lastOrientation = orientation; + hideToolbar(defaultTargetPlatform == TargetPlatform.android); + } + } + + @override + void didUpdateWidget(SelectableRegion oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.focusNode != oldWidget.focusNode) { + oldWidget.focusNode.removeListener(_handleFocusChanged); + widget.focusNode.addListener(_handleFocusChanged); + if (widget.focusNode.hasFocus != oldWidget.focusNode.hasFocus) { + _handleFocusChanged(); + } + } + } + + Action<T> _makeOverridable<T extends Intent>(Action<T> defaultAction) { + return Action<T>.overridable(context: context, defaultAction: defaultAction); + } + + void _handleFocusChanged() { + if (!widget.focusNode.hasFocus) { + if (kIsWeb) { + PlatformSelectableRegionContextMenu.detach(_selectionDelegate); + } + _clearSelection(); + } + if (kIsWeb) { + PlatformSelectableRegionContextMenu.attach(_selectionDelegate); + } + } + + void _updateSelectionStatus() { + final TextSelection selection; + final SelectionGeometry geometry = _selectionDelegate.value; + switch (geometry.status) { + case SelectionStatus.uncollapsed: + case SelectionStatus.collapsed: + selection = const TextSelection(baseOffset: 0, extentOffset: 1); + case SelectionStatus.none: + selection = const TextSelection.collapsed(offset: 1); + } + textEditingValue = TextEditingValue(text: '__', selection: selection); + if (_hasSelectionOverlayGeometry) { + _updateSelectionOverlay(); + } else { + _selectionOverlay?.dispose(); + _selectionOverlay = null; + } + } + + // gestures. + + // Converts the details.consecutiveTapCount from a TapAndDrag*Details object, + // which can grow to be infinitely large, to a value between 1 and the supported + // max consecutive tap count. The value that the raw count is converted to is + // based on the default observed behavior on the native platforms. + // + // This method should be used in all instances when details.consecutiveTapCount + // would be used. + static int _getEffectiveConsecutiveTapCount(int rawCount) { + const int maxConsecutiveTap = 2; + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + // From observation, these platforms reset their tap count to 0 when + // the number of consecutive taps exceeds the max consecutive tap supported. + // For example on Debian Linux with GTK, when going past a triple click, + // on the fourth click the selection is moved to the precise click + // position, on the fifth click the word at the position is selected, and + // on the sixth click the paragraph at the position is selected. + return rawCount <= maxConsecutiveTap ? rawCount : (rawCount % maxConsecutiveTap == 0 ? maxConsecutiveTap : rawCount % maxConsecutiveTap); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + case TargetPlatform.windows: + // From observation, these platforms either hold their tap count at the max + // consecutive tap supported. For example on macOS, when going past a triple + // click, the selection should be retained at the paragraph that was first + // selected on triple click. + return min(rawCount, maxConsecutiveTap); + } + } + + void _initMouseGestureRecognizer() { + _gestureRecognizers[TapAndPanGestureRecognizer] = GestureRecognizerFactoryWithHandlers<TapAndPanGestureRecognizer>( + () => TapAndPanGestureRecognizer(debugOwner:this, supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.mouse }), + (TapAndPanGestureRecognizer instance) { + instance + ..onTapDown = _startNewMouseSelectionGesture + ..onTapUp = _handleMouseTapUp + ..onDragStart = _handleMouseDragStart + ..onDragUpdate = _handleMouseDragUpdate + ..onDragEnd = _handleMouseDragEnd + ..onCancel = _clearSelection + ..dragStartBehavior = DragStartBehavior.down; + }, + ); + } + + void _initTouchGestureRecognizer() { + _gestureRecognizers[LongPressGestureRecognizer] = GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>( + () => LongPressGestureRecognizer(debugOwner: this, supportedDevices: _kLongPressSelectionDevices), + (LongPressGestureRecognizer instance) { + instance + ..onLongPressStart = _handleTouchLongPressStart + ..onLongPressMoveUpdate = _handleTouchLongPressMoveUpdate + ..onLongPressEnd = _handleTouchLongPressEnd; + }, + ); + } + + void _startNewMouseSelectionGesture(TapDragDownDetails details) { + switch (_getEffectiveConsecutiveTapCount(details.consecutiveTapCount)) { + case 1: + widget.focusNode.requestFocus(); + hideToolbar(); + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + // On mobile platforms the selection is set on tap up. + break; + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + _collapseSelectionAt(offset: details.globalPosition); + } + case 2: + _selectWordAt(offset: details.globalPosition); + } + _updateSelectedContentIfNeeded(); + } + + void _handleMouseDragStart(TapDragStartDetails details) { + switch (_getEffectiveConsecutiveTapCount(details.consecutiveTapCount)) { + case 1: + _selectStartTo(offset: details.globalPosition); + } + _updateSelectedContentIfNeeded(); + } + + void _handleMouseDragUpdate(TapDragUpdateDetails details) { + switch (_getEffectiveConsecutiveTapCount(details.consecutiveTapCount)) { + case 1: + _selectEndTo(offset: details.globalPosition, continuous: true); + case 2: + _selectEndTo(offset: details.globalPosition, continuous: true, textGranularity: TextGranularity.word); + } + _updateSelectedContentIfNeeded(); + } + + void _handleMouseDragEnd(TapDragEndDetails details) { + _finalizeSelection(); + _updateSelectedContentIfNeeded(); + } + + void _handleMouseTapUp(TapDragUpDetails details) { + switch (_getEffectiveConsecutiveTapCount(details.consecutiveTapCount)) { + case 1: + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + _collapseSelectionAt(offset: details.globalPosition); + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + // On desktop platforms the selection is set on tap down. + break; + } + } + _updateSelectedContentIfNeeded(); + } + + void _updateSelectedContentIfNeeded() { + if (_lastSelectedContent?.plainText != _selectable?.getSelectedContent()?.plainText) { + _lastSelectedContent = _selectable?.getSelectedContent(); + widget.onSelectionChanged?.call(_lastSelectedContent); + } + } + + void _handleTouchLongPressStart(LongPressStartDetails details) { + HapticFeedback.selectionClick(); + widget.focusNode.requestFocus(); + _selectWordAt(offset: details.globalPosition); + // Platforms besides Android will show the text selection handles when + // the long press is initiated. Android shows the text selection handles when + // the long press has ended, usually after a pointer up event is received. + if (defaultTargetPlatform != TargetPlatform.android) { + _showHandles(); + } + _updateSelectedContentIfNeeded(); + } + + void _handleTouchLongPressMoveUpdate(LongPressMoveUpdateDetails details) { + _selectEndTo(offset: details.globalPosition, textGranularity: TextGranularity.word); + _updateSelectedContentIfNeeded(); + } + + void _handleTouchLongPressEnd(LongPressEndDetails details) { + _finalizeSelection(); + _updateSelectedContentIfNeeded(); + _showToolbar(); + if (defaultTargetPlatform == TargetPlatform.android) { + _showHandles(); + } + } + + bool _positionIsOnActiveSelection({required Offset globalPosition}) { + for (final Rect selectionRect in _selectionDelegate.value.selectionRects) { + final Matrix4 transform = _selectable!.getTransformTo(null); + final Rect globalRect = MatrixUtils.transformRect(transform, selectionRect); + if (globalRect.contains(globalPosition)) { + return true; + } + } + return false; + } + + void _handleRightClickDown(TapDownDetails details) { + final Offset? previousSecondaryTapDownPosition = lastSecondaryTapDownPosition; + final bool toolbarIsVisible = _selectionOverlay?.toolbarIsVisible ?? false; + lastSecondaryTapDownPosition = details.globalPosition; + widget.focusNode.requestFocus(); + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.windows: + // If lastSecondaryTapDownPosition is within the current selection then + // keep the current selection, if not then collapse it. + final bool lastSecondaryTapDownPositionWasOnActiveSelection = _positionIsOnActiveSelection(globalPosition: details.globalPosition); + if (!lastSecondaryTapDownPositionWasOnActiveSelection) { + _collapseSelectionAt(offset: lastSecondaryTapDownPosition!); + } + _showHandles(); + _showToolbar(location: lastSecondaryTapDownPosition); + case TargetPlatform.iOS: + _selectWordAt(offset: lastSecondaryTapDownPosition!); + _showHandles(); + _showToolbar(location: lastSecondaryTapDownPosition); + case TargetPlatform.macOS: + if (previousSecondaryTapDownPosition == lastSecondaryTapDownPosition && toolbarIsVisible) { + hideToolbar(); + return; + } + _selectWordAt(offset: lastSecondaryTapDownPosition!); + _showHandles(); + _showToolbar(location: lastSecondaryTapDownPosition); + case TargetPlatform.linux: + if (toolbarIsVisible) { + hideToolbar(); + return; + } + // If lastSecondaryTapDownPosition is within the current selection then + // keep the current selection, if not then collapse it. + final bool lastSecondaryTapDownPositionWasOnActiveSelection = _positionIsOnActiveSelection(globalPosition: details.globalPosition); + if (!lastSecondaryTapDownPositionWasOnActiveSelection) { + _collapseSelectionAt(offset: lastSecondaryTapDownPosition!); + } + _showHandles(); + _showToolbar(location: lastSecondaryTapDownPosition); + } + _updateSelectedContentIfNeeded(); + } + + // Selection update helper methods. + + Offset? _selectionEndPosition; + bool get _userDraggingSelectionEnd => _selectionEndPosition != null; + bool _scheduledSelectionEndEdgeUpdate = false; + + /// Sends end [SelectionEdgeUpdateEvent] to the selectable subtree. + /// + /// If the selectable subtree returns a [SelectionResult.pending], this method + /// continues to send [SelectionEdgeUpdateEvent]s every frame until the result + /// is not pending or users end their gestures. + void _triggerSelectionEndEdgeUpdate({TextGranularity? textGranularity}) { + // This method can be called when the drag is not in progress. This can + // happen if the child scrollable returns SelectionResult.pending, and + // the selection area scheduled a selection update for the next frame, but + // the drag is lifted before the scheduled selection update is run. + if (_scheduledSelectionEndEdgeUpdate || !_userDraggingSelectionEnd) { + return; + } + if (_selectable?.dispatchSelectionEvent( + SelectionEdgeUpdateEvent.forEnd(globalPosition: _selectionEndPosition!, granularity: textGranularity)) == SelectionResult.pending) { + _scheduledSelectionEndEdgeUpdate = true; + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + if (!_scheduledSelectionEndEdgeUpdate) { + return; + } + _scheduledSelectionEndEdgeUpdate = false; + _triggerSelectionEndEdgeUpdate(textGranularity: textGranularity); + }, debugLabel: 'SelectableRegion.endEdgeUpdate'); + return; + } + } + + void _onAnyDragEnd(DragEndDetails details) { + if (widget.selectionControls is! TextSelectionHandleControls) { + _selectionOverlay!.hideMagnifier(); + _selectionOverlay!.showToolbar(); + } else { + _selectionOverlay!.hideMagnifier(); + _selectionOverlay!.showToolbar( + context: context, + contextMenuBuilder: (BuildContext context) { + return widget.contextMenuBuilder!(context, this); + }, + ); + } + _stopSelectionStartEdgeUpdate(); + _stopSelectionEndEdgeUpdate(); + _updateSelectedContentIfNeeded(); + } + + void _stopSelectionEndEdgeUpdate() { + _scheduledSelectionEndEdgeUpdate = false; + _selectionEndPosition = null; + } + + Offset? _selectionStartPosition; + bool get _userDraggingSelectionStart => _selectionStartPosition != null; + bool _scheduledSelectionStartEdgeUpdate = false; + + /// Sends start [SelectionEdgeUpdateEvent] to the selectable subtree. + /// + /// If the selectable subtree returns a [SelectionResult.pending], this method + /// continues to send [SelectionEdgeUpdateEvent]s every frame until the result + /// is not pending or users end their gestures. + void _triggerSelectionStartEdgeUpdate({TextGranularity? textGranularity}) { + // This method can be called when the drag is not in progress. This can + // happen if the child scrollable returns SelectionResult.pending, and + // the selection area scheduled a selection update for the next frame, but + // the drag is lifted before the scheduled selection update is run. + if (_scheduledSelectionStartEdgeUpdate || !_userDraggingSelectionStart) { + return; + } + if (_selectable?.dispatchSelectionEvent( + SelectionEdgeUpdateEvent.forStart(globalPosition: _selectionStartPosition!, granularity: textGranularity)) == SelectionResult.pending) { + _scheduledSelectionStartEdgeUpdate = true; + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + if (!_scheduledSelectionStartEdgeUpdate) { + return; + } + _scheduledSelectionStartEdgeUpdate = false; + _triggerSelectionStartEdgeUpdate(textGranularity: textGranularity); + }, debugLabel: 'SelectableRegion.startEdgeUpdate'); + return; + } + } + + void _stopSelectionStartEdgeUpdate() { + _scheduledSelectionStartEdgeUpdate = false; + _selectionEndPosition = null; + } + + // SelectionOverlay helper methods. + + late Offset _selectionStartHandleDragPosition; + late Offset _selectionEndHandleDragPosition; + + void _handleSelectionStartHandleDragStart(DragStartDetails details) { + assert(_selectionDelegate.value.startSelectionPoint != null); + + final Offset localPosition = _selectionDelegate.value.startSelectionPoint!.localPosition; + final Matrix4 globalTransform = _selectable!.getTransformTo(null); + _selectionStartHandleDragPosition = MatrixUtils.transformPoint(globalTransform, localPosition); + + _selectionOverlay!.showMagnifier(_buildInfoForMagnifier( + details.globalPosition, + _selectionDelegate.value.startSelectionPoint!, + )); + _updateSelectedContentIfNeeded(); + } + + void _handleSelectionStartHandleDragUpdate(DragUpdateDetails details) { + _selectionStartHandleDragPosition = _selectionStartHandleDragPosition + details.delta; + // The value corresponds to the paint origin of the selection handle. + // Offset it to the center of the line to make it feel more natural. + _selectionStartPosition = _selectionStartHandleDragPosition - Offset(0, _selectionDelegate.value.startSelectionPoint!.lineHeight / 2); + _triggerSelectionStartEdgeUpdate(); + + _selectionOverlay!.updateMagnifier(_buildInfoForMagnifier( + details.globalPosition, + _selectionDelegate.value.startSelectionPoint!, + )); + _updateSelectedContentIfNeeded(); + } + + void _handleSelectionEndHandleDragStart(DragStartDetails details) { + assert(_selectionDelegate.value.endSelectionPoint != null); + final Offset localPosition = _selectionDelegate.value.endSelectionPoint!.localPosition; + final Matrix4 globalTransform = _selectable!.getTransformTo(null); + _selectionEndHandleDragPosition = MatrixUtils.transformPoint(globalTransform, localPosition); + + _selectionOverlay!.showMagnifier(_buildInfoForMagnifier( + details.globalPosition, + _selectionDelegate.value.endSelectionPoint!, + )); + _updateSelectedContentIfNeeded(); + } + + void _handleSelectionEndHandleDragUpdate(DragUpdateDetails details) { + _selectionEndHandleDragPosition = _selectionEndHandleDragPosition + details.delta; + // The value corresponds to the paint origin of the selection handle. + // Offset it to the center of the line to make it feel more natural. + _selectionEndPosition = _selectionEndHandleDragPosition - Offset(0, _selectionDelegate.value.endSelectionPoint!.lineHeight / 2); + _triggerSelectionEndEdgeUpdate(); + + _selectionOverlay!.updateMagnifier(_buildInfoForMagnifier( + details.globalPosition, + _selectionDelegate.value.endSelectionPoint!, + )); + _updateSelectedContentIfNeeded(); + } + + MagnifierInfo _buildInfoForMagnifier(Offset globalGesturePosition, SelectionPoint selectionPoint) { + final Vector3 globalTransform = _selectable!.getTransformTo(null).getTranslation(); + final Offset globalTransformAsOffset = Offset(globalTransform.x, globalTransform.y); + final Offset globalSelectionPointPosition = selectionPoint.localPosition + globalTransformAsOffset; + final Rect caretRect = Rect.fromLTWH( + globalSelectionPointPosition.dx, + globalSelectionPointPosition.dy - selectionPoint.lineHeight, + 0, + selectionPoint.lineHeight + ); + + return MagnifierInfo( + globalGesturePosition: globalGesturePosition, + caretRect: caretRect, + fieldBounds: globalTransformAsOffset & _selectable!.size, + currentLineBoundaries: globalTransformAsOffset & _selectable!.size, + ); + } + + void _createSelectionOverlay() { + assert(_hasSelectionOverlayGeometry); + if (_selectionOverlay != null) { + return; + } + final SelectionPoint? start = _selectionDelegate.value.startSelectionPoint; + final SelectionPoint? end = _selectionDelegate.value.endSelectionPoint; + _selectionOverlay = SelectionOverlay( + context: context, + debugRequiredFor: widget, + startHandleType: start?.handleType ?? TextSelectionHandleType.left, + lineHeightAtStart: start?.lineHeight ?? end!.lineHeight, + onStartHandleDragStart: _handleSelectionStartHandleDragStart, + onStartHandleDragUpdate: _handleSelectionStartHandleDragUpdate, + onStartHandleDragEnd: _onAnyDragEnd, + endHandleType: end?.handleType ?? TextSelectionHandleType.right, + lineHeightAtEnd: end?.lineHeight ?? start!.lineHeight, + onEndHandleDragStart: _handleSelectionEndHandleDragStart, + onEndHandleDragUpdate: _handleSelectionEndHandleDragUpdate, + onEndHandleDragEnd: _onAnyDragEnd, + selectionEndpoints: selectionEndpoints, + selectionControls: widget.selectionControls, + selectionDelegate: this, + clipboardStatus: null, + startHandleLayerLink: _startHandleLayerLink, + endHandleLayerLink: _endHandleLayerLink, + toolbarLayerLink: _toolbarLayerLink, + magnifierConfiguration: widget.magnifierConfiguration + ); + } + + void _updateSelectionOverlay() { + if (_selectionOverlay == null) { + return; + } + assert(_hasSelectionOverlayGeometry); + final SelectionPoint? start = _selectionDelegate.value.startSelectionPoint; + final SelectionPoint? end = _selectionDelegate.value.endSelectionPoint; + _selectionOverlay! + ..startHandleType = start?.handleType ?? TextSelectionHandleType.left + ..lineHeightAtStart = start?.lineHeight ?? end!.lineHeight + ..endHandleType = end?.handleType ?? TextSelectionHandleType.right + ..lineHeightAtEnd = end?.lineHeight ?? start!.lineHeight + ..selectionEndpoints = selectionEndpoints; + } + + /// Shows the selection handles. + /// + /// Returns true if the handles are shown, false if the handles can't be + /// shown. + bool _showHandles() { + if (_selectionOverlay != null) { + _selectionOverlay!.showHandles(); + return true; + } + + if (!_hasSelectionOverlayGeometry) { + return false; + } + + _createSelectionOverlay(); + _selectionOverlay!.showHandles(); + return true; + } + + /// Shows the text selection toolbar. + /// + /// If the parameter `location` is set, the toolbar will be shown at the + /// location. Otherwise, the toolbar location will be calculated based on the + /// handles' locations. The `location` is in the coordinates system of the + /// [Overlay]. + /// + /// Returns true if the toolbar is shown, false if the toolbar can't be shown. + bool _showToolbar({Offset? location}) { + if (!_hasSelectionOverlayGeometry && _selectionOverlay == null) { + return false; + } + + // Web is using native dom elements to enable clipboard functionality of the + // context menu: copy, paste, select, cut. It might also provide additional + // functionality depending on the browser (such as translate). Due to this, + // we should not show a Flutter toolbar for the editable text elements + // unless the browser's context menu is explicitly disabled. + if (kIsWeb && BrowserContextMenu.enabled) { + return false; + } + + if (_selectionOverlay == null) { + _createSelectionOverlay(); + } + + _selectionOverlay!.toolbarLocation = location; + if (widget.selectionControls is! TextSelectionHandleControls) { + _selectionOverlay!.showToolbar(); + return true; + } + + _selectionOverlay!.hideToolbar(); + + _selectionOverlay!.showToolbar( + context: context, + contextMenuBuilder: (BuildContext context) { + return widget.contextMenuBuilder!(context, this); + }, + ); + return true; + } + + /// Sets or updates selection end edge to the `offset` location. + /// + /// A selection always contains a select start edge and selection end edge. + /// They can be created by calling both [_selectStartTo] and [_selectEndTo], or + /// use other selection APIs, such as [_selectWordAt] or [selectAll]. + /// + /// This method sets or updates the selection end edge by sending + /// [SelectionEdgeUpdateEvent]s to the child [Selectable]s. + /// + /// If `continuous` is set to true and the update causes scrolling, the + /// method will continue sending the same [SelectionEdgeUpdateEvent]s to the + /// child [Selectable]s every frame until the scrolling finishes or a + /// [_finalizeSelection] is called. + /// + /// The `continuous` argument defaults to false. + /// + /// The `offset` is in global coordinates. + /// + /// Provide the `textGranularity` if the selection should not move by the default + /// [TextGranularity.character]. Only [TextGranularity.character] and + /// [TextGranularity.word] are currently supported. + /// + /// See also: + /// * [_selectStartTo], which sets or updates selection start edge. + /// * [_finalizeSelection], which stops the `continuous` updates. + /// * [_clearSelection], which clears the ongoing selection. + /// * [_selectWordAt], which selects a whole word at the location. + /// * [_collapseSelectionAt], which collapses the selection at the location. + /// * [selectAll], which selects the entire content. + void _selectEndTo({required Offset offset, bool continuous = false, TextGranularity? textGranularity}) { + if (!continuous) { + _selectable?.dispatchSelectionEvent(SelectionEdgeUpdateEvent.forEnd(globalPosition: offset, granularity: textGranularity)); + return; + } + if (_selectionEndPosition != offset) { + _selectionEndPosition = offset; + _triggerSelectionEndEdgeUpdate(textGranularity: textGranularity); + } + } + + /// Sets or updates selection start edge to the `offset` location. + /// + /// A selection always contains a select start edge and selection end edge. + /// They can be created by calling both [_selectStartTo] and [_selectEndTo], or + /// use other selection APIs, such as [_selectWordAt] or [selectAll]. + /// + /// This method sets or updates the selection start edge by sending + /// [SelectionEdgeUpdateEvent]s to the child [Selectable]s. + /// + /// If `continuous` is set to true and the update causes scrolling, the + /// method will continue sending the same [SelectionEdgeUpdateEvent]s to the + /// child [Selectable]s every frame until the scrolling finishes or a + /// [_finalizeSelection] is called. + /// + /// The `continuous` argument defaults to false. + /// + /// The `offset` is in global coordinates. + /// + /// Provide the `textGranularity` if the selection should not move by the default + /// [TextGranularity.character]. Only [TextGranularity.character] and + /// [TextGranularity.word] are currently supported. + /// + /// See also: + /// * [_selectEndTo], which sets or updates selection end edge. + /// * [_finalizeSelection], which stops the `continuous` updates. + /// * [_clearSelection], which clears the ongoing selection. + /// * [_selectWordAt], which selects a whole word at the location. + /// * [_collapseSelectionAt], which collapses the selection at the location. + /// * [selectAll], which selects the entire content. + void _selectStartTo({required Offset offset, bool continuous = false, TextGranularity? textGranularity}) { + if (!continuous) { + _selectable?.dispatchSelectionEvent(SelectionEdgeUpdateEvent.forStart(globalPosition: offset, granularity: textGranularity)); + return; + } + if (_selectionStartPosition != offset) { + _selectionStartPosition = offset; + _triggerSelectionStartEdgeUpdate(textGranularity: textGranularity); + } + } + + /// Collapses the selection at the given `offset` location. + /// + /// See also: + /// * [_selectStartTo], which sets or updates selection start edge. + /// * [_selectEndTo], which sets or updates selection end edge. + /// * [_finalizeSelection], which stops the `continuous` updates. + /// * [_clearSelection], which clears the ongoing selection. + /// * [_selectWordAt], which selects a whole word at the location. + /// * [selectAll], which selects the entire content. + void _collapseSelectionAt({required Offset offset}) { + _selectStartTo(offset: offset); + _selectEndTo(offset: offset); + } + + /// Selects a whole word at the `offset` location. + /// + /// If the whole word is already in the current selection, selection won't + /// change. One call [_clearSelection] first if the selection needs to be + /// updated even if the word is already covered by the current selection. + /// + /// One can also use [_selectEndTo] or [_selectStartTo] to adjust the selection + /// edges after calling this method. + /// + /// See also: + /// * [_selectStartTo], which sets or updates selection start edge. + /// * [_selectEndTo], which sets or updates selection end edge. + /// * [_finalizeSelection], which stops the `continuous` updates. + /// * [_clearSelection], which clears the ongoing selection. + /// * [_collapseSelectionAt], which collapses the selection at the location. + /// * [selectAll], which selects the entire content. + void _selectWordAt({required Offset offset}) { + // There may be other selection ongoing. + _finalizeSelection(); + _selectable?.dispatchSelectionEvent(SelectWordSelectionEvent(globalPosition: offset)); + } + + /// Stops any ongoing selection updates. + /// + /// This method is different from [_clearSelection] that it does not remove + /// the current selection. It only stops the continuous updates. + /// + /// A continuous update can happen as result of calling [_selectStartTo] or + /// [_selectEndTo] with `continuous` sets to true which causes a [Selectable] + /// to scroll. Calling this method will stop the update as well as the + /// scrolling. + void _finalizeSelection() { + _stopSelectionEndEdgeUpdate(); + _stopSelectionStartEdgeUpdate(); + } + + /// Removes the ongoing selection. + void _clearSelection() { + _finalizeSelection(); + _directionalHorizontalBaseline = null; + _adjustingSelectionEnd = null; + _selectable?.dispatchSelectionEvent(const ClearSelectionEvent()); + _updateSelectedContentIfNeeded(); + } + + Future<void> _copy() async { + final SelectedContent? data = _selectable?.getSelectedContent(); + if (data == null) { + return; + } + await Clipboard.setData(ClipboardData(text: data.plainText)); + } + + /// {@macro flutter.widgets.EditableText.getAnchors} + /// + /// See also: + /// + /// * [contextMenuButtonItems], which provides the [ContextMenuButtonItem]s + /// for the default context menu buttons. + TextSelectionToolbarAnchors get contextMenuAnchors { + if (lastSecondaryTapDownPosition != null) { + return TextSelectionToolbarAnchors( + primaryAnchor: lastSecondaryTapDownPosition!, + ); + } + final RenderBox renderBox = context.findRenderObject()! as RenderBox; + return TextSelectionToolbarAnchors.fromSelection( + renderBox: renderBox, + startGlyphHeight: startGlyphHeight, + endGlyphHeight: endGlyphHeight, + selectionEndpoints: selectionEndpoints, + ); + } + + bool? _adjustingSelectionEnd; + bool _determineIsAdjustingSelectionEnd(bool forward) { + if (_adjustingSelectionEnd != null) { + return _adjustingSelectionEnd!; + } + final bool isReversed; + final SelectionPoint start = _selectionDelegate.value + .startSelectionPoint!; + final SelectionPoint end = _selectionDelegate.value.endSelectionPoint!; + if (start.localPosition.dy > end.localPosition.dy) { + isReversed = true; + } else if (start.localPosition.dy < end.localPosition.dy) { + isReversed = false; + } else { + isReversed = start.localPosition.dx > end.localPosition.dx; + } + // Always move the selection edge that increases the selection range. + return _adjustingSelectionEnd = forward != isReversed; + } + + void _granularlyExtendSelection(TextGranularity granularity, bool forward) { + _directionalHorizontalBaseline = null; + if (!_selectionDelegate.value.hasSelection) { + return; + } + _selectable?.dispatchSelectionEvent( + GranularlyExtendSelectionEvent( + forward: forward, + isEnd: _determineIsAdjustingSelectionEnd(forward), + granularity: granularity, + ), + ); + _updateSelectedContentIfNeeded(); + } + + double? _directionalHorizontalBaseline; + + void _directionallyExtendSelection(bool forward) { + if (!_selectionDelegate.value.hasSelection) { + return; + } + final bool adjustingSelectionExtend = _determineIsAdjustingSelectionEnd(forward); + final SelectionPoint baseLinePoint = adjustingSelectionExtend + ? _selectionDelegate.value.endSelectionPoint! + : _selectionDelegate.value.startSelectionPoint!; + _directionalHorizontalBaseline ??= baseLinePoint.localPosition.dx; + final Offset globalSelectionPointOffset = MatrixUtils.transformPoint(context.findRenderObject()!.getTransformTo(null), Offset(_directionalHorizontalBaseline!, 0)); + _selectable?.dispatchSelectionEvent( + DirectionallyExtendSelectionEvent( + isEnd: _adjustingSelectionEnd!, + direction: forward ? SelectionExtendDirection.nextLine : SelectionExtendDirection.previousLine, + dx: globalSelectionPointOffset.dx, + ), + ); + _updateSelectedContentIfNeeded(); + } + + // [TextSelectionDelegate] overrides. + + /// Returns the [ContextMenuButtonItem]s representing the buttons in this + /// platform's default selection menu. + /// + /// See also: + /// + /// * [SelectableRegion.getSelectableButtonItems], which performs a similar role, + /// but for any selectable text, not just specifically SelectableRegion. + /// * [EditableTextState.contextMenuButtonItems], which performs a similar role + /// but for content that is not just selectable but also editable. + /// * [contextMenuAnchors], which provides the anchor points for the default + /// context menu. + /// * [AdaptiveTextSelectionToolbar], which builds the toolbar itself, and can + /// take a list of [ContextMenuButtonItem]s with + /// [AdaptiveTextSelectionToolbar.buttonItems]. + /// * [AdaptiveTextSelectionToolbar.getAdaptiveButtons], which builds the + /// button Widgets for the current platform given [ContextMenuButtonItem]s. + List<ContextMenuButtonItem> get contextMenuButtonItems { + return SelectableRegion.getSelectableButtonItems( + selectionGeometry: _selectionDelegate.value, + onCopy: () { + _copy(); + + // In Android copy should clear the selection. + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + _clearSelection(); + case TargetPlatform.iOS: + hideToolbar(false); + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + hideToolbar(); + } + }, + onSelectAll: () { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + case TargetPlatform.fuchsia: + selectAll(SelectionChangedCause.toolbar); + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + selectAll(); + hideToolbar(); + } + }, + ); + } + + /// The line height at the start of the current selection. + double get startGlyphHeight { + return _selectionDelegate.value.startSelectionPoint!.lineHeight; + } + + /// The line height at the end of the current selection. + double get endGlyphHeight { + return _selectionDelegate.value.endSelectionPoint!.lineHeight; + } + + /// Returns the local coordinates of the endpoints of the current selection. + List<TextSelectionPoint> get selectionEndpoints { + final SelectionPoint? start = _selectionDelegate.value.startSelectionPoint; + final SelectionPoint? end = _selectionDelegate.value.endSelectionPoint; + late List<TextSelectionPoint> points; + final Offset startLocalPosition = start?.localPosition ?? end!.localPosition; + final Offset endLocalPosition = end?.localPosition ?? start!.localPosition; + if (startLocalPosition.dy > endLocalPosition.dy) { + points = <TextSelectionPoint>[ + TextSelectionPoint(endLocalPosition, TextDirection.ltr), + TextSelectionPoint(startLocalPosition, TextDirection.ltr), + ]; + } else { + points = <TextSelectionPoint>[ + TextSelectionPoint(startLocalPosition, TextDirection.ltr), + TextSelectionPoint(endLocalPosition, TextDirection.ltr), + ]; + } + return points; + } + + // [TextSelectionDelegate] overrides. + // TODO(justinmc): After deprecations have been removed, remove + // TextSelectionDelegate from this class. + // https://github.com/flutter/flutter/issues/111213 + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + bool get cutEnabled => false; + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + bool get pasteEnabled => false; + + @override + void hideToolbar([bool hideHandles = true]) { + _selectionOverlay?.hideToolbar(); + if (hideHandles) { + _selectionOverlay?.hideHandles(); + } + } + + @override + void selectAll([SelectionChangedCause? cause]) { + _clearSelection(); + _selectable?.dispatchSelectionEvent(const SelectAllSelectionEvent()); + if (cause == SelectionChangedCause.toolbar) { + _showToolbar(); + _showHandles(); + } + _updateSelectedContentIfNeeded(); + } + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + void copySelection(SelectionChangedCause cause) { + _copy(); + _clearSelection(); + } + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + TextEditingValue textEditingValue = const TextEditingValue(text: '_'); + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + void bringIntoView(TextPosition position) {/* SelectableRegion must be in view at this point. */} + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + void cutSelection(SelectionChangedCause cause) { + assert(false); + } + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + void userUpdateTextEditingValue(TextEditingValue value, SelectionChangedCause cause) {/* SelectableRegion maintains its own state */} + + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + @override + Future<void> pasteText(SelectionChangedCause cause) async { + assert(false); + } + + // [SelectionRegistrar] override. + + @override + void add(Selectable selectable) { + assert(_selectable == null); + _selectable = selectable; + _selectable!.addListener(_updateSelectionStatus); + _selectable!.pushHandleLayers(_startHandleLayerLink, _endHandleLayerLink); + } + + @override + void remove(Selectable selectable) { + assert(_selectable == selectable); + _selectable!.removeListener(_updateSelectionStatus); + _selectable!.pushHandleLayers(null, null); + _selectable = null; + } + + @override + void dispose() { + _selectable?.removeListener(_updateSelectionStatus); + _selectable?.pushHandleLayers(null, null); + _selectionDelegate.dispose(); + // In case dispose was triggered before gesture end, remove the magnifier + // so it doesn't remain stuck in the overlay forever. + _selectionOverlay?.hideMagnifier(); + _selectionOverlay?.dispose(); + _selectionOverlay = null; + super.dispose(); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasOverlay(context)); + Widget result = SelectionContainer( + registrar: this, + delegate: _selectionDelegate, + child: widget.child, + ); + if (kIsWeb) { + result = PlatformSelectableRegionContextMenu( + child: result, + ); + } + return CompositedTransformTarget( + link: _toolbarLayerLink, + child: RawGestureDetector( + gestures: _gestureRecognizers, + behavior: HitTestBehavior.translucent, + excludeFromSemantics: true, + child: Actions( + actions: _actions, + child: Focus( + includeSemantics: false, + focusNode: widget.focusNode, + child: result, + ), + ), + ), + ); + } +} + +/// An action that does not override any [Action.overridable] in the subtree. +/// +/// If this action is invoked by an [Action.overridable], it will immediately +/// invoke the [Action.overridable] and do nothing else. Otherwise, it will call +/// [invokeAction]. +abstract class _NonOverrideAction<T extends Intent> extends ContextAction<T> { + Object? invokeAction(T intent, [BuildContext? context]); + + @override + Object? invoke(T intent, [BuildContext? context]) { + if (callingAction != null) { + return callingAction!.invoke(intent); + } + return invokeAction(intent, context); + } +} + +class _SelectAllAction extends _NonOverrideAction<SelectAllTextIntent> { + _SelectAllAction(this.state); + + final SelectableRegionState state; + + @override + void invokeAction(SelectAllTextIntent intent, [BuildContext? context]) { + state.selectAll(SelectionChangedCause.keyboard); + } +} + +class _CopySelectionAction extends _NonOverrideAction<CopySelectionTextIntent> { + _CopySelectionAction(this.state); + + final SelectableRegionState state; + + @override + void invokeAction(CopySelectionTextIntent intent, [BuildContext? context]) { + state._copy(); + } +} + +class _GranularlyExtendSelectionAction<T extends DirectionalTextEditingIntent> extends _NonOverrideAction<T> { + _GranularlyExtendSelectionAction(this.state, {required this.granularity}); + + final SelectableRegionState state; + final TextGranularity granularity; + + @override + void invokeAction(T intent, [BuildContext? context]) { + state._granularlyExtendSelection(granularity, intent.forward); + } +} + +class _GranularlyExtendCaretSelectionAction<T extends DirectionalCaretMovementIntent> extends _NonOverrideAction<T> { + _GranularlyExtendCaretSelectionAction(this.state, {required this.granularity}); + + final SelectableRegionState state; + final TextGranularity granularity; + + @override + void invokeAction(T intent, [BuildContext? context]) { + if (intent.collapseSelection) { + // Selectable region never collapses selection. + return; + } + state._granularlyExtendSelection(granularity, intent.forward); + } +} + +class _DirectionallyExtendCaretSelectionAction<T extends DirectionalCaretMovementIntent> extends _NonOverrideAction<T> { + _DirectionallyExtendCaretSelectionAction(this.state); + + final SelectableRegionState state; + + @override + void invokeAction(T intent, [BuildContext? context]) { + if (intent.collapseSelection) { + // Selectable region never collapses selection. + return; + } + state._directionallyExtendSelection(intent.forward); + } +} + +class _SelectableRegionContainerDelegate extends MultiSelectableSelectionContainerDelegate { + final Set<Selectable> _hasReceivedStartEvent = <Selectable>{}; + final Set<Selectable> _hasReceivedEndEvent = <Selectable>{}; + + Offset? _lastStartEdgeUpdateGlobalPosition; + Offset? _lastEndEdgeUpdateGlobalPosition; + + @override + void remove(Selectable selectable) { + _hasReceivedStartEvent.remove(selectable); + _hasReceivedEndEvent.remove(selectable); + super.remove(selectable); + } + + void _updateLastEdgeEventsFromGeometries() { + if (currentSelectionStartIndex != -1 && selectables[currentSelectionStartIndex].value.hasSelection) { + final Selectable start = selectables[currentSelectionStartIndex]; + final Offset localStartEdge = start.value.startSelectionPoint!.localPosition + + Offset(0, - start.value.startSelectionPoint!.lineHeight / 2); + _lastStartEdgeUpdateGlobalPosition = MatrixUtils.transformPoint(start.getTransformTo(null), localStartEdge); + } + if (currentSelectionEndIndex != -1 && selectables[currentSelectionEndIndex].value.hasSelection) { + final Selectable end = selectables[currentSelectionEndIndex]; + final Offset localEndEdge = end.value.endSelectionPoint!.localPosition + + Offset(0, -end.value.endSelectionPoint!.lineHeight / 2); + _lastEndEdgeUpdateGlobalPosition = MatrixUtils.transformPoint(end.getTransformTo(null), localEndEdge); + } + } + + @override + SelectionResult handleSelectAll(SelectAllSelectionEvent event) { + final SelectionResult result = super.handleSelectAll(event); + for (final Selectable selectable in selectables) { + _hasReceivedStartEvent.add(selectable); + _hasReceivedEndEvent.add(selectable); + } + // Synthesize last update event so the edge updates continue to work. + _updateLastEdgeEventsFromGeometries(); + return result; + } + + /// Selects a word in a selectable at the location + /// [SelectWordSelectionEvent.globalPosition]. + @override + SelectionResult handleSelectWord(SelectWordSelectionEvent event) { + final SelectionResult result = super.handleSelectWord(event); + if (currentSelectionStartIndex != -1) { + _hasReceivedStartEvent.add(selectables[currentSelectionStartIndex]); + } + if (currentSelectionEndIndex != -1) { + _hasReceivedEndEvent.add(selectables[currentSelectionEndIndex]); + } + _updateLastEdgeEventsFromGeometries(); + return result; + } + + @override + SelectionResult handleClearSelection(ClearSelectionEvent event) { + final SelectionResult result = super.handleClearSelection(event); + _hasReceivedStartEvent.clear(); + _hasReceivedEndEvent.clear(); + _lastStartEdgeUpdateGlobalPosition = null; + _lastEndEdgeUpdateGlobalPosition = null; + return result; + } + + @override + SelectionResult handleSelectionEdgeUpdate(SelectionEdgeUpdateEvent event) { + if (event.type == SelectionEventType.endEdgeUpdate) { + _lastEndEdgeUpdateGlobalPosition = event.globalPosition; + } else { + _lastStartEdgeUpdateGlobalPosition = event.globalPosition; + } + return super.handleSelectionEdgeUpdate(event); + } + + @override + void dispose() { + _hasReceivedStartEvent.clear(); + _hasReceivedEndEvent.clear(); + super.dispose(); + } + + @override + SelectionResult dispatchSelectionEventToChild(Selectable selectable, SelectionEvent event) { + switch (event.type) { + case SelectionEventType.startEdgeUpdate: + _hasReceivedStartEvent.add(selectable); + ensureChildUpdated(selectable); + case SelectionEventType.endEdgeUpdate: + _hasReceivedEndEvent.add(selectable); + ensureChildUpdated(selectable); + case SelectionEventType.clear: + _hasReceivedStartEvent.remove(selectable); + _hasReceivedEndEvent.remove(selectable); + case SelectionEventType.selectAll: + case SelectionEventType.selectWord: + break; + case SelectionEventType.granularlyExtendSelection: + case SelectionEventType.directionallyExtendSelection: + _hasReceivedStartEvent.add(selectable); + _hasReceivedEndEvent.add(selectable); + ensureChildUpdated(selectable); + } + return super.dispatchSelectionEventToChild(selectable, event); + } + + @override + void ensureChildUpdated(Selectable selectable) { + if (_lastEndEdgeUpdateGlobalPosition != null && _hasReceivedEndEvent.add(selectable)) { + final SelectionEdgeUpdateEvent synthesizedEvent = SelectionEdgeUpdateEvent.forEnd( + globalPosition: _lastEndEdgeUpdateGlobalPosition!, + ); + if (currentSelectionEndIndex == -1) { + handleSelectionEdgeUpdate(synthesizedEvent); + } + selectable.dispatchSelectionEvent(synthesizedEvent); + } + if (_lastStartEdgeUpdateGlobalPosition != null && _hasReceivedStartEvent.add(selectable)) { + final SelectionEdgeUpdateEvent synthesizedEvent = SelectionEdgeUpdateEvent.forStart( + globalPosition: _lastStartEdgeUpdateGlobalPosition!, + ); + if (currentSelectionStartIndex == -1) { + handleSelectionEdgeUpdate(synthesizedEvent); + } + selectable.dispatchSelectionEvent(synthesizedEvent); + } + } + + @override + void didChangeSelectables() { + if (_lastEndEdgeUpdateGlobalPosition != null) { + handleSelectionEdgeUpdate( + SelectionEdgeUpdateEvent.forEnd( + globalPosition: _lastEndEdgeUpdateGlobalPosition!, + ), + ); + } + if (_lastStartEdgeUpdateGlobalPosition != null) { + handleSelectionEdgeUpdate( + SelectionEdgeUpdateEvent.forStart( + globalPosition: _lastStartEdgeUpdateGlobalPosition!, + ), + ); + } + final Set<Selectable> selectableSet = selectables.toSet(); + _hasReceivedEndEvent.removeWhere((Selectable selectable) => !selectableSet.contains(selectable)); + _hasReceivedStartEvent.removeWhere((Selectable selectable) => !selectableSet.contains(selectable)); + super.didChangeSelectables(); + } +} + +/// An abstract base class for updating multiple selectable children. +/// +/// This class provide basic [SelectionEvent] handling and child [Selectable] +/// updating. The subclass needs to implement [ensureChildUpdated] to ensure +/// child [Selectable] is updated properly. +/// +/// This class optimize the selection update by keeping track of the +/// [Selectable]s that currently contain the selection edges. +abstract class MultiSelectableSelectionContainerDelegate extends SelectionContainerDelegate with ChangeNotifier { + /// Creates an instance of [MultiSelectableSelectionContainerDelegate]. + MultiSelectableSelectionContainerDelegate() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + /// Gets the list of selectables this delegate is managing. + List<Selectable> selectables = <Selectable>[]; + + /// The number of additional pixels added to the selection handle drawable + /// area. + /// + /// Selection handles that are outside of the drawable area will be hidden. + /// That logic prevents handles that get scrolled off the viewport from being + /// drawn on the screen. + /// + /// The drawable area = current rectangle of [SelectionContainer] + + /// _kSelectionHandleDrawableAreaPadding on each side. + /// + /// This was an eyeballed value to create smooth user experiences. + static const double _kSelectionHandleDrawableAreaPadding = 5.0; + + /// The current selectable that contains the selection end edge. + @protected + int currentSelectionEndIndex = -1; + + /// The current selectable that contains the selection start edge. + @protected + int currentSelectionStartIndex = -1; + + LayerLink? _startHandleLayer; + Selectable? _startHandleLayerOwner; + LayerLink? _endHandleLayer; + Selectable? _endHandleLayerOwner; + + bool _isHandlingSelectionEvent = false; + bool _scheduledSelectableUpdate = false; + bool _selectionInProgress = false; + Set<Selectable> _additions = <Selectable>{}; + + bool _extendSelectionInProgress = false; + + @override + void add(Selectable selectable) { + assert(!selectables.contains(selectable)); + _additions.add(selectable); + _scheduleSelectableUpdate(); + } + + @override + void remove(Selectable selectable) { + if (_additions.remove(selectable)) { + // The same selectable was added in the same frame and is not yet + // incorporated into the selectables. + // + // Removing such selectable doesn't require selection geometry update. + return; + } + _removeSelectable(selectable); + _scheduleSelectableUpdate(); + } + + /// Notifies this delegate that layout of the container has changed. + void layoutDidChange() { + _updateSelectionGeometry(); + } + + void _scheduleSelectableUpdate() { + if (!_scheduledSelectableUpdate) { + _scheduledSelectableUpdate = true; + void runScheduledTask([Duration? duration]) { + if (!_scheduledSelectableUpdate) { + return; + } + _scheduledSelectableUpdate = false; + _updateSelectables(); + } + + if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.postFrameCallbacks) { + // A new task can be scheduled as a result of running the scheduled task + // from another MultiSelectableSelectionContainerDelegate. This can + // happen if nesting two SelectionContainers. The selectable can be + // safely updated in the same frame in this case. + scheduleMicrotask(runScheduledTask); + } else { + SchedulerBinding.instance.addPostFrameCallback( + runScheduledTask, + debugLabel: 'SelectionContainer.runScheduledTask', + ); + } + } + } + + void _updateSelectables() { + // Remove offScreen selectable. + if (_additions.isNotEmpty) { + _flushAdditions(); + } + didChangeSelectables(); + } + + void _flushAdditions() { + final List<Selectable> mergingSelectables = _additions.toList()..sort(compareOrder); + final List<Selectable> existingSelectables = selectables; + selectables = <Selectable>[]; + int mergingIndex = 0; + int existingIndex = 0; + int selectionStartIndex = currentSelectionStartIndex; + int selectionEndIndex = currentSelectionEndIndex; + // Merge two sorted lists. + while (mergingIndex < mergingSelectables.length || existingIndex < existingSelectables.length) { + if (mergingIndex >= mergingSelectables.length || + (existingIndex < existingSelectables.length && + compareOrder(existingSelectables[existingIndex], mergingSelectables[mergingIndex]) < 0)) { + if (existingIndex == currentSelectionStartIndex) { + selectionStartIndex = selectables.length; + } + if (existingIndex == currentSelectionEndIndex) { + selectionEndIndex = selectables.length; + } + selectables.add(existingSelectables[existingIndex]); + existingIndex += 1; + continue; + } + + // If the merging selectable falls in the selection range, their selection + // needs to be updated. + final Selectable mergingSelectable = mergingSelectables[mergingIndex]; + if (existingIndex < max(currentSelectionStartIndex, currentSelectionEndIndex) && + existingIndex > min(currentSelectionStartIndex, currentSelectionEndIndex)) { + ensureChildUpdated(mergingSelectable); + } + mergingSelectable.addListener(_handleSelectableGeometryChange); + selectables.add(mergingSelectable); + mergingIndex += 1; + } + assert(mergingIndex == mergingSelectables.length && + existingIndex == existingSelectables.length && + selectables.length == existingIndex + mergingIndex); + assert(selectionStartIndex >= -1 || selectionStartIndex < selectables.length); + assert(selectionEndIndex >= -1 || selectionEndIndex < selectables.length); + // selection indices should not be set to -1 unless they originally were. + assert((currentSelectionStartIndex == -1) == (selectionStartIndex == -1)); + assert((currentSelectionEndIndex == -1) == (selectionEndIndex == -1)); + currentSelectionEndIndex = selectionEndIndex; + currentSelectionStartIndex = selectionStartIndex; + _additions = <Selectable>{}; + } + + void _removeSelectable(Selectable selectable) { + assert(selectables.contains(selectable), 'The selectable is not in this registrar.'); + final int index = selectables.indexOf(selectable); + selectables.removeAt(index); + if (index <= currentSelectionEndIndex) { + currentSelectionEndIndex -= 1; + } + if (index <= currentSelectionStartIndex) { + currentSelectionStartIndex -= 1; + } + selectable.removeListener(_handleSelectableGeometryChange); + } + + /// Called when this delegate finishes updating the selectables. + @protected + @mustCallSuper + void didChangeSelectables() { + _updateSelectionGeometry(); + } + + @override + SelectionGeometry get value => _selectionGeometry; + SelectionGeometry _selectionGeometry = const SelectionGeometry( + hasContent: false, + status: SelectionStatus.none, + ); + + /// Updates the [value] in this class and notifies listeners if necessary. + void _updateSelectionGeometry() { + final SelectionGeometry newValue = getSelectionGeometry(); + if (_selectionGeometry != newValue) { + _selectionGeometry = newValue; + notifyListeners(); + } + _updateHandleLayersAndOwners(); + } + + Rect _getBoundingBox(Selectable selectable) { + Rect result = selectable.boundingBoxes.first; + for (int index = 1; index < selectable.boundingBoxes.length; index += 1) { + result = result.expandToInclude(selectable.boundingBoxes[index]); + } + return result; + } + + /// The compare function this delegate used for determining the selection + /// order of the selectables. + /// + /// Defaults to screen order. + @protected + Comparator<Selectable> get compareOrder => _compareScreenOrder; + + int _compareScreenOrder(Selectable a, Selectable b) { + final Rect rectA = MatrixUtils.transformRect( + a.getTransformTo(null), + _getBoundingBox(a), + ); + final Rect rectB = MatrixUtils.transformRect( + b.getTransformTo(null), + _getBoundingBox(b), + ); + final int result = _compareVertically(rectA, rectB); + if (result != 0) { + return result; + } + return _compareHorizontally(rectA, rectB); + } + + /// Compares two rectangles in the screen order solely by their vertical + /// positions. + /// + /// Returns positive if a is lower, negative if a is higher, 0 if their + /// order can't be determine solely by their vertical position. + static int _compareVertically(Rect a, Rect b) { + // The rectangles overlap so defer to horizontal comparison. + if ((a.top - b.top < _kSelectableVerticalComparingThreshold && a.bottom - b.bottom > - _kSelectableVerticalComparingThreshold) || + (b.top - a.top < _kSelectableVerticalComparingThreshold && b.bottom - a.bottom > - _kSelectableVerticalComparingThreshold)) { + return 0; + } + if ((a.top - b.top).abs() > _kSelectableVerticalComparingThreshold) { + return a.top > b.top ? 1 : -1; + } + return a.bottom > b.bottom ? 1 : -1; + } + + /// Compares two rectangles in the screen order by their horizontal positions + /// assuming one of the rectangles enclose the other rect vertically. + /// + /// Returns positive if a is lower, negative if a is higher. + static int _compareHorizontally(Rect a, Rect b) { + // a encloses b. + if (a.left - b.left < precisionErrorTolerance && a.right - b.right > - precisionErrorTolerance) { + return -1; + } + // b encloses a. + if (b.left - a.left < precisionErrorTolerance && b.right - a.right > - precisionErrorTolerance) { + return 1; + } + if ((a.left - b.left).abs() > precisionErrorTolerance) { + return a.left > b.left ? 1 : -1; + } + return a.right > b.right ? 1 : -1; + } + + void _handleSelectableGeometryChange() { + // Geometries of selectable children may change multiple times when handling + // selection events. Ignore these updates since the selection geometry of + // this delegate will be updated after handling the selection events. + if (_isHandlingSelectionEvent) { + return; + } + _updateSelectionGeometry(); + } + + /// Gets the combined selection geometry for child selectables. + @protected + SelectionGeometry getSelectionGeometry() { + if (currentSelectionEndIndex == -1 || + currentSelectionStartIndex == -1 || + selectables.isEmpty) { + // There is no valid selection. + return SelectionGeometry( + status: SelectionStatus.none, + hasContent: selectables.isNotEmpty, + ); + } + + if (!_extendSelectionInProgress) { + currentSelectionStartIndex = _adjustSelectionIndexBasedOnSelectionGeometry( + currentSelectionStartIndex, + currentSelectionEndIndex, + ); + currentSelectionEndIndex = _adjustSelectionIndexBasedOnSelectionGeometry( + currentSelectionEndIndex, + currentSelectionStartIndex, + ); + } + + // Need to find the non-null start selection point. + SelectionGeometry startGeometry = selectables[currentSelectionStartIndex].value; + final bool forwardSelection = currentSelectionEndIndex >= currentSelectionStartIndex; + int startIndexWalker = currentSelectionStartIndex; + while (startIndexWalker != currentSelectionEndIndex && startGeometry.startSelectionPoint == null) { + startIndexWalker += forwardSelection ? 1 : -1; + startGeometry = selectables[startIndexWalker].value; + } + + SelectionPoint? startPoint; + if (startGeometry.startSelectionPoint != null) { + final Matrix4 startTransform = getTransformFrom(selectables[startIndexWalker]); + final Offset start = MatrixUtils.transformPoint(startTransform, startGeometry.startSelectionPoint!.localPosition); + // It can be NaN if it is detached or off-screen. + if (start.isFinite) { + startPoint = SelectionPoint( + localPosition: start, + lineHeight: startGeometry.startSelectionPoint!.lineHeight, + handleType: startGeometry.startSelectionPoint!.handleType, + ); + } + } + + // Need to find the non-null end selection point. + SelectionGeometry endGeometry = selectables[currentSelectionEndIndex].value; + int endIndexWalker = currentSelectionEndIndex; + while (endIndexWalker != currentSelectionStartIndex && endGeometry.endSelectionPoint == null) { + endIndexWalker += forwardSelection ? -1 : 1; + endGeometry = selectables[endIndexWalker].value; + } + SelectionPoint? endPoint; + if (endGeometry.endSelectionPoint != null) { + final Matrix4 endTransform = getTransformFrom(selectables[endIndexWalker]); + final Offset end = MatrixUtils.transformPoint(endTransform, endGeometry.endSelectionPoint!.localPosition); + // It can be NaN if it is detached or off-screen. + if (end.isFinite) { + endPoint = SelectionPoint( + localPosition: end, + lineHeight: endGeometry.endSelectionPoint!.lineHeight, + handleType: endGeometry.endSelectionPoint!.handleType, + ); + } + } + + // Need to collect selection rects from selectables ranging from the + // currentSelectionStartIndex to the currentSelectionEndIndex. + final List<Rect> selectionRects = <Rect>[]; + final Rect? drawableArea = hasSize ? Rect + .fromLTWH(0, 0, containerSize.width, containerSize.height) : null; + for (int index = currentSelectionStartIndex; index <= currentSelectionEndIndex; index++) { + final List<Rect> currSelectableSelectionRects = selectables[index].value.selectionRects; + final List<Rect> selectionRectsWithinDrawableArea = currSelectableSelectionRects.map((Rect selectionRect) { + final Matrix4 transform = getTransformFrom(selectables[index]); + final Rect localRect = MatrixUtils.transformRect(transform, selectionRect); + if (drawableArea != null) { + return drawableArea.intersect(localRect); + } + return localRect; + }).where((Rect selectionRect) { + return selectionRect.isFinite && !selectionRect.isEmpty; + }).toList(); + selectionRects.addAll(selectionRectsWithinDrawableArea); + } + + return SelectionGeometry( + startSelectionPoint: startPoint, + endSelectionPoint: endPoint, + selectionRects: selectionRects, + status: startGeometry != endGeometry + ? SelectionStatus.uncollapsed + : startGeometry.status, + // Would have at least one selectable child. + hasContent: true, + ); + } + + // The currentSelectionStartIndex or currentSelectionEndIndex may not be + // the current index that contains selection edges. This can happen if the + // selection edge is in between two selectables. One of the selectable will + // have its selection collapsed at the index 0 or contentLength depends on + // whether the selection is reversed or not. The current selection index can + // be point to either one. + // + // This method adjusts the index to point to selectable with valid selection. + int _adjustSelectionIndexBasedOnSelectionGeometry(int currentIndex, int towardIndex) { + final bool forward = towardIndex > currentIndex; + while (currentIndex != towardIndex && + selectables[currentIndex].value.status != SelectionStatus.uncollapsed) { + currentIndex += forward ? 1 : -1; + } + return currentIndex; + } + + @override + void pushHandleLayers(LayerLink? startHandle, LayerLink? endHandle) { + if (_startHandleLayer == startHandle && _endHandleLayer == endHandle) { + return; + } + _startHandleLayer = startHandle; + _endHandleLayer = endHandle; + _updateHandleLayersAndOwners(); + } + + /// Pushes both handle layers to the selectables that contain selection edges. + /// + /// This method needs to be called every time the selectables that contain the + /// selection edges change, i.e. [currentSelectionStartIndex] or + /// [currentSelectionEndIndex] changes. Otherwise, the handle may be painted + /// in the wrong place. + void _updateHandleLayersAndOwners() { + LayerLink? effectiveStartHandle = _startHandleLayer; + LayerLink? effectiveEndHandle = _endHandleLayer; + if (effectiveStartHandle != null || effectiveEndHandle != null) { + final Rect? drawableArea = hasSize ? Rect + .fromLTWH(0, 0, containerSize.width, containerSize.height) + .inflate(_kSelectionHandleDrawableAreaPadding) : null; + final bool hideStartHandle = value.startSelectionPoint == null || drawableArea == null || !drawableArea.contains(value.startSelectionPoint!.localPosition); + final bool hideEndHandle = value.endSelectionPoint == null || drawableArea == null|| !drawableArea.contains(value.endSelectionPoint!.localPosition); + effectiveStartHandle = hideStartHandle ? null : _startHandleLayer; + effectiveEndHandle = hideEndHandle ? null : _endHandleLayer; + } + if (currentSelectionStartIndex == -1 || currentSelectionEndIndex == -1) { + // No valid selection. + if (_startHandleLayerOwner != null) { + _startHandleLayerOwner!.pushHandleLayers(null, null); + _startHandleLayerOwner = null; + } + if (_endHandleLayerOwner != null) { + _endHandleLayerOwner!.pushHandleLayers(null, null); + _endHandleLayerOwner = null; + } + return; + } + + if (selectables[currentSelectionStartIndex] != _startHandleLayerOwner) { + _startHandleLayerOwner?.pushHandleLayers(null, null); + } + if (selectables[currentSelectionEndIndex] != _endHandleLayerOwner) { + _endHandleLayerOwner?.pushHandleLayers(null, null); + } + + _startHandleLayerOwner = selectables[currentSelectionStartIndex]; + + if (currentSelectionStartIndex == currentSelectionEndIndex) { + // Selection edges is on the same selectable. + _endHandleLayerOwner = _startHandleLayerOwner; + _startHandleLayerOwner!.pushHandleLayers(effectiveStartHandle, effectiveEndHandle); + return; + } + + _startHandleLayerOwner!.pushHandleLayers(effectiveStartHandle, null); + _endHandleLayerOwner = selectables[currentSelectionEndIndex]; + _endHandleLayerOwner!.pushHandleLayers(null, effectiveEndHandle); + } + + /// Copies the selected contents of all selectables. + @override + SelectedContent? getSelectedContent() { + final List<SelectedContent> selections = <SelectedContent>[]; + for (final Selectable selectable in selectables) { + final SelectedContent? data = selectable.getSelectedContent(); + if (data != null) { + selections.add(data); + } + } + if (selections.isEmpty) { + return null; + } + final StringBuffer buffer = StringBuffer(); + for (final SelectedContent selection in selections) { + buffer.write(selection.plainText); + } + return SelectedContent( + plainText: buffer.toString(), + ); + } + + // Clears the selection on all selectables not in the range of + // currentSelectionStartIndex..currentSelectionEndIndex. + // + // If one of the edges does not exist, then this method will clear the selection + // in all selectables except the existing edge. + // + // If neither of the edges exist this method immediately returns. + void _flushInactiveSelections() { + if (currentSelectionStartIndex == -1 && currentSelectionEndIndex == -1) { + return; + } + if (currentSelectionStartIndex == -1 || currentSelectionEndIndex == -1) { + final int skipIndex = currentSelectionStartIndex == -1 ? currentSelectionEndIndex : currentSelectionStartIndex; + selectables + .where((Selectable target) => target != selectables[skipIndex]) + .forEach((Selectable target) => dispatchSelectionEventToChild(target, const ClearSelectionEvent())); + return; + } + final int skipStart = min(currentSelectionStartIndex, currentSelectionEndIndex); + final int skipEnd = max(currentSelectionStartIndex, currentSelectionEndIndex); + for (int index = 0; index < selectables.length; index += 1) { + if (index >= skipStart && index <= skipEnd) { + continue; + } + dispatchSelectionEventToChild(selectables[index], const ClearSelectionEvent()); + } + } + + /// Selects all contents of all selectables. + @protected + SelectionResult handleSelectAll(SelectAllSelectionEvent event) { + for (final Selectable selectable in selectables) { + dispatchSelectionEventToChild(selectable, event); + } + currentSelectionStartIndex = 0; + currentSelectionEndIndex = selectables.length - 1; + return SelectionResult.none; + } + + /// Selects a word in a selectable at the location + /// [SelectWordSelectionEvent.globalPosition]. + @protected + SelectionResult handleSelectWord(SelectWordSelectionEvent event) { + SelectionResult? lastSelectionResult; + for (int index = 0; index < selectables.length; index += 1) { + bool globalRectsContainsPosition = false; + if (selectables[index].boundingBoxes.isNotEmpty) { + for (final Rect rect in selectables[index].boundingBoxes) { + final Rect globalRect = MatrixUtils.transformRect(selectables[index].getTransformTo(null), rect); + if (globalRect.contains(event.globalPosition)) { + globalRectsContainsPosition = true; + break; + } + } + } + if (globalRectsContainsPosition) { + final SelectionGeometry existingGeometry = selectables[index].value; + lastSelectionResult = dispatchSelectionEventToChild(selectables[index], event); + if (index == selectables.length - 1 && lastSelectionResult == SelectionResult.next) { + return SelectionResult.next; + } + if (lastSelectionResult == SelectionResult.next) { + continue; + } + if (index == 0 && lastSelectionResult == SelectionResult.previous) { + return SelectionResult.previous; + } + if (selectables[index].value != existingGeometry) { + // Geometry has changed as a result of select word, need to clear the + // selection of other selectables to keep selection in sync. + selectables + .where((Selectable target) => target != selectables[index]) + .forEach((Selectable target) => dispatchSelectionEventToChild(target, const ClearSelectionEvent())); + currentSelectionStartIndex = currentSelectionEndIndex = index; + } + return SelectionResult.end; + } else { + if (lastSelectionResult == SelectionResult.next) { + currentSelectionStartIndex = currentSelectionEndIndex = index - 1; + return SelectionResult.end; + } + } + } + assert(lastSelectionResult == null); + return SelectionResult.end; + } + + /// Removes the selection of all selectables this delegate manages. + @protected + SelectionResult handleClearSelection(ClearSelectionEvent event) { + for (final Selectable selectable in selectables) { + dispatchSelectionEventToChild(selectable, event); + } + currentSelectionEndIndex = -1; + currentSelectionStartIndex = -1; + return SelectionResult.none; + } + + /// Extend current selection in a certain text granularity. + @protected + SelectionResult handleGranularlyExtendSelection(GranularlyExtendSelectionEvent event) { + assert((currentSelectionStartIndex == -1) == (currentSelectionEndIndex == -1)); + if (currentSelectionStartIndex == -1) { + if (event.forward) { + currentSelectionStartIndex = currentSelectionEndIndex = 0; + } else { + currentSelectionStartIndex = currentSelectionEndIndex = selectables.length; + } + } + int targetIndex = event.isEnd ? currentSelectionEndIndex : currentSelectionStartIndex; + SelectionResult result = dispatchSelectionEventToChild(selectables[targetIndex], event); + if (event.forward) { + assert(result != SelectionResult.previous); + while (targetIndex < selectables.length - 1 && result == SelectionResult.next) { + targetIndex += 1; + result = dispatchSelectionEventToChild(selectables[targetIndex], event); + assert(result != SelectionResult.previous); + } + } else { + assert(result != SelectionResult.next); + while (targetIndex > 0 && result == SelectionResult.previous) { + targetIndex -= 1; + result = dispatchSelectionEventToChild(selectables[targetIndex], event); + assert(result != SelectionResult.next); + } + } + if (event.isEnd) { + currentSelectionEndIndex = targetIndex; + } else { + currentSelectionStartIndex = targetIndex; + } + return result; + } + + /// Extend current selection in a certain text granularity. + @protected + SelectionResult handleDirectionallyExtendSelection(DirectionallyExtendSelectionEvent event) { + assert((currentSelectionStartIndex == -1) == (currentSelectionEndIndex == -1)); + if (currentSelectionStartIndex == -1) { + switch (event.direction) { + case SelectionExtendDirection.previousLine: + case SelectionExtendDirection.backward: + currentSelectionStartIndex = currentSelectionEndIndex = selectables.length; + case SelectionExtendDirection.nextLine: + case SelectionExtendDirection.forward: + currentSelectionStartIndex = currentSelectionEndIndex = 0; + } + } + int targetIndex = event.isEnd ? currentSelectionEndIndex : currentSelectionStartIndex; + SelectionResult result = dispatchSelectionEventToChild(selectables[targetIndex], event); + switch (event.direction) { + case SelectionExtendDirection.previousLine: + assert(result == SelectionResult.end || result == SelectionResult.previous); + if (result == SelectionResult.previous) { + if (targetIndex > 0) { + targetIndex -= 1; + result = dispatchSelectionEventToChild( + selectables[targetIndex], + event.copyWith(direction: SelectionExtendDirection.backward), + ); + assert(result == SelectionResult.end); + } + } + case SelectionExtendDirection.nextLine: + assert(result == SelectionResult.end || result == SelectionResult.next); + if (result == SelectionResult.next) { + if (targetIndex < selectables.length - 1) { + targetIndex += 1; + result = dispatchSelectionEventToChild( + selectables[targetIndex], + event.copyWith(direction: SelectionExtendDirection.forward), + ); + assert(result == SelectionResult.end); + } + } + case SelectionExtendDirection.forward: + case SelectionExtendDirection.backward: + assert(result == SelectionResult.end); + } + if (event.isEnd) { + currentSelectionEndIndex = targetIndex; + } else { + currentSelectionStartIndex = targetIndex; + } + return result; + } + + /// Updates the selection edges. + @protected + SelectionResult handleSelectionEdgeUpdate(SelectionEdgeUpdateEvent event) { + if (event.type == SelectionEventType.endEdgeUpdate) { + return currentSelectionEndIndex == -1 ? _initSelection(event, isEnd: true) : _adjustSelection(event, isEnd: true); + } + return currentSelectionStartIndex == -1 ? _initSelection(event, isEnd: false) : _adjustSelection(event, isEnd: false); + } + + @override + SelectionResult dispatchSelectionEvent(SelectionEvent event) { + final bool selectionWillbeInProgress = event is! ClearSelectionEvent; + if (!_selectionInProgress && selectionWillbeInProgress) { + // Sort the selectable every time a selection start. + selectables.sort(compareOrder); + } + _selectionInProgress = selectionWillbeInProgress; + _isHandlingSelectionEvent = true; + late SelectionResult result; + switch (event.type) { + case SelectionEventType.startEdgeUpdate: + case SelectionEventType.endEdgeUpdate: + _extendSelectionInProgress = false; + result = handleSelectionEdgeUpdate(event as SelectionEdgeUpdateEvent); + case SelectionEventType.clear: + _extendSelectionInProgress = false; + result = handleClearSelection(event as ClearSelectionEvent); + case SelectionEventType.selectAll: + _extendSelectionInProgress = false; + result = handleSelectAll(event as SelectAllSelectionEvent); + case SelectionEventType.selectWord: + _extendSelectionInProgress = false; + result = handleSelectWord(event as SelectWordSelectionEvent); + case SelectionEventType.granularlyExtendSelection: + _extendSelectionInProgress = true; + result = handleGranularlyExtendSelection(event as GranularlyExtendSelectionEvent); + case SelectionEventType.directionallyExtendSelection: + _extendSelectionInProgress = true; + result = handleDirectionallyExtendSelection(event as DirectionallyExtendSelectionEvent); + } + _isHandlingSelectionEvent = false; + _updateSelectionGeometry(); + return result; + } + + @override + void dispose() { + for (final Selectable selectable in selectables) { + selectable.removeListener(_handleSelectableGeometryChange); + } + selectables = const <Selectable>[]; + _scheduledSelectableUpdate = false; + super.dispose(); + } + + /// Ensures the selectable child has received up to date selection event. + /// + /// This method is called when a new [Selectable] is added to the delegate, + /// and its screen location falls into the previous selection. + /// + /// Subclasses are responsible for updating the selection of this newly added + /// [Selectable]. + @protected + void ensureChildUpdated(Selectable selectable); + + /// Dispatches a selection event to a specific selectable. + /// + /// Override this method if subclasses need to generate additional events or + /// treatments prior to sending the selection events. + @protected + SelectionResult dispatchSelectionEventToChild(Selectable selectable, SelectionEvent event) { + return selectable.dispatchSelectionEvent(event); + } + + /// Initializes the selection of the selectable children. + /// + /// The goal is to find the selectable child that contains the selection edge. + /// Returns [SelectionResult.end] if the selection edge ends on any of the + /// children. Otherwise, it returns [SelectionResult.previous] if the selection + /// does not reach any of its children. Returns [SelectionResult.next] + /// if the selection reaches the end of its children. + /// + /// Ideally, this method should only be called twice at the beginning of the + /// drag selection, once for start edge update event, once for end edge update + /// event. + SelectionResult _initSelection(SelectionEdgeUpdateEvent event, {required bool isEnd}) { + assert((isEnd && currentSelectionEndIndex == -1) || (!isEnd && currentSelectionStartIndex == -1)); + int newIndex = -1; + bool hasFoundEdgeIndex = false; + SelectionResult? result; + for (int index = 0; index < selectables.length && !hasFoundEdgeIndex; index += 1) { + final Selectable child = selectables[index]; + final SelectionResult childResult = dispatchSelectionEventToChild(child, event); + switch (childResult) { + case SelectionResult.next: + case SelectionResult.none: + newIndex = index; + case SelectionResult.end: + newIndex = index; + result = SelectionResult.end; + hasFoundEdgeIndex = true; + case SelectionResult.previous: + hasFoundEdgeIndex = true; + if (index == 0) { + newIndex = 0; + result = SelectionResult.previous; + } + result ??= SelectionResult.end; + case SelectionResult.pending: + newIndex = index; + result = SelectionResult.pending; + hasFoundEdgeIndex = true; + } + } + + if (newIndex == -1) { + assert(selectables.isEmpty); + return SelectionResult.none; + } + if (isEnd) { + currentSelectionEndIndex = newIndex; + } else { + currentSelectionStartIndex = newIndex; + } + _flushInactiveSelections(); + // The result can only be null if the loop went through the entire list + // without any of the selection returned end or previous. In this case, the + // caller of this method needs to find the next selectable in their list. + return result ?? SelectionResult.next; + } + + /// Adjusts the selection based on the drag selection update event if there + /// is already a selectable child that contains the selection edge. + /// + /// This method starts by sending the selection event to the current + /// selectable that contains the selection edge, and finds forward or backward + /// if that selectable no longer contains the selection edge. + SelectionResult _adjustSelection(SelectionEdgeUpdateEvent event, {required bool isEnd}) { + assert(() { + if (isEnd) { + assert(currentSelectionEndIndex < selectables.length && currentSelectionEndIndex >= 0); + return true; + } + assert(currentSelectionStartIndex < selectables.length && currentSelectionStartIndex >= 0); + return true; + }()); + SelectionResult? finalResult; + // Determines if the edge being adjusted is within the current viewport. + // - If so, we begin the search for the new selection edge position at the + // currentSelectionEndIndex/currentSelectionStartIndex. + // - If not, we attempt to locate the new selection edge starting from + // the opposite end. + // - If neither edge is in the current viewport, the search for the new + // selection edge position begins at 0. + // + // This can happen when there is a scrollable child and the edge being adjusted + // has been scrolled out of view. + final bool isCurrentEdgeWithinViewport = isEnd ? _selectionGeometry.endSelectionPoint != null : _selectionGeometry.startSelectionPoint != null; + final bool isOppositeEdgeWithinViewport = isEnd ? _selectionGeometry.startSelectionPoint != null : _selectionGeometry.endSelectionPoint != null; + int newIndex = switch ((isEnd, isCurrentEdgeWithinViewport, isOppositeEdgeWithinViewport)) { + (true, true, true) => currentSelectionEndIndex, + (true, true, false) => currentSelectionEndIndex, + (true, false, true) => currentSelectionStartIndex, + (true, false, false) => 0, + (false, true, true) => currentSelectionStartIndex, + (false, true, false) => currentSelectionStartIndex, + (false, false, true) => currentSelectionEndIndex, + (false, false, false) => 0, + }; + bool? forward; + late SelectionResult currentSelectableResult; + // This loop sends the selection event to one of the following to determine + // the direction of the search. + // - currentSelectionEndIndex/currentSelectionStartIndex if the current edge + // is in the current viewport. + // - The opposite edge index if the current edge is not in the current viewport. + // - Index 0 if neither edge is in the current viewport. + // + // If the result is `SelectionResult.next`, this loop look backward. + // Otherwise, it looks forward. + // + // The terminate condition are: + // 1. the selectable returns end, pending, none. + // 2. the selectable returns previous when looking forward. + // 2. the selectable returns next when looking backward. + while (newIndex < selectables.length && newIndex >= 0 && finalResult == null) { + currentSelectableResult = dispatchSelectionEventToChild(selectables[newIndex], event); + switch (currentSelectableResult) { + case SelectionResult.end: + case SelectionResult.pending: + case SelectionResult.none: + finalResult = currentSelectableResult; + case SelectionResult.next: + if (forward == false) { + newIndex += 1; + finalResult = SelectionResult.end; + } else if (newIndex == selectables.length - 1) { + finalResult = currentSelectableResult; + } else { + forward = true; + newIndex += 1; + } + case SelectionResult.previous: + if (forward ?? false) { + newIndex -= 1; + finalResult = SelectionResult.end; + } else if (newIndex == 0) { + finalResult = currentSelectableResult; + } else { + forward = false; + newIndex -= 1; + } + } + } + if (isEnd) { + currentSelectionEndIndex = newIndex; + } else { + currentSelectionStartIndex = newIndex; + } + _flushInactiveSelections(); + return finalResult!; + } +} + +/// Signature for a widget builder that builds a context menu for the given +/// [SelectableRegionState]. +/// +/// See also: +/// +/// * [EditableTextContextMenuBuilder], which performs the same role for +/// [EditableText]. +typedef SelectableRegionContextMenuBuilder = Widget Function( + BuildContext context, + SelectableRegionState selectableRegionState, +); diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/selection_container.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/selection_container.dart new file mode 100644 index 0000000000000000000000000000000000000000..45535ab6fb119514350525d33e04bb6f328c5ce8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/selection_container.dart @@ -0,0 +1,326 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; + +/// A container that handles [SelectionEvent]s for the [Selectable]s in +/// the subtree. +/// +/// This widget is useful when one wants to customize selection behaviors for +/// a group of [Selectable]s +/// +/// The state of this container is a single selectable and will register +/// itself to the [registrar] if provided. Otherwise, it will register to the +/// [SelectionRegistrar] from the context. Consider using a [SelectionArea] +/// widget to provide a root registrar. +/// +/// The containers handle the [SelectionEvent]s from the registered +/// [SelectionRegistrar] and delegate the events to the [delegate]. +/// +/// This widget uses [SelectionRegistrarScope] to host the [delegate] as the +/// [SelectionRegistrar] for the subtree to collect the [Selectable]s, and +/// [SelectionEvent]s received by this container are sent to the [delegate] using +/// the [SelectionHandler] API of the delegate. +/// +/// {@tool dartpad} +/// This sample demonstrates how to create a [SelectionContainer] that only +/// allows selecting everything or nothing with no partial selection. +/// +/// ** See code in examples/api/lib/material/selection_container/selection_container.0.dart ** +/// {@end-tool} +/// +/// See also: +/// * [SelectableRegion], which provides an overview of the selection system. +/// * [SelectionContainer.disabled], which disable selection for a +/// subtree. +class SelectionContainer extends StatefulWidget { + /// Creates a selection container to collect the [Selectable]s in the subtree. + /// + /// If [registrar] is not provided, this selection container gets the + /// [SelectionRegistrar] from the context instead. + const SelectionContainer({ + super.key, + this.registrar, + required SelectionContainerDelegate this.delegate, + required this.child, + }); + + /// Creates a selection container that disables selection for the + /// subtree. + /// + /// {@tool dartpad} + /// This sample demonstrates how to disable selection for a Text under a + /// SelectionArea. + /// + /// ** See code in examples/api/lib/material/selection_container/selection_container_disabled.0.dart ** + /// {@end-tool} + const SelectionContainer.disabled({ + super.key, + required this.child, + }) : registrar = null, + delegate = null; + + /// The [SelectionRegistrar] this container is registered to. + /// + /// If null, this widget gets the [SelectionRegistrar] from the current + /// context. + final SelectionRegistrar? registrar; + + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The delegate for [SelectionEvent]s sent to this selection container. + /// + /// The [Selectable]s in the subtree are added or removed from this delegate + /// using [SelectionRegistrar] API. + /// + /// This delegate is responsible for updating the selections for the selectables + /// under this widget. + final SelectionContainerDelegate? delegate; + + /// Gets the immediate ancestor [SelectionRegistrar] of the [BuildContext]. + /// + /// If this returns null, either there is no [SelectionContainer] above + /// the [BuildContext] or the immediate [SelectionContainer] is not + /// enabled. + static SelectionRegistrar? maybeOf(BuildContext context) { + final SelectionRegistrarScope? scope = context.dependOnInheritedWidgetOfExactType<SelectionRegistrarScope>(); + return scope?.registrar; + } + + bool get _disabled => delegate == null; + + @override + State<SelectionContainer> createState() => _SelectionContainerState(); +} + +class _SelectionContainerState extends State<SelectionContainer> with Selectable, SelectionRegistrant { + final Set<VoidCallback> _listeners = <VoidCallback>{}; + + static const SelectionGeometry _disabledGeometry = SelectionGeometry( + status: SelectionStatus.none, + hasContent: true, + ); + + @override + void initState() { + super.initState(); + if (!widget._disabled) { + widget.delegate!._selectionContainerContext = context; + if (widget.registrar != null) { + registrar = widget.registrar; + } + } + } + + @override + void didUpdateWidget(SelectionContainer oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.delegate != widget.delegate) { + if (!oldWidget._disabled) { + oldWidget.delegate!._selectionContainerContext = null; + _listeners.forEach(oldWidget.delegate!.removeListener); + } + if (!widget._disabled) { + widget.delegate!._selectionContainerContext = context; + _listeners.forEach(widget.delegate!.addListener); + } + if (oldWidget.delegate?.value != widget.delegate?.value) { + // Avoid concurrent modification. + for (final VoidCallback listener in _listeners.toList(growable: false)) { + listener(); + } + } + } + if (widget._disabled) { + registrar = null; + } else if (widget.registrar != null) { + registrar = widget.registrar; + } + assert(!widget._disabled || registrar == null); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (widget.registrar == null && !widget._disabled) { + registrar = SelectionContainer.maybeOf(context); + } + assert(!widget._disabled || registrar == null); + } + + @override + void addListener(VoidCallback listener) { + assert(!widget._disabled); + widget.delegate!.addListener(listener); + _listeners.add(listener); + } + + @override + void removeListener(VoidCallback listener) { + widget.delegate?.removeListener(listener); + _listeners.remove(listener); + } + + @override + void pushHandleLayers(LayerLink? startHandle, LayerLink? endHandle) { + assert(!widget._disabled); + widget.delegate!.pushHandleLayers(startHandle, endHandle); + } + + @override + SelectedContent? getSelectedContent() { + assert(!widget._disabled); + return widget.delegate!.getSelectedContent(); + } + + @override + SelectionResult dispatchSelectionEvent(SelectionEvent event) { + assert(!widget._disabled); + return widget.delegate!.dispatchSelectionEvent(event); + } + + @override + SelectionGeometry get value { + if (widget._disabled) { + return _disabledGeometry; + } + return widget.delegate!.value; + } + + @override + Matrix4 getTransformTo(RenderObject? ancestor) { + assert(!widget._disabled); + return context.findRenderObject()!.getTransformTo(ancestor); + } + + @override + Size get size => (context.findRenderObject()! as RenderBox).size; + + @override + List<Rect> get boundingBoxes => <Rect>[(context.findRenderObject()! as RenderBox).paintBounds]; + + @override + void dispose() { + if (!widget._disabled) { + widget.delegate!._selectionContainerContext = null; + _listeners.forEach(widget.delegate!.removeListener); + } + super.dispose(); + } + + @override + Widget build(BuildContext context) { + if (widget._disabled) { + return SelectionRegistrarScope._disabled(child: widget.child); + } + return SelectionRegistrarScope( + registrar: widget.delegate!, + child: widget.child, + ); + } +} + +/// An inherited widget to host a [SelectionRegistrar] for the subtree. +/// +/// Use [SelectionContainer.maybeOf] to get the SelectionRegistrar from +/// a context. +/// +/// This widget is automatically created as part of [SelectionContainer] and +/// is generally not used directly, except for disabling selection for a part +/// of subtree. In that case, one can wrap the subtree with +/// [SelectionContainer.disabled]. +class SelectionRegistrarScope extends InheritedWidget { + /// Creates a selection registrar scope that host the [registrar]. + const SelectionRegistrarScope({ + super.key, + required SelectionRegistrar this.registrar, + required super.child, + }); + + /// Creates a selection registrar scope that disables selection for the + /// subtree. + const SelectionRegistrarScope._disabled({ + required super.child, + }) : registrar = null; + + /// The [SelectionRegistrar] hosted by this widget. + final SelectionRegistrar? registrar; + + @override + bool updateShouldNotify(SelectionRegistrarScope oldWidget) { + return oldWidget.registrar != registrar; + } +} + +/// A delegate to handle [SelectionEvent]s for a [SelectionContainer]. +/// +/// This delegate needs to implement [SelectionRegistrar] to register +/// [Selectable]s in the [SelectionContainer] subtree. +abstract class SelectionContainerDelegate implements SelectionHandler, SelectionRegistrar { + BuildContext? _selectionContainerContext; + + /// Gets the paint transform from the [Selectable] child to + /// [SelectionContainer] of this delegate. + /// + /// Returns a matrix that maps the [Selectable] paint coordinate system to the + /// coordinate system of [SelectionContainer]. + /// + /// Can only be called after [SelectionContainer] is laid out. + Matrix4 getTransformFrom(Selectable child) { + assert( + _selectionContainerContext?.findRenderObject() != null, + 'getTransformFrom cannot be called before SelectionContainer is laid out.', + ); + return child.getTransformTo(_selectionContainerContext!.findRenderObject()! as RenderBox); + } + + /// Gets the paint transform from the [SelectionContainer] of this delegate to + /// the `ancestor`. + /// + /// Returns a matrix that maps the [SelectionContainer] paint coordinate + /// system to the coordinate system of `ancestor`. + /// + /// If `ancestor` is null, this method returns a matrix that maps from the + /// local paint coordinate system to the coordinate system of the + /// [PipelineOwner.rootNode]. + /// + /// Can only be called after [SelectionContainer] is laid out. + Matrix4 getTransformTo(RenderObject? ancestor) { + assert( + _selectionContainerContext?.findRenderObject() != null, + 'getTransformTo cannot be called before SelectionContainer is laid out.', + ); + final RenderBox box = _selectionContainerContext!.findRenderObject()! as RenderBox; + return box.getTransformTo(ancestor); + } + + /// Whether the [SelectionContainer] has undergone layout and has a size. + /// + /// See also: + /// + /// * [RenderBox.hasSize], which is used internally by this method. + bool get hasSize { + assert( + _selectionContainerContext?.findRenderObject() != null, + 'The _selectionContainerContext must have a renderObject, such as after the first build has completed.', + ); + final RenderBox box = _selectionContainerContext!.findRenderObject()! as RenderBox; + return box.hasSize; + } + + /// Gets the size of the [SelectionContainer] of this delegate. + /// + /// Can only be called after [SelectionContainer] is laid out. + Size get containerSize { + assert( + hasSize, + 'containerSize cannot be called before SelectionContainer is laid out.', + ); + final RenderBox box = _selectionContainerContext!.findRenderObject()! as RenderBox; + return box.size; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/semantics_debugger.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/semantics_debugger.dart new file mode 100644 index 0000000000000000000000000000000000000000..6b6c69aa2ba9fe6578b26222b0838b271a1a8013 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/semantics_debugger.dart @@ -0,0 +1,413 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; + +import 'basic.dart'; +import 'binding.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'view.dart'; + +/// A widget that visualizes the semantics for the child. +/// +/// This widget is useful for understand how an app presents itself to +/// accessibility technology. +class SemanticsDebugger extends StatefulWidget { + /// Creates a widget that visualizes the semantics for the child. + /// + /// [labelStyle] dictates the [TextStyle] used for the semantics labels. + const SemanticsDebugger({ + super.key, + required this.child, + this.labelStyle = const TextStyle( + color: Color(0xFF000000), + fontSize: 10.0, + height: 0.8, + ), + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The [TextStyle] to use when rendering semantics labels. + final TextStyle labelStyle; + + @override + State<SemanticsDebugger> createState() => _SemanticsDebuggerState(); +} + +class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindingObserver { + _SemanticsClient? _client; + PipelineOwner? _pipelineOwner; + + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addObserver(this); + } + + @override + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final PipelineOwner newOwner = View.pipelineOwnerOf(context); + if (newOwner != _pipelineOwner) { + _client?.dispose(); + _client = _SemanticsClient(newOwner) + ..addListener(_update); + _pipelineOwner = newOwner; + } + } + + @override + void dispose() { + _client?.dispose(); + WidgetsBinding.instance.removeObserver(this); + super.dispose(); + } + + @override + void didChangeMetrics() { + setState(() { + // The root transform may have changed, we have to repaint. + }); + } + + void _update() { + SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { + // Semantic information are only available at the end of a frame and our + // only chance to paint them on the screen is the next frame. To achieve + // this, we call setState() in a post-frame callback. + if (mounted) { + // If we got disposed this frame, we will still get an update, + // because the inactive list is flushed after the semantics updates + // are transmitted to the semantics clients. + setState(() { + // The generation of the _SemanticsDebuggerListener has changed. + }); + } + }, debugLabel: 'SemanticsDebugger.update'); + } + + Offset? _lastPointerDownLocation; + void _handlePointerDown(PointerDownEvent event) { + setState(() { + _lastPointerDownLocation = event.position * View.of(context).devicePixelRatio; + }); + // TODO(ianh): Use a gesture recognizer so that we can reset the + // _lastPointerDownLocation when none of the other gesture recognizers win. + } + + void _handleTap() { + assert(_lastPointerDownLocation != null); + _performAction(_lastPointerDownLocation!, SemanticsAction.tap); + setState(() { + _lastPointerDownLocation = null; + }); + } + + void _handleLongPress() { + assert(_lastPointerDownLocation != null); + _performAction(_lastPointerDownLocation!, SemanticsAction.longPress); + setState(() { + _lastPointerDownLocation = null; + }); + } + + void _handlePanEnd(DragEndDetails details) { + final double vx = details.velocity.pixelsPerSecond.dx; + final double vy = details.velocity.pixelsPerSecond.dy; + if (vx.abs() == vy.abs()) { + return; + } + if (vx.abs() > vy.abs()) { + if (vx.sign < 0) { + _performAction(_lastPointerDownLocation!, SemanticsAction.decrease); + _performAction(_lastPointerDownLocation!, SemanticsAction.scrollLeft); + } else { + _performAction(_lastPointerDownLocation!, SemanticsAction.increase); + _performAction(_lastPointerDownLocation!, SemanticsAction.scrollRight); + } + } else { + if (vy.sign < 0) { + _performAction(_lastPointerDownLocation!, SemanticsAction.scrollUp); + } else { + _performAction(_lastPointerDownLocation!, SemanticsAction.scrollDown); + } + } + setState(() { + _lastPointerDownLocation = null; + }); + } + + void _performAction(Offset position, SemanticsAction action) { + _pipelineOwner?.semanticsOwner?.performActionAt(position, action); + } + + @override + Widget build(BuildContext context) { + return CustomPaint( + foregroundPainter: _SemanticsDebuggerPainter( + _pipelineOwner!, + _client!.generation, + _lastPointerDownLocation, // in physical pixels + View.of(context).devicePixelRatio, + widget.labelStyle, + ), + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: _handleTap, + onLongPress: _handleLongPress, + onPanEnd: _handlePanEnd, + excludeFromSemantics: true, // otherwise if you don't hit anything, we end up receiving it, which causes an infinite loop... + child: Listener( + onPointerDown: _handlePointerDown, + behavior: HitTestBehavior.opaque, + child: _IgnorePointerWithSemantics( + child: widget.child, + ), + ), + ), + ); + } +} + +class _SemanticsClient extends ChangeNotifier { + _SemanticsClient(PipelineOwner pipelineOwner) { + _semanticsHandle = pipelineOwner.ensureSemantics( + listener: _didUpdateSemantics, + ); + } + + SemanticsHandle? _semanticsHandle; + + @override + void dispose() { + _semanticsHandle!.dispose(); + _semanticsHandle = null; + super.dispose(); + } + + int generation = 0; + + void _didUpdateSemantics() { + generation += 1; + notifyListeners(); + } +} + +class _SemanticsDebuggerPainter extends CustomPainter { + const _SemanticsDebuggerPainter(this.owner, this.generation, this.pointerPosition, this.devicePixelRatio, this.labelStyle); + + final PipelineOwner owner; + final int generation; + final Offset? pointerPosition; // in physical pixels + final double devicePixelRatio; + final TextStyle labelStyle; + + SemanticsNode? get _rootSemanticsNode { + return owner.semanticsOwner?.rootSemanticsNode; + } + + @override + void paint(Canvas canvas, Size size) { + final SemanticsNode? rootNode = _rootSemanticsNode; + canvas.save(); + canvas.scale(1.0 / devicePixelRatio, 1.0 / devicePixelRatio); + if (rootNode != null) { + _paint(canvas, rootNode, _findDepth(rootNode)); + } + if (pointerPosition != null) { + final Paint paint = Paint(); + paint.color = const Color(0x7F0090FF); + canvas.drawCircle(pointerPosition!, 10.0 * devicePixelRatio, paint); + } + canvas.restore(); + } + + @override + bool shouldRepaint(_SemanticsDebuggerPainter oldDelegate) { + return owner != oldDelegate.owner + || generation != oldDelegate.generation + || pointerPosition != oldDelegate.pointerPosition; + } + + @visibleForTesting + String getMessage(SemanticsNode node) { + final SemanticsData data = node.getSemanticsData(); + final List<String> annotations = <String>[]; + + bool wantsTap = false; + if (data.hasFlag(SemanticsFlag.hasCheckedState)) { + annotations.add(data.hasFlag(SemanticsFlag.isChecked) ? 'checked' : 'unchecked'); + wantsTap = true; + } + if (data.hasFlag(SemanticsFlag.isTextField)) { + annotations.add('textfield'); + wantsTap = true; + } + + if (data.hasAction(SemanticsAction.tap)) { + if (!wantsTap) { + annotations.add('button'); + } + } else { + if (wantsTap) { + annotations.add('disabled'); + } + } + + if (data.hasAction(SemanticsAction.longPress)) { + annotations.add('long-pressable'); + } + + final bool isScrollable = data.hasAction(SemanticsAction.scrollLeft) + || data.hasAction(SemanticsAction.scrollRight) + || data.hasAction(SemanticsAction.scrollUp) + || data.hasAction(SemanticsAction.scrollDown); + + final bool isAdjustable = data.hasAction(SemanticsAction.increase) + || data.hasAction(SemanticsAction.decrease); + + if (isScrollable) { + annotations.add('scrollable'); + } + + if (isAdjustable) { + annotations.add('adjustable'); + } + + final String message; + // Android will avoid pronouncing duplicating tooltip and label. + // Therefore, having two identical strings is the same as having a single + // string. + final bool shouldIgnoreDuplicatedLabel = defaultTargetPlatform == TargetPlatform.android && data.attributedLabel.string == data.tooltip; + final String tooltipAndLabel = <String>[ + if (data.tooltip.isNotEmpty) + data.tooltip, + if (data.attributedLabel.string.isNotEmpty && !shouldIgnoreDuplicatedLabel) + data.attributedLabel.string, + ].join('\n'); + if (tooltipAndLabel.isEmpty) { + message = annotations.join('; '); + } else { + final String effectivelabel; + if (data.textDirection == null) { + effectivelabel = '${Unicode.FSI}$tooltipAndLabel${Unicode.PDI}'; + annotations.insert(0, 'MISSING TEXT DIRECTION'); + } else { + switch (data.textDirection!) { + case TextDirection.rtl: + effectivelabel = '${Unicode.RLI}$tooltipAndLabel${Unicode.PDF}'; + case TextDirection.ltr: + effectivelabel = tooltipAndLabel; + } + } + if (annotations.isEmpty) { + message = effectivelabel; + } else { + message = '$effectivelabel (${annotations.join('; ')})'; + } + } + + return message.trim(); + } + + void _paintMessage(Canvas canvas, SemanticsNode node) { + final String message = getMessage(node); + if (message.isEmpty) { + return; + } + final Rect rect = node.rect; + canvas.save(); + canvas.clipRect(rect); + final TextPainter textPainter = TextPainter() + ..text = TextSpan( + style: labelStyle, + text: message, + ) + ..textDirection = TextDirection.ltr // _getMessage always returns LTR text, even if node.label is RTL + ..textAlign = TextAlign.center + ..layout(maxWidth: rect.width); + + textPainter.paint(canvas, Alignment.center.inscribe(textPainter.size, rect).topLeft); + textPainter.dispose(); + canvas.restore(); + } + + int _findDepth(SemanticsNode node) { + if (!node.hasChildren || node.mergeAllDescendantsIntoThisNode) { + return 1; + } + int childrenDepth = 0; + node.visitChildren((SemanticsNode child) { + childrenDepth = math.max(childrenDepth, _findDepth(child)); + return true; + }); + return childrenDepth + 1; + } + + void _paint(Canvas canvas, SemanticsNode node, int rank) { + canvas.save(); + if (node.transform != null) { + canvas.transform(node.transform!.storage); + } + final Rect rect = node.rect; + if (!rect.isEmpty) { + final Color lineColor = Color(0xFF000000 + math.Random(node.id).nextInt(0xFFFFFF)); + final Rect innerRect = rect.deflate(rank * 1.0); + if (innerRect.isEmpty) { + final Paint fill = Paint() + ..color = lineColor + ..style = PaintingStyle.fill; + canvas.drawRect(rect, fill); + } else { + final Paint fill = Paint() + ..color = const Color(0xFFFFFFFF) + ..style = PaintingStyle.fill; + canvas.drawRect(rect, fill); + final Paint line = Paint() + ..strokeWidth = rank * 2.0 + ..color = lineColor + ..style = PaintingStyle.stroke; + canvas.drawRect(innerRect, line); + } + _paintMessage(canvas, node); + } + if (!node.mergeAllDescendantsIntoThisNode) { + final int childRank = rank - 1; + node.visitChildren((SemanticsNode child) { + _paint(canvas, child, childRank); + return true; + }); + } + canvas.restore(); + } +} + +/// A widget ignores pointer event but still keeps semantics actions. +class _IgnorePointerWithSemantics extends SingleChildRenderObjectWidget { + const _IgnorePointerWithSemantics({ + super.child, + }); + + @override + _RenderIgnorePointerWithSemantics createRenderObject(BuildContext context) { + return _RenderIgnorePointerWithSemantics(); + } +} + +class _RenderIgnorePointerWithSemantics extends RenderProxyBox { + _RenderIgnorePointerWithSemantics(); + + @override + bool hitTest(BoxHitTestResult result, { required Offset position }) => false; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/service_extensions.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/service_extensions.dart new file mode 100644 index 0000000000000000000000000000000000000000..cb0e165c1aa9a8f18bb4087beef26b8949ccf877 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/service_extensions.dart @@ -0,0 +1,488 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Service extension constants for the widgets library. +/// +/// These constants will be used when registering service extensions in the +/// framework, and they will also be used by tools and services that call these +/// service extensions. +/// +/// The String value for each of these extension names should be accessed by +/// calling the `.name` property on the enum value. +enum WidgetsServiceExtensions { + /// Name of service extension that, when called, will output a string + /// representation of this app's widget tree to console. + /// + /// See also: + /// + /// * [WidgetsBinding.initServiceExtensions], where the service extension is + /// registered. + debugDumpApp, + + /// Name of service extension that, when called, will output a string + /// representation of the focus tree to the console. + /// + /// See also: + /// + /// * [WidgetsBinding.initServiceExtensions], where the service extension is + /// registered. + debugDumpFocusTree, + + /// Name of service extension that, when called, will overlay a performance + /// graph on top of this app. + /// + /// See also: + /// + /// * [WidgetsApp.showPerformanceOverlayOverride], which is the flag + /// that this service extension exposes. + /// * [WidgetsBinding.initServiceExtensions], where the service extension is + /// registered. + showPerformanceOverlay, + + /// Name of service extension that, when called, will return whether the first + /// 'Flutter.Frame' event has been reported on the Extension stream. + /// + /// See also: + /// + /// * [WidgetsBinding.initServiceExtensions], where the service extension is + /// registered. + didSendFirstFrameEvent, + + /// Name of service extension that, when called, will return whether the first + /// frame has been rasterized and the trace event 'Rasterized first useful + /// frame' has been sent out. + /// + /// See also: + /// + /// * [WidgetsBinding.initServiceExtensions], where the service extension is + /// registered. + didSendFirstFrameRasterizedEvent, + + /// Name of service extension that, when called, will reassemble the + /// application. + /// + /// See also: + /// + /// * [WidgetsBinding.initServiceExtensions], where the service extension is + /// registered. + fastReassemble, + + /// Name of service extension that, when called, will change the value of + /// [debugProfileBuildsEnabled], which adds [Timeline] events for every widget + /// built. + /// + /// See also: + /// + /// * [debugProfileBuildsEnabled], which is the flag that this service extension + /// exposes. + /// * [WidgetsBinding.initServiceExtensions], where the service extension is + /// registered. + profileWidgetBuilds, + + /// Name of service extension that, when called, will change the value of + /// [debugProfileBuildsEnabledUserWidgets], which adds [Timeline] events for + /// every user-created widget built. + /// + /// See also: + /// * [debugProfileBuildsEnabledUserWidgets], which is the flag that this + /// service extension exposes. + /// * [WidgetsBinding.initServiceExtensions], where the service extension is + /// registered. + profileUserWidgetBuilds, + + /// Name of service extension that, when called, will change the value of + /// [WidgetsApp.debugAllowBannerOverride], which controls the visibility of the + /// debug banner for debug mode apps. + /// + /// See also: + /// + /// * [WidgetsApp.debugAllowBannerOverride], which is the flag that this service + /// extension exposes. + /// * [WidgetsBinding.initServiceExtensions], where the service extension is + /// registered. + debugAllowBanner, +} + +/// Service extension constants for the Widget Inspector. +/// +/// These constants will be used when registering service extensions in the +/// framework, and they will also be used by tools and services that call these +/// service extensions. +/// +/// The String value for each of these extension names should be accessed by +/// calling the `.name` property on the enum value. +enum WidgetInspectorServiceExtensions { + /// Name of service extension that, when called, will determine whether + /// [FlutterError] messages will be presented using a structured format. + /// + /// See also: + /// + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + structuredErrors, + + /// Name of service extension that, when called, will change the value of + /// [WidgetsApp.debugShowWidgetInspectorOverride], which controls whether the + /// on-device widget inspector is visible. + /// + /// See also: + /// * [WidgetsApp.debugShowWidgetInspectorOverride], which is the flag that + /// this service extension exposes. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + show, + + /// Name of service extension that, when called, determines + /// whether a callback is invoked for every dirty [Widget] built each frame. + /// + /// See also: + /// + /// * [debugOnRebuildDirtyWidget], which is the nullable callback that is + /// called for every dirty widget built per frame + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + trackRebuildDirtyWidgets, + + /// Name of service extension that, when called, determines whether + /// a callback is invoked for every [RenderObject] painted each frame. + /// + /// See also: + /// + /// * [debugOnProfilePaint], which is the nullable callback that is called for + /// every dirty widget built per frame + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + trackRepaintWidgets, + + /// Name of service extension that, when called, will clear all + /// [WidgetInspectorService] object references in all groups. + /// + /// See also: + /// + /// * [WidgetInspectorService.disposeAllGroups], the method that this service + /// extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + disposeAllGroups, + + /// Name of service extension that, when called, will clear all + /// [WidgetInspectorService] object references in a group. + /// + /// See also: + /// + /// * [WidgetInspectorService.disposeGroup], the method that this service + /// extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + disposeGroup, + + /// Name of service extension that, when called, returns whether it is + /// appropriate to display the Widget tree in the inspector, which is only + /// true after the application has rendered its first frame. + /// + /// See also: + /// + /// * [WidgetInspectorService.isWidgetTreeReady], the method that this service + /// extension calls. + /// * [WidgetsBinding.debugDidSendFirstFrameEvent], which stores the + /// value of whether the first frame has been rendered. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + isWidgetTreeReady, + + /// Name of service extension that, when called, will remove the object with + /// the specified `id` from the specified object group. + /// + /// See also: + /// + /// * [WidgetInspectorService.disposeId], the method that this service + /// extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + disposeId, + + /// Name of service extension that, when called, will set the list of + /// directories that should be considered part of the local project for the + /// Widget inspector summary tree. + /// + /// See also: + /// + /// * [WidgetInspectorService.addPubRootDirectories], which should be used in + /// place of this method to add directories. + /// * [WidgetInspectorService.removePubRootDirectories], which should be used + /// in place of this method to remove directories. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + @Deprecated( + 'Use addPubRootDirectories instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + setPubRootDirectories, + + /// Name of service extension that, when called, will add a list of + /// directories that should be considered part of the local project for the + /// Widget inspector summary tree. + /// + /// See also: + /// + /// * [WidgetInspectorService.addPubRootDirectories], the method that this + /// service extension calls. + /// * [WidgetInspectorService.removePubRootDirectories], which should be used + /// to remove directories. + /// * [WidgetInspectorService.pubRootDirectories], which should be used + /// to return the active list of directories. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + addPubRootDirectories, + + /// Name of service extension that, when called, will remove a list of + /// directories that should no longer be considered part of the local project + /// for the Widget inspector summary tree. + /// + /// See also: + /// + /// * [WidgetInspectorService.removePubRootDirectories], the method that this + /// service extension calls. + /// * [WidgetInspectorService.addPubRootDirectories], which should be used + /// to add directories. + /// * [WidgetInspectorService.pubRootDirectories], which should be used + /// to return the active list of directories. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + removePubRootDirectories, + + /// Name of service extension that, when called, will return the list of + /// directories that are considered part of the local project + /// for the Widget inspector summary tree. + /// + /// See also: + /// + /// * [WidgetInspectorService.pubRootDirectories], the method that this + /// service extension calls. + /// * [WidgetInspectorService.addPubRootDirectories], which should be used + /// to add directories. + /// * [WidgetInspectorService.removePubRootDirectories], which should be used + /// to remove directories. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getPubRootDirectories, + + /// Name of service extension that, when called, will set the + /// [WidgetInspector] selection to the object matching the specified id and + /// will return whether the selection was changed. + /// + /// See also: + /// + /// * [WidgetInspectorService.setSelectionById], the method that this service + /// extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + setSelectionById, + + /// Name of service extension that, when called, will retrieve the chain of + /// [DiagnosticsNode] instances form the root of the tree to the [Element] or + /// [RenderObject] matching the specified id, passed as an argument. + /// + /// See also: + /// + /// * [WidgetInspectorService.getParentChain], which returns a json encoded + /// String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getParentChain, + + /// Name of service extension that, when called, will return the properties + /// for the [DiagnosticsNode] object matching the specified id, passed as an + /// argument. + /// + /// See also: + /// + /// * [WidgetInspectorService.getProperties], which returns a json encoded + /// String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getProperties, + + /// Name of service extension that, when called, will return the children + /// for the [DiagnosticsNode] object matching the specified id, passed as an + /// argument. + /// + /// See also: + /// + /// * [WidgetInspectorService.getChildren], which returns a json encoded + /// String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getChildren, + + /// Name of service extension that, when called, will return the children + /// created by user code for the [DiagnosticsNode] object matching the + /// specified id, passed as an argument. + /// + /// See also: + /// + /// * [WidgetInspectorService.getChildrenSummaryTree], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getChildrenSummaryTree, + + /// Name of service extension that, when called, will return all children and + /// their properties for the [DiagnosticsNode] object matching the specified + /// id, passed as an argument. + /// + /// See also: + /// + /// * [WidgetInspectorService.getChildrenDetailsSubtree], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getChildrenDetailsSubtree, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the root [Element]. + /// + /// See also: + /// + /// * [WidgetInspectorService.getRootWidget], which returns a json encoded + /// String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getRootWidget, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the root [Element] of the summary tree, which + /// only includes [Element]s that were created by user code. + /// + /// See also: + /// + /// * [WidgetInspectorService.getRootWidgetSummaryTree], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getRootWidgetSummaryTree, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the root [Element] of the summary tree with + /// text previews included. + /// + /// The summary tree only includes [Element]s that were created by user code. + /// Text previews will only be available for [Element]s with a corresponding + /// [RenderObject] of type [RenderParagraph]. + /// + /// See also: + /// + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getRootWidgetSummaryTreeWithPreviews, + + /// Name of service extension that, when called, will return the details + /// subtree, which includes properties, rooted at the [DiagnosticsNode] object + /// matching the specified id and the having a size matching the specified + /// subtree depth, both passed as arguments. + /// + /// See also: + /// + /// * [WidgetInspectorService.getDetailsSubtree], the method that this service + /// extension calls. + /// * [WidgetInspectorService.getDetailsSubtree], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getDetailsSubtree, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the currently selected [Element]. + /// + /// See also: + /// + /// * [WidgetInspectorService.getSelectedWidget], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getSelectedWidget, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the currently selected [Element] in the summary + /// tree, which only includes [Element]s created in user code. + /// + /// If the selected [Element] does not exist in the summary tree, the first + /// ancestor in the summary tree for the currently selected [Element] will be + /// returned. + /// + /// See also: + /// + /// * [WidgetInspectorService.getSelectedSummaryWidget], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getSelectedSummaryWidget, + + /// Name of service extension that, when called, will return whether [Widget] + /// creation locations are available. + /// + /// See also: + /// + /// * [WidgetInspectorService.isWidgetCreationTracked], the method that this + /// service extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + isWidgetCreationTracked, + + /// Name of service extension that, when called, will return a base64 encoded + /// image of the [RenderObject] or [Element] matching the specified 'id`, + /// passed as an argument, and sized at the specified 'width' and 'height' + /// values, also passed as arguments. + /// + /// See also: + /// + /// * [WidgetInspectorService.screenshot], the method that this service + /// extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + screenshot, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the currently selected [Element] and will + /// include information about the [Element]'s layout properties. + /// + /// See also: + /// + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getLayoutExplorerNode, + + /// Name of service extension that, when called, will set the [FlexFit] value + /// for the [FlexParentData] of the [RenderObject] matching the specified + /// `id`, passed as an argument. + /// + /// See also: + /// + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + setFlexFit, + + /// Name of service extension that, when called, will set the flex value + /// for the [FlexParentData] of the [RenderObject] matching the specified + /// `id`, passed as an argument. + /// + /// See also: + /// + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + setFlexFactor, + + /// Name of service extension that, when called, will set the + /// [MainAxisAlignment] and [CrossAxisAlignment] values for the [RenderFlex] + /// matching the specified `id`, passed as an argument. + /// + /// The [MainAxisAlignment] and [CrossAxisAlignment] values will be passed as + /// arguments `mainAxisAlignment` and `crossAxisAlignment`, respectively. + /// + /// See also: + /// + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + setFlexProperties, +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/shared_app_data.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/shared_app_data.dart new file mode 100644 index 0000000000000000000000000000000000000000..b9e4a6911c4655271e5aeb2a03cfc87583aead88 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/shared_app_data.dart @@ -0,0 +1,199 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +import 'framework.dart'; +import 'inherited_model.dart'; + +/// The type of the [SharedAppData.getValue] `init` parameter. +/// +/// This callback is used to lazily create the initial value for +/// a [SharedAppData] keyword. +typedef SharedAppDataInitCallback<T> = T Function(); + +/// Enables sharing key/value data with its `child` and all of the +/// child's descendants. +/// +/// - `SharedAppData.getValue(context, key, initCallback)` creates a dependency +/// on the key and returns the value for the key from the shared data table. +/// If no value exists for key then the initCallback is used to create +/// the initial value. +/// +/// - `SharedAppData.setValue(context, key, value)` changes the value of an entry +/// in the shared data table and forces widgets that depend on that entry +/// to be rebuilt. +/// +/// A widget whose build method uses SharedAppData.getValue(context, +/// keyword, initCallback) creates a dependency on the SharedAppData. When +/// the value of keyword changes with SharedAppData.setValue(), the widget +/// will be rebuilt. The values managed by the SharedAppData are expected +/// to be immutable: intrinsic changes to values will not cause +/// dependent widgets to be rebuilt. +/// +/// An instance of this widget is created automatically by [WidgetsApp]. +/// +/// There are many ways to share data with a widget subtree. This +/// class is based on [InheritedModel], which is an [InheritedWidget]. +/// It's intended to be used by packages that need to share a modest +/// number of values among their own components. +/// +/// SharedAppData is not intended to be a substitute for Provider or any of +/// the other general purpose application state systems. SharedAppData is +/// for situations where a package's custom widgets need to share one +/// or a handful of immutable data objects that can be lazily +/// initialized. It exists so that packages like that can deliver +/// custom widgets without requiring the developer to add a +/// package-specific umbrella widget to their application. +/// +/// A good way to create an SharedAppData key that avoids potential +/// collisions with other packages is to use a static `Object()` value. +/// The `SharedObject` example below does this. +/// +/// {@tool dartpad} +/// The following sample demonstrates using the automatically created +/// [SharedAppData]. Button presses cause changes to the values for keys +/// 'foo', and 'bar', and those changes only cause the widgets that +/// depend on those keys to be rebuilt. +/// +/// ** See code in examples/api/lib/widgets/shared_app_data/shared_app_data.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// The following sample demonstrates how a single lazily computed +/// value could be shared within an app. A Flutter package that +/// provided custom widgets might use this approach to share a (possibly +/// private) value with instances of those widgets. +/// +/// ** See code in examples/api/lib/widgets/shared_app_data/shared_app_data.1.dart ** +/// {@end-tool} +class SharedAppData extends StatefulWidget { + /// Creates a widget based on [InheritedModel] that supports build + /// dependencies qualified by keywords. Descendant widgets create + /// such dependencies with [SharedAppData.getValue] and they trigger + /// rebuilds with [SharedAppData.setValue]. + /// + /// This widget is automatically created by the [WidgetsApp]. + const SharedAppData({ super.key, required this.child }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + State<StatefulWidget> createState() => _SharedAppDataState(); + + /// Returns the app model's value for `key` and ensures that each + /// time the value of `key` is changed with [SharedAppData.setValue], the + /// specified context will be rebuilt. + /// + /// If no value for `key` exists then the `init` callback is used to + /// generate an initial value. The callback is expected to return + /// an immutable value because intrinsic changes to the value will + /// not cause dependent widgets to be rebuilt. + /// + /// A widget that depends on the app model's value for `key` should use + /// this method in their `build` methods to ensure that they are rebuilt + /// if the value changes. + /// + /// The type parameter `K` is the type of the keyword and `V` + /// is the type of the value. + static V getValue<K extends Object, V>(BuildContext context, K key, SharedAppDataInitCallback<V> init) { + final _SharedAppModel? model = InheritedModel.inheritFrom<_SharedAppModel>(context, aspect: key); + assert(_debugHasSharedAppData(model, context, 'getValue')); + return model!.sharedAppDataState.getValue<K, V>(key, init); + } + + /// Changes the app model's `value` for `key` and rebuilds any widgets + /// that have created a dependency on `key` with [SharedAppData.getValue]. + /// + /// If `value` is `==` to the current value of `key` then nothing + /// is rebuilt. + /// + /// The `value` is expected to be immutable because intrinsic + /// changes to the value will not cause dependent widgets to be + /// rebuilt. + /// + /// Unlike [SharedAppData.getValue], this method does _not_ create a dependency + /// between `context` and `key`. + /// + /// The type parameter `K` is the type of the value's keyword and `V` + /// is the type of the value. + static void setValue<K extends Object, V>(BuildContext context, K key, V value) { + final _SharedAppModel? model = context.getInheritedWidgetOfExactType<_SharedAppModel>(); + assert(_debugHasSharedAppData(model, context, 'setValue')); + model!.sharedAppDataState.setValue<K, V>(key, value); + } + + static bool _debugHasSharedAppData(_SharedAppModel? model, BuildContext context, String methodName) { + assert(() { + if (model == null) { + throw FlutterError.fromParts( + <DiagnosticsNode>[ + ErrorSummary('No SharedAppData widget found.'), + ErrorDescription('SharedAppData.$methodName requires an SharedAppData widget ancestor.\n'), + context.describeWidget('The specific widget that could not find an SharedAppData ancestor was'), + context.describeOwnershipChain('The ownership chain for the affected widget is'), + ErrorHint( + 'Typically, the SharedAppData widget is introduced by the MaterialApp ' + 'or WidgetsApp widget at the top of your application widget tree. It ' + 'provides a key/value map of data that is shared with the entire ' + 'application.', + ), + ], + ); + } + return true; + }()); + return true; + } +} + +class _SharedAppDataState extends State<SharedAppData> { + late Map<Object, Object?> data = <Object, Object?>{}; + + @override + Widget build(BuildContext context) { + return _SharedAppModel(sharedAppDataState: this, child: widget.child); + } + + V getValue<K extends Object, V>(K key, SharedAppDataInitCallback<V> init) { + data[key] ??= init(); + return data[key] as V; + } + + void setValue<K extends Object, V>(K key, V value) { + if (data[key] != value) { + setState(() { + data = Map<Object, Object?>.of(data); + data[key] = value; + }); + } + } +} + +class _SharedAppModel extends InheritedModel<Object> { + _SharedAppModel({ + required this.sharedAppDataState, + required super.child + }) : data = sharedAppDataState.data; + + final _SharedAppDataState sharedAppDataState; + final Map<Object, Object?> data; + + @override + bool updateShouldNotify(_SharedAppModel old) { + return data != old.data; + } + + @override + bool updateShouldNotifyDependent(_SharedAppModel old, Set<Object> keys) { + for (final Object key in keys) { + if (data[key] != old.data[key]) { + return true; + } + } + return false; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/shortcuts.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/shortcuts.dart new file mode 100644 index 0000000000000000000000000000000000000000..06601b44fc73679661dd74f61f7ad6c041903b36 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/shortcuts.dart @@ -0,0 +1,1498 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'actions.dart'; +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; +import 'platform_menu_bar.dart'; + +final Set<LogicalKeyboardKey> _controlSynonyms = LogicalKeyboardKey.expandSynonyms(<LogicalKeyboardKey>{LogicalKeyboardKey.control}); +final Set<LogicalKeyboardKey> _shiftSynonyms = LogicalKeyboardKey.expandSynonyms(<LogicalKeyboardKey>{LogicalKeyboardKey.shift}); +final Set<LogicalKeyboardKey> _altSynonyms = LogicalKeyboardKey.expandSynonyms(<LogicalKeyboardKey>{LogicalKeyboardKey.alt}); +final Set<LogicalKeyboardKey> _metaSynonyms = LogicalKeyboardKey.expandSynonyms(<LogicalKeyboardKey>{LogicalKeyboardKey.meta}); + +/// A set of [KeyboardKey]s that can be used as the keys in a [Map]. +/// +/// A key set contains the keys that are down simultaneously to represent a +/// shortcut. +/// +/// This is a thin wrapper around a [Set], but changes the equality comparison +/// from an identity comparison to a contents comparison so that non-identical +/// sets with the same keys in them will compare as equal. +/// +/// See also: +/// +/// * [ShortcutManager], which uses [LogicalKeySet] (a [KeySet] subclass) to +/// define its key map. +@immutable +class KeySet<T extends KeyboardKey> { + /// A constructor for making a [KeySet] of up to four keys. + /// + /// If you need a set of more than four keys, use [KeySet.fromSet]. + /// + /// The same [KeyboardKey] may not be appear more than once in the set. + KeySet( + T key1, [ + T? key2, + T? key3, + T? key4, + ]) : _keys = HashSet<T>()..add(key1) { + int count = 1; + if (key2 != null) { + _keys.add(key2); + assert(() { + count++; + return true; + }()); + } + if (key3 != null) { + _keys.add(key3); + assert(() { + count++; + return true; + }()); + } + if (key4 != null) { + _keys.add(key4); + assert(() { + count++; + return true; + }()); + } + assert(_keys.length == count, 'Two or more provided keys are identical. Each key must appear only once.'); + } + + /// Create a [KeySet] from a set of [KeyboardKey]s. + /// + /// Do not mutate the `keys` set after passing it to this object. + /// + /// The `keys` set must not be empty. + KeySet.fromSet(Set<T> keys) + : assert(keys.isNotEmpty), + assert(!keys.contains(null)), + _keys = HashSet<T>.of(keys); + + /// Returns a copy of the [KeyboardKey]s in this [KeySet]. + Set<T> get keys => _keys.toSet(); + final HashSet<T> _keys; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is KeySet<T> + && setEquals<T>(other._keys, _keys); + } + + // Cached hash code value. Improves [hashCode] performance by 27%-900%, + // depending on key set size and read/write ratio. + @override + late final int hashCode = _computeHashCode(_keys); + + // Arrays used to temporarily store hash codes for sorting. + static final List<int> _tempHashStore3 = <int>[0, 0, 0]; // used to sort exactly 3 keys + static final List<int> _tempHashStore4 = <int>[0, 0, 0, 0]; // used to sort exactly 4 keys + static int _computeHashCode<T>(Set<T> keys) { + // Compute order-independent hash and cache it. + final int length = keys.length; + final Iterator<T> iterator = keys.iterator; + + // There's always at least one key. Just extract it. + iterator.moveNext(); + final int h1 = iterator.current.hashCode; + + if (length == 1) { + // Don't do anything fancy if there's exactly one key. + return h1; + } + + iterator.moveNext(); + final int h2 = iterator.current.hashCode; + if (length == 2) { + // No need to sort if there's two keys, just compare them. + return h1 < h2 + ? Object.hash(h1, h2) + : Object.hash(h2, h1); + } + + // Sort key hash codes and feed to Object.hashAll to ensure the aggregate + // hash code does not depend on the key order. + final List<int> sortedHashes = length == 3 + ? _tempHashStore3 + : _tempHashStore4; + sortedHashes[0] = h1; + sortedHashes[1] = h2; + iterator.moveNext(); + sortedHashes[2] = iterator.current.hashCode; + if (length == 4) { + iterator.moveNext(); + sortedHashes[3] = iterator.current.hashCode; + } + sortedHashes.sort(); + return Object.hashAll(sortedHashes); + } +} + +/// An interface to define the keyboard key combination to trigger a shortcut. +/// +/// [ShortcutActivator]s are used by [Shortcuts] widgets, and are mapped to +/// [Intent]s, the intended behavior that the key combination should trigger. +/// When a [Shortcuts] widget receives a key event, its [ShortcutManager] looks +/// up the first matching [ShortcutActivator], and signals the corresponding +/// [Intent], which might trigger an action as defined by a hierarchy of +/// [Actions] widgets. For a detailed introduction on the mechanism and use of +/// the shortcut-action system, see [Actions]. +/// +/// The matching [ShortcutActivator] is looked up in the following way: +/// +/// * Find the registered [ShortcutActivator]s whose [triggers] contain the +/// incoming event. +/// * Of the previous list, finds the first activator whose [accepts] returns +/// true in the order of insertion. +/// +/// See also: +/// +/// * [SingleActivator], an implementation that represents a single key combined +/// with modifiers (control, shift, alt, meta). +/// * [CharacterActivator], an implementation that represents key combinations +/// that result in the specified character, such as question mark. +/// * [LogicalKeySet], an implementation that requires one or more +/// [LogicalKeyboardKey]s to be pressed at the same time. Prefer +/// [SingleActivator] when possible. +abstract class ShortcutActivator { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const ShortcutActivator(); + + /// An optional property to provide all the keys that might be the final event + /// to trigger this shortcut. + /// + /// For example, for `Ctrl-A`, [LogicalKeyboardKey.keyA] is the only trigger, + /// while [LogicalKeyboardKey.control] is not, because the shortcut should + /// only work by pressing KeyA *after* Ctrl, but not before. For `Ctrl-A-E`, + /// on the other hand, both KeyA and KeyE should be triggers, since either of + /// them is allowed to trigger. + /// + /// If provided, trigger keys can be used as a first-pass filter for incoming + /// events in order to optimize lookups, as [Intent]s are stored in a [Map] + /// and indexed by trigger keys. It is up to the individual implementors of + /// this interface to decide if they ignore triggers or not. + /// + /// Subclasses should make sure that the return value of this method does not + /// change throughout the lifespan of this object. + /// + /// This method might also return null, which means this activator declares + /// all keys as trigger keys. Activators whose [triggers] return null will be + /// tested with [accepts] on every event. Since this becomes a linear search, + /// and having too many might impact performance, it is preferred to return + /// non-null [triggers] whenever possible. + Iterable<LogicalKeyboardKey>? get triggers => null; + + /// Whether the triggering `event` and the keyboard `state` at the time of the + /// event meet required conditions, providing that the event is a triggering + /// event. + /// + /// For example, for `Ctrl-A`, it has to check if the event is a + /// [KeyDownEvent], if either side of the Ctrl key is pressed, and none of the + /// Shift keys, Alt keys, or Meta keys are pressed; it doesn't have to check + /// if KeyA is pressed, since it's already guaranteed. + /// + /// As a possible performance improvement, implementers of this function are + /// encouraged (but not required) to check the [triggers] member, if it is + /// non-null, to see if it contains the event's logical key before doing more + /// complicated work. + /// + /// This method must not cause any side effects for the `state`. Typically + /// this is only used to query whether [HardwareKeyboard.logicalKeysPressed] + /// contains a key. + /// + /// See also: + /// + /// * [LogicalKeyboardKey.collapseSynonyms], which helps deciding whether a + /// modifier key is pressed when the side variation is not important. + bool accepts(KeyEvent event, HardwareKeyboard state); + + /// Returns true if the event and current [HardwareKeyboard] state would cause + /// this [ShortcutActivator] to be activated. + @Deprecated( + 'Call accepts on the activator instead. ' + 'This feature was deprecated after v3.16.0-15.0.pre.', + ) + static bool isActivatedBy(ShortcutActivator activator, KeyEvent event) { + return activator.accepts(event, HardwareKeyboard.instance); + } + + /// Returns a description of the key set that is short and readable. + /// + /// Intended to be used in debug mode for logging purposes. + String debugDescribeKeys(); +} + +/// A set of [LogicalKeyboardKey]s that can be used as the keys in a map. +/// +/// [LogicalKeySet] can be used as a [ShortcutActivator]. It is not recommended +/// to use [LogicalKeySet] for a common shortcut such as `Delete` or `Ctrl+C`, +/// prefer [SingleActivator] when possible, whose behavior more closely resembles +/// that of typical platforms. +/// +/// When used as a [ShortcutActivator], [LogicalKeySet] will activate the intent +/// when all [keys] are pressed, and no others, except that modifier keys are +/// considered without considering sides (e.g. control left and control right are +/// considered the same). +/// +/// {@tool dartpad} +/// In the following example, the counter is increased when the following key +/// sequences are pressed: +/// +/// * Control left, then C. +/// * Control right, then C. +/// * C, then Control left. +/// +/// But not when: +/// +/// * Control left, then A, then C. +/// +/// ** See code in examples/api/lib/widgets/shortcuts/logical_key_set.0.dart ** +/// {@end-tool} +/// +/// This is also a thin wrapper around a [Set], but changes the equality +/// comparison from an identity comparison to a contents comparison so that +/// non-identical sets with the same keys in them will compare as equal. + +class LogicalKeySet extends KeySet<LogicalKeyboardKey> with Diagnosticable + implements ShortcutActivator { + /// A constructor for making a [LogicalKeySet] of up to four keys. + /// + /// If you need a set of more than four keys, use [LogicalKeySet.fromSet]. + /// + /// The same [LogicalKeyboardKey] may not be appear more than once in the set. + LogicalKeySet( + super.key1, [ + super.key2, + super.key3, + super.key4, + ]); + + /// Create a [LogicalKeySet] from a set of [LogicalKeyboardKey]s. + /// + /// Do not mutate the `keys` set after passing it to this object. + LogicalKeySet.fromSet(super.keys) : super.fromSet(); + + @override + Iterable<LogicalKeyboardKey> get triggers => _triggers; + late final Set<LogicalKeyboardKey> _triggers = keys.expand( + (LogicalKeyboardKey key) => _unmapSynonyms[key] ?? <LogicalKeyboardKey>[key], + ).toSet(); + + bool _checkKeyRequirements(Set<LogicalKeyboardKey> pressed) { + final Set<LogicalKeyboardKey> collapsedRequired = LogicalKeyboardKey.collapseSynonyms(keys); + final Set<LogicalKeyboardKey> collapsedPressed = LogicalKeyboardKey.collapseSynonyms(pressed); + return collapsedRequired.length == collapsedPressed.length + && collapsedRequired.difference(collapsedPressed).isEmpty; + } + + @override + bool accepts(KeyEvent event, HardwareKeyboard state) { + if (event is! KeyDownEvent && event is! KeyRepeatEvent) { + return false; + } + return triggers.contains(event.logicalKey) + && _checkKeyRequirements(state.logicalKeysPressed); + } + + static final Set<LogicalKeyboardKey> _modifiers = <LogicalKeyboardKey>{ + LogicalKeyboardKey.alt, + LogicalKeyboardKey.control, + LogicalKeyboardKey.meta, + LogicalKeyboardKey.shift, + }; + static final Map<LogicalKeyboardKey, List<LogicalKeyboardKey>> _unmapSynonyms = <LogicalKeyboardKey, List<LogicalKeyboardKey>>{ + LogicalKeyboardKey.control: <LogicalKeyboardKey>[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.controlRight], + LogicalKeyboardKey.shift: <LogicalKeyboardKey>[LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftRight], + LogicalKeyboardKey.alt: <LogicalKeyboardKey>[LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altRight], + LogicalKeyboardKey.meta: <LogicalKeyboardKey>[LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.metaRight], + }; + + @override + String debugDescribeKeys() { + final List<LogicalKeyboardKey> sortedKeys = keys.toList() + ..sort((LogicalKeyboardKey a, LogicalKeyboardKey b) { + // Put the modifiers first. If it has a synonym, then it's something + // like shiftLeft, altRight, etc. + final bool aIsModifier = a.synonyms.isNotEmpty || _modifiers.contains(a); + final bool bIsModifier = b.synonyms.isNotEmpty || _modifiers.contains(b); + if (aIsModifier && !bIsModifier) { + return -1; + } else if (bIsModifier && !aIsModifier) { + return 1; + } + return a.debugName!.compareTo(b.debugName!); + }); + return sortedKeys.map<String>((LogicalKeyboardKey key) => key.debugName.toString()).join(' + '); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Set<LogicalKeyboardKey>>('keys', _keys, description: debugDescribeKeys())); + } +} + +/// A [DiagnosticsProperty] which handles formatting a `Map<LogicalKeySet, Intent>` +/// (the same type as the [Shortcuts.shortcuts] property) so that its +/// diagnostic output is human-readable. +class ShortcutMapProperty extends DiagnosticsProperty<Map<ShortcutActivator, Intent>> { + /// Create a diagnostics property for `Map<ShortcutActivator, Intent>` objects, + /// which are the same type as the [Shortcuts.shortcuts] property. + ShortcutMapProperty( + String super.name, + Map<ShortcutActivator, Intent> super.value, { + super.showName, + Object super.defaultValue, + super.level, + super.description, + }); + + @override + Map<ShortcutActivator, Intent> get value => super.value!; + + @override + String valueToString({TextTreeConfiguration? parentConfiguration}) { + return '{${value.keys.map<String>((ShortcutActivator keySet) => '{${keySet.debugDescribeKeys()}}: ${value[keySet]}').join(', ')}}'; + } +} + +/// A shortcut key combination of a single key and modifiers. +/// +/// The [SingleActivator] implements typical shortcuts such as: +/// +/// * ArrowLeft +/// * Shift + Delete +/// * Control + Alt + Meta + Shift + A +/// +/// More specifically, it creates shortcut key combinations that are composed of a +/// [trigger] key, and zero, some, or all of the four modifiers (control, shift, +/// alt, meta). The shortcut is activated when the following conditions are met: +/// +/// * The incoming event is a down event for a [trigger] key. +/// * If [control] is true, then at least one control key must be held. +/// Otherwise, no control keys must be held. +/// * Similar conditions apply for the [alt], [shift], and [meta] keys. +/// +/// This resembles the typical behavior of most operating systems, and handles +/// modifier keys differently from [LogicalKeySet] in the following way: +/// +/// * [SingleActivator]s allow additional non-modifier keys being pressed in +/// order to activate the shortcut. For example, pressing key X while holding +/// ControlLeft *and key A* will be accepted by +/// `SingleActivator(LogicalKeyboardKey.keyX, control: true)`. +/// * [SingleActivator]s do not consider modifiers to be a trigger key. For +/// example, pressing ControlLeft while holding key X *will not* activate a +/// `SingleActivator(LogicalKeyboardKey.keyX, control: true)`. +/// +/// See also: +/// +/// * [CharacterActivator], an activator that represents key combinations +/// that result in the specified character, such as question mark. +class SingleActivator with Diagnosticable, MenuSerializableShortcut implements ShortcutActivator { + /// Triggered when the [trigger] key is pressed while the modifiers are held. + /// + /// The [trigger] should be the non-modifier key that is pressed after all the + /// modifiers, such as [LogicalKeyboardKey.keyC] as in `Ctrl+C`. It must not + /// be a modifier key (sided or unsided). + /// + /// The [control], [shift], [alt], and [meta] flags represent whether the + /// respective modifier keys should be held (true) or released (false). They + /// default to false. + /// + /// By default, the activator is checked on all [KeyDownEvent] events for the + /// [trigger] key. If [includeRepeats] is false, only [trigger] key events + /// which are not [KeyRepeatEvent]s will be considered. + /// + /// {@tool dartpad} + /// In the following example, the shortcut `Control + C` increases the + /// counter: + /// + /// ** See code in examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart ** + /// {@end-tool} + const SingleActivator( + this.trigger, { + this.control = false, + this.shift = false, + this.alt = false, + this.meta = false, + this.includeRepeats = true, + }) : // The enumerated check with `identical` is cumbersome but the only way + // since const constructors can not call functions such as `==` or + // `Set.contains`. Checking with `identical` might not work when the + // key object is created from ID, but it covers common cases. + assert( + !identical(trigger, LogicalKeyboardKey.control) && + !identical(trigger, LogicalKeyboardKey.controlLeft) && + !identical(trigger, LogicalKeyboardKey.controlRight) && + !identical(trigger, LogicalKeyboardKey.shift) && + !identical(trigger, LogicalKeyboardKey.shiftLeft) && + !identical(trigger, LogicalKeyboardKey.shiftRight) && + !identical(trigger, LogicalKeyboardKey.alt) && + !identical(trigger, LogicalKeyboardKey.altLeft) && + !identical(trigger, LogicalKeyboardKey.altRight) && + !identical(trigger, LogicalKeyboardKey.meta) && + !identical(trigger, LogicalKeyboardKey.metaLeft) && + !identical(trigger, LogicalKeyboardKey.metaRight), + ); + + /// The non-modifier key of the shortcut that is pressed after all modifiers + /// to activate the shortcut. + /// + /// For example, for `Control + C`, [trigger] should be + /// [LogicalKeyboardKey.keyC]. + final LogicalKeyboardKey trigger; + + /// Whether either (or both) control keys should be held for [trigger] to + /// activate the shortcut. + /// + /// It defaults to false, meaning all Control keys must be released when the + /// event is received in order to activate the shortcut. If it's true, then + /// either or both Control keys must be pressed. + /// + /// See also: + /// + /// * [LogicalKeyboardKey.controlLeft], [LogicalKeyboardKey.controlRight]. + final bool control; + + /// Whether either (or both) shift keys should be held for [trigger] to + /// activate the shortcut. + /// + /// It defaults to false, meaning all Shift keys must be released when the + /// event is received in order to activate the shortcut. If it's true, then + /// either or both Shift keys must be pressed. + /// + /// See also: + /// + /// * [LogicalKeyboardKey.shiftLeft], [LogicalKeyboardKey.shiftRight]. + final bool shift; + + /// Whether either (or both) alt keys should be held for [trigger] to + /// activate the shortcut. + /// + /// It defaults to false, meaning all Alt keys must be released when the + /// event is received in order to activate the shortcut. If it's true, then + /// either or both Alt keys must be pressed. + /// + /// See also: + /// + /// * [LogicalKeyboardKey.altLeft], [LogicalKeyboardKey.altRight]. + final bool alt; + + /// Whether either (or both) meta keys should be held for [trigger] to + /// activate the shortcut. + /// + /// It defaults to false, meaning all Meta keys must be released when the + /// event is received in order to activate the shortcut. If it's true, then + /// either or both Meta keys must be pressed. + /// + /// See also: + /// + /// * [LogicalKeyboardKey.metaLeft], [LogicalKeyboardKey.metaRight]. + final bool meta; + + /// Whether this activator accepts repeat events of the [trigger] key. + /// + /// If [includeRepeats] is true, the activator is checked on all + /// [KeyDownEvent] or [KeyRepeatEvent]s for the [trigger] key. If + /// [includeRepeats] is false, only [trigger] key events which are + /// [KeyDownEvent]s will be considered. + final bool includeRepeats; + + @override + Iterable<LogicalKeyboardKey> get triggers { + return <LogicalKeyboardKey>[trigger]; + } + + bool _shouldAcceptModifiers(Set<LogicalKeyboardKey> pressed) { + return control == pressed.intersection(_controlSynonyms).isNotEmpty + && shift == pressed.intersection(_shiftSynonyms).isNotEmpty + && alt == pressed.intersection(_altSynonyms).isNotEmpty + && meta == pressed.intersection(_metaSynonyms).isNotEmpty; + } + + @override + bool accepts(KeyEvent event, HardwareKeyboard state) { + return (event is KeyDownEvent || (includeRepeats && event is KeyRepeatEvent)) + && triggers.contains(event.logicalKey) + && _shouldAcceptModifiers(state.logicalKeysPressed); + } + + @override + ShortcutSerialization serializeForMenu() { + return ShortcutSerialization.modifier( + trigger, + shift: shift, + alt: alt, + meta: meta, + control: control, + ); + } + + /// Returns a short and readable description of the key combination. + /// + /// Intended to be used in debug mode for logging purposes. In release mode, + /// [debugDescribeKeys] returns an empty string. + @override + String debugDescribeKeys() { + String result = ''; + assert(() { + final List<String> keys = <String>[ + if (control) 'Control', + if (alt) 'Alt', + if (meta) 'Meta', + if (shift) 'Shift', + trigger.debugName ?? trigger.toStringShort(), + ]; + result = keys.join(' + '); + return true; + }()); + return result; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(MessageProperty('keys', debugDescribeKeys())); + properties.add(FlagProperty('includeRepeats', value: includeRepeats, ifFalse: 'excluding repeats')); + } +} + +/// A shortcut combination that is triggered by a key event that produces a +/// specific character. +/// +/// Keys often produce different characters when combined with modifiers. For +/// example, it might be helpful for the user to bring up a help menu by +/// pressing the question mark ('?'). However, there is no logical key that +/// directly represents a question mark. Although 'Shift+Slash' produces a '?' +/// character on a US keyboard, its logical key is still considered a Slash key, +/// and hard-coding 'Shift+Slash' in this situation is unfriendly to other +/// keyboard layouts. +/// +/// For example, `CharacterActivator('?')` is triggered when a key combination +/// results in a question mark, which is 'Shift+Slash' on a US keyboard, but +/// 'Shift+Comma' on a French keyboard. +/// +/// {@tool dartpad} +/// In the following example, when a key combination results in a question mark, +/// the counter is increased: +/// +/// ** See code in examples/api/lib/widgets/shortcuts/character_activator.0.dart ** +/// {@end-tool} +/// +/// The [alt], [control], and [meta] flags represent whether the respective +/// modifier keys should be held (true) or released (false). They default to +/// false. [CharacterActivator] cannot check shifted keys, since the Shift key +/// affects the resulting character, and will accept whether either of the +/// Shift keys are pressed or not, as long as the key event produces the +/// correct character. +/// +/// By default, the activator is checked on all [KeyDownEvent] or +/// [KeyRepeatEvent]s for the [character] in combination with the requested +/// modifier keys. If `includeRepeats` is false, only the [character] events +/// with that are [KeyDownEvent]s will be considered. +/// +/// {@template flutter.widgets.shortcuts.CharacterActivator.alt} +/// On macOS and iOS, the [alt] flag indicates that the Option key (⌥) is +/// pressed. Because the Option key affects the character generated on these +/// platforms, it can be unintuitive to define [CharacterActivator]s for them. +/// +/// For instance, if you want the shortcut to trigger when Option+s (⌥-s) is +/// pressed, and what you intend is to trigger whenever the character 'ß' is +/// produced, you would use `CharacterActivator('ß')` or +/// `CharacterActivator('ß', alt: true)` instead of `CharacterActivator('s', +/// alt: true)`. This is because `CharacterActivator('s', alt: true)` will +/// never trigger, since the 's' character can't be produced when the Option +/// key is held down. +/// +/// If what is intended is that the shortcut is triggered when Option+s (⌥-s) +/// is pressed, regardless of which character is produced, it is better to use +/// [SingleActivator], as in `SingleActivator(LogicalKeyboardKey.keyS, alt: +/// true)`. +/// {@endtemplate} +/// +/// See also: +/// +/// * [SingleActivator], an activator that represents a single key combined +/// with modifiers, such as `Ctrl+C` or `Ctrl-Right Arrow`. +class CharacterActivator with Diagnosticable, MenuSerializableShortcut implements ShortcutActivator { + /// Triggered when the key event yields the given character. + const CharacterActivator(this.character, { + this.alt = false, + this.control = false, + this.meta = false, + this.includeRepeats = true, + }); + + /// Whether either (or both) Alt keys should be held for the [character] to + /// activate the shortcut. + /// + /// It defaults to false, meaning all Alt keys must be released when the event + /// is received in order to activate the shortcut. If it's true, then either + /// one or both Alt keys must be pressed. + /// + /// {@macro flutter.widgets.shortcuts.CharacterActivator.alt} + /// + /// See also: + /// + /// * [LogicalKeyboardKey.altLeft], [LogicalKeyboardKey.altRight]. + final bool alt; + + /// Whether either (or both) Control keys should be held for the [character] + /// to activate the shortcut. + /// + /// It defaults to false, meaning all Control keys must be released when the + /// event is received in order to activate the shortcut. If it's true, then + /// either one or both Control keys must be pressed. + /// + /// See also: + /// + /// * [LogicalKeyboardKey.controlLeft], [LogicalKeyboardKey.controlRight]. + final bool control; + + /// Whether either (or both) Meta keys should be held for the [character] to + /// activate the shortcut. + /// + /// It defaults to false, meaning all Meta keys must be released when the + /// event is received in order to activate the shortcut. If it's true, then + /// either one or both Meta keys must be pressed. + /// + /// See also: + /// + /// * [LogicalKeyboardKey.metaLeft], [LogicalKeyboardKey.metaRight]. + final bool meta; + + /// Whether this activator accepts repeat events of the [character]. + /// + /// If [includeRepeats] is true, the activator is checked on all + /// [KeyDownEvent] and [KeyRepeatEvent]s for the [character]. If + /// [includeRepeats] is false, only the [character] events that are + /// [KeyDownEvent]s will be considered. + final bool includeRepeats; + + /// The character which triggers the shortcut. + /// + /// This is typically a single-character string, such as '?' or 'œ', although + /// [CharacterActivator] doesn't check the length of [character] or whether it + /// can be matched by any key combination at all. It is case-sensitive, since + /// the [character] is directly compared by `==` to the character reported by + /// the platform. + /// + /// See also: + /// + /// * [KeyEvent.character], the character of a key event. + final String character; + + @override + Iterable<LogicalKeyboardKey>? get triggers => null; + + bool _shouldAcceptModifiers(Set<LogicalKeyboardKey> pressed) { + // Doesn't look for shift, since the character will encode that. + return control == pressed.intersection(_controlSynonyms).isNotEmpty + && alt == pressed.intersection(_altSynonyms).isNotEmpty + && meta == pressed.intersection(_metaSynonyms).isNotEmpty; + } + + @override + bool accepts(KeyEvent event, HardwareKeyboard state) { + // Ignore triggers, since we're only interested in the character. + return event.character == character + && (event is KeyDownEvent || (includeRepeats && event is KeyRepeatEvent)) + && _shouldAcceptModifiers(state.logicalKeysPressed); + } + + @override + String debugDescribeKeys() { + String result = ''; + assert(() { + final List<String> keys = <String>[ + if (alt) 'Alt', + if (control) 'Control', + if (meta) 'Meta', + "'$character'", + ]; + result = keys.join(' + '); + return true; + }()); + return result; + } + + @override + ShortcutSerialization serializeForMenu() { + return ShortcutSerialization.character(character, alt: alt, control: control, meta: meta); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(MessageProperty('character', debugDescribeKeys())); + properties.add(FlagProperty('includeRepeats', value: includeRepeats, ifFalse: 'excluding repeats')); + } +} + +class _ActivatorIntentPair with Diagnosticable { + const _ActivatorIntentPair(this.activator, this.intent); + final ShortcutActivator activator; + final Intent intent; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String>('activator', activator.debugDescribeKeys())); + properties.add(DiagnosticsProperty<Intent>('intent', intent)); + } +} + +/// A manager of keyboard shortcut bindings used by [Shortcuts] to handle key +/// events. +/// +/// The manager may be listened to (with [addListener]/[removeListener]) for +/// change notifications when the shortcuts change. +/// +/// Typically, a [Shortcuts] widget supplies its own manager, but in uncommon +/// cases where overriding the usual shortcut manager behavior is desired, a +/// subclassed [ShortcutManager] may be supplied. +class ShortcutManager with Diagnosticable, ChangeNotifier { + /// Constructs a [ShortcutManager]. + ShortcutManager({ + Map<ShortcutActivator, Intent> shortcuts = const <ShortcutActivator, Intent>{}, + this.modal = false, + }) : _shortcuts = shortcuts { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + /// True if the [ShortcutManager] should not pass on keys that it doesn't + /// handle to any key-handling widgets that are ancestors to this one. + /// + /// Setting [modal] to true will prevent any key event given to this manager + /// from being given to any ancestor managers, even if that key doesn't appear + /// in the [shortcuts] map. + /// + /// The net effect of setting [modal] to true is to return + /// [KeyEventResult.skipRemainingHandlers] from [handleKeypress] if it does + /// not exist in the shortcut map, instead of returning + /// [KeyEventResult.ignored]. + final bool modal; + + /// Returns the shortcut map. + /// + /// When the map is changed, listeners to this manager will be notified. + /// + /// The returned map should not be modified. + Map<ShortcutActivator, Intent> get shortcuts => _shortcuts; + Map<ShortcutActivator, Intent> _shortcuts = <ShortcutActivator, Intent>{}; + set shortcuts(Map<ShortcutActivator, Intent> value) { + if (!mapEquals<ShortcutActivator, Intent>(_shortcuts, value)) { + _shortcuts = value; + _indexedShortcutsCache = null; + notifyListeners(); + } + } + + static Map<LogicalKeyboardKey?, List<_ActivatorIntentPair>> _indexShortcuts(Map<ShortcutActivator, Intent> source) { + final Map<LogicalKeyboardKey?, List<_ActivatorIntentPair>> result = <LogicalKeyboardKey?, List<_ActivatorIntentPair>>{}; + source.forEach((ShortcutActivator activator, Intent intent) { + // This intermediate variable is necessary to comply with Dart analyzer. + final Iterable<LogicalKeyboardKey?>? nullableTriggers = activator.triggers; + for (final LogicalKeyboardKey? trigger in nullableTriggers ?? <LogicalKeyboardKey?>[null]) { + result.putIfAbsent(trigger, () => <_ActivatorIntentPair>[]) + .add(_ActivatorIntentPair(activator, intent)); + } + }); + return result; + } + + Map<LogicalKeyboardKey?, List<_ActivatorIntentPair>> get _indexedShortcuts { + return _indexedShortcutsCache ??= _indexShortcuts(shortcuts); + } + + Map<LogicalKeyboardKey?, List<_ActivatorIntentPair>>? _indexedShortcutsCache; + + Iterable<_ActivatorIntentPair> _getCandidates(LogicalKeyboardKey key) { + return <_ActivatorIntentPair>[ + ... _indexedShortcuts[key] ?? <_ActivatorIntentPair>[], + ... _indexedShortcuts[null] ?? <_ActivatorIntentPair>[], + ]; + } + + /// Returns the [Intent], if any, that matches the current set of pressed + /// keys. + /// + /// Returns null if no intent matches the current set of pressed keys. + Intent? _find(KeyEvent event, HardwareKeyboard state) { + for (final _ActivatorIntentPair activatorIntent in _getCandidates(event.logicalKey)) { + if (activatorIntent.activator.accepts(event, state)) { + return activatorIntent.intent; + } + } + return null; + } + + /// Handles a key press `event` in the given `context`. + /// + /// If a key mapping is found, then the associated action will be invoked + /// using the [Intent] activated by the [ShortcutActivator] in the [shortcuts] + /// map, and the currently focused widget's context (from + /// [FocusManager.primaryFocus]). + /// + /// Returns a [KeyEventResult.handled] if an action was invoked, otherwise a + /// [KeyEventResult.skipRemainingHandlers] if [modal] is true, or if it maps + /// to a [DoNothingAction] with [DoNothingAction.consumesKey] set to false, + /// and in all other cases returns [KeyEventResult.ignored]. + /// + /// In order for an action to be invoked (and [KeyEventResult.handled] + /// returned), a [ShortcutActivator] must accept the given [KeyEvent], be + /// mapped to an [Intent], the [Intent] must be mapped to an [Action], and the + /// [Action] must be enabled. + @protected + KeyEventResult handleKeypress(BuildContext context, KeyEvent event) { + final Intent? matchedIntent = _find(event, HardwareKeyboard.instance); + if (matchedIntent != null) { + final BuildContext? primaryContext = primaryFocus?.context; + if (primaryContext != null) { + final Action<Intent>? action = Actions.maybeFind<Intent>( + primaryContext, + intent: matchedIntent, + ); + if (action != null) { + final (bool enabled, Object? invokeResult) = Actions.of(primaryContext).invokeActionIfEnabled( + action, matchedIntent, primaryContext, + ); + if (enabled) { + return action.toKeyEventResult(matchedIntent, invokeResult); + } + } + } + } + return modal ? KeyEventResult.skipRemainingHandlers : KeyEventResult.ignored; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Map<ShortcutActivator, Intent>>('shortcuts', shortcuts)); + properties.add(FlagProperty('modal', value: modal, ifTrue: 'modal', defaultValue: false)); + } +} + +/// A widget that creates key bindings to specific actions for its +/// descendants. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=6ZcQmdoz9N8} +/// +/// This widget establishes a [ShortcutManager] to be used by its descendants +/// when invoking an [Action] via a keyboard key combination that maps to an +/// [Intent]. +/// +/// This is similar to but more powerful than the [CallbackShortcuts] widget. +/// Unlike [CallbackShortcuts], this widget separates key bindings and their +/// implementations. This separation allows [Shortcuts] to have key bindings +/// that adapt to the focused context. For example, the desired action for a +/// deletion intent may be to delete a character in a text input, or to delete +/// a file in a file menu. +/// +/// See the article on [Using Actions and +/// Shortcuts](https://docs.flutter.dev/development/ui/advanced/actions_and_shortcuts) +/// for a detailed explanation. +/// +/// {@tool dartpad} +/// Here, we will use the [Shortcuts] and [Actions] widgets to add and subtract +/// from a counter. When the child widget has keyboard focus, and a user presses +/// the keys that have been defined in [Shortcuts], the action that is bound +/// to the appropriate [Intent] for the key is invoked. +/// +/// It also shows the use of a [CallbackAction] to avoid creating a new [Action] +/// subclass. +/// +/// ** See code in examples/api/lib/widgets/shortcuts/shortcuts.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This slightly more complicated, but more flexible, example creates a custom +/// [Action] subclass to increment and decrement within a widget (a [Column]) +/// that has keyboard focus. When the user presses the up and down arrow keys, +/// the counter will increment and decrement a data model using the custom +/// actions. +/// +/// One thing that this demonstrates is passing arguments to the [Intent] to be +/// carried to the [Action]. This shows how actions can get data either from +/// their own construction (like the `model` in this example), or from the +/// intent passed to them when invoked (like the increment `amount` in this +/// example). +/// +/// ** See code in examples/api/lib/widgets/shortcuts/shortcuts.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [CallbackShortcuts], a simpler but less flexible widget that defines key +/// bindings that invoke callbacks. +/// * [Intent], a class for containing a description of a user action to be +/// invoked. +/// * [Action], a class for defining an invocation of a user action. +/// * [CallbackAction], a class for creating an action from a callback. +class Shortcuts extends StatefulWidget { + /// Creates a const [Shortcuts] widget that owns the map of shortcuts and + /// creates its own manager. + /// + /// When using this constructor, [manager] will return null. + /// + /// The [child] and [shortcuts] arguments are required. + /// + /// See also: + /// + /// * [Shortcuts.manager], a constructor that uses a [ShortcutManager] to + /// manage the shortcuts list instead. + const Shortcuts({ + super.key, + required Map<ShortcutActivator, Intent> shortcuts, + required this.child, + this.debugLabel, + }) : _shortcuts = shortcuts, + manager = null; + + /// Creates a const [Shortcuts] widget that uses the [manager] to + /// manage the map of shortcuts. + /// + /// If this constructor is used, [shortcuts] will return the contents of + /// [ShortcutManager.shortcuts]. + /// + /// The [child] and [manager] arguments are required. + const Shortcuts.manager({ + super.key, + required ShortcutManager this.manager, + required this.child, + this.debugLabel, + }) : _shortcuts = const <ShortcutActivator, Intent>{}; + + /// The [ShortcutManager] that will manage the mapping between key + /// combinations and [Action]s. + /// + /// If this widget was created with [Shortcuts.manager], then + /// [ShortcutManager.shortcuts] will be used as the source for shortcuts. If + /// the unnamed constructor is used, this manager will be null, and a + /// default-constructed [ShortcutManager] will be used. + final ShortcutManager? manager; + + /// {@template flutter.widgets.shortcuts.shortcuts} + /// The map of shortcuts that describes the mapping between a key sequence + /// defined by a [ShortcutActivator] and the [Intent] that will be emitted + /// when that key sequence is pressed. + /// {@endtemplate} + Map<ShortcutActivator, Intent> get shortcuts { + return manager == null ? _shortcuts : manager!.shortcuts; + } + final Map<ShortcutActivator, Intent> _shortcuts; + + /// The child widget for this [Shortcuts] widget. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The debug label that is printed for this node when logged. + /// + /// If this label is set, then it will be displayed instead of the shortcut + /// map when logged. + /// + /// This allows simplifying the diagnostic output to avoid cluttering it + /// unnecessarily with large default shortcut maps. + final String? debugLabel; + + @override + State<Shortcuts> createState() => _ShortcutsState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ShortcutManager>('manager', manager, defaultValue: null)); + properties.add(ShortcutMapProperty('shortcuts', shortcuts, description: debugLabel?.isNotEmpty ?? false ? debugLabel : null)); + } +} + +class _ShortcutsState extends State<Shortcuts> { + ShortcutManager? _internalManager; + ShortcutManager get manager => widget.manager ?? _internalManager!; + + @override + void dispose() { + _internalManager?.dispose(); + super.dispose(); + } + + @override + void initState() { + super.initState(); + if (widget.manager == null) { + _internalManager = ShortcutManager(); + _internalManager!.shortcuts = widget.shortcuts; + } + } + + @override + void didUpdateWidget(Shortcuts oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.manager != oldWidget.manager) { + if (widget.manager != null) { + _internalManager?.dispose(); + _internalManager = null; + } else { + _internalManager ??= ShortcutManager(); + } + } + _internalManager?.shortcuts = widget.shortcuts; + } + + KeyEventResult _handleOnKeyEvent(FocusNode node, KeyEvent event) { + if (node.context == null) { + return KeyEventResult.ignored; + } + return manager.handleKeypress(node.context!, event); + } + + @override + Widget build(BuildContext context) { + return Focus( + debugLabel: '$Shortcuts', + canRequestFocus: false, + onKeyEvent: _handleOnKeyEvent, + child: widget.child, + ); + } +} + +/// A widget that binds key combinations to specific callbacks. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=VcQQ1ns_qNY} +/// +/// This is similar to but simpler than the [Shortcuts] widget as it doesn't +/// require [Intent]s and [Actions] widgets. Instead, it accepts a map +/// of [ShortcutActivator]s to [VoidCallback]s. +/// +/// Unlike [Shortcuts], this widget does not separate key bindings and their +/// implementations. This separation allows [Shortcuts] to have key bindings +/// that adapt to the focused context. For example, the desired action for a +/// deletion intent may be to delete a character in a text input, or to delete +/// a file in a file menu. +/// +/// {@tool dartpad} +/// This example uses the [CallbackShortcuts] widget to add and subtract +/// from a counter when the up or down arrow keys are pressed. +/// +/// ** See code in examples/api/lib/widgets/shortcuts/callback_shortcuts.0.dart ** +/// {@end-tool} +/// +/// [Shortcuts] and [CallbackShortcuts] can both be used in the same app. As +/// with any key handling widget, if this widget handles a key event then +/// widgets above it in the focus chain will not receive the event. This means +/// that if this widget handles a key, then an ancestor [Shortcuts] widget (or +/// any other key handling widget) will not receive that key. Similarly, if +/// a descendant of this widget handles the key, then the key event will not +/// reach this widget for handling. +/// +/// See the article on [Using Actions and +/// Shortcuts](https://docs.flutter.dev/development/ui/advanced/actions_and_shortcuts) +/// for a detailed explanation. +/// +/// See also: +/// * [Shortcuts], a more powerful widget for defining key bindings. +/// * [Focus], a widget that defines which widgets can receive keyboard focus. +class CallbackShortcuts extends StatelessWidget { + /// Creates a const [CallbackShortcuts] widget. + const CallbackShortcuts({ + super.key, + required this.bindings, + required this.child, + }); + + /// A map of key combinations to callbacks used to define the shortcut + /// bindings. + /// + /// If a descendant of this widget has focus, and a key is pressed, the + /// activator keys of this map will be asked if they accept the key event. If + /// they do, then the corresponding callback is invoked, and the key event + /// propagation is halted. If none of the activators accept the key event, + /// then the key event continues to be propagated up the focus chain. + /// + /// If more than one activator accepts the key event, then all of the + /// callbacks associated with activators that accept the key event are + /// invoked. + /// + /// Some examples of [ShortcutActivator] subclasses that can be used to define + /// the key combinations here are [SingleActivator], [CharacterActivator], and + /// [LogicalKeySet]. + final Map<ShortcutActivator, VoidCallback> bindings; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + // A helper function to make the stack trace more useful if the callback + // throws, by providing the activator and event as arguments that will appear + // in the stack trace. + bool _applyKeyEventBinding(ShortcutActivator activator, KeyEvent event) { + if (activator.accepts(event, HardwareKeyboard.instance)) { + bindings[activator]!.call(); + return true; + } + return false; + } + + @override + Widget build(BuildContext context) { + return Focus( + canRequestFocus: false, + skipTraversal: true, + onKeyEvent: (FocusNode node, KeyEvent event) { + KeyEventResult result = KeyEventResult.ignored; + // Activates all key bindings that match, returns "handled" if any handle it. + for (final ShortcutActivator activator in bindings.keys) { + result = _applyKeyEventBinding(activator, event) ? KeyEventResult.handled : result; + } + return result; + }, + child: child, + ); + } +} + +/// A entry returned by [ShortcutRegistry.addAll] that allows the caller to +/// identify the shortcuts they registered with the [ShortcutRegistry] through +/// the [ShortcutRegistrar]. +/// +/// When the entry is no longer needed, [dispose] should be called, and the +/// entry should no longer be used. +class ShortcutRegistryEntry { + // Tokens can only be created by the ShortcutRegistry. + const ShortcutRegistryEntry._(this.registry); + + /// The [ShortcutRegistry] that this entry was issued by. + final ShortcutRegistry registry; + + /// Replaces the given shortcut bindings in the [ShortcutRegistry] that this + /// entry was created from. + /// + /// This method will assert in debug mode if another [ShortcutRegistryEntry] + /// exists (i.e. hasn't been disposed of) that has already added a given + /// shortcut. + /// + /// It will also assert if this entry has already been disposed. + /// + /// If two equivalent, but different, [ShortcutActivator]s are added, all of + /// them will be executed when triggered. For example, if both + /// `SingleActivator(LogicalKeyboardKey.keyA)` and `CharacterActivator('a')` + /// are added, then both will be executed when an "a" key is pressed. + void replaceAll(Map<ShortcutActivator, Intent> value) { + registry._replaceAll(this, value); + } + + /// Called when the entry is no longer needed. + /// + /// Call this will remove all shortcuts associated with this + /// [ShortcutRegistryEntry] from the [registry]. + @mustCallSuper + void dispose() { + registry._disposeEntry(this); + } +} + +/// A class used by [ShortcutRegistrar] that allows adding or removing shortcut +/// bindings by descendants of the [ShortcutRegistrar]. +/// +/// You can reach the nearest [ShortcutRegistry] using [of] and [maybeOf]. +/// +/// The registry may be listened to (with [addListener]/[removeListener]) for +/// change notifications when the registered shortcuts change. Change +/// notifications take place after the current frame is drawn, so that +/// widgets that are not descendants of the registry can listen to it (e.g. in +/// overlays). +class ShortcutRegistry with ChangeNotifier { + /// Creates an instance of [ShortcutRegistry]. + ShortcutRegistry() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + bool _notificationScheduled = false; + bool _disposed = false; + + @override + void dispose() { + super.dispose(); + _disposed = true; + } + + /// Gets the combined shortcut bindings from all contexts that are registered + /// with this [ShortcutRegistry]. + /// + /// Listeners will be notified when the value returned by this getter changes. + /// + /// Returns a copy: modifying the returned map will have no effect. + Map<ShortcutActivator, Intent> get shortcuts { + assert(ChangeNotifier.debugAssertNotDisposed(this)); + return <ShortcutActivator, Intent>{ + for (final MapEntry<ShortcutRegistryEntry, Map<ShortcutActivator, Intent>> entry in _registeredShortcuts.entries) + ...entry.value, + }; + } + + final Map<ShortcutRegistryEntry, Map<ShortcutActivator, Intent>> _registeredShortcuts = + <ShortcutRegistryEntry, Map<ShortcutActivator, Intent>>{}; + + /// Adds all the given shortcut bindings to this [ShortcutRegistry], and + /// returns a entry for managing those bindings. + /// + /// The entry should have [ShortcutRegistryEntry.dispose] called on it when + /// these shortcuts are no longer needed. This will remove them from the + /// registry, and invalidate the entry. + /// + /// This method will assert in debug mode if another entry exists (i.e. hasn't + /// been disposed of) that has already added a given shortcut. + /// + /// If two equivalent, but different, [ShortcutActivator]s are added, all of + /// them will be executed when triggered. For example, if both + /// `SingleActivator(LogicalKeyboardKey.keyA)` and `CharacterActivator('a')` + /// are added, then both will be executed when an "a" key is pressed. + /// + /// See also: + /// + /// * [ShortcutRegistryEntry.replaceAll], a function used to replace the set of + /// shortcuts associated with a particular entry. + /// * [ShortcutRegistryEntry.dispose], a function used to remove the set of + /// shortcuts associated with a particular entry. + ShortcutRegistryEntry addAll(Map<ShortcutActivator, Intent> value) { + assert(ChangeNotifier.debugAssertNotDisposed(this)); + assert(value.isNotEmpty, 'Cannot register an empty map of shortcuts'); + final ShortcutRegistryEntry entry = ShortcutRegistryEntry._(this); + _registeredShortcuts[entry] = value; + assert(_debugCheckForDuplicates()); + _notifyListenersNextFrame(); + return entry; + } + + // Subscriber notification has to happen in the next frame because shortcuts + // are often registered that affect things in the overlay or different parts + // of the tree, and so can cause build ordering issues if notifications happen + // during the build. The _notificationScheduled check makes sure we only + // notify once per frame. + void _notifyListenersNextFrame() { + if (!_notificationScheduled) { + SchedulerBinding.instance.addPostFrameCallback((Duration _) { + _notificationScheduled = false; + if (!_disposed) { + notifyListeners(); + } + }, debugLabel: 'ShortcutRegistry.notifyListeners'); + _notificationScheduled = true; + } + } + + /// Returns the [ShortcutRegistry] that belongs to the [ShortcutRegistrar] + /// which most tightly encloses the given [BuildContext]. + /// + /// If no [ShortcutRegistrar] widget encloses the context given, [of] will + /// throw an exception in debug mode. + /// + /// There is a default [ShortcutRegistrar] instance in [WidgetsApp], so if + /// [WidgetsApp], [MaterialApp] or [CupertinoApp] are used, an additional + /// [ShortcutRegistrar] isn't needed. + /// + /// See also: + /// + /// * [maybeOf], which is similar to this function, but will return null if + /// it doesn't find a [ShortcutRegistrar] ancestor. + static ShortcutRegistry of(BuildContext context) { + final _ShortcutRegistrarScope? inherited = + context.dependOnInheritedWidgetOfExactType<_ShortcutRegistrarScope>(); + assert(() { + if (inherited == null) { + throw FlutterError( + 'Unable to find a $ShortcutRegistrar widget in the context.\n' + '$ShortcutRegistrar.of() was called with a context that does not contain a ' + '$ShortcutRegistrar widget.\n' + 'No $ShortcutRegistrar ancestor could be found starting from the context that was ' + 'passed to $ShortcutRegistrar.of().\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return inherited!.registry; + } + + /// Returns [ShortcutRegistry] of the [ShortcutRegistrar] that most tightly + /// encloses the given [BuildContext]. + /// + /// If no [ShortcutRegistrar] widget encloses the given context, [maybeOf] + /// will return null. + /// + /// There is a default [ShortcutRegistrar] instance in [WidgetsApp], so if + /// [WidgetsApp], [MaterialApp] or [CupertinoApp] are used, an additional + /// [ShortcutRegistrar] isn't needed. + /// + /// See also: + /// + /// * [of], which is similar to this function, but returns a non-nullable + /// result, and will throw an exception if it doesn't find a + /// [ShortcutRegistrar] ancestor. + static ShortcutRegistry? maybeOf(BuildContext context) { + final _ShortcutRegistrarScope? inherited = + context.dependOnInheritedWidgetOfExactType<_ShortcutRegistrarScope>(); + return inherited?.registry; + } + + // Replaces all the shortcuts associated with the given entry from this + // registry. + void _replaceAll(ShortcutRegistryEntry entry, Map<ShortcutActivator, Intent> value) { + assert(ChangeNotifier.debugAssertNotDisposed(this)); + assert(_debugCheckEntryIsValid(entry)); + _registeredShortcuts[entry] = value; + assert(_debugCheckForDuplicates()); + _notifyListenersNextFrame(); + } + + // Removes all the shortcuts associated with the given entry from this + // registry. + void _disposeEntry(ShortcutRegistryEntry entry) { + assert(_debugCheckEntryIsValid(entry)); + final Map<ShortcutActivator, Intent>? removedShortcut = _registeredShortcuts.remove(entry); + if (removedShortcut != null) { + _notifyListenersNextFrame(); + } + } + + bool _debugCheckEntryIsValid(ShortcutRegistryEntry entry) { + if (!_registeredShortcuts.containsKey(entry)) { + if (entry.registry == this) { + throw FlutterError('entry ${describeIdentity(entry)} is invalid.\n' + 'The entry has already been disposed of. Tokens are not valid after ' + 'dispose is called on them, and should no longer be used.'); + } else { + throw FlutterError('Foreign entry ${describeIdentity(entry)} used.\n' + 'This entry was not created by this registry, it was created by ' + '${describeIdentity(entry.registry)}, and should be used with that ' + 'registry instead.'); + } + } + return true; + } + + bool _debugCheckForDuplicates() { + final Map<ShortcutActivator, ShortcutRegistryEntry?> previous = <ShortcutActivator, ShortcutRegistryEntry?>{}; + for (final MapEntry<ShortcutRegistryEntry, Map<ShortcutActivator, Intent>> tokenEntry in _registeredShortcuts.entries) { + for (final ShortcutActivator shortcut in tokenEntry.value.keys) { + if (previous.containsKey(shortcut)) { + throw FlutterError( + '$ShortcutRegistry: Received a duplicate registration for the ' + 'shortcut $shortcut in ${describeIdentity(tokenEntry.key)} and ${previous[shortcut]}.'); + } + previous[shortcut] = tokenEntry.key; + } + } + return true; + } +} + +/// A widget that holds a [ShortcutRegistry] which allows descendants to add, +/// remove, or replace shortcuts. +/// +/// This widget holds a [ShortcutRegistry] so that its descendants can find it +/// with [ShortcutRegistry.of] or [ShortcutRegistry.maybeOf]. +/// +/// The registered shortcuts are valid whenever a widget below this one in the +/// hierarchy has focus. +/// +/// To add shortcuts to the registry, call [ShortcutRegistry.of] or +/// [ShortcutRegistry.maybeOf] to get the [ShortcutRegistry], and then add them +/// using [ShortcutRegistry.addAll], which will return a [ShortcutRegistryEntry] +/// which must be disposed by calling [ShortcutRegistryEntry.dispose] when the +/// shortcuts are no longer needed. +/// +/// To replace or update the shortcuts in the registry, call +/// [ShortcutRegistryEntry.replaceAll]. +/// +/// To remove previously added shortcuts from the registry, call +/// [ShortcutRegistryEntry.dispose] on the entry returned by +/// [ShortcutRegistry.addAll]. +class ShortcutRegistrar extends StatefulWidget { + /// Creates a const [ShortcutRegistrar]. + /// + /// The [child] parameter is required. + const ShortcutRegistrar({super.key, required this.child}); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + State<ShortcutRegistrar> createState() => _ShortcutRegistrarState(); +} + +class _ShortcutRegistrarState extends State<ShortcutRegistrar> { + final ShortcutRegistry registry = ShortcutRegistry(); + final ShortcutManager manager = ShortcutManager(); + + @override + void initState() { + super.initState(); + registry.addListener(_shortcutsChanged); + } + + void _shortcutsChanged() { + // This shouldn't need to update the widget, and avoids calling setState + // during build phase. + manager.shortcuts = registry.shortcuts; + } + + @override + void dispose() { + registry.removeListener(_shortcutsChanged); + registry.dispose(); + manager.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return _ShortcutRegistrarScope( + registry: registry, + child: Shortcuts.manager( + manager: manager, + child: widget.child, + ), + ); + } +} + +class _ShortcutRegistrarScope extends InheritedWidget { + const _ShortcutRegistrarScope({ + required this.registry, + required super.child, + }); + + final ShortcutRegistry registry; + + @override + bool updateShouldNotify(covariant _ShortcutRegistrarScope oldWidget) { + return registry != oldWidget.registry; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/single_child_scroll_view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/single_child_scroll_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..c7c7a1b87e012fa8adc99acfafa3d54250d7d5af --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/single_child_scroll_view.dart @@ -0,0 +1,722 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/gestures.dart' show DragStartBehavior; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; +import 'notification_listener.dart'; +import 'primary_scroll_controller.dart'; +import 'scroll_controller.dart'; +import 'scroll_notification.dart'; +import 'scroll_physics.dart'; +import 'scroll_view.dart'; +import 'scrollable.dart'; + +/// A box in which a single widget can be scrolled. +/// +/// This widget is useful when you have a single box that will normally be +/// entirely visible, for example a clock face in a time picker, but you need to +/// make sure it can be scrolled if the container gets too small in one axis +/// (the scroll direction). +/// +/// It is also useful if you need to shrink-wrap in both axes (the main +/// scrolling direction as well as the cross axis), as one might see in a dialog +/// or pop-up menu. In that case, you might pair the [SingleChildScrollView] +/// with a [ListBody] child. +/// +/// When you have a list of children and do not require cross-axis +/// shrink-wrapping behavior, for example a scrolling list that is always the +/// width of the screen, consider [ListView], which is vastly more efficient +/// than a [SingleChildScrollView] containing a [ListBody] or [Column] with +/// many children. +/// +/// ## Sample code: Using [SingleChildScrollView] with a [Column] +/// +/// Sometimes a layout is designed around the flexible properties of a +/// [Column], but there is the concern that in some cases, there might not +/// be enough room to see the entire contents. This could be because some +/// devices have unusually small screens, or because the application can +/// be used in landscape mode where the aspect ratio isn't what was +/// originally envisioned, or because the application is being shown in a +/// small window in split-screen mode. In any case, as a result, it might +/// make sense to wrap the layout in a [SingleChildScrollView]. +/// +/// Doing so, however, usually results in a conflict between the [Column], +/// which typically tries to grow as big as it can, and the [SingleChildScrollView], +/// which provides its children with an infinite amount of space. +/// +/// To resolve this apparent conflict, there are a couple of techniques, as +/// discussed below. These techniques should only be used when the content is +/// normally expected to fit on the screen, so that the lazy instantiation of a +/// sliver-based [ListView] or [CustomScrollView] is not expected to provide any +/// performance benefit. If the viewport is expected to usually contain content +/// beyond the dimensions of the screen, then [SingleChildScrollView] would be +/// very expensive (in which case [ListView] may be a better choice than +/// [Column]). +/// +/// ### Centering, spacing, or aligning fixed-height content +/// +/// If the content has fixed (or intrinsic) dimensions but needs to be spaced out, +/// centered, or otherwise positioned using the [Flex] layout model of a [Column], +/// the following technique can be used to provide the [Column] with a minimum +/// dimension while allowing it to shrink-wrap the contents when there isn't enough +/// room to apply these spacing or alignment needs. +/// +/// A [LayoutBuilder] is used to obtain the size of the viewport (implicitly via +/// the constraints that the [SingleChildScrollView] sees, since viewports +/// typically grow to fit their maximum height constraint). Then, inside the +/// scroll view, a [ConstrainedBox] is used to set the minimum height of the +/// [Column]. +/// +/// The [Column] has no [Expanded] children, so rather than take on the infinite +/// height from its [BoxConstraints.maxHeight], (the viewport provides no maximum height +/// constraint), it automatically tries to shrink to fit its children. It cannot +/// be smaller than its [BoxConstraints.minHeight], though, and It therefore +/// becomes the bigger of the minimum height provided by the +/// [ConstrainedBox] and the sum of the heights of the children. +/// +/// If the children aren't enough to fit that minimum size, the [Column] ends up +/// with some remaining space to allocate as specified by its +/// [Column.mainAxisAlignment] argument. +/// +/// {@tool dartpad} +/// In this example, the children are spaced out equally, unless there's no more +/// room, in which case they stack vertically and scroll. +/// +/// When using this technique, [Expanded] and [Flexible] are not useful, because +/// in both cases the "available space" is infinite (since this is in a viewport). +/// The next section describes a technique for providing a maximum height constraint. +/// +/// ** See code in examples/api/lib/widgets/single_child_scroll_view/single_child_scroll_view.0.dart ** +/// {@end-tool} +/// +/// ### Expanding content to fit the viewport +/// +/// The following example builds on the previous one. In addition to providing a +/// minimum dimension for the child [Column], an [IntrinsicHeight] widget is used +/// to force the column to be exactly as big as its contents. This constraint +/// combines with the [ConstrainedBox] constraints discussed previously to ensure +/// that the column becomes either as big as viewport, or as big as the contents, +/// whichever is biggest. +/// +/// Both constraints must be used to get the desired effect. If only the +/// [IntrinsicHeight] was specified, then the column would not grow to fit the +/// entire viewport when its children were smaller than the whole screen. If only +/// the size of the viewport was used, then the [Column] would overflow if the +/// children were bigger than the viewport. +/// +/// The widget that is to grow to fit the remaining space so provided is wrapped +/// in an [Expanded] widget. +/// +/// This technique is quite expensive, as it more or less requires that the contents +/// of the viewport be laid out twice (once to find their intrinsic dimensions, and +/// once to actually lay them out). The number of widgets within the column should +/// therefore be kept small. Alternatively, subsets of the children that have known +/// dimensions can be wrapped in a [SizedBox] that has tight vertical constraints, +/// so that the intrinsic sizing algorithm can short-circuit the computation when it +/// reaches those parts of the subtree. +/// +/// {@tool dartpad} +/// In this example, the column becomes either as big as viewport, or as big as +/// the contents, whichever is biggest. +/// +/// ** See code in examples/api/lib/widgets/single_child_scroll_view/single_child_scroll_view.1.dart ** +/// {@end-tool} +/// +/// {@macro flutter.widgets.ScrollView.PageStorage} +/// +/// See also: +/// +/// * [ListView], which handles multiple children in a scrolling list. +/// * [GridView], which handles multiple children in a scrolling grid. +/// * [PageView], for a scrollable that works page by page. +/// * [Scrollable], which handles arbitrary scrolling effects. +class SingleChildScrollView extends StatelessWidget { + /// Creates a box in which a single widget can be scrolled. + const SingleChildScrollView({ + super.key, + this.scrollDirection = Axis.vertical, + this.reverse = false, + this.padding, + this.primary, + this.physics, + this.controller, + this.child, + this.dragStartBehavior = DragStartBehavior.start, + this.clipBehavior = Clip.hardEdge, + this.restorationId, + this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, + }) : assert( + !(controller != null && (primary ?? false)), + 'Primary ScrollViews obtain their ScrollController via inheritance ' + 'from a PrimaryScrollController widget. You cannot both set primary to ' + 'true and pass an explicit controller.', + ); + + /// {@macro flutter.widgets.scroll_view.scrollDirection} + final Axis scrollDirection; + + /// Whether the scroll view scrolls in the reading direction. + /// + /// For example, if the reading direction is left-to-right and + /// [scrollDirection] is [Axis.horizontal], then the scroll view scrolls from + /// left to right when [reverse] is false and from right to left when + /// [reverse] is true. + /// + /// Similarly, if [scrollDirection] is [Axis.vertical], then the scroll view + /// scrolls from top to bottom when [reverse] is false and from bottom to top + /// when [reverse] is true. + /// + /// Defaults to false. + final bool reverse; + + /// The amount of space by which to inset the child. + final EdgeInsetsGeometry? padding; + + /// An object that can be used to control the position to which this scroll + /// view is scrolled. + /// + /// Must be null if [primary] is true. + /// + /// A [ScrollController] serves several purposes. It can be used to control + /// the initial scroll position (see [ScrollController.initialScrollOffset]). + /// It can be used to control whether the scroll view should automatically + /// save and restore its scroll position in the [PageStorage] (see + /// [ScrollController.keepScrollOffset]). It can be used to read the current + /// scroll position (see [ScrollController.offset]), or change it (see + /// [ScrollController.animateTo]). + final ScrollController? controller; + + /// {@macro flutter.widgets.scroll_view.primary} + final bool? primary; + + /// How the scroll view should respond to user input. + /// + /// For example, determines how the scroll view continues to animate after the + /// user stops dragging the scroll view. + /// + /// Defaults to matching platform conventions. + final ScrollPhysics? physics; + + /// The widget that scrolls. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// {@macro flutter.widgets.scrollable.restorationId} + final String? restorationId; + + /// {@macro flutter.widgets.scroll_view.keyboardDismissBehavior} + final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior; + + AxisDirection _getDirection(BuildContext context) { + return getAxisDirectionFromAxisReverseAndDirectionality(context, scrollDirection, reverse); + } + + @override + Widget build(BuildContext context) { + final AxisDirection axisDirection = _getDirection(context); + Widget? contents = child; + if (padding != null) { + contents = Padding(padding: padding!, child: contents); + } + final bool effectivePrimary = primary + ?? controller == null && PrimaryScrollController.shouldInherit(context, scrollDirection); + + final ScrollController? scrollController = effectivePrimary + ? PrimaryScrollController.maybeOf(context) + : controller; + + Widget scrollable = Scrollable( + dragStartBehavior: dragStartBehavior, + axisDirection: axisDirection, + controller: scrollController, + physics: physics, + restorationId: restorationId, + clipBehavior: clipBehavior, + viewportBuilder: (BuildContext context, ViewportOffset offset) { + return _SingleChildViewport( + axisDirection: axisDirection, + offset: offset, + clipBehavior: clipBehavior, + child: contents, + ); + }, + ); + + if (keyboardDismissBehavior == ScrollViewKeyboardDismissBehavior.onDrag) { + scrollable = NotificationListener<ScrollUpdateNotification>( + child: scrollable, + onNotification: (ScrollUpdateNotification notification) { + final FocusScopeNode focusNode = FocusScope.of(context); + if (notification.dragDetails != null && focusNode.hasFocus) { + focusNode.unfocus(); + } + return false; + }, + ); + } + + return effectivePrimary && scrollController != null + // Further descendant ScrollViews will not inherit the same + // PrimaryScrollController + ? PrimaryScrollController.none(child: scrollable) + : scrollable; + } +} + +class _SingleChildViewport extends SingleChildRenderObjectWidget { + const _SingleChildViewport({ + this.axisDirection = AxisDirection.down, + required this.offset, + super.child, + required this.clipBehavior, + }); + + final AxisDirection axisDirection; + final ViewportOffset offset; + final Clip clipBehavior; + + @override + _RenderSingleChildViewport createRenderObject(BuildContext context) { + return _RenderSingleChildViewport( + axisDirection: axisDirection, + offset: offset, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderSingleChildViewport renderObject) { + // Order dependency: The offset setter reads the axis direction. + renderObject + ..axisDirection = axisDirection + ..offset = offset + ..clipBehavior = clipBehavior; + } + + @override + SingleChildRenderObjectElement createElement() { + return _SingleChildViewportElement(this); + } +} + +class _SingleChildViewportElement extends SingleChildRenderObjectElement with NotifiableElementMixin, ViewportElementMixin { + _SingleChildViewportElement(_SingleChildViewport super.widget); +} + +class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMixin<RenderBox> implements RenderAbstractViewport { + _RenderSingleChildViewport({ + AxisDirection axisDirection = AxisDirection.down, + required ViewportOffset offset, + RenderBox? child, + required Clip clipBehavior, + }) : _axisDirection = axisDirection, + _offset = offset, + _clipBehavior = clipBehavior { + this.child = child; + } + + AxisDirection get axisDirection => _axisDirection; + AxisDirection _axisDirection; + set axisDirection(AxisDirection value) { + if (value == _axisDirection) { + return; + } + _axisDirection = value; + markNeedsLayout(); + } + + Axis get axis => axisDirectionToAxis(axisDirection); + + ViewportOffset get offset => _offset; + ViewportOffset _offset; + set offset(ViewportOffset value) { + if (value == _offset) { + return; + } + if (attached) { + _offset.removeListener(_hasScrolled); + } + _offset = value; + if (attached) { + _offset.addListener(_hasScrolled); + } + markNeedsLayout(); + } + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.none]. + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior = Clip.none; + set clipBehavior(Clip value) { + if (value != _clipBehavior) { + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + } + + void _hasScrolled() { + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + @override + void setupParentData(RenderObject child) { + // We don't actually use the offset argument in BoxParentData, so let's + // avoid allocating it at all. + if (child.parentData is! ParentData) { + child.parentData = ParentData(); + } + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _offset.addListener(_hasScrolled); + } + + @override + void detach() { + _offset.removeListener(_hasScrolled); + super.detach(); + } + + @override + bool get isRepaintBoundary => true; + + double get _viewportExtent { + assert(hasSize); + switch (axis) { + case Axis.horizontal: + return size.width; + case Axis.vertical: + return size.height; + } + } + + double get _minScrollExtent { + assert(hasSize); + return 0.0; + } + + double get _maxScrollExtent { + assert(hasSize); + if (child == null) { + return 0.0; + } + switch (axis) { + case Axis.horizontal: + return math.max(0.0, child!.size.width - size.width); + case Axis.vertical: + return math.max(0.0, child!.size.height - size.height); + } + } + + BoxConstraints _getInnerConstraints(BoxConstraints constraints) { + switch (axis) { + case Axis.horizontal: + return constraints.heightConstraints(); + case Axis.vertical: + return constraints.widthConstraints(); + } + } + + @override + double computeMinIntrinsicWidth(double height) { + if (child != null) { + return child!.getMinIntrinsicWidth(height); + } + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + if (child != null) { + return child!.getMaxIntrinsicWidth(height); + } + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + if (child != null) { + return child!.getMinIntrinsicHeight(width); + } + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + if (child != null) { + return child!.getMaxIntrinsicHeight(width); + } + return 0.0; + } + + // We don't override computeDistanceToActualBaseline(), because we + // want the default behavior (returning null). Otherwise, as you + // scroll, it would shift in its parent if the parent was baseline-aligned, + // which makes no sense. + + @override + Size computeDryLayout(BoxConstraints constraints) { + if (child == null) { + return constraints.smallest; + } + final Size childSize = child!.getDryLayout(_getInnerConstraints(constraints)); + return constraints.constrain(childSize); + } + + @override + void performLayout() { + final BoxConstraints constraints = this.constraints; + if (child == null) { + size = constraints.smallest; + } else { + child!.layout(_getInnerConstraints(constraints), parentUsesSize: true); + size = constraints.constrain(child!.size); + } + + if (offset.hasPixels) { + if (offset.pixels > _maxScrollExtent) { + offset.correctBy(_maxScrollExtent - offset.pixels); + } else if (offset.pixels < _minScrollExtent) { + offset.correctBy(_minScrollExtent - offset.pixels); + } + } + + offset.applyViewportDimension(_viewportExtent); + offset.applyContentDimensions(_minScrollExtent, _maxScrollExtent); + } + + Offset get _paintOffset => _paintOffsetForPosition(offset.pixels); + + Offset _paintOffsetForPosition(double position) { + switch (axisDirection) { + case AxisDirection.up: + return Offset(0.0, position - child!.size.height + size.height); + case AxisDirection.down: + return Offset(0.0, -position); + case AxisDirection.left: + return Offset(position - child!.size.width + size.width, 0.0); + case AxisDirection.right: + return Offset(-position, 0.0); + } + } + + bool _shouldClipAtPaintOffset(Offset paintOffset) { + assert(child != null); + switch (clipBehavior) { + case Clip.none: + return false; + case Clip.hardEdge: + case Clip.antiAlias: + case Clip.antiAliasWithSaveLayer: + return paintOffset.dx < 0 || + paintOffset.dy < 0 || + paintOffset.dx + child!.size.width > size.width || + paintOffset.dy + child!.size.height > size.height; + } + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null) { + final Offset paintOffset = _paintOffset; + + void paintContents(PaintingContext context, Offset offset) { + context.paintChild(child!, offset + paintOffset); + } + + if (_shouldClipAtPaintOffset(paintOffset)) { + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & size, + paintContents, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + } else { + _clipRectLayer.layer = null; + paintContents(context, offset); + } + } + } + + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + void dispose() { + _clipRectLayer.layer = null; + super.dispose(); + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + final Offset paintOffset = _paintOffset; + transform.translate(paintOffset.dx, paintOffset.dy); + } + + @override + Rect? describeApproximatePaintClip(RenderObject? child) { + if (child != null && _shouldClipAtPaintOffset(_paintOffset)) { + return Offset.zero & size; + } + return null; + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + if (child != null) { + return result.addWithPaintOffset( + offset: _paintOffset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position + -_paintOffset); + return child!.hitTest(result, position: transformed); + }, + ); + } + return false; + } + + @override + RevealedOffset getOffsetToReveal( + RenderObject target, + double alignment, { + Rect? rect, + Axis? axis, + }) { + // One dimensional viewport has only one axis, override if it was + // provided/may be mismatched. + axis = this.axis; + + rect ??= target.paintBounds; + if (target is! RenderBox) { + return RevealedOffset(offset: offset.pixels, rect: rect); + } + + final RenderBox targetBox = target; + final Matrix4 transform = targetBox.getTransformTo(child); + final Rect bounds = MatrixUtils.transformRect(transform, rect); + final Size contentSize = child!.size; + + final double leadingScrollOffset; + final double targetMainAxisExtent; + final double mainAxisExtent; + + switch (axisDirection) { + case AxisDirection.up: + mainAxisExtent = size.height; + leadingScrollOffset = contentSize.height - bounds.bottom; + targetMainAxisExtent = bounds.height; + case AxisDirection.right: + mainAxisExtent = size.width; + leadingScrollOffset = bounds.left; + targetMainAxisExtent = bounds.width; + case AxisDirection.down: + mainAxisExtent = size.height; + leadingScrollOffset = bounds.top; + targetMainAxisExtent = bounds.height; + case AxisDirection.left: + mainAxisExtent = size.width; + leadingScrollOffset = contentSize.width - bounds.right; + targetMainAxisExtent = bounds.width; + } + + final double targetOffset = leadingScrollOffset - (mainAxisExtent - targetMainAxisExtent) * alignment; + final Rect targetRect = bounds.shift(_paintOffsetForPosition(targetOffset)); + return RevealedOffset(offset: targetOffset, rect: targetRect); + } + + @override + void showOnScreen({ + RenderObject? descendant, + Rect? rect, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + }) { + if (!offset.allowImplicitScrolling) { + return super.showOnScreen( + descendant: descendant, + rect: rect, + duration: duration, + curve: curve, + ); + } + + final Rect? newRect = RenderViewportBase.showInViewport( + descendant: descendant, + viewport: this, + offset: offset, + rect: rect, + duration: duration, + curve: curve, + ); + super.showOnScreen( + rect: newRect, + duration: duration, + curve: curve, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Offset>('offset', _paintOffset)); + } + + @override + Rect describeSemanticsClip(RenderObject child) { + final double remainingOffset = _maxScrollExtent - offset.pixels; + switch (axisDirection) { + case AxisDirection.up: + return Rect.fromLTRB( + semanticBounds.left, + semanticBounds.top - remainingOffset, + semanticBounds.right, + semanticBounds.bottom + offset.pixels, + ); + case AxisDirection.right: + return Rect.fromLTRB( + semanticBounds.left - offset.pixels, + semanticBounds.top, + semanticBounds.right + remainingOffset, + semanticBounds.bottom, + ); + case AxisDirection.down: + return Rect.fromLTRB( + semanticBounds.left, + semanticBounds.top - offset.pixels, + semanticBounds.right, + semanticBounds.bottom + remainingOffset, + ); + case AxisDirection.left: + return Rect.fromLTRB( + semanticBounds.left - remainingOffset, + semanticBounds.top, + semanticBounds.right + offset.pixels, + semanticBounds.bottom, + ); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/size_changed_layout_notifier.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/size_changed_layout_notifier.dart new file mode 100644 index 0000000000000000000000000000000000000000..70b0e36dfbbdd3d60d6f36963eb1dbeb5e67ddf4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/size_changed_layout_notifier.dart @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; +import 'notification_listener.dart'; + +/// Indicates that the size of one of the descendants of the object receiving +/// this notification has changed, and that therefore any assumptions about that +/// layout are no longer valid. +/// +/// For example, sent by the [SizeChangedLayoutNotifier] widget whenever that +/// widget changes size. +/// +/// This notification can be used for triggering repaints, but if you use this +/// notification to trigger rebuilds or relayouts, you'll create a backwards +/// dependency in the frame pipeline because [SizeChangedLayoutNotification]s +/// are generated during layout, which is after the build phase and in the +/// middle of the layout phase. This backwards dependency can lead to visual +/// corruption or lags. +/// +/// See [LayoutChangedNotification] for additional discussion of layout +/// notifications such as this one. +/// +/// See also: +/// +/// * [SizeChangedLayoutNotifier], which sends this notification. +/// * [LayoutChangedNotification], of which this is a subclass. +class SizeChangedLayoutNotification extends LayoutChangedNotification { + /// Create a new [SizeChangedLayoutNotification]. + const SizeChangedLayoutNotification(); +} + +/// A widget that automatically dispatches a [SizeChangedLayoutNotification] +/// when the layout dimensions of its child change. +/// +/// The notification is not sent for the initial layout (since the size doesn't +/// change in that case, it's just established). +/// +/// To listen for the notification dispatched by this widget, use a +/// [NotificationListener<SizeChangedLayoutNotification>]. +/// +/// The [Material] class listens for [LayoutChangedNotification]s, including +/// [SizeChangedLayoutNotification]s, to repaint [InkResponse] and [InkWell] ink +/// effects. When a widget is likely to change size, wrapping it in a +/// [SizeChangedLayoutNotifier] will cause the ink effects to correctly repaint +/// when the child changes size. +/// +/// See also: +/// +/// * [Notification], the base class for notifications that bubble through the +/// widget tree. +class SizeChangedLayoutNotifier extends SingleChildRenderObjectWidget { + /// Creates a [SizeChangedLayoutNotifier] that dispatches layout changed + /// notifications when [child] changes layout size. + const SizeChangedLayoutNotifier({ + super.key, + super.child, + }); + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderSizeChangedWithCallback( + onLayoutChangedCallback: () { + const SizeChangedLayoutNotification().dispatch(context); + }, + ); + } +} + +class _RenderSizeChangedWithCallback extends RenderProxyBox { + _RenderSizeChangedWithCallback({ + RenderBox? child, + required this.onLayoutChangedCallback, + }) : super(child); + + // There's a 1:1 relationship between the _RenderSizeChangedWithCallback and + // the `context` that is captured by the closure created by createRenderObject + // above to assign to onLayoutChangedCallback, and thus we know that the + // onLayoutChangedCallback will never change nor need to change. + + final VoidCallback onLayoutChangedCallback; + + Size? _oldSize; + + @override + void performLayout() { + super.performLayout(); + // Don't send the initial notification, or this will be SizeObserver all + // over again! + if (_oldSize != null && size != _oldSize) { + onLayoutChangedCallback(); + } + _oldSize = size; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver.dart new file mode 100644 index 0000000000000000000000000000000000000000..9e76d448753a392984fe0c4123f56a4e4469bfb7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver.dart @@ -0,0 +1,1643 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection' show HashMap, SplayTreeMap; +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'automatic_keep_alive.dart'; +import 'basic.dart'; +import 'framework.dart'; +import 'scroll_delegate.dart'; + +/// A base class for slivers that have [KeepAlive] children. +/// +/// See also: +/// +/// * [KeepAlive], which marks whether its child widget should be kept alive. +/// * [SliverChildBuilderDelegate] and [SliverChildListDelegate], slivers +/// which make use of the keep alive functionality through the +/// `addAutomaticKeepAlives` property. +/// * [SliverGrid] and [SliverList], two sliver widgets that are commonly +/// wrapped with [KeepAlive] widgets to preserve their sliver child subtrees. +abstract class SliverWithKeepAliveWidget extends RenderObjectWidget { + /// Initializes fields for subclasses. + const SliverWithKeepAliveWidget({ + super.key, + }); + + @override + RenderSliverWithKeepAliveMixin createRenderObject(BuildContext context); +} + +/// A base class for slivers that have multiple box children. +/// +/// Helps subclasses build their children lazily using a [SliverChildDelegate]. +/// +/// The widgets returned by the [delegate] are cached and the delegate is only +/// consulted again if it changes and the new delegate's +/// [SliverChildDelegate.shouldRebuild] method returns true. +abstract class SliverMultiBoxAdaptorWidget extends SliverWithKeepAliveWidget { + /// Initializes fields for subclasses. + const SliverMultiBoxAdaptorWidget({ + super.key, + required this.delegate, + }); + + /// {@template flutter.widgets.SliverMultiBoxAdaptorWidget.delegate} + /// The delegate that provides the children for this widget. + /// + /// The children are constructed lazily using this delegate to avoid creating + /// more children than are visible through the [Viewport]. + /// + /// ## Using more than one delegate in a [Viewport] + /// + /// If multiple delegates are used in a single scroll view, the first child of + /// each delegate will always be laid out, even if it extends beyond the + /// currently viewable area. This is because at least one child is required in + /// order to estimate the max scroll offset for the whole scroll view, as it + /// uses the currently built children to estimate the remaining children's + /// extent. + /// + /// See also: + /// + /// * [SliverChildBuilderDelegate] and [SliverChildListDelegate], which are + /// commonly used subclasses of [SliverChildDelegate] that use a builder + /// callback and an explicit child list, respectively. + /// {@endtemplate} + final SliverChildDelegate delegate; + + @override + SliverMultiBoxAdaptorElement createElement() => SliverMultiBoxAdaptorElement(this); + + @override + RenderSliverMultiBoxAdaptor createRenderObject(BuildContext context); + + /// Returns an estimate of the max scroll extent for all the children. + /// + /// Subclasses should override this function if they have additional + /// information about their max scroll extent. + /// + /// This is used by [SliverMultiBoxAdaptorElement] to implement part of the + /// [RenderSliverBoxChildManager] API. + /// + /// The default implementation defers to [delegate] via its + /// [SliverChildDelegate.estimateMaxScrollOffset] method. + double? estimateMaxScrollOffset( + SliverConstraints? constraints, + int firstIndex, + int lastIndex, + double leadingScrollOffset, + double trailingScrollOffset, + ) { + assert(lastIndex >= firstIndex); + return delegate.estimateMaxScrollOffset( + firstIndex, + lastIndex, + leadingScrollOffset, + trailingScrollOffset, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<SliverChildDelegate>('delegate', delegate)); + } +} + +/// A sliver that places multiple box children in a linear array along the main +/// axis. +/// +/// _To learn more about slivers, see [CustomScrollView.slivers]._ +/// +/// Each child is forced to have the [SliverConstraints.crossAxisExtent] in the +/// cross axis but determines its own main axis extent. +/// +/// [SliverList] determines its scroll offset by "dead reckoning" because +/// children outside the visible part of the sliver are not materialized, which +/// means [SliverList] cannot learn their main axis extent. Instead, newly +/// materialized children are placed adjacent to existing children. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ORiTTaVY6mM} +/// +/// If the children have a fixed extent in the main axis, consider using +/// [SliverFixedExtentList] rather than [SliverList] because +/// [SliverFixedExtentList] does not need to perform layout on its children to +/// obtain their extent in the main axis and is therefore more efficient. +/// +/// {@macro flutter.widgets.SliverChildDelegate.lifecycle} +/// +/// See also: +/// +/// * <https://flutter.dev/docs/development/ui/advanced/slivers>, a description +/// of what slivers are and how to use them. +/// * [SliverFixedExtentList], which is more efficient for children with +/// the same extent in the main axis. +/// * [SliverPrototypeExtentList], which is similar to [SliverFixedExtentList] +/// except that it uses a prototype list item instead of a pixel value to define +/// the main axis extent of each item. +/// * [SliverAnimatedList], which animates items added to or removed from a +/// list. +/// * [SliverGrid], which places multiple children in a two dimensional grid. +/// * [SliverAnimatedGrid], a sliver which animates items when they are +/// inserted into or removed from a grid. +class SliverList extends SliverMultiBoxAdaptorWidget { + /// Creates a sliver that places box children in a linear array. + const SliverList({ + super.key, + required super.delegate, + }); + + /// A sliver that places multiple box children in a linear array along the main + /// axis. + /// + /// This constructor is appropriate for sliver lists with a large (or + /// infinite) number of children because the builder is called only for those + /// children that are actually visible. + /// + /// Providing a non-null `itemCount` improves the ability of the [SliverGrid] + /// to estimate the maximum scroll extent. + /// + /// `itemBuilder` will be called only with indices greater than or equal to + /// zero and less than `itemCount`. + /// + /// {@macro flutter.widgets.ListView.builder.itemBuilder} + /// + /// {@macro flutter.widgets.PageView.findChildIndexCallback} + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. + /// + /// {@tool snippet} + /// This example, which would be provided in [CustomScrollView.slivers], + /// shows an infinite number of items in varying shades of blue: + /// + /// ```dart + /// SliverList.builder( + /// itemBuilder: (BuildContext context, int index) { + /// return Container( + /// alignment: Alignment.center, + /// color: Colors.lightBlue[100 * (index % 9)], + /// child: Text('list item $index'), + /// ); + /// }, + /// ) + /// ``` + /// {@end-tool} + SliverList.builder({ + super.key, + required NullableIndexedWidgetBuilder itemBuilder, + ChildIndexGetter? findChildIndexCallback, + int? itemCount, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + }) : super(delegate: SliverChildBuilderDelegate( + itemBuilder, + findChildIndexCallback: findChildIndexCallback, + childCount: itemCount, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + )); + + /// A sliver that places multiple box children, separated by box widgets, in a + /// linear array along the main axis. + /// + /// This constructor is appropriate for sliver lists with a large (or + /// infinite) number of children because the builder is called only for those + /// children that are actually visible. + /// + /// Providing a non-null `itemCount` improves the ability of the [SliverGrid] + /// to estimate the maximum scroll extent. + /// + /// `itemBuilder` will be called only with indices greater than or equal to + /// zero and less than `itemCount`. + /// + /// {@macro flutter.widgets.ListView.builder.itemBuilder} + /// + /// {@macro flutter.widgets.PageView.findChildIndexCallback} + /// + /// + /// The `separatorBuilder` is similar to `itemBuilder`, except it is the widget + /// that gets placed between itemBuilder(context, index) and itemBuilder(context, index + 1). + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. + /// + /// {@tool snippet} + /// This example shows how to create a [SliverList] whose [Container] items + /// are separated by [Divider]s. The [SliverList] would be provided in + /// [CustomScrollView.slivers]. + /// + /// ```dart + /// SliverList.separated( + /// itemBuilder: (BuildContext context, int index) { + /// return Container( + /// alignment: Alignment.center, + /// color: Colors.lightBlue[100 * (index % 9)], + /// child: Text('list item $index'), + /// ); + /// }, + /// separatorBuilder: (BuildContext context, int index) => const Divider(), + /// ) + /// ``` + /// {@end-tool} + SliverList.separated({ + super.key, + required NullableIndexedWidgetBuilder itemBuilder, + ChildIndexGetter? findChildIndexCallback, + required NullableIndexedWidgetBuilder separatorBuilder, + int? itemCount, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + }) : super(delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + final int itemIndex = index ~/ 2; + final Widget? widget; + if (index.isEven) { + widget = itemBuilder(context, itemIndex); + } else { + widget = separatorBuilder(context, itemIndex); + assert(() { + if (widget == null) { + throw FlutterError('separatorBuilder cannot return null.'); + } + return true; + }()); + } + return widget; + }, + findChildIndexCallback: findChildIndexCallback, + childCount: itemCount == null ? null : math.max(0, itemCount * 2 - 1), + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + semanticIndexCallback: (Widget _, int index) { + return index.isEven ? index ~/ 2 : null; + }, + )); + + /// A sliver that places multiple box children in a linear array along the main + /// axis. + /// + /// This constructor uses a list of [Widget]s to build the sliver. + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. + /// + /// {@tool snippet} + /// This example, which would be provided in [CustomScrollView.slivers], + /// shows a list containing two [Text] widgets: + /// + /// ```dart + /// SliverList.list( + /// children: const <Widget>[ + /// Text('Hello'), + /// Text('World!'), + /// ], + /// ); + /// ``` + /// {@end-tool} + SliverList.list({ + super.key, + required List<Widget> children, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + }) : super(delegate: SliverChildListDelegate( + children, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + )); + + @override + SliverMultiBoxAdaptorElement createElement() => SliverMultiBoxAdaptorElement(this, replaceMovedChildren: true); + + @override + RenderSliverList createRenderObject(BuildContext context) { + final SliverMultiBoxAdaptorElement element = context as SliverMultiBoxAdaptorElement; + return RenderSliverList(childManager: element); + } +} + +/// A sliver that places multiple box children with the same main axis extent in +/// a linear array. +/// +/// _To learn more about slivers, see [CustomScrollView.slivers]._ +/// +/// [SliverFixedExtentList] places its children in a linear array along the main +/// axis starting at offset zero and without gaps. Each child is forced to have +/// the [itemExtent] in the main axis and the +/// [SliverConstraints.crossAxisExtent] in the cross axis. +/// +/// [SliverFixedExtentList] is more efficient than [SliverList] because +/// [SliverFixedExtentList] does not need to perform layout on its children to +/// obtain their extent in the main axis. +/// +/// {@tool snippet} +/// +/// This example, which would be inserted into a [CustomScrollView.slivers] +/// list, shows an infinite number of items in varying shades of blue: +/// +/// ```dart +/// SliverFixedExtentList( +/// itemExtent: 50.0, +/// delegate: SliverChildBuilderDelegate( +/// (BuildContext context, int index) { +/// return Container( +/// alignment: Alignment.center, +/// color: Colors.lightBlue[100 * (index % 9)], +/// child: Text('list item $index'), +/// ); +/// }, +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@macro flutter.widgets.SliverChildDelegate.lifecycle} +/// +/// See also: +/// +/// * [SliverPrototypeExtentList], which is similar to [SliverFixedExtentList] +/// except that it uses a prototype list item instead of a pixel value to define +/// the main axis extent of each item. +/// * [SliverFillViewport], which determines the [itemExtent] based on +/// [SliverConstraints.viewportMainAxisExtent]. +/// * [SliverList], which does not require its children to have the same +/// extent in the main axis. +class SliverFixedExtentList extends SliverMultiBoxAdaptorWidget { + /// Creates a sliver that places box children with the same main axis extent + /// in a linear array. + const SliverFixedExtentList({ + super.key, + required super.delegate, + required this.itemExtent, + }); + + /// A sliver that places multiple box children in a linear array along the main + /// axis. + /// + /// [SliverFixedExtentList] places its children in a linear array along the main + /// axis starting at offset zero and without gaps. Each child is forced to have + /// the [itemExtent] in the main axis and the + /// [SliverConstraints.crossAxisExtent] in the cross axis. + /// + /// This constructor is appropriate for sliver lists with a large (or + /// infinite) number of children whose extent is already determined. + /// + /// Providing a non-null `itemCount` improves the ability of the [SliverGrid] + /// to estimate the maximum scroll extent. + /// + /// `itemBuilder` will be called only with indices greater than or equal to + /// zero and less than `itemCount`. + /// + /// {@macro flutter.widgets.ListView.builder.itemBuilder} + /// + /// The `itemExtent` argument is the extent of each item. + /// + /// {@macro flutter.widgets.PageView.findChildIndexCallback} + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. + /// {@tool snippet} + /// + /// This example, which would be inserted into a [CustomScrollView.slivers] + /// list, shows an infinite number of items in varying shades of blue: + /// + /// ```dart + /// SliverFixedExtentList.builder( + /// itemExtent: 50.0, + /// itemBuilder: (BuildContext context, int index) { + /// return Container( + /// alignment: Alignment.center, + /// color: Colors.lightBlue[100 * (index % 9)], + /// child: Text('list item $index'), + /// ); + /// }, + /// ) + /// ``` + /// {@end-tool} + SliverFixedExtentList.builder({ + super.key, + required NullableIndexedWidgetBuilder itemBuilder, + required this.itemExtent, + ChildIndexGetter? findChildIndexCallback, + int? itemCount, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + }) : super(delegate: SliverChildBuilderDelegate( + itemBuilder, + findChildIndexCallback: findChildIndexCallback, + childCount: itemCount, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + )); + + /// A sliver that places multiple box children in a linear array along the main + /// axis. + /// + /// [SliverFixedExtentList] places its children in a linear array along the main + /// axis starting at offset zero and without gaps. Each child is forced to have + /// the [itemExtent] in the main axis and the + /// [SliverConstraints.crossAxisExtent] in the cross axis. + /// + /// This constructor uses a list of [Widget]s to build the sliver. + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. + /// + /// {@tool snippet} + /// This example, which would be inserted into a [CustomScrollView.slivers] + /// list, shows an infinite number of items in varying shades of blue: + /// + /// ```dart + /// SliverFixedExtentList.list( + /// itemExtent: 50.0, + /// children: const <Widget>[ + /// Text('Hello'), + /// Text('World!'), + /// ], + /// ); + /// ``` + /// {@end-tool} + SliverFixedExtentList.list({ + super.key, + required List<Widget> children, + required this.itemExtent, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + }) : super(delegate: SliverChildListDelegate( + children, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + )); + + /// The extent the children are forced to have in the main axis. + final double itemExtent; + + @override + RenderSliverFixedExtentList createRenderObject(BuildContext context) { + final SliverMultiBoxAdaptorElement element = context as SliverMultiBoxAdaptorElement; + return RenderSliverFixedExtentList(childManager: element, itemExtent: itemExtent); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverFixedExtentList renderObject) { + renderObject.itemExtent = itemExtent; + } +} + +/// A sliver that places multiple box children in a two dimensional arrangement. +/// +/// _To learn more about slivers, see [CustomScrollView.slivers]._ +/// +/// [SliverGrid] places its children in arbitrary positions determined by +/// [gridDelegate]. Each child is forced to have the size specified by the +/// [gridDelegate]. +/// +/// The main axis direction of a grid is the direction in which it scrolls; the +/// cross axis direction is the orthogonal direction. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=ORiTTaVY6mM} +/// +/// {@tool snippet} +/// +/// This example, which would be inserted into a [CustomScrollView.slivers] +/// list, shows twenty boxes in a pretty teal grid: +/// +/// ```dart +/// SliverGrid( +/// gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( +/// maxCrossAxisExtent: 200.0, +/// mainAxisSpacing: 10.0, +/// crossAxisSpacing: 10.0, +/// childAspectRatio: 4.0, +/// ), +/// delegate: SliverChildBuilderDelegate( +/// (BuildContext context, int index) { +/// return Container( +/// alignment: Alignment.center, +/// color: Colors.teal[100 * (index % 9)], +/// child: Text('grid item $index'), +/// ); +/// }, +/// childCount: 20, +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@macro flutter.widgets.SliverChildDelegate.lifecycle} +/// +/// See also: +/// +/// * [SliverList], which places its children in a linear array. +/// * [SliverFixedExtentList], which places its children in a linear +/// array with a fixed extent in the main axis. +/// * [SliverPrototypeExtentList], which is similar to [SliverFixedExtentList] +/// except that it uses a prototype list item instead of a pixel value to define +/// the main axis extent of each item. +class SliverGrid extends SliverMultiBoxAdaptorWidget { + /// Creates a sliver that places multiple box children in a two dimensional + /// arrangement. + const SliverGrid({ + super.key, + required super.delegate, + required this.gridDelegate, + }); + + /// A sliver that creates a 2D array of widgets that are created on demand. + /// + /// This constructor is appropriate for sliver grids with a large (or + /// infinite) number of children because the builder is called only for those + /// children that are actually visible. + /// + /// Providing a non-null `itemCount` improves the ability of the [SliverGrid] + /// to estimate the maximum scroll extent. + /// + /// `itemBuilder` will be called only with indices greater than or equal to + /// zero and less than `itemCount`. + /// + /// {@macro flutter.widgets.ListView.builder.itemBuilder} + /// + /// {@macro flutter.widgets.PageView.findChildIndexCallback} + /// + /// The [gridDelegate] argument is required. + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. + SliverGrid.builder({ + super.key, + required this.gridDelegate, + required NullableIndexedWidgetBuilder itemBuilder, + ChildIndexGetter? findChildIndexCallback, + int? itemCount, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + }) : super(delegate: SliverChildBuilderDelegate( + itemBuilder, + findChildIndexCallback: findChildIndexCallback, + childCount: itemCount, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + )); + + /// Creates a sliver that places multiple box children in a two dimensional + /// arrangement with a fixed number of tiles in the cross axis. + /// + /// Uses a [SliverGridDelegateWithFixedCrossAxisCount] as the [gridDelegate], + /// and a [SliverChildListDelegate] as the [delegate]. + /// + /// See also: + /// + /// * [GridView.count], the equivalent constructor for [GridView] widgets. + SliverGrid.count({ + super.key, + required int crossAxisCount, + double mainAxisSpacing = 0.0, + double crossAxisSpacing = 0.0, + double childAspectRatio = 1.0, + List<Widget> children = const <Widget>[], + }) : gridDelegate = SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: crossAxisCount, + mainAxisSpacing: mainAxisSpacing, + crossAxisSpacing: crossAxisSpacing, + childAspectRatio: childAspectRatio, + ), + super(delegate: SliverChildListDelegate(children)); + + /// Creates a sliver that places multiple box children in a two dimensional + /// arrangement with tiles that each have a maximum cross-axis extent. + /// + /// Uses a [SliverGridDelegateWithMaxCrossAxisExtent] as the [gridDelegate], + /// and a [SliverChildListDelegate] as the [delegate]. + /// + /// See also: + /// + /// * [GridView.extent], the equivalent constructor for [GridView] widgets. + SliverGrid.extent({ + super.key, + required double maxCrossAxisExtent, + double mainAxisSpacing = 0.0, + double crossAxisSpacing = 0.0, + double childAspectRatio = 1.0, + List<Widget> children = const <Widget>[], + }) : gridDelegate = SliverGridDelegateWithMaxCrossAxisExtent( + maxCrossAxisExtent: maxCrossAxisExtent, + mainAxisSpacing: mainAxisSpacing, + crossAxisSpacing: crossAxisSpacing, + childAspectRatio: childAspectRatio, + ), + super(delegate: SliverChildListDelegate(children)); + + /// The delegate that controls the size and position of the children. + final SliverGridDelegate gridDelegate; + + @override + RenderSliverGrid createRenderObject(BuildContext context) { + final SliverMultiBoxAdaptorElement element = context as SliverMultiBoxAdaptorElement; + return RenderSliverGrid(childManager: element, gridDelegate: gridDelegate); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverGrid renderObject) { + renderObject.gridDelegate = gridDelegate; + } + + @override + double estimateMaxScrollOffset( + SliverConstraints? constraints, + int firstIndex, + int lastIndex, + double leadingScrollOffset, + double trailingScrollOffset, + ) { + return super.estimateMaxScrollOffset( + constraints, + firstIndex, + lastIndex, + leadingScrollOffset, + trailingScrollOffset, + ) ?? gridDelegate.getLayout(constraints!).computeMaxScrollOffset(delegate.estimatedChildCount!); + } +} + +/// An element that lazily builds children for a [SliverMultiBoxAdaptorWidget]. +/// +/// Implements [RenderSliverBoxChildManager], which lets this element manage +/// the children of subclasses of [RenderSliverMultiBoxAdaptor]. +class SliverMultiBoxAdaptorElement extends RenderObjectElement implements RenderSliverBoxChildManager { + /// Creates an element that lazily builds children for the given widget. + /// + /// If `replaceMovedChildren` is set to true, a new child is proactively + /// inflate for the index that was previously occupied by a child that moved + /// to a new index. The layout offset of the moved child is copied over to the + /// new child. RenderObjects, that depend on the layout offset of existing + /// children during [RenderObject.performLayout] should set this to true + /// (example: [RenderSliverList]). For RenderObjects that figure out the + /// layout offset of their children without looking at the layout offset of + /// existing children this should be set to false (example: + /// [RenderSliverFixedExtentList]) to avoid inflating unnecessary children. + SliverMultiBoxAdaptorElement(SliverMultiBoxAdaptorWidget super.widget, {bool replaceMovedChildren = false}) + : _replaceMovedChildren = replaceMovedChildren; + + final bool _replaceMovedChildren; + + @override + RenderSliverMultiBoxAdaptor get renderObject => super.renderObject as RenderSliverMultiBoxAdaptor; + + @override + void update(covariant SliverMultiBoxAdaptorWidget newWidget) { + final SliverMultiBoxAdaptorWidget oldWidget = widget as SliverMultiBoxAdaptorWidget; + super.update(newWidget); + final SliverChildDelegate newDelegate = newWidget.delegate; + final SliverChildDelegate oldDelegate = oldWidget.delegate; + if (newDelegate != oldDelegate && + (newDelegate.runtimeType != oldDelegate.runtimeType || newDelegate.shouldRebuild(oldDelegate))) { + performRebuild(); + } + } + + final SplayTreeMap<int, Element?> _childElements = SplayTreeMap<int, Element?>(); + RenderBox? _currentBeforeChild; + + @override + void performRebuild() { + super.performRebuild(); + _currentBeforeChild = null; + bool childrenUpdated = false; + assert(_currentlyUpdatingChildIndex == null); + try { + final SplayTreeMap<int, Element?> newChildren = SplayTreeMap<int, Element?>(); + final Map<int, double> indexToLayoutOffset = HashMap<int, double>(); + final SliverMultiBoxAdaptorWidget adaptorWidget = widget as SliverMultiBoxAdaptorWidget; + void processElement(int index) { + _currentlyUpdatingChildIndex = index; + if (_childElements[index] != null && _childElements[index] != newChildren[index]) { + // This index has an old child that isn't used anywhere and should be deactivated. + _childElements[index] = updateChild(_childElements[index], null, index); + childrenUpdated = true; + } + final Element? newChild = updateChild(newChildren[index], _build(index, adaptorWidget), index); + if (newChild != null) { + childrenUpdated = childrenUpdated || _childElements[index] != newChild; + _childElements[index] = newChild; + final SliverMultiBoxAdaptorParentData parentData = newChild.renderObject!.parentData! as SliverMultiBoxAdaptorParentData; + if (index == 0) { + parentData.layoutOffset = 0.0; + } else if (indexToLayoutOffset.containsKey(index)) { + parentData.layoutOffset = indexToLayoutOffset[index]; + } + if (!parentData.keptAlive) { + _currentBeforeChild = newChild.renderObject as RenderBox?; + } + } else { + childrenUpdated = true; + _childElements.remove(index); + } + } + for (final int index in _childElements.keys.toList()) { + final Key? key = _childElements[index]!.widget.key; + final int? newIndex = key == null ? null : adaptorWidget.delegate.findIndexByKey(key); + final SliverMultiBoxAdaptorParentData? childParentData = + _childElements[index]!.renderObject?.parentData as SliverMultiBoxAdaptorParentData?; + + if (childParentData != null && childParentData.layoutOffset != null) { + indexToLayoutOffset[index] = childParentData.layoutOffset!; + } + + if (newIndex != null && newIndex != index) { + // The layout offset of the child being moved is no longer accurate. + if (childParentData != null) { + childParentData.layoutOffset = null; + } + + newChildren[newIndex] = _childElements[index]; + if (_replaceMovedChildren) { + // We need to make sure the original index gets processed. + newChildren.putIfAbsent(index, () => null); + } + // We do not want the remapped child to get deactivated during processElement. + _childElements.remove(index); + } else { + newChildren.putIfAbsent(index, () => _childElements[index]); + } + } + + renderObject.debugChildIntegrityEnabled = false; // Moving children will temporary violate the integrity. + newChildren.keys.forEach(processElement); + // An element rebuild only updates existing children. The underflow check + // is here to make sure we look ahead one more child if we were at the end + // of the child list before the update. By doing so, we can update the max + // scroll offset during the layout phase. Otherwise, the layout phase may + // be skipped, and the scroll view may be stuck at the previous max + // scroll offset. + // + // This logic is not needed if any existing children has been updated, + // because we will not skip the layout phase if that happens. + if (!childrenUpdated && _didUnderflow) { + final int lastKey = _childElements.lastKey() ?? -1; + final int rightBoundary = lastKey + 1; + newChildren[rightBoundary] = _childElements[rightBoundary]; + processElement(rightBoundary); + } + } finally { + _currentlyUpdatingChildIndex = null; + renderObject.debugChildIntegrityEnabled = true; + } + } + + Widget? _build(int index, SliverMultiBoxAdaptorWidget widget) { + return widget.delegate.build(this, index); + } + + @override + void createChild(int index, { required RenderBox? after }) { + assert(_currentlyUpdatingChildIndex == null); + owner!.buildScope(this, () { + final bool insertFirst = after == null; + assert(insertFirst || _childElements[index-1] != null); + _currentBeforeChild = insertFirst ? null : (_childElements[index-1]!.renderObject as RenderBox?); + Element? newChild; + try { + final SliverMultiBoxAdaptorWidget adaptorWidget = widget as SliverMultiBoxAdaptorWidget; + _currentlyUpdatingChildIndex = index; + newChild = updateChild(_childElements[index], _build(index, adaptorWidget), index); + } finally { + _currentlyUpdatingChildIndex = null; + } + if (newChild != null) { + _childElements[index] = newChild; + } else { + _childElements.remove(index); + } + }); + } + + @override + Element? updateChild(Element? child, Widget? newWidget, Object? newSlot) { + final SliverMultiBoxAdaptorParentData? oldParentData = child?.renderObject?.parentData as SliverMultiBoxAdaptorParentData?; + final Element? newChild = super.updateChild(child, newWidget, newSlot); + final SliverMultiBoxAdaptorParentData? newParentData = newChild?.renderObject?.parentData as SliverMultiBoxAdaptorParentData?; + + // Preserve the old layoutOffset if the renderObject was swapped out. + if (oldParentData != newParentData && oldParentData != null && newParentData != null) { + newParentData.layoutOffset = oldParentData.layoutOffset; + } + return newChild; + } + + @override + void forgetChild(Element child) { + assert(child.slot != null); + assert(_childElements.containsKey(child.slot)); + _childElements.remove(child.slot); + super.forgetChild(child); + } + + @override + void removeChild(RenderBox child) { + final int index = renderObject.indexOf(child); + assert(_currentlyUpdatingChildIndex == null); + assert(index >= 0); + owner!.buildScope(this, () { + assert(_childElements.containsKey(index)); + try { + _currentlyUpdatingChildIndex = index; + final Element? result = updateChild(_childElements[index], null, index); + assert(result == null); + } finally { + _currentlyUpdatingChildIndex = null; + } + _childElements.remove(index); + assert(!_childElements.containsKey(index)); + }); + } + + static double _extrapolateMaxScrollOffset( + int firstIndex, + int lastIndex, + double leadingScrollOffset, + double trailingScrollOffset, + int childCount, + ) { + if (lastIndex == childCount - 1) { + return trailingScrollOffset; + } + final int reifiedCount = lastIndex - firstIndex + 1; + final double averageExtent = (trailingScrollOffset - leadingScrollOffset) / reifiedCount; + final int remainingCount = childCount - lastIndex - 1; + return trailingScrollOffset + averageExtent * remainingCount; + } + + @override + double estimateMaxScrollOffset( + SliverConstraints? constraints, { + int? firstIndex, + int? lastIndex, + double? leadingScrollOffset, + double? trailingScrollOffset, + }) { + final int? childCount = estimatedChildCount; + if (childCount == null) { + return double.infinity; + } + return (widget as SliverMultiBoxAdaptorWidget).estimateMaxScrollOffset( + constraints, + firstIndex!, + lastIndex!, + leadingScrollOffset!, + trailingScrollOffset!, + ) ?? _extrapolateMaxScrollOffset( + firstIndex, + lastIndex, + leadingScrollOffset, + trailingScrollOffset, + childCount, + ); + } + + /// The best available estimate of [childCount], or null if no estimate is available. + /// + /// This differs from [childCount] in that [childCount] never returns null (and must + /// not be accessed if the child count is not yet available, meaning the [createChild] + /// method has not been provided an index that does not create a child). + /// + /// See also: + /// + /// * [SliverChildDelegate.estimatedChildCount], to which this getter defers. + int? get estimatedChildCount => (widget as SliverMultiBoxAdaptorWidget).delegate.estimatedChildCount; + + @override + int get childCount { + int? result = estimatedChildCount; + if (result == null) { + // Since childCount was called, we know that we reached the end of + // the list (as in, _build return null once), so we know that the + // list is finite. + // Let's do an open-ended binary search to find the end of the list + // manually. + int lo = 0; + int hi = 1; + final SliverMultiBoxAdaptorWidget adaptorWidget = widget as SliverMultiBoxAdaptorWidget; + const int max = kIsWeb + ? 9007199254740992 // max safe integer on JS (from 0 to this number x != x+1) + : ((1 << 63) - 1); + while (_build(hi - 1, adaptorWidget) != null) { + lo = hi - 1; + if (hi < max ~/ 2) { + hi *= 2; + } else if (hi < max) { + hi = max; + } else { + throw FlutterError( + 'Could not find the number of children in ${adaptorWidget.delegate}.\n' + "The childCount getter was called (implying that the delegate's builder returned null " + 'for a positive index), but even building the child with index $hi (the maximum ' + 'possible integer) did not return null. Consider implementing childCount to avoid ' + 'the cost of searching for the final child.', + ); + } + } + while (hi - lo > 1) { + final int mid = (hi - lo) ~/ 2 + lo; + if (_build(mid - 1, adaptorWidget) == null) { + hi = mid; + } else { + lo = mid; + } + } + result = lo; + } + return result; + } + + @override + void didStartLayout() { + assert(debugAssertChildListLocked()); + } + + @override + void didFinishLayout() { + assert(debugAssertChildListLocked()); + final int firstIndex = _childElements.firstKey() ?? 0; + final int lastIndex = _childElements.lastKey() ?? 0; + (widget as SliverMultiBoxAdaptorWidget).delegate.didFinishLayout(firstIndex, lastIndex); + } + + int? _currentlyUpdatingChildIndex; + + @override + bool debugAssertChildListLocked() { + assert(_currentlyUpdatingChildIndex == null); + return true; + } + + @override + void didAdoptChild(RenderBox child) { + assert(_currentlyUpdatingChildIndex != null); + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + childParentData.index = _currentlyUpdatingChildIndex; + } + + bool _didUnderflow = false; + + @override + void setDidUnderflow(bool value) { + _didUnderflow = value; + } + + @override + void insertRenderObjectChild(covariant RenderObject child, int slot) { + assert(_currentlyUpdatingChildIndex == slot); + assert(renderObject.debugValidateChild(child)); + renderObject.insert(child as RenderBox, after: _currentBeforeChild); + assert(() { + final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData; + assert(slot == childParentData.index); + return true; + }()); + } + + @override + void moveRenderObjectChild(covariant RenderObject child, int oldSlot, int newSlot) { + assert(_currentlyUpdatingChildIndex == newSlot); + renderObject.move(child as RenderBox, after: _currentBeforeChild); + } + + @override + void removeRenderObjectChild(covariant RenderObject child, int slot) { + assert(_currentlyUpdatingChildIndex != null); + renderObject.remove(child as RenderBox); + } + + @override + void visitChildren(ElementVisitor visitor) { + // The toList() is to make a copy so that the underlying list can be modified by + // the visitor: + assert(!_childElements.values.any((Element? child) => child == null)); + _childElements.values.cast<Element>().toList().forEach(visitor); + } + + @override + void debugVisitOnstageChildren(ElementVisitor visitor) { + _childElements.values.cast<Element>().where((Element child) { + final SliverMultiBoxAdaptorParentData parentData = child.renderObject!.parentData! as SliverMultiBoxAdaptorParentData; + final double itemExtent; + switch (renderObject.constraints.axis) { + case Axis.horizontal: + itemExtent = child.renderObject!.paintBounds.width; + case Axis.vertical: + itemExtent = child.renderObject!.paintBounds.height; + } + + return parentData.layoutOffset != null && + parentData.layoutOffset! < renderObject.constraints.scrollOffset + renderObject.constraints.remainingPaintExtent && + parentData.layoutOffset! + itemExtent > renderObject.constraints.scrollOffset; + }).forEach(visitor); + } +} + +/// A sliver widget that makes its sliver child partially transparent. +/// +/// This class paints its sliver child into an intermediate buffer and then +/// blends the sliver back into the scene partially transparent. +/// +/// For values of opacity other than 0.0 and 1.0, this class is relatively +/// expensive because it requires painting the sliver child into an intermediate +/// buffer. For the value 0.0, the sliver child is not painted at all. +/// For the value 1.0, the sliver child is painted immediately without an +/// intermediate buffer. +/// +/// {@tool dartpad} +/// +/// This example shows a [SliverList] when the `_visible` member field is true, +/// and hides it when it is false. +/// +/// This is more efficient than adding and removing the sliver child widget from +/// the tree on demand, but it does not affect how much the list scrolls (the +/// [SliverList] is still present, merely invisible). +/// +/// ** See code in examples/api/lib/widgets/sliver/sliver_opacity.1.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [Opacity], which can apply a uniform alpha effect to its child using the +/// [RenderBox] layout protocol. +/// * [AnimatedOpacity], which uses an animation internally to efficiently +/// animate [Opacity]. +/// * [SliverVisibility], which can hide a child more efficiently (albeit less +/// subtly, because it is either visible or hidden, rather than allowing +/// fractional opacity values). Specifically, the [SliverVisibility.maintain] +/// constructor is equivalent to using a sliver opacity widget with values of +/// `0.0` or `1.0`. +class SliverOpacity extends SingleChildRenderObjectWidget { + /// Creates a sliver that makes its sliver child partially transparent. + /// + /// The [opacity] argument must be between zero and one, inclusive. + const SliverOpacity({ + super.key, + required this.opacity, + this.alwaysIncludeSemantics = false, + Widget? sliver, + }) : assert(opacity >= 0.0 && opacity <= 1.0), + super(child: sliver); + + /// The fraction to scale the sliver child's alpha value. + /// + /// An opacity of 1.0 is fully opaque. An opacity of 0.0 is fully transparent + /// (i.e. invisible). + /// + /// Values 1.0 and 0.0 are painted with a fast path. Other values + /// require painting the sliver child into an intermediate buffer, which is + /// expensive. + final double opacity; + + /// Whether the semantic information of the sliver child is always included. + /// + /// Defaults to false. + /// + /// When true, regardless of the opacity settings, the sliver child semantic + /// information is exposed as if the widget were fully visible. This is + /// useful in cases where labels may be hidden during animations that + /// would otherwise contribute relevant semantics. + final bool alwaysIncludeSemantics; + + @override + RenderSliverOpacity createRenderObject(BuildContext context) { + return RenderSliverOpacity( + opacity: opacity, + alwaysIncludeSemantics: alwaysIncludeSemantics, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverOpacity renderObject) { + renderObject + ..opacity = opacity + ..alwaysIncludeSemantics = alwaysIncludeSemantics; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<double>('opacity', opacity)); + properties.add(FlagProperty( + 'alwaysIncludeSemantics', + value: alwaysIncludeSemantics, + ifTrue: 'alwaysIncludeSemantics', + )); + } +} + +/// A sliver widget that is invisible during hit testing. +/// +/// When [ignoring] is true, this widget (and its subtree) is invisible +/// to hit testing. It still consumes space during layout and paints its sliver +/// child as usual. It just cannot be the target of located events, because it +/// returns false from [RenderSliver.hitTest]. +/// +/// ## Semantics +/// +/// Using this class may also affect how the semantics subtree underneath is +/// collected. +/// +/// {@macro flutter.widgets.IgnorePointer.semantics} +/// +/// {@macro flutter.widgets.IgnorePointer.ignoringSemantics} +/// +/// See also: +/// +/// * [IgnorePointer], the equivalent widget for boxes. +class SliverIgnorePointer extends SingleChildRenderObjectWidget { + /// Creates a sliver widget that is invisible to hit testing. + const SliverIgnorePointer({ + super.key, + this.ignoring = true, + @Deprecated( + 'Create a custom sliver ignore pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + this.ignoringSemantics, + Widget? sliver, + }) : super(child: sliver); + + /// Whether this sliver is ignored during hit testing. + /// + /// Regardless of whether this sliver is ignored during hit testing, it will + /// still consume space during layout and be visible during painting. + /// + /// {@macro flutter.widgets.IgnorePointer.semantics} + final bool ignoring; + + /// Whether the semantics of this sliver is ignored when compiling the + /// semantics tree. + /// + /// {@macro flutter.widgets.IgnorePointer.ignoringSemantics} + @Deprecated( + 'Create a custom sliver ignore pointer widget instead. ' + 'This feature was deprecated after v3.8.0-12.0.pre.' + ) + final bool? ignoringSemantics; + + @override + RenderSliverIgnorePointer createRenderObject(BuildContext context) { + return RenderSliverIgnorePointer( + ignoring: ignoring, + ignoringSemantics: ignoringSemantics, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverIgnorePointer renderObject) { + renderObject + ..ignoring = ignoring + ..ignoringSemantics = ignoringSemantics; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('ignoring', ignoring)); + properties.add(DiagnosticsProperty<bool>('ignoringSemantics', ignoringSemantics, defaultValue: null)); + } +} + +/// A sliver that lays its sliver child out as if it was in the tree, but +/// without painting anything, without making the sliver child available for hit +/// testing, and without taking any room in the parent. +/// +/// Animations continue to run in offstage sliver children, and therefore use +/// battery and CPU time, regardless of whether the animations end up being +/// visible. +/// +/// To hide a sliver widget from view while it is +/// not needed, prefer removing the widget from the tree entirely rather than +/// keeping it alive in an [Offstage] subtree. +/// +/// See also: +/// +/// * [Offstage], the equivalent widget for boxes. +class SliverOffstage extends SingleChildRenderObjectWidget { + /// Creates a sliver that visually hides its sliver child. + const SliverOffstage({ + super.key, + this.offstage = true, + Widget? sliver, + }) : super(child: sliver); + + /// Whether the sliver child is hidden from the rest of the tree. + /// + /// If true, the sliver child is laid out as if it was in the tree, but + /// without painting anything, without making the child available for hit + /// testing, and without taking any room in the parent. + /// + /// If false, the sliver child is included in the tree as normal. + final bool offstage; + + @override + RenderSliverOffstage createRenderObject(BuildContext context) => RenderSliverOffstage(offstage: offstage); + + @override + void updateRenderObject(BuildContext context, RenderSliverOffstage renderObject) { + renderObject.offstage = offstage; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('offstage', offstage)); + } + + @override + SingleChildRenderObjectElement createElement() => _SliverOffstageElement(this); +} + +class _SliverOffstageElement extends SingleChildRenderObjectElement { + _SliverOffstageElement(SliverOffstage super.widget); + + @override + void debugVisitOnstageChildren(ElementVisitor visitor) { + if (!(widget as SliverOffstage).offstage) { + super.debugVisitOnstageChildren(visitor); + } + } +} + +/// Mark a child as needing to stay alive even when it's in a lazy list that +/// would otherwise remove it. +/// +/// This widget is for use in a [RenderAbstractViewport]s, such as +/// [Viewport] or [TwoDimensionalViewport]. +/// +/// This widget is rarely used directly. The [SliverChildBuilderDelegate] and +/// [SliverChildListDelegate] delegates, used with [SliverList] and +/// [SliverGrid], as well as the scroll view counterparts [ListView] and +/// [GridView], have an `addAutomaticKeepAlives` feature, which is enabled by +/// default, and which causes [AutomaticKeepAlive] widgets to be inserted around +/// each child, causing [KeepAlive] widgets to be automatically added and +/// configured in response to [KeepAliveNotification]s. +/// +/// The same `addAutomaticKeepAlives` feature is supported by the +/// [TwoDimensionalChildBuilderDelegate] and [TwoDimensionalChildListDelegate]. +/// +/// Therefore, to keep a widget alive, it is more common to use those +/// notifications than to directly deal with [KeepAlive] widgets. +/// +/// In practice, the simplest way to deal with these notifications is to mix +/// [AutomaticKeepAliveClientMixin] into one's [State]. See the documentation +/// for that mixin class for details. +class KeepAlive extends ParentDataWidget<KeepAliveParentDataMixin> { + /// Marks a child as needing to remain alive. + const KeepAlive({ + super.key, + required this.keepAlive, + required super.child, + }); + + /// Whether to keep the child alive. + /// + /// If this is false, it is as if this widget was omitted. + final bool keepAlive; + + @override + void applyParentData(RenderObject renderObject) { + assert(renderObject.parentData is KeepAliveParentDataMixin); + final KeepAliveParentDataMixin parentData = renderObject.parentData! as KeepAliveParentDataMixin; + if (parentData.keepAlive != keepAlive) { + // No need to redo layout if it became true. + parentData.keepAlive = keepAlive; + final RenderObject? targetParent = renderObject.parent; + if (targetParent is RenderObject && !keepAlive) { + targetParent.markNeedsLayout(); + } + } + } + + // We only return true if [keepAlive] is true, because turning _off_ keep + // alive requires a layout to do the garbage collection (but turning it on + // requires nothing, since by definition the widget is already alive and won't + // go away _unless_ we do a layout). + @override + bool debugCanApplyOutOfTurn() => keepAlive; + + @override + Type get debugTypicalAncestorWidgetClass => throw FlutterError('Multiple Types are supported, use debugTypicalAncestorWidgetDescription.'); + + @override + String get debugTypicalAncestorWidgetDescription => 'SliverWithKeepAliveWidget or TwoDimensionalViewport'; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<bool>('keepAlive', keepAlive)); + } +} + +/// A sliver that constrains the cross axis extent of its sliver child. +/// +/// The [SliverConstrainedCrossAxis] takes a [maxExtent] parameter and uses it as +/// the cross axis extent of the [SliverConstraints] passed to the sliver child. +/// The widget ensures that the [maxExtent] is a nonnegative value. +/// +/// This is useful when you want to apply a custom cross-axis extent constraint +/// to a sliver child, as slivers typically consume the full cross axis extent. +/// +/// This widget also sets its parent data's [SliverPhysicalParentData.crossAxisFlex] +/// to 0, so that it informs [SliverCrossAxisGroup] that it should not flex +/// in the cross axis direction. +/// +/// {@tool dartpad} +/// In this sample the [SliverConstrainedCrossAxis] sizes its child so that the +/// cross axis extent takes up less space than the actual viewport. +/// +/// ** See code in examples/api/lib/widgets/sliver/sliver_constrained_cross_axis.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverCrossAxisGroup], the widget which makes use of 0 flex factor set by +/// this widget. +class SliverConstrainedCrossAxis extends StatelessWidget { + /// Creates a sliver that constrains the cross axis extent of its sliver child. + /// + /// The [maxExtent] parameter is required and must be nonnegative. + const SliverConstrainedCrossAxis({ + super.key, + required this.maxExtent, + required this.sliver, + }); + + /// The cross axis extent to apply to the sliver child. + /// + /// This value must be nonnegative. + final double maxExtent; + + /// The widget below this widget in the tree. + /// + /// Must be a sliver. + final Widget sliver; + + @override + Widget build(BuildContext context) { + return _SliverZeroFlexParentDataWidget( + sliver: _SliverConstrainedCrossAxis( + maxExtent: maxExtent, + sliver: sliver, + ) + ); + } +} +class _SliverZeroFlexParentDataWidget extends ParentDataWidget<SliverPhysicalParentData> { + const _SliverZeroFlexParentDataWidget({ + required Widget sliver, + }) : super(child: sliver); + + @override + void applyParentData(RenderObject renderObject) { + assert(renderObject.parentData is SliverPhysicalParentData); + final SliverPhysicalParentData parentData = renderObject.parentData! as SliverPhysicalParentData; + bool needsLayout = false; + if (parentData.crossAxisFlex != 0) { + parentData.crossAxisFlex = 0; + needsLayout = true; + } + + if (needsLayout) { + final RenderObject? targetParent = renderObject.parent; + if (targetParent is RenderObject) { + targetParent.markNeedsLayout(); + } + + } + } + + @override + Type get debugTypicalAncestorWidgetClass => SliverCrossAxisGroup; +} + +class _SliverConstrainedCrossAxis extends SingleChildRenderObjectWidget { + const _SliverConstrainedCrossAxis({ + required this.maxExtent, + required Widget sliver, + }) : assert(maxExtent >= 0.0), + super(child: sliver); + + /// The cross axis extent to apply to the sliver child. + /// + /// This value must be nonnegative. + final double maxExtent; + + @override + RenderSliverConstrainedCrossAxis createRenderObject(BuildContext context) { + return RenderSliverConstrainedCrossAxis(maxExtent: maxExtent); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverConstrainedCrossAxis renderObject) { + renderObject.maxExtent = maxExtent; + } +} + +/// Set a flex factor for allocating space in the cross axis direction. +/// +/// This is a [ParentDataWidget] to be used in [SliverCrossAxisGroup]. +/// After all slivers with null or zero flex (e.g. [SliverConstrainedCrossAxis]) +/// are laid out (which should determine their own [SliverGeometry.crossAxisExtent]), +/// the remaining space is laid out among the slivers with nonzero flex +/// proportionally to their flex value. +class SliverCrossAxisExpanded extends ParentDataWidget<SliverPhysicalContainerParentData> { + /// Creates an object that assigns a [flex] value to the child sliver. + /// + /// The provided [flex] value must be greater than 0. + const SliverCrossAxisExpanded({ + super.key, + required this.flex, + required Widget sliver, + }): assert(flex > 0 && flex < double.infinity), + super(child: sliver); + + /// Flex value for allocating cross axis extent left after laying out the children with + /// constrained cross axis. The children with flex values will have the remaining extent + /// allocated proportionally to their flex value. This must an integer between + /// 0 and infinity, exclusive. + final int flex; + + @override + void applyParentData(RenderObject renderObject) { + assert(renderObject.parentData is SliverPhysicalContainerParentData); + assert(renderObject.parent is RenderSliverCrossAxisGroup); + final SliverPhysicalParentData parentData = renderObject.parentData! as SliverPhysicalParentData; + bool needsLayout = false; + + if (parentData.crossAxisFlex != flex) { + parentData.crossAxisFlex = flex; + needsLayout = true; + } + + if (needsLayout) { + final RenderObject? targetParent = renderObject.parent; + if (targetParent is RenderObject) { + targetParent.markNeedsLayout(); + } + } + } + + @override + Type get debugTypicalAncestorWidgetClass => SliverCrossAxisGroup; +} + + +/// A sliver that places multiple sliver children in a linear array along +/// the cross axis. +/// +/// ## Layout algorithm +/// +/// _This section describes how the framework causes [RenderSliverCrossAxisGroup] +/// to position its children._ +/// +/// Layout for a [RenderSliverCrossAxisGroup] has four steps: +/// +/// 1. Layout each child with a null or zero flex factor with cross axis constraint +/// being whatever cross axis space is remaining after laying out any previous +/// sliver. Slivers with null or zero flex factor should determine their own +/// [SliverGeometry.crossAxisExtent]. For example, the [SliverConstrainedCrossAxis] +/// widget uses either [SliverConstrainedCrossAxis.maxExtent] or +/// [SliverConstraints.crossAxisExtent], deciding between whichever is smaller. +/// 2. Divide up the remaining cross axis space among the children with non-zero flex +/// factors according to their flex factor. For example, a child with a flex +/// factor of 2.0 will receive twice the amount of cross axis space as a child +/// with a flex factor 1.0. +/// 3. Layout each of the remaining children with the cross axis constraint +/// allocated in the previous step. +/// 4. Set the geometry to that of whichever child has the longest +/// [SliverGeometry.scrollExtent] with the [SliverGeometry.crossAxisExtent] adjusted +/// to [SliverConstraints.crossAxisExtent]. +/// +/// {@tool dartpad} +/// In this sample the [SliverCrossAxisGroup] sizes its three [children] so that +/// the first normal [SliverList] has a flex factor of 1, the second [SliverConstrainedCrossAxis] +/// has a flex factor of 0 and a maximum cross axis extent of 200.0, and the third +/// [SliverCrossAxisExpanded] has a flex factor of 2. +/// +/// ** See code in examples/api/lib/widgets/sliver/sliver_cross_axis_group.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverCrossAxisExpanded], which is the [ParentDataWidget] for setting a flex +/// value to a widget. +/// * [SliverConstrainedCrossAxis], which is a [RenderObjectWidget] for setting +/// an extent to constrain the widget to. +/// * [SliverMainAxisGroup], which is the [RenderObjectWidget] for laying out +/// multiple slivers along the main axis. +class SliverCrossAxisGroup extends MultiChildRenderObjectWidget { + /// Creates a sliver that places sliver children in a linear array along + /// the cross axis. + const SliverCrossAxisGroup({ + super.key, + required List<Widget> slivers, + }): super(children: slivers); + + @override + RenderSliverCrossAxisGroup createRenderObject(BuildContext context) { + return RenderSliverCrossAxisGroup(); + } +} + +/// A sliver that places multiple sliver children in a linear array along +/// the main axis, one after another. +/// +/// ## Layout algorithm +/// +/// _This section describes how the framework causes [RenderSliverMainAxisGroup] +/// to position its children._ +/// +/// Layout for a [RenderSliverMainAxisGroup] has four steps: +/// +/// 1. Keep track of an offset variable which is the total [SliverGeometry.scrollExtent] +/// of the slivers laid out so far. +/// 2. To determine the constraints for the next sliver child to layout, calculate the +/// amount of paint extent occupied from 0.0 to the offset variable and subtract this from +/// [SliverConstraints.remainingPaintExtent] minus to use as the child's +/// [SliverConstraints.remainingPaintExtent]. For the [SliverConstraints.scrollOffset], +/// take the provided constraint's value and subtract out the offset variable, using +/// 0.0 if negative. +/// 3. Once we finish laying out all the slivers, this offset variable represents +/// the total [SliverGeometry.scrollExtent] of the sliver group. Since it is possible +/// for specialized slivers to try to paint itself outside of the bounds of the +/// sliver group's scroll extent (see [SliverPersistentHeader]), we must do a +/// second pass to set a [SliverPhysicalParentData.paintOffset] to make sure it +/// is within the bounds of the sliver group. +/// 4. Finally, set the [RenderSliverMainAxisGroup.geometry] with the total +/// [SliverGeometry.scrollExtent], [SliverGeometry.paintExtent] calculated from +/// the constraints and [SliverGeometry.scrollExtent], and [SliverGeometry.maxPaintExtent]. +/// +/// {@tool dartpad} +/// In this sample the [CustomScrollView] renders a [SliverMainAxisGroup] and a +/// [SliverToBoxAdapter] with some content. The [SliverMainAxisGroup] renders a +/// [SliverAppBar], [SliverList], and [SliverToBoxAdapter]. Notice that when the +/// [SliverMainAxisGroup] goes out of view, so does the pinned [SliverAppBar]. +/// +/// ** See code in examples/api/lib/widgets/sliver/sliver_main_axis_group.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SliverPersistentHeader], which is a [RenderObjectWidget] which may require +/// adjustment to its [SliverPhysicalParentData.paintOffset] to make it fit +/// within the computed [SliverGeometry.scrollExtent] of the [SliverMainAxisGroup]. +/// * [SliverCrossAxisGroup], which is the [RenderObjectWidget] for laying out +/// multiple slivers along the cross axis. +class SliverMainAxisGroup extends MultiChildRenderObjectWidget { + /// Creates a sliver that places sliver children in a linear array along + /// the main axis. + const SliverMainAxisGroup({ + super.key, + required List<Widget> slivers, + }) : super(children: slivers); + + @override + RenderSliverMainAxisGroup createRenderObject(BuildContext context) { + return RenderSliverMainAxisGroup(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_fill.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_fill.dart new file mode 100644 index 0000000000000000000000000000000000000000..f39a5f1b1a16fdf28dc1e761bdec622d244879dd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_fill.dart @@ -0,0 +1,347 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; +import 'scroll_delegate.dart'; +import 'sliver.dart'; + +/// A sliver that contains multiple box children that each fills the viewport. +/// +/// _To learn more about slivers, see [CustomScrollView.slivers]._ +/// +/// [SliverFillViewport] places its children in a linear array along the main +/// axis. Each child is sized to fill the viewport, both in the main and cross +/// axis. +/// +/// See also: +/// +/// * [SliverFixedExtentList], which has a configurable +/// [SliverFixedExtentList.itemExtent]. +/// * [SliverPrototypeExtentList], which is similar to [SliverFixedExtentList] +/// except that it uses a prototype list item instead of a pixel value to define +/// the main axis extent of each item. +/// * [SliverList], which does not require its children to have the same +/// extent in the main axis. +class SliverFillViewport extends StatelessWidget { + /// Creates a sliver whose box children that each fill the viewport. + const SliverFillViewport({ + super.key, + required this.delegate, + this.viewportFraction = 1.0, + this.padEnds = true, + }) : assert(viewportFraction > 0.0); + + /// The fraction of the viewport that each child should fill in the main axis. + /// + /// If this fraction is less than 1.0, more than one child will be visible at + /// once. If this fraction is greater than 1.0, each child will be larger than + /// the viewport in the main axis. + final double viewportFraction; + + /// Whether to add padding to both ends of the list. + /// + /// If this is set to true and [viewportFraction] < 1.0, padding will be added + /// such that the first and last child slivers will be in the center of the + /// viewport when scrolled all the way to the start or end, respectively. You + /// may want to set this to false if this [SliverFillViewport] is not the only + /// widget along this main axis, such as in a [CustomScrollView] with multiple + /// children. + /// + /// If [viewportFraction] is greater than one, this option has no effect. + /// Defaults to true. + final bool padEnds; + + /// {@macro flutter.widgets.SliverMultiBoxAdaptorWidget.delegate} + final SliverChildDelegate delegate; + + @override + Widget build(BuildContext context) { + return _SliverFractionalPadding( + viewportFraction: padEnds ? clampDouble(1 - viewportFraction, 0, 1) / 2 : 0, + sliver: _SliverFillViewportRenderObjectWidget( + viewportFraction: viewportFraction, + delegate: delegate, + ), + ); + } +} + +class _SliverFillViewportRenderObjectWidget extends SliverMultiBoxAdaptorWidget { + const _SliverFillViewportRenderObjectWidget({ + required super.delegate, + this.viewportFraction = 1.0, + }) : assert(viewportFraction > 0.0); + + final double viewportFraction; + + @override + RenderSliverFillViewport createRenderObject(BuildContext context) { + final SliverMultiBoxAdaptorElement element = context as SliverMultiBoxAdaptorElement; + return RenderSliverFillViewport(childManager: element, viewportFraction: viewportFraction); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverFillViewport renderObject) { + renderObject.viewportFraction = viewportFraction; + } +} + +class _SliverFractionalPadding extends SingleChildRenderObjectWidget { + const _SliverFractionalPadding({ + this.viewportFraction = 0, + Widget? sliver, + }) : assert(viewportFraction >= 0), + assert(viewportFraction <= 0.5), + super(child: sliver); + + final double viewportFraction; + + @override + RenderObject createRenderObject(BuildContext context) => _RenderSliverFractionalPadding(viewportFraction: viewportFraction); + + @override + void updateRenderObject(BuildContext context, _RenderSliverFractionalPadding renderObject) { + renderObject.viewportFraction = viewportFraction; + } +} + +class _RenderSliverFractionalPadding extends RenderSliverEdgeInsetsPadding { + _RenderSliverFractionalPadding({ + double viewportFraction = 0, + }) : assert(viewportFraction <= 0.5), + assert(viewportFraction >= 0), + _viewportFraction = viewportFraction; + + SliverConstraints? _lastResolvedConstraints; + + double get viewportFraction => _viewportFraction; + double _viewportFraction; + set viewportFraction(double newValue) { + if (_viewportFraction == newValue) { + return; + } + _viewportFraction = newValue; + _markNeedsResolution(); + } + + @override + EdgeInsets? get resolvedPadding => _resolvedPadding; + EdgeInsets? _resolvedPadding; + + void _markNeedsResolution() { + _resolvedPadding = null; + markNeedsLayout(); + } + + void _resolve() { + if (_resolvedPadding != null && _lastResolvedConstraints == constraints) { + return; + } + + final double paddingValue = constraints.viewportMainAxisExtent * viewportFraction; + _lastResolvedConstraints = constraints; + switch (constraints.axis) { + case Axis.horizontal: + _resolvedPadding = EdgeInsets.symmetric(horizontal: paddingValue); + case Axis.vertical: + _resolvedPadding = EdgeInsets.symmetric(vertical: paddingValue); + } + + return; + } + + @override + void performLayout() { + _resolve(); + super.performLayout(); + } +} + +/// A sliver that contains a single box child that fills the remaining space in +/// the viewport. +/// +/// _To learn more about slivers, see [CustomScrollView.slivers]._ +/// +/// [SliverFillRemaining] will size its [child] to fill the viewport in the +/// cross axis. The extent of the sliver and its child's size in the main axis +/// is computed conditionally, described in further detail below. +/// +/// Typically this will be the last sliver in a viewport, since (by definition) +/// there is never any room for anything beyond this sliver. +/// +/// ## Main Axis Extent +/// +/// ### When [SliverFillRemaining] has a scrollable child +/// +/// The [hasScrollBody] flag indicates whether the sliver's child has a +/// scrollable body. This value is never null, and defaults to true. A common +/// example of this use is a [NestedScrollView]. In this case, the sliver will +/// size its child to fill the maximum available extent. [SliverFillRemaining] +/// will not constrain the scrollable area, as it could potentially have an +/// infinite depth. This is also true for use cases such as a [ScrollView] when +/// [ScrollView.shrinkWrap] is true. +/// +/// ### When [SliverFillRemaining] does not have a scrollable child +/// +/// When [hasScrollBody] is set to false, the child's size is taken into account +/// when considering the extent to which it should fill the space. The extent to +/// which the preceding slivers have been scrolled is also taken into +/// account in deciding how to layout this sliver. +/// +/// [SliverFillRemaining] will size its [child] to fill the viewport in the +/// main axis if that space is larger than the child's extent, and the amount +/// of space that has been scrolled beforehand has not exceeded the main axis +/// extent of the viewport. +/// +/// {@tool dartpad} +/// In this sample the [SliverFillRemaining] sizes its [child] to fill the +/// remaining extent of the viewport in both axes. The icon is centered in the +/// sliver, and would be in any computed extent for the sliver. +/// +/// ** See code in examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.0.dart ** +/// {@end-tool} +/// +/// [SliverFillRemaining] will defer to the size of its [child] if the +/// child's size exceeds the remaining space in the viewport. +/// +/// {@tool dartpad} +/// In this sample the [SliverFillRemaining] defers to the size of its [child] +/// because the child's extent exceeds that of the remaining extent of the +/// viewport's main axis. +/// +/// ** See code in examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.1.dart ** +/// {@end-tool} +/// +/// [SliverFillRemaining] will defer to the size of its [child] if the +/// [SliverConstraints.precedingScrollExtent] exceeded the length of the viewport's main axis. +/// +/// {@tool dartpad} +/// In this sample the [SliverFillRemaining] defers to the size of its [child] +/// because the [SliverConstraints.precedingScrollExtent] has gone +/// beyond that of the viewport's main axis. +/// +/// ** See code in examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.2.dart ** +/// {@end-tool} +/// +/// For [ScrollPhysics] that allow overscroll, such as +/// [BouncingScrollPhysics], setting the [fillOverscroll] flag to true allows +/// the size of the [child] to _stretch_, filling the overscroll area. It does +/// this regardless of the path chosen to provide the child's size. +/// +/// {@animation 250 500 https://flutter.github.io/assets-for-api-docs/assets/widgets/sliver_fill_remaining_fill_overscroll.mp4} +/// +/// {@tool dartpad} +/// In this sample the [SliverFillRemaining]'s child stretches to fill the +/// overscroll area when [fillOverscroll] is true. This sample also features a +/// button that is pinned to the bottom of the sliver, regardless of size or +/// overscroll behavior. Try switching [fillOverscroll] to see the difference. +/// +/// This sample only shows the overscroll behavior on devices that support +/// overscroll. +/// +/// ** See code in examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.3.dart ** +/// {@end-tool} +/// +/// +/// See also: +/// +/// * [SliverFillViewport], which sizes its children based on the +/// size of the viewport, regardless of what else is in the scroll view. +/// * [SliverList], which shows a list of variable-sized children in a +/// viewport. +class SliverFillRemaining extends StatelessWidget { + /// Creates a sliver that fills the remaining space in the viewport. + const SliverFillRemaining({ + super.key, + this.child, + this.hasScrollBody = true, + this.fillOverscroll = false, + }); + + /// Box child widget that fills the remaining space in the viewport. + /// + /// The main [SliverFillRemaining] documentation contains more details. + final Widget? child; + + /// Indicates whether the child has a scrollable body, this value cannot be + /// null. + /// + /// Defaults to true such that the child will extend beyond the viewport and + /// scroll, as seen in [NestedScrollView]. + /// + /// Setting this value to false will allow the child to fill the remainder of + /// the viewport and not extend further. However, if the + /// [SliverConstraints.precedingScrollExtent] and/or the [child]'s + /// extent exceeds the size of the viewport, the sliver will defer to the + /// child's size rather than overriding it. + final bool hasScrollBody; + + /// Indicates whether the child should stretch to fill the overscroll area + /// created by certain scroll physics, such as iOS' default scroll physics. + /// This flag is only relevant when [hasScrollBody] is false. + /// + /// Defaults to false, meaning that the default behavior is for the child to + /// maintain its size and not extend into the overscroll area. + final bool fillOverscroll; + + @override + Widget build(BuildContext context) { + if (hasScrollBody) { + return _SliverFillRemainingWithScrollable(child: child); + } + if (!fillOverscroll) { + return _SliverFillRemainingWithoutScrollable(child: child); + } + return _SliverFillRemainingAndOverscroll(child: child); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add( + DiagnosticsProperty<Widget>( + 'child', + child, + ), + ); + final List<String> flags = <String>[ + if (hasScrollBody) 'scrollable', + if (fillOverscroll) 'fillOverscroll', + ]; + if (flags.isEmpty) { + flags.add('nonscrollable'); + } + properties.add(IterableProperty<String>('mode', flags)); + } +} + +class _SliverFillRemainingWithScrollable extends SingleChildRenderObjectWidget { + const _SliverFillRemainingWithScrollable({ + super.child, + }); + + @override + RenderSliverFillRemainingWithScrollable createRenderObject(BuildContext context) => RenderSliverFillRemainingWithScrollable(); +} + +class _SliverFillRemainingWithoutScrollable extends SingleChildRenderObjectWidget { + const _SliverFillRemainingWithoutScrollable({ + super.child, + }); + + @override + RenderSliverFillRemaining createRenderObject(BuildContext context) => RenderSliverFillRemaining(); +} + +class _SliverFillRemainingAndOverscroll extends SingleChildRenderObjectWidget { + const _SliverFillRemainingAndOverscroll({ + super.child, + }); + + @override + RenderSliverFillRemainingAndOverscroll createRenderObject(BuildContext context) => RenderSliverFillRemainingAndOverscroll(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_layout_builder.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_layout_builder.dart new file mode 100644 index 0000000000000000000000000000000000000000..43af22187511ea08418139dff1396111af2a0fa8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_layout_builder.dart @@ -0,0 +1,71 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; +import 'layout_builder.dart'; + +/// The signature of the [SliverLayoutBuilder] builder function. +typedef SliverLayoutWidgetBuilder = Widget Function(BuildContext context, SliverConstraints constraints); + +/// Builds a sliver widget tree that can depend on its own [SliverConstraints]. +/// +/// Similar to the [LayoutBuilder] widget except its builder should return a sliver +/// widget, and [SliverLayoutBuilder] is itself a sliver. The framework calls the +/// [builder] function at layout time and provides the current [SliverConstraints]. +/// The [SliverLayoutBuilder]'s final [SliverGeometry] will match the [SliverGeometry] +/// of its child. +/// +/// {@macro flutter.widgets.ConstrainedLayoutBuilder} +/// +/// See also: +/// +/// * [LayoutBuilder], the non-sliver version of this widget. +class SliverLayoutBuilder extends ConstrainedLayoutBuilder<SliverConstraints> { + /// Creates a sliver widget that defers its building until layout. + const SliverLayoutBuilder({ + super.key, + required super.builder, + }); + + @override + RenderObject createRenderObject(BuildContext context) => _RenderSliverLayoutBuilder(); +} + +class _RenderSliverLayoutBuilder extends RenderSliver with RenderObjectWithChildMixin<RenderSliver>, RenderConstrainedLayoutBuilder<SliverConstraints, RenderSliver> { + @override + double childMainAxisPosition(RenderObject child) { + assert(child == this.child); + return 0; + } + + @override + void performLayout() { + rebuildIfNecessary(); + child?.layout(constraints, parentUsesSize: true); + geometry = child?.geometry ?? SliverGeometry.zero; + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + assert(child == this.child); + // child's offset is always (0, 0), transform.translate(0, 0) does not mutate the transform. + } + + @override + void paint(PaintingContext context, Offset offset) { + // This renderObject does not introduce additional offset to child's position. + if (child?.geometry?.visible ?? false) { + context.paintChild(child!, offset); + } + } + + @override + bool hitTestChildren(SliverHitTestResult result, {required double mainAxisPosition, required double crossAxisPosition}) { + return child != null + && child!.geometry!.hitTestExtent > 0 + && child!.hitTest(result, mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_persistent_header.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_persistent_header.dart new file mode 100644 index 0000000000000000000000000000000000000000..359badf4da7ecbbfad5b413d5c6dfd5e598d9663 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_persistent_header.dart @@ -0,0 +1,515 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart' show TickerProvider; + +import 'framework.dart'; +import 'scroll_position.dart'; +import 'scrollable.dart'; + +/// Delegate for configuring a [SliverPersistentHeader]. +abstract class SliverPersistentHeaderDelegate { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const SliverPersistentHeaderDelegate(); + + /// The widget to place inside the [SliverPersistentHeader]. + /// + /// The `context` is the [BuildContext] of the sliver. + /// + /// The `shrinkOffset` is a distance from [maxExtent] towards [minExtent] + /// representing the current amount by which the sliver has been shrunk. When + /// the `shrinkOffset` is zero, the contents will be rendered with a dimension + /// of [maxExtent] in the main axis. When `shrinkOffset` equals the difference + /// between [maxExtent] and [minExtent] (a positive number), the contents will + /// be rendered with a dimension of [minExtent] in the main axis. The + /// `shrinkOffset` will always be a positive number in that range. + /// + /// The `overlapsContent` argument is true if subsequent slivers (if any) will + /// be rendered beneath this one, and false if the sliver will not have any + /// contents below it. Typically this is used to decide whether to draw a + /// shadow to simulate the sliver being above the contents below it. Typically + /// this is true when `shrinkOffset` is at its greatest value and false + /// otherwise, but that is not guaranteed. See [NestedScrollView] for an + /// example of a case where `overlapsContent`'s value can be unrelated to + /// `shrinkOffset`. + Widget build(BuildContext context, double shrinkOffset, bool overlapsContent); + + /// The smallest size to allow the header to reach, when it shrinks at the + /// start of the viewport. + /// + /// This must return a value equal to or less than [maxExtent]. + /// + /// This value should not change over the lifetime of the delegate. It should + /// be based entirely on the constructor arguments passed to the delegate. See + /// [shouldRebuild], which must return true if a new delegate would return a + /// different value. + double get minExtent; + + /// The size of the header when it is not shrinking at the top of the + /// viewport. + /// + /// This must return a value equal to or greater than [minExtent]. + /// + /// This value should not change over the lifetime of the delegate. It should + /// be based entirely on the constructor arguments passed to the delegate. See + /// [shouldRebuild], which must return true if a new delegate would return a + /// different value. + double get maxExtent; + + /// A [TickerProvider] to use when animating the header's size changes. + /// + /// Must not be null if the persistent header is a floating header, and + /// [snapConfiguration] or [showOnScreenConfiguration] is not null. + TickerProvider? get vsync => null; + + /// Specifies how floating headers should animate in and out of view. + /// + /// If the value of this property is null, then floating headers will + /// not animate into place. + /// + /// This is only used for floating headers (those with + /// [SliverPersistentHeader.floating] set to true). + /// + /// Defaults to null. + FloatingHeaderSnapConfiguration? get snapConfiguration => null; + + /// Specifies an [AsyncCallback] and offset for execution. + /// + /// If the value of this property is null, then callback will not be + /// triggered. + /// + /// This is only used for stretching headers (those with + /// [SliverAppBar.stretch] set to true). + /// + /// Defaults to null. + OverScrollHeaderStretchConfiguration? get stretchConfiguration => null; + + /// Specifies how floating headers and pinned headers should behave in + /// response to [RenderObject.showOnScreen] calls. + /// + /// Defaults to null. + PersistentHeaderShowOnScreenConfiguration? get showOnScreenConfiguration => null; + + /// Whether this delegate is meaningfully different from the old delegate. + /// + /// If this returns false, then the header might not be rebuilt, even though + /// the instance of the delegate changed. + /// + /// This must return true if `oldDelegate` and this object would return + /// different values for [minExtent], [maxExtent], [snapConfiguration], or + /// would return a meaningfully different widget tree from [build] for the + /// same arguments. + bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate); +} + +/// A sliver whose size varies when the sliver is scrolled to the edge +/// of the viewport opposite the sliver's [GrowthDirection]. +/// +/// In the normal case of a [CustomScrollView] with no centered sliver, this +/// sliver will vary its size when scrolled to the leading edge of the viewport. +/// +/// This is the layout primitive that [SliverAppBar] uses for its +/// shrinking/growing effect. +/// +/// _To learn more about slivers, see [CustomScrollView.slivers]._ +class SliverPersistentHeader extends StatelessWidget { + /// Creates a sliver that varies its size when it is scrolled to the start of + /// a viewport. + const SliverPersistentHeader({ + super.key, + required this.delegate, + this.pinned = false, + this.floating = false, + }); + + /// Configuration for the sliver's layout. + /// + /// The delegate provides the following information: + /// + /// * The minimum and maximum dimensions of the sliver. + /// + /// * The builder for generating the widgets of the sliver. + /// + /// * The instructions for snapping the scroll offset, if [floating] is true. + final SliverPersistentHeaderDelegate delegate; + + /// Whether to stick the header to the start of the viewport once it has + /// reached its minimum size. + /// + /// If this is false, the header will continue scrolling off the screen after + /// it has shrunk to its minimum extent. + final bool pinned; + + /// Whether the header should immediately grow again if the user reverses + /// scroll direction. + /// + /// If this is false, the header only grows again once the user reaches the + /// part of the viewport that contains the sliver. + /// + /// The [delegate]'s [SliverPersistentHeaderDelegate.snapConfiguration] is + /// ignored unless [floating] is true. + final bool floating; + + @override + Widget build(BuildContext context) { + if (floating && pinned) { + return _SliverFloatingPinnedPersistentHeader(delegate: delegate); + } + if (pinned) { + return _SliverPinnedPersistentHeader(delegate: delegate); + } + if (floating) { + return _SliverFloatingPersistentHeader(delegate: delegate); + } + return _SliverScrollingPersistentHeader(delegate: delegate); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add( + DiagnosticsProperty<SliverPersistentHeaderDelegate>( + 'delegate', + delegate, + ), + ); + final List<String> flags = <String>[ + if (pinned) 'pinned', + if (floating) 'floating', + ]; + if (flags.isEmpty) { + flags.add('normal'); + } + properties.add(IterableProperty<String>('mode', flags)); + } +} + +class _FloatingHeader extends StatefulWidget { + const _FloatingHeader({ required this.child }); + + final Widget child; + + @override + _FloatingHeaderState createState() => _FloatingHeaderState(); +} + +// A wrapper for the widget created by _SliverPersistentHeaderElement that +// starts and stops the floating app bar's snap-into-view or snap-out-of-view +// animation. It also informs the float when pointer scrolling by updating the +// last known ScrollDirection when scrolling began. +class _FloatingHeaderState extends State<_FloatingHeader> { + ScrollPosition? _position; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (_position != null) { + _position!.isScrollingNotifier.removeListener(_isScrollingListener); + } + _position = Scrollable.maybeOf(context)?.position; + if (_position != null) { + _position!.isScrollingNotifier.addListener(_isScrollingListener); + } + } + + @override + void dispose() { + if (_position != null) { + _position!.isScrollingNotifier.removeListener(_isScrollingListener); + } + super.dispose(); + } + + RenderSliverFloatingPersistentHeader? _headerRenderer() { + return context.findAncestorRenderObjectOfType<RenderSliverFloatingPersistentHeader>(); + } + + void _isScrollingListener() { + assert(_position != null); + + // When a scroll stops, then maybe snap the app bar into view. + // Similarly, when a scroll starts, then maybe stop the snap animation. + // Update the scrolling direction as well for pointer scrolling updates. + final RenderSliverFloatingPersistentHeader? header = _headerRenderer(); + if (_position!.isScrollingNotifier.value) { + header?.updateScrollStartDirection(_position!.userScrollDirection); + // Only SliverAppBars support snapping, headers will not snap. + header?.maybeStopSnapAnimation(_position!.userScrollDirection); + } else { + // Only SliverAppBars support snapping, headers will not snap. + header?.maybeStartSnapAnimation(_position!.userScrollDirection); + } + } + + @override + Widget build(BuildContext context) => widget.child; +} + +class _SliverPersistentHeaderElement extends RenderObjectElement { + _SliverPersistentHeaderElement( + _SliverPersistentHeaderRenderObjectWidget super.widget, { + this.floating = false, + }); + + final bool floating; + + @override + _RenderSliverPersistentHeaderForWidgetsMixin get renderObject => super.renderObject as _RenderSliverPersistentHeaderForWidgetsMixin; + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + renderObject._element = this; + } + + @override + void unmount() { + renderObject._element = null; + super.unmount(); + } + + @override + void update(_SliverPersistentHeaderRenderObjectWidget newWidget) { + final _SliverPersistentHeaderRenderObjectWidget oldWidget = widget as _SliverPersistentHeaderRenderObjectWidget; + super.update(newWidget); + final SliverPersistentHeaderDelegate newDelegate = newWidget.delegate; + final SliverPersistentHeaderDelegate oldDelegate = oldWidget.delegate; + if (newDelegate != oldDelegate && + (newDelegate.runtimeType != oldDelegate.runtimeType || newDelegate.shouldRebuild(oldDelegate))) { + renderObject.triggerRebuild(); + } + } + + @override + void performRebuild() { + super.performRebuild(); + renderObject.triggerRebuild(); + } + + Element? child; + + void _build(double shrinkOffset, bool overlapsContent) { + owner!.buildScope(this, () { + final _SliverPersistentHeaderRenderObjectWidget sliverPersistentHeaderRenderObjectWidget = widget as _SliverPersistentHeaderRenderObjectWidget; + child = updateChild( + child, + floating + ? _FloatingHeader(child: sliverPersistentHeaderRenderObjectWidget.delegate.build( + this, + shrinkOffset, + overlapsContent + )) + : sliverPersistentHeaderRenderObjectWidget.delegate.build(this, shrinkOffset, overlapsContent), + null, + ); + }); + } + + @override + void forgetChild(Element child) { + assert(child == this.child); + this.child = null; + super.forgetChild(child); + } + + @override + void insertRenderObjectChild(covariant RenderBox child, Object? slot) { + assert(renderObject.debugValidateChild(child)); + renderObject.child = child; + } + + @override + void moveRenderObjectChild(covariant RenderObject child, Object? oldSlot, Object? newSlot) { + assert(false); + } + + @override + void removeRenderObjectChild(covariant RenderObject child, Object? slot) { + renderObject.child = null; + } + + @override + void visitChildren(ElementVisitor visitor) { + if (child != null) { + visitor(child!); + } + } +} + +abstract class _SliverPersistentHeaderRenderObjectWidget extends RenderObjectWidget { + const _SliverPersistentHeaderRenderObjectWidget({ + required this.delegate, + this.floating = false, + }); + + final SliverPersistentHeaderDelegate delegate; + final bool floating; + + @override + _SliverPersistentHeaderElement createElement() => _SliverPersistentHeaderElement(this, floating: floating); + + @override + _RenderSliverPersistentHeaderForWidgetsMixin createRenderObject(BuildContext context); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder description) { + super.debugFillProperties(description); + description.add( + DiagnosticsProperty<SliverPersistentHeaderDelegate>( + 'delegate', + delegate, + ), + ); + } +} + +mixin _RenderSliverPersistentHeaderForWidgetsMixin on RenderSliverPersistentHeader { + _SliverPersistentHeaderElement? _element; + + @override + double get minExtent => (_element!.widget as _SliverPersistentHeaderRenderObjectWidget).delegate.minExtent; + + @override + double get maxExtent => (_element!.widget as _SliverPersistentHeaderRenderObjectWidget).delegate.maxExtent; + + @override + void updateChild(double shrinkOffset, bool overlapsContent) { + assert(_element != null); + _element!._build(shrinkOffset, overlapsContent); + } + + @protected + void triggerRebuild() { + markNeedsLayout(); + } +} + +class _SliverScrollingPersistentHeader extends _SliverPersistentHeaderRenderObjectWidget { + const _SliverScrollingPersistentHeader({ + required super.delegate, + }); + + @override + _RenderSliverPersistentHeaderForWidgetsMixin createRenderObject(BuildContext context) { + return _RenderSliverScrollingPersistentHeaderForWidgets( + stretchConfiguration: delegate.stretchConfiguration, + ); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderSliverScrollingPersistentHeaderForWidgets renderObject) { + renderObject.stretchConfiguration = delegate.stretchConfiguration; + } +} + +class _RenderSliverScrollingPersistentHeaderForWidgets extends RenderSliverScrollingPersistentHeader + with _RenderSliverPersistentHeaderForWidgetsMixin { + _RenderSliverScrollingPersistentHeaderForWidgets({ + super.stretchConfiguration, + }); +} + +class _SliverPinnedPersistentHeader extends _SliverPersistentHeaderRenderObjectWidget { + const _SliverPinnedPersistentHeader({ + required super.delegate, + }); + + @override + _RenderSliverPersistentHeaderForWidgetsMixin createRenderObject(BuildContext context) { + return _RenderSliverPinnedPersistentHeaderForWidgets( + stretchConfiguration: delegate.stretchConfiguration, + showOnScreenConfiguration: delegate.showOnScreenConfiguration, + ); + } + + @override + void updateRenderObject(BuildContext context, covariant _RenderSliverPinnedPersistentHeaderForWidgets renderObject) { + renderObject + ..stretchConfiguration = delegate.stretchConfiguration + ..showOnScreenConfiguration = delegate.showOnScreenConfiguration; + } +} + +class _RenderSliverPinnedPersistentHeaderForWidgets extends RenderSliverPinnedPersistentHeader + with _RenderSliverPersistentHeaderForWidgetsMixin { + _RenderSliverPinnedPersistentHeaderForWidgets({ + super.stretchConfiguration, + super.showOnScreenConfiguration, + }); +} + +class _SliverFloatingPersistentHeader extends _SliverPersistentHeaderRenderObjectWidget { + const _SliverFloatingPersistentHeader({ + required super.delegate, + }) : super( + floating: true, + ); + + @override + _RenderSliverPersistentHeaderForWidgetsMixin createRenderObject(BuildContext context) { + return _RenderSliverFloatingPersistentHeaderForWidgets( + vsync: delegate.vsync, + snapConfiguration: delegate.snapConfiguration, + stretchConfiguration: delegate.stretchConfiguration, + showOnScreenConfiguration: delegate.showOnScreenConfiguration, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderSliverFloatingPersistentHeaderForWidgets renderObject) { + renderObject.vsync = delegate.vsync; + renderObject.snapConfiguration = delegate.snapConfiguration; + renderObject.stretchConfiguration = delegate.stretchConfiguration; + renderObject.showOnScreenConfiguration = delegate.showOnScreenConfiguration; + } +} + +class _RenderSliverFloatingPinnedPersistentHeaderForWidgets extends RenderSliverFloatingPinnedPersistentHeader + with _RenderSliverPersistentHeaderForWidgetsMixin { + _RenderSliverFloatingPinnedPersistentHeaderForWidgets({ + required super.vsync, + super.snapConfiguration, + super.stretchConfiguration, + super.showOnScreenConfiguration, + }); +} + +class _SliverFloatingPinnedPersistentHeader extends _SliverPersistentHeaderRenderObjectWidget { + const _SliverFloatingPinnedPersistentHeader({ + required super.delegate, + }) : super( + floating: true, + ); + + @override + _RenderSliverPersistentHeaderForWidgetsMixin createRenderObject(BuildContext context) { + return _RenderSliverFloatingPinnedPersistentHeaderForWidgets( + vsync: delegate.vsync, + snapConfiguration: delegate.snapConfiguration, + stretchConfiguration: delegate.stretchConfiguration, + showOnScreenConfiguration: delegate.showOnScreenConfiguration, + ); + } + + @override + void updateRenderObject(BuildContext context, _RenderSliverFloatingPinnedPersistentHeaderForWidgets renderObject) { + renderObject.vsync = delegate.vsync; + renderObject.snapConfiguration = delegate.snapConfiguration; + renderObject.stretchConfiguration = delegate.stretchConfiguration; + renderObject.showOnScreenConfiguration = delegate.showOnScreenConfiguration; + } +} + +class _RenderSliverFloatingPersistentHeaderForWidgets extends RenderSliverFloatingPersistentHeader + with _RenderSliverPersistentHeaderForWidgetsMixin { + _RenderSliverFloatingPersistentHeaderForWidgets({ + required super.vsync, + super.snapConfiguration, + super.stretchConfiguration, + super.showOnScreenConfiguration, + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_prototype_extent_list.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_prototype_extent_list.dart new file mode 100644 index 0000000000000000000000000000000000000000..923497faef12eb68d70bcf004a194b69ac912a03 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_prototype_extent_list.dart @@ -0,0 +1,294 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; +import 'scroll_delegate.dart'; +import 'sliver.dart'; + +/// A sliver that places its box children in a linear array and constrains them +/// to have the same extent as a prototype item along the main axis. +/// +/// _To learn more about slivers, see [CustomScrollView.slivers]._ +/// +/// [SliverPrototypeExtentList] arranges its children in a line along +/// the main axis starting at offset zero and without gaps. Each child is +/// constrained to the same extent as the [prototypeItem] along the main axis +/// and the [SliverConstraints.crossAxisExtent] along the cross axis. +/// +/// [SliverPrototypeExtentList] is more efficient than [SliverList] because +/// [SliverPrototypeExtentList] does not need to lay out its children to obtain +/// their extent along the main axis. It's a little more flexible than +/// [SliverFixedExtentList] because there's no need to determine the appropriate +/// item extent in pixels. +/// +/// See also: +/// +/// * [SliverFixedExtentList], whose children are forced to a given pixel +/// extent. +/// * [SliverList], which does not require its children to have the same +/// extent in the main axis. +/// * [SliverFillViewport], which sizes its children based on the +/// size of the viewport, regardless of what else is in the scroll view. +class SliverPrototypeExtentList extends SliverMultiBoxAdaptorWidget { + /// Creates a sliver that places its box children in a linear array and + /// constrains them to have the same extent as a prototype item along + /// the main axis. + const SliverPrototypeExtentList({ + super.key, + required super.delegate, + required this.prototypeItem, + }); + + /// A sliver that places its box children in a linear array and constrains them + /// to have the same extent as a prototype item along the main axis. + /// + /// This constructor is appropriate for sliver lists with a large (or + /// infinite) number of children whose extent is already determined. + /// + /// Providing a non-null `itemCount` improves the ability of the [SliverGrid] + /// to estimate the maximum scroll extent. + /// + /// `itemBuilder` will be called only with indices greater than or equal to + /// zero and less than `itemCount`. + /// + /// {@macro flutter.widgets.ListView.builder.itemBuilder} + /// + /// The `prototypeItem` argument is used to determine the extent of each item. + /// + /// {@macro flutter.widgets.PageView.findChildIndexCallback} + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. + /// + /// {@tool snippet} + /// This example, which would be inserted into a [CustomScrollView.slivers] + /// list, shows an infinite number of items in varying shades of blue: + /// + /// ```dart + /// SliverPrototypeExtentList.builder( + /// prototypeItem: Container( + /// alignment: Alignment.center, + /// child: const Text('list item prototype'), + /// ), + /// itemBuilder: (BuildContext context, int index) { + /// return Container( + /// alignment: Alignment.center, + /// color: Colors.lightBlue[100 * (index % 9)], + /// child: Text('list item $index'), + /// ); + /// }, + /// ) + /// ``` + /// {@end-tool} + SliverPrototypeExtentList.builder({ + super.key, + required NullableIndexedWidgetBuilder itemBuilder, + required this.prototypeItem, + ChildIndexGetter? findChildIndexCallback, + int? itemCount, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + }) : super(delegate: SliverChildBuilderDelegate( + itemBuilder, + findChildIndexCallback: findChildIndexCallback, + childCount: itemCount, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + )); + + /// A sliver that places multiple box children in a linear array along the main + /// axis. + /// + /// This constructor uses a list of [Widget]s to build the sliver. + /// + /// The `addAutomaticKeepAlives` argument corresponds to the + /// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The + /// `addRepaintBoundaries` argument corresponds to the + /// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The + /// `addSemanticIndexes` argument corresponds to the + /// [SliverChildBuilderDelegate.addSemanticIndexes] property. + /// + /// {@tool snippet} + /// This example, which would be inserted into a [CustomScrollView.slivers] + /// list, shows an infinite number of items in varying shades of blue: + /// + /// ```dart + /// SliverPrototypeExtentList.list( + /// prototypeItem: const Text('Hello'), + /// children: const <Widget>[ + /// Text('Hello'), + /// Text('World!'), + /// ], + /// ); + /// ``` + /// {@end-tool} + SliverPrototypeExtentList.list({ + super.key, + required List<Widget> children, + required this.prototypeItem, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + }) : super(delegate: SliverChildListDelegate( + children, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + )); + + /// Defines the main axis extent of all of this sliver's children. + /// + /// The [prototypeItem] is laid out before the rest of the sliver's children + /// and its size along the main axis fixes the size of each child. The + /// [prototypeItem] is essentially [Offstage]: it is not painted and it + /// cannot respond to input. + final Widget prototypeItem; + + @override + RenderSliverMultiBoxAdaptor createRenderObject(BuildContext context) { + final _SliverPrototypeExtentListElement element = context as _SliverPrototypeExtentListElement; + return _RenderSliverPrototypeExtentList(childManager: element); + } + + @override + SliverMultiBoxAdaptorElement createElement() => _SliverPrototypeExtentListElement(this); +} + +class _SliverPrototypeExtentListElement extends SliverMultiBoxAdaptorElement { + _SliverPrototypeExtentListElement(SliverPrototypeExtentList super.widget); + + @override + _RenderSliverPrototypeExtentList get renderObject => super.renderObject as _RenderSliverPrototypeExtentList; + + Element? _prototype; + static final Object _prototypeSlot = Object(); + + @override + void insertRenderObjectChild(covariant RenderObject child, covariant Object slot) { + if (slot == _prototypeSlot) { + assert(child is RenderBox); + renderObject.child = child as RenderBox; + } else { + super.insertRenderObjectChild(child, slot as int); + } + } + + @override + void didAdoptChild(RenderBox child) { + if (child != renderObject.child) { + super.didAdoptChild(child); + } + } + + @override + void moveRenderObjectChild(RenderBox child, Object oldSlot, Object newSlot) { + if (newSlot == _prototypeSlot) { + // There's only one prototype child so it cannot be moved. + assert(false); + } else { + super.moveRenderObjectChild(child, oldSlot as int, newSlot as int); + } + } + + @override + void removeRenderObjectChild(RenderBox child, Object slot) { + if (renderObject.child == child) { + renderObject.child = null; + } else { + super.removeRenderObjectChild(child, slot as int); + } + } + + @override + void visitChildren(ElementVisitor visitor) { + if (_prototype != null) { + visitor(_prototype!); + } + super.visitChildren(visitor); + } + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + _prototype = updateChild(_prototype, (widget as SliverPrototypeExtentList).prototypeItem, _prototypeSlot); + } + + @override + void update(SliverPrototypeExtentList newWidget) { + super.update(newWidget); + assert(widget == newWidget); + _prototype = updateChild(_prototype, (widget as SliverPrototypeExtentList).prototypeItem, _prototypeSlot); + } +} + +class _RenderSliverPrototypeExtentList extends RenderSliverFixedExtentBoxAdaptor { + _RenderSliverPrototypeExtentList({ + required _SliverPrototypeExtentListElement childManager, + }) : super(childManager: childManager); + + RenderBox? _child; + RenderBox? get child => _child; + set child(RenderBox? value) { + if (_child != null) { + dropChild(_child!); + } + _child = value; + if (_child != null) { + adoptChild(_child!); + } + markNeedsLayout(); + } + + @override + void performLayout() { + child!.layout(constraints.asBoxConstraints(), parentUsesSize: true); + super.performLayout(); + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + if (_child != null) { + _child!.attach(owner); + } + } + + @override + void detach() { + super.detach(); + if (_child != null) { + _child!.detach(); + } + } + + @override + void redepthChildren() { + if (_child != null) { + redepthChild(_child!); + } + super.redepthChildren(); + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + if (_child != null) { + visitor(_child!); + } + super.visitChildren(visitor); + } + + @override + double get itemExtent { + assert(child != null && child!.hasSize); + return constraints.axis == Axis.vertical ? child!.size.height : child!.size.width; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_resizing_header.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_resizing_header.dart new file mode 100644 index 0000000000000000000000000000000000000000..38a32ad2c1575e2ee21736371ae0b20dfe3ff091 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_resizing_header.dart @@ -0,0 +1,238 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; +import 'slotted_render_object_widget.dart'; + +/// A sliver that is pinned to the start of its [CustomScrollView] and +/// reacts to scrolling by resizing between the intrinsic sizes of its +/// min and max extent prototypes. +/// +/// The minimum and maximum sizes of this sliver are defined by [minExtentPrototype] +/// and [maxExtentPrototype], a pair of widgets that are laid out once. You can +/// use [SizedBox] widgets to define the size limits. +/// +/// If the [minExtentPrototype] is null, then the default minimum extent is 0. If +/// [maxExtentPrototype] is null then the default maximum extent is based on the child's +/// intrisic size. +/// +/// This sliver is preferable to the general purpose [SliverPersistentHeader] +/// for its relatively narrow use case because there's no need to create a +/// [SliverPersistentHeaderDelegate] or to predict the header's minimum or +/// maximum size. +/// +/// {@tool dartpad} +/// This sample shows how this sliver's two extent prototype properties can be used to +/// create a resizing header whose minimum and maximum sizes match small and large +/// configurations of the same header widget. +/// +/// ** See code in examples/api/lib/widgets/sliver/sliver_resizing_header.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [PinnedHeaderSliver] - which just pins the header at the top +/// of the [CustomScrollView]. +/// * [SliverPersistentHeader] - a general purpose header that can be +/// configured as a pinned, resizing, or floating header. +class SliverResizingHeader extends StatelessWidget { + /// Create a pinned header sliver that reacts to scrolling by resizing between + /// the intrinsic sizes of the min and max extent prototypes. + const SliverResizingHeader({ + super.key, + this.minExtentPrototype, + this.maxExtentPrototype, + this.child, + }); + + /// Laid out once to define the minimum size of this sliver along the + /// [CustomScrollView.scrollDirection] axis. + /// + /// If null, the minimum size of the sliver is 0. + /// + /// This widget is never made visible. + final Widget? minExtentPrototype; + + /// Laid out once to define the maximum size of this sliver along the + /// [CustomScrollView.scrollDirection] axis. + /// + /// If null, the maximum extent of the sliver is based on the child's + /// intrinsic size. + /// + /// This widget is never made visible. + final Widget? maxExtentPrototype; + + /// The widget contained by this sliver. + final Widget? child; + + Widget? _excludeFocus(Widget? extentPrototype) { + return extentPrototype != null ? ExcludeFocus(child: extentPrototype) : null; + } + + @override + Widget build(BuildContext context) { + return _SliverResizingHeader( + minExtentPrototype: _excludeFocus(minExtentPrototype), + maxExtentPrototype: _excludeFocus(maxExtentPrototype), + child: child ?? const SizedBox.shrink(), + ); + } +} + +enum _Slot { + minExtent, + maxExtent, + child, +} + +class _SliverResizingHeader extends SlottedMultiChildRenderObjectWidget<_Slot, RenderBox> { + const _SliverResizingHeader({ + this.minExtentPrototype, + this.maxExtentPrototype, + required this.child, + }); + + final Widget? minExtentPrototype; + final Widget? maxExtentPrototype; + final Widget child; + + @override + Iterable<_Slot> get slots => _Slot.values; + + @override + Widget? childForSlot(_Slot slot) { + return switch (slot) { + _Slot.minExtent => minExtentPrototype, + _Slot.maxExtent => maxExtentPrototype, + _Slot.child => child, + }; + } + + @override + _RenderSliverResizingHeader createRenderObject(BuildContext context) { + return _RenderSliverResizingHeader(); + } +} + +class _RenderSliverResizingHeader extends RenderSliver with SlottedContainerRenderObjectMixin<_Slot, RenderBox>, RenderSliverHelpers { + RenderBox? get minExtentPrototype => childForSlot(_Slot.minExtent); + RenderBox? get maxExtentPrototype => childForSlot(_Slot.maxExtent); + RenderBox? get child => childForSlot(_Slot.child); + + @override + Iterable<RenderBox> get children { + return <RenderBox>[ + if (minExtentPrototype != null) minExtentPrototype!, + if (maxExtentPrototype != null) maxExtentPrototype!, + if (child != null) child!, + ]; + } + + double boxExtent(RenderBox box) { + assert(box.hasSize); + return switch (constraints.axis) { + Axis.vertical => box.size.height, + Axis.horizontal => box.size.width, + }; + } + + double get childExtent => child == null ? 0 : boxExtent(child!); + + @override + void setupParentData(RenderObject child) { + if (child.parentData is! SliverPhysicalParentData) { + child.parentData = SliverPhysicalParentData(); + } + } + + @protected + void setChildParentData(RenderObject child, SliverConstraints constraints, SliverGeometry geometry) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + final AxisDirection direction = applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection); + childParentData.paintOffset = switch (direction) { + AxisDirection.up => Offset(0.0, -(geometry.scrollExtent - (geometry.paintExtent + constraints.scrollOffset))), + AxisDirection.right => Offset(-constraints.scrollOffset, 0.0), + AxisDirection.down => Offset(0.0, -constraints.scrollOffset), + AxisDirection.left => Offset(-(geometry.scrollExtent - (geometry.paintExtent + constraints.scrollOffset)), 0.0), + }; + } + + @override + double childMainAxisPosition(covariant RenderObject child) => 0; + + @override + void performLayout() { + final SliverConstraints constraints = this.constraints; + final BoxConstraints prototypeBoxConstraints = constraints.asBoxConstraints(); + + double minExtent = 0; + if (minExtentPrototype != null) { + minExtentPrototype!.layout(prototypeBoxConstraints, parentUsesSize: true); + minExtent = boxExtent(minExtentPrototype!); + } + + late final double maxExtent; + if (maxExtentPrototype != null) { + maxExtentPrototype!.layout(prototypeBoxConstraints, parentUsesSize: true); + maxExtent = boxExtent(maxExtentPrototype!); + } else { + final Size childSize = child!.getDryLayout(prototypeBoxConstraints); + maxExtent = switch (constraints.axis) { + Axis.vertical => childSize.height, + Axis.horizontal => childSize.width, + }; + } + + final double scrollOffset = constraints.scrollOffset; + final double shrinkOffset = math.min(scrollOffset, maxExtent); + final BoxConstraints boxConstraints = constraints.asBoxConstraints( + minExtent: minExtent, + maxExtent: math.max(minExtent, maxExtent - shrinkOffset), + ); + child?.layout(boxConstraints, parentUsesSize: true); + + final double remainingPaintExtent = constraints.remainingPaintExtent; + final double layoutExtent = math.min(childExtent, maxExtent - scrollOffset); + geometry = SliverGeometry( + scrollExtent: maxExtent, + paintOrigin: constraints.overlap, + paintExtent: math.min(childExtent, remainingPaintExtent), + layoutExtent: clampDouble(layoutExtent, 0, remainingPaintExtent), + maxPaintExtent: childExtent, + maxScrollObstructionExtent: childExtent, + cacheExtent: calculateCacheOffset(constraints, from: 0.0, to: childExtent), + hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity. + ); + } + + @override + void applyPaintTransform(RenderObject child, Matrix4 transform) { + final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData; + childParentData.applyPaintTransform(transform); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (child != null && geometry!.visible) { + final SliverPhysicalParentData childParentData = child!.parentData! as SliverPhysicalParentData; + context.paintChild(child!, offset + childParentData.paintOffset); + } + } + + @override + bool hitTestChildren(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }) { + assert(geometry!.hitTestExtent > 0.0); + if (child != null) { + return hitTestBoxChild(BoxHitTestResult.wrap(result), child!, mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition); + } + return false; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_tree.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_tree.dart new file mode 100644 index 0000000000000000000000000000000000000000..ba3eae44ad61a8bc0481bde6b1f4beb9abd6b1db --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_tree.dart @@ -0,0 +1,1003 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'icon.dart'; +import 'icon_data.dart'; +import 'implicit_animations.dart'; +import 'scroll_delegate.dart'; +import 'sliver.dart'; +import 'text.dart'; +import 'ticker_provider.dart'; + +const double _kDefaultRowExtent = 40.0; + +/// A data structure for configuring children of a [TreeSliver]. +/// +/// A [TreeSliverNode.content] can be of any type [T], but must correspond with +/// the same type of the [TreeSliver]. +/// +/// The values returned by [depth], [parent] and [isExpanded] getters are +/// managed by the [TreeSliver]'s state. +class TreeSliverNode<T> { + /// Creates a [TreeSliverNode] instance for use in a [TreeSliver]. + TreeSliverNode( + T content, { + List<TreeSliverNode<T>>? children, + bool expanded = false, + }) : _expanded = children != null && children.isNotEmpty && expanded, + _content = content, + _children = children ?? <TreeSliverNode<T>>[]; + + /// The subject matter of the node. + /// + /// Must correspond with the type of [TreeSliver]. + T get content => _content; + final T _content; + + /// Other [TreeSliverNode]s that this node will be [parent] to. + /// + /// Modifying the children of nodes in a [TreeSliver] will cause the tree to be + /// rebuilt so that newly added active nodes are reflected in the tree. + List<TreeSliverNode<T>> get children => _children; + final List<TreeSliverNode<T>> _children; + + /// Whether or not this node is expanded in the tree. + /// + /// Cannot be expanded if there are no children. + bool get isExpanded => _expanded; + bool _expanded; + + /// The number of parent nodes between this node and the root of the tree. + int? get depth => _depth; + int? _depth; + + /// The parent [TreeSliverNode] of this node. + TreeSliverNode<T>? get parent => _parent; + TreeSliverNode<T>? _parent; + + @override + String toString() { + return 'TreeSliverNode: $content, depth: ${depth == 0 ? 'root' : depth}, ' + '${children.isEmpty ? 'leaf' : 'parent, expanded: $isExpanded'}'; + } +} + +/// Signature for a function that creates a [Widget] to represent the given +/// [TreeSliverNode] in the [TreeSliver]. +/// +/// Used by [TreeSliver.treeNodeBuilder] to build rows on demand for the +/// tree. +typedef TreeSliverNodeBuilder = Widget Function( + BuildContext context, + TreeSliverNode<Object?> node, + AnimationStyle animationStyle, +); + +/// Signature for a function that returns an extent for the given +/// [TreeSliverNode] in the [TreeSliver]. +/// +/// Used by [TreeSliver.treeRowExtentBuilder] to size rows on demand in the +/// tree. The provided [SliverLayoutDimensions] provide information about the +/// current scroll state and [Viewport] dimensions. +/// +/// See also: +/// +/// * [SliverVariedExtentList], which uses a similar item extent builder for +/// dynamic child sizing in the list. +typedef TreeSliverRowExtentBuilder = double Function( + TreeSliverNode<Object?> node, + SliverLayoutDimensions dimensions, +); + +/// Signature for a function that is called when a [TreeSliverNode] is toggled, +/// changing its expanded state. +/// +/// See also: +/// +/// * [TreeSliver.onNodeToggle], for controlling node expansion +/// programmatically. +typedef TreeSliverNodeCallback = void Function(TreeSliverNode<Object?> node); + +/// A mixin for classes implementing a tree structure as expected by a +/// [TreeSliverController]. +/// +/// Used by [TreeSliver] to implement an interface for the +/// [TreeSliverController]. +/// +/// This allows the [TreeSliverController] to be used in other widgets that +/// implement this interface. +/// +/// The type [T] correlates to the type of [TreeSliver] and [TreeSliverNode], +/// representing the type of [TreeSliverNode.content]. +mixin TreeSliverStateMixin<T> { + /// Returns whether or not the given [TreeSliverNode] is expanded. + bool isExpanded(TreeSliverNode<T> node); + + /// Returns whether or not the given [TreeSliverNode] is enclosed within its + /// parent [TreeSliverNode]. + /// + /// If the [TreeSliverNode.parent] [isExpanded] (and all its parents are + /// expanded), or this is a root node, the given node is active and this + /// method will return true. This does not reflect whether or not the node is + /// visible in the [Viewport]. + bool isActive(TreeSliverNode<T> node); + + /// Switches the given [TreeSliverNode]s expanded state. + /// + /// May trigger an animation to reveal or hide the node's children based on + /// the [TreeSliver.toggleAnimationStyle]. + /// + /// If the node does not have any children, nothing will happen. + void toggleNode(TreeSliverNode<T> node); + + /// Closes all parent [TreeSliverNode]s in the tree. + void collapseAll(); + + /// Expands all parent [TreeSliverNode]s in the tree. + void expandAll(); + + /// Retrieves the [TreeSliverNode] containing the associated content, if it + /// exists. + /// + /// If no node exists, this will return null. This does not reflect whether + /// or not a node [isActive], or if it is visible in the viewport. + TreeSliverNode<T>? getNodeFor(T content); + + /// Returns the current row index of the given [TreeSliverNode]. + /// + /// If the node is not currently active in the tree, meaning its parent is + /// collapsed, this will return null. + int? getActiveIndexFor(TreeSliverNode<T> node); +} + +/// Enables control over the [TreeSliverNode]s of a [TreeSliver]. +/// +/// It can be useful to expand or collapse nodes of the tree +/// programmatically, for example to reconfigure an existing node +/// based on a system event. To do so, create a [TreeSliver] +/// with a [TreeSliverController] that's owned by a stateful widget +/// or look up the tree's automatically created [TreeSliverController] +/// with [TreeSliverController.of] +/// +/// The controller's methods to expand or collapse nodes cause the +/// the [TreeSliver] to rebuild, so they may not be called from +/// a build method. +class TreeSliverController { + /// Create a controller to be used with [TreeSliver.controller]. + TreeSliverController(); + + TreeSliverStateMixin<Object?>? _state; + + /// Whether the given [TreeSliverNode] built with this controller is in an + /// expanded state. + /// + /// See also: + /// + /// * [expandNode], which expands a given [TreeSliverNode]. + /// * [collapseNode], which collapses a given [TreeSliverNode]. + /// * [TreeSliver.controller] to create a TreeSliver with a controller. + bool isExpanded(TreeSliverNode<Object?> node) { + assert(_state != null); + return _state!.isExpanded(node); + } + + /// Whether or not the given [TreeSliverNode] is enclosed within its parent + /// [TreeSliverNode]. + /// + /// If the [TreeSliverNode.parent] [isExpanded], or this is a root node, the + /// given node is active and this method will return true. This does not + /// reflect whether or not the node is visible in the [Viewport]. + bool isActive(TreeSliverNode<Object?> node) { + assert(_state != null); + return _state!.isActive(node); + } + + /// Returns the [TreeSliverNode] containing the associated content, if it + /// exists. + /// + /// If no node exists, this will return null. This does not reflect whether + /// or not a node [isActive], or if it is currently visible in the viewport. + TreeSliverNode<Object?>? getNodeFor(Object? content) { + assert(_state != null); + return _state!.getNodeFor(content); + } + + /// Switches the given [TreeSliverNode]s expanded state. + /// + /// May trigger an animation to reveal or hide the node's children based on + /// the [TreeSliver.toggleAnimationStyle]. + /// + /// If the node does not have any children, nothing will happen. + void toggleNode(TreeSliverNode<Object?> node) { + assert(_state != null); + return _state!.toggleNode(node); + } + + /// Expands the [TreeSliverNode] that was built with this controller. + /// + /// If the node is already in the expanded state (see [isExpanded]), calling + /// this method has no effect. + /// + /// Calling this method may cause the [TreeSliver] to rebuild, so it may + /// not be called from a build method. + /// + /// Calling this method will trigger the [TreeSliver.onNodeToggle] + /// callback. + /// + /// See also: + /// + /// * [collapseNode], which collapses the [TreeSliverNode]. + /// * [isExpanded] to check whether the tile is expanded. + /// * [TreeSliver.controller] to create a TreeSliver with a controller. + void expandNode(TreeSliverNode<Object?> node) { + assert(_state != null); + if (!node.isExpanded) { + _state!.toggleNode(node); + } + } + + /// Expands all parent [TreeSliverNode]s in the tree. + void expandAll() { + assert(_state != null); + _state!.expandAll(); + } + + /// Closes all parent [TreeSliverNode]s in the tree. + void collapseAll() { + assert(_state != null); + _state!.collapseAll(); + } + + /// Collapses the [TreeSliverNode] that was built with this controller. + /// + /// If the node is already in the collapsed state (see [isExpanded]), calling + /// this method has no effect. + /// + /// Calling this method may cause the [TreeSliver] to rebuild, so it may + /// not be called from a build method. + /// + /// Calling this method will trigger the [TreeSliver.onNodeToggle] + /// callback. + /// + /// See also: + /// + /// * [expandNode], which expands the tile. + /// * [isExpanded] to check whether the tile is expanded. + /// * [TreeSliver.controller] to create a TreeSliver with a controller. + void collapseNode(TreeSliverNode<Object?> node) { + assert(_state != null); + if (node.isExpanded) { + _state!.toggleNode(node); + } + } + + /// Returns the current row index of the given [TreeSliverNode]. + /// + /// If the node is not currently active in the tree, meaning its parent is + /// collapsed, this will return null. + int? getActiveIndexFor(TreeSliverNode<Object?> node) { + assert(_state != null); + return _state!.getActiveIndexFor(node); + } + + /// Finds the [TreeSliverController] for the closest [TreeSliver] instance + /// that encloses the given context. + /// + /// If no [TreeSliver] encloses the given context, calling this + /// method will cause an assert in debug mode, and throw an + /// exception in release mode. + /// + /// To return null if there is no [TreeSliver] use [maybeOf] instead. + /// + /// Typical usage of the [TreeSliverController.of] function is to call it + /// from within the `build` method of a descendant of a [TreeSliver]. + /// + /// When the [TreeSliver] is actually created in the same `build` + /// function as the callback that refers to the controller, then the + /// `context` argument to the `build` function can't be used to find + /// the [TreeSliverController] (since it's "above" the widget + /// being returned in the widget tree). In cases like that you can + /// add a [Builder] widget, which provides a new scope with a + /// [BuildContext] that is "under" the [TreeSliver]. + static TreeSliverController of(BuildContext context) { + final _TreeSliverState<Object?>? result = + context.findAncestorStateOfType<_TreeSliverState<Object?>>(); + if (result != null) { + return result.controller; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'TreeController.of() called with a context that does not contain a ' + 'TreeSliver.', + ), + ErrorDescription( + 'No TreeSliver ancestor could be found starting from the context that ' + 'was passed to TreeController.of(). ' + 'This usually happens when the context provided is from the same ' + 'StatefulWidget as that whose build function actually creates the ' + 'TreeSliver widget being sought.', + ), + ErrorHint( + 'There are several ways to avoid this problem. The simplest is to use ' + 'a Builder to get a context that is "under" the TreeSliver.', + ), + ErrorHint( + 'A more efficient solution is to split your build function into ' + 'several widgets. This introduces a new context from which you can ' + 'obtain the TreeSliver. In this solution, you would have an outer ' + 'widget that creates the TreeSliver populated by instances of your new ' + 'inner widgets, and then in these inner widgets you would use ' + 'TreeController.of().', + ), + context.describeElement('The context used was'), + ]); + } + + /// Finds the [TreeSliver] from the closest instance of this class that + /// encloses the given context and returns its [TreeSliverController]. + /// + /// If no [TreeSliver] encloses the given context then return null. + /// To throw an exception instead, use [of] instead of this function. + /// + /// See also: + /// + /// * [of], a similar function to this one that throws if no [TreeSliver] + /// encloses the given context. Also includes some sample code in its + /// documentation. + static TreeSliverController? maybeOf(BuildContext context) { + return context.findAncestorStateOfType<_TreeSliverState<Object?>>()?.controller; + } +} + +int _kDefaultSemanticIndexCallback(Widget _, int localIndex) => localIndex; + +/// A widget that displays [TreeSliverNode]s that expand and collapse in a +/// vertically and horizontally scrolling [Viewport]. +/// +/// The type [T] correlates to the type of [TreeSliver] and [TreeSliverNode], +/// representing the type of [TreeSliverNode.content]. +/// +/// The rows of the tree are laid out on demand by the [Viewport]'s render +/// object, using [TreeSliver.treeNodeBuilder]. This will only be called for the +/// nodes that are visible, or within the [Viewport.cacheExtent]. +/// +/// The [TreeSliver.treeNodeBuilder] returns the [Widget] that represents the +/// given [TreeSliverNode]. +/// +/// The [TreeSliver.treeRowExtentBuilder] returns a double representing the +/// extent of a given node in the main axis. +/// +/// Providing a [TreeSliverController] will enable querying and controlling the +/// state of nodes in the tree. +/// +/// A [TreeSliver] only supports a vertical axis direction of +/// [AxisDirection.down] and a horizontal axis direction of +/// [AxisDirection.right]. +/// +///{@tool dartpad} +/// This example uses a [TreeSliver] to display nodes, highlighting nodes as +/// they are selected. +/// +/// ** See code in examples/api/lib/widgets/sliver/sliver_tree.0.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This example shows a highly customized [TreeSliver] configured to +/// [TreeSliverIndentationType.none]. This allows the indentation to be handled +/// by the developer in [TreeSliver.treeNodeBuilder], where a decoration is +/// used to fill the indented space. +/// +/// ** See code in examples/api/lib/widgets/sliver/sliver_tree.1.dart ** +/// {@end-tool} +class TreeSliver<T> extends StatefulWidget { + /// Creates an instance of a [TreeSliver] for displaying [TreeSliverNode]s + /// that animate expanding and collapsing of nodes. + const TreeSliver({ + super.key, + required this.tree, + this.treeNodeBuilder = TreeSliver.defaultTreeNodeBuilder, + this.treeRowExtentBuilder = TreeSliver.defaultTreeRowExtentBuilder, + this.controller, + this.onNodeToggle, + this.toggleAnimationStyle, + this.indentation = TreeSliverIndentationType.standard, + this.addAutomaticKeepAlives = true, + this.addRepaintBoundaries = true, + this.addSemanticIndexes = true, + this.semanticIndexCallback = _kDefaultSemanticIndexCallback, + this.semanticIndexOffset = 0, + this.findChildIndexCallback, + }); + + /// The list of [TreeSliverNode]s that may be displayed in the [TreeSliver]. + /// + /// Beyond root nodes, whether or not a given [TreeSliverNode] is displayed + /// depends on the [TreeSliverNode.isExpanded] value of its parent. The + /// [TreeSliver] will set the [TreeSliverNode.parent] and + /// [TreeSliverNode.depth] as nodes are built on demand to ensure the + /// integrity of the tree. + final List<TreeSliverNode<T>> tree; + + /// Called to build and entry of the [TreeSliver] for the given node. + /// + /// By default, if this is unset, the [TreeSliver.defaultTreeNodeBuilder] + /// is used. + final TreeSliverNodeBuilder treeNodeBuilder; + + /// Called to calculate the extent of the widget built for the given + /// [TreeSliverNode]. + /// + /// By default, if this is unset, the + /// [TreeSliver.defaultTreeRowExtentBuilder] is used. + /// + /// See also: + /// + /// * [SliverVariedExtentList.itemExtentBuilder], a very similar method that + /// allows users to dynamically compute extents on demand. + final TreeSliverRowExtentBuilder treeRowExtentBuilder; + + /// If provided, the controller can be used to expand and collapse + /// [TreeSliverNode]s, or lookup information about the current state of the + /// [TreeSliver]. + final TreeSliverController? controller; + + /// Called when a [TreeSliverNode] expands or collapses. + /// + /// This will not be called if a [TreeSliverNode] does not have any children. + final TreeSliverNodeCallback? onNodeToggle; + + /// The default [AnimationStyle] for expanding and collapsing nodes in the + /// [TreeSliver]. + /// + /// The default [AnimationStyle.duration] uses + /// [TreeSliver.defaultAnimationDuration], which is 150 milliseconds. + /// + /// The default [AnimationStyle.curve] uses [TreeSliver.defaultAnimationCurve], + /// which is [Curves.linear]. + /// + /// To disable the tree animation, use [AnimationStyle.noAnimation]. + final AnimationStyle? toggleAnimationStyle; + + /// The number of pixels children will be offset by in the cross axis based on + /// their [TreeSliverNode.depth]. + /// + /// {@macro flutter.rendering.TreeSliverIndentationType} + final TreeSliverIndentationType indentation; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.addAutomaticKeepAlives} + final bool addAutomaticKeepAlives; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.addRepaintBoundaries} + final bool addRepaintBoundaries; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.addSemanticIndexes} + final bool addSemanticIndexes; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.semanticIndexCallback} + final SemanticIndexCallback semanticIndexCallback; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.semanticIndexOffset} + final int semanticIndexOffset; + + /// {@macro flutter.widgets.SliverChildBuilderDelegate.findChildIndexCallback} + final int? Function(Key)? findChildIndexCallback; + + /// The default [AnimationStyle] used for node expand and collapse animations, + /// when one has not been provided in [toggleAnimationStyle]. + static AnimationStyle defaultToggleAnimationStyle = AnimationStyle( + curve: defaultAnimationCurve, + duration: defaultAnimationDuration, + ); + + /// A default of [Curves.linear], which is used in the tree's expanding and + /// collapsing node animation. + static const Curve defaultAnimationCurve = Curves.linear; + + /// A default [Duration] of 150 milliseconds, which is used in the tree's + /// expanding and collapsing node animation. + static const Duration defaultAnimationDuration = Duration(milliseconds: 150); + + /// A wrapper method for triggering the expansion or collapse of a + /// [TreeSliverNode]. + /// + /// Used as part of [TreeSliver.defaultTreeNodeBuilder] to wrap the leading + /// icon of parent [TreeSliverNode]s such that tapping on it triggers the + /// animation. + /// + /// If defining your own [TreeSliver.treeNodeBuilder], this method can be used + /// to wrap any part, or all, of the returned widget in order to trigger the + /// change in state for the node. + static Widget wrapChildToToggleNode({ + required TreeSliverNode<Object?> node, + required Widget child, + }) { + return Builder(builder: (BuildContext context) { + return GestureDetector( + onTap: () { + TreeSliverController.of(context).toggleNode(node); + }, + child: child, + ); + }); + } + + /// Returns the fixed default extent for rows in the tree, which is 40 pixels. + /// + /// Used by [TreeSliver.treeRowExtentBuilder]. + static double defaultTreeRowExtentBuilder( + TreeSliverNode<Object?> node, + SliverLayoutDimensions dimensions, + ) { + return _kDefaultRowExtent; + } + + /// Returns the default tree row for a given [TreeSliverNode]. + /// + /// Used by [TreeSliver.treeNodeBuilder]. + /// + /// This will return a [Row] containing the [toString] of + /// [TreeSliverNode.content]. If the [TreeSliverNode] is a parent of + /// additional nodes, a arrow icon will precede the content, and will trigger + /// an expand and collapse animation when tapped. + static Widget defaultTreeNodeBuilder( + BuildContext context, + TreeSliverNode<Object?> node, + AnimationStyle toggleAnimationStyle + ) { + final Duration animationDuration = toggleAnimationStyle.duration + ?? TreeSliver.defaultAnimationDuration; + final Curve animationCurve = toggleAnimationStyle.curve + ?? TreeSliver.defaultAnimationCurve; + final int index = TreeSliverController.of(context).getActiveIndexFor(node)!; + return Padding( + padding: const EdgeInsets.all(8.0), + child: Row(children: <Widget>[ + // Icon for parent nodes + TreeSliver.wrapChildToToggleNode( + node: node, + child: SizedBox.square( + dimension: 30.0, + child: node.children.isNotEmpty + ? AnimatedRotation( + key: ValueKey<int>(index), + turns: node.isExpanded ? 0.25 : 0.0, + duration: animationDuration, + curve: animationCurve, + // Renders a unicode right-facing arrow. > + child: const Icon(IconData(0x25BA), size: 14), + ) + : null, + ), + ), + // Spacer + const SizedBox(width: 8.0), + // Content + Text(node.content.toString()), + ]), + ); + } + + @override + State<TreeSliver<T>> createState() => _TreeSliverState<T>(); +} + +// Used in _SliverTreeState for code simplicity. +typedef _AnimationRecord = ({ + AnimationController controller, + CurvedAnimation animation, + UniqueKey key, +}); + +class _TreeSliverState<T> extends State<TreeSliver<T>> with TickerProviderStateMixin, TreeSliverStateMixin<T> { + TreeSliverController get controller => _treeController!; + TreeSliverController? _treeController; + + final List<TreeSliverNode<T>> _activeNodes = <TreeSliverNode<T>>[]; + bool _shouldUnpackNode(TreeSliverNode<T> node) { + if (node.children.isEmpty) { + // No children to unpack. + return false; + } + if (_currentAnimationForParent[node] != null) { + // Whether expanding or collapsing, the child nodes are still active, so + // unpack. + return true; + } + // If we are not animating, respect node.isExpanded. + return node.isExpanded; + } + void _unpackActiveNodes({ + int depth = 0, + List<TreeSliverNode<T>>? nodes, + TreeSliverNode<T>? parent, + }) { + if (nodes == null) { + _activeNodes.clear(); + nodes = widget.tree; + } + for (final TreeSliverNode<T> node in nodes) { + node._depth = depth; + node._parent = parent; + _activeNodes.add(node); + if (_shouldUnpackNode(node)) { + _unpackActiveNodes( + depth: depth + 1, + nodes: node.children, + parent: node, + ); + } + } + } + + final Map<TreeSliverNode<T>, _AnimationRecord> _currentAnimationForParent = <TreeSliverNode<T>, _AnimationRecord>{}; + final Map<UniqueKey, TreeSliverNodesAnimation> _activeAnimations = <UniqueKey, TreeSliverNodesAnimation>{}; + + @override + void initState() { + _unpackActiveNodes(); + assert( + widget.controller?._state == null, + 'The provided TreeSliverController is already associated with another ' + 'TreeSliver. A TreeSliverController can only be associated with one ' + 'TreeSliver.', + ); + _treeController = widget.controller ?? TreeSliverController(); + _treeController!._state = this; + super.initState(); + } + + @override + void didUpdateWidget(TreeSliver<T> oldWidget) { + super.didUpdateWidget(oldWidget); + // Internal or provided, there is always a tree controller. + assert(_treeController != null); + if (oldWidget.controller == null && widget.controller != null) { + // A new tree controller has been provided, update and dispose of the + // internally generated one. + _treeController!._state = null; + _treeController = widget.controller; + _treeController!._state = this; + } else if (oldWidget.controller != null && widget.controller == null) { + // A tree controller had been provided, but was removed. We need to create + // one internally. + assert(oldWidget.controller == _treeController); + oldWidget.controller!._state = null; + _treeController = TreeSliverController(); + _treeController!._state = this; + } else if (oldWidget.controller != widget.controller) { + assert(oldWidget.controller != null); + assert(widget.controller != null); + assert(oldWidget.controller == _treeController); + // The tree is still being provided a controller, but it has changed. Just + // update it. + _treeController!._state = null; + _treeController = widget.controller; + _treeController!._state = this; + } + // Internal or provided, there is always a tree controller. + assert(_treeController != null); + assert(_treeController!._state != null); + _unpackActiveNodes(); + } + + @override + void dispose() { + _treeController!._state = null; + for (final _AnimationRecord record in _currentAnimationForParent.values) { + record.animation.dispose(); + record.controller.dispose(); + } + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return _SliverTree( + itemCount: _activeNodes.length, + activeAnimations: _activeAnimations, + itemBuilder: (BuildContext context, int index) { + final TreeSliverNode<T> node = _activeNodes[index]; + Widget child = widget.treeNodeBuilder( + context, + node, + widget.toggleAnimationStyle ?? TreeSliver.defaultToggleAnimationStyle, + ); + + if (widget.addRepaintBoundaries) { + child = RepaintBoundary(child: child); + } + if (widget.addSemanticIndexes) { + final int? semanticIndex = widget.semanticIndexCallback(child, index); + if (semanticIndex != null) { + child = IndexedSemantics( + index: semanticIndex + widget.semanticIndexOffset, + child: child, + ); + } + } + + return _TreeNodeParentDataWidget( + depth: node.depth!, + child: child, + ); + }, + itemExtentBuilder: (int index, SliverLayoutDimensions dimensions) { + return widget.treeRowExtentBuilder(_activeNodes[index], dimensions); + }, + addAutomaticKeepAlives: widget.addAutomaticKeepAlives, + findChildIndexCallback: widget.findChildIndexCallback, + indentation: widget.indentation.value, + ); + } + + // TreeStateMixin Implementation + + @override + bool isExpanded(TreeSliverNode<T> node) { + return _getNode(node.content, widget.tree)?.isExpanded ?? false; + } + + @override + bool isActive(TreeSliverNode<T> node) => _activeNodes.contains(node); + + @override + TreeSliverNode<T>? getNodeFor(T content) => _getNode(content, widget.tree); + TreeSliverNode<T>? _getNode(T content, List<TreeSliverNode<T>> tree) { + final List<TreeSliverNode<T>> nextDepth = <TreeSliverNode<T>>[]; + for (final TreeSliverNode<T> node in tree) { + if (node.content == content) { + return node; + } + if (node.children.isNotEmpty) { + nextDepth.addAll(node.children); + } + } + if (nextDepth.isNotEmpty) { + return _getNode(content, nextDepth); + } + return null; + } + + @override + int? getActiveIndexFor(TreeSliverNode<T> node) { + if (_activeNodes.contains(node)) { + return _activeNodes.indexOf(node); + } + return null; + } + + @override + void expandAll() { + final List<TreeSliverNode<T>> activeNodesToExpand = <TreeSliverNode<T>>[]; + _expandAll(widget.tree, activeNodesToExpand); + activeNodesToExpand.reversed.forEach(toggleNode); + } + void _expandAll( + List<TreeSliverNode<T>> tree, + List<TreeSliverNode<T>> activeNodesToExpand, + ) { + for (final TreeSliverNode<T> node in tree) { + if (node.children.isNotEmpty) { + // This is a parent node. + // Expand all the children, and their children. + _expandAll(node.children, activeNodesToExpand); + if (!node.isExpanded) { + // The node itself needs to be expanded. + if (_activeNodes.contains(node)) { + // This is an active node in the tree, add to + // the list to toggle once all hidden nodes + // have been handled. + activeNodesToExpand.add(node); + } else { + // This is a hidden node. Update its expanded state. + node._expanded = true; + } + } + } + } + } + + @override + void collapseAll() { + final List<TreeSliverNode<T>> activeNodesToCollapse = <TreeSliverNode<T>>[]; + _collapseAll(widget.tree, activeNodesToCollapse); + activeNodesToCollapse.reversed.forEach(toggleNode); + } + void _collapseAll( + List<TreeSliverNode<T>> tree, + List<TreeSliverNode<T>> activeNodesToCollapse, + ) { + for (final TreeSliverNode<T> node in tree) { + if (node.children.isNotEmpty) { + // This is a parent node. + // Collapse all the children, and their children. + _collapseAll(node.children, activeNodesToCollapse); + if (node.isExpanded) { + // The node itself needs to be collapsed. + if (_activeNodes.contains(node)) { + // This is an active node in the tree, add to + // the list to toggle once all hidden nodes + // have been handled. + activeNodesToCollapse.add(node); + } else { + // This is a hidden node. Update its expanded state. + node._expanded = false; + } + } + } + } + } + + void _updateActiveAnimations() { + // The indexes of various child node animations can change constantly based + // on more nodes being expanded or collapsed. Compile the indexes and their + // animations keys each time we build with an updated active node list. + _activeAnimations.clear(); + for (final TreeSliverNode<T> node in _currentAnimationForParent.keys) { + final _AnimationRecord animationRecord = _currentAnimationForParent[node]!; + final int leadingChildIndex = _activeNodes.indexOf(node) + 1; + final TreeSliverNodesAnimation animatingChildren = ( + fromIndex: leadingChildIndex, + toIndex: leadingChildIndex + node.children.length - 1, + value: animationRecord.animation.value, + ); + _activeAnimations[animationRecord.key] = animatingChildren; + } + } + + @override + void toggleNode(TreeSliverNode<T> node) { + assert(_activeNodes.contains(node)); + if (node.children.isEmpty) { + // No state to change. + return; + } + setState(() { + node._expanded = !node._expanded; + if (widget.onNodeToggle != null) { + widget.onNodeToggle!(node); + } + if (_currentAnimationForParent[node] != null) { + // Dispose of the old animation if this node was already animating. + _currentAnimationForParent[node]!.animation.dispose(); + } + + final AnimationController controller = _currentAnimationForParent[node]?.controller + ?? AnimationController( + value: node._expanded ? 0.0 : 1.0, + vsync: this, + duration: widget.toggleAnimationStyle?.duration + ?? TreeSliver.defaultAnimationDuration, + )..addStatusListener((AnimationStatus status) { + switch (status) { + case AnimationStatus.dismissed: + case AnimationStatus.completed: + _currentAnimationForParent[node]!.animation.dispose(); + _currentAnimationForParent[node]!.controller.dispose(); + _currentAnimationForParent.remove(node); + _updateActiveAnimations(); + case AnimationStatus.forward: + case AnimationStatus.reverse: + } + })..addListener(() { + setState((){ + _updateActiveAnimations(); + }); + }); + + switch (controller.status) { + case AnimationStatus.forward: + case AnimationStatus.reverse: + // We're interrupting an animation already in progress. + controller.stop(); + case AnimationStatus.dismissed: + case AnimationStatus.completed: + } + + final CurvedAnimation newAnimation = CurvedAnimation( + parent: controller, + curve: widget.toggleAnimationStyle?.curve ?? TreeSliver.defaultAnimationCurve, + ); + _currentAnimationForParent[node] = ( + controller: controller, + animation: newAnimation, + // This key helps us keep track of the lifetime of this animation in the + // render object, since the indexes can change at any time. + key: UniqueKey(), + ); + switch (node._expanded) { + case true: + // Expanding + _unpackActiveNodes(); + controller.forward(); + case false: + // Collapsing + controller.reverse().then((_) { + _unpackActiveNodes(); + }); + } + }); + } +} + +class _TreeNodeParentDataWidget extends ParentDataWidget<TreeSliverNodeParentData> { + const _TreeNodeParentDataWidget({ + required this.depth, + required super.child, + }) : assert(depth >= 0); + + final int depth; + + @override + void applyParentData(RenderObject renderObject) { + final TreeSliverNodeParentData parentData = renderObject.parentData! as TreeSliverNodeParentData; + bool needsLayout = false; + + if (parentData.depth != depth) { + assert(depth >= 0); + parentData.depth = depth; + needsLayout = true; + } + + if (needsLayout) { + renderObject.parent?.markNeedsLayout(); + } + } + + @override + Type get debugTypicalAncestorWidgetClass => _SliverTree; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('depth', depth)); + } +} + +class _SliverTree extends SliverVariedExtentList { + _SliverTree({ + required NullableIndexedWidgetBuilder itemBuilder, + required super.itemExtentBuilder, + required this.activeAnimations, + required this.indentation, + ChildIndexGetter? findChildIndexCallback, + required int itemCount, + bool addAutomaticKeepAlives = true, + }) : super(delegate: SliverChildBuilderDelegate( + itemBuilder, + findChildIndexCallback: findChildIndexCallback, + childCount: itemCount, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: false, // Added in the _SliverTreeState + addSemanticIndexes: false, // Added in the _SliverTreeState + )); + + final Map<UniqueKey, TreeSliverNodesAnimation> activeAnimations; + final double indentation; + + @override + RenderTreeSliver createRenderObject(BuildContext context) { + final SliverMultiBoxAdaptorElement element = context as SliverMultiBoxAdaptorElement; + return RenderTreeSliver( + itemExtentBuilder: itemExtentBuilder, + activeAnimations: activeAnimations, + indentation: indentation, + childManager: element, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderTreeSliver renderObject) { + renderObject + ..itemExtentBuilder = itemExtentBuilder + ..activeAnimations = activeAnimations + ..indentation = indentation; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_varied_extent_list.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_varied_extent_list.dart new file mode 100644 index 0000000000000000000000000000000000000000..b727726b36aa9628c7b31a36b4c9898c2ada6ccb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/sliver_varied_extent_list.dart @@ -0,0 +1,135 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; +import 'scroll_delegate.dart'; +import 'sliver.dart'; + +/// A sliver that places its box children in a linear array and constrains them +/// to have the corresponding extent returned by [itemExtentBuilder]. +/// +/// _To learn more about slivers, see [CustomScrollView.slivers]._ +/// +/// [SliverVariedExtentList] arranges its children in a line along +/// the main axis starting at offset zero and without gaps. Each child is +/// constrained to the corresponding extent along the main axis +/// and the [SliverConstraints.crossAxisExtent] along the cross axis. +/// +/// [SliverVariedExtentList] is more efficient than [SliverList] because +/// [SliverVariedExtentList] does not need to lay out its children to obtain +/// their extent along the main axis. It's a little more flexible than +/// [SliverFixedExtentList] because this allow the children to have different extents. +/// +/// See also: +/// +/// * [SliverFixedExtentList], whose children are forced to a given pixel +/// extent. +/// * [SliverList], which does not require its children to have the same +/// extent in the main axis. +/// * [SliverFillViewport], which sizes its children based on the +/// size of the viewport, regardless of what else is in the scroll view. +class SliverVariedExtentList extends SliverMultiBoxAdaptorWidget { + /// Creates a sliver that places box children with the same main axis extent + /// in a linear array. + const SliverVariedExtentList({ + super.key, + required super.delegate, + required this.itemExtentBuilder, + }); + + /// A sliver that places multiple box children in a linear array along the main + /// axis. + /// + /// [SliverVariedExtentList] places its children in a linear array along the main + /// axis starting at offset zero and without gaps. Each child is forced to have + /// the returned extent of [itemExtentBuilder] in the main axis and the + /// [SliverConstraints.crossAxisExtent] in the cross axis. + /// + /// This constructor is appropriate for sliver lists with a large (or + /// infinite) number of children whose extent is already determined. + /// + /// Providing a non-null `itemCount` improves the ability of the [SliverGrid] + /// to estimate the maximum scroll extent. + SliverVariedExtentList.builder({ + super.key, + required NullableIndexedWidgetBuilder itemBuilder, + required this.itemExtentBuilder, + ChildIndexGetter? findChildIndexCallback, + int? itemCount, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + }) : super(delegate: SliverChildBuilderDelegate( + itemBuilder, + findChildIndexCallback: findChildIndexCallback, + childCount: itemCount, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + )); + + /// A sliver that places multiple box children in a linear array along the main + /// axis. + /// + /// [SliverVariedExtentList] places its children in a linear array along the main + /// axis starting at offset zero and without gaps. Each child is forced to have + /// the returned extent of [itemExtentBuilder] in the main axis and the + /// [SliverConstraints.crossAxisExtent] in the cross axis. + /// + /// This constructor uses a list of [Widget]s to build the sliver. + SliverVariedExtentList.list({ + super.key, + required List<Widget> children, + required this.itemExtentBuilder, + bool addAutomaticKeepAlives = true, + bool addRepaintBoundaries = true, + bool addSemanticIndexes = true, + }) : super(delegate: SliverChildListDelegate( + children, + addAutomaticKeepAlives: addAutomaticKeepAlives, + addRepaintBoundaries: addRepaintBoundaries, + addSemanticIndexes: addSemanticIndexes, + )); + + /// The children extent builder. + final ItemExtentBuilder itemExtentBuilder; + + @override + RenderSliverVariedExtentList createRenderObject(BuildContext context) { + final SliverMultiBoxAdaptorElement element = context as SliverMultiBoxAdaptorElement; + return RenderSliverVariedExtentList(childManager: element, itemExtentBuilder: itemExtentBuilder); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverVariedExtentList renderObject) { + renderObject.itemExtentBuilder = itemExtentBuilder; + } +} + +/// A sliver that places multiple box children with the corresponding main axis extent in +/// a linear array. +class RenderSliverVariedExtentList extends RenderSliverFixedExtentBoxAdaptor { + /// Creates a sliver that contains multiple box children that have a explicit + /// extent in the main axis. + RenderSliverVariedExtentList({ + required super.childManager, + required ItemExtentBuilder itemExtentBuilder, + }) : _itemExtentBuilder = itemExtentBuilder; + + @override + ItemExtentBuilder get itemExtentBuilder => _itemExtentBuilder; + ItemExtentBuilder _itemExtentBuilder; + set itemExtentBuilder(ItemExtentBuilder value) { + if (_itemExtentBuilder == value) { + return; + } + _itemExtentBuilder = value; + markNeedsLayout(); + } + + @override + double? get itemExtent => null; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/slotted_render_object_widget.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/slotted_render_object_widget.dart new file mode 100644 index 0000000000000000000000000000000000000000..1318c046ce3a2359f5c4d55f1a1d95e442b54f9f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/slotted_render_object_widget.dart @@ -0,0 +1,356 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; + +/// A superclass for [RenderObjectWidget]s that configure [RenderObject] +/// subclasses that organize their children in different slots. +/// +/// Implementers of this mixin have to provide the list of available slots by +/// overriding [slots]. The list of slots must never change for a given class +/// implementing this mixin. In the common case, [Enum] values are used as slots +/// and [slots] is typically implemented to return the value of the enum's +/// `values` getter. +/// +/// Furthermore, [childForSlot] must be implemented to return the current +/// widget configuration for a given slot. +/// +/// The [RenderObject] returned by [createRenderObject] and updated by +/// [updateRenderObject] must implement [SlottedContainerRenderObjectMixin]. +/// +/// The type parameter `SlotType` is the type for the slots to be used by this +/// [RenderObjectWidget] and the [RenderObject] it configures. In the typical +/// case, `SlotType` is an [Enum] type. +/// +/// The type parameter `ChildType` is the type used for the [RenderObject] children +/// (e.g. [RenderBox] or [RenderSliver]). In the typical case, `ChildType` is +/// [RenderBox]. This class does not support having different kinds of children +/// for different slots. +/// +/// {@tool dartpad} +/// This example uses the [SlottedMultiChildRenderObjectWidget] in +/// combination with the [SlottedContainerRenderObjectMixin] to implement a +/// widget that provides two slots: topLeft and bottomRight. The widget arranges +/// the children in those slots diagonally. +/// +/// ** See code in examples/api/lib/widgets/slotted_render_object_widget/slotted_multi_child_render_object_widget_mixin.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [MultiChildRenderObjectWidget], which configures a [RenderObject] +/// with a single list of children. +/// * [ListTile], which uses [SlottedMultiChildRenderObjectWidget] in its +/// internal (private) implementation. +abstract class SlottedMultiChildRenderObjectWidget<SlotType, ChildType extends RenderObject> extends RenderObjectWidget with SlottedMultiChildRenderObjectWidgetMixin<SlotType, ChildType> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const SlottedMultiChildRenderObjectWidget({ super.key }); +} + +/// A mixin version of [SlottedMultiChildRenderObjectWidget]. +/// +/// This mixin provides the same logic as extending +/// [SlottedMultiChildRenderObjectWidget] directly. +/// +/// It was deprecated to simplify the process of creating slotted widgets. +@Deprecated( + 'Extend SlottedMultiChildRenderObjectWidget instead of mixing in SlottedMultiChildRenderObjectWidgetMixin. ' + 'This feature was deprecated after v3.10.0-1.5.pre.' +) +mixin SlottedMultiChildRenderObjectWidgetMixin<SlotType, ChildType extends RenderObject> on RenderObjectWidget { + /// Returns a list of all available slots. + /// + /// The list of slots must be static and must never change for a given class + /// implementing this mixin. + /// + /// Typically, an [Enum] is used to identify the different slots. In that case + /// this getter can be implemented by returning what the `values` getter + /// of the enum used returns. + @protected + Iterable<SlotType> get slots; + + /// Returns the widget that is currently occupying the provided `slot`. + /// + /// The [RenderObject] configured by this class will be configured to have + /// the [RenderObject] produced by the returned [Widget] in the provided + /// `slot`. + @protected + Widget? childForSlot(SlotType slot); + + @override + SlottedContainerRenderObjectMixin<SlotType, ChildType> createRenderObject(BuildContext context); + + @override + void updateRenderObject(BuildContext context, SlottedContainerRenderObjectMixin<SlotType, ChildType> renderObject); + + @override + SlottedRenderObjectElement<SlotType, ChildType> createElement() => SlottedRenderObjectElement<SlotType, ChildType>(this); +} + +/// Mixin for a [RenderObject] configured by a [SlottedMultiChildRenderObjectWidget]. +/// +/// The [RenderObject] child currently occupying a given slot can be obtained by +/// calling [childForSlot]. +/// +/// Implementers may consider overriding [children] to return the children +/// of this render object in a consistent order (e.g. hit test order). +/// +/// The type parameter `SlotType` is the type for the slots to be used by this +/// [RenderObject] and the [SlottedMultiChildRenderObjectWidget] it was +/// configured by. In the typical case, `SlotType` is an [Enum] type. +/// +/// The type parameter `ChildType` is the type of [RenderObject] used for the children +/// (e.g. [RenderBox] or [RenderSliver]). In the typical case, `ChildType` is +/// [RenderBox]. This mixin does not support having different kinds of children +/// for different slots. +/// +/// See [SlottedMultiChildRenderObjectWidget] for example code showcasing how +/// this mixin is used in combination with [SlottedMultiChildRenderObjectWidget]. +/// +/// See also: +/// +/// * [ContainerRenderObjectMixin], which organizes its children in a single +/// list. +mixin SlottedContainerRenderObjectMixin<SlotType, ChildType extends RenderObject> on RenderObject { + /// Returns the [RenderObject] child that is currently occupying the provided + /// `slot`. + /// + /// Returns null if no [RenderObject] is configured for the given slot. + @protected + ChildType? childForSlot(SlotType slot) => _slotToChild[slot]; + + /// Returns an [Iterable] of all non-null children. + /// + /// This getter is used by the default implementation of [attach], [detach], + /// [redepthChildren], [visitChildren], and [debugDescribeChildren] to iterate + /// over the children of this [RenderObject]. The base implementation makes no + /// guarantee about the order in which the children are returned. Subclasses + /// for which the child order is important should override this getter and + /// return the children in the desired order. + @protected + Iterable<ChildType> get children => _slotToChild.values; + + /// Returns the debug name for a given `slot`. + /// + /// This method is called by [debugDescribeChildren] for each slot that is + /// currently occupied by a child to obtain a name for that slot for debug + /// outputs. + /// + /// The default implementation calls [EnumName.name] on `slot` if it is an + /// [Enum] value and `toString` if it is not. + @protected + String debugNameForSlot(SlotType slot) { + if (slot is Enum) { + return slot.name; + } + return slot.toString(); + } + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + for (final ChildType child in children) { + child.attach(owner); + } + } + + @override + void detach() { + super.detach(); + for (final ChildType child in children) { + child.detach(); + } + } + + @override + void redepthChildren() { + children.forEach(redepthChild); + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + children.forEach(visitor); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<DiagnosticsNode> value = <DiagnosticsNode>[]; + final Map<ChildType, SlotType> childToSlot = Map<ChildType, SlotType>.fromIterables( + _slotToChild.values, + _slotToChild.keys, + ); + for (final ChildType child in children) { + _addDiagnostics(child, value, debugNameForSlot(childToSlot[child] as SlotType)); + } + return value; + } + + void _addDiagnostics(ChildType child, List<DiagnosticsNode> value, String name) { + value.add(child.toDiagnosticsNode(name: name)); + } + + final Map<SlotType, ChildType> _slotToChild = <SlotType, ChildType>{}; + + void _setChild(ChildType? child, SlotType slot) { + final ChildType? oldChild = _slotToChild[slot]; + if (oldChild != null) { + dropChild(oldChild); + _slotToChild.remove(slot); + } + if (child != null) { + _slotToChild[slot] = child; + adoptChild(child); + } + } + + void _moveChild(ChildType child, SlotType slot, SlotType oldSlot) { + assert(slot != oldSlot); + final ChildType? oldChild = _slotToChild[oldSlot]; + if (oldChild == child) { + _setChild(null, oldSlot); + } + _setChild(child, slot); + } +} + +/// Element used by the [SlottedMultiChildRenderObjectWidget]. +class SlottedRenderObjectElement<SlotType, ChildType extends RenderObject> extends RenderObjectElement { + /// Creates an element that uses the given widget as its configuration. + SlottedRenderObjectElement(SlottedMultiChildRenderObjectWidgetMixin<SlotType, ChildType> super.widget); + + Map<SlotType, Element> _slotToChild = <SlotType, Element>{}; + Map<Key, Element> _keyedChildren = <Key, Element>{}; + + @override + SlottedContainerRenderObjectMixin<SlotType, ChildType> get renderObject => super.renderObject as SlottedContainerRenderObjectMixin<SlotType, ChildType>; + + @override + void visitChildren(ElementVisitor visitor) { + _slotToChild.values.forEach(visitor); + } + + @override + void forgetChild(Element child) { + assert(_slotToChild.containsValue(child)); + assert(child.slot is SlotType); + assert(_slotToChild.containsKey(child.slot)); + _slotToChild.remove(child.slot); + super.forgetChild(child); + } + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + _updateChildren(); + } + + @override + void update(SlottedMultiChildRenderObjectWidgetMixin<SlotType, ChildType> newWidget) { + super.update(newWidget); + assert(widget == newWidget); + _updateChildren(); + } + + List<SlotType>? _debugPreviousSlots; + + void _updateChildren() { + final SlottedMultiChildRenderObjectWidgetMixin<SlotType, ChildType> slottedMultiChildRenderObjectWidgetMixin = widget as SlottedMultiChildRenderObjectWidgetMixin<SlotType, ChildType>; + assert(() { + _debugPreviousSlots ??= slottedMultiChildRenderObjectWidgetMixin.slots.toList(); + return listEquals(_debugPreviousSlots, slottedMultiChildRenderObjectWidgetMixin.slots.toList()); + }(), '${widget.runtimeType}.slots must not change.'); + assert(slottedMultiChildRenderObjectWidgetMixin.slots.toSet().length == slottedMultiChildRenderObjectWidgetMixin.slots.length, 'slots must be unique'); + + final Map<Key, Element> oldKeyedElements = _keyedChildren; + _keyedChildren = <Key, Element>{}; + final Map<SlotType, Element> oldSlotToChild = _slotToChild; + _slotToChild = <SlotType, Element>{}; + + Map<Key, List<Element>>? debugDuplicateKeys; + + for (final SlotType slot in slottedMultiChildRenderObjectWidgetMixin.slots) { + final Widget? widget = slottedMultiChildRenderObjectWidgetMixin.childForSlot(slot); + final Key? newWidgetKey = widget?.key; + + final Element? oldSlotChild = oldSlotToChild[slot]; + final Element? oldKeyChild = oldKeyedElements[newWidgetKey]; + + // Try to find the slot for the correct Element that `widget` should update. + // If key matching fails, resort to `oldSlotChild` from the same slot. + final Element? fromElement; + if (oldKeyChild != null) { + fromElement = oldSlotToChild.remove(oldKeyChild.slot as SlotType); + } else if (oldSlotChild?.widget.key == null) { + fromElement = oldSlotToChild.remove(slot); + } else { + // The only case we can't use `oldSlotChild` is when its widget has a key. + assert(oldSlotChild!.widget.key != newWidgetKey); + fromElement = null; + } + final Element? newChild = updateChild(fromElement, widget, slot); + + if (newChild != null) { + _slotToChild[slot] = newChild; + + if (newWidgetKey != null) { + assert(() { + final Element? existingElement = _keyedChildren[newWidgetKey]; + if (existingElement != null) { + (debugDuplicateKeys ??= <Key, List<Element>>{}) + .putIfAbsent(newWidgetKey, () => <Element>[existingElement]) + .add(newChild); + } + return true; + }()); + _keyedChildren[newWidgetKey] = newChild; + } + } + } + oldSlotToChild.values.forEach(deactivateChild); + assert(_debugDuplicateKeys(debugDuplicateKeys)); + assert(_keyedChildren.values.every(_slotToChild.values.contains), '_keyedChildren ${_keyedChildren.values} should be a subset of ${_slotToChild.values}'); + } + + bool _debugDuplicateKeys(Map<Key, List<Element>>? debugDuplicateKeys) { + if (debugDuplicateKeys == null) { + return true; + } + for (final MapEntry<Key, List<Element>> duplicateKey in debugDuplicateKeys.entries) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('Multiple widgets used the same key in ${widget.runtimeType}.'), + ErrorDescription( + 'The key ${duplicateKey.key} was used by multiple widgets. The offending widgets were:\n' + ), + for (final Element element in duplicateKey.value) ErrorDescription(' - $element\n'), + ErrorDescription( + 'A key can only be specified on one widget at a time in the same parent widget.', + ), + ]); + } + return true; + } + + @override + void insertRenderObjectChild(ChildType child, SlotType slot) { + renderObject._setChild(child, slot); + assert(renderObject._slotToChild[slot] == child); + } + + @override + void removeRenderObjectChild(ChildType child, SlotType slot) { + if (renderObject._slotToChild[slot] == child) { + renderObject._setChild(null, slot); + assert(renderObject._slotToChild[slot] == null); + } + } + + @override + void moveRenderObjectChild(ChildType child, SlotType oldSlot, SlotType newSlot) { + renderObject._moveChild(child, newSlot, oldSlot); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/snapshot_widget.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/snapshot_widget.dart new file mode 100644 index 0000000000000000000000000000000000000000..193616fe38a46e978eb74904c661216d264ce126 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/snapshot_widget.dart @@ -0,0 +1,494 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'media_query.dart'; + +/// Controls how the [SnapshotWidget] paints its child. +enum SnapshotMode { + /// The child is snapshotted, but only if all descendants can be snapshotted. + /// + /// If there is a platform view in the children of a snapshot widget, the + /// snapshot will not be used and the child will be rendered using + /// [SnapshotPainter.paint]. This uses an un-snapshotted child and by default + /// paints it with no additional modification. + permissive, + + /// An error is thrown if the child cannot be snapshotted. + /// + /// This setting is the default state of the [SnapshotWidget]. + normal, + + /// The child is snapshotted and any child platform views are ignored. + /// + /// This mode can be useful if there is a platform view descendant that does + /// not need to be included in the snapshot. + forced, +} + +/// A controller for the [SnapshotWidget] that controls when the child image is displayed +/// and when to regenerated the child image. +/// +/// When the value of [allowSnapshotting] is true, the [SnapshotWidget] will paint the child +/// widgets based on the [SnapshotMode] of the snapshot widget. +/// +/// The controller notifies its listeners when the value of [allowSnapshotting] changes +/// or when [clear] is called. +/// +/// To force [SnapshotWidget] to recreate the child image, call [clear]. +class SnapshotController extends ChangeNotifier { + /// Create a new [SnapshotController]. + /// + /// By default, [allowSnapshotting] is `false` and cannot be `null`. + SnapshotController({ + bool allowSnapshotting = false, + }) : _allowSnapshotting = allowSnapshotting; + + /// Reset the snapshot held by any listening [SnapshotWidget]. + /// + /// This has no effect if [allowSnapshotting] is `false`. + void clear() { + notifyListeners(); + } + + /// Whether a snapshot of this child widget is painted in its place. + bool get allowSnapshotting => _allowSnapshotting; + bool _allowSnapshotting; + set allowSnapshotting(bool value) { + if (value == allowSnapshotting) { + return; + } + _allowSnapshotting = value; + notifyListeners(); + } +} + +/// A widget that can replace its child with a snapshotted version of the child. +/// +/// A snapshot is a frozen texture-backed representation of all child pictures +/// and layers stored as a [ui.Image]. +/// +/// This widget is useful for performing short animations that would otherwise +/// be expensive or that cannot rely on raster caching. For example, scale and +/// skew animations are often expensive to perform on complex children, as are +/// blurs. For a short animation, a widget that contains these expensive effects +/// can be replaced with a snapshot of itself and manipulated instead. +/// +/// For example, the Android Q [ZoomPageTransitionsBuilder] uses a snapshot widget +/// for the forward and entering route to avoid the expensive scale animation. +/// This also has the effect of briefly pausing any animations on the page. +/// +/// Generally, this widget should not be used in places where users expect the +/// child widget to continue animating or to be responsive, such as an unbounded +/// animation. +/// +/// Caveats: +/// +/// * The contents of platform views cannot be captured by a snapshot +/// widget. If a platform view is encountered, then the snapshot widget will +/// determine how to render its children based on the [SnapshotMode]. This +/// defaults to [SnapshotMode.normal] which will throw an exception if a +/// platform view is encountered. +/// +/// * The snapshotting functionality of this widget is not supported on the HTML +/// backend of Flutter for the Web. Setting [SnapshotController.allowSnapshotting] to true +/// may cause an error to be thrown. On the CanvasKit backend of Flutter, the +/// performance of using this widget may regress performance due to the fact +/// that both the UI and engine share a single thread. +class SnapshotWidget extends SingleChildRenderObjectWidget { + /// Create a new [SnapshotWidget]. + /// + /// The [controller] and [child] arguments are required. + const SnapshotWidget({ + super.key, + this.mode = SnapshotMode.normal, + this.painter = const _DefaultSnapshotPainter(), + this.autoresize = false, + required this.controller, + required super.child + }); + + /// The controller that determines when to display the children as a snapshot. + final SnapshotController controller; + + /// Configuration that controls how the snapshot widget decides to paint its children. + /// + /// Defaults to [SnapshotMode.normal], which throws an error when a platform view + /// or texture view is encountered. + /// + /// See [SnapshotMode] for more information. + final SnapshotMode mode; + + /// Whether or not changes in render object size should automatically re-create + /// the snapshot. + /// + /// Defaults to false. + final bool autoresize; + + /// The painter used to paint the child snapshot or child widgets. + final SnapshotPainter painter; + + @override + RenderObject createRenderObject(BuildContext context) { + debugCheckHasMediaQuery(context); + return _RenderSnapshotWidget( + controller: controller, + mode: mode, + devicePixelRatio: MediaQuery.devicePixelRatioOf(context), + painter: painter, + autoresize: autoresize, + ); + } + + @override + void updateRenderObject(BuildContext context, covariant RenderObject renderObject) { + debugCheckHasMediaQuery(context); + (renderObject as _RenderSnapshotWidget) + ..controller = controller + ..mode = mode + ..devicePixelRatio = MediaQuery.devicePixelRatioOf(context) + ..painter = painter + ..autoresize = autoresize; + } +} + +// A render object that conditionally converts its child into a [ui.Image] +// and then paints it in place of the child. +class _RenderSnapshotWidget extends RenderProxyBox { + // Create a new [_RenderSnapshotWidget]. + _RenderSnapshotWidget({ + required double devicePixelRatio, + required SnapshotController controller, + required SnapshotMode mode, + required SnapshotPainter painter, + required bool autoresize, + }) : _devicePixelRatio = devicePixelRatio, + _controller = controller, + _mode = mode, + _painter = painter, + _autoresize = autoresize; + + /// The device pixel ratio used to create the child image. + double get devicePixelRatio => _devicePixelRatio; + double _devicePixelRatio; + set devicePixelRatio(double value) { + if (value == devicePixelRatio) { + return; + } + _devicePixelRatio = value; + if (_childRaster == null) { + return; + } else { + _childRaster?.dispose(); + _childRaster = null; + markNeedsPaint(); + } + } + + /// The painter used to paint the child snapshot or child widgets. + SnapshotPainter get painter => _painter; + SnapshotPainter _painter; + set painter(SnapshotPainter value) { + if (value == painter) { + return; + } + final SnapshotPainter oldPainter = painter; + oldPainter.removeListener(markNeedsPaint); + _painter = value; + if (oldPainter.runtimeType != painter.runtimeType || + painter.shouldRepaint(oldPainter)) { + markNeedsPaint(); + } + if (attached) { + painter.addListener(markNeedsPaint); + } + } + + /// A controller that determines whether to paint the child normally or to + /// paint a snapshotted version of that child. + SnapshotController get controller => _controller; + SnapshotController _controller; + set controller(SnapshotController value) { + if (value == controller) { + return; + } + controller.removeListener(_onRasterValueChanged); + final bool oldValue = controller.allowSnapshotting; + _controller = value; + if (attached) { + controller.addListener(_onRasterValueChanged); + if (oldValue != controller.allowSnapshotting) { + _onRasterValueChanged(); + } + } + } + + /// How the snapshot widget will handle platform views in child layers. + SnapshotMode get mode => _mode; + SnapshotMode _mode; + set mode(SnapshotMode value) { + if (value == _mode) { + return; + } + _mode = value; + markNeedsPaint(); + } + + /// Whether or not changes in render object size should automatically re-rasterize. + bool get autoresize => _autoresize; + bool _autoresize; + set autoresize(bool value) { + if (value == autoresize) { + return; + } + _autoresize = value; + markNeedsPaint(); + } + + ui.Image? _childRaster; + Size? _childRasterSize; + // Set to true if the snapshot mode was not forced and a platform view + // was encountered while attempting to snapshot the child. + bool _disableSnapshotAttempt = false; + + @override + void attach(covariant PipelineOwner owner) { + controller.addListener(_onRasterValueChanged); + painter.addListener(markNeedsPaint); + super.attach(owner); + } + + @override + void detach() { + _disableSnapshotAttempt = false; + controller.removeListener(_onRasterValueChanged); + painter.removeListener(markNeedsPaint); + _childRaster?.dispose(); + _childRaster = null; + _childRasterSize = null; + super.detach(); + } + + @override + void dispose() { + controller.removeListener(_onRasterValueChanged); + painter.removeListener(markNeedsPaint); + _childRaster?.dispose(); + _childRaster = null; + _childRasterSize = null; + super.dispose(); + } + + void _onRasterValueChanged() { + _disableSnapshotAttempt = false; + _childRaster?.dispose(); + _childRaster = null; + _childRasterSize = null; + markNeedsPaint(); + } + + // Paint [child] with this painting context, then convert to a raster and detach all + // children from this layer. + ui.Image? _paintAndDetachToImage() { + final OffsetLayer offsetLayer = OffsetLayer(); + final PaintingContext context = PaintingContext(offsetLayer, Offset.zero & size); + super.paint(context, Offset.zero); + // This ignore is here because this method is protected by the `PaintingContext`. Adding a new + // method that performs the work of `_paintAndDetachToImage` would avoid the need for this, but + // that would conflict with our goals of minimizing painting context. + // ignore: invalid_use_of_protected_member + context.stopRecordingIfNeeded(); + if (mode != SnapshotMode.forced && !offsetLayer.supportsRasterization()) { + offsetLayer.dispose(); + if (mode == SnapshotMode.normal) { + throw FlutterError('SnapshotWidget used with a child that contains a PlatformView.'); + } + _disableSnapshotAttempt = true; + return null; + } + final ui.Image image = offsetLayer.toImageSync(Offset.zero & size, pixelRatio: devicePixelRatio); + offsetLayer.dispose(); + _lastCachedSize = size; + return image; + } + + Size? _lastCachedSize; + + @override + void paint(PaintingContext context, Offset offset) { + if (size.isEmpty) { + _childRaster?.dispose(); + _childRaster = null; + _childRasterSize = null; + return; + } + if (!controller.allowSnapshotting || _disableSnapshotAttempt) { + _childRaster?.dispose(); + _childRaster = null; + _childRasterSize = null; + painter.paint(context, offset, size, super.paint); + return; + } + + if (autoresize && size != _lastCachedSize && _lastCachedSize != null) { + _childRaster?.dispose(); + _childRaster = null; + } + + if (_childRaster == null) { + _childRaster = _paintAndDetachToImage(); + _childRasterSize = size * devicePixelRatio; + } + if (_childRaster == null) { + painter.paint(context, offset, size, super.paint); + } else { + painter.paintSnapshot(context, offset, size, _childRaster!, _childRasterSize!, devicePixelRatio); + } + } +} + +/// A painter used to paint either a snapshot or the child widgets that +/// would be a snapshot. +/// +/// The painter can call [notifyListeners] to have the [SnapshotWidget] +/// re-paint (re-using the same raster). This allows animations to be performed +/// without re-snapshotting of children. For certain scale or perspective changing +/// transforms, such as a rotation, this can be significantly faster than performing +/// the same animation at the widget level. +/// +/// By default, the [SnapshotWidget] includes a delegate that draws the child raster +/// exactly as the child widgets would have been drawn. Nevertheless, this can +/// also be used to efficiently transform the child raster and apply complex paint +/// effects. +/// +/// {@tool snippet} +/// +/// The following method shows how to efficiently rotate the child raster. +/// +/// ```dart +/// void paint(PaintingContext context, Offset offset, Size size, ui.Image image, double pixelRatio) { +/// const double radians = 0.5; // Could be driven by an animation. +/// final Matrix4 transform = Matrix4.rotationZ(radians); +/// context.canvas.transform(transform.storage); +/// final Rect src = Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble()); +/// final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height); +/// final Paint paint = Paint() +/// ..filterQuality = FilterQuality.low; +/// context.canvas.drawImageRect(image, src, dst, paint); +/// } +/// ``` +/// {@end-tool} +abstract class SnapshotPainter extends ChangeNotifier { + /// Creates an instance of [SnapshotPainter]. + SnapshotPainter() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + /// Called whenever the [image] that represents a [SnapshotWidget]s child should be painted. + /// + /// The image is rasterized at the physical pixel resolution and should be scaled down by + /// [pixelRatio] to account for device independent pixels. + /// + /// {@tool snippet} + /// + /// The following method shows how the default implementation of the delegate used by the + /// [SnapshotPainter] paints the snapshot. This must account for the fact that the image + /// width and height will be given in physical pixels, while the image must be painted with + /// device independent pixels. That is, the width and height of the image is the widget and + /// height of the provided `size`, multiplied by the `pixelRatio`. In addition, the actual + /// size of the scene captured by the `image` is not `image.width` or `image.height`, but + /// indeed `sourceSize`, because the former is a rounded inaccurate integer: + /// + /// ```dart + /// void paint(PaintingContext context, Offset offset, Size size, ui.Image image, Size sourceSize, double pixelRatio) { + /// final Rect src = Rect.fromLTWH(0, 0, sourceSize.width, sourceSize.height); + /// final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height); + /// final Paint paint = Paint() + /// ..filterQuality = FilterQuality.low; + /// context.canvas.drawImageRect(image, src, dst, paint); + /// } + /// ``` + /// {@end-tool} + void paintSnapshot(PaintingContext context, Offset offset, Size size, ui.Image image, Size sourceSize, double pixelRatio); + + /// Paint the child via [painter], applying any effects that would have been painted + /// in [SnapshotPainter.paintSnapshot]. + /// + /// This method is called when snapshotting is disabled, or when [SnapshotMode.permissive] + /// is used and a child platform view prevents snapshotting. + /// + /// The [offset] and [size] are the location and dimensions of the render object. + void paint(PaintingContext context, Offset offset, Size size, PaintingContextCallback painter); + + /// Called whenever a new instance of the snapshot widget delegate class is + /// provided to the [SnapshotWidget] object, or any time that a new + /// [SnapshotPainter] object is created with a new instance of the + /// delegate class (which amounts to the same thing, because the latter is + /// implemented in terms of the former). + /// + /// If the new instance represents different information than the old + /// instance, then the method should return true, otherwise it should return + /// false. + /// + /// If the method returns false, then the [paint] call might be optimized + /// away. + /// + /// It's possible that the [paint] method will get called even if + /// [shouldRepaint] returns false (e.g. if an ancestor or descendant needed to + /// be repainted). It's also possible that the [paint] method will get called + /// without [shouldRepaint] being called at all (e.g. if the box changes + /// size). + /// + /// Changing the delegate will not cause the child image retained by the + /// [SnapshotWidget] to be updated. Instead, [SnapshotController.clear] can + /// be used to force the generation of a new image. + /// + /// The `oldPainter` argument will never be null. + bool shouldRepaint(covariant SnapshotPainter oldPainter); +} + +class _DefaultSnapshotPainter implements SnapshotPainter { + const _DefaultSnapshotPainter(); + + @override + void addListener(ui.VoidCallback listener) { } + + @override + void dispose() { } + + @override + bool get hasListeners => false; + + @override + void notifyListeners() { } + + @override + void paint(PaintingContext context, ui.Offset offset, ui.Size size, PaintingContextCallback painter) { + painter(context, offset); + } + + @override + void paintSnapshot(PaintingContext context, ui.Offset offset, ui.Size size, ui.Image image, Size sourceSize, double pixelRatio) { + final Rect src = Rect.fromLTWH(0, 0, sourceSize.width, sourceSize.height); + final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height); + final Paint paint = Paint() + ..filterQuality = FilterQuality.low; + context.canvas.drawImageRect(image, src, dst, paint); + } + + @override + void removeListener(ui.VoidCallback listener) { } + + @override + bool shouldRepaint(covariant _DefaultSnapshotPainter oldPainter) => false; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/spacer.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/spacer.dart new file mode 100644 index 0000000000000000000000000000000000000000..b84aac8e8ed47c2da248da18c918f99e7759477e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/spacer.dart @@ -0,0 +1,64 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'basic.dart'; +import 'framework.dart'; + +/// Spacer creates an adjustable, empty spacer that can be used to tune the +/// spacing between widgets in a [Flex] container, like [Row] or [Column]. +/// +/// The [Spacer] widget will take up any available space, so setting the +/// [Flex.mainAxisAlignment] on a flex container that contains a [Spacer] to +/// [MainAxisAlignment.spaceAround], [MainAxisAlignment.spaceBetween], or +/// [MainAxisAlignment.spaceEvenly] will not have any visible effect: the +/// [Spacer] has taken up all of the additional space, therefore there is none +/// left to redistribute. +/// +/// {@tool snippet} +/// +/// ```dart +/// const Row( +/// children: <Widget>[ +/// Text('Begin'), +/// Spacer(), // Defaults to a flex of one. +/// Text('Middle'), +/// // Gives twice the space between Middle and End than Begin and Middle. +/// Spacer(flex: 2), +/// Text('End'), +/// ], +/// ) +/// ``` +/// {@end-tool} +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=7FJgd7QN1zI} +/// +/// See also: +/// +/// * [Row] and [Column], which are the most common containers to use a Spacer +/// in. +/// * [SizedBox], to create a box with a specific size and an optional child. +class Spacer extends StatelessWidget { + /// Creates a flexible space to insert into a [Flexible] widget. + /// + /// The [flex] parameter may not be null or less than one. + const Spacer({super.key, this.flex = 1}) + : assert(flex > 0); + + /// The flex factor to use in determining how much space to take up. + /// + /// The amount of space the [Spacer] can occupy in the main axis is determined + /// by dividing the free space proportionately, after placing the inflexible + /// children, according to the flex factors of the flexible children. + /// + /// Defaults to one. + final int flex; + + @override + Widget build(BuildContext context) { + return Expanded( + flex: flex, + child: const SizedBox.shrink(), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/spell_check.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/spell_check.dart new file mode 100644 index 0000000000000000000000000000000000000000..3a4574aa0f925312bc5070cb289eeced30ed2ff0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/spell_check.dart @@ -0,0 +1,436 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show TargetPlatform, defaultTargetPlatform; +import 'package:flutter/painting.dart'; +import 'package:flutter/services.dart' + show SpellCheckResults, SpellCheckService, SuggestionSpan, TextEditingValue; + +import 'editable_text.dart' show EditableTextContextMenuBuilder; +import 'framework.dart' show immutable; + +/// Controls how spell check is performed for text input. +/// +/// This configuration determines the [SpellCheckService] used to fetch the +/// [List<SuggestionSpan>] spell check results and the [TextStyle] used to +/// mark misspelled words within text input. +@immutable +class SpellCheckConfiguration { + /// Creates a configuration that specifies the service and suggestions handler + /// for spell check. + const SpellCheckConfiguration({ + this.spellCheckService, + this.misspelledSelectionColor, + this.misspelledTextStyle, + this.spellCheckSuggestionsToolbarBuilder, + }) : _spellCheckEnabled = true; + + /// Creates a configuration that disables spell check. + const SpellCheckConfiguration.disabled() + : _spellCheckEnabled = false, + spellCheckService = null, + spellCheckSuggestionsToolbarBuilder = null, + misspelledTextStyle = null, + misspelledSelectionColor = null; + + /// The service used to fetch spell check results for text input. + final SpellCheckService? spellCheckService; + + /// The color the paint the selection highlight when spell check is showing + /// suggestions for a misspelled word. + /// + /// For example, on iOS, the selection appears red while the spell check menu + /// is showing. + final Color? misspelledSelectionColor; + + /// Style used to indicate misspelled words. + /// + /// This is nullable to allow style-specific wrappers of [EditableText] + /// to infer this, but this must be specified if this configuration is + /// provided directly to [EditableText] or its construction will fail with an + /// assertion error. + final TextStyle? misspelledTextStyle; + + /// Builds the toolbar used to display spell check suggestions for misspelled + /// words. + final EditableTextContextMenuBuilder? spellCheckSuggestionsToolbarBuilder; + + final bool _spellCheckEnabled; + + /// Whether or not the configuration should enable or disable spell check. + bool get spellCheckEnabled => _spellCheckEnabled; + + /// Returns a copy of the current [SpellCheckConfiguration] instance with + /// specified overrides. + SpellCheckConfiguration copyWith({ + SpellCheckService? spellCheckService, + Color? misspelledSelectionColor, + TextStyle? misspelledTextStyle, + EditableTextContextMenuBuilder? spellCheckSuggestionsToolbarBuilder}) { + if (!_spellCheckEnabled) { + // A new configuration should be constructed to enable spell check. + return const SpellCheckConfiguration.disabled(); + } + + return SpellCheckConfiguration( + spellCheckService: spellCheckService ?? this.spellCheckService, + misspelledSelectionColor: misspelledSelectionColor ?? this.misspelledSelectionColor, + misspelledTextStyle: misspelledTextStyle ?? this.misspelledTextStyle, + spellCheckSuggestionsToolbarBuilder : spellCheckSuggestionsToolbarBuilder ?? this.spellCheckSuggestionsToolbarBuilder, + ); + } + + @override + String toString() { + return ''' + spell check enabled : $_spellCheckEnabled + spell check service : $spellCheckService + misspelled text style : $misspelledTextStyle + spell check suggestions toolbar builder: $spellCheckSuggestionsToolbarBuilder +''' + .trim(); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is SpellCheckConfiguration + && other.spellCheckService == spellCheckService + && other.misspelledTextStyle == misspelledTextStyle + && other.spellCheckSuggestionsToolbarBuilder == spellCheckSuggestionsToolbarBuilder + && other._spellCheckEnabled == _spellCheckEnabled; + } + + @override + int get hashCode => Object.hash(spellCheckService, misspelledTextStyle, spellCheckSuggestionsToolbarBuilder, _spellCheckEnabled); +} + +// Methods for displaying spell check results: + +/// Adjusts spell check results to correspond to [newText] if the only results +/// that the handler has access to are the [results] corresponding to +/// [resultsText]. +/// +/// Used in the case where the request for the spell check results of the +/// [newText] is lagging in order to avoid display of incorrect results. +List<SuggestionSpan> _correctSpellCheckResults( + String newText, String resultsText, List<SuggestionSpan> results) { + final List<SuggestionSpan> correctedSpellCheckResults = <SuggestionSpan>[]; + int spanPointer = 0; + int offset = 0; + + // Assumes that the order of spans has not been jumbled for optimization + // purposes, and will only search since the previously found span. + int searchStart = 0; + + while (spanPointer < results.length) { + final SuggestionSpan currentSpan = results[spanPointer]; + final String currentSpanText = + resultsText.substring(currentSpan.range.start, currentSpan.range.end); + final int spanLength = currentSpan.range.end - currentSpan.range.start; + + // Try finding SuggestionSpan from resultsText in new text. + final RegExp currentSpanTextRegexp = RegExp('\\b$currentSpanText\\b'); + final int foundIndex = newText.substring(searchStart).indexOf(currentSpanTextRegexp); + + // Check whether word was found exactly where expected or elsewhere in the newText. + final bool currentSpanFoundExactly = currentSpan.range.start == foundIndex + searchStart; + final bool currentSpanFoundExactlyWithOffset = currentSpan.range.start + offset == foundIndex + searchStart; + final bool currentSpanFoundElsewhere = foundIndex >= 0; + + if (currentSpanFoundExactly || currentSpanFoundExactlyWithOffset) { + // currentSpan was found at the same index in newText and resutsText + // or at the same index with the previously calculated adjustment by + // the offset value, so apply it to new text by adding it to the list of + // corrected results. + final SuggestionSpan adjustedSpan = SuggestionSpan( + TextRange( + start: currentSpan.range.start + offset, + end: currentSpan.range.end + offset, + ), + currentSpan.suggestions, + ); + + // Start search for the next misspelled word at the end of currentSpan. + searchStart = currentSpan.range.end + 1 + offset; + correctedSpellCheckResults.add(adjustedSpan); + } else if (currentSpanFoundElsewhere) { + // Word was pushed forward but not modified. + final int adjustedSpanStart = searchStart + foundIndex; + final int adjustedSpanEnd = adjustedSpanStart + spanLength; + final SuggestionSpan adjustedSpan = SuggestionSpan( + TextRange(start: adjustedSpanStart, end: adjustedSpanEnd), + currentSpan.suggestions, + ); + + // Start search for the next misspelled word at the end of the + // adjusted currentSpan. + searchStart = adjustedSpanEnd + 1; + // Adjust offset to reflect the difference between where currentSpan + // was positioned in resultsText versus in newText. + offset = adjustedSpanStart - currentSpan.range.start; + correctedSpellCheckResults.add(adjustedSpan); + } + spanPointer++; + } + return correctedSpellCheckResults; +} + +/// Builds the [TextSpan] tree given the current state of the text input and +/// spell check results. +/// +/// The [value] is the current [TextEditingValue] requested to be rendered +/// by a text input widget. The [composingWithinCurrentTextRange] value +/// represents whether or not there is a valid composing region in the +/// [value]. The [style] is the [TextStyle] to render the [value]'s text with, +/// and the [misspelledTextStyle] is the [TextStyle] to render misspelled +/// words within the [value]'s text with. The [spellCheckResults] are the +/// results of spell checking the [value]'s text. +TextSpan buildTextSpanWithSpellCheckSuggestions( + TextEditingValue value, + bool composingWithinCurrentTextRange, + TextStyle? style, + TextStyle misspelledTextStyle, + SpellCheckResults spellCheckResults) { + List<SuggestionSpan> spellCheckResultsSpans = + spellCheckResults.suggestionSpans; + final String spellCheckResultsText = spellCheckResults.spellCheckedText; + + if (spellCheckResultsText != value.text) { + spellCheckResultsSpans = _correctSpellCheckResults( + value.text, spellCheckResultsText, spellCheckResultsSpans); + } + + // We will draw the TextSpan tree based on the composing region, if it is + // available. + // TODO(camsim99): The two separate stratgies for building TextSpan trees + // based on the availability of a composing region should be merged: + // https://github.com/flutter/flutter/issues/124142. + final bool shouldConsiderComposingRegion = defaultTargetPlatform == TargetPlatform.android; + if (shouldConsiderComposingRegion) { + return TextSpan( + style: style, + children: _buildSubtreesWithComposingRegion( + spellCheckResultsSpans, + value, + style, + misspelledTextStyle, + composingWithinCurrentTextRange, + ), + ); + } + + return TextSpan( + style: style, + children: _buildSubtreesWithoutComposingRegion( + spellCheckResultsSpans, + value, + style, + misspelledTextStyle, + value.selection.baseOffset, + ), + ); +} + +/// Builds the [TextSpan] tree for spell check without considering the composing +/// region. Instead, uses the cursor to identify the word that's actively being +/// edited and shouldn't be spell checked. This is useful for platforms and IMEs +/// that don't use the composing region for the active word. +List<TextSpan> _buildSubtreesWithoutComposingRegion( + List<SuggestionSpan>? spellCheckSuggestions, + TextEditingValue value, + TextStyle? style, + TextStyle misspelledStyle, + int cursorIndex, +) { + final List<TextSpan> textSpanTreeChildren = <TextSpan>[]; + + int textPointer = 0; + int currentSpanPointer = 0; + int endIndex; + final String text = value.text; + final TextStyle misspelledJointStyle = + style?.merge(misspelledStyle) ?? misspelledStyle; + bool cursorInCurrentSpan = false; + + // Add text interwoven with any misspelled words to the tree. + if (spellCheckSuggestions != null) { + while (textPointer < text.length && + currentSpanPointer < spellCheckSuggestions.length) { + final SuggestionSpan currentSpan = spellCheckSuggestions[currentSpanPointer]; + + if (currentSpan.range.start > textPointer) { + endIndex = currentSpan.range.start < text.length + ? currentSpan.range.start + : text.length; + textSpanTreeChildren.add( + TextSpan( + style: style, + text: text.substring(textPointer, endIndex), + ) + ); + textPointer = endIndex; + } else { + endIndex = + currentSpan.range.end < text.length ? currentSpan.range.end : text.length; + cursorInCurrentSpan = currentSpan.range.start <= cursorIndex && currentSpan.range.end >= cursorIndex; + textSpanTreeChildren.add( + TextSpan( + style: cursorInCurrentSpan + ? style + : misspelledJointStyle, + text: text.substring(currentSpan.range.start, endIndex), + ) + ); + + textPointer = endIndex; + currentSpanPointer++; + } + } + } + + // Add any remaining text to the tree if applicable. + if (textPointer < text.length) { + textSpanTreeChildren.add( + TextSpan( + style: style, + text: text.substring(textPointer, text.length), + ) + ); + } + + return textSpanTreeChildren; +} + +/// Builds [TextSpan] subtree for text with misspelled words with logic based on +/// a valid composing region. +List<TextSpan> _buildSubtreesWithComposingRegion( + List<SuggestionSpan>? spellCheckSuggestions, + TextEditingValue value, + TextStyle? style, + TextStyle misspelledStyle, + bool composingWithinCurrentTextRange) { + final List<TextSpan> textSpanTreeChildren = <TextSpan>[]; + + int textPointer = 0; + int currentSpanPointer = 0; + int endIndex; + SuggestionSpan currentSpan; + final String text = value.text; + final TextRange composingRegion = value.composing; + final TextStyle composingTextStyle = + style?.merge(const TextStyle(decoration: TextDecoration.underline)) ?? + const TextStyle(decoration: TextDecoration.underline); + final TextStyle misspelledJointStyle = + style?.merge(misspelledStyle) ?? misspelledStyle; + bool textPointerWithinComposingRegion = false; + bool currentSpanIsComposingRegion = false; + + // Add text interwoven with any misspelled words to the tree. + if (spellCheckSuggestions != null) { + while (textPointer < text.length && + currentSpanPointer < spellCheckSuggestions.length) { + currentSpan = spellCheckSuggestions[currentSpanPointer]; + + if (currentSpan.range.start > textPointer) { + endIndex = currentSpan.range.start < text.length + ? currentSpan.range.start + : text.length; + textPointerWithinComposingRegion = + composingRegion.start >= textPointer && + composingRegion.end <= endIndex && + !composingWithinCurrentTextRange; + + if (textPointerWithinComposingRegion) { + _addComposingRegionTextSpans(textSpanTreeChildren, text, textPointer, + composingRegion, style, composingTextStyle); + textSpanTreeChildren.add( + TextSpan( + style: style, + text: text.substring(composingRegion.end, endIndex), + ) + ); + } else { + textSpanTreeChildren.add( + TextSpan( + style: style, + text: text.substring(textPointer, endIndex), + ) + ); + } + + textPointer = endIndex; + } else { + endIndex = + currentSpan.range.end < text.length ? currentSpan.range.end : text.length; + currentSpanIsComposingRegion = textPointer >= composingRegion.start && + endIndex <= composingRegion.end && + !composingWithinCurrentTextRange; + textSpanTreeChildren.add( + TextSpan( + style: currentSpanIsComposingRegion + ? composingTextStyle + : misspelledJointStyle, + text: text.substring(currentSpan.range.start, endIndex), + ) + ); + + textPointer = endIndex; + currentSpanPointer++; + } + } + } + + // Add any remaining text to the tree if applicable. + if (textPointer < text.length) { + if (textPointer < composingRegion.start && + !composingWithinCurrentTextRange) { + _addComposingRegionTextSpans(textSpanTreeChildren, text, textPointer, + composingRegion, style, composingTextStyle); + + if (composingRegion.end != text.length) { + textSpanTreeChildren.add( + TextSpan( + style: style, + text: text.substring(composingRegion.end, text.length), + ) + ); + } + } else { + textSpanTreeChildren.add( + TextSpan( + style: style, text: text.substring(textPointer, text.length), + ) + ); + } + } + + return textSpanTreeChildren; +} + +/// Helper method to create [TextSpan] tree children for specified range of +/// text up to and including the composing region. +void _addComposingRegionTextSpans( + List<TextSpan> treeChildren, + String text, + int start, + TextRange composingRegion, + TextStyle? style, + TextStyle composingTextStyle) { + treeChildren.add( + TextSpan( + style: style, + text: text.substring(start, composingRegion.start), + ) + ); + treeChildren.add( + TextSpan( + style: composingTextStyle, + text: text.substring(composingRegion.start, composingRegion.end), + ) + ); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/status_transitions.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/status_transitions.dart new file mode 100644 index 0000000000000000000000000000000000000000..734cd0f29b0c011a5344cfbdd6c6da3c37439a19 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/status_transitions.dart @@ -0,0 +1,59 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'basic.dart'; +import 'framework.dart'; + +/// A widget that rebuilds when the given animation changes status. +abstract class StatusTransitionWidget extends StatefulWidget { + /// Initializes fields for subclasses. + const StatusTransitionWidget({ + super.key, + required this.animation, + }); + + /// The animation to which this widget is listening. + final Animation<double> animation; + + /// Override this method to build widgets that depend on the current status + /// of the animation. + Widget build(BuildContext context); + + @override + State<StatusTransitionWidget> createState() => _StatusTransitionState(); +} + +class _StatusTransitionState extends State<StatusTransitionWidget> { + @override + void initState() { + super.initState(); + widget.animation.addStatusListener(_animationStatusChanged); + } + + @override + void didUpdateWidget(StatusTransitionWidget oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.animation != oldWidget.animation) { + oldWidget.animation.removeStatusListener(_animationStatusChanged); + widget.animation.addStatusListener(_animationStatusChanged); + } + } + + @override + void dispose() { + widget.animation.removeStatusListener(_animationStatusChanged); + super.dispose(); + } + + void _animationStatusChanged(AnimationStatus status) { + setState(() { + // The animation's state is our build state, and it changed already. + }); + } + + @override + Widget build(BuildContext context) { + return widget.build(context); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/system_context_menu.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/system_context_menu.dart new file mode 100644 index 0000000000000000000000000000000000000000..05fd4b412cca2c030ac800f81a5569f42dd4bb88 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/system_context_menu.dart @@ -0,0 +1,132 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; + +import 'basic.dart'; +import 'editable_text.dart'; +import 'framework.dart'; +import 'media_query.dart'; +import 'text_selection_toolbar_anchors.dart'; + +/// Displays the system context menu on top of the Flutter view. +/// +/// Currently, only supports iOS 16.0 and above and displays nothing on other +/// platforms. +/// +/// The context menu is the menu that appears, for example, when doing text +/// selection. Flutter typically draws this menu itself, but this class deals +/// with the platform-rendered context menu instead. +/// +/// There can only be one system context menu visible at a time. Building this +/// widget when the system context menu is already visible will hide the old one +/// and display this one. A system context menu that is hidden is informed via +/// [onSystemHide]. +/// +/// To check if the current device supports showing the system context menu, +/// call [isSupported]. +/// +/// {@tool dartpad} +/// This example shows how to create a [TextField] that uses the system context +/// menu where supported and does not show a system notification when the user +/// presses the "Paste" button. +/// +/// ** See code in examples/api/lib/widgets/system_context_menu/system_context_menu.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [SystemContextMenuController], which directly controls the hiding and +/// showing of the system context menu. +class SystemContextMenu extends StatefulWidget { + /// Creates an instance of [SystemContextMenu] that points to the given + /// [anchor]. + const SystemContextMenu._({ + super.key, + required this.anchor, + this.onSystemHide, + }); + + /// Creates an instance of [SystemContextMenu] for the field indicated by the + /// given [EditableTextState]. + factory SystemContextMenu.editableText({ + Key? key, + required EditableTextState editableTextState, + }) { + final ( + startGlyphHeight: double startGlyphHeight, + endGlyphHeight: double endGlyphHeight, + ) = editableTextState.getGlyphHeights(); + return SystemContextMenu._( + key: key, + anchor: TextSelectionToolbarAnchors.getSelectionRect( + editableTextState.renderEditable, + startGlyphHeight, + endGlyphHeight, + editableTextState.renderEditable.getEndpointsForSelection( + editableTextState.textEditingValue.selection, + ), + ), + onSystemHide: () { + editableTextState.hideToolbar(); + }, + ); + } + + /// The [Rect] that the context menu should point to. + final Rect anchor; + + /// Called when the system hides this context menu. + /// + /// For example, tapping outside of the context menu typically causes the + /// system to hide the menu. + /// + /// This is not called when showing a new system context menu causes another + /// to be hidden. + final VoidCallback? onSystemHide; + + /// Whether the current device supports showing the system context menu. + /// + /// Currently, this is only supported on newer versions of iOS. + static bool isSupported(BuildContext context) { + return MediaQuery.maybeSupportsShowingSystemContextMenu(context) ?? false; + } + + @override + State<SystemContextMenu> createState() => _SystemContextMenuState(); +} + +class _SystemContextMenuState extends State<SystemContextMenu> { + late final SystemContextMenuController _systemContextMenuController; + + @override + void initState() { + super.initState(); + _systemContextMenuController = SystemContextMenuController( + onSystemHide: widget.onSystemHide, + ); + _systemContextMenuController.show(widget.anchor); + } + + @override + void didUpdateWidget(SystemContextMenu oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.anchor != oldWidget.anchor) { + _systemContextMenuController.show(widget.anchor); + } + } + + @override + void dispose() { + _systemContextMenuController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + assert(SystemContextMenu.isSupported(context)); + return const SizedBox.shrink(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/table.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/table.dart new file mode 100644 index 0000000000000000000000000000000000000000..11671edfa343c9635d62bce3f2417314c03c89e7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/table.dart @@ -0,0 +1,462 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'image.dart'; + +export 'package:flutter/rendering.dart' show + FixedColumnWidth, + FlexColumnWidth, + FractionColumnWidth, + IntrinsicColumnWidth, + MaxColumnWidth, + MinColumnWidth, + TableBorder, + TableCellVerticalAlignment, + TableColumnWidth; + +/// A horizontal group of cells in a [Table]. +/// +/// Every row in a table must have the same number of children. +/// +/// The alignment of individual cells in a row can be controlled using a +/// [TableCell]. +@immutable +class TableRow { + /// Creates a row in a [Table]. + const TableRow({ this.key, this.decoration, this.children = const <Widget>[]}); + + /// An identifier for the row. + final LocalKey? key; + + /// A decoration to paint behind this row. + /// + /// Row decorations fill the horizontal and vertical extent of each row in + /// the table, unlike decorations for individual cells, which might not fill + /// either. + final Decoration? decoration; + + /// The widgets that comprise the cells in this row. + /// + /// Children may be wrapped in [TableCell] widgets to provide per-cell + /// configuration to the [Table], but children are not required to be wrapped + /// in [TableCell] widgets. + final List<Widget> children; + + @override + String toString() { + final StringBuffer result = StringBuffer(); + result.write('TableRow('); + if (key != null) { + result.write('$key, '); + } + if (decoration != null) { + result.write('$decoration, '); + } + if (children.isEmpty) { + result.write('no children'); + } else { + result.write('$children'); + } + result.write(')'); + return result.toString(); + } +} + +class _TableElementRow { + const _TableElementRow({ this.key, required this.children }); + final LocalKey? key; + final List<Element> children; +} + +/// A widget that uses the table layout algorithm for its children. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=_lbE0wsVZSw} +/// +/// {@tool dartpad} +/// This sample shows a [Table] with borders, multiple types of column widths +/// and different vertical cell alignments. +/// +/// ** See code in examples/api/lib/widgets/table/table.0.dart ** +/// {@end-tool} +/// +/// If you only have one row, the [Row] widget is more appropriate. If you only +/// have one column, the [SliverList] or [Column] widgets will be more +/// appropriate. +/// +/// Rows size vertically based on their contents. To control the individual +/// column widths, use the [columnWidths] property to specify a +/// [TableColumnWidth] for each column. If [columnWidths] is null, or there is a +/// null entry for a given column in [columnWidths], the table uses the +/// [defaultColumnWidth] instead. +/// +/// By default, [defaultColumnWidth] is a [FlexColumnWidth]. This +/// [TableColumnWidth] divides up the remaining space in the horizontal axis to +/// determine the column width. If wrapping a [Table] in a horizontal +/// [ScrollView], choose a different [TableColumnWidth], such as +/// [FixedColumnWidth]. +/// +/// For more details about the table layout algorithm, see [RenderTable]. +/// To control the alignment of children, see [TableCell]. +/// +/// See also: +/// +/// * The [catalog of layout widgets](https://flutter.dev/widgets/layout/). +class Table extends RenderObjectWidget { + /// Creates a table. + Table({ + super.key, + this.children = const <TableRow>[], + this.columnWidths, + this.defaultColumnWidth = const FlexColumnWidth(), + this.textDirection, + this.border, + this.defaultVerticalAlignment = TableCellVerticalAlignment.top, + this.textBaseline, // NO DEFAULT: we don't know what the text's baseline should be + }) : assert(defaultVerticalAlignment != TableCellVerticalAlignment.baseline || textBaseline != null, 'textBaseline is required if you specify the defaultVerticalAlignment with TableCellVerticalAlignment.baseline'), + assert(() { + if (children.any((TableRow row1) => row1.key != null && children.any((TableRow row2) => row1 != row2 && row1.key == row2.key))) { + throw FlutterError( + 'Two or more TableRow children of this Table had the same key.\n' + 'All the keyed TableRow children of a Table must have different Keys.', + ); + } + return true; + }()), + assert(() { + if (children.isNotEmpty) { + final int cellCount = children.first.children.length; + if (children.any((TableRow row) => row.children.length != cellCount)) { + throw FlutterError( + 'Table contains irregular row lengths.\n' + 'Every TableRow in a Table must have the same number of children, so that every cell is filled. ' + 'Otherwise, the table will contain holes.', + ); + } + if (children.any((TableRow row) => row.children.isEmpty)) { + throw FlutterError( + 'One or more TableRow have no children.\n' + 'Every TableRow in a Table must have at least one child, so there is no empty row. ', + ); + } + } + return true; + }()), + _rowDecorations = children.any((TableRow row) => row.decoration != null) + ? children.map<Decoration?>((TableRow row) => row.decoration).toList(growable: false) + : null { + assert(() { + final List<Widget> flatChildren = children.expand<Widget>((TableRow row) => row.children).toList(growable: false); + return !debugChildrenHaveDuplicateKeys(this, flatChildren, message: + 'Two or more cells in this Table contain widgets with the same key.\n' + 'Every widget child of every TableRow in a Table must have different keys. The cells of a Table are ' + 'flattened out for processing, so separate cells cannot have duplicate keys even if they are in ' + 'different rows.', + ); + }()); + } + + /// The rows of the table. + /// + /// Every row in a table must have the same number of children. + final List<TableRow> children; + + /// How the horizontal extents of the columns of this table should be determined. + /// + /// If the [Map] has a null entry for a given column, the table uses the + /// [defaultColumnWidth] instead. By default, that uses flex sizing to + /// distribute free space equally among the columns. + /// + /// The [FixedColumnWidth] class can be used to specify a specific width in + /// pixels. That is the cheapest way to size a table's columns. + /// + /// The layout performance of the table depends critically on which column + /// sizing algorithms are used here. In particular, [IntrinsicColumnWidth] is + /// quite expensive because it needs to measure each cell in the column to + /// determine the intrinsic size of the column. + /// + /// The keys of this map (column indexes) are zero-based. + /// + /// If this is set to null, then an empty map is assumed. + final Map<int, TableColumnWidth>? columnWidths; + + /// How to determine with widths of columns that don't have an explicit sizing + /// algorithm. + /// + /// Specifically, the [defaultColumnWidth] is used for column `i` if + /// `columnWidths[i]` is null. Defaults to [FlexColumnWidth], which will + /// divide the remaining horizontal space up evenly between columns of the + /// same type [TableColumnWidth]. + /// + /// A [Table] in a horizontal [ScrollView] must use a [FixedColumnWidth], or + /// an [IntrinsicColumnWidth] as the horizontal space is infinite. + final TableColumnWidth defaultColumnWidth; + + /// The direction in which the columns are ordered. + /// + /// Defaults to the ambient [Directionality]. + final TextDirection? textDirection; + + /// The style to use when painting the boundary and interior divisions of the table. + final TableBorder? border; + + /// How cells that do not explicitly specify a vertical alignment are aligned vertically. + /// + /// Cells may specify a vertical alignment by wrapping their contents in a + /// [TableCell] widget. + final TableCellVerticalAlignment defaultVerticalAlignment; + + /// The text baseline to use when aligning rows using [TableCellVerticalAlignment.baseline]. + /// + /// This must be set if using baseline alignment. There is no default because there is no + /// way for the framework to know the correct baseline _a priori_. + final TextBaseline? textBaseline; + + final List<Decoration?>? _rowDecorations; + + @override + RenderObjectElement createElement() => _TableElement(this); + + @override + RenderTable createRenderObject(BuildContext context) { + assert(debugCheckHasDirectionality(context)); + return RenderTable( + columns: children.isNotEmpty ? children[0].children.length : 0, + rows: children.length, + columnWidths: columnWidths, + defaultColumnWidth: defaultColumnWidth, + textDirection: textDirection ?? Directionality.of(context), + border: border, + rowDecorations: _rowDecorations, + configuration: createLocalImageConfiguration(context), + defaultVerticalAlignment: defaultVerticalAlignment, + textBaseline: textBaseline, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderTable renderObject) { + assert(debugCheckHasDirectionality(context)); + assert(renderObject.columns == (children.isNotEmpty ? children[0].children.length : 0)); + assert(renderObject.rows == children.length); + renderObject + ..columnWidths = columnWidths + ..defaultColumnWidth = defaultColumnWidth + ..textDirection = textDirection ?? Directionality.of(context) + ..border = border + ..rowDecorations = _rowDecorations + ..configuration = createLocalImageConfiguration(context) + ..defaultVerticalAlignment = defaultVerticalAlignment + ..textBaseline = textBaseline; + } +} + +class _TableElement extends RenderObjectElement { + _TableElement(Table super.widget); + + @override + RenderTable get renderObject => super.renderObject as RenderTable; + + List<_TableElementRow> _children = const<_TableElementRow>[]; + + bool _doingMountOrUpdate = false; + + @override + void mount(Element? parent, Object? newSlot) { + assert(!_doingMountOrUpdate); + _doingMountOrUpdate = true; + super.mount(parent, newSlot); + int rowIndex = -1; + _children = (widget as Table).children.map<_TableElementRow>((TableRow row) { + int columnIndex = 0; + rowIndex += 1; + return _TableElementRow( + key: row.key, + children: row.children.map<Element>((Widget child) { + return inflateWidget(child, _TableSlot(columnIndex++, rowIndex)); + }).toList(growable: false), + ); + }).toList(growable: false); + _updateRenderObjectChildren(); + assert(_doingMountOrUpdate); + _doingMountOrUpdate = false; + } + + @override + void insertRenderObjectChild(RenderBox child, _TableSlot slot) { + renderObject.setupParentData(child); + // Once [mount]/[update] are done, the children are getting set all at once + // in [_updateRenderObjectChildren]. + if (!_doingMountOrUpdate) { + renderObject.setChild(slot.column, slot.row, child); + } + } + + @override + void moveRenderObjectChild(RenderBox child, _TableSlot oldSlot, _TableSlot newSlot) { + assert(_doingMountOrUpdate); + // Child gets moved at the end of [update] in [_updateRenderObjectChildren]. + } + + @override + void removeRenderObjectChild(RenderBox child, _TableSlot slot) { + renderObject.setChild(slot.column, slot.row, null); + } + + final Set<Element> _forgottenChildren = HashSet<Element>(); + + @override + void update(Table newWidget) { + assert(!_doingMountOrUpdate); + _doingMountOrUpdate = true; + final Map<LocalKey, List<Element>> oldKeyedRows = <LocalKey, List<Element>>{}; + for (final _TableElementRow row in _children) { + if (row.key != null) { + oldKeyedRows[row.key!] = row.children; + } + } + final Iterator<_TableElementRow> oldUnkeyedRows = _children.where((_TableElementRow row) => row.key == null).iterator; + final List<_TableElementRow> newChildren = <_TableElementRow>[]; + final Set<List<Element>> taken = <List<Element>>{}; + for (int rowIndex = 0; rowIndex < newWidget.children.length; rowIndex++) { + final TableRow row = newWidget.children[rowIndex]; + List<Element> oldChildren; + if (row.key != null && oldKeyedRows.containsKey(row.key)) { + oldChildren = oldKeyedRows[row.key]!; + taken.add(oldChildren); + } else if (row.key == null && oldUnkeyedRows.moveNext()) { + oldChildren = oldUnkeyedRows.current.children; + } else { + oldChildren = const <Element>[]; + } + final List<_TableSlot> slots = List<_TableSlot>.generate( + row.children.length, + (int columnIndex) => _TableSlot(columnIndex, rowIndex), + ); + newChildren.add(_TableElementRow( + key: row.key, + children: updateChildren(oldChildren, row.children, forgottenChildren: _forgottenChildren, slots: slots), + )); + } + while (oldUnkeyedRows.moveNext()) { + updateChildren(oldUnkeyedRows.current.children, const <Widget>[], forgottenChildren: _forgottenChildren); + } + for (final List<Element> oldChildren in oldKeyedRows.values.where((List<Element> list) => !taken.contains(list))) { + updateChildren(oldChildren, const <Widget>[], forgottenChildren: _forgottenChildren); + } + + _children = newChildren; + _updateRenderObjectChildren(); + _forgottenChildren.clear(); + super.update(newWidget); + assert(widget == newWidget); + assert(_doingMountOrUpdate); + _doingMountOrUpdate = false; + } + + void _updateRenderObjectChildren() { + renderObject.setFlatChildren( + _children.isNotEmpty ? _children[0].children.length : 0, + _children.expand<RenderBox>((_TableElementRow row) { + return row.children.map<RenderBox>((Element child) { + final RenderBox box = child.renderObject! as RenderBox; + return box; + }); + }).toList(), + ); + } + + @override + void visitChildren(ElementVisitor visitor) { + for (final Element child in _children.expand<Element>((_TableElementRow row) => row.children)) { + if (!_forgottenChildren.contains(child)) { + visitor(child); + } + } + } + + @override + bool forgetChild(Element child) { + _forgottenChildren.add(child); + super.forgetChild(child); + return true; + } +} + +/// A widget that controls how a child of a [Table] is aligned. +/// +/// A [TableCell] widget must be a descendant of a [Table], and the path from +/// the [TableCell] widget to its enclosing [Table] must contain only +/// [TableRow]s, [StatelessWidget]s, or [StatefulWidget]s (not +/// other kinds of widgets, like [RenderObjectWidget]s). +/// +/// To create an empty [TableCell], provide a [SizedBox.shrink] +/// as the [child]. +class TableCell extends ParentDataWidget<TableCellParentData> { + /// Creates a widget that controls how a child of a [Table] is aligned. + const TableCell({ + super.key, + this.verticalAlignment, + required super.child, + }); + + /// How this cell is aligned vertically. + final TableCellVerticalAlignment? verticalAlignment; + + @override + void applyParentData(RenderObject renderObject) { + final TableCellParentData parentData = renderObject.parentData! as TableCellParentData; + if (parentData.verticalAlignment != verticalAlignment) { + parentData.verticalAlignment = verticalAlignment; + final RenderObject? targetParent = renderObject.parent; + if (targetParent is RenderObject) { + targetParent.markNeedsLayout(); + } + } + } + + @override + Type get debugTypicalAncestorWidgetClass => Table; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<TableCellVerticalAlignment>('verticalAlignment', verticalAlignment)); + } +} + +@immutable +class _TableSlot with Diagnosticable { + const _TableSlot(this.column, this.row); + + final int column; + final int row; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _TableSlot + && column == other.column + && row == other.row; + } + + @override + int get hashCode => Object.hash(column, row); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(IntProperty('x', column)); + properties.add(IntProperty('y', row)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/tap_region.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/tap_region.dart new file mode 100644 index 0000000000000000000000000000000000000000..f4bdf8d89eaaa55323ff4ab9f8962151dffcf261 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/tap_region.dart @@ -0,0 +1,646 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; + +import 'editable_text.dart'; +import 'framework.dart'; + +// Enable if you want verbose logging about tap region changes. +const bool _kDebugTapRegion = false; + +bool _tapRegionDebug(String message, [Iterable<String>? details]) { + if (_kDebugTapRegion) { + debugPrint('TAP REGION: $message'); + if (details != null && details.isNotEmpty) { + for (final String detail in details) { + debugPrint(' $detail'); + } + } + } + // Return true so that it can be easily used inside of an assert. + return true; +} + +/// The type of callback that [TapRegion.onTapOutside] and +/// [TapRegion.onTapInside] take. +/// +/// The event is the pointer event that caused the callback to be called. +typedef TapRegionCallback = void Function(PointerDownEvent event); + +/// An interface for registering and unregistering a [RenderTapRegion] +/// (typically created with a [TapRegion] widget) with a +/// [RenderTapRegionSurface] (typically created with a [TapRegionSurface] +/// widget). +abstract class TapRegionRegistry { + /// Register the given [RenderTapRegion] with the registry. + void registerTapRegion(RenderTapRegion region); + + /// Unregister the given [RenderTapRegion] with the registry. + void unregisterTapRegion(RenderTapRegion region); + + /// Allows finding of the nearest [TapRegionRegistry], such as a + /// [RenderTapRegionSurface]. + /// + /// Will throw if a [TapRegionRegistry] isn't found. + static TapRegionRegistry of(BuildContext context) { + final TapRegionRegistry? registry = maybeOf(context); + assert(() { + if (registry == null) { + throw FlutterError( + 'TapRegionRegistry.of() was called with a context that does not contain a TapRegionSurface widget.\n' + 'No TapRegionSurface widget ancestor could be found starting from the context that was passed to ' + 'TapRegionRegistry.of().\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return registry!; + } + + /// Allows finding of the nearest [TapRegionRegistry], such as a + /// [RenderTapRegionSurface]. + static TapRegionRegistry? maybeOf(BuildContext context) { + return context.findAncestorRenderObjectOfType<RenderTapRegionSurface>(); + } +} + +/// A widget that provides notification of a tap inside or outside of a set of +/// registered regions, without participating in the [gesture +/// disambiguation](https://flutter.dev/gestures/#gesture-disambiguation) +/// system. +/// +/// The regions are defined by adding [TapRegion] widgets to the widget tree +/// around the regions of interest, and they will register with this +/// [TapRegionSurface]. Each of the tap regions can optionally belong to a group +/// by assigning a [TapRegion.groupId], where all the regions with the same +/// groupId act as if they were all one region. +/// +/// When a tap outside of a registered region or region group is detected, its +/// [TapRegion.onTapOutside] callback is called. If the tap is outside one +/// member of a group, but inside another, no notification is made. +/// +/// When a tap inside of a registered region or region group is detected, its +/// [TapRegion.onTapInside] callback is called. If the tap is inside one member +/// of a group, all members are notified. +/// +/// The [TapRegionSurface] should be defined at the highest level needed to +/// encompass the entire area where taps should be monitored. This is typically +/// around the entire app. If the entire app isn't covered, then taps outside of +/// the [TapRegionSurface] will be ignored and no [TapRegion.onTapOutside] calls +/// will be made for those events. The [WidgetsApp], [MaterialApp] and +/// [CupertinoApp] automatically include a [TapRegionSurface] around their +/// entire app. +/// +/// [TapRegionSurface] does not participate in the [gesture +/// disambiguation](https://flutter.dev/gestures/#gesture-disambiguation) +/// system, so if multiple [TapRegionSurface]s are active at the same time, they +/// will all fire, and so will any other gestures recognized by a +/// [GestureDetector] or other pointer event handlers. +/// +/// [TapRegion]s register only with the nearest ancestor [TapRegionSurface]. +/// +/// See also: +/// +/// * [RenderTapRegionSurface], the render object that is inserted into the +/// render tree by this widget. +/// * <https://flutter.dev/gestures/#gesture-disambiguation> for more +/// information about the gesture system and how it disambiguates inputs. +class TapRegionSurface extends SingleChildRenderObjectWidget { + /// Creates a const [RenderTapRegionSurface]. + /// + /// The [child] attribute is required. + const TapRegionSurface({ + super.key, + required Widget super.child, + }); + + @override + RenderObject createRenderObject(BuildContext context) { + return RenderTapRegionSurface(); + } + + @override + void updateRenderObject( + BuildContext context, + RenderProxyBoxWithHitTestBehavior renderObject, + ) {} +} + +/// A render object that provides notification of a tap inside or outside of a +/// set of registered regions, without participating in the [gesture +/// disambiguation](https://flutter.dev/gestures/#gesture-disambiguation) system +/// (other than to consume tap down events if [TapRegion.consumeOutsideTaps] is +/// true). +/// +/// The regions are defined by adding [RenderTapRegion] render objects in the +/// render tree around the regions of interest, and they will register with this +/// [RenderTapRegionSurface]. Each of the tap regions can optionally belong to a +/// group by assigning a [RenderTapRegion.groupId], where all the regions with +/// the same groupId act as if they were all one region. +/// +/// When a tap outside of a registered region or region group is detected, its +/// [TapRegion.onTapOutside] callback is called. If the tap is outside one +/// member of a group, but inside another, no notification is made. +/// +/// When a tap inside of a registered region or region group is detected, its +/// [TapRegion.onTapInside] callback is called. If the tap is inside one member +/// of a group, all members are notified. +/// +/// The [RenderTapRegionSurface] should be defined at the highest level needed +/// to encompass the entire area where taps should be monitored. This is +/// typically around the entire app. If the entire app isn't covered, then taps +/// outside of the [RenderTapRegionSurface] will be ignored and no +/// [RenderTapRegion.onTapOutside] calls will be made for those events. The +/// [WidgetsApp], [MaterialApp] and [CupertinoApp] automatically include a +/// [RenderTapRegionSurface] around the entire app. +/// +/// [RenderTapRegionSurface] does not participate in the [gesture +/// disambiguation](https://flutter.dev/gestures/#gesture-disambiguation) +/// system, so if multiple [RenderTapRegionSurface]s are active at the same +/// time, they will all fire, and so will any other gestures recognized by a +/// [GestureDetector] or other pointer event handlers. +/// +/// [RenderTapRegion]s register only with the nearest ancestor +/// [RenderTapRegionSurface]. +/// +/// See also: +/// +/// * [TapRegionSurface], a widget that inserts a [RenderTapRegionSurface] into +/// the render tree. +/// * [TapRegionRegistry.of], which can find the nearest ancestor +/// [RenderTapRegionSurface], which is a [TapRegionRegistry]. +class RenderTapRegionSurface extends RenderProxyBoxWithHitTestBehavior implements TapRegionRegistry { + final Expando<BoxHitTestResult> _cachedResults = Expando<BoxHitTestResult>(); + final Set<RenderTapRegion> _registeredRegions = <RenderTapRegion>{}; + final Map<Object?, Set<RenderTapRegion>> _groupIdToRegions = <Object?, Set<RenderTapRegion>>{}; + + @override + void registerTapRegion(RenderTapRegion region) { + assert(_tapRegionDebug('Region $region registered.')); + assert(!_registeredRegions.contains(region)); + _registeredRegions.add(region); + if (region.groupId != null) { + _groupIdToRegions[region.groupId] ??= <RenderTapRegion>{}; + _groupIdToRegions[region.groupId]!.add(region); + } + } + + @override + void unregisterTapRegion(RenderTapRegion region) { + assert(_tapRegionDebug('Region $region unregistered.')); + assert(_registeredRegions.contains(region)); + _registeredRegions.remove(region); + if (region.groupId != null) { + assert(_groupIdToRegions.containsKey(region.groupId)); + _groupIdToRegions[region.groupId]!.remove(region); + if (_groupIdToRegions[region.groupId]!.isEmpty) { + _groupIdToRegions.remove(region.groupId); + } + } + } + + @override + bool hitTest(BoxHitTestResult result, {required Offset position}) { + if (!size.contains(position)) { + return false; + } + + final bool hitTarget = hitTestChildren(result, position: position) || hitTestSelf(position); + + if (hitTarget) { + final BoxHitTestEntry entry = BoxHitTestEntry(this, position); + _cachedResults[entry] = result; + result.add(entry); + } + + return hitTarget; + } + + @override + void handleEvent(PointerEvent event, HitTestEntry entry) { + assert(debugHandleEvent(event, entry)); + assert(() { + for (final RenderTapRegion region in _registeredRegions) { + if (!region.enabled) { + return false; + } + } + return true; + }(), 'A RenderTapRegion was registered when it was disabled.'); + + if (event is! PointerDownEvent) { + return; + } + + if (_registeredRegions.isEmpty) { + assert(_tapRegionDebug('Ignored tap event because no regions are registered.')); + return; + } + + final BoxHitTestResult? result = _cachedResults[entry]; + + if (result == null) { + assert(_tapRegionDebug('Ignored tap event because no surface descendants were hit.')); + return; + } + + // A child was hit, so we need to call onTapOutside for those regions or + // groups of regions that were not hit. + final Set<RenderTapRegion> hitRegions = + _getRegionsHit(_registeredRegions, result.path).cast<RenderTapRegion>().toSet(); + final Set<RenderTapRegion> insideRegions = <RenderTapRegion>{}; + assert(_tapRegionDebug('Tap event hit ${hitRegions.length} descendants.')); + + for (final RenderTapRegion region in hitRegions) { + if (region.groupId == null) { + insideRegions.add(region); + continue; + } + // Add all grouped regions to the insideRegions so that groups act as a + // single region. + insideRegions.addAll(_groupIdToRegions[region.groupId]!); + } + // If they're not inside, then they're outside. + final Set<RenderTapRegion> outsideRegions = _registeredRegions.difference(insideRegions); + + bool consumeOutsideTaps = false; + for (final RenderTapRegion region in outsideRegions) { + assert(_tapRegionDebug('Calling onTapOutside for $region')); + if (region.consumeOutsideTaps) { + assert(_tapRegionDebug('Stopping tap propagation for $region (and all of ${region.groupId})')); + consumeOutsideTaps = true; + } + region.onTapOutside?.call(event); + } + for (final RenderTapRegion region in insideRegions) { + assert(_tapRegionDebug('Calling onTapInside for $region')); + region.onTapInside?.call(event); + } + + // If any of the "outside" regions have consumeOutsideTaps set, then stop + // the propagation of the event through the gesture recognizer by adding it + // to the recognizer and immediately resolving it. + if (consumeOutsideTaps) { + GestureBinding.instance.gestureArena.add(event.pointer, _DummyTapRecognizer()).resolve(GestureDisposition.accepted); + } + } + + // Returns the registered regions that are in the hit path. + Iterable<HitTestTarget> _getRegionsHit(Set<RenderTapRegion> detectors, Iterable<HitTestEntry> hitTestPath) { + final Set<HitTestTarget> hitRegions = <HitTestTarget>{}; + for (final HitTestEntry<HitTestTarget> entry in hitTestPath) { + final HitTestTarget target = entry.target; + if (_registeredRegions.contains(target)) { + hitRegions.add(target); + } + } + return hitRegions; + } +} + +// A dummy tap recognizer so that we don't have to deal with the lifecycle of +// TapGestureRecognizer, since we're just going to immediately resolve it +// anyhow. +class _DummyTapRecognizer extends GestureArenaMember { + @override + void acceptGesture(int pointer) { } + + @override + void rejectGesture(int pointer) { } +} + +/// A widget that defines a region that can detect taps inside or outside of +/// itself and any group of regions it belongs to, without participating in the +/// [gesture +/// disambiguation](https://flutter.dev/gestures/#gesture-disambiguation) system +/// (other than to consume tap down events if [consumeOutsideTaps] is true). +/// +/// This widget indicates to the nearest ancestor [TapRegionSurface] that the +/// region occupied by its child will participate in the tap detection for that +/// surface. +/// +/// If this region belongs to a group (by virtue of its [groupId]), all the +/// regions in the group will act as one. +/// +/// If there is no [TapRegionSurface] ancestor, [TapRegion] will do nothing. +class TapRegion extends SingleChildRenderObjectWidget { + /// Creates a const [TapRegion]. + /// + /// The [child] argument is required. + const TapRegion({ + super.key, + required super.child, + this.enabled = true, + this.behavior = HitTestBehavior.deferToChild, + this.onTapOutside, + this.onTapInside, + this.groupId, + this.consumeOutsideTaps = false, + String? debugLabel, + }) : debugLabel = kReleaseMode ? null : debugLabel; + + /// Whether or not this [TapRegion] is enabled as part of the composite region. + final bool enabled; + + /// How to behave during hit testing when deciding how the hit test propagates + /// to children and whether to consider targets behind this [TapRegion]. + /// + /// Defaults to [HitTestBehavior.deferToChild]. + /// + /// See [HitTestBehavior] for the allowed values and their meanings. + final HitTestBehavior behavior; + + /// A callback to be invoked when a tap is detected outside of this + /// [TapRegion] and any other region with the same [groupId], if any. + /// + /// The [PointerDownEvent] passed to the function is the event that caused the + /// notification. If this region is part of a group (i.e. [groupId] is set), + /// then it's possible that the event may be outside of this immediate region, + /// although it will be within the region of one of the group members. + final TapRegionCallback? onTapOutside; + + /// A callback to be invoked when a tap is detected inside of this + /// [TapRegion], or any other tap region with the same [groupId], if any. + /// + /// The [PointerDownEvent] passed to the function is the event that caused the + /// notification. If this region is part of a group (i.e. [groupId] is set), + /// then it's possible that the event may be outside of this immediate region, + /// although it will be within the region of one of the group members. + final TapRegionCallback? onTapInside; + + /// An optional group ID that groups [TapRegion]s together so that they + /// operate as one region. If any member of a group is hit by a particular + /// tap, then the [onTapOutside] will not be called for any members of the + /// group. If any member of the group is hit, then all members will have their + /// [onTapInside] called. + /// + /// If the group id is null, then only this region is hit tested. + final Object? groupId; + + /// If true, then the group that this region belongs to will stop the + /// propagation of the tap down event in the gesture arena. + /// + /// This is useful if you want to block the tap down from being given to a + /// [GestureDetector] when [onTapOutside] is called. + /// + /// If other [TapRegion]s with the same [groupId] have [consumeOutsideTaps] + /// set to false, but this one is true, then this one will take precedence, + /// and the event will be consumed. + /// + /// Defaults to false. + final bool consumeOutsideTaps; + + /// An optional debug label to help with debugging in debug mode. + /// + /// Will be null in release mode. + final String? debugLabel; + + @override + RenderObject createRenderObject(BuildContext context) { + return RenderTapRegion( + registry: TapRegionRegistry.maybeOf(context), + enabled: enabled, + consumeOutsideTaps: consumeOutsideTaps, + behavior: behavior, + onTapOutside: onTapOutside, + onTapInside: onTapInside, + groupId: groupId, + debugLabel: debugLabel, + ); + } + + @override + void updateRenderObject(BuildContext context, covariant RenderTapRegion renderObject) { + renderObject + ..registry = TapRegionRegistry.maybeOf(context) + ..enabled = enabled + ..behavior = behavior + ..groupId = groupId + ..onTapOutside = onTapOutside + ..onTapInside = onTapInside; + if (!kReleaseMode) { + renderObject.debugLabel = debugLabel; + } + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('enabled', value: enabled, ifFalse: 'DISABLED', defaultValue: true)); + properties.add(DiagnosticsProperty<HitTestBehavior>('behavior', behavior, defaultValue: HitTestBehavior.deferToChild)); + properties.add(DiagnosticsProperty<Object?>('debugLabel', debugLabel, defaultValue: null)); + properties.add(DiagnosticsProperty<Object?>('groupId', groupId, defaultValue: null)); + } +} + +/// A render object that defines a region that can detect taps inside or outside +/// of itself and any group of regions it belongs to, without participating in +/// the [gesture +/// disambiguation](https://flutter.dev/gestures/#gesture-disambiguation) +/// system. +/// +/// This render object indicates to the nearest ancestor [TapRegionSurface] that +/// the region occupied by its child (or itself if [behavior] is +/// [HitTestBehavior.opaque]) will participate in the tap detection for that +/// surface. +/// +/// If this region belongs to a group (by virtue of its [groupId]), all the +/// regions in the group will act as one. +/// +/// If there is no [RenderTapRegionSurface] ancestor in the render tree, +/// [RenderTapRegion] will do nothing. +/// +/// The [behavior] attribute describes how to behave during hit testing when +/// deciding how the hit test propagates to children and whether to consider +/// targets behind the tap region. Defaults to [HitTestBehavior.deferToChild]. +/// See [HitTestBehavior] for the allowed values and their meanings. +/// +/// See also: +/// +/// * [TapRegion], a widget that inserts a [RenderTapRegion] into the render +/// tree. +class RenderTapRegion extends RenderProxyBoxWithHitTestBehavior { + /// Creates a [RenderTapRegion]. + RenderTapRegion({ + TapRegionRegistry? registry, + bool enabled = true, + bool consumeOutsideTaps = false, + this.onTapOutside, + this.onTapInside, + super.behavior = HitTestBehavior.deferToChild, + Object? groupId, + String? debugLabel, + }) : _registry = registry, + _enabled = enabled, + _consumeOutsideTaps = consumeOutsideTaps, + _groupId = groupId, + debugLabel = kReleaseMode ? null : debugLabel; + + bool _isRegistered = false; + + /// A callback to be invoked when a tap is detected outside of this + /// [RenderTapRegion] and any other region with the same [groupId], if any. + /// + /// The [PointerDownEvent] passed to the function is the event that caused the + /// notification. If this region is part of a group (i.e. [groupId] is set), + /// then it's possible that the event may be outside of this immediate region, + /// although it will be within the region of one of the group members. + TapRegionCallback? onTapOutside; + + /// A callback to be invoked when a tap is detected inside of this + /// [RenderTapRegion], or any other tap region with the same [groupId], if any. + /// + /// The [PointerDownEvent] passed to the function is the event that caused the + /// notification. If this region is part of a group (i.e. [groupId] is set), + /// then it's possible that the event may be outside of this immediate region, + /// although it will be within the region of one of the group members. + TapRegionCallback? onTapInside; + + /// A label used in debug builds. Will be null in release builds. + String? debugLabel; + + /// Whether or not this region should participate in the composite region. + bool get enabled => _enabled; + bool _enabled; + set enabled(bool value) { + if (_enabled != value) { + _enabled = value; + markNeedsLayout(); + } + } + + /// Whether or not the tap down even that triggers a call to [onTapOutside] + /// will continue on to participate in the gesture arena. + /// + /// If any [RenderTapRegion] in the same group has [consumeOutsideTaps] set to + /// true, then the tap down event will be consumed before other gesture + /// recognizers can process them. + bool get consumeOutsideTaps => _consumeOutsideTaps; + bool _consumeOutsideTaps; + set consumeOutsideTaps(bool value) { + if (_consumeOutsideTaps != value) { + _consumeOutsideTaps = value; + markNeedsLayout(); + } + } + + /// An optional group ID that groups [RenderTapRegion]s together so that they + /// operate as one region. If any member of a group is hit by a particular + /// tap, then the [onTapOutside] will not be called for any members of the + /// group. If any member of the group is hit, then all members will have their + /// [onTapInside] called. + /// + /// If the group id is null, then only this region is hit tested. + Object? get groupId => _groupId; + Object? _groupId; + set groupId(Object? value) { + if (_groupId != value) { + // If the group changes, we need to unregister and re-register under the + // new group. The re-registration happens automatically in layout(). + if (_isRegistered) { + _registry!.unregisterTapRegion(this); + _isRegistered = false; + } + _groupId = value; + markNeedsLayout(); + } + } + + /// The registry that this [RenderTapRegion] should register with. + /// + /// If the [registry] is null, then this region will not be registered + /// anywhere, and will not do any tap detection. + /// + /// A [RenderTapRegionSurface] is a [TapRegionRegistry]. + TapRegionRegistry? get registry => _registry; + TapRegionRegistry? _registry; + set registry(TapRegionRegistry? value) { + if (_registry != value) { + if (_isRegistered) { + _registry!.unregisterTapRegion(this); + _isRegistered = false; + } + _registry = value; + markNeedsLayout(); + } + } + + @override + void layout(Constraints constraints, {bool parentUsesSize = false}) { + super.layout(constraints, parentUsesSize: parentUsesSize); + if (_registry == null) { + return; + } + if (_isRegistered) { + _registry!.unregisterTapRegion(this); + } + final bool shouldBeRegistered = _enabled && _registry != null; + if (shouldBeRegistered) { + _registry!.registerTapRegion(this); + } + _isRegistered = shouldBeRegistered; + } + + @override + void dispose() { + if (_isRegistered) { + _registry!.unregisterTapRegion(this); + } + super.dispose(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<String?>('debugLabel', debugLabel, defaultValue: null)); + properties.add(DiagnosticsProperty<Object?>('groupId', groupId, defaultValue: null)); + properties.add(FlagProperty('enabled', value: enabled, ifFalse: 'DISABLED', defaultValue: true)); + } +} + +/// A [TapRegion] that adds its children to the tap region group for widgets +/// based on the [EditableText] text editing widget, such as [TextField] and +/// [CupertinoTextField]. +/// +/// Widgets that are wrapped with a [TextFieldTapRegion] are considered to be +/// part of a text field for purposes of unfocus behavior. So, when the user +/// taps on them, the currently focused text field won't be unfocused by +/// default. This allows controls like spinners, copy buttons, and formatting +/// buttons to be associated with a text field without causing the text field to +/// lose focus when they are interacted with. +/// +/// {@tool dartpad} +/// This example shows how to use a [TextFieldTapRegion] to wrap a set of +/// "spinner" buttons that increment and decrement a value in the text field +/// without causing the text field to lose keyboard focus. +/// +/// This example includes a generic `SpinnerField<T>` class that you can copy/paste +/// into your own project and customize. +/// +/// ** See code in examples/api/lib/widgets/tap_region/text_field_tap_region.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [TapRegion], the widget that this widget uses to add widgets to the group +/// of text fields. +class TextFieldTapRegion extends TapRegion { + /// Creates a const [TextFieldTapRegion]. + /// + /// The [child] field is required. + const TextFieldTapRegion({ + super.key, + required super.child, + super.enabled, + super.onTapOutside, + super.onTapInside, + super.consumeOutsideTaps, + super.debugLabel, + }) : super(groupId: EditableText); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text.dart new file mode 100644 index 0000000000000000000000000000000000000000..7d342cb649160b610ef3ee86f0eaf8382c9f4e55 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text.dart @@ -0,0 +1,715 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show TextHeightBehavior; + +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'default_selection_style.dart'; +import 'framework.dart'; +import 'inherited_theme.dart'; +import 'media_query.dart'; +import 'selection_container.dart'; + +// Examples can assume: +// late String _name; +// late BuildContext context; + +/// The text style to apply to descendant [Text] widgets which don't have an +/// explicit style. +/// +/// {@tool dartpad} +/// This example shows how to use [DefaultTextStyle.merge] to create a default +/// text style that inherits styling information from the current default text +/// style and overrides some properties. +/// +/// ** See code in examples/api/lib/widgets/text/text.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedDefaultTextStyle], which animates changes in the text style +/// smoothly over a given duration. +/// * [DefaultTextStyleTransition], which takes a provided [Animation] to +/// animate changes in text style smoothly over time. +class DefaultTextStyle extends InheritedTheme { + /// Creates a default text style for the given subtree. + /// + /// Consider using [DefaultTextStyle.merge] to inherit styling information + /// from the current default text style for a given [BuildContext]. + /// + /// The [maxLines] property may be null (and indeed defaults to null), but if + /// it is not null, it must be greater than zero. + const DefaultTextStyle({ + super.key, + required this.style, + this.textAlign, + this.softWrap = true, + this.overflow = TextOverflow.clip, + this.maxLines, + this.textWidthBasis = TextWidthBasis.parent, + this.textHeightBehavior, + required super.child, + }) : assert(maxLines == null || maxLines > 0); + + /// A const-constructable default text style that provides fallback values. + /// + /// Returned from [of] when the given [BuildContext] doesn't have an enclosing default text style. + /// + /// This constructor creates a [DefaultTextStyle] with an invalid [child], which + /// means the constructed value cannot be incorporated into the tree. + const DefaultTextStyle.fallback({ super.key }) + : style = const TextStyle(), + textAlign = null, + softWrap = true, + maxLines = null, + overflow = TextOverflow.clip, + textWidthBasis = TextWidthBasis.parent, + textHeightBehavior = null, + super(child: const _NullWidget()); + + /// Creates a default text style that overrides the text styles in scope at + /// this point in the widget tree. + /// + /// The given [style] is merged with the [style] from the default text style + /// for the [BuildContext] where the widget is inserted, and any of the other + /// arguments that are not null replace the corresponding properties on that + /// same default text style. + /// + /// This constructor cannot be used to override the [maxLines] property of the + /// ancestor with the value null, since null here is used to mean "defer to + /// ancestor". To replace a non-null [maxLines] from an ancestor with the null + /// value (to remove the restriction on number of lines), manually obtain the + /// ambient [DefaultTextStyle] using [DefaultTextStyle.of], then create a new + /// [DefaultTextStyle] using the [DefaultTextStyle.new] constructor directly. + /// See the source below for an example of how to do this (since that's + /// essentially what this constructor does). + static Widget merge({ + Key? key, + TextStyle? style, + TextAlign? textAlign, + bool? softWrap, + TextOverflow? overflow, + int? maxLines, + TextWidthBasis? textWidthBasis, + required Widget child, + }) { + return Builder( + builder: (BuildContext context) { + final DefaultTextStyle parent = DefaultTextStyle.of(context); + return DefaultTextStyle( + key: key, + style: parent.style.merge(style), + textAlign: textAlign ?? parent.textAlign, + softWrap: softWrap ?? parent.softWrap, + overflow: overflow ?? parent.overflow, + maxLines: maxLines ?? parent.maxLines, + textWidthBasis: textWidthBasis ?? parent.textWidthBasis, + child: child, + ); + }, + ); + } + + /// The text style to apply. + final TextStyle style; + + /// How each line of text in the Text widget should be aligned horizontally. + final TextAlign? textAlign; + + /// Whether the text should break at soft line breaks. + /// + /// If false, the glyphs in the text will be positioned as if there was unlimited horizontal space. + /// + /// This also decides the [overflow] property's behavior. If this is true or null, + /// the glyph causing overflow, and those that follow, will not be rendered. + final bool softWrap; + + /// How visual overflow should be handled. + /// + /// If [softWrap] is true or null, the glyph causing overflow, and those that follow, + /// will not be rendered. Otherwise, it will be shown with the given overflow option. + final TextOverflow overflow; + + /// An optional maximum number of lines for the text to span, wrapping if necessary. + /// If the text exceeds the given number of lines, it will be truncated according + /// to [overflow]. + /// + /// If this is 1, text will not wrap. Otherwise, text will be wrapped at the + /// edge of the box. + /// + /// If this is non-null, it will override even explicit null values of + /// [Text.maxLines]. + final int? maxLines; + + /// The strategy to use when calculating the width of the Text. + /// + /// See [TextWidthBasis] for possible values and their implications. + final TextWidthBasis textWidthBasis; + + /// {@macro dart.ui.textHeightBehavior} + final ui.TextHeightBehavior? textHeightBehavior; + + /// The closest instance of this class that encloses the given context. + /// + /// If no such instance exists, returns an instance created by + /// [DefaultTextStyle.fallback], which contains fallback values. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// DefaultTextStyle style = DefaultTextStyle.of(context); + /// ``` + static DefaultTextStyle of(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<DefaultTextStyle>() ?? const DefaultTextStyle.fallback(); + } + + @override + bool updateShouldNotify(DefaultTextStyle oldWidget) { + return style != oldWidget.style || + textAlign != oldWidget.textAlign || + softWrap != oldWidget.softWrap || + overflow != oldWidget.overflow || + maxLines != oldWidget.maxLines || + textWidthBasis != oldWidget.textWidthBasis || + textHeightBehavior != oldWidget.textHeightBehavior; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return DefaultTextStyle( + style: style, + textAlign: textAlign, + softWrap: softWrap, + overflow: overflow, + maxLines: maxLines, + textWidthBasis: textWidthBasis, + textHeightBehavior: textHeightBehavior, + child: child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + style.debugFillProperties(properties); + properties.add(EnumProperty<TextAlign>('textAlign', textAlign, defaultValue: null)); + properties.add(FlagProperty('softWrap', value: softWrap, ifTrue: 'wrapping at box width', ifFalse: 'no wrapping except at line break characters', showName: true)); + properties.add(EnumProperty<TextOverflow>('overflow', overflow, defaultValue: null)); + properties.add(IntProperty('maxLines', maxLines, defaultValue: null)); + properties.add(EnumProperty<TextWidthBasis>('textWidthBasis', textWidthBasis, defaultValue: TextWidthBasis.parent)); + properties.add(DiagnosticsProperty<ui.TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null)); + } +} + +class _NullWidget extends StatelessWidget { + const _NullWidget(); + + @override + Widget build(BuildContext context) { + throw FlutterError( + 'A DefaultTextStyle constructed with DefaultTextStyle.fallback cannot be incorporated into the widget tree, ' + 'it is meant only to provide a fallback value returned by DefaultTextStyle.of() ' + 'when no enclosing default text style is present in a BuildContext.', + ); + } +} + +/// The [TextHeightBehavior] that will apply to descendant [Text] and [EditableText] +/// widgets which have not explicitly set [Text.textHeightBehavior]. +/// +/// If there is a [DefaultTextStyle] with a non-null [DefaultTextStyle.textHeightBehavior] +/// below this widget, the [DefaultTextStyle.textHeightBehavior] will be used +/// over this widget's [TextHeightBehavior]. +/// +/// See also: +/// +/// * [DefaultTextStyle], which defines a [TextStyle] to apply to descendant +/// [Text] widgets. +class DefaultTextHeightBehavior extends InheritedTheme { + /// Creates a default text height behavior for the given subtree. + const DefaultTextHeightBehavior({ + super.key, + required this.textHeightBehavior, + required super.child, + }); + + /// {@macro dart.ui.textHeightBehavior} + final TextHeightBehavior textHeightBehavior; + + /// The closest instance of [DefaultTextHeightBehavior] that encloses the + /// given context, or null if none is found. + /// + /// If no such instance exists, this method will return `null`. + /// + /// Calling this method will create a dependency on the closest + /// [DefaultTextHeightBehavior] in the [context], if there is one. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// TextHeightBehavior? defaultTextHeightBehavior = DefaultTextHeightBehavior.of(context); + /// ``` + /// + /// See also: + /// + /// * [DefaultTextHeightBehavior.maybeOf], which is similar to this method, + /// but asserts if no [DefaultTextHeightBehavior] ancestor is found. + static TextHeightBehavior? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<DefaultTextHeightBehavior>()?.textHeightBehavior; + } + + /// The closest instance of [DefaultTextHeightBehavior] that encloses the + /// given context. + /// + /// If no such instance exists, this method will assert in debug mode, and + /// throw an exception in release mode. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// TextHeightBehavior defaultTextHeightBehavior = DefaultTextHeightBehavior.of(context); + /// ``` + /// + /// Calling this method will create a dependency on the closest + /// [DefaultTextHeightBehavior] in the [context]. + /// + /// See also: + /// + /// * [DefaultTextHeightBehavior.maybeOf], which is similar to this method, + /// but returns null if no [DefaultTextHeightBehavior] ancestor is found. + static TextHeightBehavior of(BuildContext context) { + final TextHeightBehavior? behavior = maybeOf(context); + assert(() { + if (behavior == null) { + throw FlutterError( + 'DefaultTextHeightBehavior.of() was called with a context that does not contain a ' + 'DefaultTextHeightBehavior widget.\n' + 'No DefaultTextHeightBehavior widget ancestor could be found starting from the ' + 'context that was passed to DefaultTextHeightBehavior.of(). This can happen ' + 'because you are using a widget that looks for a DefaultTextHeightBehavior ' + 'ancestor, but no such ancestor exists.\n' + 'The context used was:\n' + ' $context', + ); + } + return true; + }()); + return behavior!; + } + + @override + bool updateShouldNotify(DefaultTextHeightBehavior oldWidget) { + return textHeightBehavior != oldWidget.textHeightBehavior; + } + + @override + Widget wrap(BuildContext context, Widget child) { + return DefaultTextHeightBehavior( + textHeightBehavior: textHeightBehavior, + child: child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<ui.TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null)); + } +} + +/// A run of text with a single style. +/// +/// The [Text] widget displays a string of text with single style. The string +/// might break across multiple lines or might all be displayed on the same line +/// depending on the layout constraints. +/// +/// The [style] argument is optional. When omitted, the text will use the style +/// from the closest enclosing [DefaultTextStyle]. If the given style's +/// [TextStyle.inherit] property is true (the default), the given style will +/// be merged with the closest enclosing [DefaultTextStyle]. This merging +/// behavior is useful, for example, to make the text bold while using the +/// default font family and size. +/// +/// {@tool snippet} +/// +/// This example shows how to display text using the [Text] widget with the +/// [overflow] set to [TextOverflow.ellipsis]. +/// +/// ![If the text overflows, the Text widget displays an ellipsis to trim the overflowing text](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_ellipsis.png) +/// +/// ```dart +/// Container( +/// width: 100, +/// decoration: BoxDecoration(border: Border.all()), +/// child: Text(overflow: TextOverflow.ellipsis, 'Hello $_name, how are you?')) +/// ``` +/// {@end-tool} +/// +/// {@tool snippet} +/// +/// Setting [maxLines] to `1` is not equivalent to disabling soft wrapping with +/// [softWrap]. This is apparent when using [TextOverflow.fade] as the following +/// examples show. +/// +/// ![If a second line overflows the Text widget displays a horizontal fade](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_fade_max_lines.png) +/// +/// ```dart +/// Text( +/// overflow: TextOverflow.fade, +/// maxLines: 1, +/// 'Hello $_name, how are you?') +/// ``` +/// +/// Here soft wrapping is enabled and the [Text] widget tries to wrap the words +/// "how are you?" to a second line. This is prevented by the [maxLines] value +/// of `1`. The result is that a second line overflows and the fade appears in a +/// horizontal direction at the bottom. +/// +/// ![If a single line overflows the Text widget displays a horizontal fade](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_fade_soft_wrap.png) +/// +/// ```dart +/// Text( +/// overflow: TextOverflow.fade, +/// softWrap: false, +/// 'Hello $_name, how are you?') +/// ``` +/// +/// Here soft wrapping is disabled with `softWrap: false` and the [Text] widget +/// attempts to display its text in a single unbroken line. The result is that +/// the single line overflows and the fade appears in a vertical direction at +/// the right. +/// +/// {@end-tool} +/// +/// Using the [Text.rich] constructor, the [Text] widget can +/// display a paragraph with differently styled [TextSpan]s. The sample +/// that follows displays "Hello beautiful world" with different styles +/// for each word. +/// +/// {@tool snippet} +/// +/// ![The word "Hello" is shown with the default text styles. The word "beautiful" is italicized. The word "world" is bold.](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_rich.png) +/// +/// ```dart +/// const Text.rich( +/// TextSpan( +/// text: 'Hello', // default text style +/// children: <TextSpan>[ +/// TextSpan(text: ' beautiful ', style: TextStyle(fontStyle: FontStyle.italic)), +/// TextSpan(text: 'world', style: TextStyle(fontWeight: FontWeight.bold)), +/// ], +/// ), +/// ) +/// ``` +/// {@end-tool} +/// +/// ## Interactivity +/// +/// To make [Text] react to touch events, wrap it in a [GestureDetector] widget +/// with a [GestureDetector.onTap] handler. +/// +/// In a Material Design application, consider using a [TextButton] instead, or +/// if that isn't appropriate, at least using an [InkWell] instead of +/// [GestureDetector]. +/// +/// To make sections of the text interactive, use [RichText] and specify a +/// [TapGestureRecognizer] as the [TextSpan.recognizer] of the relevant part of +/// the text. +/// +/// ## Selection +/// +/// [Text] is not selectable by default. To make a [Text] selectable, one can +/// wrap a subtree with a [SelectionArea] widget. To exclude a part of a subtree +/// under [SelectionArea] from selection, once can also wrap that part of the +/// subtree with [SelectionContainer.disabled]. +/// +/// {@tool dartpad} +/// This sample demonstrates how to disable selection for a Text under a +/// SelectionArea. +/// +/// ** See code in examples/api/lib/material/selection_container/selection_container_disabled.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [RichText], which gives you more control over the text styles. +/// * [DefaultTextStyle], which sets default styles for [Text] widgets. +/// * [SelectableRegion], which provides an overview of the selection system. +class Text extends StatelessWidget { + /// Creates a text widget. + /// + /// If the [style] argument is null, the text will use the style from the + /// closest enclosing [DefaultTextStyle]. + /// + /// The [overflow] property's behavior is affected by the [softWrap] argument. + /// If the [softWrap] is true or null, the glyph causing overflow, and those + /// that follow, will not be rendered. Otherwise, it will be shown with the + /// given overflow option. + const Text( + String this.data, { + super.key, + this.style, + this.strutStyle, + this.textAlign, + this.textDirection, + this.locale, + this.softWrap, + this.overflow, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + this.textScaleFactor, + this.textScaler, + this.maxLines, + this.semanticsLabel, + this.textWidthBasis, + this.textHeightBehavior, + this.selectionColor, + }) : textSpan = null, + assert( + textScaler == null || textScaleFactor == null, + 'textScaleFactor is deprecated and cannot be specified when textScaler is specified.', + ); + + /// Creates a text widget with a [InlineSpan]. + /// + /// The following subclasses of [InlineSpan] may be used to build rich text: + /// + /// * [TextSpan]s define text and children [InlineSpan]s. + /// * [WidgetSpan]s define embedded inline widgets. + /// + /// See [RichText] which provides a lower-level way to draw text. + const Text.rich( + InlineSpan this.textSpan, { + super.key, + this.style, + this.strutStyle, + this.textAlign, + this.textDirection, + this.locale, + this.softWrap, + this.overflow, + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + this.textScaleFactor, + this.textScaler, + this.maxLines, + this.semanticsLabel, + this.textWidthBasis, + this.textHeightBehavior, + this.selectionColor, + }) : data = null, + assert( + textScaler == null || textScaleFactor == null, + 'textScaleFactor is deprecated and cannot be specified when textScaler is specified.', + ); + + /// The text to display. + /// + /// This will be null if a [textSpan] is provided instead. + final String? data; + + /// The text to display as a [InlineSpan]. + /// + /// This will be null if [data] is provided instead. + final InlineSpan? textSpan; + + /// If non-null, the style to use for this text. + /// + /// If the style's "inherit" property is true, the style will be merged with + /// the closest enclosing [DefaultTextStyle]. Otherwise, the style will + /// replace the closest enclosing [DefaultTextStyle]. + final TextStyle? style; + + /// {@macro flutter.painting.textPainter.strutStyle} + final StrutStyle? strutStyle; + + /// How the text should be aligned horizontally. + final TextAlign? textAlign; + + /// The directionality of the text. + /// + /// This decides how [textAlign] values like [TextAlign.start] and + /// [TextAlign.end] are interpreted. + /// + /// This is also used to disambiguate how to render bidirectional text. For + /// example, if the [data] is an English phrase followed by a Hebrew phrase, + /// in a [TextDirection.ltr] context the English phrase will be on the left + /// and the Hebrew phrase to its right, while in a [TextDirection.rtl] + /// context, the English phrase will be on the right and the Hebrew phrase on + /// its left. + /// + /// Defaults to the ambient [Directionality], if any. + final TextDirection? textDirection; + + /// Used to select a font when the same Unicode character can + /// be rendered differently, depending on the locale. + /// + /// It's rarely necessary to set this property. By default its value + /// is inherited from the enclosing app with `Localizations.localeOf(context)`. + /// + /// See [RenderParagraph.locale] for more information. + final Locale? locale; + + /// Whether the text should break at soft line breaks. + /// + /// If false, the glyphs in the text will be positioned as if there was unlimited horizontal space. + final bool? softWrap; + + /// How visual overflow should be handled. + /// + /// If this is null [TextStyle.overflow] will be used, otherwise the value + /// from the nearest [DefaultTextStyle] ancestor will be used. + final TextOverflow? overflow; + + /// Deprecated. Will be removed in a future version of Flutter. Use + /// [textScaler] instead. + /// + /// The number of font pixels for each logical pixel. + /// + /// For example, if the text scale factor is 1.5, text will be 50% larger than + /// the specified font size. + /// + /// The value given to the constructor as textScaleFactor. If null, will + /// use the [MediaQueryData.textScaleFactor] obtained from the ambient + /// [MediaQuery], or 1.0 if there is no [MediaQuery] in scope. + @Deprecated( + 'Use textScaler instead. ' + 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' + 'This feature was deprecated after v3.12.0-2.0.pre.', + ) + final double? textScaleFactor; + + /// {@macro flutter.painting.textPainter.textScaler} + final TextScaler? textScaler; + + /// An optional maximum number of lines for the text to span, wrapping if necessary. + /// If the text exceeds the given number of lines, it will be truncated according + /// to [overflow]. + /// + /// If this is 1, text will not wrap. Otherwise, text will be wrapped at the + /// edge of the box. + /// + /// If this is null, but there is an ambient [DefaultTextStyle] that specifies + /// an explicit number for its [DefaultTextStyle.maxLines], then the + /// [DefaultTextStyle] value will take precedence. You can use a [RichText] + /// widget directly to entirely override the [DefaultTextStyle]. + final int? maxLines; + + /// {@template flutter.widgets.Text.semanticsLabel} + /// An alternative semantics label for this text. + /// + /// If present, the semantics of this widget will contain this value instead + /// of the actual text. This will overwrite any of the semantics labels applied + /// directly to the [TextSpan]s. + /// + /// This is useful for replacing abbreviations or shorthands with the full + /// text value: + /// + /// ```dart + /// const Text(r'$$', semanticsLabel: 'Double dollars') + /// ``` + /// {@endtemplate} + final String? semanticsLabel; + + /// {@macro flutter.painting.textPainter.textWidthBasis} + final TextWidthBasis? textWidthBasis; + + /// {@macro dart.ui.textHeightBehavior} + final ui.TextHeightBehavior? textHeightBehavior; + + /// The color to use when painting the selection. + /// + /// This is ignored if [SelectionContainer.maybeOf] returns null + /// in the [BuildContext] of the [Text] widget. + /// + /// If null, the ambient [DefaultSelectionStyle] is used (if any); failing + /// that, the selection color defaults to [DefaultSelectionStyle.defaultColor] + /// (semi-transparent grey). + final Color? selectionColor; + + @override + Widget build(BuildContext context) { + final DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(context); + TextStyle? effectiveTextStyle = style; + if (style == null || style!.inherit) { + effectiveTextStyle = defaultTextStyle.style.merge(style); + } + if (MediaQuery.boldTextOf(context)) { + effectiveTextStyle = effectiveTextStyle!.merge(const TextStyle(fontWeight: FontWeight.bold)); + } + final SelectionRegistrar? registrar = SelectionContainer.maybeOf(context); + final TextScaler textScaler = switch ((this.textScaler, textScaleFactor)) { + (final TextScaler textScaler, _) => textScaler, + // For unmigrated apps, fall back to textScaleFactor. + (null, final double textScaleFactor) => TextScaler.linear(textScaleFactor), + (null, null) => MediaQuery.textScalerOf(context), + }; + + Widget result = RichText( + textAlign: textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start, + textDirection: textDirection, // RichText uses Directionality.of to obtain a default if this is null. + locale: locale, // RichText uses Localizations.localeOf to obtain a default if this is null + softWrap: softWrap ?? defaultTextStyle.softWrap, + overflow: overflow ?? effectiveTextStyle?.overflow ?? defaultTextStyle.overflow, + textScaler: textScaler, + maxLines: maxLines ?? defaultTextStyle.maxLines, + strutStyle: strutStyle, + textWidthBasis: textWidthBasis ?? defaultTextStyle.textWidthBasis, + textHeightBehavior: textHeightBehavior ?? defaultTextStyle.textHeightBehavior ?? DefaultTextHeightBehavior.maybeOf(context), + selectionRegistrar: registrar, + selectionColor: selectionColor ?? DefaultSelectionStyle.of(context).selectionColor ?? DefaultSelectionStyle.defaultColor, + text: TextSpan( + style: effectiveTextStyle, + text: data, + children: textSpan != null ? <InlineSpan>[textSpan!] : null, + ), + ); + if (registrar != null) { + result = MouseRegion( + cursor: DefaultSelectionStyle.of(context).mouseCursor ?? SystemMouseCursors.text, + child: result, + ); + } + if (semanticsLabel != null) { + result = Semantics( + textDirection: textDirection, + label: semanticsLabel, + child: ExcludeSemantics( + child: result, + ), + ); + } + return result; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('data', data, showName: false)); + if (textSpan != null) { + properties.add(textSpan!.toDiagnosticsNode(name: 'textSpan', style: DiagnosticsTreeStyle.transition)); + } + style?.debugFillProperties(properties); + properties.add(EnumProperty<TextAlign>('textAlign', textAlign, defaultValue: null)); + properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null)); + properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null)); + properties.add(FlagProperty('softWrap', value: softWrap, ifTrue: 'wrapping at box width', ifFalse: 'no wrapping except at line break characters', showName: true)); + properties.add(EnumProperty<TextOverflow>('overflow', overflow, defaultValue: null)); + properties.add(DoubleProperty('textScaleFactor', textScaleFactor, defaultValue: null)); + properties.add(IntProperty('maxLines', maxLines, defaultValue: null)); + properties.add(EnumProperty<TextWidthBasis>('textWidthBasis', textWidthBasis, defaultValue: null)); + properties.add(DiagnosticsProperty<ui.TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null)); + if (semanticsLabel != null) { + properties.add(StringProperty('semanticsLabel', semanticsLabel)); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_editing_intents.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_editing_intents.dart new file mode 100644 index 0000000000000000000000000000000000000000..ccb39b8834bbfc4b126c50a80a2531015552345b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_editing_intents.dart @@ -0,0 +1,386 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; + +import 'actions.dart'; + +/// An [Intent] to send the event straight to the engine. +/// +/// See also: +/// +/// * [DefaultTextEditingShortcuts], which triggers this [Intent]. +class DoNothingAndStopPropagationTextIntent extends Intent { + /// Creates an instance of [DoNothingAndStopPropagationTextIntent]. + const DoNothingAndStopPropagationTextIntent(); +} + +/// A text editing related [Intent] that performs an operation towards a given +/// direction of the current caret location. +abstract class DirectionalTextEditingIntent extends Intent { + /// Creates a [DirectionalTextEditingIntent]. + const DirectionalTextEditingIntent( + this.forward, + ); + + /// Whether the input field, if applicable, should perform the text editing + /// operation from the current caret location towards the end of the document. + /// + /// Unless otherwise specified by the recipient of this intent, this parameter + /// uses the logical order of characters in the string to determine the + /// direction, and is not affected by the writing direction of the text. + final bool forward; +} + +/// Deletes the character before or after the caret location, based on whether +/// `forward` is true. +/// +/// {@template flutter.widgets.TextEditingIntents.logicalOrder} +/// {@endtemplate} +/// +/// Typically a text field will not respond to this intent if it has no active +/// caret ([TextSelection.isValid] is false for the current selection). +class DeleteCharacterIntent extends DirectionalTextEditingIntent { + /// Creates a [DeleteCharacterIntent]. + const DeleteCharacterIntent({ required bool forward }) : super(forward); +} + +/// Deletes from the current caret location to the previous or next word +/// boundary, based on whether `forward` is true. +class DeleteToNextWordBoundaryIntent extends DirectionalTextEditingIntent { + /// Creates a [DeleteToNextWordBoundaryIntent]. + const DeleteToNextWordBoundaryIntent({ required bool forward }) : super(forward); +} + +/// Deletes from the current caret location to the previous or next soft or hard +/// line break, based on whether `forward` is true. +class DeleteToLineBreakIntent extends DirectionalTextEditingIntent { + /// Creates a [DeleteToLineBreakIntent]. + const DeleteToLineBreakIntent({ required bool forward }) : super(forward); +} + +/// A [DirectionalTextEditingIntent] that moves the caret or the selection to a +/// new location. +abstract class DirectionalCaretMovementIntent extends DirectionalTextEditingIntent { + /// Creates a [DirectionalCaretMovementIntent]. + const DirectionalCaretMovementIntent( + super.forward, + this.collapseSelection, + [ + this.collapseAtReversal = false, + this.continuesAtWrap = false, + ] + ) : assert(!collapseSelection || !collapseAtReversal); + + /// Whether this [Intent] should make the selection collapsed (so it becomes a + /// caret), after the movement. + /// + /// When [collapseSelection] is false, the input field typically only moves + /// the current [TextSelection.extent] to the new location, while maintains + /// the current [TextSelection.base] location. + /// + /// When [collapseSelection] is true, the input field typically should move + /// both the [TextSelection.base] and the [TextSelection.extent] to the new + /// location. + final bool collapseSelection; + + /// Whether to collapse the selection when it would otherwise reverse order. + /// + /// For example, consider when forward is true and the extent is before the + /// base. If collapseAtReversal is true, then this will cause the selection to + /// collapse at the base. If it's false, then the extent will be placed at the + /// linebreak, reversing the order of base and offset. + /// + /// Cannot be true when collapseSelection is true. + final bool collapseAtReversal; + + /// Whether or not to continue to the next line at a wordwrap. + /// + /// If true, when an [Intent] to go to the beginning/end of a wordwrapped line + /// is received and the selection is already at the beginning/end of the line, + /// then the selection will be moved to the next/previous line. If false, the + /// selection will remain at the wordwrap. + final bool continuesAtWrap; +} + +/// Extends, or moves the current selection from the current +/// [TextSelection.extent] position to the previous or the next character +/// boundary. +class ExtendSelectionByCharacterIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExtendSelectionByCharacterIntent]. + const ExtendSelectionByCharacterIntent({ + required bool forward, + required bool collapseSelection, + }) : super(forward, collapseSelection); +} + +/// Extends, or moves the current selection from the current +/// [TextSelection.extent] position to the previous or the next word +/// boundary. +class ExtendSelectionToNextWordBoundaryIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExtendSelectionToNextWordBoundaryIntent]. + const ExtendSelectionToNextWordBoundaryIntent({ + required bool forward, + required bool collapseSelection, + }) : super(forward, collapseSelection); +} + +/// Extends, or moves the current selection from the current +/// [TextSelection.extent] position to the previous or the next word +/// boundary, or the [TextSelection.base] position if it's closer in the move +/// direction. +/// +/// This [Intent] typically has the same effect as an +/// [ExtendSelectionToNextWordBoundaryIntent], except it collapses the selection +/// when the order of [TextSelection.base] and [TextSelection.extent] would +/// reverse. +/// +/// This is typically only used on MacOS. +class ExtendSelectionToNextWordBoundaryOrCaretLocationIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExtendSelectionToNextWordBoundaryOrCaretLocationIntent]. + const ExtendSelectionToNextWordBoundaryOrCaretLocationIntent({ + required bool forward, + }) : super(forward, false, true); +} + +/// Expands the current selection to the document boundary in the direction +/// given by [forward]. +/// +/// Unlike [ExpandSelectionToLineBreakIntent], the extent will be moved, which +/// matches the behavior on MacOS. +/// +/// See also: +/// +/// [ExtendSelectionToDocumentBoundaryIntent], which is similar but always +/// moves the extent. +class ExpandSelectionToDocumentBoundaryIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExpandSelectionToDocumentBoundaryIntent]. + const ExpandSelectionToDocumentBoundaryIntent({ + required bool forward, + }) : super(forward, false); +} + +/// Expands the current selection to the closest line break in the direction +/// given by [forward]. +/// +/// Either the base or extent can move, whichever is closer to the line break. +/// The selection will never shrink. +/// +/// This behavior is common on MacOS. +/// +/// See also: +/// +/// [ExtendSelectionToLineBreakIntent], which is similar but always moves the +/// extent. +class ExpandSelectionToLineBreakIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExpandSelectionToLineBreakIntent]. + const ExpandSelectionToLineBreakIntent({ + required bool forward, + }) : super(forward, false); +} + +/// Extends, or moves the current selection from the current +/// [TextSelection.extent] position to the closest line break in the direction +/// given by [forward]. +/// +/// See also: +/// +/// [ExpandSelectionToLineBreakIntent], which is similar but always increases +/// the size of the selection. +class ExtendSelectionToLineBreakIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExtendSelectionToLineBreakIntent]. + const ExtendSelectionToLineBreakIntent({ + required bool forward, + required bool collapseSelection, + bool collapseAtReversal = false, + bool continuesAtWrap = false, + }) : assert(!collapseSelection || !collapseAtReversal), + super(forward, collapseSelection, collapseAtReversal, continuesAtWrap); +} + +/// Extends, or moves the current selection from the current +/// [TextSelection.extent] position to the closest position on the adjacent +/// line. +class ExtendSelectionVerticallyToAdjacentLineIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExtendSelectionVerticallyToAdjacentLineIntent]. + const ExtendSelectionVerticallyToAdjacentLineIntent({ + required bool forward, + required bool collapseSelection, + }) : super(forward, collapseSelection); +} + +/// Expands, or moves the current selection from the current +/// [TextSelection.extent] position to the closest position on the adjacent +/// page. +class ExtendSelectionVerticallyToAdjacentPageIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExtendSelectionVerticallyToAdjacentPageIntent]. + const ExtendSelectionVerticallyToAdjacentPageIntent({ + required bool forward, + required bool collapseSelection, + }) : super(forward, collapseSelection); +} + +/// Extends, or moves the current selection from the current +/// [TextSelection.extent] position to the previous or the next paragraph +/// boundary. +class ExtendSelectionToNextParagraphBoundaryIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExtendSelectionToNextParagraphBoundaryIntent]. + const ExtendSelectionToNextParagraphBoundaryIntent({ + required bool forward, + required bool collapseSelection, + }) : super(forward, collapseSelection); +} + +/// Extends, or moves the current selection from the current +/// [TextSelection.extent] position to the previous or the next paragraph +/// boundary depending on the [forward] parameter. +/// +/// This [Intent] typically has the same effect as an +/// [ExtendSelectionToNextParagraphBoundaryIntent], except it collapses the selection +/// when the order of [TextSelection.base] and [TextSelection.extent] would +/// reverse. +/// +/// This is typically only used on MacOS. +class ExtendSelectionToNextParagraphBoundaryOrCaretLocationIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExtendSelectionToNextParagraphBoundaryOrCaretLocationIntent]. + const ExtendSelectionToNextParagraphBoundaryOrCaretLocationIntent({ + required bool forward, + }) : super(forward, false, true); +} + +/// Extends, or moves the current selection from the current +/// [TextSelection.extent] position to the start or the end of the document. +/// +/// See also: +/// +/// [ExtendSelectionToDocumentBoundaryIntent], which is similar but always +/// increases the size of the selection. +class ExtendSelectionToDocumentBoundaryIntent extends DirectionalCaretMovementIntent { + /// Creates an [ExtendSelectionToDocumentBoundaryIntent]. + const ExtendSelectionToDocumentBoundaryIntent({ + required bool forward, + required bool collapseSelection, + }) : super(forward, collapseSelection); +} + +/// Scrolls to the beginning or end of the document depending on the [forward] +/// parameter. +class ScrollToDocumentBoundaryIntent extends DirectionalTextEditingIntent { + /// Creates a [ScrollToDocumentBoundaryIntent]. + const ScrollToDocumentBoundaryIntent({ + required bool forward, + }) : super(forward); +} + +/// Scrolls up or down by page depending on the [forward] parameter. +/// Extends the selection up or down by page based on the [forward] parameter. +class ExtendSelectionByPageIntent extends DirectionalTextEditingIntent { + /// Creates a [ExtendSelectionByPageIntent]. + const ExtendSelectionByPageIntent({ + required bool forward, + }) : super(forward); +} + +/// An [Intent] to select everything in the field. +class SelectAllTextIntent extends Intent { + /// Creates an instance of [SelectAllTextIntent]. + const SelectAllTextIntent(this.cause); + + /// {@template flutter.widgets.TextEditingIntents.cause} + /// The [SelectionChangedCause] that triggered the intent. + /// {@endtemplate} + final SelectionChangedCause cause; +} + +/// An [Intent] that represents a user interaction that attempts to copy or cut +/// the current selection in the field. +class CopySelectionTextIntent extends Intent { + const CopySelectionTextIntent._(this.cause, this.collapseSelection); + + /// Creates an [Intent] that represents a user interaction that attempts to + /// cut the current selection in the field. + const CopySelectionTextIntent.cut(SelectionChangedCause cause) : this._(cause, true); + + /// An [Intent] that represents a user interaction that attempts to copy the + /// current selection in the field. + static const CopySelectionTextIntent copy = CopySelectionTextIntent._(SelectionChangedCause.keyboard, false); + + /// {@macro flutter.widgets.TextEditingIntents.cause} + final SelectionChangedCause cause; + + /// Whether the original text needs to be removed from the input field if the + /// copy action was successful. + final bool collapseSelection; +} + +/// An [Intent] to paste text from [Clipboard] to the field. +class PasteTextIntent extends Intent { + /// Creates an instance of [PasteTextIntent]. + const PasteTextIntent(this.cause); + + /// {@macro flutter.widgets.TextEditingIntents.cause} + final SelectionChangedCause cause; +} + +/// An [Intent] that represents a user interaction that attempts to go back to +/// the previous editing state. +class RedoTextIntent extends Intent { + /// Creates a [RedoTextIntent]. + const RedoTextIntent(this.cause); + + /// {@macro flutter.widgets.TextEditingIntents.cause} + final SelectionChangedCause cause; +} + +/// An [Intent] that represents a user interaction that attempts to modify the +/// current [TextEditingValue] in an input field. +class ReplaceTextIntent extends Intent { + /// Creates a [ReplaceTextIntent]. + const ReplaceTextIntent(this.currentTextEditingValue, this.replacementText, this.replacementRange, this.cause); + + /// The [TextEditingValue] that this [Intent]'s action should perform on. + final TextEditingValue currentTextEditingValue; + + /// The text to replace the original text within the [replacementRange] with. + final String replacementText; + + /// The range of text in [currentTextEditingValue] that needs to be replaced. + final TextRange replacementRange; + + /// {@macro flutter.widgets.TextEditingIntents.cause} + final SelectionChangedCause cause; +} + +/// An [Intent] that represents a user interaction that attempts to go back to +/// the previous editing state. +class UndoTextIntent extends Intent { + /// Creates an [UndoTextIntent]. + const UndoTextIntent(this.cause); + + /// {@macro flutter.widgets.TextEditingIntents.cause} + final SelectionChangedCause cause; +} + +/// An [Intent] that represents a user interaction that attempts to change the +/// selection in an input field. +class UpdateSelectionIntent extends Intent { + /// Creates an [UpdateSelectionIntent]. + const UpdateSelectionIntent(this.currentTextEditingValue, this.newSelection, this.cause); + + /// The [TextEditingValue] that this [Intent]'s action should perform on. + final TextEditingValue currentTextEditingValue; + + /// The new [TextSelection] the input field should adopt. + final TextSelection newSelection; + + /// {@macro flutter.widgets.TextEditingIntents.cause} + final SelectionChangedCause cause; +} + +/// An [Intent] that represents a user interaction that attempts to swap the +/// characters immediately around the cursor. +class TransposeCharactersIntent extends Intent { + /// Creates a [TransposeCharactersIntent]. + const TransposeCharactersIntent(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_selection.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_selection.dart new file mode 100644 index 0000000000000000000000000000000000000000..b3c59c9cf7ffd2e9c8f3e6f16ed6f7c4f00e2e2e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_selection.dart @@ -0,0 +1,3678 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math' as math; + +import 'package:characters/characters.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +import 'basic.dart'; +import 'binding.dart'; +import 'constants.dart'; +import 'container.dart'; +import 'context_menu_controller.dart'; +import 'debug.dart'; +import 'editable_text.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'magnifier.dart'; +import 'overlay.dart'; +import 'scrollable.dart'; +import 'tap_region.dart'; +import 'ticker_provider.dart'; +import 'transitions.dart'; + +export 'package:flutter/rendering.dart' show TextSelectionPoint; +export 'package:flutter/services.dart' show TextSelectionDelegate; + +/// The type for a Function that builds a toolbar's container with the given +/// child. +/// +/// See also: +/// +/// * [TextSelectionToolbar.toolbarBuilder], which is of this type. +/// type. +/// * [CupertinoTextSelectionToolbar.toolbarBuilder], which is similar, but +/// for a Cupertino-style toolbar. +typedef ToolbarBuilder = Widget Function(BuildContext context, Widget child); + +/// ParentData that determines whether or not to paint the corresponding child. +/// +/// Used in the layout of the Cupertino and Material text selection menus, which +/// decide whether or not to paint their buttons after laying them out and +/// determining where they overflow. +class ToolbarItemsParentData extends ContainerBoxParentData<RenderBox> { + /// Whether or not this child is painted. + /// + /// Children in the selection toolbar may be laid out for measurement purposes + /// but not painted. This allows these children to be identified. + bool shouldPaint = false; + + @override + String toString() => '${super.toString()}; shouldPaint=$shouldPaint'; +} + +/// An interface for building the selection UI, to be provided by the +/// implementer of the toolbar widget. +/// +/// Parts of this class, including [buildToolbar], have been deprecated in favor +/// of [EditableText.contextMenuBuilder], which is now the preferred way to +/// customize the context menus. +/// +/// ## Use with [EditableText.contextMenuBuilder] +/// +/// For backwards compatibility during the deprecation period, when +/// [EditableText.selectionControls] is set to an object that does not mix in +/// [TextSelectionHandleControls], [EditableText.contextMenuBuilder] is ignored +/// in favor of the deprecated [buildToolbar]. +/// +/// To migrate code from [buildToolbar] to the preferred +/// [EditableText.contextMenuBuilder], while still using [buildHandle], mix in +/// [TextSelectionHandleControls] into the [TextSelectionControls] subclass when +/// moving any toolbar code to a callback passed to +/// [EditableText.contextMenuBuilder]. +/// +/// In due course, [buildToolbar] will be removed, and the mixin will no longer +/// be necessary as a way to flag to the framework that the code has been +/// migrated and does not expect [buildToolbar] to be called. +/// +/// For more information, see <https://docs.flutter.dev/release/breaking-changes/context-menus>. +/// +/// See also: +/// +/// * [SelectionArea], which selects appropriate text selection controls +/// based on the current platform. +abstract class TextSelectionControls { + /// Builds a selection handle of the given `type`. + /// + /// The top left corner of this widget is positioned at the bottom of the + /// selection position. + /// + /// The supplied [onTap] should be invoked when the handle is tapped, if such + /// interaction is allowed. As a counterexample, the default selection handle + /// on iOS [cupertinoTextSelectionControls] does not call [onTap] at all, + /// since its handles are not meant to be tapped. + Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textLineHeight, [VoidCallback? onTap]); + + /// Get the anchor point of the handle relative to itself. The anchor point is + /// the point that is aligned with a specific point in the text. A handle + /// often visually "points to" that location. + Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight); + + /// Builds a toolbar near a text selection. + /// + /// Typically displays buttons for copying and pasting text. + /// + /// The [globalEditableRegion] parameter is the TextField size of the global + /// coordinate system in logical pixels. + /// + /// The [textLineHeight] parameter is the [RenderEditable.preferredLineHeight] + /// of the [RenderEditable] we are building a toolbar for. + /// + /// The [selectionMidpoint] parameter is a general calculation midpoint + /// parameter of the toolbar. More detailed position information + /// is computable from the [endpoints] parameter. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Widget buildToolbar( + BuildContext context, + Rect globalEditableRegion, + double textLineHeight, + Offset selectionMidpoint, + List<TextSelectionPoint> endpoints, + TextSelectionDelegate delegate, + ValueListenable<ClipboardStatus>? clipboardStatus, + Offset? lastSecondaryTapDownPosition, + ); + + /// Returns the size of the selection handle. + Size getHandleSize(double textLineHeight); + + /// Whether the current selection of the text field managed by the given + /// `delegate` can be removed from the text field and placed into the + /// [Clipboard]. + /// + /// By default, false is returned when nothing is selected in the text field. + /// + /// Subclasses can use this to decide if they should expose the cut + /// functionality to the user. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + bool canCut(TextSelectionDelegate delegate) { + return delegate.cutEnabled && !delegate.textEditingValue.selection.isCollapsed; + } + + /// Whether the current selection of the text field managed by the given + /// `delegate` can be copied to the [Clipboard]. + /// + /// By default, false is returned when nothing is selected in the text field. + /// + /// Subclasses can use this to decide if they should expose the copy + /// functionality to the user. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + bool canCopy(TextSelectionDelegate delegate) { + return delegate.copyEnabled && !delegate.textEditingValue.selection.isCollapsed; + } + + /// Whether the text field managed by the given `delegate` supports pasting + /// from the clipboard. + /// + /// Subclasses can use this to decide if they should expose the paste + /// functionality to the user. + /// + /// This does not consider the contents of the clipboard. Subclasses may want + /// to, for example, disallow pasting when the clipboard contains an empty + /// string. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + bool canPaste(TextSelectionDelegate delegate) { + return delegate.pasteEnabled; + } + + /// Whether the current selection of the text field managed by the given + /// `delegate` can be extended to include the entire content of the text + /// field. + /// + /// Subclasses can use this to decide if they should expose the select all + /// functionality to the user. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + bool canSelectAll(TextSelectionDelegate delegate) { + return delegate.selectAllEnabled && delegate.textEditingValue.text.isNotEmpty && delegate.textEditingValue.selection.isCollapsed; + } + + /// Call [TextSelectionDelegate.cutSelection] to cut current selection. + /// + /// This is called by subclasses when their cut affordance is activated by + /// the user. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + void handleCut(TextSelectionDelegate delegate) { + delegate.cutSelection(SelectionChangedCause.toolbar); + } + + /// Call [TextSelectionDelegate.copySelection] to copy current selection. + /// + /// This is called by subclasses when their copy affordance is activated by + /// the user. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + void handleCopy(TextSelectionDelegate delegate) { + delegate.copySelection(SelectionChangedCause.toolbar); + } + + /// Call [TextSelectionDelegate.pasteText] to paste text. + /// + /// This is called by subclasses when their paste affordance is activated by + /// the user. + /// + /// This function is asynchronous since interacting with the clipboard is + /// asynchronous. Race conditions may exist with this API as currently + /// implemented. + // TODO(ianh): https://github.com/flutter/flutter/issues/11427 + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Future<void> handlePaste(TextSelectionDelegate delegate) async { + delegate.pasteText(SelectionChangedCause.toolbar); + } + + /// Call [TextSelectionDelegate.selectAll] to set the current selection to + /// contain the entire text value. + /// + /// Does not hide the toolbar. + /// + /// This is called by subclasses when their select-all affordance is activated + /// by the user. + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + void handleSelectAll(TextSelectionDelegate delegate) { + delegate.selectAll(SelectionChangedCause.toolbar); + } +} + +/// Text selection controls that do not show any toolbars or handles. +/// +/// This is a placeholder, suitable for temporary use during development, but +/// not practical for production. For example, it provides no way for the user +/// to interact with selections: no context menus on desktop, no toolbars or +/// drag handles on mobile, etc. For production, consider using +/// [MaterialTextSelectionControls] or creating a custom subclass of +/// [TextSelectionControls]. +/// +/// The [emptyTextSelectionControls] global variable has a +/// suitable instance of this class. +class EmptyTextSelectionControls extends TextSelectionControls { + @override + Size getHandleSize(double textLineHeight) => Size.zero; + + @override + Widget buildToolbar( + BuildContext context, + Rect globalEditableRegion, + double textLineHeight, + Offset selectionMidpoint, + List<TextSelectionPoint> endpoints, + TextSelectionDelegate delegate, + ValueListenable<ClipboardStatus>? clipboardStatus, + Offset? lastSecondaryTapDownPosition, + ) => const SizedBox.shrink(); + + @override + Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textLineHeight, [VoidCallback? onTap]) { + return const SizedBox.shrink(); + } + + @override + Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) { + return Offset.zero; + } +} + +/// Text selection controls that do not show any toolbars or handles. +/// +/// This is a placeholder, suitable for temporary use during development, but +/// not practical for production. For example, it provides no way for the user +/// to interact with selections: no context menus on desktop, no toolbars or +/// drag handles on mobile, etc. For production, consider using +/// [materialTextSelectionControls] or creating a custom subclass of +/// [TextSelectionControls]. +final TextSelectionControls emptyTextSelectionControls = EmptyTextSelectionControls(); + + +/// An object that manages a pair of text selection handles for a +/// [RenderEditable]. +/// +/// This class is a wrapper of [SelectionOverlay] to provide APIs specific for +/// [RenderEditable]s. To manage selection handles for custom widgets, use +/// [SelectionOverlay] instead. +class TextSelectionOverlay { + /// Creates an object that manages overlay entries for selection handles. + /// + /// The [context] must have an [Overlay] as an ancestor. + TextSelectionOverlay({ + required TextEditingValue value, + required this.context, + Widget? debugRequiredFor, + required LayerLink toolbarLayerLink, + required LayerLink startHandleLayerLink, + required LayerLink endHandleLayerLink, + required this.renderObject, + this.selectionControls, + bool handlesVisible = false, + required this.selectionDelegate, + DragStartBehavior dragStartBehavior = DragStartBehavior.start, + VoidCallback? onSelectionHandleTapped, + ClipboardStatusNotifier? clipboardStatus, + this.contextMenuBuilder, + required TextMagnifierConfiguration magnifierConfiguration, + }) : _handlesVisible = handlesVisible, + _value = value { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/widgets.dart', + className: '$TextSelectionOverlay', + object: this, + ); + } + renderObject.selectionStartInViewport.addListener(_updateTextSelectionOverlayVisibilities); + renderObject.selectionEndInViewport.addListener(_updateTextSelectionOverlayVisibilities); + _updateTextSelectionOverlayVisibilities(); + _selectionOverlay = SelectionOverlay( + magnifierConfiguration: magnifierConfiguration, + context: context, + debugRequiredFor: debugRequiredFor, + // The metrics will be set when show handles. + startHandleType: TextSelectionHandleType.collapsed, + startHandlesVisible: _effectiveStartHandleVisibility, + lineHeightAtStart: 0.0, + onStartHandleDragStart: _handleSelectionStartHandleDragStart, + onStartHandleDragUpdate: _handleSelectionStartHandleDragUpdate, + onEndHandleDragEnd: _handleAnyDragEnd, + endHandleType: TextSelectionHandleType.collapsed, + endHandlesVisible: _effectiveEndHandleVisibility, + lineHeightAtEnd: 0.0, + onEndHandleDragStart: _handleSelectionEndHandleDragStart, + onEndHandleDragUpdate: _handleSelectionEndHandleDragUpdate, + onStartHandleDragEnd: _handleAnyDragEnd, + toolbarVisible: _effectiveToolbarVisibility, + selectionEndpoints: const <TextSelectionPoint>[], + selectionControls: selectionControls, + selectionDelegate: selectionDelegate, + clipboardStatus: clipboardStatus, + startHandleLayerLink: startHandleLayerLink, + endHandleLayerLink: endHandleLayerLink, + toolbarLayerLink: toolbarLayerLink, + onSelectionHandleTapped: onSelectionHandleTapped, + dragStartBehavior: dragStartBehavior, + toolbarLocation: renderObject.lastSecondaryTapDownPosition, + ); + } + + /// {@template flutter.widgets.SelectionOverlay.context} + /// The context in which the selection UI should appear. + /// + /// This context must have an [Overlay] as an ancestor because this object + /// will display the text selection handles in that [Overlay]. + /// {@endtemplate} + final BuildContext context; + + // TODO(mpcomplete): what if the renderObject is removed or replaced, or + // moves? Not sure what cases I need to handle, or how to handle them. + /// The editable line in which the selected text is being displayed. + final RenderEditable renderObject; + + /// {@macro flutter.widgets.SelectionOverlay.selectionControls} + final TextSelectionControls? selectionControls; + + /// {@macro flutter.widgets.SelectionOverlay.selectionDelegate} + final TextSelectionDelegate selectionDelegate; + + late final SelectionOverlay _selectionOverlay; + + /// {@macro flutter.widgets.EditableText.contextMenuBuilder} + /// + /// If not provided, no context menu will be built. + final WidgetBuilder? contextMenuBuilder; + + /// Retrieve current value. + @visibleForTesting + TextEditingValue get value => _value; + + TextEditingValue _value; + + TextSelection get _selection => _value.selection; + + final ValueNotifier<bool> _effectiveStartHandleVisibility = ValueNotifier<bool>(false); + final ValueNotifier<bool> _effectiveEndHandleVisibility = ValueNotifier<bool>(false); + final ValueNotifier<bool> _effectiveToolbarVisibility = ValueNotifier<bool>(false); + + void _updateTextSelectionOverlayVisibilities() { + _effectiveStartHandleVisibility.value = _handlesVisible && renderObject.selectionStartInViewport.value; + _effectiveEndHandleVisibility.value = _handlesVisible && renderObject.selectionEndInViewport.value; + _effectiveToolbarVisibility.value = renderObject.selectionStartInViewport.value || renderObject.selectionEndInViewport.value; + } + + /// Whether selection handles are visible. + /// + /// Set to false if you want to hide the handles. Use this property to show or + /// hide the handle without rebuilding them. + /// + /// Defaults to false. + bool get handlesVisible => _handlesVisible; + bool _handlesVisible = false; + set handlesVisible(bool visible) { + if (_handlesVisible == visible) { + return; + } + _handlesVisible = visible; + _updateTextSelectionOverlayVisibilities(); + } + + /// {@macro flutter.widgets.SelectionOverlay.showHandles} + void showHandles() { + _updateSelectionOverlay(); + _selectionOverlay.showHandles(); + } + + /// {@macro flutter.widgets.SelectionOverlay.hideHandles} + void hideHandles() => _selectionOverlay.hideHandles(); + + /// {@macro flutter.widgets.SelectionOverlay.showToolbar} + void showToolbar() { + _updateSelectionOverlay(); + + if (selectionControls is! TextSelectionHandleControls) { + _selectionOverlay.showToolbar(); + return; + } + + if (contextMenuBuilder == null) { + return; + } + + assert(context.mounted); + _selectionOverlay.showToolbar( + context: context, + contextMenuBuilder: contextMenuBuilder, + ); + return; + } + + /// Shows toolbar with spell check suggestions of misspelled words that are + /// available for click-and-replace. + void showSpellCheckSuggestionsToolbar( + WidgetBuilder spellCheckSuggestionsToolbarBuilder + ) { + _updateSelectionOverlay(); + assert(context.mounted); + _selectionOverlay + .showSpellCheckSuggestionsToolbar( + context: context, + builder: spellCheckSuggestionsToolbarBuilder, + ); + hideHandles(); + } + + /// {@macro flutter.widgets.SelectionOverlay.showMagnifier} + void showMagnifier(Offset positionToShow) { + final TextPosition position = renderObject.getPositionForPoint(positionToShow); + _updateSelectionOverlay(); + _selectionOverlay.showMagnifier( + _buildMagnifier( + currentTextPosition: position, + globalGesturePosition: positionToShow, + renderEditable: renderObject, + ), + ); + } + + /// {@macro flutter.widgets.SelectionOverlay.updateMagnifier} + void updateMagnifier(Offset positionToShow) { + final TextPosition position = renderObject.getPositionForPoint(positionToShow); + _updateSelectionOverlay(); + _selectionOverlay.updateMagnifier( + _buildMagnifier( + currentTextPosition: position, + globalGesturePosition: positionToShow, + renderEditable: renderObject, + ), + ); + } + + /// {@macro flutter.widgets.SelectionOverlay.hideMagnifier} + void hideMagnifier() { + _selectionOverlay.hideMagnifier(); + } + + /// Updates the overlay after the selection has changed. + /// + /// If this method is called while the [SchedulerBinding.schedulerPhase] is + /// [SchedulerPhase.persistentCallbacks], i.e. during the build, layout, or + /// paint phases (see [WidgetsBinding.drawFrame]), then the update is delayed + /// until the post-frame callbacks phase. Otherwise the update is done + /// synchronously. This means that it is safe to call during builds, but also + /// that if you do call this during a build, the UI will not update until the + /// next frame (i.e. many milliseconds later). + void update(TextEditingValue newValue) { + if (_value == newValue) { + return; + } + _value = newValue; + _updateSelectionOverlay(); + // _updateSelectionOverlay may not rebuild the selection overlay if the + // text metrics and selection doesn't change even if the text has changed. + // This rebuild is needed for the toolbar to update based on the latest text + // value. + _selectionOverlay.markNeedsBuild(); + } + + void _updateSelectionOverlay() { + _selectionOverlay + // Update selection handle metrics. + ..startHandleType = _chooseType( + renderObject.textDirection, + TextSelectionHandleType.left, + TextSelectionHandleType.right, + ) + ..lineHeightAtStart = _getStartGlyphHeight() + ..endHandleType = _chooseType( + renderObject.textDirection, + TextSelectionHandleType.right, + TextSelectionHandleType.left, + ) + ..lineHeightAtEnd = _getEndGlyphHeight() + // Update selection toolbar metrics. + ..selectionEndpoints = renderObject.getEndpointsForSelection(_selection) + ..toolbarLocation = renderObject.lastSecondaryTapDownPosition; + } + + /// Causes the overlay to update its rendering. + /// + /// This is intended to be called when the [renderObject] may have changed its + /// text metrics (e.g. because the text was scrolled). + void updateForScroll() { + _updateSelectionOverlay(); + // This method may be called due to windows metrics changes. In that case, + // non of the properties in _selectionOverlay will change, but a rebuild is + // still needed. + _selectionOverlay.markNeedsBuild(); + } + + /// Whether the handles are currently visible. + bool get handlesAreVisible => _selectionOverlay._handles != null && handlesVisible; + + /// {@macro flutter.widgets.SelectionOverlay.toolbarIsVisible} + /// + /// See also: + /// + /// * [spellCheckToolbarIsVisible], which is only whether the spell check menu + /// specifically is visible. + bool get toolbarIsVisible => _selectionOverlay.toolbarIsVisible; + + /// Whether the magnifier is currently visible. + bool get magnifierIsVisible => _selectionOverlay._magnifierController.shown; + + /// Whether the spell check menu is currently visible. + /// + /// See also: + /// + /// * [toolbarIsVisible], which is whether any toolbar is visible. + bool get spellCheckToolbarIsVisible => _selectionOverlay._spellCheckToolbarController.isShown; + + /// {@macro flutter.widgets.SelectionOverlay.hide} + void hide() => _selectionOverlay.hide(); + + /// {@macro flutter.widgets.SelectionOverlay.hideToolbar} + void hideToolbar() => _selectionOverlay.hideToolbar(); + + /// {@macro flutter.widgets.SelectionOverlay.dispose} + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + _selectionOverlay.dispose(); + renderObject.selectionStartInViewport.removeListener(_updateTextSelectionOverlayVisibilities); + renderObject.selectionEndInViewport.removeListener(_updateTextSelectionOverlayVisibilities); + _effectiveToolbarVisibility.dispose(); + _effectiveStartHandleVisibility.dispose(); + _effectiveEndHandleVisibility.dispose(); + hideToolbar(); + } + + double _getStartGlyphHeight() { + final String currText = selectionDelegate.textEditingValue.text; + final int firstSelectedGraphemeExtent; + Rect? startHandleRect; + // Only calculate handle rects if the text in the previous frame + // is the same as the text in the current frame. This is done because + // widget.renderObject contains the renderEditable from the previous frame. + // If the text changed between the current and previous frames then + // widget.renderObject.getRectForComposingRange might fail. In cases where + // the current frame is different from the previous we fall back to + // renderObject.preferredLineHeight. + if (renderObject.plainText == currText && _selection.isValid && !_selection.isCollapsed) { + final String selectedGraphemes = _selection.textInside(currText); + firstSelectedGraphemeExtent = selectedGraphemes.characters.first.length; + startHandleRect = renderObject.getRectForComposingRange(TextRange(start: _selection.start, end: _selection.start + firstSelectedGraphemeExtent)); + } + return startHandleRect?.height ?? renderObject.preferredLineHeight; + } + + double _getEndGlyphHeight() { + final String currText = selectionDelegate.textEditingValue.text; + final int lastSelectedGraphemeExtent; + Rect? endHandleRect; + // See the explanation in _getStartGlyphHeight. + if (renderObject.plainText == currText && _selection.isValid && !_selection.isCollapsed) { + final String selectedGraphemes = _selection.textInside(currText); + lastSelectedGraphemeExtent = selectedGraphemes.characters.last.length; + endHandleRect = renderObject.getRectForComposingRange(TextRange(start: _selection.end - lastSelectedGraphemeExtent, end: _selection.end)); + } + return endHandleRect?.height ?? renderObject.preferredLineHeight; + } + + MagnifierInfo _buildMagnifier({ + required RenderEditable renderEditable, + required Offset globalGesturePosition, + required TextPosition currentTextPosition, + }) { + final Offset globalRenderEditableTopLeft = renderEditable.localToGlobal(Offset.zero); + final Rect localCaretRect = renderEditable.getLocalRectForCaret(currentTextPosition); + + final TextSelection lineAtOffset = renderEditable.getLineAtOffset(currentTextPosition); + final TextPosition positionAtEndOfLine = TextPosition( + offset: lineAtOffset.extentOffset, + affinity: TextAffinity.upstream, + ); + + // Default affinity is downstream. + final TextPosition positionAtBeginningOfLine = TextPosition( + offset: lineAtOffset.baseOffset, + ); + + final Rect lineBoundaries = Rect.fromPoints( + renderEditable.getLocalRectForCaret(positionAtBeginningOfLine).topCenter, + renderEditable.getLocalRectForCaret(positionAtEndOfLine).bottomCenter, + ); + + return MagnifierInfo( + fieldBounds: globalRenderEditableTopLeft & renderEditable.size, + globalGesturePosition: globalGesturePosition, + caretRect: localCaretRect.shift(globalRenderEditableTopLeft), + currentLineBoundaries: lineBoundaries.shift(globalRenderEditableTopLeft), + ); + } + + // The contact position of the gesture at the current end handle location. + // Updated when the handle moves. + late double _endHandleDragPosition; + + // The distance from _endHandleDragPosition to the center of the line that it + // corresponds to. + late double _endHandleDragPositionToCenterOfLine; + + void _handleSelectionEndHandleDragStart(DragStartDetails details) { + if (!renderObject.attached) { + return; + } + + // This adjusts for the fact that the selection handles may not + // perfectly cover the TextPosition that they correspond to. + _endHandleDragPosition = details.globalPosition.dy; + final Offset endPoint = + renderObject.localToGlobal(_selectionOverlay.selectionEndpoints.last.point); + final double centerOfLine = endPoint.dy - renderObject.preferredLineHeight / 2; + _endHandleDragPositionToCenterOfLine = centerOfLine - _endHandleDragPosition; + final TextPosition position = renderObject.getPositionForPoint( + Offset( + details.globalPosition.dx, + centerOfLine, + ), + ); + + _selectionOverlay.showMagnifier( + _buildMagnifier( + currentTextPosition: position, + globalGesturePosition: details.globalPosition, + renderEditable: renderObject, + ), + ); + } + + /// Given a handle position and drag position, returns the position of handle + /// after the drag. + /// + /// The handle jumps instantly between lines when the drag reaches a full + /// line's height away from the original handle position. In other words, the + /// line jump happens when the contact point would be located at the same + /// place on the handle at the new line as when the gesture started. + double _getHandleDy(double dragDy, double handleDy) { + final double distanceDragged = dragDy - handleDy; + final int dragDirection = distanceDragged < 0.0 ? -1 : 1; + final int linesDragged = + dragDirection * (distanceDragged.abs() / renderObject.preferredLineHeight).floor(); + return handleDy + linesDragged * renderObject.preferredLineHeight; + } + + void _handleSelectionEndHandleDragUpdate(DragUpdateDetails details) { + if (!renderObject.attached) { + return; + } + + _endHandleDragPosition = _getHandleDy(details.globalPosition.dy, _endHandleDragPosition); + final Offset adjustedOffset = Offset( + details.globalPosition.dx, + _endHandleDragPosition + _endHandleDragPositionToCenterOfLine, + ); + + final TextPosition position = renderObject.getPositionForPoint(adjustedOffset); + + if (_selection.isCollapsed) { + _selectionOverlay.updateMagnifier(_buildMagnifier( + currentTextPosition: position, + globalGesturePosition: details.globalPosition, + renderEditable: renderObject, + )); + + final TextSelection currentSelection = TextSelection.fromPosition(position); + _handleSelectionHandleChanged(currentSelection); + return; + } + + final TextSelection newSelection; + switch (defaultTargetPlatform) { + // On Apple platforms, dragging the base handle makes it the extent. + case TargetPlatform.iOS: + case TargetPlatform.macOS: + newSelection = TextSelection( + extentOffset: position.offset, + baseOffset: _selection.start, + ); + if (position.offset <= _selection.start) { + return; // Don't allow order swapping. + } + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + newSelection = TextSelection( + baseOffset: _selection.baseOffset, + extentOffset: position.offset, + ); + if (newSelection.baseOffset >= newSelection.extentOffset) { + return; // Don't allow order swapping. + } + } + + _handleSelectionHandleChanged(newSelection); + + _selectionOverlay.updateMagnifier(_buildMagnifier( + currentTextPosition: newSelection.extent, + globalGesturePosition: details.globalPosition, + renderEditable: renderObject, + )); + } + + // The contact position of the gesture at the current start handle location. + // Updated when the handle moves. + late double _startHandleDragPosition; + + // The distance from _startHandleDragPosition to the center of the line that + // it corresponds to. + late double _startHandleDragPositionToCenterOfLine; + + void _handleSelectionStartHandleDragStart(DragStartDetails details) { + if (!renderObject.attached) { + return; + } + + // This adjusts for the fact that the selection handles may not + // perfectly cover the TextPosition that they correspond to. + _startHandleDragPosition = details.globalPosition.dy; + final Offset startPoint = + renderObject.localToGlobal(_selectionOverlay.selectionEndpoints.first.point); + final double centerOfLine = startPoint.dy - renderObject.preferredLineHeight / 2; + _startHandleDragPositionToCenterOfLine = centerOfLine - _startHandleDragPosition; + final TextPosition position = renderObject.getPositionForPoint( + Offset( + details.globalPosition.dx, + centerOfLine, + ), + ); + + _selectionOverlay.showMagnifier( + _buildMagnifier( + currentTextPosition: position, + globalGesturePosition: details.globalPosition, + renderEditable: renderObject, + ), + ); + } + + void _handleSelectionStartHandleDragUpdate(DragUpdateDetails details) { + if (!renderObject.attached) { + return; + } + + _startHandleDragPosition = _getHandleDy(details.globalPosition.dy, _startHandleDragPosition); + final Offset adjustedOffset = Offset( + details.globalPosition.dx, + _startHandleDragPosition + _startHandleDragPositionToCenterOfLine, + ); + final TextPosition position = renderObject.getPositionForPoint(adjustedOffset); + + if (_selection.isCollapsed) { + _selectionOverlay.updateMagnifier(_buildMagnifier( + currentTextPosition: position, + globalGesturePosition: details.globalPosition, + renderEditable: renderObject, + )); + + final TextSelection currentSelection = TextSelection.fromPosition(position); + _handleSelectionHandleChanged(currentSelection); + return; + } + + final TextSelection newSelection; + switch (defaultTargetPlatform) { + // On Apple platforms, dragging the base handle makes it the extent. + case TargetPlatform.iOS: + case TargetPlatform.macOS: + newSelection = TextSelection( + extentOffset: position.offset, + baseOffset: _selection.end, + ); + if (newSelection.extentOffset >= _selection.end) { + return; // Don't allow order swapping. + } + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + newSelection = TextSelection( + baseOffset: position.offset, + extentOffset: _selection.extentOffset, + ); + if (newSelection.baseOffset >= newSelection.extentOffset) { + return; // Don't allow order swapping. + } + } + + _selectionOverlay.updateMagnifier(_buildMagnifier( + currentTextPosition: newSelection.extent.offset < newSelection.base.offset ? newSelection.extent : newSelection.base, + globalGesturePosition: details.globalPosition, + renderEditable: renderObject, + )); + + _handleSelectionHandleChanged(newSelection); + } + + void _handleAnyDragEnd(DragEndDetails details) { + if (!context.mounted) { + return; + } + if (selectionControls is! TextSelectionHandleControls) { + _selectionOverlay.hideMagnifier(); + if (!_selection.isCollapsed) { + _selectionOverlay.showToolbar(); + } + return; + } + _selectionOverlay.hideMagnifier(); + if (!_selection.isCollapsed) { + _selectionOverlay.showToolbar( + context: context, + contextMenuBuilder: contextMenuBuilder, + ); + } + } + + void _handleSelectionHandleChanged(TextSelection newSelection) { + selectionDelegate.userUpdateTextEditingValue( + _value.copyWith(selection: newSelection), + SelectionChangedCause.drag, + ); + } + + TextSelectionHandleType _chooseType( + TextDirection textDirection, + TextSelectionHandleType ltrType, + TextSelectionHandleType rtlType, + ) { + if (_selection.isCollapsed) { + return TextSelectionHandleType.collapsed; + } + + switch (textDirection) { + case TextDirection.ltr: + return ltrType; + case TextDirection.rtl: + return rtlType; + } + } +} + +/// An object that manages a pair of selection handles and a toolbar. +/// +/// The selection handles are displayed in the [Overlay] that most closely +/// encloses the given [BuildContext]. +class SelectionOverlay { + /// Creates an object that manages overlay entries for selection handles. + /// + /// The [context] must have an [Overlay] as an ancestor. + SelectionOverlay({ + required this.context, + this.debugRequiredFor, + required TextSelectionHandleType startHandleType, + required double lineHeightAtStart, + this.startHandlesVisible, + this.onStartHandleDragStart, + this.onStartHandleDragUpdate, + this.onStartHandleDragEnd, + required TextSelectionHandleType endHandleType, + required double lineHeightAtEnd, + this.endHandlesVisible, + this.onEndHandleDragStart, + this.onEndHandleDragUpdate, + this.onEndHandleDragEnd, + this.toolbarVisible, + required List<TextSelectionPoint> selectionEndpoints, + required this.selectionControls, + @Deprecated( + 'Use `contextMenuBuilder` in `showToolbar` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + required this.selectionDelegate, + required this.clipboardStatus, + required this.startHandleLayerLink, + required this.endHandleLayerLink, + required this.toolbarLayerLink, + this.dragStartBehavior = DragStartBehavior.start, + this.onSelectionHandleTapped, + @Deprecated( + 'Use `contextMenuBuilder` in `showToolbar` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Offset? toolbarLocation, + this.magnifierConfiguration = TextMagnifierConfiguration.disabled, + }) : _startHandleType = startHandleType, + _lineHeightAtStart = lineHeightAtStart, + _endHandleType = endHandleType, + _lineHeightAtEnd = lineHeightAtEnd, + _selectionEndpoints = selectionEndpoints, + _toolbarLocation = toolbarLocation, + assert(debugCheckHasOverlay(context)) { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/widgets.dart', + className: '$SelectionOverlay', + object: this, + ); + } + } + + /// {@macro flutter.widgets.SelectionOverlay.context} + final BuildContext context; + + final ValueNotifier<MagnifierInfo> _magnifierInfo = + ValueNotifier<MagnifierInfo>(MagnifierInfo.empty); + + /// [MagnifierController.show] and [MagnifierController.hide] should not be called directly, except + /// from inside [showMagnifier] and [hideMagnifier]. If it is desired to show or hide the magnifier, + /// call [showMagnifier] or [hideMagnifier]. This is because the magnifier needs to orchestrate + /// with other properties in [SelectionOverlay]. + final MagnifierController _magnifierController = MagnifierController(); + + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.intro} + /// + /// {@macro flutter.widgets.magnifier.intro} + /// + /// By default, [SelectionOverlay]'s [TextMagnifierConfiguration] is disabled. + /// + /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.details} + final TextMagnifierConfiguration magnifierConfiguration; + + /// {@template flutter.widgets.SelectionOverlay.toolbarIsVisible} + /// Whether the toolbar is currently visible. + /// + /// Includes both the text selection toolbar and the spell check menu. + /// {@endtemplate} + bool get toolbarIsVisible { + return selectionControls is TextSelectionHandleControls + ? _contextMenuController.isShown || _spellCheckToolbarController.isShown + : _toolbar != null || _spellCheckToolbarController.isShown; + } + + /// {@template flutter.widgets.SelectionOverlay.showMagnifier} + /// Shows the magnifier, and hides the toolbar if it was showing when [showMagnifier] + /// was called. This is safe to call on platforms not mobile, since + /// a magnifierBuilder will not be provided, or the magnifierBuilder will return null + /// on platforms not mobile. + /// + /// This is NOT the source of truth for if the magnifier is up or not, + /// since magnifiers may hide themselves. If this info is needed, check + /// [MagnifierController.shown]. + /// {@endtemplate} + void showMagnifier(MagnifierInfo initialMagnifierInfo) { + if (toolbarIsVisible) { + hideToolbar(); + } + + // Start from empty, so we don't utilize any remnant values. + _magnifierInfo.value = initialMagnifierInfo; + + // Pre-build the magnifiers so we can tell if we've built something + // or not. If we don't build a magnifiers, then we should not + // insert anything in the overlay. + final Widget? builtMagnifier = magnifierConfiguration.magnifierBuilder( + context, + _magnifierController, + _magnifierInfo, + ); + + if (builtMagnifier == null) { + return; + } + + _magnifierController.show( + context: context, + below: magnifierConfiguration.shouldDisplayHandlesInMagnifier + ? null + : _handles?.start, + builder: (_) => builtMagnifier); + } + + /// {@template flutter.widgets.SelectionOverlay.hideMagnifier} + /// Hide the current magnifier. + /// + /// This does nothing if there is no magnifier. + /// {@endtemplate} + void hideMagnifier() { + // This cannot be a check on `MagnifierController.shown`, since + // it's possible that the magnifier is still in the overlay, but + // not shown in cases where the magnifier hides itself. + if (_magnifierController.overlayEntry == null) { + return; + } + + _magnifierController.hide(); + } + + /// The type of start selection handle. + /// + /// Changing the value while the handles are visible causes them to rebuild. + TextSelectionHandleType get startHandleType => _startHandleType; + TextSelectionHandleType _startHandleType; + set startHandleType(TextSelectionHandleType value) { + if (_startHandleType == value) { + return; + } + _startHandleType = value; + markNeedsBuild(); + } + + /// The line height at the selection start. + /// + /// This value is used for calculating the size of the start selection handle. + /// + /// Changing the value while the handles are visible causes them to rebuild. + double get lineHeightAtStart => _lineHeightAtStart; + double _lineHeightAtStart; + set lineHeightAtStart(double value) { + if (_lineHeightAtStart == value) { + return; + } + _lineHeightAtStart = value; + markNeedsBuild(); + } + + bool _isDraggingStartHandle = false; + + /// Whether the start handle is visible. + /// + /// If the value changes, the start handle uses [FadeTransition] to transition + /// itself on and off the screen. + /// + /// If this is null, the start selection handle will always be visible. + final ValueListenable<bool>? startHandlesVisible; + + /// Called when the users start dragging the start selection handles. + final ValueChanged<DragStartDetails>? onStartHandleDragStart; + + void _handleStartHandleDragStart(DragStartDetails details) { + assert(!_isDraggingStartHandle); + // Calling OverlayEntry.remove may not happen until the following frame, so + // it's possible for the handles to receive a gesture after calling remove. + if (_handles == null) { + _isDraggingStartHandle = false; + return; + } + _isDraggingStartHandle = details.kind == PointerDeviceKind.touch; + onStartHandleDragStart?.call(details); + } + + void _handleStartHandleDragUpdate(DragUpdateDetails details) { + // Calling OverlayEntry.remove may not happen until the following frame, so + // it's possible for the handles to receive a gesture after calling remove. + if (_handles == null) { + _isDraggingStartHandle = false; + return; + } + onStartHandleDragUpdate?.call(details); + } + + /// Called when the users drag the start selection handles to new locations. + final ValueChanged<DragUpdateDetails>? onStartHandleDragUpdate; + + /// Called when the users lift their fingers after dragging the start selection + /// handles. + final ValueChanged<DragEndDetails>? onStartHandleDragEnd; + + void _handleStartHandleDragEnd(DragEndDetails details) { + _isDraggingStartHandle = false; + // Calling OverlayEntry.remove may not happen until the following frame, so + // it's possible for the handles to receive a gesture after calling remove. + if (_handles == null) { + return; + } + onStartHandleDragEnd?.call(details); + } + + /// The type of end selection handle. + /// + /// Changing the value while the handles are visible causes them to rebuild. + TextSelectionHandleType get endHandleType => _endHandleType; + TextSelectionHandleType _endHandleType; + set endHandleType(TextSelectionHandleType value) { + if (_endHandleType == value) { + return; + } + _endHandleType = value; + markNeedsBuild(); + } + + /// The line height at the selection end. + /// + /// This value is used for calculating the size of the end selection handle. + /// + /// Changing the value while the handles are visible causes them to rebuild. + double get lineHeightAtEnd => _lineHeightAtEnd; + double _lineHeightAtEnd; + set lineHeightAtEnd(double value) { + if (_lineHeightAtEnd == value) { + return; + } + _lineHeightAtEnd = value; + markNeedsBuild(); + } + + bool _isDraggingEndHandle = false; + + /// Whether the end handle is visible. + /// + /// If the value changes, the end handle uses [FadeTransition] to transition + /// itself on and off the screen. + /// + /// If this is null, the end selection handle will always be visible. + final ValueListenable<bool>? endHandlesVisible; + + /// Called when the users start dragging the end selection handles. + final ValueChanged<DragStartDetails>? onEndHandleDragStart; + + void _handleEndHandleDragStart(DragStartDetails details) { + assert(!_isDraggingEndHandle); + // Calling OverlayEntry.remove may not happen until the following frame, so + // it's possible for the handles to receive a gesture after calling remove. + if (_handles == null) { + _isDraggingEndHandle = false; + return; + } + _isDraggingEndHandle = details.kind == PointerDeviceKind.touch; + onEndHandleDragStart?.call(details); + } + + void _handleEndHandleDragUpdate(DragUpdateDetails details) { + // Calling OverlayEntry.remove may not happen until the following frame, so + // it's possible for the handles to receive a gesture after calling remove. + if (_handles == null) { + _isDraggingEndHandle = false; + return; + } + onEndHandleDragUpdate?.call(details); + } + + /// Called when the users drag the end selection handles to new locations. + final ValueChanged<DragUpdateDetails>? onEndHandleDragUpdate; + + /// Called when the users lift their fingers after dragging the end selection + /// handles. + final ValueChanged<DragEndDetails>? onEndHandleDragEnd; + + void _handleEndHandleDragEnd(DragEndDetails details) { + _isDraggingEndHandle = false; + // Calling OverlayEntry.remove may not happen until the following frame, so + // it's possible for the handles to receive a gesture after calling remove. + if (_handles == null) { + return; + } + onEndHandleDragEnd?.call(details); + } + + /// Whether the toolbar is visible. + /// + /// If the value changes, the toolbar uses [FadeTransition] to transition + /// itself on and off the screen. + /// + /// If this is null the toolbar will always be visible. + final ValueListenable<bool>? toolbarVisible; + + /// The text selection positions of selection start and end. + List<TextSelectionPoint> get selectionEndpoints => _selectionEndpoints; + List<TextSelectionPoint> _selectionEndpoints; + set selectionEndpoints(List<TextSelectionPoint> value) { + if (!listEquals(_selectionEndpoints, value)) { + markNeedsBuild(); + if (_isDraggingEndHandle || _isDraggingStartHandle) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + HapticFeedback.selectionClick(); + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + break; + } + } + } + _selectionEndpoints = value; + } + + /// Debugging information for explaining why the [Overlay] is required. + final Widget? debugRequiredFor; + + /// The object supplied to the [CompositedTransformTarget] that wraps the text + /// field. + final LayerLink toolbarLayerLink; + + /// The objects supplied to the [CompositedTransformTarget] that wraps the + /// location of start selection handle. + final LayerLink startHandleLayerLink; + + /// The objects supplied to the [CompositedTransformTarget] that wraps the + /// location of end selection handle. + final LayerLink endHandleLayerLink; + + /// {@template flutter.widgets.SelectionOverlay.selectionControls} + /// Builds text selection handles and toolbar. + /// {@endtemplate} + final TextSelectionControls? selectionControls; + + /// {@template flutter.widgets.SelectionOverlay.selectionDelegate} + /// The delegate for manipulating the current selection in the owning + /// text field. + /// {@endtemplate} + @Deprecated( + 'Use `contextMenuBuilder` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + final TextSelectionDelegate? selectionDelegate; + + /// Determines the way that drag start behavior is handled. + /// + /// If set to [DragStartBehavior.start], handle drag behavior will + /// begin at the position where the drag gesture won the arena. If set to + /// [DragStartBehavior.down] it will begin at the position where a down + /// event is first detected. + /// + /// In general, setting this to [DragStartBehavior.start] will make drag + /// animation smoother and setting it to [DragStartBehavior.down] will make + /// drag behavior feel slightly more reactive. + /// + /// By default, the drag start behavior is [DragStartBehavior.start]. + /// + /// See also: + /// + /// * [DragGestureRecognizer.dragStartBehavior], which gives an example for the different behaviors. + final DragStartBehavior dragStartBehavior; + + /// {@template flutter.widgets.SelectionOverlay.onSelectionHandleTapped} + /// A callback that's optionally invoked when a selection handle is tapped. + /// + /// The [TextSelectionControls.buildHandle] implementation the text field + /// uses decides where the handle's tap "hotspot" is, or whether the + /// selection handle supports tap gestures at all. For instance, + /// [MaterialTextSelectionControls] calls [onSelectionHandleTapped] when the + /// selection handle's "knob" is tapped, while + /// [CupertinoTextSelectionControls] builds a handle that's not sufficiently + /// large for tapping (as it's not meant to be tapped) so it does not call + /// [onSelectionHandleTapped] even when tapped. + /// {@endtemplate} + // See https://github.com/flutter/flutter/issues/39376#issuecomment-848406415 + // for provenance. + final VoidCallback? onSelectionHandleTapped; + + /// Maintains the status of the clipboard for determining if its contents can + /// be pasted or not. + /// + /// Useful because the actual value of the clipboard can only be checked + /// asynchronously (see [Clipboard.getData]). + final ClipboardStatusNotifier? clipboardStatus; + + /// The location of where the toolbar should be drawn in relative to the + /// location of [toolbarLayerLink]. + /// + /// If this is null, the toolbar is drawn based on [selectionEndpoints] and + /// the rect of render object of [context]. + /// + /// This is useful for displaying toolbars at the mouse right-click locations + /// in desktop devices. + @Deprecated( + 'Use the `contextMenuBuilder` parameter in `showToolbar` instead. ' + 'This feature was deprecated after v3.3.0-0.5.pre.', + ) + Offset? get toolbarLocation => _toolbarLocation; + Offset? _toolbarLocation; + set toolbarLocation(Offset? value) { + if (_toolbarLocation == value) { + return; + } + _toolbarLocation = value; + markNeedsBuild(); + } + + /// Controls the fade-in and fade-out animations for the toolbar and handles. + static const Duration fadeDuration = Duration(milliseconds: 150); + + /// A pair of handles. If this is non-null, there are always 2, though the + /// second is hidden when the selection is collapsed. + ({OverlayEntry start, OverlayEntry end})? _handles; + + /// A copy/paste toolbar. + OverlayEntry? _toolbar; + + // Manages the context menu. Not necessarily visible when non-null. + final ContextMenuController _contextMenuController = ContextMenuController(); + + final ContextMenuController _spellCheckToolbarController = ContextMenuController(); + + /// {@template flutter.widgets.SelectionOverlay.showHandles} + /// Builds the handles by inserting them into the [context]'s overlay. + /// {@endtemplate} + void showHandles() { + if (_handles != null) { + return; + } + + _handles = ( + start: OverlayEntry(builder: _buildStartHandle), + end: OverlayEntry(builder: _buildEndHandle), + ); + Overlay.of(context, rootOverlay: true, debugRequiredFor: debugRequiredFor) + .insertAll(<OverlayEntry>[_handles!.start, _handles!.end]); + } + + /// {@template flutter.widgets.SelectionOverlay.hideHandles} + /// Destroys the handles by removing them from overlay. + /// {@endtemplate} + void hideHandles() { + if (_handles != null) { + _handles!.start.remove(); + _handles!.start.dispose(); + _handles!.end.remove(); + _handles!.end.dispose(); + _handles = null; + } + } + + /// {@template flutter.widgets.SelectionOverlay.showToolbar} + /// Shows the toolbar by inserting it into the [context]'s overlay. + /// {@endtemplate} + void showToolbar({ + BuildContext? context, + WidgetBuilder? contextMenuBuilder, + }) { + if (contextMenuBuilder == null) { + if (_toolbar != null) { + return; + } + _toolbar = OverlayEntry(builder: _buildToolbar); + Overlay.of(this.context, rootOverlay: true, debugRequiredFor: debugRequiredFor).insert(_toolbar!); + return; + } + + if (context == null) { + return; + } + + final RenderBox renderBox = context.findRenderObject()! as RenderBox; + _contextMenuController.show( + context: context, + contextMenuBuilder: (BuildContext context) { + return _SelectionToolbarWrapper( + layerLink: toolbarLayerLink, + offset: -renderBox.localToGlobal(Offset.zero), + child: contextMenuBuilder(context), + ); + }, + ); + } + + /// Shows toolbar with spell check suggestions of misspelled words that are + /// available for click-and-replace. + void showSpellCheckSuggestionsToolbar({ + BuildContext? context, + required WidgetBuilder builder, + }) { + if (context == null) { + return; + } + + final RenderBox renderBox = context.findRenderObject()! as RenderBox; + _spellCheckToolbarController.show( + context: context, + contextMenuBuilder: (BuildContext context) { + return _SelectionToolbarWrapper( + layerLink: toolbarLayerLink, + offset: -renderBox.localToGlobal(Offset.zero), + child: builder(context), + ); + }, + ); + } + + bool _buildScheduled = false; + + /// Rebuilds the selection toolbar or handles if they are present. + void markNeedsBuild() { + if (_handles == null && _toolbar == null) { + return; + } + // If we are in build state, it will be too late to update visibility. + // We will need to schedule the build in next frame. + if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks) { + if (_buildScheduled) { + return; + } + _buildScheduled = true; + SchedulerBinding.instance.addPostFrameCallback((Duration duration) { + _buildScheduled = false; + if (_handles != null) { + _handles!.start.markNeedsBuild(); + _handles!.end.markNeedsBuild(); + } + _toolbar?.markNeedsBuild(); + if (_contextMenuController.isShown) { + _contextMenuController.markNeedsBuild(); + } else if (_spellCheckToolbarController.isShown) { + _spellCheckToolbarController.markNeedsBuild(); + } + }, debugLabel: 'SelectionOverlay.markNeedsBuild'); + } else { + if (_handles != null) { + _handles!.start.markNeedsBuild(); + _handles!.end.markNeedsBuild(); + } + _toolbar?.markNeedsBuild(); + if (_contextMenuController.isShown) { + _contextMenuController.markNeedsBuild(); + } else if (_spellCheckToolbarController.isShown) { + _spellCheckToolbarController.markNeedsBuild(); + } + } + } + + /// {@template flutter.widgets.SelectionOverlay.hide} + /// Hides the entire overlay including the toolbar and the handles. + /// {@endtemplate} + void hide() { + _magnifierController.hide(); + if (_handles != null) { + _handles!.start.remove(); + _handles!.start.dispose(); + _handles!.end.remove(); + _handles!.end.dispose(); + _handles = null; + } + if (_toolbar != null || _contextMenuController.isShown || _spellCheckToolbarController.isShown) { + hideToolbar(); + } + } + + /// {@template flutter.widgets.SelectionOverlay.hideToolbar} + /// Hides the toolbar part of the overlay. + /// + /// To hide the whole overlay, see [hide]. + /// {@endtemplate} + void hideToolbar() { + _contextMenuController.remove(); + _spellCheckToolbarController.remove(); + if (_toolbar == null) { + return; + } + _toolbar?.remove(); + _toolbar?.dispose(); + _toolbar = null; + } + + /// {@template flutter.widgets.SelectionOverlay.dispose} + /// Disposes this object and release resources. + /// {@endtemplate} + void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } + hide(); + _magnifierInfo.dispose(); + } + + Widget _buildStartHandle(BuildContext context) { + final Widget handle; + final TextSelectionControls? selectionControls = this.selectionControls; + if (selectionControls == null) { + handle = const SizedBox.shrink(); + } else { + handle = _SelectionHandleOverlay( + type: _startHandleType, + handleLayerLink: startHandleLayerLink, + onSelectionHandleTapped: onSelectionHandleTapped, + onSelectionHandleDragStart: _handleStartHandleDragStart, + onSelectionHandleDragUpdate: _handleStartHandleDragUpdate, + onSelectionHandleDragEnd: _handleStartHandleDragEnd, + selectionControls: selectionControls, + visibility: startHandlesVisible, + preferredLineHeight: _lineHeightAtStart, + dragStartBehavior: dragStartBehavior, + ); + } + return TextFieldTapRegion( + child: ExcludeSemantics( + child: handle, + ), + ); + } + + Widget _buildEndHandle(BuildContext context) { + final Widget handle; + final TextSelectionControls? selectionControls = this.selectionControls; + if (selectionControls == null || _startHandleType == TextSelectionHandleType.collapsed) { + // Hide the second handle when collapsed. + handle = const SizedBox.shrink(); + } else { + handle = _SelectionHandleOverlay( + type: _endHandleType, + handleLayerLink: endHandleLayerLink, + onSelectionHandleTapped: onSelectionHandleTapped, + onSelectionHandleDragStart: _handleEndHandleDragStart, + onSelectionHandleDragUpdate: _handleEndHandleDragUpdate, + onSelectionHandleDragEnd: _handleEndHandleDragEnd, + selectionControls: selectionControls, + visibility: endHandlesVisible, + preferredLineHeight: _lineHeightAtEnd, + dragStartBehavior: dragStartBehavior, + ); + } + return TextFieldTapRegion( + child: ExcludeSemantics( + child: handle, + ), + ); + } + + // Build the toolbar via TextSelectionControls. + Widget _buildToolbar(BuildContext context) { + if (selectionControls == null) { + return const SizedBox.shrink(); + } + assert(selectionDelegate != null, 'If not using contextMenuBuilder, must pass selectionDelegate.'); + + final RenderBox renderBox = this.context.findRenderObject()! as RenderBox; + + final Rect editingRegion = Rect.fromPoints( + renderBox.localToGlobal(Offset.zero), + renderBox.localToGlobal(renderBox.size.bottomRight(Offset.zero)), + ); + + final bool isMultiline = selectionEndpoints.last.point.dy - selectionEndpoints.first.point.dy > + lineHeightAtEnd / 2; + + // If the selected text spans more than 1 line, horizontally center the toolbar. + // Derived from both iOS and Android. + final double midX = isMultiline + ? editingRegion.width / 2 + : (selectionEndpoints.first.point.dx + selectionEndpoints.last.point.dx) / 2; + + final Offset midpoint = Offset( + midX, + // The y-coordinate won't be made use of most likely. + selectionEndpoints.first.point.dy - lineHeightAtStart, + ); + + return _SelectionToolbarWrapper( + visibility: toolbarVisible, + layerLink: toolbarLayerLink, + offset: -editingRegion.topLeft, + child: Builder( + builder: (BuildContext context) { + return selectionControls!.buildToolbar( + context, + editingRegion, + lineHeightAtStart, + midpoint, + selectionEndpoints, + selectionDelegate!, + clipboardStatus, + toolbarLocation, + ); + }, + ), + ); + } + + /// {@template flutter.widgets.SelectionOverlay.updateMagnifier} + /// Update the current magnifier with new selection data, so the magnifier + /// can respond accordingly. + /// + /// If the magnifier is not shown, this still updates the magnifier position + /// because the magnifier may have hidden itself and is looking for a cue to reshow + /// itself. + /// + /// If there is no magnifier in the overlay, this does nothing. + /// {@endtemplate} + void updateMagnifier(MagnifierInfo magnifierInfo) { + if (_magnifierController.overlayEntry == null) { + return; + } + + _magnifierInfo.value = magnifierInfo; + } +} + +// TODO(justinmc): Currently this fades in but not out on all platforms. It +// should follow the correct fading behavior for the current platform, then be +// made public and de-duplicated with widgets/selectable_region.dart. +// https://github.com/flutter/flutter/issues/107732 +// Wrap the given child in the widgets common to both contextMenuBuilder and +// TextSelectionControls.buildToolbar. +class _SelectionToolbarWrapper extends StatefulWidget { + const _SelectionToolbarWrapper({ + this.visibility, + required this.layerLink, + required this.offset, + required this.child, + }); + + final Widget child; + final Offset offset; + final LayerLink layerLink; + final ValueListenable<bool>? visibility; + + @override + State<_SelectionToolbarWrapper> createState() => _SelectionToolbarWrapperState(); +} + +class _SelectionToolbarWrapperState extends State<_SelectionToolbarWrapper> with SingleTickerProviderStateMixin { + late AnimationController _controller; + Animation<double> get _opacity => _controller.view; + + @override + void initState() { + super.initState(); + + _controller = AnimationController(duration: SelectionOverlay.fadeDuration, vsync: this); + + _toolbarVisibilityChanged(); + widget.visibility?.addListener(_toolbarVisibilityChanged); + } + + @override + void didUpdateWidget(_SelectionToolbarWrapper oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.visibility == widget.visibility) { + return; + } + oldWidget.visibility?.removeListener(_toolbarVisibilityChanged); + _toolbarVisibilityChanged(); + widget.visibility?.addListener(_toolbarVisibilityChanged); + } + + @override + void dispose() { + widget.visibility?.removeListener(_toolbarVisibilityChanged); + _controller.dispose(); + super.dispose(); + } + + void _toolbarVisibilityChanged() { + if (widget.visibility?.value ?? true) { + _controller.forward(); + } else { + _controller.reverse(); + } + } + + @override + Widget build(BuildContext context) { + return TextFieldTapRegion( + child: Directionality( + textDirection: Directionality.of(this.context), + child: FadeTransition( + opacity: _opacity, + child: CompositedTransformFollower( + link: widget.layerLink, + showWhenUnlinked: false, + offset: widget.offset, + child: widget.child, + ), + ), + ), + ); + } +} + +/// This widget represents a single draggable selection handle. +class _SelectionHandleOverlay extends StatefulWidget { + /// Create selection overlay. + const _SelectionHandleOverlay({ + required this.type, + required this.handleLayerLink, + this.onSelectionHandleTapped, + this.onSelectionHandleDragStart, + this.onSelectionHandleDragUpdate, + this.onSelectionHandleDragEnd, + required this.selectionControls, + this.visibility, + required this.preferredLineHeight, + this.dragStartBehavior = DragStartBehavior.start, + }); + + final LayerLink handleLayerLink; + final VoidCallback? onSelectionHandleTapped; + final ValueChanged<DragStartDetails>? onSelectionHandleDragStart; + final ValueChanged<DragUpdateDetails>? onSelectionHandleDragUpdate; + final ValueChanged<DragEndDetails>? onSelectionHandleDragEnd; + final TextSelectionControls selectionControls; + final ValueListenable<bool>? visibility; + final double preferredLineHeight; + final TextSelectionHandleType type; + final DragStartBehavior dragStartBehavior; + + @override + State<_SelectionHandleOverlay> createState() => _SelectionHandleOverlayState(); +} + +class _SelectionHandleOverlayState extends State<_SelectionHandleOverlay> with SingleTickerProviderStateMixin { + late AnimationController _controller; + Animation<double> get _opacity => _controller.view; + + @override + void initState() { + super.initState(); + + _controller = AnimationController(duration: SelectionOverlay.fadeDuration, vsync: this); + + _handleVisibilityChanged(); + widget.visibility?.addListener(_handleVisibilityChanged); + } + + void _handleVisibilityChanged() { + if (widget.visibility?.value ?? true) { + _controller.forward(); + } else { + _controller.reverse(); + } + } + + @override + void didUpdateWidget(_SelectionHandleOverlay oldWidget) { + super.didUpdateWidget(oldWidget); + oldWidget.visibility?.removeListener(_handleVisibilityChanged); + _handleVisibilityChanged(); + widget.visibility?.addListener(_handleVisibilityChanged); + } + + @override + void dispose() { + widget.visibility?.removeListener(_handleVisibilityChanged); + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final Offset handleAnchor = widget.selectionControls.getHandleAnchor( + widget.type, + widget.preferredLineHeight, + ); + final Size handleSize = widget.selectionControls.getHandleSize( + widget.preferredLineHeight, + ); + + final Rect handleRect = Rect.fromLTWH( + -handleAnchor.dx, + -handleAnchor.dy, + handleSize.width, + handleSize.height, + ); + + // Make sure the GestureDetector is big enough to be easily interactive. + final Rect interactiveRect = handleRect.expandToInclude( + Rect.fromCircle(center: handleRect.center, radius: kMinInteractiveDimension / 2), + ); + final RelativeRect padding = RelativeRect.fromLTRB( + math.max((interactiveRect.width - handleRect.width) / 2, 0), + math.max((interactiveRect.height - handleRect.height) / 2, 0), + math.max((interactiveRect.width - handleRect.width) / 2, 0), + math.max((interactiveRect.height - handleRect.height) / 2, 0), + ); + + return CompositedTransformFollower( + link: widget.handleLayerLink, + offset: interactiveRect.topLeft, + showWhenUnlinked: false, + child: FadeTransition( + opacity: _opacity, + child: Container( + alignment: Alignment.topLeft, + width: interactiveRect.width, + height: interactiveRect.height, + child: RawGestureDetector( + behavior: HitTestBehavior.translucent, + gestures: <Type, GestureRecognizerFactory>{ + PanGestureRecognizer: GestureRecognizerFactoryWithHandlers<PanGestureRecognizer>( + () => PanGestureRecognizer( + debugOwner: this, + // Mouse events select the text and do not drag the cursor. + supportedDevices: <PointerDeviceKind>{ + PointerDeviceKind.touch, + PointerDeviceKind.stylus, + PointerDeviceKind.unknown, + }, + ), + (PanGestureRecognizer instance) { + instance + ..dragStartBehavior = widget.dragStartBehavior + ..onStart = widget.onSelectionHandleDragStart + ..onUpdate = widget.onSelectionHandleDragUpdate + ..onEnd = widget.onSelectionHandleDragEnd; + }, + ), + }, + child: Padding( + padding: EdgeInsets.only( + left: padding.left, + top: padding.top, + right: padding.right, + bottom: padding.bottom, + ), + child: widget.selectionControls.buildHandle( + context, + widget.type, + widget.preferredLineHeight, + widget.onSelectionHandleTapped, + ), + ), + ), + ), + ), + ); + } +} + +/// Delegate interface for the [TextSelectionGestureDetectorBuilder]. +/// +/// The interface is usually implemented by the [State] of text field +/// implementations wrapping [EditableText], so that they can use a +/// [TextSelectionGestureDetectorBuilder] to build a +/// [TextSelectionGestureDetector] for their [EditableText]. The delegate +/// provides the builder with information about the current state of the text +/// field. Based on that information, the builder adds the correct gesture +/// handlers to the gesture detector. +/// +/// See also: +/// +/// * [TextField], which implements this delegate for the Material text field. +/// * [CupertinoTextField], which implements this delegate for the Cupertino +/// text field. +abstract class TextSelectionGestureDetectorBuilderDelegate { + /// [GlobalKey] to the [EditableText] for which the + /// [TextSelectionGestureDetectorBuilder] will build a [TextSelectionGestureDetector]. + GlobalKey<EditableTextState> get editableTextKey; + + /// Whether the text field should respond to force presses. + bool get forcePressEnabled; + + /// Whether the user may select text in the text field. + bool get selectionEnabled; +} + +/// Builds a [TextSelectionGestureDetector] to wrap an [EditableText]. +/// +/// The class implements sensible defaults for many user interactions +/// with an [EditableText] (see the documentation of the various gesture handler +/// methods, e.g. [onTapDown], [onForcePressStart], etc.). Subclasses of +/// [TextSelectionGestureDetectorBuilder] can change the behavior performed in +/// responds to these gesture events by overriding the corresponding handler +/// methods of this class. +/// +/// The resulting [TextSelectionGestureDetector] to wrap an [EditableText] is +/// obtained by calling [buildGestureDetector]. +/// +/// A [TextSelectionGestureDetectorBuilder] must be provided a +/// [TextSelectionGestureDetectorBuilderDelegate], from which information about +/// the [EditableText] may be obtained. Typically, the [State] of the widget +/// that builds the [EditableText] implements this interface, and then passes +/// itself as the [delegate]. +/// +/// See also: +/// +/// * [TextField], which uses a subclass to implement the Material-specific +/// gesture logic of an [EditableText]. +/// * [CupertinoTextField], which uses a subclass to implement the +/// Cupertino-specific gesture logic of an [EditableText]. +class TextSelectionGestureDetectorBuilder { + /// Creates a [TextSelectionGestureDetectorBuilder]. + TextSelectionGestureDetectorBuilder({ + required this.delegate, + }); + + /// The delegate for this [TextSelectionGestureDetectorBuilder]. + /// + /// The delegate provides the builder with information about what actions can + /// currently be performed on the text field. Based on this, the builder adds + /// the correct gesture handlers to the gesture detector. + /// + /// Typically implemented by a [State] of a widget that builds an + /// [EditableText]. + @protected + final TextSelectionGestureDetectorBuilderDelegate delegate; + + // Shows the magnifier on supported platforms at the given offset, currently + // only Android and iOS. + void _showMagnifierIfSupportedByPlatform(Offset positionToShow) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + editableText.showMagnifier(positionToShow); + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + } + } + + // Hides the magnifier on supported platforms, currently only Android and iOS. + void _hideMagnifierIfSupportedByPlatform() { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.iOS: + editableText.hideMagnifier(); + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + } + } + + /// Returns true if lastSecondaryTapDownPosition was on selection. + bool get _lastSecondaryTapWasOnSelection { + assert(renderEditable.lastSecondaryTapDownPosition != null); + if (renderEditable.selection == null) { + return false; + } + + final TextPosition textPosition = renderEditable.getPositionForPoint( + renderEditable.lastSecondaryTapDownPosition!, + ); + + return renderEditable.selection!.start <= textPosition.offset + && renderEditable.selection!.end >= textPosition.offset; + } + + bool _positionWasOnSelectionExclusive(TextPosition textPosition) { + final TextSelection? selection = renderEditable.selection; + if (selection == null) { + return false; + } + + return selection.start < textPosition.offset + && selection.end > textPosition.offset; + } + + bool _positionWasOnSelectionInclusive(TextPosition textPosition) { + final TextSelection? selection = renderEditable.selection; + if (selection == null) { + return false; + } + + return selection.start <= textPosition.offset + && selection.end >= textPosition.offset; + } + + /// Returns true if position was on selection. + bool _positionOnSelection(Offset position, TextSelection? targetSelection) { + if (targetSelection == null) { + return false; + } + + final TextPosition textPosition = renderEditable.getPositionForPoint(position); + + return targetSelection.start <= textPosition.offset + && targetSelection.end >= textPosition.offset; + } + + // Expand the selection to the given global position. + // + // Either base or extent will be moved to the last tapped position, whichever + // is closest. The selection will never shrink or pivot, only grow. + // + // If fromSelection is given, will expand from that selection instead of the + // current selection in renderEditable. + // + // See also: + // + // * [_extendSelection], which is similar but pivots the selection around + // the base. + void _expandSelection(Offset offset, SelectionChangedCause cause, [TextSelection? fromSelection]) { + assert(renderEditable.selection?.baseOffset != null); + + final TextPosition tappedPosition = renderEditable.getPositionForPoint(offset); + final TextSelection selection = fromSelection ?? renderEditable.selection!; + final bool baseIsCloser = + (tappedPosition.offset - selection.baseOffset).abs() + < (tappedPosition.offset - selection.extentOffset).abs(); + final TextSelection nextSelection = selection.copyWith( + baseOffset: baseIsCloser ? selection.extentOffset : selection.baseOffset, + extentOffset: tappedPosition.offset, + ); + + editableText.userUpdateTextEditingValue( + editableText.textEditingValue.copyWith( + selection: nextSelection, + ), + cause, + ); + } + + // Extend the selection to the given global position. + // + // Holds the base in place and moves the extent. + // + // See also: + // + // * [_expandSelection], which is similar but always increases the size of + // the selection. + void _extendSelection(Offset offset, SelectionChangedCause cause) { + assert(renderEditable.selection?.baseOffset != null); + + final TextPosition tappedPosition = renderEditable.getPositionForPoint(offset); + final TextSelection selection = renderEditable.selection!; + final TextSelection nextSelection = selection.copyWith( + extentOffset: tappedPosition.offset, + ); + + editableText.userUpdateTextEditingValue( + editableText.textEditingValue.copyWith( + selection: nextSelection, + ), + cause, + ); + } + + /// Whether to show the selection toolbar. + /// + /// It is based on the signal source when a [onTapDown] is called. This getter + /// will return true if current [onTapDown] event is triggered by a touch or + /// a stylus. + bool get shouldShowSelectionToolbar => _shouldShowSelectionToolbar; + bool _shouldShowSelectionToolbar = true; + + /// The [State] of the [EditableText] for which the builder will provide a + /// [TextSelectionGestureDetector]. + @protected + EditableTextState get editableText => delegate.editableTextKey.currentState!; + + /// The [RenderObject] of the [EditableText] for which the builder will + /// provide a [TextSelectionGestureDetector]. + @protected + RenderEditable get renderEditable => editableText.renderEditable; + + /// Whether the Shift key was pressed when the most recent [PointerDownEvent] + /// was tracked by the [BaseTapAndDragGestureRecognizer]. + bool _isShiftPressed = false; + + /// The viewport offset pixels of any [Scrollable] containing the + /// [RenderEditable] at the last drag start. + double _dragStartScrollOffset = 0.0; + + /// The viewport offset pixels of the [RenderEditable] at the last drag start. + double _dragStartViewportOffset = 0.0; + + double get _scrollPosition { + final ScrollableState? scrollableState = + delegate.editableTextKey.currentContext == null + ? null + : Scrollable.maybeOf(delegate.editableTextKey.currentContext!); + return scrollableState == null + ? 0.0 + : scrollableState.position.pixels; + } + + // For a shift + tap + drag gesture, the TextSelection at the point of the + // tap. Mac uses this value to reset to the original selection when an + // inversion of the base and offset happens. + TextSelection? _dragStartSelection; + + // For tap + drag gesture on iOS, whether the position where the drag started + // was on the previous TextSelection. iOS uses this value to determine if + // the cursor should move on drag update. + // + // If the drag started on the previous selection then the cursor will move on + // drag update. If the drag did not start on the previous selection then the + // cursor will not move on drag update. + bool? _dragBeganOnPreviousSelection; + + // For iOS long press behavior when the field is not focused. iOS uses this value + // to determine if a long press began on a field that was not focused. + // + // If the field was not focused when the long press began, a long press will select + // the word and a long press move will select word-by-word. If the field was + // focused, the cursor moves to the long press position. + bool _longPressStartedWithoutFocus = false; + + /// Handler for [TextSelectionGestureDetector.onTapTrackStart]. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onTapTrackStart], which triggers this + /// callback. + @protected + void onTapTrackStart() { + _isShiftPressed = HardwareKeyboard.instance.logicalKeysPressed + .intersection(<LogicalKeyboardKey>{LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftRight}) + .isNotEmpty; + } + + /// Handler for [TextSelectionGestureDetector.onTapTrackReset]. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onTapTrackReset], which triggers this + /// callback. + @protected + void onTapTrackReset() { + _isShiftPressed = false; + } + + /// Handler for [TextSelectionGestureDetector.onTapDown]. + /// + /// By default, it forwards the tap to [RenderEditable.handleTapDown] and sets + /// [shouldShowSelectionToolbar] to true if the tap was initiated by a finger or stylus. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onTapDown], which triggers this callback. + @protected + void onTapDown(TapDragDownDetails details) { + if (!delegate.selectionEnabled) { + return; + } + // TODO(Renzo-Olivares): Migrate text selection gestures away from saving state + // in renderEditable. The gesture callbacks can use the details objects directly + // in callbacks variants that provide them [TapGestureRecognizer.onSecondaryTap] + // vs [TapGestureRecognizer.onSecondaryTapUp] instead of having to track state in + // renderEditable. When this migration is complete we should remove this hack. + // See https://github.com/flutter/flutter/issues/115130. + renderEditable.handleTapDown(TapDownDetails(globalPosition: details.globalPosition)); + // The selection overlay should only be shown when the user is interacting + // through a touch screen (via either a finger or a stylus). A mouse shouldn't + // trigger the selection overlay. + // For backwards-compatibility, we treat a null kind the same as touch. + final PointerDeviceKind? kind = details.kind; + // TODO(justinmc): Should a desktop platform show its selection toolbar when + // receiving a tap event? Say a Windows device with a touchscreen. + // https://github.com/flutter/flutter/issues/106586 + _shouldShowSelectionToolbar = kind == null + || kind == PointerDeviceKind.touch + || kind == PointerDeviceKind.stylus; + + // It is impossible to extend the selection when the shift key is pressed, if the + // renderEditable.selection is invalid. + final bool isShiftPressedValid = _isShiftPressed && renderEditable.selection?.baseOffset != null; + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + // On mobile platforms the selection is set on tap up. + editableText.hideToolbar(false); + case TargetPlatform.iOS: + // On mobile platforms the selection is set on tap up. + break; + case TargetPlatform.macOS: + editableText.hideToolbar(); + // On macOS, a shift-tapped unfocused field expands from 0, not from the + // previous selection. + if (isShiftPressedValid) { + final TextSelection? fromSelection = renderEditable.hasFocus + ? null + : const TextSelection.collapsed(offset: 0); + _expandSelection( + details.globalPosition, + SelectionChangedCause.tap, + fromSelection, + ); + return; + } + // On macOS, a tap/click places the selection in a precise position. + // This differs from iOS/iPadOS, where if the gesture is done by a touch + // then the selection moves to the closest word edge, instead of a + // precise position. + renderEditable.selectPosition(cause: SelectionChangedCause.tap); + case TargetPlatform.linux: + case TargetPlatform.windows: + editableText.hideToolbar(); + if (isShiftPressedValid) { + _extendSelection(details.globalPosition, SelectionChangedCause.tap); + return; + } + renderEditable.selectPosition(cause: SelectionChangedCause.tap); + } + } + + /// Handler for [TextSelectionGestureDetector.onForcePressStart]. + /// + /// By default, it selects the word at the position of the force press, + /// if selection is enabled. + /// + /// This callback is only applicable when force press is enabled. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onForcePressStart], which triggers this + /// callback. + @protected + void onForcePressStart(ForcePressDetails details) { + assert(delegate.forcePressEnabled); + _shouldShowSelectionToolbar = true; + if (delegate.selectionEnabled) { + renderEditable.selectWordsInRange( + from: details.globalPosition, + cause: SelectionChangedCause.forcePress, + ); + } + } + + /// Handler for [TextSelectionGestureDetector.onForcePressEnd]. + /// + /// By default, it selects words in the range specified in [details] and shows + /// toolbar if it is necessary. + /// + /// This callback is only applicable when force press is enabled. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onForcePressEnd], which triggers this + /// callback. + @protected + void onForcePressEnd(ForcePressDetails details) { + assert(delegate.forcePressEnabled); + renderEditable.selectWordsInRange( + from: details.globalPosition, + cause: SelectionChangedCause.forcePress, + ); + if (shouldShowSelectionToolbar) { + editableText.showToolbar(); + } + } + + /// Whether the provided [onUserTap] callback should be dispatched on every + /// tap or only non-consecutive taps. + /// + /// Defaults to false. + @protected + bool get onUserTapAlwaysCalled => false; + + /// Handler for [TextSelectionGestureDetector.onUserTap]. + /// + /// By default, it serves as placeholder to enable subclass override. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onUserTap], which triggers this + /// callback. + /// * [TextSelectionGestureDetector.onUserTapAlwaysCalled], which controls + /// whether this callback is called only on the first tap in a series + /// of taps. + @protected + void onUserTap() { /* Subclass should override this method if needed. */ } + + /// Handler for [TextSelectionGestureDetector.onSingleTapUp]. + /// + /// By default, it selects word edge if selection is enabled. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onSingleTapUp], which triggers + /// this callback. + @protected + void onSingleTapUp(TapDragUpDetails details) { + if (delegate.selectionEnabled) { + // It is impossible to extend the selection when the shift key is pressed, if the + // renderEditable.selection is invalid. + final bool isShiftPressedValid = _isShiftPressed && renderEditable.selection?.baseOffset != null; + switch (defaultTargetPlatform) { + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + break; + // On desktop platforms the selection is set on tap down. + case TargetPlatform.android: + if (isShiftPressedValid) { + _extendSelection(details.globalPosition, SelectionChangedCause.tap); + return; + } + renderEditable.selectPosition(cause: SelectionChangedCause.tap); + editableText.showSpellCheckSuggestionsToolbar(); + case TargetPlatform.fuchsia: + if (isShiftPressedValid) { + _extendSelection(details.globalPosition, SelectionChangedCause.tap); + return; + } + renderEditable.selectPosition(cause: SelectionChangedCause.tap); + case TargetPlatform.iOS: + if (isShiftPressedValid) { + // On iOS, a shift-tapped unfocused field expands from 0, not from + // the previous selection. + final TextSelection? fromSelection = renderEditable.hasFocus + ? null + : const TextSelection.collapsed(offset: 0); + _expandSelection( + details.globalPosition, + SelectionChangedCause.tap, + fromSelection, + ); + return; + } + switch (details.kind) { + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + // TODO(camsim99): Determine spell check toolbar behavior in these cases: + // https://github.com/flutter/flutter/issues/119573. + // Precise devices should place the cursor at a precise position if the + // word at the text position is not misspelled. + renderEditable.selectPosition(cause: SelectionChangedCause.tap); + case PointerDeviceKind.touch: + case PointerDeviceKind.unknown: + // If the word that was tapped is misspelled, select the word and show the spell check suggestions + // toolbar once. If additional taps are made on a misspelled word, toggle the toolbar. If the word + // is not misspelled, default to the following behavior: + // + // Toggle the toolbar if the `previousSelection` is collapsed, the tap is on the selection, the + // TextAffinity remains the same, and the editable is focused. The TextAffinity is important when the + // cursor is on the boundary of a line wrap, if the affinity is different (i.e. it is downstream), the + // selection should move to the following line and not toggle the toolbar. + // + // Toggle the toolbar when the tap is exclusively within the bounds of a non-collapsed `previousSelection`, + // and the editable is focused. + // + // Selects the word edge closest to the tap when the editable is not focused, or if the tap was neither exclusively + // or inclusively on `previousSelection`. If the selection remains the same after selecting the word edge, then we + // toggle the toolbar. If the selection changes then we hide the toolbar. + final TextSelection previousSelection = renderEditable.selection ?? editableText.textEditingValue.selection; + final TextPosition textPosition = renderEditable.getPositionForPoint(details.globalPosition); + final bool isAffinityTheSame = textPosition.affinity == previousSelection.affinity; + final bool wordAtCursorIndexIsMisspelled = editableText.findSuggestionSpanAtCursorIndex(textPosition.offset) != null; + + if (wordAtCursorIndexIsMisspelled) { + renderEditable.selectWord(cause: SelectionChangedCause.tap); + if (previousSelection != editableText.textEditingValue.selection) { + editableText.showSpellCheckSuggestionsToolbar(); + } else { + editableText.toggleToolbar(false); + } + } else if (((_positionWasOnSelectionExclusive(textPosition) && !previousSelection.isCollapsed) || (_positionWasOnSelectionInclusive(textPosition) && previousSelection.isCollapsed && isAffinityTheSame)) && renderEditable.hasFocus) { + editableText.toggleToolbar(false); + } else { + renderEditable.selectWordEdge(cause: SelectionChangedCause.tap); + if (previousSelection == editableText.textEditingValue.selection && renderEditable.hasFocus) { + editableText.toggleToolbar(false); + } else { + editableText.hideToolbar(false); + } + } + } + } + } + } + + /// Handler for [TextSelectionGestureDetector.onSingleTapCancel]. + /// + /// By default, it serves as placeholder to enable subclass override. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onSingleTapCancel], which triggers + /// this callback. + @protected + void onSingleTapCancel() { /* Subclass should override this method if needed. */ } + + /// Handler for [TextSelectionGestureDetector.onSingleLongTapStart]. + /// + /// By default, it selects text position specified in [details] if selection + /// is enabled. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onSingleLongTapStart], which triggers + /// this callback. + @protected + void onSingleLongTapStart(LongPressStartDetails details) { + if (delegate.selectionEnabled) { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + if (!renderEditable.hasFocus) { + _longPressStartedWithoutFocus = true; + renderEditable.selectWord(cause: SelectionChangedCause.longPress); + } else { + renderEditable.selectPositionAt( + from: details.globalPosition, + cause: SelectionChangedCause.longPress, + ); + // Show the floating cursor. + final RawFloatingCursorPoint cursorPoint = RawFloatingCursorPoint( + state: FloatingCursorDragState.Start, + startLocation: ( + renderEditable.globalToLocal(details.globalPosition), + TextPosition( + offset: editableText.textEditingValue.selection.baseOffset, + affinity: editableText.textEditingValue.selection.affinity, + ), + ), + offset: Offset.zero, + ); + editableText.updateFloatingCursor(cursorPoint); + } + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + renderEditable.selectWord(cause: SelectionChangedCause.longPress); + } + + _showMagnifierIfSupportedByPlatform(details.globalPosition); + + _dragStartViewportOffset = renderEditable.offset.pixels; + _dragStartScrollOffset = _scrollPosition; + } + } + + /// Handler for [TextSelectionGestureDetector.onSingleLongTapMoveUpdate]. + /// + /// By default, it updates the selection location specified in [details] if + /// selection is enabled. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onSingleLongTapMoveUpdate], which + /// triggers this callback. + @protected + void onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) { + if (delegate.selectionEnabled) { + // Adjust the drag start offset for possible viewport offset changes. + final Offset editableOffset = renderEditable.maxLines == 1 + ? Offset(renderEditable.offset.pixels - _dragStartViewportOffset, 0.0) + : Offset(0.0, renderEditable.offset.pixels - _dragStartViewportOffset); + final Offset scrollableOffset = Offset( + 0.0, + _scrollPosition - _dragStartScrollOffset, + ); + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + if (_longPressStartedWithoutFocus) { + renderEditable.selectWordsInRange( + from: details.globalPosition - details.offsetFromOrigin - editableOffset - scrollableOffset, + to: details.globalPosition, + cause: SelectionChangedCause.longPress, + ); + } else { + renderEditable.selectPositionAt( + from: details.globalPosition, + cause: SelectionChangedCause.longPress, + ); + // Update the floating cursor. + final RawFloatingCursorPoint cursorPoint = RawFloatingCursorPoint( + state: FloatingCursorDragState.Update, + offset: details.offsetFromOrigin, + ); + editableText.updateFloatingCursor(cursorPoint); + } + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + renderEditable.selectWordsInRange( + from: details.globalPosition - details.offsetFromOrigin - editableOffset - scrollableOffset, + to: details.globalPosition, + cause: SelectionChangedCause.longPress, + ); + } + + _showMagnifierIfSupportedByPlatform(details.globalPosition); + } + } + + /// Handler for [TextSelectionGestureDetector.onSingleLongTapEnd]. + /// + /// By default, it shows toolbar if necessary. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onSingleLongTapEnd], which triggers this + /// callback. + @protected + void onSingleLongTapEnd(LongPressEndDetails details) { + _hideMagnifierIfSupportedByPlatform(); + if (shouldShowSelectionToolbar) { + editableText.showToolbar(); + } + _longPressStartedWithoutFocus = false; + _dragStartViewportOffset = 0.0; + _dragStartScrollOffset = 0.0; + if (defaultTargetPlatform == TargetPlatform.iOS && delegate.selectionEnabled && editableText.textEditingValue.selection.isCollapsed) { + // Update the floating cursor. + final RawFloatingCursorPoint cursorPoint = RawFloatingCursorPoint( + state: FloatingCursorDragState.End + ); + editableText.updateFloatingCursor(cursorPoint); + } + } + + /// Handler for [TextSelectionGestureDetector.onSecondaryTap]. + /// + /// By default, selects the word if possible and shows the toolbar. + @protected + void onSecondaryTap() { + if (!delegate.selectionEnabled) { + return; + } + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + if (!_lastSecondaryTapWasOnSelection || !renderEditable.hasFocus) { + renderEditable.selectWord(cause: SelectionChangedCause.tap); + } + if (shouldShowSelectionToolbar) { + editableText.hideToolbar(); + editableText.showToolbar(); + } + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + if (!renderEditable.hasFocus) { + renderEditable.selectPosition(cause: SelectionChangedCause.tap); + } + editableText.toggleToolbar(); + } + } + + /// Handler for [TextSelectionGestureDetector.onSecondaryTapDown]. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onSecondaryTapDown], which triggers this + /// callback. + /// * [onSecondaryTap], which is typically called after this. + @protected + void onSecondaryTapDown(TapDownDetails details) { + // TODO(Renzo-Olivares): Migrate text selection gestures away from saving state + // in renderEditable. The gesture callbacks can use the details objects directly + // in callbacks variants that provide them [TapGestureRecognizer.onSecondaryTap] + // vs [TapGestureRecognizer.onSecondaryTapUp] instead of having to track state in + // renderEditable. When this migration is complete we should remove this hack. + // See https://github.com/flutter/flutter/issues/115130. + renderEditable.handleSecondaryTapDown(TapDownDetails(globalPosition: details.globalPosition)); + _shouldShowSelectionToolbar = true; + } + + /// Handler for [TextSelectionGestureDetector.onDoubleTapDown]. + /// + /// By default, it selects a word through [RenderEditable.selectWord] if + /// selectionEnabled and shows toolbar if necessary. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onDoubleTapDown], which triggers this + /// callback. + @protected + void onDoubleTapDown(TapDragDownDetails details) { + if (delegate.selectionEnabled) { + renderEditable.selectWord(cause: SelectionChangedCause.doubleTap); + if (shouldShowSelectionToolbar) { + editableText.showToolbar(); + } + } + } + + // Selects the set of paragraphs in a document that intersect a given range of + // global positions. + void _selectParagraphsInRange({required Offset from, Offset? to, SelectionChangedCause? cause}) { + final TextBoundary paragraphBoundary = ParagraphBoundary(editableText.textEditingValue.text); + _selectTextBoundariesInRange(boundary: paragraphBoundary, from: from, to: to, cause: cause); + } + + // Selects the set of lines in a document that intersect a given range of + // global positions. + void _selectLinesInRange({required Offset from, Offset? to, SelectionChangedCause? cause}) { + final TextBoundary lineBoundary = LineBoundary(renderEditable); + _selectTextBoundariesInRange(boundary: lineBoundary, from: from, to: to, cause: cause); + } + + // Returns the location of a text boundary at `extent`. When `extent` is at + // the end of the text, returns the previous text boundary's location. + TextRange _moveToTextBoundary(TextPosition extent, TextBoundary textBoundary) { + assert(extent.offset >= 0); + // Use extent.offset - 1 when `extent` is at the end of the text to retrieve + // the previous text boundary's location. + final int start = textBoundary.getLeadingTextBoundaryAt(extent.offset == editableText.textEditingValue.text.length ? extent.offset - 1 : extent.offset) ?? 0; + final int end = textBoundary.getTrailingTextBoundaryAt(extent.offset) ?? editableText.textEditingValue.text.length; + return TextRange(start: start, end: end); + } + + // Selects the set of text boundaries in a document that intersect a given + // range of global positions. + // + // The set of text boundaries selected are not strictly bounded by the range + // of global positions. + // + // The first and last endpoints of the selection will always be at the + // beginning and end of a text boundary respectively. + void _selectTextBoundariesInRange({required TextBoundary boundary, required Offset from, Offset? to, SelectionChangedCause? cause}) { + final TextPosition fromPosition = renderEditable.getPositionForPoint(from); + final TextRange fromRange = _moveToTextBoundary(fromPosition, boundary); + final TextPosition toPosition = to == null + ? fromPosition + : renderEditable.getPositionForPoint(to); + final TextRange toRange = toPosition == fromPosition + ? fromRange + : _moveToTextBoundary(toPosition, boundary); + final bool isFromBoundaryBeforeToBoundary = fromRange.start < toRange.end; + + final TextSelection newSelection = isFromBoundaryBeforeToBoundary + ? TextSelection(baseOffset: fromRange.start, extentOffset: toRange.end) + : TextSelection(baseOffset: fromRange.end, extentOffset: toRange.start); + + editableText.userUpdateTextEditingValue( + editableText.textEditingValue.copyWith(selection: newSelection), + cause, + ); + } + + /// Handler for [TextSelectionGestureDetector.onTripleTapDown]. + /// + /// By default, it selects a paragraph if + /// [TextSelectionGestureDetectorBuilderDelegate.selectionEnabled] is true + /// and shows the toolbar if necessary. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onTripleTapDown], which triggers this + /// callback. + @protected + void onTripleTapDown(TapDragDownDetails details) { + if (!delegate.selectionEnabled) { + return; + } + if (renderEditable.maxLines == 1) { + editableText.selectAll(SelectionChangedCause.tap); + } else { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + case TargetPlatform.macOS: + case TargetPlatform.windows: + _selectParagraphsInRange(from: details.globalPosition, cause: SelectionChangedCause.tap); + case TargetPlatform.linux: + _selectLinesInRange(from: details.globalPosition, cause: SelectionChangedCause.tap); + } + } + if (shouldShowSelectionToolbar) { + editableText.showToolbar(); + } + } + + /// Handler for [TextSelectionGestureDetector.onDragSelectionStart]. + /// + /// By default, it selects a text position specified in [details]. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onDragSelectionStart], which triggers + /// this callback. + @protected + void onDragSelectionStart(TapDragStartDetails details) { + if (!delegate.selectionEnabled) { + return; + } + final PointerDeviceKind? kind = details.kind; + _shouldShowSelectionToolbar = kind == null + || kind == PointerDeviceKind.touch + || kind == PointerDeviceKind.stylus; + + _dragStartSelection = renderEditable.selection; + _dragStartScrollOffset = _scrollPosition; + _dragStartViewportOffset = renderEditable.offset.pixels; + _dragBeganOnPreviousSelection = _positionOnSelection(details.globalPosition, _dragStartSelection); + + if (_TextSelectionGestureDetectorState._getEffectiveConsecutiveTapCount(details.consecutiveTapCount) > 1) { + // Do not set the selection on a consecutive tap and drag. + return; + } + + if (_isShiftPressed && renderEditable.selection != null && renderEditable.selection!.isValid) { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + case TargetPlatform.macOS: + _expandSelection(details.globalPosition, SelectionChangedCause.drag); + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + _extendSelection(details.globalPosition, SelectionChangedCause.drag); + } + } else { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + switch (details.kind) { + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + renderEditable.selectPositionAt( + from: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.touch: + case PointerDeviceKind.unknown: + // For iOS platforms, a touch drag does not initiate unless the + // editable has focus and the drag began on the previous selection. + assert(_dragBeganOnPreviousSelection != null); + if (renderEditable.hasFocus && _dragBeganOnPreviousSelection!) { + renderEditable.selectPositionAt( + from: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + _showMagnifierIfSupportedByPlatform(details.globalPosition); + } + case null: + } + case TargetPlatform.android: + case TargetPlatform.fuchsia: + switch (details.kind) { + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + renderEditable.selectPositionAt( + from: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.touch: + case PointerDeviceKind.unknown: + // For Android, Fucshia, and iOS platforms, a touch drag + // does not initiate unless the editable has focus. + if (renderEditable.hasFocus) { + renderEditable.selectPositionAt( + from: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + _showMagnifierIfSupportedByPlatform(details.globalPosition); + } + case null: + } + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + renderEditable.selectPositionAt( + from: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + } + } + } + + /// Handler for [TextSelectionGestureDetector.onDragSelectionUpdate]. + /// + /// By default, it updates the selection location specified in the provided + /// details objects. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onDragSelectionUpdate], which triggers + /// this callback./lib/src/material/text_field.dart + @protected + void onDragSelectionUpdate(TapDragUpdateDetails details) { + if (!delegate.selectionEnabled) { + return; + } + + if (!_isShiftPressed) { + // Adjust the drag start offset for possible viewport offset changes. + final Offset editableOffset = renderEditable.maxLines == 1 + ? Offset(renderEditable.offset.pixels - _dragStartViewportOffset, 0.0) + : Offset(0.0, renderEditable.offset.pixels - _dragStartViewportOffset); + final Offset scrollableOffset = Offset( + 0.0, + _scrollPosition - _dragStartScrollOffset, + ); + final Offset dragStartGlobalPosition = details.globalPosition - details.offsetFromOrigin; + + // Select word by word. + if (_TextSelectionGestureDetectorState._getEffectiveConsecutiveTapCount(details.consecutiveTapCount) == 2) { + renderEditable.selectWordsInRange( + from: dragStartGlobalPosition - editableOffset - scrollableOffset, + to: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + + switch (details.kind) { + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.touch: + case PointerDeviceKind.unknown: + return _showMagnifierIfSupportedByPlatform(details.globalPosition); + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + case null: + return; + } + } + + // Select paragraph-by-paragraph. + if (_TextSelectionGestureDetectorState._getEffectiveConsecutiveTapCount(details.consecutiveTapCount) == 3) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + switch (details.kind) { + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + return _selectParagraphsInRange( + from: dragStartGlobalPosition - editableOffset - scrollableOffset, + to: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.touch: + case PointerDeviceKind.unknown: + case null: + // Triple tap to drag is not present on these platforms when using + // non-precise pointer devices at the moment. + break; + } + return; + case TargetPlatform.linux: + return _selectLinesInRange( + from: dragStartGlobalPosition - editableOffset - scrollableOffset, + to: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + case TargetPlatform.windows: + case TargetPlatform.macOS: + return _selectParagraphsInRange( + from: dragStartGlobalPosition - editableOffset - scrollableOffset, + to: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + } + } + + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + // With a touch device, nothing should happen, unless there was a double tap, or + // there was a collapsed selection, and the tap/drag position is at the collapsed selection. + // In that case the caret should move with the drag position. + // + // With a mouse device, a drag should select the range from the origin of the drag + // to the current position of the drag. + switch (details.kind) { + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + return renderEditable.selectPositionAt( + from: dragStartGlobalPosition - editableOffset - scrollableOffset, + to: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + case PointerDeviceKind.touch: + case PointerDeviceKind.unknown: + assert(_dragBeganOnPreviousSelection != null); + if (renderEditable.hasFocus + && _dragStartSelection!.isCollapsed + && _dragBeganOnPreviousSelection! + ) { + renderEditable.selectPositionAt( + from: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + return _showMagnifierIfSupportedByPlatform(details.globalPosition); + } + case null: + break; + } + return; + case TargetPlatform.android: + case TargetPlatform.fuchsia: + // With a precise pointer device, such as a mouse, trackpad, or stylus, + // the drag will select the text spanning the origin of the drag to the end of the drag. + // With a touch device, the cursor should move with the drag. + switch (details.kind) { + case PointerDeviceKind.mouse: + case PointerDeviceKind.trackpad: + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + return renderEditable.selectPositionAt( + from: dragStartGlobalPosition - editableOffset - scrollableOffset, + to: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + case PointerDeviceKind.touch: + case PointerDeviceKind.unknown: + if (renderEditable.hasFocus) { + renderEditable.selectPositionAt( + from: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + return _showMagnifierIfSupportedByPlatform(details.globalPosition); + } + case null: + break; + } + return; + case TargetPlatform.macOS: + case TargetPlatform.linux: + case TargetPlatform.windows: + return renderEditable.selectPositionAt( + from: dragStartGlobalPosition - editableOffset - scrollableOffset, + to: details.globalPosition, + cause: SelectionChangedCause.drag, + ); + } + } + + if (_dragStartSelection!.isCollapsed + || (defaultTargetPlatform != TargetPlatform.iOS + && defaultTargetPlatform != TargetPlatform.macOS)) { + return _extendSelection(details.globalPosition, SelectionChangedCause.drag); + } + + // If the drag inverts the selection, Mac and iOS revert to the initial + // selection. + final TextSelection selection = editableText.textEditingValue.selection; + final TextPosition nextExtent = renderEditable.getPositionForPoint(details.globalPosition); + final bool isShiftTapDragSelectionForward = + _dragStartSelection!.baseOffset < _dragStartSelection!.extentOffset; + final bool isInverted = isShiftTapDragSelectionForward + ? nextExtent.offset < _dragStartSelection!.baseOffset + : nextExtent.offset > _dragStartSelection!.baseOffset; + if (isInverted && selection.baseOffset == _dragStartSelection!.baseOffset) { + editableText.userUpdateTextEditingValue( + editableText.textEditingValue.copyWith( + selection: TextSelection( + baseOffset: _dragStartSelection!.extentOffset, + extentOffset: nextExtent.offset, + ), + ), + SelectionChangedCause.drag, + ); + } else if (!isInverted + && nextExtent.offset != _dragStartSelection!.baseOffset + && selection.baseOffset != _dragStartSelection!.baseOffset) { + editableText.userUpdateTextEditingValue( + editableText.textEditingValue.copyWith( + selection: TextSelection( + baseOffset: _dragStartSelection!.baseOffset, + extentOffset: nextExtent.offset, + ), + ), + SelectionChangedCause.drag, + ); + } else { + _extendSelection(details.globalPosition, SelectionChangedCause.drag); + } + } + + /// Handler for [TextSelectionGestureDetector.onDragSelectionEnd]. + /// + /// By default, it cleans up the state used for handling certain + /// built-in behaviors. + /// + /// See also: + /// + /// * [TextSelectionGestureDetector.onDragSelectionEnd], which triggers this + /// callback. + @protected + void onDragSelectionEnd(TapDragEndDetails details) { + _dragBeganOnPreviousSelection = null; + + if (_shouldShowSelectionToolbar && _TextSelectionGestureDetectorState._getEffectiveConsecutiveTapCount(details.consecutiveTapCount) == 2) { + editableText.showToolbar(); + } + + if (_isShiftPressed) { + _dragStartSelection = null; + } + + _hideMagnifierIfSupportedByPlatform(); + } + + /// Returns a [TextSelectionGestureDetector] configured with the handlers + /// provided by this builder. + /// + /// The [child] or its subtree should contain an [EditableText] whose key is + /// the [GlobalKey] provided by the [delegate]'s + /// [TextSelectionGestureDetectorBuilderDelegate.editableTextKey]. + Widget buildGestureDetector({ + Key? key, + HitTestBehavior? behavior, + required Widget child, + }) { + return TextSelectionGestureDetector( + key: key, + onTapTrackStart: onTapTrackStart, + onTapTrackReset: onTapTrackReset, + onTapDown: onTapDown, + onForcePressStart: delegate.forcePressEnabled ? onForcePressStart : null, + onForcePressEnd: delegate.forcePressEnabled ? onForcePressEnd : null, + onSecondaryTap: onSecondaryTap, + onSecondaryTapDown: onSecondaryTapDown, + onSingleTapUp: onSingleTapUp, + onSingleTapCancel: onSingleTapCancel, + onUserTap: onUserTap, + onSingleLongTapStart: onSingleLongTapStart, + onSingleLongTapMoveUpdate: onSingleLongTapMoveUpdate, + onSingleLongTapEnd: onSingleLongTapEnd, + onDoubleTapDown: onDoubleTapDown, + onTripleTapDown: onTripleTapDown, + onDragSelectionStart: onDragSelectionStart, + onDragSelectionUpdate: onDragSelectionUpdate, + onDragSelectionEnd: onDragSelectionEnd, + onUserTapAlwaysCalled: onUserTapAlwaysCalled, + behavior: behavior, + child: child, + ); + } +} + +/// A gesture detector to respond to non-exclusive event chains for a text field. +/// +/// An ordinary [GestureDetector] configured to handle events like tap and +/// double tap will only recognize one or the other. This widget detects both: +/// the first tap and then any subsequent taps that occurs within a time limit +/// after the first. +/// +/// See also: +/// +/// * [TextField], a Material text field which uses this gesture detector. +/// * [CupertinoTextField], a Cupertino text field which uses this gesture +/// detector. +class TextSelectionGestureDetector extends StatefulWidget { + /// Create a [TextSelectionGestureDetector]. + /// + /// Multiple callbacks can be called for one sequence of input gesture. + const TextSelectionGestureDetector({ + super.key, + this.onTapTrackStart, + this.onTapTrackReset, + this.onTapDown, + this.onForcePressStart, + this.onForcePressEnd, + this.onSecondaryTap, + this.onSecondaryTapDown, + this.onSingleTapUp, + this.onSingleTapCancel, + this.onUserTap, + this.onSingleLongTapStart, + this.onSingleLongTapMoveUpdate, + this.onSingleLongTapEnd, + this.onDoubleTapDown, + this.onTripleTapDown, + this.onDragSelectionStart, + this.onDragSelectionUpdate, + this.onDragSelectionEnd, + this.onUserTapAlwaysCalled = false, + this.behavior, + required this.child, + }); + + /// {@macro flutter.gestures.selectionrecognizers.BaseTapAndDragGestureRecognizer.onTapTrackStart} + final VoidCallback? onTapTrackStart; + + /// {@macro flutter.gestures.selectionrecognizers.BaseTapAndDragGestureRecognizer.onTapTrackReset} + final VoidCallback? onTapTrackReset; + + /// Called for every tap down including every tap down that's part of a + /// double click or a long press, except touches that include enough movement + /// to not qualify as taps (e.g. pans and flings). + final GestureTapDragDownCallback? onTapDown; + + /// Called when a pointer has tapped down and the force of the pointer has + /// just become greater than [ForcePressGestureRecognizer.startPressure]. + final GestureForcePressStartCallback? onForcePressStart; + + /// Called when a pointer that had previously triggered [onForcePressStart] is + /// lifted off the screen. + final GestureForcePressEndCallback? onForcePressEnd; + + /// Called for a tap event with the secondary mouse button. + final GestureTapCallback? onSecondaryTap; + + /// Called for a tap down event with the secondary mouse button. + final GestureTapDownCallback? onSecondaryTapDown; + + /// Called for the first tap in a series of taps, consecutive taps do not call + /// this method. + /// + /// For example, if the detector was configured with [onTapDown] and + /// [onDoubleTapDown], three quick taps would be recognized as a single tap + /// down, followed by a tap up, then a double tap down, followed by a single tap down. + final GestureTapDragUpCallback? onSingleTapUp; + + /// Called for each touch that becomes recognized as a gesture that is not a + /// short tap, such as a long tap or drag. It is called at the moment when + /// another gesture from the touch is recognized. + final GestureCancelCallback? onSingleTapCancel; + + /// Called for the first tap in a series of taps when [onUserTapAlwaysCalled] is + /// disabled, which is the default behavior. + /// + /// When [onUserTapAlwaysCalled] is enabled, this is called for every tap, + /// including consecutive taps. + final GestureTapCallback? onUserTap; + + /// Called for a single long tap that's sustained for longer than + /// [kLongPressTimeout] but not necessarily lifted. Not called for a + /// double-tap-hold, which calls [onDoubleTapDown] instead. + final GestureLongPressStartCallback? onSingleLongTapStart; + + /// Called after [onSingleLongTapStart] when the pointer is dragged. + final GestureLongPressMoveUpdateCallback? onSingleLongTapMoveUpdate; + + /// Called after [onSingleLongTapStart] when the pointer is lifted. + final GestureLongPressEndCallback? onSingleLongTapEnd; + + /// Called after a momentary hold or a short tap that is close in space and + /// time (within [kDoubleTapTimeout]) to a previous short tap. + final GestureTapDragDownCallback? onDoubleTapDown; + + /// Called after a momentary hold or a short tap that is close in space and + /// time (within [kDoubleTapTimeout]) to a previous double-tap. + final GestureTapDragDownCallback? onTripleTapDown; + + /// Called when a mouse starts dragging to select text. + final GestureTapDragStartCallback? onDragSelectionStart; + + /// Called repeatedly as a mouse moves while dragging. + final GestureTapDragUpdateCallback? onDragSelectionUpdate; + + /// Called when a mouse that was previously dragging is released. + final GestureTapDragEndCallback? onDragSelectionEnd; + + /// Whether [onUserTap] will be called for all taps including consecutive taps. + /// + /// Defaults to false, so [onUserTap] is only called for each distinct tap. + final bool onUserTapAlwaysCalled; + + /// How this gesture detector should behave during hit testing. + /// + /// This defaults to [HitTestBehavior.deferToChild]. + final HitTestBehavior? behavior; + + /// Child below this widget. + final Widget child; + + @override + State<StatefulWidget> createState() => _TextSelectionGestureDetectorState(); +} + +class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetector> { + + // Converts the details.consecutiveTapCount from a TapAndDrag*Details object, + // which can grow to be infinitely large, to a value between 1 and 3. The value + // that the raw count is converted to is based on the default observed behavior + // on the native platforms. + // + // This method should be used in all instances when details.consecutiveTapCount + // would be used. + static int _getEffectiveConsecutiveTapCount(int rawCount) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + // From observation, these platform's reset their tap count to 0 when + // the number of consecutive taps exceeds 3. For example on Debian Linux + // with GTK, when going past a triple click, on the fourth click the + // selection is moved to the precise click position, on the fifth click + // the word at the position is selected, and on the sixth click the + // paragraph at the position is selected. + return rawCount <= 3 ? rawCount : (rawCount % 3 == 0 ? 3 : rawCount % 3); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + // From observation, these platform's either hold their tap count at 3. + // For example on macOS, when going past a triple click, the selection + // should be retained at the paragraph that was first selected on triple + // click. + return math.min(rawCount, 3); + case TargetPlatform.windows: + // From observation, this platform's consecutive tap actions alternate + // between double click and triple click actions. For example, after a + // triple click has selected a paragraph, on the next click the word at + // the clicked position will be selected, and on the next click the + // paragraph at the position is selected. + return rawCount < 2 ? rawCount : 2 + rawCount % 2; + } + } + + void _handleTapTrackStart() { + widget.onTapTrackStart?.call(); + } + + void _handleTapTrackReset() { + widget.onTapTrackReset?.call(); + } + + // The down handler is force-run on success of a single tap and optimistically + // run before a long press success. + void _handleTapDown(TapDragDownDetails details) { + widget.onTapDown?.call(details); + // This isn't detected as a double tap gesture in the gesture recognizer + // because it's 2 single taps, each of which may do different things depending + // on whether it's a single tap, the first tap of a double tap, the second + // tap held down, a clean double tap etc. + if (_getEffectiveConsecutiveTapCount(details.consecutiveTapCount) == 2) { + return widget.onDoubleTapDown?.call(details); + } + + if (_getEffectiveConsecutiveTapCount(details.consecutiveTapCount) == 3) { + return widget.onTripleTapDown?.call(details); + } + } + + void _handleTapUp(TapDragUpDetails details) { + if (_getEffectiveConsecutiveTapCount(details.consecutiveTapCount) == 1) { + widget.onSingleTapUp?.call(details); + widget.onUserTap?.call(); + } else if (widget.onUserTapAlwaysCalled) { + widget.onUserTap?.call(); + } + } + + void _handleTapCancel() { + widget.onSingleTapCancel?.call(); + } + + void _handleDragStart(TapDragStartDetails details) { + widget.onDragSelectionStart?.call(details); + } + + void _handleDragUpdate(TapDragUpdateDetails details) { + widget.onDragSelectionUpdate?.call(details); + } + + void _handleDragEnd(TapDragEndDetails details) { + widget.onDragSelectionEnd?.call(details); + } + + void _forcePressStarted(ForcePressDetails details) { + widget.onForcePressStart?.call(details); + } + + void _forcePressEnded(ForcePressDetails details) { + widget.onForcePressEnd?.call(details); + } + + void _handleLongPressStart(LongPressStartDetails details) { + if (widget.onSingleLongTapStart != null) { + widget.onSingleLongTapStart!(details); + } + } + + void _handleLongPressMoveUpdate(LongPressMoveUpdateDetails details) { + if (widget.onSingleLongTapMoveUpdate != null) { + widget.onSingleLongTapMoveUpdate!(details); + } + } + + void _handleLongPressEnd(LongPressEndDetails details) { + if (widget.onSingleLongTapEnd != null) { + widget.onSingleLongTapEnd!(details); + } + } + + @override + Widget build(BuildContext context) { + final Map<Type, GestureRecognizerFactory> gestures = <Type, GestureRecognizerFactory>{}; + + gestures[TapGestureRecognizer] = GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>( + () => TapGestureRecognizer(debugOwner: this), + (TapGestureRecognizer instance) { + instance + ..onSecondaryTap = widget.onSecondaryTap + ..onSecondaryTapDown = widget.onSecondaryTapDown; + }, + ); + + if (widget.onSingleLongTapStart != null || + widget.onSingleLongTapMoveUpdate != null || + widget.onSingleLongTapEnd != null) { + gestures[LongPressGestureRecognizer] = GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>( + () => LongPressGestureRecognizer(debugOwner: this, supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch }), + (LongPressGestureRecognizer instance) { + instance + ..onLongPressStart = _handleLongPressStart + ..onLongPressMoveUpdate = _handleLongPressMoveUpdate + ..onLongPressEnd = _handleLongPressEnd; + }, + ); + } + + if (widget.onDragSelectionStart != null || + widget.onDragSelectionUpdate != null || + widget.onDragSelectionEnd != null) { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + gestures[TapAndHorizontalDragGestureRecognizer] = GestureRecognizerFactoryWithHandlers<TapAndHorizontalDragGestureRecognizer>( + () => TapAndHorizontalDragGestureRecognizer(debugOwner: this), + (TapAndHorizontalDragGestureRecognizer instance) { + instance + // Text selection should start from the position of the first pointer + // down event. + ..dragStartBehavior = DragStartBehavior.down + ..onTapTrackStart = _handleTapTrackStart + ..onTapTrackReset = _handleTapTrackReset + ..onTapDown = _handleTapDown + ..onDragStart = _handleDragStart + ..onDragUpdate = _handleDragUpdate + ..onDragEnd = _handleDragEnd + ..onTapUp = _handleTapUp + ..onCancel = _handleTapCancel; + }, + ); + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + gestures[TapAndPanGestureRecognizer] = GestureRecognizerFactoryWithHandlers<TapAndPanGestureRecognizer>( + () => TapAndPanGestureRecognizer(debugOwner: this), + (TapAndPanGestureRecognizer instance) { + instance + // Text selection should start from the position of the first pointer + // down event. + ..dragStartBehavior = DragStartBehavior.down + ..onTapTrackStart = _handleTapTrackStart + ..onTapTrackReset = _handleTapTrackReset + ..onTapDown = _handleTapDown + ..onDragStart = _handleDragStart + ..onDragUpdate = _handleDragUpdate + ..onDragEnd = _handleDragEnd + ..onTapUp = _handleTapUp + ..onCancel = _handleTapCancel; + }, + ); + } + } + + if (widget.onForcePressStart != null || widget.onForcePressEnd != null) { + gestures[ForcePressGestureRecognizer] = GestureRecognizerFactoryWithHandlers<ForcePressGestureRecognizer>( + () => ForcePressGestureRecognizer(debugOwner: this), + (ForcePressGestureRecognizer instance) { + instance + ..onStart = widget.onForcePressStart != null ? _forcePressStarted : null + ..onEnd = widget.onForcePressEnd != null ? _forcePressEnded : null; + }, + ); + } + + return RawGestureDetector( + gestures: gestures, + excludeFromSemantics: true, + behavior: widget.behavior, + child: widget.child, + ); + } +} + +/// A [ValueNotifier] whose [value] indicates whether the current contents of +/// the clipboard can be pasted. +/// +/// The contents of the clipboard can only be read asynchronously, via +/// [Clipboard.getData], so this maintains a value that can be used +/// synchronously. Call [update] to asynchronously update value if needed. +class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with WidgetsBindingObserver { + /// Create a new ClipboardStatusNotifier. + ClipboardStatusNotifier({ + ClipboardStatus value = ClipboardStatus.unknown, + }) : super(value); + + bool _disposed = false; + + /// Check the [Clipboard] and update [value] if needed. + Future<void> update() async { + if (_disposed) { + return; + } + + final bool hasStrings; + try { + hasStrings = await Clipboard.hasStrings(); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widget library', + context: ErrorDescription('while checking if the clipboard has strings'), + )); + // In the case of an error from the Clipboard API, set the value to + // unknown so that it will try to update again later. + if (_disposed) { + return; + } + value = ClipboardStatus.unknown; + return; + } + final ClipboardStatus nextStatus = hasStrings + ? ClipboardStatus.pasteable + : ClipboardStatus.notPasteable; + + if (_disposed) { + return; + } + value = nextStatus; + } + + @override + void addListener(VoidCallback listener) { + if (!hasListeners) { + WidgetsBinding.instance.addObserver(this); + } + if (value == ClipboardStatus.unknown) { + update(); + } + super.addListener(listener); + } + + @override + void removeListener(VoidCallback listener) { + super.removeListener(listener); + if (!_disposed && !hasListeners) { + WidgetsBinding.instance.removeObserver(this); + } + } + + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + switch (state) { + case AppLifecycleState.resumed: + update(); + case AppLifecycleState.detached: + case AppLifecycleState.inactive: + case AppLifecycleState.hidden: + case AppLifecycleState.paused: + // Nothing to do. + break; + } + } + + @override + void dispose() { + WidgetsBinding.instance.removeObserver(this); + _disposed = true; + super.dispose(); + } +} + +/// An enumeration of the status of the content on the user's clipboard. +enum ClipboardStatus { + /// The clipboard content can be pasted, such as a String of nonzero length. + pasteable, + + /// The status of the clipboard is unknown. Since getting clipboard data is + /// asynchronous (see [Clipboard.getData]), this status often exists while + /// waiting to receive the clipboard contents for the first time. + unknown, + + /// The content on the clipboard is not pasteable, such as when it is empty. + notPasteable, +} + +/// A [ValueNotifier] whose [value] indicates whether the current device supports the Live Text +/// (OCR) function. +/// +/// See also: +/// * [LiveText], where the availability of Live Text input can be obtained. +/// * [LiveTextInputStatus], an enumeration that indicates whether the current device is available +/// for Live Text input. +/// +/// Call [update] to asynchronously update [value] if needed. +class LiveTextInputStatusNotifier extends ValueNotifier<LiveTextInputStatus> with WidgetsBindingObserver { + /// Create a new LiveTextStatusNotifier. + LiveTextInputStatusNotifier({ + LiveTextInputStatus value = LiveTextInputStatus.unknown, + }) : super(value); + + bool _disposed = false; + + /// Check the [LiveTextInputStatus] and update [value] if needed. + Future<void> update() async { + if (_disposed) { + return; + } + + final bool isLiveTextInputEnabled; + try { + isLiveTextInputEnabled = await LiveText.isLiveTextInputAvailable(); + } catch (exception, stack) { + FlutterError.reportError(FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widget library', + context: ErrorDescription('while checking the availability of Live Text input'), + )); + // In the case of an error from the Live Text API, set the value to + // unknown so that it will try to update again later. + if (_disposed || value == LiveTextInputStatus.unknown) { + return; + } + value = LiveTextInputStatus.unknown; + return; + } + + final LiveTextInputStatus nextStatus = isLiveTextInputEnabled + ? LiveTextInputStatus.enabled + : LiveTextInputStatus.disabled; + + if (_disposed || nextStatus == value) { + return; + } + value = nextStatus; + } + + @override + void addListener(VoidCallback listener) { + if (!hasListeners) { + WidgetsBinding.instance.addObserver(this); + } + if (value == LiveTextInputStatus.unknown) { + update(); + } + super.addListener(listener); + } + + @override + void removeListener(VoidCallback listener) { + super.removeListener(listener); + if (!_disposed && !hasListeners) { + WidgetsBinding.instance.removeObserver(this); + } + } + + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + switch (state) { + case AppLifecycleState.resumed: + update(); + case AppLifecycleState.detached: + case AppLifecycleState.inactive: + case AppLifecycleState.paused: + case AppLifecycleState.hidden: + // Nothing to do. + } + } + + @override + void dispose() { + WidgetsBinding.instance.removeObserver(this); + _disposed = true; + super.dispose(); + } +} + +/// An enumeration that indicates whether the current device is available for Live Text input. +/// +/// See also: +/// * [LiveText], where the availability of Live Text input can be obtained. +enum LiveTextInputStatus { + /// This device supports Live Text input currently. + enabled, + + /// The status of the Live Text input is unknown. Since getting the Live Text input availability + /// is asynchronous (see [LiveText.isLiveTextInputAvailable]), this status often exists while + /// waiting to receive the status value for the first time. + unknown, + + /// The current device doesn't support Live Text input. + disabled, +} + +// TODO(justinmc): Deprecate this after TextSelectionControls.buildToolbar is +// deleted, when users should migrate back to TextSelectionControls.buildHandle. +// See https://github.com/flutter/flutter/pull/124262 +/// [TextSelectionControls] that specifically do not manage the toolbar in order +/// to leave that to [EditableText.contextMenuBuilder]. +mixin TextSelectionHandleControls on TextSelectionControls { + @override + Widget buildToolbar( + BuildContext context, + Rect globalEditableRegion, + double textLineHeight, + Offset selectionMidpoint, + List<TextSelectionPoint> endpoints, + TextSelectionDelegate delegate, + ValueListenable<ClipboardStatus>? clipboardStatus, + Offset? lastSecondaryTapDownPosition, + ) => const SizedBox.shrink(); + + @override + bool canCut(TextSelectionDelegate delegate) => false; + + @override + bool canCopy(TextSelectionDelegate delegate) => false; + + @override + bool canPaste(TextSelectionDelegate delegate) => false; + + @override + bool canSelectAll(TextSelectionDelegate delegate) => false; + + @override + void handleCut(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) {} + + @override + void handleCopy(TextSelectionDelegate delegate, [ClipboardStatusNotifier? clipboardStatus]) {} + + @override + Future<void> handlePaste(TextSelectionDelegate delegate) async {} + + @override + void handleSelectAll(TextSelectionDelegate delegate) {} +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_selection_toolbar_anchors.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_selection_toolbar_anchors.dart new file mode 100644 index 0000000000000000000000000000000000000000..616a13aea1a5e3e9e69dc2de95b041f734edeae5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_selection_toolbar_anchors.dart @@ -0,0 +1,77 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +/// The position information for a text selection toolbar. +/// +/// Typically, a menu will attempt to position itself at [primaryAnchor], and +/// if that's not possible, then it will use [secondaryAnchor] instead, if it +/// exists. +/// +/// See also: +/// +/// * [AdaptiveTextSelectionToolbar.anchors], which is of this type. +@immutable +class TextSelectionToolbarAnchors { + /// Creates an instance of [TextSelectionToolbarAnchors] directly from the + /// anchor points. + const TextSelectionToolbarAnchors({ + required this.primaryAnchor, + this.secondaryAnchor, + }); + + /// Creates an instance of [TextSelectionToolbarAnchors] for some selection. + factory TextSelectionToolbarAnchors.fromSelection({ + required RenderBox renderBox, + required double startGlyphHeight, + required double endGlyphHeight, + required List<TextSelectionPoint> selectionEndpoints, + }) { + final Rect editingRegion = Rect.fromPoints( + renderBox.localToGlobal(Offset.zero), + renderBox.localToGlobal(renderBox.size.bottomRight(Offset.zero)), + ); + + if (editingRegion.left.isNaN || editingRegion.top.isNaN + || editingRegion.right.isNaN || editingRegion.bottom.isNaN) { + return const TextSelectionToolbarAnchors(primaryAnchor: Offset.zero); + } + + final bool isMultiline = selectionEndpoints.last.point.dy - selectionEndpoints.first.point.dy > + endGlyphHeight / 2; + + final Rect selectionRect = Rect.fromLTRB( + isMultiline + ? editingRegion.left + : editingRegion.left + selectionEndpoints.first.point.dx, + editingRegion.top + selectionEndpoints.first.point.dy - startGlyphHeight, + isMultiline + ? editingRegion.right + : editingRegion.left + selectionEndpoints.last.point.dx, + editingRegion.top + selectionEndpoints.last.point.dy, + ); + + return TextSelectionToolbarAnchors( + primaryAnchor: Offset( + selectionRect.left + selectionRect.width / 2, + clampDouble(selectionRect.top, editingRegion.top, editingRegion.bottom), + ), + secondaryAnchor: Offset( + selectionRect.left + selectionRect.width / 2, + clampDouble(selectionRect.bottom, editingRegion.top, editingRegion.bottom), + ), + ); + } + + /// The location that the toolbar should attempt to position itself at. + /// + /// If the toolbar doesn't fit at this location, use [secondaryAnchor] if it + /// exists. + final Offset primaryAnchor; + + /// The fallback position that should be used if [primaryAnchor] doesn't work. + final Offset? secondaryAnchor; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_selection_toolbar_layout_delegate.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_selection_toolbar_layout_delegate.dart new file mode 100644 index 0000000000000000000000000000000000000000..5b00babdf953f1ca0411bc8f648b32c8ad107ef7 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/text_selection_toolbar_layout_delegate.dart @@ -0,0 +1,89 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/rendering.dart'; + +/// Positions the toolbar above [anchorAbove] if it fits, or otherwise below +/// [anchorBelow]. +/// +/// See also: +/// +/// * [TextSelectionToolbar], which uses this to position itself. +/// * [CupertinoTextSelectionToolbar], which also uses this to position +/// itself. +class TextSelectionToolbarLayoutDelegate extends SingleChildLayoutDelegate { + /// Creates an instance of TextSelectionToolbarLayoutDelegate. + TextSelectionToolbarLayoutDelegate({ + required this.anchorAbove, + required this.anchorBelow, + this.fitsAbove, + }); + + /// {@macro flutter.material.TextSelectionToolbar.anchorAbove} + /// + /// Should be provided in local coordinates. + final Offset anchorAbove; + + /// {@macro flutter.material.TextSelectionToolbar.anchorAbove} + /// + /// Should be provided in local coordinates. + final Offset anchorBelow; + + /// Whether or not the child should be considered to fit above anchorAbove. + /// + /// Typically used to force the child to be drawn at anchorAbove even when it + /// doesn't fit, such as when the Material [TextSelectionToolbar] draws an + /// open overflow menu. + /// + /// If not provided, it will be calculated. + final bool? fitsAbove; + + /// Return the value that centers width as closely as possible to position + /// while fitting inside of min and max. + static double centerOn(double position, double width, double max) { + // If it overflows on the left, put it as far left as possible. + if (position - width / 2.0 < 0.0) { + return 0.0; + } + + // If it overflows on the right, put it as far right as possible. + if (position + width / 2.0 > max) { + return max - width; + } + + // Otherwise it fits while perfectly centered. + return position - width / 2.0; + } + + @override + BoxConstraints getConstraintsForChild(BoxConstraints constraints) { + return constraints.loosen(); + } + + @override + Offset getPositionForChild(Size size, Size childSize) { + final bool fitsAbove = this.fitsAbove ?? anchorAbove.dy >= childSize.height; + final Offset anchor = fitsAbove ? anchorAbove : anchorBelow; + + return Offset( + centerOn( + anchor.dx, + childSize.width, + size.width, + ), + fitsAbove + ? math.max(0.0, anchor.dy - childSize.height) + : anchor.dy, + ); + } + + @override + bool shouldRelayout(TextSelectionToolbarLayoutDelegate oldDelegate) { + return anchorAbove != oldDelegate.anchorAbove + || anchorBelow != oldDelegate.anchorBelow + || fitsAbove != oldDelegate.fitsAbove; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/texture.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/texture.dart new file mode 100644 index 0000000000000000000000000000000000000000..4f506b46e1a89a0469320e2d61fced4fb96fc0c6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/texture.dart @@ -0,0 +1,70 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'framework.dart'; + +/// A rectangle upon which a backend texture is mapped. +/// +/// Backend textures are images that can be applied (mapped) to an area of the +/// Flutter view. They are created, managed, and updated using a +/// platform-specific texture registry. This is typically done by a plugin +/// that integrates with host platform video player, camera, or OpenGL APIs, +/// or similar image sources. +/// +/// A texture widget refers to its backend texture using an integer ID. Texture +/// IDs are obtained from the texture registry and are scoped to the Flutter +/// view. Texture IDs may be reused after deregistration, at the discretion +/// of the registry. The use of texture IDs currently unknown to the registry +/// will silently result in a blank rectangle. +/// +/// Texture widgets are repainted autonomously as dictated by the backend (e.g. +/// on arrival of a video frame). Such repainting generally does not involve +/// executing Dart code. +/// +/// The size of the rectangle is determined by its parent widget, and the +/// texture is automatically scaled to fit. +/// +/// See also: +/// +/// * [TextureRegistry](/javadoc/io/flutter/view/TextureRegistry.html) +/// for how to create and manage backend textures on Android. +/// * [TextureRegistry Protocol](/ios-embedder/protocol_flutter_texture_registry-p.html) +/// for how to create and manage backend textures on iOS. +class Texture extends LeafRenderObjectWidget { + /// Creates a widget backed by the texture identified by [textureId], and use + /// [filterQuality] to set texture's [FilterQuality]. + const Texture({ + super.key, + required this.textureId, + this.freeze = false, + this.filterQuality = FilterQuality.low, + }); + + /// The identity of the backend texture. + final int textureId; + + /// When true the texture will not be updated with new frames. + final bool freeze; + + /// {@template flutter.widgets.Texture.filterQuality} + /// The quality of sampling the texture and rendering it on screen. + /// + /// When the texture is scaled, a default [FilterQuality.low] is used for a higher quality but slower + /// interpolation (typically bilinear). It can be changed to [FilterQuality.none] for a lower quality but + /// faster interpolation (typically nearest-neighbor). See also [FilterQuality.medium] and + /// [FilterQuality.high] for more options. + /// {@endtemplate} + final FilterQuality filterQuality; + + @override + TextureBox createRenderObject(BuildContext context) => TextureBox(textureId: textureId, freeze: freeze, filterQuality: filterQuality); + + @override + void updateRenderObject(BuildContext context, TextureBox renderObject) { + renderObject.textureId = textureId; + renderObject.freeze = freeze; + renderObject.filterQuality = filterQuality; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/ticker_provider.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/ticker_provider.dart new file mode 100644 index 0000000000000000000000000000000000000000..270e7b66a7ec8a9c45b1db55a7558fe71c79e8ca --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/ticker_provider.dart @@ -0,0 +1,414 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; + +import 'framework.dart'; + +export 'package:flutter/scheduler.dart' show TickerProvider; + +// Examples can assume: +// late BuildContext context; + +/// Enables or disables tickers (and thus animation controllers) in the widget +/// subtree. +/// +/// This only works if [AnimationController] objects are created using +/// widget-aware ticker providers. For example, using a +/// [TickerProviderStateMixin] or a [SingleTickerProviderStateMixin]. +class TickerMode extends StatefulWidget { + /// Creates a widget that enables or disables tickers. + const TickerMode({ + super.key, + required this.enabled, + required this.child, + }); + + /// The requested ticker mode for this subtree. + /// + /// The effective ticker mode of this subtree may differ from this value + /// if there is an ancestor [TickerMode] with this field set to false. + /// + /// If true and all ancestor [TickerMode]s are also enabled, then tickers in + /// this subtree will tick. + /// + /// If false, then tickers in this subtree will not tick regardless of any + /// ancestor [TickerMode]s. Animations driven by such tickers are not paused, + /// they just don't call their callbacks. Time still elapses. + final bool enabled; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// Whether tickers in the given subtree should be enabled or disabled. + /// + /// This is used automatically by [TickerProviderStateMixin] and + /// [SingleTickerProviderStateMixin] to decide if their tickers should be + /// enabled or disabled. + /// + /// In the absence of a [TickerMode] widget, this function defaults to true. + /// + /// Typical usage is as follows: + /// + /// ```dart + /// bool tickingEnabled = TickerMode.of(context); + /// ``` + static bool of(BuildContext context) { + final _EffectiveTickerMode? widget = context.dependOnInheritedWidgetOfExactType<_EffectiveTickerMode>(); + return widget?.enabled ?? true; + } + + /// Obtains a [ValueListenable] from the [TickerMode] surrounding the `context`, + /// which indicates whether tickers are enabled in the given subtree. + /// + /// When that [TickerMode] enabled or disabled tickers, the listenable notifies + /// its listeners. + /// + /// While the [ValueListenable] is stable for the lifetime of the surrounding + /// [TickerMode], calling this method does not establish a dependency between + /// the `context` and the [TickerMode] and the widget owning the `context` + /// does not rebuild when the ticker mode changes from true to false or vice + /// versa. This is preferable when the ticker mode does not impact what is + /// currently rendered on screen, e.g. because it is only used to mute/unmute a + /// [Ticker]. Since no dependency is established, the widget owning the + /// `context` is also not informed when it is moved to a new location in the + /// tree where it may have a different [TickerMode] ancestor. When this + /// happens, the widget must manually unsubscribe from the old listenable, + /// obtain a new one from the new ancestor [TickerMode] by calling this method + /// again, and re-subscribe to it. [StatefulWidget]s can, for example, do this + /// in [State.activate], which is called after the widget has been moved to + /// a new location. + /// + /// Alternatively, [of] can be used instead of this method to create a + /// dependency between the provided `context` and the ancestor [TickerMode]. + /// In this case, the widget automatically rebuilds when the ticker mode + /// changes or when it is moved to a new [TickerMode] ancestor, which + /// simplifies the management cost in the widget at the expensive of some + /// potential unnecessary rebuilds. + /// + /// In the absence of a [TickerMode] widget, this function returns a + /// [ValueListenable], whose [ValueListenable.value] is always true. + static ValueListenable<bool> getNotifier(BuildContext context) { + final _EffectiveTickerMode? widget = context.getInheritedWidgetOfExactType<_EffectiveTickerMode>(); + return widget?.notifier ?? const _ConstantValueListenable<bool>(true); + } + + @override + State<TickerMode> createState() => _TickerModeState(); +} + +class _TickerModeState extends State<TickerMode> { + bool _ancestorTicketMode = true; + final ValueNotifier<bool> _effectiveMode = ValueNotifier<bool>(true); + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _ancestorTicketMode = TickerMode.of(context); + _updateEffectiveMode(); + } + + @override + void didUpdateWidget(TickerMode oldWidget) { + super.didUpdateWidget(oldWidget); + _updateEffectiveMode(); + } + + @override + void dispose() { + _effectiveMode.dispose(); + super.dispose(); + } + + void _updateEffectiveMode() { + _effectiveMode.value = _ancestorTicketMode && widget.enabled; + } + + @override + Widget build(BuildContext context) { + return _EffectiveTickerMode( + enabled: _effectiveMode.value, + notifier: _effectiveMode, + child: widget.child, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('requested mode', value: widget.enabled, ifTrue: 'enabled', ifFalse: 'disabled', showName: true)); + } +} + +class _EffectiveTickerMode extends InheritedWidget { + const _EffectiveTickerMode({ + required this.enabled, + required this.notifier, + required super.child, + }); + + final bool enabled; + final ValueNotifier<bool> notifier; + + @override + bool updateShouldNotify(_EffectiveTickerMode oldWidget) => enabled != oldWidget.enabled; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('effective mode', value: enabled, ifTrue: 'enabled', ifFalse: 'disabled', showName: true)); + } +} + +/// Provides a single [Ticker] that is configured to only tick while the current +/// tree is enabled, as defined by [TickerMode]. +/// +/// To create the [AnimationController] in a [State] that only uses a single +/// [AnimationController], mix in this class, then pass `vsync: this` +/// to the animation controller constructor. +/// +/// This mixin only supports vending a single ticker. If you might have multiple +/// [AnimationController] objects over the lifetime of the [State], use a full +/// [TickerProviderStateMixin] instead. +@optionalTypeArgs +mixin SingleTickerProviderStateMixin<T extends StatefulWidget> on State<T> implements TickerProvider { + Ticker? _ticker; + + @override + Ticker createTicker(TickerCallback onTick) { + assert(() { + if (_ticker == null) { + return true; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$runtimeType is a SingleTickerProviderStateMixin but multiple tickers were created.'), + ErrorDescription('A SingleTickerProviderStateMixin can only be used as a TickerProvider once.'), + ErrorHint( + 'If a State is used for multiple AnimationController objects, or if it is passed to other ' + 'objects and those objects might use it more than one time in total, then instead of ' + 'mixing in a SingleTickerProviderStateMixin, use a regular TickerProviderStateMixin.', + ), + ]); + }()); + _ticker = Ticker(onTick, debugLabel: kDebugMode ? 'created by ${describeIdentity(this)}' : null); + _updateTickerModeNotifier(); + _updateTicker(); // Sets _ticker.mute correctly. + return _ticker!; + } + + @override + void dispose() { + assert(() { + if (_ticker == null || !_ticker!.isActive) { + return true; + } + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$this was disposed with an active Ticker.'), + ErrorDescription( + '$runtimeType created a Ticker via its SingleTickerProviderStateMixin, but at the time ' + 'dispose() was called on the mixin, that Ticker was still active. The Ticker must ' + 'be disposed before calling super.dispose().', + ), + ErrorHint( + 'Tickers used by AnimationControllers ' + 'should be disposed by calling dispose() on the AnimationController itself. ' + 'Otherwise, the ticker will leak.', + ), + _ticker!.describeForError('The offending ticker was'), + ]); + }()); + _tickerModeNotifier?.removeListener(_updateTicker); + _tickerModeNotifier = null; + super.dispose(); + } + + ValueListenable<bool>? _tickerModeNotifier; + + @override + void activate() { + super.activate(); + // We may have a new TickerMode ancestor. + _updateTickerModeNotifier(); + _updateTicker(); + } + + void _updateTicker() { + if (_ticker != null) { + _ticker!.muted = !_tickerModeNotifier!.value; + } + } + + void _updateTickerModeNotifier() { + final ValueListenable<bool> newNotifier = TickerMode.getNotifier(context); + if (newNotifier == _tickerModeNotifier) { + return; + } + _tickerModeNotifier?.removeListener(_updateTicker); + newNotifier.addListener(_updateTicker); + _tickerModeNotifier = newNotifier; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + String? tickerDescription; + if (_ticker != null) { + if (_ticker!.isActive && _ticker!.muted) { + tickerDescription = 'active but muted'; + } else if (_ticker!.isActive) { + tickerDescription = 'active'; + } else if (_ticker!.muted) { + tickerDescription = 'inactive and muted'; + } else { + tickerDescription = 'inactive'; + } + } + properties.add(DiagnosticsProperty<Ticker>('ticker', _ticker, description: tickerDescription, showSeparator: false, defaultValue: null)); + } +} + +/// Provides [Ticker] objects that are configured to only tick while the current +/// tree is enabled, as defined by [TickerMode]. +/// +/// To create an [AnimationController] in a class that uses this mixin, pass +/// `vsync: this` to the animation controller constructor whenever you +/// create a new animation controller. +/// +/// If you only have a single [Ticker] (for example only a single +/// [AnimationController]) for the lifetime of your [State], then using a +/// [SingleTickerProviderStateMixin] is more efficient. This is the common case. +@optionalTypeArgs +mixin TickerProviderStateMixin<T extends StatefulWidget> on State<T> implements TickerProvider { + Set<Ticker>? _tickers; + + @override + Ticker createTicker(TickerCallback onTick) { + if (_tickerModeNotifier == null) { + // Setup TickerMode notifier before we vend the first ticker. + _updateTickerModeNotifier(); + } + assert(_tickerModeNotifier != null); + _tickers ??= <_WidgetTicker>{}; + final _WidgetTicker result = _WidgetTicker(onTick, this, debugLabel: kDebugMode ? 'created by ${describeIdentity(this)}' : null) + ..muted = !_tickerModeNotifier!.value; + _tickers!.add(result); + return result; + } + + void _removeTicker(_WidgetTicker ticker) { + assert(_tickers != null); + assert(_tickers!.contains(ticker)); + _tickers!.remove(ticker); + } + + ValueListenable<bool>? _tickerModeNotifier; + + @override + void activate() { + super.activate(); + // We may have a new TickerMode ancestor, get its Notifier. + _updateTickerModeNotifier(); + _updateTickers(); + } + + void _updateTickers() { + if (_tickers != null) { + final bool muted = !_tickerModeNotifier!.value; + for (final Ticker ticker in _tickers!) { + ticker.muted = muted; + } + } + } + + void _updateTickerModeNotifier() { + final ValueListenable<bool> newNotifier = TickerMode.getNotifier(context); + if (newNotifier == _tickerModeNotifier) { + return; + } + _tickerModeNotifier?.removeListener(_updateTickers); + newNotifier.addListener(_updateTickers); + _tickerModeNotifier = newNotifier; + } + + @override + void dispose() { + assert(() { + if (_tickers != null) { + for (final Ticker ticker in _tickers!) { + if (ticker.isActive) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$this was disposed with an active Ticker.'), + ErrorDescription( + '$runtimeType created a Ticker via its TickerProviderStateMixin, but at the time ' + 'dispose() was called on the mixin, that Ticker was still active. All Tickers must ' + 'be disposed before calling super.dispose().', + ), + ErrorHint( + 'Tickers used by AnimationControllers ' + 'should be disposed by calling dispose() on the AnimationController itself. ' + 'Otherwise, the ticker will leak.', + ), + ticker.describeForError('The offending ticker was'), + ]); + } + } + } + return true; + }()); + _tickerModeNotifier?.removeListener(_updateTickers); + _tickerModeNotifier = null; + super.dispose(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Set<Ticker>>( + 'tickers', + _tickers, + description: _tickers != null ? + 'tracking ${_tickers!.length} ticker${_tickers!.length == 1 ? "" : "s"}' : + null, + defaultValue: null, + )); + } +} + +// This class should really be called _DisposingTicker or some such, but this +// class name leaks into stack traces and error messages and that name would be +// confusing. Instead we use the less precise but more anodyne "_WidgetTicker", +// which attracts less attention. +class _WidgetTicker extends Ticker { + _WidgetTicker(super.onTick, this._creator, { super.debugLabel }); + + final TickerProviderStateMixin _creator; + + @override + void dispose() { + _creator._removeTicker(this); + super.dispose(); + } +} + +class _ConstantValueListenable<T> implements ValueListenable<T> { + const _ConstantValueListenable(this.value); + + @override + void addListener(VoidCallback listener) { + // Intentionally left empty: Value cannot change, so we never have to + // notify registered listeners. + } + + @override + void removeListener(VoidCallback listener) { + // Intentionally left empty: Value cannot change, so we never have to + // notify registered listeners. + } + + @override + final T value; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/title.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/title.dart new file mode 100644 index 0000000000000000000000000000000000000000..ad20e4db54a35e7a24ffbc86d111c3b090614dcb --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/title.dart @@ -0,0 +1,55 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'basic.dart'; +import 'framework.dart'; + +/// A widget that describes this app in the operating system. +class Title extends StatelessWidget { + /// Creates a widget that describes this app to the Android operating system. + /// + /// [title] will default to the empty string if not supplied. + /// [color] must be an opaque color (i.e. color.alpha must be 255 (0xFF)). + /// [color] and [child] are required arguments. + Title({ + super.key, + this.title = '', + required this.color, + required this.child, + }) : assert(color.alpha == 0xFF); + + /// A one-line description of this app for use in the window manager. + final String title; + + /// A color that the window manager should use to identify this app. Must be + /// an opaque color (i.e. color.alpha must be 255 (0xFF)), and must not be + /// null. + final Color color; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + SystemChrome.setApplicationSwitcherDescription( + ApplicationSwitcherDescription( + label: title, + primaryColor: color.value, + ), + ); + return child; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(StringProperty('title', title, defaultValue: '')); + properties.add(ColorProperty('color', color, defaultValue: null)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/toggleable.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/toggleable.dart new file mode 100644 index 0000000000000000000000000000000000000000..45aabf961e6b09a149a7262be4888b9028314dfa --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/toggleable.dart @@ -0,0 +1,630 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'actions.dart'; +import 'basic.dart'; +import 'focus_manager.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'ticker_provider.dart'; +import 'widget_state.dart'; + +// Duration of the animation that moves the toggle from one state to another. +const Duration _kToggleDuration = Duration(milliseconds: 200); + +// Duration of the fade animation for the reaction when focus and hover occur. +const Duration _kReactionFadeDuration = Duration(milliseconds: 50); + +/// A mixin for [StatefulWidget]s that implement toggleable +/// controls with toggle animations (e.g. [Switch]es, [CupertinoSwitch]es, +/// [Checkbox]es, [CupertinoCheckbox]es, [Radio]s, and [CupertinoRadio]s). +/// +/// The mixin implements the logic for toggling the control (e.g. when tapped) +/// and provides a series of animation controllers to transition the control +/// from one state to another. It does not have any opinion about the visual +/// representation of the toggleable widget. The visuals are defined by a +/// [CustomPainter] passed to the [buildToggleable]. [State] objects using this +/// mixin should call that method from their [build] method. +@optionalTypeArgs +mixin ToggleableStateMixin<S extends StatefulWidget> on TickerProviderStateMixin<S> { + /// Used by subclasses to manipulate the visual value of the control. + /// + /// Some controls respond to user input by updating their visual value. For + /// example, the thumb of a switch moves from one position to another when + /// dragged. These controls manipulate this animation controller to update + /// their [position] and eventually trigger an [onChanged] callback when the + /// animation reaches either 0.0 or 1.0. + AnimationController get positionController => _positionController; + late AnimationController _positionController; + + /// The visual value of the control. + /// + /// When the control is inactive, the [value] is false and this animation has + /// the value 0.0. When the control is active, the value is either true or + /// tristate is true and the value is null. When the control is active the + /// animation has a value of 1.0. When the control is changing from inactive + /// to active (or vice versa), [value] is the target value and this animation + /// gradually updates from 0.0 to 1.0 (or vice versa). + CurvedAnimation get position => _position; + late CurvedAnimation _position; + + /// Used by subclasses to control the radial reaction animation. + /// + /// Some controls have a radial ink reaction to user input. This animation + /// controller can be used to start or stop these ink reactions. + /// + /// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction] + /// may be used. + AnimationController get reactionController => _reactionController; + late AnimationController _reactionController; + + /// The visual value of the radial reaction animation. + /// + /// Some controls have a radial ink reaction to user input. This animation + /// controls the progress of these ink reactions. + /// + /// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction] + /// may be used. + CurvedAnimation get reaction => _reaction; + late CurvedAnimation _reaction; + + /// Controls the radial reaction's opacity animation for hover changes. + /// + /// Some controls have a radial ink reaction to pointer hover. This animation + /// controls these ink reaction fade-ins and + /// fade-outs. + /// + /// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction] + /// may be used. + CurvedAnimation get reactionHoverFade => _reactionHoverFade; + late CurvedAnimation _reactionHoverFade; + late AnimationController _reactionHoverFadeController; + + /// Controls the radial reaction's opacity animation for focus changes. + /// + /// Some controls have a radial ink reaction to focus. This animation + /// controls these ink reaction fade-ins and fade-outs. + /// + /// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction] + /// may be used. + CurvedAnimation get reactionFocusFade => _reactionFocusFade; + late CurvedAnimation _reactionFocusFade; + late AnimationController _reactionFocusFadeController; + + /// The amount of time a circular ink response should take to expand to its + /// full size if a radial reaction is drawn using + /// [ToggleablePainter.paintRadialReaction]. + Duration? get reactionAnimationDuration => _reactionAnimationDuration; + final Duration _reactionAnimationDuration = const Duration(milliseconds: 100); + + /// Whether [value] of this control can be changed by user interaction. + /// + /// The control is considered interactive if the [onChanged] callback is + /// non-null. If the callback is null, then the control is disabled, and + /// non-interactive. A disabled checkbox, for example, is displayed using a + /// grey color and its value cannot be changed. + bool get isInteractive => onChanged != null; + + late final Map<Type, Action<Intent>> _actionMap = <Type, Action<Intent>>{ + ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: _handleTap), + }; + + /// Called when the control changes value. + /// + /// If the control is tapped, [onChanged] is called immediately with the new + /// value. + /// + /// The control is considered interactive (see [isInteractive]) if this + /// callback is non-null. If the callback is null, then the control is + /// disabled, and non-interactive. A disabled checkbox, for example, is + /// displayed using a grey color and its value cannot be changed. + ValueChanged<bool?>? get onChanged; + + /// False if this control is "inactive" (not checked, off, or unselected). + /// + /// If value is true then the control "active" (checked, on, or selected). If + /// tristate is true and value is null, then the control is considered to be + /// in its third or "indeterminate" state. + /// + /// When the value changes, this object starts the [positionController] and + /// [position] animations to animate the visual appearance of the control to + /// the new value. + bool? get value; + + /// If true, [value] can be true, false, or null, otherwise [value] must + /// be true or false. + /// + /// When [tristate] is true and [value] is null, then the control is + /// considered to be in its third or "indeterminate" state. + bool get tristate; + + @override + void initState() { + super.initState(); + _positionController = AnimationController( + duration: _kToggleDuration, + value: value == false ? 0.0 : 1.0, + vsync: this, + ); + _position = CurvedAnimation( + parent: _positionController, + curve: Curves.easeIn, + reverseCurve: Curves.easeOut, + ); + _reactionController = AnimationController( + duration: _reactionAnimationDuration, + vsync: this, + ); + _reaction = CurvedAnimation( + parent: _reactionController, + curve: Curves.fastOutSlowIn, + ); + _reactionHoverFadeController = AnimationController( + duration: _kReactionFadeDuration, + value: _hovering || _focused ? 1.0 : 0.0, + vsync: this, + ); + _reactionHoverFade = CurvedAnimation( + parent: _reactionHoverFadeController, + curve: Curves.fastOutSlowIn, + ); + _reactionFocusFadeController = AnimationController( + duration: _kReactionFadeDuration, + value: _hovering || _focused ? 1.0 : 0.0, + vsync: this, + ); + _reactionFocusFade = CurvedAnimation( + parent: _reactionFocusFadeController, + curve: Curves.fastOutSlowIn, + ); + } + + /// Runs the [position] animation to transition the Toggleable's appearance + /// to match [value]. + /// + /// This method must be called whenever [value] changes to ensure that the + /// visual representation of the Toggleable matches the current [value]. + void animateToValue() { + if (tristate) { + if (value == null) { + _positionController.value = 0.0; + } + if (value ?? true) { + _positionController.forward(); + } else { + _positionController.reverse(); + } + } else { + if (value ?? false) { + _positionController.forward(); + } else { + _positionController.reverse(); + } + } + } + + @override + void dispose() { + _positionController.dispose(); + _position.dispose(); + _reactionController.dispose(); + _reaction.dispose(); + _reactionHoverFadeController.dispose(); + _reactionHoverFade.dispose(); + _reactionFocusFadeController.dispose(); + _reactionFocusFade.dispose(); + super.dispose(); + } + + /// The most recent [Offset] at which a pointer touched the Toggleable. + /// + /// This is null if currently no pointer is touching the Toggleable or if + /// [isInteractive] is false. + Offset? get downPosition => _downPosition; + Offset? _downPosition; + + void _handleTapDown(TapDownDetails details) { + if (isInteractive) { + setState(() { + _downPosition = details.localPosition; + }); + _reactionController.forward(); + } + } + + void _handleTap([Intent? _]) { + if (!isInteractive) { + return; + } + switch (value) { + case false: + onChanged!(true); + case true: + onChanged!(tristate ? null : false); + case null: + onChanged!(false); + } + context.findRenderObject()!.sendSemanticsEvent(const TapSemanticEvent()); + } + + void _handleTapEnd([TapUpDetails? _]) { + if (_downPosition != null) { + setState(() { _downPosition = null; }); + } + _reactionController.reverse(); + } + + bool _focused = false; + void _handleFocusHighlightChanged(bool focused) { + if (focused != _focused) { + setState(() { _focused = focused; }); + if (focused) { + _reactionFocusFadeController.forward(); + } else { + _reactionFocusFadeController.reverse(); + } + } + } + + bool _hovering = false; + void _handleHoverChanged(bool hovering) { + if (hovering != _hovering) { + setState(() { _hovering = hovering; }); + if (hovering) { + _reactionHoverFadeController.forward(); + } else { + _reactionHoverFadeController.reverse(); + } + } + } + + /// Describes the current [WidgetState] of the Toggleable. + /// + /// The returned set will include: + /// + /// * [WidgetState.disabled], if [isInteractive] is false + /// * [WidgetState.hovered], if a pointer is hovering over the Toggleable + /// * [WidgetState.focused], if the Toggleable has input focus + /// * [WidgetState.selected], if [value] is true or null + Set<WidgetState> get states => <WidgetState>{ + if (!isInteractive) WidgetState.disabled, + if (_hovering) WidgetState.hovered, + if (_focused) WidgetState.focused, + if (value ?? true) WidgetState.selected, + }; + + /// Typically wraps a `painter` that draws the actual visuals of the + /// Toggleable with logic to toggle it. + /// + /// If drawing a radial ink reaction is desired (in Material Design for + /// example), consider providing a subclass of [ToggleablePainter] as a + /// `painter`, which implements logic to draw a radial ink reaction for this + /// control. The painter is usually configured with the [reaction], + /// [position], [reactionHoverFade], and [reactionFocusFade] animation + /// provided by this mixin. It is expected to draw the visuals of the + /// Toggleable based on the current value of these animations. The animations + /// are triggered by this mixin to transition the Toggleable from one state + /// to another. + /// + /// Material Toggleables must provide a [mouseCursor] which resolves to a + /// [MouseCursor] based on the current [WidgetState] of the Toggleable. + /// Cupertino Toggleables may not provide a [mouseCursor]. If no [mouseCursor] + /// is provided, [SystemMouseCursors.basic] will be used as the [mouseCursor] + /// across all [WidgetState]s. + /// + /// This method must be called from the [build] method of the [State] class + /// that uses this mixin. The returned [Widget] must be returned from the + /// build method - potentially after wrapping it in other widgets. + Widget buildToggleable({ + FocusNode? focusNode, + ValueChanged<bool>? onFocusChange, + bool autofocus = false, + WidgetStateProperty<MouseCursor>? mouseCursor, + required Size size, + required CustomPainter painter, + }) { + return FocusableActionDetector( + actions: _actionMap, + focusNode: focusNode, + autofocus: autofocus, + onFocusChange: onFocusChange, + enabled: isInteractive, + onShowFocusHighlight: _handleFocusHighlightChanged, + onShowHoverHighlight: _handleHoverChanged, + mouseCursor: mouseCursor?.resolve(states) ?? SystemMouseCursors.basic, + child: GestureDetector( + excludeFromSemantics: !isInteractive, + onTapDown: isInteractive ? _handleTapDown : null, + onTap: isInteractive ? _handleTap : null, + onTapUp: isInteractive ? _handleTapEnd : null, + onTapCancel: isInteractive ? _handleTapEnd : null, + child: Semantics( + enabled: isInteractive, + child: CustomPaint( + size: size, + painter: painter, + ), + ), + ), + ); + } +} + +/// A base class for a [CustomPainter] that may be passed to +/// [ToggleableStateMixin.buildToggleable] to draw the visual representation of +/// a Toggleable. +/// +/// Subclasses must implement the [paint] method to draw the actual visuals of +/// the Toggleable. +/// +/// If drawing a radial ink reaction is desired (in Material +/// Design for example), subclasses may call [paintRadialReaction] in their +/// [paint] method. +abstract class ToggleablePainter extends ChangeNotifier implements CustomPainter { + /// The visual value of the control. + /// + /// Usually set to [ToggleableStateMixin.position]. + Animation<double> get position => _position!; + Animation<double>? _position; + set position(Animation<double> value) { + if (value == _position) { + return; + } + _position?.removeListener(notifyListeners); + value.addListener(notifyListeners); + _position = value; + notifyListeners(); + } + + /// The visual value of the radial reaction animation. + /// + /// Usually set to [ToggleableStateMixin.reaction]. + Animation<double> get reaction => _reaction!; + Animation<double>? _reaction; + set reaction(Animation<double> value) { + if (value == _reaction) { + return; + } + _reaction?.removeListener(notifyListeners); + value.addListener(notifyListeners); + _reaction = value; + notifyListeners(); + } + + /// Controls the radial reaction's opacity animation for focus changes. + /// + /// Usually set to [ToggleableStateMixin.reactionFocusFade]. + Animation<double> get reactionFocusFade => _reactionFocusFade!; + Animation<double>? _reactionFocusFade; + set reactionFocusFade(Animation<double> value) { + if (value == _reactionFocusFade) { + return; + } + _reactionFocusFade?.removeListener(notifyListeners); + value.addListener(notifyListeners); + _reactionFocusFade = value; + notifyListeners(); + } + + /// Controls the radial reaction's opacity animation for hover changes. + /// + /// Usually set to [ToggleableStateMixin.reactionHoverFade]. + Animation<double> get reactionHoverFade => _reactionHoverFade!; + Animation<double>? _reactionHoverFade; + set reactionHoverFade(Animation<double> value) { + if (value == _reactionHoverFade) { + return; + } + _reactionHoverFade?.removeListener(notifyListeners); + value.addListener(notifyListeners); + _reactionHoverFade = value; + notifyListeners(); + } + + /// The color that should be used in the active state (i.e., when + /// [ToggleableStateMixin.value] is true). + /// + /// For example, a checkbox should use this color when checked. + Color get activeColor => _activeColor!; + Color? _activeColor; + set activeColor(Color value) { + if (_activeColor == value) { + return; + } + _activeColor = value; + notifyListeners(); + } + + /// The color that should be used in the inactive state (i.e., when + /// [ToggleableStateMixin.value] is false). + /// + /// For example, a checkbox should use this color when unchecked. + Color get inactiveColor => _inactiveColor!; + Color? _inactiveColor; + set inactiveColor(Color value) { + if (_inactiveColor == value) { + return; + } + _inactiveColor = value; + notifyListeners(); + } + + /// The color that should be used for the reaction when the toggleable is + /// inactive. + /// + /// Used when the toggleable needs to change the reaction color/transparency + /// that is displayed when the toggleable is inactive and tapped. + Color get inactiveReactionColor => _inactiveReactionColor!; + Color? _inactiveReactionColor; + set inactiveReactionColor(Color value) { + if (value == _inactiveReactionColor) { + return; + } + _inactiveReactionColor = value; + notifyListeners(); + } + + /// The color that should be used for the reaction when the toggleable is + /// active. + /// + /// Used when the toggleable needs to change the reaction color/transparency + /// that is displayed when the toggleable is active and tapped. + Color get reactionColor => _reactionColor!; + Color? _reactionColor; + set reactionColor(Color value) { + if (value == _reactionColor) { + return; + } + _reactionColor = value; + notifyListeners(); + } + + /// The color that should be used for the reaction when [isHovered] is true. + /// + /// Used when the toggleable needs to change the reaction color/transparency, + /// when it is being hovered over. + Color get hoverColor => _hoverColor!; + Color? _hoverColor; + set hoverColor(Color value) { + if (value == _hoverColor) { + return; + } + _hoverColor = value; + notifyListeners(); + } + + /// The color that should be used for the reaction when [isFocused] is true. + /// + /// Used when the toggleable needs to change the reaction color/transparency, + /// when it has focus. + Color get focusColor => _focusColor!; + Color? _focusColor; + set focusColor(Color value) { + if (value == _focusColor) { + return; + } + _focusColor = value; + notifyListeners(); + } + + /// The splash radius for the radial reaction. + double get splashRadius => _splashRadius!; + double? _splashRadius; + set splashRadius(double value) { + if (value == _splashRadius) { + return; + } + _splashRadius = value; + notifyListeners(); + } + + /// The [Offset] within the Toggleable at which a pointer touched the Toggleable. + /// + /// This is null if currently no pointer is touching the Toggleable. + /// + /// Usually set to [ToggleableStateMixin.downPosition]. + Offset? get downPosition => _downPosition; + Offset? _downPosition; + set downPosition(Offset? value) { + if (value == _downPosition) { + return; + } + _downPosition = value; + notifyListeners(); + } + + /// True if this toggleable has the input focus. + bool get isFocused => _isFocused!; + bool? _isFocused; + set isFocused(bool? value) { + if (value == _isFocused) { + return; + } + _isFocused = value; + notifyListeners(); + } + + /// True if this toggleable is being hovered over by a pointer. + bool get isHovered => _isHovered!; + bool? _isHovered; + set isHovered(bool? value) { + if (value == _isHovered) { + return; + } + _isHovered = value; + notifyListeners(); + } + + /// Determines whether the toggleable shows as active. + bool get isActive => _isActive!; + bool? _isActive; + set isActive(bool? value) { + if (value == _isActive) { + return; + } + _isActive = value; + notifyListeners(); + } + + /// Used by subclasses to paint the radial ink reaction for this control. + /// + /// The reaction is painted on the given canvas at the given offset. The + /// origin is the center point of the reaction (usually distinct from the + /// [downPosition] at which the user interacted with the control). + void paintRadialReaction({ + required Canvas canvas, + Offset offset = Offset.zero, + required Offset origin, + }) { + if (!reaction.isDismissed || !reactionFocusFade.isDismissed || !reactionHoverFade.isDismissed) { + final Paint reactionPaint = Paint() + ..color = Color.lerp( + Color.lerp( + Color.lerp(inactiveReactionColor, reactionColor, position.value), + hoverColor, + reactionHoverFade.value, + ), + focusColor, + reactionFocusFade.value, + )!; + final Animatable<double> radialReactionRadiusTween = Tween<double>( + begin: 0.0, + end: splashRadius, + ); + final double reactionRadius = isFocused || isHovered + ? splashRadius + : radialReactionRadiusTween.evaluate(reaction); + if (reactionRadius > 0.0) { + canvas.drawCircle(origin + offset, reactionRadius, reactionPaint); + } + } + } + + @override + void dispose() { + _position?.removeListener(notifyListeners); + _reaction?.removeListener(notifyListeners); + _reactionFocusFade?.removeListener(notifyListeners); + _reactionHoverFade?.removeListener(notifyListeners); + super.dispose(); + } + + @override + bool shouldRepaint(covariant CustomPainter oldDelegate) => true; + + @override + bool? hitTest(Offset position) => null; + + @override + SemanticsBuilderCallback? get semanticsBuilder => null; + + @override + bool shouldRebuildSemantics(covariant CustomPainter oldDelegate) => false; + + @override + String toString() => describeIdentity(this); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/transitions.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/transitions.dart new file mode 100644 index 0000000000000000000000000000000000000000..76ef816cc933d4b05351200ba861092fe7a9ad34 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/transitions.dart @@ -0,0 +1,1228 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'container.dart'; +import 'framework.dart'; +import 'text.dart'; + +export 'package:flutter/rendering.dart' show RelativeRect; + +/// A widget that rebuilds when the given [Listenable] changes value. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=LKKgYpC-EPQ} +/// +/// [AnimatedWidget] is most commonly used with [Animation] objects, which are +/// [Listenable], but it can be used with any [Listenable], including +/// [ChangeNotifier] and [ValueNotifier]. +/// +/// [AnimatedWidget] is most useful for widgets that are otherwise stateless. To +/// use [AnimatedWidget], subclass it and implement the build function. +/// +/// {@tool dartpad} +/// This code defines a widget called `Spinner` that spins a green square +/// continually. It is built with an [AnimatedWidget]. +/// +/// ** See code in examples/api/lib/widgets/transitions/animated_widget.0.dart ** +/// {@end-tool} +/// +/// For more complex case involving additional state, consider using +/// [AnimatedBuilder] or [ListenableBuilder]. +/// +/// ## Relationship to [ImplicitlyAnimatedWidget]s +/// +/// [AnimatedWidget]s (and their subclasses) take an explicit [Listenable] as +/// argument, which is usually an [Animation] derived from an +/// [AnimationController]. In most cases, the lifecycle of that +/// [AnimationController] has to be managed manually by the developer. +/// In contrast to that, [ImplicitlyAnimatedWidget]s (and their subclasses) +/// automatically manage their own internal [AnimationController] making those +/// classes easier to use as no external [Animation] has to be provided by the +/// developer. If you only need to set a target value for the animation and +/// configure its duration/curve, consider using (a subclass of) +/// [ImplicitlyAnimatedWidget]s instead of (a subclass of) this class. +/// +/// ## Common animated widgets +/// +/// A number of animated widgets ship with the framework. They are usually named +/// `FooTransition`, where `Foo` is the name of the non-animated +/// version of that widget. The subclasses of this class should not be confused +/// with subclasses of [ImplicitlyAnimatedWidget] (see above), which are usually +/// named `AnimatedFoo`. Commonly used animated widgets include: +/// +/// * [ListenableBuilder], which uses a builder pattern that is useful for +/// complex [Listenable] use cases. +/// * [AnimatedBuilder], which uses a builder pattern that is useful for +/// complex [Animation] use cases. +/// * [AlignTransition], which is an animated version of [Align]. +/// * [DecoratedBoxTransition], which is an animated version of [DecoratedBox]. +/// * [DefaultTextStyleTransition], which is an animated version of +/// [DefaultTextStyle]. +/// * [PositionedTransition], which is an animated version of [Positioned]. +/// * [RelativePositionedTransition], which is an animated version of +/// [Positioned]. +/// * [RotationTransition], which animates the rotation of a widget. +/// * [ScaleTransition], which animates the scale of a widget. +/// * [SizeTransition], which animates its own size. +/// * [SlideTransition], which animates the position of a widget relative to +/// its normal position. +/// * [FadeTransition], which is an animated version of [Opacity]. +/// * [AnimatedModalBarrier], which is an animated version of [ModalBarrier]. +abstract class AnimatedWidget extends StatefulWidget { + /// Creates a widget that rebuilds when the given listenable changes. + /// + /// The [listenable] argument is required. + const AnimatedWidget({ + super.key, + required this.listenable, + }); + + /// The [Listenable] to which this widget is listening. + /// + /// Commonly an [Animation] or a [ChangeNotifier]. + final Listenable listenable; + + /// Override this method to build widgets that depend on the state of the + /// listenable (e.g., the current value of the animation). + @protected + Widget build(BuildContext context); + + /// Subclasses typically do not override this method. + @override + State<AnimatedWidget> createState() => _AnimatedState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Listenable>('listenable', listenable)); + } +} + +class _AnimatedState extends State<AnimatedWidget> { + @override + void initState() { + super.initState(); + widget.listenable.addListener(_handleChange); + } + + @override + void didUpdateWidget(AnimatedWidget oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.listenable != oldWidget.listenable) { + oldWidget.listenable.removeListener(_handleChange); + widget.listenable.addListener(_handleChange); + } + } + + @override + void dispose() { + widget.listenable.removeListener(_handleChange); + super.dispose(); + } + + void _handleChange() { + setState(() { + // The listenable's state is our build state, and it changed already. + }); + } + + @override + Widget build(BuildContext context) => widget.build(context); +} + +/// Animates the position of a widget relative to its normal position. +/// +/// The translation is expressed as an [Offset] scaled to the child's size. For +/// example, an [Offset] with a `dx` of 0.25 will result in a horizontal +/// translation of one quarter the width of the child. +/// +/// By default, the offsets are applied in the coordinate system of the canvas +/// (so positive x offsets move the child towards the right). If a +/// [textDirection] is provided, then the offsets are applied in the reading +/// direction, so in right-to-left text, positive x offsets move towards the +/// left, and in left-to-right text, positive x offsets move towards the right. +/// +/// Here's an illustration of the [SlideTransition] widget, with its [position] +/// animated by a [CurvedAnimation] set to [Curves.elasticIn]: +/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/slide_transition.mp4} +/// +/// {@tool dartpad} +/// The following code implements the [SlideTransition] as seen in the video +/// above: +/// +/// ** See code in examples/api/lib/widgets/transitions/slide_transition.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AlignTransition], an animated version of an [Align] that animates its +/// [Align.alignment] property. +/// * [PositionedTransition], a widget that animates its child from a start +/// position to an end position over the lifetime of the animation. +/// * [RelativePositionedTransition], a widget that transitions its child's +/// position based on the value of a rectangle relative to a bounding box. +class SlideTransition extends AnimatedWidget { + /// Creates a fractional translation transition. + const SlideTransition({ + super.key, + required Animation<Offset> position, + this.transformHitTests = true, + this.textDirection, + this.child, + }) : super(listenable: position); + + /// The animation that controls the position of the child. + /// + /// If the current value of the position animation is `(dx, dy)`, the child + /// will be translated horizontally by `width * dx` and vertically by + /// `height * dy`, after applying the [textDirection] if available. + Animation<Offset> get position => listenable as Animation<Offset>; + + /// The direction to use for the x offset described by the [position]. + /// + /// If [textDirection] is null, the x offset is applied in the coordinate + /// system of the canvas (so positive x offsets move the child towards the + /// right). + /// + /// If [textDirection] is [TextDirection.rtl], the x offset is applied in the + /// reading direction such that x offsets move the child towards the left. + /// + /// If [textDirection] is [TextDirection.ltr], the x offset is applied in the + /// reading direction such that x offsets move the child towards the right. + final TextDirection? textDirection; + + /// Whether hit testing should be affected by the slide animation. + /// + /// If false, hit testing will proceed as if the child was not translated at + /// all. Setting this value to false is useful for fast animations where you + /// expect the user to commonly interact with the child widget in its final + /// location and you want the user to benefit from "muscle memory". + final bool transformHitTests; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + @override + Widget build(BuildContext context) { + Offset offset = position.value; + if (textDirection == TextDirection.rtl) { + offset = Offset(-offset.dx, offset.dy); + } + return FractionalTranslation( + translation: offset, + transformHitTests: transformHitTests, + child: child, + ); + } +} + +/// Signature for the callback to [MatrixTransition.onTransform]. +/// +/// Computes a [Matrix4] to be used in the [MatrixTransition] transformed widget +/// from the [MatrixTransition.animation] value. +typedef TransformCallback = Matrix4 Function(double animationValue); + +/// Animates the [Matrix4] of a transformed widget. +/// +/// The [onTransform] callback computes a [Matrix4] from the animated value, it +/// is called every time the [animation] changes its value. +/// +/// {@tool dartpad} +/// The following example implements a [MatrixTransition] with a rotation around +/// the Y axis, with a 3D perspective skew. +/// +/// ** See code in examples/api/lib/widgets/transitions/matrix_transition.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ScaleTransition], which animates the scale of a widget, by providing a +/// matrix which scales along the X and Y axis. +/// * [RotationTransition], which animates the rotation of a widget, by +/// providing a matrix which rotates along the Z axis. +class MatrixTransition extends AnimatedWidget { + /// Creates a matrix transition. + /// + /// The [alignment] argument defaults to [Alignment.center]. + const MatrixTransition({ + super.key, + required Animation<double> animation, + required this.onTransform, + this.alignment = Alignment.center, + this.filterQuality, + this.child, + }) : super(listenable: animation); + + /// The callback to compute a [Matrix4] from the [animation]. It's called + /// every time [animation] changes its value. + final TransformCallback onTransform; + + /// The animation that controls the matrix of the child. + /// + /// The matrix will be computed from the animation with the [onTransform] + /// callback. + Animation<double> get animation => listenable as Animation<double>; + + /// The alignment of the origin of the coordinate system in which the + /// transform takes place, relative to the size of the box. + /// + /// For example, to set the origin of the transform to bottom middle, you can + /// use an alignment of (0.0, 1.0). + final Alignment alignment; + + /// The filter quality with which to apply the transform as a bitmap operation. + /// + /// When the animation is stopped (either in [AnimationStatus.dismissed] or + /// [AnimationStatus.completed]), the filter quality argument will be ignored. + /// + /// {@macro flutter.widgets.Transform.optional.FilterQuality} + final FilterQuality? filterQuality; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + @override + Widget build(BuildContext context) { + // The ImageFilter layer created by setting filterQuality will introduce + // a saveLayer call. This is usually worthwhile when animating the layer, + // but leaving it in the layer tree before the animation has started or after + // it has finished significantly hurts performance. + final bool useFilterQuality; + switch (animation.status) { + case AnimationStatus.dismissed: + case AnimationStatus.completed: + useFilterQuality = false; + case AnimationStatus.forward: + case AnimationStatus.reverse: + useFilterQuality = true; + } + return Transform( + transform: onTransform(animation.value), + alignment: alignment, + filterQuality: useFilterQuality ? filterQuality : null, + child: child, + ); + } +} + +/// Animates the scale of a transformed widget. +/// +/// Here's an illustration of the [ScaleTransition] widget, with it's [scale] +/// animated by a [CurvedAnimation] set to [Curves.fastOutSlowIn]: +/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/scale_transition.mp4} +/// +/// {@tool dartpad} +/// The following code implements the [ScaleTransition] as seen in the video +/// above: +/// +/// ** See code in examples/api/lib/widgets/transitions/scale_transition.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [PositionedTransition], a widget that animates its child from a start +/// position to an end position over the lifetime of the animation. +/// * [RelativePositionedTransition], a widget that transitions its child's +/// position based on the value of a rectangle relative to a bounding box. +/// * [SizeTransition], a widget that animates its own size and clips and +/// aligns its child. +class ScaleTransition extends MatrixTransition { + /// Creates a scale transition. + /// + /// The [alignment] argument defaults to [Alignment.center]. + const ScaleTransition({ + super.key, + required Animation<double> scale, + super.alignment = Alignment.center, + super.filterQuality, + super.child, + }) : super(animation: scale, onTransform: _handleScaleMatrix); + + /// The animation that controls the scale of the child. + Animation<double> get scale => animation; + + /// The callback that controls the scale of the child. + /// + /// If the current value of the animation is v, the child will be + /// painted v times its normal size. + static Matrix4 _handleScaleMatrix(double value) => Matrix4.diagonal3Values(value, value, 1.0); +} + +/// Animates the rotation of a widget. +/// +/// Here's an illustration of the [RotationTransition] widget, with it's [turns] +/// animated by a [CurvedAnimation] set to [Curves.elasticOut]: +/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/rotation_transition.mp4} +/// +/// {@tool dartpad} +/// The following code implements the [RotationTransition] as seen in the video +/// above: +/// +/// ** See code in examples/api/lib/widgets/transitions/rotation_transition.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ScaleTransition], a widget that animates the scale of a transformed +/// widget. +/// * [SizeTransition], a widget that animates its own size and clips and +/// aligns its child. +class RotationTransition extends MatrixTransition { + /// Creates a rotation transition. + const RotationTransition({ + super.key, + required Animation<double> turns, + super.alignment = Alignment.center, + super.filterQuality, + super.child, + }) : super(animation: turns, onTransform: _handleTurnsMatrix); + + /// The animation that controls the rotation of the child. + Animation<double> get turns => animation; + + /// The callback that controls the rotation of the child. + /// + /// If the current value of the animation is v, the child will be rotated + /// v * 2 * pi radians before being painted. + static Matrix4 _handleTurnsMatrix(double value) => Matrix4.rotationZ(value * math.pi * 2.0); +} + +/// Animates its own size and clips and aligns its child. +/// +/// [SizeTransition] acts as a [ClipRect] that animates either its width or its +/// height, depending upon the value of [axis]. The alignment of the child along +/// the [axis] is specified by the [axisAlignment]. +/// +/// Like most widgets, [SizeTransition] will conform to the constraints it is +/// given, so be sure to put it in a context where it can change size. For +/// instance, if you place it into a [Container] with a fixed size, then the +/// [SizeTransition] will not be able to change size, and will appear to do +/// nothing. +/// +/// Here's an illustration of the [SizeTransition] widget, with it's [sizeFactor] +/// animated by a [CurvedAnimation] set to [Curves.fastOutSlowIn]: +/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/size_transition.mp4} +/// +/// {@tool dartpad} +/// This code defines a widget that uses [SizeTransition] to change the size +/// of [FlutterLogo] continually. It is built with a [Scaffold] +/// where the internal widget has space to change its size. +/// +/// ** See code in examples/api/lib/widgets/transitions/size_transition.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedCrossFade], for a widget that automatically animates between +/// the sizes of two children, fading between them. +/// * [ScaleTransition], a widget that scales the size of the child instead of +/// clipping it. +/// * [PositionedTransition], a widget that animates its child from a start +/// position to an end position over the lifetime of the animation. +/// * [RelativePositionedTransition], a widget that transitions its child's +/// position based on the value of a rectangle relative to a bounding box. +class SizeTransition extends AnimatedWidget { + /// Creates a size transition. + /// + /// The [axis] argument defaults to [Axis.vertical]. The [axisAlignment] + /// defaults to zero, which centers the child along the main axis during the + /// transition. + const SizeTransition({ + super.key, + this.axis = Axis.vertical, + required Animation<double> sizeFactor, + this.axisAlignment = 0.0, + this.fixedCrossAxisSizeFactor, + this.child, + }) : assert(fixedCrossAxisSizeFactor == null || fixedCrossAxisSizeFactor >= 0.0), + super(listenable: sizeFactor); + + /// [Axis.horizontal] if [sizeFactor] modifies the width, otherwise + /// [Axis.vertical]. + final Axis axis; + + /// The animation that controls the (clipped) size of the child. + /// + /// The width or height (depending on the [axis] value) of this widget will be + /// its intrinsic width or height multiplied by [sizeFactor]'s value at the + /// current point in the animation. + /// + /// If the value of [sizeFactor] is less than one, the child will be clipped + /// in the appropriate axis. + Animation<double> get sizeFactor => listenable as Animation<double>; + + /// Describes how to align the child along the axis that [sizeFactor] is + /// modifying. + /// + /// A value of -1.0 indicates the top when [axis] is [Axis.vertical], and the + /// start when [axis] is [Axis.horizontal]. The start is on the left when the + /// text direction in effect is [TextDirection.ltr] and on the right when it + /// is [TextDirection.rtl]. + /// + /// A value of 1.0 indicates the bottom or end, depending upon the [axis]. + /// + /// A value of 0.0 (the default) indicates the center for either [axis] value. + final double axisAlignment; + + /// The factor by which to multiply the cross axis size of the child. + /// + /// If the value of [fixedCrossAxisSizeFactor] is less than one, the child + /// will be clipped along the appropriate axis. + /// + /// If `null` (the default), the cross axis size is as large as the parent. + final double? fixedCrossAxisSizeFactor; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget? child; + + @override + Widget build(BuildContext context) { + final AlignmentDirectional alignment; + if (axis == Axis.vertical) { + alignment = AlignmentDirectional(-1.0, axisAlignment); + } else { + alignment = AlignmentDirectional(axisAlignment, -1.0); + } + return ClipRect( + child: Align( + alignment: alignment, + heightFactor: axis == Axis.vertical ? math.max(sizeFactor.value, 0.0) : fixedCrossAxisSizeFactor, + widthFactor: axis == Axis.horizontal ? math.max(sizeFactor.value, 0.0) : fixedCrossAxisSizeFactor, + child: child, + ), + ); + } +} + +/// Animates the opacity of a widget. +/// +/// For a widget that automatically animates between the sizes of two children, +/// fading between them, see [AnimatedCrossFade]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=rLwWVbv3xDQ} +/// +/// Here's an illustration of the [FadeTransition] widget, with it's [opacity] +/// animated by a [CurvedAnimation] set to [Curves.fastOutSlowIn]: +/// +/// {@tool dartpad} +/// The following code implements the [FadeTransition] using +/// the Flutter logo: +/// +/// ** See code in examples/api/lib/widgets/transitions/fade_transition.0.dart ** +/// {@end-tool} +/// +/// ## Hit testing +/// +/// Setting the [opacity] to zero does not prevent hit testing from being +/// applied to the descendants of the [FadeTransition] widget. This can be +/// confusing for the user, who may not see anything, and may believe the area +/// of the interface where the [FadeTransition] is hiding a widget to be +/// non-interactive. +/// +/// With certain widgets, such as [Flow], that compute their positions only when +/// they are painted, this can actually lead to bugs (from unexpected geometry +/// to exceptions), because those widgets are not painted by the [FadeTransition] +/// widget at all when the [opacity] animation reaches zero. +/// +/// To avoid such problems, it is generally a good idea to combine this widget +/// with an [IgnorePointer] that one enables when the [opacity] animation +/// reaches zero. This prevents interactions with any children in the subtree +/// when the [child] is not visible. For performance reasons, when implementing +/// this, care should be taken not to rebuild the relevant widget (e.g. by +/// calling [State.setState]) except at the transition point. +/// +/// See also: +/// +/// * [Opacity], which does not animate changes in opacity. +/// * [AnimatedOpacity], which animates changes in opacity without taking an +/// explicit [Animation] argument. +/// * [SliverFadeTransition], the sliver version of this widget. +class FadeTransition extends SingleChildRenderObjectWidget { + /// Creates an opacity transition. + const FadeTransition({ + super.key, + required this.opacity, + this.alwaysIncludeSemantics = false, + super.child, + }); + + /// The animation that controls the opacity of the child. + /// + /// If the current value of the opacity animation is v, the child will be + /// painted with an opacity of v. For example, if v is 0.5, the child will be + /// blended 50% with its background. Similarly, if v is 0.0, the child will be + /// completely transparent. + final Animation<double> opacity; + + /// Whether the semantic information of the children is always included. + /// + /// Defaults to false. + /// + /// When true, regardless of the opacity settings the child semantic + /// information is exposed as if the widget were fully visible. This is + /// useful in cases where labels may be hidden during animations that + /// would otherwise contribute relevant semantics. + final bool alwaysIncludeSemantics; + + @override + RenderAnimatedOpacity createRenderObject(BuildContext context) { + return RenderAnimatedOpacity( + opacity: opacity, + alwaysIncludeSemantics: alwaysIncludeSemantics, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderAnimatedOpacity renderObject) { + renderObject + ..opacity = opacity + ..alwaysIncludeSemantics = alwaysIncludeSemantics; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Animation<double>>('opacity', opacity)); + properties.add(FlagProperty('alwaysIncludeSemantics', value: alwaysIncludeSemantics, ifTrue: 'alwaysIncludeSemantics')); + } +} + +/// Animates the opacity of a sliver widget. +/// +/// {@tool dartpad} +/// Creates a [CustomScrollView] with a [SliverFixedExtentList] that uses a +/// [SliverFadeTransition] to fade the list in and out. +/// +/// ** See code in examples/api/lib/widgets/transitions/sliver_fade_transition.0.dart ** +/// {@end-tool} +/// +/// Here's an illustration of the [FadeTransition] widget, the [RenderBox] +/// equivalent widget, with it's [opacity] animated by a [CurvedAnimation] set +/// to [Curves.fastOutSlowIn]: +/// +/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/fade_transition.mp4} +/// +/// ## Hit testing +/// +/// Setting the [opacity] to zero does not prevent hit testing from being +/// applied to the descendants of the [SliverFadeTransition] widget. This can be +/// confusing for the user, who may not see anything, and may believe the area +/// of the interface where the [SliverFadeTransition] is hiding a widget to be +/// non-interactive. +/// +/// With certain widgets, such as [Flow], that compute their positions only when +/// they are painted, this can actually lead to bugs (from unexpected geometry +/// to exceptions), because those widgets are not painted by the +/// [SliverFadeTransition] widget at all when the [opacity] animation reaches +/// zero. +/// +/// To avoid such problems, it is generally a good idea to combine this widget +/// with a [SliverIgnorePointer] that one enables when the [opacity] animation +/// reaches zero. This prevents interactions with any children in the subtree +/// when the [sliver] is not visible. For performance reasons, when implementing +/// this, care should be taken not to rebuild the relevant widget (e.g. by +/// calling [State.setState]) except at the transition point. +/// +/// See also: +/// +/// * [SliverOpacity], which does not animate changes in opacity. +/// * [FadeTransition], the box version of this widget. +class SliverFadeTransition extends SingleChildRenderObjectWidget { + /// Creates an opacity transition. + const SliverFadeTransition({ + super.key, + required this.opacity, + this.alwaysIncludeSemantics = false, + Widget? sliver, + }) : super(child: sliver); + + /// The animation that controls the opacity of the sliver child. + /// + /// If the current value of the opacity animation is v, the child will be + /// painted with an opacity of v. For example, if v is 0.5, the child will be + /// blended 50% with its background. Similarly, if v is 0.0, the child will be + /// completely transparent. + final Animation<double> opacity; + + /// Whether the semantic information of the sliver child is always included. + /// + /// Defaults to false. + /// + /// When true, regardless of the opacity settings the sliver child's semantic + /// information is exposed as if the widget were fully visible. This is + /// useful in cases where labels may be hidden during animations that + /// would otherwise contribute relevant semantics. + final bool alwaysIncludeSemantics; + + @override + RenderSliverAnimatedOpacity createRenderObject(BuildContext context) { + return RenderSliverAnimatedOpacity( + opacity: opacity, + alwaysIncludeSemantics: alwaysIncludeSemantics, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderSliverAnimatedOpacity renderObject) { + renderObject + ..opacity = opacity + ..alwaysIncludeSemantics = alwaysIncludeSemantics; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Animation<double>>('opacity', opacity)); + properties.add(FlagProperty('alwaysIncludeSemantics', value: alwaysIncludeSemantics, ifTrue: 'alwaysIncludeSemantics')); + } +} + +/// An interpolation between two relative rects. +/// +/// This class specializes the interpolation of [Tween<RelativeRect>] to +/// use [RelativeRect.lerp]. +/// +/// See [Tween] for a discussion on how to use interpolation objects. +class RelativeRectTween extends Tween<RelativeRect> { + /// Creates a [RelativeRect] tween. + /// + /// The [begin] and [end] properties may be null; the null value + /// is treated as [RelativeRect.fill]. + RelativeRectTween({ super.begin, super.end }); + + /// Returns the value this variable has at the given animation clock value. + @override + RelativeRect lerp(double t) => RelativeRect.lerp(begin, end, t)!; +} + +/// Animated version of [Positioned] which takes a specific +/// [Animation<RelativeRect>] to transition the child's position from a start +/// position to an end position over the lifetime of the animation. +/// +/// Only works if it's the child of a [Stack]. +/// +/// Here's an illustration of the [PositionedTransition] widget, with it's [rect] +/// animated by a [CurvedAnimation] set to [Curves.elasticInOut]: +/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/positioned_transition.mp4} +/// +/// {@tool dartpad} +/// The following code implements the [PositionedTransition] as seen in the video +/// above: +/// +/// ** See code in examples/api/lib/widgets/transitions/positioned_transition.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedPositioned], which transitions a child's position without +/// taking an explicit [Animation] argument. +/// * [RelativePositionedTransition], a widget that transitions its child's +/// position based on the value of a rectangle relative to a bounding box. +/// * [SlideTransition], a widget that animates the position of a widget +/// relative to its normal position. +/// * [AlignTransition], an animated version of an [Align] that animates its +/// [Align.alignment] property. +/// * [ScaleTransition], a widget that animates the scale of a transformed +/// widget. +/// * [SizeTransition], a widget that animates its own size and clips and +/// aligns its child. +class PositionedTransition extends AnimatedWidget { + /// Creates a transition for [Positioned]. + const PositionedTransition({ + super.key, + required Animation<RelativeRect> rect, + required this.child, + }) : super(listenable: rect); + + /// The animation that controls the child's size and position. + Animation<RelativeRect> get rect => listenable as Animation<RelativeRect>; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + return Positioned.fromRelativeRect( + rect: rect.value, + child: child, + ); + } +} + +/// Animated version of [Positioned] which transitions the child's position +/// based on the value of [rect] relative to a bounding box with the +/// specified [size]. +/// +/// Only works if it's the child of a [Stack]. +/// +/// Here's an illustration of the [RelativePositionedTransition] widget, with it's [rect] +/// animated by a [CurvedAnimation] set to [Curves.elasticInOut]: +/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/relative_positioned_transition.mp4} +/// +/// {@tool dartpad} +/// The following code implements the [RelativePositionedTransition] as seen in the video +/// above: +/// +/// ** See code in examples/api/lib/widgets/transitions/relative_positioned_transition.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [PositionedTransition], a widget that animates its child from a start +/// position to an end position over the lifetime of the animation. +/// * [AlignTransition], an animated version of an [Align] that animates its +/// [Align.alignment] property. +/// * [ScaleTransition], a widget that animates the scale of a transformed +/// widget. +/// * [SizeTransition], a widget that animates its own size and clips and +/// aligns its child. +/// * [SlideTransition], a widget that animates the position of a widget +/// relative to its normal position. +class RelativePositionedTransition extends AnimatedWidget { + /// Create an animated version of [Positioned]. + /// + /// Each frame, the [Positioned] widget will be configured to represent the + /// current value of the [rect] argument assuming that the stack has the given + /// [size]. + const RelativePositionedTransition({ + super.key, + required Animation<Rect?> rect, + required this.size, + required this.child, + }) : super(listenable: rect); + + /// The animation that controls the child's size and position. + /// + /// If the animation returns a null [Rect], the rect is assumed to be [Rect.zero]. + /// + /// See also: + /// + /// * [size], which gets the size of the box that the [Positioned] widget's + /// offsets are relative to. + Animation<Rect?> get rect => listenable as Animation<Rect?>; + + /// The [Positioned] widget's offsets are relative to a box of this + /// size whose origin is 0,0. + final Size size; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + final RelativeRect offsets = RelativeRect.fromSize(rect.value ?? Rect.zero, size); + return Positioned( + top: offsets.top, + right: offsets.right, + bottom: offsets.bottom, + left: offsets.left, + child: child, + ); + } +} + +/// Animated version of a [DecoratedBox] that animates the different properties +/// of its [Decoration]. +/// +/// Here's an illustration of the [DecoratedBoxTransition] widget, with it's +/// [decoration] animated by a [CurvedAnimation] set to [Curves.decelerate]: +/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/decorated_box_transition.mp4} +/// +/// {@tool dartpad} +/// The following code implements the [DecoratedBoxTransition] as seen in the video +/// above: +/// +/// ** See code in examples/api/lib/widgets/transitions/decorated_box_transition.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [DecoratedBox], which also draws a [Decoration] but is not animated. +/// * [AnimatedContainer], a more full-featured container that also animates on +/// decoration using an internal animation. +class DecoratedBoxTransition extends AnimatedWidget { + /// Creates an animated [DecoratedBox] whose [Decoration] animation updates + /// the widget. + /// + /// See also: + /// + /// * [DecoratedBox.new] + const DecoratedBoxTransition({ + super.key, + required this.decoration, + this.position = DecorationPosition.background, + required this.child, + }) : super(listenable: decoration); + + /// Animation of the decoration to paint. + /// + /// Can be created using a [DecorationTween] interpolating typically between + /// two [BoxDecoration]. + final Animation<Decoration> decoration; + + /// Whether to paint the box decoration behind or in front of the child. + final DecorationPosition position; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + return DecoratedBox( + decoration: decoration.value, + position: position, + child: child, + ); + } +} + +/// Animated version of an [Align] that animates its [Align.alignment] property. +/// +/// Here's an illustration of the [DecoratedBoxTransition] widget, with it's +/// [DecoratedBoxTransition.decoration] animated by a [CurvedAnimation] set to +/// [Curves.decelerate]: +/// +/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/align_transition.mp4} +/// +/// {@tool dartpad} +/// The following code implements the [AlignTransition] as seen in the video +/// above: +/// +/// ** See code in examples/api/lib/widgets/transitions/align_transition.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedAlign], which animates changes to the [alignment] without +/// taking an explicit [Animation] argument. +/// * [PositionedTransition], a widget that animates its child from a start +/// position to an end position over the lifetime of the animation. +/// * [RelativePositionedTransition], a widget that transitions its child's +/// position based on the value of a rectangle relative to a bounding box. +/// * [SizeTransition], a widget that animates its own size and clips and +/// aligns its child. +/// * [SlideTransition], a widget that animates the position of a widget +/// relative to its normal position. +class AlignTransition extends AnimatedWidget { + /// Creates an animated [Align] whose [AlignmentGeometry] animation updates + /// the widget. + /// + /// See also: + /// + /// * [Align.new]. + const AlignTransition({ + super.key, + required Animation<AlignmentGeometry> alignment, + required this.child, + this.widthFactor, + this.heightFactor, + }) : super(listenable: alignment); + + /// The animation that controls the child's alignment. + Animation<AlignmentGeometry> get alignment => listenable as Animation<AlignmentGeometry>; + + /// If non-null, the child's width factor, see [Align.widthFactor]. + final double? widthFactor; + + /// If non-null, the child's height factor, see [Align.heightFactor]. + final double? heightFactor; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + return Align( + alignment: alignment.value, + widthFactor: widthFactor, + heightFactor: heightFactor, + child: child, + ); + } +} + +/// Animated version of a [DefaultTextStyle] that animates the different properties +/// of its [TextStyle]. +/// +/// {@tool dartpad} +/// The following code implements the [DefaultTextStyleTransition] that shows +/// a transition between thick blue font and thin red font. +/// +/// ** See code in examples/api/lib/widgets/transitions/default_text_style_transition.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedDefaultTextStyle], which animates changes in text style without +/// taking an explicit [Animation] argument. +/// * [DefaultTextStyle], which also defines a [TextStyle] for its descendants +/// but is not animated. +class DefaultTextStyleTransition extends AnimatedWidget { + /// Creates an animated [DefaultTextStyle] whose [TextStyle] animation updates + /// the widget. + const DefaultTextStyleTransition({ + super.key, + required Animation<TextStyle> style, + required this.child, + this.textAlign, + this.softWrap = true, + this.overflow = TextOverflow.clip, + this.maxLines, + }) : super(listenable: style); + + /// The animation that controls the descendants' text style. + Animation<TextStyle> get style => listenable as Animation<TextStyle>; + + /// How the text should be aligned horizontally. + final TextAlign? textAlign; + + /// Whether the text should break at soft line breaks. + /// + /// See [DefaultTextStyle.softWrap] for more details. + final bool softWrap; + + /// How visual overflow should be handled. + /// + final TextOverflow overflow; + + /// An optional maximum number of lines for the text to span, wrapping if necessary. + /// + /// See [DefaultTextStyle.maxLines] for more details. + final int? maxLines; + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + @override + Widget build(BuildContext context) { + return DefaultTextStyle( + style: style.value, + textAlign: textAlign, + softWrap: softWrap, + overflow: overflow, + maxLines: maxLines, + child: child, + ); + } +} + +/// A general-purpose widget for building a widget subtree when a [Listenable] +/// changes. +/// +/// [ListenableBuilder] is useful for more complex widgets that wish to listen +/// to changes in other objects as part of a larger build function. To use +/// [ListenableBuilder], construct the widget and pass it a [builder] +/// function. +/// +/// Any subtype of [Listenable] (such as a [ChangeNotifier], [ValueNotifier], or +/// [Animation]) can be used with a [ListenableBuilder] to rebuild only certain +/// parts of a widget when the [Listenable] notifies its listeners. Although +/// they have identical implementations, if an [Animation] is being listened to, +/// consider using an [AnimatedBuilder] instead for better readability. +/// +/// {@tool dartpad} +/// The following example uses a subclass of [ChangeNotifier] to hold the +/// application model's state, in this case, a counter. A [ListenableBuilder] is +/// then used to update the rendering (a [Text] widget) whenever the model changes. +/// +/// ** See code in examples/api/lib/widgets/transitions/listenable_builder.2.dart ** +/// {@end-tool} +/// +/// {@tool dartpad} +/// This version is identical, but using a [ValueNotifier] instead of a +/// dedicated subclass of [ChangeNotifier]. This works well when there is only a +/// single immutable value to be tracked. +/// +/// ** See code in examples/api/lib/widgets/transitions/listenable_builder.1.dart ** +/// {@end-tool} +/// +/// ## Performance optimizations +/// +/// {@template flutter.widgets.transitions.ListenableBuilder.optimizations} +/// If the [builder] function contains a subtree that does not depend on the +/// [listenable], it is more efficient to build that subtree once instead +/// of rebuilding it on every change of the [listenable]. +/// +/// Performance is therefore improved by specifying any widgets that don't need +/// to change using the prebuilt [child] attribute. The [ListenableBuilder] +/// passes this [child] back to the [builder] callback so that it can be +/// incorporated into the build. +/// +/// Using this pre-built [child] is entirely optional, but can improve +/// performance significantly in some cases and is therefore a good practice. +/// {@endtemplate} +/// +/// {@tool dartpad} +/// This example shows how a [ListenableBuilder] can be used to listen to a +/// [FocusNode] (which is also a [ChangeNotifier]) to see when a subtree has +/// focus, and modify a decoration when its focus state changes. Only the +/// [Container] is rebuilt when the [FocusNode] changes; the rest of the tree +/// (notably the [Focus] widget) remain unchanged from frame to frame. +/// +/// ** See code in examples/api/lib/widgets/transitions/listenable_builder.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedBuilder], which has the same functionality, but is named more +/// appropriately for a builder triggered by [Animation]s. +/// * [ValueListenableBuilder], which is specialized for [ValueNotifier]s and +/// reports the new value in its builder callback. +class ListenableBuilder extends AnimatedWidget { + /// Creates a builder that responds to changes in [listenable]. + const ListenableBuilder({ + super.key, + required super.listenable, + required this.builder, + this.child, + }); + + /// The [Listenable] supplied to the constructor. + /// + /// {@tool dartpad} + /// In this example, the [listenable] is a [ChangeNotifier] subclass that + /// encapsulates a list. The [ListenableBuilder] is rebuilt each time an item + /// is added to the list. + /// + /// ** See code in examples/api/lib/widgets/transitions/listenable_builder.3.dart ** + /// {@end-tool} + /// + /// See also: + /// + /// * [AnimatedBuilder], a widget with identical functionality commonly + /// used with [Animation] [Listenable]s for better readability. + // + // Overridden getter to replace with documentation tailored to + // ListenableBuilder. + @override + Listenable get listenable => super.listenable; + + /// Called every time the [listenable] notifies about a change. + /// + /// The child given to the builder should typically be part of the returned + /// widget tree. + final TransitionBuilder builder; + + /// The child widget to pass to the [builder]. + /// + /// {@macro flutter.widgets.transitions.ListenableBuilder.optimizations} + final Widget? child; + + @override + Widget build(BuildContext context) => builder(context, child); +} + +/// A general-purpose widget for building animations. +/// +/// [AnimatedBuilder] is useful for more complex widgets that wish to include +/// an animation as part of a larger build function. To use [AnimatedBuilder], +/// construct the widget and pass it a builder function. +/// +/// For simple cases without additional state, consider using +/// [AnimatedWidget]. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=N-RiyZlv8v8} +/// +/// Despite the name, [AnimatedBuilder] is not limited to [Animation]s, any +/// subtype of [Listenable] (such as [ChangeNotifier] or [ValueNotifier]) can be +/// used to trigger rebuilds. Although they have identical implementations, if +/// an [Animation] is not being listened to, consider using a +/// [ListenableBuilder] for better readability. +/// +/// ## Performance optimizations +/// +/// {@template flutter.widgets.transitions.AnimatedBuilder.optimizations} +/// If the [builder] function contains a subtree that does not depend on the +/// animation passed to the constructor, it's more efficient to build that +/// subtree once instead of rebuilding it on every animation tick. +/// +/// If a pre-built subtree is passed as the [child] parameter, the +/// [AnimatedBuilder] will pass it back to the [builder] function so that it can +/// be incorporated into the build. +/// +/// Using this pre-built child is entirely optional, but can improve +/// performance significantly in some cases and is therefore a good practice. +/// {@endtemplate} +/// +/// {@tool dartpad} +/// This code defines a widget that spins a green square continually. It is +/// built with an [AnimatedBuilder] and makes use of the [child] feature to +/// avoid having to rebuild the [Container] each time. +/// +/// ** See code in examples/api/lib/widgets/transitions/animated_builder.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [ListenableBuilder], a widget with similar functionality, but named +/// more appropriately for a builder triggered on changes in [Listenable]s +/// that aren't [Animation]s. +/// * [TweenAnimationBuilder], which animates a property to a target value +/// without requiring manual management of an [AnimationController]. +class AnimatedBuilder extends ListenableBuilder { + /// Creates an animated builder. + /// + /// The [animation] and [builder] arguments are required. + const AnimatedBuilder({ + super.key, + required Listenable animation, + required super.builder, + super.child, + }) : super(listenable: animation); + + /// The [Listenable] supplied to the constructor (typically an [Animation]). + /// + /// Also accessible through the [listenable] getter. + /// + /// See also: + /// + /// * [ListenableBuilder], a widget with similar functionality commonly used + /// with [Listenable]s (such as [ChangeNotifier]) for better readability + /// when the [animation] isn't an [Animation]. + Listenable get animation => super.listenable; + + /// The [Listenable] supplied to the constructor (typically an [Animation]). + /// + /// Also accessible through the [animation] getter. + /// + /// See also: + /// + /// * [ListenableBuilder], a widget with identical functionality commonly + /// used with non-animation [Listenable]s for readability. + // + // Overridden getter to replace with documentation tailored to + // ListenableBuilder. + @override + Listenable get listenable => super.listenable; + + /// Called every time the [animation] notifies about a change. + /// + /// The child given to the builder should typically be part of the returned + /// widget tree. + // + // Overridden getter to replace with documentation tailored to + // AnimatedBuilder. + @override + TransitionBuilder get builder => super.builder; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/tween_animation_builder.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/tween_animation_builder.dart new file mode 100644 index 0000000000000000000000000000000000000000..3ef9f63fe4117e727f18991203b672846a0fa12f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/tween_animation_builder.dart @@ -0,0 +1,197 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/animation.dart'; + +import 'framework.dart'; +import 'implicit_animations.dart'; +import 'value_listenable_builder.dart'; + +/// [Widget] builder that animates a property of a [Widget] to a target value +/// whenever the target value changes. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=l9uHB8VXZOg} +/// +/// The type of the animated property ([Color], [Rect], [double], etc.) is +/// defined via the type of the provided [tween] (e.g. [ColorTween], +/// [RectTween], [Tween<double>], etc.). +/// +/// The [tween] also defines the target value for the animation: When the widget +/// first builds, it animates from [Tween.begin] to [Tween.end]. A new animation +/// can be triggered anytime by providing a new [tween] with a new [Tween.end] +/// value. The new animation runs from the current animation value (which may be +/// [Tween.end] of the old [tween], if that animation completed) to [Tween.end] +/// of the new [tween]. +/// +/// The animation is further customized by providing a [curve] and [duration]. +/// +/// The current value of the animation along with the [child] is passed to +/// the [builder] callback, which is expected to build a [Widget] based on the +/// current animation value. The [builder] is called throughout the animation +/// for every animation value until [Tween.end] is reached. +/// +/// A provided [onEnd] callback is called whenever an animation completes. +/// Registering an [onEnd] callback my be useful to trigger an action (like +/// another animation) at the end of the current animation. +/// +/// ## Performance optimizations +/// +/// If your [builder] function contains a subtree that does not depend on the +/// animation, it's more efficient to build that subtree once instead of +/// rebuilding it on every animation tick. +/// +/// If you pass the pre-built subtree as the [child] parameter, the +/// AnimatedBuilder will pass it back to your builder function so that you +/// can incorporate it into your build. +/// +/// Using this pre-built child is entirely optional, but can improve +/// performance significantly in some cases and is therefore a good practice. +/// +/// ## Ownership of the [Tween] +/// +/// The [TweenAnimationBuilder] takes full ownership of the provided [tween] +/// instance and it will mutate it. Once a [Tween] has been passed to a +/// [TweenAnimationBuilder], its properties should not be accessed or changed +/// anymore to avoid interference with the [TweenAnimationBuilder]. +/// +/// It is good practice to never store a [Tween] provided to a +/// [TweenAnimationBuilder] in an instance variable to avoid accidental +/// modifications of the [Tween]. +/// +/// ## Example Code +/// +/// {@tool dartpad} +/// This example shows an [IconButton] that "zooms" in when the widget first +/// builds (its size smoothly increases from 0 to 24) and whenever the button +/// is pressed, it smoothly changes its size to the new target value of either +/// 48 or 24. +/// +/// ** See code in examples/api/lib/widgets/tween_animation_builder/tween_animation_builder.0.dart ** +/// {@end-tool} +/// +/// ## Relationship to [ImplicitlyAnimatedWidget]s and [AnimatedWidget]s +/// +/// The [ImplicitlyAnimatedWidget] has many subclasses that provide animated +/// versions of regular widgets. These subclasses (like [AnimatedOpacity], +/// [AnimatedContainer], [AnimatedSize], etc.) animate changes in their +/// properties smoothly and they are easier to use than this general-purpose +/// builder. However, [TweenAnimationBuilder] (which itself is a subclass of +/// [ImplicitlyAnimatedWidget]) is handy for animating any widget property to a +/// given target value even when the framework (or third-party widget library) +/// doesn't ship with an animated version of that widget. +/// +/// Those [ImplicitlyAnimatedWidget]s (including this [TweenAnimationBuilder]) +/// all manage an internal [AnimationController] to drive the animation. If you +/// want more control over the animation than just setting a target value, +/// [duration], and [curve], have a look at (subclasses of) [AnimatedWidget]s. +/// For those, you have to manually manage an [AnimationController] giving you +/// full control over the animation. An example of an [AnimatedWidget] is the +/// [AnimatedBuilder], which can be used similarly to this +/// [TweenAnimationBuilder], but unlike the latter it is powered by a +/// developer-managed [AnimationController]. +class TweenAnimationBuilder<T extends Object?> extends ImplicitlyAnimatedWidget { + /// Creates a [TweenAnimationBuilder]. + /// + /// The [TweenAnimationBuilder] takes full ownership of the provided [tween] + /// instance and mutates it. Once a [Tween] has been passed to a + /// [TweenAnimationBuilder], its properties should not be accessed or changed + /// anymore to avoid interference with the [TweenAnimationBuilder]. + const TweenAnimationBuilder({ + super.key, + required this.tween, + required super.duration, + super.curve, + required this.builder, + super.onEnd, + this.child, + }); + + /// Defines the target value for the animation. + /// + /// When the widget first builds, the animation runs from [Tween.begin] to + /// [Tween.end], if [Tween.begin] is non-null. A new animation can be + /// triggered at anytime by providing a new [Tween] with a new [Tween.end] + /// value. The new animation runs from the current animation value (which may + /// be [Tween.end] of the old [tween], if that animation completed) to + /// [Tween.end] of the new [tween]. The [Tween.begin] value is ignored except + /// for the initial animation that is triggered when the widget builds for the + /// first time. + /// + /// Any (subclass of) [Tween] is accepted as an argument. For example, to + /// animate the height or width of a [Widget], use a [Tween<double>], or + /// check out the [ColorTween] to animate the color property of a [Widget]. + /// + /// Any [Tween] provided must have a non-null [Tween.end] value. + /// + /// ## Ownership + /// + /// The [TweenAnimationBuilder] takes full ownership of the provided [Tween] + /// and it will mutate the [Tween]. Once a [Tween] instance has been passed + /// to [TweenAnimationBuilder] its properties should not be accessed or + /// changed anymore to avoid any interference with the + /// [TweenAnimationBuilder]. If you need to change the [Tween], create a + /// **new instance** with the new values. + /// + /// It is good practice to never store a [Tween] provided to a + /// [TweenAnimationBuilder] in an instance variable to avoid accidental + /// modifications of the [Tween]. + final Tween<T> tween; + + /// Called every time the animation value changes. + /// + /// The current animation value is passed to the builder along with the + /// [child]. The builder should build a [Widget] based on the current + /// animation value and incorporate the [child] into it, if it is non-null. + final ValueWidgetBuilder<T> builder; + + /// The child widget to pass to the builder. + /// + /// If a builder callback's return value contains a subtree that does not + /// depend on the animation, it's more efficient to build that subtree once + /// instead of rebuilding it on every animation tick. + /// + /// If the pre-built subtree is passed as the child parameter, the + /// [TweenAnimationBuilder] will pass it back to the [builder] function so + /// that it can be incorporated into the build. + /// + /// Using this pre-built child is entirely optional, but can improve + /// performance significantly in some cases and is therefore a good practice. + final Widget? child; + + @override + ImplicitlyAnimatedWidgetState<ImplicitlyAnimatedWidget> createState() { + return _TweenAnimationBuilderState<T>(); + } +} + +class _TweenAnimationBuilderState<T extends Object?> extends AnimatedWidgetBaseState<TweenAnimationBuilder<T>> { + Tween<T>? _currentTween; + + @override + void initState() { + _currentTween = widget.tween; + _currentTween!.begin ??= _currentTween!.end; + super.initState(); + if (_currentTween!.begin != _currentTween!.end) { + controller.forward(); + } + } + + @override + void forEachTween(TweenVisitor<dynamic> visitor) { + assert( + widget.tween.end != null, + 'Tween provided to TweenAnimationBuilder must have non-null Tween.end value.', + ); + _currentTween = visitor(_currentTween, widget.tween.end, (dynamic value) { + assert(false); + throw StateError('Constructor will never be called because null is never provided as current tween.'); + }) as Tween<T>?; + } + + @override + Widget build(BuildContext context) { + return widget.builder(context, _currentTween!.evaluate(animation), widget.child); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/two_dimensional_scroll_view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/two_dimensional_scroll_view.dart new file mode 100644 index 0000000000000000000000000000000000000000..b5a38bec6c6e9395e9714001c8a0fed43aa9c4a6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/two_dimensional_scroll_view.dart @@ -0,0 +1,206 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/gestures.dart'; +import 'package:flutter/rendering.dart'; + +import 'focus_manager.dart'; +import 'focus_scope.dart'; +import 'framework.dart'; +import 'notification_listener.dart'; +import 'primary_scroll_controller.dart'; +import 'scroll_controller.dart'; +import 'scroll_delegate.dart'; +import 'scroll_notification.dart'; +import 'scroll_physics.dart'; +import 'scroll_view.dart'; +import 'scrollable.dart'; +import 'scrollable_helpers.dart'; +import 'two_dimensional_viewport.dart'; + +/// A widget that combines a [TwoDimensionalScrollable] and a +/// [TwoDimensionalViewport] to create an interactive scrolling pane of content +/// in both vertical and horizontal dimensions. +/// +/// A two-way scrollable widget consist of three pieces: +/// +/// 1. A [TwoDimensionalScrollable] widget, which listens for various user +/// gestures and implements the interaction design for scrolling. +/// 2. A [TwoDimensionalViewport] widget, which implements the visual design +/// for scrolling by displaying only a portion +/// of the widgets inside the scroll view. +/// 3. A [TwoDimensionalChildDelegate], which provides the children visible in +/// the scroll view. +/// +/// [TwoDimensionalScrollView] helps orchestrate these pieces by creating the +/// [TwoDimensionalScrollable] and deferring to its subclass to implement +/// [buildViewport], which builds a subclass of [TwoDimensionalViewport]. The +/// [TwoDimensionalChildDelegate] is provided by the [delegate] parameter. +/// +/// A [TwoDimensionalScrollView] has two different [ScrollPosition]s, one for +/// each [Axis]. This means that there are also two unique [ScrollController]s +/// for these positions. To provide a ScrollController to access the +/// ScrollPosition, use the [ScrollableDetails.controller] property of the +/// associated axis that is provided to this scroll view. +abstract class TwoDimensionalScrollView extends StatelessWidget { + /// Creates a widget that scrolls in both dimensions. + /// + /// The [primary] argument is associated with the [mainAxis]. The main axis + /// [ScrollableDetails.controller] must be null if [primary] is configured for + /// that axis. If [primary] is true, the nearest [PrimaryScrollController] + /// surrounding the widget is attached to the scroll position of that axis. + const TwoDimensionalScrollView({ + super.key, + this.primary, + this.mainAxis = Axis.vertical, + this.verticalDetails = const ScrollableDetails.vertical(), + this.horizontalDetails = const ScrollableDetails.horizontal(), + required this.delegate, + this.cacheExtent, + this.diagonalDragBehavior = DiagonalDragBehavior.none, + this.dragStartBehavior = DragStartBehavior.start, + this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, + this.clipBehavior = Clip.hardEdge, + }); + + /// A delegate that provides the children for the [TwoDimensionalScrollView]. + final TwoDimensionalChildDelegate delegate; + + /// {@macro flutter.rendering.RenderViewportBase.cacheExtent} + final double? cacheExtent; + + /// Whether scrolling gestures should lock to one axes, allow free movement + /// in both axes, or be evaluated on a weighted scale. + /// + /// Defaults to [DiagonalDragBehavior.none], locking axes to receive input one + /// at a time. + final DiagonalDragBehavior diagonalDragBehavior; + + /// {@macro flutter.widgets.scroll_view.primary} + final bool? primary; + + /// The main axis of the two. + /// + /// Used to determine how to apply [primary] when true. + /// + /// This value should also be provided to the subclass of + /// [TwoDimensionalViewport], where it is used to determine paint order of + /// children. + final Axis mainAxis; + + /// The configuration of the vertical Scrollable. + /// + /// These [ScrollableDetails] can be used to set the [AxisDirection], + /// [ScrollController], [ScrollPhysics] and more for the vertical axis. + final ScrollableDetails verticalDetails; + + /// The configuration of the horizontal Scrollable. + /// + /// These [ScrollableDetails] can be used to set the [AxisDirection], + /// [ScrollController], [ScrollPhysics] and more for the horizontal axis. + final ScrollableDetails horizontalDetails; + + /// {@macro flutter.widgets.scrollable.dragStartBehavior} + final DragStartBehavior dragStartBehavior; + + /// {@macro flutter.widgets.scroll_view.keyboardDismissBehavior} + final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// Build the two dimensional viewport. + /// + /// Subclasses may override this method to change how the viewport is built, + /// likely a subclass of [TwoDimensionalViewport]. + /// + /// The `verticalOffset` and `horizontalOffset` arguments are the values + /// obtained from [TwoDimensionalScrollable.viewportBuilder]. + Widget buildViewport( + BuildContext context, + ViewportOffset verticalOffset, + ViewportOffset horizontalOffset, + ); + + @override + Widget build(BuildContext context) { + assert( + axisDirectionToAxis(verticalDetails.direction) == Axis.vertical, + 'TwoDimensionalScrollView.verticalDetails are not Axis.vertical.' + ); + assert( + axisDirectionToAxis(horizontalDetails.direction) == Axis.horizontal, + 'TwoDimensionalScrollView.horizontalDetails are not Axis.horizontal.' + ); + + ScrollableDetails mainAxisDetails = switch (mainAxis) { + Axis.vertical => verticalDetails, + Axis.horizontal => horizontalDetails, + }; + + final bool effectivePrimary = primary + ?? mainAxisDetails.controller == null && PrimaryScrollController.shouldInherit( + context, + mainAxis, + ); + + if (effectivePrimary) { + // Using PrimaryScrollController for mainAxis. + assert( + mainAxisDetails.controller == null, + 'TwoDimensionalScrollView.primary was explicitly set to true, but a ' + 'ScrollController was provided in the ScrollableDetails of the ' + 'TwoDimensionalScrollView.mainAxis.' + ); + mainAxisDetails = mainAxisDetails.copyWith( + controller: PrimaryScrollController.of(context), + ); + } + + final TwoDimensionalScrollable scrollable = TwoDimensionalScrollable( + horizontalDetails : switch (mainAxis) { + Axis.horizontal => mainAxisDetails, + Axis.vertical => horizontalDetails, + }, + verticalDetails: switch (mainAxis) { + Axis.vertical => mainAxisDetails, + Axis.horizontal => verticalDetails, + }, + diagonalDragBehavior: diagonalDragBehavior, + viewportBuilder: buildViewport, + dragStartBehavior: dragStartBehavior, + ); + + final Widget scrollableResult = effectivePrimary + // Further descendant ScrollViews will not inherit the same PrimaryScrollController + ? PrimaryScrollController.none(child: scrollable) + : scrollable; + + if (keyboardDismissBehavior == ScrollViewKeyboardDismissBehavior.onDrag) { + return NotificationListener<ScrollUpdateNotification>( + child: scrollableResult, + onNotification: (ScrollUpdateNotification notification) { + final FocusScopeNode focusScope = FocusScope.of(context); + if (notification.dragDetails != null && focusScope.hasFocus) { + focusScope.unfocus(); + } + return false; + }, + ); + } + return scrollableResult; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<Axis>('mainAxis', mainAxis)); + properties.add(EnumProperty<DiagonalDragBehavior>('diagonalDragBehavior', diagonalDragBehavior)); + properties.add(FlagProperty('primary', value: primary, ifTrue: 'using primary controller', showName: true)); + properties.add(DiagnosticsProperty<ScrollableDetails>('verticalDetails', verticalDetails, showName: false)); + properties.add(DiagnosticsProperty<ScrollableDetails>('horizontalDetails', horizontalDetails, showName: false)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/two_dimensional_viewport.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/two_dimensional_viewport.dart new file mode 100644 index 0000000000000000000000000000000000000000..f2781728652e550463b765c5c4304c471381d0cc --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/two_dimensional_viewport.dart @@ -0,0 +1,1834 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/animation.dart'; +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; +import 'scroll_delegate.dart'; +import 'scroll_notification.dart'; +import 'scroll_position.dart'; + +export 'package:flutter/rendering.dart' show AxisDirection; + +// Examples can assume: +// late final RenderBox child; +// late final BoxConstraints constraints; +// class RenderSimpleTwoDimensionalViewport extends RenderTwoDimensionalViewport { +// RenderSimpleTwoDimensionalViewport({ +// required super.horizontalOffset, +// required super.horizontalAxisDirection, +// required super.verticalOffset, +// required super.verticalAxisDirection, +// required super.delegate, +// required super.mainAxis, +// required super.childManager, +// super.cacheExtent, +// super.clipBehavior = Clip.hardEdge, +// }); +// @override +// void layoutChildSequence() { } +// } + +/// Signature for a function that creates a widget for a given [ChildVicinity], +/// e.g., in a [TwoDimensionalScrollView], but may return null. +/// +/// Used by [TwoDimensionalChildBuilderDelegate.builder] and other APIs that +/// use lazily-generated widgets where the child count may not be known +/// ahead of time. +/// +/// Unlike most builders, this callback can return null, indicating the +/// [ChildVicinity.xIndex] or [ChildVicinity.yIndex] is out of range. Whether +/// and when this is valid depends on the semantics of the builder. For example, +/// [TwoDimensionalChildBuilderDelegate.builder] returns +/// null when one or both of the indices is out of range, where the range is +/// defined by the [TwoDimensionalChildBuilderDelegate.maxXIndex] or +/// [TwoDimensionalChildBuilderDelegate.maxYIndex]; so in that case the +/// vicinity values may determine whether returning null is valid or not. +/// +/// See also: +/// +/// * [WidgetBuilder], which is similar but only takes a [BuildContext]. +/// * [NullableIndexedWidgetBuilder], which is similar but may return null. +/// * [IndexedWidgetBuilder], which is similar but not nullable. +typedef TwoDimensionalIndexedWidgetBuilder = Widget? Function(BuildContext context, ChildVicinity vicinity); + +/// A widget through which a portion of larger content can be viewed, typically +/// in combination with a [TwoDimensionalScrollable]. +/// +/// [TwoDimensionalViewport] is the visual workhorse of the two dimensional +/// scrolling machinery. It displays a subset of its children according to its +/// own dimensions and the given [horizontalOffset] an [verticalOffset]. As the +/// offsets vary, different children are visible through the viewport. +/// +/// Subclasses must implement [createRenderObject] and [updateRenderObject]. +/// Both of these methods require the render object to be a subclass of +/// [RenderTwoDimensionalViewport]. This class will create its own +/// [RenderObjectElement] which already implements the +/// [TwoDimensionalChildManager], which means subclasses should cast the +/// [BuildContext] to provide as the child manager to the +/// [RenderTwoDimensionalViewport]. +/// +/// {@tool snippet} +/// This is an example of a subclass implementation of [TwoDimensionalViewport], +/// `SimpleTwoDimensionalViewport`. The `RenderSimpleTwoDimensionalViewport` is +/// a subclass of [RenderTwoDimensionalViewport]. +/// +/// ```dart +/// class SimpleTwoDimensionalViewport extends TwoDimensionalViewport { +/// const SimpleTwoDimensionalViewport({ +/// super.key, +/// required super.verticalOffset, +/// required super.verticalAxisDirection, +/// required super.horizontalOffset, +/// required super.horizontalAxisDirection, +/// required super.delegate, +/// required super.mainAxis, +/// super.cacheExtent, +/// super.clipBehavior = Clip.hardEdge, +/// }); +/// +/// @override +/// RenderSimpleTwoDimensionalViewport createRenderObject(BuildContext context) { +/// return RenderSimpleTwoDimensionalViewport( +/// horizontalOffset: horizontalOffset, +/// horizontalAxisDirection: horizontalAxisDirection, +/// verticalOffset: verticalOffset, +/// verticalAxisDirection: verticalAxisDirection, +/// mainAxis: mainAxis, +/// delegate: delegate, +/// childManager: context as TwoDimensionalChildManager, +/// cacheExtent: cacheExtent, +/// clipBehavior: clipBehavior, +/// ); +/// } +/// +/// @override +/// void updateRenderObject(BuildContext context, RenderSimpleTwoDimensionalViewport renderObject) { +/// renderObject +/// ..horizontalOffset = horizontalOffset +/// ..horizontalAxisDirection = horizontalAxisDirection +/// ..verticalOffset = verticalOffset +/// ..verticalAxisDirection = verticalAxisDirection +/// ..mainAxis = mainAxis +/// ..delegate = delegate +/// ..cacheExtent = cacheExtent +/// ..clipBehavior = clipBehavior; +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [Viewport], the equivalent of this widget that scrolls in only one +/// dimension. +abstract class TwoDimensionalViewport extends RenderObjectWidget { + /// Creates a viewport for [RenderBox] objects that extend and scroll in both + /// horizontal and vertical dimensions. + /// + /// The viewport listens to the [horizontalOffset] and [verticalOffset], which + /// means this widget does not need to be rebuilt when the offsets change. + const TwoDimensionalViewport({ + super.key, + required this.verticalOffset, + required this.verticalAxisDirection, + required this.horizontalOffset, + required this.horizontalAxisDirection, + required this.delegate, + required this.mainAxis, + this.cacheExtent, + this.clipBehavior = Clip.hardEdge, + }) : assert( + verticalAxisDirection == AxisDirection.down || verticalAxisDirection == AxisDirection.up, + 'TwoDimensionalViewport.verticalAxisDirection is not Axis.vertical.' + ), + assert( + horizontalAxisDirection == AxisDirection.left || horizontalAxisDirection == AxisDirection.right, + 'TwoDimensionalViewport.horizontalAxisDirection is not Axis.horizontal.' + ); + + /// Which part of the content inside the viewport should be visible in the + /// vertical axis. + /// + /// The [ViewportOffset.pixels] value determines the scroll offset that the + /// viewport uses to select which part of its content to display. As the user + /// scrolls the viewport vertically, this value changes, which changes the + /// content that is displayed. + /// + /// Typically a [ScrollPosition]. + final ViewportOffset verticalOffset; + + /// The direction in which the [verticalOffset]'s [ViewportOffset.pixels] + /// increases. + /// + /// For example, if the axis direction is [AxisDirection.down], a scroll + /// offset of zero is at the top of the viewport and increases towards the + /// bottom of the viewport. + /// + /// Must be either [AxisDirection.down] or [AxisDirection.up] in correlation + /// with an [Axis.vertical]. + final AxisDirection verticalAxisDirection; + + /// Which part of the content inside the viewport should be visible in the + /// horizontal axis. + /// + /// The [ViewportOffset.pixels] value determines the scroll offset that the + /// viewport uses to select which part of its content to display. As the user + /// scrolls the viewport horizontally, this value changes, which changes the + /// content that is displayed. + /// + /// Typically a [ScrollPosition]. + final ViewportOffset horizontalOffset; + + /// The direction in which the [horizontalOffset]'s [ViewportOffset.pixels] + /// increases. + /// + /// For example, if the axis direction is [AxisDirection.right], a scroll + /// offset of zero is at the left of the viewport and increases towards the + /// right of the viewport. + /// + /// Must be either [AxisDirection.left] or [AxisDirection.right] in correlation + /// with an [Axis.horizontal]. + final AxisDirection horizontalAxisDirection; + + /// The main axis of the two. + /// + /// Used to determine the paint order of the children of the viewport. When + /// the main axis is [Axis.vertical], children will be painted in row major + /// order, according to their associated [ChildVicinity]. When the main axis + /// is [Axis.horizontal], the children will be painted in column major order. + final Axis mainAxis; + + /// {@macro flutter.rendering.RenderViewportBase.cacheExtent} + final double? cacheExtent; + + /// {@macro flutter.material.Material.clipBehavior} + final Clip clipBehavior; + + /// A delegate that provides the children for the [TwoDimensionalViewport]. + final TwoDimensionalChildDelegate delegate; + + @override + RenderObjectElement createElement() => _TwoDimensionalViewportElement(this); + + @override + RenderTwoDimensionalViewport createRenderObject(BuildContext context); + + @override + void updateRenderObject(BuildContext context, RenderTwoDimensionalViewport renderObject); +} + +class _TwoDimensionalViewportElement extends RenderObjectElement + with NotifiableElementMixin, ViewportElementMixin implements TwoDimensionalChildManager { + _TwoDimensionalViewportElement(super.widget); + + @override + RenderTwoDimensionalViewport get renderObject => super.renderObject as RenderTwoDimensionalViewport; + + // Contains all children, including those that are keyed. + Map<ChildVicinity, Element> _vicinityToChild = <ChildVicinity, Element>{}; + Map<Key, Element> _keyToChild = <Key, Element>{}; + // Used between _startLayout() & _endLayout() to compute the new values for + // _vicinityToChild and _keyToChild. + Map<ChildVicinity, Element>? _newVicinityToChild; + Map<Key, Element>? _newKeyToChild; + + @override + void performRebuild() { + super.performRebuild(); + // Children list is updated during layout since we only know during layout + // which children will be visible. + renderObject.markNeedsLayout(withDelegateRebuild: true); + } + + @override + void forgetChild(Element child) { + assert(!_debugIsDoingLayout); + super.forgetChild(child); + _vicinityToChild.remove(child.slot); + if (child.widget.key != null) { + _keyToChild.remove(child.widget.key); + } + } + + @override + void insertRenderObjectChild(RenderBox child, ChildVicinity slot) { + renderObject._insertChild(child, slot); + } + + @override + void moveRenderObjectChild(RenderBox child, ChildVicinity oldSlot, ChildVicinity newSlot) { + renderObject._moveChild(child, from: oldSlot, to: newSlot); + } + + @override + void removeRenderObjectChild(RenderBox child, ChildVicinity slot) { + renderObject._removeChild(child, slot); + } + + @override + void visitChildren(ElementVisitor visitor) { + _vicinityToChild.values.forEach(visitor); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<Element> children = _vicinityToChild.values.toList()..sort(_compareChildren); + return <DiagnosticsNode>[ + for (final Element child in children) + child.toDiagnosticsNode(name: child.slot.toString()) + ]; + } + + static int _compareChildren(Element a, Element b) { + final ChildVicinity aSlot = a.slot! as ChildVicinity; + final ChildVicinity bSlot = b.slot! as ChildVicinity; + return aSlot.compareTo(bSlot); + } + + // ---- ChildManager implementation ---- + + bool get _debugIsDoingLayout => _newKeyToChild != null && _newVicinityToChild != null; + + @override + void _startLayout() { + assert(!_debugIsDoingLayout); + _newVicinityToChild = <ChildVicinity, Element>{}; + _newKeyToChild = <Key, Element>{}; + } + + @override + void _buildChild(ChildVicinity vicinity) { + assert(_debugIsDoingLayout); + owner!.buildScope(this, () { + final Widget? newWidget = (widget as TwoDimensionalViewport).delegate.build(this, vicinity); + if (newWidget == null) { + return; + } + final Element? oldElement = _retrieveOldElement(newWidget, vicinity); + final Element? newChild = updateChild(oldElement, newWidget, vicinity); + assert(newChild != null); + // Ensure we are not overwriting an existing child. + assert(_newVicinityToChild![vicinity] == null); + _newVicinityToChild![vicinity] = newChild!; + if (newWidget.key != null) { + // Ensure we are not overwriting an existing key + assert(_newKeyToChild![newWidget.key!] == null); + _newKeyToChild![newWidget.key!] = newChild; + } + }); + } + + Element? _retrieveOldElement(Widget newWidget, ChildVicinity vicinity) { + if (newWidget.key != null) { + final Element? result = _keyToChild.remove(newWidget.key); + if (result != null) { + _vicinityToChild.remove(result.slot); + } + return result; + } + final Element? potentialOldElement = _vicinityToChild[vicinity]; + if (potentialOldElement != null && potentialOldElement.widget.key == null) { + return _vicinityToChild.remove(vicinity); + } + return null; + } + + @override + void _reuseChild(ChildVicinity vicinity) { + assert(_debugIsDoingLayout); + final Element? elementToReuse = _vicinityToChild.remove(vicinity); + assert( + elementToReuse != null, + 'Expected to re-use an element at $vicinity, but none was found.' + ); + _newVicinityToChild![vicinity] = elementToReuse!; + if (elementToReuse.widget.key != null) { + assert(_keyToChild.containsKey(elementToReuse.widget.key)); + assert(_keyToChild[elementToReuse.widget.key] == elementToReuse); + _newKeyToChild![elementToReuse.widget.key!] = _keyToChild.remove(elementToReuse.widget.key)!; + } + } + + @override + void _endLayout() { + assert(_debugIsDoingLayout); + + // Unmount all elements that have not been reused in the layout cycle. + for (final Element element in _vicinityToChild.values) { + if (element.widget.key == null) { + // If it has a key, we handle it below. + updateChild(element, null, null); + } else { + assert(_keyToChild.containsValue(element)); + } + } + for (final Element element in _keyToChild.values) { + assert(element.widget.key != null); + updateChild(element, null, null); + } + + _vicinityToChild = _newVicinityToChild!; + _keyToChild = _newKeyToChild!; + _newVicinityToChild = null; + _newKeyToChild = null; + assert(!_debugIsDoingLayout); + } +} + +/// Parent data structure used by [RenderTwoDimensionalViewport]. +/// +/// The parent data primarily describes where a child is in the viewport. The +/// [layoutOffset] must be set by subclasses of [RenderTwoDimensionalViewport], +/// during [RenderTwoDimensionalViewport.layoutChildSequence] which represents +/// the position of the child in the viewport. +/// +/// The [paintOffset] is computed by [RenderTwoDimensionalViewport] after +/// [RenderTwoDimensionalViewport.layoutChildSequence]. If subclasses of +/// RenderTwoDimensionalViewport override the paint method, the [paintOffset] +/// should be used to position the child in the viewport in order to account for +/// a reversed [AxisDirection] in one or both dimensions. +class TwoDimensionalViewportParentData extends ParentData with KeepAliveParentDataMixin { + /// The offset at which to paint the child in the parent's coordinate system. + /// + /// This [Offset] represents the top left corner of the child of the + /// [TwoDimensionalViewport]. + /// + /// This value must be set by implementors during + /// [RenderTwoDimensionalViewport.layoutChildSequence]. After the method is + /// complete, the [RenderTwoDimensionalViewport] will compute the + /// [paintOffset] based on this value to account for the [AxisDirection]. + Offset? layoutOffset; + + /// The logical positioning of children in two dimensions. + /// + /// While children may not be strictly laid out in rows and columns, the + /// relative positioning determines traversal of + /// children in row or column major format. + /// + /// This is set in the [RenderTwoDimensionalViewport.buildOrObtainChildFor]. + ChildVicinity vicinity = ChildVicinity.invalid; + + /// Whether or not the child is actually visible within the viewport. + /// + /// For example, if a child is contained within the + /// [RenderTwoDimensionalViewport.cacheExtent] and out of view. + /// + /// This is used during [RenderTwoDimensionalViewport.paint] in order to skip + /// painting children that cannot be seen. + bool get isVisible { + assert(() { + if (_paintExtent == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('The paint extent of the child has not been determined yet.'), + ErrorDescription( + 'The paint extent, and therefore the visibility, of a child of a ' + 'RenderTwoDimensionalViewport is computed after ' + 'RenderTwoDimensionalViewport.layoutChildSequence.' + ), + ]); + } + return true; + }()); + return _paintExtent != Size.zero || _paintExtent!.height != 0.0 || _paintExtent!.width != 0.0; + } + + /// Represents the extent in both dimensions of the child that is actually + /// visible. + /// + /// For example, if a child [RenderBox] had a height of 100 pixels, and a + /// width of 100 pixels, but was scrolled to positions such that only 50 + /// pixels of both width and height were visible, the paintExtent would be + /// represented as `Size(50.0, 50.0)`. + /// + /// This is set in [RenderTwoDimensionalViewport.updateChildPaintData]. + Size? _paintExtent; + + /// The previous sibling in the parent's child list according to the traversal + /// order specified by [RenderTwoDimensionalViewport.mainAxis]. + RenderBox? _previousSibling; + + /// The next sibling in the parent's child list according to the traversal + /// order specified by [RenderTwoDimensionalViewport.mainAxis]. + RenderBox? _nextSibling; + + /// The position of the child relative to the bounds and [AxisDirection] of + /// the viewport. + /// + /// This is the distance from the top left visible corner of the parent to the + /// top left visible corner of the child. When the [AxisDirection]s are + /// [AxisDirection.down] or [AxisDirection.right], this value is the same as + /// the [layoutOffset]. This value deviates when scrolling in the reverse + /// directions of [AxisDirection.up] and [AxisDirection.left] to reposition + /// the children correctly. + /// + /// This is set in [RenderTwoDimensionalViewport.updateChildPaintData], after + /// [RenderTwoDimensionalViewport.layoutChildSequence]. + /// + /// If overriding [RenderTwoDimensionalViewport.paint], use this value to + /// position the children instead of [layoutOffset]. + Offset? paintOffset; + + @override + bool get keptAlive => keepAlive && !isVisible; + + @override + String toString() { + return 'vicinity=$vicinity; ' + 'layoutOffset=$layoutOffset; ' + 'paintOffset=$paintOffset; ' + '${_paintExtent == null + ? 'not visible; ' + : '${!isVisible ? 'not ' : ''}visible - paintExtent=$_paintExtent; '}' + '${keepAlive ? "keepAlive; " : ""}'; + } +} + +/// A base class for viewing render objects that scroll in two dimensions. +/// +/// The viewport listens to two [ViewportOffset]s, which determines the +/// visible content. +/// +/// Subclasses must implement [layoutChildSequence], calling on +/// [buildOrObtainChildFor] to manage the children of the viewport. +/// +/// Subclasses should not override [performLayout], as it handles housekeeping +/// on either side of the call to [layoutChildSequence]. +abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderAbstractViewport { + /// Initializes fields for subclasses. + /// + /// The [cacheExtent], if null, defaults to + /// [RenderAbstractViewport.defaultCacheExtent]. + RenderTwoDimensionalViewport({ + required ViewportOffset horizontalOffset, + required AxisDirection horizontalAxisDirection, + required ViewportOffset verticalOffset, + required AxisDirection verticalAxisDirection, + required TwoDimensionalChildDelegate delegate, + required Axis mainAxis, + required TwoDimensionalChildManager childManager, + double? cacheExtent, + Clip clipBehavior = Clip.hardEdge, + }) : assert( + verticalAxisDirection == AxisDirection.down || verticalAxisDirection == AxisDirection.up, + 'TwoDimensionalViewport.verticalAxisDirection is not Axis.vertical.' + ), + assert( + horizontalAxisDirection == AxisDirection.left || horizontalAxisDirection == AxisDirection.right, + 'TwoDimensionalViewport.horizontalAxisDirection is not Axis.horizontal.' + ), + _childManager = childManager, + _horizontalOffset = horizontalOffset, + _horizontalAxisDirection = horizontalAxisDirection, + _verticalOffset = verticalOffset, + _verticalAxisDirection = verticalAxisDirection, + _delegate = delegate, + _mainAxis = mainAxis, + _cacheExtent = cacheExtent ?? RenderAbstractViewport.defaultCacheExtent, + _clipBehavior = clipBehavior { + assert(() { + _debugDanglingKeepAlives = <RenderBox>[]; + return true; + }()); + } + + /// Which part of the content inside the viewport should be visible in the + /// horizontal axis. + /// + /// The [ViewportOffset.pixels] value determines the scroll offset that the + /// viewport uses to select which part of its content to display. As the user + /// scrolls the viewport horizontally, this value changes, which changes the + /// content that is displayed. + /// + /// Typically a [ScrollPosition]. + ViewportOffset get horizontalOffset => _horizontalOffset; + ViewportOffset _horizontalOffset; + set horizontalOffset(ViewportOffset value) { + if (_horizontalOffset == value) { + return; + } + if (attached) { + _horizontalOffset.removeListener(markNeedsLayout); + } + _horizontalOffset = value; + if (attached) { + _horizontalOffset.addListener(markNeedsLayout); + } + markNeedsLayout(); + } + + /// The direction in which the [horizontalOffset] increases. + /// + /// For example, if the axis direction is [AxisDirection.right], a scroll + /// offset of zero is at the left of the viewport and increases towards the + /// right of the viewport. + AxisDirection get horizontalAxisDirection => _horizontalAxisDirection; + AxisDirection _horizontalAxisDirection; + set horizontalAxisDirection(AxisDirection value) { + if (_horizontalAxisDirection == value) { + return; + } + _horizontalAxisDirection = value; + markNeedsLayout(); + } + + /// Which part of the content inside the viewport should be visible in the + /// vertical axis. + /// + /// The [ViewportOffset.pixels] value determines the scroll offset that the + /// viewport uses to select which part of its content to display. As the user + /// scrolls the viewport vertically, this value changes, which changes the + /// content that is displayed. + /// + /// Typically a [ScrollPosition]. + ViewportOffset get verticalOffset => _verticalOffset; + ViewportOffset _verticalOffset; + set verticalOffset(ViewportOffset value) { + if (_verticalOffset == value) { + return; + } + if (attached) { + _verticalOffset.removeListener(markNeedsLayout); + } + _verticalOffset = value; + if (attached) { + _verticalOffset.addListener(markNeedsLayout); + } + markNeedsLayout(); + } + + /// The direction in which the [verticalOffset] increases. + /// + /// For example, if the axis direction is [AxisDirection.down], a scroll + /// offset of zero is at the top the viewport and increases towards the + /// bottom of the viewport. + AxisDirection get verticalAxisDirection => _verticalAxisDirection; + AxisDirection _verticalAxisDirection; + set verticalAxisDirection(AxisDirection value) { + if (_verticalAxisDirection == value) { + return; + } + _verticalAxisDirection = value; + markNeedsLayout(); + } + + /// Supplies children for layout in the viewport. + TwoDimensionalChildDelegate get delegate => _delegate; + TwoDimensionalChildDelegate _delegate; + set delegate(covariant TwoDimensionalChildDelegate value) { + if (_delegate == value) { + return; + } + if (attached) { + _delegate.removeListener(_handleDelegateNotification); + } + final TwoDimensionalChildDelegate oldDelegate = _delegate; + _delegate = value; + if (attached) { + _delegate.addListener(_handleDelegateNotification); + } + if (_delegate.runtimeType != oldDelegate.runtimeType || _delegate.shouldRebuild(oldDelegate)) { + _handleDelegateNotification(); + } + } + + /// The major axis of the two dimensions. + /// + /// This is can be used by subclasses to determine paint order, + /// visitor patterns like row and column major ordering, or hit test + /// precedence. + /// + /// See also: + /// + /// * [TwoDimensionalScrollView], which assigns the [PrimaryScrollController] + /// to the [TwoDimensionalScrollView.mainAxis] and shares this value. + Axis get mainAxis => _mainAxis; + Axis _mainAxis; + set mainAxis(Axis value) { + if (_mainAxis == value) { + return; + } + _mainAxis = value; + // Child order needs to be resorted, which happens in performLayout. + markNeedsLayout(); + } + + /// {@macro flutter.rendering.RenderViewportBase.cacheExtent} + double get cacheExtent => _cacheExtent ?? RenderAbstractViewport.defaultCacheExtent; + double? _cacheExtent; + set cacheExtent(double? value) { + if (_cacheExtent == value) { + return; + } + _cacheExtent = value; + markNeedsLayout(); + } + + /// {@macro flutter.material.Material.clipBehavior} + Clip get clipBehavior => _clipBehavior; + Clip _clipBehavior; + set clipBehavior(Clip value) { + if (_clipBehavior == value) { + return; + } + _clipBehavior = value; + markNeedsPaint(); + markNeedsSemanticsUpdate(); + } + + final TwoDimensionalChildManager _childManager; + final Map<ChildVicinity, RenderBox> _children = <ChildVicinity, RenderBox>{}; + /// Children that have been laid out (or re-used) during the course of + /// performLayout, used to update the keep alive bucket at the end of + /// performLayout. + final Map<ChildVicinity, RenderBox> _activeChildrenForLayoutPass = <ChildVicinity, RenderBox>{}; + /// The nodes being kept alive despite not being visible. + final Map<ChildVicinity, RenderBox> _keepAliveBucket = <ChildVicinity, RenderBox>{}; + + late List<RenderBox> _debugDanglingKeepAlives; + + bool _hasVisualOverflow = false; + final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>(); + + @override + bool get isRepaintBoundary => true; + + @override + bool get sizedByParent => true; + + // Keeps track of the upper and lower bounds of ChildVicinity indices when + // subclasses call buildOrObtainChildFor during layoutChildSequence. These + // values are used to sort children in accordance with the mainAxis for + // paint order. + int? _leadingXIndex; + int? _trailingXIndex; + int? _leadingYIndex; + int? _trailingYIndex; + + /// The first child of the viewport according to the traversal order of the + /// [mainAxis]. + /// + /// {@template flutter.rendering.twoDimensionalViewport.paintOrder} + /// The [mainAxis] correlates with the [ChildVicinity] of each child to paint + /// the children in a row or column major order. + /// + /// By default, the [mainAxis] is [Axis.vertical], which would result in a + /// row major paint order, visiting children in the horizontal indices before + /// advancing to the next vertical index. + /// {@endtemplate} + /// + /// This value is null during [layoutChildSequence] as children are reified + /// into the correct order after layout is completed. This can be used when + /// overriding [paint] in order to paint the children in the correct order. + RenderBox? get firstChild => _firstChild; + RenderBox? _firstChild; + + /// The last child in the viewport according to the traversal order of the + /// [mainAxis]. + /// + /// {@macro flutter.rendering.twoDimensionalViewport.paintOrder} + /// + /// This value is null during [layoutChildSequence] as children are reified + /// into the correct order after layout is completed. This can be used when + /// overriding [paint] in order to paint the children in the correct order. + RenderBox? get lastChild => _lastChild; + RenderBox? _lastChild; + + /// The previous child before the given child in the child list according to + /// the traversal order of the [mainAxis]. + /// + /// {@macro flutter.rendering.twoDimensionalViewport.paintOrder} + /// + /// This method is useful when overriding [paint] in order to paint children + /// in the correct order. + RenderBox? childBefore(RenderBox child) { + assert(child.parent == this); + return parentDataOf(child)._previousSibling; + } + + /// The next child after the given child in the child list according to + /// the traversal order of the [mainAxis]. + /// + /// {@macro flutter.rendering.twoDimensionalViewport.paintOrder} + /// + /// This method is useful when overriding [paint] in order to paint children + /// in the correct order. + RenderBox? childAfter(RenderBox child) { + assert(child.parent == this); + return parentDataOf(child)._nextSibling; + } + + void _handleDelegateNotification() { + return markNeedsLayout(withDelegateRebuild: true); + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! TwoDimensionalViewportParentData) { + child.parentData = TwoDimensionalViewportParentData(); + } + } + + /// Convenience method for retrieving and casting the [ParentData] of the + /// viewport's children. + /// + /// Children must have a [ParentData] of type + /// [TwoDimensionalViewportParentData], or a subclass thereof. + @protected + TwoDimensionalViewportParentData parentDataOf(RenderBox child) { + assert(_children.containsValue(child)); + return child.parentData! as TwoDimensionalViewportParentData; + } + + /// Returns the active child located at the provided [ChildVicinity], if there + /// is one. + /// + /// This can be used by subclasses to access currently active children to make + /// use of their size or [TwoDimensionalViewportParentData], such as when + /// overriding the [paint] method. + /// + /// Returns null if there is no active child for the given [ChildVicinity]. + @protected + RenderBox? getChildFor(ChildVicinity vicinity) => _children[vicinity]; + + @override + void attach(PipelineOwner owner) { + super.attach(owner); + _horizontalOffset.addListener(markNeedsLayout); + _verticalOffset.addListener(markNeedsLayout); + _delegate.addListener(_handleDelegateNotification); + for (final RenderBox child in _children.values) { + child.attach(owner); + } + for (final RenderBox child in _keepAliveBucket.values) { + child.attach(owner); + } + } + + @override + void detach() { + super.detach(); + _horizontalOffset.removeListener(markNeedsLayout); + _verticalOffset.removeListener(markNeedsLayout); + _delegate.removeListener(_handleDelegateNotification); + for (final RenderBox child in _children.values) { + child.detach(); + } + for (final RenderBox child in _keepAliveBucket.values) { + child.detach(); + } + } + + @override + void redepthChildren() { + for (final RenderBox child in _children.values) { + child.redepthChildren(); + } + _keepAliveBucket.values.forEach(redepthChild); + } + + @override + void visitChildren(RenderObjectVisitor visitor) { + RenderBox? child = _firstChild; + while (child != null) { + visitor(child); + child = parentDataOf(child)._nextSibling; + } + _keepAliveBucket.values.forEach(visitor); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + // Only children that are visible should be visited, and they must be in + // paint order. + RenderBox? child = _firstChild; + while (child != null) { + final TwoDimensionalViewportParentData childParentData = parentDataOf(child); + visitor(child); + child = childParentData._nextSibling; + } + // Do not visit children in [_keepAliveBucket]. + } + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<DiagnosticsNode> debugChildren = <DiagnosticsNode>[ + ..._children.keys.map<DiagnosticsNode>((ChildVicinity vicinity) { + return _children[vicinity]!.toDiagnosticsNode(name: vicinity.toString()); + }) + ]; + return debugChildren; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + assert(debugCheckHasBoundedAxis(Axis.vertical, constraints)); + assert(debugCheckHasBoundedAxis(Axis.horizontal, constraints)); + return constraints.biggest; + } + + @override + bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { + for (final RenderBox child in _children.values) { + final TwoDimensionalViewportParentData childParentData = parentDataOf(child); + if (!childParentData.isVisible) { + // Can't hit a child that is not visible. + continue; + } + final bool isHit = result.addWithPaintOffset( + offset: childParentData.paintOffset, + position: position, + hitTest: (BoxHitTestResult result, Offset transformed) { + assert(transformed == position - childParentData.paintOffset!); + return child.hitTest(result, position: transformed); + }, + ); + if (isHit) { + return true; + } + } + return false; + } + + /// The dimensions of the viewport. + /// + /// This [Size] represents the width and height of the visible area. + Size get viewportDimension { + assert(hasSize); + return size; + } + + @override + void performResize() { + final Size? oldSize = hasSize ? size : null; + super.performResize(); + // Ignoring return value since we are doing a layout either way + // (performLayout will be invoked next). + horizontalOffset.applyViewportDimension(size.width); + verticalOffset.applyViewportDimension(size.height); + if (oldSize != size) { + // Specs can depend on viewport size. + _didResize = true; + } + } + + @protected + @override + RevealedOffset getOffsetToReveal( + RenderObject target, + double alignment, { + Rect? rect, + Axis? axis, + }) { + // If an axis has not been specified, use the mainAxis. + axis ??= mainAxis; + + final (double offset, AxisDirection axisDirection) = switch (axis) { + Axis.vertical => (verticalOffset.pixels, verticalAxisDirection), + Axis.horizontal => (horizontalOffset.pixels, horizontalAxisDirection), + }; + + rect ??= target.paintBounds; + // `child` will be the last RenderObject before the viewport when walking + // up from `target`. + RenderObject child = target; + while (child.parent != this) { + child = child.parent!; + } + + assert(child.parent == this); + final RenderBox box = child as RenderBox; + final Rect rectLocal = MatrixUtils.transformRect(target.getTransformTo(child), rect); + + final double targetMainAxisExtent; + double leadingScrollOffset = offset; + // The scroll offset of `rect` within `child`. + switch (axisDirection) { + case AxisDirection.up: + leadingScrollOffset += child.size.height - rectLocal.bottom; + targetMainAxisExtent = rectLocal.height; + case AxisDirection.right: + leadingScrollOffset += rectLocal.left; + targetMainAxisExtent = rectLocal.width; + case AxisDirection.down: + leadingScrollOffset += rectLocal.top; + targetMainAxisExtent = rectLocal.height; + case AxisDirection.left: + leadingScrollOffset += child.size.width - rectLocal.right; + targetMainAxisExtent = rectLocal.width; + } + + // The scroll offset in the viewport to `rect`. + final TwoDimensionalViewportParentData childParentData = parentDataOf(box); + leadingScrollOffset += switch (axisDirection) { + AxisDirection.down => childParentData.paintOffset!.dy, + AxisDirection.up => viewportDimension.height - childParentData.paintOffset!.dy - box.size.height, + AxisDirection.right => childParentData.paintOffset!.dx, + AxisDirection.left => viewportDimension.width - childParentData.paintOffset!.dx - box.size.width, + }; + + // This step assumes the viewport's layout is up-to-date, i.e., if + // the position is changed after the last performLayout, the new scroll + // position will not be accounted for. + final Matrix4 transform = target.getTransformTo(this); + Rect targetRect = MatrixUtils.transformRect(transform, rect); + + final double mainAxisExtent = switch (axisDirectionToAxis(axisDirection)) { + Axis.horizontal => viewportDimension.width, + Axis.vertical => viewportDimension.height, + }; + + final double targetOffset = leadingScrollOffset - (mainAxisExtent - targetMainAxisExtent) * alignment; + + final double offsetDifference = switch (axisDirectionToAxis(axisDirection)){ + Axis.vertical => verticalOffset.pixels - targetOffset, + Axis.horizontal => horizontalOffset.pixels - targetOffset, + }; + switch (axisDirection) { + case AxisDirection.down: + targetRect = targetRect.translate(0.0, offsetDifference); + case AxisDirection.right: + targetRect = targetRect.translate(offsetDifference, 0.0); + case AxisDirection.up: + targetRect = targetRect.translate(0.0, -offsetDifference); + case AxisDirection.left: + targetRect = targetRect.translate(-offsetDifference, 0.0); + } + + final RevealedOffset revealedOffset = RevealedOffset( + offset: targetOffset, + rect: targetRect, + ); + return revealedOffset; + } + + @override + void showOnScreen({ + RenderObject? descendant, + Rect? rect, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + }) { + // It is possible for one and not both axes to allow for implicit scrolling, + // so handling is split between the options for allowed implicit scrolling. + final bool allowHorizontal = horizontalOffset.allowImplicitScrolling; + final bool allowVertical = verticalOffset.allowImplicitScrolling; + AxisDirection? axisDirection; + switch ((allowHorizontal, allowVertical)) { + case (true, true): + // Both allow implicit scrolling. + break; + case (false, true): + // Only the vertical Axis allows implicit scrolling. + axisDirection = verticalAxisDirection; + case (true, false): + // Only the horizontal Axis allows implicit scrolling. + axisDirection = horizontalAxisDirection; + case (false, false): + // Neither axis allows for implicit scrolling. + return super.showOnScreen( + descendant: descendant, + rect: rect, + duration: duration, + curve: curve, + ); + } + + final Rect? newRect = RenderTwoDimensionalViewport.showInViewport( + descendant: descendant, + viewport: this, + axisDirection: axisDirection, + rect: rect, + duration: duration, + curve: curve, + ); + + super.showOnScreen( + rect: newRect, + duration: duration, + curve: curve, + ); + } + + /// Make (a portion of) the given `descendant` of the given `viewport` fully + /// visible in one or both dimensions of the `viewport` by manipulating the + /// [ViewportOffset]s. + /// + /// The `axisDirection` determines from which axes the `descendant` will be + /// revealed. When the `axisDirection` is null, both axes will be updated to + /// reveal the descendant. + /// + /// The optional `rect` parameter describes which area of the `descendant` + /// should be shown in the viewport. If `rect` is null, the entire + /// `descendant` will be revealed. The `rect` parameter is interpreted + /// relative to the coordinate system of `descendant`. + /// + /// The returned [Rect] describes the new location of `descendant` or `rect` + /// in the viewport after it has been revealed. See [RevealedOffset.rect] + /// for a full definition of this [Rect]. + /// + /// The parameter `viewport` is required and cannot be null. If `descendant` + /// is null, this is a no-op and `rect` is returned. + /// + /// If both `descendant` and `rect` are null, null is returned because there + /// is nothing to be shown in the viewport. + /// + /// The `duration` parameter can be set to a non-zero value to animate the + /// target object into the viewport with an animation defined by `curve`. + /// + /// See also: + /// + /// * [RenderObject.showOnScreen], overridden by + /// [RenderTwoDimensionalViewport] to delegate to this method. + static Rect? showInViewport({ + RenderObject? descendant, + Rect? rect, + required RenderTwoDimensionalViewport viewport, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + AxisDirection? axisDirection, + }) { + if (descendant == null) { + return rect; + } + + Rect? showVertical(Rect? rect) { + return RenderTwoDimensionalViewport._showInViewportForAxisDirection( + descendant: descendant, + viewport: viewport, + axis: Axis.vertical, + rect: rect, + duration: duration, + curve: curve, + ); + } + + Rect? showHorizontal(Rect? rect) { + return RenderTwoDimensionalViewport._showInViewportForAxisDirection( + descendant: descendant, + viewport: viewport, + axis: Axis.horizontal, + rect: rect, + duration: duration, + curve: curve, + ); + } + + switch (axisDirection) { + case AxisDirection.left: + case AxisDirection.right: + return showHorizontal(rect); + case AxisDirection.up: + case AxisDirection.down: + return showVertical(rect); + case null: + // Update rect after revealing in one axis before revealing in the next. + rect = showHorizontal(rect) ?? rect; + // We only return the final rect after both have been revealed. + rect = showVertical(rect); + if (rect == null) { + // `descendant` is between leading and trailing edge and hence already + // fully shown on screen. + assert(viewport.parent != null); + final Matrix4 transform = descendant.getTransformTo(viewport.parent); + return MatrixUtils.transformRect( + transform, + rect ?? descendant.paintBounds, + ); + } + return rect; + } + } + + static Rect? _showInViewportForAxisDirection({ + required RenderObject descendant, + Rect? rect, + required RenderTwoDimensionalViewport viewport, + required Axis axis, + Duration duration = Duration.zero, + Curve curve = Curves.ease, + }) { + final ViewportOffset offset = switch (axis) { + Axis.vertical => viewport.verticalOffset, + Axis.horizontal => viewport.horizontalOffset, + }; + + final RevealedOffset leadingEdgeOffset = viewport.getOffsetToReveal( + descendant, + 0.0, + rect: rect, + axis: axis, + ); + final RevealedOffset trailingEdgeOffset = viewport.getOffsetToReveal( + descendant, + 1.0, + rect: rect, + axis: axis, + ); + final double currentOffset = offset.pixels; + + final RevealedOffset? targetOffset = RevealedOffset.clampOffset( + leadingEdgeOffset: leadingEdgeOffset, + trailingEdgeOffset: trailingEdgeOffset, + currentOffset: currentOffset, + ); + if (targetOffset == null) { + // Already visible in this axis. + return null; + } + + offset.moveTo(targetOffset.offset, duration: duration, curve: curve); + return targetOffset.rect; + } + + /// Should be used by subclasses to invalidate any cached metrics for the + /// viewport. + /// + /// This is set to true when the viewport has been resized, indicating that + /// any cached dimensions are invalid. + /// + /// After performLayout, the value is set to false until the viewport + /// dimensions are changed again in [performResize]. + /// + /// Subclasses are not required to use this value, but it can be used to + /// safely cache layout information in between layout calls. + bool get didResize => _didResize; + bool _didResize = true; + + /// Should be used by subclasses to invalidate any cached data from the + /// [delegate]. + /// + /// This value is set to false after [layoutChildSequence]. If + /// [markNeedsLayout] is called `withDelegateRebuild` set to true, then this + /// value will be updated to true, signifying any cached delegate information + /// needs to be updated in the next call to [layoutChildSequence]. + /// + /// Subclasses are not required to use this value, but it can be used to + /// safely cache layout information in between layout calls. + @protected + bool get needsDelegateRebuild => _needsDelegateRebuild; + bool _needsDelegateRebuild = true; + + @override + void markNeedsLayout({ bool withDelegateRebuild = false }) { + _needsDelegateRebuild = _needsDelegateRebuild || withDelegateRebuild; + super.markNeedsLayout(); + } + + /// Primary work horse of [performLayout]. + /// + /// Subclasses must implement this method to layout the children of the + /// viewport. The [TwoDimensionalViewportParentData.layoutOffset] must be set + /// during this method in order for the children to be positioned during paint. + /// Further, children of the viewport must be laid out with the expectation + /// that the parent (this viewport) will use their size. + /// + /// ```dart + /// child.layout(constraints, parentUsesSize: true); + /// ``` + /// + /// The primary methods used for creating and obtaining children is + /// [buildOrObtainChildFor], which takes a [ChildVicinity] that is used by the + /// [TwoDimensionalChildDelegate]. If a child is not provided by the delegate + /// for the provided vicinity, the method will return null, otherwise, it will + /// return the [RenderBox] of the child. + /// + /// After [layoutChildSequence] is completed, any remaining children that were + /// not obtained will be disposed. + void layoutChildSequence(); + + @override + void performLayout() { + _firstChild = null; + _lastChild = null; + _activeChildrenForLayoutPass.clear(); + _childManager._startLayout(); + + // Subclass lays out children. + layoutChildSequence(); + + assert(_debugCheckContentDimensions()); + _didResize = false; + _needsDelegateRebuild = false; + _cacheKeepAlives(); + invokeLayoutCallback<BoxConstraints>((BoxConstraints _) { + _childManager._endLayout(); + assert(_debugOrphans?.isEmpty ?? true); + assert(_debugDanglingKeepAlives.isEmpty); + // Ensure we are not keeping anything alive that should not be any longer. + assert(_keepAliveBucket.values.where((RenderBox child) { + return !parentDataOf(child).keepAlive; + }).isEmpty); + // Organize children in paint order and complete parent data after + // un-used children are disposed of by the childManager. + _reifyChildren(); + }); + } + + void _cacheKeepAlives() { + final List<RenderBox> remainingChildren = _children.values.toSet().difference( + _activeChildrenForLayoutPass.values.toSet() + ).toList(); + for (final RenderBox child in remainingChildren) { + final TwoDimensionalViewportParentData childParentData = parentDataOf(child); + if (childParentData.keepAlive) { + _keepAliveBucket[childParentData.vicinity] = child; + // Let the child manager know we intend to keep this. + _childManager._reuseChild(childParentData.vicinity); + } + } + } + + // Ensures all children have a layoutOffset, sets paintExtent & paintOffset, + // and arranges children in paint order. + void _reifyChildren() { + assert(_leadingXIndex != null); + assert(_trailingXIndex != null); + assert(_leadingYIndex != null); + assert(_trailingYIndex != null); + assert(_firstChild == null); + assert(_lastChild == null); + RenderBox? previousChild; + switch (mainAxis) { + case Axis.vertical: + // Row major traversal. + // This seems backwards, but the vertical axis is the typical default + // axis for scrolling in Flutter, while Row-major ordering is the + // typical default for matrices, which is why the inverse follows + // through in the horizontal case below. + // Minor + for (int minorIndex = _leadingYIndex!; minorIndex <= _trailingYIndex!; minorIndex++) { + // Major + for (int majorIndex = _leadingXIndex!; majorIndex <= _trailingXIndex!; majorIndex++) { + final ChildVicinity vicinity = ChildVicinity(xIndex: majorIndex, yIndex: minorIndex); + previousChild = _completeChildParentData( + vicinity, + previousChild: previousChild, + ) ?? previousChild; + } + } + case Axis.horizontal: + // Column major traversal + // Minor + for (int minorIndex = _leadingXIndex!; minorIndex <= _trailingXIndex!; minorIndex++) { + // Major + for (int majorIndex = _leadingYIndex!; majorIndex <= _trailingYIndex!; majorIndex++) { + final ChildVicinity vicinity = ChildVicinity(xIndex: minorIndex, yIndex: majorIndex); + previousChild = _completeChildParentData( + vicinity, + previousChild: previousChild, + ) ?? previousChild; + } + } + } + _lastChild = previousChild; + parentDataOf(_lastChild!)._nextSibling = null; + // Reset for next layout pass. + _leadingXIndex = null; + _trailingXIndex = null; + _leadingYIndex = null; + _trailingYIndex = null; + } + + RenderBox? _completeChildParentData(ChildVicinity vicinity, { RenderBox? previousChild }) { + assert(vicinity != ChildVicinity.invalid); + // It is possible and valid for a vicinity to be skipped. + // For example, a table can have merged cells, spanning multiple + // indices, but only represented by one RenderBox and ChildVicinity. + if (_children.containsKey(vicinity)) { + final RenderBox child = _children[vicinity]!; + assert(parentDataOf(child).vicinity == vicinity); + updateChildPaintData(child); + if (previousChild == null) { + // _firstChild is only set once. + assert(_firstChild == null); + _firstChild = child; + } else { + parentDataOf(previousChild)._nextSibling = child; + parentDataOf(child)._previousSibling = previousChild; + } + return child; + } + return null; + } + + bool _debugCheckContentDimensions() { + const String hint = 'Subclasses should call applyContentDimensions on the ' + 'verticalOffset and horizontalOffset to set the min and max scroll offset. ' + 'If the contents exceed one or both sides of the viewportDimension, ' + 'ensure the viewportDimension height or width is subtracted in that axis ' + 'for the correct extent.'; + assert(() { + if (!(verticalOffset as ScrollPosition).hasContentDimensions) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'The verticalOffset was not given content dimensions during ' + 'layoutChildSequence.' + ), + ErrorHint(hint), + ]); + } + return true; + }()); + assert(() { + if (!(horizontalOffset as ScrollPosition).hasContentDimensions) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'The horizontalOffset was not given content dimensions during ' + 'layoutChildSequence.' + ), + ErrorHint(hint), + ]); + } + return true; + }()); + return true; + } + + /// Returns the child for a given [ChildVicinity], should be called during + /// [layoutChildSequence] in order to instantiate or retrieve children. + /// + /// This method will build the child if it has not been already, or will reuse + /// it if it already exists, whether it was part of the previous frame or kept + /// alive. + /// + /// Children for the given [ChildVicinity] will be inserted into the active + /// children list, and so should be visible, or contained within the + /// [cacheExtent]. + RenderBox? buildOrObtainChildFor(ChildVicinity vicinity) { + assert(vicinity != ChildVicinity.invalid); + // This should only be called during layout. + assert(debugDoingThisLayout); + if (_leadingXIndex == null || _trailingXIndex == null || _leadingXIndex == null || _trailingYIndex == null) { + // First child of this layout pass. Set leading and trailing trackers. + _leadingXIndex = vicinity.xIndex; + _trailingXIndex = vicinity.xIndex; + _leadingYIndex = vicinity.yIndex; + _trailingYIndex = vicinity.yIndex; + } else { + // If any of these are still null, we missed a child. + assert(_leadingXIndex != null); + assert(_trailingXIndex != null); + assert(_leadingYIndex != null); + assert(_trailingYIndex != null); + + // Update as we go. + _leadingXIndex = math.min(vicinity.xIndex, _leadingXIndex!); + _trailingXIndex = math.max(vicinity.xIndex, _trailingXIndex!); + _leadingYIndex = math.min(vicinity.yIndex, _leadingYIndex!); + _trailingYIndex = math.max(vicinity.yIndex, _trailingYIndex!); + } + if (_needsDelegateRebuild || (!_children.containsKey(vicinity) && !_keepAliveBucket.containsKey(vicinity))) { + invokeLayoutCallback<BoxConstraints>((BoxConstraints _) { + _childManager._buildChild(vicinity); + }); + } else { + _keepAliveBucket.remove(vicinity); + _childManager._reuseChild(vicinity); + } + if (!_children.containsKey(vicinity)) { + // There is no child for this vicinity, we may have reached the end of the + // children in one or both of the x/y indices. + return null; + } + + assert(_children.containsKey(vicinity)); + final RenderBox child = _children[vicinity]!; + _activeChildrenForLayoutPass[vicinity] = child; + parentDataOf(child).vicinity = vicinity; + return child; + } + + /// Called after [layoutChildSequence] to compute the + /// [TwoDimensionalViewportParentData.paintOffset] and + /// [TwoDimensionalViewportParentData._paintExtent] of the child. + void updateChildPaintData(RenderBox child) { + final TwoDimensionalViewportParentData childParentData = parentDataOf(child); + assert( + childParentData.layoutOffset != null, + 'The child with ChildVicinity(xIndex: ${childParentData.vicinity.xIndex}, ' + 'yIndex: ${childParentData.vicinity.yIndex}) was not provided a ' + 'layoutOffset. This should be set during layoutChildSequence, ' + 'representing the position of the child.' + ); + assert(child.hasSize); // Child must have been laid out by now. + + // Set paintExtent (and visibility) + childParentData._paintExtent = computeChildPaintExtent( + childParentData.layoutOffset!, + child.size, + ); + // Set paintOffset + childParentData.paintOffset = computeAbsolutePaintOffsetFor( + child, + layoutOffset: childParentData.layoutOffset!, + ); + // If the child is partially visible, or not visible at all, there is + // visual overflow. + _hasVisualOverflow = _hasVisualOverflow + || childParentData.layoutOffset != childParentData._paintExtent + || !childParentData.isVisible; + } + + /// Computes the portion of the child that is visible, assuming that only the + /// region from the [ViewportOffset.pixels] of both dimensions to the + /// [cacheExtent] is visible, and that the relationship between scroll offsets + /// and paint offsets is linear. + /// + /// For example, if the [ViewportOffset]s each have a scroll offset of 100 and + /// the arguments to this method describe a child with [layoutOffset] of + /// `Offset(50.0, 50.0)`, with a size of `Size(200.0, 200.0)`, then the + /// returned value would be `Size(150.0, 150.0)`, representing the visible + /// extent of the child. + Size computeChildPaintExtent(Offset layoutOffset, Size childSize) { + if (childSize == Size.zero || childSize.height == 0.0 || childSize.width == 0.0) { + return Size.zero; + } + // Horizontal extent + final double width; + if (layoutOffset.dx < 0.0) { + // The child is positioned beyond the leading edge of the viewport. + if (layoutOffset.dx + childSize.width <= 0.0) { + // The child does not extend into the viewable area, it is not visible. + return Size.zero; + } + // If the child is positioned starting at -50, then the paint extent is + // the width + (-50). + width = layoutOffset.dx + childSize.width; + } else if (layoutOffset.dx >= viewportDimension.width) { + // The child is positioned after the trailing edge of the viewport, also + // not visible. + return Size.zero; + } else { + // The child is positioned within the viewport bounds, but may extend + // beyond it. + assert(layoutOffset.dx >= 0 && layoutOffset.dx < viewportDimension.width); + if (layoutOffset.dx + childSize.width > viewportDimension.width) { + width = viewportDimension.width - layoutOffset.dx; + } else { + assert(layoutOffset.dx + childSize.width <= viewportDimension.width); + width = childSize.width; + } + } + + // Vertical extent + final double height; + if (layoutOffset.dy < 0.0) { + // The child is positioned beyond the leading edge of the viewport. + if (layoutOffset.dy + childSize.height <= 0.0) { + // The child does not extend into the viewable area, it is not visible. + return Size.zero; + } + // If the child is positioned starting at -50, then the paint extent is + // the width + (-50). + height = layoutOffset.dy + childSize.height; + } else if (layoutOffset.dy >= viewportDimension.height) { + // The child is positioned after the trailing edge of the viewport, also + // not visible. + return Size.zero; + } else { + // The child is positioned within the viewport bounds, but may extend + // beyond it. + assert(layoutOffset.dy >= 0 && layoutOffset.dy < viewportDimension.height); + if (layoutOffset.dy + childSize.height > viewportDimension.height) { + height = viewportDimension.height - layoutOffset.dy; + } else { + assert(layoutOffset.dy + childSize.height <= viewportDimension.height); + height = childSize.height; + } + } + + return Size(width, height); + } + + /// The offset at which the given `child` should be painted. + /// + /// The returned offset is from the top left corner of the inside of the + /// viewport to the top left corner of the paint coordinate system of the + /// `child`. + /// + /// This is useful when the one or both of the axes of the viewport are + /// reversed. The normalized layout offset of the child is used to compute + /// the paint offset in relation to the [verticalAxisDirection] and + /// [horizontalAxisDirection]. + @protected + Offset computeAbsolutePaintOffsetFor( + RenderBox child, { + required Offset layoutOffset, + }) { + // This is only usable once we have sizes. + assert(hasSize); + assert(child.hasSize); + final double xOffset; + final double yOffset; + switch (verticalAxisDirection) { + case AxisDirection.up: + yOffset = viewportDimension.height - (layoutOffset.dy + child.size.height); + case AxisDirection.down: + yOffset = layoutOffset.dy; + case AxisDirection.right: + case AxisDirection.left: + throw Exception('This should not happen'); + } + switch (horizontalAxisDirection) { + case AxisDirection.right: + xOffset = layoutOffset.dx; + case AxisDirection.left: + xOffset = viewportDimension.width - (layoutOffset.dx + child.size.width); + case AxisDirection.up: + case AxisDirection.down: + throw Exception('This should not happen'); + } + return Offset(xOffset, yOffset); + } + + @override + void paint(PaintingContext context, Offset offset) { + if (_children.isEmpty) { + return; + } + if (_hasVisualOverflow && clipBehavior != Clip.none) { + _clipRectLayer.layer = context.pushClipRect( + needsCompositing, + offset, + Offset.zero & viewportDimension, + _paintChildren, + clipBehavior: clipBehavior, + oldLayer: _clipRectLayer.layer, + ); + } else { + _clipRectLayer.layer = null; + _paintChildren(context, offset); + } + } + + void _paintChildren(PaintingContext context, Offset offset) { + RenderBox? child = _firstChild; + while (child != null) { + final TwoDimensionalViewportParentData childParentData = parentDataOf(child); + if (childParentData.isVisible) { + context.paintChild(child, offset + childParentData.paintOffset!); + } + child = childParentData._nextSibling; + } + } + + // ---- Called from _TwoDimensionalViewportElement ---- + + void _insertChild(RenderBox child, ChildVicinity slot) { + assert(_debugTrackOrphans(newOrphan: _children[slot])); + assert(!_keepAliveBucket.containsValue(child)); + _children[slot] = child; + adoptChild(child); + } + + void _moveChild(RenderBox child, {required ChildVicinity from, required ChildVicinity to}) { + final TwoDimensionalViewportParentData childParentData = parentDataOf(child); + if (!childParentData.keptAlive) { + if (_children[from] == child) { + _children.remove(from); + } + assert(_debugTrackOrphans(newOrphan: _children[to], noLongerOrphan: child)); + _children[to] = child; + return; + } + // If the child in the bucket is not current child, that means someone has + // already moved and replaced current child, and we cannot remove this + // child. + if (_keepAliveBucket[childParentData.vicinity] == child) { + _keepAliveBucket.remove(childParentData.vicinity); + } + assert(() { + _debugDanglingKeepAlives.remove(child); + return true; + }()); + // If there is an existing child in the new slot, that mean that child + // will be moved to other index. In other cases, the existing child should + // have been removed by _removeChild. Thus, it is ok to overwrite it. + assert(() { + if (_keepAliveBucket.containsKey(childParentData.vicinity)) { + _debugDanglingKeepAlives.add(_keepAliveBucket[childParentData.vicinity]!); + } + return true; + }()); + _keepAliveBucket[childParentData.vicinity] = child; + } + + void _removeChild(RenderBox child, ChildVicinity slot) { + final TwoDimensionalViewportParentData childParentData = parentDataOf(child); + if (!childParentData.keptAlive) { + if (_children[slot] == child) { + _children.remove(slot); + } + assert(_debugTrackOrphans(noLongerOrphan: child)); + dropChild(child); + return; + } + assert(_keepAliveBucket[childParentData.vicinity] == child); + assert(() { + _debugDanglingKeepAlives.remove(child); + return true; + }()); + _keepAliveBucket.remove(childParentData.vicinity); + dropChild(child); + } + + List<RenderBox>? _debugOrphans; + + // When a child is inserted into a slot currently occupied by another child, + // it becomes an orphan until it is either moved to another slot or removed. + bool _debugTrackOrphans({RenderBox? newOrphan, RenderBox? noLongerOrphan}) { + assert(() { + _debugOrphans ??= <RenderBox>[]; + if (newOrphan != null) { + _debugOrphans!.add(newOrphan); + } + if (noLongerOrphan != null) { + _debugOrphans!.remove(noLongerOrphan); + } + return true; + }()); + return true; + } + + /// Throws an exception saying that the object does not support returning + /// intrinsic dimensions if, in debug mode, we are not in the + /// [RenderObject.debugCheckingIntrinsics] mode. + /// + /// This is used by [computeMinIntrinsicWidth] et al because viewports do not + /// generally support returning intrinsic dimensions. See the discussion at + /// [computeMinIntrinsicWidth]. + @protected + bool debugThrowIfNotCheckingIntrinsics() { + assert(() { + if (!RenderObject.debugCheckingIntrinsics) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary('$runtimeType does not support returning intrinsic dimensions.'), + ErrorDescription( + 'Calculating the intrinsic dimensions would require instantiating every child of ' + 'the viewport, which defeats the point of viewports being lazy.', + ), + ]); + } + return true; + }()); + return true; + } + + @override + double computeMinIntrinsicWidth(double height) { + assert(debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + double computeMaxIntrinsicWidth(double height) { + assert(debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + double computeMinIntrinsicHeight(double width) { + assert(debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + double computeMaxIntrinsicHeight(double width) { + assert(debugThrowIfNotCheckingIntrinsics()); + return 0.0; + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + final Offset paintOffset = parentDataOf(child).paintOffset!; + transform.translate(paintOffset.dx, paintOffset.dy); + } + + @override + void dispose() { + _clipRectLayer.layer = null; + super.dispose(); + } +} + +/// A delegate used by [RenderTwoDimensionalViewport] to manage its children. +/// +/// [RenderTwoDimensionalViewport] objects reify their children lazily to avoid +/// spending resources on children that are not visible in the viewport. This +/// delegate lets these objects create, reuse and remove children. +abstract class TwoDimensionalChildManager { + void _startLayout(); + void _buildChild(ChildVicinity vicinity); + void _reuseChild(ChildVicinity vicinity); + void _endLayout(); +} + +/// The relative position of a child in a [TwoDimensionalViewport] in relation +/// to other children of the viewport. +/// +/// While children can be plotted arbitrarily in two dimensional space, the +/// [ChildVicinity] is used to disambiguate their positions, determining how to +/// traverse the children of the space. +/// +/// Combined with the [RenderTwoDimensionalViewport.mainAxis], each child's +/// vicinity determines its paint order among all of the children. +@immutable +class ChildVicinity implements Comparable<ChildVicinity> { + /// Creates a reference to a child in a two dimensional plane, with the + /// [xIndex] and [yIndex] being relative to other children in the viewport. + const ChildVicinity({ + required this.xIndex, + required this.yIndex, + }) : assert(xIndex >= -1), + assert(yIndex >= -1); + + /// Represents an unassigned child position. The given child may be in the + /// process of moving from one position to another. + static const ChildVicinity invalid = ChildVicinity(xIndex: -1, yIndex: -1); + + /// The index of the child in the horizontal axis, relative to neighboring + /// children. + /// + /// While children's offset and positioning may not be strictly defined in + /// terms of rows and columns, like a table, [ChildVicinity.xIndex] and + /// [ChildVicinity.yIndex] represents order of traversal in row or column + /// major format. + final int xIndex; + + /// The index of the child in the vertical axis, relative to neighboring + /// children. + /// + /// While children's offset and positioning may not be strictly defined in + /// terms of rows and columns, like a table, [ChildVicinity.xIndex] and + /// [ChildVicinity.yIndex] represents order of traversal in row or column + /// major format. + final int yIndex; + + @override + bool operator ==(Object other) { + return other is ChildVicinity + && other.xIndex == xIndex + && other.yIndex == yIndex; + } + + @override + int get hashCode => Object.hash(xIndex, yIndex); + + @override + int compareTo(ChildVicinity other) { + if (xIndex == other.xIndex) { + return yIndex - other.yIndex; + } + return xIndex - other.xIndex; + } + + @override + String toString() { + return '(xIndex: $xIndex, yIndex: $yIndex)'; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/undo_history.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/undo_history.dart new file mode 100644 index 0000000000000000000000000000000000000000..ab37737cfcd70b50e60932293b9fcd84d86b4cf4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/undo_history.dart @@ -0,0 +1,497 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'actions.dart'; +import 'focus_manager.dart'; +import 'framework.dart'; +import 'text_editing_intents.dart'; + +/// Provides undo/redo capabilities for a [ValueNotifier]. +/// +/// Listens to [value] and saves relevant values for undoing/redoing. The +/// cadence at which values are saved is a best approximation of the native +/// behaviors of a number of hardware keyboard on Flutter's desktop +/// platforms, as there are subtle differences between each of the platforms. +/// +/// Listens to keyboard undo/redo shortcuts and calls [onTriggered] when a +/// shortcut is triggered that would affect the state of the [value]. +/// +/// The [child] must manage focus on the [focusNode]. For example, using a +/// [TextField] or [Focus] widget. +class UndoHistory<T> extends StatefulWidget { + /// Creates an instance of [UndoHistory]. + const UndoHistory({ + super.key, + this.shouldChangeUndoStack, + required this.value, + required this.onTriggered, + required this.focusNode, + this.undoStackModifier, + this.controller, + required this.child, + }); + + /// The value to track over time. + final ValueNotifier<T> value; + + /// Called when checking whether a value change should be pushed onto + /// the undo stack. + final bool Function(T? oldValue, T newValue)? shouldChangeUndoStack; + + /// Called right before a new entry is pushed to the undo stack. + /// + /// The value returned from this method will be pushed to the stack instead + /// of the original value. + /// + /// If null then the original value will always be pushed to the stack. + final T Function(T value)? undoStackModifier; + + /// Called when an undo or redo causes a state change. + /// + /// If the state would still be the same before and after the undo/redo, this + /// will not be called. For example, receiving a redo when there is nothing + /// to redo will not call this method. + /// + /// Changes to the [value] while this method is running will not be recorded + /// on the undo stack. For example, a [TextInputFormatter] may change the value + /// from what was on the undo stack, but this new value will not be recorded, + /// as that would wipe out the redo history. + final void Function(T value) onTriggered; + + /// The [FocusNode] that will be used to listen for focus to set the initial + /// undo state for the element. + final FocusNode focusNode; + + /// {@template flutter.widgets.undoHistory.controller} + /// Controls the undo state. + /// + /// If null, this widget will create its own [UndoHistoryController]. + /// {@endtemplate} + final UndoHistoryController? controller; + + /// The child widget of [UndoHistory]. + final Widget child; + + @override + State<UndoHistory<T>> createState() => UndoHistoryState<T>(); +} + +/// State for a [UndoHistory]. +/// +/// Provides [undo], [redo], [canUndo], and [canRedo] for programmatic access +/// to the undo state for custom undo and redo UI implementations. +@visibleForTesting +class UndoHistoryState<T> extends State<UndoHistory<T>> with UndoManagerClient { + final _UndoStack<T> _stack = _UndoStack<T>(); + late final _Throttled<T> _throttledPush; + Timer? _throttleTimer; + bool _duringTrigger = false; + + // This duration was chosen as a best fit for the behavior of Mac, Linux, + // and Windows undo/redo state save durations, but it is not perfect for any + // of them. + static const Duration _kThrottleDuration = Duration(milliseconds: 500); + + // Record the last value to prevent pushing multiple + // of the same value in a row onto the undo stack. For example, _push gets + // called both in initState and when the EditableText receives focus. + T? _lastValue; + + UndoHistoryController? _controller; + + UndoHistoryController get _effectiveController => widget.controller ?? (_controller ??= UndoHistoryController()); + + @override + void undo() { + if (_stack.currentValue == null) { + // Returns early if there is not a first value registered in the history. + // This is important because, if an undo is received while the initial + // value is being pushed (a.k.a when the field gets the focus but the + // throttling delay is pending), the initial push should not be canceled. + return; + } + if (_throttleTimer?.isActive ?? false) { + _throttleTimer?.cancel(); // Cancel ongoing push, if any. + _update(_stack.currentValue); + } else { + _update(_stack.undo()); + } + _updateState(); + } + + @override + void redo() { + _update(_stack.redo()); + _updateState(); + } + + @override + bool get canUndo => _stack.canUndo; + + @override + bool get canRedo => _stack.canRedo; + + void _updateState() { + _effectiveController.value = UndoHistoryValue(canUndo: canUndo, canRedo: canRedo); + + if (defaultTargetPlatform != TargetPlatform.iOS) { + return; + } + + if (UndoManager.client == this) { + UndoManager.setUndoState(canUndo: canUndo, canRedo: canRedo); + } + } + + void _undoFromIntent(UndoTextIntent intent) { + undo(); + } + + void _redoFromIntent(RedoTextIntent intent) { + redo(); + } + + void _update(T? nextValue) { + if (nextValue == null) { + return; + } + if (nextValue == _lastValue) { + return; + } + _lastValue = nextValue; + _duringTrigger = true; + try { + widget.onTriggered(nextValue); + assert(widget.value.value == nextValue); + } finally { + _duringTrigger = false; + } + } + + void _push() { + if (widget.value.value == _lastValue) { + return; + } + + if (_duringTrigger) { + return; + } + + if (!(widget.shouldChangeUndoStack?.call(_lastValue, widget.value.value) ?? true)) { + return; + } + + final T nextValue = widget.undoStackModifier?.call(widget.value.value) ?? widget.value.value; + if (nextValue == _lastValue) { + return; + } + + _lastValue = nextValue; + + _throttleTimer = _throttledPush(nextValue); + } + + void _handleFocus() { + if (!widget.focusNode.hasFocus) { + return; + } + UndoManager.client = this; + _updateState(); + } + + @override + void handlePlatformUndo(UndoDirection direction) { + switch (direction) { + case UndoDirection.undo: + undo(); + case UndoDirection.redo: + redo(); + } + } + + @override + void initState() { + super.initState(); + _throttledPush = _throttle<T>( + duration: _kThrottleDuration, + function: (T currentValue) { + _stack.push(currentValue); + _updateState(); + }, + ); + _push(); + widget.value.addListener(_push); + _handleFocus(); + widget.focusNode.addListener(_handleFocus); + _effectiveController.onUndo.addListener(undo); + _effectiveController.onRedo.addListener(redo); + } + + @override + void didUpdateWidget(UndoHistory<T> oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.value != oldWidget.value) { + _stack.clear(); + oldWidget.value.removeListener(_push); + widget.value.addListener(_push); + } + if (widget.focusNode != oldWidget.focusNode) { + oldWidget.focusNode.removeListener(_handleFocus); + widget.focusNode.addListener(_handleFocus); + } + if (widget.controller != oldWidget.controller) { + _effectiveController.onUndo.removeListener(undo); + _effectiveController.onRedo.removeListener(redo); + _controller?.dispose(); + _controller = null; + _effectiveController.onUndo.addListener(undo); + _effectiveController.onRedo.addListener(redo); + } + } + + @override + void dispose() { + widget.value.removeListener(_push); + widget.focusNode.removeListener(_handleFocus); + _effectiveController.onUndo.removeListener(undo); + _effectiveController.onRedo.removeListener(redo); + _controller?.dispose(); + _throttleTimer?.cancel(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Actions( + actions: <Type, Action<Intent>>{ + UndoTextIntent: Action<UndoTextIntent>.overridable(context: context, defaultAction: CallbackAction<UndoTextIntent>(onInvoke: _undoFromIntent)), + RedoTextIntent: Action<RedoTextIntent>.overridable(context: context, defaultAction: CallbackAction<RedoTextIntent>(onInvoke: _redoFromIntent)), + }, + child: widget.child, + ); + } +} + +/// Represents whether the current undo stack can undo or redo. +@immutable +class UndoHistoryValue { + /// Creates a value for whether the current undo stack can undo or redo. + /// + /// The [canUndo] and [canRedo] arguments must have a value, but default to + /// false. + const UndoHistoryValue({this.canUndo = false, this.canRedo = false}); + + /// A value corresponding to an undo stack that can neither undo nor redo. + static const UndoHistoryValue empty = UndoHistoryValue(); + + /// Whether the current undo stack can perform an undo operation. + final bool canUndo; + + /// Whether the current undo stack can perform a redo operation. + final bool canRedo; + + @override + String toString() => '${objectRuntimeType(this, 'UndoHistoryValue')}(canUndo: $canUndo, canRedo: $canRedo)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + return other is UndoHistoryValue && other.canUndo == canUndo && other.canRedo == canRedo; + } + + @override + int get hashCode => Object.hash( + canUndo.hashCode, + canRedo.hashCode, + ); +} + +/// A controller for the undo history, for example for an editable text field. +/// +/// Whenever a change happens to the underlying value that the [UndoHistory] +/// widget tracks, that widget updates the [value] and the controller notifies +/// it's listeners. Listeners can then read the canUndo and canRedo +/// properties of the value to discover whether [undo] or [redo] are possible. +/// +/// The controller also has [undo] and [redo] methods to modify the undo +/// history. +/// +/// {@tool dartpad} +/// This example creates a [TextField] with an [UndoHistoryController] +/// which provides undo and redo buttons. +/// +/// ** See code in examples/api/lib/widgets/undo_history/undo_history_controller.0.dart ** +/// {@end-tool} +/// +/// See also: +/// +/// * [EditableText], which uses the [UndoHistory] widget and allows +/// control of the underlying history using an [UndoHistoryController]. +class UndoHistoryController extends ValueNotifier<UndoHistoryValue> { + /// Creates a controller for an [UndoHistory] widget. + UndoHistoryController({UndoHistoryValue? value}) : super(value ?? UndoHistoryValue.empty); + + /// Notifies listeners that [undo] has been called. + final ChangeNotifier onUndo = ChangeNotifier(); + + /// Notifies listeners that [redo] has been called. + final ChangeNotifier onRedo = ChangeNotifier(); + + /// Reverts the value on the stack to the previous value. + void undo() { + if (!value.canUndo) { + return; + } + + onUndo.notifyListeners(); + } + + /// Updates the value on the stack to the next value. + void redo() { + if (!value.canRedo) { + return; + } + + onRedo.notifyListeners(); + } + + @override + void dispose() { + onUndo.dispose(); + onRedo.dispose(); + super.dispose(); + } +} + +/// A data structure representing a chronological list of states that can be +/// undone and redone. +class _UndoStack<T> { + /// Creates an instance of [_UndoStack]. + _UndoStack(); + + final List<T> _list = <T>[]; + + // The index of the current value, or -1 if the list is empty. + int _index = -1; + + /// Returns the current value of the stack. + T? get currentValue => _list.isEmpty ? null : _list[_index]; + + bool get canUndo => _list.isNotEmpty && _index > 0; + + bool get canRedo => _list.isNotEmpty && _index < _list.length - 1; + + /// Add a new state change to the stack. + /// + /// Pushing identical objects will not create multiple entries. + void push(T value) { + if (_list.isEmpty) { + _index = 0; + _list.add(value); + return; + } + + assert(_index < _list.length && _index >= 0); + + if (value == currentValue) { + return; + } + + // If anything has been undone in this stack, remove those irrelevant states + // before adding the new one. + if (_index != _list.length - 1) { + _list.removeRange(_index + 1, _list.length); + } + _list.add(value); + _index = _list.length - 1; + } + + /// Returns the current value after an undo operation. + /// + /// An undo operation moves the current value to the previously pushed value, + /// if any. + /// + /// Iff the stack is completely empty, then returns null. + T? undo() { + if (_list.isEmpty) { + return null; + } + + assert(_index < _list.length && _index >= 0); + + if (_index != 0) { + _index = _index - 1; + } + + return currentValue; + } + + /// Returns the current value after a redo operation. + /// + /// A redo operation moves the current value to the value that was last + /// undone, if any. + /// + /// Iff the stack is completely empty, then returns null. + T? redo() { + if (_list.isEmpty) { + return null; + } + + assert(_index < _list.length && _index >= 0); + + if (_index < _list.length - 1) { + _index = _index + 1; + } + + return currentValue; + } + + /// Remove everything from the stack. + void clear() { + _list.clear(); + _index = -1; + } + + @override + String toString() { + return '_UndoStack $_list'; + } +} + +/// A function that can be throttled with the throttle function. +typedef _Throttleable<T> = void Function(T currentArg); + +/// A function that has been throttled by [_throttle]. +typedef _Throttled<T> = Timer Function(T currentArg); + +/// Returns a _Throttled that will call through to the given function only a +/// maximum of once per duration. +/// +/// Only works for functions that take exactly one argument and return void. +_Throttled<T> _throttle<T>({ + required Duration duration, + required _Throttleable<T> function, +}) { + Timer? timer; + late T arg; + + return (T currentArg) { + arg = currentArg; + if (timer != null && timer!.isActive) { + return timer!; + } + timer = Timer(duration, () { + function(arg); + timer = null; + }); + return timer!; + }; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/unique_widget.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/unique_widget.dart new file mode 100644 index 0000000000000000000000000000000000000000..64688e4ac4b218f89045d5e448e023aeb481eb3f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/unique_widget.dart @@ -0,0 +1,39 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'framework.dart'; + +/// Base class for stateful widgets that have exactly one inflated instance in +/// the tree. +/// +/// Such widgets must be given a [GlobalKey]. This key can be generated by the +/// subclass from its [Type] object, e.g. by calling `super(key: new +/// GlobalObjectKey(MyWidget))` where `MyWidget` is the name of the subclass. +/// +/// Since only one instance can be inflated at a time, there is only ever one +/// corresponding [State] object. That object is exposed, for convenience, via +/// the [currentState] property. +/// +/// When subclassing [UniqueWidget], provide the corresponding [State] subclass +/// as the type argument. +abstract class UniqueWidget<T extends State<StatefulWidget>> extends StatefulWidget { + /// Creates a widget that has exactly one inflated instance in the tree. + /// + /// The [key] argument is required because it identifies the unique inflated + /// instance of this widget. + const UniqueWidget({ + required GlobalKey<T> key, + }) : super(key: key); + + @override + T createState(); + + /// The state for the unique inflated instance of this widget. + /// + /// Might be null if the widget is not currently in the tree. + T? get currentState { + final GlobalKey<T> globalKey = key! as GlobalKey<T>; + return globalKey.currentState; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/value_listenable_builder.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/value_listenable_builder.dart new file mode 100644 index 0000000000000000000000000000000000000000..0673fd2fd0c84af8902104e1bfd848cb7aee1832 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/value_listenable_builder.dart @@ -0,0 +1,183 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'framework.dart'; + +/// Builds a [Widget] when given a concrete value of a [ValueListenable<T>]. +/// +/// If the `child` parameter provided to the [ValueListenableBuilder] is not +/// null, the same `child` widget is passed back to this [ValueWidgetBuilder] +/// and should typically be incorporated in the returned widget tree. +/// +/// See also: +/// +/// * [ValueListenableBuilder], a widget which invokes this builder each time +/// a [ValueListenable] changes value. +typedef ValueWidgetBuilder<T> = Widget Function(BuildContext context, T value, Widget? child); + +/// A widget whose content stays synced with a [ValueListenable]. +/// +/// Given a [ValueListenable<T>] and a [builder] which builds widgets from +/// concrete values of `T`, this class will automatically register itself as a +/// listener of the [ValueListenable] and call the [builder] with updated values +/// when the value changes. +/// +/// {@youtube 560 315 https://www.youtube.com/watch?v=s-ZG-jS5QHQ} +/// +/// ## Performance optimizations +/// +/// If your [builder] function contains a subtree that does not depend on the +/// value of the [ValueListenable], it's more efficient to build that subtree +/// once instead of rebuilding it on every animation tick. +/// +/// If you pass the pre-built subtree as the [child] parameter, the +/// [ValueListenableBuilder] will pass it back to your [builder] function so +/// that you can incorporate it into your build. +/// +/// Using this pre-built child is entirely optional, but can improve +/// performance significantly in some cases and is therefore a good practice. +/// +/// {@tool snippet} +/// +/// This sample shows how you could use a [ValueListenableBuilder] instead of +/// setting state on the whole [Scaffold] in the default `flutter create` app. +/// +/// ```dart +/// class MyHomePage extends StatefulWidget { +/// const MyHomePage({super.key, required this.title}); +/// final String title; +/// +/// @override +/// State<MyHomePage> createState() => _MyHomePageState(); +/// } +/// +/// class _MyHomePageState extends State<MyHomePage> { +/// final ValueNotifier<int> _counter = ValueNotifier<int>(0); +/// final Widget goodJob = const Text('Good job!'); +/// @override +/// Widget build(BuildContext context) { +/// return Scaffold( +/// appBar: AppBar( +/// title: Text(widget.title) +/// ), +/// body: Center( +/// child: Column( +/// mainAxisAlignment: MainAxisAlignment.center, +/// children: <Widget>[ +/// const Text('You have pushed the button this many times:'), +/// ValueListenableBuilder<int>( +/// builder: (BuildContext context, int value, Widget? child) { +/// // This builder will only get called when the _counter +/// // is updated. +/// return Row( +/// mainAxisAlignment: MainAxisAlignment.spaceEvenly, +/// children: <Widget>[ +/// Text('$value'), +/// child!, +/// ], +/// ); +/// }, +/// valueListenable: _counter, +/// // The child parameter is most helpful if the child is +/// // expensive to build and does not depend on the value from +/// // the notifier. +/// child: goodJob, +/// ) +/// ], +/// ), +/// ), +/// floatingActionButton: FloatingActionButton( +/// child: const Icon(Icons.plus_one), +/// onPressed: () => _counter.value += 1, +/// ), +/// ); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [AnimatedBuilder], which also triggers rebuilds from a [Listenable] +/// without passing back a specific value from a [ValueListenable]. +/// * [NotificationListener], which lets you rebuild based on [Notification] +/// coming from its descendant widgets rather than a [ValueListenable] that +/// you have a direct reference to. +/// * [StreamBuilder], where a builder can depend on a [Stream] rather than +/// a [ValueListenable] for more advanced use cases. +class ValueListenableBuilder<T> extends StatefulWidget { + /// Creates a [ValueListenableBuilder]. + /// + /// The [child] is optional but is good practice to use if part of the widget + /// subtree does not depend on the value of the [valueListenable]. + const ValueListenableBuilder({ + super.key, + required this.valueListenable, + required this.builder, + this.child, + }); + + /// The [ValueListenable] whose value you depend on in order to build. + /// + /// This widget does not ensure that the [ValueListenable]'s value is not + /// null, therefore your [builder] may need to handle null values. + final ValueListenable<T> valueListenable; + + /// A [ValueWidgetBuilder] which builds a widget depending on the + /// [valueListenable]'s value. + /// + /// Can incorporate a [valueListenable] value-independent widget subtree + /// from the [child] parameter into the returned widget tree. + final ValueWidgetBuilder<T> builder; + + /// A [valueListenable]-independent widget which is passed back to the [builder]. + /// + /// This argument is optional and can be null if the entire widget subtree the + /// [builder] builds depends on the value of the [valueListenable]. For + /// example, in the case where the [valueListenable] is a [String] and the + /// [builder] returns a [Text] widget with the current [String] value, there + /// would be no useful [child]. + final Widget? child; + + @override + State<StatefulWidget> createState() => _ValueListenableBuilderState<T>(); +} + +class _ValueListenableBuilderState<T> extends State<ValueListenableBuilder<T>> { + late T value; + + @override + void initState() { + super.initState(); + value = widget.valueListenable.value; + widget.valueListenable.addListener(_valueChanged); + } + + @override + void didUpdateWidget(ValueListenableBuilder<T> oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.valueListenable != widget.valueListenable) { + oldWidget.valueListenable.removeListener(_valueChanged); + value = widget.valueListenable.value; + widget.valueListenable.addListener(_valueChanged); + } + } + + @override + void dispose() { + widget.valueListenable.removeListener(_valueChanged); + super.dispose(); + } + + void _valueChanged() { + setState(() { value = widget.valueListenable.value; }); + } + + @override + Widget build(BuildContext context) { + return widget.builder(context, value, widget.child); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/view.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/view.dart new file mode 100644 index 0000000000000000000000000000000000000000..ad7ab7f7aaffbcdc41261b5eb55492d6554e5b2c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/view.dart @@ -0,0 +1,743 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:ui' show FlutterView, SemanticsUpdate; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'framework.dart'; +import 'lookup_boundary.dart'; +import 'media_query.dart'; + +/// Bootstraps a render tree that is rendered into the provided [FlutterView]. +/// +/// The content rendered into that view is determined by the provided [child]. +/// Descendants within the same [LookupBoundary] can look up the view they are +/// rendered into via [View.of] and [View.maybeOf]. +/// +/// The provided [child] is wrapped in a [MediaQuery] constructed from the given +/// [view]. +/// +/// For most use cases, using [MediaQuery.of], or its associated "...Of" methods +/// are a more appropriate way of obtaining the information that a [FlutterView] +/// exposes. For example, using [MediaQuery.sizeOf] will expose the _logical_ +/// device size ([MediaQueryData.size]) rather than the physical size +/// ([FlutterView.physicalSize]). Similarly, while [FlutterView.padding] conveys +/// the information from the operating system, the [MediaQueryData.padding] +/// attribute (obtained from [MediaQuery.paddingOf]) further adjusts this +/// information to be aware of the context of the widget; e.g. the [Scaffold] +/// widget adjusts the values for its various children. +/// +/// Each [FlutterView] can be associated with at most one [View] widget in the +/// widget tree. Two or more [View] widgets configured with the same +/// [FlutterView] must never exist within the same widget tree at the same time. +/// This limitation is enforced by a [GlobalObjectKey] that derives its identity +/// from the [view] provided to this widget. +/// +/// Since the [View] widget bootstraps its own independent render tree, neither +/// it nor any of its descendants will insert a [RenderObject] into an existing +/// render tree. Therefore, the [View] widget can only be used in those parts of +/// the widget tree where it is not required to participate in the construction +/// of the surrounding render tree. In other words, the widget may only be used +/// in a non-rendering zone of the widget tree (see [WidgetsBinding] for a +/// definition of rendering and non-rendering zones). +/// +/// In practical terms, the widget is typically used at the root of the widget +/// tree outside of any other [View] widget, as a child of a [ViewCollection] +/// widget, or in the [ViewAnchor.view] slot of a [ViewAnchor] widget. It is not +/// required to be a direct child, though, since other non-[RenderObjectWidget]s +/// (e.g. [InheritedWidget]s, [Builder]s, or [StatefulWidget]s/[StatelessWidget] +/// that only produce non-[RenderObjectWidget]s) are allowed to be present +/// between those widgets and the [View] widget. +/// +/// See also: +/// +/// * [Element.debugExpectsRenderObjectForSlot], which defines whether a [View] +/// widget is allowed in a given child slot. +class View extends StatelessWidget { + /// Create a [View] widget to bootstrap a render tree that is rendered into + /// the provided [FlutterView]. + /// + /// The content rendered into that [view] is determined by the given [child] + /// widget. + View({ + super.key, + required this.view, + @Deprecated( + 'Do not use. ' + 'This parameter only exists to implement the deprecated RendererBinding.pipelineOwner property until it is removed. ' + 'This feature was deprecated after v3.10.0-12.0.pre.' + ) + PipelineOwner? deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner, + @Deprecated( + 'Do not use. ' + 'This parameter only exists to implement the deprecated RendererBinding.renderView property until it is removed. ' + 'This feature was deprecated after v3.10.0-12.0.pre.' + ) + RenderView? deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView, + required this.child, + }) : _deprecatedPipelineOwner = deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner, + _deprecatedRenderView = deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView, + assert((deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner == null) == (deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView == null)), + assert(deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView == null || deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView.flutterView == view); + + /// The [FlutterView] into which [child] is drawn. + final FlutterView view; + + /// The widget below this widget in the tree, which will be drawn into the + /// [view]. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + final PipelineOwner? _deprecatedPipelineOwner; + final RenderView? _deprecatedRenderView; + + /// Returns the [FlutterView] that the provided `context` will render into. + /// + /// Returns null if the `context` is not associated with a [FlutterView]. + /// + /// The method creates a dependency on the `context`, which will be informed + /// when the identity of the [FlutterView] changes (i.e. the `context` is + /// moved to render into a different [FlutterView] then before). The context + /// will not be informed when the _properties_ on the [FlutterView] itself + /// change their values. To access the property values of a [FlutterView] it + /// is best practise to use [MediaQuery.maybeOf] instead, which will ensure + /// that the `context` is informed when the view properties change. + /// + /// See also: + /// + /// * [View.of], which throws instead of returning null if no [FlutterView] + /// is found. + static FlutterView? maybeOf(BuildContext context) { + return LookupBoundary.dependOnInheritedWidgetOfExactType<_ViewScope>(context)?.view; + } + + /// Returns the [FlutterView] that the provided `context` will render into. + /// + /// Throws if the `context` is not associated with a [FlutterView]. + /// + /// The method creates a dependency on the `context`, which will be informed + /// when the identity of the [FlutterView] changes (i.e. the `context` is + /// moved to render into a different [FlutterView] then before). The context + /// will not be informed when the _properties_ on the [FlutterView] itself + /// change their values. To access the property values of a [FlutterView] + /// prefer using the access methods on [MediaQuery], such as + /// [MediaQuery.sizeOf], which will ensure that the `context` is informed when + /// the view properties change. + /// + /// See also: + /// + /// * [View.maybeOf], which throws instead of returning null if no + /// [FlutterView] is found. + static FlutterView of(BuildContext context) { + final FlutterView? result = maybeOf(context); + assert(() { + if (result == null) { + final bool hiddenByBoundary = LookupBoundary.debugIsHidingAncestorWidgetOfExactType<_ViewScope>(context); + final List<DiagnosticsNode> information = <DiagnosticsNode>[ + if (hiddenByBoundary) ...<DiagnosticsNode>[ + ErrorSummary('View.of() was called with a context that does not have access to a View widget.'), + ErrorDescription('The context provided to View.of() does have a View widget ancestor, but it is hidden by a LookupBoundary.'), + ] else ...<DiagnosticsNode>[ + ErrorSummary('View.of() was called with a context that does not contain a View widget.'), + ErrorDescription('No View widget ancestor could be found starting from the context that was passed to View.of().'), + ], + ErrorDescription( + 'The context used was:\n' + ' $context', + ), + ErrorHint('This usually means that the provided context is not associated with a View.'), + ]; + throw FlutterError.fromParts(information); + } + return true; + }()); + return result!; + } + + /// Returns the [PipelineOwner] parent to which a child [View] should attach + /// its [PipelineOwner] to. + /// + /// If `context` has a [View] ancestor, it returns the [PipelineOwner] + /// responsible for managing the render tree of that view. If there is no + /// [View] ancestor, [RendererBinding.rootPipelineOwner] is returned instead. + static PipelineOwner pipelineOwnerOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<_PipelineOwnerScope>()?.pipelineOwner + ?? RendererBinding.instance.rootPipelineOwner; + } + + @override + Widget build(BuildContext context) { + return _RawView( + view: view, + deprecatedPipelineOwner: _deprecatedPipelineOwner, + deprecatedRenderView: _deprecatedRenderView, + builder: (BuildContext context, PipelineOwner owner) { + return _ViewScope( + view: view, + child: _PipelineOwnerScope( + pipelineOwner: owner, + child: MediaQuery.fromView( + view: view, + child: child, + ), + ), + ); + } + ); + } +} + +/// A builder for the content [Widget] of a [_RawView]. +/// +/// The widget returned by the builder defines the content that is drawn into +/// the [FlutterView] configured on the [_RawView]. +/// +/// The builder is given the [PipelineOwner] that the [_RawView] uses to manage +/// its render tree. Typical builder implementations make that pipeline owner +/// available as an attachment point for potential child views. +/// +/// Used by [_RawView.builder]. +typedef _RawViewContentBuilder = Widget Function(BuildContext context, PipelineOwner owner); + +/// The workhorse behind the [View] widget that actually bootstraps a render +/// tree. +/// +/// It instantiates the [RenderView] as the root of that render tree and adds it +/// to the [RendererBinding] via [RendererBinding.addRenderView]. It also owns +/// the [PipelineOwner] that manages this render tree and adds it as a child to +/// the surrounding parent [PipelineOwner] obtained with [View.pipelineOwnerOf]. +/// This ensures that the render tree bootstrapped by this widget participates +/// properly in frame production and hit testing. +class _RawView extends RenderObjectWidget { + /// Create a [RawView] widget to bootstrap a render tree that is rendered into + /// the provided [FlutterView]. + /// + /// The content rendered into that [view] is determined by the [Widget] + /// returned by [builder]. + _RawView({ + required this.view, + required PipelineOwner? deprecatedPipelineOwner, + required RenderView? deprecatedRenderView, + required this.builder, + }) : _deprecatedPipelineOwner = deprecatedPipelineOwner, + _deprecatedRenderView = deprecatedRenderView, + assert(deprecatedRenderView == null || deprecatedRenderView.flutterView == view), + // TODO(goderbauer): Replace this with GlobalObjectKey(view) when the deprecated properties are removed. + super(key: _DeprecatedRawViewKey(view, deprecatedPipelineOwner, deprecatedRenderView)); + + /// The [FlutterView] into which the [Widget] returned by [builder] is drawn. + final FlutterView view; + + /// Determines the content [Widget] that is drawn into the [view]. + /// + /// The [builder] is given the [PipelineOwner] responsible for the render tree + /// bootstrapped by this widget and typically makes it available as an + /// attachment point for potential child views. + final _RawViewContentBuilder builder; + + final PipelineOwner? _deprecatedPipelineOwner; + final RenderView? _deprecatedRenderView; + + @override + RenderObjectElement createElement() => _RawViewElement(this); + + @override + RenderObject createRenderObject(BuildContext context) { + return _deprecatedRenderView ?? RenderView( + view: view, + ); + } + + // No need to implement updateRenderObject: RawView uses the view as a + // GlobalKey, so we never need to update the RenderObject with a new view. +} + +class _RawViewElement extends RenderTreeRootElement { + _RawViewElement(super.widget); + + late final PipelineOwner _pipelineOwner = PipelineOwner( + onSemanticsOwnerCreated: _handleSemanticsOwnerCreated, + onSemanticsUpdate: _handleSemanticsUpdate, + onSemanticsOwnerDisposed: _handleSemanticsOwnerDisposed, + ); + + PipelineOwner get _effectivePipelineOwner => (widget as _RawView)._deprecatedPipelineOwner ?? _pipelineOwner; + + void _handleSemanticsOwnerCreated() { + (_effectivePipelineOwner.rootNode as RenderView?)?.scheduleInitialSemantics(); + } + + void _handleSemanticsOwnerDisposed() { + (_effectivePipelineOwner.rootNode as RenderView?)?.clearSemantics(); + } + + void _handleSemanticsUpdate(SemanticsUpdate update) { + (widget as _RawView).view.updateSemantics(update); + } + + @override + RenderView get renderObject => super.renderObject as RenderView; + + Element? _child; + + void _updateChild() { + try { + final Widget child = (widget as _RawView).builder(this, _effectivePipelineOwner); + _child = updateChild(_child, child, null); + } catch (e, stack) { + final FlutterErrorDetails details = FlutterErrorDetails( + exception: e, + stack: stack, + library: 'widgets library', + context: ErrorDescription('building $this'), + informationCollector: !kDebugMode ? null : () => <DiagnosticsNode>[ + DiagnosticsDebugCreator(DebugCreator(this)), + ], + ); + FlutterError.reportError(details); + final Widget error = ErrorWidget.builder(details); + _child = updateChild(null, error, slot); + } + } + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + assert(_effectivePipelineOwner.rootNode == null); + _effectivePipelineOwner.rootNode = renderObject; + _attachView(); + _updateChild(); + renderObject.prepareInitialFrame(); + if (_effectivePipelineOwner.semanticsOwner != null) { + renderObject.scheduleInitialSemantics(); + } + } + + PipelineOwner? _parentPipelineOwner; // Is null if view is currently not attached. + + void _attachView([PipelineOwner? parentPipelineOwner]) { + assert(_parentPipelineOwner == null); + parentPipelineOwner ??= View.pipelineOwnerOf(this); + parentPipelineOwner.adoptChild(_effectivePipelineOwner); + RendererBinding.instance.addRenderView(renderObject); + _parentPipelineOwner = parentPipelineOwner; + } + + void _detachView() { + final PipelineOwner? parentPipelineOwner = _parentPipelineOwner; + if (parentPipelineOwner != null) { + RendererBinding.instance.removeRenderView(renderObject); + parentPipelineOwner.dropChild(_effectivePipelineOwner); + _parentPipelineOwner = null; + } + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (_parentPipelineOwner == null) { + return; + } + final PipelineOwner newParentPipelineOwner = View.pipelineOwnerOf(this); + if (newParentPipelineOwner != _parentPipelineOwner) { + _detachView(); + _attachView(newParentPipelineOwner); + } + } + + @override + void performRebuild() { + super.performRebuild(); + _updateChild(); + } + + @override + void activate() { + super.activate(); + assert(_effectivePipelineOwner.rootNode == null); + _effectivePipelineOwner.rootNode = renderObject; + _attachView(); + } + + @override + void deactivate() { + _detachView(); + assert(_effectivePipelineOwner.rootNode == renderObject); + _effectivePipelineOwner.rootNode = null; // To satisfy the assert in the super class. + super.deactivate(); + } + + @override + void update(_RawView newWidget) { + super.update(newWidget); + _updateChild(); + } + + @override + void visitChildren(ElementVisitor visitor) { + if (_child != null) { + visitor(_child!); + } + } + + @override + void forgetChild(Element child) { + assert(child == _child); + _child = null; + super.forgetChild(child); + } + + @override + void insertRenderObjectChild(RenderBox child, Object? slot) { + assert(slot == null); + assert(renderObject.debugValidateChild(child)); + renderObject.child = child; + } + + @override + void moveRenderObjectChild(RenderObject child, Object? oldSlot, Object? newSlot) { + assert(false); + } + + @override + void removeRenderObjectChild(RenderObject child, Object? slot) { + assert(slot == null); + assert(renderObject.child == child); + renderObject.child = null; + } + + @override + void unmount() { + if (_effectivePipelineOwner != (widget as _RawView)._deprecatedPipelineOwner) { + _effectivePipelineOwner.dispose(); + } + super.unmount(); + } +} + +class _ViewScope extends InheritedWidget { + const _ViewScope({required this.view, required super.child}); + + final FlutterView? view; + + @override + bool updateShouldNotify(_ViewScope oldWidget) => view != oldWidget.view; +} + +class _PipelineOwnerScope extends InheritedWidget { + const _PipelineOwnerScope({ + required this.pipelineOwner, + required super.child, + }); + + final PipelineOwner pipelineOwner; + + @override + bool updateShouldNotify(_PipelineOwnerScope oldWidget) => pipelineOwner != oldWidget.pipelineOwner; +} + +class _MultiChildComponentWidget extends Widget { + const _MultiChildComponentWidget({ + super.key, + List<Widget> views = const <Widget>[], + Widget? child, + }) : _views = views, _child = child; + + // It is up to the subclasses to make the relevant properties public. + final List<Widget> _views; + final Widget? _child; + + @override + Element createElement() => _MultiChildComponentElement(this); +} + +/// A collection of sibling [View]s. +/// +/// This widget can only be used in places were a [View] widget is allowed, i.e. +/// in a non-rendering zone of the widget tree. In practical terms, it can be +/// used at the root of the widget tree outside of any [View] widget, as a child +/// to a another [ViewCollection], or in the [ViewAnchor.view] slot of a +/// [ViewAnchor] widget. It is not required to be a direct child of those +/// widgets; other non-[RenderObjectWidget]s may appear in between the two (such +/// as an [InheritedWidget]). +/// +/// Similarly, the [views] children of this widget must be [View]s, but they +/// may be wrapped in additional non-[RenderObjectWidget]s (e.g. +/// [InheritedWidget]s). +/// +/// See also: +/// +/// * [WidgetsBinding] for an explanation of rendering and non-rendering zones. +class ViewCollection extends _MultiChildComponentWidget { + /// Creates a [ViewCollection] widget. + const ViewCollection({super.key, required super.views}); + + /// The [View] descendants of this widget. + /// + /// The [View]s may be wrapped in other non-[RenderObjectWidget]s (e.g. + /// [InheritedWidget]s). However, no [RenderObjectWidget] is allowed to appear + /// between the [ViewCollection] and the next [View] widget. + List<Widget> get views => _views; +} + +/// Decorates a [child] widget with a side [View]. +/// +/// This widget must have a [View] ancestor, into which the [child] widget +/// is rendered. +/// +/// Typically, a [View] or [ViewCollection] widget is used in the [view] slot to +/// define the content of the side view(s). Those widgets may be wrapped in +/// other non-[RenderObjectWidget]s (e.g. [InheritedWidget]s). However, no +/// [RenderObjectWidget] is allowed to appear between the [ViewAnchor] and the +/// next [View] widget in the [view] slot. The widgets in the [view] slot have +/// access to all [InheritedWidget]s above the [ViewAnchor] in the tree. +/// +/// In technical terms, the [ViewAnchor] can only be used in a rendering zone of +/// the widget tree and the [view] slot marks the start of a new non-rendering +/// zone (see [WidgetsBinding] for a definition of these zones). Typically, +/// it is occupied by a [View] widget, which will start a new rendering zone. +/// +/// {@template flutter.widgets.ViewAnchor} +/// An example use case for this widget is a tooltip for a button. The tooltip +/// should be able to extend beyond the bounds of the main view. For this, the +/// tooltip can be implemented as a separate [View], which is anchored to the +/// button in the main view by wrapping that button with a [ViewAnchor]. In this +/// example, the [view] slot is configured with the tooltip [View] and the +/// [child] is the button widget rendered into the surrounding view. +/// {@endtemplate} +class ViewAnchor extends StatelessWidget { + /// Creates a [ViewAnchor] widget. + const ViewAnchor({ + super.key, + this.view, + required this.child, + }); + + /// The widget that defines the view anchored to this widget. + /// + /// Typically, a [View] or [ViewCollection] widget is used, which may be + /// wrapped in other non-[RenderObjectWidget]s (e.g. [InheritedWidget]s). + /// + /// {@macro flutter.widgets.ViewAnchor} + final Widget? view; + + /// The widget below this widget in the tree. + /// + /// It is rendered into the surrounding view, not in the view defined by + /// [view]. + /// + /// {@macro flutter.widgets.ViewAnchor} + final Widget child; + + @override + Widget build(BuildContext context) { + return _MultiChildComponentWidget( + views: <Widget>[ + if (view != null) + _ViewScope( + view: null, + child: view!, + ), + ], + child: child, + ); + } +} + +class _MultiChildComponentElement extends Element { + _MultiChildComponentElement(super.widget); + + List<Element> _viewElements = <Element>[]; + final Set<Element> _forgottenViewElements = HashSet<Element>(); + Element? _childElement; + + bool _debugAssertChildren() { + final _MultiChildComponentWidget typedWidget = widget as _MultiChildComponentWidget; + // Each view widget must have a corresponding element. + assert(_viewElements.length == typedWidget._views.length); + // Iff there is a child widget, it must have a corresponding element. + assert((_childElement == null) == (typedWidget._child == null)); + // The child element is not also a view element. + assert(!_viewElements.contains(_childElement)); + return true; + } + + @override + void attachRenderObject(Object? newSlot) { + super.attachRenderObject(newSlot); + assert(_debugCheckMustAttachRenderObject(newSlot)); + } + + @override + void mount(Element? parent, Object? newSlot) { + super.mount(parent, newSlot); + assert(_debugCheckMustAttachRenderObject(newSlot)); + assert(_viewElements.isEmpty); + assert(_childElement == null); + rebuild(); + assert(_debugAssertChildren()); + } + + @override + void updateSlot(Object? newSlot) { + super.updateSlot(newSlot); + assert(_debugCheckMustAttachRenderObject(newSlot)); + } + + bool _debugCheckMustAttachRenderObject(Object? slot) { + // Check only applies in the ViewCollection configuration. + if (!kDebugMode || (widget as _MultiChildComponentWidget)._child != null) { + return true; + } + bool hasAncestorRenderObjectElement = false; + bool ancestorWantsRenderObject = true; + visitAncestorElements((Element ancestor) { + if (!ancestor.debugExpectsRenderObjectForSlot(slot)) { + ancestorWantsRenderObject = false; + return false; + } + if (ancestor is RenderObjectElement) { + hasAncestorRenderObjectElement = true; + return false; + } + return true; + }); + if (hasAncestorRenderObjectElement && ancestorWantsRenderObject) { + FlutterError.reportError( + FlutterErrorDetails(exception: FlutterError.fromParts( + <DiagnosticsNode>[ + ErrorSummary( + 'The Element for ${toStringShort()} cannot be inserted into slot "$slot" of its ancestor. ', + ), + ErrorDescription( + 'The ownership chain for the Element in question was:\n ${debugGetCreatorChain(10)}', + ), + ErrorDescription( + 'This Element allows the creation of multiple independent render trees, which cannot ' + 'be attached to an ancestor in an existing render tree. However, an ancestor RenderObject ' + 'is expecting that a child will be attached.' + ), + ErrorHint( + 'Try moving the subtree that contains the ${toStringShort()} widget into the ' + 'view property of a ViewAnchor widget or to the root of the widget tree, where ' + 'it is not expected to attach its RenderObject to its ancestor.', + ), + ], + )), + ); + } + return true; + } + + @override + void update(_MultiChildComponentWidget newWidget) { + // Cannot switch from ViewAnchor config to ViewCollection config. + assert((newWidget._child == null) == ((widget as _MultiChildComponentWidget)._child == null)); + super.update(newWidget); + rebuild(force: true); + assert(_debugAssertChildren()); + } + + static const Object _viewSlot = Object(); + + @override + bool debugExpectsRenderObjectForSlot(Object? slot) => slot != _viewSlot; + + @override + void performRebuild() { + final _MultiChildComponentWidget typedWidget = widget as _MultiChildComponentWidget; + + _childElement = updateChild(_childElement, typedWidget._child, slot); + + final List<Widget> views = typedWidget._views; + _viewElements = updateChildren( + _viewElements, + views, + forgottenChildren: _forgottenViewElements, + slots: List<Object>.generate(views.length, (_) => _viewSlot), + ); + _forgottenViewElements.clear(); + + super.performRebuild(); // clears the dirty flag + assert(_debugAssertChildren()); + } + + @override + void forgetChild(Element child) { + if (child == _childElement) { + _childElement = null; + } else { + assert(_viewElements.contains(child)); + assert(!_forgottenViewElements.contains(child)); + _forgottenViewElements.add(child); + } + super.forgetChild(child); + } + + @override + void visitChildren(ElementVisitor visitor) { + if (_childElement != null) { + visitor(_childElement!); + } + for (final Element child in _viewElements) { + if (!_forgottenViewElements.contains(child)) { + visitor(child); + } + } + } + + @override + bool get debugDoingBuild => false; // This element does not have a concept of "building". + + @override + Element? get renderObjectAttachingChild => _childElement; + + @override + List<DiagnosticsNode> debugDescribeChildren() { + final List<DiagnosticsNode> children = <DiagnosticsNode>[]; + if (_childElement != null) { + children.add(_childElement!.toDiagnosticsNode()); + } + for (int i = 0; i < _viewElements.length; i++) { + children.add(_viewElements[i].toDiagnosticsNode( + name: 'view ${i + 1}', + style: DiagnosticsTreeStyle.offstage, + )); + } + return children; + } +} + +// A special [GlobalKey] to support passing the deprecated +// [RendererBinding.renderView] and [RendererBinding.pipelineOwner] to the +// [_RawView]. Will be removed when those deprecated properties are removed. +@optionalTypeArgs +class _DeprecatedRawViewKey<T extends State<StatefulWidget>> extends GlobalKey<T> { + const _DeprecatedRawViewKey(this.view, this.owner, this.renderView) : super.constructor(); + + final FlutterView view; + final PipelineOwner? owner; + final RenderView? renderView; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _DeprecatedRawViewKey<T> + && identical(other.view, view) + && identical(other.owner, owner) + && identical(other.renderView, renderView); + } + + @override + int get hashCode => Object.hash(view, owner, renderView); + + @override + String toString() => '[_DeprecatedRawViewKey ${describeIdentity(view)}]'; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/viewport.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/viewport.dart new file mode 100644 index 0000000000000000000000000000000000000000..36f556510e92e8b91ac436ebacbad23375337e79 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/viewport.dart @@ -0,0 +1,396 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'scroll_notification.dart'; + +export 'package:flutter/rendering.dart' show + AxisDirection, + GrowthDirection; + +/// A widget through which a portion of larger content can be viewed, typically +/// in combination with a [Scrollable]. +/// +/// [Viewport] is the visual workhorse of the scrolling machinery. It displays a +/// subset of its children according to its own dimensions and the given +/// [offset]. As the offset varies, different children are visible through +/// the viewport. +/// +/// [Viewport] hosts a bidirectional list of slivers, anchored on a [center] +/// sliver, which is placed at the zero scroll offset. The center widget is +/// displayed in the viewport according to the [anchor] property. +/// +/// Slivers that are earlier in the child list than [center] are displayed in +/// reverse order in the reverse [axisDirection] starting from the [center]. For +/// example, if the [axisDirection] is [AxisDirection.down], the first sliver +/// before [center] is placed above the [center]. The slivers that are later in +/// the child list than [center] are placed in order in the [axisDirection]. For +/// example, in the preceding scenario, the first sliver after [center] is +/// placed below the [center]. +/// +/// [Viewport] cannot contain box children directly. Instead, use a +/// [SliverList], [SliverFixedExtentList], [SliverGrid], or a +/// [SliverToBoxAdapter], for example. +/// +/// See also: +/// +/// * [ListView], [PageView], [GridView], and [CustomScrollView], which combine +/// [Scrollable] and [Viewport] into widgets that are easier to use. +/// * [SliverToBoxAdapter], which allows a box widget to be placed inside a +/// sliver context (the opposite of this widget). +/// * [ShrinkWrappingViewport], a variant of [Viewport] that shrink-wraps its +/// contents along the main axis. +/// * [ViewportElementMixin], which should be mixed in to the [Element] type used +/// by viewport-like widgets to correctly handle scroll notifications. +class Viewport extends MultiChildRenderObjectWidget { + /// Creates a widget that is bigger on the inside. + /// + /// The viewport listens to the [offset], which means you do not need to + /// rebuild this widget when the [offset] changes. + /// + /// The [cacheExtent] must be specified if the [cacheExtentStyle] is + /// not [CacheExtentStyle.pixel]. + Viewport({ + super.key, + this.axisDirection = AxisDirection.down, + this.crossAxisDirection, + this.anchor = 0.0, + required this.offset, + this.center, + this.cacheExtent, + this.cacheExtentStyle = CacheExtentStyle.pixel, + this.clipBehavior = Clip.hardEdge, + List<Widget> slivers = const <Widget>[], + }) : assert(center == null || slivers.where((Widget child) => child.key == center).length == 1), + assert(cacheExtentStyle != CacheExtentStyle.viewport || cacheExtent != null), + super(children: slivers); + + /// The direction in which the [offset]'s [ViewportOffset.pixels] increases. + /// + /// For example, if the [axisDirection] is [AxisDirection.down], a scroll + /// offset of zero is at the top of the viewport and increases towards the + /// bottom of the viewport. + final AxisDirection axisDirection; + + /// The direction in which child should be laid out in the cross axis. + /// + /// If the [axisDirection] is [AxisDirection.down] or [AxisDirection.up], this + /// property defaults to [AxisDirection.left] if the ambient [Directionality] + /// is [TextDirection.rtl] and [AxisDirection.right] if the ambient + /// [Directionality] is [TextDirection.ltr]. + /// + /// If the [axisDirection] is [AxisDirection.left] or [AxisDirection.right], + /// this property defaults to [AxisDirection.down]. + final AxisDirection? crossAxisDirection; + + /// The relative position of the zero scroll offset. + /// + /// For example, if [anchor] is 0.5 and the [axisDirection] is + /// [AxisDirection.down] or [AxisDirection.up], then the zero scroll offset is + /// vertically centered within the viewport. If the [anchor] is 1.0, and the + /// [axisDirection] is [AxisDirection.right], then the zero scroll offset is + /// on the left edge of the viewport. + /// + /// {@macro flutter.rendering.GrowthDirection.sample} + final double anchor; + + /// Which part of the content inside the viewport should be visible. + /// + /// The [ViewportOffset.pixels] value determines the scroll offset that the + /// viewport uses to select which part of its content to display. As the user + /// scrolls the viewport, this value changes, which changes the content that + /// is displayed. + /// + /// Typically a [ScrollPosition]. + final ViewportOffset offset; + + /// The first child in the [GrowthDirection.forward] growth direction. + /// + /// Children after [center] will be placed in the [axisDirection] relative to + /// the [center]. Children before [center] will be placed in the opposite of + /// the [axisDirection] relative to the [center]. + /// + /// The [center] must be the key of a child of the viewport. + /// + /// {@macro flutter.rendering.GrowthDirection.sample} + final Key? center; + + /// {@macro flutter.rendering.RenderViewportBase.cacheExtent} + /// + /// See also: + /// + /// * [cacheExtentStyle], which controls the units of the [cacheExtent]. + final double? cacheExtent; + + /// {@macro flutter.rendering.RenderViewportBase.cacheExtentStyle} + final CacheExtentStyle cacheExtentStyle; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + /// Given a [BuildContext] and an [AxisDirection], determine the correct cross + /// axis direction. + /// + /// This depends on the [Directionality] if the `axisDirection` is vertical; + /// otherwise, the default cross axis direction is downwards. + static AxisDirection getDefaultCrossAxisDirection(BuildContext context, AxisDirection axisDirection) { + switch (axisDirection) { + case AxisDirection.up: + assert(debugCheckHasDirectionality( + context, + why: "to determine the cross-axis direction when the viewport has an 'up' axisDirection", + alternative: "Alternatively, consider specifying the 'crossAxisDirection' argument on the Viewport.", + )); + return textDirectionToAxisDirection(Directionality.of(context)); + case AxisDirection.right: + return AxisDirection.down; + case AxisDirection.down: + assert(debugCheckHasDirectionality( + context, + why: "to determine the cross-axis direction when the viewport has a 'down' axisDirection", + alternative: "Alternatively, consider specifying the 'crossAxisDirection' argument on the Viewport.", + )); + return textDirectionToAxisDirection(Directionality.of(context)); + case AxisDirection.left: + return AxisDirection.down; + } + } + + @override + RenderViewport createRenderObject(BuildContext context) { + return RenderViewport( + axisDirection: axisDirection, + crossAxisDirection: crossAxisDirection ?? Viewport.getDefaultCrossAxisDirection(context, axisDirection), + anchor: anchor, + offset: offset, + cacheExtent: cacheExtent, + cacheExtentStyle: cacheExtentStyle, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderViewport renderObject) { + renderObject + ..axisDirection = axisDirection + ..crossAxisDirection = crossAxisDirection ?? Viewport.getDefaultCrossAxisDirection(context, axisDirection) + ..anchor = anchor + ..offset = offset + ..cacheExtent = cacheExtent + ..cacheExtentStyle = cacheExtentStyle + ..clipBehavior = clipBehavior; + } + + @override + MultiChildRenderObjectElement createElement() => _ViewportElement(this); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<AxisDirection>('axisDirection', axisDirection)); + properties.add(EnumProperty<AxisDirection>('crossAxisDirection', crossAxisDirection, defaultValue: null)); + properties.add(DoubleProperty('anchor', anchor)); + properties.add(DiagnosticsProperty<ViewportOffset>('offset', offset)); + if (center != null) { + properties.add(DiagnosticsProperty<Key>('center', center)); + } else if (children.isNotEmpty && children.first.key != null) { + properties.add(DiagnosticsProperty<Key>('center', children.first.key, tooltip: 'implicit')); + } + properties.add(DiagnosticsProperty<double>('cacheExtent', cacheExtent)); + properties.add(DiagnosticsProperty<CacheExtentStyle>('cacheExtentStyle', cacheExtentStyle)); + } +} + +class _ViewportElement extends MultiChildRenderObjectElement with NotifiableElementMixin, ViewportElementMixin { + /// Creates an element that uses the given widget as its configuration. + _ViewportElement(Viewport super.widget); + + bool _doingMountOrUpdate = false; + int? _centerSlotIndex; + + @override + RenderViewport get renderObject => super.renderObject as RenderViewport; + + @override + void mount(Element? parent, Object? newSlot) { + assert(!_doingMountOrUpdate); + _doingMountOrUpdate = true; + super.mount(parent, newSlot); + _updateCenter(); + assert(_doingMountOrUpdate); + _doingMountOrUpdate = false; + } + + @override + void update(MultiChildRenderObjectWidget newWidget) { + assert(!_doingMountOrUpdate); + _doingMountOrUpdate = true; + super.update(newWidget); + _updateCenter(); + assert(_doingMountOrUpdate); + _doingMountOrUpdate = false; + } + + void _updateCenter() { + // TODO(ianh): cache the keys to make this faster + final Viewport viewport = widget as Viewport; + if (viewport.center != null) { + int elementIndex = 0; + for (final Element e in children) { + if (e.widget.key == viewport.center) { + renderObject.center = e.renderObject as RenderSliver?; + break; + } + elementIndex++; + } + assert(elementIndex < children.length); + _centerSlotIndex = elementIndex; + } else if (children.isNotEmpty) { + renderObject.center = children.first.renderObject as RenderSliver?; + _centerSlotIndex = 0; + } else { + renderObject.center = null; + _centerSlotIndex = null; + } + } + + @override + void insertRenderObjectChild(RenderObject child, IndexedSlot<Element?> slot) { + super.insertRenderObjectChild(child, slot); + // Once [mount]/[update] are done, the `renderObject.center` will be updated + // in [_updateCenter]. + if (!_doingMountOrUpdate && slot.index == _centerSlotIndex) { + renderObject.center = child as RenderSliver?; + } + } + + @override + void moveRenderObjectChild(RenderObject child, IndexedSlot<Element?> oldSlot, IndexedSlot<Element?> newSlot) { + super.moveRenderObjectChild(child, oldSlot, newSlot); + assert(_doingMountOrUpdate); + } + + @override + void removeRenderObjectChild(RenderObject child, Object? slot) { + super.removeRenderObjectChild(child, slot); + if (!_doingMountOrUpdate && renderObject.center == child) { + renderObject.center = null; + } + } + + @override + void debugVisitOnstageChildren(ElementVisitor visitor) { + children.where((Element e) { + final RenderSliver renderSliver = e.renderObject! as RenderSliver; + return renderSliver.geometry!.visible; + }).forEach(visitor); + } +} + +/// A widget that is bigger on the inside and shrink wraps its children in the +/// main axis. +/// +/// [ShrinkWrappingViewport] displays a subset of its children according to its +/// own dimensions and the given [offset]. As the offset varies, different +/// children are visible through the viewport. +/// +/// [ShrinkWrappingViewport] differs from [Viewport] in that [Viewport] expands +/// to fill the main axis whereas [ShrinkWrappingViewport] sizes itself to match +/// its children in the main axis. This shrink wrapping behavior is expensive +/// because the children, and hence the viewport, could potentially change size +/// whenever the [offset] changes (e.g., because of a collapsing header). +/// +/// [ShrinkWrappingViewport] cannot contain box children directly. Instead, use +/// a [SliverList], [SliverFixedExtentList], [SliverGrid], or a +/// [SliverToBoxAdapter], for example. +/// +/// See also: +/// +/// * [ListView], [PageView], [GridView], and [CustomScrollView], which combine +/// [Scrollable] and [ShrinkWrappingViewport] into widgets that are easier to +/// use. +/// * [SliverToBoxAdapter], which allows a box widget to be placed inside a +/// sliver context (the opposite of this widget). +/// * [Viewport], a viewport that does not shrink-wrap its contents. +class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { + /// Creates a widget that is bigger on the inside and shrink wraps its + /// children in the main axis. + /// + /// The viewport listens to the [offset], which means you do not need to + /// rebuild this widget when the [offset] changes. + const ShrinkWrappingViewport({ + super.key, + this.axisDirection = AxisDirection.down, + this.crossAxisDirection, + required this.offset, + this.clipBehavior = Clip.hardEdge, + List<Widget> slivers = const <Widget>[], + }) : super(children: slivers); + + /// The direction in which the [offset]'s [ViewportOffset.pixels] increases. + /// + /// For example, if the [axisDirection] is [AxisDirection.down], a scroll + /// offset of zero is at the top of the viewport and increases towards the + /// bottom of the viewport. + final AxisDirection axisDirection; + + /// The direction in which child should be laid out in the cross axis. + /// + /// If the [axisDirection] is [AxisDirection.down] or [AxisDirection.up], this + /// property defaults to [AxisDirection.left] if the ambient [Directionality] + /// is [TextDirection.rtl] and [AxisDirection.right] if the ambient + /// [Directionality] is [TextDirection.ltr]. + /// + /// If the [axisDirection] is [AxisDirection.left] or [AxisDirection.right], + /// this property defaults to [AxisDirection.down]. + final AxisDirection? crossAxisDirection; + + /// Which part of the content inside the viewport should be visible. + /// + /// The [ViewportOffset.pixels] value determines the scroll offset that the + /// viewport uses to select which part of its content to display. As the user + /// scrolls the viewport, this value changes, which changes the content that + /// is displayed. + /// + /// Typically a [ScrollPosition]. + final ViewportOffset offset; + + /// {@macro flutter.material.Material.clipBehavior} + /// + /// Defaults to [Clip.hardEdge]. + final Clip clipBehavior; + + @override + RenderShrinkWrappingViewport createRenderObject(BuildContext context) { + return RenderShrinkWrappingViewport( + axisDirection: axisDirection, + crossAxisDirection: crossAxisDirection ?? Viewport.getDefaultCrossAxisDirection(context, axisDirection), + offset: offset, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderShrinkWrappingViewport renderObject) { + renderObject + ..axisDirection = axisDirection + ..crossAxisDirection = crossAxisDirection ?? Viewport.getDefaultCrossAxisDirection(context, axisDirection) + ..offset = offset + ..clipBehavior = clipBehavior; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty<AxisDirection>('axisDirection', axisDirection)); + properties.add(EnumProperty<AxisDirection>('crossAxisDirection', crossAxisDirection, defaultValue: null)); + properties.add(DiagnosticsProperty<ViewportOffset>('offset', offset)); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/visibility.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/visibility.dart new file mode 100644 index 0000000000000000000000000000000000000000..a5e2fca28f919b1c0564a3b50128c7eebf9cc71a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/visibility.dart @@ -0,0 +1,661 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; +import 'sliver.dart'; +import 'ticker_provider.dart'; + +/// Whether to show or hide a child. +/// +/// By default, the [visible] property controls whether the [child] is included +/// in the subtree or not; when it is not [visible], the [replacement] child +/// (typically a zero-sized box) is included instead. +/// +/// A variety of flags can be used to tweak exactly how the child is hidden. +/// (Changing the flags dynamically is discouraged, as it can cause the [child] +/// subtree to be rebuilt, with any state in the subtree being discarded. +/// Typically, only the [visible] flag is changed dynamically.) +/// +/// These widgets provide some of the facets of this one: +/// +/// * [Opacity], which can stop its child from being painted. +/// * [Offstage], which can stop its child from being laid out or painted. +/// * [TickerMode], which can stop its child from being animated. +/// * [ExcludeSemantics], which can hide the child from accessibility tools. +/// * [IgnorePointer], which can disable touch interactions with the child. +/// +/// Using this widget is not necessary to hide children. The simplest way to +/// hide a child is just to not include it, or, if a child _must_ be given (e.g. +/// because the parent is a [StatelessWidget]) then to use [SizedBox.shrink] +/// instead of the child that would otherwise be included. +/// +/// See also: +/// +/// * [AnimatedSwitcher], which can fade from one child to the next as the +/// subtree changes. +/// * [AnimatedCrossFade], which can fade between two specific children. +/// * [SliverVisibility], the sliver equivalent of this widget. +class Visibility extends StatelessWidget { + /// Control whether the given [child] is [visible]. + /// + /// The [maintainSemantics] and [maintainInteractivity] arguments can only be + /// set if [maintainSize] is set. + /// + /// The [maintainSize] argument can only be set if [maintainAnimation] is set. + /// + /// The [maintainAnimation] argument can only be set if [maintainState] is + /// set. + const Visibility({ + super.key, + required this.child, + this.replacement = const SizedBox.shrink(), + this.visible = true, + this.maintainState = false, + this.maintainAnimation = false, + this.maintainSize = false, + this.maintainSemantics = false, + this.maintainInteractivity = false, + }) : assert( + maintainState || !maintainAnimation, + 'Cannot maintain animations if the state is not also maintained.', + ), + assert( + maintainAnimation || !maintainSize, + 'Cannot maintain size if animations are not maintained.', + ), + assert( + maintainSize || !maintainSemantics, + 'Cannot maintain semantics if size is not maintained.', + ), + assert( + maintainSize || !maintainInteractivity, + 'Cannot maintain interactivity if size is not maintained.', + ); + + /// Control whether the given [child] is [visible]. + /// + /// This is equivalent to the default [Visibility] constructor with all + /// "maintain" fields set to true. This constructor should be used in place of + /// an [Opacity] widget that only takes on values of `0.0` or `1.0`, as it + /// avoids extra compositing when fully opaque. + const Visibility.maintain({ + super.key, + required this.child, + this.visible = true, + }) : maintainState = true, + maintainAnimation = true, + maintainSize = true, + maintainSemantics = true, + maintainInteractivity = true, + replacement = const SizedBox.shrink(); // Unused since maintainState is always true. + + /// The widget to show or hide, as controlled by [visible]. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// The widget to use when the child is not [visible], assuming that none of + /// the `maintain` flags (in particular, [maintainState]) are set. + /// + /// The normal behavior is to replace the widget with a zero by zero box + /// ([SizedBox.shrink]). + /// + /// See also: + /// + /// * [AnimatedCrossFade], which can animate between two children. + final Widget replacement; + + /// Switches between showing the [child] or hiding it. + /// + /// The `maintain` flags should be set to the same values regardless of the + /// state of the [visible] property, otherwise they will not operate correctly + /// (specifically, the state will be lost regardless of the state of + /// [maintainState] whenever any of the `maintain` flags are changed, since + /// doing so will result in a subtree shape change). + /// + /// Unless [maintainState] is set, the [child] subtree will be disposed + /// (removed from the tree) while hidden. + final bool visible; + + /// Whether to maintain the [State] objects of the [child] subtree when it is + /// not [visible]. + /// + /// Keeping the state of the subtree is potentially expensive (because it + /// means all the objects are still in memory; their resources are not + /// released). It should only be maintained if it cannot be recreated on + /// demand. One example of when the state would be maintained is if the child + /// subtree contains a [Navigator], since that widget maintains elaborate + /// state that cannot be recreated on the fly. + /// + /// If this property is true, an [Offstage] widget is used to hide the child + /// instead of replacing it with [replacement]. + /// + /// If this property is false, then [maintainAnimation] must also be false. + /// + /// Dynamically changing this value may cause the current state of the + /// subtree to be lost (and a new instance of the subtree, with new [State] + /// objects, to be immediately created if [visible] is true). + final bool maintainState; + + /// Whether to maintain animations within the [child] subtree when it is + /// not [visible]. + /// + /// To set this, [maintainState] must also be set. + /// + /// Keeping animations active when the widget is not visible is even more + /// expensive than only maintaining the state. + /// + /// One example when this might be useful is if the subtree is animating its + /// layout in time with an [AnimationController], and the result of that + /// layout is being used to influence some other logic. If this flag is false, + /// then any [AnimationController]s hosted inside the [child] subtree will be + /// muted while the [visible] flag is false. + /// + /// If this property is true, no [TickerMode] widget is used. + /// + /// If this property is false, then [maintainSize] must also be false. + /// + /// Dynamically changing this value may cause the current state of the + /// subtree to be lost (and a new instance of the subtree, with new [State] + /// objects, to be immediately created if [visible] is true). + final bool maintainAnimation; + + /// Whether to maintain space for where the widget would have been. + /// + /// To set this, [maintainAnimation] and [maintainState] must also be set. + /// + /// Maintaining the size when the widget is not [visible] is not notably more + /// expensive than just keeping animations running without maintaining the + /// size, and may in some circumstances be slightly cheaper if the subtree is + /// simple and the [visible] property is frequently toggled, since it avoids + /// triggering a layout change when the [visible] property is toggled. If the + /// [child] subtree is not trivial then it is significantly cheaper to not + /// even keep the state (see [maintainState]). + /// + /// If this property is false, [Offstage] is used. + /// + /// If this property is false, then [maintainSemantics] and + /// [maintainInteractivity] must also be false. + /// + /// Dynamically changing this value may cause the current state of the + /// subtree to be lost (and a new instance of the subtree, with new [State] + /// objects, to be immediately created if [visible] is true). + /// + /// See also: + /// + /// * [AnimatedOpacity] and [FadeTransition], which apply animations to the + /// opacity for a more subtle effect. + final bool maintainSize; + + /// Whether to maintain the semantics for the widget when it is hidden (e.g. + /// for accessibility). + /// + /// To set this, [maintainSize] must also be set. + /// + /// By default, with [maintainSemantics] set to false, the [child] is not + /// visible to accessibility tools when it is hidden from the user. If this + /// flag is set to true, then accessibility tools will report the widget as if + /// it was present. + final bool maintainSemantics; + + /// Whether to allow the widget to be interactive when hidden. + /// + /// To set this, [maintainSize] must also be set. + /// + /// By default, with [maintainInteractivity] set to false, touch events cannot + /// reach the [child] when it is hidden from the user. If this flag is set to + /// true, then touch events will nonetheless be passed through. + final bool maintainInteractivity; + + /// Tells the visibility state of an element in the tree based off its + /// ancestor [Visibility] elements. + /// + /// If there's one or more [Visibility] widgets in the ancestor tree, this + /// will return true if and only if all of those widgets have [visible] set + /// to true. If there is no [Visibility] widget in the ancestor tree of the + /// specified build context, this will return true. + /// + /// This will register a dependency from the specified context on any + /// [Visibility] elements in the ancestor tree, such that if any of their + /// visibilities changes, the specified context will be rebuilt. + static bool of(BuildContext context) { + bool isVisible = true; + BuildContext ancestorContext = context; + InheritedElement? ancestor = ancestorContext.getElementForInheritedWidgetOfExactType<_VisibilityScope>(); + while (isVisible && ancestor != null) { + final _VisibilityScope scope = context.dependOnInheritedElement(ancestor) as _VisibilityScope; + isVisible = scope.isVisible; + ancestor.visitAncestorElements((Element parent) { + ancestorContext = parent; + return false; + }); + ancestor = ancestorContext.getElementForInheritedWidgetOfExactType<_VisibilityScope>(); + } + return isVisible; + } + + @override + Widget build(BuildContext context) { + Widget result = child; + if (maintainSize) { + result = _Visibility( + visible: visible, + maintainSemantics: maintainSemantics, + child: IgnorePointer( + ignoring: !visible && !maintainInteractivity, + child: result, + ), + ); + } else { + assert(!maintainInteractivity); + assert(!maintainSemantics); + assert(!maintainSize); + if (maintainState) { + if (!maintainAnimation) { + result = TickerMode(enabled: visible, child: result); + } + result = Offstage( + offstage: !visible, + child: result, + ); + } else { + assert(!maintainAnimation); + assert(!maintainState); + result = visible ? child : replacement; + } + } + return _VisibilityScope(isVisible: visible, child: result); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('visible', value: visible, ifFalse: 'hidden', ifTrue: 'visible')); + properties.add(FlagProperty('maintainState', value: maintainState, ifFalse: 'maintainState')); + properties.add(FlagProperty('maintainAnimation', value: maintainAnimation, ifFalse: 'maintainAnimation')); + properties.add(FlagProperty('maintainSize', value: maintainSize, ifFalse: 'maintainSize')); + properties.add(FlagProperty('maintainSemantics', value: maintainSemantics, ifFalse: 'maintainSemantics')); + properties.add(FlagProperty('maintainInteractivity', value: maintainInteractivity, ifFalse: 'maintainInteractivity')); + } +} + +/// Inherited widget that allows descendants to find their visibility status. +class _VisibilityScope extends InheritedWidget { + const _VisibilityScope({required this.isVisible, required super.child}); + + final bool isVisible; + + @override + bool updateShouldNotify(_VisibilityScope old) { + return isVisible != old.isVisible; + } +} + +/// Whether to show or hide a sliver child. +/// +/// By default, the [visible] property controls whether the [sliver] is included +/// in the subtree or not; when it is not [visible], the [replacementSliver] is +/// included instead. +/// +/// A variety of flags can be used to tweak exactly how the sliver is hidden. +/// (Changing the flags dynamically is discouraged, as it can cause the [sliver] +/// subtree to be rebuilt, with any state in the subtree being discarded. +/// Typically, only the [visible] flag is changed dynamically.) +/// +/// These widgets provide some of the facets of this one: +/// +/// * [SliverOpacity], which can stop its sliver child from being painted. +/// * [SliverOffstage], which can stop its sliver child from being laid out or +/// painted. +/// * [TickerMode], which can stop its child from being animated. +/// * [ExcludeSemantics], which can hide the child from accessibility tools. +/// * [SliverIgnorePointer], which can disable touch interactions with the +/// sliver child. +/// +/// Using this widget is not necessary to hide children. The simplest way to +/// hide a child is just to not include it. If a child _must_ be given (e.g. +/// because the parent is a [StatelessWidget]), then including a childless +/// [SliverToBoxAdapter] instead of the child that would otherwise be included +/// is typically more efficient than using [SliverVisibility]. +/// +/// See also: +/// +/// * [Visibility], the equivalent widget for boxes. +class SliverVisibility extends StatelessWidget { + /// Control whether the given [sliver] is [visible]. + /// + /// The [maintainSemantics] and [maintainInteractivity] arguments can only be + /// set if [maintainSize] is set. + /// + /// The [maintainSize] argument can only be set if [maintainAnimation] is set. + /// + /// The [maintainAnimation] argument can only be set if [maintainState] is + /// set. + const SliverVisibility({ + super.key, + required this.sliver, + this.replacementSliver = const SliverToBoxAdapter(), + this.visible = true, + this.maintainState = false, + this.maintainAnimation = false, + this.maintainSize = false, + this.maintainSemantics = false, + this.maintainInteractivity = false, + }) : assert( + maintainState || !maintainAnimation, + 'Cannot maintain animations if the state is not also maintained.', + ), + assert( + maintainAnimation || !maintainSize, + 'Cannot maintain size if animations are not maintained.', + ), + assert( + maintainSize || !maintainSemantics, + 'Cannot maintain semantics if size is not maintained.', + ), + assert( + maintainSize || !maintainInteractivity, + 'Cannot maintain interactivity if size is not maintained.', + ); + + /// Control whether the given [sliver] is [visible]. + /// + /// This is equivalent to the default [SliverVisibility] constructor with all + /// "maintain" fields set to true. This constructor should be used in place of + /// a [SliverOpacity] widget that only takes on values of `0.0` or `1.0`, as it + /// avoids extra compositing when fully opaque. + const SliverVisibility.maintain({ + super.key, + required this.sliver, + this.replacementSliver = const SliverToBoxAdapter(), + this.visible = true, + }) : maintainState = true, + maintainAnimation = true, + maintainSize = true, + maintainSemantics = true, + maintainInteractivity = true; + + /// The sliver to show or hide, as controlled by [visible]. + final Widget sliver; + + /// The widget to use when the sliver child is not [visible], assuming that + /// none of the `maintain` flags (in particular, [maintainState]) are set. + /// + /// The normal behavior is to replace the widget with a childless + /// [SliverToBoxAdapter], which by default has a geometry of + /// [SliverGeometry.zero]. + final Widget replacementSliver; + + /// Switches between showing the [sliver] or hiding it. + /// + /// The `maintain` flags should be set to the same values regardless of the + /// state of the [visible] property, otherwise they will not operate correctly + /// (specifically, the state will be lost regardless of the state of + /// [maintainState] whenever any of the `maintain` flags are changed, since + /// doing so will result in a subtree shape change). + /// + /// Unless [maintainState] is set, the [sliver] subtree will be disposed + /// (removed from the tree) while hidden. + final bool visible; + + /// Whether to maintain the [State] objects of the [sliver] subtree when it is + /// not [visible]. + /// + /// Keeping the state of the subtree is potentially expensive (because it + /// means all the objects are still in memory; their resources are not + /// released). It should only be maintained if it cannot be recreated on + /// demand. One example of when the state would be maintained is if the sliver + /// subtree contains a [Navigator], since that widget maintains elaborate + /// state that cannot be recreated on the fly. + /// + /// If this property is true, a [SliverOffstage] widget is used to hide the + /// sliver instead of replacing it with [replacementSliver]. + /// + /// If this property is false, then [maintainAnimation] must also be false. + /// + /// Dynamically changing this value may cause the current state of the + /// subtree to be lost (and a new instance of the subtree, with new [State] + /// objects, to be immediately created if [visible] is true). + final bool maintainState; + + /// Whether to maintain animations within the [sliver] subtree when it is + /// not [visible]. + /// + /// To set this, [maintainState] must also be set. + /// + /// Keeping animations active when the widget is not visible is even more + /// expensive than only maintaining the state. + /// + /// One example when this might be useful is if the subtree is animating its + /// layout in time with an [AnimationController], and the result of that + /// layout is being used to influence some other logic. If this flag is false, + /// then any [AnimationController]s hosted inside the [sliver] subtree will be + /// muted while the [visible] flag is false. + /// + /// If this property is true, no [TickerMode] widget is used. + /// + /// If this property is false, then [maintainSize] must also be false. + /// + /// Dynamically changing this value may cause the current state of the + /// subtree to be lost (and a new instance of the subtree, with new [State] + /// objects, to be immediately created if [visible] is true). + final bool maintainAnimation; + + /// Whether to maintain space for where the sliver would have been. + /// + /// To set this, [maintainAnimation] must also be set. + /// + /// Maintaining the size when the sliver is not [visible] is not notably more + /// expensive than just keeping animations running without maintaining the + /// size, and may in some circumstances be slightly cheaper if the subtree is + /// simple and the [visible] property is frequently toggled, since it avoids + /// triggering a layout change when the [visible] property is toggled. If the + /// [sliver] subtree is not trivial then it is significantly cheaper to not + /// even keep the state (see [maintainState]). + /// + /// If this property is false, [SliverOffstage] is used. + /// + /// If this property is false, then [maintainSemantics] and + /// [maintainInteractivity] must also be false. + /// + /// Dynamically changing this value may cause the current state of the + /// subtree to be lost (and a new instance of the subtree, with new [State] + /// objects, to be immediately created if [visible] is true). + final bool maintainSize; + + /// Whether to maintain the semantics for the sliver when it is hidden (e.g. + /// for accessibility). + /// + /// To set this, [maintainSize] must also be set. + /// + /// By default, with [maintainSemantics] set to false, the [sliver] is not + /// visible to accessibility tools when it is hidden from the user. If this + /// flag is set to true, then accessibility tools will report the widget as if + /// it was present. + final bool maintainSemantics; + + /// Whether to allow the sliver to be interactive when hidden. + /// + /// To set this, [maintainSize] must also be set. + /// + /// By default, with [maintainInteractivity] set to false, touch events cannot + /// reach the [sliver] when it is hidden from the user. If this flag is set to + /// true, then touch events will nonetheless be passed through. + final bool maintainInteractivity; + + @override + Widget build(BuildContext context) { + if (maintainSize) { + Widget result = sliver; + result = SliverIgnorePointer( + ignoring: !visible && !maintainInteractivity, + sliver: result, + ); + return _SliverVisibility( + visible: visible, + maintainSemantics: maintainSemantics, + sliver: result, + ); + } + assert(!maintainInteractivity); + assert(!maintainSemantics); + assert(!maintainSize); + if (maintainState) { + Widget result = sliver; + if (!maintainAnimation) { + result = TickerMode(enabled: visible, child: sliver); + } + return SliverOffstage( + sliver: result, + offstage: !visible, + ); + } + assert(!maintainAnimation); + assert(!maintainState); + return visible ? sliver : replacementSliver; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(FlagProperty('visible', value: visible, ifFalse: 'hidden', ifTrue: 'visible')); + properties.add(FlagProperty('maintainState', value: maintainState, ifFalse: 'maintainState')); + properties.add(FlagProperty('maintainAnimation', value: maintainAnimation, ifFalse: 'maintainAnimation')); + properties.add(FlagProperty('maintainSize', value: maintainSize, ifFalse: 'maintainSize')); + properties.add(FlagProperty('maintainSemantics', value: maintainSemantics, ifFalse: 'maintainSemantics')); + properties.add(FlagProperty('maintainInteractivity', value: maintainInteractivity, ifFalse: 'maintainInteractivity')); + } +} + +// A widget that conditionally hides its child, but without the forced compositing of `Opacity`. +// +// A fully opaque `Opacity` widget is required to leave its opacity layer in the layer tree. This +// forces all parent render objects to also composite, which can break a simple scene into many +// different layers. This can be significantly more expensive, so the issue is avoided by a +// specialized render object that does not ever force compositing. +class _Visibility extends SingleChildRenderObjectWidget { + const _Visibility({ required this.visible, required this.maintainSemantics, super.child }); + + final bool visible; + final bool maintainSemantics; + + @override + _RenderVisibility createRenderObject(BuildContext context) { + return _RenderVisibility(visible, maintainSemantics); + } + + @override + void updateRenderObject(BuildContext context, _RenderVisibility renderObject) { + renderObject + ..visible = visible + ..maintainSemantics = maintainSemantics; + } +} + +class _RenderVisibility extends RenderProxyBox { + _RenderVisibility(this._visible, this._maintainSemantics); + + bool get visible => _visible; + bool _visible; + set visible(bool value) { + if (value == visible) { + return; + } + _visible = value; + markNeedsPaint(); + } + + bool get maintainSemantics => _maintainSemantics; + bool _maintainSemantics; + set maintainSemantics(bool value) { + if (value == maintainSemantics) { + return; + } + _maintainSemantics = value; + markNeedsSemanticsUpdate(); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (maintainSemantics || visible) { + super.visitChildrenForSemantics(visitor); + } + } + + @override + void paint(PaintingContext context, Offset offset) { + if (!visible) { + return; + } + super.paint(context, offset); + } +} + +// A widget that conditionally hides its child, but without the forced compositing of `SliverOpacity`. +// +// A fully opaque `SliverOpacity` widget is required to leave its opacity layer in the layer tree. +// This forces all parent render objects to also composite, which can break a simple scene into many +// different layers. This can be significantly more expensive, so the issue is avoided by a +// specialized render object that does not ever force compositing. +class _SliverVisibility extends SingleChildRenderObjectWidget { + const _SliverVisibility({ required this.visible, required this.maintainSemantics, Widget? sliver }) + : super(child: sliver); + + final bool visible; + final bool maintainSemantics; + + @override + RenderObject createRenderObject(BuildContext context) { + return _RenderSliverVisibility(visible, maintainSemantics); + } + + @override + void updateRenderObject(BuildContext context, _RenderSliverVisibility renderObject) { + renderObject + ..visible = visible + ..maintainSemantics = maintainSemantics; + } +} + +class _RenderSliverVisibility extends RenderProxySliver { + _RenderSliverVisibility(this._visible, this._maintainSemantics); + + bool get visible => _visible; + bool _visible; + set visible(bool value) { + if (value == visible) { + return; + } + _visible = value; + markNeedsPaint(); + } + + bool get maintainSemantics => _maintainSemantics; + bool _maintainSemantics; + set maintainSemantics(bool value) { + if (value == maintainSemantics) { + return; + } + _maintainSemantics = value; + markNeedsSemanticsUpdate(); + } + + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (maintainSemantics || visible) { + super.visitChildrenForSemantics(visitor); + } + } + + @override + void paint(PaintingContext context, Offset offset) { + if (!visible) { + return; + } + super.paint(context, offset); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/widget_inspector.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/widget_inspector.dart new file mode 100644 index 0000000000000000000000000000000000000000..2ad546bedad23f93cbce72c15a07394795a005a2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -0,0 +1,3889 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:collection' show HashMap; +import 'dart:convert'; +import 'dart:developer' as developer; +import 'dart:math' as math; +import 'dart:ui' as ui + show + ClipOp, + FlutterView, + Image, + ImageByteFormat, + Paragraph, + Picture, + PictureRecorder, + PointMode, + SceneBuilder, + Vertices; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:meta/meta_meta.dart'; + +import 'app.dart'; +import 'basic.dart'; +import 'binding.dart'; +import 'debug.dart'; +import 'framework.dart'; +import 'gesture_detector.dart'; +import 'service_extensions.dart'; +import 'view.dart'; + +/// Signature for the builder callback used by +/// [WidgetInspector.selectButtonBuilder]. +typedef InspectorSelectButtonBuilder = Widget Function(BuildContext context, VoidCallback onPressed); + +/// Signature for a method that registers the service extension `callback` with +/// the given `name`. +/// +/// Used as argument to [WidgetInspectorService.initServiceExtensions]. The +/// [BindingBase.registerServiceExtension] implements this signature. +typedef RegisterServiceExtensionCallback = void Function({ + required String name, + required ServiceExtensionCallback callback, +}); + +/// A layer that mimics the behavior of another layer. +/// +/// A proxy layer is used for cases where a layer needs to be placed into +/// multiple trees of layers. +class _ProxyLayer extends Layer { + _ProxyLayer(this._layer); + + final Layer _layer; + + @override + void addToScene(ui.SceneBuilder builder) { + _layer.addToScene(builder); + } + + @override + @protected + bool findAnnotations<S extends Object>( + AnnotationResult<S> result, + Offset localPosition, { + required bool onlyFirst, + }) { + return _layer.findAnnotations(result, localPosition, onlyFirst: onlyFirst); + } +} + +/// A [Canvas] that multicasts all method calls to a main canvas and a +/// secondary screenshot canvas so that a screenshot can be recorded at the same +/// time as performing a normal paint. +class _MulticastCanvas implements Canvas { + _MulticastCanvas({ + required Canvas main, + required Canvas screenshot, + }) : _main = main, + _screenshot = screenshot; + + final Canvas _main; + final Canvas _screenshot; + + @override + void clipPath(Path path, { bool doAntiAlias = true }) { + _main.clipPath(path, doAntiAlias: doAntiAlias); + _screenshot.clipPath(path, doAntiAlias: doAntiAlias); + } + + @override + void clipRRect(RRect rrect, { bool doAntiAlias = true }) { + _main.clipRRect(rrect, doAntiAlias: doAntiAlias); + _screenshot.clipRRect(rrect, doAntiAlias: doAntiAlias); + } + + @override + void clipRect(Rect rect, { ui.ClipOp clipOp = ui.ClipOp.intersect, bool doAntiAlias = true }) { + _main.clipRect(rect, clipOp: clipOp, doAntiAlias: doAntiAlias); + _screenshot.clipRect(rect, clipOp: clipOp, doAntiAlias: doAntiAlias); + } + + @override + void drawArc(Rect rect, double startAngle, double sweepAngle, bool useCenter, Paint paint) { + _main.drawArc(rect, startAngle, sweepAngle, useCenter, paint); + _screenshot.drawArc(rect, startAngle, sweepAngle, useCenter, paint); + } + + @override + void drawAtlas(ui.Image atlas, List<RSTransform> transforms, List<Rect> rects, List<Color>? colors, BlendMode? blendMode, Rect? cullRect, Paint paint) { + _main.drawAtlas(atlas, transforms, rects, colors, blendMode, cullRect, paint); + _screenshot.drawAtlas(atlas, transforms, rects, colors, blendMode, cullRect, paint); + } + + @override + void drawCircle(Offset c, double radius, Paint paint) { + _main.drawCircle(c, radius, paint); + _screenshot.drawCircle(c, radius, paint); + } + + @override + void drawColor(Color color, BlendMode blendMode) { + _main.drawColor(color, blendMode); + _screenshot.drawColor(color, blendMode); + } + + @override + void drawDRRect(RRect outer, RRect inner, Paint paint) { + _main.drawDRRect(outer, inner, paint); + _screenshot.drawDRRect(outer, inner, paint); + } + + @override + void drawImage(ui.Image image, Offset p, Paint paint) { + _main.drawImage(image, p, paint); + _screenshot.drawImage(image, p, paint); + } + + @override + void drawImageNine(ui.Image image, Rect center, Rect dst, Paint paint) { + _main.drawImageNine(image, center, dst, paint); + _screenshot.drawImageNine(image, center, dst, paint); + } + + @override + void drawImageRect(ui.Image image, Rect src, Rect dst, Paint paint) { + _main.drawImageRect(image, src, dst, paint); + _screenshot.drawImageRect(image, src, dst, paint); + } + + @override + void drawLine(Offset p1, Offset p2, Paint paint) { + _main.drawLine(p1, p2, paint); + _screenshot.drawLine(p1, p2, paint); + } + + @override + void drawOval(Rect rect, Paint paint) { + _main.drawOval(rect, paint); + _screenshot.drawOval(rect, paint); + } + + @override + void drawPaint(Paint paint) { + _main.drawPaint(paint); + _screenshot.drawPaint(paint); + } + + @override + void drawParagraph(ui.Paragraph paragraph, Offset offset) { + _main.drawParagraph(paragraph, offset); + _screenshot.drawParagraph(paragraph, offset); + } + + @override + void drawPath(Path path, Paint paint) { + _main.drawPath(path, paint); + _screenshot.drawPath(path, paint); + } + + @override + void drawPicture(ui.Picture picture) { + _main.drawPicture(picture); + _screenshot.drawPicture(picture); + } + + @override + void drawPoints(ui.PointMode pointMode, List<Offset> points, Paint paint) { + _main.drawPoints(pointMode, points, paint); + _screenshot.drawPoints(pointMode, points, paint); + } + + @override + void drawRRect(RRect rrect, Paint paint) { + _main.drawRRect(rrect, paint); + _screenshot.drawRRect(rrect, paint); + } + + @override + void drawRawAtlas(ui.Image atlas, Float32List rstTransforms, Float32List rects, Int32List? colors, BlendMode? blendMode, Rect? cullRect, Paint paint) { + _main.drawRawAtlas(atlas, rstTransforms, rects, colors, blendMode, cullRect, paint); + _screenshot.drawRawAtlas(atlas, rstTransforms, rects, colors, blendMode, cullRect, paint); + } + + @override + void drawRawPoints(ui.PointMode pointMode, Float32List points, Paint paint) { + _main.drawRawPoints(pointMode, points, paint); + _screenshot.drawRawPoints(pointMode, points, paint); + } + + @override + void drawRect(Rect rect, Paint paint) { + _main.drawRect(rect, paint); + _screenshot.drawRect(rect, paint); + } + + @override + void drawShadow(Path path, Color color, double elevation, bool transparentOccluder) { + _main.drawShadow(path, color, elevation, transparentOccluder); + _screenshot.drawShadow(path, color, elevation, transparentOccluder); + } + + @override + void drawVertices(ui.Vertices vertices, BlendMode blendMode, Paint paint) { + _main.drawVertices(vertices, blendMode, paint); + _screenshot.drawVertices(vertices, blendMode, paint); + } + + @override + int getSaveCount() { + // The main canvas is used instead of the screenshot canvas as the main + // canvas is guaranteed to be consistent with the canvas expected by the + // normal paint pipeline so any logic depending on getSaveCount() will + // behave the same as for the regular paint pipeline. + return _main.getSaveCount(); + } + + @override + void restore() { + _main.restore(); + _screenshot.restore(); + } + + @override + void rotate(double radians) { + _main.rotate(radians); + _screenshot.rotate(radians); + } + + @override + void save() { + _main.save(); + _screenshot.save(); + } + + @override + void saveLayer(Rect? bounds, Paint paint) { + _main.saveLayer(bounds, paint); + _screenshot.saveLayer(bounds, paint); + } + + @override + void scale(double sx, [ double? sy ]) { + _main.scale(sx, sy); + _screenshot.scale(sx, sy); + } + + @override + void skew(double sx, double sy) { + _main.skew(sx, sy); + _screenshot.skew(sx, sy); + } + + @override + void transform(Float64List matrix4) { + _main.transform(matrix4); + _screenshot.transform(matrix4); + } + + @override + void translate(double dx, double dy) { + _main.translate(dx, dy); + _screenshot.translate(dx, dy); + } + + @override + dynamic noSuchMethod(Invocation invocation) { + super.noSuchMethod(invocation); + } +} + +Rect _calculateSubtreeBoundsHelper(RenderObject object, Matrix4 transform) { + Rect bounds = MatrixUtils.transformRect(transform, object.semanticBounds); + + object.visitChildren((RenderObject child) { + final Matrix4 childTransform = transform.clone(); + object.applyPaintTransform(child, childTransform); + Rect childBounds = _calculateSubtreeBoundsHelper(child, childTransform); + final Rect? paintClip = object.describeApproximatePaintClip(child); + if (paintClip != null) { + final Rect transformedPaintClip = MatrixUtils.transformRect( + transform, + paintClip, + ); + childBounds = childBounds.intersect(transformedPaintClip); + } + + if (childBounds.isFinite && !childBounds.isEmpty) { + bounds = bounds.isEmpty ? childBounds : bounds.expandToInclude(childBounds); + } + }); + + return bounds; +} + +/// Calculate bounds for a render object and all of its descendants. +Rect _calculateSubtreeBounds(RenderObject object) { + return _calculateSubtreeBoundsHelper(object, Matrix4.identity()); +} + +/// A layer that omits its own offset when adding children to the scene so that +/// screenshots render to the scene in the local coordinate system of the layer. +class _ScreenshotContainerLayer extends OffsetLayer { + @override + void addToScene(ui.SceneBuilder builder) { + addChildrenToScene(builder); + } +} + +/// Data shared between nested [_ScreenshotPaintingContext] objects recording +/// a screenshot. +class _ScreenshotData { + _ScreenshotData({ + required this.target, + }) : containerLayer = _ScreenshotContainerLayer(); + + /// Target to take a screenshot of. + final RenderObject target; + + /// Root of the layer tree containing the screenshot. + final OffsetLayer containerLayer; + + /// Whether the screenshot target has already been found in the render tree. + bool foundTarget = false; + + /// Whether paint operations should record to the screenshot. + /// + /// At least one of [includeInScreenshot] and [includeInRegularContext] must + /// be true. + bool includeInScreenshot = false; + + /// Whether paint operations should record to the regular context. + /// + /// This should only be set to false before paint operations that should only + /// apply to the screenshot such rendering debug information about the + /// [target]. + /// + /// At least one of [includeInScreenshot] and [includeInRegularContext] must + /// be true. + bool includeInRegularContext = true; + + /// Offset of the screenshot corresponding to the offset [target] was given as + /// part of the regular paint. + Offset get screenshotOffset { + assert(foundTarget); + return containerLayer.offset; + } + set screenshotOffset(Offset offset) { + containerLayer.offset = offset; + } + + /// Releases allocated resources. + @mustCallSuper + void dispose() { + containerLayer.dispose(); + } +} + +/// A place to paint to build screenshots of [RenderObject]s. +/// +/// Requires that the render objects have already painted successfully as part +/// of the regular rendering pipeline. +/// This painting context behaves the same as standard [PaintingContext] with +/// instrumentation added to compute a screenshot of a specified [RenderObject] +/// added. To correctly mimic the behavior of the regular rendering pipeline, the +/// full subtree of the first [RepaintBoundary] ancestor of the specified +/// [RenderObject] will also be rendered rather than just the subtree of the +/// render object. +class _ScreenshotPaintingContext extends PaintingContext { + _ScreenshotPaintingContext({ + required ContainerLayer containerLayer, + required Rect estimatedBounds, + required _ScreenshotData screenshotData, + }) : _data = screenshotData, + super(containerLayer, estimatedBounds); + + final _ScreenshotData _data; + + // Recording state + PictureLayer? _screenshotCurrentLayer; + ui.PictureRecorder? _screenshotRecorder; + Canvas? _screenshotCanvas; + _MulticastCanvas? _multicastCanvas; + + @override + Canvas get canvas { + if (_data.includeInScreenshot) { + if (_screenshotCanvas == null) { + _startRecordingScreenshot(); + } + assert(_screenshotCanvas != null); + return _data.includeInRegularContext ? _multicastCanvas! : _screenshotCanvas!; + } else { + assert(_data.includeInRegularContext); + return super.canvas; + } + } + + bool get _isScreenshotRecording { + final bool hasScreenshotCanvas = _screenshotCanvas != null; + assert(() { + if (hasScreenshotCanvas) { + assert(_screenshotCurrentLayer != null); + assert(_screenshotRecorder != null); + assert(_screenshotCanvas != null); + } else { + assert(_screenshotCurrentLayer == null); + assert(_screenshotRecorder == null); + assert(_screenshotCanvas == null); + } + return true; + }()); + return hasScreenshotCanvas; + } + + void _startRecordingScreenshot() { + assert(_data.includeInScreenshot); + assert(!_isScreenshotRecording); + _screenshotCurrentLayer = PictureLayer(estimatedBounds); + _screenshotRecorder = ui.PictureRecorder(); + _screenshotCanvas = Canvas(_screenshotRecorder!); + _data.containerLayer.append(_screenshotCurrentLayer!); + if (_data.includeInRegularContext) { + _multicastCanvas = _MulticastCanvas( + main: super.canvas, + screenshot: _screenshotCanvas!, + ); + } else { + _multicastCanvas = null; + } + } + + @override + void stopRecordingIfNeeded() { + super.stopRecordingIfNeeded(); + _stopRecordingScreenshotIfNeeded(); + } + + void _stopRecordingScreenshotIfNeeded() { + if (!_isScreenshotRecording) { + return; + } + // There is no need to ever draw repaint rainbows as part of the screenshot. + _screenshotCurrentLayer!.picture = _screenshotRecorder!.endRecording(); + _screenshotCurrentLayer = null; + _screenshotRecorder = null; + _multicastCanvas = null; + _screenshotCanvas = null; + } + + @override + void appendLayer(Layer layer) { + if (_data.includeInRegularContext) { + super.appendLayer(layer); + if (_data.includeInScreenshot) { + assert(!_isScreenshotRecording); + // We must use a proxy layer here as the layer is already attached to + // the regular layer tree. + _data.containerLayer.append(_ProxyLayer(layer)); + } + } else { + // Only record to the screenshot. + assert(!_isScreenshotRecording); + assert(_data.includeInScreenshot); + layer.remove(); + _data.containerLayer.append(layer); + return; + } + } + + @override + PaintingContext createChildContext(ContainerLayer childLayer, Rect bounds) { + if (_data.foundTarget) { + // We have already found the screenshotTarget in the layer tree + // so we can optimize and use a standard PaintingContext. + return super.createChildContext(childLayer, bounds); + } else { + return _ScreenshotPaintingContext( + containerLayer: childLayer, + estimatedBounds: bounds, + screenshotData: _data, + ); + } + } + + @override + void paintChild(RenderObject child, Offset offset) { + final bool isScreenshotTarget = identical(child, _data.target); + if (isScreenshotTarget) { + assert(!_data.includeInScreenshot); + assert(!_data.foundTarget); + _data.foundTarget = true; + _data.screenshotOffset = offset; + _data.includeInScreenshot = true; + } + super.paintChild(child, offset); + if (isScreenshotTarget) { + _stopRecordingScreenshotIfNeeded(); + _data.includeInScreenshot = false; + } + } + + /// Captures an image of the current state of [renderObject] and its children. + /// + /// The returned [ui.Image] has uncompressed raw RGBA bytes, will be offset + /// by the top-left corner of [renderBounds], and have dimensions equal to the + /// size of [renderBounds] multiplied by [pixelRatio]. + /// + /// To use [toImage], the render object must have gone through the paint phase + /// (i.e. [debugNeedsPaint] must be false). + /// + /// The [pixelRatio] describes the scale between the logical pixels and the + /// size of the output image. It is independent of the + /// [window.devicePixelRatio] for the device, so specifying 1.0 (the default) + /// will give you a 1:1 mapping between logical pixels and the output pixels + /// in the image. + /// + /// The [debugPaint] argument specifies whether the image should include the + /// output of [RenderObject.debugPaint] for [renderObject] with + /// [debugPaintSizeEnabled] set to true. Debug paint information is not + /// included for the children of [renderObject] so that it is clear precisely + /// which object the debug paint information references. + /// + /// See also: + /// + /// * [RenderRepaintBoundary.toImage] for a similar API for [RenderObject]s + /// that are repaint boundaries that can be used outside of the inspector. + /// * [OffsetLayer.toImage] for a similar API at the layer level. + /// * [dart:ui.Scene.toImage] for more information about the image returned. + static Future<ui.Image> toImage( + RenderObject renderObject, + Rect renderBounds, { + double pixelRatio = 1.0, + bool debugPaint = false, + }) async { + RenderObject repaintBoundary = renderObject; + while (!repaintBoundary.isRepaintBoundary) { + repaintBoundary = repaintBoundary.parent!; + } + final _ScreenshotData data = _ScreenshotData(target: renderObject); + final _ScreenshotPaintingContext context = _ScreenshotPaintingContext( + containerLayer: repaintBoundary.debugLayer!, + estimatedBounds: repaintBoundary.paintBounds, + screenshotData: data, + ); + + if (identical(renderObject, repaintBoundary)) { + // Painting the existing repaint boundary to the screenshot is sufficient. + // We don't just take a direct screenshot of the repaint boundary as we + // want to capture debugPaint information as well. + data.containerLayer.append(_ProxyLayer(repaintBoundary.debugLayer!)); + data.foundTarget = true; + final OffsetLayer offsetLayer = repaintBoundary.debugLayer! as OffsetLayer; + data.screenshotOffset = offsetLayer.offset; + } else { + // Repaint everything under the repaint boundary. + // We call debugInstrumentRepaintCompositedChild instead of paintChild as + // we need to force everything under the repaint boundary to repaint. + PaintingContext.debugInstrumentRepaintCompositedChild( + repaintBoundary, + customContext: context, + ); + } + + // The check that debugPaintSizeEnabled is false exists to ensure we only + // call debugPaint when it wasn't already called. + if (debugPaint && !debugPaintSizeEnabled) { + data.includeInRegularContext = false; + // Existing recording may be to a canvas that draws to both the normal and + // screenshot canvases. + context.stopRecordingIfNeeded(); + assert(data.foundTarget); + data.includeInScreenshot = true; + + debugPaintSizeEnabled = true; + try { + renderObject.debugPaint(context, data.screenshotOffset); + } finally { + debugPaintSizeEnabled = false; + context.stopRecordingIfNeeded(); + } + } + + // We must build the regular scene before we can build the screenshot + // scene as building the screenshot scene assumes addToScene has already + // been called successfully for all layers in the regular scene. + repaintBoundary.debugLayer!.buildScene(ui.SceneBuilder()); + + final ui.Image image; + + try { + image = await data.containerLayer.toImage(renderBounds, pixelRatio: pixelRatio); + } finally { + data.dispose(); + } + + return image; + } +} + +/// A class describing a step along a path through a tree of [DiagnosticsNode] +/// objects. +/// +/// This class is used to bundle all data required to display the tree with just +/// the nodes along a path expanded into a single JSON payload. +class _DiagnosticsPathNode { + /// Creates a full description of a step in a path through a tree of + /// [DiagnosticsNode] objects. + _DiagnosticsPathNode({ + required this.node, + required this.children, + this.childIndex, + }); + + /// Node at the point in the path this [_DiagnosticsPathNode] is describing. + final DiagnosticsNode node; + + /// Children of the [node] being described. + /// + /// This value is cached instead of relying on `node.getChildren()` as that + /// method call might create new [DiagnosticsNode] objects for each child + /// and we would prefer to use the identical [DiagnosticsNode] for each time + /// a node exists in the path. + final List<DiagnosticsNode> children; + + /// Index of the child that the path continues on. + /// + /// Equal to null if the path does not continue. + final int? childIndex; +} + +List<_DiagnosticsPathNode>? _followDiagnosticableChain( + List<Diagnosticable> chain, { + String? name, + DiagnosticsTreeStyle? style, +}) { + final List<_DiagnosticsPathNode> path = <_DiagnosticsPathNode>[]; + if (chain.isEmpty) { + return path; + } + DiagnosticsNode diagnostic = chain.first.toDiagnosticsNode(name: name, style: style); + for (int i = 1; i < chain.length; i += 1) { + final Diagnosticable target = chain[i]; + bool foundMatch = false; + final List<DiagnosticsNode> children = diagnostic.getChildren(); + for (int j = 0; j < children.length; j += 1) { + final DiagnosticsNode child = children[j]; + if (child.value == target) { + foundMatch = true; + path.add(_DiagnosticsPathNode( + node: diagnostic, + children: children, + childIndex: j, + )); + diagnostic = child; + break; + } + } + assert(foundMatch); + } + path.add(_DiagnosticsPathNode(node: diagnostic, children: diagnostic.getChildren())); + return path; +} + +/// Signature for the selection change callback used by +/// [WidgetInspectorService.selectionChangedCallback]. +typedef InspectorSelectionChangedCallback = void Function(); + +/// Structure to help reference count Dart objects referenced by a GUI tool +/// using [WidgetInspectorService]. +/// +/// Does not hold the object from garbage collection. +@visibleForTesting +class InspectorReferenceData { + /// Creates an instance of [InspectorReferenceData]. + InspectorReferenceData(Object object, this.id) { + // These types are not supported by [WeakReference]. + // See https://api.dart.dev/stable/3.0.2/dart-core/WeakReference-class.html + if (object is String || object is num || object is bool) { + _value = object; + return; + } + + _ref = WeakReference<Object>(object); + } + + WeakReference<Object>? _ref; + + Object? _value; + + /// The id of the object in the widget inspector records. + final String id; + + /// The number of times the object has been referenced. + int count = 1; + + /// The value. + Object? get value { + if (_ref != null) { + return _ref!.target; + } + return _value; + } +} + +// Production implementation of [WidgetInspectorService]. +class _WidgetInspectorService with WidgetInspectorService { + _WidgetInspectorService() { + selection.addListener(() { + if (selectionChangedCallback != null) { + selectionChangedCallback!(); + } + }); + } +} + +/// Service used by GUI tools to interact with the [WidgetInspector]. +/// +/// Calls to this object are typically made from GUI tools such as the [Flutter +/// IntelliJ Plugin](https://github.com/flutter/flutter-intellij/blob/master/README.md) +/// using the [Dart VM Service](https://github.com/dart-lang/sdk/blob/main/runtime/vm/service/service.md). +/// This class uses its own object id and manages object lifecycles itself +/// instead of depending on the [object ids](https://github.com/dart-lang/sdk/blob/main/runtime/vm/service/service.md#getobject) +/// specified by the VM Service Protocol because the VM Service Protocol ids +/// expire unpredictably. Object references are tracked in groups so that tools +/// that clients can use dereference all objects in a group with a single +/// operation making it easier to avoid memory leaks. +/// +/// All methods in this class are appropriate to invoke from debugging tools +/// using the VM service protocol to evaluate Dart expressions of the +/// form `WidgetInspectorService.instance.methodName(arg1, arg2, ...)`. If you +/// make changes to any instance method of this class you need to verify that +/// the [Flutter IntelliJ Plugin](https://github.com/flutter/flutter-intellij/blob/master/README.md) +/// widget inspector support still works with the changes. +/// +/// All methods returning String values return JSON. +mixin WidgetInspectorService { + /// Ring of cached JSON values to prevent JSON from being garbage + /// collected before it can be requested over the VM service protocol. + final List<String?> _serializeRing = List<String?>.filled(20, null); + int _serializeRingIndex = 0; + + /// The current [WidgetInspectorService]. + static WidgetInspectorService get instance => _instance; + static WidgetInspectorService _instance = _WidgetInspectorService(); + + /// Whether the inspector is in select mode. + /// + /// In select mode, pointer interactions trigger widget selection instead of + /// normal interactions. Otherwise the previously selected widget is + /// highlighted but the application can be interacted with normally. + @visibleForTesting + final ValueNotifier<bool> isSelectMode = ValueNotifier<bool>(true); + + @protected + static set instance(WidgetInspectorService instance) { + _instance = instance; + } + + static bool _debugServiceExtensionsRegistered = false; + + /// Ground truth tracking what object(s) are currently selected used by both + /// GUI tools such as the Flutter IntelliJ Plugin and the [WidgetInspector] + /// displayed on the device. + final InspectorSelection selection = InspectorSelection(); + + /// Callback typically registered by the [WidgetInspector] to receive + /// notifications when [selection] changes. + /// + /// The Flutter IntelliJ Plugin does not need to listen for this event as it + /// instead listens for `dart:developer` `inspect` events which also trigger + /// when the inspection target changes on device. + InspectorSelectionChangedCallback? selectionChangedCallback; + + /// The VM service protocol does not keep alive object references so this + /// class needs to manually manage groups of objects that should be kept + /// alive. + final Map<String, Set<InspectorReferenceData>> _groups = <String, Set<InspectorReferenceData>>{}; + final Map<String, InspectorReferenceData> _idToReferenceData = <String, InspectorReferenceData>{}; + final WeakMap<Object, String> _objectToId = WeakMap<Object, String>(); + int _nextId = 0; + + /// The pubRootDirectories that are currently configured for the widget inspector. + List<String>? _pubRootDirectories; + + /// Memoization for [_isLocalCreationLocation]. + final HashMap<String, bool> _isLocalCreationCache = HashMap<String, bool>(); + + bool _trackRebuildDirtyWidgets = false; + bool _trackRepaintWidgets = false; + + /// Registers a service extension method with the given name (full + /// name "ext.flutter.inspector.name"). + /// + /// The given callback is called when the extension method is called. The + /// callback must return a value that can be converted to JSON using + /// `json.encode()` (see [JsonEncoder]). The return value is stored as a + /// property named `result` in the JSON. In case of failure, the failure is + /// reported to the remote caller and is dumped to the logs. + @protected + void registerServiceExtension({ + required String name, + required ServiceExtensionCallback callback, + required RegisterServiceExtensionCallback registerExtension, + }) { + registerExtension( + name: 'inspector.$name', + callback: callback, + ); + } + + /// Registers a service extension method with the given name (full + /// name "ext.flutter.inspector.name"), which takes no arguments. + void _registerSignalServiceExtension({ + required String name, + required FutureOr<Object?> Function() callback, + required RegisterServiceExtensionCallback registerExtension, + }) { + registerServiceExtension( + name: name, + callback: (Map<String, String> parameters) async { + return <String, Object?>{'result': await callback()}; + }, + registerExtension: registerExtension, + ); + } + + /// Registers a service extension method with the given name (full + /// name "ext.flutter.inspector.name"), which takes a single optional argument + /// "objectGroup" specifying what group is used to manage lifetimes of + /// object references in the returned JSON (see [disposeGroup]). + /// If "objectGroup" is omitted, the returned JSON will not include any object + /// references to avoid leaking memory. + void _registerObjectGroupServiceExtension({ + required String name, + required FutureOr<Object?> Function(String objectGroup) callback, + required RegisterServiceExtensionCallback registerExtension, + }) { + registerServiceExtension( + name: name, + callback: (Map<String, String> parameters) async { + return <String, Object?>{'result': await callback(parameters['objectGroup']!)}; + }, + registerExtension: registerExtension, + ); + } + + /// Registers a service extension method with the given name (full + /// name "ext.flutter.inspector.name"), which takes a single argument + /// "enabled" which can have the value "true" or the value "false" + /// or can be omitted to read the current value. (Any value other + /// than "true" is considered equivalent to "false". Other arguments + /// are ignored.) + /// + /// Calls the `getter` callback to obtain the value when + /// responding to the service extension method being called. + /// + /// Calls the `setter` callback with the new value when the + /// service extension method is called with a new value. + void _registerBoolServiceExtension({ + required String name, + required AsyncValueGetter<bool> getter, + required AsyncValueSetter<bool> setter, + required RegisterServiceExtensionCallback registerExtension, + }) { + registerServiceExtension( + name: name, + callback: (Map<String, String> parameters) async { + if (parameters.containsKey('enabled')) { + final bool value = parameters['enabled'] == 'true'; + await setter(value); + _postExtensionStateChangedEvent(name, value); + } + return <String, dynamic>{'enabled': await getter() ? 'true' : 'false'}; + }, + registerExtension: registerExtension, + ); + } + + /// Sends an event when a service extension's state is changed. + /// + /// Clients should listen for this event to stay aware of the current service + /// extension state. Any service extension that manages a state should call + /// this method on state change. + /// + /// `value` reflects the newly updated service extension value. + /// + /// This will be called automatically for service extensions registered via + /// [registerBoolServiceExtension]. + void _postExtensionStateChangedEvent(String name, Object? value) { + postEvent( + 'Flutter.ServiceExtensionStateChanged', + <String, Object?>{ + 'extension': 'ext.flutter.inspector.$name', + 'value': value, + }, + ); + } + + /// Registers a service extension method with the given name (full + /// name "ext.flutter.inspector.name") which takes an optional parameter named + /// "arg" and a required parameter named "objectGroup" used to control the + /// lifetimes of object references in the returned JSON (see [disposeGroup]). + void _registerServiceExtensionWithArg({ + required String name, + required FutureOr<Object?> Function(String? objectId, String objectGroup) callback, + required RegisterServiceExtensionCallback registerExtension, + }) { + registerServiceExtension( + name: name, + callback: (Map<String, String> parameters) async { + assert(parameters.containsKey('objectGroup')); + return <String, Object?>{ + 'result': await callback(parameters['arg'], parameters['objectGroup']!), + }; + }, + registerExtension: registerExtension, + ); + } + + /// Registers a service extension method with the given name (full + /// name "ext.flutter.inspector.name"), that takes arguments + /// "arg0", "arg1", "arg2", ..., "argn". + void _registerServiceExtensionVarArgs({ + required String name, + required FutureOr<Object?> Function(List<String> args) callback, + required RegisterServiceExtensionCallback registerExtension, + }) { + registerServiceExtension( + name: name, + callback: (Map<String, String> parameters) async { + final List<String> args = <String>[]; + int index = 0; + while (true) { + final String name = 'arg$index'; + if (parameters.containsKey(name)) { + args.add(parameters[name]!); + } else { + break; + } + index++; + } + // Verify that the only arguments other than perhaps 'isolateId' are + // arguments we have already handled. + assert(index == parameters.length || (index == parameters.length - 1 && parameters.containsKey('isolateId'))); + return <String, Object?>{'result': await callback(args)}; + }, + registerExtension: registerExtension, + ); + } + + /// Cause the entire tree to be rebuilt. This is used by development tools + /// when the application code has changed and is being hot-reloaded, to cause + /// the widget tree to pick up any changed implementations. + /// + /// This is expensive and should not be called except during development. + @protected + Future<void> forceRebuild() { + final WidgetsBinding binding = WidgetsBinding.instance; + if (binding.rootElement != null) { + binding.buildOwner!.reassemble(binding.rootElement!); + return binding.endOfFrame; + } + return Future<void>.value(); + } + + static const String _consoleObjectGroup = 'console-group'; + + int _errorsSinceReload = 0; + + void _reportStructuredError(FlutterErrorDetails details) { + final Map<String, Object?> errorJson = _nodeToJson( + details.toDiagnosticsNode(), + InspectorSerializationDelegate( + groupName: _consoleObjectGroup, + subtreeDepth: 5, + includeProperties: true, + maxDescendantsTruncatableNode: 5, + service: this, + ), + )!; + + errorJson['errorsSinceReload'] = _errorsSinceReload; + if (_errorsSinceReload == 0) { + errorJson['renderedErrorText'] = TextTreeRenderer( + wrapWidthProperties: FlutterError.wrapWidth, + maxDescendentsTruncatableNode: 5, + ).render(details.toDiagnosticsNode(style: DiagnosticsTreeStyle.error)).trimRight(); + } else { + errorJson['renderedErrorText'] = 'Another exception was thrown: ${details.summary}'; + } + + _errorsSinceReload += 1; + postEvent('Flutter.Error', errorJson); + } + + /// Resets the count of errors since the last hot reload. + /// + /// This data is sent to clients as part of the 'Flutter.Error' service + /// protocol event. Clients may choose to display errors received after the + /// first error differently. + void _resetErrorCount() { + _errorsSinceReload = 0; + } + + /// Whether structured errors are enabled. + /// + /// Structured errors provide semantic information that can be used by IDEs + /// to enhance the display of errors with rich formatting. + bool isStructuredErrorsEnabled() { + // This is a debug mode only feature and will default to false for + // profile mode. + bool enabled = false; + assert(() { + // TODO(kenz): add support for structured errors on the web. + enabled = const bool.fromEnvironment('flutter.inspector.structuredErrors', defaultValue: !kIsWeb); + return true; + }()); + return enabled; + } + + /// Called to register service extensions. + /// + /// See also: + /// + /// * <https://github.com/dart-lang/sdk/blob/main/runtime/vm/service/service.md#rpcs-requests-and-responses> + /// * [BindingBase.initServiceExtensions], which explains when service + /// extensions can be used. + void initServiceExtensions(RegisterServiceExtensionCallback registerExtension) { + final FlutterExceptionHandler defaultExceptionHandler = FlutterError.presentError; + + if (isStructuredErrorsEnabled()) { + FlutterError.presentError = _reportStructuredError; + } + assert(!_debugServiceExtensionsRegistered); + assert(() { + _debugServiceExtensionsRegistered = true; + return true; + }()); + + SchedulerBinding.instance.addPersistentFrameCallback(_onFrameStart); + + _registerBoolServiceExtension( + name: WidgetInspectorServiceExtensions.structuredErrors.name, + getter: () async => FlutterError.presentError == _reportStructuredError, + setter: (bool value) { + FlutterError.presentError = value ? _reportStructuredError : defaultExceptionHandler; + return Future<void>.value(); + }, + registerExtension: registerExtension, + ); + + _registerBoolServiceExtension( + name: WidgetInspectorServiceExtensions.show.name, + getter: () async => WidgetsApp.debugShowWidgetInspectorOverride, + setter: (bool value) { + if (WidgetsApp.debugShowWidgetInspectorOverride != value) { + WidgetsApp.debugShowWidgetInspectorOverride = value; + } + return Future<void>.value(); + }, + registerExtension: registerExtension, + ); + + if (isWidgetCreationTracked()) { + // Service extensions that are only supported if widget creation locations + // are tracked. + _registerBoolServiceExtension( + name: WidgetInspectorServiceExtensions.trackRebuildDirtyWidgets.name, + getter: () async => _trackRebuildDirtyWidgets, + setter: (bool value) async { + if (value == _trackRebuildDirtyWidgets) { + return; + } + _rebuildStats.resetCounts(); + _trackRebuildDirtyWidgets = value; + if (value) { + assert(debugOnRebuildDirtyWidget == null); + debugOnRebuildDirtyWidget = _onRebuildWidget; + // Trigger a rebuild so there are baseline stats for rebuilds + // performed by the app. + await forceRebuild(); + return; + } else { + debugOnRebuildDirtyWidget = null; + return; + } + }, + registerExtension: registerExtension, + ); + + _registerBoolServiceExtension( + name: WidgetInspectorServiceExtensions.trackRepaintWidgets.name, + getter: () async => _trackRepaintWidgets, + setter: (bool value) async { + if (value == _trackRepaintWidgets) { + return; + } + _repaintStats.resetCounts(); + _trackRepaintWidgets = value; + if (value) { + assert(debugOnProfilePaint == null); + debugOnProfilePaint = _onPaint; + // Trigger an immediate paint so the user has some baseline painting + // stats to view. + void markTreeNeedsPaint(RenderObject renderObject) { + renderObject.markNeedsPaint(); + renderObject.visitChildren(markTreeNeedsPaint); + } + RendererBinding.instance.renderViews.forEach(markTreeNeedsPaint); + } else { + debugOnProfilePaint = null; + } + }, + registerExtension: registerExtension, + ); + } + + _registerSignalServiceExtension( + name: WidgetInspectorServiceExtensions.disposeAllGroups.name, + callback: () async { + disposeAllGroups(); + return null; + }, + registerExtension: registerExtension, + ); + _registerObjectGroupServiceExtension( + name: WidgetInspectorServiceExtensions.disposeGroup.name, + callback: (String name) async { + disposeGroup(name); + return null; + }, + registerExtension: registerExtension, + ); + _registerSignalServiceExtension( + name: WidgetInspectorServiceExtensions.isWidgetTreeReady.name, + callback: isWidgetTreeReady, + registerExtension: registerExtension, + ); + _registerServiceExtensionWithArg( + name: WidgetInspectorServiceExtensions.disposeId.name, + callback: (String? objectId, String objectGroup) async { + disposeId(objectId, objectGroup); + return null; + }, + registerExtension: registerExtension, + ); + _registerServiceExtensionVarArgs( + name: WidgetInspectorServiceExtensions.setPubRootDirectories.name, + callback: (List<String> args) async { + setPubRootDirectories(args); + return null; + }, + registerExtension: registerExtension, + ); + _registerServiceExtensionVarArgs( + name: WidgetInspectorServiceExtensions.addPubRootDirectories.name, + callback: (List<String> args) async { + addPubRootDirectories(args); + return null; + }, + registerExtension: registerExtension, + ); + _registerServiceExtensionVarArgs( + name: WidgetInspectorServiceExtensions.removePubRootDirectories.name, + callback: (List<String> args) async { + removePubRootDirectories(args); + return null; + }, + registerExtension: registerExtension, + ); + registerServiceExtension( + name: WidgetInspectorServiceExtensions.getPubRootDirectories.name, + callback: pubRootDirectories, + registerExtension: registerExtension, + ); + _registerServiceExtensionWithArg( + name: WidgetInspectorServiceExtensions.setSelectionById.name, + callback: setSelectionById, + registerExtension: registerExtension, + ); + _registerServiceExtensionWithArg( + name: WidgetInspectorServiceExtensions.getParentChain.name, + callback: _getParentChain, + registerExtension: registerExtension, + ); + _registerServiceExtensionWithArg( + name: WidgetInspectorServiceExtensions.getProperties.name, + callback: _getProperties, + registerExtension: registerExtension, + ); + _registerServiceExtensionWithArg( + name: WidgetInspectorServiceExtensions.getChildren.name, + callback: _getChildren, + registerExtension: registerExtension, + ); + + _registerServiceExtensionWithArg( + name: WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + callback: _getChildrenSummaryTree, + registerExtension: registerExtension, + ); + + _registerServiceExtensionWithArg( + name: WidgetInspectorServiceExtensions.getChildrenDetailsSubtree.name, + callback: _getChildrenDetailsSubtree, + registerExtension: registerExtension, + ); + + _registerObjectGroupServiceExtension( + name: WidgetInspectorServiceExtensions.getRootWidget.name, + callback: _getRootWidget, + registerExtension: registerExtension, + ); + _registerObjectGroupServiceExtension( + name: WidgetInspectorServiceExtensions.getRootWidgetSummaryTree.name, + callback: _getRootWidgetSummaryTree, + registerExtension: registerExtension, + ); + registerServiceExtension( + name: WidgetInspectorServiceExtensions.getRootWidgetSummaryTreeWithPreviews.name, + callback: _getRootWidgetSummaryTreeWithPreviews, + registerExtension: registerExtension, + ); + registerServiceExtension( + name: WidgetInspectorServiceExtensions.getDetailsSubtree.name, + callback: (Map<String, String> parameters) async { + assert(parameters.containsKey('objectGroup')); + final String? subtreeDepth = parameters['subtreeDepth']; + return <String, Object?>{ + 'result': _getDetailsSubtree( + parameters['arg'], + parameters['objectGroup'], + subtreeDepth != null ? int.parse(subtreeDepth) : 2, + ), + }; + }, + registerExtension: registerExtension, + ); + _registerServiceExtensionWithArg( + name: WidgetInspectorServiceExtensions.getSelectedWidget.name, + callback: _getSelectedWidget, + registerExtension: registerExtension, + ); + _registerServiceExtensionWithArg( + name: WidgetInspectorServiceExtensions.getSelectedSummaryWidget.name, + callback: _getSelectedSummaryWidget, + registerExtension: registerExtension, + ); + + _registerSignalServiceExtension( + name: WidgetInspectorServiceExtensions.isWidgetCreationTracked.name, + callback: isWidgetCreationTracked, + registerExtension: registerExtension, + ); + registerServiceExtension( + name: WidgetInspectorServiceExtensions.screenshot.name, + callback: (Map<String, String> parameters) async { + assert(parameters.containsKey('id')); + assert(parameters.containsKey('width')); + assert(parameters.containsKey('height')); + + final ui.Image? image = await screenshot( + toObject(parameters['id']), + width: double.parse(parameters['width']!), + height: double.parse(parameters['height']!), + margin: parameters.containsKey('margin') ? + double.parse(parameters['margin']!) : 0.0, + maxPixelRatio: parameters.containsKey('maxPixelRatio') ? + double.parse(parameters['maxPixelRatio']!) : 1.0, + debugPaint: parameters['debugPaint'] == 'true', + ); + if (image == null) { + return <String, Object?>{'result': null}; + } + final ByteData? byteData = await image.toByteData(format:ui.ImageByteFormat.png); + image.dispose(); + + return <String, Object>{ + 'result': base64.encoder.convert(Uint8List.view(byteData!.buffer)), + }; + }, + registerExtension: registerExtension, + ); + registerServiceExtension( + name: WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + callback: _getLayoutExplorerNode, + registerExtension: registerExtension, + ); + registerServiceExtension( + name: WidgetInspectorServiceExtensions.setFlexFit.name, + callback: _setFlexFit, + registerExtension: registerExtension, + ); + registerServiceExtension( + name: WidgetInspectorServiceExtensions.setFlexFactor.name, + callback: _setFlexFactor, + registerExtension: registerExtension, + ); + registerServiceExtension( + name: WidgetInspectorServiceExtensions.setFlexProperties.name, + callback: _setFlexProperties, + registerExtension: registerExtension, + ); + } + + void _clearStats() { + _rebuildStats.resetCounts(); + _repaintStats.resetCounts(); + } + + /// Clear all InspectorService object references. + /// + /// Use this method only for testing to ensure that object references from one + /// test case do not impact other test cases. + @visibleForTesting + @protected + void disposeAllGroups() { + _groups.clear(); + _idToReferenceData.clear(); + _objectToId.clear(); + _nextId = 0; + } + + /// Reset all InspectorService state. + /// + /// Use this method only for testing to write hermetic tests for + /// WidgetInspectorService. + @visibleForTesting + @protected + @mustCallSuper + void resetAllState() { + disposeAllGroups(); + selection.clear(); + resetPubRootDirectories(); + } + + /// Free all references to objects in a group. + /// + /// Objects and their associated ids in the group may be kept alive by + /// references from a different group. + @protected + void disposeGroup(String name) { + final Set<InspectorReferenceData>? references = _groups.remove(name); + if (references == null) { + return; + } + references.forEach(_decrementReferenceCount); + } + + void _decrementReferenceCount(InspectorReferenceData reference) { + reference.count -= 1; + assert(reference.count >= 0); + if (reference.count == 0) { + final Object? value = reference.value; + if (value != null) { + _objectToId.remove(value); + } + _idToReferenceData.remove(reference.id); + } + } + + /// Returns a unique id for [object] that will remain live at least until + /// [disposeGroup] is called on [groupName]. + @protected + String? toId(Object? object, String groupName) { + if (object == null) { + return null; + } + + final Set<InspectorReferenceData> group = _groups.putIfAbsent(groupName, () => Set<InspectorReferenceData>.identity()); + String? id = _objectToId[object]; + InspectorReferenceData referenceData; + if (id == null) { + // TODO(polina-c): comment here why we increase memory footprint by the prefix 'inspector-'. + // https://github.com/flutter/devtools/issues/5995 + id = 'inspector-$_nextId'; + _nextId += 1; + _objectToId[object] = id; + referenceData = InspectorReferenceData(object, id); + _idToReferenceData[id] = referenceData; + group.add(referenceData); + } else { + referenceData = _idToReferenceData[id]!; + if (group.add(referenceData)) { + referenceData.count += 1; + } + } + return id; + } + + /// Returns whether the application has rendered its first frame and it is + /// appropriate to display the Widget tree in the inspector. + @protected + bool isWidgetTreeReady([ String? groupName ]) { + return WidgetsBinding.instance.debugDidSendFirstFrameEvent; + } + + /// Returns the Dart object associated with a reference id. + /// + /// The `groupName` parameter is not required by is added to regularize the + /// API surface of the methods in this class called from the Flutter IntelliJ + /// Plugin. + @protected + Object? toObject(String? id, [ String? groupName ]) { + if (id == null) { + return null; + } + + final InspectorReferenceData? data = _idToReferenceData[id]; + if (data == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary('Id does not exist.')]); + } + return data.value; + } + + /// Returns the object to introspect to determine the source location of an + /// object's class. + /// + /// The Dart object for the id is returned for all cases but [Element] objects + /// where the [Widget] configuring the [Element] is returned instead as the + /// class of the [Widget] is more relevant than the class of the [Element]. + /// + /// The `groupName` parameter is not required by is added to regularize the + /// API surface of methods called from the Flutter IntelliJ Plugin. + @protected + Object? toObjectForSourceLocation(String id, [ String? groupName ]) { + final Object? object = toObject(id); + if (object is Element) { + return object.widget; + } + return object; + } + + /// Remove the object with the specified `id` from the specified object + /// group. + /// + /// If the object exists in other groups it will remain alive and the object + /// id will remain valid. + @protected + void disposeId(String? id, String groupName) { + if (id == null) { + return; + } + + final InspectorReferenceData? referenceData = _idToReferenceData[id]; + if (referenceData == null) { + throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary('Id does not exist')]); + } + if (_groups[groupName]?.remove(referenceData) != true) { + throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary('Id is not in group')]); + } + _decrementReferenceCount(referenceData); + } + + /// Set the list of directories that should be considered part of the local + /// project. + /// + /// The local project directories are used to distinguish widgets created by + /// the local project from widgets created from inside the framework + /// or other packages. + @protected + @Deprecated( + 'Use addPubRootDirectories instead. ' + 'This feature was deprecated after v3.18.0-2.0.pre.', + ) + void setPubRootDirectories(List<String> pubRootDirectories) { + addPubRootDirectories(pubRootDirectories); + } + + /// Resets the list of directories, that should be considered part of the + /// local project, to the value passed in [pubRootDirectories]. + /// + /// The local project directories are used to distinguish widgets created by + /// the local project from widgets created from inside the framework + /// or other packages. + @visibleForTesting + @protected + void resetPubRootDirectories() { + _pubRootDirectories = <String>[]; + _isLocalCreationCache.clear(); + } + + /// Add a list of directories that should be considered part of the local + /// project. + /// + /// The local project directories are used to distinguish widgets created by + /// the local project from widgets created from inside the framework + /// or other packages. + @protected + void addPubRootDirectories(List<String> pubRootDirectories) { + pubRootDirectories = pubRootDirectories.map<String>((String directory) => Uri.parse(directory).path).toList(); + + final Set<String> directorySet = Set<String>.from(pubRootDirectories); + if (_pubRootDirectories != null) { + directorySet.addAll(_pubRootDirectories!); + } + + _pubRootDirectories = directorySet.toList(); + _isLocalCreationCache.clear(); + } + + /// Remove a list of directories that should no longer be considered part + /// of the local project. + /// + /// The local project directories are used to distinguish widgets created by + /// the local project from widgets created from inside the framework + /// or other packages. + @protected + void removePubRootDirectories(List<String> pubRootDirectories) { + if (_pubRootDirectories == null) { + return; + } + pubRootDirectories = pubRootDirectories.map<String>((String directory) => Uri.parse(directory).path).toList(); + + final Set<String> directorySet = Set<String>.from(_pubRootDirectories!); + directorySet.removeAll(pubRootDirectories); + + _pubRootDirectories = directorySet.toList(); + _isLocalCreationCache.clear(); + } + + /// Returns the list of directories that should be considered part of the + /// local project. + @protected + @visibleForTesting + Future<Map<String, dynamic>> pubRootDirectories( + Map<String, String> parameters, + ) { + return Future<Map<String, Object>>.value(<String, Object>{ + 'result': _pubRootDirectories ?? <String>[], + }); + } + + /// Set the [WidgetInspector] selection to the object matching the specified + /// id if the object is valid object to set as the inspector selection. + /// + /// Returns true if the selection was changed. + /// + /// The `groupName` parameter is not required by is added to regularize the + /// API surface of methods called from the Flutter IntelliJ Plugin. + @protected + bool setSelectionById(String? id, [ String? groupName ]) { + return setSelection(toObject(id), groupName); + } + + /// Set the [WidgetInspector] selection to the specified `object` if it is + /// a valid object to set as the inspector selection. + /// + /// Returns true if the selection was changed. + /// + /// The `groupName` parameter is not needed but is specified to regularize the + /// API surface of methods called from the Flutter IntelliJ Plugin. + @protected + bool setSelection(Object? object, [ String? groupName ]) { + if (object is Element || object is RenderObject) { + if (object is Element) { + if (object == selection.currentElement) { + return false; + } + selection.currentElement = object; + _sendInspectEvent(selection.currentElement); + } else { + if (object == selection.current) { + return false; + } + selection.current = object! as RenderObject; + _sendInspectEvent(selection.current); + } + + return true; + } + return false; + } + + /// Notify attached tools to navigate to an object's source location. + void _sendInspectEvent(Object? object){ + inspect(object); + + final _Location? location = _getSelectedSummaryWidgetLocation(null); + if (location != null) { + postEvent( + 'navigate', + <String, Object>{ + 'fileUri': location.file, // URI file path of the location. + 'line': location.line, // 1-based line number. + 'column': location.column, // 1-based column number. + 'source': 'flutter.inspector', + }, + stream: 'ToolEvent', + ); + } + } + + /// Returns a DevTools uri linking to a specific element on the inspector page. + String? _devToolsInspectorUriForElement(Element element) { + if (activeDevToolsServerAddress != null && connectedVmServiceUri != null) { + final String? inspectorRef = toId(element, _consoleObjectGroup); + if (inspectorRef != null) { + return devToolsInspectorUri(inspectorRef); + } + } + return null; + } + + /// Returns the DevTools inspector uri for the given vm service connection and + /// inspector reference. + @visibleForTesting + String devToolsInspectorUri(String inspectorRef) { + assert(activeDevToolsServerAddress != null); + assert(connectedVmServiceUri != null); + + final Uri uri = Uri.parse(activeDevToolsServerAddress!).replace( + queryParameters: <String, dynamic>{ + 'uri': connectedVmServiceUri, + 'inspectorRef': inspectorRef, + }, + ); + + // We cannot add the '/#/inspector' path by means of + // [Uri.replace(path: '/#/inspector')] because the '#' character will be + // encoded when we try to print the url as a string. DevTools will not + // load properly if this character is encoded in the url. + // Related: https://github.com/flutter/devtools/issues/2475. + final String devToolsInspectorUri = uri.toString(); + final int startQueryParamIndex = devToolsInspectorUri.indexOf('?'); + // The query parameter character '?' should be present because we manually + // added query parameters above. + assert(startQueryParamIndex != -1); + return '${devToolsInspectorUri.substring(0, startQueryParamIndex)}' + '/#/inspector' + '${devToolsInspectorUri.substring(startQueryParamIndex)}'; + } + + /// Returns JSON representing the chain of [DiagnosticsNode] instances from + /// root of the tree to the [Element] or [RenderObject] matching `id`. + /// + /// The JSON contains all information required to display a tree view with + /// all nodes other than nodes along the path collapsed. + @protected + String getParentChain(String id, String groupName) { + return _safeJsonEncode(_getParentChain(id, groupName)); + } + + List<Object?> _getParentChain(String? id, String groupName) { + final Object? value = toObject(id); + List<_DiagnosticsPathNode> path; + if (value is RenderObject) { + path = _getRenderObjectParentChain(value, groupName)!; + } else if (value is Element) { + path = _getElementParentChain(value, groupName); + } else { + throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary('Cannot get parent chain for node of type ${value.runtimeType}')]); + } + + return path.map<Object?>((_DiagnosticsPathNode node) => _pathNodeToJson( + node, + InspectorSerializationDelegate(groupName: groupName, service: this), + )).toList(); + } + + Map<String, Object?>? _pathNodeToJson(_DiagnosticsPathNode? pathNode, InspectorSerializationDelegate delegate) { + if (pathNode == null) { + return null; + } + return <String, Object?>{ + 'node': _nodeToJson(pathNode.node, delegate), + 'children': _nodesToJson(pathNode.children, delegate, parent: pathNode.node), + 'childIndex': pathNode.childIndex, + }; + } + + List<Element> _getRawElementParentChain(Element element, { required int? numLocalParents }) { + List<Element> elements = element.debugGetDiagnosticChain(); + if (numLocalParents != null) { + for (int i = 0; i < elements.length; i += 1) { + if (_isValueCreatedByLocalProject(elements[i])) { + numLocalParents = numLocalParents! - 1; + if (numLocalParents <= 0) { + elements = elements.take(i + 1).toList(); + break; + } + } + } + } + return elements.reversed.toList(); + } + + List<_DiagnosticsPathNode> _getElementParentChain(Element element, String groupName, { int? numLocalParents }) { + return _followDiagnosticableChain( + _getRawElementParentChain(element, numLocalParents: numLocalParents), + ) ?? const <_DiagnosticsPathNode>[]; + } + + List<_DiagnosticsPathNode>? _getRenderObjectParentChain(RenderObject? renderObject, String groupName) { + final List<RenderObject> chain = <RenderObject>[]; + while (renderObject != null) { + chain.add(renderObject); + renderObject = renderObject.parent; + } + return _followDiagnosticableChain(chain.reversed.toList()); + } + + Map<String, Object?>? _nodeToJson( + DiagnosticsNode? node, + InspectorSerializationDelegate delegate, + ) { + return node?.toJsonMap(delegate); + } + + bool _isValueCreatedByLocalProject(Object? value) { + final _Location? creationLocation = _getCreationLocation(value); + if (creationLocation == null) { + return false; + } + return _isLocalCreationLocation(creationLocation.file); + } + + bool _isLocalCreationLocationImpl(String locationUri) { + final String file = Uri.parse(locationUri).path; + + // By default check whether the creation location was within package:flutter. + if (_pubRootDirectories == null) { + // TODO(chunhtai): Make it more robust once + // https://github.com/flutter/flutter/issues/32660 is fixed. + return !file.contains('packages/flutter/'); + } + for (final String directory in _pubRootDirectories!) { + if (file.startsWith(directory)) { + return true; + } + } + return false; + } + + /// Memoized version of [_isLocalCreationLocationImpl]. + bool _isLocalCreationLocation(String locationUri) { + final bool? cachedValue = _isLocalCreationCache[locationUri]; + if (cachedValue != null) { + return cachedValue; + } + final bool result = _isLocalCreationLocationImpl(locationUri); + _isLocalCreationCache[locationUri] = result; + return result; + } + + /// Wrapper around `json.encode` that uses a ring of cached values to prevent + /// the Dart garbage collector from collecting objects between when + /// the value is returned over the VM service protocol and when the + /// separate observatory protocol command has to be used to retrieve its full + /// contents. + // + // TODO(jacobr): Replace this with a better solution once + // https://github.com/dart-lang/sdk/issues/32919 is fixed. + String _safeJsonEncode(Object? object) { + final String jsonString = json.encode(object); + _serializeRing[_serializeRingIndex] = jsonString; + _serializeRingIndex = (_serializeRingIndex + 1) % _serializeRing.length; + return jsonString; + } + + List<DiagnosticsNode> _truncateNodes(Iterable<DiagnosticsNode> nodes, int maxDescendentsTruncatableNode) { + if (nodes.every((DiagnosticsNode node) => node.value is Element) && isWidgetCreationTracked()) { + final List<DiagnosticsNode> localNodes = nodes + .where((DiagnosticsNode node) => _isValueCreatedByLocalProject(node.value)) + .toList(); + if (localNodes.isNotEmpty) { + return localNodes; + } + } + return nodes.take(maxDescendentsTruncatableNode).toList(); + } + + List<Map<String, Object?>> _nodesToJson( + List<DiagnosticsNode> nodes, + InspectorSerializationDelegate delegate, { + required DiagnosticsNode? parent, + }) { + return DiagnosticsNode.toJsonList(nodes, parent, delegate); + } + + /// Returns a JSON representation of the properties of the [DiagnosticsNode] + /// object that `diagnosticsNodeId` references. + @protected + String getProperties(String diagnosticsNodeId, String groupName) { + return _safeJsonEncode(_getProperties(diagnosticsNodeId, groupName)); + } + + List<Object> _getProperties(String? diagnosticableId, String groupName) { + final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticableId); + if (node == null) { + return const <Object>[]; + } + return _nodesToJson(node.getProperties(), InspectorSerializationDelegate(groupName: groupName, service: this), parent: node); + } + + /// Returns a JSON representation of the children of the [DiagnosticsNode] + /// object that `diagnosticsNodeId` references. + String getChildren(String diagnosticsNodeId, String groupName) { + return _safeJsonEncode(_getChildren(diagnosticsNodeId, groupName)); + } + + List<Object> _getChildren(String? diagnosticsNodeId, String groupName) { + final DiagnosticsNode? node = toObject(diagnosticsNodeId) as DiagnosticsNode?; + final InspectorSerializationDelegate delegate = InspectorSerializationDelegate(groupName: groupName, service: this); + return _nodesToJson(node == null ? const <DiagnosticsNode>[] : _getChildrenFiltered(node, delegate), delegate, parent: node); + } + + /// Returns a JSON representation of the children of the [DiagnosticsNode] + /// object that `diagnosticsNodeId` references only including children that + /// were created directly by user code. + /// + /// {@template flutter.widgets.WidgetInspectorService.getChildrenSummaryTree} + /// Requires [Widget] creation locations which are only available for debug + /// mode builds when the `--track-widget-creation` flag is enabled on the call + /// to the `flutter` tool. This flag is enabled by default in debug builds. + /// {@endtemplate} + /// + /// See also: + /// + /// * [isWidgetCreationTracked] which indicates whether this method can be + /// used. + String getChildrenSummaryTree(String diagnosticsNodeId, String groupName) { + return _safeJsonEncode(_getChildrenSummaryTree(diagnosticsNodeId, groupName)); + } + + DiagnosticsNode? _idToDiagnosticsNode(String? diagnosticableId) { + final Object? object = toObject(diagnosticableId); + return objectToDiagnosticsNode(object); + } + + /// If possible, returns [DiagnosticsNode] for the object. + @visibleForTesting + static DiagnosticsNode? objectToDiagnosticsNode(Object? object) { + if (object is Diagnosticable) { + return object.toDiagnosticsNode(); + } + return null; + } + + List<Object> _getChildrenSummaryTree(String? diagnosticableId, String groupName) { + final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticableId); + if (node == null) { + return <Object>[]; + } + + final InspectorSerializationDelegate delegate = InspectorSerializationDelegate(groupName: groupName, summaryTree: true, service: this); + return _nodesToJson(_getChildrenFiltered(node, delegate), delegate, parent: node); + } + + /// Returns a JSON representation of the children of the [DiagnosticsNode] + /// object that [diagnosticableId] references providing information needed + /// for the details subtree view. + /// + /// The details subtree shows properties inline and includes all children + /// rather than a filtered set of important children. + String getChildrenDetailsSubtree(String diagnosticableId, String groupName) { + return _safeJsonEncode(_getChildrenDetailsSubtree(diagnosticableId, groupName)); + } + + List<Object> _getChildrenDetailsSubtree(String? diagnosticableId, String groupName) { + final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticableId); + // With this value of minDepth we only expand one extra level of important nodes. + final InspectorSerializationDelegate delegate = InspectorSerializationDelegate(groupName: groupName, includeProperties: true, service: this); + return _nodesToJson(node == null ? const <DiagnosticsNode>[] : _getChildrenFiltered(node, delegate), delegate, parent: node); + } + + bool _shouldShowInSummaryTree(DiagnosticsNode node) { + if (node.level == DiagnosticLevel.error) { + return true; + } + final Object? value = node.value; + if (value is! Diagnosticable) { + return true; + } + if (value is! Element || !isWidgetCreationTracked()) { + // Creation locations are not available so include all nodes in the + // summary tree. + return true; + } + return _isValueCreatedByLocalProject(value); + } + + List<DiagnosticsNode> _getChildrenFiltered( + DiagnosticsNode node, + InspectorSerializationDelegate delegate, + ) { + return _filterChildren(node.getChildren(), delegate); + } + + List<DiagnosticsNode> _filterChildren( + List<DiagnosticsNode> nodes, + InspectorSerializationDelegate delegate, + ) { + final List<DiagnosticsNode> children = <DiagnosticsNode>[ + for (final DiagnosticsNode child in nodes) + if (!delegate.summaryTree || _shouldShowInSummaryTree(child)) + child + else + ..._getChildrenFiltered(child, delegate), + ]; + return children; + } + + /// Returns a JSON representation of the [DiagnosticsNode] for the root + /// [Element]. + String getRootWidget(String groupName) { + return _safeJsonEncode(_getRootWidget(groupName)); + } + + Map<String, Object?>? _getRootWidget(String groupName) { + return _nodeToJson(WidgetsBinding.instance.rootElement?.toDiagnosticsNode(), InspectorSerializationDelegate(groupName: groupName, service: this)); + } + + /// Returns a JSON representation of the [DiagnosticsNode] for the root + /// [Element] showing only nodes that should be included in a summary tree. + String getRootWidgetSummaryTree(String groupName) { + return _safeJsonEncode(_getRootWidgetSummaryTree(groupName)); + } + + Map<String, Object?>? _getRootWidgetSummaryTree( + String groupName, { + Map<String, Object>? Function(DiagnosticsNode, InspectorSerializationDelegate)? addAdditionalPropertiesCallback, + }) { + return _nodeToJson( + WidgetsBinding.instance.rootElement?.toDiagnosticsNode(), + InspectorSerializationDelegate( + groupName: groupName, + subtreeDepth: 1000000, + summaryTree: true, + service: this, + addAdditionalPropertiesCallback: addAdditionalPropertiesCallback, + ), + ); + } + + + Future<Map<String, Object?>> _getRootWidgetSummaryTreeWithPreviews( + Map<String, String> parameters, + ) { + final String groupName = parameters['groupName']!; + final Map<String, Object?>? result = _getRootWidgetSummaryTree( + groupName, + addAdditionalPropertiesCallback: (DiagnosticsNode node, InspectorSerializationDelegate? delegate) { + final Map<String, Object> additionalJson = <String, Object>{}; + final Object? value = node.value; + if (value is Element) { + final RenderObject? renderObject = value.renderObject; + if (renderObject is RenderParagraph) { + additionalJson['textPreview'] = renderObject.text.toPlainText(); + } + } + return additionalJson; + }, + ); + return Future<Map<String, dynamic>>.value(<String, dynamic>{ + 'result': result, + }); + } + + /// Returns a JSON representation of the subtree rooted at the + /// [DiagnosticsNode] object that `diagnosticsNodeId` references providing + /// information needed for the details subtree view. + /// + /// The number of levels of the subtree that should be returned is specified + /// by the [subtreeDepth] parameter. This value defaults to 2 for backwards + /// compatibility. + /// + /// See also: + /// + /// * [getChildrenDetailsSubtree], a method to get children of a node + /// in the details subtree. + String getDetailsSubtree( + String diagnosticableId, + String groupName, { + int subtreeDepth = 2, + }) { + return _safeJsonEncode(_getDetailsSubtree(diagnosticableId, groupName, subtreeDepth)); + } + + Map<String, Object?>? _getDetailsSubtree( + String? diagnosticableId, + String? groupName, + int subtreeDepth, + ) { + final DiagnosticsNode? root = _idToDiagnosticsNode(diagnosticableId); + if (root == null) { + return null; + } + return _nodeToJson( + root, + InspectorSerializationDelegate( + groupName: groupName, + subtreeDepth: subtreeDepth, + includeProperties: true, + service: this, + ), + ); + } + + /// Returns a [DiagnosticsNode] representing the currently selected [Element]. + @protected + String getSelectedWidget(String? previousSelectionId, String groupName) { + if (previousSelectionId != null) { + debugPrint('previousSelectionId is deprecated in API'); + } + return _safeJsonEncode(_getSelectedWidget(null, groupName)); + } + + /// Captures an image of the current state of an [object] that is a + /// [RenderObject] or [Element]. + /// + /// The returned [ui.Image] has uncompressed raw RGBA bytes and will be scaled + /// to be at most [width] pixels wide and [height] pixels tall. The returned + /// image will never have a scale between logical pixels and the + /// size of the output image larger than maxPixelRatio. + /// [margin] indicates the number of pixels relative to the un-scaled size of + /// the [object] to include as a margin to include around the bounds of the + /// [object] in the screenshot. Including a margin can be useful to capture + /// areas that are slightly outside of the normal bounds of an object such as + /// some debug paint information. + @protected + Future<ui.Image?> screenshot( + Object? object, { + required double width, + required double height, + double margin = 0.0, + double maxPixelRatio = 1.0, + bool debugPaint = false, + }) async { + if (object is! Element && object is! RenderObject) { + return null; + } + final RenderObject? renderObject = object is Element ? object.renderObject : (object as RenderObject?); + if (renderObject == null || !renderObject.attached) { + return null; + } + + if (renderObject.debugNeedsLayout) { + final PipelineOwner owner = renderObject.owner!; + assert(!owner.debugDoingLayout); + owner + ..flushLayout() + ..flushCompositingBits() + ..flushPaint(); + + // If we still need layout, then that means that renderObject was skipped + // in the layout phase and therefore can't be painted. It is clearer to + // return null indicating that a screenshot is unavailable than to return + // an empty image. + if (renderObject.debugNeedsLayout) { + return null; + } + } + + Rect renderBounds = _calculateSubtreeBounds(renderObject); + if (margin != 0.0) { + renderBounds = renderBounds.inflate(margin); + } + if (renderBounds.isEmpty) { + return null; + } + + final double pixelRatio = math.min( + maxPixelRatio, + math.min( + width / renderBounds.width, + height / renderBounds.height, + ), + ); + + return _ScreenshotPaintingContext.toImage( + renderObject, + renderBounds, + pixelRatio: pixelRatio, + debugPaint: debugPaint, + ); + } + + Future<Map<String, Object?>> _getLayoutExplorerNode( + Map<String, String> parameters, + ) { + final String? diagnosticableId = parameters['id']; + final int subtreeDepth = int.parse(parameters['subtreeDepth']!); + final String? groupName = parameters['groupName']; + Map<String, dynamic>? result = <String, dynamic>{}; + final DiagnosticsNode? root = _idToDiagnosticsNode(diagnosticableId); + if (root == null) { + return Future<Map<String, dynamic>>.value(<String, dynamic>{ + 'result': result, + }); + } + result = _nodeToJson( + root, + InspectorSerializationDelegate( + groupName: groupName, + summaryTree: true, + subtreeDepth: subtreeDepth, + service: this, + addAdditionalPropertiesCallback: + (DiagnosticsNode node, InspectorSerializationDelegate delegate) { + final Object? value = node.value; + final RenderObject? renderObject = + value is Element ? value.renderObject : null; + if (renderObject == null) { + return const <String, Object>{}; + } + + final DiagnosticsSerializationDelegate + renderObjectSerializationDelegate = delegate.copyWith( + subtreeDepth: 0, + includeProperties: true, + expandPropertyValues: false, + ); + final Map<String, Object> additionalJson = <String, Object>{ + // Only include renderObject properties separately if this value is not already the renderObject. + // Only include if we are expanding property values to mitigate the risk of infinite loops if + // RenderObjects have properties that are Element objects. + if (value is! RenderObject && delegate.expandPropertyValues) + 'renderObject': renderObject + .toDiagnosticsNode() + .toJsonMap(renderObjectSerializationDelegate), + }; + + final RenderObject? renderParent = renderObject.parent; + if (renderParent != null && + delegate.subtreeDepth > 0 && + delegate.expandPropertyValues) { + final Object? parentCreator = renderParent.debugCreator; + if (parentCreator is DebugCreator) { + additionalJson['parentRenderElement'] = + parentCreator.element.toDiagnosticsNode().toJsonMap( + delegate.copyWith( + subtreeDepth: 0, + includeProperties: true, + ), + ); + // TODO(jacobr): also describe the path back up the tree to + // the RenderParentElement from the current element. It + // could be a surprising distance up the tree if a lot of + // elements don't have their own RenderObjects. + } + } + + try { + if (!renderObject.debugNeedsLayout) { + // ignore: invalid_use_of_protected_member + final Constraints constraints = renderObject.constraints; + final Map<String, Object> constraintsProperty = <String, Object>{ + 'type': constraints.runtimeType.toString(), + 'description': constraints.toString(), + }; + if (constraints is BoxConstraints) { + constraintsProperty.addAll(<String, Object>{ + 'minWidth': constraints.minWidth.toString(), + 'minHeight': constraints.minHeight.toString(), + 'maxWidth': constraints.maxWidth.toString(), + 'maxHeight': constraints.maxHeight.toString(), + }); + } + additionalJson['constraints'] = constraintsProperty; + } + } catch (e) { + // Constraints are sometimes unavailable even though + // debugNeedsLayout is false. + } + + try { + if (renderObject is RenderBox) { + additionalJson['isBox'] = true; + additionalJson['size'] = <String, Object>{ + 'width': renderObject.size.width.toString(), + 'height': renderObject.size.height.toString(), + }; + + final ParentData? parentData = renderObject.parentData; + if (parentData is FlexParentData) { + additionalJson['flexFactor'] = parentData.flex!; + additionalJson['flexFit'] = + (parentData.fit ?? FlexFit.tight).name; + } else if (parentData is BoxParentData) { + final Offset offset = parentData.offset; + additionalJson['parentData'] = <String, Object>{ + 'offsetX': offset.dx.toString(), + 'offsetY': offset.dy.toString(), + }; + } + } else if (renderObject is RenderView) { + additionalJson['size'] = <String, Object>{ + 'width': renderObject.size.width.toString(), + 'height': renderObject.size.height.toString(), + }; + } + } catch (e) { + // Not laid out yet. + } + return additionalJson; + }, + ), + ); + return Future<Map<String, dynamic>>.value(<String, dynamic>{ + 'result': result, + }); + } + + Future<Map<String, dynamic>> _setFlexFit(Map<String, String> parameters) { + final String? id = parameters['id']; + final String parameter = parameters['flexFit']!; + final FlexFit flexFit = _toEnumEntry<FlexFit>(FlexFit.values, parameter); + final Object? object = toObject(id); + bool succeed = false; + if (object != null && object is Element) { + final RenderObject? render = object.renderObject; + final ParentData? parentData = render?.parentData; + if (parentData is FlexParentData) { + parentData.fit = flexFit; + render!.markNeedsLayout(); + succeed = true; + } + } + return Future<Map<String, Object>>.value(<String, Object>{ + 'result': succeed, + }); + } + + Future<Map<String, dynamic>> _setFlexFactor(Map<String, String> parameters) { + final String? id = parameters['id']; + final String flexFactor = parameters['flexFactor']!; + final int? factor = flexFactor == 'null' ? null : int.parse(flexFactor); + final dynamic object = toObject(id); + bool succeed = false; + if (object != null && object is Element) { + final RenderObject? render = object.renderObject; + final ParentData? parentData = render?.parentData; + if (parentData is FlexParentData) { + parentData.flex = factor; + render!.markNeedsLayout(); + succeed = true; + } + } + return Future<Map<String, Object>>.value(<String, Object>{ + 'result': succeed + }); + } + + Future<Map<String, dynamic>> _setFlexProperties( + Map<String, String> parameters, + ) { + final String? id = parameters['id']; + final MainAxisAlignment mainAxisAlignment = _toEnumEntry<MainAxisAlignment>( + MainAxisAlignment.values, + parameters['mainAxisAlignment']!, + ); + final CrossAxisAlignment crossAxisAlignment = + _toEnumEntry<CrossAxisAlignment>( + CrossAxisAlignment.values, + parameters['crossAxisAlignment']!, + ); + final Object? object = toObject(id); + bool succeed = false; + if (object != null && object is Element) { + final RenderObject? render = object.renderObject; + if (render is RenderFlex) { + render.mainAxisAlignment = mainAxisAlignment; + render.crossAxisAlignment = crossAxisAlignment; + render.markNeedsLayout(); + render.markNeedsPaint(); + succeed = true; + } + } + return Future<Map<String, Object>>.value(<String, Object>{ + 'result': succeed + }); + } + + T _toEnumEntry<T>(List<T> enumEntries, String name) { + for (final T entry in enumEntries) { + if (entry.toString() == name) { + return entry; + } + } + throw Exception('Enum value $name not found'); + } + + Map<String, Object?>? _getSelectedWidget(String? previousSelectionId, String groupName) { + return _nodeToJson( + _getSelectedWidgetDiagnosticsNode(previousSelectionId), + InspectorSerializationDelegate(groupName: groupName, service: this), + ); + } + + DiagnosticsNode? _getSelectedWidgetDiagnosticsNode(String? previousSelectionId) { + final DiagnosticsNode? previousSelection = toObject(previousSelectionId) as DiagnosticsNode?; + final Element? current = selection.currentElement; + return current == previousSelection?.value ? previousSelection : current?.toDiagnosticsNode(); + } + + /// Returns a [DiagnosticsNode] representing the currently selected [Element] + /// if the selected [Element] should be shown in the summary tree otherwise + /// returns the first ancestor of the selected [Element] shown in the summary + /// tree. + String getSelectedSummaryWidget(String? previousSelectionId, String groupName) { + if (previousSelectionId != null) { + debugPrint('previousSelectionId is deprecated in API'); + } + return _safeJsonEncode(_getSelectedSummaryWidget(null, groupName)); + } + + _Location? _getSelectedSummaryWidgetLocation(String? previousSelectionId) { + return _getCreationLocation(_getSelectedSummaryDiagnosticsNode(previousSelectionId)?.value); + } + + DiagnosticsNode? _getSelectedSummaryDiagnosticsNode(String? previousSelectionId) { + if (!isWidgetCreationTracked()) { + return _getSelectedWidgetDiagnosticsNode(previousSelectionId); + } + final DiagnosticsNode? previousSelection = toObject(previousSelectionId) as DiagnosticsNode?; + Element? current = selection.currentElement; + if (current != null && !_isValueCreatedByLocalProject(current)) { + Element? firstLocal; + for (final Element candidate in current.debugGetDiagnosticChain()) { + if (_isValueCreatedByLocalProject(candidate)) { + firstLocal = candidate; + break; + } + } + current = firstLocal; + } + return current == previousSelection?.value ? previousSelection : current?.toDiagnosticsNode(); + } + + Map<String, Object?>? _getSelectedSummaryWidget(String? previousSelectionId, String groupName) { + return _nodeToJson(_getSelectedSummaryDiagnosticsNode(previousSelectionId), InspectorSerializationDelegate(groupName: groupName, service: this)); + } + + /// Returns whether [Widget] creation locations are available. + /// + /// {@macro flutter.widgets.WidgetInspectorService.getChildrenSummaryTree} + bool isWidgetCreationTracked() { + _widgetCreationTracked ??= const _WidgetForTypeTests() is _HasCreationLocation; + return _widgetCreationTracked!; + } + + bool? _widgetCreationTracked; + + late Duration _frameStart; + + void _onFrameStart(Duration timeStamp) { + _frameStart = timeStamp; + SchedulerBinding.instance.addPostFrameCallback(_onFrameEnd, debugLabel: 'WidgetInspector.onFrameStart'); + } + + void _onFrameEnd(Duration timeStamp) { + if (_trackRebuildDirtyWidgets) { + _postStatsEvent('Flutter.RebuiltWidgets', _rebuildStats); + } + if (_trackRepaintWidgets) { + _postStatsEvent('Flutter.RepaintWidgets', _repaintStats); + } + } + + void _postStatsEvent(String eventName, _ElementLocationStatsTracker stats) { + postEvent(eventName, stats.exportToJson(_frameStart)); + } + + /// All events dispatched by a [WidgetInspectorService] use this method + /// instead of calling [developer.postEvent] directly. + /// + /// This allows tests for [WidgetInspectorService] to track which events were + /// dispatched by overriding this method. + @protected + void postEvent( + String eventKind, + Map<Object, Object?> eventData, { + String stream = 'Extension', + }) { + developer.postEvent(eventKind, eventData, stream: stream); + } + + /// All events dispatched by a [WidgetInspectorService] use this method + /// instead of calling [developer.inspect]. + /// + /// This allows tests for [WidgetInspectorService] to track which events were + /// dispatched by overriding this method. + @protected + void inspect(Object? object) { + developer.inspect(object); + } + + final _ElementLocationStatsTracker _rebuildStats = _ElementLocationStatsTracker(); + final _ElementLocationStatsTracker _repaintStats = _ElementLocationStatsTracker(); + + void _onRebuildWidget(Element element, bool builtOnce) { + _rebuildStats.add(element); + } + + void _onPaint(RenderObject renderObject) { + try { + final Element? element = (renderObject.debugCreator as DebugCreator?)?.element; + if (element is! RenderObjectElement) { + // This branch should not hit as long as all RenderObjects were created + // by Widgets. It is possible there might be some render objects + // created directly without using the Widget layer so we add this check + // to improve robustness. + return; + } + _repaintStats.add(element); + + // Give all ancestor elements credit for repainting as long as they do + // not have their own associated RenderObject. + element.visitAncestorElements((Element ancestor) { + if (ancestor is RenderObjectElement) { + // This ancestor has its own RenderObject so we can precisely track + // when it repaints. + return false; + } + _repaintStats.add(ancestor); + return true; + }); + } + catch (exception, stack) { + FlutterError.reportError( + FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widget inspector library', + context: ErrorDescription('while tracking widget repaints'), + ), + ); + } + } + + /// This method is called by [WidgetsBinding.performReassemble] to flush caches + /// of obsolete values after a hot reload. + /// + /// Do not call this method directly. Instead, use + /// [BindingBase.reassembleApplication]. + void performReassemble() { + _clearStats(); + _resetErrorCount(); + } +} + +/// Accumulator for a count associated with a specific source location. +/// +/// The accumulator stores whether the source location is [local] and what its +/// [id] for efficiency encoding terse JSON payloads describing counts. +class _LocationCount { + _LocationCount({ + required this.location, + required this.id, + required this.local, + }); + + /// Location id. + final int id; + + /// Whether the location is local to the current project. + final bool local; + + final _Location location; + + int get count => _count; + int _count = 0; + + /// Reset the count. + void reset() { + _count = 0; + } + + /// Increment the count. + void increment() { + _count++; + } +} + +/// A stat tracker that aggregates a performance metric for [Element] objects at +/// the granularity of creation locations in source code. +/// +/// This class is optimized to minimize the size of the JSON payloads describing +/// the aggregate statistics, for stable memory usage, and low CPU usage at the +/// expense of somewhat higher overall memory usage. Stable memory usage is more +/// important than peak memory usage to avoid the false impression that the +/// user's app is leaking memory each frame. +/// +/// The number of unique widget creation locations tends to be at most in the +/// low thousands for regular flutter apps so the peak memory usage for this +/// class is not an issue. +class _ElementLocationStatsTracker { + // All known creation location tracked. + // + // This could also be stored as a `Map<int, _LocationCount>` but this + // representation is more efficient as all location ids from 0 to n are + // typically present. + // + // All logic in this class assumes that if `_stats[i]` is not null + // `_stats[i].id` equals `i`. + final List<_LocationCount?> _stats = <_LocationCount?>[]; + + /// Locations with a non-zero count. + final List<_LocationCount> active = <_LocationCount>[]; + + /// Locations that were added since stats were last exported. + /// + /// Only locations local to the current project are included as a performance + /// optimization. + final List<_LocationCount> newLocations = <_LocationCount>[]; + + /// Increments the count associated with the creation location of [element] if + /// the creation location is local to the current project. + void add(Element element) { + final Object widget = element.widget; + if (widget is! _HasCreationLocation) { + return; + } + final _HasCreationLocation creationLocationSource = widget; + final _Location? location = creationLocationSource._location; + if (location == null) { + return; + } + final int id = _toLocationId(location); + + _LocationCount entry; + if (id >= _stats.length || _stats[id] == null) { + // After the first frame, almost all creation ids will already be in + // _stats so this slow path will rarely be hit. + while (id >= _stats.length) { + _stats.add(null); + } + entry = _LocationCount( + location: location, + id: id, + local: WidgetInspectorService.instance._isLocalCreationLocation(location.file), + ); + if (entry.local) { + newLocations.add(entry); + } + _stats[id] = entry; + } else { + entry = _stats[id]!; + } + + // We could in the future add an option to track stats for all widgets but + // that would significantly increase the size of the events posted using + // [developer.postEvent] and current use cases for this feature focus on + // helping users find problems with their widgets not the platform + // widgets. + if (entry.local) { + if (entry.count == 0) { + active.add(entry); + } + entry.increment(); + } + } + + /// Clear all aggregated statistics. + void resetCounts() { + // We chose to only reset the active counts instead of clearing all data + // to reduce the number memory allocations performed after the first frame. + // Once an app has warmed up, location stats tracking should not + // trigger significant additional memory allocations. Avoiding memory + // allocations is important to minimize the impact this class has on cpu + // and memory performance of the running app. + for (final _LocationCount entry in active) { + entry.reset(); + } + active.clear(); + } + + /// Exports the current counts and then resets the stats to prepare to track + /// the next frame of data. + Map<String, dynamic> exportToJson(Duration startTime) { + final List<int> events = List<int>.filled(active.length * 2, 0); + int j = 0; + for (final _LocationCount stat in active) { + events[j++] = stat.id; + events[j++] = stat.count; + } + + final Map<String, dynamic> json = <String, dynamic>{ + 'startTime': startTime.inMicroseconds, + 'events': events, + }; + + // Encode the new locations using the older encoding. + if (newLocations.isNotEmpty) { + // Add all newly used location ids to the JSON. + final Map<String, List<int>> locationsJson = <String, List<int>>{}; + for (final _LocationCount entry in newLocations) { + final _Location location = entry.location; + final List<int> jsonForFile = locationsJson.putIfAbsent( + location.file, + () => <int>[], + ); + jsonForFile..add(entry.id)..add(location.line)..add(location.column); + } + json['newLocations'] = locationsJson; + } + + // Encode the new locations using the newer encoding (as of v2.4.0). + if (newLocations.isNotEmpty) { + final Map<String, Map<String, List<Object?>>> fileLocationsMap = <String, Map<String, List<Object?>>>{}; + for (final _LocationCount entry in newLocations) { + final _Location location = entry.location; + final Map<String, List<Object?>> locations = fileLocationsMap.putIfAbsent( + location.file, () => <String, List<Object?>>{ + 'ids': <int>[], + 'lines': <int>[], + 'columns': <int>[], + 'names': <String?>[], + }, + ); + + locations['ids']!.add(entry.id); + locations['lines']!.add(location.line); + locations['columns']!.add(location.column); + locations['names']!.add(location.name); + } + json['locations'] = fileLocationsMap; + } + + resetCounts(); + newLocations.clear(); + return json; + } +} + +class _WidgetForTypeTests extends Widget { + const _WidgetForTypeTests(); + + @override + Element createElement() => throw UnimplementedError(); +} + +/// A widget that enables inspecting the child widget's structure. +/// +/// Select a location on your device or emulator and view what widgets and +/// render object that best matches the location. An outline of the selected +/// widget and terse summary information is shown on device with detailed +/// information is shown in the observatory or in IntelliJ when using the +/// Flutter Plugin. +/// +/// The inspector has a select mode and a view mode. +/// +/// In the select mode, tapping the device selects the widget that best matches +/// the location of the touch and switches to view mode. Dragging a finger on +/// the device selects the widget under the drag location but does not switch +/// modes. Touching the very edge of the bounding box of a widget triggers +/// selecting the widget even if another widget that also overlaps that +/// location would otherwise have priority. +/// +/// In the view mode, the previously selected widget is outlined, however, +/// touching the device has the same effect it would have if the inspector +/// wasn't present. This allows interacting with the application and viewing how +/// the selected widget changes position. Clicking on the select icon in the +/// bottom left corner of the application switches back to select mode. +class WidgetInspector extends StatefulWidget { + /// Creates a widget that enables inspection for the child. + const WidgetInspector({ + super.key, + required this.child, + required this.selectButtonBuilder, + }); + + /// The widget that is being inspected. + final Widget child; + + /// A builder that is called to create the select button. + /// + /// The `onPressed` callback passed as an argument to the builder should be + /// hooked up to the returned widget. + final InspectorSelectButtonBuilder? selectButtonBuilder; + + @override + State<WidgetInspector> createState() => _WidgetInspectorState(); +} + +class _WidgetInspectorState extends State<WidgetInspector> + with WidgetsBindingObserver { + + _WidgetInspectorState(); + + Offset? _lastPointerLocation; + + late InspectorSelection selection; + + late bool isSelectMode; + + final GlobalKey _ignorePointerKey = GlobalKey(); + + /// Distance from the edge of the bounding box for an element to consider + /// as selecting the edge of the bounding box. + static const double _edgeHitMargin = 2.0; + + @override + void initState() { + super.initState(); + + WidgetInspectorService.instance.selection + .addListener(_selectionInformationChanged); + WidgetInspectorService.instance.isSelectMode + .addListener(_selectionInformationChanged); + selection = WidgetInspectorService.instance.selection; + isSelectMode = WidgetInspectorService.instance.isSelectMode.value; + } + + @override + void dispose() { + WidgetInspectorService.instance.selection + .removeListener(_selectionInformationChanged); + WidgetInspectorService.instance.isSelectMode + .removeListener(_selectionInformationChanged); + super.dispose(); + } + + void _selectionInformationChanged() => setState((){ + selection = WidgetInspectorService.instance.selection; + isSelectMode = WidgetInspectorService.instance.isSelectMode.value; + }); + + bool _hitTestHelper( + List<RenderObject> hits, + List<RenderObject> edgeHits, + Offset position, + RenderObject object, + Matrix4 transform, + ) { + bool hit = false; + final Matrix4? inverse = Matrix4.tryInvert(transform); + if (inverse == null) { + // We cannot invert the transform. That means the object doesn't appear on + // screen and cannot be hit. + return false; + } + final Offset localPosition = MatrixUtils.transformPoint(inverse, position); + + final List<DiagnosticsNode> children = object.debugDescribeChildren(); + for (int i = children.length - 1; i >= 0; i -= 1) { + final DiagnosticsNode diagnostics = children[i]; + if (diagnostics.style == DiagnosticsTreeStyle.offstage || + diagnostics.value is! RenderObject) { + continue; + } + final RenderObject child = diagnostics.value! as RenderObject; + final Rect? paintClip = object.describeApproximatePaintClip(child); + if (paintClip != null && !paintClip.contains(localPosition)) { + continue; + } + + final Matrix4 childTransform = transform.clone(); + object.applyPaintTransform(child, childTransform); + if (_hitTestHelper(hits, edgeHits, position, child, childTransform)) { + hit = true; + } + } + + final Rect bounds = object.semanticBounds; + if (bounds.contains(localPosition)) { + hit = true; + // Hits that occur on the edge of the bounding box of an object are + // given priority to provide a way to select objects that would + // otherwise be hard to select. + if (!bounds.deflate(_edgeHitMargin).contains(localPosition)) { + edgeHits.add(object); + } + } + if (hit) { + hits.add(object); + } + return hit; + } + + /// Returns the list of render objects located at the given position ordered + /// by priority. + /// + /// All render objects that are not offstage that match the location are + /// included in the list of matches. Priority is given to matches that occur + /// on the edge of a render object's bounding box and to matches found by + /// [RenderBox.hitTest]. + List<RenderObject> hitTest(Offset position, RenderObject root) { + final List<RenderObject> regularHits = <RenderObject>[]; + final List<RenderObject> edgeHits = <RenderObject>[]; + + _hitTestHelper(regularHits, edgeHits, position, root, root.getTransformTo(null)); + // Order matches by the size of the hit area. + double area(RenderObject object) { + final Size size = object.semanticBounds.size; + return size.width * size.height; + } + regularHits.sort((RenderObject a, RenderObject b) => area(a).compareTo(area(b))); + final Set<RenderObject> hits = <RenderObject>{ + ...edgeHits, + ...regularHits, + }; + return hits.toList(); + } + + void _inspectAt(Offset position) { + if (!isSelectMode) { + return; + } + + final RenderIgnorePointer ignorePointer = _ignorePointerKey.currentContext!.findRenderObject()! as RenderIgnorePointer; + final RenderObject userRender = ignorePointer.child!; + final List<RenderObject> selected = hitTest(position, userRender); + + selection.candidates = selected; + } + + void _handlePanDown(DragDownDetails event) { + _lastPointerLocation = event.globalPosition; + _inspectAt(event.globalPosition); + } + + void _handlePanUpdate(DragUpdateDetails event) { + _lastPointerLocation = event.globalPosition; + _inspectAt(event.globalPosition); + } + + void _handlePanEnd(DragEndDetails details) { + // If the pan ends on the edge of the window assume that it indicates the + // pointer is being dragged off the edge of the display not a regular touch + // on the edge of the display. If the pointer is being dragged off the edge + // of the display we do not want to select anything. A user can still select + // a widget that is only at the exact screen margin by tapping. + final ui.FlutterView view = View.of(context); + final Rect bounds = (Offset.zero & (view.physicalSize / view.devicePixelRatio)).deflate(_kOffScreenMargin); + if (!bounds.contains(_lastPointerLocation!)) { + selection.clear(); + } + } + + void _handleTap() { + if (!isSelectMode) { + return; + } + if (_lastPointerLocation != null) { + _inspectAt(_lastPointerLocation!); + WidgetInspectorService.instance._sendInspectEvent(selection.current); + } + + // Only exit select mode if there is a button to return to select mode. + if (widget.selectButtonBuilder != null) { + WidgetInspectorService.instance.isSelectMode.value = false; + } + } + + void _handleEnableSelect() { + WidgetInspectorService.instance.isSelectMode.value = true; + } + + @override + Widget build(BuildContext context) { + // Be careful changing this build method. The _InspectorOverlayLayer + // assumes the root RenderObject for the WidgetInspector will be + // a RenderStack with a _RenderInspectorOverlay as the last child. + return Stack(children: <Widget>[ + GestureDetector( + onTap: _handleTap, + onPanDown: _handlePanDown, + onPanEnd: _handlePanEnd, + onPanUpdate: _handlePanUpdate, + behavior: HitTestBehavior.opaque, + excludeFromSemantics: true, + child: IgnorePointer( + ignoring: isSelectMode, + key: _ignorePointerKey, + child: widget.child, + ), + ), + if (!isSelectMode && widget.selectButtonBuilder != null) + Positioned( + left: _kInspectButtonMargin, + bottom: _kInspectButtonMargin, + child: widget.selectButtonBuilder!(context, _handleEnableSelect), + ), + _InspectorOverlay(selection: selection), + ]); + } +} + +/// Mutable selection state of the inspector. +class InspectorSelection with ChangeNotifier { + /// Creates an instance of [InspectorSelection]. + InspectorSelection() { + if (kFlutterMemoryAllocationsEnabled) { + ChangeNotifier.maybeDispatchObjectCreation(this); + } + } + + /// Render objects that are candidates to be selected. + /// + /// Tools may wish to iterate through the list of candidates. + List<RenderObject> get candidates => _candidates; + List<RenderObject> _candidates = <RenderObject>[]; + set candidates(List<RenderObject> value) { + _candidates = value; + _index = 0; + _computeCurrent(); + } + + /// Index within the list of candidates that is currently selected. + int get index => _index; + int _index = 0; + set index(int value) { + _index = value; + _computeCurrent(); + } + + /// Set the selection to empty. + void clear() { + _candidates = <RenderObject>[]; + _index = 0; + _computeCurrent(); + } + + /// Selected render object typically from the [candidates] list. + /// + /// Setting [candidates] or calling [clear] resets the selection. + /// + /// Returns null if the selection is invalid. + RenderObject? get current => active ? _current : null; + + RenderObject? _current; + set current(RenderObject? value) { + if (_current != value) { + _current = value; + _currentElement = (value?.debugCreator as DebugCreator?)?.element; + notifyListeners(); + } + } + + /// Selected [Element] consistent with the [current] selected [RenderObject]. + /// + /// Setting [candidates] or calling [clear] resets the selection. + /// + /// Returns null if the selection is invalid. + Element? get currentElement { + return _currentElement?.debugIsDefunct ?? true ? null : _currentElement; + } + + Element? _currentElement; + set currentElement(Element? element) { + if (element?.debugIsDefunct ?? false) { + _currentElement = null; + _current = null; + notifyListeners(); + return; + } + if (currentElement != element) { + _currentElement = element; + _current = element!.findRenderObject(); + notifyListeners(); + } + } + + void _computeCurrent() { + if (_index < candidates.length) { + _current = candidates[index]; + _currentElement = (_current?.debugCreator as DebugCreator?)?.element; + notifyListeners(); + } else { + _current = null; + _currentElement = null; + notifyListeners(); + } + } + + /// Whether the selected render object is attached to the tree or has gone + /// out of scope. + bool get active => _current != null && _current!.attached; +} + +class _InspectorOverlay extends LeafRenderObjectWidget { + const _InspectorOverlay({ + required this.selection, + }); + + final InspectorSelection selection; + + @override + _RenderInspectorOverlay createRenderObject(BuildContext context) { + return _RenderInspectorOverlay(selection: selection); + } + + @override + void updateRenderObject(BuildContext context, _RenderInspectorOverlay renderObject) { + renderObject.selection = selection; + } +} + +class _RenderInspectorOverlay extends RenderBox { + _RenderInspectorOverlay({ required InspectorSelection selection }) + : _selection = selection; + + InspectorSelection get selection => _selection; + InspectorSelection _selection; + set selection(InspectorSelection value) { + if (value != _selection) { + _selection = value; + } + markNeedsPaint(); + } + + @override + bool get sizedByParent => true; + + @override + bool get alwaysNeedsCompositing => true; + + @override + Size computeDryLayout(BoxConstraints constraints) { + return constraints.constrain(Size.infinite); + } + + @override + void paint(PaintingContext context, Offset offset) { + assert(needsCompositing); + context.addLayer(_InspectorOverlayLayer( + overlayRect: Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height), + selection: selection, + rootRenderObject: parent is RenderObject ? parent! : null, + )); + } +} + +@immutable +class _TransformedRect { + _TransformedRect(RenderObject object, RenderObject? ancestor) + : rect = object.semanticBounds, + transform = object.getTransformTo(ancestor); + + final Rect rect; + final Matrix4 transform; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _TransformedRect + && other.rect == rect + && other.transform == transform; + } + + @override + int get hashCode => Object.hash(rect, transform); +} + +/// State describing how the inspector overlay should be rendered. +/// +/// The equality operator can be used to determine whether the overlay needs to +/// be rendered again. +@immutable +class _InspectorOverlayRenderState { + const _InspectorOverlayRenderState({ + required this.overlayRect, + required this.selected, + required this.candidates, + required this.tooltip, + required this.textDirection, + }); + + final Rect overlayRect; + final _TransformedRect selected; + final List<_TransformedRect> candidates; + final String tooltip; + final TextDirection textDirection; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is _InspectorOverlayRenderState + && other.overlayRect == overlayRect + && other.selected == selected + && listEquals<_TransformedRect>(other.candidates, candidates) + && other.tooltip == tooltip; + } + + @override + int get hashCode => Object.hash(overlayRect, selected, Object.hashAll(candidates), tooltip); +} + +const int _kMaxTooltipLines = 5; +const Color _kTooltipBackgroundColor = Color.fromARGB(230, 60, 60, 60); +const Color _kHighlightedRenderObjectFillColor = Color.fromARGB(128, 128, 128, 255); +const Color _kHighlightedRenderObjectBorderColor = Color.fromARGB(128, 64, 64, 128); + +/// A layer that outlines the selected [RenderObject] and candidate render +/// objects that also match the last pointer location. +/// +/// This approach is horrific for performance and is only used here because this +/// is limited to debug mode. Do not duplicate the logic in production code. +class _InspectorOverlayLayer extends Layer { + /// Creates a layer that displays the inspector overlay. + _InspectorOverlayLayer({ + required this.overlayRect, + required this.selection, + required this.rootRenderObject, + }) { + bool inDebugMode = false; + assert(() { + inDebugMode = true; + return true; + }()); + if (!inDebugMode) { + throw FlutterError.fromParts(<DiagnosticsNode>[ + ErrorSummary( + 'The inspector should never be used in production mode due to the ' + 'negative performance impact.', + ), + ]); + } + } + + InspectorSelection selection; + + /// The rectangle in this layer's coordinate system that the overlay should + /// occupy. + /// + /// The scene must be explicitly recomposited after this property is changed + /// (as described at [Layer]). + final Rect overlayRect; + + /// Widget inspector root render object. The selection overlay will be painted + /// with transforms relative to this render object. + final RenderObject? rootRenderObject; + + _InspectorOverlayRenderState? _lastState; + + /// Picture generated from _lastState. + ui.Picture? _picture; + + TextPainter? _textPainter; + double? _textPainterMaxWidth; + + @override + void dispose() { + _textPainter?.dispose(); + _textPainter = null; + _picture?.dispose(); + super.dispose(); + } + + @override + void addToScene(ui.SceneBuilder builder) { + if (!selection.active) { + return; + } + + final RenderObject selected = selection.current!; + + if (!_isInInspectorRenderObjectTree(selected)) { + return; + } + + final List<_TransformedRect> candidates = <_TransformedRect>[]; + for (final RenderObject candidate in selection.candidates) { + if (candidate == selected || !candidate.attached + || !_isInInspectorRenderObjectTree(candidate)) { + continue; + } + candidates.add(_TransformedRect(candidate, rootRenderObject)); + } + final _TransformedRect selectedRect = _TransformedRect(selected, rootRenderObject); + final String widgetName = selection.currentElement!.toStringShort(); + final String width = selectedRect.rect.width.toStringAsFixed(1); + final String height = selectedRect.rect.height.toStringAsFixed(1); + + final _InspectorOverlayRenderState state = _InspectorOverlayRenderState( + overlayRect: overlayRect, + selected: selectedRect, + tooltip: '$widgetName ($width x $height)', + textDirection: TextDirection.ltr, + candidates: candidates, + ); + + if (state != _lastState) { + _lastState = state; + _picture?.dispose(); + _picture = _buildPicture(state); + } + builder.addPicture(Offset.zero, _picture!); + } + + ui.Picture _buildPicture(_InspectorOverlayRenderState state) { + final ui.PictureRecorder recorder = ui.PictureRecorder(); + final Canvas canvas = Canvas(recorder, state.overlayRect); + final Size size = state.overlayRect.size; + // The overlay rect could have an offset if the widget inspector does + // not take all the screen. + canvas.translate(state.overlayRect.left, state.overlayRect.top); + + final Paint fillPaint = Paint() + ..style = PaintingStyle.fill + ..color = _kHighlightedRenderObjectFillColor; + + final Paint borderPaint = Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 1.0 + ..color = _kHighlightedRenderObjectBorderColor; + + // Highlight the selected renderObject. + final Rect selectedPaintRect = state.selected.rect.deflate(0.5); + canvas + ..save() + ..transform(state.selected.transform.storage) + ..drawRect(selectedPaintRect, fillPaint) + ..drawRect(selectedPaintRect, borderPaint) + ..restore(); + + // Show all other candidate possibly selected elements. This helps selecting + // render objects by selecting the edge of the bounding box shows all + // elements the user could toggle the selection between. + for (final _TransformedRect transformedRect in state.candidates) { + canvas + ..save() + ..transform(transformedRect.transform.storage) + ..drawRect(transformedRect.rect.deflate(0.5), borderPaint) + ..restore(); + } + + final Rect targetRect = MatrixUtils.transformRect( + state.selected.transform, state.selected.rect, + ); + final Offset target = Offset(targetRect.left, targetRect.center.dy); + const double offsetFromWidget = 9.0; + final double verticalOffset = (targetRect.height) / 2 + offsetFromWidget; + + _paintDescription(canvas, state.tooltip, state.textDirection, target, verticalOffset, size, targetRect); + + // TODO(jacobr): provide an option to perform a debug paint of just the + // selected widget. + return recorder.endRecording(); + } + + void _paintDescription( + Canvas canvas, + String message, + TextDirection textDirection, + Offset target, + double verticalOffset, + Size size, + Rect targetRect, + ) { + canvas.save(); + final double maxWidth = math.max( + size.width - 2 * (_kScreenEdgeMargin + _kTooltipPadding), + 0, + ); + final TextSpan? textSpan = _textPainter?.text as TextSpan?; + if (_textPainter == null || textSpan!.text != message || _textPainterMaxWidth != maxWidth) { + _textPainterMaxWidth = maxWidth; + _textPainter?.dispose(); + _textPainter = TextPainter() + ..maxLines = _kMaxTooltipLines + ..ellipsis = '...' + ..text = TextSpan(style: _messageStyle, text: message) + ..textDirection = textDirection + ..layout(maxWidth: maxWidth); + } + + final Size tooltipSize = _textPainter!.size + const Offset(_kTooltipPadding * 2, _kTooltipPadding * 2); + final Offset tipOffset = positionDependentBox( + size: size, + childSize: tooltipSize, + target: target, + verticalOffset: verticalOffset, + preferBelow: false, + ); + + final Paint tooltipBackground = Paint() + ..style = PaintingStyle.fill + ..color = _kTooltipBackgroundColor; + canvas.drawRect( + Rect.fromPoints( + tipOffset, + tipOffset.translate(tooltipSize.width, tooltipSize.height), + ), + tooltipBackground, + ); + + double wedgeY = tipOffset.dy; + final bool tooltipBelow = tipOffset.dy > target.dy; + if (!tooltipBelow) { + wedgeY += tooltipSize.height; + } + + const double wedgeSize = _kTooltipPadding * 2; + double wedgeX = math.max(tipOffset.dx, target.dx) + wedgeSize * 2; + wedgeX = math.min(wedgeX, tipOffset.dx + tooltipSize.width - wedgeSize * 2); + final List<Offset> wedge = <Offset>[ + Offset(wedgeX - wedgeSize, wedgeY), + Offset(wedgeX + wedgeSize, wedgeY), + Offset(wedgeX, wedgeY + (tooltipBelow ? -wedgeSize : wedgeSize)), + ]; + canvas.drawPath(Path()..addPolygon(wedge, true), tooltipBackground); + _textPainter!.paint(canvas, tipOffset + const Offset(_kTooltipPadding, _kTooltipPadding)); + canvas.restore(); + } + + @override + @protected + bool findAnnotations<S extends Object>( + AnnotationResult<S> result, + Offset localPosition, { + bool? onlyFirst, + }) { + return false; + } + + /// Return whether or not a render object belongs to this inspector widget + /// tree. + /// The inspector selection is static, so if there are multiple inspector + /// overlays in the same app (i.e. an storyboard), a selected or candidate + /// render object may not belong to this tree. + bool _isInInspectorRenderObjectTree(RenderObject child) { + RenderObject? current = child.parent; + while (current != null) { + // We found the widget inspector render object. + if (current is RenderStack + && current.lastChild is _RenderInspectorOverlay) { + return rootRenderObject == current; + } + current = current.parent; + } + return false; + } +} + +const double _kScreenEdgeMargin = 10.0; +const double _kTooltipPadding = 5.0; +const double _kInspectButtonMargin = 10.0; + +/// Interpret pointer up events within with this margin as indicating the +/// pointer is moving off the device. +const double _kOffScreenMargin = 1.0; + +const TextStyle _messageStyle = TextStyle( + color: Color(0xFFFFFFFF), + fontSize: 10.0, + height: 1.2, +); + +/// Interface for classes that track the source code location the their +/// constructor was called from. +/// +/// {@macro flutter.widgets.WidgetInspectorService.getChildrenSummaryTree} +// ignore: unused_element +abstract class _HasCreationLocation { + _Location? get _location; +} + +/// A tuple with file, line, and column number, for displaying human-readable +/// file locations. +class _Location { + const _Location({ + required this.file, + required this.line, + required this.column, + // ignore: unused_element + this.name, + }); + + /// File path of the location. + final String file; + + /// 1-based line number. + final int line; + + /// 1-based column number. + final int column; + + /// Optional name of the parameter or function at this location. + final String? name; + + Map<String, Object?> toJsonMap() { + final Map<String, Object?> json = <String, Object?>{ + 'file': file, + 'line': line, + 'column': column, + }; + if (name != null) { + json['name'] = name; + } + return json; + } + + @override + String toString() { + final List<String> parts = <String>[]; + if (name != null) { + parts.add(name!); + } + parts.add(file); + parts..add('$line')..add('$column'); + return parts.join(':'); + } +} + +bool _isDebugCreator(DiagnosticsNode node) => node is DiagnosticsDebugCreator; + +/// Transformer to parse and gather information about [DiagnosticsDebugCreator]. +/// +/// This function will be registered to [FlutterErrorDetails.propertiesTransformers] +/// in [WidgetsBinding.initInstances]. +/// +/// This is meant to be called only in debug mode. In other modes, it yields an empty list. +Iterable<DiagnosticsNode> debugTransformDebugCreator(Iterable<DiagnosticsNode> properties) { + if (!kDebugMode) { + return <DiagnosticsNode>[]; + } + final List<DiagnosticsNode> pending = <DiagnosticsNode>[]; + ErrorSummary? errorSummary; + for (final DiagnosticsNode node in properties) { + if (node is ErrorSummary) { + errorSummary = node; + break; + } + } + bool foundStackTrace = false; + final List<DiagnosticsNode> result = <DiagnosticsNode>[]; + for (final DiagnosticsNode node in properties) { + if (!foundStackTrace && node is DiagnosticsStackTrace) { + foundStackTrace = true; + } + if (_isDebugCreator(node)) { + result.addAll(_parseDiagnosticsNode(node, errorSummary)); + } else { + if (foundStackTrace) { + pending.add(node); + } else { + result.add(node); + } + } + } + result.addAll(pending); + return result; +} + +/// Transform the input [DiagnosticsNode]. +/// +/// Return null if input [DiagnosticsNode] is not applicable. +Iterable<DiagnosticsNode> _parseDiagnosticsNode( + DiagnosticsNode node, + ErrorSummary? errorSummary, +) { + assert(_isDebugCreator(node)); + try { + final DebugCreator debugCreator = node.value! as DebugCreator; + final Element element = debugCreator.element; + return _describeRelevantUserCode(element, errorSummary); + } catch (error, stack) { + scheduleMicrotask(() { + FlutterError.reportError(FlutterErrorDetails( + exception: error, + stack: stack, + library: 'widget inspector', + informationCollector: () => <DiagnosticsNode>[ + DiagnosticsNode.message('This exception was caught while trying to describe the user-relevant code of another error.'), + ], + )); + }); + return <DiagnosticsNode>[]; + } +} + +Iterable<DiagnosticsNode> _describeRelevantUserCode( + Element element, + ErrorSummary? errorSummary, +) { + if (!WidgetInspectorService.instance.isWidgetCreationTracked()) { + return <DiagnosticsNode>[ + ErrorDescription( + 'Widget creation tracking is currently disabled. Enabling ' + 'it enables improved error messages. It can be enabled by passing ' + '`--track-widget-creation` to `flutter run` or `flutter test`.', + ), + ErrorSpacer(), + ]; + } + + bool isOverflowError() { + if (errorSummary != null && errorSummary.value.isNotEmpty) { + final Object summary = errorSummary.value.first; + if (summary is String && summary.startsWith('A RenderFlex overflowed by')) { + return true; + } + } + return false; + } + + final List<DiagnosticsNode> nodes = <DiagnosticsNode>[]; + bool processElement(Element target) { + // TODO(chunhtai): should print out all the widgets that are about to cross + // package boundaries. + if (debugIsLocalCreationLocation(target)) { + DiagnosticsNode? devToolsDiagnostic; + + // TODO(kenz): once the inspector is better at dealing with broken trees, + // we can enable deep links for more errors than just RenderFlex overflow + // errors. See https://github.com/flutter/flutter/issues/74918. + if (isOverflowError()) { + final String? devToolsInspectorUri = + WidgetInspectorService.instance._devToolsInspectorUriForElement(target); + if (devToolsInspectorUri != null) { + devToolsDiagnostic = DevToolsDeepLinkProperty( + 'To inspect this widget in Flutter DevTools, visit: $devToolsInspectorUri', + devToolsInspectorUri, + ); + } + } + + nodes.addAll(<DiagnosticsNode>[ + DiagnosticsBlock( + name: 'The relevant error-causing widget was', + children: <DiagnosticsNode>[ + ErrorDescription('${target.widget.toStringShort()} ${_describeCreationLocation(target)}'), + ], + ), + ErrorSpacer(), + if (devToolsDiagnostic != null) ...<DiagnosticsNode>[devToolsDiagnostic, ErrorSpacer()], + ]); + return false; + } + return true; + } + if (processElement(element)) { + element.visitAncestorElements(processElement); + } + return nodes; +} + +/// Debugging message for DevTools deep links. +/// +/// The [value] for this property is a string representation of the Flutter +/// DevTools url. +class DevToolsDeepLinkProperty extends DiagnosticsProperty<String> { + /// Creates a diagnostics property that displays a deep link to Flutter DevTools. + /// + /// The [value] of this property will return a map of data for the Flutter + /// DevTools deep link, including the full `url`, the Flutter DevTools `screenId`, + /// and the `objectId` in Flutter DevTools that this diagnostic references. + DevToolsDeepLinkProperty(String description, String url) + : super('', url, description: description, level: DiagnosticLevel.info); +} + +/// Returns if an object is user created. +/// +/// This always returns false if it is not called in debug mode. +/// +/// {@macro flutter.widgets.WidgetInspectorService.getChildrenSummaryTree} +/// +/// Currently is local creation locations are only available for +/// [Widget] and [Element]. +bool debugIsLocalCreationLocation(Object object) { + bool isLocal = false; + assert(() { + final _Location? location = _getCreationLocation(object); + if (location != null) { + isLocal = WidgetInspectorService.instance._isLocalCreationLocation(location.file); + } + return true; + }()); + return isLocal; +} + +/// Returns true if a [Widget] is user created. +/// +/// This is a faster variant of `debugIsLocalCreationLocation` that is available +/// in debug and profile builds but only works for [Widget]. +bool debugIsWidgetLocalCreation(Widget widget) { + final _Location? location = _getObjectCreationLocation(widget); + return location != null && + WidgetInspectorService.instance._isLocalCreationLocation(location.file); +} + +/// Returns the creation location of an object in String format if one is available. +/// +/// ex: "file:///path/to/main.dart:4:3" +/// +/// {@macro flutter.widgets.WidgetInspectorService.getChildrenSummaryTree} +/// +/// Currently creation locations are only available for [Widget] and [Element]. +String? _describeCreationLocation(Object object) { + final _Location? location = _getCreationLocation(object); + return location?.toString(); +} + +_Location? _getObjectCreationLocation(Object object) { + return object is _HasCreationLocation ? object._location : null; +} + +/// Returns the creation location of an object if one is available. +/// +/// {@macro flutter.widgets.WidgetInspectorService.getChildrenSummaryTree} +/// +/// Currently creation locations are only available for [Widget] and [Element]. +_Location? _getCreationLocation(Object? object) { + final Object? candidate = object is Element && !object.debugIsDefunct ? object.widget : object; + return candidate == null ? null : _getObjectCreationLocation(candidate); +} + +// _Location objects are always const so we don't need to worry about the GC +// issues that are a concern for other object ids tracked by +// [WidgetInspectorService]. +final Map<_Location, int> _locationToId = <_Location, int>{}; +final List<_Location> _locations = <_Location>[]; + +int _toLocationId(_Location location) { + int? id = _locationToId[location]; + if (id != null) { + return id; + } + id = _locations.length; + _locations.add(location); + _locationToId[location] = id; + return id; +} + +/// A delegate that configures how a hierarchy of [DiagnosticsNode]s are +/// serialized by the Flutter Inspector. +@visibleForTesting +class InspectorSerializationDelegate implements DiagnosticsSerializationDelegate { + /// Creates an [InspectorSerializationDelegate] that serialize [DiagnosticsNode] + /// for Flutter Inspector service. + InspectorSerializationDelegate({ + this.groupName, + this.summaryTree = false, + this.maxDescendantsTruncatableNode = -1, + this.expandPropertyValues = true, + this.subtreeDepth = 1, + this.includeProperties = false, + required this.service, + this.addAdditionalPropertiesCallback, + }); + + /// Service used by GUI tools to interact with the [WidgetInspector]. + final WidgetInspectorService service; + + /// Optional [groupName] parameter which indicates that the json should + /// contain live object ids. + /// + /// Object ids returned as part of the json will remain live at least until + /// [WidgetInspectorService.disposeGroup()] is called on [groupName]. + final String? groupName; + + /// Whether the tree should only include nodes created by the local project. + final bool summaryTree; + + /// Maximum descendants of [DiagnosticsNode] before truncating. + final int maxDescendantsTruncatableNode; + + @override + final bool includeProperties; + + @override + final int subtreeDepth; + + @override + final bool expandPropertyValues; + + /// Callback to add additional experimental serialization properties. + /// + /// This callback can be used to customize the serialization of DiagnosticsNode + /// objects for experimental features in widget inspector clients such as + /// [Dart DevTools](https://github.com/flutter/devtools). + final Map<String, Object>? Function(DiagnosticsNode, InspectorSerializationDelegate)? addAdditionalPropertiesCallback; + + final List<DiagnosticsNode> _nodesCreatedByLocalProject = <DiagnosticsNode>[]; + + bool get _interactive => groupName != null; + + @override + Map<String, Object?> additionalNodeProperties(DiagnosticsNode node) { + final Map<String, Object?> result = <String, Object?>{}; + final Object? value = node.value; + if (_interactive) { + result['valueId'] = service.toId(value, groupName!); + } + if (summaryTree) { + result['summaryTree'] = true; + } + final _Location? creationLocation = _getCreationLocation(value); + if (creationLocation != null) { + result['locationId'] = _toLocationId(creationLocation); + result['creationLocation'] = creationLocation.toJsonMap(); + if (service._isLocalCreationLocation(creationLocation.file)) { + _nodesCreatedByLocalProject.add(node); + result['createdByLocalProject'] = true; + } + } + if (addAdditionalPropertiesCallback != null) { + result.addAll(addAdditionalPropertiesCallback!(node, this) ?? <String, Object>{}); + } + return result; + } + + @override + DiagnosticsSerializationDelegate delegateForNode(DiagnosticsNode node) { + // The tricky special case here is that when in the detailsTree, + // we keep subtreeDepth from going down to zero until we reach nodes + // that also exist in the summary tree. This ensures that every time + // you expand a node in the details tree, you expand the entire subtree + // up until you reach the next nodes shared with the summary tree. + return summaryTree || subtreeDepth > 1 || service._shouldShowInSummaryTree(node) + ? copyWith(subtreeDepth: subtreeDepth - 1) + : this; + } + + @override + List<DiagnosticsNode> filterChildren(List<DiagnosticsNode> nodes, DiagnosticsNode owner) { + return service._filterChildren(nodes, this); + } + + @override + List<DiagnosticsNode> filterProperties(List<DiagnosticsNode> nodes, DiagnosticsNode owner) { + final bool createdByLocalProject = _nodesCreatedByLocalProject.contains(owner); + return nodes.where((DiagnosticsNode node) { + return !node.isFiltered(createdByLocalProject ? DiagnosticLevel.fine : DiagnosticLevel.info); + }).toList(); + } + + @override + List<DiagnosticsNode> truncateNodesList(List<DiagnosticsNode> nodes, DiagnosticsNode? owner) { + if (maxDescendantsTruncatableNode >= 0 && + owner!.allowTruncate && + nodes.length > maxDescendantsTruncatableNode) { + nodes = service._truncateNodes(nodes, maxDescendantsTruncatableNode); + } + return nodes; + } + + @override + DiagnosticsSerializationDelegate copyWith({int? subtreeDepth, bool? includeProperties, bool? expandPropertyValues}) { + return InspectorSerializationDelegate( + groupName: groupName, + summaryTree: summaryTree, + maxDescendantsTruncatableNode: maxDescendantsTruncatableNode, + expandPropertyValues: expandPropertyValues ?? this.expandPropertyValues, + subtreeDepth: subtreeDepth ?? this.subtreeDepth, + includeProperties: includeProperties ?? this.includeProperties, + service: service, + addAdditionalPropertiesCallback: addAdditionalPropertiesCallback, + ); + } +} + +@Target(<TargetKind>{TargetKind.method}) +class _WidgetFactory { + const _WidgetFactory(); +} + +/// Annotation which marks a function as a widget factory for the purpose of +/// widget creation tracking. +/// +/// When widget creation tracking is enabled, the framework tracks the source +/// code location of the constructor call for each widget instance. This +/// information is used by the DevTools to provide an improved developer +/// experience. For example, it allows the Flutter inspector to present the +/// widget tree in a manner similar to how the UI was defined in your source +/// code. +/// +/// [Widget] constructors are automatically instrumented to track the source +/// code location of constructor calls. However, there are cases where +/// a function acts as a sort of a constructor for a widget and a call to such +/// a function should be considered as the creation location for the returned +/// widget instance. +/// +/// Annotating a function with this annotation marks the function as a widget +/// factory. The framework will then instrument that function in the same way +/// as it does for [Widget] constructors. +/// +/// Tracking will not work correctly if the function has optional positional +/// parameters. +/// +/// Currently this annotation is only supported on extension methods. +/// +/// {@tool snippet} +/// +/// This example shows how to use the [widgetFactory] annotation to mark an +/// extension method as a widget factory: +/// +/// ```dart +/// extension PaddingModifier on Widget { +/// @widgetFactory +/// Widget padding(EdgeInsetsGeometry padding) { +/// return Padding(padding: padding, child: this); +/// } +/// } +/// ``` +/// +/// When using the above extension method, the framework will track the +/// creation location of the [Padding] widget instance as the source code +/// location where the `padding` extension method was called: +/// +/// ```dart +/// // continuing from previous example... +/// const Text('Hello World!') +/// .padding(const EdgeInsets.all(8)); +/// ``` +/// +/// {@end-tool} +/// +/// See also: +/// +/// * the documentation for [Track widget creation](https://docs.flutter.dev/development/tools/devtools/inspector#track-widget-creation). +// The below ignore is needed because the static type of the annotation is used +// by the CFE kernel transformer that implements the instrumentation to +// recognize the annotation. +// ignore: library_private_types_in_public_api +const _WidgetFactory widgetFactory = _WidgetFactory(); + +/// Does not hold keys from garbage collection. +@visibleForTesting +class WeakMap<K, V> { + Expando<Object> _objects = Expando<Object>(); + + /// Strings, numbers, booleans. + final Map<K, V> _primitives = <K, V>{}; + + bool _isPrimitive(Object? key) { + return key == null || key is String || key is num || key is bool; + } + + /// Returns the value for the given [key] or null if [key] is not in the map + /// or garbage collected. + /// + /// Does not support records to act as keys. + V? operator [](K key){ + if (_isPrimitive(key)) { + return _primitives[key]; + } else { + return _objects[key!] as V?; + } + } + + /// Associates the [key] with the given [value]. + void operator []=(K key, V value){ + if (_isPrimitive(key)) { + _primitives[key] = value; + } else { + _objects[key!] = value; + } + } + + /// Removes the value for the given [key] from the map. + V? remove(K key) { + if (_isPrimitive(key)) { + return _primitives.remove(key); + } else { + final V? result = _objects[key!] as V?; + _objects[key] = null; + return result; + } + } + + /// Removes all pairs from the map. + void clear() { + _objects = Expando<Object>(); + _primitives.clear(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/widget_span.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/widget_span.dart new file mode 100644 index 0000000000000000000000000000000000000000..55f4632852206ec37e55439a4b872cf428ef9184 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/widget_span.dart @@ -0,0 +1,440 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui show ParagraphBuilder, PlaceholderAlignment; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; + +import 'basic.dart'; +import 'framework.dart'; + +// Examples can assume: +// late WidgetSpan myWidgetSpan; + +/// An immutable widget that is embedded inline within text. +/// +/// The [child] property is the widget that will be embedded. Children are +/// constrained by the width of the paragraph. +/// +/// The [child] property may contain its own [Widget] children (if applicable), +/// including [Text] and [RichText] widgets which may include additional +/// [WidgetSpan]s. Child [Text] and [RichText] widgets will be laid out +/// independently and occupy a rectangular space in the parent text layout. +/// +/// [WidgetSpan]s will be ignored when passed into a [TextPainter] directly. +/// To properly layout and paint the [child] widget, [WidgetSpan] should be +/// passed into a [Text.rich] widget. +/// +/// {@tool snippet} +/// +/// A card with `Hello World!` embedded inline within a TextSpan tree. +/// +/// ```dart +/// const Text.rich( +/// TextSpan( +/// children: <InlineSpan>[ +/// TextSpan(text: 'Flutter is'), +/// WidgetSpan( +/// child: SizedBox( +/// width: 120, +/// height: 50, +/// child: Card( +/// child: Center( +/// child: Text('Hello World!') +/// ) +/// ), +/// ) +/// ), +/// TextSpan(text: 'the best!'), +/// ], +/// ) +/// ) +/// ``` +/// {@end-tool} +/// +/// [WidgetSpan] contributes the semantics of the [WidgetSpan.child] to the +/// semantics tree. +/// +/// See also: +/// +/// * [TextSpan], a node that represents text in an [InlineSpan] tree. +/// * [Text], a widget for showing uniformly-styled text. +/// * [RichText], a widget for finer control of text rendering. +/// * [TextPainter], a class for painting [InlineSpan] objects on a [Canvas]. +@immutable +class WidgetSpan extends PlaceholderSpan { + /// Creates a [WidgetSpan] with the given values. + /// + /// [WidgetSpan] is a leaf node in the [InlineSpan] tree. Child widgets are + /// constrained by the width of the paragraph they occupy. Child widget + /// heights are unconstrained, and may cause the text to overflow and be + /// ellipsized/truncated. + /// + /// A [TextStyle] may be provided with the [style] property, but only the + /// decoration, foreground, background, and spacing options will be used. + const WidgetSpan({ + required this.child, + super.alignment, + super.baseline, + super.style, + }) : assert( + baseline != null || !( + identical(alignment, ui.PlaceholderAlignment.aboveBaseline) || + identical(alignment, ui.PlaceholderAlignment.belowBaseline) || + identical(alignment, ui.PlaceholderAlignment.baseline) + ), + ); + + /// Helper function for extracting [WidgetSpan]s in preorder, from the given + /// [InlineSpan] as a list of widgets. + /// + /// The `textScaler` is the scaling strategy for scaling the content. + /// + /// This function is used by [EditableText] and [RichText] so calling it + /// directly is rarely necessary. + static List<Widget> extractFromInlineSpan(InlineSpan span, TextScaler textScaler) { + final List<Widget> widgets = <Widget>[]; + // _kEngineDefaultFontSize is the default font size to use when none of the + // ancestor spans specifies one. + final List<double> fontSizeStack = <double>[kDefaultFontSize]; + int index = 0; + // This assumes an InlineSpan tree's logical order is equivalent to preorder. + bool visitSubtree(InlineSpan span) { + final double? fontSizeToPush = switch (span.style?.fontSize) { + final double size when size != fontSizeStack.last => size, + _ => null, + }; + if (fontSizeToPush != null) { + fontSizeStack.add(fontSizeToPush); + } + if (span is WidgetSpan) { + final double fontSize = fontSizeStack.last; + final double textScaleFactor = fontSize == 0 ? 0 : textScaler.scale(fontSize) / fontSize; + widgets.add( + _WidgetSpanParentData( + span: span, + child: Semantics( + tagForChildren: PlaceholderSpanIndexSemanticsTag(index++), + child: _AutoScaleInlineWidget(span: span, textScaleFactor: textScaleFactor, child: span.child), + ), + ), + ); + } + assert( + span is WidgetSpan || span is! PlaceholderSpan, + '$span is a PlaceholderSpan but not a WidgetSpan subclass. This is currently not supported.', + ); + span.visitDirectChildren(visitSubtree); + if (fontSizeToPush != null) { + final double poppedFontSize = fontSizeStack.removeLast(); + assert(fontSizeStack.isNotEmpty); + assert(poppedFontSize == fontSizeToPush); + } + return true; + } + visitSubtree(span); + return widgets; + } + + /// The widget to embed inline within text. + final Widget child; + + /// Adds a placeholder box to the paragraph builder if a size has been + /// calculated for the widget. + /// + /// Sizes are provided through `dimensions`, which should contain a 1:1 + /// in-order mapping of widget to laid-out dimensions. If no such dimension + /// is provided, the widget will be skipped. + /// + /// The `textScaler` will be applied to the laid-out size of the widget. + @override + void build(ui.ParagraphBuilder builder, { + TextScaler textScaler = TextScaler.noScaling, + List<PlaceholderDimensions>? dimensions, + }) { + assert(debugAssertIsValid()); + assert(dimensions != null); + final bool hasStyle = style != null; + if (hasStyle) { + builder.pushStyle(style!.getTextStyle(textScaler: textScaler)); + } + assert(builder.placeholderCount < dimensions!.length); + final PlaceholderDimensions currentDimensions = dimensions![builder.placeholderCount]; + builder.addPlaceholder( + currentDimensions.size.width, + currentDimensions.size.height, + alignment, + baseline: currentDimensions.baseline, + baselineOffset: currentDimensions.baselineOffset, + ); + if (hasStyle) { + builder.pop(); + } + } + + /// Calls `visitor` on this [WidgetSpan]. There are no children spans to walk. + @override + bool visitChildren(InlineSpanVisitor visitor) => visitor(this); + + @override + bool visitDirectChildren(InlineSpanVisitor visitor) => true; + + @override + InlineSpan? getSpanForPositionVisitor(TextPosition position, Accumulator offset) { + if (position.offset == offset.value) { + return this; + } + offset.increment(1); + return null; + } + + @override + int? codeUnitAtVisitor(int index, Accumulator offset) { + final int localOffset = index - offset.value; + assert(localOffset >= 0); + offset.increment(1); + return localOffset == 0 ? PlaceholderSpan.placeholderCodeUnit : null; + } + + @override + RenderComparison compareTo(InlineSpan other) { + if (identical(this, other)) { + return RenderComparison.identical; + } + if (other.runtimeType != runtimeType) { + return RenderComparison.layout; + } + if ((style == null) != (other.style == null)) { + return RenderComparison.layout; + } + final WidgetSpan typedOther = other as WidgetSpan; + if (child != typedOther.child || alignment != typedOther.alignment) { + return RenderComparison.layout; + } + RenderComparison result = RenderComparison.identical; + if (style != null) { + final RenderComparison candidate = style!.compareTo(other.style!); + if (candidate.index > result.index) { + result = candidate; + } + if (result == RenderComparison.layout) { + return result; + } + } + return result; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + if (super != other) { + return false; + } + return other is WidgetSpan + && other.child == child + && other.alignment == alignment + && other.baseline == baseline; + } + + @override + int get hashCode => Object.hash(super.hashCode, child, alignment, baseline); + + /// Returns the text span that contains the given position in the text. + @override + InlineSpan? getSpanForPosition(TextPosition position) { + assert(debugAssertIsValid()); + return null; + } + + /// In debug mode, throws an exception if the object is not in a + /// valid configuration. Otherwise, returns true. + /// + /// This is intended to be used as follows: + /// + /// ```dart + /// assert(myWidgetSpan.debugAssertIsValid()); + /// ``` + @override + bool debugAssertIsValid() { + // WidgetSpans are always valid as asserts prevent invalid WidgetSpans + // from being constructed. + return true; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<Widget>('widget', child)); + } +} + +// A ParentDataWidget that sets TextParentData.span. +class _WidgetSpanParentData extends ParentDataWidget<TextParentData> { + const _WidgetSpanParentData({ required this.span, required super.child }); + + final WidgetSpan span; + + @override + void applyParentData(RenderObject renderObject) { + final TextParentData parentData = renderObject.parentData! as TextParentData; + parentData.span = span; + } + + @override + Type get debugTypicalAncestorWidgetClass => RichText; +} + +// A RenderObjectWidget that automatically applies text scaling on inline +// widgets. +// +// TODO(LongCatIsLooong): this shouldn't happen automatically, at least there +// should be a way to opt out: https://github.com/flutter/flutter/issues/126962 +class _AutoScaleInlineWidget extends SingleChildRenderObjectWidget { + const _AutoScaleInlineWidget({ required this.span, required this.textScaleFactor, required super.child }); + + final WidgetSpan span; + final double textScaleFactor; + + @override + _RenderScaledInlineWidget createRenderObject(BuildContext context) { + return _RenderScaledInlineWidget(span.alignment, span.baseline, textScaleFactor); + } + + @override + void updateRenderObject(BuildContext context, _RenderScaledInlineWidget renderObject) { + renderObject + ..alignment = span.alignment + ..baseline = span.baseline + ..scale = textScaleFactor; + } +} + +class _RenderScaledInlineWidget extends RenderBox with RenderObjectWithChildMixin<RenderBox> { + _RenderScaledInlineWidget(this._alignment, this._baseline, this._scale); + + double get scale => _scale; + double _scale; + set scale(double value) { + if (value == _scale) { + return; + } + assert(value > 0); + assert(value.isFinite); + _scale = value; + markNeedsLayout(); + } + + ui.PlaceholderAlignment get alignment => _alignment; + ui.PlaceholderAlignment _alignment; + set alignment(ui.PlaceholderAlignment value) { + if (_alignment == value) { + return; + } + _alignment = value; + markNeedsLayout(); + } + + TextBaseline? get baseline => _baseline; + TextBaseline? _baseline; + set baseline(TextBaseline? value) { + if (value == _baseline) { + return; + } + _baseline = value; + markNeedsLayout(); + } + + @override + double computeMaxIntrinsicHeight(double width) { + return (child?.computeMaxIntrinsicHeight(width / scale) ?? 0.0) * scale; + } + + @override + double computeMaxIntrinsicWidth(double height) { + return (child?.computeMaxIntrinsicWidth(height / scale) ?? 0.0) * scale; + } + + @override + double computeMinIntrinsicHeight(double width) { + return (child?.computeMinIntrinsicHeight(width / scale) ?? 0.0) * scale; + } + + @override + double computeMinIntrinsicWidth(double height) { + return (child?.computeMinIntrinsicWidth(height / scale) ?? 0.0) * scale; + } + + @override + double? computeDistanceToActualBaseline(TextBaseline baseline) { + return switch (child?.getDistanceToActualBaseline(baseline)) { + null => super.computeDistanceToActualBaseline(baseline), + final double childBaseline => scale * childBaseline, + }; + } + + @override + Size computeDryLayout(BoxConstraints constraints) { + assert(!constraints.hasBoundedHeight); + final Size unscaledSize = child?.computeDryLayout(BoxConstraints(maxWidth: constraints.maxWidth / scale)) ?? Size.zero; + return constraints.constrain(unscaledSize * scale); + } + + @override + void performLayout() { + final RenderBox? child = this.child; + if (child == null) { + return; + } + assert(!constraints.hasBoundedHeight); + // Only constrain the width to the maximum width of the paragraph. + // Leave height unconstrained, which will overflow if expanded past. + child.layout(BoxConstraints(maxWidth: constraints.maxWidth / scale), parentUsesSize: true); + size = constraints.constrain(child.size * scale); + } + + @override + void applyPaintTransform(RenderBox child, Matrix4 transform) { + transform.scale(scale, scale); + } + + @override + void paint(PaintingContext context, Offset offset) { + final RenderBox? child = this.child; + if (child == null) { + layer = null; + return; + } + if (scale == 1.0) { + context.paintChild(child, offset); + layer = null; + return; + } + layer = context.pushTransform( + needsCompositing, + offset, + Matrix4.diagonal3Values(scale, scale, 1.0), + (PaintingContext context, Offset offset) => context.paintChild(child, offset), + oldLayer: layer as TransformLayer? + ); + } + + @override + bool hitTestChildren(BoxHitTestResult result, {required Offset position}) { + final RenderBox? child = this.child; + if (child == null) { + return false; + } + return result.addWithPaintTransform( + transform: Matrix4.diagonal3Values(scale, scale, 1.0), + position: position, + hitTest: (BoxHitTestResult result, Offset transformedOffset) => child.hitTest(result, position: transformedOffset), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/widget_state.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/widget_state.dart new file mode 100644 index 0000000000000000000000000000000000000000..c86d4b86b10cf0330e7f7950395bae17c70014c3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/widget_state.dart @@ -0,0 +1,670 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; + +// Examples can assume: +// late BuildContext context; + +/// Interactive states that some of the widgets can take on when receiving input +/// from the user. +/// +/// States are defined by https://material.io/design/interaction/states.html#usage, +/// but are not limited to the Material design system or library. +/// +/// Some widgets track their current state in a `Set<WidgetState>`. +/// +/// See also: +/// +/// * [MaterialState], the Material specific version of `WidgetState`. +/// * [WidgetStateProperty], an interface for objects that "resolve" to +/// different values depending on a widget's state. +/// {@template flutter.widgets.WidgetStateProperty.implementations} +/// * [WidgetStateColor], a [Color] that implements `WidgetStateProperty` +/// which is used in APIs that need to accept either a [Color] or a +/// `WidgetStateProperty<Color>`. +/// * [WidgetStateMouseCursor], a [MouseCursor] that implements +/// `WidgetStateProperty` which is used in APIs that need to accept either +/// a [MouseCursor] or a [WidgetStateProperty<MouseCursor>]. +/// * [WidgetStateOutlinedBorder], an [OutlinedBorder] that implements +/// `WidgetStateProperty` which is used in APIs that need to accept either +/// an [OutlinedBorder] or a [WidgetStateProperty<OutlinedBorder>]. +/// * [WidgetStateBorderSide], a [BorderSide] that implements +/// `WidgetStateProperty` which is used in APIs that need to accept either +/// a [BorderSide] or a [WidgetStateProperty<BorderSide>]. +/// * [WidgetStateTextStyle], a [TextStyle] that implements +/// `WidgetStateProperty` which is used in APIs that need to accept either +/// a [TextStyle] or a [WidgetStateProperty<TextStyle>]. +/// {@endtemplate} +enum WidgetState { + /// The state when the user drags their mouse cursor over the given widget. + /// + /// See: https://material.io/design/interaction/states.html#hover. + hovered, + + /// The state when the user navigates with the keyboard to a given widget. + /// + /// This can also sometimes be triggered when a widget is tapped. For example, + /// when a [TextField] is tapped, it becomes [focused]. + /// + /// See: https://material.io/design/interaction/states.html#focus. + focused, + + /// The state when the user is actively pressing down on the given widget. + /// + /// See: https://material.io/design/interaction/states.html#pressed. + pressed, + + /// The state when this widget is being dragged from one place to another by + /// the user. + /// + /// https://material.io/design/interaction/states.html#dragged. + dragged, + + /// The state when this item has been selected. + /// + /// This applies to things that can be toggled (such as chips and checkboxes) + /// and things that are selected from a set of options (such as tabs and radio buttons). + /// + /// See: https://material.io/design/interaction/states.html#selected. + selected, + + /// The state when this widget overlaps the content of a scrollable below. + /// + /// Used by [AppBar] to indicate that the primary scrollable's + /// content has scrolled up and behind the app bar. + scrolledUnder, + + /// The state when this widget is disabled and cannot be interacted with. + /// + /// Disabled widgets should not respond to hover, focus, press, or drag + /// interactions. + /// + /// See: https://material.io/design/interaction/states.html#disabled. + disabled, + + /// The state when the widget has entered some form of invalid state. + /// + /// See https://material.io/design/interaction/states.html#usage. + error, +} + +/// Signature for the function that returns a value of type `T` based on a given +/// set of states. +typedef WidgetPropertyResolver<T> = T Function(Set<WidgetState> states); + +/// Defines a [Color] that is also a [WidgetStateProperty]. +/// +/// This class exists to enable widgets with [Color] valued properties +/// to also accept [WidgetStateProperty<Color>] values. A widget +/// state color property represents a color which depends on +/// a widget's "interactive state". This state is represented as a +/// [Set] of [WidgetState]s, like [WidgetState.pressed], +/// [WidgetState.focused] and [WidgetState.hovered]. +/// +/// [WidgetStateColor] should only be used with widgets that document +/// their support, like [TimePickerThemeData.dayPeriodColor]. +/// +/// To use a [WidgetStateColor], you can either: +/// 1. Create a subclass of [WidgetStateColor] and implement the abstract `resolve` method. +/// 2. Use [WidgetStateColor.resolveWith] and pass in a callback that +/// will be used to resolve the color in the given states. +/// +/// If a [WidgetStateColor] is used for a property or a parameter that doesn't +/// support resolving [WidgetStateProperty<Color>]s, then its default color +/// value will be used for all states. +/// +/// To define a `const` [WidgetStateColor], you'll need to extend +/// [WidgetStateColor] and override its [resolve] method. You'll also need +/// to provide a `defaultValue` to the super constructor, so that we can know +/// at compile-time what its default color is. +/// +/// {@tool snippet} +/// +/// This example defines a [WidgetStateColor] with a const constructor. +/// +/// ```dart +/// class MyColor extends WidgetStateColor { +/// const MyColor() : super(_defaultColor); +/// +/// static const int _defaultColor = 0xcafefeed; +/// static const int _pressedColor = 0xdeadbeef; +/// +/// @override +/// Color resolve(Set<WidgetState> states) { +/// if (states.contains(WidgetState.pressed)) { +/// return const Color(_pressedColor); +/// } +/// return const Color(_defaultColor); +/// } +/// } +/// ``` +/// {@end-tool} +/// +/// See also: +/// +/// * [MaterialStateColor], the Material specific version of `WidgetStateColor`. +abstract class WidgetStateColor extends Color implements WidgetStateProperty<Color> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const WidgetStateColor(super.defaultValue); + + /// Creates a [WidgetStateColor] from a [WidgetPropertyResolver<Color>] + /// callback function. + /// + /// If used as a regular color, the color resolved in the default state (the + /// empty set of states) will be used. + /// + /// The given callback parameter must return a non-null color in the default + /// state. + static WidgetStateColor resolveWith(WidgetPropertyResolver<Color> callback) => _WidgetStateColor(callback); + + /// Returns a [Color] that's to be used when a component is in the specified + /// state. + @override + Color resolve(Set<WidgetState> states); + + /// A constant whose value is transparent for all states. + static const WidgetStateColor transparent = _WidgetStateColorTransparent(); +} + +class _WidgetStateColor extends WidgetStateColor { + _WidgetStateColor(this._resolve) : super(_resolve(_defaultStates).value); + + final WidgetPropertyResolver<Color> _resolve; + + static const Set<WidgetState> _defaultStates = <WidgetState>{}; + + @override + Color resolve(Set<WidgetState> states) => _resolve(states); +} + +class _WidgetStateColorTransparent extends WidgetStateColor { + const _WidgetStateColorTransparent() : super(0x00000000); + + @override + Color resolve(Set<WidgetState> states) => const Color(0x00000000); +} + +/// Defines a [MouseCursor] whose value depends on a set of [WidgetState]s which +/// represent the interactive state of a component. +/// +/// This kind of [MouseCursor] is useful when the set of interactive +/// actions a widget supports varies with its state. For example, a +/// mouse pointer hovering over a disabled [ListTile] should not +/// display [SystemMouseCursors.click], since a disabled list tile +/// doesn't respond to mouse clicks. [ListTile]'s default mouse cursor +/// is a [WidgetStateMouseCursor.clickable], which resolves to +/// [SystemMouseCursors.basic] when the button is disabled. +/// +/// To use a [WidgetStateMouseCursor], you should create a subclass of +/// [WidgetStateMouseCursor] and implement the abstract `resolve` method. +/// +/// {@tool dartpad} +/// This example defines a mouse cursor that resolves to +/// [SystemMouseCursors.forbidden] when its widget is disabled. +/// +/// ** See code in examples/api/lib/material/material_state/material_state_mouse_cursor.0.dart ** +/// {@end-tool} +/// +/// This class should only be used for parameters which are documented to take +/// [WidgetStateMouseCursor], otherwise only the default state will be used. +/// +/// See also: +/// +/// * [MaterialStateMouseCursor], the Material specific version of +/// `WidgetStateMouseCursor`. +/// * [MouseCursor] for introduction on the mouse cursor system. +/// * [SystemMouseCursors], which defines cursors that are supported by +/// native platforms. +abstract class WidgetStateMouseCursor extends MouseCursor implements WidgetStateProperty<MouseCursor> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const WidgetStateMouseCursor(); + + @protected + @override + MouseCursorSession createSession(int device) { + return resolve(<WidgetState>{}).createSession(device); + } + + /// Returns a [MouseCursor] that's to be used when a component is in the + /// specified state. + @override + MouseCursor resolve(Set<WidgetState> states); + + /// A mouse cursor for clickable widgets, which resolves differently when the + /// widget is disabled. + /// + /// By default this cursor resolves to [SystemMouseCursors.click]. If the widget is + /// disabled, the cursor resolves to [SystemMouseCursors.basic]. + /// + /// This cursor is the default for many widgets. + static const WidgetStateMouseCursor clickable = _EnabledAndDisabledMouseCursor( + enabledCursor: SystemMouseCursors.click, + disabledCursor: SystemMouseCursors.basic, + name: 'clickable', + ); + + /// A mouse cursor for widgets related to text, which resolves differently + /// when the widget is disabled. + /// + /// By default this cursor resolves to [SystemMouseCursors.text]. If the widget is + /// disabled, the cursor resolves to [SystemMouseCursors.basic]. + /// + /// This cursor is the default for many widgets. + static const WidgetStateMouseCursor textable = _EnabledAndDisabledMouseCursor( + enabledCursor: SystemMouseCursors.text, + disabledCursor: SystemMouseCursors.basic, + name: 'textable', + ); +} + +class _EnabledAndDisabledMouseCursor extends WidgetStateMouseCursor { + const _EnabledAndDisabledMouseCursor({ + required this.enabledCursor, + required this.disabledCursor, + required this.name, + }); + + final MouseCursor enabledCursor; + final MouseCursor disabledCursor; + final String name; + + @override + MouseCursor resolve(Set<WidgetState> states) { + if (states.contains(WidgetState.disabled)) { + return disabledCursor; + } + return enabledCursor; + } + + @override + String get debugDescription => 'WidgetStateMouseCursor($name)'; +} + +/// Defines a [BorderSide] whose value depends on a set of [WidgetState]s +/// which represent the interactive state of a component. +/// +/// To use a [WidgetStateBorderSide], you should create a subclass of a +/// [WidgetStateBorderSide] and override the abstract `resolve` method. +/// +/// This class enables existing widget implementations with [BorderSide] +/// properties to be extended to also effectively support `WidgetStateProperty<BorderSide>` +/// property values. [WidgetStateBorderSide] should only be used with widgets that document +/// their support, like [ActionChip.side]. +/// +/// This class should only be used for parameters which are documented to take +/// [WidgetStateBorderSide], otherwise only the default state will be used. +/// +/// See also: +/// +/// * [MaterialStateBorderSide], the Material specific version of +/// `WidgetStateBorderSide`. +abstract class WidgetStateBorderSide extends BorderSide implements WidgetStateProperty<BorderSide?> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const WidgetStateBorderSide(); + + /// Creates a [WidgetStateBorderSide] from a + /// [WidgetPropertyResolver<BorderSide?>] callback function. + /// + /// If used as a regular [BorderSide], the border resolved in the default state + /// (the empty set of states) will be used. + /// + /// Usage: + /// + /// ```dart + /// ChipTheme( + /// data: Theme.of(context).chipTheme.copyWith( + /// side: WidgetStateBorderSide.resolveWith((Set<WidgetState> states) { + /// if (states.contains(WidgetState.selected)) { + /// return const BorderSide(color: Colors.red); + /// } + /// return null; // Defer to default value on the theme or widget. + /// }), + /// ), + /// child: const Chip( + /// label: Text('Transceiver'), + /// ), + /// ), + /// ``` + /// + /// Alternatively: + /// + /// ```dart + /// Chip( + /// label: const Text('Transceiver'), + /// side: WidgetStateBorderSide.resolveWith((Set<WidgetState> states) { + /// if (states.contains(WidgetState.selected)) { + /// return const BorderSide(color: Colors.red); + /// } + /// return null; // Defer to default value on the theme or widget. + /// }), + /// ), + /// ``` + const factory WidgetStateBorderSide.resolveWith(WidgetPropertyResolver<BorderSide?> callback) = _WidgetStateBorderSide; + + /// Returns a [BorderSide] that's to be used when a Material component is + /// in the specified state. Return null to defer to the default value of the + /// widget or theme. + @override + BorderSide? resolve(Set<WidgetState> states); + + /// Linearly interpolate between two [WidgetStateProperty]s of [BorderSide]. + static WidgetStateProperty<BorderSide?>? lerp( + WidgetStateProperty<BorderSide?>? a, + WidgetStateProperty<BorderSide?>? b, + double t, + ) { + // Avoid creating a _LerpSides object for a common case. + if (a == null && b == null) { + return null; + } + return _LerpSides(a, b, t); + } +} + +class _LerpSides implements WidgetStateProperty<BorderSide?> { + const _LerpSides(this.a, this.b, this.t); + + final WidgetStateProperty<BorderSide?>? a; + final WidgetStateProperty<BorderSide?>? b; + final double t; + + @override + BorderSide? resolve(Set<WidgetState> states) { + final BorderSide? resolvedA = a?.resolve(states); + final BorderSide? resolvedB = b?.resolve(states); + if (resolvedA == null && resolvedB == null) { + return null; + } + if (resolvedA == null) { + return BorderSide.lerp(BorderSide(width: 0, color: resolvedB!.color.withAlpha(0)), resolvedB, t); + } + if (resolvedB == null) { + return BorderSide.lerp(resolvedA, BorderSide(width: 0, color: resolvedA.color.withAlpha(0)), t); + } + return BorderSide.lerp(resolvedA, resolvedB, t); + } +} + +class _WidgetStateBorderSide extends WidgetStateBorderSide { + const _WidgetStateBorderSide(this._resolve); + + final WidgetPropertyResolver<BorderSide?> _resolve; + + @override + BorderSide? resolve(Set<WidgetState> states) => _resolve(states); +} + +/// Defines an [OutlinedBorder] whose value depends on a set of [WidgetState]s +/// which represent the interactive state of a component. +/// +/// To use a [WidgetStateOutlinedBorder], you should create a subclass of an +/// [OutlinedBorder] and implement [WidgetStateOutlinedBorder]'s abstract +/// `resolve` method. +/// +/// {@tool dartpad} +/// This example defines a subclass of [RoundedRectangleBorder] and an +/// implementation of [WidgetStateOutlinedBorder], that resolves to +/// [RoundedRectangleBorder] when its widget is selected. +/// +/// ** See code in examples/api/lib/material/material_state/material_state_outlined_border.0.dart ** +/// {@end-tool} +/// +/// This class should only be used for parameters which are documented to take +/// [WidgetStateOutlinedBorder], otherwise only the default state will be used. +/// +/// See also: +/// +/// * [ShapeBorder] the base class for shape outlines. +/// * [MaterialStateOutlinedBorder], the Material specific version of +/// `WidgetStateOutlinedBorder`. +abstract class WidgetStateOutlinedBorder extends OutlinedBorder implements WidgetStateProperty<OutlinedBorder?> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const WidgetStateOutlinedBorder(); + + /// Returns an [OutlinedBorder] that's to be used when a component is in the + /// specified state. Return null to defer to the default value of the widget + /// or theme. + @override + OutlinedBorder? resolve(Set<WidgetState> states); +} + +/// Defines a [TextStyle] that is also a [WidgetStateProperty]. +/// +/// This class exists to enable widgets with [TextStyle] valued properties +/// to also accept [WidgetStateProperty<TextStyle>] values. A widget +/// state text style property represents a text style which depends on +/// a widget's "interactive state". This state is represented as a +/// [Set] of [WidgetState]s, like [WidgetState.pressed], +/// [WidgetState.focused] and [WidgetState.hovered]. +/// +/// [WidgetStateTextStyle] should only be used with widgets that document +/// their support, like [InputDecoration.labelStyle]. +/// +/// To use a [WidgetStateTextStyle], you can either: +/// 1. Create a subclass of [WidgetStateTextStyle] and implement the abstract `resolve` method. +/// 2. Use [WidgetStateTextStyle.resolveWith] and pass in a callback that +/// will be used to resolve the color in the given states. +/// +/// If a [WidgetStateTextStyle] is used for a property or a parameter that doesn't +/// support resolving [WidgetStateProperty<TextStyle>]s, then its default color +/// value will be used for all states. +/// +/// To define a `const` [WidgetStateTextStyle], you'll need to extend +/// [WidgetStateTextStyle] and override its [resolve] method. You'll also need +/// to provide a `defaultValue` to the super constructor, so that we can know +/// at compile-time what its default color is. +/// See also: +/// +/// * [MaterialStateTextStyle], the Material specific version of +/// `WidgetStateTextStyle`. +abstract class WidgetStateTextStyle extends TextStyle implements WidgetStateProperty<TextStyle> { + /// Abstract const constructor. This constructor enables subclasses to provide + /// const constructors so that they can be used in const expressions. + const WidgetStateTextStyle(); + + /// Creates a [WidgetStateTextStyle] from a [WidgetPropertyResolver<TextStyle>] + /// callback function. + /// + /// If used as a regular text style, the style resolved in the default state (the + /// empty set of states) will be used. + /// + /// The given callback parameter must return a non-null text style in the default + /// state. + const factory WidgetStateTextStyle.resolveWith(WidgetPropertyResolver<TextStyle> callback) = _WidgetStateTextStyle; + + /// Returns a [TextStyle] that's to be used when a component is in the + /// specified state. + @override + TextStyle resolve(Set<WidgetState> states); +} + +class _WidgetStateTextStyle extends WidgetStateTextStyle { + const _WidgetStateTextStyle(this._resolve); + + final WidgetPropertyResolver<TextStyle> _resolve; + + @override + TextStyle resolve(Set<WidgetState> states) => _resolve(states); +} + +/// Interface for classes that [resolve] to a value of type `T` based +/// on a widget's interactive "state", which is defined as a set +/// of [WidgetState]s. +/// +/// Widget state properties represent values that depend on a widget's "state". +/// The state is encoded as a set of [WidgetState] values, like +/// [WidgetState.focused], [WidgetState.hovered], [WidgetState.pressed]. For +/// example the [InkWell.overlayColor] defines the color that fills the ink well +/// when it's pressed (the "splash color"), focused, or hovered. The [InkWell] +/// uses the overlay color's [resolve] method to compute the color for the +/// ink well's current state. +/// +/// [ButtonStyle], which is used to configure the appearance of +/// buttons like [TextButton], [ElevatedButton], and [OutlinedButton], +/// has many material state properties. The button widgets keep track +/// of their current material state and [resolve] the button style's +/// material state properties when their value is needed. +/// +/// See also: +/// +/// * [MaterialStateProperty], the Material specific version of +/// `WidgetStateProperty`. +/// {@macro flutter.widgets.WidgetStateProperty.implementations} +abstract class WidgetStateProperty<T> { + /// Returns a value of type `T` that depends on [states]. + /// + /// Widgets like [TextButton] and [ElevatedButton] apply this method to their + /// current [WidgetState]s to compute colors and other visual parameters + /// at build time. + T resolve(Set<WidgetState> states); + + /// Resolves the value for the given set of states if `value` is a + /// [WidgetStateProperty], otherwise returns the value itself. + /// + /// This is useful for widgets that have parameters which can optionally be a + /// [WidgetStateProperty]. For example, [InkWell.mouseCursor] can be a + /// [MouseCursor] or a [WidgetStateProperty<MouseCursor>]. + static T resolveAs<T>(T value, Set<WidgetState> states) { + if (value is WidgetStateProperty<T>) { + final WidgetStateProperty<T> property = value; + return property.resolve(states); + } + return value; + } + + /// Convenience method for creating a [WidgetStateProperty] from a + /// [WidgetPropertyResolver] function alone. + static WidgetStateProperty<T> resolveWith<T>(WidgetPropertyResolver<T> callback) => _WidgetStatePropertyWith<T>(callback); + + /// Convenience method for creating a [WidgetStateProperty] that resolves + /// to a single value for all states. + /// + /// If you need a const value, use [WidgetStatePropertyAll] directly. + /// + // TODO(darrenaustin): Deprecate this when we have the ability to create + // a dart fix that will replace this with WidgetStatePropertyAll: + // https://github.com/dart-lang/sdk/issues/49056. + static WidgetStateProperty<T> all<T>(T value) => WidgetStatePropertyAll<T>(value); + + /// Linearly interpolate between two [WidgetStateProperty]s. + static WidgetStateProperty<T?>? lerp<T>( + WidgetStateProperty<T>? a, + WidgetStateProperty<T>? b, + double t, + T? Function(T?, T?, double) lerpFunction, + ) { + // Avoid creating a _LerpProperties object for a common case. + if (a == null && b == null) { + return null; + } + return _LerpProperties<T>(a, b, t, lerpFunction); + } +} + +class _LerpProperties<T> implements WidgetStateProperty<T?> { + const _LerpProperties(this.a, this.b, this.t, this.lerpFunction); + + final WidgetStateProperty<T>? a; + final WidgetStateProperty<T>? b; + final double t; + final T? Function(T?, T?, double) lerpFunction; + + @override + T? resolve(Set<WidgetState> states) { + final T? resolvedA = a?.resolve(states); + final T? resolvedB = b?.resolve(states); + return lerpFunction(resolvedA, resolvedB, t); + } +} + +class _WidgetStatePropertyWith<T> implements WidgetStateProperty<T> { + _WidgetStatePropertyWith(this._resolve); + + final WidgetPropertyResolver<T> _resolve; + + @override + T resolve(Set<WidgetState> states) => _resolve(states); +} + +/// Convenience class for creating a [WidgetStateProperty] that +/// resolves to the given value for all states. +/// +/// See also: +/// +/// * [MaterialStatePropertyAll], the Material specific version of +/// `WidgetStatePropertyAll`. +class WidgetStatePropertyAll<T> implements WidgetStateProperty<T> { + + /// Constructs a [WidgetStateProperty] that always resolves to the given + /// value. + const WidgetStatePropertyAll(this.value); + + /// The value of the property that will be used for all states. + final T value; + + @override + T resolve(Set<WidgetState> states) => value; + + @override + String toString() { + if (value is double) { + return 'WidgetStatePropertyAll(${debugFormatDouble(value as double)})'; + } else { + return 'WidgetStatePropertyAll($value)'; + } + } +} + +/// Manages a set of [WidgetState]s and notifies listeners of changes. +/// +/// Used by widgets that expose their internal state for the sake of +/// extensions that add support for additional states. See +/// [TextButton] for an example. +/// +/// The controller's [value] is its current set of states. Listeners +/// are notified whenever the [value] changes. The [value] should only be +/// changed with [update]; it should not be modified directly. +/// +/// The controller's [value] represents the set of states that a +/// widget's visual properties, typically [WidgetStateProperty] +/// values, are resolved against. It is _not_ the intrinsic state of +/// the widget. The widget is responsible for ensuring that the +/// controller's [value] tracks its intrinsic state. For example one +/// cannot request the keyboard focus for a widget by adding +/// [WidgetState.focused] to its controller. When the widget gains the +/// or loses the focus it will [update] its controller's [value] and +/// notify listeners of the change. +/// +/// When calling `setState` in a [WidgetStatesController] listener, use the +/// [SchedulerBinding.addPostFrameCallback] to delay the call to `setState` after +/// the frame has been rendered. It's generally prudent to use the +/// [SchedulerBinding.addPostFrameCallback] because some of the widgets that +/// depend on [WidgetStatesController] may call [update] in their build method. +/// In such cases, listener's that call `setState` - during the build phase - will cause +/// an error. +/// +/// See also: +/// +/// * [MaterialStatesController], the Material specific version of +/// `WidgetStatesController`. +class WidgetStatesController extends ValueNotifier<Set<WidgetState>> { + /// Creates a WidgetStatesController. + WidgetStatesController([Set<WidgetState>? value]) : super(<WidgetState>{...?value}); + + /// Adds [state] to [value] if [add] is true, and removes it otherwise, + /// and notifies listeners if [value] has changed. + void update(WidgetState state, bool add) { + final bool valueChanged = add ? value.add(state) : value.remove(state); + if (valueChanged) { + notifyListeners(); + } + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/will_pop_scope.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/will_pop_scope.dart new file mode 100644 index 0000000000000000000000000000000000000000..81b59454861c3369d5bc17b2f9c9444ea09801da --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/will_pop_scope.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'framework.dart'; +import 'navigator.dart'; +import 'routes.dart'; + +/// Registers a callback to veto attempts by the user to dismiss the enclosing +/// [ModalRoute]. +/// +/// See also: +/// +/// * [ModalRoute.addScopedWillPopCallback] and [ModalRoute.removeScopedWillPopCallback], +/// which this widget uses to register and unregister [onWillPop]. +/// * [Form], which provides an `onWillPop` callback that enables the form +/// to veto a `pop` initiated by the app's back button. +@Deprecated( + 'Use PopScope instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', +) +class WillPopScope extends StatefulWidget { + /// Creates a widget that registers a callback to veto attempts by the user to + /// dismiss the enclosing [ModalRoute]. + @Deprecated( + 'Use PopScope instead. ' + 'This feature was deprecated after v3.12.0-1.0.pre.', + ) + const WillPopScope({ + super.key, + required this.child, + required this.onWillPop, + }); + + /// The widget below this widget in the tree. + /// + /// {@macro flutter.widgets.ProxyWidget.child} + final Widget child; + + /// Called to veto attempts by the user to dismiss the enclosing [ModalRoute]. + /// + /// If the callback returns a Future that resolves to false, the enclosing + /// route will not be popped. + final WillPopCallback? onWillPop; + + @override + State<WillPopScope> createState() => _WillPopScopeState(); +} + +class _WillPopScopeState extends State<WillPopScope> { + ModalRoute<dynamic>? _route; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (widget.onWillPop != null) { + _route?.removeScopedWillPopCallback(widget.onWillPop!); + } + _route = ModalRoute.of(context); + if (widget.onWillPop != null) { + _route?.addScopedWillPopCallback(widget.onWillPop!); + } + } + + @override + void didUpdateWidget(WillPopScope oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.onWillPop != oldWidget.onWillPop && _route != null) { + if (oldWidget.onWillPop != null) { + _route!.removeScopedWillPopCallback(oldWidget.onWillPop!); + } + if (widget.onWillPop != null) { + _route!.addScopedWillPopCallback(widget.onWillPop!); + } + } + } + + @override + void dispose() { + if (widget.onWillPop != null) { + _route?.removeScopedWillPopCallback(widget.onWillPop!); + } + super.dispose(); + } + + @override + Widget build(BuildContext context) => widget.child; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/window.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/window.dart new file mode 100644 index 0000000000000000000000000000000000000000..87e176fb483050215c91f1f03320eef130329ed2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/lib/src/widgets/window.dart @@ -0,0 +1,6 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Placeholder to be used in a future version of Flutter. +abstract final class Window { } diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/cupertino/material/README.md b/novelforge-project/agent-workspace/flutter/packages/flutter/test/cupertino/material/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d927fbcc323d2b9c16c6b4cf851aea5665575c0c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/cupertino/material/README.md @@ -0,0 +1,4 @@ +# Tests for the Cupertino+Material mixed usages + +In this package, we test for interactions between Material and Cupertino +widgets. diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/cupertino/material/tab_scaffold_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/cupertino/material/tab_scaffold_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..2ccf74c1febb781093bcf312bbfd9ed8353dd994 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/cupertino/material/tab_scaffold_test.dart @@ -0,0 +1,344 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:typed_data'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../../image_data.dart'; + +late List<int> selectedTabs; + +void main() { + setUp(() { + selectedTabs = <int>[]; + }); + + testWidgets('Last tab gets focus', (WidgetTester tester) async { + // 2 nodes for 2 tabs + final List<FocusNode> focusNodes = <FocusNode>[]; + for (int i = 0; i < 2; i++) { + final FocusNode focusNode = FocusNode(); + focusNodes.add(focusNode); + addTearDown(focusNode.dispose); + } + + await tester.pumpWidget( + MaterialApp( + home: Material( + child: CupertinoTabScaffold( + tabBar: _buildTabBar(), + tabBuilder: (BuildContext context, int index) { + return TextField( + focusNode: focusNodes[index], + autofocus: true, + ); + }, + ), + ), + ), + ); + + expect(focusNodes[0].hasFocus, isTrue); + + await tester.tap(find.text('Tab 2')); + await tester.pump(); + + expect(focusNodes[0].hasFocus, isFalse); + expect(focusNodes[1].hasFocus, isTrue); + + await tester.tap(find.text('Tab 1')); + await tester.pump(); + + expect(focusNodes[0].hasFocus, isTrue); + expect(focusNodes[1].hasFocus, isFalse); + }); + + testWidgets('Do not affect focus order in the route', (WidgetTester tester) async { + final List<FocusNode> focusNodes = <FocusNode>[]; + for (int i = 0; i < 4; i++) { + final FocusNode focusNode = FocusNode(); + focusNodes.add(focusNode); + addTearDown(focusNode.dispose); + } + + await tester.pumpWidget( + MaterialApp( + home: Material( + child: CupertinoTabScaffold( + tabBar: _buildTabBar(), + tabBuilder: (BuildContext context, int index) { + return Column( + children: <Widget>[ + TextField( + focusNode: focusNodes[index * 2], + decoration: const InputDecoration( + hintText: 'TextField 1', + ), + ), + TextField( + focusNode: focusNodes[index * 2 + 1], + decoration: const InputDecoration( + hintText: 'TextField 2', + ), + ), + ], + ); + }, + ), + ), + ), + ); + + expect( + focusNodes.any((FocusNode node) => node.hasFocus), + isFalse, + ); + + await tester.tap(find.widgetWithText(TextField, 'TextField 2')); + + expect( + focusNodes.indexOf(focusNodes.singleWhere((FocusNode node) => node.hasFocus)), + 1, + ); + + await tester.tap(find.text('Tab 2')); + await tester.pump(); + + await tester.tap(find.widgetWithText(TextField, 'TextField 1')); + + expect( + focusNodes.indexOf(focusNodes.singleWhere((FocusNode node) => node.hasFocus)), + 2, + ); + + await tester.tap(find.text('Tab 1')); + await tester.pump(); + + // Upon going back to tab 1, the item it tab 1 that previously had the focus + // (TextField 2) gets it back. + expect( + focusNodes.indexOf(focusNodes.singleWhere((FocusNode node) => node.hasFocus)), + 1, + ); + }); + + testWidgets('Tab bar respects themes', (WidgetTester tester) async { + await tester.pumpWidget( + CupertinoApp( + home: CupertinoTabScaffold( + tabBar: _buildTabBar(), + tabBuilder: (BuildContext context, int index) { + return const Placeholder(); + }, + ), + ), + ); + + BoxDecoration tabDecoration = tester.widget<DecoratedBox>(find.descendant( + of: find.byType(CupertinoTabBar), + matching: find.byType(DecoratedBox), + )).decoration as BoxDecoration; + + expect(tabDecoration.color, isSameColorAs(const Color(0xF0F9F9F9))); // Inherited from theme. + + await tester.tap(find.text('Tab 2')); + await tester.pump(); + + // Pump again but with dark theme. + await tester.pumpWidget( + CupertinoApp( + theme: const CupertinoThemeData( + brightness: Brightness.dark, + primaryColor: CupertinoColors.destructiveRed, + ), + home: CupertinoTabScaffold( + tabBar: _buildTabBar(), + tabBuilder: (BuildContext context, int index) { + return const Placeholder(); + }, + ), + ), + ); + + tabDecoration = tester.widget<DecoratedBox>(find.descendant( + of: find.byType(CupertinoTabBar), + matching: find.byType(DecoratedBox), + )).decoration as BoxDecoration; + + expect(tabDecoration.color, isSameColorAs(const Color(0xF01D1D1D))); + + final RichText tab1 = tester.widget(find.descendant( + of: find.text('Tab 1'), + matching: find.byType(RichText), + )); + // Tab 2 should still be selected after changing theme. + expect(tab1.text.style!.color!.value, 0xFF757575); + final RichText tab2 = tester.widget(find.descendant( + of: find.text('Tab 2'), + matching: find.byType(RichText), + )); + expect(tab2.text.style!.color!.value, CupertinoColors.systemRed.darkColor.value); + }); + + testWidgets('dark mode background color', (WidgetTester tester) async { + const CupertinoDynamicColor backgroundColor = CupertinoDynamicColor.withBrightness( + color: Color(0xFF123456), + darkColor: Color(0xFF654321), + ); + await tester.pumpWidget( + CupertinoApp( + theme: const CupertinoThemeData(brightness: Brightness.light), + home: CupertinoTabScaffold( + backgroundColor: backgroundColor, + tabBar: _buildTabBar(), + tabBuilder: (BuildContext context, int index) { + return const Placeholder(); + }, + ), + ), + ); + + // The DecoratedBox with the smallest depth is the DecoratedBox of the + // CupertinoTabScaffold. + BoxDecoration tabDecoration = tester.firstWidget<DecoratedBox>( + find.descendant( + of: find.byType(CupertinoTabScaffold), + matching: find.byType(DecoratedBox), + ), + ).decoration as BoxDecoration; + + expect(tabDecoration.color!.value, backgroundColor.color.value); + + // Dark mode + await tester.pumpWidget( + CupertinoApp( + theme: const CupertinoThemeData(brightness: Brightness.dark), + home: CupertinoTabScaffold( + backgroundColor: backgroundColor, + tabBar: _buildTabBar(), + tabBuilder: (BuildContext context, int index) { + return const Placeholder(); + }, + ), + ), + ); + + tabDecoration = tester.firstWidget<DecoratedBox>( + find.descendant( + of: find.byType(CupertinoTabScaffold), + matching: find.byType(DecoratedBox), + ), + ).decoration as BoxDecoration; + + expect(tabDecoration.color!.value, backgroundColor.darkColor.value); + }); + + testWidgets('Does not lose state when focusing on text input', (WidgetTester tester) async { + // Regression testing for https://github.com/flutter/flutter/issues/28457. + + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(), + child: MaterialApp( + home: Material( + child: CupertinoTabScaffold( + tabBar: _buildTabBar(), + tabBuilder: (BuildContext context, int index) { + return const TextField(); + }, + ), + ), + ), + ), + ); + + final EditableTextState editableState = tester.state<EditableTextState>(find.byType(EditableText)); + + await tester.enterText(find.byType(TextField), "don't lose me"); + + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData( + viewInsets: EdgeInsets.only(bottom: 100), + ), + child: MaterialApp( + home: Material( + child: CupertinoTabScaffold( + tabBar: _buildTabBar(), + tabBuilder: (BuildContext context, int index) { + return const TextField(); + }, + ), + ), + ), + ), + ); + + // The exact same state instance is still there. + expect(tester.state<EditableTextState>(find.byType(EditableText)), editableState); + expect(find.text("don't lose me"), findsOneWidget); + }); + + testWidgets('textScaleFactor is set to 1.0', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Builder(builder: (BuildContext context) { + return MediaQuery( + data: MediaQuery.of(context).copyWith(textScaleFactor: 99), + child: CupertinoTabScaffold( + tabBar: CupertinoTabBar( + items: List<BottomNavigationBarItem>.generate( + 10, + (int i) => BottomNavigationBarItem(icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))), label: '$i'), + ), + ), + tabBuilder: (BuildContext context, int index) => const Text('content'), + ), + ); + }), + ), + ); + + final Iterable<RichText> barItems = tester.widgetList<RichText>( + find.descendant( + of: find.byType(CupertinoTabBar), + matching: find.byType(RichText), + ), + ); + + final Iterable<RichText> contents = tester.widgetList<RichText>( + find.descendant( + of: find.text('content'), + matching: find.byType(RichText), + skipOffstage: false, + ), + ); + + expect(barItems.length, greaterThan(0)); + expect(barItems, isNot(contains(predicate((RichText t) => t.textScaler != TextScaler.noScaling)))); + + expect(contents.length, greaterThan(0)); + expect(contents, isNot(contains(predicate((RichText t) => t.textScaler != const TextScaler.linear(99.0))))); + }); +} + +CupertinoTabBar _buildTabBar({ int selectedTab = 0 }) { + return CupertinoTabBar( + items: <BottomNavigationBarItem>[ + BottomNavigationBarItem( + icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))), + label: 'Tab 1', + ), + BottomNavigationBarItem( + icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))), + label: 'Tab 2', + ), + ], + currentIndex: selectedTab, + onTap: (int newTab) => selectedTabs.add(newTab), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_cross_axis_group_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_cross_axis_group_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..a238c14e915c914c39fab6b27ea4ad96dc09558c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_cross_axis_group_test.dart @@ -0,0 +1,957 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../rendering/sliver_utils.dart'; + + +const double VIEWPORT_HEIGHT = 600; +const double VIEWPORT_WIDTH = 300; + +void main() { + testWidgets('SliverCrossAxisGroup is laid out properly', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + _buildSliverList(itemMainAxisExtent: 300, items: items, label: (int item) => Text('Group 0 Tile $item')), + _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 1 Tile $item')), + ]), + ); + await tester.pumpAndSettle(); + + expect(controller.offset, 0); + + expect(find.text('Group 0 Tile 0'), findsOneWidget); + expect(find.text('Group 0 Tile 1'), findsOneWidget); + expect(find.text('Group 0 Tile 2'), findsNothing); + + expect(find.text('Group 1 Tile 0'), findsOneWidget); + expect(find.text('Group 1 Tile 2'), findsOneWidget); + expect(find.text('Group 1 Tile 3'), findsNothing); + + const double scrollOffset = 18 * 300.0; + controller.jumpTo(scrollOffset); + await tester.pumpAndSettle(); + + expect(controller.offset, scrollOffset); + expect(find.text('Group 0 Tile 17'), findsNothing); + expect(find.text('Group 0 Tile 18'), findsOneWidget); + expect(find.text('Group 0 Tile 19'), findsOneWidget); + expect(find.text('Group 1 Tile 19'), findsNothing); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + + expect(first.constraints.crossAxisExtent, equals(VIEWPORT_WIDTH / 2)); + expect(second.constraints.crossAxisExtent, equals(VIEWPORT_WIDTH / 2)); + + expect((first.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(0)); + expect((second.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(VIEWPORT_WIDTH / 2)); + + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20)); + }); + + testWidgets('SliverExpanded is laid out properly', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + slivers: <Widget>[ + SliverCrossAxisExpanded( + flex: 3, + sliver: _buildSliverList( + itemMainAxisExtent: 300, + items: items, + label: (int item) => Text('Group 0 Tile $item') + ), + ), + SliverCrossAxisExpanded( + flex: 2, + sliver: _buildSliverList( + itemMainAxisExtent: 200, + items: items, + label: (int item) => Text('Group 1 Tile $item') + ), + ), + ]), + ); + await tester.pumpAndSettle(); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + + expect(first.constraints.crossAxisExtent, equals(3 * VIEWPORT_WIDTH / 5)); + expect(second.constraints.crossAxisExtent, equals(2 * VIEWPORT_WIDTH / 5)); + + expect((first.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(0)); + expect((second.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(3 * VIEWPORT_WIDTH / 5)); + + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20)); + }); + + testWidgets('SliverConstrainedCrossAxis is laid out properly', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + slivers: <Widget>[ + SliverConstrainedCrossAxis(maxExtent: 60, sliver: _buildSliverList(itemMainAxisExtent: 300, items: items, label: (int item) => Text('Group 0 Tile $item'))), + SliverConstrainedCrossAxis(maxExtent: 120, sliver: _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 1 Tile $item'))), + ]), + ); + await tester.pumpAndSettle(); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + + expect(first.constraints.crossAxisExtent, equals(60)); + expect(second.constraints.crossAxisExtent, equals(120)); + + // Check that their parent SliverConstrainedCrossAxis have the correct paintOffsets. + final List<RenderSliverConstrainedCrossAxis> renderSliversConstrained = tester.renderObjectList<RenderSliverConstrainedCrossAxis>(find.byType(SliverConstrainedCrossAxis)).toList(); + final RenderSliverConstrainedCrossAxis firstConstrained = renderSliversConstrained[0]; + final RenderSliverConstrainedCrossAxis secondConstrained = renderSliversConstrained[1]; + + expect((firstConstrained.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(0)); + expect((secondConstrained.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(60)); + + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20)); + }); + + testWidgets('Mix of slivers is laid out properly', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + slivers: <Widget>[ + SliverConstrainedCrossAxis(maxExtent: 30, sliver: _buildSliverList(itemMainAxisExtent: 300, items: items, label: (int item) => Text('Group 0 Tile $item'))), + SliverCrossAxisExpanded(flex: 2, sliver: _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 1 Tile $item'))), + _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 2 Tile $item')), + ]), + ); + await tester.pumpAndSettle(); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + final RenderSliverList third = renderSlivers[2]; + + expect(first.constraints.crossAxisExtent, equals(30)); + expect(second.constraints.crossAxisExtent, equals(180)); + expect(third.constraints.crossAxisExtent, equals(90)); + + // Check that paint offset for sliver children are correct as well. + final RenderSliverCrossAxisGroup sliverCrossAxisRenderObject = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + RenderSliver child = sliverCrossAxisRenderObject.firstChild!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(0)); + child = sliverCrossAxisRenderObject.childAfter(child)!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(30)); + child = sliverCrossAxisRenderObject.childAfter(child)!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(210)); + + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20)); + }); + + testWidgets('Mix of slivers is laid out properly when horizontal', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + scrollDirection: Axis.horizontal, + slivers: <Widget>[ + SliverConstrainedCrossAxis( + maxExtent: 30, + sliver: _buildSliverList( + scrollDirection: Axis.horizontal, + itemMainAxisExtent: 300, + items: items, + label: (int item) => Text('Group 0 Tile $item') + ) + ), + SliverCrossAxisExpanded( + flex: 2, + sliver: _buildSliverList( + scrollDirection: Axis.horizontal, + itemMainAxisExtent: 200, + items: items, + label: (int item) => Text('Group 1 Tile $item') + ) + ), + _buildSliverList( + scrollDirection: Axis.horizontal, + itemMainAxisExtent: 200, + items: items, + label: (int item) => Text('Group 2 Tile $item') + ), + ]), + ); + await tester.pumpAndSettle(); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + final RenderSliverList third = renderSlivers[2]; + + expect(first.constraints.crossAxisExtent, equals(30)); + expect(second.constraints.crossAxisExtent, equals(380)); + expect(third.constraints.crossAxisExtent, equals(190)); + + // Check that paint offset for sliver children are correct as well. + final RenderSliverCrossAxisGroup sliverCrossAxisRenderObject = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + RenderSliver child = sliverCrossAxisRenderObject.firstChild!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0)); + child = sliverCrossAxisRenderObject.childAfter(child)!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(30)); + child = sliverCrossAxisRenderObject.childAfter(child)!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(410)); + + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20)); + }); + + testWidgets('Mix of slivers is laid out properly when reversed horizontal', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + scrollDirection: Axis.horizontal, + reverse: true, + slivers: <Widget>[ + SliverConstrainedCrossAxis( + maxExtent: 30, + sliver: _buildSliverList( + scrollDirection: Axis.horizontal, + itemMainAxisExtent: 300, + items: items, + label: (int item) => Text('Group 0 Tile $item') + ) + ), + SliverCrossAxisExpanded( + flex: 2, + sliver: _buildSliverList( + scrollDirection: Axis.horizontal, + itemMainAxisExtent: 200, + items: items, + label: (int item) => Text('Group 1 Tile $item') + ) + ), + _buildSliverList( + scrollDirection: Axis.horizontal, + itemMainAxisExtent: 200, + items: items, + label: (int item) => Text('Group 2 Tile $item') + ), + ]), + ); + await tester.pumpAndSettle(); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + final RenderSliverList third = renderSlivers[2]; + + expect(first.constraints.crossAxisExtent, equals(30)); + expect(second.constraints.crossAxisExtent, equals(380)); + expect(third.constraints.crossAxisExtent, equals(190)); + + // Check that paint offset for sliver children are correct as well. + final RenderSliverCrossAxisGroup sliverCrossAxisRenderObject = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + RenderSliver child = sliverCrossAxisRenderObject.firstChild!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0)); + child = sliverCrossAxisRenderObject.childAfter(child)!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(30)); + child = sliverCrossAxisRenderObject.childAfter(child)!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(410)); + + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20)); + }); + + testWidgets('Mix of slivers is laid out properly when reversed vertical', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + reverse: true, + slivers: <Widget>[ + SliverConstrainedCrossAxis( + maxExtent: 30, + sliver: _buildSliverList( + itemMainAxisExtent: 300, + items: items, + label: (int item) => Text('Group 0 Tile $item') + ) + ), + SliverCrossAxisExpanded( + flex: 2, + sliver: _buildSliverList( + itemMainAxisExtent: 200, + items: items, + label: (int item) => Text('Group 1 Tile $item') + ) + ), + _buildSliverList( + itemMainAxisExtent: 200, + items: items, + label: (int item) => Text('Group 2 Tile $item') + ), + ]), + ); + await tester.pumpAndSettle(); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + final RenderSliverList third = renderSlivers[2]; + + expect(first.constraints.crossAxisExtent, equals(30)); + expect(second.constraints.crossAxisExtent, equals(180)); + expect(third.constraints.crossAxisExtent, equals(90)); + + // Check that paint offset for sliver children are correct as well. + final RenderSliverCrossAxisGroup sliverCrossAxisRenderObject = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + RenderSliver child = sliverCrossAxisRenderObject.firstChild!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(0)); + child = sliverCrossAxisRenderObject.childAfter(child)!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(30)); + child = sliverCrossAxisRenderObject.childAfter(child)!; + expect((child.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(210)); + + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20)); + }); + + testWidgets('Assertion error when SliverExpanded is used outside of SliverCrossAxisGroup', (WidgetTester tester) async { + final List<FlutterErrorDetails> errors = <FlutterErrorDetails>[]; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + FlutterError.onError = (FlutterErrorDetails error) => errors.add(error); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: CustomScrollView( + slivers: <Widget>[ + SliverCrossAxisExpanded( + flex: 2, + sliver: SliverToBoxAdapter( + child: Text('Hello World'), + ), + ), + ], + ), + ), + ), + ); + FlutterError.onError = oldHandler; + expect(errors, isNotEmpty); + final AssertionError error = errors.first.exception as AssertionError; + expect( + error.toString(), + contains('renderObject.parent is RenderSliverCrossAxisGroup'), + ); + }); + + testWidgets('Hit test works properly on various parts of SliverCrossAxisGroup', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + String? clickedTile; + + int group = 0; + int tile = 0; + + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + _buildSliverList( + itemMainAxisExtent: 300, + items: items, + label: (int item) => tile == item && group == 0 + ? TextButton( + onPressed: () => clickedTile = 'Group 0 Tile $item', + child: Text('Group 0 Tile $item'), + ) + : Text('Group 0 Tile $item'), + ), + _buildSliverList( + items: items, + label: (int item) => tile == item && group == 1 + ? TextButton( + onPressed: () => clickedTile = 'Group 1 Tile $item', + child: Text('Group 1 Tile $item'), + ) + : Text('Group 1 Tile $item'), + ), + ]), + ); + await tester.pumpAndSettle(); + await tester.tap(find.byType(TextButton)); + await tester.pumpAndSettle(); + expect(clickedTile, equals('Group 0 Tile 0')); + + clickedTile = null; + group = 1; + tile = 2; + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + _buildSliverList( + itemMainAxisExtent: 300, + items: items, + label: (int item) => tile == item && group == 0 + ? TextButton( + onPressed: () => clickedTile = 'Group 0 Tile $item', + child: Text('Group 0 Tile $item'), + ) + : Text('Group 0 Tile $item'), + ), + _buildSliverList( + items: items, + label: (int item) => tile == item && group == 1 + ? TextButton( + onPressed: () => clickedTile = 'Group 1 Tile $item', + child: Text('Group 1 Tile $item'), + ) + : Text('Group 1 Tile $item'), + ), + ]), + ); + await tester.pumpAndSettle(); + await tester.tap(find.byType(TextButton)); + await tester.pumpAndSettle(); + expect(clickedTile, equals('Group 1 Tile 2')); + }); + + testWidgets('Constrained sliver takes up remaining space', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + slivers: <Widget>[ + SliverConstrainedCrossAxis(maxExtent: 200, sliver: _buildSliverList(itemMainAxisExtent: 300, items: items, label: (int item) => Text('Group 0 Tile $item'))), + SliverConstrainedCrossAxis(maxExtent: 200, sliver: _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 1 Tile $item'))), + ]), + ); + await tester.pumpAndSettle(); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + + expect(first.constraints.crossAxisExtent, equals(200)); + expect(second.constraints.crossAxisExtent, equals(100)); + + // Check that their parent SliverConstrainedCrossAxis have the correct paintOffsets. + final List<RenderSliverConstrainedCrossAxis> renderSliversConstrained = tester.renderObjectList<RenderSliverConstrainedCrossAxis>(find.byType(SliverConstrainedCrossAxis)).toList(); + final RenderSliverConstrainedCrossAxis firstConstrained = renderSliversConstrained[0]; + final RenderSliverConstrainedCrossAxis secondConstrained = renderSliversConstrained[1]; + + expect((firstConstrained.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(0)); + expect((secondConstrained.parentData! as SliverPhysicalParentData).paintOffset.dx, equals(200)); + + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject<RenderSliverCrossAxisGroup>(find.byType(SliverCrossAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20)); + }); + + testWidgets('Assertion error when constrained widget runs out of cross axis extent', (WidgetTester tester) async { + final List<FlutterErrorDetails> errors = <FlutterErrorDetails>[]; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + FlutterError.onError = (FlutterErrorDetails error) => errors.add(error); + + final List<int> items = List<int>.generate(20, (int i) => i); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + slivers: <Widget>[ + SliverConstrainedCrossAxis(maxExtent: 400, sliver: _buildSliverList(itemMainAxisExtent: 300, items: items, label: (int item) => Text('Group 0 Tile $item'))), + SliverConstrainedCrossAxis(maxExtent: 200, sliver: _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 1 Tile $item'))), + ]), + ); + await tester.pumpAndSettle(); + FlutterError.onError = oldHandler; + expect(errors, isNotEmpty); + final AssertionError error = errors.first.exception as AssertionError; + expect( + error.toString(), + contains('SliverCrossAxisGroup ran out of extent before child could be laid out.'), + ); + }); + + testWidgets('Assertion error when expanded widget runs out of cross axis extent', (WidgetTester tester) async { + final List<FlutterErrorDetails> errors = <FlutterErrorDetails>[]; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + FlutterError.onError = (FlutterErrorDetails error) => errors.add(error); + + final List<int> items = List<int>.generate(20, (int i) => i); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + slivers: <Widget>[ + SliverConstrainedCrossAxis(maxExtent: 200, sliver: _buildSliverList(itemMainAxisExtent: 300, items: items, label: (int item) => Text('Group 0 Tile $item'))), + SliverConstrainedCrossAxis(maxExtent: 100, sliver: _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 1 Tile $item'))), + _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 2 Tile $item')), + ]), + ); + await tester.pumpAndSettle(); + FlutterError.onError = oldHandler; + expect(errors, isNotEmpty); + final AssertionError error = errors.first.exception as AssertionError; + expect( + error.toString(), + contains('SliverCrossAxisGroup ran out of extent before child could be laid out.'), + ); + }); + + testWidgets('applyPaintTransform is implemented properly', (WidgetTester tester) async { + await tester.pumpWidget(_buildSliverCrossAxisGroup( + slivers: <Widget>[ + const SliverToBoxAdapter(child: Text('first box')), + const SliverToBoxAdapter(child: Text('second box')), + ]), + ); + await tester.pumpAndSettle(); + + // localToGlobal calculates offset via applyPaintTransform + final RenderBox first = tester.renderObject(find.text('first box')); + final RenderBox second = tester.renderObject(find.text('second box')); + expect(first.localToGlobal(Offset.zero), Offset.zero); + expect(second.localToGlobal(Offset.zero), const Offset(VIEWPORT_WIDTH / 2, 0)); + }); + + testWidgets('SliverPinnedPersistentHeader is painted within bounds of SliverCrossAxisGroup', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 600)), + SliverPersistentHeader( + delegate: TestDelegate(), + pinned: true, + ), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject(find.byType(SliverCrossAxisGroup)) as RenderSliverCrossAxisGroup; + expect(renderGroup.geometry!.scrollExtent, equals(600)); + controller.jumpTo(560); + await tester.pumpAndSettle(); + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + // Paint extent after header's layout is 60.0, so we must offset by -20.0 to fit within the 40.0 remaining extent. + expect(renderHeader.geometry!.paintExtent, equals(60.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-20.0)); + }); + + testWidgets('SliverFloatingPersistentHeader is painted within bounds of SliverCrossAxisGroup', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 600)), + SliverPersistentHeader( + delegate: TestDelegate(), + floating: true, + ), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject(find.byType(SliverCrossAxisGroup)) as RenderSliverCrossAxisGroup; + expect(renderGroup.geometry!.scrollExtent, equals(600)); + controller.jumpTo(600.0); + await tester.pumpAndSettle(); + final TestGesture gesture = await tester.startGesture(const Offset(150.0, 300.0)); + await gesture.moveBy(const Offset(0.0, 40)); + await tester.pump(); + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + // Paint extent after header's layout is 40.0, so no need to correct the paintOffset. + expect(renderHeader.geometry!.paintExtent, equals(40.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + }); + + testWidgets('SliverPinnedPersistentHeader is painted within bounds of SliverCrossAxisGroup with different minExtent/maxExtent', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 600)), + SliverPersistentHeader( + delegate: TestDelegate(minExtent: 40.0), + pinned: true, + ), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject(find.byType(SliverCrossAxisGroup)) as RenderSliverCrossAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(600)); + controller.jumpTo(570); + await tester.pumpAndSettle(); + // Paint extent of the header is 40.0, so we must provide an offset of -10.0 to make it fit in the 30.0 remaining paint extent of the group. + expect(renderHeader.geometry!.paintExtent, equals(40.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-10.0)); + // Pinned headers should not expand to the maximum extent unless the scroll offset is at the top of the sliver group. + controller.jumpTo(550); + await tester.pumpAndSettle(); + expect(renderHeader.geometry!.paintExtent, equals(40.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + }); + + testWidgets('SliverFloatingPersistentHeader is painted within bounds of SliverCrossAxisGroup with different minExtent/maxExtent', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 600)), + SliverPersistentHeader( + delegate: TestDelegate(minExtent: 40.0), + floating: true, + ), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject(find.byType(SliverCrossAxisGroup)) as RenderSliverCrossAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(600)); + + controller.jumpTo(600); + await tester.pumpAndSettle(); + + final TestGesture gesture = await tester.startGesture(const Offset(150.0, 300.0)); + await gesture.moveBy(const Offset(0.0, 30.0)); + await tester.pump(); + // Paint extent after header's layout is 30.0, so no need to correct the paintOffset. + expect(renderHeader.geometry!.paintExtent, equals(30.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + // Floating headers should expand to maximum extent as we continue scrolling. + await gesture.moveBy(const Offset(0.0, 20.0)); + await tester.pump(); + expect(renderHeader.geometry!.paintExtent, equals(50.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + }); + + testWidgets('SliverPinnedFloatingPersistentHeader is painted within bounds of SliverCrossAxisGroup with different minExtent/maxExtent', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 600)), + SliverPersistentHeader( + delegate: TestDelegate(minExtent: 40.0), + pinned: true, + floating: true, + ), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject(find.byType(SliverCrossAxisGroup)) as RenderSliverCrossAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(600)); + + controller.jumpTo(600); + await tester.pumpAndSettle(); + + final TestGesture gesture = await tester.startGesture(const Offset(150.0, 300.0)); + await gesture.moveBy(const Offset(0.0, 30.0)); + await tester.pump(); + // Paint extent after header's layout is 40.0, so we need to adjust by -10.0. + expect(renderHeader.geometry!.paintExtent, equals(40.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-10.0)); + // Pinned floating headers should expand to maximum extent as we continue scrolling. + await gesture.moveBy(const Offset(0.0, 20.0)); + await tester.pump(); + expect(renderHeader.geometry!.paintExtent, equals(50.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + }); + + testWidgets('SliverAppBar with floating: false, pinned: false, snap: false is painted within bounds of SliverCrossAxisGroup', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 600)), + const SliverAppBar( + toolbarHeight: 30, + expandedHeight: 60, + ), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject(find.byType(SliverCrossAxisGroup)) as RenderSliverCrossAxisGroup; + expect(renderGroup.geometry!.scrollExtent, equals(600)); + + controller.jumpTo(600); + await tester.pumpAndSettle(); + controller.jumpTo(570); + await tester.pumpAndSettle(); + + // At a scroll offset of 570, a normal scrolling header should be out of view. + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderHeader.geometry!.paintExtent, equals(0.0)); + }); + + testWidgets('SliverAppBar with floating: true, pinned: false, snap: true is painted within bounds of SliverCrossAxisGroup', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 600)), + const SliverAppBar( + toolbarHeight: 30, + expandedHeight: 60, + floating: true, + snap: true, + ), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject(find.byType(SliverCrossAxisGroup)) as RenderSliverCrossAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(600)); + + controller.jumpTo(600); + await tester.pumpAndSettle(); + + final TestGesture gesture = await tester.startGesture(const Offset(150.0, 300.0)); + await gesture.moveBy(const Offset(0.0, 10)); + await tester.pump(); + + // The snap animation does not go through until the gesture is released. + expect(renderHeader.geometry!.paintExtent, equals(10)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + + // Once it is released, the header's paint extent becomes the maximum and the group sets an offset of -50.0. + await gesture.up(); + await tester.pumpAndSettle(); + expect(renderHeader.geometry!.paintExtent, equals(60)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-50.0)); + }); + + testWidgets('SliverAppBar with floating: true, pinned: true, snap: true is painted within bounds of SliverCrossAxisGroup', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 600)), + const SliverAppBar( + toolbarHeight: 30, + expandedHeight: 60, + floating: true, + pinned: true, + snap: true, + ), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject(find.byType(SliverCrossAxisGroup)) as RenderSliverCrossAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(600)); + + controller.jumpTo(600); + await tester.pumpAndSettle(); + + final TestGesture gesture = await tester.startGesture(const Offset(150.0, 300.0)); + await gesture.moveBy(const Offset(0.0, 10)); + await tester.pump(); + + expect(renderHeader.geometry!.paintExtent, equals(30.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-20.0)); + + // Once we lift the gesture up, the animation should finish. + await gesture.up(); + await tester.pumpAndSettle(); + expect(renderHeader.geometry!.paintExtent, equals(60.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-50.0)); + }); + + testWidgets('SliverFloatingPersistentHeader scroll direction is not affected by controller.jumpTo', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(_buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 600)), + SliverPersistentHeader( + delegate: TestDelegate(), + floating: true, + ), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverCrossAxisGroup renderGroup = tester.renderObject(find.byType(SliverCrossAxisGroup)) as RenderSliverCrossAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(600)); + + controller.jumpTo(600); + await tester.pumpAndSettle(); + controller.jumpTo(570); + await tester.pumpAndSettle(); + + // If renderHeader._lastStartedScrollDirection is not ScrollDirection.forward, then we shouldn't see the header at all. + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + }); + + testWidgets('SliverCrossAxisGroup skips painting invisible children', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + int counter = 0; + void incrementCounter() { + counter += 1; + } + + await tester.pumpWidget( + _buildSliverCrossAxisGroup( + controller: controller, + slivers: <Widget>[ + MockSliverToBoxAdapter( + incrementCounter: incrementCounter, + child: Container( + height: 1000, + decoration: const BoxDecoration(color: Colors.amber), + ), + ), + MockSliverToBoxAdapter( + incrementCounter: incrementCounter, + child: Container( + height: 400, + decoration: const BoxDecoration(color: Colors.amber) + ), + ), + MockSliverToBoxAdapter( + incrementCounter: incrementCounter, + child: Container( + height: 500, + decoration: const BoxDecoration(color: Colors.amber) + ), + ), + MockSliverToBoxAdapter( + incrementCounter: incrementCounter, + child: Container( + height: 300, + decoration: const BoxDecoration(color: Colors.amber) + ), + ), + ], + ), + ); + expect(counter, equals(4)); + + // Reset paint counter. + counter = 0; + controller.jumpTo(400); + await tester.pumpAndSettle(); + + expect(controller.offset, 400); + expect(counter, equals(2)); + }); +} + + +Widget _buildSliverList({ + double itemMainAxisExtent = 100, + List<int> items = const <int>[], + required Widget Function(int) label, + Axis scrollDirection = Axis.vertical, +}) { + return SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int i) { + return scrollDirection == Axis.vertical + ? SizedBox( + key: ValueKey<int>(items[i]), + height: itemMainAxisExtent, + child: label(items[i]), + ) + : SizedBox( + key: ValueKey<int>(items[i]), + width: itemMainAxisExtent, + child: label(items[i])); + }, + findChildIndexCallback: (Key key) { + final ValueKey<int> valueKey = key as ValueKey<int>; + final int index = items.indexOf(valueKey.value); + return index == -1 ? null : index; + }, + childCount: items.length, + ), + ); +} + +Widget _buildSliverCrossAxisGroup({ + required List<Widget> slivers, + ScrollController? controller, + double viewportHeight = VIEWPORT_HEIGHT, + double viewportWidth = VIEWPORT_WIDTH, + Axis scrollDirection = Axis.vertical, + bool reverse = false, + List<Widget> otherSlivers = const <Widget>[], +}) { + return MaterialApp( + home: Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + height: viewportHeight, + width: viewportWidth, + child: CustomScrollView( + scrollDirection: scrollDirection, + reverse: reverse, + controller: controller, + slivers: <Widget>[SliverCrossAxisGroup(slivers: slivers), ...otherSlivers], + ), + ), + ), + ) + ); +} + +class TestDelegate extends SliverPersistentHeaderDelegate { + TestDelegate({ this.maxExtent = 60.0, this.minExtent = 60.0 }); + + @override + final double maxExtent; + + @override + final double minExtent; + + @override + Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) { + return Container(height: maxExtent); + } + + @override + bool shouldRebuild(TestDelegate oldDelegate) => true; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_fill_remaining_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_fill_remaining_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..90692a69394b8bbd99c1602a353d58e3dec00645 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_fill_remaining_test.dart @@ -0,0 +1,829 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + + // Helpers + final Widget sliverBox = SliverToBoxAdapter( + child: Container( + color: Colors.amber, + height: 150.0, + width: 150, + ), + ); + Widget boilerplate( + List<Widget> slivers, { + ScrollController? controller, + Axis scrollDirection = Axis.vertical, + }) { + return MaterialApp( + theme: ThemeData( + useMaterial3: false, + materialTapTargetSize: MaterialTapTargetSize.padded, + ), + home: Scaffold( + body: CustomScrollView( + scrollDirection: scrollDirection, + slivers: slivers, + controller: controller, + ), + ), + ); + } + + group('SliverFillRemaining', () { + group('hasScrollBody: true, default', () { + testWidgets('no siblings', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: CustomScrollView( + controller: controller, + slivers: <Widget>[ + SliverFillRemaining(child: Container()), + ], + ), + ), + ); + expect( + tester.renderObject<RenderBox>(find.byType(Container)).size.height, + equals(600.0), + ); + + controller.jumpTo(50.0); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byType(Container)).size.height, + equals(600.0), + ); + + controller.jumpTo(-100.0); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byType(Container)).size.height, + equals(600.0), + ); + + controller.jumpTo(0.0); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byType(Container)).size.height, + equals(600.0), + ); + }); + + testWidgets('one sibling', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: CustomScrollView( + controller: controller, + slivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 100.0)), + SliverFillRemaining(child: Container()), + ], + ), + ), + ); + expect( + tester.renderObject<RenderBox>(find.byType(Container)).size.height, + equals(500.0), + ); + + controller.jumpTo(50.0); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byType(Container)).size.height, + equals(550.0), + ); + + controller.jumpTo(-100.0); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byType(Container)).size.height, + equals(400.0), + ); + + controller.jumpTo(0.0); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byType(Container)).size.height, + equals(500.0), + ); + }); + + testWidgets('scrolls beyond viewportMainAxisExtent', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + child: Container(color: Colors.white), + ), + ]; + await tester.pumpWidget(boilerplate(slivers, controller: controller)); + expect(controller.offset, 0.0); + expect(find.byType(Container), findsNWidgets(2)); + controller.jumpTo(150.0); + await tester.pumpAndSettle(); + expect(controller.offset, 150.0); + expect(find.byType(Container), findsOneWidget); + }); + }); + + group('hasScrollBody: false', () { + testWidgets('does not extend past viewportMainAxisExtent', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + hasScrollBody: false, + child: Container(color: Colors.white), + ), + ]; + + await tester.pumpWidget(boilerplate(slivers, controller: controller)); + expect(controller.offset, 0.0); + expect(find.byType(Container), findsNWidgets(2)); + controller.jumpTo(150.0); + await tester.pumpAndSettle(); + expect(controller.offset, 0.0); + expect(find.byType(Container), findsNWidgets(2)); + }); + + testWidgets('child without size is sized by extent', (WidgetTester tester) async { + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + hasScrollBody: false, + child: Container(color: Colors.blue), + ), + ]; + + await tester.pumpWidget(boilerplate(slivers)); + RenderBox box = tester.renderObject<RenderBox>(find.byType(Container).last); + expect(box.size.height, equals(450)); + + await tester.pumpWidget(boilerplate( + slivers, + scrollDirection: Axis.horizontal, + )); + box = tester.renderObject<RenderBox>(find.byType(Container).last); + expect(box.size.width, equals(650)); + }); + + testWidgets('child with smaller size is sized by extent', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + hasScrollBody: false, + child: ColoredBox( + key: key, + color: Colors.blue, + child: Align( + alignment: Alignment.bottomCenter, + child: ElevatedButton( + child: const Text('bottomCenter button'), + onPressed: () {}, + ), + ), + ), + ), + ]; + await tester.pumpWidget(boilerplate(slivers)); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(450), + ); + + // Also check that the button alignment is true to expectations + final Finder button = find.byType(ElevatedButton); + expect(tester.getBottomLeft(button).dy, equals(600.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + + // Check Axis.horizontal + await tester.pumpWidget(boilerplate( + slivers, + scrollDirection: Axis.horizontal, + )); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.width, + equals(650), + ); + }); + + testWidgets('extent is overridden by child with larger size', (WidgetTester tester) async { + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + hasScrollBody: false, + child: Container( + color: Colors.blue, + height: 600, + width: 1000, + ), + ), + ]; + await tester.pumpWidget(boilerplate(slivers)); + RenderBox box = tester.renderObject<RenderBox>(find.byType(Container).last); + expect(box.size.height, equals(600)); + + await tester.pumpWidget(boilerplate( + slivers, + scrollDirection: Axis.horizontal, + )); + box = tester.renderObject<RenderBox>(find.byType(Container).last); + expect(box.size.width, equals(1000)); + }); + + testWidgets('extent is overridden by child size if precedingScrollExtent > viewportMainAxisExtent', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final List<Widget> slivers = <Widget>[ + SliverFixedExtentList( + itemExtent: 150, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => Container(color: Colors.amber), + childCount: 5, + ), + ), + SliverFillRemaining( + hasScrollBody: false, + child: Container( + key: key, + color: Colors.blue[300], + child: Align( + child: Padding( + padding: const EdgeInsets.all(50.0), + child: ElevatedButton( + child: const Text('center button'), + onPressed: () {}, + ), + ), + ), + ), + ), + ]; + await tester.pumpWidget(boilerplate(slivers)); + await tester.drag(find.byType(Scrollable), const Offset(0.0, -750.0)); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(148.0), + ); + + // Also check that the button alignment is true to expectations + final Finder button = find.byType(ElevatedButton); + expect(tester.getBottomLeft(button).dy, equals(550.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + }); + + testWidgets('alignment with a flexible works', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + hasScrollBody: false, + child: Column( + key: key, + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + const Flexible( + child: Center(child: FlutterLogo(size: 100)), + ), + ElevatedButton( + child: const Text('Bottom'), + onPressed: () {}, + ), + ], + ), + ), + ]; + + await tester.pumpWidget(boilerplate(slivers)); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(450), + ); + + // Check that the logo alignment is true to expectations + final Finder logo = find.byType(FlutterLogo); + expect( + tester.renderObject<RenderBox>(logo).size, + const Size(100.0, 100.0), + ); + final VisualDensity density = VisualDensity.adaptivePlatformDensity; + expect(tester.getCenter(logo), Offset(400.0, 351.0 - density.vertical * 2.0)); + + // Also check that the button alignment is true to expectations + // Buttons do not decrease their horizontal padding per the VisualDensity. + final Finder button = find.byType(ElevatedButton); + expect( + tester.renderObject<RenderBox>(button).size, + Size(116.0 + math.max(0, density.horizontal) * 8.0, 48.0 + density.vertical * 4.0), + ); + expect(tester.getBottomLeft(button).dy, equals(600.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + + // Overscroll and see that alignment and size is maintained + await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0)); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(450), + ); + expect( + tester.renderObject<RenderBox>(logo).size, + const Size(100.0, 100.0), + ); + expect(tester.getCenter(logo).dy, lessThan(351.0)); + expect( + tester.renderObject<RenderBox>(button).size, + // Buttons do not decrease their horizontal padding per the VisualDensity. + Size(116.0 + math.max(0, density.horizontal) * 8.0, 48.0 + density.vertical * 4.0), + ); + expect(tester.getBottomLeft(button).dy, lessThan(600.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); + + group('fillOverscroll: true, relevant platforms', () { + testWidgets('child without size is sized by extent and overscroll', (WidgetTester tester) async { + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + hasScrollBody: false, + fillOverscroll: true, + child: Container(color: Colors.blue), + ), + ]; + + // Check size + await tester.pumpWidget(boilerplate(slivers)); + final RenderBox box1 = tester.renderObject<RenderBox>(find.byType(Container).last); + expect(box1.size.height, equals(450)); + + // Overscroll and check size + await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0)); + await tester.pump(); + final RenderBox box2 = tester.renderObject<RenderBox>(find.byType(Container).last); + expect(box2.size.height, greaterThan(450)); + + // Ensure overscroll retracts to original size after releasing gesture + await tester.pumpAndSettle(); + final RenderBox box3 = tester.renderObject<RenderBox>(find.byType(Container).last); + expect(box3.size.height, equals(450)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); + + testWidgets('child with smaller size is overridden and sized by extent and overscroll', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + hasScrollBody: false, + fillOverscroll: true, + child: ColoredBox( + key: key, + color: Colors.blue, + child: Align( + alignment: Alignment.bottomCenter, + child: ElevatedButton( + child: const Text('bottomCenter button'), + onPressed: () {}, + ), + ), + ), + ), + ]; + await tester.pumpWidget(boilerplate(slivers)); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(450), + ); + + await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0)); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + greaterThan(450), + ); + + // Also check that the button alignment is true to expectations, even with + // child stretching to fill overscroll + final Finder button = find.byType(ElevatedButton); + expect(tester.getBottomLeft(button).dy, equals(600.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + + // Ensure overscroll retracts to original size after releasing gesture + await tester.pumpAndSettle(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(450), + ); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); + + testWidgets('extent is overridden by child size and overscroll if precedingScrollExtent > viewportMainAxisExtent', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + final List<Widget> slivers = <Widget>[ + SliverFixedExtentList( + itemExtent: 150, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => + Container(color: Colors.amber), + childCount: 5, + ), + ), + SliverFillRemaining( + hasScrollBody: false, + fillOverscroll: true, + child: Container( + key: key, + color: Colors.blue[300], + child: Align( + child: Padding( + padding: const EdgeInsets.all(50.0), + child: ElevatedButton( + child: const Text('center button'), + onPressed: () {}, + ), + ), + ), + ), + ), + ]; + await tester.pumpWidget(boilerplate(slivers, controller: controller)); + + // Scroll to the end + controller.jumpTo(controller.position.maxScrollExtent); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(148.0 + VisualDensity.adaptivePlatformDensity.vertical * 4.0), + ); + // Check that the button alignment is true to expectations + final Finder button = find.byType(ElevatedButton); + expect(tester.getBottomLeft(button).dy, equals(550.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + + // Drag for overscroll + await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0)); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + greaterThan(148.0), + ); + + // Check that the button alignment is still centered in stretched child + expect(tester.getBottomLeft(button).dy, lessThan(550.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + + // Ensure overscroll retracts to original size after releasing gesture + await tester.pumpAndSettle(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(148.0 + VisualDensity.adaptivePlatformDensity.vertical * 4.0), + ); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); + + testWidgets('fillOverscroll works when child has no size and precedingScrollExtent > viewportMainAxisExtent', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + final List<Widget> slivers = <Widget>[ + SliverFixedExtentList( + itemExtent: 150, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return Semantics(label: index.toString(), child: Container(color: Colors.amber)); + }, + childCount: 5, + ), + ), + SliverFillRemaining( + hasScrollBody: false, + fillOverscroll: true, + child: Container( + key: key, + color: Colors.blue, + ), + ), + ]; + + await tester.pumpWidget(boilerplate(slivers, controller: controller)); + + expect(find.byKey(key), findsNothing); + expect( + find.bySemanticsLabel('4'), + findsNothing, + ); + + // Scroll to bottom + controller.jumpTo(controller.position.maxScrollExtent); + await tester.pump(); + + // Check item at the end of the list + expect(find.byKey(key), findsNothing); + expect( + find.bySemanticsLabel('4'), + findsOneWidget, + ); + + // Overscroll + await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0)); + await tester.pump(); + + // Check for new item at the end of the now overscrolled list + expect(find.byKey(key), findsOneWidget); + expect( + find.bySemanticsLabel('4'), + findsOneWidget, + ); + + // Ensure overscroll retracts to original size after releasing gesture + await tester.pumpAndSettle(); + expect(find.byKey(key), findsNothing); + expect( + find.bySemanticsLabel('4'), + findsOneWidget, + ); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); + + testWidgets('alignment with a flexible works with fillOverscroll', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + hasScrollBody: false, + fillOverscroll: true, + child: Column( + key: key, + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + const Flexible( + child: Center(child: FlutterLogo(size: 100)), + ), + ElevatedButton( + child: const Text('Bottom'), + onPressed: () {}, + ), + ], + ), + ), + ]; + + await tester.pumpWidget(boilerplate(slivers)); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(450), + ); + + // Check that the logo alignment is true to expectations. + final Finder logo = find.byType(FlutterLogo); + expect( + tester.renderObject<RenderBox>(logo).size, + const Size(100.0, 100.0), + ); + final VisualDensity density = VisualDensity.adaptivePlatformDensity; + expect(tester.getCenter(logo), Offset(400.0, 351.0 - density.vertical * 2.0)); + + // Also check that the button alignment is true to expectations. + // Buttons do not decrease their horizontal padding per the VisualDensity. + final Finder button = find.byType(ElevatedButton); + expect( + tester.renderObject<RenderBox>(button).size, + Size(116.0 + math.max(0, density.horizontal) * 8.0, 48.0 + density.vertical * 4.0), + ); + expect(tester.getBottomLeft(button).dy, equals(600.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + + // Overscroll and see that logo alignment shifts to maintain center as + // container stretches with overscroll, button remains aligned at the + // bottom. + await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0)); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + greaterThan(450), + ); + expect( + tester.renderObject<RenderBox>(logo).size, + const Size(100.0, 100.0), + ); + expect(tester.getCenter(logo).dy, lessThan(351.0)); + expect( + tester.renderObject<RenderBox>(button).size, + // Buttons do not decrease their horizontal padding per the VisualDensity. + Size(116.0 + math.max(0, density.horizontal) * 8.0, 48.0 + density.vertical * 4.0), + ); + expect(tester.getBottomLeft(button).dy, equals(600.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + + // Ensure overscroll retracts to original position when gesture is + // released. + await tester.pumpAndSettle(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(450), + ); + expect( + tester.renderObject<RenderBox>(logo).size, + const Size(100.0, 100.0), + ); + expect(tester.getCenter(logo), Offset(400.0, 351.0 - density.vertical * 2.0)); + expect( + tester.renderObject<RenderBox>(button).size, + // Buttons do not decrease their horizontal padding per the VisualDensity. + Size(116.0 + math.max(0, density.horizontal) * 8.0, 48.0 + density.vertical * 4.0), + ); + expect(tester.getBottomLeft(button).dy, equals(600.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); + }); + + group('fillOverscroll: true, is ignored on irrelevant platforms', () { + // Android/Other scroll physics when hasScrollBody: false, ignores fillOverscroll: true + testWidgets('child without size is sized by extent', (WidgetTester tester) async { + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + hasScrollBody: false, + fillOverscroll: true, + child: Container(color: Colors.blue), + ), + ]; + await tester.pumpWidget(boilerplate(slivers)); + final RenderBox box1 = tester.renderObject<RenderBox>(find.byType(Container).last); + expect(box1.size.height, equals(450)); + + await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0)); + await tester.pump(); + final RenderBox box2 = tester.renderObject<RenderBox>(find.byType(Container).last); + expect(box2.size.height, equals(450)); + }); + + testWidgets('child with size is overridden and sized by extent', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final List<Widget> slivers = <Widget>[ + sliverBox, + SliverFillRemaining( + hasScrollBody: false, + fillOverscroll: true, + child: ColoredBox( + key: key, + color: Colors.blue, + child: Align( + alignment: Alignment.bottomCenter, + child: ElevatedButton( + child: const Text('bottomCenter button'), + onPressed: () {}, + ), + ), + ), + ), + ]; + await tester.pumpWidget(boilerplate(slivers)); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(450), + ); + + await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0)); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(450), + ); + + // Also check that the button alignment is true to expectations + final Finder button = find.byType(ElevatedButton); + expect(tester.getBottomLeft(button).dy, equals(600.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + }); + + testWidgets('extent is overridden by child size if precedingScrollExtent > viewportMainAxisExtent', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + final List<Widget> slivers = <Widget>[ + SliverFixedExtentList( + itemExtent: 150, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => + Container(color: Colors.amber), + childCount: 5, + ), + ), + SliverFillRemaining( + hasScrollBody: false, + fillOverscroll: true, + child: Container( + key: key, + color: Colors.blue[300], + child: Align( + child: Padding( + padding: const EdgeInsets.all(50.0), + child: ElevatedButton( + child: const Text('center button'), + onPressed: () {}, + ), + ), + ), + ), + ), + ]; + await tester.pumpWidget(boilerplate(slivers, controller: controller)); + + // Scroll to the end + controller.jumpTo(controller.position.maxScrollExtent); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(148.0), + ); + + // Check that the button alignment is true to expectations + final Finder button = find.byType(ElevatedButton); + expect(tester.getBottomLeft(button).dy, equals(550.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + + await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0)); + await tester.pump(); + expect( + tester.renderObject<RenderBox>(find.byKey(key)).size.height, + equals(148.0), + ); + + // Check that the button alignment is still centered + expect(tester.getBottomLeft(button).dy, equals(550.0)); + expect(tester.getCenter(button).dx, equals(400.0)); + }); + + testWidgets('child has no size and precedingScrollExtent > viewportMainAxisExtent', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + final List<Widget> slivers = <Widget>[ + SliverFixedExtentList( + itemExtent: 150, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return Semantics(label: index.toString(), child: Container(color: Colors.amber)); + }, + childCount: 5, + ), + ), + SliverFillRemaining( + hasScrollBody: false, + fillOverscroll: true, + child: Container( + key: key, + color: Colors.blue, + ), + ), + ]; + + await tester.pumpWidget(boilerplate(slivers, controller: controller)); + + expect(find.byKey(key), findsNothing); + expect( + find.bySemanticsLabel('4'), + findsNothing, + ); + + // Scroll to bottom + controller.jumpTo(controller.position.maxScrollExtent); + await tester.pump(); + + // End of list + expect(find.byKey(key), findsNothing); + expect( + find.bySemanticsLabel('4'), + findsOneWidget, + ); + + // Overscroll + await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0)); + await tester.pump(); + + expect(find.byKey(key), findsNothing); + expect( + find.bySemanticsLabel('4'), + findsOneWidget, + ); + }); + }); + }); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_fill_viewport_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_fill_viewport_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..a08d235a979ef3b1d0ac78ba33f969047ffeaab4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_fill_viewport_test.dart @@ -0,0 +1,205 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('SliverFillViewport control test', (WidgetTester tester) async { + final List<Widget> children = List<Widget>.generate(20, (int i) { + return ColoredBox(color: Colors.green, child: Text('$i', textDirection: TextDirection.ltr)); + }); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: CustomScrollView( + slivers: <Widget>[ + SliverFillViewport( + delegate: SliverChildListDelegate(children, addAutomaticKeepAlives: false, addSemanticIndexes: false), + ), + ], + ), + ), + ); + + final RenderBox box = tester.renderObject<RenderBox>(find.byType(ColoredBox).first); + expect(box.size.height, equals(600.0)); + + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + expect(find.text('2'), findsNothing); + + await tester.drag(find.byType(Scrollable), const Offset(0.0, -700.0)); + await tester.pump(); + + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + expect(find.text('2'), findsOneWidget); + expect(find.text('3'), findsNothing); + expect(find.text('4'), findsNothing); + + await tester.drag(find.byType(Scrollable), const Offset(0.0, 200.0)); + await tester.pump(); + + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsOneWidget); + expect(find.text('2'), findsNothing); + expect(find.text('3'), findsNothing); + + await tester.drag(find.byType(Scrollable), const Offset(0.0, 700.0)); + await tester.pump(); + + final RenderBox box2 = tester.renderObject<RenderBox>(find.byType(ColoredBox).first); + expect(box2.size.height, equals(600.0)); + + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + expect(find.text('2'), findsNothing); + expect(find.text('3'), findsNothing); + + final RenderObject viewport = tester.renderObject<RenderObject>(find.byType(SliverFillViewport).first); + expect(viewport, hasAGoodToStringDeep); + expect( + viewport.toStringDeep(minLevel: DiagnosticLevel.info), + equalsIgnoringHashCodes( + '_RenderSliverFractionalPadding#00000 relayoutBoundary=up1\n' + ' │ needs compositing\n' + ' │ parentData: paintOffset=Offset(0.0, 0.0) (can use size)\n' + ' │ constraints: SliverConstraints(AxisDirection.down,\n' + ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' + ' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' + ' │ crossAxisDirection: AxisDirection.right,\n' + ' │ viewportMainAxisExtent: 600.0, remainingCacheExtent: 850.0,\n' + ' │ cacheOrigin: 0.0)\n' + ' │ geometry: SliverGeometry(scrollExtent: 12000.0, paintExtent:\n' + ' │ 600.0, maxPaintExtent: 12000.0, hasVisualOverflow: true,\n' + ' │ cacheExtent: 850.0)\n' + ' │\n' + ' └─child: RenderSliverFillViewport#00000 relayoutBoundary=up2\n' + ' │ needs compositing\n' + ' │ parentData: paintOffset=Offset(0.0, 0.0) (can use size)\n' + ' │ constraints: SliverConstraints(AxisDirection.down,\n' + ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' + ' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' + ' │ crossAxisDirection: AxisDirection.right,\n' + ' │ viewportMainAxisExtent: 600.0, remainingCacheExtent: 850.0,\n' + ' │ cacheOrigin: 0.0)\n' + ' │ geometry: SliverGeometry(scrollExtent: 12000.0, paintExtent:\n' + ' │ 600.0, maxPaintExtent: 12000.0, hasVisualOverflow: true,\n' + ' │ cacheExtent: 850.0)\n' + ' │ currently live children: 0 to 1\n' + ' │\n' + ' ├─child with index 0: RenderRepaintBoundary#00000\n' + ' │ │ needs compositing\n' + ' │ │ parentData: index=0; layoutOffset=0.0\n' + ' │ │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ │ layer: OffsetLayer#00000\n' + ' │ │ size: Size(800.0, 600.0)\n' + ' │ │ metrics: 66.7% useful (1 bad vs 2 good)\n' + ' │ │ diagnosis: insufficient data to draw conclusion (less than five\n' + ' │ │ repaints)\n' + ' │ │\n' + ' │ └─child: _RenderColoredBox#00000\n' + ' │ │ parentData: <none> (can use size)\n' + ' │ │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ │ size: Size(800.0, 600.0)\n' + ' │ │ behavior: opaque\n' + ' │ │\n' + ' │ └─child: RenderParagraph#00000\n' + ' │ │ parentData: <none> (can use size)\n' + ' │ │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ │ semantics node: SemanticsNode#2\n' + ' │ │ size: Size(800.0, 600.0)\n' + ' │ │ textAlign: start\n' + ' │ │ textDirection: ltr\n' + ' │ │ softWrap: wrapping at box width\n' + ' │ │ overflow: clip\n' + ' │ │ maxLines: unlimited\n' + ' │ ╘═╦══ text ═══\n' + ' │ ║ TextSpan:\n' + ' │ ║ <all styles inherited>\n' + ' │ ║ "0"\n' + ' │ ╚═══════════\n' + ' └─child with index 1: RenderRepaintBoundary#00000\n' + ' │ needs compositing\n' + ' │ parentData: index=1; layoutOffset=600.0\n' + ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ layer: OffsetLayer#00000 DETACHED\n' + ' │ size: Size(800.0, 600.0)\n' + ' │ metrics: 50.0% useful (1 bad vs 1 good)\n' + ' │ diagnosis: insufficient data to draw conclusion (less than five\n' + ' │ repaints)\n' + ' │\n' + ' └─child: _RenderColoredBox#00000\n' + ' │ parentData: <none> (can use size)\n' + ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ size: Size(800.0, 600.0)\n' + ' │ behavior: opaque\n' + ' │\n' + ' └─child: RenderParagraph#00000\n' + ' │ parentData: <none> (can use size)\n' + ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ semantics node: SemanticsNode#3\n' + ' │ size: Size(800.0, 600.0)\n' + ' │ textAlign: start\n' + ' │ textDirection: ltr\n' + ' │ softWrap: wrapping at box width\n' + ' │ overflow: clip\n' + ' │ maxLines: unlimited\n' + ' ╘═╦══ text ═══\n' + ' ║ TextSpan:\n' + ' ║ <all styles inherited>\n' + ' ║ "1"\n' + ' ╚═══════════\n', + ), + ); + }); + + testWidgets('SliverFillViewport padding test', (WidgetTester tester) async { + final SliverChildListDelegate delegate = SliverChildListDelegate( + <Widget>[ + const Text('0'), + ], + addAutomaticKeepAlives: false, + addSemanticIndexes: false, + ); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: CustomScrollView( + slivers: <Widget>[ + SliverFillViewport( + viewportFraction: 0.5, + delegate: delegate, + ), + ], + ), + ), + ); + + final RenderSliver boxWithPadding = tester.renderObject<RenderSliver>(find.byType(SliverFillViewport)); + expect(boxWithPadding.geometry!.paintExtent, equals(600.0)); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: CustomScrollView( + slivers: <Widget>[ + SliverFillViewport( + padEnds: false, + viewportFraction: 0.5, + delegate: delegate, + ), + ], + ), + ), + ); + + final RenderSliver boxWithoutPadding = tester.renderObject<RenderSliver>(find.byType(SliverFillViewport)); + expect(boxWithoutPadding.geometry!.paintExtent, equals(300.0)); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_list_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_list_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..7f377fbcc94606e550d1c86e8476f9fe091ba526 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_list_test.dart @@ -0,0 +1,414 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('SliverList reverse children (with keys)', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + const double itemHeight = 300.0; + const double viewportHeight = 500.0; + + const double scrollPosition = 18 * itemHeight; + final ScrollController controller = ScrollController(initialScrollOffset: scrollPosition); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverList( + items: items, + controller: controller, + itemHeight: itemHeight, + viewportHeight: viewportHeight, + )); + await tester.pumpAndSettle(); + + expect(controller.offset, scrollPosition); + expect(find.text('Tile 0'), findsNothing); + expect(find.text('Tile 1'), findsNothing); + expect(find.text('Tile 18'), findsOneWidget); + expect(find.text('Tile 19'), findsOneWidget); + + await tester.pumpWidget(_buildSliverList( + items: items.reversed.toList(), + controller: controller, + itemHeight: itemHeight, + viewportHeight: viewportHeight, + )); + final int frames = await tester.pumpAndSettle(); + expect(frames, 1); // ensures that there is no (animated) bouncing of the scrollable + + expect(controller.offset, scrollPosition); + expect(find.text('Tile 19'), findsNothing); + expect(find.text('Tile 18'), findsNothing); + expect(find.text('Tile 1'), findsOneWidget); + expect(find.text('Tile 0'), findsOneWidget); + + controller.jumpTo(0.0); + await tester.pumpAndSettle(); + + expect(controller.offset, 0.0); + expect(find.text('Tile 19'), findsOneWidget); + expect(find.text('Tile 18'), findsOneWidget); + expect(find.text('Tile 1'), findsNothing); + expect(find.text('Tile 0'), findsNothing); + }); + + testWidgets('SliverList replace children (with keys)', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + const double itemHeight = 300.0; + const double viewportHeight = 500.0; + + const double scrollPosition = 18 * itemHeight; + final ScrollController controller = ScrollController(initialScrollOffset: scrollPosition); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverList( + items: items, + controller: controller, + itemHeight: itemHeight, + viewportHeight: viewportHeight, + )); + await tester.pumpAndSettle(); + + expect(controller.offset, scrollPosition); + expect(find.text('Tile 0'), findsNothing); + expect(find.text('Tile 1'), findsNothing); + expect(find.text('Tile 18'), findsOneWidget); + expect(find.text('Tile 19'), findsOneWidget); + + await tester.pumpWidget(_buildSliverList( + items: items.map<int>((int i) => i + 100).toList(), + controller: controller, + itemHeight: itemHeight, + viewportHeight: viewportHeight, + )); + final int frames = await tester.pumpAndSettle(); + expect(frames, 1); // ensures that there is no (animated) bouncing of the scrollable + + expect(controller.offset, scrollPosition); + expect(find.text('Tile 0'), findsNothing); + expect(find.text('Tile 1'), findsNothing); + expect(find.text('Tile 18'), findsNothing); + expect(find.text('Tile 19'), findsNothing); + + expect(find.text('Tile 100'), findsNothing); + expect(find.text('Tile 101'), findsNothing); + expect(find.text('Tile 118'), findsOneWidget); + expect(find.text('Tile 119'), findsOneWidget); + + controller.jumpTo(0.0); + await tester.pumpAndSettle(); + + expect(controller.offset, 0.0); + expect(find.text('Tile 100'), findsOneWidget); + expect(find.text('Tile 101'), findsOneWidget); + expect(find.text('Tile 118'), findsNothing); + expect(find.text('Tile 119'), findsNothing); + }); + + testWidgets('SliverList replace with shorter children list (with keys)', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + const double itemHeight = 300.0; + const double viewportHeight = 500.0; + + final double scrollPosition = items.length * itemHeight - viewportHeight; + final ScrollController controller = ScrollController(initialScrollOffset: scrollPosition); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverList( + items: items, + controller: controller, + itemHeight: itemHeight, + viewportHeight: viewportHeight, + )); + await tester.pumpAndSettle(); + + expect(controller.offset, scrollPosition); + expect(find.text('Tile 0'), findsNothing); + expect(find.text('Tile 1'), findsNothing); + expect(find.text('Tile 17'), findsNothing); + expect(find.text('Tile 18'), findsOneWidget); + expect(find.text('Tile 19'), findsOneWidget); + + await tester.pumpWidget(_buildSliverList( + items: items.sublist(0, items.length - 1), + controller: controller, + itemHeight: itemHeight, + viewportHeight: viewportHeight, + )); + final int frames = await tester.pumpAndSettle(); + expect(frames, 1); // No animation when content shrinks suddenly. + + expect(controller.offset, scrollPosition - itemHeight); + expect(find.text('Tile 0'), findsNothing); + expect(find.text('Tile 1'), findsNothing); + expect(find.text('Tile 17'), findsOneWidget); + expect(find.text('Tile 18'), findsOneWidget); + expect(find.text('Tile 19'), findsNothing); + }); + + testWidgets('SliverList should layout first child in case of child reordering', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/35904. + List<String> items = <String>['1', '2']; + final ScrollController controller1 = ScrollController(); + addTearDown(controller1.dispose); + await tester.pumpWidget(_buildSliverListRenderWidgetChild(items, controller1)); + await tester.pumpAndSettle(); + + expect(find.text('Tile 1'), findsOneWidget); + expect(find.text('Tile 2'), findsOneWidget); + + items = items.reversed.toList(); + final ScrollController controller2 = ScrollController(); + addTearDown(controller2.dispose); + await tester.pumpWidget(_buildSliverListRenderWidgetChild(items, controller2)); + await tester.pumpAndSettle(); + + expect(find.text('Tile 1'), findsOneWidget); + expect(find.text('Tile 2'), findsOneWidget); + }); + + testWidgets('SliverList should recalculate inaccurate layout offset case 1', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/42142. + final List<int> items = List<int>.generate(20, (int i) => i); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + _buildSliverList( + items: List<int>.from(items), + controller: controller, + itemHeight: 50, + viewportHeight: 200, + ), + ); + await tester.pumpAndSettle(); + + await tester.drag(find.text('Tile 2'), const Offset(0.0, -1000.0)); + await tester.pumpAndSettle(); + + // Viewport should be scrolled to the end of list. + expect(controller.offset, 800.0); + expect(find.text('Tile 15'), findsNothing); + expect(find.text('Tile 16'), findsOneWidget); + expect(find.text('Tile 17'), findsOneWidget); + expect(find.text('Tile 18'), findsOneWidget); + expect(find.text('Tile 19'), findsOneWidget); + + // Prepends item to the list. + items.insert(0, -1); + await tester.pumpWidget( + _buildSliverList( + items: List<int>.from(items), + controller: controller, + itemHeight: 50, + viewportHeight: 200, + ), + ); + await tester.pump(); + // We need second pump to ensure the scheduled animation gets run. + await tester.pumpAndSettle(); + // Scroll offset should stay the same, and the items in viewport should be + // shifted by one. + expect(controller.offset, 800.0); + expect(find.text('Tile 14'), findsNothing); + expect(find.text('Tile 15'), findsOneWidget); + expect(find.text('Tile 16'), findsOneWidget); + expect(find.text('Tile 17'), findsOneWidget); + expect(find.text('Tile 18'), findsOneWidget); + expect(find.text('Tile 19'), findsNothing); + + // Drags back to beginning and newly added item is visible. + await tester.drag(find.text('Tile 16'), const Offset(0.0, 1000.0)); + await tester.pumpAndSettle(); + expect(controller.offset, 0.0); + expect(find.text('Tile -1'), findsOneWidget); + expect(find.text('Tile 0'), findsOneWidget); + expect(find.text('Tile 1'), findsOneWidget); + expect(find.text('Tile 2'), findsOneWidget); + expect(find.text('Tile 3'), findsNothing); + + }); + + testWidgets('SliverList should recalculate inaccurate layout offset case 2', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/42142. + final List<int> items = List<int>.generate(20, (int i) => i); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + _buildSliverList( + items: List<int>.from(items), + controller: controller, + itemHeight: 50, + viewportHeight: 200, + ), + ); + await tester.pumpAndSettle(); + + await tester.drag(find.text('Tile 2'), const Offset(0.0, -1000.0)); + await tester.pumpAndSettle(); + + // Viewport should be scrolled to the end of list. + expect(controller.offset, 800.0); + expect(find.text('Tile 15'), findsNothing); + expect(find.text('Tile 16'), findsOneWidget); + expect(find.text('Tile 17'), findsOneWidget); + expect(find.text('Tile 18'), findsOneWidget); + expect(find.text('Tile 19'), findsOneWidget); + + // Reorders item to the front. This should make item 19 to be first child + // with layout offset = null. + final int swap = items[19]; + items[19] = items[3]; + items[3] = swap; + + await tester.pumpWidget( + _buildSliverList( + items: List<int>.from(items), + controller: controller, + itemHeight: 50, + viewportHeight: 200, + ), + ); + await tester.pump(); + // We need second pump to ensure the scheduled animation gets run. + await tester.pumpAndSettle(); + // Scroll offset should stay the same + expect(controller.offset, 800.0); + expect(find.text('Tile 14'), findsNothing); + expect(find.text('Tile 15'), findsNothing); + expect(find.text('Tile 16'), findsOneWidget); + expect(find.text('Tile 17'), findsOneWidget); + expect(find.text('Tile 18'), findsOneWidget); + expect(find.text('Tile 3'), findsOneWidget); + }); + + testWidgets('SliverList should start to perform layout from the initial child when there is no valid offset', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/66198. + bool isShow = true; + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + Widget buildSliverList(ScrollController controller) { + return Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + height: 200, + child: ListView( + controller: controller, + children: <Widget>[ + if (isShow) + for (int i = 0; i < 20; i++) + SizedBox( + height: 50, + child: Text('Tile $i'), + ), + const SizedBox(), // Use this widget to occupy the position where the offset is 0 when rebuild + const SizedBox(key: Key('key0'), height: 50.0), + const SizedBox(key: Key('key1'), height: 50.0), + ], + ), + ), + ), + ); + } + + await tester.pumpWidget(buildSliverList(controller)); + await tester.pumpAndSettle(); + + // Scrolling to the bottom. + await tester.drag(find.text('Tile 2'), const Offset(0.0, -1000.0)); + await tester.pumpAndSettle(); + + // Viewport should be scrolled to the end of list. + expect(controller.offset, 900.0); + expect(find.text('Tile 17'), findsNothing); + expect(find.text('Tile 18'), findsOneWidget); + expect(find.text('Tile 19'), findsOneWidget); + expect(find.byKey(const Key('key0')), findsOneWidget); + expect(find.byKey(const Key('key1')), findsOneWidget); + + // Trigger rebuild. + isShow = false; + await tester.pumpWidget(buildSliverList(controller)); + + // After rebuild, [ContainerRenderObjectMixin] has two children, and + // neither of them has a valid layout offset. + // SliverList can layout normally without any assert or dead loop. + // Only the 'SizeBox' show in the viewport. + expect(controller.offset, 0.0); + expect(find.text('Tile 0'), findsNothing); + expect(find.text('Tile 19'), findsNothing); + expect(find.byKey(const Key('key0')), findsOneWidget); + expect(find.byKey(const Key('key1')), findsOneWidget); + }); +} + +Widget _buildSliverListRenderWidgetChild(List<String> items, ScrollController controller) { + return MaterialApp( + home: Directionality( + textDirection: TextDirection.ltr, + child: Material( + child: SizedBox( + height: 500, + child: CustomScrollView( + controller: controller, + slivers: <Widget>[ + SliverList( + delegate: SliverChildListDelegate( + items.map<Widget>((String item) { + return Chip( + key: Key(item), + label: Text('Tile $item'), + ); + }).toList(), + ), + ), + ], + ), + ), + ), + ), + ); +} + +Widget _buildSliverList({ + List<int> items = const <int>[], + ScrollController? controller, + double itemHeight = 500.0, + double viewportHeight = 300.0, +}) { + return Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + height: viewportHeight, + child: CustomScrollView( + controller: controller, + slivers: <Widget>[ + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int i) { + return SizedBox( + key: ValueKey<int>(items[i]), + height: itemHeight, + child: Text('Tile ${items[i]}'), + ); + }, + findChildIndexCallback: (Key key) { + final ValueKey<int> valueKey = key as ValueKey<int>; + final int index = items.indexOf(valueKey.value); + return index == -1 ? null : index; + }, + childCount: items.length, + ), + ), + ], + ), + ), + ), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_main_axis_group_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_main_axis_group_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..b0cf025e260e1865dc0e78cb95df0ab934d93995 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_main_axis_group_test.dart @@ -0,0 +1,772 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../rendering/sliver_utils.dart'; + + +const double VIEWPORT_HEIGHT = 600; +const double VIEWPORT_WIDTH = 300; + +void main() { + testWidgets('SliverMainAxisGroup is laid out properly', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + _buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + _buildSliverList(itemMainAxisExtent: 300, items: items, label: (int item) => Text('Group 0 Tile $item')), + _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 1 Tile $item')), + ], + ), + ); + await tester.pumpAndSettle(); + + expect(controller.offset, 0); + + expect(find.text('Group 0 Tile 0'), findsOneWidget); + expect(find.text('Group 0 Tile 1'), findsOneWidget); + expect(find.text('Group 0 Tile 2'), findsNothing); + + expect(find.text('Group 1 Tile 0'), findsNothing); + + const double scrollOffset = 19 * 300.0; + controller.jumpTo(scrollOffset); + await tester.pumpAndSettle(); + + expect(controller.offset, scrollOffset); + expect(find.text('Group 0 Tile 18'), findsNothing); + expect(find.text('Group 0 Tile 19'), findsOneWidget); + expect(find.text('Group 1 Tile 0'), findsOneWidget); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + + expect(first.geometry!.layoutExtent, equals(300.0)); + expect(second.geometry!.layoutExtent, equals(300.0)); + expect(first.geometry!.scrollExtent, equals(20 * 300.0)); + expect(second.geometry!.scrollExtent, equals(20 * 200.0)); + + expect((first.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + expect(first.constraints.scrollOffset, equals(19 * 300.0)); + expect((second.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(1 * 300.0)); + + final RenderSliverMainAxisGroup renderGroup = + tester.renderObject<RenderSliverMainAxisGroup>(find.byType(SliverMainAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20 + 200 * 20)); + expect(renderGroup.geometry!.hasVisualOverflow, isTrue); + }); + + testWidgets('SliverMainAxisGroup is laid out properly when reversed', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + _buildSliverMainAxisGroup( + controller: controller, + reverse: true, + slivers: <Widget>[ + _buildSliverList(itemMainAxisExtent: 300, items: items, label: (int item) => Text('Group 0 Tile $item')), + _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 1 Tile $item')), + ], + ), + ); + await tester.pumpAndSettle(); + + expect(controller.offset, 0); + + expect(find.text('Group 0 Tile 0'), findsOneWidget); + expect(find.text('Group 0 Tile 1'), findsOneWidget); + expect(find.text('Group 0 Tile 2'), findsNothing); + + expect(find.text('Group 1 Tile 0'), findsNothing); + + const double scrollOffset = 19 * 300.0; + controller.jumpTo(scrollOffset); + await tester.pumpAndSettle(); + + expect(controller.offset, scrollOffset); + expect(find.text('Group 0 Tile 18'), findsNothing); + expect(find.text('Group 0 Tile 19'), findsOneWidget); + expect(find.text('Group 1 Tile 0'), findsOneWidget); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + + expect(first.geometry!.layoutExtent, equals(300.0)); + expect(second.geometry!.layoutExtent, equals(300.0)); + expect(first.geometry!.scrollExtent, equals(20 * 300.0)); + expect(second.geometry!.scrollExtent, equals(20 * 200.0)); + + expect((first.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + expect(first.constraints.scrollOffset, equals(19 * 300.0)); + expect((second.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(1 * 300.0)); + + final RenderSliverMainAxisGroup renderGroup = + tester.renderObject<RenderSliverMainAxisGroup>(find.byType(SliverMainAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20 + 200 * 20)); + expect(renderGroup.geometry!.hasVisualOverflow, isTrue); + }); + + testWidgets('SliverMainAxisGroup is laid out properly when horizontal', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + _buildSliverMainAxisGroup( + controller: controller, + scrollDirection: Axis.horizontal, + slivers: <Widget>[ + _buildSliverList(itemMainAxisExtent: 300, items: items, label: (int item) => Text('Group 0 Tile $item'), scrollDirection: Axis.horizontal), + _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 1 Tile $item'), scrollDirection: Axis.horizontal), + ], + ), + ); + await tester.pumpAndSettle(); + + expect(controller.offset, 0); + + expect(find.text('Group 0 Tile 0'), findsOneWidget); + expect(find.text('Group 0 Tile 1'), findsNothing); + + expect(find.text('Group 1 Tile 0'), findsNothing); + + const double scrollOffset = 19 * 300.0; + controller.jumpTo(scrollOffset); + await tester.pumpAndSettle(); + + expect(controller.offset, scrollOffset); + expect(find.text('Group 0 Tile 18'), findsNothing); + expect(find.text('Group 0 Tile 19'), findsOneWidget); + expect(find.text('Group 1 Tile 0'), findsNothing); + + const double scrollOffset2 = 20 * 300.0; + controller.jumpTo(scrollOffset2); + await tester.pumpAndSettle(); + expect(find.text('Group 0 Tile 19'), findsNothing); + expect(find.text('Group 1 Tile 0'), findsOneWidget); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + + expect(first.geometry!.layoutExtent, equals(0.0)); + expect(second.geometry!.layoutExtent, equals(300.0)); + expect(first.geometry!.scrollExtent, equals(20 * 300.0)); + expect(second.geometry!.scrollExtent, equals(20 * 200.0)); + + expect((first.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + expect(first.constraints.scrollOffset, equals(20 * 300.0)); + expect((second.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + + final RenderSliverMainAxisGroup renderGroup = + tester.renderObject<RenderSliverMainAxisGroup>(find.byType(SliverMainAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20 + 200 * 20)); + expect(renderGroup.geometry!.hasVisualOverflow, isTrue); + }); + + testWidgets('SliverMainAxisGroup is laid out properly when horizontal, reversed', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + _buildSliverMainAxisGroup( + controller: controller, + scrollDirection: Axis.horizontal, + reverse: true, + slivers: <Widget>[ + _buildSliverList(itemMainAxisExtent: 300, items: items, label: (int item) => Text('Group 0 Tile $item'), scrollDirection: Axis.horizontal), + _buildSliverList(itemMainAxisExtent: 200, items: items, label: (int item) => Text('Group 1 Tile $item'), scrollDirection: Axis.horizontal), + ], + ), + ); + await tester.pumpAndSettle(); + + expect(controller.offset, 0); + + expect(find.text('Group 0 Tile 0'), findsOneWidget); + expect(find.text('Group 0 Tile 1'), findsNothing); + + expect(find.text('Group 1 Tile 0'), findsNothing); + + const double scrollOffset = 19 * 300.0; + controller.jumpTo(scrollOffset); + await tester.pumpAndSettle(); + + expect(controller.offset, scrollOffset); + expect(find.text('Group 0 Tile 18'), findsNothing); + expect(find.text('Group 0 Tile 19'), findsOneWidget); + expect(find.text('Group 1 Tile 0'), findsNothing); + + const double scrollOffset2 = 20 * 300.0; + controller.jumpTo(scrollOffset2); + await tester.pumpAndSettle(); + expect(find.text('Group 0 Tile 19'), findsNothing); + expect(find.text('Group 1 Tile 0'), findsOneWidget); + + final List<RenderSliverList> renderSlivers = tester.renderObjectList<RenderSliverList>(find.byType(SliverList)).toList(); + final RenderSliverList first = renderSlivers[0]; + final RenderSliverList second = renderSlivers[1]; + + expect(first.geometry!.layoutExtent, equals(0.0)); + expect(second.geometry!.layoutExtent, equals(300.0)); + expect(first.geometry!.scrollExtent, equals(20 * 300.0)); + expect(second.geometry!.scrollExtent, equals(20 * 200.0)); + + expect((first.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + expect(first.constraints.scrollOffset, equals(20 * 300.0)); + expect((second.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + + final RenderSliverMainAxisGroup renderGroup = + tester.renderObject<RenderSliverMainAxisGroup>(find.byType(SliverMainAxisGroup)); + expect(renderGroup.geometry!.scrollExtent, equals(300 * 20 + 200 * 20)); + expect(renderGroup.geometry!.hasVisualOverflow, isTrue); + }); + + testWidgets('Hit test works properly on various parts of SliverMainAxisGroup', (WidgetTester tester) async { + final List<int> items = List<int>.generate(20, (int i) => i); + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + String? clickedTile; + + int group = 0; + int tile = 0; + + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + _buildSliverList( + itemMainAxisExtent: 300, + items: items, + label: (int item) => tile == item && group == 0 + ? TextButton( + onPressed: () => clickedTile = 'Group 0 Tile $item', + child: Text('Group 0 Tile $item'), + ) + : Text('Group 0 Tile $item'), + ), + _buildSliverList( + items: items, + label: (int item) => tile == item && group == 1 + ? TextButton( + onPressed: () => clickedTile = 'Group 1 Tile $item', + child: Text('Group 1 Tile $item'), + ) + : Text('Group 1 Tile $item'), + ), + ]), + ); + await tester.pumpAndSettle(); + await tester.tap(find.byType(TextButton)); + await tester.pumpAndSettle(); + expect(clickedTile, equals('Group 0 Tile 0')); + + clickedTile = null; + group = 1; + tile = 2; + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + _buildSliverList( + itemMainAxisExtent: 300, + items: items, + label: (int item) => tile == item && group == 0 + ? TextButton( + onPressed: () => clickedTile = 'Group 0 Tile $item', + child: Text('Group 0 Tile $item'), + ) + : Text('Group 0 Tile $item'), + ), + _buildSliverList( + items: items, + label: (int item) => tile == item && group == 1 + ? TextButton( + onPressed: () => clickedTile = 'Group 1 Tile $item', + child: Text('Group 1 Tile $item'), + ) + : Text('Group 1 Tile $item'), + ), + ]), + ); + controller.jumpTo(300.0 * 20); + await tester.pumpAndSettle(); + await tester.tap(find.byType(TextButton)); + await tester.pumpAndSettle(); + expect(clickedTile, equals('Group 1 Tile 2')); + }); + + testWidgets('applyPaintTransform is implemented properly', (WidgetTester tester) async { + await tester.pumpWidget(_buildSliverMainAxisGroup( + slivers: <Widget>[ + const SliverToBoxAdapter(child: Text('first box')), + const SliverToBoxAdapter(child: Text('second box')), + ]), + ); + await tester.pumpAndSettle(); + + // localToGlobal calculates offset via applyPaintTransform + final RenderBox first = tester.renderObject(find.text('first box')) as RenderBox; + final RenderBox second = tester.renderObject(find.text('second box')); + expect(first.localToGlobal(Offset.zero), Offset.zero); + expect(second.localToGlobal(Offset.zero), Offset(0, first.size.height)); + }); + + testWidgets('visitChildrenForSemantics visits children in the correct order', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: const <Widget>[ + SliverToBoxAdapter(child: SizedBox(height: 200)), + SliverToBoxAdapter(child: SizedBox(height: 300)), + SliverToBoxAdapter(child: SizedBox(height: 500)), + SliverToBoxAdapter(child: SizedBox(height: 400)), + ]), + ); + controller.jumpTo(300); + await tester.pumpAndSettle(); + + final List<RenderSliver> visitedChildren = <RenderSliver>[]; + final RenderSliverMainAxisGroup renderGroup = tester.renderObject<RenderSliverMainAxisGroup>(find.byType(SliverMainAxisGroup)); + void visitor(RenderObject child) { + visitedChildren.add(child as RenderSliver); + } + renderGroup.visitChildrenForSemantics(visitor); + expect(visitedChildren.length, equals(2)); + expect(visitedChildren[0].geometry!.scrollExtent, equals(300)); + expect(visitedChildren[1].geometry!.scrollExtent, equals(500)); + }); + + testWidgets('SliverPinnedPersistentHeader is painted within bounds of SliverMainAxisGroup', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + SliverPersistentHeader( + delegate: TestDelegate(), + pinned: true, + ), + const SliverToBoxAdapter(child: SizedBox(height: 600)), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + final RenderSliverMainAxisGroup renderGroup = tester.renderObject(find.byType(SliverMainAxisGroup)) as RenderSliverMainAxisGroup; + // Scroll extent is the total of the box sliver and the sliver persistent header. + expect(renderGroup.geometry!.scrollExtent, equals(600.0 + 60.0)); + controller.jumpTo(620); + await tester.pumpAndSettle(); + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + // Paint extent after header's layout is 60.0, so we must offset by -20.0 to fit within the 40.0 remaining extent. + expect(renderHeader.geometry!.paintExtent, equals(60.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-20.0)); + }); + + + testWidgets('SliverFloatingPersistentHeader is painted within bounds of SliverMainAxisGroup', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + SliverPersistentHeader( + delegate: TestDelegate(), + floating: true, + ), + const SliverToBoxAdapter(child: SizedBox(height: 600)), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverMainAxisGroup renderGroup = tester.renderObject(find.byType(SliverMainAxisGroup)) as RenderSliverMainAxisGroup; + expect(renderGroup.geometry!.scrollExtent, equals(660)); + controller.jumpTo(660.0); + await tester.pumpAndSettle(); + final TestGesture gesture = await tester.startGesture(const Offset(150.0, 300.0)); + await gesture.moveBy(const Offset(0.0, 40)); + await tester.pump(); + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + // Paint extent after header's layout is 40.0, so no need to correct the paintOffset. + expect(renderHeader.geometry!.paintExtent, equals(40.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + }); + + testWidgets('SliverPinnedPersistentHeader is painted within bounds of SliverMainAxisGroup with different minExtent/maxExtent', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + SliverPersistentHeader( + delegate: TestDelegate(minExtent: 40.0), + pinned: true, + ), + const SliverToBoxAdapter(child: SizedBox(height: 600)), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + final RenderSliverMainAxisGroup renderGroup = tester.renderObject(find.byType(SliverMainAxisGroup)) as RenderSliverMainAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(660)); + controller.jumpTo(630); + await tester.pumpAndSettle(); + // Paint extent of the header is 40.0, so we must provide an offset of -10.0 to make it fit in the 30.0 remaining paint extent of the group. + expect(renderHeader.geometry!.paintExtent, equals(40.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-10.0)); + controller.jumpTo(610); + await tester.pumpAndSettle(); + expect(renderHeader.geometry!.paintExtent, equals(40.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + }); + + testWidgets('SliverFloatingPersistentHeader is painted within bounds of SliverMainAxisGroup with different minExtent/maxExtent', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + SliverPersistentHeader( + delegate: TestDelegate(minExtent: 40.0), + floating: true, + ), + const SliverToBoxAdapter(child: SizedBox(height: 600)), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverMainAxisGroup renderGroup = tester.renderObject(find.byType(SliverMainAxisGroup)) as RenderSliverMainAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(660)); + + controller.jumpTo(660); + await tester.pumpAndSettle(); + + final TestGesture gesture = await tester.startGesture(const Offset(150.0, 300.0)); + await gesture.moveBy(const Offset(0.0, 30.0)); + await tester.pump(); + // Paint extent after header's layout is 30.0, so no need to correct the paintOffset. + expect(renderHeader.geometry!.paintExtent, equals(30.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + // Floating headers should expand to maximum extent as we continue scrolling. + await gesture.moveBy(const Offset(0.0, 20.0)); + await tester.pump(); + expect(renderHeader.geometry!.paintExtent, equals(50.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + }); + + testWidgets('SliverPinnedFloatingPersistentHeader is painted within bounds of SliverMainAxisGroup with different minExtent/maxExtent', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + SliverPersistentHeader( + delegate: TestDelegate(minExtent: 40.0), + pinned: true, + floating: true, + ), + const SliverToBoxAdapter(child: SizedBox(height: 600)), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverMainAxisGroup renderGroup = tester.renderObject(find.byType(SliverMainAxisGroup)) as RenderSliverMainAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(660)); + + controller.jumpTo(660); + await tester.pumpAndSettle(); + + final TestGesture gesture = await tester.startGesture(const Offset(150.0, 300.0)); + await gesture.moveBy(const Offset(0.0, 30.0)); + await tester.pump(); + // Paint extent after header's layout is 40.0, so we need to adjust by -10.0. + expect(renderHeader.geometry!.paintExtent, equals(40.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-10.0)); + // Pinned floating headers should expand to maximum extent as we continue scrolling. + await gesture.moveBy(const Offset(0.0, 20.0)); + await tester.pump(); + expect(renderHeader.geometry!.paintExtent, equals(50.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + }); + + testWidgets('SliverAppBar with floating: false, pinned: false, snap: false is painted within bounds of SliverMainAxisGroup', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverAppBar( + toolbarHeight: 30, + expandedHeight: 60, + ), + const SliverToBoxAdapter(child: SizedBox(height: 600)), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverMainAxisGroup renderGroup = tester.renderObject(find.byType(SliverMainAxisGroup)) as RenderSliverMainAxisGroup; + expect(renderGroup.geometry!.scrollExtent, equals(660)); + + controller.jumpTo(660); + await tester.pumpAndSettle(); + controller.jumpTo(630); + await tester.pumpAndSettle(); + + // At a scroll offset of 630, a normal scrolling header should be out of view. + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderHeader.constraints.scrollOffset, equals(630)); + expect(renderHeader.geometry!.layoutExtent, equals(0.0)); + }); + + testWidgets('SliverAppBar with floating: true, pinned: false, snap: true is painted within bounds of SliverMainAxisGroup', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverAppBar( + toolbarHeight: 30, + expandedHeight: 60, + floating: true, + snap: true, + ), + const SliverToBoxAdapter(child: SizedBox(height: 600)), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverMainAxisGroup renderGroup = tester.renderObject(find.byType(SliverMainAxisGroup)) as RenderSliverMainAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(660)); + + controller.jumpTo(660); + await tester.pumpAndSettle(); + + final TestGesture gesture = await tester.startGesture(const Offset(150.0, 300.0)); + await gesture.moveBy(const Offset(0.0, 10)); + await tester.pump(); + + // The snap animation does not go through until the gesture is released. + expect(renderHeader.geometry!.paintExtent, equals(10)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(0.0)); + + // Once it is released, the header's paint extent becomes the maximum and the group sets an offset of -50.0. + await gesture.up(); + await tester.pumpAndSettle(); + expect(renderHeader.geometry!.paintExtent, equals(60)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-50.0)); + }); + + testWidgets('SliverAppBar with floating: true, pinned: true, snap: true is painted within bounds of SliverMainAxisGroup', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(_buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + const SliverAppBar( + toolbarHeight: 30, + expandedHeight: 60, + floating: true, + pinned: true, + snap: true, + ), + const SliverToBoxAdapter(child: SizedBox(height: 600)), + ], + otherSlivers: <Widget>[ + const SliverToBoxAdapter(child: SizedBox(height: 2400)), + ], + )); + await tester.pumpAndSettle(); + final RenderSliverMainAxisGroup renderGroup = tester.renderObject(find.byType(SliverMainAxisGroup)) as RenderSliverMainAxisGroup; + final RenderSliverPersistentHeader renderHeader = tester.renderObject(find.byType(SliverPersistentHeader)) as RenderSliverPersistentHeader; + expect(renderGroup.geometry!.scrollExtent, equals(660)); + + controller.jumpTo(660); + await tester.pumpAndSettle(); + + final TestGesture gesture = await tester.startGesture(const Offset(150.0, 300.0)); + await gesture.moveBy(const Offset(0.0, 10)); + await tester.pump(); + + expect(renderHeader.geometry!.paintExtent, equals(30.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-20.0)); + + // Once we lift the gesture up, the animation should finish. + await gesture.up(); + await tester.pumpAndSettle(); + expect(renderHeader.geometry!.paintExtent, equals(60.0)); + expect((renderHeader.parentData! as SliverPhysicalParentData).paintOffset.dy, equals(-50.0)); + }); + + testWidgets('SliverMainAxisGroup skips painting invisible children', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + int counter = 0; + void incrementCounter() { + counter += 1; + } + + await tester.pumpWidget( + _buildSliverMainAxisGroup( + controller: controller, + slivers: <Widget>[ + MockSliverToBoxAdapter( + incrementCounter: incrementCounter, + child: Container( + height: 1000, + decoration: const BoxDecoration(color: Colors.amber), + ), + ), + MockSliverToBoxAdapter( + incrementCounter: incrementCounter, + child: Container( + height: 400, + decoration: const BoxDecoration(color: Colors.amber) + ), + ), + MockSliverToBoxAdapter( + incrementCounter: incrementCounter, + child: Container( + height: 500, + decoration: const BoxDecoration(color: Colors.amber) + ), + ), + MockSliverToBoxAdapter( + incrementCounter: incrementCounter, + child: Container( + height: 300, + decoration: const BoxDecoration(color: Colors.amber) + ), + ), + ], + ), + ); + + // Can only see top sliver. + expect(counter, equals(1)); + + // Reset paint counter. + counter = 0; + controller.jumpTo(1000); + await tester.pumpAndSettle(); + + // Can only see second and third slivers. + expect(controller.offset, 1000); + expect(counter, equals(2)); + }); +} + +Widget _buildSliverList({ + double itemMainAxisExtent = 100, + List<int> items = const <int>[], + required Widget Function(int) label, + Axis scrollDirection = Axis.vertical, +}) { + return SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int i) { + return scrollDirection == Axis.vertical + ? SizedBox( + key: ValueKey<int>(items[i]), + height: itemMainAxisExtent, + child: label(items[i]), + ) + : SizedBox( + key: ValueKey<int>(items[i]), + width: itemMainAxisExtent, + child: label(items[i])); + }, + findChildIndexCallback: (Key key) { + final ValueKey<int> valueKey = key as ValueKey<int>; + final int index = items.indexOf(valueKey.value); + return index == -1 ? null : index; + }, + childCount: items.length, + ), + ); +} + +Widget _buildSliverMainAxisGroup({ + required List<Widget> slivers, + ScrollController? controller, + double viewportHeight = VIEWPORT_HEIGHT, + double viewportWidth = VIEWPORT_WIDTH, + Axis scrollDirection = Axis.vertical, + bool reverse = false, + List<Widget> otherSlivers = const <Widget>[], +}) { + return MaterialApp( + home: Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + height: viewportHeight, + width: viewportWidth, + child: CustomScrollView( + scrollDirection: scrollDirection, + reverse: reverse, + controller: controller, + slivers: <Widget>[SliverMainAxisGroup(slivers: slivers), ...otherSlivers], + ), + ), + ), + ), + ); +} + +class TestDelegate extends SliverPersistentHeaderDelegate { + TestDelegate({ this.maxExtent = 60.0, this.minExtent = 60.0 }); + + @override + final double maxExtent; + + @override + final double minExtent; + + @override + Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) { + return Container(height: maxExtent); + } + + @override + bool shouldRebuild(TestDelegate oldDelegate) => true; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_persistent_header_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_persistent_header_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..8fb239f7a52d5f2a481b5d779ea7540ef6443cad --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_persistent_header_test.dart @@ -0,0 +1,125 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/src/rendering/sliver_persistent_header.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets( + '_SliverScrollingPersistentHeader should update stretchConfiguration', + (WidgetTester tester) async { + for (final double stretchTriggerOffset in <double>[10.0, 20.0]) { + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + SliverPersistentHeader( + delegate: TestDelegate( + stretchConfiguration: OverScrollHeaderStretchConfiguration( + stretchTriggerOffset: stretchTriggerOffset, + ), + ), + ) + ], + ), + )); + } + + expect( + tester.allWidgets.where((Widget w) => + w.runtimeType.toString() == '_SliverScrollingPersistentHeader'), + isNotEmpty); + + final RenderSliverScrollingPersistentHeader render = tester.allRenderObjects + .whereType<RenderSliverScrollingPersistentHeader>() + .first; + expect(render.stretchConfiguration?.stretchTriggerOffset, 20); + }); + + testWidgets( + '_SliverPinnedPersistentHeader should update stretchConfiguration', + (WidgetTester tester) async { + for (final double stretchTriggerOffset in <double>[10.0, 20.0]) { + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + SliverPersistentHeader( + pinned: true, + delegate: TestDelegate( + stretchConfiguration: OverScrollHeaderStretchConfiguration( + stretchTriggerOffset: stretchTriggerOffset, + ), + ), + ) + ], + ), + )); + } + + expect( + tester.allWidgets.where((Widget w) => + w.runtimeType.toString() == '_SliverPinnedPersistentHeader'), + isNotEmpty); + + final RenderSliverPinnedPersistentHeader render = tester.allRenderObjects + .whereType<RenderSliverPinnedPersistentHeader>() + .first; + expect(render.stretchConfiguration?.stretchTriggerOffset, 20); + }); + + testWidgets( + '_SliverPinnedPersistentHeader should update showOnScreenConfiguration', + (WidgetTester tester) async { + for (final double maxShowOnScreenExtent in <double>[1000, 2000]) { + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + SliverPersistentHeader( + pinned: true, + delegate: TestDelegate( + showOnScreenConfiguration: + PersistentHeaderShowOnScreenConfiguration( + maxShowOnScreenExtent: maxShowOnScreenExtent), + ), + ) + ], + ), + )); + } + + expect( + tester.allWidgets.where((Widget w) => + w.runtimeType.toString() == '_SliverPinnedPersistentHeader'), + isNotEmpty); + + final RenderSliverPinnedPersistentHeader render = tester.allRenderObjects + .whereType<RenderSliverPinnedPersistentHeader>() + .first; + expect(render.showOnScreenConfiguration?.maxShowOnScreenExtent, 2000); + }); +} + +class TestDelegate extends SliverPersistentHeaderDelegate { + TestDelegate({this.stretchConfiguration, this.showOnScreenConfiguration}); + + @override + double get maxExtent => 200.0; + + @override + double get minExtent => 200.0; + + @override + Widget build( + BuildContext context, double shrinkOffset, bool overlapsContent) { + return Container(height: maxExtent); + } + + @override + bool shouldRebuild(TestDelegate oldDelegate) => false; + + @override + final OverScrollHeaderStretchConfiguration? stretchConfiguration; + @override + final PersistentHeaderShowOnScreenConfiguration? showOnScreenConfiguration; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_prototype_item_extent_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_prototype_item_extent_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..48b000f5eb477473937bcb7eeadedcc90376483e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_prototype_item_extent_test.dart @@ -0,0 +1,219 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class TestItem extends StatelessWidget { + const TestItem({ super.key, required this.item, this.width, this.height }); + final int item; + final double? width; + final double? height; + @override + Widget build(BuildContext context) { + return Container( + width: width, + height: height, + alignment: Alignment.center, + child: Text('Item $item', textDirection: TextDirection.ltr), + ); + } +} + +Widget buildFrame({ int? count, double? width, double? height, Axis? scrollDirection, Key? prototypeKey }) { + return Directionality( + textDirection: TextDirection.ltr, + child: CustomScrollView( + scrollDirection: scrollDirection ?? Axis.vertical, + slivers: <Widget>[ + SliverPrototypeExtentList( + prototypeItem: TestItem(item: -1, width: width, height: height, key: prototypeKey), + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => TestItem(item: index), + childCount: count, + ), + ), + ], + ), + ); +} + +void main() { + testWidgets('SliverPrototypeExtentList.builder test', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: CustomScrollView( + slivers: <Widget>[ + SliverPrototypeExtentList.builder( + itemBuilder: (BuildContext context, int index) => TestItem(item: index), + prototypeItem: const TestItem(item: -1, height: 100.0), + itemCount: 20, + ), + ], + ), + ), + ), + ); + + // The viewport is 600 pixels high, lazily created items are 100 pixels high. + for (int i = 0; i < 6; i += 1) { + final Finder item = find.widgetWithText(Container, 'Item $i'); + expect(item, findsOneWidget); + expect(tester.getTopLeft(item).dy, i * 100.0); + expect(tester.getSize(item).height, 100.0); + } + for (int i = 7; i < 20; i += 1) { + expect(find.text('Item $i'), findsNothing); + } + }); + + testWidgets('SliverPrototypeExtentList.builder test', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: CustomScrollView( + slivers: <Widget>[ + SliverPrototypeExtentList.list( + prototypeItem: const TestItem(item: -1, height: 100.0), + children: <int>[0, 1, 2, 3, 4, 5, 6, 7].map((int index) => TestItem(item: index)).toList(), + ), + ], + ), + ), + ), + ); + + // The viewport is 600 pixels high, lazily created items are 100 pixels high. + for (int i = 0; i < 6; i += 1) { + final Finder item = find.widgetWithText(Container, 'Item $i'); + expect(item, findsOneWidget); + expect(tester.getTopLeft(item).dy, i * 100.0); + expect(tester.getSize(item).height, 100.0); + } + expect(find.text('Item 7'), findsNothing); + }); + + testWidgets('SliverPrototypeExtentList vertical scrolling basics', (WidgetTester tester) async { + await tester.pumpWidget(buildFrame(count: 20, height: 100.0)); + + // The viewport is 600 pixels high, lazily created items are 100 pixels high. + for (int i = 0; i < 6; i += 1) { + final Finder item = find.widgetWithText(Container, 'Item $i'); + expect(item, findsOneWidget); + expect(tester.getTopLeft(item).dy, i * 100.0); + expect(tester.getSize(item).height, 100.0); + } + for (int i = 7; i < 20; i += 1) { + expect(find.text('Item $i'), findsNothing); + } + + // Fling scroll to the end. + await tester.fling(find.text('Item 2'), const Offset(0.0, -200.0), 5000.0); + await tester.pumpAndSettle(); + + for (int i = 19; i >= 14; i -= 1) { + expect(find.text('Item $i'), findsOneWidget); + } + for (int i = 13; i >= 0; i -= 1) { + expect(find.text('Item $i'), findsNothing); + } + }); + + testWidgets('SliverPrototypeExtentList horizontal scrolling basics', (WidgetTester tester) async { + await tester.pumpWidget(buildFrame(count: 20, width: 100.0, scrollDirection: Axis.horizontal)); + + // The viewport is 800 pixels wide, lazily created items are 100 pixels wide. + for (int i = 0; i < 8; i += 1) { + final Finder item = find.widgetWithText(Container, 'Item $i'); + expect(item, findsOneWidget); + expect(tester.getTopLeft(item).dx, i * 100.0); + expect(tester.getSize(item).width, 100.0); + } + for (int i = 9; i < 20; i += 1) { + expect(find.text('Item $i'), findsNothing); + } + + // Fling scroll to the end. + await tester.fling(find.text('Item 3'), const Offset(-200.0, 0.0), 5000.0); + await tester.pumpAndSettle(); + + for (int i = 19; i >= 12; i -= 1) { + expect(find.text('Item $i'), findsOneWidget); + } + for (int i = 11; i >= 0; i -= 1) { + expect(find.text('Item $i'), findsNothing); + } + }); + + testWidgets('SliverPrototypeExtentList change the prototype item', (WidgetTester tester) async { + await tester.pumpWidget(buildFrame(count: 10, height: 60.0)); + + // The viewport is 600 pixels high, each of the 10 items is 60 pixels high + for (int i = 0; i < 10; i += 1) { + expect(find.text('Item $i'), findsOneWidget); + } + + await tester.pumpWidget(buildFrame(count: 10, height: 120.0)); + + // Now the items are 120 pixels high, so only 5 fit. + for (int i = 0; i < 5; i += 1) { + expect(find.text('Item $i'), findsOneWidget); + } + for (int i = 5; i < 10; i += 1) { + expect(find.text('Item $i'), findsNothing); + } + + await tester.pumpWidget(buildFrame(count: 10, height: 60.0)); + + // Now they all fit again + for (int i = 0; i < 10; i += 1) { + expect(find.text('Item $i'), findsOneWidget); + } + }); + + testWidgets('SliverPrototypeExtentList first item is also the prototype', (WidgetTester tester) async { + final List<Widget> items = List<Widget>.generate(10, (int index) { + return TestItem(key: ValueKey<int>(index), item: index, height: index == 0 ? 60.0 : null); + }).toList(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: CustomScrollView( + slivers: <Widget>[ + SliverPrototypeExtentList( + prototypeItem: items[0], + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => items[index], + childCount: 10, + ), + ), + ], + ), + ), + ); + + // Item 0 exists in the list and as the prototype item. + expect(tester.widgetList(find.text('Item 0', skipOffstage: false)).length, 2); + + for (int i = 1; i < 10; i += 1) { + expect(find.text('Item $i'), findsOneWidget); + } + }); + + testWidgets('SliverPrototypeExtentList prototypeItem paint transform is zero.', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/67117 + // This test ensures that the SliverPrototypeExtentList does not cause an + // assertion error when calculating the paint transform of its prototypeItem. + // The paint transform of the prototypeItem should be zero, since it is not visible. + final GlobalKey prototypeKey = GlobalKey(); + await tester.pumpWidget(buildFrame(count: 20, height: 100.0, prototypeKey: prototypeKey)); + + final RenderObject scrollView = tester.renderObject(find.byType(CustomScrollView)); + final RenderObject prototype = prototypeKey.currentContext!.findRenderObject()!; + + expect(prototype.getTransformTo(scrollView), Matrix4.zero()); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_resizing_header_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_resizing_header_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..1fd7a08422507e15c90d3bc4c81d25057a899504 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_resizing_header_test.dart @@ -0,0 +1,352 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + + +void main() { + testWidgets('SliverResizingHeader basics', (WidgetTester tester) async { + Widget buildFrame({ required Axis axis, required bool reverse }) { + final (Widget minPrototype, Widget maxPrototype) = switch (axis) { + Axis.vertical => (const SizedBox(height: 100), const SizedBox(height: 300)), + Axis.horizontal => (const SizedBox(width: 100), const SizedBox(width: 300)), + }; + return MaterialApp( + home: Scaffold( + body: CustomScrollView( + scrollDirection: axis, + reverse: reverse, + slivers: <Widget>[ + SliverResizingHeader( + minExtentPrototype: minPrototype, + maxExtentPrototype: maxPrototype, + child: const SizedBox.expand(child: Text('header')), + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => Text('item $index'), + childCount: 100, + ), + ), + ], + ), + ), + ); + } + + Rect getHeaderRect() => tester.getRect(find.text('header')); + Rect getItemRect(int index) => tester.getRect(find.text('item $index')); + + // axis: Axis.vertical, reverse: false + { + await tester.pumpWidget(buildFrame(axis: Axis.vertical, reverse: false)); + await tester.pumpAndSettle(); + final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; + + // The test viewport is width=800 x height=600 + // The height=300 header is at the top of the scroll view and all items are the same height. + expect(getHeaderRect().topLeft, Offset.zero); + expect(getHeaderRect().width, 800); + expect(getHeaderRect().height, 300); + + // First and last visible items + final double itemHeight = getItemRect(0).height; + final int visibleItemCount = 300 ~/ itemHeight; // 300 = viewport height - header height + expect(find.text('item 0'), findsOneWidget); + expect(find.text('item ${visibleItemCount - 1}'), findsOneWidget); + + // Scrolling up and down leaves the header at the top but changes its height + // between the heights of the min and max extent prototypes. + position.moveTo(200); + await tester.pumpAndSettle(); + expect(getHeaderRect().topLeft, Offset.zero); + expect(getHeaderRect().width, 800); + expect(getHeaderRect().height, 100); + position.moveTo(0); + await tester.pumpAndSettle(); + expect(getHeaderRect().topLeft, Offset.zero); + expect(getHeaderRect().width, 800); + expect(getHeaderRect().height, 300); + } + + // axis: Axis.horizontal, reverse: false + { + await tester.pumpWidget(buildFrame(axis: Axis.horizontal, reverse: false)); + await tester.pumpAndSettle(); + final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; + + // The width=300 header is at the left of the scroll view and all items are the same width. + expect(getHeaderRect().topLeft, Offset.zero); + expect(getHeaderRect().width, 300); + expect(getHeaderRect().height, 600); + + // First and last visible items (assuming < 10 items visible) + final double itemWidth = getItemRect(0).width; + final int visibleItemCount = 500 ~/ itemWidth; // 500 = viewport width - header width + expect(find.text('item 0'), findsOneWidget); + expect(find.text('item ${visibleItemCount - 1}'), findsOneWidget); + + // Scrolling up and down leaves the header on the left but changes its width + // between the heights of the min and max extent prototypes. + position.moveTo(200); + await tester.pumpAndSettle(); + expect(getHeaderRect().topLeft, Offset.zero); + expect(getHeaderRect().height, 600); + expect(getHeaderRect().width, 100); + position.moveTo(0); + await tester.pumpAndSettle(); + expect(getHeaderRect().topLeft, Offset.zero); + expect(getHeaderRect().height, 600); + expect(getHeaderRect().width, 300); + } + + // axis: Axis.vertical, reverse: true + { + await tester.pumpWidget(buildFrame(axis: Axis.vertical, reverse: true)); + await tester.pumpAndSettle(); + final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; + + // The height=300 header is at the bottom of the scroll view and all items are the same height. + expect(getHeaderRect().bottomLeft, const Offset(0, 600)); + expect(getHeaderRect().width, 800); + expect(getHeaderRect().height, 300); + + // First and last visible items (assuming < 10 items visible) + final double itemHeight = getItemRect(0).height; + final int visibleItemCount = 300 ~/ itemHeight; // 300 = viewport height - header height + expect(find.text('item 0'), findsOneWidget); + expect(find.text('item ${visibleItemCount - 1}'), findsOneWidget); + + // Scrolling up and down leaves the header at the bottom but changes its height + // between the heights of the min and max extent prototypes. + position.moveTo(200); + await tester.pumpAndSettle(); + expect(getHeaderRect().bottomLeft, const Offset(0, 600)); + expect(getHeaderRect().width, 800); + expect(getHeaderRect().height, 100); + position.moveTo(0); + await tester.pumpAndSettle(); + expect(getHeaderRect().bottomLeft, const Offset(0, 600)); + expect(getHeaderRect().width, 800); + expect(getHeaderRect().height, 300); + } + + // axis: Axis.horizontal, reverse: true + { + await tester.pumpWidget(buildFrame(axis: Axis.horizontal, reverse: true)); + await tester.pumpAndSettle(); + final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; + + // The width=300 header is on the right of the scroll view and all items are the same width. + expect(getHeaderRect().topRight, const Offset(800, 0)); + expect(getHeaderRect().width, 300); + expect(getHeaderRect().height, 600); + + final double itemWidth = getItemRect(0).width; + final int visibleItemCount = 500 ~/ itemWidth; // 500 = viewport width - header width + expect(find.text('item 0'), findsOneWidget); + expect(find.text('item ${visibleItemCount - 1}'), findsOneWidget); + + // Scrolling up and down leaves the header on the left but changes its width + // between the heights of the min and max extent prototypes. + position.moveTo(200); + await tester.pumpAndSettle(); + expect(getHeaderRect().topRight, const Offset(800, 0)); + expect(getHeaderRect().height, 600); + expect(getHeaderRect().width, 100); + position.moveTo(0); + await tester.pumpAndSettle(); + expect(getHeaderRect().topRight, const Offset(800, 0)); + expect(getHeaderRect().height, 600); + expect(getHeaderRect().width, 300); + } + }); + + testWidgets('SliverResizingHeader default minExtent is 0', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: CustomScrollView( + slivers: <Widget>[ + const SliverResizingHeader( + maxExtentPrototype: SizedBox(height: 300), + child: SizedBox.expand(child: Text('header')), + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => Text('item $index'), + childCount: 100, + ), + ), + ], + ), + ), + ), + ); + + expect(tester.getSize(find.text('header')).height, 300); + + final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; + + position.moveTo(299); + await tester.pumpAndSettle(); + expect(tester.getSize(find.text('header')).height, 1); + + position.moveTo(300); + await tester.pumpAndSettle(); + expect(find.text('header'), findsNothing); + }); + + testWidgets('SliverResizingHeader with identcial min/max prototypes is effectively a pinned header', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: CustomScrollView( + slivers: <Widget>[ + const SliverResizingHeader( + minExtentPrototype: SizedBox(height: 100), + maxExtentPrototype: SizedBox(height: 100), + child: SizedBox.expand(child: Text('header')), + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => Text('item $index'), + childCount: 100, + ), + ), + ], + ), + ), + ), + ); + + expect(tester.getTopLeft(find.text('header')), Offset.zero); + expect(tester.getSize(find.text('header')), const Size(800, 100)); + + final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; + + position.moveTo(100); + await tester.pumpAndSettle(); + expect(tester.getTopLeft(find.text('header')), Offset.zero); + expect(tester.getSize(find.text('header')), const Size(800, 100)); + + position.moveTo(0); + await tester.pumpAndSettle(); + expect(tester.getTopLeft(find.text('header')), Offset.zero); + expect(tester.getSize(find.text('header')), const Size(800, 100)); + }); + + testWidgets('SliverResizingHeader default maxExtent matches the child', (WidgetTester tester) async { + final Key headerKey = UniqueKey(); + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: CustomScrollView( + slivers: <Widget>[ + SliverResizingHeader( + child: SizedBox(key: headerKey, height: 300), + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => Text('item $index'), + childCount: 100, + ), + ), + ], + ), + ), + ), + ); + + expect(tester.getSize(find.byKey(headerKey)).height, 300); + + final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; + + position.moveTo(299); + await tester.pumpAndSettle(); + expect(tester.getSize(find.byKey(headerKey)).height, 1); + + position.moveTo(300); + await tester.pumpAndSettle(); + expect(find.byKey(headerKey), findsNothing); + }); + + testWidgets('SliverResizingHeader overrides initial out of bounds child size', (WidgetTester tester) async { + Widget buildFrame(double childHeight) { + return MaterialApp( + home: Scaffold( + body: CustomScrollView( + slivers: <Widget>[ + SliverResizingHeader( + minExtentPrototype: const SizedBox(height: 100), + maxExtentPrototype: const SizedBox(height: 300), + child: SizedBox(height: childHeight, child: const Text('header')), + ), + ], + ), + ), + ); + } + + await tester.pumpWidget(buildFrame(50)); + expect(tester.getSize(find.text('header')).height, 100); + + await tester.pumpWidget(buildFrame(350)); + expect(tester.getSize(find.text('header')).height, 300); + }); + + testWidgets('SliverResizingHeader update prototypes', (WidgetTester tester) async { + Widget buildFrame(double minHeight, double maxHeight) { + return MaterialApp( + home: Scaffold( + body: CustomScrollView( + slivers: <Widget>[ + SliverResizingHeader( + minExtentPrototype: SizedBox(height: minHeight), + maxExtentPrototype: SizedBox(height: maxHeight), + child: const SizedBox(height: 300, child: Text('header')), + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => SizedBox(height: 50, child: Text('$index')), + childCount: 100, + ), + ), + ], + ), + ), + ); + } + + + double getHeaderHeight() => tester.getSize(find.text('header')).height; + + await tester.pumpWidget(buildFrame(100, 300)); + expect(getHeaderHeight(), 300); + + // Scroll more than needed to reach the min and max header heights. + + await tester.drag(find.byType(CustomScrollView), const Offset(0, -300)); + await tester.pumpAndSettle(); + expect(getHeaderHeight(), 100); + + await tester.drag(find.byType(CustomScrollView), const Offset(0, 300)); + await tester.pumpAndSettle(); + expect(getHeaderHeight(), 300); + + // Change min,maxExtentPrototype widget heights from 150,200 to + + await tester.pumpWidget(buildFrame(150, 200)); + expect(getHeaderHeight(), 200); + + await tester.drag(find.byType(CustomScrollView), const Offset(0, -100)); + await tester.pumpAndSettle(); + expect(getHeaderHeight(), 150); + + await tester.drag(find.byType(CustomScrollView), const Offset(0, 100)); + await tester.pumpAndSettle(); + expect(getHeaderHeight(), 200); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_semantics_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_semantics_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..c7d5981a8e1740eacf77effbb4d9b8cd7791b4c2 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_semantics_test.dart @@ -0,0 +1,1132 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'semantics_tester.dart'; + +void main() { + group('Sliver Semantics', () { + setUp(() { + debugResetSemanticsIdCounter(); + }); + + _tests(); + }); +} + +void _tests() { + testWidgets('excludeFromScrollable works correctly', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + + const double appBarExpandedHeight = 200.0; + + final ScrollController scrollController = ScrollController(); + addTearDown(scrollController.dispose); + final List<Widget> listChildren = List<Widget>.generate(30, (int i) { + return SizedBox( + height: appBarExpandedHeight, + child: Text('Item $i'), + ); + }); + await tester.pumpWidget( + Semantics( + textDirection: TextDirection.ltr, + child: Localizations( + locale: const Locale('en', 'us'), + delegates: const <LocalizationsDelegate<dynamic>>[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: Directionality( + textDirection: TextDirection.ltr, + child: MediaQuery( + data: const MediaQueryData(), + child: CustomScrollView( + controller: scrollController, + slivers: <Widget>[ + const SliverAppBar( + pinned: true, + expandedHeight: appBarExpandedHeight, + title: Text('Semantics Test with Slivers'), + ), + SliverList( + delegate: SliverChildListDelegate(listChildren), + ), + ], + ), + ), + ), + ), + ), + ); + + // AppBar is child of node with semantic scroll actions. + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + id: 1, + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + id: 2, + children: <TestSemantics>[ + TestSemantics( + id: 7, + children: <TestSemantics>[ + TestSemantics( + id: 8, + flags: <SemanticsFlag>[ + SemanticsFlag.namesRoute, + SemanticsFlag.isHeader, + ], + label: 'Semantics Test with Slivers', + textDirection: TextDirection.ltr, + ), + ], + ), + TestSemantics( + id: 9, + flags: <SemanticsFlag>[ + SemanticsFlag.hasImplicitScrolling, + ], + actions: <SemanticsAction>[SemanticsAction.scrollUp], + children: <TestSemantics>[ + TestSemantics( + id: 3, + label: 'Item 0', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 4, + label: 'Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 5, + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 6, + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 3', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreRect: true, + ignoreTransform: true, + )); + + // Scroll down far enough to reach the pinned state of the app bar. + scrollController.jumpTo(appBarExpandedHeight); + await tester.pump(); + + // App bar is NOT a child of node with semantic scroll actions. + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + id: 1, + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + id: 2, + children: <TestSemantics>[ + TestSemantics( + id: 7, + tags: <SemanticsTag>[RenderViewport.excludeFromScrolling], + children: <TestSemantics>[ + TestSemantics( + id: 8, + flags: <SemanticsFlag>[ + SemanticsFlag.namesRoute, + SemanticsFlag.isHeader, + ], + label: 'Semantics Test with Slivers', + textDirection: TextDirection.ltr, + ), + ], + ), + TestSemantics( + id: 9, + actions: <SemanticsAction>[ + SemanticsAction.scrollUp, + SemanticsAction.scrollDown, + ], + flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling], + children: <TestSemantics>[ + TestSemantics( + id: 3, + label: 'Item 0', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 4, + label: 'Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 5, + label: 'Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 6, + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 3', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 10, + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 4', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreRect: true, + ignoreTransform: true, + )); + + // Scroll halfway back to the top, app bar is no longer in pinned state. + scrollController.jumpTo(appBarExpandedHeight / 2); + await tester.pump(); + + // AppBar is child of node with semantic scroll actions. + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + id: 1, + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + id: 2, + children: <TestSemantics>[ + TestSemantics( + id: 7, + children: <TestSemantics>[ + TestSemantics( + id: 8, + flags: <SemanticsFlag>[ + SemanticsFlag.namesRoute, + SemanticsFlag.isHeader, + ], + label: 'Semantics Test with Slivers', + textDirection: TextDirection.ltr, + ), + ], + ), + TestSemantics( + id: 9, + flags: <SemanticsFlag>[ + SemanticsFlag.hasImplicitScrolling, + ], + actions: <SemanticsAction>[ + SemanticsAction.scrollUp, + SemanticsAction.scrollDown, + ], + children: <TestSemantics>[ + TestSemantics( + id: 3, + label: 'Item 0', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 4, + label: 'Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 5, + label: 'Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + id: 6, + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 3', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreRect: true, + ignoreTransform: true, + )); + + semantics.dispose(); + }); + + testWidgets('Offscreen sliver are hidden in semantics tree', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + + const double containerHeight = 200.0; + + final ScrollController scrollController = ScrollController( + initialScrollOffset: containerHeight * 1.5, + ); + addTearDown(scrollController.dispose); + final List<Widget> slivers = List<Widget>.generate(30, (int i) { + return SliverToBoxAdapter( + child: SizedBox( + height: containerHeight, + child: Text('Item $i', textDirection: TextDirection.ltr), + ), + ); + }); + await tester.pumpWidget( + Semantics( + textDirection: TextDirection.ltr, + child: Localizations( + locale: const Locale('en', 'us'), + delegates: const <LocalizationsDelegate<dynamic>>[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + height: containerHeight, + child: CustomScrollView( + controller: scrollController, + slivers: slivers, + ), + ), + ), + ), + ), + ), + ); + + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.hasImplicitScrolling, + ], + actions: <SemanticsAction>[ + SemanticsAction.scrollUp, + SemanticsAction.scrollDown, + ], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 0', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 3', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreRect: true, + ignoreTransform: true, + ignoreId: true, + )); + + semantics.dispose(); + }); + + testWidgets('SemanticsNodes of Slivers are in paint order', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + + final List<Widget> slivers = List<Widget>.generate(5, (int i) { + return SliverToBoxAdapter( + child: SizedBox( + height: 20.0, + child: Text('Item $i'), + ), + ); + }); + await tester.pumpWidget( + Semantics( + textDirection: TextDirection.ltr, + child: Localizations( + locale: const Locale('en', 'us'), + delegates: const <LocalizationsDelegate<dynamic>>[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: Directionality( + textDirection: TextDirection.ltr, + child: CustomScrollView( + slivers: slivers, + ), + ), + ), + ), + ); + + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.hasImplicitScrolling, + ], + children: <TestSemantics>[ + TestSemantics( + label: 'Item 4', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 3', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 0', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreRect: true, + ignoreTransform: true, + ignoreId: true, + childOrder: DebugSemanticsDumpOrder.inverseHitTest, + )); + + semantics.dispose(); + }); + + testWidgets('SemanticsNodes of a sliver fully covered by another overlapping sliver are excluded', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + + final List<Widget> listChildren = List<Widget>.generate(10, (int i) { + return SizedBox( + height: 200.0, + child: Text('Item $i', textDirection: TextDirection.ltr), + ); + }); + final ScrollController controller = ScrollController(initialScrollOffset: 280.0); + addTearDown(controller.dispose); + await tester.pumpWidget(Semantics( + textDirection: TextDirection.ltr, + child: Localizations( + locale: const Locale('en', 'us'), + delegates: const <LocalizationsDelegate<dynamic>>[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: Directionality( + textDirection: TextDirection.ltr, + child: MediaQuery( + data: const MediaQueryData(), + child: CustomScrollView( + slivers: <Widget>[ + const SliverAppBar( + pinned: true, + expandedHeight: 100.0, + title: Text('AppBar'), + ), + SliverList( + delegate: SliverChildListDelegate(listChildren), + ), + ], + controller: controller, + ), + ), + ), + ), + )); + + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + tags: <SemanticsTag>[RenderViewport.excludeFromScrolling], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.namesRoute, + SemanticsFlag.isHeader, + ], + label: 'AppBar', + textDirection: TextDirection.ltr, + ), + ], + ), + TestSemantics( + actions: <SemanticsAction>[ + SemanticsAction.scrollUp, + SemanticsAction.scrollDown, + ], + flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 0', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 3', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 4', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 5', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + )); + + semantics.dispose(); + }); + + testWidgets('Slivers fully covered by another overlapping sliver are hidden', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + + final ScrollController controller = ScrollController(initialScrollOffset: 280.0); + addTearDown(controller.dispose); + final List<Widget> slivers = List<Widget>.generate(10, (int i) { + return SliverToBoxAdapter( + child: SizedBox( + height: 200.0, + child: Text('Item $i', textDirection: TextDirection.ltr), + ), + ); + }); + await tester.pumpWidget(Semantics( + textDirection: TextDirection.ltr, + child: Localizations( + locale: const Locale('en', 'us'), + delegates: const <LocalizationsDelegate<dynamic>>[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: Directionality( + textDirection: TextDirection.ltr, + child: MediaQuery( + data: const MediaQueryData(), + child: CustomScrollView( + controller: controller, + slivers: <Widget>[ + const SliverAppBar( + pinned: true, + expandedHeight: 100.0, + title: Text('AppBar'), + ), + ...slivers, + ], + ), + ), + ), + ), + )); + + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + tags: <SemanticsTag>[RenderViewport.excludeFromScrolling], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.namesRoute, + SemanticsFlag.isHeader, + ], + label: 'AppBar', + textDirection: TextDirection.ltr, + ), + ], + ), + TestSemantics( + actions: <SemanticsAction>[ + SemanticsAction.scrollUp, + SemanticsAction.scrollDown, + ], + flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 0', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 3', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 4', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 5', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreTransform: true, + ignoreRect: true, + ignoreId: true, + )); + + semantics.dispose(); + }); + + testWidgets('SemanticsNodes of a sliver fully covered by another overlapping sliver are excluded (reverse)', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + + final List<Widget> listChildren = List<Widget>.generate(10, (int i) { + return SizedBox( + height: 200.0, + child: Text('Item $i', textDirection: TextDirection.ltr), + ); + }); + final ScrollController controller = ScrollController(initialScrollOffset: 280.0); + addTearDown(controller.dispose); + await tester.pumpWidget(Semantics( + textDirection: TextDirection.ltr, + child: Localizations( + locale: const Locale('en', 'us'), + delegates: const <LocalizationsDelegate<dynamic>>[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: Directionality( + textDirection: TextDirection.ltr, + child: MediaQuery( + data: const MediaQueryData(), + child: CustomScrollView( + reverse: true, // This is the important setting for this test. + slivers: <Widget>[ + const SliverAppBar( + pinned: true, + expandedHeight: 100.0, + title: Text('AppBar'), + ), + SliverList( + delegate: SliverChildListDelegate(listChildren), + ), + ], + controller: controller, + ), + ), + ), + ), + )); + + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.hasImplicitScrolling, + ], + actions: <SemanticsAction>[ + SemanticsAction.scrollUp, + SemanticsAction.scrollDown, + ], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 5', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 4', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 3', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 0', + textDirection: TextDirection.ltr, + ), + ], + ), + TestSemantics( + tags: <SemanticsTag>[RenderViewport.excludeFromScrolling], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.namesRoute, + SemanticsFlag.isHeader, + ], + label: 'AppBar', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + )); + + semantics.dispose(); + }); + + testWidgets('Slivers fully covered by another overlapping sliver are hidden (reverse)', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + + final ScrollController controller = ScrollController(initialScrollOffset: 280.0); + addTearDown(controller.dispose); + final List<Widget> slivers = List<Widget>.generate(10, (int i) { + return SliverToBoxAdapter( + child: SizedBox( + height: 200.0, + child: Text('Item $i', textDirection: TextDirection.ltr), + ), + ); + }); + await tester.pumpWidget(Semantics( + textDirection: TextDirection.ltr, + child: Localizations( + locale: const Locale('en', 'us'), + delegates: const <LocalizationsDelegate<dynamic>>[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: Directionality( + textDirection: TextDirection.ltr, + child: MediaQuery( + data: const MediaQueryData(), + child: CustomScrollView( + reverse: true, // This is the important setting for this test. + controller: controller, + slivers: <Widget>[ + const SliverAppBar( + pinned: true, + expandedHeight: 100.0, + title: Text('AppBar'), + ), + ...slivers, + ], + ), + ), + ), + ), + )); + + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.hasImplicitScrolling, + ], + actions: <SemanticsAction>[ + SemanticsAction.scrollUp, + SemanticsAction.scrollDown, + ], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 5', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 4', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 3', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Item 0', + textDirection: TextDirection.ltr, + ), + ], + ), + TestSemantics( + tags: <SemanticsTag>[RenderViewport.excludeFromScrolling], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.namesRoute, + SemanticsFlag.isHeader, + ], + label: 'AppBar', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + )); + + semantics.dispose(); + }); + + testWidgets('Slivers fully covered by another overlapping sliver are hidden (with center sliver)', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + + final ScrollController controller = ScrollController(initialScrollOffset: 280.0); + addTearDown(controller.dispose); + final GlobalKey forwardAppBarKey = GlobalKey(debugLabel: 'forward app bar'); + final List<Widget> forwardChildren = List<Widget>.generate(10, (int i) { + return SizedBox( + height: 200.0, + child: Text('Forward Item $i', textDirection: TextDirection.ltr), + ); + }); + final List<Widget> backwardChildren = List<Widget>.generate(10, (int i) { + return SizedBox( + height: 200.0, + child: Text('Backward Item $i', textDirection: TextDirection.ltr), + ); + }); + await tester.pumpWidget(Semantics( + textDirection: TextDirection.ltr, + child: Directionality( + textDirection: TextDirection.ltr, + child: Localizations( + locale: const Locale('en', 'us'), + delegates: const <LocalizationsDelegate<dynamic>>[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: MediaQuery( + data: const MediaQueryData(), + child: Scrollable( + controller: controller, + viewportBuilder: (BuildContext context, ViewportOffset offset) { + return Viewport( + offset: offset, + center: forwardAppBarKey, + slivers: <Widget>[ + SliverList( + delegate: SliverChildListDelegate(backwardChildren), + ), + const SliverAppBar( + pinned: true, + expandedHeight: 100.0, + flexibleSpace: FlexibleSpaceBar( + title: Text('Backward app bar', textDirection: TextDirection.ltr), + ), + ), + SliverAppBar( + pinned: true, + key: forwardAppBarKey, + expandedHeight: 100.0, + flexibleSpace: const FlexibleSpaceBar( + title: Text('Forward app bar', textDirection: TextDirection.ltr), + ), + ), + SliverList( + delegate: SliverChildListDelegate(forwardChildren), + ), + ], + ); + }, + ), + ), + ), + ), + )); + + // 'Forward Item 0' is covered by app bar. + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + tags: <SemanticsTag>[RenderViewport.excludeFromScrolling], + children: <TestSemantics>[ + TestSemantics(), + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.namesRoute, + SemanticsFlag.isHeader, + ], + label: 'Forward app bar', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + TestSemantics( + actions: <SemanticsAction>[ + SemanticsAction.scrollUp, + SemanticsAction.scrollDown, + ], + flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Forward Item 0', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Forward Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Forward Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Forward Item 3', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Forward Item 4', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Forward Item 5', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreTransform: true, + ignoreRect: true, + ignoreId: true, + )); + + controller.jumpTo(-880.0); + await tester.pumpAndSettle(); + + // 'Backward Item 0' is covered by app bar. + expect(semantics, hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + textDirection: TextDirection.ltr, + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.hasImplicitScrolling, + ], + actions: <SemanticsAction>[ + SemanticsAction.scrollUp, + SemanticsAction.scrollDown, + ], + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Backward Item 5', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Backward Item 4', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Backward Item 3', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Backward Item 2', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Backward Item 1', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.isHidden], + label: 'Backward Item 0', + textDirection: TextDirection.ltr, + ), + ], + ), + TestSemantics( + tags: <SemanticsTag>[RenderViewport.excludeFromScrolling], + children: <TestSemantics>[ + TestSemantics(), + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[ + SemanticsFlag.namesRoute, + SemanticsFlag.isHeader, + ], + label: 'Backward app bar', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), ignoreTransform: true, ignoreRect: true, ignoreId: true, + )); + + semantics.dispose(); + }); + +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_tree_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_tree_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..a7a7a2581ecd48aa89dd1d908672953668b52218 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_tree_test.dart @@ -0,0 +1,791 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +List<TreeSliverNode<String>> simpleNodeSet = <TreeSliverNode<String>>[ + TreeSliverNode<String>('Root 0'), + TreeSliverNode<String>( + 'Root 1', + expanded: true, + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 1:0'), + TreeSliverNode<String>('Child 1:1'), + ], + ), + TreeSliverNode<String>( + 'Root 2', + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 2:0'), + TreeSliverNode<String>('Child 2:1'), + ], + ), + TreeSliverNode<String>('Root 3'), +]; + +void main() { + group('TreeSliverNode', () { + setUp(() { + // Reset node conditions for each test. + simpleNodeSet = <TreeSliverNode<String>>[ + TreeSliverNode<String>('Root 0'), + TreeSliverNode<String>( + 'Root 1', + expanded: true, + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 1:0'), + TreeSliverNode<String>('Child 1:1'), + ], + ), + TreeSliverNode<String>( + 'Root 2', + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 2:0'), + TreeSliverNode<String>('Child 2:1'), + ], + ), + TreeSliverNode<String>('Root 3'), + ]; + }); + + test('getters, toString', () { + final List<TreeSliverNode<String>> children = <TreeSliverNode<String>>[ + TreeSliverNode<String>('child'), + ]; + final TreeSliverNode<String> node = TreeSliverNode<String>( + 'parent', + children: children, + expanded: true, + ); + expect(node.content, 'parent'); + expect(node.children, children); + expect(node.isExpanded, isTrue); + expect(node.children.first.content, 'child'); + expect(node.children.first.children.isEmpty, isTrue); + expect(node.children.first.isExpanded, isFalse); + // Set by TreeSliver when built for tree integrity + expect(node.depth, isNull); + expect(node.parent, isNull); + expect(node.children.first.depth, isNull); + expect(node.children.first.parent, isNull); + + expect( + node.toString(), + 'TreeSliverNode: parent, depth: null, parent, expanded: true', + ); + expect( + node.children.first.toString(), + 'TreeSliverNode: child, depth: null, leaf', + ); + }); + + testWidgets('TreeSliverNode sets ups parent and depth properties', (WidgetTester tester) async { + final List<TreeSliverNode<String>> children = <TreeSliverNode<String>>[ + TreeSliverNode<String>('child'), + ]; + final TreeSliverNode<String> node = TreeSliverNode<String>( + 'parent', + children: children, + expanded: true, + ); + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: <TreeSliverNode<String>>[node], + ), + ], + ) + )); + expect(node.content, 'parent'); + expect(node.children, children); + expect(node.isExpanded, isTrue); + expect(node.children.first.content, 'child'); + expect(node.children.first.children.isEmpty, isTrue); + expect(node.children.first.isExpanded, isFalse); + // Set by TreeSliver when built for tree integrity + expect(node.depth, 0); + expect(node.parent, isNull); + expect(node.children.first.depth, 1); + expect(node.children.first.parent, node); + + expect( + node.toString(), + 'TreeSliverNode: parent, depth: root, parent, expanded: true', + ); + expect( + node.children.first.toString(), + 'TreeSliverNode: child, depth: 1, leaf', + ); + }); + }); + + group('TreeController', () { + setUp(() { + // Reset node conditions for each test. + simpleNodeSet = <TreeSliverNode<String>>[ + TreeSliverNode<String>('Root 0'), + TreeSliverNode<String>( + 'Root 1', + expanded: true, + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 1:0'), + TreeSliverNode<String>('Child 1:1'), + ], + ), + TreeSliverNode<String>( + 'Root 2', + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 2:0'), + TreeSliverNode<String>('Child 2:1'), + ], + ), + TreeSliverNode<String>('Root 3'), + ]; + }); + + testWidgets('Can set controller on TreeSliver', (WidgetTester tester) async { + final TreeSliverController controller = TreeSliverController(); + TreeSliverController? returnedController; + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + treeNodeBuilder: ( + BuildContext context, + TreeSliverNode<Object?> node, + AnimationStyle toggleAnimationStyle, + ) { + returnedController ??= TreeSliverController.of(context); + return TreeSliver.defaultTreeNodeBuilder( + context, + node, + toggleAnimationStyle, + ); + }, + ), + ], + ), + )); + expect(controller, returnedController); + }); + + testWidgets('Can get default controller on TreeSliver', (WidgetTester tester) async { + TreeSliverController? returnedController; + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + treeNodeBuilder: ( + BuildContext context, + TreeSliverNode<Object?> node, + AnimationStyle toggleAnimationStyle, + ) { + returnedController ??= TreeSliverController.maybeOf(context); + return TreeSliver.defaultTreeNodeBuilder( + context, + node, + toggleAnimationStyle, + ); + }, + ), + ], + ), + )); + expect(returnedController, isNotNull); + }); + + testWidgets('Can get node for TreeSliverNode.content', (WidgetTester tester) async { + final TreeSliverController controller = TreeSliverController(); + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + ), + ], + ), + )); + + expect(controller.getNodeFor('Root 0'), simpleNodeSet[0]); + }); + + testWidgets('Can get isExpanded for a node', (WidgetTester tester) async { + final TreeSliverController controller = TreeSliverController(); + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + ), + ], + ), + )); + expect( + controller.isExpanded(simpleNodeSet[0]), + isFalse, + ); + expect( + controller.isExpanded(simpleNodeSet[1]), + isTrue, + ); + }); + + testWidgets('Can get isActive for a node', (WidgetTester tester) async { + final TreeSliverController controller = TreeSliverController(); + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + ), + ], + ), + )); + expect( + controller.isActive(simpleNodeSet[0]), + isTrue, + ); + expect( + controller.isActive(simpleNodeSet[1]), + isTrue, + ); + // The parent 'Root 2' is not expanded, so its children are not active. + expect( + controller.isExpanded(simpleNodeSet[2]), + isFalse, + ); + expect( + controller.isActive(simpleNodeSet[2].children[0]), + isFalse, + ); + }); + + testWidgets('Can toggleNode, to collapse or expand', (WidgetTester tester) async { + final TreeSliverController controller = TreeSliverController(); + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + ), + ], + ), + )); + + // The parent 'Root 2' is not expanded, so its children are not active. + expect( + controller.isExpanded(simpleNodeSet[2]), + isFalse, + ); + expect( + controller.isActive(simpleNodeSet[2].children[0]), + isFalse, + ); + // Toggle 'Root 2' to expand it + controller.toggleNode(simpleNodeSet[2]); + expect( + controller.isExpanded(simpleNodeSet[2]), + isTrue, + ); + expect( + controller.isActive(simpleNodeSet[2].children[0]), + isTrue, + ); + + // The parent 'Root 1' is expanded, so its children are active. + expect( + controller.isExpanded(simpleNodeSet[1]), + isTrue, + ); + expect( + controller.isActive(simpleNodeSet[1].children[0]), + isTrue, + ); + // Collapse 'Root 1' + controller.toggleNode(simpleNodeSet[1]); + expect( + controller.isExpanded(simpleNodeSet[1]), + isFalse, + ); + expect( + controller.isActive(simpleNodeSet[1].children[0]), + isTrue, + ); + // Nodes are not removed from the active list until the collapse animation + // completes. The parent expansion state also updates. + await tester.pumpAndSettle(); + expect( + controller.isExpanded(simpleNodeSet[1]), + isFalse, + ); + expect( + controller.isActive(simpleNodeSet[1].children[0]), + isFalse, + ); + }); + + testWidgets('Can expandNode, then collapseAll', + (WidgetTester tester) async { + final TreeSliverController controller = TreeSliverController(); + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + ), + ], + ), + )); + + // The parent 'Root 2' is not expanded, so its children are not active. + expect( + controller.isExpanded(simpleNodeSet[2]), + isFalse, + ); + expect( + controller.isActive(simpleNodeSet[2].children[0]), + isFalse, + ); + // Expand 'Root 2' + controller.expandNode(simpleNodeSet[2]); + expect( + controller.isExpanded(simpleNodeSet[2]), + isTrue, + ); + expect( + controller.isActive(simpleNodeSet[2].children[0]), + isTrue, + ); + + // Both parents from our simple node set are expanded. + // 'Root 1' + expect(controller.isExpanded(simpleNodeSet[1]), isTrue); + // 'Root 2' + expect(controller.isExpanded(simpleNodeSet[2]), isTrue); + // Collapse both. + controller.collapseAll(); + await tester.pumpAndSettle(); + // Both parents from our simple node set have collapsed. + // 'Root 1' + expect(controller.isExpanded(simpleNodeSet[1]), isFalse); + // 'Root 2' + expect(controller.isExpanded(simpleNodeSet[2]), isFalse); + }); + + testWidgets('Can collapseNode, then expandAll', (WidgetTester tester) async { + final TreeSliverController controller = TreeSliverController(); + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + ), + ], + ), + )); + + // The parent 'Root 1' is expanded, so its children are active. + expect( + controller.isExpanded(simpleNodeSet[1]), + isTrue, + ); + expect( + controller.isActive(simpleNodeSet[1].children[0]), + isTrue, + ); + // Collapse 'Root 1' + controller.collapseNode(simpleNodeSet[1]); + expect( + controller.isExpanded(simpleNodeSet[1]), + isFalse, + ); + expect( + controller.isActive(simpleNodeSet[1].children[0]), + isTrue, + ); + // Nodes are not removed from the active list until the collapse animation + // completes. + await tester.pumpAndSettle(); + expect( + controller.isActive(simpleNodeSet[1].children[0]), + isFalse, + ); + + // Both parents from our simple node set are collapsed. + // 'Root 1' + expect(controller.isExpanded(simpleNodeSet[1]), isFalse); + // 'Root 2' + expect(controller.isExpanded(simpleNodeSet[2]), isFalse); + // Expand both. + controller.expandAll(); + // Both parents from our simple node set are expanded. + // 'Root 1' + expect(controller.isExpanded(simpleNodeSet[1]), isTrue); + // 'Root 2' + expect(controller.isExpanded(simpleNodeSet[2]), isTrue); + }); + }); + + test('TreeSliverIndentationType values are properly reflected', () { + double value = TreeSliverIndentationType.standard.value; + expect(value, 10.0); + + value = TreeSliverIndentationType.none.value; + expect(value, 0.0); + + value = TreeSliverIndentationType.custom(50.0).value; + expect(value, 50.0); + }); + + testWidgets('.toggleNodeWith, onNodeToggle', (WidgetTester tester) async { + simpleNodeSet = <TreeSliverNode<String>>[ + TreeSliverNode<String>('Root 0'), + TreeSliverNode<String>( + 'Root 1', + expanded: true, + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 1:0'), + TreeSliverNode<String>('Child 1:1'), + ], + ), + TreeSliverNode<String>( + 'Root 2', + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 2:0'), + TreeSliverNode<String>('Child 2:1'), + ], + ), + TreeSliverNode<String>('Root 3'), + ]; + + final TreeSliverController controller = TreeSliverController(); + // The default node builder wraps the leading icon with toggleNodeWith. + bool toggled = false; + TreeSliverNode<String>? toggledNode; + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + onNodeToggle: (TreeSliverNode<Object?> node) { + toggled = true; + toggledNode = node as TreeSliverNode<String>; + }, + ), + ], + ), + )); + expect(controller.isExpanded(simpleNodeSet[1]), isTrue); + await tester.tap(find.byType(Icon).first); + await tester.pump(); + expect(controller.isExpanded(simpleNodeSet[1]), isFalse); + expect(toggled, isTrue); + expect(toggledNode, simpleNodeSet[1]); + await tester.pumpAndSettle(); + expect(controller.isExpanded(simpleNodeSet[1]), isFalse); + toggled = false; + toggledNode = null; + // Use toggleNodeWith to make the whole row trigger the node state. + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + onNodeToggle: (TreeSliverNode<Object?> node) { + toggled = true; + toggledNode = node as TreeSliverNode<String>; + }, + treeNodeBuilder: ( + BuildContext context, + TreeSliverNode<Object?> node, + AnimationStyle toggleAnimationStyle, + ) { + final Duration animationDuration = + toggleAnimationStyle.duration ?? TreeSliver.defaultAnimationDuration; + final Curve animationCurve = + toggleAnimationStyle.curve ?? TreeSliver.defaultAnimationCurve; + // This makes the whole row trigger toggling. + return TreeSliver.wrapChildToToggleNode( + node: node, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Row(children: <Widget>[ + // Icon for parent nodes + SizedBox.square( + dimension: 30.0, + child: node.children.isNotEmpty + ? AnimatedRotation( + turns: node.isExpanded ? 0.25 : 0.0, + duration: animationDuration, + curve: animationCurve, + child: const Icon(IconData(0x25BA), size: 14), + ) + : null, + ), + // Spacer + const SizedBox(width: 8.0), + // Content + Text(node.content.toString()), + ]), + ), + ); + }, + ), + ], + ), + )); + // Still collapsed from earlier + expect(controller.isExpanded(simpleNodeSet[1]), isFalse); + // Tapping on the text instead of the Icon. + await tester.tap(find.text('Root 1')); + await tester.pump(); + expect(controller.isExpanded(simpleNodeSet[1]), isTrue); + expect(toggled, isTrue); + expect(toggledNode, simpleNodeSet[1]); + }); + + testWidgets('AnimationStyle is piped through to node builder', (WidgetTester tester) async { + simpleNodeSet = <TreeSliverNode<String>>[ + TreeSliverNode<String>('Root 0'), + TreeSliverNode<String>( + 'Root 1', + expanded: true, + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 1:0'), + TreeSliverNode<String>('Child 1:1'), + ], + ), + TreeSliverNode<String>( + 'Root 2', + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 2:0'), + TreeSliverNode<String>('Child 2:1'), + ], + ), + TreeSliverNode<String>('Root 3'), + ]; + + AnimationStyle? style; + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + treeNodeBuilder: ( + BuildContext context, + TreeSliverNode<Object?> node, + AnimationStyle toggleAnimationStyle, + ) { + style ??= toggleAnimationStyle; + return Text(node.content.toString()); + }, + ), + ], + ), + )); + // Default + expect(style, TreeSliver.defaultToggleAnimationStyle); + + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + toggleAnimationStyle: AnimationStyle.noAnimation, + treeNodeBuilder: ( + BuildContext context, + TreeSliverNode<Object?> node, + AnimationStyle toggleAnimationStyle, + ) { + style = toggleAnimationStyle; + return Text(node.content.toString()); + }, + ), + ], + ), + )); + expect(style, isNotNull); + expect(style!.curve, isNull); + expect(style!.duration, Duration.zero); + style = null; + + await tester.pumpWidget(MaterialApp( + home: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + toggleAnimationStyle: AnimationStyle( + curve: Curves.easeIn, + duration: const Duration(milliseconds: 200), + ), + treeNodeBuilder: ( + BuildContext context, + TreeSliverNode<Object?> node, + AnimationStyle toggleAnimationStyle, + ) { + style ??= toggleAnimationStyle; + return Text(node.content.toString()); + }, + ), + ], + ), + )); + expect(style, isNotNull); + expect(style!.curve, Curves.easeIn); + expect(style!.duration, const Duration(milliseconds: 200)); + }); + + testWidgets('Adding more root TreeViewNodes are reflected in the tree', (WidgetTester tester) async { + simpleNodeSet = <TreeSliverNode<String>>[ + TreeSliverNode<String>('Root 0'), + TreeSliverNode<String>( + 'Root 1', + expanded: true, + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 1:0'), + TreeSliverNode<String>('Child 1:1'), + ], + ), + TreeSliverNode<String>( + 'Root 2', + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 2:0'), + TreeSliverNode<String>('Child 2:1'), + ], + ), + TreeSliverNode<String>('Root 3'), + ]; + final TreeSliverController controller = TreeSliverController(); + await tester.pumpWidget(MaterialApp( + home: StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return Scaffold( + body: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + ), + ], + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + setState(() { + simpleNodeSet.add(TreeSliverNode<String>('Added root')); + }); + }, + ), + ); + }, + ), + )); + await tester.pump(); + + expect(find.text('Root 0'), findsOneWidget); + expect(find.text('Root 1'), findsOneWidget); + expect(find.text('Child 1:0'), findsOneWidget); + expect(find.text('Child 1:1'), findsOneWidget); + expect(find.text('Root 2'), findsOneWidget); + expect(find.text('Child 2:0'), findsNothing); + expect(find.text('Child 2:1'), findsNothing); + expect(find.text('Root 3'), findsOneWidget); + expect(find.text('Added root'), findsNothing); + + await tester.tap(find.byType(FloatingActionButton)); + await tester.pump(); + + expect(find.text('Root 0'), findsOneWidget); + expect(find.text('Root 1'), findsOneWidget); + expect(find.text('Child 1:0'), findsOneWidget); + expect(find.text('Child 1:1'), findsOneWidget); + expect(find.text('Root 2'), findsOneWidget); + expect(find.text('Child 2:0'), findsNothing); + expect(find.text('Child 2:1'), findsNothing); + expect(find.text('Root 3'), findsOneWidget); + // Node was added + expect(find.text('Added root'), findsOneWidget); + }); + + testWidgets('Adding more TreeViewNodes below the root are reflected in the tree', (WidgetTester tester) async { + simpleNodeSet = <TreeSliverNode<String>>[ + TreeSliverNode<String>('Root 0'), + TreeSliverNode<String>( + 'Root 1', + expanded: true, + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 1:0'), + TreeSliverNode<String>('Child 1:1'), + ], + ), + TreeSliverNode<String>( + 'Root 2', + children: <TreeSliverNode<String>>[ + TreeSliverNode<String>('Child 2:0'), + TreeSliverNode<String>('Child 2:1'), + ], + ), + TreeSliverNode<String>('Root 3'), + ]; + final TreeSliverController controller = TreeSliverController(); + await tester.pumpWidget(MaterialApp( + home: StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return Scaffold( + body: CustomScrollView( + slivers: <Widget>[ + TreeSliver<String>( + tree: simpleNodeSet, + controller: controller, + ), + ], + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + setState(() { + simpleNodeSet[1].children.add(TreeSliverNode<String>('Added child')); + }); + }, + ), + ); + }, + ), + )); + await tester.pump(); + expect(find.text('Root 0'), findsOneWidget); + expect(find.text('Root 1'), findsOneWidget); + expect(find.text('Child 1:0'), findsOneWidget); + expect(find.text('Child 1:1'), findsOneWidget); + expect(find.text('Added child'), findsNothing); + expect(find.text('Root 2'), findsOneWidget); + expect(find.text('Child 2:0'), findsNothing); + expect(find.text('Child 2:1'), findsNothing); + expect(find.text('Root 3'), findsOneWidget); + await tester.tap(find.byType(FloatingActionButton)); + await tester.pump(); + expect(find.text('Root 0'), findsOneWidget); + expect(find.text('Root 1'), findsOneWidget); + expect(find.text('Child 1:0'), findsOneWidget); + expect(find.text('Child 1:1'), findsOneWidget); + // Child node was added + expect(find.text('Added child'), findsOneWidget); + expect(find.text('Root 2'), findsOneWidget); + expect(find.text('Child 2:0'), findsNothing); + expect(find.text('Child 2:1'), findsNothing); + expect(find.text('Root 3'), findsOneWidget); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_visibility_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_visibility_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..841563452f473aecf11dbb564cda17ef6b37864a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/sliver_visibility_test.dart @@ -0,0 +1,481 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'semantics_tester.dart'; + +class TestState extends StatefulWidget { + const TestState({ super.key, required this.child, required this.log }); + final Widget child; + final List<String> log; + @override + State<TestState> createState() => _TestStateState(); +} + +class _TestStateState extends State<TestState> { + @override + void initState() { + super.initState(); + widget.log.add('created new state'); + } + @override + Widget build(BuildContext context) { + return widget.child; + } +} + +void main() { + testWidgets('SliverVisibility', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + final List<String> log = <String>[]; + const Key anchor = Key('drag'); + + Widget boilerPlate(Widget sliver) { + return Localizations( + locale: const Locale('en', 'us'), + delegates: const <LocalizationsDelegate<dynamic>>[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: Directionality( + textDirection: TextDirection.ltr, + child: MediaQuery( + data: const MediaQueryData(), + child: CustomScrollView(slivers: <Widget>[sliver]), + ), + ), + ); + } + + final Widget testChild = SliverToBoxAdapter( + child: GestureDetector( + onTap: () { + log.add('tap'); + }, + child: Builder( + builder: (BuildContext context) { + final bool animating = TickerMode.of(context); + return TestState( + key: anchor, + log: log, + child: Text('a $animating', textDirection: TextDirection.rtl), + ); + }, + ), + ), + ); + + // We now run a sequence of pumpWidget calls one after the other. In + // addition to verifying that the right behavior is seen in each case, this + // also verifies that the widget can dynamically change from state to state. + + // Default + await tester.pumpWidget(boilerPlate(SliverVisibility(sliver: testChild))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paints..paragraph()); + RenderViewport renderViewport = tester.renderObject(find.byType(Viewport)); + RenderSliver renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(1)); + expect(log, <String>['created new state']); + await tester.tap(find.byKey(anchor)); + expect(log, <String>['created new state', 'tap']); + log.clear(); + + // visible: false + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + ))); + expect(find.byType(Text), findsNothing); + expect(find.byType(Text, skipOffstage: false), findsNothing); + expect(find.byType(SliverVisibility, skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 0.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(0)); + expect(log, <String>[]); + expect(find.byKey(anchor), findsNothing); + log.clear(); + + // visible: false, with replacementSliver + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + replacementSliver: const SliverToBoxAdapter(child: Placeholder()), + visible: false, + ))); + expect(find.byType(Text, skipOffstage: false), findsNothing); + expect(find.byType(Placeholder), findsOneWidget); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paints..path()); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 400.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(0)); + expect(log, <String>[]); + expect(find.byKey(anchor), findsNothing); + log.clear(); + + // visible: true, with replacementSliver + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + replacementSliver: const SliverToBoxAdapter(child: Placeholder()), + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paints..paragraph()); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(1)); + expect(log, <String>['created new state']); + await tester.tap(find.byKey(anchor)); + expect(log, <String>['created new state', 'tap']); + log.clear(); + + // visible: true, maintain all + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + maintainState: true, + maintainAnimation: true, + maintainSize: true, + maintainInteractivity: true, + maintainSemantics: true, + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paints..paragraph()); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(1)); + expect(log, <String>['created new state']); + await tester.tap(find.byKey(anchor)); + expect(log, <String>['created new state', 'tap']); + log.clear(); + + // visible: false, maintain all + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + maintainState: true, + maintainAnimation: true, + maintainSize: true, + maintainInteractivity: true, + maintainSemantics: true, + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(1)); + expect(log, <String>[]); + await tester.tap(find.byKey(anchor)); + expect(log, <String>['tap']); + log.clear(); + + // visible: false, maintain all, replacementSliver + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + replacementSliver: const SliverToBoxAdapter(child: Placeholder()), + visible: false, + maintainState: true, + maintainAnimation: true, + maintainSize: true, + maintainInteractivity: true, + maintainSemantics: true, + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(1)); + expect(log, <String>[]); + await tester.tap(find.byKey(anchor)); + expect(log, <String>['tap']); + log.clear(); + + // visible: false, maintain all but semantics + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + maintainState: true, + maintainAnimation: true, + maintainSize: true, + maintainInteractivity: true, + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(0)); + expect(log, <String>[]); + await tester.tap(find.byKey(anchor)); + expect(log, <String>['tap']); + log.clear(); + + // visible: false, maintain all but interactivity + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + maintainState: true, + maintainAnimation: true, + maintainSize: true, + maintainSemantics: true, + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(1)); + expect(log, <String>[]); + await tester.tap(find.byKey(anchor), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + // visible: false, maintain state, animation, size. + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + maintainState: true, + maintainAnimation: true, + maintainSize: true, + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(0)); + expect(log, <String>[]); + await tester.tap(find.byKey(anchor), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + // visible: false, maintain state and animation. + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + maintainState: true, + maintainAnimation: true, + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.byType(Text), findsNothing); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 0.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(0)); + expect(log, <String>['created new state']); + expect(find.byKey(anchor), findsNothing); + log.clear(); + + // visible: false, maintain state. + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + maintainState: true, + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.byType(Text), findsNothing); + expect(find.text('a false', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 0.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(0)); + expect(log, <String>['created new state']); + expect(find.byKey(anchor), findsNothing); + log.clear(); + + // Now we toggle the visibility off and on a few times to make sure that + // works. + + // visible: true, maintain state + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + maintainState: true, + ))); + expect(find.byType(Text), findsOneWidget); + expect(find.text('a true'), findsOneWidget); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paints..paragraph()); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(1)); + expect(log, <String>[]); + await tester.tap(find.byKey(anchor)); + expect(log, <String>['tap']); + log.clear(); + + // visible: false, maintain state. + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + maintainState: true, + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.byType(Text), findsNothing); + expect(find.text('a false', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 0.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a false'), hasLength(0)); + expect(log, <String>[]); + expect(find.byKey(anchor), findsNothing); + log.clear(); + + // visible: true, maintain state. + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + maintainState: true, + ))); + expect(find.byType(Text), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), paints..paragraph()); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(1)); + expect(log, <String>[]); + await tester.tap(find.byKey(anchor)); + expect(log, <String>['tap']); + log.clear(); + + // visible: false, maintain state. + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + maintainState: true, + ))); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.byType(Text), findsNothing); + expect(find.text('a false', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 0.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a false'), hasLength(0)); + expect(log, <String>[]); + expect(find.byKey(anchor), findsNothing); + log.clear(); + + // Same but without maintainState. + + // visible: false. + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + ))); + expect(find.byType(Text, skipOffstage: false), findsNothing); + expect(find.byType(SliverVisibility, skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 0.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(0)); + expect(log, <String>[]); + expect(find.byKey(anchor), findsNothing); + log.clear(); + + // visible: true. + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + ))); + expect(find.byType(Text), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paints..paragraph()); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(1)); + expect(log, <String>['created new state']); + await tester.tap(find.byKey(anchor)); + expect(log, <String>['created new state', 'tap']); + log.clear(); + + //visible: false. + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + visible: false, + ))); + expect(find.byType(Text, skipOffstage: false), findsNothing); + expect(find.byType(SliverVisibility, skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility, skipOffstage: false), paintsNothing); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 0.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(0)); + expect(log, <String>[]); + expect(find.byKey(anchor), findsNothing); + log.clear(); + + // visible: true. + await tester.pumpWidget(boilerPlate(SliverVisibility( + sliver: testChild, + ))); + expect(find.byType(Text), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(SliverVisibility), findsOneWidget); + expect(find.byType(SliverVisibility), paints..paragraph()); + renderViewport = tester.renderObject(find.byType(Viewport)); + renderSliver = renderViewport.lastChild!; + expect(renderSliver.geometry!.scrollExtent, 14.0); + expect(renderSliver.constraints.crossAxisExtent, 800.0); + expect(semantics.nodesWith(label: 'a true'), hasLength(1)); + expect(log, <String>['created new state']); + await tester.tap(find.byKey(anchor)); + expect(log, <String>['created new state', 'tap']); + log.clear(); + + semantics.dispose(); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/slotted_render_object_widget_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/slotted_render_object_widget_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..55b222b24fb80367d986d0ef18378d75891c75c3 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/slotted_render_object_widget_test.dart @@ -0,0 +1,376 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +const Color green = Color(0xFF00FF00); +const Color yellow = Color(0xFFFFFF00); + +void main() { + testWidgets('SlottedRenderObjectWidget test', (WidgetTester tester) async { + await tester.pumpWidget(buildWidget( + topLeft: Container( + height: 100, + width: 80, + color: yellow, + child: const Text('topLeft'), + ), + bottomRight: Container( + height: 120, + width: 110, + color: green, + child: const Text('bottomRight'), + ), + )); + + expect(find.text('topLeft'), findsOneWidget); + expect(find.text('bottomRight'), findsOneWidget); + expect(tester.getSize(find.byType(_Diagonal)), const Size(80 + 110, 100 + 120)); + expect(find.byType(_Diagonal), paints + ..rect( + rect: const Rect.fromLTWH(0, 0, 80, 100), + color: yellow, + ) + ..rect( + rect: const Rect.fromLTWH(80, 100, 110, 120), + color: green, + ) + ); + + await tester.pumpWidget(buildWidget( + topLeft: Container( + height: 200, + width: 100, + color: yellow, + child: const Text('topLeft'), + ), + bottomRight: Container( + height: 220, + width: 210, + color: green, + child: const Text('bottomRight'), + ), + )); + + expect(find.text('topLeft'), findsOneWidget); + expect(find.text('bottomRight'), findsOneWidget); + expect(tester.getSize(find.byType(_Diagonal)), const Size(100 + 210, 200 + 220)); + expect(find.byType(_Diagonal), paints + ..rect( + rect: const Rect.fromLTWH(0, 0, 100, 200), + color: yellow, + ) + ..rect( + rect: const Rect.fromLTWH(100, 200, 210, 220), + color: green, + ) + ); + + await tester.pumpWidget(buildWidget( + topLeft: Container( + height: 200, + width: 100, + color: yellow, + child: const Text('topLeft'), + ), + bottomRight: Container( + key: UniqueKey(), + height: 230, + width: 220, + color: green, + child: const Text('bottomRight'), + ), + )); + + expect(find.text('topLeft'), findsOneWidget); + expect(find.text('bottomRight'), findsOneWidget); + expect(tester.getSize(find.byType(_Diagonal)), const Size(100 + 220, 200 + 230)); + expect(find.byType(_Diagonal), paints + ..rect( + rect: const Rect.fromLTWH(0, 0, 100, 200), + color: yellow, + ) + ..rect( + rect: const Rect.fromLTWH(100, 200, 220, 230), + color: green, + ) + ); + + await tester.pumpWidget(buildWidget( + topLeft: Container( + height: 200, + width: 100, + color: yellow, + child: const Text('topLeft'), + ), + )); + + expect(find.text('topLeft'), findsOneWidget); + expect(find.text('bottomRight'), findsNothing); + expect(tester.getSize(find.byType(_Diagonal)), const Size(100, 200)); + expect(find.byType(_Diagonal), paints + ..rect( + rect: const Rect.fromLTWH(0, 0, 100, 200), + color: yellow, + ) + ); + + await tester.pumpWidget(buildWidget()); + expect(find.text('topLeft'), findsNothing); + expect(find.text('bottomRight'), findsNothing); + expect(tester.getSize(find.byType(_Diagonal)), Size.zero); + expect(find.byType(_Diagonal), paintsNothing); + + await tester.pumpWidget(Container()); + expect(find.byType(_Diagonal), findsNothing); + }); + + test('nameForSlot', () { + expect(_RenderDiagonal().publicNameForSlot(_DiagonalSlot.bottomRight), 'bottomRight'); + expect(_RenderDiagonal().publicNameForSlot(_DiagonalSlot.topLeft), 'topLeft'); + final _Slot slot = _Slot(); + expect(_RenderTest().publicNameForSlot(slot), slot.toString()); + }); + + testWidgets('key reparenting', (WidgetTester tester) async { + const Widget widget1 = SizedBox(key: ValueKey<String>('smol'), height: 10, width: 10); + const Widget widget2 = SizedBox(key: ValueKey<String>('big'), height: 100, width: 100); + const Widget nullWidget = SizedBox(key: ValueKey<String>('null'), height: 50, width: 50); + + await tester.pumpWidget(buildWidget(topLeft: widget1, bottomRight: widget2, nullSlot: nullWidget)); + final _RenderDiagonal renderObject = tester.renderObject(find.byType(_Diagonal)); + expect(renderObject._topLeft!.size, const Size(10, 10)); + expect(renderObject._bottomRight!.size, const Size(100, 100)); + expect(renderObject._nullSlot!.size, const Size(50, 50)); + + final Element widget1Element = tester.element(find.byWidget(widget1)); + final Element widget2Element = tester.element(find.byWidget(widget2)); + final Element nullWidgetElement = tester.element(find.byWidget(nullWidget)); + + // Swapping 1 and 2. + await tester.pumpWidget(buildWidget(topLeft: widget2, bottomRight: widget1, nullSlot: nullWidget)); + expect(renderObject._topLeft!.size, const Size(100, 100)); + expect(renderObject._bottomRight!.size, const Size(10, 10)); + expect(renderObject._nullSlot!.size, const Size(50, 50)); + expect(widget1Element, same(tester.element(find.byWidget(widget1)))); + expect(widget2Element, same(tester.element(find.byWidget(widget2)))); + expect(nullWidgetElement, same(tester.element(find.byWidget(nullWidget)))); + + // Shifting slots + await tester.pumpWidget(buildWidget(topLeft: nullWidget, bottomRight: widget2, nullSlot: widget1)); + expect(renderObject._topLeft!.size, const Size(50, 50)); + expect(renderObject._bottomRight!.size, const Size(100, 100)); + expect(renderObject._nullSlot!.size, const Size(10, 10)); + expect(widget1Element, same(tester.element(find.byWidget(widget1)))); + expect(widget2Element, same(tester.element(find.byWidget(widget2)))); + expect(nullWidgetElement, same(tester.element(find.byWidget(nullWidget)))); + + // Moving + Deleting. + await tester.pumpWidget(buildWidget(bottomRight: widget2)); + expect(renderObject._topLeft, null); + expect(renderObject._bottomRight!.size, const Size(100, 100)); + expect(renderObject._nullSlot, null); + expect(widget1Element.debugIsDefunct, isTrue); + expect(nullWidgetElement.debugIsDefunct, isTrue); + expect(widget2Element, same(tester.element(find.byWidget(widget2)))); + + // Moving. + await tester.pumpWidget(buildWidget(topLeft: widget2)); + expect(renderObject._topLeft!.size, const Size(100, 100)); + expect(renderObject._bottomRight, null); + expect(widget2Element, same(tester.element(find.byWidget(widget2)))); + }); + + testWidgets('duplicated key error message', (WidgetTester tester) async { + const Widget widget1 = SizedBox(key: ValueKey<String>('widget 1'), height: 10, width: 10); + const Widget widget2 = SizedBox(key: ValueKey<String>('widget 1'), height: 100, width: 100); + const Widget widget3 = SizedBox(key: ValueKey<String>('widget 1'), height: 50, width: 50); + + await tester.pumpWidget(buildWidget(topLeft: widget1, bottomRight: widget2, nullSlot: widget3)); + + expect((tester.takeException() as FlutterError).toString(), equalsIgnoringHashCodes( + 'Multiple widgets used the same key in _Diagonal.\n' + "The key [<'widget 1'>] was used by multiple widgets. The offending widgets were:\n" + " - SizedBox-[<'widget 1'>](width: 50.0, height: 50.0, renderObject: RenderConstrainedBox#00000 NEEDS-LAYOUT NEEDS-PAINT)\n" + " - SizedBox-[<'widget 1'>](width: 10.0, height: 10.0, renderObject: RenderConstrainedBox#00000 NEEDS-LAYOUT NEEDS-PAINT)\n" + " - SizedBox-[<'widget 1'>](width: 100.0, height: 100.0, renderObject: RenderConstrainedBox#a4685 NEEDS-LAYOUT NEEDS-PAINT)\n" + 'A key can only be specified on one widget at a time in the same parent widget.' + )); + }); + + testWidgets('debugDescribeChildren', (WidgetTester tester) async { + await tester.pumpWidget(buildWidget( + topLeft: const SizedBox( + height: 100, + width: 80, + ), + bottomRight: const SizedBox( + height: 120, + width: 110, + ), + )); + + expect( + tester.renderObject(find.byType(_Diagonal)).toStringDeep(), + equalsIgnoringHashCodes( + '_RenderDiagonal#00000 relayoutBoundary=up1\n' + ' │ creator: _Diagonal ← Align ← Directionality ← MediaQuery ←\n' + ' │ _MediaQueryFromView ← _PipelineOwnerScope ← _ViewScope ←\n' + ' │ _RawView-[_DeprecatedRawViewKey TestFlutterView#00000] ← View ←\n' + ' │ [root]\n' + ' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n' + ' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n' + ' │ size: Size(190.0, 220.0)\n' + ' │\n' + ' ├─topLeft: RenderConstrainedBox#00000 relayoutBoundary=up2\n' + ' │ creator: SizedBox ← _Diagonal ← Align ← Directionality ←\n' + ' │ MediaQuery ← _MediaQueryFromView ← _PipelineOwnerScope ←\n' + ' │ _ViewScope ← _RawView-[_DeprecatedRawViewKey\n' + ' │ TestFlutterView#00000] ← View ← [root]\n' + ' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n' + ' │ constraints: BoxConstraints(unconstrained)\n' + ' │ size: Size(80.0, 100.0)\n' + ' │ additionalConstraints: BoxConstraints(w=80.0, h=100.0)\n' + ' │\n' + ' └─bottomRight: RenderConstrainedBox#00000 relayoutBoundary=up2\n' + ' creator: SizedBox ← _Diagonal ← Align ← Directionality ←\n' + ' MediaQuery ← _MediaQueryFromView ← _PipelineOwnerScope ←\n' + ' _ViewScope ← _RawView-[_DeprecatedRawViewKey\n' + ' TestFlutterView#00000] ← View ← [root]\n' + ' parentData: offset=Offset(80.0, 100.0) (can use size)\n' + ' constraints: BoxConstraints(unconstrained)\n' + ' size: Size(110.0, 120.0)\n' + ' additionalConstraints: BoxConstraints(w=110.0, h=120.0)\n', + ) + ); + }); +} + +Widget buildWidget({Widget? topLeft, Widget? bottomRight, Widget? nullSlot}) { + return Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: _Diagonal( + topLeft: topLeft, + bottomRight: bottomRight, + nullSlot: nullSlot, + ), + ), + ); +} + +enum _DiagonalSlot { + topLeft, + bottomRight, +} + +class _Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidgetMixin<_DiagonalSlot?, RenderBox> { + const _Diagonal({ + this.topLeft, + this.bottomRight, + this.nullSlot, + }); + + final Widget? topLeft; + final Widget? bottomRight; + final Widget? nullSlot; + + @override + Iterable<_DiagonalSlot?> get slots => <_DiagonalSlot?>[null, ..._DiagonalSlot.values]; + + @override + Widget? childForSlot(_DiagonalSlot? slot) { + switch (slot) { + case null: + return nullSlot; + case _DiagonalSlot.topLeft: + return topLeft; + case _DiagonalSlot.bottomRight: + return bottomRight; + } + } + + @override + SlottedContainerRenderObjectMixin<_DiagonalSlot?, RenderBox> createRenderObject( + BuildContext context, + ) { + return _RenderDiagonal(); + } +} + +class _RenderDiagonal extends RenderBox with SlottedContainerRenderObjectMixin<_DiagonalSlot?, RenderBox> { + RenderBox? get _topLeft => childForSlot(_DiagonalSlot.topLeft); + RenderBox? get _bottomRight => childForSlot(_DiagonalSlot.bottomRight); + RenderBox? get _nullSlot => childForSlot(null); + + @override + void performLayout() { + const BoxConstraints childConstraints = BoxConstraints(); + + Size topLeftSize = Size.zero; + if (_topLeft != null) { + _topLeft!.layout(childConstraints, parentUsesSize: true); + _positionChild(_topLeft!, Offset.zero); + topLeftSize = _topLeft!.size; + } + + Size bottomRightSize = Size.zero; + if (_bottomRight != null) { + _bottomRight!.layout(childConstraints, parentUsesSize: true); + _positionChild( + _bottomRight!, + Offset(topLeftSize.width, topLeftSize.height), + ); + bottomRightSize = _bottomRight!.size; + } + + Size nullSlotSize = Size.zero; + final RenderBox? nullSlot = _nullSlot; + if (nullSlot != null) { + nullSlot.layout(childConstraints, parentUsesSize: true); + _positionChild(nullSlot, Offset.zero); + nullSlotSize = nullSlot.size; + } + + size = constraints.constrain(Size( + topLeftSize.width + bottomRightSize.width + nullSlotSize.width, + topLeftSize.height + bottomRightSize.height + nullSlotSize.height, + )); + } + + void _positionChild(RenderBox child, Offset offset) { + (child.parentData! as BoxParentData).offset = offset; + } + + @override + void paint(PaintingContext context, Offset offset) { + if (_topLeft != null) { + _paintChild(_topLeft!, context, offset); + } + if (_bottomRight != null) { + _paintChild(_bottomRight!, context, offset); + } + } + + void _paintChild(RenderBox child, PaintingContext context, Offset offset) { + final BoxParentData childParentData = child.parentData! as BoxParentData; + context.paintChild(child, childParentData.offset + offset); + } + + String publicNameForSlot(_DiagonalSlot slot) => debugNameForSlot(slot); +} + +class _Slot { + @override + String toString() => describeIdentity(this); +} + +class _RenderTest extends RenderBox with SlottedContainerRenderObjectMixin<_Slot, RenderBox> { + String publicNameForSlot(_Slot slot) => debugNameForSlot(slot); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/snapshot_widget_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/snapshot_widget_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..f2e35095d88c8f5e9b67855b79f0c171b4466fcd --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/snapshot_widget_test.dart @@ -0,0 +1,413 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is run as part of a reduced test set in CI on Mac and Windows +// machines. +@Tags(<String>['reduced-test-set']) +library; + +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; + +void main() { + testWidgets('SnapshotWidget can rasterize child', (WidgetTester tester) async { + final SnapshotController controller = SnapshotController(allowSnapshotting: true); + addTearDown(controller.dispose); + final Key key = UniqueKey(); + + await tester.pumpWidget(RepaintBoundary( + key: key, + child: TestDependencies( + child: SnapshotWidget( + controller: controller, + child: Container( + width: 100, + height: 100, + color: const Color(0xFFAABB11), + ), + ), + ), + )); + await expectLater(find.byKey(key), matchesGoldenFile('raster_widget.yellow.png')); + + // Now change the color and assert the old snapshot still matches. + await tester.pumpWidget(RepaintBoundary( + key: key, + child: TestDependencies( + child: SnapshotWidget( + controller: controller, + child: Container( + width: 100, + height: 100, + color: const Color(0xFFAA0000), + ), + ), + ), + )); + await expectLater(find.byKey(key), matchesGoldenFile('raster_widget.yellow.png')); + + // Now invoke clear and the raster is re-generated. + controller.clear(); + await tester.pump(); + + await expectLater(find.byKey(key), matchesGoldenFile('raster_widget.red.png')); + }, skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 + + testWidgets('Changing devicePixelRatio does not repaint if snapshotting is not enabled', (WidgetTester tester) async { + final SnapshotController controller = SnapshotController(); + addTearDown(controller.dispose); + final TestPainter painter = TestPainter(); + addTearDown(painter.dispose); + double devicePixelRatio = 1.0; + late StateSetter localSetState; + + await tester.pumpWidget( + StatefulBuilder(builder: (BuildContext context, StateSetter setState) { + localSetState = setState; + return Center( + child: TestDependencies( + devicePixelRatio: devicePixelRatio, + child: SnapshotWidget( + controller: controller, + painter: painter, + child: const SizedBox(width: 100, height: 100), + ), + ), + ); + }), + ); + + expect(painter.count, 1); + + localSetState(() { + devicePixelRatio = 2.0; + }); + await tester.pump(); + + // Not repainted as dpr was not used. + expect(painter.count, 1); + }, skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 + + testWidgets('Changing devicePixelRatio forces raster regeneration', (WidgetTester tester) async { + final SnapshotController controller = SnapshotController(allowSnapshotting: true); + addTearDown(controller.dispose); + final TestPainter painter = TestPainter(); + addTearDown(painter.dispose); + double devicePixelRatio = 1.0; + late StateSetter localSetState; + + await tester.pumpWidget( + StatefulBuilder(builder: (BuildContext context, StateSetter setState) { + localSetState = setState; + return Center( + child: TestDependencies( + devicePixelRatio: devicePixelRatio, + child: SnapshotWidget( + controller: controller, + painter: painter, + child: const SizedBox(width: 100, height: 100), + ), + ), + ); + }), + ); + final ui.Image? raster = painter.lastImage; + + expect(raster, isNotNull); + expect(painter.count, 1); + + localSetState(() { + devicePixelRatio = 2.0; + }); + await tester.pump(); + + final ui.Image? newRaster = painter.lastImage; + + expect(painter.count, 2); + expect(raster, isNot(newRaster)); + }, skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 + + testWidgets('SnapshotWidget paints its child as a single picture layer', (WidgetTester tester) async { + final SnapshotController controller = SnapshotController(allowSnapshotting: true); + addTearDown(controller.dispose); + + await tester.pumpWidget(RepaintBoundary( + child: Center( + child: TestDependencies( + child: SnapshotWidget( + controller: controller, + child: Container( + width: 100, + height: 100, + color: const Color(0xFFAABB11), + ), + ), + ), + ), + )); + + expect(tester.layers, hasLength(3)); + expect(tester.layers.last, isA<PictureLayer>()); + + controller.allowSnapshotting = false; + await tester.pump(); + + expect(tester.layers, hasLength(3)); + expect(tester.layers.last, isA<PictureLayer>()); + }, skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 + + testWidgets('SnapshotWidget can update the painter type', (WidgetTester tester) async { + final SnapshotController controller = SnapshotController(allowSnapshotting: true); + addTearDown(controller.dispose); + final TestPainter painter1 = TestPainter(); + addTearDown(painter1.dispose); + final TestPainter2 painter2 = TestPainter2(); + addTearDown(painter2.dispose); + + + await tester.pumpWidget( + Center( + child: TestDependencies( + child: SnapshotWidget( + controller: controller, + painter: painter1, + child: const SizedBox(), + ), + ), + ), + ); + + await tester.pumpWidget( + Center( + child: TestDependencies( + child: SnapshotWidget( + controller: controller, + painter: painter2, + child: const SizedBox(), + ), + ), + ), + ); + + expect(tester.takeException(), isNull); + }, skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 + + testWidgets('RenderSnapshotWidget does not error on rasterization of child with empty size', (WidgetTester tester) async { + final SnapshotController controller = SnapshotController(allowSnapshotting: true); + addTearDown(controller.dispose); + + await tester.pumpWidget( + Center( + child: TestDependencies( + child: SnapshotWidget( + controller: controller, + child: const SizedBox(), + ), + ), + ), + ); + + expect(tester.takeException(), isNull); + }, skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 + + + testWidgets('RenderSnapshotWidget throws assertion if platform view is encountered', (WidgetTester tester) async { + final SnapshotController controller = SnapshotController(allowSnapshotting: true); + addTearDown(controller.dispose); + + await tester.pumpWidget( + Center( + child: TestDependencies( + child: SnapshotWidget( + controller: controller, + child: const SizedBox( + width: 100, + height: 100, + child: TestPlatformView(), + ), + ), + ), + ), + ); + + expect(tester.takeException(), isA<FlutterError>() + .having((FlutterError error) => error.message, 'message', contains('SnapshotWidget used with a child that contains a PlatformView'))); + }, skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 + + testWidgets('RenderSnapshotWidget does not assert if SnapshotMode.forced', (WidgetTester tester) async { + final SnapshotController controller = SnapshotController(allowSnapshotting: true); + addTearDown(controller.dispose); + + await tester.pumpWidget( + Center( + child: TestDependencies( + child: SnapshotWidget( + controller: controller, + mode: SnapshotMode.forced, + child: const SizedBox( + width: 100, + height: 100, + child: TestPlatformView(), + ), + ), + ), + ), + ); + + expect(tester.takeException(), isNull); + }, skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 + + testWidgets('RenderSnapshotWidget does not take a snapshot if a platform view is encountered with SnapshotMode.permissive', (WidgetTester tester) async { + final SnapshotController controller = SnapshotController(allowSnapshotting: true); + addTearDown(controller.dispose); + + await tester.pumpWidget( + Center( + child: TestDependencies( + child: SnapshotWidget( + controller: controller, + mode: SnapshotMode.permissive, + child: const SizedBox( + width: 100, + height: 100, + child: TestPlatformView(), + ), + ), + ), + ), + ); + + expect(tester.takeException(), isNull); + expect(tester.layers.last, isA<PlatformViewLayer>()); + }, + skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 + + testWidgets('SnapshotWidget should have same result when enabled', (WidgetTester tester) async { + addTearDown(tester.view.reset); + + tester.view + ..physicalSize = const Size(10, 10) + ..devicePixelRatio = 1; + + const ValueKey<String> repaintBoundaryKey = ValueKey<String>('boundary'); + final SnapshotController controller = SnapshotController(); + addTearDown(controller.dispose); + + await tester.pumpWidget(RepaintBoundary( + key: repaintBoundaryKey, + child: MaterialApp( + debugShowCheckedModeBanner: false, + home: Container( + color: Colors.black, + padding: const EdgeInsets.only(right: 0.6, bottom: 0.6), + child: SnapshotWidget( + controller: controller, + child: Container( + margin: const EdgeInsets.only(right: 0.4, bottom: 0.4), + color: Colors.blue, + ), + ), + ), + ), + )); + + final ui.Image imageWhenDisabled = (tester.renderObject(find.byKey(repaintBoundaryKey)) as RenderRepaintBoundary).toImageSync(); + addTearDown(imageWhenDisabled.dispose); + + controller.allowSnapshotting = true; + await tester.pump(); + + await expectLater(find.byKey(repaintBoundaryKey), matchesReferenceImage(imageWhenDisabled)); + }, + skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 + + test('SnapshotPainter dispatches memory events', () async { + await expectLater( + await memoryEvents( + () => TestPainter().dispose(), + TestPainter, + ), + areCreateAndDispose, + ); + }); +} + +class TestPlatformView extends SingleChildRenderObjectWidget { + const TestPlatformView({super.key}); + + @override + RenderObject createRenderObject(BuildContext context) { + return RenderTestPlatformView(); + } +} + +class RenderTestPlatformView extends RenderProxyBox { + @override + void paint(PaintingContext context, ui.Offset offset) { + context.addLayer(PlatformViewLayer(rect: offset & size, viewId: 1)); + } +} + +class TestPainter extends SnapshotPainter { + int count = 0; + bool shouldRepaintValue = false; + ui.Image? lastImage; + + int addedListenerCount = 0; + int removedListenerCount = 0; + + @override + void addListener(ui.VoidCallback listener) { + addedListenerCount += 1; + super.addListener(listener); + } + + @override + void removeListener(ui.VoidCallback listener) { + removedListenerCount += 1; + super.removeListener(listener); + } + + @override + void paintSnapshot(PaintingContext context, Offset offset, Size size, ui.Image image, Size sourceSize, double pixelRatio) { + count += 1; + lastImage = image; + } + + @override + void paint(PaintingContext context, ui.Offset offset, ui.Size size, PaintingContextCallback painter) { + count += 1; + } + + @override + bool shouldRepaint(covariant TestPainter oldDelegate) => shouldRepaintValue; +} + +class TestPainter2 extends TestPainter { + @override + bool shouldRepaint(covariant TestPainter2 oldDelegate) => shouldRepaintValue; +} + +class TestDependencies extends StatelessWidget { + const TestDependencies({required this.child, super.key, this.devicePixelRatio}); + + final Widget child; + final double? devicePixelRatio; + + @override + Widget build(BuildContext context) { + return Directionality( + textDirection: TextDirection.ltr, + child: MediaQuery( + data: const MediaQueryData().copyWith(devicePixelRatio: devicePixelRatio), + child: child, + ), + ); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/spacer_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/spacer_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..06fbda26d2451be2226671e2a0aa0778f766bca9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/spacer_test.dart @@ -0,0 +1,73 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Spacer takes up space.', (WidgetTester tester) async { + await tester.pumpWidget(const Column( + children: <Widget>[ + SizedBox(width: 10.0, height: 10.0), + Spacer(), + SizedBox(width: 10.0, height: 10.0), + ], + )); + final Rect spacerRect = tester.getRect(find.byType(Spacer)); + expect(spacerRect.size, const Size(0.0, 580.0)); + expect(spacerRect.topLeft, const Offset(400.0, 10.0)); + }); + + testWidgets('Spacer takes up space proportional to flex.', (WidgetTester tester) async { + const Spacer spacer1 = Spacer(); + const Spacer spacer2 = Spacer(); + const Spacer spacer3 = Spacer(flex: 2); + const Spacer spacer4 = Spacer(flex: 4); + await tester.pumpWidget(const Row( + textDirection: TextDirection.rtl, + children: <Widget>[ + SizedBox(width: 10.0, height: 10.0), + spacer1, + SizedBox(width: 10.0, height: 10.0), + spacer2, + SizedBox(width: 10.0, height: 10.0), + spacer3, + SizedBox(width: 10.0, height: 10.0), + spacer4, + SizedBox(width: 10.0, height: 10.0), + ], + )); + final Rect spacer1Rect = tester.getRect(find.byType(Spacer).at(0)); + final Rect spacer2Rect = tester.getRect(find.byType(Spacer).at(1)); + final Rect spacer3Rect = tester.getRect(find.byType(Spacer).at(2)); + final Rect spacer4Rect = tester.getRect(find.byType(Spacer).at(3)); + expect(spacer1Rect.size.height, 0.0); + expect(spacer1Rect.size.width, moreOrLessEquals(93.8, epsilon: 0.1)); + expect(spacer1Rect.left, moreOrLessEquals(696.3, epsilon: 0.1)); + expect(spacer2Rect.size.width, moreOrLessEquals(93.8, epsilon: 0.1)); + expect(spacer2Rect.left, moreOrLessEquals(592.5, epsilon: 0.1)); + expect(spacer3Rect.size.width, spacer2Rect.size.width * 2.0); + expect(spacer3Rect.left, moreOrLessEquals(395.0, epsilon: 0.1)); + expect(spacer4Rect.size.width, spacer3Rect.size.width * 2.0); + expect(spacer4Rect.left, moreOrLessEquals(10.0, epsilon: 0.1)); + }); + + testWidgets('Spacer takes up space.', (WidgetTester tester) async { + await tester.pumpWidget(const UnconstrainedBox( + constrainedAxis: Axis.vertical, + child: Column( + children: <Widget>[ + SizedBox(width: 20.0, height: 10.0), + Spacer(), + SizedBox(width: 10.0, height: 10.0), + ], + ), + )); + final Rect spacerRect = tester.getRect(find.byType(Spacer)); + final Rect flexRect = tester.getRect(find.byType(Column)); + expect(spacerRect.size, const Size(0.0, 580.0)); + expect(spacerRect.topLeft, const Offset(400.0, 10.0)); + expect(flexRect, const Rect.fromLTWH(390.0, 0.0, 20.0, 600.0)); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/spell_check_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/spell_check_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..f9b89dcde36b88150efa16cef449542e222dfb3d --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/spell_check_test.dart @@ -0,0 +1,356 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; + +late TextStyle composingStyle; +late TextStyle misspelledTextStyle; + +void main() { + setUp(() { + composingStyle = const TextStyle(decoration: TextDecoration.underline); + + // Using Android handling for testing. + misspelledTextStyle = TextField.materialMisspelledTextStyle; + }); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions ignores composing region when composing region out of range', + (WidgetTester tester) async { + const String text = 'Hello, wrold! Hey'; + const TextEditingValue value = TextEditingValue(text: text); + const bool composingRegionOutOfRange = true; + const SpellCheckResults spellCheckResults = + SpellCheckResults(text, <SuggestionSpan>[ + SuggestionSpan( + TextRange(start: 7, end: 12), <String>['world', 'word', 'old']) + ]); + + final TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + const TextSpan(text: 'Hello, '), + TextSpan(style: misspelledTextStyle, text: 'wrold'), + const TextSpan(text: '! Hey') + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS })); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions, isolated misspelled word with separate composing region example', + (WidgetTester tester) async { + const String text = 'Hello, wrold! Hey'; + const TextEditingValue value = TextEditingValue( + text: text, composing: TextRange(start: 14, end: 17)); + const bool composingRegionOutOfRange = false; + const SpellCheckResults spellCheckResults = + SpellCheckResults(text, <SuggestionSpan>[ + SuggestionSpan( + TextRange(start: 7, end: 12), <String>['world', 'word', 'old']) + ]); + + final TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + const TextSpan(text: 'Hello, '), + TextSpan(style: misspelledTextStyle, text: 'wrold'), + const TextSpan(text: '! '), + TextSpan(style: composingStyle, text: 'Hey') + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android })); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions, composing region and misspelled words overlap example', + (WidgetTester tester) async { + const String text = 'Right worng worng right'; + const TextEditingValue value = TextEditingValue( + text: text, composing: TextRange(start: 12, end: 17)); + const bool composingRegionOutOfRange = false; + const SpellCheckResults spellCheckResults = + SpellCheckResults(text, <SuggestionSpan>[ + SuggestionSpan( + TextRange(start: 6, end: 11), <String>['wrong', 'worn', 'wrung']), + SuggestionSpan( + TextRange(start: 12, end: 17), <String>['wrong', 'worn', 'wrung']) + ]); + + final TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + const TextSpan(text: 'Right '), + TextSpan(style: misspelledTextStyle, text: 'worng'), + const TextSpan(text: ' '), + TextSpan(style: composingStyle, text: 'worng'), + const TextSpan(text: ' right'), + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android })); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions, consecutive misspelled words example', + (WidgetTester tester) async { + const String text = 'Right worng worng right'; + const TextEditingValue value = TextEditingValue(text: text); + const bool composingRegionOutOfRange = true; + const SpellCheckResults spellCheckResults = + SpellCheckResults(text, <SuggestionSpan>[ + SuggestionSpan( + TextRange(start: 6, end: 11), <String>['wrong', 'worn', 'wrung']), + SuggestionSpan( + TextRange(start: 12, end: 17), <String>['wrong', 'worn', 'wrung']) + ]); + + final TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + const TextSpan(text: 'Right '), + TextSpan(style: misspelledTextStyle, text: 'worng'), + const TextSpan(text: ' '), + TextSpan(style: misspelledTextStyle, text: 'worng'), + const TextSpan(text: ' right'), + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS })); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results text shorter than actual text example', + (WidgetTester tester) async { + const String text = 'Hello, wrold! Hey'; + const String resultsText = 'Hello, wrold!'; + const TextEditingValue value = TextEditingValue(text: text); + const bool composingRegionOutOfRange = false; + const SpellCheckResults spellCheckResults = + SpellCheckResults(resultsText, <SuggestionSpan>[ + SuggestionSpan( + TextRange(start: 7, end: 12), <String>['world', 'word', 'old']) + ]); + + final TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + const TextSpan(text: 'Hello, '), + TextSpan(style: misspelledTextStyle, text: 'wrold'), + const TextSpan(text: '! Hey'), + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS })); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results text longer with more misspelled words than actual text example', + (WidgetTester tester) async { + const String text = 'Hello, wrold! Hey'; + const String resultsText = 'Hello, wrold Hey feirnd!'; + const TextEditingValue value = TextEditingValue(text: text); + const bool composingRegionOutOfRange = false; + const SpellCheckResults spellCheckResults = + SpellCheckResults(resultsText, <SuggestionSpan>[ + SuggestionSpan( + TextRange(start: 7, end: 12), <String>['world', 'word', 'old']), + SuggestionSpan( + TextRange(start: 17, end: 23), <String>['friend', 'fiend', 'fern']) + ]); + + final TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + const TextSpan(text: 'Hello, '), + TextSpan(style: misspelledTextStyle, text: 'wrold'), + const TextSpan(text: '! Hey'), + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS })); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results text mismatched example', + (WidgetTester tester) async { + const String text = 'Hello, wrold! Hey'; + const String resultsText = 'Hello, wrild! Hey'; + const TextEditingValue value = TextEditingValue(text: text); + const bool composingRegionOutOfRange = false; + const SpellCheckResults spellCheckResults = + SpellCheckResults(resultsText, <SuggestionSpan>[ + SuggestionSpan(TextRange(start: 7, end: 12), <String>['wild', 'world']), + ]); + + const TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + TextSpan(text: 'Hello, wrold! Hey'), + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS })); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results shifted forward example', + (WidgetTester tester) async { + const String text = 'Hello, there wrold! Hey'; + const String resultsText = 'Hello, wrold! Hey'; + const TextEditingValue value = TextEditingValue(text: text); + const bool composingRegionOutOfRange = false; + const SpellCheckResults spellCheckResults = + SpellCheckResults(resultsText, <SuggestionSpan>[ + SuggestionSpan( + TextRange(start: 7, end: 12), <String>['world', 'word', 'old']), + ]); + + final TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + const TextSpan(text: 'Hello, there '), + TextSpan(style: misspelledTextStyle, text: 'wrold'), + const TextSpan(text: '! Hey'), + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS })); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results shifted backwards example', + (WidgetTester tester) async { + const String text = 'Hello, wrold! Hey'; + const String resultsText = 'Hello, great wrold! Hey'; + const TextEditingValue value = TextEditingValue(text: text); + const bool composingRegionOutOfRange = false; + const SpellCheckResults spellCheckResults = + SpellCheckResults(resultsText, <SuggestionSpan>[ + SuggestionSpan( + TextRange(start: 13, end: 18), <String>['world', 'word', 'old']), + ]); + + final TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + const TextSpan(text: 'Hello, '), + TextSpan(style: misspelledTextStyle, text: 'wrold'), + const TextSpan(text: '! Hey'), + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS })); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results shifted backwards and forwards example', + (WidgetTester tester) async { + const String text = 'Hello, wrold! And Hye!'; + const String resultsText = 'Hello, great wrold! Hye!'; + const TextEditingValue value = TextEditingValue(text: text); + const bool composingRegionOutOfRange = false; + const SpellCheckResults spellCheckResults = + SpellCheckResults(resultsText, <SuggestionSpan>[ + SuggestionSpan( + TextRange(start: 13, end: 18), <String>['world', 'word', 'old']), + SuggestionSpan(TextRange(start: 20, end: 23), <String>['Hey', 'He']) + ]); + + final TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + const TextSpan(text: 'Hello, '), + TextSpan(style: misspelledTextStyle, text: 'wrold'), + const TextSpan(text: '! And '), + TextSpan(style: misspelledTextStyle, text: 'Hye'), + const TextSpan(text: '!') + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS })); + + testWidgets( + 'buildTextSpanWithSpellCheckSuggestions discards result when additions are made to misspelled word example', + (WidgetTester tester) async { + const String text = 'Hello, wroldd!'; + const String resultsText = 'Hello, wrold!'; + const TextEditingValue value = TextEditingValue(text: text); + const bool composingRegionOutOfRange = false; + const SpellCheckResults spellCheckResults = + SpellCheckResults(resultsText, <SuggestionSpan>[ + SuggestionSpan( + TextRange(start: 7, end: 12), <String>['world', 'word', 'old']), + ]); + + const TextSpan expectedTextSpanTree = TextSpan(children: <TextSpan>[ + TextSpan(text: 'Hello, wroldd!'), + ]); + final TextSpan textSpanTree = + buildTextSpanWithSpellCheckSuggestions( + value, + composingRegionOutOfRange, + null, + misspelledTextStyle, + spellCheckResults, + ); + + expect(textSpanTree, equals(expectedTextSpanTree)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS })); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/stack_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/stack_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..cd3174f5037ef80ea86f909c4ff2b13d59ada535 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/stack_test.dart @@ -0,0 +1,960 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../rendering/rendering_tester.dart' show TestCallbackPainter; + +class TestPaintingContext implements PaintingContext { + final List<Invocation> invocations = <Invocation>[]; + + @override + void noSuchMethod(Invocation invocation) { + invocations.add(invocation); + } +} + +void main() { + testWidgets('Can construct an empty Stack', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack(), + ), + ); + }); + + testWidgets('Can construct an empty Centered Stack', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center(child: Stack()), + ), + ); + }); + + testWidgets('Can change position data', (WidgetTester tester) async { + const Key key = Key('container'); + + await tester.pumpWidget( + const Stack( + alignment: Alignment.topLeft, + children: <Widget>[ + Positioned( + left: 10.0, + child: SizedBox( + key: key, + width: 10.0, + height: 10.0, + ), + ), + ], + ), + ); + + Element container; + StackParentData parentData; + + container = tester.element(find.byKey(key)); + parentData = container.renderObject!.parentData! as StackParentData; + expect(parentData.top, isNull); + expect(parentData.right, isNull); + expect(parentData.bottom, isNull); + expect(parentData.left, equals(10.0)); + expect(parentData.width, isNull); + expect(parentData.height, isNull); + + await tester.pumpWidget( + const Stack( + alignment: Alignment.topLeft, + children: <Widget>[ + Positioned( + right: 10.0, + child: SizedBox( + key: key, + width: 10.0, + height: 10.0, + ), + ), + ], + ), + ); + + container = tester.element(find.byKey(key)); + parentData = container.renderObject!.parentData! as StackParentData; + expect(parentData.top, isNull); + expect(parentData.right, equals(10.0)); + expect(parentData.bottom, isNull); + expect(parentData.left, isNull); + expect(parentData.width, isNull); + expect(parentData.height, isNull); + }); + + testWidgets('Can remove parent data', (WidgetTester tester) async { + const Key key = Key('container'); + const SizedBox sizedBox = SizedBox(key: key, width: 10.0, height: 10.0); + + await tester.pumpWidget( + const Stack( + textDirection: TextDirection.ltr, + children: <Widget>[ Positioned(left: 10.0, child: sizedBox) ], + ), + ); + Element containerElement = tester.element(find.byKey(key)); + + StackParentData parentData; + parentData = containerElement.renderObject!.parentData! as StackParentData; + expect(parentData.top, isNull); + expect(parentData.right, isNull); + expect(parentData.bottom, isNull); + expect(parentData.left, equals(10.0)); + expect(parentData.width, isNull); + expect(parentData.height, isNull); + + await tester.pumpWidget( + const Stack( + textDirection: TextDirection.ltr, + children: <Widget>[ sizedBox ], + ), + ); + containerElement = tester.element(find.byKey(key)); + + parentData = containerElement.renderObject!.parentData! as StackParentData; + expect(parentData.top, isNull); + expect(parentData.right, isNull); + expect(parentData.bottom, isNull); + expect(parentData.left, isNull); + expect(parentData.width, isNull); + expect(parentData.height, isNull); + }); + + testWidgets('Can align non-positioned children (LTR)', (WidgetTester tester) async { + const Key child0Key = Key('child0'); + const Key child1Key = Key('child1'); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Stack( + alignment: Alignment.center, + children: <Widget>[ + SizedBox(key: child0Key, width: 20.0, height: 20.0), + SizedBox(key: child1Key, width: 10.0, height: 10.0), + ], + ), + ), + ), + ); + + final Element child0 = tester.element(find.byKey(child0Key)); + final StackParentData child0RenderObjectParentData = child0.renderObject!.parentData! as StackParentData; + expect(child0RenderObjectParentData.offset, equals(Offset.zero)); + + final Element child1 = tester.element(find.byKey(child1Key)); + final StackParentData child1RenderObjectParentData = child1.renderObject!.parentData! as StackParentData; + expect(child1RenderObjectParentData.offset, equals(const Offset(5.0, 5.0))); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Stack( + alignment: AlignmentDirectional.bottomEnd, + children: <Widget>[ + SizedBox(key: child0Key, width: 20.0, height: 20.0), + SizedBox(key: child1Key, width: 10.0, height: 10.0), + ], + ), + ), + ), + ); + + expect(child0RenderObjectParentData.offset, equals(Offset.zero)); + expect(child1RenderObjectParentData.offset, equals(const Offset(10.0, 10.0))); + }); + + testWidgets('Can align non-positioned children (RTL)', (WidgetTester tester) async { + const Key child0Key = Key('child0'); + const Key child1Key = Key('child1'); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.rtl, + child: Center( + child: Stack( + alignment: Alignment.center, + children: <Widget>[ + SizedBox(key: child0Key, width: 20.0, height: 20.0), + SizedBox(key: child1Key, width: 10.0, height: 10.0), + ], + ), + ), + ), + ); + + final Element child0 = tester.element(find.byKey(child0Key)); + final StackParentData child0RenderObjectParentData = child0.renderObject!.parentData! as StackParentData; + expect(child0RenderObjectParentData.offset, equals(Offset.zero)); + + final Element child1 = tester.element(find.byKey(child1Key)); + final StackParentData child1RenderObjectParentData = child1.renderObject!.parentData! as StackParentData; + expect(child1RenderObjectParentData.offset, equals(const Offset(5.0, 5.0))); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.rtl, + child: Center( + child: Stack( + alignment: AlignmentDirectional.bottomEnd, + children: <Widget>[ + SizedBox(key: child0Key, width: 20.0, height: 20.0), + SizedBox(key: child1Key, width: 10.0, height: 10.0), + ], + ), + ), + ), + ); + + expect(child0RenderObjectParentData.offset, equals(Offset.zero)); + expect(child1RenderObjectParentData.offset, equals(const Offset(0.0, 10.0))); + }); + + testWidgets('Can construct an empty IndexedStack', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: IndexedStack(), + ), + ); + }); + + testWidgets('Can construct an empty Centered IndexedStack', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center(child: IndexedStack()), + ), + ); + }); + + testWidgets('Can construct an IndexedStack', (WidgetTester tester) async { + const int itemCount = 3; + late List<int> itemsPainted; + + Widget buildFrame(int index) { + itemsPainted = <int>[]; + final List<Widget> items = List<Widget>.generate(itemCount, (int i) { + return CustomPaint( + painter: TestCallbackPainter( + onPaint: () { itemsPainted.add(i); }, + ), + child: Text('$i', textDirection: TextDirection.ltr), + ); + }); + return Center( + child: IndexedStack( + alignment: Alignment.topLeft, + index: index, + children: items, + ), + ); + } + + void expectFindsChild(int n) { + for (int i = 0; i < 3; i++) { + expect(find.text('$i', skipOffstage: false), findsOneWidget); + + if (i == n) { + expect(find.text('$i'), findsOneWidget); + } else { + expect(find.text('$i'), findsNothing); + } + } + } + + await tester.pumpWidget(buildFrame(0)); + expectFindsChild(0); + expect(itemsPainted, equals(<int>[0])); + + await tester.pumpWidget(buildFrame(1)); + expectFindsChild(1); + expect(itemsPainted, equals(<int>[1])); + + await tester.pumpWidget(buildFrame(2)); + expectFindsChild(2); + expect(itemsPainted, equals(<int>[2])); + }); + + testWidgets('Can hit test an IndexedStack', (WidgetTester tester) async { + const Key key = Key('indexedStack'); + const int itemCount = 3; + late List<int> itemsTapped; + + Widget buildFrame(int index) { + itemsTapped = <int>[]; + final List<Widget> items = List<Widget>.generate(itemCount, (int i) { + return GestureDetector(child: Text('$i', textDirection: TextDirection.ltr), onTap: () { itemsTapped.add(i); }); + }); + return Center( + child: IndexedStack( + alignment: Alignment.topLeft, + key: key, + index: index, + children: items, + ), + ); + } + + await tester.pumpWidget(buildFrame(0)); + expect(itemsTapped, isEmpty); + await tester.tap(find.byKey(key)); + expect(itemsTapped, <int>[0]); + + await tester.pumpWidget(buildFrame(2)); + expect(itemsTapped, isEmpty); + await tester.tap(find.byKey(key)); + expect(itemsTapped, <int>[2]); + }); + + testWidgets('IndexedStack sets non-selected indexes to visible=false', (WidgetTester tester) async { + Widget buildStack({required int itemCount, required int? selectedIndex}) { + final List<Widget> children = List<Widget>.generate(itemCount, (int i) { + return _ShowVisibility(index: i); + }); + return Directionality( + textDirection: TextDirection.ltr, + child: IndexedStack( + index: selectedIndex, + children: children, + ), + ); + } + + await tester.pumpWidget(buildStack(itemCount: 3, selectedIndex: null)); + expect(find.text('index 0 is visible ? false', skipOffstage: false), findsOneWidget); + expect(find.text('index 1 is visible ? false', skipOffstage: false), findsOneWidget); + expect(find.text('index 2 is visible ? false', skipOffstage: false), findsOneWidget); + + await tester.pumpWidget(buildStack(itemCount: 3, selectedIndex: 0)); + expect(find.text('index 0 is visible ? true', skipOffstage: false), findsOneWidget); + expect(find.text('index 1 is visible ? false', skipOffstage: false), findsOneWidget); + expect(find.text('index 2 is visible ? false', skipOffstage: false), findsOneWidget); + + await tester.pumpWidget(buildStack(itemCount: 3, selectedIndex: 1)); + expect(find.text('index 0 is visible ? false', skipOffstage: false), findsOneWidget); + expect(find.text('index 1 is visible ? true', skipOffstage: false), findsOneWidget); + expect(find.text('index 2 is visible ? false', skipOffstage: false), findsOneWidget); + + await tester.pumpWidget(buildStack(itemCount: 3, selectedIndex: 2)); + expect(find.text('index 0 is visible ? false', skipOffstage: false), findsOneWidget); + expect(find.text('index 1 is visible ? false', skipOffstage: false), findsOneWidget); + expect(find.text('index 2 is visible ? true', skipOffstage: false), findsOneWidget); + }); + + testWidgets('Can set width and height', (WidgetTester tester) async { + const Key key = Key('container'); + + const BoxDecoration kBoxDecoration = BoxDecoration( + color: Color(0xFF00FF00), + ); + + await tester.pumpWidget( + const Stack( + textDirection: TextDirection.ltr, + children: <Widget>[ + Positioned( + left: 10.0, + width: 11.0, + height: 12.0, + child: DecoratedBox(key: key, decoration: kBoxDecoration), + ), + ], + ), + ); + + Element box; + RenderBox renderBox; + StackParentData parentData; + + box = tester.element(find.byKey(key)); + renderBox = box.renderObject! as RenderBox; + parentData = renderBox.parentData! as StackParentData; + expect(parentData.top, isNull); + expect(parentData.right, isNull); + expect(parentData.bottom, isNull); + expect(parentData.left, equals(10.0)); + expect(parentData.width, equals(11.0)); + expect(parentData.height, equals(12.0)); + expect(parentData.offset.dx, equals(10.0)); + expect(parentData.offset.dy, equals(0.0)); + expect(renderBox.size.width, equals(11.0)); + expect(renderBox.size.height, equals(12.0)); + + await tester.pumpWidget( + const Stack( + textDirection: TextDirection.ltr, + children: <Widget>[ + Positioned( + right: 10.0, + width: 11.0, + height: 12.0, + child: DecoratedBox(key: key, decoration: kBoxDecoration), + ), + ], + ), + ); + + box = tester.element(find.byKey(key)); + renderBox = box.renderObject! as RenderBox; + parentData = renderBox.parentData! as StackParentData; + expect(parentData.top, isNull); + expect(parentData.right, equals(10.0)); + expect(parentData.bottom, isNull); + expect(parentData.left, isNull); + expect(parentData.width, equals(11.0)); + expect(parentData.height, equals(12.0)); + expect(parentData.offset.dx, equals(779.0)); + expect(parentData.offset.dy, equals(0.0)); + expect(renderBox.size.width, equals(11.0)); + expect(renderBox.size.height, equals(12.0)); + }); + + testWidgets('Can set and update clipBehavior', (WidgetTester tester) async { + await tester.pumpWidget(const Stack(textDirection: TextDirection.ltr)); + final RenderStack renderObject = tester.allRenderObjects.whereType<RenderStack>().first; + expect(renderObject.clipBehavior, equals(Clip.hardEdge)); + + await tester.pumpWidget(const Stack(textDirection: TextDirection.ltr)); + expect(renderObject.clipBehavior, equals(Clip.hardEdge)); + }); + + testWidgets('Clip.none is respected by describeApproximateClip', (WidgetTester tester) async { + await tester.pumpWidget(const Stack( + textDirection: TextDirection.ltr, + children: <Widget>[Positioned(left: 1000, right: 2000, child: SizedBox(width: 2000, height: 2000))], + )); + final RenderStack renderObject = tester.allRenderObjects.whereType<RenderStack>().first; + expect(renderObject.clipBehavior, equals(Clip.hardEdge)); + + bool visited = false; + renderObject.visitChildren((RenderObject child) { + visited = true; + expect(renderObject.describeApproximatePaintClip(child), const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0)); + }); + expect(visited, true); + visited = false; + renderObject.clipBehavior = Clip.none; + renderObject.visitChildren((RenderObject child) { + visited = true; + expect(renderObject.describeApproximatePaintClip(child), null); + }); + expect(visited, true); + }); + + testWidgets('IndexedStack with null index', (WidgetTester tester) async { + bool? tapped; + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: IndexedStack( + index: null, + children: <Widget>[ + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { tapped = true; }, + child: const SizedBox( + width: 200.0, + height: 200.0, + ), + ), + ], + ), + ), + ), + ); + + await tester.tap(find.byType(IndexedStack), warnIfMissed: false); + final RenderBox box = tester.renderObject(find.byType(IndexedStack)); + expect(box.size, equals(const Size(200.0, 200.0))); + expect(tapped, isNull); + }); + + testWidgets('IndexedStack reports hidden children as offstage', (WidgetTester tester) async { + final List<Widget> children = <Widget>[ + for (int i = 0; i < 5; i++) Text('child $i'), + ]; + + Future<void> pumpIndexedStack(int? activeIndex) async{ + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: IndexedStack( + index: activeIndex, + children: children, + ), + ) + ); + } + + final Finder finder = find.byType(Text); + final Finder finderIncludingOffstage = find.byType(Text, skipOffstage: false); + + await pumpIndexedStack(null); + expect(finder, findsNothing); // IndexedStack with null index shows nothing + expect(finderIncludingOffstage, findsNWidgets(5)); + + for (int i = 0; i < 5; i++) { + await pumpIndexedStack(i); + + expect(finder, findsOneWidget); + expect(finderIncludingOffstage, findsNWidgets(5)); + + expect(find.text('child $i'), findsOneWidget); + } + }); + + testWidgets('Stack clip test', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Stack( + children: <Widget>[ + SizedBox( + width: 100.0, + height: 100.0, + ), + Positioned( + top: 0.0, + left: 0.0, + child: SizedBox( + width: 200.0, + height: 200.0, + ), + ), + ], + ), + ), + ), + ); + + RenderBox box = tester.renderObject(find.byType(Stack)); + TestPaintingContext context = TestPaintingContext(); + box.paint(context, Offset.zero); + expect(context.invocations.first.memberName, equals(#pushClipRect)); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Stack( + clipBehavior: Clip.none, + children: <Widget>[ + SizedBox( + width: 100.0, + height: 100.0, + ), + Positioned( + top: 0.0, + left: 0.0, + child: SizedBox( + width: 200.0, + height: 200.0, + ), + ), + ], + ), + ), + ), + ); + + box = tester.renderObject(find.byType(Stack)); + context = TestPaintingContext(); + box.paint(context, Offset.zero); + expect(context.invocations.first.memberName, equals(#paintChild)); + }); + + testWidgets('Stack sizing: default', (WidgetTester tester) async { + final List<String> logs = <String>[]; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: ConstrainedBox( + constraints: const BoxConstraints( + minWidth: 2.0, + maxWidth: 3.0, + minHeight: 5.0, + maxHeight: 7.0, + ), + child: Stack( + children: <Widget>[ + LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + logs.add(constraints.toString()); + return const Placeholder(); + }, + ), + ], + ), + ), + ), + ), + ); + expect(logs, <String>['BoxConstraints(0.0<=w<=3.0, 0.0<=h<=7.0)']); + }); + + testWidgets('Stack sizing: explicit', (WidgetTester tester) async { + final List<String> logs = <String>[]; + Widget buildStack(StackFit sizing) { + return Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: ConstrainedBox( + constraints: const BoxConstraints( + minWidth: 2.0, + maxWidth: 3.0, + minHeight: 5.0, + maxHeight: 7.0, + ), + child: Stack( + fit: sizing, + children: <Widget>[ + LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + logs.add(constraints.toString()); + return const Placeholder(); + }, + ), + ], + ), + ), + ), + ); + } + await tester.pumpWidget(buildStack(StackFit.loose)); + logs.add('=1='); + await tester.pumpWidget(buildStack(StackFit.expand)); + logs.add('=2='); + await tester.pumpWidget(buildStack(StackFit.passthrough)); + expect(logs, <String>[ + 'BoxConstraints(0.0<=w<=3.0, 0.0<=h<=7.0)', + '=1=', + 'BoxConstraints(w=3.0, h=7.0)', + '=2=', + 'BoxConstraints(2.0<=w<=3.0, 5.0<=h<=7.0)', + ]); + }); + + testWidgets('Positioned.directional control test', (WidgetTester tester) async { + final Key key = UniqueKey(); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Positioned.directional( + textDirection: TextDirection.rtl, + start: 50.0, + child: SizedBox(key: key, width: 75.0, height: 175.0), + ), + ], + ), + ), + ); + + expect(tester.getTopLeft(find.byKey(key)), const Offset(675.0, 0.0)); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Positioned.directional( + textDirection: TextDirection.ltr, + start: 50.0, + child: SizedBox(key: key, width: 75.0, height: 175.0), + ), + ], + ), + ), + ); + + expect(tester.getTopLeft(find.byKey(key)), const Offset(50.0, 0.0)); + }); + + testWidgets('PositionedDirectional control test', (WidgetTester tester) async { + final Key key = UniqueKey(); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.rtl, + child: Stack( + children: <Widget>[ + PositionedDirectional( + start: 50.0, + child: SizedBox(key: key, width: 75.0, height: 175.0), + ), + ], + ), + ), + ); + + expect(tester.getTopLeft(find.byKey(key)), const Offset(675.0, 0.0)); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + PositionedDirectional( + start: 50.0, + child: SizedBox(key: key, width: 75.0, height: 175.0), + ), + ], + ), + ), + ); + + expect(tester.getTopLeft(find.byKey(key)), const Offset(50.0, 0.0)); + }); + + testWidgets('Can change the text direction of a Stack', (WidgetTester tester) async { + await tester.pumpWidget( + const Stack( + alignment: Alignment.center, + ), + ); + await tester.pumpWidget( + const Stack( + textDirection: TextDirection.rtl, + ), + ); + await tester.pumpWidget( + const Stack( + alignment: Alignment.center, + ), + ); + }); + + testWidgets('Alignment with partially-positioned children', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.rtl, + child: Stack( + alignment: Alignment.center, + children: <Widget>[ + SizedBox(width: 100.0, height: 100.0), + Positioned(left: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(right: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(start: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(end: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + ], + ), + ), + ); + expect(tester.getRect(find.byType(SizedBox).at(0)), const Rect.fromLTWH(350.0, 250.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(1)), const Rect.fromLTWH(0.0, 250.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(2)), const Rect.fromLTWH(700.0, 250.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(3)), const Rect.fromLTWH(350.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(4)), const Rect.fromLTWH(350.0, 500.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(5)), const Rect.fromLTWH(700.0, 250.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(6)), const Rect.fromLTWH(0.0, 250.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(7)), const Rect.fromLTWH(350.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(8)), const Rect.fromLTWH(350.0, 500.0, 100.0, 100.0)); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + alignment: Alignment.center, + children: <Widget>[ + SizedBox(width: 100.0, height: 100.0), + Positioned(left: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(right: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(start: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(end: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + ], + ), + ), + ); + expect(tester.getRect(find.byType(SizedBox).at(0)), const Rect.fromLTWH(350.0, 250.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(1)), const Rect.fromLTWH(0.0, 250.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(2)), const Rect.fromLTWH(700.0, 250.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(3)), const Rect.fromLTWH(350.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(4)), const Rect.fromLTWH(350.0, 500.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(5)), const Rect.fromLTWH(0.0, 250.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(6)), const Rect.fromLTWH(700.0, 250.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(7)), const Rect.fromLTWH(350.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(8)), const Rect.fromLTWH(350.0, 500.0, 100.0, 100.0)); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + alignment: Alignment.bottomRight, + children: <Widget>[ + SizedBox(width: 100.0, height: 100.0), + Positioned(left: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(right: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(start: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(end: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + ], + ), + ), + ); + expect(tester.getRect(find.byType(SizedBox).at(0)), const Rect.fromLTWH(700.0, 500.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(1)), const Rect.fromLTWH(0.0, 500.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(2)), const Rect.fromLTWH(700.0, 500.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(3)), const Rect.fromLTWH(700.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(4)), const Rect.fromLTWH(700.0, 500.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(5)), const Rect.fromLTWH(0.0, 500.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(6)), const Rect.fromLTWH(700.0, 500.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(7)), const Rect.fromLTWH(700.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(8)), const Rect.fromLTWH(700.0, 500.0, 100.0, 100.0)); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + alignment: Alignment.topLeft, + children: <Widget>[ + SizedBox(width: 100.0, height: 100.0), + Positioned(left: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(right: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + Positioned(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(start: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(end: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(top: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + PositionedDirectional(bottom: 0.0, child: SizedBox(width: 100.0, height: 100.0)), + ], + ), + ), + ); + expect(tester.getRect(find.byType(SizedBox).at(0)), const Rect.fromLTWH(0.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(1)), const Rect.fromLTWH(0.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(2)), const Rect.fromLTWH(700.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(3)), const Rect.fromLTWH(0.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(4)), const Rect.fromLTWH(0.0, 500.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(5)), const Rect.fromLTWH(0.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(6)), const Rect.fromLTWH(700.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(7)), const Rect.fromLTWH(0.0, 0.0, 100.0, 100.0)); + expect(tester.getRect(find.byType(SizedBox).at(8)), const Rect.fromLTWH(0.0, 500.0, 100.0, 100.0)); + }); + + testWidgets('Stack error messages', (WidgetTester tester) async { + await tester.pumpWidget( + const Stack(), + ); + final String exception = tester.takeException().toString(); + + expect( + exception, startsWith( + 'No Directionality widget found.\n' + "Stack widgets require a Directionality widget ancestor to resolve the 'alignment' argument.\n" + "The default value for 'alignment' is AlignmentDirectional.topStart, which requires a text direction.\n" + 'The specific widget that could not find a Directionality ancestor was:\n' + ' Stack\n' + 'The ownership chain for the affected widget is: "Stack ← ', // Omitted full ownership chain because it is not relevant for the test. + )); + expect( + exception, endsWith( + '← [root]"\n' // End of ownership chain. + 'Typically, the Directionality widget is introduced by the MaterialApp or WidgetsApp widget at the ' + 'top of your application widget tree. It determines the ambient reading direction and is used, for ' + 'example, to determine how to lay out text, how to interpret "start" and "end" values, and to resolve ' + 'EdgeInsetsDirectional, AlignmentDirectional, and other *Directional objects.\n' + 'Instead of providing a Directionality widget, another solution would be passing a non-directional ' + "'alignment', or an explicit 'textDirection', to the Stack.", + )); + }); + + testWidgets('Can update clipBehavior of IndexedStack', + (WidgetTester tester) async { + await tester.pumpWidget(const IndexedStack(textDirection: TextDirection.ltr)); + final RenderIndexedStack renderObject = + tester.renderObject<RenderIndexedStack>(find.byType(IndexedStack)); + expect(renderObject.clipBehavior, equals(Clip.hardEdge)); + + // Update clipBehavior to Clip.antiAlias + + await tester.pumpWidget(const IndexedStack( + textDirection: TextDirection.ltr, + clipBehavior: Clip.antiAlias, + )); + final RenderIndexedStack renderIndexedObject = + tester.renderObject<RenderIndexedStack>(find.byType(IndexedStack)); + expect(renderIndexedObject.clipBehavior, equals(Clip.antiAlias)); + }); + + testWidgets('IndexedStack sizing: explicit', (WidgetTester tester) async { + final List<String> logs = <String>[]; + Widget buildIndexedStack(StackFit sizing) { + return Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: ConstrainedBox( + constraints: const BoxConstraints( + minWidth: 2.0, + maxWidth: 3.0, + minHeight: 5.0, + maxHeight: 7.0, + ), + child: IndexedStack( + sizing: sizing, + children: <Widget>[ + LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + logs.add(constraints.toString()); + return const Placeholder(); + }, + ), + ], + ), + ), + ), + ); + } + await tester.pumpWidget(buildIndexedStack(StackFit.loose)); + logs.add('=1='); + await tester.pumpWidget(buildIndexedStack(StackFit.expand)); + logs.add('=2='); + await tester.pumpWidget(buildIndexedStack(StackFit.passthrough)); + expect(logs, <String>[ + 'BoxConstraints(0.0<=w<=3.0, 0.0<=h<=7.0)', + '=1=', + 'BoxConstraints(w=3.0, h=7.0)', + '=2=', + 'BoxConstraints(2.0<=w<=3.0, 5.0<=h<=7.0)', + ]); + }); +} + +class _ShowVisibility extends StatelessWidget { + const _ShowVisibility({required this.index}); + + final int index; + + @override + Widget build(BuildContext context) { + return Text('index $index is visible ? ${Visibility.of(context)}'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..06a7dfd890ae67bd40c02c2b98127788cd2f8703 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart @@ -0,0 +1,102 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class Foo extends StatefulWidget { + const Foo({ super.key }); + @override + FooState createState() => FooState(); +} + +class FooState extends State<Foo> { + final ScrollController scrollController = ScrollController(); + + @override + void dispose() { + scrollController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return ScrollConfiguration( + behavior: const FooScrollBehavior(), + child: ListView( + controller: scrollController, + children: <Widget>[ + GestureDetector( + onTap: () { + setState(() { /* this is needed to trigger the original bug this is regression-testing */ }); + scrollController.animateTo(200.0, duration: const Duration(milliseconds: 500), curve: Curves.linear); + }, + child: const DecoratedBox( + decoration: BoxDecoration(color: Color(0x00000000)), + child: SizedBox( + height: 200.0, + ), + ), + ), + const DecoratedBox( + decoration: BoxDecoration(color: Color(0x00000000)), + child: SizedBox( + height: 200.0, + ), + ), + const DecoratedBox( + decoration: BoxDecoration(color: Color(0x00000000)), + child: SizedBox( + height: 200.0, + ), + ), + const DecoratedBox( + decoration: BoxDecoration(color: Color(0x00000000)), + child: SizedBox( + height: 200.0, + ), + ), + const DecoratedBox( + decoration: BoxDecoration(color: Color(0x00000000)), + child: SizedBox( + height: 200.0, + ), + ), + const DecoratedBox( + decoration: BoxDecoration(color: Color(0x00000000)), + child: SizedBox( + height: 200.0, + ), + ), + ], + ), + ); + }, + ); + } +} + +class FooScrollBehavior extends ScrollBehavior { + const FooScrollBehavior(); + + @override + bool shouldNotify(FooScrollBehavior old) => true; +} + +void main() { + testWidgets('Can animate scroll after setState', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Foo(), + ), + ); + expect(tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels, 0.0); + await tester.tap(find.byType(GestureDetector).first); + await tester.pumpAndSettle(); + expect(tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels, 200.0); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/stateful_component_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/stateful_component_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..078e30f0cd6fd1bbc33b011d44bb8592c347175e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/stateful_component_test.dart @@ -0,0 +1,74 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'test_widgets.dart'; + +void main() { + testWidgets('Stateful widget smoke test', (WidgetTester tester) async { + void checkTree(BoxDecoration expectedDecoration) { + final SingleChildRenderObjectElement element = tester.element( + find.byElementPredicate((Element element) => element is SingleChildRenderObjectElement && element.renderObject is! RenderView), + ); + expect(element, isNotNull); + expect(element.renderObject, isA<RenderDecoratedBox>()); + final RenderDecoratedBox renderObject = element.renderObject as RenderDecoratedBox; + expect(renderObject.decoration, equals(expectedDecoration)); + } + + await tester.pumpWidget( + const FlipWidget( + left: DecoratedBox(decoration: kBoxDecorationA), + right: DecoratedBox(decoration: kBoxDecorationB), + ), + ); + + checkTree(kBoxDecorationA); + + await tester.pumpWidget( + const FlipWidget( + left: DecoratedBox(decoration: kBoxDecorationB), + right: DecoratedBox(decoration: kBoxDecorationA), + ), + ); + + checkTree(kBoxDecorationB); + + flipStatefulWidget(tester); + + await tester.pump(); + + checkTree(kBoxDecorationA); + + await tester.pumpWidget( + const FlipWidget( + left: DecoratedBox(decoration: kBoxDecorationA), + right: DecoratedBox(decoration: kBoxDecorationB), + ), + ); + + checkTree(kBoxDecorationB); + }); + + testWidgets("Don't rebuild subwidgets", (WidgetTester tester) async { + await tester.pumpWidget( + const FlipWidget( + key: Key('rebuild test'), + left: TestBuildCounter(), + right: DecoratedBox(decoration: kBoxDecorationB), + ), + ); + + expect(TestBuildCounter.buildCount, equals(1)); + + flipStatefulWidget(tester); + + await tester.pump(); + + expect(TestBuildCounter.buildCount, equals(1)); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/stateful_components_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/stateful_components_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..13f5a6ac7fd610890f118d38578f2451bb779ed5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/stateful_components_test.dart @@ -0,0 +1,86 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class InnerWidget extends StatefulWidget { + const InnerWidget({ super.key }); + + @override + InnerWidgetState createState() => InnerWidgetState(); +} + +class InnerWidgetState extends State<InnerWidget> { + bool _didInitState = false; + + @override + void initState() { + super.initState(); + _didInitState = true; + } + + @override + Widget build(BuildContext context) { + return Container(); + } +} + +class OuterContainer extends StatefulWidget { + const OuterContainer({ super.key, required this.child }); + + final InnerWidget child; + + @override + OuterContainerState createState() => OuterContainerState(); +} + +class OuterContainerState extends State<OuterContainer> { + @override + Widget build(BuildContext context) { + return widget.child; + } +} + +void main() { + testWidgets('resync stateful widget', (WidgetTester tester) async { + const Key innerKey = Key('inner'); + const Key outerKey = Key('outer'); + + const InnerWidget inner1 = InnerWidget(key: innerKey); + InnerWidget inner2; + const OuterContainer outer1 = OuterContainer(key: outerKey, child: inner1); + OuterContainer outer2; + + await tester.pumpWidget(outer1); + + final StatefulElement innerElement = tester.element(find.byKey(innerKey)); + final InnerWidgetState innerElementState = innerElement.state as InnerWidgetState; + expect(innerElementState.widget, equals(inner1)); + expect(innerElementState._didInitState, isTrue); + expect(innerElement.renderObject!.attached, isTrue); + + inner2 = const InnerWidget(key: innerKey); + outer2 = OuterContainer(key: outerKey, child: inner2); + + await tester.pumpWidget(outer2); + + expect(tester.element(find.byKey(innerKey)), equals(innerElement)); + expect(innerElement.state, equals(innerElementState)); + + expect(innerElementState.widget, equals(inner2)); + expect(innerElementState._didInitState, isTrue); + expect(innerElement.renderObject!.attached, isTrue); + + final StatefulElement outerElement = tester.element(find.byKey(outerKey)); + expect(outerElement.state.widget, equals(outer2)); + outerElement.markNeedsBuild(); + await tester.pump(); + + expect(tester.element(find.byKey(innerKey)), equals(innerElement)); + expect(innerElement.state, equals(innerElementState)); + expect(innerElementState.widget, equals(inner2)); + expect(innerElement.renderObject!.attached, isTrue); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/states.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/states.dart new file mode 100644 index 0000000000000000000000000000000000000000..02d38fea48a2d07fded4d5ab176b8a5ad2952c7e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/states.dart @@ -0,0 +1,56 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +const List<String> kStates = <String>[ + 'Alabama', + 'Alaska', + 'Arizona', + 'Arkansas', + 'California', + 'Colorado', + 'Connecticut', + 'Delaware', + 'Florida', + 'Georgia', + 'Hawaii', + 'Idaho', + 'Illinois', + 'Indiana', + 'Iowa', + 'Kansas', + 'Kentucky', + 'Louisiana', + 'Maine', + 'Maryland', + 'Massachusetts', + 'Michigan', + 'Minnesota', + 'Mississippi', + 'Missouri', + 'Montana', + 'Nebraska', + 'Nevada', + 'New Hampshire', + 'New Jersey', + 'New Mexico', + 'New York', + 'North Carolina', + 'North Dakota', + 'Ohio', + 'Oklahoma', + 'Oregon', + 'Pennsylvania', + 'Rhode Island', + 'South Carolina', + 'South Dakota', + 'Tennessee', + 'Texas', + 'Utah', + 'Vermont', + 'Virginia', + 'Washington', + 'West Virginia', + 'Wisconsin', + 'Wyoming', +]; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/status_transitions_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/status_transitions_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..581bfd15ac3d29770c8d295926e620ba84993291 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/status_transitions_test.dart @@ -0,0 +1,90 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class TestStatusTransitionWidget extends StatusTransitionWidget { + const TestStatusTransitionWidget({ + super.key, + required this.builder, + required super.animation, + }); + + final WidgetBuilder builder; + + @override + Widget build(BuildContext context) => builder(context); +} + +void main() { + testWidgets('Status transition control test', (WidgetTester tester) async { + bool didBuild = false; + final AnimationController controller = AnimationController( + duration: const Duration(seconds: 1), + vsync: const TestVSync(), + ); + addTearDown(controller.dispose); + + await tester.pumpWidget(TestStatusTransitionWidget( + animation: controller, + builder: (BuildContext context) { + expect(didBuild, isFalse); + didBuild = true; + return Container(); + }, + )); + + expect(didBuild, isTrue); + didBuild = false; + + controller.forward(); + + expect(didBuild, isFalse); + await tester.pump(); + expect(didBuild, isTrue); + didBuild = false; + await tester.pump(const Duration(milliseconds: 100)); + expect(didBuild, isFalse); + await tester.pump(const Duration(milliseconds: 850)); + expect(didBuild, isFalse); + await tester.pump(const Duration(milliseconds: 100)); + expect(didBuild, isTrue); + didBuild = false; + controller.forward(); + await tester.pump(const Duration(milliseconds: 100)); + expect(didBuild, isFalse); + controller.stop(); + await tester.pump(const Duration(milliseconds: 100)); + expect(didBuild, isFalse); + + final AnimationController anotherController = AnimationController( + duration: const Duration(seconds: 1), + vsync: const TestVSync(), + ); + addTearDown(anotherController.dispose); + + await tester.pumpWidget(TestStatusTransitionWidget( + animation: anotherController, + builder: (BuildContext context) { + expect(didBuild, isFalse); + didBuild = true; + return Container(); + }, + )); + + expect(didBuild, isTrue); + didBuild = false; + controller.reverse(); + await tester.pump(const Duration(milliseconds: 100)); + expect(didBuild, isFalse); + anotherController.forward(); + await tester.pump(const Duration(milliseconds: 100)); + expect(didBuild, isTrue); + didBuild = false; + + controller.stop(); + anotherController.stop(); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/syncing_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/syncing_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..84745ca07cd30b15028d962fc14367ca5fb53a84 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/syncing_test.dart @@ -0,0 +1,219 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class TestWidget extends StatefulWidget { + const TestWidget({ + super.key, + required this.child, + required this.persistentState, + required this.syncedState, + }); + + final Widget child; + final int persistentState; + final int syncedState; + + @override + TestWidgetState createState() => TestWidgetState(); +} + +class TestWidgetState extends State<TestWidget> { + late int persistentState; + late int syncedState; + int updates = 0; + + @override + void initState() { + super.initState(); + persistentState = widget.persistentState; + syncedState = widget.syncedState; + } + + @override + void didUpdateWidget(TestWidget oldWidget) { + super.didUpdateWidget(oldWidget); + syncedState = widget.syncedState; + // we explicitly do NOT sync the persistentState from the new instance + // because we're using that to track whether we got recreated + updates += 1; + } + + @override + Widget build(BuildContext context) => widget.child; +} + +void main() { + + testWidgets('no change', (WidgetTester tester) async { + await tester.pumpWidget( + ColoredBox( + color: Colors.blue, + child: ColoredBox( + color: Colors.blue, + child: TestWidget( + persistentState: 1, + syncedState: 0, + child: Container(), + ), + ), + ), + ); + + final TestWidgetState state = tester.state(find.byType(TestWidget)); + + expect(state.persistentState, equals(1)); + expect(state.updates, equals(0)); + + await tester.pumpWidget( + ColoredBox( + color: Colors.blue, + child: ColoredBox( + color: Colors.blue, + child: TestWidget( + persistentState: 2, + syncedState: 0, + child: Container(), + ), + ), + ), + ); + + expect(state.persistentState, equals(1)); + expect(state.updates, equals(1)); + + await tester.pumpWidget(Container()); + }); + + testWidgets('remove one', (WidgetTester tester) async { + await tester.pumpWidget( + ColoredBox( + color: Colors.blue, + child: ColoredBox( + color: Colors.blue, + child: TestWidget( + persistentState: 10, + syncedState: 0, + child: Container(), + ), + ), + ), + ); + + TestWidgetState state = tester.state(find.byType(TestWidget)); + + expect(state.persistentState, equals(10)); + expect(state.updates, equals(0)); + + await tester.pumpWidget( + ColoredBox( + color: Colors.green, + child: TestWidget( + persistentState: 11, + syncedState: 0, + child: Container(), + ), + ), + ); + + state = tester.state(find.byType(TestWidget)); + + expect(state.persistentState, equals(11)); + expect(state.updates, equals(0)); + + await tester.pumpWidget(Container()); + }); + + testWidgets('swap instances around', (WidgetTester tester) async { + const Widget a = TestWidget(persistentState: 0x61, syncedState: 0x41, child: Text('apple', textDirection: TextDirection.ltr)); + const Widget b = TestWidget(persistentState: 0x62, syncedState: 0x42, child: Text('banana', textDirection: TextDirection.ltr)); + await tester.pumpWidget(const Column()); + + final GlobalKey keyA = GlobalKey(); + final GlobalKey keyB = GlobalKey(); + + await tester.pumpWidget( + Column( + children: <Widget>[ + Container( + key: keyA, + child: a, + ), + Container( + key: keyB, + child: b, + ), + ], + ), + ); + + TestWidgetState first, second; + + first = tester.state(find.byWidget(a)); + second = tester.state(find.byWidget(b)); + + expect(first.widget, equals(a)); + expect(first.persistentState, equals(0x61)); + expect(first.syncedState, equals(0x41)); + expect(second.widget, equals(b)); + expect(second.persistentState, equals(0x62)); + expect(second.syncedState, equals(0x42)); + + await tester.pumpWidget( + Column( + children: <Widget>[ + Container( + key: keyA, + child: a, + ), + Container( + key: keyB, + child: b, + ), + ], + ), + ); + + first = tester.state(find.byWidget(a)); + second = tester.state(find.byWidget(b)); + + // same as before + expect(first.widget, equals(a)); + expect(first.persistentState, equals(0x61)); + expect(first.syncedState, equals(0x41)); + expect(second.widget, equals(b)); + expect(second.persistentState, equals(0x62)); + expect(second.syncedState, equals(0x42)); + + // now we swap the nodes over + // since they are both "old" nodes, they shouldn't sync with each other even though they look alike + + await tester.pumpWidget( + Column( + children: <Widget>[ + Container( + key: keyA, + child: b, + ), + Container( + key: keyB, + child: a, + ), + ], + ), + ); + + first = tester.state(find.byWidget(b)); + second = tester.state(find.byWidget(a)); + + expect(first.widget, equals(b)); + expect(first.persistentState, equals(0x61)); + expect(first.syncedState, equals(0x42)); + expect(second.widget, equals(a)); + expect(second.persistentState, equals(0x62)); + expect(second.syncedState, equals(0x41)); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/system_context_menu_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/system_context_menu_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..4f340185b6395cdbe8ab1e7fccec98e4b6b5f101 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/system_context_menu_test.dart @@ -0,0 +1,494 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; + +void main() { + final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('asserts when built on an unsupported device', (WidgetTester tester) async { + final TextEditingController controller = TextEditingController( + text: 'one two three', + ); + addTearDown(controller.dispose); + await tester.pumpWidget( + // By default, MediaQueryData.supportsShowingSystemContextMenu is false. + MaterialApp( + home: Scaffold( + body: Center( + child: TextField( + controller: controller, + contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) { + return SystemContextMenu.editableText( + editableTextState: editableTextState, + ); + }, + ), + ), + ), + ), + ); + + await tester.tap(find.byType(TextField)); + final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText)); + expect(state.showToolbar(), true); + await tester.pump(); + + expect(tester.takeException(), isAssertionError); + }, + skip: kIsWeb, // [intended] + variant: TargetPlatformVariant.all(), + ); + + testWidgets('asserts when built on web', (WidgetTester tester) async { + // Disable the browser context menu so that contextMenuBuilder will be used. + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler( + SystemChannels.contextMenu, + (MethodCall call) { + // Just complete successfully, so that BrowserContextMenu thinks that + // the engine successfully received its call. + return Future<void>.value(); + }, + ); + await BrowserContextMenu.disableContextMenu(); + addTearDown(() async { + await BrowserContextMenu.enableContextMenu(); + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.contextMenu, null); + }); + + final TextEditingController controller = TextEditingController( + text: 'one two three', + ); + addTearDown(controller.dispose); + await tester.pumpWidget( + // By default, MediaQueryData.supportsShowingSystemContextMenu is false. + MaterialApp( + home: Scaffold( + body: Center( + child: TextField( + controller: controller, + contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) { + return SystemContextMenu.editableText( + editableTextState: editableTextState, + ); + }, + ), + ), + ), + ), + ); + + await tester.tap(find.byType(TextField)); + final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText)); + expect(state.showToolbar(), true); + await tester.pump(); + + expect(tester.takeException(), isAssertionError); + }, + skip: !kIsWeb, // [intended] + variant: TargetPlatformVariant.only(TargetPlatform.iOS), + ); + + testWidgets('can be shown and hidden like a normal context menu', (WidgetTester tester) async { + final TextEditingController controller = TextEditingController( + text: 'one two three', + ); + addTearDown(controller.dispose); + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + final MediaQueryData mediaQueryData = MediaQuery.of(context); + return MediaQuery( + data: mediaQueryData.copyWith( + supportsShowingSystemContextMenu: true, + ), + child: MaterialApp( + home: Scaffold( + body: Center( + child: TextField( + controller: controller, + contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) { + return SystemContextMenu.editableText( + editableTextState: editableTextState, + ); + }, + ), + ), + ), + ), + ); + }, + ), + ); + + expect(find.byType(SystemContextMenu), findsNothing); + + await tester.tap(find.byType(TextField)); + final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText)); + expect(state.showToolbar(), true); + await tester.pump(); + expect(find.byType(SystemContextMenu), findsOneWidget); + + state.hideToolbar(); + await tester.pump(); + expect(find.byType(SystemContextMenu), findsNothing); + }, + skip: kIsWeb, // [intended] + variant: TargetPlatformVariant.only(TargetPlatform.iOS), + ); + + testWidgets('can be updated.', (WidgetTester tester) async { + final List<Map<String, double>> targetRects = <Map<String, double>>[]; + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(SystemChannels.platform, (MethodCall methodCall) async { + if (methodCall.method == 'ContextMenu.showSystemContextMenu') { + final Map<String, dynamic> arguments = methodCall.arguments as Map<String, dynamic>; + final Map<String, dynamic> untypedTargetRect = arguments['targetRect'] as Map<String, dynamic>; + final Map<String, double> lastTargetRect = untypedTargetRect.map((String key, dynamic value) { + return MapEntry<String, double>(key, value as double); + }); + targetRects.add(lastTargetRect); + } + return; + }); + addTearDown(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(SystemChannels.platform, null); + }); + + final TextEditingController controller = TextEditingController( + text: 'one two three', + ); + addTearDown(controller.dispose); + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + final MediaQueryData mediaQueryData = MediaQuery.of(context); + return MediaQuery( + data: mediaQueryData.copyWith( + supportsShowingSystemContextMenu: true, + ), + child: MaterialApp( + home: Scaffold( + body: Center( + child: TextField( + controller: controller, + contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) { + return SystemContextMenu.editableText( + editableTextState: editableTextState, + ); + }, + ), + ), + ), + ), + ); + }, + ), + ); + + expect(targetRects, isEmpty); + + await tester.tap(find.byType(TextField)); + final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText)); + expect(state.showToolbar(), true); + await tester.pump(); + + expect(targetRects, hasLength(1)); + expect(targetRects.last, containsPair('width', 0.0)); + + controller.selection = const TextSelection( + baseOffset: 4, + extentOffset: 7, + ); + await tester.pumpAndSettle(); + + expect(targetRects, hasLength(2)); + expect(targetRects.last['width'], greaterThan(0.0)); + }, + skip: kIsWeb, // [intended] + variant: TargetPlatformVariant.only(TargetPlatform.iOS), + ); + + testWidgets('can be rebuilt', (WidgetTester tester) async { + final TextEditingController controller = TextEditingController( + text: 'one two three', + ); + addTearDown(controller.dispose); + late StateSetter setState; + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + final MediaQueryData mediaQueryData = MediaQuery.of(context); + return MediaQuery( + data: mediaQueryData.copyWith( + supportsShowingSystemContextMenu: true, + ), + child: MaterialApp( + home: Scaffold( + body: Center( + child: StatefulBuilder( + builder: (BuildContext context, StateSetter localSetState) { + setState = localSetState; + return TextField( + controller: controller, + contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) { + return SystemContextMenu.editableText( + editableTextState: editableTextState, + ); + }, + ); + }, + ), + ), + ), + ), + ); + }, + ), + ); + + await tester.tap(find.byType(TextField)); + final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText)); + expect(state.showToolbar(), true); + await tester.pump(); + + setState(() {}); + await tester.pumpAndSettle(); + + expect(tester.takeException(), isNull); + }, + skip: kIsWeb, // [intended] + variant: TargetPlatformVariant.only(TargetPlatform.iOS), + ); + + testWidgets('can handle multiple instances', (WidgetTester tester) async { + final TextEditingController controller1 = TextEditingController( + text: 'one two three', + ); + addTearDown(controller1.dispose); + final TextEditingController controller2 = TextEditingController( + text: 'four five six', + ); + addTearDown(controller2.dispose); + final GlobalKey field1Key = GlobalKey(); + final GlobalKey field2Key = GlobalKey(); + final GlobalKey menu1Key = GlobalKey(); + final GlobalKey menu2Key = GlobalKey(); + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + final MediaQueryData mediaQueryData = MediaQuery.of(context); + return MediaQuery( + data: mediaQueryData.copyWith( + supportsShowingSystemContextMenu: true, + ), + child: MaterialApp( + home: Scaffold( + body: Center( + child: Column( + children: <Widget>[ + TextField( + key: field1Key, + controller: controller1, + contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) { + return SystemContextMenu.editableText( + key: menu1Key, + editableTextState: editableTextState, + ); + }, + ), + TextField( + key: field2Key, + controller: controller2, + contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) { + return SystemContextMenu.editableText( + key: menu2Key, + editableTextState: editableTextState, + ); + }, + ), + ], + ), + ), + ), + ), + ); + }, + ), + ); + + expect(find.byType(SystemContextMenu), findsNothing); + + await tester.tap(find.byKey(field1Key)); + final EditableTextState state1 = tester.state<EditableTextState>( + find.descendant( + of: find.byKey(field1Key), + matching: find.byType(EditableText), + ), + ); + expect(state1.showToolbar(), true); + await tester.pump(); + expect(find.byKey(menu1Key), findsOneWidget); + expect(find.byKey(menu2Key), findsNothing); + + // In a real app, this message is sent by iOS when the user taps anywhere + // outside of the system context menu. + final ByteData? messageBytes = const JSONMessageCodec().encodeMessage(<String, dynamic>{ + 'method': 'ContextMenu.onDismissSystemContextMenu', + }); + await binding.defaultBinaryMessenger.handlePlatformMessage( + 'flutter/platform', + messageBytes, + (ByteData? data) {}, + ); + await tester.pump(); + expect(find.byType(SystemContextMenu), findsNothing); + + await tester.tap(find.byKey(field2Key)); + final EditableTextState state2 = tester.state<EditableTextState>( + find.descendant( + of: find.byKey(field2Key), + matching: find.byType(EditableText), + ), + ); + expect(state2.showToolbar(), true); + await tester.pump(); + expect(find.byKey(menu1Key), findsNothing); + expect(find.byKey(menu2Key), findsOneWidget); + }, + skip: kIsWeb, // [intended] + variant: TargetPlatformVariant.only(TargetPlatform.iOS), + ); + + testWidgets('asserts when built with no text input connection', + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), // leaking by design because of exception + (WidgetTester tester) async { + SystemContextMenu? systemContextMenu; + late StateSetter setState; + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + final MediaQueryData mediaQueryData = MediaQuery.of(context); + return MediaQuery( + data: mediaQueryData.copyWith( + supportsShowingSystemContextMenu: true, + ), + child: MaterialApp( + home: Scaffold( + body: StatefulBuilder( + builder: (BuildContext context, StateSetter localSetState) { + setState = localSetState; + return Column( + children: <Widget>[ + const TextField(), + if (systemContextMenu != null) + systemContextMenu!, + ], + ); + }, + ), + ), + ), + ); + }, + ), + ); + + // No SystemContextMenu yet, so no assertion error. + expect(tester.takeException(), isNull); + + // Add the SystemContextMenu and receive an assertion since there is no + // active text input connection. + setState(() { + final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText)); + systemContextMenu = SystemContextMenu.editableText( + editableTextState: state, + ); + }); + + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + dynamic exception; + FlutterError.onError = (FlutterErrorDetails details) { + exception ??= details.exception; + }; + addTearDown(() { + FlutterError.onError = oldHandler; + }); + + await tester.pump(); + expect(exception, isAssertionError); + expect(exception.toString(), contains('only be shown for an active text input connection')); + }, + skip: kIsWeb, // [intended] + variant: TargetPlatformVariant.only(TargetPlatform.iOS), + ); + + testWidgets('does not assert when built with an active text input connection', (WidgetTester tester) async { + SystemContextMenu? systemContextMenu; + late StateSetter setState; + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + final MediaQueryData mediaQueryData = MediaQuery.of(context); + return MediaQuery( + data: mediaQueryData.copyWith( + supportsShowingSystemContextMenu: true, + ), + child: MaterialApp( + home: Scaffold( + body: StatefulBuilder( + builder: (BuildContext context, StateSetter localSetState) { + setState = localSetState; + return Column( + children: <Widget>[ + const TextField(), + if (systemContextMenu != null) + systemContextMenu!, + ], + ); + }, + ), + ), + ), + ); + }, + ), + ); + + // No SystemContextMenu yet, so no assertion error. + expect(tester.takeException(), isNull); + + // Tap the field to open a text input connection. + await tester.tap(find.byType(TextField)); + await tester.pump(); + + // Add the SystemContextMenu and expect no error. + setState(() { + final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText)); + systemContextMenu = SystemContextMenu.editableText( + editableTextState: state, + ); + }); + + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + dynamic exception; + FlutterError.onError = (FlutterErrorDetails details) { + exception ??= details.exception; + }; + addTearDown(() { + FlutterError.onError = oldHandler; + }); + + await tester.pump(); + expect(exception, isNull); + }, + skip: kIsWeb, // [intended] + variant: TargetPlatformVariant.only(TargetPlatform.iOS), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/table_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/table_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..3e7d813cfcb2eb28e6a24bba177d8018d30ecd5e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/table_test.dart @@ -0,0 +1,1125 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class TestStatefulWidget extends StatefulWidget { + const TestStatefulWidget({ super.key }); + + @override + TestStatefulWidgetState createState() => TestStatefulWidgetState(); +} + +class TestStatefulWidgetState extends State<TestStatefulWidget> { + @override + Widget build(BuildContext context) => Container(); +} + +class TestChildWidget extends StatefulWidget { + const TestChildWidget({ super.key }); + + @override + TestChildState createState() => TestChildState(); +} + +class TestChildState extends State<TestChildWidget> { + bool toggle = true; + + void toggleMe() { + setState(() { toggle = !toggle; }); + } + + @override + Widget build(BuildContext context) => toggle ? const SizedBox() : const Text('CRASHHH'); +} + +void main() { + testWidgets('Table widget - empty', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table(), + ), + ); + }); + + testWidgets('Table widget - control test', (WidgetTester tester) async { + Future<void> run(TextDirection textDirection) async { + await tester.pumpWidget( + Directionality( + textDirection: textDirection, + child: Table( + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('AAAAAA'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('EEE'), Text('F'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('III'), + ], + ), + ], + ), + ), + ); + final RenderBox boxA = tester.renderObject(find.text('AAAAAA')); + final RenderBox boxD = tester.renderObject(find.text('D')); + final RenderBox boxG = tester.renderObject(find.text('G')); + final RenderBox boxB = tester.renderObject(find.text('B')); + expect(boxA.size, equals(boxD.size)); + expect(boxA.size, equals(boxG.size)); + expect(boxA.size, equals(boxB.size)); + } + + await run(TextDirection.ltr); + await tester.pumpWidget(Container()); + await run(TextDirection.rtl); + }); + + testWidgets('Table widget can be detached and re-attached', (WidgetTester tester) async { + final Widget table = Table( + key: GlobalKey(), + children: const <TableRow>[ + TableRow( + decoration: BoxDecoration( + color: Colors.yellow, + ), + children: <Widget>[Placeholder()], + ), + ], + ); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: table, + ), + ), + ); + // Move table to a different location to simulate detaching and re-attaching effect. + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Center( + child: table, + ), + ), + ), + ); + + expect(tester.takeException(), isNull); + }); + + testWidgets('Table widget - column offset (LTR)', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Table( + columnWidths: const <int, TableColumnWidth>{ + 0: FixedColumnWidth(100.0), + 1: FixedColumnWidth(110.0), + 2: FixedColumnWidth(125.0), + }, + defaultColumnWidth: const FixedColumnWidth(333.0), + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('A1'), Text('B1'), Text('C1'), + ], + ), + TableRow( + children: <Widget>[ + Text('A2'), Text('B2'), Text('C2'), + ], + ), + TableRow( + children: <Widget>[ + Text('A3'), Text('B3'), Text('C3'), + ], + ), + ], + ), + ), + ), + ); + + final Rect table = tester.getRect(find.byType(Table)); + final Rect a1 = tester.getRect(find.text('A1')); + final Rect a2 = tester.getRect(find.text('A2')); + final Rect a3 = tester.getRect(find.text('A3')); + final Rect b1 = tester.getRect(find.text('B1')); + final Rect b2 = tester.getRect(find.text('B2')); + final Rect b3 = tester.getRect(find.text('B3')); + final Rect c1 = tester.getRect(find.text('C1')); + final Rect c2 = tester.getRect(find.text('C2')); + final Rect c3 = tester.getRect(find.text('C3')); + + expect(a1.width, equals(100.0)); + expect(a2.width, equals(100.0)); + expect(a3.width, equals(100.0)); + expect(b1.width, equals(110.0)); + expect(b2.width, equals(110.0)); + expect(b3.width, equals(110.0)); + expect(c1.width, equals(125.0)); + expect(c2.width, equals(125.0)); + expect(c3.width, equals(125.0)); + + expect(table.width, equals(335.0)); + + expect(a1.left, equals(table.left)); + expect(a2.left, equals(a1.left)); + expect(a3.left, equals(a1.left)); + + expect(b1.left, equals(table.left + a1.width)); + expect(b2.left, equals(b1.left)); + expect(b3.left, equals(b1.left)); + + expect(c1.left, equals(table.left + a1.width + b1.width)); + expect(c2.left, equals(c1.left)); + expect(c3.left, equals(c1.left)); + }); + + testWidgets('Table widget - column offset (RTL)', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.rtl, + child: Center( + child: Table( + columnWidths: const <int, TableColumnWidth>{ + 0: FixedColumnWidth(100.0), + 1: FixedColumnWidth(110.0), + 2: FixedColumnWidth(125.0), + }, + defaultColumnWidth: const FixedColumnWidth(333.0), + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('A1'), Text('B1'), Text('C1'), + ], + ), + TableRow( + children: <Widget>[ + Text('A2'), Text('B2'), Text('C2'), + ], + ), + TableRow( + children: <Widget>[ + Text('A3'), Text('B3'), Text('C3'), + ], + ), + ], + ), + ), + ), + ); + + final Rect table = tester.getRect(find.byType(Table)); + final Rect a1 = tester.getRect(find.text('A1')); + final Rect a2 = tester.getRect(find.text('A2')); + final Rect a3 = tester.getRect(find.text('A3')); + final Rect b1 = tester.getRect(find.text('B1')); + final Rect b2 = tester.getRect(find.text('B2')); + final Rect b3 = tester.getRect(find.text('B3')); + final Rect c1 = tester.getRect(find.text('C1')); + final Rect c2 = tester.getRect(find.text('C2')); + final Rect c3 = tester.getRect(find.text('C3')); + + expect(a1.width, equals(100.0)); + expect(a2.width, equals(100.0)); + expect(a3.width, equals(100.0)); + expect(b1.width, equals(110.0)); + expect(b2.width, equals(110.0)); + expect(b3.width, equals(110.0)); + expect(c1.width, equals(125.0)); + expect(c2.width, equals(125.0)); + expect(c3.width, equals(125.0)); + + expect(table.width, equals(335.0)); + + expect(a1.right, equals(table.right)); + expect(a2.right, equals(a1.right)); + expect(a3.right, equals(a1.right)); + + expect(b1.right, equals(table.right - a1.width)); + expect(b2.right, equals(b1.right)); + expect(b3.right, equals(b1.right)); + + expect(c1.right, equals(table.right - a1.width - b1.width)); + expect(c2.right, equals(c1.right)); + expect(c3.right, equals(c1.right)); + }); + + testWidgets('Table border - smoke test', (WidgetTester tester) async { + Future<void> run(TextDirection textDirection) async { + await tester.pumpWidget( + Directionality( + textDirection: textDirection, + child: Table( + border: TableBorder.all(), + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('AAAAAA'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('EEE'), Text('F'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('III'), + ], + ), + ], + ), + ), + ); + } + + await run(TextDirection.ltr); + await tester.pumpWidget(Container()); + await run(TextDirection.rtl); + }); + + testWidgets('Table widget - changing table dimensions', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('A'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('E'), Text('F'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('I'), + ], + ), + ], + ), + ), + ); + final RenderBox boxA1 = tester.renderObject(find.text('A')); + final RenderBox boxG1 = tester.renderObject(find.text('G')); + expect(boxA1, isNotNull); + expect(boxG1, isNotNull); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('a'), Text('b'), Text('c'), Text('d'), + ], + ), + TableRow( + children: <Widget>[ + Text('e'), Text('f'), Text('g'), Text('h'), + ], + ), + ], + ), + ), + ); + final RenderBox boxA2 = tester.renderObject(find.text('a')); + final RenderBox boxG2 = tester.renderObject(find.text('g')); + expect(boxA2, isNotNull); + expect(boxG2, isNotNull); + expect(boxA1, equals(boxA2)); + expect(boxG1, isNot(equals(boxG2))); + }); + + testWidgets('Really small deficit double precision error', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/27083 + const SizedBox cell = SizedBox(width: 16, height: 16); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow( + children: <Widget>[ + cell, cell, cell, cell, cell, cell, + ], + ), + TableRow( + children: <Widget>[ + cell, cell, cell, cell, cell, cell, + ], + ), + ], + ), + ), + ); + // If the above bug is present this test will never terminate. + }); + + testWidgets('Calculating flex columns with small width deficit', (WidgetTester tester) async { + const SizedBox cell = SizedBox(width: 1, height: 1); + // If the error is present, pumpWidget() will fail due to an unsatisfied + // assertion during the layout phase. + await tester.pumpWidget( + ConstrainedBox( + constraints: BoxConstraints.tight(const Size(600, 800)), + child: Directionality( + textDirection: TextDirection.ltr, + child: Table( + columnWidths: const <int, TableColumnWidth>{ + 0: FlexColumnWidth(), + 1: FlexColumnWidth(0.123), + 2: FlexColumnWidth(0.123), + 3: FlexColumnWidth(0.123), + 4: FlexColumnWidth(0.123), + 5: FlexColumnWidth(0.123), + 6: FlexColumnWidth(0.123), + }, + children: <TableRow>[ + TableRow(children: List<Widget>.filled(7, cell)), + TableRow(children: List<Widget>.filled(7, cell)), + ], + ), + ), + ), + ); + expect(tester.takeException(), null); + }); + + testWidgets('Table widget - repump test', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('AAAAAA'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('EEE'), Text('F'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('III'), + ], + ), + ], + ), + ), + ); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('AAA'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('E'), Text('FFFFFF'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('III'), + ], + ), + ], + ), + ), + ); + final RenderBox boxA = tester.renderObject(find.text('AAA')); + final RenderBox boxD = tester.renderObject(find.text('D')); + final RenderBox boxG = tester.renderObject(find.text('G')); + final RenderBox boxB = tester.renderObject(find.text('B')); + expect(boxA.size, equals(boxD.size)); + expect(boxA.size, equals(boxG.size)); + expect(boxA.size, equals(boxB.size)); + }); + + testWidgets('Table widget - intrinsic sizing test', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + defaultColumnWidth: const IntrinsicColumnWidth(), + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('AAA'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('E'), Text('FFFFFF'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('III'), + ], + ), + ], + ), + ), + ); + final RenderBox boxA = tester.renderObject(find.text('AAA')); + final RenderBox boxD = tester.renderObject(find.text('D')); + final RenderBox boxG = tester.renderObject(find.text('G')); + final RenderBox boxB = tester.renderObject(find.text('B')); + expect(boxA.size, equals(boxD.size)); + expect(boxA.size, equals(boxG.size)); + expect(boxA.size.width, greaterThan(boxB.size.width)); + expect(boxA.size.height, equals(boxB.size.height)); + }); + + testWidgets('Table widget - intrinsic sizing test, resizing', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + defaultColumnWidth: const IntrinsicColumnWidth(), + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('AAAAAA'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('EEE'), Text('F'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('III'), + ], + ), + ], + ), + ), + ); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + defaultColumnWidth: const IntrinsicColumnWidth(), + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('A'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('EEE'), Text('F'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('III'), + ], + ), + ], + ), + ), + ); + final RenderBox boxA = tester.renderObject(find.text('A')); + final RenderBox boxD = tester.renderObject(find.text('D')); + final RenderBox boxG = tester.renderObject(find.text('G')); + final RenderBox boxB = tester.renderObject(find.text('B')); + expect(boxA.size, equals(boxD.size)); + expect(boxA.size, equals(boxG.size)); + expect(boxA.size.width, lessThan(boxB.size.width)); + expect(boxA.size.height, equals(boxB.size.height)); + }); + + testWidgets('Table widget - intrinsic sizing test, changing column widths', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('AAA'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('E'), Text('FFFFFF'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('III'), + ], + ), + ], + ), + ), + ); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + defaultColumnWidth: const IntrinsicColumnWidth(), + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('AAA'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('E'), Text('FFFFFF'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('III'), + ], + ), + ], + ), + ), + ); + final RenderBox boxA = tester.renderObject(find.text('AAA')); + final RenderBox boxD = tester.renderObject(find.text('D')); + final RenderBox boxG = tester.renderObject(find.text('G')); + final RenderBox boxB = tester.renderObject(find.text('B')); + expect(boxA.size, equals(boxD.size)); + expect(boxA.size, equals(boxG.size)); + expect(boxA.size.width, greaterThan(boxB.size.width)); + expect(boxA.size.height, equals(boxB.size.height)); + }); + + testWidgets('Table widget - moving test', (WidgetTester tester) async { + final List<BuildContext> contexts = <BuildContext>[]; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: <TableRow>[ + TableRow( + key: const ValueKey<int>(1), + children: <Widget>[ + StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + contexts.add(context); + return const Text('A'); + }, + ), + ], + ), + const TableRow( + children: <Widget>[ + Text('b'), + ], + ), + ], + ), + ), + ); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: <TableRow>[ + const TableRow( + children: <Widget>[ + Text('b'), + ], + ), + TableRow( + key: const ValueKey<int>(1), + children: <Widget>[ + StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + contexts.add(context); + return const Text('A'); + }, + ), + ], + ), + ], + ), + ), + ); + expect(contexts.length, equals(2)); + expect(contexts[0], equals(contexts[1])); + }); + + testWidgets('Table widget - keyed rows', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow( + key: ValueKey<int>(1), + children: <Widget>[ + TestStatefulWidget(key: ValueKey<int>(11)), + TestStatefulWidget(key: ValueKey<int>(12)), + ], + ), + TableRow( + key: ValueKey<int>(2), + children: <Widget>[ + TestStatefulWidget(key: ValueKey<int>(21)), + TestStatefulWidget(key: ValueKey<int>(22)), + ], + ), + ], + ), + ), + ); + + final TestStatefulWidgetState state11 = tester.state(find.byKey(const ValueKey<int>(11))); + final TestStatefulWidgetState state12 = tester.state(find.byKey(const ValueKey<int>(12))); + final TestStatefulWidgetState state21 = tester.state(find.byKey(const ValueKey<int>(21))); + final TestStatefulWidgetState state22 = tester.state(find.byKey(const ValueKey<int>(22))); + + expect(state11.mounted, isTrue); + expect(state12.mounted, isTrue); + expect(state21.mounted, isTrue); + expect(state22.mounted, isTrue); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow( + key: ValueKey<int>(2), + children: <Widget>[ + TestStatefulWidget(key: ValueKey<int>(21)), + TestStatefulWidget(key: ValueKey<int>(22)), + ], + ), + ], + ), + ), + ); + + expect(state11.mounted, isFalse); + expect(state12.mounted, isFalse); + expect(state21.mounted, isTrue); + expect(state22.mounted, isTrue); + }); + + testWidgets('Table widget - global key reparenting', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + final Key tableKey = UniqueKey(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget> [ + Expanded( + key: tableKey, + child: Table( + children: <TableRow>[ + TableRow( + children: <Widget>[ + Container(key: const ValueKey<int>(1)), + TestStatefulWidget(key: key), + Container(key: const ValueKey<int>(2)), + ], + ), + ], + ), + ), + ], + ), + ), + ); + + final RenderTable table = tester.renderObject(find.byType(Table)); + expect(table.row(0).length, 3); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget> [ + Expanded(child: TestStatefulWidget(key: key)), + Expanded( + key: tableKey, + child: Table( + children: <TableRow>[ + TableRow( + children: <Widget>[ + Container(key: const ValueKey<int>(1)), + Container(key: const ValueKey<int>(2)), + ], + ), + ], + ), + ), + ], + ), + ), + ); + + expect(tester.renderObject(find.byType(Table)), equals(table)); + expect(table.row(0).length, 2); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget> [ + Expanded( + key: tableKey, + child: Table( + children: <TableRow>[ + TableRow( + children: <Widget>[ + Container(key: const ValueKey<int>(1)), + TestStatefulWidget(key: key), + Container(key: const ValueKey<int>(2)), + ], + ), + ], + ), + ), + ], + ), + ), + ); + + expect(tester.renderObject(find.byType(Table)), equals(table)); + expect(table.row(0).length, 3); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget> [ + Expanded( + key: tableKey, + child: Table( + children: <TableRow>[ + TableRow( + children: <Widget>[ + Container(key: const ValueKey<int>(1)), + Container(key: const ValueKey<int>(2)), + ], + ), + ], + ), + ), + Expanded(child: TestStatefulWidget(key: key)), + ], + ), + ), + ); + + expect(tester.renderObject(find.byType(Table)), equals(table)); + expect(table.row(0).length, 2); + }); + + testWidgets('Table widget diagnostics', (WidgetTester tester) async { + GlobalKey key0; + final Widget table = Directionality( + textDirection: TextDirection.ltr, + child: Table( + key: key0 = GlobalKey(), + defaultColumnWidth: const IntrinsicColumnWidth(), + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('A'), Text('B'), Text('C'), + ], + ), + TableRow( + children: <Widget>[ + Text('D'), Text('EEE'), Text('F'), + ], + ), + TableRow( + children: <Widget>[ + Text('G'), Text('H'), Text('III'), + ], + ), + ], + ), + ); + await tester.pumpWidget(table); + final RenderObjectElement element = key0.currentContext! as RenderObjectElement; + expect(element, hasAGoodToStringDeep); + expect( + element.toStringDeep(minLevel: DiagnosticLevel.info), + equalsIgnoringHashCodes( + 'Table-[GlobalKey#00000](dependencies: [Directionality, MediaQuery], renderObject: RenderTable#00000)\n' + '├Text("A", dependencies: [MediaQuery])\n' + '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "A", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n' + '├Text("B", dependencies: [MediaQuery])\n' + '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "B", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n' + '├Text("C", dependencies: [MediaQuery])\n' + '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "C", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n' + '├Text("D", dependencies: [MediaQuery])\n' + '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "D", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n' + '├Text("EEE", dependencies: [MediaQuery])\n' + '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "EEE", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n' + '├Text("F", dependencies: [MediaQuery])\n' + '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "F", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n' + '├Text("G", dependencies: [MediaQuery])\n' + '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "G", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n' + '├Text("H", dependencies: [MediaQuery])\n' + '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "H", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n' + '└Text("III", dependencies: [MediaQuery])\n' + ' └RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "III", dependencies: [Directionality], renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n', + ), + ); + }); + + // Regression test for https://github.com/flutter/flutter/issues/31473. + testWidgets( + 'Does not crash if a child RenderObject is replaced by another RenderObject of a different type', + (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table(children: const <TableRow>[TableRow(children: <Widget>[TestChildWidget()])]), + ), + ); + expect(find.text('CRASHHH'), findsNothing); + + final TestChildState state = tester.state(find.byType(TestChildWidget)); + state.toggleMe(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table(children: const <TableRow>[TableRow(children: <Widget>[TestChildWidget()])]), + ), + ); + + // Should not crash. + expect(find.text('CRASHHH'), findsOneWidget); + }, + ); + + testWidgets('Table widget - Default textBaseline is null', (WidgetTester tester) async { + expect( + () => Table(defaultVerticalAlignment: TableCellVerticalAlignment.baseline), + throwsA( + isAssertionError + .having((AssertionError error) => error.message, 'exception message', contains('baseline')), + ), + ); + }); + + testWidgets( + 'Table widget requires all TableRows to have same number of children', + (WidgetTester tester) async { + FlutterError? error; + try { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow(children: <Widget>[Text('Some Text')]), + TableRow(), + ], + ), + ), + ); + } on FlutterError catch (e) { + error = e; + } finally { + expect(error, isNotNull); + expect(error!.toStringDeep(), contains('Table contains irregular row lengths.')); + } + }, + ); + + testWidgets('Can replace child with a different RenderObject type', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/69395. + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Table(children: const <TableRow>[ + TableRow(children: <Widget>[ + TestChildWidget(), + TestChildWidget(), + TestChildWidget(), + ]), + TableRow(children: <Widget>[ + TestChildWidget(), + TestChildWidget(), + TestChildWidget(), + ]), + ]), + ), + ); + final RenderTable table = tester.renderObject(find.byType(Table)); + + expect(find.text('CRASHHH'), findsNothing); + expect(find.byType(SizedBox), findsNWidgets(3 * 2)); + final Type toBeReplaced = table.column(2).last.runtimeType; + + final TestChildState state = tester.state(find.byType(TestChildWidget).last); + state.toggleMe(); + await tester.pump(); + + expect(find.byType(SizedBox), findsNWidgets(5)); + expect(find.text('CRASHHH'), findsOneWidget); + + // The RenderObject got replaced by a different type. + expect(table.column(2).last.runtimeType, isNot(toBeReplaced)); + }); + + testWidgets('Do not crash if a child that has not been layed out in a previous build is removed', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/60488. + Widget buildTable(Key key) { + return Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: <TableRow>[ + TableRow( + children: <Widget>[ + KeyedSubtree( + key: key, + child: const Text('Hello'), + ), + ], + ), + ], + ), + ); + } + + await tester.pumpWidget( + buildTable(const ValueKey<int>(1)), + null, EnginePhase.build, // Children are not layed out! + ); + + await tester.pumpWidget( + buildTable(const ValueKey<int>(2)), + ); + + expect(tester.takeException(), isNull); + expect(find.text('Hello'), findsOneWidget); + }); + + testWidgets('TableRow with no children throws an error message', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/119541. + String result = 'no exception'; + + // Test TableRow with children. + try { + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow( + children: <Widget>[ + Text('A'), + ], + ), + ], + ), + )); + } on FlutterError catch (e) { + result = e.toString(); + } + + expect(result, 'no exception'); + + // Test TableRow with no children. + try { + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: Table( + children: const <TableRow>[ + TableRow(), + ], + ), + )); + } on FlutterError catch (e) { + result = e.toString(); + } + + expect( + result, + 'One or more TableRow have no children.\n' + 'Every TableRow in a Table must have at least one child, so there is no empty row.', + ); + }); + + testWidgets('Set defaultVerticalAlignment to intrisic height and check their heights', (WidgetTester tester) async { + final Widget table = Directionality( + textDirection: TextDirection.ltr, + child: Table( + defaultVerticalAlignment: TableCellVerticalAlignment.intrinsicHeight, + children: const <TableRow>[ + TableRow( + children: <Widget>[ + SizedBox(height: 100, child: Text('A')), + SizedBox(height: 200, child: Text('B')), + ], + ), + TableRow( + children: <Widget>[ + SizedBox(height: 200, child: Text('C')), + SizedBox(height: 300, child: Text('D')), + ], + ), + ], + ), + ); + + // load and check if render object was created. + await tester.pumpWidget(table); + expect(find.byWidget(table), findsOneWidget); + + final RenderBox boxA = tester.renderObject(find.text('A')); + final RenderBox boxB = tester.renderObject(find.text('B')); + + // boxA and boxB must be the same height, even though boxB is higher than boxA initially. + expect(boxA.size.height, equals(boxB.size.height)); + + final RenderBox boxC = tester.renderObject(find.text('C')); + final RenderBox boxD = tester.renderObject(find.text('D')); + + // boxC and boxD must be the same height, even though boxD is higher than boxC initially. + expect(boxC.size.height, equals(boxD.size.height)); + + // boxD (300.0h) should be higher than boxA (200.0h) which has the same height of boxB. + expect(boxD.size.height, greaterThan(boxA.size.height)); + }); + + // TODO(ianh): Test handling of TableCell object +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tap_region_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tap_region_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..8dfbd9f93be80be41ec381d241d676b4f53d12c8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tap_region_test.dart @@ -0,0 +1,1056 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('TapRegionSurface detects outside taps', (WidgetTester tester) async { + final Set<String> tappedOutside = <String>{}; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget>[ + const Text('Outside Surface'), + TapRegionSurface( + child: Row( + children: <Widget>[ + const Text('Outside'), + TapRegion( + onTapOutside: (PointerEvent event) { + tappedOutside.add('No Group'); + }, + child: const Text('No Group'), + ), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 B'); + }, + child: const Text('Group 1 B'), + ), + ], + ), + ), + ], + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedOutside, isEmpty); + + await click(find.text('No Group')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + tappedOutside.clear(); + + await click(find.text('Group 1 A')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + tappedOutside.clear(); + + await click(find.text('Group 1 B')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + tappedOutside.clear(); + + await click(find.text('Outside')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'No Group', + 'Group 1 A', + 'Group 1 B', + })); + tappedOutside.clear(); + + await click(find.text('Outside Surface')); + expect(tappedOutside, isEmpty); + }); + + testWidgets('TapRegionSurface consumes outside taps when asked', (WidgetTester tester) async { + final Set<String> tappedOutside = <String>{}; + int propagatedTaps = 0; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget>[ + const Text('Outside Surface'), + TapRegionSurface( + child: Row( + children: <Widget>[ + GestureDetector( + onTap: () { + propagatedTaps += 1; + }, + child: const Text('Outside'), + ), + TapRegion( + consumeOutsideTaps: true, + onTapOutside: (PointerEvent event) { + tappedOutside.add('No Group'); + }, + child: const Text('No Group'), + ), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 1, + consumeOutsideTaps: true, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 B'); + }, + child: const Text('Group 1 B'), + ), + ], + ), + ), + ], + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedOutside, isEmpty); + expect(propagatedTaps, equals(0)); + + await click(find.text('No Group')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Group 1 A')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Group 1 B')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Outside')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'No Group', + 'Group 1 A', + 'Group 1 B', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Outside Surface')); + expect(tappedOutside, isEmpty); + }); + + testWidgets('TapRegionSurface detects inside taps', (WidgetTester tester) async { + final Set<String> tappedInside = <String>{}; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget>[ + const Text('Outside Surface'), + TapRegionSurface( + child: Row( + children: <Widget>[ + const Text('Outside'), + TapRegion( + onTapInside: (PointerEvent event) { + tappedInside.add('No Group'); + }, + child: const Text('No Group'), + ), + TapRegion( + groupId: 1, + onTapInside: (PointerEvent event) { + tappedInside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 1, + onTapInside: (PointerEvent event) { + tappedInside.add('Group 1 B'); + }, + child: const Text('Group 1 B'), + ), + ], + ), + ), + ], + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedInside, isEmpty); + + await click(find.text('No Group')); + expect( + tappedInside, + unorderedEquals(<String>{ + 'No Group', + })); + tappedInside.clear(); + + await click(find.text('Group 1 A')); + expect( + tappedInside, + equals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + tappedInside.clear(); + + await click(find.text('Group 1 B')); + expect( + tappedInside, + equals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + tappedInside.clear(); + + await click(find.text('Outside')); + expect(tappedInside, isEmpty); + tappedInside.clear(); + + await click(find.text('Outside Surface')); + expect(tappedInside, isEmpty); + }); + + testWidgets('TapRegionSurface detects inside taps correctly with behavior', (WidgetTester tester) async { + final Set<String> tappedInside = <String>{}; + const ValueKey<String> noGroupKey = ValueKey<String>('No Group'); + const ValueKey<String> group1AKey = ValueKey<String>('Group 1 A'); + const ValueKey<String> group1BKey = ValueKey<String>('Group 1 B'); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget>[ + const Text('Outside Surface'), + TapRegionSurface( + child: Row( + children: <Widget>[ + ConstrainedBox( + constraints: const BoxConstraints.tightFor(width: 100, height: 100), + child: TapRegion( + onTapInside: (PointerEvent event) { + tappedInside.add(noGroupKey.value); + }, + child: const Stack(key: noGroupKey), + ), + ), + ConstrainedBox( + constraints: const BoxConstraints.tightFor(width: 100, height: 100), + child: TapRegion( + groupId: 1, + behavior: HitTestBehavior.opaque, + onTapInside: (PointerEvent event) { + tappedInside.add(group1AKey.value); + }, + child: const Stack(key: group1AKey), + ), + ), + ConstrainedBox( + constraints: const BoxConstraints.tightFor(width: 100, height: 100), + child: TapRegion( + groupId: 1, + behavior: HitTestBehavior.translucent, + onTapInside: (PointerEvent event) { + tappedInside.add(group1BKey.value); + }, + child: const Stack(key: group1BKey), + ), + ), + ], + ), + ), + ], + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedInside, isEmpty); + + await click(find.byKey(noGroupKey)); + expect(tappedInside, isEmpty); // No hittable children, so no hit. + + await click(find.byKey(group1AKey)); + // No hittable children, but set to opaque, so it hits, triggering the + // group. + expect( + tappedInside, + equals(<String>{ + 'Group 1 A', + 'Group 1 B', + }), + ); + tappedInside.clear(); + + await click(find.byKey(group1BKey)); + expect(tappedInside, isEmpty); // No hittable children while translucent, so no hit. + tappedInside.clear(); + }); + + testWidgets('Setting the group updates the registration', (WidgetTester tester) async { + final Set<String> tappedOutside = <String>{}; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: TapRegionSurface( + child: Row( + children: <Widget>[ + const Text('Outside'), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 B'); + }, + child: const Text('Group 1 B'), + ), + ], + ), + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedOutside, isEmpty); + + await click(find.text('Group 1 A')); + expect(tappedOutside, isEmpty); + await click(find.text('Group 1 B')); + expect(tappedOutside, isEmpty); + await click(find.text('Outside')); + expect( + tappedOutside, + equals(<String>[ + 'Group 1 A', + 'Group 1 B', + ])); + tappedOutside.clear(); + + // Now change out the groups. + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: TapRegionSurface( + child: Row( + children: <Widget>[ + const Text('Outside'), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 2, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 2 A'); + }, + child: const Text('Group 2 A'), + ), + ], + ), + ), + ), + ); + + await click(find.text('Group 1 A')); + expect(tappedOutside, equals(<String>['Group 2 A'])); + tappedOutside.clear(); + + await click(find.text('Group 2 A')); + expect(tappedOutside, equals(<String>['Group 1 A'])); + tappedOutside.clear(); + + await click(find.text('Outside')); + expect( + tappedOutside, + equals(<String>[ + 'Group 1 A', + 'Group 2 A', + ])); + tappedOutside.clear(); + }); + + testWidgets('TapRegionSurface detects outside right click', (WidgetTester tester) async { + final Set<String> tappedOutside = <String>{}; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget>[ + const Text('Outside Surface'), + TapRegionSurface( + child: Row( + children: <Widget>[ + const Text('Outside'), + TapRegion( + onTapOutside: (PointerEvent event) { + tappedOutside.add('No Group'); + }, + child: const Text('No Group'), + ), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 B'); + }, + child: const Text('Group 1 B'), + ), + ], + ), + ), + ], + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + buttons: kSecondaryButton, + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedOutside, isEmpty); + + await click(find.text('No Group')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + tappedOutside.clear(); + + await click(find.text('Group 1 A')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + tappedOutside.clear(); + + await click(find.text('Group 1 B')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + tappedOutside.clear(); + + await click(find.text('Outside')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'No Group', + 'Group 1 A', + 'Group 1 B', + })); + tappedOutside.clear(); + + await click(find.text('Outside Surface')); + expect(tappedOutside, isEmpty); + }); + + testWidgets('TapRegionSurface detects outside middle click', (WidgetTester tester) async { + final Set<String> tappedOutside = <String>{}; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget>[ + const Text('Outside Surface'), + TapRegionSurface( + child: Row( + children: <Widget>[ + const Text('Outside'), + TapRegion( + onTapOutside: (PointerEvent event) { + tappedOutside.add('No Group'); + }, + child: const Text('No Group'), + ), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 B'); + }, + child: const Text('Group 1 B'), + ), + ], + ), + ), + ], + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + buttons: kTertiaryButton, + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedOutside, isEmpty); + + await click(find.text('No Group')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + tappedOutside.clear(); + + await click(find.text('Group 1 A')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + tappedOutside.clear(); + + await click(find.text('Group 1 B')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + tappedOutside.clear(); + + await click(find.text('Outside')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'No Group', + 'Group 1 A', + 'Group 1 B', + })); + tappedOutside.clear(); + + await click(find.text('Outside Surface')); + expect(tappedOutside, isEmpty); + }); + + testWidgets('TapRegionSurface consumes outside right click when asked', (WidgetTester tester) async { + final Set<String> tappedOutside = <String>{}; + int propagatedTaps = 0; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget>[ + const Text('Outside Surface'), + TapRegionSurface( + child: Row( + children: <Widget>[ + GestureDetector( + onTap: () { + propagatedTaps += 1; + }, + child: const Text('Outside'), + ), + TapRegion( + consumeOutsideTaps: true, + onTapOutside: (PointerEvent event) { + tappedOutside.add('No Group'); + }, + child: const Text('No Group'), + ), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 1, + consumeOutsideTaps: true, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 B'); + }, + child: const Text('Group 1 B'), + ), + ], + ), + ), + ], + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + buttons: kSecondaryButton + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedOutside, isEmpty); + expect(propagatedTaps, equals(0)); + + await click(find.text('No Group')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Group 1 A')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Group 1 B')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Outside')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'No Group', + 'Group 1 A', + 'Group 1 B', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Outside Surface')); + expect(tappedOutside, isEmpty); + }); + + testWidgets('TapRegionSurface consumes outside middle click when asked', (WidgetTester tester) async { + final Set<String> tappedOutside = <String>{}; + int propagatedTaps = 0; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget>[ + const Text('Outside Surface'), + TapRegionSurface( + child: Row( + children: <Widget>[ + GestureDetector( + onTap: () { + propagatedTaps += 1; + }, + child: const Text('Outside'), + ), + TapRegion( + consumeOutsideTaps: true, + onTapOutside: (PointerEvent event) { + tappedOutside.add('No Group'); + }, + child: const Text('No Group'), + ), + TapRegion( + groupId: 1, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 1, + consumeOutsideTaps: true, + onTapOutside: (PointerEvent event) { + tappedOutside.add('Group 1 B'); + }, + child: const Text('Group 1 B'), + ), + ], + ), + ), + ], + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + buttons: kTertiaryButton, + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedOutside, isEmpty); + expect(propagatedTaps, equals(0)); + + await click(find.text('No Group')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Group 1 A')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Group 1 B')); + expect( + tappedOutside, + equals(<String>{ + 'No Group', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Outside')); + expect( + tappedOutside, + unorderedEquals(<String>{ + 'No Group', + 'Group 1 A', + 'Group 1 B', + })); + expect(propagatedTaps, equals(0)); + tappedOutside.clear(); + + await click(find.text('Outside Surface')); + expect(tappedOutside, isEmpty); + }); + + testWidgets('TapRegionSurface detects inside right click', (WidgetTester tester) async { + final Set<String> tappedInside = <String>{}; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget>[ + const Text('Outside Surface'), + TapRegionSurface( + child: Row( + children: <Widget>[ + const Text('Outside'), + TapRegion( + onTapInside: (PointerEvent event) { + tappedInside.add('No Group'); + }, + child: const Text('No Group'), + ), + TapRegion( + groupId: 1, + onTapInside: (PointerEvent event) { + tappedInside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 1, + onTapInside: (PointerEvent event) { + tappedInside.add('Group 1 B'); + }, + child: const Text('Group 1 B'), + ), + ], + ), + ), + ], + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + buttons: kSecondaryButton, + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedInside, isEmpty); + + await click(find.text('No Group')); + expect( + tappedInside, + unorderedEquals(<String>{ + 'No Group', + })); + tappedInside.clear(); + + await click(find.text('Group 1 A')); + expect( + tappedInside, + equals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + tappedInside.clear(); + + await click(find.text('Group 1 B')); + expect( + tappedInside, + equals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + tappedInside.clear(); + + await click(find.text('Outside')); + expect(tappedInside, isEmpty); + tappedInside.clear(); + + await click(find.text('Outside Surface')); + expect(tappedInside, isEmpty); + }); + + testWidgets('TapRegionSurface detects inside middle click', (WidgetTester tester) async { + final Set<String> tappedInside = <String>{}; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Column( + children: <Widget>[ + const Text('Outside Surface'), + TapRegionSurface( + child: Row( + children: <Widget>[ + const Text('Outside'), + TapRegion( + onTapInside: (PointerEvent event) { + tappedInside.add('No Group'); + }, + child: const Text('No Group'), + ), + TapRegion( + groupId: 1, + onTapInside: (PointerEvent event) { + tappedInside.add('Group 1 A'); + }, + child: const Text('Group 1 A'), + ), + TapRegion( + groupId: 1, + onTapInside: (PointerEvent event) { + tappedInside.add('Group 1 B'); + }, + child: const Text('Group 1 B'), + ), + ], + ), + ), + ], + ), + ), + ); + + await tester.pump(); + + Future<void> click(Finder finder) async { + final TestGesture gesture = await tester.startGesture( + tester.getCenter(finder), + kind: PointerDeviceKind.mouse, + buttons: kTertiaryButton, + ); + await gesture.up(); + await gesture.removePointer(); + } + + expect(tappedInside, isEmpty); + + await click(find.text('No Group')); + expect( + tappedInside, + unorderedEquals(<String>{ + 'No Group', + })); + tappedInside.clear(); + + await click(find.text('Group 1 A')); + expect( + tappedInside, + equals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + tappedInside.clear(); + + await click(find.text('Group 1 B')); + expect( + tappedInside, + equals(<String>{ + 'Group 1 A', + 'Group 1 B', + })); + tappedInside.clear(); + + await click(find.text('Outside')); + expect(tappedInside, isEmpty); + tappedInside.clear(); + + await click(find.text('Outside Surface')); + expect(tappedInside, isEmpty); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/test_border.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/test_border.dart new file mode 100644 index 0000000000000000000000000000000000000000..9c8054816f33ab26d76bb88f58e802dc51a53391 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/test_border.dart @@ -0,0 +1,36 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; + +typedef Logger = void Function(String caller); + +class TestBorder extends ShapeBorder { + const TestBorder(this.onLog); + + final Logger onLog; + + @override + EdgeInsetsGeometry get dimensions => const EdgeInsetsDirectional.only(start: 1.0); + + @override + ShapeBorder scale(double t) => TestBorder(onLog); + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + onLog('getInnerPath $rect $textDirection'); + return Path(); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + onLog('getOuterPath $rect $textDirection'); + return Path(); + } + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { + onLog('paint $rect $textDirection'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/test_widgets.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/test_widgets.dart new file mode 100644 index 0000000000000000000000000000000000000000..4a999f94d621937020828ff1d7825c93234de029 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/test_widgets.dart @@ -0,0 +1,60 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +const BoxDecoration kBoxDecorationA = BoxDecoration( + color: Color(0xFFFF0000), +); + +const BoxDecoration kBoxDecorationB = BoxDecoration( + color: Color(0xFF00FF00), +); + +const BoxDecoration kBoxDecorationC = BoxDecoration( + color: Color(0xFF0000FF), +); + +class TestBuildCounter extends StatelessWidget { + const TestBuildCounter({ super.key }); + + static int buildCount = 0; + + @override + Widget build(BuildContext context) { + buildCount += 1; + return const DecoratedBox(decoration: kBoxDecorationA); + } +} + + +class FlipWidget extends StatefulWidget { + const FlipWidget({ super.key, required this.left, required this.right }); + + final Widget left; + final Widget right; + + @override + FlipWidgetState createState() => FlipWidgetState(); +} + +class FlipWidgetState extends State<FlipWidget> { + bool _showLeft = true; + + void flip() { + setState(() { + _showLeft = !_showLeft; + }); + } + + @override + Widget build(BuildContext context) { + return _showLeft ? widget.left : widget.right; + } +} + +void flipStatefulWidget(WidgetTester tester, { bool skipOffstage = true }) { + tester.state<FlipWidgetState>(find.byType(FlipWidget, skipOffstage: skipOffstage)).flip(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_golden_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_golden_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..4267da2d79a182a7b2e4164fbd5ea518bc8a2315 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_golden_test.dart @@ -0,0 +1,1384 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is run as part of a reduced test set in CI on Mac and Windows +// machines. +@Tags(<String>['reduced-test-set']) +@TestOn('!chrome') +library; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Centered text', (WidgetTester tester) async { + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 200.0, + height: 100.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: const Text('Hello', + textDirection: TextDirection.ltr, + textAlign: TextAlign.center, + style: TextStyle(color: Color(0xffff0000)), + ), + ), + ), + ), + ); + + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.Centered.png'), + ); + + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 200.0, + height: 100.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: const Text('Hello world how are you today', + textDirection: TextDirection.ltr, + textAlign: TextAlign.center, + style: TextStyle(color: Color(0xffff0000)), + ), + ), + ), + ), + ); + + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.Centered.wrap.png'), + ); + }); + + + testWidgets('Text Foreground', (WidgetTester tester) async { + const Color black = Color(0xFF000000); + const Color red = Color(0xFFFF0000); + const Color blue = Color(0xFF0000FF); + final Shader linearGradient = const LinearGradient( + colors: <Color>[red, blue], + ).createShader(const Rect.fromLTWH(0.0, 0.0, 50.0, 20.0)); + + await tester.pumpWidget( + Align( + alignment: Alignment.topLeft, + child: RepaintBoundary( + child: Text('Hello', + textDirection: TextDirection.ltr, + style: TextStyle( + foreground: Paint() + ..color = black + ..shader = linearGradient, + ), + ), + ), + ), + ); + + await expectLater( + find.byType(RepaintBoundary), + matchesGoldenFile('text_golden.Foreground.gradient.png'), + ); + + await tester.pumpWidget( + Align( + alignment: Alignment.topLeft, + child: RepaintBoundary( + child: Text('Hello', + textDirection: TextDirection.ltr, + style: TextStyle( + foreground: Paint() + ..color = black + ..style = PaintingStyle.stroke + ..strokeWidth = 2.0, + ), + ), + ), + ), + ); + + await expectLater( + find.byType(RepaintBoundary), + matchesGoldenFile('text_golden.Foreground.stroke.png'), + ); + + await tester.pumpWidget( + Align( + alignment: Alignment.topLeft, + child: RepaintBoundary( + child: Text('Hello', + textDirection: TextDirection.ltr, + style: TextStyle( + foreground: Paint() + ..color = black + ..style = PaintingStyle.stroke + ..strokeWidth = 2.0 + ..shader = linearGradient, + ), + ), + ), + ), + ); + + await expectLater( + find.byType(RepaintBoundary), + matchesGoldenFile('text_golden.Foreground.stroke_and_gradient.png'), + ); + }); + + // TODO(garyq): This test requires an update when the background + // drawing from the beginning of the line bug is fixed. The current + // tested version is not completely correct. + testWidgets('Text Background', (WidgetTester tester) async { + const Color red = Colors.red; + const Color blue = Colors.blue; + const Color translucentGreen = Color(0x5000F000); + const Color translucentDarkRed = Color(0x500F0000); + await tester.pumpWidget( + Align( + alignment: Alignment.topLeft, + child: RepaintBoundary( + child: Container( + width: 200.0, + height: 100.0, + decoration: const BoxDecoration( + color: Colors.green, + ), + child: Text.rich( + TextSpan( + text: 'text1 ', + style: TextStyle( + color: translucentGreen, + background: Paint() + ..color = red.withOpacity(0.5), + ), + children: <InlineSpan>[ + TextSpan( + text: 'text2', + style: TextStyle( + color: translucentDarkRed, + background: Paint() + ..color = blue.withOpacity(0.5), + ), + ), + ], + ), + textDirection: TextDirection.ltr, + ), + ), + ), + ), + ); + + await expectLater( + find.byType(RepaintBoundary), + matchesGoldenFile('text_golden.Background.png'), + ); + }); + + testWidgets('Text Fade', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Scaffold( + backgroundColor: Colors.transparent, + body: RepaintBoundary( + child: Center( + child: Container( + width: 200.0, + height: 200.0, + color: Colors.green, + child: Center( + child: Container( + width: 100.0, + color: Colors.blue, + child: const Text( + 'Pp PPp PPPp PPPPp PPPPpp PPPPppp PPPPppppp ', + style: TextStyle(color: Colors.black), + maxLines: 3, + overflow: TextOverflow.fade, + ), + ), + ), + ), + ), + ), + ), + ), + ); + + await expectLater( + find.byType(RepaintBoundary).first, + matchesGoldenFile('text_golden.Fade.png'), + ); + }); + + testWidgets('Default Strut text', (WidgetTester tester) async { + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 200.0, + height: 100.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: const Text('Hello\nLine 2\nLine 3', + textDirection: TextDirection.ltr, + style: TextStyle(), + strutStyle: StrutStyle(), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.StrutDefault.png'), + ); + }); + + testWidgets('Strut text 1', (WidgetTester tester) async { + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 200.0, + height: 100.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: const Text('Hello\nLine2\nLine3', + textDirection: TextDirection.ltr, + style: TextStyle(), + strutStyle: StrutStyle( + height: 1.5, + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.Strut.1.png'), + ); + }); + + testWidgets('Strut text 2', (WidgetTester tester) async { + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 200.0, + height: 100.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: const Text('Hello\nLine 2\nLine 3', + textDirection: TextDirection.ltr, + style: TextStyle(), + strutStyle: StrutStyle( + height: 1.5, + fontSize: 14, + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.Strut.2.png'), + ); + }); + + testWidgets('Strut text rich', (WidgetTester tester) async { + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 200.0, + height: 150.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: const Text.rich( + TextSpan( + text: 'Hello\n', + style: TextStyle( + color: Colors.red, + fontSize: 30, + ), + children: <InlineSpan>[ + TextSpan( + text: 'Second line!\n', + style: TextStyle( + fontSize: 5, + color: Colors.blue, + ), + ), + TextSpan( + text: 'Third line!\n', + style: TextStyle( + fontSize: 25, + color: Colors.white, + ), + ), + ], + ), + textDirection: TextDirection.ltr, + strutStyle: StrutStyle( + fontSize: 14, + height: 1.1, + leading: 0.1, + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.Strut.3.png'), + ); + }); + + testWidgets('Strut text font fallback', (WidgetTester tester) async { + // Font Fallback + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 200.0, + height: 100.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: const Text('Hello\nLine 2\nLine 3', + textDirection: TextDirection.ltr, + style: TextStyle(), + strutStyle: StrutStyle( + fontFamily: 'FakeFont 1', + fontFamilyFallback: <String>[ + 'FakeFont 2', + 'EvilFont 3', + 'Nice Font 4', + 'ahem', + ], + fontSize: 14, + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.Strut.4.png'), + ); + }); + + testWidgets('Strut text rich forceStrutHeight', (WidgetTester tester) async { + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 200.0, + height: 100.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: const Text.rich( + TextSpan( + text: 'Hello\n', + style: TextStyle( + color: Colors.red, + fontSize: 30, + ), + children: <InlineSpan>[ + TextSpan( + text: 'Second line!\n', + style: TextStyle( + fontSize: 9, + color: Colors.blue, + ), + ), + TextSpan( + text: 'Third line!\n', + style: TextStyle( + fontSize: 27, + color: Colors.white, + ), + ), + ], + ), + textDirection: TextDirection.ltr, + strutStyle: StrutStyle( + fontSize: 14, + height: 1.1, + forceStrutHeight: true, + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.StrutForce.1.png'), + ); + }); + + testWidgets('Decoration thickness', (WidgetTester tester) async { + final TextDecoration allDecorations = TextDecoration.combine( + <TextDecoration>[ + TextDecoration.underline, + TextDecoration.overline, + TextDecoration.lineThrough, + ], + ); + + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 300.0, + height: 100.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: Text( + 'Hello, wor!\nabcd.', + style: TextStyle( + fontSize: 25, + decoration: allDecorations, + decorationColor: Colors.blue, + decorationStyle: TextDecorationStyle.dashed, + ), + textDirection: TextDirection.rtl, + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.Decoration.1.png'), + ); + }); + + testWidgets('Decoration thickness', (WidgetTester tester) async { + final TextDecoration allDecorations = TextDecoration.combine( + <TextDecoration>[ + TextDecoration.underline, + TextDecoration.overline, + TextDecoration.lineThrough, + ], + ); + + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 300.0, + height: 100.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: Text( + 'Hello, wor!\nabcd.', + style: TextStyle( + fontSize: 25, + decoration: allDecorations, + decorationColor: Colors.blue, + decorationStyle: TextDecorationStyle.wavy, + decorationThickness: 4, + ), + textDirection: TextDirection.rtl, + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.DecorationThickness.1.png'), + ); + }); + + testWidgets('Text Inline widget', (WidgetTester tester) async { + await tester.pumpWidget( + Theme(data: ThemeData(useMaterial3: false), child: Center( + child: RepaintBoundary( + child: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Container( + width: 400.0, + height: 200.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 200, maxHeight: 100), + child: const Text.rich( + TextSpan( + text: 'C ', + style: TextStyle( + fontSize: 16, + ), + children: <InlineSpan>[ + WidgetSpan( + child: Checkbox(value: true, onChanged: null), + ), + WidgetSpan( + child: Checkbox(value: false, onChanged: null), + ), + TextSpan(text: 'He ', style: TextStyle(fontSize: 20)), + WidgetSpan( + child: SizedBox( + width: 50.0, + height: 55.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffffff00), + ), + child: Center( + child:SizedBox( + width: 10.0, + height: 15.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffff0000), + ), + ), + ), + ), + ), + ), + ), + TextSpan(text: 'hello world! seize the day!'), + WidgetSpan( + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + child: Checkbox(value: false, onChanged: null), + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + ), + WidgetSpan( + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + child: Text('embedded'), + ), + ], + ), + textDirection: TextDirection.ltr, + ), + ), + ), + ), + ), + ), + )), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.TextInlineWidget.1.png'), + ); + }); + + testWidgets('Text Inline widget textfield', (WidgetTester tester) async { + await tester.pumpWidget( + Center( + child: MaterialApp( + theme: ThemeData(useMaterial3: false), + home: RepaintBoundary( + child: Material( + child: Container( + width: 400.0, + height: 200.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 200, maxHeight: 100), + child: const Text.rich( + TextSpan( + text: 'My name is: ', + style: TextStyle( + fontSize: 20, + ), + children: <InlineSpan>[ + WidgetSpan( + child: SizedBox(width: 70, height: 25, child: TextField()), + ), + TextSpan(text: ', and my favorite city is: ', style: TextStyle(fontSize: 20)), + WidgetSpan( + child: SizedBox(width: 70, height: 25, child: TextField()), + ), + ], + ), + textDirection: TextDirection.ltr, + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.TextInlineWidget.2.png'), + ); + }); + + // This tests if multiple Text.rich widgets are able to inline nest within each other. + testWidgets('Text Inline widget nesting', (WidgetTester tester) async { + await tester.pumpWidget( + Center( + child: MaterialApp( + theme: ThemeData(useMaterial3: false), + home: RepaintBoundary( + child: Material( + child: Container( + width: 400.0, + height: 200.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 200, maxHeight: 100), + child: const Text.rich( + TextSpan( + text: 'outer', + style: TextStyle( + fontSize: 20, + ), + children: <InlineSpan>[ + WidgetSpan( + child: Text.rich( + TextSpan( + text: 'inner', + style: TextStyle(color: Color(0xf402f4ff)), + children: <InlineSpan>[ + WidgetSpan( + child: Text.rich( + TextSpan( + text: 'inner2', + style: TextStyle(color: Color(0xf003ffff)), + children: <InlineSpan>[ + WidgetSpan( + child: SizedBox( + width: 50.0, + height: 55.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffffff30), + ), + child: Center( + child:SizedBox( + width: 10.0, + height: 15.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xff5f00f0), + ), + ), + ), + ), + ), + ), + ), + ], + ), + ), + ), + WidgetSpan( + child: SizedBox( + width: 50.0, + height: 55.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xff5fff00), + ), + child: Center( + child:SizedBox( + width: 10.0, + height: 15.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xff5f0000), + ), + ), + ), + ), + ), + ), + ), + ], + ), + ), + ), + TextSpan(text: 'outer', style: TextStyle(fontSize: 20)), + WidgetSpan( + child: SizedBox(width: 70, height: 25, child: TextField()), + ), + WidgetSpan( + child: SizedBox( + width: 50.0, + height: 55.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffff00ff), + ), + child: Center( + child:SizedBox( + width: 10.0, + height: 15.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xff0000ff), + ), + ), + ), + ), + ), + ), + ), + ], + ), + textDirection: TextDirection.ltr, + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.TextInlineWidgetNest.1.png'), + ); + }); + + testWidgets('Text Inline widget baseline', (WidgetTester tester) async { + await tester.pumpWidget( + Theme( + data: ThemeData(useMaterial3: false), + child: Center( + child: RepaintBoundary( + child: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Container( + width: 400.0, + height: 200.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 200, maxHeight: 100), + child: const Text.rich( + TextSpan( + text: 'C ', + style: TextStyle( + fontSize: 16, + ), + children: <InlineSpan>[ + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: true, onChanged: null), + ), + WidgetSpan( + child: Checkbox(value: false, onChanged: null), + ), + TextSpan(text: 'He ', style: TextStyle(fontSize: 20)), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 50.0, + height: 55.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffffff00), + ), + child: Center( + child:SizedBox( + width: 10.0, + height: 15.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffff0000), + ), + ), + ), + ), + ), + ), + ), + TextSpan(text: 'hello world! seize the day!'), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: Text('embedded'), + ), + TextSpan(text: 'ref'), + ], + ), + textDirection: TextDirection.ltr, + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.TextInlineWidgetBaseline.1.png'), + ); + }); + + testWidgets('Text Inline widget aboveBaseline', (WidgetTester tester) async { + await tester.pumpWidget( + Theme( + data: ThemeData(useMaterial3: false), + child: Center( + child: RepaintBoundary( + child: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Container( + width: 400.0, + height: 200.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 200, maxHeight: 100), + child: const Text.rich( + TextSpan( + text: 'C ', + style: TextStyle( + fontSize: 16, + ), + children: <InlineSpan>[ + WidgetSpan( + alignment: PlaceholderAlignment.aboveBaseline, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: true, onChanged: null), + ), + WidgetSpan( + child: Checkbox(value: false, onChanged: null), + ), + TextSpan(text: 'He ', style: TextStyle(fontSize: 20)), + WidgetSpan( + alignment: PlaceholderAlignment.aboveBaseline, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 50.0, + height: 55.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffffff00), + ), + child: Center( + child:SizedBox( + width: 10.0, + height: 15.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffff0000), + ), + ), + ), + ), + ), + ), + ), + TextSpan(text: 'hello world! seize the day!'), + WidgetSpan( + alignment: PlaceholderAlignment.aboveBaseline, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + alignment: PlaceholderAlignment.aboveBaseline, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + alignment: PlaceholderAlignment.aboveBaseline, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + alignment: PlaceholderAlignment.aboveBaseline, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + alignment: PlaceholderAlignment.aboveBaseline, + baseline: TextBaseline.alphabetic, + child: Text('embedded'), + ), + TextSpan(text: 'ref'), + ], + ), + textDirection: TextDirection.ltr, + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.TextInlineWidgetAboveBaseline.1.png'), + ); + }); + + testWidgets('Text Inline widget belowBaseline', (WidgetTester tester) async { + await tester.pumpWidget( + Theme( + data: ThemeData(useMaterial3: false), + child: Center( + child: RepaintBoundary( + child: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Container( + width: 400.0, + height: 200.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 200, maxHeight: 100), + child: const Text.rich( + TextSpan( + text: 'C ', + style: TextStyle( + fontSize: 16, + ), + children: <InlineSpan>[ + WidgetSpan( + alignment: PlaceholderAlignment.belowBaseline, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: true, onChanged: null), + ), + WidgetSpan( + child: Checkbox(value: false, onChanged: null), + ), + TextSpan(text: 'He ', style: TextStyle(fontSize: 20)), + WidgetSpan( + alignment: PlaceholderAlignment.belowBaseline, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 50.0, + height: 55.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffffff00), + ), + child: Center( + child:SizedBox( + width: 10.0, + height: 15.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffff0000), + ), + ), + ), + ), + ), + ), + ), + TextSpan(text: 'hello world! seize the day!'), + WidgetSpan( + alignment: PlaceholderAlignment.belowBaseline, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + alignment: PlaceholderAlignment.belowBaseline, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + alignment: PlaceholderAlignment.belowBaseline, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + alignment: PlaceholderAlignment.belowBaseline, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + alignment: PlaceholderAlignment.belowBaseline, + baseline: TextBaseline.alphabetic, + child: Text('embedded'), + ), + TextSpan(text: 'ref'), + ], + ), + textDirection: TextDirection.ltr, + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.TextInlineWidgetBelowBaseline.1.png'), + ); + }); + + testWidgets('Text Inline widget top', (WidgetTester tester) async { + await tester.pumpWidget( + Theme( + data: ThemeData(useMaterial3: false), + child: Center( + child: RepaintBoundary( + child: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Container( + width: 400.0, + height: 200.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 200, maxHeight: 100), + child: const Text.rich( + TextSpan( + text: 'C ', + style: TextStyle( + fontSize: 16, + ), + children: <InlineSpan>[ + WidgetSpan( + alignment: PlaceholderAlignment.top, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: true, onChanged: null), + ), + WidgetSpan( + child: Checkbox(value: false, onChanged: null), + ), + TextSpan(text: 'He ', style: TextStyle(fontSize: 20)), + WidgetSpan( + alignment: PlaceholderAlignment.top, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 50.0, + height: 55.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffffff00), + ), + child: Center( + child:SizedBox( + width: 10.0, + height: 15.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffff0000), + ), + ), + ), + ), + ), + ), + ), + TextSpan(text: 'hello world! seize the day!'), + WidgetSpan( + alignment: PlaceholderAlignment.top, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + alignment: PlaceholderAlignment.top, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + alignment: PlaceholderAlignment.top, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + alignment: PlaceholderAlignment.top, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + alignment: PlaceholderAlignment.top, + baseline: TextBaseline.alphabetic, + child: Text('embedded'), + ), + TextSpan(text: 'ref'), + ], + ), + textDirection: TextDirection.ltr, + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.TextInlineWidgetTop.1.png'), + ); + }); + + testWidgets('Text Inline widget middle', (WidgetTester tester) async { + await tester.pumpWidget( + Theme( + data: ThemeData(useMaterial3: false), + child: Center( + child: RepaintBoundary( + child: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Container( + width: 400.0, + height: 200.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 200, maxHeight: 100), + child: const Text.rich( + TextSpan( + text: 'C ', + style: TextStyle( + fontSize: 16, + ), + children: <InlineSpan>[ + WidgetSpan( + alignment: PlaceholderAlignment.middle, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: true, onChanged: null), + ), + WidgetSpan( + child: Checkbox(value: false, onChanged: null), + ), + TextSpan(text: 'He ', style: TextStyle(fontSize: 20)), + WidgetSpan( + alignment: PlaceholderAlignment.middle, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 50.0, + height: 55.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffffff00), + ), + child: Center( + child:SizedBox( + width: 10.0, + height: 15.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: Color(0xffff0000), + ), + ), + ), + ), + ), + ), + ), + TextSpan(text: 'hello world! seize the day!'), + WidgetSpan( + alignment: PlaceholderAlignment.middle, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + alignment: PlaceholderAlignment.middle, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + alignment: PlaceholderAlignment.middle, + baseline: TextBaseline.alphabetic, + child: Checkbox(value: false, onChanged: null), + ), + WidgetSpan( + alignment: PlaceholderAlignment.middle, + baseline: TextBaseline.alphabetic, + child: SizedBox( + width: 20, + height: 20, + child: Checkbox(value: true, onChanged: null), + ), + ), + WidgetSpan( + alignment: PlaceholderAlignment.middle, + baseline: TextBaseline.alphabetic, + child: Text('embedded'), + ), + TextSpan(text: 'ref'), + ], + ), + textDirection: TextDirection.ltr, + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.TextInlineWidgetMiddle.1.png'), + ); + }); + + testWidgets('Text TextHeightBehavior', (WidgetTester tester) async { + await tester.pumpWidget( + Center( + child: RepaintBoundary( + child: Container( + width: 200.0, + height: 700.0, + decoration: const BoxDecoration( + color: Color(0xff00ff00), + ), + child: const Column( + children: <Widget>[ + Text('Hello\nLine 2\nLine 3', + textDirection: TextDirection.ltr, + style: TextStyle(height: 5), + ), + Text('Hello\nLine 2\nLine 3', + textDirection: TextDirection.ltr, + style: TextStyle(height: 5), + textHeightBehavior: TextHeightBehavior( + applyHeightToFirstAscent: false, + applyHeightToLastDescent: false, + ), + ), + Text('Hello', + textDirection: TextDirection.ltr, + style: TextStyle(height: 5), + textHeightBehavior: TextHeightBehavior( + applyHeightToFirstAscent: false, + ), + ), + ], + ), + ), + ), + ), + ); + await expectLater( + find.byType(Container), + matchesGoldenFile('text_golden.TextHeightBehavior.1.png'), + ); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_scaler_backward_compatibility_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_scaler_backward_compatibility_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..49d62b276236fc2e145eab34bb7bc061a7d33b54 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_scaler_backward_compatibility_test.dart @@ -0,0 +1,280 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// TODO(LongCatIsLooong): Remove this file once textScaleFactor is removed. +import 'package:flutter/foundation.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('TextStyle', () { + test('getTextSyle is backward compatible', () { + expect( + const TextStyle(fontSize: 14).getTextStyle(textScaleFactor: 2.0).toString(), + contains('fontSize: 28'), + ); + }, skip: kIsWeb); // [intended] CkTextStyle doesn't have a custom toString implementation. + }); + group('TextPainter', () { + test('textScaleFactor translates to textScaler', () { + final TextPainter textPainter = TextPainter( + text: const TextSpan(text: 'text'), + textDirection: TextDirection.ltr, + textScaleFactor: 42, + ); + + expect(textPainter.textScaler, const TextScaler.linear(42.0)); + + // Linear TextScaler translates to textScaleFactor. + textPainter.textScaler = const TextScaler.linear(12.0); + expect(textPainter.textScaleFactor, 12.0); + + textPainter.textScaleFactor = 10; + expect(textPainter.textScaler, const TextScaler.linear(10)); + }); + }); + + group('MediaQuery', () { + test('specifying both textScaler and textScalingFactor asserts', () { + expect( + () => MediaQueryData(textScaleFactor: 2, textScaler: const TextScaler.linear(2.0)), + throwsAssertionError, + ); + }); + + test('copyWith is backward compatible', () { + const MediaQueryData data = MediaQueryData(textScaler: TextScaler.linear(2.0)); + + final MediaQueryData data1 = data.copyWith(textScaleFactor: 42); + expect(data1.textScaler, const TextScaler.linear(42)); + expect(data1.textScaleFactor, 42); + + final MediaQueryData data2 = data.copyWith(textScaler: TextScaler.noScaling); + expect(data2.textScaler, TextScaler.noScaling); + expect(data2.textScaleFactor, 1.0); + }); + + test('copyWith specifying both textScaler and textScalingFactor asserts', () { + const MediaQueryData data = MediaQueryData(); + expect( + () => data.copyWith(textScaleFactor: 2, textScaler: const TextScaler.linear(2.0)), + throwsAssertionError, + ); + }); + + testWidgets('MediaQuery.textScaleFactorOf overriding compatibility', (WidgetTester tester) async { + late final double outsideTextScaleFactor; + late final TextScaler outsideTextScaler; + late final double insideTextScaleFactor; + late final TextScaler insideTextScaler; + + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + outsideTextScaleFactor = MediaQuery.textScaleFactorOf(context); + outsideTextScaler = MediaQuery.textScalerOf(context); + return MediaQuery( + data: const MediaQueryData( + textScaleFactor: 4.0, + ), + child: Builder( + builder: (BuildContext context) { + insideTextScaleFactor = MediaQuery.textScaleFactorOf(context); + insideTextScaler = MediaQuery.textScalerOf(context); + return Container(); + }, + ), + ); + }, + ), + ); + + // Overriding textScaleFactor should work for unmigrated widgets that are + // still using MediaQuery.textScaleFactorOf. Also if a unmigrated widget + // overrides MediaQuery.textScaleFactor, migrated widgets in the subtree + // should get the correct TextScaler. + expect(outsideTextScaleFactor, 1.0); + expect(outsideTextScaler.textScaleFactor, 1.0); + expect(outsideTextScaler, TextScaler.noScaling); + expect(insideTextScaleFactor, 4.0); + expect(insideTextScaler.textScaleFactor, 4.0); + expect(insideTextScaler, const TextScaler.linear(4.0)); + }); + + testWidgets('textScaleFactor overriding backward compatibility', (WidgetTester tester) async { + late final double outsideTextScaleFactor; + late final TextScaler outsideTextScaler; + late final double insideTextScaleFactor; + late final TextScaler insideTextScaler; + + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + outsideTextScaleFactor = MediaQuery.textScaleFactorOf(context); + outsideTextScaler = MediaQuery.textScalerOf(context); + return MediaQuery( + data: const MediaQueryData(textScaler: TextScaler.linear(4.0)), + child: Builder( + builder: (BuildContext context) { + insideTextScaleFactor = MediaQuery.textScaleFactorOf(context); + insideTextScaler = MediaQuery.textScalerOf(context); + return Container(); + }, + ), + ); + }, + ), + ); + + expect(outsideTextScaleFactor, 1.0); + expect(outsideTextScaler.textScaleFactor, 1.0); + expect(outsideTextScaler, TextScaler.noScaling); + expect(insideTextScaleFactor, 4.0); + expect(insideTextScaler.textScaleFactor, 4.0); + expect(insideTextScaler, const TextScaler.linear(4.0)); + }); + }); + + group('RenderObjects backward compatibility', () { + test('RenderEditable', () { + final RenderEditable renderObject = RenderEditable( + backgroundCursorColor: const Color.fromARGB(0xFF, 0xFF, 0x00, 0x00), + textDirection: TextDirection.ltr, + cursorColor: const Color.fromARGB(0xFF, 0xFF, 0x00, 0x00), + offset: ViewportOffset.zero(), + textSelectionDelegate: _FakeEditableTextState(), + text: const TextSpan( + text: 'test', + style: TextStyle(height: 1.0, fontSize: 10.0), + ), + startHandleLayerLink: LayerLink(), + endHandleLayerLink: LayerLink(), + selection: const TextSelection.collapsed(offset: 0), + ); + expect(renderObject.textScaleFactor, 1.0); + + renderObject.textScaleFactor = 3.0; + expect(renderObject.textScaleFactor, 3.0); + expect(renderObject.textScaler, const TextScaler.linear(3.0)); + + renderObject.textScaler = const TextScaler.linear(4.0); + expect(renderObject.textScaleFactor, 4.0); + }); + + test('RenderParagraph', () { + final RenderParagraph renderObject = RenderParagraph( + const TextSpan( + text: 'test', + style: TextStyle(height: 1.0, fontSize: 10.0), + ), + textDirection: TextDirection.ltr, + ); + expect(renderObject.textScaleFactor, 1.0); + + renderObject.textScaleFactor = 3.0; + expect(renderObject.textScaleFactor, 3.0); + expect(renderObject.textScaler, const TextScaler.linear(3.0)); + + renderObject.textScaler = const TextScaler.linear(4.0); + expect(renderObject.textScaleFactor, 4.0); + }); + }); + + group('Widgets backward compatibility', () { + testWidgets('RichText', (WidgetTester tester) async { + await tester.pumpWidget( + RichText( + textDirection: TextDirection.ltr, + text: const TextSpan(), + textScaleFactor: 2.0, + ), + ); + + expect( + tester.renderObject<RenderParagraph>(find.byType(RichText)).textScaler, + const TextScaler.linear(2.0), + ); + expect(tester.renderObject<RenderParagraph>(find.byType(RichText)).textScaleFactor, 2.0); + }); + + testWidgets('Text', (WidgetTester tester) async { + await tester.pumpWidget( + const Text( + 'text', + textDirection: TextDirection.ltr, + textScaleFactor: 2.0, + ), + ); + + expect( + tester.renderObject<RenderParagraph>(find.text('text')).textScaler, + const TextScaler.linear(2.0), + ); + }); + + testWidgets('EditableText', (WidgetTester tester) async { + final TextEditingController controller = TextEditingController(); + addTearDown(controller.dispose); + final FocusNode focusNode = FocusNode(debugLabel: 'EditableText Node'); + addTearDown(focusNode.dispose); + const TextStyle textStyle = TextStyle(); + const Color cursorColor = Color.fromARGB(0xFF, 0xFF, 0x00, 0x00); + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(), + child: Directionality( + textDirection: TextDirection.rtl, + child: EditableText( + backgroundCursorColor: cursorColor, + controller: controller, + focusNode: focusNode, + style: textStyle, + cursorColor: cursorColor, + textScaleFactor: 2.0, + ), + ), + ), + ); + + final RenderEditable renderEditable = tester.allRenderObjects.whereType<RenderEditable>().first; + expect( + renderEditable.textScaler, + const TextScaler.linear(2.0), + ); + }); + }); +} + +class _FakeEditableTextState with TextSelectionDelegate { + @override + TextEditingValue textEditingValue = TextEditingValue.empty; + + TextSelection? selection; + + @override + void hideToolbar([bool hideHandles = true]) { } + + @override + void userUpdateTextEditingValue(TextEditingValue value, SelectionChangedCause cause) { + selection = value.selection; + } + + @override + void bringIntoView(TextPosition position) { } + + @override + void cutSelection(SelectionChangedCause cause) { } + + @override + Future<void> pasteText(SelectionChangedCause cause) { + return Future<void>.value(); + } + + @override + void selectAll(SelectionChangedCause cause) { } + + @override + void copySelection(SelectionChangedCause cause) { } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_selection_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_selection_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..f0a08da5f6d6f6bc740230bebcbcf21ca5c1ff9c --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_selection_test.dart @@ -0,0 +1,2017 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show ValueListenable, defaultTargetPlatform; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; + +import 'clipboard_utils.dart'; +import 'editable_text_utils.dart'; + +const int kSingleTapUpTimeout = 500; + +void main() { + late int tapCount; + late int singleTapUpCount; + late int singleTapCancelCount; + late int singleLongTapStartCount; + late int doubleTapDownCount; + late int tripleTapDownCount; + late int forcePressStartCount; + late int forcePressEndCount; + late int dragStartCount; + late int dragUpdateCount; + late int dragEndCount; + const Offset forcePressOffset = Offset(400.0, 50.0); + + void handleTapDown(TapDragDownDetails details) { tapCount++; } + void handleSingleTapUp(TapDragUpDetails details) { singleTapUpCount++; } + void handleSingleTapCancel() { singleTapCancelCount++; } + void handleSingleLongTapStart(LongPressStartDetails details) { singleLongTapStartCount++; } + void handleDoubleTapDown(TapDragDownDetails details) { doubleTapDownCount++; } + void handleTripleTapDown(TapDragDownDetails details) { tripleTapDownCount++; } + void handleForcePressStart(ForcePressDetails details) { forcePressStartCount++; } + void handleForcePressEnd(ForcePressDetails details) { forcePressEndCount++; } + void handleDragSelectionStart(TapDragStartDetails details) { dragStartCount++; } + void handleDragSelectionUpdate(TapDragUpdateDetails details) { dragUpdateCount++; } + void handleDragSelectionEnd(TapDragEndDetails details) { dragEndCount++; } + + setUp(() { + tapCount = 0; + singleTapUpCount = 0; + singleTapCancelCount = 0; + singleLongTapStartCount = 0; + doubleTapDownCount = 0; + tripleTapDownCount = 0; + forcePressStartCount = 0; + forcePressEndCount = 0; + dragStartCount = 0; + dragUpdateCount = 0; + dragEndCount = 0; + }); + + Future<void> pumpGestureDetector(WidgetTester tester) async { + await tester.pumpWidget( + TextSelectionGestureDetector( + behavior: HitTestBehavior.opaque, + onTapDown: handleTapDown, + onSingleTapUp: handleSingleTapUp, + onSingleTapCancel: handleSingleTapCancel, + onSingleLongTapStart: handleSingleLongTapStart, + onDoubleTapDown: handleDoubleTapDown, + onTripleTapDown: handleTripleTapDown, + onForcePressStart: handleForcePressStart, + onForcePressEnd: handleForcePressEnd, + onDragSelectionStart: handleDragSelectionStart, + onDragSelectionUpdate: handleDragSelectionUpdate, + onDragSelectionEnd: handleDragSelectionEnd, + child: Container(), + ), + ); + } + + Future<void> pumpTextSelectionGestureDetectorBuilder( + WidgetTester tester, { + bool forcePressEnabled = true, + bool selectionEnabled = true, + }) async { + final GlobalKey<EditableTextState> editableTextKey = GlobalKey<EditableTextState>(); + final FakeTextSelectionGestureDetectorBuilderDelegate delegate = FakeTextSelectionGestureDetectorBuilderDelegate( + editableTextKey: editableTextKey, + forcePressEnabled: forcePressEnabled, + selectionEnabled: selectionEnabled, + ); + + final TextSelectionGestureDetectorBuilder provider = + TextSelectionGestureDetectorBuilder(delegate: delegate); + final TextEditingController controller = TextEditingController(); + addTearDown(controller.dispose); + final FocusNode focusNode = FocusNode(); + addTearDown(focusNode.dispose); + + await tester.pumpWidget( + MaterialApp( + home: provider.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: FakeEditableText( + key: editableTextKey, + controller: controller, + focusNode: focusNode, + ), + ), + ), + ); + } + + testWidgets('a series of taps all call onTaps', (WidgetTester tester) async { + await pumpGestureDetector(tester); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 150)); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 150)); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 150)); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 150)); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 150)); + await tester.tapAt(const Offset(200, 200)); + expect(tapCount, 6); + }); + + testWidgets('in a series of rapid taps, onTapDown, onDoubleTapDown, and onTripleTapDown alternate', (WidgetTester tester) async { + await pumpGestureDetector(tester); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 50)); + expect(singleTapUpCount, 1); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 50)); + expect(singleTapUpCount, 1); + expect(doubleTapDownCount, 1); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 50)); + expect(singleTapUpCount, 1); + expect(doubleTapDownCount, 1); + expect(tripleTapDownCount, 1); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 50)); + expect(singleTapUpCount, 2); + expect(doubleTapDownCount, 1); + expect(tripleTapDownCount, 1); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 50)); + expect(singleTapUpCount, 2); + expect(doubleTapDownCount, 2); + expect(tripleTapDownCount, 1); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 50)); + expect(singleTapUpCount, 2); + expect(doubleTapDownCount, 2); + expect(tripleTapDownCount, 2); + await tester.tapAt(const Offset(200, 200)); + expect(singleTapUpCount, 3); + expect(doubleTapDownCount, 2); + expect(tripleTapDownCount, 2); + expect(tapCount, 7); + }); + + testWidgets('quick tap-tap-hold is a double tap down', (WidgetTester tester) async { + await pumpGestureDetector(tester); + await tester.tapAt(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 50)); + expect(singleTapUpCount, 1); + final TestGesture gesture = await tester.startGesture(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 200)); + expect(singleTapUpCount, 1); + // Every down is counted. + expect(tapCount, 2); + // No cancels because the second tap of the double tap is a second successful + // single tap behind the scene. + expect(singleTapCancelCount, 0); + expect(doubleTapDownCount, 1); + // The double tap down hold supersedes the single tap down. + expect(singleLongTapStartCount, 0); + + await gesture.up(); + // Nothing else happens on up. + expect(singleTapUpCount, 1); + expect(tapCount, 2); + expect(singleTapCancelCount, 0); + expect(doubleTapDownCount, 1); + expect(singleLongTapStartCount, 0); + }); + + testWidgets('a very quick swipe is ignored', (WidgetTester tester) async { + await pumpGestureDetector(tester); + final TestGesture gesture = await tester.startGesture(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 20)); + await gesture.moveBy(const Offset(100, 100)); + await tester.pump(); + expect(singleTapUpCount, 0); + // Before the move to TapAndDragGestureRecognizer the tapCount was 0 because the + // TapGestureRecognizer rejected itself when the initial pointer moved past a certain + // threshold. With TapAndDragGestureRecognizer, we have two thresholds, a normal tap + // threshold, and a drag threshold, so it is possible for the tap count to increase + // even though the original pointer has moved beyond the tap threshold. + expect(tapCount, 1); + expect(singleTapCancelCount, 0); + expect(doubleTapDownCount, 0); + expect(singleLongTapStartCount, 0); + + await gesture.up(); + // Nothing else happens on up. + expect(singleTapUpCount, 0); + expect(tapCount, 1); + expect(singleTapCancelCount, 0); + expect(doubleTapDownCount, 0); + expect(singleLongTapStartCount, 0); + }); + + testWidgets('a slower swipe has a tap down and a canceled tap', (WidgetTester tester) async { + await pumpGestureDetector(tester); + final TestGesture gesture = await tester.startGesture(const Offset(200, 200)); + await tester.pump(const Duration(milliseconds: 120)); + await gesture.moveBy(const Offset(100, 100)); + await tester.pump(); + expect(singleTapUpCount, 0); + expect(tapCount, 1); + expect(singleTapCancelCount, 0); + expect(doubleTapDownCount, 0); + expect(singleLongTapStartCount, 0); + }); + + testWidgets('a force press initiates a force press', (WidgetTester tester) async { + await pumpGestureDetector(tester); + + final int pointerValue = tester.nextPointer; + + final TestGesture gesture = await tester.createGesture(); + + await gesture.downWithCustomEvent( + forcePressOffset, + PointerDownEvent( + pointer: pointerValue, + position: forcePressOffset, + pressure: 0.0, + pressureMax: 6.0, + pressureMin: 0.0, + ), + ); + + await gesture.updateWithCustomEvent(PointerMoveEvent( + pointer: pointerValue, + pressure: 0.5, + pressureMin: 0, + )); + await gesture.up(); + await tester.pumpAndSettle(); + + await gesture.downWithCustomEvent( + forcePressOffset, + PointerDownEvent( + pointer: pointerValue, + position: forcePressOffset, + pressure: 0.0, + pressureMax: 6.0, + pressureMin: 0.0, + ), + ); + await gesture.updateWithCustomEvent(PointerMoveEvent( + pointer: pointerValue, + pressure: 0.5, + pressureMin: 0, + )); + await gesture.up(); + await tester.pump(const Duration(milliseconds: 20)); + + await gesture.downWithCustomEvent( + forcePressOffset, + PointerDownEvent( + pointer: pointerValue, + position: forcePressOffset, + pressure: 0.0, + pressureMax: 6.0, + pressureMin: 0.0, + ), + ); + await gesture.updateWithCustomEvent(PointerMoveEvent( + pointer: pointerValue, + pressure: 0.5, + pressureMin: 0, + )); + await gesture.up(); + await tester.pump(const Duration(milliseconds: 20)); + + await gesture.downWithCustomEvent( + forcePressOffset, + PointerDownEvent( + pointer: pointerValue, + position: forcePressOffset, + pressure: 0.0, + pressureMax: 6.0, + pressureMin: 0.0, + ), + ); + await gesture.updateWithCustomEvent(PointerMoveEvent( + pointer: pointerValue, + pressure: 0.5, + pressureMin: 0, + )); + await gesture.up(); + + expect(forcePressStartCount, 4); + }); + + testWidgets('a tap and then force press initiates a force press and not a double tap', (WidgetTester tester) async { + await pumpGestureDetector(tester); + + final int pointerValue = tester.nextPointer; + final TestGesture gesture = await tester.createGesture(); + await gesture.downWithCustomEvent( + forcePressOffset, + PointerDownEvent( + pointer: pointerValue, + position: forcePressOffset, + pressure: 0.0, + pressureMax: 6.0, + pressureMin: 0.0, + ), + + ); + // Initiate a quick tap. + await gesture.updateWithCustomEvent( + PointerMoveEvent( + pointer: pointerValue, + pressure: 0.0, + pressureMin: 0, + ), + ); + await tester.pump(const Duration(milliseconds: 50)); + await gesture.up(); + + // Initiate a force tap. + await gesture.downWithCustomEvent( + forcePressOffset, + PointerDownEvent( + pointer: pointerValue, + position: forcePressOffset, + pressure: 0.0, + pressureMax: 6.0, + pressureMin: 0.0, + ), + ); + await gesture.updateWithCustomEvent(PointerMoveEvent( + pointer: pointerValue, + pressure: 0.5, + pressureMin: 0, + )); + expect(forcePressStartCount, 1); + + await tester.pump(const Duration(milliseconds: 50)); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(forcePressEndCount, 1); + expect(doubleTapDownCount, 0); + }); + + testWidgets('a long press from a touch device is recognized as a long single tap', (WidgetTester tester) async { + await pumpGestureDetector(tester); + + final int pointerValue = tester.nextPointer; + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: pointerValue, + ); + await tester.pump(const Duration(seconds: 2)); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(tapCount, 1); + expect(singleTapUpCount, 0); + expect(singleLongTapStartCount, 1); + }); + + testWidgets('a long press from a mouse is just a tap', (WidgetTester tester) async { + await pumpGestureDetector(tester); + + final int pointerValue = tester.nextPointer; + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: pointerValue, + kind: PointerDeviceKind.mouse, + ); + await tester.pump(const Duration(seconds: 2)); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(tapCount, 1); + expect(singleTapUpCount, 1); + expect(singleLongTapStartCount, 0); + }); + + testWidgets('a touch drag is recognized for text selection', (WidgetTester tester) async { + await pumpGestureDetector(tester); + + final int pointerValue = tester.nextPointer; + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: pointerValue, + ); + await tester.pump(); + await gesture.moveBy(const Offset(210.0, 200.0)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(tapCount, 1); + expect(singleTapUpCount, 0); + expect(singleTapCancelCount, 0); + expect(dragStartCount, 1); + expect(dragUpdateCount, 1); + expect(dragEndCount, 1); + }); + + testWidgets('a mouse drag is recognized for text selection', (WidgetTester tester) async { + await pumpGestureDetector(tester); + + final int pointerValue = tester.nextPointer; + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: pointerValue, + kind: PointerDeviceKind.mouse, + ); + await tester.pump(); + await gesture.moveBy(const Offset(210.0, 200.0)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + // The tap and drag gesture recognizer will detect the tap down, but not the tap up. + expect(tapCount, 1); + expect(singleTapCancelCount, 0); + expect(singleTapUpCount, 0); + + expect(dragStartCount, 1); + expect(dragUpdateCount, 1); + expect(dragEndCount, 1); + }); + + testWidgets('a slow mouse drag is still recognized for text selection', (WidgetTester tester) async { + await pumpGestureDetector(tester); + + final int pointerValue = tester.nextPointer; + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: pointerValue, + kind: PointerDeviceKind.mouse, + ); + await tester.pump(const Duration(seconds: 2)); + await gesture.moveBy(const Offset(210.0, 200.0)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + // The tap and drag gesture recognizer will detect the tap down, but not the tap up. + expect(tapCount, 1); + expect(singleTapCancelCount, 0); + expect(singleTapUpCount, 0); + + expect(dragStartCount, 1); + expect(dragUpdateCount, 1); + expect(dragEndCount, 1); + }); + + testWidgets('test TextSelectionGestureDetectorBuilder long press on Apple Platforms - focused renderEditable', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester); + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + renderEditable.hasFocus = true; + + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: 0, + ); + await tester.pump(const Duration(seconds: 2)); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(state.showToolbarCalled, isTrue); + expect(renderEditable.selectPositionAtCalled, isTrue); + expect(renderEditable.lastCause, SelectionChangedCause.longPress); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); + + testWidgets('test TextSelectionGestureDetectorBuilder long press on iOS - renderEditable not focused', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester); + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: 0, + ); + await tester.pump(const Duration(seconds: 2)); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(state.showToolbarCalled, isTrue); + expect(renderEditable.selectWordCalled, isTrue); + expect(renderEditable.lastCause, SelectionChangedCause.longPress); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS })); + + testWidgets('test TextSelectionGestureDetectorBuilder long press on non-Apple Platforms', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester); + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: 0, + ); + await tester.pump(const Duration(seconds: 2)); + await gesture.up(); + await tester.pumpAndSettle(); + + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + expect(state.showToolbarCalled, isTrue); + expect(renderEditable.selectWordCalled, isTrue); + expect(renderEditable.lastCause, SelectionChangedCause.longPress); + }, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); + + testWidgets('TextSelectionGestureDetectorBuilder right click Apple platforms', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/80119 + await pumpTextSelectionGestureDetectorBuilder(tester); + + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + renderEditable.text = const TextSpan(text: 'one two three four five six seven'); + await tester.pump(); + + final TestGesture gesture = await tester.createGesture( + pointer: 0, + kind: PointerDeviceKind.mouse, + buttons: kSecondaryButton, + ); + + // Get the location of the 10th character + final Offset charLocation = renderEditable + .getLocalRectForCaret(const TextPosition(offset: 10)).center; + final Offset globalCharLocation = charLocation + tester.getTopLeft(find.byType(FakeEditable)); + + // Right clicking on a word should select it + await gesture.down(globalCharLocation); + await gesture.up(); + await tester.pump(); + expect(renderEditable.selectWordCalled, isTrue); + expect(renderEditable.lastCause, SelectionChangedCause.tap); + + // Right clicking on a word within a selection shouldn't change the selection + renderEditable.selectWordCalled = false; + renderEditable.selection = const TextSelection(baseOffset: 3, extentOffset: 20); + await gesture.down(globalCharLocation); + await gesture.up(); + await tester.pump(); + expect(renderEditable.selectWordCalled, isFalse); + + // Right clicking on a word within a reverse (right-to-left) selection shouldn't change the selection + renderEditable.selectWordCalled = false; + renderEditable.selection = const TextSelection(baseOffset: 20, extentOffset: 3); + await gesture.down(globalCharLocation); + await gesture.up(); + await tester.pump(); + expect(renderEditable.selectWordCalled, isFalse); + }, + variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }), + ); + + testWidgets('TextSelectionGestureDetectorBuilder right click non-Apple platforms', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/80119 + await pumpTextSelectionGestureDetectorBuilder(tester); + + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + renderEditable.text = const TextSpan(text: 'one two three four five six seven'); + await tester.pump(); + + final TestGesture gesture = await tester.createGesture( + pointer: 0, + kind: PointerDeviceKind.mouse, + buttons: kSecondaryButton, + ); + + // Get the location of the 10th character + final Offset charLocation = renderEditable + .getLocalRectForCaret(const TextPosition(offset: 10)).center; + final Offset globalCharLocation = charLocation + tester.getTopLeft(find.byType(FakeEditable)); + + // Right clicking on an unfocused field should place the cursor, not select + // the word. + await gesture.down(globalCharLocation); + await gesture.up(); + await tester.pump(); + expect(renderEditable.selectWordCalled, isFalse); + expect(renderEditable.selectPositionCalled, isTrue); + + // Right clicking on a focused field with selection shouldn't change the + // selection. + renderEditable.selectPositionCalled = false; + renderEditable.selection = const TextSelection(baseOffset: 3, extentOffset: 20); + renderEditable.hasFocus = true; + await gesture.down(globalCharLocation); + await gesture.up(); + await tester.pump(); + expect(renderEditable.selectWordCalled, isFalse); + expect(renderEditable.selectPositionCalled, isFalse); + + // Right clicking on a focused field with a reverse (right to left) + // selection shouldn't change the selection. + renderEditable.selection = const TextSelection(baseOffset: 20, extentOffset: 3); + await gesture.down(globalCharLocation); + await gesture.up(); + await tester.pump(); + expect(renderEditable.selectWordCalled, isFalse); + expect(renderEditable.selectPositionCalled, isFalse); + }, + variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia, TargetPlatform.linux, TargetPlatform.windows }), + ); + + testWidgets('test TextSelectionGestureDetectorBuilder tap', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester); + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: 0, + ); + await gesture.up(); + await tester.pumpAndSettle(); + + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + expect(state.showToolbarCalled, isFalse); + + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + expect(renderEditable.selectWordEdgeCalled, isTrue); + expect(renderEditable.lastCause, SelectionChangedCause.tap); + case TargetPlatform.macOS: + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + expect(renderEditable.selectPositionAtCalled, isTrue); + expect(renderEditable.lastCause, SelectionChangedCause.tap); + } + }, variant: TargetPlatformVariant.all()); + + testWidgets('test TextSelectionGestureDetectorBuilder toggles toolbar on single tap on previous selection iOS', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester); + + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + expect(state.showToolbarCalled, isFalse); + expect(state.toggleToolbarCalled, isFalse); + renderEditable.selection = const TextSelection(baseOffset: 2, extentOffset: 6); + renderEditable.hasFocus = true; + + final TestGesture gesture = await tester.startGesture( + const Offset(25.0, 200.0), + pointer: 0, + ); + await gesture.up(); + await tester.pumpAndSettle(); + + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + expect(renderEditable.selectWordEdgeCalled, isFalse); + expect(state.toggleToolbarCalled, isTrue); + case TargetPlatform.macOS: + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + expect(renderEditable.selectPositionAtCalled, isTrue); + expect(renderEditable.lastCause, SelectionChangedCause.tap); + } + }, variant: TargetPlatformVariant.all()); + + + testWidgets('test TextSelectionGestureDetectorBuilder shows spell check toolbar on single tap on Android', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester); + + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + expect(state.showSpellCheckSuggestionsToolbarCalled, isFalse); + renderEditable.selection = const TextSelection(baseOffset: 2, extentOffset: 6); + renderEditable.hasFocus = true; + + final TestGesture gesture = await tester.startGesture( + const Offset(25.0, 200.0), + pointer: 0, + ); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(state.showSpellCheckSuggestionsToolbarCalled, isTrue); + + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android })); + + testWidgets('test TextSelectionGestureDetectorBuilder shows spell check toolbar on single tap on iOS if word misspelled and text selection toolbar on additonal taps', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester); + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + const TextSelection selection = TextSelection.collapsed(offset: 1); + state.updateEditingValue(const TextEditingValue(text: 'something misspelled', selection: selection)); + + // Mark word to be tapped as misspelled for testing. + state.markCurrentSelectionAsMisspelled = true; + await tester.pump(); + + // Test spell check suggestions toolbar is shown on first tap of misspelled word. + const Offset position = Offset(25.0, 200.0); + await tester.tapAt(position); + await tester.pumpAndSettle(); + + expect(state.showSpellCheckSuggestionsToolbarCalled, isTrue); + + // Reset and test text selection toolbar is toggled for additional taps. + state.showSpellCheckSuggestionsToolbarCalled = false; + renderEditable.selection = selection; + await tester.pump(const Duration(milliseconds: kSingleTapUpTimeout)); + + // Test first tap. + await tester.tapAt(position); + await tester.pumpAndSettle(); + + expect(state.showSpellCheckSuggestionsToolbarCalled, isFalse); + expect(state.toggleToolbarCalled, isTrue); + + // Reset and test second tap. + state.toggleToolbarCalled = false; + await tester.pump(const Duration(milliseconds: kSingleTapUpTimeout)); + + await tester.tapAt(position); + await tester.pumpAndSettle(); + + expect(state.showSpellCheckSuggestionsToolbarCalled, isFalse); + expect(state.toggleToolbarCalled, isTrue); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS })); + + testWidgets('test TextSelectionGestureDetectorBuilder double tap', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester); + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: 0, + ); + await tester.pump(const Duration(milliseconds: 50)); + await gesture.up(); + await gesture.down(const Offset(200.0, 200.0)); + await tester.pump(const Duration(milliseconds: 50)); + await gesture.up(); + await tester.pumpAndSettle(); + + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + expect(state.showToolbarCalled, isTrue); + expect(renderEditable.selectWordCalled, isTrue); + expect(renderEditable.lastCause, SelectionChangedCause.doubleTap); + }); + + testWidgets('test TextSelectionGestureDetectorBuilder forcePress enabled', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester); + final TestGesture gesture = await tester.createGesture(); + await gesture.downWithCustomEvent( + const Offset(200.0, 200.0), + const PointerDownEvent( + position: Offset(200.0, 200.0), + pressure: 3.0, + pressureMax: 6.0, + pressureMin: 0.0, + ), + ); + await gesture.updateWithCustomEvent( + const PointerUpEvent( + position: Offset(200.0, 200.0), + pressureMax: 6.0, + pressureMin: 0.0, + ), + ); + await tester.pump(); + + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + expect(state.showToolbarCalled, isTrue); + expect(renderEditable.selectWordsInRangeCalled, isTrue); + }); + + testWidgets('Mouse drag does not show handles nor toolbar', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/69001 + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: SelectableText('I love Flutter!'), + ), + ), + ); + + final Offset textFieldStart = tester.getTopLeft(find.byType(SelectableText)); + + final TestGesture gesture = await tester.startGesture(textFieldStart, kind: PointerDeviceKind.mouse); + await tester.pump(); + await gesture.moveTo(textFieldStart + const Offset(50.0, 0)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + final EditableTextState editableText = tester.state(find.byType(EditableText)); + expect(editableText.selectionOverlay!.handlesAreVisible, isFalse); + expect(editableText.selectionOverlay!.toolbarIsVisible, isFalse); + }); + + testWidgets('Mouse drag selects and cannot drag cursor', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/102928 + final TextEditingController controller = TextEditingController( + text: 'I love flutter!', + ); + addTearDown(controller.dispose); + final GlobalKey<EditableTextState> editableTextKey = GlobalKey<EditableTextState>(); + final FakeTextSelectionGestureDetectorBuilderDelegate delegate = FakeTextSelectionGestureDetectorBuilderDelegate( + editableTextKey: editableTextKey, + forcePressEnabled: false, + selectionEnabled: true, + ); + final TextSelectionGestureDetectorBuilder provider = + TextSelectionGestureDetectorBuilder(delegate: delegate); + final FocusNode focusNode = FocusNode(); + addTearDown(focusNode.dispose); + + await tester.pumpWidget( + MaterialApp( + home: provider.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: EditableText( + key: editableTextKey, + controller: controller, + focusNode: focusNode, + backgroundCursorColor: Colors.white, + cursorColor: Colors.white, + style: const TextStyle(), + selectionControls: materialTextSelectionControls, + ), + ), + ), + ); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, -1); + + final Offset position = textOffsetToPosition(tester, 4); + + await tester.tapAt(position); + // Don't do a double tap drag. + await tester.pump(const Duration(milliseconds: 300)); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, 4); + + final TestGesture gesture = await tester.startGesture(position, kind: PointerDeviceKind.mouse); + + // Checking that double-tap was not registered. + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, 4); + + addTearDown(gesture.removePointer); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, 7)); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, 10)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(controller.selection.isCollapsed, isFalse); + expect(controller.selection.baseOffset, 4); + expect(controller.selection.extentOffset, 10); + }); + + testWidgets('Touch drag moves the cursor', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/102928 + final TextEditingController controller = TextEditingController( + text: 'I love flutter!', + ); + addTearDown(controller.dispose); + final GlobalKey<EditableTextState> editableTextKey = GlobalKey<EditableTextState>(); + final FakeTextSelectionGestureDetectorBuilderDelegate delegate = FakeTextSelectionGestureDetectorBuilderDelegate( + editableTextKey: editableTextKey, + forcePressEnabled: false, + selectionEnabled: true, + ); + final TextSelectionGestureDetectorBuilder provider = + TextSelectionGestureDetectorBuilder(delegate: delegate); + final FocusNode focusNode = FocusNode(); + addTearDown(focusNode.dispose); + + await tester.pumpWidget( + MaterialApp( + home: provider.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: EditableText( + key: editableTextKey, + controller: controller, + focusNode: focusNode, + backgroundCursorColor: Colors.white, + cursorColor: Colors.white, + style: const TextStyle(), + selectionControls: materialTextSelectionControls, + ), + ), + ), + ); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, -1); + + final Offset position = textOffsetToPosition(tester, 4); + + await tester.tapAt(position); + await tester.pump(); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, 4); + + final TestGesture gesture = await tester.startGesture(position); + addTearDown(gesture.removePointer); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, 7)); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, 10)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, 10); + }); + + testWidgets('Stylus drag moves the cursor', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/102928 + final TextEditingController controller = TextEditingController( + text: 'I love flutter!', + ); + addTearDown(controller.dispose); + final GlobalKey<EditableTextState> editableTextKey = GlobalKey<EditableTextState>(); + final FakeTextSelectionGestureDetectorBuilderDelegate delegate = FakeTextSelectionGestureDetectorBuilderDelegate( + editableTextKey: editableTextKey, + forcePressEnabled: false, + selectionEnabled: true, + ); + final TextSelectionGestureDetectorBuilder provider = + TextSelectionGestureDetectorBuilder(delegate: delegate); + final FocusNode focusNode = FocusNode(); + addTearDown(focusNode.dispose); + + await tester.pumpWidget( + MaterialApp( + home: provider.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: EditableText( + key: editableTextKey, + controller: controller, + focusNode: focusNode, + backgroundCursorColor: Colors.white, + cursorColor: Colors.white, + style: const TextStyle(), + selectionControls: materialTextSelectionControls, + ), + ), + ), + ); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, -1); + + final Offset position = textOffsetToPosition(tester, 4); + + await tester.tapAt(position); + await tester.pump(); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, 4); + + final TestGesture gesture = await tester.startGesture(position, kind: PointerDeviceKind.stylus); + addTearDown(gesture.removePointer); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, 7)); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, 10)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, 10); + }); + + testWidgets('Drag of unknown type moves the cursor', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/102928 + final TextEditingController controller = TextEditingController( + text: 'I love flutter!', + ); + addTearDown(controller.dispose); + final GlobalKey<EditableTextState> editableTextKey = GlobalKey<EditableTextState>(); + final FakeTextSelectionGestureDetectorBuilderDelegate delegate = FakeTextSelectionGestureDetectorBuilderDelegate( + editableTextKey: editableTextKey, + forcePressEnabled: false, + selectionEnabled: true, + ); + final TextSelectionGestureDetectorBuilder provider = + TextSelectionGestureDetectorBuilder(delegate: delegate); + final FocusNode focusNode = FocusNode(); + addTearDown(focusNode.dispose); + + await tester.pumpWidget( + MaterialApp( + home: provider.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: EditableText( + key: editableTextKey, + controller: controller, + focusNode: focusNode, + backgroundCursorColor: Colors.white, + cursorColor: Colors.white, + style: const TextStyle(), + selectionControls: materialTextSelectionControls, + ), + ), + ), + ); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, -1); + + final Offset position = textOffsetToPosition(tester, 4); + + await tester.tapAt(position); + await tester.pump(); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, 4); + + final TestGesture gesture = await tester.startGesture(position, kind: PointerDeviceKind.unknown); + addTearDown(gesture.removePointer); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, 7)); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, 10)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, 10); + }); + + testWidgets('test TextSelectionGestureDetectorBuilder drag with RenderEditable viewport offset change', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + + // Reconfigure the RenderEditable for multi-line. + renderEditable.maxLines = null; + final ViewportOffset offset1 = ViewportOffset.fixed(20.0); + addTearDown(offset1.dispose); + renderEditable.offset = offset1; + renderEditable.layout(const BoxConstraints.tightFor(width: 400, height: 300.0)); + await tester.pumpAndSettle(); + + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + kind: PointerDeviceKind.mouse, + ); + await tester.pumpAndSettle(); + expect(renderEditable.selectPositionAtCalled, isFalse); + + await gesture.moveTo(const Offset(300.0, 200.0)); + await tester.pumpAndSettle(); + expect(renderEditable.selectPositionAtCalled, isTrue); + expect(renderEditable.selectPositionAtFrom, const Offset(200.0, 200.0)); + expect(renderEditable.selectPositionAtTo, const Offset(300.0, 200.0)); + + // Move the viewport offset (scroll). + final ViewportOffset offset2 = ViewportOffset.fixed(150.0); + addTearDown(offset2.dispose); + renderEditable.offset = offset2; + renderEditable.layout(const BoxConstraints.tightFor(width: 400, height: 300.0)); + await tester.pumpAndSettle(); + + await gesture.moveTo(const Offset(300.0, 400.0)); + await tester.pumpAndSettle(); + await gesture.up(); + await tester.pumpAndSettle(); + expect(renderEditable.selectPositionAtCalled, isTrue); + expect(renderEditable.selectPositionAtFrom, const Offset(200.0, 70.0)); + expect(renderEditable.selectPositionAtTo, const Offset(300.0, 400.0)); + }); + + testWidgets('test TextSelectionGestureDetectorBuilder selection disabled', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester, selectionEnabled: false); + final TestGesture gesture = await tester.startGesture( + const Offset(200.0, 200.0), + pointer: 0, + ); + await tester.pump(const Duration(seconds: 2)); + await gesture.up(); + await tester.pumpAndSettle(); + + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + expect(state.showToolbarCalled, isTrue); + expect(renderEditable.selectWordsInRangeCalled, isFalse); + }); + + testWidgets('test TextSelectionGestureDetectorBuilder mouse drag disabled', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester, selectionEnabled: false); + final TestGesture gesture = await tester.startGesture( + Offset.zero, + kind: PointerDeviceKind.mouse, + ); + await tester.pump(); + await gesture.moveTo(const Offset(50.0, 0)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + expect(renderEditable.selectPositionAtCalled, isFalse); + }); + + testWidgets('test TextSelectionGestureDetectorBuilder forcePress disabled', (WidgetTester tester) async { + await pumpTextSelectionGestureDetectorBuilder(tester, forcePressEnabled: false); + final TestGesture gesture = await tester.createGesture(); + await gesture.downWithCustomEvent( + const Offset(200.0, 200.0), + const PointerDownEvent( + position: Offset(200.0, 200.0), + pressure: 3.0, + pressureMax: 6.0, + pressureMin: 0.0, + ), + ); + await gesture.up(); + await tester.pump(); + + final FakeEditableTextState state = tester.state(find.byType(FakeEditableText)); + final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); + expect(state.showToolbarCalled, isFalse); + expect(renderEditable.selectWordsInRangeCalled, isFalse); + }); + + // Regression test for https://github.com/flutter/flutter/issues/37032. + testWidgets("selection handle's GestureDetector should not cover the entire screen", (WidgetTester tester) async { + final TextEditingController controller = TextEditingController(text: 'a'); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: TextField( + autofocus: true, + controller: controller, + ), + ), + ), + ); + + await tester.pumpAndSettle(); + + final Finder gestureDetector = find.descendant( + of: find.byType(CompositedTransformFollower), + matching: find.descendant( + of: find.byType(FadeTransition), + matching: find.byType(RawGestureDetector), + ), + ); + + expect(gestureDetector, findsOneWidget); + // The GestureDetector's size should not exceed that of the TextField. + final Rect hitRect = tester.getRect(gestureDetector); + final Rect textFieldRect = tester.getRect(find.byType(TextField)); + + expect(hitRect.size.width, lessThan(textFieldRect.size.width)); + expect(hitRect.size.height, lessThan(textFieldRect.size.height)); + }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS })); + + group('SelectionOverlay', () { + Future<SelectionOverlay> pumpApp(WidgetTester tester, { + ValueChanged<DragStartDetails>? onStartDragStart, + ValueChanged<DragUpdateDetails>? onStartDragUpdate, + ValueChanged<DragEndDetails>? onStartDragEnd, + ValueChanged<DragStartDetails>? onEndDragStart, + ValueChanged<DragUpdateDetails>? onEndDragUpdate, + ValueChanged<DragEndDetails>? onEndDragEnd, + VoidCallback? onSelectionHandleTapped, + TextSelectionControls? selectionControls, + TextMagnifierConfiguration? magnifierConfiguration, + }) async { + final UniqueKey column = UniqueKey(); + final LayerLink startHandleLayerLink = LayerLink(); + final LayerLink endHandleLayerLink = LayerLink(); + final LayerLink toolbarLayerLink = LayerLink(); + await tester.pumpWidget(MaterialApp( + home: Column( + key: column, + children: <Widget>[ + CompositedTransformTarget( + link: startHandleLayerLink, + child: const Text('start handle'), + ), + CompositedTransformTarget( + link: endHandleLayerLink, + child: const Text('end handle'), + ), + CompositedTransformTarget( + link: toolbarLayerLink, + child: const Text('toolbar'), + ), + ], + ), + )); + + final FakeClipboardStatusNotifier clipboardStatus = FakeClipboardStatusNotifier(); + addTearDown(clipboardStatus.dispose); + + return SelectionOverlay( + context: tester.element(find.byKey(column)), + onSelectionHandleTapped: onSelectionHandleTapped, + startHandleType: TextSelectionHandleType.collapsed, + startHandleLayerLink: startHandleLayerLink, + lineHeightAtStart: 0.0, + onStartHandleDragStart: onStartDragStart, + onStartHandleDragUpdate: onStartDragUpdate, + onStartHandleDragEnd: onStartDragEnd, + endHandleType: TextSelectionHandleType.collapsed, + endHandleLayerLink: endHandleLayerLink, + lineHeightAtEnd: 0.0, + onEndHandleDragStart: onEndDragStart, + onEndHandleDragUpdate: onEndDragUpdate, + onEndHandleDragEnd: onEndDragEnd, + clipboardStatus: clipboardStatus, + selectionDelegate: FakeTextSelectionDelegate(), + selectionControls: selectionControls, + selectionEndpoints: const <TextSelectionPoint>[], + toolbarLayerLink: toolbarLayerLink, + magnifierConfiguration: magnifierConfiguration ?? TextMagnifierConfiguration.disabled, + ); + } + + testWidgets('dispatches memory events', (WidgetTester tester) async { + await expectLater( + await memoryEvents( + () async { + final SelectionOverlay overlay = await pumpApp(tester); + overlay.dispose(); + }, + SelectionOverlay, + ), + areCreateAndDispose, + ); + }); + + testWidgets('can show and hide handles', (WidgetTester tester) async { + final TextSelectionControlsSpy spy = TextSelectionControlsSpy(); + final SelectionOverlay selectionOverlay = await pumpApp( + tester, + selectionControls: spy, + ); + selectionOverlay + ..startHandleType = TextSelectionHandleType.left + ..endHandleType = TextSelectionHandleType.right + ..selectionEndpoints = const <TextSelectionPoint>[ + TextSelectionPoint(Offset(10, 10), TextDirection.ltr), + TextSelectionPoint(Offset(20, 20), TextDirection.ltr), + ]; + selectionOverlay.showHandles(); + await tester.pump(); + expect(find.byKey(spy.leftHandleKey), findsOneWidget); + expect(find.byKey(spy.rightHandleKey), findsOneWidget); + + selectionOverlay.hideHandles(); + await tester.pump(); + expect(find.byKey(spy.leftHandleKey), findsNothing); + expect(find.byKey(spy.rightHandleKey), findsNothing); + + selectionOverlay.showToolbar(); + await tester.pump(); + expect(find.byKey(spy.toolBarKey), findsOneWidget); + + selectionOverlay.hideToolbar(); + await tester.pump(); + expect(find.byKey(spy.toolBarKey), findsNothing); + + selectionOverlay.showHandles(); + selectionOverlay.showToolbar(); + await tester.pump(); + expect(find.byKey(spy.leftHandleKey), findsOneWidget); + expect(find.byKey(spy.rightHandleKey), findsOneWidget); + expect(find.byKey(spy.toolBarKey), findsOneWidget); + + selectionOverlay.hide(); + await tester.pump(); + expect(find.byKey(spy.leftHandleKey), findsNothing); + expect(find.byKey(spy.rightHandleKey), findsNothing); + expect(find.byKey(spy.toolBarKey), findsNothing); + + selectionOverlay.dispose(); + await tester.pumpAndSettle(); + }); + + testWidgets('only paints one collapsed handle', (WidgetTester tester) async { + final TextSelectionControlsSpy spy = TextSelectionControlsSpy(); + final SelectionOverlay selectionOverlay = await pumpApp( + tester, + selectionControls: spy, + ); + selectionOverlay + ..startHandleType = TextSelectionHandleType.collapsed + ..endHandleType = TextSelectionHandleType.collapsed + ..selectionEndpoints = const <TextSelectionPoint>[ + TextSelectionPoint(Offset(10, 10), TextDirection.ltr), + TextSelectionPoint(Offset(20, 20), TextDirection.ltr), + ]; + selectionOverlay.showHandles(); + await tester.pump(); + expect(find.byKey(spy.leftHandleKey), findsNothing); + expect(find.byKey(spy.rightHandleKey), findsNothing); + expect(find.byKey(spy.collapsedHandleKey), findsOneWidget); + + selectionOverlay.dispose(); + await tester.pumpAndSettle(); + }); + + testWidgets('can change handle parameter', (WidgetTester tester) async { + final TextSelectionControlsSpy spy = TextSelectionControlsSpy(); + final SelectionOverlay selectionOverlay = await pumpApp( + tester, + selectionControls: spy, + ); + selectionOverlay + ..startHandleType = TextSelectionHandleType.left + ..lineHeightAtStart = 10.0 + ..endHandleType = TextSelectionHandleType.right + ..lineHeightAtEnd = 11.0 + ..selectionEndpoints = const <TextSelectionPoint>[ + TextSelectionPoint(Offset(10, 10), TextDirection.ltr), + TextSelectionPoint(Offset(20, 20), TextDirection.ltr), + ]; + selectionOverlay.showHandles(); + await tester.pump(); + Text leftHandle = tester.widget(find.byKey(spy.leftHandleKey)) as Text; + Text rightHandle = tester.widget(find.byKey(spy.rightHandleKey)) as Text; + expect(leftHandle.data, 'height 10'); + expect(rightHandle.data, 'height 11'); + + selectionOverlay + ..startHandleType = TextSelectionHandleType.right + ..lineHeightAtStart = 12.0 + ..endHandleType = TextSelectionHandleType.left + ..lineHeightAtEnd = 13.0; + await tester.pump(); + leftHandle = tester.widget(find.byKey(spy.leftHandleKey)) as Text; + rightHandle = tester.widget(find.byKey(spy.rightHandleKey)) as Text; + expect(leftHandle.data, 'height 13'); + expect(rightHandle.data, 'height 12'); + + selectionOverlay.dispose(); + await tester.pumpAndSettle(); + }); + + testWidgets('can trigger selection handle onTap', (WidgetTester tester) async { + bool selectionHandleTapped = false; + void handleTapped() => selectionHandleTapped = true; + final TextSelectionControlsSpy spy = TextSelectionControlsSpy(); + final SelectionOverlay selectionOverlay = await pumpApp( + tester, + onSelectionHandleTapped: handleTapped, + selectionControls: spy, + ); + selectionOverlay + ..startHandleType = TextSelectionHandleType.left + ..lineHeightAtStart = 10.0 + ..endHandleType = TextSelectionHandleType.right + ..lineHeightAtEnd = 11.0 + ..selectionEndpoints = const <TextSelectionPoint>[ + TextSelectionPoint(Offset(10, 10), TextDirection.ltr), + TextSelectionPoint(Offset(20, 20), TextDirection.ltr), + ]; + selectionOverlay.showHandles(); + await tester.pump(); + expect(find.byKey(spy.leftHandleKey), findsOneWidget); + expect(find.byKey(spy.rightHandleKey), findsOneWidget); + expect(selectionHandleTapped, isFalse); + + await tester.tap(find.byKey(spy.leftHandleKey)); + expect(selectionHandleTapped, isTrue); + + selectionHandleTapped = false; + await tester.tap(find.byKey(spy.rightHandleKey)); + expect(selectionHandleTapped, isTrue); + + selectionOverlay.dispose(); + await tester.pumpAndSettle(); + }); + + testWidgets('can trigger selection handle drag', (WidgetTester tester) async { + DragStartDetails? startDragStartDetails; + DragUpdateDetails? startDragUpdateDetails; + DragEndDetails? startDragEndDetails; + DragStartDetails? endDragStartDetails; + DragUpdateDetails? endDragUpdateDetails; + DragEndDetails? endDragEndDetails; + void startDragStart(DragStartDetails details) => startDragStartDetails = details; + void startDragUpdate(DragUpdateDetails details) => startDragUpdateDetails = details; + void startDragEnd(DragEndDetails details) => startDragEndDetails = details; + void endDragStart(DragStartDetails details) => endDragStartDetails = details; + void endDragUpdate(DragUpdateDetails details) => endDragUpdateDetails = details; + void endDragEnd(DragEndDetails details) => endDragEndDetails = details; + final TextSelectionControlsSpy spy = TextSelectionControlsSpy(); + final SelectionOverlay selectionOverlay = await pumpApp( + tester, + onStartDragStart: startDragStart, + onStartDragUpdate: startDragUpdate, + onStartDragEnd: startDragEnd, + onEndDragStart: endDragStart, + onEndDragUpdate: endDragUpdate, + onEndDragEnd: endDragEnd, + selectionControls: spy, + ); + selectionOverlay + ..startHandleType = TextSelectionHandleType.left + ..lineHeightAtStart = 10.0 + ..endHandleType = TextSelectionHandleType.right + ..lineHeightAtEnd = 11.0 + ..selectionEndpoints = const <TextSelectionPoint>[ + TextSelectionPoint(Offset(10, 10), TextDirection.ltr), + TextSelectionPoint(Offset(20, 20), TextDirection.ltr), + ]; + selectionOverlay.showHandles(); + await tester.pump(); + expect(find.byKey(spy.leftHandleKey), findsOneWidget); + expect(find.byKey(spy.rightHandleKey), findsOneWidget); + expect(startDragStartDetails, isNull); + expect(startDragUpdateDetails, isNull); + expect(startDragEndDetails, isNull); + expect(endDragStartDetails, isNull); + expect(endDragUpdateDetails, isNull); + expect(endDragEndDetails, isNull); + + final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byKey(spy.leftHandleKey))); + await tester.pump(const Duration(milliseconds: 200)); + expect(startDragStartDetails!.globalPosition, tester.getCenter(find.byKey(spy.leftHandleKey))); + + const Offset newLocation = Offset(20, 20); + await gesture.moveTo(newLocation); + await tester.pump(const Duration(milliseconds: 20)); + expect(startDragUpdateDetails!.globalPosition, newLocation); + + await gesture.up(); + await tester.pump(const Duration(milliseconds: 20)); + expect(startDragEndDetails, isNotNull); + + final TestGesture gesture2 = await tester.startGesture(tester.getCenter(find.byKey(spy.rightHandleKey))); + addTearDown(gesture2.removePointer); + await tester.pump(const Duration(milliseconds: 200)); + expect(endDragStartDetails!.globalPosition, tester.getCenter(find.byKey(spy.rightHandleKey))); + + await gesture2.moveTo(newLocation); + await tester.pump(const Duration(milliseconds: 20)); + expect(endDragUpdateDetails!.globalPosition, newLocation); + + await gesture2.up(); + await tester.pump(const Duration(milliseconds: 20)); + expect(endDragEndDetails, isNotNull); + + selectionOverlay.dispose(); + await tester.pumpAndSettle(); + }); + + testWidgets('can show magnifier when no handles exist', (WidgetTester tester) async { + final GlobalKey magnifierKey = GlobalKey(); + final SelectionOverlay selectionOverlay = await pumpApp( + tester, + magnifierConfiguration: TextMagnifierConfiguration( + shouldDisplayHandlesInMagnifier: false, + magnifierBuilder: (BuildContext context, MagnifierController controller, ValueNotifier<MagnifierInfo>? notifier) { + return SizedBox.shrink( + key: magnifierKey, + ); + }, + ), + ); + + expect(find.byKey(magnifierKey), findsNothing); + + final MagnifierInfo info = MagnifierInfo( + globalGesturePosition: Offset.zero, + caretRect: Offset.zero & const Size(5.0, 20.0), + fieldBounds: Offset.zero & const Size(200.0, 50.0), + currentLineBoundaries: Offset.zero & const Size(200.0, 50.0), + ); + selectionOverlay.showMagnifier(info); + await tester.pump(); + + expect(tester.takeException(), isNull); + expect(find.byKey(magnifierKey), findsOneWidget); + + selectionOverlay.dispose(); + await tester.pumpAndSettle(); + }); + }); + + group('ClipboardStatusNotifier', () { + group('when Clipboard fails', () { + setUp(() { + final MockClipboard mockClipboard = MockClipboard(hasStringsThrows: true); + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, mockClipboard.handleMethodCall); + }); + + tearDown(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, null); + }); + + test('Clipboard API failure is gracefully recovered from', () async { + final ClipboardStatusNotifier notifier = ClipboardStatusNotifier(); + expect(notifier.value, ClipboardStatus.unknown); + + await expectLater(notifier.update(), completes); + expect(notifier.value, ClipboardStatus.unknown); + }); + }); + + group('when Clipboard succeeds', () { + final MockClipboard mockClipboard = MockClipboard(); + + setUp(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, mockClipboard.handleMethodCall); + }); + + tearDown(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, null); + }); + + test('update sets value based on clipboard contents', () async { + final ClipboardStatusNotifier notifier = ClipboardStatusNotifier(); + expect(notifier.value, ClipboardStatus.unknown); + + await expectLater(notifier.update(), completes); + expect(notifier.value, ClipboardStatus.notPasteable); + + mockClipboard.handleMethodCall(const MethodCall( + 'Clipboard.setData', + <String, dynamic>{ + 'text': 'pasteablestring', + }, + )); + await expectLater(notifier.update(), completes); + expect(notifier.value, ClipboardStatus.pasteable); + }); + }); + }); + + testWidgets('Mouse edge scrolling works in an outer scrollable', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/102484 + final TextEditingController controller = TextEditingController( + text: 'I love flutter!\n' * 8, + ); + addTearDown(controller.dispose); + final GlobalKey<EditableTextState> editableTextKey = GlobalKey<EditableTextState>(); + final FakeTextSelectionGestureDetectorBuilderDelegate delegate = FakeTextSelectionGestureDetectorBuilderDelegate( + editableTextKey: editableTextKey, + forcePressEnabled: false, + selectionEnabled: true, + ); + + final ScrollController scrollController = ScrollController(); + addTearDown(scrollController.dispose); + const double kLineHeight = 16.0; + final TextSelectionGestureDetectorBuilder provider = + TextSelectionGestureDetectorBuilder( + delegate: delegate, + ); + final FocusNode focusNode = FocusNode(); + addTearDown(focusNode.dispose); + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: SizedBox( + // Only 4 lines visible of 8 given. + height: kLineHeight * 4, + child: SingleChildScrollView( + controller: scrollController, + child: provider.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: EditableText( + key: editableTextKey, + controller: controller, + focusNode: focusNode, + backgroundCursorColor: Colors.white, + cursorColor: Colors.white, + style: const TextStyle(), + selectionControls: materialTextSelectionControls, + // EditableText will expand to the full 8 line height and will + // not scroll itself. + maxLines: null, + ), + ), + ), + ), + ), + ), + ); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, -1); + expect(scrollController.position.pixels, 0.0); + + final Offset position = textOffsetToPosition(tester, 4); + + await tester.tapAt(position); + await tester.pump(); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, 4); + + // Select all text with the mouse. + final TestGesture gesture = await tester.startGesture(position, kind: PointerDeviceKind.mouse); + addTearDown(gesture.removePointer); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, (controller.text.length / 2).floor())); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, controller.text.length)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(controller.selection.isCollapsed, isFalse); + expect(controller.selection.baseOffset, 4); + expect(controller.selection.extentOffset, controller.text.length); + expect(scrollController.position.pixels, scrollController.position.maxScrollExtent); + }); + + testWidgets('Mouse edge scrolling works with both an outer scrollable and scrolling in the EditableText', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/102484 + final TextEditingController controller = TextEditingController( + text: 'I love flutter!\n' * 8, + ); + addTearDown(controller.dispose); + final GlobalKey<EditableTextState> editableTextKey = GlobalKey<EditableTextState>(); + final FakeTextSelectionGestureDetectorBuilderDelegate delegate = FakeTextSelectionGestureDetectorBuilderDelegate( + editableTextKey: editableTextKey, + forcePressEnabled: false, + selectionEnabled: true, + ); + + final ScrollController scrollController = ScrollController(); + addTearDown(scrollController.dispose); + const double kLineHeight = 16.0; + final TextSelectionGestureDetectorBuilder provider = + TextSelectionGestureDetectorBuilder( + delegate: delegate, + ); + final FocusNode focusNode = FocusNode(); + addTearDown(focusNode.dispose); + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: SizedBox( + // Only 4 lines visible of 8 given. + height: kLineHeight * 4, + child: SingleChildScrollView( + controller: scrollController, + child: provider.buildGestureDetector( + behavior: HitTestBehavior.translucent, + child: EditableText( + key: editableTextKey, + controller: controller, + focusNode: focusNode, + backgroundCursorColor: Colors.white, + cursorColor: Colors.white, + style: const TextStyle(), + selectionControls: materialTextSelectionControls, + // EditableText is taller than the SizedBox but not taller + // than the text. + maxLines: 6, + ), + ), + ), + ), + ), + ), + ); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, -1); + expect(scrollController.position.pixels, 0.0); + + final Offset position = textOffsetToPosition(tester, 4); + + await tester.tapAt(position); + await tester.pump(); + + expect(controller.selection.isCollapsed, isTrue); + expect(controller.selection.baseOffset, 4); + + // Select all text with the mouse. + final TestGesture gesture = await tester.startGesture(position, kind: PointerDeviceKind.mouse); + addTearDown(gesture.removePointer); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, (controller.text.length / 2).floor())); + await tester.pump(); + await gesture.moveTo(textOffsetToPosition(tester, controller.text.length)); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(controller.selection.isCollapsed, isFalse); + expect(controller.selection.baseOffset, 4); + expect(controller.selection.extentOffset, controller.text.length); + expect(scrollController.position.pixels, scrollController.position.maxScrollExtent); + }); + + group('TextSelectionOverlay', () { + Future<TextSelectionOverlay> pumpApp(WidgetTester tester) async { + final UniqueKey column = UniqueKey(); + final LayerLink startHandleLayerLink = LayerLink(); + final LayerLink endHandleLayerLink = LayerLink(); + final LayerLink toolbarLayerLink = LayerLink(); + + final UniqueKey editableText = UniqueKey(); + final TextEditingController controller = TextEditingController(); + addTearDown(controller.dispose); + final FocusNode focusNode = FocusNode(); + addTearDown(focusNode.dispose); + + await tester.pumpWidget(MaterialApp( + home: Column( + key: column, + children: <Widget>[ + FakeEditableText( + key: editableText, + controller: controller, + focusNode: focusNode, + ), + CompositedTransformTarget( + link: startHandleLayerLink, + child: const Text('start handle'), + ), + CompositedTransformTarget( + link: endHandleLayerLink, + child: const Text('end handle'), + ), + CompositedTransformTarget( + link: toolbarLayerLink, + child: const Text('toolbar'), + ), + ], + ), + )); + + return TextSelectionOverlay( + value: TextEditingValue.empty, + renderObject: tester.state<EditableTextState>(find.byKey(editableText)).renderEditable, + context: tester.element(find.byKey(column)), + onSelectionHandleTapped: () {}, + startHandleLayerLink: startHandleLayerLink, + endHandleLayerLink: endHandleLayerLink, + selectionDelegate: FakeTextSelectionDelegate(), + toolbarLayerLink: toolbarLayerLink, + magnifierConfiguration: TextMagnifierConfiguration.disabled, + ); + } + + testWidgets('dispatches memory events', (WidgetTester tester) async { + await expectLater( + await memoryEvents( + () async { + final TextSelectionOverlay overlay = await pumpApp(tester); + overlay.dispose(); + }, + TextSelectionOverlay, + ), + areCreateAndDispose, + ); + }); + }); +} + +class FakeTextSelectionGestureDetectorBuilderDelegate implements TextSelectionGestureDetectorBuilderDelegate { + FakeTextSelectionGestureDetectorBuilderDelegate({ + required this.editableTextKey, + required this.forcePressEnabled, + required this.selectionEnabled, + }); + + @override + final GlobalKey<EditableTextState> editableTextKey; + + @override + final bool forcePressEnabled; + + @override + final bool selectionEnabled; +} + +class FakeEditableText extends EditableText { + FakeEditableText({ + required super.controller, + required super.focusNode, + super.key, + }): super( + backgroundCursorColor: Colors.white, + cursorColor: Colors.white, + style: const TextStyle(), + ); + + @override + FakeEditableTextState createState() => FakeEditableTextState(); +} + +class FakeEditableTextState extends EditableTextState { + final GlobalKey _editableKey = GlobalKey(); + bool showToolbarCalled = false; + bool toggleToolbarCalled = false; + bool showSpellCheckSuggestionsToolbarCalled = false; + bool markCurrentSelectionAsMisspelled = false; + + @override + RenderEditable get renderEditable => _editableKey.currentContext!.findRenderObject()! as RenderEditable; + + @override + bool showToolbar() { + showToolbarCalled = true; + return true; + } + + @override + void toggleToolbar([bool hideHandles = true]) { + toggleToolbarCalled = true; + return; + } + + @override + bool showSpellCheckSuggestionsToolbar() { + showSpellCheckSuggestionsToolbarCalled = true; + return true; + } + + @override + SuggestionSpan? findSuggestionSpanAtCursorIndex(int cursorIndex) { + return markCurrentSelectionAsMisspelled + ? const SuggestionSpan( + TextRange(start: 7, end: 12), + <String>['word', 'world', 'old'], + ) : null; + } + + @override + Widget build(BuildContext context) { + super.build(context); + return FakeEditable(this, key: _editableKey); + } +} + +class FakeEditable extends LeafRenderObjectWidget { + const FakeEditable( + this.delegate, { + super.key, + }); + final EditableTextState delegate; + + @override + RenderEditable createRenderObject(BuildContext context) { + return FakeRenderEditable(delegate); + } +} + +class FakeRenderEditable extends RenderEditable { + FakeRenderEditable(EditableTextState delegate) + : this._(delegate, ViewportOffset.fixed(10.0)); + + FakeRenderEditable._( + EditableTextState delegate, + this._offset, + ) : super( + text: const TextSpan( + style: TextStyle(height: 1.0, fontSize: 10.0), + text: 'placeholder', + ), + startHandleLayerLink: LayerLink(), + endHandleLayerLink: LayerLink(), + ignorePointer: true, + textAlign: TextAlign.start, + textDirection: TextDirection.ltr, + locale: const Locale('en', 'US'), + offset: _offset, + textSelectionDelegate: delegate, + selection: const TextSelection.collapsed( + offset: 0, + ), + ); + + SelectionChangedCause? lastCause; + + ViewportOffset _offset; + + bool selectWordsInRangeCalled = false; + @override + void selectWordsInRange({ required Offset from, Offset? to, required SelectionChangedCause cause }) { + selectWordsInRangeCalled = true; + hasFocus = true; + lastCause = cause; + } + + bool selectWordEdgeCalled = false; + @override + void selectWordEdge({ required SelectionChangedCause cause }) { + selectWordEdgeCalled = true; + hasFocus = true; + lastCause = cause; + } + + bool selectPositionAtCalled = false; + Offset? selectPositionAtFrom; + Offset? selectPositionAtTo; + @override + void selectPositionAt({ required Offset from, Offset? to, required SelectionChangedCause cause }) { + selectPositionAtCalled = true; + selectPositionAtFrom = from; + selectPositionAtTo = to; + hasFocus = true; + lastCause = cause; + } + + bool selectPositionCalled = false; + @override + void selectPosition({ required SelectionChangedCause cause }) { + selectPositionCalled = true; + lastCause = cause; + return super.selectPosition(cause: cause); + } + + bool selectWordCalled = false; + @override + void selectWord({ required SelectionChangedCause cause }) { + selectWordCalled = true; + hasFocus = true; + lastCause = cause; + } + + @override + bool hasFocus = false; + + @override + void dispose() { + _offset.dispose(); + super.dispose(); + } +} + +class TextSelectionControlsSpy extends TextSelectionControls { + UniqueKey leftHandleKey = UniqueKey(); + UniqueKey rightHandleKey = UniqueKey(); + UniqueKey collapsedHandleKey = UniqueKey(); + UniqueKey toolBarKey = UniqueKey(); + + @override + Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textLineHeight, [VoidCallback? onTap]) { + switch (type) { + case TextSelectionHandleType.left: + return ElevatedButton(onPressed: onTap, child: Text('height ${textLineHeight.toInt()}', key: leftHandleKey)); + case TextSelectionHandleType.right: + return ElevatedButton(onPressed: onTap, child: Text('height ${textLineHeight.toInt()}', key: rightHandleKey)); + case TextSelectionHandleType.collapsed: + return ElevatedButton(onPressed: onTap, child: Text('height ${textLineHeight.toInt()}', key: collapsedHandleKey)); + } + } + + @override + Widget buildToolbar( + BuildContext context, + Rect globalEditableRegion, + double textLineHeight, + Offset position, + List<TextSelectionPoint> endpoints, + TextSelectionDelegate delegate, + ValueListenable<ClipboardStatus>? clipboardStatus, + Offset? lastSecondaryTapDownPosition, + ) { + return Text('dummy', key: toolBarKey); + } + + @override + Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) { + return Offset.zero; + } + + @override + Size getHandleSize(double textLineHeight) { + return Size(textLineHeight, textLineHeight); + } +} + +class FakeClipboardStatusNotifier extends ClipboardStatusNotifier { + FakeClipboardStatusNotifier() : super(value: ClipboardStatus.unknown); + + bool updateCalled = false; + @override + Future<void> update() async { + updateCalled = true; + } +} + +class FakeTextSelectionDelegate extends Fake implements TextSelectionDelegate { + @override + void cutSelection(SelectionChangedCause cause) { } + + @override + void copySelection(SelectionChangedCause cause) { } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_selection_toolbar_layout_delegate_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_selection_toolbar_layout_delegate_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..1fc67c761d6d448edb0b5a583de0cbba2491edf6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_selection_toolbar_layout_delegate_test.dart @@ -0,0 +1,61 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('positions itself at anchorAbove if it fits', (WidgetTester tester) async { + late StateSetter setState; + const double height = 43.0; + const double anchorBelowY = 500.0; + double anchorAboveY = 0.0; + + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(), + child: Directionality( + textDirection: TextDirection.ltr, + child: StatefulBuilder( + builder: (BuildContext context, StateSetter setter) { + setState = setter; + return CustomSingleChildLayout( + delegate: TextSelectionToolbarLayoutDelegate( + anchorAbove: Offset(50.0, anchorAboveY), + anchorBelow: const Offset(50.0, anchorBelowY), + ), + child: Container( + width: 200.0, + height: height, + color: const Color(0xffff0000), + ), + ); + }, + ), + ), + ), + ); + + // When the toolbar doesn't fit above aboveAnchor, it positions itself below + // belowAnchor. + double toolbarY = tester.getTopLeft(find.byType(Container)).dy; + expect(toolbarY, equals(anchorBelowY)); + + // Even when it barely doesn't fit. + setState(() { + anchorAboveY = height - 1.0; + }); + await tester.pump(); + toolbarY = tester.getTopLeft(find.byType(Container)).dy; + expect(toolbarY, equals(anchorBelowY)); + + // When it does fit above aboveAnchor, it positions itself there. + setState(() { + anchorAboveY = height; + }); + await tester.pump(); + toolbarY = tester.getTopLeft(find.byType(Container)).dy; + expect(toolbarY, equals(anchorAboveY - height)); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_selection_toolbar_utils.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_selection_toolbar_utils.dart new file mode 100644 index 0000000000000000000000000000000000000000..23a9830bc5f426d072d45366a874c501c62fc916 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_selection_toolbar_utils.dart @@ -0,0 +1,205 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/src/foundation/platform.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../widgets/editable_text_utils.dart'; + +Finder findCupertinoOverflowNextButton() { + return find.byWidgetPredicate((Widget widget) { + return widget is CustomPaint && '${widget.painter?.runtimeType}' == '_RightCupertinoChevronPainter'; + }); +} + +Finder findCupertinoOverflowBackButton() { + return find.byWidgetPredicate((Widget widget) { + return widget is CustomPaint && '${widget.painter?.runtimeType}' == '_LeftCupertinoChevronPainter'; + }); +} + +Future<void> tapCupertinoOverflowNextButton(WidgetTester tester) async{ + await tester.tapAt(tester.getCenter(findCupertinoOverflowNextButton())); + await tester.pumpAndSettle(); +} + +void expectNoCupertinoToolbar() { + expect(find.byType(CupertinoButton), findsNothing); +} + +// Check that the Cupertino text selection toolbars show the expected buttons +// when the content is partially selected. +void expectCupertinoToolbarForPartialSelection() { + if (isContextMenuProvidedByPlatform) { + expectNoCupertinoToolbar(); + return; + } + + switch (defaultTargetPlatform) { + case TargetPlatform.android: + expect(find.byType(CupertinoButton), findsNWidgets(5)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + expect(find.text('Share...'), findsOneWidget); + expect(find.text('Select All'), findsOneWidget); + case TargetPlatform.iOS: + expect(find.byType(CupertinoButton), findsNWidgets(6)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + expect(find.text('Share...'), findsOneWidget); + expect(find.text('Look Up'), findsOneWidget); + expect(find.text('Search Web'), findsOneWidget); + case TargetPlatform.macOS: + expect(find.byType(CupertinoButton), findsNWidgets(3)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + expect(find.byType(CupertinoButton), findsNWidgets(4)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + expect(find.text('Select All'), findsOneWidget); + } +} + +// Check that the Cupertino text selection toolbar shows the expected buttons +// when the content is fully selected. +void expectCupertinoToolbarForFullSelection() { + if (isContextMenuProvidedByPlatform) { + expectNoCupertinoToolbar(); + return; + } + + switch (defaultTargetPlatform) { + case TargetPlatform.android: + expect(find.byType(CupertinoButton), findsNWidgets(4)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + expect(find.text('Share...'), findsOneWidget); + case TargetPlatform.iOS: + expect(find.byType(CupertinoButton), findsNWidgets(6)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + expect(find.text('Share...'), findsOneWidget); + expect(find.text('Look Up'), findsOneWidget); + expect(find.text('Search Web'), findsOneWidget); + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(find.byType(CupertinoButton), findsNWidgets(3)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + } +} + +// Check that the Cupertino text selection toolbar is correct for a collapsed selection. +void expectCupertinoToolbarForCollapsedSelection() { + if (isContextMenuProvidedByPlatform) { + expectNoCupertinoToolbar(); + return; + } + + switch (defaultTargetPlatform) { + case TargetPlatform.android: + expect(find.byType(CupertinoButton), findsNWidgets(4)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + expect(find.text('Share...'), findsOneWidget); + case TargetPlatform.iOS: + expect(find.byType(CupertinoButton), findsNWidgets(2)); + expect(find.text('Paste'), findsOneWidget); + expect(find.text('Select All'), findsOneWidget); + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + case TargetPlatform.macOS: + expect(find.byType(CupertinoButton), findsNWidgets(1)); + expect(find.text('Paste'), findsOneWidget); + } +} + +void expectNoMaterialToolbar() { + expect(find.byType(TextButton), findsNothing); +} + +// Check that the Material text selection toolbars show the expected buttons +// when the content is partially selected. +void expectMaterialToolbarForPartialSelection() { + if (isContextMenuProvidedByPlatform) { + expectNoMaterialToolbar(); + return; + } + + switch (defaultTargetPlatform) { + case TargetPlatform.android: + expect(find.byType(TextButton), findsNWidgets(5)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + expect(find.text('Share'), findsOneWidget); + expect(find.text('Select all'), findsOneWidget); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + expect(find.byType(TextButton), findsNWidgets(4)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + expect(find.text('Select all'), findsOneWidget); + } +} + +// Check that the Material text selection toolbar shows the expected buttons +// when the content is fully selected. +void expectMaterialToolbarForFullSelection() { + if (isContextMenuProvidedByPlatform) { + expectNoMaterialToolbar(); + return; + } + + switch (defaultTargetPlatform) { + case TargetPlatform.android: + expect(find.byType(TextButton), findsNWidgets(4)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + expect(find.text('Share'), findsOneWidget); + case TargetPlatform.iOS: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(find.byType(TextButton), findsNWidgets(3)); + expect(find.text('Cut'), findsOneWidget); + expect(find.text('Copy'), findsOneWidget); + expect(find.text('Paste'), findsOneWidget); + } +} + +Finder findMaterialOverflowNextButton() { + return find.byIcon(Icons.more_vert); +} + +Finder findMaterialOverflowBackButton() { + return find.byIcon(Icons.arrow_back); +} + +Future<void> tapMaterialOverflowNextButton(WidgetTester tester) async { + await tester.tapAt(tester.getCenter(findMaterialOverflowNextButton())); + await tester.pumpAndSettle(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_semantics_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_semantics_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..c3a94c65a29755715acaf4b9daf5d6c5b0d73b7f --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_semantics_test.dart @@ -0,0 +1,152 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'semantics_tester.dart'; + +void main() { + testWidgets('SemanticsNode ids are stable', (WidgetTester tester) async { + // Regression test for b/151732341. + final SemanticsTester semantics = SemanticsTester(tester); + final TapGestureRecognizer recognizer1 = TapGestureRecognizer(); + addTearDown(recognizer1.dispose); + final TapGestureRecognizer recognizer2 = TapGestureRecognizer(); + addTearDown(recognizer2.dispose); + final TapGestureRecognizer recognizer3 = TapGestureRecognizer(); + addTearDown(recognizer3.dispose); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: Text.rich( + TextSpan( + text: 'Hallo ', + recognizer: recognizer1..onTap = () {}, + children: <TextSpan>[ + TextSpan( + text: 'Welt ', + recognizer: recognizer2..onTap = () {}, + ), + TextSpan( + text: '!!!', + recognizer: recognizer3..onTap = () {}, + ), + ], + ), + ), + )); + expect(find.text('Hallo Welt !!!'), findsOneWidget); + final SemanticsNode node = tester.getSemantics(find.text('Hallo Welt !!!')); + final Map<String, int> labelToNodeId = <String, int>{}; + node.visitChildren((SemanticsNode node) { + labelToNodeId[node.label] = node.id; + return true; + }); + expect(node.id, 1); + expect(labelToNodeId['Hallo '], 2); + expect(labelToNodeId['Welt '], 3); + expect(labelToNodeId['!!!'], 4); + expect(labelToNodeId.length, 3); + + // Rebuild semantics. + tester.renderObject(find.text('Hallo Welt !!!')).markNeedsSemanticsUpdate(); + await tester.pump(); + + final SemanticsNode nodeAfterRebuild = tester.getSemantics(find.text('Hallo Welt !!!')); + final Map<String, int> labelToNodeIdAfterRebuild = <String, int>{}; + nodeAfterRebuild.visitChildren((SemanticsNode node) { + labelToNodeIdAfterRebuild[node.label] = node.id; + return true; + }); + + // Node IDs are stable. + expect(nodeAfterRebuild.id, node.id); + expect(labelToNodeIdAfterRebuild['Hallo '], labelToNodeId['Hallo ']); + expect(labelToNodeIdAfterRebuild['Welt '], labelToNodeId['Welt ']); + expect(labelToNodeIdAfterRebuild['!!!'], labelToNodeId['!!!']); + expect(labelToNodeIdAfterRebuild.length, 3); + + final TapGestureRecognizer recognizer4 = TapGestureRecognizer(); + addTearDown(recognizer4.dispose); + final TapGestureRecognizer recognizer5 = TapGestureRecognizer(); + addTearDown(recognizer5.dispose); + + // Remove one node. + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: Text.rich( + TextSpan( + text: 'Hallo ', + recognizer: recognizer4..onTap = () {}, + children: <TextSpan>[ + TextSpan( + text: 'Welt ', + recognizer: recognizer5..onTap = () {}, + ), + ], + ), + ), + )); + + final SemanticsNode nodeAfterRemoval = tester.getSemantics(find.text('Hallo Welt ')); + final Map<String, int> labelToNodeIdAfterRemoval = <String, int>{}; + nodeAfterRemoval.visitChildren((SemanticsNode node) { + labelToNodeIdAfterRemoval[node.label] = node.id; + return true; + }); + + // Node IDs are stable. + expect(nodeAfterRemoval.id, node.id); + expect(labelToNodeIdAfterRemoval['Hallo '], labelToNodeId['Hallo ']); + expect(labelToNodeIdAfterRemoval['Welt '], labelToNodeId['Welt ']); + expect(labelToNodeIdAfterRemoval.length, 2); + + final TapGestureRecognizer recognizer6 = TapGestureRecognizer(); + addTearDown(recognizer6.dispose); + final TapGestureRecognizer recognizer7 = TapGestureRecognizer(); + addTearDown(recognizer7.dispose); + final TapGestureRecognizer recognizer8 = TapGestureRecognizer(); + addTearDown(recognizer8.dispose); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: Text.rich( + TextSpan( + text: 'Hallo ', + recognizer: recognizer6..onTap = () {}, + children: <TextSpan>[ + TextSpan( + text: 'Welt ', + recognizer: recognizer7..onTap = () {}, + ), + TextSpan( + text: '!!!', + recognizer: recognizer8..onTap = () {}, + ), + ], + ), + ), + )); + expect(find.text('Hallo Welt !!!'), findsOneWidget); + final SemanticsNode nodeAfterAddition = tester.getSemantics(find.text('Hallo Welt !!!')); + final Map<String, int> labelToNodeIdAfterAddition = <String, int>{}; + nodeAfterAddition.visitChildren((SemanticsNode node) { + labelToNodeIdAfterAddition[node.label] = node.id; + return true; + }); + + // New node gets a new ID. + expect(nodeAfterAddition.id, node.id); + expect(labelToNodeIdAfterAddition['Hallo '], labelToNodeId['Hallo ']); + expect(labelToNodeIdAfterAddition['Welt '], labelToNodeId['Welt ']); + expect(labelToNodeIdAfterAddition['!!!'], isNot(labelToNodeId['!!!'])); + expect(labelToNodeIdAfterAddition['!!!'], isNotNull); + expect(labelToNodeIdAfterAddition.length, 3); + + semantics.dispose(); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..bd891575b54d1feb6b8c4d057a8b690503cf2e70 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/text_test.dart @@ -0,0 +1,1758 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'semantics_tester.dart'; + +void main() { + testWidgets('Text respects media query', (WidgetTester tester) async { + await tester.pumpWidget(const MediaQuery( + data: MediaQueryData(textScaleFactor: 1.3), + child: Center( + child: Text('Hello', textDirection: TextDirection.ltr), + ), + )); + + RichText text = tester.firstWidget(find.byType(RichText)); + expect(text, isNotNull); + expect(text.textScaler, const TextScaler.linear(1.3)); + + await tester.pumpWidget(const Center( + child: Text('Hello', textDirection: TextDirection.ltr), + )); + + text = tester.firstWidget(find.byType(RichText)); + expect(text, isNotNull); + expect(text.textScaler, TextScaler.noScaling); + }); + + testWidgets('Text respects textScaleFactor with default font size', (WidgetTester tester) async { + await tester.pumpWidget( + const Center(child: Text('Hello', textDirection: TextDirection.ltr)), + ); + + RichText text = tester.firstWidget(find.byType(RichText)); + expect(text, isNotNull); + expect(text.textScaler, TextScaler.noScaling); + final Size baseSize = tester.getSize(find.byType(RichText)); + expect(baseSize.width, equals(70.0)); + expect(baseSize.height, equals(14.0)); + + await tester.pumpWidget(const Center( + child: Text( + 'Hello', + textScaleFactor: 1.5, + textDirection: TextDirection.ltr, + ), + )); + + text = tester.firstWidget(find.byType(RichText)); + expect(text, isNotNull); + expect(text.textScaler, const TextScaler.linear(1.5)); + final Size largeSize = tester.getSize(find.byType(RichText)); + expect(largeSize.width, 105.0); + expect(largeSize.height, equals(21.0)); + }); + + testWidgets('Text respects textScaleFactor with explicit font size', (WidgetTester tester) async { + await tester.pumpWidget(const Center( + child: Text( + 'Hello', + style: TextStyle(fontSize: 20.0), + textDirection: TextDirection.ltr, + ), + )); + + RichText text = tester.firstWidget(find.byType(RichText)); + expect(text, isNotNull); + expect(text.textScaler, TextScaler.noScaling); + final Size baseSize = tester.getSize(find.byType(RichText)); + expect(baseSize.width, equals(100.0)); + expect(baseSize.height, equals(20.0)); + + await tester.pumpWidget(const Center( + child: Text( + 'Hello', + style: TextStyle(fontSize: 20.0), + textScaleFactor: 1.3, + textDirection: TextDirection.ltr, + ), + )); + + text = tester.firstWidget(find.byType(RichText)); + expect(text, isNotNull); + expect(text.textScaler, const TextScaler.linear(1.3)); + final Size largeSize = tester.getSize(find.byType(RichText)); + expect(largeSize.width, 130.0); + expect(largeSize.height, equals(26.0)); + }); + + testWidgets("Text throws a nice error message if there's no Directionality", (WidgetTester tester) async { + await tester.pumpWidget(const Text('Hello')); + final String message = tester.takeException().toString(); + expect(message, contains('Directionality')); + expect(message, contains(' Text ')); + }); + + testWidgets('Text can be created from TextSpans and uses defaultTextStyle', (WidgetTester tester) async { + await tester.pumpWidget( + const DefaultTextStyle( + style: TextStyle( + fontSize: 20.0, + ), + child: Text.rich( + TextSpan( + text: 'Hello', + children: <TextSpan>[ + TextSpan( + text: ' beautiful ', + style: TextStyle(fontStyle: FontStyle.italic), + ), + TextSpan( + text: 'world', + style: TextStyle(fontWeight: FontWeight.bold), + ), + ], + ), + textDirection: TextDirection.ltr, + ), + ), + ); + + final RichText text = tester.firstWidget(find.byType(RichText)); + expect(text, isNotNull); + expect(text.text.style!.fontSize, 20.0); + }); + + testWidgets('inline widgets works with ellipsis', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/35869 + const TextStyle textStyle = TextStyle(); + await tester.pumpWidget( + Text.rich( + TextSpan( + children: <InlineSpan>[ + const TextSpan( + text: 'a very very very very very very very very very very long line', + ), + WidgetSpan( + child: SizedBox( + width: 20, + height: 40, + child: Card( + child: RichText( + text: const TextSpan(text: 'widget should be truncated'), + textDirection: TextDirection.rtl, + ), + ), + ), + ), + ], + style: textStyle, + ), + textDirection: TextDirection.ltr, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ); + expect(tester.takeException(), null); + }); + + testWidgets('inline widgets hitTest works with ellipsis', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/68559 + const TextStyle textStyle = TextStyle(); + await tester.pumpWidget( + Text.rich( + TextSpan( + children: <InlineSpan>[ + const TextSpan( + text: 'a very very very very very very very very very very long line', + ), + WidgetSpan( + child: SizedBox( + width: 20, + height: 40, + child: Card( + child: RichText( + text: const TextSpan(text: 'widget should be truncated'), + textDirection: TextDirection.rtl, + ), + ), + ), + ), + ], + style: textStyle, + ), + textDirection: TextDirection.ltr, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ); + + await tester.tap(find.byType(Text)); + + expect(tester.takeException(), null); + }); + + testWidgets('inline widgets works with textScaleFactor', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/59316 + final UniqueKey key = UniqueKey(); + double textScaleFactor = 1.0; + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Scaffold( + appBar: AppBar(title: const Text('title')), + body: Center( + child: Text.rich( + TextSpan( + children: <InlineSpan>[ + WidgetSpan( + child: RichText( + text: const TextSpan(text: 'widget should be truncated'), + textDirection: TextDirection.ltr, + ), + ), + ], + ), + key: key, + textDirection: TextDirection.ltr, + textScaleFactor: textScaleFactor, + ), + ), + ), + ), + ); + RenderBox renderText = tester.renderObject(find.byKey(key)); + final double singleLineHeight = renderText.size.height; + // Now, increases the text scale factor by 5 times. + textScaleFactor = textScaleFactor * 5; + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Scaffold( + appBar: AppBar(title: const Text('title')), + body: Center( + child: Text.rich( + TextSpan( + children: <InlineSpan>[ + WidgetSpan( + child: RichText( + text: const TextSpan(text: 'widget should be truncated'), + textDirection: TextDirection.ltr, + ), + ), + ], + ), + key: key, + textDirection: TextDirection.ltr, + textScaleFactor: textScaleFactor, + ), + ), + ), + ), + ); + + renderText = tester.renderObject(find.byKey(key)); + // The RichText in the widget span should wrap into three lines. + expect(renderText.size.height, singleLineHeight * textScaleFactor * 3); + }); + + testWidgets("Inline widgets' scaled sizes are constrained", (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/130588 + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + width: 502.5454545454545, + child: Text.rich(WidgetSpan(child: Row()), textScaleFactor: 0.95), + ), + ), + ), + ); + + expect(tester.takeException(), isNull); + }); + + testWidgets('semanticsLabel can override text label', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + await tester.pumpWidget( + const Text( + r'$$', + semanticsLabel: 'Double dollars', + textDirection: TextDirection.ltr, + ), + ); + final TestSemantics expectedSemantics = TestSemantics.root( + children: <TestSemantics>[ + TestSemantics.rootChild( + label: 'Double dollars', + textDirection: TextDirection.ltr, + ), + ], + ); + expect( + semantics, + hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + ), + ); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Text(r'$$', semanticsLabel: 'Double dollars'), + ), + ); + + expect( + semantics, + hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + ), + ); + semantics.dispose(); + }); + + testWidgets('semantics label is in order when uses widget span', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Text.rich( + TextSpan( + children: <InlineSpan>[ + const TextSpan(text: 'before '), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: Semantics(label: 'foo'), + ), + const TextSpan(text: ' after'), + ], + ), + ), + ), + ); + expect( + tester.getSemantics(find.byType(Text)), + matchesSemantics(label: 'before \nfoo\n after'), + ); + + // If the Paragraph is not dirty it should use the cache correctly. + final RenderObject parent = tester.renderObject<RenderObject>(find.byType(Directionality)); + parent.markNeedsSemanticsUpdate(); + await tester.pumpAndSettle(); + + expect( + tester.getSemantics(find.byType(Text)), + matchesSemantics(label: 'before \nfoo\n after'), + ); + }); + + testWidgets('semantics can handle some widget spans without semantics', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Text.rich( + TextSpan( + children: <InlineSpan>[ + const TextSpan(text: 'before '), + const WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: SizedBox(width: 10.0), + ), + const TextSpan(text: ' mid'), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: Semantics(label: 'foo'), + ), + const TextSpan(text: ' after'), + const WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: SizedBox(width: 10.0), + ), + ], + ), + ), + ), + ); + expect(tester.getSemantics(find.byType(Text)), + matchesSemantics(label: 'before \n mid\nfoo\n after')); + + // If the Paragraph is not dirty it should use the cache correctly. + final RenderObject parent = tester.renderObject<RenderObject>(find.byType(Directionality)); + parent.markNeedsSemanticsUpdate(); + await tester.pumpAndSettle(); + + expect(tester.getSemantics(find.byType(Text)), + matchesSemantics(label: 'before \n mid\nfoo\n after')); + }); + + testWidgets('semantics can handle all widget spans without semantics', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Text.rich( + TextSpan( + children: <InlineSpan>[ + TextSpan(text: 'before '), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: SizedBox(width: 10.0), + ), + TextSpan(text: ' mid'), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: SizedBox(width: 10.0), + ), + TextSpan(text: ' after'), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: SizedBox(width: 10.0), + ), + ], + ), + ), + ), + ); + expect(tester.getSemantics(find.byType(Text)), + matchesSemantics(label: 'before \n mid\n after')); + + // If the Paragraph is not dirty it should use the cache correctly. + final RenderObject parent = tester.renderObject<RenderObject>(find.byType(Directionality)); + parent.markNeedsSemanticsUpdate(); + await tester.pumpAndSettle(); + + expect(tester.getSemantics(find.byType(Text)), + matchesSemantics(label: 'before \n mid\n after')); + }); + + testWidgets('semantics can handle widget spans with explicit semantics node', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Text.rich( + TextSpan( + children: <InlineSpan>[ + const TextSpan(text: 'before '), + WidgetSpan( + alignment: PlaceholderAlignment.baseline, + baseline: TextBaseline.alphabetic, + child: Semantics(label: 'inner', container: true), + ), + const TextSpan(text: ' after'), + ], + ), + ), + ), + ); + expect( + tester.getSemantics(find.byType(Text)), + matchesSemantics(label: 'before \n after', children: <Matcher>[matchesSemantics(label: 'inner')]), + ); + + // If the Paragraph is not dirty it should use the cache correctly. + final RenderObject parent = tester.renderObject<RenderObject>(find.byType(Directionality)); + parent.markNeedsSemanticsUpdate(); + await tester.pumpAndSettle(); + + expect( + tester.getSemantics(find.byType(Text)), + matchesSemantics(label: 'before \n after', children: <Matcher>[matchesSemantics(label: 'inner')]), + ); + }); + + testWidgets('semanticsLabel can be shorter than text', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: RichText( + text: TextSpan( + children: <InlineSpan>[ + const TextSpan( + text: 'Some Text', + semanticsLabel: '', + ), + TextSpan( + text: 'Clickable', + recognizer: recognizer..onTap = () { }, + ), + ], + ), + ), + )); + final TestSemantics expectedSemantics = TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'Clickable', + actions: <SemanticsAction>[SemanticsAction.tap], + flags: <SemanticsFlag>[SemanticsFlag.isLink], + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ); + expect( + semantics, + hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + ), + ); + semantics.dispose(); + }); + + testWidgets('recognizers split semantic node', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + const TextStyle textStyle = TextStyle(); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget( + Text.rich( + TextSpan( + children: <TextSpan>[ + const TextSpan(text: 'hello '), + TextSpan( + text: 'world', + recognizer: recognizer..onTap = () { }, + ), + const TextSpan(text: ' this is a '), + const TextSpan(text: 'cat-astrophe'), + ], + style: textStyle, + ), + textDirection: TextDirection.ltr, + ), + ); + final TestSemantics expectedSemantics = TestSemantics.root( + children: <TestSemantics>[ + TestSemantics.rootChild( + children: <TestSemantics>[ + TestSemantics( + label: 'hello ', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'world', + textDirection: TextDirection.ltr, + actions: <SemanticsAction>[SemanticsAction.tap], + flags: <SemanticsFlag>[SemanticsFlag.isLink], + ), + TestSemantics( + label: ' this is a cat-astrophe', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ); + expect( + semantics, + hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + ), + ); + semantics.dispose(); + }); + + testWidgets('semantic nodes of offscreen recognizers are marked hidden', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/100395. + final SemanticsTester semantics = SemanticsTester(tester); + const TextStyle textStyle = TextStyle(fontSize: 200); + const String onScreenText = 'onscreen\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'; + const String offScreenText = 'off screen'; + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget( + SingleChildScrollView( + controller: controller, + child: Text.rich( + TextSpan( + children: <TextSpan>[ + const TextSpan(text: onScreenText), + TextSpan( + text: offScreenText, + recognizer: recognizer..onTap = () { }, + ), + ], + style: textStyle, + ), + textDirection: TextDirection.ltr, + ), + ), + ); + + final TestSemantics expectedSemantics = TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling], + actions: <SemanticsAction>[SemanticsAction.scrollUp], + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics( + label: onScreenText, + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: offScreenText, + textDirection: TextDirection.ltr, + actions: <SemanticsAction>[SemanticsAction.tap], + flags: <SemanticsFlag>[SemanticsFlag.isLink, SemanticsFlag.isHidden], + ), + ], + ), + ], + ), + ], + ); + expect( + semantics, + hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + ), + ); + + // Test show on screen. + expect(controller.offset, 0.0); + tester.binding.pipelineOwner.semanticsOwner!.performAction(4, SemanticsAction.showOnScreen); + await tester.pumpAndSettle(); + expect(controller.offset != 0.0, isTrue); + + semantics.dispose(); + }); + + testWidgets('recognizers split semantic node when TextSpan overflows', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + const TextStyle textStyle = TextStyle(); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget( + SizedBox( + height: 10, + child: Text.rich( + TextSpan( + children: <TextSpan>[ + const TextSpan(text: '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'), + TextSpan( + text: 'world', + recognizer: recognizer..onTap = () { }, + ), + ], + style: textStyle, + ), + textDirection: TextDirection.ltr, + ), + ), + ); + final TestSemantics expectedSemantics = TestSemantics.root( + children: <TestSemantics>[ + TestSemantics.rootChild( + children: <TestSemantics>[ + TestSemantics( + label: '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'world', + textDirection: TextDirection.ltr, + actions: <SemanticsAction>[SemanticsAction.tap], + flags: <SemanticsFlag>[SemanticsFlag.isLink], + ), + ], + ), + ], + ); + expect( + semantics, + hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + ), + ); + semantics.dispose(); + }); + + testWidgets('recognizers split semantic nodes with text span labels', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + const TextStyle textStyle = TextStyle(); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget( + Text.rich( + TextSpan( + children: <TextSpan>[ + const TextSpan(text: 'hello '), + TextSpan( + text: 'world', + recognizer: recognizer..onTap = () { }, + ), + const TextSpan(text: ' this is a '), + const TextSpan( + text: 'cat-astrophe', + semanticsLabel: 'regrettable event', + ), + ], + style: textStyle, + ), + textDirection: TextDirection.ltr, + ), + ); + final TestSemantics expectedSemantics = TestSemantics.root( + children: <TestSemantics>[ + TestSemantics.rootChild( + children: <TestSemantics>[ + TestSemantics( + label: 'hello ', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'world', + textDirection: TextDirection.ltr, + actions: <SemanticsAction>[SemanticsAction.tap], + flags: <SemanticsFlag>[SemanticsFlag.isLink], + ), + TestSemantics( + label: ' this is a regrettable event', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ); + expect( + semantics, + hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + ), + ); + semantics.dispose(); + }); + + + testWidgets('recognizers split semantic node - bidi', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + const TextStyle textStyle = TextStyle(); + final LongPressGestureRecognizer recognizer1 = LongPressGestureRecognizer(); + addTearDown(recognizer1.dispose); + final TapGestureRecognizer recognizer2 = TapGestureRecognizer(); + addTearDown(recognizer2.dispose); + + await tester.pumpWidget( + RichText( + text: TextSpan( + style: textStyle, + children: <TextSpan>[ + const TextSpan(text: 'hello world${Unicode.RLE}${Unicode.RLO} '), + TextSpan( + text: 'BOY', + recognizer: recognizer1..onLongPress = () { }, + ), + const TextSpan(text: ' HOW DO${Unicode.PDF} you ${Unicode.RLO} DO '), + TextSpan( + text: 'SIR', + recognizer: recognizer2..onTap = () { }, + ), + const TextSpan(text: '${Unicode.PDF}${Unicode.PDF} good bye'), + ], + ), + textDirection: TextDirection.ltr, + ), + ); + // The expected visual order of the text is: + // hello world RIS OD you OD WOH YOB good bye + // There are five unique text areas, they are, in visual order but + // showing the logical text: + // [hello world][SIR][HOW DO you DO][BOY][good bye] + // The direction of each varies based on the first bit of that area. + // The presence of the bidi formatting characters in the text is a + // bit dubious, but that's what we do currently, and it's not really + // clear what the perfect behavior would be... + final TestSemantics expectedSemantics = TestSemantics.root( + children: <TestSemantics>[ + TestSemantics.rootChild( + rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), + children: <TestSemantics>[ + TestSemantics( + rect: const Rect.fromLTRB(-4.0, -4.0, 480.0, 18.0), + label: 'hello world${Unicode.RLE}${Unicode.RLO} ', + textDirection: TextDirection.ltr, + ), + TestSemantics( + rect: const Rect.fromLTRB(416.0, -4.0, 466.0, 18.0), + label: 'BOY', + textDirection: TextDirection.rtl, + actions: <SemanticsAction>[SemanticsAction.longPress], + ), + TestSemantics( + rect: const Rect.fromLTRB(192.0, -4.0, 424.0, 18.0), + label: ' HOW DO${Unicode.PDF} you ${Unicode.RLO} DO ', + textDirection: TextDirection.rtl, + ), + TestSemantics( + rect: const Rect.fromLTRB(150.0, -4.0, 200.0, 18.0), + label: 'SIR', + textDirection: TextDirection.rtl, + actions: <SemanticsAction>[SemanticsAction.tap], + flags: <SemanticsFlag>[SemanticsFlag.isLink], + ), + TestSemantics( + rect: const Rect.fromLTRB(472.0, -4.0, 606.0, 18.0), + label: '${Unicode.PDF}${Unicode.PDF} good bye', + textDirection: TextDirection.rtl, + ), + ], + ), + ], + ); + expect( + semantics, + hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ), + ); + semantics.dispose(); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/62945 + + testWidgets('TapGesture recognizers contribute link semantics', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + const TextStyle textStyle = TextStyle(); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget( + Text.rich( + TextSpan( + children: <TextSpan>[ + TextSpan( + text: 'click me', + recognizer: recognizer..onTap = () { }, + ), + ], + style: textStyle, + ), + textDirection: TextDirection.ltr, + ), + ); + final TestSemantics expectedSemantics = TestSemantics.root( + children: <TestSemantics>[ + TestSemantics.rootChild( + children: <TestSemantics>[ + TestSemantics( + label: 'click me', + textDirection: TextDirection.ltr, + actions: <SemanticsAction>[SemanticsAction.tap], + flags: <SemanticsFlag>[SemanticsFlag.isLink], + ), + ], + ), + ], + ); + expect(semantics, hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + )); + semantics.dispose(); + }); + + testWidgets('inline widgets generate semantic nodes', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + const TextStyle textStyle = TextStyle(); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget( + Text.rich( + TextSpan( + children: <InlineSpan>[ + const TextSpan(text: 'a '), + TextSpan( + text: 'pebble', + recognizer: recognizer..onTap = () { }, + ), + const TextSpan(text: ' in the '), + WidgetSpan( + child: SizedBox( + width: 20, + height: 40, + child: Card( + child: RichText( + text: const TextSpan(text: 'INTERRUPTION'), + textDirection: TextDirection.rtl, + ), + ), + ), + ), + const TextSpan(text: 'sky'), + ], + style: textStyle, + ), + textDirection: TextDirection.ltr, + ), + ); + final TestSemantics expectedSemantics = TestSemantics.root( + children: <TestSemantics>[ + TestSemantics.rootChild( + children: <TestSemantics>[ + TestSemantics( + label: 'a ', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'pebble', + textDirection: TextDirection.ltr, + actions: <SemanticsAction>[SemanticsAction.tap], + flags: <SemanticsFlag>[SemanticsFlag.isLink], + ), + TestSemantics( + label: ' in the ', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: 'INTERRUPTION', + textDirection: TextDirection.rtl, + ), + TestSemantics( + label: 'sky', + textDirection: TextDirection.ltr, + ), + ], + ), + ], + ); + expect( + semantics, + hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ignoreRect: true, + ), + ); + semantics.dispose(); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/62945 + + testWidgets('inline widgets semantic nodes scale', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + const TextStyle textStyle = TextStyle(); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget( + Text.rich( + TextSpan( + children: <InlineSpan>[ + const TextSpan(text: 'a '), + TextSpan( + text: 'pebble', + recognizer: recognizer..onTap = () { }, + ), + const TextSpan(text: ' in the '), + WidgetSpan( + child: SizedBox( + width: 20, + height: 40, + child: Card( + child: RichText( + text: const TextSpan(text: 'INTERRUPTION'), + textDirection: TextDirection.rtl, + ), + ), + ), + ), + const TextSpan(text: 'sky'), + ], + style: textStyle, + ), + textDirection: TextDirection.ltr, + textScaleFactor: 2, + ), + ); + final TestSemantics expectedSemantics = TestSemantics.root( + children: <TestSemantics>[ + TestSemantics.rootChild( + rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), + children: <TestSemantics>[ + TestSemantics( + label: 'a ', + textDirection: TextDirection.ltr, + rect: const Rect.fromLTRB(-4.0, 48.0, 60.0, 84.0), + ), + TestSemantics( + label: 'pebble', + textDirection: TextDirection.ltr, + actions: <SemanticsAction>[SemanticsAction.tap], + flags: <SemanticsFlag>[SemanticsFlag.isLink], + rect: const Rect.fromLTRB(52.0, 48.0, 228.0, 84.0), + ), + TestSemantics( + label: ' in the ', + textDirection: TextDirection.ltr, + rect: const Rect.fromLTRB(220.0, 48.0, 452.0, 84.0), + ), + TestSemantics( + label: 'INTERRUPTION', + textDirection: TextDirection.rtl, + rect: const Rect.fromLTRB(0.0, 0.0, 20.0, 40.0), + ), + TestSemantics( + label: 'sky', + textDirection: TextDirection.ltr, + rect: const Rect.fromLTRB(484.0, 48.0, 576.0, 84.0), + ), + ], + ), + ], + ); + expect( + semantics, + hasSemantics( + expectedSemantics, + ignoreTransform: true, + ignoreId: true, + ), + ); + semantics.dispose(); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/62945 + + testWidgets('receives fontFamilyFallback and package from root ThemeData', (WidgetTester tester) async { + const String fontFamily = 'fontFamily'; + const String package = 'package_name'; + final List<String> fontFamilyFallback = <String>['font', 'family', 'fallback']; + await tester.pumpWidget( + MaterialApp( + theme: ThemeData( + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, + package: package, + primarySwatch: Colors.blue, + ), + home: const Scaffold( + body: Center( + child: Text( + 'foo', + ), + ), + ), + ), + ); + + expect(find.byType(RichText), findsOneWidget); + final RichText richText = tester.widget(find.byType(RichText)); + final InlineSpan text = richText.text; + final TextStyle? style = text.style; + expect(style?.fontFamily, equals('packages/$package/$fontFamily')); + for (int i = 0; i < fontFamilyFallback.length; i++) { + final String fallback = fontFamilyFallback[i]; + expect(style?.fontFamilyFallback?[i], equals('packages/$package/$fallback')); + } + }); + + testWidgets('Overflow is clipping correctly - short text with overflow: clip', (WidgetTester tester) async { + await _pumpTextWidget( + tester: tester, + overflow: TextOverflow.clip, + text: 'Hi', + ); + + expect(find.byType(Text), isNot(paints..clipRect())); + }); + + testWidgets('Overflow is clipping correctly - long text with overflow: ellipsis', (WidgetTester tester) async { + await _pumpTextWidget( + tester: tester, + overflow: TextOverflow.ellipsis, + text: 'a long long long long text, should be clip', + ); + + expect( + find.byType(Text), + paints..clipRect(rect: const Rect.fromLTWH(0, 0, 50, 50)), + ); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/87878 + + testWidgets('Overflow is clipping correctly - short text with overflow: ellipsis', (WidgetTester tester) async { + await _pumpTextWidget( + tester: tester, + overflow: TextOverflow.ellipsis, + text: 'Hi', + ); + + expect(find.byType(Text), isNot(paints..clipRect())); + }); + + testWidgets('Overflow is clipping correctly - long text with overflow: fade', (WidgetTester tester) async { + await _pumpTextWidget( + tester: tester, + overflow: TextOverflow.fade, + text: 'a long long long long text, should be clip', + ); + + expect( + find.byType(Text), + paints..clipRect(rect: const Rect.fromLTWH(0, 0, 50, 50)), + ); + }); + + testWidgets('Overflow is clipping correctly - short text with overflow: fade', (WidgetTester tester) async { + await _pumpTextWidget( + tester: tester, + overflow: TextOverflow.fade, + text: 'Hi', + ); + + expect(find.byType(Text), isNot(paints..clipRect())); + }); + + testWidgets('Overflow is clipping correctly - long text with overflow: visible', (WidgetTester tester) async { + await _pumpTextWidget( + tester: tester, + overflow: TextOverflow.visible, + text: 'a long long long long text, should be clip', + ); + + expect(find.byType(Text), isNot(paints..clipRect())); + }); + + testWidgets('Overflow is clipping correctly - short text with overflow: visible', (WidgetTester tester) async { + await _pumpTextWidget( + tester: tester, + overflow: TextOverflow.visible, + text: 'Hi', + ); + + expect(find.byType(Text), isNot(paints..clipRect())); + }); + + testWidgets('textWidthBasis affects the width of a Text widget', (WidgetTester tester) async { + Future<void> createText(TextWidthBasis textWidthBasis) { + return tester.pumpWidget( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Scaffold( + body: Center( + // Each word takes up more than a half of a line. Together they + // wrap onto two lines, but leave a lot of extra space. + child: Text( + 'twowordsthateachtakeupmorethanhalfof alineoftextsothattheywrapwithlotsofextraspace', + textDirection: TextDirection.ltr, + textWidthBasis: textWidthBasis, + ), + ), + ), + ), + ); + } + + const double fontHeight = 14.0; + const double screenWidth = 800.0; + + // When textWidthBasis is parent, takes up full screen width. + await createText(TextWidthBasis.parent); + final Size textSizeParent = tester.getSize(find.byType(Text)); + expect(textSizeParent.width, equals(screenWidth)); + expect(textSizeParent.height, equals(fontHeight * 2)); + + // When textWidthBasis is longestLine, sets the width to as small as + // possible for the two lines. + await createText(TextWidthBasis.longestLine); + final Size textSizeLongestLine = tester.getSize(find.byType(Text)); + expect(textSizeLongestLine.width, equals(630.0)); + expect(textSizeLongestLine.height, equals(fontHeight * 2)); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/44020 + + testWidgets('textWidthBasis with textAlign still obeys parent alignment', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Text( + 'LEFT ALIGNED, PARENT', + textAlign: TextAlign.left, + textWidthBasis: TextWidthBasis.parent, + ), + Text( + 'RIGHT ALIGNED, PARENT', + textAlign: TextAlign.right, + textWidthBasis: TextWidthBasis.parent, + ), + Text( + 'LEFT ALIGNED, LONGEST LINE', + textAlign: TextAlign.left, + textWidthBasis: TextWidthBasis.longestLine, + ), + Text( + 'RIGHT ALIGNED, LONGEST LINE', + textAlign: TextAlign.right, + textWidthBasis: TextWidthBasis.longestLine, + ), + ], + ), + ), + ), + ), + ); + + // All Texts have the same horizontal alignment. + final double offsetX = tester.getTopLeft(find.text('LEFT ALIGNED, PARENT')).dx; + expect(tester.getTopLeft(find.text('RIGHT ALIGNED, PARENT')).dx, equals(offsetX)); + expect(tester.getTopLeft(find.text('LEFT ALIGNED, LONGEST LINE')).dx, equals(offsetX)); + expect(tester.getTopLeft(find.text('RIGHT ALIGNED, LONGEST LINE')).dx, equals(offsetX)); + + // All Texts are less than or equal to the width of the Column. + final double width = tester.getSize(find.byType(Column)).width; + expect(tester.getSize(find.text('LEFT ALIGNED, PARENT')).width, lessThan(width)); + expect(tester.getSize(find.text('RIGHT ALIGNED, PARENT')).width, lessThan(width)); + expect(tester.getSize(find.text('LEFT ALIGNED, LONGEST LINE')).width, lessThan(width)); + expect(tester.getSize(find.text('RIGHT ALIGNED, LONGEST LINE')).width, equals(width)); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/44020 + + testWidgets( + 'textWidthBasis.longestLine confines the width of the paragraph ' + 'when given loose constraints', + (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/62550. + await tester.pumpWidget( + Center( + child: SizedBox( + width: 400, + child: Center( + child: RichText( + // 400 is not wide enough for this string. The part after the + // whitespace is going to be broken into a 2nd line. + text: const TextSpan(text: 'fwefwefwewfefewfwe fwfwfwefweabcdefghijklmnopqrstuvwxyz'), + textWidthBasis: TextWidthBasis.longestLine, + textDirection: TextDirection.rtl, + ), + ), + ), + ), + ); + + expect(find.byType(RichText), paints..something((Symbol method, List<dynamic> arguments) { + if (method != #drawParagraph) { + return false; + } + final ui.Paragraph paragraph = arguments[0] as ui.Paragraph; + final Offset offset = arguments[1] as Offset; + final List<ui.LineMetrics> lines = paragraph.computeLineMetrics(); + for (final ui.LineMetrics line in lines) { + if (line.left + offset.dx + line.width >= 400) { + throw 'line $line is greater than the max width constraints'; + } + } + return true; + })); + }, + skip: isBrowser, // https://github.com/flutter/flutter/issues/44020 + ); + + testWidgets('Paragraph.getBoxesForRange returns nothing when selection range is zero length', (WidgetTester tester) async { + final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle()); + builder.addText('hello'); + final ui.Paragraph paragraph = builder.build(); + paragraph.layout(const ui.ParagraphConstraints(width: 1000)); + expect(paragraph.getBoxesForRange(2, 2), isEmpty); + paragraph.dispose(); + }); + + // Regression test for https://github.com/flutter/flutter/issues/65818 + testWidgets('WidgetSpans with no semantic information are elided from semantics', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + // Without the fix for this bug the pump widget will throw a RangeError. + await tester.pumpWidget( + RichText( + textDirection: TextDirection.ltr, + text: TextSpan(children: <InlineSpan>[ + const WidgetSpan(child: SizedBox.shrink()), + TextSpan( + text: 'HELLO', + style: const TextStyle(color: Colors.black), + recognizer: recognizer..onTap = () {}, + ), + ]), + ), + ); + + expect(semantics, hasSemantics(TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + id: 1, + rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), + transform: Matrix4( + 3.0,0.0,0.0,0.0, + 0.0,3.0,0.0,0.0, + 0.0,0.0,1.0,0.0, + 0.0,0.0,0.0,1.0, + ), + children: <TestSemantics>[ + TestSemantics( + rect: const Rect.fromLTRB(-4.0, -4.0, 74.0, 18.0), + id: 2, + label: 'HELLO', + actions: <SemanticsAction>[ + SemanticsAction.tap, + ], + flags: <SemanticsFlag>[ + SemanticsFlag.isLink, + ], + ), + ], + ), + ], + ))); + semantics.dispose(); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/87877 + + // Regression test for https://github.com/flutter/flutter/issues/69787 + testWidgets('WidgetSpans with no semantic information are elided from semantics - case 2', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: RichText( + text: TextSpan(children: <InlineSpan>[ + const WidgetSpan(child: SizedBox.shrink()), + const WidgetSpan(child: Text('included')), + TextSpan( + text: 'HELLO', + style: const TextStyle(color: Colors.black), + recognizer: recognizer..onTap = () {}, + ), + const WidgetSpan(child: Text('included2')), + ]), + ), + ), + ); + + expect( + semantics, + hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics(label: 'included'), + TestSemantics( + label: 'HELLO', + actions: <SemanticsAction>[ + SemanticsAction.tap, + ], + flags: <SemanticsFlag>[ + SemanticsFlag.isLink, + ], + ), + TestSemantics(label: 'included2'), + ], + ), + ], + ), + ignoreId: true, + ignoreRect: true, + ignoreTransform: true, + ), + ); + semantics.dispose(); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/87877 + + // Regression test for https://github.com/flutter/flutter/issues/69787 + testWidgets('WidgetSpans with no semantic information are elided from semantics - case 3', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: RichText( + text: TextSpan(children: <InlineSpan>[ + const WidgetSpan(child: SizedBox.shrink()), + WidgetSpan( + child: Row( + children: <Widget>[ + Semantics( + container: true, + child: const Text('foo'), + ), + Semantics( + container: true, + child: const Text('bar'), + ), + ], + ), + ), + TextSpan( + text: 'HELLO', + style: const TextStyle(color: Colors.black), + recognizer: recognizer..onTap = () {}, + ), + ]), + ), + ), + ); + + expect( + semantics, + hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics(label: 'foo'), + TestSemantics(label: 'bar'), + TestSemantics( + label: 'HELLO', + actions: <SemanticsAction>[ + SemanticsAction.tap, + ], + flags: <SemanticsFlag>[ + SemanticsFlag.isLink, + ], + ), + ], + ), + ], + ), + ignoreId: true, + ignoreRect: true, + ignoreTransform: true, + ), + ); + semantics.dispose(); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/87877 + + // Regression test for https://github.com/flutter/flutter/issues/69787 + testWidgets('WidgetSpans with no semantic information are elided from semantics - case 4', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + final TapGestureRecognizer recognizer = TapGestureRecognizer(); + addTearDown(recognizer.dispose); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: ClipRect( + child: Container( + color: Colors.green, + height: 100, + width: 100, + child: OverflowBox( + alignment: Alignment.topLeft, + maxWidth: double.infinity, + child: RichText( + text: TextSpan( + children: <InlineSpan>[ + const WidgetSpan( + child: Icon( + Icons.edit, + size: 16, + semanticLabel: 'not clipped', + ), + ), + TextSpan( + text: 'next WS is clipped', + recognizer: recognizer..onTap = () { }, + ), + const WidgetSpan( + child: Icon( + Icons.edit, + size: 16, + semanticLabel: 'clipped', + ), + ), + ], + ), + ), + ), + ), + ), + ), + ), + ); + + expect( + semantics, + hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics( + children: <TestSemantics>[ + TestSemantics(label: 'not clipped'), + TestSemantics( + label: 'next WS is clipped', + flags: <SemanticsFlag>[SemanticsFlag.isLink], + actions: <SemanticsAction>[SemanticsAction.tap], + ), + ], + ), + ], + ), + ignoreId: true, + ignoreRect: true, + ignoreTransform: true, + ), + ); + semantics.dispose(); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/87877 + + testWidgets('RenderParagraph intrinsic width', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + height: 100, + child: IntrinsicWidth( + child: RichText( + text: const TextSpan( + style: TextStyle(fontSize: 16, height: 1), + children: <InlineSpan>[ + TextSpan(text: 'S '), + WidgetSpan( + alignment: PlaceholderAlignment.top, + child: Wrap( + direction: Axis.vertical, + children: <Widget>[ + SizedBox(width: 200, height: 100), + SizedBox(width: 200, height: 30), + ], + ), + ), + TextSpan(text: ' E'), + ], + ), + ), + ), + ), + ), + ), + ); + + expect(tester.getSize(find.byType(RichText)).width, 200 + 4 * 16.0); + final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(find.byType(RichText)); + // The inline spans are rendered on one (horizontal) line, the sum of the widths is the max intrinsic width. + expect(paragraph.getMaxIntrinsicWidth(0.0), 200 + 4 * 16.0); + // The inline spans are rendered in one vertical run, the widest one determines the min intrinsic width. + expect(paragraph.getMinIntrinsicWidth(0.0), 200); + }); + + testWidgets('can compute intrinsic width and height for widget span with text scaling', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/59316 + const Key textKey = Key('RichText'); + Widget textWithNestedInlineSpans({ required double textScaleFactor, required double screenWidth }) { + return Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: OverflowBox( + alignment: Alignment.topLeft, + maxWidth: screenWidth, + child: RichText( + key: textKey, + textScaleFactor: textScaleFactor, + text: const TextSpan(children: <InlineSpan>[ + WidgetSpan(child: Text('one two')), + ]), + ), + ), + ), + ); + } + // The render object is going to be reused across widget tree rebuilds. + late final RenderParagraph outerParagraph = tester.renderObject(find.byKey(textKey)); + + await tester.pumpWidget(textWithNestedInlineSpans(textScaleFactor: 1.0, screenWidth: 100.0)); + expect( + outerParagraph.getMaxIntrinsicHeight(100.0), + 14.0, + reason: 'singleLineHeight = 14.0', + ); + + await tester.pumpWidget(textWithNestedInlineSpans(textScaleFactor: 2.0, screenWidth: 100.0)); + expect( + outerParagraph.getMinIntrinsicHeight(100.0), + 14.0 * 2.0 * 2, + reason: 'intrinsicHeight = singleLineHeight * textScaleFactor * two lines.', + ); + + await tester.pumpWidget(textWithNestedInlineSpans(textScaleFactor: 1.0, screenWidth: 1000.0)); + expect( + outerParagraph.getMaxIntrinsicWidth(1000.0), + 14.0 * 7, + reason: 'intrinsic width = 14.0 * 7', + ); + + await tester.pumpWidget(textWithNestedInlineSpans(textScaleFactor: 2.0, screenWidth: 1000.0)); + expect( + outerParagraph.getMaxIntrinsicWidth(1000.0), + 14.0 * 2.0 * 7, + reason: 'intrinsic width = glyph advance * textScaleFactor * num of glyphs', + ); + }); + + testWidgets('Text uses TextStyle.overflow', (WidgetTester tester) async { + const TextOverflow overflow = TextOverflow.fade; + + await tester.pumpWidget(const Text( + 'Hello World', + textDirection: TextDirection.ltr, + style: TextStyle(overflow: overflow), + )); + + final RichText richText = tester.firstWidget(find.byType(RichText)); + + expect(richText.overflow, overflow); + expect(richText.text.style!.overflow, overflow); + }); + + testWidgets( + 'Text can be hit-tested without layout or paint being called in a frame', + (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/85108. + await tester.pumpWidget( + const Opacity( + opacity: 1.0, + child: Text( + 'Hello World', + textDirection: TextDirection.ltr, + style: TextStyle(color: Color(0xFF123456)), + ), + ), + ); + + // The color changed and the opacity is set to 0: + // * 0 opacity will prevent RenderParagraph.paint from being called. + // * Only changing the color will prevent RenderParagraph.performLayout + // from being called. + // The underlying TextPainter should not evict its layout cache in this + // case, for hit-testing. + await tester.pumpWidget( + const Opacity( + opacity: 0.0, + child: Text( + 'Hello World', + textDirection: TextDirection.ltr, + style: TextStyle(color: Color(0x87654321)), + ), + ), + ); + + await tester.tap(find.text('Hello World')); + expect(tester.takeException(), isNull); + }); + + testWidgets('Mouse hovering over selectable Text uses SystemMouseCursor.text', (WidgetTester tester) async { + await tester.pumpWidget(const MaterialApp( + home: SelectionArea( + child: Text('Flutter'), + ), + )); + + final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1); + await gesture.addPointer(location: tester.getCenter(find.byType(Text))); + + await tester.pump(); + + expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text); + }); + + testWidgets('Mouse hovering over selectable Text uses default selection style mouse cursor', (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp( + home: SelectionArea( + child: DefaultSelectionStyle.merge( + mouseCursor: SystemMouseCursors.click, + child: const Text('Flutter'), + ), + ), + )); + + final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1); + await gesture.addPointer(location: tester.getCenter(find.byType(Text))); + + await tester.pump(); + + expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click); + }); +} + +Future<void> _pumpTextWidget({ + required WidgetTester tester, + required String text, + required TextOverflow overflow, +}) { + return tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + width: 50.0, + height: 50.0, + child: Text( + text, + overflow: overflow, + ), + ), + ), + ), + ); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/texture_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/texture_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..e832ec021d1e3d4da7afd0c8b1572941ff8a61b8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/texture_test.dart @@ -0,0 +1,126 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Texture with freeze set to true', (WidgetTester tester) async { + await tester.pumpWidget( + const Center(child: Texture(textureId: 1, freeze: true)), + ); + + final Texture texture = tester.firstWidget(find.byType(Texture)); + expect(texture, isNotNull); + expect(texture.textureId, 1); + expect(texture.freeze, true); + + final RenderObject renderObject = tester.firstRenderObject(find.byType(Texture)); + expect(renderObject, isNotNull); + final TextureBox textureBox = renderObject as TextureBox; + expect(textureBox, isNotNull); + expect(textureBox.textureId, 1); + expect(textureBox.freeze, true); + + final ContainerLayer containerLayer = ContainerLayer(); + addTearDown(containerLayer.dispose); + final PaintingContext paintingContext = PaintingContext(containerLayer, Rect.zero); + textureBox.paint(paintingContext, Offset.zero); + final Layer layer = containerLayer.lastChild!; + expect(layer, isNotNull); + final TextureLayer textureLayer = layer as TextureLayer; + expect(textureLayer, isNotNull); + expect(textureLayer.textureId, 1); + expect(textureLayer.freeze, true); + }); + + testWidgets('Texture with default FilterQuality', (WidgetTester tester) async { + await tester.pumpWidget( + const Center(child: Texture(textureId: 1)), + ); + + final Texture texture = tester.firstWidget(find.byType(Texture)); + expect(texture, isNotNull); + expect(texture.textureId, 1); + expect(texture.filterQuality, FilterQuality.low); + + final RenderObject renderObject = tester.firstRenderObject(find.byType(Texture)); + expect(renderObject, isNotNull); + final TextureBox textureBox = renderObject as TextureBox; + expect(textureBox, isNotNull); + expect(textureBox.textureId, 1); + expect(textureBox.filterQuality, FilterQuality.low); + + final ContainerLayer containerLayer = ContainerLayer(); + addTearDown(containerLayer.dispose); + final PaintingContext paintingContext = PaintingContext(containerLayer, Rect.zero); + textureBox.paint(paintingContext, Offset.zero); + final Layer layer = containerLayer.lastChild!; + expect(layer, isNotNull); + final TextureLayer textureLayer = layer as TextureLayer; + expect(textureLayer, isNotNull); + expect(textureLayer.textureId, 1); + expect(textureLayer.filterQuality, FilterQuality.low); + }); + + + testWidgets('Texture with FilterQuality.none', (WidgetTester tester) async { + await tester.pumpWidget( + const Center(child: Texture(textureId: 1, filterQuality: FilterQuality.none)), + ); + + final Texture texture = tester.firstWidget(find.byType(Texture)); + expect(texture, isNotNull); + expect(texture.textureId, 1); + expect(texture.filterQuality, FilterQuality.none); + + final RenderObject renderObject = tester.firstRenderObject(find.byType(Texture)); + expect(renderObject, isNotNull); + final TextureBox textureBox = renderObject as TextureBox; + expect(textureBox, isNotNull); + expect(textureBox.textureId, 1); + expect(textureBox.filterQuality, FilterQuality.none); + + final ContainerLayer containerLayer = ContainerLayer(); + addTearDown(containerLayer.dispose); + final PaintingContext paintingContext = PaintingContext(containerLayer, Rect.zero); + textureBox.paint(paintingContext, Offset.zero); + final Layer layer = containerLayer.lastChild!; + expect(layer, isNotNull); + final TextureLayer textureLayer = layer as TextureLayer; + expect(textureLayer, isNotNull); + expect(textureLayer.textureId, 1); + expect(textureLayer.filterQuality, FilterQuality.none); + }); + + testWidgets('Texture with FilterQuality.low', (WidgetTester tester) async { + await tester.pumpWidget( + const Center(child: Texture(textureId: 1)), + ); + + final Texture texture = tester.firstWidget(find.byType(Texture)); + expect(texture, isNotNull); + expect(texture.textureId, 1); + expect(texture.filterQuality, FilterQuality.low); + + final RenderObject renderObject = tester.firstRenderObject(find.byType(Texture)); + expect(renderObject, isNotNull); + final TextureBox textureBox = renderObject as TextureBox; + expect(textureBox, isNotNull); + expect(textureBox.textureId, 1); + expect(textureBox.filterQuality, FilterQuality.low); + + final ContainerLayer containerLayer = ContainerLayer(); + addTearDown(containerLayer.dispose); + final PaintingContext paintingContext = PaintingContext(containerLayer, Rect.zero); + textureBox.paint(paintingContext, Offset.zero); + final Layer layer = containerLayer.lastChild!; + expect(layer, isNotNull); + final TextureLayer textureLayer = layer as TextureLayer; + expect(textureLayer, isNotNull); + expect(textureLayer.textureId, 1); + expect(textureLayer.filterQuality, FilterQuality.low); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/ticker_mode_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/ticker_mode_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..aa09b8c9c2e6c7423616e913d9d250648585bda5 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/ticker_mode_test.dart @@ -0,0 +1,288 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Nested TickerMode cannot turn tickers back on', (WidgetTester tester) async { + int outerTickCount = 0; + int innerTickCount = 0; + + Widget nestedTickerModes({required bool innerEnabled, required bool outerEnabled}) { + return Directionality( + textDirection: TextDirection.rtl, + child: TickerMode( + enabled: outerEnabled, + child: Row( + children: <Widget>[ + _TickingWidget( + onTick: () { + outerTickCount++; + }, + ), + TickerMode( + enabled: innerEnabled, + child: _TickingWidget( + onTick: () { + innerTickCount++; + }, + ), + ), + ], + ), + ), + ); + } + + await tester.pumpWidget( + nestedTickerModes( + outerEnabled: false, + innerEnabled: true, + ), + ); + + expect(outerTickCount, 0); + expect(innerTickCount, 0); + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + expect(outerTickCount, 0); + expect(innerTickCount, 0); + + await tester.pumpWidget( + nestedTickerModes( + outerEnabled: true, + innerEnabled: false, + ), + ); + outerTickCount = 0; + innerTickCount = 0; + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + expect(outerTickCount, 4); + expect(innerTickCount, 0); + + await tester.pumpWidget( + nestedTickerModes( + outerEnabled: true, + innerEnabled: true, + ), + ); + outerTickCount = 0; + innerTickCount = 0; + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + expect(outerTickCount, 4); + expect(innerTickCount, 4); + + await tester.pumpWidget( + nestedTickerModes( + outerEnabled: false, + innerEnabled: false, + ), + ); + outerTickCount = 0; + innerTickCount = 0; + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + expect(outerTickCount, 0); + expect(innerTickCount, 0); + }); + + testWidgets('Changing TickerMode does not rebuild widgets with SingleTickerProviderStateMixin', (WidgetTester tester) async { + Widget widgetUnderTest({required bool tickerEnabled}) { + return TickerMode( + enabled: tickerEnabled, + child: const _TickingWidget(), + ); + } + _TickingWidgetState state() => tester.state<_TickingWidgetState>(find.byType(_TickingWidget)); + + await tester.pumpWidget(widgetUnderTest(tickerEnabled: true)); + expect(state().ticker.isTicking, isTrue); + expect(state().buildCount, 1); + + await tester.pumpWidget(widgetUnderTest(tickerEnabled: false)); + expect(state().ticker.isTicking, isFalse); + expect(state().buildCount, 1); + + await tester.pumpWidget(widgetUnderTest(tickerEnabled: true)); + expect(state().ticker.isTicking, isTrue); + expect(state().buildCount, 1); + }); + + testWidgets('Changing TickerMode does not rebuild widgets with TickerProviderStateMixin', (WidgetTester tester) async { + Widget widgetUnderTest({required bool tickerEnabled}) { + return TickerMode( + enabled: tickerEnabled, + child: const _MultiTickingWidget(), + ); + } + _MultiTickingWidgetState state() => tester.state<_MultiTickingWidgetState>(find.byType(_MultiTickingWidget)); + + await tester.pumpWidget(widgetUnderTest(tickerEnabled: true)); + expect(state().ticker.isTicking, isTrue); + expect(state().buildCount, 1); + + await tester.pumpWidget(widgetUnderTest(tickerEnabled: false)); + expect(state().ticker.isTicking, isFalse); + expect(state().buildCount, 1); + + await tester.pumpWidget(widgetUnderTest(tickerEnabled: true)); + expect(state().ticker.isTicking, isTrue); + expect(state().buildCount, 1); + }); + + testWidgets('Moving widgets with SingleTickerProviderStateMixin to a new TickerMode ancestor works', (WidgetTester tester) async { + final GlobalKey tickingWidgetKey = GlobalKey(); + Widget widgetUnderTest({required LocalKey tickerModeKey, required bool tickerEnabled}) { + return TickerMode( + key: tickerModeKey, + enabled: tickerEnabled, + child: _TickingWidget(key: tickingWidgetKey), + ); + } + // Using different local keys to simulate changing TickerMode ancestors. + await tester.pumpWidget(widgetUnderTest(tickerEnabled: true, tickerModeKey: UniqueKey())); + final State tickerModeState = tester.state(find.byType(TickerMode)); + final _TickingWidgetState tickingState = tester.state<_TickingWidgetState>(find.byType(_TickingWidget)); + expect(tickingState.ticker.isTicking, isTrue); + + await tester.pumpWidget(widgetUnderTest(tickerEnabled: false, tickerModeKey: UniqueKey())); + expect(tester.state(find.byType(TickerMode)), isNot(same(tickerModeState))); + expect(tickingState, same(tester.state<_TickingWidgetState>(find.byType(_TickingWidget)))); + expect(tickingState.ticker.isTicking, isFalse); + }); + + testWidgets('Moving widgets with TickerProviderStateMixin to a new TickerMode ancestor works', (WidgetTester tester) async { + final GlobalKey tickingWidgetKey = GlobalKey(); + Widget widgetUnderTest({required LocalKey tickerModeKey, required bool tickerEnabled}) { + return TickerMode( + key: tickerModeKey, + enabled: tickerEnabled, + child: _MultiTickingWidget(key: tickingWidgetKey), + ); + } + // Using different local keys to simulate changing TickerMode ancestors. + await tester.pumpWidget(widgetUnderTest(tickerEnabled: true, tickerModeKey: UniqueKey())); + final State tickerModeState = tester.state(find.byType(TickerMode)); + final _MultiTickingWidgetState tickingState = tester.state<_MultiTickingWidgetState>(find.byType(_MultiTickingWidget)); + expect(tickingState.ticker.isTicking, isTrue); + + await tester.pumpWidget(widgetUnderTest(tickerEnabled: false, tickerModeKey: UniqueKey())); + expect(tester.state(find.byType(TickerMode)), isNot(same(tickerModeState))); + expect(tickingState, same(tester.state<_MultiTickingWidgetState>(find.byType(_MultiTickingWidget)))); + expect(tickingState.ticker.isTicking, isFalse); + }); + + testWidgets('Ticking widgets in old route do not rebuild when new route is pushed', (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp( + routes: <String, WidgetBuilder>{ + '/foo' : (BuildContext context) => const Text('New route'), + }, + home: const Row( + children: <Widget>[ + _TickingWidget(), + _MultiTickingWidget(), + Text('Old route'), + ], + ), + )); + + _MultiTickingWidgetState multiTickingState() => tester.state<_MultiTickingWidgetState>(find.byType(_MultiTickingWidget, skipOffstage: false)); + _TickingWidgetState tickingState() => tester.state<_TickingWidgetState>(find.byType(_TickingWidget, skipOffstage: false)); + + expect(find.text('Old route'), findsOneWidget); + expect(find.text('New route'), findsNothing); + + expect(multiTickingState().ticker.isTicking, isTrue); + expect(multiTickingState().buildCount, 1); + expect(tickingState().ticker.isTicking, isTrue); + expect(tickingState().buildCount, 1); + + tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/foo'); + await tester.pumpAndSettle(); + expect(find.text('Old route'), findsNothing); + expect(find.text('New route'), findsOneWidget); + + expect(multiTickingState().ticker.isTicking, isFalse); + expect(multiTickingState().buildCount, 1); + expect(tickingState().ticker.isTicking, isFalse); + expect(tickingState().buildCount, 1); + }); +} + +class _TickingWidget extends StatefulWidget { + const _TickingWidget({super.key, this.onTick}); + + final VoidCallback? onTick; + + @override + State<_TickingWidget> createState() => _TickingWidgetState(); +} + +class _TickingWidgetState extends State<_TickingWidget> with SingleTickerProviderStateMixin { + late Ticker ticker; + int buildCount = 0; + + @override + void initState() { + super.initState(); + ticker = createTicker((Duration _) { + widget.onTick?.call(); + })..start(); + } + + @override + Widget build(BuildContext context) { + buildCount += 1; + return Container(); + } + + @override + void dispose() { + ticker.dispose(); + super.dispose(); + } +} + +class _MultiTickingWidget extends StatefulWidget { + const _MultiTickingWidget({super.key}); + + @override + State<_MultiTickingWidget> createState() => _MultiTickingWidgetState(); +} + +class _MultiTickingWidgetState extends State<_MultiTickingWidget> with TickerProviderStateMixin { + late Ticker ticker; + int buildCount = 0; + + @override + void initState() { + super.initState(); + ticker = createTicker((Duration _) { + })..start(); + } + + @override + Widget build(BuildContext context) { + buildCount += 1; + return Container(); + } + + @override + void dispose() { + ticker.dispose(); + super.dispose(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/ticker_provider_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/ticker_provider_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..2f342dae0bab4ece1895b07412e3b422bcd295f4 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/ticker_provider_test.dart @@ -0,0 +1,331 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('TickerMode', (WidgetTester tester) async { + const Widget widget = TickerMode( + enabled: false, + child: CircularProgressIndicator(), + ); + expect(widget.toString, isNot(throwsException)); + + await tester.pumpWidget(widget); + + expect(tester.binding.transientCallbackCount, 0); + + await tester.pumpWidget(const TickerMode( + enabled: true, + child: CircularProgressIndicator(), + )); + + expect(tester.binding.transientCallbackCount, 1); + + await tester.pumpWidget(const TickerMode( + enabled: false, + child: CircularProgressIndicator(), + )); + + expect(tester.binding.transientCallbackCount, 0); + }); + + testWidgets('Navigation with TickerMode', (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp( + home: const LinearProgressIndicator(), + routes: <String, WidgetBuilder>{ + '/test': (BuildContext context) => const Text('hello'), + }, + )); + expect(tester.binding.transientCallbackCount, 1); + tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/test'); + expect(tester.binding.transientCallbackCount, 2); + await tester.pump(); + expect(tester.binding.transientCallbackCount, 2); + await tester.pump(const Duration(seconds: 5)); + expect(tester.binding.transientCallbackCount, 0); + tester.state<NavigatorState>(find.byType(Navigator)).pop(); + expect(tester.binding.transientCallbackCount, 1); + await tester.pump(); + expect(tester.binding.transientCallbackCount, 2); + await tester.pump(const Duration(seconds: 5)); + expect(tester.binding.transientCallbackCount, 1); + }); + + testWidgets('SingleTickerProviderStateMixin can handle not being used', (WidgetTester tester) async { + const Widget widget = BoringTickerTest(); + expect(widget.toString, isNot(throwsException)); + + await tester.pumpWidget(widget); + await tester.pumpWidget(Container()); + // the test is that this doesn't crash, like it used to... + }); + + group('TickerProviderStateMixin assertion control test', () { + testWidgets('SingleTickerProviderStateMixin create multiple tickers', (WidgetTester tester) async { + const Widget widget = _SingleTickerCreateMultipleTicker(); + await tester.pumpWidget(widget); + final dynamic exception = tester.takeException(); + expect(exception, isNotNull); + expect(exception, isFlutterError); + final FlutterError error = exception as FlutterError; + expect(error.diagnostics.length, 3); + expect(error.diagnostics[2].level, DiagnosticLevel.hint); + expect(error.diagnostics[2].toStringDeep(), equalsIgnoringHashCodes( + 'If a State is used for multiple AnimationController objects, or\n' + 'if it is passed to other objects and those objects might use it\n' + 'more than one time in total, then instead of mixing in a\n' + 'SingleTickerProviderStateMixin, use a regular\n' + 'TickerProviderStateMixin.\n', + )); + expect(error.toStringDeep(), equalsIgnoringHashCodes( + 'FlutterError\n' + ' _SingleTickerCreateMultipleTickerState is a\n' + ' SingleTickerProviderStateMixin but multiple tickers were created.\n' + ' A SingleTickerProviderStateMixin can only be used as a\n' + ' TickerProvider once.\n' + ' If a State is used for multiple AnimationController objects, or\n' + ' if it is passed to other objects and those objects might use it\n' + ' more than one time in total, then instead of mixing in a\n' + ' SingleTickerProviderStateMixin, use a regular\n' + ' TickerProviderStateMixin.\n', + )); + }); + + testWidgets('SingleTickerProviderStateMixin dispose while active', (WidgetTester tester) async { + final GlobalKey<_SingleTickerTestState> key = GlobalKey<_SingleTickerTestState>(); + final Widget widget = _SingleTickerTest(key: key); + await tester.pumpWidget(widget); + FlutterError? error; + key.currentState!.controller.repeat(); + try { + key.currentState!.dispose(); + } on FlutterError catch (e) { + error = e; + } finally { + expect(error, isNotNull); + expect(error!.diagnostics.length, 4); + expect(error.diagnostics[2].level, DiagnosticLevel.hint); + expect( + error.diagnostics[2].toStringDeep(), + 'Tickers used by AnimationControllers should be disposed by\n' + 'calling dispose() on the AnimationController itself. Otherwise,\n' + 'the ticker will leak.\n', + ); + expect(error.diagnostics[3], isA<DiagnosticsProperty<Ticker>>()); + expect(error.toStringDeep().split('\n').take(13).join('\n'), equalsIgnoringHashCodes( + 'FlutterError\n' + ' _SingleTickerTestState#00000(ticker active) was disposed with an\n' + ' active Ticker.\n' + ' _SingleTickerTestState created a Ticker via its\n' + ' SingleTickerProviderStateMixin, but at the time dispose() was\n' + ' called on the mixin, that Ticker was still active. The Ticker\n' + ' must be disposed before calling super.dispose().\n' + ' Tickers used by AnimationControllers should be disposed by\n' + ' calling dispose() on the AnimationController itself. Otherwise,\n' + ' the ticker will leak.\n' + ' The offending ticker was:\n' + ' Ticker(created by _SingleTickerTestState#00000)\n' + ' The stack trace when the Ticker was actually created was:', + )); + key.currentState!.controller.stop(); + } + }); + + testWidgets('SingleTickerProviderStateMixin dispose while active', (WidgetTester tester) async { + final GlobalKey<_SingleTickerTestState> key = GlobalKey<_SingleTickerTestState>(); + final Widget widget = _SingleTickerTest(key: key); + await tester.pumpWidget(widget); + FlutterError? error; + key.currentState!.controller.repeat(); + try { + key.currentState!.dispose(); + } on FlutterError catch (e) { + error = e; + } finally { + expect(error, isNotNull); + expect(error!.diagnostics.length, 4); + expect(error.diagnostics[2].level, DiagnosticLevel.hint); + expect( + error.diagnostics[2].toStringDeep(), + 'Tickers used by AnimationControllers should be disposed by\n' + 'calling dispose() on the AnimationController itself. Otherwise,\n' + 'the ticker will leak.\n', + ); + expect(error.diagnostics[3], isA<DiagnosticsProperty<Ticker>>()); + expect(error.toStringDeep().split('\n').take(13).join('\n'), equalsIgnoringHashCodes( + 'FlutterError\n' + ' _SingleTickerTestState#00000(ticker active) was disposed with an\n' + ' active Ticker.\n' + ' _SingleTickerTestState created a Ticker via its\n' + ' SingleTickerProviderStateMixin, but at the time dispose() was\n' + ' called on the mixin, that Ticker was still active. The Ticker\n' + ' must be disposed before calling super.dispose().\n' + ' Tickers used by AnimationControllers should be disposed by\n' + ' calling dispose() on the AnimationController itself. Otherwise,\n' + ' the ticker will leak.\n' + ' The offending ticker was:\n' + ' Ticker(created by _SingleTickerTestState#00000)\n' + ' The stack trace when the Ticker was actually created was:', + )); + key.currentState!.controller.stop(); + } + }); + + testWidgets('TickerProviderStateMixin dispose while any ticker is active', (WidgetTester tester) async { + final GlobalKey<_MultipleTickerTestState> key = GlobalKey<_MultipleTickerTestState>(); + final Widget widget = _MultipleTickerTest(key: key); + await tester.pumpWidget(widget); + FlutterError? error; + key.currentState!.controllers.first.repeat(); + try { + key.currentState!.dispose(); + } on FlutterError catch (e) { + error = e; + } finally { + expect(error, isNotNull); + expect(error!.diagnostics.length, 4); + expect(error.diagnostics[2].level, DiagnosticLevel.hint); + expect( + error.diagnostics[2].toStringDeep(), + 'Tickers used by AnimationControllers should be disposed by\n' + 'calling dispose() on the AnimationController itself. Otherwise,\n' + 'the ticker will leak.\n', + ); + expect(error.diagnostics[3], isA<DiagnosticsProperty<Ticker>>()); + expect(error.toStringDeep().split('\n').take(12).join('\n'), equalsIgnoringHashCodes( + 'FlutterError\n' + ' _MultipleTickerTestState#00000(tickers: tracking 2 tickers) was\n' + ' disposed with an active Ticker.\n' + ' _MultipleTickerTestState created a Ticker via its\n' + ' TickerProviderStateMixin, but at the time dispose() was called on\n' + ' the mixin, that Ticker was still active. All Tickers must be\n' + ' disposed before calling super.dispose().\n' + ' Tickers used by AnimationControllers should be disposed by\n' + ' calling dispose() on the AnimationController itself. Otherwise,\n' + ' the ticker will leak.\n' + ' The offending ticker was:\n' + ' _WidgetTicker(created by _MultipleTickerTestState#00000)', + )); + key.currentState!.controllers.first.stop(); + } + }); + }); + + testWidgets('SingleTickerProviderStateMixin does not call State.toString', (WidgetTester tester) async { + await tester.pumpWidget(const _SingleTickerTest()); + expect(tester.state<_SingleTickerTestState>(find.byType(_SingleTickerTest)).toStringCount, 0); + }); + + testWidgets('TickerProviderStateMixin does not call State.toString', (WidgetTester tester) async { + await tester.pumpWidget(const _MultipleTickerTest()); + expect(tester.state<_MultipleTickerTestState>(find.byType(_MultipleTickerTest)).toStringCount, 0); + }); +} + +class BoringTickerTest extends StatefulWidget { + const BoringTickerTest({ super.key }); + @override + State<BoringTickerTest> createState() => _BoringTickerTestState(); +} + +class _BoringTickerTestState extends State<BoringTickerTest> with SingleTickerProviderStateMixin { + @override + Widget build(BuildContext context) => Container(); +} + +class _SingleTickerTest extends StatefulWidget { + const _SingleTickerTest({super.key}); + + @override + _SingleTickerTestState createState() => _SingleTickerTestState(); +} + +class _SingleTickerTestState extends State<_SingleTickerTest> with SingleTickerProviderStateMixin { + late AnimationController controller; + + @override + void initState() { + super.initState(); + controller = AnimationController( + vsync: this, + duration: const Duration(seconds: 100), + ); + } + + @override + Widget build(BuildContext context) { + return Container(); + } + + int toStringCount = 0; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + toStringCount += 1; + return super.toString(minLevel: minLevel); + } +} + +class _MultipleTickerTest extends StatefulWidget { + const _MultipleTickerTest({super.key}); + + @override + _MultipleTickerTestState createState() => _MultipleTickerTestState(); +} + +class _MultipleTickerTestState extends State<_MultipleTickerTest> with TickerProviderStateMixin { + List<AnimationController> controllers = <AnimationController>[]; + + @override + void initState() { + super.initState(); + const Duration duration = Duration(seconds: 100); + controllers.add(AnimationController(vsync: this, duration: duration)); + controllers.add(AnimationController(vsync: this, duration: duration)); + } + + @override + Widget build(BuildContext context) { + return Container(); + } + + int toStringCount = 0; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + toStringCount += 1; + return super.toString(minLevel: minLevel); + } +} + +class _SingleTickerCreateMultipleTicker extends StatefulWidget { + const _SingleTickerCreateMultipleTicker(); + + @override + _SingleTickerCreateMultipleTickerState createState() => _SingleTickerCreateMultipleTickerState(); +} + +class _SingleTickerCreateMultipleTickerState extends State<_SingleTickerCreateMultipleTicker> with SingleTickerProviderStateMixin { + @override + void initState() { + super.initState(); + AnimationController( + duration: const Duration(seconds: 5), + vsync: this, + ); + AnimationController( + duration: const Duration(seconds: 6), + vsync: this, + ); + } + + @override + Widget build(BuildContext context) { + return Container(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/title_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/title_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..71dbf6f9e1c793b297a044c94be4a0878ab0b5e0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/title_test.dart @@ -0,0 +1,55 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('toString control test', (WidgetTester tester) async { + final Widget widget = Title( + color: const Color(0xFF00FF00), + title: 'Awesome app', + child: Container(), + ); + expect(widget.toString, isNot(throwsException)); + }); + + testWidgets('should handle having no title', (WidgetTester tester) async { + final Title widget = Title( + color: const Color(0xFF00FF00), + child: Container(), + ); + expect(widget.toString, isNot(throwsException)); + expect(widget.title, equals('')); + expect(widget.color, equals(const Color(0xFF00FF00))); + }); + + testWidgets('should not allow non-opaque color', (WidgetTester tester) async { + expect(() => Title( + color: const Color(0x00000000), + child: Container(), + ), throwsAssertionError); + }); + + testWidgets('should not pass "null" to setApplicationSwitcherDescription', (WidgetTester tester) async { + final List<MethodCall> log = <MethodCall>[]; + + tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, (MethodCall methodCall) async { + log.add(methodCall); + return null; + }); + + await tester.pumpWidget(Title( + color: const Color(0xFF00FF00), + child: Container(), + )); + + expect(log, hasLength(1)); + expect(log.single, isMethodCall( + 'SystemChrome.setApplicationSwitcherDescription', + arguments: <String, dynamic>{'label': '', 'primaryColor': 4278255360}, + )); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/toggleable_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/toggleable_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..0c4627c3e9ad505ab7bcd79e8c9bd7bad2922e6a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/toggleable_test.dart @@ -0,0 +1,19 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Toggleable exists in widget layer', (WidgetTester tester) async { + final TestPainter testPainter = TestPainter(); + expect(testPainter, isA<ToggleablePainter>()); + expect(testPainter, isNot(throwsException)); + }); +} + +class TestPainter extends ToggleablePainter { + @override + void paint(Canvas canvas, Size size) {} +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tracking_scroll_controller_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tracking_scroll_controller_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..884583e1139f2b25c8f42bd04af422f368527f51 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tracking_scroll_controller_test.dart @@ -0,0 +1,101 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('TrackingScrollController saves offset', (WidgetTester tester) async { + final TrackingScrollController controller = TrackingScrollController(); + addTearDown(controller.dispose); + const double listItemHeight = 100.0; + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: PageView.builder( + itemBuilder: (BuildContext context, int index) { + return ListView( + controller: controller, + children: List<Widget>.generate( + 10, + (int i) => SizedBox( + height: listItemHeight, + child: Text('Page$index-Item$i'), + ), + ).toList(), + ); + }, + ), + ), + ); + + expect(find.text('Page0-Item1'), findsOneWidget); + expect(find.text('Page1-Item1'), findsNothing); + expect(find.text('Page2-Item0'), findsNothing); + expect(find.text('Page2-Item1'), findsNothing); + + controller.jumpTo(listItemHeight + 10); + await tester.pumpAndSettle(); + + await tester.fling(find.text('Page0-Item1'), const Offset(-100.0, 0.0), 10000.0); + await tester.pumpAndSettle(); + + expect(find.text('Page0-Item1'), findsNothing); + expect(find.text('Page1-Item1'), findsOneWidget); + expect(find.text('Page2-Item0'), findsNothing); + expect(find.text('Page2-Item1'), findsNothing); + + await tester.fling(find.text('Page1-Item1'), const Offset(-100.0, 0.0), 10000.0); + await tester.pumpAndSettle(); + + expect(find.text('Page0-Item1'), findsNothing); + expect(find.text('Page1-Item1'), findsNothing); + expect(find.text('Page2-Item0'), findsNothing); + expect(find.text('Page2-Item1'), findsOneWidget); + + await tester.pumpWidget(const Text('Another page', textDirection: TextDirection.ltr)); + + expect(controller.initialScrollOffset, 0.0); + }); + + testWidgets('TrackingScrollController saves offset', (WidgetTester tester) async { + int attach = 0; + int detach = 0; + final TrackingScrollController controller = TrackingScrollController( + onAttach: (_) { attach++; }, + onDetach: (_) { detach++; }, + ); + addTearDown(controller.dispose); + const double listItemHeight = 100.0; + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: PageView.builder( + itemBuilder: (BuildContext context, int index) { + return ListView( + controller: controller, + children: List<Widget>.generate( + 10, + (int i) => SizedBox( + height: listItemHeight, + child: Text('Page$index-Item$i'), + ), + ).toList(), + ); + }, + ), + )); + await tester.pumpAndSettle(); + + expect(attach, 1); + expect(detach, 0); + + await tester.pumpWidget(Container()); + await tester.pumpAndSettle(); + + expect(attach, 1); + expect(detach, 1); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/transform_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/transform_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..c772678c236771b6a7dd73da8e8f7f45e9ba14d0 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/transform_test.dart @@ -0,0 +1,898 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is run as part of a reduced test set in CI on Mac and Windows +// machines. +@Tags(<String>['reduced-test-set']) +library; + +import 'dart:math' as math; +import 'dart:ui' as ui; + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:vector_math/vector_math_64.dart'; + +void main() { + testWidgets('Transform origin', (WidgetTester tester) async { + bool didReceiveTap = false; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Positioned( + top: 100.0, + left: 100.0, + child: Container( + width: 100.0, + height: 100.0, + color: const Color(0xFF0000FF), + ), + ), + Positioned( + top: 100.0, + left: 100.0, + child: SizedBox( + width: 100.0, + height: 100.0, + child: Transform( + transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0), + origin: const Offset(100.0, 50.0), + child: GestureDetector( + onTap: () { + didReceiveTap = true; + }, + child: Container( + color: const Color(0xFF00FFFF), + ), + ), + ), + ), + ), + ], + ), + ), + ); + + expect(didReceiveTap, isFalse); + await tester.tapAt(const Offset(110.0, 110.0)); + expect(didReceiveTap, isFalse); + await tester.tapAt(const Offset(190.0, 150.0)); + expect(didReceiveTap, isTrue); + }); + + testWidgets('Transform alignment', (WidgetTester tester) async { + bool didReceiveTap = false; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Positioned( + top: 100.0, + left: 100.0, + child: Container( + width: 100.0, + height: 100.0, + color: const Color(0xFF0000FF), + ), + ), + Positioned( + top: 100.0, + left: 100.0, + child: SizedBox( + width: 100.0, + height: 100.0, + child: Transform( + transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0), + alignment: Alignment.centerRight, + child: GestureDetector( + onTap: () { + didReceiveTap = true; + }, + child: Container( + color: const Color(0xFF00FFFF), + ), + ), + ), + ), + ), + ], + ), + ), + ); + + expect(didReceiveTap, isFalse); + await tester.tapAt(const Offset(110.0, 110.0)); + expect(didReceiveTap, isFalse); + await tester.tapAt(const Offset(190.0, 150.0)); + expect(didReceiveTap, isTrue); + }); + + testWidgets('Transform AlignmentDirectional alignment', (WidgetTester tester) async { + bool didReceiveTap = false; + + Widget buildFrame(TextDirection textDirection, AlignmentGeometry alignment) { + return Directionality( + textDirection: textDirection, + child: Stack( + children: <Widget>[ + Positioned( + top: 100.0, + left: 100.0, + child: Container( + width: 100.0, + height: 100.0, + color: const Color(0xFF0000FF), + ), + ), + Positioned( + top: 100.0, + left: 100.0, + child: SizedBox( + width: 100.0, + height: 100.0, + child: Transform( + transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0), + alignment: alignment, + child: GestureDetector( + onTap: () { + didReceiveTap = true; + }, + child: Container( + color: const Color(0xFF00FFFF), + ), + ), + ), + ), + ), + ], + ), + ); + } + + await tester.pumpWidget(buildFrame(TextDirection.ltr, AlignmentDirectional.centerEnd)); + didReceiveTap = false; + await tester.tapAt(const Offset(110.0, 110.0)); + expect(didReceiveTap, isFalse); + await tester.tapAt(const Offset(190.0, 150.0)); + expect(didReceiveTap, isTrue); + + await tester.pumpWidget(buildFrame(TextDirection.rtl, AlignmentDirectional.centerStart)); + didReceiveTap = false; + await tester.tapAt(const Offset(110.0, 110.0)); + expect(didReceiveTap, isFalse); + await tester.tapAt(const Offset(190.0, 150.0)); + expect(didReceiveTap, isTrue); + + await tester.pumpWidget(buildFrame(TextDirection.ltr, AlignmentDirectional.centerStart)); + didReceiveTap = false; + await tester.tapAt(const Offset(190.0, 150.0)); + expect(didReceiveTap, isFalse); + await tester.tapAt(const Offset(110.0, 150.0)); + expect(didReceiveTap, isTrue); + + await tester.pumpWidget(buildFrame(TextDirection.rtl, AlignmentDirectional.centerEnd)); + didReceiveTap = false; + await tester.tapAt(const Offset(190.0, 150.0)); + expect(didReceiveTap, isFalse); + await tester.tapAt(const Offset(110.0, 150.0)); + expect(didReceiveTap, isTrue); + }); + + testWidgets('Transform offset + alignment', (WidgetTester tester) async { + bool didReceiveTap = false; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Positioned( + top: 100.0, + left: 100.0, + child: Container( + width: 100.0, + height: 100.0, + color: const Color(0xFF0000FF), + ), + ), + Positioned( + top: 100.0, + left: 100.0, + child: SizedBox( + width: 100.0, + height: 100.0, + child: Transform( + transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0), + origin: const Offset(100.0, 0.0), + alignment: Alignment.centerLeft, + child: GestureDetector( + onTap: () { + didReceiveTap = true; + }, + child: Container( + color: const Color(0xFF00FFFF), + ), + ), + ), + ), + ), + ], + ), + ), + ); + + expect(didReceiveTap, isFalse); + await tester.tapAt(const Offset(110.0, 110.0)); + expect(didReceiveTap, isFalse); + await tester.tapAt(const Offset(190.0, 150.0)); + expect(didReceiveTap, isTrue); + }); + + testWidgets('Composited transform offset', (WidgetTester tester) async { + await tester.pumpWidget( + Center( + child: SizedBox( + width: 400.0, + height: 300.0, + child: ClipRect( + child: Transform( + transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0), + child: RepaintBoundary( + child: Container( + color: const Color(0xFF00FF00), + ), + ), + ), + ), + ), + ), + ); + + final List<Layer> layers = tester.layers + ..retainWhere((Layer layer) => layer is TransformLayer); + expect(layers.length, 2); + // The first transform is from the render view. + final TransformLayer layer = layers[1] as TransformLayer; + final Matrix4 transform = layer.transform!; + expect(transform.getTranslation(), equals(Vector3(100.0, 75.0, 0.0))); + }); + + testWidgets('Transform.rotate', (WidgetTester tester) async { + await tester.pumpWidget( + Transform.rotate( + angle: math.pi / 2.0, + child: RepaintBoundary(child: Container()), + ), + ); + + final List<Layer> layers = tester.layers + ..retainWhere((Layer layer) => layer is TransformLayer); + expect(layers.length, 2); + // The first transform is from the render view. + final TransformLayer layer = layers[1] as TransformLayer; + final Matrix4 transform = layer.transform!; + expect(transform.storage, <dynamic>[ + moreOrLessEquals(0.0), 1.0, 0.0, 0.0, + -1.0, moreOrLessEquals(0.0), 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 700.0, -100.0, 0.0, 1.0, + ]); + }); + + testWidgets('applyPaintTransform of Transform in Padding', (WidgetTester tester) async { + await tester.pumpWidget( + Padding( + padding: const EdgeInsets.only( + left: 30.0, + top: 20.0, + right: 50.0, + bottom: 70.0, + ), + child: Transform( + transform: Matrix4.diagonal3Values(2.0, 2.0, 2.0), + child: const Placeholder(), + ), + ), + ); + expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(30.0, 20.0)); + }); + + testWidgets('Transform.translate', (WidgetTester tester) async { + await tester.pumpWidget( + Transform.translate( + offset: const Offset(100.0, 50.0), + child: RepaintBoundary(child: Container()), + ), + ); + + // This should not cause a transform layer to be inserted. + final List<Layer> layers = tester.layers + ..retainWhere((Layer layer) => layer is TransformLayer); + expect(layers.length, 1); // only the render view + expect(tester.getTopLeft(find.byType(Container)), const Offset(100.0, 50.0)); + }); + + testWidgets('Transform.scale', (WidgetTester tester) async { + await tester.pumpWidget( + Transform.scale( + scale: 2.0, + child: RepaintBoundary(child: Container()), + ), + ); + + final List<Layer> layers = tester.layers + ..retainWhere((Layer layer) => layer is TransformLayer); + expect(layers.length, 2); + // The first transform is from the render view. + final TransformLayer layer = layers[1] as TransformLayer; + final Matrix4 transform = layer.transform!; + expect(transform.storage, <dynamic>[ + // These are column-major, not row-major. + 2.0, 0.0, 0.0, 0.0, + 0.0, 2.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + -400.0, -300.0, 0.0, 1.0, // it's 1600x1200, centered in an 800x600 square + ]); + }); + + testWidgets('Transform with nan value short-circuits rendering', (WidgetTester tester) async { + await tester.pumpWidget( + Transform( + transform: Matrix4.identity() + ..storage[0] = double.nan, + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers, hasLength(1)); + }); + + testWidgets('Transform with inf value short-circuits rendering', (WidgetTester tester) async { + await tester.pumpWidget( + Transform( + transform: Matrix4.identity() + ..storage[0] = double.infinity, + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers, hasLength(1)); + }); + + testWidgets('Transform with -inf value short-circuits rendering', (WidgetTester tester) async { + await tester.pumpWidget( + Transform( + transform: Matrix4.identity() + ..storage[0] = double.negativeInfinity, + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers, hasLength(1)); + }); + + testWidgets('Transform.rotate does not remove layers due to singular short-circuit', (WidgetTester tester) async { + await tester.pumpWidget( + Transform.rotate( + angle: math.pi / 2, + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers, hasLength(3)); + }); + + testWidgets('Transform.rotate creates nice rotation matrices for 0, 90, 180, 270 degrees', (WidgetTester tester) async { + await tester.pumpWidget( + Transform.rotate( + angle: math.pi / 2, + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers[1], isA<TransformLayer>() + .having((TransformLayer layer) => layer.transform, 'transform', equals(Matrix4.fromList(<double>[ + 0.0, -1.0, 0.0, 700.0, + 1.0, 0.0, 0.0, -100.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0, + ])..transpose())) + ); + + await tester.pumpWidget( + Transform.rotate( + angle: math.pi, + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers[1], isA<TransformLayer>() + .having((TransformLayer layer) => layer.transform, 'transform', equals(Matrix4.fromList(<double>[ + -1.0, 0.0, 0.0, 800.0, + 0.0, -1.0, 0.0, 600.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0, + ])..transpose())) + ); + + await tester.pumpWidget( + Transform.rotate( + angle: 3 * math.pi / 2, + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers[1], isA<TransformLayer>() + .having((TransformLayer layer) => layer.transform, 'transform', equals(Matrix4.fromList(<double>[ + 0.0, 1.0, 0.0, 100.0, + -1.0, 0.0, 0.0, 700.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0, + ])..transpose())) + ); + + await tester.pumpWidget( + Transform.rotate( + angle: 0, + child: RepaintBoundary(child: Container()), + ), + ); + + // No transform layer created + expect(tester.layers[1], isA<OffsetLayer>()); + expect(tester.layers, hasLength(2)); + }); + + testWidgets('Transform.scale with 0.0 does not paint child layers', (WidgetTester tester) async { + await tester.pumpWidget( + Transform.scale( + scale: 0.0, + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers, hasLength(1)); // root transform layer + + await tester.pumpWidget( + Transform.scale( + scaleX: 0.0, + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers, hasLength(1)); + + await tester.pumpWidget( + Transform.scale( + scaleY: 0.0, + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers, hasLength(1)); + + await tester.pumpWidget( + Transform.scale( + scale: 0.01, // small but non-zero + child: RepaintBoundary(child: Container()), + ), + ); + + expect(tester.layers, hasLength(3)); + }); + + + testWidgets('Translated child into translated box - hit test', (WidgetTester tester) async { + final GlobalKey key1 = GlobalKey(); + bool pointerDown = false; + await tester.pumpWidget( + Transform.translate( + offset: const Offset(100.0, 50.0), + child: Transform.translate( + offset: const Offset(1000.0, 1000.0), + child: Listener( + onPointerDown: (PointerDownEvent event) { + pointerDown = true; + }, + child: Container( + key: key1, + color: const Color(0xFF000000), + ), + ), + ), + ), + ); + expect(pointerDown, isFalse); + await tester.tap(find.byKey(key1)); + expect(pointerDown, isTrue); + }); + + Widget generateTransform(bool needsCompositing, double angle) { + final Widget customPaint = CustomPaint(painter: TestRectPainter()); + return Transform( + transform: MatrixUtils.createCylindricalProjectionTransform( + radius: 100, + angle: angle, + perspective: 0.003, + ), + // A RepaintBoundary child forces the Transform to needsCompositing + child: needsCompositing ? RepaintBoundary(child: customPaint) : customPaint, + ); + } + + testWidgets( + '3D transform renders the same with or without needsCompositing', + (WidgetTester tester) async { + for (double angle = 0; angle <= math.pi/4; angle += 0.01) { + await tester.pumpWidget(RepaintBoundary(child: generateTransform(true, angle))); + final RenderBox renderBox = tester.binding.renderView.child!; + final OffsetLayer layer = renderBox.debugLayer! as OffsetLayer; + final ui.Image imageWithCompositing = await layer.toImage(renderBox.paintBounds); + addTearDown(imageWithCompositing.dispose); + + await tester.pumpWidget(RepaintBoundary(child: generateTransform(false, angle))); + await expectLater(find.byType(RepaintBoundary).first, matchesReferenceImage(imageWithCompositing)); + } + }, + skip: isBrowser, // due to https://github.com/flutter/flutter/issues/49857 + ); + + List<double> extractMatrix(ui.ImageFilter? filter) { + final List<String> numbers = filter.toString().split('[').last.split(']').first.split(','); + return numbers.map<double>((String str) => double.parse(str.trim())).toList(); + } + + testWidgets('Transform.translate with FilterQuality produces filter layer', (WidgetTester tester) async { + await tester.pumpWidget( + Transform.translate( + offset: const Offset(25.0, 25.0), + filterQuality: FilterQuality.low, + child: const SizedBox(width: 100, height: 100), + ), + ); + expect(tester.layers.whereType<ImageFilterLayer>().length, 1); + final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first; + expect(extractMatrix(layer.imageFilter), <double>[ + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 25.0, 25.0, 0.0, 1.0, + ]); + }); + + testWidgets('Transform.scale with FilterQuality produces filter layer', (WidgetTester tester) async { + await tester.pumpWidget( + Transform.scale( + scale: 3.14159, + filterQuality: FilterQuality.low, + child: const SizedBox(width: 100, height: 100), + ), + ); + expect(tester.layers.whereType<ImageFilterLayer>().length, 1); + final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first; + expect(extractMatrix(layer.imageFilter), <double>[ + 3.14159, 0.0, 0.0, 0.0, + 0.0, 3.14159, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + -856.636, -642.477, 0.0, 1.0, + ]); + }); + + testWidgets('Transform.rotate with FilterQuality produces filter layer', (WidgetTester tester) async { + await tester.pumpWidget( + Transform.rotate( + angle: math.pi / 4, + filterQuality: FilterQuality.low, + child: const SizedBox(width: 100, height: 100), + ), + ); + expect(tester.layers.whereType<ImageFilterLayer>().length, 1); + final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first; + expect(extractMatrix(layer.imageFilter), <dynamic>[ + moreOrLessEquals(0.7071067811865476), moreOrLessEquals(0.7071067811865475), 0.0, 0.0, + moreOrLessEquals(-0.7071067811865475), moreOrLessEquals(0.7071067811865476), 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + moreOrLessEquals(329.28932188134524), moreOrLessEquals(-194.97474683058329), 0.0, 1.0, + ]); + }); + + testWidgets('Offset Transform.rotate with FilterQuality produces filter layer', (WidgetTester tester) async { + await tester.pumpWidget( + SizedBox(width: 400, height: 400, + child: Center( + child: Transform.rotate( + angle: math.pi / 4, + filterQuality: FilterQuality.low, + child: const SizedBox(width: 100, height: 100), + ), + ), + ), + ); + expect(tester.layers.whereType<ImageFilterLayer>().length, 1); + final ImageFilterLayer layer = tester.layers.whereType<ImageFilterLayer>().first; + expect(extractMatrix(layer.imageFilter), <dynamic>[ + moreOrLessEquals(0.7071067811865476), moreOrLessEquals(0.7071067811865475), 0.0, 0.0, + moreOrLessEquals(-0.7071067811865475), moreOrLessEquals(0.7071067811865476), 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + moreOrLessEquals(329.28932188134524), moreOrLessEquals(-194.97474683058329), 0.0, 1.0, + ]); + }); + + testWidgets('Transform layers update to match child and filterQuality', (WidgetTester tester) async { + await tester.pumpWidget( + Transform.rotate( + angle: math.pi / 4, + filterQuality: FilterQuality.low, + child: const SizedBox(width: 100, height: 100), + ), + ); + expect(tester.layers.whereType<ImageFilterLayer>(), hasLength(1)); + + await tester.pumpWidget( + Transform.rotate( + angle: math.pi / 4, + child: const SizedBox(width: 100, height: 100), + ), + ); + expect(tester.layers.whereType<ImageFilterLayer>(), isEmpty); + + await tester.pumpWidget( + Transform.rotate( + angle: math.pi / 4, + filterQuality: FilterQuality.low, + ), + ); + expect(tester.layers.whereType<ImageFilterLayer>(), isEmpty); + + await tester.pumpWidget( + Transform.rotate( + angle: math.pi / 4, + filterQuality: FilterQuality.low, + child: const SizedBox(width: 100, height: 100), + ), + ); + expect(tester.layers.whereType<ImageFilterLayer>(), hasLength(1)); + }); + + testWidgets('Transform layers with filterQuality golden', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: GridView.count( + crossAxisCount: 3, + children: <Widget>[ + Transform.rotate( + angle: math.pi / 6, + child: Center(child: Container(width: 100, height: 20, color: const Color(0xffffff00))), + ), + Transform.scale( + scale: 1.5, + child: Center(child: Container(width: 100, height: 20, color: const Color(0xffffff00))), + ), + Transform.translate( + offset: const Offset(20.0, 60.0), + child: Center(child: Container(width: 100, height: 20, color: const Color(0xffffff00))), + ), + Transform.rotate( + angle: math.pi / 6, + filterQuality: FilterQuality.low, + child: Center(child: Container(width: 100, height: 20, color: const Color(0xff00ff00))), + ), + Transform.scale( + scale: 1.5, + filterQuality: FilterQuality.low, + child: Center(child: Container(width: 100, height: 20, color: const Color(0xff00ff00))), + ), + Transform.translate( + offset: const Offset(20.0, 60.0), + filterQuality: FilterQuality.low, + child: Center(child: Container(width: 100, height: 20, color: const Color(0xff00ff00))), + ), + ], + ), + ), + ); + await expectLater( + find.byType(GridView), + matchesGoldenFile('transform_golden.BitmapRotate.png'), + ); + }); + + testWidgets("Transform.scale() does not accept all three 'scale', 'scaleX' and 'scaleY' parameters to be non-null", (WidgetTester tester) async { + await expectLater(() { + tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Transform.scale( + scale: 1.0, + scaleX: 1.0, + scaleY: 1.0, + child: const SizedBox( + height: 100, + width: 100, + ), + ), + ))); + }, throwsAssertionError); + }); + + testWidgets("Transform.scale() needs at least one of 'scale', 'scaleX' and 'scaleY' to be non-null, otherwise throws AssertionError", (WidgetTester tester) async { + await expectLater(() { + tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Transform.scale( + child: const SizedBox( + height: 100, + width: 100, + ), + ), + ))); + }, throwsAssertionError); + }); + + testWidgets("Transform.scale() scales widget uniformly with 'scale' parameter", (WidgetTester tester) async { + const double scale = 1.5; + const double height = 100; + const double width = 150; + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: SizedBox( + height: 400, + width: 400, + child: Center( + child: Transform.scale( + scale: scale, + child: Container( + height: height, + width: width, + decoration: const BoxDecoration(), + ), + ), + ), + ))); + + const Size target = Size(width * scale, height * scale); + + expect(tester.getBottomRight(find.byType(Container)), target.bottomRight(tester.getTopLeft(find.byType(Container)))); + }); + + testWidgets("Transform.scale() scales widget according to 'scaleX' and 'scaleY'", (WidgetTester tester) async { + const double scaleX = 1.5; + const double scaleY = 1.2; + const double height = 100; + const double width = 150; + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: SizedBox( + height: 400, + width: 400, + child: Center( + child: Transform.scale( + scaleX: scaleX, + scaleY: scaleY, + child: Container( + height: height, + width: width, + decoration: const BoxDecoration(), + ), + ), + ), + ))); + + const Size target = Size(width * scaleX, height * scaleY); + + expect(tester.getBottomRight(find.byType(Container)), target.bottomRight(tester.getTopLeft(find.byType(Container)))); + }); + + testWidgets( + 'Transform.flip does flip child correctly', + (WidgetTester tester) async { + const Offset topRight = Offset(60, 20); + const Offset bottomLeft = Offset(20, 60); + const Offset bottomRight = Offset(60, 60); + + bool tappedRed = false; + + const Widget square = SizedBox.square(dimension: 40); + final Widget child = Column( + mainAxisSize: MainAxisSize.min, + children: <Widget> [ + Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ + GestureDetector( + onTap: () => tappedRed = true, + child: const ColoredBox(color: Color(0xffff0000), child: square), + ), + const ColoredBox(color: Color(0xff00ff00), child: square), + ]), + const Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ + ColoredBox(color: Color(0xff0000ff), child: square), + ColoredBox(color: Color(0xffeeff00), child: square), + ]), + ], + ); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: Transform.flip( + flipX: true, + child: child, + ), + ), + ), + ); + + await tester.pumpAndSettle(); + + await tester.tapAt(topRight); + + expect(tappedRed, isTrue, reason: 'Transform.flip cannot flipX'); + + tappedRed = false; + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: Transform.flip( + flipY: true, + child: child, + ), + ), + ), + ); + + await tester.pumpAndSettle(); + + await tester.tapAt(bottomLeft); + + expect(tappedRed, isTrue, reason: 'Transform.flip cannot flipY'); + + tappedRed = false; + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: Transform.flip( + flipX: true, + flipY: true, + child: child, + ), + ), + ), + ); + + await tester.pumpAndSettle(); + + await tester.tapAt(bottomRight); + + expect( + tappedRed, + isTrue, + reason: 'Transform.flip cannot flipX and flipY together', + ); + }, + ); +} + +class TestRectPainter extends CustomPainter { + @override + void paint(ui.Canvas canvas, ui.Size size) { + canvas.drawRect( + const Offset(200, 200) & const Size(10, 10), + Paint()..color = const Color(0xFFFF0000), + ); + } + @override + bool shouldRepaint(CustomPainter oldDelegate) => true; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/transformed_scrollable_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/transformed_scrollable_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..3c872353e2be1cc2321ac045621e00f74cf66662 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/transformed_scrollable_test.dart @@ -0,0 +1,223 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Scrollable scaled up', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: Transform.scale( + scale: 2.0, + child: Center( + child: SizedBox( + width: 200, + child: ListView.builder( + controller: controller, + cacheExtent: 0.0, + itemBuilder: (BuildContext context, int index) { + return Container( + height: 100.0, + color: index.isEven ? Colors.blue : Colors.red, + child: Text('Tile $index'), + ); + }, + ), + ), + ), + ), + ), + ); + expect(controller.offset, 0.0); + + await tester.drag(find.byType(ListView), const Offset(0.0, -100.0)); + await tester.pump(); + expect(controller.offset, 50.0); // 100.0 / 2.0 + + await tester.drag(find.byType(ListView), const Offset(80.0, -70.0)); + await tester.pump(); + expect(controller.offset, 85.0); // 50.0 + (70.0 / 2) + + await tester.drag(find.byType(ListView), const Offset(100.0, 0.0)); + await tester.pump(); + expect(controller.offset, 85.0); + + await tester.drag(find.byType(ListView), const Offset(0.0, 85.0)); + await tester.pump(); + expect(controller.offset, 42.5); // 85.0 - (85.0 / 2) + }); + + testWidgets('Scrollable scaled down', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: Transform.scale( + scale: 0.5, + child: Center( + child: SizedBox( + width: 200, + child: ListView.builder( + controller: controller, + cacheExtent: 0.0, + itemBuilder: (BuildContext context, int index) { + return Container( + height: 100.0, + color: index.isEven ? Colors.blue : Colors.red, + child: Text('Tile $index'), + ); + }, + ), + ), + ), + ), + ), + ); + expect(controller.offset, 0.0); + + await tester.drag(find.byType(ListView), const Offset(0.0, -100.0)); + await tester.pump(); + expect(controller.offset, 200.0); // 100.0 * 2.0 + + await tester.drag(find.byType(ListView), const Offset(80.0, -70.0)); + await tester.pump(); + expect(controller.offset, 340.0); // 200.0 + (70.0 * 2) + + await tester.drag(find.byType(ListView), const Offset(100.0, 0.0)); + await tester.pump(); + expect(controller.offset, 340.0); + + await tester.drag(find.byType(ListView), const Offset(0.0, 170.0)); + await tester.pump(); + expect(controller.offset, 0.0); // 340.0 - (170.0 * 2) + }); + + testWidgets('Scrollable rotated 90 degrees', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: Transform.rotate( + angle: math.pi / 2, + child: Center( + child: SizedBox( + width: 200, + child: ListView.builder( + controller: controller, + cacheExtent: 0.0, + itemBuilder: (BuildContext context, int index) { + return Container( + height: 100.0, + color: index.isEven ? Colors.blue : Colors.red, + child: Text('Tile $index'), + ); + }, + ), + ), + ), + ), + ), + ); + expect(controller.offset, 0.0); + + await tester.drag(find.byType(ListView), const Offset(100.0, 0.0)); + await tester.pump(); + expect(controller.offset, 100.0); + + await tester.drag(find.byType(ListView), const Offset(0.0, -100.0)); + await tester.pump(); + expect(controller.offset, 100.0); + + await tester.drag(find.byType(ListView), const Offset(-70.0, -50.0)); + await tester.pump(); + expect(controller.offset, 30.0); // 100.0 - 70.0 + }); + + testWidgets('Perspective transform on scrollable', (WidgetTester tester) async { + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: Transform( + transform: Matrix4.identity() + ..setEntry(3, 2, 0.001) + ..rotateX(math.pi / 4), + child: Center( + child: SizedBox( + width: 200, + child: ListView.builder( + controller: controller, + cacheExtent: 0.0, + itemBuilder: (BuildContext context, int index) { + return Container( + height: 100.0, + color: index.isEven ? Colors.blue : Colors.red, + child: Text('Tile $index'), + ); + }, + ), + ), + ), + ), + ), + ); + expect(controller.offset, 0.0); + + // We want to test that the point in the ListView that the finger touches + // on the screen stays under the finger as the finger scrolls the ListView + // in vertical direction. For this, we pick a point in the ListView (here + // the center of Tile 5) and calculate its position in the coordinate space + // of the screen. We then place our finger on that point and drag that + // point up in vertical direction. After the scroll activity is done, + // we verify that - in the coordinate space of the screen (!) - the point + // has moved the same distance as the finger. Due to the perspective + // transform the point will have moved more distance in the *local* + // coordinate system of the ListView. + + // Calculate where the center of Tile 5 is located in the coordinate + // space of the screen. We cannot use `tester.getCenter` because it + // does not properly remove the perspective component from the transform + // to give us the place on the screen at which we need to touch the screen + // to have the center of Tile 5 directly under our finger. + final RenderBox tile5 = tester.renderObject(find.text('Tile 5')); + final Offset pointOnScreenStart = MatrixUtils.transformPoint( + PointerEvent.removePerspectiveTransform(tile5.getTransformTo(null)), + tile5.size.center(Offset.zero), + ); + + // Place the finger on the tracked point and move the finger upwards for + // 50 pixels to scroll the ListView (the ListView's scroll offset will + // move more then 50 pixels due to the perspective transform). + await tester.dragFrom(pointOnScreenStart, const Offset(0.0, -50.0)); + await tester.pump(); + + // Get the new position of the tracked point in the screen's coordinate + // system. + final Offset pointOnScreenEnd = MatrixUtils.transformPoint( + PointerEvent.removePerspectiveTransform(tile5.getTransformTo(null)), + tile5.size.center(Offset.zero), + ); + + // The tracked point (in the coordinate space of the screen) and the finger + // should have moved the same vertical distance over the screen. + expect( + pointOnScreenStart.dy - pointOnScreenEnd.dy, + within(distance: 0.00001, from: 50.0), + ); + + // While the point traveled the same distance as the finger in the + // coordinate space of the screen, the scroll view actually moved far more + // pixels in its local coordinate system due to the perspective transform. + expect(controller.offset, greaterThan(100)); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/transitions_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/transitions_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..f1b39b509658fc270abf0dd990af7c01cf7b8fa1 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/transitions_test.dart @@ -0,0 +1,985 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('toString control test', (WidgetTester tester) async { + const Widget widget = FadeTransition( + opacity: kAlwaysCompleteAnimation, + child: Text('Ready', textDirection: TextDirection.ltr), + ); + expect(widget.toString, isNot(throwsException)); + }); + + group('DecoratedBoxTransition test', () { + final DecorationTween decorationTween = DecorationTween( + begin: BoxDecoration( + color: const Color(0xFFFFFFFF), + border: Border.all( + width: 4.0, + ), + borderRadius: BorderRadius.zero, + boxShadow: const <BoxShadow>[ + BoxShadow( + color: Color(0x66000000), + blurRadius: 10.0, + spreadRadius: 4.0, + ), + ], + ), + end: BoxDecoration( + color: const Color(0xFF000000), + border: Border.all( + color: const Color(0xFF202020), + ), + borderRadius: const BorderRadius.all(Radius.circular(10.0)), + // No shadow. + ), + ); + + late AnimationController controller; + + setUp(() { + controller = AnimationController(vsync: const TestVSync()); + }); + + testWidgets('decoration test', (WidgetTester tester) async { + final DecoratedBoxTransition transitionUnderTest = + DecoratedBoxTransition( + decoration: decorationTween.animate(controller), + child: const Text( + "Doesn't matter", + textDirection: TextDirection.ltr, + ), + ); + + await tester.pumpWidget(transitionUnderTest); + RenderDecoratedBox actualBox = tester.renderObject(find.byType(DecoratedBox)); + BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration; + + expect(actualDecoration.color, const Color(0xFFFFFFFF)); + expect(actualDecoration.boxShadow![0].blurRadius, 10.0); + expect(actualDecoration.boxShadow![0].spreadRadius, 4.0); + expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); + + controller.value = 0.5; + + await tester.pump(); + actualBox = tester.renderObject(find.byType(DecoratedBox)); + actualDecoration = actualBox.decoration as BoxDecoration; + + expect(actualDecoration.color, const Color(0xFF7F7F7F)); + expect(actualDecoration.border, isA<Border>()); + final Border border = actualDecoration.border! as Border; + expect(border.left.width, 2.5); + expect(border.left.style, BorderStyle.solid); + expect(border.left.color, const Color(0xFF101010)); + expect(actualDecoration.borderRadius, const BorderRadius.all(Radius.circular(5.0))); + expect(actualDecoration.shape, BoxShape.rectangle); + expect(actualDecoration.boxShadow![0].blurRadius, 5.0); + expect(actualDecoration.boxShadow![0].spreadRadius, 2.0); + // Scaling a shadow doesn't change the color. + expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); + + controller.value = 1.0; + + await tester.pump(); + actualBox = tester.renderObject(find.byType(DecoratedBox)); + actualDecoration = actualBox.decoration as BoxDecoration; + + expect(actualDecoration.color, const Color(0xFF000000)); + expect(actualDecoration.boxShadow, null); + }); + + testWidgets('animations work with curves test', (WidgetTester tester) async { + final Animation<Decoration> curvedDecorationAnimation = + decorationTween.animate(CurvedAnimation( + parent: controller, + curve: Curves.easeOut, + )); + + final DecoratedBoxTransition transitionUnderTest = DecoratedBoxTransition( + decoration: curvedDecorationAnimation, + position: DecorationPosition.foreground, + child: const Text( + "Doesn't matter", + textDirection: TextDirection.ltr, + ), + ); + + await tester.pumpWidget(transitionUnderTest); + + RenderDecoratedBox actualBox = tester.renderObject(find.byType(DecoratedBox)); + BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration; + + expect(actualDecoration.color, const Color(0xFFFFFFFF)); + expect(actualDecoration.boxShadow![0].blurRadius, 10.0); + expect(actualDecoration.boxShadow![0].spreadRadius, 4.0); + expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); + + controller.value = 0.5; + + await tester.pump(); + actualBox = tester.renderObject(find.byType(DecoratedBox)); + actualDecoration = actualBox.decoration as BoxDecoration; + + // Same as the test above but the values should be much closer to the + // tween's end values given the easeOut curve. + expect(actualDecoration.color, const Color(0xFF505050)); + expect(actualDecoration.border, isA<Border>()); + final Border border = actualDecoration.border! as Border; + expect(border.left.width, moreOrLessEquals(1.9, epsilon: 0.1)); + expect(border.left.style, BorderStyle.solid); + expect(border.left.color, const Color(0xFF151515)); + expect(actualDecoration.borderRadius!.resolve(TextDirection.ltr).topLeft.x, moreOrLessEquals(6.8, epsilon: 0.1)); + expect(actualDecoration.shape, BoxShape.rectangle); + expect(actualDecoration.boxShadow![0].blurRadius, moreOrLessEquals(3.1, epsilon: 0.1)); + expect(actualDecoration.boxShadow![0].spreadRadius, moreOrLessEquals(1.2, epsilon: 0.1)); + // Scaling a shadow doesn't change the color. + expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); + }); + }); + + testWidgets('AlignTransition animates', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<Alignment> alignmentTween = AlignmentTween( + begin: Alignment.centerLeft, + end: Alignment.bottomRight, + ).animate(controller); + final Widget widget = AlignTransition( + alignment: alignmentTween, + child: const Text('Ready', textDirection: TextDirection.ltr), + ); + + await tester.pumpWidget(widget); + + final RenderPositionedBox actualPositionedBox = tester.renderObject(find.byType(Align)); + + Alignment actualAlignment = actualPositionedBox.alignment as Alignment; + expect(actualAlignment, Alignment.centerLeft); + + controller.value = 0.5; + await tester.pump(); + actualAlignment = actualPositionedBox.alignment as Alignment; + expect(actualAlignment, const Alignment(0.0, 0.5)); + }); + + testWidgets('RelativePositionedTransition animates', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<Rect?> rectTween = RectTween( + begin: const Rect.fromLTWH(0, 0, 30, 40), + end: const Rect.fromLTWH(100, 200, 100, 200), + ).animate(controller); + final Widget widget = Directionality( + textDirection: TextDirection.rtl, + child: Stack( + alignment: Alignment.centerLeft, + children: <Widget>[ + RelativePositionedTransition( + size: const Size(200, 300), + rect: rectTween, + child: const Placeholder(), + ), + ], + ), + ); + + await tester.pumpWidget(widget); + + final Positioned actualPositioned = tester.widget(find.byType(Positioned)); + final RenderBox renderBox = tester.renderObject(find.byType(Placeholder)); + + Rect actualRect = Rect.fromLTRB( + actualPositioned.left!, + actualPositioned.top!, + actualPositioned.right ?? 0.0, + actualPositioned.bottom ?? 0.0, + ); + expect(actualRect, equals(const Rect.fromLTRB(0, 0, 170, 260))); + expect(renderBox.size, equals(const Size(630, 340))); + + controller.value = 0.5; + await tester.pump(); + actualRect = Rect.fromLTRB( + actualPositioned.left!, + actualPositioned.top!, + actualPositioned.right ?? 0.0, + actualPositioned.bottom ?? 0.0, + ); + expect(actualRect, equals(const Rect.fromLTWH(0, 0, 170, 260))); + expect(renderBox.size, equals(const Size(665, 420))); + }); + + testWidgets('AlignTransition keeps width and height factors', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<Alignment> alignmentTween = AlignmentTween( + begin: Alignment.centerLeft, + end: Alignment.bottomRight, + ).animate(controller); + final Widget widget = AlignTransition( + alignment: alignmentTween, + widthFactor: 0.3, + heightFactor: 0.4, + child: const Text('Ready', textDirection: TextDirection.ltr), + ); + + await tester.pumpWidget(widget); + + final Align actualAlign = tester.widget(find.byType(Align)); + + expect(actualAlign.widthFactor, 0.3); + expect(actualAlign.heightFactor, 0.4); + }); + + testWidgets('SizeTransition clamps negative size factors - vertical axis', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<double> animation = Tween<double>(begin: -1.0, end: 1.0).animate(controller); + + final Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: SizeTransition( + sizeFactor: animation, + fixedCrossAxisSizeFactor: 2.0, + child: const Text('Ready'), + ), + ); + + await tester.pumpWidget(widget); + + final RenderPositionedBox actualPositionedBox = tester.renderObject(find.byType(Align)); + expect(actualPositionedBox.heightFactor, 0.0); + expect(actualPositionedBox.widthFactor, 2.0); + + controller.value = 0.0; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 0.0); + expect(actualPositionedBox.widthFactor, 2.0); + + controller.value = 0.75; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 0.5); + expect(actualPositionedBox.widthFactor, 2.0); + + controller.value = 1.0; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 1.0); + expect(actualPositionedBox.widthFactor, 2.0); + }); + + testWidgets('SizeTransition clamps negative size factors - horizontal axis', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<double> animation = Tween<double>(begin: -1.0, end: 1.0).animate(controller); + + final Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: SizeTransition( + axis: Axis.horizontal, + sizeFactor: animation, + fixedCrossAxisSizeFactor: 1.0, + child: const Text('Ready'), + ), + ); + + await tester.pumpWidget(widget); + + final RenderPositionedBox actualPositionedBox = tester.renderObject(find.byType(Align)); + expect(actualPositionedBox.widthFactor, 0.0); + expect(actualPositionedBox.heightFactor, 1.0); + + controller.value = 0.0; + await tester.pump(); + expect(actualPositionedBox.widthFactor, 0.0); + expect(actualPositionedBox.heightFactor, 1.0); + + controller.value = 0.75; + await tester.pump(); + expect(actualPositionedBox.widthFactor, 0.5); + expect(actualPositionedBox.heightFactor, 1.0); + + controller.value = 1.0; + await tester.pump(); + expect(actualPositionedBox.widthFactor, 1.0); + expect(actualPositionedBox.heightFactor, 1.0); + }); + + testWidgets('SizeTransition with fixedCrossAxisSizeFactor should size its cross axis from its children - vertical axis', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<double> animation = Tween<double>(begin: 0, end: 1.0).animate(controller); + + const Key key = Key('key'); + + final Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + key: key, + child: SizeTransition( + sizeFactor: animation, + fixedCrossAxisSizeFactor: 1.0, + child: const SizedBox.square(dimension: 100), + ), + ), + ), + ); + + await tester.pumpWidget(widget); + + final RenderPositionedBox actualPositionedBox = tester.renderObject(find.byType(Align)); + expect(actualPositionedBox.heightFactor, 0.0); + expect(actualPositionedBox.widthFactor, 1.0); + expect(tester.getSize(find.byKey(key)), const Size(100, 0)); + + controller.value = 0.0; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 0.0); + expect(actualPositionedBox.widthFactor, 1.0); + expect(tester.getSize(find.byKey(key)), const Size(100, 0)); + + controller.value = 0.5; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 0.5); + expect(actualPositionedBox.widthFactor, 1.0); + expect(tester.getSize(find.byKey(key)), const Size(100, 50)); + + controller.value = 1.0; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 1.0); + expect(actualPositionedBox.widthFactor, 1.0); + expect(tester.getSize(find.byKey(key)), const Size.square(100)); + + controller.value = 0.5; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 0.5); + expect(actualPositionedBox.widthFactor, 1.0); + expect(tester.getSize(find.byKey(key)), const Size(100, 50)); + + controller.value = 0.0; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 0.0); + expect(actualPositionedBox.widthFactor, 1.0); + expect(tester.getSize(find.byKey(key)), const Size(100, 0)); + }); + + testWidgets('SizeTransition with fixedCrossAxisSizeFactor should size its cross axis from its children - horizontal axis', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<double> animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller); + + const Key key = Key('key'); + + final Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + key: key, + child: SizeTransition( + axis: Axis.horizontal, + sizeFactor: animation, + fixedCrossAxisSizeFactor: 1.0, + child: const SizedBox.square(dimension: 100), + ), + ), + ), + ); + + await tester.pumpWidget(widget); + + final RenderPositionedBox actualPositionedBox = tester.renderObject(find.byType(Align)); + expect(actualPositionedBox.heightFactor, 1.0); + expect(actualPositionedBox.widthFactor, 0.0); + expect(tester.getSize(find.byKey(key)), const Size(0, 100)); + + controller.value = 0.0; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 1.0); + expect(actualPositionedBox.widthFactor, 0.0); + expect(tester.getSize(find.byKey(key)), const Size(0, 100)); + + controller.value = 0.5; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 1.0); + expect(actualPositionedBox.widthFactor, 0.5); + expect(tester.getSize(find.byKey(key)), const Size(50, 100)); + + controller.value = 1.0; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 1.0); + expect(actualPositionedBox.widthFactor, 1.0); + expect(tester.getSize(find.byKey(key)), const Size.square(100)); + + controller.value = 0.5; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 1.0); + expect(actualPositionedBox.widthFactor, 0.5); + expect(tester.getSize(find.byKey(key)), const Size(50, 100)); + + controller.value = 0.0; + await tester.pump(); + expect(actualPositionedBox.heightFactor, 1.0); + expect(actualPositionedBox.widthFactor, 0.0); + expect(tester.getSize(find.byKey(key)), const Size(0, 100)); + }); + + testWidgets('MatrixTransition animates', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Widget widget = MatrixTransition( + alignment: Alignment.topRight, + onTransform: (double value) => Matrix4.translationValues(value, value, value), + animation: controller, + child: const Text( + 'Matrix', + textDirection: TextDirection.ltr, + ), + ); + + await tester.pumpWidget(widget); + Transform actualTransformedBox = tester.widget(find.byType(Transform)); + Matrix4 actualTransform = actualTransformedBox.transform; + expect(actualTransform, equals(Matrix4.rotationZ(0.0))); + + controller.value = 0.5; + await tester.pump(); + actualTransformedBox = tester.widget(find.byType(Transform)); + actualTransform = actualTransformedBox.transform; + expect(actualTransform, Matrix4.fromList(<double>[ + 1.0, 0.0, 0.0, 0.5, + 0.0, 1.0, 0.0, 0.5, + 0.0, 0.0, 1.0, 0.5, + 0.0, 0.0, 0.0, 1.0, + ])..transpose()); + + controller.value = 0.75; + await tester.pump(); + actualTransformedBox = tester.widget(find.byType(Transform)); + actualTransform = actualTransformedBox.transform; + expect(actualTransform, Matrix4.fromList(<double>[ + 1.0, 0.0, 0.0, 0.75, + 0.0, 1.0, 0.0, 0.75, + 0.0, 0.0, 1.0, 0.75, + 0.0, 0.0, 0.0, 1.0, + ])..transpose()); + }); + + testWidgets('MatrixTransition maintains chosen alignment during animation', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Widget widget = MatrixTransition( + alignment: Alignment.topRight, + onTransform: (double value) => Matrix4.identity(), + animation: controller, + child: const Text('Matrix', textDirection: TextDirection.ltr), + ); + + await tester.pumpWidget(widget); + MatrixTransition actualTransformedBox = tester.widget(find.byType(MatrixTransition)); + Alignment actualAlignment = actualTransformedBox.alignment; + expect(actualAlignment, Alignment.topRight); + + controller.value = 0.5; + await tester.pump(); + actualTransformedBox = tester.widget(find.byType(MatrixTransition)); + actualAlignment = actualTransformedBox.alignment; + expect(actualAlignment, Alignment.topRight); + }); + + testWidgets('RotationTransition animates', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Widget widget = RotationTransition( + alignment: Alignment.topRight, + turns: controller, + child: const Text( + 'Rotation', + textDirection: TextDirection.ltr, + ), + ); + + await tester.pumpWidget(widget); + Transform actualRotatedBox = tester.widget(find.byType(Transform)); + Matrix4 actualTurns = actualRotatedBox.transform; + expect(actualTurns, equals(Matrix4.rotationZ(0.0))); + + controller.value = 0.5; + await tester.pump(); + actualRotatedBox = tester.widget(find.byType(Transform)); + actualTurns = actualRotatedBox.transform; + expect(actualTurns, matrixMoreOrLessEquals(Matrix4.fromList(<double>[ + -1.0, 0.0, 0.0, 0.0, + 0.0, -1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0, + ])..transpose())); + + controller.value = 0.75; + await tester.pump(); + actualRotatedBox = tester.widget(find.byType(Transform)); + actualTurns = actualRotatedBox.transform; + expect(actualTurns, matrixMoreOrLessEquals(Matrix4.fromList(<double>[ + 0.0, 1.0, 0.0, 0.0, + -1.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0, + ])..transpose())); + }); + + testWidgets('RotationTransition maintains chosen alignment during animation', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Widget widget = RotationTransition( + alignment: Alignment.topRight, + turns: controller, + child: const Text('Rotation', textDirection: TextDirection.ltr), + ); + + await tester.pumpWidget(widget); + RotationTransition actualRotatedBox = tester.widget(find.byType(RotationTransition)); + Alignment actualAlignment = actualRotatedBox.alignment; + expect(actualAlignment, Alignment.topRight); + + controller.value = 0.5; + await tester.pump(); + actualRotatedBox = tester.widget(find.byType(RotationTransition)); + actualAlignment = actualRotatedBox.alignment; + expect(actualAlignment, Alignment.topRight); + }); + + group('FadeTransition', () { + double getOpacity(WidgetTester tester, String textValue) { + final FadeTransition opacityWidget = tester.widget<FadeTransition>( + find.ancestor( + of: find.text(textValue), + matching: find.byType(FadeTransition), + ).first, + ); + return opacityWidget.opacity.value; + } + testWidgets('animates', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<double> animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller); + final Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: FadeTransition( + opacity: animation, + child: const Text('Fade In'), + ), + ); + + await tester.pumpWidget(widget); + + expect(getOpacity(tester, 'Fade In'), 0.0); + + controller.value = 0.25; + await tester.pump(); + expect(getOpacity(tester, 'Fade In'), 0.25); + + controller.value = 0.5; + await tester.pump(); + expect(getOpacity(tester, 'Fade In'), 0.5); + + controller.value = 0.75; + await tester.pump(); + expect(getOpacity(tester, 'Fade In'), 0.75); + + controller.value = 1.0; + await tester.pump(); + expect(getOpacity(tester, 'Fade In'), 1.0); + }); + }); + + group('SliverFadeTransition', () { + double getOpacity(WidgetTester tester, String textValue) { + final SliverFadeTransition opacityWidget = tester.widget<SliverFadeTransition>( + find.ancestor( + of: find.text(textValue), + matching: find.byType(SliverFadeTransition), + ).first, + ); + return opacityWidget.opacity.value; + } + testWidgets('animates', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<double> animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller); + final Widget widget = Localizations( + locale: const Locale('en', 'us'), + delegates: const <LocalizationsDelegate<dynamic>>[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: Directionality( + textDirection: TextDirection.ltr, + child: MediaQuery( + data: const MediaQueryData(), + child: CustomScrollView( + slivers: <Widget>[ + SliverFadeTransition( + opacity: animation, + sliver: const SliverToBoxAdapter( + child: Text('Fade In'), + ), + ), + ], + ), + ), + ), + ); + + await tester.pumpWidget(widget); + + expect(getOpacity(tester, 'Fade In'), 0.0); + + controller.value = 0.25; + await tester.pump(); + expect(getOpacity(tester, 'Fade In'), 0.25); + + controller.value = 0.5; + await tester.pump(); + expect(getOpacity(tester, 'Fade In'), 0.5); + + controller.value = 0.75; + await tester.pump(); + expect(getOpacity(tester, 'Fade In'), 0.75); + + controller.value = 1.0; + await tester.pump(); + expect(getOpacity(tester, 'Fade In'), 1.0); + }); + }); + + group('MatrixTransition', () { + testWidgets('uses ImageFilter when provided with FilterQuality argument', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<double> animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller); + final Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: MatrixTransition( + animation: animation, + onTransform: (double value) => Matrix4.identity(), + filterQuality: FilterQuality.none, + child: const Text('Matrix Transition'), + ), + ); + + await tester.pumpWidget(widget); + + // Validate that expensive layer is not left in tree before animation has started. + expect(tester.layers, isNot(contains(isA<ImageFilterLayer>()))); + + controller.value = 0.25; + await tester.pump(); + + expect( + tester.layers, + contains(isA<ImageFilterLayer>().having( + (ImageFilterLayer layer) => layer.imageFilter.toString(), + 'image filter', + startsWith('ImageFilter.matrix('), + )), + ); + + controller.value = 0.5; + await tester.pump(); + + expect( + tester.layers, + contains(isA<ImageFilterLayer>().having( + (ImageFilterLayer layer) => layer.imageFilter.toString(), + 'image filter', + startsWith('ImageFilter.matrix('), + )), + ); + + controller.value = 0.75; + await tester.pump(); + + expect( + tester.layers, + contains(isA<ImageFilterLayer>().having( + (ImageFilterLayer layer) => layer.imageFilter.toString(), + 'image filter', + startsWith('ImageFilter.matrix('), + )), + ); + + controller.value = 1; + await tester.pump(); + + // Validate that expensive layer is not left in tree after animation has finished. + expect(tester.layers, isNot(contains(isA<ImageFilterLayer>()))); + }); + }); + + group('ScaleTransition', () { + testWidgets('uses ImageFilter when provided with FilterQuality argument', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<double> animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller); + final Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: ScaleTransition( + scale: animation, + filterQuality: FilterQuality.none, + child: const Text('Scale Transition'), + ), + ); + + await tester.pumpWidget(widget); + + // Validate that expensive layer is not left in tree before animation has started. + expect(tester.layers, isNot(contains(isA<ImageFilterLayer>()))); + + controller.value = 0.25; + await tester.pump(); + + expect(tester.layers, contains(isA<ImageFilterLayer>().having( + (ImageFilterLayer layer) => layer.imageFilter.toString(), + 'image filter', + startsWith('ImageFilter.matrix('), + ))); + + controller.value = 0.5; + await tester.pump(); + + expect(tester.layers, contains(isA<ImageFilterLayer>().having( + (ImageFilterLayer layer) => layer.imageFilter.toString(), + 'image filter', + startsWith('ImageFilter.matrix('), + ))); + + controller.value = 0.75; + await tester.pump(); + + expect(tester.layers, contains(isA<ImageFilterLayer>().having( + (ImageFilterLayer layer) => layer.imageFilter.toString(), + 'image filter', + startsWith('ImageFilter.matrix('), + ))); + + controller.value = 1; + await tester.pump(); + + // Validate that expensive layer is not left in tree after animation has finished. + expect(tester.layers, isNot(contains(isA<ImageFilterLayer>()))); + }); + }); + + group('RotationTransition', () { + testWidgets('uses ImageFilter when provided with FilterQuality argument', (WidgetTester tester) async { + final AnimationController controller = AnimationController(vsync: const TestVSync()); + addTearDown(controller.dispose); + final Animation<double> animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller); + final Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: RotationTransition( + turns: animation, + filterQuality: FilterQuality.none, + child: const Text('Scale Transition'), + ), + ); + + await tester.pumpWidget(widget); + + // Validate that expensive layer is not left in tree before animation has started. + expect(tester.layers, isNot(contains(isA<ImageFilterLayer>()))); + + controller.value = 0.25; + await tester.pump(); + + expect(tester.layers, contains(isA<ImageFilterLayer>().having( + (ImageFilterLayer layer) => layer.imageFilter.toString(), + 'image filter', + startsWith('ImageFilter.matrix('), + ))); + + controller.value = 0.5; + await tester.pump(); + + expect(tester.layers, contains(isA<ImageFilterLayer>().having( + (ImageFilterLayer layer) => layer.imageFilter.toString(), + 'image filter', + startsWith('ImageFilter.matrix('), + ))); + + controller.value = 0.75; + await tester.pump(); + + expect(tester.layers, contains(isA<ImageFilterLayer>().having( + (ImageFilterLayer layer) => layer.imageFilter.toString(), + 'image filter', + startsWith('ImageFilter.matrix('), + ))); + + controller.value = 1; + await tester.pump(); + + // Validate that expensive layer is not left in tree after animation has finished. + expect(tester.layers, isNot(contains(isA<ImageFilterLayer>()))); + }); + }); + + group('Builders', () { + testWidgets('AnimatedBuilder rebuilds when changed', (WidgetTester tester) async { + final GlobalKey<RedrawCounterState> redrawKey = GlobalKey<RedrawCounterState>(); + final ChangeNotifier notifier = ChangeNotifier(); + addTearDown(notifier.dispose); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: AnimatedBuilder( + animation: notifier, + builder: (BuildContext context, Widget? child) { + return RedrawCounter(key: redrawKey, child: child); + }, + ), + ), + ); + + expect(redrawKey.currentState!.redraws, equals(1)); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(1)); + notifier.notifyListeners(); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(2)); + + // Pump a few more times to make sure that we don't rebuild unnecessarily. + await tester.pump(); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(2)); + }); + + testWidgets("AnimatedBuilder doesn't rebuild the child", (WidgetTester tester) async { + final GlobalKey<RedrawCounterState> redrawKey = GlobalKey<RedrawCounterState>(); + final GlobalKey<RedrawCounterState> redrawKeyChild = GlobalKey<RedrawCounterState>(); + final ChangeNotifier notifier = ChangeNotifier(); + addTearDown(notifier.dispose); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: AnimatedBuilder( + animation: notifier, + builder: (BuildContext context, Widget? child) { + return RedrawCounter(key: redrawKey, child: child); + }, + child: RedrawCounter(key: redrawKeyChild), + ), + ), + ); + + expect(redrawKey.currentState!.redraws, equals(1)); + expect(redrawKeyChild.currentState!.redraws, equals(1)); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(1)); + expect(redrawKeyChild.currentState!.redraws, equals(1)); + notifier.notifyListeners(); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(2)); + expect(redrawKeyChild.currentState!.redraws, equals(1)); + + // Pump a few more times to make sure that we don't rebuild unnecessarily. + await tester.pump(); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(2)); + expect(redrawKeyChild.currentState!.redraws, equals(1)); + }); + + testWidgets('ListenableBuilder rebuilds when changed', (WidgetTester tester) async { + final GlobalKey<RedrawCounterState> redrawKey = GlobalKey<RedrawCounterState>(); + final ChangeNotifier notifier = ChangeNotifier(); + addTearDown(notifier.dispose); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: ListenableBuilder( + listenable: notifier, + builder: (BuildContext context, Widget? child) { + return RedrawCounter(key: redrawKey, child: child); + }, + ), + ), + ); + + expect(redrawKey.currentState!.redraws, equals(1)); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(1)); + notifier.notifyListeners(); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(2)); + + // Pump a few more times to make sure that we don't rebuild unnecessarily. + await tester.pump(); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(2)); + }); + + testWidgets("ListenableBuilder doesn't rebuild the child", (WidgetTester tester) async { + final GlobalKey<RedrawCounterState> redrawKey = GlobalKey<RedrawCounterState>(); + final GlobalKey<RedrawCounterState> redrawKeyChild = GlobalKey<RedrawCounterState>(); + final ChangeNotifier notifier = ChangeNotifier(); + addTearDown(notifier.dispose); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: ListenableBuilder( + listenable: notifier, + builder: (BuildContext context, Widget? child) { + return RedrawCounter(key: redrawKey, child: child); + }, + child: RedrawCounter(key: redrawKeyChild), + ), + ), + ); + + expect(redrawKey.currentState!.redraws, equals(1)); + expect(redrawKeyChild.currentState!.redraws, equals(1)); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(1)); + expect(redrawKeyChild.currentState!.redraws, equals(1)); + notifier.notifyListeners(); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(2)); + expect(redrawKeyChild.currentState!.redraws, equals(1)); + + // Pump a few more times to make sure that we don't rebuild unnecessarily. + await tester.pump(); + await tester.pump(); + expect(redrawKey.currentState!.redraws, equals(2)); + expect(redrawKeyChild.currentState!.redraws, equals(1)); + }); + }); +} + +class RedrawCounter extends StatefulWidget { + const RedrawCounter({ super.key, this.child }); + + final Widget? child; + + @override + State<RedrawCounter> createState() => RedrawCounterState(); +} + +class RedrawCounterState extends State<RedrawCounter> { + int redraws = 0; + + @override + Widget build(BuildContext context) { + redraws += 1; + return SizedBox(child: widget.child); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tree_shape_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tree_shape_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..7c9576d7ee94621b5aee239b68e9f3de5c6eb911 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tree_shape_test.dart @@ -0,0 +1,1152 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'multi_view_testing.dart'; + +void main() { + testWidgets('Providing a RenderObjectWidget directly to the RootWidget fails', (WidgetTester tester) async { + // No render tree exists to attach the RenderObjectWidget to. + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: const ColoredBox(color: Colors.red), + ); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + startsWith('The render object for ColoredBox cannot find ancestor render object to attach to.'), + )); + }); + + testWidgets('Moving a RenderObjectWidget to the RootWidget via GlobalKey fails', (WidgetTester tester) async { + final Widget globalKeyedWidget = ColoredBox( + key: GlobalKey(), + color: Colors.red, + ); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: View( + view: tester.view, + child: globalKeyedWidget, + ), + ); + expect(tester.takeException(), isNull); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: globalKeyedWidget, + ); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + contains('cannot find ancestor render object to attach to.'), + )); + }); + + testWidgets('A View cannot be a child of a render object widget', (WidgetTester tester) async { + await tester.pumpWidget(Center( + child: View( + view: FakeView(tester.view), + child: Container(), + ), + )); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + contains('cannot maintain an independent render tree at its current location.'), + )); + }); + + testWidgets('The child of a ViewAnchor cannot be a View', (WidgetTester tester) async { + await tester.pumpWidget( + ViewAnchor( + child: View( + view: FakeView(tester.view), + child: Container(), + ), + ), + ); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + contains('cannot maintain an independent render tree at its current location.'), + )); + }); + + testWidgets('A View can not be moved via GlobalKey to be a child of a RenderObject', (WidgetTester tester) async { + final Widget globalKeyedView = View( + key: GlobalKey(), + view: FakeView(tester.view), + child: const ColoredBox(color: Colors.red), + ); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: globalKeyedView, + ); + expect(tester.takeException(), isNull); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: View( + view: tester.view, + child: globalKeyedView, + ), + ); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + contains('cannot maintain an independent render tree at its current location.'), + )); + }); + + testWidgets('The view property of a ViewAnchor cannot be a render object widget', (WidgetTester tester) async { + await tester.pumpWidget( + ViewAnchor( + view: const ColoredBox(color: Colors.red), + child: Container(), + ), + ); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + startsWith('The render object for ColoredBox cannot find ancestor render object to attach to.'), + )); + }); + + testWidgets('A RenderObject cannot be moved into the view property of a ViewAnchor via GlobalKey', (WidgetTester tester) async { + final Widget globalKeyedWidget = ColoredBox( + key: GlobalKey(), + color: Colors.red, + ); + + await tester.pumpWidget( + ViewAnchor( + child: globalKeyedWidget, + ), + ); + expect(tester.takeException(), isNull); + + await tester.pumpWidget( + ViewAnchor( + view: globalKeyedWidget, + child: const SizedBox(), + ), + ); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + contains('cannot find ancestor render object to attach to.'), + )); + }); + + testWidgets('ViewAnchor cannot be used at the top of the widget tree (outside of View)', (WidgetTester tester) async { + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: const ViewAnchor( + child: SizedBox(), + ), + ); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + startsWith('The render object for SizedBox cannot find ancestor render object to attach to.'), + )); + }); + + testWidgets('ViewAnchor cannot be moved to the top of the widget tree (outside of View) via GlobalKey', (WidgetTester tester) async { + final Widget globalKeyedViewAnchor = ViewAnchor( + key: GlobalKey(), + child: const SizedBox(), + ); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: View( + view: tester.view, + child: globalKeyedViewAnchor, + ), + ); + expect(tester.takeException(), isNull); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: globalKeyedViewAnchor, + ); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + contains('cannot find ancestor render object to attach to.'), + )); + }); + + testWidgets('View can be used at the top of the widget tree', (WidgetTester tester) async { + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: View( + view: tester.view, + child: Container(), + ), + ); + + expect(tester.takeException(), isNull); + }); + + testWidgets('View can be moved to the top of the widget tree view GlobalKey', (WidgetTester tester) async { + final Widget globalKeyView = View( + view: FakeView(tester.view), + child: const ColoredBox(color: Colors.red), + ); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: View( + view: tester.view, + child: ViewAnchor( + view: globalKeyView, // This one has trouble when deactivating + child: const SizedBox(), + ), + ), + ); + expect(tester.takeException(), isNull); + expect(find.byType(SizedBox), findsOneWidget); + expect(find.byType(ColoredBox), findsOneWidget); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: globalKeyView, + ); + expect(tester.takeException(), isNull); + expect(find.byType(SizedBox), findsNothing); + expect(find.byType(ColoredBox), findsOneWidget); + }); + + testWidgets('ViewCollection can be used at the top of the widget tree', (WidgetTester tester) async { + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + view: tester.view, + child: Container(), + ), + ], + ), + ); + + expect(tester.takeException(), isNull); + }); + + testWidgets('ViewCollection cannot be used inside a View', (WidgetTester tester) async { + await tester.pumpWidget( + ViewCollection( + views: <Widget>[ + View( + view: FakeView(tester.view), + child: Container(), + ), + ], + ), + ); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + startsWith('The Element for ViewCollection cannot be inserted into slot "null" of its ancestor.'), + )); + }); + + testWidgets('ViewCollection can be used as ViewAnchor.view', (WidgetTester tester) async { + await tester.pumpWidget( + ViewAnchor( + view: ViewCollection( + views: <Widget>[ + View( + view: FakeView(tester.view), + child: Container(), + ) + ], + ), + child: Container(), + ), + ); + + expect(tester.takeException(), isNull); + }); + + testWidgets('ViewCollection cannot have render object widgets as children', (WidgetTester tester) async { + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: const ViewCollection( + views: <Widget>[ + ColoredBox(color: Colors.red), + ], + ), + ); + + expect(tester.takeException(), isFlutterError.having( + (FlutterError error) => error.message, + 'message', + startsWith('The render object for ColoredBox cannot find ancestor render object to attach to.'), + )); + }); + + testWidgets('Views can be moved in and out of ViewCollections via GlobalKey', (WidgetTester tester) async { + final Widget greenView = View( + key: GlobalKey(debugLabel: 'green'), + view: tester.view, + child: const ColoredBox(color: Colors.green), + ); + final Widget redView = View( + key: GlobalKey(debugLabel: 'red'), + view: FakeView(tester.view), + child: const ColoredBox(color: Colors.red), + ); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + greenView, + ViewCollection( + views: <Widget>[ + redView, + ], + ), + ] + ), + ); + expect(tester.takeException(), isNull); + expect(find.byType(ColoredBox), findsNWidgets(2)); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + redView, + ViewCollection( + views: <Widget>[ + greenView, + ], + ), + ] + ), + ); + expect(tester.takeException(), isNull); + expect(find.byType(ColoredBox), findsNWidgets(2)); + }); + + testWidgets('Can move stuff between views via global key: viewA -> viewB', (WidgetTester tester) async { + final FlutterView greenView = tester.view; + final FlutterView redView = FakeView(tester.view); + final Widget globalKeyChild = SizedBox( + key: GlobalKey(), + ); + + Map<int, RenderObject> collectLeafRenderObjects() { + final Map<int, RenderObject> result = <int, RenderObject>{}; + for (final RenderView renderView in RendererBinding.instance.renderViews) { + void visit(RenderObject object) { + result[renderView.flutterView.viewId] = object; + object.visitChildren(visit); + } + visit(renderView); + } + return result; + } + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + view: greenView, + child: ColoredBox( + color: Colors.green, + child: globalKeyChild, + ), + ), + View( + view: redView, + child: const ColoredBox( + color: Colors.red, + ), + ), + ], + ), + ); + expect( + find.descendant( + of: findsColoredBox(Colors.green), + matching: find.byType(SizedBox), + ), + findsOneWidget, + ); + expect( + find.descendant( + of: findsColoredBox(Colors.red), + matching: find.byType(SizedBox), + ), + findsNothing, + ); + final RenderObject boxWithGlobalKey = tester.renderObject(find.byKey(globalKeyChild.key!)); + + Map<int, RenderObject> leafRenderObject = collectLeafRenderObjects(); + expect(leafRenderObject[greenView.viewId], isA<RenderConstrainedBox>()); + expect(leafRenderObject[redView.viewId], isNot(isA<RenderConstrainedBox>())); + + // Move the child. + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + view: greenView, + child: const ColoredBox( + color: Colors.green, + ), + ), + View( + view: redView, + child: ColoredBox( + color: Colors.red, + child: globalKeyChild, + ), + ), + ], + ), + ); + + expect( + find.descendant( + of: findsColoredBox(Colors.green), + matching: find.byType(SizedBox), + ), + findsNothing, + ); + expect( + find.descendant( + of: findsColoredBox(Colors.red), + matching: find.byType(SizedBox), + ), + findsOneWidget, + ); + expect( + tester.renderObject(find.byKey(globalKeyChild.key!)), + equals(boxWithGlobalKey), + ); + + leafRenderObject = collectLeafRenderObjects(); + expect(leafRenderObject[greenView.viewId], isNot(isA<RenderConstrainedBox>())); + expect(leafRenderObject[redView.viewId], isA<RenderConstrainedBox>()); + }); + + testWidgets('Can move stuff between views via global key: viewB -> viewA', (WidgetTester tester) async { + final FlutterView greenView = tester.view; + final FlutterView redView = FakeView(tester.view); + final Widget globalKeyChild = SizedBox( + key: GlobalKey(), + ); + + Map<int, RenderObject> collectLeafRenderObjects() { + final Map<int, RenderObject> result = <int, RenderObject>{}; + for (final RenderView renderView in RendererBinding.instance.renderViews) { + void visit(RenderObject object) { + result[renderView.flutterView.viewId] = object; + object.visitChildren(visit); + } + visit(renderView); + } + return result; + } + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + view: greenView, + child: const ColoredBox( + color: Colors.green, + ), + ), + View( + view: redView, + child: ColoredBox( + color: Colors.red, + child: globalKeyChild, + ), + ), + ], + ), + ); + expect( + find.descendant( + of: findsColoredBox(Colors.red), + matching: find.byType(SizedBox), + ), + findsOneWidget, + ); + expect( + find.descendant( + of: findsColoredBox(Colors.green), + matching: find.byType(SizedBox), + ), + findsNothing, + ); + final RenderObject boxWithGlobalKey = tester.renderObject(find.byKey(globalKeyChild.key!)); + + Map<int, RenderObject> leafRenderObject = collectLeafRenderObjects(); + expect(leafRenderObject[redView.viewId], isA<RenderConstrainedBox>()); + expect(leafRenderObject[greenView.viewId], isNot(isA<RenderConstrainedBox>())); + + // Move the child. + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + view: greenView, + child: ColoredBox( + color: Colors.green, + child: globalKeyChild, + ), + ), + View( + view: redView, + child: const ColoredBox( + color: Colors.red, + ), + ), + ], + ), + ); + + expect( + find.descendant( + of: findsColoredBox(Colors.red), + matching: find.byType(SizedBox), + ), + findsNothing, + ); + expect( + find.descendant( + of: findsColoredBox(Colors.green), + matching: find.byType(SizedBox), + ), + findsOneWidget, + ); + expect( + tester.renderObject(find.byKey(globalKeyChild.key!)), + equals(boxWithGlobalKey), + ); + + leafRenderObject = collectLeafRenderObjects(); + expect(leafRenderObject[redView.viewId], isNot(isA<RenderConstrainedBox>())); + expect(leafRenderObject[greenView.viewId], isA<RenderConstrainedBox>()); + }); + + testWidgets('Can move stuff out of a view that is going away, viewA -> ViewB', (WidgetTester tester) async { + final FlutterView greenView = tester.view; + final Key greenKey = UniqueKey(); + final FlutterView redView = FakeView(tester.view); + final Key redKey = UniqueKey(); + final Widget globalKeyChild = SizedBox( + key: GlobalKey(), + ); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + key: greenKey, + view: greenView, + child: const ColoredBox( + color: Colors.green, + ), + ), + View( + key: redKey, + view: redView, + child: ColoredBox( + color: Colors.red, + child: globalKeyChild, + ), + ), + ], + ), + ); + expect( + find.descendant( + of: findsColoredBox(Colors.red), + matching: find.byType(SizedBox), + ), + findsOneWidget, + ); + expect( + find.descendant( + of: findsColoredBox(Colors.green), + matching: find.byType(SizedBox), + ), + findsNothing, + ); + final RenderObject boxWithGlobalKey = tester.renderObject(find.byKey(globalKeyChild.key!)); + + // Move the child and remove its view. + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + key: greenKey, + view: greenView, + child: ColoredBox( + color: Colors.green, + child: globalKeyChild, + ), + ), + ], + ), + ); + + expect( + findsColoredBox(Colors.red), + findsNothing, + ); + expect( + find.descendant( + of: findsColoredBox(Colors.green), + matching: find.byType(SizedBox), + ), + findsOneWidget, + ); + expect( + tester.renderObject(find.byKey(globalKeyChild.key!)), + equals(boxWithGlobalKey), + ); + }); + + testWidgets('Can move stuff out of a view that is going away, viewB -> ViewA', (WidgetTester tester) async { + final FlutterView greenView = tester.view; + final Key greenKey = UniqueKey(); + final FlutterView redView = FakeView(tester.view); + final Key redKey = UniqueKey(); + final Widget globalKeyChild = SizedBox( + key: GlobalKey(), + ); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + key: greenKey, + view: greenView, + child: ColoredBox( + color: Colors.green, + child: globalKeyChild, + ), + ), + View( + key: redKey, + view: redView, + child: const ColoredBox( + color: Colors.red, + ), + ), + ], + ), + ); + expect( + find.descendant( + of: findsColoredBox(Colors.green), + matching: find.byType(SizedBox), + ), + findsOneWidget, + ); + expect( + find.descendant( + of: findsColoredBox(Colors.red), + matching: find.byType(SizedBox), + ), + findsNothing, + ); + final RenderObject boxWithGlobalKey = tester.renderObject(find.byKey(globalKeyChild.key!)); + + // Move the child and remove its view. + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + key: redKey, + view: redView, + child: ColoredBox( + color: Colors.red, + child: globalKeyChild, + ), + ), + ], + ), + ); + + expect( + findsColoredBox(Colors.green), + findsNothing, + ); + expect( + find.descendant( + of: findsColoredBox(Colors.red), + matching: find.byType(SizedBox), + ), + findsOneWidget, + ); + expect( + tester.renderObject(find.byKey(globalKeyChild.key!)), + equals(boxWithGlobalKey), + ); + }); + + testWidgets('Can move stuff out of a view that is moving itself, stuff ends up before view', (WidgetTester tester) async { + final Key key1 = UniqueKey(); + final Key key2 = UniqueKey(); + final Key key3 = UniqueKey(); + final Key key4 = UniqueKey(); + + final GlobalKey viewKey = GlobalKey(); + final GlobalKey childKey = GlobalKey(); + + await tester.pumpWidget(Column( + children: <Widget>[ + SizedBox(key: key1), + ViewAnchor( + key: key2, + view: View( + key: viewKey, + view: FakeView(tester.view), + child: SizedBox( + child: ColoredBox( + key: childKey, + color: Colors.green, + ), + ), + ), + child: const SizedBox(), + ), + ViewAnchor( + key: key3, + child: const SizedBox(), + ), + SizedBox(key: key4), + ], + )); + + await tester.pumpWidget(Column( + children: <Widget>[ + SizedBox( + key: key1, + child: ColoredBox( + key: childKey, + color: Colors.green, + ), + ), + ViewAnchor( + key: key2, + child: const SizedBox(), + ), + ViewAnchor( + key: key3, + view: View( + key: viewKey, + view: FakeView(tester.view), + child: const SizedBox(), + ), + child: const SizedBox(), + ), + SizedBox(key: key4), + ], + )); + + await tester.pumpWidget(Column( + children: <Widget>[ + SizedBox(key: key1), + ViewAnchor( + key: key2, + view: View( + key: viewKey, + view: FakeView(tester.view), + child: SizedBox( + child: ColoredBox( + key: childKey, + color: Colors.green, + ), + ), + ), + child: const SizedBox(), + ), + ViewAnchor( + key: key3, + child: const SizedBox(), + ), + SizedBox(key: key4), + ], + )); + }); + + testWidgets('Can move stuff out of a view that is moving itself, stuff ends up after view', (WidgetTester tester) async { + final Key key1 = UniqueKey(); + final Key key2 = UniqueKey(); + final Key key3 = UniqueKey(); + final Key key4 = UniqueKey(); + + final GlobalKey viewKey = GlobalKey(); + final GlobalKey childKey = GlobalKey(); + + await tester.pumpWidget(Column( + children: <Widget>[ + SizedBox(key: key1), + ViewAnchor( + key: key2, + view: View( + key: viewKey, + view: FakeView(tester.view), + child: SizedBox( + child: ColoredBox( + key: childKey, + color: Colors.green, + ), + ), + ), + child: const SizedBox(), + ), + ViewAnchor( + key: key3, + child: const SizedBox(), + ), + SizedBox(key: key4), + ], + )); + + await tester.pumpWidget(Column( + children: <Widget>[ + SizedBox( + key: key1, + ), + ViewAnchor( + key: key2, + child: const SizedBox(), + ), + ViewAnchor( + key: key3, + view: View( + key: viewKey, + view: FakeView(tester.view), + child: const SizedBox(), + ), + child: const SizedBox(), + ), + SizedBox( + key: key4, + child: ColoredBox( + key: childKey, + color: Colors.green, + ), + ), + ], + )); + + await tester.pumpWidget(Column( + children: <Widget>[ + SizedBox(key: key1), + ViewAnchor( + key: key2, + view: View( + key: viewKey, + view: FakeView(tester.view), + child: SizedBox( + child: ColoredBox( + key: childKey, + color: Colors.green, + ), + ), + ), + child: const SizedBox(), + ), + ViewAnchor( + key: key3, + child: const SizedBox(), + ), + SizedBox(key: key4), + ], + )); + }); + + testWidgets('Can globalkey move down the tree from a view that is going away', (WidgetTester tester) async { + final FlutterView anchorView = FakeView(tester.view); + final Widget globalKeyChild = SizedBox( + key: GlobalKey(), + ); + + await tester.pumpWidget( + ColoredBox( + color: Colors.green, + child: ViewAnchor( + view: View( + view: anchorView, + child: ColoredBox( + color: Colors.yellow, + child: globalKeyChild, + ), + ), + child: const ColoredBox(color: Colors.red), + ), + ), + ); + + expect(findsColoredBox(Colors.green), findsOneWidget); + expect(findsColoredBox(Colors.yellow), findsOneWidget); + expect( + find.descendant( + of: findsColoredBox(Colors.yellow), + matching: find.byType(SizedBox), + ), + findsOneWidget, + ); + expect(findsColoredBox(Colors.red), findsOneWidget); + expect( + find.descendant( + of: findsColoredBox(Colors.red), + matching: find.byType(SizedBox), + ), + findsNothing, + ); + expect(find.byType(SizedBox), findsOneWidget); + final RenderObject boxWithGlobalKey = tester.renderObject(find.byKey(globalKeyChild.key!)); + + await tester.pumpWidget( + ColoredBox( + color: Colors.green, + child: ViewAnchor( + child: ColoredBox( + color: Colors.red, + child: globalKeyChild, + ), + ), + ), + ); + expect(findsColoredBox(Colors.green), findsOneWidget); + expect(findsColoredBox(Colors.yellow), findsNothing); + expect( + find.descendant( + of: findsColoredBox(Colors.yellow), + matching: find.byType(SizedBox), + ), + findsNothing, + ); + expect(findsColoredBox(Colors.red), findsOneWidget); + expect( + find.descendant( + of: findsColoredBox(Colors.red), + matching: find.byType(SizedBox), + ), + findsOneWidget, + ); + expect(find.byType(SizedBox), findsOneWidget); + expect( + tester.renderObject(find.byKey(globalKeyChild.key!)), + boxWithGlobalKey, + ); + }); + + testWidgets('RenderObjects are disposed when a view goes away from a ViewAnchor', (WidgetTester tester) async { + final FlutterView anchorView = FakeView(tester.view); + + await tester.pumpWidget( + ColoredBox( + color: Colors.green, + child: ViewAnchor( + view: View( + view: anchorView, + child: const ColoredBox(color: Colors.yellow), + ), + child: const ColoredBox(color: Colors.red), + ), + ), + ); + + final RenderObject box = tester.renderObject(findsColoredBox(Colors.yellow)); + + await tester.pumpWidget( + const ColoredBox( + color: Colors.green, + child: ViewAnchor( + child: ColoredBox(color: Colors.red), + ), + ), + ); + + expect(box.debugDisposed, isTrue); + }); + + testWidgets('RenderObjects are disposed when a view goes away from a ViewCollection', (WidgetTester tester) async { + final FlutterView redView = tester.view; + final FlutterView greenView = FakeView(tester.view); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + view: redView, + child: const ColoredBox(color: Colors.red), + ), + View( + view: greenView, + child: const ColoredBox(color: Colors.green), + ), + ], + ), + ); + + expect(findsColoredBox(Colors.green), findsOneWidget); + expect(findsColoredBox(Colors.red), findsOneWidget); + final RenderObject box = tester.renderObject(findsColoredBox(Colors.green)); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + view: redView, + child: const ColoredBox(color: Colors.red), + ), + ], + ), + ); + + expect(findsColoredBox(Colors.green), findsNothing); + expect(findsColoredBox(Colors.red), findsOneWidget); + expect(box.debugDisposed, isTrue); + }); + + testWidgets('View can be wrapped and unwrapped', (WidgetTester tester) async { + final Widget view = View( + view: tester.view, + child: const SizedBox(), + ); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: view, + ); + + final RenderObject renderView = tester.renderObject(find.byType(View)); + final RenderObject renderSizedBox = tester.renderObject(find.byType(SizedBox)); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[view], + ), + ); + + expect(tester.renderObject(find.byType(View)), same(renderView)); + expect(tester.renderObject(find.byType(SizedBox)), same(renderSizedBox)); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: view, + ); + + expect(tester.renderObject(find.byType(View)), same(renderView)); + expect(tester.renderObject(find.byType(SizedBox)), same(renderSizedBox)); + }); + + testWidgets('ViewAnchor with View can be wrapped and unwrapped', (WidgetTester tester) async { + final Widget viewAnchor = ViewAnchor( + view: View( + view: FakeView(tester.view), + child: const SizedBox(), + ), + child: const ColoredBox(color: Colors.green), + ); + + await tester.pumpWidget(viewAnchor); + + final List<RenderObject> renderViews = tester.renderObjectList(find.byType(View)).toList(); + final RenderObject renderSizedBox = tester.renderObject(find.byType(SizedBox)); + + await tester.pumpWidget(ColoredBox(color: Colors.yellow, child: viewAnchor)); + + expect(tester.renderObjectList(find.byType(View)), renderViews); + expect(tester.renderObject(find.byType(SizedBox)), same(renderSizedBox)); + + await tester.pumpWidget(viewAnchor); + + expect(tester.renderObjectList(find.byType(View)), renderViews); + expect(tester.renderObject(find.byType(SizedBox)), same(renderSizedBox)); + }); + + testWidgets('Moving a View keeps its semantics tree stable', (WidgetTester tester) async { + final Widget view = View( + // No explicit key, we rely on the implicit key of the underlying RawView. + view: tester.view, + child: Semantics( + textDirection: TextDirection.ltr, + label: 'Hello', + child: const SizedBox(), + ) + ); + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: view, + ); + + final RenderObject renderSemantics = tester.renderObject(find.bySemanticsLabel('Hello')); + final SemanticsNode semantics = tester.getSemantics(find.bySemanticsLabel('Hello')); + expect(semantics.id, 1); + expect(renderSemantics.debugSemantics, same(semantics)); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + view, + ], + ), + ); + + final RenderObject renderSemanticsAfterMove = tester.renderObject(find.bySemanticsLabel('Hello')); + final SemanticsNode semanticsAfterMove = tester.getSemantics(find.bySemanticsLabel('Hello')); + expect(renderSemanticsAfterMove, same(renderSemantics)); + expect(semanticsAfterMove.id, 1); + expect(semanticsAfterMove, same(semantics)); + }); +} + +Finder findsColoredBox(Color color) { + return find.byWidgetPredicate((Widget widget) => widget is ColoredBox && widget.color == color); +} + +Future<void> pumpWidgetWithoutViewWrapper({required WidgetTester tester, required Widget widget}) { + tester.binding.attachRootWidget(widget); + tester.binding.scheduleFrame(); + return tester.binding.pump(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tween_animation_builder_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tween_animation_builder_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..afad96ecfe1d539054024f22a5f961ae0233567e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/tween_animation_builder_test.dart @@ -0,0 +1,407 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Animates forward when built', (WidgetTester tester) async { + final List<int> values = <int>[]; + int endCount = 0; + await tester.pumpWidget( + TweenAnimationBuilder<int>( + duration: const Duration(seconds: 1), + tween: IntTween(begin: 10, end: 110), + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + onEnd: () { + endCount++; + }, + ), + ); + expect(endCount, 0); + expect(values, <int>[10]); + + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[10, 60]); + + await tester.pump(const Duration(milliseconds: 501)); + expect(endCount, 1); + expect(values, <int>[10, 60, 110]); + + await tester.pump(const Duration(milliseconds: 500)); + expect(endCount, 1); + expect(values, <int>[10, 60, 110]); + }); + + testWidgets('No initial animation when begin=null', (WidgetTester tester) async { + final List<int> values = <int>[]; + int endCount = 0; + await tester.pumpWidget( + TweenAnimationBuilder<int>( + duration: const Duration(seconds: 1), + tween: IntTween(end: 100), + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + onEnd: () { + endCount++; + }, + ), + ); + expect(endCount, 0); + expect(values, <int>[100]); + await tester.pump(const Duration(seconds: 2)); + expect(endCount, 0); + expect(values, <int>[100]); + }); + + + testWidgets('No initial animation when begin=end', (WidgetTester tester) async { + final List<int> values = <int>[]; + int endCount = 0; + await tester.pumpWidget( + TweenAnimationBuilder<int>( + duration: const Duration(seconds: 1), + tween: IntTween(begin: 100, end: 100), + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + onEnd: () { + endCount++; + }, + ), + ); + expect(endCount, 0); + expect(values, <int>[100]); + await tester.pump(const Duration(seconds: 2)); + expect(endCount, 0); + expect(values, <int>[100]); + }); + + testWidgets('Replace tween animates new tween', (WidgetTester tester) async { + final List<int> values = <int>[]; + Widget buildWidget({required IntTween tween}) { + return TweenAnimationBuilder<int>( + duration: const Duration(seconds: 1), + tween: tween, + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + ); + } + + await tester.pumpWidget(buildWidget(tween: IntTween(begin: 0, end: 100))); + expect(values, <int>[0]); + await tester.pump(const Duration(seconds: 2)); // finish first animation. + expect(values, <int>[0, 100]); + + await tester.pumpWidget(buildWidget(tween: IntTween(begin: 100, end: 200))); + expect(values, <int>[0, 100, 100]); + + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[0, 100, 100, 150]); + + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[0, 100, 100, 150, 200]); + }); + + testWidgets('Curve is respected', (WidgetTester tester) async { + final List<int> values = <int>[]; + Widget buildWidget({required IntTween tween, required Curve curve}) { + return TweenAnimationBuilder<int>( + duration: const Duration(seconds: 1), + tween: tween, + curve: curve, + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + ); + } + + await tester.pumpWidget(buildWidget(tween: IntTween(begin: 0, end: 100), curve: Curves.easeInExpo)); + expect(values, <int>[0]); + await tester.pump(const Duration(milliseconds: 500)); + expect(values.last, lessThan(50)); + expect(values.last, greaterThan(0)); + + await tester.pump(const Duration(seconds: 2)); // finish animation. + + values.clear(); + // Update curve (and tween to re-trigger animation). + await tester.pumpWidget(buildWidget(tween: IntTween(begin: 100, end: 200), curve: Curves.linear)); + expect(values, <int>[100]); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[100, 150]); + }); + + testWidgets('Duration is respected', (WidgetTester tester) async { + final List<int> values = <int>[]; + Widget buildWidget({required IntTween tween, required Duration duration}) { + return TweenAnimationBuilder<int>( + tween: tween, + duration: duration, + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + ); + } + + await tester.pumpWidget(buildWidget(tween: IntTween(begin: 0, end: 100), duration: const Duration(seconds: 1))); + expect(values, <int>[0]); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[0, 50]); + + await tester.pump(const Duration(seconds: 2)); // finish animation. + + values.clear(); + // Update duration (and tween to re-trigger animation). + await tester.pumpWidget(buildWidget(tween: IntTween(begin: 100, end: 200), duration: const Duration(seconds: 2))); + expect(values, <int>[100]); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[100, 125]); + }); + + testWidgets('Child is integrated into tree', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: TweenAnimationBuilder<int>( + tween: IntTween(begin: 0, end: 100), + duration: const Duration(seconds: 1), + builder: (BuildContext context, int i, Widget? child) { + return child!; + }, + child: const Text('Hello World'), + ), + ), + ); + + expect(find.text('Hello World'), findsOneWidget); + }); + + group('Change tween gapless while', () { + testWidgets('running forward', (WidgetTester tester) async { + final List<int> values = <int>[]; + Widget buildWidget({required IntTween tween}) { + return TweenAnimationBuilder<int>( + tween: tween, + duration: const Duration(seconds: 1), + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + ); + } + + await tester.pumpWidget(buildWidget( + tween: IntTween(begin: 0, end: 100), + )); + expect(values, <int>[0]); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[0, 50]); + + // Change tween + await tester.pumpWidget(buildWidget( + tween: IntTween(begin: 200, end: 300), + )); + expect(values, <int>[0, 50, 50]); // gapless: animation continues where it left off. + + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[0, 50, 50, 175]); // 175 = halfway between 50 and new target 300. + + // Run animation to end + await tester.pump(const Duration(seconds: 2)); + expect(values, <int>[0, 50, 50, 175, 300]); + values.clear(); + }); + + testWidgets('running forward and then reverse with same tween instance', (WidgetTester tester) async { + final List<int> values = <int>[]; + Widget buildWidget({required IntTween tween}) { + return TweenAnimationBuilder<int>( + tween: tween, + duration: const Duration(seconds: 1), + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + ); + } + + final IntTween tween1 = IntTween(begin: 0, end: 100); + final IntTween tween2 = IntTween(begin: 200, end: 300); + + await tester.pumpWidget(buildWidget( + tween: tween1, + )); + await tester.pump(const Duration(milliseconds: 500)); + await tester.pumpWidget(buildWidget( + tween: tween2, + )); + await tester.pump(const Duration(milliseconds: 500)); + await tester.pump(const Duration(seconds: 2)); + expect(values, <int>[0, 50, 50, 175, 300]); + values.clear(); + }); + }); + + testWidgets('Changing tween while gapless tween change is in progress', (WidgetTester tester) async { + final List<int> values = <int>[]; + Widget buildWidget({required IntTween tween}) { + return TweenAnimationBuilder<int>( + tween: tween, + duration: const Duration(seconds: 1), + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + ); + } + + final IntTween tween1 = IntTween(begin: 0, end: 100); + final IntTween tween2 = IntTween(begin: 200, end: 300); + final IntTween tween3 = IntTween(begin: 400, end: 501); + + await tester.pumpWidget(buildWidget( + tween: tween1, + )); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[0, 50]); + values.clear(); + + // Change tween + await tester.pumpWidget(buildWidget( + tween: tween2, + )); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[50, 175]); + values.clear(); + + await tester.pumpWidget(buildWidget( + tween: tween3, + )); + await tester.pump(const Duration(milliseconds: 500)); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[175, 338, 501]); + }); + + testWidgets('Changing curve while no animation is running does not trigger animation', (WidgetTester tester) async { + final List<int> values = <int>[]; + Widget buildWidget({required Curve curve}) { + return TweenAnimationBuilder<int>( + tween: IntTween(begin: 0, end: 100), + curve: curve, + duration: const Duration(seconds: 1), + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + ); + } + + await tester.pumpWidget(buildWidget( + curve: Curves.linear, + )); + await tester.pump(const Duration(seconds: 2)); + expect(values, <int>[0, 100]); + values.clear(); + + await tester.pumpWidget(buildWidget( + curve: Curves.easeInExpo, + )); + expect(values, <int>[100]); + await tester.pump(const Duration(seconds: 2)); + expect(values, <int>[100]); + }); + + testWidgets('Setting same tween and direction does not trigger animation', (WidgetTester tester) async { + final List<int> values = <int>[]; + Widget buildWidget({required IntTween tween}) { + return TweenAnimationBuilder<int>( + tween: tween, + duration: const Duration(seconds: 1), + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + ); + } + + await tester.pumpWidget(buildWidget( + tween: IntTween(begin: 0, end: 100), + )); + await tester.pump(const Duration(milliseconds: 500)); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[0, 50, 100]); + values.clear(); + + await tester.pumpWidget(buildWidget( + tween: IntTween(begin: 0, end: 100), + )); + await tester.pump(const Duration(milliseconds: 500)); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, everyElement(100)); + }); + + testWidgets('Setting same tween and direction while gapless animation is in progress works', (WidgetTester tester) async { + final List<int> values = <int>[]; + Widget buildWidget({required IntTween tween}) { + return TweenAnimationBuilder<int>( + tween: tween, + duration: const Duration(seconds: 1), + builder: (BuildContext context, int i, Widget? child) { + values.add(i); + return const Placeholder(); + }, + ); + } + + await tester.pumpWidget(buildWidget( + tween: IntTween(begin: 0, end: 100), + )); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[0, 50]); + await tester.pumpWidget(buildWidget( + tween: IntTween(begin: 200, end: 300), + )); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[0, 50, 50, 175]); + + await tester.pumpWidget(buildWidget( + tween: IntTween(begin: 200, end: 300), + )); + expect(values, <int>[0, 50, 50, 175, 175]); + await tester.pump(const Duration(milliseconds: 500)); + expect(values, <int>[0, 50, 50, 175, 175, 300]); + + values.clear(); + await tester.pump(const Duration(seconds: 2)); + expect(values, everyElement(300)); + }); + + testWidgets('Works with nullable tweens', (WidgetTester tester) async { + final List<Size?> values = <Size?>[]; + await tester.pumpWidget( + TweenAnimationBuilder<Size?>( + duration: const Duration(seconds: 1), + tween: SizeTween(end: const Size(10,10)), + builder: (BuildContext context, Size? s, Widget? child) { + values.add(s); + return const Placeholder(); + }, + ), + ); + expect(values, <Size>[const Size(10,10)]); + await tester.pump(const Duration(seconds: 2)); + expect(values, <Size>[const Size(10,10)]); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/two_dimensional_scroll_view_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/two_dimensional_scroll_view_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..1101b033b35170fb5eba767496d251152ca0c935 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/two_dimensional_scroll_view_test.dart @@ -0,0 +1,580 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/src/gestures/monodrag.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'two_dimensional_utils.dart'; + +Widget? _testChildBuilder(BuildContext context, ChildVicinity vicinity) { + return SizedBox( + height: 200, + width: 200, + child: Center(child: Text('C${vicinity.xIndex}:R${vicinity.yIndex}')), + ); +} + +void main() { + group('TwoDimensionalScrollView',() { + testWidgets('asserts the axis directions do not conflict with one another', (WidgetTester tester) async { + final List<Object> exceptions = <Object>[]; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + FlutterError.onError = (FlutterErrorDetails details) { + exceptions.add(details.exception); + }; + // Horizontal wrong + late final TwoDimensionalChildBuilderDelegate delegate1; + addTearDown(() => delegate1.dispose()); + await tester.pumpWidget(MaterialApp( + home: SimpleBuilderTableView( + delegate: delegate1 = TwoDimensionalChildBuilderDelegate(builder: (_, __) => null), + horizontalDetails: const ScrollableDetails.vertical(), + // Horizontal has default const ScrollableDetails.horizontal() + ), + )); + + // Vertical wrong + late final TwoDimensionalChildBuilderDelegate delegate2; + addTearDown(() => delegate2.dispose()); + await tester.pumpWidget(MaterialApp( + home: SimpleBuilderTableView( + delegate: delegate2 = TwoDimensionalChildBuilderDelegate(builder: (_, __) => null), + verticalDetails: const ScrollableDetails.horizontal(), + // Horizontal has default const ScrollableDetails.horizontal() + ), + )); + + // Both wrong + late final TwoDimensionalChildBuilderDelegate delegate3; + addTearDown(() => delegate3.dispose()); + await tester.pumpWidget(MaterialApp( + home: SimpleBuilderTableView( + delegate: delegate3 = TwoDimensionalChildBuilderDelegate(builder: (_, __) => null), + verticalDetails: const ScrollableDetails.horizontal(), + horizontalDetails: const ScrollableDetails.vertical(), + ), + )); + + FlutterError.onError = oldHandler; + expect(exceptions.length, 3); + for (final Object exception in exceptions) { + expect(exception, isAssertionError); + expect((exception as AssertionError).message, contains('are not Axis')); + } + }, variant: TargetPlatformVariant.all()); + + testWidgets('ScrollableDetails.controller can set initial scroll positions, modify within bounds', (WidgetTester tester) async { + final ScrollController verticalController = ScrollController(initialScrollOffset: 100); + addTearDown(verticalController.dispose); + final ScrollController horizontalController = ScrollController(initialScrollOffset: 50); + addTearDown(horizontalController.dispose); + late final TwoDimensionalChildBuilderDelegate delegate; + addTearDown(() => delegate.dispose()); + + await tester.pumpWidget(MaterialApp( + home: SimpleBuilderTableView( + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), + delegate: delegate = TwoDimensionalChildBuilderDelegate( + builder: _testChildBuilder, + maxXIndex: 99, + maxYIndex: 99, + ), + ), + )); + await tester.pumpAndSettle(); + + expect(verticalController.position.pixels, 100); + expect(verticalController.position.maxScrollExtent, 19400); + expect(horizontalController.position.pixels, 50); + expect(horizontalController.position.maxScrollExtent, 19200); + + verticalController.jumpTo(verticalController.position.maxScrollExtent); + horizontalController.jumpTo(horizontalController.position.maxScrollExtent); + await tester.pump(); + + expect(verticalController.position.pixels, 19400); + expect(horizontalController.position.pixels, 19200); + + // Out of bounds + verticalController.jumpTo(verticalController.position.maxScrollExtent + 100); + horizontalController.jumpTo(horizontalController.position.maxScrollExtent + 100); + // Account for varying scroll physics for different platforms (overscroll) + await tester.pumpAndSettle(); + + expect(verticalController.position.pixels, 19400); + expect(horizontalController.position.pixels, 19200); + }, variant: TargetPlatformVariant.all()); + + testWidgets('Properly assigns the PrimaryScrollController to the main axis on the correct platform', (WidgetTester tester) async { + late ScrollController controller; + Widget buildForPrimaryScrollController({ + bool? explicitPrimary, + Axis mainAxis = Axis.vertical, + bool addControllerConflict = false, + }) { + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + final ScrollController horizontalController = ScrollController(); + addTearDown(horizontalController.dispose); + late final TwoDimensionalChildBuilderDelegate delegate; + addTearDown(() => delegate.dispose()); + + return MaterialApp( + home: PrimaryScrollController( + controller: controller, + child: SimpleBuilderTableView( + mainAxis: mainAxis, + primary: explicitPrimary, + verticalDetails: ScrollableDetails.vertical( + controller: addControllerConflict && mainAxis == Axis.vertical + ? verticalController + : null + ), + horizontalDetails: ScrollableDetails.horizontal( + controller: addControllerConflict && mainAxis == Axis.horizontal + ? horizontalController + : null + ), + delegate: delegate = TwoDimensionalChildBuilderDelegate( + builder: _testChildBuilder, + maxXIndex: 99, + maxYIndex: 99, + ), + ), + ), + ); + } + + // Horizontal default - horizontal never automatically adopts PSC + controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(buildForPrimaryScrollController( + mainAxis: Axis.horizontal, + )); + await tester.pumpAndSettle(); + + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(controller.hasClients, isFalse); + } + + // Horizontal explicitly true + controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(buildForPrimaryScrollController( + mainAxis: Axis.horizontal, + explicitPrimary: true, + )); + await tester.pumpAndSettle(); + + switch (defaultTargetPlatform) { + // Primary explicitly true is always adopted. + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(controller.hasClients, isTrue); + expect(controller.position.axis, Axis.horizontal); + } + + // Horizontal explicitly false + controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(buildForPrimaryScrollController( + mainAxis: Axis.horizontal, + explicitPrimary: false, + )); + await tester.pumpAndSettle(); + + switch (defaultTargetPlatform) { + // Primary explicitly false is never adopted. + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(controller.hasClients, isFalse); + } + + // Vertical default + controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(buildForPrimaryScrollController()); + await tester.pumpAndSettle(); + + switch (defaultTargetPlatform) { + // Mobile platforms inherit the PSC without explicitly setting + // primary + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + expect(controller.hasClients, isTrue); + expect(controller.position.axis, Axis.vertical); + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(controller.hasClients, isFalse); + } + + // Vertical explicitly true + controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(buildForPrimaryScrollController( + explicitPrimary: true, + )); + await tester.pumpAndSettle(); + + switch (defaultTargetPlatform) { + // Primary explicitly true is always adopted. + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(controller.hasClients, isTrue); + expect(controller.position.axis, Axis.vertical); + } + + // Vertical explicitly false + controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(buildForPrimaryScrollController( + explicitPrimary: false, + )); + await tester.pumpAndSettle(); + + switch (defaultTargetPlatform) { + // Primary explicitly false is never adopted. + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(controller.hasClients, isFalse); + } + + // Assertions + final List<Object> exceptions = <Object>[]; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + FlutterError.onError = (FlutterErrorDetails details) { + exceptions.add(details.exception); + }; + // Vertical asserts ScrollableDetails.controller has not been provided if + // primary is explicitly set + controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(buildForPrimaryScrollController( + explicitPrimary: true, + addControllerConflict: true, + )); + expect(exceptions.length, 1); + expect(exceptions[0], isAssertionError); + expect( + (exceptions[0] as AssertionError).message, + contains('TwoDimensionalScrollView.primary was explicitly set to true'), + ); + exceptions.clear(); + + // Horizontal asserts ScrollableDetails.controller has not been provided + // if primary is explicitly set true + controller = ScrollController(); + addTearDown(controller.dispose); + await tester.pumpWidget(buildForPrimaryScrollController( + mainAxis: Axis.horizontal, + explicitPrimary: true, + addControllerConflict: true, + )); + expect(exceptions.length, 1); + expect(exceptions[0], isAssertionError); + expect( + (exceptions[0] as AssertionError).message, + contains('TwoDimensionalScrollView.primary was explicitly set to true'), + ); + FlutterError.onError = oldHandler; + }, variant: TargetPlatformVariant.all()); + + testWidgets('TwoDimensionalScrollable receives the correct details from TwoDimensionalScrollView', (WidgetTester tester) async { + late BuildContext capturedContext; + // Default + late final TwoDimensionalChildBuilderDelegate delegate1; + addTearDown(() => delegate1.dispose()); + await tester.pumpWidget(MaterialApp( + home: SimpleBuilderTableView( + delegate: delegate1 = TwoDimensionalChildBuilderDelegate( + builder: (BuildContext context, ChildVicinity vicinity) { + capturedContext = context; + return Text(vicinity.toString()); + }, + ), + ), + )); + await tester.pumpAndSettle(); + TwoDimensionalScrollableState scrollable = TwoDimensionalScrollable.of( + capturedContext, + ); + expect(scrollable.widget.verticalDetails.direction, AxisDirection.down); + expect(scrollable.widget.horizontalDetails.direction, AxisDirection.right); + expect(scrollable.widget.diagonalDragBehavior, DiagonalDragBehavior.none); + expect(scrollable.widget.dragStartBehavior, DragStartBehavior.start); + + // Customized + late final TwoDimensionalChildBuilderDelegate delegate2; + addTearDown(() => delegate2.dispose()); + await tester.pumpWidget(MaterialApp( + home: SimpleBuilderTableView( + verticalDetails: const ScrollableDetails.vertical(reverse: true), + horizontalDetails: const ScrollableDetails.horizontal(reverse: true), + diagonalDragBehavior: DiagonalDragBehavior.weightedContinuous, + dragStartBehavior: DragStartBehavior.down, + delegate: delegate2 = TwoDimensionalChildBuilderDelegate( + builder: _testChildBuilder, + ), + ), + )); + await tester.pumpAndSettle(); + scrollable = TwoDimensionalScrollable.of(capturedContext); + expect(scrollable.widget.verticalDetails.direction, AxisDirection.up); + expect(scrollable.widget.horizontalDetails.direction, AxisDirection.left); + expect(scrollable.widget.diagonalDragBehavior, DiagonalDragBehavior.weightedContinuous); + expect(scrollable.widget.dragStartBehavior, DragStartBehavior.down); + }, variant: TargetPlatformVariant.all()); + + testWidgets('Interrupt fling with tap stops scrolling', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/133529 + final List<String> log = <String>[]; + final ScrollController verticalController = ScrollController(); + final ScrollController horizontalController = ScrollController(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: SimpleBuilderTableView( + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), + diagonalDragBehavior: DiagonalDragBehavior.free, + delegate: TwoDimensionalChildBuilderDelegate( + maxXIndex: 100, + maxYIndex: 100, + builder: (BuildContext context, ChildVicinity vicinity) { + return GestureDetector( + onTapUp: (TapUpDetails details) { + log.add('Tapped: $vicinity'); + }, + child: Text('$vicinity'), + ); + }, + ), + ), + ), + ); + + await tester.pumpAndSettle(); + expect(log, equals(<String>[])); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, 0.0); + expect(horizontalController.position.activity!.velocity, 0.0); + + // Tap once + await tester.tap(find.byType(TwoDimensionalScrollable)); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, equals(<String>['Tapped: (xIndex: 0, yIndex: 0)'])); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, 0.0); + expect(horizontalController.position.activity!.velocity, 0.0); + + // Fling the scrollview to get it scrolling, verify that no tap occurs. + await tester.fling(find.byType(TwoDimensionalScrollable), const Offset(0.0, -200.0), 2000.0); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, equals(<String>['Tapped: (xIndex: 0, yIndex: 0)'])); + expect(verticalController.position.pixels, greaterThan(170.0)); + double unchangedOffset = verticalController.position.pixels; + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity!.isScrolling, isTrue); + expect(horizontalController.position.activity!.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, greaterThan(1500)); + expect(horizontalController.position.activity!.velocity, 0.0); + + // Tap to stop the scroll movement, this should stop the fling but not tap anything + await tester.tap(find.byType(TwoDimensionalScrollable)); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, equals(<String>['Tapped: (xIndex: 0, yIndex: 0)'])); + expect(verticalController.position.pixels, unchangedOffset); + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, 0.0); + expect(horizontalController.position.activity!.velocity, 0.0); + + // Another tap. + await tester.tap(find.byType(TwoDimensionalScrollable)); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, <String>['Tapped: (xIndex: 0, yIndex: 0)', 'Tapped: (xIndex: 0, yIndex: 0)']); + expect(verticalController.position.pixels, unchangedOffset); + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, 0.0); + expect(horizontalController.position.activity!.velocity, 0.0); + + log.clear(); + verticalController.jumpTo(0.0); + await tester.pump(); + // Fling off in the other direction now ---------------------------------- + expect(log, equals(<String>[])); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, 0.0); + expect(horizontalController.position.activity!.velocity, 0.0); + + // Tap once + await tester.tap(find.byType(TwoDimensionalScrollable)); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, equals(<String>['Tapped: (xIndex: 0, yIndex: 0)'])); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, 0.0); + expect(horizontalController.position.activity!.velocity, 0.0); + + // Fling the scrollview to get it scrolling, verify that no tap occurs. + await tester.fling(find.byType(TwoDimensionalScrollable), const Offset(-200.0, 0.0), 2000.0); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, equals(<String>['Tapped: (xIndex: 0, yIndex: 0)'])); + expect(horizontalController.position.pixels, greaterThan(170.0)); + unchangedOffset = horizontalController.position.pixels; + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.activity!.isScrolling, isTrue); + expect(verticalController.position.activity!.isScrolling, isFalse); + expect(horizontalController.position.activity!.velocity, greaterThan(1500)); + expect(verticalController.position.activity!.velocity, 0.0); + + // Tap to stop the scroll movement, this should stop the fling but not tap anything + await tester.tap(find.byType(TwoDimensionalScrollable)); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, equals(<String>['Tapped: (xIndex: 0, yIndex: 0)'])); + expect(horizontalController.position.pixels, unchangedOffset); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity!.velocity, 0.0); + expect(verticalController.position.activity!.velocity, 0.0); + + // Another tap. + await tester.tap(find.byType(TwoDimensionalScrollable)); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, <String>['Tapped: (xIndex: 0, yIndex: 0)', 'Tapped: (xIndex: 0, yIndex: 0)']); + expect(horizontalController.position.pixels, unchangedOffset); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity!.velocity, 0.0); + expect(verticalController.position.activity!.velocity, 0.0); + }, variant: TargetPlatformVariant.all()); + + testWidgets('Fling, wait to stop and tap', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/133529 + final List<String> log = <String>[]; + final ScrollController verticalController = ScrollController(); + final ScrollController horizontalController = ScrollController(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: SimpleBuilderTableView( + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), + diagonalDragBehavior: DiagonalDragBehavior.free, + delegate: TwoDimensionalChildBuilderDelegate( + maxXIndex: 100, + maxYIndex: 100, + builder: (BuildContext context, ChildVicinity vicinity) { + return GestureDetector( + onTapUp: (TapUpDetails details) { + log.add('Tapped: $vicinity'); + }, + child: Text('$vicinity'), + ); + }, + ), + ), + ), + ); + + await tester.pumpAndSettle(); + expect(log, equals(<String>[])); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, 0.0); + expect(horizontalController.position.activity!.velocity, 0.0); + + // Tap once + await tester.tap(find.byType(TwoDimensionalScrollable)); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, equals(<String>['Tapped: (xIndex: 0, yIndex: 0)'])); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, 0.0); + expect(horizontalController.position.activity!.velocity, 0.0); + + // Fling the scrollview to get it scrolling, verify that no tap occurs. + await tester.fling(find.byType(TwoDimensionalScrollable), const Offset(0.0, -200.0), 2000.0); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, equals(<String>['Tapped: (xIndex: 0, yIndex: 0)'])); + expect(verticalController.position.pixels, greaterThan(170.0)); + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity!.isScrolling, isTrue); + expect(horizontalController.position.activity!.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, greaterThan(1500)); + expect(horizontalController.position.activity!.velocity, 0.0); + + // Wait for the fling to finish. + await tester.pumpAndSettle(); + expect(log, equals(<String>['Tapped: (xIndex: 0, yIndex: 0)'])); + expect(verticalController.position.pixels, greaterThan(800.0)); + final double unchangedOffset = verticalController.position.pixels; + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity!.velocity, 0.0); + expect(horizontalController.position.activity!.velocity, 0.0); + + // Another tap. + await tester.tap(find.byType(TwoDimensionalScrollable)); + await tester.pump(const Duration(milliseconds: 50)); + expect(log, <String>['Tapped: (xIndex: 0, yIndex: 0)', 'Tapped: (xIndex: 0, yIndex: 4)']); + expect(horizontalController.position.pixels, 0.0); + expect(verticalController.position.pixels, unchangedOffset); + expect(horizontalController.position.activity?.isScrolling, isFalse); + expect(verticalController.position.activity?.isScrolling, isFalse); + expect(horizontalController.position.activity!.velocity, 0.0); + expect(verticalController.position.activity!.velocity, 0.0); + }); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/two_dimensional_utils.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/two_dimensional_utils.dart new file mode 100644 index 0000000000000000000000000000000000000000..a518f52170a13efcee72f1d5886e3bfefa7dc0d8 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/two_dimensional_utils.dart @@ -0,0 +1,512 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:math' as math; + +import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/gestures.dart' show DragStartBehavior; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart' show ViewportOffset; + + +// BUILDER DELEGATE --- + +final TwoDimensionalChildBuilderDelegate builderDelegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + return Container( + key: ValueKey<ChildVicinity>(vicinity), + color: vicinity.xIndex.isEven && vicinity.yIndex.isEven + ? Colors.amber[100] + : (vicinity.xIndex.isOdd && vicinity.yIndex.isOdd + ? Colors.blueAccent[100] + : null), + height: 200, + width: 200, + child: Center(child: Text('R${vicinity.xIndex}:C${vicinity.yIndex}')), + ); + } +); + +// Creates a simple 2D table of 200x200 squares with a builder delegate. +Widget simpleBuilderTest({ + Axis mainAxis = Axis.vertical, + bool? primary, + ScrollableDetails? verticalDetails, + ScrollableDetails? horizontalDetails, + TwoDimensionalChildBuilderDelegate? delegate, + double? cacheExtent, + DiagonalDragBehavior? diagonalDrag, + Clip? clipBehavior, + String? restorationID, + bool useCacheExtent = false, + bool applyDimensions = true, + bool forgetToLayoutChild = false, + bool setLayoutOffset = true, +}) { + return MaterialApp( + theme: ThemeData(useMaterial3: false), + restorationScopeId: restorationID, + home: Scaffold( + body: SimpleBuilderTableView( + mainAxis: mainAxis, + verticalDetails: verticalDetails ?? const ScrollableDetails.vertical(), + horizontalDetails: horizontalDetails ?? const ScrollableDetails.horizontal(), + cacheExtent: cacheExtent, + useCacheExtent: useCacheExtent, + diagonalDragBehavior: diagonalDrag ?? DiagonalDragBehavior.none, + clipBehavior: clipBehavior ?? Clip.hardEdge, + delegate: delegate ?? builderDelegate, + applyDimensions: applyDimensions, + forgetToLayoutChild: forgetToLayoutChild, + setLayoutOffset: setLayoutOffset, + ), + ), + ); +} + +class SimpleBuilderTableView extends TwoDimensionalScrollView { + const SimpleBuilderTableView({ + super.key, + super.primary, + super.mainAxis = Axis.vertical, + super.verticalDetails = const ScrollableDetails.vertical(), + super.horizontalDetails = const ScrollableDetails.horizontal(), + required TwoDimensionalChildBuilderDelegate delegate, + super.cacheExtent, + super.diagonalDragBehavior = DiagonalDragBehavior.none, + super.dragStartBehavior = DragStartBehavior.start, + super.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, + super.clipBehavior = Clip.hardEdge, + this.useCacheExtent = false, + this.applyDimensions = true, + this.forgetToLayoutChild = false, + this.setLayoutOffset = true, + }) : super(delegate: delegate); + + // Piped through for testing in RenderTwoDimensionalViewport + final bool useCacheExtent; + final bool applyDimensions; + final bool forgetToLayoutChild; + final bool setLayoutOffset; + + @override + Widget buildViewport(BuildContext context, ViewportOffset verticalOffset, ViewportOffset horizontalOffset) { + return SimpleBuilderTableViewport( + horizontalOffset: horizontalOffset, + horizontalAxisDirection: horizontalDetails.direction, + verticalOffset: verticalOffset, + verticalAxisDirection: verticalDetails.direction, + mainAxis: mainAxis, + delegate: delegate as TwoDimensionalChildBuilderDelegate, + cacheExtent: cacheExtent, + clipBehavior: clipBehavior, + useCacheExtent: useCacheExtent, + applyDimensions: applyDimensions, + forgetToLayoutChild: forgetToLayoutChild, + setLayoutOffset: setLayoutOffset, + ); + } +} + +class SimpleBuilderTableViewport extends TwoDimensionalViewport { + const SimpleBuilderTableViewport({ + super.key, + required super.verticalOffset, + required super.verticalAxisDirection, + required super.horizontalOffset, + required super.horizontalAxisDirection, + required TwoDimensionalChildBuilderDelegate delegate, + required super.mainAxis, + super.cacheExtent, + super.clipBehavior = Clip.hardEdge, + this.useCacheExtent = false, + this.applyDimensions = true, + this.forgetToLayoutChild = false, + this.setLayoutOffset = true, + }) : super(delegate: delegate); + + // Piped through for testing in RenderTwoDimensionalViewport + final bool useCacheExtent; + final bool applyDimensions; + final bool forgetToLayoutChild; + final bool setLayoutOffset; + + @override + RenderTwoDimensionalViewport createRenderObject(BuildContext context) { + return RenderSimpleBuilderTableViewport( + horizontalOffset: horizontalOffset, + horizontalAxisDirection: horizontalAxisDirection, + verticalOffset: verticalOffset, + verticalAxisDirection: verticalAxisDirection, + mainAxis: mainAxis, + delegate: delegate as TwoDimensionalChildBuilderDelegate, + childManager: context as TwoDimensionalChildManager, + cacheExtent: cacheExtent, + clipBehavior: clipBehavior, + useCacheExtent: useCacheExtent, + applyDimensions: applyDimensions, + forgetToLayoutChild: forgetToLayoutChild, + setLayoutOffset: setLayoutOffset, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderSimpleBuilderTableViewport renderObject) { + renderObject + ..horizontalOffset = horizontalOffset + ..horizontalAxisDirection = horizontalAxisDirection + ..verticalOffset = verticalOffset + ..verticalAxisDirection = verticalAxisDirection + ..mainAxis = mainAxis + ..delegate = delegate + ..cacheExtent = cacheExtent + ..clipBehavior = clipBehavior; + } +} + +class RenderSimpleBuilderTableViewport extends RenderTwoDimensionalViewport { + RenderSimpleBuilderTableViewport({ + required super.horizontalOffset, + required super.horizontalAxisDirection, + required super.verticalOffset, + required super.verticalAxisDirection, + required TwoDimensionalChildBuilderDelegate delegate, + required super.mainAxis, + required super.childManager, + super.cacheExtent, + super.clipBehavior = Clip.hardEdge, + this.applyDimensions = true, + this.setLayoutOffset = true, + this.useCacheExtent = false, + this.forgetToLayoutChild = false, + }) : super(delegate: delegate); + + // These are to test conditions to validate subclass implementations after + // layoutChildSequence + final bool applyDimensions; + final bool setLayoutOffset; + final bool useCacheExtent; + final bool forgetToLayoutChild; + + RenderBox? testGetChildFor(ChildVicinity vicinity) => getChildFor(vicinity); + + @override + TestExtendedParentData parentDataOf(RenderBox child) { + return child.parentData! as TestExtendedParentData; + } + + @override + void setupParentData(RenderBox child) { + if (child.parentData is! TestExtendedParentData) { + child.parentData = TestExtendedParentData(); + } + } + + @override + void layoutChildSequence() { + // Really simple table implementation for testing. + // Every child is 200x200 square + final double horizontalPixels = horizontalOffset.pixels; + final double verticalPixels = verticalOffset.pixels; + final double viewportWidth = viewportDimension.width + (useCacheExtent ? cacheExtent : 0.0); + final double viewportHeight = viewportDimension.height + (useCacheExtent ? cacheExtent : 0.0); + final TwoDimensionalChildBuilderDelegate builderDelegate = delegate as TwoDimensionalChildBuilderDelegate; + + final int maxRowIndex; + final int maxColumnIndex; + maxRowIndex = builderDelegate.maxYIndex ?? 5; + maxColumnIndex = builderDelegate.maxXIndex ?? 5; + + final int leadingColumn = math.max((horizontalPixels / 200).floor(), 0); + final int leadingRow = math.max((verticalPixels / 200).floor(), 0); + final int trailingColumn = math.min( + ((horizontalPixels + viewportWidth) / 200).ceil(), + maxColumnIndex, + ); + final int trailingRow = math.min( + ((verticalPixels + viewportHeight) / 200).ceil(), + maxRowIndex, + ); + + double xLayoutOffset = (leadingColumn * 200) - horizontalOffset.pixels; + for (int column = leadingColumn; column <= trailingColumn; column++) { + double yLayoutOffset = (leadingRow * 200) - verticalOffset.pixels; + for (int row = leadingRow; row <= trailingRow; row++) { + final ChildVicinity vicinity = ChildVicinity(xIndex: column, yIndex: row); + final RenderBox child = buildOrObtainChildFor(vicinity)!; + if (!forgetToLayoutChild) { + child.layout(constraints.tighten(width: 200.0, height: 200.0)); + } + + if (setLayoutOffset) { + parentDataOf(child).layoutOffset = Offset(xLayoutOffset, yLayoutOffset); + } + yLayoutOffset += 200; + } + xLayoutOffset += 200; + } + if (applyDimensions) { + final double verticalExtent = 200 * (maxRowIndex + 1); + verticalOffset.applyContentDimensions( + 0.0, + clampDouble(verticalExtent - viewportDimension.height, 0.0, double.infinity), + ); + final double horizontalExtent = 200 * (maxColumnIndex + 1); + horizontalOffset.applyContentDimensions( + 0.0, + clampDouble(horizontalExtent - viewportDimension.width, 0.0, double.infinity), + ); + } + } +} + +// LIST DELEGATE --- +final List<List<Widget>> children = List<List<Widget>>.generate( + 100, + (int xIndex) { + return List<Widget>.generate( + 100, + (int yIndex) { + return Container( + color: xIndex.isEven && yIndex.isEven + ? Colors.amber[100] + : (xIndex.isOdd && yIndex.isOdd + ? Colors.blueAccent[100] + : null), + height: 200, + width: 200, + child: Center(child: Text('R$xIndex:C$yIndex')), + ); + }, + ); + }, +); + +// Builds a simple 2D table of 200x200 squares with a list delegate. +Widget simpleListTest({ + Axis mainAxis = Axis.vertical, + bool? primary, + ScrollableDetails? verticalDetails, + ScrollableDetails? horizontalDetails, + TwoDimensionalChildListDelegate? delegate, + double? cacheExtent, + DiagonalDragBehavior? diagonalDrag, + Clip? clipBehavior, +}) { + return MaterialApp( + theme: ThemeData(useMaterial3: true), + home: Scaffold( + body: SimpleListTableView( + mainAxis: mainAxis, + verticalDetails: verticalDetails ?? const ScrollableDetails.vertical(), + horizontalDetails: horizontalDetails ?? const ScrollableDetails.horizontal(), + cacheExtent: cacheExtent, + diagonalDragBehavior: diagonalDrag ?? DiagonalDragBehavior.none, + clipBehavior: clipBehavior ?? Clip.hardEdge, + delegate: delegate ?? TwoDimensionalChildListDelegate(children: children), + ), + ), + ); +} + +class SimpleListTableView extends TwoDimensionalScrollView { + const SimpleListTableView({ + super.key, + super.primary, + super.mainAxis = Axis.vertical, + super.verticalDetails = const ScrollableDetails.vertical(), + super.horizontalDetails = const ScrollableDetails.horizontal(), + required TwoDimensionalChildListDelegate delegate, + super.cacheExtent, + super.diagonalDragBehavior = DiagonalDragBehavior.none, + super.dragStartBehavior = DragStartBehavior.start, + super.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, + super.clipBehavior = Clip.hardEdge, + }) : super(delegate: delegate); + + @override + Widget buildViewport(BuildContext context, ViewportOffset verticalOffset, ViewportOffset horizontalOffset) { + return SimpleListTableViewport( + horizontalOffset: horizontalOffset, + horizontalAxisDirection: horizontalDetails.direction, + verticalOffset: verticalOffset, + verticalAxisDirection: verticalDetails.direction, + mainAxis: mainAxis, + delegate: delegate as TwoDimensionalChildListDelegate, + cacheExtent: cacheExtent, + clipBehavior: clipBehavior, + ); + } +} + +class SimpleListTableViewport extends TwoDimensionalViewport { + const SimpleListTableViewport({ + super.key, + required super.verticalOffset, + required super.verticalAxisDirection, + required super.horizontalOffset, + required super.horizontalAxisDirection, + required TwoDimensionalChildListDelegate delegate, + required super.mainAxis, + super.cacheExtent, + super.clipBehavior = Clip.hardEdge, + }) : super(delegate: delegate); + + @override + RenderTwoDimensionalViewport createRenderObject(BuildContext context) { + return RenderSimpleListTableViewport( + horizontalOffset: horizontalOffset, + horizontalAxisDirection: horizontalAxisDirection, + verticalOffset: verticalOffset, + verticalAxisDirection: verticalAxisDirection, + mainAxis: mainAxis, + delegate: delegate as TwoDimensionalChildListDelegate, + childManager: context as TwoDimensionalChildManager, + cacheExtent: cacheExtent, + clipBehavior: clipBehavior, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderSimpleListTableViewport renderObject) { + renderObject + ..horizontalOffset = horizontalOffset + ..horizontalAxisDirection = horizontalAxisDirection + ..verticalOffset = verticalOffset + ..verticalAxisDirection = verticalAxisDirection + ..mainAxis = mainAxis + ..delegate = delegate + ..cacheExtent = cacheExtent + ..clipBehavior = clipBehavior; + } +} + +class RenderSimpleListTableViewport extends RenderTwoDimensionalViewport { + RenderSimpleListTableViewport({ + required super.horizontalOffset, + required super.horizontalAxisDirection, + required super.verticalOffset, + required super.verticalAxisDirection, + required TwoDimensionalChildListDelegate delegate, + required super.mainAxis, + required super.childManager, + super.cacheExtent, + super.clipBehavior = Clip.hardEdge, + }) : super(delegate: delegate); + + @override + void layoutChildSequence() { + // Really simple table implementation for testing. + // Every child is 200x200 square + final double horizontalPixels = horizontalOffset.pixels; + final double verticalPixels = verticalOffset.pixels; + final TwoDimensionalChildListDelegate listDelegate = delegate as TwoDimensionalChildListDelegate; + final int rowCount; + final int columnCount; + rowCount = listDelegate.children.length; + columnCount = listDelegate.children[0].length; + + final int leadingColumn = math.max((horizontalPixels / 200).floor(), 0); + final int leadingRow = math.max((verticalPixels / 200).floor(), 0); + final int trailingColumn = math.min( + ((horizontalPixels + viewportDimension.width) / 200).ceil(), + columnCount - 1, + ); + final int trailingRow = math.min( + ((verticalPixels + viewportDimension.height) / 200).ceil(), + rowCount - 1, + ); + + double xLayoutOffset = (leadingColumn * 200) - horizontalOffset.pixels; + for (int column = leadingColumn; column <= trailingColumn; column++) { + double yLayoutOffset = (leadingRow * 200) - verticalOffset.pixels; + for (int row = leadingRow; row <= trailingRow; row++) { + final ChildVicinity vicinity = ChildVicinity(xIndex: column, yIndex: row); + final RenderBox child = buildOrObtainChildFor(vicinity)!; + child.layout(constraints.tighten(width: 200.0, height: 200.0)); + + parentDataOf(child).layoutOffset = Offset(xLayoutOffset, yLayoutOffset); + yLayoutOffset += 200; + } + xLayoutOffset += 200; + } + + verticalOffset.applyContentDimensions( + 0.0, + math.max(200 * rowCount - viewportDimension.height, 0.0), + ); + horizontalOffset.applyContentDimensions( + 0, + math.max(200 * columnCount - viewportDimension.width, 0.0), + ); + } +} + +class KeepAliveCheckBox extends StatefulWidget { + const KeepAliveCheckBox({ super.key }); + + @override + KeepAliveCheckBoxState createState() => KeepAliveCheckBoxState(); +} + +class KeepAliveCheckBoxState extends State<KeepAliveCheckBox> with AutomaticKeepAliveClientMixin { + bool checkValue = false; + + @override + bool get wantKeepAlive => _wantKeepAlive; + bool _wantKeepAlive = false; + set wantKeepAlive(bool value) { + if (_wantKeepAlive != value) { + _wantKeepAlive = value; + updateKeepAlive(); + } + } + + @override + Widget build(BuildContext context) { + super.build(context); + return Checkbox( + value: checkValue, + onChanged: (bool? value) { + if (checkValue != value) { + setState(() { + checkValue = value!; + wantKeepAlive = value; + }); + } + }, + ); + } +} + +// TwoDimensionalViewportParentData already mixes in KeepAliveParentDataMixin, +// and so should be compatible with both the KeepAlive and +// TestParentDataWidget ParentDataWidgets. +// This ParentData is set up above as part of the +// RenderSimpleBuilderTableViewport for testing. +class TestExtendedParentData extends TwoDimensionalViewportParentData { + int? testValue; +} + +class TestParentDataWidget extends ParentDataWidget<TestExtendedParentData> { + const TestParentDataWidget({ + super.key, + required super.child, + this.testValue, + }); + + final int? testValue; + + @override + void applyParentData(RenderObject renderObject) { + assert(renderObject.parentData is TestExtendedParentData); + final TestExtendedParentData parentData = renderObject.parentData! as TestExtendedParentData; + parentData.testValue = testValue; + } + + @override + Type get debugTypicalAncestorWidgetClass => SimpleBuilderTableViewport; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/two_dimensional_viewport_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/two_dimensional_viewport_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..fd1804b5d9d04491716aef4f0ccf144d4f5cb027 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/two_dimensional_viewport_test.dart @@ -0,0 +1,2783 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'two_dimensional_utils.dart'; + +void main() { + group('TwoDimensionalChildDelegate', () { + group('TwoDimensionalChildBuilderDelegate', () { + testWidgets('repaintBoundaries', (WidgetTester tester) async { + // Default - adds repaint boundaries + late final TwoDimensionalChildBuilderDelegate delegate1; + addTearDown(() => delegate1.dispose()); + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate1 = TwoDimensionalChildBuilderDelegate( + // Only build 1 child + maxXIndex: 0, + maxYIndex: 0, + builder: (BuildContext context, ChildVicinity vicinity) { + return SizedBox( + height: 200, + width: 200, + child: Center(child: Text('C${vicinity.xIndex}:R${vicinity.yIndex}')), + ); + } + ) + )); + await tester.pumpAndSettle(); + + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + expect(find.byType(RepaintBoundary), findsNWidgets(7)); + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(find.byType(RepaintBoundary), findsNWidgets(3)); + } + + // None + late final TwoDimensionalChildBuilderDelegate delegate2; + addTearDown(() => delegate2.dispose()); + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate2 = TwoDimensionalChildBuilderDelegate( + // Only build 1 child + maxXIndex: 0, + maxYIndex: 0, + addRepaintBoundaries: false, + builder: (BuildContext context, ChildVicinity vicinity) { + return SizedBox( + height: 200, + width: 200, + child: Center(child: Text('C${vicinity.xIndex}:R${vicinity.yIndex}')), + ); + } + ) + )); + await tester.pumpAndSettle(); + + switch (defaultTargetPlatform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + expect(find.byType(RepaintBoundary), findsNWidgets(6)); + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(find.byType(RepaintBoundary), findsNWidgets(2)); + } + }, variant: TargetPlatformVariant.all()); + + testWidgets('will return null from build for exceeding maxXIndex and maxYIndex', (WidgetTester tester) async { + late BuildContext capturedContext; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + // Only build 1 child + maxXIndex: 0, + maxYIndex: 0, + addRepaintBoundaries: false, + builder: (BuildContext context, ChildVicinity vicinity) { + capturedContext = context; + return SizedBox( + height: 200, + width: 200, + child: Center(child: Text('C${vicinity.xIndex}:R${vicinity.yIndex}')), + ); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + // maxXIndex + expect( + delegate.build(capturedContext, const ChildVicinity(xIndex: 1, yIndex: 0)), + isNull, + ); + + // maxYIndex + expect( + delegate.build(capturedContext, const ChildVicinity(xIndex: 0, yIndex: 1)), + isNull, + ); + + // Both + expect( + delegate.build(capturedContext, const ChildVicinity(xIndex: 1, yIndex: 1)), + isNull, + ); + }, variant: TargetPlatformVariant.all()); + + test('maxXIndex and maxYIndex assertions', () { + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 0, + maxYIndex: 0, + builder: (BuildContext context, ChildVicinity vicinity) { + return const SizedBox.shrink(); + } + ); + // Update + delegate.maxXIndex = -1; // No exception. + expect( + () { + delegate.maxXIndex = -2; + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('value == null || value >= -1'), + ), + ), + ); + delegate.maxYIndex = -1; // No exception + expect( + () { + delegate.maxYIndex = -2; + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('value == null || value >= -1'), + ), + ), + ); + // Constructor + expect( + () { + TwoDimensionalChildBuilderDelegate( + maxXIndex: -2, + maxYIndex: 0, + builder: (BuildContext context, ChildVicinity vicinity) { + return const SizedBox.shrink(); + } + ); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('maxXIndex == null || maxXIndex >= -1'), + ), + ), + ); + expect( + () { + TwoDimensionalChildBuilderDelegate( + maxXIndex: 0, + maxYIndex: -2, + builder: (BuildContext context, ChildVicinity vicinity) { + return const SizedBox.shrink(); + } + ); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('maxYIndex == null || maxYIndex >= -1'), + ), + ), + ); + }); + + testWidgets('throws an error when builder throws', (WidgetTester tester) async { + final List<Object> exceptions = <Object>[]; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + FlutterError.onError = (FlutterErrorDetails details) { + exceptions.add(details.exception); + }; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + // Only build 1 child + maxXIndex: 0, + maxYIndex: 0, + addRepaintBoundaries: false, + builder: (BuildContext context, ChildVicinity vicinity) { + throw 'Builder error!'; + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + FlutterError.onError = oldHandler; + + expect(exceptions.isNotEmpty, isTrue); + expect(exceptions.length, 1); + expect(exceptions[0] as String, contains('Builder error!')); + }, variant: TargetPlatformVariant.all()); + + testWidgets('shouldRebuild', (WidgetTester tester) async { + expect(builderDelegate.shouldRebuild(builderDelegate), isTrue); + }, variant: TargetPlatformVariant.all()); + + testWidgets('builder delegate supports automatic keep alive - default true', (WidgetTester tester) async { + const ChildVicinity firstCell = ChildVicinity(xIndex: 0, yIndex: 0); + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + final UniqueKey checkBoxKey = UniqueKey(); + final TwoDimensionalChildBuilderDelegate builderDelegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + return SizedBox.square( + dimension: 200, + child: Center(child: vicinity == firstCell + ? KeepAliveCheckBox(key: checkBoxKey) + : Text('R${vicinity.xIndex}:C${vicinity.yIndex}') + ), + ); + } + ); + addTearDown(builderDelegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: builderDelegate, + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + )); + await tester.pumpAndSettle(); + + expect(verticalController.hasClients, isTrue); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isFalse, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isFalse, + ); + // Scroll away, disposing of the checkbox. + verticalController.jumpTo(verticalController.position.maxScrollExtent); + await tester.pump(); + expect(verticalController.position.pixels, 600.0); + expect(find.byKey(checkBoxKey), findsNothing); + + // Bring back into view, still unchecked, not kept alive. + verticalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + await tester.tap(find.byKey(checkBoxKey)); + await tester.pumpAndSettle(); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + + // Scroll away again, checkbox should be kept alive now. + verticalController.jumpTo(verticalController.position.maxScrollExtent); + await tester.pump(); + expect(verticalController.position.pixels, 600.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + + // Bring back into view, still checked, after being kept alive. + verticalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + }); + + testWidgets('Keep alive works with additional parent data widgets', (WidgetTester tester) async { + const ChildVicinity firstCell = ChildVicinity(xIndex: 0, yIndex: 0); + final ScrollController verticalController = ScrollController(); + final UniqueKey checkBoxKey = UniqueKey(); + final TwoDimensionalChildBuilderDelegate builderDelegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + addRepaintBoundaries: false, + builder: (BuildContext context, ChildVicinity vicinity) { + // The delegate will add a KeepAlive ParentDataWidget, this add an + // additional ParentDataWidget. + return TestParentDataWidget( + testValue: 20, + child: SizedBox.square( + dimension: 200, + child: Center(child: vicinity == firstCell + ? KeepAliveCheckBox(key: checkBoxKey) + : Text('R${vicinity.xIndex}:C${vicinity.yIndex}') + ), + ), + ); + } + ); + + await tester.pumpWidget(simpleBuilderTest( + delegate: builderDelegate, + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + )); + await tester.pumpAndSettle(); + + expect(verticalController.hasClients, isTrue); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isFalse, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isFalse, + ); + RenderSimpleBuilderTableViewport viewport = getViewport(tester, checkBoxKey) as RenderSimpleBuilderTableViewport; + TestExtendedParentData parentData = viewport.parentDataOf(viewport.testGetChildFor(firstCell)!); + // Check parent data from both ParentDataWidgets + expect(parentData.testValue, 20); + expect(parentData.keepAlive, isFalse); + + // Scroll away, disposing of the checkbox. + verticalController.jumpTo(verticalController.position.maxScrollExtent); + await tester.pump(); + expect(verticalController.position.pixels, 600.0); + expect(find.byKey(checkBoxKey), findsNothing); + + // Bring back into view, still unchecked, not kept alive. + verticalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + // Check the box to set keep alive to true. + await tester.tap(find.byKey(checkBoxKey)); + await tester.pumpAndSettle(); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + viewport = getViewport(tester, checkBoxKey) as RenderSimpleBuilderTableViewport; + parentData = viewport.parentDataOf(viewport.testGetChildFor(firstCell)!); + // Check parent data from both ParentDataWidgets + expect(parentData.testValue, 20); + expect(parentData.keepAlive, isTrue); + + // Scroll away again, checkbox should be kept alive now. + verticalController.jumpTo(verticalController.position.maxScrollExtent); + await tester.pump(); + expect(verticalController.position.pixels, 600.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + viewport = getViewport(tester, checkBoxKey) as RenderSimpleBuilderTableViewport; + parentData = viewport.parentDataOf(viewport.testGetChildFor(firstCell)!); + // Check parent data from both ParentDataWidgets + expect(parentData.testValue, 20); + expect(parentData.keepAlive, isTrue); + + // Bring back into view, still checked, after being kept alive. + verticalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + viewport = getViewport(tester, checkBoxKey) as RenderSimpleBuilderTableViewport; + parentData = viewport.parentDataOf(viewport.testGetChildFor(firstCell)!); + // Check parent data from both ParentDataWidgets + expect(parentData.testValue, 20); + expect(parentData.keepAlive, isTrue); + }); + + testWidgets('builder delegate will not add automatic keep alives', (WidgetTester tester) async { + const ChildVicinity firstCell = ChildVicinity(xIndex: 0, yIndex: 0); + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + final UniqueKey checkBoxKey = UniqueKey(); + final TwoDimensionalChildBuilderDelegate builderDelegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + addAutomaticKeepAlives: false, // No keeping alive this time + builder: (BuildContext context, ChildVicinity vicinity) { + return SizedBox.square( + dimension: 200, + child: Center(child: vicinity == firstCell + ? KeepAliveCheckBox(key: checkBoxKey) + : Text('R${vicinity.xIndex}:C${vicinity.yIndex}') + ), + ); + } + ); + addTearDown(builderDelegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: builderDelegate, + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + )); + await tester.pumpAndSettle(); + + expect(verticalController.hasClients, isTrue); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isFalse, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isFalse, + ); + // Scroll away, disposing of the checkbox. + verticalController.jumpTo(verticalController.position.maxScrollExtent); + await tester.pump(); + expect(verticalController.position.pixels, 600.0); + expect(find.byKey(checkBoxKey), findsNothing); + + // Bring back into view, still unchecked, not kept alive. + verticalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + await tester.tap(find.byKey(checkBoxKey)); + await tester.pumpAndSettle(); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + + // Scroll away again, checkbox should not be kept alive since the + // delegate did not add automatic keep alive. + verticalController.jumpTo(verticalController.position.maxScrollExtent); + await tester.pump(); + expect(verticalController.position.pixels, 600.0); + expect(find.byKey(checkBoxKey), findsNothing); + + // Bring back into view, not checked, having not been kept alive. + verticalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isFalse, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isFalse, + ); + }); + }); + + group('TwoDimensionalChildListDelegate', () { + testWidgets('repaintBoundaries', (WidgetTester tester) async { + final List<List<Widget>> children = <List<Widget>>[]; + children.add(<Widget>[ + const SizedBox( + height: 200, + width: 200, + child: Center(child: Text('R0:C0')), + ) + ]); + // Default - adds repaint boundaries + late final TwoDimensionalChildListDelegate delegate1; + addTearDown(() => delegate1.dispose()); + await tester.pumpWidget(simpleListTest( + delegate: delegate1 = TwoDimensionalChildListDelegate( + // Only builds 1 child + children: children, + ) + )); + await tester.pumpAndSettle(); + + // In the tests below the number of RepaintBoundary widgets depends on: + // ModalRoute - builds 2 + // GlowingOverscrollIndicator - builds 2 + // TwoDimensionalChildListDelegate - builds 1 unless addRepaintBoundaries is false + + void expectModalRoute() { + expect(ModalRoute.of(tester.element(find.byType(SimpleListTableViewport))), isA<MaterialPageRoute<void>>()); + } + + switch (defaultTargetPlatform) { + case TargetPlatform.fuchsia: + expectModalRoute(); + expect(find.byType(GlowingOverscrollIndicator), findsNWidgets(2)); + expect(find.byType(RepaintBoundary), findsNWidgets(7)); + + case TargetPlatform.android: + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expectModalRoute(); + expect(find.byType(RepaintBoundary), findsNWidgets(3)); + } + + // None + late final TwoDimensionalChildListDelegate delegate2; + addTearDown(() => delegate2.dispose()); + await tester.pumpWidget(simpleListTest( + delegate: delegate2 = TwoDimensionalChildListDelegate( + // Different children triggers rebuild + children: <List<Widget>>[<Widget>[Container()]], + addRepaintBoundaries: false, + ) + )); + await tester.pumpAndSettle(); + + switch (defaultTargetPlatform) { + case TargetPlatform.fuchsia: + expectModalRoute(); + expect(find.byType(GlowingOverscrollIndicator), findsNWidgets(2)); + expect(find.byType(RepaintBoundary), findsNWidgets(6)); + + case TargetPlatform.android: + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expectModalRoute(); + expect(find.byType(RepaintBoundary), findsNWidgets(2)); + } + }, variant: TargetPlatformVariant.all()); + + testWidgets('will return null for a ChildVicinity outside of list bounds', (WidgetTester tester) async { + final List<List<Widget>> children = <List<Widget>>[]; + children.add(<Widget>[ + const SizedBox( + height: 200, + width: 200, + child: Center(child: Text('R0:C0')), + ) + ]); + final TwoDimensionalChildListDelegate delegate = TwoDimensionalChildListDelegate( + // Only builds 1 child + children: children, + ); + addTearDown(delegate.dispose); + + // X index + expect( + delegate.build(_NullBuildContext(), const ChildVicinity(xIndex: 1, yIndex: 0)), + isNull, + ); + // Y index + expect( + delegate.build(_NullBuildContext(), const ChildVicinity(xIndex: 0, yIndex: 1)), + isNull, + ); + + // Both + expect( + delegate.build(_NullBuildContext(), const ChildVicinity(xIndex: 1, yIndex: 1)), + isNull, + ); + }, variant: TargetPlatformVariant.all()); + + testWidgets('shouldRebuild', (WidgetTester tester) async { + final List<List<Widget>> children = <List<Widget>>[]; + children.add(<Widget>[ + const SizedBox( + height: 200, + width: 200, + child: Center(child: Text('R0:C0')), + ) + ]); + final TwoDimensionalChildListDelegate delegate = TwoDimensionalChildListDelegate( + // Only builds 1 child + children: children, + ); + addTearDown(delegate.dispose); + expect(delegate.shouldRebuild(delegate), isFalse); + + final List<List<Widget>> newChildren = <List<Widget>>[]; + final TwoDimensionalChildListDelegate oldDelegate = TwoDimensionalChildListDelegate( + children: newChildren, + ); + addTearDown(oldDelegate.dispose); + + expect(delegate.shouldRebuild(oldDelegate), isTrue); + }, variant: TargetPlatformVariant.all()); + }); + + testWidgets('list delegate supports automatic keep alive - default true', (WidgetTester tester) async { + final UniqueKey checkBoxKey = UniqueKey(); + final Widget originCell = SizedBox.square( + dimension: 200, + child: Center(child: KeepAliveCheckBox(key: checkBoxKey) + ), + ); + const Widget otherCell = SizedBox.square(dimension: 200); + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + final TwoDimensionalChildListDelegate listDelegate = TwoDimensionalChildListDelegate( + children: <List<Widget>>[ + <Widget>[originCell, otherCell, otherCell, otherCell, otherCell], + <Widget>[otherCell, otherCell, otherCell, otherCell, otherCell], + <Widget>[otherCell, otherCell, otherCell, otherCell, otherCell], + <Widget>[otherCell, otherCell, otherCell, otherCell, otherCell], + <Widget>[otherCell, otherCell, otherCell, otherCell, otherCell], + ], + ); + addTearDown(listDelegate.dispose); + + await tester.pumpWidget(simpleListTest( + delegate: listDelegate, + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + )); + await tester.pumpAndSettle(); + + expect(verticalController.hasClients, isTrue); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isFalse, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isFalse, + ); + // Scroll away, disposing of the checkbox. + verticalController.jumpTo(verticalController.position.maxScrollExtent); + await tester.pump(); + expect(verticalController.position.pixels, 400.0); + expect(find.byKey(checkBoxKey), findsNothing); + + // Bring back into view, still unchecked, not kept alive. + verticalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + await tester.tap(find.byKey(checkBoxKey)); + await tester.pumpAndSettle(); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + + // Scroll away again, checkbox should be kept alive now. + verticalController.jumpTo(verticalController.position.maxScrollExtent); + await tester.pump(); + expect(verticalController.position.pixels, 400.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + + // Bring back into view, still checked, after being kept alive. + verticalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + }); + + testWidgets('list delegate will not add automatic keep alives', (WidgetTester tester) async { + final UniqueKey checkBoxKey = UniqueKey(); + final Widget originCell = SizedBox.square( + dimension: 200, + child: Center(child: KeepAliveCheckBox(key: checkBoxKey) + ), + ); + const Widget otherCell = SizedBox.square(dimension: 200); + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + final TwoDimensionalChildListDelegate listDelegate = TwoDimensionalChildListDelegate( + addAutomaticKeepAlives: false, + children: <List<Widget>>[ + <Widget>[originCell, otherCell, otherCell, otherCell, otherCell], + <Widget>[otherCell, otherCell, otherCell, otherCell, otherCell], + <Widget>[otherCell, otherCell, otherCell, otherCell, otherCell], + <Widget>[otherCell, otherCell, otherCell, otherCell, otherCell], + <Widget>[otherCell, otherCell, otherCell, otherCell, otherCell], + ], + ); + addTearDown(listDelegate.dispose); + + await tester.pumpWidget(simpleListTest( + delegate: listDelegate, + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + )); + await tester.pumpAndSettle(); + + expect(verticalController.hasClients, isTrue); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isFalse, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isFalse, + ); + // Scroll away, disposing of the checkbox. + verticalController.jumpTo(verticalController.position.maxScrollExtent); + await tester.pump(); + expect(verticalController.position.pixels, 400.0); + expect(find.byKey(checkBoxKey), findsNothing); + + // Bring back into view, still unchecked, not kept alive. + verticalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + await tester.tap(find.byKey(checkBoxKey)); + await tester.pumpAndSettle(); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isTrue, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isTrue, + ); + + // Scroll away again, checkbox should not be kept alive since the + // delegate did not add automatic keep alive. + verticalController.jumpTo(verticalController.position.maxScrollExtent); + await tester.pump(); + expect(verticalController.position.pixels, 400.0); + expect(find.byKey(checkBoxKey), findsNothing); + + // Bring back into view, not checked, having not been kept alive. + verticalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(find.byKey(checkBoxKey), findsOneWidget); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).checkValue, + isFalse, + ); + expect( + tester.state<KeepAliveCheckBoxState>(find.byKey(checkBoxKey)).wantKeepAlive, + isFalse, + ); + }); + }); + + group('TwoDimensionalScrollable', () { + testWidgets('.of, .maybeOf', (WidgetTester tester) async { + late BuildContext capturedContext; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 0, + maxYIndex: 0, + builder: (BuildContext context, ChildVicinity vicinity) { + capturedContext = context; + return const SizedBox.square(dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + + expect(TwoDimensionalScrollable.of(capturedContext), isNotNull); + expect(TwoDimensionalScrollable.maybeOf(capturedContext), isNotNull); + + await tester.pumpWidget(Builder( + builder: (BuildContext context) { + capturedContext = context; + TwoDimensionalScrollable.of(context); + return Container(); + } + )); + await tester.pumpAndSettle(); + final dynamic exception = tester.takeException(); + expect(exception, isFlutterError); + final FlutterError error = exception as FlutterError; + expect(error.toString(), contains( + 'TwoDimensionalScrollable.of() was called with a context that does ' + 'not contain a TwoDimensionalScrollable widget.' + )); + + expect(TwoDimensionalScrollable.maybeOf(capturedContext), isNull); + }, variant: TargetPlatformVariant.all()); + + testWidgets('horizontal and vertical getters', (WidgetTester tester) async { + late BuildContext capturedContext; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 0, + maxYIndex: 0, + builder: (BuildContext context, ChildVicinity vicinity) { + capturedContext = context; + return const SizedBox.square(dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + + final TwoDimensionalScrollableState scrollable = TwoDimensionalScrollable.of(capturedContext); + expect(scrollable.verticalScrollable.position.pixels, 0.0); + expect(scrollable.horizontalScrollable.position.pixels, 0.0); + }, variant: TargetPlatformVariant.all()); + + testWidgets('creates fallback ScrollControllers if not provided by ScrollableDetails', (WidgetTester tester) async { + late BuildContext capturedContext; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 0, + maxYIndex: 0, + builder: (BuildContext context, ChildVicinity vicinity) { + capturedContext = context; + return const SizedBox.square(dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + + // Vertical + final ScrollableState vertical = Scrollable.of(capturedContext, axis: Axis.vertical); + expect(vertical.widget.controller, isNotNull); + // Horizontal + final ScrollableState horizontal = Scrollable.of(capturedContext, axis: Axis.horizontal); + expect(horizontal.widget.controller, isNotNull); + }, variant: TargetPlatformVariant.all()); + + testWidgets('asserts the axis directions do not conflict with one another', (WidgetTester tester) async { + final List<Object> exceptions = <Object>[]; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + FlutterError.onError = (FlutterErrorDetails details) { + exceptions.add(details.exception); + }; + // Horizontal mismatch + await tester.pumpWidget(TwoDimensionalScrollable( + horizontalDetails: const ScrollableDetails.horizontal(), + verticalDetails: const ScrollableDetails.horizontal(), + viewportBuilder: (BuildContext context, ViewportOffset verticalPosition, ViewportOffset horizontalPosition) { + return Container(); + }, + )); + + // Vertical mismatch + await tester.pumpWidget(TwoDimensionalScrollable( + horizontalDetails: const ScrollableDetails.vertical(), + verticalDetails: const ScrollableDetails.vertical(), + viewportBuilder: (BuildContext context, ViewportOffset verticalPosition, ViewportOffset horizontalPosition) { + return Container(); + }, + )); + + // Both + await tester.pumpWidget(TwoDimensionalScrollable( + horizontalDetails: const ScrollableDetails.vertical(), + verticalDetails: const ScrollableDetails.horizontal(), + viewportBuilder: (BuildContext context, ViewportOffset verticalPosition, ViewportOffset horizontalPosition) { + return Container(); + }, + )); + + expect(exceptions.length, 3); + for (final Object exception in exceptions) { + expect(exception, isAssertionError); + expect((exception as AssertionError).message, contains('are not Axis')); + } + FlutterError.onError = oldHandler; + }, variant: TargetPlatformVariant.all()); + + testWidgets('correctly sets restorationIds', (WidgetTester tester) async { + late BuildContext capturedContext; + // with restorationID set + await tester.pumpWidget(WidgetsApp( + color: const Color(0xFFFFFFFF), + restorationScopeId: 'Test ID', + builder: (BuildContext context, Widget? child) => TwoDimensionalScrollable( + restorationId: 'Custom Restoration ID', + horizontalDetails: const ScrollableDetails.horizontal(), + verticalDetails: const ScrollableDetails.vertical(), + viewportBuilder: (BuildContext context, ViewportOffset verticalPosition, ViewportOffset horizontalPosition) { + return SizedBox.square( + dimension: 200, + child: Builder( + builder: (BuildContext context) { + capturedContext = context; + return Container(); + }, + ) + ); + }, + ), + )); + await tester.pumpAndSettle(); + + expect( + RestorationScope.of(capturedContext).restorationId, + 'Custom Restoration ID', + ); + expect( + Scrollable.of(capturedContext, axis: Axis.vertical).widget.restorationId, + 'OuterVerticalTwoDimensionalScrollable', + ); + expect( + Scrollable.of(capturedContext, axis: Axis.horizontal).widget.restorationId, + 'InnerHorizontalTwoDimensionalScrollable', + ); + + // default restorationID + await tester.pumpWidget(TwoDimensionalScrollable( + horizontalDetails: const ScrollableDetails.horizontal(), + verticalDetails: const ScrollableDetails.vertical(), + viewportBuilder: (BuildContext context, ViewportOffset verticalPosition, ViewportOffset horizontalPosition) { + return SizedBox.square( + dimension: 200, + child: Builder( + builder: (BuildContext context) { + capturedContext = context; + return Container(); + }, + ) + ); + }, + )); + await tester.pumpAndSettle(); + + expect( + RestorationScope.maybeOf(capturedContext), + isNull, + ); + expect( + Scrollable.of(capturedContext, axis: Axis.vertical).widget.restorationId, + 'OuterVerticalTwoDimensionalScrollable', + ); + expect( + Scrollable.of(capturedContext, axis: Axis.horizontal).widget.restorationId, + 'InnerHorizontalTwoDimensionalScrollable', + ); + }, variant: TargetPlatformVariant.all()); + + testWidgets('Restoration works', (WidgetTester tester) async { + await tester.pumpWidget(WidgetsApp( + color: const Color(0xFFFFFFFF), + restorationScopeId: 'Test ID', + builder: (BuildContext context, Widget? child) => TwoDimensionalScrollable( + restorationId: 'Custom Restoration ID', + horizontalDetails: const ScrollableDetails.horizontal(), + verticalDetails: const ScrollableDetails.vertical(), + viewportBuilder: (BuildContext context, ViewportOffset verticalPosition, ViewportOffset horizontalPosition) { + return SimpleBuilderTableViewport( + verticalOffset: verticalPosition, + verticalAxisDirection: AxisDirection.down, + horizontalOffset: horizontalPosition, + horizontalAxisDirection: AxisDirection.right, + delegate: builderDelegate, + mainAxis: Axis.vertical, + ); + }, + ), + )); + await tester.pumpAndSettle(); + + await restoreScrollAndVerify(tester); + }, variant: TargetPlatformVariant.all()); + + testWidgets('Inner Scrollables receive the correct details from TwoDimensionalScrollable', (WidgetTester tester) async { + // Default + late BuildContext capturedContext; + await tester.pumpWidget(TwoDimensionalScrollable( + horizontalDetails: const ScrollableDetails.horizontal(), + verticalDetails: const ScrollableDetails.vertical(), + viewportBuilder: (BuildContext context, ViewportOffset verticalPosition, ViewportOffset horizontalPosition) { + return SizedBox.square( + dimension: 200, + child: Builder( + builder: (BuildContext context) { + capturedContext = context; + return Container(); + }, + ) + ); + }, + )); + await tester.pumpAndSettle(); + + // Vertical + ScrollableState vertical = Scrollable.of(capturedContext, axis: Axis.vertical); + expect(vertical.widget.key, isNotNull); + expect(vertical.widget.axisDirection, AxisDirection.down); + expect(vertical.widget.controller, isNotNull); + expect(vertical.widget.physics, isNull); + expect(vertical.widget.clipBehavior, Clip.hardEdge); + expect(vertical.widget.incrementCalculator, isNull); + expect(vertical.widget.excludeFromSemantics, isFalse); + expect(vertical.widget.restorationId, 'OuterVerticalTwoDimensionalScrollable'); + expect(vertical.widget.dragStartBehavior, DragStartBehavior.start); + + // Horizontal + ScrollableState horizontal = Scrollable.of(capturedContext, axis: Axis.horizontal); + expect(horizontal.widget.key, isNotNull); + expect(horizontal.widget.axisDirection, AxisDirection.right); + expect(horizontal.widget.controller, isNotNull); + expect(horizontal.widget.physics, isNull); + expect(horizontal.widget.clipBehavior, Clip.hardEdge); + expect(horizontal.widget.incrementCalculator, isNull); + expect(horizontal.widget.excludeFromSemantics, isFalse); + expect(horizontal.widget.restorationId, 'InnerHorizontalTwoDimensionalScrollable'); + expect(horizontal.widget.dragStartBehavior, DragStartBehavior.start); + + // Customized + final ScrollController horizontalController = ScrollController(); + addTearDown(horizontalController.dispose); + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + double calculator(_) => 0.0; + await tester.pumpWidget(TwoDimensionalScrollable( + incrementCalculator: calculator, + excludeFromSemantics: true, + dragStartBehavior: DragStartBehavior.down, + horizontalDetails: ScrollableDetails.horizontal( + reverse: true, + controller: horizontalController, + physics: const ClampingScrollPhysics(), + decorationClipBehavior: Clip.antiAlias, + ), + verticalDetails: ScrollableDetails.vertical( + reverse: true, + controller: verticalController, + physics: const AlwaysScrollableScrollPhysics(), + decorationClipBehavior: Clip.antiAliasWithSaveLayer, + ), + viewportBuilder: (BuildContext context, ViewportOffset verticalPosition, ViewportOffset horizontalPosition) { + return SizedBox.square( + dimension: 200, + child: Builder( + builder: (BuildContext context) { + capturedContext = context; + return Container(); + }, + ) + ); + }, + )); + await tester.pumpAndSettle(); + + // Vertical + vertical = Scrollable.of(capturedContext, axis: Axis.vertical); + expect(vertical.widget.key, isNotNull); + expect(vertical.widget.axisDirection, AxisDirection.up); + expect(vertical.widget.controller, verticalController); + expect(vertical.widget.physics, const AlwaysScrollableScrollPhysics()); + expect(vertical.widget.clipBehavior, Clip.antiAliasWithSaveLayer); + expect( + vertical.widget.incrementCalculator!(ScrollIncrementDetails( + type: ScrollIncrementType.line, + metrics: verticalController.position, + )), + 0.0, + ); + expect(vertical.widget.excludeFromSemantics, isTrue); + expect(vertical.widget.restorationId, 'OuterVerticalTwoDimensionalScrollable'); + expect(vertical.widget.dragStartBehavior, DragStartBehavior.down); + + // Horizontal + horizontal = Scrollable.of(capturedContext, axis: Axis.horizontal); + expect(horizontal.widget.key, isNotNull); + expect(horizontal.widget.axisDirection, AxisDirection.left); + expect(horizontal.widget.controller, horizontalController); + expect(horizontal.widget.physics, const ClampingScrollPhysics()); + expect(horizontal.widget.clipBehavior, Clip.antiAlias); + expect( + horizontal.widget.incrementCalculator!(ScrollIncrementDetails( + type: ScrollIncrementType.line, + metrics: horizontalController.position, + )), + 0.0, + ); + expect(horizontal.widget.excludeFromSemantics, isTrue); + expect(horizontal.widget.restorationId, 'InnerHorizontalTwoDimensionalScrollable'); + expect(horizontal.widget.dragStartBehavior, DragStartBehavior.down); + }, variant: TargetPlatformVariant.all()); + + group('DiagonalDragBehavior', () { + testWidgets('none (default)', (WidgetTester tester) async { + // Vertical and horizontal axes are locked. + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + final ScrollController horizontalController = ScrollController(); + addTearDown(horizontalController.dispose); + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: simpleBuilderTest( + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), + ) + )); + await tester.pumpAndSettle(); + final Finder findScrollable = find.byElementPredicate((Element e) => e.widget is TwoDimensionalScrollable); + + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + await tester.drag(findScrollable, const Offset(0.0, -100.0)); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 80.0); + expect(horizontalController.position.pixels, 0.0); + await tester.drag(findScrollable, const Offset(-100.0, 0.0)); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 80.0); + expect(horizontalController.position.pixels, 80.0); + // Drag with and x and y offset, only vertical will accept the gesture + // since the x is < kTouchSlop + await tester.drag(findScrollable, const Offset(-10.0, -50.0)); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 110.0); + expect(horizontalController.position.pixels, 80.0); + // Drag with and x and y offset, only horizontal will accept the gesture + // since the y is < kTouchSlop + await tester.drag(findScrollable, const Offset(-50.0, -10.0)); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 110.0); + expect(horizontalController.position.pixels, 110.0); + // Drag with and x and y offset, only vertical will accept the gesture + // x is > kTouchSlop, larger offset wins + await tester.drag(findScrollable, const Offset(-20.0, -50.0)); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 140.0); + expect(horizontalController.position.pixels, 110.0); + // Drag with and x and y offset, only horizontal will accept the gesture + // y is > kTouchSlop, larger offset wins + await tester.drag(findScrollable, const Offset(-50.0, -20.0)); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 140.0); + expect(horizontalController.position.pixels, 140.0); + }, variant: TargetPlatformVariant.all()); + + testWidgets('weightedEvent', (WidgetTester tester) async { + // For weighted event, the winning axis is locked for the duration of + // the gesture. + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + final ScrollController horizontalController = ScrollController(); + addTearDown(horizontalController.dispose); + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: simpleBuilderTest( + diagonalDrag: DiagonalDragBehavior.weightedEvent, + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), + ) + )); + await tester.pumpAndSettle(); + final Finder findScrollable = find.byElementPredicate((Element e) => e.widget is TwoDimensionalScrollable); + + // Locks to vertical axis - simple. + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + TestGesture gesture = await tester.startGesture(tester.getCenter(findScrollable)); + // In this case, the vertical axis clearly wins. + Offset secondLocation = tester.getCenter(findScrollable) + const Offset(0.0, -50.0); + await gesture.moveTo(secondLocation); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 50.0); + expect(horizontalController.position.pixels, 0.0); + // Gesture has not ended yet, move with horizontal diff + Offset thirdLocation = secondLocation + const Offset(-30, -15); + await gesture.moveTo(thirdLocation); + await tester.pumpAndSettle(); + // Only vertical diff applied + expect(verticalController.position.pixels, 65.0); + expect(horizontalController.position.pixels, 0.0); + await gesture.up(); + await tester.pumpAndSettle(); + + // Lock to vertical axis - scrolls diagonally until certain + verticalController.jumpTo(0.0); + horizontalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + gesture = await tester.startGesture(tester.getCenter(findScrollable)); + // In this case, the no one clearly wins, so it moves diagonally. + secondLocation = tester.getCenter(findScrollable) + const Offset(-50.0, -50.0); + await gesture.moveTo(secondLocation); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 50.0); + expect(horizontalController.position.pixels, 50.0); + // Gesture has not ended yet, move clearly indicating vertical + thirdLocation = secondLocation + const Offset(-20, -50); + await gesture.moveTo(thirdLocation); + await tester.pumpAndSettle(); + // Only vertical diff applied + expect(verticalController.position.pixels, 100.0); + expect(horizontalController.position.pixels, 50.0); + // Gesture has not ended yet, and vertical axis has won for the gesture + // continue only vertical scrolling. + Offset fourthLocation = thirdLocation + const Offset(-30, -30); + await gesture.moveTo(fourthLocation); + await tester.pumpAndSettle(); + // Only vertical diff applied + expect(verticalController.position.pixels, 130.0); + expect(horizontalController.position.pixels, 50.0); + await gesture.up(); + await tester.pumpAndSettle(); + + // Locks to horizontal axis - simple. + verticalController.jumpTo(0.0); + horizontalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + gesture = await tester.startGesture(tester.getCenter(findScrollable)); + // In this case, the horizontal axis clearly wins. + secondLocation = tester.getCenter(findScrollable) + const Offset(-50.0, 0.0); + await gesture.moveTo(secondLocation); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 50.0); + // Gesture has not ended yet, move with vertical diff + thirdLocation = secondLocation + const Offset(-15, -30); + await gesture.moveTo(thirdLocation); + await tester.pumpAndSettle(); + // Only vertical diff applied + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 65.0); + await gesture.up(); + await tester.pumpAndSettle(); + + // Lock to horizontal axis - scrolls diagonally until certain + verticalController.jumpTo(0.0); + horizontalController.jumpTo(0.0); + await tester.pump(); + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + gesture = await tester.startGesture(tester.getCenter(findScrollable)); + // In this case, the no one clearly wins, so it moves diagonally. + secondLocation = tester.getCenter(findScrollable) + const Offset(-50.0, -50.0); + await gesture.moveTo(secondLocation); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 50.0); + expect(horizontalController.position.pixels, 50.0); + // Gesture has not ended yet, move clearly indicating horizontal + thirdLocation = secondLocation + const Offset(-50, -20); + await gesture.moveTo(thirdLocation); + await tester.pumpAndSettle(); + // Only horizontal diff applied + expect(verticalController.position.pixels, 50.0); + expect(horizontalController.position.pixels, 100.0); + // Gesture has not ended yet, and horizontal axis has won for the gesture + // continue only horizontal scrolling. + fourthLocation = thirdLocation + const Offset(-30, -30); + await gesture.moveTo(fourthLocation); + await tester.pumpAndSettle(); + // Only horizontal diff applied + expect(verticalController.position.pixels, 50.0); + expect(horizontalController.position.pixels, 130.0); + await gesture.up(); + await tester.pumpAndSettle(); + }, variant: TargetPlatformVariant.all()); + + testWidgets('weightedContinuous', (WidgetTester tester) async { + // For weighted continuous, the winning axis can change if the axis + // differential for the gesture exceeds kTouchSlop. So it can lock, and + // remain locked, if the user maintains a generally straight gesture, + // otherwise it will unlock and re-evaluate. + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + final ScrollController horizontalController = ScrollController(); + addTearDown(horizontalController.dispose); + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: simpleBuilderTest( + diagonalDrag: DiagonalDragBehavior.weightedContinuous, + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), + ) + )); + await tester.pumpAndSettle(); + final Finder findScrollable = find.byElementPredicate((Element e) => e.widget is TwoDimensionalScrollable); + + // Locks to vertical, and then unlocks, resets to horizontal, then + // unlocks and scrolls diagonally. + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + final TestGesture gesture = await tester.startGesture(tester.getCenter(findScrollable)); + // In this case, the vertical axis clearly wins. + final Offset secondLocation = tester.getCenter(findScrollable) + const Offset(0.0, -50.0); + await gesture.moveTo(secondLocation); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 50.0); + expect(horizontalController.position.pixels, 0.0); + // Gesture has not ended yet, move with horizontal diff, but still + // dominant vertical + final Offset thirdLocation = secondLocation + const Offset(-15, -50); + await gesture.moveTo(thirdLocation); + await tester.pumpAndSettle(); + // Only vertical diff applied since kTouchSlop was not exceeded in the + // horizontal axis from one drag event to the next. + expect(verticalController.position.pixels, 100.0); + expect(horizontalController.position.pixels, 0.0); + // Gesture has not ended yet, move with unlocking horizontal diff + final Offset fourthLocation = thirdLocation + const Offset(-50, -15); + await gesture.moveTo(fourthLocation); + await tester.pumpAndSettle(); + // Only horizontal diff applied + expect(verticalController.position.pixels, 100.0); + expect(horizontalController.position.pixels, 50.0); + // Gesture has not ended yet, move with unlocking diff that results in + // diagonal move since neither wins. + final Offset fifthLocation = fourthLocation + const Offset(-50, -50); + await gesture.moveTo(fifthLocation); + await tester.pumpAndSettle(); + // Only horizontal diff applied + expect(verticalController.position.pixels, 150.0); + expect(horizontalController.position.pixels, 100.0); + await gesture.up(); + await tester.pumpAndSettle(); + }, variant: TargetPlatformVariant.all()); + + testWidgets('free', (WidgetTester tester) async { + // For free, anything goes. + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + final ScrollController horizontalController = ScrollController(); + addTearDown(horizontalController.dispose); + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: simpleBuilderTest( + diagonalDrag: DiagonalDragBehavior.free, + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), + ) + )); + await tester.pumpAndSettle(); + final Finder findScrollable = find.byElementPredicate((Element e) => e.widget is TwoDimensionalScrollable); + + // Nothing locks. + expect(verticalController.position.pixels, 0.0); + expect(horizontalController.position.pixels, 0.0); + final TestGesture gesture = await tester.startGesture(tester.getCenter(findScrollable)); + final Offset secondLocation = tester.getCenter(findScrollable) + const Offset(0.0, -50.0); + await gesture.moveTo(secondLocation); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 50.0); + expect(horizontalController.position.pixels, 0.0); + final Offset thirdLocation = secondLocation + const Offset(-15, -50); + await gesture.moveTo(thirdLocation); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 100.0); + expect(horizontalController.position.pixels, 15.0); + final Offset fourthLocation = thirdLocation + const Offset(-50, -15); + await gesture.moveTo(fourthLocation); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 115.0); + expect(horizontalController.position.pixels, 65.0); + final Offset fifthLocation = fourthLocation + const Offset(-50, -50); + await gesture.moveTo(fifthLocation); + await tester.pumpAndSettle(); + expect(verticalController.position.pixels, 165.0); + expect(horizontalController.position.pixels, 115.0); + await gesture.up(); + await tester.pumpAndSettle(); + }); + }); + }); + + testWidgets('TwoDimensionalViewport asserts against axes mismatch', (WidgetTester tester) async { + // Horizontal mismatch + expect( + () { + final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0); + addTearDown(verticalOffset.dispose); + final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0); + addTearDown(horizontalOffset.dispose); + + SimpleBuilderTableViewport( + verticalOffset: verticalOffset, + verticalAxisDirection: AxisDirection.left, + horizontalOffset: horizontalOffset, + horizontalAxisDirection: AxisDirection.right, + delegate: builderDelegate, + mainAxis: Axis.vertical, + ); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('AxisDirection is not Axis.'), + ), + ), + ); + + // Vertical mismatch + expect( + () { + final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0); + addTearDown(verticalOffset.dispose); + final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0); + addTearDown(horizontalOffset.dispose); + + SimpleBuilderTableViewport( + verticalOffset: verticalOffset, + verticalAxisDirection: AxisDirection.up, + horizontalOffset: horizontalOffset, + horizontalAxisDirection: AxisDirection.down, + delegate: builderDelegate, + mainAxis: Axis.vertical, + ); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('AxisDirection is not Axis.'), + ), + ), + ); + + // Both + expect( + () { + final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0); + addTearDown(verticalOffset.dispose); + final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0); + addTearDown(horizontalOffset.dispose); + + SimpleBuilderTableViewport( + verticalOffset: verticalOffset, + verticalAxisDirection: AxisDirection.left, + horizontalOffset: horizontalOffset, + horizontalAxisDirection: AxisDirection.down, + delegate: builderDelegate, + mainAxis: Axis.vertical, + ); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('AxisDirection is not Axis.'), + ), + ), + ); + }); + + test('TwoDimensionalViewportParentData', () { + // Default vicinity is invalid + final TwoDimensionalViewportParentData parentData = TwoDimensionalViewportParentData(); + expect(parentData.vicinity, ChildVicinity.invalid); + + // toString + parentData + ..vicinity = const ChildVicinity(xIndex: 10, yIndex: 10) + ..paintOffset = const Offset(20.0, 20.0) + ..layoutOffset = const Offset(20.0, 20.0); + expect( + parentData.toString(), + 'vicinity=(xIndex: 10, yIndex: 10); layoutOffset=Offset(20.0, 20.0); ' + 'paintOffset=Offset(20.0, 20.0); not visible; ', + ); + }); + + test('ChildVicinity comparable', () { + const ChildVicinity baseVicinity = ChildVicinity(xIndex: 0, yIndex: 0); + const ChildVicinity sameXVicinity = ChildVicinity(xIndex: 0, yIndex: 2); + const ChildVicinity sameYVicinity = ChildVicinity(xIndex: 3, yIndex: 0); + const ChildVicinity sameNothingVicinity = ChildVicinity(xIndex: 20, yIndex: 30); + // == + expect(baseVicinity == baseVicinity, isTrue); + expect(baseVicinity == sameXVicinity, isFalse); + expect(baseVicinity == sameYVicinity, isFalse); + expect(baseVicinity == sameNothingVicinity, isFalse); + + // compareTo + expect(baseVicinity.compareTo(baseVicinity), 0); + expect(baseVicinity.compareTo(sameXVicinity), -2); + expect(baseVicinity.compareTo(sameYVicinity), -3); + expect(baseVicinity.compareTo(sameNothingVicinity), -20); + + // toString + expect(baseVicinity.toString(), '(xIndex: 0, yIndex: 0)'); + expect(sameXVicinity.toString(), '(xIndex: 0, yIndex: 2)'); + expect(sameYVicinity.toString(), '(xIndex: 3, yIndex: 0)'); + expect(sameNothingVicinity.toString(), '(xIndex: 20, yIndex: 30)'); + }); + + group('RenderTwoDimensionalViewport', () { + testWidgets('asserts against axes mismatch', (WidgetTester tester) async { + // Horizontal mismatch + expect( + () { + final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0); + addTearDown(verticalOffset.dispose); + final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0); + addTearDown(horizontalOffset.dispose); + + RenderSimpleBuilderTableViewport( + verticalOffset: verticalOffset, + verticalAxisDirection: AxisDirection.left, + horizontalOffset: horizontalOffset, + horizontalAxisDirection: AxisDirection.right, + delegate: builderDelegate, + mainAxis: Axis.vertical, + childManager: _NullBuildContext(), + ); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('AxisDirection is not Axis.'), + ), + ), + ); + + // Vertical mismatch + expect( + () { + final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0); + addTearDown(verticalOffset.dispose); + final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0); + addTearDown(horizontalOffset.dispose); + + RenderSimpleBuilderTableViewport( + verticalOffset: verticalOffset, + verticalAxisDirection: AxisDirection.up, + horizontalOffset: horizontalOffset, + horizontalAxisDirection: AxisDirection.down, + delegate: builderDelegate, + mainAxis: Axis.vertical, + childManager: _NullBuildContext(), + ); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('AxisDirection is not Axis.'), + ), + ), + ); + + // Both + expect( + () { + final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0); + addTearDown(verticalOffset.dispose); + final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0); + addTearDown(horizontalOffset.dispose); + + RenderSimpleBuilderTableViewport( + verticalOffset: verticalOffset, + verticalAxisDirection: AxisDirection.left, + horizontalOffset: horizontalOffset, + horizontalAxisDirection: AxisDirection.down, + delegate: builderDelegate, + mainAxis: Axis.vertical, + childManager: _NullBuildContext(), + ); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('AxisDirection is not Axis.'), + ), + ), + ); + }); + + testWidgets('getters', (WidgetTester tester) async { + final UniqueKey childKey = UniqueKey(); + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 0, + maxYIndex: 0, + builder: (BuildContext context, ChildVicinity vicinity) { + return SizedBox.square(key: childKey, dimension: 200); + } + ); + addTearDown(delegate.dispose); + final ViewportOffset verticalOffset = ViewportOffset.fixed(10.0); + addTearDown(verticalOffset.dispose); + final ViewportOffset horizontalOffset = ViewportOffset.fixed(20.0); + addTearDown(horizontalOffset.dispose); + + final RenderSimpleBuilderTableViewport renderViewport = RenderSimpleBuilderTableViewport( + verticalOffset: verticalOffset, + verticalAxisDirection: AxisDirection.down, + horizontalOffset: horizontalOffset, + horizontalAxisDirection: AxisDirection.right, + delegate: delegate, + mainAxis: Axis.vertical, + childManager: _NullBuildContext(), + ); + addTearDown(renderViewport.dispose); + + expect(renderViewport.clipBehavior, Clip.hardEdge); + expect(renderViewport.cacheExtent, RenderAbstractViewport.defaultCacheExtent); + expect(renderViewport.isRepaintBoundary, isTrue); + expect(renderViewport.sizedByParent, isTrue); + // No size yet, should assert. + expect( + () { + renderViewport.viewportDimension; + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('hasSize'), + ), + ), + ); + expect(renderViewport.horizontalOffset.pixels, 20.0); + expect(renderViewport.horizontalAxisDirection, AxisDirection.right); + expect(renderViewport.verticalOffset.pixels, 10.0); + expect(renderViewport.verticalAxisDirection, AxisDirection.down); + expect(renderViewport.delegate, delegate); + expect(renderViewport.mainAxis, Axis.vertical); + + // viewportDimension when hasSize + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + final RenderTwoDimensionalViewport viewport = getViewport(tester, childKey); + expect(viewport.viewportDimension, const Size(800.0, 600.0)); + }, variant: TargetPlatformVariant.all()); + + testWidgets('Children are organized according to mainAxis', (WidgetTester tester) async { + final Map<ChildVicinity, UniqueKey> childKeys = <ChildVicinity, UniqueKey>{}; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + childKeys[vicinity] = childKeys[vicinity] ?? UniqueKey(); + return SizedBox.square(key: childKeys[vicinity], dimension: 200); + } + ); + addTearDown(delegate.dispose); + TwoDimensionalViewportParentData parentDataOf(RenderBox child) { + return child.parentData! as TwoDimensionalViewportParentData; + } + // mainAxis is vertical (default) + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + RenderTwoDimensionalViewport viewport = getViewport( + tester, + childKeys.values.first, + ); + expect(viewport.mainAxis, Axis.vertical); + // first child + expect( + parentDataOf(viewport.firstChild!).vicinity, + const ChildVicinity(xIndex: 0, yIndex: 0), + ); + expect( + parentDataOf(viewport.childAfter(viewport.firstChild!)!).vicinity, + const ChildVicinity(xIndex: 1, yIndex: 0), + ); + expect( + viewport.childBefore(viewport.firstChild!), + isNull, + ); + // last child + expect( + parentDataOf(viewport.lastChild!).vicinity, + const ChildVicinity(xIndex: 4, yIndex: 3), + ); + expect( + viewport.childAfter(viewport.lastChild!), + isNull, + ); + expect( + parentDataOf(viewport.childBefore(viewport.lastChild!)!).vicinity, + const ChildVicinity(xIndex: 3, yIndex: 3), + ); + + // mainAxis is horizontal + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + mainAxis: Axis.horizontal, + )); + await tester.pumpAndSettle(); + viewport = getViewport(tester, childKeys.values.first); + expect(viewport.mainAxis, Axis.horizontal); + // first child + expect( + parentDataOf(viewport.firstChild!).vicinity, + const ChildVicinity(xIndex: 0, yIndex: 0), + ); + expect( + parentDataOf(viewport.childAfter(viewport.firstChild!)!).vicinity, + const ChildVicinity(xIndex: 0, yIndex: 1), + ); + expect( + viewport.childBefore(viewport.firstChild!), + isNull, + ); + // last child + expect( + parentDataOf(viewport.lastChild!).vicinity, + const ChildVicinity(xIndex: 4, yIndex: 3), + ); + expect( + viewport.childAfter(viewport.lastChild!), + isNull, + ); + expect( + parentDataOf(viewport.childBefore(viewport.lastChild!)!).vicinity, + const ChildVicinity(xIndex: 4, yIndex: 2), + ); + }, variant: TargetPlatformVariant.all()); + + testWidgets('sets up parent data', (WidgetTester tester) async { + // Also tests computeAbsolutePaintOffsetFor & computeChildPaintExtent + // Regression test for https://github.com/flutter/flutter/issues/128723 + final Map<ChildVicinity, UniqueKey> childKeys = <ChildVicinity, UniqueKey>{}; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + childKeys[vicinity] = childKeys[vicinity] ?? UniqueKey(); + return SizedBox.square(key: childKeys[vicinity], dimension: 200); + } + ); + addTearDown(delegate.dispose); + + // parent data is TwoDimensionalViewportParentData + TwoDimensionalViewportParentData parentDataOf(RenderBox child) { + return child.parentData! as TwoDimensionalViewportParentData; + } + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + useCacheExtent: true, + )); + await tester.pumpAndSettle(); + + RenderTwoDimensionalViewport viewport = getViewport( + tester, + childKeys.values.first, + ); + + // first child + // parentData is computed correctly - normal axes + // - layoutOffset, paintOffset, isVisible, ChildVicinity + TwoDimensionalViewportParentData childParentData = parentDataOf(viewport.firstChild!); + expect(childParentData.vicinity, const ChildVicinity(xIndex: 0, yIndex: 0)); + expect(childParentData.isVisible, isTrue); + expect(childParentData.paintOffset, Offset.zero); + expect(childParentData.layoutOffset, Offset.zero); + // The last child is in the cache extent, and should not be visible. + childParentData = parentDataOf(viewport.lastChild!); + expect(childParentData.vicinity, const ChildVicinity(xIndex: 5, yIndex: 5)); + expect(childParentData.isVisible, isFalse); + expect(childParentData.paintOffset, const Offset(1000.0, 1000.0)); + expect(childParentData.layoutOffset, const Offset(1000.0, 1000.0)); + + // parentData is computed correctly - reverse axes + // - vertical reverse + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + verticalDetails: const ScrollableDetails.vertical(reverse: true), + )); + await tester.pumpAndSettle(); + + viewport = getViewport(tester, childKeys.values.first); + + childParentData = parentDataOf(viewport.firstChild!); + expect(childParentData.vicinity, const ChildVicinity(xIndex: 0, yIndex: 0)); + expect(childParentData.isVisible, isTrue); + expect(childParentData.paintOffset, const Offset(0.0, 400.0)); + expect(childParentData.layoutOffset, Offset.zero); + // The last child is in the cache extent, and should not be visible. + childParentData = parentDataOf(viewport.lastChild!); + expect(childParentData.vicinity, const ChildVicinity(xIndex: 5, yIndex: 5)); + expect(childParentData.isVisible, isFalse); + expect(childParentData.paintOffset, const Offset(1000.0, -600.0)); + expect(childParentData.layoutOffset, const Offset(1000.0, 1000.0)); + + // - horizontal reverse + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + horizontalDetails: const ScrollableDetails.horizontal(reverse: true), + )); + await tester.pumpAndSettle(); + + viewport = getViewport(tester, childKeys.values.first); + + childParentData = parentDataOf(viewport.firstChild!); + expect(childParentData.vicinity, const ChildVicinity(xIndex: 0, yIndex: 0)); + expect(childParentData.isVisible, isTrue); + expect(childParentData.paintOffset, const Offset(600.0, 0.0)); + expect(childParentData.layoutOffset, Offset.zero); + // The last child is in the cache extent, and should not be visible. + childParentData = parentDataOf(viewport.lastChild!); + expect(childParentData.vicinity, const ChildVicinity(xIndex: 5, yIndex: 5)); + expect(childParentData.isVisible, isFalse); + expect(childParentData.paintOffset, const Offset(-400.0, 1000.0)); + expect(childParentData.layoutOffset, const Offset(1000.0, 1000.0)); + + // - both reverse + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + horizontalDetails: const ScrollableDetails.horizontal(reverse: true), + verticalDetails: const ScrollableDetails.vertical(reverse: true), + )); + await tester.pumpAndSettle(); + + viewport = getViewport(tester, childKeys.values.first); + + childParentData = parentDataOf(viewport.firstChild!); + expect(childParentData.vicinity, const ChildVicinity(xIndex: 0, yIndex: 0)); + expect(childParentData.isVisible, isTrue); + expect(childParentData.paintOffset, const Offset(600.0, 400.0)); + expect(childParentData.layoutOffset, Offset.zero); + // The last child is in the cache extent, and should not be visible. + childParentData = parentDataOf(viewport.lastChild!); + expect(childParentData.vicinity, const ChildVicinity(xIndex: 5, yIndex: 5)); + expect(childParentData.isVisible, isFalse); + expect(childParentData.paintOffset, const Offset(-400.0, -600.0)); + expect(childParentData.layoutOffset, const Offset(1000.0, 1000.0)); + + // Change the scroll positions to test partially visible. + final ScrollController verticalController = ScrollController(); + addTearDown(verticalController.dispose); + final ScrollController horizontalController = ScrollController(); + addTearDown(horizontalController.dispose); + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), + verticalDetails: ScrollableDetails.vertical(controller: verticalController), + )); + await tester.pumpAndSettle(); + verticalController.jumpTo(50.0); + horizontalController.jumpTo(50.0); + await tester.pump(); + + viewport = getViewport(tester, childKeys.values.first); + + childParentData = parentDataOf(viewport.firstChild!); + expect(childParentData.vicinity, const ChildVicinity(xIndex: 0, yIndex: 0)); + expect(childParentData.isVisible, isTrue); + expect(childParentData.paintOffset, const Offset(-50.0, -50.0)); + expect(childParentData.layoutOffset, const Offset(-50.0, -50.0)); + }, variant: TargetPlatformVariant.all()); + + testWidgets('debugDescribeChildren', (WidgetTester tester) async { + final Map<ChildVicinity, UniqueKey> childKeys = <ChildVicinity, UniqueKey>{}; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + childKeys[vicinity] = childKeys[vicinity] ?? UniqueKey(); + return SizedBox.square(key: childKeys[vicinity], dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + + final RenderTwoDimensionalViewport viewport = getViewport( + tester, + childKeys.values.first, + ); + final List<DiagnosticsNode> result = viewport.debugDescribeChildren(); + expect(result.length, 20); + expect( + result.first.toString(), + equalsIgnoringHashCodes('(xIndex: 0, yIndex: 0): RenderRepaintBoundary#00000'), + ); + expect( + result.last.toString(), + equalsIgnoringHashCodes('(xIndex: 4, yIndex: 3): RenderRepaintBoundary#00000 NEEDS-PAINT'), + ); + }, variant: TargetPlatformVariant.all()); + + testWidgets('asserts that both axes are bounded', (WidgetTester tester) async { + final List<Object> exceptions = <Object>[]; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + FlutterError.onError = (FlutterErrorDetails details) { + exceptions.add(details.exception); + }; + // Compose unbounded - vertical axis + await tester.pumpWidget(WidgetsApp( + color: const Color(0xFFFFFFFF), + builder: (BuildContext context, Widget? child) => Column( + children: <Widget>[ + SimpleBuilderTableView(delegate: builderDelegate) + ] + ), + )); + await tester.pumpAndSettle(); + FlutterError.onError = oldHandler; + expect(exceptions.isNotEmpty, isTrue); + expect((exceptions[0] as FlutterError).message, contains('unbounded')); + + exceptions.clear(); + FlutterError.onError = (FlutterErrorDetails details) { + exceptions.add(details.exception); + }; + // Compose unbounded - horizontal axis + await tester.pumpWidget(WidgetsApp( + color: const Color(0xFFFFFFFF), + builder: (BuildContext context, Widget? child) => Row( + children: <Widget>[ + SimpleBuilderTableView(delegate: builderDelegate) + ] + ), + )); + await tester.pumpAndSettle(); + FlutterError.onError = oldHandler; + expect(exceptions.isNotEmpty, isTrue); + expect((exceptions[0] as FlutterError).message, contains('unbounded')); + }, variant: TargetPlatformVariant.all()); + + testWidgets('computeDryLayout asserts axes are bounded', (WidgetTester tester) async { + final UniqueKey childKey = UniqueKey(); + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 0, + maxYIndex: 0, + builder: (BuildContext context, ChildVicinity vicinity) { + return SizedBox.square(key: childKey, dimension: 200); + } + ); + addTearDown(delegate.dispose); + + // Call computeDryLayout with unbounded constraints + await tester.pumpWidget(simpleBuilderTest(delegate: delegate)); + final RenderTwoDimensionalViewport viewport = getViewport( + tester, + childKey, + ); + expect( + () { + viewport.computeDryLayout(const BoxConstraints()); + }, + throwsA( + isA<FlutterError>().having( + (FlutterError error) => error.message, + 'error.message', + contains('unbounded'), + ), + ), + ); + }, variant: TargetPlatformVariant.all()); + + testWidgets('correctly resizes dimensions', (WidgetTester tester) async { + final UniqueKey childKey = UniqueKey(); + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 0, + maxYIndex: 0, + builder: (BuildContext context, ChildVicinity vicinity) { + return SizedBox.square(key: childKey, dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + RenderTwoDimensionalViewport viewport = getViewport( + tester, + childKey, + ); + expect(viewport.viewportDimension, const Size(800.0, 600.0)); + tester.view.physicalSize = const Size(300.0, 300.0); + tester.view.devicePixelRatio = 1; + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + viewport = getViewport(tester, childKey); + expect(viewport.viewportDimension, const Size(300.0, 300.0)); + tester.view.resetPhysicalSize(); + tester.view.resetDevicePixelRatio(); + }, variant: TargetPlatformVariant.all()); + + testWidgets('Rebuilds when delegate changes', (WidgetTester tester) async { + final UniqueKey firstChildKey = UniqueKey(); + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 0, + maxYIndex: 0, + addRepaintBoundaries: false, + builder: (BuildContext context, ChildVicinity vicinity) { + return SizedBox.square(key: firstChildKey, dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + RenderTwoDimensionalViewport viewport = getViewport(tester, firstChildKey); + expect(viewport.firstChild, tester.renderObject<RenderBox>(find.byKey(firstChildKey))); + // New delegate + final UniqueKey newChildKey = UniqueKey(); + final TwoDimensionalChildBuilderDelegate newDelegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 0, + maxYIndex: 0, + addRepaintBoundaries: false, + builder: (BuildContext context, ChildVicinity vicinity) { + return Container(key: newChildKey, height: 300, width: 300, color: const Color(0xFFFFFFFF)); + } + ); + addTearDown(() => newDelegate.dispose()); + + await tester.pumpWidget(simpleBuilderTest( + delegate: newDelegate, + )); + viewport = getViewport(tester, newChildKey); + expect(firstChildKey, isNot(newChildKey)); + expect(find.byKey(firstChildKey), findsNothing); + expect(find.byKey(newChildKey), findsOneWidget); + expect(viewport.firstChild, tester.renderObject<RenderBox>(find.byKey(newChildKey))); + }, variant: TargetPlatformVariant.all()); + + testWidgets('hitTestChildren', (WidgetTester tester) async { + final List<ChildVicinity> taps = <ChildVicinity>[]; + final Map<ChildVicinity, UniqueKey> childKeys = <ChildVicinity, UniqueKey>{}; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 19, + maxYIndex: 19, + builder: (BuildContext context, ChildVicinity vicinity) { + childKeys[vicinity] = childKeys[vicinity] ?? UniqueKey(); + return SizedBox.square( + dimension: 200, + child: Center( + child: FloatingActionButton( + key: childKeys[vicinity], + onPressed: () { + taps.add(vicinity); + }, + ), + ), + ); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + useCacheExtent: true, // Untappable children are rendered in the cache extent + )); + await tester.pumpAndSettle(); + // Regular orientation + // Offset at center of first child + await tester.tapAt(const Offset(100.0, 100.0)); + await tester.pump(); + expect(taps.contains(const ChildVicinity(xIndex: 0, yIndex: 0)), isTrue); + // Offset by child location + await tester.tap(find.byKey(childKeys[const ChildVicinity(xIndex: 2, yIndex: 2)]!)); + await tester.pump(); + expect(taps.contains(const ChildVicinity(xIndex: 2, yIndex: 2)), isTrue); + // Offset out of bounds + await tester.tap( + find.byKey(childKeys[const ChildVicinity(xIndex: 5, yIndex: 5)]!), + warnIfMissed: false, + ); + await tester.pump(); + expect(taps.contains(const ChildVicinity(xIndex: 5, yIndex: 5)), isFalse); + + // Reversed + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + verticalDetails: const ScrollableDetails.vertical(reverse: true), + horizontalDetails: const ScrollableDetails.horizontal(reverse: true), + useCacheExtent: true, // Untappable children are rendered in the cache extent + )); + await tester.pumpAndSettle(); + // Offset at center of first child + await tester.tapAt(const Offset(700.0, 500.0)); + await tester.pump(); + expect(taps.contains(const ChildVicinity(xIndex: 0, yIndex: 0)), isTrue); + // Offset by child location + await tester.tap(find.byKey(childKeys[const ChildVicinity(xIndex: 2, yIndex: 2)]!)); + await tester.pump(); + expect(taps.contains(const ChildVicinity(xIndex: 2, yIndex: 2)), isTrue); + // Offset out of bounds + await tester.tap( + find.byKey(childKeys[const ChildVicinity(xIndex: 5, yIndex: 5)]!), + warnIfMissed: false, + ); + await tester.pump(); + expect(taps.contains(const ChildVicinity(xIndex: 5, yIndex: 5)), isFalse); + }, variant: TargetPlatformVariant.all()); + + testWidgets('getChildFor', (WidgetTester tester) async { + final Map<ChildVicinity, UniqueKey> childKeys = <ChildVicinity, UniqueKey>{}; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + childKeys[vicinity] = childKeys[vicinity] ?? UniqueKey(); + return SizedBox.square(key: childKeys[vicinity], dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + + final RenderSimpleBuilderTableViewport viewport = getViewport( + tester, childKeys.values.first, + ) as RenderSimpleBuilderTableViewport; + // returns child + expect( + viewport.testGetChildFor(const ChildVicinity(xIndex: 0, yIndex: 0)), + isNotNull, + ); + expect( + viewport.testGetChildFor(const ChildVicinity(xIndex: 0, yIndex: 0)), + viewport.firstChild, + ); + + // returns null + expect( + viewport.testGetChildFor(const ChildVicinity(xIndex: 10, yIndex: 10)), + isNull, + ); + }, variant: TargetPlatformVariant.all()); + + testWidgets('asserts vicinity is valid when children are asked to build', (WidgetTester tester) async { + final Map<ChildVicinity, UniqueKey> childKeys = <ChildVicinity, UniqueKey>{}; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + childKeys[vicinity] = childKeys[vicinity] ?? UniqueKey(); + return SizedBox.square(key: childKeys[vicinity], dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + + final RenderTwoDimensionalViewport viewport = getViewport( + tester, + childKeys.values.first, + ); + expect( + () { + viewport.buildOrObtainChildFor(ChildVicinity.invalid); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('ChildVicinity.invalid'), + ), + ), + ); + }, variant: TargetPlatformVariant.all()); + + testWidgets('asserts that content dimensions have been applied', (WidgetTester tester) async { + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + return const SizedBox.square(dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + // Will cause the test implementation to not set dimensions + applyDimensions: false, + )); + final FlutterError error = tester.takeException() as FlutterError; + expect(error.message, contains('was not given content dimensions')); + }, variant: TargetPlatformVariant.all()); + + testWidgets('will not rebuild a child if it can be reused', (WidgetTester tester) async { + final List<ChildVicinity> builtChildren = <ChildVicinity>[]; + final ScrollController controller = ScrollController(); + addTearDown(controller.dispose); + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + builtChildren.add(vicinity); + return const SizedBox.square(dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + verticalDetails: ScrollableDetails.vertical(controller: controller), + )); + expect(controller.position.pixels, 0.0); + expect(builtChildren.length, 20); + expect(builtChildren[0], const ChildVicinity(xIndex: 0, yIndex: 0)); + builtChildren.clear(); + controller.jumpTo(1.0); // Move slightly to trigger another layout + await tester.pump(); + expect(controller.position.pixels, 1.0); + expect(builtChildren.length, 5); // Next row of children was built + // Children from the first layout pass were re-used, not rebuilt. + expect( + builtChildren.contains(const ChildVicinity(xIndex: 0, yIndex: 0)), + isFalse, + ); + }, variant: TargetPlatformVariant.all()); + + testWidgets('asserts the layoutOffset has been set by the subclass', (WidgetTester tester) async { + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + return const SizedBox.square(dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + // Will cause the test implementation to not set the layoutOffset of + // the parent data + setLayoutOffset: false, + )); + final AssertionError error = tester.takeException() as AssertionError; + expect(error.message, contains('was not provided a layoutOffset')); + }, variant: TargetPlatformVariant.all()); + + testWidgets('asserts the children have a size after layoutChildSequence', (WidgetTester tester) async { + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + return const SizedBox.square(dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + // Will cause the test implementation to not actually layout the + // children it asked for. + forgetToLayoutChild: true, + )); + final AssertionError error = tester.takeException() as AssertionError; + expect(error.toString(), contains('child.hasSize')); + }, variant: TargetPlatformVariant.all()); + + testWidgets('does not support intrinsics', (WidgetTester tester) async { + final Map<ChildVicinity, UniqueKey> childKeys = <ChildVicinity, UniqueKey>{}; + final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate( + maxXIndex: 5, + maxYIndex: 5, + builder: (BuildContext context, ChildVicinity vicinity) { + childKeys[vicinity] = childKeys[vicinity] ?? UniqueKey(); + return SizedBox.square(key: childKeys[vicinity], dimension: 200); + } + ); + addTearDown(delegate.dispose); + + await tester.pumpWidget(simpleBuilderTest( + delegate: delegate, + )); + await tester.pumpAndSettle(); + + final RenderTwoDimensionalViewport viewport = getViewport( + tester, + childKeys.values.first, + ); + expect( + () { + viewport.computeMinIntrinsicWidth(100); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('does not support returning intrinsic dimensions'), + ), + ), + ); + expect( + () { + viewport.computeMaxIntrinsicWidth(100); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('does not support returning intrinsic dimensions'), + ), + ), + ); + expect( + () { + viewport.computeMinIntrinsicHeight(100); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('does not support returning intrinsic dimensions'), + ), + ), + ); + expect( + () { + viewport.computeMaxIntrinsicHeight(100); + }, + throwsA( + isA<AssertionError>().having( + (AssertionError error) => error.toString(), + 'description', + contains('does not support returning intrinsic dimensions'), + ), + ), + ); + }, variant: TargetPlatformVariant.all()); + + group('showOnScreen & showInViewport', () { + Finder findKey(ChildVicinity vicinity) { + return find.byKey(ValueKey<ChildVicinity>(vicinity)); + } + + testWidgets('getOffsetToReveal', (WidgetTester tester) async { + await tester.pumpWidget(simpleBuilderTest(useCacheExtent: true)); + + RenderAbstractViewport viewport = tester.allRenderObjects.whereType<RenderAbstractViewport>().first; + final RevealedOffset verticalOffset = viewport.getOffsetToReveal( + tester.renderObject(findKey(const ChildVicinity(xIndex: 5, yIndex: 5))), + 1.0, + axis: Axis.vertical, + ); + final RevealedOffset horizontalOffset = viewport.getOffsetToReveal( + tester.renderObject(findKey(const ChildVicinity(xIndex: 5, yIndex: 5))), + 1.0, + axis: Axis.horizontal, + ); + expect(verticalOffset.offset, 600.0); + expect(verticalOffset.rect, const Rect.fromLTRB(1000.0, 400.0, 1200.0, 600.0)); + expect(horizontalOffset.offset, 400.0); + expect(horizontalOffset.rect, const Rect.fromLTRB(600.0, 1000.0, 800.0, 1200.0)); + + // default is to use mainAxis when axis is not provided, mainAxis + // defaults to Axis.vertical. + RevealedOffset defaultOffset = viewport.getOffsetToReveal( + tester.renderObject(findKey(const ChildVicinity(xIndex: 5, yIndex: 5))), + 1.0, + ); + expect(defaultOffset.offset, verticalOffset.offset); + expect(defaultOffset.rect, verticalOffset.rect); + + // mainAxis as Axis.horizontal + await tester.pumpWidget(simpleBuilderTest( + useCacheExtent: true, + mainAxis: Axis.horizontal, + )); + viewport = tester.allRenderObjects.whereType<RenderAbstractViewport>().first; + defaultOffset = viewport.getOffsetToReveal( + tester.renderObject(findKey(const ChildVicinity(xIndex: 5, yIndex: 5))), + 1.0, + ); + expect(defaultOffset.offset, horizontalOffset.offset); + expect(defaultOffset.rect, horizontalOffset.rect); + }); + + testWidgets('Axis.vertical', (WidgetTester tester) async { + await tester.pumpWidget(simpleBuilderTest(useCacheExtent: true)); + // Child visible at origin + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 0))).dy, + equals(0.0), + ); + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 0, yIndex: 0)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 0))).dy, + equals(0.0), + ); + // (0, 3) is in the cache extent, and will be brought into view next + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 3))).dy, + equals(600.0), + ); + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 0, yIndex: 3)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + // Now in view + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 3))).dy, + equals(400.0), + ); + + // If already visible, no change + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 0, yIndex: 3)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 3))).dy, + equals(400.0), + ); + }); + + testWidgets('Axis.horizontal', (WidgetTester tester) async { + await tester.pumpWidget(simpleBuilderTest(useCacheExtent: true)); + + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 1, yIndex: 0)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 1, yIndex: 0))).dx, + equals(200.0), // No change since already fully visible + ); + // (5, 0) is now in the cache extent, and will be brought into view next + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 5, yIndex: 0))).dx, + equals(1000.0), + ); + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 5, yIndex: 0)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + // Now in view + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 5, yIndex: 0))).dx, + equals(600.0), + ); + + // If already in position, no change + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 5, yIndex: 0)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 5, yIndex: 0))).dx, + equals(600.0), + ); + }); + + testWidgets('both axes', (WidgetTester tester) async { + await tester.pumpWidget(simpleBuilderTest(useCacheExtent: true)); + + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 1, yIndex: 1)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getRect(findKey(const ChildVicinity(xIndex: 1, yIndex: 1))), + const Rect.fromLTRB(200.0, 200.0, 400.0, 400.0), + ); + // (5, 4) is in the cache extent, and will be brought into view next + expect( + tester.getRect(findKey(const ChildVicinity(xIndex: 5, yIndex: 4))), + const Rect.fromLTRB(1000.0, 800.0, 1200.0, 1000.0), + ); + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 5, yIndex: 4)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + // Now in view + expect( + tester.getRect(findKey(const ChildVicinity(xIndex: 5, yIndex: 4))), + const Rect.fromLTRB(600.0, 200.0, 800.0, 400.0), + ); + + // If already visible, no change + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 5, yIndex: 4)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getRect(findKey(const ChildVicinity(xIndex: 5, yIndex: 4))), + const Rect.fromLTRB(600.0, 200.0, 800.0, 400.0), + ); + }); + + testWidgets('Axis.vertical reverse', (WidgetTester tester) async { + await tester.pumpWidget(simpleBuilderTest( + verticalDetails: const ScrollableDetails.vertical(reverse: true), + useCacheExtent: true, + )); + + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 0))).dy, + equals(400.0), + ); + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 0, yIndex: 0)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + // Already visible so no change. + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 0))).dy, + equals(400.0), + ); + // (0, 3) is in the cache extent, and will be brought into view next + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 3))).dy, + equals(-200.0), + ); + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 0, yIndex: 3)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + // Now in view + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 3))).dy, + equals(0.0), + ); + + // If already visible, no change + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 0, yIndex: 3)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 3))).dy, + equals(0.0), + ); + }); + + testWidgets('Axis.horizontal reverse', (WidgetTester tester) async { + await tester.pumpWidget(simpleBuilderTest( + horizontalDetails: const ScrollableDetails.horizontal(reverse: true), + useCacheExtent: true, + )); + + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 0))).dx, + equals(600.0), + ); + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 0, yIndex: 0)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + // Already visible so no change. + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 0, yIndex: 0))).dx, + equals(600.0), + ); + // (4, 0) is in the cache extent, and will be brought into view next + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 4, yIndex: 0))).dx, + equals(-200.0), + ); + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 4, yIndex: 0)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 4, yIndex: 0))).dx, + equals(0.0), + ); + + // If already visible, no change + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 4, yIndex: 0)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getTopLeft(findKey(const ChildVicinity(xIndex: 4, yIndex: 0))).dx, + equals(0.0), + ); + }); + + testWidgets('both axes reverse', (WidgetTester tester) async { + await tester.pumpWidget(simpleBuilderTest( + verticalDetails: const ScrollableDetails.vertical(reverse: true), + horizontalDetails: const ScrollableDetails.horizontal(reverse: true), + useCacheExtent: true, + )); + + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 1, yIndex: 1)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getRect(findKey(const ChildVicinity(xIndex: 1, yIndex: 1))), + const Rect.fromLTRB(400.0, 200.0, 600.0, 400.0), + ); + // (5, 4) is in the cache extent, and will be brought into view next + expect( + tester.getRect(findKey(const ChildVicinity(xIndex: 5, yIndex: 4))), + const Rect.fromLTRB(-400.0, -400.0, -200.0, -200.0), + ); + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 5, yIndex: 4)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + // Now in view + expect( + tester.getRect(findKey(const ChildVicinity(xIndex: 5, yIndex: 4))), + const Rect.fromLTRB(0.0, 200.0, 200.0, 400.0), + ); + + // If already visible, no change + tester.renderObject(find.byKey( + const ValueKey<ChildVicinity>(ChildVicinity(xIndex: 5, yIndex: 4)), + skipOffstage: false, + )).showOnScreen(); + await tester.pump(); + expect( + tester.getRect(findKey(const ChildVicinity(xIndex: 5, yIndex: 4))), + const Rect.fromLTRB(0.0, 200.0, 200.0, 400.0), + ); + }); + }); + }); +} + +RenderTwoDimensionalViewport getViewport(WidgetTester tester, Key childKey) { + return RenderAbstractViewport.of( + tester.renderObject(find.byKey(childKey)) + ) as RenderSimpleBuilderTableViewport; +} + +class _NullBuildContext implements BuildContext, TwoDimensionalChildManager { + @override + dynamic noSuchMethod(Invocation invocation) => throw UnimplementedError(); +} + +Future<void> restoreScrollAndVerify(WidgetTester tester) async { + final Finder findScrollable = find.byElementPredicate((Element e) => e.widget is TwoDimensionalScrollable); + + tester.state<TwoDimensionalScrollableState>(findScrollable).horizontalScrollable.position.jumpTo(100); + tester.state<TwoDimensionalScrollableState>(findScrollable).verticalScrollable.position.jumpTo(100); + await tester.pump(); + await tester.restartAndRestore(); + + expect( + tester.state<TwoDimensionalScrollableState>(findScrollable).horizontalScrollable.position.pixels, + 100.0, + ); + expect( + tester.state<TwoDimensionalScrollableState>(findScrollable).verticalScrollable.position.pixels, + 100.0, + ); + + final TestRestorationData data = await tester.getRestorationData(); + tester.state<TwoDimensionalScrollableState>(findScrollable).horizontalScrollable.position.jumpTo(0); + tester.state<TwoDimensionalScrollableState>(findScrollable).verticalScrollable.position.jumpTo(0); + await tester.pump(); + await tester.restoreFrom(data); + + expect( + tester.state<TwoDimensionalScrollableState>(findScrollable).horizontalScrollable.position.pixels, + 100.0, + ); + expect( + tester.state<TwoDimensionalScrollableState>(findScrollable).verticalScrollable.position.pixels, + 100.0, + ); +} + +// Validates covariant through analysis. +mixin _SomeDelegateMixin on TwoDimensionalChildDelegate {} + +class _SomeRenderTwoDimensionalViewport extends RenderTwoDimensionalViewport { // ignore: unused_element + _SomeRenderTwoDimensionalViewport({ + required super.horizontalOffset, + required super.horizontalAxisDirection, + required super.verticalOffset, + required super.verticalAxisDirection, + required _SomeDelegateMixin super.delegate, + required super.mainAxis, + required super.childManager, + }); + + @override + _SomeDelegateMixin get delegate => super.delegate as _SomeDelegateMixin; + @override + set delegate(_SomeDelegateMixin value) { // Analysis would fail without covariant + super.delegate = value; + } + + @override + void layoutChildSequence() {} +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/undo_history_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/undo_history_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..6cbb3a377c1c9fb627683cd18aaa615319031263 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/undo_history_test.dart @@ -0,0 +1,540 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'editable_text_utils.dart'; + +final FocusNode _focusNode = FocusNode(debugLabel: 'UndoHistory Node'); + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('UndoHistory', () { + Future<void> sendUndoRedo(WidgetTester tester, [bool redo = false]) { + return sendKeys( + tester, + <LogicalKeyboardKey>[ + LogicalKeyboardKey.keyZ, + ], + shortcutModifier: true, + shift: redo, + targetPlatform: defaultTargetPlatform, + ); + } + + Future<void> sendUndo(WidgetTester tester) => sendUndoRedo(tester); + Future<void> sendRedo(WidgetTester tester) => sendUndoRedo(tester, true); + + testWidgets('allows undo and redo to be called programmatically from the UndoHistoryController', (WidgetTester tester) async { + final ValueNotifier<int> value = ValueNotifier<int>(0); + addTearDown(value.dispose); + final UndoHistoryController controller = UndoHistoryController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: UndoHistory<int>( + value: value, + controller: controller, + onTriggered: (int newValue) { + value.value = newValue; + }, + focusNode: _focusNode, + child: Container(), + ), + ), + ); + + await tester.pump(const Duration(milliseconds: 500)); + + // Undo/redo have no effect if the value has never changed. + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, false); + controller.undo(); + expect(value.value, 0); + controller.redo(); + expect(value.value, 0); + + _focusNode.requestFocus(); + await tester.pump(); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, false); + controller.undo(); + expect(value.value, 0); + controller.redo(); + expect(value.value, 0); + + value.value = 1; + + // Wait for the throttling. + await tester.pump(const Duration(milliseconds: 500)); + + // Can undo/redo a single change. + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + controller.undo(); + expect(value.value, 0); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, true); + controller.redo(); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + + value.value = 2; + await tester.pump(const Duration(milliseconds: 500)); + + // And can undo/redo multiple changes. + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + controller.undo(); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, true); + controller.undo(); + expect(value.value, 0); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, true); + controller.redo(); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, true); + controller.redo(); + expect(value.value, 2); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + + // Changing the value again clears the redo stack. + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + controller.undo(); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, true); + value.value = 3; + await tester.pump(const Duration(milliseconds: 500)); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + }, variant: TargetPlatformVariant.all()); + + testWidgets('allows undo and redo to be called using the keyboard', (WidgetTester tester) async { + final ValueNotifier<int> value = ValueNotifier<int>(0); + addTearDown(value.dispose); + final UndoHistoryController controller = UndoHistoryController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: UndoHistory<int>( + controller: controller, + value: value, + onTriggered: (int newValue) { + value.value = newValue; + }, + focusNode: _focusNode, + child: Focus( + focusNode: _focusNode, + child: Container(), + ), + ), + ), + ); + + await tester.pump(const Duration(milliseconds: 500)); + + // Undo/redo have no effect if the value has never changed. + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, false); + await sendUndo(tester); + expect(value.value, 0); + await sendRedo(tester); + expect(value.value, 0); + + _focusNode.requestFocus(); + await tester.pump(); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, false); + await sendUndo(tester); + expect(value.value, 0); + await sendRedo(tester); + expect(value.value, 0); + + value.value = 1; + + // Wait for the throttling. + await tester.pump(const Duration(milliseconds: 500)); + + // Can undo/redo a single change. + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + await sendUndo(tester); + expect(value.value, 0); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, true); + await sendRedo(tester); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + + value.value = 2; + await tester.pump(const Duration(milliseconds: 500)); + + // And can undo/redo multiple changes. + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + await sendUndo(tester); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, true); + await sendUndo(tester); + expect(value.value, 0); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, true); + await sendRedo(tester); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, true); + await sendRedo(tester); + expect(value.value, 2); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + + // Changing the value again clears the redo stack. + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + await sendUndo(tester); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, true); + value.value = 3; + await tester.pump(const Duration(milliseconds: 500)); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + }, variant: TargetPlatformVariant.all(), skip: kIsWeb); // [intended] + + testWidgets('duplicate changes do not affect the undo history', (WidgetTester tester) async { + final ValueNotifier<int> value = ValueNotifier<int>(0); + addTearDown(value.dispose); + final UndoHistoryController controller = UndoHistoryController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: UndoHistory<int>( + controller: controller, + value: value, + onTriggered: (int newValue) { + value.value = newValue; + }, + focusNode: _focusNode, + child: Container(), + ), + ), + ); + + _focusNode.requestFocus(); + + // Wait for the throttling. + await tester.pump(const Duration(milliseconds: 500)); + + value.value = 1; + + // Wait for the throttling. + await tester.pump(const Duration(milliseconds: 500)); + + // Can undo/redo a single change. + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + controller.undo(); + expect(value.value, 0); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, true); + controller.redo(); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + + // Changes that result in the same state won't be saved on the undo stack. + value.value = 1; + await tester.pump(const Duration(milliseconds: 500)); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + controller.undo(); + expect(value.value, 0); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, true); + }, variant: TargetPlatformVariant.all()); + + testWidgets('ignores value changes pushed during onTriggered', (WidgetTester tester) async { + final ValueNotifier<int> value = ValueNotifier<int>(0); + addTearDown(value.dispose); + final UndoHistoryController controller = UndoHistoryController(); + addTearDown(controller.dispose); + int Function(int newValue) valueToUse = (int value) => value; + final GlobalKey<UndoHistoryState<int>> key = GlobalKey<UndoHistoryState<int>>(); + + await tester.pumpWidget( + MaterialApp( + home: UndoHistory<int>( + key: key, + value: value, + controller: controller, + onTriggered: (int newValue) { + value.value = valueToUse(newValue); + }, + focusNode: _focusNode, + child: Container(), + ), + ), + ); + + await tester.pump(const Duration(milliseconds: 500)); + + // Undo/redo have no effect if the value has never changed. + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, false); + controller.undo(); + expect(value.value, 0); + controller.redo(); + expect(value.value, 0); + + _focusNode.requestFocus(); + await tester.pump(); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, false); + controller.undo(); + expect(value.value, 0); + controller.redo(); + expect(value.value, 0); + + value.value = 1; + + // Wait for the throttling. + await tester.pump(const Duration(milliseconds: 500)); + + valueToUse = (int value) => 3; + expect(() => key.currentState!.undo(), throwsAssertionError); + }, variant: TargetPlatformVariant.all()); + + testWidgets('changes should send setUndoState to the UndoManagerConnection on iOS', (WidgetTester tester) async { + final List<MethodCall> log = <MethodCall>[]; + tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.undoManager, (MethodCall methodCall) async { + log.add(methodCall); + return null; + }); + final FocusNode focusNode = FocusNode(); + addTearDown(focusNode.dispose); + + final ValueNotifier<int> value = ValueNotifier<int>(0); + addTearDown(value.dispose); + final UndoHistoryController controller = UndoHistoryController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: UndoHistory<int>( + controller: controller, + value: value, + onTriggered: (int newValue) { + value.value = newValue; + }, + focusNode: focusNode, + child: Focus( + focusNode: focusNode, + child: Container(), + ), + ), + ), + ); + + await tester.pump(); + + focusNode.requestFocus(); + await tester.pump(); + + // Wait for the throttling. + await tester.pump(const Duration(milliseconds: 500)); + + // Undo and redo should both be disabled. + MethodCall methodCall = log.lastWhere((MethodCall m) => m.method == 'UndoManager.setUndoState'); + expect(methodCall.method, 'UndoManager.setUndoState'); + expect(methodCall.arguments as Map<String, dynamic>, <String, bool>{'canUndo': false, 'canRedo': false}); + + // Making a change should enable undo. + value.value = 1; + await tester.pump(const Duration(milliseconds: 500)); + + methodCall = log.lastWhere((MethodCall m) => m.method == 'UndoManager.setUndoState'); + expect(methodCall.method, 'UndoManager.setUndoState'); + expect(methodCall.arguments as Map<String, dynamic>, <String, bool>{'canUndo': true, 'canRedo': false}); + + // Undo should remain enabled after another change. + value.value = 2; + await tester.pump(const Duration(milliseconds: 500)); + + methodCall = log.lastWhere((MethodCall m) => m.method == 'UndoManager.setUndoState'); + expect(methodCall.method, 'UndoManager.setUndoState'); + expect(methodCall.arguments as Map<String, dynamic>, <String, bool>{'canUndo': true, 'canRedo': false}); + + // Undo and redo should be enabled after one undo. + controller.undo(); + methodCall = log.lastWhere((MethodCall m) => m.method == 'UndoManager.setUndoState'); + expect(methodCall.method, 'UndoManager.setUndoState'); + expect(methodCall.arguments as Map<String, dynamic>, <String, bool>{'canUndo': true, 'canRedo': true}); + + // Only redo should be enabled after a second undo. + controller.undo(); + methodCall = log.lastWhere((MethodCall m) => m.method == 'UndoManager.setUndoState'); + expect(methodCall.method, 'UndoManager.setUndoState'); + expect(methodCall.arguments as Map<String, dynamic>, <String, bool>{'canUndo': false, 'canRedo': true}); + }, variant: const TargetPlatformVariant(<TargetPlatform>{TargetPlatform.iOS}), skip: kIsWeb); // [intended] + + testWidgets('handlePlatformUndo should undo or redo appropriately on iOS', (WidgetTester tester) async { + final ValueNotifier<int> value = ValueNotifier<int>(0); + addTearDown(value.dispose); + final UndoHistoryController controller = UndoHistoryController(); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: UndoHistory<int>( + controller: controller, + value: value, + onTriggered: (int newValue) { + value.value = newValue; + }, + focusNode: _focusNode, + child: Focus( + focusNode: _focusNode, + child: Container(), + ), + ), + ), + ); + + await tester.pump(const Duration(milliseconds: 500)); + _focusNode.requestFocus(); + await tester.pump(); + + // Undo/redo have no effect if the value has never changed. + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, false); + UndoManager.client!.handlePlatformUndo(UndoDirection.undo); + expect(value.value, 0); + UndoManager.client!.handlePlatformUndo(UndoDirection.redo); + expect(value.value, 0); + + value.value = 1; + + // Wait for the throttling. + await tester.pump(const Duration(milliseconds: 500)); + + // Can undo/redo a single change. + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + UndoManager.client!.handlePlatformUndo(UndoDirection.undo); + expect(value.value, 0); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, true); + UndoManager.client!.handlePlatformUndo(UndoDirection.redo); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + + value.value = 2; + await tester.pump(const Duration(milliseconds: 500)); + + // And can undo/redo multiple changes. + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + UndoManager.client!.handlePlatformUndo(UndoDirection.undo); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, true); + UndoManager.client!.handlePlatformUndo(UndoDirection.undo); + expect(value.value, 0); + expect(controller.value.canUndo, false); + expect(controller.value.canRedo, true); + UndoManager.client!.handlePlatformUndo(UndoDirection.redo); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, true); + UndoManager.client!.handlePlatformUndo(UndoDirection.redo); + expect(value.value, 2); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + + // Changing the value again clears the redo stack. + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + UndoManager.client!.handlePlatformUndo(UndoDirection.undo); + expect(value.value, 1); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, true); + value.value = 3; + await tester.pump(const Duration(milliseconds: 500)); + expect(controller.value.canUndo, true); + expect(controller.value.canRedo, false); + }, variant: const TargetPlatformVariant(<TargetPlatform>{TargetPlatform.iOS}), skip: kIsWeb); // [intended] + }); + + group('UndoHistoryController', () { + testWidgets('UndoHistoryController notifies onUndo listeners onUndo', (WidgetTester tester) async { + int calls = 0; + final UndoHistoryController controller = UndoHistoryController(); + addTearDown(controller.dispose); + controller.onUndo.addListener(() { + calls++; + }); + + // Does not notify the listener if canUndo is false. + controller.undo(); + expect(calls, 0); + + // Does notify the listener if canUndo is true. + controller.value = const UndoHistoryValue(canUndo: true); + controller.undo(); + expect(calls, 1); + }); + + testWidgets('UndoHistoryController notifies onRedo listeners onRedo', (WidgetTester tester) async { + int calls = 0; + final UndoHistoryController controller = UndoHistoryController(); + addTearDown(controller.dispose); + controller.onRedo.addListener(() { + calls++; + }); + + // Does not notify the listener if canUndo is false. + controller.redo(); + expect(calls, 0); + + // Does notify the listener if canRedo is true. + controller.value = const UndoHistoryValue(canRedo: true); + controller.redo(); + expect(calls, 1); + }); + + testWidgets('UndoHistoryController notifies listeners on value change', (WidgetTester tester) async { + int calls = 0; + final UndoHistoryController controller = UndoHistoryController(value: const UndoHistoryValue(canUndo: true)); + addTearDown(controller.dispose); + controller.addListener(() { + calls++; + }); + + // Does not notify if the value is the same. + controller.value = const UndoHistoryValue(canUndo: true); + expect(calls, 0); + + // Does notify if the value has changed. + controller.value = const UndoHistoryValue(canRedo: true); + expect(calls, 1); + }); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/unique_widget_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/unique_widget_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..be060bc0ee1bb4d4e6afc63c5727885580dfd862 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/unique_widget_test.dart @@ -0,0 +1,34 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class TestUniqueWidget extends UniqueWidget<TestUniqueWidgetState> { + const TestUniqueWidget({ required super.key }); + + @override + TestUniqueWidgetState createState() => TestUniqueWidgetState(); +} + +class TestUniqueWidgetState extends State<TestUniqueWidget> { + @override + Widget build(BuildContext context) => Container(); +} + +void main() { + testWidgets('Unique widget control test', (WidgetTester tester) async { + final TestUniqueWidget widget = TestUniqueWidget(key: GlobalKey<TestUniqueWidgetState>()); + + await tester.pumpWidget(widget); + + final TestUniqueWidgetState state = widget.currentState!; + + expect(state, isNotNull); + + await tester.pumpWidget(Container(child: widget)); + + expect(widget.currentState, equals(state)); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/value_listenable_builder_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/value_listenable_builder_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..3961a80ba1049cb381cff69f9f98b375ca9e348a --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/value_listenable_builder_test.dart @@ -0,0 +1,126 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + late SpyStringValueNotifier valueListenable; + late Widget textBuilderUnderTest; + + Widget builderForValueListenable( + ValueListenable<String?> valueListenable, + ) { + return Directionality( + textDirection: TextDirection.ltr, + child: ValueListenableBuilder<String?>( + valueListenable: valueListenable, + builder: (BuildContext context, String? value, Widget? child) { + if (value == null) { + return const Placeholder(); + } + return Text(value); + }, + ), + ); + } + + setUp(() { + valueListenable = SpyStringValueNotifier(null); + textBuilderUnderTest = builderForValueListenable(valueListenable); + }); + + tearDown(() { + valueListenable.dispose(); + }); + + testWidgets('Null value is ok', (WidgetTester tester) async { + await tester.pumpWidget(textBuilderUnderTest); + + expect(find.byType(Placeholder), findsOneWidget); + }); + + testWidgets('Widget builds with initial value', (WidgetTester tester) async { + final SpyStringValueNotifier valueListenable = SpyStringValueNotifier('Bachman'); + addTearDown(valueListenable.dispose); + + await tester.pumpWidget(builderForValueListenable(valueListenable)); + + expect(find.text('Bachman'), findsOneWidget); + }); + + testWidgets('Widget updates when value changes', (WidgetTester tester) async { + await tester.pumpWidget(textBuilderUnderTest); + + valueListenable.value = 'Gilfoyle'; + await tester.pump(); + expect(find.text('Gilfoyle'), findsOneWidget); + + valueListenable.value = 'Dinesh'; + await tester.pump(); + expect(find.text('Gilfoyle'), findsNothing); + expect(find.text('Dinesh'), findsOneWidget); + }); + + testWidgets('Can change listenable', (WidgetTester tester) async { + await tester.pumpWidget(textBuilderUnderTest); + + valueListenable.value = 'Gilfoyle'; + await tester.pump(); + expect(find.text('Gilfoyle'), findsOneWidget); + + final SpyStringValueNotifier differentListenable = SpyStringValueNotifier('Hendricks'); + addTearDown(differentListenable.dispose); + + await tester.pumpWidget(builderForValueListenable(differentListenable)); + + expect(find.text('Gilfoyle'), findsNothing); + expect(find.text('Hendricks'), findsOneWidget); + }); + + testWidgets('Stops listening to old listenable after changing listenable', (WidgetTester tester) async { + await tester.pumpWidget(textBuilderUnderTest); + + valueListenable.value = 'Gilfoyle'; + await tester.pump(); + expect(find.text('Gilfoyle'), findsOneWidget); + + final SpyStringValueNotifier differentListenable = SpyStringValueNotifier('Hendricks'); + addTearDown(differentListenable.dispose); + + await tester.pumpWidget(builderForValueListenable(differentListenable)); + + expect(find.text('Gilfoyle'), findsNothing); + expect(find.text('Hendricks'), findsOneWidget); + + // Change value of the (now) disconnected listenable. + valueListenable.value = 'Big Head'; + + expect(find.text('Gilfoyle'), findsNothing); + expect(find.text('Big Head'), findsNothing); + expect(find.text('Hendricks'), findsOneWidget); + }); + + testWidgets('Self-cleans when removed', (WidgetTester tester) async { + await tester.pumpWidget(textBuilderUnderTest); + + valueListenable.value = 'Gilfoyle'; + await tester.pump(); + expect(find.text('Gilfoyle'), findsOneWidget); + + await tester.pumpWidget(const Placeholder()); + + expect(find.text('Gilfoyle'), findsNothing); + expect(valueListenable.hasListeners, false); + }); +} + +class SpyStringValueNotifier extends ValueNotifier<String?> { + SpyStringValueNotifier(super.initialValue); + + /// Override for test visibility only. + @override + bool get hasListeners => super.hasListeners; +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/view_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/view_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..2177459d0b89cba87e6292aa953d839ed1998bb6 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/view_test.dart @@ -0,0 +1,494 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'multi_view_testing.dart'; + +void main() { + testWidgets('Widgets running with runApp can find View', (WidgetTester tester) async { + FlutterView? viewOf; + FlutterView? viewMaybeOf; + + runApp( + Builder( + builder: (BuildContext context) { + viewOf = View.of(context); + viewMaybeOf = View.maybeOf(context); + return Container(); + }, + ), + ); + + expect(viewOf, isNotNull); + expect(viewOf, isA<FlutterView>()); + expect(viewMaybeOf, isNotNull); + expect(viewMaybeOf, isA<FlutterView>()); + }); + + testWidgets('Widgets running with pumpWidget can find View', (WidgetTester tester) async { + FlutterView? view; + FlutterView? viewMaybeOf; + + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + view = View.of(context); + viewMaybeOf = View.maybeOf(context); + return Container(); + }, + ), + ); + + expect(view, isNotNull); + expect(view, isA<FlutterView>()); + expect(viewMaybeOf, isNotNull); + expect(viewMaybeOf, isA<FlutterView>()); + }); + + testWidgets('cannot find View behind a LookupBoundary', (WidgetTester tester) async { + await tester.pumpWidget( + LookupBoundary( + child: Container(), + ), + ); + + final BuildContext context = tester.element(find.byType(Container)); + + expect(View.maybeOf(context), isNull); + expect( + () => View.of(context), + throwsA(isA<FlutterError>().having( + (FlutterError error) => error.message, + 'message', + contains('The context provided to View.of() does have a View widget ancestor, but it is hidden by a LookupBoundary.'), + )), + ); + }); + + testWidgets('child of view finds view, parentPipelineOwner, mediaQuery', (WidgetTester tester) async { + FlutterView? outsideView; + FlutterView? insideView; + PipelineOwner? outsideParent; + PipelineOwner? insideParent; + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: Builder( + builder: (BuildContext context) { + outsideView = View.maybeOf(context); + outsideParent = View.pipelineOwnerOf(context); + return View( + view: tester.view, + child: Builder( + builder: (BuildContext context) { + insideView = View.maybeOf(context); + insideParent = View.pipelineOwnerOf(context); + return const SizedBox(); + }, + ), + ); + }, + ), + ); + expect(outsideView, isNull); + expect(insideView, equals(tester.view)); + + expect(outsideParent, isNotNull); + expect(insideParent, isNotNull); + expect(outsideParent, isNot(equals(insideParent))); + + expect(outsideParent, tester.binding.rootPipelineOwner); + expect(insideParent, equals(tester.renderObject(find.byType(SizedBox)).owner)); + + final List<PipelineOwner> pipelineOwners = <PipelineOwner> []; + tester.binding.rootPipelineOwner.visitChildren((PipelineOwner child) { + pipelineOwners.add(child); + }); + expect(pipelineOwners.single, equals(insideParent)); + }); + + testWidgets('cannot have multiple views with same FlutterView', (WidgetTester tester) async { + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + view: tester.view, + child: const SizedBox(), + ), + View( + view: tester.view, + child: const SizedBox(), + ), + ], + ), + ); + + expect( + tester.takeException(), + isFlutterError.having( + (FlutterError e) => e.message, + 'message', + contains('Multiple widgets used the same GlobalKey'), + ), + ); + }); + + testWidgets('ViewCollection may start with zero views', (WidgetTester tester) async { + expect(() => const ViewCollection(views: <Widget>[]), returnsNormally); + }); + + testWidgets('ViewAnchor.child does not see surrounding view', (WidgetTester tester) async { + FlutterView? inside; + FlutterView? outside; + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + outside = View.maybeOf(context); + return ViewAnchor( + view: Builder( + builder: (BuildContext context) { + inside = View.maybeOf(context); + return View(view: FakeView(tester.view), child: const SizedBox()); + }, + ), + child: const SizedBox(), + ); + }, + ), + ); + expect(inside, isNull); + expect(outside, isNotNull); + }); + + testWidgets('ViewAnchor layout order', (WidgetTester tester) async { + Finder findSpyWidget(int label) { + return find.byWidgetPredicate((Widget w) => w is SpyRenderWidget && w.label == label); + } + + final List<String> log = <String>[]; + await tester.pumpWidget( + SpyRenderWidget( + label: 1, + log: log, + child: ViewAnchor( + view: View( + view: FakeView(tester.view), + child: SpyRenderWidget(label: 2, log: log), + ), + child: SpyRenderWidget(label: 3, log: log), + ), + ), + ); + log.clear(); + tester.renderObject(findSpyWidget(3)).markNeedsLayout(); + tester.renderObject(findSpyWidget(2)).markNeedsLayout(); + tester.renderObject(findSpyWidget(1)).markNeedsLayout(); + await tester.pump(); + expect(log, <String>['layout 1', 'layout 3', 'layout 2']); + }); + + testWidgets('visitChildren of ViewAnchor visits both children', (WidgetTester tester) async { + await tester.pumpWidget( + ViewAnchor( + view: View( + view: FakeView(tester.view), + child: const ColoredBox(color: Colors.green), + ), + child: const SizedBox(), + ), + ); + final Element viewAnchorElement = tester.element(find.byElementPredicate((Element e) => e.runtimeType.toString() == '_MultiChildComponentElement')); + final List<Element> children = <Element>[]; + viewAnchorElement.visitChildren((Element element) { + children.add(element); + }); + expect(children, hasLength(2)); + + await tester.pumpWidget( + const ViewAnchor( + child: SizedBox(), + ), + ); + children.clear(); + viewAnchorElement.visitChildren((Element element) { + children.add(element); + }); + expect(children, hasLength(1)); + }); + + testWidgets('visitChildren of ViewCollection visits all children', (WidgetTester tester) async { + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + view: tester.view, + child: const SizedBox(), + ), + View( + view: FakeView(tester.view), + child: const SizedBox(), + ), + View( + view: FakeView(tester.view, viewId: 423), + child: const SizedBox(), + ), + ], + ), + ); + final Element viewAnchorElement = tester.element(find.byElementPredicate((Element e) => e.runtimeType.toString() == '_MultiChildComponentElement')); + final List<Element> children = <Element>[]; + viewAnchorElement.visitChildren((Element element) { + children.add(element); + }); + expect(children, hasLength(3)); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: ViewCollection( + views: <Widget>[ + View( + view: tester.view, + child: const SizedBox(), + ), + ], + ), + ); + children.clear(); + viewAnchorElement.visitChildren((Element element) { + children.add(element); + }); + expect(children, hasLength(1)); + }); + + group('renderObject getter', () { + testWidgets('ancestors of view see RenderView as renderObject', (WidgetTester tester) async { + late BuildContext builderContext; + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: Builder( + builder: (BuildContext context) { + builderContext = context; + return View( + view: tester.view, + child: const SizedBox(), + ); + }, + ), + ); + + final RenderObject? renderObject = builderContext.findRenderObject(); + expect(renderObject, isNotNull); + expect(renderObject, isA<RenderView>()); + expect(renderObject, tester.renderObject(find.byType(View))); + expect(tester.element(find.byType(Builder)).renderObject, renderObject); + }); + + testWidgets('ancestors of ViewCollection get null for renderObject', (WidgetTester tester) async { + late BuildContext builderContext; + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: Builder( + builder: (BuildContext context) { + builderContext = context; + return ViewCollection( + views: <Widget>[ + View( + view: tester.view, + child: const SizedBox(), + ), + View( + view: FakeView(tester.view), + child: const SizedBox(), + ), + ], + ); + }, + ), + ); + + final RenderObject? renderObject = builderContext.findRenderObject(); + expect(renderObject, isNull); + expect(tester.element(find.byType(Builder)).renderObject, isNull); + }); + + testWidgets('ancestors of a ViewAnchor see the right RenderObject', (WidgetTester tester) async { + late BuildContext builderContext; + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + builderContext = context; + return ViewAnchor( + view: View( + view: FakeView(tester.view), + child: const ColoredBox(color: Colors.green), + ), + child: const SizedBox(), + ); + }, + ), + ); + + final RenderObject? renderObject = builderContext.findRenderObject(); + expect(renderObject, isNotNull); + expect(renderObject, isA<RenderConstrainedBox>()); + expect(renderObject, tester.renderObject(find.byType(SizedBox))); + expect(tester.element(find.byType(Builder)).renderObject, renderObject); + }); + }); + + testWidgets('correctly switches between view configurations', (WidgetTester tester) async { + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: View( + view: tester.view, + deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner: tester.binding.pipelineOwner, + deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView: tester.binding.renderView, + child: const SizedBox(), + ), + ); + RenderObject renderView = tester.renderObject(find.byType(View)); + expect(renderView, same(tester.binding.renderView)); + expect(renderView.owner, same(tester.binding.pipelineOwner)); + expect(tester.renderObject(find.byType(SizedBox)).owner, same(tester.binding.pipelineOwner)); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: View( + view: tester.view, + child: const SizedBox(), + ), + ); + renderView = tester.renderObject(find.byType(View)); + expect(renderView, isNot(same(tester.binding.renderView))); + expect(renderView.owner, isNot(same(tester.binding.pipelineOwner))); + expect(tester.renderObject(find.byType(SizedBox)).owner, isNot(same(tester.binding.pipelineOwner))); + + await pumpWidgetWithoutViewWrapper( + tester: tester, + widget: View( + view: tester.view, + deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner: tester.binding.pipelineOwner, + deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView: tester.binding.renderView, + child: const SizedBox(), + ), + ); + renderView = tester.renderObject(find.byType(View)); + expect(renderView, same(tester.binding.renderView)); + expect(renderView.owner, same(tester.binding.pipelineOwner)); + expect(tester.renderObject(find.byType(SizedBox)).owner, same(tester.binding.pipelineOwner)); + + expect(() => View( + view: tester.view, + deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner: tester.binding.pipelineOwner, + child: const SizedBox(), + ), throwsAssertionError); + expect(() => View( + view: tester.view, + deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView: tester.binding.renderView, + child: const SizedBox(), + ), throwsAssertionError); + expect(() => View( + view: FakeView(tester.view), + deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView: tester.binding.renderView, + deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner: tester.binding.pipelineOwner, + child: const SizedBox(), + ), throwsAssertionError); + }); + + testWidgets('attaches itself correctly', (WidgetTester tester) async { + final Key viewKey = UniqueKey(); + late final PipelineOwner parentPipelineOwner; + await tester.pumpWidget( + ViewAnchor( + view: Builder( + builder: (BuildContext context) { + parentPipelineOwner = View.pipelineOwnerOf(context); + return View( + key: viewKey, + view: FakeView(tester.view), + child: const SizedBox(), + ); + }, + ), + child: const ColoredBox(color: Colors.green), + ), + ); + + expect(parentPipelineOwner, isNot(RendererBinding.instance.rootPipelineOwner)); + + final RenderView rawView = tester.renderObject<RenderView>(find.byKey(viewKey)); + expect(RendererBinding.instance.renderViews, contains(rawView)); + + final List<PipelineOwner> children = <PipelineOwner>[]; + parentPipelineOwner.visitChildren((PipelineOwner child) { + children.add(child); + }); + final PipelineOwner rawViewOwner = rawView.owner!; + expect(children, contains(rawViewOwner)); + + // Remove that View from the tree. + await tester.pumpWidget( + const ViewAnchor( + child: ColoredBox(color: Colors.green), + ), + ); + + expect(rawView.owner, isNull); + expect(RendererBinding.instance.renderViews, isNot(contains(rawView))); + children.clear(); + parentPipelineOwner.visitChildren((PipelineOwner child) { + children.add(child); + }); + expect(children, isNot(contains(rawViewOwner))); + }); +} + +Future<void> pumpWidgetWithoutViewWrapper({required WidgetTester tester, required Widget widget}) { + tester.binding.attachRootWidget(widget); + tester.binding.scheduleFrame(); + return tester.binding.pump(); +} + +class SpyRenderWidget extends SizedBox { + const SpyRenderWidget({super.key, required this.label, required this.log, super.child}); + + final int label; + final List<String> log; + + @override + RenderSpy createRenderObject(BuildContext context) { + return RenderSpy( + additionalConstraints: const BoxConstraints(), + label: label, + log: log, + ); + } + + @override + void updateRenderObject(BuildContext context, RenderSpy renderObject) { + renderObject + ..label = label + ..log = log; + } +} + +class RenderSpy extends RenderConstrainedBox { + RenderSpy({required super.additionalConstraints, required this.label, required this.log}); + + int label; + List<String> log; + + @override + void performLayout() { + log.add('layout $label'); + super.performLayout(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/visibility_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/visibility_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..cd11376111d50103ba92025ac2b5a8f8edff8715 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/visibility_test.dart @@ -0,0 +1,591 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'semantics_tester.dart'; + +class TestState extends StatefulWidget { + const TestState({ super.key, required this.child, required this.log }); + final Widget child; + final List<String> log; + @override + State<TestState> createState() => _TestStateState(); +} + +class _TestStateState extends State<TestState> { + @override + void initState() { + super.initState(); + widget.log.add('created new state'); + } + @override + Widget build(BuildContext context) { + return widget.child; + } +} + +void main() { + testWidgets('Visibility', (WidgetTester tester) async { + final SemanticsTester semantics = SemanticsTester(tester); + final List<String> log = <String>[]; + + final Widget testChild = GestureDetector( + onTap: () { log.add('tap'); }, + child: Builder( + builder: (BuildContext context) { + final bool animating = TickerMode.of(context); + return TestState( + log: log, + child: Text('a $animating', textDirection: TextDirection.rtl), + ); + }, + ), + ); + + final Matcher expectedSemanticsWhenPresent = hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics.rootChild( + label: 'a true', + textDirection: TextDirection.rtl, + actions: <SemanticsAction>[SemanticsAction.tap], + ), + ], + ), + ignoreId: true, + ignoreRect: true, + ignoreTransform: true, + ); + + final Matcher expectedSemanticsWhenPresentWithIgnorePointer = hasSemantics( + TestSemantics.root( + children: <TestSemantics>[ + TestSemantics.rootChild( + label: 'a true', + textDirection: TextDirection.rtl, + ), + ], + ), + ignoreId: true, + ignoreRect: true, + ignoreTransform: true, + ); + + final Matcher expectedSemanticsWhenAbsent = hasSemantics(TestSemantics.root()); + + // We now run a sequence of pumpWidget calls one after the other. In + // addition to verifying that the right behavior is seen in each case, this + // also verifies that the widget can dynamically change from state to state. + + await tester.pumpWidget(Visibility(child: testChild)); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Visibility), paints..paragraph()); + expect(tester.getSize(find.byType(Visibility)), const Size(800.0, 600.0)); + expect(semantics, expectedSemanticsWhenPresent); + expect(log, <String>['created new state']); + await tester.tap(find.byType(Visibility)); + expect(log, <String>['created new state', 'tap']); + log.clear(); + + await tester.pumpWidget(Visibility(visible: false, child: testChild)); + expect(find.byType(Text, skipOffstage: false), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), const Size(800.0, 600.0)); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsNothing); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), Size.zero); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + replacement: const Placeholder(), + visible: false, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsNothing); + expect(find.byType(Placeholder), findsOneWidget); + expect(find.byType(Visibility), paints..path()); + expect(tester.getSize(find.byType(Visibility)), const Size(800.0, 600.0)); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + replacement: const Placeholder(), + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paints..paragraph()); + expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); + expect(semantics, expectedSemanticsWhenPresent); + expect(log, <String>['created new state']); + await tester.tap(find.byType(Visibility)); + expect(log, <String>['created new state', 'tap']); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + maintainState: true, + maintainAnimation: true, + maintainSize: true, + maintainInteractivity: true, + maintainSemantics: true, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paints..paragraph()); + expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); + expect(semantics, expectedSemanticsWhenPresent); + expect(log, <String>['created new state']); + await tester.tap(find.byType(Visibility)); + expect(log, <String>['created new state', 'tap']); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + maintainState: true, + maintainAnimation: true, + maintainSize: true, + maintainInteractivity: true, + maintainSemantics: true, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); + expect(semantics, expectedSemanticsWhenPresent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility)); + expect(log, <String>['tap']); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + maintainState: true, + maintainAnimation: true, + maintainSize: true, + maintainInteractivity: true, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility)); + expect(log, <String>['tap']); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + maintainState: true, + maintainAnimation: true, + maintainSize: true, + maintainSemantics: true, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); + expect(semantics, expectedSemanticsWhenPresentWithIgnorePointer); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + maintainState: true, + maintainAnimation: true, + maintainSize: true, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + maintainState: true, + maintainAnimation: true, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.byType(Text), findsNothing); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), Size.zero); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>['created new state']); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>['created new state']); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + maintainState: true, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.byType(Text), findsNothing); + expect(find.text('a false', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), Size.zero); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>['created new state']); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>['created new state']); + log.clear(); + + // Now we toggle the visibility off and on a few times to make sure that works. + + await tester.pumpWidget(Center( + child: Visibility( + maintainState: true, + child: testChild, + ), + )); + expect(find.byType(Text), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paints..paragraph()); + expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); + expect(semantics, expectedSemanticsWhenPresent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>['tap']); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + maintainState: true, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.byType(Text), findsNothing); + expect(find.text('a false', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), Size.zero); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + maintainState: true, + child: testChild, + ), + )); + expect(find.byType(Text), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paints..paragraph()); + expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); + expect(semantics, expectedSemanticsWhenPresent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility)); + expect(log, <String>['tap']); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + maintainState: true, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsOneWidget); + expect(find.byType(Text), findsNothing); + expect(find.text('a false', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), Size.zero); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + // Same but without maintainState. + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsNothing); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), Size.zero); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + child: testChild, + ), + )); + expect(find.byType(Text), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paints..paragraph()); + expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); + expect(semantics, expectedSemanticsWhenPresent); + expect(log, <String>['created new state']); + await tester.tap(find.byType(Visibility)); + expect(log, <String>['created new state', 'tap']); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + visible: false, + child: testChild, + ), + )); + expect(find.byType(Text, skipOffstage: false), findsNothing); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paintsNothing); + expect(tester.getSize(find.byType(Visibility)), Size.zero); + expect(semantics, expectedSemanticsWhenAbsent); + expect(log, <String>[]); + await tester.tap(find.byType(Visibility), warnIfMissed: false); + expect(log, <String>[]); + log.clear(); + + await tester.pumpWidget(Center( + child: Visibility( + child: testChild, + ), + )); + expect(find.byType(Text), findsOneWidget); + expect(find.text('a true', skipOffstage: false), findsOneWidget); + expect(find.byType(Placeholder), findsNothing); + expect(find.byType(Visibility), paints..paragraph()); + expect(tester.getSize(find.byType(Visibility)), const Size(84.0, 14.0)); + expect(semantics, expectedSemanticsWhenPresent); + expect(log, <String>['created new state']); + await tester.tap(find.byType(Visibility)); + expect(log, <String>['created new state', 'tap']); + log.clear(); + + semantics.dispose(); + }); + + testWidgets('Visibility does not force compositing when visible and maintain*', (WidgetTester tester) async { + await tester.pumpWidget( + const Visibility( + maintainSize: true, + maintainAnimation: true, + maintainState: true, + child: Text('hello', textDirection: TextDirection.ltr), + ), + ); + + // Root transform from the tester and then the picture created by the text. + expect(tester.layers, hasLength(2)); + expect(tester.layers, isNot(contains(isA<OpacityLayer>()))); + expect(tester.layers.last, isA<PictureLayer>()); + }); + + testWidgets('SliverVisibility does not force compositing when visible and maintain*', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: CustomScrollView( + slivers: <Widget>[ + SliverVisibility( + maintainSize: true, + maintainAnimation: true, + maintainState: true, + sliver: SliverList( + delegate: SliverChildListDelegate.fixed( + addRepaintBoundaries: false, + <Widget>[ + Text('hello'), + ], + ), + )) + ] + ), + ), + ); + + // This requires a lot more layers due to including sliver lists which do manage additional + // offset layers. Just trust me this is one fewer layers than before... + expect(tester.layers, hasLength(6)); + expect(tester.layers, isNot(contains(isA<OpacityLayer>()))); + expect(tester.layers.last, isA<PictureLayer>()); + }); + + testWidgets('Visibility.of returns correct value', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: _ShowVisibility(), + ), + ); + expect(find.text('is visible ? true', skipOffstage: false), findsOneWidget); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Visibility( + maintainState: true, + child: _ShowVisibility(), + ), + ), + ); + expect(find.text('is visible ? true', skipOffstage: false), findsOneWidget); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Visibility( + visible: false, + maintainState: true, + child: _ShowVisibility(), + ), + ), + ); + expect(find.text('is visible ? false', skipOffstage: false), findsOneWidget); + }); + + testWidgets('Visibility.of works when multiple Visibility widgets are in hierarchy', (WidgetTester tester) async { + bool didChangeDependencies = false; + void handleDidChangeDependencies() { + didChangeDependencies = true; + } + + Widget newWidget({required bool ancestorIsVisible, required bool descendantIsVisible}) { + return Directionality( + textDirection: TextDirection.ltr, + child: Visibility( + visible: ancestorIsVisible, + maintainState: true, + child: Center( + child: Visibility( + visible: descendantIsVisible, + maintainState: true, + child: _ShowVisibility( + onDidChangeDependencies: handleDidChangeDependencies, + ), + ), + ), + ), + ); + } + + await tester.pumpWidget(newWidget(ancestorIsVisible: true, descendantIsVisible: true)); + expect(didChangeDependencies, isTrue); + expect(find.text('is visible ? true', skipOffstage: false), findsOneWidget); + didChangeDependencies = false; + + await tester.pumpWidget(newWidget(ancestorIsVisible: true, descendantIsVisible: false)); + expect(didChangeDependencies, isTrue); + expect(find.text('is visible ? false', skipOffstage: false), findsOneWidget); + didChangeDependencies = false; + + await tester.pumpWidget(newWidget(ancestorIsVisible: true, descendantIsVisible: false)); + expect(didChangeDependencies, isFalse); + + await tester.pumpWidget(newWidget(ancestorIsVisible: false, descendantIsVisible: false)); + expect(didChangeDependencies, isTrue); + didChangeDependencies = false; + + await tester.pumpWidget(newWidget(ancestorIsVisible: false, descendantIsVisible: true)); + expect(didChangeDependencies, isTrue); + expect(find.text('is visible ? false', skipOffstage: false), findsOneWidget); + }); +} + +class _ShowVisibility extends StatefulWidget { + const _ShowVisibility({this.onDidChangeDependencies}); + + final VoidCallback? onDidChangeDependencies; + + @override + State<_ShowVisibility> createState() => _ShowVisibilityState(); +} + +class _ShowVisibilityState extends State<_ShowVisibility> { + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (widget.onDidChangeDependencies != null) { + widget.onDidChangeDependencies!(); + } + } + + @override + Widget build(BuildContext context) { + return Text('is visible ? ${Visibility.of(context)}'); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_inspector_structure_error_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_inspector_structure_error_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..0c08631d2c591422a25b7e083b6d485cb27498af --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_inspector_structure_error_test.dart @@ -0,0 +1,89 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'widget_inspector_test_utils.dart'; + +void main() { + StructureErrorTestWidgetInspectorService.runTests(); +} + +class StructureErrorTestWidgetInspectorService extends TestWidgetInspectorService { + static void runTests() { + final StructureErrorTestWidgetInspectorService service = StructureErrorTestWidgetInspectorService(); + WidgetInspectorService.instance = service; + + test('ext.flutter.inspector.structuredErrors - custom FlutterError.onError', () async { + // Regression test for https://github.com/flutter/flutter/issues/41540 + + // Ensures that + // * structured errors are enabled by default + // * FlutterError.onError without FlutterError.presentError doesn't present structured errors + // * FlutterError.onError with FlutterError.presentError does present structured errors + // * disabling structured errors sets the default FlutterError.presentError + + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + + try { + expect(service.dispatchedEvents('Flutter.Error'), isEmpty); + + // Set callback that doesn't call presentError. + bool onErrorCalled = false; + FlutterError.onError = (FlutterErrorDetails details) { + onErrorCalled = true; + }; + + // Get the service registered. + WidgetsFlutterBinding.ensureInitialized(); + + final FlutterErrorDetails expectedError = FlutterErrorDetails( + library: 'rendering library', + context: ErrorDescription('during layout'), + exception: StackTrace.current, + ); + FlutterError.reportError(expectedError); + + // Verify structured errors are not shown. + expect(onErrorCalled, true); + expect(service.dispatchedEvents('Flutter.Error'), isEmpty); + + // Set callback that calls presentError. + onErrorCalled = false; + FlutterError.onError = (FlutterErrorDetails details) { + FlutterError.presentError(details); + onErrorCalled = true; + }; + + FlutterError.reportError(expectedError); + + // Verify structured errors are shown. + expect(onErrorCalled, true); + // Structured errors are not supported on web. + if (!kIsWeb) { + expect(service.dispatchedEvents('Flutter.Error'), hasLength(1)); + } else { + expect(service.dispatchedEvents('Flutter.Error'), isEmpty); + } + + // Verify disabling structured errors sets the default FlutterError.presentError + expect( + await service.testBoolExtension('structuredErrors', <String, String>{'enabled': 'true'}), + equals('true'), + ); + expect(FlutterError.presentError, isNot(equals(oldHandler))); + + expect( + await service.testBoolExtension('structuredErrors', <String, String>{'enabled': 'false'}), + equals('false'), + ); + expect(FlutterError.presentError, equals(oldHandler)); + } finally { + FlutterError.onError = oldHandler; + } + }); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_inspector_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_inspector_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..4902f310fe83a0f5635c801796e1cbef97111794 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_inspector_test.dart @@ -0,0 +1,5499 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// reduced-test-set: +// This file is run as part of a reduced test set in CI on Mac and Windows +// machines. +@Tags(<String>['reduced-test-set']) +@TestOn('!chrome') +library; + +import 'dart:convert'; +import 'dart:math'; +import 'dart:ui' as ui; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart' show DragStartBehavior; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker/leak_tracker.dart'; + +import 'widget_inspector_test_utils.dart'; + +// Start of block of code where widget creation location line numbers and +// columns will impact whether tests pass. + +class ClockDemo extends StatelessWidget { + const ClockDemo({ super.key }); + + @override + Widget build(BuildContext context) { + return Directionality( + textDirection: TextDirection.ltr, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: <Widget>[ + const Text('World Clock'), + makeClock('Local', DateTime.now().timeZoneOffset.inHours), + makeClock('UTC', 0), + makeClock('New York, NY', -4), + makeClock('Chicago, IL', -5), + makeClock('Denver, CO', -6), + makeClock('Los Angeles, CA', -7), + ], + ), + ); + } + + Widget makeClock(String label, int utcOffset) { + return Stack( + children: <Widget>[ + const Icon(Icons.watch), + Text(label), + ClockText(utcOffset: utcOffset), + ], + ); + } +} + +class ClockText extends StatefulWidget { + const ClockText({ + super.key, + this.utcOffset = 0, + }); + + final int utcOffset; + + @override + State<ClockText> createState() => _ClockTextState(); +} + +class _ClockTextState extends State<ClockText> { + DateTime? currentTime = DateTime.now(); + + void updateTime() { + setState(() { + currentTime = DateTime.now(); + }); + } + + void stopClock() { + setState(() { + currentTime = null; + }); + } + + @override + Widget build(BuildContext context) { + if (currentTime == null) { + return const Text('stopped'); + } + return Text( + currentTime! + .toUtc() + .add(Duration(hours: widget.utcOffset)) + .toIso8601String(), + ); + } +} + +// End of block of code where widget creation location line numbers and +// columns will impact whether tests pass. + +// Class to enable building trees of nodes with cycles between properties of +// nodes and the properties of those properties. +// This exposed a bug in code serializing DiagnosticsNode objects that did not +// handle these sorts of cycles robustly. +class CyclicDiagnostic extends DiagnosticableTree { + CyclicDiagnostic(this.name); + + // Field used to create cyclic relationships. + CyclicDiagnostic? related; + final List<DiagnosticsNode> children = <DiagnosticsNode>[]; + + final String name; + + @override + String toStringShort() => '${objectRuntimeType(this, 'CyclicDiagnostic')}-$name'; + + // We have to override toString to avoid the toString call itself triggering a + // stack overflow. + @override + String toString({ DiagnosticLevel minLevel = DiagnosticLevel.info }) { + return toStringShort(); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(DiagnosticsProperty<CyclicDiagnostic>('related', related)); + } + + @override + List<DiagnosticsNode> debugDescribeChildren() => children; +} + +class _CreationLocation { + _CreationLocation({ + required this.id, + required this.file, + required this.line, + required this.column, + required this.name, + }); + + final int id; + final String file; + final int line; + final int column; + String? name; +} + +class RenderRepaintBoundaryWithDebugPaint extends RenderRepaintBoundary { + @override + void debugPaintSize(PaintingContext context, Offset offset) { + super.debugPaintSize(context, offset); + assert(() { + // Draw some debug paint UI interleaving creating layers and drawing + // directly to the context's canvas. + final Paint paint = Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 1.0 + ..color = Colors.red; + { + final PictureLayer pictureLayer = PictureLayer(Offset.zero & size); + final ui.PictureRecorder recorder = ui.PictureRecorder(); + final Canvas pictureCanvas = Canvas(recorder); + pictureCanvas.drawCircle(Offset.zero, 20.0, paint); + pictureLayer.picture = recorder.endRecording(); + context.addLayer( + OffsetLayer() + ..offset = offset + ..append(pictureLayer), + ); + } + context.canvas.drawLine( + offset, + offset.translate(size.width, size.height), + paint, + ); + { + final PictureLayer pictureLayer = PictureLayer(Offset.zero & size); + final ui.PictureRecorder recorder = ui.PictureRecorder(); + final Canvas pictureCanvas = Canvas(recorder); + pictureCanvas.drawCircle(const Offset(20.0, 20.0), 20.0, paint); + pictureLayer.picture = recorder.endRecording(); + context.addLayer( + OffsetLayer() + ..offset = offset + ..append(pictureLayer), + ); + } + paint.color = Colors.blue; + context.canvas.drawLine( + offset, + offset.translate(size.width * 0.5, size.height * 0.5), + paint, + ); + return true; + }()); + } +} + +class RepaintBoundaryWithDebugPaint extends RepaintBoundary { + /// Creates a widget that isolates repaints. + const RepaintBoundaryWithDebugPaint({ + super.key, + super.child, + }); + + @override + RenderRepaintBoundary createRenderObject(BuildContext context) { + return RenderRepaintBoundaryWithDebugPaint(); + } +} + +Widget _applyConstructor(Widget Function() constructor) => constructor(); + +class _TrivialWidget extends StatelessWidget { + const _TrivialWidget() : super(key: const Key('singleton')); + @override + Widget build(BuildContext context) => const Text('Hello, world!'); +} + +int getChildLayerCount(OffsetLayer layer) { + Layer? child = layer.firstChild; + int count = 0; + while (child != null) { + count++; + child = child.nextSibling; + } + return count; +} + +extension TextFromString on String { + @widgetFactory + Widget text() { + return Text(this); + } +} + +final List<Object> _weakValueTests = <Object>[1, 1.0, 'hello', true, false, Object(), <int>[3, 4], DateTime(2023)]; + +void main() { + group('$InspectorReferenceData', (){ + for (final Object item in _weakValueTests) { + test('can be created for any type but $Record, $item', () async { + final InspectorReferenceData weakValue = InspectorReferenceData(item, 'id'); + expect(weakValue.value, item); + }); + } + + test('throws for $Record', () async { + expect(()=> InspectorReferenceData((1, 2), 'id'), throwsA(isA<ArgumentError>())); + }); + }); + + group('$WeakMap', (){ + for (final Object item in _weakValueTests) { + test('assigns and removes value, $item', () async { + final WeakMap<Object, Object> weakMap = WeakMap<Object, Object>(); + weakMap[item] = 1; + expect(weakMap[item], 1); + expect(weakMap.remove(item), 1); + expect(weakMap[item], null); + }); + } + + for (final Object item in _weakValueTests) { + test('returns null for absent value, $item', () async { + final WeakMap<Object, Object> weakMap = WeakMap<Object, Object>(); + expect(weakMap[item], null); + }); + } + }); + + _TestWidgetInspectorService.runTests(); +} + +class _TestWidgetInspectorService extends TestWidgetInspectorService { + // These tests need access to protected members of WidgetInspectorService. + static void runTests() { + final TestWidgetInspectorService service = TestWidgetInspectorService(); + WidgetInspectorService.instance = service; + setUp(() { + WidgetInspectorService.instance.isSelectMode.value = true; + }); + tearDown(() async { + service.resetAllState(); + + if (WidgetInspectorService.instance.isWidgetCreationTracked()) { + await service.testBoolExtension( + WidgetInspectorServiceExtensions.trackRebuildDirtyWidgets.name, + <String, String>{'enabled': 'false'}, + ); + } + }); + + test ('objectToDiagnosticsNode returns null for non-diagnosticable', () { + expect(WidgetInspectorService.objectToDiagnosticsNode(Alignment.bottomCenter), isNull); + }); + + test('WidgetInspector does not hold objects from GC', () async { + List<DateTime>? someObject = <DateTime>[DateTime.now(), DateTime.now()]; + final String? id = service.toId(someObject, 'group_name'); + + expect(id, isNotNull); + + final WeakReference<Object> ref = WeakReference<Object>(someObject); + someObject = null; + + // 1 should be enough for [fullGcCycles], but it is 3 to make sure tests are not flaky. + await forceGC(fullGcCycles: 3); + + expect(ref.target, null); + }); + + testWidgets('WidgetInspector smoke test', (WidgetTester tester) async { + // This is a smoke test to verify that adding the inspector doesn't crash. + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: WidgetInspector( + selectButtonBuilder: null, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ), + ); + + expect(true, isTrue); // Expect that we reach here without crashing. + }); + + testWidgets('WidgetInspector interaction test', (WidgetTester tester) async { + final List<String> log = <String>[]; + final GlobalKey selectButtonKey = GlobalKey(); + final GlobalKey inspectorKey = GlobalKey(); + final GlobalKey topButtonKey = GlobalKey(); + + Widget selectButtonBuilder(BuildContext context, VoidCallback onPressed) { + return Material(child: ElevatedButton(onPressed: onPressed, key: selectButtonKey, child: null)); + } + + String paragraphText(RenderParagraph paragraph) { + final TextSpan textSpan = paragraph.text as TextSpan; + return textSpan.text!; + } + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: WidgetInspector( + key: inspectorKey, + selectButtonBuilder: selectButtonBuilder, + child: Material( + child: ListView( + children: <Widget>[ + ElevatedButton( + key: topButtonKey, + onPressed: () { + log.add('top'); + }, + child: const Text('TOP'), + ), + ElevatedButton( + onPressed: () { + log.add('bottom'); + }, + child: const Text('BOTTOM'), + ), + ], + ), + ), + ), + ), + ); + + expect(WidgetInspectorService.instance.selection.current, isNull); + await tester.tap(find.text('TOP'), warnIfMissed: false); + await tester.pump(); + // Tap intercepted by the inspector + expect(log, equals(<String>[])); + expect( + paragraphText( + WidgetInspectorService.instance.selection.current! as RenderParagraph, + ), + equals('TOP'), + ); + final RenderObject topButton = find.byKey(topButtonKey).evaluate().first.renderObject!; + expect( + WidgetInspectorService.instance.selection.candidates, + contains(topButton), + ); + + await tester.tap(find.text('TOP')); + expect(log, equals(<String>['top'])); + log.clear(); + + await tester.tap(find.text('BOTTOM')); + expect(log, equals(<String>['bottom'])); + log.clear(); + // Ensure the inspector selection has not changed to bottom. + expect( + paragraphText( + WidgetInspectorService.instance.selection.current! as RenderParagraph, + ), + equals('TOP'), + ); + + await tester.tap(find.byKey(selectButtonKey)); + await tester.pump(); + + // We are now back in select mode so tapping the bottom button will have + // not trigger a click but will cause it to be selected. + await tester.tap(find.text('BOTTOM'), warnIfMissed: false); + expect(log, equals(<String>[])); + log.clear(); + expect( + paragraphText( + WidgetInspectorService.instance.selection.current! as RenderParagraph, + ), + equals('BOTTOM'), + ); + }); + + testWidgets('WidgetInspector non-invertible transform regression test', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: WidgetInspector( + selectButtonBuilder: null, + child: Transform( + transform: Matrix4.identity()..scale(0.0), + child: const Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ), + ), + ); + + await tester.tap(find.byType(Transform), warnIfMissed: false); + + expect(true, isTrue); // Expect that we reach here without crashing. + }); + + testWidgets('WidgetInspector scroll test', (WidgetTester tester) async { + final Key childKey = UniqueKey(); + final GlobalKey selectButtonKey = GlobalKey(); + final GlobalKey inspectorKey = GlobalKey(); + + Widget selectButtonBuilder(BuildContext context, VoidCallback onPressed) { + return Material(child: ElevatedButton(onPressed: onPressed, key: selectButtonKey, child: null)); + } + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: WidgetInspector( + key: inspectorKey, + selectButtonBuilder: selectButtonBuilder, + child: ListView( + dragStartBehavior: DragStartBehavior.down, + children: <Widget>[ + Container( + key: childKey, + height: 5000.0, + ), + ], + ), + ), + ), + ); + expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); + + await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 200.0, warnIfMissed: false); + await tester.pump(); + + // Fling does nothing as are in inspect mode. + expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); + + await tester.fling(find.byType(ListView), const Offset(200.0, 0.0), 200.0, warnIfMissed: false); + await tester.pump(); + + // Fling still does nothing as are in inspect mode. + expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); + + await tester.tap(find.byType(ListView), warnIfMissed: false); + await tester.pump(); + expect(WidgetInspectorService.instance.selection.current, isNotNull); + + // Now out of inspect mode due to the click. + await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 200.0); + await tester.pump(); + + expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(-200.0)); + + await tester.fling(find.byType(ListView), const Offset(0.0, 200.0), 200.0); + await tester.pump(); + + expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); + }); + + testWidgets('WidgetInspector long press', (WidgetTester tester) async { + bool didLongPress = false; + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: WidgetInspector( + selectButtonBuilder: null, + child: GestureDetector( + onLongPress: () { + expect(didLongPress, isFalse); + didLongPress = true; + }, + child: const Text('target', textDirection: TextDirection.ltr), + ), + ), + ), + ); + + await tester.longPress(find.text('target'), warnIfMissed: false); + // The inspector will swallow the long press. + expect(didLongPress, isFalse); + }); + + testWidgets('WidgetInspector offstage', (WidgetTester tester) async { + final GlobalKey inspectorKey = GlobalKey(); + final GlobalKey clickTarget = GlobalKey(); + + Widget createSubtree({ double? width, Key? key }) { + return Stack( + children: <Widget>[ + Positioned( + key: key, + left: 0.0, + top: 0.0, + width: width, + height: 100.0, + child: Text(width.toString(), textDirection: TextDirection.ltr), + ), + ], + ); + } + + late final OverlayEntry entry1; + addTearDown(() => entry1..remove()..dispose()); + late final OverlayEntry entry2; + addTearDown(() => entry2..remove()..dispose()); + late final OverlayEntry entry3; + addTearDown(() => entry3..remove()..dispose()); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: WidgetInspector( + key: inspectorKey, + selectButtonBuilder: null, + child: Overlay( + initialEntries: <OverlayEntry>[ + entry1 = OverlayEntry( + maintainState: true, + builder: (BuildContext _) => createSubtree(width: 94.0), + ), + entry2 = OverlayEntry( + opaque: true, + maintainState: true, + builder: (BuildContext _) => createSubtree(width: 95.0), + ), + entry3 = OverlayEntry( + maintainState: true, + builder: (BuildContext _) => createSubtree(width: 96.0, key: clickTarget), + ), + ], + ), + ), + ), + ); + + await tester.longPress(find.byKey(clickTarget), warnIfMissed: false); + // The object with width 95.0 wins over the object with width 94.0 because + // the subtree with width 94.0 is offstage. + expect( + WidgetInspectorService.instance.selection.current?.semanticBounds.width, + equals(95.0), + ); + + // Exactly 2 out of the 3 text elements should be in the candidate list of + // objects to select as only 2 are onstage. + expect( + WidgetInspectorService.instance.selection.candidates + .whereType<RenderParagraph>() + .length, + equals(2), + ); + }); + + testWidgets('WidgetInspector with Transform above', (WidgetTester tester) async { + final GlobalKey childKey = GlobalKey(); + final GlobalKey repaintBoundaryKey = GlobalKey(); + + final Matrix4 mainTransform = Matrix4.identity() + ..translate(50.0, 30.0) + ..scale(0.8, 0.8) + ..translate(100.0, 50.0); + + await tester.pumpWidget( + RepaintBoundary( + key: repaintBoundaryKey, + child: ColoredBox( + color: Colors.grey, + child: Transform( + transform: mainTransform, + child: Directionality( + textDirection: TextDirection.ltr, + child: WidgetInspector( + selectButtonBuilder: null, + child: ColoredBox( + color: Colors.white, + child: Center( + child: Container( + key: childKey, + height: 100.0, + width: 50.0, + color: Colors.red, + ), + ), + ), + ), + ), + ), + ), + ), + ); + + await tester.tap(find.byKey(childKey), warnIfMissed: false); + await tester.pump(); + + await expectLater( + find.byKey(repaintBoundaryKey), + matchesGoldenFile('inspector.overlay_positioning_with_transform.png'), + ); + }); + + testWidgets('Multiple widget inspectors', (WidgetTester tester) async { + // This test verifies that interacting with different inspectors + // works correctly. This use case may be an app that displays multiple + // apps inside (i.e. a storyboard). + final GlobalKey selectButton1Key = GlobalKey(); + final GlobalKey selectButton2Key = GlobalKey(); + + final GlobalKey inspector1Key = GlobalKey(); + final GlobalKey inspector2Key = GlobalKey(); + + final GlobalKey child1Key = GlobalKey(); + final GlobalKey child2Key = GlobalKey(); + + InspectorSelectButtonBuilder selectButtonBuilder(Key key) { + return (BuildContext context, VoidCallback onPressed) { + return Material(child: ElevatedButton(onPressed: onPressed, key: key, child: null)); + }; + } + + String paragraphText(RenderParagraph paragraph) { + final TextSpan textSpan = paragraph.text as TextSpan; + return textSpan.text!; + } + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Row( + children: <Widget>[ + Flexible( + child: WidgetInspector( + key: inspector1Key, + selectButtonBuilder: selectButtonBuilder(selectButton1Key), + child: Container( + key: child1Key, + child: const Text('Child 1'), + ), + ), + ), + Flexible( + child: WidgetInspector( + key: inspector2Key, + selectButtonBuilder: selectButtonBuilder(selectButton2Key), + child: Container( + key: child2Key, + child: const Text('Child 2'), + ), + ), + ), + ], + ), + ), + ); + + await tester.tap(find.text('Child 1'), warnIfMissed: false); + await tester.pump(); + expect( + paragraphText( + WidgetInspectorService.instance.selection.current! as RenderParagraph, + ), + equals('Child 1'), + ); + + // Re-enable select mode since it's state is shared between the + // WidgetInspectors + WidgetInspectorService.instance.isSelectMode.value = true; + + await tester.tap(find.text('Child 2'), warnIfMissed: false); + await tester.pump(); + expect( + paragraphText( + WidgetInspectorService.instance.selection.current! as RenderParagraph, + ), + equals('Child 2'), + ); + }); + + test('WidgetInspectorService null id', () { + service.disposeAllGroups(); + expect(service.toObject(null), isNull); + expect(service.toId(null, 'test-group'), isNull); + }); + + test('WidgetInspectorService dispose group', () { + service.disposeAllGroups(); + final Object a = Object(); + const String group1 = 'group-1'; + const String group2 = 'group-2'; + const String group3 = 'group-3'; + final String? aId = service.toId(a, group1); + expect(service.toId(a, group2), equals(aId)); + expect(service.toId(a, group3), equals(aId)); + service.disposeGroup(group1); + service.disposeGroup(group2); + expect(service.toObject(aId), equals(a)); + service.disposeGroup(group3); + expect(() => service.toObject(aId), throwsFlutterError); + }); + + test('WidgetInspectorService dispose id', () { + service.disposeAllGroups(); + final Object a = Object(); + final Object b = Object(); + const String group1 = 'group-1'; + const String group2 = 'group-2'; + final String? aId = service.toId(a, group1); + final String? bId = service.toId(b, group1); + expect(service.toId(a, group2), equals(aId)); + service.disposeId(bId, group1); + expect(() => service.toObject(bId), throwsFlutterError); + service.disposeId(aId, group1); + expect(service.toObject(aId), equals(a)); + service.disposeId(aId, group2); + expect(() => service.toObject(aId), throwsFlutterError); + }); + + test('WidgetInspectorService toObjectForSourceLocation', () { + const String group = 'test-group'; + const Text widget = Text('a', textDirection: TextDirection.ltr); + service.disposeAllGroups(); + final String id = service.toId(widget, group)!; + expect(service.toObjectForSourceLocation(id), equals(widget)); + final Element element = widget.createElement(); + final String elementId = service.toId(element, group)!; + expect(service.toObjectForSourceLocation(elementId), equals(widget)); + expect(element, isNot(equals(widget))); + service.disposeGroup(group); + expect(() => service.toObjectForSourceLocation(elementId), throwsFlutterError); + }); + + test('WidgetInspectorService object id test', () { + const Text a = Text('a', textDirection: TextDirection.ltr); + const Text b = Text('b', textDirection: TextDirection.ltr); + const Text c = Text('c', textDirection: TextDirection.ltr); + const Text d = Text('d', textDirection: TextDirection.ltr); + + const String group1 = 'group-1'; + const String group2 = 'group-2'; + const String group3 = 'group-3'; + service.disposeAllGroups(); + + final String? aId = service.toId(a, group1); + final String? bId = service.toId(b, group2); + final String? cId = service.toId(c, group3); + final String? dId = service.toId(d, group1); + // Make sure we get a consistent id if we add the object to a group multiple + // times. + expect(aId, equals(service.toId(a, group1))); + expect(service.toObject(aId), equals(a)); + expect(service.toObject(aId), isNot(equals(b))); + expect(service.toObject(bId), equals(b)); + expect(service.toObject(cId), equals(c)); + expect(service.toObject(dId), equals(d)); + // Make sure we get a consistent id even if we add the object to a different + // group. + expect(aId, equals(service.toId(a, group3))); + expect(aId, isNot(equals(bId))); + expect(aId, isNot(equals(cId))); + + service.disposeGroup(group3); + }); + + testWidgets('WidgetInspectorService maybeSetSelection', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + final Element elementB = find.text('b').evaluate().first; + + service.disposeAllGroups(); + service.selection.clear(); + int selectionChangedCount = 0; + service.selectionChangedCallback = () => selectionChangedCount++; + service.setSelection('invalid selection'); + expect(selectionChangedCount, equals(0)); + expect(service.selection.currentElement, isNull); + service.setSelection(elementA); + expect(selectionChangedCount, equals(1)); + expect(service.selection.currentElement, equals(elementA)); + expect(service.selection.current, equals(elementA.renderObject)); + + service.setSelection(elementB.renderObject); + expect(selectionChangedCount, equals(2)); + expect(service.selection.current, equals(elementB.renderObject)); + expect(service.selection.currentElement, equals((elementB.renderObject!.debugCreator! as DebugCreator).element)); + + service.setSelection('invalid selection'); + expect(selectionChangedCount, equals(2)); + expect(service.selection.current, equals(elementB.renderObject)); + + service.setSelectionById(service.toId(elementA, 'my-group')); + expect(selectionChangedCount, equals(3)); + expect(service.selection.currentElement, equals(elementA)); + expect(service.selection.current, equals(elementA.renderObject)); + + service.setSelectionById(service.toId(elementA, 'my-group')); + expect(selectionChangedCount, equals(3)); + expect(service.selection.currentElement, equals(elementA)); + }); + + testWidgets('WidgetInspectorService defunct selection regression test', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + + service.setSelection(elementA); + expect(service.selection.currentElement, equals(elementA)); + expect(service.selection.current, equals(elementA.renderObject)); + + await tester.pumpWidget( + const SizedBox( + child: Text('b', textDirection: TextDirection.ltr), + ), + ); + // Selection is now empty as the element is defunct. + expect(service.selection.currentElement, equals(null)); + expect(service.selection.current, equals(null)); + + // Verify that getting the debug creation location of the defunct element + // does not crash. + expect(debugIsLocalCreationLocation(elementA), isFalse); + + // Verify that generating json for a defunct element does not crash. + expect( + elementA.toDiagnosticsNode().toJsonMap( + InspectorSerializationDelegate( + service: service, + includeProperties: true, + ), + ), + isNotNull, + ); + + final Element elementB = find.text('b').evaluate().first; + service.setSelection(elementB); + expect(service.selection.currentElement, equals(elementB)); + expect(service.selection.current, equals(elementB.renderObject)); + + // Set selection back to a defunct element. + service.setSelection(elementA); + + expect(service.selection.currentElement, equals(null)); + expect(service.selection.current, equals(null)); + }); + + testWidgets('WidgetInspectorService getParentChain', (WidgetTester tester) async { + const String group = 'test-group'; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + + service.disposeAllGroups(); + final Element elementB = find.text('b').evaluate().first; + final String bId = service.toId(elementB, group)!; + final Object? jsonList = json.decode(service.getParentChain(bId, group)); + expect(jsonList, isList); + final List<Object?> chainElements = jsonList! as List<Object?>; + final List<Element> expectedChain = elementB.debugGetDiagnosticChain().reversed.toList(); + // Sanity check that the chain goes back to the root. + expect(expectedChain.first, tester.binding.rootElement); + + expect(chainElements.length, equals(expectedChain.length)); + for (int i = 0; i < expectedChain.length; i += 1) { + expect(chainElements[i], isMap); + final Map<String, Object?> chainNode = chainElements[i]! as Map<String, Object?>; + final Element element = expectedChain[i]; + expect(chainNode['node'], isMap); + final Map<String, Object?> jsonNode = chainNode['node']! as Map<String, Object?>; + expect(service.toObject(jsonNode['valueId']! as String), equals(element)); + + expect(chainNode['children'], isList); + final List<Object?> jsonChildren = chainNode['children']! as List<Object?>; + final List<Element> childrenElements = <Element>[]; + element.visitChildren(childrenElements.add); + expect(jsonChildren.length, equals(childrenElements.length)); + if (i + 1 == expectedChain.length) { + expect(chainNode['childIndex'], isNull); + } else { + expect(chainNode['childIndex'], equals(childrenElements.indexOf(expectedChain[i+1]))); + } + for (int j = 0; j < childrenElements.length; j += 1) { + expect(jsonChildren[j], isMap); + final Map<String, Object?> childJson = jsonChildren[j]! as Map<String, Object?>; + expect(service.toObject(childJson['valueId']! as String), equals(childrenElements[j])); + } + } + }); + + test('WidgetInspectorService getProperties', () { + const Diagnosticable diagnosticable = Text('a', textDirection: TextDirection.ltr); + const String group = 'group'; + service.disposeAllGroups(); + final String id = service.toId(diagnosticable, group)!; + final List<Object?> propertiesJson = json.decode(service.getProperties(id, group)) as List<Object?>; + final List<DiagnosticsNode> properties = diagnosticable.toDiagnosticsNode().getProperties(); + expect(properties, isNotEmpty); + expect(propertiesJson.length, equals(properties.length)); + for (int i = 0; i < propertiesJson.length; ++i) { + final Map<String, Object?> propertyJson = propertiesJson[i]! as Map<String, Object?>; + expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value)); + } + }); + + testWidgets('WidgetInspectorService getChildren', (WidgetTester tester) async { + const String group = 'test-group'; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); + service.disposeAllGroups(); + final String id = service.toId(diagnostic, group)!; + final List<Object?> propertiesJson = json.decode(service.getChildren(id, group)) as List<Object?>; + final List<DiagnosticsNode> children = diagnostic.getChildren(); + expect(children.length, equals(3)); + expect(propertiesJson.length, equals(children.length)); + for (int i = 0; i < propertiesJson.length; ++i) { + final Map<String, Object?> propertyJson = propertiesJson[i]! as Map<String, Object?>; + expect(service.toObject(propertyJson['valueId']! as String), equals(children[i].value)); + } + }); + + testWidgets('WidgetInspectorService creationLocation', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + const Text('a'), + const Text('b', textDirection: TextDirection.ltr), + 'c'.text(), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + final Element elementB = find.text('b').evaluate().first; + final Element elementC = find.text('c').evaluate().first; + + service.disposeAllGroups(); + service.resetPubRootDirectories(); + service.setSelection(elementA, 'my-group'); + final Map<String, Object?> jsonA = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object?>; + final Map<String, Object?> creationLocationA = jsonA['creationLocation']! as Map<String, Object?>; + expect(creationLocationA, isNotNull); + final String fileA = creationLocationA['file']! as String; + final int lineA = creationLocationA['line']! as int; + final int columnA = creationLocationA['column']! as int; + final String nameA = creationLocationA['name']! as String; + expect(nameA, equals('Text')); + + service.setSelection(elementB, 'my-group'); + final Map<String, Object?> jsonB = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object?>; + final Map<String, Object?> creationLocationB = jsonB['creationLocation']! as Map<String, Object?>; + expect(creationLocationB, isNotNull); + final String fileB = creationLocationB['file']! as String; + final int lineB = creationLocationB['line']! as int; + final int columnB = creationLocationB['column']! as int; + final String? nameB = creationLocationB['name'] as String?; + expect(nameB, equals('Text')); + + service.setSelection(elementC, 'my-group'); + final Map<String, Object?> jsonC = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object?>; + final Map<String, Object?> creationLocationC = jsonC['creationLocation']! as Map<String, Object?>; + expect(creationLocationC, isNotNull); + final String fileC = creationLocationC['file']! as String; + final int lineC = creationLocationC['line']! as int; + final int columnC = creationLocationC['column']! as int; + final String? nameC = creationLocationC['name'] as String?; + expect(nameC, equals('TextFromString|text')); + + expect(fileA, endsWith('widget_inspector_test.dart')); + expect(fileA, equals(fileB)); + expect(fileA, equals(fileC)); + // We don't hardcode the actual lines the widgets are created on as that + // would make this test fragile. + expect(lineA + 1, equals(lineB)); + expect(lineB + 1, equals(lineC)); + // Column numbers are more stable than line numbers. + expect(columnA, equals(21)); + expect(columnA, equals(columnB)); + expect(columnC, equals(19)); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('WidgetInspectorService setSelection notifiers for an Element', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + + service.disposeAllGroups(); + + setupDefaultPubRootDirectory(service); + + // Select the widget + service.setSelection(elementA, 'my-group'); + + // ensure that developer.inspect was called on the widget + final List<Object?> objectsInspected = service.inspectedObjects(); + expect(objectsInspected, equals(<Element>[elementA])); + + // ensure that a navigate event was sent for the element + final List<Map<Object, Object?>> navigateEventsPosted + = service.dispatchedEvents('navigate', stream: 'ToolEvent',); + expect(navigateEventsPosted.length, equals(1)); + final Map<Object,Object?> event = navigateEventsPosted[0]; + final String file = event['fileUri']! as String; + final int line = event['line']! as int; + final int column = event['column']! as int; + expect(file, endsWith('widget_inspector_test.dart')); + // We don't hardcode the actual lines the widgets are created on as that + // would make this test fragile. + expect(line, isNotNull); + // Column numbers are more stable than line numbers. + expect(column, equals(15)); + }, + skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag. + ); + + testWidgets( + 'WidgetInspectorService setSelection notifiers for a RenderObject', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + + service.disposeAllGroups(); + + setupDefaultPubRootDirectory(service); + + // Select the render object for the widget. + service.setSelection(elementA.renderObject, 'my-group'); + + // ensure that developer.inspect was called on the widget + final List<Object?> objectsInspected = service.inspectedObjects(); + expect(objectsInspected, equals(<RenderObject?>[elementA.renderObject])); + + // ensure that a navigate event was sent for the renderObject + final List<Map<Object, Object?>> navigateEventsPosted + = service.dispatchedEvents('navigate', stream: 'ToolEvent',); + expect(navigateEventsPosted.length, equals(1)); + final Map<Object,Object?> event = navigateEventsPosted[0]; + final String file = event['fileUri']! as String; + final int line = event['line']! as int; + final int column = event['column']! as int; + expect(file, endsWith('widget_inspector_test.dart')); + // We don't hardcode the actual lines the widgets are created on as that + // would make this test fragile. + expect(line, isNotNull); + // Column numbers are more stable than line numbers. + expect(column, equals(17)); + }, + skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag. + ); + + testWidgets( + 'WidgetInspector selectButton inspection for tap', + (WidgetTester tester) async { + final GlobalKey selectButtonKey = GlobalKey(); + final GlobalKey inspectorKey = GlobalKey(); + setupDefaultPubRootDirectory(service); + + Widget selectButtonBuilder(BuildContext context, VoidCallback onPressed) { + return Material(child: ElevatedButton(onPressed: onPressed, key: selectButtonKey, child: null)); + } + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: WidgetInspector( + key: inspectorKey, + selectButtonBuilder: selectButtonBuilder, + child: const Text('Child 1'), + ), + ), + ); + final Finder child = find.text('Child 1'); + final Element childElement = child.evaluate().first; + + await tester.tap(child, warnIfMissed: false); + + await tester.pump(); + + // ensure that developer.inspect was called on the widget + final List<Object?> objectsInspected = service.inspectedObjects(); + expect(objectsInspected, equals(<RenderObject?>[childElement.renderObject])); + + // ensure that a navigate event was sent for the renderObject + final List<Map<Object, Object?>> navigateEventsPosted + = service.dispatchedEvents('navigate', stream: 'ToolEvent',); + expect(navigateEventsPosted.length, equals(1)); + final Map<Object,Object?> event = navigateEventsPosted[0]; + final String file = event['fileUri']! as String; + final int line = event['line']! as int; + final int column = event['column']! as int; + expect(file, endsWith('widget_inspector_test.dart')); + // We don't hardcode the actual lines the widgets are created on as that + // would make this test fragile. + expect(line, isNotNull); + // Column numbers are more stable than line numbers. + expect(column, equals(28)); + }, + skip: !WidgetInspectorService.instance.isWidgetCreationTracked() // [intended] Test requires --track-widget-creation flag. + ); + + testWidgets('test transformDebugCreator will re-order if after stack trace', (WidgetTester tester) async { + final bool widgetTracked = WidgetInspectorService.instance.isWidgetCreationTracked(); + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + late String pubRootTest; + if (widgetTracked) { + final Map<String, Object?> jsonObject = json.decode( + service.getSelectedWidget(null, 'my-group'), + ) as Map<String, Object?>; + final Map<String, Object?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + final String fileA = creationLocation['file']! as String; + expect(fileA, endsWith('widget_inspector_test.dart')); + expect(jsonObject, isNot(contains('createdByLocalProject'))); + final List<String> segments = Uri + .parse(fileA) + .pathSegments; + // Strip a couple subdirectories away to generate a plausible pub root + // directory. + pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; + service.resetPubRootDirectories(); + service.addPubRootDirectories(<String>[pubRootTest]); + } + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + builder.add(StringProperty('dummy1', 'value')); + builder.add(StringProperty('dummy2', 'value')); + builder.add(DiagnosticsStackTrace('When the exception was thrown, this was the stack', null)); + builder.add(DiagnosticsDebugCreator(DebugCreator(elementA))); + + final List<DiagnosticsNode> nodes = List<DiagnosticsNode>.from(debugTransformDebugCreator(builder.properties)); + expect(nodes.length, 5); + expect(nodes[0].runtimeType, StringProperty); + expect(nodes[0].name, 'dummy1'); + expect(nodes[1].runtimeType, StringProperty); + expect(nodes[1].name, 'dummy2'); + // transformed node should come in front of stack trace. + if (widgetTracked) { + expect(nodes[2].runtimeType, DiagnosticsBlock); + final DiagnosticsBlock node = nodes[2] as DiagnosticsBlock; + final List<DiagnosticsNode> children = node.getChildren(); + expect(children.length, 1); + final ErrorDescription child = children[0] as ErrorDescription; + expect(child.valueToString(), contains(Uri.parse(pubRootTest).path)); + } else { + expect(nodes[2].runtimeType, ErrorDescription); + final ErrorDescription node = nodes[2] as ErrorDescription; + expect(node.valueToString().startsWith('Widget creation tracking is currently disabled.'), true); + } + expect(nodes[3].runtimeType, ErrorSpacer); + expect(nodes[4].runtimeType, DiagnosticsStackTrace); + }); + + testWidgets('test transformDebugCreator will not re-order if before stack trace', (WidgetTester tester) async { + final bool widgetTracked = WidgetInspectorService.instance.isWidgetCreationTracked(); + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + late String pubRootTest; + if (widgetTracked) { + final Map<String, Object?> jsonObject = json.decode( + service.getSelectedWidget(null, 'my-group'), + ) as Map<String, Object?>; + final Map<String, Object?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + final String fileA = creationLocation['file']! as String; + expect(fileA, endsWith('widget_inspector_test.dart')); + expect(jsonObject, isNot(contains('createdByLocalProject'))); + final List<String> segments = Uri + .parse(fileA) + .pathSegments; + // Strip a couple subdirectories away to generate a plausible pub root + // directory. + pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; + service.resetPubRootDirectories(); + service.addPubRootDirectories(<String>[pubRootTest]); + } + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + builder.add(StringProperty('dummy1', 'value')); + builder.add(DiagnosticsDebugCreator(DebugCreator(elementA))); + builder.add(StringProperty('dummy2', 'value')); + builder.add(DiagnosticsStackTrace('When the exception was thrown, this was the stack', null)); + + final List<DiagnosticsNode> nodes = List<DiagnosticsNode>.from(debugTransformDebugCreator(builder.properties)); + expect(nodes.length, 5); + expect(nodes[0].runtimeType, StringProperty); + expect(nodes[0].name, 'dummy1'); + // transformed node stays at original place. + if (widgetTracked) { + expect(nodes[1].runtimeType, DiagnosticsBlock); + final DiagnosticsBlock node = nodes[1] as DiagnosticsBlock; + final List<DiagnosticsNode> children = node.getChildren(); + expect(children.length, 1); + final ErrorDescription child = children[0] as ErrorDescription; + expect(child.valueToString(), contains(Uri.parse(pubRootTest).path)); + } else { + expect(nodes[1].runtimeType, ErrorDescription); + final ErrorDescription node = nodes[1] as ErrorDescription; + expect(node.valueToString().startsWith('Widget creation tracking is currently disabled.'), true); + } + expect(nodes[2].runtimeType, ErrorSpacer); + expect(nodes[3].runtimeType, StringProperty); + expect(nodes[3].name, 'dummy2'); + expect(nodes[4].runtimeType, DiagnosticsStackTrace); + }, skip: WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --no-track-widget-creation flag. + + testWidgets('test transformDebugCreator will add DevToolsDeepLinkProperty for overflow errors', (WidgetTester tester) async { + activeDevToolsServerAddress = 'http://127.0.0.1:9100'; + connectedVmServiceUri = 'http://127.0.0.1:55269/798ay5al_FM=/'; + + setupDefaultPubRootDirectory(service); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + builder.add(ErrorSummary('A RenderFlex overflowed by 273 pixels on the bottom')); + builder.add(DiagnosticsDebugCreator(DebugCreator(elementA))); + builder.add(StringProperty('dummy2', 'value')); + + final List<DiagnosticsNode> nodes = List<DiagnosticsNode>.from(debugTransformDebugCreator(builder.properties)); + expect(nodes.length, 6); + expect(nodes[0].runtimeType, ErrorSummary); + expect(nodes[1].runtimeType, DiagnosticsBlock); + expect(nodes[2].runtimeType, ErrorSpacer); + expect(nodes[3].runtimeType, DevToolsDeepLinkProperty); + expect(nodes[4].runtimeType, ErrorSpacer); + expect(nodes[5].runtimeType, StringProperty); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('test transformDebugCreator will not add DevToolsDeepLinkProperty for non-overflow errors', (WidgetTester tester) async { + activeDevToolsServerAddress = 'http://127.0.0.1:9100'; + connectedVmServiceUri = 'http://127.0.0.1:55269/798ay5al_FM=/'; + setupDefaultPubRootDirectory(service); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + builder.add(ErrorSummary('some other error')); + builder.add(DiagnosticsDebugCreator(DebugCreator(elementA))); + builder.add(StringProperty('dummy2', 'value')); + + final List<DiagnosticsNode> nodes = List<DiagnosticsNode>.from(debugTransformDebugCreator(builder.properties)); + expect(nodes.length, 4); + expect(nodes[0].runtimeType, ErrorSummary); + expect(nodes[1].runtimeType, DiagnosticsBlock); + expect(nodes[2].runtimeType, ErrorSpacer); + expect(nodes[3].runtimeType, StringProperty); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('test transformDebugCreator will not add DevToolsDeepLinkProperty if devtoolsServerAddress is unavailable', (WidgetTester tester) async { + activeDevToolsServerAddress = null; + connectedVmServiceUri = 'http://127.0.0.1:55269/798ay5al_FM=/'; + setupDefaultPubRootDirectory(service); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + builder.add(ErrorSummary('A RenderFlex overflowed by 273 pixels on the bottom')); + builder.add(DiagnosticsDebugCreator(DebugCreator(elementA))); + builder.add(StringProperty('dummy2', 'value')); + + final List<DiagnosticsNode> nodes = List<DiagnosticsNode>.from(debugTransformDebugCreator(builder.properties)); + expect(nodes.length, 4); + expect(nodes[0].runtimeType, ErrorSummary); + expect(nodes[1].runtimeType, DiagnosticsBlock); + expect(nodes[2].runtimeType, ErrorSpacer); + expect(nodes[3].runtimeType, StringProperty); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + // TODO(CoderDake): Clean up pubRootDirectory tests https://github.com/flutter/flutter/issues/107186 + group('pubRootDirectory', () { + const String directoryA = '/a/b/c'; + const String directoryB = '/d/e/f'; + const String directoryC = '/g/h/i'; + + setUp(() { + service.resetPubRootDirectories(); + }); + + group('addPubRootDirectories', () { + test('can add multiple directories', () async { + const List<String> directories = <String>[directoryA, directoryB]; + service.addPubRootDirectories(directories); + + final List<String> pubRoots = await service.currentPubRootDirectories; + expect(pubRoots, unorderedEquals(directories)); + }); + + test('can add multiple directories separately', () async { + service.addPubRootDirectories(<String>[directoryA]); + service.addPubRootDirectories(<String>[directoryB]); + service.addPubRootDirectories(<String>[]); + + final List<String> pubRoots = await service.currentPubRootDirectories; + expect(pubRoots, unorderedEquals(<String>[ + directoryA, + directoryB, + ])); + }); + + test('handles duplicates', () async { + const List<String> directories = <String>[ + directoryA, + 'file://$directoryA', + directoryB, + directoryB + ]; + service.addPubRootDirectories(directories); + + final List<String> pubRoots = await service.currentPubRootDirectories; + expect(pubRoots, unorderedEquals(<String>[ + directoryA, + directoryB, + ])); + }); + }); + + group('removePubRootDirectories', () { + setUp(() { + service.resetPubRootDirectories(); + service.addPubRootDirectories(<String>[directoryA, directoryB, directoryC]); + }); + + test('removes multiple directories', () async { + service.removePubRootDirectories(<String>[directoryA, directoryB,]); + + final List<String> pubRoots = await service.currentPubRootDirectories; + expect(pubRoots, equals(<String>[directoryC])); + }); + + test('removes multiple directories separately', () async { + service.removePubRootDirectories(<String>[directoryA]); + service.removePubRootDirectories(<String>[directoryB]); + service.removePubRootDirectories(<String>[]); + + final List<String> pubRoots = await service.currentPubRootDirectories; + expect(pubRoots, equals(<String>[directoryC])); + }); + + test('handles duplicates', () async { + service.removePubRootDirectories(<String>[ + 'file://$directoryA', + directoryA, + directoryB, + directoryB, + ]); + + final List<String> pubRoots = await service.currentPubRootDirectories; + expect(pubRoots, equals(<String>[directoryC])); + }); + + test("does nothing if the directories doesn't exist ", () async { + service.removePubRootDirectories(<String>['/x/y/z']); + + final List<String> pubRoots = await service.currentPubRootDirectories; + expect(pubRoots, unorderedEquals(<String>[ + directoryA, + directoryB, + directoryC, + ])); + }); + }); + }); + + group( + 'WidgetInspectorService', + () { + late final String pubRootTest; + + setUpAll(() { + pubRootTest = generateTestPubRootDirectory(service); + }); + + setUp(() { + service.disposeAllGroups(); + service.resetPubRootDirectories(); + }); + + group('addPubRootDirectories', () { + testWidgets( + 'does not have createdByLocalProject when there are no pubRootDirectories', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + final Map<String, Object?> jsonObject = + json.decode(service.getSelectedWidget(null, 'my-group')) + as Map<String, Object?>; + final Map<String, Object?> creationLocation = + jsonObject['creationLocation']! as Map<String, Object?>; + + expect(creationLocation, isNotNull); + final String fileA = creationLocation['file']! as String; + expect(fileA, endsWith('widget_inspector_test.dart')); + expect(jsonObject, isNot(contains('createdByLocalProject'))); + }, + ); + + testWidgets( + 'has createdByLocalProject when the element is part of the pubRootDirectory', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + + service.addPubRootDirectories(<String>[pubRootTest]); + + service.setSelection(elementA, 'my-group'); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'does not have createdByLocalProject when widget package directory is a suffix of a pubRootDirectory', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.addPubRootDirectories(<String>['/invalid/$pubRootTest']); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'has createdByLocalProject when the pubRootDirectory is prefixed with file://', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.addPubRootDirectories(<String>['file://$pubRootTest']); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'does not have createdByLocalProject when thePubRootDirectory has a different suffix', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.addPubRootDirectories(<String>['$pubRootTest/different']); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'has createdByLocalProject even if another pubRootDirectory does not match', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.addPubRootDirectories(<String>[ + '/invalid/$pubRootTest', + pubRootTest, + ]); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'widget is part of core framework and is the child of a widget in the package pubRootDirectories', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + final Element richText = find + .descendant( + of: find.text('a'), + matching: find.byType(RichText), + ) + .evaluate() + .first; + service.setSelection(richText, 'my-group'); + service.addPubRootDirectories(<String>[pubRootTest]); + + final Map<String, Object?> jsonObject = + json.decode(service.getSelectedWidget(null, 'my-group')) + as Map<String, Object?>; + expect(jsonObject, isNot(contains('createdByLocalProject'))); + final Map<String, Object?> creationLocation = + jsonObject['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + // This RichText widget is created by the build method of the Text widget + // thus the creation location is in text.dart not basic.dart + final List<String> pathSegmentsFramework = + Uri.parse(creationLocation['file']! as String).pathSegments; + expect( + pathSegmentsFramework.join('/'), + endsWith('/flutter/lib/src/widgets/text.dart'), + ); + + // Strip off /src/widgets/text.dart. + final String pubRootFramework = + '/${pathSegmentsFramework.take(pathSegmentsFramework.length - 3).join('/')}'; + service.resetPubRootDirectories(); + service.addPubRootDirectories(<String>[pubRootFramework]); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + service.setSelection(elementA, 'my-group'); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + isNot(contains('createdByLocalProject')), + ); + + service + .setPubRootDirectories(<String>[pubRootFramework, pubRootTest]); + service.setSelection(elementA, 'my-group'); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + service.setSelection(richText, 'my-group'); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + }, + ); + }); + + group('createdByLocalProject', () { + setUp(() { + service.resetPubRootDirectories(); + }); + + testWidgets( + 'reacts to add and removing pubRootDirectories', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + + service.addPubRootDirectories(<String>[ + pubRootTest, + 'file://$pubRootTest', + '/unrelated/$pubRootTest', + ]); + + service.setSelection(elementA, 'my-group'); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + + service.removePubRootDirectories(<String>[pubRootTest]); + + service.setSelection(elementA, 'my-group'); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'does not match when the package directory does not match', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.addPubRootDirectories(<String>[ + '$pubRootTest/different', + '/unrelated/$pubRootTest', + ]); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'has createdByLocalProject when the pubRootDirectory is prefixed with file://', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.addPubRootDirectories(<String>['file://$pubRootTest']); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'can handle consecutive calls to add', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.addPubRootDirectories(<String>[ + pubRootTest, + ]); + service.addPubRootDirectories(<String>[ + '/invalid/$pubRootTest', + ]); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + }, + ); + testWidgets( + 'can handle removing an unrelated pubRootDirectory', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.addPubRootDirectories(<String>[ + pubRootTest, + '/invalid/$pubRootTest', + ]); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + + service.removePubRootDirectories(<String>[ + '/invalid/$pubRootTest', + ]); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'can handle parent widget being part of a separate package', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + final Element richText = find + .descendant( + of: find.text('a'), + matching: find.byType(RichText), + ) + .evaluate() + .first; + service.setSelection(richText, 'my-group'); + service.addPubRootDirectories(<String>[pubRootTest]); + + final Map<String, Object?> jsonObject = + json.decode(service.getSelectedWidget(null, 'my-group')) + as Map<String, Object?>; + expect(jsonObject, isNot(contains('createdByLocalProject'))); + final Map<String, Object?> creationLocation = + jsonObject['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + // This RichText widget is created by the build method of the Text widget + // thus the creation location is in text.dart not basic.dart + final List<String> pathSegmentsFramework = + Uri.parse(creationLocation['file']! as String).pathSegments; + expect( + pathSegmentsFramework.join('/'), + endsWith('/flutter/lib/src/widgets/text.dart'), + ); + + // Strip off /src/widgets/text.dart. + final String pubRootFramework = + '/${pathSegmentsFramework.take(pathSegmentsFramework.length - 3).join('/')}'; + service.resetPubRootDirectories(); + service.addPubRootDirectories(<String>[pubRootFramework]); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + service.setSelection(elementA, 'my-group'); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + isNot(contains('createdByLocalProject')), + ); + + service.resetPubRootDirectories(); + service + .addPubRootDirectories(<String>[pubRootFramework, pubRootTest]); + service.setSelection(elementA, 'my-group'); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + service.setSelection(richText, 'my-group'); + expect( + json.decode(service.getSelectedWidget(null, 'my-group')), + contains('createdByLocalProject'), + ); + }, + ); + }); + }, + skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag. + ); + + group('InspectorSelection', () { + testWidgets('receives notifications when selection changes', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b'), + ], + ), + ), + ); + final InspectorSelection selection = InspectorSelection(); + addTearDown(selection.dispose); + int count = 0; + selection.addListener(() { + count++; + }); + final RenderParagraph renderObjectA = + tester.renderObject<RenderParagraph>(find.text('a')); + final RenderParagraph renderObjectB = + tester.renderObject<RenderParagraph>(find.text('b')); + final Element elementA = find.text('a').evaluate().first; + + selection.candidates = <RenderObject>[renderObjectA, renderObjectB]; + await tester.pump(); + expect(count, equals(1)); + + selection.index = 1; + await tester.pump(); + expect(count, equals(2)); + + selection.clear(); + await tester.pump(); + expect(count, equals(3)); + + selection.current = renderObjectA; + await tester.pump(); + expect(count, equals(4)); + + selection.currentElement = elementA; + expect(count, equals(5)); + }); + }); + + test('ext.flutter.inspector.disposeGroup', () async { + final Object a = Object(); + const String group1 = 'group-1'; + const String group2 = 'group-2'; + const String group3 = 'group-3'; + final String? aId = service.toId(a, group1); + expect(service.toId(a, group2), equals(aId)); + expect(service.toId(a, group3), equals(aId)); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeGroup.name, + <String, String>{'objectGroup': group1}, + ); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeGroup.name, + <String, String>{'objectGroup': group2}, + ); + expect(service.toObject(aId), equals(a)); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeGroup.name, + <String, String>{'objectGroup': group3}, + ); + expect(() => service.toObject(aId), throwsFlutterError); + }); + + test('ext.flutter.inspector.disposeId', () async { + final Object a = Object(); + final Object b = Object(); + const String group1 = 'group-1'; + const String group2 = 'group-2'; + final String aId = service.toId(a, group1)!; + final String bId = service.toId(b, group1)!; + expect(service.toId(a, group2), equals(aId)); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeId.name, + <String, String>{'arg': bId, 'objectGroup': group1}, + ); + expect(() => service.toObject(bId), throwsFlutterError); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeId.name, + <String, String>{'arg': aId, 'objectGroup': group1}, + ); + expect(service.toObject(aId), equals(a)); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeId.name, + <String, String>{'arg': aId, 'objectGroup': group2}, + ); + expect(() => service.toObject(aId), throwsFlutterError); + }); + + testWidgets('ext.flutter.inspector.setSelection', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + final Element elementB = find.text('b').evaluate().first; + + service.disposeAllGroups(); + service.selection.clear(); + int selectionChangedCount = 0; + service.selectionChangedCallback = () => selectionChangedCount++; + service.setSelection('invalid selection'); + expect(selectionChangedCount, equals(0)); + expect(service.selection.currentElement, isNull); + service.setSelection(elementA); + expect(selectionChangedCount, equals(1)); + expect(service.selection.currentElement, equals(elementA)); + expect(service.selection.current, equals(elementA.renderObject)); + + service.setSelection(elementB.renderObject); + expect(selectionChangedCount, equals(2)); + expect(service.selection.current, equals(elementB.renderObject)); + expect(service.selection.currentElement, equals((elementB.renderObject!.debugCreator! as DebugCreator).element)); + + service.setSelection('invalid selection'); + expect(selectionChangedCount, equals(2)); + expect(service.selection.current, equals(elementB.renderObject)); + + await service.testExtension( + WidgetInspectorServiceExtensions.setSelectionById.name, + <String, String>{'arg': service.toId(elementA, 'my-group')!, 'objectGroup': 'my-group'}, + ); + expect(selectionChangedCount, equals(3)); + expect(service.selection.currentElement, equals(elementA)); + expect(service.selection.current, equals(elementA.renderObject)); + + service.setSelectionById(service.toId(elementA, 'my-group')); + expect(selectionChangedCount, equals(3)); + expect(service.selection.currentElement, equals(elementA)); + }); + + testWidgets('ext.flutter.inspector.getParentChain', (WidgetTester tester) async { + const String group = 'test-group'; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + + final Element elementB = find.text('b').evaluate().first; + final String bId = service.toId(elementB, group)!; + final Object? jsonList = await service.testExtension( + WidgetInspectorServiceExtensions.getParentChain.name, + <String, String>{'arg': bId, 'objectGroup': group}, + ); + expect(jsonList, isList); + final List<Object?> chainElements = jsonList! as List<Object?>; + final List<Element> expectedChain = elementB.debugGetDiagnosticChain().reversed.toList(); + // Sanity check that the chain goes back to the root. + expect(expectedChain.first, tester.binding.rootElement); + + expect(chainElements.length, equals(expectedChain.length)); + for (int i = 0; i < expectedChain.length; i += 1) { + expect(chainElements[i], isMap); + final Map<String, Object?> chainNode = chainElements[i]! as Map<String, Object?>; + final Element element = expectedChain[i]; + expect(chainNode['node'], isMap); + final Map<String, Object?> jsonNode = chainNode['node']! as Map<String, Object?>; + expect(service.toObject(jsonNode['valueId']! as String), equals(element)); + + expect(chainNode['children'], isList); + final List<Object?> jsonChildren = chainNode['children']! as List<Object?>; + final List<Element> childrenElements = <Element>[]; + element.visitChildren(childrenElements.add); + expect(jsonChildren.length, equals(childrenElements.length)); + if (i + 1 == expectedChain.length) { + expect(chainNode['childIndex'], isNull); + } else { + expect(chainNode['childIndex'], equals(childrenElements.indexOf(expectedChain[i+1]))); + } + for (int j = 0; j < childrenElements.length; j += 1) { + expect(jsonChildren[j], isMap); + final Map<String, Object?> childJson = jsonChildren[j]! as Map<String, Object?>; + expect(service.toObject(childJson['valueId']! as String), equals(childrenElements[j])); + } + } + }); + + test('ext.flutter.inspector.getProperties', () async { + const Diagnosticable diagnosticable = Text('a', textDirection: TextDirection.ltr); + const String group = 'group'; + final String id = service.toId(diagnosticable, group)!; + final List<Object?> propertiesJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getProperties.name, + <String, String>{'arg': id, 'objectGroup': group}, + ))! as List<Object?>; + final List<DiagnosticsNode> properties = diagnosticable.toDiagnosticsNode().getProperties(); + expect(properties, isNotEmpty); + expect(propertiesJson.length, equals(properties.length)); + for (int i = 0; i < propertiesJson.length; ++i) { + final Map<String, Object?> propertyJson = propertiesJson[i]! as Map<String, Object?>; + expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value)); + } + }); + + testWidgets('ext.flutter.inspector.getChildren', (WidgetTester tester) async { + const String group = 'test-group'; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); + final String id = service.toId(diagnostic, group)!; + final List<Object?> propertiesJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildren.name, + <String, String>{'arg': id, 'objectGroup': group}, + ))! as List<Object?>; + final List<DiagnosticsNode> children = diagnostic.getChildren(); + expect(children.length, equals(3)); + expect(propertiesJson.length, equals(children.length)); + for (int i = 0; i < propertiesJson.length; ++i) { + final Map<String, Object?> propertyJson = propertiesJson[i]! as Map<String, Object?>; + expect(service.toObject(propertyJson['valueId']! as String), equals(children[i].value)); + } + }); + + testWidgets('ext.flutter.inspector.getChildrenDetailsSubtree', (WidgetTester tester) async { + const String group = 'test-group'; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Diagnosticable diagnosticable = find.byType(Stack).evaluate().first; + final String id = service.toId(diagnosticable, group)!; + final List<Object?> childrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenDetailsSubtree.name, + <String, String>{'arg': id, 'objectGroup': group}, + ))! as List<Object?>; + final List<DiagnosticsNode> children = diagnosticable.toDiagnosticsNode().getChildren(); + expect(children.length, equals(3)); + expect(childrenJson.length, equals(children.length)); + for (int i = 0; i < childrenJson.length; ++i) { + final Map<String, Object?> childJson = childrenJson[i]! as Map<String, Object?>; + expect(service.toObject(childJson['valueId']! as String), equals(children[i].value)); + final List<Object?> propertiesJson = childJson['properties']! as List<Object?>; + final Element element = service.toObject(childJson['valueId']! as String)! as Element; + final List<DiagnosticsNode> expectedProperties = element.toDiagnosticsNode().getProperties(); + final Iterable<Object?> propertyValues = expectedProperties.map((DiagnosticsNode e) => e.value.toString()); + for (final Map<String, Object?> propertyJson in propertiesJson.cast<Map<String, Object?>>()) { + final String id = propertyJson['valueId']! as String; + final String property = service.toObject(id)!.toString(); + expect(propertyValues, contains(property)); + } + } + }); + + testWidgets('WidgetInspectorService getDetailsSubtree', (WidgetTester tester) async { + const String group = 'test-group'; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Diagnosticable diagnosticable = find.byType(Stack).evaluate().first; + final String id = service.toId(diagnosticable, group)!; + final Map<String, Object?> subtreeJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getDetailsSubtree.name, + <String, String>{'arg': id, 'objectGroup': group}, + ))! as Map<String, Object?>; + expect(subtreeJson['valueId'], equals(id)); + final List<Object?> childrenJson = subtreeJson['children']! as List<Object?>; + final List<DiagnosticsNode> children = diagnosticable.toDiagnosticsNode().getChildren(); + expect(children.length, equals(3)); + expect(childrenJson.length, equals(children.length)); + for (int i = 0; i < childrenJson.length; ++i) { + final Map<String, Object?> childJson = childrenJson[i]! as Map<String, Object?>; + expect(service.toObject(childJson['valueId']! as String), equals(children[i].value)); + final List<Object?> propertiesJson = childJson['properties']! as List<Object?>; + for (final Map<String, Object?> propertyJson in propertiesJson.cast<Map<String, Object?>>()) { + expect(propertyJson, isNot(contains('children'))); + } + final Element element = service.toObject(childJson['valueId']! as String)! as Element; + final List<DiagnosticsNode> expectedProperties = element.toDiagnosticsNode().getProperties(); + final Iterable<Object?> propertyValues = expectedProperties.map((DiagnosticsNode e) => e.value.toString()); + for (final Map<String, Object?> propertyJson in propertiesJson.cast<Map<String, Object?>>()) { + final String id = propertyJson['valueId']! as String; + final String property = service.toObject(id)!.toString(); + expect(propertyValues, contains(property)); + } + } + + final Map<String, Object?> deepSubtreeJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getDetailsSubtree.name, + <String, String>{'arg': id, 'objectGroup': group, 'subtreeDepth': '3'}, + ))! as Map<String, Object?>; + final List<Object?> deepChildrenJson = deepSubtreeJson['children']! as List<Object?>; + for (final Map<String, Object?> childJson in deepChildrenJson.cast<Map<String, Object?>>()) { + final List<Object?> propertiesJson = childJson['properties']! as List<Object?>; + for (final Map<String, Object?> propertyJson in propertiesJson.cast<Map<String, Object?>>()) { + expect(propertyJson, contains('children')); + } + } + }); + + testWidgets('cyclic diagnostics regression test', (WidgetTester tester) async { + const String group = 'test-group'; + final CyclicDiagnostic a = CyclicDiagnostic('a'); + final CyclicDiagnostic b = CyclicDiagnostic('b'); + a.related = b; + a.children.add(b.toDiagnosticsNode()); + b.related = a; + + final String id = service.toId(a, group)!; + final Map<String, Object?> subtreeJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getDetailsSubtree.name, + <String, String>{'arg': id, 'objectGroup': group}, + ))! as Map<String, Object?>; + expect(subtreeJson['valueId'], equals(id)); + expect(subtreeJson, contains('children')); + final List<Object?> propertiesJson = subtreeJson['properties']! as List<Object?>; + expect(propertiesJson.length, equals(1)); + final Map<String, Object?> relatedProperty = propertiesJson.first! as Map<String, Object?>; + expect(relatedProperty['name'], equals('related')); + expect(relatedProperty['description'], equals('CyclicDiagnostic-b')); + expect(relatedProperty, contains('isDiagnosticableValue')); + expect(relatedProperty, isNot(contains('children'))); + expect(relatedProperty, contains('properties')); + final List<Object?> relatedWidgetProperties = relatedProperty['properties']! as List<Object?>; + expect(relatedWidgetProperties.length, equals(1)); + final Map<String, Object?> nestedRelatedProperty = relatedWidgetProperties.first! as Map<String, Object?>; + expect(nestedRelatedProperty['name'], equals('related')); + // Make sure we do not include properties or children for diagnostic a + // which we already included as the root node as that would indicate a + // cycle. + expect(nestedRelatedProperty['description'], equals('CyclicDiagnostic-a')); + expect(nestedRelatedProperty, contains('isDiagnosticableValue')); + expect(nestedRelatedProperty, isNot(contains('properties'))); + expect(nestedRelatedProperty, isNot(contains('children'))); + }); + + testWidgets('ext.flutter.inspector.getRootWidgetSummaryTree', (WidgetTester tester) async { + const String group = 'test-group'; + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + + final Element elementA = find.text('a').evaluate().first; + + service.disposeAllGroups(); + service.resetPubRootDirectories(); + service.setSelection(elementA, 'my-group'); + final Map<String, dynamic> jsonA = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ))! as Map<String, dynamic>; + + service.resetPubRootDirectories(); + Map<String, Object?> rootJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getRootWidgetSummaryTree.name, + <String, String>{'objectGroup': group}, + ))! as Map<String, Object?>; + + // We haven't yet properly specified which directories are summary tree + // directories so we get an empty tree other than the root that is always + // included. + final Object? rootWidget = service.toObject(rootJson['valueId']! as String); + expect(rootWidget, equals(WidgetsBinding.instance.rootElement)); + List<Object?> childrenJson = rootJson['children']! as List<Object?>; + // There are no summary tree children. + expect(childrenJson.length, equals(0)); + + final Map<String, Object?> creationLocation = jsonA['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + final String testFile = creationLocation['file']! as String; + expect(testFile, endsWith('widget_inspector_test.dart')); + final List<String> segments = Uri.parse(testFile).pathSegments; + // Strip a couple subdirectories away to generate a plausible pub root + // directory. + final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; + service.resetPubRootDirectories(); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': pubRootTest}, + ); + + rootJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getRootWidgetSummaryTree.name, + <String, String>{'objectGroup': group}, + ))! as Map<String, Object?>; + childrenJson = rootJson['children']! as List<Object?>; + // The tree of nodes returned contains all widgets created directly by the + // test. + childrenJson = rootJson['children']! as List<Object?>; + expect(childrenJson.length, equals(1)); + + List<Object?> alternateChildrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + <String, String>{'arg': rootJson['valueId']! as String, 'objectGroup': group}, + ))! as List<Object?>; + expect(alternateChildrenJson.length, equals(1)); + Map<String, Object?> childJson = childrenJson[0]! as Map<String, Object?>; + Map<String, Object?> alternateChildJson = alternateChildrenJson[0]! as Map<String, Object?>; + expect(childJson['description'], startsWith('Directionality')); + expect(alternateChildJson['description'], startsWith('Directionality')); + expect(alternateChildJson['valueId'], equals(childJson['valueId'])); + + childrenJson = childJson['children']! as List<Object?>; + alternateChildrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + <String, String>{'arg': childJson['valueId']! as String, 'objectGroup': group}, + ))! as List<Object?>; + expect(alternateChildrenJson.length, equals(1)); + expect(childrenJson.length, equals(1)); + alternateChildJson = alternateChildrenJson[0]! as Map<String, Object?>; + childJson = childrenJson[0]! as Map<String, Object?>; + expect(childJson['description'], startsWith('Stack')); + expect(alternateChildJson['description'], startsWith('Stack')); + expect(alternateChildJson['valueId'], equals(childJson['valueId'])); + childrenJson = childJson['children']! as List<Object?>; + + childrenJson = childJson['children']! as List<Object?>; + alternateChildrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + <String, String>{'arg': childJson['valueId']! as String, 'objectGroup': group}, + ))! as List<Object?>; + expect(alternateChildrenJson.length, equals(3)); + expect(childrenJson.length, equals(3)); + alternateChildJson = alternateChildrenJson[2]! as Map<String, Object?>; + childJson = childrenJson[2]! as Map<String, Object?>; + expect(childJson['description'], startsWith('Text')); + expect(alternateChildJson['description'], startsWith('Text')); + expect(alternateChildJson['valueId'], equals(childJson['valueId'])); + alternateChildrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + <String, String>{'arg': childJson['valueId']! as String, 'objectGroup': group}, + ))! as List<Object?>; + expect(alternateChildrenJson.length , equals(0)); + // Tests are failing when this typo is fixed. + expect(childJson['chidlren'], isNull); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('ext.flutter.inspector.getRootWidgetSummaryTreeWithPreviews', (WidgetTester tester) async { + const String group = 'test-group'; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + + service + ..disposeAllGroups() + ..resetPubRootDirectories() + ..setSelection(elementA, 'my-group'); + + final Map<String, dynamic> jsonA = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ))! as Map<String, dynamic>; + + + final Map<String, Object?> creationLocation = jsonA['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + final String testFile = creationLocation['file']! as String; + expect(testFile, endsWith('widget_inspector_test.dart')); + final List<String> segments = Uri.parse(testFile).pathSegments; + // Strip a couple subdirectories away to generate a plausible pub root + // directory. + final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; + service + ..resetPubRootDirectories() + ..addPubRootDirectories(<String>[pubRootTest]); + + final Map<String, Object?> rootJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getRootWidgetSummaryTreeWithPreviews.name, + <String, String>{'groupName': group}, + ))! as Map<String, Object?>; + List<Object?> childrenJson = rootJson['children']! as List<Object?>; + // The tree of nodes returned contains all widgets created directly by the + // test. + childrenJson = rootJson['children']! as List<Object?>; + expect(childrenJson.length, equals(1)); + + List<Object?> alternateChildrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + <String, String>{'arg': rootJson['valueId']! as String, 'objectGroup': group}, + ))! as List<Object?>; + expect(alternateChildrenJson.length, equals(1)); + Map<String, Object?> childJson = childrenJson[0]! as Map<String, Object?>; + Map<String, Object?> alternateChildJson = alternateChildrenJson[0]! as Map<String, Object?>; + expect(childJson['description'], startsWith('Directionality')); + expect(alternateChildJson['description'], startsWith('Directionality')); + expect(alternateChildJson['valueId'], equals(childJson['valueId'])); + + childrenJson = childJson['children']! as List<Object?>; + alternateChildrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + <String, String>{'arg': childJson['valueId']! as String, 'objectGroup': group}, + ))! as List<Object?>; + expect(alternateChildrenJson.length, equals(1)); + expect(childrenJson.length, equals(1)); + alternateChildJson = alternateChildrenJson[0]! as Map<String, Object?>; + childJson = childrenJson[0]! as Map<String, Object?>; + expect(childJson['description'], startsWith('Stack')); + expect(alternateChildJson['description'], startsWith('Stack')); + expect(alternateChildJson['valueId'], equals(childJson['valueId'])); + childrenJson = childJson['children']! as List<Object?>; + + childrenJson = childJson['children']! as List<Object?>; + alternateChildrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + <String, String>{'arg': childJson['valueId']! as String, 'objectGroup': group}, + ))! as List<Object?>; + expect(alternateChildrenJson.length, equals(3)); + expect(childrenJson.length, equals(3)); + alternateChildJson = alternateChildrenJson[2]! as Map<String, Object?>; + childJson = childrenJson[2]! as Map<String, Object?>; + expect(childJson['description'], startsWith('Text')); + + // [childJson] contains the 'textPreview' key since the tree was requested + // with previews [getRootWidgetSummaryTreeWithPreviews]. + expect(childJson['textPreview'], equals('c')); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('ext.flutter.inspector.getSelectedSummaryWidget', (WidgetTester tester) async { + const String group = 'test-group'; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a', textDirection: TextDirection.ltr), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + + final List<DiagnosticsNode> children = elementA.debugDescribeChildren(); + expect(children.length, equals(1)); + final DiagnosticsNode richTextDiagnostic = children.first; + + service.disposeAllGroups(); + service.resetPubRootDirectories(); + service.setSelection(elementA, 'my-group'); + final Map<String, Object?> jsonA = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ))! as Map<String, Object?>; + service.setSelection(richTextDiagnostic.value, 'my-group'); + + service.resetPubRootDirectories(); + Map<String, Object?>? summarySelection = await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedSummaryWidget.name, + <String, String>{'objectGroup': group}, + ) as Map<String, Object?>?; + // No summary selection because we haven't set the pub root directories + // yet to indicate what directories are in the summary tree. + expect(summarySelection, isNull); + + final Map<String, Object?> creationLocation = jsonA['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + final String testFile = creationLocation['file']! as String; + expect(testFile, endsWith('widget_inspector_test.dart')); + final List<String> segments = Uri.parse(testFile).pathSegments; + // Strip a couple subdirectories away to generate a plausible pub root + // directory. + final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; + service.resetPubRootDirectories(); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': pubRootTest}, + ); + + summarySelection = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedSummaryWidget.name, + <String, String>{'objectGroup': group}, + ))! as Map<String, Object?>; + expect(summarySelection['valueId'], isNotNull); + // We got the Text element instead of the selected RichText element + // because only the RichText element is part of the summary tree. + expect(service.toObject(summarySelection['valueId']! as String), elementA); + + // Verify tha the regular getSelectedWidget method still returns + // the RichText object not the Text element. + final Map<String, Object?> regularSelection = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ))! as Map<String, Object?>; + expect(service.toObject(regularSelection['valueId']! as String), richTextDiagnostic.value); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('ext.flutter.inspector creationLocation', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + final Element elementB = find.text('b').evaluate().first; + + service.disposeAllGroups(); + service.resetPubRootDirectories(); + service.setSelection(elementA, 'my-group'); + final Map<String, Object?> jsonA = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ))! as Map<String, Object?>; + final Map<String, Object?> creationLocationA = jsonA['creationLocation']! as Map<String, Object?>; + expect(creationLocationA, isNotNull); + final String fileA = creationLocationA['file']! as String; + final int lineA = creationLocationA['line']! as int; + final int columnA = creationLocationA['column']! as int; + + service.setSelection(elementB, 'my-group'); + final Map<String, Object?> jsonB = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ))! as Map<String, Object?>; + final Map<String, Object?> creationLocationB = jsonB['creationLocation']! as Map<String, Object?>; + expect(creationLocationB, isNotNull); + final String fileB = creationLocationB['file']! as String; + final int lineB = creationLocationB['line']! as int; + final int columnB = creationLocationB['column']! as int; + expect(fileA, endsWith('widget_inspector_test.dart')); + expect(fileA, equals(fileB)); + // We don't hardcode the actual lines the widgets are created on as that + // would make this test fragile. + expect(lineA + 1, equals(lineB)); + // Column numbers are more stable than line numbers. + expect(columnA, equals(15)); + expect(columnA, equals(columnB)); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + group( + 'ext.flutter.inspector.addPubRootDirectories group', + () { + late final String pubRootTest; + + setUpAll(() async { + pubRootTest = generateTestPubRootDirectory(service); + }); + + setUp(() { + service.resetPubRootDirectories(); + }); + + testWidgets( + 'has createdByLocalProject when the widget is in the pubRootDirectory', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': pubRootTest}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'does not have createdByLocalProject if the prefix of the pubRootDirectory is different', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': '/invalid/$pubRootTest'}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'has createdByLocalProject if the pubRootDirectory is prefixed with file://', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': 'file://$pubRootTest'}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'does not have createdByLocalProject if the pubRootDirectory has a different suffix', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': '$pubRootTest/different'}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'has createdByLocalProject if at least one of the pubRootDirectories matches', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': '/unrelated/$pubRootTest', + 'arg1': 'file://$pubRootTest', + }, + ); + + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'widget is part of core framework and is the child of a widget in the package pubRootDirectories', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + + // The RichText child of the Text widget is created by the core framework + // not the current package. + final Element richText = find + .descendant( + of: find.text('a'), + matching: find.byType(RichText), + ) + .evaluate() + .first; + service.setSelection(richText, 'my-group'); + service.setPubRootDirectories(<String>[pubRootTest]); + final Map<String, Object?> jsonObject = + json.decode(service.getSelectedWidget(null, 'my-group')) + as Map<String, Object?>; + expect(jsonObject, isNot(contains('createdByLocalProject'))); + final Map<String, Object?> creationLocation = + jsonObject['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + // This RichText widget is created by the build method of the Text widget + // thus the creation location is in text.dart not basic.dart + final List<String> pathSegmentsFramework = + Uri.parse(creationLocation['file']! as String).pathSegments; + expect( + pathSegmentsFramework.join('/'), + endsWith('/flutter/lib/src/widgets/text.dart'), + ); + + // Strip off /src/widgets/text.dart. + final String pubRootFramework = + '/${pathSegmentsFramework.take(pathSegmentsFramework.length - 3).join('/')}'; + service.resetPubRootDirectories(); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': pubRootFramework}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + service.setSelection(elementA, 'my-group'); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + isNot(contains('createdByLocalProject')), + ); + + service.resetPubRootDirectories(); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': pubRootFramework, 'arg1': pubRootTest}, + ); + service.setSelection(elementA, 'my-group'); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + service.setSelection(richText, 'my-group'); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + }, + skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag. + ); + + group( + 'ext.flutter.inspector.setPubRootDirectories extra args regression test', + () { + // Ensure that passing the isolate id as an argument won't break + // setPubRootDirectories command. + + late final String pubRootTest; + + setUpAll(() { + pubRootTest = generateTestPubRootDirectory(service); + }); + + setUp(() { + service.resetPubRootDirectories(); + }); + + testWidgets( + 'has createdByLocalProject when the widget is in the pubRootDirectory', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': pubRootTest, 'isolateId': '34'}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'does not have createdByLocalProject if the prefix of the pubRootDirectory is different', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': '/invalid/$pubRootTest', + 'isolateId': '34' + }, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'has createdByLocalProject if the pubRootDirectory is prefixed with file://', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': 'file://$pubRootTest', 'isolateId': '34'}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'does not have createdByLocalProject if the pubRootDirectory has a different suffix', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': '$pubRootTest/different', + 'isolateId': '34' + }, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'has createdByLocalProject if at least one of the pubRootDirectories matches', + (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ), + ); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': '/unrelated/$pubRootTest', + 'isolateId': '34', + 'arg1': 'file://$pubRootTest', + }, + ); + + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + }, + skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag. + ); + + Map<Object, Object?> removeLastEvent(List<Map<Object, Object?>> events) { + final Map<Object, Object?> event = events.removeLast(); + // Verify that the event is json encodable. + json.encode(event); + return event; + } + + group('ext.flutter.inspector createdByLocalProject', () { + late final String pubRootTest; + + setUpAll(() { + pubRootTest = generateTestPubRootDirectory(service); + }); + + setUp(() { + service.resetPubRootDirectories(); + }); + + testWidgets( + 'reacts to add and removing pubRootDirectories', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': pubRootTest, + 'arg1': 'file://$pubRootTest', + 'arg2': '/unrelated/$pubRootTest', + }, + ); + service.setSelection(elementA, 'my-group'); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + + await service.testExtension( + WidgetInspectorServiceExtensions.removePubRootDirectories.name, + <String, String>{ + 'arg0': pubRootTest, + }, + ); + service.setSelection(elementA, 'my-group'); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'does not match when the package directory does not match', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': '$pubRootTest/different', + 'arg1': '/unrelated/$pubRootTest', + }, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'has createdByLocalProject when the pubRootDirectory is prefixed with file://', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0':'file://$pubRootTest'}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'can handle consecutive calls to add', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': pubRootTest}, + ); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': '/invalid/$pubRootTest'}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + testWidgets( + 'can handle removing an unrelated pubRootDirectory', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': pubRootTest, + 'arg1': '/invalid/$pubRootTest', + }, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + + service.testExtension( + WidgetInspectorServiceExtensions.removePubRootDirectories.name, + <String, String>{'arg0': '/invalid/$pubRootTest'}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'can handle parent widget being part of a separate package', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + final Element richText = find + .descendant( + of: find.text('a'), + matching: find.byType(RichText), + ) + .evaluate() + .first; + service.setSelection(richText, 'my-group'); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ 'arg0': pubRootTest }, + ); + + final Map<String, Object?> jsonObject = + (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ))! as Map<String, Object?>; + expect(jsonObject, isNot(contains('createdByLocalProject'))); + final Map<String, Object?> creationLocation = + jsonObject['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + // This RichText widget is created by the build method of the Text widget + // thus the creation location is in text.dart not basic.dart + final List<String> pathSegmentsFramework = + Uri.parse(creationLocation['file']! as String).pathSegments; + expect( + pathSegmentsFramework.join('/'), + endsWith('/flutter/lib/src/widgets/text.dart'), + ); + + // Strip off /src/widgets/text.dart. + final String pubRootFramework = + '/${pathSegmentsFramework.take(pathSegmentsFramework.length - 3).join('/')}'; + service.resetPubRootDirectories(); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': pubRootFramework}, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + service.setSelection(elementA, 'my-group'); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + isNot(contains('createdByLocalProject')), + ); + + service.resetPubRootDirectories(); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': pubRootFramework, + 'arg1': pubRootTest, + }, + ); + service.setSelection(elementA, 'my-group'); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + service.setSelection(richText, 'my-group'); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ), + contains('createdByLocalProject'), + ); + }, + ); + }, + skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag. + ); + + group('ext.flutter.inspector createdByLocalProject extra args regression test', () { + late final String pubRootTest; + + setUpAll(() { + pubRootTest = generateTestPubRootDirectory(service); + }); + + setUp(() { + service.resetPubRootDirectories(); + }); + + testWidgets( + 'reacts to add and removing pubRootDirectories', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': pubRootTest, + 'arg1': 'file://$pubRootTest', + 'arg2': '/unrelated/$pubRootTest', + 'isolateId': '34', + }, + ); + service.setSelection(elementA, 'my-group'); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group', 'isolateId': '34',}, + ), + contains('createdByLocalProject'), + ); + + await service.testExtension( + WidgetInspectorServiceExtensions.removePubRootDirectories.name, + <String, String>{ + 'arg0': pubRootTest, + 'isolateId': '34', + }, + ); + service.setSelection(elementA, 'my-group'); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group', 'isolateId': '34',}, + ), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'does not match when the package directory does not match', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': '$pubRootTest/different', + 'arg1': '/unrelated/$pubRootTest', + }, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group', 'isolateId': '34',}, + ), + isNot(contains('createdByLocalProject')), + ); + }, + ); + + testWidgets( + 'has createdByLocalProject when the pubRootDirectory is prefixed with file://', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0':'file://$pubRootTest', + 'isolateId': '34', + }, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group', 'isolateId': '34',}, + ), + contains('createdByLocalProject'), + ); + }, + ); + + testWidgets( + 'can handle consecutive calls to add', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': pubRootTest, + 'isolateId': '34', + }, + ); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': '/invalid/$pubRootTest', + 'isolateId': '34', + }, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group', 'isolateId': '34',}, + ), + contains('createdByLocalProject'), + ); + }, + ); + testWidgets( + 'can handle removing an unrelated pubRootDirectory', + (WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: <Widget>[ + Text('a'), + Text('b', textDirection: TextDirection.ltr), + Text('c', textDirection: TextDirection.ltr), + ], + ), + ); + await tester.pumpWidget(widget); + final Element elementA = find.text('a').evaluate().first; + service.setSelection(elementA, 'my-group'); + + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{ + 'arg0': pubRootTest, + 'arg1': '/invalid/$pubRootTest', + 'isolateId': '34', + }, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{ + 'objectGroup': 'my-group', + 'isolateId': '34', + }, + ), + contains('createdByLocalProject'), + ); + + service.testExtension( + WidgetInspectorServiceExtensions.removePubRootDirectories.name, + <String, String>{ + 'arg0': '/invalid/$pubRootTest', + 'isolateId': '34', + }, + ); + expect( + await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{ + 'objectGroup': 'my-group', + 'isolateId': '34', + }, + ), + contains('createdByLocalProject'), + ); + }, + ); + }, + skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag. + ); + + testWidgets('ext.flutter.inspector.trackRebuildDirtyWidgets with tear-offs', (WidgetTester tester) async { + final Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: WidgetInspector( + selectButtonBuilder: null, + child: _applyConstructor(_TrivialWidget.new), + ), + ); + + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.trackRebuildDirtyWidgets.name, + <String, String>{'enabled': 'true'}, + ), + equals('true'), + ); + + await tester.pumpWidget(widget); + }, + skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag. + ); + + testWidgets('ext.flutter.inspector.trackRebuildDirtyWidgets', (WidgetTester tester) async { + service.rebuildCount = 0; + + await tester.pumpWidget(const ClockDemo()); + + final Element clockDemoElement = find.byType(ClockDemo).evaluate().first; + + service.setSelection(clockDemoElement, 'my-group'); + final Map<String, Object?> jsonObject = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ))! as Map<String, Object?>; + final Map<String, Object?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + final String file = creationLocation['file']! as String; + expect(file, endsWith('widget_inspector_test.dart')); + final List<String> segments = Uri.parse(file).pathSegments; + // Strip a couple subdirectories away to generate a plausible pub root + // directory. + final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; + service.resetPubRootDirectories(); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': pubRootTest}, + ); + + final List<Map<Object, Object?>> rebuildEvents = + service.dispatchedEvents('Flutter.RebuiltWidgets'); + expect(rebuildEvents, isEmpty); + + expect(service.rebuildCount, equals(0)); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.trackRebuildDirtyWidgets.name, + <String, String>{'enabled': 'true'}, + ), + equals('true'), + ); + expect(service.rebuildCount, equals(1)); + await tester.pump(); + + expect(rebuildEvents.length, equals(1)); + Map<Object, Object?> event = removeLastEvent(rebuildEvents); + expect(event['startTime'], isA<int>()); + List<int> data = event['events']! as List<int>; + expect(data.length, equals(14)); + final int numDataEntries = data.length ~/ 2; + Map<String, List<int>> newLocations = event['newLocations']! as Map<String, List<int>>; + expect(newLocations, isNotNull); + expect(newLocations.length, equals(1)); + expect(newLocations.keys.first, equals(file)); + Map<String, Map<String, List<Object?>>> fileLocationsMap = event['locations']! as Map<String, Map<String, List<Object?>>>; + expect(fileLocationsMap, isNotNull); + expect(fileLocationsMap.length, equals(1)); + expect(fileLocationsMap.keys.first, equals(file)); + final List<int> locationsForFile = newLocations[file]!; + expect(locationsForFile.length, equals(21)); + final int numLocationEntries = locationsForFile.length ~/ 3; + expect(numLocationEntries, equals(numDataEntries)); + final Map<String, List<Object?>> locations = fileLocationsMap[file]!; + expect(locations.length, equals(4)); + expect(locations['ids']!.length, equals(7)); + + final Map<int, _CreationLocation> knownLocations = <int, _CreationLocation>{}; + _addToKnownLocationsMap( + knownLocations: knownLocations, + newLocations: fileLocationsMap, + ); + int totalCount = 0; + int maxCount = 0; + for (int i = 0; i < data.length; i += 2) { + final int id = data[i]; + final int count = data[i + 1]; + totalCount += count; + maxCount = max(maxCount, count); + expect(knownLocations, contains(id)); + } + expect(totalCount, equals(27)); + // The creation locations that were rebuilt the most were rebuilt 6 times + // as there are 6 instances of the ClockText widget. + expect(maxCount, equals(6)); + + final List<Element> clocks = find.byType(ClockText).evaluate().toList(); + expect(clocks.length, equals(6)); + // Update a single clock. + StatefulElement clockElement = clocks.first as StatefulElement; + _ClockTextState state = clockElement.state as _ClockTextState; + state.updateTime(); // Triggers a rebuild. + await tester.pump(); + expect(rebuildEvents.length, equals(1)); + event = removeLastEvent(rebuildEvents); + expect(event['startTime'], isA<int>()); + data = event['events']! as List<int>; + // No new locations were rebuilt. + expect(event, isNot(contains('newLocations'))); + expect(event, isNot(contains('locations'))); + + // There were two rebuilds: one for the ClockText element itself and one + // for its child. + expect(data.length, equals(4)); + int id = data[0]; + int count = data[1]; + _CreationLocation location = knownLocations[id]!; + expect(location.file, equals(file)); + // ClockText widget. + expect(location.line, equals(56)); + expect(location.column, equals(9)); + expect(location.name, equals('ClockText')); + expect(count, equals(1)); + + id = data[2]; + count = data[3]; + location = knownLocations[id]!; + expect(location.file, equals(file)); + // Text widget in _ClockTextState build method. + expect(location.line, equals(94)); + expect(location.column, equals(12)); + expect(location.name, equals('Text')); + expect(count, equals(1)); + + // Update 3 of the clocks; + for (int i = 0; i < 3; i++) { + clockElement = clocks[i] as StatefulElement; + state = clockElement.state as _ClockTextState; + state.updateTime(); // Triggers a rebuild. + } + + await tester.pump(); + expect(rebuildEvents.length, equals(1)); + event = removeLastEvent(rebuildEvents); + expect(event['startTime'], isA<int>()); + data = event['events']! as List<int>; + // No new locations were rebuilt. + expect(event, isNot(contains('newLocations'))); + expect(event, isNot(contains('locations'))); + + expect(data.length, equals(4)); + id = data[0]; + count = data[1]; + location = knownLocations[id]!; + expect(location.file, equals(file)); + // ClockText widget. + expect(location.line, equals(56)); + expect(location.column, equals(9)); + expect(location.name, equals('ClockText')); + expect(count, equals(3)); // 3 clock widget instances rebuilt. + + id = data[2]; + count = data[3]; + location = knownLocations[id]!; + expect(location.file, equals(file)); + // Text widget in _ClockTextState build method. + expect(location.line, equals(94)); + expect(location.column, equals(12)); + expect(location.name, equals('Text')); + expect(count, equals(3)); // 3 clock widget instances rebuilt. + + // Update one clock 3 times. + clockElement = clocks.first as StatefulElement; + state = clockElement.state as _ClockTextState; + state.updateTime(); // Triggers a rebuild. + state.updateTime(); // Triggers a rebuild. + state.updateTime(); // Triggers a rebuild. + + await tester.pump(); + expect(rebuildEvents.length, equals(1)); + event = removeLastEvent(rebuildEvents); + expect(event['startTime'], isA<int>()); + data = event['events']! as List<int>; + // No new locations were rebuilt. + expect(event, isNot(contains('newLocations'))); + expect(event, isNot(contains('locations'))); + + expect(data.length, equals(4)); + id = data[0]; + count = data[1]; + // Even though a rebuild was triggered 3 times, only one rebuild actually + // occurred. + expect(count, equals(1)); + + // Trigger a widget creation location that wasn't previously triggered. + state.stopClock(); + await tester.pump(); + expect(rebuildEvents.length, equals(1)); + event = removeLastEvent(rebuildEvents); + expect(event['startTime'], isA<int>()); + data = event['events']! as List<int>; + newLocations = event['newLocations']! as Map<String, List<int>>; + fileLocationsMap = event['locations']! as Map<String, Map<String, List<Object?>>>; + + expect(data.length, equals(4)); + // The second pair in data is the previously unseen rebuild location. + id = data[2]; + count = data[3]; + expect(count, equals(1)); + // Verify the rebuild location is new. + expect(knownLocations, isNot(contains(id))); + _addToKnownLocationsMap( + knownLocations: knownLocations, + newLocations: fileLocationsMap, + ); + // Verify the rebuild location was included in the newLocations data. + expect(knownLocations, contains(id)); + + // Turn off rebuild counts. + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.trackRebuildDirtyWidgets.name, + <String, String>{'enabled': 'false'}, + ), + equals('false'), + ); + + state.updateTime(); // Triggers a rebuild. + await tester.pump(); + // Verify that rebuild events are not fired once the extension is disabled. + expect(rebuildEvents, isEmpty); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('ext.flutter.inspector.trackRepaintWidgets', (WidgetTester tester) async { + service.rebuildCount = 0; + + await tester.pumpWidget(const ClockDemo()); + + final Element clockDemoElement = find.byType(ClockDemo).evaluate().first; + + service.setSelection(clockDemoElement, 'my-group'); + final Map<String, Object?> jsonObject = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ))! as Map<String, Object?>; + final Map<String, Object?> creationLocation = + jsonObject['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + final String file = creationLocation['file']! as String; + expect(file, endsWith('widget_inspector_test.dart')); + final List<String> segments = Uri.parse(file).pathSegments; + // Strip a couple subdirectories away to generate a plausible pub root + // directory. + final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; + service.resetPubRootDirectories(); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + <String, String>{'arg0': pubRootTest}, + ); + + final List<Map<Object, Object?>> repaintEvents = + service.dispatchedEvents('Flutter.RepaintWidgets'); + expect(repaintEvents, isEmpty); + + expect(service.rebuildCount, equals(0)); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.trackRepaintWidgets.name, + <String, String>{'enabled': 'true'}, + ), + equals('true'), + ); + // Unlike trackRebuildDirtyWidgets, trackRepaintWidgets doesn't force a full + // rebuild. + expect(service.rebuildCount, equals(0)); + + await tester.pump(); + + expect(repaintEvents.length, equals(1)); + Map<Object, Object?> event = removeLastEvent(repaintEvents); + expect(event['startTime'], isA<int>()); + List<int> data = event['events']! as List<int>; + expect(data.length, equals(18)); + final int numDataEntries = data.length ~/ 2; + final Map<String, List<int>> newLocations = event['newLocations']! as Map<String, List<int>>; + expect(newLocations, isNotNull); + expect(newLocations.length, equals(1)); + expect(newLocations.keys.first, equals(file)); + final Map<String, Map<String, List<Object?>>> fileLocationsMap = event['locations']! as Map<String, Map<String, List<Object?>>>; + expect(fileLocationsMap, isNotNull); + expect(fileLocationsMap.length, equals(1)); + expect(fileLocationsMap.keys.first, equals(file)); + final List<int> locationsForFile = newLocations[file]!; + expect(locationsForFile.length, equals(27)); + final int numLocationEntries = locationsForFile.length ~/ 3; + expect(numLocationEntries, equals(numDataEntries)); + final Map<String, List<Object?>> locations = fileLocationsMap[file]!; + expect(locations.length, equals(4)); + expect(locations['ids']!.length, equals(9)); + + final Map<int, _CreationLocation> knownLocations = <int, _CreationLocation>{}; + _addToKnownLocationsMap( + knownLocations: knownLocations, + newLocations: fileLocationsMap, + ); + int totalCount = 0; + int maxCount = 0; + for (int i = 0; i < data.length; i += 2) { + final int id = data[i]; + final int count = data[i + 1]; + totalCount += count; + maxCount = max(maxCount, count); + expect(knownLocations, contains(id)); + } + expect(totalCount, equals(34)); + // The creation locations that were rebuilt the most were rebuilt 6 times + // as there are 6 instances of the ClockText widget. + expect(maxCount, equals(6)); + + final List<Element> clocks = find.byType(ClockText).evaluate().toList(); + expect(clocks.length, equals(6)); + // Update a single clock. + final StatefulElement clockElement = clocks.first as StatefulElement; + final _ClockTextState state = clockElement.state as _ClockTextState; + state.updateTime(); // Triggers a rebuild. + await tester.pump(); + expect(repaintEvents.length, equals(1)); + event = removeLastEvent(repaintEvents); + expect(event['startTime'], isA<int>()); + data = event['events']! as List<int>; + // No new locations were rebuilt. + expect(event, isNot(contains('newLocations'))); + expect(event, isNot(contains('locations'))); + + // Triggering a rebuild of one widget in this app causes the whole app + // to repaint. + expect(data.length, equals(18)); + + // TODO(jacobr): add an additional repaint test that uses multiple repaint + // boundaries to test more complex repaint conditions. + + // Turn off rebuild counts. + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.trackRepaintWidgets.name, + <String, String>{'enabled': 'false'}, + ), + equals('false'), + ); + + state.updateTime(); // Triggers a rebuild. + await tester.pump(); + // Verify that repaint events are not fired once the extension is disabled. + expect(repaintEvents, isEmpty); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('ext.flutter.inspector.show', (WidgetTester tester) async { + final Iterable<Map<Object, Object?>> extensionChangedEvents = service.getServiceExtensionStateChangedEvents('ext.flutter.inspector.show'); + Map<Object, Object?> extensionChangedEvent; + int debugShowChangeCounter = 0; + + final GlobalKey key = GlobalKey(); + await tester.pumpWidget( + WidgetsApp( + key: key, + builder: (BuildContext context, Widget? child) { + return const Placeholder(); + }, + color: const Color(0xFF123456), + ), + ); + + final ValueListenableBuilder<bool> valueListenableBuilderWidget = tester.widget( + find.byType(ValueListenableBuilder<bool>), + ); + void debugShowWidgetInspectorOverrideCallback() { + debugShowChangeCounter++; + } + + WidgetsApp.debugShowWidgetInspectorOverride = false; + valueListenableBuilderWidget.valueListenable.addListener(debugShowWidgetInspectorOverrideCallback); + + service.rebuildCount = 0; + expect(extensionChangedEvents, isEmpty); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.show.name, + <String, String>{'enabled': 'true'}, + ), + equals('true'), + ); + expect(extensionChangedEvents.length, equals(1)); + extensionChangedEvent = extensionChangedEvents.last; + expect(extensionChangedEvent['extension'], equals('ext.flutter.inspector.show')); + expect(extensionChangedEvent['value'], isTrue); + expect(service.rebuildCount, equals(0)); // Should not be force rebuilt. + expect(debugShowChangeCounter, equals(1)); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.show.name, + <String, String>{}, + ), + equals('true'), + ); + expect(WidgetsApp.debugShowWidgetInspectorOverride, isTrue); + expect(extensionChangedEvents.length, equals(1)); + expect(service.rebuildCount, equals(0)); // Should not be force rebuilt. + expect(debugShowChangeCounter, equals(1)); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.show.name, + <String, String>{'enabled': 'true'}, + ), + equals('true'), + ); + expect(extensionChangedEvents.length, equals(2)); + extensionChangedEvent = extensionChangedEvents.last; + expect(extensionChangedEvent['extension'], equals('ext.flutter.inspector.show')); + expect(extensionChangedEvent['value'], isTrue); + expect(service.rebuildCount, equals(0)); // Should not be force rebuilt. + expect(debugShowChangeCounter, equals(1)); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.show.name, + <String, String>{'enabled': 'false'}, + ), + equals('false'), + ); + expect(extensionChangedEvents.length, equals(3)); + extensionChangedEvent = extensionChangedEvents.last; + expect(extensionChangedEvent['extension'], equals('ext.flutter.inspector.show')); + expect(extensionChangedEvent['value'], isFalse); + expect(service.rebuildCount, equals(0)); // Should not be force rebuilt. + expect(debugShowChangeCounter, equals(2)); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.show.name, + <String, String>{}, + ), + equals('false'), + ); + expect(extensionChangedEvents.length, equals(3)); + expect(service.rebuildCount, equals(0)); // Should not be force rebuilt. + expect(debugShowChangeCounter, equals(2)); + expect(WidgetsApp.debugShowWidgetInspectorOverride, isFalse); + }); + + testWidgets('ext.flutter.inspector.screenshot', (WidgetTester tester) async { + final GlobalKey outerContainerKey = GlobalKey(); + final GlobalKey paddingKey = GlobalKey(); + final GlobalKey redContainerKey = GlobalKey(); + final GlobalKey whiteContainerKey = GlobalKey(); + final GlobalKey sizedBoxKey = GlobalKey(); + + // Complex widget tree intended to exercise features such as children + // with rotational transforms and clipping without introducing platform + // specific behavior as text rendering would. + await tester.pumpWidget( + Center( + child: RepaintBoundaryWithDebugPaint( + child: ColoredBox( + key: outerContainerKey, + color: Colors.white, + child: Padding( + key: paddingKey, + padding: const EdgeInsets.all(100.0), + child: SizedBox( + key: sizedBoxKey, + height: 100.0, + width: 100.0, + child: Transform.rotate( + angle: 1.0, // radians + child: ClipRRect( + borderRadius: const BorderRadius.only( + topLeft: Radius.elliptical(10.0, 20.0), + topRight: Radius.elliptical(5.0, 30.0), + bottomLeft: Radius.elliptical(2.5, 12.0), + bottomRight: Radius.elliptical(15.0, 6.0), + ), + child: ColoredBox( + key: redContainerKey, + color: Colors.red, + child: ColoredBox( + key: whiteContainerKey, + color: Colors.white, + child: RepaintBoundary( + child: Center( + child: Container( + color: Colors.black, + height: 10.0, + width: 10.0, + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ); + + final Element repaintBoundary = + find.byType(RepaintBoundaryWithDebugPaint).evaluate().single; + + final RenderRepaintBoundary renderObject = repaintBoundary.renderObject! as RenderRepaintBoundary; + + final OffsetLayer layer = renderObject.debugLayer! as OffsetLayer; + final int expectedChildLayerCount = getChildLayerCount(layer); + expect(expectedChildLayerCount, equals(2)); + + final ui.Image image1 = await layer.toImage( + renderObject.semanticBounds.inflate(50.0), + ); + addTearDown(image1.dispose); + + await expectLater( + image1, + matchesGoldenFile('inspector.repaint_boundary_margin.png'), + ); + + // Regression test for how rendering with a pixel scale other than 1.0 + // was handled. + final ui.Image image2 = await layer.toImage( + renderObject.semanticBounds.inflate(50.0), + pixelRatio: 0.5, + ); + addTearDown(image2.dispose); + + await expectLater( + image2, + matchesGoldenFile('inspector.repaint_boundary_margin_small.png'), + ); + + final ui.Image image3 = await layer.toImage( + renderObject.semanticBounds.inflate(50.0), + pixelRatio: 2.0, + ); + addTearDown(image3.dispose); + + await expectLater( + image3, + matchesGoldenFile('inspector.repaint_boundary_margin_large.png'), + ); + + final Layer? layerParent = layer.parent; + final Layer? firstChild = layer.firstChild; + + expect(layerParent, isNotNull); + expect(firstChild, isNotNull); + + final ui.Image? screenshot1 = await service.screenshot( + repaintBoundary, + width: 300.0, + height: 300.0, + ); + addTearDown(() => screenshot1?.dispose()); + + await expectLater( + screenshot1, + matchesGoldenFile('inspector.repaint_boundary.png'), + ); + + // Verify that taking a screenshot didn't change the layers associated with + // the renderObject. + expect(renderObject.debugLayer, equals(layer)); + // Verify that taking a screenshot did not change the number of children + // of the layer. + expect(getChildLayerCount(layer), equals(expectedChildLayerCount)); + + final ui.Image? screenshot2 = await service.screenshot( + repaintBoundary, + width: 500.0, + height: 500.0, + margin: 50.0, + ); + addTearDown(() => screenshot2?.dispose()); + + await expectLater( + screenshot2, + matchesGoldenFile('inspector.repaint_boundary_margin.png'), + ); + + // Verify that taking a screenshot didn't change the layers associated with + // the renderObject. + expect(renderObject.debugLayer, equals(layer)); + // Verify that taking a screenshot did not change the number of children + // of the layer. + expect(getChildLayerCount(layer), equals(expectedChildLayerCount)); + + // Make sure taking a screenshot didn't change the parent of the layer. + expect(layer.parent, equals(layerParent)); + + final ui.Image? screenshot3 = await service.screenshot( + repaintBoundary, + width: 300.0, + height: 300.0, + debugPaint: true, + ); + addTearDown(() => screenshot3?.dispose()); + + await expectLater( + screenshot3, + matchesGoldenFile('inspector.repaint_boundary_debugPaint.png'), + ); + // Verify that taking a screenshot with debug paint on did not change + // the number of children the layer has. + expect(getChildLayerCount(layer), equals(expectedChildLayerCount)); + + // Ensure that creating screenshots including ones with debug paint + // hasn't changed the regular render of the widget. + await expectLater( + find.byType(RepaintBoundaryWithDebugPaint), + matchesGoldenFile('inspector.repaint_boundary.png'), + ); + + expect(renderObject.debugLayer, equals(layer)); + expect(layer.attached, isTrue); + + // Full size image + final ui.Image? screenshot4 = await service.screenshot( + find.byKey(outerContainerKey).evaluate().single, + width: 100.0, + height: 100.0, + ); + addTearDown(() => screenshot4?.dispose()); + + await expectLater( + screenshot4, + matchesGoldenFile('inspector.container.png'), + ); + + final ui.Image? screenshot5 = await service.screenshot( + find.byKey(outerContainerKey).evaluate().single, + width: 100.0, + height: 100.0, + debugPaint: true, + ); + addTearDown(() => screenshot5?.dispose()); + + await expectLater( + screenshot5, + matchesGoldenFile('inspector.container_debugPaint.png'), + ); + + { + // Verify calling the screenshot method still works if the RenderObject + // needs to be laid out again. + final RenderObject container = + find.byKey(outerContainerKey).evaluate().single.renderObject!; + container + ..markNeedsLayout() + ..markNeedsPaint(); + expect(container.debugNeedsLayout, isTrue); + + final ui.Image? screenshot6 = await service.screenshot( + find.byKey(outerContainerKey).evaluate().single, + width: 100.0, + height: 100.0, + debugPaint: true, + ); + addTearDown(() => screenshot6?.dispose()); + + await expectLater( + screenshot6, + matchesGoldenFile('inspector.container_debugPaint.png'), + ); + expect(container.debugNeedsLayout, isFalse); + } + + // Small image + final ui.Image? screenshot7 = await service.screenshot( + find.byKey(outerContainerKey).evaluate().single, + width: 50.0, + height: 100.0, + ); + addTearDown(() => screenshot7?.dispose()); + + await expectLater( + screenshot7, + matchesGoldenFile('inspector.container_small.png'), + ); + + final ui.Image? screenshot8 = await service.screenshot( + find.byKey(outerContainerKey).evaluate().single, + width: 400.0, + height: 400.0, + maxPixelRatio: 3.0, + ); + addTearDown(() => screenshot8?.dispose()); + + await expectLater( + screenshot8, + matchesGoldenFile('inspector.container_large.png'), + ); + + // This screenshot will show the clip rect debug paint but no other + // debug paint. + final ui.Image? screenshot9 = await service.screenshot( + find.byType(ClipRRect).evaluate().single, + width: 100.0, + height: 100.0, + debugPaint: true, + ); + addTearDown(() => screenshot9?.dispose()); + + await expectLater( + screenshot9, + matchesGoldenFile('inspector.clipRect_debugPaint.png'), + ); + + final Element clipRect = find.byType(ClipRRect).evaluate().single; + + final ui.Image? clipRectScreenshot = await service.screenshot( + clipRect, + width: 100.0, + height: 100.0, + margin: 20.0, + debugPaint: true, + ); + addTearDown(() => clipRectScreenshot?.dispose()); + + // Add a margin so that the clip icon shows up in the screenshot. + // This golden image is platform dependent due to the clip icon. + await expectLater( + clipRectScreenshot, + matchesGoldenFile('inspector.clipRect_debugPaint_margin.png'), + ); + + // Verify we get the same image if we go through the service extension + // instead of invoking the screenshot method directly. + final Future<Object?> base64ScreenshotFuture = service.testExtension( + WidgetInspectorServiceExtensions.screenshot.name, + <String, String>{ + 'id': service.toId(clipRect, 'group')!, + 'width': '100.0', + 'height': '100.0', + 'margin': '20.0', + 'debugPaint': 'true', + }, + ); + + final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); + final ui.Image screenshotImage = (await binding.runAsync<ui.Image>(() async { + final String base64Screenshot = (await base64ScreenshotFuture)! as String; + final ui.Codec codec = await ui.instantiateImageCodec(base64.decode(base64Screenshot)); + final ui.FrameInfo frame = await codec.getNextFrame(); + return frame.image; + }))!; + addTearDown(screenshotImage.dispose); + + await expectLater( + screenshotImage, + matchesReferenceImage(clipRectScreenshot!), + ); + + // Test with a very visible debug paint + final ui.Image? screenshot10 = await service.screenshot( + find.byKey(paddingKey).evaluate().single, + width: 300.0, + height: 300.0, + debugPaint: true, + ); + addTearDown(() => screenshot10?.dispose()); + + await expectLater( + screenshot10, + matchesGoldenFile('inspector.padding_debugPaint.png'), + ); + + // The bounds for this box crop its rendered content. + final ui.Image? screenshot11 = await service.screenshot( + find.byKey(sizedBoxKey).evaluate().single, + width: 300.0, + height: 300.0, + debugPaint: true, + ); + addTearDown(() => screenshot11?.dispose()); + + await expectLater( + screenshot11, + matchesGoldenFile('inspector.sizedBox_debugPaint.png'), + ); + + // Verify that setting a margin includes the previously cropped content. + final ui.Image? screenshot12 = await service.screenshot( + find.byKey(sizedBoxKey).evaluate().single, + width: 300.0, + height: 300.0, + margin: 50.0, + debugPaint: true, + ); + addTearDown(() => screenshot12?.dispose()); + + await expectLater( + screenshot12, + matchesGoldenFile('inspector.sizedBox_debugPaint_margin.png'), + ); + }); + + group('layout explorer', () { + const String group = 'test-group'; + + tearDown(() { + service.disposeAllGroups(); + }); + + Future<void> pumpWidgetForLayoutExplorer(WidgetTester tester) async { + const Widget widget = Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Row( + children: <Widget>[ + Flexible( + child: ColoredBox( + color: Colors.green, + child: Text('a'), + ), + ), + Text('b'), + ], + ), + ), + ); + await tester.pumpWidget(widget); + } + + testWidgets('ext.flutter.inspector.getLayoutExplorerNode for RenderBox with BoxParentData',(WidgetTester tester) async { + await pumpWidgetForLayoutExplorer(tester); + + final Element rowElement = tester.element(find.byType(Row)); + service.setSelection(rowElement, group); + + final String id = service.toId(rowElement, group)!; + final Map<String, Object?> result = (await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ))! as Map<String, Object?>; + expect(result['description'], equals('Row')); + + final Map<String, Object?>? renderObject = result['renderObject'] as Map<String, Object?>?; + expect(renderObject, isNotNull); + expect(renderObject!['description'], startsWith('RenderFlex')); + + final Map<String, Object?>? parentRenderElement = result['parentRenderElement'] as Map<String, Object?>?; + expect(parentRenderElement, isNotNull); + expect(parentRenderElement!['description'], equals('Center')); + + final Map<String, Object?>? constraints = result['constraints'] as Map<String, Object?>?; + expect(constraints, isNotNull); + expect(constraints!['type'], equals('BoxConstraints')); + expect(constraints['minWidth'], equals('0.0')); + expect(constraints['minHeight'], equals('0.0')); + expect(constraints['maxWidth'], equals('800.0')); + expect(constraints['maxHeight'], equals('600.0')); + + expect(result['isBox'], equals(true)); + + final Map<String, Object?>? size = result['size'] as Map<String, Object?>?; + expect(size, isNotNull); + expect(size!['width'], equals('800.0')); + expect(size['height'], equals('14.0')); + + expect(result['flexFactor'], isNull); + expect(result['flexFit'], isNull); + + final Map<String, Object?>? parentData = result['parentData'] as Map<String, Object?>?; + expect(parentData, isNotNull); + expect(parentData!['offsetX'], equals('0.0')); + expect(parentData['offsetY'], equals('293.0')); + }); + + testWidgets('ext.flutter.inspector.getLayoutExplorerNode for RenderBox with FlexParentData',(WidgetTester tester) async { + await pumpWidgetForLayoutExplorer(tester); + + final Element flexibleElement = tester.element(find.byType(Flexible).first); + service.setSelection(flexibleElement, group); + + final String id = service.toId(flexibleElement, group)!; + final Map<String, Object?> result = (await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ))! as Map<String, Object?>; + expect(result['description'], equals('Flexible')); + + final Map<String, Object?>? renderObject = result['renderObject'] as Map<String, Object?>?; + expect(renderObject, isNotNull); + expect(renderObject!['description'], startsWith('_RenderColoredBox')); + + final Map<String, Object?>? parentRenderElement = result['parentRenderElement'] as Map<String, Object?>?; + expect(parentRenderElement, isNotNull); + expect(parentRenderElement!['description'], equals('Row')); + + final Map<String, Object?>? constraints = result['constraints'] as Map<String, Object?>?; + expect(constraints, isNotNull); + expect(constraints!['type'], equals('BoxConstraints')); + expect(constraints['minWidth'], equals('0.0')); + expect(constraints['minHeight'], equals('0.0')); + expect(constraints['maxWidth'], equals('786.0')); + expect(constraints['maxHeight'], equals('600.0')); + + expect(result['isBox'], equals(true)); + + final Map<String, Object?>? size = result['size'] as Map<String, Object?>?; + expect(size, isNotNull); + expect(size!['width'], equals('14.0')); + expect(size['height'], equals('14.0')); + + expect(result['flexFactor'], equals(1)); + expect(result['flexFit'], equals('loose')); + + expect(result['parentData'], isNull); + }); + + testWidgets('ext.flutter.inspector.getLayoutExplorerNode for RenderView',(WidgetTester tester) async { + await pumpWidgetForLayoutExplorer(tester); + + final Element element = tester.element(find.byType(Directionality).first); + late Element root; + element.visitAncestorElements((Element ancestor) { + root = ancestor; + return true; + }); + service.setSelection(root, group); + + final String id = service.toId(root, group)!; + final Map<String, Object?> result = (await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ))! as Map<String, Object?>; + expect(result['description'], equals('[root]')); + + final Map<String, Object?>? renderObject = result['renderObject'] as Map<String, Object?>?; + expect(renderObject, isNotNull); + expect(renderObject!['description'], contains('RenderView')); + + expect(result['parentRenderElement'], isNull); + expect(result['constraints'], isNull); + expect(result['isBox'], isNull); + + final Map<String, Object?>? size = result['size'] as Map<String, Object?>?; + expect(size, isNotNull); + expect(size!['width'], equals('800.0')); + expect(size['height'], equals('600.0')); + + expect(result['flexFactor'], isNull); + expect(result['flexFit'], isNull); + expect(result['parentData'], isNull); + }); + + testWidgets('ext.flutter.inspector.setFlexFit', (WidgetTester tester) async { + await pumpWidgetForLayoutExplorer(tester); + + final Element childElement = tester.element(find.byType(Flexible).first); + service.setSelection(childElement, group); + + final String id = service.toId(childElement, group)!; + Map<String, Object?> result = (await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ))! as Map<String, Object?>; + expect(result['description'], equals('Flexible')); + expect(result['flexFit'], equals('loose')); + + final String valueId = result['valueId']! as String; + + final bool flexFitSuccess = (await service.testExtension( + WidgetInspectorServiceExtensions.setFlexFit.name, + <String, String>{'id': valueId, 'flexFit': 'FlexFit.tight'}, + ))! as bool; + expect(flexFitSuccess, isTrue); + + result = (await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ))! as Map<String, Object?>; + expect(result['description'], equals('Flexible')); + expect(result['flexFit'], equals('tight')); + }); + + testWidgets('ext.flutter.inspector.setFlexFactor', (WidgetTester tester) async { + await pumpWidgetForLayoutExplorer(tester); + + final Element childElement = tester.element(find.byType(Flexible).first); + service.setSelection(childElement, group); + + final String id = service.toId(childElement, group)!; + Map<String, Object?> result = (await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ))! as Map<String, Object?>; + expect(result['description'], equals('Flexible')); + expect(result['flexFactor'], equals(1)); + + final String valueId = result['valueId']! as String; + + final bool flexFactorSuccess = (await service.testExtension( + WidgetInspectorServiceExtensions.setFlexFactor.name, + <String, String>{'id': valueId, 'flexFactor': '3'}, + ))! as bool; + expect(flexFactorSuccess, isTrue); + + result = (await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ))! as Map<String, Object?>; + expect(result['description'], equals('Flexible')); + expect(result['flexFactor'], equals(3)); + }); + + testWidgets('ext.flutter.inspector.setFlexProperties', (WidgetTester tester) async { + await pumpWidgetForLayoutExplorer(tester); + + final Element rowElement = tester.element(find.byType(Row).first); + service.setSelection(rowElement, group); + + final String id = service.toId(rowElement, group)!; + Map<String, Object?> result = (await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ))! as Map<String, Object?>; + expect(result['description'], equals('Row')); + + Map<String, Object?> renderObject = result['renderObject']! as Map<String, Object?>; + List<Map<String, Object?>> properties = + (renderObject['properties']! as List<dynamic>).cast<Map<String, Object?>>(); + Map<String, Object?> mainAxisAlignmentProperties = + properties.firstWhere( + (Map<String, Object?> p) => p['type'] == 'EnumProperty<MainAxisAlignment>', + ); + Map<String, Object?> crossAxisAlignmentProperties = + properties.firstWhere( + (Map<String, Object?> p) => p['type'] == 'EnumProperty<CrossAxisAlignment>', + ); + String mainAxisAlignment = mainAxisAlignmentProperties['description']! as String; + String crossAxisAlignment = crossAxisAlignmentProperties['description']! as String; + expect(mainAxisAlignment, equals('start')); + expect(crossAxisAlignment, equals('center')); + + final String valueId = result['valueId']! as String; + final bool flexFactorSuccess = (await service.testExtension( + WidgetInspectorServiceExtensions.setFlexProperties.name, + <String, String>{ + 'id': valueId, + 'mainAxisAlignment': 'MainAxisAlignment.center', + 'crossAxisAlignment': 'CrossAxisAlignment.start', + }, + ))! as bool; + expect(flexFactorSuccess, isTrue); + + result = (await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ))! as Map<String, Object?>; + expect(result['description'], equals('Row')); + + renderObject = result['renderObject']! as Map<String, Object?>; + properties = + (renderObject['properties']! as List<dynamic>).cast<Map<String, Object?>>(); + mainAxisAlignmentProperties = + properties.firstWhere( + (Map<String, Object?> p) => p['type'] == 'EnumProperty<MainAxisAlignment>', + ); + crossAxisAlignmentProperties = + properties.firstWhere( + (Map<String, Object?> p) => p['type'] == 'EnumProperty<CrossAxisAlignment>', + ); + mainAxisAlignment = mainAxisAlignmentProperties['description']! as String; + crossAxisAlignment = crossAxisAlignmentProperties['description']! as String; + expect(mainAxisAlignment, equals('center')); + expect(crossAxisAlignment, equals('start')); + }); + + testWidgets('ext.flutter.inspector.getLayoutExplorerNode does not throw StackOverflowError',(WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/115228 + const Key leafKey = ValueKey<String>('ColoredBox'); + await tester.pumpWidget( + CupertinoApp( + home: CupertinoPageScaffold( + child: Builder( + builder: (BuildContext context) => ColoredBox(key: leafKey, color: CupertinoTheme.of(context).primaryColor), + ), + ), + ), + ); + + final Element leaf = tester.element(find.byKey(leafKey)); + service.setSelection(leaf, group); + final DiagnosticsNode diagnostic = leaf.toDiagnosticsNode(); + final String id = service.toId(diagnostic, group)!; + + Object? error; + try { + await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ); + } catch (e) { + error = e; + } + expect(error, isNull); + }); + + testWidgets( + 'ext.flutter.inspector.getLayoutExplorerNode, on a ToolTip, does not throw StackOverflowError', + (WidgetTester tester) async { + // Regression test for https://github.com/flutter/devtools/issues/5946 + const Widget widget = MaterialApp( + home: Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Row( + children: <Widget>[ + Flexible( + child: ColoredBox( + color: Colors.green, + child: Tooltip( + message: 'a', + child: ElevatedButton( + onPressed: null, + child: Text('a'), + ), + ), + ), + ), + ], + ), + ), + ), + ); + await tester.pumpWidget(widget); + + final Element elevatedButton = + tester.element(find.byType(ElevatedButton).first); + service.setSelection(elevatedButton, group); + + final String id = service.toId(elevatedButton, group)!; + + Object? error; + try { + await service.testExtension( + WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, + <String, String>{'id': id, 'groupName': group, 'subtreeDepth': '1'}, + ); + } catch (e) { + error = e; + } + expect(error, isNull); + }); + }); + + test('ext.flutter.inspector.structuredErrors', () async { + List<Map<Object, Object?>> flutterErrorEvents = service.dispatchedEvents('Flutter.Error'); + expect(flutterErrorEvents, isEmpty); + + final FlutterExceptionHandler oldHandler = FlutterError.presentError; + + try { + // Enable structured errors. + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.structuredErrors.name, + <String, String>{'enabled': 'true'}, + ), + equals('true'), + ); + + // Create an error. + FlutterError.reportError(FlutterErrorDetails( + library: 'rendering library', + context: ErrorDescription('during layout'), + exception: StackTrace.current, + )); + + // Validate that we received an error. + flutterErrorEvents = service.dispatchedEvents('Flutter.Error'); + expect(flutterErrorEvents, hasLength(1)); + + // Validate the error contents. + Map<Object, Object?> error = flutterErrorEvents.first; + expect(error['description'], 'Exception caught by rendering library'); + expect(error['children'], isEmpty); + + // Validate that we received an error count. + expect(error['errorsSinceReload'], 0); + expect( + error['renderedErrorText'], + startsWith('══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞════════════'), + ); + + // Send a second error. + FlutterError.reportError(FlutterErrorDetails( + library: 'rendering library', + context: ErrorDescription('also during layout'), + exception: StackTrace.current, + )); + + // Validate that the error count increased. + flutterErrorEvents = service.dispatchedEvents('Flutter.Error'); + expect(flutterErrorEvents, hasLength(2)); + error = flutterErrorEvents.last; + expect(error['errorsSinceReload'], 1); + expect(error['renderedErrorText'], startsWith('Another exception was thrown:')); + + // Reloads the app. + final FlutterExceptionHandler? oldHandler = FlutterError.onError; + final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); + // We need the runTest to setup the fake async in the test binding. + await binding.runTest(() async { + binding.reassembleApplication(); + await binding.pump(); + }, () { }); + // The run test overrides the flutter error handler, so we should + // restore it back for the structure error to continue working. + FlutterError.onError = oldHandler; + // Cleans up the fake async so it does not bleed into next test. + binding.postTest(); + + // Send another error. + FlutterError.reportError(FlutterErrorDetails( + library: 'rendering library', + context: ErrorDescription('during layout'), + exception: StackTrace.current, + )); + + // And, validate that the error count has been reset. + flutterErrorEvents = service.dispatchedEvents('Flutter.Error'); + expect(flutterErrorEvents, hasLength(3)); + error = flutterErrorEvents.last; + expect(error['errorsSinceReload'], 0); + } finally { + FlutterError.presentError = oldHandler; + } + }); + + testWidgets('Screenshot of composited transforms - only offsets', (WidgetTester tester) async { + // Composited transforms are challenging to take screenshots of as the + // LeaderLayer and FollowerLayer classes used by CompositedTransformTarget + // and CompositedTransformFollower depend on traversing ancestors of the + // layer tree and mutating a [LayerLink] object when attaching layers to + // the tree so that the FollowerLayer knows about the LeaderLayer. + // 1. Finding the correct position for the follower layers requires + // traversing the ancestors of the follow layer to find a common ancestor + // with the leader layer. + // 2. Creating a LeaderLayer and attaching it to a layer tree has side + // effects as the leader layer will attempt to modify the mutable + // LeaderLayer object shared by the LeaderLayer and FollowerLayer. + // These tests verify that screenshots can still be taken and look correct + // when the leader and follower layer are both in the screenshots and when + // only the leader or follower layer is in the screenshot. + final LayerLink link = LayerLink(); + final GlobalKey key = GlobalKey(); + final GlobalKey mainStackKey = GlobalKey(); + final GlobalKey transformTargetParent = GlobalKey(); + final GlobalKey stackWithTransformFollower = GlobalKey(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: RepaintBoundary( + child: Stack( + key: mainStackKey, + children: <Widget>[ + Stack( + key: transformTargetParent, + children: <Widget>[ + Positioned( + left: 123.0, + top: 456.0, + child: CompositedTransformTarget( + link: link, + child: Container(height: 20.0, width: 20.0, color: const Color.fromARGB(128, 255, 0, 0)), + ), + ), + ], + ), + Positioned( + left: 787.0, + top: 343.0, + child: Stack( + key: stackWithTransformFollower, + children: <Widget>[ + // Container so we can see how the follower layer was + // transformed relative to its initial location. + Container(height: 15.0, width: 15.0, color: const Color.fromARGB(128, 0, 0, 255)), + CompositedTransformFollower( + link: link, + child: Container(key: key, height: 10.0, width: 10.0, color: const Color.fromARGB(128, 0, 255, 0)), + ), + ], + ), + ), + ], + ), + ), + ), + ); + final RenderBox box = key.currentContext!.findRenderObject()! as RenderBox; + expect(box.localToGlobal(Offset.zero), const Offset(123.0, 456.0)); + + await expectLater( + find.byKey(mainStackKey), + matchesGoldenFile('inspector.composited_transform.only_offsets.png'), + ); + + final ui.Image? screenshot1 = await WidgetInspectorService.instance.screenshot( + find.byKey(stackWithTransformFollower).evaluate().first, + width: 5000.0, + height: 500.0, + ); + addTearDown(() => screenshot1?.dispose()); + + await expectLater( + screenshot1, + matchesGoldenFile('inspector.composited_transform.only_offsets_follower.png'), + ); + + final ui.Image? screenshot2 = await WidgetInspectorService.instance.screenshot( + find.byType(Stack).evaluate().first, + width: 300.0, + height: 300.0, + ); + addTearDown(() => screenshot2?.dispose()); + + await expectLater( + screenshot2, + matchesGoldenFile('inspector.composited_transform.only_offsets_small.png'), + ); + + final ui.Image? screenshot3 = await WidgetInspectorService.instance.screenshot( + find.byKey(transformTargetParent).evaluate().first, + width: 500.0, + height: 500.0, + ); + addTearDown(() => screenshot3?.dispose()); + + await expectLater( + screenshot3, + matchesGoldenFile('inspector.composited_transform.only_offsets_target.png'), + ); + }); + + testWidgets('Screenshot composited transforms - with rotations', (WidgetTester tester) async { + final LayerLink link = LayerLink(); + final GlobalKey key1 = GlobalKey(); + final GlobalKey key2 = GlobalKey(); + final GlobalKey rotate1 = GlobalKey(); + final GlobalKey rotate2 = GlobalKey(); + final GlobalKey mainStackKey = GlobalKey(); + final GlobalKey stackWithTransformTarget = GlobalKey(); + final GlobalKey stackWithTransformFollower = GlobalKey(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Stack( + key: mainStackKey, + children: <Widget>[ + Stack( + key: stackWithTransformTarget, + children: <Widget>[ + Positioned( + top: 123.0, + left: 456.0, + child: Transform.rotate( + key: rotate1, + angle: 1.0, // radians + child: CompositedTransformTarget( + link: link, + child: Container(key: key1, height: 20.0, width: 20.0, color: const Color.fromARGB(128, 255, 0, 0)), + ), + ), + ), + ], + ), + Positioned( + top: 487.0, + left: 243.0, + child: Stack( + key: stackWithTransformFollower, + children: <Widget>[ + Container(height: 15.0, width: 15.0, color: const Color.fromARGB(128, 0, 0, 255)), + Transform.rotate( + key: rotate2, + angle: -0.3, // radians + child: CompositedTransformFollower( + link: link, + child: Container(key: key2, height: 10.0, width: 10.0, color: const Color.fromARGB(128, 0, 255, 0)), + ), + ), + ], + ), + ), + ], + ), + ), + ); + final RenderBox box1 = key1.currentContext!.findRenderObject()! as RenderBox; + final RenderBox box2 = key2.currentContext!.findRenderObject()! as RenderBox; + // Snapshot the positions of the two relevant boxes to ensure that taking + // screenshots doesn't impact their positions. + final Offset position1 = box1.localToGlobal(Offset.zero); + final Offset position2 = box2.localToGlobal(Offset.zero); + expect(position1.dx, moreOrLessEquals(position2.dx)); + expect(position1.dy, moreOrLessEquals(position2.dy)); + + // Image of the full scene to use as reference to help validate that the + // screenshots of specific subtrees are reasonable. + await expectLater( + find.byKey(mainStackKey), + matchesGoldenFile('inspector.composited_transform.with_rotations.png'), + ); + + final ui.Image? screenshot1 = await WidgetInspectorService.instance.screenshot( + find.byKey(mainStackKey).evaluate().first, + width: 500.0, + height: 500.0, + ); + addTearDown(() => screenshot1?.dispose()); + + await expectLater( + screenshot1, + matchesGoldenFile('inspector.composited_transform.with_rotations_small.png'), + ); + + final ui.Image? screenshot2 = await WidgetInspectorService.instance.screenshot( + find.byKey(stackWithTransformTarget).evaluate().first, + width: 500.0, + height: 500.0, + ); + addTearDown(() => screenshot2?.dispose()); + + await expectLater( + screenshot2, + matchesGoldenFile('inspector.composited_transform.with_rotations_target.png'), + ); + + final ui.Image? screenshot3 = await WidgetInspectorService.instance.screenshot( + find.byKey(stackWithTransformFollower).evaluate().first, + width: 500.0, + height: 500.0, + ); + addTearDown(() => screenshot3?.dispose()); + + await expectLater( + screenshot3, + matchesGoldenFile('inspector.composited_transform.with_rotations_follower.png'), + ); + + // Make sure taking screenshots hasn't modified the positions of the + // TransformTarget or TransformFollower layers. + expect(identical(key1.currentContext!.findRenderObject(), box1), isTrue); + expect(identical(key2.currentContext!.findRenderObject(), box2), isTrue); + expect(box1.localToGlobal(Offset.zero), equals(position1)); + expect(box2.localToGlobal(Offset.zero), equals(position2)); + }); + + testWidgets('getChildrenDetailsSubtree', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Hello, World', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: Scaffold( + appBar: AppBar( + title: const Text('Hello, World'), + ), + body: const Center( + child: Text('Hello, World!'), + ), + ), + ), + ); + service.setSelection(find.text('Hello, World!').evaluate().first, 'my-group'); + + // Figure out the pubRootDirectory + final Map<String, Object?> jsonObject = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + <String, String>{'objectGroup': 'my-group'}, + ))! as Map<String, Object?>; + final Map<String, Object?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + final String file = creationLocation['file']! as String; + expect(file, endsWith('widget_inspector_test.dart')); + final List<String> segments = Uri.parse(file).pathSegments; + // Strip a couple subdirectories away to generate a plausible pub rootdirectory. + final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; + service.resetPubRootDirectories(); + service.addPubRootDirectories(<String>[pubRootTest]); + + final String summary = service.getRootWidgetSummaryTree('foo1'); + // ignore: avoid_dynamic_calls + final List<Object?> childrenOfRoot = json.decode(summary)['children'] as List<Object?>; + final List<Object?> childrenOfMaterialApp = (childrenOfRoot.first! as Map<String, Object?>)['children']! as List<Object?>; + final Map<String, Object?> scaffold = childrenOfMaterialApp.first! as Map<String, Object?>; + expect(scaffold['description'], 'Scaffold'); + final String objectId = scaffold['valueId']! as String; + final String details = service.getDetailsSubtree(objectId, 'foo2'); + // ignore: avoid_dynamic_calls + final List<Object?> detailedChildren = json.decode(details)['children'] as List<Object?>; + + final List<Map<String, Object?>> appBars = <Map<String, Object?>>[]; + void visitChildren(List<Object?> children) { + for (final Map<String, Object?> child in children.cast<Map<String, Object?>>()) { + if (child['description'] == 'AppBar') { + appBars.add(child); + } + if (child.containsKey('children')) { + visitChildren(child['children']! as List<Object?>); + } + } + } + visitChildren(detailedChildren); + expect(appBars.single, isNot(contains('children'))); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('InspectorSerializationDelegate addAdditionalPropertiesCallback', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Hello World!', + home: Scaffold( + appBar: AppBar( + title: const Text('Hello World!'), + ), + body: const Center( + child: Column( + children: <Widget>[ + Text('Hello World!'), + ], + ), + ), + ), + ), + ); + final Finder columnWidgetFinder = find.byType(Column); + expect(columnWidgetFinder, findsOneWidget); + final Element columnWidgetElement = columnWidgetFinder + .evaluate() + .first; + final DiagnosticsNode node = columnWidgetElement.toDiagnosticsNode(); + final InspectorSerializationDelegate delegate = + InspectorSerializationDelegate( + service: service, + includeProperties: true, + addAdditionalPropertiesCallback: + (DiagnosticsNode node, InspectorSerializationDelegate delegate) { + final Map<String, Object> additionalJson = <String, Object>{}; + final Object? value = node.value; + if (value is Element) { + final RenderObject? renderObject = value.renderObject; + if (renderObject != null) { + additionalJson['renderObject'] = + renderObject.toDiagnosticsNode().toJsonMap( + delegate.copyWith(subtreeDepth: 0), + ); + } + } + additionalJson['callbackExecuted'] = true; + return additionalJson; + }, + ); + final Map<String, Object?> json = node.toJsonMap(delegate); + expect(json['callbackExecuted'], true); + expect(json.containsKey('renderObject'), true); + expect(json['renderObject'], isA<Map<String, Object?>>()); + final Map<String, Object?> renderObjectJson = json['renderObject']! as Map<String, Object?>; + expect(renderObjectJson['description'], startsWith('RenderFlex')); + + final InspectorSerializationDelegate emptyDelegate = + InspectorSerializationDelegate( + service: service, + includeProperties: true, + addAdditionalPropertiesCallback: + (DiagnosticsNode node, InspectorSerializationDelegate delegate) { + return null; + }, + ); + final InspectorSerializationDelegate defaultDelegate = + InspectorSerializationDelegate( + service: service, + includeProperties: true, + ); + expect(node.toJsonMap(emptyDelegate), node.toJsonMap(defaultDelegate)); + }); + + testWidgets('debugIsLocalCreationLocation test', (WidgetTester tester) async { + setupDefaultPubRootDirectory(service); + + final GlobalKey key = GlobalKey(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Container( + padding: const EdgeInsets.all(8), + child: Text('target', key: key, textDirection: TextDirection.ltr), + ), + ), + ); + + final Element element = key.currentContext! as Element; + + expect(debugIsLocalCreationLocation(element), isTrue); + expect(debugIsLocalCreationLocation(element.widget), isTrue); + + // Padding is inside container + final Finder paddingFinder = find.byType(Padding); + + final Element paddingElement = paddingFinder.evaluate().first; + + expect(debugIsLocalCreationLocation(paddingElement), isFalse); + expect(debugIsLocalCreationLocation(paddingElement.widget), isFalse); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('debugIsWidgetLocalCreation test', (WidgetTester tester) async { + setupDefaultPubRootDirectory(service); + + final GlobalKey key = GlobalKey(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Container( + padding: const EdgeInsets.all(8), + child: Text('target', key: key, textDirection: TextDirection.ltr), + ), + ), + ); + + final Element element = key.currentContext! as Element; + expect(debugIsWidgetLocalCreation(element.widget), isTrue); + + final Finder paddingFinder = find.byType(Padding); + final Element paddingElement = paddingFinder.evaluate().first; + expect(debugIsWidgetLocalCreation(paddingElement.widget), isFalse); + }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. + + testWidgets('debugIsWidgetLocalCreation false test', (WidgetTester tester) async { + final GlobalKey key = GlobalKey(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Container( + padding: const EdgeInsets.all(8), + child: Text('target', key: key, textDirection: TextDirection.ltr), + ), + ), + ); + + final Element element = key.currentContext! as Element; + expect(debugIsWidgetLocalCreation(element.widget), isFalse); + }, skip: WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --no-track-widget-creation flag. + + test('devToolsInspectorUri test', () { + activeDevToolsServerAddress = 'http://127.0.0.1:9100'; + connectedVmServiceUri = 'http://127.0.0.1:55269/798ay5al_FM=/'; + expect( + WidgetInspectorService.instance.devToolsInspectorUri('inspector-0'), + equals('http://127.0.0.1:9100/#/inspector?uri=http%3A%2F%2F127.0.0.1%3A55269%2F798ay5al_FM%3D%2F&inspectorRef=inspector-0'), + ); + }); + + test('DevToolsDeepLinkProperty test', () { + final DevToolsDeepLinkProperty node = + DevToolsDeepLinkProperty( + 'description of the deep link', + 'http://the-deeplink/', + ); + expect(node.toString(), equals('description of the deep link')); + expect(node.name, isEmpty); + expect(node.value, equals('http://the-deeplink/')); + expect( + node.toJsonMap(const DiagnosticsSerializationDelegate()), + equals(<String, dynamic>{ + 'description': 'description of the deep link', + 'type': 'DevToolsDeepLinkProperty', + 'name': '', + 'style': 'singleLine', + 'allowNameWrap': true, + 'missingIfNull': false, + 'propertyType': 'String', + 'defaultLevel': 'info', + 'value': 'http://the-deeplink/', + }), + ); + }); + } + + static String generateTestPubRootDirectory(TestWidgetInspectorService service) { + final Map<String, Object?> jsonObject = const SizedBox().toDiagnosticsNode().toJsonMap(InspectorSerializationDelegate(service: service)); + final Map<String, Object?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>; + expect(creationLocation, isNotNull); + final String file = creationLocation['file']! as String; + expect(file, endsWith('widget_inspector_test.dart')); + final List<String> segments = Uri + .parse(file) + .pathSegments; + + // Strip a couple subdirectories away to generate a plausible pub root + // directory. + final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; + + return pubRootTest; + } + + static void setupDefaultPubRootDirectory(TestWidgetInspectorService service) { + service.resetPubRootDirectories(); + service + .addPubRootDirectories(<String>[generateTestPubRootDirectory(service)]); + } +} + +void _addToKnownLocationsMap({ + required Map<int, _CreationLocation> knownLocations, + required Map<String, Map<String, List<Object?>>> newLocations, +}) { + newLocations.forEach((String file, Map<String, List<Object?>> entries) { + final List<int> ids = entries['ids']!.cast<int>(); + final List<int> lines = entries['lines']!.cast<int>(); + final List<int> columns = entries['columns']!.cast<int>(); + final List<String> names = entries['names']!.cast<String>(); + + for (int i = 0; i < ids.length; i++) { + final int id = ids[i]; + knownLocations[id] = _CreationLocation( + id: id, + file: file, + line: lines[i], + column: columns[i], + name: names[i], + ); + } + }); +} + +extension WidgetInspectorServiceExtension on WidgetInspectorService { + Future<List<String>> get currentPubRootDirectories async { + return ((await pubRootDirectories( + <String, String>{}, + ))['result'] as List<Object?>).cast<String>(); + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_inspector_test_utils.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_inspector_test_utils.dart new file mode 100644 index 0000000000000000000000000000000000000000..19370bfa778b914ca798c3b2d868a765b3a501d9 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_inspector_test_utils.dart @@ -0,0 +1,129 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:convert'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +/// Tuple-like test class for storing a [stream] and [eventKind]. +/// +/// Used to store the [stream] and [eventKind] that a dispatched event would be +/// sent on. +@immutable +class DispatchedEventKey { + const DispatchedEventKey({required this.stream, required this.eventKind}); + + final String stream; + final String eventKind; + + @override + String toString() { + return '[DispatchedEventKey]($stream, $eventKind)'; + } + + @override + bool operator ==(Object other) { + return other is DispatchedEventKey && + stream == other.stream && + eventKind == other.eventKind; + } + + @override + int get hashCode => Object.hash(stream, eventKind); +} + +class TestWidgetInspectorService extends Object with WidgetInspectorService { + TestWidgetInspectorService() { + selection.addListener(() { + if (selectionChangedCallback != null) { + selectionChangedCallback!(); + } + }); + } + final Map<String, ServiceExtensionCallback> extensions = <String, ServiceExtensionCallback>{}; + + final Map<DispatchedEventKey, List<Map<Object, Object?>>> eventsDispatched = + <DispatchedEventKey, List<Map<Object, Object?>>>{}; + final List<Object?> objectsInspected = <Object?>[]; + + @override + void registerServiceExtension({ + required String name, + required ServiceExtensionCallback callback, + required RegisterServiceExtensionCallback registerExtension, + }) { + assert(!extensions.containsKey(name)); + extensions[name] = callback; + } + + @override + void postEvent( + String eventKind, + Map<Object, Object?> eventData, { + String stream = 'Extension', + }) { + dispatchedEvents(eventKind, stream: stream).add(eventData); + } + + @override + void inspect(Object? object) { + objectsInspected.add(object); + } + + List<Map<Object, Object?>> dispatchedEvents( + String eventKind, { + String stream = 'Extension', + }) { + return eventsDispatched.putIfAbsent( + DispatchedEventKey(stream: stream, eventKind: eventKind), + () => <Map<Object, Object?>>[], + ); + } + + List<Object?> inspectedObjects(){ + return objectsInspected; + } + + Iterable<Map<Object, Object?>> getServiceExtensionStateChangedEvents(String extensionName) { + return dispatchedEvents('Flutter.ServiceExtensionStateChanged') + .where((Map<Object, Object?> event) => event['extension'] == extensionName); + } + + Future<Object?> testExtension(String name, Map<String, String> arguments) async { + expect(extensions, contains(name)); + // Encode and decode to JSON to match behavior using a real service + // extension where only JSON is allowed. + return (json.decode(json.encode(await extensions[name]!(arguments))) as Map<String, dynamic>)['result']; + } + + Future<String> testBoolExtension(String name, Map<String, String> arguments) async { + expect(extensions, contains(name)); + // Encode and decode to JSON to match behavior using a real service + // extension where only JSON is allowed. + return (json.decode(json.encode(await extensions[name]!(arguments))) as Map<String, dynamic>)['enabled'] as String; + } + + int rebuildCount = 0; + + @override + Future<void> forceRebuild() async { + rebuildCount++; + final WidgetsBinding binding = WidgetsBinding.instance; + + if (binding.rootElement != null) { + binding.buildOwner!.reassemble(binding.rootElement!); + } + } + + @override + void resetAllState() { + super.resetAllState(); + eventsDispatched.clear(); + objectsInspected.clear(); + rebuildCount = 0; + } +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_span_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_span_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..d903ab567e972f77745ade21c09f8b63a22366de --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_span_test.dart @@ -0,0 +1,77 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + test('WidgetSpan codeUnitAt', () { + const InlineSpan span = WidgetSpan(child: SizedBox()); + expect(span.codeUnitAt(-1), isNull); + expect(span.codeUnitAt(0), PlaceholderSpan.placeholderCodeUnit); + expect(span.codeUnitAt(1), isNull); + expect(span.codeUnitAt(2), isNull); + + const InlineSpan nestedSpan = TextSpan( + text: 'AAA', + children: <InlineSpan>[span, span], + ); + expect(nestedSpan.codeUnitAt(-1), isNull); + expect(nestedSpan.codeUnitAt(0), 65); + expect(nestedSpan.codeUnitAt(1), 65); + expect(nestedSpan.codeUnitAt(2), 65); + expect(nestedSpan.codeUnitAt(3), PlaceholderSpan.placeholderCodeUnit); + expect(nestedSpan.codeUnitAt(4), PlaceholderSpan.placeholderCodeUnit); + expect(nestedSpan.codeUnitAt(5), isNull); + }); + + test('WidgetSpan.extractFromInlineSpan applies the correct scaling factor', () { + const WidgetSpan a = WidgetSpan(child: SizedBox(), style: TextStyle(fontSize: 0)); + const WidgetSpan b = WidgetSpan(child: SizedBox(), style: TextStyle(fontSize: 10)); + const WidgetSpan c = WidgetSpan(child: SizedBox()); + const WidgetSpan d = WidgetSpan(child: SizedBox(), style: TextStyle(letterSpacing: 999)); + + const TextSpan span = TextSpan( + children: <InlineSpan>[ + a, // fontSize = 0. + TextSpan( + children: <InlineSpan>[ + b, // fontSize = 10. + c, // fontSize = 20. + ], + style: TextStyle(fontSize: 20), + ), + d, // fontSize = 14. + ] + ); + + double effectiveTextScaleFactorFromWidget(Widget widget) { + final Semantics child = (widget as ProxyWidget).child as Semantics; + final dynamic grandChild = child.child; + final double textScaleFactor = grandChild.textScaleFactor as double; // ignore: avoid_dynamic_calls + return textScaleFactor; + } + + final List<double> textScaleFactors = WidgetSpan.extractFromInlineSpan(span, const _QuadraticScaler()) + .map(effectiveTextScaleFactorFromWidget).toList(); + + expect(textScaleFactors, <double>[ + 0, // a + 10, // b + 20, // c + 14, // d + ]); + }); +} + + +class _QuadraticScaler extends TextScaler { + const _QuadraticScaler(); + + @override + double scale(double fontSize) => fontSize * fontSize; + + @override + double get textScaleFactor => throw UnimplementedError(); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_state_property_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_state_property_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..9bf1a24f82823e0eb31054edc009beea5fd64753 --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_state_property_test.dart @@ -0,0 +1,133 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + + +void main() { + test('WidgetStateProperty.resolveWith()', () { + final WidgetStateProperty<WidgetState> value = WidgetStateProperty.resolveWith<WidgetState>( + (Set<WidgetState> states) => states.first, + ); + expect(value.resolve(<WidgetState>{WidgetState.hovered}), WidgetState.hovered); + expect(value.resolve(<WidgetState>{WidgetState.focused}), WidgetState.focused); + expect(value.resolve(<WidgetState>{WidgetState.pressed}), WidgetState.pressed); + expect(value.resolve(<WidgetState>{WidgetState.dragged}), WidgetState.dragged); + expect(value.resolve(<WidgetState>{WidgetState.selected}), WidgetState.selected); + expect(value.resolve(<WidgetState>{WidgetState.disabled}), WidgetState.disabled); + expect(value.resolve(<WidgetState>{WidgetState.error}), WidgetState.error); + }); + + test('WidgetStateProperty.all()', () { + final WidgetStateProperty<int> value = WidgetStateProperty.all<int>(123); + expect(value.resolve(<WidgetState>{WidgetState.hovered}), 123); + expect(value.resolve(<WidgetState>{WidgetState.focused}), 123); + expect(value.resolve(<WidgetState>{WidgetState.pressed}), 123); + expect(value.resolve(<WidgetState>{WidgetState.dragged}), 123); + expect(value.resolve(<WidgetState>{WidgetState.selected}), 123); + expect(value.resolve(<WidgetState>{WidgetState.disabled}), 123); + expect(value.resolve(<WidgetState>{WidgetState.error}), 123); + }); + + test('WidgetStatePropertyAll', () { + const WidgetStatePropertyAll<int> value = WidgetStatePropertyAll<int>(123); + expect(value.resolve(<WidgetState>{}), 123); + expect(value.resolve(<WidgetState>{WidgetState.hovered}), 123); + expect(value.resolve(<WidgetState>{WidgetState.focused}), 123); + expect(value.resolve(<WidgetState>{WidgetState.pressed}), 123); + expect(value.resolve(<WidgetState>{WidgetState.dragged}), 123); + expect(value.resolve(<WidgetState>{WidgetState.selected}), 123); + expect(value.resolve(<WidgetState>{WidgetState.disabled}), 123); + expect(value.resolve(<WidgetState>{WidgetState.error}), 123); + }); + + test('toString formats correctly', () { + const WidgetStateProperty<Color?> colorProperty = WidgetStatePropertyAll<Color?>(Color(0xFFFFFFFF)); + expect(colorProperty.toString(), equals('WidgetStatePropertyAll(Color(0xffffffff))')); + + const WidgetStateProperty<double?> doubleProperty = WidgetStatePropertyAll<double?>(33 + 1/3); + expect(doubleProperty.toString(), equals('WidgetStatePropertyAll(33.3)')); + }); + + test("Can interpolate between two WidgetStateProperty's", () { + const WidgetStateProperty<TextStyle?> textStyle1 = WidgetStatePropertyAll<TextStyle?>( + TextStyle(fontSize: 14.0), + ); + const WidgetStateProperty<TextStyle?> textStyle2 = WidgetStatePropertyAll<TextStyle?>( + TextStyle(fontSize: 20.0), + ); + + // Using `0.0` interpolation value. + TextStyle textStyle = WidgetStateProperty.lerp<TextStyle?>( + textStyle1, + textStyle2, + 0.0, + TextStyle.lerp, + )!.resolve(enabled)!; + expect(textStyle.fontSize, 14.0); + + // Using `0.5` interpolation value. + textStyle = WidgetStateProperty.lerp<TextStyle?>( + textStyle1, + textStyle2, + 0.5, + TextStyle.lerp, + )!.resolve(enabled)!; + expect(textStyle.fontSize, 17.0); + + // Using `1.0` interpolation value. + textStyle = WidgetStateProperty.lerp<TextStyle?>( + textStyle1, + textStyle2, + 1.0, + TextStyle.lerp, + )!.resolve(enabled)!; + expect(textStyle.fontSize, 20.0); + }); + + test('WidgetStateBorderSide.lerp()', () { + const WidgetStateProperty<BorderSide?> borderSide1 = WidgetStatePropertyAll<BorderSide?>( + BorderSide( + color: Color(0xffff0000), + width: 4.0, + ), + ); + const WidgetStateProperty<BorderSide?> borderSide2 = WidgetStatePropertyAll<BorderSide?>( + BorderSide( + color: Color(0xff0000ff), + width: 12.0, + ), + ); + + // Using `0.0` interpolation value. + BorderSide borderSide = WidgetStateBorderSide.lerp( + borderSide1, + borderSide2, + 0.0, + )!.resolve(enabled)!; + expect(borderSide.color, const Color(0xffff0000)); + expect(borderSide.width, 4.0); + + // Using `0.5` interpolation value. + borderSide = WidgetStateBorderSide.lerp( + borderSide1, + borderSide2, + 0.5, + )!.resolve(enabled)!; + expect(borderSide.color, const Color(0xff7f007f)); + expect(borderSide.width, 8.0); + + // Using `1.0` interpolation value. + borderSide = WidgetStateBorderSide.lerp( + borderSide1, + borderSide2, + 1.0, + )!.resolve(enabled)!; + expect(borderSide.color, const Color(0xff0000ff)); + expect(borderSide.width, 12.0); + }); +} + +Set<WidgetState> enabled = <WidgetState>{}; diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_states_controller_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_states_controller_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..07462bff13dc82f17c5847c37f9241713eca6f1e --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/widget_states_controller_test.dart @@ -0,0 +1,93 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; + +void main() { + test('WidgetStatesController constructor', () { + expect(WidgetStatesController().value, <WidgetState>{}); + expect(WidgetStatesController(<WidgetState>{}).value, <WidgetState>{}); + expect(WidgetStatesController(<WidgetState>{WidgetState.selected}).value, <WidgetState>{WidgetState.selected}); + }); + + test('WidgetStatesController dispatches memory events', () async { + await expectLater( + await memoryEvents(() => WidgetStatesController().dispose(), WidgetStatesController), + areCreateAndDispose, + ); + }); + + test('WidgetStatesController update, listener', () { + int count = 0; + void valueChanged() { + count += 1; + } + final WidgetStatesController controller = WidgetStatesController(); + controller.addListener(valueChanged); + + controller.update(WidgetState.selected, true); + expect(controller.value, <WidgetState>{WidgetState.selected}); + expect(count, 1); + controller.update(WidgetState.selected, true); + expect(controller.value, <WidgetState>{WidgetState.selected}); + expect(count, 1); + + controller.update(WidgetState.hovered, false); + expect(count, 1); + expect(controller.value, <WidgetState>{WidgetState.selected}); + controller.update(WidgetState.selected, false); + expect(count, 2); + expect(controller.value, <WidgetState>{}); + + controller.update(WidgetState.hovered, true); + expect(controller.value, <WidgetState>{WidgetState.hovered}); + expect(count, 3); + controller.update(WidgetState.hovered, true); + expect(controller.value, <WidgetState>{WidgetState.hovered}); + expect(count, 3); + controller.update(WidgetState.pressed, true); + expect(controller.value, <WidgetState>{WidgetState.hovered, WidgetState.pressed}); + expect(count, 4); + controller.update(WidgetState.selected, true); + expect(controller.value, <WidgetState>{WidgetState.hovered, WidgetState.pressed, WidgetState.selected}); + expect(count, 5); + controller.update(WidgetState.selected, false); + expect(controller.value, <WidgetState>{WidgetState.hovered, WidgetState.pressed}); + expect(count, 6); + controller.update(WidgetState.selected, false); + expect(controller.value, <WidgetState>{WidgetState.hovered, WidgetState.pressed}); + expect(count, 6); + controller.update(WidgetState.pressed, false); + expect(controller.value, <WidgetState>{WidgetState.hovered}); + expect(count, 7); + controller.update(WidgetState.hovered, false); + expect(controller.value, <WidgetState>{}); + expect(count, 8); + + controller.removeListener(valueChanged); + controller.update(WidgetState.selected, true); + expect(controller.value, <WidgetState>{WidgetState.selected}); + expect(count, 8); + }); + + + test('WidgetStatesController const initial value', () { + int count = 0; + void valueChanged() { + count += 1; + } + final WidgetStatesController controller = WidgetStatesController(const <WidgetState>{WidgetState.selected}); + controller.addListener(valueChanged); + + controller.update(WidgetState.selected, true); + expect(controller.value, <WidgetState>{WidgetState.selected}); + expect(count, 0); + + controller.update(WidgetState.selected, false); + expect(controller.value, <WidgetState>{}); + expect(count, 1); + }); +} diff --git a/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/wrap_test.dart b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/wrap_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..1a132ef0255f2dedaf053bef29c38e714765a68b --- /dev/null +++ b/novelforge-project/agent-workspace/flutter/packages/flutter/test/widgets/wrap_test.dart @@ -0,0 +1,955 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void verify(WidgetTester tester, List<Offset> answerKey) { + final List<Offset> testAnswers = tester.renderObjectList<RenderBox>(find.byType(SizedBox)).map<Offset>( + (RenderBox target) => target.localToGlobal(Offset.zero), + ).toList(); + expect(testAnswers, equals(answerKey)); +} + +void main() { + testWidgets('Basic Wrap test (LTR)', (WidgetTester tester) async { + await tester.pumpWidget( + const Wrap( + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + ], + ), + ); + verify(tester, <Offset>[ + Offset.zero, + const Offset(300.0, 0.0), + const Offset(0.0, 100.0), + const Offset(300.0, 100.0), + ]); + + await tester.pumpWidget( + const Wrap( + alignment: WrapAlignment.center, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + ], + ), + ); + verify(tester, <Offset>[ + const Offset(100.0, 0.0), + const Offset(400.0, 0.0), + const Offset(100.0, 100.0), + const Offset(400.0, 100.0), + ]); + + await tester.pumpWidget( + const Wrap( + alignment: WrapAlignment.end, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + ], + ), + ); + verify(tester, <Offset>[ + const Offset(200.0, 0.0), + const Offset(500.0, 0.0), + const Offset(200.0, 100.0), + const Offset(500.0, 100.0), + ]); + + await tester.pumpWidget( + const Wrap( + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 300.0, height: 50.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 50.0), + ], + ), + ); + verify(tester, <Offset>[ + Offset.zero, + const Offset(300.0, 0.0), + const Offset(0.0, 100.0), + const Offset(300.0, 100.0), + ]); + + await tester.pumpWidget( + const Wrap( + crossAxisAlignment: WrapCrossAlignment.center, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 300.0, height: 50.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 50.0), + ], + ), + ); + verify(tester, <Offset>[ + const Offset(0.0, 25.0), + const Offset(300.0, 0.0), + const Offset(0.0, 100.0), + const Offset(300.0, 125.0), + ]); + + await tester.pumpWidget( + const Wrap( + crossAxisAlignment: WrapCrossAlignment.end, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 300.0, height: 50.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 50.0), + ], + ), + ); + verify(tester, <Offset>[ + const Offset(0.0, 50.0), + const Offset(300.0, 0.0), + const Offset(0.0, 100.0), + const Offset(300.0, 150.0), + ]); + + }); + + testWidgets('Basic Wrap test (RTL)', (WidgetTester tester) async { + await tester.pumpWidget( + const Wrap( + textDirection: TextDirection.rtl, + children: <Widget>[ + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + ], + ), + ); + verify(tester, <Offset>[ + const Offset(500.0, 0.0), + const Offset(200.0, 0.0), + const Offset(500.0, 100.0), + const Offset(200.0, 100.0), + ]); + + await tester.pumpWidget( + const Wrap( + alignment: WrapAlignment.center, + textDirection: TextDirection.rtl, + children: <Widget>[ + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + ], + ), + ); + verify(tester, <Offset>[ + const Offset(400.0, 0.0), + const Offset(100.0, 0.0), + const Offset(400.0, 100.0), + const Offset(100.0, 100.0), + ]); + + await tester.pumpWidget( + const Wrap( + alignment: WrapAlignment.end, + textDirection: TextDirection.rtl, + children: <Widget>[ + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + ], + ), + ); + verify(tester, <Offset>[ + const Offset(300.0, 0.0), + Offset.zero, + const Offset(300.0, 100.0), + const Offset(0.0, 100.0), + ]); + + await tester.pumpWidget( + const Wrap( + textDirection: TextDirection.ltr, + verticalDirection: VerticalDirection.up, + children: <Widget>[ + SizedBox(width: 300.0, height: 50.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 50.0), + ], + ), + ); + verify(tester, <Offset>[ + const Offset(0.0, 550.0), + const Offset(300.0, 500.0), + const Offset(0.0, 400.0), + const Offset(300.0, 450.0), + ]); + + await tester.pumpWidget( + const Wrap( + crossAxisAlignment: WrapCrossAlignment.center, + textDirection: TextDirection.ltr, + verticalDirection: VerticalDirection.up, + children: <Widget>[ + SizedBox(width: 300.0, height: 50.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 50.0), + ], + ), + ); + verify(tester, <Offset>[ + const Offset(0.0, 525.0), + const Offset(300.0, 500.0), + const Offset(0.0, 400.0), + const Offset(300.0, 425.0), + ]); + + await tester.pumpWidget( + const Wrap( + crossAxisAlignment: WrapCrossAlignment.end, + textDirection: TextDirection.ltr, + verticalDirection: VerticalDirection.up, + children: <Widget>[ + SizedBox(width: 300.0, height: 50.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 100.0), + SizedBox(width: 300.0, height: 50.0), + ], + ), + ); + verify(tester, <Offset>[ + const Offset(0.0, 500.0), + const Offset(300.0, 500.0), + const Offset(0.0, 400.0), + const Offset(300.0, 400.0), + ]); + + }); + + testWidgets('Empty wrap', (WidgetTester tester) async { + await tester.pumpWidget(const Center(child: Wrap(alignment: WrapAlignment.center))); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(Size.zero)); + }); + + testWidgets('Wrap alignment (LTR)', (WidgetTester tester) async { + await tester.pumpWidget(const Wrap( + alignment: WrapAlignment.center, + spacing: 5.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(95.0, 0.0), + const Offset(200.0, 0.0), + const Offset(405.0, 0.0), + ]); + + await tester.pumpWidget(const Wrap( + alignment: WrapAlignment.spaceBetween, + spacing: 5.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + Offset.zero, + const Offset(200.0, 0.0), + const Offset(500.0, 0.0), + ]); + + await tester.pumpWidget(const Wrap( + alignment: WrapAlignment.spaceAround, + spacing: 5.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 310.0, height: 30.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(30.0, 0.0), + const Offset(195.0, 0.0), + const Offset(460.0, 0.0), + ]); + + await tester.pumpWidget(const Wrap( + alignment: WrapAlignment.spaceEvenly, + spacing: 5.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 310.0, height: 30.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(45.0, 0.0), + const Offset(195.0, 0.0), + const Offset(445.0, 0.0), + ]); + }); + + testWidgets('Wrap alignment (RTL)', (WidgetTester tester) async { + await tester.pumpWidget(const Wrap( + alignment: WrapAlignment.center, + spacing: 5.0, + textDirection: TextDirection.rtl, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(605.0, 0.0), + const Offset(400.0, 0.0), + const Offset(95.0, 0.0), + ]); + + await tester.pumpWidget(const Wrap( + alignment: WrapAlignment.spaceBetween, + spacing: 5.0, + textDirection: TextDirection.rtl, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(700.0, 0.0), + const Offset(400.0, 0.0), + Offset.zero, + ]); + + await tester.pumpWidget(const Wrap( + alignment: WrapAlignment.spaceAround, + spacing: 5.0, + textDirection: TextDirection.rtl, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 310.0, height: 30.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(670.0, 0.0), + const Offset(405.0, 0.0), + const Offset(30.0, 0.0), + ]); + + await tester.pumpWidget(const Wrap( + alignment: WrapAlignment.spaceEvenly, + spacing: 5.0, + textDirection: TextDirection.rtl, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 310.0, height: 30.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(655.0, 0.0), + const Offset(405.0, 0.0), + const Offset(45.0, 0.0), + ]); + }); + + testWidgets('Wrap runAlignment (DOWN)', (WidgetTester tester) async { + await tester.pumpWidget(const Wrap( + runAlignment: WrapAlignment.center, + runSpacing: 5.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + SizedBox(width: 400.0, height: 40.0), + SizedBox(width: 500.0, height: 60.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(0.0, 230.0), + const Offset(100.0, 230.0), + const Offset(300.0, 230.0), + const Offset(0.0, 265.0), + const Offset(0.0, 310.0), + ]); + + await tester.pumpWidget(const Wrap( + runAlignment: WrapAlignment.spaceBetween, + runSpacing: 5.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + SizedBox(width: 400.0, height: 40.0), + SizedBox(width: 500.0, height: 60.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + Offset.zero, + const Offset(100.0, 0.0), + const Offset(300.0, 0.0), + const Offset(0.0, 265.0), + const Offset(0.0, 540.0), + ]); + + await tester.pumpWidget(const Wrap( + runAlignment: WrapAlignment.spaceAround, + runSpacing: 5.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + SizedBox(width: 400.0, height: 40.0), + SizedBox(width: 500.0, height: 70.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(0.0, 75.0), + const Offset(100.0, 75.0), + const Offset(300.0, 75.0), + const Offset(0.0, 260.0), + const Offset(0.0, 455.0), + ]); + + await tester.pumpWidget(const Wrap( + runAlignment: WrapAlignment.spaceEvenly, + runSpacing: 5.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + SizedBox(width: 400.0, height: 40.0), + SizedBox(width: 500.0, height: 60.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(0.0, 115.0), + const Offset(100.0, 115.0), + const Offset(300.0, 115.0), + const Offset(0.0, 265.0), + const Offset(0.0, 425.0), + ]); + + }); + + testWidgets('Wrap runAlignment (UP)', (WidgetTester tester) async { + await tester.pumpWidget(const Wrap( + runAlignment: WrapAlignment.center, + runSpacing: 5.0, + textDirection: TextDirection.ltr, + verticalDirection: VerticalDirection.up, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + SizedBox(width: 400.0, height: 40.0), + SizedBox(width: 500.0, height: 60.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(0.0, 360.0), + const Offset(100.0, 350.0), + const Offset(300.0, 340.0), + const Offset(0.0, 295.0), + const Offset(0.0, 230.0), + ]); + + await tester.pumpWidget(const Wrap( + runAlignment: WrapAlignment.spaceBetween, + runSpacing: 5.0, + textDirection: TextDirection.ltr, + verticalDirection: VerticalDirection.up, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + SizedBox(width: 400.0, height: 40.0), + SizedBox(width: 500.0, height: 60.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(0.0, 590.0), + const Offset(100.0, 580.0), + const Offset(300.0, 570.0), + const Offset(0.0, 295.0), + Offset.zero, + ]); + + await tester.pumpWidget(const Wrap( + runAlignment: WrapAlignment.spaceAround, + runSpacing: 5.0, + textDirection: TextDirection.ltr, + verticalDirection: VerticalDirection.up, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + SizedBox(width: 400.0, height: 40.0), + SizedBox(width: 500.0, height: 70.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(0.0, 515.0), + const Offset(100.0, 505.0), + const Offset(300.0, 495.0), + const Offset(0.0, 300.0), + const Offset(0.0, 75.0), + ]); + + await tester.pumpWidget(const Wrap( + runAlignment: WrapAlignment.spaceEvenly, + runSpacing: 5.0, + textDirection: TextDirection.ltr, + verticalDirection: VerticalDirection.up, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + SizedBox(width: 400.0, height: 40.0), + SizedBox(width: 500.0, height: 60.0), + ], + )); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + const Offset(0.0, 475.0), + const Offset(100.0, 465.0), + const Offset(300.0, 455.0), + const Offset(0.0, 295.0), + const Offset(0.0, 115.0), + ]); + + }); + + testWidgets('Shrink-wrapping Wrap test', (WidgetTester tester) async { + await tester.pumpWidget( + const Align( + alignment: Alignment.topLeft, + child: Wrap( + alignment: WrapAlignment.end, + crossAxisAlignment: WrapCrossAlignment.end, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 100.0, height: 10.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 300.0, height: 30.0), + SizedBox(width: 400.0, height: 40.0), + ], + ), + ), + ); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(600.0, 70.0))); + verify(tester, <Offset>[ + const Offset(0.0, 20.0), + const Offset(100.0, 10.0), + const Offset(300.0, 0.0), + const Offset(200.0, 30.0), + ]); + + await tester.pumpWidget( + const Align( + alignment: Alignment.topLeft, + child: Wrap( + alignment: WrapAlignment.end, + crossAxisAlignment: WrapCrossAlignment.end, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 400.0, height: 40.0), + SizedBox(width: 300.0, height: 30.0), + SizedBox(width: 200.0, height: 20.0), + SizedBox(width: 100.0, height: 10.0), + ], + ), + ), + ); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(700.0, 60.0))); + verify(tester, <Offset>[ + Offset.zero, + const Offset(400.0, 10.0), + const Offset(400.0, 40.0), + const Offset(600.0, 50.0), + ]); + }); + + testWidgets('Wrap spacing test', (WidgetTester tester) async { + await tester.pumpWidget( + const Align( + alignment: Alignment.topLeft, + child: Wrap( + runSpacing: 10.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 500.0, height: 10.0), + SizedBox(width: 500.0, height: 20.0), + SizedBox(width: 500.0, height: 30.0), + SizedBox(width: 500.0, height: 40.0), + ], + ), + ), + ); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(500.0, 130.0))); + verify(tester, <Offset>[ + Offset.zero, + const Offset(0.0, 20.0), + const Offset(0.0, 50.0), + const Offset(0.0, 90.0), + ]); + }); + + testWidgets('Vertical Wrap test with spacing', (WidgetTester tester) async { + await tester.pumpWidget( + const Align( + alignment: Alignment.topLeft, + child: Wrap( + direction: Axis.vertical, + spacing: 10.0, + runSpacing: 15.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 10.0, height: 250.0), + SizedBox(width: 20.0, height: 250.0), + SizedBox(width: 30.0, height: 250.0), + SizedBox(width: 40.0, height: 250.0), + SizedBox(width: 50.0, height: 250.0), + SizedBox(width: 60.0, height: 250.0), + ], + ), + ), + ); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(150.0, 510.0))); + verify(tester, <Offset>[ + Offset.zero, + const Offset(0.0, 260.0), + const Offset(35.0, 0.0), + const Offset(35.0, 260.0), + const Offset(90.0, 0.0), + const Offset(90.0, 260.0), + ]); + + await tester.pumpWidget( + const Align( + alignment: Alignment.topLeft, + child: Wrap( + spacing: 12.0, + runSpacing: 8.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 10.0, height: 250.0), + SizedBox(width: 20.0, height: 250.0), + SizedBox(width: 30.0, height: 250.0), + SizedBox(width: 40.0, height: 250.0), + SizedBox(width: 50.0, height: 250.0), + SizedBox(width: 60.0, height: 250.0), + ], + ), + ), + ); + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(270.0, 250.0))); + verify(tester, <Offset>[ + Offset.zero, + const Offset(22.0, 0.0), + const Offset(54.0, 0.0), + const Offset(96.0, 0.0), + const Offset(148.0, 0.0), + const Offset(210.0, 0.0), + ]); + }); + + testWidgets('Visual overflow generates a clip', (WidgetTester tester) async { + await tester.pumpWidget(const Wrap( + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 500.0, height: 500.0), + ], + )); + + expect(tester.renderObject<RenderBox>(find.byType(Wrap)), isNot(paints..clipRect())); + + await tester.pumpWidget(const Wrap( + textDirection: TextDirection.ltr, + clipBehavior: Clip.hardEdge, + children: <Widget>[ + SizedBox(width: 500.0, height: 500.0), + SizedBox(width: 500.0, height: 500.0), + ], + )); + + expect(tester.renderObject<RenderBox>(find.byType(Wrap)), paints..clipRect()); + }); + + testWidgets('Hit test children in wrap', (WidgetTester tester) async { + final List<String> log = <String>[]; + + await tester.pumpWidget(Wrap( + spacing: 10.0, + runSpacing: 15.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + const SizedBox(width: 200.0, height: 300.0), + const SizedBox(width: 200.0, height: 300.0), + const SizedBox(width: 200.0, height: 300.0), + const SizedBox(width: 200.0, height: 300.0), + SizedBox( + width: 200.0, + height: 300.0, + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { log.add('hit'); }, + ), + ), + ], + )); + + await tester.tapAt(const Offset(209.0, 314.0)); + expect(log, isEmpty); + + await tester.tapAt(const Offset(211.0, 314.0)); + expect(log, isEmpty); + + await tester.tapAt(const Offset(209.0, 316.0)); + expect(log, isEmpty); + + await tester.tapAt(const Offset(211.0, 316.0)); + expect(log, equals(<String>['hit'])); + }); + + testWidgets('RenderWrap toStringShallow control test', (WidgetTester tester) async { + await tester.pumpWidget(const Wrap(alignment: WrapAlignment.center)); + + final RenderBox wrap = tester.renderObject(find.byType(Wrap)); + expect(wrap.toStringShallow(), hasOneLineDescription); + }); + + testWidgets('RenderWrap toString control test', (WidgetTester tester) async { + await tester.pumpWidget(const Wrap( + direction: Axis.vertical, + runSpacing: 7.0, + textDirection: TextDirection.ltr, + children: <Widget>[ + SizedBox(width: 500.0, height: 400.0), + SizedBox(width: 500.0, height: 400.0), + SizedBox(width: 500.0, height: 400.0), + SizedBox(width: 500.0, height: 400.0), + ], + )); + + final RenderBox wrap = tester.renderObject(find.byType(Wrap)); + final double width = wrap.getMinIntrinsicWidth(600.0); + expect(width, equals(2021)); + }); + + testWidgets('Wrap baseline control test', (WidgetTester tester) async { + await tester.pumpWidget( + const Center( + child: Baseline( + baseline: 175.0, + baselineType: TextBaseline.alphabetic, + child: DefaultTextStyle( + style: TextStyle( + fontFamily: 'FlutterTest', + fontSize: 100.0, + ), + child: Wrap( + textDirection: TextDirection.ltr, + children: <Widget>[ + Text('X', textDirection: TextDirection.ltr), + ], + ), + ), + ), + ), + ); + expect(tester.renderObject<RenderBox>(find.text('X')).size, const Size(100.0, 100.0)); + expect( + tester.renderObject<RenderBox>(find.byType(Baseline)).size, + const Size(100.0, 200.0), + ); + }); + + testWidgets('Spacing with slight overflow', (WidgetTester tester) async { + await tester.pumpWidget(const Wrap( + textDirection: TextDirection.ltr, + spacing: 10.0, + runSpacing: 10.0, + children: <Widget>[ + SizedBox(width: 200.0, height: 10.0), + SizedBox(width: 200.0, height: 10.0), + SizedBox(width: 200.0, height: 10.0), + SizedBox(width: 171.0, height: 10.0), + ], + )); + + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0))); + verify(tester, <Offset>[ + Offset.zero, + const Offset(210.0, 0.0), + const Offset(420.0, 0.0), + const Offset(0.0, 20.0), + ]); + }); + + testWidgets('Object exactly matches container width', (WidgetTester tester) async { + await tester.pumpWidget( + const Column( + children: <Widget>[ + Wrap( + textDirection: TextDirection.ltr, + spacing: 10.0, + runSpacing: 10.0, + children: <Widget>[ + SizedBox(width: 800.0, height: 10.0), + ], + ), + ], + ), + ); + + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 10.0))); + verify(tester, <Offset>[Offset.zero]); + + await tester.pumpWidget( + const Column( + children: <Widget>[ + Wrap( + textDirection: TextDirection.ltr, + spacing: 10.0, + runSpacing: 10.0, + children: <Widget>[ + SizedBox(width: 800.0, height: 10.0), + SizedBox(width: 800.0, height: 10.0), + ], + ), + ], + ), + ); + + expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 30.0))); + verify(tester, <Offset>[ + Offset.zero, + const Offset(0.0, 20.0), + ]); + }); + + testWidgets('Wrap can set and update clipBehavior', (WidgetTester tester) async { + await tester.pumpWidget(const Wrap(textDirection: TextDirection.ltr)); + final RenderWrap renderObject = tester.allRenderObjects.whereType<RenderWrap>().first; + expect(renderObject.clipBehavior, equals(Clip.none)); + + await tester.pumpWidget(const Wrap(textDirection: TextDirection.ltr, clipBehavior: Clip.antiAlias)); + expect(renderObject.clipBehavior, equals(Clip.antiAlias)); + }); + + testWidgets('Horizontal wrap - IntrinsicsHeight', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/48679. + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: IntrinsicHeight( + child: ColoredBox( + color: Colors.green, + child: Wrap( + children: <Widget>[ + Text('Start', style: TextStyle(height: 1.0, fontSize: 16)), + Row( + children: <Widget>[ + SizedBox(height: 40, width: 60), + ], + ), + Text('End', style: TextStyle(height: 1.0, fontSize: 16)), + ], + ), + ), + ), + ), + ), + ); + + // The row takes up the full width, therefore the "Start" and "End" text + // are placed before and after it and the total height is the sum of the + // individual heights. + expect(tester.getSize(find.byType(IntrinsicHeight)).height, 2 * 16 + 40); + }); + + testWidgets('Vertical wrap - IntrinsicsWidth', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/48679. + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: IntrinsicWidth( + child: ColoredBox( + color: Colors.green, + child: Wrap( + direction: Axis.vertical, + children: <Widget>[ + Text('Start', style: TextStyle(height: 1.0, fontSize: 16)), + Column( + children: <Widget>[ + SizedBox(height: 40, width: 60), + ], + ), + Text('End', style: TextStyle(height: 1.0, fontSize: 16)), + ], + ), + ), + ), + ), + ), + ); + + // The column takes up the full height, therefore the "Start" and "End" text + // are placed to the left and right of it and the total width is the sum of + // the individual widths. + expect(tester.getSize(find.byType(IntrinsicWidth)).width, 5 * 16 + 60 + 3 * 16); + }); +} diff --git a/novelforge-project/flutter/bin/cache/artifacts/engine/android-arm64-release/flutter.jar b/novelforge-project/flutter/bin/cache/artifacts/engine/android-arm64-release/flutter.jar new file mode 100644 index 0000000000000000000000000000000000000000..0ee406950b60284b7496e91fb16056d301078793 --- /dev/null +++ b/novelforge-project/flutter/bin/cache/artifacts/engine/android-arm64-release/flutter.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:068edfcd9d81660dc8b3592c7b7d330ac4b9b9fac45d3915449c8cdec56f762e +size 132 diff --git a/novelforge-project/flutter/bin/cache/artifacts/engine/android-x64-profile/flutter.jar b/novelforge-project/flutter/bin/cache/artifacts/engine/android-x64-profile/flutter.jar new file mode 100644 index 0000000000000000000000000000000000000000..8a37e48914a6e98d2486c18f40aecd59670968a7 --- /dev/null +++ b/novelforge-project/flutter/bin/cache/artifacts/engine/android-x64-profile/flutter.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0345cef4ff861d7e07b04d53c9a536d3aefab6dd0f344253a8d1d95da4f489c7 +size 132 diff --git a/novelforge-project/flutter/bin/cache/artifacts/engine/android-x64-release/flutter.jar b/novelforge-project/flutter/bin/cache/artifacts/engine/android-x64-release/flutter.jar new file mode 100644 index 0000000000000000000000000000000000000000..b4ab9b1f95cc003007ce0e4a42de299c4b72c523 --- /dev/null +++ b/novelforge-project/flutter/bin/cache/artifacts/engine/android-x64-release/flutter.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd84f9afa434dc1c7fa2eeb557288c02a31bf3e53f6c45b2e12747d5ea1e93b7 +size 132 diff --git a/novelforge-project/flutter/bin/cache/artifacts/engine/android-x64/flutter.jar b/novelforge-project/flutter/bin/cache/artifacts/engine/android-x64/flutter.jar new file mode 100644 index 0000000000000000000000000000000000000000..56270646213c68185203ee62475a1cfa0e25376d --- /dev/null +++ b/novelforge-project/flutter/bin/cache/artifacts/engine/android-x64/flutter.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1bab6868fb51d278196509adb52f6144ac776a9c465d09a43123eac1a7bb3aa7 +size 133